📄 addresschange.cpp
字号:
/*
* Copyright (C) 2003-2007 Funambol, Inc
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY, TITLE, NONINFRINGEMENT or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
* 02111-1307 USA
*/
#include "client/DMTClientConfig.h"
#include "spds/SyncManager.h"
#include "notify/checknet.h"
#include "notify/addresschange.h"
#include "notify/AddressChangeSyncSource.h"
#include "pim/utils.h"
#include "base/Log.h"
#include "notify/timed_msgbox.h"
#include "localizationUtils.h"
#ifdef WIN32_PLATFORM_WFSP
#include "funresourcesp.h"
#endif
#ifdef WIN32_PLATFORM_PSPC
#include "funresourceppc.h"
#endif
//------------------------------------------------------------ Config SubClass
// Address Notificator Configuration
//
// This class reads the same config used for DSClient from the DM,
// and changes some values for the address notification.
// The change to the url is now hard-coded.
//
class AddressChangeConfig : public DMTClientConfig {
public:
AddressChangeConfig(const char *context): DMTClientConfig(context) {}
bool set() {
// Read access config from DM
if( !read() )
return false;
// Replace SyncURL
char *url = new char[strlen(accessConfig.getSyncURL())+10];
strcpy(url, accessConfig.getSyncURL());
// Find the last part of the path
char *p = strrchr(url, '/');
if( !p )
return false;
strcpy(p, "/devinfo");
accessConfig.setSyncURL(url);
delete [] url;
// Discard source configs
if (sourceConfigs) {
delete [] sourceConfigs;
}
// Set AddressChangeSyncSource fixed config data
sourceConfigsCount = 1;
sourceConfigs = new SyncSourceConfig[1];
sourceConfigs[0].setName(ADDR_CHANGE_SOURCE_NAME);
sourceConfigs[0].setURI("");
sourceConfigs[0].setSync("addrchange");
sourceConfigs[0].setType("text/plain");
return true;
}
};
//----------------------------------------------------------- Public Functions
AN_ResponseCode notifyAddressChange(const wchar_t *context)
{
AN_ResponseCode code = AN_Unspecified ;
int ret = 0;
LogLevel l = getLOGLevel();
LOG.setLevel(l);
LOG.debug("notifyAddressChange START....");
if(!checkNetwork())
return AN_ServerUnreachable;
char *ctx = toMultibyte(context);
AddressChangeConfig config(ctx);
delete [] ctx;
config.set();
AddressChangeSyncSource source(TEXT(ADDR_CHANGE_SOURCE_NAME), config.getSyncSourceConfig(ADDR_CHANGE_SOURCE_NAME));
SyncReport sr;
sr.setSyncSourceReports(config);
source.setReport(sr.getSyncSourceReport(ADDR_CHANGE_SOURCE_NAME));
SyncSource** ssArray = new SyncSource*[2];
ssArray[0] = &source;
ssArray[1] = NULL;
if( config.set() ) {
LOG.debug("notifyAddressChange: config set\n");
SyncManager sm(config, sr);
ret = sm.prepareSync(ssArray);
if (ret) {
code = AN_AddressNotValid; // TODO: check status
if(ret == 401){
// display msgbox
TimedMessageBox(NULL, MSG_ERR_ADDRESSCHANGE_FAILED_CRED, getLocalizationUtils()->getLocalizationString(IDS_FUNAMBOL_ALERT),
MB_OK | MB_ICONWARNING | MB_SETFOREGROUND,
10000);
} else if (ret == 420){
LOG.error(MSG_ERR_ADDRESSCHANGE_FAILED_NOTIF);
}
LOG.debug("notifyAddressChange: prepareSync failed (%d: %s)",lastErrorCode, lastErrorMsg);
}
else {
code = AN_AddressAccepted; // Success
LOG.debug("notifyAddressChange: success\n");
}
}
else {
code = AN_InvalidConfig ;
LOG.debug("notifyAddressChange: config failed\n");
}
LOG.debug("notifyAddressChange END....");
delete [] ssArray;
return code;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -