presence crap

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@6048 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Anthony Minessale 2007-10-24 23:20:47 +00:00
parent 5b3f19fb30
commit a93ddbd212
8 changed files with 200 additions and 116 deletions

View File

@ -4425,6 +4425,7 @@ static switch_status_t chat_send(char *proto, char *from, char *to, char *subjec
switch_copy_string(name, to, sizeof(name)); switch_copy_string(name, to, sizeof(name));
} }
if (!(conference = (conference_obj_t *) switch_core_hash_find(globals.conference_hash, name))) { if (!(conference = (conference_obj_t *) switch_core_hash_find(globals.conference_hash, name))) {
ci->chat_send(CONF_CHAT_PROTO, to, hint && strchr(hint, '/') ? hint : from, "", "Conference not active.", NULL); ci->chat_send(CONF_CHAT_PROTO, to, hint && strchr(hint, '/') ? hint : from, "", "Conference not active.", NULL);
return SWITCH_STATUS_FALSE; return SWITCH_STATUS_FALSE;
@ -4433,19 +4434,22 @@ static switch_status_t chat_send(char *proto, char *from, char *to, char *subjec
SWITCH_STANDARD_STREAM(stream); SWITCH_STANDARD_STREAM(stream);
if (body != NULL && (lbuf = strdup(body))) { if (body != NULL && (lbuf = strdup(body))) {
int argc; //int argc;
char *argv[25]; //char *argv[25];
memset(argv, 0, sizeof(argv)); //memset(argv, 0, sizeof(argv));
argc = switch_separate_string(lbuf, ' ', argv, (sizeof(argv) / sizeof(argv[0]))); //argc = switch_separate_string(lbuf, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
/* try to find a command to execute */ /* try to find a command to execute */
if (argc) { //if (argc) {
/* special case list */ /* special case list */
if (strcasecmp(argv[0], "list") == 0) { if (switch_stristr("list", lbuf)) {
conference_list_pretty(conference, &stream); conference_list_pretty(conference, &stream);
/* provide help */ /* provide help */
} }
else {
return SWITCH_STATUS_SUCCESS;
}
#if 0 #if 0
else { else {
if (strcasecmp(argv[0], "help") == 0 || strcasecmp(argv[0], "commands") == 0) { if (strcasecmp(argv[0], "help") == 0 || strcasecmp(argv[0], "commands") == 0) {
@ -4456,12 +4460,11 @@ static switch_status_t chat_send(char *proto, char *from, char *to, char *subjec
} }
} }
#endif #endif
} else { //} else {
stream.write_function(&stream, "No parameters specified.\nTry 'help'\n"); //stream.write_function(&stream, "No parameters specified.\nTry 'help'\n");
} //}
} }
switch_safe_free(lbuf); switch_safe_free(lbuf);
ci->chat_send(CONF_CHAT_PROTO, to, from, "", stream.data, NULL); ci->chat_send(CONF_CHAT_PROTO, to, from, "", stream.data, NULL);
switch_safe_free(stream.data); switch_safe_free(stream.data);

View File

@ -1710,7 +1710,7 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_sofia_shutdown)
{ {
int sanity = 0; int sanity = 0;
sofia_presence_cancel(); //sofia_presence_cancel();
switch_mutex_lock(mod_sofia_globals.mutex); switch_mutex_lock(mod_sofia_globals.mutex);
if (mod_sofia_globals.running == 1) { if (mod_sofia_globals.running == 1) {

View File

@ -248,7 +248,7 @@ struct sofia_profile {
switch_mutex_t *gateway_mutex; switch_mutex_t *gateway_mutex;
sofia_gateway_t *gateways; sofia_gateway_t *gateways;
su_home_t *home; su_home_t *home;
switch_hash_t *profile_hash; switch_hash_t *sub_hash;
switch_hash_t *chat_hash; switch_hash_t *chat_hash;
switch_core_db_t *master_db; switch_core_db_t *master_db;
switch_thread_rwlock_t *rwlock; switch_thread_rwlock_t *rwlock;

View File

@ -42,6 +42,18 @@ static void sofia_handle_sip_i_state(switch_core_session_t *session, int status,
char const *phrase, char const *phrase,
nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sofia_private_t *sofia_private, sip_t const *sip, tagi_t tags[]); nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sofia_private_t *sofia_private, sip_t const *sip, tagi_t tags[]);
void sofia_handle_sip_r_notify(switch_core_session_t *session, 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, tagi_t tags[])
{
#if 0
if (status > 299) {
nua_handle_destroy(nh);
switch_core_hash_delete(profile->sub_hash, sip->sip_call_id->i_id);
}
#endif
}
void sofia_handle_sip_i_notify(switch_core_session_t *session, int status, void sofia_handle_sip_i_notify(switch_core_session_t *session, int status,
char const *phrase, char const *phrase,
nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sofia_private_t *sofia_private, sip_t const *sip, tagi_t tags[]) nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sofia_private_t *sofia_private, sip_t const *sip, tagi_t tags[])
@ -177,7 +189,6 @@ void sofia_event_callback(nua_event_t event,
case nua_i_bye: case nua_i_bye:
case nua_r_unsubscribe: case nua_r_unsubscribe:
case nua_r_publish: case nua_r_publish:
case nua_r_notify:
case nua_i_cancel: case nua_i_cancel:
case nua_i_error: case nua_i_error:
case nua_i_active: case nua_i_active:
@ -185,6 +196,9 @@ void sofia_event_callback(nua_event_t event,
case nua_i_terminated: case nua_i_terminated:
case nua_r_set_params: case nua_r_set_params:
break; break;
case nua_r_notify:
sofia_handle_sip_r_notify(session, status, phrase, nua, profile, nh, sofia_private, sip, tags);
break;
case nua_i_notify: case nua_i_notify:
sofia_handle_sip_i_notify(session, status, phrase, nua, profile, nh, sofia_private, sip, tags); sofia_handle_sip_i_notify(session, status, phrase, nua, profile, nh, sofia_private, sip, tags);
break; break;
@ -462,6 +476,7 @@ void *SWITCH_THREAD_FUNC sofia_profile_thread_run(switch_thread_t *thread, void
sofia_glue_del_profile(profile); sofia_glue_del_profile(profile);
switch_core_hash_destroy(&profile->chat_hash); switch_core_hash_destroy(&profile->chat_hash);
switch_core_hash_destroy(&profile->sub_hash);
switch_thread_rwlock_unlock(profile->rwlock); switch_thread_rwlock_unlock(profile->rwlock);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Write unlock %s\n", profile->name); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Write unlock %s\n", profile->name);
@ -789,6 +804,7 @@ switch_status_t config_sofia(int reload, char *profile_name)
profile->dbname = switch_core_strdup(profile->pool, url); profile->dbname = switch_core_strdup(profile->pool, url);
switch_core_hash_init(&profile->chat_hash, profile->pool); switch_core_hash_init(&profile->chat_hash, profile->pool);
switch_core_hash_init(&profile->sub_hash, profile->pool);
switch_thread_rwlock_create(&profile->rwlock, profile->pool); switch_thread_rwlock_create(&profile->rwlock, profile->pool);
switch_mutex_init(&profile->flag_mutex, SWITCH_MUTEX_NESTED, profile->pool); switch_mutex_init(&profile->flag_mutex, SWITCH_MUTEX_NESTED, profile->pool);
profile->dtmf_duration = 100; profile->dtmf_duration = 100;

View File

@ -1684,7 +1684,7 @@ int sofia_glue_init_sql(sofia_profile_t *profile)
switch_odbc_handle_exec(profile->master_odbc, reg_sql, NULL); switch_odbc_handle_exec(profile->master_odbc, reg_sql, NULL);
} }
if (switch_odbc_handle_exec(profile->master_odbc, "select contact from sip_subscriptions", NULL) != SWITCH_ODBC_SUCCESS) { if (switch_odbc_handle_exec(profile->master_odbc, "delete from sip_subscriptions", NULL) != SWITCH_ODBC_SUCCESS) {
switch_odbc_handle_exec(profile->master_odbc, "DROP TABLE sip_subscriptions", NULL); switch_odbc_handle_exec(profile->master_odbc, "DROP TABLE sip_subscriptions", NULL);
switch_odbc_handle_exec(profile->master_odbc, sub_sql, NULL); switch_odbc_handle_exec(profile->master_odbc, sub_sql, NULL);
} }
@ -1700,7 +1700,7 @@ int sofia_glue_init_sql(sofia_profile_t *profile)
} }
switch_core_db_test_reactive(profile->master_db, "select call_id from sip_registrations", "DROP TABLE sip_registrations", reg_sql); switch_core_db_test_reactive(profile->master_db, "select call_id from sip_registrations", "DROP TABLE sip_registrations", reg_sql);
switch_core_db_test_reactive(profile->master_db, "select contact from sip_subscriptions", "DROP TABLE sip_subscriptions", sub_sql); switch_core_db_test_reactive(profile->master_db, "delete from sip_subscriptions", "DROP TABLE sip_subscriptions", sub_sql);
switch_core_db_test_reactive(profile->master_db, "select * from sip_authentication", "DROP TABLE sip_authentication", auth_sql); switch_core_db_test_reactive(profile->master_db, "select * from sip_authentication", "DROP TABLE sip_authentication", auth_sql);
#ifdef SWITCH_HAVE_ODBC #ifdef SWITCH_HAVE_ODBC

View File

@ -114,7 +114,7 @@ void sofia_presence_cancel(void)
switch_hash_index_t *hi; switch_hash_index_t *hi;
void *val; void *val;
if ((sql = switch_mprintf("select 0,'unavailable','unavailable',* from sip_subscriptions where event='presence'"))) { if ((sql = switch_mprintf("select *,-1,'unavailable','unavailable' from sip_subscriptions where event='presence'"))) {
switch_mutex_lock(mod_sofia_globals.hash_mutex); switch_mutex_lock(mod_sofia_globals.hash_mutex);
for (hi = switch_hash_first(NULL, mod_sofia_globals.profile_hash); hi; hi = switch_hash_next(hi)) { for (hi = switch_hash_first(NULL, mod_sofia_globals.profile_hash); hi; hi = switch_hash_next(hi)) {
switch_hash_this(hi, NULL, NULL, &val); switch_hash_this(hi, NULL, NULL, &val);
@ -153,9 +153,9 @@ void sofia_presence_establish_presence(sofia_profile_t *profile)
char *sofia_presence_translate_rpid(char *in, char *ext) char *sofia_presence_translate_rpid(char *in, char *ext)
{ {
char *r = NULL; char *r = in;
if (in && (strstr(in, "null") || strstr(in, "NULL"))) { if (in && (switch_stristr(in, "null"))) {
in = NULL; in = NULL;
} }
@ -167,14 +167,10 @@ char *sofia_presence_translate_rpid(char *in, char *ext)
return NULL; return NULL;
} }
if (!strcasecmp(in, "dnd")) { if (!strcasecmp(in, "dnd") || !strcasecmp(in, "idle")) {
r = "busy"; r = "busy";
} }
if (ext && !strcasecmp(ext, "away")) {
r = "idle";
}
return r; return r;
} }
@ -245,6 +241,7 @@ void sofia_presence_mwi_event_handler(switch_event_t *event)
} }
} }
void sofia_presence_event_handler(switch_event_t *event) void sofia_presence_event_handler(switch_event_t *event)
{ {
sofia_profile_t *profile = NULL; sofia_profile_t *profile = NULL;
@ -293,9 +290,9 @@ void sofia_presence_event_handler(switch_event_t *event)
if (event->event_id == SWITCH_EVENT_ROSTER) { if (event->event_id == SWITCH_EVENT_ROSTER) {
if (from) { if (from) {
sql = switch_mprintf("select 1,'%q','%q',* from sip_subscriptions where event='presence' and full_from like '%%%q%%'", status, rpid, from); sql = switch_mprintf("select *,1,'%q','%q' from sip_subscriptions where event='presence' and full_from like '%%%q%%'", status, rpid, from);
} else { } else {
sql = switch_mprintf("select 1,'%q','%q',* from sip_subscriptions where event='presence'", status, rpid); sql = switch_mprintf("select *,1,'%q','%q' from sip_subscriptions where event='presence'", status, rpid);
} }
assert(sql != NULL); assert(sql != NULL);
@ -388,13 +385,13 @@ void sofia_presence_event_handler(switch_event_t *event)
case SWITCH_EVENT_PRESENCE_IN: case SWITCH_EVENT_PRESENCE_IN:
sql = sql =
switch_mprintf switch_mprintf
("select 1,'%q','%q',* from sip_subscriptions where proto='%q' and event='%q' and sub_to_user='%q' and sub_to_host='%q'", ("select *,1,'%q','%q' from sip_subscriptions where proto='%q' and event='%q' and sub_to_user='%q' and sub_to_host='%q'",
status, rpid, proto, event_type, euser, host); status, rpid, proto, event_type, euser, host);
break; break;
case SWITCH_EVENT_PRESENCE_OUT: case SWITCH_EVENT_PRESENCE_OUT:
sql = sql =
switch_mprintf switch_mprintf
("select 0,'%q','%q',* from sip_subscriptions where proto='%q' and event='%q' and sub_to_user='%q' and sub_to_host='%q'", ("select *,0,'%q','%q' from sip_subscriptions where proto='%q' and event='%q' and sub_to_user='%q' and sub_to_host='%q'",
status, rpid, proto, event_type, euser, host); status, rpid, proto, event_type, euser, host);
break; break;
default: default:
@ -486,34 +483,82 @@ static int sofia_presence_resub_callback(void *pArg, int argc, char **argv, char
return 0; return 0;
} }
static char *translate_rpid(char *in)
{
char *r = in;
if (in && (strstr(in, "null") || strstr(in, "NULL"))) {
in = NULL;
}
if (!in || !strcasecmp(in, "unknown")) {
r = "online";
goto end;
}
if (!strcasecmp(in, "busy")) {
r = in;
goto end;
}
if (!strcasecmp(in, "unavailable")) {
r = "away";
goto end;
}
if (!strcasecmp(in, "idle")) {
r = "busy";
}
end:
return r;
}
static int sofia_presence_sub_callback(void *pArg, int argc, char **argv, char **columnNames) static int sofia_presence_sub_callback(void *pArg, int argc, char **argv, char **columnNames)
{ {
sofia_profile_t *profile = (sofia_profile_t *) pArg; sofia_profile_t *profile = (sofia_profile_t *) pArg;
char *pl; char *pl;
char *id, *note; char *id, *note;
uint32_t in = atoi(argv[0]); uint32_t in = atoi(argv[11]);
char *status = argv[1]; char *status = argv[12];
char *rpid = argv[2]; char *rpid = argv[13];
char *proto = argv[3];
char *user = argv[4]; char *proto = argv[0];
char *host = argv[5]; char *user = argv[1];
char *sub_to_user = argv[6]; char *host = argv[2];
char *sub_to_host = argv[7]; char *sub_to_user = argv[3];
char *event = argv[8]; char *sub_to_host = argv[4];
char *contact = argv[9]; char *event = argv[5];
char *callid = argv[10]; char *contact = argv[6];
char *full_from = argv[11]; char *call_id = argv[7];
char *full_via = argv[12]; //char *full_from = argv[8];
//char *full_via = argv[9];
//char *expires = argv[10];
nua_handle_t *nh; nua_handle_t *nh;
char *to; char *to;
char *open; char *open;
char *tmp; char *tmp;
char *prpid = "onthephone"; char *prpid;
int done = 0;
if (!(nh = (nua_handle_t *) switch_core_hash_find(profile->sub_hash, call_id))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot find handle for %s\n", call_id);
return 0;
}
if (!rpid) { if (!rpid) {
rpid = "unknown"; rpid = "unknown";
} }
prpid = translate_rpid(rpid);
if (in < 0) {
done = 1;
in = 0;
}
if (in) { if (in) {
note = switch_mprintf("<dm:note>%s</dm:note>", status); note = switch_mprintf("<dm:note>%s</dm:note>", status);
open = "open"; open = "open";
@ -542,7 +587,7 @@ static int sofia_presence_sub_callback(void *pArg, int argc, char **argv, char *
"<presentity uri=\"%s;method=SUBSCRIBE\"/>\r\n" "<presentity uri=\"%s;method=SUBSCRIBE\"/>\r\n"
"<atom id=\"1002\">\r\n" "<atom id=\"1002\">\r\n"
"<address uri=\"%s\" priority=\"0.800000\">\r\n" "<address uri=\"%s\" priority=\"0.800000\">\r\n"
"<status status=\"inuse\">\r\n" "<status status=\"%s\">\r\n"
"<note>%s</note>\r\n" "<note>%s</note>\r\n"
"</status>\r\n" "</status>\r\n"
"<msnsubstatus substatus=\"%s\"/>\r\n" "<msnsubstatus substatus=\"%s\"/>\r\n"
@ -554,28 +599,26 @@ static int sofia_presence_sub_callback(void *pArg, int argc, char **argv, char *
"</status>\r\n" "</status>\r\n"
"</tuple>\r\n" "</tuple>\r\n"
"<dm:person id='p06360c4a'>\r\n" "<dm:person id='p06360c4a'>\r\n"
"<rpid:activities>\r\n" "<rpid:%s/>\r\n" "</rpid:activities>%s</dm:person>\r\n" "</presence>", id, "<rpid:activities>\r\n" "<rpid:%s/>\r\n"
id, profile->url, status, prpid, "</rpid:activities>%s</dm:person>\r\n"
"</presence>", id,
id, profile->url, open, status, prpid,
open, rpid, note); open, rpid, note);
tmp = contact; tmp = contact;
contact = sofia_glue_get_url_from_contact(tmp, 0); contact = sofia_glue_get_url_from_contact(tmp, 0);
nh = nua_handle(profile->nua, NULL, TAG_END());
nua_notify(nh, nua_notify(nh,
NUTAG_NEWSUB(1),
NUTAG_URL(contact),
SIPTAG_TO_STR(full_from),
SIPTAG_FROM_STR(id),
SIPTAG_CONTACT_STR(profile->url),
SIPTAG_CALL_ID_STR(callid),
SIPTAG_VIA_STR(full_via),
SIPTAG_SUBSCRIPTION_STATE_STR("active;expires=3600"), SIPTAG_SUBSCRIPTION_STATE_STR("active;expires=3600"),
SIPTAG_EVENT_STR(event), SIPTAG_CONTENT_TYPE_STR("application/pidf+xml"), SIPTAG_PAYLOAD_STR(pl), TAG_END()); SIPTAG_EVENT_STR(event), SIPTAG_CONTENT_TYPE_STR("application/pidf+xml"), SIPTAG_PAYLOAD_STR(pl), TAG_END());
if (done) {
switch_core_hash_delete(profile->sub_hash, call_id);
}
switch_safe_free(id); switch_safe_free(id);
switch_safe_free(note); switch_safe_free(note);
switch_safe_free(pl); switch_safe_free(pl);
@ -594,8 +637,8 @@ static int sofia_presence_mwi_callback(void *pArg, int argc, char **argv, char *
char *event = argv[5]; char *event = argv[5];
char *contact = argv[6]; char *contact = argv[6];
char *call_id = argv[7]; char *call_id = argv[7];
char *full_from = argv[8]; //char *full_from = argv[8];
char *full_via = argv[9]; //char *full_via = argv[9];
char *expires = argv[10]; char *expires = argv[10];
char *body = argv[11]; char *body = argv[11];
char *exp; char *exp;
@ -609,8 +652,10 @@ static int sofia_presence_mwi_callback(void *pArg, int argc, char **argv, char *
return 0; return 0;
} }
nh = nua_handle(profile->nua, NULL, TAG_END()); if (!(nh = (nua_handle_t *) switch_core_hash_find(profile->sub_hash, call_id))) {
assert(nh != NULL); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot find handle for %s\n", call_id);
return 0;
}
id = switch_mprintf("sip:%s@%s", sub_to_user, sub_to_host); id = switch_mprintf("sip:%s@%s", sub_to_user, sub_to_host);
expire_sec = (int)(expire_sec - time(NULL)); expire_sec = (int)(expire_sec - time(NULL));
@ -623,15 +668,6 @@ static int sofia_presence_mwi_callback(void *pArg, int argc, char **argv, char *
contact = sofia_glue_get_url_from_contact(tmp, 0); contact = sofia_glue_get_url_from_contact(tmp, 0);
nua_notify(nh, nua_notify(nh,
NUTAG_WITH_THIS(profile->nua),
NUTAG_NEWSUB(1),
NUTAG_URL(contact),
SIPTAG_TO_STR(full_from),
SIPTAG_FROM_STR(id),
//SIPTAG_CONTACT_STR(profile->url),
SIPTAG_CONTACT_STR(id),
SIPTAG_CALL_ID_STR(call_id),
SIPTAG_VIA_STR(full_via),
SIPTAG_SUBSCRIPTION_STATE_STR(exp), SIPTAG_SUBSCRIPTION_STATE_STR(exp),
SIPTAG_EVENT_STR(event), SIPTAG_CONTENT_TYPE_STR("application/simple-message-summary"), SIPTAG_PAYLOAD_STR(body), TAG_END()); SIPTAG_EVENT_STR(event), SIPTAG_CONTENT_TYPE_STR("application/simple-message-summary"), SIPTAG_PAYLOAD_STR(body), TAG_END());
@ -663,13 +699,18 @@ void sofia_presence_handle_sip_i_subscribe(int status,
char *proto = "sip"; char *proto = "sip";
char *d_user = NULL; char *d_user = NULL;
char *contact_str = ""; char *contact_str = "";
char *call_id = NULL; const char *call_id = NULL;
char *to_str = NULL; char *to_str = NULL;
char *full_from = NULL; char *full_from = NULL;
char *full_via = NULL; char *full_via = NULL;
char *sstr; char *sstr;
const char *display = "\"user\""; const char *display = "\"user\"";
switch_event_t *sevent; switch_event_t *sevent;
int sub_state;
tl_gets(tags,
NUTAG_SUBSTATE_REF(sub_state), TAG_END());
if (contact) { if (contact) {
char *port = (char *) contact->m_url->url_port; char *port = (char *) contact->m_url->url_port;
@ -708,8 +749,15 @@ void sofia_presence_handle_sip_i_subscribe(int status,
to_host = (char *) to->a_url->url_host; to_host = (char *) to->a_url->url_host;
} }
if (sip && sip->sip_from) {
from_user = (char *) sip->sip_from->a_url->url_user;
from_host = (char *) sip->sip_from->a_url->url_host;
} else {
from_user = "n/a";
from_host = "n/a";
}
if (strstr(to_user, "ext+") || strstr(to_user, "user+") || strstr(to_user, "conf+")) { if (strstr(to_user, "ext+") || strstr(to_user, "user+")) {
char proto[80]; char proto[80];
char *p; char *p;
@ -719,13 +767,23 @@ void sofia_presence_handle_sip_i_subscribe(int status,
} }
if (switch_event_create(&sevent, SWITCH_EVENT_PRESENCE_IN) == SWITCH_STATUS_SUCCESS) { if (switch_event_create(&sevent, SWITCH_EVENT_PRESENCE_IN) == SWITCH_STATUS_SUCCESS) {
switch_event_add_header(sevent, SWITCH_STACK_BOTTOM, "proto", SOFIA_CHAT_PROTO); switch_event_add_header(sevent, SWITCH_STACK_BOTTOM, "proto", proto);
switch_event_add_header(sevent, SWITCH_STACK_BOTTOM, "login", "%s", profile->name); switch_event_add_header(sevent, SWITCH_STACK_BOTTOM, "login", "%s", profile->name);
switch_event_add_header(sevent, SWITCH_STACK_BOTTOM, "from", "%s@%s", to_user, to_host); switch_event_add_header(sevent, SWITCH_STACK_BOTTOM, "from", "%s@%s", to_user, to_host);
switch_event_add_header(sevent, SWITCH_STACK_BOTTOM, "rpid", "unknown"); switch_event_add_header(sevent, SWITCH_STACK_BOTTOM, "rpid", "active");
switch_event_add_header(sevent, SWITCH_STACK_BOTTOM, "status", "Click To Call"); switch_event_add_header(sevent, SWITCH_STACK_BOTTOM, "status", "Click To Call");
switch_event_fire(&sevent); switch_event_fire(&sevent);
} }
} else {
if (switch_event_create(&sevent, SWITCH_EVENT_PRESENCE_PROBE) == SWITCH_STATUS_SUCCESS) {
switch_event_add_header(sevent, SWITCH_STACK_BOTTOM, "proto", SOFIA_CHAT_PROTO);
switch_event_add_header(sevent, SWITCH_STACK_BOTTOM, "login", "%s", 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_fire(&sevent);
}
} }
if (strchr(to_user, '+')) { if (strchr(to_user, '+')) {
@ -746,7 +804,7 @@ void sofia_presence_handle_sip_i_subscribe(int status,
} }
} }
call_id = sip_header_as_string(profile->home, (void *) sip->sip_call_id); call_id = sip->sip_call_id->i_id; //sip_header_as_string(profile->home, (void *) sip->sip_call_id);
event = sip_header_as_string(profile->home, (void *) sip->sip_event); event = sip_header_as_string(profile->home, (void *) sip->sip_event);
full_from = sip_header_as_string(profile->home, (void *) sip->sip_from); full_from = sip_header_as_string(profile->home, (void *) sip->sip_from);
full_via = sip_header_as_string(profile->home, (void *) sip->sip_via); full_via = sip_header_as_string(profile->home, (void *) sip->sip_via);
@ -754,13 +812,7 @@ void sofia_presence_handle_sip_i_subscribe(int status,
exp_raw = (sip->sip_expires ? sip->sip_expires->ex_delta : 3600); exp_raw = (sip->sip_expires ? sip->sip_expires->ex_delta : 3600);
exp = (long) time(NULL) + exp_raw; exp = (long) time(NULL) + exp_raw;
if (sip && sip->sip_from) {
from_user = (char *) sip->sip_from->a_url->url_user;
from_host = (char *) sip->sip_from->a_url->url_host;
} else {
from_user = "n/a";
from_host = "n/a";
}
switch_mutex_lock(profile->ireg_mutex); switch_mutex_lock(profile->ireg_mutex);
@ -776,6 +828,11 @@ void sofia_presence_handle_sip_i_subscribe(int status,
assert(sql != NULL); assert(sql != NULL);
sofia_glue_execute_sql(profile, SWITCH_FALSE, sql, NULL); sofia_glue_execute_sql(profile, SWITCH_FALSE, sql, NULL);
free(sql); free(sql);
if (sub_state == nua_substate_terminated) {
sstr = switch_mprintf("terminated");
switch_core_hash_delete(profile->sub_hash, call_id);
} else {
sql = switch_mprintf("insert into sip_subscriptions values ('%q','%q','%q','%q','%q','%q','%q','%q','%q','%q',%ld)", sql = switch_mprintf("insert into sip_subscriptions values ('%q','%q','%q','%q','%q','%q','%q','%q','%q','%q',%ld)",
proto, from_user, from_host, to_user, to_host, event, contact_str, call_id, full_from, full_via, exp); proto, from_user, from_host, to_user, to_host, event, contact_str, call_id, full_from, full_via, exp);
@ -783,9 +840,12 @@ void sofia_presence_handle_sip_i_subscribe(int status,
sofia_glue_execute_sql(profile, SWITCH_FALSE, sql, NULL); sofia_glue_execute_sql(profile, SWITCH_FALSE, sql, NULL);
free(sql); free(sql);
switch_mutex_unlock(profile->ireg_mutex);
switch_mutex_unlock(profile->ireg_mutex);
sstr = switch_mprintf("active;expires=%ld", exp_raw); sstr = switch_mprintf("active;expires=%ld", exp_raw);
switch_core_hash_insert(profile->sub_hash, call_id, nh);
}
nua_respond(nh, SIP_202_ACCEPTED, nua_respond(nh, SIP_202_ACCEPTED,
NUTAG_WITH_THIS(nua), NUTAG_WITH_THIS(nua),
@ -815,9 +875,13 @@ void sofia_presence_handle_sip_i_subscribe(int status,
if (event) { if (event) {
su_free(profile->home, event); su_free(profile->home, event);
} }
/*
if (call_id) { if (call_id) {
su_free(profile->home, call_id); su_free(profile->home, call_id);
} }
*/
if (full_from) { if (full_from) {
su_free(profile->home, full_from); su_free(profile->home, full_from);
} }

View File

@ -344,7 +344,7 @@ uint8_t sofia_reg_handle_register(nua_t * nua, sofia_profile_t *profile, nua_han
char *register_gateway = NULL; char *register_gateway = NULL;
int network_port; int network_port;
int cd = 0; int cd = 0;
char *call_id = NULL; const char *call_id = NULL;
/* all callers must confirm that sip, sip->sip_request and sip->sip_contact are not NULL */ /* all callers must confirm that sip, sip->sip_request and sip->sip_contact are not NULL */
assert(sip != NULL && sip->sip_contact != NULL && sip->sip_request != NULL); assert(sip != NULL && sip->sip_contact != NULL && sip->sip_request != NULL);
@ -475,7 +475,7 @@ uint8_t sofia_reg_handle_register(nua_t * nua, sofia_profile_t *profile, nua_han
return 0; return 0;
} }
call_id = sip_header_as_string(profile->home, (void *) sip->sip_call_id); call_id = sip->sip_call_id->i_id; //sip_header_as_string(profile->home, (void *) sip->sip_call_id);
assert(call_id); assert(call_id);
@ -582,9 +582,11 @@ uint8_t sofia_reg_handle_register(nua_t * nua, sofia_profile_t *profile, nua_han
} }
/*
if (call_id) { if (call_id) {
su_free(profile->home, call_id); su_free(profile->home, call_id);
} }
*/
if (regtype == REG_REGISTER) { if (regtype == REG_REGISTER) {
char *new_contact = NULL; char *new_contact = NULL;

View File

@ -201,7 +201,6 @@ SWITCH_DECLARE(const char *) switch_stristr(const char *str, const char *instr)
{ {
switch_size_t score = strlen(str), x = 0; switch_size_t score = strlen(str), x = 0;
const char *a = str, *b = instr, *p = NULL; const char *a = str, *b = instr, *p = NULL;
while(*a && *b) { while(*a && *b) {
if (tolower(*b) == tolower(*a)) { if (tolower(*b) == tolower(*a)) {
if (++x == score) { if (++x == score) {