Changeset 506

Show
Ignore:
Timestamp:
07/22/08 16:48:46 (4 months ago)
Author:
bellmich
Message:

- fixed several compiler warnings
- removed unnecessary include in nokia_6230 test

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/libsyncml/parser/sml_xml_assm.c

    r486 r506  
    133133} 
    134134 
    135 SmlBool smlLocationAssemble(SmlLocation *location, SmlXmlAssembler *assm, const char *name, SmlError **error) 
    136 
    137         smlTrace(TRACE_ENTRY, "%s(%p, %p, %s, %p)", __func__, location, assm, name, error); 
    138         smlAssert(assm); 
    139         smlAssert(location); 
    140          
    141         if (name) { 
    142                 if (!_smlXmlAssemblerStartNode(assm, name, error)) 
    143                         goto error; 
    144         } 
    145          
    146         if (!location->locURI) { 
    147                 smlErrorSet(error, SML_ERROR_GENERIC, "No locURI set"); 
    148                 goto error; 
    149         } 
    150          
    151         if (!_smlXmlAssemblerAddString(assm, SML_ELEMENT_LOCURI, location->locURI, error)) 
    152                 goto error; 
    153          
    154         if (location->locName) { 
    155                 if (!_smlXmlAssemblerAddString(assm, SML_ELEMENT_LOCNAME, location->locName, error)) 
    156                         goto error; 
    157         } 
    158          
    159         if (name) { 
    160                 if (!_smlXmlAssemblerEndNode(assm, error)) 
    161                         goto error; 
    162         } 
    163          
    164         smlTrace(TRACE_EXIT, "%s", __func__); 
    165         return TRUE; 
    166  
    167 error: 
    168         smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error)); 
    169         return FALSE; 
    170 
    171  
    172  
    173  
    174 SmlBool smlAnchorAssemble(SmlAnchor *anchor, SmlXmlAssembler *assm, SmlError **error) 
    175 
    176         smlTrace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, anchor, assm, error); 
    177         smlAssert(assm); 
    178         smlAssert(anchor); 
    179  
    180         /* Start the anchor and switch to syncml:metinf namespace. 
    181          * It is not possible to remove the namespace from Last and 
    182          * Next because otherwise the Status commands could be longer 
    183          * then the Alert commands. If this would happen then the 
    184          * Status commands alone could be longer than MaxMsgSize. 
    185          * 
    186          * It is not sure how a mobile would react in this situation. 
    187          */ 
    188         if (!_smlXmlAssemblerStartNodeNS(assm, SML_ELEMENT_ANCHOR, SML_NAMESPACE_METINF, error)) 
    189                 goto error; 
    190          
    191         if (!anchor->next) { 
    192                 smlErrorSet(error, SML_ERROR_GENERIC, "No next set"); 
    193                 goto error; 
    194         } 
    195          
    196         /* SyncML Meta-Information DTD 1.1, Page 6, 5.1 Anchor - Content Model: (Last?, Next) 
    197            Last is optional, don't write a empty Last node. 
    198          */  
    199         if (anchor->last) { 
    200                 if (!_smlXmlAssemblerAddStringNS(assm, SML_ELEMENT_LAST, SML_NAMESPACE_METINF, anchor->last, error)) 
    201                         goto error; 
    202                  
    203         } 
    204          
    205         if (!_smlXmlAssemblerAddStringNS(assm, SML_ELEMENT_NEXT, SML_NAMESPACE_METINF, anchor->next, error)) 
    206                 goto error; 
    207          
    208         if (!_smlXmlAssemblerEndNode(assm, error)) 
    209                 goto error; 
    210          
    211         smlTrace(TRACE_EXIT, "%s", __func__); 
    212         return TRUE; 
    213  
    214 error: 
    215         smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error)); 
    216         return FALSE; 
    217 
    218  
    219 SmlBool smlItemAssemble(SmlItem *item, SmlXmlAssembler *assm, SmlError **error) 
    220 
    221         smlTrace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, item, assm, error); 
    222         smlAssert(assm); 
    223         smlAssert(item); 
    224          
    225         if (assm->moreDataSet) { 
    226                 smlErrorSet(error, SML_ERROR_GENERIC, "Trying to start a new item while last item had more data"); 
    227                 goto error; 
    228         } 
    229  
    230         /* Begin of Item */ 
    231         if (!_smlXmlAssemblerStartNode(assm, SML_ELEMENT_ITEM, error)) 
    232                 goto error; 
    233  
    234         /* Target */ 
    235         if (smlItemGetTarget(item)) { 
    236                 if (!smlLocationAssemble(smlItemGetTarget(item), assm, SML_ELEMENT_TARGET, error)) 
    237                         goto error; 
    238         } 
    239  
    240         /* Source */ 
    241         if (smlItemGetSource(item)) { 
    242                 if (!smlLocationAssemble(smlItemGetSource(item), assm, SML_ELEMENT_SOURCE, error)) 
    243                         goto error; 
    244         } 
    245  
    246         /* SourceParent */ 
    247  
    248         /* TargetParent */ 
    249  
    250         /* Data */ 
    251         if (smlItemHasData(item)) { 
    252                 if (item->disabled) { 
    253                         if (!_smlXmlAssemblerAddData(assm, SML_ELEMENT_DATA, "", 0, item->raw, error)) 
    254                                 goto error; 
    255                 } else { 
    256                         char *data = NULL; 
    257                         unsigned int size = 0; 
    258                         if (!smlItemGetData(item, &data, &size, error)) 
    259                                 goto error; 
    260                          
    261                         if (!_smlXmlAssemblerAddData(assm, SML_ELEMENT_DATA, data, size, item->raw, error)) 
    262                                 goto error; 
    263                 } 
    264         } 
    265  
    266         /* MoreData */ 
    267         if (item->moreData) { 
    268                 if (!_smlXmlAssemblerAddString(assm, SML_ELEMENT_MOREDATA, "", error)) 
    269                         goto error; 
    270                  
    271                 assm->moreDataSet = TRUE; 
    272         } 
    273  
    274         /* End of Item */ 
    275         if (!_smlXmlAssemblerEndNode(assm, error)) 
    276                 goto error; 
    277          
    278         smlTrace(TRACE_EXIT, "%s", __func__); 
    279         return TRUE; 
    280  
    281 error: 
    282         smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error)); 
    283         return FALSE; 
    284 
    285  
    286 SmlBool smlCredAssemble(SmlCred *cred, SmlXmlAssembler *assm, SmlError **error) 
    287 
    288         smlTrace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, cred, assm, error); 
    289         smlAssert(assm); 
    290         smlAssert(cred); 
    291                  
    292         if (!_smlXmlAssemblerStartNode(assm, SML_ELEMENT_CRED, error)) 
    293                 goto error; 
    294          
    295         //Meta 
    296         if (!_smlXmlAssemblerStartNode(assm, SML_ELEMENT_META, error)) 
    297                 goto error; 
    298          
    299         switch (cred->format) { 
    300                 case SML_FORMAT_TYPE_BASE64: 
    301                         if (!_smlXmlAssemblerAddStringNS(assm, SML_ELEMENT_FORMAT, SML_NAMESPACE_METINF, SML_BASE64, error)) 
    302                                 goto error; 
    303                         break; 
    304                 default: 
    305                         smlErrorSet(error, SML_ERROR_GENERIC, "SyncML credential: Unknown format %d.", cred->format); 
    306                         goto error; 
    307         } 
    308          
    309         switch (cred->type) { 
    310                 case SML_AUTH_TYPE_BASIC: 
    311                         if (!_smlXmlAssemblerAddStringNS(assm, SML_ELEMENT_TYPE, SML_NAMESPACE_METINF, SML_AUTH_BASIC, error)) 
    312                                 goto error; 
    313                         break; 
    314                 case SML_AUTH_TYPE_MD5: 
    315                         if (!_smlXmlAssemblerAddStringNS(assm, SML_ELEMENT_TYPE, SML_NAMESPACE_METINF, SML_AUTH_MD5, error)) 
    316                                 goto error; 
    317                         break; 
    318                 default: 
    319                         smlErrorSet(error, SML_ERROR_GENERIC, "Unknown format"); 
    320                         goto error; 
    321         } 
    322          
    323         //META 
    324         if (!_smlXmlAssemblerEndNode(assm, error)) 
    325                 goto error; 
    326          
    327         if (!_smlXmlAssemblerAddData(assm, SML_ELEMENT_DATA, cred->data, strlen(cred->data), TRUE, error)) 
    328                 goto error; 
    329          
    330         if (!_smlXmlAssemblerEndNode(assm, error)) 
    331                 goto error; 
    332          
    333         smlTrace(TRACE_EXIT, "%s", __func__); 
    334         return TRUE; 
    335  
    336 error: 
    337         smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error)); 
    338         return FALSE; 
    339 
    340  
    341 SmlBool smlAccessAssemble(SmlXmlAssembler *assm, SmlCommand *change, SmlError **error) 
    342 
    343         smlTrace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, assm, change, error); 
    344         smlAssert(change); 
    345         smlAssert(assm); 
    346          
    347         if (!change->private.access.item) { 
    348                 smlErrorSet(error, SML_ERROR_GENERIC, "Missing item"); 
    349                 goto error; 
    350         } 
    351          
    352         if (!change->private.access.item->contenttype) { 
    353                 smlErrorSet(error, SML_ERROR_GENERIC, "Missing contenttype"); 
    354                 goto error; 
    355         } 
    356          
    357         //Meta 
    358         if (!_smlXmlAssemblerStartNode(assm, SML_ELEMENT_META, error)) 
    359                 goto error; 
    360          
    361         if (!_smlXmlAssemblerAddStringNS(assm, SML_ELEMENT_TYPE, SML_NAMESPACE_METINF, change->private.access.item->contenttype, error)) 
    362                 goto error; 
    363          
    364         //META 
    365         if (!_smlXmlAssemblerEndNode(assm, error)) 
    366                 goto error; 
    367          
    368         if (!smlItemAssemble(change->private.access.item, assm, error)) 
    369                 goto error; 
    370          
    371         smlTrace(TRACE_EXIT, "%s", __func__); 
    372         return TRUE; 
    373  
    374 error: 
    375         smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error)); 
    376         return FALSE; 
    377 
    378  
    379 SmlBool smlChangeAssemble(SmlXmlAssembler *assm, SmlCommand *change, SmlError **error) 
    380 
    381         smlTrace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, assm, change, error); 
    382         smlAssert(change); 
    383         smlAssert(assm); 
    384          
    385         if (!change->private.change.items || 
    386             !g_list_length(change->private.change.items)) { 
    387                 smlErrorSet(error, SML_ERROR_GENERIC, "Missing items"); 
    388                 goto error; 
    389         } 
    390  
    391         /* libsyncml only supports one item per change command */ 
    392         smlAssert(g_list_length(change->private.change.items) == 1); 
    393         SmlItem *item = g_list_nth_data(change->private.change.items, 0); 
    394  
    395         if (!item) { 
    396                 smlErrorSet(error, SML_ERROR_GENERIC, "One item of the item list is NULL."); 
    397                 goto error; 
    398         } 
    399         if (!item->contenttype) { 
    400                 smlErrorSet(error, SML_ERROR_GENERIC, "Missing contenttype"); 
    401                 goto error; 
    402         } 
    403          
    404         //Meta 
    405         if (!_smlXmlAssemblerStartNode(assm, SML_ELEMENT_META, error)) 
    406                 goto error; 
    407          
    408         if (!_smlXmlAssemblerAddStringNS(assm, SML_ELEMENT_TYPE, SML_NAMESPACE_METINF, item->contenttype, error)) 
    409                 goto error; 
    410          
    411         /* We will add the max obj size node, if USE_LARGEOBJECTS is true or not set at all. 
    412          * And the remote side must have set a maxobjsize if we are a server */ 
    413         const char *opt = smlAssemblerGetOption(assm->assembler, "USE_LARGEOBJECTS"); 
    414         SmlBool supportsLargeObjects = (opt && !atoi(opt)) ? FALSE : TRUE; 
    415          
    416         smlTrace(TRACE_INTERNAL, "Large object: use %i, server %i, requestedSize %i", supportsLargeObjects, assm->session->sessionType == SML_SESSION_TYPE_SERVER ? 1 : 0, smlAssemblerGetRemoteMaxObjSize(assm->assembler)); 
    417          
    418         if (assm->session->sessionType == SML_SESSION_TYPE_SERVER) { 
    419                 if (smlAssemblerGetRemoteMaxObjSize(assm->assembler) == -1) 
    420                         supportsLargeObjects = FALSE; 
    421         } 
    422          
    423         if (supportsLargeObjects && change->size) { 
    424                 if (!_smlXmlAssemblerAddIDNS(assm, SML_ELEMENT_SIZE, SML_NAMESPACE_METINF, change->size, error)) 
    425                         goto error; 
    426         } 
    427  
    428         //META 
    429         if (!_smlXmlAssemblerEndNode(assm, error)) 
    430                 goto error; 
    431  
    432         //Item(s) 
    433         opt = smlAssemblerGetOption(assm->assembler, "ONLY_REPLACE"); 
    434         if (opt && atoi(opt) && change->type == SML_COMMAND_TYPE_ADD) { 
    435                 if (item->target) 
    436                         smlLocationUnref(item->target); 
    437                 item->target = item->source; 
    438                 item->source = NULL; 
    439         } 
    440          
    441         if (!smlItemAssemble(item, assm, error)) 
    442                 goto error; 
    443          
    444         smlTrace(TRACE_EXIT, "%s", __func__); 
    445         return TRUE; 
    446  
    447 error: 
    448         smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error)); 
    449         return FALSE; 
    450 
    451  
    452 SmlBool smlSyncAssemble(SmlXmlAssembler *assm, SmlCommand *cmd, SmlError **error) 
    453 
    454         smlTrace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, assm, cmd, error); 
    455         smlAssert(cmd); 
    456         smlAssert(assm); 
    457          
    458         if (!cmd->target) { 
    459                 smlErrorSet(error, SML_ERROR_GENERIC, "No target set"); 
    460                 goto error; 
    461         } 
    462          
    463         /* The specification OMA DS Protocol v1.2 allows to add 
    464          * MaxObjsize to Alert or Sync commands but all examples show 
    465          * it only in Alert commands. Therefore libsyncml adds it to 
    466          * Alert commands only. 
    467          */ 
    468  
    469         if (!smlLocationAssemble(cmd->target, assm, SML_ELEMENT_TARGET, error)) 
    470                 goto error; 
    471          
    472         if (!cmd->source) { 
    473                 smlErrorSet(error, SML_ERROR_GENERIC, "No source set"); 
    474                 goto error; 
    475         } 
    476          
    477         if (!smlLocationAssemble(cmd->source, assm, SML_ELEMENT_SOURCE, error)) 
    478                 goto error; 
    479  
    480         if (_smlAssembleUseMaxObjSize(assm)) 
    481         { 
    482                 if (!_smlXmlAssemblerStartNode(assm, SML_ELEMENT_META, error)) 
    483                         goto error; 
    484  
    485                 if (!_smlAssembleMaxObjSize(assm, error)) 
    486                         goto error; 
    487  
    488                 if (!_smlXmlAssemblerEndNode(assm, error)) 
    489                         goto error; 
    490         } 
    491  
    492         const char *opt = smlAssemblerGetOption(assm->assembler, "USE_NUMBEROFCHANGES"); 
    493         SmlBool supportsNumberOfChanges = (opt && !atoi(opt)) ? FALSE : TRUE; 
    494         if (supportsNumberOfChanges && assm->session->version != SML_VERSION_10) { 
    495                 if (!_smlXmlAssemblerAddID(assm, SML_ELEMENT_NUMBEROFCHANGES, cmd->private.sync.numChanged, error)) 
    496                         goto error; 
    497         } 
    498          
    499         smlTrace(TRACE_EXIT, "%s", __func__); 
    500         return TRUE; 
    501  
    502 error: 
    503         smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error)); 
    504         return FALSE; 
    505 
    506  
    507 SmlBool smlMapItemAssemble(SmlXmlAssembler *assm, SmlMapItem *item, SmlError **error) 
    508 
    509         smlTrace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, assm, item, error); 
    510         smlAssert(assm); 
    511         smlAssert(item); 
    512                  
    513         if (!_smlXmlAssemblerStartNode(assm, SML_ELEMENT_MAPITEM, error)) 
    514                 goto error; 
    515          
    516         if (item->source) { 
    517                 if (!smlLocationAssemble(item->source, assm, SML_ELEMENT_SOURCE, error)) 
    518                         goto error; 
    519         } 
    520          
    521         if (item->target) { 
    522                 if (!smlLocationAssemble(item->target, assm, SML_ELEMENT_TARGET, error)) 
    523                         goto error; 
    524         } 
    525          
    526         //MapItem 
    527         if (!_smlXmlAssemblerEndNode(assm, error)) 
    528                 goto error; 
    529          
    530         smlTrace(TRACE_EXIT, "%s", __func__); 
    531         return TRUE; 
    532  
    533 error: 
    534         smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error)); 
    535         return FALSE; 
    536 
    537  
    538 SmlBool smlMapAssemble(SmlXmlAssembler *assm, SmlCommand *cmd, SmlError **error) 
    539 
    540         smlTrace(TRACE_ENTRY, "%s(%p, %p, %p, %p)", __func__, assm, cmd, error); 
    541         smlAssert(cmd); 
    542         smlAssert(assm); 
    543          
    544         if (!cmd->target) { 
    545                 smlErrorSet(error, SML_ERROR_GENERIC, "No target set"); 
    546                 goto error; 
    547         } 
    548          
    549         if (!smlLocationAssemble(cmd->target, assm, SML_ELEMENT_TARGET, error)) 
    550                 goto error; 
    551          
    552         if (!cmd->source) { 
    553                 smlErrorSet(error, SML_ERROR_GENERIC, "No source set"); 
    554                 goto error; 
    555         } 
    556          
    557         if (!smlLocationAssemble(cmd->source, assm, SML_ELEMENT_SOURCE, error)) 
    558                 goto error; 
    559                  
    560         GList *m = NULL; 
    561         for (m = cmd->private.map.items; m; m = m->next) { 
    562                 SmlMapItem *item = m->data; 
    563                 if (!smlMapItemAssemble(assm, item, error)) 
    564                         goto error; 
    565         } 
    566          
    567         smlTrace(TRACE_EXIT, "%s", __func__); 
    568         return TRUE; 
    569  
    570 error: 
    571         smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error)); 
    572         return FALSE; 
    573 
    574  
    575 SmlBool _smlAssembleUseMaxObjSize(SmlXmlAssembler *assm) 
     135static SmlBool _smlAssembleUseMaxObjSize(SmlXmlAssembler *assm) 
    576136{ 
    577137        smlTrace(TRACE_ENTRY, "%s(%p)", __func__, assm); 
     
    604164} 
    605165 
    606 SmlBool _smlAssembleMaxObjSize(SmlXmlAssembler *assm, SmlError **error) 
     166static SmlBool _smlAssembleMaxObjSize(SmlXmlAssembler *assm, SmlError **error) 
    607167{ 
    608168        smlTrace(TRACE_ENTRY, "%s(%p)", __func__, assm); 
     
    629189                goto error; 
    630190 
     191        smlTrace(TRACE_EXIT, "%s", __func__); 
     192        return TRUE; 
     193 
     194error: 
     195        smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error)); 
     196        return FALSE; 
     197} 
     198 
     199SmlBool smlLocationAssemble(SmlLocation *location, SmlXmlAssembler *assm, const char *name, SmlError **error) 
     200{ 
     201        smlTrace(TRACE_ENTRY, "%s(%p, %p, %s, %p)", __func__, location, assm, name, error); 
     202        smlAssert(assm); 
     203        smlAssert(location); 
     204         
     205        if (name) { 
     206                if (!_smlXmlAssemblerStartNode(assm, name, error)) 
     207                        goto error; 
     208        } 
     209         
     210        if (!location->locURI) { 
     211                smlErrorSet(error, SML_ERROR_GENERIC, "No locURI set"); 
     212                goto error; 
     213        } 
     214         
     215        if (!_smlXmlAssemblerAddString(assm, SML_ELEMENT_LOCURI, location->locURI, error)) 
     216                goto error; 
     217         
     218        if (location->locName) { 
     219                if (!_smlXmlAssemblerAddString(assm, SML_ELEMENT_LOCNAME, location->locName, error)) 
     220                        goto error; 
     221        } 
     222         
     223        if (name) { 
     224                if (!_smlXmlAssemblerEndNode(assm, error)) 
     225                        goto error; 
     226        } 
     227         
     228        smlTrace(TRACE_EXIT, "%s", __func__); 
     229        return TRUE; 
     230 
     231error: 
     232        smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error)); 
     233        return FALSE; 
     234} 
     235 
     236 
     237 
     238SmlBool smlAnchorAssemble(SmlAnchor *anchor, SmlXmlAssembler *assm, SmlError **error) 
     239{ 
     240        smlTrace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, anchor, assm, error); 
     241        smlAssert(assm); 
     242        smlAssert(anchor); 
     243 
     244        /* Start the anchor and switch to syncml:metinf namespace. 
     245         * It is not possible to remove the namespace from Last and 
     246         * Next because otherwise the Status commands could be longer 
     247         * then the Alert commands. If this would happen then the 
     248         * Status commands alone could be longer than MaxMsgSize. 
     249         * 
     250         * It is not sure how a mobile would react in this situation. 
     251         */ 
     252        if (!_smlXmlAssemblerStartNodeNS(assm, SML_ELEMENT_ANCHOR, SML_NAMESPACE_METINF, error)) 
     253                goto error; 
     254         
     255        if (!anchor->next) { 
     256                smlErrorSet(error, SML_ERROR_GENERIC, "No next set"); 
     257                goto error; 
     258        } 
     259         
     260        /* SyncML Meta-Information DTD 1.1, Page 6, 5.1 Anchor - Content Model: (Last?, Next) 
     261           Last is optional, don't write a empty Last node. 
     262         */  
     263        if (anchor->last) { 
     264                if (!_smlXmlAssemblerAddStringNS(assm, SML_ELEMENT_LAST, SML_NAMESPACE_METINF, anchor->last, error)) 
     265                        goto error; 
     266                 
     267        } 
     268         
     269        if (!_smlXmlAssemblerAddStringNS(assm, SML_ELEMENT_NEXT, SML_NAMESPACE_METINF, anchor->next, error)) 
     270                goto error; 
     271         
     272        if (!_smlXmlAssemblerEndNode(assm, error)) 
     273                goto error; 
     274         
     275        smlTrace(TRACE_EXIT, "%s", __func__); 
     276        return TRUE; 
     277 
     278error: 
     279        smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error)); 
     280        return FALSE; 
     281} 
     282 
     283SmlBool smlItemAssemble(SmlItem *item, SmlXmlAssembler *assm, SmlError **error) 
     284{ 
     285        smlTrace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, item, assm, error); 
     286        smlAssert(assm); 
     287        smlAssert(item); 
     288         
     289        if (assm->moreDataSet) { 
     290                smlErrorSet(error, SML_ERROR_GENERIC, "Trying to start a new item while last item had more data"); 
     291                goto error; 
     292        } 
     293 
     294        /* Begin of Item */ 
     295        if (!_smlXmlAssemblerStartNode(assm, SML_ELEMENT_ITEM, error)) 
     296                goto error; 
     297 
     298        /* Target */ 
     299        if (smlItemGetTarget(item)) { 
     300                if (!smlLocationAssemble(smlItemGetTarget(item), assm, SML_ELEMENT_TARGET, error)) 
     301                        goto error; 
     302        } 
     303 
     304        /* Source */ 
     305        if (smlItemGetSource(item)) { 
     306                if (!smlLocationAssemble(smlItemGetSource(item), assm, SML_ELEMENT_SOURCE, error)) 
     307                        goto error; 
     308        } 
     309 
     310        /* SourceParent */ 
     311 
     312        /* TargetParent */ 
     313 
     314        /* Data */ 
     315        if (smlItemHasData(item)) { 
     316                if (item->disabled) { 
     317                        if (!_smlXmlAssemblerAddData(assm, SML_ELEMENT_DATA, "", 0, item->raw, error)) 
     318                                goto error; 
     319                } else { 
     320                        char *data = NULL; 
     321                        unsigned int size = 0; 
     322                        if (!smlItemGetData(item, &data, &size, error)) 
     323                                goto error; 
     324                         
     325                        if (!_smlXmlAssemblerAddData(assm, SML_ELEMENT_DATA, data, size, item->raw, error)) 
     326                                goto error; 
     327                } 
     328        } 
     329 
     330        /* MoreData */ 
     331        if (item->moreData) { 
     332                if (!_smlXmlAssemblerAddString(assm, SML_ELEMENT_MOREDATA, "", error)) 
     333                        goto error; 
     334                 
     335                assm->moreDataSet = TRUE; 
     336        } 
     337 
     338        /* End of Item */ 
     339        if (!_smlXmlAssemblerEndNode(assm, error)) 
     340                goto error; 
     341         
     342        smlTrace(TRACE_EXIT, "%s", __func__); 
     343        return TRUE; 
     344 
     345error: 
     346        smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error)); 
     347        return FALSE; 
     348} 
     349 
     350SmlBool smlCredAssemble(SmlCred *cred, SmlXmlAssembler *assm, SmlError **error) 
     351{ 
     352        smlTrace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, cred, assm, error); 
     353        smlAssert(assm); 
     354        smlAssert(cred); 
     355                 
     356        if (!_smlXmlAssemblerStartNode(assm, SML_ELEMENT_CRED, error)) 
     357                goto error; 
     358         
     359        //Meta 
     360        if (!_smlXmlAssemblerStartNode(assm, SML_ELEMENT_META, error)) 
     361                goto error; 
     362         
     363        switch (cred->format) { 
     364                case SML_FORMAT_TYPE_BASE64: 
     365                        if (!_smlXmlAssemblerAddStringNS(assm, SML_ELEMENT_FORMAT, SML_NAMESPACE_METINF, SML_BASE64, error)) 
     366                                goto error; 
     367                        break; 
     368                default: 
     369                        smlErrorSet(error, SML_ERROR_GENERIC, "SyncML credential: Unknown format %d.", cred->format); 
     370                        goto error; 
     371        } 
     372         
     373        switch (cred->type) { 
     374                case SML_AUTH_TYPE_BASIC: 
     375                        if (!_smlXmlAssemblerAddStringNS(assm, SML_ELEMENT_TYPE, SML_NAMESPACE_METINF, SML_AUTH_BASIC, error)) 
     376                                goto error; 
     377                        break; 
     378                case SML_AUTH_TYPE_MD5: 
     379                        if (!_smlXmlAssemblerAddStringNS(assm, SML_ELEMENT_TYPE, SML_NAMESPACE_METINF, SML_AUTH_MD5, error)) 
     380                                goto error; 
     381                        break; 
     382                default: 
     383                        smlErrorSet(error, SML_ERROR_GENERIC, "Unknown format"); 
     384                        goto error; 
     385        } 
     386         
     387        //META 
     388        if (!_smlXmlAssemblerEndNode(assm, error)) 
     389                goto error; 
     390         
     391        if (!_smlXmlAssemblerAddData(assm, SML_ELEMENT_DATA, cred->data, strlen(cred->data), TRUE, error)) 
     392                goto error; 
     393         
     394        if (!_smlXmlAssemblerEndNode(assm, error)) 
     395                goto error; 
     396         
     397        smlTrace(TRACE_EXIT, "%s", __func__); 
     398        return TRUE; 
     399 
     400error: 
     401        smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error)); 
     402        return FALSE; 
     403} 
     404 
     405SmlBool smlAccessAssemble(SmlXmlAssembler *assm, SmlCommand *change, SmlError **error) 
     406{ 
     407        smlTrace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, assm, change, error); 
     408        smlAssert(change); 
     409        smlAssert(assm); 
     410         
     411        if (!change->private.access.item) { 
     412                smlErrorSet(error, SML_ERROR_GENERIC, "Missing item"); 
     413                goto error; 
     414        } 
     415         
     416        if (!change->private.access.item->contenttype) { 
     417                smlErrorSet(error, SML_ERROR_GENERIC, "Missing contenttype"); 
     418                goto error; 
     419        } 
     420         
     421        //Meta 
     422        if (!_smlXmlAssemblerStartNode(assm, SML_ELEMENT_META, error)) 
     423                goto error; 
     424         
     425        if (!_smlXmlAssemblerAddStringNS(assm, SML_ELEMENT_TYPE, SML_NAMESPACE_METINF, change->private.access.item->contenttype, error)) 
     426                goto error; 
     427         
     428        //META 
     429        if (!_smlXmlAssemblerEndNode(assm, error)) 
     430                goto error; 
     431         
     432        if (!smlItemAssemble(change->private.access.item, assm, error)) 
     433                goto error; 
     434         
     435        smlTrace(TRACE_EXIT, "%s", __func__); 
     436        return TRUE; 
     437 
     438error: 
     439        smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error)); 
     440        return FALSE; 
     441} 
     442 
     443SmlBool smlChangeAssemble(SmlXmlAssembler *assm, SmlCommand *change, SmlError **error) 
     444{ 
     445        smlTrace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, assm, change, error); 
     446        smlAssert(change); 
     447        smlAssert(assm); 
     448         
     449        if (!change->private.change.items || 
     450            !g_list_length(change->private.change.items)) { 
     451                smlErrorSet(error, SML_ERROR_GENERIC, "Missing items"); 
     452                goto error; 
     453        } 
     454 
     455        /* libsyncml only supports one item per change command */ 
     456        smlAssert(g_list_length(change->private.change.items) == 1); 
     457        SmlItem *item = g_list_nth_data(change->private.change.items, 0); 
     458 
     459        if (!item) { 
     460                smlErrorSet(error, SML_ERROR_GENERIC, "One item of the item list is NULL."); 
     461                goto error; 
     462        } 
     463        if (!item->contenttype) { 
     464                smlErrorSet(error, SML_ERROR_GENERIC, "Missing contenttype"); 
     465                goto error; 
     466        } 
     467         
     468        //Meta 
     469        if (!_smlXmlAssemblerStartNode(assm, SML_ELEMENT_META, error)) 
     470                goto error; 
     471         
     472        if (!_smlXmlAssemblerAddStringNS(assm, SML_ELEMENT_TYPE, SML_NAMESPACE_METINF, item->contenttype, error)) 
     473                goto error; 
     474         
     475        /* We will add the max obj size node, if USE_LARGEOBJECTS is true or not set at all. 
     476         * And the remote side must have set a maxobjsize if we are a server */ 
     477        const char *opt = smlAssemblerGetOption(assm->assembler, "USE_LARGEOBJECTS"); 
     478        SmlBool supportsLargeObjects = (opt && !atoi(opt)) ? FALSE : TRUE; 
     479         
     480        smlTrace(TRACE_INTERNAL, "Large object: use %i, server %i, requestedSize %i", supportsLargeObjects, assm->session->sessionType == SML_SESSION_TYPE_SERVER ? 1 : 0, smlAssemblerGetRemoteMaxObjSize(assm->assembler)); 
     481         
     482        if (assm->session->sessionType == SML_SESSION_TYPE_SERVER) { 
     483                if (smlAssemblerGetRemoteMaxObjSize(assm->assembler) == -1) 
     484                        supportsLargeObjects = FALSE; 
     485        } 
     486         
     487        if (supportsLargeObjects && change->size) { 
     488                if (!_smlXmlAssemblerAddIDNS(assm, SML_ELEMENT_SIZE, SML_NAMESPACE_METINF, change->size, error)) 
     489                        goto error; 
     490        } 
     491 
     492        //META 
     493        if (!_smlXmlAssemblerEndNode(assm, error)) 
     494                goto error; 
     495 
     496        //Item(s) 
     497        opt = smlAssemblerGetOption(assm->assembler, "ONLY_REPLACE"); 
     498        if (opt && atoi(opt) && change->type == SML_COMMAND_TYPE_ADD) { 
     499                if (item->target) 
     500                        smlLocationUnref(item->target); 
     501                item->target = item->source; 
     502                item->source = NULL; 
     503        } 
     504         
     505        if (!smlItemAssemble(item, assm, error)) 
     506                goto error; 
     507         
     508        smlTrace(TRACE_EXIT, "%s", __func__); 
     509        return TRUE; 
     510 
     511error: 
     512        smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error)); 
     513        return FALSE; 
     514} 
     515 
     516SmlBool smlSyncAssemble(SmlXmlAssembler *assm, SmlCommand *cmd, SmlError **error) 
     517{ 
     518        smlTrace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, assm, cmd, error); 
     519        smlAssert(cmd); 
     520        smlAssert(assm); 
     521         
     522        if (!cmd->target) { 
     523                smlErrorSet(error, SML_ERROR_GENERIC, "No target set"); 
     524                goto error; 
     525        } 
     526         
     527        /* The specification OMA DS Protocol v1.2 allows to add 
     528         * MaxObjsize to Alert or Sync commands but all examples show 
     529         * it only in Alert commands. Therefore libsyncml adds it to 
     530         * Alert commands only. 
     531         */ 
     532 
     533        if (!smlLocationAssemble(cmd->target, assm, SML_ELEMENT_TARGET, error)) 
     534                goto error; 
     535         
     536        if (!cmd->source) { 
     537                smlErrorSet(error, SML_ERROR_GENERIC, "No source set"); 
     538                goto error; 
     539        } 
     540         
     541        if (!smlLocationAssemble(cmd->source, assm, SML_ELEMENT_SOURCE, error)) 
     542                goto error; 
     543 
     544        if (_smlAssembleUseMaxObjSize(assm)) 
     545        { 
     546                if (!_smlXmlAssemblerStartNode(assm, SML_ELEMENT_META, error)) 
     547                        goto error; 
     548 
     549                if (!_smlAssembleMaxObjSize(assm, error)) 
     550                        goto error; 
     551 
     552                if (!_smlXmlAssemblerEndNode(assm, error)) 
     553                        goto error; 
     554        } 
     555 
     556        const char *opt = smlAssemblerGetOption(assm->assembler, "USE_NUMBEROFCHANGES"); 
     557        SmlBool supportsNumberOfChanges = (opt && !atoi(opt)) ? FALSE : TRUE; 
     558        if (supportsNumberOfChanges && assm->session->version != SML_VERSION_10) { 
     559                if (!_smlXmlAssemblerAddID(assm, SML_ELEMENT_NUMBEROFCHANGES, cmd->private.sync.numChanged, error)) 
     560                        goto error; 
     561        } 
     562         
     563        smlTrace(TRACE_EXIT, "%s", __func__); 
     564        return TRUE; 
     565 
     566error: 
     567        smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error)); 
     568        return FALSE; 
     569} 
     570 
     571SmlBool smlMapItemAssemble(SmlXmlAssembler *assm, SmlMapItem *item, SmlError **error) 
     572{ 
     573        smlTrace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, assm, item, error); 
     574        smlAssert(assm); 
     575        smlAssert(item); 
     576                 
     577        if (!_smlXmlAssemblerStartNode(assm, SML_ELEMENT_MAPITEM, error)) 
     578                goto error; 
     579         
     580        if (item->source) { 
     581                if (!smlLocationAssemble(item->source, assm, SML_ELEMENT_SOURCE, error)) 
     582                        goto error; 
     583        } 
     584         
     585        if (item->target) { 
     586                if (!smlLocationAssemble(item->target, assm, SML_ELEMENT_TARGET, error)) 
     587                        goto error; 
     588        } 
     589         
     590        //MapItem 
     591        if (!_smlXmlAssemblerEndNode(assm, error)) 
     592                goto error; 
     593         
     594        smlTrace(TRACE_EXIT, "%s", __func__); 
     595        return TRUE; 
     596 
     597error: 
     598        smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error)); 
     599        return FALSE; 
     600} 
     601 
     602SmlBool smlMapAssemble(SmlXmlAssembler *assm, SmlCommand *cmd, SmlError **error) 
     603{ 
     604        smlTrace(TRACE_ENTRY, "%s(%p, %p, %p, %p)", __func__, assm, cmd, error); 
     605        smlAssert(cmd); 
     606        smlAssert(assm); 
     607         
     608        if (!cmd->target) { 
     609                smlErrorSet(error, SML_ERROR_GENERIC, "No target set"); 
     610                goto error; 
     611        } 
     612         
     613        if (!smlLocationAssemble(cmd->target, assm, SML_ELEMENT_TARGET, error)) 
     614                goto error; 
     615         
     616        if (!cmd->source) { 
     617                smlErrorSet(error, SML_ERROR_GENERIC, "No source set"); 
     618                goto error; 
     619        } 
     620         
     621        if (!smlLocationAssemble(cmd->source, assm, SML_ELEMENT_SOURCE, error)) 
     622                goto error; 
     623                 
     624        GList *m = NULL; 
     625        for (m = cmd->private.map.items; m; m = m->next) { 
     626                SmlMapItem *item = m->data; 
     627                if (!smlMapItemAssemble(assm, item, error)) 
     628                        goto error; 
     629        } 
     630         
    631631        smlTrace(TRACE_EXIT, "%s", __func__); 
    632632        return TRUE; 
  • trunk/libsyncml/transports/obex_server.c

    r501 r506  
    651651        smlAssert(data || error); 
    652652        smlAssert(userdata); 
    653         SmlTransportObexServerEnv *env = userdata; 
     653        // Unused: SmlTransportObexServerEnv *env = userdata; 
    654654        SmlLinkObexServerEnv *linkenv = link; 
    655655        SmlError *local_error = NULL; 
  • trunk/tests/check_devinf.c

    r486 r506  
    5151                        break; 
    5252                case SML_MANAGER_CONNECT_DONE: 
     53                case SML_MANAGER_SESSION_ESTABLISHED: 
    5354                case SML_MANAGER_DISCONNECT_DONE: 
    5455                        /* FIXME: Why is it an error if the transport layer signals correctly? */ 
  • trunk/tests/check_ds.c

    r486 r506  
    452452                                        smlDsSessionRecvSync(session, command, corr->dsession); 
    453453                                        break; 
     454                                default: 
     455                                        fail("Unexpected command"); 
     456                                        break; 
    454457                        } 
    455458                        break; 
  • trunk/tests/check_manager.c

    r502 r506  
    9595                        break; 
    9696                case SML_MANAGER_CONNECT_DONE: 
     97                case SML_MANAGER_SESSION_ESTABLISHED: 
    9798                case SML_MANAGER_DISCONNECT_DONE: 
    9899                        /* FIXME: Why is it an error if the transport layer signals correctly? */ 
  • trunk/tests/check_san.c

    r488 r506  
    4848} 
    4949 
    50 void *_stop_manager(SmlManager *manager) 
     50void _stop_manager(SmlManager *manager) 
    5151{ 
    5252        smlManagerFree(manager); 
  • trunk/tests/check_session.c

    r488