2005-11-19 20:07:43 +00:00
|
|
|
/*
|
|
|
|
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
|
|
|
|
* Copyright (C) 2005/2006, Anthony Minessale II <anthmct@yahoo.com>
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* Anthony Minessale II <anthmct@yahoo.com>
|
|
|
|
* Portions created by the Initial Developer are Copyright (C)
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
* Anthony Minessale II <anthmct@yahoo.com>
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* switch_caller.c -- Caller Identification
|
|
|
|
*
|
|
|
|
*/
|
2006-04-29 01:00:52 +00:00
|
|
|
#include <switch.h>
|
2006-04-29 06:05:03 +00:00
|
|
|
#include <switch_caller.h>
|
2005-11-19 20:07:43 +00:00
|
|
|
|
2006-04-29 06:05:03 +00:00
|
|
|
SWITCH_DECLARE(switch_caller_profile_t *) switch_caller_profile_new(switch_memory_pool_t *pool,
|
2006-05-26 16:00:08 +00:00
|
|
|
char *username,
|
|
|
|
char *dialplan,
|
|
|
|
char *caller_id_name,
|
|
|
|
char *caller_id_number,
|
|
|
|
char *network_addr,
|
|
|
|
char *ani,
|
2006-10-17 23:33:32 +00:00
|
|
|
char *aniii,
|
2006-05-26 16:00:08 +00:00
|
|
|
char *rdnis,
|
|
|
|
char *source,
|
|
|
|
char *context,
|
|
|
|
char *destination_number)
|
2005-11-19 20:07:43 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
|
2006-04-29 06:05:03 +00:00
|
|
|
switch_caller_profile_t *profile = NULL;
|
2005-11-19 20:07:43 +00:00
|
|
|
|
2006-04-29 06:05:03 +00:00
|
|
|
if ((profile = switch_core_alloc(pool, sizeof(switch_caller_profile_t))) != 0) {
|
2006-04-28 19:46:57 +00:00
|
|
|
if (!context) {
|
|
|
|
context = "default";
|
|
|
|
}
|
2006-05-26 16:00:08 +00:00
|
|
|
profile->username = switch_core_strdup(pool, username);
|
2006-03-01 22:55:28 +00:00
|
|
|
profile->dialplan = switch_core_strdup(pool, dialplan);
|
|
|
|
profile->caller_id_name = switch_core_strdup(pool, caller_id_name);
|
|
|
|
profile->caller_id_number = switch_core_strdup(pool, caller_id_number);
|
|
|
|
profile->network_addr = switch_core_strdup(pool, network_addr);
|
|
|
|
profile->ani = switch_core_strdup(pool, ani);
|
2006-10-17 23:33:32 +00:00
|
|
|
profile->aniii = switch_core_strdup(pool, aniii);
|
2006-04-21 22:31:08 +00:00
|
|
|
profile->rdnis = switch_core_strdup(pool, rdnis);
|
|
|
|
profile->source = switch_core_strdup(pool, source);
|
2006-04-28 19:46:57 +00:00
|
|
|
profile->context = switch_core_strdup(pool, context);
|
2006-03-01 22:55:28 +00:00
|
|
|
profile->destination_number = switch_core_strdup(pool, destination_number);
|
2006-10-16 04:39:00 +00:00
|
|
|
switch_set_flag(profile, SWITCH_CPF_SCREEN);
|
2005-11-19 20:07:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return profile;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-04-29 06:05:03 +00:00
|
|
|
SWITCH_DECLARE(switch_caller_profile_t *) switch_caller_profile_clone(switch_core_session_t *session, switch_caller_profile_t *tocopy)
|
2006-04-21 22:31:08 +00:00
|
|
|
|
2005-11-19 20:07:43 +00:00
|
|
|
{
|
2006-04-29 06:05:03 +00:00
|
|
|
switch_caller_profile_t *profile = NULL;
|
|
|
|
if ((profile = switch_core_session_alloc(session, sizeof(switch_caller_profile_t))) != 0) {
|
2006-05-26 16:00:08 +00:00
|
|
|
profile->username = switch_core_session_strdup(session, tocopy->username);
|
2005-11-19 20:07:43 +00:00
|
|
|
profile->dialplan = switch_core_session_strdup(session, tocopy->dialplan);
|
|
|
|
profile->caller_id_name = switch_core_session_strdup(session, tocopy->caller_id_name);
|
|
|
|
profile->ani = switch_core_session_strdup(session, tocopy->ani);
|
2006-10-17 23:33:32 +00:00
|
|
|
profile->aniii = switch_core_session_strdup(session, tocopy->aniii);
|
2005-11-19 20:07:43 +00:00
|
|
|
profile->caller_id_number = switch_core_session_strdup(session, tocopy->caller_id_number);
|
2005-12-20 16:01:18 +00:00
|
|
|
profile->network_addr = switch_core_session_strdup(session, tocopy->network_addr);
|
2006-04-21 22:31:08 +00:00
|
|
|
profile->rdnis = switch_core_session_strdup(session, tocopy->rdnis);
|
2005-11-19 20:07:43 +00:00
|
|
|
profile->destination_number = switch_core_session_strdup(session, tocopy->destination_number);
|
2006-02-22 02:50:33 +00:00
|
|
|
profile->uuid = switch_core_session_strdup(session, tocopy->uuid);
|
2006-04-21 22:31:08 +00:00
|
|
|
profile->source = switch_core_session_strdup(session, tocopy->source);
|
2006-04-28 19:46:57 +00:00
|
|
|
profile->context = switch_core_session_strdup(session, tocopy->context);
|
2006-02-22 02:50:33 +00:00
|
|
|
profile->chan_name = switch_core_session_strdup(session, tocopy->chan_name);
|
2006-10-16 04:39:00 +00:00
|
|
|
profile->flags = tocopy->flags;
|
2005-11-19 20:07:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return profile;
|
|
|
|
}
|
|
|
|
|
2006-05-10 03:23:05 +00:00
|
|
|
SWITCH_DECLARE(char *) switch_caller_get_field_by_name(switch_caller_profile_t *caller_profile, char *name)
|
|
|
|
{
|
|
|
|
if (!strcasecmp(name, "dialplan")) {
|
|
|
|
return caller_profile->dialplan;
|
|
|
|
}
|
2006-05-26 16:00:08 +00:00
|
|
|
if (!strcasecmp(name, "username")) {
|
|
|
|
return caller_profile->username;
|
|
|
|
}
|
2006-05-10 03:23:05 +00:00
|
|
|
if (!strcasecmp(name, "caller_id_name")) {
|
|
|
|
return caller_profile->caller_id_name;
|
|
|
|
}
|
|
|
|
if (!strcasecmp(name, "ani")) {
|
|
|
|
return caller_profile->ani;
|
|
|
|
}
|
2006-10-17 23:33:32 +00:00
|
|
|
if (!strcasecmp(name, "aniii")) {
|
|
|
|
return caller_profile->aniii;
|
2006-05-10 03:23:05 +00:00
|
|
|
}
|
|
|
|
if (!strcasecmp(name, "caller_id_number")) {
|
|
|
|
return caller_profile->caller_id_number;
|
|
|
|
}
|
|
|
|
if (!strcasecmp(name, "network_addr")) {
|
|
|
|
return caller_profile->network_addr;
|
|
|
|
}
|
|
|
|
if (!strcasecmp(name, "rdnis")) {
|
|
|
|
return caller_profile->rdnis;
|
|
|
|
}
|
|
|
|
if (!strcasecmp(name, "destination_number")) {
|
|
|
|
return caller_profile->destination_number;
|
|
|
|
}
|
|
|
|
if (!strcasecmp(name, "uuid")) {
|
|
|
|
return caller_profile->uuid;
|
|
|
|
}
|
|
|
|
if (!strcasecmp(name, "source")) {
|
|
|
|
return caller_profile->source;
|
|
|
|
}
|
|
|
|
if (!strcasecmp(name, "context")) {
|
|
|
|
return caller_profile->context;
|
|
|
|
}
|
|
|
|
if (!strcasecmp(name, "chan_name")) {
|
|
|
|
return caller_profile->chan_name;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2006-04-29 06:05:03 +00:00
|
|
|
SWITCH_DECLARE(void) switch_caller_profile_event_set_data(switch_caller_profile_t *caller_profile, char *prefix,
|
2006-04-29 01:00:52 +00:00
|
|
|
switch_event_t *event)
|
2005-12-23 21:09:36 +00:00
|
|
|
{
|
2005-12-26 19:09:59 +00:00
|
|
|
char header_name[1024];
|
|
|
|
|
2006-05-26 16:00:08 +00:00
|
|
|
|
|
|
|
if (caller_profile->username) {
|
|
|
|
snprintf(header_name, sizeof(header_name), "%s-Username", prefix);
|
2006-10-06 22:39:49 +00:00
|
|
|
switch_event_add_header(event, SWITCH_STACK_BOTTOM, header_name, "%s", caller_profile->username);
|
2006-05-26 16:00:08 +00:00
|
|
|
}
|
2005-12-26 19:09:59 +00:00
|
|
|
if (caller_profile->dialplan) {
|
|
|
|
snprintf(header_name, sizeof(header_name), "%s-Dialplan", prefix);
|
2006-10-06 22:39:49 +00:00
|
|
|
switch_event_add_header(event, SWITCH_STACK_BOTTOM, header_name, "%s", caller_profile->dialplan);
|
2005-12-26 19:09:59 +00:00
|
|
|
}
|
|
|
|
if (caller_profile->caller_id_name) {
|
|
|
|
snprintf(header_name, sizeof(header_name), "%s-Caller-ID-Name", prefix);
|
2006-10-06 22:39:49 +00:00
|
|
|
switch_event_add_header(event, SWITCH_STACK_BOTTOM, header_name, "%s", caller_profile->caller_id_name);
|
2005-12-26 19:09:59 +00:00
|
|
|
}
|
|
|
|
if (caller_profile->caller_id_number) {
|
|
|
|
snprintf(header_name, sizeof(header_name), "%s-Caller-ID-Number", prefix);
|
2006-10-06 22:39:49 +00:00
|
|
|
switch_event_add_header(event, SWITCH_STACK_BOTTOM, header_name, "%s", caller_profile->caller_id_number);
|
2005-12-26 19:09:59 +00:00
|
|
|
}
|
|
|
|
if (caller_profile->network_addr) {
|
|
|
|
snprintf(header_name, sizeof(header_name), "%s-Network-Addr", prefix);
|
2006-10-06 22:39:49 +00:00
|
|
|
switch_event_add_header(event, SWITCH_STACK_BOTTOM, header_name, "%s", caller_profile->network_addr);
|
2005-12-26 19:09:59 +00:00
|
|
|
}
|
|
|
|
if (caller_profile->ani) {
|
|
|
|
snprintf(header_name, sizeof(header_name), "%s-ANI", prefix);
|
2006-10-06 22:39:49 +00:00
|
|
|
switch_event_add_header(event, SWITCH_STACK_BOTTOM, header_name, "%s", caller_profile->ani);
|
2005-12-26 19:09:59 +00:00
|
|
|
}
|
2006-10-17 23:33:32 +00:00
|
|
|
if (caller_profile->aniii) {
|
|
|
|
snprintf(header_name, sizeof(header_name), "%s-ANI-II", prefix);
|
|
|
|
switch_event_add_header(event, SWITCH_STACK_BOTTOM, header_name, "%s", caller_profile->aniii);
|
2005-12-26 19:09:59 +00:00
|
|
|
}
|
|
|
|
if (caller_profile->destination_number) {
|
|
|
|
snprintf(header_name, sizeof(header_name), "%s-Destination-Number", prefix);
|
2006-10-06 22:39:49 +00:00
|
|
|
switch_event_add_header(event, SWITCH_STACK_BOTTOM, header_name, "%s", caller_profile->destination_number);
|
2005-12-26 19:09:59 +00:00
|
|
|
}
|
2006-04-11 14:55:14 +00:00
|
|
|
if (caller_profile->uuid) {
|
|
|
|
snprintf(header_name, sizeof(header_name), "%s-Unique-ID", prefix);
|
2006-10-06 22:39:49 +00:00
|
|
|
switch_event_add_header(event, SWITCH_STACK_BOTTOM, header_name, "%s", caller_profile->uuid);
|
2006-04-11 14:55:14 +00:00
|
|
|
}
|
2006-04-21 22:31:08 +00:00
|
|
|
if (caller_profile->source) {
|
2006-04-28 19:46:57 +00:00
|
|
|
snprintf(header_name, sizeof(header_name), "%s-Source", prefix);
|
2006-10-06 22:39:49 +00:00
|
|
|
switch_event_add_header(event, SWITCH_STACK_BOTTOM, header_name, "%s", caller_profile->source);
|
2006-04-21 22:31:08 +00:00
|
|
|
}
|
2006-04-28 19:46:57 +00:00
|
|
|
if (caller_profile->context) {
|
|
|
|
snprintf(header_name, sizeof(header_name), "%s-Context", prefix);
|
2006-10-06 22:39:49 +00:00
|
|
|
switch_event_add_header(event, SWITCH_STACK_BOTTOM, header_name, "%s", caller_profile->context);
|
2006-04-28 19:46:57 +00:00
|
|
|
}
|
2006-04-21 22:31:08 +00:00
|
|
|
if (caller_profile->rdnis) {
|
|
|
|
snprintf(header_name, sizeof(header_name), "%s-RDNIS", prefix);
|
2006-10-06 22:39:49 +00:00
|
|
|
switch_event_add_header(event, SWITCH_STACK_BOTTOM, header_name, "%s", caller_profile->rdnis);
|
2006-04-21 22:31:08 +00:00
|
|
|
}
|
2006-04-11 14:55:14 +00:00
|
|
|
if (caller_profile->chan_name) {
|
|
|
|
snprintf(header_name, sizeof(header_name), "%s-Channel-Name", prefix);
|
2006-10-06 22:39:49 +00:00
|
|
|
switch_event_add_header(event, SWITCH_STACK_BOTTOM, header_name, "%s", caller_profile->chan_name);
|
2006-04-11 14:55:14 +00:00
|
|
|
}
|
2005-12-23 21:09:36 +00:00
|
|
|
|
2006-10-16 04:39:00 +00:00
|
|
|
snprintf(header_name, sizeof(header_name), "%s-Screen-Bit", prefix);
|
|
|
|
switch_event_add_header(event, SWITCH_STACK_BOTTOM, header_name, switch_test_flag(caller_profile, SWITCH_CPF_SCREEN) ? "yes" : "no");
|
|
|
|
|
|
|
|
snprintf(header_name, sizeof(header_name), "%s-Privacy-Hide-Name", prefix);
|
|
|
|
switch_event_add_header(event, SWITCH_STACK_BOTTOM, header_name, switch_test_flag(caller_profile, SWITCH_CPF_HIDE_NAME) ? "yes" : "no");
|
|
|
|
|
|
|
|
snprintf(header_name, sizeof(header_name), "%s-Privacy-Hide-Number", prefix);
|
|
|
|
switch_event_add_header(event, SWITCH_STACK_BOTTOM, header_name, switch_test_flag(caller_profile, SWITCH_CPF_HIDE_NUMBER) ? "yes" : "no");
|
|
|
|
|
|
|
|
|
|
|
|
|
2005-12-23 21:09:36 +00:00
|
|
|
}
|
|
|
|
|
2006-04-29 06:05:03 +00:00
|
|
|
SWITCH_DECLARE(switch_caller_extension_t *) switch_caller_extension_new(switch_core_session_t *session,
|
2006-01-20 15:05:05 +00:00
|
|
|
char *extension_name, char *extension_number)
|
2005-11-19 20:07:43 +00:00
|
|
|
{
|
2006-04-29 06:05:03 +00:00
|
|
|
switch_caller_extension_t *caller_extension = NULL;
|
2005-11-19 20:07:43 +00:00
|
|
|
|
2006-04-29 06:05:03 +00:00
|
|
|
if ((caller_extension = switch_core_session_alloc(session, sizeof(switch_caller_extension_t))) != 0) {
|
2005-11-19 20:07:43 +00:00
|
|
|
caller_extension->extension_name = switch_core_session_strdup(session, extension_name);
|
|
|
|
caller_extension->extension_number = switch_core_session_strdup(session, extension_number);
|
|
|
|
caller_extension->current_application = caller_extension->last_application = caller_extension->applications;
|
|
|
|
}
|
|
|
|
|
|
|
|
return caller_extension;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-04-29 06:05:03 +00:00
|
|
|
SWITCH_DECLARE(void) switch_caller_extension_add_application(switch_core_session_t *session,
|
|
|
|
switch_caller_extension_t *caller_extension,
|
2006-01-20 15:05:05 +00:00
|
|
|
char *application_name, char *application_data)
|
2005-11-19 20:07:43 +00:00
|
|
|
{
|
2006-04-29 06:05:03 +00:00
|
|
|
switch_caller_application_t *caller_application = NULL;
|
2005-11-19 20:07:43 +00:00
|
|
|
|
|
|
|
assert(session != NULL);
|
|
|
|
|
2006-04-29 06:05:03 +00:00
|
|
|
if ((caller_application = switch_core_session_alloc(session, sizeof(switch_caller_application_t))) != 0) {
|
2005-11-19 20:07:43 +00:00
|
|
|
caller_application->application_name = switch_core_session_strdup(session, application_name);
|
|
|
|
caller_application->application_data = switch_core_session_strdup(session, application_data);
|
|
|
|
if (!caller_extension->applications) {
|
|
|
|
caller_extension->applications = caller_application;
|
2006-01-20 15:05:05 +00:00
|
|
|
} else if (caller_extension->last_application) {
|
2005-11-19 20:07:43 +00:00
|
|
|
caller_extension->last_application->next = caller_application;
|
|
|
|
}
|
|
|
|
|
|
|
|
caller_extension->last_application = caller_application;
|
|
|
|
caller_extension->current_application = caller_extension->applications;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2006-11-27 22:30:48 +00:00
|
|
|
|
|
|
|
/* For Emacs:
|
|
|
|
* Local Variables:
|
|
|
|
* mode:c
|
|
|
|
* indent-tabs-mode:nil
|
|
|
|
* tab-width:4
|
|
|
|
* c-basic-offset:4
|
|
|
|
* End:
|
|
|
|
* For VIM:
|
|
|
|
* vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab:
|
|
|
|
*/
|