Changeset 490

Show
Ignore:
Timestamp:
07/14/08 14:58:59 (4 months ago)
Author:
bellmich
Message:

enforce error handling and give nice error messages

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/libsyncml/objects/sml_ds_server.c

    r477 r490  
    188188        smlTrace(TRACE_ENTRY, "%s(%s, %p, %p)", __func__, type, location, error); 
    189189        smlAssert(location); 
     190        smlAssertMsg(error, SML_ASSERT_MSG_ERROR_MUST_NOT_BE_NULL); 
     191        smlAssertMsg(*error == NULL, SML_ASSERT_MSG_ERROR_MUST_BE_EMPTY); 
    190192         
    191193        SmlDsServer *server = smlTryMalloc0(sizeof(SmlDsServer), error); 
     
    212214        smlAssert(location); 
    213215        smlAssert(target); 
     216        smlAssertMsg(error, SML_ASSERT_MSG_ERROR_MUST_NOT_BE_NULL); 
     217        smlAssertMsg(*error == NULL, SML_ASSERT_MSG_ERROR_MUST_BE_EMPTY); 
    214218         
    215219        SmlDsServer *server = smlTryMalloc0(sizeof(SmlDsServer), error); 
     
    311315        smlAssert(server); 
    312316        smlAssert(san); 
     317        smlAssertMsg(error, SML_ASSERT_MSG_ERROR_MUST_NOT_BE_NULL); 
     318        smlAssertMsg(*error == NULL, SML_ASSERT_MSG_ERROR_MUST_BE_EMPTY); 
    313319         
    314320        if (!smlNotificationNewAlert(san, SML_ALERT_TWO_WAY_BY_SERVER, server->contenttype, smlLocationGetURI(server->location), error)) 
     
    353359        smlAssert(server); 
    354360        smlAssert(session); 
     361        smlAssertMsg(error, SML_ASSERT_MSG_ERROR_MUST_NOT_BE_NULL); 
     362        smlAssertMsg(*error == NULL, SML_ASSERT_MSG_ERROR_MUST_BE_EMPTY); 
    355363         
    356364        SmlDsSession *dsession = smlDsSessionNew(server, session, error); 
     
    386394        smlTrace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, server, session, error); 
    387395        smlAssert(server); 
     396        smlAssertMsg(error, SML_ASSERT_MSG_ERROR_MUST_NOT_BE_NULL); 
     397        smlAssertMsg(*error == NULL, SML_ASSERT_MSG_ERROR_MUST_BE_EMPTY); 
    388398         
    389399        SmlDsSession *dsession = smlTryMalloc0(sizeof(SmlDsSession), error); 
     
    926936        smlTrace(TRACE_ENTRY, "%s(%p, %i, %s, %s, %p)", __func__, dsession, type, last, next, error); 
    927937        smlAssert(dsession); 
     938        smlAssertMsg(error, SML_ASSERT_MSG_ERROR_MUST_NOT_BE_NULL); 
     939        smlAssertMsg(*error == NULL, SML_ASSERT_MSG_ERROR_MUST_BE_EMPTY); 
    928940         
    929941        SmlCommand *alert = smlCommandNewAlert(type, dsession->target, dsession->location, next, last, NULL, error); 
     
    10191031        smlTrace(TRACE_ENTRY, "%s(%p, %i, %p, %p, %p)", __func__, dsession, num_changes, callback, userdata, error); 
    10201032        smlAssert(dsession); 
     1033        smlAssertMsg(error, SML_ASSERT_MSG_ERROR_MUST_NOT_BE_NULL); 
     1034        smlAssertMsg(*error == NULL, SML_ASSERT_MSG_ERROR_MUST_BE_EMPTY); 
    10211035         
    10221036        if (dsession->syncCommand) { 
     
    10481062        smlTrace(TRACE_ENTRY, "%s(%p, %i, %s, %p, %i, %s, %p, %p, %p)", __func__, dsession, type, uid, data, size, contenttype, callback, userdata, error); 
    10491063        smlAssert(dsession); 
     1064        smlAssertMsg(error, SML_ASSERT_MSG_ERROR_MUST_NOT_BE_NULL); 
     1065        smlAssertMsg(*error == NULL, SML_ASSERT_MSG_ERROR_MUST_BE_EMPTY); 
    10501066         
    10511067        if (!dsession->syncCommand) { 
     
    10981114        smlTrace(TRACE_ENTRY, "%s(%p, %p)", __func__, dsession, error); 
    10991115        smlAssert(dsession); 
     1116        smlAssertMsg(error, SML_ASSERT_MSG_ERROR_MUST_NOT_BE_NULL); 
     1117        smlAssertMsg(*error == NULL, SML_ASSERT_MSG_ERROR_MUST_BE_EMPTY); 
    11001118         
    11011119        if (!dsession->syncCommand) { 
     
    11221140        smlTrace(TRACE_ENTRY, "%s(%p, %s, %s, %p)", __func__, dsession, uid, newuid, error); 
    11231141        smlAssert(dsession); 
     1142        smlAssertMsg(error, SML_ASSERT_MSG_ERROR_MUST_NOT_BE_NULL); 
     1143        smlAssertMsg(*error == NULL, SML_ASSERT_MSG_ERROR_MUST_BE_EMPTY); 
    11241144         
    11251145        SmlMapItem *item = smlMapItemNew(uid, newuid, error); 
     
    11501170        smlTrace(TRACE_ENTRY, "%s(%p, %p, %p, %p)", __func__, dsession, callback, userdata, error); 
    11511171        smlAssert(dsession); 
     1172        smlAssertMsg(error, SML_ASSERT_MSG_ERROR_MUST_NOT_BE_NULL); 
     1173        smlAssertMsg(*error == NULL, SML_ASSERT_MSG_ERROR_MUST_BE_EMPTY); 
    11521174         
    11531175        if (!dsession->mapItems) { 
     
    12731295        smlAssert(server); 
    12741296        smlAssert(manager); 
     1297        smlAssertMsg(error, SML_ASSERT_MSG_ERROR_MUST_NOT_BE_NULL); 
     1298        smlAssertMsg(*error == NULL, SML_ASSERT_MSG_ERROR_MUST_BE_EMPTY); 
    12751299         
    12761300        if (!smlManagerObjectRegister(manager, SML_COMMAND_TYPE_ALERT, NULL, server->location, NULL, NULL, _recv_manager_alert, NULL, server, error)) 
  • trunk/libsyncml/sml_manager.c

    r489 r490  
    325325        smlTrace(TRACE_ENTRY, "%s(%p, %p)", __func__, tsp, error); 
    326326        smlAssert(tsp);          
     327        smlAssertMsg(error, SML_ASSERT_MSG_ERROR_MUST_NOT_BE_NULL); 
     328        smlAssertMsg(*error == NULL, SML_ASSERT_MSG_ERROR_MUST_BE_EMPTY); 
    327329         
    328330        SmlManager *manager = smlTryMalloc0(sizeof(SmlManager), error); 
     
    430432        smlTrace(TRACE_ENTRY, "%s(%p, %p)", __func__, manager, error); 
    431433        smlAssert(manager); 
     434        smlAssertMsg(error, SML_ASSERT_MSG_ERROR_MUST_NOT_BE_NULL); 
     435        smlAssertMsg(*error == NULL, SML_ASSERT_MSG_ERROR_MUST_BE_EMPTY); 
    432436     
    433437        manager->functions->prepare = _manager_prepare_internal; 
     
    629633{ 
    630634        smlTrace(TRACE_ENTRY, "%s(%p, %p, %p, %p)", __func__, manager, session, link, error); 
     635        smlAssertMsg(error, SML_ASSERT_MSG_ERROR_MUST_NOT_BE_NULL); 
     636        smlAssertMsg(*error == NULL, SML_ASSERT_MSG_ERROR_MUST_BE_EMPTY); 
    631637         
    632638        smlSessionRef(session); 
     
    782788        smlAssert(manager); 
    783789        smlAssert(callback); 
     790        smlAssertMsg(error, SML_ASSERT_MSG_ERROR_MUST_NOT_BE_NULL); 
     791        smlAssertMsg(*error == NULL, SML_ASSERT_MSG_ERROR_MUST_BE_EMPTY); 
    784792 
    785793        /* first we have to check if this an update for an already registered object */ 
     
    10191027        smlAssert(session); 
    10201028        smlAssert(header); 
     1029        smlAssertMsg(error, SML_ASSERT_MSG_ERROR_MUST_NOT_BE_NULL); 
     1030        smlAssertMsg(*error == NULL, SML_ASSERT_MSG_ERROR_MUST_BE_EMPTY); 
    10211031         
    10221032        //If not send command to default handler 
     
    10511061        smlAssert(session); 
    10521062        smlAssert(parent); 
     1063        smlAssertMsg(error, SML_ASSERT_MSG_ERROR_MUST_NOT_BE_NULL); 
     1064        smlAssertMsg(*error == NULL, SML_ASSERT_MSG_ERROR_MUST_BE_EMPTY); 
    10531065         
    10541066        //Check if a handler for this object at this path has been installed. 
     
    10931105        smlAssert(session); 
    10941106        smlAssert(cmd); 
     1107        smlAssertMsg(error, SML_ASSERT_MSG_ERROR_MUST_NOT_BE_NULL); 
     1108        smlAssertMsg(*error == NULL, SML_ASSERT_MSG_ERROR_MUST_BE_EMPTY); 
    10951109         
    10961110        //Check if a handler for this object at this path has been installed. 
  • trunk/libsyncml/sml_session.c

    r487 r490  
    9494        smlAssert(session); 
    9595        smlAssert(session->dataCallback); 
     96        smlAssertMsg(error, SML_ASSERT_MSG_ERROR_MUST_NOT_BE_NULL); 
     97        smlAssertMsg(*error == NULL, SML_ASSERT_MSG_ERROR_MUST_BE_EMPTY); 
    9698         
    9799        char *data = NULL; 
     
    199201{ 
    200202        smlTrace(TRACE_ENTRY, "%s(%p, %p, %p, %i, %i, %i, %p)", __func__, session, orig_cmd, parent, space, start, complete_size, error); 
     203        smlAssertMsg(error, SML_ASSERT_MSG_ERROR_MUST_NOT_BE_NULL); 
     204        smlAssertMsg(*error == NULL, SML_ASSERT_MSG_ERROR_MUST_BE_EMPTY); 
    201205        /* This library must not send more that one item per change 
    202206         * command. This is compliant with all specification and only a 
     
    299303        smlAssert(session); 
    300304        smlAssert(cmd); 
     305        smlAssertMsg(error, SML_ASSERT_MSG_ERROR_MUST_NOT_BE_NULL); 
     306        smlAssertMsg(*error == NULL, SML_ASSERT_MSG_ERROR_MUST_BE_EMPTY); 
    301307        SmlPendingStatus *pending = NULL; 
    302308        SmlBool fragmented = FALSE; 
     
    497503        smlTrace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, session, parent, error); 
    498504        smlAssert(session); 
     505        smlAssertMsg(error, SML_ASSERT_MSG_ERROR_MUST_NOT_BE_NULL); 
     506        smlAssertMsg(*error == NULL, SML_ASSERT_MSG_ERROR_MUST_BE_EMPTY); 
    499507         
    500508        if (!smlAssemblerEndCommand(session->assembler, parent, error)) 
     
    637645        smlAssert(session); 
    638646        smlAssert(header); 
     647        smlAssertMsg(error, SML_ASSERT_MSG_ERROR_MUST_NOT_BE_NULL); 
     648        smlAssertMsg(*error == NULL, SML_ASSERT_MSG_ERROR_MUST_BE_EMPTY); 
    639649 
    640650        /* check and set the counters */ 
     
    707717        smlTrace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, session, status, error); 
    708718        smlAssert(status); 
     719        smlAssertMsg(error, SML_ASSERT_MSG_ERROR_MUST_NOT_BE_NULL); 
     720        smlAssertMsg(*error == NULL, SML_ASSERT_MSG_ERROR_MUST_BE_EMPTY); 
    709721         
    710722        if (status->cmdRef == 0) { 
     
    936948        smlAssert(session); 
    937949        smlAssert(parser); 
     950        smlAssertMsg(error, SML_ASSERT_MSG_ERROR_MUST_NOT_BE_NULL); 
     951        smlAssertMsg(*error == NULL, SML_ASSERT_MSG_ERROR_MUST_BE_EMPTY); 
    938952        SmlStatus *status = NULL; 
    939953        SmlCommand *cmd = NULL; 
     
    17001714{ 
    17011715        smlTrace(TRACE_ENTRY, "%s(%i, %i, %i, %i, %p, %p, %s, %i, %p)", __func__, sessionType, mimetype, version, protocol, target, source, sessionID, messageID, error); 
     1716        smlAssertMsg(error, SML_ASSERT_MSG_ERROR_MUST_NOT_BE_NULL); 
     1717        smlAssertMsg(*error == NULL, SML_ASSERT_MSG_ERROR_MUST_BE_EMPTY); 
    17021718 
    17031719        /* Initialize GLib thread system. */ 
     
    18651881        smlTrace(TRACE_ENTRY, "%s(%p, %i, %p)", __func__, session, final, error); 
    18661882        smlAssert(session); 
    1867         smlAssert(error != NULL); /* common mistake */ 
    1868         smlAssert(*error == NULL); /* do not overwrite other error */ 
     1883        smlAssertMsg(error, SML_ASSERT_MSG_ERROR_MUST_NOT_BE_NULL); 
     1884        smlAssertMsg(*error == NULL, SML_ASSERT_MSG_ERROR_MUST_BE_EMPTY); 
    18691885         
    18701886        SmlSessionCommand *sesscmd = smlTryMalloc0(sizeof(SmlSessionCommand), error); 
     
    19131929        smlTrace(TRACE_ENTRY, "%s(%p, %p)", __func__, session, error); 
    19141930        smlAssert(session); 
    1915         smlAssert(error != NULL); /* common mistake */ 
    1916         smlAssert(*error == NULL); /* do not overwrite other error */ 
     1931        smlAssertMsg(error, SML_ASSERT_MSG_ERROR_MUST_NOT_BE_NULL); 
     1932        smlAssertMsg(*error == NULL, SML_ASSERT_MSG_ERROR_MUST_BE_EMPTY); 
    19171933 
    19181934        if (! g_mutex_trylock(session->reportEnd)) 
     
    22512267        smlAssert(session); 
    22522268        smlAssert(cmd); 
     2269        smlAssertMsg(error, SML_ASSERT_MSG_ERROR_MUST_NOT_BE_NULL); 
     2270        smlAssertMsg(*error == NULL, SML_ASSERT_MSG_ERROR_MUST_BE_EMPTY); 
    22532271         
    22542272        if (!smlSessionStartCommand(session, cmd, parent, callback, userdata, error)) 
     
    22822300        smlAssert(session); 
    22832301        smlAssert(cmd); 
     2302        smlAssertMsg(error, SML_ASSERT_MSG_ERROR_MUST_NOT_BE_NULL); 
     2303        smlAssertMsg(*error == NULL, SML_ASSERT_MSG_ERROR_MUST_BE_EMPTY); 
    22842304         
    22852305        SmlSessionCommand *sesscmd = smlTryMalloc0(sizeof(SmlSessionCommand), error); 
     
    23212341        smlTrace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, session, parent, error); 
    23222342        smlAssert(session); 
     2343        smlAssertMsg(error, SML_ASSERT_MSG_ERROR_MUST_NOT_BE_NULL); 
     2344        smlAssertMsg(*error == NULL, SML_ASSERT_MSG_ERROR_MUST_BE_EMPTY); 
    23232345         
    23242346        SmlSessionCommand *sesscmd = smlTryMalloc0(sizeof(SmlSessionCommand), error); 
     
    23622384        smlAssert(session); 
    23632385        smlAssert(status); 
     2386        smlAssertMsg(error, SML_ASSERT_MSG_ERROR_MUST_NOT_BE_NULL); 
     2387        smlAssertMsg(*error == NULL, SML_ASSERT_MSG_ERROR_MUST_BE_EMPTY); 
    23642388         
    23652389        SmlSessionCommand *sesscmd = smlTryMalloc0(sizeof(SmlSessionCommand), error); 
  • trunk/libsyncml/sml_transport.c

    r486 r490  
    718718        smlAssert(tsp); 
    719719        smlAssert(tsp->functions.finalize); 
     720        smlAssertMsg(error, SML_ASSERT_MSG_ERROR_MUST_NOT_BE_NULL); 
     721        smlAssertMsg(*error == NULL, SML_ASSERT_MSG_ERROR_MUST_BE_EMPTY); 
    720722 
    721723        if (tsp->state != SML_TRANSPORT_INITIALIZED && 
  • trunk/libsyncml/syncml_internals.h

    r295 r490  
    5656#include "sml_parse.h" 
    5757 
     58/* Error messages for assertions */ 
     59#define SML_ASSERT_MSG_ERROR_MUST_NOT_BE_NULL "The error handling of the function must be used." 
     60#define SML_ASSERT_MSG_ERROR_MUST_BE_EMPTY "The error parameter is already filled (ignored error)." 
     61 
    5862#endif