}
if (!strncasecmp(dest, "sip:", 4) || !strncasecmp(dest, "sips:", 5)) {
+ char *c;
tech_pvt->dest = switch_core_session_strdup(nsession, dest);
+ if ((c = strchr(tech_pvt->dest, ':'))) {
+ c++;
+ tech_pvt->e_dest = switch_core_session_strdup(nsession, c);
+ }
} else if ((host = strchr(dest, '%'))) {
char buf[1024];
*host = '@';
} else {
host++;
tech_pvt->dest = switch_core_session_alloc(nsession, strlen(dest) + 5);
+ tech_pvt->e_dest = switch_core_session_strdup(nsession, dest);
switch_snprintf(tech_pvt->dest, strlen(dest) + 5, "sip:%s", dest);
}
}
const char *body = switch_event_get_body(event);
sofia_profile_t *profile;
nua_handle_t *nh;
-
+
if (profile_name && ct && user && host) {
char *id = NULL;
char *contact, *p;
- char buf[512] = "";
-
+ switch_console_callback_match_t *list = NULL;
+ switch_console_callback_match_node_t *m;
+
if (!(profile = sofia_glue_find_profile(profile_name))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't find profile %s\n", profile_name);
return;
}
-
-
- if (!sofia_reg_find_reg_url(profile, user, host, buf, sizeof(buf))) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't find user %s@%s\n", user, host);
+
+ if (!(list = sofia_reg_find_reg_url_multi(profile, user, host))) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't find registered user %s@%s\n", user, host);
return;
}
id = switch_mprintf("sip:%s@%s", user, host);
switch_assert(id);
- contact = sofia_glue_get_url_from_contact(buf, 0);
- if ((p = strstr(contact, ";fs_"))) {
- *p = '\0';
- }
+ for (m = list->head; m; m = m->next) {
+ contact = sofia_glue_get_url_from_contact(m->val, 0);
- nh = nua_handle(profile->nua,
- NULL, NUTAG_URL(contact), SIPTAG_FROM_STR(id), SIPTAG_TO_STR(id), SIPTAG_CONTACT_STR(profile->url), TAG_END());
+ if ((p = strstr(contact, ";fs_"))) {
+ *p = '\0';
+ }
+
+ nh = nua_handle(profile->nua,
+ NULL, NUTAG_URL(contact), SIPTAG_FROM_STR(id), SIPTAG_TO_STR(id), SIPTAG_CONTACT_STR(profile->url), TAG_END());
- nua_message(nh, NUTAG_NEWSUB(1), SIPTAG_CONTENT_TYPE_STR(ct),
- TAG_IF(!zstr(body), SIPTAG_PAYLOAD_STR(body)), TAG_IF(!zstr(subject), SIPTAG_SUBJECT_STR(subject)), TAG_END());
+ nua_message(nh, NUTAG_NEWSUB(1), SIPTAG_CONTENT_TYPE_STR(ct),
+ TAG_IF(!zstr(body), SIPTAG_PAYLOAD_STR(body)), TAG_IF(!zstr(subject), SIPTAG_SUBJECT_STR(subject)), TAG_END());
- free(id);
+ free(id);
+ }
+ switch_console_free_matches(&list);
+
sofia_glue_release_profile(profile);
}
PFLAG_EXTENDED_INFO_PARSING,
PFLAG_T38_PASSTHRU,
PFLAG_CID_IN_1XX,
+ PFLAG_IN_DIALOG_CHAT,
/* No new flags below this line */
PFLAG_MAX
} PFLAGS;
struct callback_t {
char *val;
switch_size_t len;
+ switch_console_callback_match_t *list;
int matches;
};
switch_t38_options_t *sofia_glue_extract_t38_options(switch_core_session_t *session, const char *r_sdp);
char *sofia_glue_get_multipart(switch_core_session_t *session, const char *prefix, const char *sdp, char **mp_type);
void sofia_glue_tech_simplify(private_object_t *tech_pvt);
+switch_console_callback_match_t *sofia_reg_find_reg_url_multi(sofia_profile_t *profile, const char *user, const char *host);
} else {
sofia_clear_pflag(profile, PFLAG_PASS_CALLEE_ID);
}
+ } else if (!strcasecmp(var, "in-dialog-chat")) {
+ if (switch_true(val)) {
+ sofia_set_pflag(profile, PFLAG_IN_DIALOG_CHAT);
+ } else {
+ sofia_clear_pflag(profile, PFLAG_IN_DIALOG_CHAT);
+ }
} else if (!strcasecmp(var, "disable-hold")) {
if (switch_true(val)) {
sofia_set_pflag(profile, PFLAG_DISABLE_HOLD);
} else {
sofia_clear_pflag(profile, PFLAG_LOG_AUTH_FAIL);
}
+ } else if (!strcasecmp(var, "in-dialog-chat")) {
+ if (switch_true(val)) {
+ sofia_set_pflag(profile, PFLAG_IN_DIALOG_CHAT);
+ } else {
+ sofia_clear_pflag(profile, PFLAG_IN_DIALOG_CHAT);
+ }
} else if (!strcasecmp(var, "t38-passthru")) {
if (switch_true(val)) {
sofia_set_pflag(profile, PFLAG_T38_PASSTHRU);
sofia_private->is_call++;
tech_pvt->sofia_private = sofia_private;
- if ((profile->pres_type)) {
+ if (profile->pres_type && sofia_test_pflag(profile, PFLAG_IN_DIALOG_CHAT)) {
sofia_presence_set_chat_hash(tech_pvt, sip);
}
switch_copy_string(tech_pvt->sofia_private->uuid, switch_core_session_get_uuid(session), sizeof(tech_pvt->sofia_private->uuid));
nua_handle_bind(tech_pvt->nh, tech_pvt->sofia_private);
}
- if (tech_pvt->e_dest) {
+ if (tech_pvt->e_dest && sofia_test_pflag(tech_pvt->profile, PFLAG_IN_DIALOG_CHAT)) {
char *user = NULL, *host = NULL;
char hash_key[256] = "";
switch_status_t sofia_presence_chat_send(const char *proto, const char *from, const char *to, const char *subject,
const char *body, const char *type, const char *hint)
{
- char buf[256];
char *prof = NULL, *user = NULL, *host = NULL;
sofia_profile_t *profile = NULL;
char *ffrom = NULL;
const char *ct = "text/html";
sofia_destination_t *dst = NULL;
char *to_uri = NULL;
+ switch_console_callback_match_t *list = NULL;
+ switch_console_callback_match_node_t *m;
if (!to) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing To: header.\n");
host = prof;
}
}
-
- if (!to_uri && !sofia_reg_find_reg_url(profile, user, host, buf, sizeof(buf))) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot find user. [%s][%s]\n", user, host);
+
+ if (to_uri) {
+ switch_console_push_match(&list, to_uri);
+ } else if (!(list = sofia_reg_find_reg_url_multi(profile, user, host))) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't find registered user %s@%s\n", user, host);
goto end;
}
-
+
if (!strcasecmp(proto, SOFIA_CHAT_PROTO)) {
from = hint;
} else {
char *fp, *p = NULL;
-
+
fp = strdup(from);
if (!fp) {
switch_safe_free(fp);
}
- if (!(dst = sofia_glue_get_destination(to_uri ? to_uri : buf))) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Memory Error!\n");
- goto end;
- }
-
- /* sofia_glue is running sofia_overcome_sip_uri_weakness we do not, not sure if it matters */
-
- status = SWITCH_STATUS_SUCCESS;
- /* if this cries, add contact here too, change the 1 to 0 and omit the safe_free */
- msg_nh = nua_handle(profile->nua, NULL, TAG_IF(dst->route_uri, NUTAG_PROXY(dst->route_uri)), TAG_IF(dst->route, SIPTAG_ROUTE_STR(dst->route)),
- SIPTAG_FROM_STR(from), TAG_IF(contact, NUTAG_URL(contact)), SIPTAG_TO_STR(dst->to), SIPTAG_CONTACT_STR(profile->url), TAG_END());
- nua_handle_bind(msg_nh, &mod_sofia_globals.destroy_private);
- nua_message(msg_nh, SIPTAG_CONTENT_TYPE_STR(ct), SIPTAG_PAYLOAD_STR(body), TAG_END());
+ for (m = list->head; m; m = m->next) {
+ 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 */
+
+ status = SWITCH_STATUS_SUCCESS;
+ /* if this cries, add contact here too, change the 1 to 0 and omit the safe_free */
+ msg_nh = nua_handle(profile->nua, NULL, TAG_IF(dst->route_uri, NUTAG_PROXY(dst->route_uri)), TAG_IF(dst->route, SIPTAG_ROUTE_STR(dst->route)),
+ SIPTAG_FROM_STR(from), TAG_IF(contact, NUTAG_URL(contact)), SIPTAG_TO_STR(dst->to), SIPTAG_CONTACT_STR(profile->url), TAG_END());
+ nua_handle_bind(msg_nh, &mod_sofia_globals.destroy_private);
+ nua_message(msg_nh, SIPTAG_CONTENT_TYPE_STR(ct), SIPTAG_PAYLOAD_STR(body), TAG_END());
+ sofia_glue_free_destination(dst);
+ }
+
+ switch_console_free_matches(&list);
end:
- sofia_glue_free_destination(dst);
+
switch_safe_free(contact);
switch_safe_free(ffrom);
switch_safe_free(dup);
from_addr = switch_mprintf("%s@%s", from_user, from_host);
- sofia_presence_set_hash_key(hash_key, sizeof(hash_key), sip);
- if ((tech_pvt = (private_object_t *) switch_core_hash_find(profile->chat_hash, hash_key))) {
+ if (sofia_test_pflag(profile, PFLAG_IN_DIALOG_CHAT)) {
+ sofia_presence_set_hash_key(hash_key, sizeof(hash_key), sip);
+ }
+
+ if (sofia_test_pflag(profile, PFLAG_IN_DIALOG_CHAT) && (tech_pvt = (private_object_t *) switch_core_hash_find(profile->chat_hash, hash_key))) {
channel = switch_core_session_get_channel(tech_pvt->session);
if (switch_event_create(&event, SWITCH_EVENT_MESSAGE) == SWITCH_STATUS_SUCCESS) {
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "proto", SOFIA_CHAT_PROTO);
{
struct callback_t *cbt = (struct callback_t *) pArg;
+ if (!cbt->len) {
+ switch_console_push_match(&cbt->list, argv[0]);
+ cbt->matches++;
+ return 0;
+ }
+
switch_copy_string(cbt->val, argv[0], cbt->len);
cbt->matches++;
- return 0;
+ return cbt->matches == 1 ? 0 : 1;
}
int sofia_reg_nat_callback(void *pArg, int argc, char **argv, char **columnNames)
}
+switch_console_callback_match_t *sofia_reg_find_reg_url_multi(sofia_profile_t *profile, const char *user, const char *host)
+{
+ struct callback_t cbt = { 0 };
+ char sql[512] = "";
+
+ if (!user) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Called with null user!\n");
+ return NULL;
+ }
+
+ if (host) {
+ switch_snprintf(sql, sizeof(sql), "select contact from sip_registrations where sip_user='%s' and (sip_host='%s' or presence_hosts like '%%%s%%')",
+ user, host, host);
+ } else {
+ switch_snprintf(sql, sizeof(sql), "select contact from sip_registrations where sip_user='%s'", user);
+ }
+
+
+ sofia_glue_execute_sql_callback(profile, profile->ireg_mutex, sql, sofia_reg_find_callback, &cbt);
+
+ return cbt.list;
+}
+
+
void sofia_reg_auth_challenge(nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sofia_regtype_t regtype, const char *realm, int stale)
{
switch_uuid_t uuid;
status = input_callback(session_a, event, SWITCH_INPUT_TYPE_EVENT, user_data, 0);
}
- if (event->event_id != SWITCH_EVENT_COMMAND || switch_core_session_receive_event(session_b, &event) != SWITCH_STATUS_SUCCESS) {
+ if ((event->event_id != SWITCH_EVENT_COMMAND && event->event_id != SWITCH_EVENT_MESSAGE)
+ || switch_core_session_receive_event(session_b, &event) != SWITCH_STATUS_SUCCESS) {
switch_event_destroy(&event);
}