Bläddra i källkod

modules/ims_registrar_scscf: new function to pass extra argument to lookup (ue_type)
- useful if looking for a specific type of UE ie VoLTE vs SIP for example

jaybeepee 9 år sedan
förälder
incheckning
6901182228

+ 21 - 4
modules/ims_registrar_scscf/lookup.c

@@ -54,11 +54,12 @@
 
 /*! \brief
  * Lookup contact in the database and rewrite Request-URI
- * \return: -1 : not found
+ * \return:  1 : found
+ *          -1 : not found
  *          -2 : found but method not allowed
  *          -3 : error
  */
-int lookup(struct sip_msg* _m, udomain_t* _d) {
+int lookup(struct sip_msg* _m, udomain_t* _d, char* ue_type_c) {
     impurecord_t* r;
     str aor;
     ucontact_t* ptr;
@@ -67,11 +68,27 @@ int lookup(struct sip_msg* _m, udomain_t* _d) {
     str path_dst;
     flag_t old_bflags;
     int i = 0;
+    int ue_type;    /*0=any, 1=3gpp, 2=sip */
 
     if (!_m) {
         LM_ERR("NULL message!!!\n");
         return -1;
     }
+    
+    switch (ue_type_c[0]) {
+            case '3':
+                LM_DBG("looking for 3gpp terminals\n");
+                ue_type = 1;
+                break;
+            case 's':
+            case 'S':
+                LM_DBG("looking for sip terminals\n");
+                ue_type = 2;
+                break;
+        default:
+            LM_DBG("looking for any type of terminal\n");
+            ue_type=0;
+    }
 
     if (_m->new_uri.s) aor = _m->new_uri;
     else aor = _m->first_line.u.request.uri;
@@ -97,7 +114,7 @@ int lookup(struct sip_msg* _m, udomain_t* _d) {
     i = 0;
 
     while (i < MAX_CONTACTS_PER_IMPU && (ptr = r->newcontacts[i])) {
-        if (VALID_CONTACT(ptr, act_time) && allowed_method(_m, ptr)) {
+        if (VALID_UE_TYPE(ptr, ue_type) && VALID_CONTACT(ptr, act_time) && allowed_method(_m, ptr)) {
             LM_DBG("Found a valid contact [%.*s]\n", ptr->c.len, ptr->c.s);
             i++;
             break;
@@ -166,7 +183,7 @@ int lookup(struct sip_msg* _m, udomain_t* _d) {
 
     //the last i was the first valid contact we found - let's go through the rest of valid contacts and append the branches.
     while (i < MAX_CONTACTS_PER_IMPU && (ptr = r->newcontacts[i])) {
-        if (VALID_CONTACT(ptr, act_time) && allowed_method(_m, ptr)) {
+        if (VALID_UE_TYPE(ptr, ue_type) && VALID_CONTACT(ptr, act_time) && allowed_method(_m, ptr)) {
             path_dst.len = 0;
             if (ptr->path.s && ptr->path.len
                     && get_path_dst_uri(&ptr->path, &path_dst) < 0) {

+ 1 - 1
modules/ims_registrar_scscf/lookup.h

@@ -39,7 +39,7 @@
 /*! \brief
  * Lookup a contact in usrloc and rewrite R-URI if found
  */
-int lookup(struct sip_msg* _m, udomain_t* _d);
+int lookup(struct sip_msg* _m, udomain_t* _d, char * ue_type);
 int lookup_path_to_contact(struct sip_msg* _m, char* contact_uri);
 
 /*! \brief

+ 7 - 4
modules/ims_registrar_scscf/reg_mod.c

@@ -118,6 +118,7 @@ static void mod_destroy(void);
 static int w_save(struct sip_msg* _m, char * _route, char* _d, char* mode, char* _cflags);
 static int w_assign_server_unreg(struct sip_msg* _m, char* _route, char* _d, char* _direction);
 static int w_lookup(struct sip_msg* _m, char* _d, char* _p2);
+static int w_lookup_ue_type(struct sip_msg* _m, char* _d, char* _p2);
 static int w_lookup_path_to_contact(struct sip_msg* _m, char* contact_uri);
 
 /*! \brief Fixup functions */
@@ -201,6 +202,7 @@ static pv_export_t mod_pvs[] = {
 static cmd_export_t cmds[] = {
     {"save", (cmd_function) w_save, 2, assign_save_fixup3_async, 0, REQUEST_ROUTE | ONREPLY_ROUTE},
     {"lookup", (cmd_function) w_lookup, 1, domain_fixup, 0, REQUEST_ROUTE | FAILURE_ROUTE},
+    {"lookup", (cmd_function) w_lookup_ue_type, 2, domain_fixup, 0, REQUEST_ROUTE | FAILURE_ROUTE},
     {"lookup_path_to_contact", (cmd_function) w_lookup_path_to_contact, 1, fixup_var_str_12, 0, REQUEST_ROUTE},
     {"term_impu_registered", (cmd_function) term_impu_registered, 1, domain_fixup, 0, REQUEST_ROUTE | FAILURE_ROUTE},
     {"term_impu_has_contact", (cmd_function) term_impu_has_contact, 1, domain_fixup, 0, REQUEST_ROUTE | FAILURE_ROUTE},
@@ -606,12 +608,13 @@ static int w_lookup_path_to_contact(struct sip_msg* _m, char* contact_uri) {
  * Wrapper to lookup(location)
  */
 static int w_lookup(struct sip_msg* _m, char* _d, char* _p2) {
-    return lookup(_m, (udomain_t*) _d);
+    return lookup(_m, (udomain_t*) _d, "any");
+}
+
+static int w_lookup_ue_type(struct sip_msg* _m, char* _d, char* _p2) {
+    return lookup(_m, (udomain_t*) _d, _p2);
 }
 
-/*! \brief
- * Convert char* parameter to udomain_t* pointer
- */
 static int domain_fixup(void** param, int param_no) {
     udomain_t* d;