diff --git a/src/modules/rtpproxy/rtpproxy.c b/src/modules/rtpproxy/rtpproxy.c index 2e381a537e3..8c2b174448b 100644 --- a/src/modules/rtpproxy/rtpproxy.c +++ b/src/modules/rtpproxy/rtpproxy.c @@ -25,7 +25,7 @@ #include #include #ifndef __USE_BSD -#define __USE_BSD +#define __USE_BSD #endif #include #ifndef __FAVOR_BSD @@ -82,43 +82,44 @@ MODULE_VERSION #if !defined(AF_LOCAL) -#define AF_LOCAL AF_UNIX +#define AF_LOCAL AF_UNIX #endif #if !defined(PF_LOCAL) -#define PF_LOCAL PF_UNIX +#define PF_LOCAL PF_UNIX #endif /* NAT UAC test constants */ -#define NAT_UAC_TEST_C_1918 0x01 -#define NAT_UAC_TEST_RCVD 0x02 -#define NAT_UAC_TEST_V_1918 0x04 -#define NAT_UAC_TEST_S_1918 0x08 -#define NAT_UAC_TEST_RPORT 0x10 +#define NAT_UAC_TEST_C_1918 0x01 +#define NAT_UAC_TEST_RCVD 0x02 +#define NAT_UAC_TEST_V_1918 0x04 +#define NAT_UAC_TEST_S_1918 0x08 +#define NAT_UAC_TEST_RPORT 0x10 -#define DEFAULT_RTPP_SET_ID 0 +#define DEFAULT_RTPP_SET_ID 0 static str DEFAULT_RTPP_SET_ID_STR = str_init("0"); -#define RPC_DEFAULT_NATPING_STATE 1 +#define RPC_DEFAULT_NATPING_STATE 1 -#define RPC_MIN_RECHECK_TICKS 0 -#define RPC_MAX_RECHECK_TICKS (unsigned int)-1 +#define RPC_MIN_RECHECK_TICKS 0 +#define RPC_MAX_RECHECK_TICKS (unsigned int)-1 /* Supported version of the RTP proxy command protocol */ -#define SUP_CPROTOVER 20040107 +#define SUP_CPROTOVER 20040107 /* Required additional version of the RTP proxy command protocol */ -#define REQ_CPROTOVER "20050322" +#define REQ_CPROTOVER "20050322" /* Additional version necessary for re-packetization support */ -#define REP_CPROTOVER "20071116" -#define PTL_CPROTOVER "20081102" +#define REP_CPROTOVER "20071116" +#define PTL_CPROTOVER "20081102" -#define CPORT "22222" +#define CPORT "22222" static int alter_mediaip(struct sip_msg *, str *, str *, int, str *, int, int); static int alter_mediaport(struct sip_msg *, str *, str *, str *, int); -static int alter_rtcp(struct sip_msg *msg, str *body, str *oldport, str *newport); +static int alter_rtcp( + struct sip_msg *msg, str *body, str *oldport, str *newport); static char *gencookie(); -static int rtpp_test(struct rtpp_node*, int, int); +static int rtpp_test(struct rtpp_node *, int, int); static int unforce_rtp_proxy1_f(struct sip_msg *, char *, char *); static int unforce_rtp_proxy(struct sip_msg *, char *); static int force_rtp_proxy(struct sip_msg *, char *, char *, int, int); @@ -131,13 +132,13 @@ static int rtpproxy_manage0(struct sip_msg *msg, char *flags, char *ip); static int rtpproxy_manage1(struct sip_msg *msg, char *flags, char *ip); static int rtpproxy_manage2(struct sip_msg *msg, char *flags, char *ip); -static int add_rtpproxy_socks(struct rtpp_set * rtpp_list, char * rtpproxy); -static int fixup_set_id(void ** param, int param_no); -static int set_rtp_proxy_set_f(struct sip_msg * msg, char * str1, char * str2); -static struct rtpp_set * select_rtpp_set(int id_set); +static int add_rtpproxy_socks(struct rtpp_set *rtpp_list, char *rtpproxy); +static int fixup_set_id(void **param, int param_no); +static int set_rtp_proxy_set_f(struct sip_msg *msg, char *str1, char *str2); +static struct rtpp_set *select_rtpp_set(int id_set); -static int rtpproxy_set_store(modparam_t type, void * val); -static int rtpproxy_add_rtpproxy_set( char * rtp_proxies); +static int rtpproxy_set_store(modparam_t type, void *val); +static int rtpproxy_add_rtpproxy_set(char *rtp_proxies); static int mod_init(void); static int child_init(int); @@ -154,14 +155,14 @@ static unsigned int myseqn = 0; static str nortpproxy_str = str_init("a=nortpproxy:yes"); static str extra_id_pv_param = {NULL, 0}; -static char ** rtpp_strings=0; -static int rtpp_sets=0; /*used in rtpproxy_set_store()*/ +static char **rtpp_strings = 0; +static int rtpp_sets = 0; /*used in rtpproxy_set_store()*/ static int rtpp_set_count = 0; static unsigned int current_msg_id = (unsigned int)-1; /* RTP proxy balancing list */ -struct rtpp_set_head * rtpp_set_list =0; -struct rtpp_set * selected_rtpp_set =0; -struct rtpp_set * default_rtpp_set=0; +struct rtpp_set_head *rtpp_set_list = 0; +struct rtpp_set *selected_rtpp_set = 0; +struct rtpp_set *default_rtpp_set = 0; static char *ice_candidate_priority_avp_param = NULL; static int ice_candidate_priority_avp_type; static int_str ice_candidate_priority_avp; @@ -173,7 +174,8 @@ static unsigned int rtpp_no = 0; static int *rtpp_socks = 0; -typedef struct rtpp_set_link { +typedef struct rtpp_set_link +{ struct rtpp_set *rset; pv_spec_t *rpv; } rtpp_set_link_t; @@ -182,132 +184,108 @@ typedef struct rtpp_set_link { static struct tm_binds tmb; /*0-> disabled, 1 ->enabled*/ -unsigned int *natping_state=0; +unsigned int *natping_state = 0; static str timeout_socket_str = {0, 0}; static pv_elem_t *extra_id_pv = NULL; static cmd_export_t cmds[] = { - {"set_rtp_proxy_set", (cmd_function)set_rtp_proxy_set_f, 1, - fixup_set_id, 0, - ANY_ROUTE}, - {"unforce_rtp_proxy", (cmd_function)unforce_rtp_proxy1_f, 0, - 0, 0, - ANY_ROUTE}, - {"rtpproxy_destroy", (cmd_function)unforce_rtp_proxy1_f, 0, - 0, 0, - ANY_ROUTE}, - {"unforce_rtp_proxy", (cmd_function)unforce_rtp_proxy1_f, 1, - fixup_spve_null, 0, - ANY_ROUTE}, - {"rtpproxy_destroy", (cmd_function)unforce_rtp_proxy1_f, 1, - fixup_spve_null, 0, - ANY_ROUTE}, - {"start_recording", (cmd_function)start_recording_f, 0, - 0, 0, - ANY_ROUTE }, - {"rtpproxy_offer", (cmd_function)rtpproxy_offer1_f, 0, - 0, 0, - ANY_ROUTE}, - {"rtpproxy_offer", (cmd_function)rtpproxy_offer1_f, 1, - fixup_spve_null, 0, - ANY_ROUTE}, - {"rtpproxy_offer", (cmd_function)rtpproxy_offer2_f, 2, - fixup_spve_spve, 0, - ANY_ROUTE}, - {"rtpproxy_answer", (cmd_function)rtpproxy_answer1_f, 0, - 0, 0, - ANY_ROUTE}, - {"rtpproxy_answer", (cmd_function)rtpproxy_answer1_f, 1, - fixup_spve_null, 0, - ANY_ROUTE}, - {"rtpproxy_answer", (cmd_function)rtpproxy_answer2_f, 2, - fixup_spve_spve, 0, - ANY_ROUTE}, - {"rtpproxy_stream2uac",(cmd_function)rtpproxy_stream2uac2_f, 2, - fixup_var_str_int, 0, - ANY_ROUTE }, - {"rtpproxy_stream2uas",(cmd_function)rtpproxy_stream2uas2_f, 2, - fixup_var_str_int, 0, - ANY_ROUTE }, - {"rtpproxy_stop_stream2uac",(cmd_function)rtpproxy_stop_stream2uac2_f,0, - NULL, 0, - ANY_ROUTE }, - {"rtpproxy_stop_stream2uas",(cmd_function)rtpproxy_stop_stream2uas2_f,0, - NULL, 0, - ANY_ROUTE }, - {"rtpproxy_manage", (cmd_function)rtpproxy_manage0, 0, - 0, 0, - ANY_ROUTE}, - {"rtpproxy_manage", (cmd_function)rtpproxy_manage1, 1, - fixup_spve_null, fixup_free_spve_null, - ANY_ROUTE}, - {"rtpproxy_manage", (cmd_function)rtpproxy_manage2, 2, - fixup_spve_spve, fixup_free_spve_spve, - ANY_ROUTE}, - {0, 0, 0, 0, 0, 0} -}; + {"set_rtp_proxy_set", (cmd_function)set_rtp_proxy_set_f, 1, + fixup_set_id, 0, ANY_ROUTE}, + {"unforce_rtp_proxy", (cmd_function)unforce_rtp_proxy1_f, 0, 0, 0, + ANY_ROUTE}, + {"rtpproxy_destroy", (cmd_function)unforce_rtp_proxy1_f, 0, 0, 0, + ANY_ROUTE}, + {"unforce_rtp_proxy", (cmd_function)unforce_rtp_proxy1_f, 1, + fixup_spve_null, 0, ANY_ROUTE}, + {"rtpproxy_destroy", (cmd_function)unforce_rtp_proxy1_f, 1, + fixup_spve_null, 0, ANY_ROUTE}, + {"start_recording", (cmd_function)start_recording_f, 0, 0, 0, + ANY_ROUTE}, + {"rtpproxy_offer", (cmd_function)rtpproxy_offer1_f, 0, 0, 0, ANY_ROUTE}, + {"rtpproxy_offer", (cmd_function)rtpproxy_offer1_f, 1, fixup_spve_null, + 0, ANY_ROUTE}, + {"rtpproxy_offer", (cmd_function)rtpproxy_offer2_f, 2, fixup_spve_spve, + 0, ANY_ROUTE}, + {"rtpproxy_answer", (cmd_function)rtpproxy_answer1_f, 0, 0, 0, + ANY_ROUTE}, + {"rtpproxy_answer", (cmd_function)rtpproxy_answer1_f, 1, + fixup_spve_null, 0, ANY_ROUTE}, + {"rtpproxy_answer", (cmd_function)rtpproxy_answer2_f, 2, + fixup_spve_spve, 0, ANY_ROUTE}, + {"rtpproxy_stream2uac", (cmd_function)rtpproxy_stream2uac2_f, 2, + fixup_var_str_int, 0, ANY_ROUTE}, + {"rtpproxy_stream2uas", (cmd_function)rtpproxy_stream2uas2_f, 2, + fixup_var_str_int, 0, ANY_ROUTE}, + {"rtpproxy_stop_stream2uac", (cmd_function)rtpproxy_stop_stream2uac2_f, + 0, NULL, 0, ANY_ROUTE}, + {"rtpproxy_stop_stream2uas", (cmd_function)rtpproxy_stop_stream2uas2_f, + 0, NULL, 0, ANY_ROUTE}, + {"rtpproxy_manage", (cmd_function)rtpproxy_manage0, 0, 0, 0, ANY_ROUTE}, + {"rtpproxy_manage", (cmd_function)rtpproxy_manage1, 1, fixup_spve_null, + fixup_free_spve_null, ANY_ROUTE}, + {"rtpproxy_manage", (cmd_function)rtpproxy_manage2, 2, fixup_spve_spve, + fixup_free_spve_spve, ANY_ROUTE}, + {0, 0, 0, 0, 0, 0}}; static pv_export_t mod_pvs[] = { - {{"rtpstat", (sizeof("rtpstat")-1)}, /* RTP-Statistics */ - PVT_OTHER, pv_get_rtppstat_f, 0, 0, 0, 0, 0}, - {{"rtppstat", (sizeof("rtppstat")-1)}, /* RTP-Statistics */ - PVT_OTHER, pv_get_rtppstat_f, 0, 0, 0, 0, 0}, - {{0, 0}, 0, 0, 0, 0, 0, 0, 0} -}; + {{"rtpstat", (sizeof("rtpstat") - 1)}, /* RTP-Statistics */ + PVT_OTHER, pv_get_rtppstat_f, 0, 0, 0, 0, 0}, + {{"rtppstat", (sizeof("rtppstat") - 1)}, /* RTP-Statistics */ + PVT_OTHER, pv_get_rtppstat_f, 0, 0, 0, 0, 0}, + {{0, 0}, 0, 0, 0, 0, 0, 0, 0}}; static param_export_t params[] = { - {"nortpproxy_str", PARAM_STR, &nortpproxy_str }, - {"rtpproxy_sock", PARAM_STRING|USE_FUNC_PARAM, - (void*)rtpproxy_set_store }, - {"rtpproxy_disable_tout", INT_PARAM, &rtpproxy_disable_tout }, - {"rtpproxy_retr", INT_PARAM, &rtpproxy_retr }, - {"rtpproxy_tout", INT_PARAM, &rtpproxy_tout }, - {"timeout_socket", PARAM_STR, &timeout_socket_str }, - {"ice_candidate_priority_avp", PARAM_STRING, - &ice_candidate_priority_avp_param}, - {"extra_id_pv", PARAM_STR, &extra_id_pv_param }, - {"db_url", PARAM_STR, &rtpp_db_url }, - {"table_name", PARAM_STR, &rtpp_table_name }, - {"rtp_inst_pvar", PARAM_STR, &rtp_inst_pv_param }, - {0, 0, 0} -}; + {"nortpproxy_str", PARAM_STR, &nortpproxy_str}, + {"rtpproxy_sock", PARAM_STRING | USE_FUNC_PARAM, + (void *)rtpproxy_set_store}, + {"rtpproxy_disable_tout", INT_PARAM, &rtpproxy_disable_tout}, + {"rtpproxy_retr", INT_PARAM, &rtpproxy_retr}, + {"rtpproxy_tout", INT_PARAM, &rtpproxy_tout}, + {"timeout_socket", PARAM_STR, &timeout_socket_str}, + {"ice_candidate_priority_avp", PARAM_STRING, + &ice_candidate_priority_avp_param}, + {"extra_id_pv", PARAM_STR, &extra_id_pv_param}, + {"db_url", PARAM_STR, &rtpp_db_url}, + {"table_name", PARAM_STR, &rtpp_table_name}, + {"rtp_inst_pvar", PARAM_STR, &rtp_inst_pv_param}, {0, 0, 0}}; struct module_exports exports = { - "rtpproxy", /* module name */ - DEFAULT_DLFLAGS, /* dlopen flags */ - cmds, /* cmd exports */ - params, /* param exports */ - 0, /* RPC method exports */ - mod_pvs, /* exported pseudo-variables */ - 0, /* reply processing */ - mod_init, /* module init function */ - child_init, /* per-child init function */ - mod_destroy, /* destroy function */ + "rtpproxy", /* module name */ + DEFAULT_DLFLAGS, /* dlopen flags */ + cmds, /* cmd exports */ + params, /* param exports */ + 0, /* RPC method exports */ + mod_pvs, /* exported pseudo-variables */ + 0, /* reply processing */ + mod_init, /* module init function */ + child_init, /* per-child init function */ + mod_destroy, /* destroy function */ }; -static int rtpproxy_set_store(modparam_t type, void * val){ +static int rtpproxy_set_store(modparam_t type, void *val) +{ - char * p; + char *p; int len; - p = (char* )val; + p = (char *)val; - if(p==0 || *p=='\0'){ + if(p == 0 || *p == '\0') { return 0; } - if(rtpp_sets==0){ - rtpp_strings = (char**)pkg_malloc(sizeof(char*)); - if(!rtpp_strings){ + if(rtpp_sets == 0) { + rtpp_strings = (char **)pkg_malloc(sizeof(char *)); + if(!rtpp_strings) { LM_ERR("no pkg memory left\n"); return -1; } - } else {/*realloc to make room for the current set*/ - rtpp_strings = (char**)pkg_reallocxf(rtpp_strings, - (rtpp_sets+1)* sizeof(char*)); - if(!rtpp_strings){ + } else { /*realloc to make room for the current set*/ + rtpp_strings = (char **)pkg_reallocxf( + rtpp_strings, (rtpp_sets + 1) * sizeof(char *)); + if(!rtpp_strings) { LM_ERR("no pkg memory left\n"); return -1; } @@ -315,9 +293,9 @@ static int rtpproxy_set_store(modparam_t type, void * val){ /*allocate for the current set of urls*/ len = strlen(p); - rtpp_strings[rtpp_sets] = (char*)pkg_malloc((len+1)*sizeof(char)); + rtpp_strings[rtpp_sets] = (char *)pkg_malloc((len + 1) * sizeof(char)); - if(!rtpp_strings[rtpp_sets]){ + if(!rtpp_strings[rtpp_sets]) { LM_ERR("no pkg memory left\n"); return -1; } @@ -333,35 +311,32 @@ struct rtpp_set *get_rtpp_set(str *const set_name) { unsigned int this_set_id; struct rtpp_set *rtpp_list; - if (rtpp_set_list == NULL) - { + if(rtpp_set_list == NULL) { LM_ERR("rtpp set list not configured\n"); return NULL; } /* Only integer set_names are valid at the moment */ - if ((set_name->s == NULL) || (set_name->len == 0)) - { + if((set_name->s == NULL) || (set_name->len == 0)) { LM_ERR("Invalid set name '%.*s'\n", set_name->len, set_name->s); return NULL; } - if (str2int(set_name, &this_set_id) < 0) - { - LM_ERR("Invalid set name '%.*s' - must be integer\n", set_name->len, set_name->s); + if(str2int(set_name, &this_set_id) < 0) { + LM_ERR("Invalid set name '%.*s' - must be integer\n", set_name->len, + set_name->s); return NULL; } rtpp_list = select_rtpp_set(this_set_id); - if(rtpp_list==NULL){ /*if a new id_set : add a new set of rtpp*/ + if(rtpp_list == NULL) { /*if a new id_set : add a new set of rtpp*/ rtpp_list = shm_malloc(sizeof(struct rtpp_set)); - if(!rtpp_list){ + if(!rtpp_list) { LM_ERR("no shm memory left\n"); return NULL; } memset(rtpp_list, 0, sizeof(struct rtpp_set)); rtpp_list->id_set = this_set_id; - if (rtpp_set_list->rset_first == NULL) - { + if(rtpp_set_list->rset_first == NULL) { rtpp_set_list->rset_first = rtpp_list; } else { rtpp_set_list->rset_last->rset_next = rtpp_list; @@ -369,20 +344,19 @@ struct rtpp_set *get_rtpp_set(str *const set_name) rtpp_set_list->rset_last = rtpp_list; rtpp_set_count++; - if (this_set_id == DEFAULT_RTPP_SET_ID) - { + if(this_set_id == DEFAULT_RTPP_SET_ID) { default_rtpp_set = rtpp_list; } } return rtpp_list; } -int insert_rtpp_node(struct rtpp_set *const rtpp_list, const str *const url, const int weight, const int disabled) +int insert_rtpp_node(struct rtpp_set *const rtpp_list, const str *const url, + const int weight, const int disabled) { struct rtpp_node *pnode; - if ((pnode = shm_malloc(sizeof(struct rtpp_node) + url->len + 1)) == NULL) - { + if((pnode = shm_malloc(sizeof(struct rtpp_node) + url->len + 1)) == NULL) { LM_ERR("out of shm memory\n"); return -1; } @@ -393,7 +367,7 @@ int insert_rtpp_node(struct rtpp_set *const rtpp_list, const str *const url, con pnode->rn_disabled = disabled; /* Permanently disable if marked as disabled */ pnode->rn_recheck_ticks = disabled ? RPC_MAX_RECHECK_TICKS : 0; - pnode->rn_url.s = (char*)(pnode + 1); + pnode->rn_url.s = (char *)(pnode + 1); memcpy(pnode->rn_url.s, url->s, url->len); pnode->rn_url.len = url->len; @@ -401,19 +375,18 @@ int insert_rtpp_node(struct rtpp_set *const rtpp_list, const str *const url, con /* Find protocol and store address */ pnode->rn_address = pnode->rn_url.s; - if (strncasecmp(pnode->rn_address, "udp:", 4) == 0) { + if(strncasecmp(pnode->rn_address, "udp:", 4) == 0) { pnode->rn_umode = 1; pnode->rn_address += 4; - } else if (strncasecmp(pnode->rn_address, "udp6:", 5) == 0) { + } else if(strncasecmp(pnode->rn_address, "udp6:", 5) == 0) { pnode->rn_umode = 6; pnode->rn_address += 5; - } else if (strncasecmp(pnode->rn_address, "unix:", 5) == 0) { + } else if(strncasecmp(pnode->rn_address, "unix:", 5) == 0) { pnode->rn_umode = 0; pnode->rn_address += 5; } - if (rtpp_list->rn_first == NULL) - { + if(rtpp_list->rn_first == NULL) { rtpp_list->rn_first = pnode; } else { rtpp_list->rn_last->rn_next = pnode; @@ -424,8 +397,8 @@ int insert_rtpp_node(struct rtpp_set *const rtpp_list, const str *const url, con return 0; } -static int add_rtpproxy_socks(struct rtpp_set * rtpp_list, - char * rtpproxy){ +static int add_rtpproxy_socks(struct rtpp_set *rtpp_list, char *rtpproxy) +{ /* Make rtp proxies list. */ char *p, *p1, *p2, *plim; int weight; @@ -436,25 +409,25 @@ static int add_rtpproxy_socks(struct rtpp_set * rtpp_list, for(;;) { weight = 1; - while (*p && isspace((int)*p)) + while(*p && isspace((int)*p)) ++p; - if (p >= plim) + if(p >= plim) break; p1 = p; - while (*p && !isspace((int)*p)) + while(*p && !isspace((int)*p)) ++p; - if (p <= p1) + if(p <= p1) break; /* may happen??? */ /* Have weight specified? If yes, scan it */ p2 = memchr(p1, '=', p - p1); - if (p2 != NULL) { + if(p2 != NULL) { weight = strtoul(p2 + 1, NULL, 10); } else { p2 = p; } url.s = p1; - url.len = (p2-p1); + url.len = (p2 - p1); insert_rtpp_node(rtpp_list, &url, weight, 0); } return 0; @@ -464,61 +437,66 @@ static int add_rtpproxy_socks(struct rtpp_set * rtpp_list, /* 0-succes * -1 - erorr * */ -static int rtpproxy_add_rtpproxy_set( char * rtp_proxies) +static int rtpproxy_add_rtpproxy_set(char *rtp_proxies) { - char *p,*p2; - struct rtpp_set * rtpp_list; + char *p, *p2; + struct rtpp_set *rtpp_list; str id_set; /* empty definition? */ - p= rtp_proxies; - if(!p || *p=='\0'){ + p = rtp_proxies; + if(!p || *p == '\0') { return 0; } - for(;*p && isspace(*p);p++); - if(*p=='\0'){ + for(; *p && isspace(*p); p++) + ; + if(*p == '\0') { return 0; } rtp_proxies = strstr(p, "=="); - if(rtp_proxies){ - if(*(rtp_proxies +2)=='\0'){ + if(rtp_proxies) { + if(*(rtp_proxies + 2) == '\0') { LM_ERR("script error -invalid rtp proxy list!\n"); return -1; } *rtp_proxies = '\0'; - p2 = rtp_proxies-1; - for(;isspace(*p2); *p2 = '\0',p2--); - id_set.s = p; id_set.len = p2 - p+1; + p2 = rtp_proxies - 1; + for(; isspace(*p2); *p2 = '\0', p2--) + ; + id_set.s = p; + id_set.len = p2 - p + 1; - if(id_set.len <= 0){ + if(id_set.len <= 0) { LM_ERR("script error -invalid set_id value!\n"); return -1; } - rtp_proxies+=2; - }else{ + rtp_proxies += 2; + } else { rtp_proxies = p; id_set = DEFAULT_RTPP_SET_ID_STR; } - for(;*rtp_proxies && isspace(*rtp_proxies);rtp_proxies++); + for(; *rtp_proxies && isspace(*rtp_proxies); rtp_proxies++) + ; - if(!(*rtp_proxies)){ + if(!(*rtp_proxies)) { LM_ERR("script error -empty rtp_proxy list\n"); - return -1;; + return -1; + ; } rtpp_list = get_rtpp_set(&id_set); - if (rtpp_list == NULL) - { - LM_ERR("Failed to get or create rtpp_list for '%.*s'\n", id_set.len, id_set.s); + if(rtpp_list == NULL) { + LM_ERR("Failed to get or create rtpp_list for '%.*s'\n", id_set.len, + id_set.s); return -1; } - if(add_rtpproxy_socks(rtpp_list, rtp_proxies)!= 0){ + if(add_rtpproxy_socks(rtpp_list, rtp_proxies) != 0) { return -1; } @@ -526,25 +504,25 @@ static int rtpproxy_add_rtpproxy_set( char * rtp_proxies) } -static int fixup_set_id(void ** param, int param_no) +static int fixup_set_id(void **param, int param_no) { int int_val, err; - struct rtpp_set* rtpp_list; + struct rtpp_set *rtpp_list; rtpp_set_link_t *rtpl = NULL; str s; - rtpl = (rtpp_set_link_t*)pkg_malloc(sizeof(rtpp_set_link_t)); - if(rtpl==NULL) { + rtpl = (rtpp_set_link_t *)pkg_malloc(sizeof(rtpp_set_link_t)); + if(rtpl == NULL) { LM_ERR("no more pkg memory\n"); return -1; } memset(rtpl, 0, sizeof(rtpp_set_link_t)); - s.s = (char*)*param; + s.s = (char *)*param; s.len = strlen(s.s); if(s.s[0] == PV_MARKER) { int_val = pv_locate_name(&s); - if(int_val<0 || int_val!=s.len) { + if(int_val < 0 || int_val != s.len) { LM_ERR("invalid parameter %s\n", s.s); pkg_free(rtpl); return -1; @@ -557,25 +535,25 @@ static int fixup_set_id(void ** param, int param_no) } } else { int_val = str2s(*param, strlen(*param), &err); - if (err == 0) { + if(err == 0) { pkg_free(*param); - if((rtpp_list = select_rtpp_set(int_val)) ==0){ + if((rtpp_list = select_rtpp_set(int_val)) == 0) { LM_ERR("rtpp_proxy set %i not configured\n", int_val); pkg_free(rtpl); return E_CFG; } rtpl->rset = rtpp_list; } else { - LM_ERR("bad number <%s>\n", (char *)(*param)); + LM_ERR("bad number <%s>\n", (char *)(*param)); pkg_free(rtpl); return E_CFG; } } - *param = (void*)rtpl; + *param = (void *)rtpl; return 0; } -static void rtpproxy_rpc_enable(rpc_t* rpc, void* ctx) +static void rtpproxy_rpc_enable(rpc_t *rpc, void *ctx) { str rtpp_url; int enable; @@ -586,10 +564,10 @@ static void rtpproxy_rpc_enable(rpc_t* rpc, void* ctx) found = 0; enable = 0; - if(rtpp_set_list ==NULL) + if(rtpp_set_list == NULL) goto end; - if (rpc->scan(ctx, "Sd", &rtpp_url, &enable) < 2) { + if(rpc->scan(ctx, "Sd", &rtpp_url, &enable) < 2) { rpc->fault(ctx, 500, "Not enough parameters"); return; } @@ -605,9 +583,9 @@ static void rtpproxy_rpc_enable(rpc_t* rpc, void* ctx) if(strncmp(crt_rtpp->rn_url.s, rtpp_url.s, rtpp_url.len) == 0) { /*set the enabled/disabled status*/ found = 1; - crt_rtpp->rn_recheck_ticks = - enable? RPC_MIN_RECHECK_TICKS : RPC_MAX_RECHECK_TICKS; - crt_rtpp->rn_disabled = enable?0:1; + crt_rtpp->rn_recheck_ticks = enable ? RPC_MIN_RECHECK_TICKS + : RPC_MAX_RECHECK_TICKS; + crt_rtpp->rn_disabled = enable ? 0 : 1; } } } @@ -621,13 +599,13 @@ static void rtpproxy_rpc_enable(rpc_t* rpc, void* ctx) } -static void rtpproxy_rpc_list(rpc_t* rpc, void* ctx) +static void rtpproxy_rpc_list(rpc_t *rpc, void *ctx) { struct rtpp_set *rtpp_list; struct rtpp_node *crt_rtpp; void *vh; - if(rtpp_set_list ==NULL) + if(rtpp_set_list == NULL) return; for(rtpp_list = rtpp_set_list->rset_first; rtpp_list != NULL; @@ -636,93 +614,79 @@ static void rtpproxy_rpc_list(rpc_t* rpc, void* ctx) for(crt_rtpp = rtpp_list->rn_first; crt_rtpp != NULL; crt_rtpp = crt_rtpp->rn_next) { - if (rpc->add(ctx, "{", &vh) < 0) { + if(rpc->add(ctx, "{", &vh) < 0) { rpc->fault(ctx, 500, "Server error"); return; } - rpc->struct_add(vh, "dSdddd", - "setid", rtpp_list->id_set, - "url", &crt_rtpp->rn_url, - "index", crt_rtpp->idx, - "disabled", crt_rtpp->rn_disabled, - "weight", crt_rtpp->rn_weight, - "recheck", crt_rtpp->rn_recheck_ticks); + rpc->struct_add(vh, "dSdddd", "setid", rtpp_list->id_set, "url", + &crt_rtpp->rn_url, "index", crt_rtpp->idx, "disabled", + crt_rtpp->rn_disabled, "weight", crt_rtpp->rn_weight, + "recheck", crt_rtpp->rn_recheck_ticks); } } } -static const char* rtpproxy_rpc_enable_doc[2] = { - "Set state (enable/disable) for a rtp proxy.", - 0 -}; +static const char *rtpproxy_rpc_enable_doc[2] = { + "Set state (enable/disable) for a rtp proxy.", 0}; -static const char* rtpproxy_rpc_list_doc[2] = { - "List rtp proxies.", - 0 -}; +static const char *rtpproxy_rpc_list_doc[2] = {"List rtp proxies.", 0}; rpc_export_t rtpproxy_rpc[] = { - {"rtpproxy.list", rtpproxy_rpc_list, rtpproxy_rpc_list_doc, RET_ARRAY}, - {"rtpproxy.enable", rtpproxy_rpc_enable, rtpproxy_rpc_enable_doc, 0}, - {0, 0, 0, 0} -}; + {"rtpproxy.list", rtpproxy_rpc_list, rtpproxy_rpc_list_doc, RET_ARRAY}, + {"rtpproxy.enable", rtpproxy_rpc_enable, rtpproxy_rpc_enable_doc, 0}, + {0, 0, 0, 0}}; static int rtpproxy_rpc_init(void) { - if (rpc_register_array(rtpproxy_rpc)!=0) - { + if(rpc_register_array(rtpproxy_rpc) != 0) { LM_ERR("failed to register RPC commands\n"); return -1; } return 0; } - static int -mod_init(void) +static int mod_init(void) { int i; pv_spec_t avp_spec; str s; unsigned short avp_flags; - if(rtpproxy_rpc_init()<0) - { + if(rtpproxy_rpc_init() < 0) { LM_ERR("failed to register RPC commands\n"); return -1; } /* Configure the head of the rtpp_set_list */ rtpp_set_list = shm_malloc(sizeof(struct rtpp_set_head)); - if (rtpp_set_list == NULL) - { + if(rtpp_set_list == NULL) { LM_ERR("no shm memory for rtpp_set_list\n"); return -1; } memset(rtpp_set_list, 0, sizeof(struct rtpp_set_head)); - if (nortpproxy_str.s==NULL || nortpproxy_str.len<=0) { + if(nortpproxy_str.s == NULL || nortpproxy_str.len <= 0) { nortpproxy_str.len = 0; } else { - while (nortpproxy_str.len > 0 - && (nortpproxy_str.s[nortpproxy_str.len - 1] == '\r' || - nortpproxy_str.s[nortpproxy_str.len - 1] == '\n')) + while(nortpproxy_str.len > 0 + && (nortpproxy_str.s[nortpproxy_str.len - 1] == '\r' + || nortpproxy_str.s[nortpproxy_str.len - 1] == '\n')) nortpproxy_str.len--; } - if (rtpp_db_url.s != NULL) - { + if(rtpp_db_url.s != NULL) { init_rtpproxy_db(); - if (rtpp_sets > 0) - { + if(rtpp_sets > 0) { LM_WARN("rtpproxy db url configured - ignoring modparam sets\n"); } } /* storing the list of rtp proxy sets in shared memory*/ - for(i=0;i\n", ice_candidate_priority_avp_param); return -1; } - if (pv_get_avp_name(0, &(avp_spec.pvp), &ice_candidate_priority_avp, - &avp_flags) != 0) { + if(pv_get_avp_name( + 0, &(avp_spec.pvp), &ice_candidate_priority_avp, &avp_flags) + != 0) { LM_ERR("invalid AVP definition <%s>\n", ice_candidate_priority_avp_param); return -1; @@ -749,19 +715,19 @@ mod_init(void) ice_candidate_priority_avp_type = avp_flags; } - if (rtp_inst_pv_param.s) { + if(rtp_inst_pv_param.s) { rtp_inst_pvar = pv_cache_get(&rtp_inst_pv_param); - if ((rtp_inst_pvar == NULL) || - ((rtp_inst_pvar->type != PVT_AVP) && - (rtp_inst_pvar->type != PVT_XAVP) && - (rtp_inst_pvar->type != PVT_SCRIPTVAR))) { + if((rtp_inst_pvar == NULL) + || ((rtp_inst_pvar->type != PVT_AVP) + && (rtp_inst_pvar->type != PVT_XAVP) + && (rtp_inst_pvar->type != PVT_SCRIPTVAR))) { LM_ERR("Invalid pvar name <%.*s>\n", rtp_inst_pv_param.len, rtp_inst_pv_param.s); return -1; } } - if (extra_id_pv_param.s && *extra_id_pv_param.s) { + if(extra_id_pv_param.s && *extra_id_pv_param.s) { if(pv_parse_format(&extra_id_pv_param, &extra_id_pv) < 0) { LM_ERR("malformed PV string: %s\n", extra_id_pv_param.s); return -1; @@ -770,13 +736,12 @@ mod_init(void) extra_id_pv = NULL; } - if (rtpp_strings) + if(rtpp_strings) pkg_free(rtpp_strings); - if (load_tm_api( &tmb ) < 0) - { + if(load_tm_api(&tmb) < 0) { LM_DBG("could not load the TM-functions - answer-offer model" - " auto-detection is disabled\n"); + " auto-detection is disabled\n"); memset(&tmb, 0, sizeof(struct tm_binds)); } @@ -784,40 +749,39 @@ mod_init(void) } - static int -child_init(int rank) +static int child_init(int rank) { int n; char *cp; struct addrinfo hints, *res; - struct rtpp_set *rtpp_list; + struct rtpp_set *rtpp_list; struct rtpp_node *pnode; - if(rtpp_set_list==NULL ) + if(rtpp_set_list == NULL) return 0; /* do not init sockets for PROC_INIT and main process when fork=yes */ - if(rank==PROC_INIT || (rank==PROC_MAIN && dont_fork==0)) { + if(rank == PROC_INIT || (rank == PROC_MAIN && dont_fork == 0)) { return 0; } /* Iterate known RTP proxies - create sockets */ mypid = getpid(); - rtpp_socks = (int*)pkg_malloc( sizeof(int)*rtpp_no ); - if (rtpp_socks==NULL) { + rtpp_socks = (int *)pkg_malloc(sizeof(int) * rtpp_no); + if(rtpp_socks == NULL) { LM_ERR("no more pkg memory\n"); return -1; } - memset(rtpp_socks, -1, sizeof(int)*rtpp_no); + memset(rtpp_socks, -1, sizeof(int) * rtpp_no); for(rtpp_list = rtpp_set_list->rset_first; rtpp_list != 0; - rtpp_list = rtpp_list->rset_next){ + rtpp_list = rtpp_list->rset_next) { - for (pnode=rtpp_list->rn_first; pnode!=0; pnode = pnode->rn_next){ + for(pnode = rtpp_list->rn_first; pnode != 0; pnode = pnode->rn_next) { char *hostname; - if (pnode->rn_umode == 0) { + if(pnode->rn_umode == 0) { rtpp_socks[pnode->idx] = -1; goto rptest; } @@ -826,49 +790,51 @@ child_init(int rank) * This is UDP or UDP6. Detect host and port; lookup host; * do connect() in order to specify peer address */ - hostname = (char*)pkg_malloc(sizeof(char) * (strlen(pnode->rn_address) + 1)); - if (hostname==NULL) { + hostname = (char *)pkg_malloc( + sizeof(char) * (strlen(pnode->rn_address) + 1)); + if(hostname == NULL) { LM_ERR("no more pkg memory\n"); return -1; } strcpy(hostname, pnode->rn_address); cp = strrchr(hostname, ':'); - if (cp != NULL) { + if(cp != NULL) { *cp = '\0'; cp++; } - if (cp == NULL || *cp == '\0') + if(cp == NULL || *cp == '\0') cp = CPORT; memset(&hints, 0, sizeof(hints)); hints.ai_flags = 0; hints.ai_family = (pnode->rn_umode == 6) ? AF_INET6 : AF_INET; hints.ai_socktype = SOCK_DGRAM; - if ((n = getaddrinfo(hostname, cp, &hints, &res)) != 0) { + if((n = getaddrinfo(hostname, cp, &hints, &res)) != 0) { LM_ERR("%s\n", gai_strerror(n)); pkg_free(hostname); return -1; } pkg_free(hostname); - rtpp_socks[pnode->idx] = socket((pnode->rn_umode == 6) - ? AF_INET6 : AF_INET, SOCK_DGRAM, 0); - if ( rtpp_socks[pnode->idx] == -1) { + rtpp_socks[pnode->idx] = socket( + (pnode->rn_umode == 6) ? AF_INET6 : AF_INET, SOCK_DGRAM, 0); + if(rtpp_socks[pnode->idx] == -1) { LM_ERR("can't create socket\n"); freeaddrinfo(res); return -1; } - if (connect( rtpp_socks[pnode->idx], res->ai_addr, res->ai_addrlen) == -1) { + if(connect(rtpp_socks[pnode->idx], res->ai_addr, res->ai_addrlen) + == -1) { LM_ERR("can't connect to a RTP proxy\n"); - close( rtpp_socks[pnode->idx] ); + close(rtpp_socks[pnode->idx]); rtpp_socks[pnode->idx] = -1; freeaddrinfo(res); return -1; } freeaddrinfo(res); -rptest: + rptest: pnode->rn_disabled = rtpp_test(pnode, pnode->rn_disabled, 1); } } @@ -879,19 +845,19 @@ child_init(int rank) static void mod_destroy(void) { - struct rtpp_set * crt_list, * last_list; - struct rtpp_node * crt_rtpp, *last_rtpp; + struct rtpp_set *crt_list, *last_list; + struct rtpp_node *crt_rtpp, *last_rtpp; /*free the shared memory*/ - if (natping_state) + if(natping_state) shm_free(natping_state); if(rtpp_set_list == NULL) return; - for(crt_list = rtpp_set_list->rset_first; crt_list != NULL; ){ + for(crt_list = rtpp_set_list->rset_first; crt_list != NULL;) { - for(crt_rtpp = crt_list->rn_first; crt_rtpp != NULL; ){ + for(crt_rtpp = crt_list->rn_first; crt_rtpp != NULL;) { last_rtpp = crt_rtpp; crt_rtpp = last_rtpp->rn_next; @@ -907,62 +873,58 @@ static void mod_destroy(void) } - - static int -isnulladdr(str *sx, int pf) +static int isnulladdr(str *sx, int pf) { char *cp; - if (pf == AF_INET6) { + if(pf == AF_INET6) { for(cp = sx->s; cp < sx->s + sx->len; cp++) - if (*cp != '0' && *cp != ':') + if(*cp != '0' && *cp != ':') return 0; return 1; } return (sx->len == 7 && memcmp("0.0.0.0", sx->s, 7) == 0); } -#define ADD_ADIRECTION 0x01 -#define FIX_MEDIP 0x02 -#define ADD_ANORTPPROXY 0x04 -#define FIX_ORGIP 0x08 +#define ADD_ADIRECTION 0x01 +#define FIX_MEDIP 0x02 +#define ADD_ANORTPPROXY 0x04 +#define FIX_ORGIP 0x08 -#define ADIRECTION "a=direction:active" -#define ADIRECTION_LEN (sizeof(ADIRECTION) - 1) +#define ADIRECTION "a=direction:active" +#define ADIRECTION_LEN (sizeof(ADIRECTION) - 1) -#define AOLDMEDIP "a=oldmediaip:" -#define AOLDMEDIP_LEN (sizeof(AOLDMEDIP) - 1) +#define AOLDMEDIP "a=oldmediaip:" +#define AOLDMEDIP_LEN (sizeof(AOLDMEDIP) - 1) -#define AOLDMEDIP6 "a=oldmediaip6:" -#define AOLDMEDIP6_LEN (sizeof(AOLDMEDIP6) - 1) +#define AOLDMEDIP6 "a=oldmediaip6:" +#define AOLDMEDIP6_LEN (sizeof(AOLDMEDIP6) - 1) -#define AOLDMEDPRT "a=oldmediaport:" -#define AOLDMEDPRT_LEN (sizeof(AOLDMEDPRT) - 1) +#define AOLDMEDPRT "a=oldmediaport:" +#define AOLDMEDPRT_LEN (sizeof(AOLDMEDPRT) - 1) - static int -alter_mediaip(struct sip_msg *msg, str *body, str *oldip, int oldpf, +static int alter_mediaip(struct sip_msg *msg, str *body, str *oldip, int oldpf, str *newip, int newpf, int preserve) { char *buf; int offset; - struct lump* anchor; + struct lump *anchor; str omip, nip, oip; /* check that updating mediaip is really necessary */ - if (oldpf == newpf && isnulladdr(oldip, oldpf)) + if(oldpf == newpf && isnulladdr(oldip, oldpf)) return 0; - if (newip->len == oldip->len && - memcmp(newip->s, oldip->s, newip->len) == 0) + if(newip->len == oldip->len && memcmp(newip->s, oldip->s, newip->len) == 0) return 0; - if (preserve != 0) { + if(preserve != 0) { anchor = anchor_lump(msg, body->s + body->len - msg->buf, 0, 0); - if (anchor == NULL) { + if(anchor == NULL) { LM_ERR("anchor_lump failed\n"); return -1; } - if (oldpf == AF_INET6) { + if(oldpf == AF_INET6) { omip.s = AOLDMEDIP6; omip.len = AOLDMEDIP6_LEN; } else { @@ -970,25 +932,26 @@ alter_mediaip(struct sip_msg *msg, str *body, str *oldip, int oldpf, omip.len = AOLDMEDIP_LEN; } buf = pkg_malloc(omip.len + oldip->len + CRLF_LEN); - if (buf == NULL) { + if(buf == NULL) { LM_ERR("out of pkg memory\n"); return -1; } memcpy(buf, CRLF, CRLF_LEN); memcpy(buf + CRLF_LEN, omip.s, omip.len); memcpy(buf + CRLF_LEN + omip.len, oldip->s, oldip->len); - if (insert_new_lump_after(anchor, buf, - omip.len + oldip->len + CRLF_LEN, 0) == NULL) { + if(insert_new_lump_after( + anchor, buf, omip.len + oldip->len + CRLF_LEN, 0) + == NULL) { LM_ERR("insert_new_lump_after failed\n"); pkg_free(buf); return -1; } } - if (oldpf == newpf) { + if(oldpf == newpf) { nip.len = newip->len; nip.s = pkg_malloc(nip.len); - if (nip.s == NULL) { + if(nip.s == NULL) { LM_ERR("out of pkg memory\n"); return -1; } @@ -996,7 +959,7 @@ alter_mediaip(struct sip_msg *msg, str *body, str *oldip, int oldpf, } else { nip.len = newip->len + 2; nip.s = pkg_malloc(nip.len); - if (nip.s == NULL) { + if(nip.s == NULL) { LM_ERR("out of pkg memory\n"); return -1; } @@ -1006,21 +969,21 @@ alter_mediaip(struct sip_msg *msg, str *body, str *oldip, int oldpf, } oip = *oldip; - if (oldpf != newpf) { + if(oldpf != newpf) { do { oip.s--; oip.len++; - } while (*oip.s != '6' && *oip.s != '4'); + } while(*oip.s != '6' && *oip.s != '4'); } offset = oip.s - msg->buf; anchor = del_lump(msg, offset, oip.len, 0); - if (anchor == NULL) { + if(anchor == NULL) { LM_ERR("del_lump failed\n"); pkg_free(nip.s); return -1; } - if (insert_new_lump_after(anchor, nip.s, nip.len, 0) == 0) { + if(insert_new_lump_after(anchor, nip.s, nip.len, 0) == 0) { LM_ERR("insert_new_lump_after failed\n"); pkg_free(nip.s); return -1; @@ -1028,20 +991,19 @@ alter_mediaip(struct sip_msg *msg, str *body, str *oldip, int oldpf, return 0; } - static int -alter_mediaport(struct sip_msg *msg, str *body, str *oldport, str *newport, - int preserve) +static int alter_mediaport(struct sip_msg *msg, str *body, str *oldport, + str *newport, int preserve) { char *buf; int offset; - struct lump* anchor; + struct lump *anchor; /* check that updating mediaport is really necessary */ - if (newport->len == oldport->len && - memcmp(newport->s, oldport->s, newport->len) == 0) + if(newport->len == oldport->len + && memcmp(newport->s, oldport->s, newport->len) == 0) return 0; - /* + /* * Since rewriting the same info twice will mess SDP up, * apply simple anti foot shooting measure - put flag on * messages that have been altered and check it when @@ -1056,22 +1018,23 @@ alter_mediaport(struct sip_msg *msg, str *body, str *oldport, str *newport, } #endif - if (preserve != 0) { + if(preserve != 0) { anchor = anchor_lump(msg, body->s + body->len - msg->buf, 0, 0); - if (anchor == NULL) { + if(anchor == NULL) { LM_ERR("anchor_lump failed\n"); return -1; } buf = pkg_malloc(AOLDMEDPRT_LEN + oldport->len + CRLF_LEN); - if (buf == NULL) { + if(buf == NULL) { LM_ERR("out of pkg memory\n"); return -1; } memcpy(buf, CRLF, CRLF_LEN); memcpy(buf + CRLF_LEN, AOLDMEDPRT, AOLDMEDPRT_LEN); memcpy(buf + CRLF_LEN + AOLDMEDPRT_LEN, oldport->s, oldport->len); - if (insert_new_lump_after(anchor, buf, - AOLDMEDPRT_LEN + oldport->len + CRLF_LEN, 0) == NULL) { + if(insert_new_lump_after( + anchor, buf, AOLDMEDPRT_LEN + oldport->len + CRLF_LEN, 0) + == NULL) { LM_ERR("insert_new_lump_after failed\n"); pkg_free(buf); return -1; @@ -1079,19 +1042,19 @@ alter_mediaport(struct sip_msg *msg, str *body, str *oldport, str *newport, } buf = pkg_malloc(newport->len); - if (buf == NULL) { + if(buf == NULL) { LM_ERR("out of pkg memory\n"); return -1; } offset = oldport->s - msg->buf; anchor = del_lump(msg, offset, oldport->len, 0); - if (anchor == NULL) { + if(anchor == NULL) { LM_ERR("del_lump failed\n"); pkg_free(buf); return -1; } memcpy(buf, newport->s, newport->len); - if (insert_new_lump_after(anchor, buf, newport->len, 0) == 0) { + if(insert_new_lump_after(anchor, buf, newport->len, 0) == 0) { LM_ERR("insert_new_lump_after failed\n"); pkg_free(buf); return -1; @@ -1106,32 +1069,32 @@ alter_mediaport(struct sip_msg *msg, str *body, str *oldport, str *newport, /** * */ - static int -alter_rtcp(struct sip_msg *msg, str *body, str *oldport, str *newport) +static int alter_rtcp( + struct sip_msg *msg, str *body, str *oldport, str *newport) { char *buf; int offset; - struct lump* anchor; + struct lump *anchor; /* check that updating rtcpport is really necessary */ - if (newport->len == oldport->len && - memcmp(newport->s, oldport->s, newport->len) == 0) + if(newport->len == oldport->len + && memcmp(newport->s, oldport->s, newport->len) == 0) return 0; buf = pkg_malloc(newport->len); - if (buf == NULL) { + if(buf == NULL) { LM_ERR("alter_rtcp: out of memory\n"); return -1; } offset = oldport->s - msg->buf; anchor = del_lump(msg, offset, oldport->len, 0); - if (anchor == NULL) { + if(anchor == NULL) { LM_ERR("alter_rtcp: del_lump failed\n"); pkg_free(buf); return -1; } memcpy(buf, newport->s, newport->len); - if (insert_new_lump_after(anchor, buf, newport->len, 0) == 0) { + if(insert_new_lump_after(anchor, buf, newport->len, 0) == 0) { LM_ERR("alter_rtcp: insert_new_lump_after failed\n"); pkg_free(buf); return -1; @@ -1141,12 +1104,11 @@ alter_rtcp(struct sip_msg *msg, str *body, str *oldport, str *newport) } - static char * -append_filtered_ip(char *at, str *ip) +static char *append_filtered_ip(char *at, str *ip) { int i; - for (i = 0; i < ip->len; i++) { - if (isdigit(ip->s[i])) { + for(i = 0; i < ip->len; i++) { + if(isdigit(ip->s[i])) { append_chr(at, ip->s[i]); } } @@ -1154,18 +1116,18 @@ append_filtered_ip(char *at, str *ip) } - static int -insert_candidates(struct sip_msg *msg, char *where, str *ip, unsigned int port, - int priority) +static int insert_candidates(struct sip_msg *msg, char *where, str *ip, + unsigned int port, int priority) { char *buf, *at; - struct lump* anchor; + struct lump *anchor; str rtp_port; str rtcp_port; - rtcp_port.s = int2str(port+1, &rtcp_port.len); /* beware static buffer */ - buf = pkg_malloc(24 + 78 + 14 + 24 + 2*ip->len + 2 + 2*rtcp_port.len + 24); - if (buf == NULL) { + rtcp_port.s = int2str(port + 1, &rtcp_port.len); /* beware static buffer */ + buf = pkg_malloc( + 24 + 78 + 14 + 24 + 2 * ip->len + 2 + 2 * rtcp_port.len + 24); + if(buf == NULL) { LM_ERR("insert_candidates: out of memory\n"); return -1; } @@ -1175,7 +1137,7 @@ insert_candidates(struct sip_msg *msg, char *where, str *ip, unsigned int port, append_str(at, "a=candidate:", 12); at = append_filtered_ip(at, ip); append_str(at, " 2 UDP ", 7); - if (priority == 2) { + if(priority == 2) { append_str(at, "16777214 ", 9); } else { append_str(at, "2197815294 ", 11); @@ -1189,7 +1151,7 @@ insert_candidates(struct sip_msg *msg, char *where, str *ip, unsigned int port, append_str(at, "a=candidate:", 12); at = append_filtered_ip(at, ip); append_str(at, " 1 UDP ", 7); - if (priority == 2) { + if(priority == 2) { append_str(at, "16777215 ", 9); } else { append_str(at, "2197815295 ", 11); @@ -1202,12 +1164,12 @@ insert_candidates(struct sip_msg *msg, char *where, str *ip, unsigned int port, LM_DBG("inserting '%.*s'\n", (int)(at - buf), buf); anchor = anchor_lump(msg, where - msg->buf, 0, 0); - if (anchor == 0) { + if(anchor == 0) { LM_ERR("can't get anchor\n"); pkg_free(buf); return -1; } - if (insert_new_lump_before(anchor, buf, at - buf, 0) == 0) { + if(insert_new_lump_before(anchor, buf, at - buf, 0) == 0) { LM_ERR("insert_new_lump_before failed\n"); pkg_free(buf); return -1; @@ -1217,7 +1179,7 @@ insert_candidates(struct sip_msg *msg, char *where, str *ip, unsigned int port, } -static char * gencookie(void) +static char *gencookie(void) { static char cook[34]; @@ -1226,8 +1188,7 @@ static char * gencookie(void) return cook; } - static int -rtpp_checkcap(struct rtpp_node *node, char *cap, int caplen) +static int rtpp_checkcap(struct rtpp_node *node, char *cap, int caplen) { char *cp; struct iovec vf[4] = {{NULL, 0}, {"VF", 2}, {" ", 1}, {NULL, 0}}; @@ -1236,63 +1197,64 @@ rtpp_checkcap(struct rtpp_node *node, char *cap, int caplen) vf[3].iov_len = caplen; cp = send_rtpp_command(node, vf, 4); - if (cp == NULL) + if(cp == NULL) return -1; - if (cp[0] == 'E' || atoi(cp) != 1) + if(cp[0] == 'E' || atoi(cp) != 1) return 0; return 1; } - static int -rtpp_test(struct rtpp_node *node, int isdisabled, int force) +static int rtpp_test(struct rtpp_node *node, int isdisabled, int force) { int rtpp_ver, rval; char *cp; struct iovec v[2] = {{NULL, 0}, {"V", 1}}; - if(node->rn_recheck_ticks == RPC_MAX_RECHECK_TICKS){ + if(node->rn_recheck_ticks == RPC_MAX_RECHECK_TICKS) { LM_DBG("rtpp %s disabled for ever\n", node->rn_url.s); return 1; } - if (force == 0) { - if (isdisabled == 0) + if(force == 0) { + if(isdisabled == 0) return 0; - if (node->rn_recheck_ticks > get_ticks()) + if(node->rn_recheck_ticks > get_ticks()) return 1; } cp = send_rtpp_command(node, v, 2); - if (cp == NULL) { + if(cp == NULL) { LM_WARN("can't get version of the RTP proxy\n"); goto error; } rtpp_ver = atoi(cp); - if (rtpp_ver != SUP_CPROTOVER) { + if(rtpp_ver != SUP_CPROTOVER) { LM_WARN("unsupported version of RTP proxy <%s> found: %d supported," - "%d present\n", node->rn_url.s, SUP_CPROTOVER, rtpp_ver); + "%d present\n", + node->rn_url.s, SUP_CPROTOVER, rtpp_ver); goto error; } rval = rtpp_checkcap(node, REQ_CPROTOVER, sizeof(REQ_CPROTOVER) - 1); - if (rval == -1) { + if(rval == -1) { LM_WARN("RTP proxy went down during version query\n"); goto error; } - if (rval == 0) { + if(rval == 0) { LM_WARN("of RTP proxy <%s> doesn't support required protocol version" - "%s\n", node->rn_url.s, REQ_CPROTOVER); + "%s\n", + node->rn_url.s, REQ_CPROTOVER); goto error; } - LM_INFO("rtp proxy <%s> found, support for it %senabled\n", - node->rn_url.s, force == 0 ? "re-" : ""); + LM_INFO("rtp proxy <%s> found, support for it %senabled\n", node->rn_url.s, + force == 0 ? "re-" : ""); /* Check for optional capabilities */ rval = rtpp_checkcap(node, REP_CPROTOVER, sizeof(REP_CPROTOVER) - 1); - if (rval != -1) { + if(rval != -1) { node->rn_rep_supported = rval; } else { node->rn_rep_supported = 0; } rval = rtpp_checkcap(node, PTL_CPROTOVER, sizeof(PTL_CPROTOVER) - 1); - if (rval != -1) { + if(rval != -1) { node->rn_ptl_supported = rval; } else { node->rn_ptl_supported = 0; @@ -1301,14 +1263,13 @@ rtpp_test(struct rtpp_node *node, int isdisabled, int force) error: LM_WARN("support for RTP proxy <%s> has been disabled%s\n", node->rn_url.s, rtpproxy_disable_tout < 0 ? "" : " temporarily"); - if (rtpproxy_disable_tout >= 0) + if(rtpproxy_disable_tout >= 0) node->rn_recheck_ticks = get_ticks() + rtpproxy_disable_tout; return 1; } - char * -send_rtpp_command(struct rtpp_node *node, struct iovec *v, int vcnt) +char *send_rtpp_command(struct rtpp_node *node, struct iovec *v, int vcnt) { struct sockaddr_un addr; int fd, len, i; @@ -1318,21 +1279,20 @@ send_rtpp_command(struct rtpp_node *node, struct iovec *v, int vcnt) len = 0; cp = buf; - if (node->rn_umode == 0) { + if(node->rn_umode == 0) { memset(&addr, 0, sizeof(addr)); addr.sun_family = AF_LOCAL; - strncpy(addr.sun_path, node->rn_address, - sizeof(addr.sun_path) - 1); + strncpy(addr.sun_path, node->rn_address, sizeof(addr.sun_path) - 1); #ifdef HAVE_SOCKADDR_SA_LEN addr.sun_len = strlen(addr.sun_path); #endif fd = socket(AF_LOCAL, SOCK_STREAM, 0); - if (fd < 0) { + if(fd < 0) { LM_ERR("can't create socket\n"); goto badproxy; } - if (connect(fd, (struct sockaddr *) &addr, sizeof(addr)) < 0) { + if(connect(fd, (struct sockaddr *)&addr, sizeof(addr)) < 0) { close(fd); LM_ERR("can't connect to RTP proxy\n"); goto badproxy; @@ -1340,17 +1300,17 @@ send_rtpp_command(struct rtpp_node *node, struct iovec *v, int vcnt) do { len = writev(fd, v + 1, vcnt - 1); - } while (len == -1 && errno == EINTR); - if (len <= 0) { + } while(len == -1 && errno == EINTR); + if(len <= 0) { close(fd); LM_ERR("can't send command to a RTP proxy\n"); goto badproxy; } do { len = read(fd, buf, sizeof(buf) - 1); - } while (len == -1 && errno == EINTR); + } while(len == -1 && errno == EINTR); close(fd); - if (len <= 0) { + if(len <= 0) { LM_ERR("can't read reply from a RTP proxy\n"); goto badproxy; } @@ -1359,35 +1319,35 @@ send_rtpp_command(struct rtpp_node *node, struct iovec *v, int vcnt) fds[0].events = POLLIN; fds[0].revents = 0; /* Drain input buffer */ - while ((poll(fds, 1, 0) == 1) && - ((fds[0].revents & POLLIN) != 0)) { + while((poll(fds, 1, 0) == 1) && ((fds[0].revents & POLLIN) != 0)) { recv(rtpp_socks[node->idx], buf, sizeof(buf) - 1, 0); fds[0].revents = 0; } v[0].iov_base = gencookie(); v[0].iov_len = strlen(v[0].iov_base); - for (i = 0; i < rtpproxy_retr; i++) { + for(i = 0; i < rtpproxy_retr; i++) { do { len = writev(rtpp_socks[node->idx], v, vcnt); - } while (len == -1 && (errno == EINTR || errno == ENOBUFS)); - if (len <= 0) { + } while(len == -1 && (errno == EINTR || errno == ENOBUFS)); + if(len <= 0) { LM_ERR("can't send command to a RTP proxy\n"); goto badproxy; } - while ((poll(fds, 1, rtpproxy_tout * 1000) == 1) && - (fds[0].revents & POLLIN) != 0) { + while((poll(fds, 1, rtpproxy_tout * 1000) == 1) + && (fds[0].revents & POLLIN) != 0) { do { - len = recv(rtpp_socks[node->idx], buf, sizeof(buf)-1, 0); - } while (len == -1 && errno == EINTR); - if (len <= 0) { + len = recv(rtpp_socks[node->idx], buf, sizeof(buf) - 1, 0); + } while(len == -1 && errno == EINTR); + if(len <= 0) { LM_ERR("can't read reply from a RTP proxy\n"); goto badproxy; } - if (len >= (v[0].iov_len - 1) && - memcmp(buf, v[0].iov_base, (v[0].iov_len - 1)) == 0) { + if(len >= (v[0].iov_len - 1) + && memcmp(buf, v[0].iov_base, (v[0].iov_len - 1)) + == 0) { len -= (v[0].iov_len - 1); cp += (v[0].iov_len - 1); - if (len != 0) { + if(len != 0) { len--; cp++; } @@ -1396,7 +1356,7 @@ send_rtpp_command(struct rtpp_node *node, struct iovec *v, int vcnt) fds[0].revents = 0; } } - if (i == rtpproxy_retr) { + if(i == rtpproxy_retr) { LM_ERR("timeout waiting reply from a RTP proxy\n"); goto badproxy; } @@ -1417,19 +1377,21 @@ send_rtpp_command(struct rtpp_node *node, struct iovec *v, int vcnt) * select the set with the id_set id */ -static struct rtpp_set * select_rtpp_set(int id_set ){ +static struct rtpp_set *select_rtpp_set(int id_set) +{ - struct rtpp_set * rtpp_list; + struct rtpp_set *rtpp_list; /*is it a valid set_id?*/ - if(!rtpp_set_list) - { + if(!rtpp_set_list) { LM_ERR("rtpproxy set list not initialised\n"); return NULL; } - for(rtpp_list=rtpp_set_list->rset_first; rtpp_list!=NULL && - rtpp_list->id_set!=id_set; rtpp_list=rtpp_list->rset_next); + for(rtpp_list = rtpp_set_list->rset_first; + rtpp_list != NULL && rtpp_list->id_set != id_set; + rtpp_list = rtpp_list->rset_next) + ; return rtpp_list; } @@ -1439,21 +1401,20 @@ static struct rtpp_set * select_rtpp_set(int id_set ){ * too rare. Otherwise we should implement "mature" HA clustering, which is * too expensive here. */ - struct rtpp_node * -select_rtpp_node(str callid, int do_test) +struct rtpp_node *select_rtpp_node(str callid, int do_test) { unsigned sum, sumcut, weight_sum; - struct rtpp_node* node; + struct rtpp_node *node; int was_forced; - if(!selected_rtpp_set){ + if(!selected_rtpp_set) { LM_ERR("script error -no valid set selected\n"); return NULL; } /* Most popular case: 1 proxy, nothing to calculate */ - if (selected_rtpp_set->rtpp_node_count == 1) { + if(selected_rtpp_set->rtpp_node_count == 1) { node = selected_rtpp_set->rn_first; - if (node->rn_disabled && node->rn_recheck_ticks <= get_ticks()) + if(node->rn_disabled && node->rn_recheck_ticks <= get_ticks()) node->rn_disabled = rtpp_test(node, 1, 0); return node->rn_disabled ? NULL : node; } @@ -1466,21 +1427,23 @@ select_rtpp_node(str callid, int do_test) was_forced = 0; retry: weight_sum = 0; - for (node=selected_rtpp_set->rn_first; node!=NULL; node=node->rn_next) { + for(node = selected_rtpp_set->rn_first; node != NULL; + node = node->rn_next) { - if (node->rn_disabled && node->rn_recheck_ticks <= get_ticks()){ + if(node->rn_disabled && node->rn_recheck_ticks <= get_ticks()) { /* Try to enable if it's time to try. */ node->rn_disabled = rtpp_test(node, 1, 0); } - if (!node->rn_disabled) + if(!node->rn_disabled) weight_sum += node->rn_weight; } - if (weight_sum == 0) { + if(weight_sum == 0) { /* No proxies? Force all to be redetected, if not yet */ - if (was_forced) + if(was_forced) return NULL; was_forced = 1; - for(node=selected_rtpp_set->rn_first; node!=NULL; node=node->rn_next) { + for(node = selected_rtpp_set->rn_first; node != NULL; + node = node->rn_next) { node->rn_disabled = rtpp_test(node, 1, 1); } goto retry; @@ -1490,32 +1453,33 @@ select_rtpp_node(str callid, int do_test) * sumcut here lays from 0 to weight_sum-1. * Scan proxy list and decrease until appropriate proxy is found. */ - for (node=selected_rtpp_set->rn_first; node!=NULL; node=node->rn_next) { - if (node->rn_disabled) + for(node = selected_rtpp_set->rn_first; node != NULL; + node = node->rn_next) { + if(node->rn_disabled) continue; - if (sumcut < node->rn_weight) + if(sumcut < node->rn_weight) goto found; sumcut -= node->rn_weight; } /* No node list */ return NULL; found: - if (do_test) { + if(do_test) { node->rn_disabled = rtpp_test(node, node->rn_disabled, 0); - if (node->rn_disabled) + if(node->rn_disabled) goto retry; } return node; } -static int -get_extra_id(struct sip_msg* msg, str *id_str) { - if(msg==NULL || extra_id_pv==NULL || id_str==NULL) { +static int get_extra_id(struct sip_msg *msg, str *id_str) +{ + if(msg == NULL || extra_id_pv == NULL || id_str == NULL) { LM_ERR("bad parameters\n"); return 0; } - if (pv_printf_s(msg, extra_id_pv, id_str)<0) { + if(pv_printf_s(msg, extra_id_pv, id_str) < 0) { LM_ERR("cannot print the additional id\n"); return 0; } @@ -1524,13 +1488,12 @@ get_extra_id(struct sip_msg* msg, str *id_str) { } - static int -unforce_rtp_proxy1_f(struct sip_msg* msg, char* str1, char* str2) +static int unforce_rtp_proxy1_f(struct sip_msg *msg, char *str1, char *str2) { str flags; - if (str1) { - if(get_str_fparam(&flags, msg, (fparam_t *) str1)<0) { + if(str1) { + if(get_str_fparam(&flags, msg, (fparam_t *)str1) < 0) { LM_ERR("failed to get flags parameter\n"); return -1; } @@ -1542,8 +1505,7 @@ unforce_rtp_proxy1_f(struct sip_msg* msg, char* str1, char* str2) } - static int -unforce_rtp_proxy(struct sip_msg* msg, char* flags) +static int unforce_rtp_proxy(struct sip_msg *msg, char *flags) { str callid, from_tag, to_tag, viabranch; char *cp; @@ -1555,15 +1517,15 @@ unforce_rtp_proxy(struct sip_msg* msg, char* flags) struct rtpp_node *node; struct iovec v[1 + 4 + 3 + 2] = {{NULL, 0}, {"D", 1}, {" ", 1}, {NULL, 0}, {NULL, 0}, {NULL, 0}, {" ", 1}, {NULL, 0}, {" ", 1}, {NULL, 0}}; - /* 1 */ /* 2 */ /* 3 */ /* 4 */ /* 5 */ /* 6 */ /* 7 */ /* 8 */ /* 9 */ + /* 1 */ /* 2 */ /* 3 */ /* 4 */ /* 5 */ /* 6 */ /* 7 */ /* 8 */ /* 9 */ - if(msg==NULL) { + if(msg == NULL) { LM_ERR("invalid sip message structure\n"); return -1; } - for (cp = flags; cp && *cp; cp++) { - switch (*cp) { + for(cp = flags; cp && *cp; cp++) { + switch(*cp) { case '1': via = 1; break; @@ -1617,26 +1579,26 @@ unforce_rtp_proxy(struct sip_msg* msg, char* flags) } } - if (get_callid(msg, &callid) == -1 || callid.len == 0) { + if(get_callid(msg, &callid) == -1 || callid.len == 0) { LM_ERR("can't get Call-Id field\n"); return -1; } to_tag.s = 0; to_tag.len = 0; - if ((to == 1) && get_to_tag(msg, &to_tag) == -1) { + if((to == 1) && get_to_tag(msg, &to_tag) == -1) { LM_ERR("can't get To tag\n"); return -1; } - if (get_from_tag(msg, &from_tag) == -1 || from_tag.len == 0) { + if(get_from_tag(msg, &from_tag) == -1 || from_tag.len == 0) { LM_ERR("can't get From tag\n"); return -1; } - if (via) { - if (via == 1) + if(via) { + if(via == 1) ret = get_via_branch(msg, 1, &viabranch); else /* (via == 2) */ ret = get_via_branch(msg, 2, &viabranch); - if (ret == -1 || viabranch.len == 0) { + if(ret == -1 || viabranch.len == 0) { LM_ERR("can't get Via branch\n"); return -1; } @@ -1645,7 +1607,7 @@ unforce_rtp_proxy(struct sip_msg* msg, char* flags) STR2IOVEC(viabranch, v[5]); } else /* Append extra id to call-id */ - if (extra && extra_id_pv && get_extra_id(msg, &extra_id)) { + if(extra && extra_id_pv && get_extra_id(msg, &extra_id)) { v[4].iov_base = ";"; v[4].iov_len = 1; STR2IOVEC(extra_id, v[5]); @@ -1654,12 +1616,12 @@ unforce_rtp_proxy(struct sip_msg* msg, char* flags) STR2IOVEC(from_tag, v[7]); STR2IOVEC(to_tag, v[9]); - if(msg->id != current_msg_id){ + if(msg->id != current_msg_id) { selected_rtpp_set = default_rtpp_set; } node = select_rtpp_node(callid, 1); - if (!node) { + if(!node) { LM_ERR("no available proxies\n"); return -1; } @@ -1671,13 +1633,12 @@ unforce_rtp_proxy(struct sip_msg* msg, char* flags) /* This function assumes p points to a line of requested type. */ - static int -set_rtp_proxy_set_f(struct sip_msg * msg, char * str1, char * str2) +static int set_rtp_proxy_set_f(struct sip_msg *msg, char *str1, char *str2) { rtpp_set_link_t *rtpl; pv_value_t val; - rtpl = (rtpp_set_link_t*)str1; + rtpl = (rtpp_set_link_t *)str1; current_msg_id = 0; selected_rtpp_set = 0; @@ -1686,7 +1647,7 @@ set_rtp_proxy_set_f(struct sip_msg * msg, char * str1, char * str2) current_msg_id = msg->id; selected_rtpp_set = rtpl->rset; } else { - if(pv_get_spec_value(msg, rtpl->rpv, &val)<0) { + if(pv_get_spec_value(msg, rtpl->rpv, &val) < 0) { LM_ERR("cannot evaluate pv param\n"); return -1; } @@ -1695,7 +1656,7 @@ set_rtp_proxy_set_f(struct sip_msg * msg, char * str1, char * str2) return -1; } selected_rtpp_set = select_rtpp_set(val.ri); - if(selected_rtpp_set==NULL) { + if(selected_rtpp_set == NULL) { LM_ERR("could not locate rtpproxy set %ld\n", val.ri); return -1; } @@ -1704,37 +1665,37 @@ set_rtp_proxy_set_f(struct sip_msg * msg, char * str1, char * str2) return 1; } - static int -rtpproxy_manage(struct sip_msg *msg, char *flags, char *ip) +static int rtpproxy_manage(struct sip_msg *msg, char *flags, char *ip) { char *cp = NULL; char newip[IP_ADDR_MAX_STR_SIZE]; int method; int nosdp; - if(route_type==BRANCH_FAILURE_ROUTE) { + if(route_type == BRANCH_FAILURE_ROUTE) { /* do nothing in branch failure event route * - delete done on transaction failure route */ return 1; } - if(msg->cseq==NULL && ((parse_headers(msg, HDR_CSEQ_F, 0)==-1) - || (msg->cseq==NULL))) { + if(msg->cseq == NULL + && ((parse_headers(msg, HDR_CSEQ_F, 0) == -1) + || (msg->cseq == NULL))) { LM_ERR("no CSEQ header\n"); return -1; } method = get_cseq(msg)->method_id; - if(!(method==METHOD_INVITE || method==METHOD_ACK || method==METHOD_CANCEL - || method==METHOD_BYE || method==METHOD_UPDATE - || method==METHOD_PRACK)) + if(!(method == METHOD_INVITE || method == METHOD_ACK + || method == METHOD_CANCEL || method == METHOD_BYE + || method == METHOD_UPDATE || method == METHOD_PRACK)) return -1; - if(method==METHOD_CANCEL || method==METHOD_BYE) + if(method == METHOD_CANCEL || method == METHOD_BYE) return unforce_rtp_proxy(msg, flags); - if(ip==NULL) { + if(ip == NULL) { cp = ip_addr2a(&msg->rcv.dst_ip); strcpy(newip, cp); } @@ -1745,87 +1706,80 @@ rtpproxy_manage(struct sip_msg *msg, char *flags, char *ip) nosdp = parse_sdp(msg); if(msg->first_line.type == SIP_REQUEST) { - if(method==METHOD_ACK && nosdp==0) - return force_rtp_proxy(msg, flags, (cp!=NULL)?newip:ip, 0, - (ip!=NULL)?1:0); - if(method==METHOD_PRACK && nosdp==0) - return force_rtp_proxy(msg, flags, (cp!=NULL)?newip:ip, 1, - (ip!=NULL)?1:0); - if(method==METHOD_UPDATE && nosdp==0) - return force_rtp_proxy(msg, flags, (cp!=NULL)?newip:ip, 1, - (ip!=NULL)?1:0); - if(method==METHOD_INVITE && nosdp==0) { + if(method == METHOD_ACK && nosdp == 0) + return force_rtp_proxy(msg, flags, (cp != NULL) ? newip : ip, 0, + (ip != NULL) ? 1 : 0); + if(method == METHOD_PRACK && nosdp == 0) + return force_rtp_proxy(msg, flags, (cp != NULL) ? newip : ip, 1, + (ip != NULL) ? 1 : 0); + if(method == METHOD_UPDATE && nosdp == 0) + return force_rtp_proxy(msg, flags, (cp != NULL) ? newip : ip, 1, + (ip != NULL) ? 1 : 0); + if(method == METHOD_INVITE && nosdp == 0) { msg->msg_flags |= FL_SDP_BODY; - if(tmb.t_gett!=NULL && tmb.t_gett()!=NULL - && tmb.t_gett()!=T_UNDEFINED) + if(tmb.t_gett != NULL && tmb.t_gett() != NULL + && tmb.t_gett() != T_UNDEFINED) tmb.t_gett()->uas.request->msg_flags |= FL_SDP_BODY; - if(route_type==FAILURE_ROUTE) + if(route_type == FAILURE_ROUTE) return unforce_rtp_proxy(msg, flags); - return force_rtp_proxy(msg, flags, (cp!=NULL)?newip:ip, 1, - (ip!=NULL)?1:0); + return force_rtp_proxy(msg, flags, (cp != NULL) ? newip : ip, 1, + (ip != NULL) ? 1 : 0); } } else if(msg->first_line.type == SIP_REPLY) { - if(msg->first_line.u.reply.statuscode>=300) + if(msg->first_line.u.reply.statuscode >= 300) return unforce_rtp_proxy(msg, flags); - if(nosdp==0) { - if(method==METHOD_PRACK) - return force_rtp_proxy(msg, flags, (cp!=NULL)?newip:ip, 0, - (ip!=NULL)?1:0); - if(method==METHOD_UPDATE) - return force_rtp_proxy(msg, flags, (cp!=NULL)?newip:ip, 0, - (ip!=NULL)?1:0); - if(tmb.t_gett==NULL || tmb.t_gett()==NULL - || tmb.t_gett()==T_UNDEFINED) - return force_rtp_proxy(msg, flags, (cp!=NULL)?newip:ip, 0, - (ip!=NULL)?1:0); + if(nosdp == 0) { + if(method == METHOD_PRACK) + return force_rtp_proxy(msg, flags, (cp != NULL) ? newip : ip, 0, + (ip != NULL) ? 1 : 0); + if(method == METHOD_UPDATE) + return force_rtp_proxy(msg, flags, (cp != NULL) ? newip : ip, 0, + (ip != NULL) ? 1 : 0); + if(tmb.t_gett == NULL || tmb.t_gett() == NULL + || tmb.t_gett() == T_UNDEFINED) + return force_rtp_proxy(msg, flags, (cp != NULL) ? newip : ip, 0, + (ip != NULL) ? 1 : 0); if(tmb.t_gett()->uas.request->msg_flags & FL_SDP_BODY) - return force_rtp_proxy(msg, flags, (cp!=NULL)?newip:ip, 0, - (ip!=NULL)?1:0); - return force_rtp_proxy(msg, flags, (cp!=NULL)?newip:ip, 1, - (ip!=NULL)?1:0); + return force_rtp_proxy(msg, flags, (cp != NULL) ? newip : ip, 0, + (ip != NULL) ? 1 : 0); + return force_rtp_proxy(msg, flags, (cp != NULL) ? newip : ip, 1, + (ip != NULL) ? 1 : 0); } } return -1; } - static int -rtpproxy_manage0(struct sip_msg *msg, char *flags, char *ip) +static int rtpproxy_manage0(struct sip_msg *msg, char *flags, char *ip) { return rtpproxy_manage(msg, 0, 0); } - static int -rtpproxy_manage1(struct sip_msg *msg, char *flags, char *ip) +static int rtpproxy_manage1(struct sip_msg *msg, char *flags, char *ip) { str flag_str; - if(fixup_get_svalue(msg, (gparam_p)flags, &flag_str)<0) - { + if(fixup_get_svalue(msg, (gparam_p)flags, &flag_str) < 0) { LM_ERR("invalid flags parameter\n"); return -1; } return rtpproxy_manage(msg, flag_str.s, 0); } - static int -rtpproxy_manage2(struct sip_msg *msg, char *flags, char *ip) +static int rtpproxy_manage2(struct sip_msg *msg, char *flags, char *ip) { str flag_str; str ip_str; - if(fixup_get_svalue(msg, (gparam_p)flags, &flag_str)<0) - { + if(fixup_get_svalue(msg, (gparam_p)flags, &flag_str) < 0) { LM_ERR("invalid flags parameter\n"); return -1; } - if(fixup_get_svalue(msg, (gparam_p)ip, &ip_str)<0) - { + if(fixup_get_svalue(msg, (gparam_p)ip, &ip_str) < 0) { LM_ERR("invalid IP parameter\n"); return -1; } return rtpproxy_manage(msg, flag_str.s, ip_str.s); } - static int -rtpproxy_offer1_helper_f(struct sip_msg *msg, char *flags) +static int rtpproxy_offer1_helper_f(struct sip_msg *msg, char *flags) { char *cp; char newip[IP_ADDR_MAX_STR_SIZE]; @@ -1836,13 +1790,12 @@ rtpproxy_offer1_helper_f(struct sip_msg *msg, char *flags) return force_rtp_proxy(msg, flags, newip, 1, 0); } - static int -rtpproxy_offer1_f(struct sip_msg *msg, char *str1, char *str2) +static int rtpproxy_offer1_f(struct sip_msg *msg, char *str1, char *str2) { str flags; - if (str1) { - if(get_str_fparam(&flags, msg, (fparam_t *) str1)<0) { + if(str1) { + if(get_str_fparam(&flags, msg, (fparam_t *)str1) < 0) { LM_ERR("failed to get flags parameter\n"); return -1; } @@ -1853,30 +1806,28 @@ rtpproxy_offer1_f(struct sip_msg *msg, char *str1, char *str2) return rtpproxy_offer1_helper_f(msg, flags.s); } - static int -rtpproxy_offer2_f(struct sip_msg *msg, char *param1, char *param2) +static int rtpproxy_offer2_f(struct sip_msg *msg, char *param1, char *param2) { str flags, new_ip; - if(get_str_fparam(&flags, msg, (fparam_t *) param1)<0) { + if(get_str_fparam(&flags, msg, (fparam_t *)param1) < 0) { LM_ERR("failed to get flags parameter\n"); return -1; } - if(get_str_fparam(&new_ip, msg, (fparam_t *) param2)<0) { + if(get_str_fparam(&new_ip, msg, (fparam_t *)param2) < 0) { LM_ERR("failed to get new ip parameter\n"); return -1; } return force_rtp_proxy(msg, flags.s, new_ip.s, 1, 1); } - static int -rtpproxy_answer1_helper_f(struct sip_msg *msg, char *flags) +static int rtpproxy_answer1_helper_f(struct sip_msg *msg, char *flags) { char *cp; char newip[IP_ADDR_MAX_STR_SIZE]; - if (msg->first_line.type == SIP_REQUEST) - if (msg->first_line.u.request.method_value != METHOD_ACK) + if(msg->first_line.type == SIP_REQUEST) + if(msg->first_line.u.request.method_value != METHOD_ACK) return -1; cp = ip_addr2a(&msg->rcv.dst_ip); @@ -1885,13 +1836,12 @@ rtpproxy_answer1_helper_f(struct sip_msg *msg, char *flags) return force_rtp_proxy(msg, flags, newip, 0, 0); } - static int -rtpproxy_answer1_f(struct sip_msg *msg, char *str1, char *str2) +static int rtpproxy_answer1_f(struct sip_msg *msg, char *str1, char *str2) { str flags; - if (str1) { - if(get_str_fparam(&flags, msg, (fparam_t *) str1)<0) { + if(str1) { + if(get_str_fparam(&flags, msg, (fparam_t *)str1) < 0) { LM_ERR("failed to get flags parameter\n"); return -1; } @@ -1902,21 +1852,20 @@ rtpproxy_answer1_f(struct sip_msg *msg, char *str1, char *str2) return rtpproxy_answer1_helper_f(msg, flags.s); } - static int -rtpproxy_answer2_f(struct sip_msg *msg, char *param1, char *param2) +static int rtpproxy_answer2_f(struct sip_msg *msg, char *param1, char *param2) { str flags, new_ip; - if (msg->first_line.type == SIP_REQUEST) - if (msg->first_line.u.request.method_value != METHOD_ACK) + if(msg->first_line.type == SIP_REQUEST) + if(msg->first_line.u.request.method_value != METHOD_ACK) return -1; - if(get_str_fparam(&flags, msg, (fparam_t *) param1)<0) { + if(get_str_fparam(&flags, msg, (fparam_t *)param1) < 0) { LM_ERR("failed to get flags parameter\n"); return -1; } - if(get_str_fparam(&new_ip, msg, (fparam_t *) param2)<0) { + if(get_str_fparam(&new_ip, msg, (fparam_t *)param2) < 0) { LM_ERR("failed to get new ip parameter\n"); return -1; } @@ -1924,19 +1873,19 @@ rtpproxy_answer2_f(struct sip_msg *msg, char *param1, char *param2) } -struct options { +struct options +{ str s; int oidx; }; - static int -append_opts(struct options *op, char ch) +static int append_opts(struct options *op, char ch) { void *p; - if (op->s.len <= op->oidx) { + if(op->s.len <= op->oidx) { p = pkg_realloc(op->s.s, op->oidx + 32); - if (p == NULL) { + if(p == NULL) { return (-1); } op->s.s = p; @@ -1946,38 +1895,38 @@ append_opts(struct options *op, char ch) return (0); } - static void -free_opts(struct options *op1, struct options *op2, struct options *op3) +static void free_opts( + struct options *op1, struct options *op2, struct options *op3) { - if (op1->s.len > 0 && op1->s.s != NULL) { + if(op1->s.len > 0 && op1->s.s != NULL) { pkg_free(op1->s.s); op1->s.len = 0; } - if (op2->s.len > 0 && op2->s.s != NULL) { + if(op2->s.len > 0 && op2->s.s != NULL) { pkg_free(op2->s.s); op2->s.len = 0; } - if (op3->s.len > 0 && op3->s.s != NULL) { + if(op3->s.len > 0 && op3->s.s != NULL) { pkg_free(op3->s.s); op3->s.len = 0; } } -#define FORCE_RTP_PROXY_RET(e) \ - do { \ +#define FORCE_RTP_PROXY_RET(e) \ + do { \ free_opts(&opts, &rep_opts, &pt_opts); \ - return (e); \ - } while (0); + return (e); \ + } while(0); -struct new_mediaip { +struct new_mediaip +{ str strip; int pf; }; - static int -force_rtp_proxy(struct sip_msg* msg, char* str1, char* str2, int offer, - int forcedIP) +static int force_rtp_proxy( + struct sip_msg *msg, char *str1, char *str2, int offer, int forcedIP) { str body, body1, oldport, oldip, newport; struct new_mediaip newip; @@ -1989,33 +1938,33 @@ force_rtp_proxy(struct sip_msg* msg, char* str1, char* str2, int offer, int pf, force; struct options opts, rep_opts, pt_opts; char *cp, *cp1; - char *cpend, *next; + char *cpend, *next; char **ap, *argv[10]; - struct lump* anchor; + struct lump *anchor; struct rtpp_node *node; struct iovec v[] = { - {NULL, 0}, /* reserved (cookie) */ - {NULL, 0}, /* command & common options */ - {NULL, 0}, /* per-media/per-node options 1 */ - {NULL, 0}, /* per-media/per-node options 2 */ - {" ", 1}, /* separator */ - {NULL, 0}, /* callid */ - {NULL, 0}, /* via-branch separator ";" */ - {NULL, 0}, /* via-branch */ - {" ", 1}, /* separator */ - {NULL, 7}, /* newip */ - {" ", 1}, /* separator */ - {NULL, 1}, /* oldport */ - {" ", 1}, /* separator */ - {NULL, 0}, /* from_tag */ - {";", 1}, /* separator */ - {NULL, 0}, /* medianum */ - {" ", 1}, /* separator */ - {NULL, 0}, /* to_tag */ - {";", 1}, /* separator */ - {NULL, 0}, /* medianum */ - {" ", 1}, /* separator */ - {NULL, 0}, /* Timeout-Socket */ + {NULL, 0}, /* reserved (cookie) */ + {NULL, 0}, /* command & common options */ + {NULL, 0}, /* per-media/per-node options 1 */ + {NULL, 0}, /* per-media/per-node options 2 */ + {" ", 1}, /* separator */ + {NULL, 0}, /* callid */ + {NULL, 0}, /* via-branch separator ";" */ + {NULL, 0}, /* via-branch */ + {" ", 1}, /* separator */ + {NULL, 7}, /* newip */ + {" ", 1}, /* separator */ + {NULL, 1}, /* oldport */ + {" ", 1}, /* separator */ + {NULL, 0}, /* from_tag */ + {";", 1}, /* separator */ + {NULL, 0}, /* medianum */ + {" ", 1}, /* separator */ + {NULL, 0}, /* to_tag */ + {";", 1}, /* separator */ + {NULL, 0}, /* medianum */ + {" ", 1}, /* separator */ + {NULL, 0}, /* Timeout-Socket */ }; int iovec_param_count; int autobridge_ipv4v6; @@ -2029,10 +1978,10 @@ force_rtp_proxy(struct sip_msg* msg, char* str1, char* str2, int offer, int c1p_altered; int sdp_session_num, sdp_stream_num; - sdp_session_cell_t* sdp_session; - sdp_stream_cell_t* sdp_stream; + sdp_session_cell_t *sdp_session; + sdp_stream_cell_t *sdp_stream; - if(msg==NULL) { + if(msg == NULL) { LM_ERR("invalid sip message structure\n"); return -1; } @@ -2043,13 +1992,14 @@ force_rtp_proxy(struct sip_msg* msg, char* str1, char* str2, int offer, memset(&rep_opts, '\0', sizeof(rep_opts)); memset(&pt_opts, '\0', sizeof(pt_opts)); /* Leave space for U/L prefix TBD later */ - if (append_opts(&opts, '?') == -1) { + if(append_opts(&opts, '?') == -1) { LM_ERR("out of pkg memory\n"); - FORCE_RTP_PROXY_RET (-1); + FORCE_RTP_PROXY_RET(-1); } - flookup = force = real = orgip = commip = via = autobridge_ipv4v6 = extra = 0; - for (cp = str1; cp != NULL && *cp != '\0'; cp++) { - switch (*cp) { + flookup = force = real = orgip = commip = via = autobridge_ipv4v6 = extra = + 0; + for(cp = str1; cp != NULL && *cp != '\0'; cp++) { + switch(*cp) { case '1': via = 1; break; @@ -2067,9 +2017,9 @@ force_rtp_proxy(struct sip_msg* msg, char* str1, char* str2, int offer, case 'a': case 'A': - if (append_opts(&opts, 'A') == -1) { + if(append_opts(&opts, 'A') == -1) { LM_ERR("out of pkg memory\n"); - FORCE_RTP_PROXY_RET (-1); + FORCE_RTP_PROXY_RET(-1); } real = 1; break; @@ -2080,24 +2030,24 @@ force_rtp_proxy(struct sip_msg* msg, char* str1, char* str2, int offer, case 'i': case 'I': - if (append_opts(&opts, 'I') == -1) { + if(append_opts(&opts, 'I') == -1) { LM_ERR("out of pkg memory\n"); - FORCE_RTP_PROXY_RET (-1); + FORCE_RTP_PROXY_RET(-1); } break; case 'e': case 'E': - if (append_opts(&opts, 'E') == -1) { + if(append_opts(&opts, 'E') == -1) { LM_ERR("out of pkg memory\n"); - FORCE_RTP_PROXY_RET (-1); + FORCE_RTP_PROXY_RET(-1); } break; case 'l': case 'L': - if (offer == 0) { - FORCE_RTP_PROXY_RET (-1); + if(offer == 0) { + FORCE_RTP_PROXY_RET(-1); } flookup = 1; break; @@ -2129,23 +2079,23 @@ force_rtp_proxy(struct sip_msg* msg, char* str1, char* str2, int offer, case 'w': case 'W': - if (append_opts(&opts, 'S') == -1) { + if(append_opts(&opts, 'S') == -1) { LM_ERR("out of pkg memory\n"); - FORCE_RTP_PROXY_RET (-1); + FORCE_RTP_PROXY_RET(-1); } break; case 'z': case 'Z': - if (append_opts(&rep_opts, 'Z') == -1) { + if(append_opts(&rep_opts, 'Z') == -1) { LM_ERR("out of pkg memory\n"); - FORCE_RTP_PROXY_RET (-1); + FORCE_RTP_PROXY_RET(-1); } /* If there are any digits following Z copy them into the command */ - for (; cp[1] != '\0' && isdigit(cp[1]); cp++) { - if (append_opts(&rep_opts, cp[1]) == -1) { + for(; cp[1] != '\0' && isdigit(cp[1]); cp++) { + if(append_opts(&rep_opts, cp[1]) == -1) { LM_ERR("out of pkg memory\n"); - FORCE_RTP_PROXY_RET (-1); + FORCE_RTP_PROXY_RET(-1); } } break; @@ -2157,11 +2107,11 @@ force_rtp_proxy(struct sip_msg* msg, char* str1, char* str2, int offer, default: LM_ERR("unknown option `%c'\n", *cp); - FORCE_RTP_PROXY_RET (-1); + FORCE_RTP_PROXY_RET(-1); } } - if (offer != 0) { + if(offer != 0) { create = 1; } else { create = 0; @@ -2169,76 +2119,77 @@ force_rtp_proxy(struct sip_msg* msg, char* str1, char* str2, int offer, /* extract_body will also parse all the headers in the message as * a side effect => don't move get_callid/get_to_tag in front of it * -- andrei */ - if (extract_body(msg, &body) == -1) { + if(extract_body(msg, &body) == -1) { LM_ERR("can't extract body from the message\n"); - FORCE_RTP_PROXY_RET (-1); + FORCE_RTP_PROXY_RET(-1); } - if (get_callid(msg, &callid) == -1 || callid.len == 0) { + if(get_callid(msg, &callid) == -1 || callid.len == 0) { LM_ERR("can't get Call-Id field\n"); - FORCE_RTP_PROXY_RET (-1); + FORCE_RTP_PROXY_RET(-1); } to_tag.s = 0; - if (get_to_tag(msg, &to_tag) == -1) { + if(get_to_tag(msg, &to_tag) == -1) { LM_ERR("can't get To tag\n"); - FORCE_RTP_PROXY_RET (-1); + FORCE_RTP_PROXY_RET(-1); } - if (get_from_tag(msg, &from_tag) == -1 || from_tag.len == 0) { + if(get_from_tag(msg, &from_tag) == -1 || from_tag.len == 0) { LM_ERR("can't get From tag\n"); - FORCE_RTP_PROXY_RET (-1); + FORCE_RTP_PROXY_RET(-1); } - if (via) { - if (via == 1) + if(via) { + if(via == 1) ret = get_via_branch(msg, 1, &viabranch); else /* (via == 2) */ ret = get_via_branch(msg, 2, &viabranch); - if (ret == -1 || viabranch.len == 0) { + if(ret == -1 || viabranch.len == 0) { LM_ERR("can't get Via branch\n"); - FORCE_RTP_PROXY_RET (-1); + FORCE_RTP_PROXY_RET(-1); } v[6].iov_base = ";"; v[6].iov_len = 1; STR2IOVEC(viabranch, v[7]); } else /* Append extra id to call-id */ - if (extra && extra_id_pv && get_extra_id(msg, &extra_id)) { + if(extra && extra_id_pv && get_extra_id(msg, &extra_id)) { v[6].iov_base = ";"; v[6].iov_len = 1; STR2IOVEC(extra_id, v[7]); } - if (flookup != 0) { - if (to_tag.len == 0) { - FORCE_RTP_PROXY_RET (-1); + if(flookup != 0) { + if(to_tag.len == 0) { + FORCE_RTP_PROXY_RET(-1); } - if (msg->first_line.type == SIP_REQUEST) { + if(msg->first_line.type == SIP_REQUEST) { tmp = from_tag; from_tag = to_tag; to_tag = tmp; } create = 0; - } else if ((msg->first_line.type == SIP_REPLY && offer != 0) - || (msg->first_line.type == SIP_REQUEST && offer == 0)) { - if (to_tag.len == 0) { - FORCE_RTP_PROXY_RET (-1); + } else if((msg->first_line.type == SIP_REPLY && offer != 0) + || (msg->first_line.type == SIP_REQUEST && offer == 0)) { + if(to_tag.len == 0) { + FORCE_RTP_PROXY_RET(-1); } tmp = from_tag; from_tag = to_tag; to_tag = tmp; } proxied = 0; - if (nortpproxy_str.len) { - for ( cp=body.s ; (len=body.s+body.len-cp) >= nortpproxy_str.len ; ) { + if(nortpproxy_str.len) { + for(cp = body.s; + (len = body.s + body.len - cp) >= nortpproxy_str.len;) { cp1 = ser_memmem(cp, nortpproxy_str.s, len, nortpproxy_str.len); - if (cp1 == NULL) + if(cp1 == NULL) break; - if (cp1[-1] == '\n' || cp1[-1] == '\r') { + if(cp1[-1] == '\n' || cp1[-1] == '\r') { proxied = 1; break; } cp = cp1 + nortpproxy_str.len; } } - if (proxied != 0 && force == 0) { - FORCE_RTP_PROXY_RET (-2); + if(proxied != 0 && force == 0) { + FORCE_RTP_PROXY_RET(-2); } /* * Parsing of SDP body. @@ -2254,15 +2205,15 @@ force_rtp_proxy(struct sip_msg* msg, char* str1, char* str2, int offer, */ if(0 != parse_sdp(msg)) { LM_ERR("Unable to parse sdp\n"); - FORCE_RTP_PROXY_RET (-1); + FORCE_RTP_PROXY_RET(-1); } #ifdef EXTRA_DEBUG - print_sdp((sdp_info_t*)msg->body, L_DBG); + print_sdp((sdp_info_t *)msg->body, L_DBG); #endif bodylimit = body.s + body.len; - if(msg->id != current_msg_id){ + if(msg->id != current_msg_id) { selected_rtpp_set = default_rtpp_set; } @@ -2273,17 +2224,16 @@ force_rtp_proxy(struct sip_msg* msg, char* str1, char* str2, int offer, STR2IOVEC(from_tag, v[13]); STR2IOVEC(to_tag, v[17]); - if (ice_candidate_priority_avp_param) { - if (search_first_avp(ice_candidate_priority_avp_type, - ice_candidate_priority_avp, - &ice_candidate_priority_val, 0) + if(ice_candidate_priority_avp_param) { + if(search_first_avp(ice_candidate_priority_avp_type, + ice_candidate_priority_avp, &ice_candidate_priority_val, 0) == NULL) { ice_candidate_priority_val.n = 2; - } else if ((ice_candidate_priority_val.n < 0) || - (ice_candidate_priority_val.n > 2)) { + } else if((ice_candidate_priority_val.n < 0) + || (ice_candidate_priority_val.n > 2)) { LM_ERR("invalid ice candidate priority value %ld\n", ice_candidate_priority_val.n); - FORCE_RTP_PROXY_RET (-1); + FORCE_RTP_PROXY_RET(-1); } } else { ice_candidate_priority_val.n = 0; @@ -2291,10 +2241,10 @@ force_rtp_proxy(struct sip_msg* msg, char* str1, char* str2, int offer, /* check if this is a single or a multi stream SDP offer/answer */ sdp_stream_num = get_sdp_stream_num(msg); - switch (sdp_stream_num) { + switch(sdp_stream_num) { case 0: LM_ERR("sdp w/o streams\n"); - FORCE_RTP_PROXY_RET (-1); + FORCE_RTP_PROXY_RET(-1); break; case 1: media_multi = 0; @@ -2309,17 +2259,19 @@ force_rtp_proxy(struct sip_msg* msg, char* str1, char* str2, int offer, sdp_session_num = 0; for(;;) { sdp_session = get_sdp_session(msg, sdp_session_num); - if(!sdp_session) break; + if(!sdp_session) + break; sdp_stream_num = 0; c1p_altered = 0; o1p = sdp_session->o_ip_addr.s; for(;;) { sdp_stream = get_sdp_stream(msg, sdp_session_num, sdp_stream_num); - if (!sdp_stream || - (ice_candidate_priority_val.n - && sdp_stream->remote_candidates.len)) break; + if(!sdp_stream + || (ice_candidate_priority_val.n + && sdp_stream->remote_candidates.len)) + break; - if (sdp_stream->ip_addr.s && sdp_stream->ip_addr.len>0) { + if(sdp_stream->ip_addr.s && sdp_stream->ip_addr.len > 0) { oldip = sdp_stream->ip_addr; pf = sdp_stream->pf; } else { @@ -2330,7 +2282,7 @@ force_rtp_proxy(struct sip_msg* msg, char* str1, char* str2, int offer, payload_types = sdp_stream->payloads; medianum++; - if (real != 0) { + if(real != 0) { newip.strip = oldip; newip.pf = pf; } else { @@ -2339,29 +2291,29 @@ force_rtp_proxy(struct sip_msg* msg, char* str1, char* str2, int offer, newip.pf = msg->rcv.src_ip.af; } /* XXX must compare address families in all addresses */ - if (pf == AF_INET6) { - if (autobridge_ipv4v6 != 0) { - if ((append_opts(&opts, 'E') == -1) - || (append_opts(&opts, 'I') == -1)) { + if(pf == AF_INET6) { + if(autobridge_ipv4v6 != 0) { + if((append_opts(&opts, 'E') == -1) + || (append_opts(&opts, 'I') == -1)) { LM_ERR("out of pkg memory\n"); - FORCE_RTP_PROXY_RET (-1); + FORCE_RTP_PROXY_RET(-1); } /* Only execute once */ autobridge_ipv4v6 = 0; } - if (append_opts(&opts, '6') == -1) { + if(append_opts(&opts, '6') == -1) { LM_ERR("out of pkg memory\n"); - FORCE_RTP_PROXY_RET (-1); + FORCE_RTP_PROXY_RET(-1); } /* We need to update the pointers and the length here, it has changed. */ v[1].iov_base = opts.s.s; v[1].iov_len = opts.oidx; } else { - if (autobridge_ipv4v6 != 0) { - if ((append_opts(&opts, 'I') == -1) - || (append_opts(&opts, 'E') == -1)) { + if(autobridge_ipv4v6 != 0) { + if((append_opts(&opts, 'I') == -1) + || (append_opts(&opts, 'E') == -1)) { LM_ERR("out of pkg memory\n"); - FORCE_RTP_PROXY_RET (-1); + FORCE_RTP_PROXY_RET(-1); } /* We need to update the pointers and the length here, it has changed. */ v[1].iov_base = opts.s.s; @@ -2374,10 +2326,11 @@ force_rtp_proxy(struct sip_msg* msg, char* str1, char* str2, int offer, STR2IOVEC(newip.strip, v[9]); STR2IOVEC(oldport, v[11]); #ifdef EXTRA_DEBUG - LM_DBG("STR2IOVEC(newip[%.*s], v[9])", newip.strip.len, newip.strip.s); + LM_DBG("STR2IOVEC(newip[%.*s], v[9])", newip.strip.len, + newip.strip.s); LM_DBG("STR2IOVEC(oldport[%.*s], v[11])", oldport.len, oldport.s); #endif - if (1 || media_multi) /* XXX netch: can't choose now*/ + if(1 || media_multi) /* XXX netch: can't choose now*/ { snprintf(itoabuf_buf, sizeof itoabuf_buf, "%d", medianum); itoabuf_str.s = itoabuf_buf; @@ -2394,13 +2347,13 @@ force_rtp_proxy(struct sip_msg* msg, char* str1, char* str2, int offer, } do { node = select_rtpp_node(callid, 1); - if (!node) { + if(!node) { LM_ERR("no available proxies\n"); - FORCE_RTP_PROXY_RET (-3); + FORCE_RTP_PROXY_RET(-3); } set_rtp_inst_pvar(msg, &node->rn_url); - if (rep_opts.oidx > 0) { - if (node->rn_rep_supported == 0) { + if(rep_opts.oidx > 0) { + if(node->rn_rep_supported == 0) { LM_WARN("re-packetization is requested but is not " "supported by the selected RTP proxy node\n"); v[2].iov_len = 0; @@ -2413,36 +2366,36 @@ force_rtp_proxy(struct sip_msg* msg, char* str1, char* str2, int offer, LM_DBG("payload_types='%.*s'\n", payload_types.len, payload_types.s); #endif - if (sdp_stream->is_rtp && payload_types.len > 0 + if(sdp_stream->is_rtp && payload_types.len > 0 && node->rn_ptl_supported != 0) { pt_opts.oidx = 0; - if (append_opts(&pt_opts, 'c') == -1) { + if(append_opts(&pt_opts, 'c') == -1) { LM_ERR("out of pkg memory\n"); - FORCE_RTP_PROXY_RET (-1); + FORCE_RTP_PROXY_RET(-1); } /* * Convert space-separated payload types list into * a comma-separated list. */ - for (cp = payload_types.s; + for(cp = payload_types.s; cp < payload_types.s + payload_types.len; cp++) { - if (isdigit(*cp)) { - if (append_opts(&pt_opts, *cp) == -1) { + if(isdigit(*cp)) { + if(append_opts(&pt_opts, *cp) == -1) { LM_ERR("out of pkg memory\n"); - FORCE_RTP_PROXY_RET (-1); + FORCE_RTP_PROXY_RET(-1); } continue; } do { cp++; - } while (!isdigit(*cp) && - cp < payload_types.s + payload_types.len); + } while(!isdigit(*cp) + && cp < payload_types.s + payload_types.len); /* Check EOL */ - if (cp >= payload_types.s + payload_types.len) + if(cp >= payload_types.s + payload_types.len) break; - if (append_opts(&pt_opts, ',') == -1) { + if(append_opts(&pt_opts, ',') == -1) { LM_ERR("out of pkg memory\n"); - FORCE_RTP_PROXY_RET (-1); + FORCE_RTP_PROXY_RET(-1); } cp--; } @@ -2451,9 +2404,9 @@ force_rtp_proxy(struct sip_msg* msg, char* str1, char* str2, int offer, } else { v[3].iov_len = 0; } - if (to_tag.len > 0) { + if(to_tag.len > 0) { iovec_param_count = 20; - if (opts.s.s[0] == 'U' && timeout_socket_str.len > 0) { + if(opts.s.s[0] == 'U' && timeout_socket_str.len > 0) { iovec_param_count = 22; STR2IOVEC(timeout_socket_str, v[21]); } @@ -2462,32 +2415,34 @@ force_rtp_proxy(struct sip_msg* msg, char* str1, char* str2, int offer, } cp = send_rtpp_command(node, v, iovec_param_count); - } while (cp == NULL); + } while(cp == NULL); LM_DBG("proxy reply: %s\n", cp); /* Parse proxy reply to */ argc = 0; memset(argv, 0, sizeof(argv)); - cpend=cp+strlen(cp); - next=eat_token_end(cp, cpend); - for (ap=argv; cp= ((char*)argv+sizeof(argv))) + if((char *)++ap >= ((char *)argv + sizeof(argv))) break; } } - if (argc < 1) { + if(argc < 1) { LM_ERR("no reply from rtp proxy\n"); - FORCE_RTP_PROXY_RET (-1); + FORCE_RTP_PROXY_RET(-1); } port = atoi(argv[0]); - if (port <= 0 || port > 65535) { - if (port != 0 || flookup == 0) + if(port <= 0 || port > 65535) { + if(port != 0 || flookup == 0) LM_ERR("incorrect port %i in reply " - "from rtp proxy\n",port); - FORCE_RTP_PROXY_RET (-1); + "from rtp proxy\n", + port); + FORCE_RTP_PROXY_RET(-1); } /* @@ -2496,14 +2451,14 @@ force_rtp_proxy(struct sip_msg* msg, char* str1, char* str2, int offer, * the original request. * } */ - if (argc == 2) { + if(argc == 2) { /* * For historical reasons, if rtpproxy returns * bare address without AF flag, this means * IPv4. */ newip.pf = AF_INET; - } else if (argc >= 3) { + } else if(argc >= 3) { /* * When rtpproxy returns explicit address + * "AF" flag, use that. @@ -2511,8 +2466,8 @@ force_rtp_proxy(struct sip_msg* msg, char* str1, char* str2, int offer, newip.pf = (argv[2][0] == '6') ? AF_INET6 : AF_INET; } - if (isnulladdr(&oldip, pf)) { - if (newip.pf == AF_INET6) { + if(isnulladdr(&oldip, pf)) { + if(newip.pf == AF_INET6) { newip.strip.s = "::"; newip.strip.len = 2; } else { @@ -2520,7 +2475,7 @@ force_rtp_proxy(struct sip_msg* msg, char* str1, char* str2, int offer, newip.strip.len = 7; } } else { - if (forcedIP) { + if(forcedIP) { newip.strip.s = str2; newip.strip.len = strlen(newip.strip.s); #ifdef EXTRA_DEBUG @@ -2545,10 +2500,9 @@ force_rtp_proxy(struct sip_msg* msg, char* str1, char* str2, int offer, * by returning also 0 * - or by not sending to rtpproxy the old port if 0 */ - if(oldport.len!=1 || oldport.s[0]!='0') - { - if (alter_mediaport(msg, &body1, &oldport, &newport, 0) == -1) { - FORCE_RTP_PROXY_RET (-1); + if(oldport.len != 1 || oldport.s[0] != '0') { + if(alter_mediaport(msg, &body1, &oldport, &newport, 0) == -1) { + FORCE_RTP_PROXY_RET(-1); } } @@ -2560,26 +2514,30 @@ force_rtp_proxy(struct sip_msg* msg, char* str1, char* str2, int offer, * ported from ser */ - if (sdp_stream->rtcp_port.s && sdp_stream->rtcp_port.len) { - newrtcp.s = int2str(port+1, &newrtcp.len); /* beware static buffer */ + if(sdp_stream->rtcp_port.s && sdp_stream->rtcp_port.len) { + newrtcp.s = int2str( + port + 1, &newrtcp.len); /* beware static buffer */ /* Alter port. */ body1.s = sdp_stream->rtcp_port.s; body1.len = bodylimit - body1.s; #ifdef EXTRA_DEBUG LM_DBG("alter rtcp body1='%.*s'\n", body1.len, body1.s); #endif - if (alter_rtcp(msg, &body1, &sdp_stream->rtcp_port, &newrtcp) == -1) { - FORCE_RTP_PROXY_RET (-1); + if(alter_rtcp(msg, &body1, &sdp_stream->rtcp_port, &newrtcp) + == -1) { + FORCE_RTP_PROXY_RET(-1); } } /* Add ice relay candidates */ - if (ice_candidate_priority_val.n && sdp_stream->ice_attrs_num > 0) { + if(ice_candidate_priority_val.n && sdp_stream->ice_attrs_num > 0) { body1.s = sdp_stream->ice_attr->foundation.s - 12; body1.len = bodylimit - body1.s; - if (insert_candidates(msg, sdp_stream->ice_attr->foundation.s - 12, - &newip.strip, port, ice_candidate_priority_val.n) == -1) { - FORCE_RTP_PROXY_RET (-1); + if(insert_candidates(msg, + sdp_stream->ice_attr->foundation.s - 12, + &newip.strip, port, ice_candidate_priority_val.n) + == -1) { + FORCE_RTP_PROXY_RET(-1); } } @@ -2589,45 +2547,49 @@ force_rtp_proxy(struct sip_msg* msg, char* str1, char* str2, int offer, * Alter IP. Don't alter IP common for the session * more than once. */ - if (c2p != NULL || !c1p_altered) { + if(c2p != NULL || !c1p_altered) { body1.s = c2p ? c2p : c1p; body1.len = bodylimit - body1.s; #ifdef EXTRA_DEBUG LM_DBG("alter ip body1='%.*s'\n", body1.len, body1.s); #endif - if (alter_mediaip(msg, &body1, &oldip, pf, &newip.strip, newip.pf, 0)==-1) { - FORCE_RTP_PROXY_RET (-1); + if(alter_mediaip( + msg, &body1, &oldip, pf, &newip.strip, newip.pf, 0) + == -1) { + FORCE_RTP_PROXY_RET(-1); } - if (!c2p) + if(!c2p) c1p_altered = 1; } /* * Alter common IP if required, but don't do it more than once. */ - if (commip && c1p && !c1p_altered) { + if(commip && c1p && !c1p_altered) { body1.s = c1p; body1.len = bodylimit - body1.s; #ifdef EXTRA_DEBUG LM_DBG("alter common ip body1='%.*s'\n", body1.len, body1.s); #endif - if (alter_mediaip(msg, &body1, &sdp_session->ip_addr, - sdp_session->pf, &newip.strip, newip.pf, 0)==-1) { - FORCE_RTP_PROXY_RET (-1); + if(alter_mediaip(msg, &body1, &sdp_session->ip_addr, + sdp_session->pf, &newip.strip, newip.pf, 0) + == -1) { + FORCE_RTP_PROXY_RET(-1); } c1p_altered = 1; } /* * Alter the IP in "o=", but only once per session */ - if (o1p) { + if(o1p) { body1.s = o1p; body1.len = bodylimit - body1.s; #ifdef EXTRA_DEBUG LM_DBG("alter media ip body1='%.*s'\n", body1.len, body1.s); #endif - if (alter_mediaip(msg, &body1, &sdp_session->o_ip_addr, - sdp_session->o_pf, &newip.strip, newip.pf, 0)==-1) { - FORCE_RTP_PROXY_RET (-1); + if(alter_mediaip(msg, &body1, &sdp_session->o_ip_addr, + sdp_session->o_pf, &newip.strip, newip.pf, 0) + == -1) { + FORCE_RTP_PROXY_RET(-1); } o1p = 0; } @@ -2637,24 +2599,24 @@ force_rtp_proxy(struct sip_msg* msg, char* str1, char* str2, int offer, } - free_opts(&opts, &rep_opts, &pt_opts); - if (proxied == 0 && nortpproxy_str.len) { + if(proxied == 0 && nortpproxy_str.len) { cp = pkg_malloc((nortpproxy_str.len + CRLF_LEN) * sizeof(char)); - if (cp == NULL) { + if(cp == NULL) { LM_ERR("out of pkg memory\n"); return -1; } anchor = anchor_lump(msg, body.s + body.len - msg->buf, 0, 0); - if (anchor == NULL) { + if(anchor == NULL) { LM_ERR("anchor_lump failed\n"); pkg_free(cp); return -1; } memcpy(cp, CRLF, CRLF_LEN); memcpy(cp + CRLF_LEN, nortpproxy_str.s, nortpproxy_str.len); - if (insert_new_lump_after(anchor, cp, nortpproxy_str.len + CRLF_LEN, 0) == NULL) { + if(insert_new_lump_after(anchor, cp, nortpproxy_str.len + CRLF_LEN, 0) + == NULL) { LM_ERR("insert_new_lump_after failed\n"); pkg_free(cp); return -1; @@ -2665,7 +2627,7 @@ force_rtp_proxy(struct sip_msg* msg, char* str1, char* str2, int offer, } -static int ki_start_recording(sip_msg_t* msg) +static int ki_start_recording(sip_msg_t *msg) { int nitems; str callid = {0, 0}; @@ -2673,25 +2635,25 @@ static int ki_start_recording(sip_msg_t* msg) str to_tag = {0, 0}; struct rtpp_node *node; struct iovec v[1 + 4 + 3] = {{NULL, 0}, {"R", 1}, {" ", 1}, {NULL, 0}, - {" ", 1}, {NULL, 0}, {" ", 1}, {NULL, 0}}; - /* 1 */ /* 2 */ /* 3 */ /* 4 */ /* 5 */ /* 6 */ /* 1 */ + {" ", 1}, {NULL, 0}, {" ", 1}, {NULL, 0}}; + /* 1 */ /* 2 */ /* 3 */ /* 4 */ /* 5 */ /* 6 */ /* 1 */ - if (get_callid(msg, &callid) == -1 || callid.len == 0) { + if(get_callid(msg, &callid) == -1 || callid.len == 0) { LM_ERR("can't get Call-Id field\n"); return -1; } - if (get_to_tag(msg, &to_tag) == -1) { + if(get_to_tag(msg, &to_tag) == -1) { LM_ERR("can't get To tag\n"); return -1; } - if (get_from_tag(msg, &from_tag) == -1 || from_tag.len == 0) { + if(get_from_tag(msg, &from_tag) == -1 || from_tag.len == 0) { LM_ERR("can't get From tag\n"); return -1; } - if(msg->id != current_msg_id){ + if(msg->id != current_msg_id) { selected_rtpp_set = default_rtpp_set; } @@ -2699,22 +2661,22 @@ static int ki_start_recording(sip_msg_t* msg) STR2IOVEC(from_tag, v[5]); STR2IOVEC(to_tag, v[7]); node = select_rtpp_node(callid, 1); - if (!node) { + if(!node) { LM_ERR("no available proxies\n"); return -1; } set_rtp_inst_pvar(msg, &node->rn_url); nitems = 8; - if (msg->first_line.type == SIP_REPLY) { - if (to_tag.len == 0) + if(msg->first_line.type == SIP_REPLY) { + if(to_tag.len == 0) return -1; STR2IOVEC(to_tag, v[5]); STR2IOVEC(from_tag, v[7]); } else { STR2IOVEC(from_tag, v[5]); STR2IOVEC(to_tag, v[7]); - if (to_tag.len <= 0) + if(to_tag.len <= 0) nitems = 6; } send_rtpp_command(node, v, nitems); @@ -2722,7 +2684,7 @@ static int ki_start_recording(sip_msg_t* msg) return 1; } -static int start_recording_f(struct sip_msg* msg, char *foo, char *bar) +static int start_recording_f(struct sip_msg *msg, char *foo, char *bar) { return ki_start_recording(msg); } @@ -2730,9 +2692,8 @@ static int start_recording_f(struct sip_msg* msg, char *foo, char *bar) /* * Returns the current RTP-Statistics from the RTP-Proxy */ - static int -pv_get_rtppstat_f(struct sip_msg *msg, pv_param_t *param, - pv_value_t *res) +static int pv_get_rtppstat_f( + struct sip_msg *msg, pv_param_t *param, pv_value_t *res) { str ret_val = {0, 0}; int nitems; @@ -2741,21 +2702,25 @@ pv_get_rtppstat_f(struct sip_msg *msg, pv_param_t *param, str to_tag = {0, 0}; struct rtpp_node *node; struct iovec v[1 + 4 + 3 + 1] = {{NULL, 0}, {"Q", 1}, {" ", 1}, {NULL, 0}, - {" ", 1}, {NULL, 0}, {";1 ", 3}, {";1", }, {NULL, 0}}; + {" ", 1}, {NULL, 0}, {";1 ", 3}, + { + ";1", + }, + {NULL, 0}}; - if (get_callid(msg, &callid) == -1 || callid.len == 0) { + if(get_callid(msg, &callid) == -1 || callid.len == 0) { LM_ERR("can't get Call-Id field\n"); return pv_get_null(msg, param, res); } - if (get_to_tag(msg, &to_tag) == -1) { + if(get_to_tag(msg, &to_tag) == -1) { LM_ERR("can't get To tag\n"); return pv_get_null(msg, param, res); } - if (get_from_tag(msg, &from_tag) == -1 || from_tag.len == 0) { + if(get_from_tag(msg, &from_tag) == -1 || from_tag.len == 0) { LM_ERR("can't get From tag\n"); return pv_get_null(msg, param, res); } - if(msg->id != current_msg_id){ + if(msg->id != current_msg_id) { selected_rtpp_set = default_rtpp_set; } @@ -2763,42 +2728,42 @@ pv_get_rtppstat_f(struct sip_msg *msg, pv_param_t *param, STR2IOVEC(from_tag, v[5]); STR2IOVEC(to_tag, v[7]); node = select_rtpp_node(callid, 1); - if (!node) { + if(!node) { LM_ERR("no available proxies\n"); return -1; } set_rtp_inst_pvar(msg, &node->rn_url); nitems = 8; - if (msg->first_line.type == SIP_REPLY) { - if (to_tag.len == 0) + if(msg->first_line.type == SIP_REPLY) { + if(to_tag.len == 0) return -1; STR2IOVEC(to_tag, v[5]); STR2IOVEC(from_tag, v[7]); } else { STR2IOVEC(from_tag, v[5]); STR2IOVEC(to_tag, v[7]); - if (to_tag.len <= 0) + if(to_tag.len <= 0) nitems = 6; } ret_val.s = send_rtpp_command(node, v, nitems); - if(ret_val.s==NULL) + if(ret_val.s == NULL) return pv_get_null(msg, param, res); ret_val.len = strlen(ret_val.s); return pv_get_strval(msg, param, res, &ret_val); } -int set_rtp_inst_pvar(struct sip_msg *msg, const str * const uri) { +int set_rtp_inst_pvar(struct sip_msg *msg, const str *const uri) +{ pv_value_t val; - if (rtp_inst_pvar == NULL) + if(rtp_inst_pvar == NULL) return 0; memset(&val, 0, sizeof(pv_value_t)); val.flags = PV_VAL_STR; val.rs = *uri; - if (rtp_inst_pvar->setf(msg, &rtp_inst_pvar->pvp, (int)EQ_T, &val) < 0) - { + if(rtp_inst_pvar->setf(msg, &rtp_inst_pvar->pvp, (int)EQ_T, &val) < 0) { LM_ERR("Failed to add RTPProxy URI to pvar\n"); return -1; } @@ -2818,7 +2783,8 @@ static int ki_rtpproxy_manage0(sip_msg_t *msg) */ static int ki_rtpproxy_manage(sip_msg_t *msg, str *flags) { - return rtpproxy_manage(msg, ((flags && flags->len>0)?flags->s:NULL), NULL); + return rtpproxy_manage( + msg, ((flags && flags->len > 0) ? flags->s : NULL), NULL); } /** @@ -2827,14 +2793,14 @@ static int ki_rtpproxy_manage(sip_msg_t *msg, str *flags) static int ki_rtpproxy_manage_ip(sip_msg_t *msg, str *flags, str *mip) { /* str->s from kemi params is zero-terminated */ - return rtpproxy_manage(msg, ((flags && flags->len>0)?flags->s:NULL), - ((mip && mip->len>0)?mip->s:NULL)); + return rtpproxy_manage(msg, ((flags && flags->len > 0) ? flags->s : NULL), + ((mip && mip->len > 0) ? mip->s : NULL)); } static int ki_set_rtp_proxy_set(sip_msg_t *msg, int rset) { selected_rtpp_set = select_rtpp_set(rset); - if(selected_rtpp_set==NULL) { + if(selected_rtpp_set == NULL) { LM_ERR("could not locate rtpproxy set %d\n", rset); return -1; } @@ -2849,7 +2815,7 @@ static int ki_rtpproxy_destroy0(sip_msg_t *msg) static int ki_rtpproxy_destroy(sip_msg_t *msg, str *flags) { - if(flags==NULL || flags->len<=0) + if(flags == NULL || flags->len <= 0) return unforce_rtp_proxy(msg, NULL); return unforce_rtp_proxy(msg, flags->s); } @@ -2861,7 +2827,7 @@ static int ki_rtpproxy_offer0(sip_msg_t *msg) static int ki_rtpproxy_offer(sip_msg_t *msg, str *flags) { - if(flags==NULL || flags->len<=0) + if(flags == NULL || flags->len <= 0) return rtpproxy_offer1_helper_f(msg, NULL); return rtpproxy_offer1_helper_f(msg, flags->s); } @@ -2878,7 +2844,7 @@ static int ki_rtpproxy_answer0(sip_msg_t *msg) static int ki_rtpproxy_answer(sip_msg_t *msg, str *flags) { - if(flags==NULL || flags->len<=0) + if(flags == NULL || flags->len <= 0) return rtpproxy_answer1_helper_f(msg, NULL); return rtpproxy_answer1_helper_f(msg, flags->s); } @@ -2888,12 +2854,12 @@ static int ki_rtpproxy_answer_ip(sip_msg_t *msg, str *flags, str *mip) return force_rtp_proxy(msg, flags->s, mip->s, 0, 1); } -static int ki_rtpproxy_stream2uac(sip_msg_t* msg, str* pname, int count) +static int ki_rtpproxy_stream2uac(sip_msg_t *msg, str *pname, int count) { return rtpproxy_stream(msg, pname, count, 1); } -static int ki_rtpproxy_stream2uas(sip_msg_t* msg, str* pname, int count) +static int ki_rtpproxy_stream2uas(sip_msg_t *msg, str *pname, int count) { return rtpproxy_stream(msg, pname, count, 0); } @@ -2903,7 +2869,7 @@ static int ki_rtpproxy_stop_stream2uac(sip_msg_t *msg) return rtpproxy_stop_stream(msg, 1); } -static int ki_rtpproxy_stop_stream2uas(sip_msg_t* msg) +static int ki_rtpproxy_stop_stream2uas(sip_msg_t *msg) { return rtpproxy_stop_stream(msg, 0); } diff --git a/src/modules/rtpproxy/rtpproxy.h b/src/modules/rtpproxy/rtpproxy.h index 8e16cc97559..a69c64093e3 100644 --- a/src/modules/rtpproxy/rtpproxy.h +++ b/src/modules/rtpproxy/rtpproxy.h @@ -28,38 +28,49 @@ #include "../../core/str.h" /* Handy macros */ -#define STR2IOVEC(sx, ix) do {(ix).iov_base = (sx).s; (ix).iov_len = (sx).len;} while(0) -#define SZ2IOVEC(sx, ix) do {(ix).iov_base = (sx); (ix).iov_len = strlen(sx);} while(0) +#define STR2IOVEC(sx, ix) \ + do { \ + (ix).iov_base = (sx).s; \ + (ix).iov_len = (sx).len; \ + } while(0) +#define SZ2IOVEC(sx, ix) \ + do { \ + (ix).iov_base = (sx); \ + (ix).iov_len = strlen(sx); \ + } while(0) -struct rtpp_node { - unsigned int idx; /* overall index */ - str rn_url; /* unparsed, deletable */ - int rn_umode; - char *rn_address; /* substring of rn_url */ - int rn_disabled; /* found unaccessible? */ - unsigned rn_weight; /* for load balancing */ - unsigned int rn_recheck_ticks; - int rn_rep_supported; - int rn_ptl_supported; - struct rtpp_node *rn_next; +struct rtpp_node +{ + unsigned int idx; /* overall index */ + str rn_url; /* unparsed, deletable */ + int rn_umode; + char *rn_address; /* substring of rn_url */ + int rn_disabled; /* found unaccessible? */ + unsigned rn_weight; /* for load balancing */ + unsigned int rn_recheck_ticks; + int rn_rep_supported; + int rn_ptl_supported; + struct rtpp_node *rn_next; }; -struct rtpp_set{ - unsigned int id_set; - unsigned weight_sum; - unsigned int rtpp_node_count; - int set_disabled; - unsigned int set_recheck_ticks; - struct rtpp_node *rn_first; - struct rtpp_node *rn_last; - struct rtpp_set *rset_next; +struct rtpp_set +{ + unsigned int id_set; + unsigned weight_sum; + unsigned int rtpp_node_count; + int set_disabled; + unsigned int set_recheck_ticks; + struct rtpp_node *rn_first; + struct rtpp_node *rn_last; + struct rtpp_set *rset_next; }; -struct rtpp_set_head{ - struct rtpp_set *rset_first; - struct rtpp_set *rset_last; +struct rtpp_set_head +{ + struct rtpp_set *rset_first; + struct rtpp_set *rset_last; }; /* Functions from nathelper */ @@ -70,7 +81,7 @@ struct rtpp_set *get_rtpp_set(str *set_name); int insert_rtpp_node(struct rtpp_set *const rtpp_list, const str *const url, const int weight, const int disabled); -int set_rtp_inst_pvar(struct sip_msg *msg, const str * const uri); +int set_rtp_inst_pvar(struct sip_msg *msg, const str *const uri); int init_rtpproxy_db(void); diff --git a/src/modules/rtpproxy/rtpproxy_db.c b/src/modules/rtpproxy/rtpproxy_db.c index ea48ec5c310..eb2e12bc515 100644 --- a/src/modules/rtpproxy/rtpproxy_db.c +++ b/src/modules/rtpproxy/rtpproxy_db.c @@ -41,10 +41,9 @@ str rtpp_flags_col = str_init("flags"); static int rtpp_connect_db(void) { - if ((rtpp_db_url.s == NULL) || (rtpp_db_url.len == 0)) + if((rtpp_db_url.s == NULL) || (rtpp_db_url.len == 0)) return -1; - if ((rtpp_db_handle = rtpp_dbf.init(&rtpp_db_url)) == NULL) - { + if((rtpp_db_handle = rtpp_dbf.init(&rtpp_db_url)) == NULL) { LM_ERR("Cannot initialize db connection\n"); return -1; } @@ -53,8 +52,7 @@ static int rtpp_connect_db(void) static void rtpp_disconnect_db(void) { - if (rtpp_db_handle) - { + if(rtpp_db_handle) { rtpp_dbf.close(rtpp_db_handle); rtpp_db_handle = NULL; } @@ -67,56 +65,50 @@ static int rtpp_load_db(void) db1_res_t *res = NULL; db_val_t *values = NULL; db_row_t *rows = NULL; - db_key_t query_cols[] = {&rtpp_setid_col, &rtpp_url_col, &rtpp_weight_col, - &rtpp_flags_col}; + db_key_t query_cols[] = { + &rtpp_setid_col, &rtpp_url_col, &rtpp_weight_col, &rtpp_flags_col}; str set, url; int weight, flags; int n_rows = 0; int n_cols = 4; - if (rtpp_db_handle == NULL) - { + if(rtpp_db_handle == NULL) { LM_ERR("invalid db handle\n"); return -1; } - if (rtpp_dbf.use_table(rtpp_db_handle, &rtpp_table_name) < 0) - { + if(rtpp_dbf.use_table(rtpp_db_handle, &rtpp_table_name) < 0) { LM_ERR("unable to use table '%.*s'\n", rtpp_table_name.len, rtpp_table_name.s); return -1; } - if (rtpp_dbf.query(rtpp_db_handle, 0, 0, 0, query_cols, 0, n_cols, 0, &res) < 0) - { + if(rtpp_dbf.query(rtpp_db_handle, 0, 0, 0, query_cols, 0, n_cols, 0, &res) + < 0) { LM_ERR("error while running db query\n"); return -1; } n_rows = RES_ROW_N(res); rows = RES_ROWS(res); - if (n_rows == 0) - { + if(n_rows == 0) { LM_WARN("No rtpproxy instances in database\n"); return 0; } - for (i=0; i(_str).s+(_str).len)\ - goto _error;\ - (_ptr) = (_ptr) + (_n);\ - }while(0); -#define one_of_16( _x , _t ) \ - (_x==_t[0]||_x==_t[15]||_x==_t[8]||_x==_t[2]||_x==_t[3]||_x==_t[4]\ - ||_x==_t[5]||_x==_t[6]||_x==_t[7]||_x==_t[1]||_x==_t[9]||_x==_t[10]\ - ||_x==_t[11]||_x==_t[12]||_x==_t[13]||_x==_t[14]) -#define one_of_8( _x , _t ) \ - (_x==_t[0]||_x==_t[7]||_x==_t[1]||_x==_t[2]||_x==_t[3]||_x==_t[4]\ - ||_x==_t[5]||_x==_t[6]) - +#define advance(_ptr, _n, _str, _error) \ + do { \ + if((_ptr) + (_n) > (_str).s + (_str).len) \ + goto _error; \ + (_ptr) = (_ptr) + (_n); \ + } while(0); +#define one_of_16(_x, _t) \ + (_x == _t[0] || _x == _t[15] || _x == _t[8] || _x == _t[2] || _x == _t[3] \ + || _x == _t[4] || _x == _t[5] || _x == _t[6] || _x == _t[7] \ + || _x == _t[1] || _x == _t[9] || _x == _t[10] || _x == _t[11] \ + || _x == _t[12] || _x == _t[13] || _x == _t[14]) +#define one_of_8(_x, _t) \ + (_x == _t[0] || _x == _t[7] || _x == _t[1] || _x == _t[2] || _x == _t[3] \ + || _x == _t[4] || _x == _t[5] || _x == _t[6]) /** @@ -67,77 +67,72 @@ */ int check_content_type(struct sip_msg *msg) { - static unsigned int appl[16] = { - 0x6c707061/*appl*/,0x6c707041/*Appl*/,0x6c705061/*aPpl*/, - 0x6c705041/*APpl*/,0x6c507061/*apPl*/,0x6c507041/*ApPl*/, - 0x6c505061/*aPPl*/,0x6c505041/*APPl*/,0x4c707061/*appL*/, - 0x4c707041/*AppL*/,0x4c705061/*aPpL*/,0x4c705041/*APpL*/, - 0x4c507061/*apPL*/,0x4c507041/*ApPL*/,0x4c505061/*aPPL*/, - 0x4c505041/*APPL*/}; - static unsigned int icat[16] = { - 0x74616369/*icat*/,0x74616349/*Icat*/,0x74614369/*iCat*/, - 0x74614349/*ICat*/,0x74416369/*icAt*/,0x74416349/*IcAt*/, - 0x74414369/*iCAt*/,0x74414349/*ICAt*/,0x54616369/*icaT*/, - 0x54616349/*IcaT*/,0x54614369/*iCaT*/,0x54614349/*ICaT*/, - 0x54416369/*icAT*/,0x54416349/*IcAT*/,0x54414369/*iCAT*/, - 0x54414349/*ICAT*/}; - static unsigned int ion_[8] = { - 0x006e6f69/*ion_*/,0x006e6f49/*Ion_*/,0x006e4f69/*iOn_*/, - 0x006e4f49/*IOn_*/,0x004e6f69/*ioN_*/,0x004e6f49/*IoN_*/, - 0x004e4f69/*iON_*/,0x004e4f49/*ION_*/}; - static unsigned int sdp_[8] = { - 0x00706473/*sdp_*/,0x00706453/*Sdp_*/,0x00704473/*sDp_*/, - 0x00704453/*SDp_*/,0x00506473/*sdP_*/,0x00506453/*SdP_*/, - 0x00504473/*sDP_*/,0x00504453/*SDP_*/}; - str str_type; - unsigned int x; - char *p; - - if (!msg->content_type) - { + static unsigned int appl[16] = {0x6c707061 /*appl*/, 0x6c707041 /*Appl*/, + 0x6c705061 /*aPpl*/, 0x6c705041 /*APpl*/, 0x6c507061 /*apPl*/, + 0x6c507041 /*ApPl*/, 0x6c505061 /*aPPl*/, 0x6c505041 /*APPl*/, + 0x4c707061 /*appL*/, 0x4c707041 /*AppL*/, 0x4c705061 /*aPpL*/, + 0x4c705041 /*APpL*/, 0x4c507061 /*apPL*/, 0x4c507041 /*ApPL*/, + 0x4c505061 /*aPPL*/, 0x4c505041 /*APPL*/}; + static unsigned int icat[16] = {0x74616369 /*icat*/, 0x74616349 /*Icat*/, + 0x74614369 /*iCat*/, 0x74614349 /*ICat*/, 0x74416369 /*icAt*/, + 0x74416349 /*IcAt*/, 0x74414369 /*iCAt*/, 0x74414349 /*ICAt*/, + 0x54616369 /*icaT*/, 0x54616349 /*IcaT*/, 0x54614369 /*iCaT*/, + 0x54614349 /*ICaT*/, 0x54416369 /*icAT*/, 0x54416349 /*IcAT*/, + 0x54414369 /*iCAT*/, 0x54414349 /*ICAT*/}; + static unsigned int ion_[8] = {0x006e6f69 /*ion_*/, 0x006e6f49 /*Ion_*/, + 0x006e4f69 /*iOn_*/, 0x006e4f49 /*IOn_*/, 0x004e6f69 /*ioN_*/, + 0x004e6f49 /*IoN_*/, 0x004e4f69 /*iON_*/, 0x004e4f49 /*ION_*/}; + static unsigned int sdp_[8] = {0x00706473 /*sdp_*/, 0x00706453 /*Sdp_*/, + 0x00704473 /*sDp_*/, 0x00704453 /*SDp_*/, 0x00506473 /*sdP_*/, + 0x00506453 /*SdP_*/, 0x00504473 /*sDP_*/, 0x00504453 /*SDP_*/}; + str str_type; + unsigned int x; + char *p; + + if(!msg->content_type) { LM_WARN("the header Content-TYPE is absent!" "let's assume the content is text/plain ;-)\n"); return 1; } - trim_len(str_type.len,str_type.s,msg->content_type->body); - if (str_type.len>=15 && (*str_type.s=='m' || *str_type.s=='M') + trim_len(str_type.len, str_type.s, msg->content_type->body); + if(str_type.len >= 15 && (*str_type.s == 'm' || *str_type.s == 'M') && strncasecmp(str_type.s, "multipart/mixed", 15) == 0) { return 2; } p = str_type.s; - advance(p,4,str_type,error_1); - x = READ(p-4); - if (!one_of_16(x,appl)) + advance(p, 4, str_type, error_1); + x = READ(p - 4); + if(!one_of_16(x, appl)) goto other; - advance(p,4,str_type,error_1); - x = READ(p-4); - if (!one_of_16(x,icat)) + advance(p, 4, str_type, error_1); + x = READ(p - 4); + if(!one_of_16(x, icat)) goto other; - advance(p,3,str_type,error_1); - x = READ(p-3) & 0x00ffffff; - if (!one_of_8(x,ion_)) + advance(p, 3, str_type, error_1); + x = READ(p - 3) & 0x00ffffff; + if(!one_of_8(x, ion_)) goto other; /* skip spaces and tabs if any */ - while (*p==' ' || *p=='\t') - advance(p,1,str_type,error_1); - if (*p!='/') - { + while(*p == ' ' || *p == '\t') + advance(p, 1, str_type, error_1); + if(*p != '/') { LM_ERR("no / found after primary type\n"); goto error; } - advance(p,1,str_type,error_1); - while ((*p==' ' || *p=='\t') && p+1 found valid\n", (int)(p-str_type.s), str_type.s); + if(*p == ';' || *p == ' ' || *p == '\t' || *p == '\n' || *p == '\r' + || *p == 0) { + LM_DBG("type <%.*s> found valid\n", (int)(p - str_type.s), str_type.s); return 1; } else { LM_ERR("bad end for type!\n"); @@ -157,7 +152,7 @@ int check_content_type(struct sip_msg *msg) /* * Get message body and check Content-Type header field */ -int extract_body(struct sip_msg *msg, str *body ) +int extract_body(struct sip_msg *msg, str *body) { char c; int skip; @@ -168,7 +163,7 @@ int extract_body(struct sip_msg *msg, str *body ) unsigned int mime; body->s = get_body(msg); - if (body->s==0) { + if(body->s == 0) { LM_ERR("failed to get the message body\n"); goto error; } @@ -178,18 +173,18 @@ int extract_body(struct sip_msg *msg, str *body ) * parcing as get_body() parsed all headers and Conten-Length * body header is automaticaly parsed when found. */ - if (msg->content_length==0) { + if(msg->content_length == 0) { LM_ERR("failed to get the content length in message\n"); goto error; } body->len = get_content_length(msg); - if (body->len==0) { + if(body->len == 0) { LM_ERR("message body has length zero\n"); goto error; } - if (body->len + body->s > msg->buf + msg->len) { + if(body->len + body->s > msg->buf + msg->len) { LM_ERR("content-length exceeds packet-length by %d\n", (int)((body->len + body->s) - (msg->buf + msg->len))); goto error; @@ -198,60 +193,57 @@ int extract_body(struct sip_msg *msg, str *body ) /* no need for parse_headers(msg, EOH), get_body will * parse everything */ /*is the content type correct?*/ - if((ret = check_content_type(msg))==-1) - { + if((ret = check_content_type(msg)) == -1) { LM_ERR("content type mismatching\n"); goto error; } - if(ret!=2) + if(ret != 2) goto done; /* multipart body */ - if(get_mixed_part_delimiter(&msg->content_type->body,&mpdel) < 0) { + if(get_mixed_part_delimiter(&msg->content_type->body, &mpdel) < 0) { goto error; } - p1 = find_sdp_line_delimiter(body->s, body->s+body->len, mpdel); - if (p1 == NULL) { + p1 = find_sdp_line_delimiter(body->s, body->s + body->len, mpdel); + if(p1 == NULL) { LM_ERR("empty multipart content\n"); return -1; } - p2=p1; + p2 = p1; c = 0; - for(;;) - { + for(;;) { p1 = p2; - if (p1 == NULL || p1 >= body->s+body->len) + if(p1 == NULL || p1 >= body->s + body->len) break; /* No parts left */ - p2 = find_next_sdp_line_delimiter(p1, body->s+body->len, - mpdel, body->s+body->len); + p2 = find_next_sdp_line_delimiter( + p1, body->s + body->len, mpdel, body->s + body->len); /* p2 is text limit for application parsing */ rest = eat_line(p1 + mpdel.len + 2, p2 - p1 - mpdel.len - 2); - if ( rest > p2 ) { - LM_ERR("Unparsable <%.*s>\n", (int)(p2-p1), p1); + if(rest > p2) { + LM_ERR("Unparsable <%.*s>\n", (int)(p2 - p1), p1); return -1; } - while( rest>16) == TYPE_APPLICATION) - && ((mime&0x00ff) == SUBTYPE_SDP)) { + if(((((unsigned int)mime) >> 16) == TYPE_APPLICATION) + && ((mime & 0x00ff) == SUBTYPE_SDP)) { c = 1; } } } /* end of while */ - if(c==1) - { + if(c == 1) { body->s = rest; - body->len = p2-rest; + body->len = p2 - rest; goto done; } } @@ -260,12 +252,12 @@ int extract_body(struct sip_msg *msg, str *body ) return -1; done: - for (skip = 0; skip < body->len; skip++) { + for(skip = 0; skip < body->len; skip++) { c = body->s[body->len - skip - 1]; - if (c != '\r' && c != '\n') + if(c != '\r' && c != '\n') break; } - if (skip == body->len) { + if(skip == body->len) { LM_ERR("empty body"); goto error; } @@ -280,14 +272,13 @@ int extract_body(struct sip_msg *msg, str *body ) * pattern b2 of size len2 in memory block b1 of size len1 or * NULL if none is found. Obtained from NetBSD. */ - void * -ser_memmem(const void *b1, const void *b2, size_t len1, size_t len2) +void *ser_memmem(const void *b1, const void *b2, size_t len1, size_t len2) { /* Initialize search pointer */ - char *sp = (char *) b1; + char *sp = (char *)b1; /* Initialize pattern pointer */ - char *pp = (char *) b2; + char *pp = (char *)b2; /* Initialize end of search address space pointer */ char *eos = sp + len1 - len2; @@ -296,9 +287,9 @@ ser_memmem(const void *b1, const void *b2, size_t len1, size_t len2) if(!(b1 && b2 && len1 && len2)) return NULL; - while (sp <= eos) { - if (*sp == *pp) - if (memcmp(sp, pp, len2) == 0) + while(sp <= eos) { + if(*sp == *pp) + if(memcmp(sp, pp, len2) == 0) return sp; sp++; @@ -317,16 +308,15 @@ ser_memmem(const void *b1, const void *b2, size_t len1, size_t len2) * (so make sure it is, before calling this function or * it might fail even if the message _has_ a callid) */ - int -get_callid(struct sip_msg* _m, str* _cid) +int get_callid(struct sip_msg *_m, str *_cid) { - if ((parse_headers(_m, HDR_CALLID_F, 0) == -1)) { + if((parse_headers(_m, HDR_CALLID_F, 0) == -1)) { LM_ERR("failed to parse call-id header\n"); return -1; } - if (_m->callid == NULL) { + if(_m->callid == NULL) { LM_ERR("call-id not found\n"); return -1; } @@ -342,16 +332,15 @@ get_callid(struct sip_msg* _m, str* _cid) * assumes the to header is already parsed, so * make sure it really is before calling this function */ - int -get_to_tag(struct sip_msg* _m, str* _tag) +int get_to_tag(struct sip_msg *_m, str *_tag) { - if (!_m->to) { + if(!_m->to) { LM_ERR("To header field missing\n"); return -1; } - if (get_to(_m)->tag_value.len) { + if(get_to(_m)->tag_value.len) { _tag->s = get_to(_m)->tag_value.s; _tag->len = get_to(_m)->tag_value.len; } else { @@ -365,16 +354,15 @@ get_to_tag(struct sip_msg* _m, str* _tag) /* * Extract tag from From header field of a request */ - int -get_from_tag(struct sip_msg* _m, str* _tag) +int get_from_tag(struct sip_msg *_m, str *_tag) { - if (parse_from_header(_m)<0) { + if(parse_from_header(_m) < 0) { LM_ERR("failed to parse From header\n"); return -1; } - if (get_from(_m)->tag_value.len) { + if(get_from(_m)->tag_value.len) { _tag->s = get_from(_m)->tag_value.s; _tag->len = get_from(_m)->tag_value.len; } else { @@ -388,24 +376,23 @@ get_from_tag(struct sip_msg* _m, str* _tag) /* * Extract URI from the Contact header field */ - int -get_contact_uri(struct sip_msg* _m, struct sip_uri *uri, contact_t** _c) +int get_contact_uri(struct sip_msg *_m, struct sip_uri *uri, contact_t **_c) { - if ((parse_headers(_m, HDR_CONTACT_F, 0) == -1) || !_m->contact) + if((parse_headers(_m, HDR_CONTACT_F, 0) == -1) || !_m->contact) return -1; - if (!_m->contact->parsed && parse_contact(_m->contact) < 0) { + if(!_m->contact->parsed && parse_contact(_m->contact) < 0) { LM_ERR("failed to parse Contact body\n"); return -1; } - *_c = ((contact_body_t*)_m->contact->parsed)->contacts; - if (*_c == NULL) + *_c = ((contact_body_t *)_m->contact->parsed)->contacts; + if(*_c == NULL) /* no contacts found */ return -1; - if (parse_uri((*_c)->uri.s, (*_c)->uri.len, uri) < 0 || uri->host.len <= 0) { - LM_ERR("failed to parse Contact URI [%.*s]\n", - (*_c)->uri.len, ((*_c)->uri.s)?(*_c)->uri.s:""); + if(parse_uri((*_c)->uri.s, (*_c)->uri.len, uri) < 0 || uri->host.len <= 0) { + LM_ERR("failed to parse Contact URI [%.*s]\n", (*_c)->uri.len, + ((*_c)->uri.s) ? (*_c)->uri.s : ""); return -1; } return 0; @@ -414,18 +401,16 @@ get_contact_uri(struct sip_msg* _m, struct sip_uri *uri, contact_t** _c) /* * Extract branch from Via header */ - int -get_via_branch(struct sip_msg* msg, int vianum, str* _branch) +int get_via_branch(struct sip_msg *msg, int vianum, str *_branch) { struct via_body *via; struct via_param *p; - if (parse_via_header(msg, vianum, &via) < 0) + if(parse_via_header(msg, vianum, &via) < 0) return -1; - for (p = via->param_lst; p; p = p->next) - { - if (p->name.len == strlen("branch") + for(p = via->param_lst; p; p = p->next) { + if(p->name.len == strlen("branch") && strncasecmp(p->name.s, "branch", strlen("branch")) == 0) { _branch->s = p->value.s; _branch->len = p->value.len; diff --git a/src/modules/rtpproxy/rtpproxy_funcs.h b/src/modules/rtpproxy/rtpproxy_funcs.h index 4c95d9534d3..98bb70e6d01 100644 --- a/src/modules/rtpproxy/rtpproxy_funcs.h +++ b/src/modules/rtpproxy/rtpproxy_funcs.h @@ -26,8 +26,8 @@ #include "../../core/parser/msg_parser.h" #include "../../core/parser/contact/contact.h" -int extract_body(struct sip_msg * , str *); -int check_content_type(struct sip_msg * ); +int extract_body(struct sip_msg *, str *); +int check_content_type(struct sip_msg *); void *ser_memmem(const void *, const void *, size_t, size_t); int get_callid(struct sip_msg *, str *); int get_to_tag(struct sip_msg *, str *); diff --git a/src/modules/rtpproxy/rtpproxy_stream.c b/src/modules/rtpproxy/rtpproxy_stream.c index c20074f4e62..e4a19a8b6b2 100644 --- a/src/modules/rtpproxy/rtpproxy_stream.c +++ b/src/modules/rtpproxy/rtpproxy_stream.c @@ -34,33 +34,32 @@ #include "rtpproxy.h" #include "rtpproxy_funcs.h" - int -fixup_var_str_int(void **param, int param_no) +int fixup_var_str_int(void **param, int param_no) { int ret; pv_elem_t *model; str s; - if (param_no == 1) { + if(param_no == 1) { model = NULL; s.s = (char *)(*param); s.len = strlen(s.s); - if (pv_parse_format(&s, &model) < 0) { + if(pv_parse_format(&s, &model) < 0) { LM_ERR("wrong format[%s]!\n", (char *)(*param)); return E_UNSPEC; } - if (model == NULL) { + if(model == NULL) { LM_ERR("empty parameter!\n"); return E_UNSPEC; } *param = (void *)model; - } else if (param_no == 2) { + } else if(param_no == 2) { /* According to * http://www.kamailio.org/docs/modules/1.5.x/nathelper.html#rtpproxy_stream2xxx * this could be -1 */ s.s = (char *)(*param); s.len = strlen(s.s); - if (str2sint(&s, &ret)==0) { + if(str2sint(&s, &ret) == 0) { pkg_free(*param); *param = (void *)(long)ret; } else { @@ -71,36 +70,28 @@ fixup_var_str_int(void **param, int param_no) return 0; } - int -rtpproxy_stream(struct sip_msg* msg, str *pname, int count, int stream2uac) +int rtpproxy_stream(struct sip_msg *msg, str *pname, int count, int stream2uac) { int nitems; str callid, from_tag, to_tag; struct rtpp_node *node; char cbuf[16]; - struct iovec v[] = { - {NULL, 0}, - {cbuf, 0}, /* 1 P */ - {" ", 1}, - {NULL, 0}, /* 3 callid */ - {" ", 1}, - {NULL, 0}, /* 5 pname */ - {" session ", 9}, - {NULL, 0}, /* 7 from tag */ - {";1 ", 3}, - {NULL, 0}, /* 9 to tag */ - {";1", 2} - }; - - if (get_callid(msg, &callid) == -1 || callid.len == 0) { + struct iovec v[] = {{NULL, 0}, {cbuf, 0}, /* 1 P */ + {" ", 1}, {NULL, 0}, /* 3 callid */ + {" ", 1}, {NULL, 0}, /* 5 pname */ + {" session ", 9}, {NULL, 0}, /* 7 from tag */ + {";1 ", 3}, {NULL, 0}, /* 9 to tag */ + {";1", 2}}; + + if(get_callid(msg, &callid) == -1 || callid.len == 0) { LM_ERR("can't get Call-Id field\n"); return -1; } - if (get_to_tag(msg, &to_tag) == -1) { + if(get_to_tag(msg, &to_tag) == -1) { LM_ERR("can't get To tag\n"); return -1; } - if (get_from_tag(msg, &from_tag) == -1 || from_tag.len == 0) { + if(get_from_tag(msg, &from_tag) == -1 || from_tag.len == 0) { LM_ERR("can't get From tag\n"); return -1; } @@ -108,27 +99,28 @@ rtpproxy_stream(struct sip_msg* msg, str *pname, int count, int stream2uac) STR2IOVEC(callid, v[3]); STR2IOVEC(*pname, v[5]); node = select_rtpp_node(callid, 1); - if (!node) { + if(!node) { LM_ERR("no available proxies\n"); return -1; } - if (node->rn_ptl_supported == 0) { + if(node->rn_ptl_supported == 0) { LM_ERR("required functionality is not " - "supported by the version of the RTPproxy running on the selected " - "node. Please upgrade the RTPproxy and try again.\n"); + "supported by the version of the RTPproxy running on the " + "selected " + "node. Please upgrade the RTPproxy and try again.\n"); return -1; } set_rtp_inst_pvar(msg, &node->rn_url); nitems = 11; - if (stream2uac == 0) { - if (to_tag.len == 0) + if(stream2uac == 0) { + if(to_tag.len == 0) return -1; STR2IOVEC(to_tag, v[7]); STR2IOVEC(from_tag, v[9]); } else { STR2IOVEC(from_tag, v[7]); STR2IOVEC(to_tag, v[9]); - if (to_tag.len <= 0) + if(to_tag.len <= 0) nitems -= 2; } send_rtpp_command(node, v, nitems); @@ -136,83 +128,75 @@ rtpproxy_stream(struct sip_msg* msg, str *pname, int count, int stream2uac) return 1; } - static int -rtpproxy_stream2_f(struct sip_msg *msg, char *str1, int count, int stream2uac) +static int rtpproxy_stream2_f( + struct sip_msg *msg, char *str1, int count, int stream2uac) { str pname; - if (str1 == NULL || pv_printf_s(msg, (pv_elem_p)str1, &pname) != 0) + if(str1 == NULL || pv_printf_s(msg, (pv_elem_p)str1, &pname) != 0) return -1; return rtpproxy_stream(msg, &pname, count, stream2uac); } - int -rtpproxy_stream2uac2_f(struct sip_msg* msg, char* str1, char* str2) +int rtpproxy_stream2uac2_f(struct sip_msg *msg, char *str1, char *str2) { return rtpproxy_stream2_f(msg, str1, (int)(long)str2, 1); } - int -rtpproxy_stream2uas2_f(struct sip_msg* msg, char* str1, char* str2) +int rtpproxy_stream2uas2_f(struct sip_msg *msg, char *str1, char *str2) { return rtpproxy_stream2_f(msg, str1, (int)(long)str2, 0); } - int -rtpproxy_stop_stream(struct sip_msg* msg, int stream2uac) +int rtpproxy_stop_stream(struct sip_msg *msg, int stream2uac) { int nitems; str callid, from_tag, to_tag; struct rtpp_node *node; - struct iovec v[] = { - {NULL, 0}, - {"S", 1}, /* 1 */ - {" ", 1}, - {NULL, 0}, /* 3 callid */ - {" ", 1}, - {NULL, 0}, /* 5 from tag */ - {";1 ", 3}, - {NULL, 0}, /* 7 to tag */ - {";1", 2} - }; - - if (get_callid(msg, &callid) == -1 || callid.len == 0) { + struct iovec v[] = {{NULL, 0}, {"S", 1}, /* 1 */ + {" ", 1}, {NULL, 0}, /* 3 callid */ + {" ", 1}, {NULL, 0}, /* 5 from tag */ + {";1 ", 3}, {NULL, 0}, /* 7 to tag */ + {";1", 2}}; + + if(get_callid(msg, &callid) == -1 || callid.len == 0) { LM_ERR("can't get Call-Id field\n"); return -1; } - if (get_to_tag(msg, &to_tag) == -1) { + if(get_to_tag(msg, &to_tag) == -1) { LM_ERR("can't get To tag\n"); return -1; } - if (get_from_tag(msg, &from_tag) == -1 || from_tag.len == 0) { + if(get_from_tag(msg, &from_tag) == -1 || from_tag.len == 0) { LM_ERR("can't get From tag\n"); return -1; } STR2IOVEC(callid, v[3]); node = select_rtpp_node(callid, 1); - if (!node) { + if(!node) { LM_ERR("no available proxies\n"); return -1; } - if (node->rn_ptl_supported == 0) { + if(node->rn_ptl_supported == 0) { LM_ERR("required functionality is not " - "supported by the version of the RTPproxy running on the selected " - "node. Please upgrade the RTPproxy and try again.\n"); + "supported by the version of the RTPproxy running on the " + "selected " + "node. Please upgrade the RTPproxy and try again.\n"); return -1; } set_rtp_inst_pvar(msg, &node->rn_url); nitems = 9; - if (stream2uac == 0) { - if (to_tag.len == 0) + if(stream2uac == 0) { + if(to_tag.len == 0) return -1; STR2IOVEC(to_tag, v[5]); STR2IOVEC(from_tag, v[7]); } else { STR2IOVEC(from_tag, v[5]); STR2IOVEC(to_tag, v[7]); - if (to_tag.len <= 0) + if(to_tag.len <= 0) nitems -= 2; } send_rtpp_command(node, v, nitems); @@ -220,15 +204,13 @@ rtpproxy_stop_stream(struct sip_msg* msg, int stream2uac) return 1; } - int -rtpproxy_stop_stream2uac2_f(struct sip_msg* msg, char* str1, char* str2) +int rtpproxy_stop_stream2uac2_f(struct sip_msg *msg, char *str1, char *str2) { return rtpproxy_stop_stream(msg, 1); } - int -rtpproxy_stop_stream2uas2_f(struct sip_msg* msg, char* str1, char* str2) +int rtpproxy_stop_stream2uas2_f(struct sip_msg *msg, char *str1, char *str2) { return rtpproxy_stop_stream(msg, 0); diff --git a/src/modules/rtpproxy/rtpproxy_stream.h b/src/modules/rtpproxy/rtpproxy_stream.h index ce056a407e5..377cac4279e 100644 --- a/src/modules/rtpproxy/rtpproxy_stream.h +++ b/src/modules/rtpproxy/rtpproxy_stream.h @@ -26,13 +26,13 @@ */ #ifndef _RTPPROXY_STREAM_H -#define _RTPPROXY_STREAM_H +#define _RTPPROXY_STREAM_H int fixup_var_str_int(void **, int); -int rtpproxy_stream(struct sip_msg* msg, str *pname, int count, int stream2uac); +int rtpproxy_stream(struct sip_msg *msg, str *pname, int count, int stream2uac); int rtpproxy_stream2uac2_f(struct sip_msg *, char *, char *); int rtpproxy_stream2uas2_f(struct sip_msg *, char *, char *); -int rtpproxy_stop_stream(struct sip_msg* msg, int stream2uac); +int rtpproxy_stop_stream(struct sip_msg *msg, int stream2uac); int rtpproxy_stop_stream2uac2_f(struct sip_msg *, char *, char *); int rtpproxy_stop_stream2uas2_f(struct sip_msg *, char *, char *);