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

📄 addresschange.cpp

📁 funambol window mobile客户端源代码
💻 CPP
字号:
/*
 * 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 "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"
#include "http/GPRSConnection.h"
#include "base/stringUtils.h"
#include "pim/ClientSettings.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) {}

    char* 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;       
    }

    bool set() {
        // Read access config from DM
        if( !read() )
            return false;

        char* passDecoded = decodePassword(accessConfig.getPassword());
        accessConfig.setPassword(passDecoded);
        if (passDecoded) { delete [] passDecoded; }

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

int notifyAddressChange(const wchar_t *context)
{
    int retCode = AN_AddressAccepted;
    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);
        retCode = sm.prepareSync(ssArray);
        if (retCode) {
            LOG.info("Address notification failed, STP not available (code %d)", retCode);

            // Display msgbox if necessary
            if (retCode == INVALID_CREDENTIALS ||           // code 401
                retCode == PAYMENT_REQUIRED    ||           // code 402
                retCode == FORBIDDEN ){                     // code 403
                showInvalidCredentialsMsgBox(retCode, 10);
            }

            LOG.debug("notifyAddressChange: prepareSync failed (%d: %s)",getLastErrorCode(), getLastErrorMsg());
        }
        else {
            LOG.debug("notifyAddressChange: success\n");
        }
    }
    else {
        retCode = AN_InvalidConfig;
        LOG.debug("notifyAddressChange: config failed\n");
    }
    LOG.debug("notifyAddressChange END....");

    delete [] ssArray;

    // Return 'AN_AddressAccepted' or the error code
    return retCode;
}



void showInvalidCredentialsMsgBox(int statusCode, int timeout) 
{
    if (timeout<0) {
        timeout = 10;
    }

    wstring message;
    if (statusCode == INVALID_CREDENTIALS) {        // 401
        message = getLocalizationUtils()->getLocalizationString(IDS_CODE_INVALID_CREDENTIALS_401);
    }
    else if (statusCode == PAYMENT_REQUIRED) {      // 402
        message = getLocalizationUtils()->getLocalizationString(IDS_CODE_AUTH_EXPIRED_402);
    }
    else {  // FORBIDDEN                            // 403
        message = getLocalizationUtils()->getLocalizationString(IDS_CODE_FORBIDDEN_403);
    }

    wchar_t title[128];
    wsprintf(title, TEXT("%s"), getLocalizationUtils()->getLocalizationString(IDS_FUNAMBOL_ALERT));
    
    TimedMessageBox(NULL, 
                    message.c_str(), 
                    title,
                    MB_OK | MB_ICONHAND | MB_SETFOREGROUND, 
                    timeout*1000);
}

⌨️ 快捷键说明

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