/***********************************************************************
 *
 *  Copyright (C) 2005-2006 Novell, Inc. All Rights Reserved.
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; version 2.1
 *  of the License.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Library Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, Novell, Inc.
 *
 *  To contact Novell about this file by physical or electronic mail,
 *  you may find current contact information at www.novell.com.
 *
 ***********************************************************************/


#ifndef __FPM_PROFILE_MANAGER_H__
#define __FPM_PROFILE_MANAGER_H__

#include "FirefoxPasswordManager.h"
#include "Common.h"
#include "SignonManager.h"


class ProfileManager
{
	SignonManager signonManager;
	
	char *profilePath;
	char *libraryPath;
	char *masterPassword;

	HMODULE libnss;
	HMODULE libplc;

	// NSS Library function pointers
	NSS_Init                NSSInit;
	NSS_Shutdown            NSSShutdown;
	//PK11_SetPasswordFunc    PK11SetPasswordFunc;
	PK11_GetInternalKeySlot PK11GetInternalKeySlot;
	PK11_FreeSlot           PK11FreeSlot;
	PK11_Authenticate       PK11Authenticate;
    PK11_CheckUserPassword  PK11CheckUserPassword;
	PK11SDR_Decrypt         PK11SDRDecrypt;
	PK11SDR_Encrypt         PK11SDREncrypt;

	PL_Base64Encode         PLBase64Encode;
	PL_Base64Decode         PLBase64Decode;

public : 

	char *profileName;
	int isInitialized;

private :

	char *GetFirefoxProfilePath(char *profileName);
	char *GetFirefoxLibPath();
	HMODULE PMLoadLibrary(char *firefoxDir, char *libName);
	int RefreshSignonData();
	


public:

	ProfileManager();

	int IsStoreAvailable();
	int ProfileInit(char *profileName);
	void ProfileExit();

	int IsMasterPasswordSet();
	int CheckMasterPassword(char *masterPassword, int doSave);

	int GetSignonData( struct Host **host, int doRefresh);
	int WriteSignonData();

	int AddHost(struct Host *host, int doUpdate);
	int ModifyHost(struct Host *host, int doUpdat);
	int RemoveHost(char *hostname, int doUpdate);

};


#endif