major source structure and module name change - continue4

This commit is contained in:
soochoi
2006-06-08 21:38:52 +00:00
parent 1d82ff5d6a
commit 6ac32abb91
36 changed files with 51 additions and 15 deletions

View File

@@ -0,0 +1,123 @@
/*
* DO NOT EDIT. THIS FILE IS GENERATED FROM IMiCASAKeys.idl
*/
/***********************************************************************
*
* 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 __gen_IMiCASAKeys_h__
#define __gen_IMiCASAKeys_h__
#ifndef __gen_nsISupports_h__
#include "nsISupports.h"
#endif
/* For IDL files that don't want to include root IDL files. */
#ifndef NS_NO_VTABLE
#define NS_NO_VTABLE
#endif
/* starting interface: IMiCASAKeys */
#define IMICASAKEYS_IID_STR "a3f70ce4-fae8-4bd1-98eb-0cf581e4b4dc"
#define IMICASAKEYS_IID \
{0xa3f70ce4, 0xfae8, 0x4bd1, \
{ 0x98, 0xeb, 0x0c, 0xf5, 0x81, 0xe4, 0xb4, 0xdc }}
class NS_NO_VTABLE IMiCASAKeys : public nsISupports {
public:
NS_DEFINE_STATIC_IID_ACCESSOR(IMICASAKEYS_IID)
/* PRInt32 miCASAWriteKey (in AUTF8String secretId, in AUTF8String key, in AUTF8String value); */
NS_IMETHOD MiCASAWriteKey(const nsACString & secretId, const nsACString & key, const nsACString & value, PRInt32 *_retval) = 0;
/* PRInt32 miCASAReadKey (in AUTF8String secretId, in AUTF8String key, out AUTF8String value); */
NS_IMETHOD MiCASAReadKey(const nsACString & secretId, const nsACString & key, nsACString & value, PRInt32 *_retval) = 0;
};
/* Use this macro when declaring classes that implement this interface. */
#define NS_DECL_IMICASAKEYS \
NS_IMETHOD MiCASAWriteKey(const nsACString & secretId, const nsACString & key, const nsACString & value, PRInt32 *_retval); \
NS_IMETHOD MiCASAReadKey(const nsACString & secretId, const nsACString & key, nsACString & value, PRInt32 *_retval);
/* Use this macro to declare functions that forward the behavior of this interface to another object. */
#define NS_FORWARD_IMICASAKEYS(_to) \
NS_IMETHOD MiCASAWriteKey(const nsACString & secretId, const nsACString & key, const nsACString & value, PRInt32 *_retval) { return _to MiCASAWriteKey(secretId, key, value, _retval); } \
NS_IMETHOD MiCASAReadKey(const nsACString & secretId, const nsACString & key, nsACString & value, PRInt32 *_retval) { return _to MiCASAReadKey(secretId, key, value, _retval); }
/* Use this macro to declare functions that forward the behavior of this interface to another object in a safe way. */
#define NS_FORWARD_SAFE_IMICASAKEYS(_to) \
NS_IMETHOD MiCASAWriteKey(const nsACString & secretId, const nsACString & key, const nsACString & value, PRInt32 *_retval) { return !_to ? NS_ERROR_NULL_POINTER : _to->MiCASAWriteKey(secretId, key, value, _retval); } \
NS_IMETHOD MiCASAReadKey(const nsACString & secretId, const nsACString & key, nsACString & value, PRInt32 *_retval) { return !_to ? NS_ERROR_NULL_POINTER : _to->MiCASAReadKey(secretId, key, value, _retval); }
#if 0
/* Use the code below as a template for the implementation class for this interface. */
/* Header file */
class _MYCLASS_ : public IMiCASAKeys
{
public:
NS_DECL_ISUPPORTS
NS_DECL_IMICASAKEYS
_MYCLASS_();
private:
~_MYCLASS_();
protected:
/* additional members */
};
/* Implementation file */
NS_IMPL_ISUPPORTS1(_MYCLASS_, IMiCASAKeys)
_MYCLASS_::_MYCLASS_()
{
/* member initializers and constructor code */
}
_MYCLASS_::~_MYCLASS_()
{
/* destructor code */
}
/* PRInt32 miCASAWriteKey (in AUTF8String secretId, in AUTF8String key, in AUTF8String value); */
NS_IMETHODIMP _MYCLASS_::MiCASAWriteKey(const nsACString & secretId, const nsACString & key, const nsACString & value, PRInt32 *_retval)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* PRInt32 miCASAReadKey (in AUTF8String secretId, in AUTF8String key, out AUTF8String value); */
NS_IMETHODIMP _MYCLASS_::MiCASAReadKey(const nsACString & secretId, const nsACString & key, nsACString & value, PRInt32 *_retval)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* End of implementation class template. */
#endif
#endif /* __gen_IMiCASAKeys_h__ */

View File

@@ -0,0 +1,41 @@
CXX = c++
CPPFLAGS += -fno-rtti \
-fno-exceptions \
-shared
# CASA includes
CASA_INCLUDE_PATH = ../../../include
# Change this to point at your Gecko SDK directory.
GECKO_LIB_PATH = /usr/lib/xulrunner-1.8.0.1
GECKO_INCLUDE_PATH = /usr/include/xulrunner-1.8.0.1
MOZILLA_NSPR4_DEVEL = /usr/include/nspr4
# GCC only define which allows us to not have to #include mozilla-config
# in every .cpp file. If your not using GCC remove this line and add
# #include "mozilla-config.h" to each of your .cpp files.
GECKO_CONFIG_INCLUDE = -include mozilla-config.h
#MOZILLA_STRICT_API is needed for gecko-sdk 1.7 or earlier
#GECKO_DEFINES = -DMOZILLA_STRICT_API
GECKO_DEFINES =
CASA_INCLUDE = -I $(CASA_INCLUDE_PATH)
XPCOM_INCLUDES = -I $(GECKO_INCLUDE_PATH) -I $(MOZILLA_NSPR4_DEVEL)
GECKO_LDFLAGS = -L $(GECKO_LIB_PATH) \
-lxpcom \
-lnspr4 \
-lplds4
FILES = MiCASAKeys.cpp MiCASAKeysModule.cpp
TARGET = MiCASAKeys.so
build:
$(CXX) -Wall -Os -o $(TARGET) $(CASA_INCLUDE) $(GECKO_CONFIG_INCLUDE) $(GECKO_DEFINES) $(XPCOM_INCLUDES) $(CPPFLAGS) $(CXXFLAGS) $(FILES) $(GECKO_LIB_PATH)/libxpcomglue_s.a $(GECKO_LDFLAGS)
chmod +x $(TARGET)
# strip $(TARGET)
clean:
rm $(TARGET)

View File

@@ -0,0 +1,253 @@
/***********************************************************************
*
* 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.
*
***********************************************************************/
#include "MiCASAKeys.h"
#include <nsMemory.h>
#include <nsStringAPI.h>
#include <stdarg.h>
#include <dlfcn.h>
#include <syslog.h>
#include <errno.h>
#define MODULE_NAME "MiCASAKeys.so"
#define VERSION "1.00.0.0"
void _xpcom_log (int error, const char *format, ...)
{
char buffer [1024];
char identification [32];
va_list args;
sprintf (identification, "%s %s ", MODULE_NAME, VERSION);
va_start (args, format);
vsprintf (buffer, format, args);
openlog (identification, LOG_PID, LOG_AUTH);
setlogmask (LOG_UPTO (LOG_DEBUG));
syslog (error, buffer);
closelog ();
//printf("%i\t%s\t%s\n", error, identification, buffer);
}
/* Implementation file */
NS_IMPL_ISUPPORTS1(MiCASAKeys, IMiCASAKeys)
MiCASAKeys::MiCASAKeys()
{
m_bLibraryLoaded = FALSE;
m_pCASAOpen = NULL;
m_pCASAClose = NULL;
m_pCASAWriteKey = NULL;
m_pCASAReadKey = NULL;
_xpcom_log (LOG_INFO, "MiCASAKeys::MiCASAKeys constructor called.");
/* member initializers and constructor code */
m_hCASALibrary = dlopen("libmicasa.so", RTLD_LAZY);
if (m_hCASALibrary)
{
_xpcom_log (LOG_INFO, "libmicasa.so opened successfully.");
m_pCASAOpen = (PCASAOPEN)dlsym(m_hCASALibrary, "miCASAOpenSecretStoreCache");
m_pCASAClose = (PCASACLOSE)dlsym(m_hCASALibrary, "miCASACloseSecretStoreCache");
m_pCASAWriteKey = (PCASAWRITEKEY)dlsym(m_hCASALibrary, "miCASAWriteKey");
m_pCASAReadKey = (PCASAREADKEY)dlsym(m_hCASALibrary, "miCASAReadKey");
m_bLibraryLoaded = TRUE;
}
else
{
_xpcom_log(LOG_ERR, "dlopen on libmicasa.so failed, errno - %d.", errno);
}
}
MiCASAKeys::~MiCASAKeys()
{
/* destructor code */
// if (m_bLibraryLoaded == TRUE)
// {
// dlclose(hMod);
// m_bLibraryLoaded = FALSE;
// }
}
/* PRInt32 miCASAWriteKey (in string secretId, in string key, in string value); */
//NS_IMETHODIMP MiCASAKeys::MiCASAWriteKey(const char *secretId, const char *key, const char *value, PRInt32 *_retval)
/* PRInt32 miCASAWriteKey (in AUTF8String secretId, in AUTF8String key, in AUTF8String value); */
NS_IMETHODIMP MiCASAKeys::MiCASAWriteKey(const nsACString & secretId, const nsACString & key, const nsACString & value, PRInt32 *_retval)
{
_xpcom_log (LOG_INFO, "MiCASAKeys::MiCASAWriteKey called.");
if (m_bLibraryLoaded == TRUE)
{
nsresult result;
SSCS_KEYCHAIN_ID_T sessionKeyChain = {26, "SSCS_SESSION_KEY_CHAIN_ID"};
SSCS_SECRET_ID_T sharedId;
SSCS_SECRETSTORE_T ssId;
HANDLE context;
ssId.version = NSSCS_VERSION_NUMBER;
strncpy((char *)ssId.ssName, (char *)SSCS_DEFAULT_SECRETSTORE_ID, sizeof(ssId.ssName));
result = NSSCS_E_SYSTEM_FAILURE;
if (m_pCASAOpen)
{
context = (*m_pCASAOpen)(
&ssId,
0,
NULL);
if (context)
{
sharedId.len = secretId.Length() + 1;
strncpy((char *)sharedId.id, secretId.BeginReading(), sizeof(sharedId.id));
if (m_pCASAReadKey)
{
result = (*m_pCASAWriteKey)(
context,
0,
&sessionKeyChain,
&sharedId,
(unsigned char *)key.BeginReading(),
key.Length() + 1,
(unsigned char *)value.BeginReading(),
value.Length() + 1,
NULL,
NULL);
}
else
{
_xpcom_log (LOG_INFO, "MiCASAKeys::MiCASAWriteKey - m_pCASAWriteKey is NULL.");
}
(*m_pCASAClose)(
context,
0,
NULL);
}
else
{
_xpcom_log (LOG_INFO, "MiCASAKeys::MiCASAWriteKey - miCASAOpenSecretStoreCache failed.");
}
}
else
{
_xpcom_log (LOG_INFO, "MiCASAKeys::MiCASAWriteKey - m_pCASAOpen is NULL.");
}
*_retval = result;
return result;
}
else
{
_xpcom_log (LOG_INFO, "MiCASAKeys::MiCASAWriteKey library not loaded.");
return NSSCS_E_SERVICE_NOT_FOUND;
}
}
/* PRInt32 miCASAReadKey (in string secretId, in string key, out string value); */
//NS_IMETHODIMP MiCASAKeys::MiCASAReadKey(const char *secretId, const char *key, char **value, PRInt32 *_retval)
/* PRInt32 miCASAReadKey (in AUTF8String secretId, in AUTF8String key, out AUTF8String value); */
NS_IMETHODIMP MiCASAKeys::MiCASAReadKey(const nsACString & secretId, const nsACString & key, nsACString & value, PRInt32 *_retval)
{
_xpcom_log (LOG_INFO, "MiCASAKeys::MiCASAReadKey called.");
if (m_bLibraryLoaded == TRUE)
{
nsresult result;
SSCS_KEYCHAIN_ID_T sessionKeyChain = {26, "SSCS_SESSION_KEY_CHAIN_ID"};
SSCS_SECRET_ID_T sharedId;
SSCS_SECRETSTORE_T ssId;
uint32_t bytesRequired;
HANDLE context;
ssId.version = NSSCS_VERSION_NUMBER;
strncpy((char *)ssId.ssName, (char *)SSCS_DEFAULT_SECRETSTORE_ID, sizeof(ssId.ssName));
result = NSSCS_E_SYSTEM_FAILURE;
if (m_pCASAOpen)
{
context = (*m_pCASAOpen)(
&ssId,
0,
NULL);
if (context)
{
uint32_t valueLength = 256;
unsigned char tempValue[257];
sharedId.len = secretId.Length() + 1;
strncpy((char *)sharedId.id, secretId.BeginReading(), sizeof(sharedId.id));
if (m_pCASAReadKey)
{
result = (*m_pCASAReadKey)(
context,
0,
&sessionKeyChain,
&sharedId,
(unsigned char *)key.BeginReading(),
key.Length() + 1,
tempValue,
&valueLength,
NULL,
&bytesRequired,
NULL);
value.Assign((char *)tempValue, valueLength - 1);
}
else
{
_xpcom_log (LOG_INFO, "MiCASAKeys::MiCASAReadKey - m_pCASAReadKey is NULL.");
}
(*m_pCASAClose)(
context,
0,
NULL);
}
else
{
_xpcom_log (LOG_INFO, "MiCASAKeys::MiCASAReadKey - miCASAOpenSecretStoreCache failed.");
}
}
else
{
_xpcom_log (LOG_INFO, "MiCASAKeys::MiCASAReadKey - m_pCASAOpen is NULL.");
}
*_retval = result;
return result;
}
else
{
_xpcom_log (LOG_INFO, "MiCASAKeys::MiCASAReadKey library not loaded.");
return NSSCS_E_SERVICE_NOT_FOUND;
}
}

View File

@@ -0,0 +1,112 @@
/***********************************************************************
*
* 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 _MICASA_KEYS_H_
#define _MICASA_KEYS_H_
#include "IMiCASAKeys.h"
#include <micasa.h>
#define MICASA_KEYS_CONTRACTID "@novell.com/CASA/MiCASAKeys;1"
#define MICASA_KEYS_CLASSNAME "Common Authentication Services Adapter"
// {287249D7-A851-4aa4-9AEE-5BCDA3B53566}
#define MICASA_KEYS_CID { 0x287249d7, 0xa851, 0x4aa4, { 0x9a, 0xee, 0x5b, 0xcd, 0xa3, 0xb5, 0x35, 0x66 } }
// External prototypes not yet in micasa.h
typedef
void *
(*PCASAOPEN)(
SSCS_SECRETSTORE_T * ssid,
unsigned long ssFlags,
SSCS_EXT_T * ext
);
typedef
int
(*PCASACLOSE)(
void * context,
unsigned long ssFlags,
SSCS_EXT_T * ext
);
typedef
int
(*PCASAWRITEKEY)(
void * context,
uint32_t ssFlags,
SSCS_KEYCHAIN_ID_T * keyChainID,
SSCS_SECRET_ID_T * sharedSecretID,
SS_UTF8_T * key,
uint32_t keyLen,
uint8_t * val,
uint32_t valLen,
SSCS_PASSWORD_T * epPassword,
SSCS_EXT_T * ext
);
typedef
int
(*PCASAREADKEY)(
void * context,
uint32_t ssFlags,
SSCS_KEYCHAIN_ID_T * keyChainID,
SSCS_SECRET_ID_T * sharedSecretID,
SS_UTF8_T * key,
uint32_t keyLen,
uint8_t * val,
uint32_t * valLen,
SSCS_PASSWORD_T * epPassword,
uint32_t * bytesRequired,
SSCS_EXT_T * ext
);
typedef void * HANDLE;
#define TRUE 1
#define FALSE 0
/* Header file */
class MiCASAKeys : public IMiCASAKeys
{
public:
NS_DECL_ISUPPORTS
NS_DECL_IMICASAKEYS
MiCASAKeys();
private:
~MiCASAKeys();
void * m_hCASALibrary;
int m_bLibraryLoaded;
PCASAOPEN m_pCASAOpen;
PCASACLOSE m_pCASAClose;
PCASAWRITEKEY m_pCASAWriteKey;
PCASAREADKEY m_pCASAReadKey;
protected:
/* additional members */
};
#endif //_MICASA_KEYS_H_

View File

@@ -0,0 +1,39 @@
/***********************************************************************
*
* 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.
*
***********************************************************************/
#include "nsIGenericFactory.h"
#include "MiCASAKeys.h"
NS_GENERIC_FACTORY_CONSTRUCTOR(MiCASAKeys)
static nsModuleComponentInfo components[] =
{
{
MICASA_KEYS_CLASSNAME,
MICASA_KEYS_CID,
MICASA_KEYS_CONTRACTID,
MiCASAKeysConstructor,
}
};
NS_IMPL_NSGETMODULE("MiCASAModule", components)