📄 startsync.cpp
字号:
wcscmp(command, PARAM_ADDRESSCHANGE) == 0 ||
wcscmp(command, PARAM_REGISTER) == 0 ||
wcscmp(command, PARAM_DEREGISTER) == 0 ||
wcscmp(command, PARAM_NOTIFY) == 0 ||
wcscmp(command, PARAM_TRANSPORT) == 0 ||
wcscmp(command, PARAM_INCLUSIVE) == 0 ||
wcscmp(command, PARAM_MANUAL) == 0 ||
wcscmp(command, PARAM_REFRESHSERVER) == 0 ||
wcscmp(command, PARAM_REFRESHCLIENT ) == 0 ||
wcscmp(command, PARAM_T_REFRESHSERVER) == 0 ||
wcscmp(command, PARAM_T_REFRESHCLIENT ) == 0 ||
wcscmp(command, c_szParams) == 0 ||
wcscmp(command, PARAM_TCPIP) == 0 ||
wcscmp(command, APP_RUN_AT_TIME) == 0
) ) {
quit(0);
}
/*
* These two following test are only to understand and make right
* modification. So the Cradle action is normalized and the RunAppAtTime
* currently only schedules the next time sync and leaves to the flow
* the right choice.
*/
if (wcsicmp(command, PARAM_NOTIFY) == 0 ){
//This if for the on cradle notification
delete [] command;
command = wstrdup(TEXT("cradle"));
//command = TEXT("cradle");
if (sources){
delete [] sources;
}
sources = NULL;
} else if(wcscmp(command, APP_RUN_AT_TIME) == 0 ){
LogLevel l = getLOGLevel();
LOG.setLevel(l);
schedule(false);
}
if(wcscmp(command, PARAM_AVAILABLE) == 0) {
getAvailability();
} else if(wcscmp(command, PARAM_REMOVENOTIF) == 0) {
removeNotif();
retValue = NOT_RETURN_TO_MAIN_FORM;
} else if(wcscmp(command, PARAM_SCHEDULE) == 0) {
LogLevel l = getLOGLevel();
LOG.setLevel(l);
schedule(true);
} else if (wcscmp(command, PARAM_ADDRESSCHANGE) == 0) {
LogLevel l = getLOGLevel();
LOG.setLevel(l);
notify((const wchar_t **)sources);
} else if(wcscmp(command, PARAM_REGISTER) == 0) {
WCHAR c_szPath[MAX_PATH];
getAppName(c_szPath); // /Program files/Funambol/startsync.exe
LogLevel l = getLOGLevel();
LOG.setLevel(l);
hr = PushRouter_RegisterClient(c_szContentType, c_szAppId, c_szPath, c_szParams);
if (hr == S_OK) {
LOG.debug("Wap push client registered successfully");
} else if (hr == PUSHRTR_E_ALREADYREGISTERED) {
LOG.debug("Wap push client already registered");
} else {
LOG.error("Error to register wap push client");
}
retValue = NOT_RETURN_TO_MAIN_FORM;
} else if(wcscmp(command, PARAM_DEREGISTER) == 0) {
//
// unregister the startsync from the pushrouter
//
hr = PushRouter_UnRegisterClient(c_szContentType, c_szAppId);
LogLevel l = getLOGLevel();
LOG.setLevel(l);
if (hr == S_OK) {
LOG.debug("Wap push client unregistered successfully");
} else if (hr == PUSHRTR_E_NOTFOUND) {
LOG.debug("Wap push client not found. Arleady unregistered");
} else {
LOG.error("Error to unregister wap push client");
}
retValue = NOT_RETURN_TO_MAIN_FORM;
} else if(wcscmp(command, c_szParams) == 0) {
LogLevel l = getLOGLevel();
LOG.setLevel(l);
memset(&PushMsg, 0, sizeof(PUSHMSG));
PushMsg.cbSize = sizeof(PUSHMSG);
hr = PushRouter_Open(c_szContentType, c_szAppId, &hevtMsgAvailable, &hPushRouter);
if (hr != S_OK) {
LOG.error("Wap push: PushRouter_Open - it is not possible to register the client.");
}
while(WaitForSingleObject(hevtMsgAvailable, 10000) != WAIT_TIMEOUT) {
hr = PushRouter_GetMessage(hPushRouter, &PushMsg);
if (hr != S_OK) {
LOG.error("Error in PushRouter_GetMessage wap push client");
break;
}
wchar_t** ss;
wchar_t** ws = NULL;
int ret = handleWapPushMessage(&PushMsg, &ws);
int i = 0;
int a = 0;
while(ws[i]){
char* srctocmp = toMultibyte(ws[i]);
if (!(strcmp(getRegConfig()->getConfigSourcesParameter(srctocmp, "sync"), "none") == 0)){
a++;
}
i++;
if (srctocmp){
delete [] srctocmp;
}
}
if(a != 0){
ss = new wchar_t*[a+1];
i = 0;
a = 0;
int sizews = 0;
while(ws[i]){
char* srctocmp = toMultibyte(ws[i]);
if (!(strcmp(getRegConfig()->getConfigSourcesParameter(srctocmp, "sync"), "none") == 0)){
sizews = wcslen(ws[i])+ 1;
ss[a] = new wchar_t[sizews];
wcscpy(ss[a], ws[i]);
a++;
}
if ( srctocmp ){
delete [] srctocmp;
}
i++;
}
ss[a] = 0;
}
else{
ss = NULL;
}
if (ret != 0) {
LOG.error("Wap push: error in handleWapPushMessage message");
break;
}
if (ss) {
if (askConfirm(ASK_WAP_PUSH)) {
#if _WIN32_WCE > 0x500
bool found = false;
int i = 0;
for (i = 0; ss[i]; i++) {
if (wcsstr(ss[i], L"mail") != 0) {
found = true;
}
}
if (found) {
setSourceOnReg(ss);
MailSyncMessages(PROVIDER_W, MCF_ACCOUNT_IS_NAME | MCF_RUN_IN_BACKGROUND);
return retValue = NOT_RETURN_TO_MAIN_FORM;
}
#endif
sync((const wchar_t **)ss);
}
}
PushRouter_FreeMessage(&PushMsg);
memset(&PushMsg, 0, sizeof(PUSHMSG));
PushMsg.cbSize = sizeof(PUSHMSG);
}
} else if (wcscmp(command, PARAM_INCLUSIVE) == 0) {
// just to know the number of ids
unsigned int i = 0;
for (i = 0; sources[i]; i++) {
// the position start from 0 [that is mail, the name of the source]
// [1], [2].. contains the ids
//
}
// the name of the source: it should be "mail"
wchar_t* mailSourceName = wstrdup(sources[0]);
// the buffer for the ids
const wchar_t ** ids = new const wchar_t*[i];
for (unsigned j = 0; j < i; j++) {
ids[j] = wstrdup(sources[j + 1]);
}
delete [] sources;
sources = new wchar_t* [2];
sources[0] = mailSourceName;
sources[1] = 0;
sync((const wchar_t **)sources, (const wchar_t **)ids);
} else if (wcscmp(command, PARAM_TRANSPORT) == 0 ||
wcscmp(command, PARAM_T_REFRESHSERVER) == 0 ||
wcscmp(command, PARAM_T_REFRESHCLIENT ) == 0) {
if (strcmp(getRegConfig()->getConfigSourcesParameter("mail", "sync"), "none") == 0) {
int ret = TimedMessageBox(NULL,
getLocalizationUtils()->getLocalizationString(IDS_MAIL_DISABLED),
getLocalizationUtils()->getLocalizationString(IDS_FUNAMBOL_ALERT),
MB_YESNO | MB_ICONQUESTION | MB_SETFOREGROUND, 10 * 1000);
if(ret == IDYES){
getRegConfig()->setConfigSourcesParameter( "mail" , "sync" , "two-way" );
getRegConfig()->setDirty(CS_DIRTY_SOURCE_ENABLED);
getRegConfig()->saveDirty();
} else {
return 1;
}
}
if( wcscmp(command, PARAM_T_REFRESHSERVER) == 0) {
if (sources == 0) { //////****************
LOG.error("%S call without sources", PARAM_T_REFRESHSERVER);
retValue = NOT_RETURN_TO_MAIN_FORM;
} else {
recover("refresh-from-server", (const wchar_t **)sources);
}
} else if (wcscmp(command, PARAM_T_REFRESHCLIENT ) == 0) {
if (sources == 0 ){ //////****************
LOG.error("%S call without sources", PARAM_T_REFRESHCLIENT);
retValue = NOT_RETURN_TO_MAIN_FORM;
} else {
recover("refresh-from-client", (const wchar_t **)sources);
}
} else if (sources) {
sync((const wchar_t **)sources);
} else if (!sources) {
LOG.error("Transport call without sources");
retValue = 0;
}
} else {
if (!sources) {
sources = getEnabledSourcesFromConfig();
if (!sources) {
LOG.error("No sources in the config are selected to be synced");
quit(1);
}
}
bool flagmail = false;
for(int i = 0; sources[i]; i++){
if (wcsicmp(sources[i], TEXT("mail")) == 0){
flagmail = true;
}
}
if(!flagmail) {
if (wcsicmp(command, TEXT("refresh-from-server")) == 0) {
if (sources == 0) {
quit(1);
}
recover("refresh-from-server", (const wchar_t **)sources);
} else if (wcscmp(command, TEXT("refresh-from-client")) == 0) {
if (sources == 0) {
quit(1);
}
recover("refresh-from-client", (const wchar_t **)sources);
} else { // manual parameter
sync((const wchar_t **)sources);
}
} else {
if (wcscmp(command, TEXT("refresh-from-server")) == 0 ||
wcscmp(command, TEXT("refresh-from-client")) == 0){
wstring value = TEXT("transport-");
value += command;
setValuesInRegistry(TEXT("transportCommand"), value.c_str());
}
setSourceOnReg(sources);
MailSyncMessages(PROVIDER_W, MCF_ACCOUNT_IS_NAME | MCF_RUN_IN_BACKGROUND);
return retValue = NOT_RETURN_TO_MAIN_FORM;
}
}
if (hPushRouter) {
PushRouter_Close(hPushRouter);
PushRouter_FreeMessage(&PushMsg);
}
PowerPolicyNotify(PPN_UNATTENDEDMODE, FALSE);
if (command){
delete [] command;
}
if (sources){
delete [] sources;
}
}//end try
catch (OutOfMemoryException& e) {
int k = e.getMemExcErrorCode();
if (k == -50) {
LOG.error("Low Storage Memory Exception.");
quit(k);
}
else if (k == -1) { // error due to Out of memory
LOG.error("Out of memory. Required %lu ", e.getMemExcMemoryRequired());
quit(-40);
} else { // error due to Out of memory. Not -1 set but supposed
LOG.error("Out of memory");
quit(-40);
}
}
catch (...) {
LOG.error("Generic failure");
quit(-2);
}
return retValue;
}
void setValuesInRegistry(const wchar_t* name, const wchar_t* value) {
HKEY key;
DWORD res;
int sizew = 0;
RegCreateKeyEx(
HKEY_LOCAL_MACHINE,
TEXT("Software\\") ROOT_CONTEXT_W,
0,
NULL,
REG_OPTION_NON_VOLATILE,
KEY_ALL_ACCESS,
NULL,
&key,
&res
);
if (key == 0) {
goto finally;
}
RegSetValueEx(
key,
name,
NULL,
REG_SZ, // we currently support only strings
(UCHAR*)value,
(wcslen(value)+1)*sizeof(WCHAR)
);
RegFlushKey(key);
finally:
if (key != 0) {
RegCloseKey(key);
}
}
/**
* Set a list of sources that has to be synced passing through
* the SyncMLTransport to take advantage of the mail notification.
* This is done only if the mail source is in the list of sources
* to be synced
*/
void setSourceOnReg(wchar_t** sources) {
wchar_t* value = NULL;
int sizew = 0;
for (int i = 0; sources[i]; i++ ){
sizew += wcslen (sources[i]) + 1;
}
value = new wchar_t[sizew];
for (int i = 0; sources[i]; i++ ){
if (i == 0){
wcscpy(value, sources[i]);
} else {
wcscat(value, TEXT(","));
wcscat(value, sources[i]);
}
}
setValuesInRegistry(TEXT("transportSources"), value);
if (value) {
delete [] value; value = NULL;
}
}
/**
* Read the enabled sources from the configuration and return an array null terminated
* with the names of the sources to be synced
*/
wchar_t** getEnabledSourcesFromConfig() {
int i = 0, count = 0;
wchar_t** sourcesfr = NULL;
if(!(strcmp(getRegConfig()->getConfigSourcesParameter("mail", "sync"), "none") == 0)) {
count++;
}
if(!(strcmp(getRegConfig()->getConfigSourcesParameter("contact", "sync"), "none") == 0)) {
count++;
}
if(!(strcmp(getRegConfig()->getConfigSourcesParameter("calendar", "sync"), "none") == 0)) {
count++;
}
if(!(strcmp(getRegConfig()->getConfigSourcesParameter("task", "sync"), "none") == 0)) {
count++;
}
if(!(strcmp(getRegConfig()->getConfigSourcesParameter("note", "sync"), "none") == 0)) {
count++;
}
if(!(strcmp(getRegConfig()->getConfigSourcesParameter("briefcase", "sync"), "none") == 0)) {
count++;
}
if (count == 0) {
return sourcesfr;
}
sourcesfr = new wchar_t*[count + 1];
if(!(strcmp(getRegConfig()->getConfigSourcesParameter("mail", "sync"), "none") == 0)){
sourcesfr[i] = wstrdup(TEXT("mail"));
i++;
}
if(!(strcmp(getRegConfig()->getConfigSourcesParameter("contact", "sync"), "none") == 0)){
sourcesfr[i] = wstrdup(TEXT("contact"));
i++;
}
if(!(strcmp(getRegConfig()->getConfigSourcesParameter("calendar", "sync"), "none") == 0)){
sourcesfr[i] = wstrdup(TEXT("calendar"));
i++;
}
if(!(strcmp(getRegConfig()->getConfigSourcesParameter("task", "sync"), "none") == 0)){
sourcesfr[i] = wstrdup(TEXT("task"));
i++;
}
if(!(strcmp(getRegConfig()->getConfigSourcesParameter("note", "sync"), "none") == 0)){
sourcesfr[i] = wstrdup(TEXT("note"));
i++;
}
if(!(strcmp(getRegConfig()->getConfigSourcesParameter("briefcase", "sync"), "none") == 0)){
sourcesfr[i] = wstrdup(TEXT("briefcase"));
i++;
}
sourcesfr[i] = 0;
return sourcesfr;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -