Browse Source

modules/ims_registrar_scscf: new function term_impu_has_contact
- Use this function to check if an IMPU has a valid contact

Jason Penton 10 năm trước cách đây
mục cha
commit
9af8528041

+ 11 - 0
modules/ims_registrar_scscf/cxdx_avp.c

@@ -142,6 +142,17 @@ static inline str cxdx_get_avp(AAAMessage *msg,int avp_code,int vendor_id,
 		return avp->data;
 		return avp->data;
 }
 }
 
 
+inline int cxdx_add_call_id(AAAMessage *msg, str data) 
+{
+    return 
+	cxdx_add_avp(msg,data.s,data.len,
+		AVP_Call_Id,
+		AAA_AVP_FLAG_VENDOR_SPECIFIC,
+		50,
+		AVP_DUPLICATE_DATA,
+		__FUNCTION__);
+}
+
 /**
 /**
  * Creates and adds a Destination-Realm AVP.
  * Creates and adds a Destination-Realm AVP.
  * @param msg - the Diameter message to add to.
  * @param msg - the Diameter message to add to.

+ 1 - 0
modules/ims_registrar_scscf/cxdx_avp.h

@@ -53,6 +53,7 @@ struct AAAMessage;
 struct AAA_AVP;
 struct AAA_AVP;
 struct sip_msg;
 struct sip_msg;
 
 
+inline int cxdx_add_call_id(AAAMessage *msg, str data);
 /**
 /**
  * Creates and adds a Destination-Realm AVP.
  * Creates and adds a Destination-Realm AVP.
  * @param msg - the Diameter message to add to.
  * @param msg - the Diameter message to add to.

+ 4 - 0
modules/ims_registrar_scscf/cxdx_sar.c

@@ -61,6 +61,8 @@
 #include "../../data_lump_rpl.h"
 #include "../../data_lump_rpl.h"
 #include "sip_msg.h"
 #include "sip_msg.h"
 #include "regtime.h"
 #include "regtime.h"
+#include "../../parser/hf.h"
+#include "../../lib/ims/ims_getters.h"
 
 
 int create_return_code(int result) {
 int create_return_code(int result) {
     int rc;
     int rc;
@@ -310,6 +312,7 @@ int cxdx_send_sar(struct sip_msg *msg, str public_identity, str private_identity
     AAAMessage *sar = 0;
     AAAMessage *sar = 0;
     AAASession *session = 0;
     AAASession *session = 0;
     unsigned int hash = 0, label = 0;
     unsigned int hash = 0, label = 0;
+    struct hdr_field *hdr;
 
 
     session = cdpb.AAACreateSession(0);
     session = cdpb.AAACreateSession(0);
 
 
@@ -320,6 +323,7 @@ int cxdx_send_sar(struct sip_msg *msg, str public_identity, str private_identity
     }
     }
     if (!sar) goto error1;
     if (!sar) goto error1;
 
 
+    if (!cxdx_add_call_id(sar, cscf_get_call_id(msg, &hdr)));
     if (!cxdx_add_destination_realm(sar, cxdx_dest_realm)) goto error1;
     if (!cxdx_add_destination_realm(sar, cxdx_dest_realm)) goto error1;
 
 
     if (!cxdx_add_vendor_specific_appid(sar, IMS_vendor_id_3GPP, IMS_Cx, 0 /*IMS_Cx*/)) goto error1;
     if (!cxdx_add_vendor_specific_appid(sar, IMS_vendor_id_3GPP, IMS_Cx, 0 /*IMS_Cx*/)) goto error1;

+ 58 - 1
modules/ims_registrar_scscf/lookup.c

@@ -60,7 +60,7 @@
  */
  */
 int lookup(struct sip_msg* _m, udomain_t* _d) {
 int lookup(struct sip_msg* _m, udomain_t* _d) {
     impurecord_t* r;
     impurecord_t* r;
-    str aor, uri;
+    str aor;
     ucontact_t* ptr;
     ucontact_t* ptr;
     int res;
     int res;
     int ret;
     int ret;
@@ -206,14 +206,17 @@ int lookup_path_to_contact(struct sip_msg* _m, char* contact_uri) {
 	
 	
 	if (get_path_dst_uri(&contact->path, &path_dst) < 0) {
 	if (get_path_dst_uri(&contact->path, &path_dst) < 0) {
 	    LM_ERR("failed to get dst_uri for Path\n");
 	    LM_ERR("failed to get dst_uri for Path\n");
+	    ul.release_ucontact(contact);
 	    return -1;
 	    return -1;
 	}
 	}
 	if (set_path_vector(_m, &contact->path) < 0) {
 	if (set_path_vector(_m, &contact->path) < 0) {
 	    LM_ERR("failed to set path vector\n");
 	    LM_ERR("failed to set path vector\n");
+	    ul.release_ucontact(contact);
 	    return -1;
 	    return -1;
 	}
 	}
 	if (set_dst_uri(_m, &path_dst) < 0) {
 	if (set_dst_uri(_m, &path_dst) < 0) {
 	    LM_ERR("failed to set dst_uri of Path\n");
 	    LM_ERR("failed to set dst_uri of Path\n");
+	    ul.release_ucontact(contact);
 	    return -1;
 	    return -1;
 	}
 	}
 	
 	
@@ -259,6 +262,60 @@ int impu_registered(struct sip_msg* _m, char* _t, char* _s)
 	return ret;
 	return ret;
 }
 }
 
 
+/**
+ * Check that the IMPU at the Term S has at least one valid contact...
+ * @param _m - msg
+ * @param _t - t
+ * @param _s - s
+ * @return true if there is at least one valid contact. false if not
+ */
+int term_impu_has_contact(struct sip_msg* _m, udomain_t* _d, char* _s) 
+{
+    impurecord_t* r;
+    str aor, uri;
+    ucontact_t* ptr;
+    int res;
+    int ret;
+    int i = 0;
+
+    if (_m->new_uri.s) uri = _m->new_uri;
+    else uri = _m->first_line.u.request.uri;
+
+    if (extract_aor(&uri, &aor) < 0) {
+	LM_ERR("failed to extract address of record\n");
+	return -3;
+    }
+
+    get_act_time();
+
+    ul.lock_udomain(_d, &aor);
+    res = ul.get_impurecord(_d, &aor, &r);
+    if (res > 0) {
+	LM_DBG("'%.*s' Not found in usrloc\n", aor.len, ZSW(aor.s));
+	ul.unlock_udomain(_d, &aor);
+	return -1;
+    }
+
+    while (i < MAX_CONTACTS_PER_IMPU && (ptr = r->newcontacts[i])) {
+	if (VALID_CONTACT(ptr, act_time) && allowed_method(_m, ptr)) {
+	    LM_DBG("Found a valid contact [%.*s]\n", ptr->c.len, ptr->c.s);
+	    i++;
+	    ret = 1;
+	    break;
+	}
+	i++;
+    }
+
+    /* look first for an un-expired and supported contact */
+    if (ptr == 0) {
+	/* nothing found */
+	ret = -1;
+    } 
+
+    ul.unlock_udomain(_d, &aor);
+
+    return ret;
+}
 /*! \brief the term_impu_registered() function
 /*! \brief the term_impu_registered() function
  * Return true if the AOR in the Request-URI  for the terminating user is registered
  * Return true if the AOR in the Request-URI  for the terminating user is registered
  */
  */

+ 1 - 0
modules/ims_registrar_scscf/lookup.h

@@ -49,6 +49,7 @@ int lookup_path_to_contact(struct sip_msg* _m, char* contact_uri);
  */
  */
 int impu_registered(struct sip_msg* _m, char* _t, char* _s);
 int impu_registered(struct sip_msg* _m, char* _t, char* _s);
 int term_impu_registered(struct sip_msg* _m, char* _t, char* _s);
 int term_impu_registered(struct sip_msg* _m, char* _t, char* _s);
+int term_impu_has_contact(struct sip_msg* _m, udomain_t* _d, char* _s);
 
 
 
 
 #endif /* LOOKUP_H */
 #endif /* LOOKUP_H */

+ 1 - 0
modules/ims_registrar_scscf/reg_mod.c

@@ -195,6 +195,7 @@ static cmd_export_t cmds[] = {
     {"lookup", (cmd_function) w_lookup, 1, domain_fixup, 0, REQUEST_ROUTE | FAILURE_ROUTE},
     {"lookup", (cmd_function) w_lookup, 1, 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},
     {"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_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},
     {"impu_registered", (cmd_function) impu_registered, 1, domain_fixup, 0, REQUEST_ROUTE | FAILURE_ROUTE},
     {"impu_registered", (cmd_function) impu_registered, 1, domain_fixup, 0, REQUEST_ROUTE | FAILURE_ROUTE},
     {"assign_server_unreg", (cmd_function) w_assign_server_unreg, 3, assign_save_fixup3_async, 0, REQUEST_ROUTE},
     {"assign_server_unreg", (cmd_function) w_assign_server_unreg, 3, assign_save_fixup3_async, 0, REQUEST_ROUTE},
     {"add_sock_hdr", (cmd_function) add_sock_hdr, 1, fixup_str_null, 0, REQUEST_ROUTE},
     {"add_sock_hdr", (cmd_function) add_sock_hdr, 1, fixup_str_null, 0, REQUEST_ROUTE},