switch_hash_t *hash;
sofia_profile_t *profile;
switch_memory_pool_t *pool;
+ int total;
};
static int sofia_presence_sub_callback(void *pArg, int argc, char **argv, char **columnNames);
static int broadsoft_sla_gather_state_callback(void *pArg, int argc, char **argv, char **columnNames);
static int broadsoft_sla_notify_callback(void *pArg, int argc, char **argv, char **columnNames);
-static void sync_sla(sofia_profile_t *profile, const char *to_user, const char *to_host, switch_bool_t clear, switch_bool_t unseize);
+static int sync_sla(sofia_profile_t *profile, const char *to_user, const char *to_host, switch_bool_t clear, switch_bool_t unseize, const char *call_id);
static int sofia_dialog_probe_callback(void *pArg, int argc, char **argv, char **columnNames);
static int sofia_dialog_probe_notify_callback(void *pArg, int argc, char **argv, char **columnNames);
}
-static void do_normal_probe(sofia_profile_t *profile, switch_event_t *event)
+static void do_normal_probe(switch_event_t *event)
{
char *sql;
struct resub_helper h = { 0 };
char *proto = switch_event_get_header(event, "proto");
char *probe_user = NULL, *probe_euser, *probe_host, *p;
struct dialog_helper dh = { { 0 } };
+ char *sub_call_id = switch_event_get_header(event, "sub-call-id");
+ sofia_profile_t *profile;
//DUMP_EVENT(event);
sql = switch_mprintf("select status,rpid,presence_id from sip_dialogs "
"where ((sip_from_user='%q' and sip_from_host='%q') or presence_id='%q@%q') order by rcd desc",
probe_euser, probe_host, probe_euser, probe_host);
+
+
sofia_glue_execute_sql_callback(profile, profile->ireg_mutex, sql, sofia_presence_dialog_callback, &dh);
h.profile = profile;
"sip_presence.rpid,"
"sip_dialogs.presence_id, "
"sip_presence.open_closed,"
- "'%q','%q' "
+ "'%q','%q','%q' "
"from sip_registrations "
"left join sip_dialogs on "
"left join sip_presence on "
"(sip_registrations.sip_user=sip_presence.sip_user and sip_registrations.orig_server_host=sip_presence.sip_host and "
"sip_registrations.profile_name=sip_presence.profile_name) "
- "where sip_dialogs.presence_id='%q@%q' or (sip_registrations.sip_user='%q' and "
+ "where sip_dialogs.call_info_state != 'seized' and "
+ "(sip_registrations.profile_name='%q' or sip_registrations.presence_hosts like '%%%q%%') "
+ "and sip_dialogs.presence_id='%q@%q' or (sip_registrations.sip_user='%q' and "
"(sip_registrations.orig_server_host='%q' or sip_registrations.sub_host='%q' "
- "or sip_registrations.presence_hosts like '%%%q%%'))",
- dh.status, dh.rpid,
+ "))",
+ dh.status, dh.rpid, switch_str_nil(sub_call_id),
switch_sql_concat(), switch_sql_concat(),
- probe_euser, probe_host, probe_euser, probe_host, probe_host, probe_host);
+ profile->name, probe_host, probe_euser, probe_host, probe_euser, probe_host, probe_host);
+
+
+
switch_assert(sql);
if (mod_sofia_globals.debug_presence > 0) {
}
sofia_glue_execute_sql_callback(profile, profile->ireg_mutex, sql, sofia_presence_resub_callback, &h);
-
+
if (!h.rowcount) {
h.noreg++;
switch_safe_free(sql);
+
/* find ones with presence_id defined that are not registred */
sql = switch_mprintf("select sip_from_user, sip_from_host, 'Registered', '', '', "
"uuid, state, direction, "
switch_safe_free(probe_user);
}
-static void do_dialog_probe(sofia_profile_t *profile, switch_event_t *event)
+static void do_dialog_probe(switch_event_t *event)
{
// Received SUBSCRIBE for "dialog" events.
// Return a complete list of dialogs for the monitored entity.
char *sql;
char *to = switch_event_get_header(event, "to");
char *probe_user = NULL, *probe_euser, *probe_host, *p;
+ sofia_profile_t *profile;
if (!to || !(probe_user = strdup(to))) {
return;
"(sip_dialogs.sip_from_user = sip_registrations.sip_user "
"and (sip_dialogs.sip_from_host = sip_registrations.orig_server_host or "
"sip_dialogs.sip_from_host = sip_registrations.sip_host) ) "
- "where sip_dialogs.presence_id='%q@%q' or (sip_registrations.sip_user='%q' and "
+ "where sip_dialogs.call_info_state != 'seized' and sip_dialogs.presence_id='%q@%q' or (sip_registrations.sip_user='%q' and "
"(sip_registrations.orig_server_host='%q' or sip_registrations.sub_host='%q' "
"or sip_registrations.presence_hosts like '%%%q%%'))",
probe_euser, probe_host,
char *sql = NULL;
char *euser = NULL, *user = NULL, *host = NULL;
char *call_info = switch_event_get_header(event, "presence-call-info");
+ char *call_id = switch_event_get_header(event, "call-id");
char *presence_source = switch_event_get_header(event, "presence-source");
char *call_info_state = switch_event_get_header(event, "presence-call-info-state");
switch_console_callback_match_t *matches;
+ struct presence_helper helper = { 0 };
if (!mod_sofia_globals.running) {
return;
if (!probe_type || strcasecmp(probe_type, "dialog")) {
/* NORMAL PROBE */
- do_normal_probe(profile, event);
+ do_normal_probe(event);
} else {
/* DIALOG PROBE */
- do_dialog_probe(profile, event);
+ do_dialog_probe(event);
}
}
goto done;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "PROCESS PRESENCE EVENT\n");
}
- sync_sla(profile, euser, host, SWITCH_TRUE, SWITCH_TRUE);
+ sync_sla(profile, euser, host, SWITCH_TRUE, SWITCH_TRUE, call_id);
}
if (!strcmp(proto, "dp")) {
switch_safe_free(sql);
- if (dh.hits && presence_source && (!strcasecmp(presence_source, "register") || switch_stristr("register", status))) {
+ if (zstr(call_id) && (dh.hits && presence_source && (!strcasecmp(presence_source, "register") || switch_stristr("register", status)))) {
goto done;
}
+ if (zstr(call_id)) {
- if ((sql = switch_mprintf("select distinct sip_subscriptions.proto,sip_subscriptions.sip_user,sip_subscriptions.sip_host,"
- "sip_subscriptions.sub_to_user,sip_subscriptions.sub_to_host,sip_subscriptions.event,"
- "sip_subscriptions.contact,sip_subscriptions.call_id,sip_subscriptions.full_from,"
- "sip_subscriptions.full_via,sip_subscriptions.expires,sip_subscriptions.user_agent,"
- "sip_subscriptions.accept,sip_subscriptions.profile_name"
- ",'%q','%q','%q',sip_presence.status,sip_presence.rpid,sip_presence.open_closed,'%q','%q',"
- "sip_subscriptions.version, '%q',sip_subscriptions.orig_proto,sip_subscriptions.full_to,"
- "sip_subscriptions.network_ip, sip_subscriptions.network_port "
- "from sip_subscriptions "
- "left join sip_presence on "
- "(sip_subscriptions.sub_to_user=sip_presence.sip_user and sip_subscriptions.sub_to_host=sip_presence.sip_host and "
- "sip_subscriptions.profile_name=sip_presence.profile_name) "
+ sql = switch_mprintf("select distinct sip_subscriptions.proto,sip_subscriptions.sip_user,sip_subscriptions.sip_host,"
+ "sip_subscriptions.sub_to_user,sip_subscriptions.sub_to_host,sip_subscriptions.event,"
+ "sip_subscriptions.contact,sip_subscriptions.call_id,sip_subscriptions.full_from,"
+ "sip_subscriptions.full_via,sip_subscriptions.expires,sip_subscriptions.user_agent,"
+ "sip_subscriptions.accept,sip_subscriptions.profile_name"
+ ",'%q','%q','%q',sip_presence.status,sip_presence.rpid,sip_presence.open_closed,'%q','%q',"
+ "sip_subscriptions.version, '%q',sip_subscriptions.orig_proto,sip_subscriptions.full_to,"
+ "sip_subscriptions.network_ip, sip_subscriptions.network_port "
+ "from sip_subscriptions "
+ "left join sip_presence on "
+ "(sip_subscriptions.sub_to_user=sip_presence.sip_user and sip_subscriptions.sub_to_host=sip_presence.sip_host and "
+ "sip_subscriptions.profile_name=sip_presence.profile_name) "
- "where sip_subscriptions.version > -1 and sip_subscriptions.expires > -1 and "
- "sip_subscriptions.proto='%q' and "
- "(event='%q' or event='%q') and sub_to_user='%q' "
- "and (sub_to_host='%q' or presence_hosts like '%%%q%%') "
- "and (sip_subscriptions.profile_name = '%q' or sip_subscriptions.presence_hosts != sip_subscriptions.sub_to_host) ",
+ "where sip_subscriptions.version > -1 and sip_subscriptions.expires > -1 and "
+ "sip_subscriptions.proto='%q' and "
+ "(event='%q' or event='%q') and sub_to_user='%q' "
+ "and (sub_to_host='%q' or sub_to_host='%q' or sub_to_host='%q' or presence_hosts like '%%%q%%') "
+ "and (sip_subscriptions.profile_name = '%q' or presence_hosts like '%%%q%%') ",
- switch_str_nil(status), switch_str_nil(rpid), host,
- dh.status,dh.rpid,dh.presence_id, proto,
- event_type, alt_event_type, euser, host, host, profile->name))) {
-
- struct presence_helper helper = { 0 };
+ switch_str_nil(status), switch_str_nil(rpid), host,
+ dh.status,dh.rpid,dh.presence_id, proto,
+ event_type, alt_event_type, euser, host, profile->sipip,
+ profile->extsipip ? profile->extsipip : "N/A", host, profile->name, host);
+ } else {
+ sql = switch_mprintf("select distinct sip_subscriptions.proto,sip_subscriptions.sip_user,sip_subscriptions.sip_host,"
+ "sip_subscriptions.sub_to_user,sip_subscriptions.sub_to_host,sip_subscriptions.event,"
+ "sip_subscriptions.contact,sip_subscriptions.call_id,sip_subscriptions.full_from,"
+ "sip_subscriptions.full_via,sip_subscriptions.expires,sip_subscriptions.user_agent,"
+ "sip_subscriptions.accept,sip_subscriptions.profile_name"
+ ",'%q','%q','%q',sip_presence.status,sip_presence.rpid,sip_presence.open_closed,'%q','%q',"
+ "sip_subscriptions.version, '%q',sip_subscriptions.orig_proto,sip_subscriptions.full_to,"
+ "sip_subscriptions.network_ip, sip_subscriptions.network_port "
+ "from sip_subscriptions "
+ "left join sip_presence on "
+ "(sip_subscriptions.sub_to_user=sip_presence.sip_user and sip_subscriptions.sub_to_host=sip_presence.sip_host and "
+ "sip_subscriptions.profile_name=sip_presence.profile_name) "
+
+ "where sip_subscriptions.event != 'line-seize' and "
+ "sip_subscriptions.profile_name = '%q' and sip_subscriptions.call_id='%q'",
+
+ switch_str_nil(status), switch_str_nil(rpid), host,
+ dh.status,dh.rpid,dh.presence_id, profile->name, call_id);
- helper.profile = profile;
- helper.event = event;
- SWITCH_STANDARD_STREAM(helper.stream);
- switch_assert(helper.stream.data);
+ }
+
+
+ helper.profile = profile;
+ helper.event = event;
+ SWITCH_STANDARD_STREAM(helper.stream);
+ switch_assert(helper.stream.data);
- if (mod_sofia_globals.debug_presence > 0) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "%s START_PRESENCE_SQL (%s)\n",
- event->event_id == SWITCH_EVENT_PRESENCE_IN ? "IN" : "OUT", profile->name);
- }
+ if (mod_sofia_globals.debug_presence > 0) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "%s START_PRESENCE_SQL (%s)\n",
+ event->event_id == SWITCH_EVENT_PRESENCE_IN ? "IN" : "OUT", profile->name);
+ }
- if (mod_sofia_globals.debug_presence) {
- char *buf;
- switch_event_serialize(event, &buf, SWITCH_FALSE);
- switch_assert(buf);
- if (mod_sofia_globals.debug_presence > 1) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "DUMP PRESENCE SQL:\n%s\nEVENT DUMP:\n%s\n", sql, buf);
- } else {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "EVENT DUMP:\n%s\n", buf);
- }
- free(buf);
- }
+ if (mod_sofia_globals.debug_presence) {
+ char *buf;
+ switch_event_serialize(event, &buf, SWITCH_FALSE);
+ switch_assert(buf);
+ if (mod_sofia_globals.debug_presence > 1) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "DUMP PRESENCE SQL:\n%s\nEVENT DUMP:\n%s\n", sql, buf);
+ } else {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "EVENT DUMP:\n%s\n", buf);
+ }
+ free(buf);
+ }
- sofia_glue_execute_sql_callback(profile, profile->ireg_mutex, sql, sofia_presence_sub_callback, &helper);
- switch_safe_free(sql);
+ sofia_glue_execute_sql_callback(profile, profile->ireg_mutex, sql, sofia_presence_sub_callback, &helper);
+ switch_safe_free(sql);
- sql = switch_mprintf("update sip_subscriptions set version=version+1 where event!='dialog' and sub_to_user='%q' "
- "and (sub_to_host='%q' or presence_hosts like '%%%q%%') "
- "and (profile_name = '%q' or presence_hosts != sub_to_host)",
- euser, host, host, profile->name);
+ sql = switch_mprintf("update sip_subscriptions set version=version+1 where event!='dialog' and sub_to_user='%q' "
+ "and (sub_to_host='%q' or presence_hosts like '%%%q%%') "
+ "and (profile_name = '%q' or presence_hosts != sub_to_host)",
+ euser, host, host, profile->name);
- sofia_glue_execute_sql_now(profile, &sql, SWITCH_TRUE);
+ sofia_glue_execute_sql_now(profile, &sql, SWITCH_TRUE);
- if (mod_sofia_globals.debug_presence > 0) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "%s END_PRESENCE_SQL (%s)\n",
- event->event_id == SWITCH_EVENT_PRESENCE_IN ? "IN" : "OUT", profile->name);
- }
+ if (mod_sofia_globals.debug_presence > 0) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "%s END_PRESENCE_SQL (%s)\n",
+ event->event_id == SWITCH_EVENT_PRESENCE_IN ? "IN" : "OUT", profile->name);
+ }
-#if 1
- if (event) {
- const char *refresh = switch_event_get_header(event, "refresh");
- if (switch_true(refresh)) {
- switch_event_t *s_event;
+#if 0
+ if (event) {
+ const char *refresh = switch_event_get_header(event, "refresh");
+ if (switch_true(refresh)) {
+ switch_event_t *s_event;
- if (switch_event_create(&s_event, SWITCH_EVENT_PRESENCE_PROBE) == SWITCH_STATUS_SUCCESS) {
- switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "proto", SOFIA_CHAT_PROTO);
- switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "login", profile->name);
- switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "from", "%s@%s", euser, host);
- switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "to", "%s@%s", euser, host);
- switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "event_type", "presence");
- switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "alt_event_type", "dialog");
- switch_event_fire(&s_event);
- }
- }
+ if (switch_event_create(&s_event, SWITCH_EVENT_PRESENCE_PROBE) == SWITCH_STATUS_SUCCESS) {
+ switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "proto", SOFIA_CHAT_PROTO);
+ switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "login", profile->name);
+ switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "from", "%s@%s", euser, host);
+ switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "to", "%s@%s", euser, host);
+ switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "event_type", "presence");
+ switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "alt_event_type", "dialog");
+ switch_event_fire(&s_event);
}
+ }
+ }
#endif
- if (!zstr((char *) helper.stream.data)) {
- char *this_sql = (char *) helper.stream.data;
- char *next = NULL;
- char *last = NULL;
+ if (!zstr((char *) helper.stream.data)) {
+ char *this_sql = (char *) helper.stream.data;
+ char *next = NULL;
+ char *last = NULL;
- do {
- if ((next = strchr(this_sql, ';'))) {
- *next++ = '\0';
- while (*next == '\n' || *next == ' ' || *next == '\r') {
- *next++ = '\0';
- }
- }
+ do {
+ if ((next = strchr(this_sql, ';'))) {
+ *next++ = '\0';
+ while (*next == '\n' || *next == ' ' || *next == '\r') {
+ *next++ = '\0';
+ }
+ }
- if (!zstr(this_sql) && (!last || strcmp(last, this_sql))) {
- sofia_glue_execute_sql(profile, &this_sql, SWITCH_FALSE);
- last = this_sql;
- }
- this_sql = next;
- } while (this_sql);
+ if (!zstr(this_sql) && (!last || strcmp(last, this_sql))) {
+ sofia_glue_execute_sql(profile, &this_sql, SWITCH_FALSE);
+ last = this_sql;
}
- switch_safe_free(helper.stream.data);
- helper.stream.data = NULL;
- }
- sofia_glue_release_profile(profile);
+ this_sql = next;
+ } while (this_sql);
}
+ switch_safe_free(helper.stream.data);
+ helper.stream.data = NULL;
+
+ sofia_glue_release_profile(profile);
}
- switch_console_free_matches(&matches);
}
+ switch_console_free_matches(&matches);
+}
- done:
- switch_safe_free(sql);
- switch_safe_free(user);
+done:
+switch_safe_free(sql);
+switch_safe_free(user);
}
static int EVENT_THREAD_RUNNING = 0;
char *status = argv[2];
char *rpid = argv[3];
char *proto = argv[4];
-
+ char *call_id = NULL;
char *presence_id = NULL;
char *to_user = NULL;
char *uuid = NULL;
char to_buf[128] = "";
switch_event_header_t *hp;
char *free_me = NULL;
- int do_event = 1;
+ int do_event = 1, i;
+
+
+ if (mod_sofia_globals.debug_presence > 1) {
+ for (i = 0; i < argc; i++) {
+ switch_log_printf(SWITCH_CHANNEL_LOG,SWITCH_LOG_WARNING, "sofia_presence_resub_callback: %d [%s]=[%s]\n", i, columnNames[i], argv[i]);
+ }
+ }
if (argc > 5) {
uuid = argv[5];
if ((p = strchr(free_me, '@'))) *p = '\0';
user = free_me;
}
+
+ if (argc > 16) {
+ call_id = argv[16];
+ }
+
}
if (!zstr(uuid) && !switch_ivr_uuid_exists(uuid)) {
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Force-Direction", "inbound");
}
+ if (!zstr(call_id)) {
+ switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "call-id", call_id);
+ }
+
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "resub", "true");
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "status", status);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "rpid", rpid);
if (mod_sofia_globals.debug_presence > 1) {
for (i = 0; i < argc; i++) {
- switch_log_printf(SWITCH_CHANNEL_LOG,SWITCH_LOG_DEBUG, "sofia_dialog_probe_callback: %d [%s]=[%s]\n", i, columnNames[i], argv[i]);
+ switch_log_printf(SWITCH_CHANNEL_LOG,SWITCH_LOG_WARNING, "sofia_dialog_probe_callback: %d [%s]=[%s]\n", i, columnNames[i], argv[i]);
}
}
if (zstr(to_user) || zstr(contact_user)) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "sofia_dialog_probe_callback: not enough info to generate a dialog entry\n");
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "sofia_dialog_probe_callback: not enough info to generate a dialog entry\n");
return 0;
}
data = "";
}
tmp = switch_core_sprintf(h->pool, "%s"
- "<dialog id=\"%s\" call-id=\"%s\" local-tag=\"%s\" remote-tag=\"%s\" direction=\"%s\">\n"
- " <state>%s</state>\n"
- " <local>\n"
- " <identity display=\"%s\">sip:%s@%s%s</identity>\n"
- " <target uri=\"sip:%s@%s\">\n"
- " <param pname=\"+sip.rendering\" pvalue=\"%s\"/>\n"
- " </target>\n"
- " </local>\n"
- " <remote>\n"
- " <identity display=\"%s\">sip:%s@%s</identity>\n"
- " <target uri=\"%s\"/>\n"
- " </remote>\n"
- "</dialog>\n",
- data,
- uuid, call_id, to_tag, from_tag, direction,
- state,
- local_user, local_user, local_host, local_user_param,
- local_user, local_host,
- !strcasecmp(event_status, "hold") ? "no" : "yes",
- remote_display_buf, remote_user, remote_host,
- remote_uri
- );
+ "<dialog id=\"%s\" call-id=\"%s\" local-tag=\"%s\" remote-tag=\"%s\" direction=\"%s\">\n"
+ " <state>%s</state>\n"
+ " <local>\n"
+ " <identity display=\"%s\">sip:%s@%s%s</identity>\n"
+ " <target uri=\"sip:%s@%s\">\n"
+ " <param pname=\"+sip.rendering\" pvalue=\"%s\"/>\n"
+ " </target>\n"
+ " </local>\n"
+ " <remote>\n"
+ " <identity display=\"%s\">sip:%s@%s</identity>\n"
+ " <target uri=\"%s\"/>\n"
+ " </remote>\n"
+ "</dialog>\n",
+ data,
+ uuid, call_id, to_tag, from_tag, direction,
+ state,
+ local_user, local_user, local_host, local_user_param,
+ local_user, local_host,
+ !strcasecmp(event_status, "hold") ? "no" : "yes",
+ remote_display_buf, remote_user, remote_host,
+ remote_uri
+ );
switch_core_hash_insert(h->hash, key, tmp);
switch_safe_free(buf_to_free);
return 0;
}
-static void send_presence_notify(sofia_profile_t *profile,
- const char *full_to,
- const char *full_from,
- const char *contact,
- const char *expires,
- const char *call_id,
- const char *event,
- const char *remote_ip,
- const char *remote_port,
- const char *ct,
- const char *pl,
- const char *call_info
+#define send_presence_notify(_a,_b,_c,_d,_e,_f,_g,_h,_i,_j,_k,_l) \
+_send_presence_notify(_a,_b,_c,_d,_e,_f,_g,_h,_i,_j,_k,_l,__FILE__, __SWITCH_FUNC__, __LINE__)
+
+static void _send_presence_notify(sofia_profile_t *profile,
+ const char *full_to,
+ const char *full_from,
+ const char *o_contact,
+ const char *expires,
+ const char *call_id,
+ const char *event,
+ const char *remote_ip,
+ const char *remote_port,
+ const char *ct,
+ const char *pl,
+ const char *call_info,
+ const char *file, const char *func, int line
)
{
char sstr[128] = "";
nua_handle_t *nh;
int exptime = 0;
char expires_str[10] = "";
- char *tmp, *route = NULL;
sip_cseq_t *cseq = NULL;
uint32_t callsequence;
uint32_t now = (uint32_t) switch_epoch_time_now(NULL);
- const char *tp;
char *our_contact = profile->url, *our_contact_dup = NULL;
- if (expires) {
- long ltmp = atol(expires);
+ sofia_destination_t *dst = NULL;
+ char *contact_str, *contact, *user_via = NULL;
+ char *route_uri = NULL, *o_contact_dup = NULL, *tmp;
+ const char *tp;
+
+ tmp = (char *)o_contact;
+ o_contact_dup = sofia_glue_get_url_from_contact(tmp, 1);
- if (ltmp > 0) {
- exptime = (ltmp - now);
- } else {
- exptime = 0;
- }
+
+ if ((tp = switch_stristr("transport=", o_contact_dup))) {
+ tp += 10;
}
+ if (zstr(tp)) {
+ tp = "udp";
+ }
- switch_mutex_lock(profile->ireg_mutex);
- if (!profile->cseq_base) {
- profile->cseq_base = (now - 1312693200) * 10;
+ if (!switch_stristr("transport=", our_contact)) {
+ our_contact_dup = switch_mprintf("<%s;transport=%s>", our_contact, tp);
+ our_contact = our_contact_dup;
}
- callsequence = ++profile->cseq_base;
- switch_mutex_unlock(profile->ireg_mutex);
-
- nh = nua_handle(profile->nua, NULL, TAG_END());
- cseq = sip_cseq_create(nh->nh_home, callsequence, SIP_METHOD_NOTIFY);
- nua_handle_bind(nh, &mod_sofia_globals.destroy_private);
- if (exptime <= 0) {
- switch_snprintf(sstr, sizeof(sstr), "terminated;reason=noresource");
+ if (!zstr(remote_ip) && sofia_glue_check_nat(profile, remote_ip)) {
+ char *ptr = NULL;
+
+ if ((ptr = sofia_glue_find_parameter(o_contact, "transport="))) {
+ sofia_transport_t transport = sofia_glue_str2transport(ptr);
+
+ switch (transport) {
+ case SOFIA_TRANSPORT_TCP:
+ contact_str = profile->tcp_public_contact;
+ break;
+ case SOFIA_TRANSPORT_TCP_TLS:
+ contact_str = profile->tls_public_contact;
+ break;
+ default:
+ contact_str = profile->public_url;
+ break;
+ }
+ user_via = sofia_glue_create_external_via(NULL, profile, transport);
+ } else {
+ user_via = sofia_glue_create_external_via(NULL, profile, SOFIA_TRANSPORT_UDP);
+ contact_str = profile->public_url;
+ }
+
} else {
- switch_snprintf(sstr, sizeof(sstr), "active;expires=%u", (unsigned) exptime);
+ contact_str = our_contact;
}
- tmp = (char *)contact;
- contact = sofia_glue_get_url_from_contact(tmp, 0);
+ dst = sofia_glue_get_destination((char *) o_contact);
+ switch_assert(dst);
- if ((tp = switch_stristr("transport=", contact))) {
- tp += 10;
+ contact = sofia_glue_get_url_from_contact(dst->contact, 1);
+
+ if (dst->route_uri) {
+ route_uri = sofia_glue_strip_uri(dst->route_uri);
+ } else {
+ if (remote_ip && remote_port) {
+ route_uri = switch_mprintf("sip:%s:%s;transport=%s", remote_ip, remote_port, tp);
+ }
}
- if (zstr(tp)) {
- tp = "udp";
+ if (expires) {
+ long ltmp = atol(expires);
+
+ if (ltmp > 0) {
+ exptime = (ltmp - now);
+ } else {
+ exptime = 0;
+ }
}
- if (remote_ip && remote_port) {
- route = switch_mprintf("sip:%s:%s;transport=%s", remote_ip, remote_port, tp);
- }
- if (!switch_stristr("transport=", our_contact)) {
- our_contact_dup = switch_mprintf("<%s;transport=%s>", our_contact, tp);
- our_contact = our_contact_dup;
+
+ if (exptime <= 0) {
+ switch_snprintf(sstr, sizeof(sstr), "terminated;reason=noresource");
+ } else {
+ switch_snprintf(sstr, sizeof(sstr), "active;expires=%u", (unsigned) exptime);
}
if (mod_sofia_globals.debug_presence > 1) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "SEND PRES NOTIFY:\n"
- "route[%s]\ncontact[%s]\nto[%s]\nfrom[%s]\nurl[%s]\ncall_id[%s]\nexpires_str[%s]\n"
+ "file[%s]\nfunc[%s]\nline[%d]\n"
+ "profile[%s]\nvia[%s]\nip[%s]\nport[%s]\nroute[%s]\ncontact[%s]\nto[%s]\nfrom[%s]\nurl[%s]\ncall_id[%s]\nexpires_str[%s]\n"
"event[%s]\nct[%s]\npl[%s]\ncall_info[%s]\nexptime[%ld]\n",
- route,
- contact,
+ file, func, line,
+ profile->name,
+ switch_str_nil(user_via),
+ remote_ip,
+ remote_port,
+ route_uri,
+ o_contact,
full_to,
full_from,
- our_contact,
+ contact,
call_id,
expires_str,
event,
switch_str_nil(call_info),
(long)exptime
);
+ }
-
+
+ switch_mutex_lock(profile->ireg_mutex);
+ if (!profile->cseq_base) {
+ profile->cseq_base = (now - 1312693200) * 10;
}
+ callsequence = ++profile->cseq_base;
+ switch_mutex_unlock(profile->ireg_mutex);
+
+
+ nh = nua_handle(profile->nua, NULL, NUTAG_URL(contact), SIPTAG_CONTACT_STR(contact_str), TAG_END());
+ cseq = sip_cseq_create(nh->nh_home, callsequence, SIP_METHOD_NOTIFY);
+ nua_handle_bind(nh, &mod_sofia_globals.destroy_private);
+
nua_notify(nh,
NUTAG_NEWSUB(1),
- TAG_IF(route, NUTAG_PROXY(route)),
- NUTAG_URL(contact),
+ TAG_IF(dst->route_uri, NUTAG_PROXY(route_uri)), TAG_IF(dst->route, SIPTAG_ROUTE_STR(dst->route)),
+ TAG_IF(user_via, SIPTAG_VIA_STR(user_via)),
+
+
SIPTAG_FROM_STR(full_to),
SIPTAG_TO_STR(full_from),
- SIPTAG_CONTACT_STR(our_contact),
+
SIPTAG_CALL_ID_STR(call_id),
TAG_IF(*expires_str, SIPTAG_EXPIRES_STR(expires_str)),
SIPTAG_SUBSCRIPTION_STATE_STR(sstr),
SIPTAG_CSEQ(cseq),
TAG_END());
- switch_safe_free(route);
- switch_safe_free(our_contact_dup);
+
+ switch_safe_free(route_uri);
+ switch_safe_free(contact);
+
+ sofia_glue_free_destination(dst);
+ switch_safe_free(user_via);
+ switch_safe_free(o_contact_dup);
+
}
const char *pl = NULL;
const char *ct = "application/dialog-info+xml";
+ if (mod_sofia_globals.debug_presence > 0) {
+ int i;
+ for(i = 0; i < argc; i++) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "arg %d[%s] = [%s]\n", i, columnNames[i], argv[i]);
+ }
+ }
+
if (mod_sofia_globals.debug_presence > 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE,
- "SEND DIALOG\nTo: \t%s@%s\nFrom: \t%s@%s\nCall-ID: \t%s\n",
- user, host, user, host, call_id);
+ "SEND DIALOG\nTo: \t%s@%s\nFrom: \t%s@%s\nCall-ID: \t%s\n",
+ user, host, user, host, call_id);
}
to = switch_mprintf("sip:%s@%s", user, host);
r = "busy";
}
- end:
+ end:
return r;
}
struct mwi_helper *h = (struct mwi_helper *) pArg;
sofia_profile_t *ext_profile = NULL, *profile = h->profile;
+
+ if (mod_sofia_globals.debug_presence > 0) {
+ int i;
+ for(i = 0; i < argc; i++) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "arg %d[%s] = [%s]\n", i, columnNames[i], argv[i]);
+ }
+ }
+
if (profile_name && strcasecmp(profile_name, h->profile->name)) {
if ((ext_profile = sofia_glue_find_profile(profile_name))) {
profile = ext_profile;
char *event = argv[4];
int i;
+
if (mod_sofia_globals.debug_sla > 1) {
for (i = 0; i < argc; i++) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "SLA3: %d [%s]=[%s]\n", i, columnNames[i], argv[i]);
}
send_presence_notify(sh->profile, argv[5], argv[6], argv[7], argv[8], call_id, event, argv[9], argv[10], NULL, NULL, tmp);
+
+ sh->total++;
return 0;
}
return 0;
}
-static void sync_sla(sofia_profile_t *profile, const char *to_user, const char *to_host, switch_bool_t clear, switch_bool_t unseize)
+static int sync_sla(sofia_profile_t *profile, const char *to_user, const char *to_host, switch_bool_t clear, switch_bool_t unseize, const char *call_id)
{
struct state_helper *sh;
switch_memory_pool_t *pool;
char *sql;
+ int total = 0;
switch_core_new_memory_pool(&pool);
sh = switch_core_alloc(pool, sizeof(*sh));
switch_core_hash_init(&sh->hash, sh->pool);
sql = switch_mprintf("select sip_from_user,sip_from_host,call_info,call_info_state,uuid from sip_dialogs "
- "where call_info_state is not null and hostname='%q' and ((sip_from_user='%q' and sip_from_host='%q') or presence_id='%q@%q')",
- mod_sofia_globals.hostname, to_user, to_host, to_user, to_host);
+ "where call_info_state is not null and hostname='%q' and ((sip_from_user='%q' and sip_from_host='%q') or presence_id='%q@%q') "
+ "and profile_name='%q'",
+ mod_sofia_globals.hostname, to_user, to_host, to_user, to_host, profile->name);
if (mod_sofia_globals.debug_sla > 1) {
switch_safe_free(sql);
- if (unseize) {
- sql = switch_mprintf("select call_id,expires,sub_to_user,sub_to_host,event,full_to,full_from,contact,expires,network_ip,network_port "
- "from sip_subscriptions "
- "where version > -1 and expires > -1 and hostname='%q' "
- "and sub_to_user='%q' and sub_to_host='%q' "
- "and (event='call-info' or event='line-seize')", mod_sofia_globals.hostname, to_user, to_host);
+ if (!zstr(call_id)) {
+
+ if (unseize) {
+ sql = switch_mprintf("select call_id,expires,sub_to_user,sub_to_host,event,full_to,full_from,contact,expires,network_ip,network_port "
+ "from sip_subscriptions where call_id='%q' and profile_name='%q')", call_id, profile->name);
+
+ } else {
+ sql = switch_mprintf("select call_id,expires,sub_to_user,sub_to_host,event,full_to,full_from,contact,expires,network_ip,network_port "
+ "from sip_subscriptions where call_id='%q' and profile_name='%q'", call_id, profile->name);
+ }
+
} else {
- sql = switch_mprintf("select call_id,expires,sub_to_user,sub_to_host,event,full_to,full_from,contact,expires,network_ip,network_port "
- "from sip_subscriptions "
- "where version > -1 and expires > -1 and hostname='%q' "
- "and sub_to_user='%q' and sub_to_host='%q' " "and (event='call-info')", mod_sofia_globals.hostname, to_user, to_host);
- }
+ if (unseize) {
+ sql = switch_mprintf("select call_id,expires,sub_to_user,sub_to_host,event,full_to,full_from,contact,expires,network_ip,network_port "
+ "from sip_subscriptions "
+ "where version > -1 and expires > -1 and hostname='%q' "
+ "and sub_to_user='%q' and sub_to_host='%q' "
+ "and (event='call-info' or event='line-seize') and (profile_name='%q' or presence_hosts like '%%%q%%')",
+ mod_sofia_globals.hostname, to_user, to_host, profile->name, to_host);
+ } else {
+ sql = switch_mprintf("select call_id,expires,sub_to_user,sub_to_host,event,full_to,full_from,contact,expires,network_ip,network_port "
+ "from sip_subscriptions "
+ "where version > -1 and expires > -1 and hostname='%q' "
+ "and sub_to_user='%q' and sub_to_host='%q' " "and (event='call-info') and "
+ "(profile_name='%q' or presence_hosts like '%%%q%%')",
+ mod_sofia_globals.hostname, to_user, to_host, profile->name, to_host);
+ }
+ }
if (mod_sofia_globals.debug_sla > 1) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "PRES SQL %s\n", sql);
}
+
sh->profile = profile;
sofia_glue_execute_sql_callback(profile, profile->ireg_mutex, sql, broadsoft_sla_notify_callback, sh);
switch_safe_free(sql);
+ total = sh->total;
sh = NULL;
switch_core_destroy_memory_pool(&pool);
sofia_glue_execute_sql_now(profile, &sql, SWITCH_TRUE);
}
+ return total;
+
}
void sofia_presence_handle_sip_i_subscribe(int status,
char const *phrase,
nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sofia_private_t *sofia_private, sip_t const *sip,
- sofia_dispatch_event_t *de,
+ sofia_dispatch_event_t *de,
tagi_t tags[])
{
to = sip->sip_to;
contact = sip->sip_contact;
- if (!(contact_str = sofia_glue_gen_contact_str(profile, sip, de, &np))) {
+ np.fs_path = 1;
+ if (!(contact_str = sofia_glue_gen_contact_str(profile, sip, nh, de, &np))) {
nua_respond(nh, 481, "INVALID SUBSCRIPTION", TAG_END());
return;
}
sstr = switch_mprintf("active;expires=%ld", exp_delta);
sql = switch_mprintf("update sip_subscriptions "
- "set expires=%ld,version=0 "
+ "set version=0,expires=%ld,contact='%q' "
"where call_id='%q'",
- (long) switch_epoch_time_now(NULL) + exp_delta,
+ (long) switch_epoch_time_now(NULL) + exp_delta, contact_str,
call_id);
if (mod_sofia_globals.debug_presence > 0 || mod_sofia_globals.debug_sla > 0) {
sofia_glue_execute_sql_now(profile, &sql, SWITCH_TRUE);
} else {
- sql = switch_mprintf("delete from sip_subscriptions where call_id='%q'", call_id, mod_sofia_globals.hostname);
-
- if (mod_sofia_globals.debug_presence > 0 || mod_sofia_globals.debug_sla > 0) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
- "sub del sql: %s\n", sql);
- }
-
- switch_mutex_lock(profile->ireg_mutex);
- switch_assert(sql != NULL);
- sofia_glue_actually_execute_sql(profile, sql, NULL);
- switch_safe_free(sql);
-
if (sub_state == nua_substate_terminated) {
- sstr = switch_mprintf("terminated");
+ sql = switch_mprintf("delete from sip_subscriptions where call_id='%q'", call_id, mod_sofia_globals.hostname);
+
+ if (mod_sofia_globals.debug_presence > 0 || mod_sofia_globals.debug_sla > 0) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
+ "sub del sql: %s\n", sql);
+ }
+
+ switch_mutex_lock(profile->ireg_mutex);
+ switch_assert(sql != NULL);
+ sofia_glue_actually_execute_sql(profile, sql, NULL);
+ switch_safe_free(sql);
+
+ sstr = switch_mprintf("terminated;reason=noresource");
} else {
sip_accept_t *ap = sip->sip_accept;
char accept[256] = "";
"(proto,sip_user,sip_host,sub_to_user,sub_to_host,presence_hosts,event,contact,call_id,full_from,"
"full_via,expires,user_agent,accept,profile_name,hostname,network_port,network_ip, orig_proto, full_to) "
"values ('%q','%q','%q','%q','%q','%q','%q','%q','%q','%q','%q',%ld,'%q','%q','%q','%q','%d','%q','%q','%q;tag=%q')",
- proto, from_user, from_host, to_user, to_host, profile->presence_hosts ? profile->presence_hosts : to_host,
+ proto, from_user, from_host, to_user, to_host, profile->presence_hosts ? profile->presence_hosts : "",
event, contact_str, call_id, full_from, full_via,
(long) switch_epoch_time_now(NULL) + exp_delta,
full_agent, accept, profile->name, mod_sofia_globals.hostname,
p++;
}
+#if 0
nua_notify(nh,
SIPTAG_EXPIRES_STR("0"),
SIPTAG_SUBSCRIPTION_STATE_STR(sstr), TAG_IF(full_call_info, SIPTAG_CALL_INFO_STR(full_call_info)), TAG_END());
-
+#endif
if (!strcasecmp(event, "line-seize")) {
if (mod_sofia_globals.debug_sla > 1) {
}
sofia_glue_execute_sql_now(profile, &sql, SWITCH_TRUE);
- sync_sla(profile, to_user, to_host, SWITCH_FALSE, SWITCH_FALSE);
+ sync_sla(profile, to_user, to_host, SWITCH_FALSE, SWITCH_FALSE, NULL);
}
su_free(nh->nh_home, full_call_info);
sql = switch_mprintf("delete from sip_dialogs where ((sip_from_user='%q' and sip_from_host='%q') or presence_id='%q@%q') "
- "and call_info_state='seized'",
- to_user, to_host, to_user, to_host);
+ "and call_info_state='seized' and profile_name='%q'",
+ to_user, to_host, to_user, to_host, profile->name);
if (mod_sofia_globals.debug_sla > 1) {
sofia_glue_execute_sql_now(profile, &sql, SWITCH_TRUE);
now = switch_epoch_time_now(NULL);
- sql = switch_mprintf("insert into sip_dialogs (sip_from_user,sip_from_host,call_info,call_info_state,hostname,expires,rcd) "
- "values ('%q','%q','%q','seized','%q',%ld,%ld)",
- to_user, to_host, switch_str_nil(p), mod_sofia_globals.hostname, switch_epoch_time_now(NULL) + exp_delta, (long)now);
+ sql = switch_mprintf("insert into sip_dialogs (sip_from_user,sip_from_host,call_info,call_info_state,hostname,expires,rcd,profile_name) "
+ "values ('%q','%q','%q','seized','%q',%ld,%ld,'%q')",
+ to_user, to_host, switch_str_nil(p), mod_sofia_globals.hostname,
+ switch_epoch_time_now(NULL) + exp_delta, (long)now, profile->name);
if (mod_sofia_globals.debug_sla > 1) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "SEIZE SQL %s\n", sql);
}
sofia_glue_execute_sql_now(profile, &sql, SWITCH_TRUE);
- sync_sla(profile, to_user, to_host, SWITCH_FALSE, SWITCH_FALSE);
+ sync_sla(profile, to_user, to_host, SWITCH_FALSE, SWITCH_FALSE, NULL);
su_free(nh->nh_home, full_call_info);
}
} else if (!strcasecmp(event, "call-info")) {
- sync_sla(profile, to_user, to_host, SWITCH_FALSE, SWITCH_FALSE);
+ sync_sla(profile, to_user, to_host, SWITCH_FALSE, SWITCH_FALSE, call_id);
}
}
end:
- if (to_user && (strstr(to_user, "ext+") || strstr(to_user, "user+"))) {
- char protocol[80];
- char *p;
+ if (strcasecmp(event, "call-info") && strcasecmp(event, "line-seize")) {
- switch_copy_string(protocol, to_user, sizeof(protocol));
- if ((p = strchr(protocol, '+'))) {
- *p = '\0';
- }
+ if (to_user && (strstr(to_user, "ext+") || strstr(to_user, "user+"))) {
+ char protocol[80];
+ char *p;
- if (switch_event_create(&sevent, SWITCH_EVENT_PRESENCE_IN) == SWITCH_STATUS_SUCCESS) {
- switch_event_add_header_string(sevent, SWITCH_STACK_BOTTOM, "proto", protocol);
- if (!zstr(orig_proto)) {
- switch_event_add_header_string(sevent, SWITCH_STACK_BOTTOM, "orig_proto", orig_proto);
- }
- switch_event_add_header_string(sevent, SWITCH_STACK_BOTTOM, "login", profile->name);
- switch_event_add_header(sevent, SWITCH_STACK_BOTTOM, "from", "%s@%s", to_user, to_host);
- switch_event_add_header_string(sevent, SWITCH_STACK_BOTTOM, "rpid", "active");
- switch_event_add_header_string(sevent, SWITCH_STACK_BOTTOM, "status", "Click To Call");
- switch_event_fire(&sevent);
- }
-
- } else if (to_user && (strcasecmp(proto, SOFIA_CHAT_PROTO) != 0)) {
- if (switch_event_create(&sevent, SWITCH_EVENT_PRESENCE_PROBE) == SWITCH_STATUS_SUCCESS) {
- switch_event_add_header_string(sevent, SWITCH_STACK_BOTTOM, "proto", proto);
- if (!zstr(orig_proto)) {
- switch_event_add_header_string(sevent, SWITCH_STACK_BOTTOM, "orig_proto", orig_proto);
- }
- switch_event_add_header_string(sevent, SWITCH_STACK_BOTTOM, "login", profile->name);
- switch_event_add_header(sevent, SWITCH_STACK_BOTTOM, "from", "%s@%s", from_user, from_host);
- switch_event_add_header(sevent, SWITCH_STACK_BOTTOM, "to", "%s%s%s@%s", proto, "+", to_user, to_host);
- switch_event_add_header_string(sevent, SWITCH_STACK_BOTTOM, "proto-specific-event-name", event);
- switch_event_add_header_string(sevent, SWITCH_STACK_BOTTOM, "expires", exp_delta_str);
- switch_event_add_header_string(sevent, SWITCH_STACK_BOTTOM, "event_type", "presence");
- switch_event_add_header_string(sevent, SWITCH_STACK_BOTTOM, "alt_event_type", "dialog");
- switch_event_add_header_string(sevent, SWITCH_STACK_BOTTOM, "expires", exp_delta_str);
- switch_event_fire(&sevent);
+ switch_copy_string(protocol, to_user, sizeof(protocol));
+ if ((p = strchr(protocol, '+'))) {
+ *p = '\0';
+ }
+
+ if (switch_event_create(&sevent, SWITCH_EVENT_PRESENCE_IN) == SWITCH_STATUS_SUCCESS) {
+ switch_event_add_header_string(sevent, SWITCH_STACK_BOTTOM, "proto", protocol);
+ if (!zstr(orig_proto)) {
+ switch_event_add_header_string(sevent, SWITCH_STACK_BOTTOM, "orig_proto", orig_proto);
+ }
+ switch_event_add_header_string(sevent, SWITCH_STACK_BOTTOM, "login", profile->name);
+ switch_event_add_header(sevent, SWITCH_STACK_BOTTOM, "from", "%s@%s", to_user, to_host);
+ switch_event_add_header_string(sevent, SWITCH_STACK_BOTTOM, "rpid", "active");
+ switch_event_add_header_string(sevent, SWITCH_STACK_BOTTOM, "status", "Click To Call");
+ switch_event_fire(&sevent);
+ }
+
+ } else if (to_user && (strcasecmp(proto, SOFIA_CHAT_PROTO) != 0)) {
+ if (switch_event_create(&sevent, SWITCH_EVENT_PRESENCE_PROBE) == SWITCH_STATUS_SUCCESS) {
+ switch_event_add_header_string(sevent, SWITCH_STACK_BOTTOM, "proto", proto);
+ if (!zstr(orig_proto)) {
+ switch_event_add_header_string(sevent, SWITCH_STACK_BOTTOM, "orig_proto", orig_proto);
+ }
+ switch_event_add_header_string(sevent, SWITCH_STACK_BOTTOM, "login", profile->name);
+ switch_event_add_header(sevent, SWITCH_STACK_BOTTOM, "from", "%s@%s", from_user, from_host);
+ switch_event_add_header(sevent, SWITCH_STACK_BOTTOM, "to", "%s%s%s@%s", proto, "+", to_user, to_host);
+ switch_event_add_header_string(sevent, SWITCH_STACK_BOTTOM, "proto-specific-event-name", event);
+ switch_event_add_header_string(sevent, SWITCH_STACK_BOTTOM, "expires", exp_delta_str);
+ switch_event_add_header_string(sevent, SWITCH_STACK_BOTTOM, "event_type", "presence");
+ switch_event_add_header_string(sevent, SWITCH_STACK_BOTTOM, "alt_event_type", "dialog");
+ switch_event_add_header_string(sevent, SWITCH_STACK_BOTTOM, "expires", exp_delta_str);
+ switch_event_fire(&sevent);
- }
- } else {
- if (switch_event_create(&sevent, SWITCH_EVENT_PRESENCE_PROBE) == SWITCH_STATUS_SUCCESS) {
- if (!strcasecmp(event, "dialog")) {
- switch_event_add_header_string(sevent, SWITCH_STACK_BOTTOM, "probe-type", "dialog");
}
+ } else {
- switch_event_add_header_string(sevent, SWITCH_STACK_BOTTOM, "proto", SOFIA_CHAT_PROTO);
- switch_event_add_header_string(sevent, SWITCH_STACK_BOTTOM, "login", profile->name);
- switch_event_add_header(sevent, SWITCH_STACK_BOTTOM, "from", "%s@%s", from_user, from_host);
- switch_event_add_header(sevent, SWITCH_STACK_BOTTOM, "to", "%s@%s", to_user, to_host);
- switch_event_add_header_string(sevent, SWITCH_STACK_BOTTOM, "proto-specific-event-name", event);
- switch_event_add_header_string(sevent, SWITCH_STACK_BOTTOM, "expires", exp_delta_str);
- switch_event_add_header_string(sevent, SWITCH_STACK_BOTTOM, "event_type", "presence");
- switch_event_add_header_string(sevent, SWITCH_STACK_BOTTOM, "alt_event_type", "dialog");
- switch_event_add_header_string(sevent, SWITCH_STACK_BOTTOM, "expires", exp_delta_str);
- switch_event_add_header_string(sevent, SWITCH_STACK_BOTTOM, "sub-call-id", call_id);
- switch_event_fire(&sevent);
+ if (!strcasecmp(event, "dialog")) {
+ if (switch_event_create(&sevent, SWITCH_EVENT_PRESENCE_PROBE) == SWITCH_STATUS_SUCCESS) {
+ switch_event_add_header_string(sevent, SWITCH_STACK_BOTTOM, "probe-type", "dialog");
+ switch_event_add_header_string(sevent, SWITCH_STACK_BOTTOM, "proto", SOFIA_CHAT_PROTO);
+ switch_event_add_header_string(sevent, SWITCH_STACK_BOTTOM, "login", profile->name);
+ switch_event_add_header(sevent, SWITCH_STACK_BOTTOM, "from", "%s@%s", from_user, from_host);
+ switch_event_add_header(sevent, SWITCH_STACK_BOTTOM, "to", "%s@%s", to_user, to_host);
+ switch_event_add_header_string(sevent, SWITCH_STACK_BOTTOM, "proto-specific-event-name", event);
+ switch_event_add_header_string(sevent, SWITCH_STACK_BOTTOM, "expires", exp_delta_str);
+ switch_event_add_header_string(sevent, SWITCH_STACK_BOTTOM, "event_type", "presence");
+ switch_event_add_header_string(sevent, SWITCH_STACK_BOTTOM, "alt_event_type", "dialog");
+ switch_event_add_header_string(sevent, SWITCH_STACK_BOTTOM, "expires", exp_delta_str);
+ switch_event_add_header_string(sevent, SWITCH_STACK_BOTTOM, "sub-call-id", call_id);
+ switch_event_fire(&sevent);
+ }
+ } else {
+ if (switch_event_create(&sevent, SWITCH_EVENT_PRESENCE_IN) == SWITCH_STATUS_SUCCESS) {
+ switch_event_add_header_string(sevent, SWITCH_STACK_BOTTOM, "proto", SOFIA_CHAT_PROTO);
+ switch_event_add_header_string(sevent, SWITCH_STACK_BOTTOM, "login", profile->name);
+ switch_event_add_header_string(sevent, SWITCH_STACK_BOTTOM, "presence-source", "subscribe");
+ switch_event_add_header(sevent, SWITCH_STACK_BOTTOM, "from", "%s@%s", from_user, from_host);
+ switch_event_add_header_string(sevent, SWITCH_STACK_BOTTOM, "rpid", "unknown");
+ switch_event_add_header_string(sevent, SWITCH_STACK_BOTTOM, "status", "Registered");
+ switch_event_add_header_string(sevent, SWITCH_STACK_BOTTOM, "call-id", call_id);
+ switch_event_fire(&sevent);
+ }
+ }
}
}
-
-
if (event) {
su_free(nh->nh_home, event);
}
{
struct pres_sql_cb *cb = (struct pres_sql_cb *) pArg;
+
+ if (mod_sofia_globals.debug_presence > 0) {
+ int i;
+ for(i = 0; i < argc; i++) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "arg %d[%s] = [%s]\n", i, columnNames[i], argv[i]);
+ }
+ }
+
send_presence_notify(cb->profile, argv[0], argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7], argv[8], argv[9], NULL);
cb->ttl++;
}
void sofia_presence_handle_sip_i_publish(nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sofia_private_t *sofia_private, sip_t const *sip,
- sofia_dispatch_event_t *de,
+ sofia_dispatch_event_t *de,
tagi_t tags[])
{
from = sip->sip_from;
payload = sip->sip_payload;
- contact_str = sofia_glue_gen_contact_str(profile, sip, de, NULL);
+ contact_str = sofia_glue_gen_contact_str(profile, sip, nh, de, NULL);
if (from) {
from_user = (char *) from->a_url->url_user;
void sofia_presence_handle_sip_i_message(int status,
char const *phrase,
nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sofia_private_t *sofia_private, sip_t const *sip,
- sofia_dispatch_event_t *de,
+ sofia_dispatch_event_t *de,
tagi_t tags[])
{
if (sip) {