<h1>Project "FreeSWITCH Source" received a push.</h1>

<h2>branch: master updated</h2>
<pre>
       via: a2c0da53f368f0b11340c3a72814c93b182753b7 (commit)
      from: 88d410d31485d13911f0958af5a73f1f6f49a454 (commit)


</pre>= COMMIT LOG ===========================================================
<div class="highlight"><pre>committer: Anthony Minessale
comments: 
add centralized registration db to core db and use it from mod_sofia

<span style="color: #000080; font-weight: bold">diff --git a/src/include/switch_core.h b/src/include/switch_core.h</span>
<span style="color: #000080; font-weight: bold">index 69b0642..984b54f 100644</span>
<span style="color: #A00000">--- a/src/include/switch_core.h</span>
<span style="color: #00A000">+++ b/src/include/switch_core.h</span>
<span style="color: #800080; font-weight: bold">@@ -2227,6 +2227,11 @@ SWITCH_DECLARE(const char *) switch_core_banner(void);</span>
 SWITCH_DECLARE(switch_bool_t) switch_core_session_in_thread(switch_core_session_t *session);
 SWITCH_DECLARE(uint32_t) switch_default_ptime(const char *name, uint32_t number);
 
<span style="color: #00A000">+SWITCH_DECLARE(switch_status_t) switch_core_add_registration(const char *user, const char *realm, const char *token, const char *url, uint32_t expires, </span>
<span style="color: #00A000">+                                                                                                                         const char *network_ip, const char *network_port, const char *network_proto);</span>
<span style="color: #00A000">+SWITCH_DECLARE(switch_status_t) switch_core_del_registration(const char *user, const char *realm, const char *token);</span>
<span style="color: #00A000">+SWITCH_DECLARE(switch_status_t) switch_core_expire_registration(int force);</span>
<span style="color: #00A000">+</span>
 SWITCH_END_EXTERN_C
 #endif
 /* For Emacs:
<span style="color: #000080; font-weight: bold">diff --git a/src/mod/applications/mod_commands/mod_commands.c b/src/mod/applications/mod_commands/mod_commands.c</span>
<span style="color: #000080; font-weight: bold">index f34042a..030cb8e 100644</span>
<span style="color: #A00000">--- a/src/mod/applications/mod_commands/mod_commands.c</span>
<span style="color: #00A000">+++ b/src/mod/applications/mod_commands/mod_commands.c</span>
<span style="color: #800080; font-weight: bold">@@ -45,6 +45,149 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_commands_load);</span>
 SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_commands_shutdown);
 SWITCH_MODULE_DEFINITION(mod_commands, mod_commands_load, mod_commands_shutdown, NULL);
 
<span style="color: #00A000">+</span>
<span style="color: #00A000">+struct cb_helper {</span>
<span style="color: #00A000">+        uint32_t row_process;</span>
<span style="color: #00A000">+        switch_stream_handle_t *stream;</span>
<span style="color: #00A000">+};</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+static int url_callback(void *pArg, int argc, char **argv, char **columnNames)</span>
<span style="color: #00A000">+{</span>
<span style="color: #00A000">+        struct cb_helper *cb = (struct cb_helper *) pArg;</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+        cb-&gt;row_process++;</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+        if (!zstr(argv[0])) {</span>
<span style="color: #00A000">+                cb-&gt;stream-&gt;write_function(cb-&gt;stream, &quot;%s,&quot;, argv[0]);</span>
<span style="color: #00A000">+        }</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+        return 0;</span>
<span style="color: #00A000">+}</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+static switch_status_t select_url(const char *user,</span>
<span style="color: #00A000">+                                           const char *domain,</span>
<span style="color: #00A000">+                                           const char *concat,</span>
<span style="color: #00A000">+                                           const char *exclude_contact, </span>
<span style="color: #00A000">+                                           switch_stream_handle_t *stream)</span>
<span style="color: #00A000">+{</span>
<span style="color: #00A000">+        struct cb_helper cb;</span>
<span style="color: #00A000">+        char *sql, *errmsg = NULL;</span>
<span style="color: #00A000">+        switch_core_flag_t cflags = switch_core_flags();</span>
<span style="color: #00A000">+        switch_cache_db_handle_t *db = NULL;</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+        if (!(cflags &amp; SCF_USE_SQL)) {</span>
<span style="color: #00A000">+                stream-&gt;write_function(stream, &quot;-ERR SQL DISABLED NO DATA AVAILABLE!\n&quot;);</span>
<span style="color: #00A000">+                return SWITCH_STATUS_SUCCESS;</span>
<span style="color: #00A000">+        }</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+        if (switch_core_db_handle(&amp;db) != SWITCH_STATUS_SUCCESS) {</span>
<span style="color: #00A000">+                stream-&gt;write_function(stream, &quot;%s&quot;, &quot;-ERR Databse Error!\n&quot;);</span>
<span style="color: #00A000">+                return SWITCH_STATUS_SUCCESS;</span>
<span style="color: #00A000">+        }</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+        cb.row_process = 0;</span>
<span style="color: #00A000">+        cb.stream = stream;</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+        if (exclude_contact) {</span>
<span style="color: #00A000">+                sql = switch_mprintf(&quot;select url, &#39;%q&#39; &quot;</span>
<span style="color: #00A000">+                                                         &quot;from registrations where user=&#39;%q&#39; and realm=&#39;%q&#39; &quot;</span>
<span style="color: #00A000">+                                                         &quot;and url not like &#39;%%%s%%&#39;&quot;, (concat != NULL) ? concat : &quot;&quot;, user, domain, exclude_contact);</span>
<span style="color: #00A000">+        } else {</span>
<span style="color: #00A000">+                sql = switch_mprintf(&quot;select url, &#39;%q&#39; &quot;</span>
<span style="color: #00A000">+                                                         &quot;from registrations where user=&#39;%q&#39; and realm=&#39;%q&#39;&quot;,</span>
<span style="color: #00A000">+                                                         (concat != NULL) ? concat : &quot;&quot;, user, domain);</span>
<span style="color: #00A000">+        }</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+        switch_assert(sql);</span>
<span style="color: #00A000">+        switch_cache_db_execute_sql_callback(db, sql, url_callback, &amp;cb, &amp;errmsg);</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+        if (errmsg) {</span>
<span style="color: #00A000">+                stream-&gt;write_function(stream, &quot;-ERR SQL Error [%s]\n&quot;, errmsg);</span>
<span style="color: #00A000">+                free(errmsg);</span>
<span style="color: #00A000">+                errmsg = NULL;</span>
<span style="color: #00A000">+        }        </span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+        switch_safe_free(sql);</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+        if (db) {</span>
<span style="color: #00A000">+                switch_cache_db_release_db_handle(&amp;db);</span>
<span style="color: #00A000">+        }</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+        return SWITCH_STATUS_SUCCESS;</span>
<span style="color: #00A000">+}</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+SWITCH_STANDARD_API(reg_url_function)</span>
<span style="color: #00A000">+{</span>
<span style="color: #00A000">+        char *data;</span>
<span style="color: #00A000">+        char *user = NULL;</span>
<span style="color: #00A000">+        char *domain = NULL, *dup_domain = NULL;</span>
<span style="color: #00A000">+        char *concat = NULL;</span>
<span style="color: #00A000">+        const char *exclude_contact = NULL;</span>
<span style="color: #00A000">+        char *reply = &quot;error/facility_not_subscribed&quot;;</span>
<span style="color: #00A000">+        switch_stream_handle_t mystream = { 0 };</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+        if (!cmd) {</span>
<span style="color: #00A000">+                stream-&gt;write_function(stream, &quot;%s&quot;, &quot;&quot;);</span>
<span style="color: #00A000">+                return SWITCH_STATUS_SUCCESS;</span>
<span style="color: #00A000">+        }</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+        if (session) {</span>
<span style="color: #00A000">+                switch_channel_t *channel = switch_core_session_get_channel(session);</span>
<span style="color: #00A000">+                exclude_contact = switch_channel_get_variable(channel, &quot;sip_exclude_contact&quot;);</span>
<span style="color: #00A000">+        }</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+        </span>
<span style="color: #00A000">+        data = strdup(cmd);</span>
<span style="color: #00A000">+        switch_assert(data);</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+        user = data;</span>
<span style="color: #00A000">+        </span>
<span style="color: #00A000">+        if ((domain = strchr(user, &#39;@&#39;))) {</span>
<span style="color: #00A000">+                *domain++ = &#39;\0&#39;;</span>
<span style="color: #00A000">+                if ((concat = strchr(domain, &#39;/&#39;))) {</span>
<span style="color: #00A000">+                        *concat++ = &#39;\0&#39;;</span>
<span style="color: #00A000">+                }</span>
<span style="color: #00A000">+        } else {</span>
<span style="color: #00A000">+                if ((concat = strchr(user, &#39;/&#39;))) {</span>
<span style="color: #00A000">+                        *concat++ = &#39;\0&#39;;</span>
<span style="color: #00A000">+                }</span>
<span style="color: #00A000">+        }</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+        if (zstr(domain)) {</span>
<span style="color: #00A000">+                dup_domain = switch_core_get_variable_dup(&quot;domain&quot;);</span>
<span style="color: #00A000">+                domain = dup_domain;</span>
<span style="color: #00A000">+        }</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+        if (!user) goto end;</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+        </span>
<span style="color: #00A000">+        SWITCH_STANDARD_STREAM(mystream);</span>
<span style="color: #00A000">+        switch_assert(mystream.data);</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+        select_url(user, domain, concat, exclude_contact, &amp;mystream);</span>
<span style="color: #00A000">+        reply = mystream.data;</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+ end:</span>
<span style="color: #00A000">+        </span>
<span style="color: #00A000">+        if (zstr(reply)) {</span>
<span style="color: #00A000">+                reply = &quot;error/user_not_registered&quot;;</span>
<span style="color: #00A000">+        } else if (end_of(reply) == &#39;,&#39;) {</span>
<span style="color: #00A000">+                end_of(reply) = &#39;\0&#39;;</span>
<span style="color: #00A000">+        }</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+        stream-&gt;write_function(stream, &quot;%s&quot;, reply);</span>
<span style="color: #00A000">+        reply = NULL;</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+        switch_safe_free(mystream.data);                                        </span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+        switch_safe_free(data);</span>
<span style="color: #00A000">+        switch_safe_free(dup_domain);</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+        return SWITCH_STATUS_SUCCESS;</span>
<span style="color: #00A000">+}</span>
<span style="color: #00A000">+</span>
 SWITCH_STANDARD_API(banner_function)
 {
         stream-&gt;write_function(stream, &quot;%s&quot;, switch_core_banner());
<span style="color: #800080; font-weight: bold">@@ -3738,6 +3881,14 @@ SWITCH_STANDARD_API(show_function)</span>
                                 as = argv[3];
                         }
                 }
<span style="color: #00A000">+        } else if (!strcasecmp(command, &quot;registrations&quot;)) {</span>
<span style="color: #00A000">+                sprintf(sql, &quot;select * from registrations where hostname=&#39;%s&#39;&quot;, hostname);</span>
<span style="color: #00A000">+                if (argv[1] &amp;&amp; !strcasecmp(argv[1], &quot;count&quot;)) {</span>
<span style="color: #00A000">+                        holder.justcount = 1;</span>
<span style="color: #00A000">+                        if (argv[3] &amp;&amp; !strcasecmp(argv[2], &quot;as&quot;)) {</span>
<span style="color: #00A000">+                                as = argv[3];</span>
<span style="color: #00A000">+                        }</span>
<span style="color: #00A000">+                }</span>
         } else if (!strcasecmp(command, &quot;channels&quot;) &amp;&amp; argv[1] &amp;&amp; !strcasecmp(argv[1], &quot;like&quot;)) {
                 if (argv[2]) {
                         char *p;
<span style="color: #800080; font-weight: bold">@@ -4890,6 +5041,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_commands_load)</span>
         SWITCH_ADD_API(commands_api_interface, &quot;tone_detect&quot;, &quot;Start Tone Detection on a channel&quot;, tone_detect_session_function, TONE_DETECT_SYNTAX);
         SWITCH_ADD_API(commands_api_interface, &quot;unload&quot;, &quot;Unload Module&quot;, unload_function, UNLOAD_SYNTAX);
         SWITCH_ADD_API(commands_api_interface, &quot;unsched_api&quot;, &quot;Unschedule an api command&quot;, unsched_api_function, UNSCHED_SYNTAX);
<span style="color: #00A000">+        SWITCH_ADD_API(commands_api_interface, &quot;reg_url&quot;, &quot;&quot;, reg_url_function, &quot;&lt;user&gt;@&lt;realm&gt;&quot;);</span>
         SWITCH_ADD_API(commands_api_interface, &quot;url_decode&quot;, &quot;url decode a string&quot;, url_decode_function, &quot;&lt;string&gt;&quot;);
         SWITCH_ADD_API(commands_api_interface, &quot;url_encode&quot;, &quot;url encode a string&quot;, url_encode_function, &quot;&lt;string&gt;&quot;);
         SWITCH_ADD_API(commands_api_interface, &quot;user_data&quot;, &quot;find user data&quot;, user_data_function, &quot;&lt;user&gt;@&lt;domain&gt; [var|param|attr] &lt;name&gt;&quot;);
<span style="color: #800080; font-weight: bold">@@ -5000,6 +5152,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_commands_load)</span>
         switch_console_set_complete(&quot;add show management&quot;);
         switch_console_set_complete(&quot;add show modules&quot;);
         switch_console_set_complete(&quot;add show nat_map&quot;);
<span style="color: #00A000">+        switch_console_set_complete(&quot;add show registrations&quot;);</span>
         switch_console_set_complete(&quot;add show say&quot;);
         switch_console_set_complete(&quot;add show timer&quot;);
         switch_console_set_complete(&quot;add shutdown&quot;);
<span style="color: #000080; font-weight: bold">diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.c b/src/mod/endpoints/mod_sofia/mod_sofia.c</span>
<span style="color: #000080; font-weight: bold">index 07c285f..4853dff 100644</span>
<span style="color: #A00000">--- a/src/mod/endpoints/mod_sofia/mod_sofia.c</span>
<span style="color: #00A000">+++ b/src/mod/endpoints/mod_sofia/mod_sofia.c</span>
<span style="color: #800080; font-weight: bold">@@ -3314,6 +3314,7 @@ static int contact_callback(void *pArg, int argc, char **argv, char **columnName</span>
 
         return 0;
 }
<span style="color: #00A000">+</span>
 static int sql2str_callback(void *pArg, int argc, char **argv, char **columnNames)
 {
         struct cb_helper_sql2str *cbt = (struct cb_helper_sql2str *) pArg;
<span style="color: #000080; font-weight: bold">diff --git a/src/mod/endpoints/mod_sofia/sofia_reg.c b/src/mod/endpoints/mod_sofia/sofia_reg.c</span>
<span style="color: #000080; font-weight: bold">index 631cbdb..76b1dcc 100644</span>
<span style="color: #A00000">--- a/src/mod/endpoints/mod_sofia/sofia_reg.c</span>
<span style="color: #00A000">+++ b/src/mod/endpoints/mod_sofia/sofia_reg.c</span>
<span style="color: #800080; font-weight: bold">@@ -877,6 +877,7 @@ uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_hand</span>
         const char *agent = &quot;unknown&quot;;
         const char *pres_on_reg = NULL;
         int send_pres = 0;
<span style="color: #00A000">+        int is_tls = 0, is_tcp = 0;</span>
 
         delete_subs = sofia_test_pflag(profile, PFLAG_DEL_SUBS_ON_REG);
 
<span style="color: #800080; font-weight: bold">@@ -944,8 +945,6 @@ uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_hand</span>
                 char *path_encoded = NULL;
                 int path_encoded_len = 0;
                 const char *proto = &quot;sip&quot;;
<span style="color: #A00000">-                int is_tls = 0, is_tcp = 0;</span>
<span style="color: #A00000">-</span>
 
                 if (switch_stristr(&quot;transport=tls&quot;, sip-&gt;sip_contact-&gt;m_url-&gt;url_params)) {
                         is_tls += 1;
<span style="color: #800080; font-weight: bold">@@ -1292,6 +1291,8 @@ uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_hand</span>
                 char guess_ip4[256];
                 const char *username = &quot;unknown&quot;;
                 const char *realm = reg_host;
<span style="color: #00A000">+                char *url = NULL;</span>
<span style="color: #00A000">+                char *contact = NULL;</span>
 
                 if (auth_params) {
                         username = switch_event_get_header(auth_params, &quot;sip_auth_username&quot;);
<span style="color: #800080; font-weight: bold">@@ -1327,7 +1328,15 @@ uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_hand</span>
 
                 switch_find_local_ip(guess_ip4, sizeof(guess_ip4), NULL, AF_INET);
 
<span style="color: #00A000">+                contact = sofia_glue_get_url_from_contact(contact_str, 1);</span>
<span style="color: #00A000">+                url = switch_mprintf(&quot;sofia/%q/sip:%q&quot;, profile-&gt;name, sofia_glue_strip_proto(contact));</span>
                 
<span style="color: #00A000">+                switch_core_add_registration(to_user, reg_host, call_id, url, (long) switch_epoch_time_now(NULL) + (long) exptime + 60,</span>
<span style="color: #00A000">+                                                                         network_ip, network_port_c, is_tls ? &quot;tls&quot; : is_tcp ? &quot;tcp&quot; : &quot;udp&quot;);</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+                switch_safe_free(url);</span>
<span style="color: #00A000">+                switch_safe_free(contact);</span>
<span style="color: #00A000">+</span>
                 sql = switch_mprintf(&quot;insert into sip_registrations &quot;
                                                          &quot;(call_id,sip_user,sip_host,presence_hosts,contact,status,rpid,expires,&quot;
                                                          &quot;user_agent,server_user,server_host,profile_name,hostname,network_ip,network_port,sip_username,sip_realm,&quot;
<span style="color: #000080; font-weight: bold">diff --git a/src/switch_core_sqldb.c b/src/switch_core_sqldb.c</span>
<span style="color: #000080; font-weight: bold">index 73890a1..ba92ebc 100644</span>
<span style="color: #A00000">--- a/src/switch_core_sqldb.c</span>
<span style="color: #00A000">+++ b/src/switch_core_sqldb.c</span>
<span style="color: #800080; font-weight: bold">@@ -87,6 +87,7 @@ SWITCH_DECLARE(switch_status_t) _switch_core_db_handle(switch_cache_db_handle_t</span>
 
 
 #define SQL_CACHE_TIMEOUT 120
<span style="color: #00A000">+#define SQL_REG_TIMEOUT 15</span>
 
 static void sql_close(time_t prune)
 {
<span style="color: #800080; font-weight: bold">@@ -906,7 +907,7 @@ SWITCH_DECLARE(switch_bool_t) switch_cache_db_test_reactive(switch_cache_db_hand</span>
 
 static void *SWITCH_THREAD_FUNC switch_core_sql_db_thread(switch_thread_t *thread, void *obj)
 {
<span style="color: #A00000">-        int sec = 0;</span>
<span style="color: #00A000">+        int sec = 0, reg_sec = 0;;</span>
 
         sql_manager.db_thread_running = 1;
 
<span style="color: #800080; font-weight: bold">@@ -916,6 +917,11 @@ static void *SWITCH_THREAD_FUNC switch_core_sql_db_thread(switch_thread_t *threa</span>
                         wake_thread(0);
                         sec = 0;
                 }
<span style="color: #00A000">+</span>
<span style="color: #00A000">+                if (++reg_sec == SQL_REG_TIMEOUT) {</span>
<span style="color: #00A000">+                        switch_core_expire_registration(0);</span>
<span style="color: #00A000">+                        reg_sec = 0;</span>
<span style="color: #00A000">+                }</span>
                 switch_yield(1000000);
         }
 
<span style="color: #800080; font-weight: bold">@@ -1616,6 +1622,108 @@ static char create_nat_sql[] =</span>
         &quot;   hostname VARCHAR(256)\n&quot;
         &quot;);\n&quot;;
 
<span style="color: #00A000">+</span>
<span style="color: #00A000">+static char create_registrations_sql[] =</span>
<span style="color: #00A000">+        &quot;CREATE TABLE registrations (\n&quot;</span>
<span style="color: #00A000">+        &quot;   user      VARCHAR(256),\n&quot;</span>
<span style="color: #00A000">+        &quot;   realm     VARCHAR(256),\n&quot;</span>
<span style="color: #00A000">+        &quot;   token     VARCHAR(256),\n&quot;</span>
<span style="color: #00A000">+        &quot;   url      TEXT,\n&quot;</span>
<span style="color: #00A000">+        &quot;   expires  INTEGER,\n&quot;</span>
<span style="color: #00A000">+        &quot;   network_ip VARCHAR(256),\n&quot;</span>
<span style="color: #00A000">+        &quot;   network_port VARCHAR(256),\n&quot;</span>
<span style="color: #00A000">+        &quot;   network_proto VARCHAR(256),\n&quot;</span>
<span style="color: #00A000">+        &quot;   hostname VARCHAR(256)\n&quot;</span>
<span style="color: #00A000">+        &quot;);\n&quot;</span>
<span style="color: #00A000">+        &quot;create index regindex1 on registrations (user,real,hostname);\n&quot;;</span>
<span style="color: #00A000">+        </span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+SWITCH_DECLARE(switch_status_t) switch_core_add_registration(const char *user, const char *realm, const char *token, const char *url, uint32_t expires, </span>
<span style="color: #00A000">+                                                                                                                         const char *network_ip, const char *network_port, const char *network_proto)</span>
<span style="color: #00A000">+{</span>
<span style="color: #00A000">+        switch_cache_db_handle_t *dbh;</span>
<span style="color: #00A000">+        char *sql;</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+        if (switch_core_db_handle(&amp;dbh) != SWITCH_STATUS_SUCCESS) {</span>
<span style="color: #00A000">+                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, &quot;Error Opening DB!\n&quot;);</span>
<span style="color: #00A000">+                return SWITCH_STATUS_FALSE;</span>
<span style="color: #00A000">+        }</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+        sql = switch_mprintf(&quot;delete from registrations where hostname=&#39;%q&#39; and (url=&#39;%q&#39; or token=&#39;%q&#39;)&quot;, switch_core_get_hostname(), url, switch_str_nil(token));</span>
<span style="color: #00A000">+        switch_cache_db_execute_sql(dbh, sql, NULL);</span>
<span style="color: #00A000">+        free(sql);</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+        sql = switch_mprintf(&quot;insert into registrations (user,realm,token,url,expires,network_ip,network_port,network_proto,hostname) &quot;</span>
<span style="color: #00A000">+                                                 &quot;values (&#39;%q&#39;,&#39;%q&#39;,&#39;%q&#39;,&#39;%q&#39;,%ld,&#39;%q&#39;,&#39;%q&#39;,&#39;%q&#39;,&#39;%q&#39;)&quot;,</span>
<span style="color: #00A000">+                                                 switch_str_nil(user),</span>
<span style="color: #00A000">+                                                 switch_str_nil(realm),</span>
<span style="color: #00A000">+                                                 switch_str_nil(token),</span>
<span style="color: #00A000">+                                                 switch_str_nil(url),</span>
<span style="color: #00A000">+                                                 expires,</span>
<span style="color: #00A000">+                                                 switch_str_nil(network_ip),</span>
<span style="color: #00A000">+                                                 switch_str_nil(network_port),</span>
<span style="color: #00A000">+                                                 switch_str_nil(network_proto),</span>
<span style="color: #00A000">+                                                 switch_core_get_hostname()</span>
<span style="color: #00A000">+                                                 );</span>
<span style="color: #00A000">+        </span>
<span style="color: #00A000">+        switch_cache_db_execute_sql(dbh, sql, NULL);</span>
<span style="color: #00A000">+        switch_cache_db_release_db_handle(&amp;dbh);</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+        free(sql);</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+        return SWITCH_STATUS_SUCCESS;</span>
<span style="color: #00A000">+}</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+SWITCH_DECLARE(switch_status_t) switch_core_del_registration(const char *user, const char *realm, const char *token)</span>
<span style="color: #00A000">+{</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+        switch_cache_db_handle_t *dbh;</span>
<span style="color: #00A000">+        char *sql;</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+        if (switch_core_db_handle(&amp;dbh) != SWITCH_STATUS_SUCCESS) {</span>
<span style="color: #00A000">+                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, &quot;Error Opening DB!\n&quot;);</span>
<span style="color: #00A000">+                return SWITCH_STATUS_FALSE;</span>
<span style="color: #00A000">+        }</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+        sql = switch_mprintf(&quot;delete from registrations where user=&#39;%q&#39; and realm=&#39;%q&#39; and hostname=&#39;%q&#39;&quot;, user, realm, switch_core_get_hostname());</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+        switch_cache_db_execute_sql(dbh, sql, NULL);</span>
<span style="color: #00A000">+        switch_cache_db_release_db_handle(&amp;dbh);</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+        free(sql);</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+        return SWITCH_STATUS_SUCCESS;</span>
<span style="color: #00A000">+}</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+SWITCH_DECLARE(switch_status_t) switch_core_expire_registration(int force)</span>
<span style="color: #00A000">+{</span>
<span style="color: #00A000">+        </span>
<span style="color: #00A000">+        switch_cache_db_handle_t *dbh;</span>
<span style="color: #00A000">+        char *sql;</span>
<span style="color: #00A000">+        switch_time_t now;</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+        if (switch_core_db_handle(&amp;dbh) != SWITCH_STATUS_SUCCESS) {</span>
<span style="color: #00A000">+                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, &quot;Error Opening DB!\n&quot;);</span>
<span style="color: #00A000">+                return SWITCH_STATUS_FALSE;</span>
<span style="color: #00A000">+        }</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+        now = switch_epoch_time_now(NULL);</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+        if (force) {</span>
<span style="color: #00A000">+                sql = switch_mprintf(&quot;delete from registrations where hostname=&#39;%q&#39;&quot;, switch_core_get_hostname());</span>
<span style="color: #00A000">+        } else {</span>
<span style="color: #00A000">+                sql = switch_mprintf(&quot;delete from registrations where expires &lt;= %ld and hostname=&#39;%q&#39;&quot;, now, switch_core_get_hostname());</span>
<span style="color: #00A000">+        }</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+        switch_cache_db_execute_sql(dbh, sql, NULL);</span>
<span style="color: #00A000">+        switch_cache_db_release_db_handle(&amp;dbh);</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+        free(sql);</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+        return SWITCH_STATUS_SUCCESS;</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+}</span>
<span style="color: #00A000">+</span>
 switch_status_t switch_core_sqldb_start(switch_memory_pool_t *pool, switch_bool_t manage)
 {
         switch_threadattr_t *thd_attr;
<span style="color: #800080; font-weight: bold">@@ -1690,6 +1798,8 @@ switch_status_t switch_core_sqldb_start(switch_memory_pool_t *pool, switch_bool_</span>
         switch_cache_db_test_reactive(dbh, &quot;select hostname from complete&quot;, &quot;DROP TABLE complete&quot;, create_complete_sql);
         switch_cache_db_test_reactive(dbh, &quot;select hostname from aliases&quot;, &quot;DROP TABLE aliases&quot;, create_alias_sql);
         switch_cache_db_test_reactive(dbh, &quot;select hostname from nat&quot;, &quot;DROP TABLE nat&quot;, create_nat_sql);
<span style="color: #00A000">+        switch_cache_db_test_reactive(dbh, &quot;delete from registrations where network_proto=&#39;tcp&#39; or network_proto=&#39;tls&#39;&quot;, </span>
<span style="color: #00A000">+                                                                  &quot;DROP TABLE registrations&quot;, create_registrations_sql);</span>
 
 
         switch (dbh-&gt;type) {
<span style="color: #800080; font-weight: bold">@@ -1706,6 +1816,8 @@ switch_status_t switch_core_sqldb_start(switch_memory_pool_t *pool, switch_bool_</span>
                         }
                         switch_cache_db_test_reactive(dbh, &quot;select ikey from interfaces&quot;, &quot;DROP TABLE interfaces&quot;, create_interfaces_sql);
                         switch_cache_db_test_reactive(dbh, &quot;select hostname from tasks&quot;, &quot;DROP TABLE tasks&quot;, create_tasks_sql);
<span style="color: #00A000">+                        switch_cache_db_test_reactive(dbh, &quot;delete from registrations where network_proto=&#39;tcp&#39; or network_proto=&#39;tls&#39;&quot;, </span>
<span style="color: #00A000">+                                                                                  &quot;DROP TABLE registrations&quot;, create_registrations_sql);</span>
 
                         if (runtime.odbc_dbtype == DBTYPE_DEFAULT) {
                                 switch_cache_db_execute_sql(dbh, &quot;begin;delete from channels where hostname=&#39;&#39;;delete from channels where hostname=&#39;&#39;;commit;&quot;, &amp;err);
</pre></div>
========================================================================<pre>

Summary of changes:
 src/include/switch_core.h                        |    5 +
 src/mod/applications/mod_commands/mod_commands.c |  153 ++++++++++++++++++++++
 src/mod/endpoints/mod_sofia/mod_sofia.c          |    1 +
 src/mod/endpoints/mod_sofia/sofia_reg.c          |   13 ++-
 src/switch_core_sqldb.c                          |  114 ++++++++++++++++-
 5 files changed, 283 insertions(+), 3 deletions(-)
</pre>
<p>this email was generated because of /git/your-repo.git/hooks/post-receive by the file /git-core/contrib/hooks/post-receive-email<br />
For more info, see <a href="http://blog.chomperstomp.com/?p=630">http://blog.chomperstomp.com/?p=630</a>
-- <br />
FreeSWITCH Source</p>