⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 clientsettings.cpp

📁 funambol windows mobile plugin source code, the source code is taken from the funambol site
💻 CPP
📖 第 1 页 / 共 3 页
字号:
/*
 * 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 "pim/ClientSettings.h"
#include "spds/constants.h"
#include "spds/SyncReport.h"
#include "notify/checknet.h"
#include "customization.h"

#define PROPERTY_PUSH_NOTIFICATION      ("push")
#define PROPERTY_NOTIFICATION_PORT      ("pushPort")
#define PROPERTY_SMS_WAP_PUSH           ("sms")
#define PROPERTY_POLLING_NOTIFICATION   ("polling")
#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")


// to decide if the plug-in version is for portal or not
#define PROPERTY_IS_PORTAL              ("isPortal")

#define PROPERTY_ASK_USER               ("askUser")

//
// 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) {

        winSourceConfigs      = NULL;
        winSourceConfigsCount = 0;
        dirty = FALSE;
        mailssconfig = NULL;
}

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::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();
}

// 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;
}

/**
 * Read the custom parameters that are in the SyncclientPIM 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;

        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());

        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) {
        char buf[512];

        sprintf(buf, "%lu", deviceConfig.getLogLevel());
        node->setPropertyValue(PROPERTY_LOG_LEVEL, buf);
        node->setPropertyValue(PROPERTY_DEVINF_HASH, deviceConfig.getDevInfHash());

        delete node;
        node = NULL;
    }

    // read parameter of the client only

    node = dmt->readManagementNode(rootContext);
    if (node) {
        node->setPropertyValue(PROPERTY_PUSH_NOTIFICATION, getPush().data());
        node->setPropertyValue(PROPERTY_NOTIFICATION_PORT, getPushPort().data());
        node->setPropertyValue(PROPERTY_SMS_WAP_PUSH, getSms().data());
        node->setPropertyValue(PROPERTY_POLLING_NOTIFICATION, getPolling().data());
        node->setPropertyValue(PROPERTY_SERVER_NOTIFIED, getSvrNotified().data());
        node->setPropertyValue(PROPERTY_PATH, getPath().data());
        node->setPropertyValue(PROPERTY_CRADLE_NOTIFICATION, getCradleNotification().data());
        node->setPropertyValue(PROPERTY_ASK_USER, getAskUser().data());

        delete node;
        node = NULL;
    }

    close();
    return TRUE;

}

const char* ClientSettings::getConfigSourcesParameter(const char* sourceName, const char* parameter) {

    for (unsigned int i=0; i<winSourceConfigsCount; ++i) {
        if (strcmp(winSourceConfigs[i].getName(), sourceName) == 0) {
            if (strcmp(parameter, "sync") == 0) {
                return winSourceConfigs[i].getSync();
            }
            else if (strcmp(parameter, "encryption") == 0) {
                return winSourceConfigs[i].getEncryption();
            }
            else {
                return "to implement";
            }
        }
    }
    return "";
}


BOOL ClientSettings::setConfigSourcesParameter(const char* sourceName, const char* parameter, const char* value) {

    for (unsigned int i=0; i<winSourceConfigsCount; ++i) {
        if (strcmp(winSourceConfigs[i].getName(), sourceName) == 0) {
            if (strcmp(parameter, "sync") == 0) {
                winSourceConfigs[i].setSync(value);
            }
            else if (strcmp(parameter, "encryption") == 0) {
                winSourceConfigs[i].setEncryption(value);
            }
            return true;
        }
    }
    return false;
}



BOOL ClientSettings::saveSyncSourceConfig(const char* name) {

    int ret = 0;
    lastErrorCode = ERR_NONE;

    for (unsigned int i=0; i<winSourceConfigsCount; ++i) {

        if (strcmp(name, winSourceConfigs[i].getName()) == 0) {
            saveWinSourceConfig(i);
            break;
        }
    }
    ret = (lastErrorCode == ERR_NONE);

    return ret;
}

// method used to get the singleton instance
ClientSettings* getRegConfig(){
    return ClientSettings::getInstance();
}

int ClientSettings::getConfigSourcesLastTimestamp(const char* sourceName) {
    for (unsigned int i=0; i<sourceConfigsCount; ++i) {
        if (strcmp(sourceConfigs[i].getName(), sourceName) == 0) {
            return sourceConfigs[i].getLast();
        }
    }
    return 0;
}

// ------------------------- Read properties from win registry -------------------------
/**
* Read the configuration from Windows registry into this object.
* This method overrides 'DMTClientConfig::read()'.
* 'DMTClientConfig::read()' is first called to read all common properties, then
* specific SyncSource properties are retrieved.
*
* A separate 'winSourceConfigs' array is used to store all specific SS config, common
* props are linked to original 'sourceConfigs' array (no copy!).
*
* @return TRUE if no errors

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -