2007-04-02 19:54:25 +00:00
|
|
|
/*
|
|
|
|
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
|
2011-01-05 10:08:55 -06:00
|
|
|
* Copyright (C) 2005-2011, Anthony Minessale II <anthm@freeswitch.org>
|
2007-04-02 19:54:25 +00:00
|
|
|
*
|
|
|
|
* Version: MPL 1.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
2009-02-04 21:20:54 +00:00
|
|
|
* Anthony Minessale II <anthm@freeswitch.org>
|
2007-04-02 19:54:25 +00:00
|
|
|
* Portions created by the Initial Developer are Copyright (C)
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
*
|
2009-02-04 21:20:54 +00:00
|
|
|
* Anthony Minessale II <anthm@freeswitch.org>
|
2007-04-02 19:54:25 +00:00
|
|
|
* Ken Rice, Asteria Solutions Group, Inc <ken@asteriasgi.com>
|
|
|
|
* Paul D. Tinsley <pdt at jackhammer.org>
|
|
|
|
* Bret McDanel <trixter AT 0xdecafbad.com>
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* sofia_presence.c -- SOFIA SIP Endpoint (presence code)
|
|
|
|
*
|
|
|
|
*/
|
2007-03-31 19:01:33 +00:00
|
|
|
#include "mod_sofia.h"
|
2010-01-08 21:22:06 +00:00
|
|
|
#include "switch_stun.h"
|
2007-03-31 19:01:33 +00:00
|
|
|
|
2008-12-11 20:20:20 +00:00
|
|
|
#define SUB_OVERLAP 300
|
2010-01-07 06:09:35 +00:00
|
|
|
struct state_helper {
|
|
|
|
switch_hash_t *hash;
|
|
|
|
sofia_profile_t *profile;
|
|
|
|
switch_memory_pool_t *pool;
|
2012-01-26 04:46:48 -06:00
|
|
|
int total;
|
2010-01-07 06:09:35 +00:00
|
|
|
};
|
|
|
|
|
2008-12-11 20:20:20 +00:00
|
|
|
|
2007-04-02 19:54:25 +00:00
|
|
|
static int sofia_presence_mwi_callback(void *pArg, int argc, char **argv, char **columnNames);
|
2007-12-13 23:30:16 +00:00
|
|
|
static int sofia_presence_mwi_callback2(void *pArg, int argc, char **argv, char **columnNames);
|
2007-04-02 19:54:25 +00:00
|
|
|
static int sofia_presence_sub_reg_callback(void *pArg, int argc, char **argv, char **columnNames);
|
|
|
|
static int sofia_presence_resub_callback(void *pArg, int argc, char **argv, char **columnNames);
|
|
|
|
static int sofia_presence_sub_callback(void *pArg, int argc, char **argv, char **columnNames);
|
2010-01-07 06:09:35 +00:00
|
|
|
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);
|
2012-01-26 04:46:48 -06:00
|
|
|
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);
|
2011-10-21 20:00:34 -05:00
|
|
|
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);
|
2009-12-24 05:44:23 +00:00
|
|
|
|
2010-07-29 23:39:39 -05:00
|
|
|
struct dialog_helper {
|
2012-02-02 12:05:15 -06:00
|
|
|
char state[128];
|
2010-07-29 23:39:39 -05:00
|
|
|
char status[512];
|
|
|
|
char rpid[512];
|
2010-12-20 15:43:54 -06:00
|
|
|
char presence_id[1024];
|
2011-10-24 18:54:22 -05:00
|
|
|
int hits;
|
2010-07-29 23:39:39 -05:00
|
|
|
};
|
|
|
|
|
2009-12-24 05:44:23 +00:00
|
|
|
struct resub_helper {
|
|
|
|
sofia_profile_t *profile;
|
|
|
|
switch_event_t *event;
|
2010-07-27 22:08:47 -05:00
|
|
|
int rowcount;
|
2010-10-22 15:13:44 -05:00
|
|
|
int noreg;
|
2009-12-24 05:44:23 +00:00
|
|
|
};
|
2007-03-31 19:01:33 +00:00
|
|
|
|
2011-10-21 20:00:34 -05:00
|
|
|
struct rfc4235_helper {
|
|
|
|
switch_hash_t *hash;
|
|
|
|
sofia_profile_t *profile;
|
|
|
|
switch_memory_pool_t *pool;
|
|
|
|
switch_event_t *event;
|
|
|
|
int rowcount;
|
|
|
|
};
|
|
|
|
|
2007-12-15 00:39:53 +00:00
|
|
|
struct presence_helper {
|
|
|
|
sofia_profile_t *profile;
|
|
|
|
switch_event_t *event;
|
2007-12-18 01:12:50 +00:00
|
|
|
switch_stream_handle_t stream;
|
2008-04-11 19:41:24 +00:00
|
|
|
char last_uuid[512];
|
2007-12-15 00:39:53 +00:00
|
|
|
};
|
|
|
|
|
2011-09-13 16:51:30 -05:00
|
|
|
switch_status_t sofia_presence_chat_send(switch_event_t *message_event)
|
|
|
|
|
2007-03-31 19:01:33 +00:00
|
|
|
{
|
2008-09-27 20:52:33 +00:00
|
|
|
char *prof = NULL, *user = NULL, *host = NULL;
|
2007-04-29 01:16:49 +00:00
|
|
|
sofia_profile_t *profile = NULL;
|
2007-03-31 19:01:33 +00:00
|
|
|
char *ffrom = NULL;
|
|
|
|
nua_handle_t *msg_nh;
|
2009-03-04 22:39:47 +00:00
|
|
|
char *contact = NULL;
|
2008-09-27 20:52:33 +00:00
|
|
|
char *dup = NULL;
|
2008-06-27 17:46:04 +00:00
|
|
|
switch_status_t status = SWITCH_STATUS_FALSE;
|
2008-07-23 18:19:56 +00:00
|
|
|
const char *ct = "text/html";
|
2009-06-19 15:35:26 +00:00
|
|
|
sofia_destination_t *dst = NULL;
|
2010-04-11 18:51:37 -04:00
|
|
|
char *to_uri = NULL;
|
2010-08-18 14:58:14 -05:00
|
|
|
switch_console_callback_match_t *list = NULL;
|
|
|
|
switch_console_callback_match_node_t *m;
|
2010-12-02 16:52:23 -06:00
|
|
|
char *remote_ip = NULL;
|
|
|
|
char *user_via = NULL;
|
2011-10-21 20:04:43 -05:00
|
|
|
//char *contact_str = NULL;
|
2010-12-02 16:52:23 -06:00
|
|
|
char *dup_dest = NULL;
|
2011-02-28 09:27:05 -06:00
|
|
|
char *p = NULL;
|
2010-12-09 12:01:24 -06:00
|
|
|
char *remote_host = NULL;
|
2011-09-13 16:51:30 -05:00
|
|
|
const char *proto;
|
|
|
|
const char *from;
|
|
|
|
const char *to;
|
|
|
|
//const char *subject;
|
|
|
|
const char *body;
|
|
|
|
const char *type;
|
2011-09-21 14:31:10 -05:00
|
|
|
const char *from_full;
|
|
|
|
char header[256] = "";
|
|
|
|
char *route_uri = NULL;
|
2011-10-21 20:38:41 -05:00
|
|
|
const char *network_ip = NULL, *network_port = NULL, *from_proto;
|
2012-02-22 15:26:38 -06:00
|
|
|
char *extra_headers = NULL;
|
2011-10-21 20:38:41 -05:00
|
|
|
|
2011-09-13 16:51:30 -05:00
|
|
|
proto = switch_event_get_header(message_event, "proto");
|
2011-10-21 20:38:41 -05:00
|
|
|
from_proto = switch_event_get_header(message_event, "from_proto");
|
2011-09-13 16:51:30 -05:00
|
|
|
from = switch_event_get_header(message_event, "from");
|
|
|
|
to = switch_event_get_header(message_event, "to");
|
|
|
|
//subject = switch_event_get_header(message_event, "subject");
|
|
|
|
body = switch_event_get_body(message_event);
|
|
|
|
type = switch_event_get_header(message_event, "type");
|
2011-09-21 14:31:10 -05:00
|
|
|
from_full = switch_event_get_header(message_event, "from_full");
|
|
|
|
|
|
|
|
network_ip = switch_event_get_header(message_event, "to_sip_ip");
|
|
|
|
network_port = switch_event_get_header(message_event, "to_sip_port");
|
2008-07-23 18:19:56 +00:00
|
|
|
|
2012-02-22 15:26:38 -06:00
|
|
|
extra_headers = sofia_glue_get_extra_headers_from_event(message_event, SOFIA_SIP_HEADER_PREFIX);
|
|
|
|
|
2007-11-20 03:26:40 +00:00
|
|
|
if (!to) {
|
2008-06-27 17:46:04 +00:00
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing To: header.\n");
|
|
|
|
goto end;
|
2007-11-20 03:26:40 +00:00
|
|
|
}
|
2007-03-31 19:01:33 +00:00
|
|
|
|
2009-10-23 16:03:42 +00:00
|
|
|
if (!zstr(type)) {
|
2009-01-20 21:24:37 +00:00
|
|
|
ct = type;
|
|
|
|
}
|
|
|
|
|
2008-09-27 20:52:33 +00:00
|
|
|
dup = strdup(to);
|
|
|
|
switch_assert(dup);
|
|
|
|
prof = dup;
|
|
|
|
|
2008-10-11 19:20:11 +00:00
|
|
|
/* Do we have a user of the form profile/user[@host]? */
|
2008-09-27 20:52:33 +00:00
|
|
|
if ((user = strchr(prof, '/'))) {
|
|
|
|
*user++ = '\0';
|
|
|
|
} else {
|
|
|
|
user = prof;
|
|
|
|
prof = NULL;
|
2010-02-06 03:38:24 +00:00
|
|
|
}
|
2011-09-21 14:31:10 -05:00
|
|
|
|
|
|
|
if (!prof) {
|
|
|
|
prof = switch_event_get_header(message_event, "sip_profile");
|
|
|
|
}
|
2010-04-11 18:51:37 -04:00
|
|
|
|
|
|
|
if (!strncasecmp(user, "sip:", 4)) {
|
|
|
|
to_uri = user;
|
|
|
|
}
|
2007-03-31 19:01:33 +00:00
|
|
|
|
2007-11-20 03:26:40 +00:00
|
|
|
if ((host = strchr(user, '@'))) {
|
2010-04-11 18:51:37 -04:00
|
|
|
if (!to_uri) {
|
|
|
|
*host++ = '\0';
|
|
|
|
} else {
|
|
|
|
host++;
|
|
|
|
}
|
2011-09-21 14:31:10 -05:00
|
|
|
if (!prof) {
|
2010-02-06 03:38:24 +00:00
|
|
|
prof = host;
|
2011-09-21 14:31:10 -05:00
|
|
|
}
|
2007-11-20 03:26:40 +00:00
|
|
|
}
|
2007-03-31 19:01:33 +00:00
|
|
|
|
2009-01-20 21:24:37 +00:00
|
|
|
if (!prof || !(profile = sofia_glue_find_profile(prof))) {
|
2007-11-20 03:26:40 +00:00
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
|
2011-09-02 14:41:20 -05:00
|
|
|
"Chat proto [%s]\nfrom [%s]\nto [%s]\n%s\nInvalid Profile %s\n", proto, from, to,
|
2008-09-27 20:52:33 +00:00
|
|
|
body ? body : "[no body]", prof ? prof : "NULL");
|
2008-06-27 17:46:04 +00:00
|
|
|
goto end;
|
2007-11-20 03:26:40 +00:00
|
|
|
}
|
2007-03-31 19:01:33 +00:00
|
|
|
|
2009-10-23 16:03:42 +00:00
|
|
|
if (zstr(host)) {
|
2009-01-20 21:24:37 +00:00
|
|
|
host = profile->domain_name;
|
2009-10-23 16:03:42 +00:00
|
|
|
if (zstr(host)) {
|
2009-01-20 21:28:25 +00:00
|
|
|
host = prof;
|
2009-01-20 21:24:37 +00:00
|
|
|
}
|
|
|
|
}
|
2010-08-18 14:58:14 -05:00
|
|
|
|
2011-09-21 14:31:10 -05:00
|
|
|
|
2010-08-18 14:58:14 -05:00
|
|
|
if (to_uri) {
|
|
|
|
switch_console_push_match(&list, to_uri);
|
|
|
|
} else if (!(list = sofia_reg_find_reg_url_multi(profile, user, host))) {
|
2011-09-21 14:31:10 -05:00
|
|
|
sofia_profile_t *test;
|
|
|
|
|
|
|
|
if ((test = sofia_glue_find_profile(host))) {
|
|
|
|
sofia_glue_release_profile(test);
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Not sending to local box for %s@%s\n", user, host);
|
|
|
|
/* our box let's not send it */
|
|
|
|
} else {
|
|
|
|
char *tmp;
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Can't find registered user %s@%s\n", user, host);
|
|
|
|
tmp = switch_mprintf("sip:%s@%s", user, host);
|
|
|
|
switch_console_push_match(&list, tmp);
|
|
|
|
free(tmp);
|
|
|
|
}
|
|
|
|
|
2007-11-20 03:26:40 +00:00
|
|
|
}
|
2010-08-18 14:58:14 -05:00
|
|
|
|
2008-06-27 17:46:04 +00:00
|
|
|
if (!strcasecmp(proto, SOFIA_CHAT_PROTO)) {
|
2011-09-21 14:31:10 -05:00
|
|
|
from = from_full;
|
2007-11-20 03:26:40 +00:00
|
|
|
} else {
|
2009-01-20 21:24:37 +00:00
|
|
|
char *fp, *p = NULL;
|
2010-08-18 14:58:14 -05:00
|
|
|
|
2011-10-21 20:38:41 -05:00
|
|
|
|
2007-11-20 03:26:40 +00:00
|
|
|
fp = strdup(from);
|
2011-09-21 14:31:10 -05:00
|
|
|
switch_assert(fp);
|
2009-01-20 21:24:37 +00:00
|
|
|
|
2007-03-31 19:01:33 +00:00
|
|
|
|
2007-11-20 03:26:40 +00:00
|
|
|
if ((p = strchr(fp, '@'))) {
|
2009-01-20 21:24:37 +00:00
|
|
|
*p++ = '\0';
|
2007-03-31 19:01:33 +00:00
|
|
|
}
|
|
|
|
|
2009-10-23 16:03:42 +00:00
|
|
|
if (zstr(p)) {
|
2009-01-20 21:28:54 +00:00
|
|
|
p = profile->domain_name;
|
2009-10-23 16:03:42 +00:00
|
|
|
if (zstr(p)) {
|
2009-01-20 21:28:25 +00:00
|
|
|
p = host;
|
2009-01-20 21:24:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-21 14:31:10 -05:00
|
|
|
if (switch_stristr("global", proto)) {
|
2011-10-21 20:38:41 -05:00
|
|
|
if (!from_proto || !strcasecmp(from_proto, SOFIA_CHAT_PROTO)) {
|
|
|
|
ffrom = switch_mprintf("\"%s\" <sip:%s@%s>", fp, fp, p);
|
|
|
|
} else {
|
|
|
|
ffrom = switch_mprintf("\"%s\" <sip:%s+%s@%s>", fp, from_proto, fp, p);
|
|
|
|
}
|
|
|
|
|
2011-09-21 14:31:10 -05:00
|
|
|
} else {
|
2011-10-21 20:38:41 -05:00
|
|
|
ffrom = switch_mprintf("\"%s\" <sip:%s+%s@%s>", fp, from_proto ? from_proto : proto, fp, p);
|
2011-09-21 14:31:10 -05:00
|
|
|
}
|
2009-01-20 21:24:37 +00:00
|
|
|
|
2007-11-20 03:26:40 +00:00
|
|
|
from = ffrom;
|
|
|
|
switch_safe_free(fp);
|
|
|
|
}
|
2010-02-06 03:38:24 +00:00
|
|
|
|
2011-09-21 14:31:10 -05:00
|
|
|
if (!list) {
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
|
|
|
|
"Chat proto [%s]\nfrom [%s]\nto [%s]\n%s\nNobody to send to: Profile %s\n", proto, from, to,
|
|
|
|
body ? body : "[no body]", prof ? prof : "NULL");
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
2010-08-18 14:58:14 -05:00
|
|
|
for (m = list->head; m; m = m->next) {
|
2010-02-06 03:38:24 +00:00
|
|
|
|
2010-08-18 14:58:14 -05:00
|
|
|
if (!(dst = sofia_glue_get_destination(m->val))) {
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Memory Error!\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* sofia_glue is running sofia_overcome_sip_uri_weakness we do not, not sure if it matters */
|
|
|
|
|
2011-02-28 09:27:05 -06:00
|
|
|
if (dst->route_uri) {
|
|
|
|
dup_dest = strdup(dst->route_uri);
|
|
|
|
} else {
|
|
|
|
dup_dest = strdup(dst->to);
|
|
|
|
}
|
|
|
|
|
2010-12-02 16:52:23 -06:00
|
|
|
|
2011-05-22 19:10:52 -05:00
|
|
|
remote_host = strdup(dup_dest);
|
|
|
|
if (!zstr(remote_host)) {
|
|
|
|
switch_split_user_domain(remote_host, NULL, &remote_ip);
|
2010-12-02 16:52:23 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!zstr(remote_ip) && sofia_glue_check_nat(profile, remote_ip)) {
|
|
|
|
char *ptr = NULL;
|
2011-04-22 16:43:29 -05:00
|
|
|
//const char *transport_str = NULL;
|
2010-12-02 16:52:23 -06:00
|
|
|
if ((ptr = sofia_glue_find_parameter(dst->contact, "transport="))) {
|
|
|
|
sofia_transport_t transport = sofia_glue_str2transport(ptr);
|
2011-04-22 16:43:29 -05:00
|
|
|
//transport_str = sofia_glue_transport2str(transport);
|
2010-12-02 16:52:23 -06:00
|
|
|
switch (transport) {
|
|
|
|
case SOFIA_TRANSPORT_TCP:
|
|
|
|
break;
|
|
|
|
case SOFIA_TRANSPORT_TCP_TLS:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
user_via = sofia_glue_create_external_via(NULL, profile, transport);
|
|
|
|
} else {
|
|
|
|
user_via = sofia_glue_create_external_via(NULL, profile, SOFIA_TRANSPORT_UDP);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-18 14:58:14 -05:00
|
|
|
status = SWITCH_STATUS_SUCCESS;
|
2010-12-02 16:52:23 -06:00
|
|
|
|
2011-02-28 09:27:05 -06:00
|
|
|
if (dup_dest && (p = strstr(dup_dest, ";fs_"))) {
|
2011-02-15 16:30:57 -06:00
|
|
|
*p = '\0';
|
|
|
|
}
|
2011-02-28 09:27:05 -06:00
|
|
|
|
2011-02-15 16:30:57 -06:00
|
|
|
/* if this cries, add contact here too, change the 1 to 0 and omit the safe_free */
|
2011-09-02 14:41:20 -05:00
|
|
|
|
2011-09-21 14:31:10 -05:00
|
|
|
//printf("DEBUG To: [%s] From: [%s] Contact: [%s] RURI [%s] ip [%s] port [%s]\n", to, from, contact, dst->route_uri, network_ip, network_port);
|
|
|
|
|
|
|
|
//DUMP_EVENT(message_event);
|
|
|
|
|
|
|
|
if (zstr(dst->route_uri) && !zstr(user) && !zstr(network_ip) && (zstr(host) || strcmp(network_ip, host))) {
|
|
|
|
route_uri = switch_mprintf("sip:%s@%s:%s", user, network_ip, network_port);
|
|
|
|
}
|
|
|
|
|
2010-12-02 16:52:23 -06:00
|
|
|
msg_nh = nua_handle(profile->nua, NULL,
|
|
|
|
TAG_END());
|
|
|
|
|
2010-08-18 14:58:14 -05:00
|
|
|
nua_handle_bind(msg_nh, &mod_sofia_globals.destroy_private);
|
2010-12-02 16:52:23 -06:00
|
|
|
|
2011-09-21 14:31:10 -05:00
|
|
|
switch_snprintf(header, sizeof(header), "X-FS-Sending-Message: %s", switch_core_get_uuid());
|
|
|
|
|
2010-12-02 16:52:23 -06:00
|
|
|
nua_message(msg_nh,
|
2011-09-21 14:31:10 -05:00
|
|
|
TAG_IF(dst->route_uri, NUTAG_PROXY(dst->route_uri)),
|
|
|
|
TAG_IF(route_uri, NUTAG_PROXY(route_uri)),
|
|
|
|
TAG_IF(dst->route, SIPTAG_ROUTE_STR(dst->route)),
|
|
|
|
SIPTAG_FROM_STR(from),
|
|
|
|
TAG_IF(contact, NUTAG_URL(contact)),
|
|
|
|
SIPTAG_TO_STR(dup_dest),
|
|
|
|
|
2010-12-02 16:52:23 -06:00
|
|
|
TAG_IF(user_via, SIPTAG_VIA_STR(user_via)),
|
|
|
|
SIPTAG_CONTENT_TYPE_STR(ct),
|
|
|
|
SIPTAG_PAYLOAD_STR(body),
|
2011-09-21 14:31:10 -05:00
|
|
|
SIPTAG_HEADER_STR(header),
|
2012-02-22 15:26:38 -06:00
|
|
|
TAG_IF(!zstr(extra_headers), SIPTAG_HEADER_STR(extra_headers)),
|
2010-12-02 16:52:23 -06:00
|
|
|
TAG_END());
|
|
|
|
|
2010-08-18 14:58:14 -05:00
|
|
|
sofia_glue_free_destination(dst);
|
2011-02-28 09:27:05 -06:00
|
|
|
switch_safe_free(dup_dest);
|
|
|
|
switch_safe_free(remote_host);
|
2010-08-18 14:58:14 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
switch_console_free_matches(&list);
|
2010-02-06 03:38:24 +00:00
|
|
|
|
|
|
|
end:
|
2010-08-18 14:58:14 -05:00
|
|
|
|
2009-03-04 22:39:47 +00:00
|
|
|
switch_safe_free(contact);
|
2011-09-21 14:31:10 -05:00
|
|
|
switch_safe_free(route_uri);
|
2007-11-20 03:26:40 +00:00
|
|
|
switch_safe_free(ffrom);
|
2008-09-27 20:52:33 +00:00
|
|
|
switch_safe_free(dup);
|
2010-12-02 16:52:23 -06:00
|
|
|
|
2007-11-20 03:26:40 +00:00
|
|
|
if (profile) {
|
|
|
|
switch_thread_rwlock_unlock(profile->rwlock);
|
2007-03-31 19:01:33 +00:00
|
|
|
}
|
|
|
|
|
2008-06-27 17:46:04 +00:00
|
|
|
return status;
|
2007-03-31 19:01:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void sofia_presence_cancel(void)
|
|
|
|
{
|
2007-04-04 03:08:17 +00:00
|
|
|
char *sql;
|
2007-03-31 19:01:33 +00:00
|
|
|
sofia_profile_t *profile;
|
2007-12-18 01:12:50 +00:00
|
|
|
struct presence_helper helper = { 0 };
|
2011-06-16 14:32:08 -05:00
|
|
|
switch_console_callback_match_t *matches;
|
2008-02-04 19:01:22 +00:00
|
|
|
|
2011-06-16 14:32:08 -05:00
|
|
|
if (!mod_sofia_globals.profile_hash) {
|
2008-05-27 04:54:52 +00:00
|
|
|
return;
|
2011-06-16 14:32:08 -05:00
|
|
|
}
|
|
|
|
|
2011-07-14 16:01:44 -05:00
|
|
|
if (list_profiles_full(NULL, NULL, &matches, SWITCH_FALSE) == SWITCH_STATUS_SUCCESS) {
|
2011-06-16 14:32:08 -05:00
|
|
|
switch_console_callback_match_node_t *m;
|
|
|
|
|
|
|
|
sql = switch_mprintf("select proto,sip_user,sip_host,sub_to_user,sub_to_host,event,contact,call_id,full_from,"
|
|
|
|
"full_via,expires,user_agent,accept,profile_name,network_ip"
|
2012-01-26 15:53:05 -06:00
|
|
|
",-1,'unavailable','unavailable' from sip_subscriptions where "
|
|
|
|
"event='presence' and hostname='%q'",
|
2011-06-16 14:32:08 -05:00
|
|
|
mod_sofia_globals.hostname);
|
|
|
|
|
2010-02-06 03:38:24 +00:00
|
|
|
|
2011-06-16 14:32:08 -05:00
|
|
|
for (m = matches->head; m; m = m->next) {
|
|
|
|
if ((profile = sofia_glue_find_profile(m->val))) {
|
|
|
|
if (profile->pres_type == PRES_TYPE_FULL) {
|
|
|
|
helper.profile = profile;
|
|
|
|
helper.event = NULL;
|
|
|
|
if (sofia_glue_execute_sql_callback(profile, profile->ireg_mutex, sql, sofia_presence_sub_callback, &helper) != SWITCH_TRUE) {
|
|
|
|
sofia_glue_release_profile(profile);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sofia_glue_release_profile(profile);
|
2007-03-31 19:01:33 +00:00
|
|
|
}
|
|
|
|
}
|
2011-06-16 14:32:08 -05:00
|
|
|
|
2007-03-31 19:01:33 +00:00
|
|
|
switch_safe_free(sql);
|
2011-06-16 14:32:08 -05:00
|
|
|
switch_console_free_matches(&matches);
|
|
|
|
|
2007-03-31 19:01:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
char *sofia_presence_translate_rpid(char *in, char *ext)
|
|
|
|
{
|
2007-10-24 23:20:47 +00:00
|
|
|
char *r = in;
|
2007-03-31 19:01:33 +00:00
|
|
|
|
2007-11-15 16:22:18 +00:00
|
|
|
if (in && (switch_stristr("null", in))) {
|
2007-03-31 19:01:33 +00:00
|
|
|
in = NULL;
|
|
|
|
}
|
2008-05-27 04:54:52 +00:00
|
|
|
|
2007-03-31 19:01:33 +00:00
|
|
|
if (!in) {
|
|
|
|
in = ext;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!in) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2007-10-24 23:20:47 +00:00
|
|
|
if (!strcasecmp(in, "dnd") || !strcasecmp(in, "idle")) {
|
2007-03-31 19:01:33 +00:00
|
|
|
r = "busy";
|
|
|
|
}
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2008-05-08 16:09:49 +00:00
|
|
|
struct mwi_helper {
|
|
|
|
sofia_profile_t *profile;
|
|
|
|
int total;
|
|
|
|
};
|
|
|
|
|
2008-03-14 03:46:54 +00:00
|
|
|
static void actual_sofia_presence_mwi_event_handler(switch_event_t *event)
|
2007-04-02 19:54:25 +00:00
|
|
|
{
|
2008-01-11 01:03:51 +00:00
|
|
|
char *account, *dup_account, *yn, *host, *user;
|
2007-04-02 19:54:25 +00:00
|
|
|
char *sql;
|
2007-04-29 01:16:49 +00:00
|
|
|
sofia_profile_t *profile = NULL;
|
2007-04-02 19:54:25 +00:00
|
|
|
switch_stream_handle_t stream = { 0 };
|
|
|
|
switch_event_header_t *hp;
|
2008-05-08 16:09:49 +00:00
|
|
|
struct mwi_helper h = { 0 };
|
2010-06-18 17:38:50 -05:00
|
|
|
const char *pname = NULL;
|
2009-03-27 00:27:07 +00:00
|
|
|
const char *call_id;
|
|
|
|
const char *sub_call_id;
|
2009-03-30 17:20:46 +00:00
|
|
|
int for_everyone = 0;
|
2008-05-08 16:09:49 +00:00
|
|
|
|
2007-12-12 23:21:45 +00:00
|
|
|
switch_assert(event != NULL);
|
2007-04-02 19:54:25 +00:00
|
|
|
|
2008-01-11 01:03:51 +00:00
|
|
|
if (!(account = switch_event_get_header(event, "mwi-message-account"))) {
|
2007-04-02 19:54:25 +00:00
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing required Header 'MWI-Message-Account'\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(yn = switch_event_get_header(event, "mwi-messages-waiting"))) {
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing required Header 'MWI-Messages-Waiting'\n");
|
|
|
|
return;
|
|
|
|
}
|
2008-01-11 01:03:51 +00:00
|
|
|
|
2009-03-27 00:27:07 +00:00
|
|
|
call_id = switch_event_get_header(event, "call-id");
|
|
|
|
sub_call_id = switch_event_get_header(event, "sub-call-id");
|
|
|
|
|
2009-03-30 17:20:46 +00:00
|
|
|
if (!call_id && !sub_call_id) {
|
|
|
|
for_everyone = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-11 01:03:51 +00:00
|
|
|
dup_account = strdup(account);
|
2007-12-12 23:21:45 +00:00
|
|
|
switch_assert(dup_account != NULL);
|
2010-06-02 01:09:54 +02:00
|
|
|
switch_split_user_domain(dup_account, &user, &host);
|
2007-04-02 19:54:25 +00:00
|
|
|
|
2008-05-08 16:09:49 +00:00
|
|
|
|
2011-06-09 10:36:35 -05:00
|
|
|
if ((pname = switch_event_get_header(event, "sofia-profile"))) {
|
2010-06-18 17:38:50 -05:00
|
|
|
profile = sofia_glue_find_profile(pname);
|
2008-05-08 16:09:49 +00:00
|
|
|
}
|
2012-02-10 10:49:19 -06:00
|
|
|
|
2008-05-08 16:09:49 +00:00
|
|
|
if (!profile) {
|
|
|
|
if (!host || !(profile = sofia_glue_find_profile(host))) {
|
2011-06-09 10:45:28 -05:00
|
|
|
char *sql;
|
|
|
|
char buf[512] = "";
|
2011-06-16 14:32:08 -05:00
|
|
|
switch_console_callback_match_t *matches;
|
2011-06-09 10:45:28 -05:00
|
|
|
|
2012-02-01 16:44:18 -06:00
|
|
|
sql = switch_mprintf("select profile_name from sip_registrations where hostname='%q' and (sip_host='%s' or mwi_host='%s')",
|
|
|
|
mod_sofia_globals.hostname, host, host);
|
2012-02-10 10:49:19 -06:00
|
|
|
|
2011-07-14 16:01:44 -05:00
|
|
|
if (list_profiles_full(NULL, NULL, &matches, SWITCH_FALSE) == SWITCH_STATUS_SUCCESS) {
|
2011-06-16 14:32:08 -05:00
|
|
|
switch_console_callback_match_node_t *m;
|
|
|
|
|
|
|
|
for (m = matches->head; m; m = m->next) {
|
|
|
|
if ((profile = sofia_glue_find_profile(m->val))) {
|
|
|
|
|
|
|
|
sofia_glue_execute_sql2str(profile, profile->ireg_mutex, sql, buf, sizeof(buf));
|
|
|
|
if (!zstr(buf)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
sofia_glue_release_profile(profile);
|
|
|
|
}
|
2011-06-09 10:45:28 -05:00
|
|
|
}
|
2011-06-16 14:32:08 -05:00
|
|
|
|
|
|
|
switch_console_free_matches(&matches);
|
2011-06-09 10:45:28 -05:00
|
|
|
}
|
2011-06-16 14:32:08 -05:00
|
|
|
|
2012-02-01 16:44:18 -06:00
|
|
|
switch_safe_free(sql);
|
2011-06-09 10:45:28 -05:00
|
|
|
|
|
|
|
if (!(profile = sofia_glue_find_profile(buf))) {
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot find profile %s\n", switch_str_nil(host));
|
|
|
|
switch_safe_free(dup_account);
|
|
|
|
return;
|
|
|
|
}
|
2008-05-08 16:09:49 +00:00
|
|
|
}
|
2007-04-02 19:54:25 +00:00
|
|
|
}
|
2008-05-27 04:54:52 +00:00
|
|
|
|
2012-02-10 10:49:19 -06:00
|
|
|
|
2008-08-13 17:24:33 +00:00
|
|
|
if (profile->domain_name && strcasecmp(profile->domain_name, host)) {
|
2008-05-08 16:09:49 +00:00
|
|
|
host = profile->domain_name;
|
|
|
|
}
|
|
|
|
|
|
|
|
h.profile = profile;
|
|
|
|
h.total = 0;
|
|
|
|
|
2007-04-02 19:54:25 +00:00
|
|
|
SWITCH_STANDARD_STREAM(stream);
|
|
|
|
|
|
|
|
for (hp = event->headers; hp; hp = hp->next) {
|
|
|
|
if (!strncasecmp(hp->name, "mwi-", 4)) {
|
2007-10-12 22:08:30 +00:00
|
|
|
char *tmp = NULL;
|
|
|
|
char *value = hp->value;
|
|
|
|
if (!strcasecmp(hp->name, "mwi-message-account") && strncasecmp(hp->value, "sip:", 4)) {
|
|
|
|
tmp = switch_mprintf("sip:%s", hp->value);
|
|
|
|
value = tmp;
|
2008-05-27 04:54:52 +00:00
|
|
|
}
|
2007-10-12 22:08:30 +00:00
|
|
|
stream.write_function(&stream, "%s: %s\r\n", hp->name + 4, value);
|
|
|
|
switch_safe_free(tmp);
|
2007-04-02 19:54:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
stream.write_function(&stream, "\r\n");
|
2010-02-06 03:38:24 +00:00
|
|
|
|
2009-03-27 00:27:07 +00:00
|
|
|
sql = NULL;
|
|
|
|
|
2009-03-30 17:20:46 +00:00
|
|
|
if (for_everyone) {
|
2009-03-27 00:27:07 +00:00
|
|
|
sql = switch_mprintf("select proto,sip_user,sip_host,sub_to_user,sub_to_host,event,contact,call_id,full_from,"
|
2009-06-04 01:18:00 +00:00
|
|
|
"full_via,expires,user_agent,accept,profile_name,network_ip"
|
2012-01-30 11:43:43 -06:00
|
|
|
",'%q',full_to,network_ip,network_port from sip_subscriptions "
|
|
|
|
"where hostname='%q' and profile_name='%q' and event='message-summary' "
|
|
|
|
"and sub_to_user='%q' and (sub_to_host='%q' or presence_hosts like '%%%q%%')",
|
|
|
|
stream.data, mod_sofia_globals.hostname, profile->name, user, host, host);
|
2009-03-30 17:20:46 +00:00
|
|
|
} else if (sub_call_id) {
|
2009-03-27 00:27:07 +00:00
|
|
|
sql = switch_mprintf("select proto,sip_user,sip_host,sub_to_user,sub_to_host,event,contact,call_id,full_from,"
|
2009-06-04 01:18:00 +00:00
|
|
|
"full_via,expires,user_agent,accept,profile_name,network_ip"
|
2012-01-30 11:43:43 -06:00
|
|
|
",'%q',full_to,network_ip,network_port from sip_subscriptions where "
|
|
|
|
"hostname='%q' and profile_name='%q' and event='message-summary' "
|
2012-01-26 15:53:05 -06:00
|
|
|
"and sub_to_user='%q' and (sub_to_host='%q' or presence_hosts like '%%%q%%') and call_id='%q'",
|
2012-01-30 11:43:43 -06:00
|
|
|
stream.data, mod_sofia_globals.hostname, profile->name, user, host, host, sub_call_id);
|
2009-03-27 00:27:07 +00:00
|
|
|
}
|
|
|
|
|
2009-03-30 17:20:46 +00:00
|
|
|
|
2009-03-27 00:27:07 +00:00
|
|
|
if (sql) {
|
2009-11-12 03:52:07 +00:00
|
|
|
sofia_glue_execute_sql_callback(profile, profile->ireg_mutex, sql, sofia_presence_mwi_callback, &h);
|
2009-03-30 17:20:46 +00:00
|
|
|
free(sql);
|
|
|
|
sql = NULL;
|
2010-02-06 03:38:24 +00:00
|
|
|
|
2009-03-30 17:20:46 +00:00
|
|
|
}
|
2008-05-27 04:54:52 +00:00
|
|
|
|
2009-03-30 17:20:46 +00:00
|
|
|
if (for_everyone) {
|
2011-08-19 17:29:42 -05:00
|
|
|
sql = switch_mprintf("select sip_user,sip_host,contact,profile_name,network_ip,'%q' "
|
2012-01-30 11:43:43 -06:00
|
|
|
"from sip_registrations where hostname='%q' and profile_name='%q' and mwi_user='%q' and mwi_host='%q'",
|
|
|
|
stream.data, mod_sofia_globals.hostname, profile->name, user, host);
|
2009-03-27 00:27:07 +00:00
|
|
|
} else if (call_id) {
|
2011-08-19 17:29:42 -05:00
|
|
|
sql = switch_mprintf("select sip_user,sip_host,contact,profile_name,network_ip,'%q' "
|
2012-02-10 10:49:19 -06:00
|
|
|
"from sip_registrations where hostname='%q' and profile_name='%q' and call_id='%q'",
|
|
|
|
stream.data, mod_sofia_globals.hostname, profile->name, call_id);
|
2009-03-30 17:20:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (sql) {
|
2009-03-27 00:27:07 +00:00
|
|
|
switch_assert(sql != NULL);
|
2009-11-12 03:52:07 +00:00
|
|
|
sofia_glue_execute_sql_callback(profile, profile->ireg_mutex, sql, sofia_presence_mwi_callback2, &h);
|
2009-03-30 17:20:46 +00:00
|
|
|
free(sql);
|
|
|
|
sql = NULL;
|
2009-03-27 00:27:07 +00:00
|
|
|
}
|
2008-05-27 04:54:52 +00:00
|
|
|
|
2007-12-13 23:30:16 +00:00
|
|
|
switch_safe_free(stream.data);
|
2007-04-02 19:54:25 +00:00
|
|
|
switch_safe_free(dup_account);
|
2009-03-27 00:27:07 +00:00
|
|
|
|
2007-04-29 01:16:49 +00:00
|
|
|
if (profile) {
|
2007-05-03 01:55:25 +00:00
|
|
|
sofia_glue_release_profile(profile);
|
2007-04-29 01:16:49 +00:00
|
|
|
}
|
2007-04-02 19:54:25 +00:00
|
|
|
}
|
|
|
|
|
2010-07-29 23:39:39 -05:00
|
|
|
static int sofia_presence_dialog_callback(void *pArg, int argc, char **argv, char **columnNames)
|
|
|
|
{
|
|
|
|
struct dialog_helper *helper = (struct dialog_helper *) pArg;
|
|
|
|
|
2012-02-02 19:58:39 -06:00
|
|
|
if (argc >= 4) {
|
|
|
|
|
|
|
|
if (mod_sofia_globals.debug_presence > 0) {
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "CHECK DIALOG state[%s] status[%s] rpid[%s] pres[%s]\n",
|
|
|
|
argv[0], argv[1], argv[2], argv[3]);
|
|
|
|
}
|
|
|
|
|
2012-02-01 19:32:22 -06:00
|
|
|
if (!helper->hits) {
|
2012-02-02 12:05:15 -06:00
|
|
|
switch_set_string(helper->state, argv[0]);
|
|
|
|
switch_set_string(helper->status, argv[1]);
|
|
|
|
switch_set_string(helper->rpid, argv[2]);
|
|
|
|
switch_set_string(helper->presence_id, argv[3]);
|
2012-02-01 19:32:22 -06:00
|
|
|
}
|
2011-10-24 18:54:22 -05:00
|
|
|
helper->hits++;
|
2010-07-29 23:39:39 -05:00
|
|
|
}
|
|
|
|
|
2012-02-01 19:32:22 -06:00
|
|
|
return 0;
|
2010-07-29 23:39:39 -05:00
|
|
|
}
|
|
|
|
|
2011-10-21 20:00:34 -05:00
|
|
|
|
2012-01-26 04:46:48 -06:00
|
|
|
static void do_normal_probe(switch_event_t *event)
|
2011-10-21 20:00:34 -05:00
|
|
|
{
|
|
|
|
char *sql;
|
|
|
|
struct resub_helper h = { 0 };
|
|
|
|
char *to = switch_event_get_header(event, "to");
|
|
|
|
char *proto = switch_event_get_header(event, "proto");
|
|
|
|
char *probe_user = NULL, *probe_euser, *probe_host, *p;
|
|
|
|
struct dialog_helper dh = { { 0 } };
|
2012-01-26 04:46:48 -06:00
|
|
|
char *sub_call_id = switch_event_get_header(event, "sub-call-id");
|
|
|
|
sofia_profile_t *profile;
|
2011-10-21 20:00:34 -05:00
|
|
|
|
2011-10-24 18:54:22 -05:00
|
|
|
//DUMP_EVENT(event);
|
|
|
|
|
2011-10-21 20:00:34 -05:00
|
|
|
if (!proto || strcasecmp(proto, SOFIA_CHAT_PROTO) != 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!to || !(probe_user = strdup(to))) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((probe_host = strchr(probe_user, '@'))) {
|
|
|
|
*probe_host++ = '\0';
|
|
|
|
}
|
|
|
|
probe_euser = probe_user;
|
|
|
|
if ((p = strchr(probe_euser, '+'))) {
|
|
|
|
probe_euser = (p + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (probe_euser && probe_host && (profile = sofia_glue_find_profile(probe_host))) {
|
2012-02-02 19:58:39 -06:00
|
|
|
sql = switch_mprintf("select state,status,rpid,presence_id from sip_dialogs "
|
2012-01-30 11:43:43 -06:00
|
|
|
"where hostname='%q' and profile_name='%q' and "
|
|
|
|
"((sip_from_user='%q' and sip_from_host='%q') or presence_id='%q@%q') order by rcd desc",
|
|
|
|
mod_sofia_globals.hostname, profile->name, probe_euser, probe_host, probe_euser, probe_host);
|
2012-01-26 04:46:48 -06:00
|
|
|
|
|
|
|
|
2011-10-21 20:00:34 -05:00
|
|
|
sofia_glue_execute_sql_callback(profile, profile->ireg_mutex, sql, sofia_presence_dialog_callback, &dh);
|
|
|
|
|
|
|
|
h.profile = profile;
|
|
|
|
|
|
|
|
switch_safe_free(sql);
|
|
|
|
|
|
|
|
sql = switch_mprintf("select sip_registrations.sip_user, "
|
2012-02-14 18:59:37 -06:00
|
|
|
"sip_registrations.sub_host, "
|
|
|
|
"sip_registrations.status, "
|
|
|
|
"sip_registrations.rpid, "
|
|
|
|
"'', "
|
|
|
|
"sip_dialogs.uuid, "
|
|
|
|
"sip_dialogs.state, "
|
|
|
|
"sip_dialogs.direction, "
|
|
|
|
"sip_dialogs.sip_to_user, "
|
|
|
|
"sip_dialogs.sip_to_host, "
|
|
|
|
|
|
|
|
"sip_presence.status,"
|
|
|
|
"sip_presence.rpid,"
|
|
|
|
"sip_dialogs.presence_id, "
|
|
|
|
"sip_presence.open_closed,"
|
|
|
|
"'%q','%q','%q' "
|
|
|
|
"from sip_registrations "
|
|
|
|
|
|
|
|
"left join sip_dialogs on "
|
|
|
|
"sip_dialogs.hostname = sip_registrations.hostname and sip_dialogs.profile_name = sip_registrations.profile_name and ("
|
|
|
|
"sip_dialogs.presence_id = sip_registrations.sip_user %q '@' %q sip_registrations.sub_host "
|
|
|
|
"or (sip_dialogs.sip_from_user = sip_registrations.sip_user "
|
|
|
|
"and sip_dialogs.sip_from_host = sip_registrations.sip_host)) "
|
2011-10-21 20:00:34 -05:00
|
|
|
|
2012-02-14 18:59:37 -06:00
|
|
|
"left join sip_presence on "
|
|
|
|
"sip_presence.hostname=sip_registrations.hostname and "
|
|
|
|
"(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_registrations.hostname='%q' and sip_registrations.profile_name='%q' and 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' "
|
|
|
|
"))",
|
|
|
|
dh.status, dh.rpid, switch_str_nil(sub_call_id),
|
|
|
|
switch_sql_concat(), switch_sql_concat(),
|
|
|
|
mod_sofia_globals.hostname, profile->name, probe_euser, probe_host, probe_euser, probe_host, probe_host);
|
2012-01-26 04:46:48 -06:00
|
|
|
|
2012-02-14 18:59:37 -06:00
|
|
|
|
2012-01-26 04:46:48 -06:00
|
|
|
|
2011-10-21 20:00:34 -05:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mod_sofia_globals.debug_presence > 1) {
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "%s DUMP PRESENCE_PROBE_SQL:\n%s\n", profile->name, sql);
|
|
|
|
}
|
|
|
|
|
|
|
|
sofia_glue_execute_sql_callback(profile, profile->ireg_mutex, sql, sofia_presence_resub_callback, &h);
|
2012-01-26 04:46:48 -06:00
|
|
|
|
2011-10-21 20:00:34 -05:00
|
|
|
|
|
|
|
if (!h.rowcount) {
|
|
|
|
h.noreg++;
|
|
|
|
switch_safe_free(sql);
|
2012-01-26 04:46:48 -06:00
|
|
|
|
2011-10-21 20:00:34 -05:00
|
|
|
/* find ones with presence_id defined that are not registred */
|
|
|
|
sql = switch_mprintf("select sip_from_user, sip_from_host, 'Registered', '', '', "
|
|
|
|
"uuid, state, direction, "
|
|
|
|
"sip_to_user, sip_to_host,"
|
|
|
|
"'%q','%q',presence_id, '','','' "
|
|
|
|
|
|
|
|
"from sip_dialogs "
|
|
|
|
|
2012-01-30 11:43:43 -06:00
|
|
|
"where hostname='%q' and profile_name='%q' and (presence_id='%q@%q' or "
|
2011-10-21 20:00:34 -05:00
|
|
|
"(sip_from_user='%q' and (sip_from_host='%q' or sip_to_host='%q')))",
|
2012-01-30 11:43:43 -06:00
|
|
|
mod_sofia_globals.hostname, profile->name,
|
2011-10-21 20:00:34 -05:00
|
|
|
dh.status, dh.rpid, probe_euser, probe_host, probe_euser, probe_host, probe_host);
|
|
|
|
|
|
|
|
if (mod_sofia_globals.debug_presence > 0) {
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "%s START_PRESENCE_PROBE_SQL\n", profile->name);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mod_sofia_globals.debug_presence > 1) {
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "%s DUMP PRESENCE_PROBE_SQL:\n%s\n", profile->name, sql);
|
|
|
|
}
|
|
|
|
|
|
|
|
sofia_glue_execute_sql_callback(profile, profile->ireg_mutex, sql, sofia_presence_resub_callback, &h);
|
|
|
|
|
|
|
|
if (mod_sofia_globals.debug_presence > 0) {
|
|
|
|
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_safe_free(probe_user);
|
|
|
|
}
|
|
|
|
|
2012-01-26 04:46:48 -06:00
|
|
|
static void do_dialog_probe(switch_event_t *event)
|
2011-10-21 20:00:34 -05:00
|
|
|
{
|
|
|
|
// 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;
|
2012-01-26 04:46:48 -06:00
|
|
|
sofia_profile_t *profile;
|
2011-10-21 20:00:34 -05:00
|
|
|
|
|
|
|
if (!to || !(probe_user = strdup(to))) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((probe_host = strchr(probe_user, '@'))) {
|
|
|
|
*probe_host++ = '\0';
|
|
|
|
}
|
|
|
|
probe_euser = probe_user;
|
|
|
|
if ((p = strchr(probe_euser, '+'))) {
|
|
|
|
probe_euser = (p + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (probe_euser && probe_host && (profile = sofia_glue_find_profile(probe_host))) {
|
|
|
|
char *sub_call_id = switch_event_get_header(event, "sub-call-id");
|
|
|
|
struct rfc4235_helper *h4235 = {0};
|
|
|
|
switch_memory_pool_t *pool;
|
|
|
|
|
|
|
|
// We need all dialogs with presence_id matching the subscription entity,
|
|
|
|
// or from a registered set matching the subscription entity.
|
|
|
|
// We need the "proto" of the subscription in case it is for the special "conf" or "park".
|
|
|
|
sql = switch_mprintf(
|
|
|
|
"select sip_subscriptions.proto, '%q','%q',"
|
|
|
|
"sip_dialogs.uuid, sip_dialogs.call_id, sip_dialogs.state, sip_dialogs.direction, "
|
|
|
|
"sip_dialogs.sip_to_user, sip_dialogs.sip_to_host, "
|
|
|
|
"sip_dialogs.sip_from_user, sip_dialogs.sip_from_host, "
|
|
|
|
"sip_dialogs.contact, sip_dialogs.contact_user, sip_dialogs.contact_host, "
|
2011-10-24 09:49:34 -05:00
|
|
|
"sip_dialogs.sip_to_tag, sip_dialogs.sip_from_tag, sip_subscriptions.orig_proto "
|
2011-10-21 20:00:34 -05:00
|
|
|
"from sip_dialogs "
|
2012-01-30 11:43:43 -06:00
|
|
|
"left join sip_subscriptions on sip_subscriptions.hostname=sip_dialogs.hostname and "
|
|
|
|
"sip_subscriptions.profile_name=sip_dialogs.profile_name and "
|
|
|
|
"sip_subscriptions.call_id='%q' "
|
|
|
|
"left join sip_registrations on sip_registrations.hostname=sip_dialogs.hostname and "
|
|
|
|
"sip_registrations.profile_name=sip_dialogs.profile_name and "
|
2011-10-21 20:00:34 -05:00
|
|
|
"(sip_dialogs.sip_from_user = sip_registrations.sip_user "
|
|
|
|
"and (sip_dialogs.sip_from_host = sip_registrations.orig_server_host or "
|
2012-01-24 14:52:16 -06:00
|
|
|
"sip_dialogs.sip_from_host = sip_registrations.sip_host) ) "
|
2012-01-30 11:43:43 -06:00
|
|
|
"where sip_dialogs.hostname='%q' and sip_dialogs.profile_name='%q' and "
|
|
|
|
"sip_dialogs.call_info_state != 'seized' and sip_dialogs.presence_id='%q@%q' or (sip_registrations.sip_user='%q' and "
|
2012-01-10 17:33:40 -06:00
|
|
|
"(sip_registrations.orig_server_host='%q' or sip_registrations.sub_host='%q' "
|
2011-10-21 20:00:34 -05:00
|
|
|
"or sip_registrations.presence_hosts like '%%%q%%'))",
|
|
|
|
probe_euser, probe_host,
|
2012-01-30 11:43:43 -06:00
|
|
|
sub_call_id, mod_sofia_globals.hostname, profile->name,
|
2011-10-21 20:00:34 -05:00
|
|
|
probe_euser, probe_host,
|
|
|
|
probe_euser, probe_host, 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 DIALOG_PROBE_SQL %s@%s\n", profile->name,probe_euser, probe_host);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mod_sofia_globals.debug_presence > 1) {
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s DUMP DIALOG_PROBE_SQL:\n%s\n", profile->name, sql);
|
|
|
|
}
|
|
|
|
|
|
|
|
switch_core_new_memory_pool(&pool);
|
|
|
|
h4235 = switch_core_alloc(pool, sizeof(*h4235));
|
|
|
|
h4235->pool = pool;
|
|
|
|
h4235->profile = profile;
|
|
|
|
switch_core_hash_init(&h4235->hash, h4235->pool);
|
|
|
|
sofia_glue_execute_sql_callback(profile, profile->ireg_mutex, sql, sofia_dialog_probe_callback, h4235);
|
|
|
|
switch_safe_free(sql);
|
|
|
|
if (mod_sofia_globals.debug_presence > 0) {
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "%s END DIALOG_PROBE_SQL\n\n", profile->name);
|
|
|
|
}
|
|
|
|
|
2012-01-26 15:53:05 -06:00
|
|
|
|
|
|
|
sql = switch_mprintf("update sip_subscriptions set version=version+1 "
|
2012-01-30 11:43:43 -06:00
|
|
|
"where hostname='%q' and profile_name='%q' and sub_to_user='%q' and sub_to_host='%q' and call_id='%q'",
|
|
|
|
mod_sofia_globals.hostname, profile->name, probe_euser, probe_host, sub_call_id);
|
2012-01-26 15:53:05 -06:00
|
|
|
|
|
|
|
if (mod_sofia_globals.debug_presence > 1) {
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s DUMP DIALOG_PROBE set version sql:\n%s\n", profile->name, sql);
|
|
|
|
}
|
|
|
|
sofia_glue_execute_sql_now(profile, &sql, SWITCH_TRUE);
|
|
|
|
switch_safe_free(sql);
|
|
|
|
|
|
|
|
|
2011-10-21 20:00:34 -05:00
|
|
|
// The dialog_probe_callback has built up the dialogs to be included in the NOTIFY.
|
|
|
|
// Now send the "full" dialog event to the triggering subscription.
|
|
|
|
sql = switch_mprintf("select call_id,expires,sub_to_user,sub_to_host,event,version, "
|
2012-01-17 16:08:25 -06:00
|
|
|
"'full',full_to,full_from,contact,network_ip,network_port "
|
2011-10-21 20:00:34 -05:00
|
|
|
"from sip_subscriptions "
|
2012-01-30 11:43:43 -06:00
|
|
|
"where hostname='%q' and profile_name='%q' and sub_to_user='%q' and sub_to_host='%q' and call_id='%q'",
|
|
|
|
mod_sofia_globals.hostname, profile->name, probe_euser, probe_host, sub_call_id);
|
2012-01-27 09:00:15 -06:00
|
|
|
|
2011-10-21 20:00:34 -05:00
|
|
|
if (mod_sofia_globals.debug_presence > 1) {
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s DUMP DIALOG_PROBE subscription sql:\n%s\n", profile->name, sql);
|
|
|
|
}
|
2012-01-27 09:00:15 -06:00
|
|
|
|
2011-10-21 20:00:34 -05:00
|
|
|
sofia_glue_execute_sql_callback(profile, profile->ireg_mutex, sql, sofia_dialog_probe_notify_callback, h4235);
|
|
|
|
switch_safe_free(sql);
|
|
|
|
|
|
|
|
sofia_glue_release_profile(profile);
|
|
|
|
switch_core_hash_destroy(&h4235->hash);
|
|
|
|
h4235 = NULL;
|
|
|
|
switch_core_destroy_memory_pool(&pool);
|
|
|
|
}
|
|
|
|
|
|
|
|
switch_safe_free(probe_user);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-03-14 03:46:54 +00:00
|
|
|
static void actual_sofia_presence_event_handler(switch_event_t *event)
|
2007-03-31 19:01:33 +00:00
|
|
|
{
|
2007-04-29 01:16:49 +00:00
|
|
|
sofia_profile_t *profile = NULL;
|
2007-03-31 19:01:33 +00:00
|
|
|
char *from = switch_event_get_header(event, "from");
|
|
|
|
char *proto = switch_event_get_header(event, "proto");
|
|
|
|
char *rpid = switch_event_get_header(event, "rpid");
|
|
|
|
char *status = switch_event_get_header(event, "status");
|
|
|
|
char *event_type = switch_event_get_header(event, "event_type");
|
2007-12-15 00:39:53 +00:00
|
|
|
char *alt_event_type = switch_event_get_header(event, "alt_event_type");
|
2009-12-24 05:44:23 +00:00
|
|
|
//char *event_subtype = switch_event_get_header(event, "event_subtype");
|
2007-03-31 19:01:33 +00:00
|
|
|
char *sql = NULL;
|
|
|
|
char *euser = NULL, *user = NULL, *host = NULL;
|
2009-12-24 05:44:23 +00:00
|
|
|
char *call_info = switch_event_get_header(event, "presence-call-info");
|
2012-01-26 04:46:48 -06:00
|
|
|
char *call_id = switch_event_get_header(event, "call-id");
|
2011-10-24 18:54:22 -05:00
|
|
|
char *presence_source = switch_event_get_header(event, "presence-source");
|
2009-12-24 05:44:23 +00:00
|
|
|
char *call_info_state = switch_event_get_header(event, "presence-call-info-state");
|
2012-02-02 20:41:15 -06:00
|
|
|
const char *uuid = switch_event_get_header(event, "unique-id");
|
2011-06-16 14:32:08 -05:00
|
|
|
switch_console_callback_match_t *matches;
|
2012-01-26 04:46:48 -06:00
|
|
|
struct presence_helper helper = { 0 };
|
2012-02-01 19:32:22 -06:00
|
|
|
int hup = 0;
|
2007-03-31 19:01:33 +00:00
|
|
|
|
2012-02-02 20:41:15 -06:00
|
|
|
|
2008-03-14 03:46:54 +00:00
|
|
|
if (!mod_sofia_globals.running) {
|
|
|
|
return;
|
|
|
|
}
|
2008-05-27 04:54:52 +00:00
|
|
|
|
2011-10-21 20:00:34 -05:00
|
|
|
if (zstr(proto) || !strcasecmp(proto, "any")) {
|
|
|
|
proto = SOFIA_CHAT_PROTO;
|
|
|
|
}
|
|
|
|
|
2012-01-11 21:32:23 -06:00
|
|
|
//DUMP_EVENT(event);
|
2011-10-21 20:00:34 -05:00
|
|
|
|
2007-03-31 19:01:33 +00:00
|
|
|
if (rpid && !strcasecmp(rpid, "n/a")) {
|
|
|
|
rpid = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (status && !strcasecmp(status, "n/a")) {
|
|
|
|
status = NULL;
|
|
|
|
}
|
2010-02-06 03:38:24 +00:00
|
|
|
|
2008-11-25 20:54:58 +00:00
|
|
|
if (status && switch_stristr("CS_HANGUP", status)) {
|
2010-07-29 23:39:39 -05:00
|
|
|
status = "Available";
|
2012-02-01 19:32:22 -06:00
|
|
|
hup = 1;
|
2008-11-22 16:14:56 +00:00
|
|
|
}
|
2007-03-31 19:01:33 +00:00
|
|
|
|
|
|
|
if (rpid) {
|
|
|
|
rpid = sofia_presence_translate_rpid(rpid, status);
|
|
|
|
}
|
2010-02-06 03:38:24 +00:00
|
|
|
|
2007-03-31 19:01:33 +00:00
|
|
|
if (event->event_id == SWITCH_EVENT_ROSTER) {
|
2011-07-14 16:01:44 -05:00
|
|
|
if (list_profiles_full(NULL, NULL, &matches, SWITCH_FALSE) == SWITCH_STATUS_SUCCESS) {
|
2011-06-16 14:32:08 -05:00
|
|
|
switch_console_callback_match_node_t *m;
|
|
|
|
|
|
|
|
for (m = matches->head; m; m = m->next) {
|
|
|
|
if ((profile = sofia_glue_find_profile(m->val))) {
|
|
|
|
if (profile->pres_type != PRES_TYPE_FULL) {
|
2012-02-17 09:51:04 -06:00
|
|
|
|
|
|
|
|
|
|
|
if (!mod_sofia_globals.profile_hash) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (from) {
|
|
|
|
|
|
|
|
sql = switch_mprintf("update sip_subscriptions set version=version+1 where hostname='%q' and profile_name='%q' and "
|
|
|
|
"sip_subscriptions.event='presence' and sip_subscriptions.full_from like '%%%q%%'",
|
|
|
|
mod_sofia_globals.hostname, profile->name, from);
|
|
|
|
|
|
|
|
if (mod_sofia_globals.debug_presence > 1) {
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "PRES SQL %s\n", sql);
|
|
|
|
}
|
|
|
|
|
|
|
|
sofia_glue_execute_sql_now(profile, &sql, SWITCH_TRUE);
|
|
|
|
|
|
|
|
|
|
|
|
sql = switch_mprintf("select 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,sip_subscriptions.network_ip"
|
|
|
|
",1,'%q','%q',sip_presence.status,sip_presence.rpid,sip_presence.open_closed,'','','','','sip',"
|
|
|
|
" 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 and "
|
|
|
|
"sip_presence.profile_name=sip_subscriptions.profile_name) "
|
|
|
|
"where sip_subscriptions.hostname='%q' and sip_subscriptions.profile_name='%q' and "
|
|
|
|
"sip_subscriptions.event='presence' and sip_subscriptions.full_from like '%%%q%%'",
|
|
|
|
switch_str_nil(status), switch_str_nil(rpid), mod_sofia_globals.hostname, profile->name, from);
|
|
|
|
} else {
|
|
|
|
|
|
|
|
sql = switch_mprintf("update sip_subscriptions set version=version+1 where hostname='%q' and profile_name='%q' and "
|
|
|
|
"sip_subscriptions.event='presence'", mod_sofia_globals.hostname, profile->name);
|
|
|
|
|
|
|
|
if (mod_sofia_globals.debug_presence > 1) {
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "PRES SQL %s\n", sql);
|
|
|
|
}
|
|
|
|
|
|
|
|
sofia_glue_execute_sql_now(profile, &sql, SWITCH_TRUE);
|
|
|
|
|
|
|
|
sql = switch_mprintf("select 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,sip_subscriptions.network_ip"
|
|
|
|
",1,'%q','%q',sip_presence.status,sip_presence.rpid,sip_presence.open_closed,'','','','','sip',"
|
|
|
|
"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 and "
|
|
|
|
"sip_subscriptions.hostname = sip_presence.hostname) "
|
|
|
|
"where sip_subscriptions.hostname='%q' and sip_subscriptions.profile_name='%q' and "
|
|
|
|
"sip_subscriptions.event='presence'", switch_str_nil(status),
|
|
|
|
switch_str_nil(rpid), mod_sofia_globals.hostname, profile->name);
|
|
|
|
}
|
|
|
|
|
|
|
|
switch_assert(sql != NULL);
|
|
|
|
|
|
|
|
|
2011-06-16 14:32:08 -05:00
|
|
|
if (mod_sofia_globals.debug_presence > 0) {
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "%s is passive, skipping\n", (char *) profile->name);
|
|
|
|
}
|
|
|
|
sofia_glue_release_profile(profile);
|
|
|
|
continue;
|
|
|
|
}
|
2012-02-17 09:51:04 -06:00
|
|
|
memset(&helper, 0, sizeof(helper));
|
2011-06-16 14:32:08 -05:00
|
|
|
helper.profile = profile;
|
|
|
|
helper.event = NULL;
|
|
|
|
sofia_glue_execute_sql_callback(profile, profile->ireg_mutex, sql, sofia_presence_sub_callback, &helper);
|
2012-02-17 09:51:04 -06:00
|
|
|
switch_safe_free(sql);
|
2011-06-16 14:32:08 -05:00
|
|
|
sofia_glue_release_profile(profile);
|
2008-12-10 20:54:24 +00:00
|
|
|
}
|
2007-03-31 19:01:33 +00:00
|
|
|
}
|
2011-06-16 14:32:08 -05:00
|
|
|
switch_console_free_matches(&matches);
|
2007-03-31 19:01:33 +00:00
|
|
|
}
|
2011-06-16 14:32:08 -05:00
|
|
|
|
2012-02-17 09:51:04 -06:00
|
|
|
switch_safe_free(sql);
|
2007-03-31 19:01:33 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-10-23 16:03:42 +00:00
|
|
|
if (zstr(event_type)) {
|
2007-03-31 19:01:33 +00:00
|
|
|
event_type = "presence";
|
|
|
|
}
|
|
|
|
|
2009-10-23 16:03:42 +00:00
|
|
|
if (zstr(alt_event_type)) {
|
2010-08-27 16:54:37 -05:00
|
|
|
if (!strcasecmp(event_type, "presence")) {
|
|
|
|
alt_event_type = "dialog";
|
|
|
|
} else {
|
|
|
|
alt_event_type = "presence";
|
|
|
|
}
|
2007-12-15 00:39:53 +00:00
|
|
|
}
|
2008-05-27 04:54:52 +00:00
|
|
|
|
2010-08-24 11:53:46 -05:00
|
|
|
if (from && (user = strdup(from))) {
|
2007-03-31 19:01:33 +00:00
|
|
|
if ((host = strchr(user, '@'))) {
|
|
|
|
char *p;
|
|
|
|
*host++ = '\0';
|
|
|
|
if ((p = strchr(host, '/'))) {
|
|
|
|
*p = '\0';
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
switch_safe_free(user);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if ((euser = strchr(user, '+'))) {
|
|
|
|
euser++;
|
|
|
|
} else {
|
|
|
|
euser = user;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (event->event_id) {
|
|
|
|
case SWITCH_EVENT_PRESENCE_PROBE:
|
2011-10-21 20:00:34 -05:00
|
|
|
{
|
|
|
|
char *probe_type = switch_event_get_header(event, "probe-type");
|
|
|
|
|
|
|
|
if (!probe_type || strcasecmp(probe_type, "dialog")) {
|
|
|
|
/* NORMAL PROBE */
|
2012-01-26 04:46:48 -06:00
|
|
|
do_normal_probe(event);
|
2011-10-21 20:00:34 -05:00
|
|
|
} else {
|
|
|
|
/* DIALOG PROBE */
|
2012-01-26 04:46:48 -06:00
|
|
|
do_dialog_probe(event);
|
2007-03-31 19:01:33 +00:00
|
|
|
}
|
|
|
|
}
|
2008-12-15 21:13:03 +00:00
|
|
|
goto done;
|
2011-10-21 20:00:34 -05:00
|
|
|
|
2008-12-10 20:54:24 +00:00
|
|
|
default:
|
|
|
|
break;
|
2011-10-21 20:00:34 -05:00
|
|
|
}
|
2008-12-10 20:54:24 +00:00
|
|
|
|
2011-06-16 14:32:08 -05:00
|
|
|
if (!mod_sofia_globals.profile_hash) {
|
2008-12-10 20:54:24 +00:00
|
|
|
goto done;
|
2011-06-16 14:32:08 -05:00
|
|
|
}
|
2008-12-10 20:54:24 +00:00
|
|
|
|
2011-07-14 16:01:44 -05:00
|
|
|
if (list_profiles_full(NULL, NULL, &matches, SWITCH_FALSE) == SWITCH_STATUS_SUCCESS) {
|
2011-06-16 14:32:08 -05:00
|
|
|
switch_console_callback_match_node_t *m;
|
2008-12-10 20:54:24 +00:00
|
|
|
|
2011-06-16 14:32:08 -05:00
|
|
|
for (m = matches->head; m; m = m->next) {
|
|
|
|
struct dialog_helper dh = { { 0 } };
|
2008-12-10 20:54:24 +00:00
|
|
|
|
2011-06-16 14:32:08 -05:00
|
|
|
if ((profile = sofia_glue_find_profile(m->val))) {
|
|
|
|
if (profile->pres_type != PRES_TYPE_FULL) {
|
|
|
|
if (mod_sofia_globals.debug_presence > 0) {
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "%s is passive, skipping\n", (char *) profile->name);
|
|
|
|
}
|
|
|
|
sofia_glue_release_profile(profile);
|
|
|
|
continue;
|
|
|
|
}
|
2010-02-06 03:38:24 +00:00
|
|
|
|
2012-02-02 20:41:15 -06:00
|
|
|
if (call_info) {
|
2011-06-16 14:32:08 -05:00
|
|
|
|
2010-01-07 06:09:35 +00:00
|
|
|
#if 0
|
2011-06-16 14:32:08 -05:00
|
|
|
if (mod_sofia_globals.debug_sla > 1) {
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "SLA EVENT:\n");
|
|
|
|
DUMP_EVENT(event);
|
|
|
|
}
|
2010-01-07 06:09:35 +00:00
|
|
|
#endif
|
2010-01-13 01:40:11 +00:00
|
|
|
|
2011-06-16 14:32:08 -05:00
|
|
|
if (uuid) {
|
2012-01-30 11:43:43 -06:00
|
|
|
sql = switch_mprintf("update sip_dialogs set call_info='%q',call_info_state='%q' where "
|
|
|
|
"hostname='%q' and profile_name='%q' and uuid='%q'",
|
|
|
|
call_info, call_info_state, mod_sofia_globals.hostname, profile->name, uuid);
|
2011-06-16 14:32:08 -05:00
|
|
|
} else {
|
2012-01-30 11:43:43 -06:00
|
|
|
sql = switch_mprintf("update sip_dialogs set call_info='%q', call_info_state='%q' where hostname='%q' and profile_name='%q' and "
|
2011-06-16 14:32:08 -05:00
|
|
|
"((sip_dialogs.sip_from_user='%q' and sip_dialogs.sip_from_host='%q') or presence_id='%q@%q') and call_info='%q'",
|
|
|
|
|
2012-01-30 11:43:43 -06:00
|
|
|
call_info, call_info_state, mod_sofia_globals.hostname, profile->name, euser, host, euser, host, call_info);
|
2011-06-16 14:32:08 -05:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mod_sofia_globals.debug_sla > 1) {
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "STATE SQL %s\n", sql);
|
|
|
|
}
|
|
|
|
sofia_glue_execute_sql_now(profile, &sql, SWITCH_TRUE);
|
|
|
|
|
2010-02-06 03:38:24 +00:00
|
|
|
|
2008-12-10 20:54:24 +00:00
|
|
|
|
2011-06-16 14:32:08 -05:00
|
|
|
if (mod_sofia_globals.debug_sla > 1) {
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "PROCESS PRESENCE EVENT\n");
|
|
|
|
}
|
|
|
|
|
2012-01-26 04:46:48 -06:00
|
|
|
sync_sla(profile, euser, host, SWITCH_TRUE, SWITCH_TRUE, call_id);
|
2009-04-27 17:31:34 +00:00
|
|
|
}
|
2011-06-16 14:32:08 -05:00
|
|
|
|
|
|
|
if (!strcmp(proto, "dp")) {
|
2012-02-09 16:47:32 -06:00
|
|
|
sql = switch_mprintf("update sip_presence set rpid='%q',status='%q' where hostname='%q' and profile_name='%q' and "
|
2012-01-30 11:43:43 -06:00
|
|
|
"sip_user='%q' and sip_host='%q'",
|
|
|
|
rpid, status, mod_sofia_globals.hostname, profile->name, euser, host);
|
2011-06-16 14:32:08 -05:00
|
|
|
sofia_glue_execute_sql_now(profile, &sql, SWITCH_TRUE);
|
|
|
|
}
|
2012-02-02 20:41:15 -06:00
|
|
|
|
|
|
|
if (zstr(uuid)) {
|
2011-06-16 14:32:08 -05:00
|
|
|
|
2012-02-02 20:41:15 -06:00
|
|
|
sql = switch_mprintf("select state,status,rpid,presence_id from sip_dialogs "
|
|
|
|
"where call_info_state != 'seized' and hostname='%q' and profile_name='%q' and "
|
|
|
|
"((sip_from_user='%q' and sip_from_host='%q') or presence_id='%q@%q') order by rcd desc",
|
|
|
|
mod_sofia_globals.hostname, profile->name, euser, host, euser, host);
|
|
|
|
} else {
|
|
|
|
sql = switch_mprintf("select state,status,rpid,presence_id from sip_dialogs "
|
|
|
|
"where uuid != '%q' and call_info_state != 'seized' and hostname='%q' and profile_name='%q' and "
|
|
|
|
"((sip_from_user='%q' and sip_from_host='%q') or presence_id='%q@%q') order by rcd desc",
|
|
|
|
uuid, mod_sofia_globals.hostname, profile->name, euser, host, euser, host);
|
|
|
|
}
|
2012-02-02 19:58:39 -06:00
|
|
|
|
|
|
|
if (mod_sofia_globals.debug_presence > 0) {
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "CHECK SQL: %s@%s [%s]\nhits: %d\n", euser, host, sql, dh.hits);
|
|
|
|
}
|
|
|
|
|
2012-02-02 20:41:15 -06:00
|
|
|
sofia_glue_execute_sql_callback(profile, profile->ireg_mutex, sql, sofia_presence_dialog_callback, &dh);
|
2012-02-14 18:59:37 -06:00
|
|
|
|
2012-02-02 19:58:39 -06:00
|
|
|
|
2011-06-16 14:32:08 -05:00
|
|
|
switch_safe_free(sql);
|
2012-02-20 11:11:15 -06:00
|
|
|
#if 0
|
2012-02-01 19:32:22 -06:00
|
|
|
if (hup && dh.hits > 0) {
|
2012-02-02 12:05:15 -06:00
|
|
|
/* sigh, mangle this packet to simulate a call that is up instead of hungup */
|
|
|
|
event->flags |= EF_UNIQ_HEADERS;
|
|
|
|
|
|
|
|
if (!strcasecmp(dh.state, "early")) {
|
|
|
|
status = "CS_ROUTING";
|
|
|
|
if (rpid) {
|
|
|
|
rpid = sofia_presence_translate_rpid(rpid, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Answer-State", "early");
|
|
|
|
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "status", status);
|
|
|
|
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Channel-State", status);
|
|
|
|
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Channel-Call-State", "EARLY");
|
|
|
|
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "astate", "early");
|
|
|
|
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "answer-state", "early");
|
|
|
|
} else {
|
|
|
|
status = "CS_EXECUTE";
|
|
|
|
if (rpid) {
|
|
|
|
rpid = sofia_presence_translate_rpid(rpid, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Answer-State", "answered");
|
|
|
|
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "status", status);
|
|
|
|
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Channel-State", status);
|
|
|
|
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Channel-Call-State", "ACTIVE");
|
|
|
|
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "astate", "confirmed");
|
|
|
|
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "answer-state", "confirmed");
|
|
|
|
}
|
2012-02-01 19:32:22 -06:00
|
|
|
}
|
2012-02-20 11:11:15 -06:00
|
|
|
#endif
|
2011-10-24 18:54:22 -05:00
|
|
|
|
2012-01-26 04:46:48 -06:00
|
|
|
if (zstr(call_id) && (dh.hits && presence_source && (!strcasecmp(presence_source, "register") || switch_stristr("register", status)))) {
|
2011-10-24 18:54:22 -05:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2012-01-26 04:46:48 -06:00
|
|
|
if (zstr(call_id)) {
|
2012-01-26 15:53:05 -06:00
|
|
|
|
2012-01-30 11:43:43 -06:00
|
|
|
sql = switch_mprintf("update sip_subscriptions set version=version+1 where hostname='%q' and profile_name='%q' and "
|
2012-01-26 15:53:05 -06:00
|
|
|
"sip_subscriptions.event != 'line-seize' "
|
|
|
|
"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%%')",
|
2012-01-30 11:43:43 -06:00
|
|
|
mod_sofia_globals.hostname, profile->name,
|
2012-01-26 15:53:05 -06:00
|
|
|
proto, event_type, alt_event_type, euser, host, profile->sipip,
|
|
|
|
profile->extsipip ? profile->extsipip : "N/A", host, profile->name, host);
|
|
|
|
|
|
|
|
|
|
|
|
if (mod_sofia_globals.debug_presence > 1) {
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "PRES SQL %s\n", sql);
|
|
|
|
}
|
|
|
|
|
|
|
|
sofia_glue_execute_sql_now(profile, &sql, SWITCH_TRUE);
|
|
|
|
|
|
|
|
|
2011-06-16 14:32:08 -05:00
|
|
|
|
2012-01-26 04:46:48 -06:00
|
|
|
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 "
|
2012-01-30 11:43:43 -06:00
|
|
|
"sip_subscriptions.profile_name=sip_presence.profile_name and sip_subscriptions.hostname=sip_presence.hostname) "
|
2011-06-16 14:32:08 -05:00
|
|
|
|
2012-01-30 11:43:43 -06:00
|
|
|
"where sip_subscriptions.hostname='%q' and sip_subscriptions.profile_name='%q' and "
|
|
|
|
"sip_subscriptions.event != 'line-seize' and "
|
2012-01-26 04:46:48 -06:00
|
|
|
"sip_subscriptions.proto='%q' and "
|
|
|
|
"(event='%q' or event='%q') and sub_to_user='%q' "
|
2012-01-30 11:43:43 -06:00
|
|
|
"and (sub_to_host='%q' or sub_to_host='%q' or sub_to_host='%q' or presence_hosts like '%%%q%%') ",
|
|
|
|
|
2011-06-16 14:32:08 -05:00
|
|
|
|
2012-01-26 04:46:48 -06:00
|
|
|
switch_str_nil(status), switch_str_nil(rpid), host,
|
2012-01-30 11:43:43 -06:00
|
|
|
dh.status,dh.rpid,dh.presence_id, mod_sofia_globals.hostname, profile->name, proto,
|
2012-01-26 04:46:48 -06:00
|
|
|
event_type, alt_event_type, euser, host, profile->sipip,
|
2012-01-30 11:43:43 -06:00
|
|
|
profile->extsipip ? profile->extsipip : "N/A", host);
|
2012-01-26 04:46:48 -06:00
|
|
|
} else {
|
2012-01-26 15:53:05 -06:00
|
|
|
sql = switch_mprintf("update sip_subscriptions set version=version+1 where sip_subscriptions.event != 'line-seize' and "
|
2012-01-30 11:43:43 -06:00
|
|
|
"hostname='%q' and profile_name = '%q' and sip_subscriptions.call_id='%q'",
|
|
|
|
mod_sofia_globals.hostname, profile->name, call_id);
|
2012-01-26 15:53:05 -06:00
|
|
|
|
|
|
|
|
|
|
|
if (mod_sofia_globals.debug_presence > 1) {
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "PRES SQL %s\n", sql);
|
|
|
|
}
|
|
|
|
|
|
|
|
sofia_glue_execute_sql_now(profile, &sql, SWITCH_TRUE);
|
|
|
|
|
|
|
|
|
2012-01-26 04:46:48 -06:00
|
|
|
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 "
|
2012-01-30 11:43:43 -06:00
|
|
|
"sip_subscriptions.profile_name=sip_presence.profile_name and sip_subscriptions.hostname=sip_presence.hostname) "
|
2012-01-26 04:46:48 -06:00
|
|
|
|
2012-01-30 11:43:43 -06:00
|
|
|
"where sip_subscriptions.hostname='%q' and sip_subscriptions.profile_name='%q' and "
|
|
|
|
"sip_subscriptions.event != 'line-seize' and "
|
|
|
|
"sip_subscriptions.call_id='%q'",
|
2012-01-26 04:46:48 -06:00
|
|
|
|
|
|
|
switch_str_nil(status), switch_str_nil(rpid), host,
|
2012-01-30 11:43:43 -06:00
|
|
|
dh.status,dh.rpid,dh.presence_id, mod_sofia_globals.hostname, profile->name, call_id);
|
2011-06-16 14:32:08 -05:00
|
|
|
|
2012-01-26 04:46:48 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
helper.profile = profile;
|
|
|
|
helper.event = event;
|
|
|
|
SWITCH_STANDARD_STREAM(helper.stream);
|
|
|
|
switch_assert(helper.stream.data);
|
2011-06-16 14:32:08 -05:00
|
|
|
|
2012-01-26 04:46:48 -06:00
|
|
|
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);
|
|
|
|
}
|
2008-05-27 04:54:52 +00:00
|
|
|
|
2012-01-26 04:46:48 -06:00
|
|
|
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);
|
|
|
|
}
|
2008-05-27 04:54:52 +00:00
|
|
|
|
2012-01-26 04:46:48 -06:00
|
|
|
sofia_glue_execute_sql_callback(profile, profile->ireg_mutex, sql, sofia_presence_sub_callback, &helper);
|
|
|
|
switch_safe_free(sql);
|
2012-01-26 15:53:05 -06:00
|
|
|
|
2012-01-26 04:46:48 -06:00
|
|
|
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);
|
|
|
|
}
|
2011-06-16 14:32:08 -05:00
|
|
|
|
2012-02-17 20:21:44 -06:00
|
|
|
|
|
|
|
if (hup) {
|
|
|
|
/* so many phones get confused when whe hangup we have to reprobe to get them all to reset to absolute states so the lights stay correct */
|
2012-02-02 12:05:15 -06:00
|
|
|
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);
|
2012-01-26 04:46:48 -06:00
|
|
|
}
|
|
|
|
}
|
2012-02-02 12:05:15 -06:00
|
|
|
|
2012-01-26 04:46:48 -06:00
|
|
|
if (!zstr((char *) helper.stream.data)) {
|
|
|
|
char *this_sql = (char *) helper.stream.data;
|
|
|
|
char *next = NULL;
|
|
|
|
char *last = NULL;
|
2011-06-16 14:32:08 -05:00
|
|
|
|
2012-01-26 04:46:48 -06:00
|
|
|
do {
|
|
|
|
if ((next = strchr(this_sql, ';'))) {
|
|
|
|
*next++ = '\0';
|
|
|
|
while (*next == '\n' || *next == ' ' || *next == '\r') {
|
|
|
|
*next++ = '\0';
|
|
|
|
}
|
|
|
|
}
|
2011-06-16 14:32:08 -05:00
|
|
|
|
2012-01-26 04:46:48 -06:00
|
|
|
if (!zstr(this_sql) && (!last || strcmp(last, this_sql))) {
|
|
|
|
sofia_glue_execute_sql(profile, &this_sql, SWITCH_FALSE);
|
|
|
|
last = this_sql;
|
2008-04-11 17:07:06 +00:00
|
|
|
}
|
2012-01-26 04:46:48 -06:00
|
|
|
this_sql = next;
|
|
|
|
} while (this_sql);
|
2007-12-18 01:12:50 +00:00
|
|
|
}
|
2012-01-26 04:46:48 -06:00
|
|
|
switch_safe_free(helper.stream.data);
|
|
|
|
helper.stream.data = NULL;
|
|
|
|
|
|
|
|
sofia_glue_release_profile(profile);
|
2007-03-31 19:01:33 +00:00
|
|
|
}
|
|
|
|
}
|
2012-01-26 04:46:48 -06:00
|
|
|
switch_console_free_matches(&matches);
|
|
|
|
}
|
2007-03-31 19:01:33 +00:00
|
|
|
|
2012-01-26 04:46:48 -06:00
|
|
|
done:
|
|
|
|
switch_safe_free(sql);
|
|
|
|
switch_safe_free(user);
|
2007-03-31 19:01:33 +00:00
|
|
|
}
|
|
|
|
|
2008-03-14 13:05:28 +00:00
|
|
|
static int EVENT_THREAD_RUNNING = 0;
|
|
|
|
static int EVENT_THREAD_STARTED = 0;
|
2008-03-14 03:46:54 +00:00
|
|
|
|
|
|
|
void *SWITCH_THREAD_FUNC sofia_presence_event_thread_run(switch_thread_t *thread, void *obj)
|
|
|
|
{
|
|
|
|
void *pop;
|
2008-03-14 13:05:28 +00:00
|
|
|
int done = 0;
|
2008-03-14 03:46:54 +00:00
|
|
|
|
|
|
|
switch_mutex_lock(mod_sofia_globals.mutex);
|
2008-03-14 13:05:28 +00:00
|
|
|
if (!EVENT_THREAD_RUNNING) {
|
|
|
|
EVENT_THREAD_RUNNING++;
|
|
|
|
mod_sofia_globals.threads++;
|
|
|
|
} else {
|
|
|
|
done = 1;
|
|
|
|
}
|
2008-03-14 03:46:54 +00:00
|
|
|
switch_mutex_unlock(mod_sofia_globals.mutex);
|
|
|
|
|
2008-03-14 13:05:28 +00:00
|
|
|
if (done) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Event Thread Started\n");
|
2008-05-27 04:54:52 +00:00
|
|
|
|
2008-03-14 03:46:54 +00:00
|
|
|
while (mod_sofia_globals.running == 1) {
|
|
|
|
int count = 0;
|
2010-02-06 03:38:24 +00:00
|
|
|
|
2008-03-14 03:46:54 +00:00
|
|
|
if (switch_queue_trypop(mod_sofia_globals.presence_queue, &pop) == SWITCH_STATUS_SUCCESS) {
|
|
|
|
switch_event_t *event = (switch_event_t *) pop;
|
|
|
|
|
|
|
|
if (!pop) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
actual_sofia_presence_event_handler(event);
|
|
|
|
switch_event_destroy(&event);
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (switch_queue_trypop(mod_sofia_globals.mwi_queue, &pop) == SWITCH_STATUS_SUCCESS) {
|
|
|
|
switch_event_t *event = (switch_event_t *) pop;
|
|
|
|
|
|
|
|
if (!pop) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
actual_sofia_presence_mwi_event_handler(event);
|
|
|
|
switch_event_destroy(&event);
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!count) {
|
|
|
|
switch_yield(100000);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
while (switch_queue_trypop(mod_sofia_globals.presence_queue, &pop) == SWITCH_STATUS_SUCCESS && pop) {
|
|
|
|
switch_event_t *event = (switch_event_t *) pop;
|
|
|
|
switch_event_destroy(&event);
|
|
|
|
}
|
2008-05-27 04:54:52 +00:00
|
|
|
|
2008-03-14 03:46:54 +00:00
|
|
|
while (switch_queue_trypop(mod_sofia_globals.mwi_queue, &pop) == SWITCH_STATUS_SUCCESS && pop) {
|
|
|
|
switch_event_t *event = (switch_event_t *) pop;
|
|
|
|
switch_event_destroy(&event);
|
|
|
|
}
|
|
|
|
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Event Thread Ended\n");
|
|
|
|
|
|
|
|
switch_mutex_lock(mod_sofia_globals.mutex);
|
|
|
|
mod_sofia_globals.threads--;
|
2008-03-14 13:05:28 +00:00
|
|
|
EVENT_THREAD_RUNNING = EVENT_THREAD_STARTED = 0;
|
2008-03-14 03:46:54 +00:00
|
|
|
switch_mutex_unlock(mod_sofia_globals.mutex);
|
2008-05-27 04:54:52 +00:00
|
|
|
|
2008-03-14 03:46:54 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void sofia_presence_event_thread_start(void)
|
|
|
|
{
|
|
|
|
switch_thread_t *thread;
|
|
|
|
switch_threadattr_t *thd_attr = NULL;
|
2008-03-14 13:05:28 +00:00
|
|
|
int done = 0;
|
|
|
|
|
|
|
|
switch_mutex_lock(mod_sofia_globals.mutex);
|
|
|
|
if (!EVENT_THREAD_STARTED) {
|
|
|
|
EVENT_THREAD_STARTED++;
|
|
|
|
} else {
|
|
|
|
done = 1;
|
|
|
|
}
|
|
|
|
switch_mutex_unlock(mod_sofia_globals.mutex);
|
|
|
|
|
|
|
|
if (done) {
|
|
|
|
return;
|
|
|
|
}
|
2008-03-14 03:46:54 +00:00
|
|
|
|
|
|
|
switch_threadattr_create(&thd_attr, mod_sofia_globals.pool);
|
|
|
|
switch_threadattr_detach_set(thd_attr, 1);
|
|
|
|
switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
|
|
|
|
switch_threadattr_priority_increase(thd_attr);
|
|
|
|
switch_thread_create(&thread, thd_attr, sofia_presence_event_thread_run, NULL, mod_sofia_globals.pool);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void sofia_presence_event_handler(switch_event_t *event)
|
|
|
|
{
|
|
|
|
switch_event_t *cloned_event;
|
|
|
|
|
|
|
|
switch_event_dup(&cloned_event, event);
|
|
|
|
switch_assert(cloned_event);
|
|
|
|
switch_queue_push(mod_sofia_globals.presence_queue, cloned_event);
|
2008-03-14 13:05:28 +00:00
|
|
|
|
|
|
|
if (!EVENT_THREAD_STARTED) {
|
|
|
|
sofia_presence_event_thread_start();
|
|
|
|
}
|
2008-03-14 03:46:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void sofia_presence_mwi_event_handler(switch_event_t *event)
|
|
|
|
{
|
|
|
|
switch_event_t *cloned_event;
|
|
|
|
|
|
|
|
switch_event_dup(&cloned_event, event);
|
|
|
|
switch_assert(cloned_event);
|
|
|
|
switch_queue_push(mod_sofia_globals.mwi_queue, cloned_event);
|
2008-03-14 13:05:28 +00:00
|
|
|
|
|
|
|
if (!EVENT_THREAD_STARTED) {
|
|
|
|
sofia_presence_event_thread_start();
|
|
|
|
}
|
2008-03-14 03:46:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-02 19:54:25 +00:00
|
|
|
static int sofia_presence_sub_reg_callback(void *pArg, int argc, char **argv, char **columnNames)
|
2007-03-31 19:01:33 +00:00
|
|
|
{
|
|
|
|
sofia_profile_t *profile = (sofia_profile_t *) pArg;
|
|
|
|
char *user = argv[1];
|
|
|
|
char *host = argv[2];
|
|
|
|
switch_event_t *event;
|
2007-04-02 19:54:25 +00:00
|
|
|
char *event_name = argv[5];
|
2010-03-11 15:52:29 +00:00
|
|
|
char *expires = argv[10];
|
2007-04-02 19:54:25 +00:00
|
|
|
|
|
|
|
if (!strcasecmp(event_name, "message-summary")) {
|
2007-04-02 20:20:46 +00:00
|
|
|
if (switch_event_create(&event, SWITCH_EVENT_MESSAGE_QUERY) == SWITCH_STATUS_SUCCESS) {
|
|
|
|
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Message-Account", "sip:%s@%s", user, host);
|
2008-08-16 02:19:43 +00:00
|
|
|
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "VM-Sofia-Profile", profile->name);
|
2009-03-27 00:27:07 +00:00
|
|
|
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "VM-sub-call-id", argv[7]);
|
2007-04-02 19:54:25 +00:00
|
|
|
switch_event_fire(&event);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-12-15 00:39:53 +00:00
|
|
|
if (switch_event_create(&event, SWITCH_EVENT_PRESENCE_PROBE) == SWITCH_STATUS_SUCCESS) {
|
2008-08-16 02:19:43 +00:00
|
|
|
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "proto", SOFIA_CHAT_PROTO);
|
|
|
|
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "login", profile->url);
|
2007-03-31 19:01:33 +00:00
|
|
|
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "from", "%s@%s", user, host);
|
2008-08-16 02:19:43 +00:00
|
|
|
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "event_type", "presence");
|
|
|
|
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "event_subtype", "probe");
|
|
|
|
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "proto-specific-event-name", event_name);
|
2010-03-11 15:52:29 +00:00
|
|
|
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "expires", expires);
|
2007-03-31 19:01:33 +00:00
|
|
|
switch_event_fire(&event);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-04-02 19:54:25 +00:00
|
|
|
static int sofia_presence_resub_callback(void *pArg, int argc, char **argv, char **columnNames)
|
2007-03-31 19:01:33 +00:00
|
|
|
{
|
2009-12-24 05:44:23 +00:00
|
|
|
struct resub_helper *h = (struct resub_helper *) pArg;
|
|
|
|
sofia_profile_t *profile = h->profile;
|
2007-03-31 19:01:33 +00:00
|
|
|
char *user = argv[0];
|
|
|
|
char *host = argv[1];
|
|
|
|
char *status = argv[2];
|
|
|
|
char *rpid = argv[3];
|
|
|
|
char *proto = argv[4];
|
2012-01-26 04:46:48 -06:00
|
|
|
char *call_id = NULL;
|
2010-10-18 15:30:11 -05:00
|
|
|
char *presence_id = NULL;
|
2008-06-02 16:40:44 +00:00
|
|
|
char *to_user = NULL;
|
2007-12-18 01:12:50 +00:00
|
|
|
char *uuid = NULL;
|
|
|
|
char *state = NULL;
|
|
|
|
char *direction = NULL;
|
2007-03-31 19:01:33 +00:00
|
|
|
switch_event_t *event;
|
2008-06-02 16:40:44 +00:00
|
|
|
char to_buf[128] = "";
|
2009-12-24 05:44:23 +00:00
|
|
|
switch_event_header_t *hp;
|
2010-10-18 15:30:11 -05:00
|
|
|
char *free_me = NULL;
|
2012-01-26 04:46:48 -06:00
|
|
|
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]);
|
|
|
|
}
|
|
|
|
}
|
2007-03-31 19:01:33 +00:00
|
|
|
|
2007-12-18 01:12:50 +00:00
|
|
|
if (argc > 5) {
|
2010-09-02 16:01:50 -05:00
|
|
|
uuid = argv[5];
|
2007-12-18 01:12:50 +00:00
|
|
|
state = switch_str_nil(argv[6]);
|
|
|
|
direction = switch_str_nil(argv[7]);
|
2008-06-02 16:40:44 +00:00
|
|
|
if (argc > 8) {
|
|
|
|
switch_set_string(to_buf, argv[8]);
|
|
|
|
switch_url_decode(to_buf);
|
|
|
|
to_user = to_buf;
|
|
|
|
}
|
2010-08-27 13:08:33 -05:00
|
|
|
if (argc > 10 && !zstr(argv[10]) && !zstr(argv[11])) {
|
|
|
|
status = argv[10];
|
|
|
|
rpid = argv[11];
|
2008-11-22 01:34:19 +00:00
|
|
|
}
|
2010-10-18 15:30:11 -05:00
|
|
|
|
|
|
|
if (argc > 12 && !zstr(argv[12]) && strchr(argv[12], '@')) {
|
|
|
|
char *p;
|
|
|
|
|
|
|
|
presence_id = argv[12];
|
|
|
|
free_me = strdup(presence_id);
|
|
|
|
if ((p = strchr(free_me, '@'))) *p = '\0';
|
|
|
|
user = free_me;
|
|
|
|
}
|
2012-01-26 04:46:48 -06:00
|
|
|
|
|
|
|
if (argc > 16) {
|
|
|
|
call_id = argv[16];
|
|
|
|
}
|
|
|
|
|
2007-12-18 01:12:50 +00:00
|
|
|
}
|
|
|
|
|
2012-01-11 21:32:23 -06:00
|
|
|
if (!zstr(uuid) && !switch_ivr_uuid_exists(uuid)) {
|
|
|
|
if (mod_sofia_globals.debug_presence > 0) {
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "%s SKIPPING NOT FOUND UUID %s\n", profile->name, uuid);
|
|
|
|
}
|
|
|
|
do_event = 0;
|
|
|
|
}
|
|
|
|
|
2009-10-23 16:03:42 +00:00
|
|
|
if (zstr(proto)) {
|
2007-03-31 19:01:33 +00:00
|
|
|
proto = NULL;
|
|
|
|
}
|
|
|
|
|
2008-12-10 20:54:24 +00:00
|
|
|
if (mod_sofia_globals.debug_presence > 0) {
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "%s PRESENCE_PROBE %s@%s\n", profile->name, user, host);
|
|
|
|
}
|
|
|
|
|
2012-01-11 21:32:23 -06:00
|
|
|
if (do_event && switch_event_create(&event, SWITCH_EVENT_PRESENCE_IN) == SWITCH_STATUS_SUCCESS) {
|
2008-08-16 02:19:43 +00:00
|
|
|
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "proto", proto ? proto : SOFIA_CHAT_PROTO);
|
|
|
|
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "login", profile->url);
|
2010-10-18 15:30:11 -05:00
|
|
|
|
2007-03-31 19:01:33 +00:00
|
|
|
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "from", "%s@%s", user, host);
|
2010-10-18 15:30:11 -05:00
|
|
|
|
2010-10-22 15:13:44 -05:00
|
|
|
if (h->noreg) {
|
|
|
|
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Force-Direction", "inbound");
|
|
|
|
}
|
2010-10-18 15:30:11 -05:00
|
|
|
|
2012-01-26 04:46:48 -06:00
|
|
|
if (!zstr(call_id)) {
|
|
|
|
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "call-id", call_id);
|
|
|
|
}
|
|
|
|
|
2012-02-14 18:59:37 -06:00
|
|
|
//switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "resub", "true");
|
2008-08-16 02:19:43 +00:00
|
|
|
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "status", status);
|
|
|
|
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "rpid", rpid);
|
|
|
|
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "event_type", "presence");
|
|
|
|
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "alt_event_type", "dialog");
|
2007-12-18 01:12:50 +00:00
|
|
|
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "event_count", "%d", 0);
|
|
|
|
|
2009-10-23 16:03:42 +00:00
|
|
|
if (!zstr(to_user)) {
|
2008-08-16 02:19:43 +00:00
|
|
|
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "to-user", to_user);
|
2008-06-02 16:40:44 +00:00
|
|
|
}
|
2010-02-06 03:38:24 +00:00
|
|
|
|
2009-10-23 16:03:42 +00:00
|
|
|
if (zstr(state)) {
|
2008-08-16 02:19:43 +00:00
|
|
|
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "channel-state", "CS_HANGUP");
|
2010-09-02 16:01:50 -05:00
|
|
|
//switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "answer-state", "resubscribe");
|
2007-12-18 01:12:50 +00:00
|
|
|
} else {
|
2008-08-16 02:19:43 +00:00
|
|
|
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "channel-state", "CS_ROUTING");
|
2010-09-02 16:01:50 -05:00
|
|
|
if (uuid) {
|
|
|
|
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "unique-id", uuid);
|
|
|
|
}
|
2008-08-16 02:19:43 +00:00
|
|
|
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "answer-state", state);
|
|
|
|
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "astate", state);
|
2009-02-23 16:31:59 +00:00
|
|
|
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "presence-call-direction", direction);
|
2007-12-18 01:12:50 +00:00
|
|
|
}
|
2008-05-27 04:54:52 +00:00
|
|
|
|
2009-12-24 05:44:23 +00:00
|
|
|
if (h->event) {
|
|
|
|
for (hp = h->event->headers; hp; hp = hp->next) {
|
|
|
|
if (!strncasecmp(hp->name, "fwd-", 4)) {
|
|
|
|
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, hp->name + 4, hp->value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-31 19:01:33 +00:00
|
|
|
switch_event_fire(&event);
|
|
|
|
}
|
|
|
|
|
2010-10-18 15:30:11 -05:00
|
|
|
switch_safe_free(free_me);
|
|
|
|
|
2012-01-11 21:32:23 -06:00
|
|
|
|
2010-07-27 22:08:47 -05:00
|
|
|
h->rowcount++;
|
2012-01-11 21:32:23 -06:00
|
|
|
|
|
|
|
|
2007-03-31 19:01:33 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-10-21 20:00:34 -05:00
|
|
|
char *get_display_name_from_contact(const char *in, char* dst)
|
|
|
|
{
|
|
|
|
// name-addr = [ display-name ] LAQUOT addr-spec RAQUOT
|
|
|
|
// display-name = *(token LWS)/ quoted-string
|
|
|
|
// return whatever comes before the left angle bracket, stripped of whitespace and quotes
|
|
|
|
char *p;
|
|
|
|
char *buf;
|
|
|
|
|
|
|
|
strcpy(dst, "");
|
|
|
|
if (strchr(in, '<') && strchr(in, '>')) {
|
|
|
|
buf = strdup(in);
|
|
|
|
p = strchr(buf, '<');
|
|
|
|
*p = '\0';
|
|
|
|
if (!zstr(buf)) {
|
|
|
|
p = switch_strip_whitespace(buf);
|
|
|
|
if (p) {
|
|
|
|
if (*p == '"') {
|
|
|
|
if (end_of(p+1) == '"') {
|
|
|
|
char *q = strdup(p + 1);
|
|
|
|
end_of(q) = '\0';
|
|
|
|
strcpy(dst, q);
|
|
|
|
switch_safe_free(q);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
strcpy(dst, p);
|
|
|
|
}
|
|
|
|
switch_safe_free(p);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
switch_safe_free(buf);
|
|
|
|
}
|
|
|
|
return dst;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int sofia_dialog_probe_callback(void *pArg, int argc, char **argv, char **columnNames)
|
|
|
|
{
|
|
|
|
struct rfc4235_helper *h = (struct rfc4235_helper *) pArg;
|
|
|
|
|
|
|
|
char *proto = argv[0];
|
|
|
|
char *user = argv[1];
|
|
|
|
char *host = argv[2];
|
|
|
|
char *uuid = argv[3];
|
|
|
|
char *call_id = argv[4];
|
|
|
|
char *state = argv[5];
|
|
|
|
char *direction = argv[6];
|
|
|
|
char *to_user = argv[7];
|
|
|
|
char *to_host = argv[8];
|
|
|
|
char *from_user = argv[9];
|
|
|
|
// char *from_host = argv[10];
|
|
|
|
char *contact = switch_str_nil(argv[11]);
|
|
|
|
char *contact_user = switch_str_nil(argv[12]);
|
|
|
|
char *contact_host = switch_str_nil(argv[13]);
|
|
|
|
char *to_tag = switch_str_nil(argv[14]);
|
|
|
|
char *from_tag = switch_str_nil(argv[15]);
|
2011-10-24 09:49:34 -05:00
|
|
|
char *orig_proto = switch_str_nil(argv[16]);
|
2011-10-21 20:00:34 -05:00
|
|
|
|
|
|
|
const char *event_status = "";
|
|
|
|
char *data = NULL, *tmp;
|
|
|
|
char key[256] = "";
|
|
|
|
char *local_user;
|
|
|
|
char *local_host;
|
|
|
|
char *remote_user;
|
|
|
|
char *remote_host;
|
|
|
|
char *remote_uri;
|
|
|
|
char *local_user_param = "";
|
|
|
|
char remote_display_buf[512];
|
|
|
|
char *buf_to_free = NULL;
|
|
|
|
int bInternal = 0;
|
2011-10-24 09:42:54 -05:00
|
|
|
int i;
|
2011-10-24 09:49:34 -05:00
|
|
|
int skip_proto = 0;
|
2011-10-21 20:00:34 -05:00
|
|
|
|
|
|
|
if (mod_sofia_globals.debug_presence > 1) {
|
2011-10-24 09:42:54 -05:00
|
|
|
for (i = 0; i < argc; i++) {
|
2012-01-26 04:46:48 -06:00
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG,SWITCH_LOG_WARNING, "sofia_dialog_probe_callback: %d [%s]=[%s]\n", i, columnNames[i], argv[i]);
|
2011-10-21 20:00:34 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (zstr(to_user) || zstr(contact_user)) {
|
2012-01-26 04:46:48 -06:00
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "sofia_dialog_probe_callback: not enough info to generate a dialog entry\n");
|
2011-10-21 20:00:34 -05:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Usually we report the dialogs FROM the probed user. The exception is when the monitored endpoint is internal,
|
|
|
|
// and its presence_id is set in the dialplan. Reverse the direction if this is not a registered entity.
|
|
|
|
if (!strcmp(direction, "inbound") && strcmp(user, from_user) ) {
|
|
|
|
// If inbound and the entity is not the caller (i.e. internal to FS), then the direction is reversed
|
|
|
|
// because it is not going through the B2BUA
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "sofia_dialog_probe_callback: endpt is internal\n");
|
|
|
|
direction = !strcasecmp(direction, "outbound") ? "inbound" : "outbound";
|
|
|
|
bInternal = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!strcasecmp(direction, "outbound")) {
|
|
|
|
direction = "recipient";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
direction = "initiator";
|
|
|
|
}
|
|
|
|
|
2011-10-24 09:49:34 -05:00
|
|
|
if (!zstr(orig_proto) && !strcmp(orig_proto, SOFIA_CHAT_PROTO)) {
|
|
|
|
skip_proto = 1;
|
|
|
|
}
|
|
|
|
|
2011-10-21 20:00:34 -05:00
|
|
|
local_host = to_host;
|
2011-10-24 09:49:34 -05:00
|
|
|
if (proto && !strcasecmp(proto, "queue")) {
|
2012-01-04 12:10:53 -06:00
|
|
|
local_user = to_user;
|
|
|
|
local_user_param = switch_mprintf(";proto=%s", proto);
|
2011-10-21 20:00:34 -05:00
|
|
|
event_status = "hold";
|
2011-10-24 09:49:34 -05:00
|
|
|
if (skip_proto) {
|
|
|
|
buf_to_free = switch_mprintf("sip:%s", to_user);
|
|
|
|
} else {
|
|
|
|
buf_to_free = switch_mprintf("sip:queue+%s", to_user);
|
|
|
|
}
|
2011-10-21 20:00:34 -05:00
|
|
|
remote_uri = buf_to_free;
|
2011-10-24 09:49:34 -05:00
|
|
|
strcpy(remote_display_buf, "queue");
|
|
|
|
remote_user = to_user;
|
|
|
|
remote_host = local_host;
|
|
|
|
}
|
|
|
|
else if (proto && !strcasecmp(proto, "park")) {
|
2012-01-04 12:10:53 -06:00
|
|
|
local_user = to_user;
|
|
|
|
local_user_param = switch_mprintf(";proto=%s", proto);
|
2011-10-24 09:49:34 -05:00
|
|
|
event_status = "hold";
|
|
|
|
if (skip_proto) {
|
|
|
|
buf_to_free = switch_mprintf("sip:%s", to_user);
|
|
|
|
} else {
|
|
|
|
buf_to_free = switch_mprintf("sip:park+%s", to_user);
|
|
|
|
}
|
|
|
|
remote_uri = buf_to_free;
|
|
|
|
strcpy(remote_display_buf, "park");
|
2011-10-21 20:00:34 -05:00
|
|
|
remote_user = to_user;
|
|
|
|
remote_host = local_host;
|
|
|
|
}
|
|
|
|
else if (proto && !strcasecmp(proto, "conf")) {
|
2012-01-04 12:10:53 -06:00
|
|
|
local_user = to_user;
|
|
|
|
local_user_param = switch_mprintf(";proto=%s", proto);
|
2011-10-24 09:49:34 -05:00
|
|
|
if (skip_proto) {
|
|
|
|
buf_to_free = switch_mprintf("sip:%s@%s", to_user, host);
|
|
|
|
} else {
|
|
|
|
buf_to_free = switch_mprintf("sip:conf+%s@%s", to_user, host);
|
|
|
|
}
|
2011-10-21 20:00:34 -05:00
|
|
|
remote_uri = buf_to_free;
|
|
|
|
strcpy(remote_display_buf, "conference");
|
|
|
|
remote_user = to_user;
|
|
|
|
remote_host = local_host;
|
|
|
|
}
|
|
|
|
else if (bInternal) {
|
|
|
|
local_user = to_user;
|
|
|
|
get_display_name_from_contact(contact, remote_display_buf);
|
|
|
|
buf_to_free = sofia_glue_strip_uri(contact);
|
|
|
|
remote_uri = buf_to_free;
|
|
|
|
remote_user = contact_user;
|
|
|
|
remote_host = contact_host;
|
|
|
|
} else {
|
|
|
|
local_user = from_user;
|
|
|
|
buf_to_free = switch_mprintf("**%s@%s", from_user, local_host);
|
|
|
|
remote_uri = buf_to_free;
|
|
|
|
strcpy(remote_display_buf, to_user);
|
|
|
|
remote_user = to_user;
|
|
|
|
remote_host = local_host;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch_snprintf(key, sizeof(key), "%s%s", user, host);
|
|
|
|
data = switch_core_hash_find(h->hash, key);
|
|
|
|
if (!data) {
|
|
|
|
data = "";
|
|
|
|
}
|
|
|
|
tmp = switch_core_sprintf(h->pool, "%s"
|
2012-01-26 04:46:48 -06:00
|
|
|
"<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
|
|
|
|
);
|
2011-10-21 20:00:34 -05:00
|
|
|
switch_core_hash_insert(h->hash, key, tmp);
|
|
|
|
switch_safe_free(buf_to_free);
|
|
|
|
|
|
|
|
h->rowcount++;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-01-26 04:46:48 -06:00
|
|
|
#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
|
2011-12-15 16:30:33 -06:00
|
|
|
)
|
|
|
|
{
|
|
|
|
char sstr[128] = "";
|
|
|
|
nua_handle_t *nh;
|
|
|
|
int exptime = 0;
|
|
|
|
char expires_str[10] = "";
|
|
|
|
sip_cseq_t *cseq = NULL;
|
|
|
|
uint32_t callsequence;
|
|
|
|
uint32_t now = (uint32_t) switch_epoch_time_now(NULL);
|
2012-01-11 21:32:23 -06:00
|
|
|
char *our_contact = profile->url, *our_contact_dup = NULL;
|
2011-12-15 16:30:33 -06:00
|
|
|
|
2012-01-26 04:46:48 -06:00
|
|
|
sofia_destination_t *dst = NULL;
|
|
|
|
char *contact_str, *contact, *user_via = NULL;
|
2012-02-06 11:59:57 -06:00
|
|
|
char *route_uri = NULL, *o_contact_dup = NULL, *tmp, *to_uri, *dcs = NULL;
|
2012-01-26 04:46:48 -06:00
|
|
|
const char *tp;
|
|
|
|
|
|
|
|
tmp = (char *)o_contact;
|
|
|
|
o_contact_dup = sofia_glue_get_url_from_contact(tmp, 1);
|
2011-12-15 16:30:33 -06:00
|
|
|
|
2012-01-26 04:46:48 -06:00
|
|
|
|
|
|
|
if ((tp = switch_stristr("transport=", o_contact_dup))) {
|
|
|
|
tp += 10;
|
2011-12-15 16:30:33 -06:00
|
|
|
}
|
|
|
|
|
2012-01-26 04:46:48 -06:00
|
|
|
if (zstr(tp)) {
|
|
|
|
tp = "udp";
|
|
|
|
}
|
2011-12-15 16:30:33 -06:00
|
|
|
|
2012-01-26 04:46:48 -06:00
|
|
|
if (!switch_stristr("transport=", our_contact)) {
|
|
|
|
our_contact_dup = switch_mprintf("<%s;transport=%s>", our_contact, tp);
|
|
|
|
our_contact = our_contact_dup;
|
2011-12-15 16:30:33 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-01-26 04:46:48 -06:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2012-01-17 16:08:25 -06:00
|
|
|
} else {
|
2012-01-26 04:46:48 -06:00
|
|
|
contact_str = our_contact;
|
2011-12-15 16:30:33 -06:00
|
|
|
}
|
2012-02-06 11:59:57 -06:00
|
|
|
|
|
|
|
|
|
|
|
if ((to_uri = sofia_glue_get_url_from_contact((char *)full_to, 1))) {
|
|
|
|
char *p;
|
|
|
|
|
|
|
|
if ((p = strstr(to_uri, "sip:"))) {
|
|
|
|
char *q;
|
|
|
|
|
|
|
|
p += 4;
|
|
|
|
if ((q = strchr(p, '@'))) {
|
|
|
|
*q++ = '\0';
|
|
|
|
|
|
|
|
if ((dcs = switch_string_replace(contact_str, "mod_sofia", p))) {
|
|
|
|
contact_str = dcs;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
free(to_uri);
|
|
|
|
}
|
2011-12-15 16:30:33 -06:00
|
|
|
|
2012-01-26 04:46:48 -06:00
|
|
|
dst = sofia_glue_get_destination((char *) o_contact);
|
|
|
|
switch_assert(dst);
|
2011-12-15 16:30:33 -06:00
|
|
|
|
2012-01-28 13:09:12 -06:00
|
|
|
if (!zstr(dst->contact)) {
|
|
|
|
contact = sofia_glue_get_url_from_contact(dst->contact, 1);
|
|
|
|
} else {
|
|
|
|
contact = strdup(o_contact);
|
|
|
|
}
|
2012-01-26 04:46:48 -06:00
|
|
|
|
|
|
|
if (dst->route_uri) {
|
|
|
|
route_uri = sofia_glue_strip_uri(dst->route_uri);
|
|
|
|
} else {
|
|
|
|
if (remote_ip && remote_port) {
|
2012-02-23 17:59:01 -06:00
|
|
|
route_uri = switch_mprintf("sip:user@%s:%s;transport=%s", remote_ip, remote_port, tp);
|
2012-01-26 04:46:48 -06:00
|
|
|
}
|
2012-01-11 21:32:23 -06:00
|
|
|
}
|
|
|
|
|
2012-01-26 04:46:48 -06:00
|
|
|
if (expires) {
|
|
|
|
long ltmp = atol(expires);
|
|
|
|
|
|
|
|
if (ltmp > 0) {
|
|
|
|
exptime = (ltmp - now);
|
|
|
|
} else {
|
|
|
|
exptime = 0;
|
|
|
|
}
|
2012-01-11 21:32:23 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-01-26 04:46:48 -06:00
|
|
|
|
|
|
|
if (exptime <= 0) {
|
|
|
|
switch_snprintf(sstr, sizeof(sstr), "terminated;reason=noresource");
|
|
|
|
} else {
|
|
|
|
switch_snprintf(sstr, sizeof(sstr), "active;expires=%u", (unsigned) exptime);
|
2011-12-15 16:30:33 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mod_sofia_globals.debug_presence > 1) {
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "SEND PRES NOTIFY:\n"
|
2012-01-26 04:46:48 -06:00
|
|
|
"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"
|
2011-12-15 16:30:33 -06:00
|
|
|
"event[%s]\nct[%s]\npl[%s]\ncall_info[%s]\nexptime[%ld]\n",
|
2012-01-26 04:46:48 -06:00
|
|
|
file, func, line,
|
|
|
|
profile->name,
|
|
|
|
switch_str_nil(user_via),
|
|
|
|
remote_ip,
|
|
|
|
remote_port,
|
|
|
|
route_uri,
|
|
|
|
o_contact,
|
2011-12-15 16:30:33 -06:00
|
|
|
full_to,
|
|
|
|
full_from,
|
2012-01-26 04:46:48 -06:00
|
|
|
contact,
|
2011-12-15 16:30:33 -06:00
|
|
|
call_id,
|
|
|
|
expires_str,
|
|
|
|
event,
|
|
|
|
switch_str_nil(ct),
|
|
|
|
switch_str_nil(pl),
|
|
|
|
switch_str_nil(call_info),
|
|
|
|
(long)exptime
|
|
|
|
);
|
2012-01-26 04:46:48 -06:00
|
|
|
}
|
2011-12-15 16:30:33 -06:00
|
|
|
|
2012-01-28 13:09:12 -06:00
|
|
|
|
2012-01-26 04:46:48 -06:00
|
|
|
switch_mutex_lock(profile->ireg_mutex);
|
|
|
|
if (!profile->cseq_base) {
|
|
|
|
profile->cseq_base = (now - 1312693200) * 10;
|
2011-12-15 16:30:33 -06:00
|
|
|
}
|
2012-01-26 04:46:48 -06:00
|
|
|
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);
|
|
|
|
|
2011-12-15 16:30:33 -06:00
|
|
|
|
|
|
|
nua_notify(nh,
|
|
|
|
NUTAG_NEWSUB(1),
|
2012-02-23 17:59:01 -06:00
|
|
|
TAG_IF(route_uri, NUTAG_PROXY(route_uri)),
|
|
|
|
TAG_IF(dst->route, SIPTAG_ROUTE_STR(dst->route)),
|
2012-01-26 04:46:48 -06:00
|
|
|
TAG_IF(user_via, SIPTAG_VIA_STR(user_via)),
|
|
|
|
|
|
|
|
|
2011-12-15 16:30:33 -06:00
|
|
|
SIPTAG_FROM_STR(full_to),
|
|
|
|
SIPTAG_TO_STR(full_from),
|
2012-01-26 04:46:48 -06:00
|
|
|
|
2011-12-15 16:30:33 -06:00
|
|
|
SIPTAG_CALL_ID_STR(call_id),
|
|
|
|
TAG_IF(*expires_str, SIPTAG_EXPIRES_STR(expires_str)),
|
|
|
|
SIPTAG_SUBSCRIPTION_STATE_STR(sstr),
|
|
|
|
SIPTAG_EVENT_STR(event),
|
|
|
|
TAG_IF(!zstr(ct), SIPTAG_CONTENT_TYPE_STR(ct)),
|
|
|
|
TAG_IF(!zstr(pl), SIPTAG_PAYLOAD_STR(pl)),
|
|
|
|
TAG_IF(!zstr(call_info), SIPTAG_CALL_INFO_STR(call_info)),
|
|
|
|
TAG_IF(!exptime, SIPTAG_EXPIRES_STR("0")),
|
|
|
|
SIPTAG_CSEQ(cseq),
|
|
|
|
TAG_END());
|
|
|
|
|
2012-01-26 04:46:48 -06:00
|
|
|
|
2011-12-15 16:30:33 -06:00
|
|
|
|
2012-01-26 04:46:48 -06:00
|
|
|
switch_safe_free(route_uri);
|
2012-02-06 11:59:57 -06:00
|
|
|
switch_safe_free(dcs);
|
2012-01-26 04:46:48 -06:00
|
|
|
switch_safe_free(contact);
|
|
|
|
|
|
|
|
sofia_glue_free_destination(dst);
|
|
|
|
switch_safe_free(user_via);
|
|
|
|
switch_safe_free(o_contact_dup);
|
2012-03-02 11:51:32 -06:00
|
|
|
switch_safe_free(our_contact_dup);
|
2012-01-26 04:46:48 -06:00
|
|
|
|
2011-12-15 16:30:33 -06:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-21 20:00:34 -05:00
|
|
|
static int sofia_dialog_probe_notify_callback(void *pArg, int argc, char **argv, char **columnNames)
|
|
|
|
{
|
|
|
|
struct rfc4235_helper *sh = (struct rfc4235_helper *) pArg;
|
|
|
|
char key[256] = "";
|
|
|
|
char *data = NULL;
|
|
|
|
char *call_id = argv[0];
|
|
|
|
char *expires = argv[1];
|
|
|
|
char *user = argv[2];
|
|
|
|
char *host = argv[3];
|
|
|
|
char *event = argv[4];
|
|
|
|
char *version = argv[5];
|
|
|
|
char *notify_state = argv[6];
|
2011-12-15 16:30:33 -06:00
|
|
|
char *full_to = argv[7];
|
|
|
|
char *full_from = argv[8];
|
|
|
|
char *contact = argv[9];
|
|
|
|
char *remote_ip = argv[10];
|
|
|
|
char *remote_port = argv[11];
|
|
|
|
|
2011-10-21 20:00:34 -05:00
|
|
|
switch_stream_handle_t stream = { 0 };
|
|
|
|
char *to;
|
|
|
|
const char *pl = NULL;
|
|
|
|
const char *ct = "application/dialog-info+xml";
|
|
|
|
|
2012-01-26 04:46:48 -06:00
|
|
|
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]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-15 16:30:33 -06:00
|
|
|
|
2011-10-21 20:00:34 -05:00
|
|
|
if (mod_sofia_globals.debug_presence > 0) {
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE,
|
2012-01-26 04:46:48 -06:00
|
|
|
"SEND DIALOG\nTo: \t%s@%s\nFrom: \t%s@%s\nCall-ID: \t%s\n",
|
|
|
|
user, host, user, host, call_id);
|
2011-10-21 20:00:34 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
to = switch_mprintf("sip:%s@%s", user, host);
|
|
|
|
|
|
|
|
SWITCH_STANDARD_STREAM(stream);
|
|
|
|
|
|
|
|
if (zstr(version)) {
|
|
|
|
version = "0";
|
|
|
|
}
|
|
|
|
|
|
|
|
stream.write_function(&stream,
|
|
|
|
"<?xml version=\"1.0\"?>\n"
|
|
|
|
"<dialog-info xmlns=\"urn:ietf:params:xml:ns:dialog-info\" "
|
|
|
|
"version=\"%s\" state=\"%s\" entity=\"%s\">\n",
|
|
|
|
version,
|
|
|
|
notify_state, to);
|
|
|
|
|
|
|
|
switch_snprintf(key, sizeof(key), "%s%s", user, host);
|
|
|
|
|
|
|
|
data = switch_core_hash_find(sh->hash, key);
|
|
|
|
|
|
|
|
if (data) {
|
|
|
|
stream.write_function(&stream, "%s\n", data);
|
|
|
|
}
|
|
|
|
|
|
|
|
stream.write_function(&stream, "</dialog-info>\n");
|
|
|
|
pl = stream.data;
|
|
|
|
ct = "application/dialog-info+xml";
|
|
|
|
|
|
|
|
if (mod_sofia_globals.debug_presence > 0 && pl) {
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "send payload:\n%s\n", pl);
|
|
|
|
}
|
|
|
|
|
2011-12-15 16:30:33 -06:00
|
|
|
|
|
|
|
send_presence_notify(sh->profile,
|
|
|
|
full_to,
|
|
|
|
full_from,
|
|
|
|
contact,
|
|
|
|
expires,
|
|
|
|
call_id,
|
|
|
|
event,
|
|
|
|
remote_ip,
|
|
|
|
remote_port,
|
|
|
|
ct,
|
|
|
|
pl,
|
|
|
|
NULL
|
|
|
|
);
|
|
|
|
|
2011-10-21 20:00:34 -05:00
|
|
|
|
|
|
|
switch_safe_free(to);
|
|
|
|
switch_safe_free(stream.data);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-10-24 23:20:47 +00:00
|
|
|
static char *translate_rpid(char *in)
|
|
|
|
{
|
|
|
|
char *r = in;
|
2008-05-27 04:54:52 +00:00
|
|
|
|
2007-10-24 23:20:47 +00:00
|
|
|
if (in && (strstr(in, "null") || strstr(in, "NULL"))) {
|
|
|
|
in = NULL;
|
|
|
|
}
|
|
|
|
|
2010-07-29 23:39:39 -05:00
|
|
|
if (zstr(in)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!strcasecmp(in, "unknown")) {
|
2010-08-03 13:55:08 -05:00
|
|
|
r = NULL;
|
2007-10-24 23:20:47 +00:00
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!strcasecmp(in, "busy")) {
|
|
|
|
r = in;
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!strcasecmp(in, "unavailable")) {
|
|
|
|
r = "away";
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!strcasecmp(in, "idle")) {
|
2011-10-18 12:56:54 -05:00
|
|
|
r = "busy";
|
2007-10-24 23:20:47 +00:00
|
|
|
}
|
|
|
|
|
2012-01-26 04:46:48 -06:00
|
|
|
end:
|
2007-10-24 23:20:47 +00:00
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-06-02 15:42:59 +00:00
|
|
|
static char *gen_pidf(char *user_agent, char *id, char *url, char *open, char *rpid, char *prpid, char *status, const char **ct)
|
2008-05-28 20:58:57 +00:00
|
|
|
{
|
2009-04-27 17:31:34 +00:00
|
|
|
char *ret = NULL;
|
|
|
|
|
2008-05-28 20:58:57 +00:00
|
|
|
if (switch_stristr("polycom", user_agent)) {
|
|
|
|
*ct = "application/xpidf+xml";
|
2010-02-06 03:38:24 +00:00
|
|
|
|
2010-08-20 23:40:37 -04:00
|
|
|
/* If unknown/none prpid is provided, just show the user as online. */
|
2010-08-24 11:53:46 -05:00
|
|
|
if (!prpid || !strcasecmp(prpid, "unknown")) {
|
2010-08-20 23:40:37 -04:00
|
|
|
prpid = "online";
|
|
|
|
}
|
|
|
|
|
|
|
|
/* of course!, lets make a big deal over dashes. Now the stupidity is complete. */
|
2008-10-21 20:01:52 +00:00
|
|
|
if (!strcmp(prpid, "on-the-phone")) {
|
|
|
|
prpid = "onthephone";
|
|
|
|
}
|
|
|
|
|
2010-02-06 03:38:24 +00:00
|
|
|
ret = switch_mprintf("<?xml version=\"1.0\"?>\n"
|
|
|
|
"<!DOCTYPE presence PUBLIC \"-//IETF//DTD RFCxxxx XPIDF 1.0//EN\" \"xpidf.dtd\">\n"
|
|
|
|
"<presence>\n"
|
|
|
|
" <status>\n"
|
|
|
|
" <note>%s</note>\n"
|
|
|
|
" </status>\n"
|
|
|
|
" <presentity uri=\"%s;method=SUBSCRIBE\" />\n"
|
|
|
|
" <atom id=\"%s\">\n"
|
|
|
|
" <address uri=\"%s;user=ip\" priority=\"0.800000\">\n"
|
|
|
|
" <status status=\"%s\" />\n"
|
2010-07-27 19:47:35 -05:00
|
|
|
" <msnsubstatus substatus=\"%s\" />\n"
|
|
|
|
" </address>\n"
|
|
|
|
" </atom>\n"
|
|
|
|
"</presence>\n", status, id, id, url, open, prpid);
|
2008-05-28 20:58:57 +00:00
|
|
|
} else {
|
2010-08-17 13:00:32 -05:00
|
|
|
char *xml_rpid = NULL;
|
|
|
|
|
2008-05-28 20:58:57 +00:00
|
|
|
*ct = "application/pidf+xml";
|
2010-07-27 19:47:35 -05:00
|
|
|
|
2010-08-17 13:00:32 -05:00
|
|
|
if (!strcasecmp(open, "closed")) {
|
|
|
|
status = "Unregistered";
|
|
|
|
prpid = NULL;
|
|
|
|
}
|
|
|
|
|
2010-07-27 22:08:47 -05:00
|
|
|
if (!strncasecmp(status, "Registered", 10)) {
|
2010-07-27 19:47:35 -05:00
|
|
|
status = "Available";
|
|
|
|
}
|
2010-08-17 13:00:32 -05:00
|
|
|
|
2010-08-24 11:53:46 -05:00
|
|
|
if (!strcasecmp(status, "Available")) {
|
|
|
|
prpid = NULL;
|
|
|
|
}
|
|
|
|
|
2010-07-27 22:08:47 -05:00
|
|
|
|
|
|
|
if (!strcasecmp(status, "Unregistered")) {
|
|
|
|
prpid = NULL;
|
|
|
|
open = "closed";
|
|
|
|
}
|
2010-07-29 23:39:39 -05:00
|
|
|
|
|
|
|
if (zstr(rpid)) {
|
|
|
|
prpid = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-17 13:00:32 -05:00
|
|
|
if (zstr(status) && !zstr(prpid)) {
|
|
|
|
status = "Available";
|
2010-08-24 11:53:46 -05:00
|
|
|
prpid = NULL;
|
2010-07-27 19:47:35 -05:00
|
|
|
}
|
2010-08-17 13:00:32 -05:00
|
|
|
|
|
|
|
if (prpid) {
|
|
|
|
xml_rpid = switch_mprintf(" <rpid:activities>\r\n"
|
|
|
|
" <rpid:%s/>\n"
|
|
|
|
" </rpid:activities>\n", prpid);
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = switch_mprintf("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?> \n"
|
|
|
|
"<presence xmlns='urn:ietf:params:xml:ns:pidf' \n"
|
|
|
|
"xmlns:dm='urn:ietf:params:xml:ns:pidf:data-model' \n"
|
|
|
|
"xmlns:rpid='urn:ietf:params:xml:ns:pidf:rpid' \n"
|
|
|
|
"xmlns:c='urn:ietf:params:xml:ns:pidf:cipid' entity='%s'>\n"
|
|
|
|
" <tuple id='t6a5ed77e'>\n"
|
|
|
|
" <status>\r\n"
|
|
|
|
" <basic>%s</basic>\n"
|
|
|
|
" </status>\n"
|
|
|
|
" </tuple>\n"
|
|
|
|
" <dm:person id='p06360c4a'>\n"
|
|
|
|
"%s"
|
|
|
|
" <dm:note>%s</dm:note>\n"
|
|
|
|
" </dm:person>\n"
|
|
|
|
"</presence>", id, open, switch_str_nil(xml_rpid), status);
|
|
|
|
|
|
|
|
|
|
|
|
switch_safe_free(xml_rpid);
|
2008-05-28 20:58:57 +00:00
|
|
|
}
|
2009-04-27 17:31:34 +00:00
|
|
|
|
|
|
|
|
|
|
|
return ret;
|
2008-05-28 20:58:57 +00:00
|
|
|
}
|
|
|
|
|
2010-07-29 23:39:39 -05:00
|
|
|
|
|
|
|
|
2007-04-02 19:54:25 +00:00
|
|
|
static int sofia_presence_sub_callback(void *pArg, int argc, char **argv, char **columnNames)
|
2007-03-31 19:01:33 +00:00
|
|
|
{
|
2007-12-15 00:39:53 +00:00
|
|
|
struct presence_helper *helper = (struct presence_helper *) pArg;
|
2007-12-18 01:12:50 +00:00
|
|
|
char *pl = NULL;
|
2008-06-02 15:42:59 +00:00
|
|
|
char *clean_id = NULL, *id = NULL;
|
2011-12-15 16:30:33 -06:00
|
|
|
|
2007-10-24 23:20:47 +00:00
|
|
|
char *proto = argv[0];
|
|
|
|
char *user = argv[1];
|
|
|
|
char *host = argv[2];
|
|
|
|
char *sub_to_user = argv[3];
|
|
|
|
char *event = argv[5];
|
2011-12-15 16:30:33 -06:00
|
|
|
char *contact = argv[6];
|
2007-10-24 23:20:47 +00:00
|
|
|
char *call_id = argv[7];
|
2011-12-15 16:30:33 -06:00
|
|
|
char *full_from = argv[8];
|
|
|
|
//char *full_via = argv[9];
|
|
|
|
|
2007-12-29 16:07:03 +00:00
|
|
|
char *expires = argv[10];
|
2008-05-28 20:58:57 +00:00
|
|
|
char *user_agent = argv[11];
|
2008-09-18 00:01:03 +00:00
|
|
|
char *profile_name = argv[13];
|
2008-12-11 20:20:20 +00:00
|
|
|
uint32_t in = 0;
|
|
|
|
char *status = argv[14];
|
|
|
|
char *rpid = argv[15];
|
|
|
|
char *sub_to_host = argv[16];
|
2010-07-29 23:39:39 -05:00
|
|
|
char *open_closed = NULL;
|
|
|
|
char *dialog_status = NULL;
|
|
|
|
char *dialog_rpid = NULL;
|
2012-02-13 13:50:21 -06:00
|
|
|
char *default_dialog = "partial";
|
2010-07-29 23:39:39 -05:00
|
|
|
const char *ct = "no/idea";
|
2011-12-15 16:30:33 -06:00
|
|
|
|
2007-12-18 01:12:50 +00:00
|
|
|
char *to = NULL;
|
2007-03-31 19:01:33 +00:00
|
|
|
char *open;
|
2007-10-24 23:20:47 +00:00
|
|
|
char *prpid;
|
2011-12-15 16:30:33 -06:00
|
|
|
|
2008-02-14 17:28:58 +00:00
|
|
|
int is_dialog = 0;
|
2008-09-18 00:01:03 +00:00
|
|
|
sofia_profile_t *ext_profile = NULL, *profile = helper->profile;
|
2011-12-15 16:30:33 -06:00
|
|
|
|
2010-07-29 23:39:39 -05:00
|
|
|
char status_line[256] = "";
|
2010-10-01 14:04:06 -05:00
|
|
|
char *version = "0";
|
2010-10-18 15:30:11 -05:00
|
|
|
char *presence_id = NULL;
|
|
|
|
char *free_me = NULL;
|
2011-10-21 20:00:34 -05:00
|
|
|
int holding = 0;
|
2011-10-24 09:49:34 -05:00
|
|
|
char *orig_proto = NULL;
|
|
|
|
int skip_proto = 0;
|
2011-12-15 16:30:33 -06:00
|
|
|
char *full_to = NULL;
|
|
|
|
char *ip = NULL;
|
|
|
|
char *port = 0;
|
2011-10-24 09:49:34 -05:00
|
|
|
|
2011-12-15 16:30:33 -06:00
|
|
|
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]);
|
|
|
|
}
|
|
|
|
DUMP_EVENT(helper->event);
|
|
|
|
}
|
2011-10-21 20:00:34 -05:00
|
|
|
|
2010-08-17 13:00:32 -05:00
|
|
|
if (argc > 18) {
|
|
|
|
if (!zstr(argv[17])) {
|
|
|
|
status = argv[17];
|
|
|
|
}
|
|
|
|
if (!zstr(argv[18])) {
|
|
|
|
rpid = argv[18];
|
|
|
|
}
|
2010-07-29 23:39:39 -05:00
|
|
|
open_closed = argv[19];
|
2008-11-22 02:51:00 +00:00
|
|
|
}
|
|
|
|
|
2010-07-29 23:39:39 -05:00
|
|
|
if (argc > 20) {
|
|
|
|
dialog_status = argv[20];
|
|
|
|
dialog_rpid = argv[21];
|
2010-10-01 14:04:06 -05:00
|
|
|
version = argv[22];
|
2010-10-18 15:30:11 -05:00
|
|
|
presence_id = argv[23];
|
2011-10-24 09:49:34 -05:00
|
|
|
orig_proto = argv[24];
|
2011-12-15 16:30:33 -06:00
|
|
|
full_to = argv[25];
|
|
|
|
ip = argv[26];
|
|
|
|
port = argv[27];
|
2010-10-18 15:30:11 -05:00
|
|
|
}
|
|
|
|
|
2012-01-20 13:00:37 -06:00
|
|
|
|
2010-10-18 15:30:11 -05:00
|
|
|
if (!zstr(presence_id) && strchr(presence_id, '@')) {
|
|
|
|
char *p;
|
|
|
|
|
|
|
|
free_me = strdup(presence_id);
|
|
|
|
|
|
|
|
if ((p = strchr(free_me, '@'))) {
|
|
|
|
*p = '\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
user = free_me;
|
2010-07-29 23:39:39 -05:00
|
|
|
}
|
2010-10-18 15:30:11 -05:00
|
|
|
|
2011-10-24 09:49:34 -05:00
|
|
|
|
|
|
|
if (!zstr(orig_proto) && !strcmp(orig_proto, SOFIA_CHAT_PROTO)) {
|
|
|
|
skip_proto = 1;
|
|
|
|
}
|
|
|
|
|
2010-07-29 23:39:39 -05:00
|
|
|
in = helper->event && helper->event->event_id == SWITCH_EVENT_PRESENCE_IN;
|
2008-12-11 20:20:20 +00:00
|
|
|
|
2009-10-23 16:03:42 +00:00
|
|
|
if (zstr(rpid)) {
|
2008-11-25 20:54:58 +00:00
|
|
|
rpid = "unknown";
|
2008-11-22 02:51:00 +00:00
|
|
|
}
|
|
|
|
|
2009-10-23 16:03:42 +00:00
|
|
|
if (zstr(status)) {
|
2008-11-25 20:54:58 +00:00
|
|
|
if (!strcasecmp(rpid, "busy")) {
|
|
|
|
status = "Busy";
|
|
|
|
} else if (!strcasecmp(rpid, "unavailable")) {
|
|
|
|
status = "Idle";
|
|
|
|
} else if (!strcasecmp(rpid, "away")) {
|
|
|
|
status = "Idle";
|
|
|
|
} else {
|
|
|
|
status = "Available";
|
|
|
|
}
|
|
|
|
}
|
2010-02-06 03:38:24 +00:00
|
|
|
|
2011-10-21 20:00:34 -05:00
|
|
|
if (status && !strncasecmp(status, "hold", 4)) {
|
|
|
|
holding = 1;
|
|
|
|
}
|
|
|
|
|
2008-09-18 00:01:03 +00:00
|
|
|
if (profile_name && strcasecmp(profile_name, helper->profile->name)) {
|
2010-02-06 03:38:24 +00:00
|
|
|
if ((ext_profile = sofia_glue_find_profile(profile_name))) {
|
|
|
|
profile = ext_profile;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-11 13:23:56 -05:00
|
|
|
|
2011-12-15 16:30:33 -06:00
|
|
|
if (!strcasecmp(proto, SOFIA_CHAT_PROTO) || skip_proto) {
|
|
|
|
clean_id = switch_mprintf("sip:%s@%s", sub_to_user, sub_to_host);
|
|
|
|
} else {
|
|
|
|
clean_id = switch_mprintf("sip:%s+%s@%s", proto, sub_to_user, sub_to_host);
|
2008-12-11 20:20:20 +00:00
|
|
|
}
|
2010-02-06 03:38:24 +00:00
|
|
|
|
2011-12-15 16:30:33 -06:00
|
|
|
|
2010-02-06 03:38:24 +00:00
|
|
|
|
2007-03-31 19:01:33 +00:00
|
|
|
if (!rpid) {
|
|
|
|
rpid = "unknown";
|
|
|
|
}
|
2011-10-24 09:49:34 -05:00
|
|
|
|
2011-12-15 16:30:33 -06:00
|
|
|
// if (!strcasecmp(proto, SOFIA_CHAT_PROTO) || skip_proto) {
|
|
|
|
// clean_id = switch_mprintf("sip:%s@%s", sub_to_user, sub_to_host);
|
|
|
|
//} else {
|
|
|
|
// clean_id = switch_mprintf("sip:%s+%s@%s", proto, sub_to_user, sub_to_host);
|
|
|
|
//}
|
2007-12-15 18:26:10 +00:00
|
|
|
|
2008-12-10 20:54:24 +00:00
|
|
|
if (mod_sofia_globals.debug_presence > 0) {
|
2010-02-06 03:38:24 +00:00
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE,
|
|
|
|
"SEND PRESENCE\nTo: \t%s@%s\nFrom: \t%s@%s\nCall-ID: \t%s\nProfile:\t%s [%s]\n\n",
|
2008-12-11 20:20:20 +00:00
|
|
|
user, host, sub_to_user, sub_to_host, call_id, profile_name, helper->profile->name);
|
2008-12-10 20:54:24 +00:00
|
|
|
}
|
|
|
|
|
2011-10-24 09:49:34 -05:00
|
|
|
if (!strcasecmp(sub_to_host, host) && !skip_proto) {
|
2007-03-31 19:01:33 +00:00
|
|
|
/* same host */
|
|
|
|
id = switch_mprintf("sip:%s+%s@%s", proto, sub_to_user, sub_to_host);
|
2011-10-24 09:49:34 -05:00
|
|
|
} else if (strcasecmp(proto, SOFIA_CHAT_PROTO) && !skip_proto) {
|
2007-03-31 19:01:33 +00:00
|
|
|
/*encapsulate */
|
|
|
|
id = switch_mprintf("sip:%s+%s+%s@%s", proto, sub_to_user, sub_to_host, host);
|
|
|
|
} else {
|
|
|
|
id = switch_mprintf("sip:%s@%s", sub_to_user, sub_to_host);
|
|
|
|
}
|
|
|
|
|
|
|
|
to = switch_mprintf("sip:%s@%s", user, host);
|
2008-02-14 17:28:58 +00:00
|
|
|
|
|
|
|
is_dialog = !strcmp(event, "dialog");
|
2008-05-27 04:54:52 +00:00
|
|
|
|
2008-02-14 17:28:58 +00:00
|
|
|
if (helper->event) {
|
2007-12-15 00:39:53 +00:00
|
|
|
switch_stream_handle_t stream = { 0 };
|
2009-02-23 16:31:59 +00:00
|
|
|
const char *direction = switch_str_nil(switch_event_get_header(helper->event, "presence-call-direction"));
|
2011-10-21 20:00:34 -05:00
|
|
|
//const char *force_direction = switch_str_nil(switch_event_get_header(helper->event, "force-direction"));
|
2007-12-15 00:39:53 +00:00
|
|
|
const char *uuid = switch_str_nil(switch_event_get_header(helper->event, "unique-id"));
|
2007-12-15 19:33:36 +00:00
|
|
|
const char *event_status = switch_str_nil(switch_event_get_header(helper->event, "status"));
|
2011-10-24 18:54:22 -05:00
|
|
|
const char *resub = switch_str_nil(switch_event_get_header(helper->event, "resub"));
|
2011-10-18 11:53:49 -05:00
|
|
|
const char *force_event_status = switch_str_nil(switch_event_get_header(helper->event, "force-status"));
|
2007-12-18 03:12:51 +00:00
|
|
|
const char *astate = switch_str_nil(switch_event_get_header(helper->event, "astate"));
|
2007-12-29 18:30:48 +00:00
|
|
|
const char *answer_state = switch_str_nil(switch_event_get_header(helper->event, "answer-state"));
|
2007-12-18 01:12:50 +00:00
|
|
|
const char *dft_state;
|
2011-05-11 13:23:56 -05:00
|
|
|
const char *from_id;
|
2008-02-14 17:28:58 +00:00
|
|
|
const char *to_user = switch_str_nil(switch_event_get_header(helper->event, "variable_sip_to_user"));
|
|
|
|
const char *from_user = switch_str_nil(switch_event_get_header(helper->event, "variable_sip_from_user"));
|
2009-04-01 20:11:36 +00:00
|
|
|
char *clean_to_user = NULL;
|
|
|
|
char *clean_from_user = NULL;
|
2010-08-19 12:09:21 -05:00
|
|
|
int force_status = 0;
|
2012-01-11 21:32:23 -06:00
|
|
|
const char *call_state = switch_event_get_header(helper->event, "channel-state");
|
2012-02-14 18:59:37 -06:00
|
|
|
char *call_info_state = switch_event_get_header(helper->event, "presence-call-info-state");
|
2012-01-11 21:32:23 -06:00
|
|
|
|
2012-02-13 13:50:21 -06:00
|
|
|
if (user_agent && switch_stristr("snom", user_agent) && uuid) {
|
|
|
|
default_dialog = "full" ;
|
|
|
|
}
|
|
|
|
|
2012-01-11 21:32:23 -06:00
|
|
|
if (call_state && !strcasecmp(call_state, "cs_hangup")) {
|
|
|
|
astate = "hangup";
|
|
|
|
}
|
2011-05-11 13:23:56 -05:00
|
|
|
|
2011-10-21 20:00:34 -05:00
|
|
|
if (event_status && !strncasecmp(event_status, "hold", 4)) {
|
|
|
|
holding = 1;
|
|
|
|
}
|
2011-10-18 11:53:49 -05:00
|
|
|
|
|
|
|
if (force_event_status && !event_status) {
|
|
|
|
event_status = force_event_status;
|
|
|
|
}
|
|
|
|
|
2011-10-21 20:00:34 -05:00
|
|
|
if (event_status && !strncasecmp(event_status, "hold", 4)) {
|
|
|
|
holding = 1;
|
|
|
|
}
|
|
|
|
|
2011-05-11 13:23:56 -05:00
|
|
|
if (!strcasecmp(direction, "inbound")) {
|
|
|
|
from_id = switch_str_nil(switch_event_get_header(helper->event, "Caller-Destination-Number"));
|
|
|
|
} else {
|
|
|
|
from_id = switch_str_nil(switch_event_get_header(helper->event, "Other-Leg-Caller-ID-Number"));
|
|
|
|
}
|
2008-06-02 20:06:07 +00:00
|
|
|
#if 0
|
|
|
|
char *buf;
|
|
|
|
switch_event_serialize(helper->event, &buf, SWITCH_FALSE);
|
|
|
|
switch_assert(buf);
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "CHANNEL_DATA:\n%s\n", buf);
|
|
|
|
free(buf);
|
|
|
|
#endif
|
|
|
|
|
2008-02-14 17:28:58 +00:00
|
|
|
if (is_dialog) {
|
|
|
|
SWITCH_STANDARD_STREAM(stream);
|
|
|
|
}
|
2010-10-22 15:13:44 -05:00
|
|
|
|
2011-10-21 20:00:34 -05:00
|
|
|
if (is_dialog) {
|
|
|
|
// Usually we report the dialogs FROM the probed user. The exception is when the monitored endpoint is internal,
|
|
|
|
// and its presence_id is set in the dialplan. Reverse the direction if this is not a registered entity.
|
|
|
|
const char *caller = switch_str_nil(switch_event_get_header(helper->event, "caller-username"));
|
|
|
|
if (!strcmp(direction, "inbound") && strcmp(sub_to_user, caller)) {
|
|
|
|
// If inbound and the entity is not the caller (i.e. internal to FS), then the direction is reversed
|
|
|
|
// because it is not going through the B2BUA
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "sofia_presence_sub_callback: endpt is internal\n");
|
|
|
|
direction = !strcasecmp(direction, "outbound") ? "inbound" : "outbound";
|
|
|
|
}
|
|
|
|
|
2010-10-22 15:13:44 -05:00
|
|
|
}
|
2007-12-18 03:12:51 +00:00
|
|
|
|
2007-12-18 01:12:50 +00:00
|
|
|
if (!strcasecmp(direction, "outbound")) {
|
|
|
|
direction = "recipient";
|
|
|
|
dft_state = "early";
|
|
|
|
} else {
|
|
|
|
direction = "initiator";
|
|
|
|
dft_state = "confirmed";
|
|
|
|
}
|
2008-05-27 04:54:52 +00:00
|
|
|
|
2008-02-14 17:28:58 +00:00
|
|
|
if (is_dialog) {
|
2010-10-01 14:04:06 -05:00
|
|
|
if (zstr(version)) {
|
2010-09-01 11:46:32 -05:00
|
|
|
version = "0";
|
|
|
|
}
|
|
|
|
|
2008-05-27 04:54:52 +00:00
|
|
|
stream.write_function(&stream,
|
2008-02-14 17:28:58 +00:00
|
|
|
"<?xml version=\"1.0\"?>\n"
|
|
|
|
"<dialog-info xmlns=\"urn:ietf:params:xml:ns:dialog-info\" "
|
2012-02-13 13:50:21 -06:00
|
|
|
"version=\"%s\" state=\"%s\" entity=\"%s\">\n", version, default_dialog, clean_id);
|
2011-04-04 11:39:39 -05:00
|
|
|
|
2008-02-14 17:28:58 +00:00
|
|
|
}
|
2008-05-27 04:54:52 +00:00
|
|
|
|
2010-09-02 16:01:50 -05:00
|
|
|
if (!zstr(uuid)) {
|
2010-08-19 12:09:21 -05:00
|
|
|
if (!zstr(answer_state)) {
|
|
|
|
astate = answer_state;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (zstr(astate)) {
|
|
|
|
if (is_dialog) {
|
|
|
|
astate = dft_state;
|
|
|
|
} else {
|
|
|
|
astate = "terminated";
|
2008-01-01 01:03:33 +00:00
|
|
|
}
|
2008-05-27 04:54:52 +00:00
|
|
|
}
|
|
|
|
|
2008-01-01 01:03:33 +00:00
|
|
|
if (!strcasecmp(astate, "answered")) {
|
2007-12-18 03:12:51 +00:00
|
|
|
astate = "confirmed";
|
|
|
|
}
|
2012-02-07 11:10:42 -06:00
|
|
|
|
2012-02-09 12:03:11 -06:00
|
|
|
|
2008-02-14 17:28:58 +00:00
|
|
|
if (is_dialog) {
|
2011-10-21 20:00:34 -05:00
|
|
|
|
2010-08-18 19:51:10 -05:00
|
|
|
if (!strcasecmp(astate, "ringing")) {
|
|
|
|
if (!strcasecmp(direction, "recipient")) {
|
|
|
|
astate = "early";
|
|
|
|
} else {
|
|
|
|
astate = "confirmed";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-21 20:00:34 -05:00
|
|
|
if (holding) {
|
|
|
|
astate = "early";
|
|
|
|
}
|
2012-02-22 23:08:19 -06:00
|
|
|
|
|
|
|
|
|
|
|
if (!strcasecmp(astate, "hangup")) {
|
|
|
|
astate = "terminated";
|
|
|
|
}
|
2011-10-21 20:00:34 -05:00
|
|
|
|
2008-02-14 17:28:58 +00:00
|
|
|
stream.write_function(&stream, "<dialog id=\"%s\" direction=\"%s\">\n", uuid, direction);
|
|
|
|
stream.write_function(&stream, "<state>%s</state>\n", astate);
|
2010-08-18 19:51:10 -05:00
|
|
|
} else {
|
|
|
|
if (!strcasecmp(astate, "ringing")) {
|
2010-08-19 12:09:21 -05:00
|
|
|
astate = "early";
|
2010-08-18 19:51:10 -05:00
|
|
|
}
|
2008-02-14 17:28:58 +00:00
|
|
|
}
|
2010-08-18 19:51:10 -05:00
|
|
|
|
2012-02-13 13:50:21 -06:00
|
|
|
|
2012-02-14 18:59:37 -06:00
|
|
|
if (sofia_test_pflag(profile, PFLAG_PRESENCE_DISABLE_EARLY) &&
|
|
|
|
(!zstr(call_info_state) && (!strcasecmp(call_info_state, "alterting") || !strcasecmp(call_info_state, "progressing")))) {
|
2012-02-13 13:50:21 -06:00
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
2008-02-14 17:28:58 +00:00
|
|
|
if (!strcasecmp(astate, "early") || !strcasecmp(astate, "confirmed")) {
|
2008-05-27 04:54:52 +00:00
|
|
|
|
2008-02-14 17:28:58 +00:00
|
|
|
clean_to_user = switch_mprintf("%s", sub_to_user ? sub_to_user : to_user);
|
|
|
|
clean_from_user = switch_mprintf("%s", from_id ? from_id : from_user);
|
|
|
|
|
|
|
|
if (is_dialog) {
|
2009-10-23 16:03:42 +00:00
|
|
|
if (!zstr(clean_to_user) && !zstr(clean_from_user)) {
|
2008-02-14 17:28:58 +00:00
|
|
|
stream.write_function(&stream, "<local>\n<identity display=\"%s\">sip:%s@%s</identity>\n", clean_to_user, clean_to_user, host);
|
|
|
|
stream.write_function(&stream, "<target uri=\"sip:%s@%s\">\n", clean_to_user, host);
|
2011-10-21 20:00:34 -05:00
|
|
|
stream.write_function(&stream, "<param pname=\"+sip.rendering\" pvalue=\"%s\"/>\n", holding ? "no" : "yes");
|
|
|
|
|
2008-05-27 04:54:52 +00:00
|
|
|
stream.write_function(&stream, "</target>\n</local>\n");
|
2011-06-07 13:58:12 +02:00
|
|
|
if (switch_true(switch_event_get_header(helper->event, "Presence-Privacy"))) {
|
|
|
|
stream.write_function(&stream, "<remote>\n<identity display=\"Anonymous\">sip:anonymous@anonymous.invalid</identity>\n");
|
|
|
|
} else {
|
|
|
|
stream.write_function(&stream, "<remote>\n<identity display=\"%s\">sip:%s@%s</identity>\n", clean_from_user, clean_from_user,
|
|
|
|
host);
|
|
|
|
}
|
2008-02-14 17:28:58 +00:00
|
|
|
stream.write_function(&stream, "<target uri=\"sip:**%s@%s\"/>\n", clean_to_user, host);
|
2011-10-24 09:49:34 -05:00
|
|
|
stream.write_function(&stream, "</remote>\n");
|
|
|
|
} else if (!strcasecmp(proto, "queue")) {
|
2012-01-04 12:10:53 -06:00
|
|
|
stream.write_function(&stream, "<local>\n<identity display=\"queue\">sip:%s@%s;proto=queue</identity>\n",
|
|
|
|
!zstr(clean_to_user) ? clean_to_user : "unknown", host);
|
|
|
|
stream.write_function(&stream, "<target uri=\"sip:%s@%s;proto=fifo\">\n", !zstr(clean_to_user) ? clean_to_user : "unknown", host);
|
2011-10-24 09:49:34 -05:00
|
|
|
stream.write_function(&stream, "<param pname=\"+sip.rendering\" pvalue=\"no\"/>\n</target>\n</local>\n");
|
|
|
|
stream.write_function(&stream, "<remote>\n<identity display=\"queue\">sip:%s</identity>\n", uuid);
|
|
|
|
if (skip_proto) {
|
|
|
|
stream.write_function(&stream, "<target uri=\"sip:%s\"/>\n", uuid);
|
|
|
|
} else {
|
|
|
|
stream.write_function(&stream, "<target uri=\"sip:queue+%s\"/>\n", uuid);
|
|
|
|
}
|
|
|
|
|
2008-02-14 17:28:58 +00:00
|
|
|
stream.write_function(&stream, "</remote>\n");
|
|
|
|
} else if (!strcasecmp(proto, "park")) {
|
2012-01-04 12:10:53 -06:00
|
|
|
stream.write_function(&stream, "<local>\n<identity display=\"park\">sip:%s@%s;proto=park</identity>\n",
|
|
|
|
!zstr(clean_to_user) ? clean_to_user : "unknown", host);
|
|
|
|
stream.write_function(&stream, "<target uri=\"sip:%s@%s;proto=park\">\n", !zstr(clean_to_user) ? clean_to_user : "unknown", host);
|
2008-05-27 04:54:52 +00:00
|
|
|
stream.write_function(&stream, "<param pname=\"+sip.rendering\" pvalue=\"no\"/>\n</target>\n</local>\n");
|
2011-10-24 09:49:34 -05:00
|
|
|
stream.write_function(&stream, "<remote>\n<identity display=\"park\">sip:%s</identity>\n", uuid);
|
|
|
|
if (skip_proto) {
|
|
|
|
stream.write_function(&stream, "<target uri=\"sip:%s\"/>\n", uuid);
|
|
|
|
} else {
|
|
|
|
stream.write_function(&stream, "<target uri=\"sip:park+%s\"/>\n", uuid);
|
|
|
|
}
|
2008-02-14 17:28:58 +00:00
|
|
|
stream.write_function(&stream, "</remote>\n");
|
|
|
|
} else if (!strcasecmp(proto, "conf")) {
|
2012-01-04 12:10:53 -06:00
|
|
|
stream.write_function(&stream, "<local>\n<identity display=\"conference\">sip:%s@%s;proto=conference</identity>\n",
|
|
|
|
!zstr(clean_to_user) ? clean_to_user : "unknown", host);
|
|
|
|
stream.write_function(&stream, "<target uri=\"sip:%s@%s;proto=conference\">\n",
|
|
|
|
!zstr(clean_to_user) ? clean_to_user : "unknown", host);
|
2008-05-27 04:54:52 +00:00
|
|
|
stream.write_function(&stream, "<param pname=\"+sip.rendering\" pvalue=\"yes\"/>\n</target>\n</local>\n");
|
2008-02-14 17:28:58 +00:00
|
|
|
stream.write_function(&stream, "<remote>\n<identity display=\"conference\">sip:%s@%s</identity>\n", uuid, host);
|
2011-10-24 09:49:34 -05:00
|
|
|
if (skip_proto) {
|
|
|
|
stream.write_function(&stream, "<target uri=\"sip:%s@%s\"/>\n", uuid, host);
|
|
|
|
} else {
|
|
|
|
stream.write_function(&stream, "<target uri=\"sip:conf+%s@%s\"/>\n", uuid, host);
|
|
|
|
}
|
2008-02-14 17:28:58 +00:00
|
|
|
stream.write_function(&stream, "</remote>\n");
|
|
|
|
}
|
2007-12-29 17:50:38 +00:00
|
|
|
}
|
2009-04-01 20:11:36 +00:00
|
|
|
|
|
|
|
switch_safe_free(clean_to_user);
|
|
|
|
switch_safe_free(clean_from_user);
|
2007-12-29 17:50:38 +00:00
|
|
|
}
|
2008-02-14 17:28:58 +00:00
|
|
|
if (is_dialog) {
|
2008-05-27 04:54:52 +00:00
|
|
|
stream.write_function(&stream, "</dialog>\n");
|
2008-02-14 17:28:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_dialog) {
|
|
|
|
stream.write_function(&stream, "</dialog-info>\n");
|
|
|
|
pl = stream.data;
|
|
|
|
ct = "application/dialog-info+xml";
|
|
|
|
}
|
2008-05-27 04:54:52 +00:00
|
|
|
|
2011-10-24 18:54:22 -05:00
|
|
|
if (!zstr(astate) && !zstr(uuid) &&
|
|
|
|
helper && helper->stream.data && strcmp(helper->last_uuid, uuid) && strcasecmp(astate, "terminated") && strchr(uuid, '-')) {
|
2012-01-30 11:43:43 -06:00
|
|
|
helper->stream.write_function(&helper->stream, "update sip_dialogs set state='%s' where hostname='%q' and profile_name='%q' and uuid='%s';",
|
|
|
|
mod_sofia_globals.hostname, profile->name, astate, uuid);
|
2008-04-11 19:41:24 +00:00
|
|
|
switch_copy_string(helper->last_uuid, uuid, sizeof(helper->last_uuid));
|
2007-12-29 17:50:38 +00:00
|
|
|
}
|
2007-12-29 17:52:22 +00:00
|
|
|
|
2012-01-11 21:32:23 -06:00
|
|
|
if (zstr(astate)) astate = "";
|
2008-11-22 01:34:19 +00:00
|
|
|
|
2012-01-11 21:32:23 -06:00
|
|
|
if (!is_dialog) {
|
2008-11-22 01:34:19 +00:00
|
|
|
switch_set_string(status_line, status);
|
|
|
|
|
2008-02-14 17:28:58 +00:00
|
|
|
if (in) {
|
2011-10-24 18:54:22 -05:00
|
|
|
open = "open";
|
2008-05-27 04:54:52 +00:00
|
|
|
|
2012-02-22 18:39:16 -06:00
|
|
|
if (switch_false(resub)) {
|
2012-01-11 21:32:23 -06:00
|
|
|
int term;
|
2010-08-19 12:09:21 -05:00
|
|
|
|
2011-10-24 18:54:22 -05:00
|
|
|
const char *direction = switch_event_get_header(helper->event, "Caller-Direction");
|
|
|
|
const char *op, *what = "Ring";
|
|
|
|
|
|
|
|
if (direction && !strcasecmp(direction, "outbound")) {
|
|
|
|
op = switch_event_get_header(helper->event, "Other-Leg-Caller-ID-Number");
|
2010-08-19 12:09:21 -05:00
|
|
|
} else {
|
2011-10-24 18:54:22 -05:00
|
|
|
op = switch_event_get_header(helper->event, "Caller-Callee-ID-Number");
|
2008-06-02 16:40:44 +00:00
|
|
|
}
|
2010-02-06 03:38:24 +00:00
|
|
|
|
2010-08-19 12:09:21 -05:00
|
|
|
if (zstr(op)) {
|
2011-10-24 18:54:22 -05:00
|
|
|
op = switch_event_get_header(helper->event, "Caller-Destination-Number");
|
2008-02-14 19:45:15 +00:00
|
|
|
}
|
2010-08-19 12:09:21 -05:00
|
|
|
|
2011-10-24 18:54:22 -05:00
|
|
|
if (direction) {
|
|
|
|
what = strcasecmp(direction, "outbound") ? "Call" : "Ring";
|
|
|
|
}
|
2007-12-29 18:30:48 +00:00
|
|
|
|
2011-10-24 18:54:22 -05:00
|
|
|
if (!strcmp(astate, "early")) {
|
|
|
|
if (!zstr(op)) {
|
|
|
|
//switch_snprintf(status_line, sizeof(status_line), "%sing", what);
|
|
|
|
//} else {
|
|
|
|
switch_snprintf(status_line, sizeof(status_line), "%s %s", what, op);
|
|
|
|
}
|
2011-10-21 20:00:34 -05:00
|
|
|
|
2011-10-24 18:54:22 -05:00
|
|
|
rpid = "on-the-phone";
|
|
|
|
force_status = 1;
|
|
|
|
|
|
|
|
} else if (!strcmp(astate, "confirmed")) {
|
|
|
|
if (!zstr(op)) {
|
2011-12-15 13:20:27 -05:00
|
|
|
if (sofia_test_pflag(profile, PFLAG_PRESENCE_PRIVACY)) {
|
|
|
|
switch_snprintf(status_line, sizeof(status_line), "On The Phone");
|
|
|
|
} else {
|
|
|
|
switch_snprintf(status_line, sizeof(status_line), "Talk %s", op);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
switch_snprintf(status_line, sizeof(status_line), "On The Phone");
|
2011-10-24 18:54:22 -05:00
|
|
|
}
|
2011-10-21 20:00:34 -05:00
|
|
|
|
2011-10-24 18:54:22 -05:00
|
|
|
rpid = "on-the-phone";
|
|
|
|
force_status = 1;
|
2012-02-22 19:27:02 -06:00
|
|
|
} else if (!strcmp(astate, "terminated") || !strcmp(astate, "hangup")) {
|
2012-01-11 21:32:23 -06:00
|
|
|
rpid = "online";
|
|
|
|
dialog_rpid = "";
|
|
|
|
force_event_status = "Available";
|
|
|
|
term = 1;
|
2011-10-24 18:54:22 -05:00
|
|
|
}
|
2012-01-11 21:32:23 -06:00
|
|
|
|
|
|
|
if (!term && !strcmp(status, "hold")) {
|
2011-10-24 18:54:22 -05:00
|
|
|
rpid = "on-the-phone";
|
|
|
|
if (!zstr(op)) {
|
|
|
|
switch_snprintf(status_line, sizeof(status_line), "Hold %s", op);
|
|
|
|
force_status = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-02-14 17:28:58 +00:00
|
|
|
} else {
|
|
|
|
open = "closed";
|
|
|
|
}
|
2010-08-19 12:09:21 -05:00
|
|
|
|
2010-07-29 23:39:39 -05:00
|
|
|
if (open_closed) {
|
|
|
|
open = open_closed;
|
|
|
|
}
|
|
|
|
|
|
|
|
prpid = translate_rpid(rpid);
|
2010-02-06 03:38:24 +00:00
|
|
|
|
2010-08-19 12:09:21 -05:00
|
|
|
if (!zstr(dialog_status) && !force_status) {
|
2010-07-29 23:39:39 -05:00
|
|
|
status = dialog_status;
|
|
|
|
switch_set_string(status_line, status);
|
|
|
|
}
|
2011-10-18 11:53:49 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!zstr(force_event_status)) {
|
|
|
|
switch_set_string(status_line, force_event_status);
|
|
|
|
}
|
|
|
|
|
2010-07-29 23:39:39 -05:00
|
|
|
|
|
|
|
if (!zstr(dialog_rpid)) {
|
|
|
|
prpid = rpid = dialog_rpid;
|
2010-07-27 19:47:35 -05:00
|
|
|
}
|
2011-10-21 20:00:34 -05:00
|
|
|
|
2010-07-29 23:39:39 -05:00
|
|
|
pl = gen_pidf(user_agent, clean_id, profile->url, open, rpid, prpid, status_line, &ct);
|
2007-12-18 01:12:50 +00:00
|
|
|
}
|
2010-02-06 03:38:24 +00:00
|
|
|
|
2007-12-15 00:39:53 +00:00
|
|
|
} else {
|
2008-02-14 17:28:58 +00:00
|
|
|
if (in) {
|
|
|
|
open = "open";
|
|
|
|
} else {
|
|
|
|
open = "closed";
|
|
|
|
}
|
2010-07-27 19:47:35 -05:00
|
|
|
|
2010-07-29 23:39:39 -05:00
|
|
|
if (open_closed) {
|
|
|
|
open = open_closed;
|
|
|
|
}
|
|
|
|
|
|
|
|
prpid = translate_rpid(rpid);
|
|
|
|
|
|
|
|
if (!zstr(dialog_status)) {
|
|
|
|
status = dialog_status;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!zstr(dialog_rpid)) {
|
|
|
|
prpid = rpid = dialog_rpid;
|
2010-07-27 19:47:35 -05:00
|
|
|
}
|
2010-07-29 23:39:39 -05:00
|
|
|
|
|
|
|
|
|
|
|
pl = gen_pidf(user_agent, clean_id, profile->url, open, rpid, prpid, status, &ct);
|
2007-12-15 00:39:53 +00:00
|
|
|
}
|
2010-02-06 03:38:24 +00:00
|
|
|
|
2010-11-23 13:18:50 -06:00
|
|
|
|
2011-10-24 18:54:22 -05:00
|
|
|
if (!is_dialog && helper->event && !switch_stristr("registered", status_line)){
|
2010-07-29 23:39:39 -05:00
|
|
|
const char *uuid = switch_event_get_header_nil(helper->event, "unique-id");
|
2011-10-24 18:54:22 -05:00
|
|
|
const char *register_source = switch_event_get_header_nil(helper->event, "register-source");
|
|
|
|
|
|
|
|
if (!zstr(uuid) && strchr(uuid, '-') && !zstr(status_line) && !zstr(rpid) && (zstr(register_source) || strcasecmp(register_source, "register"))) {
|
2012-01-30 11:43:43 -06:00
|
|
|
char *sql = switch_mprintf("update sip_dialogs set rpid='%q',status='%q' where hostname='%q' and profile_name='%q' and uuid='%q'",
|
|
|
|
mod_sofia_globals.hostname, profile->name,
|
|
|
|
rpid, status_line, uuid);
|
2010-07-29 23:39:39 -05:00
|
|
|
sofia_glue_execute_sql(profile, &sql, SWITCH_TRUE);
|
|
|
|
}
|
|
|
|
}
|
2010-11-23 13:18:50 -06:00
|
|
|
|
2011-12-15 16:30:33 -06:00
|
|
|
send_presence_notify(profile, full_to, full_from, contact, expires, call_id, event, ip, port, ct, pl, NULL);
|
2010-02-06 03:38:24 +00:00
|
|
|
|
2012-02-10 15:14:26 -06:00
|
|
|
|
|
|
|
end:
|
|
|
|
|
2010-10-18 15:30:11 -05:00
|
|
|
switch_safe_free(free_me);
|
|
|
|
|
2008-09-18 00:01:03 +00:00
|
|
|
if (ext_profile) {
|
|
|
|
sofia_glue_release_profile(ext_profile);
|
|
|
|
}
|
2007-12-18 01:12:50 +00:00
|
|
|
|
2007-03-31 19:01:33 +00:00
|
|
|
switch_safe_free(id);
|
2007-12-15 18:26:10 +00:00
|
|
|
switch_safe_free(clean_id);
|
2007-03-31 19:01:33 +00:00
|
|
|
switch_safe_free(pl);
|
|
|
|
switch_safe_free(to);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-04-02 19:54:25 +00:00
|
|
|
static int sofia_presence_mwi_callback(void *pArg, int argc, char **argv, char **columnNames)
|
|
|
|
{
|
2011-12-15 16:30:33 -06:00
|
|
|
//char *sub_to_user = argv[3];
|
|
|
|
//char *sub_to_host = argv[4];
|
2007-04-02 19:54:25 +00:00
|
|
|
char *event = argv[5];
|
2011-12-15 16:30:33 -06:00
|
|
|
char *contact = argv[6];
|
2007-04-02 19:54:25 +00:00
|
|
|
char *call_id = argv[7];
|
2011-12-15 16:30:33 -06:00
|
|
|
char *full_from = argv[8];
|
2007-04-02 19:54:25 +00:00
|
|
|
char *expires = argv[10];
|
2008-09-18 00:01:03 +00:00
|
|
|
char *profile_name = argv[13];
|
2009-06-09 14:13:32 +00:00
|
|
|
char *body = argv[15];
|
2011-12-15 16:30:33 -06:00
|
|
|
char *full_to = argv[16];
|
|
|
|
char *remote_ip = argv[17];
|
|
|
|
char *remote_port = argv[18];
|
|
|
|
|
2008-05-08 16:09:49 +00:00
|
|
|
struct mwi_helper *h = (struct mwi_helper *) pArg;
|
2008-09-18 00:01:03 +00:00
|
|
|
sofia_profile_t *ext_profile = NULL, *profile = h->profile;
|
2008-05-27 04:54:52 +00:00
|
|
|
|
2012-01-26 04:46:48 -06:00
|
|
|
|
|
|
|
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]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-18 00:01:03 +00:00
|
|
|
if (profile_name && strcasecmp(profile_name, h->profile->name)) {
|
|
|
|
if ((ext_profile = sofia_glue_find_profile(profile_name))) {
|
|
|
|
profile = ext_profile;
|
|
|
|
}
|
|
|
|
}
|
2010-02-06 03:38:24 +00:00
|
|
|
|
2011-12-15 16:30:33 -06:00
|
|
|
send_presence_notify(profile,
|
|
|
|
full_to,
|
|
|
|
full_from,
|
|
|
|
contact,
|
|
|
|
expires,
|
|
|
|
call_id,
|
|
|
|
event,
|
|
|
|
remote_ip,
|
|
|
|
remote_port,
|
|
|
|
"application/simple-message-summary",
|
|
|
|
body,
|
|
|
|
NULL
|
|
|
|
);
|
2008-05-27 04:54:52 +00:00
|
|
|
|
2007-04-29 01:16:49 +00:00
|
|
|
|
2008-05-08 16:09:49 +00:00
|
|
|
h->total++;
|
2008-09-18 00:01:03 +00:00
|
|
|
|
|
|
|
if (ext_profile) {
|
|
|
|
sofia_glue_release_profile(ext_profile);
|
|
|
|
}
|
|
|
|
|
2007-12-13 23:30:16 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int sofia_presence_mwi_callback2(void *pArg, int argc, char **argv, char **columnNames)
|
|
|
|
{
|
2009-08-21 00:59:09 +00:00
|
|
|
const char *user = argv[0];
|
|
|
|
const char *host = argv[1];
|
|
|
|
const char *event = "message-summary";
|
|
|
|
const char *contenttype = "application/simple-message-summary";
|
|
|
|
const char *body = argv[5];
|
|
|
|
const char *o_contact = argv[2];
|
|
|
|
const char *network_ip = argv[4];
|
|
|
|
|
2008-09-18 00:01:03 +00:00
|
|
|
char *profile_name = argv[3];
|
2008-05-08 16:09:49 +00:00
|
|
|
struct mwi_helper *h = (struct mwi_helper *) pArg;
|
2008-09-18 00:01:03 +00:00
|
|
|
sofia_profile_t *ext_profile = NULL, *profile = h->profile;
|
2008-05-27 04:54:52 +00:00
|
|
|
|
2008-09-18 00:01:03 +00:00
|
|
|
if (profile_name && strcasecmp(profile_name, h->profile->name)) {
|
|
|
|
if ((ext_profile = sofia_glue_find_profile(profile_name))) {
|
|
|
|
profile = ext_profile;
|
|
|
|
}
|
|
|
|
}
|
2008-05-27 04:54:52 +00:00
|
|
|
|
2011-08-19 17:29:42 -05:00
|
|
|
sofia_glue_send_notify(profile, user, host, event, contenttype, body, o_contact, network_ip);
|
2009-06-03 21:08:34 +00:00
|
|
|
|
2008-09-18 00:01:03 +00:00
|
|
|
if (ext_profile) {
|
|
|
|
sofia_glue_release_profile(ext_profile);
|
|
|
|
}
|
|
|
|
|
2007-04-02 19:54:25 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-01-07 06:09:35 +00:00
|
|
|
static int broadsoft_sla_notify_callback(void *pArg, int argc, char **argv, char **columnNames)
|
2009-12-24 05:44:23 +00:00
|
|
|
{
|
2010-01-07 06:09:35 +00:00
|
|
|
struct state_helper *sh = (struct state_helper *) pArg;
|
|
|
|
char key[256] = "";
|
|
|
|
char *data = NULL, *tmp;
|
2009-12-24 05:44:23 +00:00
|
|
|
char *call_id = argv[0];
|
2011-12-15 16:30:33 -06:00
|
|
|
//char *expires = argv[1];
|
2010-01-07 06:09:35 +00:00
|
|
|
char *user = argv[2];
|
|
|
|
char *host = argv[3];
|
|
|
|
char *event = argv[4];
|
|
|
|
int i;
|
2009-12-24 05:44:23 +00:00
|
|
|
|
2012-01-26 04:46:48 -06:00
|
|
|
|
2010-01-07 06:09:35 +00:00
|
|
|
if (mod_sofia_globals.debug_sla > 1) {
|
2010-02-06 03:38:24 +00:00
|
|
|
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]);
|
2009-12-24 05:44:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-07 06:09:35 +00:00
|
|
|
switch_snprintf(key, sizeof(key), "%s%s", user, host);
|
|
|
|
data = switch_core_hash_find(sh->hash, key);
|
2011-12-15 16:30:33 -06:00
|
|
|
|
2009-12-24 05:44:23 +00:00
|
|
|
|
2010-01-07 06:09:35 +00:00
|
|
|
data = switch_core_hash_find(sh->hash, key);
|
2009-12-24 05:44:23 +00:00
|
|
|
|
2010-01-07 06:09:35 +00:00
|
|
|
if (data) {
|
|
|
|
tmp = switch_core_sprintf(sh->pool, "%s,<sip:%s>;appearance-index=*;appearance-state=idle", data, host);
|
|
|
|
} else {
|
|
|
|
tmp = switch_core_sprintf(sh->pool, "<sip:%s>;appearance-index=*;appearance-state=idle", host);
|
2009-12-24 05:44:23 +00:00
|
|
|
}
|
2010-02-06 03:38:24 +00:00
|
|
|
|
2011-12-15 16:30:33 -06:00
|
|
|
|
|
|
|
if (!strcasecmp(event, "line-seize")) {
|
2010-01-07 06:09:35 +00:00
|
|
|
char *hack;
|
2009-12-24 05:44:23 +00:00
|
|
|
|
2010-02-06 03:38:24 +00:00
|
|
|
if ((hack = (char *) switch_stristr("=seized", tmp))) {
|
2010-01-07 06:09:35 +00:00
|
|
|
switch_snprintf(hack, 7, "=idle ");
|
|
|
|
}
|
2009-12-24 05:44:23 +00:00
|
|
|
}
|
2010-02-06 03:38:24 +00:00
|
|
|
|
2011-12-15 16:30:33 -06:00
|
|
|
if (mod_sofia_globals.debug_sla > 1) {
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "DB PRES NOTIFY: [%s]\n[%s]\n[%s]\n[%s]\n[%s]\n[%s]\n[%s]\n[%s]\n[%s]\n",
|
|
|
|
argv[5], argv[6], argv[7], argv[8], call_id, event, argv[9], argv[10], tmp);
|
|
|
|
|
2009-12-24 05:44:23 +00:00
|
|
|
}
|
2011-12-15 16:30:33 -06:00
|
|
|
|
|
|
|
send_presence_notify(sh->profile, argv[5], argv[6], argv[7], argv[8], call_id, event, argv[9], argv[10], NULL, NULL, tmp);
|
2012-01-26 04:46:48 -06:00
|
|
|
|
|
|
|
sh->total++;
|
2011-12-15 16:30:33 -06:00
|
|
|
|
2010-01-07 06:09:35 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int broadsoft_sla_gather_state_callback(void *pArg, int argc, char **argv, char **columnNames)
|
|
|
|
{
|
|
|
|
struct state_helper *sh = (struct state_helper *) pArg;
|
|
|
|
char key[256] = "";
|
2010-03-19 23:40:30 +00:00
|
|
|
switch_core_session_t *session;
|
|
|
|
const char *callee_name = NULL, *callee_number = NULL;
|
2010-01-07 06:09:35 +00:00
|
|
|
char *data = NULL, *tmp;
|
|
|
|
char *user = argv[0];
|
|
|
|
char *host = argv[1];
|
|
|
|
char *info = argv[2];
|
|
|
|
char *state = argv[3];
|
2010-03-19 23:40:30 +00:00
|
|
|
char *uuid = argv[4];
|
2010-01-07 06:09:35 +00:00
|
|
|
int i;
|
2009-12-24 05:44:23 +00:00
|
|
|
|
2010-01-07 06:09:35 +00:00
|
|
|
if (mod_sofia_globals.debug_sla > 1) {
|
2010-02-06 03:38:24 +00:00
|
|
|
for (i = 0; i < argc; i++) {
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "SLA2: %d [%s]=[%s]\n", i, columnNames[i], argv[i]);
|
2009-12-24 05:44:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-07 06:09:35 +00:00
|
|
|
if (zstr(info)) {
|
|
|
|
return 0;
|
|
|
|
}
|
2009-12-24 05:44:23 +00:00
|
|
|
|
2010-01-07 06:09:35 +00:00
|
|
|
if (zstr(state)) {
|
|
|
|
state = "idle";
|
2009-12-24 05:44:23 +00:00
|
|
|
}
|
2010-01-07 06:09:35 +00:00
|
|
|
|
|
|
|
switch_snprintf(key, sizeof(key), "%s%s", user, host);
|
2010-02-06 03:38:24 +00:00
|
|
|
|
2010-01-07 06:09:35 +00:00
|
|
|
data = switch_core_hash_find(sh->hash, key);
|
2010-02-06 03:38:24 +00:00
|
|
|
|
2010-03-19 23:40:30 +00:00
|
|
|
if (uuid && (session = switch_core_session_locate(uuid))) {
|
|
|
|
switch_channel_t *channel = switch_core_session_get_channel(session);
|
|
|
|
|
2011-09-01 15:10:23 -05:00
|
|
|
if (switch_channel_direction(channel) == SWITCH_CALL_DIRECTION_INBOUND) {
|
|
|
|
|
|
|
|
if (zstr((callee_name = switch_channel_get_variable(channel, "effective_callee_id_name"))) &&
|
|
|
|
zstr((callee_name = switch_channel_get_variable(channel, "sip_callee_id_name")))) {
|
|
|
|
callee_name = switch_channel_get_variable(channel, "callee_id_name");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (zstr((callee_number = switch_channel_get_variable(channel, "effective_callee_id_number"))) &&
|
|
|
|
zstr((callee_number = switch_channel_get_variable(channel, "sip_callee_id_number"))) &&
|
|
|
|
zstr((callee_number = switch_channel_get_variable(channel, "callee_id_number")))) {
|
|
|
|
callee_number = switch_channel_get_variable(channel, "destination_number");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
callee_name = switch_channel_get_variable(channel, "caller_id_name");
|
|
|
|
callee_number = switch_channel_get_variable(channel, "caller_id_number");
|
2010-03-19 23:40:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (zstr(callee_name) && !zstr(callee_number)) {
|
|
|
|
callee_name = callee_number;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!zstr(callee_number)) {
|
|
|
|
callee_number = switch_sanitize_number(switch_core_session_strdup(session, callee_number));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!zstr(callee_name)) {
|
|
|
|
callee_name = switch_sanitize_number(switch_core_session_strdup(session, callee_name));
|
|
|
|
}
|
|
|
|
switch_core_session_rwunlock(session);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!zstr(callee_number)) {
|
|
|
|
if (zstr(callee_name)) {
|
|
|
|
callee_name = "unknown";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (data) {
|
|
|
|
tmp = switch_core_sprintf(sh->pool,
|
|
|
|
"%s,<sip:%s>;%s;appearance-state=%s;appearance-uri=\"\\\"%s\\\" <sip:%s@%s>\"",
|
|
|
|
data, host, info, state, callee_name, callee_number, host);
|
|
|
|
} else {
|
|
|
|
tmp = switch_core_sprintf(sh->pool,
|
|
|
|
"<sip:%s>;%s;appearance-state=%s;appearance-uri=\"\\\"%s\\\" <sip:%s@%s>\"",
|
|
|
|
host, info, state, callee_name, callee_number, host);
|
|
|
|
}
|
2010-01-07 06:09:35 +00:00
|
|
|
} else {
|
2010-03-19 23:40:30 +00:00
|
|
|
if (data) {
|
|
|
|
tmp = switch_core_sprintf(sh->pool, "%s,<sip:%s>;%s;appearance-state=%s", data, host, info, state);
|
|
|
|
} else {
|
|
|
|
tmp = switch_core_sprintf(sh->pool, "<sip:%s>;%s;appearance-state=%s", host, info, state);
|
|
|
|
}
|
2010-01-07 06:09:35 +00:00
|
|
|
}
|
2009-12-24 05:44:23 +00:00
|
|
|
|
2010-01-07 06:09:35 +00:00
|
|
|
switch_core_hash_insert(sh->hash, key, tmp);
|
2010-02-06 03:38:24 +00:00
|
|
|
|
2009-12-24 05:44:23 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-01-26 04:46:48 -06:00
|
|
|
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)
|
2010-01-07 06:09:35 +00:00
|
|
|
{
|
|
|
|
struct state_helper *sh;
|
|
|
|
switch_memory_pool_t *pool;
|
|
|
|
char *sql;
|
2012-01-26 04:46:48 -06:00
|
|
|
int total = 0;
|
2010-01-07 06:09:35 +00:00
|
|
|
|
|
|
|
switch_core_new_memory_pool(&pool);
|
|
|
|
sh = switch_core_alloc(pool, sizeof(*sh));
|
|
|
|
sh->pool = pool;
|
|
|
|
switch_core_hash_init(&sh->hash, sh->pool);
|
2010-02-06 03:38:24 +00:00
|
|
|
|
2010-03-19 23:40:30 +00:00
|
|
|
sql = switch_mprintf("select sip_from_user,sip_from_host,call_info,call_info_state,uuid from sip_dialogs "
|
2012-01-30 11:43:43 -06:00
|
|
|
"where call_info_state is not null and hostname='%q' and profile_name='%q' "
|
|
|
|
"and ((sip_from_user='%q' and sip_from_host='%q') or presence_id='%q@%q') "
|
2012-01-26 04:46:48 -06:00
|
|
|
"and profile_name='%q'",
|
2012-01-30 11:43:43 -06:00
|
|
|
mod_sofia_globals.hostname, profile->name, to_user, to_host, to_user, to_host, profile->name);
|
2010-01-07 06:09:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
if (mod_sofia_globals.debug_sla > 1) {
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "PRES SQL %s\n", sql);
|
|
|
|
}
|
|
|
|
sofia_glue_execute_sql_callback(profile, profile->ireg_mutex, sql, broadsoft_sla_gather_state_callback, sh);
|
|
|
|
switch_safe_free(sql);
|
|
|
|
|
2010-02-06 03:38:24 +00:00
|
|
|
|
2012-01-26 04:46:48 -06:00
|
|
|
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 "
|
2012-01-30 11:43:43 -06:00
|
|
|
"from sip_subscriptions where call_id='%q' and hostname='%q' and profile_name='%q')",
|
2012-02-15 11:48:12 -06:00
|
|
|
call_id, mod_sofia_globals.hostname, profile->name);
|
2012-01-26 04:46:48 -06:00
|
|
|
|
|
|
|
} 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 "
|
2012-01-30 11:43:43 -06:00
|
|
|
"from sip_subscriptions where call_id='%q' and hostname='%q' and profile_name='%q'",
|
2012-02-15 11:48:12 -06:00
|
|
|
call_id, mod_sofia_globals.hostname, profile->name);
|
2012-01-26 04:46:48 -06:00
|
|
|
}
|
|
|
|
|
2010-01-07 06:09:35 +00:00
|
|
|
} else {
|
|
|
|
|
2012-01-26 04:46:48 -06:00
|
|
|
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 "
|
2012-01-30 11:43:43 -06:00
|
|
|
"where hostname='%q' and profile_name='%q' "
|
2012-01-26 04:46:48 -06:00
|
|
|
"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%%')",
|
2012-01-30 11:43:43 -06:00
|
|
|
mod_sofia_globals.hostname, profile->name, to_user, to_host, profile->name, to_host);
|
2012-01-26 04:46:48 -06:00
|
|
|
} 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 "
|
2012-01-30 11:43:43 -06:00
|
|
|
"where hostname='%q' and profile_name='%q' "
|
2012-01-26 04:46:48 -06:00
|
|
|
"and sub_to_user='%q' and sub_to_host='%q' " "and (event='call-info') and "
|
|
|
|
"(profile_name='%q' or presence_hosts like '%%%q%%')",
|
2012-01-30 11:43:43 -06:00
|
|
|
mod_sofia_globals.hostname, profile->name, to_user, to_host, profile->name, to_host);
|
2012-01-26 04:46:48 -06:00
|
|
|
}
|
|
|
|
}
|
2010-01-07 06:09:35 +00:00
|
|
|
|
|
|
|
if (mod_sofia_globals.debug_sla > 1) {
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "PRES SQL %s\n", sql);
|
|
|
|
}
|
2012-01-26 04:46:48 -06:00
|
|
|
|
2010-01-07 06:09:35 +00:00
|
|
|
sh->profile = profile;
|
|
|
|
sofia_glue_execute_sql_callback(profile, profile->ireg_mutex, sql, broadsoft_sla_notify_callback, sh);
|
|
|
|
switch_safe_free(sql);
|
2012-01-26 04:46:48 -06:00
|
|
|
total = sh->total;
|
2010-01-07 06:09:35 +00:00
|
|
|
sh = NULL;
|
|
|
|
switch_core_destroy_memory_pool(&pool);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (clear) {
|
2012-01-30 11:43:43 -06:00
|
|
|
sql = switch_mprintf("delete from sip_dialogs where hostname='%q' and profile_name='%q' and "
|
|
|
|
"((sip_from_user='%q' and sip_from_host='%q') or presence_id='%q@%q') "
|
|
|
|
"and call_info_state='seized'", mod_sofia_globals.hostname, profile->name, to_user, to_host, to_user, to_host);
|
2010-01-07 06:09:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
if (mod_sofia_globals.debug_sla > 1) {
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "CLEAR SQL %s\n", sql);
|
|
|
|
}
|
2010-01-09 00:34:17 +00:00
|
|
|
sofia_glue_execute_sql_now(profile, &sql, SWITCH_TRUE);
|
2010-01-07 06:09:35 +00:00
|
|
|
}
|
|
|
|
|
2012-01-26 04:46:48 -06:00
|
|
|
return total;
|
|
|
|
|
2010-01-07 06:09:35 +00:00
|
|
|
}
|
|
|
|
|
2007-03-31 19:01:33 +00:00
|
|
|
void sofia_presence_handle_sip_i_subscribe(int status,
|
2008-05-27 04:54:52 +00:00
|
|
|
char const *phrase,
|
|
|
|
nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sofia_private_t *sofia_private, sip_t const *sip,
|
2012-01-26 04:46:48 -06:00
|
|
|
sofia_dispatch_event_t *de,
|
2008-05-27 04:54:52 +00:00
|
|
|
tagi_t tags[])
|
2007-03-31 19:01:33 +00:00
|
|
|
{
|
2008-05-21 21:49:27 +00:00
|
|
|
|
2011-12-15 16:30:33 -06:00
|
|
|
long exp_delta = 0;
|
2010-12-30 11:38:23 -06:00
|
|
|
char exp_delta_str[30] = "";
|
|
|
|
sip_to_t const *to;
|
|
|
|
const char *from_user = NULL, *from_host = NULL;
|
|
|
|
const char *to_user = NULL, *to_host = NULL;
|
|
|
|
char *my_to_user = NULL;
|
|
|
|
char *sql, *event = NULL;
|
|
|
|
char *proto = "sip";
|
2011-10-24 09:49:34 -05:00
|
|
|
char *orig_proto = "";
|
2011-10-22 09:40:59 -05:00
|
|
|
char *alt_proto = NULL;
|
2010-12-30 11:38:23 -06:00
|
|
|
char *d_user = NULL;
|
|
|
|
char *contact_str = "";
|
|
|
|
const char *call_id = NULL;
|
|
|
|
char *to_str = NULL;
|
|
|
|
char *full_from = NULL;
|
2011-12-15 16:30:33 -06:00
|
|
|
char *full_to = NULL;
|
2010-12-30 11:38:23 -06:00
|
|
|
char *full_via = NULL;
|
|
|
|
char *full_agent = NULL;
|
|
|
|
char *sstr;
|
|
|
|
switch_event_t *sevent;
|
2012-01-17 16:08:25 -06:00
|
|
|
int sub_state = nua_substate_pending;
|
2010-12-30 11:38:23 -06:00
|
|
|
int sent_reply = 0;
|
|
|
|
sip_contact_t const *contact;
|
|
|
|
const char *ipv6;
|
2011-04-22 16:43:29 -05:00
|
|
|
const char *contact_user;
|
2010-12-30 11:38:23 -06:00
|
|
|
sofia_nat_parse_t np = { { 0 } };
|
2011-10-22 09:40:59 -05:00
|
|
|
int found_proto = 0;
|
2011-12-15 16:30:33 -06:00
|
|
|
char to_tag[13] = "";
|
2012-01-17 16:08:25 -06:00
|
|
|
char buf[32] = "";
|
|
|
|
int subbed = 0;
|
2009-06-03 21:08:34 +00:00
|
|
|
|
2010-12-30 11:38:23 -06:00
|
|
|
if (!sip) {
|
|
|
|
return;
|
|
|
|
}
|
2007-10-24 23:20:47 +00:00
|
|
|
|
2010-12-30 11:38:23 -06:00
|
|
|
to = sip->sip_to;
|
|
|
|
contact = sip->sip_contact;
|
2007-10-24 23:20:47 +00:00
|
|
|
|
2012-01-26 04:46:48 -06:00
|
|
|
np.fs_path = 1;
|
|
|
|
if (!(contact_str = sofia_glue_gen_contact_str(profile, sip, nh, de, &np))) {
|
2010-12-30 11:38:23 -06:00
|
|
|
nua_respond(nh, 481, "INVALID SUBSCRIPTION", TAG_END());
|
|
|
|
return;
|
|
|
|
}
|
2007-12-15 00:39:53 +00:00
|
|
|
|
2011-12-15 16:30:33 -06:00
|
|
|
switch_stun_random_string(to_tag, 12, NULL);
|
|
|
|
|
2011-04-22 16:43:29 -05:00
|
|
|
//contact_host = sip->sip_contact->m_url->url_host;
|
2010-12-30 11:38:23 -06:00
|
|
|
contact_user = sip->sip_contact->m_url->url_user;
|
2008-05-27 04:54:52 +00:00
|
|
|
|
2012-01-17 16:08:25 -06:00
|
|
|
//tl_gets(tags, NUTAG_SUBSTATE_REF(sub_state), TAG_END());
|
|
|
|
|
|
|
|
//sip->sip_subscription_state->ss_substate
|
|
|
|
|
|
|
|
if (sip->sip_subscription_state && sip->sip_subscription_state->ss_substate) {
|
|
|
|
if (switch_stristr("terminated", sip->sip_subscription_state->ss_substate)) {
|
|
|
|
sub_state = nua_substate_terminated;
|
|
|
|
} else if (switch_stristr("active", sip->sip_subscription_state->ss_substate)) {
|
|
|
|
sub_state = nua_substate_active;
|
|
|
|
}
|
|
|
|
}
|
2007-03-31 19:01:33 +00:00
|
|
|
|
2011-06-16 14:37:22 -05:00
|
|
|
event = sip_header_as_string(nh->nh_home, (void *) sip->sip_event);
|
2008-05-27 04:54:52 +00:00
|
|
|
|
2010-12-30 11:38:23 -06:00
|
|
|
if (to) {
|
|
|
|
to_str = switch_mprintf("sip:%s@%s", to->a_url->url_user, to->a_url->url_host);
|
|
|
|
}
|
2010-04-27 13:56:37 -05:00
|
|
|
|
2010-12-30 11:38:23 -06:00
|
|
|
if (to) {
|
|
|
|
to_user = to->a_url->url_user;
|
|
|
|
to_host = to->a_url->url_host;
|
|
|
|
}
|
2008-05-27 04:54:52 +00:00
|
|
|
|
2010-12-30 11:38:23 -06:00
|
|
|
if (profile->sub_domain) {
|
|
|
|
to_host = profile->sub_domain;
|
|
|
|
}
|
2008-05-27 04:54:52 +00:00
|
|
|
|
2010-12-30 11:38:23 -06:00
|
|
|
if (sip->sip_from) {
|
|
|
|
from_user = sip->sip_from->a_url->url_user;
|
|
|
|
from_host = sip->sip_from->a_url->url_host;
|
|
|
|
} else {
|
|
|
|
from_user = "n/a";
|
|
|
|
from_host = "n/a";
|
|
|
|
}
|
2008-05-27 04:54:52 +00:00
|
|
|
|
2010-12-30 11:38:23 -06:00
|
|
|
if ((exp_delta = sip->sip_expires ? sip->sip_expires->ex_delta : 3600)) {
|
2011-11-10 07:38:47 -06:00
|
|
|
if ((profile->force_subscription_expires > 0) && (profile->force_subscription_expires < (uint32_t)exp_delta)) {
|
2010-12-30 11:38:23 -06:00
|
|
|
exp_delta = profile->force_subscription_expires;
|
2009-12-24 05:44:23 +00:00
|
|
|
}
|
2010-12-30 11:38:23 -06:00
|
|
|
}
|
2009-12-24 05:44:23 +00:00
|
|
|
|
2012-01-17 16:08:25 -06:00
|
|
|
if (mod_sofia_globals.debug_presence > 0 || mod_sofia_globals.debug_sla > 0) {
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "DELTA %ld\n", exp_delta);
|
|
|
|
}
|
|
|
|
|
2011-04-22 16:43:29 -05:00
|
|
|
if (!exp_delta) {
|
2010-12-30 11:38:23 -06:00
|
|
|
sub_state = nua_substate_terminated;
|
|
|
|
}
|
2010-09-21 14:31:36 -05:00
|
|
|
|
2010-12-30 11:38:23 -06:00
|
|
|
switch_snprintf(exp_delta_str, sizeof(exp_delta_str), "%ld", exp_delta);
|
2008-05-21 21:49:27 +00:00
|
|
|
|
2010-12-30 11:38:23 -06:00
|
|
|
if (to_user && strchr(to_user, '+')) {
|
|
|
|
char *h;
|
|
|
|
if ((proto = (d_user = strdup(to_user)))) {
|
|
|
|
if ((my_to_user = strchr(d_user, '+'))) {
|
|
|
|
*my_to_user++ = '\0';
|
|
|
|
to_user = my_to_user;
|
|
|
|
if ((h = strchr(to_user, '+')) || (h = strchr(to_user, '@'))) {
|
|
|
|
*h++ = '\0';
|
|
|
|
to_host = h;
|
|
|
|
}
|
|
|
|
}
|
2010-09-21 14:31:36 -05:00
|
|
|
}
|
2008-05-21 21:49:27 +00:00
|
|
|
|
2010-12-30 11:38:23 -06:00
|
|
|
if (!(proto && to_user && to_host)) {
|
2011-06-16 14:37:22 -05:00
|
|
|
nua_respond(nh, SIP_404_NOT_FOUND, NUTAG_WITH_THIS_MSG(de->data->e_msg), TAG_END());
|
2010-12-30 11:38:23 -06:00
|
|
|
goto end;
|
2008-05-21 21:49:27 +00:00
|
|
|
}
|
2011-10-22 09:40:59 -05:00
|
|
|
|
|
|
|
found_proto++;
|
2010-12-30 11:38:23 -06:00
|
|
|
}
|
2008-05-27 04:54:52 +00:00
|
|
|
|
2010-12-30 11:38:23 -06:00
|
|
|
call_id = sip->sip_call_id->i_id;
|
2011-06-16 14:37:22 -05:00
|
|
|
full_from = sip_header_as_string(nh->nh_home, (void *) sip->sip_from);
|
2011-12-15 16:30:33 -06:00
|
|
|
full_to = sip_header_as_string(nh->nh_home, (void *) sip->sip_to);
|
2011-06-16 14:37:22 -05:00
|
|
|
full_via = sip_header_as_string(nh->nh_home, (void *) sip->sip_via);
|
2008-05-27 04:54:52 +00:00
|
|
|
|
2011-12-15 16:30:33 -06:00
|
|
|
|
2010-12-30 11:38:23 -06:00
|
|
|
if (sip->sip_expires && sip->sip_expires->ex_delta > 31536000) {
|
|
|
|
sip->sip_expires->ex_delta = 31536000;
|
|
|
|
}
|
2009-02-01 00:06:46 +00:00
|
|
|
|
2011-10-22 09:40:59 -05:00
|
|
|
if (sofia_test_pflag(profile, PFLAG_PRESENCE_MAP) && !found_proto && (alt_proto = switch_ivr_check_presence_mapping(to_user, to_host))) {
|
2011-10-24 09:49:34 -05:00
|
|
|
orig_proto = proto;
|
2011-10-22 09:40:59 -05:00
|
|
|
proto = alt_proto;
|
|
|
|
}
|
2011-05-20 11:51:01 -05:00
|
|
|
|
2012-01-18 11:35:43 -06:00
|
|
|
if ((sub_state != nua_substate_terminated)) {
|
2012-01-30 11:43:43 -06:00
|
|
|
sql = switch_mprintf("select count(*) from sip_subscriptions where call_id='%q' and hostname='%q' and profile_name='%q'",
|
|
|
|
call_id, mod_sofia_globals.hostname, profile->name);
|
2012-01-18 11:35:43 -06:00
|
|
|
sofia_glue_execute_sql2str(profile, profile->ireg_mutex, sql, buf, sizeof(buf));
|
2012-01-19 11:38:15 -06:00
|
|
|
|
2012-01-17 16:08:25 -06:00
|
|
|
|
2012-01-18 11:35:43 -06:00
|
|
|
if (mod_sofia_globals.debug_presence > 0 || mod_sofia_globals.debug_sla > 0) {
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
|
|
|
|
"check subs sql: %s [%s]\n", sql, buf);
|
|
|
|
}
|
2012-01-17 16:08:25 -06:00
|
|
|
|
2012-01-19 11:38:15 -06:00
|
|
|
switch_safe_free(sql);
|
|
|
|
|
2012-01-18 11:35:43 -06:00
|
|
|
if ((subbed = atoi(buf)) > 0) {
|
|
|
|
sub_state = nua_substate_active;
|
|
|
|
}
|
2012-01-17 16:08:25 -06:00
|
|
|
}
|
|
|
|
|
2012-01-26 16:54:27 -06:00
|
|
|
if (sub_state == nua_substate_active) {
|
2011-05-20 11:51:01 -05:00
|
|
|
|
|
|
|
sstr = switch_mprintf("active;expires=%ld", exp_delta);
|
|
|
|
|
|
|
|
sql = switch_mprintf("update sip_subscriptions "
|
2012-01-26 15:53:05 -06:00
|
|
|
"set expires=%ld,contact='%q' "
|
2012-01-30 11:43:43 -06:00
|
|
|
"where hostname='%q' and profile_name='%q' and call_id='%q' and profile_name='%q'",
|
|
|
|
(long) switch_epoch_time_now(NULL) + exp_delta, contact_str, mod_sofia_globals.hostname, profile->name,
|
|
|
|
call_id, profile->name);
|
2009-02-01 00:06:46 +00:00
|
|
|
|
2011-05-20 11:51:01 -05:00
|
|
|
if (mod_sofia_globals.debug_presence > 0 || mod_sofia_globals.debug_sla > 0) {
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
|
2012-01-03 11:40:52 -06:00
|
|
|
"re-subscribe event %s, sql: %s\n", event, sql);
|
2011-05-20 11:51:01 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
sofia_glue_execute_sql_now(profile, &sql, SWITCH_TRUE);
|
2010-12-30 11:38:23 -06:00
|
|
|
} else {
|
2012-01-03 11:40:52 -06:00
|
|
|
|
2011-05-20 11:51:01 -05:00
|
|
|
if (sub_state == nua_substate_terminated) {
|
2012-01-30 11:43:43 -06:00
|
|
|
sql = switch_mprintf("delete from sip_subscriptions where call_id='%q' and profile_name='%q' and hostname='%q'",
|
|
|
|
call_id, profile->name, mod_sofia_globals.hostname);
|
2012-01-26 04:46:48 -06:00
|
|
|
|
|
|
|
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");
|
2011-05-20 11:51:01 -05:00
|
|
|
} else {
|
|
|
|
sip_accept_t *ap = sip->sip_accept;
|
|
|
|
char accept[256] = "";
|
2012-01-17 16:08:25 -06:00
|
|
|
|
|
|
|
sub_state = nua_substate_active;
|
2011-12-15 16:30:33 -06:00
|
|
|
|
2011-06-16 14:37:22 -05:00
|
|
|
full_agent = sip_header_as_string(nh->nh_home, (void *) sip->sip_user_agent);
|
2011-05-20 11:51:01 -05:00
|
|
|
while (ap) {
|
|
|
|
switch_snprintf(accept + strlen(accept), sizeof(accept) - strlen(accept), "%s%s ", ap->ac_type, ap->ac_next ? "," : "");
|
|
|
|
ap = ap->ac_next;
|
|
|
|
}
|
2012-01-17 16:08:25 -06:00
|
|
|
|
2011-05-20 11:51:01 -05:00
|
|
|
sql = switch_mprintf("insert into sip_subscriptions "
|
|
|
|
"(proto,sip_user,sip_host,sub_to_user,sub_to_host,presence_hosts,event,contact,call_id,full_from,"
|
2012-01-26 15:53:05 -06:00
|
|
|
"full_via,expires,user_agent,accept,profile_name,hostname,network_port,network_ip,version,orig_proto, full_to) "
|
|
|
|
"values ('%q','%q','%q','%q','%q','%q','%q','%q','%q','%q','%q',%ld,'%q','%q','%q','%q','%d','%q',-1,'%q','%q;tag=%q')",
|
2012-01-26 04:46:48 -06:00
|
|
|
proto, from_user, from_host, to_user, to_host, profile->presence_hosts ? profile->presence_hosts : "",
|
2011-05-20 11:51:01 -05:00
|
|
|
event, contact_str, call_id, full_from, full_via,
|
2011-11-10 07:38:47 -06:00
|
|
|
(long) switch_epoch_time_now(NULL) + exp_delta,
|
2011-12-15 16:30:33 -06:00
|
|
|
full_agent, accept, profile->name, mod_sofia_globals.hostname,
|
|
|
|
np.network_port, np.network_ip, orig_proto, full_to, to_tag);
|
2011-05-20 11:51:01 -05:00
|
|
|
|
|
|
|
switch_assert(sql != NULL);
|
2012-02-09 16:47:32 -06:00
|
|
|
|
2012-01-17 16:08:25 -06:00
|
|
|
|
2011-05-20 11:51:01 -05:00
|
|
|
if (mod_sofia_globals.debug_presence > 0 || mod_sofia_globals.debug_sla > 0) {
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "%s SUBSCRIBE %s@%s %s@%s\n%s\n",
|
|
|
|
profile->name, from_user, from_host, to_user, to_host, sql);
|
|
|
|
}
|
2009-09-24 22:27:19 +00:00
|
|
|
|
2011-05-20 11:51:01 -05:00
|
|
|
|
|
|
|
sofia_glue_execute_sql_now(profile, &sql, SWITCH_TRUE);
|
|
|
|
sstr = switch_mprintf("active;expires=%ld", exp_delta);
|
2011-12-15 16:30:33 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
switch_mutex_unlock(profile->ireg_mutex);
|
2011-05-20 11:51:01 -05:00
|
|
|
}
|
2010-12-30 11:38:23 -06:00
|
|
|
|
|
|
|
if (status < 200) {
|
|
|
|
char *sticky = NULL;
|
|
|
|
char *contactstr = profile->url, *cs = NULL;
|
|
|
|
char *p = NULL, *new_contactstr = NULL;
|
2011-12-15 16:30:33 -06:00
|
|
|
|
2010-12-30 11:38:23 -06:00
|
|
|
|
|
|
|
if (np.is_nat) {
|
|
|
|
char params[128] = "";
|
|
|
|
if (contact->m_url->url_params) {
|
|
|
|
switch_snprintf(params, sizeof(params), ";%s", contact->m_url->url_params);
|
2010-09-13 15:27:10 -05:00
|
|
|
}
|
2010-12-30 11:38:23 -06:00
|
|
|
ipv6 = strchr(np.network_ip, ':');
|
|
|
|
sticky = switch_mprintf("sip:%s@%s%s%s:%d%s", contact_user, ipv6 ? "[" : "", np.network_ip, ipv6 ? "]" : "", np.network_port, params);
|
2010-09-13 15:27:10 -05:00
|
|
|
}
|
2010-03-11 15:52:29 +00:00
|
|
|
|
2010-12-30 11:38:23 -06:00
|
|
|
if (np.is_auto_nat) {
|
|
|
|
contactstr = profile->public_url;
|
2010-03-11 15:52:29 +00:00
|
|
|
} else {
|
2010-12-30 11:38:23 -06:00
|
|
|
contactstr = profile->url;
|
2010-03-11 15:52:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-30 11:38:23 -06:00
|
|
|
if (switch_stristr("port=tcp", contact->m_url->url_params)) {
|
|
|
|
if (np.is_auto_nat) {
|
|
|
|
cs = profile->tcp_public_contact;
|
|
|
|
} else {
|
|
|
|
cs = profile->tcp_contact;
|
2007-03-31 19:01:33 +00:00
|
|
|
}
|
2010-12-30 11:38:23 -06:00
|
|
|
} else if (switch_stristr("port=tls", contact->m_url->url_params)) {
|
|
|
|
if (np.is_auto_nat) {
|
|
|
|
cs = profile->tls_public_contact;
|
|
|
|
} else {
|
|
|
|
cs = profile->tls_contact;
|
2007-03-31 19:01:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-30 11:38:23 -06:00
|
|
|
if (cs) {
|
|
|
|
contactstr = cs;
|
2010-01-20 19:20:11 +00:00
|
|
|
}
|
|
|
|
|
2010-12-30 11:38:23 -06:00
|
|
|
|
|
|
|
if (nh && nh->nh_ds && nh->nh_ds->ds_usage) {
|
|
|
|
/* nua_dialog_usage_set_refresh_range(nh->nh_ds->ds_usage, exp_delta + SUB_OVERLAP, exp_delta + SUB_OVERLAP); */
|
2011-11-10 07:38:47 -06:00
|
|
|
nua_dialog_usage_set_refresh_range(nh->nh_ds->ds_usage, exp_delta, exp_delta);
|
2008-03-05 20:31:18 +00:00
|
|
|
}
|
2007-04-04 03:08:17 +00:00
|
|
|
|
2010-12-30 11:38:23 -06:00
|
|
|
if (contactstr && (p = strchr(contactstr, '@'))) {
|
|
|
|
if (strrchr(p, '>')) {
|
|
|
|
new_contactstr = switch_mprintf("<sip:%s%s", to_user, p);
|
|
|
|
} else {
|
|
|
|
new_contactstr = switch_mprintf("<sip:%s%s>", to_user, p);
|
2008-12-11 20:20:20 +00:00
|
|
|
}
|
2007-10-24 23:20:47 +00:00
|
|
|
}
|
2011-12-15 16:30:33 -06:00
|
|
|
|
|
|
|
sip_to_tag(nh->nh_home, sip->sip_to, to_tag);
|
|
|
|
|
2010-12-30 11:38:23 -06:00
|
|
|
nua_respond(nh, SIP_202_ACCEPTED,
|
2011-12-15 16:30:33 -06:00
|
|
|
SIPTAG_TO(sip->sip_to),
|
2010-12-30 11:38:23 -06:00
|
|
|
TAG_IF(new_contactstr, SIPTAG_CONTACT_STR(new_contactstr)),
|
2011-06-16 14:37:22 -05:00
|
|
|
NUTAG_WITH_THIS_MSG(de->data->e_msg),
|
2010-12-30 11:38:23 -06:00
|
|
|
SIPTAG_SUBSCRIPTION_STATE_STR(sstr), SIPTAG_EXPIRES_STR(exp_delta_str), TAG_IF(sticky, NUTAG_PROXY(sticky)), TAG_END());
|
2007-12-30 23:25:45 +00:00
|
|
|
|
2010-12-30 11:38:23 -06:00
|
|
|
switch_safe_free(new_contactstr);
|
|
|
|
switch_safe_free(sticky);
|
|
|
|
}
|
2010-02-06 03:38:24 +00:00
|
|
|
|
2010-12-30 11:38:23 -06:00
|
|
|
if (sub_state == nua_substate_terminated) {
|
|
|
|
char *full_call_info = NULL;
|
|
|
|
char *p = NULL;
|
2009-06-03 21:08:34 +00:00
|
|
|
|
2010-12-30 11:38:23 -06:00
|
|
|
if (sip->sip_call_info) {
|
2011-06-16 14:37:22 -05:00
|
|
|
full_call_info = sip_header_as_string(nh->nh_home, (void *) sip->sip_call_info);
|
2010-12-30 11:38:23 -06:00
|
|
|
if ((p = strchr(full_call_info, ';'))) {
|
|
|
|
p++;
|
2009-06-03 21:08:34 +00:00
|
|
|
}
|
|
|
|
|
2012-01-26 04:46:48 -06:00
|
|
|
#if 0
|
2010-12-30 11:38:23 -06:00
|
|
|
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());
|
2012-01-26 04:46:48 -06:00
|
|
|
#endif
|
2010-12-30 11:38:23 -06:00
|
|
|
|
|
|
|
if (!strcasecmp(event, "line-seize")) {
|
|
|
|
if (mod_sofia_globals.debug_sla > 1) {
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "CANCEL LINE SEIZE\n");
|
2009-06-03 21:08:34 +00:00
|
|
|
}
|
2008-11-26 19:30:40 +00:00
|
|
|
|
2012-01-30 11:43:43 -06:00
|
|
|
sql = switch_mprintf("delete from sip_dialogs where hostname='%q' and profile_name='%q' and "
|
|
|
|
"((sip_from_user='%q' and sip_from_host='%q') or presence_id='%q@%q') "
|
2010-12-30 11:38:23 -06:00
|
|
|
"and call_info_state='seized'",
|
2012-01-30 11:43:43 -06:00
|
|
|
mod_sofia_globals.hostname, profile->name, to_user, to_host, to_user, to_host);
|
2010-02-11 15:18:52 +00:00
|
|
|
|
2010-01-24 19:04:48 +00:00
|
|
|
|
2010-12-30 11:38:23 -06:00
|
|
|
if (mod_sofia_globals.debug_sla > 1) {
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "CLEAR SQL %s\n", sql);
|
2010-02-11 15:18:52 +00:00
|
|
|
}
|
2010-12-30 11:38:23 -06:00
|
|
|
sofia_glue_execute_sql_now(profile, &sql, SWITCH_TRUE);
|
|
|
|
|
2012-01-26 04:46:48 -06:00
|
|
|
sync_sla(profile, to_user, to_host, SWITCH_FALSE, SWITCH_FALSE, NULL);
|
2010-02-06 03:38:24 +00:00
|
|
|
}
|
2010-01-24 19:04:48 +00:00
|
|
|
|
2011-06-16 14:37:22 -05:00
|
|
|
su_free(nh->nh_home, full_call_info);
|
2010-01-24 19:04:48 +00:00
|
|
|
|
2009-12-24 05:44:23 +00:00
|
|
|
}
|
2010-12-30 11:38:23 -06:00
|
|
|
|
|
|
|
} else {
|
|
|
|
if (!strcasecmp(event, "line-seize")) {
|
2009-12-24 05:44:23 +00:00
|
|
|
char *full_call_info = NULL;
|
2010-12-30 11:38:23 -06:00
|
|
|
char *p;
|
2011-10-24 18:54:22 -05:00
|
|
|
switch_time_t now;
|
2009-12-24 05:44:23 +00:00
|
|
|
|
|
|
|
if (sip->sip_call_info) {
|
2011-06-16 14:37:22 -05:00
|
|
|
full_call_info = sip_header_as_string(nh->nh_home, (void *) sip->sip_call_info);
|
2010-01-07 06:09:35 +00:00
|
|
|
if ((p = strchr(full_call_info, ';'))) {
|
|
|
|
p++;
|
|
|
|
}
|
2009-12-24 05:44:23 +00:00
|
|
|
|
2010-01-07 06:09:35 +00:00
|
|
|
nua_notify(nh,
|
2010-12-30 11:38:23 -06:00
|
|
|
SIPTAG_EXPIRES_STR(exp_delta_str),
|
|
|
|
SIPTAG_SUBSCRIPTION_STATE_STR(sstr),
|
|
|
|
SIPTAG_EVENT_STR("line-seize"), TAG_IF(full_call_info, SIPTAG_CALL_INFO_STR(full_call_info)), TAG_END());
|
2010-02-06 03:38:24 +00:00
|
|
|
|
2009-12-24 05:44:23 +00:00
|
|
|
|
2010-02-06 03:38:24 +00:00
|
|
|
|
2012-01-30 11:43:43 -06:00
|
|
|
sql = switch_mprintf("delete from sip_dialogs where hostname='%q' and profile_name='%q' and "
|
|
|
|
"((sip_from_user='%q' and sip_from_host='%q') or presence_id='%q@%q') "
|
2012-01-26 04:46:48 -06:00
|
|
|
"and call_info_state='seized' and profile_name='%q'",
|
2012-01-30 11:43:43 -06:00
|
|
|
mod_sofia_globals.hostname, profile->name, to_user, to_host, to_user, to_host, profile->name);
|
2010-01-09 00:34:17 +00:00
|
|
|
|
|
|
|
|
2010-12-30 11:38:23 -06:00
|
|
|
if (mod_sofia_globals.debug_sla > 1) {
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "CLEAR SQL %s\n", sql);
|
2009-12-24 05:44:23 +00:00
|
|
|
}
|
2010-12-30 11:38:23 -06:00
|
|
|
sofia_glue_execute_sql_now(profile, &sql, SWITCH_TRUE);
|
2010-01-07 19:50:56 +00:00
|
|
|
|
2011-10-24 18:54:22 -05:00
|
|
|
now = switch_epoch_time_now(NULL);
|
2012-01-26 04:46:48 -06:00
|
|
|
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);
|
2010-02-06 03:38:24 +00:00
|
|
|
|
2010-12-30 11:38:23 -06:00
|
|
|
if (mod_sofia_globals.debug_sla > 1) {
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "SEIZE SQL %s\n", sql);
|
2009-12-24 05:44:23 +00:00
|
|
|
}
|
2010-12-30 11:38:23 -06:00
|
|
|
sofia_glue_execute_sql_now(profile, &sql, SWITCH_TRUE);
|
2012-01-26 04:46:48 -06:00
|
|
|
sync_sla(profile, to_user, to_host, SWITCH_FALSE, SWITCH_FALSE, NULL);
|
2010-12-30 11:38:23 -06:00
|
|
|
|
2011-06-16 14:37:22 -05:00
|
|
|
su_free(nh->nh_home, full_call_info);
|
2009-12-24 05:44:23 +00:00
|
|
|
}
|
2010-12-30 11:38:23 -06:00
|
|
|
} else if (!strcasecmp(event, "call-info")) {
|
2012-01-26 04:46:48 -06:00
|
|
|
sync_sla(profile, to_user, to_host, SWITCH_FALSE, SWITCH_FALSE, call_id);
|
2007-12-15 00:39:53 +00:00
|
|
|
}
|
2010-12-30 11:38:23 -06:00
|
|
|
}
|
2008-05-27 04:54:52 +00:00
|
|
|
|
2010-12-30 11:38:23 -06:00
|
|
|
sent_reply++;
|
2007-12-15 00:39:53 +00:00
|
|
|
|
2010-12-30 11:38:23 -06:00
|
|
|
switch_safe_free(sstr);
|
2007-03-31 19:01:33 +00:00
|
|
|
|
2010-12-30 11:38:23 -06:00
|
|
|
if (!strcasecmp(event, "message-summary")) {
|
|
|
|
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"
|
2012-01-30 11:43:43 -06:00
|
|
|
" from sip_subscriptions where hostname='%q' and profile_name='%q' and "
|
2012-01-26 15:53:05 -06:00
|
|
|
"event='message-summary' and sip_user='%q' "
|
2012-01-30 11:43:43 -06:00
|
|
|
"and (sip_host='%q' or presence_hosts like '%%%q%%')",
|
|
|
|
mod_sofia_globals.hostname, profile->name,
|
|
|
|
to_host, to_user, to_host, to_host))) {
|
2010-12-30 11:38:23 -06:00
|
|
|
sofia_glue_execute_sql_callback(profile, profile->ireg_mutex, sql, sofia_presence_sub_reg_callback, profile);
|
2010-02-06 03:38:24 +00:00
|
|
|
|
2010-12-30 11:38:23 -06:00
|
|
|
switch_safe_free(sql);
|
2007-03-31 19:01:33 +00:00
|
|
|
}
|
2010-12-30 11:38:23 -06:00
|
|
|
}
|
2010-07-27 19:47:35 -05:00
|
|
|
|
2010-12-30 11:38:23 -06:00
|
|
|
end:
|
2007-03-31 19:01:33 +00:00
|
|
|
|
2012-01-26 04:46:48 -06:00
|
|
|
if (strcasecmp(event, "call-info") && strcasecmp(event, "line-seize")) {
|
2010-07-27 22:08:47 -05:00
|
|
|
|
2012-01-26 04:46:48 -06:00
|
|
|
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);
|
|
|
|
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);
|
|
|
|
}
|
2010-07-27 22:08:47 -05:00
|
|
|
|
2012-01-26 04:46:48 -06:00
|
|
|
} 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);
|
2011-01-21 14:35:23 -06:00
|
|
|
|
2011-10-21 20:00:34 -05:00
|
|
|
}
|
2012-01-26 04:46:48 -06:00
|
|
|
} else {
|
2011-10-21 20:00:34 -05:00
|
|
|
|
2012-01-26 04:46:48 -06:00
|
|
|
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);
|
|
|
|
}
|
2012-02-10 12:23:58 -06:00
|
|
|
} else if (!strcasecmp(event, "presence")) {
|
2012-02-14 18:59:37 -06:00
|
|
|
if (switch_event_create(&sevent, SWITCH_EVENT_PRESENCE_PROBE) == SWITCH_STATUS_SUCCESS) {
|
2012-01-26 04:46:48 -06:00
|
|
|
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");
|
2012-02-22 11:51:49 -06:00
|
|
|
switch_event_add_header(sevent, SWITCH_STACK_BOTTOM, "from", "%s@%s", from_user, from_host);
|
2012-02-14 18:59:37 -06:00
|
|
|
switch_event_add_header(sevent, SWITCH_STACK_BOTTOM, "to", "%s@%s", to_user, to_host);
|
2012-02-22 11:51:49 -06:00
|
|
|
switch_event_add_header_string(sevent, SWITCH_STACK_BOTTOM, "expires", exp_delta_str);
|
2012-02-14 18:59:37 -06:00
|
|
|
switch_event_add_header_string(sevent, SWITCH_STACK_BOTTOM, "alt_event_type", "dialog");
|
2012-01-26 04:46:48 -06:00
|
|
|
switch_event_add_header_string(sevent, SWITCH_STACK_BOTTOM, "rpid", "unknown");
|
|
|
|
switch_event_add_header_string(sevent, SWITCH_STACK_BOTTOM, "status", "Registered");
|
2012-02-14 18:59:37 -06:00
|
|
|
switch_event_add_header_string(sevent, SWITCH_STACK_BOTTOM, "sub-call-id", call_id);
|
2012-01-26 04:46:48 -06:00
|
|
|
switch_event_fire(&sevent);
|
|
|
|
}
|
|
|
|
}
|
2010-07-27 22:08:47 -05:00
|
|
|
}
|
2010-12-30 11:38:23 -06:00
|
|
|
}
|
2010-07-27 22:08:47 -05:00
|
|
|
|
2010-12-30 11:38:23 -06:00
|
|
|
if (event) {
|
2011-06-16 14:37:22 -05:00
|
|
|
su_free(nh->nh_home, event);
|
2010-12-30 11:38:23 -06:00
|
|
|
}
|
2007-10-24 23:20:47 +00:00
|
|
|
|
2010-12-30 11:38:23 -06:00
|
|
|
if (full_from) {
|
2011-06-16 14:37:22 -05:00
|
|
|
su_free(nh->nh_home, full_from);
|
2010-12-30 11:38:23 -06:00
|
|
|
}
|
2011-12-15 16:30:33 -06:00
|
|
|
if (full_to) {
|
|
|
|
su_free(nh->nh_home, full_to);
|
|
|
|
}
|
|
|
|
|
2010-12-30 11:38:23 -06:00
|
|
|
if (full_via) {
|
2011-06-16 14:37:22 -05:00
|
|
|
su_free(nh->nh_home, full_via);
|
2010-12-30 11:38:23 -06:00
|
|
|
}
|
|
|
|
if (full_agent) {
|
2011-06-16 14:37:22 -05:00
|
|
|
su_free(nh->nh_home, full_agent);
|
2010-12-30 11:38:23 -06:00
|
|
|
}
|
2007-03-31 19:01:33 +00:00
|
|
|
|
2010-12-30 11:38:23 -06:00
|
|
|
switch_safe_free(d_user);
|
|
|
|
switch_safe_free(to_str);
|
|
|
|
switch_safe_free(contact_str);
|
2011-10-22 09:40:59 -05:00
|
|
|
switch_safe_free(alt_proto);
|
2007-12-15 00:39:53 +00:00
|
|
|
|
2010-12-30 11:38:23 -06:00
|
|
|
if (!sent_reply) {
|
|
|
|
nua_respond(nh, 481, "INVALID SUBSCRIPTION", TAG_END());
|
2007-03-31 19:01:33 +00:00
|
|
|
}
|
2011-12-15 16:30:33 -06:00
|
|
|
|
|
|
|
nua_handle_destroy(nh);
|
|
|
|
|
2007-03-31 19:01:33 +00:00
|
|
|
}
|
|
|
|
|
2010-12-30 11:38:23 -06:00
|
|
|
|
2010-02-06 03:38:24 +00:00
|
|
|
sofia_gateway_subscription_t *sofia_find_gateway_subscription(sofia_gateway_t *gateway_ptr, const char *event)
|
|
|
|
{
|
2008-11-24 15:52:55 +00:00
|
|
|
sofia_gateway_subscription_t *gw_sub_ptr;
|
|
|
|
for (gw_sub_ptr = gateway_ptr->subscriptions; gw_sub_ptr; gw_sub_ptr = gw_sub_ptr->next) {
|
|
|
|
if (!strcasecmp(gw_sub_ptr->event, event)) {
|
|
|
|
/* this is the gateway subscription we are interested in */
|
|
|
|
return gw_sub_ptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2007-03-31 19:01:33 +00:00
|
|
|
void sofia_presence_handle_sip_r_subscribe(int status,
|
2008-05-27 04:54:52 +00:00
|
|
|
char const *phrase,
|
|
|
|
nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sofia_private_t *sofia_private, sip_t const *sip,
|
2011-11-10 12:49:13 -06:00
|
|
|
sofia_dispatch_event_t *de,
|
2008-05-27 04:54:52 +00:00
|
|
|
tagi_t tags[])
|
2007-03-31 19:01:33 +00:00
|
|
|
{
|
2008-11-24 15:52:55 +00:00
|
|
|
sip_event_t const *o = NULL;
|
|
|
|
sofia_gateway_subscription_t *gw_sub_ptr;
|
2010-02-06 03:38:24 +00:00
|
|
|
|
2008-11-24 15:52:55 +00:00
|
|
|
if (!sip) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
tl_gets(tags, SIPTAG_EVENT_REF(o), TAG_END());
|
|
|
|
/* o->o_type: message-summary (for example) */
|
|
|
|
if (!o) {
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Event information not given\n");
|
|
|
|
return;
|
|
|
|
}
|
2007-03-31 19:01:33 +00:00
|
|
|
|
2008-11-24 15:52:55 +00:00
|
|
|
if (!sofia_private || !sofia_private->gateway) {
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Gateway information missing\n");
|
|
|
|
return;
|
|
|
|
}
|
2010-02-06 03:38:24 +00:00
|
|
|
|
2008-11-24 15:52:55 +00:00
|
|
|
/* Find the subscription if one exists */
|
|
|
|
if (!(gw_sub_ptr = sofia_find_gateway_subscription(sofia_private->gateway, o->o_type))) {
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Could not find gateway subscription. Gateway: %s. Subscription Event: %s\n",
|
2010-02-06 03:38:24 +00:00
|
|
|
sofia_private->gateway->name, o->o_type);
|
2008-11-24 15:52:55 +00:00
|
|
|
return;
|
|
|
|
}
|
2010-02-06 03:38:24 +00:00
|
|
|
|
2008-11-24 15:52:55 +00:00
|
|
|
/* Update the subscription status for the subscription */
|
|
|
|
switch (status) {
|
|
|
|
case 200:
|
2011-11-10 10:48:06 -06:00
|
|
|
case 202:
|
2008-11-24 15:52:55 +00:00
|
|
|
/* TODO: in the spec it is possible for the other side to change the original expiry time,
|
|
|
|
* this needs to be researched (eg, what sip header this information will be in) and implemented.
|
|
|
|
* Although, since it seems the sofia stack is pretty much handling the subscription expiration
|
|
|
|
* anyway, then maybe its not even worth bothering.
|
|
|
|
*/
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "got 200 OK response, updated state to SUB_STATE_SUBSCRIBE.\n");
|
|
|
|
gw_sub_ptr->state = SUB_STATE_SUBSCRIBE;
|
|
|
|
break;
|
|
|
|
case 100:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "status (%d) != 200, updated state to SUB_STATE_FAILED.\n", status);
|
|
|
|
gw_sub_ptr->state = SUB_STATE_FAILED;
|
2010-02-06 03:38:24 +00:00
|
|
|
|
2009-03-22 05:15:17 +00:00
|
|
|
if (sofia_private) {
|
2011-11-10 12:49:13 -06:00
|
|
|
if (sofia_private->gateway->sub_nh) {
|
|
|
|
nua_handle_bind(sofia_private->gateway->sub_nh, NULL);
|
|
|
|
nua_handle_destroy(sofia_private->gateway->sub_nh);
|
|
|
|
sofia_private->gateway->sub_nh = NULL;
|
|
|
|
}
|
2009-03-22 05:15:17 +00:00
|
|
|
} else {
|
|
|
|
nua_handle_destroy(nh);
|
|
|
|
}
|
|
|
|
|
2008-11-24 15:52:55 +00:00
|
|
|
break;
|
|
|
|
}
|
2007-03-31 19:01:33 +00:00
|
|
|
}
|
|
|
|
|
2012-01-17 16:08:25 -06:00
|
|
|
struct pres_sql_cb {
|
|
|
|
sofia_profile_t *profile;
|
|
|
|
int ttl;
|
|
|
|
};
|
2011-06-16 14:37:22 -05:00
|
|
|
|
2011-12-15 16:30:33 -06:00
|
|
|
static int sofia_presence_send_sql(void *pArg, int argc, char **argv, char **columnNames)
|
2010-12-30 11:38:23 -06:00
|
|
|
{
|
2012-01-17 16:08:25 -06:00
|
|
|
struct pres_sql_cb *cb = (struct pres_sql_cb *) pArg;
|
2011-12-15 16:30:33 -06:00
|
|
|
|
2012-01-26 04:46:48 -06:00
|
|
|
|
|
|
|
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]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-17 16:08:25 -06:00
|
|
|
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++;
|
|
|
|
|
2010-12-30 11:38:23 -06:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-02-02 16:05:57 -06:00
|
|
|
|
|
|
|
uint32_t sofia_presence_contact_count(sofia_profile_t *profile, const char *contact_str)
|
|
|
|
{
|
|
|
|
char buf[32] = "";
|
|
|
|
char *sql;
|
|
|
|
|
2012-01-30 11:43:43 -06:00
|
|
|
sql = switch_mprintf("select count(*) from sip_subscriptions where hostname='%q' and profile_name='%q' and contact='%q'",
|
|
|
|
mod_sofia_globals.hostname, profile->name, contact_str);
|
2011-02-02 16:05:57 -06:00
|
|
|
|
|
|
|
sofia_glue_execute_sql2str(profile, profile->ireg_mutex, sql, buf, sizeof(buf));
|
|
|
|
switch_safe_free(sql);
|
|
|
|
return atoi(buf);
|
|
|
|
}
|
|
|
|
|
2008-05-27 04:54:52 +00:00
|
|
|
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,
|
2012-01-26 04:46:48 -06:00
|
|
|
sofia_dispatch_event_t *de,
|
2008-05-27 04:54:52 +00:00
|
|
|
tagi_t tags[])
|
2007-03-31 19:01:33 +00:00
|
|
|
{
|
2010-12-30 11:38:23 -06:00
|
|
|
|
|
|
|
sip_from_t const *from;
|
|
|
|
char *from_user = NULL;
|
|
|
|
char *from_host = NULL;
|
|
|
|
char *rpid = "";
|
|
|
|
sip_payload_t *payload;
|
|
|
|
char *event_type = NULL;
|
|
|
|
char etag[9] = "";
|
|
|
|
char expstr[30] = "";
|
|
|
|
long exp = 0, exp_delta = 3600;
|
|
|
|
char *pd_dup = NULL;
|
2012-02-23 16:55:54 -06:00
|
|
|
int count = 1, sub_count = 1;
|
2010-12-30 11:38:23 -06:00
|
|
|
char *contact_str;
|
|
|
|
int open = 1;
|
2012-02-10 11:02:41 -06:00
|
|
|
sofia_nat_parse_t np = { { 0 } };
|
2009-01-30 16:46:37 +00:00
|
|
|
|
2010-12-30 11:38:23 -06:00
|
|
|
if (!sip) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
from = sip->sip_from;
|
|
|
|
payload = sip->sip_payload;
|
|
|
|
|
2012-02-10 11:02:41 -06:00
|
|
|
np.fs_path = 1;
|
|
|
|
contact_str = sofia_glue_gen_contact_str(profile, sip, nh, de, &np);
|
2010-12-30 11:38:23 -06:00
|
|
|
|
|
|
|
if (from) {
|
|
|
|
from_user = (char *) from->a_url->url_user;
|
|
|
|
from_host = (char *) from->a_url->url_host;
|
|
|
|
}
|
2010-07-29 23:39:39 -05:00
|
|
|
|
2010-12-30 11:38:23 -06:00
|
|
|
exp_delta = (sip->sip_expires ? sip->sip_expires->ex_delta : 3600);
|
2011-11-10 07:38:47 -06:00
|
|
|
if ((profile->force_publish_expires > 0) && (profile->force_publish_expires < (uint32_t)exp_delta)) {
|
2010-12-30 11:38:23 -06:00
|
|
|
exp_delta = profile->force_publish_expires;
|
|
|
|
}
|
2010-10-21 12:50:19 -05:00
|
|
|
|
2010-12-30 11:38:23 -06:00
|
|
|
if (exp_delta < 0) {
|
|
|
|
exp = exp_delta;
|
|
|
|
} else {
|
|
|
|
exp = (long) switch_epoch_time_now(NULL) + exp_delta;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (payload) {
|
|
|
|
switch_xml_t xml, note, person, tuple, status, basic, act;
|
|
|
|
switch_event_t *event;
|
|
|
|
char *sql;
|
|
|
|
char *full_agent = NULL;
|
|
|
|
|
|
|
|
pd_dup = strdup(payload->pl_data);
|
2010-08-30 17:33:05 -05:00
|
|
|
|
2010-12-30 11:38:23 -06:00
|
|
|
if ((xml = switch_xml_parse_str(pd_dup, strlen(pd_dup)))) {
|
|
|
|
char *open_closed = "", *note_txt = "";
|
2010-07-27 19:47:35 -05:00
|
|
|
|
2010-12-30 11:38:23 -06:00
|
|
|
if (sip->sip_user_agent) {
|
2011-06-16 14:37:22 -05:00
|
|
|
full_agent = sip_header_as_string(nh->nh_home, (void *) sip->sip_user_agent);
|
2010-12-30 11:38:23 -06:00
|
|
|
}
|
2010-07-27 19:47:35 -05:00
|
|
|
|
2010-12-30 11:38:23 -06:00
|
|
|
if ((tuple = switch_xml_child(xml, "tuple")) && (status = switch_xml_child(tuple, "status"))
|
|
|
|
&& (basic = switch_xml_child(status, "basic"))) {
|
|
|
|
open_closed = basic->txt;
|
|
|
|
}
|
2007-03-31 19:01:33 +00:00
|
|
|
|
2010-12-30 11:38:23 -06:00
|
|
|
if ((person = switch_xml_child(xml, "dm:person")) && (note = switch_xml_child(person, "dm:note"))) {
|
|
|
|
note_txt = note->txt;
|
|
|
|
}
|
2010-02-06 03:38:24 +00:00
|
|
|
|
2010-12-30 11:38:23 -06:00
|
|
|
if (person && (act = switch_xml_child(person, "rpid:activities")) && act->child && act->child->name) {
|
|
|
|
if ((rpid = strchr(act->child->name, ':'))) {
|
|
|
|
rpid++;
|
|
|
|
} else {
|
|
|
|
rpid = act->child->name;
|
2007-03-31 19:01:33 +00:00
|
|
|
}
|
2010-12-30 11:38:23 -06:00
|
|
|
}
|
2007-03-31 19:01:33 +00:00
|
|
|
|
2010-12-30 11:38:23 -06:00
|
|
|
if (sofia_test_pflag(profile, PFLAG_MULTIREG) && !open) {
|
2011-01-03 16:48:10 -06:00
|
|
|
count = sofia_reg_reg_count(profile, from_user, from_host);
|
2012-02-23 16:55:54 -06:00
|
|
|
sub_count = sofia_presence_contact_count(profile, contact_str);
|
2010-12-30 11:38:23 -06:00
|
|
|
}
|
2010-10-21 12:50:19 -05:00
|
|
|
|
2010-12-30 11:38:23 -06:00
|
|
|
/* if (count > 1) let's not and say we did or all the clients who subscribe to their own presence will think they selves is offline */
|
2010-10-21 12:50:19 -05:00
|
|
|
|
2011-06-16 14:37:22 -05:00
|
|
|
event_type = sip_header_as_string(nh->nh_home, (void *) sip->sip_event);
|
2010-12-30 11:38:23 -06:00
|
|
|
|
|
|
|
if (count < 2) {
|
2011-02-02 16:05:57 -06:00
|
|
|
if ((sql = switch_mprintf("delete from sip_presence where sip_user='%q' and sip_host='%q' "
|
|
|
|
" and profile_name='%q' and hostname='%q'",
|
|
|
|
from_user, from_host, profile->name, mod_sofia_globals.hostname))) {
|
2010-12-30 11:38:23 -06:00
|
|
|
sofia_glue_execute_sql_now(profile, &sql, SWITCH_TRUE);
|
|
|
|
}
|
2010-08-23 17:02:06 -05:00
|
|
|
|
2011-02-02 16:05:57 -06:00
|
|
|
if (sub_count > 0 && (sql = switch_mprintf("insert into sip_presence (sip_user, sip_host, status, rpid, expires, user_agent,"
|
|
|
|
" profile_name, hostname, open_closed) "
|
|
|
|
"values ('%q','%q','%q','%q',%ld,'%q','%q','%q','%q')",
|
|
|
|
from_user, from_host, note_txt, rpid, exp, full_agent, profile->name,
|
|
|
|
mod_sofia_globals.hostname, open_closed))) {
|
|
|
|
|
2010-12-30 11:38:23 -06:00
|
|
|
sofia_glue_execute_sql_now(profile, &sql, SWITCH_TRUE);
|
|
|
|
}
|
2010-08-23 17:02:06 -05:00
|
|
|
|
2010-12-30 11:38:23 -06:00
|
|
|
} else if (contact_str) {
|
2012-01-17 16:08:25 -06:00
|
|
|
struct pres_sql_cb cb = {profile, 0};
|
|
|
|
|
2011-12-15 16:30:33 -06:00
|
|
|
sql = switch_mprintf("select full_to, full_from, contact, expires, call_id, event, network_ip, network_port, "
|
|
|
|
"'application/pidf+xml' as ct,'%q' as pt "
|
2012-01-30 11:43:43 -06:00
|
|
|
" from sip_subscriptions where "
|
|
|
|
"hostname='%q' and profile_name='%q' and sub_to_user='%q' and sub_to_host='%q' and event='%q'"
|
|
|
|
"and contact = '%q' ",
|
|
|
|
|
|
|
|
switch_str_nil(payload->pl_data),
|
|
|
|
mod_sofia_globals.hostname, profile->name,
|
|
|
|
from_user, from_host, event_type);
|
2011-12-15 16:30:33 -06:00
|
|
|
|
2012-01-17 16:08:25 -06:00
|
|
|
sofia_glue_execute_sql_callback(profile, profile->ireg_mutex, sql, sofia_presence_send_sql, &cb);
|
2010-12-30 11:38:23 -06:00
|
|
|
switch_safe_free(sql);
|
|
|
|
}
|
2010-02-06 03:38:24 +00:00
|
|
|
|
2011-02-02 16:05:57 -06:00
|
|
|
if (sub_count > 0) {
|
|
|
|
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(event, SWITCH_STACK_BOTTOM, "user-agent", full_agent);
|
|
|
|
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "from", "%s@%s", from_user, from_host);
|
|
|
|
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "status", note_txt);
|
|
|
|
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "event_type", event_type);
|
|
|
|
switch_event_fire(&event);
|
|
|
|
}
|
2010-12-30 11:38:23 -06:00
|
|
|
}
|
2008-11-22 01:34:19 +00:00
|
|
|
|
2010-12-30 11:38:23 -06:00
|
|
|
if (event_type) {
|
2011-06-16 14:37:22 -05:00
|
|
|
su_free(nh->nh_home, event_type);
|
2010-12-30 11:38:23 -06:00
|
|
|
}
|
2010-07-27 19:47:35 -05:00
|
|
|
|
2010-12-30 11:38:23 -06:00
|
|
|
if (full_agent) {
|
2011-06-16 14:37:22 -05:00
|
|
|
su_free(nh->nh_home, full_agent);
|
2007-03-31 19:01:33 +00:00
|
|
|
}
|
2010-12-30 11:38:23 -06:00
|
|
|
|
|
|
|
switch_xml_free(xml);
|
2007-03-31 19:01:33 +00:00
|
|
|
}
|
2010-12-30 11:38:23 -06:00
|
|
|
} else {
|
|
|
|
char *sql = switch_mprintf("update sip_presence set expires=%ld where sip_user='%q' and sip_host='%q' and profile_name='%q' and hostname='%q'",
|
|
|
|
exp, from_user, from_host, profile->name, mod_sofia_globals.hostname);
|
|
|
|
sofia_glue_execute_sql_now(profile, &sql, SWITCH_TRUE);
|
|
|
|
}
|
2010-01-08 21:22:06 +00:00
|
|
|
|
2010-12-30 11:38:23 -06:00
|
|
|
switch_safe_free(pd_dup);
|
2010-07-27 19:47:35 -05:00
|
|
|
|
2010-12-30 11:38:23 -06:00
|
|
|
switch_snprintf(expstr, sizeof(expstr), "%d", exp_delta);
|
|
|
|
switch_stun_random_string(etag, 8, NULL);
|
2011-02-02 16:05:57 -06:00
|
|
|
|
|
|
|
if (sub_count > 0) {
|
2011-06-16 14:37:22 -05:00
|
|
|
nua_respond(nh, SIP_200_OK, NUTAG_WITH_THIS_MSG(de->data->e_msg), SIPTAG_ETAG_STR(etag), SIPTAG_EXPIRES_STR(expstr), TAG_END());
|
2011-02-02 16:05:57 -06:00
|
|
|
} else {
|
2011-06-16 14:37:22 -05:00
|
|
|
nua_respond(nh, SIP_404_NOT_FOUND, NUTAG_WITH_THIS_MSG(de->data->e_msg), TAG_END());
|
2011-02-02 16:05:57 -06:00
|
|
|
}
|
2010-12-30 11:38:23 -06:00
|
|
|
|
|
|
|
switch_safe_free(contact_str);
|
2007-03-31 19:01:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void sofia_presence_set_hash_key(char *hash_key, int32_t len, sip_t const *sip)
|
|
|
|
{
|
2007-11-20 03:26:40 +00:00
|
|
|
url_t *to = sip->sip_to->a_url;
|
|
|
|
url_t *from = sip->sip_from->a_url;
|
2007-12-12 21:53:32 +00:00
|
|
|
switch_snprintf(hash_key, len, "%s%s%s", from->url_user, from->url_host, to->url_user);
|
2007-03-31 19:01:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void sofia_presence_handle_sip_i_message(int status,
|
2008-05-27 04:54:52 +00:00
|
|
|
char const *phrase,
|
|
|
|
nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sofia_private_t *sofia_private, sip_t const *sip,
|
2012-01-26 04:46:48 -06:00
|
|
|
sofia_dispatch_event_t *de,
|
2008-05-27 04:54:52 +00:00
|
|
|
tagi_t tags[])
|
2007-03-31 19:01:33 +00:00
|
|
|
{
|
|
|
|
if (sip) {
|
|
|
|
sip_from_t const *from = sip->sip_from;
|
2007-11-20 03:26:40 +00:00
|
|
|
const char *from_user = NULL;
|
|
|
|
const char *from_host = NULL;
|
2007-03-31 19:01:33 +00:00
|
|
|
sip_to_t const *to = sip->sip_to;
|
2007-11-20 03:26:40 +00:00
|
|
|
const char *to_user = NULL;
|
|
|
|
const char *to_host = NULL;
|
2007-03-31 19:01:33 +00:00
|
|
|
sip_payload_t *payload = sip->sip_payload;
|
|
|
|
char *msg = NULL;
|
2011-09-21 14:31:10 -05:00
|
|
|
const char *us;
|
|
|
|
char network_ip[80];
|
|
|
|
int network_port = 0;
|
|
|
|
|
|
|
|
if ((us = sofia_glue_get_unknown_header(sip, "X-FS-Sending-Message")) && !strcmp(us, switch_core_get_uuid())) {
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Not sending message to ourselves!\n");
|
|
|
|
goto end;
|
|
|
|
}
|
2007-03-31 19:01:33 +00:00
|
|
|
|
2007-12-30 01:43:57 +00:00
|
|
|
if (sip->sip_content_type && sip->sip_content_type->c_subtype) {
|
2007-11-20 03:26:40 +00:00
|
|
|
if (strstr(sip->sip_content_type->c_subtype, "composing")) {
|
2011-09-21 14:31:10 -05:00
|
|
|
goto end;
|
2007-03-31 19:01:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-21 14:31:10 -05:00
|
|
|
|
|
|
|
sofia_glue_get_addr(de->data->e_msg, network_ip, sizeof(network_ip), &network_port);
|
|
|
|
|
|
|
|
|
2007-03-31 19:01:33 +00:00
|
|
|
if (from) {
|
2007-11-20 03:26:40 +00:00
|
|
|
from_user = from->a_url->url_user;
|
|
|
|
from_host = from->a_url->url_host;
|
2007-03-31 19:01:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (to) {
|
2007-11-20 03:26:40 +00:00
|
|
|
to_user = to->a_url->url_user;
|
|
|
|
to_host = to->a_url->url_host;
|
2007-03-31 19:01:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!to_user) {
|
2011-09-21 14:31:10 -05:00
|
|
|
goto end;
|
2007-03-31 19:01:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (payload) {
|
|
|
|
msg = payload->pl_data;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nh) {
|
|
|
|
char hash_key[512];
|
|
|
|
private_object_t *tech_pvt;
|
|
|
|
switch_event_t *event;
|
|
|
|
char *to_addr;
|
|
|
|
char *from_addr;
|
|
|
|
char *p;
|
|
|
|
char *full_from;
|
|
|
|
char proto[512] = SOFIA_CHAT_PROTO;
|
|
|
|
|
2011-06-16 14:37:22 -05:00
|
|
|
full_from = sip_header_as_string(nh->nh_home, (void *) sip->sip_from);
|
2007-03-31 19:01:33 +00:00
|
|
|
|
|
|
|
if ((p = strchr(to_user, '+'))) {
|
|
|
|
switch_copy_string(proto, to_user, sizeof(proto));
|
|
|
|
p = strchr(proto, '+');
|
|
|
|
*p++ = '\0';
|
2010-02-06 03:38:24 +00:00
|
|
|
|
2007-03-31 19:01:33 +00:00
|
|
|
if ((to_addr = strdup(p))) {
|
|
|
|
if ((p = strchr(to_addr, '+'))) {
|
|
|
|
*p = '@';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
to_addr = switch_mprintf("%s@%s", to_user, to_host);
|
|
|
|
}
|
|
|
|
|
2011-09-21 14:31:10 -05:00
|
|
|
from_addr = switch_mprintf("%s@%s", from_user, from_host);
|
2007-03-31 19:01:33 +00:00
|
|
|
|
2010-08-18 14:58:14 -05:00
|
|
|
if (sofia_test_pflag(profile, PFLAG_IN_DIALOG_CHAT)) {
|
|
|
|
sofia_presence_set_hash_key(hash_key, sizeof(hash_key), sip);
|
|
|
|
}
|
|
|
|
|
2011-09-13 16:51:30 -05:00
|
|
|
if (switch_event_create(&event, SWITCH_EVENT_MESSAGE) == SWITCH_STATUS_SUCCESS) {
|
|
|
|
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "login", profile->url);
|
|
|
|
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "proto", SOFIA_CHAT_PROTO);
|
2011-10-21 20:38:41 -05:00
|
|
|
|
|
|
|
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "to_proto", proto);
|
|
|
|
|
2011-09-13 16:51:30 -05:00
|
|
|
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "from", from_addr);
|
|
|
|
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "from_user", from_user);
|
|
|
|
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "from_host", from_host);
|
2011-09-21 14:31:10 -05:00
|
|
|
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "to_user", to_user);
|
|
|
|
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "to_host", to_host);
|
|
|
|
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "from_sip_ip", network_ip);
|
|
|
|
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "from_sip_port", "%d", network_port);
|
2011-09-13 16:51:30 -05:00
|
|
|
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "to", to_addr);
|
|
|
|
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "subject", "SIMPLE MESSAGE");
|
2011-09-21 14:31:10 -05:00
|
|
|
|
|
|
|
|
|
|
|
if (sip->sip_content_type && sip->sip_content_type->c_subtype) {
|
|
|
|
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "type", sip->sip_content_type->c_type);
|
|
|
|
} else {
|
|
|
|
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "type", "text/plain");
|
|
|
|
}
|
|
|
|
|
|
|
|
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "from_full", full_from);
|
|
|
|
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "sip_profile", profile->name);
|
2011-09-13 16:51:30 -05:00
|
|
|
|
|
|
|
if (msg) {
|
|
|
|
switch_event_add_body(event, "%s", msg);
|
2007-03-31 19:01:33 +00:00
|
|
|
}
|
|
|
|
} else {
|
2011-09-13 16:51:30 -05:00
|
|
|
abort();
|
2007-03-31 19:01:33 +00:00
|
|
|
}
|
2011-09-13 16:51:30 -05:00
|
|
|
|
|
|
|
if (sofia_test_pflag(profile, PFLAG_IN_DIALOG_CHAT) && (tech_pvt = (private_object_t *) switch_core_hash_find(profile->chat_hash, hash_key))) {
|
|
|
|
switch_core_session_queue_event(tech_pvt->session, &event);
|
|
|
|
} else {
|
|
|
|
switch_core_chat_send(proto, event);
|
|
|
|
switch_event_destroy(&event);
|
2011-09-02 14:41:20 -05:00
|
|
|
}
|
|
|
|
|
2007-03-31 19:01:33 +00:00
|
|
|
switch_safe_free(to_addr);
|
|
|
|
switch_safe_free(from_addr);
|
2011-09-13 16:51:30 -05:00
|
|
|
|
2007-03-31 19:01:33 +00:00
|
|
|
if (full_from) {
|
2011-06-16 14:37:22 -05:00
|
|
|
su_free(nh->nh_home, full_from);
|
2007-03-31 19:01:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-09-21 14:31:10 -05:00
|
|
|
|
|
|
|
end:
|
|
|
|
|
2012-02-02 20:00:46 -06:00
|
|
|
nua_respond(nh, SIP_202_ACCEPTED, NUTAG_WITH_THIS_MSG(de->data->e_msg), TAG_END());
|
2011-09-21 14:31:10 -05:00
|
|
|
|
2007-03-31 19:01:33 +00:00
|
|
|
}
|
|
|
|
|
2007-04-13 22:15:58 +00:00
|
|
|
void sofia_presence_set_chat_hash(private_object_t *tech_pvt, sip_t const *sip)
|
2007-03-31 19:01:33 +00:00
|
|
|
{
|
|
|
|
char hash_key[256] = "";
|
|
|
|
char buf[512];
|
2007-09-29 01:06:08 +00:00
|
|
|
su_home_t *home = NULL;
|
2007-03-31 19:01:33 +00:00
|
|
|
|
2010-02-06 03:38:24 +00:00
|
|
|
if (!tech_pvt || tech_pvt->hash_key || !sip || !sip->sip_from || !sip->sip_from->a_url ||
|
2008-06-27 18:38:21 +00:00
|
|
|
!sip->sip_from->a_url->url_user || !sip->sip_from->a_url->url_host) {
|
2007-03-31 19:01:33 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sofia_reg_find_reg_url(tech_pvt->profile, sip->sip_from->a_url->url_user, sip->sip_from->a_url->url_host, buf, sizeof(buf))) {
|
2007-09-29 01:06:08 +00:00
|
|
|
home = su_home_new(sizeof(*home));
|
2008-05-27 04:54:52 +00:00
|
|
|
switch_assert(home != NULL);
|
2007-09-29 01:06:08 +00:00
|
|
|
tech_pvt->chat_from = sip_header_as_string(home, (const sip_header_t *) sip->sip_to);
|
2007-03-31 19:01:33 +00:00
|
|
|
tech_pvt->chat_to = switch_core_session_strdup(tech_pvt->session, buf);
|
|
|
|
sofia_presence_set_hash_key(hash_key, sizeof(hash_key), sip);
|
2007-09-29 01:06:08 +00:00
|
|
|
su_home_unref(home);
|
|
|
|
home = NULL;
|
2007-03-31 19:01:33 +00:00
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
}
|
2010-02-06 03:38:24 +00:00
|
|
|
|
2008-09-16 20:04:33 +00:00
|
|
|
switch_mutex_lock(tech_pvt->profile->flag_mutex);
|
2007-03-31 19:01:33 +00:00
|
|
|
tech_pvt->hash_key = switch_core_session_strdup(tech_pvt->session, hash_key);
|
|
|
|
switch_core_hash_insert(tech_pvt->profile->chat_hash, tech_pvt->hash_key, tech_pvt);
|
2008-09-16 20:04:33 +00:00
|
|
|
switch_mutex_unlock(tech_pvt->profile->flag_mutex);
|
2007-03-31 19:01:33 +00:00
|
|
|
}
|
2008-05-27 04:54:52 +00:00
|
|
|
|
2011-12-15 16:30:33 -06:00
|
|
|
|
|
|
|
void sofia_presence_check_subscriptions(sofia_profile_t *profile, time_t now)
|
|
|
|
{
|
|
|
|
char *sql;
|
|
|
|
|
|
|
|
if (now) {
|
2012-01-17 16:08:25 -06:00
|
|
|
struct pres_sql_cb cb = {profile, 0};
|
2012-01-16 17:24:39 -06:00
|
|
|
|
2012-01-17 16:08:25 -06:00
|
|
|
if (profile->pres_type != PRES_TYPE_FULL) {
|
|
|
|
if (mod_sofia_globals.debug_presence > 0) {
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "check_subs: %s is passive, skipping\n", (char *) profile->name);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-01-26 15:53:05 -06:00
|
|
|
sql = switch_mprintf("update sip_subscriptions set version=version+1 where "
|
|
|
|
"((expires > 0 and expires <= %ld)) and profile_name='%q' and hostname='%q'",
|
|
|
|
(long) now, profile->name, mod_sofia_globals.hostname);
|
|
|
|
|
|
|
|
sofia_glue_execute_sql_now(profile, &sql, SWITCH_TRUE);
|
|
|
|
switch_safe_free(sql);
|
2012-01-17 16:08:25 -06:00
|
|
|
|
|
|
|
sql = switch_mprintf("select full_to, full_from, contact, -1, call_id, event, network_ip, network_port, "
|
2011-12-15 16:30:33 -06:00
|
|
|
"NULL as ct, NULL as pt "
|
2012-01-26 15:53:05 -06:00
|
|
|
" from sip_subscriptions where ((expires > 0 and expires <= %ld)) and profile_name='%q' and hostname='%q'",
|
2012-01-17 16:08:25 -06:00
|
|
|
(long) now, profile->name, mod_sofia_globals.hostname);
|
2011-12-15 16:30:33 -06:00
|
|
|
|
2012-01-17 16:08:25 -06:00
|
|
|
sofia_glue_execute_sql_callback(profile, profile->ireg_mutex, sql, sofia_presence_send_sql, &cb);
|
2011-12-15 16:30:33 -06:00
|
|
|
switch_safe_free(sql);
|
|
|
|
|
2012-01-17 16:08:25 -06:00
|
|
|
if (cb.ttl) {
|
2012-01-26 15:53:05 -06:00
|
|
|
sql = switch_mprintf("delete from sip_subscriptions where ((expires > 0 and expires <= %ld)) "
|
2012-01-17 16:08:25 -06:00
|
|
|
"and profile_name='%q' and hostname='%q'",
|
|
|
|
(long) now, profile->name, 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);
|
|
|
|
}
|
|
|
|
|
|
|
|
sofia_glue_actually_execute_sql(profile, sql, profile->ireg_mutex);
|
2012-01-26 15:53:05 -06:00
|
|
|
switch_safe_free(sql);
|
2012-01-17 16:08:25 -06:00
|
|
|
}
|
2011-12-15 16:30:33 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-17 04:10:35 +00:00
|
|
|
/* For Emacs:
|
|
|
|
* Local Variables:
|
|
|
|
* mode:c
|
2008-02-03 22:14:57 +00:00
|
|
|
* indent-tabs-mode:t
|
2007-11-17 04:10:35 +00:00
|
|
|
* tab-width:4
|
|
|
|
* c-basic-offset:4
|
|
|
|
* End:
|
|
|
|
* For VIM:
|
2008-07-03 19:12:26 +00:00
|
|
|
* vim:set softtabstop=4 shiftwidth=4 tabstop=4:
|
2007-11-17 04:10:35 +00:00
|
|
|
*/
|