clientsettings.cpp
来自「funambol window mobile客户端源代码」· C++ 代码 · 共 1,830 行 · 第 1/4 页
CPP
1,830 行
/*
* Funambol is a mobile platform developed by Funambol, Inc.
* 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 Affero General Public License version 3 as published by
* the Free Software Foundation with the addition of the following permission
* added to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED
* WORK IN WHICH THE COPYRIGHT IS OWNED BY FUNAMBOL, FUNAMBOL DISCLAIMS THE
* WARRANTY OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program 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 General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program; if not, see http://www.gnu.org/licenses or write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA.
*
* You can contact Funambol, Inc. headquarters at 643 Bair Island Road, Suite
* 305, Redwood City, CA 94063, USA, or at email address info@funambol.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License
* version 3, these Appropriate Legal Notices must retain the display of the
* "Powered by Funambol" logo. If the display of the logo is not reasonably
* feasible for technical reasons, the Appropriate Legal Notices must display
* the words "Powered by Funambol".
*/
#include "vocl/WinItem.h"
#include "pim/ClientSettings.h"
#include "spds/constants.h"
#include "spds/SyncReport.h"
#include "notify/checknet.h"
#include "customization.h"
#include "base/stringUtils.h"
#include "pim/ConfigParams.h"
#define PROPERTY_NOTIFICATION_PORT ("pushPort")
#define PROPERTY_SMS_WAP_PUSH ("sms")
#define PROPERTY_SERVER_NOTIFIED ("svrNotified")
#define PROPERTY_SOURCE_USE_SIF ("useSIF")
#define PROPERTY_SOURCE_DIR ("dir")
#define PROPERTY_PATH ("path")
#define PROPERTY_SCHEDULE ("schedule")
#define PROPERTY_CRADLE_NOTIFICATION ("cradleNotif")
#define PROPERTY_CLIENT_PUSH_INTERVAL ("clientPushInterval")
#define PROPERTY_EMAIL_FILTER ("emailFilter")
#define PROPERTY_LAST_EMAIL_ADDRESS ("lastEmailAddress")
#define PROPERTY_LAST_EMAIL_VISIBLENAME ("lastEmailVisibleName")
#define PROPERTY_CONFIGSYNC_DIRTY ("configSyncDirty")
// to decide if the plug-in version is for portal or not
#define PROPERTY_IS_PORTAL ("isPortal")
#define PROPERTY_ASK_USER ("askUser")
#define PROPERTY_TO_SYNC_CONFIGURATION ("toSyncConfiguration") // 1 to sync, 0 don't sync
/**
* For the Update process
*/
#define CONTEXT_UPDATE "/Update"
#define UPDATE_VERSION "version"
#define UPDATE_MANDATORY "mandatory"
#define UPDATE_RELEASE_DATE "releaseDate"
#define UPDATE_URL_UPDATE "urlUpdate"
#define UPDATE_URL_COMMENT "urlComment"
#define UPDATE_SIZE "size"
#define UPDATE_LAST_CHECK_UPDATE "lastCheckUpdate"
#define UPDATE_INT_CHECK_UP_HTTP "intervalCheckUpdateHttp"
#define UPDATE_INT_REMIND "intervalRemind"
#define UPDATE_SKIPPED "skipped"
#define UPDATE_LAST_UPDATE "lastUpdated"
#define UPDATE_LATER "later"
#define UPDATE_NOW "now"
#define UPDATE_IS_AN_UPDATE_AVAILABLE "isUpdateAvailable"
/**
* For branding parameters. It is a context under Funambol/SyncClient
* The logic is boolean to choose to SHOW the corrispondend property (field, label...)
*/
#define CONTEXT_BRAND "/brand"
#define BRAND_URL_FIELD "showUrlField"
#define BRAND_NOTE_SOURCE "showNoteSource"
#define BRAND_BRIEFCASE_SOURCE "showBriefcaseSource"
#define BRAND_ADV_SETTING_MENU "showAdvSettingMenu"
//
// Init static pointer.
//
ClientSettings* ClientSettings::pinstance = NULL;
/*
* Method to get the sole instance
*/
ClientSettings* ClientSettings::getInstance() {
if (pinstance == NULL) {
// TODO: use #define
pinstance = new ClientSettings(ROOT_CONTEXT);
pinstance->read();
}
return pinstance;
}
ClientSettings::ClientSettings(const char* application_uri)
: DMTClientConfig(application_uri), updateParams(0) {
winSourceConfigs = NULL;
winSourceConfigsCount = 0;
dirty = FALSE;
mailssconfig = NULL;
configSyncDirty = 0;
}
ClientSettings::~ClientSettings() {
if (winSourceConfigs) {
delete [] winSourceConfigs;
winSourceConfigs = NULL;
}
if (mailssconfig) {
delete mailssconfig;
mailssconfig = NULL;
}
pinstance = NULL;
}
void ClientSettings::setIp(string extip) {
ipaddress = extip;
}
string ClientSettings::getIp() {
refreshIP();
return ipaddress;
}
void ClientSettings::setPush(string extpush) {
push = extpush;
}
string ClientSettings::getPush() {
return push;
}
void ClientSettings::setEmailFilter(string filter) {
emailFilter = filter;
}
string ClientSettings::getEmailFilter() {
return emailFilter;
}
void ClientSettings::setPushPost(string extpushPort) {
pushPort = extpushPort;
}
string ClientSettings::getPushPort() {
return pushPort;
}
void ClientSettings::setSms(string extsms){
sms = extsms;
}
string ClientSettings::getSms() {
return sms;
}
void ClientSettings::setPolling(string extpolling) {
polling = extpolling;
}
string ClientSettings::getPolling() {
return polling;
}
void ClientSettings::setSvrNotified(string extsvrNotified) {
svrNotified = extsvrNotified;
}
string ClientSettings::getSvrNotified() {
return svrNotified;
}
void ClientSettings::setPath(string extpath) {
path = extpath;
}
string ClientSettings::getPath() {
return path;
}
string ClientSettings::getAppPath(){
return getPath();
}
string ClientSettings::getClientPushInterval() {
return clientPushInterval;
}
void ClientSettings::setClientPushInterval(string extclientPushInterval) {
clientPushInterval = extclientPushInterval;
}
void ClientSettings::setToSyncConfiguration(string exttoSyncConfiguration) {
toSyncConfiguration = exttoSyncConfiguration;
}
string ClientSettings::getToSyncConfiguration() {
return toSyncConfiguration;
}
// for the sources
// TODO: to be removed all common source-related properties
// when they will be no longer used in the code, use instead the methods from WindowsSyncSourceConfig
void ClientSettings::setDir(string extdir) {
dir = extdir;
}
string ClientSettings::getDir() {
return dir;
}
void ClientSettings::setIsPortal(string extportal) {
isPortal = extportal;
}
bool ClientSettings::getIsPortal() {
return isPortal == "1" ? true : false;
}
void ClientSettings::setCradleNotification(string v) {
cradleNotif = v;
}
string ClientSettings::getCradleNotification() {
return cradleNotif;
}
void ClientSettings::setAskUser(string extaskUser){
askUser = extaskUser;
}
string ClientSettings::getAskUser() {
return askUser;
}
StringBuffer ClientSettings::encodePassword(const char* password) {
StringBuffer buffer("");
if (password && strlen(password) > 0) {
char* encoded = encryptData(password, PASS_KEY);
buffer = encoded;
}
return buffer;
}
char* ClientSettings::decodePassword(const char* password) {
char* decripted = NULL;
if (password && strlen(password) > 0) {
decripted = decryptData(password, PASS_KEY);
}
if (decripted == NULL || getLastErrorCode() == 801) {
decripted = new char[1];
decripted[0] = 0;
setError(ERR_NONE, getLastErrorMsg());
}
return decripted;
}
/**
* Read the custom parameters that are in the SyncClient node.
*
*/
bool ClientSettings::readConfig() {
bool ret = FALSE;
LOG.debug("ClientSettings: readConfig");
//
// Reading syncml node
//
if (!sourcesNode) {
if (!open()) {
return FALSE;
}
}
ManagementNode* node;
// read parameter of the client only
node = dmt->readManagementNode(rootContext);
if (node) {
char* tmp;
string t;
tmp = node->readPropertyValue(PROPERTY_PUSH_NOTIFICATION);
t = tmp;
setPush(t);
delete [] tmp;
tmp = node->readPropertyValue(PROPERTY_NOTIFICATION_PORT);
t = tmp;
setPushPost(t);
delete [] tmp;
tmp = node->readPropertyValue(PROPERTY_SMS_WAP_PUSH);
t = tmp;
setSms(t);
delete [] tmp;
tmp = node->readPropertyValue(PROPERTY_POLLING_NOTIFICATION);
t = tmp;
setPolling(t);
delete [] tmp;
tmp = node->readPropertyValue(PROPERTY_SERVER_NOTIFIED);
t = tmp;
setSvrNotified(t);
delete [] tmp;
tmp = node->readPropertyValue(PROPERTY_PATH);
t = tmp;
setPath(t);
delete [] tmp;
tmp = node->readPropertyValue(PROPERTY_IS_PORTAL);
t = tmp;
setIsPortal(t);
delete [] tmp;
tmp = node->readPropertyValue(PROPERTY_CRADLE_NOTIFICATION);
t = tmp;
setCradleNotification(t);
delete [] tmp;
tmp = node->readPropertyValue(PROPERTY_ASK_USER);
t = tmp;
setAskUser(t);
delete [] tmp;
tmp = node->readPropertyValue(PROPERTY_CLIENT_PUSH_INTERVAL);
t = tmp;
setClientPushInterval(t);
delete [] tmp;
tmp = node->readPropertyValue(PROPERTY_TO_SYNC_CONFIGURATION);
t = tmp;
setToSyncConfiguration(t);
delete [] tmp;
tmp = node->readPropertyValue(PROPERTY_EMAIL_FILTER);
t = tmp;
setEmailFilter(t);
delete [] tmp;
tmp = node->readPropertyValue(PROPERTY_LAST_EMAIL_ADDRESS);
t = tmp;
setLastEmailAdress(t);
delete [] tmp;
tmp = node->readPropertyValue(PROPERTY_LAST_EMAIL_VISIBLENAME);
t = tmp;
setLastEmailVisibleName(t);
delete [] tmp;
tmp = node->readPropertyValue(PROPERTY_CONFIGSYNC_DIRTY);
if (strlen(tmp)) {
configSyncDirty = atoi(tmp);
}
delete [] tmp;
delete node;
node = NULL;
}
return ret;
}
/**
* It saves only the parameter that can be changed by the configuration
* in the different Acc, Ext, Conn DevInfo nodes
* username/password in Auth
* syncURL in Conn
* log/encryption in Ext
*/
bool ClientSettings::saveConfig() {
ManagementNode* node;
char nodeName[DIM_MANAGEMENT_PATH];
if (!sourcesNode) {
open();
}
char syncMLContext[DIM_MANAGEMENT_PATH];
char* fn = syncMLNode->createFullName();
sprintf(syncMLContext, "%s", fn);
delete [] fn;
//
// Auth properties
//
sprintf(nodeName, "%s%s", syncMLContext, CONTEXT_AUTH);
node = dmt->readManagementNode(nodeName);
if (node) {
node->setPropertyValue(PROPERTY_USERNAME, accessConfig.getUsername());
//node->setPropertyValue(PROPERTY_PASSWORD, accessConfig.getPassword());
// modification of the password here
StringBuffer buffer = encodePassword(accessConfig.getPassword());
if (buffer == NULL) {
buffer = "";
}
node->setPropertyValue(PROPERTY_PASSWORD, buffer.c_str());
delete node;
node = NULL;
}
//
// DevInfo properties
//
sprintf(nodeName, "%s%s", syncMLContext, CONTEXT_DEV_INFO);
node = dmt->readManagementNode(nodeName);
if (node) {
node->setPropertyValue(PROPERTY_DEVICE_ID, deviceConfig.getDevID());
delete node;
node = NULL;
}
//
// Conn properties
//
sprintf(nodeName, "%s%s", syncMLContext, CONTEXT_CONN);
node = dmt->readManagementNode(nodeName);
if (node) {
node->setPropertyValue(PROPERTY_SYNC_URL, accessConfig.getSyncURL());
node->setPropertyValue(PROPERTY_ENABLE_COMPRESSION,accessConfig.getCompression() ? "1": "0" );
delete node;
node = NULL;
}
//
// Ext properties (other misc props)
//
sprintf(nodeName, "%s%s", syncMLContext, CONTEXT_EXT);
node = dmt->readManagementNode(nodeName);
if (node) {
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?