changeset 381:3591d0486a2c

Allow NULL model in msg_new
author Sebastien Decugis <sdecugis@nict.go.jp>
date Tue, 26 May 2009 17:17:05 +0900
parents 0183e656d6ab
children 8fdd47ce352a
files include/waaad/message-api.h waaad/message.c
diffstat 2 files changed, 24 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- 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.
  *
--- 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 ),  
 			{
"Welcome to our mercurial repository"