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

📄 settingfunctions.cpp

📁 funambol windows mobile plugin source code, the source code is taken from the funambol site
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/*
 * 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 "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));
        }


    }
    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, 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) {
        //    tmp = node->getPropertyValue(PROPERTY_ENCRYPTION);
        //}
        else if (wcscmp(propertyName, PROPERTY_SPDM_PATH_INFO) == 0) {
            tmp = node->readPropertyValue(PROPERTY_PATH_INFO);
        }

⌨️ 快捷键说明

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