# HG changeset patch # User Sebastien Decugis # Date 1243325825 -32400 # Node ID 3591d0486a2c442c6c89ccd603c6859845f17b9f # Parent 0183e656d6abc9815e22267f16a411b39fc4d7b3 Allow NULL model in msg_new diff -r 0183e656d6ab -r 3591d0486a2c include/waaad/message-api.h --- a/include/waaad/message-api.h Tue May 26 16:35:43 2009 +0900 +++ b/include/waaad/message-api.h Tue May 26 17:17:05 2009 +0900 @@ -259,7 +259,7 @@ * FUNCTION: msg_new * * PARAMETERS: - * model : Pointer to a DICT_COMMAND dictionary object describing the message to create. + * model : Pointer to a DICT_COMMAND dictionary object describing the message to create, or NULL. * flags : combination of MSGFL_* flags. * msg : Upon success, pointer to the new message is stored here. * diff -r 0183e656d6ab -r 3591d0486a2c waaad/message.c --- a/waaad/message.c Tue May 26 16:35:43 2009 +0900 +++ b/waaad/message.c Tue May 26 17:17:05 2009 +0900 @@ -1439,34 +1439,38 @@ TRACE_ENTRY("%p %x %p", model, flags, msg); /* Check the parameters */ - CHECK_PARAMS( model && msg && CHECK_MSGFL(flags) ); + CHECK_PARAMS( msg && CHECK_MSGFL(flags) ); - ret = dict_gettype(model, &dicttype); - if (ret || (dicttype != DICT_COMMAND)) { - TRACE_DEBUG (INFO, "(%d, %d) -> EINVAL.", ret, dicttype ); - return EINVAL; + if (model) { + ret = dict_gettype(model, &dicttype); + if (ret || (dicttype != DICT_COMMAND)) { + TRACE_DEBUG (INFO, "(%d, %d) -> EINVAL.", ret, dicttype ); + return EINVAL; + } + + CHECK_FCT( dict_getval(model, &dictdata) ); } - CHECK_FCT( dict_getval(model, &dictdata) ); - /* Create a new object */ CHECK_MALLOC( new = (_msg_t *) malloc (sizeof(_msg_t)) ); /* Initialize the fields */ init_msg(new); - new->msg_model = model; - new->msg_public.msg_version = MSG_VERSION; new->msg_public.msg_length = GETMSGHDRSZ(); /* This will be updated later */ - new->msg_public.msg_flags = dictdata.cmd_flag_val; - new->msg_public.msg_code = dictdata.cmd_code; - - /* Initialize application from the parent, if any */ - CHECK_FCT( dict_search( DICT_APPLICATION, APPLICATION_OF_COMMAND, model, &dictappl) ); - if (dictappl != NULL) { - dict_application_data_t appdata; - CHECK_FCT( dict_getval(dictappl, &appdata) ); - new->msg_public.msg_appl = appdata.application_id; + + if (model) { + new->msg_model = model; + new->msg_public.msg_flags = dictdata.cmd_flag_val; + new->msg_public.msg_code = dictdata.cmd_code; + + /* Initialize application from the parent, if any */ + CHECK_FCT( dict_search( DICT_APPLICATION, APPLICATION_OF_COMMAND, model, &dictappl) ); + if (dictappl != NULL) { + dict_application_data_t appdata; + CHECK_FCT( dict_getval(dictappl, &appdata) ); + new->msg_public.msg_appl = appdata.application_id; + } } if (flags & MSGFL_ALLOW_ETEID) { @@ -1474,7 +1478,7 @@ } /* Create the children from template if needed */ - if (flags & MSGFL_FROM_TEMPLATE) { + if (model && (flags & MSGFL_FROM_TEMPLATE)) { cb_data_t data = { _C(new), flags}; CHECK_FCT_DO( ret = dict_iterate_rules ( model, &data, create_child_avp ), {