Fixes issue with Outlook COM server arguments and implements logger level for the native logger.

fix-message-formatting 5212
hristoterezov 12 years ago
parent d9917f1e79
commit f264230de7

@ -10,13 +10,15 @@
#define LOGGER_DATE_STRING_LENGTH 25
/**
* Constructs new Logger object.
* @param pLogFile the filename of the log file.
* @param pLogPath the path of the log file.
*/
Logger::Logger(const char* pLogFile, const char* pLogPath)
Logger::Logger(const char* pLogFile, const char* pLogPath, int pLogLevel)
{
logLevel = pLogLevel;
canWriteInFile = false;
if(pLogPath != NULL && strlen(pLogPath) != 0)
{
@ -87,7 +89,23 @@ void Logger::getCurrentTimeString(char* dateString)
*/
void Logger::log(const char* message)
{
if(canWriteInFile)
if(canWriteInFile && logLevel >= LOGGER_LEVEL_TRACE)
{
char *dateString = (char*)malloc(LOGGER_DATE_STRING_LENGTH*sizeof(char));
getCurrentTimeString(dateString);
fprintf(file, "%s %s: %s\n",dateString, getCurrentFile(), message);
fflush(file);
free(dateString);
}
}
/**
* Logs a message
* @param message the message.
*/
void Logger::logInfo(const char* message)
{
if(canWriteInFile && logLevel >= LOGGER_LEVEL_INFO )
{
char *dateString = (char*)malloc(LOGGER_DATE_STRING_LENGTH*sizeof(char));
getCurrentTimeString(dateString);
@ -105,4 +123,12 @@ char* Logger::getLogPath()
return logPath;
}
/**
* Returns the current log level.
*/
int Logger::getLogLevel()
{
return logLevel;
}

@ -9,6 +9,9 @@
#include <stdio.h>
#define LOGGER_LEVEL_INFO 0
#define LOGGER_LEVEL_TRACE 1
/**
* Utility class for logging messages in file.
*/
@ -34,6 +37,11 @@ class Logger
*/
bool canWriteInFile;
/**
* Current log level.
**/
int logLevel;
/**
* Returns current timestamp string.
*/
@ -49,8 +57,9 @@ public:
* Constructs new Logger object.
* @param pLogFile the filename of the log file.
* @param pLogPath the path of the log file.
* @param pLogLevel the current log level
*/
Logger(const char* pLogFile, const char* pLogPath);
Logger(const char* pLogFile, const char* pLogPath, int pLogLevel);
/**
* Destructor.
@ -63,10 +72,21 @@ public:
*/
void log(const char* message);
/**
* Logs a message
* @param message the message.
*/
void logInfo(const char* message);
/**
* Returns the path of the log file.
*/
char* getLogPath();
/**
* Returns the current log level.
*/
int getLogLevel();
};
#endif

@ -68,7 +68,7 @@ HRESULT MsOutlookAddrBookContactSourceService_MAPIInitialize
255 // The size limit of key name as documented in MSDN
+ 20 // \Outlook\InstallRoot
+ 1]; // The terminating null character
MsOutlookUtils_log("Searching for outlook InstallRoot.");
MsOutlookUtils_logInfo("Searching for outlook InstallRoot.");
while (1)
{
LONG regEnumKeyEx;
@ -89,14 +89,14 @@ HRESULT MsOutlookAddrBookContactSourceService_MAPIInitialize
NULL);
if (ERROR_NO_MORE_ITEMS == regEnumKeyEx)
{
MsOutlookUtils_log("No more Software\\Microsoft\\Office items.");
MsOutlookUtils_logInfo("No more Software\\Microsoft\\Office items.");
break;
}
i++;
if (ERROR_SUCCESS != regEnumKeyEx)
{
MsOutlookUtils_log("Error quering the next Software\\Microsoft\\Office item.");
MsOutlookUtils_logInfo("Error quering the next Software\\Microsoft\\Office item.");
continue;
}
@ -113,7 +113,7 @@ HRESULT MsOutlookAddrBookContactSourceService_MAPIInitialize
KEY_QUERY_VALUE,
&installRootKey))
{
MsOutlookUtils_log("The key is opened successfully.");
MsOutlookUtils_logInfo("The key is opened successfully.");
if ((ERROR_SUCCESS
== RegQueryValueEx(
installRootKey,
@ -125,7 +125,7 @@ HRESULT MsOutlookAddrBookContactSourceService_MAPIInitialize
&& (REG_SZ == pathValueType)
&& pathValueSize)
{
MsOutlookUtils_log("Path value found.");
MsOutlookUtils_logInfo("Path value found.");
LPTSTR pathValue;
// MSDN says "the string may not have been stored with the
@ -142,7 +142,7 @@ HRESULT MsOutlookAddrBookContactSourceService_MAPIInitialize
pathValue = (LPTSTR)::malloc(pathValueSize);
if (!pathValue)
{
MsOutlookUtils_log("Error with memory allocation for the pathValue.");
MsOutlookUtils_logInfo("Error with memory allocation for the pathValue.");
continue;
}
}
@ -155,12 +155,12 @@ HRESULT MsOutlookAddrBookContactSourceService_MAPIInitialize
NULL,
(LPBYTE) pathValue, &pathValueSize))
{
MsOutlookUtils_log("The path value is retrieved");
MsOutlookUtils_logInfo("The path value is retrieved");
DWORD pathValueLength = pathValueSize / sizeof(TCHAR);
if (pathValueLength)
{
MsOutlookUtils_log("The path value is retrieved successfully. The length is not 0.");
MsOutlookUtils_logInfo("The path value is retrieved successfully. The length is not 0.");
DWORD fileAttributes;
str = pathValue + (pathValueLength - 1);
@ -168,27 +168,27 @@ HRESULT MsOutlookAddrBookContactSourceService_MAPIInitialize
str++;
memcpy(str, _T("\\Outlook.exe"), 12 * sizeof(TCHAR));
*(str + 12) = 0;
MsOutlookUtils_log("Trying to retrieve atributes for:");
MsOutlookUtils_log(pathValue);
MsOutlookUtils_logInfo("Trying to retrieve atributes for:");
MsOutlookUtils_logInfo(pathValue);
fileAttributes = GetFileAttributes(pathValue);
if (INVALID_FILE_ATTRIBUTES != fileAttributes)
{
MsOutlookUtils_log("The file exists.");
MsOutlookUtils_logInfo("The file exists.");
hResult = S_OK;
}
else
{
MsOutlookUtils_log("The file doesn't exists");
MsOutlookUtils_logInfo("The file doesn't exists");
}
}
else
{
MsOutlookUtils_log("Error - the length of the path value is 0.");
MsOutlookUtils_logInfo("Error - the length of the path value is 0.");
}
}
else
{
MsOutlookUtils_log("Error retrieving the pathValue.");
MsOutlookUtils_logInfo("Error retrieving the pathValue.");
}
if (pathValue != installRootKeyName)
@ -196,13 +196,13 @@ HRESULT MsOutlookAddrBookContactSourceService_MAPIInitialize
}
else
{
MsOutlookUtils_log("Error Path value not found.");
MsOutlookUtils_logInfo("Error Path value not found.");
}
RegCloseKey(installRootKey);
}
else
{
MsOutlookUtils_log("Error openning the key.");
MsOutlookUtils_logInfo("Error openning the key.");
}
}
RegCloseKey(regKey);
@ -212,7 +212,7 @@ HRESULT MsOutlookAddrBookContactSourceService_MAPIInitialize
// client.
if (HR_SUCCEEDED(hResult))
{
MsOutlookUtils_log("Outlook is installed and we are checking if it is default mail client.");
MsOutlookUtils_logInfo("Outlook is installed and we are checking if it is default mail client.");
DWORD defaultValueType;
// The buffer installRootKeyName is long enough to receive
// "Microsoft Outlook" so use it in order to not have to allocate
@ -230,7 +230,7 @@ HRESULT MsOutlookAddrBookContactSourceService_MAPIInitialize
KEY_QUERY_VALUE,
&regKey))
{
MsOutlookUtils_log("HKCU\\Software\\Clients\\Mail exists.");
MsOutlookUtils_logInfo("HKCU\\Software\\Clients\\Mail exists.");
DWORD defaultValueSize = defaultValueCapacity;
LONG regQueryValueEx = RegQueryValueEx(
regKey,
@ -244,7 +244,7 @@ HRESULT MsOutlookAddrBookContactSourceService_MAPIInitialize
{
case ERROR_SUCCESS:
{
MsOutlookUtils_log("Successfull retrieve the default value of HKCU\\Software\\Clients\\Mail .");
MsOutlookUtils_logInfo("Successfull retrieve the default value of HKCU\\Software\\Clients\\Mail .");
if (REG_SZ == defaultValueType)
{
DWORD defaultValueLength
@ -255,45 +255,45 @@ HRESULT MsOutlookAddrBookContactSourceService_MAPIInitialize
defaultValue,
defaultValueLength))
{
MsOutlookUtils_log("The default value of HKCU\\Software\\Clients\\Mail is valid default mail client.");
MsOutlookUtils_logInfo("The default value of HKCU\\Software\\Clients\\Mail is valid default mail client.");
checkHKeyLocalMachine = JNI_FALSE;
if (_tcsnicmp(
_T("Microsoft Outlook"), defaultValue,
defaultValueLength)
== 0)
{
MsOutlookUtils_log("The default value of HKCU\\Software\\Clients\\Mail is Microsoft Office .");
MsOutlookUtils_logInfo("The default value of HKCU\\Software\\Clients\\Mail is Microsoft Office .");
hResult = S_OK;
}
else
{
MsOutlookUtils_log("The default value of HKCU\\Software\\Clients\\Mail is not Microsoft Office .");
MsOutlookUtils_log(defaultValue);
MsOutlookUtils_logInfo("The default value of HKCU\\Software\\Clients\\Mail is not Microsoft Office .");
MsOutlookUtils_logInfo(defaultValue);
}
}
else
{
MsOutlookUtils_log("Not valid default mail client for the default value of HKCU\\Software\\Clients\\Mail .");
MsOutlookUtils_logInfo("Not valid default mail client for the default value of HKCU\\Software\\Clients\\Mail .");
checkHKeyLocalMachine = JNI_TRUE;
}
}
else
{
MsOutlookUtils_log("Wrong type for the default value of HKCU\\Software\\Clients\\Mail .");
MsOutlookUtils_logInfo("Wrong type for the default value of HKCU\\Software\\Clients\\Mail .");
checkHKeyLocalMachine = JNI_FALSE;
}
break;
}
case ERROR_FILE_NOT_FOUND:
MsOutlookUtils_log("Failed to retrieve the default value of HKCU\\Software\\Clients\\Mail . ERROR_FILE_NOT_FOUND");
MsOutlookUtils_logInfo("Failed to retrieve the default value of HKCU\\Software\\Clients\\Mail . ERROR_FILE_NOT_FOUND");
checkHKeyLocalMachine = JNI_TRUE;
break;
case ERROR_MORE_DATA:
MsOutlookUtils_log("Failed to retrieve the default value of HKCU\\Software\\Clients\\Mail . ERROR_MORE_DATA");
MsOutlookUtils_logInfo("Failed to retrieve the default value of HKCU\\Software\\Clients\\Mail . ERROR_MORE_DATA");
checkHKeyLocalMachine = JNI_FALSE;
break;
default:
MsOutlookUtils_log("Failed to retrieve the default value of HKCU\\Software\\Clients\\Mail . Unknown error.");
MsOutlookUtils_logInfo("Failed to retrieve the default value of HKCU\\Software\\Clients\\Mail . Unknown error.");
checkHKeyLocalMachine = JNI_FALSE;
break;
}
@ -301,7 +301,7 @@ HRESULT MsOutlookAddrBookContactSourceService_MAPIInitialize
}
else
{
MsOutlookUtils_log("Failed to open HKCU\\Software\\Clients\\Mail .");
MsOutlookUtils_logInfo("Failed to open HKCU\\Software\\Clients\\Mail .");
checkHKeyLocalMachine = JNI_TRUE;
}
if ((JNI_TRUE == checkHKeyLocalMachine)
@ -313,7 +313,7 @@ HRESULT MsOutlookAddrBookContactSourceService_MAPIInitialize
KEY_QUERY_VALUE,
&regKey)))
{
MsOutlookUtils_log("HKLM\\Software\\Clients\\Mail exists.");
MsOutlookUtils_logInfo("HKLM\\Software\\Clients\\Mail exists.");
DWORD defaultValueSize = defaultValueCapacity;
LONG regQueryValueEx
= RegQueryValueEx(
@ -327,7 +327,7 @@ HRESULT MsOutlookAddrBookContactSourceService_MAPIInitialize
&& (REG_SZ == defaultValueType))
{
DWORD defaultValueLength = defaultValueSize / sizeof(TCHAR);
MsOutlookUtils_log("The default value of HKLM\\Software\\Clients\\Mail is retrieved .");
MsOutlookUtils_logInfo("The default value of HKLM\\Software\\Clients\\Mail is retrieved .");
if ((_tcsnicmp(
_T("Microsoft Outlook"), defaultValue,
@ -336,47 +336,47 @@ HRESULT MsOutlookAddrBookContactSourceService_MAPIInitialize
&& (JNI_TRUE
== MsOutlookAddrBookContactSourceService_isValidDefaultMailClient(_T("Microsoft Outlook"), 17)))
{
MsOutlookUtils_log("The default value of HKLM\\Software\\Clients\\Mail is Microsoft Office .");
MsOutlookUtils_logInfo("The default value of HKLM\\Software\\Clients\\Mail is Microsoft Office .");
hResult = S_OK;
}
else
{
MsOutlookUtils_log("The default value of HKLM\\Software\\Clients\\Mail is not Microsoft Office .");
MsOutlookUtils_log(defaultValue);
MsOutlookUtils_logInfo("The default value of HKLM\\Software\\Clients\\Mail is not Microsoft Office .");
MsOutlookUtils_logInfo(defaultValue);
}
}
else
{
MsOutlookUtils_log("Failed to retrieve the default value of HKLM\\Software\\Clients\\Mail .");
MsOutlookUtils_logInfo("Failed to retrieve the default value of HKLM\\Software\\Clients\\Mail .");
}
RegCloseKey(regKey);
}
else
{
MsOutlookUtils_log("HKLM\\Software\\Clients\\Mail doesn't exists.");
MsOutlookUtils_logInfo("HKLM\\Software\\Clients\\Mail doesn't exists.");
}
}
else
{
MsOutlookUtils_log("Outlook is not installed.");
MsOutlookUtils_logInfo("Outlook is not installed.");
}
}
else
{
MsOutlookUtils_log("Error opening HKLM\\Software\\Microsoft\\Office registry.");
MsOutlookUtils_logInfo("Error opening HKLM\\Software\\Microsoft\\Office registry.");
}
// If we've determined that we'd like to go on with MAPI, try to load it.
if (HR_SUCCEEDED(hResult))
{
MsOutlookUtils_log("Loading MAPI.");
MsOutlookUtils_logInfo("Loading MAPI.");
MsOutlookAddrBookContactSourceService_hMapiLib
= ::LoadLibrary(_T("mapi32.dll"));
hResult = MAPI_E_NO_SUPPORT;
if(MsOutlookAddrBookContactSourceService_hMapiLib)
{
MsOutlookUtils_log("Loading MAPI functions");
MsOutlookUtils_logInfo("Loading MAPI functions");
// get and check function pointers
MsOutlookAddrBookContactSourceService_mapiInitialize
= (LPMAPIINITIALIZE) GetProcAddress(
@ -491,6 +491,7 @@ HRESULT MsOutlookAddrBookContactSourceService_MAPIInitialize
if(HR_SUCCEEDED(hResult)
&& MAPISession_getMapiSession() == NULL)
{
MsOutlookUtils_logInfo("MAPI logon.");
LPMAPISESSION mapiSession = NULL;
hResult = MsOutlookAddrBook_mapiLogonEx(
0,
@ -501,11 +502,20 @@ HRESULT MsOutlookAddrBookContactSourceService_MAPIInitialize
&mapiSession);
if(HR_SUCCEEDED(hResult))
{
MsOutlookUtils_logInfo("MAPI logon success.");
// Register the notification of contact changed,
// created and deleted.
MAPINotification_registerNotifyAllMsgStores(
mapiSession);
}
else
{
MsOutlookUtils_logInfo("MAPI logon error.");
}
}
else
{
MsOutlookUtils_logInfo("Error calling MAPI init from MAPI library.");
}
::SetCurrentDirectory(lpszWorkingDir);
MAPISession_unlock();
@ -513,6 +523,7 @@ HRESULT MsOutlookAddrBookContactSourceService_MAPIInitialize
else
{
hResult = HRESULT_FROM_WIN32(::GetLastError());
MsOutlookUtils_logInfo("Error getting current directory.[1]");
}
::free(lpszWorkingDir);
@ -520,21 +531,30 @@ HRESULT MsOutlookAddrBookContactSourceService_MAPIInitialize
else
{
hResult = HRESULT_FROM_WIN32(::GetLastError());
MsOutlookUtils_logInfo("Error getting current directory.[2]");
}
}
else
{
MsOutlookUtils_logInfo("Cannot get MAPI functions.");
}
}
else
{
MsOutlookUtils_logInfo("Error while loading MAPI library.");
}
}
else
{
MsOutlookUtils_log("ERROR - we won't load MAPI.");
MsOutlookUtils_logInfo("ERROR - we won't load MAPI.");
}
if (HR_FAILED(hResult))
{
MsOutlookUtils_log("ERROR - in MAPI native init.");
MsOutlookUtils_logInfo("ERROR - in MAPI native init.");
if(MsOutlookAddrBookContactSourceService_hMapiLib)
{
MsOutlookUtils_log("ERROR - free MAPI library.");
MsOutlookUtils_logInfo("ERROR - free MAPI library.");
FreeLibrary(MsOutlookAddrBookContactSourceService_hMapiLib);
MsOutlookAddrBookContactSourceService_hMapiLib = NULL;
}
@ -641,7 +661,7 @@ HRESULT MsOutlookAddrBookContactSourceService_NativeMAPIInitialize
(jlong version, jlong flags,
void * deletedMethod, void * insertedMethod, void * updatedMethod)
{
MsOutlookUtils_log("MAPI native init.");
MsOutlookUtils_logInfo("MAPI native init.");
MAPINotification_registerNativeNotificationsDelegate(
deletedMethod, insertedMethod, updatedMethod);
@ -660,7 +680,7 @@ MsOutlookAddrBookContactSourceService_isValidDefaultMailClient
(LPCTSTR name, DWORD nameLength)
{
jboolean validDefaultMailClient = JNI_FALSE;
MsOutlookUtils_log("We are validating the default mail client.");
MsOutlookUtils_logInfo("We are validating the default mail client.");
if ((0 != nameLength) && (0 != name[0]))
{
LPTSTR str;
@ -678,8 +698,8 @@ MsOutlookAddrBookContactSourceService_isValidDefaultMailClient
_tcsncpy(str, name, nameLength);
*(str + nameLength) = 0;
MsOutlookUtils_log("We are searching in HKLM for the key");
MsOutlookUtils_log(keyName);
MsOutlookUtils_logInfo("We are searching in HKLM for the key");
MsOutlookUtils_logInfo(keyName);
if (ERROR_SUCCESS
== RegOpenKeyEx(
HKEY_LOCAL_MACHINE,
@ -688,13 +708,13 @@ MsOutlookAddrBookContactSourceService_isValidDefaultMailClient
KEY_QUERY_VALUE,
&key))
{
MsOutlookUtils_log("The key is found");
MsOutlookUtils_logInfo("The key is found");
validDefaultMailClient = JNI_TRUE;
RegCloseKey(key);
}
else
{
MsOutlookUtils_log("The key for default mail client is not found");
MsOutlookUtils_logInfo("The key for default mail client is not found");
}
}
return validDefaultMailClient;
@ -736,17 +756,36 @@ HRESULT MsOutlookAddrBookContactSourceService_startComServer(void)
int loggerPathLenght = 0;
char* comServerWithLogger;
char* appNameWithLogger;
char* loggerPathEscaped = NULL;
if(loggerPath != NULL)
{
loggerPathLenght = strlen(loggerPath);
int loggerLevel = MsOutlookUtils_getLoggerLevel();
char* loggerPathEscaped = (char* ) malloc(strlen(loggerPath) *
sizeof(char) * 2);
int i = 0;
while(*loggerPath != '\0')
{
*(loggerPathEscaped + i) = *loggerPath;
i++;
if(*loggerPath == '\\')
{
*(loggerPathEscaped + i) = '\\';
i++;
}
loggerPath++;
}
*(loggerPathEscaped + i) = '\0';
loggerPathLenght = strlen(loggerPathEscaped);
comServerWithLogger
= (char*) malloc(
(FILENAME_MAX + loggerPathLenght) * sizeof(char));
appNameWithLogger
= (char*) malloc(
(FILENAME_MAX + loggerPathLenght) * sizeof(char));
sprintf(comServerWithLogger, "%s \"%s\"", comServer, loggerPath);
sprintf(appNameWithLogger, "%s \"%s\"", applicationName, loggerPath);
sprintf(comServerWithLogger, "%s \"%s\" %d", comServer,
loggerPathEscaped, loggerLevel);
sprintf(appNameWithLogger, "%s \"%s\" %d", applicationName
, loggerPathEscaped, loggerLevel);
}
else
{
@ -769,13 +808,14 @@ HRESULT MsOutlookAddrBookContactSourceService_startComServer(void)
{
MsOutlookAddrBookContactSourceService_comServerHandle
= processInfo.hProcess;
MsOutlookUtils_log("COM Server started successful.[1]");
MsOutlookUtils_logInfo(serverExec[i]);
MsOutlookUtils_logInfo("COM Server started successful.[1]");
if(loggerPath != NULL)
{
free(comServerWithLogger);
free(appNameWithLogger);
}
MsOutlookUtils_log("COM Server started successful.[2]");
MsOutlookUtils_logInfo("COM Server started successful.[2]");
return S_OK;
}
}
@ -783,6 +823,7 @@ HRESULT MsOutlookAddrBookContactSourceService_startComServer(void)
{
free(comServerWithLogger);
free(appNameWithLogger);
free(loggerPathEscaped);
}
}

@ -405,9 +405,10 @@ MsOutlookUtils_IMAPIProp_GetProps(
return javaProps;
}
void MsOutlookUtils_createLogger(const char* logFile, const char* logPath)
void MsOutlookUtils_createLogger(const char* logFile, const char* logPath,
int logLevel)
{
logger = new Logger(logFile, logPath);
logger = new Logger(logFile, logPath, logLevel);
}
void MsOutlookUtils_log(const char* message)
@ -416,6 +417,11 @@ void MsOutlookUtils_log(const char* message)
logger->log(message);
}
void MsOutlookUtils_logInfo(const char* message)
{
if(logger != NULL)
logger->logInfo(message);
}
void MsOutlookUtils_deleteLogger()
{
@ -429,3 +435,10 @@ char* MsOutlookUtils_getLoggerPath()
return logger->getLogPath();
return NULL;
}
int MsOutlookUtils_getLoggerLevel()
{
if(logger != NULL)
return logger->getLogLevel();
return 0;
}

@ -10,14 +10,19 @@
#include <mapidefs.h>
#include <jni.h>
void MsOutlookUtils_createLogger(const char* logFile, const char* logPath);
void MsOutlookUtils_createLogger(const char* logFile, const char* logPath,
int logLevel);
void MsOutlookUtils_log(const char* message);
void MsOutlookUtils_logInfo(const char* message);
void MsOutlookUtils_deleteLogger();
char* MsOutlookUtils_getLoggerPath();
int MsOutlookUtils_getLoggerLevel();
HRESULT
MsOutlookUtils_getFolderEntryIDByType
(LPMDB msgStore,

@ -16,6 +16,7 @@
#include <stdio.h>
#include <string.h>
#include <TlHelp32.h>
#include <stdlib.h>
#define MAPI_NO_COINIT 8
@ -32,18 +33,25 @@ int main(int argc, char** argv)
HRESULT hr = E_FAIL;
if(argc > 1)
if(argc > 2)
{
char* path = argv[1];
*(path + strlen(path) - 1) = '\\';
MsOutlookUtils_createLogger("msoutlookaddrbook_server.log", path);
int loggerLevel = 0;
char* loggerLevelString = argv[2];
loggerLevel = atoi(loggerLevelString);
MsOutlookUtils_createLogger("msoutlookaddrbook_server.log", path,
loggerLevel);
}
MsOutlookUtils_log("Starting the Outlook Server.");
MsOutlookUtils_logInfo(argv[1]);
MsOutlookUtils_logInfo(argv[2]);
MsOutlookUtils_logInfo("Starting the Outlook Server.");
MsOutlookUtils_log("Test");
if((hr = ::CoInitializeEx(NULL, COINIT_MULTITHREADED)) != S_OK
&& hr != S_FALSE)
{
MsOutlookUtils_log("Error in initialization of the Outlook Server.[1]");
MsOutlookUtils_logInfo("Error in initialization of the Outlook Server.[1]");
return hr;
}
MAPISession_initLock();
@ -55,7 +63,7 @@ int main(int argc, char** argv)
(void*) Server_updated)
!= S_OK)
{
MsOutlookUtils_log("Error in native MAPI initialization of the Outlook Server.[2]");
MsOutlookUtils_logInfo("Error in native MAPI initialization of the Outlook Server.[2]");
CoUninitialize();
return hr;
}
@ -65,18 +73,18 @@ int main(int argc, char** argv)
if(typeLib != NULL)
{
MsOutlookUtils_log("TLB initialized.");
MsOutlookUtils_logInfo("TLB initialized.");
ClassFactory *classObject = new MsOutlookAddrBookServerClassFactory();
if(classObject != NULL)
{
MsOutlookUtils_log("Server object created.");
MsOutlookUtils_logInfo("Server object created.");
hr = classObject->registerClassObject();
hr = ::CoResumeClassObjects();
MsOutlookUtils_log("Server started.");
MsOutlookUtils_logInfo("Server started.");
waitParentProcessStop();
MsOutlookUtils_log("Stop waiting.[3]");
MsOutlookUtils_logInfo("Stop waiting.[3]");
hr = ::CoSuspendClassObjects();
hr = classObject->revokeClassObject();
@ -84,13 +92,13 @@ int main(int argc, char** argv)
}
else
{
MsOutlookUtils_log("Error - server object can't be created.");
MsOutlookUtils_logInfo("Error - server object can't be created.");
}
TypeLib_releaseTypeLib(typeLib);
}
else
{
MsOutlookUtils_log("Error - TLB isn't initialized.");
MsOutlookUtils_logInfo("Error - TLB isn't initialized.");
}
MsOutlookAddrBookContactSourceService_NativeMAPIUninitialize();
MsOutlookUtils_deleteLogger();

@ -17,7 +17,7 @@
JNIEXPORT void JNICALL
Java_net_java_sip_communicator_plugin_addrbook_msoutlook_MsOutlookAddrBookContactSourceService_MAPIInitialize
(JNIEnv *jniEnv, jclass clazz, jlong version, jlong flags,
jobject notificationsDelegate, jstring logPath)
jobject notificationsDelegate, jstring logPath, jint logLevel)
{
HRESULT hr;
@ -25,7 +25,7 @@ Java_net_java_sip_communicator_plugin_addrbook_msoutlook_MsOutlookAddrBookContac
jniEnv,
notificationsDelegate);
const char* logFileString = jniEnv->GetStringUTFChars(logPath, NULL);
MsOutlookUtils_createLogger("msoutlookaddrbook.log", logFileString);
MsOutlookUtils_createLogger("msoutlookaddrbook.log", logFileString, logLevel);
jniEnv->ReleaseStringUTFChars(logPath, logFileString);
hr = MsOutlookAddrBookContactSourceService_MAPIInitializeCOMServer();

@ -7,13 +7,14 @@
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: net_java_sip_communicator_plugin_addrbook_msoutlook_MsOutlookAddrBookContactSourceService
* Method: MAPIInitialize
* Signature: (JJLnet/java/sip/communicator/plugin/addrbook/msoutlook/MsOutlookAddrBookContactSourceService/NotificationsDelegate;Ljava/lang/String;)V
* Signature: (JJLnet/java/sip/communicator/plugin/addrbook/msoutlook/MsOutlookAddrBookContactSourceService/NotificationsDelegate;Ljava/lang/String;I)V
*/
JNIEXPORT void JNICALL Java_net_java_sip_communicator_plugin_addrbook_msoutlook_MsOutlookAddrBookContactSourceService_MAPIInitialize
(JNIEnv *, jclass, jlong, jlong, jobject, jstring);
(JNIEnv *, jclass, jlong, jlong, jobject, jstring, jint);
/*
* Class: net_java_sip_communicator_plugin_addrbook_msoutlook_MsOutlookAddrBookContactSourceService

@ -51,6 +51,10 @@ public class MsOutlookAddrBookContactSourceService
private static final long MAPI_INIT_VERSION = 0;
private static final long MAPI_MULTITHREAD_NOTIFICATIONS = 0x00000001;
private static final int NATIVE_LOGGER_LEVEL_INFO = 0;
private static final int NATIVE_LOGGER_LEVEL_TRACE = 1;
/**
* The thread used to collect the notifications.
@ -129,25 +133,31 @@ public static void initMAPI(NotificationsDelegate notificationDelegate)
if(!isMAPIInitialized)
{
String logFileName = "";
String homeLocation = System.getProperty(
"net.java.sip.communicator.SC_LOG_DIR_LOCATION");
String dirName = System.getProperty(
"net.java.sip.communicator.SC_HOME_DIR_NAME");
if(homeLocation != null && dirName != null)
{
logFileName = homeLocation + "\\" + dirName + "\\log\\";
}
int logLevel = NATIVE_LOGGER_LEVEL_INFO;
if(logger.isTraceEnabled())
{
String homeLocation = System.getProperty(
"net.java.sip.communicator.SC_LOG_DIR_LOCATION");
String dirName = System.getProperty(
"net.java.sip.communicator.SC_HOME_DIR_NAME");
if(homeLocation != null && dirName != null)
{
logFileName = homeLocation + "\\" + dirName
+ "\\log\\";
}
logLevel = NATIVE_LOGGER_LEVEL_TRACE;
}
logger.info("Init mapi with log level " + logLevel + " and log file"
+ " path " + logFileName);
MAPIInitialize(
MAPI_INIT_VERSION,
MAPI_MULTITHREAD_NOTIFICATIONS,
notificationDelegate,
logFileName);
logFileName,
logLevel);
isMAPIInitialized = true;
}
}
@ -191,7 +201,8 @@ private static native void MAPIInitialize(
long version,
long flags,
NotificationsDelegate callback,
String logFileName)
String logFileName,
int logLevel)
throws MsOutlookMAPIHResultException;
/**

Loading…
Cancel
Save