<p>George Joseph has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/8102">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">res_pjsip_registrar_expire:  Refactor into res_pjsip_register<br><br>res_pjsip_registrar_expire remains as an empty module for now.<br><br>Change-Id: Ib93698938bae548d2199cb542f3692d1a171239f<br>---<br>M res/res_pjsip_registrar.c<br>M res/res_pjsip_registrar_expire.c<br>2 files changed, 107 insertions(+), 110 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/02/8102/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">diff --git a/res/res_pjsip_registrar.c b/res/res_pjsip_registrar.c<br>index 00981fb..078e13e 100644<br>--- a/res/res_pjsip_registrar.c<br>+++ b/res/res_pjsip_registrar.c<br>@@ -1091,6 +1091,93 @@<br>     .on_rx_request = registrar_on_rx_request,<br> };<br> <br>+/*! \brief Thread keeping things alive */<br>+static pthread_t check_thread = AST_PTHREADT_NULL;<br>+<br>+/*! \brief The global interval at which to check for contact expiration */<br>+static unsigned int check_interval;<br>+<br>+/*! \brief Callback function which deletes a contact */<br>+static int expire_contact(void *obj, void *arg, int flags)<br>+{<br>+       struct ast_sip_contact *contact = obj;<br>+       struct ast_named_lock *lock;<br>+<br>+      lock = ast_named_lock_get(AST_NAMED_LOCK_TYPE_MUTEX, "aor", contact->aor);<br>+      if (!lock) {<br>+         return 0;<br>+    }<br>+<br>+ /*<br>+    * We need to check the expiration again with the aor lock held<br>+       * in case another thread is attempting to renew the contact.<br>+         */<br>+  ao2_lock(lock);<br>+      if (ast_tvdiff_ms(ast_tvnow(), contact->expiration_time) > 0) {<br>+                ast_sip_location_delete_contact(contact);<br>+    }<br>+    ao2_unlock(lock);<br>+    ast_named_lock_put(lock);<br>+<br>+ return 0;<br>+}<br>+<br>+static void *check_expiration_thread(void *data)<br>+{<br>+      struct ao2_container *contacts;<br>+      struct ast_variable *var;<br>+    char *time = alloca(64);<br>+<br>+  while (check_interval) {<br>+             sleep(check_interval);<br>+<br>+            sprintf(time, "%ld", ast_tvnow().tv_sec);<br>+          var = ast_variable_new("expiration_time <=", time, "");<br>+<br>+            ast_debug(4, "Woke up at %s  Interval: %d\n", time, check_interval);<br>+<br>+            contacts = ast_sorcery_retrieve_by_fields(ast_sip_get_sorcery(), "contact",<br>+                        AST_RETRIEVE_FLAG_MULTIPLE, var);<br>+<br>+         ast_variables_destroy(var);<br>+          if (contacts) {<br>+                      ast_debug(3, "Expiring %d contacts\n", ao2_container_count(contacts));<br>+                     ao2_callback(contacts, OBJ_NODATA, expire_contact, NULL);<br>+                    ao2_ref(contacts, -1);<br>+               }<br>+    }<br>+<br>+ return NULL;<br>+}<br>+<br>+static void expiration_global_loaded(const char *object_type)<br>+{<br>+      check_interval = ast_sip_get_contact_expiration_check_interval();<br>+<br>+ /* Observer calls are serialized so this is safe without it's own lock */<br>+        if (check_interval) {<br>+                if (check_thread == AST_PTHREADT_NULL) {<br>+                     if (ast_pthread_create_background(&check_thread, NULL, check_expiration_thread, NULL)) {<br>+                         ast_log(LOG_ERROR, "Could not create thread for checking contact expiration.\n");<br>+                          return;<br>+                      }<br>+                    ast_debug(3, "Interval = %d, starting thread\n", check_interval);<br>+          }<br>+    } else {<br>+             if (check_thread != AST_PTHREADT_NULL) {<br>+                     pthread_kill(check_thread, SIGURG);<br>+                  pthread_join(check_thread, NULL);<br>+                    check_thread = AST_PTHREADT_NULL;<br>+                    ast_debug(3, "Interval = 0, shutting thread down\n");<br>+              }<br>+    }<br>+}<br>+<br>+/*! \brief Observer which is used to update our interval when the global setting changes */<br>+static struct ast_sorcery_observer expiration_global_observer = {<br>+   .loaded = expiration_global_loaded,<br>+};<br>+<br> static int load_module(void)<br> {<br>        const pj_str_t STR_REGISTER = { "REGISTER", 8 };<br>@@ -1113,11 +1200,24 @@<br>   ast_manager_register_xml(AMI_SHOW_REGISTRATION_CONTACT_STATUSES, EVENT_FLAG_SYSTEM,<br>                            ami_show_registration_contact_statuses);<br> <br>+ ast_sorcery_observer_add(ast_sip_get_sorcery(), "global", &expiration_global_observer);<br>+        ast_sorcery_reload_object(ast_sip_get_sorcery(), "global");<br>+<br>      return AST_MODULE_LOAD_SUCCESS;<br> }<br> <br> static int unload_module(void)<br> {<br>+  if (check_thread != AST_PTHREADT_NULL) {<br>+             check_interval = 0;<br>+          pthread_kill(check_thread, SIGURG);<br>+          pthread_join(check_thread, NULL);<br>+<br>+         check_thread = AST_PTHREADT_NULL;<br>+    }<br>+<br>+ ast_sorcery_observer_remove(ast_sip_get_sorcery(), "global", &expiration_global_observer);<br>+<br>   ast_manager_unregister(AMI_SHOW_REGISTRATIONS);<br>       ast_manager_unregister(AMI_SHOW_REGISTRATION_CONTACT_STATUSES);<br>       ast_sip_unregister_service(&registrar_module);<br>diff --git a/res/res_pjsip_registrar_expire.c b/res/res_pjsip_registrar_expire.c<br>index e89ea03..4c21895 100644<br>--- a/res/res_pjsip_registrar_expire.c<br>+++ b/res/res_pjsip_registrar_expire.c<br>@@ -19,132 +19,29 @@<br> /*** MODULEINFO<br>   <depend>pjproject</depend><br>        <depend>res_pjsip</depend><br>-       <support_level>core</support_level><br>+      <support_level>extended</support_level><br>  ***/<br>+<br>+/*<br>+ * This module has been refactored into res_pjsip_registrar<br>+ */<br> <br> #include "asterisk.h"<br> <br>-#include <pjsip.h><br>-#include <sys/time.h><br>-#include <signal.h><br>-<br>-#include "asterisk/res_pjsip.h"<br> #include "asterisk/module.h"<br>-#include "asterisk/named_locks.h"<br>-<br>-/*! \brief Thread keeping things alive */<br>-static pthread_t check_thread = AST_PTHREADT_NULL;<br>-<br>-/*! \brief The global interval at which to check for contact expiration */<br>-static unsigned int check_interval;<br>-<br>-/*! \brief Callback function which deletes a contact */<br>-static int expire_contact(void *obj, void *arg, int flags)<br>-{<br>-   struct ast_sip_contact *contact = obj;<br>-       struct ast_named_lock *lock;<br>-<br>-      lock = ast_named_lock_get(AST_NAMED_LOCK_TYPE_MUTEX, "aor", contact->aor);<br>-      if (!lock) {<br>-         return 0;<br>-    }<br>-<br>- /*<br>-    * We need to check the expiration again with the aor lock held<br>-       * in case another thread is attempting to renew the contact.<br>-         */<br>-  ao2_lock(lock);<br>-      if (ast_tvdiff_ms(ast_tvnow(), contact->expiration_time) > 0) {<br>-                ast_sip_location_delete_contact(contact);<br>-    }<br>-    ao2_unlock(lock);<br>-    ast_named_lock_put(lock);<br>-<br>- return 0;<br>-}<br>-<br>-static void *check_expiration_thread(void *data)<br>-{<br>-      struct ao2_container *contacts;<br>-      struct ast_variable *var;<br>-    char *time = alloca(64);<br>-<br>-  while (check_interval) {<br>-             sleep(check_interval);<br>-<br>-            sprintf(time, "%ld", ast_tvnow().tv_sec);<br>-          var = ast_variable_new("expiration_time <=", time, "");<br>-<br>-            ast_debug(4, "Woke up at %s  Interval: %d\n", time, check_interval);<br>-<br>-            contacts = ast_sorcery_retrieve_by_fields(ast_sip_get_sorcery(), "contact",<br>-                        AST_RETRIEVE_FLAG_MULTIPLE, var);<br>-<br>-         ast_variables_destroy(var);<br>-          if (contacts) {<br>-                      ast_debug(3, "Expiring %d contacts\n", ao2_container_count(contacts));<br>-                     ao2_callback(contacts, OBJ_NODATA, expire_contact, NULL);<br>-                    ao2_ref(contacts, -1);<br>-               }<br>-    }<br>-<br>- return NULL;<br>-}<br>-<br>-static void expiration_global_loaded(const char *object_type)<br>-{<br>-      check_interval = ast_sip_get_contact_expiration_check_interval();<br>-<br>- /* Observer calls are serialized so this is safe without it's own lock */<br>-        if (check_interval) {<br>-                if (check_thread == AST_PTHREADT_NULL) {<br>-                     if (ast_pthread_create_background(&check_thread, NULL, check_expiration_thread, NULL)) {<br>-                         ast_log(LOG_ERROR, "Could not create thread for checking contact expiration.\n");<br>-                          return;<br>-                      }<br>-                    ast_debug(3, "Interval = %d, starting thread\n", check_interval);<br>-          }<br>-    } else {<br>-             if (check_thread != AST_PTHREADT_NULL) {<br>-                     pthread_kill(check_thread, SIGURG);<br>-                  pthread_join(check_thread, NULL);<br>-                    check_thread = AST_PTHREADT_NULL;<br>-                    ast_debug(3, "Interval = 0, shutting thread down\n");<br>-              }<br>-    }<br>-}<br>-<br>-/*! \brief Observer which is used to update our interval when the global setting changes */<br>-static struct ast_sorcery_observer expiration_global_observer = {<br>-   .loaded = expiration_global_loaded,<br>-};<br> <br> static int unload_module(void)<br> {<br>-     if (check_thread != AST_PTHREADT_NULL) {<br>-             check_interval = 0;<br>-          pthread_kill(check_thread, SIGURG);<br>-          pthread_join(check_thread, NULL);<br>-<br>-         check_thread = AST_PTHREADT_NULL;<br>-    }<br>-<br>- ast_sorcery_observer_remove(ast_sip_get_sorcery(), "global", &expiration_global_observer);<br>-<br>   return 0;<br> }<br> <br>-<br> static int load_module(void)<br> {<br>-       ast_sorcery_observer_add(ast_sip_get_sorcery(), "global", &expiration_global_observer);<br>-        ast_sorcery_reload_object(ast_sip_get_sorcery(), "global");<br>-<br>      return AST_MODULE_LOAD_SUCCESS;<br> }<br> <br>-AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "PJSIP Contact Auto-Expiration",<br>-        .support_level = AST_MODULE_SUPPORT_CORE,<br>+AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "OBSOLETE PJSIP Contact Auto-Expiration",<br>+    .support_level = AST_MODULE_SUPPORT_EXTENDED,<br>         .load = load_module,<br>  .unload = unload_module,<br>      .load_pri = AST_MODPRI_APP_DEPEND,<br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/8102">change 8102</a>. To unsubscribe, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/8102"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>
<div style="display:none"> Gerrit-Change-Id: Ib93698938bae548d2199cb542f3692d1a171239f </div>
<div style="display:none"> Gerrit-Change-Number: 8102 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: George Joseph <gjoseph@digium.com> </div>