Mercurial > hg > waaad
changeset 175:37ac727cfee3
Added new function to add the Origin-* information to message
author | Sebastien Decugis <sdecugis@nict.go.jp> |
---|---|
date | Tue, 30 Sep 2008 17:38:57 +0900 |
parents | df5a4fc1076e |
children | 1783205793e2 |
files | waaad/message.c waaad/message.h |
diffstat | 2 files changed, 64 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/waaad/message.c Tue Sep 30 17:38:21 2008 +0900 +++ b/waaad/message.c Tue Sep 30 17:38:57 2008 +0900 @@ -137,7 +137,7 @@ #define CHECK_MSGFL(_fl) ( ((_fl) & (- (MSGFL_MAX << 1) )) == 0 ) /* initial sizes of AVP from their types, in bytes. -1 for unknown sizes */ -int avp_value_sizes[] = { +static int avp_value_sizes[] = { 0, /* AVP_TYPE_GROUPED: size is dynamic */ 0, /* AVP_TYPE_OCTETSTRING: size is dynamic */ 4, /* AVP_TYPE_INTEGER32: size is 32 bits */ @@ -150,6 +150,10 @@ #define CHECK_BASETYPE( _type ) ( (_type <= AVP_TYPE_MAX) && (_type >= 0) ) #define GETINITIALSIZE( _type, _vend ) (avp_value_sizes[ CHECK_BASETYPE(_type) ? _type : 0] + GETAVPHDRSZ(_vend)) +static dict_object_t * dict_avp_OH = NULL; /* Origin-Host */ +static dict_object_t * dict_avp_OR = NULL; /* Origin-Realm */ +static dict_object_t * dict_avp_OSI = NULL; /* Origin-State-Id */ + /***************************************************************************************************************/ /* Initialize a _msg_avp_chain_t structure */ @@ -1243,7 +1247,11 @@ { TRACE_ENTRY(""); - /* There are no globals to initialize in this module... */ + /* Initialize the dictionary objects that we may use frequently */ + CHECK_FCT( dict_search( DICT_AVP, AVP_BY_NAME, "Origin-Host", &dict_avp_OH ) ); + CHECK_FCT( dict_search( DICT_AVP, AVP_BY_NAME, "Origin-Realm", &dict_avp_OR ) ); + CHECK_FCT( dict_search( DICT_AVP, AVP_BY_NAME, "Origin-State-Id", &dict_avp_OSI) ); + return 0; } @@ -1973,3 +1981,54 @@ return 0; } +/* Add Origin-Host, Origin-Realm, Origin-State-Id AVPS at the end of the message */ +int msg_add_origin ( msg_t * msg ) +{ + avp_value_t val; + msg_avp_t * avp_OH = NULL; + msg_avp_t * avp_OR = NULL; + msg_avp_t * avp_OSI = NULL; + + TRACE_ENTRY("%p", msg); + + CHECK_PARAMS( CHECK_MSG(msg) ); + + /* Create the Origin-Host AVP */ + CHECK_FCT( msg_avp_new( dict_avp_OH, 0, &avp_OH ) ); + + /* Set its value */ + memset(&val, 0, sizeof(val)); + val.os.data = (unsigned char *)g_pconf->diameter_identity; + val.os.len = g_conf->diamid_len; + CHECK_FCT( msg_avp_setvalue( avp_OH, &val ) ); + + /* Add it to the message */ + CHECK_FCT( msg_avp_add( msg, MSG_BRW_LAST_CHILD, avp_OH ) ); + + + /* Create the Origin-Realm AVP */ + CHECK_FCT( msg_avp_new( dict_avp_OR, 0, &avp_OR ) ); + + /* Set its value */ + memset(&val, 0, sizeof(val)); + val.os.data = (unsigned char *)g_pconf->diameter_realm; + val.os.len = g_conf->realm_len; + CHECK_FCT( msg_avp_setvalue( avp_OR, &val ) ); + + /* Add it to the message */ + CHECK_FCT( msg_avp_add( msg, MSG_BRW_LAST_CHILD, avp_OR ) ); + + + /* Create the Origin-State-Id AVP */ + CHECK_FCT( msg_avp_new( dict_avp_OSI, 0, &avp_OSI ) ); + + /* Set its value */ + memset(&val, 0, sizeof(val)); + val.u32 = g_pconf->origin_state_id; + CHECK_FCT( msg_avp_setvalue( avp_OSI, &val ) ); + + /* Add it to the message */ + CHECK_FCT( msg_avp_add( msg, MSG_BRW_LAST_CHILD, avp_OSI ) ); + + return 0; +}
--- a/waaad/message.h Tue Sep 30 17:38:21 2008 +0900 +++ b/waaad/message.h Tue Sep 30 17:38:57 2008 +0900 @@ -209,5 +209,8 @@ void msg_dump_one ( void * obj ); +/* The following functions are used to achieve frequent operations on the messages */ +int msg_add_origin ( msg_t * msg ); /* Add Origin-Host, Origin-Realm, Origin-State-Id AVPS at the end of the message */ + #endif /* _MESSAGE_H */