/***********************************************************************
 * 
 *  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 _SSCS_IPC_H
#define _SSCS_IPC_H
#include <micasa_types.h>

typedef uint8_t Byte;
#define MAX_SOCKET_PATH_LEN 256
#ifdef DEBUG
#define DMSG(x) printf x
#else
#define DMSG(x)
#endif
// Used for global buffers.
#define	MIN_REQUEST_BUF_LEN		1024
#define	MIN_REPLY_BUF_LEN		4096

#ifdef SSCS_LINUX_PLAT_F
#include "sscs_unx_ipc_client.h"
#include "sscs_unx_cache_defines.h"
#include <sscs_lldefs.h>
#include <errno.h>
#include <unistd.h>

#define IPC_CREATE(...) ipc_unx_create(__VA_ARGS__);
#define IPC_READ(...)   ipc_unx_read(__VA_ARGS__);
#define IPC_WRITE(...)  ipc_unx_write(__VA_ARGS__);
#define IPC_CLOSE(...)  ipc_unx_close(__VA_ARGS__);

#else

//#ifdef SSCS_WIN32_PLAT_F

#include <windows.h>
#include "sscs_unx_ipc_client.h"
#include "sscs_unx_cache_defines.h"
#include <sscs_lldefs.h>
#include <errno.h>

#define IPC_CREATE()		 ipc_win_create();
#define IPC_READ(s1,s2,s3)   ipc_win_read(s1,s2,s3);
#define IPC_WRITE(s1,s2,s3)  ipc_win_write(s1,s2,s3);
#define IPC_CLOSE(s1)		 ipc_win_close(s1);

//#endif

// function prototypes
int ipc_OpenSecretStore
(
    void *secretStoreID,
    SSCS_SECRETSTORE_HANDLE_T *ssHandle
);

int ipc_CloseSecretStore
(
    SSCS_SECRETSTORE_HANDLE_T *ssHandle,
	uint32_t	ssFlags
);

int ipc_RemoveSecretStore
(
    SSCS_SECRETSTORE_HANDLE_T *ssHandle
);

int ipc_EnumerateKeychainIDs
(
    SSCS_SECRETSTORE_HANDLE_T *ssHandle,
    SSCS_KEYCHAIN_ID_LIST_T *kcIDList
);

int ipc_AddKeychain
(
    SSCS_SECRETSTORE_HANDLE_T *ssHandle,
    unsigned int ssFlags,
    SSCS_KEYCHAIN_ID_T *keychainID
);

int ipc_RemoveKeychain
(
    SSCS_SECRETSTORE_HANDLE_T *ssHandle,
    SSCS_KEYCHAIN_ID_T *keychainID
);

int ipc_EnumerateSecretIDs
(
    SSCS_SECRETSTORE_HANDLE_T *ssHandle,
    SSCS_KEYCHAIN_ID_T        *keychainID,
    SSCS_SECRET_ID_LIST_T     *secretIDList
);

int ipc_ReadSecret
(
    SSCS_SECRETSTORE_HANDLE_T *ssHandle,
    SSCS_KEYCHAIN_ID_T        *keychainID,
    SSCS_SECRET_ID_T          *secretID,
    SSCS_SECRET_T             *secretData,
    SSCS_PASSWORD_T           *epPassword,
    unsigned int              *bytesRequired
);

int ipc_WriteSecret
(
    SSCS_SECRETSTORE_HANDLE_T *ssHandle,
    unsigned int              ssFlags,
    SSCS_KEYCHAIN_ID_T        *keychainID,
    SSCS_SECRET_ID_T          *secretID,
    SSCS_SECRET_T             *secretData,
    SSCS_PASSWORD_T           *epPassword,
	SSCS_EXT_T				  *ext
);

int ipc_RemoveSecret
(
    SSCS_SECRETSTORE_HANDLE_T *ssHandle,
    SSCS_KEYCHAIN_ID_T        *keychainID,
    SSCS_SECRET_ID_T          *secretID,
    SSCS_PASSWORD_T           *epPassword
);

int  ipc_GetSecretStoreInfo
(
    SSCS_SECRETSTORE_HANDLE_T *ssHandle,
    SSCS_SECRETSTORE_INFO_T *ssInfo
);

int  ipc_GetKeychainInfo
(
    SSCS_SECRETSTORE_HANDLE_T *ssHandle,
    SSCS_KEYCHAIN_ID_T        *keychainID,
    SSCS_KEYCHAIN_INFO_T      *kcInfo
);

int  ipc_LockCache
(
    SSCS_SECRETSTORE_HANDLE_T *ssHandle
);

int ipc_UnlockCache
(
    SSCS_SECRETSTORE_HANDLE_T *ssHandle,
    SSCS_PASSCODE_T *passcode
);

int ipc_SetMasterPasscode
(
    SSCS_SECRETSTORE_HANDLE_T *ssHandle,
    SSCS_PASSCODE_T *passcode
);

int ipc_ReadKey
(
    SSCS_SECRETSTORE_HANDLE_T *ssHandle,
    SSCS_KEYCHAIN_ID_T        *keychainID,
    SSCS_SECRET_ID_T          *secretID,
    SS_UTF8_T                 *key,
    uint32_t                   keyLen,
    uint8_t                    *val,
    uint32_t                   *valLen,
    SSCS_PASSWORD_T           *epPassword,
    uint32_t                  *bytesRequired
);

int ipc_WriteKey
(
    SSCS_SECRETSTORE_HANDLE_T *ssHandle,
    uint32_t                  ssFlags,
    SSCS_KEYCHAIN_ID_T        *keychainID,
    SSCS_SECRET_ID_T          *secretID,
    SS_UTF8_T                 *key,
    uint32_t                   keyLen,
    uint8_t                    *val,
    uint32_t                   valLen,
    SSCS_PASSWORD_T           *epPassword,
    SSCS_EXT_T				  *ext
);

int ipc_ReadBinaryKey
(
    SSCS_SECRETSTORE_HANDLE_T *ssHandle,
    SSCS_KEYCHAIN_ID_T        *keychainID,
    SSCS_SECRET_ID_T          *secretID,
    SS_UTF8_T                 *key,
    uint32_t                   keyLen,
    uint8_t                    *val,
    uint32_t                   *valLen,
    SSCS_PASSWORD_T           *epPassword,
    uint32_t                  *bytesRequired
);

int ipc_WriteBinaryKey
(
    SSCS_SECRETSTORE_HANDLE_T *ssHandle,
    uint32_t                  ssFlags,
    SSCS_KEYCHAIN_ID_T        *keychainID,
    SSCS_SECRET_ID_T          *secretID,
    SS_UTF8_T                 *key,
    uint32_t                   keyLen,
    uint8_t                    *val,
    uint32_t                   valLen,
    SSCS_PASSWORD_T           *epPassword,
    SSCS_EXT_T				  *ext
);

int32_t ipc_SetMasterPassword
(
    SSCS_SECRETSTORE_HANDLE_T *ssHandle,
    SSCS_PASSWORD_T *passwd,
    SSCS_HINT_T *hint
);

int ipc_IsSecretPersistent
(
    SSCS_SECRETSTORE_HANDLE_T *ssHandle,
    uint32_t                  ssFlags,
    SSCS_KEYCHAIN_ID_T        *keychainID,
    SSCS_SECRET_ID_T          *secretID,
    SSCS_EXT_T				  *ext
);

#endif
#endif