struct resub_helper {
sofia_profile_t *profile;
switch_event_t *event;
+ int rowcount;
};
struct presence_helper {
"(sip_registrations.sip_host='%q' or sip_registrations.presence_hosts like '%%%q%%')",
probe_host, probe_euser, probe_host, probe_host);
switch_assert(sql);
-
+
if (mod_sofia_globals.debug_presence > 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "%s START_PRESENCE_PROBE_SQL\n", profile->name);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "%s END_PRESENCE_PROBE_SQL\n\n", profile->name);
}
+ if (!h.rowcount) {
+ switch_event_t *sevent;
+ 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(sevent, SWITCH_STACK_BOTTOM, "from", "%s@%s", probe_euser, probe_host);
+ switch_event_add_header_string(sevent, SWITCH_STACK_BOTTOM, "status", "Unregistered");
+ switch_event_fire(&sevent);
+ }
+ }
+
+
sofia_glue_release_profile(profile);
switch_safe_free(sql);
}
switch_event_fire(&event);
}
+ h->rowcount++;
return 0;
}
} else {
*ct = "application/pidf+xml";
- if (!strncasecmp(status, "Registered(", 11)) {
+ if (!strncasecmp(status, "Registered", 10)) {
prpid = NULL;
status = "Available";
}
+
+ if (!strcasecmp(status, "Unregistered")) {
+ prpid = NULL;
+ open = "closed";
+ }
+
if (prpid) {
ret = switch_mprintf("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?> \n"
"<presence xmlns='urn:ietf:params:xml:ns:pidf' \n"
open = "closed";
}
- printf("WTF %s\n%s\n", ct, content);
-
if (content) {
pl = strdup(content);
} else {
open = "closed";
}
- printf("WTF2 %s\n%s\n", ct, content);
-
if (content) {
pl = strdup(content);
} else {
switch_snprintf(exp_delta_str, sizeof(exp_delta_str), "%ld", exp_delta);
- if (to_user && (strstr(to_user, "ext+") || strstr(to_user, "user+"))) {
- char protocol[80];
- char *p;
-
- 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);
- 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 (switch_event_create(&sevent, SWITCH_EVENT_PRESENCE_PROBE) == 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(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_fire(&sevent);
- }
- }
-
if (to_user && strchr(to_user, '+')) {
char *h;
if ((proto = (d_user = strdup(to_user)))) {
switch_safe_free(sql);
}
- } else {
- if ((sql = switch_mprintf("select proto,sip_user,'%q',sub_to_user,sub_to_host,event,contact,call_id,full_from,"
- "full_via,expires,user_agent,accept,profile_name,network_ip"
- " from sip_subscriptions where expires > -1 and event='%s' and sip_user='%q' "
- "and (sip_host='%q' or presence_hosts like '%%%q%%')", to_host, event, to_user, to_host, to_host))) {
- sofia_glue_execute_sql_callback(profile, profile->ireg_mutex, sql, sofia_presence_sub_callback, profile);
-
- switch_safe_free(sql);
- }
}
end:
+ if (to_user && (strstr(to_user, "ext+") || strstr(to_user, "user+"))) {
+ char protocol[80];
+ char *p;
+
+ 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);
+ 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 (switch_event_create(&sevent, SWITCH_EVENT_PRESENCE_PROBE) == 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(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_fire(&sevent);
+ }
+ }
+
+
+
if (event) {
su_free(profile->home, event);
}
sql = switch_mprintf("delete from sip_registrations where sip_user='%q' and sip_host='%q'", to_user, reg_host);
}
switch_mutex_lock(profile->ireg_mutex);
- sofia_glue_execute_sql(profile, &sql, SWITCH_TRUE);
+ sofia_glue_execute_sql_now(profile, &sql, SWITCH_TRUE);
switch_find_local_ip(guess_ip4, sizeof(guess_ip4), NULL, AF_INET);
sql = switch_mprintf("insert into sip_registrations "
mwi_user, mwi_host, guess_ip4, mod_sofia_globals.hostname);
if (sql) {
- sofia_glue_execute_sql(profile, &sql, SWITCH_TRUE);
+ sofia_glue_execute_sql_now(profile, &sql, SWITCH_TRUE);
}
switch_mutex_unlock(profile->ireg_mutex);
} else {
- if (switch_event_create(&event, SWITCH_EVENT_PRESENCE_OUT) == SWITCH_STATUS_SUCCESS) {
+ if (switch_event_create(&event, SWITCH_EVENT_PRESENCE_IN) == SWITCH_STATUS_SUCCESS) {
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "proto", SOFIA_CHAT_PROTO);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "rpid", rpid);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "login", profile->url);
switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "VM-Call-ID", call_id);
}
}
+
+
+ if (switch_event_create(&s_event, SWITCH_EVENT_PRESENCE_IN) == 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", to_user, reg_host);
+ switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "rpid", "closed");
+ switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "status", "Registered");
+ switch_event_fire(&s_event);
+ }
+
} else {
if (switch_event_create_subclass(&s_event, SWITCH_EVENT_CUSTOM, MY_EVENT_UNREGISTER) == SWITCH_STATUS_SUCCESS) {
switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "profile-name", profile->name);