diff options
Diffstat (limited to 'engine/dmlib/dmengine/dm_util')
-rw-r--r-- | engine/dmlib/dmengine/dm_util/hdr/dm_uri_utils.h | 112 | ||||
-rw-r--r-- | engine/dmlib/dmengine/dm_util/hdr/dmbuffer.h | 84 | ||||
-rw-r--r-- | engine/dmlib/dmengine/dm_util/hdr/dmdefs.h | 16 | ||||
-rw-r--r-- | engine/dmlib/dmengine/dm_util/hdr/dmtoken.h | 271 | ||||
-rw-r--r-- | engine/dmlib/dmengine/dm_util/hdr/syncml_dm_data_types.h | 339 | ||||
-rw-r--r-- | engine/dmlib/dmengine/dm_util/src/dm_uri_utils.cc | 242 | ||||
-rw-r--r-- | engine/dmlib/dmengine/dm_util/src/dmbuffer.cc | 208 | ||||
-rw-r--r-- | engine/dmlib/dmengine/dm_util/src/dmtoken.cc | 334 |
8 files changed, 1606 insertions, 0 deletions
diff --git a/engine/dmlib/dmengine/dm_util/hdr/dm_uri_utils.h b/engine/dmlib/dmengine/dm_util/hdr/dm_uri_utils.h new file mode 100644 index 0000000..c5a35fd --- /dev/null +++ b/engine/dmlib/dmengine/dm_util/hdr/dm_uri_utils.h @@ -0,0 +1,112 @@ +/* + * Copyright (C) 2014 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef DMURIUTILITY_H +#define DMURIUTILITY_H + +/*================================================================================================== + +Header Name: dm_uri_utils.h + +General Description: This file contains declaration declaration of helper functions for uri processing + +==================================================================================================*/ + +#include <stdlib.h> +#include "xpl_Types.h" +#include "syncml_dm_data_types.h" +#include "dmvector.h" + +#define SYNCML_DM_NULL ('\0') +#define SYNCML_DM_AMPERSAND ('&') +#define SYNCML_DM_STAR ('*') +#define SYNCML_DM_PLUS ('+') +#define SYNCML_DM_EQUAL_TO ('=') +#define SYNCML_DM_FORWARD_SLASH ('/') +#define SYNCML_DM_DOT ('.') +#define SYNCML_DM_PERCENTAGE ('%') +#define SYNCML_DM_QUESTION_MARK ('?') +#define SYNCML_DM_SPACE (' ') +#define SYNCML_DM_COMMA (',') + + +#ifdef __cplusplus +extern "C" { +#endif + +void DmParseURI(CPCHAR szPath, DMString& strURI, DMString& strKey ); + +bool DmStringParserGetItem( DMString& strItem, DMString& strReminder, char cDelim ); + +int DmStrToStringVector(const char * pStr, int nLen, DMStringVector& oVector, char cDelim ); + +char* GetURISegment(char **ppbURI); + +char* GetStringSegment(char **ppbURI, char cDelim); + +/** + * Verifies if path is the DMAcc path + * \param szPath [in/out] - node path + * \return TRUE if path is the DMAcc path + */ +SYNCML_DM_RET_STATUS_T DmIsDMAccNodePath(CPCHAR szPath); + +/** + * Verifies if path is enabled + * \param szPath [in/out] - node path + * \return TRUE if enabled + */ +BOOLEAN DmIsEnabledURI(CPCHAR szPath); + +/** + * Verifies if szParentURI is direct or indirect parent (including node itself) of node szChildURI + * Both URIs can contain multi-node characters ('*') + * \param szParentURI [in] - parent path + * \param szChildURI [in] - child path + * \return TRUE if path is a parent + */ +BOOLEAN DmIsParentURI(CPCHAR szParentURI, CPCHAR szChildURI); + + +#ifdef __cplusplus +} +#endif + +class CEnv +{ +public: + CEnv(); + + BOOLEAN Init(); + void Done(); + + CPCHAR GetWFS() const { return m_szWFS;} + CPCHAR GetMainRFS() const { return m_szMainRFS; } + int GetRFSCount() const { return m_aFSes.size() > 1 ? m_aFSes.size() - 1 : 0;} + CPCHAR GetRFS( int index ) const { return (index +1) >= m_aFSes.size() ? NULL : m_aFSes[index +1].c_str(); } + CPCHAR GetWFSFullPath(CPCHAR name, DMString & path); + CPCHAR GetMainRFSFullPath(CPCHAR name, DMString & path); + CPCHAR GetRFSFullPath(int index, CPCHAR name, DMString & path); + +private: + DMStringVector m_aFSes; // first element is WFS, second is MainRFS, all other - auxulary RFS + CPCHAR m_szWFS; + CPCHAR m_szMainRFS; + + CPCHAR GetFullPath(CPCHAR fs_path, CPCHAR name, DMString & path); +}; + +#endif diff --git a/engine/dmlib/dmengine/dm_util/hdr/dmbuffer.h b/engine/dmlib/dmengine/dm_util/hdr/dmbuffer.h new file mode 100644 index 0000000..e35afee --- /dev/null +++ b/engine/dmlib/dmengine/dm_util/hdr/dmbuffer.h @@ -0,0 +1,84 @@ +/* + * Copyright (C) 2014 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __DMBUFFER_H__ +#define __DMBUFFER_H__ + +#ifndef __cplusplus +#error "This is a C++ header file; it requires C++ to compile." +#endif + +#include "xpl_Types.h" +#include "dmstring.h" + +/** + * A simple Buffer class. + */ +class DMBuffer +{ + public: + DMBuffer(); + ~DMBuffer(); + + DMBuffer & operator=(const DMBuffer& pBuffer); + + inline UINT8* getBuffer() const {return m_pBuf;} + + inline UINT32 getSize() const {return m_nSize;} + + UINT8 * allocate(UINT32 nCapacity); + + UINT8 * assign(CPCHAR szStr); + + UINT8 * assign(const UINT8 * pBuffer, INT32 size); + void append(const UINT8 * pBuffer, INT32 size); + + inline UINT8 * assign(CPCHAR szStr, INT32 size) { return assign((UINT8*)szStr,size); } + + void clear(); + void free(); + void reset(); + + void setSize(UINT32 size); + + void copyTo(UINT8 **ppBuffer) const; + + void copyTo(INT32 offset,INT32 size, DMBuffer& pBuffer) const; + + inline void copyTo(char ** ppStr) const { copyTo((UINT8**)ppStr); } + + void copyTo(char * pStr) const; + + void copyTo(DMString & sStr) const; + + BOOLEAN compare(CPCHAR pStr) const; + + BOOLEAN compare(CPCHAR pStr, UINT32 len) const; + + BOOLEAN empty() { return ((m_nSize == 0) ? TRUE : FALSE); } + + void attach(UINT8 * pBuffer, INT32 nCapacity); + + UINT8 * detach(); + + + private: + UINT8 *m_pBuf; + UINT32 m_nSize; + UINT32 m_nCapacity; +}; + +#endif //End of include File diff --git a/engine/dmlib/dmengine/dm_util/hdr/dmdefs.h b/engine/dmlib/dmengine/dm_util/hdr/dmdefs.h new file mode 100644 index 0000000..137b0da --- /dev/null +++ b/engine/dmlib/dmengine/dm_util/hdr/dmdefs.h @@ -0,0 +1,16 @@ +#ifndef DM_DEFS_H +#define DM_DEFS_H + +/************** HEADER FILE INCLUDES *****************************************/ + +#include "dmMemory.h" + + +#define DIM(array) (sizeof(array)/sizeof((array)[0])) + +#define FreeAndSetNull(_x) \ + if ((_x)!=NULL) { DmFreeMem(_x); (_x)=NULL; } + + +#endif /* DMDEFS_H */ + diff --git a/engine/dmlib/dmengine/dm_util/hdr/dmtoken.h b/engine/dmlib/dmengine/dm_util/hdr/dmtoken.h new file mode 100644 index 0000000..cc87925 --- /dev/null +++ b/engine/dmlib/dmengine/dm_util/hdr/dmtoken.h @@ -0,0 +1,271 @@ +/* + * Copyright (C) 2014 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __DMTOKEN_H__ +#define __DMTOKEN_H__ + +#ifndef __cplusplus +#error "This is a C++ header file; it requires C++ to compile." +#endif + +/*================================================================================================== + +Header Name: dmToken.h + +General Description: This file contains declaration of utility classes DMToken, DMURI, DMParser + +==================================================================================================*/ + +#include "xpl_Types.h" +#include "dmStringUtil.h" +#include "dm_uri_utils.h" + +/** + * DMToken represents a parser of a string with segments separated by specified delimeter. + */ +class DMToken +{ + public: + /** + * Default constructor + */ + DMToken(); + + /** + * Constructor that sets value of delimeter + * \param delimeter [in] - delimeter + */ + DMToken(char delimeter); + + /** + * Constructor that sets parameters of an object + * \param bIsAlloc [in] - specifies if internal buffer should be allocated and string copied into it + * \param szStr [in] - string to parse + * \param delimeter [in] - delimeter + */ + DMToken(BOOLEAN bIsAlloc, CPCHAR szStr, char delimeter); + + /** + * Destructor + */ + ~DMToken(); + + /** + * Assigns string to parse + * \param szStr [in] - string to parse + * \return Return Type (CPCHAR) + * - Pointer on internal buffer if operation is completed successfully. + * - NULL otherwise. + */ + CPCHAR assign(CPCHAR szStr); + + /** + * Retrieves next segment of a string + * \return Return Type (CPCHAR) + * - Pointer on next segment if operation is completed successfully. + * - NULL otherwise. + */ + CPCHAR nextSegment(); + + /** + * Retrieves pointer on string + */ + char * getBuffer() const { return m_pStr; } + + /** + * Retrieves length of a string + */ + INT32 length() { return m_pStr ? DmStrlen(m_pStr):0; } + + /** + * Retrieves count of segments in a string + */ + UINT32 getSegmentsCount(); + + /** + * Resets object + */ + void reset(); + + + protected: + /* Pointer on current segment position */ + char * m_pTokenPos; + /* Pointer on current delimeter position */ + char * m_pDelimPos; + /* Pointer on parsed string */ + char * m_pStr; + /* Delimeter */ + char m_cDelim; + /* Specifies if internal buffer should eb allocated */ + BOOLEAN m_bIsAlloc; + + +}; + + +/** +* DMToken represents a URI parser +*/ +class DMURI : public DMToken +{ + +public: + /** + * Default constructor + */ + DMURI(); + + /** + * Constructor that sets parameters of an object + * \param bIsAlloc [in] - specifies if internal buffer should be allocated and string copied into it + */ + DMURI(BOOLEAN bIsAlloc); + + /** + * Constructor that sets parameters of an object + * \param bIsAlloc [in] - specifies if internal buffer should be allocated and string copied into it + * \param szURI [in] - string to parse + */ + DMURI(BOOLEAN bIsAlloc, CPCHAR szURI); + + /** + * Retrieves last segment of URI + * \return Return Type (CPCHAR) + * - Pointer on last segment if operation is completed successfully. + * - NULL otherwise. + */ + CPCHAR getLastSegment(); + + /** + * Retrieves tail segments of URI + * \return Return Type (CPCHAR) + * - Pointer on last segment if operation is completed successfully. + * - NULL otherwise. + */ + CPCHAR getTailSegments() const; + + /** + * Retrieves parent URI (without last segment) + * \return Return Type (CPCHAR) + * - Pointer on last segment if operation is completed successfully. + * - NULL otherwise. + */ + CPCHAR getParentURI(); + +}; + + +/** +* Represents segments of URI +*/ +struct DM_URI_SEGMENT_T +{ + +public: + /** + * Default constructor + */ + DM_URI_SEGMENT_T() + { + m_pStr = 0; + m_nLen = 0; + } + + /* Pointer on segment */ + char * m_pStr; + /* Segment length */ + INT32 m_nLen; +}; + + +/** +* DMToken represents a URI parser +*/ +class DMParser +{ + +public: + /** + * Constructor that sets parameters of an object + * \param delimeter [in] - delimeter + */ + DMParser(char delimeter = SYNCML_DM_FORWARD_SLASH); + + /** + * Constructor that sets parameters of an object + * \param szURI [in] - URI to parse + * \param delimeter [in] - delimeter + */ + DMParser(CPCHAR szURI, char delimeter = SYNCML_DM_FORWARD_SLASH); + + /** + * Destructor + */ + ~DMParser(); + + /** + * Retrieves count of segments in a string + */ + inline UINT32 getSegmentsCount() const { return m_nSegmentsCount; } + + /** + * Assigns string to parse + * \param szStr [in] - string to parse + * \return Return Type (CPCHAR) + * - Pointer on internal buffer if operation is completed successfully. + * - NULL otherwise. + */ + CPCHAR assign(CPCHAR szStr); + + /** + * Retrieves next segment of a string + * \return Return Type (CPCHAR) + * - Pointer on next segment if operation is completed successfully. + * - NULL otherwise. + */ + CPCHAR nextSegment(); + + /** + * Searches segment in the URI + * \return TRUE if segment is found + */ + BOOLEAN findSegment(CPCHAR szSegment); + + /** + * Resets object + */ + void reset(); + +protected: + /* Parsed segments */ + DM_URI_SEGMENT_T * m_aSegments; + /* Current segment index */ + INT32 m_nCurrentSegment; + /* Segments count */ + INT32 m_nSegmentsCount; + /* Pointer on current segment position */ + char * m_pTokenPos; + /* Pointer on current delimeter position */ + char * m_pDelimPos; + /* Pointer on parsed string */ + char * m_pStr; + /* Delimeter */ + char m_cDelim; + +}; + +#endif diff --git a/engine/dmlib/dmengine/dm_util/hdr/syncml_dm_data_types.h b/engine/dmlib/dmengine/dm_util/hdr/syncml_dm_data_types.h new file mode 100644 index 0000000..64ebef6 --- /dev/null +++ b/engine/dmlib/dmengine/dm_util/hdr/syncml_dm_data_types.h @@ -0,0 +1,339 @@ +/* + * Copyright (C) 2014 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef SYNCML_DM_DATA_TYPES_H +#define SYNCML_DM_DATA_TYPES_H + +#ifdef __cplusplus +extern "C" { +#endif + +/*================================================================================================== + + Header Name: syncml_dm_data_types.h + + General Description: This contains declaration of DM engine general enums and data structures. + +==================================================================================================*/ + +#include "dmtError.h" +#include "dmMemory.h" +#include "dmtDefs.h" + +/*================================================================================================== + CONSTANTS +==================================================================================================*/ + +#define DM_MD5_DIGEST_LENGTH 16 /* For package 0 data */ + +#define SYNCML_DM_MAX_SERVER_ALLOWED 3 /* for Current implementation */ + +#define SYNCML_DM_URI_MAX_DEPTH 20 //Max allowed levels + +/* The DDF file for Motorola SyncML DM devices defines MaxTotLen = 127, and MaxSegLen = 32. + MaxTotLen is limited to 127 due to persistent storage implementation. It serializes the tree + structure into a flat file using WBXML format; opaque data values are stored with a multi-byte + integer encoded length. The implementation of the mb_uint_32 format is limited to encode/decode + up to the value 127. Anywhere memory is allocated for the Max URI length should use + SYNCML_DM_URI_MAX_TOTAL_LENGTH+1 to account for a null string terminator, since the code works + with the URI as a string. In the same manner, SYNCML_DM_URI_MAX_SEGMENT_LENGTH+1 should be used + to account for its string terminator. Note! The SyncML specs state that by default, characters + are encoded in UTF-8. The MaxTotLen and MaxSegLen values indicate the number of characters the + device allows, which may be LESS than the number of bytes it actually takes to UTF-8 encode the + string. In theory, the size in bytes of the memory to hold these strings should be much larger, + to allow the UTF-8 encoded data to fit (as much as 2 or 3 times the size, worst case). At the + moment, the byte-size and character-length for these limits are coded to be the same, which + always works if the characters are ASCII. */ + +#define SYNCML_DM_URI_MAX_TOTAL_LENGTH 255 // will use too many stack spaces +#define SYNCML_DM_URI_MAX_SEGMENT_LENGTH 120 + +#define SYNCML_DM_MAX_TITLE_LENGTH 255 +#define SYNCML_DM_MAX_TSTAMP_LENGTH 17 +#define SYNCML_DM_STR_MAX_LEN 120 /* Max length of a string leaf node data value. */ +#define SYNCML_DM_MAX_OBJ_SIZE 262080 // This is the maximum FOTA obj size required by TRS. + +#define DEFAULT_DM_SMLTK_WORKSPACE_SIZE (120*1024) + +#define DM_MSG_OVERHEAD 600 /* SyncML DM document overhead (none data part). */ +extern INT32 g_iDMWorkspaceSize; + +#define DM_FSTAB_FILENAME "fstab" +#define DM_ROOT_MDF_FILENAME "root.bmdf" +#define DM_PLUGINS_INI_FILENAME "sysplugins.ini" +#define DM_PLIGINS_INI_FILEEXTENSION "ini" +#define DM_MDF_FILEEXTENSION "bmdf" +#define DM_DEFAULT_ACL_FILENAME "acl.dat" +#define DM_DEFAULT_EVENT_FILENAME "event.dat" +#define DM_DATASUBFOLDER "" + +#define DM_MAX_CONFIG_LINE 400 + + +/*================================================================================================== + GLOBAL VARIABLES DECLARATION +==================================================================================================*/ +/* These strings are used throughout the DM engine code. They are externed here to keep them + * in one ROM location. Please see the actual value definitions in "syncml_dm_main.cc". + */ + +#define SYNCML_CONTENT_TYPE_DM_WBXML "application/vnd.syncml.dm+wbxml" +#define SYNCML_CONTENT_TYPE_DM_XML "application/vnd.syncml.dm+xml" +#define SYNCML_CONTENT_TYPE_DM_TNDS_WBXML "application/vnd.syncml.dmtnds+wbxml" +#define SYNCML_CONTENT_TYPE_DM_TNDS_XML "application/vnd.syncml.dmtnds+xml" +#define SYNCML_DM_PROTOCOL_VERSION_1_2 "DM/1.2" +#define SYNCML_DM_PROTOCOL_VERSION_1_1 "DM/1.1" + + +#define RECV_WORKSPACE_NAME "Received SyncML Document" +#define SEND_WORKSPACE_NAME "Send SyncML Document" +#define CACHE_WORKSPACE_NAME "SyncML Document Cache" + +#define DM_DEV_INFO_URI_PAK1 "./DevInfo?list=Struct" + +#define RECV_WORKSPACE_NAME "Received SyncML Document" +#define SEND_WORKSPACE_NAME "Send SyncML Document" +#define CACHE_WORKSPACE_NAME "SyncML Document Cache" + +#define DM_ROOT_URI "." +#define DM_STR_SLASH "/" +#define DM_INBOX "./Inbox" +#define DM_DMACC_1_1_URI "./SyncML/DMAcc" +#define DM_DMACC_1_2_URI "./DMAcc" +#define DM_DMCON_URI "./SyncML/Con" + +#define DM_APPID "AppID" +#define DM_SERVERID_1_2 "ServerID" +#define DM_SERVERID_1_1 "ServerId" + +#define MNG_OBJID_DMACC1 "urn:oma:mo:oma-dm-dmacc:1.0" +#define MNG_OBJID_DMACC2 "org.openmobilealliance/1.0/w7" + +#define DM_NAME "Name" +#define DM_PREFCONREF "PrefConRef" +#define DM_CONREF "ConRef" +#define DM_TOCONREF "ToConRef" +#define DM_APPADDR "AppAddr" +#define DM_ADDR "Addr" +#define DM_ADDRTYPE "AddrType" +#define DM_PORT "Port" +#define DM_PORTNBR "PortNbr" +#define DM_USERNAME "UserName" +#define DM_AUTHPREF "AuthPref" +#define DM_CLIENTNONCE "ClientNonce" +#define DM_SERVERNONCE "ServerNonce" +#define DM_CLIENTPW "ClientPW" +#define DM_SERVERPW "ServerPW" + +// OMA DM 1.2 changes +#define DM_AAUTHPREF "AAuthPref" +#define DM_APPAUTH "AppAuth" +#define DM_AAUTHLEVEL "AAuthLevel" +#define DM_AAUTHTYPE "AAuthType" +#define DM_AAUTHNAME "AAuthName" +#define DM_AAUTHSECRET "AAuthSecret" +#define DM_AAUTHDATA "AAuthData" +#define DM_EXT "Ext" +#define DM_LASTCLIENTAUTHTYPE "LastClientAuthType" + +// Application service +#define DM_APPID_VALUE "w7" + +#define DM_AUTHLEVEL_CLCRED "CLCRED" +#define DM_AUTHLEVEL_SRVCRED "SRVCRED" +#define DM_AUTHLEVEL_OBEX "OBEX" +#define DM_AUTHLEVEL_HTTP "HTTP" + +#define DM_AUTHTYPE_HTTPBASIC "HTTP-BASIC" +#define DM_AUTHTYPE_HTTPDIGEST "HTTP-DIGEST" +#define DM_AUTHTYPE_BASIC "BASIC" +#define DM_AUTHTYPE_DIGEST "DIGEST" +#define DM_AUTHTYPE_HMAC "HMAC" +#define DM_AUTHTYPE_TRANPORT "TRANSPORT" +// end of OMA DM 1.2 changes + +#define DM_DEV_INFO_URI_PAK1 "./DevInfo?list=Struct" +#define DM_DEV_INFO_DEVID_URI "./DevInfo/DevId" +#define DM_DEV_INFO_MOD_URI "./DevInfo/Mod" +#define DM_DEV_INFO_MAN_URI "./DevInfo/Man" + +#define SYNCML_AUTH_MAC "syncml:auth-MAC" +#define SYNCML_AUTH_MD5 "syncml:auth-md5" +#define SYNCML_AUTH_BASIC "syncml:auth-basic" +#define SYNCML_B64 "b64" +#define SYNCML_MAC_ALG "MD5" + +#define SYNCML_SYNCHDR "SyncHdr" +#define SYNCML_REPLACE "Replace" +#define SYNCML_ALERT "Alert" + +/*================================================================================================== + ENUMS +==================================================================================================*/ +/* Need to find the right global .h file for these defines */ + +typedef UINT32 MAX_MSG_SIZE_T; + +/* These enum values are used to indicate the node scope for DMTNM_NODE_SCOPE */ +enum +{ + DMTNM_NODE_PERMANENT = 1, + DMTNM_NODE_DYNAMIC = 2 +}; +typedef UINT8 DMTNM_NODE_SCOPE; + +enum +{ + DMTNM_NODE_INTERIOR = 1, + DMTNM_NODE_LEAF = 2 +}; +typedef UINT8 DMTNM_NODE_TYPE; + +/* These enum values are used to indicate command type for SYNCML_DM_COMMAND_T. + * DON'T CHANGE THE ORDER OF THIS ENUM, TEHY ARE USED BY FEATURE DATABASES. */ +enum +{ + SYNCML_DM_NO_COMMAND, + SYNCML_DM_ADD, + SYNCML_DM_DELETE, + SYNCML_DM_REPLACE, + SYNCML_DM_GET, + SYNCML_DM_RENAME, + SYNCML_DM_EXEC, + SYNCML_DM_COPY, + SYNCML_DM_ALERT, + SYNCML_DM_HEADER, + SYNCML_DM_STATUS, + SYNCML_DM_ATOMIC, + SYNCML_DM_SEQUENCE, + SYNCML_DM_MAX_CMD, + SYNCML_DM_ADD_CHILD, + SYNCML_DM_RELEASE, + SYNCML_DM_ROLLBACK, + SYNCML_DM_COMMIT +}; +typedef UINT8 SYNCML_DM_COMMAND_T; + +/* These enum values are used to indicate the format of the data for SYNCML_DM_FORMAT_T */ +enum +{ + SYNCML_DM_FORMAT_BIN = SYNCML_DM_DATAFORMAT_BIN, + SYNCML_DM_FORMAT_BOOL = SYNCML_DM_DATAFORMAT_BOOL, + SYNCML_DM_FORMAT_B64 = SYNCML_DM_DATAFORMAT_B64, + SYNCML_DM_FORMAT_CHR = SYNCML_DM_DATAFORMAT_STRING, + SYNCML_DM_FORMAT_INT = SYNCML_DM_DATAFORMAT_INT, + SYNCML_DM_FORMAT_NODE = SYNCML_DM_DATAFORMAT_NODE, + SYNCML_DM_FORMAT_NULL = SYNCML_DM_DATAFORMAT_NULL, + SYNCML_DM_FORMAT_XML = SYNCML_DM_DATAFORMAT_XML, + SYNCML_DM_FORMAT_FLOAT = SYNCML_DM_DATAFORMAT_FLOAT, + SYNCML_DM_FORMAT_DATE = SYNCML_DM_DATAFORMAT_DATE, + SYNCML_DM_FORMAT_TIME = SYNCML_DM_DATAFORMAT_TIME, + SYNCML_DM_FORMAT_TEST = 9, + SYNCML_DM_FORMAT_INVALID = 21, + SYNCML_DM_FORMAT_NODE_PDATA = 22 /* special type for serialization only */ +}; +typedef UINT8 SYNCML_DM_FORMAT_T; + + +/* These values came from the DM spec, are used for SYNCML_DM_ALERT_CODE. */ +enum +{ + DM_ALERT_DISPLAY = 1100, + DM_ALERT_CONTINUE_OR_ABORT = 1101, + DM_ALERT_TEXT_INPUT = 1102, + DM_ALERT_SINGLE_CHOICE = 1103, + DM_ALERT_MULTIPLE_CHOICE = 1104, + DM_ALERT_SERVER_INITIATED_MGMT = 1200, + DM_ALERT_CLIENT_INITIATED_MGMT = 1201, + DM_ALERT_NEXT_MESSAGE = 1222, + DM_ALERT_SESSION_ABORT = 1223, + DM_ALERT_END_OF_DATA_NOT_RECEIVED = 1225, + DM_ALERT_FIRMWARE_UPDATE = 1226 +}; +typedef UINT16 SYNCML_DM_ALERT_CODE; + + +/* These enum values are used to indicate the state of Security for the DM User Agent + * SYNCML_DM_SEC_STATE_FLAG_T */ +/* NOTE: DO NOT change numeric values, since bitwise operations used */ +enum { + DM_CLIENT_NO_SERVER_NO_AUTH = 0, /* Neither client nor server are authenticated.*/ + DM_CLIENT_NO_SERVER_Y_AUTH = 1, /* Server Authenticated, Client not authenticated.*/ + DM_CLIENT_Y_SERVER_NO_AUTH = 2, /* Client Authenticated, Server not authenticated.*/ + DM_BOTH_CLIENT_SERVER_AUTH = 3 /* Both Client and Server Authenticated.*/ +}; +typedef UINT8 SYNCML_DM_SEC_STATE_FLAG_T; + + +/* These enum values are used to indicate the URI checking result for SYNCML_DM_URI_RESULT_T */ +enum +{ + SYNCML_DM_COMMAND_ON_NODE, /* means URI doesnt have any special case */ + SYNCML_DM_COMMAND_ON_ACL_PROPERTY, /* ?prop=ACL or ?prop=Name , Format etc */ + SYNCML_DM_COMMAND_ON_FORMAT_PROPERTY, + SYNCML_DM_COMMAND_ON_NAME_PROPERTY, + SYNCML_DM_COMMAND_ON_SIZE_PROPERTY, + SYNCML_DM_COMMAND_ON_ESN_PROPERTY, + SYNCML_DM_COMMAND_ON_TYPE_PROPERTY, + SYNCML_DM_COMMAND_ON_TITLE_PROPERTY, + SYNCML_DM_COMMAND_ON_TSTAMP_PROPERTY, + SYNCML_DM_COMMAND_ON_VERNO_PROPERTY, + SYNCML_DM_COMMAND_ON_UNKNOWN_PROPERTY, + SYNCML_DM_COMMAND_LIST_STRUCT, /* ?list=Struct found in URI */ + SYNCML_DM_COMMAND_LIST_STRUCTDATA, /* ?list=StructData found in URI */ + SYNCML_DM_COMMAND_LIST_TNDS, /* ?list=TNDS found in URI */ + SYNCML_DM_COMMAND_URI_TOO_LONG, /* URI is too long */ + SYNCML_DM_COMMAND_INVALID_URI /* URI was invalid */ +}; +typedef UINT8 SYNCML_DM_URI_RESULT_T; + + +enum +{ + SYNCML_DM_ALERT_NONE, + SYNCML_DM_ALERT_CANCEL, + SYNCML_DM_ALERT_NO +}; +typedef UINT8 SYNCML_DM_ALERT_RES_T; + + +/*================================================================================================== + Structures +==================================================================================================*/ + +/* This buffer is used to hold syncml document data */ +typedef struct +{ + UINT32 dataSize; + UINT8 *pData; +} SYNCML_DM_INDIRECT_BUFFER_T; + + +typedef struct +{ + BOOLEAN _AuthFlag; + CPCHAR _pServerId; + UINT8 *_md5Digest; + UINT8 *_pTrigger; + UINT8 _triggerLen; +} SYNCML_DM_AuthContext_T; + +/*================================================================================================*/ +#ifdef __cplusplus +} +#endif + +#endif /* SYNCML_DM_DATA_TYPES_H */ diff --git a/engine/dmlib/dmengine/dm_util/src/dm_uri_utils.cc b/engine/dmlib/dmengine/dm_util/src/dm_uri_utils.cc new file mode 100644 index 0000000..b0deda6 --- /dev/null +++ b/engine/dmlib/dmengine/dm_util/src/dm_uri_utils.cc @@ -0,0 +1,242 @@ +/* + * Copyright (C) 2014 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/*================================================================================================== + + Source Name: dm_uri_utils.cc + + General Description: File contains implementation for helper functions for uri processing + +==================================================================================================*/ + +#include "dm_uri_utils.h" +#include "xpl_dm_Manager.h" +#include "dmdefs.h" +#include "dmtoken.h" +#include "dm_tree_class.H" + +CEnv::CEnv() +{ + m_szWFS = m_szMainRFS = ""; +} + +CPCHAR CEnv::GetWFSFullPath(CPCHAR name, DMString & path) +{ + return GetFullPath(m_szWFS,name,path); +} + +CPCHAR CEnv::GetMainRFSFullPath(CPCHAR name, DMString & path) +{ + return GetFullPath(m_szMainRFS,name,path); +} + +CPCHAR CEnv::GetFullPath(CPCHAR fs_path, CPCHAR name, DMString & path) +{ + path = fs_path; + path += "/"; + path += name; + return path.GetBuffer(); +} + +CPCHAR CEnv::GetRFSFullPath(int index, CPCHAR name, DMString & path) +{ + return GetFullPath(GetRFS(index),name,path); +} + + +BOOLEAN CEnv::Init() +{ + const char* szEnv = XPL_DM_GetEnv(SYNCML_DM_SETTINGS_PATH); + + if ( !szEnv ) + return FALSE; + + DMString strItem, strReminder(szEnv); + + while( DmStringParserGetItem( strItem, strReminder, ':' ) ) + m_aFSes.push_back( strItem ); + + if ( m_aFSes.size() == 0 ) + return FALSE; + + m_szWFS = m_aFSes[0].c_str(); + + if ( m_aFSes.size() > 1 ) + m_szMainRFS = m_aFSes[1].c_str(); + else + m_szMainRFS = m_szWFS; + + return TRUE; +} + +void CEnv::Done() +{ + m_szWFS = m_szMainRFS = ""; + m_aFSes.clear(); +} + + + +bool DmStringParserGetItem( DMString& strItem, DMString& strReminder, char cDelim ) +{ + if ( strReminder[0] == 0 ) + return false; + + const char* s = DmStrchr( strReminder, cDelim ); + int nPos = s ? s - strReminder : -1; //strReminder.find( cDelim ); + + if ( nPos < 0 ){ + strItem = strReminder; + strReminder = ""; + } + else { + strItem.assign( strReminder, nPos ); + strReminder = DMString(s+1); + } + return true; +} + + +void DmParseURI(CPCHAR szPath, DMString& strURI, DMString& strKey ) +{ + const char* szSlashPos = DmStrrchr( szPath, SYNCML_DM_FORWARD_SLASH ); + + if ( !szSlashPos ) + return; + + strURI.assign( szPath, szSlashPos-szPath); + + szSlashPos++; // skip slash + const char* szQuestionPos = DmStrchr( szSlashPos, '?' ); + + if ( szQuestionPos ) { + strKey.assign( szSlashPos, szQuestionPos-szSlashPos ); + } + else + strKey = szSlashPos; +} + +int DmStrToStringVector(const char * pStr, int nLen, DMStringVector& oVector, char cDelim ) +{ + // load/unload plugins + DMString strChild, strList; // = (const char*)pStr; + if (nLen >0) + { + strChild= DMString((const char*)pStr, nLen); + strList= DMString((const char*)pStr, nLen); + } else + { + strChild= (const char*)pStr; + strList = (const char*)pStr; + } + + int i=0; + while ( DmStringParserGetItem( strChild, strList, cDelim ) ) + { + oVector.push_back(strChild); + i++; + } + return i; +} + +char* GetURISegment(char **ppbURI) +{ + return GetStringSegment(ppbURI, SYNCML_DM_FORWARD_SLASH); +} + +char* GetStringSegment(char **ppbURI, char cDelim) +{ + char *pbURI = *ppbURI; + char *pURIStartLocation = pbURI; + + if(pbURI != NULL) + { + pbURI = DmStrchr(pbURI, cDelim); + if(pbURI != NULL) + { + *pbURI++ = SYNCML_DM_NULL; + } + } + *ppbURI = pbURI; + return (pURIStartLocation); +} + +BOOLEAN DmIsParentURI( CPCHAR szParentURI, CPCHAR szChildURI ) +{ + DMParser sURIParserP(szParentURI); + DMParser sURIParserC(szChildURI); + CPCHAR sSegmentP = sURIParserP.nextSegment(); + CPCHAR sSegmentC = sURIParserC.nextSegment(); + + UINT16 countP = sURIParserP.getSegmentsCount(); + UINT16 countC = sURIParserC.getSegmentsCount(); + + if ( countP == 0 ) + return TRUE; + + if ( countP > countC ) + return FALSE; + + while ( sSegmentP && sSegmentC ) + { + if ( *sSegmentP != '*' && *sSegmentC != '*' && DmStrcmp(sSegmentC, sSegmentP) != 0 ) + { + return FALSE; + } + + sSegmentP = sURIParserP.nextSegment(); + sSegmentC = sURIParserC.nextSegment(); + } + return TRUE; +} + + +SYNCML_DM_RET_STATUS_T +DmIsDMAccNodePath(CPCHAR szPath) +{ + //CPCHAR dm_ver = XPL_DM_GetEnv(SYNCML_DM_VERSION); + SYNCML_DM_RET_STATUS_T result = SYNCML_DM_COMMAND_INVALID_URI; + + const char *found = NULL; + + if( dmTreeObj.IsVersion_12() ) + { + found = DmStrstr(szPath, DM_DMACC_1_1_URI ); + } + else + { + found = DmStrstr(szPath, DM_DMACC_1_2_URI ); + } + + result = found && ( found == szPath ) + ? SYNCML_DM_FEATURE_NOT_SUPPORTED + : SYNCML_DM_SUCCESS; + + return result; +} + +BOOLEAN +DmIsEnabledURI(CPCHAR szPath) +{ + + SYNCML_DM_RET_STATUS_T dm_stat; + + dm_stat = DmIsDMAccNodePath(szPath); + if ( dm_stat == SYNCML_DM_FEATURE_NOT_SUPPORTED ) + return FALSE; + + return XPL_DM_IsFeatureEnabled(szPath); +} diff --git a/engine/dmlib/dmengine/dm_util/src/dmbuffer.cc b/engine/dmlib/dmengine/dm_util/src/dmbuffer.cc new file mode 100644 index 0000000..b51fcbd --- /dev/null +++ b/engine/dmlib/dmengine/dm_util/src/dmbuffer.cc @@ -0,0 +1,208 @@ +#include "dmStringUtil.h" +#include "dmbuffer.h" +#include "dmdefs.h" +#include "xpl_Logger.h" + +DMBuffer::DMBuffer() +{ + m_pBuf = NULL; + m_nCapacity = 0; + m_nSize = 0; +} + +DMBuffer::~DMBuffer() +{ + FreeAndSetNull(m_pBuf); + m_nCapacity = 0; + m_nSize = 0; +} + + +DMBuffer& DMBuffer::operator=(const DMBuffer & buffer ) +{ + assign(buffer.getBuffer(),buffer.getSize()); + return *this; +} + +UINT8 * DMBuffer::allocate(UINT32 nCapacity) +{ + if ( !nCapacity ) + return m_pBuf; + + m_nSize = 0; + if ( m_nCapacity < nCapacity + 1 ) + { + FreeAndSetNull(m_pBuf); + m_pBuf = (UINT8*)DmAllocMem(nCapacity+1); + if ( m_pBuf ) + { + m_nCapacity = nCapacity+1; + memset(m_pBuf,0,m_nCapacity); + } + else + { + m_nCapacity = 0; + XPL_LOG_DM_TMN_Error(("DMBuffer::Allocate : Unable to allocate memory\n")); + } + } + else + if ( m_pBuf ) + memset(m_pBuf,0,m_nCapacity); + return m_pBuf; +} + +void DMBuffer::reset() +{ + m_pBuf = NULL; + m_nCapacity = 0; + m_nSize = 0; +} +void DMBuffer::free() +{ + FreeAndSetNull(m_pBuf); + m_nCapacity = 0; + m_nSize = 0; +} + +void DMBuffer::clear() +{ + if ( m_pBuf ) + { + memset(m_pBuf,0,m_nCapacity); + m_nSize = 0; + } +} + +UINT8 * DMBuffer::assign(CPCHAR szStr) +{ + return assign((UINT8*)szStr,DmStrlen(szStr)); +} +void DMBuffer::append(const UINT8 * pBuffer, INT32 size) +{ + if ( m_pBuf && (m_nSize + size <= m_nCapacity)) + { + memcpy((UINT8*)&m_pBuf[m_nSize],pBuffer,size); + m_nSize += size; + } +} + +UINT8 * DMBuffer::assign(const UINT8 * pBuffer, INT32 size) +{ + allocate(size); + if ( m_pBuf ) + { + memcpy(m_pBuf,pBuffer,size); + m_pBuf[size] = (UINT8)'\0'; + m_nSize = size; + } + else + { + m_nSize = 0; + } + return m_pBuf; +} + +void DMBuffer::setSize(UINT32 size) +{ + if ( size == 0 ) + clear(); + else + { + if ( size <= m_nCapacity-1 ) + { + m_nSize = size; + } + else + { + m_nSize = m_nCapacity - 1; + } + m_pBuf[m_nSize] = (UINT8)'\0'; + } +} + + +void DMBuffer::copyTo(UINT8 ** pBuffer) const +{ + if ( pBuffer == NULL ) + return; + + *pBuffer = NULL; + + *pBuffer = (UINT8*)DmAllocMem(m_nSize+1); + if ( *pBuffer == NULL ) + { + XPL_LOG_DM_TMN_Error(("DMBuffer::copyTo : Unable to allocate memory\n")); + return; + } + if ( m_nSize ) + memcpy(*pBuffer,m_pBuf,m_nSize+1); + else + (*pBuffer)[0] = 0; +} + + +void DMBuffer::copyTo(DMString &sStr) const +{ + + if ( m_nSize == 0 ) + return; + + sStr.assign((char*)m_pBuf,m_nSize); +} +void DMBuffer::copyTo(INT32 offset,INT32 size, DMBuffer& pBuffer) const +{ + if(offset > m_nSize) + return; + + pBuffer.assign((char*)&m_pBuf[offset],size); +} +void DMBuffer::copyTo(char * pStr) const +{ + if ( pStr == NULL ) + return; + + if ( m_nSize == 0 ) + return; + + memcpy(pStr,m_pBuf,m_nSize+1); +} + +BOOLEAN DMBuffer::compare(CPCHAR pStr) const +{ + if ( !m_nSize || m_nSize != DmStrlen(pStr) ) + return FALSE; + return ( DmStrncmp(pStr,(CPCHAR)m_pBuf,m_nSize) == 0 ? TRUE : FALSE ); + +} + + +BOOLEAN DMBuffer::compare(CPCHAR pStr, UINT32 size) const +{ + + if ( !m_nSize || m_nSize < size ) + return FALSE; + + return ( DmStrncmp(pStr,(CPCHAR)m_pBuf,size) == 0 ? TRUE : FALSE ); + +} + + + +void DMBuffer::attach(UINT8 * pBuffer, INT32 nCapacity) +{ + FreeAndSetNull(m_pBuf); + m_pBuf = pBuffer; + m_nCapacity = nCapacity; + m_nSize = nCapacity-1; + m_pBuf[m_nSize] = (UINT8)'\0'; +} + +UINT8 * DMBuffer::detach() +{ + UINT8 *pBuffer = m_pBuf; + m_pBuf = NULL; + m_nCapacity = 0; + m_nSize = 0; + return pBuffer; +} + diff --git a/engine/dmlib/dmengine/dm_util/src/dmtoken.cc b/engine/dmlib/dmengine/dm_util/src/dmtoken.cc new file mode 100644 index 0000000..aee3f3a --- /dev/null +++ b/engine/dmlib/dmengine/dm_util/src/dmtoken.cc @@ -0,0 +1,334 @@ +/* + * Copyright (C) 2014 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/*================================================================================================== + +Source Name: dmToken.cc + +General Description: This file contains implementation of utility classes DMToken, DMURI, DMParser + +==================================================================================================*/ + +#include "dmtoken.h" +#include "dmdefs.h" +#include "xpl_Logger.h" +#include "syncml_dm_data_types.h" +#include "dm_tree_class.H" + +DMToken::DMToken() +{ + m_pDelimPos = NULL; + m_pStr = NULL; + m_pTokenPos = NULL; + m_cDelim = SYNCML_DM_COMMA; + m_bIsAlloc = TRUE; +} + +DMToken::DMToken(char delimeter) +{ + m_pDelimPos = NULL; + m_pStr = NULL; + m_pTokenPos = NULL; + m_cDelim = delimeter; + m_bIsAlloc = TRUE; +} + + +DMToken::DMToken(BOOLEAN bIsAlloc, CPCHAR str, char delimeter) +{ + + m_pDelimPos = NULL; + m_pStr = NULL; + m_bIsAlloc = bIsAlloc; + m_cDelim = delimeter; + assign(str); +} + + +DMToken::~DMToken() +{ + if ( m_bIsAlloc == TRUE ) + { + FreeAndSetNull(m_pStr); + } + else + reset(); +} + + +CPCHAR DMToken::assign(CPCHAR szStr) +{ + if ( m_bIsAlloc == TRUE ) + { + FreeAndSetNull(m_pStr); + + if ( szStr && szStr[0] ) + { // copy non empty string only + m_pStr = (char *)DmAllocMem( DmStrlen(szStr)+1); + if ( m_pStr != NULL) { + DmStrcpy( m_pStr, szStr ); + } + else { + XPL_LOG_DM_TMN_Error(("DMToken::assign : unable allocate memory\n")); + } + } + } + else + { + reset(); + m_pStr = (char*)szStr; + } + + m_pDelimPos = m_pStr; + m_pTokenPos = m_pStr; + return m_pStr; +} + +CPCHAR DMToken::nextSegment() +{ + + if ( m_pDelimPos == NULL ) + return NULL; + + if ( m_pDelimPos != m_pStr ) + { + *m_pDelimPos = m_cDelim; + m_pTokenPos = m_pDelimPos+1; + } + m_pDelimPos = DmStrchr(m_pTokenPos, m_cDelim); + if(m_pDelimPos != NULL) + { + *m_pDelimPos = SYNCML_DM_NULL; + } + + if ( m_pTokenPos[0] == SYNCML_DM_NULL ) + return NULL; + + return (m_pTokenPos); + +} + + +UINT32 DMToken::getSegmentsCount() +{ + UINT32 count = 0; + char * sTokenPos = m_pStr; + + if ( !sTokenPos ) + return 0; + + reset(); + + m_pDelimPos = DmStrchr(m_pTokenPos,m_cDelim); + while ( m_pDelimPos ) + { + count++; + m_pTokenPos = m_pDelimPos + 1; + m_pDelimPos = DmStrchr(m_pTokenPos,m_cDelim); + } + + if ( *m_pTokenPos == SYNCML_DM_NULL ) + return count; + + m_pDelimPos = m_pStr; + m_pTokenPos = m_pStr; + return count+1; +} + +void DMToken::reset() +{ + if ( m_pDelimPos && m_pDelimPos != m_pStr ) + *m_pDelimPos = m_cDelim; + m_pDelimPos = m_pStr; + m_pTokenPos = m_pStr; +} + +DMURI::DMURI() : DMToken(TRUE, NULL,SYNCML_DM_FORWARD_SLASH) +{ +} + +DMURI::DMURI(BOOLEAN bIsAlloc) : DMToken(bIsAlloc, NULL,SYNCML_DM_FORWARD_SLASH) +{ +} + +DMURI::DMURI(BOOLEAN bIsAlloc, CPCHAR szURI) : DMToken(bIsAlloc, szURI,SYNCML_DM_FORWARD_SLASH) +{ +} + + +CPCHAR DMURI::getTailSegments() const +{ + if ( m_pDelimPos == NULL ) + return NULL; + + if ( m_pDelimPos == m_pStr && *m_pStr != SYNCML_DM_FORWARD_SLASH ) + return m_pStr; + + return m_pDelimPos+1; +} + + +CPCHAR DMURI::getLastSegment() +{ + + if ( m_pStr == NULL ) + return NULL; + + reset(); + char * sPos = DmStrrchr(m_pStr,m_cDelim); + if ( sPos == NULL ) + return NULL; + else + return sPos+1; +} + +CPCHAR DMURI::getParentURI() +{ + + if ( m_pStr == NULL ) + return NULL; + + char * pDelimPosPrev = m_pDelimPos; + m_pDelimPos = DmStrrchr(m_pStr, SYNCML_DM_FORWARD_SLASH); + if ( !m_pDelimPos || m_pDelimPos == m_pStr ) + { + m_pDelimPos = pDelimPosPrev; + return NULL; + } + + *m_pDelimPos = SYNCML_DM_NULL; + if ( pDelimPosPrev != m_pStr ) + *pDelimPosPrev = SYNCML_DM_FORWARD_SLASH; + + + return m_pStr; +} + +DMParser::DMParser(char delimeter) +{ + m_pDelimPos = NULL; + m_pStr = NULL; + m_cDelim = delimeter; + + m_nCurrentSegment = 0; + m_nSegmentsCount = 0; + + m_aSegments = (DM_URI_SEGMENT_T*)DmAllocMem( dmTreeObj.GetMaxPathDepth() * sizeof(DM_URI_SEGMENT_T)); + +} + +DMParser::DMParser(CPCHAR szURI, char delimeter) +{ + m_pDelimPos = NULL; + m_pStr = NULL; + m_cDelim = delimeter; + + + m_nCurrentSegment = 0; + m_nSegmentsCount = 0; + m_aSegments = (DM_URI_SEGMENT_T*)DmAllocMem( dmTreeObj.GetMaxPathDepth() * sizeof(DM_URI_SEGMENT_T)); + assign(szURI); +} + + +DMParser::~DMParser() +{ + reset(); + FreeAndSetNull(m_aSegments); +} + +CPCHAR DMParser::nextSegment() +{ + + if ( m_nCurrentSegment == m_nSegmentsCount ) + return NULL; + + char * pStr = m_aSegments[m_nCurrentSegment].m_pStr; +// XPL_LOG_DM_TMN_Debug(("DMParser::nextSegment, pStr:%s, m_nCurrentSegment:%d, m_nLen:%d\n", pStr, m_nCurrentSegment, m_aSegments[m_nCurrentSegment].m_nLen)); + pStr[m_aSegments[m_nCurrentSegment].m_nLen] = SYNCML_DM_NULL; +// XPL_LOG_DM_TMN_Debug(("DMParser::nextSegment, pStr:%s, m_nCurrentSegment:%d, m_nLen:%d\n", pStr, m_nCurrentSegment, m_aSegments[m_nCurrentSegment].m_nLen)); + + m_nCurrentSegment++; + + return pStr; +} + + +CPCHAR DMParser::assign(CPCHAR szStr) +{ + DM_URI_SEGMENT_T segment; + + if ( !m_aSegments ) + return NULL; + + m_pStr = (char*)szStr; + + m_nCurrentSegment = 0; + m_nSegmentsCount = 0; + + if ( !m_pStr ) + return m_pStr; + + + m_pTokenPos = m_pStr; + m_pDelimPos = DmStrchr(m_pTokenPos,m_cDelim); + + while ( m_pDelimPos ) + { + segment.m_pStr = m_pTokenPos; + segment.m_nLen = m_pDelimPos - m_pTokenPos; + m_aSegments[m_nSegmentsCount++] = segment; + m_pTokenPos = m_pDelimPos + 1; + m_pDelimPos = DmStrchr(m_pTokenPos,m_cDelim); + } + + if ( *m_pTokenPos == SYNCML_DM_NULL ) + return m_pStr; + + + segment.m_pStr = m_pTokenPos; + segment.m_nLen = DmStrlen(m_pTokenPos); + m_aSegments[m_nSegmentsCount++] = segment; + return m_pStr; + +} + +void DMParser::reset() +{ + if ( !m_aSegments ) + return; + + if ( m_nCurrentSegment > 0 ) + { + for (int i=0; i<m_nSegmentsCount-1; i++) + m_aSegments[i].m_pStr[m_aSegments[i].m_nLen] = m_cDelim; + } + + m_nCurrentSegment = 0; +} + +BOOLEAN DMParser::findSegment(CPCHAR szSegment) +{ + + for (int i=0; i<m_nSegmentsCount; i++) + { + m_aSegments[i].m_pStr[m_aSegments[i].m_nLen] = SYNCML_DM_NULL; + if ( DmStrcmp(m_aSegments[i].m_pStr,szSegment) == 0) + return TRUE; + } + + return FALSE; +} |