Bläddra i källkod

modules:ims_usrloc_scscf: added new API method to expire contact

Richard Good 10 år sedan
förälder
incheckning
077c400202

+ 52 - 0
modules/ims_usrloc_scscf/ucontact.c

@@ -67,6 +67,7 @@
 #include "usrloc_db.h"
 #include "usrloc_db.h"
 #include "../../hashes.h"
 #include "../../hashes.h"
 #include "contact_hslot.h"
 #include "contact_hslot.h"
+#include "utime.h"
 
 
 extern struct contact_list* contact_list;
 extern struct contact_list* contact_list;
 extern int db_mode;
 extern int db_mode;
@@ -330,6 +331,20 @@ int mem_update_ucontact(ucontact_t* _c, ucontact_info_t* _ci) {
     return 0;
     return 0;
 }
 }
 
 
+/*!
+ * \brief Setting contact expires to now in memory
+ * \param _c contact
+  * \return 0 on success, -1 on failure
+ */
+int mem_expire_ucontact(ucontact_t* _c) {
+    get_act_time();
+    _c->expires = act_time;
+
+    return 0;
+}
+
+
+
 /*!
 /*!
  * \brief Insert a new contact into the list at the correct position
  * \brief Insert a new contact into the list at the correct position
  * \param _r record that holds the sorted contacts
  * \param _r record that holds the sorted contacts
@@ -368,6 +383,43 @@ static inline void update_contact_pos(struct impurecord* _r, ucontact_t* _c) {
     }
     }
 }
 }
 
 
+/*!
+ * \brief Setting ucontact expires to now
+ * \param _r record the contact belongs to
+ * \param _c updated contact
+ * \return 0 on success, -1 on failure
+ */
+int expire_ucontact(struct impurecord* _r, ucontact_t* _c) {
+    /* we have to update memory in any case, but database directly
+     * only in db_mode 1 */
+    LM_DBG("Expiring contact aor: [%.*s] and contact uri: [%.*s]\n", _c->aor.len, _c->aor.s, _c->c.len, _c->c.s);
+    if (mem_expire_ucontact(_c) < 0) {
+        LM_ERR("failed to update memory\n");
+        return -1;
+    }
+    
+    if (db_mode == WRITE_THROUGH && (db_insert_ucontact(_r, _c) != 0)) {  /* this is an insert/update */
+	LM_ERR("failed to update contact in DB [%.*s]\n", _c->aor.len, _c->aor.s);
+	return -1;
+    }
+    
+    //make sure IMPU is linked to this contact
+    link_contact_to_impu(_r, _c, 1);
+
+    /* run callbacks for UPDATE event */
+    if (exists_ulcb_type(_c->cbs, UL_CONTACT_EXPIRE)) {
+        LM_DBG("exists callback for type= UL_CONTACT_UPDATE\n");
+        run_ul_callbacks(_c->cbs, UL_CONTACT_EXPIRE, _r, _c);
+    }
+    if (exists_ulcb_type(_r->cbs, UL_IMPU_EXPIRE_CONTACT)) {
+        run_ul_callbacks(_r->cbs, UL_IMPU_EXPIRE_CONTACT, _r, _c);
+    }
+
+    return 0;
+}
+
+
+
 /*!
 /*!
  * \brief Update ucontact with new values
  * \brief Update ucontact with new values
  * \param _r record the contact belongs to
  * \param _r record the contact belongs to

+ 15 - 0
modules/ims_usrloc_scscf/ucontact.h

@@ -107,6 +107,21 @@ int mem_update_ucontact(ucontact_t* _c, ucontact_info_t *_ci);
  */
  */
 int update_ucontact(struct impurecord* _r, ucontact_t* _c, ucontact_info_t* _ci);
 int update_ucontact(struct impurecord* _r, ucontact_t* _c, ucontact_info_t* _ci);
 
 
+/*!
+ * \brief Setting contact expires to now in memory
+ * \param _c contact
+  * \return 0 on success, -1 on failure
+ */
+int mem_expire_ucontact(ucontact_t* _c);
+
+/*!
+ * \brief Setting ucontact expires to now
+ * \param _r record the contact belongs to
+ * \param _c updated contact
+ * \return 0 on success, -1 on failure
+ */
+int expire_ucontact(struct impurecord* _r, ucontact_t* _c);
+
 int remove_dialog_data_from_contact(ucontact_t* _c, unsigned int h_entry, unsigned int h_id);
 int remove_dialog_data_from_contact(ucontact_t* _c, unsigned int h_entry, unsigned int h_id);
 
 
 int add_dialog_data_to_contact(ucontact_t* _c, unsigned int h_entry, unsigned int h_id);
 int add_dialog_data_to_contact(ucontact_t* _c, unsigned int h_entry, unsigned int h_id);

+ 1 - 0
modules/ims_usrloc_scscf/usrloc.c

@@ -94,6 +94,7 @@ int bind_usrloc(usrloc_api_t* api) {
 	api->get_ucontact = get_ucontact;
 	api->get_ucontact = get_ucontact;
 	api->release_ucontact = release_ucontact;
 	api->release_ucontact = release_ucontact;
 	api->update_ucontact = update_ucontact;
 	api->update_ucontact = update_ucontact;
+	api->expire_ucontact = expire_ucontact;
 	api->add_dialog_data_to_contact = add_dialog_data_to_contact;
 	api->add_dialog_data_to_contact = add_dialog_data_to_contact;
 	api->remove_dialog_data_from_contact = remove_dialog_data_from_contact;
 	api->remove_dialog_data_from_contact = remove_dialog_data_from_contact;
 	api->unlink_contact_from_impu = unlink_contact_from_impu;
 	api->unlink_contact_from_impu = unlink_contact_from_impu;

+ 3 - 0
modules/ims_usrloc_scscf/usrloc.h

@@ -430,6 +430,8 @@ typedef void (*unlock_contact_slot_i_t)(int sl);
 
 
 typedef int (*update_ucontact_t)(struct impurecord* _r, struct ucontact* _c, struct ucontact_info* _ci);
 typedef int (*update_ucontact_t)(struct impurecord* _r, struct ucontact* _c, struct ucontact_info* _ci);
 
 
+typedef int (*expire_ucontact_t)(struct impurecord* _r, struct ucontact* _c);
+
 typedef int (*unlink_contact_from_impu_t)(struct impurecord* _r, struct ucontact* _c, int write_to_db);
 typedef int (*unlink_contact_from_impu_t)(struct impurecord* _r, struct ucontact* _c, int write_to_db);
 
 
 typedef int (*link_contact_to_impu_t)(struct impurecord* _r, struct ucontact* _c, int wirte_to_db);
 typedef int (*link_contact_to_impu_t)(struct impurecord* _r, struct ucontact* _c, int wirte_to_db);
@@ -496,6 +498,7 @@ typedef struct usrloc_api {
     release_ucontact_t release_ucontact;
     release_ucontact_t release_ucontact;
     get_all_ucontacts_t get_all_ucontacts;
     get_all_ucontacts_t get_all_ucontacts;
     update_ucontact_t update_ucontact;
     update_ucontact_t update_ucontact;
+    expire_ucontact_t expire_ucontact;
     unlink_contact_from_impu_t unlink_contact_from_impu;
     unlink_contact_from_impu_t unlink_contact_from_impu;
     link_contact_to_impu_t link_contact_to_impu;
     link_contact_to_impu_t link_contact_to_impu;
     //update_user_profile_t update_user_profile;
     //update_user_profile_t update_user_profile;