]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
fix regressions in sql stuff
authorMichael Jerris <mike@jerris.com>
Tue, 27 Nov 2012 18:48:57 +0000 (13:48 -0500)
committerMichael Jerris <mike@jerris.com>
Wed, 28 Nov 2012 02:14:05 +0000 (21:14 -0500)
src/mod/endpoints/mod_sofia/mod_sofia.h
src/mod/endpoints/mod_sofia/sofia_reg.c
src/switch_core_sqldb.c

index 45f73c58660aa7b96080a7784e8e16b6f9359f09..dc62141f2e22ffec1fc5235e6d7ed087607c9ff1 100644 (file)
@@ -859,6 +859,9 @@ struct callback_t {
        switch_size_t len;
        switch_console_callback_match_t *list;
        int matches;
+       time_t time;
+       const char *contact_str;
+       long exptime;
 };
 
 typedef enum {
@@ -1189,7 +1192,7 @@ switch_t38_options_t *sofia_glue_extract_t38_options(switch_core_session_t *sess
 char *sofia_glue_get_multipart(switch_core_session_t *session, const char *prefix, const char *sdp, char **mp_type);
 void sofia_glue_tech_simplify(private_object_t *tech_pvt);
 switch_console_callback_match_t *sofia_reg_find_reg_url_multi(sofia_profile_t *profile, const char *user, const char *host);
-switch_console_callback_match_t *sofia_reg_find_reg_url_with_positive_expires_multi(sofia_profile_t *profile, const char *user, const char *host);
+switch_console_callback_match_t *sofia_reg_find_reg_url_with_positive_expires_multi(sofia_profile_t *profile, const char *user, const char *host, time_t reg_time, const char *contact_str, long exptime);
 switch_bool_t sofia_glue_profile_exists(const char *key);
 void sofia_glue_global_siptrace(switch_bool_t on);
 void sofia_glue_global_capture(switch_bool_t on);
index d2bea6e5ea75d3c1b46dff54b7f4cd7bc2f5e425..7961f24e08db1f062c736dd3ce74d9776d510885 100644 (file)
@@ -524,7 +524,11 @@ int sofia_reg_find_reg_with_positive_expires_callback(void *pArg, int argc, char
        long int expires;
        char *contact = NULL;
 
-       expires = atol(argv[1]) - 60 - (long) switch_epoch_time_now(NULL);
+       if (argv[0] && cbt->contact_str && !strcasecmp(argv[0], cbt->contact_str)) {
+               expires = cbt->exptime;
+       } else {
+               expires = atol(argv[1]) - 60 - (long) cbt->time;
+       }
 
        if (expires > 0) {
                dst = sofia_glue_get_destination(argv[0]);
@@ -930,7 +934,7 @@ switch_console_callback_match_t *sofia_reg_find_reg_url_multi(sofia_profile_t *p
 }
 
 
-switch_console_callback_match_t *sofia_reg_find_reg_url_with_positive_expires_multi(sofia_profile_t *profile, const char *user, const char *host)
+switch_console_callback_match_t *sofia_reg_find_reg_url_with_positive_expires_multi(sofia_profile_t *profile, const char *user, const char *host, time_t reg_time, const char *contact_str, long exptime)
 {
        struct callback_t cbt = { 0 };
        char *sql;
@@ -947,6 +951,10 @@ switch_console_callback_match_t *sofia_reg_find_reg_url_with_positive_expires_mu
                sql = switch_mprintf("select contact,expires from sip_registrations where sip_user='%q'", user);
        }
 
+       cbt.time = reg_time;
+       cbt.contact_str = contact_str;
+       cbt.exptime = exptime;
+
        sofia_glue_execute_sql_callback(profile, profile->ireg_mutex, sql, sofia_reg_find_reg_with_positive_expires_callback, &cbt);
        free(sql);
 
@@ -1075,6 +1083,8 @@ uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_hand
        int send_pres = 0;
        int is_tls = 0, is_tcp = 0;
        char expbuf[35] = "";
+       time_t reg_time = switch_epoch_time_now(NULL);
+       
 
        if (v_event && *v_event) pres_on_reg = switch_event_get_header(*v_event, "send-presence-on-register");
 
@@ -1577,7 +1587,7 @@ uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_hand
                contact = sofia_glue_get_url_from_contact(contact_str, 1);
                url = switch_mprintf("sofia/%q/sip:%q", profile->name, sofia_glue_strip_proto(contact));
                
-               switch_core_add_registration(to_user, reg_host, call_id, url, (long) switch_epoch_time_now(NULL) + (long) exptime + 60,
+               switch_core_add_registration(to_user, reg_host, call_id, url, (long) reg_time + (long) exptime + 60,
                                                                         network_ip, network_port_c, is_tls ? "tls" : is_tcp ? "tcp" : "udp", reg_meta);
 
                switch_safe_free(url);
@@ -1590,7 +1600,7 @@ uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_hand
                                        "mwi_user,mwi_host, orig_server_host, orig_hostname, sub_host) "
                                        "values ('%q','%q', '%q','%q','%q','%q', '%q', %ld, '%q', '%q', '%q', '%q', '%q', '%q', '%q','%q','%q','%q','%q','%q','%q','%q')", 
                                        call_id, to_user, reg_host, profile->presence_hosts ? profile->presence_hosts : "", 
-                                       contact_str, reg_desc, rpid, (long) switch_epoch_time_now(NULL) + (long) exptime + 60, 
+                                       contact_str, reg_desc, rpid, (long) reg_time + (long) exptime + 60, 
                                        agent, from_user, guess_ip4, profile->name, mod_sofia_globals.hostname, network_ip, network_port_c, username, realm, 
                                                                 mwi_user, mwi_host, guess_ip4, mod_sofia_globals.hostname, sub_host);
                } else {
@@ -1602,7 +1612,7 @@ uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_hand
                                                                 sub_host, network_ip, network_port_c,
                                                                 profile->presence_hosts ? profile->presence_hosts : "", guess_ip4, guess_ip4,
                                                                  mod_sofia_globals.hostname, mod_sofia_globals.hostname,
-                                                                (long) switch_epoch_time_now(NULL) + (long) exptime + 60, 
+                                                                (long) reg_time + (long) exptime + 60, 
                                                                 to_user, username, reg_host, contact_str);
                }                                
 
@@ -1794,7 +1804,7 @@ uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_hand
                                                TAG_IF(!zstr(expbuf), SIPTAG_EXPIRES_STR(expbuf)),
                                                NUTAG_WITH_THIS_MSG(de->data->e_msg), SIPTAG_DATE_STR(date), TAG_END());
  
-               } else if ((contact_list = sofia_reg_find_reg_url_with_positive_expires_multi(profile, from_user, reg_host))) {
+               } else if ((contact_list = sofia_reg_find_reg_url_with_positive_expires_multi(profile, from_user, reg_host, reg_time, contact_str, exptime))) {
                        /* all + 1 tag_i elements initialized as NULL - last one implies TAG_END() */
                        switch_zmalloc(contact_tags, sizeof(*contact_tags) * (contact_list->count + 1));
                        i = 0;
@@ -2358,7 +2368,6 @@ auth_res_t sofia_reg_parse_auth(sofia_profile_t *profile,
        if (zstr(np)) {
                nonce_cb_t cb = { 0 };
                long nc_long = 0;
-               int sanity = 0;
 
                first = 1;
 
@@ -2374,13 +2383,7 @@ auth_res_t sofia_reg_parse_auth(sofia_profile_t *profile,
 
                switch_assert(sql != NULL);
 
-               do {
-                       if (sanity) {
-                               switch_yield(100000 * sanity);
-                       }
-                       sofia_glue_execute_sql_callback(profile, profile->ireg_mutex, sql, sofia_reg_nonce_callback, &cb);
-               } while(nc_long < 2 && ++sanity < 10 && zstr(np));
-
+               sofia_glue_execute_sql_callback(profile, profile->ireg_mutex, sql, sofia_reg_nonce_callback, &cb);
                free(sql);
 
                //if (!sofia_glue_execute_sql2str(profile, profile->ireg_mutex, sql, np, nplen)) {
index 3ad163b54e390a7fe025ef2a242a446afa44966e..c1381bd351fb6f6328194e93d4b2cb4d27be1988 100644 (file)
@@ -1706,11 +1706,14 @@ static void *SWITCH_THREAD_FUNC switch_user_sql_thread(switch_thread_t *thread,
 
        check:
 
-               if ((lc = qm_ttl(qm)) < qm->max_trans / 4) {
-                       switch_yield(500000);
-                       if ((lc = qm_ttl(qm)) == 0) {
-                               switch_thread_cond_wait(qm->cond, qm->cond_mutex);
-                       }
+               if ((lc = qm_ttl(qm)) == 0) {
+                       switch_thread_cond_wait(qm->cond, qm->cond_mutex);
+               }
+
+               i = 4;
+
+               while (--i > 0 && (lc = qm_ttl(qm)) < qm->max_trans / 4) {
+                       switch_yield(50000);
                }
        }