fix regressions in sql stuff

This commit is contained in:
Michael Jerris 2012-11-27 13:48:57 -05:00
parent 92945f8a01
commit 827b680afc
3 changed files with 29 additions and 20 deletions

View File

@ -859,6 +859,9 @@ struct callback_t {
switch_size_t len; switch_size_t len;
switch_console_callback_match_t *list; switch_console_callback_match_t *list;
int matches; int matches;
time_t time;
const char *contact_str;
long exptime;
}; };
typedef enum { 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); 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); 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_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); switch_bool_t sofia_glue_profile_exists(const char *key);
void sofia_glue_global_siptrace(switch_bool_t on); void sofia_glue_global_siptrace(switch_bool_t on);
void sofia_glue_global_capture(switch_bool_t on); void sofia_glue_global_capture(switch_bool_t on);

View File

@ -524,7 +524,11 @@ int sofia_reg_find_reg_with_positive_expires_callback(void *pArg, int argc, char
long int expires; long int expires;
char *contact = NULL; 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) { if (expires > 0) {
dst = sofia_glue_get_destination(argv[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 }; struct callback_t cbt = { 0 };
char *sql; 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); 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); sofia_glue_execute_sql_callback(profile, profile->ireg_mutex, sql, sofia_reg_find_reg_with_positive_expires_callback, &cbt);
free(sql); 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 send_pres = 0;
int is_tls = 0, is_tcp = 0; int is_tls = 0, is_tcp = 0;
char expbuf[35] = ""; 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"); 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); contact = sofia_glue_get_url_from_contact(contact_str, 1);
url = switch_mprintf("sofia/%q/sip:%q", profile->name, sofia_glue_strip_proto(contact)); 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); network_ip, network_port_c, is_tls ? "tls" : is_tcp ? "tcp" : "udp", reg_meta);
switch_safe_free(url); 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) " "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')", "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 : "", 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, 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); mwi_user, mwi_host, guess_ip4, mod_sofia_globals.hostname, sub_host);
} else { } 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, sub_host, network_ip, network_port_c,
profile->presence_hosts ? profile->presence_hosts : "", guess_ip4, guess_ip4, profile->presence_hosts ? profile->presence_hosts : "", guess_ip4, guess_ip4,
mod_sofia_globals.hostname, mod_sofia_globals.hostname, 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); 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)), TAG_IF(!zstr(expbuf), SIPTAG_EXPIRES_STR(expbuf)),
NUTAG_WITH_THIS_MSG(de->data->e_msg), SIPTAG_DATE_STR(date), TAG_END()); 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() */ /* all + 1 tag_i elements initialized as NULL - last one implies TAG_END() */
switch_zmalloc(contact_tags, sizeof(*contact_tags) * (contact_list->count + 1)); switch_zmalloc(contact_tags, sizeof(*contact_tags) * (contact_list->count + 1));
i = 0; i = 0;
@ -2358,7 +2368,6 @@ auth_res_t sofia_reg_parse_auth(sofia_profile_t *profile,
if (zstr(np)) { if (zstr(np)) {
nonce_cb_t cb = { 0 }; nonce_cb_t cb = { 0 };
long nc_long = 0; long nc_long = 0;
int sanity = 0;
first = 1; first = 1;
@ -2374,13 +2383,7 @@ auth_res_t sofia_reg_parse_auth(sofia_profile_t *profile,
switch_assert(sql != NULL); switch_assert(sql != NULL);
do { sofia_glue_execute_sql_callback(profile, profile->ireg_mutex, sql, sofia_reg_nonce_callback, &cb);
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));
free(sql); free(sql);
//if (!sofia_glue_execute_sql2str(profile, profile->ireg_mutex, sql, np, nplen)) { //if (!sofia_glue_execute_sql2str(profile, profile->ireg_mutex, sql, np, nplen)) {

View File

@ -1706,11 +1706,14 @@ static void *SWITCH_THREAD_FUNC switch_user_sql_thread(switch_thread_t *thread,
check: check:
if ((lc = qm_ttl(qm)) < qm->max_trans / 4) { if ((lc = qm_ttl(qm)) == 0) {
switch_yield(500000); 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);
} }
} }