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

📄 ctpconfig.cpp

📁 funambol windows mobile plugin source code, the source code is taken from the funambol site
💻 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 "CTPConfig.h"     

#define CTP_QUEUE_PUSH      "queuePush"
#define CTP_RETRY           "ctpRetry"
#define CTP_MAX_RETRY_TIMEOUT "maxCtpRetry"
#define CTP_CMD_TIMEOUT     "ctpCmdTimeout"
#define CTP_CONN_TIMEOUT    "ctpConnTimeout"
#define CTP_PORT            "ctpPort"
#define CTP_NONCE           "ctpNonce"
#define CTP_READY           "ctpReady"



CTPConfig::CTPConfig(const char* application_uri)
                    : DMTClientConfig(application_uri) {
    leavingState = false;
}
        
CTPConfig::~CTPConfig() {}

        
void CTPConfig::readCTPConfig() {

    if (!open()) {
        LOG.error("Impossible read the ctp configuration. exit");
        return;
    }

    if (readAccessConfig(*syncMLNode)) {
        setUsername(accessConfig.getUsername());
        setUrlTo(getHostName(accessConfig.getSyncURL()));        
    }
    if (readDeviceConfig(*syncMLNode)) {
        setDeviceId(deviceConfig.getDevID());

    }
    
    // now read the single CTP properties
    ManagementNode* node;

    // read parameter of the client only
    node = dmt->readManagementNode(rootContext);
    if (node) {
        char* tmp;        
        tmp = node->readPropertyValue(PROPERTY_PUSH_NOTIFICATION);
        if (tmp) {
            setPush(atoi(tmp));
        } else {
            setPush(0);
        }        
        delete [] tmp;
             
        tmp = node->readPropertyValue(PROPERTY_POLLING_NOTIFICATION);
        if (tmp) {
            setPolling(atoi(tmp));
        } else {
            setPolling(0);
        }                
        delete [] tmp;

        tmp = node->readPropertyValue(CTP_QUEUE_PUSH);
        if (tmp) {
            setQueuePush(atoi(tmp) == 0 ? false : true);
        } else {
            setQueuePush(false);
        }                
        delete [] tmp;

        tmp = node->readPropertyValue(CTP_RETRY);
        if (tmp) {
            setCtpRetry(atoi(tmp));
        } else {
            setCtpRetry(5);
        }                
        delete [] tmp;

        tmp = node->readPropertyValue(CTP_MAX_RETRY_TIMEOUT);
        if (tmp) {
            setMaxCtpRetry(atoi(tmp));
        } else {
            setMaxCtpRetry(900); // 15 min
        }                
        delete [] tmp;

        tmp = node->readPropertyValue(CTP_CMD_TIMEOUT);
        if (tmp) {
            setCtpCmdTimeout(atoi(tmp));
        } else {
            setCtpCmdTimeout(0); 
        }                
        delete [] tmp;

        tmp = node->readPropertyValue(CTP_CONN_TIMEOUT);
        if (tmp) {
            setCtpConnTimeout(atoi(tmp));
        } else {
            setCtpConnTimeout(0); 
        }                
        delete [] tmp;

        tmp = node->readPropertyValue(CTP_PORT);
        if (tmp) {
            setCtpPort(atoi(tmp));
        } else {
            setCtpPort(0); 
        }                
        delete [] tmp;

        tmp = node->readPropertyValue(CTP_NONCE);
        if (tmp) {
            setCtpNonce(tmp);
        } else {
            setCtpNonce(""); 
        }                
        delete [] tmp;
        
        tmp = node->readPropertyValue(CTP_READY);
        if (tmp) {
            setCtpReady(atoi(tmp));
        } else {
            setCtpReady(5);
        }                
        delete [] tmp;

        delete node;
        node = NULL;
    }
    
    close();
    return;

}


void CTPConfig::saveCTPConfig() {
    ManagementNode* node;    

    if (!open()) {
        return;
    }
  
    node = dmt->readManagementNode(rootContext);
    if (node) {
        node->setPropertyValue(CTP_NONCE, getCtpNonce().c_str());        
        delete node;
        node = NULL;
    }

    close();
}
                      

string CTPConfig::getHostName(string syncUrl) {

    std::string::size_type start, end;
    std::string host;
    // Extract the hostName from syncUrl: "http://<hostName>:8080/funambol/ds"    
    start = syncUrl.find("://", 0);
    if (start != std::string::npos) {
        start += 3;
    } else {
        // try to extract hostname from <hostName>:8080/funambol/ds"  
        start = 0;
    }
    
    end = syncUrl.find_first_of(":/", start);       // stop if ":" or "/" found
    if (end == std::string::npos) { // so the url is only <hostName>
        end = syncUrl.length();
    }

    if (end > start) {
        host = syncUrl.substr(start, end-start);        
    }      

    return host;
}

int CTPConfig::getHostPort(string syncUrl) {

    std::string::size_type start, endSlash, endColon, urlLength;
    string hostPort = "";
    urlLength = syncUrl.length();
    int port = 0;
    // Extract the port from syncUrl: "http://<hostName>:8080/funambol/ds"    
    start = syncUrl.find("://", 0);
    if (start != std::string::npos) {
        start += 3;
    } else {
        // try to extract the port from <hostName>:8080/funambol/ds"  
        start = 0;
    }
    
    endSlash = syncUrl.find_first_of("/", start);       // stop if ":" or "/" found
    endColon = syncUrl.find_first_of(":", start);       // stop if ":" or "/" found
    
    if (endSlash == std::string::npos && endColon == std::string::npos) {
        // there is no port
        // hostname
    } else if (endSlash != std::string::npos && endColon == std::string::npos) {
        // there is no port
        // hostname/funambol
    } else if (endSlash == std::string::npos && endColon != std::string::npos) {
        // there is port
        // hostname:8080            
        hostPort = syncUrl.substr(endColon + 1, urlLength - start);
    } else {
        if (endSlash > endColon) {
            // there is port
            // hostname:8080/funambol            
            hostPort = syncUrl.substr(endColon + 1, endSlash - endColon - 1);
        }
    }
    
    if (hostPort != "") {
        port = atoi(hostPort.c_str());
    }

    return port;
}
    

⌨️ 快捷键说明

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