Mercurial > hg > waaad
diff waaad/message.c @ 411:7b3d4431610a
Improved support for creating error messages, even when no dictionary definition is present
author | Sebastien Decugis <sdecugis@nict.go.jp> |
---|---|
date | Thu, 11 Jun 2009 18:08:17 +0900 |
parents | 316bb3f38d04 |
children |
line wrap: on
line diff
--- a/waaad/message.c Thu Jun 11 16:59:45 2009 +0900 +++ b/waaad/message.c Thu Jun 11 18:08:17 2009 +0900 @@ -1502,12 +1502,24 @@ qry = _M(*msg); /* Find the model for the answer */ - CHECK_FCT( _mpd_do_msg(qry, 0, 1) ); - CHECK_FCT( dict_search ( DICT_COMMAND, CMD_ANSWER, qry->msg_model, &model, EINVAL ) ); + if (flags & MSGFL_ANSW_ERROR) { + /* The model is the generic error format */ + model = dict_cmd_error; + } else { + /* The model is the answer corresponding to the query. It supposes that these are defined in the dictionary */ + CHECK_FCT( _mpd_do_msg(qry, 0, 1) ); + CHECK_FCT( dict_search ( DICT_COMMAND, CMD_ANSWER, qry->msg_model, &model, EINVAL ) ); + } /* Create the answer */ CHECK_FCT( msg_new( model, flags, msg ) ); + /* Set informations in the answer as in the query */ + _M(*msg)->msg_public.msg_code = qry->msg_public.msg_code; /* useful for MSGFL_ANSW_ERROR */ + _M(*msg)->msg_public.msg_appl = qry->msg_public.msg_appl; + _M(*msg)->msg_public.msg_eteid = qry->msg_public.msg_eteid; + _M(*msg)->msg_public.msg_hbhid = qry->msg_public.msg_hbhid; + /* associate with query */ /* may do that but this is faster... CHECK_FCT( msg_answ_associate( *msg, (msg_t *)qry ) ); */ _M(*msg)->msg_query = (msg_t *)qry; @@ -2320,8 +2332,8 @@ return 0; } -/* Create an anwer to a query */ -int msg_new_answer_from_req ( msg_t ** msg ) +/* Create an anwer to a query, possibly an error message */ +int msg_new_answer_from_req ( msg_t ** msg, int error ) { _msg_t *qry; @@ -2333,7 +2345,7 @@ CHECK_PARAMS( qry->msg_public.msg_flags & CMD_FLAG_REQUEST ); /* Create the new message */ - CHECK_FCT( msg_new_answ(msg, 0) ); + CHECK_FCT( msg_new_answ(msg, error ? MSGFL_ANSW_ERROR : 0) ); /* If the first AVP of the query is a Session-Id, copy it to the answer */ { @@ -2463,12 +2475,15 @@ } - if (set_e_bit) { + { msg_data_t * hdr = NULL; CHECK_FCT( msg_data( msg, &hdr ) ); - hdr->msg_flags |= CMD_FLAG_ERROR; + if (set_e_bit) + hdr->msg_flags |= CMD_FLAG_ERROR; + else + hdr->msg_flags &= ! CMD_FLAG_ERROR; } if (std_err_msg || errormsg) {