Module: sip-router
Branch: master
Commit: fcbe9878c6f09adc000edaffb0f292b555eb6b48
URL:    
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=fcbe9878c6f09adc000edaffb0f292b555eb6b48

Author: pd <[email protected]>
Committer: pd <[email protected]>
Date:   Sun Nov 20 22:05:14 2011 +0000

modules/app_lua, modules_k/siputils, modules_k/uac: Added 
siputils.is_uri_user_e164 and uac.replace_from to app_lua

---

 modules/app_lua/app_lua_exp.c |  118 +++++++++++++++++++++++++++++++++++++++++
 modules_k/siputils/checks.c   |   22 +++++---
 modules_k/siputils/checks.h   |    3 +-
 modules_k/siputils/siputils.c |    4 +-
 modules_k/siputils/siputils.h |    2 +
 modules_k/uac/api.h           |   25 +++++++++
 modules_k/uac/uac.c           |   16 +++++-
 7 files changed, 180 insertions(+), 10 deletions(-)

diff --git a/modules/app_lua/app_lua_exp.c b/modules/app_lua/app_lua_exp.c
index 93db02b..3b15fb7 100644
--- a/modules/app_lua/app_lua_exp.c
+++ b/modules/app_lua/app_lua_exp.c
@@ -50,6 +50,7 @@
 #include "../../modules_k/rls/api.h"
 #include "../../modules_k/alias_db/api.h"
 #include "../../modules_k/msilo/api.h"
+#include "../../modules_k/uac/api.h"
 
 #include "app_lua_api.h"
 
@@ -72,6 +73,7 @@
 #define SR_LUA_EXP_MOD_RLS        (1<<16)
 #define SR_LUA_EXP_MOD_ALIAS_DB   (1<<17)
 #define SR_LUA_EXP_MOD_MSILO      (1<<18)
+#define SR_LUA_EXP_MOD_UAC        (1<<19)
 
 /**
  *
@@ -175,6 +177,11 @@ static alias_db_api_t _lua_alias_dbb;
 static msilo_api_t _lua_msilob;
 
 /**
+ * uac
+ */
+static uac_api_t _lua_uacb;
+
+/**
  *
  */
 static int lua_sr_sl_send_reply (lua_State *L)
@@ -1837,8 +1844,48 @@ static int lua_sr_siputils_has_totag(lua_State *L)
 /**
  *
  */
+static int lua_sr_siputils_is_uri_user_e164(lua_State *L)
+{
+       int ret;
+       sr_lua_env_t *env_L;
+       str param[1];
+
+       env_L = sr_lua_env_get();
+       
+       if(!(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_SIPUTILS))
+       {
+               LM_WARN("weird: siputils function executed but module not 
registered\n");
+               return app_lua_return_error(L);
+       }
+
+       if(env_L->msg==NULL)
+       {
+               LM_WARN("invalid parameters from Lua env\n");
+               return app_lua_return_error(L);
+       }
+
+       if(lua_gettop(L)!=1)
+       {
+               LM_ERR("incorrect number of arguments\n");
+               return app_lua_return_error(L);
+       }
+
+       param[0].s = (char *) lua_tostring(L, -1);
+       param[0].len = strlen(param[0].s);
+       
+       ret = _lua_siputilsb.is_uri_user_e164(env_L->msg, &param[0]);
+       if (ret < 0)
+               return app_lua_return_false(L);
+
+       return app_lua_return_true(L);
+}
+
+/**
+ *
+ */
 static const luaL_reg _sr_siputils_Map [] = {
        {"has_totag",            lua_sr_siputils_has_totag},
+       {"is_uri_user_e164",     lua_sr_siputils_is_uri_user_e164},
        {NULL, NULL}
 };
 
@@ -2063,6 +2110,62 @@ static const luaL_reg _sr_msilo_Map [] = {
 /**
  *
  */
+static int lua_sr_uac_replace_from(lua_State *L)
+{
+       int ret;
+       sr_lua_env_t *env_L;
+       str param[2];
+
+       env_L = sr_lua_env_get();
+
+       if (!(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_UAC))
+       {
+               LM_WARN("weird:uac function executed but module not 
registered\n");
+               return app_lua_return_error(L);
+       }
+
+       if (env_L->msg == NULL)
+       {
+               LM_WARN("invalid parameters from Lua env\n");
+               return app_lua_return_error(L);
+       }
+
+       if (lua_gettop(L) == 1)
+       {
+               param[0].s = "";
+               param[0].len = 0;
+               param[1].s = (char *) lua_tostring(L, -1);
+               param[1].len = strlen(param[1].s);
+       
+       }
+       else if (lua_gettop(L) == 2)
+       {
+               param[0].s = (char *) lua_tostring(L, -2);
+               param[0].len = strlen(param[0].s);
+               param[1].s = (char *) lua_tostring(L, -1);
+               param[1].len = strlen(param[1].s);
+       }
+       else
+       {
+               LM_ERR("incorrect number of arguments\n");
+               return app_lua_return_error(L);
+       }
+
+       ret = _lua_uacb.replace_from(env_L->msg, &param[0], &param[1]);
+       return app_lua_return_int(L, ret);
+}
+
+/**
+ *
+ */
+static const luaL_reg _sr_uac_Map [] = {
+       {"replace_from",lua_sr_uac_replace_from},
+       {NULL, NULL}
+};
+
+/**
+ *
+ */
 int lua_sr_exp_init_mod(void)
 {
        if(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_SL)
@@ -2261,6 +2364,16 @@ int lua_sr_exp_init_mod(void)
                }
                LM_DBG("loaded msilo api\n");
        }
+       if(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_UAC)
+       {
+               /* bind the UAC API */
+               if (load_uac_api(&_lua_uacb) < 0)
+               {
+                       LM_ERR("cannot bind to UAC API\n");
+                       return -1;
+               }
+               LM_DBG("loaded uac api\n");
+       }
        return 0;
 }
 
@@ -2331,6 +2444,9 @@ int lua_sr_exp_register_mod(char *mname)
        } else  if(len==5 && strcmp(mname, "msilo")==0) {
                _sr_lua_exp_reg_mods |= SR_LUA_EXP_MOD_MSILO;
                return 0;
+       } else  if(len==3 && strcmp(mname, "uac")==0) {
+               _sr_lua_exp_reg_mods |= SR_LUA_EXP_MOD_UAC;
+               return 0;
        }
 
        return -1;
@@ -2379,5 +2495,7 @@ void lua_sr_exp_openlibs(lua_State *L)
                luaL_openlib(L, "sr.alias_db", _sr_alias_db_Map,      0);
        if(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_MSILO)
                luaL_openlib(L, "sr.msilo", _sr_msilo_Map,            0);
+       if(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_UAC)
+               luaL_openlib(L, "sr.uac", _sr_uac_Map,                0);
 }
 
diff --git a/modules_k/siputils/checks.c b/modules_k/siputils/checks.c
index 6ccac04..52db0ae 100644
--- a/modules_k/siputils/checks.c
+++ b/modules_k/siputils/checks.c
@@ -467,11 +467,10 @@ int is_e164(struct sip_msg* _m, char* _sp, char* _s2)
 /*
  * Check if user part of URI in pseudo variable is an e164 number
  */
-int is_uri_user_e164(struct sip_msg* _m, char* _sp, char* _s2)
+int w_is_uri_user_e164(struct sip_msg* _m, char* _sp, char* _s2)
 {
     pv_spec_t *sp;
     pv_value_t pv_val;
-    struct sip_uri puri;
 
     sp = (pv_spec_t *)_sp;
 
@@ -481,11 +480,7 @@ int is_uri_user_e164(struct sip_msg* _m, char* _sp, char* 
_s2)
                LM_DBG("missing uri\n");
                return -1;
            }
-           if (parse_uri(pv_val.rs.s, pv_val.rs.len, &puri) < 0) {
-               LM_ERR("parsing URI failed\n");
-               return -1;
-           }
-           return e164_check(&(puri.user));
+           return is_uri_user_e164(_m, &pv_val.rs);
        } else {
            LM_ERR("pseudo variable value is not string\n");
            return -1;
@@ -496,6 +491,19 @@ int is_uri_user_e164(struct sip_msg* _m, char* _sp, char* 
_s2)
     }
 }
 
+
+int is_uri_user_e164(struct sip_msg *msg, str *uri)
+{
+    struct sip_uri puri;
+
+    if (parse_uri(uri->s, uri->len, &puri) < 0) {
+       LM_ERR("parsing URI failed\n");
+       return -1;
+    }
+
+    return e164_check(&(puri.user));
+}
+
 /*
  * Set userpart of URI
  */
diff --git a/modules_k/siputils/checks.h b/modules_k/siputils/checks.h
index 706e54b..07a71a2 100644
--- a/modules_k/siputils/checks.h
+++ b/modules_k/siputils/checks.h
@@ -84,7 +84,8 @@ int tel2sip(struct sip_msg* _msg, char* _uri, char* 
_hostpart, char* _res);
 /*
  * Check if user part of URI in pseudo variable is an e164 number
  */
-int is_uri_user_e164(struct sip_msg* _m, char* _sp, char* _s2);
+int w_is_uri_user_e164(struct sip_msg* _m, char* _sp, char* _s2);
+int is_uri_user_e164(struct sip_msg* msg, str *uri);
 
 /*
  * Check if pseudo variable argument value is an e164 number
diff --git a/modules_k/siputils/siputils.c b/modules_k/siputils/siputils.c
index 9970f45..b5c9806 100644
--- a/modules_k/siputils/siputils.c
+++ b/modules_k/siputils/siputils.c
@@ -132,7 +132,7 @@ static cmd_export_t cmds[]={
         REQUEST_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE|ONREPLY_ROUTE},
        {"is_e164",            (cmd_function)is_e164,           1, 
fixup_pvar_null,
                fixup_free_pvar_null, REQUEST_ROUTE|FAILURE_ROUTE|LOCAL_ROUTE},
-       {"is_uri_user_e164",   (cmd_function)is_uri_user_e164,  1, 
fixup_pvar_null,
+       {"is_uri_user_e164",   (cmd_function)w_is_uri_user_e164,  1, 
fixup_pvar_null,
                fixup_free_pvar_null, REQUEST_ROUTE|FAILURE_ROUTE|LOCAL_ROUTE},
        {"encode_contact",     (cmd_function)encode_contact,    2, 0,
                0, REQUEST_ROUTE|ONREPLY_ROUTE},
@@ -263,6 +263,8 @@ int bind_siputils(siputils_api_t* api)
        }
 
        get_rpid_avp( &api->rpid_avp, &api->rpid_avp_type );
+       api->has_totag = has_totag;
+       api->is_uri_user_e164 = is_uri_user_e164;
 
        return 0;
 }
diff --git a/modules_k/siputils/siputils.h b/modules_k/siputils/siputils.h
index b640a25..a4fc655 100644
--- a/modules_k/siputils/siputils.h
+++ b/modules_k/siputils/siputils.h
@@ -25,12 +25,14 @@
 #define _SIPUTILS_H_
 
 typedef int (*siputils_has_totag_t)(struct sip_msg*, char*, char*);
+typedef int (*siputils_is_uri_user_e164_t)(struct sip_msg*, str*);
 
 /*! Siputils module API */
 typedef struct siputils_api {
        int_str rpid_avp;      /*!< Name of AVP containing Remote-Party-ID */
        int     rpid_avp_type; /*!< type of the RPID AVP */
        siputils_has_totag_t has_totag;
+       siputils_is_uri_user_e164_t is_uri_user_e164;
 } siputils_api_t;
 
 typedef int (*bind_siputils_t)(siputils_api_t* api);
diff --git a/modules_k/uac/api.h b/modules_k/uac/api.h
new file mode 100644
index 0000000..64c4b37
--- /dev/null
+++ b/modules_k/uac/api.h
@@ -0,0 +1,25 @@
+#ifndef UAC_API_H_
+#define UAC_API_H_
+#include "../../sr_module.h"
+
+
+typedef int (*uac_replace_from_t)(struct sip_msg *, str *, str *);
+
+typedef struct uac_binds {
+       uac_replace_from_t      replace_from;
+} uac_api_t;
+
+typedef int (*bind_uac_f)(uac_api_t*);
+
+int bind_uac(uac_api_t*);
+
+inline static int load_uac_api(uac_api_t *uacb){
+       bind_uac_f bind_uac_exports;
+       if(!(bind_uac_exports=(bind_uac_f)find_export("bind_uac",1,0))){
+               LM_ERR("Failed to import bind_iuax\n");
+               return -1;
+       }
+       return bind_uac_exports(uacb);
+}
+
+#endif /* UAC_API_H_ */
diff --git a/modules_k/uac/uac.c b/modules_k/uac/uac.c
index 95abd10..5f6112a 100644
--- a/modules_k/uac/uac.c
+++ b/modules_k/uac/uac.c
@@ -57,6 +57,7 @@
 #include "auth.h"
 #include "uac_send.h"
 #include "uac_reg.h"
+#include "api.h"
 
 
 MODULE_VERSION
@@ -115,7 +116,8 @@ static cmd_export_t cmds[]={
                fixup_free_pvar_pvar, ANY_ROUTE },
        {"uac_reg_request_to",  (cmd_function)w_uac_reg_request_to,  2, 
fixup_pvar_uint, fixup_free_pvar_uint,
                REQUEST_ROUTE | FAILURE_ROUTE | BRANCH_ROUTE },
-
+       {"bind_uac", (cmd_function)bind_uac,                  1,                
  0, 0,
+               0},
        {0,0,0,0,0,0}
 };
 
@@ -496,3 +498,15 @@ static int w_uac_reg_request_to(struct sip_msg* msg, char* 
src, char* mode_s)
        return uac_reg_request_to(msg, &val.rs, mode);
 }
 
+
+int bind_uac(struct uac_binds *uacb)
+{
+       if (uacb == NULL)
+        {
+                LM_WARN("bind_uac: Cannot load uac API into a NULL pointer\n");
+                return -1;
+        }
+
+        uacb->replace_from = replace_from;
+        return 0;
+}


_______________________________________________
sr-dev mailing list
[email protected]
http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev

Reply via email to