Hello, Daniel-Constantin! >> I think yes, with documentation, it took some days. >ok, attach the patch as a file on the mailing list or bug tracker,
ready, attached >don't paste it inline because it is not easy to apply. I think need documentation patch too. what we get: modparam("misc_radius", "common_response", 1) // default is 0 when common_response is 0 (default) load_caller_avps and load_callee_avps work as before: look SIP-AVP in response and parse result for avp's. when common_response is 1 (set in config) load_caller_avps and load_callee_avps parse radius server response and all avpairs save in avp. integer and string values are parsed, other - skipped. examples that i posted before are ok. -- WBR, Victor JID: coy...@bks.tv JID: coy...@bryansktel.ru I use FREE operation system: 3.8.4-calculate GNU/Linux
diff --git a/modules/misc_radius/functions.c b/modules/misc_radius/functions.c index 2a42024..6d7d12d 100644 --- a/modules/misc_radius/functions.c +++ b/modules/misc_radius/functions.c @@ -107,6 +107,60 @@ error: return -1; } +static void generate_avps_rad(VALUE_PAIR* received) +{ + int_str name, val; + unsigned short flags; + VALUE_PAIR *vp; + + vp = received; + + for( ; vp ; vp=vp->next) { + flags = AVP_NAME_STR; + switch(vp->type) + { + case PW_TYPE_STRING: + flags |= AVP_VAL_STR; + name.s.len = strlen(vp->name); + val.s.len = strlen(vp->strvalue); + name.s.s = vp->name; + val.s.s = vp->strvalue; + if (add_avp( flags, name, val ) < 0) { + LM_ERR("unable to create a new AVP\n"); + } else { + LM_DBG("AVP '%.*s'/%d='%.*s'/%d has been added\n", + (flags&AVP_NAME_STR)?name.s.len:4, + (flags&AVP_NAME_STR)?name.s.s:"null", + (flags&AVP_NAME_STR)?0:name.n, + (flags&AVP_VAL_STR)?val.s.len:4, + (flags&AVP_VAL_STR)?val.s.s:"null", + (flags&AVP_VAL_STR)?0:val.n ); + } + continue; + case PW_TYPE_INTEGER: + name.s.len = strlen(vp->name); + name.s.s = vp->name; + val.n = vp->lvalue; + if (add_avp( flags, name, val ) < 0) { + LM_ERR("unable to create a new AVP\n"); + } else { + LM_DBG("AVP '%.*s'/%d='%.*s'/%d has been added\n", + (flags&AVP_NAME_STR)?name.s.len:4, + (flags&AVP_NAME_STR)?name.s.s:"null", + (flags&AVP_NAME_STR)?0:name.n, + (flags&AVP_VAL_STR)?val.s.len:4, + (flags&AVP_VAL_STR)?val.s.s:"null", + (flags&AVP_VAL_STR)?0:val.n ); + } + continue; + default: + LM_ERR("skip attribute type %d (non-string)", vp->type); + continue; + } + return; + } +} + /* Generate AVPs from Radius reply items */ static void generate_avps(struct attr *attrs, VALUE_PAIR* received) @@ -211,7 +265,11 @@ int radius_load_caller_avps(struct sip_msg* _m, char* _caller, char* _s2) if ((res = rc_auth(rh, 0, send, &received, msg)) == OK_RC) { LM_DBG("success\n"); rc_avpair_free(send); - generate_avps(caller_attrs, received); + if (common_response) { + generate_avps_rad(received); + } else { + generate_avps(caller_attrs, received); + } rc_avpair_free(received); return 1; } else { @@ -292,7 +350,11 @@ int radius_load_callee_avps(struct sip_msg* _m, char* _callee, char* _s2) if ((res = rc_auth(rh, 0, send, &received, msg)) == OK_RC) { LM_DBG("success\n"); rc_avpair_free(send); - generate_avps(callee_attrs, received); + if (common_response) { + generate_avps_rad(received); + } else { + generate_avps(callee_attrs, received); + } rc_avpair_free(received); return 1; } else { diff --git a/modules/misc_radius/misc_radius.c b/modules/misc_radius/misc_radius.c index 0330909..15c9caf 100644 --- a/modules/misc_radius/misc_radius.c +++ b/modules/misc_radius/misc_radius.c @@ -57,6 +57,7 @@ static int caller_service_type = -1; static int callee_service_type = -1; static int group_service_type = -1; static int uri_service_type = -1; +int common_response = 0; int use_sip_uri_host = 0; void *rh; @@ -117,7 +118,8 @@ static param_export_t params[] = { {"callee_extra", STR_PARAM, &callee_extra_str }, {"group_extra", STR_PARAM, &group_extra_str }, {"uri_extra", STR_PARAM, &uri_extra_str }, - {"use_sip_uri_host", INT_PARAM, &use_sip_uri_host}, + {"use_sip_uri_host", INT_PARAM, &use_sip_uri_host }, + {"common_response", INT_PARAM, &common_response }, {0, 0, 0} }; @@ -139,19 +141,19 @@ struct module_exports exports = { /* Macro to set static attribute names */ -#define SET_STATIC(_attrs) \ - do { \ +#define SET_STATIC(_attrs) \ + do { \ memset((_attrs), 0, sizeof((_attrs))); \ - (_attrs)[SA_SERVICE_TYPE].n = "Service-Type"; \ + (_attrs)[SA_SERVICE_TYPE].n = "Service-Type"; \ (_attrs)[SA_USER_NAME].n = "User-Name"; \ - (_attrs)[SA_SIP_AVP].n = "SIP-AVP"; \ + (_attrs)[SA_SIP_AVP].n = "SIP-AVP"; \ (_attrs)[SA_SIP_GROUP].n = "SIP-Group"; \ - if (use_sip_uri_host) { \ - (_attrs)[SA_SIP_URI_HOST].n = "SIP-URI-Host"; \ - } else { \ - (_attrs)[SA_SIP_URI_HOST].n = "User-Name"; \ - } \ - n = SA_STATIC_MAX; \ + if (use_sip_uri_host) { \ + (_attrs)[SA_SIP_URI_HOST].n = "SIP-URI-Host"; \ + } else { \ + (_attrs)[SA_SIP_URI_HOST].n = "User-Name"; \ + } \ + n = SA_STATIC_MAX; \ }while(0) diff --git a/modules/misc_radius/misc_radius.h b/modules/misc_radius/misc_radius.h index 02af2d0..0717cfd 100644 --- a/modules/misc_radius/misc_radius.h +++ b/modules/misc_radius/misc_radius.h @@ -35,6 +35,7 @@ enum {GV_GROUP_CHECK = 0, GV_STATIC_MAX}; enum {UV_CALL_CHECK = 0, UV_STATIC_MAX}; extern int use_sip_uri_host; +extern int common_response; extern void *rh;
_______________________________________________ SIP Express Router (SER) and Kamailio (OpenSER) - sr-users mailing list sr-users@lists.sip-router.org http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users