Home | History | Annotate | Download | only in src
      1 /*************************************************************************/
      2 /* module:          SyncML Command Builder                               */
      3 /*                                                                       */
      4 /* file:            mgrcmdbuilder.c                                      */
      5 /* target system:   all                                                  */
      6 /* target OS:       all                                                  */
      7 /*                                                                       */
      8 /* Description:                                                          */
      9 /* Core Module for assembling SyncML compliant documents                 */
     10 /*************************************************************************/
     11 
     12 
     13 /*
     14  * Copyright Notice
     15  * Copyright (c) Ericsson, IBM, Lotus, Matsushita Communication
     16  * Industrial Co., Ltd., Motorola, Nokia, Openwave Systems, Inc.,
     17  * Palm, Inc., Psion, Starfish Software, Symbian, Ltd. (2001).
     18  * All Rights Reserved.
     19  * Implementation of all or part of any Specification may require
     20  * licenses under third party intellectual property rights,
     21  * including without limitation, patent rights (such a third party
     22  * may or may not be a Supporter). The Sponsors of the Specification
     23  * are not responsible and shall not be held responsible in any
     24  * manner for identifying or failing to identify any or all such
     25  * third party intellectual property rights.
     26  *
     27  * THIS DOCUMENT AND THE INFORMATION CONTAINED HEREIN ARE PROVIDED
     28  * ON AN "AS IS" BASIS WITHOUT WARRANTY OF ANY KIND AND ERICSSON, IBM,
     29  * LOTUS, MATSUSHITA COMMUNICATION INDUSTRIAL CO. LTD, MOTOROLA,
     30  * NOKIA, PALM INC., PSION, STARFISH SOFTWARE AND ALL OTHER SYNCML
     31  * SPONSORS DISCLAIM ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING
     32  * BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF THE INFORMATION
     33  * HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED WARRANTIES OF
     34  * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT
     35  * SHALL ERICSSON, IBM, LOTUS, MATSUSHITA COMMUNICATION INDUSTRIAL CO.,
     36  * LTD, MOTOROLA, NOKIA, PALM INC., PSION, STARFISH SOFTWARE OR ANY
     37  * OTHER SYNCML SPONSOR BE LIABLE TO ANY PARTY FOR ANY LOSS OF
     38  * PROFITS, LOSS OF BUSINESS, LOSS OF USE OF DATA, INTERRUPTION OF
     39  * BUSINESS, OR FOR DIRECT, INDIRECT, SPECIAL OR EXEMPLARY, INCIDENTAL,
     40  * PUNITIVE OR CONSEQUENTIAL DAMAGES OF ANY KIND IN CONNECTION WITH
     41  * THIS DOCUMENT OR THE INFORMATION CONTAINED HEREIN, EVEN IF ADVISED
     42  * OF THE POSSIBILITY OF SUCH LOSS OR DAMAGE.
     43  *
     44  * The above notice and this paragraph must be included on all copies
     45  * of this document that are made.
     46  *
     47  */
     48 
     49 
     50 
     51 
     52 /*************************************************************************
     53  *  Definitions
     54  *************************************************************************/
     55 
     56 
     57 /* Include Headers */
     58 #include <smldef.h>
     59 #include "xltenc.h"
     60 #include "xltdec.h"
     61 #include "libmem.h"
     62 #include "mgr.h"
     63 
     64 
     65 /* Used external functions */
     66 extern Ret_t smlLockWriteBuffer(InstanceID_t id, MemPtr_t *pWritePosition, MemSize_t *freeSize);
     67 extern Ret_t smlUnlockWriteBuffer(InstanceID_t id, MemSize_t writtenBytes);
     68 
     69 #ifndef __SML_LITE__  /* these API calls are NOT included in the Toolkit lite version */
     70   extern Ret_t addInfo(InstanceInfoPtr_t pInfo);
     71   extern InstanceInfoPtr_t findInfo(InstanceID_t id);
     72   extern Ret_t removeInfo(InstanceID_t id);
     73 #endif
     74 
     75 /* Prototypes of exported SyncML API functions */
     76 SML_API Ret_t smlStartMessage(InstanceID_t id, SmlSyncHdrPtr_t pContent);
     77 SML_API Ret_t smlStartMessageExt(InstanceID_t id, SmlSyncHdrPtr_t pContent, SmlVersion_t vers);
     78 SML_API Ret_t smlEndMessage(InstanceID_t id, Boolean_t final);
     79 SML_API Ret_t smlStartSync(InstanceID_t id, SmlSyncPtr_t pContent);
     80 SML_API Ret_t smlEndSync(InstanceID_t id);
     81 
     82 #ifdef ATOMIC_SEND  /* these API calls are NOT included in the Toolkit lite version */
     83   SML_API Ret_t smlStartAtomic(InstanceID_t id, SmlAtomicPtr_t pContent);
     84   SML_API Ret_t smlEndAtomic(InstanceID_t id);
     85 #endif
     86 #ifdef SEQUENCE_SEND
     87   SML_API Ret_t smlStartSequence(InstanceID_t id, SmlSequencePtr_t pContent);
     88   SML_API Ret_t smlEndSequence(InstanceID_t id);
     89 #endif
     90 
     91 #ifdef ADD_SEND
     92   SML_API Ret_t smlAddCmd(InstanceID_t id, SmlAddPtr_t pContent);
     93 #endif
     94 SML_API Ret_t smlAlertCmd(InstanceID_t id, SmlAlertPtr_t pContent);
     95 SML_API Ret_t smlDeleteCmd(InstanceID_t id, SmlDeletePtr_t pContent);
     96 #ifdef GET_SEND
     97   SML_API Ret_t smlGetCmd(InstanceID_t id, SmlGetPtr_t pContent);
     98 #endif
     99 SML_API Ret_t smlPutCmd(InstanceID_t id, SmlPutPtr_t pContent);
    100 SML_API Ret_t smlMapCmd(InstanceID_t id, SmlMapPtr_t pContent);
    101 SML_API Ret_t smlResultsCmd(InstanceID_t id, SmlResultsPtr_t pContent);
    102 SML_API Ret_t smlStatusCmd(InstanceID_t id, SmlStatusPtr_t pContent);
    103 SML_API Ret_t smlReplaceCmd(InstanceID_t id, SmlReplacePtr_t pContent);
    104 
    105 #ifdef COPY_SEND  /* these API calls are NOT included in the Toolkit lite version */
    106   SML_API Ret_t smlCopyCmd(InstanceID_t id, SmlCopyPtr_t pContent);
    107 #endif
    108 #ifdef EXEC_SEND
    109   SML_API Ret_t smlExecCmd(InstanceID_t id, SmlExecPtr_t pContent);
    110 #endif
    111 #ifdef SEARCH_SEND
    112   SML_API Ret_t smlSearchCmd(InstanceID_t id, SmlSearchPtr_t pContent);
    113 #endif
    114 
    115 /* Private function prototypes */
    116 static Ret_t mgrCreateNextCommand(InstanceID_t id, SmlProtoElement_t cmdType, VoidPtr_t pContent);
    117 Ret_t mgrResetWorkspace (InstanceID_t id);
    118 
    119 
    120 
    121 
    122 /*************************************************************************
    123  *  Exported SyncML API functions
    124  *************************************************************************/
    125 
    126 
    127 /**
    128  * FUNCTION: smlStartMessage
    129  *
    130  * Start a SyncML Message
    131  *
    132  * IN:              InstanceID_t
    133  *                  ID of the used instance
    134  *
    135  * IN:              SmlSyncHdrPtr_t
    136  *                  Data to pass along with that SyncML command
    137  *
    138  * RETURN:          Ret_t
    139  *                  Return Code
    140  *
    141  * NOTE:            (%%% luz 2003-08-06) this entry point is for compatibilty reasons only
    142  *                  and works for SyncML 1.0 only
    143  *                  please use smlStartMessageExt() instead in new projects.
    144  */
    145 SML_API Ret_t smlStartMessage(InstanceID_t id, SmlSyncHdrPtr_t pContent)
    146 {
    147   /* just call smlStartMessageExt with vers set to SyncML 1.0 */
    148   return smlStartMessageExt(id,pContent,SML_VERS_1_1);
    149 }
    150 
    151 
    152 /**
    153  * FUNCTION: smlStartMessageExt
    154  * (%%% added by luz 2003-08-06 to support SyncML versions other than
    155  * 1.0 with new vers parameter)
    156  *
    157  * Start a SyncML Message
    158  *
    159  * IN:              InstanceID_t
    160  *                  ID of the used instance
    161  *                  SyncML version
    162  *
    163  * IN:              SmlSyncHdrPtr_t
    164  *                  Data to pass along with that SyncML command
    165  *
    166  * RETURN:          Ret_t
    167  *                  Return Code
    168  */
    169 SML_API Ret_t smlStartMessageExt(InstanceID_t id, SmlSyncHdrPtr_t pContent, SmlVersion_t vers)
    170 {
    171 
    172   /* --- Definitions --- */
    173   InstanceInfoPtr_t   pInstanceInfo;               // pointer the the instance info structure for this id
    174   Ret_t               rc;
    175   MemPtr_t            pCurrentWritePosition;       // current Position from to which to write
    176   MemPtr_t            pBeginPosition;              // saves the first position which has been written
    177   MemSize_t           freeSize;                    // size of free memory for writing
    178 
    179 
    180   #ifdef NOWSM
    181     pInstanceInfo = (InstanceInfoPtr_t)id; // ID is the instance info pointer
    182   #else
    183     /* --- Retrieve the corresponding instanceInfo structure --- */
    184     #ifdef __SML_LITE__  /* Only ONE instance is supported in the Toolkit lite version */
    185       pInstanceInfo = mgrGetInstanceListAnchor();
    186     #else
    187       pInstanceInfo = (InstanceInfoPtr_t) findInfo(id);
    188     #endif
    189   #endif
    190 
    191   if (pInstanceInfo==NULL) return SML_ERR_MGR_INVALID_INSTANCE_INFO;
    192 
    193 
    194   /* --- Get Write Access to the workspace --- */
    195   rc = smlLockWriteBuffer(id, &pCurrentWritePosition, &freeSize);
    196 
    197   if (rc!=SML_ERR_OK) {
    198     // abort, unlock the buffer again without changing it's current position
    199     smlUnlockWriteBuffer(id, (MemSize_t)0);
    200     return rc;
    201     }
    202 
    203   #ifdef NOWSM
    204   // remember where outgoing message starts in buffer
    205   smlSetOutgoingBegin(id);
    206   #endif
    207 
    208   /* Remember the position we have started writing */
    209   pBeginPosition=pCurrentWritePosition;
    210 
    211   /* --- Call the encoder module --- */
    212   /*     (Saves the returned encoder state to the corresponding instanceInfo structure */
    213   rc = xltEncInit(pInstanceInfo->instanceOptions->encoding, pContent,
    214                   pCurrentWritePosition+freeSize, &pCurrentWritePosition,
    215                   (XltEncoderPtr_t *)&(pInstanceInfo->encoderState),
    216                   vers);
    217 
    218   if (rc!=SML_ERR_OK) {
    219     // abort, unlock the buffer again without changing it's current position
    220     smlUnlockWriteBuffer(id, (MemSize_t)0);
    221   	// Reset the encoder module (free the encoding object)
    222 	  xltEncReset(pInstanceInfo->encoderState);
    223     // this encoding job is over! reset instanceInfo pointer
    224     pInstanceInfo->encoderState=NULL;
    225 
    226     return rc;
    227     }
    228 
    229   /* --- End Write Access to the workspace --- */
    230   rc = smlUnlockWriteBuffer(id, (MemSize_t)pCurrentWritePosition-(MemSize_t)pBeginPosition);
    231   return rc;
    232 }
    233 
    234 /**
    235  * FUNCTION: smlEndMessage
    236  *
    237  * End a SyncML Message
    238  *
    239  * IN:              InstanceID_t
    240  *                  ID of the used instance
    241  *
    242  * IN:              Boolean_t
    243  *                  Final Flag indicates last message within a package
    244  *
    245  * RETURN:          Ret_t
    246  *                  Return Code
    247  */
    248 SML_API Ret_t smlEndMessage(InstanceID_t id, Boolean_t final)
    249 {
    250 
    251   /* --- Definitions --- */
    252   InstanceInfoPtr_t   pInstanceInfo;               // pointer the the instance info structure for this id
    253   Ret_t               rc;
    254   MemPtr_t            pCurrentWritePosition;       // current Position from to which to write
    255   MemPtr_t            pBeginPosition;              // saves the first position which has been written
    256   MemSize_t           freeSize;                    // size of free memory for writing
    257 
    258 
    259   #ifdef NOWSM
    260     pInstanceInfo = (InstanceInfoPtr_t)id; // ID is the instance info pointer
    261   #else
    262     /* --- Retrieve the corresponding instanceInfo structure --- */
    263     #ifdef __SML_LITE__  /* Only ONE instance is supported in the Toolkit lite version */
    264       pInstanceInfo = mgrGetInstanceListAnchor();
    265     #else
    266       pInstanceInfo = (InstanceInfoPtr_t) findInfo(id);
    267     #endif
    268   #endif
    269 
    270   if (pInstanceInfo==NULL) return SML_ERR_MGR_INVALID_INSTANCE_INFO;
    271   // %%% luz 2003-08-19: added NULL check as previously failed encoding will delete encoder
    272   if (pInstanceInfo->encoderState==NULL) return SML_ERR_MGR_INVALID_INSTANCE_INFO;
    273 
    274 
    275   /* --- Get Write Access to the workspace --- */
    276   rc = smlLockWriteBuffer(id, &pCurrentWritePosition, &freeSize);
    277 
    278   if (rc!=SML_ERR_OK) {
    279     // abort, unlock the buffer again without changing it's current position
    280     smlUnlockWriteBuffer(id, (MemSize_t)0);
    281     return rc;
    282     }
    283 
    284 
    285   /* Remember the position we have started writing */
    286   pBeginPosition=pCurrentWritePosition;
    287 
    288   /* -- set Final Flag --*/
    289   ((XltEncoderPtr_t)(pInstanceInfo->encoderState))->final = final;
    290 
    291   /* --- Call the encoder module --- */
    292   rc = xltEncTerminate(pInstanceInfo->encoderState, pCurrentWritePosition+freeSize,&pCurrentWritePosition);
    293 
    294   if (rc!=SML_ERR_OK) {
    295     // abort, unlock the buffer again without changing it's current position
    296     smlUnlockWriteBuffer(id, (MemSize_t)0);
    297     // this encoding job is over! reset instanceInfo pointer
    298     pInstanceInfo->encoderState=NULL;
    299 
    300     return rc;
    301   }
    302 
    303   // this encoding job is over! reset instanceInfo pointer
    304   // (the decoding object itself has been freed by the decoder)
    305   pInstanceInfo->encoderState=NULL;
    306 
    307   /* --- End Write Access to the workspace --- */
    308   rc = smlUnlockWriteBuffer(id, (MemSize_t)pCurrentWritePosition-(MemSize_t)pBeginPosition);
    309 
    310 
    311   return rc;
    312 }
    313 
    314 
    315 
    316 
    317 
    318 /**
    319  * FUNCTION: smlStartSync
    320  *
    321  * Start synchronizing
    322  *
    323  * IN:              InstanceID_t
    324  *                  ID of the used instance
    325  *
    326  * IN:              SyncPtr_t
    327  *                  Data to pass along with that SyncML command
    328  *
    329  * RETURN:          Ret_t
    330  *                  Return Code
    331  */
    332 SML_API Ret_t smlStartSync(InstanceID_t id, SmlSyncPtr_t pContent)
    333 {
    334   return mgrCreateNextCommand(id, SML_PE_SYNC_START, pContent);
    335 }
    336 
    337 
    338 
    339 /**
    340  * FUNCTION: smlEndSync
    341  *
    342  * End synchronizing
    343  *
    344  * IN:              InstanceID_t
    345  *
    346  * RETURN:          Ret_t
    347  *                  Return Code
    348  */
    349 SML_API Ret_t smlEndSync(InstanceID_t id)
    350 {
    351   return mgrCreateNextCommand(id, SML_PE_SYNC_END, NULL);
    352 }
    353 
    354 
    355 #ifdef ATOMIC_SEND  /* these API calls are NOT included in the Toolkit lite version */
    356 
    357 /**
    358  * FUNCTION: smlStartAtomic
    359  *
    360  * Start an atomic sequence
    361  *
    362  * IN:              InstanceID_t
    363  *                  ID of the used instance
    364  *
    365  * IN:              SmlAtomicPtr_t
    366  *                  Data to pass along with that SyncML command
    367  *
    368  * RETURN:          Ret_t
    369  *                  Return Code
    370  */
    371 SML_API Ret_t smlStartAtomic(InstanceID_t id, SmlAtomicPtr_t pContent)
    372 {
    373   return mgrCreateNextCommand(id, SML_PE_ATOMIC_START, pContent);
    374 }
    375 
    376 
    377 /**
    378  * FUNCTION: smlEndAtomic
    379  *
    380  * End an atomic sequence
    381  *
    382  * IN:              InstanceID_t
    383  *                  ID of the used instance
    384  *
    385  * RETURN:          Ret_t
    386  *                  Return Code
    387  */
    388 SML_API Ret_t smlEndAtomic(InstanceID_t id)
    389 {
    390   return mgrCreateNextCommand(id, SML_PE_ATOMIC_END, NULL);
    391 }
    392 
    393 #endif
    394 
    395 #ifdef SEQUENCE_SEND
    396 
    397 /**
    398  * FUNCTION: smlStartSequence
    399  *
    400  * Start a sequence
    401  *
    402  * IN:              InstanceID_t
    403  *                  ID of the used instance
    404  *
    405  * IN:              SequencePtr_t
    406  *                  Data to pass along with that SyncML command
    407  *
    408  * RETURN:          Ret_t
    409  *                  Return Code
    410  */
    411 SML_API Ret_t smlStartSequence(InstanceID_t id, SmlSequencePtr_t pContent)
    412 {
    413   return mgrCreateNextCommand(id, SML_PE_SEQUENCE_START, pContent);
    414 }
    415 
    416 
    417 
    418 /**
    419  * FUNCTION: smlEndSequence
    420  *
    421  * End a sequence
    422  *
    423  * IN:              InstanceID_t
    424  *                  ID of the used instance
    425  *
    426  * RETURN:          Ret_t
    427  *                  Return Code
    428  */
    429 SML_API Ret_t smlEndSequence(InstanceID_t id)
    430 {
    431   return mgrCreateNextCommand(id, SML_PE_SEQUENCE_END, NULL);
    432 }
    433 
    434 #endif
    435 
    436 
    437 #ifdef ADD_SEND
    438 /**
    439  * FUNCTION: smlAddCmd
    440  *
    441  * Create a Add Command
    442  *
    443  * IN:              InstanceID_t
    444  *                  ID of the used instance
    445  *
    446  * IN:              SmlAddPtr_t
    447  *                  Data to pass along with that SyncML command
    448  *
    449  * RETURN:          Ret_t
    450  *                  Return Code
    451  */
    452 SML_API Ret_t smlAddCmd(InstanceID_t id, SmlAddPtr_t pContent)
    453 {
    454   return mgrCreateNextCommand(id, SML_PE_ADD, pContent);
    455 }
    456 #endif
    457 
    458 
    459 /**
    460  * FUNCTION: smlAlertCmd
    461  *
    462  * Create a Alert Command
    463  *
    464  * IN:              InstanceID_t
    465  *                  ID of the used instance
    466  *
    467  * IN:              SmlAlertPtr_t
    468  *                  Data to pass along with that SyncML command
    469  *
    470  * RETURN:          Ret_t
    471  *                  Return Code
    472  */
    473 SML_API Ret_t smlAlertCmd(InstanceID_t id, SmlAlertPtr_t pContent)
    474 {
    475    return mgrCreateNextCommand(id, SML_PE_ALERT, pContent);
    476 }
    477 
    478 
    479 
    480 
    481 /**
    482  * FUNCTION: smlDeleteCmd
    483  *
    484  * Create a Start Message Command
    485  *
    486  * IN:              InstanceID_t
    487  *                  ID of the used instance
    488  *
    489  * IN:              DeletePtr_t
    490  *                  Data to pass along with that SyncML command
    491  *
    492  * RETURN:          Ret_t
    493  *                  Return Code
    494  */
    495 SML_API Ret_t smlDeleteCmd(InstanceID_t id, SmlDeletePtr_t pContent)
    496 {
    497   return mgrCreateNextCommand(id, SML_PE_DELETE, pContent);
    498 }
    499 
    500 
    501 
    502 #ifdef GET_SEND
    503 
    504 
    505 /**
    506  * FUNCTION: smlGetCmd
    507  *
    508  * Create a Get Command
    509  *
    510  * IN:              InstanceID_t
    511  *                  ID of the used instance
    512  *
    513  * IN:              GetPtr_t
    514  *                  Data to pass along with that SyncML command
    515  *
    516  * RETURN:          Ret_t
    517  *                  Return Code
    518  */
    519 SML_API Ret_t smlGetCmd(InstanceID_t id, SmlGetPtr_t pContent)
    520 {
    521   return mgrCreateNextCommand(id, SML_PE_GET, pContent);
    522 }
    523 
    524 #endif
    525 
    526 
    527 /**
    528  * FUNCTION: smlPutCmd
    529  *
    530  * Create a Put Command
    531  *
    532  * IN:              InstanceID_t
    533  *                  ID of the used instance
    534  *
    535  * IN:              PutPtr_t
    536  *                  Data to pass along with that SyncML command
    537  *
    538  * RETURN:          Ret_t
    539  *                  Return Code
    540  */
    541 SML_API Ret_t smlPutCmd(InstanceID_t id, SmlPutPtr_t pContent)
    542 {
    543   return mgrCreateNextCommand(id, SML_PE_PUT, pContent);
    544 }
    545 
    546 
    547 
    548 /**
    549  * FUNCTION: smlMapCmd
    550  *
    551  * Create a Map Command
    552  *
    553  * IN:              InstanceID_t
    554  *                  ID of the used instance
    555  *
    556  * IN:              MapPtr_t
    557  *                  Data to pass along with that SyncML command
    558  *
    559  * RETURN:          Ret_t
    560  *                  Return Code
    561  */
    562 SML_API Ret_t smlMapCmd(InstanceID_t id, SmlMapPtr_t pContent)
    563 {
    564   return mgrCreateNextCommand(id, SML_PE_MAP, pContent);
    565 }
    566 
    567 
    568 
    569 /**
    570  * FUNCTION: smlResultsCmd
    571  *
    572  * Create a Results  Command
    573  *
    574  * IN:              InstanceID_t
    575  *                  ID of the used instance
    576  *
    577  * IN:              ResultsPtr_t
    578  *                  Data to pass along with that SyncML command
    579  *
    580  * RETURN:          Ret_t
    581  *                  Return Code
    582  */
    583 SML_API Ret_t smlResultsCmd(InstanceID_t id, SmlResultsPtr_t pContent)
    584 {
    585   return mgrCreateNextCommand(id, SML_PE_RESULTS, pContent);
    586 }
    587 
    588 
    589 
    590 
    591 
    592 /**
    593  * FUNCTION: smlStatusCmd
    594  *
    595  * Create a Status Command
    596  *
    597  * IN:              InstanceID_t
    598  *                  ID of the used instance
    599  *
    600  * IN:              StatusPtr_t
    601  *                  Data to pass along with that SyncML command
    602  *
    603  * RETURN:          Ret_t
    604  *                  Return Code
    605  */
    606 SML_API Ret_t smlStatusCmd(InstanceID_t id, SmlStatusPtr_t pContent)
    607 {
    608   return mgrCreateNextCommand(id, SML_PE_STATUS, pContent);
    609 }
    610 
    611 
    612 
    613 /**
    614  * FUNCTION: smlReplaceCmd
    615  *
    616  * Create a Replace Command
    617  *
    618  * IN:              InstanceID_t
    619  *                  ID of the used instance
    620  *
    621  * IN:              SmlReplacePtr_t
    622  *                  Data to pass along with that SyncML command
    623  *
    624  * RETURN:          Ret_t
    625  *                  Return Code
    626  */
    627 SML_API Ret_t smlReplaceCmd(InstanceID_t id, SmlReplacePtr_t pContent)
    628 {
    629   return mgrCreateNextCommand(id, SML_PE_REPLACE, pContent);
    630 }
    631 
    632 
    633 
    634 #ifdef COPY_SEND  /* these API calls are NOT included in the Toolkit lite version */
    635 
    636 
    637 /**
    638  * FUNCTION: smlCopyCmd
    639  *
    640  * Create a Copy Command
    641  *
    642  * IN:              InstanceID_t
    643  *                  ID of the used instance
    644  *
    645  * IN:              CopyPtr_t
    646  *                  Data to pass along with that SyncML command
    647  *
    648  * RETURN:          Ret_t
    649  *                  Return Code
    650  */
    651 SML_API Ret_t smlCopyCmd(InstanceID_t id, SmlCopyPtr_t pContent)
    652 {
    653   return mgrCreateNextCommand(id, SML_PE_COPY, pContent);
    654 }
    655 
    656 #endif
    657 
    658 #ifdef EXEC_SEND
    659 
    660 /**
    661  * FUNCTION: smlExecCmd
    662  *
    663  * Create a Exec Command
    664  *
    665  * IN:              InstanceID_t
    666  *                  ID of the used instance
    667  *
    668  * IN:              ExecPtr_t
    669  *                  Data to pass along with that SyncML command
    670  *
    671  * RETURN:          Ret_t
    672  *                  Return Code
    673  */
    674 SML_API Ret_t smlExecCmd(InstanceID_t id, SmlExecPtr_t pContent)
    675 {
    676   return mgrCreateNextCommand(id, SML_PE_EXEC, pContent);
    677 }
    678 
    679 #endif
    680 
    681 #ifdef SEARCH_SEND
    682 
    683 /**
    684  * FUNCTION: smlSearchCmd
    685  *
    686  * Create a Search Command
    687  *
    688  * IN:              InstanceID_t
    689  *                  ID of the used instance
    690  *
    691  * IN:              SearchPtr_t
    692  *                  Data to pass along with that SyncML command
    693  *
    694  * RETURN:          Ret_t
    695  *                  Return Code
    696  */
    697 SML_API Ret_t smlSearchCmd(InstanceID_t id, SmlSearchPtr_t pContent)
    698 {
    699   return mgrCreateNextCommand(id, SML_PE_SEARCH, pContent);
    700 }
    701 
    702 
    703 #endif
    704 
    705 
    706 /*************************************************************************
    707  *  Exported SyncML API functions (FULL-SIZE TOOLKIT ONLY)
    708  *************************************************************************/
    709 
    710 #ifndef __SML_LITE__  /* these API calls are NOT included in the Toolkit lite version */
    711 /**
    712  * FUNCTION: smlStartEvaluation
    713  *
    714  * Starts an evaluation run which prevents further API-Calls to write tags -
    715  * just the tag-sizes are calculated. Must be sopped via smlEndEvaluation
    716  *
    717  * IN:              InstanceID_t
    718  *                  ID of the used instance
    719  *
    720  *
    721  * RETURN:          Ret_t
    722  *                  Return Code
    723  */
    724 SML_API Ret_t smlStartEvaluation(InstanceID_t id)
    725 {
    726   InstanceInfoPtr_t   pInstanceInfo;               // pointer the the instance info structure for this id
    727   Ret_t               rc;
    728 
    729   #ifdef NOWSM
    730     pInstanceInfo = (InstanceInfoPtr_t)id; // ID is the instance info pointer
    731   #else
    732     /* --- Retrieve the corresponding instanceInfo structure --- */
    733     #ifdef __SML_LITE__  /* Only ONE instance is supported in the Toolkit lite version */
    734       pInstanceInfo = mgrGetInstanceListAnchor();
    735     #else
    736       pInstanceInfo = (InstanceInfoPtr_t) findInfo(id);
    737     #endif
    738   #endif
    739 
    740   if (pInstanceInfo==NULL) return SML_ERR_MGR_INVALID_INSTANCE_INFO;
    741 
    742 
    743   /* --- Initialize Encoder for evaluation mode --- */
    744 
    745   rc = xltStartEvaluation((XltEncoderPtr_t)(pInstanceInfo->encoderState));
    746 
    747   return rc;
    748 }
    749 
    750 
    751 /**
    752  * FUNCTION: smlEndEvaluation
    753  *
    754  * Stops an evaluation run which prevents further API-Calls to write tags -
    755  * the remaining free buffer size after all Tags are written is returned
    756  *
    757  * IN:              InstanceID_t
    758  *                  ID of the used instance
    759  *
    760  * IN/OUT:          MemSize_t
    761  *					Size of free buffer for data after all tags are written
    762  *
    763  * RETURN:          Ret_t
    764  *                  Return Code
    765  */
    766 SML_API Ret_t smlEndEvaluation(InstanceID_t id, MemSize_t *freemem)
    767 {
    768   InstanceInfoPtr_t   pInstanceInfo;               // pointer the the instance info structure for this id
    769   Ret_t               rc;
    770 
    771   #ifdef NOWSM
    772     pInstanceInfo = (InstanceInfoPtr_t)id; // ID is the instance info pointer
    773   #else
    774     /* --- Retrieve the corresponding instanceInfo structure --- */
    775     #ifdef __SML_LITE__  /* Only ONE instance is supported in the Toolkit lite version */
    776       pInstanceInfo = mgrGetInstanceListAnchor();
    777     #else
    778       pInstanceInfo = (InstanceInfoPtr_t) findInfo(id);
    779     #endif
    780   #endif
    781 
    782   if (pInstanceInfo==NULL) return SML_ERR_MGR_INVALID_INSTANCE_INFO;
    783 
    784   // %%% luz 2002-09-03: encoder can be null here if fatal error occurred before
    785   if (pInstanceInfo->encoderState==NULL)
    786     return SML_ERR_WRONG_USAGE;
    787 
    788   rc = xltEndEvaluation(id, (XltEncoderPtr_t)(pInstanceInfo->encoderState), freemem);
    789   return SML_ERR_OK;
    790 }
    791 
    792 #endif
    793 
    794 
    795 /*************************************************************************
    796  *  Private Functions
    797  *************************************************************************/
    798 
    799 
    800 /**
    801  * FUNCTION:
    802  * Calls the encoding routines of the Encoder Module for a given Command Type
    803  * and Command Content
    804  *
    805  *
    806  * IN:        InstanceID_t
    807  *            ID of the Instance
    808  *
    809  * IN:        ProtoElement_t
    810  *            Type of the command (defined by the Proto Element Enumeration)
    811  *
    812  * IN:        VoidPtr_t
    813  *            Content of the command to encode
    814  *
    815  * RETURN:    Return value,
    816  *            SML_ERR_OK if command has been encoded successfully
    817  */
    818 static Ret_t mgrCreateNextCommand(InstanceID_t id, SmlProtoElement_t cmdType, VoidPtr_t pContent)
    819 {
    820   /* --- Definitions --- */
    821   InstanceInfoPtr_t   pInstanceInfo;               // pointer the the instance info structure for this id
    822   Ret_t               rc;
    823   MemPtr_t            pCurrentWritePosition;       // current Position from to which to write
    824   MemPtr_t            pBeginPosition;              // saves the first position which has been written
    825   MemSize_t           freeSize;                    // size of free memory for writing
    826 
    827 
    828   #ifdef NOWSM
    829     pInstanceInfo = (InstanceInfoPtr_t)id; // ID is the instance info pointer
    830   #else
    831     /* --- Retrieve the corresponding instanceInfo structure --- */
    832     #ifdef __SML_LITE__  /* Only ONE instance is supported in the Toolkit lite version */
    833       pInstanceInfo = mgrGetInstanceListAnchor();
    834     #else
    835       pInstanceInfo = (InstanceInfoPtr_t) findInfo(id);
    836     #endif
    837   #endif
    838 
    839   if (pInstanceInfo==NULL) return SML_ERR_MGR_INVALID_INSTANCE_INFO;
    840   // %%% luz 2002-11-27: added NULL check as previously failed encoding will delete encoder
    841   if (pInstanceInfo->encoderState==NULL) return SML_ERR_MGR_INVALID_INSTANCE_INFO;
    842 
    843   /* --- Get Write Access to the workspace --- */
    844   rc = smlLockWriteBuffer(id, &pCurrentWritePosition, &freeSize);
    845 
    846   if (rc!=SML_ERR_OK)  {
    847     // abort, unlock the buffer again without changing it's current position
    848     smlUnlockWriteBuffer(id, (MemSize_t)0);
    849     return rc;
    850     }
    851 
    852 
    853   // Remember the position we have started writing
    854   pBeginPosition=pCurrentWritePosition;
    855 
    856 
    857   /* --- Call the encoder module --- */
    858   rc = xltEncAppend(pInstanceInfo->encoderState, cmdType, pCurrentWritePosition+freeSize, pContent, &pCurrentWritePosition);
    859 
    860   if (rc!=SML_ERR_OK) {
    861 	  /* check for full buffer and call TransmitChunk */
    862 	  if (rc == SML_ERR_XLT_BUF_ERR) {
    863 		  // first check wether callback is defined
    864       if (pInstanceInfo->callbacks->transmitChunkFunc!= NULL) {
    865 			  // abort, unlock the buffer again without changing it's current position
    866         smlUnlockWriteBuffer(id, (MemSize_t)0);
    867 		    // call the callback
    868 			  pInstanceInfo->callbacks->transmitChunkFunc(id,NULL);
    869 		    // lock -> returns the amount of free buffer space
    870 			  smlLockWriteBuffer(id, &pCurrentWritePosition, &freeSize);
    871         pBeginPosition = pCurrentWritePosition;
    872 		    // now try again to encode and see wether we now have enough mem available
    873 			  rc = xltEncAppend(pInstanceInfo->encoderState, cmdType, pCurrentWritePosition+freeSize, pContent, &pCurrentWritePosition);
    874 		    // if rc == SML_ERR_OK continue else
    875           // return the errorcode
    876 			  if( rc !=	SML_ERR_OK)
    877 			  {
    878           smlUnlockWriteBuffer(id, (MemSize_t)0);
    879 	        // Reset the encoder module (free the encoding object)
    880 	        xltEncReset(pInstanceInfo->encoderState);
    881           // this encoding job is over! reset instanceInfo pointer
    882           pInstanceInfo->encoderState=NULL;
    883           return rc;
    884 			  }
    885 		  }
    886 	  } else {
    887       // abort, unlock the buffer again without changing it's current position
    888       smlUnlockWriteBuffer(id, (MemSize_t)0);
    889 	    // Reset the encoder module (free the encoding object)
    890 	    xltEncReset(pInstanceInfo->encoderState);
    891       // this encoding job is over! reset instanceInfo pointer
    892       pInstanceInfo->encoderState=NULL;
    893       return rc;
    894 	  }
    895   }
    896   /* --- End Write Access to the workspace --- */
    897   rc = smlUnlockWriteBuffer(id, (MemSize_t)pCurrentWritePosition-(MemSize_t)pBeginPosition);
    898   return rc;
    899 }
    900 
    901 /* eof */
    902