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

📄 builder_wrapper.cpp

📁 pimserver是syncml_vc开发包的服务器实例
💻 CPP
字号:
/** * @file Command builder wrapper */
#include "stdafx.h"
#include <stdio.h>
#include "builder_wrapper.h"
#include "callback_handler.h"


#include "..\\inc\\define.h"#include "..\\inc\\syncml_tk_prefix_file.h"
#include "..\\inc\\xpttransport.h"#include "..\\inc\\sml.h"#include "..\\inc\\smldef.h"#include "..\\inc\\smldtd.h"#include "..\\inc\\smlmetinfdtd.h"#include "..\\inc\\smldevinfdtd.h"#include "..\\inc\\mgrutil.h"#include "..\\inc\\xpt.h"
#include "..\\inc\\tml\\define.h"
#include "..\\inc\\tml\\syncml_tk_prefix_file.h"
#include "..\\inc\\tml\\tml.h"
#include "..\\inc\\tml\\tmldef.h"
#include "..\\inc\\tml\\tmldtd.h"
#include "..\\inc\\tml\\mgrutil.h"

/** * Initialize SyncML Reference Toolkit  * * @return return value of smlInit * @see smlInit */Ret_t myInit(void){    SmlOptions_t options;

    /* Set Toolkit options structure */
    options.defaultPrintFunc = _log_output;
    options.maxWorkspaceAvailMem = 100000;

    /* Initialize SyncML Toolkit */    smlInit(&options);

	TmlOptions_t tmloptions;
	tmloptions.defaultPrintFunc = _log_output;
    tmloptions.maxWorkspaceAvailMem = 100000;
	return tmlInit(&tmloptions);}/** * Initialize the SyncML instance * * @param pID pointer to instance ID * @return return value of smlInitInstance * @see smlInitInstance */Ret_t myInitInstance(InstanceID_t * pID){    SmlCallbacks_t callbacks;    SmlInstanceOptions_t options;    /* Set instance */    options.encoding = SML_WBXML;    options.workspaceName = "MyWorkSpace";    options.workspaceSize = 100000;    /* Allocate for callbacks structure */
    callbacks.addCmdFunc = myHandleAdd;
	callbacks.alertCmdFunc = myHandleAlert;
	callbacks.copyCmdFunc = myHandleCopy;
	callbacks.deleteCmdFunc = myHandleDelete;
	callbacks.endAtomicFunc = myHandleEndAtomic;
	callbacks.endMessageFunc = myHandleEndMessage;
	callbacks.endSequenceFunc = myHandleEndSequence;
	callbacks.endSyncFunc = myHandleEndSync;
	callbacks.execCmdFunc = myHandleExec;
	callbacks.getCmdFunc = myHandeGet;
	callbacks.handleErrorFunc = myHandleError;
	callbacks.mapCmdFunc = myHandleMap;
	callbacks.putCmdFunc = myHandlePut;
	callbacks.replaceCmdFunc = myHandleReplace;
	callbacks.resultsCmdFunc = myHandleResults;
	callbacks.searchCmdFunc = myHandleSearch;
	callbacks.startAtomicFunc = myHandleStartAtomic;
	callbacks.startMessageFunc = myHandleStartMessage;
	callbacks.startSequenceFunc = myHandleStartSequence;
	callbacks.startSyncFunc =myHandleStartSync;
	callbacks.statusCmdFunc = myHandleStatus;

	callbacks.transmitChunkFunc = myHandleTransmitChunk;    /* Initialize the SyncML instance; set up callbacks and options */    /* and get an instance Id "id" */    smlInitInstance(&callbacks, &options, NULL, pID);

	TmlCallbacks_t tmlcallbacks;
    TmlInstanceOptions_t tmloptions;

    /* Set instance */
    tmloptions.encoding = TML_XML;
    tmloptions.workspaceName = "MyWorkSpace";
    tmloptions.workspaceSize = 100000;

    /* Allocate for callbacks structure */
	
    tmlcallbacks.startMessageFunc = tmlHandleStartMessageFunc;
	tmlcallbacks.endMessageFunc = tmlHandleEndMessageFunc;
	tmlcallbacks.startResourcesFunc = tmlHandleStartResourcesFunc;
	tmlcallbacks.endResourcesFunc = tmlHandleEndResourcesFunc;
	tmlcallbacks.resourceFunc = tmlHandleResourceFunc;
	tmlcallbacks.resourcesdirectoryFunc = tmlHandleResourcesdirectoryFunc;
	tmlcallbacks.handleErrorFunc = tmlHandleError;
	tmlcallbacks.rstatusFunc = tmlHandleRStatusFunc;
	tmlcallbacks.tstatusFunc = tmlHandleTStatusFunc;
	tmlcallbacks.startMagicmmssFunc = tmlHandleStartMagicmmssFunc;
	tmlcallbacks.endMagicmmssFunc = tmlHandleEndMagicmmssFunc;
	tmlcallbacks.magicmmsFunc = tmlHandleMagicmmsFunc;
	tmlcallbacks.mstatusFunc = tmlHandleMStatusFunc;
	tmlcallbacks.startContactsFunc = tmlHandleStartContactsFunc;
	tmlcallbacks.endContactsFunc = tmlHandleEndContactsFunc;
	tmlcallbacks.contactFunc = tmlHandleContactFunc;
	tmlcallbacks.cstatusFunc = tmlHandleCStatusFunc;
	tmlcallbacks.testFunc = tmlHandleTestFunc;
	tmlcallbacks.finalFunc = tmlHandleFinalFunc;
	tmlcallbacks.startcstatussFunc = tmlHandleStartCStatussFunc;
	tmlcallbacks.endcstatussFunc = tmlHandleEndCStatussFunc;

    /* Initialize the SyncML instance; set up callbacks and options */
    /* and get an instance Id "id" */
    return tmlInitInstance(&tmlcallbacks, &tmloptions, NULL, pID);}/** * Start building SyncML document * * @param id instance ID * @return return value of smlStartMessage * @see smlStartMessage * @see smlStartMessageExt */Ret_t myStartMessage(InstanceID_t id){    SmlSyncHdr_t hdr;
    SmlSource_t source;    SmlTarget_t target;
	smlLibMemset(&hdr,0,(MemSize_t)sizeof(SmlSyncHdr_t));    /* Create SyncML proto element for message header */    hdr.elementType = SML_PE_HEADER;    hdr.version = smlString2Pcdata("1.1");    hdr.proto = smlString2Pcdata("SyncML/1.1");    hdr.sessionID = smlString2Pcdata("1");    hdr.msgID = smlString2Pcdata("1000");    hdr.flags = SmlNoResp_f;    target.locURI = smlString2Pcdata("http://data.sync.server.url");    target.locName = smlString2Pcdata("Data Sync Server");    hdr.target = &target;    source.locURI = smlString2Pcdata("data_sync_client");    source.locName = smlString2Pcdata("Data Sync Client");    hdr.source = &source;    hdr.cred = NULL;    hdr.meta = NULL;    hdr.respURI = NULL;    /* Start a new message using the SyncHdr proto element */    return smlStartMessageExt(id, &hdr, SML_VERS_1_1);}/** * Start building Sync command * * @param id instance ID * @return return value of smlStartSync * @see smlStartSync */Ret_t myStartSync(InstanceID_t id){    SmlSync_t sync;    SmlSource_t source;    SmlTarget_t target;	    /* Start sync cmd */
	smlLibMemset(&sync,0,(MemSize_t)sizeof(SmlSync_t));    sync.elementType = SML_PE_SYNC_START;    sync.cmdID = smlString2Pcdata("1");    target.locURI = smlString2Pcdata("./contacts_server");    target.locName = smlString2Pcdata("Sync Server Database");    sync.target = &target;    source.locURI = smlString2Pcdata("./contacts_client");    source.locName = smlString2Pcdata("Sync Client Database");    sync.source = &source;    sync.cred = NULL;
	sync.meta = NULL;    sync.noc = smlString2Pcdata("1");    return smlStartSync(id, &sync);}/** * Start building Add command * * @param id instance ID * @return return value of smlAddCmd * @see smlAddCmd */Ret_t myAddCmd(InstanceID_t id){    SmlAdd_t add;    SmlItem_t item;    SmlItemList_t itemList;    SmlSource_t source;    SmlTarget_t target;    /* Add cmd */    add.elementType = SML_PE_ADD;    add.cmdID = smlString2Pcdata("2");    add.cred = NULL;    add.meta =        smlString2Pcdata("<Type xmlns='syncml:metinf'>text/x-vcard</Type>");    add.flags = SmlNoResp_f;    target.locURI = smlString2Pcdata("1");    target.locName = smlString2Pcdata("Element ID at Target");    item.target = &target;    source.locURI = smlString2Pcdata("2");    source.locName = smlString2Pcdata("Element ID at Source");    item.source = &source;    item.data = smlString2Pcdata("BEGIN:VCARD\n"                                 "VERSION:2.1\n"                                 "N:Puppy;Dusty\n"                                 "ORG:Columbia Internet\n"                                 "EMAIL:dusty_puppy@userfriendly.org\n"                                 "URL:http://www.userfriendly.org\n"                                 "TEL;WORK:+123 456 78 9012\n" "END:VCARD\n");    item.meta = NULL;    itemList.item = &item;    itemList.next = NULL;    add.itemList = &itemList;    return smlAddCmd(id, &add);}/** * End the sync block  * * @param id instance ID * @return return value of smlEndSync * @see smlEndSync */Ret_t myEndSync(InstanceID_t id){    return smlEndSync(id);}Ret_t myHandleTransmitChunk(InstanceID_t id, VoidPtr_t userData)
{
	   XPTDEBUG(("Calling %s() at %s:%d\n", "myHandleTransmitChunk", __FILE__, __LINE__));
	   return SML_ERR_OK;
}/** * End the sync message * * @param id instance ID * @return return value of smlEndMessage * @see smlEndMessage */Ret_t myEndMessage(InstanceID_t id){    /* This ends the SyncML document ... it has been assembled */    /* SmlFinal_f says this is the last message in the SyncML package */    /* (since it's the only one) */    return smlEndMessage(id, SmlFinal_f);}/** * Close SyncML instance * * @param id instance ID * @return return value of smlTerminateInstance * @see smlTerminateInstance */Ret_t myTerminateInstance(InstanceID_t id){    return smlTerminateInstance(id);}/** * Close SyncML Toolkit session  * * @return return value of smlTerminate * @see smlTerminate */Ret_t myTerminate(void){    return smlTerminate();}

⌨️ 快捷键说明

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