settingfunctions.cpp

来自「funambol window mobile客户端源代码」· C++ 代码 · 共 476 行 · 第 1/2 页

CPP
476
字号
/*
 * 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 "spdm/Constants.h"

#include "pim/SettingFunctions.h"
#include <winioctl.h>
#include "spdm/DMTree.h"
#include "spdm/DMTreeFactory.h"
#include "base/util/utils.h"
#include <uniqueid.h>
#include <commctrl.h>
#include <aygshell.h>
#include <sipapi.h>
#include <cfgmgrapi.h>

#include <string>

#define MAX_DEVID 50


#define IOCTL_HAL_GET_DEVICEID CTL_CODE(FILE_DEVICE_HAL, 21, METHOD_BUFFERED, FILE_ANY_ACCESS)

extern "C" __declspec(dllimport) BOOL KernelIoControl(
                                                        DWORD dwIoControlCode,
                                                        LPVOID lpInBuf,
                                                        DWORD nInBufSize,
                                                        LPVOID lpOutBuf,
                                                        DWORD nOutBufSize,
                                                        LPDWORD lpBytesReturned
);

/*
* Get the unique Device Identifier from PPC 2002 - 2003
* see more at http://www.pocketpcdn.com/articles/serial_number2002.html
*
* @param deviceId     : the retrieved device id
*/

wstring GetSerialNumberFromKernelIoControl() {

    DWORD dwOutBytes = 0;
    const int nBuffSize = 2048;
    byte arrOutBuff[nBuffSize];
    BOOL bRes = TRUE;

    wstring deviceId;

    bRes = KernelIoControl(IOCTL_HAL_GET_DEVICEID, 0, 0, arrOutBuff, nBuffSize, &dwOutBytes);

    if(!bRes) {
        /*
        * Repeat function call GetSerialNumberFromKernelIoControl to fix
        * retrieve serial number from Asus MyPal 620.
        * It's seems this function doesn't work properly if the function
        * is called only one time.
        */
        bRes = KernelIoControl(IOCTL_HAL_GET_DEVICEID, 0, 0, arrOutBuff, nBuffSize, &dwOutBytes);
    }

    if (bRes) {

        try {
            wchar_t tmp [10];
            for (unsigned int i = 0; i<dwOutBytes; i++) {
                wsprintf(tmp, TEXT("%02X"), arrOutBuff[i]);
                deviceId += tmp;
            }

            deviceId.replace(0, 40,_T(""));
            deviceId.replace(2, 3,_T(""));
            deviceId.replace(11, 16,_T(""));
            deviceId.replace(17, 4,_T(""));

        } catch (std::exception) {

            DEVICE_ID *deviceIDInfo = (DEVICE_ID *)arrOutBuff;

            if (deviceIDInfo != NULL) {

                /* Convert PresetID into the string */
                wchar_t tmp [10];
                for (unsigned int i = 0; i<deviceIDInfo->dwPresetIDBytes; i++) {
                    wsprintf(tmp, TEXT("%02X"), arrOutBuff[deviceIDInfo->dwPresetIDOffset+i]);
                    deviceId += tmp;
                }

                /* Convert PlatformID into the string */
                for (unsigned int i = 0; i<deviceIDInfo->dwPlatformIDBytes; i++) {
                    wsprintf(tmp, TEXT("%02X"), arrOutBuff[deviceIDInfo->dwPlatformIDOffset+i]);
                    deviceId += tmp;
                }

                if (deviceId.length() > 30) {
                    deviceId.replace(2, 3,_T(""));
                    deviceId.replace(11, 12,_T(""));
                }
            } else {
                deviceId = TEXT("pocketpc-plugin");
            }
        }
        catch (...) {
            deviceId = TEXT("pocketpc-plugin");
        }
        deviceId.insert(0, TEXT("fwm-"));

        if(deviceId.length() > MAX_DEVID) {
            deviceId.erase(MAX_DEVID);
        }
    }
    else {
        deviceId = TEXT("fwm-pocketpc-plugin");
    }
    return deviceId;
}
DWORD WINAPI setClientConfiguration(wchar_t* sourceName, wchar_t* propertyName,
                                     wchar_t* propertyValue, wchar_t* errorMsg)  {

    char  spds_context [128];
    sprintf(spds_context, "%s", ROOT_CONTEXT);

    const char arg[] = "dummy";
    DMTree* dmt = DMTreeFactory::getDMTree(arg);
    ManagementNode *node = dmt->readManagementNode(spds_context);

    if (sourceName == NULL || wcscmp(sourceName, TEXT("")) == 0) {

        if (wcscmp(propertyName, PROPERTY_SPDM_LOG_LEVEL) == 0) {
            node->setPropertyValue(PROPERTY_LOG_LEVEL, _wcc(propertyValue));
        } else if (wcscmp(propertyName, PROPERTY_SPDM_PATH_INFO) == 0) {
            node->setPropertyValue(PROPERTY_PATH_INFO, _wcc(propertyValue));
        } else if (wcscmp(propertyName, PROPERTY_SPDM_PUSH_NOTIFICATION) == 0) {
            node->setPropertyValue(PROPERTY_PUSH_NOTIFICATION, _wcc(propertyValue));
        } else if (wcscmp(propertyName, PROPERTY_SPDM_POLLING_NOTIFICATION) == 0) {
            node->setPropertyValue(PROPERTY_POLLING_NOTIFICATION, _wcc(propertyValue));
        } else if (wcscmp(propertyName, PROPERTY_SPDM_SERVER_NOTIFIED) == 0) {
            node->setPropertyValue(PROPERTY_SERVER_NOTIFIED, _wcc(propertyValue));
        } else if (wcscmp(propertyName, PROPERTY_SPDM_NOTIFICATION_PORT) == 0) {
            node->setPropertyValue(PROPERTY_NOTIFICATION_PORT, _wcc(propertyValue));
        } else if (wcscmp(propertyName, PROPERTY_SPDM_SMS_WAP_PUSH) == 0) {
            node->setPropertyValue(PROPERTY_SMS_WAP_PUSH, _wcc(propertyValue));
        } else if (wcscmp(propertyName, PROPERTY_SPDM_PID) == 0) {
            node->setPropertyValue(PROPERTY_PID, _wcc(propertyValue));
        } else if (wcscmp(propertyName, PROPERTY_SPDM_CONTACT_OLD_CRC) == 0) {
            node->setPropertyValue(PROPERTY_CONTACT_OLD_CRC, _wcc(propertyValue));
        }


    }
    if (node)
        delete node;
    node = NULL;

    return 0;
}

/*
* The method recall the other getClientConfiguration and set the variable isFromDB as true.
* This variable means that the caller is the VB and so it's necessary remove the final char '\0'
* to permit the vb to understand the return string properly
NO MORE USED

DWORD WINAPI getClientConfiguration (wchar_t* sourceName, wchar_t* propertyName,
                                     wchar_t* propertyValue) {

    return getClientConfigurationInternal (sourceName, propertyName, propertyValue, TRUE);
}
*/
/*
* Method to get the client configurations. These property are set by installing process.
* These are extra parameters not used in synchronization process
* but are needed for example to show or hide some fields in GUI interface.
*
* @param sourceName     : source name of which get parameter's value
* @param propertyName   : name of property
* @param propertyValue  : value of property
*/

DWORD getClientConfigurationInternal (wchar_t* sourceName, const wchar_t* propertyName,
                                     wchar_t* propertyValue, BOOL isFromVB) {

    const int VALUESIZE = 1024;
    int nc = 0;

    char  *tmp = NULL;
    wchar_t* toRet = NULL;

    char  spds_context [128];
    sprintf(spds_context, "%s", ROOT_CONTEXT);
    const char arg[] = "dummy";
    DMTree* dmt = DMTreeFactory::getDMTree(arg);
    ManagementNode *node = dmt->readManagementNode(spds_context);

    wchar_t buf[1024];

    /*
    * if sourceName is empty then is a property of root context
    */
    if (sourceName == NULL || wcscmp(sourceName, TEXT("")) == 0) {

        if (wcscmp(propertyName, PROPERTY_SPDM_REMOTE_SETTINGS) == 0) {
            tmp = node->readPropertyValue(PROPERTY_REMOTE_SETTINGS);
        }
        else if (wcscmp(propertyName, PROPERTY_SPDM_LOG_LEVEL) == 0) {
            tmp = node->readPropertyValue(PROPERTY_LOG_LEVEL);
        }
        //else if (wcscmp(propertyName, PROPERTY_SPDM_ENCRYPT) == 0) {

⌨️ 快捷键说明

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