1 /*************************************************************************/ 2 /* module: Definition of WBXML/XML tags for the en-/decoder */ 3 /* file: XLTTags.c */ 4 /* target system: all */ 5 /* target OS: all */ 6 /*************************************************************************/ 7 8 /* 9 * Copyright Notice 10 * Copyright (c) Ericsson, IBM, Lotus, Matsushita Communication 11 * Industrial Co., Ltd., Motorola, Nokia, Openwave Systems, Inc., 12 * Palm, Inc., Psion, Starfish Software, Symbian, Ltd. (2001). 13 * All Rights Reserved. 14 * Implementation of all or part of any Specification may require 15 * licenses under third party intellectual property rights, 16 * including without limitation, patent rights (such a third party 17 * may or may not be a Supporter). The Sponsors of the Specification 18 * are not responsible and shall not be held responsible in any 19 * manner for identifying or failing to identify any or all such 20 * third party intellectual property rights. 21 * 22 * THIS DOCUMENT AND THE INFORMATION CONTAINED HEREIN ARE PROVIDED 23 * ON AN "AS IS" BASIS WITHOUT WARRANTY OF ANY KIND AND ERICSSON, IBM, 24 * LOTUS, MATSUSHITA COMMUNICATION INDUSTRIAL CO. LTD, MOTOROLA, 25 * NOKIA, PALM INC., PSION, STARFISH SOFTWARE AND ALL OTHER SYNCML 26 * SPONSORS DISCLAIM ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING 27 * BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF THE INFORMATION 28 * HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED WARRANTIES OF 29 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT 30 * SHALL ERICSSON, IBM, LOTUS, MATSUSHITA COMMUNICATION INDUSTRIAL CO., 31 * LTD, MOTOROLA, NOKIA, PALM INC., PSION, STARFISH SOFTWARE OR ANY 32 * OTHER SYNCML SPONSOR BE LIABLE TO ANY PARTY FOR ANY LOSS OF 33 * PROFITS, LOSS OF BUSINESS, LOSS OF USE OF DATA, INTERRUPTION OF 34 * BUSINESS, OR FOR DIRECT, INDIRECT, SPECIAL OR EXEMPLARY, INCIDENTAL, 35 * PUNITIVE OR CONSEQUENTIAL DAMAGES OF ANY KIND IN CONNECTION WITH 36 * THIS DOCUMENT OR THE INFORMATION CONTAINED HEREIN, EVEN IF ADVISED 37 * OF THE POSSIBILITY OF SUCH LOSS OR DAMAGE. 38 * 39 * The above notice and this paragraph must be included on all copies 40 * of this document that are made. 41 * 42 */ 43 44 45 #include "xlttags.h" 46 47 #include <libstr.h> 48 #include <smlerr.h> 49 #include <libmem.h> 50 #include <libutil.h> 51 #include <mgr.h> 52 53 #include "xltmetinf.h" 54 #include "xltdevinf.h" 55 #include "xlttagtbl.h" 56 57 58 // %%% luz:2003-07-31: added SyncML namespace tables 59 const char * const SyncMLNamespaces[SML_NUM_VERS] = { 60 "???", 61 "SYNCML:SYNCML1.0", 62 "SYNCML:SYNCML1.1", 63 "SYNCML:SYNCML1.2" 64 }; 65 66 /* local prototypes */ 67 #ifdef NOWSM 68 const // without WSM, the tag table is a global read-only constant 69 #endif 70 TagPtr_t getTagTable(SmlPcdataExtension_t ext); 71 72 //SmlPcdataExtension_t getByName(String_t ns); 73 void freeDtdTable(DtdPtr_t tbl); 74 75 #ifdef NOWSM 76 const // without WSM, the DTD table is a global read-only constant 77 #endif 78 DtdPtr_t getDtdTable(); 79 80 81 // free table obtained with getDtdTable() 82 void freeDtdTable(DtdPtr_t tbl) 83 { 84 #ifndef NOWSM 85 // only with WSM this is an allocated table 86 smlLibFree(tbl); 87 #endif 88 } 89 90 /** 91 * FUNCTION: getDtdTable 92 * 93 * Returns a copy of the table containing all known (sub) dtd's 94 * On error a NULL pointer is returned 95 */ 96 #ifdef NOWSM 97 const // without WSM, the DTD table is a global read-only constant 98 #endif 99 DtdPtr_t getDtdTable() { 100 #ifdef NOWSM 101 // NOWSM method, table is const, just return a pointer 102 static const Dtd_t XltDtdTbl[] = { 103 { "SYNCML:SYNCML1.0", SML_EXT_UNDEFINED}, // %%% note that this is the default, will be override by syncml version specific string from 104 { "syncml:metinf", SML_EXT_METINF}, 105 { "syncml:devinf", SML_EXT_DEVINF}, 106 { "syncml:dmddf1.2", SML_EXT_DMTND}, 107 { NULL, SML_EXT_LAST} 108 }; 109 return (DtdPtr_t)XltDtdTbl; 110 #else 111 // WSM method wasting a lot of memory 112 DtdPtr_t _tmpPtr; 113 114 Dtd_t XltDtdTbl[] = { 115 { "SYNCML:SYNCML1.0", SML_EXT_UNDEFINED}, 116 { "syncml:metinf", SML_EXT_METINF}, 117 { "syncml:devinf", SML_EXT_DEVINF}, 118 { "syncml:dmddf1.2", SML_EXT_DMTND}, 119 { NULL, SML_EXT_LAST} 120 }; 121 _tmpPtr = NULL; 122 _tmpPtr = (DtdPtr_t)smlLibMalloc(sizeof(XltDtdTbl)); 123 if (_tmpPtr == NULL) return NULL; 124 smlLibMemcpy(_tmpPtr, &XltDtdTbl, sizeof(XltDtdTbl)); 125 return _tmpPtr; 126 #endif 127 } 128 129 130 /** 131 * FUNCTION: getExtName 132 * 133 * Returns the official name for a given extention/sub-DTD 134 * and stored it in 'name'. If not found name isn't modified 135 */ 136 // %%% luz:2003-04-24: added syncmlvers parameter 137 // %%% luz:2003-07-31: changed to vers enum 138 Ret_t getExtName(SmlPcdataExtension_t ext, String_t *name, SmlVersion_t vers) { 139 DtdPtr_t dtdhead = getDtdTable(); 140 DtdPtr_t dtd = dtdhead; 141 const char *dtdname; 142 if (!dtdhead) return -1; 143 for (;dtd->ext != SML_EXT_LAST; dtd++) { 144 if (!dtd->name) continue; /* skip empty names (should not appear but better be on the safe side) */ 145 if (dtd->ext == ext) { 146 String_t _tmp; 147 // this is the default 148 dtdname=dtd->name; 149 // %%% luz:2003-04-24: added dynamic generation of namespace according to SyncML version 150 if (ext==SML_EXT_UNDEFINED && vers!=SML_VERS_UNDEF) { 151 // this requests SyncML namespace 152 if (vers >= SML_NUM_VERS ) 153 { 154 freeDtdTable(dtdhead); 155 return SML_ERR_INVALID_SIZE; 156 } 157 dtdname=SyncMLNamespaces[vers]; 158 } 159 _tmp = smlLibMalloc(smlLibStrlen(dtdname)+1); 160 if (!_tmp) { 161 freeDtdTable(dtdhead); 162 return SML_ERR_NOT_ENOUGH_SPACE; 163 } 164 smlLibStrcpy(_tmp, dtdname); 165 freeDtdTable(dtdhead); 166 *name = _tmp; 167 return SML_ERR_OK; 168 } 169 } 170 freeDtdTable(dtdhead); 171 return -1; 172 } 173 174 /** 175 * FUNCTION: getCpByName 176 * 177 * Returns the codepage constant assoziated with the name stored in 'ns' 178 * 179 * RETURN: a SmlPcdataExtension_t representing the corresponding codepage id. 180 * If no corresponding codepage is found -1 is returned. 181 */ 182 SmlPcdataExtension_t getExtByName(String_t ns) { 183 DtdPtr_t dtdhead = getDtdTable(); 184 DtdPtr_t dtd = dtdhead; 185 SmlPcdataExtension_t ext = (SmlPcdataExtension_t) 255; 186 if (!dtdhead) return SML_EXT_UNDEFINED; 187 for (;dtd->ext != SML_EXT_LAST; dtd++) { 188 const char *dtdname=dtd->name; 189 if (!dtdname) continue; /* skip empty names (should not appear but better be on the safe side) */ 190 if (dtd->ext==SML_EXT_UNDEFINED && smlLibStrncmp("SYNCML:SYNCML",ns,13)==0) { 191 // SyncML namespace is ok without checking version! 192 ext = SML_EXT_UNDEFINED; 193 break; 194 } 195 else if (smlLibStrcmp(dtdname,ns) == 0) { 196 ext = dtd->ext; 197 break; 198 } 199 } 200 freeDtdTable(dtdhead); 201 return ext; 202 } 203 204 205 206 /* if the commands are not defined we let the functions point to NULL */ 207 #ifndef RESULT_RECEIVE 208 #define buildResults NULL 209 #endif 210 211 #ifndef MAP_RECEIVE 212 #define buildMap NULL 213 #endif 214 215 #ifndef EXEC_RECEIVE 216 #define buildExec NULL 217 #endif 218 219 #if !defined(ATOM_RECEIVE) && !defined(SEQUENCE_RECEIVE) 220 #define buildAtomOrSeq NULL 221 #endif 222 223 #ifndef SEARCH_RECEIVE 224 #define buildSearch NULL 225 #endif 226 227 228 /** 229 * FUNCTION: getTagTable 230 * 231 * Returns the tag table - this function is used to avoid a global 232 * tag table variable 233 * 234 * RETURN: a pointer to the tag table containing tag ids, 235 * codepages, wbxml tags and xml tags 236 */ 237 /* T.K. initialized the structure via _TOKEN Macro, to take 238 * out the XML name tags when not compiled with XML support. 239 * In addtion removed the (unused) pointer for the build functions 240 */ 241 #ifdef __SML_XML__ 242 #define _TOKEN(id, wbxml, xml) (id), (wbxml), (xml) 243 #else 244 #define _TOKEN(id, wbxml, xml) (id), (wbxml), "" 245 #endif 246 247 #ifdef NOWSM 248 const // without WSM, the tag table is a global read-only constant 249 #endif 250 TagPtr_t getTagTable(SmlPcdataExtension_t ext) 251 { 252 #ifndef NOWSM 253 int mySize = 0; 254 TagPtr_t _tmpTagPtr; 255 SyncMLInfoPtr_t pGA = NULL; 256 #else 257 TagPtr_t _tmpTagPtr=NULL; 258 #endif 259 /* standard SyncML codepage */ 260 static const Tag_t syncml[] = 261 { 262 { _TOKEN(TN_ADD, 0x05, "Add")}, 263 { _TOKEN(TN_ALERT, 0x06, "Alert")}, 264 { _TOKEN(TN_ARCHIVE, 0x07, "Archive")}, 265 { _TOKEN(TN_ATOMIC, 0x08, "Atomic")}, 266 { _TOKEN(TN_CHAL, 0x09, "Chal")}, 267 { _TOKEN(TN_CMD, 0x0A, "Cmd")}, 268 { _TOKEN(TN_CMDID, 0x0B, "CmdID")}, 269 { _TOKEN(TN_CMDREF, 0x0C, "CmdRef")}, 270 { _TOKEN(TN_COPY, 0x0D, "Copy")}, 271 { _TOKEN(TN_CRED, 0x0E, "Cred")}, 272 { _TOKEN(TN_DATA, 0x0F, "Data")}, 273 { _TOKEN(TN_DELETE, 0x10, "Delete")}, 274 { _TOKEN(TN_EXEC, 0x11, "Exec")}, 275 { _TOKEN(TN_FINAL, 0x12, "Final")}, 276 { _TOKEN(TN_GET, 0x13, "Get")}, 277 { _TOKEN(TN_ITEM, 0x14, "Item")}, 278 { _TOKEN(TN_LANG, 0x15, "Lang")}, 279 { _TOKEN(TN_LOCNAME, 0x16, "LocName")}, 280 { _TOKEN(TN_LOCURI, 0x17, "LocURI")}, 281 { _TOKEN(TN_MAP, 0x18, "Map")}, 282 { _TOKEN(TN_MAPITEM, 0x19, "MapItem")}, 283 { _TOKEN(TN_META, 0x1A, "Meta")}, 284 { _TOKEN(TN_MSGID, 0x1B, "MsgID")}, 285 { _TOKEN(TN_MSGREF, 0x1C, "MsgRef")}, 286 { _TOKEN(TN_NORESP, 0x1D, "NoResp")}, 287 { _TOKEN(TN_NORESULTS, 0x1E, "NoResults")}, 288 { _TOKEN(TN_PUT, 0x1F, "Put")}, 289 { _TOKEN(TN_REPLACE, 0x20, "Replace")}, 290 { _TOKEN(TN_RESPURI, 0x21, "RespURI")}, 291 { _TOKEN(TN_RESULTS, 0x22, "Results")}, 292 { _TOKEN(TN_SEARCH, 0x23, "Search")}, 293 { _TOKEN(TN_SEQUENCE, 0x24, "Sequence")}, 294 { _TOKEN(TN_SESSIONID, 0x25, "SessionID")}, 295 { _TOKEN(TN_SFTDEL, 0x26, "SftDel")}, 296 { _TOKEN(TN_SOURCE, 0x27, "Source")}, 297 { _TOKEN(TN_SOURCEREF, 0x28, "SourceRef")}, 298 { _TOKEN(TN_STATUS, 0x29, "Status")}, 299 { _TOKEN(TN_SYNC, 0x2A, "Sync")}, 300 { _TOKEN(TN_SYNCBODY, 0x2B, "SyncBody")}, 301 { _TOKEN(TN_SYNCHDR, 0x2C, "SyncHdr")}, 302 { _TOKEN(TN_SYNCML, 0x2D, "SyncML")}, 303 { _TOKEN(TN_TARGET, 0x2E, "Target")}, 304 { _TOKEN(TN_TARGETREF, 0x2F, "TargetRef")}, 305 { _TOKEN(TN_VERSION, 0x31, "VerDTD")}, 306 { _TOKEN(TN_PROTO, 0x32, "VerProto")}, 307 { _TOKEN(TN_NUMBEROFCHANGES,0x33, "NumberOfChanges")}, 308 { _TOKEN(TN_MOREDATA, 0x34, "MoreData")}, 309 /* from version 1.2 */ 310 { _TOKEN(TN_CORRELATOR, 0x3C, "Correlator")}, 311 312 { _TOKEN(TN_UNDEF, 0x00, NULL)} 313 }; 314 315 #ifdef __USE_METINF__ 316 static const Tag_t metinf[] = { 317 { _TOKEN(TN_METINF_ANCHOR, 0x05, "Anchor")}, 318 { _TOKEN(TN_METINF_EMI, 0x06, "EMI")}, 319 { _TOKEN(TN_METINF_FORMAT, 0x07, "Format")}, 320 { _TOKEN(TN_METINF_FREEID, 0x08, "FreeID")}, 321 { _TOKEN(TN_METINF_FREEMEM, 0x09, "FreeMem")}, 322 { _TOKEN(TN_METINF_LAST, 0x0A, "Last")}, 323 { _TOKEN(TN_METINF_MARK, 0x0B, "Mark")}, 324 { _TOKEN(TN_METINF_MAXMSGSIZE, 0x0C, "MaxMsgSize")}, 325 { _TOKEN(TN_METINF_MEM, 0x0D, "Mem")}, 326 { _TOKEN(TN_METINF_METINF, 0x0E, "MetInf")}, 327 { _TOKEN(TN_METINF_NEXT, 0x0F, "Next")}, 328 { _TOKEN(TN_METINF_NEXTNONCE, 0x10, "NextNonce")}, 329 { _TOKEN(TN_METINF_SHAREDMEM, 0x11, "SharedMem")}, 330 { _TOKEN(TN_METINF_SIZE, 0x12, "Size")}, 331 { _TOKEN(TN_METINF_TYPE, 0x13, "Type")}, 332 { _TOKEN(TN_METINF_VERSION, 0x14, "Version")}, 333 /* SCTSTK - 18/03/2002, S.H. 2002-04-05 : SyncML 1.1 */ 334 { _TOKEN(TN_METINF_MAXOBJSIZE, 0x15, "MaxObjSize")}, 335 { _TOKEN(TN_UNDEF, 0x00, NULL)} 336 }; 337 #endif 338 339 340 #ifdef __USE_DEVINF__ 341 static const Tag_t devinf[] = { 342 {_TOKEN(TN_DEVINF_CTCAP, 0x05, "CTCap")}, 343 {_TOKEN(TN_DEVINF_CTTYPE, 0x06, "CTType")}, 344 {_TOKEN(TN_DEVINF_DATASTORE, 0x07, "DataStore")}, 345 {_TOKEN(TN_DEVINF_DATATYPE, 0x08, "DataType")}, 346 {_TOKEN(TN_DEVINF_DEVID, 0x09, "DevID")}, 347 {_TOKEN(TN_DEVINF_DEVINF, 0x0A, "DevInf")}, 348 {_TOKEN(TN_DEVINF_DEVTYP, 0x0B, "DevTyp")}, 349 {_TOKEN(TN_DEVINF_DISPLAYNAME, 0x0C, "DisplayName")}, 350 {_TOKEN(TN_DEVINF_DSMEM, 0x0D, "DSMem")}, 351 {_TOKEN(TN_DEVINF_EXT, 0x0E, "Ext")}, 352 {_TOKEN(TN_DEVINF_FWV, 0x0F, "FwV")}, 353 {_TOKEN(TN_DEVINF_HWV, 0x10, "HwV")}, 354 {_TOKEN(TN_DEVINF_MAN, 0x11, "Man")}, 355 {_TOKEN(TN_DEVINF_MAXGUIDSIZE, 0x12, "MaxGUIDSize")}, 356 {_TOKEN(TN_DEVINF_MAXID, 0x13, "MaxID")}, 357 {_TOKEN(TN_DEVINF_MAXMEM, 0x14, "MaxMem")}, 358 {_TOKEN(TN_DEVINF_MOD, 0x15, "Mod")}, 359 {_TOKEN(TN_DEVINF_OEM, 0x16, "OEM")}, 360 {_TOKEN(TN_DEVINF_PARAMNAME, 0x17, "ParamName")}, 361 {_TOKEN(TN_DEVINF_PROPNAME, 0x18, "PropName")}, 362 {_TOKEN(TN_DEVINF_RX, 0x19, "Rx")}, 363 {_TOKEN(TN_DEVINF_RXPREF, 0x1A, "Rx-Pref")}, 364 {_TOKEN(TN_DEVINF_SHAREDMEM, 0x1B, "SharedMem")}, 365 {_TOKEN(TN_DEVINF_SIZE, 0x1C, "Size")}, 366 {_TOKEN(TN_DEVINF_SOURCEREF, 0x1D, "SourceRef")}, 367 {_TOKEN(TN_DEVINF_SWV, 0x1E, "SwV")}, 368 {_TOKEN(TN_DEVINF_SYNCCAP, 0x1F, "SyncCap")}, 369 {_TOKEN(TN_DEVINF_SYNCTYPE, 0x20, "SyncType")}, 370 {_TOKEN(TN_DEVINF_TX, 0x21, "Tx")}, 371 {_TOKEN(TN_DEVINF_TXPREF, 0x22, "Tx-Pref")}, 372 {_TOKEN(TN_DEVINF_VALENUM, 0x23, "ValEnum")}, 373 {_TOKEN(TN_DEVINF_VERCT, 0x24, "VerCT")}, 374 {_TOKEN(TN_DEVINF_VERDTD, 0x25, "VerDTD")}, 375 {_TOKEN(TN_DEVINF_XNAM, 0x26, "XNam")}, 376 {_TOKEN(TN_DEVINF_XVAL, 0x27, "XVal")}, 377 // %%% luz:2003-04-28 : added these, they were missing 378 {_TOKEN(TN_DEVINF_UTC, 0x28, "UTC")}, 379 {_TOKEN(TN_DEVINF_NOFM, 0x29, "SupportNumberOfChanges")}, 380 {_TOKEN(TN_DEVINF_LARGEOBJECT, 0x2A, "SupportLargeObjs")}, 381 // %%% end luz 382 { _TOKEN(TN_UNDEF, 0x00, NULL)} 383 }; 384 #endif 385 386 #ifdef __USE_DMTND__ 387 static const Tag_t dmtnd[] = { 388 { _TOKEN(TN_DMTND_AccessType, 0x05, "AccessType")}, 389 { _TOKEN(TN_DMTND_ACL, 0x06, "ACL")}, 390 { _TOKEN(TN_DMTND_Add, 0x07, "Add")}, 391 { _TOKEN(TN_DMTND_b64, 0x08, "b64")}, 392 { _TOKEN(TN_DMTND_bin, 0x09, "bin")}, 393 { _TOKEN(TN_DMTND_bool, 0x0A, "bool")}, 394 { _TOKEN(TN_DMTND_chr, 0x0B, "chr")}, 395 { _TOKEN(TN_DMTND_CaseSense, 0x0C, "CaseSense")}, 396 { _TOKEN(TN_DMTND_CIS, 0x0D, "CIS")}, 397 { _TOKEN(TN_DMTND_Copy, 0x0E, "Copy")}, 398 { _TOKEN(TN_DMTND_CS, 0x0F, "CS")}, 399 { _TOKEN(TN_DMTND_date, 0x10, "date")}, 400 { _TOKEN(TN_DMTND_DDFName, 0x11, "DDFName")}, 401 { _TOKEN(TN_DMTND_DefaultValue, 0x12, "DefaultValue")}, 402 { _TOKEN(TN_DMTND_Delete, 0x13, "Delete")}, 403 { _TOKEN(TN_DMTND_Description, 0x14, "Description")}, 404 { _TOKEN(TN_DMTND_DFFormat, 0x15, "DFFormat")}, 405 { _TOKEN(TN_DMTND_DFProperties, 0x16, "DFProperties")}, 406 { _TOKEN(TN_DMTND_DFTitle, 0x17, "DFTitle")}, 407 { _TOKEN(TN_DMTND_DFType, 0x18, "DFType")}, 408 { _TOKEN(TN_DMTND_Dynamic, 0x19, "Dynamic")}, 409 { _TOKEN(TN_DMTND_Exec, 0x1A, "Exec")}, 410 { _TOKEN(TN_DMTND_float, 0x1B, "float")}, 411 { _TOKEN(TN_DMTND_Format, 0x1C, "Format")}, 412 { _TOKEN(TN_DMTND_Get, 0x1D, "Get")}, 413 { _TOKEN(TN_DMTND_int, 0x1E, "int")}, 414 { _TOKEN(TN_DMTND_Man, 0x1F, "Man")}, 415 { _TOKEN(TN_DMTND_MgmtTree, 0x20, "MgmtTree")}, 416 { _TOKEN(TN_DMTND_MIME, 0x21, "MIME")}, 417 { _TOKEN(TN_DMTND_Mod, 0x22, "Mod")}, 418 { _TOKEN(TN_DMTND_Name, 0x23, "Name")}, 419 { _TOKEN(TN_DMTND_Node, 0x24, "Node")}, 420 { _TOKEN(TN_DMTND_node, 0x25, "node")}, 421 { _TOKEN(TN_DMTND_NodeName, 0x26, "NodeName")}, 422 { _TOKEN(TN_DMTND_null, 0x27, "null")}, 423 { _TOKEN(TN_DMTND_Occurrence, 0x28, "Occurrence")}, 424 { _TOKEN(TN_DMTND_One, 0x29, "One")}, 425 { _TOKEN(TN_DMTND_OneOrMore, 0x2A, "OneOrMore")}, 426 { _TOKEN(TN_DMTND_OneOrN, 0x2B, "OneOrN")}, 427 { _TOKEN(TN_DMTND_Path, 0x2C, "Path")}, 428 { _TOKEN(TN_DMTND_Permanent, 0x2D, "Permanent")}, 429 { _TOKEN(TN_DMTND_Replace, 0x2E, "Replace")}, 430 { _TOKEN(TN_DMTND_RTProperties, 0x2F, "RTProperties")}, 431 { _TOKEN(TN_DMTND_Scope, 0x30, "Scope")}, 432 { _TOKEN(TN_DMTND_Size, 0x31, "Size")}, 433 { _TOKEN(TN_DMTND_time, 0x32, "time")}, 434 { _TOKEN(TN_DMTND_Title, 0x33, "Title")}, 435 { _TOKEN(TN_DMTND_TStamp, 0x34, "TStamp")}, 436 { _TOKEN(TN_DMTND_Type, 0x35, "Type")}, 437 { _TOKEN(TN_DMTND_Value, 0x36, "Value")}, 438 { _TOKEN(TN_DMTND_VerDTD, 0x37, "VerDTD")}, 439 { _TOKEN(TN_DMTND_VerNo, 0x38, "VerNo")}, 440 { _TOKEN(TN_DMTND_xml, 0x39, "xml")}, 441 { _TOKEN(TN_DMTND_ZeroOrMore, 0x3A, "ZeroOrMore")}, 442 { _TOKEN(TN_DMTND_ZeroOrN, 0x3B, "ZeroOrN")}, 443 { _TOKEN(TN_DMTND_ZeroOrOne, 0x3C, "ZeroOrOne") } 444 }; 445 #endif 446 447 #ifndef NOWSM 448 _tmpTagPtr = NULL; 449 pGA = mgrGetSyncMLAnchor(); 450 if (pGA == NULL) return NULL; 451 #endif 452 453 /* get the correct codepage */ 454 if (ext == SML_EXT_UNDEFINED) { 455 #ifndef NOWSM 456 _tmpTagPtr = pGA->tokTbl->SyncML; 457 if (_tmpTagPtr == NULL) { 458 mySize = sizeof(syncml); 459 pGA->tokTbl->SyncML = (TagPtr_t)smlLibMalloc(mySize); 460 if (pGA->tokTbl->SyncML == NULL) return NULL; 461 smlLibMemcpy(pGA->tokTbl->SyncML, &syncml, mySize); 462 _tmpTagPtr = pGA->tokTbl->SyncML; 463 } 464 #else 465 _tmpTagPtr=(TagPtr_t)syncml; 466 #endif 467 } 468 469 #ifdef __USE_METINF__ 470 else if (ext == SML_EXT_METINF) { 471 #ifndef NOWSM 472 _tmpTagPtr = pGA->tokTbl->MetInf; 473 if (_tmpTagPtr == NULL) { 474 mySize = sizeof(metinf); 475 pGA->tokTbl->MetInf = (TagPtr_t)smlLibMalloc(mySize); 476 if (pGA->tokTbl->MetInf == NULL) return NULL; 477 smlLibMemcpy(pGA->tokTbl->MetInf, &metinf, mySize); 478 _tmpTagPtr = pGA->tokTbl->MetInf; 479 } 480 #else 481 _tmpTagPtr=(TagPtr_t)metinf; 482 #endif 483 } 484 #endif 485 486 #ifdef __USE_DEVINF__ 487 else if (ext == SML_EXT_DEVINF) { 488 #ifndef NOWSM 489 _tmpTagPtr = pGA->tokTbl->DevInf; 490 if (_tmpTagPtr == NULL) { 491 mySize = sizeof(devinf); 492 pGA->tokTbl->DevInf = (TagPtr_t)smlLibMalloc(mySize); 493 if (pGA->tokTbl->DevInf == NULL) return NULL; 494 smlLibMemcpy(pGA->tokTbl->DevInf, &devinf, mySize); 495 _tmpTagPtr = pGA->tokTbl->DevInf; 496 } 497 #else 498 _tmpTagPtr=(TagPtr_t)devinf; 499 #endif 500 } 501 #endif 502 503 #ifdef __USE_DMTND__ 504 else if (ext == SML_EXT_DMTND) { 505 #ifndef NOWSM 506 _tmpTagPtr = pGA->tokTbl->DmTnd; 507 if (_tmpTagPtr == NULL) { 508 mySize = sizeof(dmtnd); 509 pGA->tokTbl->DmTnd = (TagPtr_t)smlLibMalloc(mySize); 510 if (pGA->tokTbl->DmTnd == NULL) return NULL; 511 smlLibMemcpy(pGA->tokTbl->DmTnd, &dmtnd, mySize); 512 _tmpTagPtr = pGA->tokTbl->DmTnd; 513 } 514 #else 515 _tmpTagPtr=(TagPtr_t)dmtnd; 516 #endif 517 } 518 #endif 519 520 return _tmpTagPtr; 521 } 522 523 #undef _TOKEN // we don't need that macro any longer 524 525 /** 526 * FUNCTION: getTagString 527 * 528 * Returns a tag string which belongs to a tag ID. 529 * This function is needed for the XML encoding 530 * 531 * PRE-Condition: valid tag ID, the tagSring has to be allocated 532 * 533 * POST-Condition: tag string is returned 534 * 535 * IN: tagId, the ID for the tag 536 * 537 * IN/OUT: tagString, allocated string into which the XML 538 * tag string will be written 539 * 540 * RETURN: 0,if OK 541 */ 542 #ifdef __SML_XML__ 543 Ret_t getTagString(XltTagID_t tagID, String_t tagString, SmlPcdataExtension_t ext) 544 { 545 int i = 0; 546 TagPtr_t pTags = getTagTable(ext); 547 if (pTags == NULL) { 548 tagString[0] = '\0'; 549 return SML_ERR_NOT_ENOUGH_SPACE; 550 } 551 while (((pTags+i)->id) != TN_UNDEF) { 552 if ((((pTags+i)->id) == tagID)) { 553 String_t _tmp = (pTags+i)->xml; 554 smlLibStrcpy(tagString, _tmp); 555 return SML_ERR_OK; 556 } 557 i++; 558 } 559 //smlLibStrcpy(tagString, '\0'); 560 tagString[0] = '\0'; 561 return SML_ERR_XLT_INVAL_PROTO_ELEM; 562 } 563 #endif 564 565 /** 566 * FUNCTION: getTagByte 567 * 568 * Returns a WBXML byte which belongs to a tag ID in a defined codepage. 569 * This function is needed for the WBXML encoding 570 * 571 * PRE-Condition: valid tag ID, valid code page 572 * 573 * POST-Condition: tag byte is returned 574 * 575 * IN: tagId, the ID for the tag 576 * cp, code page group for the tag 577 * pTagByte, the byte representation of the tag 578 * 579 * RETURN: 0, if OK 580 */ 581 Ret_t getTagByte(XltTagID_t tagID, SmlPcdataExtension_t ext, Byte_t *pTagByte) 582 { 583 int i = 0; 584 TagPtr_t pTags = getTagTable(ext); 585 if (pTags == NULL) 586 { 587 return SML_ERR_NOT_ENOUGH_SPACE; 588 } 589 while (((pTags+i)->id) != TN_UNDEF) 590 { 591 if (((pTags+i)->id) == tagID) 592 { 593 *pTagByte = (pTags+i)->wbxml; 594 return SML_ERR_OK; 595 } 596 i++; 597 } 598 *pTagByte = 0; 599 return SML_ERR_XLT_INVAL_PROTO_ELEM; 600 } 601 602 /** 603 * FUNCTION: getCodePage 604 * 605 * Returns the code page which belongs to a certain PCDATA extension type. 606 * 607 * PRE-Condition: valid PCDATA extension type 608 * 609 * POST-Condition: the code page is returned 610 * 611 * IN: ext, the PCDATA extension type 612 * 613 * RETURN: the code page 614 */ 615 Byte_t getCodePage(SmlPcdataExtension_t ext) 616 { 617 #ifdef __USE_DMTND__ 618 if (ext == SML_EXT_DMTND) 619 return 2; 620 #endif 621 #ifdef __USE_METINF__ 622 if (ext == SML_EXT_METINF) 623 return 1; 624 #endif 625 #ifdef __USE_DEVINF__ 626 if (ext == SML_EXT_DEVINF) 627 return 0; 628 #endif 629 return 0; 630 } 631 632 /** 633 * FUNCTION: getCodePageById 634 * 635 * Returns the codepage which belongs to a certain tag ID 636 * 637 * PRE-Condition: valid tag ID 638 * 639 * POST-Condition: the code page is returned 640 * 641 * IN: tagID, the ID of the tag 642 * pCp, the codepage/extention of the tag 643 * 644 * RETURN: 0, if OK 645 */ 646 Ret_t getExtById(XltTagID_t tagID, SmlPcdataExtension_t *pExt) 647 { 648 int i = 0; 649 SmlPcdataExtension_t ext; 650 /* Iterate over all defined extensions to find the corresponding TAG. 651 * Empty extensions, e.g. not defined numbers will be skipped. 652 */ 653 for (ext = SML_EXT_UNDEFINED; ext < SML_EXT_LAST; ext++) { 654 TagPtr_t pTags = getTagTable(ext); 655 if (pTags == NULL) { 656 continue; /* skip empty codepage */ 657 } 658 i = 0; 659 while (((pTags+i)->id) != TN_UNDEF) { 660 if ((((pTags+i)->id) == tagID)){ 661 *pExt = ext; 662 return SML_ERR_OK; 663 } 664 i++; 665 } 666 } 667 /* tag not found in any extension */ 668 *pExt = (SmlPcdataExtension_t)255; 669 return SML_ERR_XLT_INVAL_PROTO_ELEM; 670 } 671 672 /** 673 * FUNCTION: getTagIDByStringAndCodepage 674 * 675 * Returns the tag ID which belongs to a tag string in a certain codepage 676 * 677 * PRE-Condition: valid tag string, valid code page 678 * 679 * POST-Condition: tag id is returned 680 * 681 * IN: tag, the string representation of the tag 682 * cp, code page group for the tag 683 * pTagID, the tag id of the tag 684 * 685 * RETURN: 0, if OK 686 */ 687 688 Ret_t getTagIDByStringAndExt(String_t tag, SmlPcdataExtension_t ext, XltTagID_t *pTagID) 689 { 690 int i = 0; 691 TagPtr_t pTags = getTagTable(ext); 692 if (pTags == NULL) { 693 return SML_ERR_NOT_ENOUGH_SPACE; 694 } 695 for (i=0;((pTags+i)->id) != TN_UNDEF; i++) { 696 if (*(pTags+i)->xml != *tag) continue; // if the first char doesn't match we skip the strcmp to speed things up 697 if (smlLibStrcmp(((pTags+i)->xml), tag) == 0) { 698 *pTagID = (pTags+i)->id; 699 return SML_ERR_OK; 700 } 701 } 702 *pTagID = TN_UNDEF; 703 return SML_ERR_XLT_INVAL_PROTO_ELEM; 704 } 705 706 /** 707 * FUNCTION: getTagIDByByteAndCodepage 708 * 709 * Returns the tag ID which belongs to a tag byte in a certain codepage 710 * 711 * PRE-Condition: valid tag byte, valid code page 712 * 713 * POST-Condition: tag id is returned 714 * 715 * IN: tag, the byte representation of the tag 716 * cp, code page group for the tag 717 * pTagID, the tag id of the tag 718 * 719 * RETURN: 0, if OK 720 */ 721 Ret_t getTagIDByByteAndExt(Byte_t tag, SmlPcdataExtension_t ext, XltTagID_t *pTagID) 722 { 723 724 int i = 0; 725 TagPtr_t pTags = getTagTable(ext); 726 if (pTags == NULL) 727 { 728 return SML_ERR_NOT_ENOUGH_SPACE; 729 } 730 while (((pTags+i)->id) != TN_UNDEF) 731 { 732 if (((pTags+i)->wbxml) == tag) 733 { 734 *pTagID = (pTags+i)->id; 735 return SML_ERR_OK; 736 } 737 i++; 738 } 739 *pTagID = TN_UNDEF; 740 return SML_ERR_XLT_INVAL_PROTO_ELEM; 741 } 742 743 /** 744 * FUNCTION: getTagIDByStringAndNamespace 745 * 746 * Returns the tag ID which belongs to a tag string in a certain namespace 747 * 748 * PRE-Condition: valid tag string, valid namespace 749 * 750 * POST-Condition: tag id is returned 751 * 752 * IN: tag, the string representation of the tag 753 * ns, namespace group for the tag 754 * pTagID, the tag id of the tag 755 * 756 * RETURN: 0, if OK 757 */ 758 #ifdef __SML_XML__ 759 Ret_t getTagIDByStringAndNamespace(String_t tag, String_t ns, XltTagID_t *pTagID) 760 { 761 int i = 0; 762 TagPtr_t pTags = getTagTable(getExtByName(ns)); 763 if (pTags == NULL) 764 { 765 return SML_ERR_NOT_ENOUGH_SPACE; 766 } 767 while (((pTags+i)->id) != TN_UNDEF) 768 { 769 if ((smlLibStrcmp(((pTags+i)->xml), tag) == 0)) 770 { 771 *pTagID = (pTags+i)->id; 772 return SML_ERR_OK; 773 } 774 i++; 775 } 776 *pTagID = TN_UNDEF; 777 return SML_ERR_XLT_INVAL_PROTO_ELEM; 778 } 779 780 #endif 781