Module: sip-router Branch: carstenbock/dispatcher Commit: e207c10747fa937e12f305f27b8592b871677d60 URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=e207c107...
Author: Carsten Bock lists@bock.info Committer: Carsten Bock lists@bock.info Date: Wed Sep 22 12:51:12 2010 +0200
- Allow the configuration of valid return values from OPTIONs-Request. - Inspiration taken from OpenSIPs
---
modules_k/dispatcher/dispatch.c | 8 +- modules_k/dispatcher/dispatch.h | 4 + modules_k/dispatcher/dispatcher.c | 124 +++++++++++++++++++++++++ modules_k/dispatcher/doc/dispatcher_admin.xml | 22 +++++ 4 files changed, 152 insertions(+), 6 deletions(-)
diff --git a/modules_k/dispatcher/dispatch.c b/modules_k/dispatcher/dispatch.c old mode 100644 new mode 100755 index 528bf9d..2b2a189 --- a/modules_k/dispatcher/dispatch.c +++ b/modules_k/dispatcher/dispatch.c @@ -2259,12 +2259,8 @@ static void ds_options_callback( struct cell *t, int type, ps->code, uri.len, uri.s, group); /* ps->code contains the result-code of the request. * - * We accept both a "200 OK", "501 Not supported" and "403" as an - * successful reply. - * 501: Cisco-Gateways reply with a "501 Not supported" to the request. - * 403: Aastra-Gateways reply with a "403" to the request. - * 405: Some GWs reply with a "405 Method Not Allowed" to the request. */ - if ((ps->code == 200) || (ps->code == 501) || (ps->code == 403) || (ps->code == 405)) + * We accept "200 OK" and custom reply codes as a valid response. */ + if ((ps->code == 200) || check_options_rplcode(ps->code)) { /* Set the according entry back to "Active": * remove the Probing/Inactive Flag and reset the failure counter. */ diff --git a/modules_k/dispatcher/dispatch.h b/modules_k/dispatcher/dispatch.h old mode 100644 new mode 100755 index 16ab844..5ae6478 --- a/modules_k/dispatcher/dispatch.h +++ b/modules_k/dispatcher/dispatch.h @@ -116,6 +116,10 @@ int ds_is_from_list(struct sip_msg *_m, int group); */ void ds_check_timer(unsigned int ticks, void* param);
+/*! \brief + * Function for checking, ig the reply-code is valid. + */ +int check_options_rplcode(int code);
/*! \brief * Timer for checking active calls load diff --git a/modules_k/dispatcher/dispatcher.c b/modules_k/dispatcher/dispatcher.c old mode 100644 new mode 100755 index 8632283..63ddd89 --- a/modules_k/dispatcher/dispatcher.c +++ b/modules_k/dispatcher/dispatcher.c @@ -127,6 +127,10 @@ str ds_table_name = str_init(DS_TABLE_NAME); str ds_setid_pvname = {NULL, 0}; pv_spec_t ds_setid_pv;
+static str options_reply_codes_str= {NULL, 0}; +static int* options_reply_codes = NULL; +static int options_codes_no; + /** module functions */ static int mod_init(void); static int child_init(int); @@ -152,6 +156,8 @@ static struct mi_root* ds_mi_list(struct mi_root* cmd, void* param); static struct mi_root* ds_mi_reload(struct mi_root* cmd_tree, void* param); static int mi_child_init(void);
+static int parse_reply_codes(); + static cmd_export_t cmds[]={ {"ds_select_dst", (cmd_function)w_ds_select_dst, 2, fixup_igp_igp, 0, REQUEST_ROUTE|FAILURE_ROUTE}, @@ -206,6 +212,7 @@ static param_export_t params[]={ {"ds_hash_expire", INT_PARAM, &ds_hash_expire}, {"ds_hash_initexpire", INT_PARAM, &ds_hash_initexpire}, {"ds_hash_check_interval", INT_PARAM, &ds_hash_check_interval}, + {"ds_options_reply_codes", STR_PARAM, &options_reply_codes_str.s}, {0,0,0} };
@@ -264,6 +271,16 @@ static int mod_init(void) if (ds_ping_from.s) ds_ping_from.len = strlen(ds_ping_from.s); if (ds_ping_method.s) ds_ping_method.len = strlen(ds_ping_method.s);
+ if(options_reply_codes_str.s) { + options_reply_codes_str.len = strlen(options_reply_codes_str.s); + if(parse_reply_codes()< 0) + { + LM_ERR("Bad format for options_reply_code parameter" + " - Need a code list separated by commas\n"); + return -1; + } + } + if(init_data()!= 0) return -1;
@@ -475,6 +492,9 @@ static void destroy(void) if(ds_db_url.s) ds_disconnect_db(); ds_hash_load_destroy(); + + if(options_reply_codes) + pkg_free(options_reply_codes); }
/** @@ -709,3 +729,107 @@ static int w_ds_is_from_list1(struct sip_msg *msg, char *set, char *str2) { return ds_is_from_list(msg, (int)(long)set); } + +static int parse_reply_codes(void) +{ + str code_str; + unsigned int code; + int index= 0; + char* sep1, *sep2, *aux; + + options_reply_codes = (int*)pkg_malloc( + options_reply_codes_str.len/3 * sizeof(int)); + + if(options_reply_codes== NULL) + { + LM_ERR("no more memory\n"); + return -1; + } + + sep1 = options_reply_codes_str.s; + sep2 = strchr(options_reply_codes_str.s, ','); + + while(sep2 != NULL) + { + // Trim the values: + aux = sep2; + while(*sep1 == ' ') + sep1++; + + sep2--; + while(*sep2 == ' ') + sep2--; + + // The resulting string + code_str.s = sep1; + code_str.len = sep2-sep1+1; + + // Create a Integer from the String: + if(str2int(&code_str, &code)< 0) + { + LM_ERR("Bad format - not am integer [%.*s]\n", + code_str.len, code_str.s); + return -1; + } + + // Check if it is valid: + if(code<100 ||code > 700) + { + LM_ERR("Wrong number [%d]- must be a valid SIP reply code\n", code); + return -1; + } + + // Add it to the List + options_reply_codes[index] = code; + index++; + + // Next item: + sep1 = aux +1; + sep2 = strchr(sep1, ','); + } + + // No more commas? Last value: + // Trim: + while(*sep1 == ' ') + sep1++; + sep2 = options_reply_codes_str.s+options_reply_codes_str.len -1; + while(*sep2 == ' ') + sep2--; + + // Convert + code_str.s = sep1; + code_str.len = sep2 -sep1 +1; + if(str2int(&code_str, &code)< 0) + { + LM_ERR("Bad format - not am integer [%.*s]\n", + code_str.len, code_str.s); + return -1; + } + // Validate: + if(code<100 ||code > 700) + { + LM_ERR("Wrong number [%d]- must be a valid SIP reply code\n", code); + return -1; + } + // Add: + options_reply_codes[index] = code; + index++; + + // Done: + options_codes_no = index; + + return 0; +} + +int check_options_rplcode(int code) +{ + int i; + + for (i =0; i< options_codes_no; i++) + { + if(options_reply_codes[i] == code) + return 1; + } + + return 0; +} diff --git a/modules_k/dispatcher/doc/dispatcher_admin.xml b/modules_k/dispatcher/doc/dispatcher_admin.xml old mode 100644 new mode 100755 index 62f0f89..3b6c2fe --- a/modules_k/dispatcher/doc/dispatcher_admin.xml +++ b/modules_k/dispatcher/doc/dispatcher_admin.xml @@ -568,6 +568,28 @@ modparam("dispatcher", "force_dst", 1) </section>
<section> + <title><varname>ds_options_reply_codes</varname> (string)</title> + <para> + This parameters allows the configuration of valid return codes to the OPTIONS-Request. + The "200 OK" is always accepted, if you want to accept other return codes you may specify + them in this parameter as a comma separated value: + </para> + <para> + <emphasis> + Default value is <quote>null</quote> - only accept "200 OK" as a reply. + </emphasis> + </para> + <example> + <title>Set the <quote>ds_options_reply_codes</quote> parameter</title> + <programlisting format="linespecific"> + ... + modparam("dispatcher", "ds_options_reply_codes", "403,500,604") + ... + </programlisting> + </example> + </section> + + <section> <title><varname>ds_append_branch</varname> (int)</title> <para> If set to 1, functions will automaticall append a new branch if