Merge branch 'master' into smgmaster

Conflicts:
	build/modules.conf.in
This commit is contained in:
Moises Silva committed 2011-06-16 13:43:37 -04:00
commit 2a9046fdb8
608 files changed
+33546 -20511

No files matched your search

+2
View File
@@ -1323,6 +1323,8 @@ SWITCH_DECLARE(switch_status_t) switch_socket_send(switch_socket_t *sock, const
*/
SWITCH_DECLARE(switch_status_t) switch_socket_sendto(switch_socket_t *sock, switch_sockaddr_t *where, int32_t flags, const char *buf,
switch_size_t *len);
SWITCH_DECLARE(switch_status_t) switch_socket_send_nonblock(switch_socket_t *sock, const char *buf, switch_size_t *len);
/**
* @param from The apr_sockaddr_t to fill in the recipient info
+2
View File
@@ -109,6 +109,8 @@ SWITCH_DECLARE(switch_size_t) switch_buffer_read(_In_ switch_buffer_t *buffer, _
*/
SWITCH_DECLARE(switch_size_t) switch_buffer_peek(_In_ switch_buffer_t *buffer, _In_ void *data, _In_ switch_size_t datalen);
SWITCH_DECLARE(switch_size_t) switch_buffer_peek_zerocopy(_In_ switch_buffer_t *buffer, _Out_ const void **ptr);
/*! \brief Read data endlessly from a switch_buffer_t
* \param buffer any buffer of type switch_buffer_t
* \param data pointer to the read data to be returned
+6 -2
View File
@@ -251,6 +251,8 @@ SWITCH_DECLARE(switch_status_t) switch_channel_set_profile_var(switch_channel_t
SWITCH_DECLARE(switch_status_t) switch_channel_set_variable_var_check(switch_channel_t *channel,
const char *varname, const char *value, switch_bool_t var_check);
SWITCH_DECLARE(switch_status_t) switch_channel_add_variable_var_check(switch_channel_t *channel,
const char *varname, const char *value, switch_bool_t var_check, switch_stack_t stack);
SWITCH_DECLARE(switch_status_t) switch_channel_set_variable_printf(switch_channel_t *channel, const char *varname, const char *fmt, ...);
SWITCH_DECLARE(switch_status_t) switch_channel_set_variable_name_printf(switch_channel_t *channel, const char *val, const char *fmt, ...);
@@ -277,6 +279,8 @@ SWITCH_DECLARE(void) switch_channel_process_export(switch_channel_t *channel, sw
SWITCH_DECLARE(switch_status_t) switch_channel_export_variable_printf(switch_channel_t *channel, const char *varname,
const char *export_varname, const char *fmt, ...);
SWITCH_DECLARE(void) switch_channel_set_scope_variables(switch_channel_t *channel, switch_event_t **event);
SWITCH_DECLARE(switch_status_t) switch_channel_get_scope_variables(switch_channel_t *channel, switch_event_t **event);
/*!
\brief Retrieve a variable from a given channel
@@ -284,8 +288,8 @@ SWITCH_DECLARE(switch_status_t) switch_channel_export_variable_printf(switch_cha
\param varname the name of the variable
\return the value of the requested variable
*/
SWITCH_DECLARE(const char *) switch_channel_get_variable_dup(switch_channel_t *channel, const char *varname, switch_bool_t dup);
#define switch_channel_get_variable(_c, _v) switch_channel_get_variable_dup(_c, _v, SWITCH_TRUE)
SWITCH_DECLARE(const char *) switch_channel_get_variable_dup(switch_channel_t *channel, const char *varname, switch_bool_t dup, int idx);
#define switch_channel_get_variable(_c, _v) switch_channel_get_variable_dup(_c, _v, SWITCH_TRUE, -1)
SWITCH_DECLARE(switch_status_t) switch_channel_get_variables(switch_channel_t *channel, switch_event_t **event);
+29 -2
View File
@@ -248,6 +248,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_bug_close(_Inout_ switch_media
SWITCH_DECLARE(switch_status_t) switch_core_media_bug_remove_all(_In_ switch_core_session_t *session);
SWITCH_DECLARE(switch_status_t) switch_core_media_bug_enumerate(switch_core_session_t *session, switch_stream_handle_t *stream);
SWITCH_DECLARE(switch_status_t) switch_core_media_bug_transfer_recordings(switch_core_session_t *orig_session, switch_core_session_t *new_session);
/*!
\brief Read a frame from the bug
@@ -1226,7 +1227,15 @@ SWITCH_DECLARE(switch_status_t) switch_core_hash_insert(_In_ switch_hash_t *hash
\note the string key must be a constant or a dynamic string
*/
SWITCH_DECLARE(switch_status_t) switch_core_hash_insert_locked(_In_ switch_hash_t *hash, _In_z_ const char *key, _In_opt_ const void *data,
_In_ switch_mutex_t *mutex);
_In_opt_ switch_mutex_t *mutex);
/*!
\brief Retrieve data from a given hash
\param hash the hash to retrieve from
\param key the key to retrieve
\param mutex optional rwlock to wrlock
\return a pointer to the data held in the key
*/
SWITCH_DECLARE(switch_status_t) switch_core_hash_insert_wrlock(switch_hash_t *hash, const char *key, const void *data, switch_thread_rwlock_t *rwlock);
/*!
\brief Delete data from a hash based on desired key
@@ -1243,7 +1252,16 @@ SWITCH_DECLARE(switch_status_t) switch_core_hash_delete(_In_ switch_hash_t *hash
\param mutex optional mutex to lock
\return SWITCH_STATUS_SUCCESS if the data is deleted
*/
SWITCH_DECLARE(switch_status_t) switch_core_hash_delete_locked(_In_ switch_hash_t *hash, _In_z_ const char *key, _In_ switch_mutex_t *mutex);
SWITCH_DECLARE(switch_status_t) switch_core_hash_delete_locked(_In_ switch_hash_t *hash, _In_z_ const char *key, _In_opt_ switch_mutex_t *mutex);
/*!
\brief Delete data from a hash based on desired key
\param hash the hash to delete from
\param key the key from which to delete the data
\param mutex optional rwlock to wrlock
\return SWITCH_STATUS_SUCCESS if the data is deleted
*/
SWITCH_DECLARE(switch_status_t) switch_core_hash_delete_wrlock(_In_ switch_hash_t *hash, _In_z_ const char *key, _In_opt_ switch_thread_rwlock_t *rwlock);
/*!
\brief Delete data from a hash based on callback function
@@ -1271,6 +1289,15 @@ SWITCH_DECLARE(void *) switch_core_hash_find(_In_ switch_hash_t *hash, _In_z_ co
*/
SWITCH_DECLARE(void *) switch_core_hash_find_locked(_In_ switch_hash_t *hash, _In_z_ const char *key, _In_ switch_mutex_t *mutex);
/*!
\brief Retrieve data from a given hash
\param hash the hash to retrieve from
\param key the key to retrieve
\param mutex optional rwlock to rdlock
\return a pointer to the data held in the key
*/
SWITCH_DECLARE(void *) switch_core_hash_find_rdlock(_In_ switch_hash_t *hash, _In_z_ const char *key, _In_ switch_thread_rwlock_t *rwlock);
/*!
\brief Gets the first element of a hashtable
\param depricate_me [deprecated] NULL
-7
View File
@@ -40,9 +40,6 @@ static inline void switch_curl_init(void)
if (curl_count == 0) {
curl_global_init(CURL_GLOBAL_ALL);
#if defined(HAVE_OPENSSL)
switch_ssl_init_ssl_locks();
#endif
}
curl_count++;
@@ -56,10 +53,6 @@ static inline void switch_curl_destroy()
curl_count--;
if (curl_count == 0) {
#if defined(HAVE_OPENSSL)
switch_ssl_destroy_ssl_locks();
#endif
curl_global_cleanup();
}
switch_core_curl_count(&curl_count);
+9 -2
View File
@@ -67,6 +67,10 @@ SWITCH_BEGIN_EXTERN_C
char *name;
/*! the header value */
char *value;
/*! array space */
char **array;
/*! array index */
int idx;
/*! hash of the header name */
unsigned long hash;
struct switch_event_header *next;
@@ -146,7 +150,10 @@ SWITCH_DECLARE(switch_status_t) switch_event_set_priority(switch_event_t *event,
\param header_name the name of the header to read
\return the value of the requested header
*/
_Ret_opt_z_ SWITCH_DECLARE(char *) switch_event_get_header(switch_event_t *event, const char *header_name);
SWITCH_DECLARE(switch_event_header_t *) switch_event_get_header_ptr(switch_event_t *event, const char *header_name);
_Ret_opt_z_ SWITCH_DECLARE(char *) switch_event_get_header_idx(switch_event_t *event, const char *header_name, int idx);
#define switch_event_get_header(_e, _h) switch_event_get_header_idx(_e, _h, -1)
#define switch_event_get_header_nil(e, h) switch_str_nil(switch_event_get_header(e,h))
@@ -184,7 +191,7 @@ SWITCH_DECLARE(switch_status_t) switch_event_add_header_string(switch_event_t *e
SWITCH_DECLARE(switch_status_t) switch_event_del_header_val(switch_event_t *event, const char *header_name, const char *val);
#define switch_event_del_header(_e, _h) switch_event_del_header_val(_e, _h, NULL)
SWITCH_DECLARE(int) switch_event_add_array(switch_event_t *event, const char *var, const char *val);
/*!
\brief Destroy an event
\param event pointer to the pointer to event to destroy
+6
View File
@@ -62,6 +62,12 @@ SWITCH_BEGIN_EXTERN_C struct switch_unicast_conninfo {
};
typedef struct switch_unicast_conninfo switch_unicast_conninfo_t;
#define SWITCH_IVR_VERIFY_SILENCE_DIVISOR(divisor) \
{ \
if ((divisor) <= 0 && (divisor) != -1) { \
divisor = 400; \
} \
}
/**
* @defgroup switch_ivr IVR Library
+4
View File
@@ -70,6 +70,10 @@ SWITCH_DECLARE(switch_status_t) switch_regex_match(const char *target, const cha
*/
SWITCH_DECLARE(switch_status_t) switch_regex_match_partial(const char *target, const char *expression, int *partial_match);
SWITCH_DECLARE(void) switch_capture_regex(switch_regex_t *re, int match_count, const char *field_data,
int *ovector, const char *var, switch_cap_callback_t callback, void *user_data);
SWITCH_DECLARE_NONSTD(void) switch_regex_set_var_callback(const char *var, const char *val, void *user_data);
#define switch_regex_safe_free(re) if (re) {\
switch_regex_free(re);\
+3 -1
View File
@@ -90,7 +90,9 @@ static inline void switch_ssl_destroy_ssl_locks()
if (ssl_count == 0) {
CRYPTO_set_locking_callback(NULL);
for (i = 0; i < CRYPTO_num_locks(); i++) {
switch_mutex_destroy(ssl_mutexes[i]);
if (ssl_mutexes[i]) {
switch_mutex_destroy(ssl_mutexes[i]);
}
}
OPENSSL_free(ssl_mutexes);
+7 -2
View File
@@ -830,7 +830,9 @@ SWITCH_STACK_TOP - Stack on the top
typedef enum {
SWITCH_STACK_BOTTOM = (1 << 0),
SWITCH_STACK_TOP = (1 << 1),
SWITCH_STACK_NODUP = (1 << 2)
SWITCH_STACK_NODUP = (1 << 2),
SWITCH_STACK_UNSHIFT = (1 << 3),
SWITCH_STACK_PUSH = (1 << 4),
} switch_stack_t;
/*!
@@ -1118,7 +1120,9 @@ typedef enum {
typedef enum {
CF_APP_TAGGED = (1 << 0),
CF_APP_T38 = (1 << 1)
CF_APP_T38 = (1 << 1),
CF_APP_T38_REQ = (1 << 2),
CF_APP_T38_FAIL = (1 << 3)
} switch_channel_app_flag_t;
@@ -1688,6 +1692,7 @@ struct switch_console_callback_match {
};
typedef struct switch_console_callback_match switch_console_callback_match_t;
typedef void (*switch_cap_callback_t) (const char *var, const char *val, void *user_data);
typedef switch_status_t (*switch_console_complete_callback_t) (const char *, const char *, switch_console_callback_match_t **matches);
typedef switch_bool_t (*switch_media_bug_callback_t) (switch_media_bug_t *, void *, switch_abc_type_t);
typedef switch_bool_t (*switch_tone_detect_callback_t) (switch_core_session_t *, const char *, const char *);
+3 -3
View File
@@ -793,9 +793,9 @@ SWITCH_DECLARE(int) switch_split_user_domain(char *in, char **user, char **domai
/* malloc or DIE macros */
#ifdef NDEBUG
#define switch_malloc(ptr, len) (void)( (!!(ptr = malloc(len))) || (fprintf(stderr,"ABORT! Malloc failure at: %s:%s", __FILE__, __LINE__),abort(), 0), ptr )
#define switch_zmalloc(ptr, len) (void)( (!!(ptr = calloc(1, (len)))) || (fprintf(stderr,"ABORT! Malloc failure at: %s:%s", __FILE__, __LINE__),abort(), 0), ptr)
#define switch_strdup(ptr, s) (void)( (!!(ptr = strdup(s))) || (fprintf(stderr,"ABORT! Malloc failure at: %s:%s", __FILE__, __LINE__),abort(), 0), ptr)
#define switch_malloc(ptr, len) (void)( (!!(ptr = malloc(len))) || (fprintf(stderr,"ABORT! Malloc failure at: %s:%d", __FILE__, __LINE__),abort(), 0), ptr )
#define switch_zmalloc(ptr, len) (void)( (!!(ptr = calloc(1, (len)))) || (fprintf(stderr,"ABORT! Malloc failure at: %s:%d", __FILE__, __LINE__),abort(), 0), ptr)
#define switch_strdup(ptr, s) (void)( (!!(ptr = strdup(s))) || (fprintf(stderr,"ABORT! Malloc failure at: %s:%d", __FILE__, __LINE__),abort(), 0), ptr)
#else
#if (_MSC_VER >= 1500) // VC9+
#define switch_malloc(ptr, len) (void)(assert(((ptr) = malloc((len)))),ptr);__analysis_assume( ptr )
+1 -1
View File
@@ -378,7 +378,7 @@ SWITCH_DECLARE(switch_status_t) switch_xml_locate_user_in_domain(_In_z_ const ch
SWITCH_DECLARE(switch_status_t) switch_xml_locate_user_merged(const char *key, const char *user_name, const char *domain_name,
const char *ip, switch_xml_t *user, switch_event_t *params);
SWITCH_DECLARE(uint32_t) switch_xml_clear_user_cache(const char *key, const char *user_name, const char *domain_name);
SWITCH_DECLARE(void) switch_xml_merge_user(switch_xml_t user, switch_xml_t domain, switch_xml_t group);
SWITCH_DECLARE(switch_xml_t) switch_xml_dup(switch_xml_t xml);
@@ -2123,6 +2123,34 @@ SWITCH_STANDARD_API(kill_function)
return SWITCH_STATUS_SUCCESS;
}
#define OUTGOING_ANSWER_SYNTAX "<uuid>"
SWITCH_STANDARD_API(outgoing_answer_function)
{
switch_core_session_t *outgoing_session = NULL;
char *mycmd = NULL;
if (zstr(cmd) || !(mycmd = strdup(cmd))) {
stream->write_function(stream, "-USAGE: %s\n", OUTGOING_ANSWER_SYNTAX);
return SWITCH_STATUS_SUCCESS;
}
if (zstr(mycmd) || !(outgoing_session = switch_core_session_locate(mycmd))) {
stream->write_function(stream, "-ERR No Such Channel!\n");
} else {
switch_channel_t *channel = switch_core_session_get_channel(outgoing_session);
if (switch_channel_direction(channel) == SWITCH_CALL_DIRECTION_OUTBOUND) {
switch_channel_mark_answered(channel);
stream->write_function(stream, "+OK\n");
} else {
stream->write_function(stream, "-ERR Not an outbound channel!\n");
}
switch_core_session_rwunlock(outgoing_session);
}
switch_safe_free(mycmd);
return SWITCH_STATUS_SUCCESS;
}
#define PREPROCESS_SYNTAX "<>"
SWITCH_STANDARD_API(preprocess_function)
{
@@ -4720,6 +4748,30 @@ SWITCH_STANDARD_API(hupall_api_function)
return SWITCH_STATUS_SUCCESS;
}
SWITCH_STANDARD_API(xml_flush_function)
{
char *mycmd = NULL, *argv[3] = { 0 };
int argc = 0;
int r = 0;
if (!zstr(cmd) && (mycmd = strdup(cmd))) {
argc = switch_split(mycmd, ' ', argv);
}
if (argc == 3) {
r = switch_xml_clear_user_cache(argv[0], argv[1], argv[2]);
} else {
r = switch_xml_clear_user_cache(NULL, NULL, NULL);
}
stream->write_function(stream, "+OK cleared %u entr%s\n", r, r == 1 ? "y" : "ies");
switch_safe_free(mycmd);
return SWITCH_STATUS_SUCCESS;
}
SWITCH_STANDARD_API(escape_function)
{
int len;
@@ -5214,6 +5266,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_commands_load)
SWITCH_ADD_API(commands_api_interface, "uuid_getvar", "uuid_getvar", uuid_getvar_function, GETVAR_SYNTAX);
SWITCH_ADD_API(commands_api_interface, "uuid_hold", "hold", uuid_hold_function, HOLD_SYNTAX);
SWITCH_ADD_API(commands_api_interface, "uuid_kill", "Kill Channel", kill_function, KILL_SYNTAX);
SWITCH_ADD_API(commands_api_interface, "uuid_outgoing_answer", "Answer Outgoing Channel", outgoing_answer_function, OUTGOING_ANSWER_SYNTAX);
SWITCH_ADD_API(commands_api_interface, "uuid_limit", "Increase limit resource", uuid_limit_function, LIMIT_SYNTAX);
SWITCH_ADD_API(commands_api_interface, "uuid_limit_release", "Release limit resource", uuid_limit_release_function, LIMIT_RELEASE_SYNTAX);
SWITCH_ADD_API(commands_api_interface, "uuid_loglevel", "set loglevel on session", uuid_loglevel, UUID_LOGLEVEL_SYNTAX);
@@ -5233,8 +5286,11 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_commands_load)
SWITCH_ADD_API(commands_api_interface, "uuid_simplify", "Try to cut out of a call path / attended xfer", uuid_simplify_function, SIMPLIFY_SYNTAX);
SWITCH_ADD_API(commands_api_interface, "uuid_jitterbuffer", "Try to cut out of a call path / attended xfer",
uuid_jitterbuffer_function, JITTERBUFFER_SYNTAX);
SWITCH_ADD_API(commands_api_interface, "xml_flush_cache", "clear xml cache", xml_flush_function, "<id> <key> <val>");
SWITCH_ADD_API(commands_api_interface, "xml_locate", "find some xml", xml_locate_function, "[root | <section> <tag> <tag_attr_name> <tag_attr_val>]");
SWITCH_ADD_API(commands_api_interface, "xml_wrap", "Wrap another api command in xml", xml_wrap_api_function, "<command> <args>");
switch_console_set_complete("add alias add");
switch_console_set_complete("add alias del");
switch_console_set_complete("add complete add");
@@ -5333,6 +5389,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_commands_load)
switch_console_set_complete("add uuid_hold ::console::list_uuid");
switch_console_set_complete("add uuid_jitterbuffer ::console::list_uuid");
switch_console_set_complete("add uuid_kill ::console::list_uuid");
switch_console_set_complete("add uuid_outgoing_answer ::console::list_uuid");
switch_console_set_complete("add uuid_limit ::console::list_uuid");
switch_console_set_complete("add uuid_limit_release ::console::list_uuid");
switch_console_set_complete("add uuid_loglevel ::console::list_uuid console");
@@ -141,7 +141,10 @@ typedef enum {
MFLAG_MINTWO = (1 << 13),
MFLAG_MUTE_DETECT = (1 << 14),
MFLAG_DIST_DTMF = (1 << 15),
MFLAG_MOD = (1 << 16)
MFLAG_MOD = (1 << 16),
MFLAG_INDICATE_MUTE = (1 << 17),
MFLAG_INDICATE_UNMUTE = (1 << 18),
MFLAG_NOMOH = (1 << 19)
} member_flag_t;
typedef enum {
@@ -1094,6 +1097,7 @@ static void *SWITCH_THREAD_FUNC conference_thread_run(switch_thread_t *thread, v
switch_size_t file_data_len = samples * 2;
int has_file_data = 0, members_with_video = 0;
uint32_t conf_energy = 0;
int nomoh = 0;
/* Sync the conference to a single timing source */
if (switch_core_timer_next(&timer) != SWITCH_STATUS_SUCCESS) {
@@ -1104,11 +1108,6 @@ static void *SWITCH_THREAD_FUNC conference_thread_run(switch_thread_t *thread, v
switch_mutex_lock(conference->mutex);
has_file_data = ready = total = 0;
if (conference->perpetual_sound && !conference->async_fnode) {
conference_play_file(conference, conference->perpetual_sound, CONF_DEFAULT_LEADIN, NULL, 1);
} else if (conference->moh_sound && (conference->count == 1 || switch_test_flag(conference, CFLAG_WAIT_MOD)) && !conference->async_fnode) {
conference_play_file(conference, conference->moh_sound, CONF_DEFAULT_LEADIN, NULL, 1);
}
/* Read one frame of audio from each member channel and save it for redistribution */
for (imember = conference->members; imember; imember = imember->next) {
@@ -1116,8 +1115,14 @@ static void *SWITCH_THREAD_FUNC conference_thread_run(switch_thread_t *thread, v
total++;
imember->read = 0;
if (imember->session && switch_channel_test_flag(switch_core_session_get_channel(imember->session), CF_VIDEO)) {
members_with_video++;
if (imember->session) {
if (switch_channel_test_flag(switch_core_session_get_channel(imember->session), CF_VIDEO)) {
members_with_video++;
}
if (switch_test_flag(imember, MFLAG_NOMOH)) {
nomoh++;
}
}
switch_clear_flag_locked(imember, MFLAG_HAS_AUDIO);
@@ -1132,6 +1137,14 @@ static void *SWITCH_THREAD_FUNC conference_thread_run(switch_thread_t *thread, v
switch_mutex_unlock(imember->audio_in_mutex);
}
if (conference->perpetual_sound && !conference->async_fnode) {
conference_play_file(conference, conference->perpetual_sound, CONF_DEFAULT_LEADIN, NULL, 1);
} else if (conference->moh_sound && ((nomoh == 0 && conference->count == 1)
|| switch_test_flag(conference, CFLAG_WAIT_MOD)) && !conference->async_fnode) {
conference_play_file(conference, conference->moh_sound, CONF_DEFAULT_LEADIN, NULL, 1);
}
/* Find if no one talked for more than x number of second */
if (conference->terminate_on_silence && conference->count > 1) {
int is_talking = 0;
@@ -2494,6 +2507,7 @@ static void conference_loop_output(conference_member_t *member)
uint32_t low_count, bytes;
call_list_t *call_list, *cp;
switch_codec_implementation_t read_impl = { 0 };
int sanity;
switch_core_session_get_read_impl(member->session, &read_impl);
@@ -2594,6 +2608,13 @@ static void conference_loop_output(conference_member_t *member)
switch_channel_answer(channel);
}
sanity = 2000;
while(!switch_test_flag(member, MFLAG_ITHREAD) && sanity > 0) {
switch_cond_next();
sanity--;
}
/* Fair WARNING, If you expect the caller to hear anything or for digit handling to be processed, */
/* you better not block this thread loop for more than the duration of member->conference->timer_name! */
while (switch_test_flag(member, MFLAG_RUNNING) && switch_test_flag(member, MFLAG_ITHREAD)
@@ -2745,6 +2766,30 @@ static void conference_loop_output(conference_member_t *member)
switch_mutex_unlock(member->write_mutex);
if (switch_test_flag(member, MFLAG_INDICATE_MUTE)) {
if (!zstr(member->conference->muted_sound)) {
conference_member_play_file(member, member->conference->muted_sound, 0);
} else {
char msg[512];
switch_snprintf(msg, sizeof(msg), "Muted");
conference_member_say(member, msg, 0);
}
switch_clear_flag(member, MFLAG_INDICATE_MUTE);
}
if (switch_test_flag(member, MFLAG_INDICATE_UNMUTE)) {
if (!zstr(member->conference->unmuted_sound)) {
conference_member_play_file(member, member->conference->unmuted_sound, 0);
} else {
char msg[512];
switch_snprintf(msg, sizeof(msg), "Un-Muted");
conference_member_say(member, msg, 0);
}
switch_clear_flag(member, MFLAG_INDICATE_UNMUTE);
}
if (switch_core_session_private_event_count(member->session)) {
switch_channel_set_app_flag(channel, CF_APP_TAGGED);
switch_ivr_parse_all_events(member->session);
@@ -3590,6 +3635,14 @@ static void conference_list(conference_obj_t *conference, switch_stream_handle_t
switch_mutex_unlock(conference->member_mutex);
}
static void conference_list_count_only(conference_obj_t *conference, switch_stream_handle_t *stream)
{
switch_assert(conference != NULL);
switch_assert(stream != NULL);
stream->write_function(stream, "%d", conference->count);
}
static switch_status_t conf_api_sub_mute(conference_member_t *member, switch_stream_handle_t *stream, void *data)
{
switch_event_t *event;
@@ -3600,18 +3653,12 @@ static switch_status_t conf_api_sub_mute(conference_member_t *member, switch_str
switch_clear_flag_locked(member, MFLAG_CAN_SPEAK);
switch_clear_flag_locked(member, MFLAG_TALKING);
switch_set_flag(member, MFLAG_INDICATE_MUTE);
if (!zstr(member->conference->muted_sound)) {
conference_member_play_file(member, member->conference->muted_sound, 0);
} else {
char msg[512];
switch_snprintf(msg, sizeof(msg), "Muted");
conference_member_say(member, msg, 0);
}
if (stream != NULL) {
stream->write_function(stream, "OK mute %u\n", member->id);
}
if (test_eflag(member->conference, EFLAG_MUTE_MEMBER) &&
switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, CONF_EVENT_MAINT) == SWITCH_STATUS_SUCCESS) {
conference_add_event_member_data(member, event);
@@ -3676,17 +3723,12 @@ static switch_status_t conf_api_sub_unmute(conference_member_t *member, switch_s
return SWITCH_STATUS_GENERR;
switch_set_flag_locked(member, MFLAG_CAN_SPEAK);
switch_set_flag(member, MFLAG_INDICATE_UNMUTE);
if (stream != NULL) {
stream->write_function(stream, "OK unmute %u\n", member->id);
}
if (!zstr(member->conference->unmuted_sound)) {
conference_member_play_file(member, member->conference->unmuted_sound, 0);
} else {
char msg[512];
switch_snprintf(msg, sizeof(msg), "Un-Muted");
conference_member_say(member, msg, 0);
}
if (test_eflag(member->conference, EFLAG_UNMUTE_MEMBER) &&
switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, CONF_EVENT_MAINT) == SWITCH_STATUS_SUCCESS) {
conference_add_event_member_data(member, event);
@@ -3889,6 +3931,7 @@ static switch_status_t conf_api_sub_list(conference_obj_t *conference, switch_st
char *d = ";";
int pretty = 0;
int summary = 0;
int countonly = 0;
int argofs = (argc >= 2 && strcasecmp(argv[1], "list") == 0); /* detect being called from chat vs. api */
if (argv[1 + argofs]) {
@@ -3909,6 +3952,8 @@ static switch_status_t conf_api_sub_list(conference_obj_t *conference, switch_st
pretty = 1;
} else if (strcasecmp(argv[1 + argofs], "summary") == 0) {
summary = 1;
} else if (strcasecmp(argv[1 + argofs], "count") == 0) {
countonly = 1;
}
}
@@ -3934,7 +3979,9 @@ static switch_status_t conf_api_sub_list(conference_obj_t *conference, switch_st
switch_mutex_unlock(globals.hash_mutex);
} else {
count++;
if (pretty) {
if (countonly) {
conference_list_count_only(conference, stream);
} else if (pretty) {
conference_list_pretty(conference, stream);
} else {
conference_list(conference, stream, d);
@@ -5368,6 +5415,8 @@ static void set_mflags(const char *flags, member_flag_t *f)
*f |= MFLAG_DIST_DTMF;
} else if (!strcasecmp(argv[i], "moderator")) {
*f |= MFLAG_MOD;
} else if (!strcasecmp(argv[i], "nomoh")) {
*f |= MFLAG_NOMOH;
} else if (!strcasecmp(argv[i], "endconf")) {
*f |= MFLAG_ENDCONF;
} else if (!strcasecmp(argv[i], "mintwo")) {
+57 -9
View File
@@ -1033,7 +1033,7 @@ SWITCH_STANDARD_APP(sched_cancel_function)
switch_scheduler_del_task_group(group);
}
SWITCH_STANDARD_APP(set_function)
static void base_set (switch_core_session_t *session, const char *data, switch_stack_t stack)
{
char *var, *val = NULL;
@@ -1044,7 +1044,10 @@ SWITCH_STANDARD_APP(set_function)
char *expanded = NULL;
var = switch_core_session_strdup(session, data);
val = strchr(var, '=');
if (!(val = strchr(var, '='))) {
val = strchr(var, ',');
}
if (val) {
*val++ = '\0';
@@ -1059,7 +1062,7 @@ SWITCH_STANDARD_APP(set_function)
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s SET [%s]=[%s]\n", switch_channel_get_name(channel), var,
expanded ? expanded : "UNDEF");
switch_channel_set_variable_var_check(channel, var, expanded, SWITCH_FALSE);
switch_channel_add_variable_var_check(channel, var, expanded, SWITCH_FALSE, stack);
if (expanded && expanded != val) {
switch_safe_free(expanded);
@@ -1067,6 +1070,21 @@ SWITCH_STANDARD_APP(set_function)
}
}
SWITCH_STANDARD_APP(set_function)
{
base_set(session, data, SWITCH_STACK_BOTTOM);
}
SWITCH_STANDARD_APP(push_function)
{
base_set(session, data, SWITCH_STACK_PUSH);
}
SWITCH_STANDARD_APP(unshift_function)
{
base_set(session, data, SWITCH_STACK_UNSHIFT);
}
SWITCH_STANDARD_APP(set_global_function)
{
char *var, *val = NULL;
@@ -2290,6 +2308,26 @@ SWITCH_STANDARD_APP(stop_displace_session_function)
switch_ivr_stop_displace_session(session, data);
}
SWITCH_STANDARD_APP(capture_function)
{
char *argv[3] = { 0 };
int argc;
switch_regex_t *re = NULL;
int ovector[30] = {0};
char *lbuf;
int proceed;
if (!zstr(data) && (lbuf = switch_core_session_strdup(session, data))
&& (argc = switch_separate_string(lbuf, '|', argv, (sizeof(argv) / sizeof(argv[0])))) == 3) {
if ((proceed = switch_regex_perform(argv[1], argv[2], &re, ovector, sizeof(ovector) / sizeof(ovector[0])))) {
switch_capture_regex(re, proceed, argv[1], ovector, argv[0], switch_regex_set_var_callback, session);
}
switch_regex_safe_free(re);
} else {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "No data specified.\n");
}
}
SWITCH_STANDARD_APP(record_function)
{
switch_channel_t *channel = switch_core_session_get_channel(session);
@@ -2491,8 +2529,7 @@ SWITCH_STANDARD_APP(audio_bridge_function)
char *tof_data = NULL;
char *tof_array[4] = { 0 };
//int tof_arrayc = 0;
const char *continue_on_fail = NULL, *failure_causes = NULL,
*v_campon = NULL, *v_campon_retries, *v_campon_sleep, *v_campon_timeout, *v_campon_fallback_exten = NULL;
const char *v_campon = NULL, *v_campon_retries, *v_campon_sleep, *v_campon_timeout, *v_campon_fallback_exten = NULL;
switch_call_cause_t cause = SWITCH_CAUSE_NORMAL_CLEARING;
int campon_retries = 100, campon_timeout = 10, campon_sleep = 10, tmp, camping = 0, fail = 0, thread_started = 0;
struct camping_stake stake = { 0 };
@@ -2506,15 +2543,11 @@ SWITCH_STANDARD_APP(audio_bridge_function)
return;
}
continue_on_fail = switch_channel_get_variable(caller_channel, "continue_on_fail");
transfer_on_fail = switch_channel_get_variable(caller_channel, "transfer_on_fail");
tof_data = switch_core_session_strdup(session, transfer_on_fail);
switch_split(tof_data, ' ', tof_array);
transfer_on_fail = tof_array[0];
failure_causes = switch_channel_get_variable(caller_channel, "failure_causes");
if ((v_campon = switch_channel_get_variable(caller_channel, "campon")) && switch_true(v_campon)) {
const char *cid_name = NULL;
const char *cid_number = NULL;
@@ -2655,6 +2688,11 @@ SWITCH_STANDARD_APP(audio_bridge_function)
EXCEPTION... ATTENDED_TRANSFER never is a reason to continue.......
*/
if (cause != SWITCH_CAUSE_ATTENDED_TRANSFER) {
const char *continue_on_fail = NULL, *failure_causes = NULL;
continue_on_fail = switch_channel_get_variable(caller_channel, "continue_on_fail");
failure_causes = switch_channel_get_variable(caller_channel, "failure_causes");
if (continue_on_fail || failure_causes) {
const char *cause_str;
char cause_num[35] = "";
@@ -3722,6 +3760,9 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_dptools_load)
SWITCH_ADD_APP(app_interface, "bind_digit_action", "bind a key sequence or regex to an action",
"bind a key sequence or regex to an action", bind_digit_action_function, BIND_DIGIT_ACTION_USAGE, SAF_SUPPORT_NOMEDIA);
SWITCH_ADD_APP(app_interface, "capture", "capture data into a var", "capture data into a var",
capture_function, "<varname>|<data>|<regex>", SAF_SUPPORT_NOMEDIA);
SWITCH_ADD_APP(app_interface, "clear_digit_action", "clear all digit bindings", "",
clear_digit_action_function, CLEAR_DIGIT_ACTION_USAGE, SAF_SUPPORT_NOMEDIA);
@@ -3769,6 +3810,13 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_dptools_load)
SAF_SUPPORT_NOMEDIA | SAF_ROUTING_EXEC);
SWITCH_ADD_APP(app_interface, "set", "Set a channel variable", SET_LONG_DESC, set_function, "<varname>=<value>",
SAF_SUPPORT_NOMEDIA | SAF_ROUTING_EXEC);
SWITCH_ADD_APP(app_interface, "push", "Set a channel variable", SET_LONG_DESC, push_function, "<varname>=<value>",
SAF_SUPPORT_NOMEDIA | SAF_ROUTING_EXEC);
SWITCH_ADD_APP(app_interface, "unshift", "Set a channel variable", SET_LONG_DESC, unshift_function, "<varname>=<value>",
SAF_SUPPORT_NOMEDIA | SAF_ROUTING_EXEC);
SWITCH_ADD_APP(app_interface, "set_global", "Set a global variable", SET_GLOBAL_LONG_DESC, set_global_function, "<varname>=<value>",
SAF_SUPPORT_NOMEDIA | SAF_ROUTING_EXEC);
SWITCH_ADD_APP(app_interface, "set_profile_var", "Set a caller profile variable", SET_PROFILE_VAR_LONG_DESC, set_profile_var_function,
+85 -5
View File
@@ -51,6 +51,7 @@ struct record_helper {
switch_mutex_t *mutex;
int fd;
int up;
switch_size_t shared_ts;
};
static void *SWITCH_THREAD_FUNC record_video_thread(switch_thread_t *thread, void *obj)
@@ -63,7 +64,7 @@ static void *SWITCH_THREAD_FUNC record_video_thread(switch_thread_t *thread, voi
int bytes;
eh->up = 1;
while (switch_channel_ready(channel)) {
while (switch_channel_ready(channel) && eh->up) {
status = switch_core_session_read_video_frame(session, &read_frame, SWITCH_IO_FLAG_NONE, 0);
if (!SWITCH_READ_ACCEPTABLE(status)) {
@@ -108,11 +109,13 @@ SWITCH_STANDARD_APP(record_fsv_function)
switch_mutex_t *mutex = NULL;
switch_codec_t codec, *vid_codec;
switch_codec_implementation_t read_impl = { 0 };
switch_dtmf_t dtmf = { 0 };
int count = 0, sanity = 30;
switch_core_session_get_read_impl(session, &read_impl);
switch_channel_answer(channel);
switch_channel_set_variable(channel, SWITCH_PLAYBACK_TERMINATOR_USED, "");
while (switch_channel_up(channel) && !switch_channel_test_flag(channel, CF_VIDEO)) {
switch_yield(10000);
@@ -125,6 +128,7 @@ SWITCH_STANDARD_APP(record_fsv_function)
if (!--sanity) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "%s timeout waiting for video.\n",
switch_channel_get_name(channel));
switch_channel_set_variable(channel, SWITCH_CURRENT_APPLICATION_RESPONSE_VARIABLE, "Got timeout while waiting for video");
return;
}
}
@@ -132,11 +136,13 @@ SWITCH_STANDARD_APP(record_fsv_function)
if (!switch_channel_ready(channel)) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_CRIT, "%s not ready.\n", switch_channel_get_name(channel));
switch_channel_set_variable(channel, SWITCH_CURRENT_APPLICATION_RESPONSE_VARIABLE, "Channel not ready");
return;
}
if ((fd = open((char *) data, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, S_IRUSR | S_IWUSR)) < 0) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_CRIT, "Error opening file %s\n", (char *) data);
switch_channel_set_variable(channel, SWITCH_CURRENT_APPLICATION_RESPONSE_VARIABLE, "Got error while opening file");
return;
}
@@ -150,6 +156,7 @@ SWITCH_STANDARD_APP(record_fsv_function)
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Audio Codec Activation Success\n");
} else {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Audio Codec Activation Fail\n");
switch_channel_set_variable(channel, SWITCH_CURRENT_APPLICATION_RESPONSE_VARIABLE, "Audio codec activation failed");
goto end;
}
@@ -170,6 +177,7 @@ SWITCH_STANDARD_APP(record_fsv_function)
h.audio_ptime = read_impl.microseconds_per_packet / 1000;
if (write(fd, &h, sizeof(h)) != sizeof(h)) {
switch_channel_set_variable(channel, SWITCH_CURRENT_APPLICATION_RESPONSE_VARIABLE, "File write failed");
goto end;
}
@@ -186,9 +194,37 @@ SWITCH_STANDARD_APP(record_fsv_function)
while (switch_channel_ready(channel)) {
status = switch_core_session_read_frame(session, &read_frame, SWITCH_IO_FLAG_NONE, 0);
status = switch_core_session_read_frame(session, &read_frame, SWITCH_IO_FLAG_SINGLE_READ, 0);
if (switch_channel_test_flag(channel, CF_BREAK)) {
switch_channel_clear_flag(channel, CF_BREAK);
eh.up = 0;
break;
}
switch_ivr_parse_all_events(session);
//check for dtmf interrupts
if (switch_channel_has_dtmf(channel)) {
const char * terminators = switch_channel_get_variable(channel, SWITCH_PLAYBACK_TERMINATORS_VARIABLE);
switch_channel_dequeue_dtmf(channel, &dtmf);
if (terminators && !strcasecmp(terminators, "none"))
{
terminators = NULL;
}
if (terminators && strchr(terminators, dtmf.digit)) {
char sbuf[2] = {dtmf.digit, '\0'};
switch_channel_set_variable(channel, SWITCH_PLAYBACK_TERMINATOR_USED, sbuf);
eh.up = 0;
break;
}
}
if (!SWITCH_READ_ACCEPTABLE(status)) {
eh.up = 0;
break;
}
@@ -213,12 +249,15 @@ SWITCH_STANDARD_APP(record_fsv_function)
}
break;
}
if (mutex) {
switch_mutex_unlock(mutex);
}
switch_core_session_write_frame(session, read_frame, SWITCH_IO_FLAG_NONE, 0);
}
switch_channel_set_variable(channel, SWITCH_CURRENT_APPLICATION_RESPONSE_VARIABLE, "OK");
end:
@@ -239,7 +278,7 @@ SWITCH_STANDARD_APP(play_fsv_function)
switch_frame_t write_frame = { 0 }, vid_frame = {
0};
int fd = -1;
int bytes;
int bytes;
switch_codec_t codec = { 0 }, vid_codec = {
0}, *read_vid_codec;
unsigned char *aud_buffer;
@@ -248,24 +287,32 @@ SWITCH_STANDARD_APP(play_fsv_function)
uint32_t ts = 0, last = 0;
switch_timer_t timer = { 0 };
switch_payload_t pt = 0;
switch_dtmf_t dtmf = { 0 };
switch_frame_t *read_frame;
switch_codec_implementation_t read_impl = { 0 };
switch_core_session_get_read_impl(session, &read_impl);
aud_buffer = switch_core_session_alloc(session, SWITCH_RECOMMENDED_BUFFER_SIZE);
vid_buffer = switch_core_session_alloc(session, SWITCH_RECOMMENDED_BUFFER_SIZE);
switch_channel_set_variable(channel, SWITCH_PLAYBACK_TERMINATOR_USED, "");
if ((fd = open((char *) data, O_RDONLY | O_BINARY)) < 0) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_CRIT, "Error opening file %s\n", (char *) data);
switch_channel_set_variable(channel, SWITCH_CURRENT_APPLICATION_RESPONSE_VARIABLE, "Got error while opening file");
return;
}
if (read(fd, &h, sizeof(h)) != sizeof(h)) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_CRIT, "Error reading file header\n");
switch_channel_set_variable(channel, SWITCH_CURRENT_APPLICATION_RESPONSE_VARIABLE, "Got error reading file header");
goto end;
}
if (h.version != VERSION) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_CRIT, "File version does not match!\n");
switch_channel_set_variable(channel, SWITCH_CURRENT_APPLICATION_RESPONSE_VARIABLE, "File version does not match!");
goto end;
}
@@ -290,6 +337,7 @@ SWITCH_STANDARD_APP(play_fsv_function)
if (switch_core_timer_init(&timer, "soft", read_impl.microseconds_per_packet / 1000,
read_impl.samples_per_packet, switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Timer Activation Fail\n");
switch_channel_set_variable(channel, SWITCH_CURRENT_APPLICATION_RESPONSE_VARIABLE, "Timer activation failed!");
goto end;
}
@@ -303,6 +351,7 @@ SWITCH_STANDARD_APP(play_fsv_function)
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Audio Codec Activation Success\n");
} else {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Audio Codec Activation Fail\n");
switch_channel_set_variable(channel, SWITCH_CURRENT_APPLICATION_RESPONSE_VARIABLE, "Audio codec activation failed");
goto end;
}
@@ -316,6 +365,7 @@ SWITCH_STANDARD_APP(play_fsv_function)
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Video Codec Activation Success\n");
} else {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Video Codec Activation Fail\n");
switch_channel_set_variable(channel, SWITCH_CURRENT_APPLICATION_RESPONSE_VARIABLE, "Video codec activation failed");
goto end;
}
switch_core_session_set_read_codec(session, &codec);
@@ -353,15 +403,45 @@ SWITCH_STANDARD_APP(play_fsv_function)
if (bytes > (int) write_frame.buflen) {
bytes = write_frame.buflen;
}
if ((write_frame.datalen = read(fd, write_frame.data, bytes)) <= 0) {
break;
}
switch_core_session_write_frame(session, &write_frame, SWITCH_IO_FLAG_NONE, 0);
switch_core_timer_next(&timer);
}
switch_core_session_read_frame(session, &read_frame, SWITCH_IO_FLAG_NONE, 0);
if (switch_channel_test_flag(channel, CF_BREAK)) {
switch_channel_clear_flag(channel, CF_BREAK);
break;
}
switch_ivr_parse_all_events(session);
//check for dtmf interrupts
if (switch_channel_has_dtmf(channel)) {
const char * terminators = switch_channel_get_variable(channel, SWITCH_PLAYBACK_TERMINATORS_VARIABLE);
switch_channel_dequeue_dtmf(channel, &dtmf);
if (terminators && !strcasecmp(terminators, "none"))
{
terminators = NULL;
}
if (terminators && strchr(terminators, dtmf.digit)) {
char sbuf[2] = {dtmf.digit, '\0'};
switch_channel_set_variable(channel, SWITCH_PLAYBACK_TERMINATOR_USED, sbuf);
break;
}
}
}
}
switch_channel_set_variable(channel, SWITCH_CURRENT_APPLICATION_RESPONSE_VARIABLE, "OK");
end:
if (timer.interval) {
@@ -330,7 +330,7 @@ static void phase_e_handler(t30_state_t *s, void *user_data, int result)
local_ident = switch_str_nil(t30_get_tx_ident(s));
far_ident = switch_str_nil(t30_get_rx_ident(s));
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "==============================================================================\n");
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "==============================================================================\n");
if (result == T30_ERR_OK) {
if (pvt->app_mode == FUNCTION_TX) {
@@ -414,6 +414,8 @@ static void phase_e_handler(t30_state_t *s, void *user_data, int result)
/* Fire event */
if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, pvt->app_mode == FUNCTION_TX ? SPANDSP_EVENT_TXFAXRESULT : SPANDSP_EVENT_RXFAXRESULT) == SWITCH_STATUS_SUCCESS) {
switch_channel_event_set_data(channel, event);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "fax-success", (result == T30_ERR_OK) ? "1" : "0");
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "fax-result-code", fax_result_code);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "fax-result-text", t30_completion_code_to_str(result));
@@ -904,6 +906,7 @@ static t38_mode_t request_t38(pvt_t *pvt)
switch_channel_set_private(channel, "t38_options", t38_options);
pvt->t38_mode = T38_MODE_REQUESTED;
switch_channel_set_app_flag_key("T38", channel, CF_APP_T38_REQ);
/* This will send a request for t.38 mode */
msg.from = __FILE__;
@@ -1173,7 +1176,10 @@ void mod_spandsp_fax_process_fax(switch_core_session_t *session, const char *dat
switch (pvt->t38_mode) {
case T38_MODE_REQUESTED:
{
if (switch_channel_test_app_flag_key("T38", channel, CF_APP_T38)) {
if (switch_channel_test_app_flag_key("T38", channel, CF_APP_T38_FAIL)) {
pvt->t38_mode = T38_MODE_REFUSED;
continue;
} else if (switch_channel_test_app_flag_key("T38", channel, CF_APP_T38)) {
switch_core_session_message_t msg = { 0 };
pvt->t38_mode = T38_MODE_NEGOTIATED;
spanfax_init(pvt, T38_MODE);
+4 -4
View File
@@ -1,7 +1,7 @@
SPHINXBASE=sphinxbase-0.4.99
SPHINXBASE=sphinxbase-0.7
SPHINXBASE_DIR=$(switch_srcdir)/libs/$(SPHINXBASE)
SPHINXBASE_BUILDDIR=$(switch_builddir)/libs/$(SPHINXBASE)
POCKETSPHINX=pocketsphinx-0.5.99
POCKETSPHINX=pocketsphinx-0.7
POCKETSPHINX_DIR=$(switch_srcdir)/libs/$(POCKETSPHINX)
POCKETSPHINX_BUILDDIR=$(switch_builddir)/libs/$(POCKETSPHINX)
SPHINXBASE_LA=$(SPHINXBASE_BUILDDIR)/src/libsphinxbase/libsphinxbase.la
@@ -17,7 +17,7 @@ BASE=../../../..
include $(BASE)/build/modmake.rules
$(SPHINXBASE_DIR):
$(GETLIB) $(SPHINXBASE)-20091212.tar.gz
$(GETLIB) $(SPHINXBASE).tar.gz
$(SPHINXBASE_BUILDDIR)/buildstamp: $(SPHINXBASE_DIR)
mkdir -p $(SPHINXBASE_BUILDDIR)
@@ -29,7 +29,7 @@ $(SPHINXBASE_LA): $(SPHINXBASE_BUILDDIR)/buildstamp
$(TOUCH_TARGET)
$(POCKETSPHINX_DIR):
$(GETLIB) $(POCKETSPHINX)-20091212.tar.gz
$(GETLIB) $(POCKETSPHINX).tar.gz
$(POCKETSPHINX_BUILDDIR)/Makefile: $(POCKETSPHINX_DIR) $(SPHINXBASE_LA)
mkdir -p $(POCKETSPHINX_BUILDDIR)
@@ -43,7 +43,7 @@
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="&quot;..\..\..\..\libs\sphinxbase-0.4.99\include&quot;;&quot;..\..\..\..\libs\pocketsphinx-0.5.99\include&quot;"
AdditionalIncludeDirectories="&quot;..\..\..\..\libs\sphinxbase-0.7\include&quot;;&quot;..\..\..\..\libs\pocketsphinx-0.7\include&quot;"
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;MOD_POCKETSPHINX_EXPORTS"
MinimalRebuild="true"
BasicRuntimeChecks="3"
@@ -117,7 +117,7 @@
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="&quot;..\..\..\..\libs\sphinxbase-0.4.99\include&quot;;&quot;..\..\..\..\libs\pocketsphinx-0.5.99\include&quot;"
AdditionalIncludeDirectories="&quot;..\..\..\..\libs\sphinxbase-0.7\include&quot;;&quot;..\..\..\..\libs\pocketsphinx-0.7\include&quot;"
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;MOD_POCKETSPHINX_EXPORTS"
MinimalRebuild="true"
BasicRuntimeChecks="3"
@@ -193,7 +193,7 @@
Name="VCCLCompilerTool"
Optimization="2"
EnableIntrinsicFunctions="true"
AdditionalIncludeDirectories="&quot;..\..\..\..\libs\sphinxbase-0.4.99\include&quot;;&quot;..\..\..\..\libs\pocketsphinx-0.5.99\include&quot;"
AdditionalIncludeDirectories="&quot;..\..\..\..\libs\sphinxbase-0.7\include&quot;;&quot;..\..\..\..\libs\pocketsphinx-0.7\include&quot;"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;MOD_POCKETSPHINX_EXPORTS"
RuntimeLibrary="2"
EnableFunctionLevelLinking="true"
@@ -271,7 +271,7 @@
Name="VCCLCompilerTool"
Optimization="2"
EnableIntrinsicFunctions="true"
AdditionalIncludeDirectories="&quot;..\..\..\..\libs\sphinxbase-0.4.99\include&quot;;&quot;..\..\..\..\libs\pocketsphinx-0.5.99\include&quot;"
AdditionalIncludeDirectories="&quot;..\..\..\..\libs\sphinxbase-0.7\include&quot;;&quot;..\..\..\..\libs\pocketsphinx-0.7\include&quot;"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;MOD_POCKETSPHINX_EXPORTS"
RuntimeLibrary="2"
EnableFunctionLevelLinking="true"
@@ -73,7 +73,7 @@
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>..\..\..\..\libs\sphinxbase-0.4.99\include;..\..\..\..\libs\pocketsphinx-0.5.99\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>..\..\..\..\libs\sphinxbase-0.7\include;..\..\..\..\libs\pocketsphinx-0.7\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;MOD_POCKETSPHINX_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MinimalRebuild>true</MinimalRebuild>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
@@ -99,7 +99,7 @@
</Midl>
<ClCompile>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>..\..\..\..\libs\sphinxbase-0.4.99\include;..\..\..\..\libs\pocketsphinx-0.5.99\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>..\..\..\..\libs\sphinxbase-0.7\include;..\..\..\..\libs\pocketsphinx-0.7\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;MOD_POCKETSPHINX_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MinimalRebuild>true</MinimalRebuild>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
@@ -123,7 +123,7 @@
<ClCompile>
<Optimization>MaxSpeed</Optimization>
<IntrinsicFunctions>true</IntrinsicFunctions>
<AdditionalIncludeDirectories>..\..\..\..\libs\sphinxbase-0.4.99\include;..\..\..\..\libs\pocketsphinx-0.5.99\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>..\..\..\..\libs\sphinxbase-0.7\include;..\..\..\..\libs\pocketsphinx-0.7\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;MOD_POCKETSPHINX_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<FunctionLevelLinking>true</FunctionLevelLinking>
@@ -154,7 +154,7 @@
<ClCompile>
<Optimization>MaxSpeed</Optimization>
<IntrinsicFunctions>true</IntrinsicFunctions>
<AdditionalIncludeDirectories>..\..\..\..\libs\sphinxbase-0.4.99\include;..\..\..\..\libs\pocketsphinx-0.5.99\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>..\..\..\..\libs\sphinxbase-0.7\include;..\..\..\..\libs\pocketsphinx-0.7\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;MOD_POCKETSPHINX_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<FunctionLevelLinking>true</FunctionLevelLinking>
@@ -32,8 +32,8 @@
#include <switch.h>
#include <pocketsphinx.h>
#include <err.h>
#include <logmath.h>
#include <sphinxbase/err.h>
#include <sphinxbase/logmath.h>
SWITCH_MODULE_LOAD_FUNCTION(mod_pocketsphinx_load);
SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_pocketsphinx_shutdown);
+1 -1
View File
@@ -28,7 +28,7 @@ mod_unimrcp_la_CFLAGS += -I$(UNIMRCP_DIR)/libs/mrcp/resources/include
mod_unimrcp_la_CFLAGS += -I$(UNIMRCP_DIR)/libs/mpf/include
mod_unimrcp_la_CFLAGS += -I$(UNIMRCP_DIR)/libs/apr-toolkit/include
mod_unimrcp_la_LIBADD = $(switch_builddir)/libfreeswitch.la $(UNIMRCPLA) $(switch_builddir)/libs/apr/libapr-1.la
mod_unimrcp_la_LIBADD = $(switch_builddir)/libfreeswitch.la $(UNIMRCPLA) $(switch_builddir)/libs/apr/libapr-1.la $(switch_builddir)/libs/apr-util/libaprutil-1.la $(switch_builddir)/libs/apr-util/xml/expat/lib/libexpat.la
mod_unimrcp_la_LDFLAGS = -avoid-version -module -no-undefined -shared
if ISMAC
+125 -84
View File
@@ -89,6 +89,8 @@ typedef struct mod_unimrcp_application mod_unimrcp_application_t;
struct mod_unimrcp_globals {
/** max-connection-count config */
char *unimrcp_max_connection_count;
/** request-timeout config */
char *unimrcp_request_timeout;
/** offer-new-connection config */
char *unimrcp_offer_new_connection;
/** default-tts-profile config */
@@ -168,6 +170,8 @@ static switch_xml_config_item_t instructions[] = {
"EMERGENCY|ALERT|CRITICAL|ERROR|WARNING|NOTICE|INFO|DEBUG", "Logging level for UniMRCP"),
SWITCH_CONFIG_ITEM_STRING_STRDUP("enable-profile-events", CONFIG_REQUIRED, &globals.enable_profile_events_param, "false", "",
"Fire profile events (true|false)"),
SWITCH_CONFIG_ITEM_STRING_STRDUP("request-timeout", CONFIG_REQUIRED, &globals.unimrcp_request_timeout, "10000", "",
"Maximum time to wait for server response to a request"),
SWITCH_CONFIG_ITEM_END()
};
@@ -179,13 +183,13 @@ SWITCH_MODULE_DEFINITION(mod_unimrcp, mod_unimrcp_load, mod_unimrcp_shutdown, NU
static switch_status_t mod_unimrcp_do_config();
static mrcp_client_t *mod_unimrcp_client_create(switch_memory_pool_t *mod_pool);
static int process_rtp_config(mrcp_client_t *client, mpf_rtp_config_t *rtp_config, const char *param, const char *val, apr_pool_t *pool);
static int process_mrcpv1_config(rtsp_client_config_t *config, const char *param, const char *val, apr_pool_t *pool);
static int process_mrcpv2_config(mrcp_sofia_client_config_t *config, const char *param, const char *val, apr_pool_t *pool);
static int process_rtp_config(mrcp_client_t *client, mpf_rtp_config_t *rtp_config, mpf_rtp_settings_t *rtp_settings, const char *param, const char *val, apr_pool_t *pool);
static int process_mrcpv1_config(rtsp_client_config_t *config, mrcp_sig_settings_t *sig_settings, const char *param, const char *val, apr_pool_t *pool);
static int process_mrcpv2_config(mrcp_sofia_client_config_t *config, mrcp_sig_settings_t *sig_settings, const char *param, const char *val, apr_pool_t *pool);
static int process_profile_config(profile_t *profile, const char *param, const char *val, apr_pool_t *pool);
/* UniMRCP <--> FreeSWITCH logging bridge */
static apt_bool_t unimrcp_log(const char *file, int line, const char *id, apt_log_priority_e priority, const char *format, va_list arg_ptr);
static apt_bool_t unimrcp_log(const char *file, int line, const char *obj, apt_log_priority_e priority, const char *format, va_list arg_ptr);
static apt_log_priority_e str_to_log_level(const char *level);
static int get_next_speech_channel_number(void);
@@ -1810,56 +1814,66 @@ static apt_bool_t speech_on_session_terminate(mrcp_application_t *application, m
* @return TRUE
*/
static apt_bool_t speech_on_channel_add(mrcp_application_t *application, mrcp_session_t *session, mrcp_channel_t *channel,
mrcp_sig_status_code_e status)
mrcp_sig_status_code_e status)
{
switch_event_t *event = NULL;
speech_channel_t *schannel = (speech_channel_t *) mrcp_application_channel_object_get(channel);
char codec_name[60] = { 0 };
const mpf_codec_descriptor_t *descriptor;
/* check status */
if (session && schannel && status == MRCP_SIG_STATUS_CODE_SUCCESS) {
char codec_name[60] = { 0 };
const mpf_codec_descriptor_t *descriptor;
/* what sample rate did we negotiate? */
if (schannel->type == SPEECH_CHANNEL_SYNTHESIZER) {
descriptor = mrcp_application_sink_descriptor_get(channel);
} else {
descriptor = mrcp_application_source_descriptor_get(channel);
}
schannel->rate = descriptor->sampling_rate;
if (descriptor->name.length) {
strncpy(codec_name, descriptor->name.buf, sizeof(codec_name));
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "(%s) %s channel is ready, codec = %s, sample rate = %d\n", schannel->name,
speech_channel_type_to_string(schannel->type), codec_name, schannel->rate);
speech_channel_set_state(schannel, SPEECH_CHANNEL_READY);
/* notify of channel open */
if (globals.enable_profile_events && switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, MY_EVENT_PROFILE_OPEN) == SWITCH_STATUS_SUCCESS) {
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "MRCP-Profile", schannel->profile->name);
if (schannel->type == SPEECH_CHANNEL_SYNTHESIZER) {
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "MRCP-Resource-Type", "TTS");
} else {
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "MRCP-Resource-Type", "ASR");
}
switch_event_fire(&event);
}
schannel->channel_opened = 1;
if (!session || !schannel || status != MRCP_SIG_STATUS_CODE_SUCCESS) {
goto error;
}
/* what sample rate did we negotiate? */
if (schannel->type == SPEECH_CHANNEL_SYNTHESIZER) {
descriptor = mrcp_application_sink_descriptor_get(channel);
} else {
if (schannel) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "(%s) %s channel error!\n", schannel->name,
speech_channel_type_to_string(schannel->type));
descriptor = mrcp_application_source_descriptor_get(channel);
}
if (!descriptor) {
goto error;
}
schannel->rate = descriptor->sampling_rate;
if (descriptor->name.length) {
strncpy(codec_name, descriptor->name.buf, sizeof(codec_name));
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "(%s) %s channel is ready, codec = %s, sample rate = %d\n", schannel->name,
speech_channel_type_to_string(schannel->type), codec_name, schannel->rate);
speech_channel_set_state(schannel, SPEECH_CHANNEL_READY);
/* notify of channel open */
if (globals.enable_profile_events && switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, MY_EVENT_PROFILE_OPEN) == SWITCH_STATUS_SUCCESS) {
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "MRCP-Profile", schannel->profile->name);
if (schannel->type == SPEECH_CHANNEL_SYNTHESIZER) {
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "MRCP-Resource-Type", "TTS");
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "(unknown) channel error!\n");
}
if (session) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Terminating MRCP session\n");
speech_channel_set_state(schannel, SPEECH_CHANNEL_ERROR);
mrcp_application_session_terminate(session);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "MRCP-Resource-Type", "ASR");
}
switch_event_fire(&event);
}
schannel->channel_opened = 1;
return TRUE;
error:
if (schannel) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "(%s) %s channel error!\n", schannel->name,
speech_channel_type_to_string(schannel->type));
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "(unknown) channel error!\n");
}
if (session) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Terminating MRCP session\n");
speech_channel_set_state(schannel, SPEECH_CHANNEL_ERROR);
mrcp_application_session_terminate(session);
}
return TRUE;
}
/**
* Handle the UniMRCP responses sent to channel remove requests
*
@@ -3729,7 +3743,7 @@ static int process_profile_config(profile_t *profile, const char *param, const c
* @param pool memory pool to use
* @return true if this param belongs to RTP config
*/
static int process_rtp_config(mrcp_client_t *client, mpf_rtp_config_t *rtp_config, const char *param, const char *val, apr_pool_t *pool)
static int process_rtp_config(mrcp_client_t *client, mpf_rtp_config_t *rtp_config, mpf_rtp_settings_t *rtp_settings, const char *param, const char *val, apr_pool_t *pool)
{
int mine = 1;
if (strcasecmp(param, "rtp-ip") == 0) {
@@ -3741,26 +3755,26 @@ static int process_rtp_config(mrcp_client_t *client, mpf_rtp_config_t *rtp_confi
} else if (strcasecmp(param, "rtp-port-max") == 0) {
rtp_config->rtp_port_max = (apr_port_t) atol(val);
} else if (strcasecmp(param, "playout-delay") == 0) {
rtp_config->jb_config.initial_playout_delay = atol(val);
rtp_settings->jb_config.initial_playout_delay = atol(val);
} else if (strcasecmp(param, "min-playout-delay") == 0) {
rtp_config->jb_config.min_playout_delay = atol(val);
rtp_settings->jb_config.min_playout_delay = atol(val);
} else if (strcasecmp(param, "max-playout-delay") == 0) {
rtp_config->jb_config.max_playout_delay = atol(val);
rtp_settings->jb_config.max_playout_delay = atol(val);
} else if (strcasecmp(param, "codecs") == 0) {
const mpf_codec_manager_t *codec_manager = mrcp_client_codec_manager_get(client);
if (codec_manager) {
mpf_codec_manager_codec_list_load(codec_manager, &rtp_config->codec_list, val, pool);
mpf_codec_manager_codec_list_load(codec_manager, &rtp_settings->codec_list, val, pool);
}
} else if (strcasecmp(param, "ptime") == 0) {
rtp_config->ptime = (apr_uint16_t) atol(val);
rtp_settings->ptime = (apr_uint16_t) atol(val);
} else if (strcasecmp(param, "rtcp") == 0) {
rtp_config->rtcp = atoi(val);
rtp_settings->rtcp = atoi(val);
} else if (strcasecmp(param, "rtcp-bye") == 0) {
rtp_config->rtcp_bye_policy = atoi(val);
rtp_settings->rtcp_bye_policy = atoi(val);
} else if (strcasecmp(param, "rtcp-tx-interval") == 0) {
rtp_config->rtcp_tx_interval = (apr_uint16_t) atoi(val);
rtp_settings->rtcp_tx_interval = (apr_uint16_t) atoi(val);
} else if (strcasecmp(param, "rtcp-rx-resolution") == 0) {
rtp_config->rtcp_rx_resolution = (apr_uint16_t) atol(val);
rtp_settings->rtcp_rx_resolution = (apr_uint16_t) atol(val);
} else {
mine = 0;
}
@@ -3771,28 +3785,29 @@ static int process_rtp_config(mrcp_client_t *client, mpf_rtp_config_t *rtp_confi
/**
* set RTSP client config struct with param, val pair
* @param config the config struct to set
* @param sig_settings the sig settings struct to set
* @param param the param name
* @param val the param value
* @param pool memory pool to use
* @return true if this param belongs to RTSP config
*/
static int process_mrcpv1_config(rtsp_client_config_t *config, const char *param, const char *val, apr_pool_t *pool)
static int process_mrcpv1_config(rtsp_client_config_t *config, mrcp_sig_settings_t *sig_settings, const char *param, const char *val, apr_pool_t *pool)
{
int mine = 1;
if (strcasecmp(param, "server-ip") == 0) {
config->server_ip = ip_addr_get(val, pool);
sig_settings->server_ip = ip_addr_get(val, pool);
} else if (strcasecmp(param, "server-port") == 0) {
config->server_port = (apr_port_t) atol(val);
sig_settings->server_port = (apr_port_t) atol(val);
} else if (strcasecmp(param, "resource-location") == 0) {
config->resource_location = apr_pstrdup(pool, val);
sig_settings->resource_location = apr_pstrdup(pool, val);
} else if (strcasecmp(param, "sdp-origin") == 0) {
config->origin = apr_pstrdup(pool, val);
} else if (strcasecmp(param, "max-connection-count") == 0) {
config->max_connection_count = atol(val);
} else if (strcasecmp(param, "force-destination") == 0) {
config->force_destination = atoi(val);
sig_settings->force_destination = atoi(val);
} else if (strcasecmp(param, "speechsynth") == 0 || strcasecmp(param, "speechrecog") == 0) {
apr_table_set(config->resource_map, param, val);
apr_table_set(sig_settings->resource_map, param, val);
} else {
mine = 0;
}
@@ -3802,12 +3817,13 @@ static int process_mrcpv1_config(rtsp_client_config_t *config, const char *param
/**
* set SofiaSIP client config struct with param, val pair
* @param config the config struct to set
* @param sig_settings the sig settings struct to set
* @param param the param name
* @param val the param value
* @param pool memory pool to use
* @return true if this param belongs to SofiaSIP config
*/
static int process_mrcpv2_config(mrcp_sofia_client_config_t *config, const char *param, const char *val, apr_pool_t *pool)
static int process_mrcpv2_config(mrcp_sofia_client_config_t *config, mrcp_sig_settings_t *sig_settings, const char *param, const char *val, apr_pool_t *pool)
{
int mine = 1;
if (strcasecmp(param, "client-ip") == 0) {
@@ -3817,13 +3833,13 @@ static int process_mrcpv2_config(mrcp_sofia_client_config_t *config, const char
} else if (strcasecmp(param, "client-port") == 0) {
config->local_port = (apr_port_t) atol(val);
} else if (strcasecmp(param, "server-ip") == 0) {
config->remote_ip = ip_addr_get(val, pool);
sig_settings->server_ip = ip_addr_get(val, pool);
} else if (strcasecmp(param, "server-port") == 0) {
config->remote_port = (apr_port_t) atol(val);
sig_settings->server_port = (apr_port_t) atol(val);
} else if (strcasecmp(param, "server-username") == 0) {
config->remote_user_name = apr_pstrdup(pool, val);
sig_settings->user_name = apr_pstrdup(pool, val);
} else if (strcasecmp(param, "force-destination") == 0) {
config->force_destination = atoi(val);
sig_settings->force_destination = atoi(val);
} else if (strcasecmp(param, "sip-transport") == 0) {
config->transport = apr_pstrdup(pool, val);
} else if (strcasecmp(param, "ua-name") == 0) {
@@ -3905,15 +3921,21 @@ static mrcp_client_t *mod_unimrcp_client_create(switch_memory_pool_t *mod_pool)
if (!zstr(globals.unimrcp_offer_new_connection)) {
offer_new_connection = strcasecmp("true", globals.unimrcp_offer_new_connection);
}
connection_agent = mrcp_client_connection_agent_create(max_connection_count, offer_new_connection, pool);
connection_agent = mrcp_client_connection_agent_create("MRCPv2ConnectionAgent", max_connection_count, offer_new_connection, pool);
if (connection_agent) {
mrcp_client_connection_agent_register(client, connection_agent, "MRCPv2ConnectionAgent");
if (!zstr(globals.unimrcp_request_timeout)) {
apr_size_t request_timeout = (apr_size_t)atol(globals.unimrcp_request_timeout);
if (request_timeout > 0) {
mrcp_client_connection_timeout_set(connection_agent, request_timeout);
}
}
mrcp_client_connection_agent_register(client, connection_agent);
}
/* Set up the media engine that will be shared with all profiles */
media_engine = mpf_engine_create(pool);
media_engine = mpf_engine_create("MediaEngine", pool);
if (media_engine) {
mrcp_client_media_engine_register(client, media_engine, "MediaEngine");
mrcp_client_media_engine_register(client, media_engine);
}
/* configure the client profiles */
@@ -3929,6 +3951,8 @@ static mrcp_client_t *mod_unimrcp_client_create(switch_memory_pool_t *mod_pool)
mpf_termination_factory_t *termination_factory = NULL;
mrcp_profile_t *mprofile = NULL;
mpf_rtp_config_t *rtp_config = NULL;
mpf_rtp_settings_t *rtp_settings = mpf_rtp_settings_alloc(pool);
mrcp_sig_settings_t *sig_settings = mrcp_signaling_settings_alloc(pool);
profile_t *mod_profile = NULL;
switch_xml_t default_params = NULL;
@@ -3958,8 +3982,13 @@ static mrcp_client_t *mod_unimrcp_client_create(switch_memory_pool_t *mod_pool)
client = NULL;
goto done;
}
if (zstr(param_value)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing SPEAK param value\n");
client = NULL;
goto done;
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Loading SPEAK Param %s:%s\n", param_name, param_value);
switch_core_hash_insert(mod_profile->default_synth_params, param_name, param_value);
switch_core_hash_insert(mod_profile->default_synth_params, switch_core_strdup(pool, param_name), switch_core_strdup(pool, param_value));
}
}
@@ -3976,24 +4005,35 @@ static mrcp_client_t *mod_unimrcp_client_create(switch_memory_pool_t *mod_pool)
client = NULL;
goto done;
}
if (zstr(param_value)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing RECOGNIZE param value\n");
client = NULL;
goto done;
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Loading RECOGNIZE Param %s:%s\n", param_name, param_value);
switch_core_hash_insert(mod_profile->default_recog_params, param_name, param_value);
switch_core_hash_insert(mod_profile->default_recog_params, switch_core_strdup(pool, param_name), switch_core_strdup(pool, param_value));
}
}
/* create RTP config, common to MRCPv1 and MRCPv2 */
rtp_config = mpf_rtp_config_create(pool);
rtp_config = mpf_rtp_config_alloc(pool);
rtp_config->rtp_port_min = DEFAULT_RTP_PORT_MIN;
rtp_config->rtp_port_max = DEFAULT_RTP_PORT_MAX;
apt_string_set(&rtp_config->ip, DEFAULT_LOCAL_IP_ADDRESS);
if (strcmp("1", version) == 0) {
/* MRCPv1 configuration */
rtsp_client_config_t *config = mrcp_unirtsp_client_config_alloc(pool);
switch_xml_t param = NULL;
rtsp_client_config_t *config = mrcp_unirtsp_client_config_alloc(pool);
config->origin = DEFAULT_SDP_ORIGIN;
config->resource_location = DEFAULT_RESOURCE_LOCATION;
sig_settings->resource_location = DEFAULT_RESOURCE_LOCATION;
if (!zstr(globals.unimrcp_request_timeout)) {
apr_size_t request_timeout = (apr_size_t)atol(globals.unimrcp_request_timeout);
if (request_timeout > 0) {
config->request_timeout = request_timeout;
}
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Loading MRCPv1 profile: %s\n", name);
for (param = switch_xml_child(profile, "param"); param; param = switch_xml_next(param)) {
const char *param_name = switch_xml_attr(param, "name");
@@ -4004,21 +4044,21 @@ static mrcp_client_t *mod_unimrcp_client_create(switch_memory_pool_t *mod_pool)
goto done;
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Loading Param %s:%s\n", param_name, param_value);
if (!process_mrcpv1_config(config, param_name, param_value, pool) &&
!process_rtp_config(client, rtp_config, param_name, param_value, pool) &&
if (!process_mrcpv1_config(config, sig_settings, param_name, param_value, pool) &&
!process_rtp_config(client, rtp_config, rtp_settings, param_name, param_value, pool) &&
!process_profile_config(mod_profile, param_name, param_value, mod_pool)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Unknown param %s\n", param_name);
}
}
agent = mrcp_unirtsp_client_agent_create(config, pool);
agent = mrcp_unirtsp_client_agent_create(name, config, pool);
} else if (strcmp("2", version) == 0) {
/* MRCPv2 configuration */
mrcp_sofia_client_config_t *config = mrcp_sofiasip_client_config_alloc(pool);
switch_xml_t param = NULL;
config->local_ip = DEFAULT_LOCAL_IP_ADDRESS;
config->local_port = DEFAULT_SIP_LOCAL_PORT;
config->remote_ip = DEFAULT_REMOTE_IP_ADDRESS;
config->remote_port = DEFAULT_SIP_REMOTE_PORT;
sig_settings->server_ip = DEFAULT_REMOTE_IP_ADDRESS;
sig_settings->server_port = DEFAULT_SIP_REMOTE_PORT;
config->ext_ip = NULL;
config->user_agent_name = DEFAULT_SOFIASIP_UA_NAME;
config->origin = DEFAULT_SDP_ORIGIN;
@@ -4032,13 +4072,13 @@ static mrcp_client_t *mod_unimrcp_client_create(switch_memory_pool_t *mod_pool)
goto done;
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Loading Param %s:%s\n", param_name, param_value);
if (!process_mrcpv2_config(config, param_name, param_value, pool) &&
!process_rtp_config(client, rtp_config, param_name, param_value, pool) &&
if (!process_mrcpv2_config(config, sig_settings, param_name, param_value, pool) &&
!process_rtp_config(client, rtp_config, rtp_settings, param_name, param_value, pool) &&
!process_profile_config(mod_profile, param_name, param_value, mod_pool)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Unknown param %s\n", param_name);
}
}
agent = mrcp_sofiasip_client_agent_create(config, pool);
agent = mrcp_sofiasip_client_agent_create(name, config, pool);
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "version must be either \"1\" or \"2\"\n");
client = NULL;
@@ -4050,11 +4090,11 @@ static mrcp_client_t *mod_unimrcp_client_create(switch_memory_pool_t *mod_pool)
mrcp_client_rtp_factory_register(client, termination_factory, name);
}
if (agent) {
mrcp_client_signaling_agent_register(client, agent, name);
mrcp_client_signaling_agent_register(client, agent);
}
/* create the profile and register it */
mprofile = mrcp_client_profile_create(NULL, agent, connection_agent, media_engine, termination_factory, pool);
mprofile = mrcp_client_profile_create(NULL, agent, connection_agent, media_engine, termination_factory, rtp_settings, sig_settings, pool);
if (mprofile) {
mrcp_client_profile_register(client, mprofile, name);
}
@@ -4185,11 +4225,12 @@ static apt_log_priority_e str_to_log_level(const char *level)
* Connects UniMRCP logging to FreeSWITCH
* @return TRUE
*/
static apt_bool_t unimrcp_log(const char *file, int line, const char *id, apt_log_priority_e priority, const char *format, va_list arg_ptr)
static apt_bool_t unimrcp_log(const char *file, int line, const char *obj, apt_log_priority_e priority, const char *format, va_list arg_ptr)
{
switch_log_level_t level;
char log_message[4096] = { 0 }; /* same size as MAX_LOG_ENTRY_SIZE in UniMRCP apt_log.c */
size_t msglen;
const char *id = (obj == NULL) ? "" : ((speech_channel_t *)obj)->name;
if (zstr(format)) {
return TRUE;
@@ -4227,10 +4268,10 @@ static apt_bool_t unimrcp_log(const char *file, int line, const char *id, apt_lo
msglen = strlen(log_message);
if (msglen >= 2 && log_message[msglen - 2] == '\\' && log_message[msglen - 1] == 'n') {
/* log_message already ends in \n */
switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, "", line, id, level, "%s", log_message);
switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, "", line, NULL, level, "(%s) %s", id, log_message);
} else if (msglen > 0) {
/* log message needs \n appended */
switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, "", line, id, level, "%s\n", log_message);
switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, "", line, NULL, level, "(%s) %s\n", id, log_message);
}
return TRUE;
@@ -89,7 +89,7 @@ vocallo_codec_t g_codec_map[] =
{ SNGTC_CODEC_PCMA, IANA_PCMA_A_8000_1, "PCMA", "Sangoma PCMA", 40, 64000, 10000, 80, 160, 80, 8000, 8000, 1 },
{ SNGTC_CODEC_L16_1, IANA_L16_A_8000_1, "L16", "Sangoma L16", 40, 120000, 10000, 80, 160, 160, 8000, 8000, 0 },
{ SNGTC_CODEC_L16_2, IANA_L16_A_16000_1, "L16", "Sangoma L16 2", 40, 320000, 10000, 160, 320, 320, 16000, 16000, 0 },
{ SNGTC_CODEC_G729AB, IANA_G729_AB_8000_1, "G729", "Sangoma G729", 200, 8000, 10000, 80, 160, 10, 8000, 8000, 1 },
{ SNGTC_CODEC_G729AB, IANA_G729_AB_8000_1, "G729", "Sangoma G729", 50, 8000, 10000, 80, 160, 10, 8000, 8000, 1 },
{ SNGTC_CODEC_G726_32, IANA_G726_32_8000_1, "G726-32", "Sangoma G.726 32k", 40, 32000, 10000, 80, 160, 40, 8000, 8000, 1 },
{ SNGTC_CODEC_G722, IANA_G722_A_8000_1, "G722", "Sangoma G722", 20, 64000, 10000, 80, 160, 80, 8000, 8000, 1 },
@@ -224,7 +224,7 @@ static int sangoma_create_rtp_port(void *usr_priv, uint32_t host_ip, uint32_t *p
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "New allocated port %d for IP %s/%d.%d.%d.%d\n", rtp_port, local_ip,
SNGTC_NIPV4(host_ip));
*p_rtp_port = rtp_port;
*rtp_fd = (void *)(long)rtp_port;
*rtp_fd = NULL;
return 0;
}
@@ -259,6 +259,9 @@ static int sangoma_create_rtp(void *usr_priv, sngtc_codec_request_leg_t *codec_r
switch_port_t rtp_port;
struct sangoma_transcoding_session *sess = usr_priv;
rtp_port = codec_req_leg->host_udp_port;
*rtp_fd = NULL;
/*
* We *MUST* use a new pool
* Do not use the session pool since the session may go away while the RTP socket should linger around
@@ -271,10 +274,6 @@ static int sangoma_create_rtp(void *usr_priv, sngtc_codec_request_leg_t *codec_r
return -1;
}
rtp_port = (switch_port_t)(long)*rtp_fd;
codec_req_leg->host_udp_port = rtp_port;
local_ip_addr.s_addr = htonl(codec_req_leg->host_ip);
switch_inet_ntop(AF_INET, &local_ip_addr, local_ip, sizeof(local_ip));
sngtc_codec_ipv4_hex_to_str(codec_reply_leg->codec_ip, codec_ip);
@@ -307,6 +306,9 @@ static int sangoma_destroy_rtp(void *usr_priv, void *fd)
{
switch_memory_pool_t *sesspool;
switch_rtp_t *rtp = fd;
if (!rtp) {
return 0;
}
sesspool = switch_rtp_get_private(rtp);
switch_rtp_destroy(&rtp);
switch_core_destroy_memory_pool(&sesspool);
@@ -1267,10 +1269,10 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_sangoma_codec_load)
* At this point there is an empty shell codec interface registered, but not yet implementations */
SWITCH_ADD_CODEC(codec_interface, g_codec_map[c].fs_name);
/* Now add as many codec implementations as needed, just up to 40ms for now */
/* Now add as many codec implementations as needed, just up to 200ms for now */
if (g_codec_map[c].autoinit) {
int ms = 0;
for (i = 1; i <= 4; i++) {
for (i = 1; i <= 20; i++) {
ms = i * 10;
if (g_codec_map[c].maxms < ms) {
break;
@@ -222,6 +222,11 @@ static int parse_exten(switch_core_session_t *session, switch_caller_profile_t *
proceed = 1;
}
} else {
if (field && strchr(expression, '(')) {
switch_channel_set_variable(channel, "DP_MATCH", NULL);
switch_capture_regex(re, proceed, field_data, ovector, "DP_MATCH", switch_regex_set_var_callback, session);
}
for (xaction = switch_xml_child(xcond, "action"); xaction; xaction = xaction->next) {
char *application = (char *) switch_xml_attr_soft(xaction, "application");
const char *loop = switch_xml_attr(xaction, "loop");
@@ -30,7 +30,6 @@
*
*/
#include <switch.h>
#include <switch_ssl.h>
#include <switch_stun.h>
#include <libdingaling.h>
@@ -1912,9 +1911,6 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_dingaling_load)
SWITCH_ADD_API(api_interface, "dingaling", "DingaLing Menu", dingaling, DINGALING_SYNTAX);
SWITCH_ADD_CHAT(chat_interface, MDL_CHAT_PROTO, chat_send);
switch_ssl_init_ssl_locks();
/* indicate that the module should continue to be loaded */
return SWITCH_STATUS_SUCCESS;
}
@@ -2012,8 +2008,6 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_dingaling_shutdown)
switch_safe_free(globals.codec_string);
switch_safe_free(globals.codec_rates_string);
switch_ssl_destroy_ssl_locks();
return SWITCH_STATUS_SUCCESS;
}
+21 -14
View File
@@ -54,7 +54,8 @@ typedef enum {
TFLAG_BLEG = (1 << 6),
TFLAG_APP = (1 << 7),
TFLAG_RUNNING_APP = (1 << 8),
TFLAG_BOWOUT_USED = (1 << 9)
TFLAG_BOWOUT_USED = (1 << 9),
TFLAG_CLEAR = (1 << 10)
} TFLAGS;
struct private_object {
@@ -105,6 +106,17 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch
static switch_status_t channel_write_frame(switch_core_session_t *session, switch_frame_t *frame, switch_io_flag_t flags, int stream_id);
static switch_status_t channel_kill_channel(switch_core_session_t *session, int sig);
static void clear_queue(private_t *tech_pvt)
{
void *pop;
while (switch_queue_trypop(tech_pvt->frame_queue, &pop) == SWITCH_STATUS_SUCCESS && pop) {
switch_frame_t *frame = (switch_frame_t *) pop;
switch_frame_free(&frame);
}
}
static switch_status_t tech_init(private_t *tech_pvt, switch_core_session_t *session, switch_codec_t *codec)
{
const char *iananame = "L16";
@@ -566,6 +578,12 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch
mutex = tech_pvt->mutex;
switch_mutex_lock(mutex);
if (switch_test_flag(tech_pvt, TFLAG_CLEAR)) {
clear_queue(tech_pvt);
switch_clear_flag(tech_pvt, TFLAG_CLEAR);
}
if (switch_queue_trypop(tech_pvt->frame_queue, &pop) == SWITCH_STATUS_SUCCESS && pop) {
if (tech_pvt->write_frame) {
switch_frame_free(&tech_pvt->write_frame);
@@ -599,17 +617,6 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch
return status;
}
static void clear_queue(private_t *tech_pvt)
{
void *pop;
while (switch_queue_trypop(tech_pvt->frame_queue, &pop) == SWITCH_STATUS_SUCCESS && pop) {
switch_frame_t *frame = (switch_frame_t *) pop;
switch_frame_free(&frame);
}
}
static switch_status_t channel_write_frame(switch_core_session_t *session, switch_frame_t *frame, switch_io_flag_t flags, int stream_id)
{
switch_channel_t *channel = NULL;
@@ -750,9 +757,9 @@ static switch_status_t channel_receive_message(switch_core_session_t *session, s
{
done = 1;
switch_set_flag(tech_pvt, TFLAG_CLEAR);
switch_set_flag(tech_pvt->other_tech_pvt, TFLAG_CLEAR);
clear_queue(tech_pvt);
clear_queue(tech_pvt->other_tech_pvt);
switch_core_timer_sync(&tech_pvt->timer);
switch_core_timer_sync(&tech_pvt->other_tech_pvt->timer);
}
File diff suppressed because it is too large. Load diff
+68 -38
View File
@@ -78,14 +78,23 @@ static PaError PABLIO_TermFIFO(PaUtilRingBuffer * rbuf);
static int iblockingIOCallback(const void *inputBuffer, void *outputBuffer,
unsigned long framesPerBuffer, const PaStreamCallbackTimeInfo * timeInfo, PaStreamCallbackFlags statusFlags, void *userData)
{
int c = 0, i = 0, j = 0;
PABLIO_Stream *data = (PABLIO_Stream *) userData;
long numBytes = data->bytesPerFrame * framesPerBuffer;
const int16_t *inputSamples = inputBuffer;
int16_t *chanSamples = (int16_t*)data->iobuff;
/* This may get called with NULL inputBuffer during initial setup. */
if (inputBuffer != NULL) {
if (PaUtil_WriteRingBuffer(&data->inFIFO, inputBuffer, numBytes) != numBytes) {
PaUtil_FlushRingBuffer(&data->inFIFO);
PaUtil_WriteRingBuffer(&data->inFIFO, inputBuffer, numBytes);
/* retrieve the data for each channel and put it in the ring buffer */
for (c = 0; c < data->channelCount; c++) {
for (i = 0, j = c; i < framesPerBuffer; j += data->channelCount, i++) {
chanSamples[i] = inputSamples[j];
}
if (PaUtil_WriteRingBuffer(&data->inFIFOs[c], chanSamples, numBytes) != numBytes) {
PaUtil_FlushRingBuffer(&data->inFIFOs[c]);
PaUtil_WriteRingBuffer(&data->inFIFOs[c], inputBuffer, numBytes);
}
}
}
@@ -97,13 +106,21 @@ static int oblockingIOCallback(const void *inputBuffer, void *outputBuffer,
{
PABLIO_Stream *data = (PABLIO_Stream *) userData;
long numBytes = data->bytesPerFrame * framesPerBuffer;
int16_t *outputSamples = outputBuffer;
int16_t *chanSamples = (short *)data->iobuff;
int c = 0, i = 0, j = 0;
if (outputBuffer != NULL) {
int i;
int numRead = PaUtil_ReadRingBuffer(&data->outFIFO, outputBuffer, numBytes);
/* Zero out remainder of buffer if we run out of data. */
for (i = numRead; i < numBytes; i++) {
((char *) outputBuffer)[i] = 0;
for (c = 0; c < data->channelCount; c++) {
int numRead = PaUtil_ReadRingBuffer(&data->outFIFOs[c], chanSamples, numBytes);
numRead = numRead / sizeof(int16_t);
for (i = 0, j = c; i < framesPerBuffer; j += data->channelCount, i++) {
if (i < numRead) {
outputSamples[j] = chanSamples[i];
} else {
outputSamples[j] = 0;
}
}
}
}
@@ -143,7 +160,7 @@ static PaError PABLIO_TermFIFO(PaUtilRingBuffer * rbuf)
* Write data to ring buffer.
* Will not return until all the data has been written.
*/
long WriteAudioStream(PABLIO_Stream * aStream, void *data, long numFrames, switch_timer_t *timer)
long WriteAudioStream(PABLIO_Stream * aStream, void *data, long numFrames, int chan, switch_timer_t *timer)
{
long bytesWritten;
char *p = (char *) data;
@@ -151,12 +168,12 @@ long WriteAudioStream(PABLIO_Stream * aStream, void *data, long numFrames, switc
switch_core_timer_next(timer);
bytesWritten = PaUtil_WriteRingBuffer(&aStream->outFIFO, p, numBytes);
bytesWritten = PaUtil_WriteRingBuffer(&aStream->outFIFOs[chan], p, numBytes);
numBytes -= bytesWritten;
p += bytesWritten;
if (numBytes > 0) {
PaUtil_FlushRingBuffer(&aStream->outFIFO);
PaUtil_FlushRingBuffer(&aStream->outFIFOs[chan]);
return 0;
}
return numFrames;
@@ -166,7 +183,7 @@ long WriteAudioStream(PABLIO_Stream * aStream, void *data, long numFrames, switc
* Read data from ring buffer.
* Will not return until all the data has been read.
*/
long ReadAudioStream(PABLIO_Stream * aStream, void *data, long numFrames, switch_timer_t *timer)
long ReadAudioStream(PABLIO_Stream * aStream, void *data, long numFrames, int chan, switch_timer_t *timer)
{
long bytesRead = 0;
char *p = (char *) data;
@@ -177,17 +194,17 @@ long ReadAudioStream(PABLIO_Stream * aStream, void *data, long numFrames, switch
while (totalBytes < neededBytes && --max > 0) {
avail = PaUtil_GetRingBufferReadAvailable(&aStream->inFIFO);
avail = PaUtil_GetRingBufferReadAvailable(&aStream->inFIFOs[chan]);
//printf("AVAILABLE BYTES %ld pass %d\n", avail, 5000 - max);
if (avail >= neededBytes * 6) {
PaUtil_FlushRingBuffer(&aStream->inFIFO);
PaUtil_FlushRingBuffer(&aStream->inFIFOs[chan]);
avail = 0;
} else {
bytesRead = 0;
if (totalBytes < neededBytes && avail >= neededBytes) {
bytesRead = PaUtil_ReadRingBuffer(&aStream->inFIFO, p, neededBytes);
bytesRead = PaUtil_ReadRingBuffer(&aStream->inFIFOs[chan], p, neededBytes);
totalBytes += bytesRead;
}
@@ -206,9 +223,9 @@ long ReadAudioStream(PABLIO_Stream * aStream, void *data, long numFrames, switch
* Return the number of frames that could be written to the stream without
* having to wait.
*/
long GetAudioStreamWriteable(PABLIO_Stream * aStream)
long GetAudioStreamWriteable(PABLIO_Stream * aStream, int chan)
{
int bytesEmpty = PaUtil_GetRingBufferWriteAvailable(&aStream->outFIFO);
int bytesEmpty = PaUtil_GetRingBufferWriteAvailable(&aStream->outFIFOs[chan]);
return bytesEmpty / aStream->bytesPerFrame;
}
@@ -216,9 +233,9 @@ long GetAudioStreamWriteable(PABLIO_Stream * aStream)
* Return the number of frames that are available to be read from the
* stream without having to wait.
*/
long GetAudioStreamReadable(PABLIO_Stream * aStream)
long GetAudioStreamReadable(PABLIO_Stream * aStream, int chan)
{
int bytesFull = PaUtil_GetRingBufferReadAvailable(&aStream->inFIFO);
int bytesFull = PaUtil_GetRingBufferReadAvailable(&aStream->inFIFOs[chan]);
return bytesFull / aStream->bytesPerFrame;
}
@@ -251,7 +268,8 @@ PaError OpenAudioStream(PABLIO_Stream ** rwblPtr,
PABLIO_Stream *aStream;
long numFrames;
//long numBytes;
//int channels = 1;
int c = 0;
int channels = 1;
if (!(inputParameters || outputParameters)) {
return -1;
@@ -262,31 +280,34 @@ PaError OpenAudioStream(PABLIO_Stream ** rwblPtr,
switch_assert(aStream);
memset(aStream, 0, sizeof(PABLIO_Stream));
/*
if (inputParameters) {
channels = inputParameters->channelCount;
} else if (outputParameters) {
channels = outputParameters->channelCount;
}
*/
numFrames = RoundUpToNextPowerOf2(samples_per_packet * 5);
aStream->bytesPerFrame = bytesPerSample;
aStream->channelCount = channels;
/* Initialize Ring Buffers */
if (inputParameters) {
err = PABLIO_InitFIFO(&aStream->inFIFO, numFrames, aStream->bytesPerFrame);
if (err != paNoError) {
goto error;
for (c = 0; c < channels; c++) {
err = PABLIO_InitFIFO(&aStream->inFIFOs[c], numFrames, aStream->bytesPerFrame);
if (err != paNoError) {
goto error;
}
}
aStream->has_in = 1;
}
if (outputParameters) {
err = PABLIO_InitFIFO(&aStream->outFIFO, numFrames, aStream->bytesPerFrame);
if (err != paNoError) {
goto error;
for (c = 0; c < channels; c++) {
err = PABLIO_InitFIFO(&aStream->outFIFOs[c], numFrames, aStream->bytesPerFrame);
if (err != paNoError) {
goto error;
}
}
aStream->has_out = 1;
}
@@ -355,17 +376,21 @@ PaError CloseAudioStream(PABLIO_Stream * aStream)
{
int bytesEmpty;
int byteSize;
int c = 0;
byteSize = aStream->outFIFO.bufferSize;
if (aStream->has_out) {
/* If we are writing data, make sure we play everything written. */
if (byteSize > 0) {
bytesEmpty = PaUtil_GetRingBufferWriteAvailable(&aStream->outFIFO);
while (bytesEmpty < byteSize) {
Pa_Sleep(10);
bytesEmpty = PaUtil_GetRingBufferWriteAvailable(&aStream->outFIFO);
for (c = 0; c < aStream->channelCount; c++) {
byteSize = aStream->outFIFOs[c].bufferSize;
/* If we are writing data, make sure we play everything written. */
if (byteSize > 0) {
bytesEmpty = PaUtil_GetRingBufferWriteAvailable(&aStream->outFIFOs[c]);
while (bytesEmpty < byteSize) {
Pa_Sleep(10);
bytesEmpty = PaUtil_GetRingBufferWriteAvailable(&aStream->outFIFOs[c]);
}
}
}
}
@@ -401,11 +426,15 @@ PaError CloseAudioStream(PABLIO_Stream * aStream)
}
if (aStream->has_in) {
PABLIO_TermFIFO(&aStream->inFIFO);
for (c = 0; c < aStream->channelCount; c++) {
PABLIO_TermFIFO(&aStream->inFIFOs[c]);
}
}
if (aStream->has_out) {
PABLIO_TermFIFO(&aStream->outFIFO);
for (c = 0; c < aStream->channelCount; c++) {
PABLIO_TermFIFO(&aStream->outFIFOs[c]);
}
}
free(aStream);
@@ -413,3 +442,4 @@ PaError CloseAudioStream(PABLIO_Stream * aStream)
return paNoError;
}
+33 -20
View File
@@ -56,17 +56,30 @@ extern "C" {
#include <string.h>
typedef struct {
PaUtilRingBuffer inFIFO;
PaUtilRingBuffer outFIFO;
PaStream *istream;
PaStream *ostream;
PaStream *iostream;
int bytesPerFrame;
int do_dual;
int has_in;
int has_out;
} PABLIO_Stream;
/*! Maximum number of channels per stream */
#define MAX_IO_CHANNELS 2
/*! Maximum numer of milliseconds per packet */
#define MAX_IO_MS 100
/*! Maximum sampling rate (48Khz) */
#define MAX_SAMPLING_RATE 48000
/* Maximum size of a read */
#define MAX_IO_BUFFER (((MAX_IO_MS * MAX_SAMPLING_RATE)/1000)*sizeof(int16_t))
typedef struct {
PaStream *istream;
PaStream *ostream;
PaStream *iostream;
int bytesPerFrame;
int do_dual;
int has_in;
int has_out;
PaUtilRingBuffer inFIFOs[MAX_IO_CHANNELS];
PaUtilRingBuffer outFIFOs[MAX_IO_CHANNELS];
int channelCount;
char iobuff[MAX_IO_BUFFER];
} PABLIO_Stream;
/* Values for flags for OpenAudioStream(). */
#define PABLIO_READ (1<<0)
@@ -79,25 +92,25 @@ extern "C" {
* Write data to ring buffer.
* Will not return until all the data has been written.
*/
long WriteAudioStream(PABLIO_Stream * aStream, void *data, long numFrames, switch_timer_t *timer);
long WriteAudioStream(PABLIO_Stream * aStream, void *data, long numFrames, int chan, switch_timer_t *timer);
/************************************************************
* Read data from ring buffer.
* Will not return until all the data has been read.
*/
long ReadAudioStream(PABLIO_Stream * aStream, void *data, long numFrames, switch_timer_t *timer);
long ReadAudioStream(PABLIO_Stream * aStream, void *data, long numFrames, int chan, switch_timer_t *timer);
/************************************************************
* Return the number of frames that could be written to the stream without
* having to wait.
*/
long GetAudioStreamWriteable(PABLIO_Stream * aStream);
long GetAudioStreamWriteable(PABLIO_Stream * aStream, int chan);
/************************************************************
* Return the number of frames that are available to be read from the
* stream without having to wait.
*/
long GetAudioStreamReadable(PABLIO_Stream * aStream);
long GetAudioStreamReadable(PABLIO_Stream * aStream, int chan);
/************************************************************
* Opens a PortAudio stream with default characteristics.
@@ -107,12 +120,12 @@ extern "C" {
* PABLIO_READ, PABLIO_WRITE, or PABLIO_READ_WRITE,
* and either PABLIO_MONO or PABLIO_STEREO
*/
PaError OpenAudioStream(PABLIO_Stream ** rwblPtr,
const PaStreamParameters * inputParameters,
const PaStreamParameters * outputParameters,
double sampleRate, PaStreamCallbackFlags statusFlags, long samples_per_packet, int do_dual);
PaError OpenAudioStream(PABLIO_Stream ** rwblPtr,
const PaStreamParameters * inputParameters,
const PaStreamParameters * outputParameters,
double sampleRate, PaStreamCallbackFlags statusFlags, long samples_per_packet, int do_dual);
PaError CloseAudioStream(PABLIO_Stream * aStream);
PaError CloseAudioStream(PABLIO_Stream * aStream);
#ifdef __cplusplus
}
+7
View File
@@ -0,0 +1,7 @@
BASE=../../../..
LIBAMF_OBJS=libamf/src/amf0.o libamf/src/hash.o libamf/src/io.o libamf/src/ptrarray.o libamf/src/types.o
LOCAL_OBJS=rtmp_sig.o rtmp.o rtmp_tcp.o $(LIBAMF_OBJS)
LOCAL_CFLAGS=-Ilibamf/src
include $(BASE)/build/modmake.rules
@@ -0,0 +1,64 @@
cmake_minimum_required(VERSION 2.6)
project(libamf C)
# generic variables
set(PACKAGE "libamf")
set(PACKAGE_NAME ${PACKAGE})
set(PACKAGE_BUGREPORT "libamf@sf.net")
set(PACKAGE_VERSION "0.1.0")
set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}")
#platform tests
include(CheckFunctionExists)
include(CheckIncludeFile)
include(CheckTypeSize)
include(TestBigEndian)
check_include_file(sys/types.h HAVE_SYS_TYPES_H)
check_include_file(stdint.h HAVE_STDINT_H)
check_include_file(stddef.h HAVE_STDDEF_H)
check_include_file(inttypes.h HAVE_INTTYPES_H)
check_type_size("double" SIZEOF_DOUBLE)
check_type_size("float" SIZEOF_FLOAT)
check_type_size("long double" SIZEOF_LONG_DOUBLE)
if(WIN32)
set(int16_t 1)
set(int32_t 1)
set(int64_t 1)
set(int8_t 1)
set(uint16_t 1)
set(uint32_t 1)
set(uint64_t 1)
set(uint8_t 1)
endif(WIN32)
test_big_endian(IS_BIGENDIAN)
if(IS_BIGENDIAN)
set(WORDS_BIGENDIAN 1)
endif(IS_BIGENDIAN)
# configuration file
configure_file(amf-cmake.h.in ${CMAKE_BINARY_DIR}/amf.h)
include_directories(${CMAKE_BINARY_DIR})
install(
FILES ${CMAKE_BINARY_DIR}/amf.h
DESTINATION include/amf
)
# Visual C++ specific configuration
if(MSVC)
# use static library
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /MT")
# C runtime deprecation in Visual C++ 2005 and later
add_definitions(-D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE)
endif(MSVC)
add_subdirectory(src)
# tests
enable_testing()
add_subdirectory(tests)
@@ -0,0 +1,105 @@
#ifndef __AMF_H__
#define __AMF_H__
/* Name of package */
#define PACKAGE "@PACKAGE@"
/* Define to the address where bug reports for this package should be sent. */
#define PACKAGE_BUGREPORT "@PACKAGE_BUGREPORT@"
/* Define to the full name of this package. */
#define PACKAGE_NAME "@PACKAGE_NAME@"
/* Define to the full name and version of this package. */
#define PACKAGE_STRING "@PACKAGE_STRING@"
/* Define to the one symbol short name of this package. */
#define PACKAGE_TARNAME "@PACKAGE_NAME@"
/* Define to the version of this package. */
#define PACKAGE_VERSION "@PACKAGE_VERSION@"
/* The size of `double', as computed by sizeof. */
#define SIZEOF_DOUBLE @SIZEOF_DOUBLE@
/* The size of `float', as computed by sizeof. */
#define SIZEOF_FLOAT @SIZEOF_FLOAT@
/* The size of `long double', as computed by sizeof. */
#define SIZEOF_LONG_DOUBLE @SIZEOF_LONG_DOUBLE@
/* Version number of package */
#define VERSION "@PACKAGE_VERSION@"
/* Define to 1 if you have the <sys/types.h> header file. */
#cmakedefine HAVE_SYS_TYPES_H
/* Define to 1 if you have the <stdint.h> header file. */
#cmakedefine HAVE_STDINT_H
/* Define to 1 if you have the <stddef.h> header file. */
#cmakedefine HAVE_STDDEF_H
/* Define to 1 if you have the <inttypes.h> header file. */
#cmakedefine HAVE_INTTYPES_H
/* Define to 1 if your processor stores words with the most significant byte
first (like Motorola and SPARC, unlike Intel and VAX). */
#cmakedefine WORDS_BIGENDIAN
/* Define to the type of an integer type of width exactly 16 bits if
such a type exists and the standard includes do not define it. */
#cmakedefine int16_t short int
/* Define to the type of an integer type of width exactly 32 bits if
such a type exists and the standard includes do not define it. */
#cmakedefine int32_t int
/* Define to the type of an integer type of width exactly 64 bits if
such a type exists and the standard includes do not define it. */
#cmakedefine int64_t long long int
/* Define to the type of an integer type of width exactly 8 bits if
such a type exists and the standard includes do not define it. */
#cmakedefine int8_t char
/* Define to the type of an unsigned integer type of width exactly 16 bits if
such a type exists and the standard includes do not define it. */
#cmakedefine uint16_t unsigned short int
/* Define to the type of an unsigned integer type of width exactly 32 bits if
such a type exists and the standard includes do not define it. */
#cmakedefine uint32_t unsigned int
/* Define to the type of an unsigned integer type of width exactly 64 bits if
such a type exists and the standard includes do not define it. */
#cmakedefine uint64_t unsigned long long int
/* Define to the type of an unsigned integer type of width exactly 8 bits if
such a type exists and the standard includes do not define it. */
#cmakedefine uint8_t unsigned char
#ifdef HAVE_INTTYPES_H
#include <inttypes.h>
#endif
#include <stdlib.h>
/* AMF number */
typedef
#if SIZEOF_FLOAT == 8
float
#elif SIZEOF_DOUBLE == 8
double
#elif SIZEOF_LONG_DOUBLE == 8
long double
#else
uint64_t
#endif
number64_t;
/* custom read/write function type */
typedef size_t (*read_proc_t)(void * out_buffer, size_t size, void * user_data);
typedef size_t (*write_proc_t)(const void * in_buffer, size_t size, void * user_data);
#endif /* __AMF_H__ */
@@ -0,0 +1,26 @@
set(libamf_src
amf0.c
amf0.h
hash.c
hash.h
io.c
io.h
ptrarray.c
ptrarray.h
types.c
types.h
${CMAKE_BINARY_DIR}/amf.h
)
add_library(amf ${libamf_src})
install(TARGETS amf
RUNTIME DESTINATION lib
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
)
install(
FILES amf0.h amf3.h
DESTINATION include/amf
)
@@ -0,0 +1,13 @@
#ifndef __AMF_H__
#define __AMF_H__
#include <switch.h>
/* AMF number */
typedef double number64_t;
/* custom read/write function type */
typedef size_t (*read_proc_t)(void * out_buffer, size_t size, void * user_data);
typedef size_t (*write_proc_t)(const void * in_buffer, size_t size, void * user_data);
#endif /* __AMF_H__ */
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,190 @@
#ifndef __AMF0_H__
#define __AMF0_H__
#include <stdio.h>
#include <time.h>
#include "amf.h"
/* AMF data types */
#define AMF0_TYPE_NUMBER 0x00
#define AMF0_TYPE_BOOLEAN 0x01
#define AMF0_TYPE_STRING 0x02
#define AMF0_TYPE_OBJECT 0x03
#define AMF0_TYPE_MOVIECLIP 0x04 /* reserved, not supported */
#define AMF0_TYPE_NULL 0x05
#define AMF0_TYPE_UNDEFINED 0x06
#define AMF0_TYPE_REFERENCE 0x07
#define AMF0_TYPE_ECMA_ARRAY 0x08
#define AMF0_TYPE_OBJECT_END 0x09
#define AMF0_TYPE_STRICT_ARRAY 0x0A
#define AMF0_TYPE_DATE 0x0B
#define AMF0_TYPE_LONG_STRING 0x0C
#define AMF0_TYPE_UNSUPPORTED 0x0D
#define AMF0_TYPE_RECORDSET 0x0E /* reserved, not supported */
#define AMF0_TYPE_XML_DOCUMENT 0x0F
#define AMF0_TYPE_TYPED_OBJECT 0x10
typedef struct __amf0_node * p_amf0_node;
/* string type */
typedef struct __amf0_string {
uint16_t size;
uint8_t * mbstr;
} amf0_string;
/* array type */
typedef struct __amf0_list {
uint32_t size;
p_amf0_node first_element;
p_amf0_node last_element;
} amf0_list;
/* date type */
typedef struct __amf0_date {
number64_t milliseconds;
int16_t timezone;
} amf0_date;
/* XML string type */
typedef struct __amf0_xmlstring {
uint32_t size;
uint8_t * mbstr;
} amf0_xmlstring;
/* class type */
typedef struct __amf0_class {
amf0_string name;
amf0_list elements;
} amf0_class;
/* structure encapsulating the various AMF objects */
typedef struct __amf0_data {
uint8_t type;
union {
number64_t number_data;
uint8_t boolean_data;
amf0_string string_data;
amf0_list list_data;
amf0_date date_data;
amf0_xmlstring xmlstring_data;
amf0_class class_data;
} u;
} amf0_data;
/* node used in lists, relies on amf0_data */
typedef struct __amf0_node {
amf0_data * data;
p_amf0_node prev;
p_amf0_node next;
} amf0_node;
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/* read AMF data */
amf0_data * amf0_data_read(read_proc_t read_proc, void * user_data);
/* write AMF data */
size_t amf0_data_write(amf0_data * data, write_proc_t write_proc, void * user_data);
/* generic functions */
/* allocate an AMF data object */
amf0_data * amf0_data_new(uint8_t type);
/* load AMF data from buffer */
amf0_data * amf0_data_buffer_read(uint8_t * buffer, size_t maxbytes);
/* load AMF data from stream */
amf0_data * amf0_data_file_read(FILE * stream);
/* AMF data size */
size_t amf0_data_size(amf0_data * data);
/* write encoded AMF data into a buffer */
size_t amf0_data_buffer_write(amf0_data * data, uint8_t * buffer, size_t maxbytes);
/* write encoded AMF data into a stream */
size_t amf0_data_file_write(amf0_data * data, FILE * stream);
/* get the type of AMF data */
uint8_t amf0_data_get_type(amf0_data * data);
/* return a new copy of AMF data */
amf0_data * amf0_data_clone(amf0_data * data);
/* release the memory of AMF data */
void amf0_data_free(amf0_data * data);
/* dump AMF data into a stream as text */
void amf0_data_dump(FILE * stream, amf0_data * data, int indent_level);
/* number functions */
amf0_data * amf0_number_new(number64_t value);
number64_t amf0_number_get_value(amf0_data * data);
void amf0_number_set_value(amf0_data * data, number64_t value);
/* boolean functions */
amf0_data * amf0_boolean_new(uint8_t value);
uint8_t amf0_boolean_get_value(amf0_data * data);
void amf0_boolean_set_value(amf0_data * data, uint8_t value);
/* string functions */
amf0_data * amf0_string_new(uint8_t * str, uint16_t size);
amf0_data * amf0_str(const char * str);
uint16_t amf0_string_get_size(amf0_data * data);
uint8_t * amf0_string_get_uint8_ts(amf0_data * data);
/* object functions */
amf0_data * amf0_object_new(void);
uint32_t amf0_object_size(amf0_data * data);
amf0_data * amf0_object_add(amf0_data * data, const char * name, amf0_data * element);
amf0_data * amf0_object_get(amf0_data * data, const char * name);
amf0_data * amf0_object_set(amf0_data * data, const char * name, amf0_data * element);
amf0_data * amf0_object_delete(amf0_data * data, const char * name);
amf0_node * amf0_object_first(amf0_data * data);
amf0_node * amf0_object_last(amf0_data * data);
amf0_node * amf0_object_next(amf0_node * node);
amf0_node * amf0_object_prev(amf0_node * node);
amf0_data * amf0_object_get_name(amf0_node * node);
amf0_data * amf0_object_get_data(amf0_node * node);
/* null functions */
#define amf0_null_new() amf0_data_new(AMF0_TYPE_NULL)
/* undefined functions */
#define amf0_undefined_new() amf0_data_new(AMF0_TYPE_UNDEFINED)
/* associative array functions */
amf0_data * amf0_associative_array_new(void);
#define amf0_associative_array_size(d) amf0_object_size(d)
#define amf0_associative_array_add(d, n, e) amf0_object_add(d, n, e)
#define amf0_associative_array_get(d, n) amf0_object_get(d, n)
#define amf0_associative_array_set(d, n, e) amf0_object_set(d, n, e)
#define amf0_associative_array_delete(d, n) amf0_object_delete(d, n)
#define amf0_associative_array_first(d) amf0_object_first(d)
#define amf0_associative_array_last(d) amf0_object_last(d)
#define amf0_associative_array_next(n) amf0_object_next(n)
#define amf0_associative_array_prev(n) amf0_object_prev(n)
#define amf0_associative_array_get_name(n) amf0_object_get_name(n)
#define amf0_associative_array_get_data(n) amf0_object_get_data(n)
/* array functions */
amf0_data * amf0_array_new(void);
uint32_t amf0_array_size(amf0_data * data);
amf0_data * amf0_array_push(amf0_data * data, amf0_data * element);
amf0_data * amf0_array_pop(amf0_data * data);
amf0_node * amf0_array_first(amf0_data * data);
amf0_node * amf0_array_last(amf0_data * data);
amf0_node * amf0_array_next(amf0_node * node);
amf0_node * amf0_array_prev(amf0_node * node);
amf0_data * amf0_array_get(amf0_node * node);
amf0_data * amf0_array_get_at(amf0_data * data, uint32_t n);
amf0_data * amf0_array_delete(amf0_data * data, amf0_node * node);
amf0_data * amf0_array_insert_before(amf0_data * data, amf0_node * node, amf0_data * element);
amf0_data * amf0_array_insert_after(amf0_data * data, amf0_node * node, amf0_data * element);
/* date functions */
amf0_data * amf0_date_new(number64_t milliseconds, int16_t timezone);
number64_t amf0_date_get_milliseconds(amf0_data * data);
int16_t amf0_date_get_timezone(amf0_data * data);
time_t amf0_date_to_time_t(amf0_data * data);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* __AMF0_H__ */
Whitespace-only changes.
@@ -0,0 +1,130 @@
/* function common to all array types */
static void amf_list_init(amf_list * list) {
if (list != NULL) {
list->size = 0;
list->first_element = NULL;
list->last_element = NULL;
}
}
static amf_data * amf_list_push(amf_list * list, amf_data * data) {
amf_node * node = (amf_node*)malloc(sizeof(amf_node));
if (node != NULL) {
node->data = data;
node->next = NULL;
node->prev = NULL;
if (list->size == 0) {
list->first_element = node;
list->last_element = node;
}
else {
list->last_element->next = node;
node->prev = list->last_element;
list->last_element = node;
}
++(list->size);
return data;
}
return NULL;
}
static amf_data * amf_list_insert_before(amf_list * list, amf_node * node, amf_data * data) {
if (node != NULL) {
amf_node * new_node = (amf_node*)malloc(sizeof(amf_node));
if (new_node != NULL) {
new_node->next = node;
new_node->prev = node->prev;
if (node->prev != NULL) {
node->prev->next = new_node;
node->prev = new_node;
}
if (node == list->first_element) {
list->first_element = new_node;
}
++(list->size);
new_node->data = data;
return data;
}
}
return NULL;
}
static amf_data * amf_list_insert_after(amf_list * list, amf_node * node, amf_data * data) {
if (node != NULL) {
amf_node * new_node = (amf_node*)malloc(sizeof(amf_node));
if (new_node != NULL) {
new_node->next = node->next;
new_node->prev = node;
if (node->next != NULL) {
node->next->prev = new_node;
node->next = new_node;
}
if (node == list->last_element) {
list->last_element = new_node;
}
++(list->size);
new_node->data = data;
return data;
}
}
return NULL;
}
static amf_data * amf_list_delete(amf_list * list, amf_node * node) {
amf_data * data = NULL;
if (node != NULL) {
if (node->next != NULL) {
node->next->prev = node->prev;
}
if (node->prev != NULL) {
node->prev->next = node->next;
}
if (node == list->first_element) {
list->first_element = node->next;
}
if (node == list->last_element) {
list->last_element = node->prev;
}
data = node->data;
free(node);
--(list->size);
}
return data;
}
static amf_data * amf_list_get_at(amf_list * list, uint32 n) {
if (n < list->size) {
uint32 i;
amf_node * node = list->first_element;
for (i = 0; i < n; ++i) {
node = node->next;
}
return node->data;
}
return NULL;
}
static amf_data * amf_list_pop(amf_list * list) {
return amf_list_delete(list, list->last_element);
}
static amf_node * amf_list_first(amf_list * list) {
return list->first_element;
}
static amf_node * amf_list_last(amf_list * list) {
return list->last_element;
}
static void amf_list_clear(amf_list * list) {
amf_node * node = list->first_element;
while (node != NULL) {
amf_data_free(node->data);
amf_node * tmp = node;
node = node->next;
free(tmp);
}
list->size = 0;
}
@@ -0,0 +1,5 @@
typedef struct __amf_list {
uint32 size;
p_amf_node first_element;
p_amf_node last_element;
} amf_list;
@@ -0,0 +1,312 @@
#include <stdlib.h>
#include <string.h>
#include "hash.h"
#define assert(x)
/*static void *malloc_and_zero(int n){
void *p = malloc(n);
if( p ){
memset(p, 0, n);
}
return p;
}*/
/**
Create a hash table
*/
Hash * HashCreate(char copyKey) {
return HashCreateAlloc(copyKey, malloc, free);
}
Hash * HashCreateAlloc(char copyKey, void *(*xMalloc)(size_t), void (*xFree)(void *)) {
Hash * pHash = (Hash*)xMalloc(sizeof(Hash));
if (pHash != NULL) {
HashInit(pHash, copyKey, xMalloc, xFree);
return pHash;
}
else {
return 0;
}
}
/**
Erase the hash table
*/
void HashFree(Hash* pHash) {
pHash->xFree(pHash);
}
/*
insert a string key element
*/
void * HashInsertSz(Hash *pH, const char *pKey, void *data) {
return HashInsert(pH, pKey, (int) strlen(pKey)+1, data);
}
/*
find a string key element
*/
void * HashFindSz(const Hash* pH, const char *pKey) {
return HashFind(pH, pKey, (int) strlen(pKey)+1);
}
/* Turn bulk memory into a hash table object by initializing the
** fields of the Hash structure.
**
** "pNew" is a pointer to the hash table that is to be initialized.
** "copyKey" is true if the hash table should make its own private
** copy of keys and false if it should just use the supplied pointer.
*/
void HashInit(Hash* pNew, char copyKey, void *(*xMalloc)(size_t), void (*xFree)(void *)){
assert( pNew!=0 );
pNew->copyKey = copyKey;
pNew->first = 0;
pNew->count = 0;
pNew->htsize = 0;
pNew->ht = 0;
pNew->xMalloc = xMalloc;
pNew->xFree = xFree;
}
/* Remove all entries from a hash table. Reclaim all memory.
** Call this routine to delete a hash table or to reset a hash table
** to the empty state.
*/
void HashClear(Hash *pH){
HashElem *elem; /* For looping over all elements of the table */
assert( pH!=0 );
elem = pH->first;
pH->first = 0;
if( pH->ht ) pH->xFree(pH->ht);
pH->ht = 0;
pH->htsize = 0;
while( elem ){
HashElem *next_elem = elem->next;
if( pH->copyKey && elem->pKey ){
pH->xFree(elem->pKey);
}
pH->xFree(elem);
elem = next_elem;
}
pH->count = 0;
}
/*
** Hash and comparison functions
*/
static int binHash(const void *pKey, int nKey){
int h = 0;
const char *z = (const char *)pKey;
while( nKey-- > 0 ){
h = (h<<3) ^ h ^ *(z++);
}
return h & 0x7fffffff;
}
static int binCompare(const void *pKey1, int n1, const void *pKey2, int n2){
if( n1!=n2 ) return 1;
return memcmp(pKey1,pKey2,n1);
}
/* Link an element into the hash table
*/
static void insertElement(
Hash *pH, /* The complete hash table */
struct _ht *pEntry, /* The entry into which pNew is inserted */
HashElem *pNew /* The element to be inserted */
){
HashElem *pHead; /* First element already in pEntry */
pHead = pEntry->chain;
if( pHead ){
pNew->next = pHead;
pNew->prev = pHead->prev;
if( pHead->prev ){ pHead->prev->next = pNew; }
else { pH->first = pNew; }
pHead->prev = pNew;
}else{
pNew->next = pH->first;
if( pH->first ){ pH->first->prev = pNew; }
pNew->prev = 0;
pH->first = pNew;
}
pEntry->count++;
pEntry->chain = pNew;
}
/* Resize the hash table so that it cantains "new_size" buckets.
** "new_size" must be a power of 2. The hash table might fail
** to resize if malloc fails.
*/
static void rehash(Hash *pH, int new_size){
struct _ht *new_ht; /* The new hash table */
HashElem *elem, *next_elem; /* For looping over existing elements */
assert( (new_size & (new_size-1))==0 );
new_ht = (struct _ht *)pH->xMalloc( new_size*sizeof(struct _ht) );
if( new_ht==0 ) return;
if( pH->ht ) pH->xFree(pH->ht);
pH->ht = new_ht;
pH->htsize = new_size;
for(elem=pH->first, pH->first=0; elem; elem = next_elem){
int h = binHash(elem->pKey, elem->nKey) & (new_size-1);
next_elem = elem->next;
insertElement(pH, &new_ht[h], elem);
}
}
/* This function (for internal use only) locates an element in an
** hash table that matches the given key. The hash for this key has
** already been computed and is passed as the 4th parameter.
*/
static HashElem *findElementGivenHash(
const Hash *pH, /* The pH to be searched */
const void *pKey, /* The key we are searching for */
int nKey,
int h /* The hash for this key. */
){
HashElem *elem; /* Used to loop thru the element list */
int count; /* Number of elements left to test */
if( pH->ht ){
struct _ht *pEntry = &pH->ht[h];
elem = pEntry->chain;
count = pEntry->count;
while( count-- && elem ){
if( binCompare(elem->pKey,elem->nKey,pKey,nKey)==0 ){
return elem;
}
elem = elem->next;
}
}
return 0;
}
/* Remove a single entry from the hash table given a pointer to that
** element and a hash on the element's key.
*/
static void removeElementGivenHash(
Hash *pH, /* The pH containing "elem" */
HashElem* elem, /* The element to be removed from the pH */
int h /* Hash value for the element */
){
struct _ht *pEntry;
if( elem->prev ){
elem->prev->next = elem->next;
}else{
pH->first = elem->next;
}
if( elem->next ){
elem->next->prev = elem->prev;
}
pEntry = &pH->ht[h];
if( pEntry->chain==elem ){
pEntry->chain = elem->next;
}
pEntry->count--;
if( pEntry->count<=0 ){
pEntry->chain = 0;
}
if( pH->copyKey && elem->pKey ){
pH->xFree(elem->pKey);
}
pH->xFree( elem );
pH->count--;
if( pH->count<=0 ){
assert( pH->first==0 );
assert( pH->count==0 );
HashClear(pH);
}
}
/* Attempt to locate an element of the hash table pH with a key
** that matches pKey,nKey. Return the data for this element if it is
** found, or NULL if there is no match.
*/
void * HashFind(const Hash *pH, const void *pKey, int nKey){
int h; /* A hash on key */
HashElem *elem; /* The element that matches key */
if( pH==0 || pH->ht==0 ) return 0;
h = binHash(pKey,nKey);
assert( (pH->htsize & (pH->htsize-1))==0 );
elem = findElementGivenHash(pH,pKey,nKey, h & (pH->htsize-1));
return elem ? elem->data : 0;
}
/* Insert an element into the hash table pH. The key is pKey,nKey
** and the data is "data".
**
** If no element exists with a matching key, then a new
** element is created. A copy of the key is made if the copyKey
** flag is set. NULL is returned.
**
** If another element already exists with the same key, then the
** new data replaces the old data and the old data is returned.
** The key is not copied in this instance. If a malloc fails, then
** the new data is returned and the hash table is unchanged.
**
** If the "data" parameter to this function is NULL, then the
** element corresponding to "key" is removed from the hash table.
*/
void * HashInsert(
Hash *pH, /* The hash table to insert into */
const void *pKey, /* The key */
int nKey, /* Number of bytes in the key */
void *data /* The data */
){
int hraw; /* Raw hash value of the key */
int h; /* the hash of the key modulo hash table size */
HashElem *elem; /* Used to loop thru the element list */
HashElem *new_elem; /* New element added to the pH */
assert( pH!=0 );
hraw = binHash(pKey, nKey);
assert( (pH->htsize & (pH->htsize-1))==0 );
h = hraw & (pH->htsize-1);
elem = findElementGivenHash(pH,pKey,nKey,h);
if( elem ){
void *old_data = elem->data;
if( data==0 ){
removeElementGivenHash(pH,elem,h);
}else{
elem->data = data;
}
return old_data;
}
if( data==0 ) return 0;
new_elem = (HashElem*)pH->xMalloc( sizeof(HashElem) );
if( new_elem==0 ) return data;
if( pH->copyKey && pKey!=0 ){
new_elem->pKey = pH->xMalloc( nKey );
if( new_elem->pKey==0 ){
pH->xFree(new_elem);
return data;
}
memcpy((void*)new_elem->pKey, pKey, nKey);
}else{
new_elem->pKey = (void*)pKey;
}
new_elem->nKey = nKey;
pH->count++;
if( pH->htsize==0 ){
rehash(pH,8);
if( pH->htsize==0 ){
pH->count = 0;
pH->xFree(new_elem);
return data;
}
}
if( pH->count > pH->htsize ){
rehash(pH,pH->htsize*2);
}
assert( pH->htsize>0 );
assert( (pH->htsize & (pH->htsize-1))==0 );
h = hraw & (pH->htsize-1);
insertElement(pH, &pH->ht[h], new_elem);
new_elem->data = data;
return 0;
}
@@ -0,0 +1,107 @@
#ifndef _HASH_H_
#define _HASH_H_
/* Forward declarations of structures. */
typedef struct Hash Hash;
typedef struct HashElem HashElem;
/* A complete hash table is an instance of the following structure.
** The internals of this structure are intended to be opaque -- client
** code should not attempt to access or modify the fields of this structure
** directly. Change this structure only by using the routines below.
** However, many of the "procedures" and "functions" for modifying and
** accessing this structure are really macros, so we can't really make
** this structure opaque.
*/
struct Hash {
char copyKey; /* True if copy of key made on insert */
int count; /* Number of entries in this table */
HashElem *first; /* The first element of the array */
void *(*xMalloc)(size_t); /* malloc() function to use */
void (*xFree)(void *); /* free() function to use */
int htsize; /* Number of buckets in the hash table */
struct _ht { /* the hash table */
int count; /* Number of entries with this hash */
HashElem *chain; /* Pointer to first entry with this hash */
} *ht;
};
/* Each element in the hash table is an instance of the following
** structure. All elements are stored on a single doubly-linked list.
**
** Again, this structure is intended to be opaque, but it can't really
** be opaque because it is used by macros.
*/
struct HashElem {
HashElem *next, *prev; /* Next and previous elements in the table */
void *data; /* Data associated with this element */
void *pKey; int nKey; /* Key associated with this element */
};
/*
** Access routines. To delete, insert a NULL pointer.
*/
Hash * HashCreate(char copyKey);
Hash * HashCreateAlloc(char copyKey, void *(*xMalloc)(size_t), void (*xFree)(void *));
void HashFree(Hash*);
void HashInit(Hash*, char copyKey, void *(*xMalloc)(size_t), void (*xFree)(void *));
void * HashInsert(Hash*, const void *pKey, int nKey, void *pData);
void * HashFind(const Hash*, const void *pKey, int nKey);
void HashClear(Hash*);
void * HashInsertSz(Hash*, const char *pKey, void *pData);
void * HashFindSz(const Hash*, const char *pKey);
/*
Element deletion macro
*/
#define HashDelete(H, K, N) (HashInsert(H, K, N, 0))
/*
** Macros for looping over all elements of a hash table. The idiom is
** like this:
**
** Hash h;
** HashElem *p;
** ...
** for(p=HashFirst(&h); p; p=HashNext(p)){
** SomeStructure *pData = HashData(p);
** // do something with pData
** }
*/
#define HashFirst(H) ((H)->first)
#define HashNext(E) ((E)->next)
#define HashData(E) ((E)->data)
#define HashKey(E) ((E)->pKey)
#define HashKeysize(E) ((E)->nKey)
/*
** Number of entries in a hash table
*/
#define HashCount(H) ((H)->count)
/*
more macros
*/
typedef struct Hash* hash_table;
typedef struct HashElem* hash_elem;
#define hash_create() (HashCreate(1))
#define hash_insert(H, K, V) (HashInsertSz(H, K, V))
#define hash_find(H, K) (HashFindSz(H, K))
#define hash_delete(H, K) (HashInsertSz(H, K, 0))
#define hash_clear(H) (HashClear(H))
#define hash_free(H) (HashFree(H))
#define hash_first(H) ((H)->first)
#define hash_next(E) ((E)->next)
#define hash_data(E) ((E)->data)
#define hash_key(E) ((E)->pKey)
#define hash_keysize(E) ((E)->nKey)
#define hash_count(H) ((H)->count)
#endif /* _HASH_H_ */
@@ -0,0 +1,44 @@
#include <stdio.h>
#include <string.h>
#include "io.h"
/* callback function to mimic fread using a memory buffer */
size_t buffer_read(void * out_buffer, size_t size, void * user_data) {
buffer_context * ctxt = (buffer_context *)user_data;
if (ctxt->current_address >= ctxt->start_address &&
ctxt->current_address + size <= ctxt->start_address + ctxt->buffer_size) {
memcpy(out_buffer, ctxt->current_address, size);
ctxt->current_address += size;
return size;
}
else {
return 0;
}
}
/* callback function to mimic fwrite using a memory buffer */
size_t buffer_write(const void * in_buffer, size_t size, void * user_data) {
buffer_context * ctxt = (buffer_context *)user_data;
if (ctxt->current_address >= ctxt->start_address &&
ctxt->current_address + size <= ctxt->start_address + ctxt->buffer_size) {
memcpy(ctxt->current_address, in_buffer, size);
ctxt->current_address += size;
return size;
}
else {
return 0;
}
}
/* callback function to read data from a file stream */
size_t file_read(void * out_buffer, size_t size, void * user_data) {
return fread(out_buffer, sizeof(uint8_t), size, (FILE *)user_data);
}
/* callback function to write data to a file stream */
size_t file_write(const void * in_buffer, size_t size, void * user_data) {
return fwrite(in_buffer, sizeof(uint8_t), size, (FILE *)user_data);
}
@@ -0,0 +1,33 @@
#ifndef __IO_H__
#define __IO_H__
#include "amf.h"
/* structure used to mimic a stream with a memory buffer */
typedef struct __buffer_context {
uint8_t * start_address;
uint8_t * current_address;
size_t buffer_size;
} buffer_context;
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/* callback function to mimic fread using a memory buffer */
size_t buffer_read(void * out_buffer, size_t size, void * user_data);
/* callback function to mimic fwrite using a memory buffer */
size_t buffer_write(const void * in_buffer, size_t size, void * user_data);
/* callback function to read data from a file stream */
size_t file_read(void * out_buffer, size_t size, void * user_data);
/* callback function to write data to a file stream */
size_t file_write(const void * in_buffer, size_t size, void * user_data);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* __IO_H__ */
@@ -0,0 +1,172 @@
#include "ptrarray.h"
#include <string.h>
/**
Customize default capacity
*/
#ifndef PTRARRAY_DEFAULT_CAPACITY
# define PTRARRAY_DEFAULT_CAPACITY 5
#endif
/**
Enable array security checking
*/
/* #define PTRARRAY_SECURITY_CHECKS */
/**
Customize memory allocation routines
*/
#ifndef PTRARRAY_MALLOC
# define PTRARRAY_MALLOC malloc
#endif
#ifndef PTRARRAY_FREE
# define PTRARRAY_FREE free
#endif
#ifndef PTRARRAY_REALLOC
# define PTRARRAY_REALLOC realloc
#endif
/**
This function doubles the current capacity
of the given dynamic array.
*/
static int ptrarray_grow(ptrarray * array) {
void * new_mem;
size_t new_capacity;
#ifdef PTRARRAY_SECURITY_CHECKS
if (array == NULL)
return;
#endif
new_capacity = array->capacity * 2;
new_mem = PTRARRAY_REALLOC(array->data, new_capacity * sizeof(void*));
if (new_mem != NULL) {
array->data = new_mem;
array->capacity = new_capacity;
return 1;
}
else {
return 0;
}
}
void ptrarray_init(ptrarray * array, size_t initial_capacity, data_free_proc free_proc) {
if (free_proc == NULL) {
free_proc = PTRARRAY_FREE;
}
array->data_free = free_proc;
if (initial_capacity <= 0) {
initial_capacity = PTRARRAY_DEFAULT_CAPACITY;
}
array->capacity = initial_capacity;
array->data = PTRARRAY_MALLOC(initial_capacity * sizeof(void*));
array->size = 0;
}
/*size_t ptrarray_capacity(ptrarray * array) {
return array->capacity;
}*/
/*size_t ptrarray_size(ptrarray * array) {
return array->size;
}*/
/*int ptrarray_empty(ptrarray * array) {
return !((array)->size);
}*/
void ptrarray_reserve(ptrarray * array, size_t new_capacity) {
void * new_mem;
#ifdef PTRARRAY_SECURITY_CHECKS
if (array == NULL)
return;
#endif
if (new_capacity > array->capacity) {
new_mem = PTRARRAY_REALLOC(array->data, new_capacity * sizeof(void*));
if (new_mem != NULL) {
array->data = new_mem;
array->capacity = new_capacity;
}
}
else if (new_capacity < array->capacity) {
new_capacity = (new_capacity < array->size) ? array->size : new_capacity;
new_capacity = (new_capacity < PTRARRAY_DEFAULT_CAPACITY) ? PTRARRAY_DEFAULT_CAPACITY : new_capacity;
new_mem = PTRARRAY_REALLOC(array->data, new_capacity * sizeof(void*));
if (new_mem != NULL) {
array->data = new_mem;
array->capacity = new_capacity;
}
}
}
void ptrarray_compact(ptrarray * array) {
size_t new_capacity;
void * new_mem;
#ifdef PTRARRAY_SECURITY_CHECKS
if (array == NULL)
return;
#endif
new_capacity = (array->size < PTRARRAY_DEFAULT_CAPACITY) ? PTRARRAY_DEFAULT_CAPACITY : array->size;
new_mem = PTRARRAY_REALLOC(array->data, new_capacity * sizeof(void*));
if (new_mem != NULL) {
array->data = new_mem;
array->capacity = new_capacity;
}
}
void ptrarray_push(ptrarray * array, void * data) {
#ifdef PTRARRAY_SECURITY_CHECKS
if (array == NULL)
return;
#endif
if (array->size == array->capacity) {
if (!ptrarray_grow(array)) {
return;
}
}
array->data[array->size++] = data;
}
void * ptrarray_pop(ptrarray * array) {
#ifdef PTRARRAY_SECURITY_CHECKS
if (array == NULL)
return NULL;
#endif
if (ptrarray_empty(array)) {
return NULL;
}
return array->data[array->size--];
}
void ptrarray_insert(ptrarray * array, size_t position, void * data) {
void ** src_pos;
#ifdef PTRARRAY_SECURITY_CHECKS
if (array == NULL)
return;
#endif
if (array->size > position) {
if (array->size == array->capacity) {
if (!ptrarray_grow(array)) {
return;
}
}
src_pos = array->data + position;
memmove(src_pos + 1, src_pos, array->size - position);
*src_pos = data;
}
}
void ptrarray_prepend(ptrarray * array, void * data);
void * ptrarray_replace(ptrarray * array, size_t position, void * data);
void * ptrarray_remove(ptrarray * array, size_t position);
void ptrarray_clear(ptrarray * array);
void * ptrarray_first(ptrarray * array);
void * ptrarray_last(ptrarray * array);
void * ptrarray_get(size_t position);
void ptrarray_destroy(ptrarray * array) {
}
@@ -0,0 +1,52 @@
#ifndef __PTRARRAY_H__
#define __PTRARRAY_H__
#include <stdlib.h>
typedef void (*data_free_proc)(void *);
typedef struct __ptrarray {
size_t capacity;
size_t size;
void ** data;
data_free_proc data_free;
} ptrarray;
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
void ptrarray_init(ptrarray * array, size_t initial_capacity, data_free_proc free_proc);
/*size_t ptrarray_capacity(ptrarray * array);*/
#define ptrarray_capacity(a) ((a)->capacity)
/*size_t ptrarray_size(ptrarray * array);*/
#define ptrarray_size(a) ((a)->size)
/*int ptrarray_empty(ptrarray * array);*/
#define ptrarray_empty(a) (!((a)->size))
void ptrarray_reserve(ptrarray * array, size_t new_capacity);
void ptrarray_compact(ptrarray * array);
void ptrarray_push(ptrarray * array, void * data);
void * ptrarray_pop(ptrarray * array);
void ptrarray_insert(ptrarray * array, size_t position, void * data);
void ptrarray_prepend(ptrarray * array, void * data);
void * ptrarray_replace(ptrarray * array, size_t position, void * data);
void * ptrarray_remove(ptrarray * array, size_t position);
void ptrarray_clear(ptrarray * array);
void * ptrarray_first(ptrarray * array);
void * ptrarray_last(ptrarray * array);
void * ptrarray_get(size_t position);
void ptrarray_destroy(ptrarray * array);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* __PTRARRAY_H__ */
@@ -0,0 +1,48 @@
/*
$Id: types.c 1 2009-11-13 00:04:24Z noirotm $
FLV Metadata updater
Copyright (C) 2007, 2008 Marc Noirot <marc.noirot AT gmail.com>
This file is part of FLVMeta.
FLVMeta is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLVMeta is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLVMeta; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "types.h"
#ifndef WORDS_BIGENDIAN
/* swap 64 bits doubles */
typedef union __convert_u {
uint64_t i;
number64_t f;
} convert_u;
number64_t swap_number64(number64_t n) {
convert_u c;
c.f = n;
c.i = (((c.i & 0x00000000000000FFULL) << 56) |
((c.i & 0x000000000000FF00ULL) << 40) |
((c.i & 0x0000000000FF0000ULL) << 24) |
((c.i & 0x00000000FF000000ULL) << 8) |
((c.i & 0x000000FF00000000ULL) >> 8) |
((c.i & 0x0000FF0000000000ULL) >> 24) |
((c.i & 0x00FF000000000000ULL) >> 40) |
((c.i & 0xFF00000000000000ULL) >> 56));
return c.f;
}
#endif /* !WORDS_BIGENDIAN */
@@ -0,0 +1,60 @@
/*
$Id: types.h 1 2009-11-13 00:04:24Z noirotm $
FLV Metadata updater
Copyright (C) 2007, 2008 Marc Noirot <marc.noirot AT gmail.com>
This file is part of FLVMeta.
FLVMeta is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLVMeta is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLVMeta; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __TYPES_H__
#define __TYPES_H__
#include "amf.h"
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
#ifdef WORDS_BIGENDIAN
# define swap_uint16(x) (x)
# define swap_int16(x) (x)
# define swap_uint32(x) (x)
# define swap_number64(x) (x)
#else /* WORDS_BIGENDIAN */
/* swap 16 bits integers */
# define swap_uint16(x) ((((x) & 0x00FFU) << 8) | (((x) & 0xFF00U) >> 8))
# define swap_sint16(x) ((((x) & 0x00FF) << 8) | (((x) & 0xFF00) >> 8))
/* swap 32 bits integers */
# define swap_uint32(x) ((((x) & 0x000000FFU) << 24) | \
(((x) & 0x0000FF00U) << 8) | \
(((x) & 0x00FF0000U) >> 8) | \
(((x) & 0xFF000000U) >> 24))
/* swap 64 bits doubles */
number64_t swap_number64(number64_t);
#endif /* WORDS_BIGENDIAN */
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* __TYPES_H__ */
@@ -0,0 +1,5 @@
include_directories(${CMAKE_SOURCE_DIR}/src)
add_executable(amf0_demo amf0_demo.c)
add_dependencies(amf0_demo amf)
Binary file not shown.
@@ -0,0 +1,17 @@
#include <stdio.h>
#include "amf0.h"
#include "io.h"
#include "types.h"
int main() {
amf0_data * test;
test = amf0_object_new();
amf0_object_add(test, "toto", amf0_str("une chaine de caracteres"));
amf0_object_add(test, "test_bool", amf0_boolean_new(1));
amf0_data_dump(stdout, test, 0);
amf0_data_free(test);
}
File diff suppressed because it is too large. Load diff
+638
View File
@@ -0,0 +1,638 @@
/*
* mod_rtmp for FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
* Copyright (C) 2011, Barracuda Networks Inc.
*
* 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 mod_rtmp for FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
*
* The Initial Developer of the Original Code is Barracuda Networks Inc.
* Portions created by the Initial Developer are Copyright (C)
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Mathieu Rene <mrene@avgs.ca>
*
* mod_rtmp.h -- RTMP Endpoint Module
*
*/
#ifndef MOD_RTMP_H
#define MOD_RTMP_H
#include <switch.h>
/* AMF */
#include "amf0.h"
#include "io.h"
#include "types.h"
//#define RTMP_DEBUG_IO
#define RTMP_DONT_HOLD
#define RTMP_THREE_WAY_UUID_VARIABLE "rtmp_three_way_uuid"
#define RTMP_ATTACH_ON_HANGUP_VARIABLE "rtmp_attach_on_hangup"
#define RTMP_USER_VARIABLE_PREFIX "rtmp_u_"
#define RTMP_DEFAULT_PORT 1935
#define RTMP_TCP_READ_BUF 2048
#define AMF_MAX_SIZE 2048
#define SUPPORT_SND_NONE 0x0000
#define SUPPORT_SND_ADPCM 0x0002
#define SUPPORT_SND_MP3 0x0004
#define SUPPORT_SND_INTEL 0x0008
#define SUPPORT_SND_UNUSED 0x0010
#define SUPPORT_SND_NELLY8 0x0020
#define SUPPORT_SND_NELLY 0x0040
#define SUPPORT_SND_G711A 0x0080
#define SUPPORT_SND_G711U 0x0100
#define SUPPORT_SND_NELLY16 0x0200
#define SUPPORT_SND_AAC 0x0400
#define SUPPORT_SND_SPEEX 0x0800
#define SUPPORT_SND_ALL 0x0FFF
#define SUPPORT_VID_UNUSED 0x0001
#define SUPPORT_VID_JPEG 0x0002
#define SUPPORT_VID_SORENSON 0x0004
#define SUPPORT_VID_HOMEBREW 0x0008
#define SUPPORT_VID_VP6 0x0010
#define SUPPORT_VID_VP6ALPHA 0x0020
#define SUPPORT_VID_HOMEBREWV 0x0040
#define SUPPORT_VID_H264 0x0080
#define SUPPORT_VID_ALL 0x00FF
#define SUPPORT_VID_CLIENT_SEEK 1
#define kAMF0 0
#define kAMF3 3
#define RTMP_DEFAULT_ACK_WINDOW 0x20000
#define RTMP_TYPE_CHUNKSIZE 0x01
#define RTMP_TYPE_ABORT 0x2
#define RTMP_TYPE_ACK 0x3
#define RTMP_TYPE_USERCTRL 0x04
#define RTMP_TYPE_WINDOW_ACK_SIZE 0x5
#define RTMP_TYPE_SET_PEER_BW 0x6
#define RTMP_TYPE_AUDIO 0x08
#define RTMP_TYPE_VIDEO 0x09
#define RTMP_TYPE_METADATA 0x12
#define RTMP_TYPE_INVOKE 0x14
#define RTMP_TYPE_NOTIFY 0x12
#define RTMP_CTRL_STREAM_BEGIN 0x00
#define RTMP_CTRL_STREAM_EOF 0x01
#define RTMP_CTRL_STREAM_DRY 0x02
#define RTMP_CTRL_SET_BUFFER_LENGTH 0x03
#define RTMP_CTRL_STREAM_IS_RECORDED 0x04
#define RTMP_CTRL_PING_REQUEST 0x06
#define RTMP_CTRL_PING_RESPONSE 0x07
#define RTMP_DEFAULT_STREAM_CONTROL 0x02
#define RTMP_DEFAULT_STREAM_INVOKE 0x03
#define RTMP_DEFAULT_STREAM_NOTIFY 0x05
#define RTMP_DEFAULT_STREAM_VIDEO 0x07
#define RTMP_DEFAULT_STREAM_AUDIO 0x06
#define RTMP_MSGSTREAM_DEFAULT 0x0
/* It seems everything media-related (play/onStatus and the actual audio data are using this stream) */
#define RTMP_MSGSTREAM_MEDIA 0x01
#define RTMP_EVENT_CONNECT "rtmp::connect"
#define RTMP_EVENT_DISCONNECT "rtmp::disconnect"
#define RTMP_EVENT_REGISTER "rtmp::register"
#define RTMP_EVENT_UNREGISTER "rtmp::unregister"
#define RTMP_EVENT_LOGIN "rtmp::login"
#define RTMP_EVENT_LOGOUT "rtmp::logout"
#define RTMP_EVENT_ATTACH "rtmp::attach"
#define RTMP_EVENT_DETACH "rtmp::detach"
#define RTMP_EVENT_CUSTOM "rtmp::custom"
#define RTMP_EVENT_CLIENTCUSTOM "rtmp::clientcustom"
#define INT32_LE(x) (x) & 0xFF, ((x) >> 8) & 0xFF, ((x) >> 16) & 0xFF, ((x) >> 24) & 0xFF
#define INT32(x) ((x) >> 24) & 0xFF, ((x) >> 16) & 0xFF, ((x) >> 8) & 0xFF, (x) & 0xFF
#define INT24(x) ((x) >> 16) & 0xFF, ((x) >> 8) & 0xFF, (x) & 0xFF
#define INT16(x) ((x) >> 8) & 0xFF, (x) & 0xFF
typedef enum {
RTMP_AUDIO_PCM = 0,
RTMP_AUDIO_ADPCM = 1,
RTMP_AUDIO_MP3 = 2,
RTMP_AUDIO_NELLYMOSER_8K_MONO= 5,
RTMP_AUDIO_NELLYMOSER = 6,
RTMP_AUDIO_SPEEX = 11
} rtmp_audio_format_t;
/*
From: http://osflash.org/flv
0x08: AUDIO
The first byte of an audio packet contains bitflags that describe the codec used, with the following layout:
Name Expression Description
soundType (byte & 0×01) » 0 0: mono, 1: stereo
soundSize (byte & 0×02) » 1 0: 8-bit, 1: 16-bit
soundRate (byte & 0x0C) » 2 0: 5.5 kHz, 1: 11 kHz, 2: 22 kHz, 3: 44 kHz
soundFormat (byte & 0xf0) » 4 0: Uncompressed, 1: ADPCM, 2: MP3, 5: Nellymoser 8kHz mono, 6: Nellymoser, 11: Speex
0x09: VIDEO
The first byte of a video packet describes contains bitflags that describe the codec used, and the type of frame
Name Expression Description
codecID (byte & 0x0f) » 0 2: Sorensen H.263, 3: Screen video, 4: On2 VP6, 5: On2 VP6 Alpha, 6: ScreenVideo 2
frameType (byte & 0xf0) » 4 1: keyframe, 2: inter frame, 3: disposable inter frame
0x12: META
The contents of a meta packet are two AMF packets.
The first is almost always a short uint16_be length-prefixed UTF-8 string (AMF type 0×02),
and the second is typically a mixed array (AMF type 0×08). However, the second chunk typically contains a variety of types,
so a full AMF parser should be used.
*/
static inline int rtmp_audio_codec_get_channels(uint8_t codec) {
return (codec & 0x01) ? 2 : 1;
}
static inline int rtmp_audio_codec_get_sample_size(uint8_t codec) {
return (codec & 0x02) ? 16 : 8;
}
static inline int rtmp_audio_codec_get_rate(uint8_t codec) {
switch(codec & 0x0C) {
case 0:
return 5500;
case 1:
return 11000;
case 2:
return 22000;
case 3:
return 44000;
default:
return 0;
}
}
static inline rtmp_audio_format_t rtmp_audio_codec_get_format(uint8_t codec) {
return (rtmp_audio_format_t)(codec & 0xf0);
}
static inline uint8_t rtmp_audio_codec(int channels, int bits, int rate, rtmp_audio_format_t format) {
uint8_t codec = 0;
switch (channels) {
case 1:
break;
case 2:
codec |= 1;
default:
return 0;
}
switch (bits) {
case 8:
break;
case 16:
codec |= 2;
default:
return 0;
}
switch (rate) {
case 0:
case 5500:
break;
case 11000:
codec |= 0x4;
break;
case 22000:
codec |= 0x8;
break;
case 44000:
codec |= 0xC;
default:
return 0;
}
switch(format) {
case RTMP_AUDIO_PCM:
break;
case RTMP_AUDIO_ADPCM:
codec |= 0x10;
break;
case RTMP_AUDIO_MP3:
codec |= 0x20;
break;
case RTMP_AUDIO_NELLYMOSER_8K_MONO:
codec |= 0x50;
break;
case RTMP_AUDIO_NELLYMOSER:
codec |= 0x60;
break;
case RTMP_AUDIO_SPEEX:
codec |= 0x80;
break;
default:
return 0;
}
return codec;
}
struct rtmp_session;
typedef struct rtmp_session rtmp_session_t;
struct rtmp_profile;
typedef struct rtmp_profile rtmp_profile_t;
typedef struct rtmp_state rtmp_state_t;
#define RTMP_INVOKE_FUNCTION_ARGS rtmp_session_t *rsession, rtmp_state_t *state, int amfnumber, int transaction_id, int argc, amf0_data *argv[]
typedef switch_status_t (*rtmp_invoke_function_t)(RTMP_INVOKE_FUNCTION_ARGS);
#define RTMP_INVOKE_FUNCTION(_x) switch_status_t _x (RTMP_INVOKE_FUNCTION_ARGS)
/* AMF Helpers */
#define amf0_is_string(_x) (_x && (_x)->type == AMF0_TYPE_STRING)
#define amf0_is_number(_x) (_x && (_x)->type == AMF0_TYPE_NUMBER)
#define amf0_is_boolean(_x) (_x && (_x)->type == AMF0_TYPE_BOOLEAN)
#define amf0_is_object(_x) (_x && (_x)->type == AMF0_TYPE_OBJECT)
static inline char *amf0_get_string(amf0_data *x)
{
return (amf0_is_string(x) ? (char*)amf0_string_get_uint8_ts(x) : NULL);
}
static inline int amf0_get_number(amf0_data *x)
{
return (amf0_is_number(x) ? amf0_number_get_value(x) : 0);
}
static inline switch_bool_t amf0_get_boolean(amf0_data *x)
{
return (amf0_is_boolean(x) ? amf0_boolean_get_value(x) : SWITCH_FALSE);
}
struct rtmp_io {
switch_status_t (*read)(rtmp_session_t *rsession, unsigned char *buf, switch_size_t *len);
switch_status_t (*write)(rtmp_session_t *rsession, const unsigned char *buf, switch_size_t *len);
switch_status_t (*close)(rtmp_session_t *rsession);
rtmp_profile_t *profile;
switch_memory_pool_t *pool;
int running;
const char *name;
const char *address;
};
typedef struct rtmp_io rtmp_io_t;
typedef enum {
TFLAG_IO = (1 << 0),
TFLAG_DETACHED = (1 << 1), /* Call isn't the current active call */
TFLAG_BREAK = (1 << 2),
TFLAG_THREE_WAY = (1 << 3), /* In a three-way call */
TFLAG_VID_WAIT_KEYFRAME = (1 << 4) /* Wait for video keyframe */
} TFLAGS;
/* Session flags */
typedef enum {
SFLAG_AUDIO = (1 << 0), /* < Send audio */
SFLAG_VIDEO = (1 << 1) /* < Send video */
} SFLAGS;
typedef enum {
PFLAG_RUNNING = (1 << 0)
} PFLAGS;
struct mod_rtmp_globals {
switch_endpoint_interface_t *rtmp_endpoint_interface;
switch_memory_pool_t *pool;
switch_mutex_t *mutex;
switch_hash_t *profile_hash;
switch_thread_rwlock_t *profile_rwlock;
switch_hash_t *session_hash;
switch_thread_rwlock_t *session_rwlock;
switch_hash_t *invoke_hash;
};
extern struct mod_rtmp_globals rtmp_globals;
struct rtmp_profile {
char *name; /* < Profile name */
switch_memory_pool_t *pool; /* < Memory pool */
rtmp_io_t *io; /* < IO Module instance */
switch_thread_rwlock_t *rwlock; /* < Rwlock for reference counting */
uint32_t flags; /* < PFLAGS */
switch_mutex_t *mutex; /* < Mutex for call count */
int calls; /* < Active calls count */
int clients; /* < Number of connected clients */
switch_hash_t *session_hash; /* < Active rtmp sessions */
switch_thread_rwlock_t *session_rwlock; /* < rwlock for session hashtable */
const char *context; /* < Default dialplan name */
const char *dialplan; /* < Default dialplan context */
const char *bind_address; /* < Bind address */
const char *io_name; /* < Name of I/O module (from config) */
int chunksize; /* < Override default chunksize (from config) */
int buffer_len; /* < Receive buffer length the flash clients should use */
switch_hash_t *reg_hash; /* < Registration hashtable */
switch_thread_rwlock_t *reg_rwlock; /* < Registration hash rwlock */
switch_bool_t auth_calls; /* < Require authentiation */
};
typedef struct {
unsigned ts:24;
unsigned len:24;
unsigned type:8;
unsigned src:16;
unsigned dst:16;
} rtmp_hdr_t;
#define RTMP_DEFAULT_CHUNKSIZE 128
struct rtmp_state {
union {
char sz[12];
rtmp_hdr_t packed;
} header;
int remainlen;
int origlen;
uint32_t ts; /* 24 bits max */
uint32_t ts_delta; /* 24 bits max */
uint8_t type;
uint32_t stream_id;
unsigned char buf[AMF_MAX_SIZE];
switch_size_t buf_pos;
};
typedef enum {
RS_HANDSHAKE = 0,
RS_HANDSHAKE2 = 1,
RS_ESTABLISHED = 2,
RS_DESTROY = 3
} rtmp_session_state_t;
struct rtmp_private;
typedef struct rtmp_private rtmp_private_t;
struct rtmp_account;
typedef struct rtmp_account rtmp_account_t;
struct rtmp_account {
const char *user;
const char *domain;
rtmp_account_t *next;
};
struct rtmp_session {
switch_memory_pool_t *pool;
rtmp_profile_t *profile;
char uuid[SWITCH_UUID_FORMATTED_LENGTH+1];
void *io_private;
rtmp_session_state_t state;
int parse_state;
uint16_t parse_remain; /* < Remaining bytes required before changing parse state */
int hdrsize; /* < The current header size */
int amfnumber; /* < The current AMF number */
rtmp_state_t amfstate[64];
rtmp_state_t amfstate_out[64];
switch_mutex_t *socket_mutex;
switch_mutex_t *count_mutex;
int active_sessions;
unsigned char hsbuf[2048];
int hspos;
uint16_t in_chunksize;
uint16_t out_chunksize;
/* Connect params */
const char *flashVer;
const char *swfUrl;
const char *tcUrl;
const char *app;
const char *pageUrl;
uint32_t capabilities;
uint32_t audioCodecs;
uint32_t videoCodecs;
uint32_t videoFunction;
switch_thread_rwlock_t *rwlock;
rtmp_private_t *tech_pvt; /* < Active call's tech_pvt */
#ifdef RTMP_DEBUG_IO
FILE *io_debug_in;
FILE *io_debug_out;
#endif
const char *remote_address;
switch_port_t remote_port;
switch_hash_t *session_hash; /* < Hash of call uuids and tech_pvt */
switch_thread_rwlock_t *session_rwlock; /* < RWLock protecting session_hash */
rtmp_account_t *account;
switch_thread_rwlock_t *account_rwlock;
uint_least32_t flags;
int8_t sendAudio, sendVideo;
uint64_t recv_ack_window; /* < ACK Window */
uint64_t recv_ack_sent; /* < Bytes ack'd */
uint64_t recv; /* < Bytes received */
uint32_t send_ack_window;
uint32_t send_ack;
uint32_t send;
switch_time_t send_ack_ts;
uint32_t send_bw; /* < Current send bandwidth (in bytes/sec) */
uint32_t next_streamid; /* < The next stream id that will be used */
uint32_t active_streamid; /* < The stream id returned by the last call to createStream */
uint32_t media_streamid; /* < The stream id that was used for the last "play" command,
where we should send media */
};
struct rtmp_private {
unsigned int flags;
switch_codec_t read_codec;
switch_codec_t write_codec;
switch_frame_t read_frame;
unsigned char databuf[SWITCH_RECOMMENDED_BUFFER_SIZE]; /* < Buffer for read_frame */
switch_caller_profile_t *caller_profile;
switch_mutex_t *mutex;
switch_mutex_t *flag_mutex;
switch_core_session_t *session;
switch_channel_t *channel;
rtmp_session_t *rtmp_session;
int read_channel; /* RTMP channel #s for read and write */
int write_channel;
uint8_t audio_codec;
uint8_t video_codec;
switch_time_t stream_start_ts;
switch_timer_t timer;
switch_buffer_t *readbuf;
switch_mutex_t *readbuf_mutex;
const char *display_callee_id_name;
const char *display_callee_id_number;
const char *auth_user;
const char *auth_domain;
const char *auth;
};
struct rtmp_reg;
typedef struct rtmp_reg rtmp_reg_t;
struct rtmp_reg {
const char *uuid; /* < The rtmp session id */
const char *nickname; /* < This instance's nickname, optional */
rtmp_reg_t *next; /* < Next entry */
};
typedef enum {
MSG_FULLHEADER = 1
} rtmp_message_send_flag_t;
/* Invokable functions from flash */
RTMP_INVOKE_FUNCTION(rtmp_i_connect);
RTMP_INVOKE_FUNCTION(rtmp_i_createStream);
RTMP_INVOKE_FUNCTION(rtmp_i_noop);
RTMP_INVOKE_FUNCTION(rtmp_i_play);
RTMP_INVOKE_FUNCTION(rtmp_i_publish);
RTMP_INVOKE_FUNCTION(rtmp_i_makeCall);
RTMP_INVOKE_FUNCTION(rtmp_i_sendDTMF);
RTMP_INVOKE_FUNCTION(rtmp_i_login);
RTMP_INVOKE_FUNCTION(rtmp_i_logout);
RTMP_INVOKE_FUNCTION(rtmp_i_register);
RTMP_INVOKE_FUNCTION(rtmp_i_unregister);
RTMP_INVOKE_FUNCTION(rtmp_i_answer);
RTMP_INVOKE_FUNCTION(rtmp_i_attach);
RTMP_INVOKE_FUNCTION(rtmp_i_hangup);
RTMP_INVOKE_FUNCTION(rtmp_i_transfer);
RTMP_INVOKE_FUNCTION(rtmp_i_three_way);
RTMP_INVOKE_FUNCTION(rtmp_i_join);
RTMP_INVOKE_FUNCTION(rtmp_i_sendevent);
RTMP_INVOKE_FUNCTION(rtmp_i_receiveaudio);
RTMP_INVOKE_FUNCTION(rtmp_i_receivevideo);
RTMP_INVOKE_FUNCTION(rtmp_i_log);
/*** RTMP Sessions ***/
rtmp_session_t *rtmp_session_locate(const char *uuid);
void rtmp_session_rwunlock(rtmp_session_t *rsession);
switch_status_t rtmp_session_login(rtmp_session_t *rsession, const char *user, const char *domain);
switch_status_t rtmp_session_logout(rtmp_session_t *rsession, const char *user, const char *domain);
switch_status_t rtmp_session_check_user(rtmp_session_t *rsession, const char *user, const char *domain);
switch_status_t rtmp_check_auth(rtmp_session_t *rsession, const char *user, const char *domain, const char *authmd5);
void rtmp_event_fill(rtmp_session_t *rsession, switch_event_t *event);
switch_status_t amf_object_to_event(amf0_data *obj, switch_event_t **event);
switch_status_t amf_event_to_object(amf0_data **obj, switch_event_t *event);
/*** Endpoint interface ***/
switch_call_cause_t rtmp_session_create_call(rtmp_session_t *rsession, switch_core_session_t **newsession, int read_channel, int write_channel, const char *number, const char *auth_user, const char *auth_domain, switch_event_t *event);
switch_status_t rtmp_on_execute(switch_core_session_t *session);
switch_status_t rtmp_send_dtmf(switch_core_session_t *session, const switch_dtmf_t *dtmf);
switch_status_t rtmp_receive_message(switch_core_session_t *session, switch_core_session_message_t *msg);
switch_status_t rtmp_receive_event(switch_core_session_t *session, switch_event_t *event);
switch_status_t rtmp_on_init(switch_core_session_t *session);
switch_status_t rtmp_on_hangup(switch_core_session_t *session);
switch_status_t rtmp_on_destroy(switch_core_session_t *session);
switch_status_t rtmp_on_routing(switch_core_session_t *session);
switch_status_t rtmp_on_exchange_media(switch_core_session_t *session);
switch_status_t rtmp_on_soft_execute(switch_core_session_t *session);
switch_call_cause_t rtmp_outgoing_channel(switch_core_session_t *session, switch_event_t *var_event,
switch_caller_profile_t *outbound_profile,
switch_core_session_t **new_session, switch_memory_pool_t **pool, switch_originate_flag_t flags,
switch_call_cause_t *cancel_cause);
switch_status_t rtmp_read_frame(switch_core_session_t *session, switch_frame_t **frame, switch_io_flag_t flags, int stream_id);
switch_status_t rtmp_write_frame(switch_core_session_t *session, switch_frame_t *frame, switch_io_flag_t flags, int stream_id);
switch_status_t rtmp_kill_channel(switch_core_session_t *session, int sig);
switch_status_t rtmp_tech_init(rtmp_private_t *tech_pvt, rtmp_session_t *rtmp_session, switch_core_session_t *session);
rtmp_profile_t *rtmp_profile_locate(const char *name);
void rtmp_profile_release(rtmp_profile_t *profile);
/**** I/O ****/
switch_status_t rtmp_tcp_init(rtmp_profile_t *profile, const char *bindaddr, rtmp_io_t **new_io, switch_memory_pool_t *pool);
switch_status_t rtmp_session_request(rtmp_profile_t *profile, rtmp_session_t **newsession);
switch_status_t rtmp_session_destroy(rtmp_session_t **session);
/**** Protocol ****/
void rtmp_set_chunksize(rtmp_session_t *rsession, uint32_t chunksize);
switch_status_t rtmp_send_invoke(rtmp_session_t *rsession, uint8_t amfnumber, uint32_t timestamp, uint32_t stream_id, ...);
switch_status_t rtmp_send_invoke_free(rtmp_session_t *rsession, uint8_t amfnumber, uint32_t timestamp, uint32_t stream_id, ...);
switch_status_t rtmp_send_notify(rtmp_session_t *rsession, uint8_t amfnumber, uint32_t timestamp, uint32_t stream_id, ...);
switch_status_t rtmp_send_notify_free(rtmp_session_t *rsession, uint8_t amfnumber, uint32_t timestamp, uint32_t stream_id, ...);
switch_status_t rtmp_send_invoke_v(rtmp_session_t *rsession, uint8_t amfnumber, uint8_t type, uint32_t timestamp, uint32_t stream_id, va_list list, switch_bool_t freethem);
switch_status_t rtmp_send_message(rtmp_session_t *rsession, uint8_t amfnumber, uint32_t timestamp, uint8_t type, uint32_t stream_id, const unsigned char *message, switch_size_t len, uint32_t flags);
void rtmp_send_event(rtmp_session_t *rsession, switch_event_t *event);
void rtmp_notify_call_state(switch_core_session_t *session);
void rtmp_send_display_update(switch_core_session_t *session);
void rtmp_send_incoming_call(switch_core_session_t *session);
void rtmp_send_onhangup(switch_core_session_t *session);
void rtmp_add_registration(rtmp_session_t *rsession, const char *auth, const char *nickname);
void rtmp_clear_registration(rtmp_session_t *rsession, const char *auth, const char *nickname);
/* Attaches an rtmp session to one of its calls, use NULL to hold everything */
void rtmp_attach_private(rtmp_session_t *rsession, rtmp_private_t *tech_pvt);
rtmp_private_t *rtmp_locate_private(rtmp_session_t *rsession, const char *uuid);
void rtmp_ping(rtmp_session_t *rsession);
void rtmp_session_send_onattach(rtmp_session_t *rsession);
/* Protocol handler */
switch_status_t rtmp_handle_data(rtmp_session_t *rsession);
#endif /* defined(MOD_RTMP_H) */
/* For Emacs:
* Local Variables:
* mode:c
* indent-tabs-mode:t
* tab-width:4
* c-basic-offset:4
* End:
* For VIM:
* vim:set softtabstop=4 shiftwidth=4 tabstop=4:
*/
+913
View File
@@ -0,0 +1,913 @@
/*
* mod_rtmp for FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
* Copyright (C) 2011, Barracuda Networks Inc.
*
* 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 mod_rtmp for FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
*
* The Initial Developer of the Original Code is Barracuda Networks Inc.
* Portions created by the Initial Developer are Copyright (C)
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Mathieu Rene <mrene@avgs.ca>
*
* rtmp.c -- RTMP Protocol Handler
*
*/
#include "mod_rtmp.h"
typedef struct {
unsigned char *buf;
size_t pos;
size_t len;
} buffer_helper_t;
size_t my_buffer_read(void * out_buffer, size_t size, void * user_data)
{
buffer_helper_t *helper = (buffer_helper_t*)user_data;
size_t len = (helper->len - helper->pos) < size ? (helper->len - helper->pos) : size;
if (len <= 0) {
return 0;
}
memcpy(out_buffer, helper->buf + helper->pos, len);
helper->pos += len;
return len;
}
size_t my_buffer_write(const void *buffer, size_t size, void * user_data)
{
buffer_helper_t *helper = (buffer_helper_t*)user_data;
size_t len = (helper->len - helper->pos) < size ? (helper->len - helper->pos) : size;
if (len <= 0) {
return 0;
}
memcpy(helper->buf + helper->pos, buffer, len);
helper->pos += len;
return len;
}
void rtmp_handle_control(rtmp_session_t *rsession, int amfnumber)
{
rtmp_state_t *state = &rsession->amfstate[amfnumber];
char buf[200] = { 0 };
char *p = buf;
int type = state->buf[0] << 8 | state->buf[1];
int i;
for (i = 2; i < state->origlen; i++) {
p += sprintf(p, "%02x ", state->buf[i] & 0xFF);
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Control (%d): %s\n", type, buf);
switch(type) {
case RTMP_CTRL_STREAM_BEGIN:
break;
case RTMP_CTRL_PING_REQUEST:
{
unsigned char buf[] = {
INT16(RTMP_CTRL_PING_RESPONSE),
state->buf[2], state->buf[3], state->buf[4], state->buf[5]
};
rtmp_send_message(rsession, amfnumber, 0, RTMP_TYPE_USERCTRL, 0, buf, sizeof(buf), 0);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Ping request\n");
}
break;
case RTMP_CTRL_PING_RESPONSE:
{
uint32_t now = ((switch_micro_time_now()/1000) & 0xFFFFFFFF);
uint32_t sent = state->buf[2] << 24 | state->buf[3] << 16 | state->buf[4] << 8 | state->buf[5];
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Ping reply: %d ms\n", (int)(now - sent));
}
break;
default:
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "[amfnumber=%d] Unhandled control packet (type=0x%x)\n",
amfnumber, type);
}
}
void rtmp_handle_invoke(rtmp_session_t *rsession, int amfnumber)
{
rtmp_state_t *state = &rsession->amfstate[amfnumber];
//amf0_data *dump;
int i = 0;
buffer_helper_t helper = { state->buf, 0, state->origlen };
int64_t transaction_id;
const char *command;
int argc = 0;
amf0_data *argv[100] = { 0 };
rtmp_invoke_function_t function;
#if 0
printf(">>>>> BEGIN INVOKE MSG (num=0x%02x, type=0x%02x, stream_id=0x%x)\n", amfnumber, state->type, state->stream_id);
while((dump = amf0_data_read(my_buffer_read, &helper))) {
amf0_data *dump2;
printf("ELM> ");
amf0_data_dump(stdout, dump, 0);
printf("\n");
while ((dump2 = amf0_data_read(my_buffer_read, &helper))) {
printf("ELM> ");
amf0_data_dump(stdout, dump2, 0);
printf("\n");
amf0_data_free(dump2);
}
amf0_data_free(dump);
}
printf("<<<<< END AMF MSG\n");
#endif
#ifdef RTMP_DEBUG_IO
{
helper.pos = 0;
fprintf(rsession->io_debug_in, ">>>>> BEGIN INVOKE MSG (chunk_stream=0x%02x, type=0x%02x, stream_id=0x%x)\n", amfnumber, state->type, state->stream_id);
while((dump = amf0_data_read(my_buffer_read, &helper))) {
amf0_data *dump2;
fprintf(rsession->io_debug_in, "ELM> ");
amf0_data_dump(rsession->io_debug_in, dump, 0);
fprintf(rsession->io_debug_in, "\n");
while ((dump2 = amf0_data_read(my_buffer_read, &helper))) {
fprintf(rsession->io_debug_in, "ELM> ");
amf0_data_dump(rsession->io_debug_in, dump2, 0);
fprintf(rsession->io_debug_in, "\n");
amf0_data_free(dump2);
}
amf0_data_free(dump);
}
fprintf(rsession->io_debug_in, "<<<<< END AMF MSG\n");
fflush(rsession->io_debug_in);
}
#endif
helper.pos = 0;
while (argc < switch_arraylen(argv) && (argv[argc++] = amf0_data_read(my_buffer_read, &helper)));
if (!(command = amf0_get_string(argv[i++]))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Bogus INVOKE request\n");
return;
}
transaction_id = amf0_get_number(argv[i++]);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "[amfnumber=%d] Got INVOKE for %s\n", amfnumber,
command);
if ((function = (rtmp_invoke_function_t)(intptr_t)switch_core_hash_find(rtmp_globals.invoke_hash, command))) {
function(rsession, state, amfnumber, transaction_id, argc - 2, argv + 2);
} else {
switch_log_printf(SWITCH_CHANNEL_UUID_LOG(rsession->uuid), SWITCH_LOG_WARNING, "Unhandled invoke for \"%s\"\n",
command);
}
/* Free all the AMF data we've read */
for (i = 0; i < argc; i++) {
amf0_data_free(argv[i]);
}
}
switch_status_t rtmp_check_auth(rtmp_session_t *rsession, const char *user, const char *domain, const char *authmd5)
{
switch_status_t status = SWITCH_STATUS_FALSE;
char *auth;
char md5[SWITCH_MD5_DIGEST_STRING_SIZE];
switch_xml_t xml = NULL, x_param, x_params;
switch_bool_t allow_empty_password = SWITCH_FALSE;
const char *passwd = NULL;
/* Locate user */
if (switch_xml_locate_user_merged("id", user, domain, NULL, &xml, NULL) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_UUID_LOG(rsession->uuid), SWITCH_LOG_WARNING, "Authentication failed. No such user %s@%s\n", user, domain);
goto done;
}
if ((x_params = switch_xml_child(xml, "params"))) {
for (x_param = switch_xml_child(x_params, "param"); x_param; x_param = x_param->next) {
const char *var = switch_xml_attr_soft(x_param, "name");
const char *val = switch_xml_attr_soft(x_param, "value");
if (!strcasecmp(var, "password")) {
passwd = val;
}
if (!strcasecmp(var, "allow-empty-password")) {
allow_empty_password = switch_true(val);
}
}
}
if (zstr(passwd)) {
if (allow_empty_password) {
status = SWITCH_STATUS_SUCCESS;
} else {
switch_log_printf(SWITCH_CHANNEL_UUID_LOG(rsession->uuid), SWITCH_LOG_WARNING, "Authentication failed for %s@%s: empty password not allowed\n", user, switch_str_nil(domain));
}
goto done;
}
auth = switch_core_sprintf(rsession->pool, "%s:%s@%s:%s", rsession->uuid, user, domain, passwd);
switch_md5_string(md5, auth, strlen(auth));
if (!strncmp(md5, authmd5, SWITCH_MD5_DIGEST_STRING_SIZE)) {
status = SWITCH_STATUS_SUCCESS;
} else {
switch_log_printf(SWITCH_CHANNEL_UUID_LOG(rsession->uuid), SWITCH_LOG_WARNING, "Authentication failed for %s@%s\n", user, domain);
}
done:
if (xml) {
switch_xml_free(xml);
}
return status;
}
switch_status_t amf_object_to_event(amf0_data *obj, switch_event_t **event)
{
switch_status_t status = SWITCH_STATUS_SUCCESS;
if (obj && obj->type == AMF0_TYPE_OBJECT) {
amf0_node *node;
if (!*event) {
if ((status = switch_event_create(event, SWITCH_EVENT_CUSTOM)) != SWITCH_STATUS_SUCCESS) {
return status;
}
}
for (node = amf0_object_first(obj); node; node = amf0_object_next(node)) {
const char *name = amf0_get_string(amf0_object_get_name(node));
const char *value = amf0_get_string(amf0_object_get_data(node));
if (!zstr(name) && !zstr(value)) {
if (!strcmp(name, "_body")) {
switch_event_add_body(*event, "%s", value);
} else {
switch_event_add_header_string(*event, SWITCH_STACK_BOTTOM, name, value);
}
}
}
} else {
status = SWITCH_STATUS_FALSE;
}
return status;
}
switch_status_t amf_event_to_object(amf0_data **obj, switch_event_t *event)
{
switch_event_header_t *hp;
const char *body;
switch_assert(event);
switch_assert(obj);
if (!*obj) {
*obj = amf0_object_new();
}
for (hp = event->headers; hp; hp = hp->next) {
amf0_object_add(*obj, hp->name, amf0_str(hp->value));
}
body = switch_event_get_body(event);
if (!zstr(body)) {
amf0_object_add(*obj, "_body", amf0_str(body));
}
return SWITCH_STATUS_SUCCESS;
}
void rtmp_set_chunksize(rtmp_session_t *rsession, uint32_t chunksize)
{
if (rsession->out_chunksize != chunksize) {
unsigned char buf[] = {
INT32(chunksize)
};
rtmp_send_message(rsession, 2 /*amfnumber*/, 0, RTMP_TYPE_CHUNKSIZE, 0, buf, sizeof(buf), MSG_FULLHEADER);
rsession->out_chunksize = chunksize;
}
}
void rtmp_get_user_variables(switch_event_t **event, switch_core_session_t *session)
{
switch_channel_t *channel = switch_core_session_get_channel(session);
switch_event_header_t *he;
if (!*event && switch_event_create(event, SWITCH_EVENT_CLONE) != SWITCH_STATUS_SUCCESS) {
return;
}
if ((he = switch_channel_variable_first(channel))) {
for (; he; he = he->next) {
if (!strncmp(he->name, RTMP_USER_VARIABLE_PREFIX, strlen(RTMP_USER_VARIABLE_PREFIX))) {
switch_event_add_header_string(*event, SWITCH_STACK_BOTTOM, he->name, he->value);
}
}
switch_channel_variable_last(channel);
}
}
void rtmp_session_send_onattach(rtmp_session_t *rsession)
{
const char *uuid = "";
if (rsession->tech_pvt) {
uuid = switch_core_session_get_uuid(rsession->tech_pvt->session);
}
rtmp_send_invoke_free(rsession, 3, 0, 0,
amf0_str("onAttach"),
amf0_number_new(0),
amf0_null_new(),
amf0_str(uuid), NULL);
}
void rtmp_send_display_update(switch_core_session_t *session)
{
rtmp_private_t *tech_pvt = switch_core_session_get_private(session);
rtmp_send_invoke_free(tech_pvt->rtmp_session, 3, 0, 0,
amf0_str("displayUpdate"),
amf0_number_new(0),
amf0_null_new(),
amf0_str(switch_core_session_get_uuid(session)),
amf0_str(switch_str_nil(tech_pvt->display_callee_id_name)),
amf0_str(switch_str_nil(tech_pvt->display_callee_id_number)), NULL);
}
void rtmp_send_incoming_call(switch_core_session_t *session)
{
rtmp_private_t *tech_pvt = switch_core_session_get_private(session);
switch_channel_t *channel = switch_core_session_get_channel(session);
switch_caller_profile_t *caller_profile = switch_channel_get_caller_profile(channel);
switch_event_t *event = NULL;
amf0_data *obj = NULL;
rtmp_get_user_variables(&event, session);
if (event) {
amf_event_to_object(&obj, event);
switch_event_destroy(&event);
}
rtmp_send_invoke_free(tech_pvt->rtmp_session, 3, 0, 0,
amf0_str("incomingCall"),
amf0_number_new(0),
amf0_null_new(),
amf0_str(switch_core_session_get_uuid(session)),
amf0_str(switch_str_nil(caller_profile->caller_id_name)),
amf0_str(switch_str_nil(caller_profile->caller_id_number)),
!zstr(tech_pvt->auth) ? amf0_str(tech_pvt->auth) : amf0_null_new(),
obj ? obj : amf0_null_new(), NULL);
}
void rtmp_send_onhangup(switch_core_session_t *session)
{
rtmp_private_t *tech_pvt = switch_core_session_get_private(session);
switch_channel_t *channel = switch_core_session_get_channel(session);
rtmp_send_invoke_free(tech_pvt->rtmp_session, 3, 0, 0,
amf0_str("onHangup"),
amf0_number_new(0),
amf0_null_new(),
amf0_str(switch_core_session_get_uuid(session)),
amf0_str(switch_channel_cause2str(switch_channel_get_cause(channel))), NULL);
}
void rtmp_send_event(rtmp_session_t *rsession, switch_event_t *event)
{
amf0_data *obj = NULL;
switch_assert(event != NULL);
switch_assert(rsession != NULL);
if (amf_event_to_object(&obj, event) == SWITCH_STATUS_SUCCESS) {
rtmp_send_invoke_free(rsession, 3, 0, 0, amf0_str("event"), amf0_number_new(0), amf0_null_new(), obj, NULL);
}
}
void rtmp_ping(rtmp_session_t *rsession)
{
uint32_t now = (uint32_t)((switch_micro_time_now() / 1000) & 0xFFFFFFFF);
unsigned char buf[] = {
INT16(RTMP_CTRL_PING_REQUEST),
INT32(now)
};
rtmp_send_message(rsession, 2, 0, RTMP_TYPE_USERCTRL, 0, buf, sizeof(buf), 0);
}
void rtmp_notify_call_state(switch_core_session_t *session)
{
switch_channel_t *channel = switch_core_session_get_channel(session);
const char *state = switch_channel_callstate2str(switch_channel_get_callstate(channel));
rtmp_private_t *tech_pvt = switch_core_session_get_private(session);
rtmp_send_invoke_free(tech_pvt->rtmp_session, 3, 0, 0,
amf0_str("callState"),
amf0_number_new(0),
amf0_null_new(),
amf0_str(switch_core_session_get_uuid(session)),
amf0_str(state), NULL);
}
switch_status_t rtmp_send_invoke(rtmp_session_t *rsession, uint8_t amfnumber, uint32_t timestamp, uint32_t stream_id, ...)
{
switch_status_t s;
va_list list;
va_start(list, stream_id);
s = rtmp_send_invoke_v(rsession, amfnumber, RTMP_TYPE_INVOKE, timestamp, stream_id, list, SWITCH_FALSE);
va_end(list);
return s;
}
switch_status_t rtmp_send_invoke_free(rtmp_session_t *rsession, uint8_t amfnumber, uint32_t timestamp, uint32_t stream_id, ...)
{
switch_status_t s;
va_list list;
va_start(list, stream_id);
s = rtmp_send_invoke_v(rsession, amfnumber, RTMP_TYPE_INVOKE, timestamp, stream_id, list, SWITCH_TRUE);
va_end(list);
return s;
}
switch_status_t rtmp_send_notify(rtmp_session_t *rsession, uint8_t amfnumber, uint32_t timestamp, uint32_t stream_id, ...)
{
switch_status_t s;
va_list list;
va_start(list, stream_id);
s = rtmp_send_invoke_v(rsession, amfnumber, RTMP_TYPE_NOTIFY, timestamp, stream_id, list, SWITCH_FALSE);
va_end(list);
return s;
}
switch_status_t rtmp_send_notify_free(rtmp_session_t *rsession, uint8_t amfnumber, uint32_t timestamp, uint32_t stream_id, ...)
{
switch_status_t s;
va_list list;
va_start(list, stream_id);
s = rtmp_send_invoke_v(rsession, amfnumber, RTMP_TYPE_NOTIFY, timestamp, stream_id, list, SWITCH_TRUE);
va_end(list);
return s;
}
switch_status_t rtmp_send_invoke_v(rtmp_session_t *rsession, uint8_t amfnumber, uint8_t type, uint32_t timestamp, uint32_t stream_id, va_list list, switch_bool_t freethem)
{
amf0_data *data;
unsigned char buf[AMF_MAX_SIZE];
buffer_helper_t helper = { buf, 0, AMF_MAX_SIZE };
while ((data = va_arg(list, amf0_data*))) {
//amf0_data_dump(stdout, data, 0);
//printf("\n");
amf0_data_write(data, my_buffer_write, &helper);
if (freethem) {
amf0_data_free(data);
}
}
return rtmp_send_message(rsession, amfnumber, timestamp, type, stream_id, buf, helper.pos, 0);
}
/* Break message down into 128 bytes chunks, add the appropriate headers and send it out */
switch_status_t rtmp_send_message(rtmp_session_t *rsession, uint8_t amfnumber, uint32_t timestamp, uint8_t type, uint32_t stream_id, const unsigned char *message, switch_size_t len, uint32_t flags)
{
switch_size_t pos = 0;
uint8_t header[12] = { amfnumber & 0x3F, INT24(0), INT24(len), type, INT32_LE(stream_id) };
switch_size_t chunksize;
uint8_t microhdr = (3 << 6) | amfnumber;
switch_size_t hdrsize = 1;
switch_status_t status = SWITCH_STATUS_SUCCESS;
rtmp_state_t *state = &rsession->amfstate_out[amfnumber];
if ((rsession->send_ack + rsession->send_ack_window) < rsession->send &&
(type == RTMP_TYPE_VIDEO || type == RTMP_TYPE_AUDIO)) {
/* We're sending too fast, drop the frame */
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "DROP %s FRAME [amfnumber=%d type=0x%x stream_id=0x%x] len=%"SWITCH_SIZE_T_FMT" \n",
type == RTMP_TYPE_AUDIO ? "AUDIO" : "VIDEO", amfnumber, type, stream_id, len);
return SWITCH_STATUS_SUCCESS;
}
if (type != RTMP_TYPE_AUDIO && type != RTMP_TYPE_VIDEO && type != RTMP_TYPE_ACK) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "[amfnumber=%d type=0x%x stream_id=0x%x] len=%"SWITCH_SIZE_T_FMT" \n", amfnumber, type, stream_id, len);
}
#ifdef RTMP_DEBUG_IO
{
fprintf(rsession->io_debug_out, "[amfnumber=%d type=0x%x stream_id=0x%x] len=%"SWITCH_SIZE_T_FMT" \n", amfnumber, type, stream_id, len);
if (type == RTMP_TYPE_INVOKE || type == RTMP_TYPE_NOTIFY) {
buffer_helper_t helper = { (unsigned char*)message, 0, len };
amf0_data *dump;
while((dump = amf0_data_read(my_buffer_read, &helper))) {
amf0_data *dump2;
fprintf(rsession->io_debug_out, "ELM> ");
amf0_data_dump(rsession->io_debug_out, dump, 0);
fprintf(rsession->io_debug_out, "\n");
while ((dump2 = amf0_data_read(my_buffer_read, &helper))) {
fprintf(rsession->io_debug_out, "ELM> ");
amf0_data_dump(rsession->io_debug_out, dump2, 0);
fprintf(rsession->io_debug_out, "\n");
amf0_data_free(dump2);
}
amf0_data_free(dump);
}
fprintf(rsession->io_debug_out, "<<<<< END AMF MSG\n");
}
fflush(rsession->io_debug_out);
}
#endif
/* Find out what is the smallest header we can use */
if (!(flags & MSG_FULLHEADER) && stream_id > 0 && state->stream_id == stream_id && timestamp >= state->ts) {
if (state->type == type && state->origlen == len) {
if (state->ts == timestamp) {
/* Type 3: no header! */
hdrsize = 1;
header[0] |= 3 << 6;
} else {
uint32_t delta = timestamp - state->ts;
/* Type 2: timestamp delta */
hdrsize = 4;
header[0] |= 2 << 6;
header[1] = (delta >> 16) & 0xFF;
header[2] = (delta >> 8) & 0xFF;
header[3] = delta & 0xFF;
}
} else {
/* Type 1: ts delta + msg len + type */
uint32_t delta = timestamp - state->ts;
hdrsize = 8;
header[0] |= 1 << 6;
header[1] = (delta >> 16) & 0xFF;
header[2] = (delta >> 8) & 0xFF;
header[3] = delta & 0xFF;
}
} else {
hdrsize = 12; /* Type 0, full header */
header[1] = (timestamp >> 16) & 0xFF;
header[2] = (timestamp >> 8) & 0xFF;
header[3] = timestamp & 0xFF;
}
state->ts = timestamp;
state->type = type;
state->origlen = len;
state->stream_id = stream_id;
switch_mutex_lock(rsession->socket_mutex);
chunksize = (len - pos) < rsession->out_chunksize ? (len - pos) : rsession->out_chunksize;
if (rsession->profile->io->write(rsession, (unsigned char*)header, &hdrsize) != SWITCH_STATUS_SUCCESS) {
switch_goto_status(SWITCH_STATUS_FALSE, end);
}
rsession->send += hdrsize;
/* Write one chunk of data */
if (rsession->profile->io->write(rsession, (unsigned char*)message, &chunksize) != SWITCH_STATUS_SUCCESS) {
switch_goto_status(SWITCH_STATUS_FALSE, end);
}
rsession->send += chunksize;
pos += chunksize;
/* Send more chunks if we need to */
while (((signed)len - (signed)pos) > 0) {
switch_mutex_unlock(rsession->socket_mutex);
/* Let other threads send data on the socket */
switch_mutex_lock(rsession->socket_mutex);
hdrsize = 1;
if (rsession->profile->io->write(rsession, (unsigned char*)&microhdr, &hdrsize) != SWITCH_STATUS_SUCCESS) {
switch_goto_status(SWITCH_STATUS_FALSE, end);
}
rsession->send += hdrsize;
chunksize = (len - pos) < rsession->out_chunksize ? (len - pos) : rsession->out_chunksize;
if (rsession->profile->io->write(rsession, message + pos, &chunksize) != SWITCH_STATUS_SUCCESS) {
switch_goto_status(SWITCH_STATUS_FALSE, end);
}
rsession->send += chunksize;
pos += chunksize;
}
end:
switch_mutex_unlock(rsession->socket_mutex);
return SWITCH_STATUS_SUCCESS;
}
/* Returns SWITCH_STATUS_SUCCESS of the connection is still active or SWITCH_STATUS_FALSE to tear it down */
switch_status_t rtmp_handle_data(rtmp_session_t *rsession)
{
uint8_t buf[RTMP_TCP_READ_BUF];
switch_size_t s = RTMP_TCP_READ_BUF;
if (rsession->state == RS_HANDSHAKE) {
s = 1537 - rsession->hspos;
if (rsession->profile->io->read(rsession, rsession->hsbuf + rsession->hspos, &s) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Read error\n");
return SWITCH_STATUS_FALSE;
}
rsession->hspos += s;
/* Receive C0 and C1 */
if (rsession->hspos < 1537) {
/* Not quite there yet */
return SWITCH_STATUS_SUCCESS;
}
/* Send reply (S0 + S1) */
memset(buf, 0, sizeof(buf));
*buf = '\x03';
s = 1537;
rsession->profile->io->write(rsession, (unsigned char*)buf, &s);
/* Send S2 */
s = 1536;
rsession->profile->io->write(rsession, rsession->hsbuf, &s);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Sent handshake response\n");
rsession->state++;
rsession->hspos = 0;
} else if (rsession->state == RS_HANDSHAKE2) {
s = 1536 - rsession->hspos;
/* Receive C2 */
if (rsession->profile->io->read(rsession, rsession->hsbuf + rsession->hspos, &s) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Read error\n");
return SWITCH_STATUS_FALSE;
}
rsession->hspos += s;
if (rsession->hspos < 1536) {
/* Not quite there yet */
return SWITCH_STATUS_SUCCESS;
}
rsession->state++;
//s = 1536;
//rsession->profile->io->write(rsession, (char*)buf, &s);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Done with handshake\n");
return SWITCH_STATUS_SUCCESS;
} else if (rsession->state == RS_ESTABLISHED) {
/* Process RTMP packet */
switch(rsession->parse_state) {
case 0:
// Read the header's first byte
s = 1;
if (rsession->profile->io->read(rsession, (unsigned char*)buf, &s) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Read error\n");
return SWITCH_STATUS_FALSE;
}
rsession->recv += s;
switch(buf[0] >> 6) {
case 0:
rsession->hdrsize = 12;
break;
case 1:
rsession->hdrsize = 8;
break;
case 2:
rsession->hdrsize = 4;
break;
case 3:
rsession->hdrsize = 1;
break;
default:
rsession->hdrsize = 0;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "WTF hdrsize 0x%02x %d\n", *buf, *buf >> 6);
return SWITCH_STATUS_FALSE;
}
rsession->amfnumber = buf[0] & 0x3F; /* Get rid of the 2 first bits */
if (rsession->amfnumber > 64) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Protocol error\n");
return SWITCH_STATUS_FALSE;
}
//switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Header size: %d AMF Number: %d\n", rsession->hdrsize, rsession->amfnumber);
rsession->parse_state++;
if (rsession->hdrsize == 1) {
/* Skip header fetch on one-byte headers since we have it already */
rsession->parse_state++;
}
rsession->parse_remain = 0;
break;
case 1:
{
/* Read full header and decode */
rtmp_state_t *state = &rsession->amfstate[rsession->amfnumber];
uint8_t *hdr = (uint8_t*)state->header.sz;
unsigned char *readbuf = (unsigned char*)hdr;
if (!rsession->parse_remain) {
rsession->parse_remain = s = rsession->hdrsize - 1;
} else {
s = rsession->parse_remain;
readbuf += (rsession->hdrsize - 1) - s;
}
switch_assert(s < 12 && s > 0); /** XXX **/
if (rsession->profile->io->read(rsession, readbuf, &s) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Read error\n");
return SWITCH_STATUS_FALSE;
}
rsession->parse_remain -= s;
if (rsession->parse_remain > 0) {
/* More data please */
return SWITCH_STATUS_SUCCESS;
}
rsession->recv += s;
if (rsession->hdrsize == 12) {
state->ts = (hdr[0] << 16) | (hdr[1] << 8) | (hdr[2]);
state->ts_delta = 0;
} else if (rsession->hdrsize >= 4) {
/* Save the timestamp delta since we have to re-use it with type 3 headers */
state->ts_delta = (hdr[0] << 16) | (hdr[1] << 8) | (hdr[2]);
state->ts += state->ts_delta;
} else if (rsession->hdrsize == 1) {
/* Type 3: Re-use timestamp delta if we have one */
state->ts += state->ts_delta;
}
if (rsession->hdrsize >= 8) {
/* Reset length counter since its included in the header */
state->remainlen = state->origlen = (hdr[3] << 16) | (hdr[4] << 8) | (hdr[5]);
state->buf_pos = 0;
state->type = hdr[6];
}
if (rsession->hdrsize == 12) {
state->stream_id = (hdr[10] << 24) | (hdr[9] << 16) | (hdr[8] << 8) | hdr[7];
}
if (rsession->hdrsize >= 8 && state->origlen == 0) {
/* Happens we sometimes get a 0 length packet */
rsession->parse_state = 0;
return SWITCH_STATUS_SUCCESS;
}
/* FIXME: Handle extended timestamps */
if (state->ts == 0x00ffffff) {
return SWITCH_STATUS_FALSE;
}
rsession->parse_state++;
}
case 2:
{
rtmp_state_t *state = &rsession->amfstate[rsession->amfnumber];
if (rsession->parse_remain > 0) {
s = rsession->parse_remain;
} else {
s = state->remainlen < rsession->in_chunksize ? state->remainlen : rsession->in_chunksize;
rsession->parse_remain = s;
}
if (!s) {
/* Restart from beginning */
s = state->remainlen = state->origlen;
rsession->parse_remain = s;
if (!s) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Protocol error, forcing big read\n");
s = sizeof(state->buf);
rsession->profile->io->read(rsession, state->buf, &s);
return SWITCH_STATUS_FALSE;
}
}
/* Sanity check */
if ((state->buf_pos + s) > AMF_MAX_SIZE) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "WTF %"SWITCH_SIZE_T_FMT" %"SWITCH_SIZE_T_FMT"\n",
state->buf_pos, s);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Protocol error: exceeding max AMF packet size\n");
return SWITCH_STATUS_FALSE;
}
switch_assert(s <= rsession->in_chunksize);
if (rsession->profile->io->read(rsession, state->buf + state->buf_pos, &s) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Read error\n");
return SWITCH_STATUS_FALSE;
}
rsession->recv += s;
state->remainlen -= s;
rsession->parse_remain -= s;
state->buf_pos += s;
if (rsession->parse_remain > 0) {
/* Need more data */
return SWITCH_STATUS_SUCCESS;
}
if (state->remainlen == 0) {
if (state->type != RTMP_TYPE_AUDIO && state->type != RTMP_TYPE_VIDEO && state->type != RTMP_TYPE_ACK) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "[chunk_stream=%d type=0x%x ts=%d stream_id=0x%x] len=%d\n", rsession->amfnumber, state->type, (int)state->ts, state->stream_id, state->origlen);
}
#ifdef RTMP_DEBUG_IO
fprintf(rsession->io_debug_in, "[chunk_stream=%d type=0x%x ts=%d stream_id=0x%x] len=%d\n", rsession->amfnumber, state->type, (int)state->ts, state->stream_id, state->origlen);
#endif
switch(state->type) {
case RTMP_TYPE_CHUNKSIZE:
rsession->in_chunksize = state->buf[0] << 24 | state->buf[1] << 16 | state->buf[2] << 8 | state->buf[3];
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "SET CHUNKSIZE=%d\n", (int)rsession->in_chunksize);
break;
case RTMP_TYPE_USERCTRL:
rtmp_handle_control(rsession, rsession->amfnumber);
break;
case RTMP_TYPE_INVOKE:
rtmp_handle_invoke(rsession, rsession->amfnumber);
break;
case RTMP_TYPE_AUDIO: /* Audio data */
if (rsession->tech_pvt) {
uint16_t len = state->origlen;
switch_mutex_lock(rsession->tech_pvt->readbuf_mutex);
switch_buffer_write(rsession->tech_pvt->readbuf, &len, 2);
switch_buffer_write(rsession->tech_pvt->readbuf, state->buf, len);
switch_mutex_unlock(rsession->tech_pvt->readbuf_mutex);
}
break;
case RTMP_TYPE_VIDEO: /* Video data */
case RTMP_TYPE_METADATA: /* Metadata */
break;
case RTMP_TYPE_WINDOW_ACK_SIZE:
rsession->send_ack_window = (state->buf[0] << 24) | (state->buf[1] << 16) | (state->buf[2] << 8) | (state->buf[3]);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Set window size: %lu bytes\n", (long unsigned int)rsession->send_ack_window);
break;
case RTMP_TYPE_ACK:
{
switch_time_t now = switch_micro_time_now();
uint32_t ack = (state->buf[0] << 24) | (state->buf[1] << 16) | (state->buf[2] << 8) | (state->buf[3]);
uint32_t delta = rsession->send_ack_ts == 0 ? 0 : now - rsession->send_ack_ts;
delta /= 1000000; /* microseconds -> seconds */
if (delta) {
rsession->send_bw = (ack - rsession->send_ack) / delta;
}
rsession->send_ack = ack;
rsession->send_ack_ts = switch_micro_time_now();
break;
}
default:
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Cannot handle message type 0x%x\n", state->type);
break;
}
state->buf_pos = 0;
}
rsession->parse_state = 0;
/* Send an ACK if we need to */
if (rsession->recv - rsession->recv_ack_sent >= rsession->recv_ack_window) {
unsigned char ackbuf[] = { INT32(rsession->recv) };
rtmp_send_message(rsession, 2/*chunkstream*/, 0/*ts*/, RTMP_TYPE_ACK, 0/*msg stream id */, ackbuf, sizeof(ackbuf), 0 /*flags*/);
rsession->recv_ack_sent = rsession->recv;
}
}
}
}
return SWITCH_STATUS_SUCCESS;
}
/* For Emacs:
* Local Variables:
* mode:c
* indent-tabs-mode:t
* tab-width:4
* c-basic-offset:4
* End:
* For VIM:
* vim:set softtabstop=4 shiftwidth=4 tabstop=4:
*/
+841
View File
@@ -0,0 +1,841 @@
/*
* mod_rtmp for FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
* Copyright (C) 2011, Barracuda Networks Inc.
*
* 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 mod_rtmp for FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
*
* The Initial Developer of the Original Code is Barracuda Networks Inc.
* Portions created by the Initial Developer are Copyright (C)
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Mathieu Rene <mrene@avgs.ca>
*
* rtmp.c -- RTMP Signalling functions
*
*/
#include "mod_rtmp.h"
/* AMF */
#include "amf0.h"
#include "io.h"
#include "types.h"
/* RTMP_INVOKE_FUNCTION is a macro that expands to:
switch_status_t function(rtmp_session_t *rsession, rtmp_state_t *state, int amfnumber, int transaction_id, int argc, amf0_data *argv[])
*/
RTMP_INVOKE_FUNCTION(rtmp_i_connect)
{
amf0_data *object1 = amf0_object_new(), *object2 = amf0_object_new(), *params = argv[0], *d;
const char *s;
if ((d = amf0_object_get(params, "app")) && (s = amf0_get_string(d))) {
rsession->app = switch_core_strdup(rsession->pool, s);
}
if ((d = amf0_object_get(params, "flashVer")) && (s = amf0_get_string(d))) {
rsession->flashVer = switch_core_strdup(rsession->pool, s);
}
if ((d = amf0_object_get(params, "swfUrl")) && (s = amf0_get_string(d))) {
rsession->swfUrl = switch_core_strdup(rsession->pool, s);
}
if ((d = amf0_object_get(params, "tcUrl")) && (s = amf0_get_string(d))) {
rsession->tcUrl = switch_core_strdup(rsession->pool, s);
}
if ((d = amf0_object_get(params, "pageUrl")) && (s = amf0_get_string(d))) {
rsession->pageUrl = switch_core_strdup(rsession->pool, s);
}
if ((d = amf0_object_get(params, "capabilities"))) {
rsession->capabilities = amf0_get_number(d);
}
if ((d = amf0_object_get(params, "audioCodecs"))) {
rsession->audioCodecs = amf0_get_number(d);
}
if ((d = amf0_object_get(params, "videoCodecs"))) {
rsession->videoCodecs = amf0_get_number(d);
}
if ((d = amf0_object_get(params, "videoFunction"))) {
rsession->videoFunction = amf0_get_number(d);
}
amf0_object_add(object1, "fmsVer", amf0_number_new(1));
amf0_object_add(object1, "capabilities", amf0_number_new(31));
amf0_object_add(object2, "level", amf0_str("status"));
amf0_object_add(object2, "code", amf0_str("NetConnection.Connect.Success"));
amf0_object_add(object2, "description", amf0_str("Connection succeeded"));
amf0_object_add(object2, "clientId", amf0_number_new(217834719));
amf0_object_add(object2, "objectEncoding", amf0_number_new(0));
rtmp_set_chunksize(rsession, rsession->profile->chunksize);
{
unsigned char ackbuf[] = { INT32(RTMP_DEFAULT_ACK_WINDOW) };
rtmp_send_message(rsession, 2, 0, RTMP_TYPE_WINDOW_ACK_SIZE, 0, ackbuf, sizeof(ackbuf), MSG_FULLHEADER);
}
{
unsigned char ackbuf[] = { INT32(RTMP_DEFAULT_ACK_WINDOW), 0x1 /* Soft limit */};
rtmp_send_message(rsession, 2, 0, RTMP_TYPE_SET_PEER_BW, 0, ackbuf, sizeof(ackbuf), MSG_FULLHEADER);
}
{
unsigned char buf[] = {
INT16(RTMP_CTRL_STREAM_BEGIN),
INT32(0)
};
rtmp_send_message(rsession, 2, 0, RTMP_TYPE_USERCTRL, 0, buf, sizeof(buf), 0);
}
/* respond with a success message */
rtmp_send_invoke_free(rsession, amfnumber, 0, 0,
amf0_str("_result"),
amf0_number_new(1),
object1,
object2,
NULL);
rtmp_send_invoke_free(rsession, 3, 0, 0,
amf0_str("connected"),
amf0_number_new(0),
amf0_null_new(),
amf0_str(rsession->uuid), NULL);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Sent connect reply\n");
return SWITCH_STATUS_SUCCESS;
}
RTMP_INVOKE_FUNCTION(rtmp_i_createStream)
{
rtmp_send_invoke_free(rsession, amfnumber, 0, 0,
amf0_str("_result"),
amf0_number_new(transaction_id),
amf0_null_new(),
amf0_number_new(rsession->next_streamid),
NULL);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Replied to createStream (%u)\n", rsession->next_streamid);
rsession->next_streamid++;
return SWITCH_STATUS_SUCCESS;
}
RTMP_INVOKE_FUNCTION(rtmp_i_noop)
{
return SWITCH_STATUS_SUCCESS;
}
RTMP_INVOKE_FUNCTION(rtmp_i_receiveaudio)
{
switch_bool_t enabled = argv[1] ? amf0_boolean_get_value(argv[1]) : SWITCH_FALSE;
if (enabled) {
switch_set_flag(rsession, SFLAG_AUDIO);
} else {
switch_clear_flag(rsession, SFLAG_AUDIO);
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "%sending audio\n", enabled ? "S" : "Not s");
return SWITCH_STATUS_SUCCESS;
}
RTMP_INVOKE_FUNCTION(rtmp_i_receivevideo)
{
switch_bool_t enabled = argv[1] ? amf0_boolean_get_value(argv[1]) : SWITCH_FALSE;
if (enabled) {
switch_set_flag(rsession, SFLAG_VIDEO);
if (rsession->tech_pvt) {
switch_set_flag(rsession->tech_pvt, TFLAG_VID_WAIT_KEYFRAME);
}
} else {
switch_clear_flag(rsession, SFLAG_VIDEO);
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "%sending video\n", enabled ? "S" : "Not s");
return SWITCH_STATUS_SUCCESS;
}
RTMP_INVOKE_FUNCTION(rtmp_i_play)
{
amf0_data *obj = amf0_object_new();
amf0_data *object = amf0_object_new();
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Got play for %s on stream %d\n", switch_str_nil(amf0_get_string(argv[1])),
state->stream_id);
/* Set outgoing chunk size to 1024 bytes */
rtmp_set_chunksize(rsession, 1024);
rsession->media_streamid = state->stream_id;
/* Send StreamBegin on the current stream */
{
unsigned char buf[] = {
INT16(RTMP_CTRL_STREAM_BEGIN),
INT32(rsession->media_streamid)
};
rtmp_send_message(rsession, 2, 0, RTMP_TYPE_USERCTRL, 0, buf, sizeof(buf), 0);
}
{
unsigned char buf[] = {
INT16(RTMP_CTRL_SET_BUFFER_LENGTH),
INT32(rsession->media_streamid),
INT32(rsession->profile->buffer_len)
};
rtmp_send_message(rsession, 2, 0, RTMP_TYPE_USERCTRL, 0, buf, sizeof(buf), 0);
}
/* Send onStatus */
amf0_object_add(object, "level", amf0_str("status"));
amf0_object_add(object, "code", amf0_str("NetStream.Play.Reset"));
amf0_object_add(object, "description", amf0_str("description"));
amf0_object_add(object, "details", amf0_str("details"));
amf0_object_add(object, "clientid", amf0_number_new(217834719));
rtmp_send_invoke_free(rsession, RTMP_DEFAULT_STREAM_NOTIFY, 0, rsession->media_streamid,
amf0_str("onStatus"),
amf0_number_new(1),
amf0_null_new(),
object, NULL);
object = amf0_object_new();
amf0_object_add(object, "level", amf0_str("status"));
amf0_object_add(object, "code", amf0_str("NetStream.Play.Start"));
amf0_object_add(object, "description", amf0_str("description"));
amf0_object_add(object, "details", amf0_str("details"));
amf0_object_add(object, "clientid", amf0_number_new(217834719));
rtmp_send_invoke_free(rsession, RTMP_DEFAULT_STREAM_NOTIFY, 0, rsession->media_streamid,
amf0_str("onStatus"),
amf0_number_new(1),
amf0_null_new(),
object, NULL);
amf0_object_add(obj, "code", amf0_str("NetStream.Data.Start"));
rtmp_send_notify_free(rsession, RTMP_DEFAULT_STREAM_NOTIFY, 0, rsession->media_streamid,
amf0_str("onStatus"),
obj, NULL);
rtmp_send_notify_free(rsession, RTMP_DEFAULT_STREAM_NOTIFY, 0, rsession->media_streamid,
amf0_str("|RtmpSampleAccess"),
amf0_boolean_new(1),
amf0_boolean_new(1), NULL);
return SWITCH_STATUS_SUCCESS;
}
RTMP_INVOKE_FUNCTION(rtmp_i_publish)
{
unsigned char buf[] = {
INT16(RTMP_CTRL_STREAM_BEGIN),
INT32(state->stream_id)
};
rtmp_send_message(rsession, 2, 0, RTMP_TYPE_USERCTRL, 0, buf, sizeof(buf), 0);
rtmp_send_invoke_free(rsession, amfnumber, 0, 0,
amf0_str("_result"),
amf0_number_new(transaction_id),
amf0_null_new(),
amf0_null_new(),
NULL);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Got publish on stream %u.\n", state->stream_id);
return SWITCH_STATUS_SUCCESS;
}
RTMP_INVOKE_FUNCTION(rtmp_i_makeCall)
{
switch_core_session_t *newsession = NULL;
char *number = NULL;
if ((number = amf0_get_string(argv[1]))) {
switch_event_t *event = NULL;
char *auth, *user = NULL, *domain = NULL;
if ((auth = amf0_get_string(argv[2])) && !zstr(auth)) {
switch_split_user_domain(auth, &user, &domain);
if (rtmp_session_check_user(rsession, user, domain) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_UUID_LOG(rsession->uuid), SWITCH_LOG_WARNING, "Unauthorized call to %s, client is not logged in account [%s@%s]\n",
number, switch_str_nil(user), switch_str_nil(domain));
return SWITCH_STATUS_FALSE;
}
} else if (rsession->profile->auth_calls && !rsession->account) {
switch_log_printf(SWITCH_CHANNEL_UUID_LOG(rsession->uuid), SWITCH_LOG_WARNING, "Unauthorized call to %s, client is not logged in\n", number);
return SWITCH_STATUS_FALSE;
}
if (amf0_is_object(argv[3])) {
amf_object_to_event(argv[3], &event);
}
if (rtmp_session_create_call(rsession, &newsession, 0, RTMP_DEFAULT_STREAM_AUDIO, number, user, domain, event) != SWITCH_CAUSE_NONE) {
switch_log_printf(SWITCH_CHANNEL_UUID_LOG(rsession->uuid), SWITCH_LOG_ERROR, "Couldn't create call.\n");
}
if (event) {
switch_event_destroy(&event);
}
}
if (newsession) {
rtmp_private_t *new_pvt = switch_core_session_get_private(newsession);
rtmp_send_invoke_free(rsession, 3, 0, 0,
amf0_str("onMakeCall"),
amf0_number_new(transaction_id),
amf0_null_new(),
amf0_str(switch_core_session_get_uuid(newsession)),
amf0_str(switch_str_nil(number)),
amf0_str(switch_str_nil(new_pvt->auth)),
NULL);
rtmp_attach_private(rsession, switch_core_session_get_private(newsession));
}
return SWITCH_STATUS_SUCCESS;
}
RTMP_INVOKE_FUNCTION(rtmp_i_sendDTMF)
{
/* Send DTMFs on the active channel */
switch_dtmf_t dtmf = { 0 };
switch_channel_t *channel;
char *digits;
if (!rsession->tech_pvt) {
return SWITCH_STATUS_FALSE;
}
channel = switch_core_session_get_channel(rsession->tech_pvt->session);
if (amf0_is_number(argv[2])) {
dtmf.duration = amf0_get_number(argv[2]);
} else if (!zstr(amf0_get_string(argv[2]))) {
dtmf.duration = atoi(amf0_get_string(argv[2]));
}
if ((digits = amf0_get_string(argv[1]))) {
size_t len = strlen(digits);
size_t j;
for (j = 0; j < len; j++) {
dtmf.digit = digits[j];
switch_channel_queue_dtmf(channel, &dtmf);
}
}
return SWITCH_STATUS_SUCCESS;
}
RTMP_INVOKE_FUNCTION(rtmp_i_login)
{
char *user, *auth, *domain, *ddomain = NULL;
user = amf0_get_string(argv[1]);
auth = amf0_get_string(argv[2]);
if (zstr(user) || zstr(auth)) {
return SWITCH_STATUS_FALSE;
}
if ((domain = strchr(user, '@'))) {
*domain++ = '\0';
}
if (zstr(domain)) {
ddomain = switch_core_get_variable_dup("domain");
domain = ddomain;
}
if (rtmp_check_auth(rsession, user, domain, auth) == SWITCH_STATUS_SUCCESS) {
rtmp_session_login(rsession, user, domain);
} else {
rtmp_send_invoke_free(rsession, 3, 0, 0,
amf0_str("onLogin"),
amf0_number_new(0),
amf0_null_new(),
amf0_str("failure"),
amf0_null_new(),
amf0_null_new(), NULL);
}
switch_safe_free(ddomain);
return SWITCH_STATUS_SUCCESS;
}
RTMP_INVOKE_FUNCTION(rtmp_i_logout)
{
char *auth = amf0_get_string(argv[1]);
char *user = NULL, *domain = NULL;
/* Unregister from that user */
rtmp_clear_registration(rsession, auth, NULL);
switch_split_user_domain(auth, &user, &domain);
if (!zstr(user) && !zstr(domain)) {
rtmp_session_logout(rsession, user, domain);
}
return SWITCH_STATUS_SUCCESS;
}
RTMP_INVOKE_FUNCTION(rtmp_i_register)
{
char *auth = amf0_get_string(argv[1]);
const char *user = NULL, *domain = NULL;
char *dup = NULL;
switch_status_t status;
if (!rsession->account) {
return SWITCH_STATUS_FALSE;
}
if (!zstr(auth)) {
dup = strdup(auth);
switch_split_user_domain(dup, (char**)&user, (char**)&domain);
} else {
dup = auth = switch_mprintf("%s@%s", rsession->account->user, rsession->account->domain);
user = rsession->account->user;
domain = rsession->account->domain;
}
if (rtmp_session_check_user(rsession, user, domain) == SWITCH_STATUS_SUCCESS) {
rtmp_add_registration(rsession, auth, amf0_get_string(argv[2]));
status = SWITCH_STATUS_SUCCESS;
} else {
status = SWITCH_STATUS_FALSE;
}
switch_safe_free(dup);
return status;
}
RTMP_INVOKE_FUNCTION(rtmp_i_unregister)
{
rtmp_clear_registration(rsession, amf0_get_string(argv[1]), amf0_get_string(argv[2]));
return SWITCH_STATUS_SUCCESS;
}
RTMP_INVOKE_FUNCTION(rtmp_i_answer)
{
switch_channel_t *channel = NULL;
char *uuid = amf0_get_string(argv[1]);
if (!zstr(uuid)) {
rtmp_private_t *new_tech_pvt = rtmp_locate_private(rsession, uuid);
if (new_tech_pvt) {
switch_channel_mark_answered(switch_core_session_get_channel(new_tech_pvt->session));
rtmp_attach_private(rsession, new_tech_pvt);
}
return SWITCH_STATUS_FALSE;
}
if (!rsession->tech_pvt) {
return SWITCH_STATUS_FALSE;
}
/* No UUID specified but we're attached to a channel, mark it as answered */
channel = switch_core_session_get_channel(rsession->tech_pvt->session);
switch_channel_mark_answered(channel);
rtmp_attach_private(rsession, rsession->tech_pvt);
return SWITCH_STATUS_SUCCESS;
}
RTMP_INVOKE_FUNCTION(rtmp_i_attach)
{
rtmp_private_t *tech_pvt = NULL;
char *uuid = amf0_get_string(argv[1]);
if (!zstr(uuid)) {
tech_pvt = rtmp_locate_private(rsession, uuid);
}
/* Will detach if an empty (or invalid) uuid is received */
rtmp_attach_private(rsession, tech_pvt);
return SWITCH_STATUS_SUCCESS;
}
RTMP_INVOKE_FUNCTION(rtmp_i_hangup)
{
/* CallID (or null/nothing to hangup the current call) */
char *uuid = amf0_get_string(argv[1]);
char *scause;
switch_channel_t *channel = NULL;
switch_call_cause_t cause = SWITCH_CAUSE_NORMAL_CLEARING;
if (!zstr(uuid)) {
rtmp_private_t *tech_pvt = rtmp_locate_private(rsession, uuid);
if (tech_pvt) {
channel = switch_core_session_get_channel(tech_pvt->session);
}
}
if (!channel) {
if (!rsession->tech_pvt) {
return SWITCH_STATUS_FALSE;
}
channel = switch_core_session_get_channel(rsession->tech_pvt->session);
}
if (amf0_is_number(argv[2])) {
cause = amf0_get_number(argv[2]);
} else if ((scause = amf0_get_string(argv[2])) && !zstr(scause)) {
cause = switch_channel_str2cause(scause);
}
switch_channel_hangup(channel, cause);
return SWITCH_STATUS_SUCCESS;
}
RTMP_INVOKE_FUNCTION(rtmp_i_transfer)
{
char *uuid = amf0_get_string(argv[1]);
char *dest = amf0_get_string(argv[2]);
rtmp_private_t *tech_pvt;
if (zstr(uuid) || zstr(dest)) {
return SWITCH_STATUS_FALSE;
}
if ((tech_pvt = rtmp_locate_private(rsession, uuid))) {
const char *other_uuid = switch_channel_get_variable(tech_pvt->channel, SWITCH_SIGNAL_BOND_VARIABLE);
switch_core_session_t *session;
if (!zstr(other_uuid) && (session = switch_core_session_locate(other_uuid))) {
switch_ivr_session_transfer(session, dest, NULL, NULL);
switch_core_session_rwunlock(session);
}
}
return SWITCH_STATUS_SUCCESS;
}
RTMP_INVOKE_FUNCTION(rtmp_i_join)
{
char *uuid[] = { amf0_get_string(argv[1]), amf0_get_string(argv[2]) };
const char *other_uuid[2];
rtmp_private_t *tech_pvt[2];
if (zstr(uuid[0]) || zstr(uuid[1])) {
return SWITCH_STATUS_SUCCESS;
}
if (!(tech_pvt[0] = rtmp_locate_private(rsession, uuid[0])) ||
!(tech_pvt[1] = rtmp_locate_private(rsession, uuid[1]))) {
return SWITCH_STATUS_FALSE;
}
if (tech_pvt[0] == tech_pvt[1]) {
return SWITCH_STATUS_FALSE;
}
if ((other_uuid[0] = switch_channel_get_variable(tech_pvt[0]->channel, SWITCH_SIGNAL_BOND_VARIABLE)) &&
(other_uuid[1] = switch_channel_get_variable(tech_pvt[1]->channel, SWITCH_SIGNAL_BOND_VARIABLE))) {
#ifndef RTMP_DONT_HOLD
if (switch_test_flag(tech_pvt[0], TFLAG_DETACHED)) {
switch_ivr_unhold(tech_pvt[0]->session);
}
if (switch_test_flag(tech_pvt[1], TFLAG_DETACHED)) {
switch_ivr_unhold(tech_pvt[1]->session);
}
#endif
switch_ivr_uuid_bridge(other_uuid[0], other_uuid[1]);
}
return SWITCH_STATUS_SUCCESS;
}
/*
3-way:
[0] is always the current active call
[1] is the call to be brought into the call, and that will be running the three_way application
- Set the current app of other[1] to three_way with other_uuid[0]
- Put tech_pvt[0] to sleep: set state to CS_HIBERNATE
- set CF_TRANSFER, set state CS_EXECUTE (do we need CF_TRANSFER here?)
- setup a state handler in other[1] to detect when it hangs up
Check list:
tech_pvt[0] or other[0] hangs up
If we were attached to the call, switch the active call to tech_pvt[1]
tech_pvt[1] or other[1] hangs up
Clear up any 3-way indications on the tech_pvt[0]
*/
static switch_status_t three_way_on_soft_execute(switch_core_session_t *session);
#if 0
static switch_status_t three_way_on_hangup(switch_core_session_t *session);
#endif
static const switch_state_handler_table_t three_way_state_handlers_remote = {
/*.on_init */ NULL,
/*.on_routing */ NULL,
/*.on_execute */ NULL,
/*.on_hangup */ NULL,
/*.on_exchange_media */ NULL,
/*.on_soft_execute */ three_way_on_soft_execute,
/*.on_consume_media */ NULL,
/*.on_hibernate */ NULL
};
/* runs on other_session[1] */
static switch_status_t three_way_on_soft_execute(switch_core_session_t *other_session)
{
switch_channel_t *other_channel = switch_core_session_get_channel(other_session);
const char *uuid = switch_channel_get_variable(other_channel, RTMP_THREE_WAY_UUID_VARIABLE);
const char *my_uuid = switch_channel_get_variable(other_channel, SWITCH_SOFT_HOLDING_UUID_VARIABLE);
switch_core_session_t *my_session;
switch_channel_t *my_channel;
rtmp_private_t *tech_pvt;
if (zstr(uuid) || zstr(my_uuid)) {
return SWITCH_STATUS_SUCCESS;
}
if (zstr(my_uuid) || !(my_session = switch_core_session_locate(my_uuid))) {
return SWITCH_STATUS_SUCCESS;
}
if (!switch_core_session_check_interface(my_session, rtmp_globals.rtmp_endpoint_interface)) {
/* In case someone tempers with my variables, since we get tech_pvt from there */
switch_core_session_rwunlock(my_session);
return SWITCH_STATUS_SUCCESS;
}
my_channel = switch_core_session_get_channel(my_session);
tech_pvt = switch_core_session_get_private(my_session);
switch_ivr_eavesdrop_session(other_session, uuid, NULL, ED_MUX_READ | ED_MUX_WRITE);
/* 3-way call ended, whatever the reason
* We need to go back to our original state. */
if (!switch_channel_up(other_channel)) {
/* channel[1] hung up, check if we have special post-bridge actions, and hangup otherwise */
/* if my_channel isn't ready, it means something else has control of it, leave it alone */
if (switch_channel_ready(my_channel)) {
const char *s;
if ((s = switch_channel_get_variable(my_channel, SWITCH_PARK_AFTER_BRIDGE_VARIABLE)) && switch_true(s)) {
switch_ivr_park_session(my_session);
} else if ((s = switch_channel_get_variable(my_channel, SWITCH_TRANSFER_AFTER_BRIDGE_VARIABLE)) && !zstr(s)) {
int argc;
char *argv[4] = { 0 };
char *mydata = switch_core_session_strdup(my_session, s);
switch_channel_set_variable(my_channel, SWITCH_TRANSFER_AFTER_BRIDGE_VARIABLE, NULL);
if ((argc = switch_split(mydata, ':', argv)) >= 1) {
switch_ivr_session_transfer(my_session, argv[0], argv[1], argv[2]);
} else {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(my_session), SWITCH_LOG_ERROR, "No extension specified.\n");
}
} else {
switch_channel_hangup(my_channel, SWITCH_CAUSE_NORMAL_CLEARING);
}
}
} else if (switch_channel_ready(other_channel)) {
/* channel[1] didn't hangup, must be channel[0] then, rebridge this one with its original partner */
switch_ivr_uuid_bridge(switch_core_session_get_uuid(other_session), my_uuid);
} else {
/* channel[1] being taken out of our control, take the other leg out of CS_HIBERNATE if its ready, or else leave it alone */
if (switch_channel_ready(my_channel)) {
switch_channel_set_state(my_channel, CS_EXECUTE);
}
}
switch_channel_clear_state_handler(other_channel, &three_way_state_handlers_remote);
switch_channel_set_variable(other_channel, SWITCH_SOFT_HOLDING_UUID_VARIABLE, NULL);
switch_channel_set_variable(my_channel, SWITCH_SOFT_HOLDING_UUID_VARIABLE, NULL);
switch_channel_set_variable(other_channel, RTMP_THREE_WAY_UUID_VARIABLE, NULL);
switch_clear_flag(tech_pvt, TFLAG_THREE_WAY);
if (my_session) {
switch_core_session_rwunlock(my_session);
}
return SWITCH_STATUS_SUCCESS;
}
RTMP_INVOKE_FUNCTION(rtmp_i_three_way)
{
/* The first uuid is the (local) uuid of the current call, the 2nd one should be already detached */
char *uuid[] = { amf0_get_string(argv[1]), amf0_get_string(argv[2]) };
rtmp_private_t *tech_pvt[2];
const char *other_uuid[2];
switch_core_session_t *other_session[2] = { 0 };
switch_channel_t *other_channel[2] = { 0 };
if (zstr(uuid[0]) || zstr(uuid[1]) ||
!(tech_pvt[0] = rtmp_locate_private(rsession, uuid[0])) ||
!(tech_pvt[1] = rtmp_locate_private(rsession, uuid[1]))) {
return SWITCH_STATUS_FALSE;
}
/* Make sure we don't 3-way with the same call, and that it doesnt turn into a 4-way, we aren't that permissive */
if (tech_pvt[0] == tech_pvt[1] || switch_test_flag(tech_pvt[0], TFLAG_THREE_WAY) ||
switch_test_flag(tech_pvt[1], TFLAG_THREE_WAY)) {
return SWITCH_STATUS_FALSE;
}
if (!(other_uuid[0] = switch_channel_get_variable(tech_pvt[0]->channel, SWITCH_SIGNAL_BOND_VARIABLE)) ||
!(other_uuid[1] = switch_channel_get_variable(tech_pvt[1]->channel, SWITCH_SIGNAL_BOND_VARIABLE))) {
return SWITCH_STATUS_FALSE; /* Both calls aren't bridged */
}
if (!(other_session[0] = switch_core_session_locate(other_uuid[0])) ||
!(other_session[1] = switch_core_session_locate(other_uuid[1]))) {
goto done;
}
other_channel[0] = switch_core_session_get_channel(other_session[0]);
other_channel[1] = switch_core_session_get_channel(other_session[1]);
/* Save which uuid is the 3-way target */
switch_channel_set_variable(other_channel[1], RTMP_THREE_WAY_UUID_VARIABLE, uuid[0]);
switch_channel_set_variable(tech_pvt[1]->channel, RTMP_THREE_WAY_UUID_VARIABLE, uuid[0]);
/* Attach redirect */
switch_set_flag(tech_pvt[1], TFLAG_THREE_WAY);
/* Set soft_holding_uuid to the uuid of the other matching channel, so they can can be bridged back when the 3-way is over */
switch_channel_set_variable(tech_pvt[1]->channel, SWITCH_SOFT_HOLDING_UUID_VARIABLE, other_uuid[1]);
switch_channel_set_variable(other_channel[1], SWITCH_SOFT_HOLDING_UUID_VARIABLE, uuid[1]);
/* Start the 3-way on the 2nd channel using a media bug */
switch_channel_add_state_handler(other_channel[1], &three_way_state_handlers_remote);
switch_channel_set_flag(tech_pvt[1]->channel, CF_TRANSFER);
switch_channel_set_state(tech_pvt[1]->channel, CS_HIBERNATE);
switch_channel_set_flag(other_channel[1], CF_TRANSFER);
switch_channel_set_state(other_channel[1], CS_SOFT_EXECUTE);
done:
if (other_session[0]) {
switch_core_session_rwunlock(other_session[0]);
}
if (other_session[1]) {
switch_core_session_rwunlock(other_session[1]);
}
return SWITCH_STATUS_SUCCESS;
}
RTMP_INVOKE_FUNCTION(rtmp_i_sendevent)
{
amf0_data *obj = NULL;
switch_event_t *event = NULL;
switch_status_t status = SWITCH_STATUS_SUCCESS;
const char *uuid = NULL;
if (argv[1] && argv[1]->type == AMF0_TYPE_OBJECT) {
obj = argv[1];
} else if (argv[2] && argv[2]->type == AMF0_TYPE_OBJECT) {
uuid = amf0_get_string(argv[1]);
obj = argv[2];
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Bad argument for sendevent");
return SWITCH_STATUS_FALSE;
}
if (switch_event_create_subclass(&event, zstr(uuid) ? SWITCH_EVENT_CUSTOM : SWITCH_EVENT_MESSAGE,
zstr(uuid) ? RTMP_EVENT_CLIENTCUSTOM : NULL) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_UUID_LOG(rsession->uuid), SWITCH_LOG_ERROR, "Couldn't create event\n");
return SWITCH_STATUS_FALSE;
}
rtmp_event_fill(rsession, event);
/* Build event using amf array */
if ((status = amf_object_to_event(obj, &event)) != SWITCH_STATUS_SUCCESS) {
switch_event_destroy(&event);
return SWITCH_STATUS_FALSE;
}
if (!zstr(uuid)) {
rtmp_private_t *session_pvt = rtmp_locate_private(rsession, uuid);
if (session_pvt) {
if (switch_core_session_queue_event(session_pvt->session, &event) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session_pvt->session), SWITCH_LOG_ERROR, "Couldn't queue event to session\n");
switch_event_destroy(&event);
status = SWITCH_STATUS_FALSE;
} else {
status = SWITCH_STATUS_SUCCESS;
}
}
}
switch_event_fire(&event);
return SWITCH_STATUS_SUCCESS;
}
RTMP_INVOKE_FUNCTION(rtmp_i_log)
{
const char *data = amf0_get_string(argv[1]);
switch_log_printf(SWITCH_CHANNEL_UUID_LOG(rsession->uuid), SWITCH_LOG_INFO, "Log: %s\n", data);
return SWITCH_STATUS_SUCCESS;
}
/* For Emacs:
* Local Variables:
* mode:c
* indent-tabs-mode:t
* tab-width:4
* c-basic-offset:4
* End:
* For VIM:
* vim:set softtabstop=4 shiftwidth=4 tabstop=4:
*/
+368
View File
@@ -0,0 +1,368 @@
/*
* mod_rtmp for FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
* Copyright (C) 2011, Barracuda Networks Inc.
*
* 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 mod_rtmp for FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
*
* The Initial Developer of the Original Code is Barracuda Networks Inc.
* Portions created by the Initial Developer are Copyright (C)
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Mathieu Rene <mrene@avgs.ca>
*
* rtmp_tcp.c -- RTMP TCP I/O module
*
*/
#include "mod_rtmp.h"
/* Locally-extended version of rtmp_io_t */
struct rtmp_io_tcp {
rtmp_io_t base;
switch_pollset_t *pollset;
switch_pollfd_t *listen_pollfd;
switch_socket_t *listen_socket;
const char *ip;
switch_port_t port;
switch_thread_t *thread;
switch_mutex_t *mutex;
};
typedef struct rtmp_io_tcp rtmp_io_tcp_t;
struct rtmp_tcp_io_private {
switch_pollfd_t *pollfd;
switch_socket_t *socket;
switch_buffer_t *sendq;
switch_bool_t poll_send;
};
typedef struct rtmp_tcp_io_private rtmp_tcp_io_private_t;
static void rtmp_tcp_alter_pollfd(rtmp_session_t *rsession, switch_bool_t pollout)
{
rtmp_tcp_io_private_t *io_pvt = rsession->io_private;
rtmp_io_tcp_t *io = (rtmp_io_tcp_t*)rsession->profile->io;
if (pollout && (io_pvt->pollfd->reqevents & SWITCH_POLLOUT)) {
return;
} else if (!pollout && !(io_pvt->pollfd->reqevents & SWITCH_POLLOUT)) {
return;
}
switch_pollset_remove(io->pollset, io_pvt->pollfd);
io_pvt->pollfd->reqevents = SWITCH_POLLIN | SWITCH_POLLERR;
if (pollout) {
io_pvt->pollfd->reqevents |= SWITCH_POLLOUT;
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Pollout: %s\n",
pollout ? "true" : "false");
switch_pollset_add(io->pollset, io_pvt->pollfd);
}
static switch_status_t rtmp_tcp_read(rtmp_session_t *rsession, unsigned char *buf, switch_size_t *len)
{
//rtmp_io_tcp_t *io = (rtmp_io_tcp_t*)rsession->profile->io;
rtmp_tcp_io_private_t *io_pvt = rsession->io_private;
switch_status_t status = SWITCH_STATUS_SUCCESS;
#ifdef RTMP_DEBUG_IO
switch_size_t olen = *len;
#endif
switch_assert(*len > 0 && *len < 1024000);
status = switch_socket_recv(io_pvt->socket, (char*)buf, len);
#ifdef RTMP_DEBUG_IO
{
int i;
fprintf(rsession->io_debug_in, "recv %p max=%"SWITCH_SIZE_T_FMT" got=%"SWITCH_SIZE_T_FMT"\n< ", (void*)buf, olen, *len);
for (i = 0; i < *len; i++) {
fprintf(rsession->io_debug_in, "%02X ", (uint8_t)buf[i]);
if (i != 0 && i % 32 == 0) {
fprintf(rsession->io_debug_in, "\n> ");
}
}
fprintf(rsession->io_debug_in, "\n\n");
fflush(rsession->io_debug_in);
}
#endif
return status;
}
static switch_status_t rtmp_tcp_write(rtmp_session_t *rsession, const unsigned char *buf, switch_size_t *len)
{
//rtmp_io_tcp_t *io = (rtmp_io_tcp_t*)rsession->profile->io;
rtmp_tcp_io_private_t *io_pvt = rsession->io_private;
switch_status_t status;
switch_size_t orig_len = *len;
#ifdef RTMP_DEBUG_IO
{
int i;
fprintf(rsession->io_debug_out,
"SEND %"SWITCH_SIZE_T_FMT" bytes\n> ", *len);
for (i = 0; i < *len; i++) {
fprintf(rsession->io_debug_out, "%02X ", (uint8_t)buf[i]);
if (i != 0 && i % 32 == 0) {
fprintf(rsession->io_debug_out, "\n> ");
}
}
fprintf(rsession->io_debug_out, "\n\n ");
fflush(rsession->io_debug_out);
}
#endif
if (io_pvt->sendq && switch_buffer_inuse(io_pvt->sendq) > 0) {
/* We already have queued data, append it to the sendq */
switch_buffer_write(io_pvt->sendq, buf, *len);
return SWITCH_STATUS_SUCCESS;
}
status = switch_socket_send_nonblock(io_pvt->socket, (char*)buf, len);
if (*len < orig_len) {
if (rsession->state >= RS_DESTROY) {
return SWITCH_STATUS_FALSE;
}
/* We didnt send it all... add it to the sendq*/
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%"SWITCH_SIZE_T_FMT" bytes added to sendq.\n", (orig_len - *len));
switch_buffer_write(io_pvt->sendq, (buf + *len), orig_len - *len);
/* Make sure we poll-write */
rtmp_tcp_alter_pollfd(rsession, SWITCH_TRUE);
}
return status;
}
static switch_status_t rtmp_tcp_close(rtmp_session_t *rsession)
{
rtmp_io_tcp_t *io = (rtmp_io_tcp_t*)rsession->profile->io;
rtmp_tcp_io_private_t *io_pvt = rsession->io_private;
if (io_pvt->socket) {
switch_mutex_lock(io->mutex);
switch_pollset_remove(io->pollset, io_pvt->pollfd);
switch_mutex_unlock(io->mutex);
switch_socket_close(io_pvt->socket);
io_pvt->socket = NULL;
}
return SWITCH_STATUS_SUCCESS;
}
void *SWITCH_THREAD_FUNC rtmp_io_tcp_thread(switch_thread_t *thread, void *obj)
{
rtmp_io_tcp_t *io = (rtmp_io_tcp_t*)obj;
io->base.running = 1;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s: I/O Thread starting\n", io->base.profile->name);
while(io->base.running) {
const switch_pollfd_t *fds;
int32_t numfds;
int32_t i;
switch_status_t status;
switch_mutex_lock(io->mutex);
status = switch_pollset_poll(io->pollset, 500000, &numfds, &fds);
switch_mutex_unlock(io->mutex);
if (status != SWITCH_STATUS_SUCCESS && status != SWITCH_STATUS_TIMEOUT) {
//switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "pollset_poll failed\n");
continue;
} else if (status == SWITCH_STATUS_TIMEOUT) {
switch_yield(1);
}
for (i = 0; i < numfds; i++) {
if (!fds[i].client_data) {
switch_socket_t *newsocket;
if (switch_socket_accept(&newsocket, io->listen_socket, io->base.pool) != SWITCH_STATUS_SUCCESS) {
if (io->base.running) {
/* Don't spam the logs if we are shutting down */
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Socket Error [%s]\n", strerror(errno));
} else {
return NULL;
}
} else {
rtmp_session_t *newsession;
if (switch_socket_opt_set(newsocket, SWITCH_SO_NONBLOCK, TRUE)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Couldn't set socket as non-blocking\n");
}
if (rtmp_session_request(io->base.profile, &newsession) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "RTMP session request failed\n");
switch_socket_close(newsocket);
} else {
switch_sockaddr_t *addr = NULL;
char ipbuf[200];
/* Create out private data and attach it to the rtmp session structure */
rtmp_tcp_io_private_t *pvt = switch_core_alloc(newsession->pool, sizeof(*pvt));
newsession->io_private = pvt;
pvt->socket = newsocket;
switch_socket_create_pollfd(&pvt->pollfd, newsocket, SWITCH_POLLIN | SWITCH_POLLERR, newsession, newsession->pool);
switch_pollset_add(io->pollset, pvt->pollfd);
switch_buffer_create_dynamic(&pvt->sendq, 512, 1024, 0);
/* Get the remote address/port info */
switch_socket_addr_get(&addr, SWITCH_TRUE, newsocket);
switch_get_addr(ipbuf, sizeof(ipbuf), addr);
newsession->remote_address = switch_core_strdup(newsession->pool, ipbuf);
newsession->remote_port = switch_sockaddr_get_port(addr);
}
}
} else {
rtmp_session_t *rsession = (rtmp_session_t*)fds[i].client_data;
rtmp_tcp_io_private_t *io_pvt = (rtmp_tcp_io_private_t*)rsession->io_private;
if (fds[i].rtnevents & SWITCH_POLLOUT && switch_buffer_inuse(io_pvt->sendq) > 0) {
/* Send as much remaining data as possible */
switch_size_t sendlen;
const void *ptr;
sendlen = switch_buffer_peek_zerocopy(io_pvt->sendq, &ptr);
switch_socket_send_nonblock(io_pvt->socket, ptr, &sendlen);
switch_buffer_toss(io_pvt->sendq, sendlen);
if (switch_buffer_inuse(io_pvt->sendq) == 0) {
/* Remove our fd from OUT polling */
rtmp_tcp_alter_pollfd(rsession, SWITCH_FALSE);
}
} else if (fds[i].rtnevents & SWITCH_POLLIN && rtmp_handle_data(rsession) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_UUID_LOG(rsession->uuid), SWITCH_LOG_DEBUG, "Closing socket\n");
switch_mutex_lock(io->mutex);
switch_pollset_remove(io->pollset, io_pvt->pollfd);
switch_mutex_unlock(io->mutex);
switch_socket_close(io_pvt->socket);
io_pvt->socket = NULL;
rtmp_session_destroy(&rsession);
}
}
}
}
io->base.running = -1;
switch_socket_close(io->listen_socket);
return NULL;
}
switch_status_t rtmp_tcp_init(rtmp_profile_t *profile, const char *bindaddr, rtmp_io_t **new_io, switch_memory_pool_t *pool)
{
char *szport;
switch_sockaddr_t *sa;
switch_threadattr_t *thd_attr = NULL;
rtmp_io_tcp_t *io_tcp;
io_tcp = (rtmp_io_tcp_t*)switch_core_alloc(pool, sizeof(rtmp_io_tcp_t));
io_tcp->base.pool = pool;
io_tcp->ip = switch_core_strdup(pool, bindaddr);
*new_io = (rtmp_io_t*)io_tcp;
io_tcp->base.profile = profile;
io_tcp->base.read = rtmp_tcp_read;
io_tcp->base.write = rtmp_tcp_write;
io_tcp->base.close = rtmp_tcp_close;
io_tcp->base.name = "tcp";
io_tcp->base.address = switch_core_strdup(pool, io_tcp->ip);
if ((szport = strchr(io_tcp->ip, ':'))) {
*szport++ = '\0';
io_tcp->port = atoi(szport);
} else {
io_tcp->port = RTMP_DEFAULT_PORT;
}
if (switch_sockaddr_info_get(&sa, io_tcp->ip, SWITCH_INET, io_tcp->port, 0, pool)) {
goto fail;
}
if (switch_socket_create(&io_tcp->listen_socket, switch_sockaddr_get_family(sa), SOCK_STREAM, SWITCH_PROTO_TCP, pool)) {
goto fail;
}
if (switch_socket_opt_set(io_tcp->listen_socket, SWITCH_SO_REUSEADDR, 1)) {
goto fail;
}
if (switch_socket_bind(io_tcp->listen_socket, sa)) {
goto fail;
}
if (switch_socket_listen(io_tcp->listen_socket, 10)) {
goto fail;
}
if (switch_socket_opt_set(io_tcp->listen_socket, SWITCH_SO_NONBLOCK, TRUE)) {
goto fail;
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Listening on %s:%u (tcp)\n", io_tcp->ip, io_tcp->port);
io_tcp->base.running = 1;
if (switch_pollset_create(&io_tcp->pollset, 1000 /* max poll fds */, pool, 0) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "pollset_create failed\n");
goto fail;
}
switch_socket_create_pollfd(&(io_tcp->listen_pollfd), io_tcp->listen_socket, SWITCH_POLLIN | SWITCH_POLLERR, NULL, pool);
if (switch_pollset_add(io_tcp->pollset, io_tcp->listen_pollfd) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "pollset_add failed\n");
goto fail;
}
switch_mutex_init(&io_tcp->mutex, SWITCH_MUTEX_NESTED, pool);
switch_threadattr_create(&thd_attr, pool);
switch_threadattr_detach_set(thd_attr, 1);
switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
switch_thread_create(&io_tcp->thread, thd_attr, rtmp_io_tcp_thread, *new_io, pool);
return SWITCH_STATUS_SUCCESS;
fail:
if (io_tcp->listen_socket) {
switch_socket_close(io_tcp->listen_socket);
}
*new_io = NULL;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Socket error. Couldn't listen on %s:%u\n", io_tcp->ip, io_tcp->port);
return SWITCH_STATUS_FALSE;
}
/* For Emacs:
* Local Variables:
* mode:c
* indent-tabs-mode:t
* tab-width:4
* c-basic-offset:4
* End:
* For VIM:
* vim:set softtabstop=4 shiftwidth=4 tabstop=4:
*/
+264 -264
View File
@@ -50,58 +50,58 @@ skinny_globals_t globals;
/* SQL TABLES */
/*****************************************************************************/
static char devices_sql[] =
"CREATE TABLE skinny_devices (\n"
" name VARCHAR(16),\n"
" user_id INTEGER,\n"
" instance INTEGER,\n"
" ip VARCHAR(15),\n"
" type INTEGER,\n"
" max_streams INTEGER,\n"
" port INTEGER,\n"
" codec_string VARCHAR(255),\n"
" headset INTEGER,\n"
" handset INTEGER,\n"
" speaker INTEGER\n"
");\n";
"CREATE TABLE skinny_devices (\n"
" name VARCHAR(16),\n"
" user_id INTEGER,\n"
" instance INTEGER,\n"
" ip VARCHAR(15),\n"
" type INTEGER,\n"
" max_streams INTEGER,\n"
" port INTEGER,\n"
" codec_string VARCHAR(255),\n"
" headset INTEGER,\n"
" handset INTEGER,\n"
" speaker INTEGER\n"
");\n";
static char lines_sql[] =
"CREATE TABLE skinny_lines (\n"
" device_name VARCHAR(16),\n"
" device_instance INTEGER,\n"
" position INTEGER,\n"
" line_instance INTEGER,\n"
" label VARCHAR(40),\n"
" value VARCHAR(24),\n"
" caller_name VARCHAR(44),\n"
" ring_on_idle INTEGER,\n"
" ring_on_active INTEGER,\n"
" busy_trigger INTEGER,\n"
" forward_all VARCHAR(255),\n"
" forward_busy VARCHAR(255),\n"
" forward_noanswer VARCHAR(255),\n"
" noanswer_duration INTEGER\n"
");\n";
"CREATE TABLE skinny_lines (\n"
" device_name VARCHAR(16),\n"
" device_instance INTEGER,\n"
" position INTEGER,\n"
" line_instance INTEGER,\n"
" label VARCHAR(40),\n"
" value VARCHAR(24),\n"
" caller_name VARCHAR(44),\n"
" ring_on_idle INTEGER,\n"
" ring_on_active INTEGER,\n"
" busy_trigger INTEGER,\n"
" forward_all VARCHAR(255),\n"
" forward_busy VARCHAR(255),\n"
" forward_noanswer VARCHAR(255),\n"
" noanswer_duration INTEGER\n"
");\n";
static char buttons_sql[] =
"CREATE TABLE skinny_buttons (\n"
" device_name VARCHAR(16),\n"
" device_instance INTEGER,\n"
" position INTEGER,\n"
" type INTEGER,\n"
" label VARCHAR(40),\n"
" value VARCHAR(255),\n"
" settings VARCHAR(44)\n"
");\n";
"CREATE TABLE skinny_buttons (\n"
" device_name VARCHAR(16),\n"
" device_instance INTEGER,\n"
" position INTEGER,\n"
" type INTEGER,\n"
" label VARCHAR(40),\n"
" value VARCHAR(255),\n"
" settings VARCHAR(44)\n"
");\n";
static char active_lines_sql[] =
"CREATE TABLE skinny_active_lines (\n"
" device_name VARCHAR(16),\n"
" device_instance INTEGER,\n"
" line_instance INTEGER,\n"
" channel_uuid VARCHAR(256),\n"
" call_id INTEGER,\n"
" call_state INTEGER\n"
");\n";
"CREATE TABLE skinny_active_lines (\n"
" device_name VARCHAR(16),\n"
" device_instance INTEGER,\n"
" line_instance INTEGER,\n"
" channel_uuid VARCHAR(256),\n"
" call_id INTEGER,\n"
" call_state INTEGER\n"
");\n";
/*****************************************************************************/
/* PROFILES FUNCTIONS */
@@ -238,7 +238,7 @@ char * skinny_profile_find_session_uuid(skinny_profile_t *profile, listener_t *l
if(listener) {
device_condition = switch_mprintf("device_name='%s' AND device_instance=%d",
listener->device_name, listener->device_instance);
listener->device_name, listener->device_instance);
} else {
device_condition = switch_mprintf("1=1");
}
@@ -256,14 +256,14 @@ char * skinny_profile_find_session_uuid(skinny_profile_t *profile, listener_t *l
}
switch_assert(call_id_condition);
if((sql = switch_mprintf(
"SELECT channel_uuid, line_instance "
"FROM skinny_active_lines "
"WHERE %s AND %s AND %s "
"ORDER BY call_state, channel_uuid", /* off hook first */
device_condition, line_instance_condition, call_id_condition
))) {
"SELECT channel_uuid, line_instance "
"FROM skinny_active_lines "
"WHERE %s AND %s AND %s "
"ORDER BY call_state, channel_uuid", /* off hook first */
device_condition, line_instance_condition, call_id_condition
))) {
skinny_execute_sql_callback(profile, profile->sql_mutex, sql,
skinny_profile_find_session_uuid_callback, &helper);
skinny_profile_find_session_uuid_callback, &helper);
switch_safe_free(sql);
}
switch_safe_free(device_condition);
@@ -291,8 +291,8 @@ switch_core_session_t * skinny_profile_find_session(skinny_profile_t *profile, l
#endif
if(!result) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING,
"Unable to find session %s on %s:%d, line %d\n",
uuid, listener->device_name, listener->device_instance, *line_instance_p);
"Unable to find session %s on %s:%d, line %d\n",
uuid, listener->device_name, listener->device_instance, *line_instance_p);
}
switch_safe_free(uuid);
}
@@ -340,7 +340,7 @@ switch_status_t skinny_execute_sql(skinny_profile_t *profile, char *sql, switch_
status = switch_cache_db_execute_sql(dbh, sql, NULL);
end:
end:
switch_cache_db_release_db_handle(&dbh);
@@ -352,7 +352,7 @@ switch_status_t skinny_execute_sql(skinny_profile_t *profile, char *sql, switch_
}
switch_bool_t skinny_execute_sql_callback(skinny_profile_t *profile, switch_mutex_t *mutex, char *sql, switch_core_db_callback_func_t callback,
void *pdata)
void *pdata)
{
switch_bool_t ret = SWITCH_FALSE;
char *errmsg = NULL;
@@ -374,7 +374,7 @@ switch_bool_t skinny_execute_sql_callback(skinny_profile_t *profile, switch_mute
free(errmsg);
}
end:
end:
switch_cache_db_release_db_handle(&dbh);
@@ -400,9 +400,9 @@ void skinny_line_perform_set_state(const char *file, const char *func, int line,
switch_event_fire(&event);
send_call_state(listener, call_state, line_instance, call_id);
switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_DEBUG,
"Device %s:%d, Line %d, Call %d Change State to %s (%d)\n",
listener->device_name, listener->device_instance, line_instance, call_id,
skinny_call_state2str(call_state), call_state);
"Device %s:%d, Line %d, Call %d Change State to %s (%d)\n",
listener->device_name, listener->device_instance, line_instance, call_id,
skinny_call_state2str(call_state), call_state);
}
@@ -443,13 +443,13 @@ uint32_t skinny_line_get_state(listener_t *listener, uint32_t line_instance, uin
helper.call_state = -1;
if ((sql = switch_mprintf(
"SELECT call_state FROM skinny_active_lines "
"WHERE device_name='%s' AND device_instance=%d "
"AND %s AND %s "
"ORDER BY call_state, channel_uuid", /* off hook first */
listener->device_name, listener->device_instance,
line_instance_condition, call_id_condition
))) {
"SELECT call_state FROM skinny_active_lines "
"WHERE device_name='%s' AND device_instance=%d "
"AND %s AND %s "
"ORDER BY call_state, channel_uuid", /* off hook first */
listener->device_name, listener->device_instance,
line_instance_condition, call_id_condition
))) {
skinny_execute_sql_callback(listener->profile, listener->profile->sql_mutex, sql, skinny_line_get_state_callback, &helper);
switch_safe_free(sql);
}
@@ -475,13 +475,13 @@ switch_status_t skinny_tech_set_codec(private_t *tech_pvt, int force)
switch_goto_status(SWITCH_STATUS_SUCCESS, end);
}
if (strcasecmp(tech_pvt->read_impl.iananame, tech_pvt->iananame) ||
tech_pvt->read_impl.samples_per_second != tech_pvt->rm_rate ||
tech_pvt->codec_ms != (uint32_t)tech_pvt->read_impl.microseconds_per_packet / 1000) {
tech_pvt->read_impl.samples_per_second != tech_pvt->rm_rate ||
tech_pvt->codec_ms != (uint32_t)tech_pvt->read_impl.microseconds_per_packet / 1000) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(tech_pvt->session), SWITCH_LOG_DEBUG, "Changing Codec from %s@%dms to %s@%dms\n",
tech_pvt->read_impl.iananame, tech_pvt->read_impl.microseconds_per_packet / 1000,
tech_pvt->rm_encoding, tech_pvt->codec_ms);
tech_pvt->read_impl.iananame, tech_pvt->read_impl.microseconds_per_packet / 1000,
tech_pvt->rm_encoding, tech_pvt->codec_ms);
switch_core_session_lock_codec_write(tech_pvt->session);
switch_core_session_lock_codec_read(tech_pvt->session);
resetting = 1;
@@ -494,25 +494,25 @@ switch_status_t skinny_tech_set_codec(private_t *tech_pvt, int force)
}
if (switch_core_codec_init(&tech_pvt->read_codec,
tech_pvt->iananame,
tech_pvt->rm_fmtp,
tech_pvt->rm_rate,
tech_pvt->codec_ms,
1,
SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE | 0 /* TODO tech_pvt->profile->codec_flags */,
NULL, switch_core_session_get_pool(tech_pvt->session)) != SWITCH_STATUS_SUCCESS) {
tech_pvt->iananame,
tech_pvt->rm_fmtp,
tech_pvt->rm_rate,
tech_pvt->codec_ms,
1,
SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE | 0 /* TODO tech_pvt->profile->codec_flags */,
NULL, switch_core_session_get_pool(tech_pvt->session)) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(tech_pvt->session), SWITCH_LOG_ERROR, "Can't load codec?\n");
switch_goto_status(SWITCH_STATUS_FALSE, end);
}
if (switch_core_codec_init(&tech_pvt->write_codec,
tech_pvt->iananame,
tech_pvt->rm_fmtp,
tech_pvt->rm_rate,
tech_pvt->codec_ms,
1,
SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE | 0 /* TODO tech_pvt->profile->codec_flags */,
NULL, switch_core_session_get_pool(tech_pvt->session)) != SWITCH_STATUS_SUCCESS) {
tech_pvt->iananame,
tech_pvt->rm_fmtp,
tech_pvt->rm_rate,
tech_pvt->codec_ms,
1,
SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE | 0 /* TODO tech_pvt->profile->codec_flags */,
NULL, switch_core_session_get_pool(tech_pvt->session)) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(tech_pvt->session), SWITCH_LOG_ERROR, "Can't load codec?\n");
switch_goto_status(SWITCH_STATUS_FALSE, end);
}
@@ -530,9 +530,9 @@ switch_status_t skinny_tech_set_codec(private_t *tech_pvt, int force)
switch_assert(tech_pvt->read_codec.implementation);
if (switch_rtp_change_interval(tech_pvt->rtp_session,
tech_pvt->read_impl.microseconds_per_packet,
tech_pvt->read_impl.samples_per_packet
) != SWITCH_STATUS_SUCCESS) {
tech_pvt->read_impl.microseconds_per_packet,
tech_pvt->read_impl.samples_per_packet
) != SWITCH_STATUS_SUCCESS) {
switch_channel_t *channel = switch_core_session_get_channel(tech_pvt->session);
switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
@@ -549,8 +549,8 @@ switch_status_t skinny_tech_set_codec(private_t *tech_pvt, int force)
}
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(tech_pvt->session), SWITCH_LOG_DEBUG, "Set Codec %s %s/%ld %d ms %d samples\n",
"" /* TODO switch_channel_get_name(tech_pvt->channel)*/, tech_pvt->iananame, tech_pvt->rm_rate, tech_pvt->codec_ms,
tech_pvt->read_impl.samples_per_packet);
"" /* TODO switch_channel_get_name(tech_pvt->channel)*/, tech_pvt->iananame, tech_pvt->rm_rate, tech_pvt->codec_ms,
tech_pvt->read_impl.samples_per_packet);
tech_pvt->read_frame.codec = &tech_pvt->read_codec;
tech_pvt->write_codec.agreed_pt = tech_pvt->agreed_pt;
@@ -562,16 +562,16 @@ switch_status_t skinny_tech_set_codec(private_t *tech_pvt, int force)
}
/* TODO
tech_pvt->fmtp_out = switch_core_session_strdup(tech_pvt->session, tech_pvt->write_codec.fmtp_out);
*/
tech_pvt->fmtp_out = switch_core_session_strdup(tech_pvt->session, tech_pvt->write_codec.fmtp_out);
*/
/* TODO
if (switch_rtp_ready(tech_pvt->rtp_session)) {
switch_rtp_set_default_payload(tech_pvt->rtp_session, tech_pvt->pt);
}
*/
if (switch_rtp_ready(tech_pvt->rtp_session)) {
switch_rtp_set_default_payload(tech_pvt->rtp_session, tech_pvt->pt);
}
*/
end:
end:
if (resetting) {
switch_core_session_unlock_codec_write(tech_pvt->session);
switch_core_session_unlock_codec_read(tech_pvt->session);
@@ -600,7 +600,7 @@ void tech_init(private_t *tech_pvt, skinny_profile_t *profile, switch_core_sessi
State methods they get called when the state changes to the specific state
returning SWITCH_STATUS_SUCCESS tells the core to execute the standard state method next
so if you fully implement the state you can return SWITCH_STATUS_FALSE to skip it.
*/
*/
switch_status_t channel_on_init(switch_core_session_t *session)
{
switch_channel_t *channel = switch_core_session_get_channel(session);
@@ -641,23 +641,23 @@ int channel_on_routing_callback(void *pArg, int argc, char **argv, char **column
skinny_profile_find_listener_by_device_name_and_instance(helper->tech_pvt->profile, device_name, device_instance, &listener);
if(listener) {
if(!strcmp(device_name, helper->listener->device_name)
&& (device_instance == helper->listener->device_instance)
&& (line_instance == helper->line_instance)) {/* the calling line */
if(!strcmp(device_name, helper->listener->device_name)
&& (device_instance == helper->listener->device_instance)
&& (line_instance == helper->line_instance)) {/* the calling line */
helper->tech_pvt->caller_profile->dialplan = switch_core_strdup(helper->tech_pvt->caller_profile->pool, listener->profile->dialplan);
helper->tech_pvt->caller_profile->context = switch_core_strdup(helper->tech_pvt->caller_profile->pool, listener->profile->context);
send_dialed_number(listener, helper->tech_pvt->caller_profile->destination_number, line_instance, helper->tech_pvt->call_id);
skinny_line_set_state(listener, line_instance, helper->tech_pvt->call_id, SKINNY_PROCEED);
skinny_session_send_call_info(helper->tech_pvt->session, listener, line_instance);
skinny_session_ring_out(helper->tech_pvt->session, listener, line_instance);
} else {
} else {
send_set_lamp(listener, SKINNY_BUTTON_LINE, line_instance, SKINNY_LAMP_ON);
skinny_line_set_state(listener, line_instance, helper->tech_pvt->call_id, SKINNY_IN_USE_REMOTELY);
send_select_soft_keys(listener, line_instance, helper->tech_pvt->call_id, SKINNY_KEY_SET_IN_USE_HINT, 0xffff);
send_display_prompt_status(listener, 0, SKINNY_DISP_IN_USE_REMOTE,
line_instance, helper->tech_pvt->call_id);
line_instance, helper->tech_pvt->call_id);
skinny_session_send_call_info(helper->tech_pvt->session, listener, line_instance);
}
}
}
return 0;
}
@@ -673,15 +673,15 @@ switch_status_t channel_on_routing(switch_core_session_t *session)
struct channel_on_routing_helper helper = {0};
if(switch_test_flag(tech_pvt, TFLAG_FORCE_ROUTE)) {
action = SKINNY_ACTION_ROUTE;
action = SKINNY_ACTION_PROCESS;
} else {
action = skinny_session_dest_match_pattern(session, &data);
}
switch(action) {
case SKINNY_ACTION_ROUTE:
case SKINNY_ACTION_PROCESS:
skinny_profile_find_listener_by_device_name_and_instance(tech_pvt->profile,
switch_channel_get_variable(channel, "skinny_device_name"),
atoi(switch_channel_get_variable(channel, "skinny_device_instance")), &listener);
switch_channel_get_variable(channel, "skinny_device_name"),
atoi(switch_channel_get_variable(channel, "skinny_device_instance")), &listener);
if (listener) {
helper.tech_pvt = tech_pvt;
helper.listener = listener;
@@ -689,8 +689,8 @@ switch_status_t channel_on_routing(switch_core_session_t *session)
skinny_session_walk_lines(tech_pvt->profile, switch_core_session_get_uuid(session), channel_on_routing_callback, &helper);
} else {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "Could not find listener %s:%s for Channel %s\n",
switch_channel_get_variable(channel, "skinny_device_name"), switch_channel_get_variable(channel, "skinny_device_instance"),
switch_channel_get_name(channel));
switch_channel_get_variable(channel, "skinny_device_name"), switch_channel_get_variable(channel, "skinny_device_instance"),
switch_channel_get_name(channel));
}
/* Future bridge should go straight */
switch_set_flag_locked(tech_pvt, TFLAG_FORCE_ROUTE);
@@ -777,16 +777,16 @@ int channel_on_hangup_callback(void *pArg, int argc, char **argv, char **columnN
send_set_lamp(listener, SKINNY_BUTTON_LINE, line_instance, SKINNY_LAMP_OFF);
switch (helper->cause) {
case SWITCH_CAUSE_UNALLOCATED_NUMBER:
send_start_tone(listener, SKINNY_TONE_REORDER, 0, line_instance, call_id);
send_start_tone(listener, SKINNY_TONE_REORDER, 0, line_instance, call_id);
skinny_session_send_call_info(helper->tech_pvt->session, listener, line_instance);
send_display_prompt_status(listener, 0, SKINNY_DISP_UNKNOWN_NUMBER, line_instance, call_id);
break;
case SWITCH_CAUSE_USER_BUSY:
send_start_tone(listener, SKINNY_TONE_BUSYTONE, 0, line_instance, call_id);
send_start_tone(listener, SKINNY_TONE_BUSYTONE, 0, line_instance, call_id);
send_display_prompt_status(listener, 0, SKINNY_DISP_BUSY, line_instance, call_id);
break;
break;
case SWITCH_CAUSE_NORMAL_CLEARING:
send_clear_prompt_status(listener, line_instance, call_id);
send_clear_prompt_status(listener, line_instance, call_id);
break;
default:
send_display_prompt_status(listener, 0, switch_channel_cause2str(helper->cause), line_instance, call_id);
@@ -821,9 +821,9 @@ switch_status_t channel_on_hangup(switch_core_session_t *session)
skinny_session_walk_lines(tech_pvt->profile, switch_core_session_get_uuid(session), channel_on_hangup_callback, &helper);
if ((sql = switch_mprintf(
"DELETE FROM skinny_active_lines WHERE channel_uuid='%s'",
switch_core_session_get_uuid(session)
))) {
"DELETE FROM skinny_active_lines WHERE channel_uuid='%s'",
switch_core_session_get_uuid(session)
))) {
skinny_execute_sql(tech_pvt->profile, sql, tech_pvt->profile->sql_mutex);
switch_safe_free(sql);
}
@@ -836,16 +836,16 @@ switch_status_t channel_kill_channel(switch_core_session_t *session, int sig)
private_t *tech_pvt = switch_core_session_get_private(session);
switch (sig) {
case SWITCH_SIG_KILL:
switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING);
break;
case SWITCH_SIG_BREAK:
if (switch_rtp_ready(tech_pvt->rtp_session)) {
switch_rtp_break(tech_pvt->rtp_session);
}
break;
default:
break;
case SWITCH_SIG_KILL:
switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING);
break;
case SWITCH_SIG_BREAK:
if (switch_rtp_ready(tech_pvt->rtp_session)) {
switch_rtp_break(tech_pvt->rtp_session);
}
break;
default:
break;
}
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s CHANNEL KILL %d\n", switch_channel_get_name(channel), sig);
@@ -968,8 +968,8 @@ switch_status_t channel_answer_channel(switch_core_session_t *session)
listener_t *listener = NULL;
skinny_profile_find_listener_by_device_name_and_instance(tech_pvt->profile,
switch_channel_get_variable(channel, "skinny_device_name"),
atoi(switch_channel_get_variable(channel, "skinny_device_instance")), &listener);
switch_channel_get_variable(channel, "skinny_device_name"),
atoi(switch_channel_get_variable(channel, "skinny_device_instance")), &listener);
if (listener) {
int x = 0;
skinny_session_start_media(session, listener, atoi(switch_channel_get_variable(channel, "skinny_line_instance")));
@@ -978,13 +978,13 @@ switch_status_t channel_answer_channel(switch_core_session_t *session)
switch_cond_next();
if (++x > 1000) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "Wait tooo long to answer %s:%s\n",
switch_channel_get_variable(channel, "skinny_device_name"), switch_channel_get_variable(channel, "skinny_device_instance"));
switch_channel_get_variable(channel, "skinny_device_name"), switch_channel_get_variable(channel, "skinny_device_instance"));
return SWITCH_STATUS_FALSE;
}
}
} else {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "Unable to find listener to answer %s:%s\n",
switch_channel_get_variable(channel, "skinny_device_name"), switch_channel_get_variable(channel, "skinny_device_instance"));
switch_channel_get_variable(channel, "skinny_device_name"), switch_channel_get_variable(channel, "skinny_device_instance"));
}
return SWITCH_STATUS_SUCCESS;
}
@@ -995,24 +995,24 @@ switch_status_t channel_receive_message(switch_core_session_t *session, switch_c
private_t *tech_pvt = switch_core_session_get_private(session);
switch (msg->message_id) {
case SWITCH_MESSAGE_INDICATE_ANSWER:
switch_clear_flag_locked(tech_pvt, TFLAG_EARLY_MEDIA);
return channel_answer_channel(session);
case SWITCH_MESSAGE_INDICATE_DISPLAY:
skinny_session_send_call_info_all(session);
return SWITCH_STATUS_SUCCESS;
case SWITCH_MESSAGE_INDICATE_PROGRESS:
if (!switch_test_flag(tech_pvt, TFLAG_EARLY_MEDIA)) {
/* early media */
switch_set_flag_locked(tech_pvt, TFLAG_EARLY_MEDIA);
case SWITCH_MESSAGE_INDICATE_ANSWER:
switch_clear_flag_locked(tech_pvt, TFLAG_EARLY_MEDIA);
return channel_answer_channel(session);
}
return SWITCH_STATUS_SUCCESS;
default:
return SWITCH_STATUS_SUCCESS;
case SWITCH_MESSAGE_INDICATE_DISPLAY:
skinny_session_send_call_info_all(session);
return SWITCH_STATUS_SUCCESS;
case SWITCH_MESSAGE_INDICATE_PROGRESS:
if (!switch_test_flag(tech_pvt, TFLAG_EARLY_MEDIA)) {
/* early media */
switch_set_flag_locked(tech_pvt, TFLAG_EARLY_MEDIA);
return channel_answer_channel(session);
}
return SWITCH_STATUS_SUCCESS;
default:
return SWITCH_STATUS_SUCCESS;
}
@@ -1020,10 +1020,10 @@ switch_status_t channel_receive_message(switch_core_session_t *session, switch_c
/* Make sure when you have 2 sessions in the same scope that you pass the appropriate one to the routines
that allocate memory or you will have 1 channel with memory allocated from another channel's pool!
*/
*/
switch_call_cause_t channel_outgoing_channel(switch_core_session_t *session, switch_event_t *var_event,
switch_caller_profile_t *outbound_profile,
switch_core_session_t **new_session, switch_memory_pool_t **pool, switch_originate_flag_t flags, switch_call_cause_t *cancel_cause)
switch_caller_profile_t *outbound_profile,
switch_core_session_t **new_session, switch_memory_pool_t **pool, switch_originate_flag_t flags, switch_call_cause_t *cancel_cause)
{
switch_call_cause_t cause = SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
switch_core_session_t *nsession = NULL;
@@ -1082,13 +1082,13 @@ switch_call_cause_t channel_outgoing_channel(switch_core_session_t *session, swi
tech_pvt->caller_profile = caller_profile;
if ((sql = switch_mprintf(
"INSERT INTO skinny_active_lines "
"(device_name, device_instance, line_instance, channel_uuid, call_id, call_state) "
"SELECT device_name, device_instance, line_instance, '%s', %d, %d "
"FROM skinny_lines "
"WHERE value='%s'",
switch_core_session_get_uuid(nsession), tech_pvt->call_id, SKINNY_ON_HOOK, dest
))) {
"INSERT INTO skinny_active_lines "
"(device_name, device_instance, line_instance, channel_uuid, call_id, call_state) "
"SELECT device_name, device_instance, line_instance, '%s', %d, %d "
"FROM skinny_lines "
"WHERE value='%s'",
switch_core_session_get_uuid(nsession), tech_pvt->call_id, SKINNY_ON_HOOK, dest
))) {
skinny_execute_sql(profile, sql, profile->sql_mutex);
switch_safe_free(sql);
}
@@ -1098,7 +1098,7 @@ switch_call_cause_t channel_outgoing_channel(switch_core_session_t *session, swi
switch_channel_set_variable(switch_core_session_get_channel(session), SWITCH_SIGNAL_BOND_VARIABLE, switch_core_session_get_uuid(nsession));
switch_channel_set_variable(nchannel, SWITCH_SIGNAL_BOND_VARIABLE, switch_core_session_get_uuid(session));
}
cause = skinny_ring_lines(tech_pvt, session);
if(cause != SWITCH_CAUSE_SUCCESS) {
@@ -1116,7 +1116,7 @@ switch_call_cause_t channel_outgoing_channel(switch_core_session_t *session, swi
cause = SWITCH_CAUSE_SUCCESS;
goto done;
error:
error:
if (nsession) {
switch_core_session_destroy(&nsession);
}
@@ -1126,7 +1126,7 @@ switch_call_cause_t channel_outgoing_channel(switch_core_session_t *session, swi
}
done:
done:
if (profile) {
if (cause == SWITCH_CAUSE_SUCCESS) {
@@ -1267,37 +1267,37 @@ static void flush_listener(listener_t *listener)
char *sql;
if ((sql = switch_mprintf(
"SELECT '%q', value, '%q', '%q', '%d' "
"FROM skinny_lines "
"WHERE device_name='%s' AND device_instance=%d "
"ORDER BY position",
profile->name, profile->domain, listener->device_name, listener->device_instance,
listener->device_name, listener->device_instance
))) {
"SELECT '%q', value, '%q', '%q', '%d' "
"FROM skinny_lines "
"WHERE device_name='%s' AND device_instance=%d "
"ORDER BY position",
profile->name, profile->domain, listener->device_name, listener->device_instance,
listener->device_name, listener->device_instance
))) {
skinny_execute_sql_callback(profile, profile->sql_mutex, sql, flush_listener_callback, NULL);
switch_safe_free(sql);
}
if ((sql = switch_mprintf(
"DELETE FROM skinny_devices "
"WHERE name='%s' and instance=%d",
listener->device_name, listener->device_instance))) {
"DELETE FROM skinny_devices "
"WHERE name='%s' and instance=%d",
listener->device_name, listener->device_instance))) {
skinny_execute_sql(profile, sql, profile->sql_mutex);
switch_safe_free(sql);
}
if ((sql = switch_mprintf(
"DELETE FROM skinny_lines "
"WHERE device_name='%s' and device_instance=%d",
listener->device_name, listener->device_instance))) {
"DELETE FROM skinny_lines "
"WHERE device_name='%s' and device_instance=%d",
listener->device_name, listener->device_instance))) {
skinny_execute_sql(profile, sql, profile->sql_mutex);
switch_safe_free(sql);
}
if ((sql = switch_mprintf(
"DELETE FROM skinny_buttons "
"WHERE device_name='%s' and device_instance=%d",
listener->device_name, listener->device_instance))) {
"DELETE FROM skinny_buttons "
"WHERE device_name='%s' and device_instance=%d",
listener->device_name, listener->device_instance))) {
skinny_execute_sql(profile, sql, profile->sql_mutex);
switch_safe_free(sql);
}
@@ -1348,8 +1348,8 @@ switch_status_t dump_device(skinny_profile_t *profile, const char *device_name,
{
char *sql;
if ((sql = switch_mprintf("SELECT name, user_id, instance, ip, type, max_streams, port, codec_string, headset, handset, speaker "
"FROM skinny_devices WHERE name='%s'",
device_name))) {
"FROM skinny_devices WHERE name='%s'",
device_name))) {
skinny_execute_sql_callback(profile, profile->sql_mutex, sql, dump_device_callback, stream);
switch_safe_free(sql);
}
@@ -1372,7 +1372,7 @@ static void close_socket(switch_socket_t **sock, skinny_profile_t *profile)
static switch_status_t kill_listener(listener_t *listener, void *pvt)
{
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Killing listener %s:%d.\n",
listener->device_name, listener->device_instance);
listener->device_name, listener->device_instance);
switch_clear_flag(listener, LFLAG_RUNNING);
close_socket(&listener->sock, listener->profile);
return SWITCH_STATUS_SUCCESS;
@@ -1435,7 +1435,7 @@ static void *SWITCH_THREAD_FUNC listener_run(switch_thread_t *thread, void *obj)
switch(status) {
case SWITCH_STATUS_TIMEOUT:
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Communication Time Out with %s:%d.\n",
listener->remote_ip, listener->remote_port);
listener->remote_ip, listener->remote_port);
if(listener->expire_time < switch_epoch_time_now(NULL)) {
switch_event_t *event = NULL;
@@ -1446,7 +1446,7 @@ static void *SWITCH_THREAD_FUNC listener_run(switch_thread_t *thread, void *obj)
break;
default:
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Communication Error with %s:%d.\n",
listener->remote_ip, listener->remote_port);
listener->remote_ip, listener->remote_port);
}
switch_clear_flag_locked(listener, LFLAG_RUNNING);
break;
@@ -1470,7 +1470,7 @@ static void *SWITCH_THREAD_FUNC listener_run(switch_thread_t *thread, void *obj)
if (listener->profile->debug > 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Communication Complete with %s:%d.\n",
listener->remote_ip, listener->remote_port);
listener->remote_ip, listener->remote_port);
}
switch_thread_rwlock_wrlock(listener->rwlock);
@@ -1484,7 +1484,7 @@ static void *SWITCH_THREAD_FUNC listener_run(switch_thread_t *thread, void *obj)
if (listener->profile->debug > 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Communication Closed with %s:%d.\n",
listener->remote_ip, listener->remote_port);
listener->remote_ip, listener->remote_port);
}
if(destroy_pool == 0) {
@@ -1559,7 +1559,7 @@ new_socket:
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Socket up listening on %s:%u\n", profile->ip, profile->port);
break;
sock_fail:
sock_fail:
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Socket Error! Could not listen on %s:%u\n", profile->ip, profile->port);
switch_yield(100000);
}
@@ -1622,7 +1622,7 @@ new_socket:
}
end:
end:
close_socket(&profile->sock, profile);
@@ -1635,7 +1635,7 @@ new_socket:
}
fail:
fail:
return NULL;
}
@@ -1677,7 +1677,7 @@ switch_status_t skinny_profile_set(skinny_profile_t *profile, const char *var, c
if (profile->sock && !strcasecmp(var, "odbc-dsn")) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"Skinny profile setting 'odbc-dsn' can't be changed while running\n");
"Skinny profile setting 'odbc-dsn' can't be changed while running\n");
return SWITCH_STATUS_FALSE;
}
@@ -1758,7 +1758,7 @@ static switch_status_t load_skinny_config(void)
switch_xml_t xsettings, xdevice_types, xsoft_key_set_sets;
if (zstr(profile_name)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"<profile> is missing name attribute\n");
"<profile> is missing name attribute\n");
continue;
}
if ((xsettings = switch_xml_child(xprofile, "settings"))) {
@@ -1767,11 +1767,11 @@ static switch_status_t load_skinny_config(void)
switch_core_db_t *db;
skinny_profile_t *profile = NULL;
switch_xml_t param;
if (switch_core_new_memory_pool(&profile_pool) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "OH OH no pool\n");
return SWITCH_STATUS_TERM;
}
if (switch_core_new_memory_pool(&profile_pool) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "OH OH no pool\n");
return SWITCH_STATUS_TERM;
}
profile = switch_core_alloc(profile_pool, sizeof(skinny_profile_t));
profile->pool = profile_pool;
profile->name = switch_core_strdup(profile->pool, profile_name);
@@ -1780,17 +1780,17 @@ static switch_status_t load_skinny_config(void)
switch_mutex_init(&profile->listener_mutex, SWITCH_MUTEX_NESTED, profile->pool);
switch_mutex_init(&profile->sock_mutex, SWITCH_MUTEX_NESTED, profile->pool);
switch_mutex_init(&profile->flag_mutex, SWITCH_MUTEX_NESTED, profile->pool);
for (param = switch_xml_child(xsettings, "param"); param; param = param->next) {
char *var = (char *) switch_xml_attr_soft(param, "name");
char *val = (char *) switch_xml_attr_soft(param, "value");
if (skinny_profile_set(profile, var, val) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING,
"Unable to set skinny setting '%s'. Does it exists?\n", var);
"Unable to set skinny setting '%s'. Does it exists?\n", var);
}
} /* param */
if (!profile->dialplan) {
skinny_profile_set(profile, "dialplan","XML");
}
@@ -1838,8 +1838,8 @@ static switch_status_t load_skinny_config(void)
}
if (soft_key_set_id > 15) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING,
"soft-key-set name '%s' is greater than 15 in soft-key-set-set '%s' in profile %s.\n",
switch_xml_attr_soft(xsoft_key_set, "name"), soft_key_set_set_name, profile->name);
"soft-key-set name '%s' is greater than 15 in soft-key-set-set '%s' in profile %s.\n",
switch_xml_attr_soft(xsoft_key_set, "name"), soft_key_set_set_name, profile->name);
continue;
}
for (string_pos = 0; string_pos <= string_len; string_pos++) {
@@ -1847,8 +1847,8 @@ static switch_status_t load_skinny_config(void)
val[string_pos] = '\0';
if (field_no > 15) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING,
"soft-key-set name '%s' is limited to 16 buttons in soft-key-set-set '%s' in profile %s.\n",
switch_xml_attr_soft(xsoft_key_set, "name"), soft_key_set_set_name, profile->name);
"soft-key-set name '%s' is limited to 16 buttons in soft-key-set-set '%s' in profile %s.\n",
switch_xml_attr_soft(xsoft_key_set, "name"), soft_key_set_set_name, profile->name);
break;
}
message->data.soft_key_set.soft_key_set[soft_key_set_id].soft_key_template_index[field_no++] = skinny_str2soft_key_event(&val[start]);
@@ -1857,28 +1857,28 @@ static switch_status_t load_skinny_config(void)
}
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING,
"Unknown soft-key-set name '%s' in soft-key-set-set '%s' in profile %s.\n",
switch_xml_attr_soft(xsoft_key_set, "name"), soft_key_set_set_name, profile->name);
"Unknown soft-key-set name '%s' in soft-key-set-set '%s' in profile %s.\n",
switch_xml_attr_soft(xsoft_key_set, "name"), soft_key_set_set_name, profile->name);
}
} /* soft-key-set */
switch_core_hash_insert(profile->soft_key_set_sets_hash, soft_key_set_set_name, message);
switch_core_hash_insert(profile->soft_key_set_sets_hash, soft_key_set_set_name, message);
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING,
"<soft-key-set-set> is missing a name attribute in profile %s.\n", profile->name);
"<soft-key-set-set> is missing a name attribute in profile %s.\n", profile->name);
}
} /* soft-key-set-set */
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING,
"<soft-key-set-sets> is missing in profile %s.\n", profile->name);
"<soft-key-set-sets> is missing in profile %s.\n", profile->name);
} /* soft-key-set-sets */
if (!switch_core_hash_find(profile->soft_key_set_sets_hash, "default")) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"Profile %s doesn't have a default <soft-key-set-set>. Profile ignored.\n", profile->name);
"Profile %s doesn't have a default <soft-key-set-set>. Profile ignored.\n", profile->name);
switch_core_destroy_memory_pool(&profile_pool);
continue;
}
/* Device types */
switch_core_hash_init(&profile->device_type_params_hash, profile->pool);
if ((xdevice_types = switch_xml_child(xprofile, "device-types"))) {
@@ -1893,13 +1893,13 @@ static switch_status_t load_skinny_config(void)
char *val = (char *) switch_xml_attr_soft(param, "value");
if (!strcasecmp(var, "firmware-version")) {
strncpy(params->firmware_version, val, 16);
strncpy(params->firmware_version, val, 16);
}
} /* param */
switch_core_hash_insert(profile->device_type_params_hash, id_str, params);
switch_core_hash_insert(profile->device_type_params_hash, id_str, params);
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING,
"Unknow device type %s in profile %s.\n", switch_xml_attr_soft(xdevice_type, "id"), profile->name);
"Unknow device type %s in profile %s.\n", switch_xml_attr_soft(xdevice_type, "id"), profile->name);
}
}
}
@@ -1936,7 +1936,7 @@ static switch_status_t load_skinny_config(void)
}
switch_core_db_close(db);
}
skinny_execute_sql_callback(profile, profile->sql_mutex, "DELETE FROM skinny_devices", NULL, NULL);
skinny_execute_sql_callback(profile, profile->sql_mutex, "DELETE FROM skinny_lines", NULL, NULL);
skinny_execute_sql_callback(profile, profile->sql_mutex, "DELETE FROM skinny_buttons", NULL, NULL);
@@ -1945,13 +1945,13 @@ static switch_status_t load_skinny_config(void)
skinny_profile_respawn(profile, 0);
/* Register profile */
switch_mutex_lock(globals.mutex);
switch_core_hash_insert(globals.profile_hash, profile->name, profile);
switch_mutex_unlock(globals.mutex);
switch_mutex_lock(globals.mutex);
switch_core_hash_insert(globals.profile_hash, profile->name, profile);
switch_mutex_unlock(globals.mutex);
profile = NULL;
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"Settings are missing from profile %s.\n", profile_name);
"Settings are missing from profile %s.\n", profile_name);
} /* settings */
} /* profile */
}
@@ -1991,26 +1991,26 @@ static void skinny_user_to_device_event_handler(switch_event_t *event)
case USER_TO_DEVICE_DATA_MESSAGE:
data_length = strlen(data); /* we ignore data_length sent */
send_data(listener, message_type,
application_id, line_instance, call_id, transaction_id, data_length,
data);
application_id, line_instance, call_id, transaction_id, data_length,
data);
case USER_TO_DEVICE_DATA_VERSION1_MESSAGE:
data_length = strlen(data); /* we ignore data_length sent */
send_extended_data(listener, message_type,
application_id, line_instance, call_id, transaction_id, data_length,
sequence_flag, display_priority, conference_id, app_instance_id, routing_id,
data);
application_id, line_instance, call_id, transaction_id, data_length,
sequence_flag, display_priority, conference_id, app_instance_id, routing_id,
data);
break;
default:
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING,
"Incorrect message type %s (%d).\n", skinny_message_type2str(message_type), message_type);
"Incorrect message type %s (%d).\n", skinny_message_type2str(message_type), message_type);
}
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING,
"Device %s:%d in profile '%s' not found.\n", device_name, device_instance, profile_name);
"Device %s:%d in profile '%s' not found.\n", device_name, device_instance, profile_name);
}
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING,
"Profile '%s' not found.\n", profile_name);
"Profile '%s' not found.\n", profile_name);
}
}
@@ -2032,41 +2032,41 @@ static void skinny_call_state_event_handler(switch_event_t *event)
if ((profile = skinny_find_profile(profile_name))) {
skinny_profile_find_listener_by_device_name_and_instance(profile, device_name, device_instance, &listener);
if(listener) {
if(line_instance > 0) {
line_instance_condition = switch_mprintf("line_instance=%d", line_instance);
} else {
line_instance_condition = switch_mprintf("1=1");
}
switch_assert(line_instance_condition);
if(call_id > 0) {
call_id_condition = switch_mprintf("call_id=%d", call_id);
} else {
call_id_condition = switch_mprintf("1=1");
}
switch_assert(call_id_condition);
if(listener) {
if(line_instance > 0) {
line_instance_condition = switch_mprintf("line_instance=%d", line_instance);
} else {
line_instance_condition = switch_mprintf("1=1");
}
switch_assert(line_instance_condition);
if(call_id > 0) {
call_id_condition = switch_mprintf("call_id=%d", call_id);
} else {
call_id_condition = switch_mprintf("1=1");
}
switch_assert(call_id_condition);
if ((sql = switch_mprintf(
"UPDATE skinny_active_lines "
"SET call_state=%d "
"WHERE device_name='%s' AND device_instance=%d "
"AND %s AND %s",
call_state,
listener->device_name, listener->device_instance,
line_instance_condition, call_id_condition
))) {
skinny_execute_sql(listener->profile, sql, listener->profile->sql_mutex);
switch_safe_free(sql);
}
switch_safe_free(line_instance_condition);
switch_safe_free(call_id_condition);
if ((sql = switch_mprintf(
"UPDATE skinny_active_lines "
"SET call_state=%d "
"WHERE device_name='%s' AND device_instance=%d "
"AND %s AND %s",
call_state,
listener->device_name, listener->device_instance,
line_instance_condition, call_id_condition
))) {
skinny_execute_sql(listener->profile, sql, listener->profile->sql_mutex);
switch_safe_free(sql);
}
switch_safe_free(line_instance_condition);
switch_safe_free(call_id_condition);
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING,
"Device %s:%d in profile '%s' not found.\n", device_name, device_instance, profile_name);
"Device %s:%d in profile '%s' not found.\n", device_name, device_instance, profile_name);
}
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING,
"Profile '%s' not found.\n", profile_name);
"Profile '%s' not found.\n", profile_name);
}
}
}
@@ -2089,7 +2089,7 @@ int skinny_message_waiting_event_handler_callback(void *pArg, int argc, char **a
listener_t *listener = NULL;
skinny_profile_find_listener_by_device_name_and_instance(helper->profile,
device_name, device_instance, &listener);
device_name, device_instance, &listener);
if (listener) {
if (helper->yn == SWITCH_TRUE) {
@@ -2143,15 +2143,15 @@ static void skinny_message_waiting_event_handler(switch_event_t *event)
count_str = switch_event_get_header(event, "mwi-voice-message");
if ((sql = switch_mprintf(
"SELECT device_name, device_instance FROM skinny_lines "
"WHERE value='%s' AND line_instance=1", user))) {
"SELECT device_name, device_instance FROM skinny_lines "
"WHERE value='%s' AND line_instance=1", user))) {
struct skinny_message_waiting_event_handler_helper helper = {0};
helper.profile = profile;
helper.yn = switch_true(yn);
if (count_str) {
sscanf(count_str,"%d/%d (%d/%d)",
&helper.total_new_messages, &helper.total_saved_messages,
&helper.total_new_urgent_messages, &helper.total_saved_urgent_messages);
&helper.total_new_messages, &helper.total_saved_messages,
&helper.total_new_urgent_messages, &helper.total_saved_urgent_messages);
}
skinny_execute_sql_callback(profile, profile->sql_mutex, sql, skinny_message_waiting_event_handler_callback, &helper);
switch_safe_free(sql);
@@ -2285,7 +2285,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_skinny_load)
switch_hash_this(hi, NULL, NULL, &val);
profile = (skinny_profile_t *) val;
launch_skinny_profile_thread(profile);
}
switch_mutex_unlock(globals.mutex);
@@ -2303,7 +2303,7 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_skinny_shutdown)
int sanity = 0;
skinny_api_unregister();
/* release events */
switch_event_unbind(&globals.user_to_device_node);
switch_event_unbind(&globals.call_state_node);
+62 -62
View File
@@ -48,66 +48,66 @@
#define SKINNY_EVENT_DEVICE_TO_USER "skinny::device_to_user"
struct skinny_globals {
int running;
switch_memory_pool_t *pool;
switch_mutex_t *mutex;
switch_hash_t *profile_hash;
switch_event_node_t *user_to_device_node;
switch_event_node_t *call_state_node;
switch_event_node_t *message_waiting_node;
switch_event_node_t *trap_node;
int auto_restart;
int running;
switch_memory_pool_t *pool;
switch_mutex_t *mutex;
switch_hash_t *profile_hash;
switch_event_node_t *user_to_device_node;
switch_event_node_t *call_state_node;
switch_event_node_t *message_waiting_node;
switch_event_node_t *trap_node;
int auto_restart;
};
typedef struct skinny_globals skinny_globals_t;
extern skinny_globals_t globals;
typedef enum {
PFLAG_LISTENER_READY = (1 << 0),
PFLAG_SHOULD_RESPAWN = (1 << 1),
PFLAG_RESPAWN = (1 << 2),
PFLAG_LISTENER_READY = (1 << 0),
PFLAG_SHOULD_RESPAWN = (1 << 1),
PFLAG_RESPAWN = (1 << 2),
} profile_flag_t;
struct skinny_profile {
/* prefs */
char *name;
char *domain;
char *ip;
unsigned int port;
char *dialplan;
char *context;
char *patterns_dialplan;
char *patterns_context;
uint32_t keep_alive;
char date_format[6];
int debug;
/* prefs */
char *name;
char *domain;
char *ip;
unsigned int port;
char *dialplan;
char *context;
char *patterns_dialplan;
char *patterns_context;
uint32_t keep_alive;
char date_format[6];
int debug;
int auto_restart;
switch_hash_t *soft_key_set_sets_hash;
switch_hash_t *device_type_params_hash;
/* db */
char *dbname;
char *odbc_dsn;
char *odbc_user;
char *odbc_pass;
switch_odbc_handle_t *master_odbc;
switch_mutex_t *sql_mutex;
/* stats */
uint32_t ib_calls;
uint32_t ob_calls;
uint32_t ib_failed_calls;
uint32_t ob_failed_calls;
/* listener */
int listener_threads;
switch_mutex_t *listener_mutex;
switch_socket_t *sock;
switch_mutex_t *sock_mutex;
struct listener *listeners;
int flags;
switch_mutex_t *flag_mutex;
/* call id */
uint32_t next_call_id;
/* others */
switch_memory_pool_t *pool;
switch_hash_t *soft_key_set_sets_hash;
switch_hash_t *device_type_params_hash;
/* db */
char *dbname;
char *odbc_dsn;
char *odbc_user;
char *odbc_pass;
switch_odbc_handle_t *master_odbc;
switch_mutex_t *sql_mutex;
/* stats */
uint32_t ib_calls;
uint32_t ob_calls;
uint32_t ib_failed_calls;
uint32_t ob_failed_calls;
/* listener */
int listener_threads;
switch_mutex_t *listener_mutex;
switch_socket_t *sock;
switch_mutex_t *sock_mutex;
struct listener *listeners;
int flags;
switch_mutex_t *flag_mutex;
/* call id */
uint32_t next_call_id;
/* others */
switch_memory_pool_t *pool;
};
typedef struct skinny_profile skinny_profile_t;
@@ -117,7 +117,7 @@ struct skinny_device_type_params {
typedef struct skinny_device_type_params skinny_device_type_params_t;
typedef enum {
SKINNY_ACTION_ROUTE,
SKINNY_ACTION_PROCESS,
SKINNY_ACTION_DROP,
SKINNY_ACTION_WAIT
} skinny_action_t;
@@ -127,7 +127,7 @@ typedef enum {
/*****************************************************************************/
typedef enum {
LFLAG_RUNNING = (1 << 0),
LFLAG_RUNNING = (1 << 0),
} listener_flag_t;
#define SKINNY_MAX_LINES 42
@@ -161,25 +161,25 @@ typedef switch_status_t (*skinny_listener_callback_func_t) (listener_t *listener
/* CHANNEL TYPES */
/*****************************************************************************/
typedef enum {
TFLAG_FORCE_ROUTE = (1 << 0),
TFLAG_EARLY_MEDIA = (1 << 1),
TFLAG_IO = (1 << 2),
TFLAG_READING = (1 << 3),
TFLAG_WRITING = (1 << 4)
TFLAG_FORCE_ROUTE = (1 << 0),
TFLAG_EARLY_MEDIA = (1 << 1),
TFLAG_IO = (1 << 2),
TFLAG_READING = (1 << 3),
TFLAG_WRITING = (1 << 4)
} TFLAGS;
typedef enum {
GFLAG_MY_CODEC_PREFS = (1 << 0)
GFLAG_MY_CODEC_PREFS = (1 << 0)
} GFLAGS;
struct private_object {
unsigned int flags;
switch_mutex_t *flag_mutex;
switch_frame_t read_frame;
unsigned char databuf[SWITCH_RECOMMENDED_BUFFER_SIZE];
switch_core_session_t *session;
switch_caller_profile_t *caller_profile;
switch_mutex_t *mutex;
switch_mutex_t *flag_mutex;
/* identification */
skinny_profile_t *profile;
@@ -236,7 +236,7 @@ void profile_walk_listeners(skinny_profile_t *profile, skinny_listener_callback_
switch_cache_db_handle_t *skinny_get_db_handle(skinny_profile_t *profile);
switch_status_t skinny_execute_sql(skinny_profile_t *profile, char *sql, switch_mutex_t *mutex);
switch_bool_t skinny_execute_sql_callback(skinny_profile_t *profile,
switch_mutex_t *mutex, char *sql, switch_core_db_callback_func_t callback, void *pdata);
switch_mutex_t *mutex, char *sql, switch_core_db_callback_func_t callback, void *pdata);
/*****************************************************************************/
/* LISTENER FUNCTIONS */
@@ -261,8 +261,8 @@ switch_status_t channel_on_routing(switch_core_session_t *session);
switch_status_t channel_on_exchange_media(switch_core_session_t *session);
switch_status_t channel_on_soft_execute(switch_core_session_t *session);
switch_call_cause_t channel_outgoing_channel(switch_core_session_t *session, switch_event_t *var_event,
switch_caller_profile_t *outbound_profile,
switch_core_session_t **new_session, switch_memory_pool_t **pool, switch_originate_flag_t flags, switch_call_cause_t *cancel_cause);
switch_caller_profile_t *outbound_profile,
switch_core_session_t **new_session, switch_memory_pool_t **pool, switch_originate_flag_t flags, switch_call_cause_t *cancel_cause);
switch_status_t channel_read_frame(switch_core_session_t *session, switch_frame_t **frame, switch_io_flag_t flags, int stream_id);
switch_status_t channel_write_frame(switch_core_session_t *session, switch_frame_t *frame, switch_io_flag_t flags, int stream_id);
switch_status_t channel_kill_channel(switch_core_session_t *session, int sig);
+349 -349
View File
@@ -41,202 +41,202 @@
static switch_status_t skinny_api_list_profiles(const char *line, const char *cursor, switch_console_callback_match_t **matches)
{
switch_console_callback_match_t *my_matches = NULL;
switch_status_t status = SWITCH_STATUS_FALSE;
switch_hash_index_t *hi;
void *val;
skinny_profile_t *profile;
switch_console_callback_match_t *my_matches = NULL;
switch_status_t status = SWITCH_STATUS_FALSE;
switch_hash_index_t *hi;
void *val;
skinny_profile_t *profile;
/* walk profiles */
switch_mutex_lock(globals.mutex);
for (hi = switch_hash_first(NULL, globals.profile_hash); hi; hi = switch_hash_next(hi)) {
switch_hash_this(hi, NULL, NULL, &val);
profile = (skinny_profile_t *) val;
/* walk profiles */
switch_mutex_lock(globals.mutex);
for (hi = switch_hash_first(NULL, globals.profile_hash); hi; hi = switch_hash_next(hi)) {
switch_hash_this(hi, NULL, NULL, &val);
profile = (skinny_profile_t *) val;
switch_console_push_match(&my_matches, profile->name);
}
switch_mutex_unlock(globals.mutex);
switch_console_push_match(&my_matches, profile->name);
}
switch_mutex_unlock(globals.mutex);
if (my_matches) {
*matches = my_matches;
status = SWITCH_STATUS_SUCCESS;
}
if (my_matches) {
*matches = my_matches;
status = SWITCH_STATUS_SUCCESS;
}
return status;
return status;
}
struct match_helper {
switch_console_callback_match_t *my_matches;
switch_console_callback_match_t *my_matches;
};
static int skinny_api_list_devices_callback(void *pArg, int argc, char **argv, char **columnNames)
{
struct match_helper *h = (struct match_helper *) pArg;
char *device_name = argv[0];
struct match_helper *h = (struct match_helper *) pArg;
char *device_name = argv[0];
switch_console_push_match(&h->my_matches, device_name);
return 0;
switch_console_push_match(&h->my_matches, device_name);
return 0;
}
static switch_status_t skinny_api_list_devices(const char *line, const char *cursor, switch_console_callback_match_t **matches)
{
struct match_helper h = { 0 };
switch_status_t status = SWITCH_STATUS_FALSE;
skinny_profile_t *profile = NULL;
char *sql;
struct match_helper h = { 0 };
switch_status_t status = SWITCH_STATUS_FALSE;
skinny_profile_t *profile = NULL;
char *sql;
char *myline;
char *argv[1024] = { 0 };
int argc = 0;
char *myline;
char *argv[1024] = { 0 };
int argc = 0;
if (!(myline = strdup(line))) {
status = SWITCH_STATUS_MEMERR;
return status;
}
if (!(argc = switch_separate_string(myline, ' ', argv, (sizeof(argv) / sizeof(argv[0])))) || argc < 4) {
return status;
}
if (!(myline = strdup(line))) {
status = SWITCH_STATUS_MEMERR;
return status;
}
if (!(argc = switch_separate_string(myline, ' ', argv, (sizeof(argv) / sizeof(argv[0])))) || argc < 4) {
return status;
}
if(!strcasecmp(argv[1], "profile")) {/* skinny profile <profile_name> ... */
profile = skinny_find_profile(argv[2]);
} else if(!strcasecmp(argv[2], "profile")) {/* skinny status profile <profile_name> ... */
profile = skinny_find_profile(argv[3]);
}
if(!strcasecmp(argv[1], "profile")) {/* skinny profile <profile_name> ... */
profile = skinny_find_profile(argv[2]);
} else if(!strcasecmp(argv[2], "profile")) {/* skinny status profile <profile_name> ... */
profile = skinny_find_profile(argv[3]);
}
if(profile) {
if ((sql = switch_mprintf("SELECT name FROM skinny_devices"))) {
skinny_execute_sql_callback(profile, profile->sql_mutex, sql, skinny_api_list_devices_callback, &h);
switch_safe_free(sql);
}
}
if(profile) {
if ((sql = switch_mprintf("SELECT name FROM skinny_devices"))) {
skinny_execute_sql_callback(profile, profile->sql_mutex, sql, skinny_api_list_devices_callback, &h);
switch_safe_free(sql);
}
}
if (h.my_matches) {
*matches = h.my_matches;
status = SWITCH_STATUS_SUCCESS;
}
if (h.my_matches) {
*matches = h.my_matches;
status = SWITCH_STATUS_SUCCESS;
}
return status;
return status;
}
static switch_status_t skinny_api_list_reset_types(const char *line, const char *cursor, switch_console_callback_match_t **matches)
{
switch_status_t status = SWITCH_STATUS_FALSE;
SKINNY_PUSH_DEVICE_RESET_TYPES
return status;
switch_status_t status = SWITCH_STATUS_FALSE;
SKINNY_PUSH_DEVICE_RESET_TYPES
return status;
}
static switch_status_t skinny_api_list_stimuli(const char *line, const char *cursor, switch_console_callback_match_t **matches)
{
switch_status_t status = SWITCH_STATUS_FALSE;
SKINNY_PUSH_STIMULI
return status;
switch_status_t status = SWITCH_STATUS_FALSE;
SKINNY_PUSH_STIMULI
return status;
}
static switch_status_t skinny_api_list_ring_types(const char *line, const char *cursor, switch_console_callback_match_t **matches)
{
switch_status_t status = SWITCH_STATUS_FALSE;
SKINNY_PUSH_RING_TYPES
return status;
switch_status_t status = SWITCH_STATUS_FALSE;
SKINNY_PUSH_RING_TYPES
return status;
}
static switch_status_t skinny_api_list_ring_modes(const char *line, const char *cursor, switch_console_callback_match_t **matches)
{
switch_status_t status = SWITCH_STATUS_FALSE;
SKINNY_PUSH_RING_MODES
return status;
switch_status_t status = SWITCH_STATUS_FALSE;
SKINNY_PUSH_RING_MODES
return status;
}
static switch_status_t skinny_api_list_stimulus_instances(const char *line, const char *cursor, switch_console_callback_match_t **matches)
{
switch_status_t status = SWITCH_STATUS_FALSE;
switch_console_callback_match_t *my_matches = NULL;
switch_status_t status = SWITCH_STATUS_FALSE;
switch_console_callback_match_t *my_matches = NULL;
switch_console_push_match(&my_matches, "<stimulus_instance>");
switch_console_push_match(&my_matches, "0");
switch_console_push_match(&my_matches, "<stimulus_instance>");
switch_console_push_match(&my_matches, "0");
if (my_matches) {
*matches = my_matches;
status = SWITCH_STATUS_SUCCESS;
}
return status;
if (my_matches) {
*matches = my_matches;
status = SWITCH_STATUS_SUCCESS;
}
return status;
}
static switch_status_t skinny_api_list_stimulus_modes(const char *line, const char *cursor, switch_console_callback_match_t **matches)
{
switch_status_t status = SWITCH_STATUS_FALSE;
SKINNY_PUSH_LAMP_MODES
return status;
switch_status_t status = SWITCH_STATUS_FALSE;
SKINNY_PUSH_LAMP_MODES
return status;
}
static switch_status_t skinny_api_list_speaker_modes(const char *line, const char *cursor, switch_console_callback_match_t **matches)
{
switch_status_t status = SWITCH_STATUS_FALSE;
SKINNY_PUSH_SPEAKER_MODES
return status;
switch_status_t status = SWITCH_STATUS_FALSE;
SKINNY_PUSH_SPEAKER_MODES
return status;
}
static switch_status_t skinny_api_list_call_states(const char *line, const char *cursor, switch_console_callback_match_t **matches)
{
switch_status_t status = SWITCH_STATUS_FALSE;
SKINNY_PUSH_CALL_STATES
return status;
switch_status_t status = SWITCH_STATUS_FALSE;
SKINNY_PUSH_CALL_STATES
return status;
}
static switch_status_t skinny_api_list_line_instances(const char *line, const char *cursor, switch_console_callback_match_t **matches)
{
switch_status_t status = SWITCH_STATUS_FALSE;
switch_console_callback_match_t *my_matches = NULL;
switch_status_t status = SWITCH_STATUS_FALSE;
switch_console_callback_match_t *my_matches = NULL;
/* TODO */
switch_console_push_match(&my_matches, "1");
switch_console_push_match(&my_matches, "<line_instance>");
/* TODO */
switch_console_push_match(&my_matches, "1");
switch_console_push_match(&my_matches, "<line_instance>");
if (my_matches) {
*matches = my_matches;
status = SWITCH_STATUS_SUCCESS;
}
return status;
if (my_matches) {
*matches = my_matches;
status = SWITCH_STATUS_SUCCESS;
}
return status;
}
static switch_status_t skinny_api_list_call_ids(const char *line, const char *cursor, switch_console_callback_match_t **matches)
{
switch_status_t status = SWITCH_STATUS_FALSE;
switch_console_callback_match_t *my_matches = NULL;
switch_status_t status = SWITCH_STATUS_FALSE;
switch_console_callback_match_t *my_matches = NULL;
/* TODO */
switch_console_push_match(&my_matches, "1345");
switch_console_push_match(&my_matches, "<call_id>");
/* TODO */
switch_console_push_match(&my_matches, "1345");
switch_console_push_match(&my_matches, "<call_id>");
if (my_matches) {
*matches = my_matches;
status = SWITCH_STATUS_SUCCESS;
}
return status;
if (my_matches) {
*matches = my_matches;
status = SWITCH_STATUS_SUCCESS;
}
return status;
}
static switch_status_t skinny_api_list_settings(const char *line, const char *cursor, switch_console_callback_match_t **matches)
{
switch_status_t status = SWITCH_STATUS_FALSE;
switch_console_callback_match_t *my_matches = NULL;
switch_status_t status = SWITCH_STATUS_FALSE;
switch_console_callback_match_t *my_matches = NULL;
switch_console_push_match(&my_matches, "domain");
switch_console_push_match(&my_matches, "ip");
switch_console_push_match(&my_matches, "port");
switch_console_push_match(&my_matches, "patterns-dialplan");
switch_console_push_match(&my_matches, "patterns-context");
switch_console_push_match(&my_matches, "dialplan");
switch_console_push_match(&my_matches, "context");
switch_console_push_match(&my_matches, "keep-alive");
switch_console_push_match(&my_matches, "date-format");
switch_console_push_match(&my_matches, "odbc-dsn");
switch_console_push_match(&my_matches, "debug");
switch_console_push_match(&my_matches, "auto-restart");
switch_console_push_match(&my_matches, "domain");
switch_console_push_match(&my_matches, "ip");
switch_console_push_match(&my_matches, "port");
switch_console_push_match(&my_matches, "patterns-dialplan");
switch_console_push_match(&my_matches, "patterns-context");
switch_console_push_match(&my_matches, "dialplan");
switch_console_push_match(&my_matches, "context");
switch_console_push_match(&my_matches, "keep-alive");
switch_console_push_match(&my_matches, "date-format");
switch_console_push_match(&my_matches, "odbc-dsn");
switch_console_push_match(&my_matches, "debug");
switch_console_push_match(&my_matches, "auto-restart");
if (my_matches) {
*matches = my_matches;
status = SWITCH_STATUS_SUCCESS;
}
return status;
if (my_matches) {
*matches = my_matches;
status = SWITCH_STATUS_SUCCESS;
}
return status;
}
/*****************************************************************************/
@@ -244,136 +244,136 @@ static switch_status_t skinny_api_list_settings(const char *line, const char *cu
/*****************************************************************************/
static switch_status_t skinny_api_cmd_status_profile(const char *profile_name, switch_stream_handle_t *stream)
{
skinny_profile_t *profile;
if ((profile = skinny_find_profile(profile_name))) {
skinny_profile_dump(profile, stream);
} else {
stream->write_function(stream, "Profile not found!\n");
}
skinny_profile_t *profile;
if ((profile = skinny_find_profile(profile_name))) {
skinny_profile_dump(profile, stream);
} else {
stream->write_function(stream, "Profile not found!\n");
}
return SWITCH_STATUS_SUCCESS;
return SWITCH_STATUS_SUCCESS;
}
static switch_status_t skinny_api_cmd_status_profile_device(const char *profile_name, const char *device_name, switch_stream_handle_t *stream)
{
skinny_profile_t *profile;
if ((profile = skinny_find_profile(profile_name))) {
dump_device(profile, device_name, stream);
} else {
stream->write_function(stream, "Profile not found!\n");
}
skinny_profile_t *profile;
if ((profile = skinny_find_profile(profile_name))) {
dump_device(profile, device_name, stream);
} else {
stream->write_function(stream, "Profile not found!\n");
}
return SWITCH_STATUS_SUCCESS;
return SWITCH_STATUS_SUCCESS;
}
static switch_status_t skinny_api_cmd_profile_device_send_ringer_message(const char *profile_name, const char *device_name, const char *ring_type, const char *ring_mode, switch_stream_handle_t *stream)
{
skinny_profile_t *profile;
skinny_profile_t *profile;
if ((profile = skinny_find_profile(profile_name))) {
listener_t *listener = NULL;
skinny_profile_find_listener_by_device_name(profile, device_name, &listener);
if(listener) {
send_set_ringer(listener, skinny_str2ring_type(ring_type), skinny_str2ring_mode(ring_mode), 0, 0);
if ((profile = skinny_find_profile(profile_name))) {
listener_t *listener = NULL;
skinny_profile_find_listener_by_device_name(profile, device_name, &listener);
if(listener) {
send_set_ringer(listener, skinny_str2ring_type(ring_type), skinny_str2ring_mode(ring_mode), 0, 0);
stream->write_function(stream, "+OK\n");
} else {
stream->write_function(stream, "Listener not found!\n");
}
} else {
stream->write_function(stream, "Profile not found!\n");
}
} else {
stream->write_function(stream, "Listener not found!\n");
}
} else {
stream->write_function(stream, "Profile not found!\n");
}
return SWITCH_STATUS_SUCCESS;
return SWITCH_STATUS_SUCCESS;
}
static switch_status_t skinny_api_cmd_profile_device_send_lamp_message(const char *profile_name, const char *device_name, const char *stimulus, const char *instance, const char *lamp_mode, switch_stream_handle_t *stream)
{
skinny_profile_t *profile;
skinny_profile_t *profile;
if ((profile = skinny_find_profile(profile_name))) {
listener_t *listener = NULL;
skinny_profile_find_listener_by_device_name(profile, device_name, &listener);
if(listener) {
send_set_lamp(listener, skinny_str2button(stimulus), atoi(instance), skinny_str2lamp_mode(lamp_mode));
if ((profile = skinny_find_profile(profile_name))) {
listener_t *listener = NULL;
skinny_profile_find_listener_by_device_name(profile, device_name, &listener);
if(listener) {
send_set_lamp(listener, skinny_str2button(stimulus), atoi(instance), skinny_str2lamp_mode(lamp_mode));
stream->write_function(stream, "+OK\n");
} else {
stream->write_function(stream, "Listener not found!\n");
}
} else {
stream->write_function(stream, "Profile not found!\n");
}
} else {
stream->write_function(stream, "Listener not found!\n");
}
} else {
stream->write_function(stream, "Profile not found!\n");
}
return SWITCH_STATUS_SUCCESS;
return SWITCH_STATUS_SUCCESS;
}
static switch_status_t skinny_api_cmd_profile_device_send_speaker_mode_message(const char *profile_name, const char *device_name, const char *speaker_mode, switch_stream_handle_t *stream)
{
skinny_profile_t *profile;
skinny_profile_t *profile;
if ((profile = skinny_find_profile(profile_name))) {
listener_t *listener = NULL;
skinny_profile_find_listener_by_device_name(profile, device_name, &listener);
if(listener) {
send_set_speaker_mode(listener, skinny_str2speaker_mode(speaker_mode));
if ((profile = skinny_find_profile(profile_name))) {
listener_t *listener = NULL;
skinny_profile_find_listener_by_device_name(profile, device_name, &listener);
if(listener) {
send_set_speaker_mode(listener, skinny_str2speaker_mode(speaker_mode));
stream->write_function(stream, "+OK\n");
} else {
stream->write_function(stream, "Listener not found!\n");
}
} else {
stream->write_function(stream, "Profile not found!\n");
}
} else {
stream->write_function(stream, "Listener not found!\n");
}
} else {
stream->write_function(stream, "Profile not found!\n");
}
return SWITCH_STATUS_SUCCESS;
return SWITCH_STATUS_SUCCESS;
}
static switch_status_t skinny_api_cmd_profile_device_send_call_state_message(const char *profile_name, const char *device_name, const char *call_state, const char *line_instance, const char *call_id, switch_stream_handle_t *stream)
{
skinny_profile_t *profile;
skinny_profile_t *profile;
if ((profile = skinny_find_profile(profile_name))) {
listener_t *listener = NULL;
skinny_profile_find_listener_by_device_name(profile, device_name, &listener);
if(listener) {
send_call_state(listener, skinny_str2call_state(call_state), atoi(line_instance), atoi(call_id));
if ((profile = skinny_find_profile(profile_name))) {
listener_t *listener = NULL;
skinny_profile_find_listener_by_device_name(profile, device_name, &listener);
if(listener) {
send_call_state(listener, skinny_str2call_state(call_state), atoi(line_instance), atoi(call_id));
stream->write_function(stream, "+OK\n");
} else {
stream->write_function(stream, "Listener not found!\n");
}
} else {
stream->write_function(stream, "Profile not found!\n");
}
} else {
stream->write_function(stream, "Listener not found!\n");
}
} else {
stream->write_function(stream, "Profile not found!\n");
}
return SWITCH_STATUS_SUCCESS;
return SWITCH_STATUS_SUCCESS;
}
static switch_status_t skinny_api_cmd_profile_device_send_reset_message(const char *profile_name, const char *device_name, const char *reset_type, switch_stream_handle_t *stream)
{
skinny_profile_t *profile;
skinny_profile_t *profile;
if ((profile = skinny_find_profile(profile_name))) {
listener_t *listener = NULL;
skinny_profile_find_listener_by_device_name(profile, device_name, &listener);
if(listener) {
send_reset(listener, skinny_str2device_reset_type(reset_type));
if ((profile = skinny_find_profile(profile_name))) {
listener_t *listener = NULL;
skinny_profile_find_listener_by_device_name(profile, device_name, &listener);
if(listener) {
send_reset(listener, skinny_str2device_reset_type(reset_type));
stream->write_function(stream, "+OK\n");
} else {
stream->write_function(stream, "Listener not found!\n");
}
} else {
stream->write_function(stream, "Profile not found!\n");
}
} else {
stream->write_function(stream, "Listener not found!\n");
}
} else {
stream->write_function(stream, "Profile not found!\n");
}
return SWITCH_STATUS_SUCCESS;
return SWITCH_STATUS_SUCCESS;
}
static switch_status_t skinny_api_cmd_profile_device_send_data(const char *profile_name, const char *device_name, const char *message_type, char *params, const char *body, switch_stream_handle_t *stream)
{
skinny_profile_t *profile;
skinny_profile_t *profile;
if ((profile = skinny_find_profile(profile_name))) {
listener_t *listener = NULL;
skinny_profile_find_listener_by_device_name(profile, device_name, &listener);
if(listener) {
if ((profile = skinny_find_profile(profile_name))) {
listener_t *listener = NULL;
skinny_profile_find_listener_by_device_name(profile, device_name, &listener);
if(listener) {
switch_event_t *event = NULL;
char *argv[64] = { 0 };
int argc = 0;
@@ -395,49 +395,49 @@ static switch_status_t skinny_api_cmd_profile_device_send_data(const char *profi
switch_event_add_header(event, SWITCH_STACK_BOTTOM, tmp, "%s", var_value);
switch_safe_free(tmp);
/*
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Skinny-UserToDevice-Application-Id", "%d", request->data.extended_data.application_id);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Skinny-UserToDevice-Line-Instance", "%d", request->data.extended_data.line_instance);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Skinny-UserToDevice-Call-Id", "%d", request->data.extended_data.call_id);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Skinny-UserToDevice-Transaction-Id", "%d", request->data.extended_data.transaction_id);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Skinny-UserToDevice-Data-Length", "%d", request->data.extended_data.data_length);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Skinny-UserToDevice-Sequence-Flag", "%d", request->data.extended_data.sequence_flag);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Skinny-UserToDevice-Display-Priority", "%d", request->data.extended_data.display_priority);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Skinny-UserToDevice-Conference-Id", "%d", request->data.extended_data.conference_id);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Skinny-UserToDevice-App-Instance-Id", "%d", request->data.extended_data.app_instance_id);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Skinny-UserToDevice-Routing-Id", "%d", request->data.extended_data.routing_id);
*/
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Skinny-UserToDevice-Application-Id", "%d", request->data.extended_data.application_id);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Skinny-UserToDevice-Line-Instance", "%d", request->data.extended_data.line_instance);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Skinny-UserToDevice-Call-Id", "%d", request->data.extended_data.call_id);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Skinny-UserToDevice-Transaction-Id", "%d", request->data.extended_data.transaction_id);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Skinny-UserToDevice-Data-Length", "%d", request->data.extended_data.data_length);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Skinny-UserToDevice-Sequence-Flag", "%d", request->data.extended_data.sequence_flag);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Skinny-UserToDevice-Display-Priority", "%d", request->data.extended_data.display_priority);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Skinny-UserToDevice-Conference-Id", "%d", request->data.extended_data.conference_id);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Skinny-UserToDevice-App-Instance-Id", "%d", request->data.extended_data.app_instance_id);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Skinny-UserToDevice-Routing-Id", "%d", request->data.extended_data.routing_id);
*/
}
}
switch_event_add_body(event, "%s", body);
switch_event_fire(&event);
stream->write_function(stream, "+OK\n");
} else {
stream->write_function(stream, "Listener not found!\n");
}
} else {
stream->write_function(stream, "Profile not found!\n");
}
} else {
stream->write_function(stream, "Listener not found!\n");
}
} else {
stream->write_function(stream, "Profile not found!\n");
}
return SWITCH_STATUS_SUCCESS;
return SWITCH_STATUS_SUCCESS;
}
static switch_status_t skinny_api_cmd_profile_set(const char *profile_name, const char *name, const char *value, switch_stream_handle_t *stream)
{
skinny_profile_t *profile;
skinny_profile_t *profile;
if ((profile = skinny_find_profile(profile_name))) {
if (skinny_profile_set(profile, name, value) == SWITCH_STATUS_SUCCESS) {
if ((profile = skinny_find_profile(profile_name))) {
if (skinny_profile_set(profile, name, value) == SWITCH_STATUS_SUCCESS) {
skinny_profile_respawn(profile, 0);
stream->write_function(stream, "+OK\n");
} else {
stream->write_function(stream, "Unable to set skinny setting '%s'. Does it exists?\n", name);
}
} else {
stream->write_function(stream, "Profile not found!\n");
}
} else {
stream->write_function(stream, "Unable to set skinny setting '%s'. Does it exists?\n", name);
}
} else {
stream->write_function(stream, "Profile not found!\n");
}
return SWITCH_STATUS_SUCCESS;
return SWITCH_STATUS_SUCCESS;
}
/*****************************************************************************/
@@ -445,148 +445,148 @@ static switch_status_t skinny_api_cmd_profile_set(const char *profile_name, cons
/*****************************************************************************/
SWITCH_STANDARD_API(skinny_function)
{
char *argv[1024] = { 0 };
int argc = 0;
char *mycmd = NULL;
switch_status_t status = SWITCH_STATUS_SUCCESS;
const char *usage_string = "USAGE:\n"
"--------------------------------------------------------------------------------\n"
"skinny help\n"
"skinny status profile <profile_name>\n"
"skinny status profile <profile_name> device <device_name>\n"
"skinny profile <profile_name> device <device_name> send ResetMessage [DeviceReset|DeviceRestart]\n"
"skinny profile <profile_name> device <device_name> send SetRingerMessage <ring_type> <ring_mode>\n"
"skinny profile <profile_name> device <device_name> send SetLampMessage <stimulus> <instance> <lamp_mode>\n"
"skinny profile <profile_name> device <device_name> send SetSpeakerModeMessage <speaker_mode>\n"
"skinny profile <profile_name> device <device_name> send CallStateMessage <call_state> <line_instance> <call_id>\n"
"skinny profile <profile_name> device <device_name> send <UserToDeviceDataMessage|UserToDeviceDataVersion1Message> [ <param>=<value>;... ] <data>\n"
"skinny profile <profile_name> set <name> <value>\n"
"--------------------------------------------------------------------------------\n";
if (session) {
return SWITCH_STATUS_FALSE;
}
char *argv[1024] = { 0 };
int argc = 0;
char *mycmd = NULL;
switch_status_t status = SWITCH_STATUS_SUCCESS;
const char *usage_string = "USAGE:\n"
"--------------------------------------------------------------------------------\n"
"skinny help\n"
"skinny status profile <profile_name>\n"
"skinny status profile <profile_name> device <device_name>\n"
"skinny profile <profile_name> device <device_name> send ResetMessage [DeviceReset|DeviceRestart]\n"
"skinny profile <profile_name> device <device_name> send SetRingerMessage <ring_type> <ring_mode>\n"
"skinny profile <profile_name> device <device_name> send SetLampMessage <stimulus> <instance> <lamp_mode>\n"
"skinny profile <profile_name> device <device_name> send SetSpeakerModeMessage <speaker_mode>\n"
"skinny profile <profile_name> device <device_name> send CallStateMessage <call_state> <line_instance> <call_id>\n"
"skinny profile <profile_name> device <device_name> send <UserToDeviceDataMessage|UserToDeviceDataVersion1Message> [ <param>=<value>;... ] <data>\n"
"skinny profile <profile_name> set <name> <value>\n"
"--------------------------------------------------------------------------------\n";
if (session) {
return SWITCH_STATUS_FALSE;
}
if (zstr(cmd)) {
stream->write_function(stream, "%s", usage_string);
goto done;
}
if (zstr(cmd)) {
stream->write_function(stream, "%s", usage_string);
goto done;
}
if (!(mycmd = strdup(cmd))) {
status = SWITCH_STATUS_MEMERR;
goto done;
}
if (!(mycmd = strdup(cmd))) {
status = SWITCH_STATUS_MEMERR;
goto done;
}
if (!(argc = switch_separate_string(mycmd, ' ', argv, (sizeof(argv) / sizeof(argv[0])))) || !argv[0]) {
stream->write_function(stream, "%s", usage_string);
goto done;
}
if (!(argc = switch_separate_string(mycmd, ' ', argv, (sizeof(argv) / sizeof(argv[0])))) || !argv[0]) {
stream->write_function(stream, "%s", usage_string);
goto done;
}
if (!strcasecmp(argv[0], "help")) {/* skinny help */
stream->write_function(stream, "%s", usage_string);
} else if (argc == 3 && !strcasecmp(argv[0], "status") && !strcasecmp(argv[1], "profile")) {
/* skinny status profile <profile_name> */
status = skinny_api_cmd_status_profile(argv[2], stream);
} else if (argc == 5 && !strcasecmp(argv[0], "status") && !strcasecmp(argv[1], "profile") && !strcasecmp(argv[3], "device")) {
/* skinny status profile <profile_name> device <device_name> */
status = skinny_api_cmd_status_profile_device(argv[2], argv[4], stream);
} else if (argc >= 6 && !strcasecmp(argv[0], "profile") && !strcasecmp(argv[2], "device") && !strcasecmp(argv[4], "send")) {
/* skinny profile <profile_name> device <device_name> send ... */
switch(skinny_str2message_type(argv[5])) {
case SET_RINGER_MESSAGE:
if(argc == 8) {
/* SetRingerMessage <ring_type> <ring_mode> */
status = skinny_api_cmd_profile_device_send_ringer_message(argv[1], argv[3], argv[6], argv[7], stream);
}
break;
case SET_LAMP_MESSAGE:
if (argc == 9) {
/* SetLampMessage <stimulus> <instance> <lamp_mode> */
status = skinny_api_cmd_profile_device_send_lamp_message(argv[1], argv[3], argv[6], argv[7], argv[8], stream);
}
break;
case SET_SPEAKER_MODE_MESSAGE:
if (argc == 7) {
/* SetSpeakerModeMessage <speaker_mode> */
status = skinny_api_cmd_profile_device_send_speaker_mode_message(argv[1], argv[3], argv[6], stream);
}
break;
case CALL_STATE_MESSAGE:
if (argc == 9) {
/* CallStateMessage <call_state> <line_instance> <call_id> */
status = skinny_api_cmd_profile_device_send_call_state_message(argv[1], argv[3], argv[6], argv[7], argv[8], stream);
}
break;
case RESET_MESSAGE:
if (argc == 7) {
/* ResetMessage <reset_type> */
status = skinny_api_cmd_profile_device_send_reset_message(argv[1], argv[3], argv[6], stream);
}
break;
if (!strcasecmp(argv[0], "help")) {/* skinny help */
stream->write_function(stream, "%s", usage_string);
} else if (argc == 3 && !strcasecmp(argv[0], "status") && !strcasecmp(argv[1], "profile")) {
/* skinny status profile <profile_name> */
status = skinny_api_cmd_status_profile(argv[2], stream);
} else if (argc == 5 && !strcasecmp(argv[0], "status") && !strcasecmp(argv[1], "profile") && !strcasecmp(argv[3], "device")) {
/* skinny status profile <profile_name> device <device_name> */
status = skinny_api_cmd_status_profile_device(argv[2], argv[4], stream);
} else if (argc >= 6 && !strcasecmp(argv[0], "profile") && !strcasecmp(argv[2], "device") && !strcasecmp(argv[4], "send")) {
/* skinny profile <profile_name> device <device_name> send ... */
switch(skinny_str2message_type(argv[5])) {
case SET_RINGER_MESSAGE:
if(argc == 8) {
/* SetRingerMessage <ring_type> <ring_mode> */
status = skinny_api_cmd_profile_device_send_ringer_message(argv[1], argv[3], argv[6], argv[7], stream);
}
break;
case SET_LAMP_MESSAGE:
if (argc == 9) {
/* SetLampMessage <stimulus> <instance> <lamp_mode> */
status = skinny_api_cmd_profile_device_send_lamp_message(argv[1], argv[3], argv[6], argv[7], argv[8], stream);
}
break;
case SET_SPEAKER_MODE_MESSAGE:
if (argc == 7) {
/* SetSpeakerModeMessage <speaker_mode> */
status = skinny_api_cmd_profile_device_send_speaker_mode_message(argv[1], argv[3], argv[6], stream);
}
break;
case CALL_STATE_MESSAGE:
if (argc == 9) {
/* CallStateMessage <call_state> <line_instance> <call_id> */
status = skinny_api_cmd_profile_device_send_call_state_message(argv[1], argv[3], argv[6], argv[7], argv[8], stream);
}
break;
case RESET_MESSAGE:
if (argc == 7) {
/* ResetMessage <reset_type> */
status = skinny_api_cmd_profile_device_send_reset_message(argv[1], argv[3], argv[6], stream);
}
break;
case USER_TO_DEVICE_DATA_MESSAGE:
case USER_TO_DEVICE_DATA_VERSION1_MESSAGE:
if(argc == 8) {
if(argc == 8) {
/* <UserToDeviceDataMessage|UserToDeviceDataVersion1Message> [ <param>=<value>;... ] <data> */
status = skinny_api_cmd_profile_device_send_data(argv[1], argv[3], argv[5], argv[6], argv[7], stream);
} else if(argc == 7) {
} else if(argc == 7) {
/* <UserToDeviceDataMessage|UserToDeviceDataVersion1Message> <data> */
status = skinny_api_cmd_profile_device_send_data(argv[1], argv[3], argv[5], "", argv[6], stream);
}
break;
default:
stream->write_function(stream, "Unhandled message %s\n", argv[5]);
}
} else if (argc == 5 && !strcasecmp(argv[0], "profile") && !strcasecmp(argv[2], "set")) {
/* skinny profile <profile_name> set <name> <value> */
status = skinny_api_cmd_profile_set(argv[1], argv[3], argv[4], stream);
} else {
stream->write_function(stream, "%s", usage_string);
}
break;
default:
stream->write_function(stream, "Unhandled message %s\n", argv[5]);
}
} else if (argc == 5 && !strcasecmp(argv[0], "profile") && !strcasecmp(argv[2], "set")) {
/* skinny profile <profile_name> set <name> <value> */
status = skinny_api_cmd_profile_set(argv[1], argv[3], argv[4], stream);
} else {
stream->write_function(stream, "%s", usage_string);
}
done:
switch_safe_free(mycmd);
return status;
switch_safe_free(mycmd);
return status;
}
switch_status_t skinny_api_register(switch_loadable_module_interface_t **module_interface)
{
switch_api_interface_t *api_interface;
switch_api_interface_t *api_interface;
SWITCH_ADD_API(api_interface, "skinny", "Skinny Controls", skinny_function, "<cmd> <args>");
switch_console_set_complete("add skinny help");
SWITCH_ADD_API(api_interface, "skinny", "Skinny Controls", skinny_function, "<cmd> <args>");
switch_console_set_complete("add skinny help");
switch_console_set_complete("add skinny status profile ::skinny::list_profiles");
switch_console_set_complete("add skinny status profile ::skinny::list_profiles device ::skinny::list_devices");
switch_console_set_complete("add skinny status profile ::skinny::list_profiles");
switch_console_set_complete("add skinny status profile ::skinny::list_profiles device ::skinny::list_devices");
switch_console_set_complete("add skinny profile ::skinny::list_profiles device ::skinny::list_devices send ResetMessage ::skinny::list_reset_types");
switch_console_set_complete("add skinny profile ::skinny::list_profiles device ::skinny::list_devices send SetRingerMessage ::skinny::list_ring_types ::skinny::list_ring_modes");
switch_console_set_complete("add skinny profile ::skinny::list_profiles device ::skinny::list_devices send SetLampMessage ::skinny::list_stimuli ::skinny::list_stimulus_instances ::skinny::list_stimulus_modes");
switch_console_set_complete("add skinny profile ::skinny::list_profiles device ::skinny::list_devices send SetSpeakerModeMessage ::skinny::list_speaker_modes");
switch_console_set_complete("add skinny profile ::skinny::list_profiles device ::skinny::list_devices send CallStateMessage ::skinny::list_call_states ::skinny::list_line_instances ::skinny::list_call_ids");
switch_console_set_complete("add skinny profile ::skinny::list_profiles device ::skinny::list_devices send UserToDeviceDataMessage");
switch_console_set_complete("add skinny profile ::skinny::list_profiles device ::skinny::list_devices send UserToDeviceDataVersion1Message");
switch_console_set_complete("add skinny profile ::skinny::list_profiles set ::skinny::list_settings");
switch_console_set_complete("add skinny profile ::skinny::list_profiles device ::skinny::list_devices send ResetMessage ::skinny::list_reset_types");
switch_console_set_complete("add skinny profile ::skinny::list_profiles device ::skinny::list_devices send SetRingerMessage ::skinny::list_ring_types ::skinny::list_ring_modes");
switch_console_set_complete("add skinny profile ::skinny::list_profiles device ::skinny::list_devices send SetLampMessage ::skinny::list_stimuli ::skinny::list_stimulus_instances ::skinny::list_stimulus_modes");
switch_console_set_complete("add skinny profile ::skinny::list_profiles device ::skinny::list_devices send SetSpeakerModeMessage ::skinny::list_speaker_modes");
switch_console_set_complete("add skinny profile ::skinny::list_profiles device ::skinny::list_devices send CallStateMessage ::skinny::list_call_states ::skinny::list_line_instances ::skinny::list_call_ids");
switch_console_set_complete("add skinny profile ::skinny::list_profiles device ::skinny::list_devices send UserToDeviceDataMessage");
switch_console_set_complete("add skinny profile ::skinny::list_profiles device ::skinny::list_devices send UserToDeviceDataVersion1Message");
switch_console_set_complete("add skinny profile ::skinny::list_profiles set ::skinny::list_settings");
switch_console_add_complete_func("::skinny::list_profiles", skinny_api_list_profiles);
switch_console_add_complete_func("::skinny::list_devices", skinny_api_list_devices);
switch_console_add_complete_func("::skinny::list_reset_types", skinny_api_list_reset_types);
switch_console_add_complete_func("::skinny::list_ring_types", skinny_api_list_ring_types);
switch_console_add_complete_func("::skinny::list_ring_modes", skinny_api_list_ring_modes);
switch_console_add_complete_func("::skinny::list_stimuli", skinny_api_list_stimuli);
switch_console_add_complete_func("::skinny::list_stimulus_instances", skinny_api_list_stimulus_instances);
switch_console_add_complete_func("::skinny::list_stimulus_modes", skinny_api_list_stimulus_modes);
switch_console_add_complete_func("::skinny::list_speaker_modes", skinny_api_list_speaker_modes);
switch_console_add_complete_func("::skinny::list_call_states", skinny_api_list_call_states);
switch_console_add_complete_func("::skinny::list_line_instances", skinny_api_list_line_instances);
switch_console_add_complete_func("::skinny::list_call_ids", skinny_api_list_call_ids);
switch_console_add_complete_func("::skinny::list_settings", skinny_api_list_settings);
return SWITCH_STATUS_SUCCESS;
switch_console_add_complete_func("::skinny::list_profiles", skinny_api_list_profiles);
switch_console_add_complete_func("::skinny::list_devices", skinny_api_list_devices);
switch_console_add_complete_func("::skinny::list_reset_types", skinny_api_list_reset_types);
switch_console_add_complete_func("::skinny::list_ring_types", skinny_api_list_ring_types);
switch_console_add_complete_func("::skinny::list_ring_modes", skinny_api_list_ring_modes);
switch_console_add_complete_func("::skinny::list_stimuli", skinny_api_list_stimuli);
switch_console_add_complete_func("::skinny::list_stimulus_instances", skinny_api_list_stimulus_instances);
switch_console_add_complete_func("::skinny::list_stimulus_modes", skinny_api_list_stimulus_modes);
switch_console_add_complete_func("::skinny::list_speaker_modes", skinny_api_list_speaker_modes);
switch_console_add_complete_func("::skinny::list_call_states", skinny_api_list_call_states);
switch_console_add_complete_func("::skinny::list_line_instances", skinny_api_list_line_instances);
switch_console_add_complete_func("::skinny::list_call_ids", skinny_api_list_call_ids);
switch_console_add_complete_func("::skinny::list_settings", skinny_api_list_settings);
return SWITCH_STATUS_SUCCESS;
}
switch_status_t skinny_api_unregister()
{
switch_console_set_complete("del skinny");
return SWITCH_STATUS_SUCCESS;
return SWITCH_STATUS_SUCCESS;
}
/* For Emacs:
+199 -199
View File
@@ -149,26 +149,26 @@ switch_status_t skinny_read_packet(listener_t *listener, skinny_message_t **req)
if(mlen) {
bytes += mlen;
if(bytes >= SKINNY_MESSAGE_FIELD_SIZE) {
do_sleep = 0;
ptr += mlen;
memcpy(request, mbuf, bytes);
#ifdef SKINNY_MEGA_DEBUG
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
"Got request: length=%d,reserved=%x,type=%x\n",
request->length,request->reserved,request->type);
"Got request: length=%d,reserved=%x,type=%x\n",
request->length,request->reserved,request->type);
#endif
if(request->length < SKINNY_MESSAGE_FIELD_SIZE) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"Skinny client sent invalid data. Length should be greater than 4 but got %d.\n",
request->length);
"Skinny client sent invalid data. Length should be greater than 4 but got %d.\n",
request->length);
return SWITCH_STATUS_FALSE;
}
if(request->length + 2*SKINNY_MESSAGE_FIELD_SIZE > SKINNY_MESSAGE_MAXSIZE) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"Skinny client sent too huge data. Got %d which is above threshold %d.\n",
request->length, SKINNY_MESSAGE_MAXSIZE - 2*SKINNY_MESSAGE_FIELD_SIZE);
"Skinny client sent too huge data. Got %d which is above threshold %d.\n",
request->length, SKINNY_MESSAGE_MAXSIZE - 2*SKINNY_MESSAGE_FIELD_SIZE);
return SWITCH_STATUS_FALSE;
}
if(bytes >= request->length + 2*SKINNY_MESSAGE_FIELD_SIZE) {
@@ -224,10 +224,10 @@ switch_status_t skinny_device_event(listener_t *listener, switch_event_t **ev, s
switch_event_create_subclass(&event, event_id, subclass_name);
switch_assert(event);
if ((sql = switch_mprintf("SELECT '%s', name, user_id, instance, ip, type, max_streams, port, codec_string "
"FROM skinny_devices "
"WHERE name='%s' AND instance=%d",
listener->profile->name,
listener->device_name, listener->device_instance))) {
"FROM skinny_devices "
"WHERE name='%s' AND instance=%d",
listener->profile->name,
listener->device_name, listener->device_instance))) {
skinny_execute_sql_callback(profile, profile->sql_mutex, sql, skinny_device_event_callback, event);
switch_safe_free(sql);
}
@@ -243,14 +243,14 @@ switch_status_t skinny_session_walk_lines(skinny_profile_t *profile, char *chann
{
char *sql;
if ((sql = switch_mprintf(
"SELECT skinny_lines.*, channel_uuid, call_id, call_state "
"FROM skinny_active_lines "
"INNER JOIN skinny_lines "
"ON skinny_active_lines.device_name = skinny_lines.device_name "
"AND skinny_active_lines.device_instance = skinny_lines.device_instance "
"AND skinny_active_lines.line_instance = skinny_lines.line_instance "
"WHERE channel_uuid='%s'",
channel_uuid))) {
"SELECT skinny_lines.*, channel_uuid, call_id, call_state "
"FROM skinny_active_lines "
"INNER JOIN skinny_lines "
"ON skinny_active_lines.device_name = skinny_lines.device_name "
"AND skinny_active_lines.device_instance = skinny_lines.device_instance "
"AND skinny_active_lines.line_instance = skinny_lines.line_instance "
"WHERE channel_uuid='%s'",
channel_uuid))) {
skinny_execute_sql_callback(profile, profile->sql_mutex, sql, callback, data);
switch_safe_free(sql);
}
@@ -261,14 +261,14 @@ switch_status_t skinny_session_walk_lines_by_call_id(skinny_profile_t *profile,
{
char *sql;
if ((sql = switch_mprintf(
"SELECT skinny_lines.*, channel_uuid, call_id, call_state "
"FROM skinny_active_lines "
"INNER JOIN skinny_lines "
"ON skinny_active_lines.device_name = skinny_lines.device_name "
"AND skinny_active_lines.device_instance = skinny_lines.device_instance "
"AND skinny_active_lines.line_instance = skinny_lines.line_instance "
"WHERE call_id='%d'",
call_id))) {
"SELECT skinny_lines.*, channel_uuid, call_id, call_state "
"FROM skinny_active_lines "
"INNER JOIN skinny_lines "
"ON skinny_active_lines.device_name = skinny_lines.device_name "
"AND skinny_active_lines.device_instance = skinny_lines.device_instance "
"AND skinny_active_lines.line_instance = skinny_lines.line_instance "
"WHERE call_id='%d'",
call_id))) {
skinny_execute_sql_callback(profile, profile->sql_mutex, sql, callback, data);
switch_safe_free(sql);
}
@@ -309,13 +309,13 @@ void skinny_line_get(listener_t *listener, uint32_t instance, struct line_stat_r
helper.button = switch_core_alloc(listener->pool, sizeof(struct line_stat_res_message));
if ((sql = switch_mprintf(
"SELECT '%d' AS wanted_position, position, label, value, caller_name "
"FROM skinny_lines "
"WHERE device_name='%s' AND device_instance=%d "
"ORDER BY position",
instance,
listener->device_name, listener->device_instance
))) {
"SELECT '%d' AS wanted_position, position, label, value, caller_name "
"FROM skinny_lines "
"WHERE device_name='%s' AND device_instance=%d "
"ORDER BY position",
instance,
listener->device_name, listener->device_instance
))) {
skinny_execute_sql_callback(listener->profile, listener->profile->sql_mutex, sql, skinny_line_get_callback, &helper);
switch_safe_free(sql);
}
@@ -352,14 +352,14 @@ void skinny_speed_dial_get(listener_t *listener, uint32_t instance, struct speed
helper.button = switch_core_alloc(listener->pool, sizeof(struct speed_dial_stat_res_message));
if ((sql = switch_mprintf(
"SELECT '%d' AS wanted_position, position, label, value, settings "
"FROM skinny_buttons "
"WHERE device_name='%s' AND device_instance=%d AND type=%d "
"ORDER BY position",
instance,
listener->device_name, listener->device_instance,
SKINNY_BUTTON_SPEED_DIAL
))) {
"SELECT '%d' AS wanted_position, position, label, value, settings "
"FROM skinny_buttons "
"WHERE device_name='%s' AND device_instance=%d AND type=%d "
"ORDER BY position",
instance,
listener->device_name, listener->device_instance,
SKINNY_BUTTON_SPEED_DIAL
))) {
skinny_execute_sql_callback(listener->profile, listener->profile->sql_mutex, sql, skinny_speed_dial_get_callback, &helper);
switch_safe_free(sql);
}
@@ -396,15 +396,15 @@ void skinny_service_url_get(listener_t *listener, uint32_t instance, struct serv
helper.button = switch_core_alloc(listener->pool, sizeof(struct service_url_stat_res_message));
if ((sql = switch_mprintf(
"SELECT '%d' AS wanted_position, position, label, value, settings "
"FROM skinny_buttons "
"WHERE device_name='%s' AND device_instance=%d AND type=%d "
"ORDER BY position",
instance,
listener->device_name,
listener->device_instance,
SKINNY_BUTTON_SERVICE_URL
))) {
"SELECT '%d' AS wanted_position, position, label, value, settings "
"FROM skinny_buttons "
"WHERE device_name='%s' AND device_instance=%d AND type=%d "
"ORDER BY position",
instance,
listener->device_name,
listener->device_instance,
SKINNY_BUTTON_SERVICE_URL
))) {
skinny_execute_sql_callback(listener->profile, listener->profile->sql_mutex, sql, skinny_service_url_get_callback, &helper);
switch_safe_free(sql);
}
@@ -442,15 +442,15 @@ void skinny_feature_get(listener_t *listener, uint32_t instance, struct feature_
helper.button = switch_core_alloc(listener->pool, sizeof(struct feature_stat_res_message));
if ((sql = switch_mprintf(
"SELECT '%d' AS wanted_position, position, label, value, settings "
"FROM skinny_buttons "
"WHERE device_name='%s' AND device_instance=%d AND NOT (type=%d OR type=%d) "
"ORDER BY position",
instance,
listener->device_name,
listener->device_instance,
SKINNY_BUTTON_SPEED_DIAL, SKINNY_BUTTON_SERVICE_URL
))) {
"SELECT '%d' AS wanted_position, position, label, value, settings "
"FROM skinny_buttons "
"WHERE device_name='%s' AND device_instance=%d AND NOT (type=%d OR type=%d) "
"ORDER BY position",
instance,
listener->device_name,
listener->device_instance,
SKINNY_BUTTON_SPEED_DIAL, SKINNY_BUTTON_SERVICE_URL
))) {
skinny_execute_sql_callback(listener->profile, listener->profile->sql_mutex, sql, skinny_feature_get_callback, &helper);
switch_safe_free(sql);
}
@@ -461,11 +461,11 @@ void skinny_feature_get(listener_t *listener, uint32_t instance, struct feature_
/* SKINNY MESSAGE SENDER */
/*****************************************************************************/
switch_status_t send_register_ack(listener_t *listener,
uint32_t keep_alive,
char *date_format,
char *reserved,
uint32_t secondary_keep_alive,
char *reserved2)
uint32_t keep_alive,
char *date_format,
char *reserved,
uint32_t secondary_keep_alive,
char *reserved2)
{
skinny_message_t *message;
message = switch_core_alloc(listener->pool, 12+sizeof(message->data.reg_ack));
@@ -480,10 +480,10 @@ switch_status_t send_register_ack(listener_t *listener,
}
switch_status_t send_start_tone(listener_t *listener,
uint32_t tone,
uint32_t reserved,
uint32_t line_instance,
uint32_t call_id)
uint32_t tone,
uint32_t reserved,
uint32_t line_instance,
uint32_t call_id)
{
skinny_message_t *message;
message = switch_core_alloc(listener->pool, 12+sizeof(message->data.start_tone));
@@ -497,8 +497,8 @@ switch_status_t send_start_tone(listener_t *listener,
}
switch_status_t send_stop_tone(listener_t *listener,
uint32_t line_instance,
uint32_t call_id)
uint32_t line_instance,
uint32_t call_id)
{
skinny_message_t *message;
message = switch_core_alloc(listener->pool, 12+sizeof(message->data.stop_tone));
@@ -510,10 +510,10 @@ switch_status_t send_stop_tone(listener_t *listener,
}
switch_status_t send_set_ringer(listener_t *listener,
uint32_t ring_type,
uint32_t ring_mode,
uint32_t line_instance,
uint32_t call_id)
uint32_t ring_type,
uint32_t ring_mode,
uint32_t line_instance,
uint32_t call_id)
{
skinny_message_t *message;
message = switch_core_alloc(listener->pool, 12+sizeof(message->data.ringer));
@@ -527,9 +527,9 @@ switch_status_t send_set_ringer(listener_t *listener,
}
switch_status_t send_set_lamp(listener_t *listener,
uint32_t stimulus,
uint32_t stimulus_instance,
uint32_t mode)
uint32_t stimulus,
uint32_t stimulus_instance,
uint32_t mode)
{
skinny_message_t *message;
message = switch_core_alloc(listener->pool, 12+sizeof(message->data.lamp));
@@ -542,7 +542,7 @@ switch_status_t send_set_lamp(listener_t *listener,
}
switch_status_t send_set_speaker_mode(listener_t *listener,
uint32_t mode)
uint32_t mode)
{
skinny_message_t *message;
message = switch_core_alloc(listener->pool, 12+sizeof(message->data.speaker_mode));
@@ -553,16 +553,16 @@ switch_status_t send_set_speaker_mode(listener_t *listener,
}
switch_status_t send_start_media_transmission(listener_t *listener,
uint32_t conference_id,
uint32_t pass_thru_party_id,
uint32_t remote_ip,
uint32_t remote_port,
uint32_t ms_per_packet,
uint32_t payload_capacity,
uint32_t precedence,
uint32_t silence_suppression,
uint16_t max_frames_per_packet,
uint32_t g723_bitrate)
uint32_t conference_id,
uint32_t pass_thru_party_id,
uint32_t remote_ip,
uint32_t remote_port,
uint32_t ms_per_packet,
uint32_t payload_capacity,
uint32_t precedence,
uint32_t silence_suppression,
uint16_t max_frames_per_packet,
uint32_t g723_bitrate)
{
skinny_message_t *message;
message = switch_core_alloc(listener->pool, 12+sizeof(message->data.start_media));
@@ -583,9 +583,9 @@ switch_status_t send_start_media_transmission(listener_t *listener,
}
switch_status_t send_stop_media_transmission(listener_t *listener,
uint32_t conference_id,
uint32_t pass_thru_party_id,
uint32_t conference_id2)
uint32_t conference_id,
uint32_t pass_thru_party_id,
uint32_t conference_id2)
{
skinny_message_t *message;
message = switch_core_alloc(listener->pool, 12+sizeof(message->data.stop_media));
@@ -599,26 +599,26 @@ switch_status_t send_stop_media_transmission(listener_t *listener,
}
switch_status_t skinny_send_call_info(listener_t *listener,
const char *calling_party_name,
const char *calling_party,
const char *called_party_name,
const char *called_party,
uint32_t line_instance,
uint32_t call_id,
uint32_t call_type,
const char *original_called_party_name,
const char *original_called_party,
const char *last_redirecting_party_name,
const char *last_redirecting_party,
uint32_t original_called_party_redirect_reason,
uint32_t last_redirecting_reason,
const char *calling_party_voice_mailbox,
const char *called_party_voice_mailbox,
const char *original_called_party_voice_mailbox,
const char *last_redirecting_voice_mailbox,
uint32_t call_instance,
uint32_t call_security_status,
uint32_t party_pi_restriction_bits)
const char *calling_party_name,
const char *calling_party,
const char *called_party_name,
const char *called_party,
uint32_t line_instance,
uint32_t call_id,
uint32_t call_type,
const char *original_called_party_name,
const char *original_called_party,
const char *last_redirecting_party_name,
const char *last_redirecting_party,
uint32_t original_called_party_redirect_reason,
uint32_t last_redirecting_reason,
const char *calling_party_voice_mailbox,
const char *called_party_voice_mailbox,
const char *original_called_party_voice_mailbox,
const char *last_redirecting_voice_mailbox,
uint32_t call_instance,
uint32_t call_security_status,
uint32_t party_pi_restriction_bits)
{
skinny_message_t *message;
message = switch_core_alloc(listener->pool, 12+sizeof(message->data.call_info));
@@ -648,15 +648,15 @@ switch_status_t skinny_send_call_info(listener_t *listener,
}
switch_status_t send_define_time_date(listener_t *listener,
uint32_t year,
uint32_t month,
uint32_t day_of_week, /* monday = 1 */
uint32_t day,
uint32_t hour,
uint32_t minute,
uint32_t seconds,
uint32_t milliseconds,
uint32_t timestamp)
uint32_t year,
uint32_t month,
uint32_t day_of_week, /* monday = 1 */
uint32_t day,
uint32_t hour,
uint32_t minute,
uint32_t seconds,
uint32_t milliseconds,
uint32_t timestamp)
{
skinny_message_t *message;
message = switch_core_alloc(listener->pool, 12+sizeof(message->data.define_time_date));
@@ -681,15 +681,15 @@ switch_status_t send_define_current_time_date(listener_t *listener)
ts = switch_micro_time_now();
switch_time_exp_lt(&tm, ts);
return send_define_time_date(listener,
tm.tm_year + 1900,
tm.tm_mon + 1,
tm.tm_wday,
tm.tm_mday,
tm.tm_hour,
tm.tm_min,
tm.tm_sec,
tm.tm_usec / 1000,
ts / 1000000);
tm.tm_year + 1900,
tm.tm_mon + 1,
tm.tm_wday,
tm.tm_mday,
tm.tm_hour,
tm.tm_min,
tm.tm_sec,
tm.tm_usec / 1000,
ts / 1000000);
}
switch_status_t send_capabilities_req(listener_t *listener)
@@ -702,7 +702,7 @@ switch_status_t send_capabilities_req(listener_t *listener)
}
switch_status_t send_version(listener_t *listener,
char *version)
char *version)
{
skinny_message_t *message;
message = switch_core_alloc(listener->pool, 12+sizeof(message->data.version));
@@ -713,7 +713,7 @@ switch_status_t send_version(listener_t *listener,
}
switch_status_t send_register_reject(listener_t *listener,
char *error)
char *error)
{
skinny_message_t *message;
message = switch_core_alloc(listener->pool, 12+sizeof(message->data.reg_rej));
@@ -724,14 +724,14 @@ switch_status_t send_register_reject(listener_t *listener,
}
switch_status_t send_open_receive_channel(listener_t *listener,
uint32_t conference_id,
uint32_t pass_thru_party_id,
uint32_t packets,
uint32_t payload_capacity,
uint32_t echo_cancel_type,
uint32_t g723_bitrate,
uint32_t conference_id2,
uint32_t reserved[10])
uint32_t conference_id,
uint32_t pass_thru_party_id,
uint32_t packets,
uint32_t payload_capacity,
uint32_t echo_cancel_type,
uint32_t g723_bitrate,
uint32_t conference_id2,
uint32_t reserved[10])
{
skinny_message_t *message;
message = switch_core_alloc(listener->pool, 12+sizeof(message->data.open_receive_channel));
@@ -745,24 +745,24 @@ switch_status_t send_open_receive_channel(listener_t *listener,
message->data.open_receive_channel.g723_bitrate = g723_bitrate;
message->data.open_receive_channel.conference_id2 = conference_id2;
/*
message->data.open_receive_channel.reserved[0] = reserved[0];
message->data.open_receive_channel.reserved[1] = reserved[1];
message->data.open_receive_channel.reserved[2] = reserved[2];
message->data.open_receive_channel.reserved[3] = reserved[3];
message->data.open_receive_channel.reserved[4] = reserved[4];
message->data.open_receive_channel.reserved[5] = reserved[5];
message->data.open_receive_channel.reserved[6] = reserved[6];
message->data.open_receive_channel.reserved[7] = reserved[7];
message->data.open_receive_channel.reserved[8] = reserved[8];
message->data.open_receive_channel.reserved[9] = reserved[9];
*/
message->data.open_receive_channel.reserved[0] = reserved[0];
message->data.open_receive_channel.reserved[1] = reserved[1];
message->data.open_receive_channel.reserved[2] = reserved[2];
message->data.open_receive_channel.reserved[3] = reserved[3];
message->data.open_receive_channel.reserved[4] = reserved[4];
message->data.open_receive_channel.reserved[5] = reserved[5];
message->data.open_receive_channel.reserved[6] = reserved[6];
message->data.open_receive_channel.reserved[7] = reserved[7];
message->data.open_receive_channel.reserved[8] = reserved[8];
message->data.open_receive_channel.reserved[9] = reserved[9];
*/
return skinny_send_reply(listener, message);
}
switch_status_t send_close_receive_channel(listener_t *listener,
uint32_t conference_id,
uint32_t pass_thru_party_id,
uint32_t conference_id2)
uint32_t conference_id,
uint32_t pass_thru_party_id,
uint32_t conference_id2)
{
skinny_message_t *message;
message = switch_core_alloc(listener->pool, 12+sizeof(message->data.close_receive_channel));
@@ -775,10 +775,10 @@ switch_status_t send_close_receive_channel(listener_t *listener,
}
switch_status_t send_select_soft_keys(listener_t *listener,
uint32_t line_instance,
uint32_t call_id,
uint32_t soft_key_set,
uint32_t valid_key_mask)
uint32_t line_instance,
uint32_t call_id,
uint32_t soft_key_set,
uint32_t valid_key_mask)
{
skinny_message_t *message;
message = switch_core_alloc(listener->pool, 12+sizeof(message->data.select_soft_keys));
@@ -792,9 +792,9 @@ switch_status_t send_select_soft_keys(listener_t *listener,
}
switch_status_t send_call_state(listener_t *listener,
uint32_t call_state,
uint32_t line_instance,
uint32_t call_id)
uint32_t call_state,
uint32_t line_instance,
uint32_t call_id)
{
skinny_message_t *message;
message = switch_core_alloc(listener->pool, 12+sizeof(message->data.call_state));
@@ -807,10 +807,10 @@ switch_status_t send_call_state(listener_t *listener,
}
switch_status_t send_display_prompt_status(listener_t *listener,
uint32_t timeout,
const char *display,
uint32_t line_instance,
uint32_t call_id)
uint32_t timeout,
const char *display,
uint32_t line_instance,
uint32_t call_id)
{
skinny_message_t *message;
message = switch_core_alloc(listener->pool, 12+sizeof(message->data.display_prompt_status));
@@ -824,8 +824,8 @@ switch_status_t send_display_prompt_status(listener_t *listener,
}
switch_status_t send_clear_prompt_status(listener_t *listener,
uint32_t line_instance,
uint32_t call_id)
uint32_t line_instance,
uint32_t call_id)
{
skinny_message_t *message;
message = switch_core_alloc(listener->pool, 12+sizeof(message->data.clear_prompt_status));
@@ -837,7 +837,7 @@ switch_status_t send_clear_prompt_status(listener_t *listener,
}
switch_status_t send_activate_call_plane(listener_t *listener,
uint32_t line_instance)
uint32_t line_instance)
{
skinny_message_t *message;
message = switch_core_alloc(listener->pool, 12+sizeof(message->data.activate_call_plane));
@@ -848,8 +848,8 @@ switch_status_t send_activate_call_plane(listener_t *listener,
}
switch_status_t send_back_space_request(listener_t *listener,
uint32_t line_instance,
uint32_t call_id)
uint32_t line_instance,
uint32_t call_id)
{
skinny_message_t *message;
message = switch_core_alloc(listener->pool, 12+sizeof(message->data.back_space_req));
@@ -862,9 +862,9 @@ switch_status_t send_back_space_request(listener_t *listener,
}
switch_status_t send_dialed_number(listener_t *listener,
char called_party[24],
uint32_t line_instance,
uint32_t call_id)
char called_party[24],
uint32_t line_instance,
uint32_t call_id)
{
skinny_message_t *message;
message = switch_core_alloc(listener->pool, 12+sizeof(message->data.dialed_number));
@@ -877,9 +877,9 @@ switch_status_t send_dialed_number(listener_t *listener,
}
switch_status_t send_display_pri_notify(listener_t *listener,
uint32_t message_timeout,
uint32_t priority,
char *notify)
uint32_t message_timeout,
uint32_t priority,
char *notify)
{
skinny_message_t *message;
message = switch_core_alloc(listener->pool, 12+sizeof(message->data.display_pri_notify));
@@ -903,12 +903,12 @@ switch_status_t send_reset(listener_t *listener, uint32_t reset_type)
}
switch_status_t send_data(listener_t *listener, uint32_t message_type,
uint32_t application_id,
uint32_t line_instance,
uint32_t call_id,
uint32_t transaction_id,
uint32_t data_length,
const char *data)
uint32_t application_id,
uint32_t line_instance,
uint32_t call_id,
uint32_t transaction_id,
uint32_t data_length,
const char *data)
{
skinny_message_t *message;
switch_assert(data_length == strlen(data));
@@ -929,17 +929,17 @@ switch_status_t send_data(listener_t *listener, uint32_t message_type,
}
switch_status_t send_extended_data(listener_t *listener, uint32_t message_type,
uint32_t application_id,
uint32_t line_instance,
uint32_t call_id,
uint32_t transaction_id,
uint32_t data_length,
uint32_t sequence_flag,
uint32_t display_priority,
uint32_t conference_id,
uint32_t app_instance_id,
uint32_t routing_id,
const char *data)
uint32_t application_id,
uint32_t line_instance,
uint32_t call_id,
uint32_t transaction_id,
uint32_t data_length,
uint32_t sequence_flag,
uint32_t display_priority,
uint32_t conference_id,
uint32_t app_instance_id,
uint32_t routing_id,
const char *data)
{
skinny_message_t *message;
switch_assert(data_length == strlen(data));
@@ -975,16 +975,16 @@ switch_status_t skinny_perform_send_reply(listener_t *listener, const char *file
if (listener_is_ready(listener)) {
if (listener->profile->debug >= 10 || reply->type != KEEP_ALIVE_ACK_MESSAGE) {
switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_DEBUG,
"Sending %s (type=%x,length=%d) to %s:%d.\n",
skinny_message_type2str(reply->type), reply->type, reply->length,
listener->device_name, listener->device_instance);
"Sending %s (type=%x,length=%d) to %s:%d.\n",
skinny_message_type2str(reply->type), reply->type, reply->length,
listener->device_name, listener->device_instance);
}
return switch_socket_send(listener->sock, ptr, &len);
} else {
switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_WARNING,
"Not sending %s (type=%x,length=%d) to %s:%d while not ready.\n",
skinny_message_type2str(reply->type), reply->type, reply->length,
listener->device_name, listener->device_instance);
"Not sending %s (type=%x,length=%d) to %s:%d while not ready.\n",
skinny_message_type2str(reply->type), reply->type, reply->length,
listener->device_name, listener->device_instance);
return SWITCH_STATUS_FALSE;
}
}
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
+151 -151
View File
@@ -108,181 +108,181 @@ struct skinny_table SKINNY_MESSAGE_TYPES[] = {
{XML_ALARM_MESSAGE, "XMLAlarmMessage"},
{0, NULL}
};
SKINNY_DECLARE_ID2STR(skinny_message_type2str, SKINNY_MESSAGE_TYPES, "UnknownMessage")
SKINNY_DECLARE_ID2STR(skinny_message_type2str, SKINNY_MESSAGE_TYPES, "UnknownMessage")
SKINNY_DECLARE_STR2ID(skinny_str2message_type, SKINNY_MESSAGE_TYPES, -1)
struct skinny_table SKINNY_DEVICE_TYPES[] = {
{1, "Cisco 30 SP+"},
{2, "Cisco 12 SP+"},
{3, "Cisco 12 SP"},
{4, "Cisco 12"},
{5, "Cisco 30 VIP"},
{6, "Cisco IP Phone 7910"},
{7, "Cisco IP Phone 7960"},
{8, "Cisco IP Phone 7940"},
{9, "Cisco IP Phone 7935"},
{12, "Cisco ATA 186"},
{365, "Cisco IP Phone CP-7921G"},
{404, "Cisco IP Phone CP-7962G"},
{436, "Cisco IP Phone CP-7965G"},
{30018, "Cisco IP Phone CP-7961G"},
{30019, "Cisco IP Phone 7936"},
{0, NULL}
};
SKINNY_DECLARE_ID2STR(skinny_device_type2str, SKINNY_DEVICE_TYPES, "UnknownDeviceType")
struct skinny_table SKINNY_DEVICE_TYPES[] = {
{1, "Cisco 30 SP+"},
{2, "Cisco 12 SP+"},
{3, "Cisco 12 SP"},
{4, "Cisco 12"},
{5, "Cisco 30 VIP"},
{6, "Cisco IP Phone 7910"},
{7, "Cisco IP Phone 7960"},
{8, "Cisco IP Phone 7940"},
{9, "Cisco IP Phone 7935"},
{12, "Cisco ATA 186"},
{365, "Cisco IP Phone CP-7921G"},
{404, "Cisco IP Phone CP-7962G"},
{436, "Cisco IP Phone CP-7965G"},
{30018, "Cisco IP Phone CP-7961G"},
{30019, "Cisco IP Phone 7936"},
{0, NULL}
};
SKINNY_DECLARE_ID2STR(skinny_device_type2str, SKINNY_DEVICE_TYPES, "UnknownDeviceType")
SKINNY_DECLARE_STR2ID(skinny_str2device_type, SKINNY_DEVICE_TYPES, -1)
struct skinny_table SKINNY_RING_TYPES[] = {
{SKINNY_RING_OFF, "RingOff"},
{SKINNY_RING_INSIDE, "RingInside"},
{SKINNY_RING_OUTSIDE, "RingOutside"},
{SKINNY_RING_FEATURE, "RingFeature"},
{0, NULL}
};
SKINNY_DECLARE_ID2STR(skinny_ring_type2str, SKINNY_RING_TYPES, "RingTypeUnknown")
struct skinny_table SKINNY_RING_TYPES[] = {
{SKINNY_RING_OFF, "RingOff"},
{SKINNY_RING_INSIDE, "RingInside"},
{SKINNY_RING_OUTSIDE, "RingOutside"},
{SKINNY_RING_FEATURE, "RingFeature"},
{0, NULL}
};
SKINNY_DECLARE_ID2STR(skinny_ring_type2str, SKINNY_RING_TYPES, "RingTypeUnknown")
SKINNY_DECLARE_STR2ID(skinny_str2ring_type, SKINNY_RING_TYPES, -1)
struct skinny_table SKINNY_RING_MODES[] = {
{SKINNY_RING_FOREVER, "RingForever"},
{SKINNY_RING_ONCE, "RingOnce"},
{0, NULL}
};
SKINNY_DECLARE_ID2STR(skinny_ring_mode2str, SKINNY_RING_MODES, "RingModeUnknown")
struct skinny_table SKINNY_RING_MODES[] = {
{SKINNY_RING_FOREVER, "RingForever"},
{SKINNY_RING_ONCE, "RingOnce"},
{0, NULL}
};
SKINNY_DECLARE_ID2STR(skinny_ring_mode2str, SKINNY_RING_MODES, "RingModeUnknown")
SKINNY_DECLARE_STR2ID(skinny_str2ring_mode, SKINNY_RING_MODES, -1)
struct skinny_table SKINNY_BUTTONS[] = {
{SKINNY_BUTTON_UNKNOWN, "Unknown"},
{SKINNY_BUTTON_LAST_NUMBER_REDIAL, "LastNumberRedial"},
{SKINNY_BUTTON_SPEED_DIAL, "SpeedDial"},
{SKINNY_BUTTON_HOLD, "Hold"},
{SKINNY_BUTTON_TRANSFER, "Transfer"},
{SKINNY_BUTTON_LINE, "Line"},
{SKINNY_BUTTON_VOICEMAIL, "Voicemail"},
{SKINNY_BUTTON_PRIVACY, "Privacy"},
{SKINNY_BUTTON_SERVICE_URL, "ServiceUrl"},
{SKINNY_BUTTON_UNDEFINED, "Undefined"},
{0, NULL}
};
SKINNY_DECLARE_ID2STR(skinny_button2str, SKINNY_BUTTONS, "Unknown")
struct skinny_table SKINNY_BUTTONS[] = {
{SKINNY_BUTTON_UNKNOWN, "Unknown"},
{SKINNY_BUTTON_LAST_NUMBER_REDIAL, "LastNumberRedial"},
{SKINNY_BUTTON_SPEED_DIAL, "SpeedDial"},
{SKINNY_BUTTON_HOLD, "Hold"},
{SKINNY_BUTTON_TRANSFER, "Transfer"},
{SKINNY_BUTTON_LINE, "Line"},
{SKINNY_BUTTON_VOICEMAIL, "Voicemail"},
{SKINNY_BUTTON_PRIVACY, "Privacy"},
{SKINNY_BUTTON_SERVICE_URL, "ServiceUrl"},
{SKINNY_BUTTON_UNDEFINED, "Undefined"},
{0, NULL}
};
SKINNY_DECLARE_ID2STR(skinny_button2str, SKINNY_BUTTONS, "Unknown")
SKINNY_DECLARE_STR2ID(skinny_str2button, SKINNY_BUTTONS, -1)
struct skinny_table SKINNY_SOFT_KEY_EVENTS[] = {
{SOFTKEY_REDIAL, "SoftkeyRedial"},
{SOFTKEY_NEWCALL, "SoftkeyNewcall"},
{SOFTKEY_HOLD, "SoftkeyHold"},
{SOFTKEY_TRANSFER, "SoftkeyTransfer"},
{SOFTKEY_CFWDALL, "SoftkeyCfwdall"},
{SOFTKEY_CFWDBUSY, "SoftkeyCfwdbusy"},
{SOFTKEY_CFWDNOANSWER, "SoftkeyCfwdnoanswer"},
{SOFTKEY_BACKSPACE, "SoftkeyBackspace"},
{SOFTKEY_ENDCALL, "SoftkeyEndcall"},
{SOFTKEY_RESUME, "SoftkeyResume"},
{SOFTKEY_ANSWER , "SoftkeyAnswer"},
{SOFTKEY_INFO, "SoftkeyInfo"},
{SOFTKEY_CONFRM, "SoftkeyConfrm"},
{SOFTKEY_PARK, "SoftkeyPark"},
{SOFTKEY_JOIN, "SoftkeyJoin"},
{SOFTKEY_MEETMECONFRM, "SoftkeyMeetmeconfrm"},
{SOFTKEY_CALLPICKUP, "SoftkeyCallpickup"},
{SOFTKEY_GRPCALLPICKUP, "SoftkeyGrpcallpickup"},
{SOFTKEY_DND, "SoftkeyDnd"},
{SOFTKEY_IDIVERT, "SoftkeyIdivert"},
{0, NULL}
};
SKINNY_DECLARE_ID2STR(skinny_soft_key_event2str, SKINNY_SOFT_KEY_EVENTS, "SoftkeyUnknown")
struct skinny_table SKINNY_SOFT_KEY_EVENTS[] = {
{SOFTKEY_REDIAL, "SoftkeyRedial"},
{SOFTKEY_NEWCALL, "SoftkeyNewcall"},
{SOFTKEY_HOLD, "SoftkeyHold"},
{SOFTKEY_TRANSFER, "SoftkeyTransfer"},
{SOFTKEY_CFWDALL, "SoftkeyCfwdall"},
{SOFTKEY_CFWDBUSY, "SoftkeyCfwdbusy"},
{SOFTKEY_CFWDNOANSWER, "SoftkeyCfwdnoanswer"},
{SOFTKEY_BACKSPACE, "SoftkeyBackspace"},
{SOFTKEY_ENDCALL, "SoftkeyEndcall"},
{SOFTKEY_RESUME, "SoftkeyResume"},
{SOFTKEY_ANSWER , "SoftkeyAnswer"},
{SOFTKEY_INFO, "SoftkeyInfo"},
{SOFTKEY_CONFRM, "SoftkeyConfrm"},
{SOFTKEY_PARK, "SoftkeyPark"},
{SOFTKEY_JOIN, "SoftkeyJoin"},
{SOFTKEY_MEETMECONFRM, "SoftkeyMeetmeconfrm"},
{SOFTKEY_CALLPICKUP, "SoftkeyCallpickup"},
{SOFTKEY_GRPCALLPICKUP, "SoftkeyGrpcallpickup"},
{SOFTKEY_DND, "SoftkeyDnd"},
{SOFTKEY_IDIVERT, "SoftkeyIdivert"},
{0, NULL}
};
SKINNY_DECLARE_ID2STR(skinny_soft_key_event2str, SKINNY_SOFT_KEY_EVENTS, "SoftkeyUnknown")
SKINNY_DECLARE_STR2ID(skinny_str2soft_key_event, SKINNY_SOFT_KEY_EVENTS, 0)
struct skinny_table SKINNY_LAMP_MODES[] = {
{SKINNY_LAMP_OFF, "Off"},
{SKINNY_LAMP_ON, "On"},
{SKINNY_LAMP_WINK, "Wink"},
{SKINNY_LAMP_FLASH, "Flash"},
{SKINNY_LAMP_BLINK, "Blink"},
{0, NULL}
};
SKINNY_DECLARE_ID2STR(skinny_lamp_mode2str, SKINNY_LAMP_MODES, "Unknown")
struct skinny_table SKINNY_LAMP_MODES[] = {
{SKINNY_LAMP_OFF, "Off"},
{SKINNY_LAMP_ON, "On"},
{SKINNY_LAMP_WINK, "Wink"},
{SKINNY_LAMP_FLASH, "Flash"},
{SKINNY_LAMP_BLINK, "Blink"},
{0, NULL}
};
SKINNY_DECLARE_ID2STR(skinny_lamp_mode2str, SKINNY_LAMP_MODES, "Unknown")
SKINNY_DECLARE_STR2ID(skinny_str2lamp_mode, SKINNY_LAMP_MODES, -1)
struct skinny_table SKINNY_SPEAKER_MODES[] = {
{SKINNY_SPEAKER_ON, "SpeakerOn"},
{SKINNY_SPEAKER_OFF, "SpeakerOff"},
{0, NULL}
};
SKINNY_DECLARE_ID2STR(skinny_speaker_mode2str, SKINNY_SPEAKER_MODES, "Unknown")
struct skinny_table SKINNY_SPEAKER_MODES[] = {
{SKINNY_SPEAKER_ON, "SpeakerOn"},
{SKINNY_SPEAKER_OFF, "SpeakerOff"},
{0, NULL}
};
SKINNY_DECLARE_ID2STR(skinny_speaker_mode2str, SKINNY_SPEAKER_MODES, "Unknown")
SKINNY_DECLARE_STR2ID(skinny_str2speaker_mode, SKINNY_SPEAKER_MODES, -1)
struct skinny_table SKINNY_KEY_SETS[] = {
{SKINNY_KEY_SET_ON_HOOK, "KeySetOnHook"},
{SKINNY_KEY_SET_CONNECTED, "KeySetConnected"},
{SKINNY_KEY_SET_ON_HOLD, "KeySetOnHold"},
{SKINNY_KEY_SET_RING_IN, "KeySetRingIn"},
{SKINNY_KEY_SET_OFF_HOOK, "KeySetOffHook"},
{SKINNY_KEY_SET_CONNECTED_WITH_TRANSFER, "KeySetConnectedWithTransfer"},
{SKINNY_KEY_SET_DIGITS_AFTER_DIALING_FIRST_DIGIT, "KeySetDigitsAfterDialingFirstDigit"},
{SKINNY_KEY_SET_CONNECTED_WITH_CONFERENCE, "KeySetConnectedWithConference"},
{SKINNY_KEY_SET_RING_OUT, "KeySetRingOut"},
{SKINNY_KEY_SET_OFF_HOOK_WITH_FEATURES, "KeySetOffHookWithFeatures"},
{SKINNY_KEY_SET_IN_USE_HINT, "KeySetInUseHint"},
{0, NULL}
};
SKINNY_DECLARE_ID2STR(skinny_soft_key_set2str, SKINNY_KEY_SETS, "UNKNOWN_SOFT_KEY_SET")
struct skinny_table SKINNY_KEY_SETS[] = {
{SKINNY_KEY_SET_ON_HOOK, "KeySetOnHook"},
{SKINNY_KEY_SET_CONNECTED, "KeySetConnected"},
{SKINNY_KEY_SET_ON_HOLD, "KeySetOnHold"},
{SKINNY_KEY_SET_RING_IN, "KeySetRingIn"},
{SKINNY_KEY_SET_OFF_HOOK, "KeySetOffHook"},
{SKINNY_KEY_SET_CONNECTED_WITH_TRANSFER, "KeySetConnectedWithTransfer"},
{SKINNY_KEY_SET_DIGITS_AFTER_DIALING_FIRST_DIGIT, "KeySetDigitsAfterDialingFirstDigit"},
{SKINNY_KEY_SET_CONNECTED_WITH_CONFERENCE, "KeySetConnectedWithConference"},
{SKINNY_KEY_SET_RING_OUT, "KeySetRingOut"},
{SKINNY_KEY_SET_OFF_HOOK_WITH_FEATURES, "KeySetOffHookWithFeatures"},
{SKINNY_KEY_SET_IN_USE_HINT, "KeySetInUseHint"},
{0, NULL}
};
SKINNY_DECLARE_ID2STR(skinny_soft_key_set2str, SKINNY_KEY_SETS, "UNKNOWN_SOFT_KEY_SET")
SKINNY_DECLARE_STR2ID(skinny_str2soft_key_set, SKINNY_KEY_SETS, -1)
struct skinny_table SKINNY_CALL_STATES[] = {
{SKINNY_OFF_HOOK, "OffHook"},
{SKINNY_ON_HOOK, "OnHook"},
{SKINNY_RING_OUT, "RingOut"},
{SKINNY_RING_IN, "RingIn"},
{SKINNY_CONNECTED, "Connected"},
{SKINNY_BUSY, "Busy"},
{SKINNY_LINE_IN_USE, "LineInUse"},
{SKINNY_HOLD, "Hold"},
{SKINNY_CALL_WAITING, "CallWaiting"},
{SKINNY_CALL_TRANSFER, "CallTransfer"},
{SKINNY_CALL_PARK, "CallPark"},
{SKINNY_PROCEED, "Proceed"},
{SKINNY_IN_USE_REMOTELY, "InUseRemotely"},
{SKINNY_INVALID_NUMBER, "InvalidNumber"},
{0, NULL}
};
SKINNY_DECLARE_ID2STR(skinny_call_state2str, SKINNY_CALL_STATES, "CallStateUnknown")
struct skinny_table SKINNY_CALL_STATES[] = {
{SKINNY_OFF_HOOK, "OffHook"},
{SKINNY_ON_HOOK, "OnHook"},
{SKINNY_RING_OUT, "RingOut"},
{SKINNY_RING_IN, "RingIn"},
{SKINNY_CONNECTED, "Connected"},
{SKINNY_BUSY, "Busy"},
{SKINNY_LINE_IN_USE, "LineInUse"},
{SKINNY_HOLD, "Hold"},
{SKINNY_CALL_WAITING, "CallWaiting"},
{SKINNY_CALL_TRANSFER, "CallTransfer"},
{SKINNY_CALL_PARK, "CallPark"},
{SKINNY_PROCEED, "Proceed"},
{SKINNY_IN_USE_REMOTELY, "InUseRemotely"},
{SKINNY_INVALID_NUMBER, "InvalidNumber"},
{0, NULL}
};
SKINNY_DECLARE_ID2STR(skinny_call_state2str, SKINNY_CALL_STATES, "CallStateUnknown")
SKINNY_DECLARE_STR2ID(skinny_str2call_state, SKINNY_CALL_STATES, -1)
struct skinny_table SKINNY_DEVICE_RESET_TYPES[] = {
{SKINNY_DEVICE_RESET, "DeviceReset"},
{SKINNY_DEVICE_RESTART, "DeviceRestart"},
{0, NULL}
};
SKINNY_DECLARE_ID2STR(skinny_device_reset_type2str, SKINNY_DEVICE_RESET_TYPES, "DeviceResetTypeUnknown")
struct skinny_table SKINNY_DEVICE_RESET_TYPES[] = {
{SKINNY_DEVICE_RESET, "DeviceReset"},
{SKINNY_DEVICE_RESTART, "DeviceRestart"},
{0, NULL}
};
SKINNY_DECLARE_ID2STR(skinny_device_reset_type2str, SKINNY_DEVICE_RESET_TYPES, "DeviceResetTypeUnknown")
SKINNY_DECLARE_STR2ID(skinny_str2device_reset_type, SKINNY_DEVICE_RESET_TYPES, -1)
struct skinny_table SKINNY_ACCESSORY_TYPES[] = {
{SKINNY_ACCESSORY_NONE, "AccessoryNone"},
{SKINNY_ACCESSORY_HEADSET, "Headset"},
{SKINNY_ACCESSORY_HANDSET, "Handset"},
{SKINNY_ACCESSORY_SPEAKER, "Speaker"},
{0, NULL}
};
SKINNY_DECLARE_ID2STR(skinny_accessory_type2str, SKINNY_ACCESSORY_TYPES, "AccessoryUnknown")
struct skinny_table SKINNY_ACCESSORY_TYPES[] = {
{SKINNY_ACCESSORY_NONE, "AccessoryNone"},
{SKINNY_ACCESSORY_HEADSET, "Headset"},
{SKINNY_ACCESSORY_HANDSET, "Handset"},
{SKINNY_ACCESSORY_SPEAKER, "Speaker"},
{0, NULL}
};
SKINNY_DECLARE_ID2STR(skinny_accessory_type2str, SKINNY_ACCESSORY_TYPES, "AccessoryUnknown")
SKINNY_DECLARE_STR2ID(skinny_str2accessory_type, SKINNY_ACCESSORY_TYPES, -1)
struct skinny_table SKINNY_ACCESSORY_STATES[] = {
{SKINNY_ACCESSORY_STATE_NONE, "AccessoryNoState"},
{SKINNY_ACCESSORY_STATE_OFFHOOK, "OffHook"},
{SKINNY_ACCESSORY_STATE_ONHOOK, "OnHook"},
{0, NULL}
};
SKINNY_DECLARE_ID2STR(skinny_accessory_state2str, SKINNY_ACCESSORY_STATES, "AccessoryStateUnknown")
struct skinny_table SKINNY_ACCESSORY_STATES[] = {
{SKINNY_ACCESSORY_STATE_NONE, "AccessoryNoState"},
{SKINNY_ACCESSORY_STATE_OFFHOOK, "OffHook"},
{SKINNY_ACCESSORY_STATE_ONHOOK, "OnHook"},
{0, NULL}
};
SKINNY_DECLARE_ID2STR(skinny_accessory_state2str, SKINNY_ACCESSORY_STATES, "AccessoryStateUnknown")
SKINNY_DECLARE_STR2ID(skinny_str2accessory_state, SKINNY_ACCESSORY_STATES, -1)
/* For Emacs:
* Local Variables:
* mode:c
* indent-tabs-mode:t
* tab-width:4
* c-basic-offset:4
* End:
* For VIM:
* vim:set softtabstop=4 shiftwidth=4 tabstop=4:
*/
/* For Emacs:
* Local Variables:
* mode:c
* indent-tabs-mode:t
* tab-width:4
* c-basic-offset:4
* End:
* For VIM:
* vim:set softtabstop=4 shiftwidth=4 tabstop=4:
*/
+118 -118
View File
@@ -36,55 +36,55 @@
/* SKINNY TABLES */
/*****************************************************************************/
struct skinny_table {
uint32_t id;
const char *name;
uint32_t id;
const char *name;
};
#define SKINNY_DECLARE_ID2STR(func, TABLE, DEFAULT_STR) \
const char *func(uint32_t id) \
const char *func(uint32_t id) \
{ \
const char *str = DEFAULT_STR; \
uint8_t x; \
\
for (x = 0; x < (sizeof(TABLE) / sizeof(struct skinny_table)) - 1; x++) {\
if (TABLE[x].id == id) {\
str = TABLE[x].name;\
break;\
}\
}\
\
return str;\
const char *str = DEFAULT_STR; \
uint8_t x; \
\
for (x = 0; x < (sizeof(TABLE) / sizeof(struct skinny_table)) - 1; x++) {\
if (TABLE[x].id == id) {\
str = TABLE[x].name;\
break;\
}\
}\
\
return str;\
}
#define SKINNY_DECLARE_STR2ID(func, TABLE, DEFAULT_ID) \
uint32_t func(const char *str)\
uint32_t func(const char *str)\
{\
uint32_t id = (uint32_t) DEFAULT_ID;\
\
if (*str > 47 && *str < 58) {\
id = atoi(str);\
} else {\
uint8_t x;\
for (x = 0; x < (sizeof(TABLE) / sizeof(struct skinny_table)) - 1 && TABLE[x].name; x++) {\
if (!strcasecmp(TABLE[x].name, str)) {\
id = TABLE[x].id;\
break;\
}\
}\
}\
return id;\
uint32_t id = (uint32_t) DEFAULT_ID;\
\
if (*str > 47 && *str < 58) {\
id = atoi(str);\
} else {\
uint8_t x;\
for (x = 0; x < (sizeof(TABLE) / sizeof(struct skinny_table)) - 1 && TABLE[x].name; x++) {\
if (!strcasecmp(TABLE[x].name, str)) {\
id = TABLE[x].id;\
break;\
}\
}\
}\
return id;\
}
#define SKINNY_DECLARE_PUSH_MATCH(TABLE) \
switch_console_callback_match_t *my_matches = NULL;\
uint8_t x;\
for (x = 0; x < (sizeof(TABLE) / sizeof(struct skinny_table)) - 1; x++) {\
switch_console_push_match(&my_matches, TABLE[x].name);\
}\
if (my_matches) {\
*matches = my_matches;\
status = SWITCH_STATUS_SUCCESS;\
}
switch_console_callback_match_t *my_matches = NULL;\
uint8_t x;\
for (x = 0; x < (sizeof(TABLE) / sizeof(struct skinny_table)) - 1; x++) {\
switch_console_push_match(&my_matches, TABLE[x].name);\
}\
if (my_matches) {\
*matches = my_matches;\
status = SWITCH_STATUS_SUCCESS;\
}
extern struct skinny_table SKINNY_MESSAGE_TYPES[72];
@@ -98,20 +98,20 @@ uint32_t skinny_str2device_type(const char *str);
#define SKINNY_PUSH_DEVICE_TYPES SKINNY_DECLARE_PUSH_MATCH(SKINNY_DEVICE_TYPES)
enum skinny_tone {
SKINNY_TONE_SILENCE = 0x00,
SKINNY_TONE_DIALTONE = 0x21,
SKINNY_TONE_BUSYTONE = 0x23,
SKINNY_TONE_ALERT = 0x24,
SKINNY_TONE_REORDER = 0x25,
SKINNY_TONE_CALLWAITTONE = 0x2D,
SKINNY_TONE_NOTONE = 0x7F,
SKINNY_TONE_SILENCE = 0x00,
SKINNY_TONE_DIALTONE = 0x21,
SKINNY_TONE_BUSYTONE = 0x23,
SKINNY_TONE_ALERT = 0x24,
SKINNY_TONE_REORDER = 0x25,
SKINNY_TONE_CALLWAITTONE = 0x2D,
SKINNY_TONE_NOTONE = 0x7F,
};
enum skinny_ring_type {
SKINNY_RING_OFF = 1,
SKINNY_RING_INSIDE = 2,
SKINNY_RING_OUTSIDE = 3,
SKINNY_RING_FEATURE = 4
SKINNY_RING_OFF = 1,
SKINNY_RING_INSIDE = 2,
SKINNY_RING_OUTSIDE = 3,
SKINNY_RING_FEATURE = 4
};
extern struct skinny_table SKINNY_RING_TYPES[5];
const char *skinny_ring_type2str(uint32_t id);
@@ -119,8 +119,8 @@ uint32_t skinny_str2ring_type(const char *str);
#define SKINNY_PUSH_RING_TYPES SKINNY_DECLARE_PUSH_MATCH(SKINNY_RING_TYPES)
enum skinny_ring_mode {
SKINNY_RING_FOREVER = 1,
SKINNY_RING_ONCE = 2,
SKINNY_RING_FOREVER = 1,
SKINNY_RING_ONCE = 2,
};
extern struct skinny_table SKINNY_RING_MODES[3];
const char *skinny_ring_mode2str(uint32_t id);
@@ -129,11 +129,11 @@ uint32_t skinny_str2ring_mode(const char *str);
enum skinny_lamp_mode {
SKINNY_LAMP_OFF = 1,
SKINNY_LAMP_ON = 2,
SKINNY_LAMP_WINK = 3,
SKINNY_LAMP_FLASH = 4,
SKINNY_LAMP_BLINK = 5,
SKINNY_LAMP_OFF = 1,
SKINNY_LAMP_ON = 2,
SKINNY_LAMP_WINK = 3,
SKINNY_LAMP_FLASH = 4,
SKINNY_LAMP_BLINK = 5,
};
extern struct skinny_table SKINNY_LAMP_MODES[6];
const char *skinny_lamp_mode2str(uint32_t id);
@@ -141,8 +141,8 @@ uint32_t skinny_str2lamp_mode(const char *str);
#define SKINNY_PUSH_LAMP_MODES SKINNY_DECLARE_PUSH_MATCH(SKINNY_LAMP_MODES)
enum skinny_speaker_mode {
SKINNY_SPEAKER_ON = 1,
SKINNY_SPEAKER_OFF = 2,
SKINNY_SPEAKER_ON = 1,
SKINNY_SPEAKER_OFF = 2,
};
extern struct skinny_table SKINNY_SPEAKER_MODES[3];
const char *skinny_speaker_mode2str(uint32_t id);
@@ -150,22 +150,22 @@ uint32_t skinny_str2speaker_mode(const char *str);
#define SKINNY_PUSH_SPEAKER_MODES SKINNY_DECLARE_PUSH_MATCH(SKINNY_SPEAKER_MODES)
enum skinny_call_type {
SKINNY_INBOUND_CALL = 1,
SKINNY_OUTBOUND_CALL = 2,
SKINNY_FORWARD_CALL = 3,
SKINNY_INBOUND_CALL = 1,
SKINNY_OUTBOUND_CALL = 2,
SKINNY_FORWARD_CALL = 3,
};
enum skinny_button_definition {
SKINNY_BUTTON_UNKNOWN = 0x00,
SKINNY_BUTTON_LAST_NUMBER_REDIAL = 0x01,
SKINNY_BUTTON_SPEED_DIAL = 0x02,
SKINNY_BUTTON_HOLD = 0x03,
SKINNY_BUTTON_TRANSFER = 0x04,
SKINNY_BUTTON_LINE = 0x09,
SKINNY_BUTTON_VOICEMAIL = 0x0F,
SKINNY_BUTTON_PRIVACY = 0x13,
SKINNY_BUTTON_SERVICE_URL = 0x14,
SKINNY_BUTTON_UNDEFINED = 0xFF,
SKINNY_BUTTON_UNKNOWN = 0x00,
SKINNY_BUTTON_LAST_NUMBER_REDIAL = 0x01,
SKINNY_BUTTON_SPEED_DIAL = 0x02,
SKINNY_BUTTON_HOLD = 0x03,
SKINNY_BUTTON_TRANSFER = 0x04,
SKINNY_BUTTON_LINE = 0x09,
SKINNY_BUTTON_VOICEMAIL = 0x0F,
SKINNY_BUTTON_PRIVACY = 0x13,
SKINNY_BUTTON_SERVICE_URL = 0x14,
SKINNY_BUTTON_UNDEFINED = 0xFF,
};
extern struct skinny_table SKINNY_BUTTONS[11];
const char *skinny_button2str(uint32_t id);
@@ -173,26 +173,26 @@ uint32_t skinny_str2button(const char *str);
#define SKINNY_PUSH_STIMULI SKINNY_DECLARE_PUSH_MATCH(SKINNY_BUTTONS)
enum skinny_soft_key_event {
SOFTKEY_REDIAL = 0x01,
SOFTKEY_NEWCALL = 0x02,
SOFTKEY_HOLD = 0x03,
SOFTKEY_TRANSFER = 0x04,
SOFTKEY_CFWDALL = 0x05,
SOFTKEY_CFWDBUSY = 0x06,
SOFTKEY_CFWDNOANSWER = 0x07,
SOFTKEY_BACKSPACE = 0x08,
SOFTKEY_ENDCALL = 0x09,
SOFTKEY_RESUME = 0x0A,
SOFTKEY_ANSWER = 0x0B,
SOFTKEY_INFO = 0x0C,
SOFTKEY_CONFRM = 0x0D,
SOFTKEY_PARK = 0x0E,
SOFTKEY_JOIN = 0x0F,
SOFTKEY_MEETMECONFRM = 0x10,
SOFTKEY_CALLPICKUP = 0x11,
SOFTKEY_GRPCALLPICKUP = 0x12,
SOFTKEY_DND = 0x13,
SOFTKEY_IDIVERT = 0x14,
SOFTKEY_REDIAL = 0x01,
SOFTKEY_NEWCALL = 0x02,
SOFTKEY_HOLD = 0x03,
SOFTKEY_TRANSFER = 0x04,
SOFTKEY_CFWDALL = 0x05,
SOFTKEY_CFWDBUSY = 0x06,
SOFTKEY_CFWDNOANSWER = 0x07,
SOFTKEY_BACKSPACE = 0x08,
SOFTKEY_ENDCALL = 0x09,
SOFTKEY_RESUME = 0x0A,
SOFTKEY_ANSWER = 0x0B,
SOFTKEY_INFO = 0x0C,
SOFTKEY_CONFRM = 0x0D,
SOFTKEY_PARK = 0x0E,
SOFTKEY_JOIN = 0x0F,
SOFTKEY_MEETMECONFRM = 0x10,
SOFTKEY_CALLPICKUP = 0x11,
SOFTKEY_GRPCALLPICKUP = 0x12,
SOFTKEY_DND = 0x13,
SOFTKEY_IDIVERT = 0x14,
};
extern struct skinny_table SKINNY_SOFT_KEY_EVENTS[21];
const char *skinny_soft_key_event2str(uint32_t id);
@@ -200,17 +200,17 @@ uint32_t skinny_str2soft_key_event(const char *str);
#define SKINNY_PUSH_SOFT_KEY_EVENTS SKINNY_DECLARE_PUSH_MATCH(SOFT_KEY_EVENTS)
enum skinny_key_set {
SKINNY_KEY_SET_ON_HOOK = 0,
SKINNY_KEY_SET_CONNECTED = 1,
SKINNY_KEY_SET_ON_HOLD = 2,
SKINNY_KEY_SET_RING_IN = 3,
SKINNY_KEY_SET_OFF_HOOK = 4,
SKINNY_KEY_SET_CONNECTED_WITH_TRANSFER = 5,
SKINNY_KEY_SET_DIGITS_AFTER_DIALING_FIRST_DIGIT = 6,
SKINNY_KEY_SET_CONNECTED_WITH_CONFERENCE = 7,
SKINNY_KEY_SET_RING_OUT = 8,
SKINNY_KEY_SET_OFF_HOOK_WITH_FEATURES = 9,
SKINNY_KEY_SET_IN_USE_HINT = 10,
SKINNY_KEY_SET_ON_HOOK = 0,
SKINNY_KEY_SET_CONNECTED = 1,
SKINNY_KEY_SET_ON_HOLD = 2,
SKINNY_KEY_SET_RING_IN = 3,
SKINNY_KEY_SET_OFF_HOOK = 4,
SKINNY_KEY_SET_CONNECTED_WITH_TRANSFER = 5,
SKINNY_KEY_SET_DIGITS_AFTER_DIALING_FIRST_DIGIT = 6,
SKINNY_KEY_SET_CONNECTED_WITH_CONFERENCE = 7,
SKINNY_KEY_SET_RING_OUT = 8,
SKINNY_KEY_SET_OFF_HOOK_WITH_FEATURES = 9,
SKINNY_KEY_SET_IN_USE_HINT = 10,
};
extern struct skinny_table SKINNY_KEY_SETS[12];
const char *skinny_soft_key_set2str(uint32_t id);
@@ -219,20 +219,20 @@ uint32_t skinny_str2soft_key_set(const char *str);
enum skinny_call_state {
SKINNY_OFF_HOOK = 1,
SKINNY_ON_HOOK = 2,
SKINNY_RING_OUT = 3,
SKINNY_RING_IN = 4,
SKINNY_CONNECTED = 5,
SKINNY_BUSY = 6,
SKINNY_LINE_IN_USE = 7,
SKINNY_HOLD = 8,
SKINNY_CALL_WAITING = 9,
SKINNY_CALL_TRANSFER = 10,
SKINNY_CALL_PARK = 11,
SKINNY_PROCEED = 12,
SKINNY_IN_USE_REMOTELY = 13,
SKINNY_INVALID_NUMBER = 14
SKINNY_OFF_HOOK = 1,
SKINNY_ON_HOOK = 2,
SKINNY_RING_OUT = 3,
SKINNY_RING_IN = 4,
SKINNY_CONNECTED = 5,
SKINNY_BUSY = 6,
SKINNY_LINE_IN_USE = 7,
SKINNY_HOLD = 8,
SKINNY_CALL_WAITING = 9,
SKINNY_CALL_TRANSFER = 10,
SKINNY_CALL_PARK = 11,
SKINNY_PROCEED = 12,
SKINNY_IN_USE_REMOTELY = 13,
SKINNY_INVALID_NUMBER = 14
};
extern struct skinny_table SKINNY_CALL_STATES[15];
const char *skinny_call_state2str(uint32_t id);
@@ -240,8 +240,8 @@ uint32_t skinny_str2call_state(const char *str);
#define SKINNY_PUSH_CALL_STATES SKINNY_DECLARE_PUSH_MATCH(SKINNY_CALL_STATES)
enum skinny_device_reset_types {
SKINNY_DEVICE_RESET = 1,
SKINNY_DEVICE_RESTART = 2
SKINNY_DEVICE_RESET = 1,
SKINNY_DEVICE_RESTART = 2
};
extern struct skinny_table SKINNY_DEVICE_RESET_TYPES[3];
const char *skinny_device_reset_type2str(uint32_t id);
+124 -27
View File
@@ -37,6 +37,7 @@
/*************************************************************************************************************************************************************/
#include "mod_sofia.h"
#include "sofia-sip/sip_extra.h"
SWITCH_MODULE_LOAD_FUNCTION(mod_sofia_load);
SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_sofia_shutdown);
SWITCH_MODULE_DEFINITION(mod_sofia, mod_sofia_load, mod_sofia_shutdown, NULL);
@@ -523,6 +524,12 @@ switch_status_t sofia_on_hangup(switch_core_session_t *session)
if (!sofia_test_flag(tech_pvt, TFLAG_BYE)) {
char *cid = generate_pai_str(tech_pvt);
if (sip_cause > 299) {
switch_channel_clear_app_flag_key("T38", tech_pvt->channel, CF_APP_T38);
switch_channel_clear_app_flag_key("T38", tech_pvt->channel, CF_APP_T38_REQ);
switch_channel_set_app_flag_key("T38", tech_pvt->channel, CF_APP_T38_FAIL);
}
nua_respond(tech_pvt->nh, sip_cause, sip_status_phrase(sip_cause),
TAG_IF(!zstr(reason), SIPTAG_REASON_STR(reason)),
TAG_IF(cid, SIPTAG_HEADER_STR(cid)), TAG_IF(!zstr(bye_headers), SIPTAG_HEADER_STR(bye_headers)), TAG_END());
@@ -568,9 +575,31 @@ static switch_status_t sofia_answer_channel(switch_core_session_t *session)
const char *val;
const char *b_sdp = NULL;
int is_proxy = 0;
int is_3pcc = 0;
char *sticky = NULL;
const char *call_info = switch_channel_get_variable(channel, "presence_call_info_full");
if(sofia_test_flag(tech_pvt, TFLAG_3PCC_INVITE)) {
// SNARK: complete hack to get final ack sent when a 3pcc invite has been passed from the other leg in bypass_media mode.
// This code handles the pass_indication sent after the 3pcc ack is received by the other leg in the is_3pcc && is_proxy case below.
// Is there a better place to hang this...?
b_sdp = switch_channel_get_variable(channel, SWITCH_B_SDP_VARIABLE);
sofia_glue_tech_set_local_sdp(tech_pvt, b_sdp, SWITCH_TRUE);
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "3PCC-PROXY nomedia - sending ack\n");
nua_ack(tech_pvt->nh,
TAG_IF(!zstr(tech_pvt->user_via), SIPTAG_VIA_STR(tech_pvt->user_via)),
SIPTAG_CONTACT_STR(tech_pvt->reply_contact),
SOATAG_USER_SDP_STR(tech_pvt->local_sdp_str),
SOATAG_REUSE_REJECTED(1),
SOATAG_RTP_SELECT(1), SOATAG_ORDERED_USER(1), SOATAG_AUDIO_AUX("cn telephone-event"),
TAG_IF(sofia_test_pflag(tech_pvt->profile, PFLAG_DISABLE_100REL), NUTAG_INCLUDE_EXTRA_SDP(1)),
TAG_END());
sofia_clear_flag(tech_pvt, TFLAG_3PCC_INVITE); // all done
return SWITCH_STATUS_SUCCESS;
}
if (sofia_test_flag(tech_pvt, TFLAG_ANS) || switch_channel_direction(channel) == SWITCH_CALL_DIRECTION_OUTBOUND) {
return SWITCH_STATUS_SUCCESS;
}
@@ -578,8 +607,9 @@ static switch_status_t sofia_answer_channel(switch_core_session_t *session)
b_sdp = switch_channel_get_variable(channel, SWITCH_B_SDP_VARIABLE);
is_proxy = (switch_channel_test_flag(channel, CF_PROXY_MODE) || switch_channel_test_flag(channel, CF_PROXY_MEDIA));
is_3pcc = (sofia_test_pflag(tech_pvt->profile, PFLAG_3PCC_PROXY) && sofia_test_flag(tech_pvt, TFLAG_3PCC));
if (b_sdp && is_proxy) {
if (b_sdp && is_proxy && !is_3pcc) {
sofia_glue_tech_set_local_sdp(tech_pvt, b_sdp, SWITCH_TRUE);
if (switch_channel_test_flag(channel, CF_PROXY_MEDIA)) {
@@ -590,23 +620,35 @@ static switch_status_t sofia_answer_channel(switch_core_session_t *session)
}
} else {
/* This if statement check and handles the 3pcc proxy mode */
if (sofia_test_pflag(tech_pvt->profile, PFLAG_3PCC_PROXY) && sofia_test_flag(tech_pvt, TFLAG_3PCC)) {
if (is_3pcc) {
if(!is_proxy) {
tech_pvt->num_codecs = 0;
sofia_glue_tech_prepare_codecs(tech_pvt);
tech_pvt->local_sdp_str = NULL;
sofia_glue_tech_choose_port(tech_pvt, 0);
sofia_glue_set_local_sdp(tech_pvt, NULL, 0, NULL, 0);
} else {
sofia_glue_tech_set_local_sdp(tech_pvt, b_sdp, SWITCH_TRUE);
if (switch_channel_test_flag(channel, CF_PROXY_MEDIA)) {
sofia_glue_tech_patch_sdp(tech_pvt);
if (sofia_glue_activate_rtp(tech_pvt, 0) != SWITCH_STATUS_SUCCESS) {
return SWITCH_STATUS_FALSE;
}
}
}
/* Send the 200 OK */
if (!sofia_test_flag(tech_pvt, TFLAG_BYE)) {
char *extra_headers = sofia_glue_get_extra_headers(channel, SOFIA_SIP_RESPONSE_HEADER_PREFIX);
if (sofia_use_soa(tech_pvt)) {
nua_respond(tech_pvt->nh, SIP_200_OK,
TAG_IF(is_proxy, NUTAG_AUTOANSWER(0)),
SIPTAG_CONTACT_STR(tech_pvt->profile->url),
SOATAG_USER_SDP_STR(tech_pvt->local_sdp_str),
TAG_IF(call_info, SIPTAG_CALL_INFO_STR(call_info)),
SOATAG_REUSE_REJECTED(1),
SOATAG_REUSE_REJECTED(1), TAG_IF(is_proxy, SOATAG_RTP_SELECT(1)),
SOATAG_ORDERED_USER(1), SOATAG_AUDIO_AUX("cn telephone-event"), NUTAG_INCLUDE_EXTRA_SDP(1),
TAG_IF(!zstr(extra_headers), SIPTAG_HEADER_STR(extra_headers)),
TAG_IF(switch_stristr("update_display", tech_pvt->x_freeswitch_support_remote),
@@ -638,6 +680,14 @@ static switch_status_t sofia_answer_channel(switch_core_session_t *session)
/* Regain lock on sofia */
switch_mutex_lock(tech_pvt->sofia_mutex);
if(is_proxy) {
sofia_clear_flag(tech_pvt, TFLAG_3PCC_HAS_ACK);
sofia_clear_flag(tech_pvt, TFLAG_3PCC);
// This sends the message to the other leg that causes it to call the TFLAG_3PCC_INVITE code at the start of this function.
// Is there another message it would be better to hang this on though?
switch_core_session_pass_indication(session, SWITCH_MESSAGE_INDICATE_ANSWER);
}
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "3PCC-PROXY, Done waiting for ACK\n");
return SWITCH_STATUS_SUCCESS;
}
@@ -1344,7 +1394,7 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi
case SWITCH_MESSAGE_INDICATE_JITTER_BUFFER:
{
if (switch_rtp_ready(tech_pvt->rtp_session)) {
int len, maxlen = 0, qlen = 0, maxqlen = 50, max_drift = 0;
int len = 0, maxlen = 0, qlen = 0, maxqlen = 50, max_drift = 0;
if (msg->string_arg) {
char *p, *q;
@@ -1625,7 +1675,7 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi
ip = switch_channel_get_variable(channel, SWITCH_REMOTE_MEDIA_IP_VARIABLE);
port = switch_channel_get_variable(channel, SWITCH_REMOTE_MEDIA_PORT_VARIABLE);
if (ip && port) {
sofia_glue_set_local_sdp(tech_pvt, ip, atoi(port), msg->string_arg, 1);
sofia_glue_set_local_sdp(tech_pvt, ip, (switch_port_t)atoi(port), msg->string_arg, 1);
}
if (!sofia_test_flag(tech_pvt, TFLAG_BYE)) {
@@ -1665,7 +1715,7 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi
port = switch_channel_get_variable(other_channel, SWITCH_REMOTE_MEDIA_PORT_VARIABLE);
switch_core_session_rwunlock(other_session);
if (ip && port) {
sofia_glue_set_local_sdp(tech_pvt, ip, atoi(port), NULL, 1);
sofia_glue_set_local_sdp(tech_pvt, ip, (switch_port_t)atoi(port), NULL, 1);
}
}
@@ -1684,6 +1734,10 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi
switch_channel_get_name(channel), msg->string_arg);
sofia_glue_tech_set_local_sdp(tech_pvt, msg->string_arg, SWITCH_TRUE);
if(zstr(tech_pvt->local_sdp_str)) {
sofia_set_flag(tech_pvt, TFLAG_3PCC_INVITE);
}
sofia_set_flag_locked(tech_pvt, TFLAG_SENT_UPDATE);
switch_channel_set_flag(channel, CF_REQ_MEDIA);
sofia_glue_do_invite(session);
@@ -2182,6 +2236,23 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi
SIPTAG_PAYLOAD_STR(tech_pvt->local_sdp_str),
TAG_IF(!zstr(extra_headers), SIPTAG_HEADER_STR(extra_headers)), TAG_END());
}
if (sofia_test_pflag(tech_pvt->profile, PFLAG_3PCC_PROXY) && sofia_test_flag(tech_pvt, TFLAG_3PCC)) {
/* Unlock the session signal to allow the ack to make it in */
// Maybe we should timeout?
switch_mutex_unlock(tech_pvt->sofia_mutex);
while (switch_channel_ready(channel) && !sofia_test_flag(tech_pvt, TFLAG_3PCC_HAS_ACK)) {
switch_cond_next();
}
/* Regain lock on sofia */
switch_mutex_lock(tech_pvt->sofia_mutex);
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "3PCC-PROXY, Done waiting for ACK\n");
sofia_clear_flag(tech_pvt, TFLAG_3PCC);
sofia_clear_flag(tech_pvt, TFLAG_3PCC_HAS_ACK);
switch_core_session_pass_indication(session, SWITCH_MESSAGE_INDICATE_ANSWER);
}
} else {
nua_respond(tech_pvt->nh, code, su_strdup(nua_handle_home(tech_pvt->nh), reason), SIPTAG_CONTACT_STR(tech_pvt->reply_contact),
TAG_IF(!zstr(extra_headers), SIPTAG_HEADER_STR(extra_headers)), TAG_END());
@@ -3208,6 +3279,19 @@ static switch_status_t cmd_profile(char **argv, int argc, switch_stream_handle_t
goto done;
}
if (!strcasecmp(argv[1], "check_sync")) {
if (argc > 2) {
sofia_reg_check_call_id(profile, argv[2]);
stream->write_function(stream, "+OK syncing all registrations matching specified call_id\n");
} else {
sofia_reg_check_sync(profile);
stream->write_function(stream, "+OK syncing all registrations\n");
}
goto done;
}
if (!strcasecmp(argv[1], "flush_inbound_reg")) {
int reboot = 0;
@@ -3879,22 +3963,23 @@ SWITCH_STANDARD_API(sofia_function)
switch_status_t status = SWITCH_STATUS_SUCCESS;
sofia_command_t func = NULL;
int lead = 1;
const char *usage_string = "USAGE:\n"
static const char usage_string[] = "USAGE:\n"
"--------------------------------------------------------------------------------\n"
"sofia help\n"
"sofia profile <profile_name> [[start|stop|restart|rescan]|"
"flush_inbound_reg [<call_id>|<[user]@domain>] [reboot]|"
"[register|unregister] [<gateway name>|all]|"
"killgw <gateway name>|"
"[stun-auto-disable|stun-enabled] [true|false]]|"
"siptrace <on|off>|"
"watchdog <on|off>\n"
"sofia status|xmlstatus profile <name> [ reg <contact str> ] | [ pres <pres str> ] | [ user <user@domain> ]\n"
"sofia status|xmlstatus gateway <name>\n"
"sofia global siptrace <on|off>\n"
" watchdog <on|off>\n\n"
"sofia profile <name> [start | stop | restart | rescan]\n"
" flush_inbound_reg [<call_id> | <[user]@domain>] [reboot]\n"
" check_sync [<call_id> | <[user]@domain>]\n"
" [register | unregister] [<gateway name> | all]\n"
" killgw <gateway name>\n"
" [stun-auto-disable | stun-enabled] [true | false]]\n"
" siptrace <on|off>\n"
" watchdog <on|off>\n\n"
"sofia <status|xmlstatus> profile <name> [reg <contact str>] | [pres <pres str>] | [user <user@domain>]\n"
"sofia <status|xmlstatus> gateway <name>\n\n"
"sofia loglevel <all|default|tport|iptsec|nea|nta|nth_client|nth_server|nua|soa|sresolv|stun> [0-9]\n"
"sofia tracelevel <console|alert|crit|err|warning|notice|info|debug>\n"
"sofia global siptrace <on|off>|"
"watchdog <on|off>\n"
"sofia tracelevel <console|alert|crit|err|warning|notice|info|debug>\n\n"
"sofia help\n"
"--------------------------------------------------------------------------------\n";
if (zstr(cmd)) {
@@ -4080,6 +4165,7 @@ static switch_call_cause_t sofia_outgoing_channel(switch_core_session_t *session
char *not_const = NULL;
int cid_locked = 0;
switch_channel_t *o_channel = NULL;
sofia_gateway_t *gateway_ptr = NULL;
*new_session = NULL;
@@ -4119,7 +4205,6 @@ static switch_call_cause_t sofia_outgoing_channel(switch_core_session_t *session
if (!strncasecmp(profile_name, "gateway/", 8)) {
char *gw, *params;
sofia_gateway_t *gateway_ptr = NULL;
if (!(gw = strchr(profile_name, '/'))) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Invalid URL\n");
@@ -4147,8 +4232,6 @@ static switch_call_cause_t sofia_outgoing_channel(switch_core_session_t *session
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Gateway is down!\n");
cause = SWITCH_CAUSE_NETWORK_OUT_OF_ORDER;
gateway_ptr->ob_failed_calls++;
sofia_reg_release_gateway(gateway_ptr);
gateway_ptr = NULL;
goto error;
}
@@ -4475,6 +4558,14 @@ static switch_call_cause_t sofia_outgoing_channel(switch_core_session_t *session
} else {
sofia_clear_flag(ctech_pvt, TFLAG_ENABLE_SOA);
}
/* SNARK: lets copy this across so we can see if we're the other leg of 3PCC + bypass_media... */
if (sofia_test_flag(ctech_pvt, TFLAG_3PCC) && (switch_channel_test_flag(o_channel, CF_PROXY_MODE) || switch_channel_test_flag(o_channel, CF_PROXY_MEDIA))) {
sofia_set_flag(tech_pvt, TFLAG_3PCC_INVITE);
sofia_set_flag(tech_pvt, TFLAG_LATE_NEGOTIATION);
} else {
sofia_clear_flag(tech_pvt, TFLAG_3PCC_INVITE);
}
}
if (switch_channel_test_flag(o_channel, CF_PROXY_MEDIA)) {
@@ -4494,6 +4585,10 @@ static switch_call_cause_t sofia_outgoing_channel(switch_core_session_t *session
goto done;
error:
if (gateway_ptr) {
sofia_reg_release_gateway(gateway_ptr);
}
if (nsession) {
switch_core_session_destroy(&nsession);
}
@@ -4730,7 +4825,7 @@ static void general_event_handler(switch_event_t *event)
id = switch_mprintf("sip:%s@%s", user, host);
switch_assert(id);
for (m = list->head; m; m = m->next) {
contact = sofia_glue_get_url_from_contact(m->val, 0);
@@ -4743,10 +4838,9 @@ static void general_event_handler(switch_event_t *event)
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);
@@ -4892,6 +4986,8 @@ static void general_event_handler(switch_event_t *event)
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "EVENT_TRAP: IP change detected\n");
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "IP change detected [%s]->[%s] [%s]->[%s]\n", old_ip4, new_ip4, old_ip6, new_ip6);
strncpy(mod_sofia_globals.guess_ip, new_ip4, sizeof(mod_sofia_globals.guess_ip));
switch_mutex_lock(mod_sofia_globals.hash_mutex);
if (mod_sofia_globals.profile_hash) {
for (hi = switch_hash_first(NULL, mod_sofia_globals.profile_hash); hi; hi = switch_hash_next(hi)) {
@@ -5181,6 +5277,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_sofia_load)
switch_console_set_complete("add sofia profile ::sofia::list_profiles restart");
switch_console_set_complete("add sofia profile ::sofia::list_profiles flush_inbound_reg");
switch_console_set_complete("add sofia profile ::sofia::list_profiles check_sync");
switch_console_set_complete("add sofia profile ::sofia::list_profiles register ::sofia::list_profile_gateway");
switch_console_set_complete("add sofia profile ::sofia::list_profiles unregister ::sofia::list_profile_gateway");
switch_console_set_complete("add sofia profile ::sofia::list_profiles killgw ::sofia::list_profile_gateway");
+6 -2
View File
@@ -294,6 +294,8 @@ typedef enum {
TFLAG_AUTOFLUSH_DURING_BRIDGE,
TFLAG_NOTIMER_DURING_BRIDGE,
TFLAG_JB_PAUSED,
TFLAG_3PCC_INVITE,
TFLAG_NOREPLY,
/* No new flags below this line */
TFLAG_MAX
} TFLAGS;
@@ -795,7 +797,7 @@ switch_status_t sofia_glue_activate_rtp(private_object_t *tech_pvt, switch_rtp_f
void sofia_glue_deactivate_rtp(private_object_t *tech_pvt);
void sofia_glue_set_local_sdp(private_object_t *tech_pvt, const char *ip, uint32_t port, const char *sr, int force);
void sofia_glue_set_local_sdp(private_object_t *tech_pvt, const char *ip, switch_port_t port, const char *sr, int force);
void sofia_glue_tech_prepare_codecs(private_object_t *tech_pvt);
@@ -982,6 +984,8 @@ void sofia_glue_tech_patch_sdp(private_object_t *tech_pvt);
switch_status_t sofia_glue_tech_proxy_remote_addr(private_object_t *tech_pvt);
void sofia_presence_event_thread_start(void);
void sofia_reg_expire_call_id(sofia_profile_t *profile, const char *call_id, int reboot);
void sofia_reg_check_call_id(sofia_profile_t *profile, const char *call_id);
void sofia_reg_check_sync(sofia_profile_t *profile);
switch_status_t sofia_glue_tech_choose_video_port(private_object_t *tech_pvt, int force);
switch_status_t sofia_glue_tech_set_video_codec(private_object_t *tech_pvt, int force);
char *sofia_glue_get_register_host(const char *uri);
@@ -1065,6 +1069,6 @@ void sofia_glue_proxy_codec(switch_core_session_t *session, const char *r_sdp);
switch_status_t sofia_glue_sdp_map(const char *r_sdp, switch_event_t **fmtp, switch_event_t **pt);
void sofia_glue_build_vid_refresh_message(switch_core_session_t *session, const char *pl);
void sofia_glue_check_dtmf_type(private_object_t *tech_pvt);
void sofia_glue_parse_rtp_bugs(uint32_t *flag_pole, const char *str);
void sofia_glue_parse_rtp_bugs(switch_rtp_bug_flag_t *flag_pole, const char *str);
char *sofia_glue_gen_contact_str(sofia_profile_t *profile, sip_t const *sip, sofia_nat_parse_t *np);
void sofia_glue_pause_jitterbuffer(switch_core_session_t *session, switch_bool_t on);
+215 -17
View File
@@ -1326,6 +1326,10 @@ void *SWITCH_THREAD_FUNC sofia_profile_worker_thread_run(switch_thread_t *thread
(statements == 0 || (statements <= 1024 && (switch_micro_time_now() - last_commit)/1000 < profile->trans_timeout)))) {
switch_interval_time_t sleepy_time = !statements ? 1000000 : switch_micro_time_now() - last_commit - profile->trans_timeout*1000;
if (sleepy_time < 1000 || sleepy_time > 1000000) {
sleepy_time = 1000;
}
if (sql || (switch_queue_pop_timeout(profile->sql_queue, &pop, sleepy_time) == SWITCH_STATUS_SUCCESS && pop)) {
switch_size_t newlen;
@@ -4157,6 +4161,16 @@ static void sofia_handle_sip_r_invite(switch_core_session_t *session, int status
tech_pvt->last_sdp_str = switch_core_session_strdup(session, sip->sip_payload->pl_data);
}
if (status > 299 && switch_channel_test_app_flag_key("T38", tech_pvt->channel, CF_APP_T38_REQ)) {
switch_channel_set_private(channel, "t38_options", NULL);
switch_channel_clear_app_flag_key("T38", tech_pvt->channel, CF_APP_T38);
switch_channel_clear_app_flag_key("T38", tech_pvt->channel, CF_APP_T38_REQ);
switch_channel_set_app_flag_key("T38", tech_pvt->channel, CF_APP_T38_FAIL);
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s T38 invite failed\n", switch_channel_get_name(tech_pvt->channel));
}
if (sofia_test_pflag(profile, PFLAG_MANAGE_SHARED_APPEARANCE)) {
if (channel && sip->sip_call_info) {
char *p;
@@ -4373,6 +4387,11 @@ static void sofia_handle_sip_r_invite(switch_core_session_t *session, int status
if (sofia_test_pflag(profile, PFLAG_MANUAL_REDIRECT)) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Redirect: Transfering to %s %s %s\n",
p_contact->m_url->url_user, sip_redirect_dialplan, sip_redirect_context);
if (switch_true(switch_channel_get_variable(channel, "recording_follow_transfer"))) {
switch_core_media_bug_transfer_recordings(session, a_session);
}
switch_ivr_session_transfer(a_session, p_contact->m_url->url_user, sip_redirect_dialplan, sip_redirect_context);
switch_channel_hangup(channel, SWITCH_CAUSE_REDIRECTION_TO_NEW_DESTINATION);
} else if ((!strcmp(profile->sipip, p_contact->m_url->url_host))
@@ -4380,6 +4399,11 @@ static void sofia_handle_sip_r_invite(switch_core_session_t *session, int status
|| (switch_xml_locate_domain(p_contact->m_url->url_host, NULL, &root, &domain) == SWITCH_STATUS_SUCCESS)) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Redirect: Transfering to %s\n",
p_contact->m_url->url_user);
if (switch_true(switch_channel_get_variable(channel, "recording_follow_transfer"))) {
switch_core_media_bug_transfer_recordings(session, a_session);
}
switch_ivr_session_transfer(a_session, p_contact->m_url->url_user, NULL, NULL);
switch_channel_hangup(channel, SWITCH_CAUSE_REDIRECTION_TO_NEW_DESTINATION);
switch_xml_free(root);
@@ -4448,6 +4472,9 @@ static void sofia_handle_sip_r_invite(switch_core_session_t *session, int status
switch_channel_set_private(other_channel, "t38_options", NULL);
sofia_clear_flag(tech_pvt, TFLAG_T38_PASSTHRU);
sofia_clear_flag(other_tech_pvt, TFLAG_T38_PASSTHRU);
switch_channel_clear_app_flag_key("T38", tech_pvt->channel, CF_APP_T38);
switch_channel_clear_app_flag_key("T38", tech_pvt->channel, CF_APP_T38_REQ);
switch_channel_set_app_flag_key("T38", tech_pvt->channel, CF_APP_T38_FAIL);
} else if (status == 200 && sofia_test_flag(tech_pvt, TFLAG_T38_PASSTHRU) && has_t38 && sip->sip_payload && sip->sip_payload->pl_data) {
switch_t38_options_t *t38_options = sofia_glue_extract_t38_options(session, sip->sip_payload->pl_data);
@@ -4520,7 +4547,9 @@ static void sofia_handle_sip_r_invite(switch_core_session_t *session, int status
}
}
switch_core_session_queue_message(other_session, msg);
/* SNARK: message to respond to reinvite wasn't being delivered in 3pcc+bypass media case. */
//switch_core_session_queue_message(other_session, msg);
switch_core_session_receive_message(other_session, msg);
switch_core_session_rwunlock(other_session);
}
@@ -4694,6 +4723,7 @@ static void sofia_handle_sip_i_state(switch_core_session_t *session, int status,
const char *uuid;
switch_core_session_t *other_session = NULL;
switch_channel_t *other_channel = NULL;
//private_object_t *other_tech_pvt = NULL;
char st[80] = "";
int is_dup_sdp = 0;
switch_event_t *s_event = NULL;
@@ -4894,6 +4924,24 @@ static void sofia_handle_sip_i_state(switch_core_session_t *session, int status,
break;
case nua_callstate_completing:
{
if (r_sdp && sofia_test_flag(tech_pvt, TFLAG_3PCC_INVITE) && !sofia_test_flag(tech_pvt, TFLAG_SDP)) {
sofia_set_flag(tech_pvt, TFLAG_SDP);
if ((uuid = switch_channel_get_variable(channel, SWITCH_SIGNAL_BOND_VARIABLE))
&& (other_session = switch_core_session_locate(uuid))) {
other_channel = switch_core_session_get_channel(other_session);
//other_tech_pvt = switch_core_session_get_private(other_session);
if (!switch_channel_get_variable(other_channel, SWITCH_B_SDP_VARIABLE)) {
switch_channel_set_variable(other_channel, SWITCH_B_SDP_VARIABLE, r_sdp);
}
switch_core_session_queue_indication(other_session, SWITCH_MESSAGE_INDICATE_ANSWER);
switch_core_session_rwunlock(other_session);
}
goto done;
}
if (sofia_test_pflag(profile, PFLAG_TRACK_CALLS)) {
const char *invite_full_via = switch_channel_get_variable(tech_pvt->channel, "sip_invite_full_via");
const char *invite_route_uri = switch_channel_get_variable(tech_pvt->channel, "sip_invite_route_uri");
@@ -4971,6 +5019,14 @@ static void sofia_handle_sip_i_state(switch_core_session_t *session, int status,
char *br_a = b_private->uuid;
if (br_b) {
switch_core_session_t *tmp;
if (switch_true(switch_channel_get_variable(channel, "recording_follow_transfer")) &&
(tmp = switch_core_session_locate(br_a))) {
switch_core_media_bug_transfer_recordings(session, tmp);
switch_core_session_rwunlock(tmp);
}
switch_ivr_uuid_bridge(br_a, br_b);
switch_channel_set_variable(channel, SWITCH_ENDPOINT_DISPOSITION_VARIABLE, "ATTENDED_TRANSFER");
sofia_clear_flag_locked(tech_pvt, TFLAG_SIP_HOLD);
@@ -4998,10 +5054,12 @@ static void sofia_handle_sip_i_state(switch_core_session_t *session, int status,
switch_channel_hangup(channel, SWITCH_CAUSE_INCOMPATIBLE_DESTINATION);
}
} else {
if (sofia_test_pflag(profile, PFLAG_3PCC)) {
if (switch_channel_test_flag(channel, CF_PROXY_MODE) || switch_channel_test_flag(channel, CF_PROXY_MEDIA)) {
goto done;
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "No SDP in INVITE and 3pcc=yes cannot work with bypass or proxy media, hanging up.\n");
switch_channel_set_variable(channel, SWITCH_ENDPOINT_DISPOSITION_VARIABLE, "3PCC DISABLED");
switch_channel_hangup(channel, SWITCH_CAUSE_MANDATORY_IE_MISSING);
} else {
if (sofia_test_pflag(profile, PFLAG_3PCC)) {
switch_channel_set_variable(channel, SWITCH_ENDPOINT_DISPOSITION_VARIABLE, "RECEIVED_NOSDP");
sofia_glue_tech_choose_port(tech_pvt, 0);
sofia_glue_set_local_sdp(tech_pvt, NULL, 0, NULL, 0);
@@ -5020,8 +5078,10 @@ static void sofia_handle_sip_i_state(switch_core_session_t *session, int status,
SIPTAG_CONTACT_STR(tech_pvt->profile->url),
SIPTAG_CONTENT_TYPE_STR("application/sdp"), SIPTAG_PAYLOAD_STR(tech_pvt->local_sdp_str), TAG_END());
}
}
} else if (sofia_test_pflag(profile, PFLAG_3PCC_PROXY)) {
//3PCC proxy mode delays the 200 OK until the call is answered
// so can be made to work with bypass media as we have time to find out what the other end thinks codec offer should be...
switch_channel_set_variable(channel, SWITCH_ENDPOINT_DISPOSITION_VARIABLE, "RECEIVED_NOSDP");
sofia_set_flag_locked(tech_pvt, TFLAG_3PCC);
//sofia_glue_tech_choose_port(tech_pvt, 0);
@@ -5036,11 +5096,29 @@ static void sofia_handle_sip_i_state(switch_core_session_t *session, int status,
}
goto done;
}
}
} else if (tech_pvt && sofia_test_flag(tech_pvt, TFLAG_SDP) && !r_sdp) {
nua_respond(tech_pvt->nh, SIP_200_OK, TAG_END());
sofia_set_flag_locked(tech_pvt, TFLAG_NOSDP_REINVITE);
if ((switch_channel_test_flag(channel, CF_PROXY_MODE) || switch_channel_test_flag(channel, CF_PROXY_MEDIA)) && sofia_test_pflag(profile, PFLAG_3PCC_PROXY)) {
sofia_set_flag_locked(tech_pvt, TFLAG_3PCC);
if ((uuid = switch_channel_get_variable(channel, SWITCH_SIGNAL_BOND_VARIABLE))
&& (other_session = switch_core_session_locate(uuid))) {
switch_core_session_message_t *msg;
msg = switch_core_session_alloc(other_session, sizeof(*msg));
msg->message_id = SWITCH_MESSAGE_INDICATE_MEDIA_REDIRECT;
msg->from = __FILE__;
msg->string_arg = NULL;
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Passing NOSDP to other leg.\n");
switch_core_session_queue_message(other_session, msg);
switch_core_session_rwunlock(other_session);
} else {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING,
"NOSDP Re-INVITE to a proxy mode channel that is not in a bridge.\n");
switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
}
goto done;
}
nua_respond(tech_pvt->nh, SIP_200_OK, TAG_END());
goto done;
} else {
ss_state = nua_callstate_completed;
@@ -5052,12 +5130,10 @@ static void sofia_handle_sip_i_state(switch_core_session_t *session, int status,
break;
case nua_callstate_completed:
if (r_sdp) {
const char *var;
uint8_t match = 0, is_ok = 1, is_t38 = 0;
tech_pvt->hold_laps = 0;
if (r_sdp) {
const char *var;
if ((var = switch_channel_get_variable(channel, "sip_ignore_reinvites")) && switch_true(var)) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Ignoring Re-invite\n");
nua_respond(tech_pvt->nh, SIP_200_OK, TAG_END());
@@ -5168,8 +5244,9 @@ static void sofia_handle_sip_i_state(switch_core_session_t *session, int status,
if (tech_pvt->num_codecs) {
match = sofia_glue_negotiate_sdp(session, r_sdp);
}
if (match && switch_channel_test_app_flag_key("T38", tech_pvt->channel, CF_APP_T38)) {
if (match && sofia_test_flag(tech_pvt, TFLAG_NOREPLY)) {
sofia_clear_flag(tech_pvt, TFLAG_NOREPLY);
goto done;
}
@@ -5218,7 +5295,6 @@ static void sofia_handle_sip_i_state(switch_core_session_t *session, int status,
nua_respond(tech_pvt->nh, SIP_488_NOT_ACCEPTABLE, TAG_END());
}
}
}
break;
case nua_callstate_ready:
if (r_sdp && !is_dup_sdp && switch_rtp_ready(tech_pvt->rtp_session)) {
@@ -5251,10 +5327,34 @@ static void sofia_handle_sip_i_state(switch_core_session_t *session, int status,
}
if (r_sdp && sofia_test_flag(tech_pvt, TFLAG_NOSDP_REINVITE)) {
sofia_clear_flag_locked(tech_pvt, TFLAG_NOSDP_REINVITE);
if (switch_channel_test_flag(channel, CF_PROXY_MODE) || switch_channel_test_flag(channel, CF_PROXY_MEDIA)) {
if (switch_channel_test_flag(channel, CF_PROXY_MEDIA)) {
if (sofia_glue_activate_rtp(tech_pvt, 0) != SWITCH_STATUS_SUCCESS) {
goto done;
}
}
if ((uuid = switch_channel_get_variable(channel, SWITCH_SIGNAL_BOND_VARIABLE))
&& (other_session = switch_core_session_locate(uuid))) {
other_channel = switch_core_session_get_channel(other_session);
if (!switch_channel_get_variable(other_channel, SWITCH_B_SDP_VARIABLE)) {
switch_channel_set_variable(other_channel, SWITCH_B_SDP_VARIABLE, r_sdp);
}
if (sofia_test_flag(tech_pvt, TFLAG_3PCC) && sofia_test_pflag(profile, PFLAG_3PCC_PROXY)) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "3PCC-PROXY, Got my ACK\n");
sofia_set_flag(tech_pvt, TFLAG_3PCC_HAS_ACK);
} else {
switch_core_session_queue_indication(other_session, SWITCH_MESSAGE_INDICATE_ANSWER);
}
switch_core_session_rwunlock(other_session);
}
} else {
uint8_t match = 0;
int is_ok = 1;
sofia_clear_flag_locked(tech_pvt, TFLAG_NOSDP_REINVITE);
if (tech_pvt->num_codecs) {
match = sofia_glue_negotiate_sdp(session, r_sdp);
@@ -5277,7 +5377,7 @@ static void sofia_handle_sip_i_state(switch_core_session_t *session, int status,
nua_respond(nh, SIP_488_NOT_ACCEPTABLE, TAG_END());
switch_channel_hangup(tech_pvt->channel, SWITCH_CAUSE_INCOMPATIBLE_DESTINATION);
}
}
goto done;
}
@@ -5344,6 +5444,12 @@ static void sofia_handle_sip_i_state(switch_core_session_t *session, int status,
switch_core_session_rwunlock(other_session);
}
if (sofia_test_flag(tech_pvt, TFLAG_3PCC) && sofia_test_pflag(profile, PFLAG_3PCC_PROXY)) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "3PCC-PROXY, Got my ACK\n");
sofia_set_flag(tech_pvt, TFLAG_3PCC_HAS_ACK);
}
goto done;
} else {
uint8_t match = 0;
@@ -5474,6 +5580,11 @@ void *SWITCH_THREAD_FUNC nightmare_xfer_thread_run(switch_thread_t *thread, void
if ((status = switch_ivr_originate(NULL, &tsession, &cause, nhelper->exten_with_params, timeout, NULL, NULL, NULL,
switch_channel_get_caller_profile(channel_a), nhelper->vars, SOF_NONE, NULL)) == SWITCH_STATUS_SUCCESS) {
if (switch_channel_up(channel_a)) {
if (switch_true(switch_channel_get_variable(channel_a, "recording_follow_transfer"))) {
switch_core_media_bug_transfer_recordings(session, a_session);
}
tuuid_str = switch_core_session_get_uuid(tsession);
switch_ivr_uuid_bridge(nhelper->bridge_to_uuid, tuuid_str);
switch_channel_set_variable(channel_a, SWITCH_ENDPOINT_DISPOSITION_VARIABLE, "ATTENDED_TRANSFER");
@@ -5668,6 +5779,8 @@ void sofia_handle_sip_i_refer(nua_t *nua, sofia_profile_t *profile, nua_handle_t
switch_channel_set_variable(channel_a, SOFIA_REPLACES_HEADER, rep);
if ((b_private = nua_handle_magic(bnh))) {
int deny_refer_requests = 0;
if (!(b_session = switch_core_session_locate(b_private->uuid))) {
goto done;
}
@@ -5685,7 +5798,46 @@ void sofia_handle_sip_i_refer(nua_t *nua, sofia_profile_t *profile, nua_handle_t
br_b = NULL;
}
if (switch_channel_test_flag(channel_b, CF_ORIGINATOR)) {
if (channel_a && switch_true(switch_channel_get_variable(channel_a, "deny_refer_requests"))) {
deny_refer_requests = 1;
}
if (!deny_refer_requests && channel_b && switch_true(switch_channel_get_variable(channel_b, "deny_refer_requests"))) {
deny_refer_requests = 1;
}
if (!deny_refer_requests && br_a) {
switch_core_session_t *a_session;
if ((a_session = switch_core_session_locate(br_a))) {
switch_channel_t *a_channel = switch_core_session_get_channel(a_session);
if (a_channel && switch_true(switch_channel_get_variable(a_channel, "deny_refer_requests"))) {
deny_refer_requests = 1;
}
switch_core_session_rwunlock(a_session);
}
}
if (!deny_refer_requests && br_b) {
switch_core_session_t *b_session;
if ((b_session = switch_core_session_locate(br_b))) {
switch_channel_t *b_channel = switch_core_session_get_channel(b_session);
if (b_channel && switch_true(switch_channel_get_variable(b_channel, "deny_refer_requests"))) {
deny_refer_requests = 1;
}
switch_core_session_rwunlock(b_session);
}
}
if (deny_refer_requests) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_NOTICE, "Denying Attended Transfer, variable [deny_refer_requests] was set to true\n");
nua_notify(tech_pvt->nh, NUTAG_NEWSUB(1), SIPTAG_CONTENT_TYPE_STR("message/sipfrag;version=2.0"),
NUTAG_SUBSTATE(nua_substate_terminated),
SIPTAG_PAYLOAD_STR("SIP/2.0 403 Forbidden\r\n"), SIPTAG_EVENT_STR(etmp), TAG_END());
} else if (switch_channel_test_flag(channel_b, CF_ORIGINATOR)) {
switch_core_session_t *a_session;
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_NOTICE,
@@ -5783,6 +5935,21 @@ void sofia_handle_sip_i_refer(nua_t *nua, sofia_profile_t *profile, nua_handle_t
switch_core_session_rwunlock(tmp);
}
if (switch_true(switch_channel_get_variable(channel_a, "recording_follow_transfer")) &&
(tmp = switch_core_session_locate(br_a))) {
switch_core_media_bug_transfer_recordings(session, tmp);
switch_core_session_rwunlock(tmp);
}
if (switch_true(switch_channel_get_variable(channel_b, "recording_follow_transfer")) &&
(tmp = switch_core_session_locate(br_b))) {
switch_core_media_bug_transfer_recordings(b_session, tmp);
switch_core_session_rwunlock(tmp);
}
switch_ivr_uuid_bridge(br_b, br_a);
switch_channel_set_variable(channel_b, SWITCH_ENDPOINT_DISPOSITION_VARIABLE, "ATTENDED_TRANSFER");
nua_notify(tech_pvt->nh, NUTAG_NEWSUB(1), SIPTAG_CONTENT_TYPE_STR("message/sipfrag;version=2.0"),
@@ -5803,17 +5970,19 @@ void sofia_handle_sip_i_refer(nua_t *nua, sofia_profile_t *profile, nua_handle_t
NUTAG_SUBSTATE(nua_substate_terminated), SIPTAG_PAYLOAD_STR("SIP/2.0 403 Forbidden\r\n"),
SIPTAG_EVENT_STR(etmp), TAG_END());
} else {
switch_core_session_t *t_session;
switch_core_session_t *t_session, *hup_session;
switch_channel_t *hup_channel;
const char *ext;
if (br_a && !br_b) {
t_session = switch_core_session_locate(br_a);
hup_channel = channel_b;
hup_session = b_session;
} else {
private_object_t *h_tech_pvt = (private_object_t *) switch_core_session_get_private(b_session);
t_session = switch_core_session_locate(br_b);
hup_channel = channel_a;
hup_session = session;
sofia_clear_flag_locked(tech_pvt, TFLAG_SIP_HOLD);
switch_channel_clear_flag(tech_pvt->channel, CF_LEG_HOLDING);
sofia_clear_flag_locked(h_tech_pvt, TFLAG_SIP_HOLD);
@@ -5834,6 +6003,11 @@ void sofia_handle_sip_i_refer(nua_t *nua, sofia_profile_t *profile, nua_handle_t
switch_channel_set_variable(t_channel, SOFIA_REFER_TO_VARIABLE, full_ref_to);
}
if (switch_true(switch_channel_get_variable(hup_channel, "recording_follow_transfer"))) {
switch_core_media_bug_transfer_recordings(hup_session, t_session);
}
if (idest) {
switch_ivr_session_transfer(t_session, idest, "inline", NULL);
} else {
@@ -5996,6 +6170,10 @@ void sofia_handle_sip_i_refer(nua_t *nua, sofia_profile_t *profile, nua_handle_t
switch_channel_set_variable(b_channel, SOFIA_REFER_TO_VARIABLE, full_ref_to);
}
if (switch_true(switch_channel_get_variable(channel, "recording_follow_transfer"))) {
switch_core_media_bug_transfer_recordings(session, b_session);
}
switch_ivr_session_transfer(b_session, exten, NULL, NULL);
switch_core_session_rwunlock(b_session);
}
@@ -6096,6 +6274,11 @@ void sofia_handle_sip_i_info(nua_t *nua, sofia_profile_t *profile, nua_handle_t
const char *clientcode_header;
switch_dtmf_t dtmf = { 0, switch_core_default_dtmf_duration(0) };
switch_event_t *event;
private_object_t *tech_pvt = NULL;
if (session) {
tech_pvt = (private_object_t *) switch_core_session_get_private(session);
}
if (sofia_test_pflag(profile, PFLAG_EXTENDED_INFO_PARSING)) {
if (sip && sip->sip_content_type && sip->sip_content_type->c_type && sip->sip_content_type->c_subtype &&
@@ -6228,7 +6411,7 @@ void sofia_handle_sip_i_info(nua_t *nua, sofia_profile_t *profile, nua_handle_t
goto end;
}
if (dtmf.digit) {
if (dtmf.digit && tech_pvt->dtmf_type == DTMF_INFO) {
/* queue it up */
switch_channel_queue_dtmf(channel, &dtmf);
@@ -6253,6 +6436,9 @@ void sofia_handle_sip_i_info(nua_t *nua, sofia_profile_t *profile, nua_handle_t
/* Send 200 OK response */
nua_respond(nh, SIP_200_OK, NUTAG_WITH_THIS(nua), TAG_END());
} else {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING,
"IGNORE INFO DTMF(%c) (This channel was not configured to use INFO DTMF!)\n", dtmf.digit);
}
goto end;
}
@@ -6806,7 +6992,7 @@ void sofia_handle_sip_i_invite(nua_t *nua, sofia_profile_t *profile, nua_handle_
if (sip->sip_to && sip->sip_to->a_url) {
const char *host, *user;
int port;
int port, check_nat = 0;
url_t *transport_url;
if (sip->sip_record_route && sip->sip_record_route->r_url) {
@@ -6846,10 +7032,22 @@ void sofia_handle_sip_i_invite(nua_t *nua, sofia_profile_t *profile, nua_handle_
if (sofia_glue_check_nat(profile, tech_pvt->remote_ip)) {
url = (sofia_glue_transport_has_tls(transport)) ? profile->tls_public_url : profile->public_url;
check_nat = 1;
} else {
url = (sofia_glue_transport_has_tls(transport)) ? profile->tls_url : profile->url;
}
if (!url) {
if (check_nat) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "Nat detected but no external address configured.\n");
}
url = profile->url;
}
if (!url) {
switch_channel_hangup(tech_pvt->channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
}
tmp = sofia_overcome_sip_uri_weakness(session, url, transport, SWITCH_TRUE, NULL);
if ((at = strchr(tmp, '@'))) {
+27 -16
View File
@@ -358,7 +358,7 @@ void sofia_glue_check_dtmf_type(private_object_t *tech_pvt)
}
void sofia_glue_set_local_sdp(private_object_t *tech_pvt, const char *ip, uint32_t port, const char *sr, int force)
void sofia_glue_set_local_sdp(private_object_t *tech_pvt, const char *ip, switch_port_t port, const char *sr, int force)
{
char buf[2048];
int ptime = 0;
@@ -2396,6 +2396,8 @@ switch_status_t sofia_glue_do_invite(switch_core_session_t *session)
if (sofia_use_soa(tech_pvt)) {
nua_invite(tech_pvt->nh,
NUTAG_AUTOANSWER(0),
TAG_IF(zstr(tech_pvt->local_sdp_str), NUTAG_AUTOACK(0)),
TAG_IF(!zstr(tech_pvt->local_sdp_str), NUTAG_AUTOACK(1)),
NUTAG_SESSION_TIMER(session_timeout),
NUTAG_SESSION_REFRESHER(session_timeout ? nua_local_refresher : nua_no_refresher),
TAG_IF(sofia_test_flag(tech_pvt, TFLAG_RECOVERED), NUTAG_INVITE_TIMER(UINT_MAX)),
@@ -2417,15 +2419,19 @@ switch_status_t sofia_glue_do_invite(switch_core_session_t *session)
TAG_IF(!zstr(route), SIPTAG_ROUTE_STR(route)),
TAG_IF(tech_pvt->profile->minimum_session_expires, NUTAG_MIN_SE(tech_pvt->profile->minimum_session_expires)),
TAG_IF(cseq, SIPTAG_CSEQ(cseq)),
SOATAG_ADDRESS(tech_pvt->adv_sdp_audio_ip),
SOATAG_USER_SDP_STR(tech_pvt->local_sdp_str),
SOATAG_REUSE_REJECTED(1),
SOATAG_ORDERED_USER(1),
SOATAG_RTP_SORT(SOA_RTP_SORT_REMOTE),
SOATAG_RTP_SELECT(SOA_RTP_SELECT_ALL), TAG_IF(rep, SIPTAG_REPLACES_STR(rep)), SOATAG_HOLD(holdstr), TAG_END());
TAG_IF(zstr(tech_pvt->local_sdp_str), SIPTAG_PAYLOAD_STR("")),
TAG_IF(!zstr(tech_pvt->local_sdp_str), SOATAG_ADDRESS(tech_pvt->adv_sdp_audio_ip)),
TAG_IF(!zstr(tech_pvt->local_sdp_str), SOATAG_USER_SDP_STR(tech_pvt->local_sdp_str)),
TAG_IF(!zstr(tech_pvt->local_sdp_str), SOATAG_REUSE_REJECTED(1)),
TAG_IF(!zstr(tech_pvt->local_sdp_str), SOATAG_ORDERED_USER(1)),
TAG_IF(!zstr(tech_pvt->local_sdp_str), SOATAG_RTP_SORT(SOA_RTP_SORT_REMOTE)),
TAG_IF(!zstr(tech_pvt->local_sdp_str), SOATAG_RTP_SELECT(SOA_RTP_SELECT_ALL)),
TAG_IF(rep, SIPTAG_REPLACES_STR(rep)),
TAG_IF(!zstr(tech_pvt->local_sdp_str), SOATAG_HOLD(holdstr)), TAG_END());
} else {
nua_invite(tech_pvt->nh,
NUTAG_AUTOANSWER(0),
NUTAG_AUTOACK(0),
NUTAG_SESSION_TIMER(session_timeout),
TAG_IF(session_timeout, NUTAG_SESSION_REFRESHER(nua_remote_refresher)),
TAG_IF(sofia_test_flag(tech_pvt, TFLAG_RECOVERED), NUTAG_INVITE_TIMER(UINT_MAX)),
@@ -3579,7 +3585,7 @@ static void add_audio_codec(sdp_rtpmap_t *map, int ptime, char *buf, switch_size
codec_ms = switch_default_ptime(map->rm_encoding, map->rm_pt);
}
map_bit_rate = switch_known_bitrate(map->rm_pt);
map_bit_rate = switch_known_bitrate((switch_payload_t)map->rm_pt);
if (!ptime && !strcasecmp(map->rm_encoding, "g723")) {
ptime = codec_ms = 30;
@@ -4384,8 +4390,13 @@ uint8_t sofia_glue_negotiate_sdp(switch_core_session_t *session, const char *r_s
if (got_udptl && m->m_type == sdp_media_image && m->m_port) {
switch_t38_options_t *t38_options = tech_process_udptl(tech_pvt, sdp, m);
if (switch_channel_test_app_flag_key("T38", tech_pvt->channel, CF_APP_T38)) {
sofia_set_flag(tech_pvt, TFLAG_NOREPLY);
}
if (switch_true(switch_channel_get_variable(channel, "refuse_t38"))) {
switch_channel_clear_app_flag_key("T38", tech_pvt->channel, CF_APP_T38);
match = 0;
goto done;
} else {
@@ -4649,7 +4660,7 @@ uint8_t sofia_glue_negotiate_sdp(switch_core_session_t *session, const char *r_s
codec_ms = switch_default_ptime(rm_encoding, map->rm_pt);
}
map_bit_rate = switch_known_bitrate(map->rm_pt);
map_bit_rate = switch_known_bitrate((switch_payload_t)map->rm_pt);
if (!ptime && !strcasecmp(map->rm_encoding, "g723")) {
ptime = codec_ms = 30;
@@ -4765,7 +4776,7 @@ uint8_t sofia_glue_negotiate_sdp(switch_core_session_t *session, const char *r_s
switch_snprintf(tmp, sizeof(tmp), "%d", tech_pvt->remote_sdp_audio_port);
switch_channel_set_variable(tech_pvt->channel, SWITCH_REMOTE_MEDIA_IP_VARIABLE, tech_pvt->remote_sdp_audio_ip);
switch_channel_set_variable(tech_pvt->channel, SWITCH_REMOTE_MEDIA_PORT_VARIABLE, tmp);
tech_pvt->audio_recv_pt = map->rm_pt;
tech_pvt->audio_recv_pt = (switch_payload_t)map->rm_pt;
if (switch_channel_direction(channel) == SWITCH_CALL_DIRECTION_OUTBOUND && !sofia_test_flag(tech_pvt, TFLAG_REINVITE)) {
sofia_glue_get_offered_pt(tech_pvt, mimp, &tech_pvt->audio_recv_pt);
@@ -4889,7 +4900,7 @@ uint8_t sofia_glue_negotiate_sdp(switch_core_session_t *session, const char *r_s
switch_channel_set_variable(tech_pvt->channel, "sip_video_pt", tmp);
sofia_glue_check_video_codecs(tech_pvt);
tech_pvt->video_recv_pt = map->rm_pt;
tech_pvt->video_recv_pt = (switch_payload_t)map->rm_pt;
if (switch_channel_direction(channel) == SWITCH_CALL_DIRECTION_OUTBOUND) {
sofia_glue_get_offered_pt(tech_pvt, mimp, &tech_pvt->video_recv_pt);
@@ -5332,11 +5343,11 @@ static int recover_callback(void *pArg, int argc, char **argv, char **columnName
tech_pvt->dest = switch_core_session_sprintf(session, "sip:%s", switch_channel_get_variable(channel, "sip_from_uri"));
if (!switch_channel_get_variable_dup(channel, "sip_handle_full_from", SWITCH_FALSE)) {
if (!switch_channel_get_variable_dup(channel, "sip_handle_full_from", SWITCH_FALSE, -1)) {
switch_channel_set_variable(channel, "sip_handle_full_from", switch_channel_get_variable(channel, "sip_full_to"));
}
if (!switch_channel_get_variable_dup(channel, "sip_handle_full_to", SWITCH_FALSE)) {
if (!switch_channel_get_variable_dup(channel, "sip_handle_full_to", SWITCH_FALSE, -1)) {
switch_channel_set_variable(channel, "sip_handle_full_to", switch_channel_get_variable(channel, "sip_full_from"));
}
}
@@ -5458,13 +5469,13 @@ static int recover_callback(void *pArg, int argc, char **argv, char **columnName
if (switch_rtp_ready(tech_pvt->rtp_session)) {
if ((tmp = switch_channel_get_variable(channel, "sip_audio_recv_pt"))) {
switch_rtp_set_recv_pt(tech_pvt->rtp_session, atoi(tmp));
switch_rtp_set_recv_pt(tech_pvt->rtp_session, (switch_payload_t)atoi(tmp));
}
}
if (switch_rtp_ready(tech_pvt->video_rtp_session)) {
if ((tmp = switch_channel_get_variable(channel, "sip_video_recv_pt"))) {
switch_rtp_set_recv_pt(tech_pvt->rtp_session, atoi(tmp));
switch_rtp_set_recv_pt(tech_pvt->rtp_session, (switch_payload_t)atoi(tmp));
}
}
@@ -6415,7 +6426,7 @@ void sofia_glue_build_vid_refresh_message(switch_core_session_t *session, const
}
void sofia_glue_parse_rtp_bugs(uint32_t *flag_pole, const char *str)
void sofia_glue_parse_rtp_bugs(switch_rtp_bug_flag_t *flag_pole, const char *str)
{
if (switch_stristr("clear", str)) {
+33 -14
View File
@@ -195,15 +195,9 @@ switch_status_t sofia_presence_chat_send(const char *proto, const char *from, co
}
if (dst->route_uri) {
remote_host = strdup(dst->route_uri);
if (!zstr(remote_host)) {
switch_split_user_domain(remote_host, NULL, &remote_ip);
}
}
if (zstr(remote_ip)) {
switch_split_user_domain(dup_dest, NULL, &remote_ip);
remote_host = strdup(dup_dest);
if (!zstr(remote_host)) {
switch_split_user_domain(remote_host, NULL, &remote_ip);
}
if (!zstr(remote_ip) && sofia_glue_check_nat(profile, remote_ip)) {
@@ -402,9 +396,30 @@ static void actual_sofia_presence_mwi_event_handler(switch_event_t *event)
if (!profile) {
if (!host || !(profile = sofia_glue_find_profile(host))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot find profile %s\n", switch_str_nil(host));
switch_safe_free(dup_account);
return;
char *sql;
switch_hash_index_t *hi;
void *val;
const void *vvar;
char buf[512] = "";
sql = switch_mprintf("select profile_name from sip_registrations where sip_host='%s' or mwi_host='%s'", host, host);
switch_mutex_lock(mod_sofia_globals.hash_mutex);
for (hi = switch_hash_first(NULL, mod_sofia_globals.profile_hash); hi; hi = switch_hash_next(hi)) {
switch_hash_this(hi, &vvar, NULL, &val);
profile = (sofia_profile_t *) val;
sofia_glue_execute_sql2str(profile, profile->ireg_mutex, sql, buf, sizeof(buf));
if (!zstr(buf)) {
break;
}
}
switch_mutex_unlock(mod_sofia_globals.hash_mutex);
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;
}
}
}
@@ -1577,8 +1592,12 @@ static int sofia_presence_sub_callback(void *pArg, int argc, char **argv, char *
stream.write_function(&stream, "<param pname=\"+sip.rendering\" pvalue=\"%s\"/>\n",
!strcasecmp(event_status, "hold") ? "no" : "yes");
stream.write_function(&stream, "</target>\n</local>\n");
stream.write_function(&stream, "<remote>\n<identity display=\"%s\">sip:%s@%s</identity>\n", clean_from_user, clean_from_user,
host);
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);
}
stream.write_function(&stream, "<target uri=\"sip:**%s@%s\"/>\n", clean_to_user, host);
stream.write_function(&stream, "</remote>\n");
} else if (!strcasecmp(proto, "park")) {
+93 -107
View File
@@ -733,6 +733,92 @@ void sofia_reg_check_expire(sofia_profile_t *profile, time_t now, int reboot)
}
int sofia_reg_check_callback(void *pArg, int argc, char **argv, char **columnNames)
{
sofia_profile_t *profile = (sofia_profile_t *) pArg;
sofia_reg_send_reboot(profile, argv[1], argv[2], argv[3], argv[7], argv[11]);
return 0;
}
void sofia_reg_check_call_id(sofia_profile_t *profile, const char *call_id)
{
char *sql = NULL;
char *sqlextra = NULL;
char *dup = strdup(call_id);
char *host = NULL, *user = NULL;
switch_assert(dup);
if ((host = strchr(dup, '@'))) {
*host++ = '\0';
user = dup;
} else {
host = dup;
}
if (!host) {
host = "none";
}
if (zstr(user)) {
sqlextra = switch_mprintf(" or (sip_host='%q')", host);
} else {
sqlextra = switch_mprintf(" or (sip_user='%q' and sip_host='%q')", user, host);
}
sql = switch_mprintf("select call_id,sip_user,sip_host,contact,status,rpid,expires"
",user_agent,server_user,server_host,profile_name,network_ip"
" from sip_registrations where call_id='%q' %s", call_id, sqlextra);
switch_mutex_lock(profile->ireg_mutex);
sofia_glue_execute_sql_callback(profile, NULL, sql, sofia_reg_check_callback, profile);
switch_mutex_unlock(profile->ireg_mutex);
switch_safe_free(sql);
switch_safe_free(sqlextra);
switch_safe_free(dup);
}
void sofia_reg_check_sync(sofia_profile_t *profile)
{
char sql[1024];
switch_mutex_lock(profile->ireg_mutex);
switch_snprintf(sql, sizeof(sql), "select call_id,sip_user,sip_host,contact,status,rpid,expires"
",user_agent,server_user,server_host,profile_name,network_ip"
" from sip_registrations where expires > 0");
sofia_glue_execute_sql_callback(profile, NULL, sql, sofia_reg_del_callback, profile);
switch_snprintf(sql, sizeof(sql), "delete from sip_registrations where expires > 0 and hostname='%s'", mod_sofia_globals.hostname);
sofia_glue_actually_execute_sql(profile, sql, NULL);
switch_snprintf(sql, sizeof(sql), "delete from sip_presence where expires > 0 and hostname='%s'", mod_sofia_globals.hostname);
sofia_glue_actually_execute_sql(profile, sql, NULL);
switch_snprintf(sql, sizeof(sql), "delete from sip_authentication where expires > 0 and hostname='%s'", mod_sofia_globals.hostname);
sofia_glue_actually_execute_sql(profile, sql, NULL);
switch_snprintf(sql, sizeof(sql), "select sub_to_user,sub_to_host,call_id from sip_subscriptions where expires >= -1 and hostname='%s'",
mod_sofia_globals.hostname);
sofia_glue_execute_sql_callback(profile, NULL, sql, sofia_sub_del_callback, profile);
switch_snprintf(sql, sizeof(sql), "delete from sip_subscriptions where expires >= -1 and hostname='%s'", mod_sofia_globals.hostname);
sofia_glue_actually_execute_sql(profile, sql, NULL);
switch_snprintf(sql, sizeof(sql), "delete from sip_dialogs where expires >= -1 and hostname='%s'", mod_sofia_globals.hostname);
sofia_glue_actually_execute_sql(profile, sql, NULL);
switch_mutex_unlock(profile->ireg_mutex);
}
char *sofia_reg_find_reg_url(sofia_profile_t *profile, const char *user, const char *host, char *val, switch_size_t len)
{
struct callback_t cbt = { 0 };
@@ -1050,7 +1136,7 @@ uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_hand
}
if (authorization) {
char *v_contact_str;
char *v_contact_str = NULL;
const char *username = "unknown";
const char *realm = reg_host;
if ((auth_res = sofia_reg_parse_auth(profile, authorization, sip, sip->sip_request->rq_method_name,
@@ -2002,7 +2088,7 @@ auth_res_t sofia_reg_parse_auth(sofia_profile_t *profile,
const char *call_id = NULL;
char *sql;
char *number_alias = NULL;
switch_xml_t domain, xml = NULL, user, param, uparams, dparams, group = NULL, gparams = NULL;
switch_xml_t user = NULL, param, uparams;
char hexdigest[2 * SU_MD5_DIGEST_SIZE + 1] = "";
char *domain_name = NULL;
switch_event_t *params = NULL;
@@ -2179,7 +2265,7 @@ auth_res_t sofia_reg_parse_auth(sofia_profile_t *profile,
domain_name = realm;
}
if (switch_xml_locate_user("id", zstr(username) ? "nobody" : username, domain_name, ip, &xml, &domain, &user, &group, params) != SWITCH_STATUS_SUCCESS) {
if (switch_xml_locate_user_merged("id", zstr(username) ? "nobody" : username, domain_name, ip, &user, params) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Can't find user [%s@%s]\n"
"You must define a domain called '%s' in your directory and add a user with the id=\"%s\" attribute\n"
"and you must configure your device to use the proper domain in it's authentication credentials.\n", username, domain_name,
@@ -2200,90 +2286,10 @@ auth_res_t sofia_reg_parse_auth(sofia_profile_t *profile,
number_alias = zstr(username) ? "nobody" : username;
}
dparams = switch_xml_child(domain, "params");
uparams = switch_xml_child(user, "params");
if (group) {
gparams = switch_xml_child(group, "params");
}
if (!(dparams || uparams)) {
if (!(uparams = switch_xml_child(user, "params"))) {
ret = AUTH_OK;
goto skip_auth;
}
if (dparams) {
for (param = switch_xml_child(dparams, "param"); param; param = param->next) {
const char *var = switch_xml_attr_soft(param, "name");
const char *val = switch_xml_attr_soft(param, "value");
if (!strcasecmp(var, "sip-forbid-register") && switch_true(val)) {
ret = AUTH_FORBIDDEN;
goto end;
}
if (!strcasecmp(var, "password")) {
passwd = val;
}
if (!strcasecmp(var, "auth-acl")) {
auth_acl = val;
}
if (!strcasecmp(var, "a1-hash")) {
a1_hash = val;
}
if (!strcasecmp(var, "mwi-account")) {
mwi_account = val;
}
if (!strcasecmp(var, "allow-empty-password")) {
allow_empty_password = switch_true(val);
}
if (!strcasecmp(var, "user-agent-filter")) {
user_agent_filter = val;
}
if (!strcasecmp(var, "max-registrations-per-extension")) {
max_registrations_perext = atoi(val);
}
}
}
if (gparams) {
for (param = switch_xml_child(gparams, "param"); param; param = param->next) {
const char *var = switch_xml_attr_soft(param, "name");
const char *val = switch_xml_attr_soft(param, "value");
if (!strcasecmp(var, "sip-forbid-register") && switch_true(val)) {
ret = AUTH_FORBIDDEN;
goto end;
}
if (!strcasecmp(var, "password")) {
passwd = val;
}
if (!strcasecmp(var, "auth-acl")) {
auth_acl = val;
}
if (!strcasecmp(var, "a1-hash")) {
a1_hash = val;
}
if (!strcasecmp(var, "mwi-account")) {
mwi_account = val;
}
if (!strcasecmp(var, "allow-empty-password")) {
allow_empty_password = switch_true(val);
}
if (!strcasecmp(var, "user-agent-filter")) {
user_agent_filter = val;
}
if (!strcasecmp(var, "max-registrations-per-extension")) {
max_registrations_perext = atoi(val);
}
}
}
if (uparams) {
} else {
for (param = switch_xml_child(uparams, "param"); param; param = param->next) {
const char *var = switch_xml_attr_soft(param, "name");
const char *val = switch_xml_attr_soft(param, "value");
@@ -2504,31 +2510,11 @@ auth_res_t sofia_reg_parse_auth(sofia_profile_t *profile,
switch_event_add_header_string(*v_event, SWITCH_STACK_BOTTOM, "mwi-account", mwi_account);
}
if ((dparams = switch_xml_child(domain, "params"))) {
xparams_type[i] = 0;
xparams[i++] = dparams;
}
if (group && (gparams = switch_xml_child(group, "params"))) {
xparams_type[i] = 0;
xparams[i++] = gparams;
}
if ((uparams = switch_xml_child(user, "params"))) {
xparams_type[i] = 0;
xparams[i++] = uparams;
}
if ((dparams = switch_xml_child(domain, "variables"))) {
xparams_type[i] = 1;
xparams[i++] = dparams;
}
if (group && (gparams = switch_xml_child(group, "variables"))) {
xparams_type[i] = 1;
xparams[i++] = gparams;
}
if ((uparams = switch_xml_child(user, "variables"))) {
xparams_type[i] = 1;
xparams[i++] = uparams;
@@ -2632,8 +2618,8 @@ auth_res_t sofia_reg_parse_auth(sofia_profile_t *profile,
switch_event_destroy(&params);
if (xml) {
switch_xml_free(xml);
if (user) {
switch_xml_free(user);
}
switch_safe_free(input);
@@ -3,6 +3,7 @@ BASE=../../../..
ZMQ=zeromq-2.1.4
ZMQ_BASEURL=http://download.zeromq.org
ZMQ_BASEURL_ALT=http://download.zeromq.org/historic
ZMQ_DIR=$(switch_srcdir)/libs/$(ZMQ)
ZMQ_BUILDDIR=$(switch_builddir)/libs/$(ZMQ)
@@ -13,7 +14,7 @@ LOCAL_LIBADD=$(ZMQ_LA)
include $(BASE)/build/modmake.rules
$(ZMQ_DIR):
$(GETLIB) $(ZMQ_BASEURL) $(ZMQ).tar.gz
$(GETLIB) $(ZMQ_BASEURL) $(ZMQ).tar.gz || $(GETLIB) $(ZMQ_BASEURL_ALT) $(ZMQ).tar.gz
cd $(ZMQ_DIR) && ./autogen.sh
$(ZMQ_BUILDDIR)/Makefile: $(ZMQ_DIR)
@@ -285,7 +285,7 @@ static void *SWITCH_THREAD_FUNC read_stream_thread(switch_thread_t *thread, void
samples = 0;
switch_mutex_lock(source->device_lock);
samples = ReadAudioStream(source->audio_stream, source->databuf,
source->read_codec.implementation->samples_per_packet, &source->timer);
source->read_codec.implementation->samples_per_packet, 0, &source->timer);
switch_mutex_unlock(source->device_lock);
@@ -29,6 +29,7 @@
*
*/
#include <switch.h>
#include <sys/wait.h>
#define MY_BUF_LEN 1024 * 32
#define MY_BLOCK_SIZE MY_BUF_LEN
@@ -135,6 +136,8 @@ static switch_status_t shell_stream_file_open(switch_file_handle_t *handle, cons
switch_cond_next();
}
wait(&(context->pid));
goto end;
} else { /* child */
close(context->fds[0]);
+6 -4
View File
@@ -655,9 +655,6 @@ static switch_status_t shout_file_open(switch_file_handle_t *handle, const char
}
} else if (switch_test_flag(handle, SWITCH_FILE_FLAG_WRITE)) {
if (switch_test_flag(handle, SWITCH_FILE_WRITE_APPEND)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Appending to MP3 not supported.\n");
}
if (!(context->gfp = lame_init())) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Could not allocate lame\n");
goto error;
@@ -781,8 +778,13 @@ static switch_status_t shout_file_open(switch_file_handle_t *handle, const char
}
} else {
const char *mask = "wb+";
if (switch_test_flag(handle, SWITCH_FILE_WRITE_APPEND)) {
mask = "ab+";
}
/* lame being lame and all has FILE * coded into it's API for some functions so we gotta use it */
if (!(context->fp = fopen(path, "wb+"))) {
if (!(context->fp = fopen(path, mask))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error opening %s\n", path);
goto error;
}
@@ -2857,6 +2857,34 @@ SWIGEXPORT void * SWIGSTDCALL CSharp_switch_rtp_numbers_t_flush_packet_count_get
}
SWIGEXPORT void SWIGSTDCALL CSharp_switch_rtp_numbers_t_largest_jb_size_set(void * jarg1, void * jarg2) {
switch_rtp_numbers_t *arg1 = (switch_rtp_numbers_t *) 0 ;
switch_size_t arg2 ;
switch_size_t *argp2 ;
arg1 = (switch_rtp_numbers_t *)jarg1;
argp2 = (switch_size_t *)jarg2;
if (!argp2) {
SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "Attempt to dereference null switch_size_t", 0);
return ;
}
arg2 = *argp2;
if (arg1) (arg1)->largest_jb_size = arg2;
}
SWIGEXPORT void * SWIGSTDCALL CSharp_switch_rtp_numbers_t_largest_jb_size_get(void * jarg1) {
void * jresult ;
switch_rtp_numbers_t *arg1 = (switch_rtp_numbers_t *) 0 ;
switch_size_t result;
arg1 = (switch_rtp_numbers_t *)jarg1;
result = ((arg1)->largest_jb_size);
jresult = new switch_size_t((const switch_size_t &)result);
return jresult;
}
SWIGEXPORT void * SWIGSTDCALL CSharp_new_switch_rtp_numbers_t() {
void * jresult ;
switch_rtp_numbers_t *result = 0 ;
@@ -5158,6 +5186,38 @@ SWIGEXPORT int SWIGSTDCALL CSharp_switch_regex_match_partial(char * jarg1, char
}
SWIGEXPORT void SWIGSTDCALL CSharp_switch_capture_regex(void * jarg1, int jarg2, char * jarg3, void * jarg4, char * jarg5, void * jarg6, void * jarg7) {
switch_regex_t *arg1 = (switch_regex_t *) 0 ;
int arg2 ;
char *arg3 = (char *) 0 ;
int *arg4 = (int *) 0 ;
char *arg5 = (char *) 0 ;
switch_cap_callback_t arg6 = (switch_cap_callback_t) 0 ;
void *arg7 = (void *) 0 ;
arg1 = (switch_regex_t *)jarg1;
arg2 = (int)jarg2;
arg3 = (char *)jarg3;
arg4 = (int *)jarg4;
arg5 = (char *)jarg5;
arg6 = (switch_cap_callback_t)jarg6;
arg7 = (void *)jarg7;
switch_capture_regex(arg1,arg2,(char const *)arg3,arg4,(char const *)arg5,arg6,arg7);
}
SWIGEXPORT void SWIGSTDCALL CSharp_switch_regex_set_var_callback(char * jarg1, char * jarg2, void * jarg3) {
char *arg1 = (char *) 0 ;
char *arg2 = (char *) 0 ;
void *arg3 = (void *) 0 ;
arg1 = (char *)jarg1;
arg2 = (char *)jarg2;
arg3 = (void *)jarg3;
switch_regex_set_var_callback((char const *)arg1,(char const *)arg2,arg3);
}
SWIGEXPORT int SWIGSTDCALL CSharp_SWITCH_MAX_CORE_THREAD_SESSION_OBJS_get() {
int jresult ;
int result;
@@ -5410,6 +5470,34 @@ SWIGEXPORT char * SWIGSTDCALL CSharp_switch_app_log_arg_get(void * jarg1) {
}
SWIGEXPORT void SWIGSTDCALL CSharp_switch_app_log_stamp_set(void * jarg1, void * jarg2) {
switch_app_log *arg1 = (switch_app_log *) 0 ;
switch_time_t arg2 ;
switch_time_t *argp2 ;
arg1 = (switch_app_log *)jarg1;
argp2 = (switch_time_t *)jarg2;
if (!argp2) {
SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "Attempt to dereference null switch_time_t", 0);
return ;
}
arg2 = *argp2;
if (arg1) (arg1)->stamp = arg2;
}
SWIGEXPORT void * SWIGSTDCALL CSharp_switch_app_log_stamp_get(void * jarg1) {
void * jresult ;
switch_app_log *arg1 = (switch_app_log *) 0 ;
switch_time_t result;
arg1 = (switch_app_log *)jarg1;
result = ((arg1)->stamp);
jresult = new switch_time_t((const switch_time_t &)result);
return jresult;
}
SWIGEXPORT void SWIGSTDCALL CSharp_switch_app_log_next_set(void * jarg1, void * jarg2) {
switch_app_log *arg1 = (switch_app_log *) 0 ;
switch_app_log *arg2 = (switch_app_log *) 0 ;
@@ -6361,6 +6449,20 @@ SWIGEXPORT int SWIGSTDCALL CSharp_switch_core_media_bug_enumerate(void * jarg1,
}
SWIGEXPORT int SWIGSTDCALL CSharp_switch_core_media_bug_transfer_recordings(void * jarg1, void * jarg2) {
int jresult ;
switch_core_session_t *arg1 = (switch_core_session_t *) 0 ;
switch_core_session_t *arg2 = (switch_core_session_t *) 0 ;
switch_status_t result;
arg1 = (switch_core_session_t *)jarg1;
arg2 = (switch_core_session_t *)jarg2;
result = (switch_status_t)switch_core_media_bug_transfer_recordings(arg1,arg2);
jresult = result;
return jresult;
}
SWIGEXPORT int SWIGSTDCALL CSharp_switch_core_media_bug_read(void * jarg1, void * jarg2, int jarg3) {
int jresult ;
switch_media_bug_t *arg1 = (switch_media_bug_t *) 0 ;
@@ -6605,6 +6707,30 @@ SWIGEXPORT int SWIGSTDCALL CSharp_switch_core_add_state_handler(void * jarg1) {
}
SWIGEXPORT int SWIGSTDCALL CSharp_switch_core_curl_count(void * jarg1) {
int jresult ;
int *arg1 = (int *) 0 ;
int result;
arg1 = (int *)jarg1;
result = (int)switch_core_curl_count(arg1);
jresult = result;
return jresult;
}
SWIGEXPORT int SWIGSTDCALL CSharp_switch_core_ssl_count(void * jarg1) {
int jresult ;
int *arg1 = (int *) 0 ;
int result;
arg1 = (int *)jarg1;
result = (int)switch_core_ssl_count(arg1);
jresult = result;
return jresult;
}
SWIGEXPORT void SWIGSTDCALL CSharp_switch_core_remove_state_handler(void * jarg1) {
switch_state_handler_table_t *arg1 = (switch_state_handler_table_t *) 0 ;
@@ -13101,6 +13227,106 @@ SWIGEXPORT int SWIGSTDCALL CSharp_switch_split_user_domain(char * jarg1, void *
}
SWIGEXPORT void SWIGSTDCALL CSharp_profile_node_t_var_set(void * jarg1, char * jarg2) {
profile_node_t *arg1 = (profile_node_t *) 0 ;
char *arg2 = (char *) 0 ;
arg1 = (profile_node_t *)jarg1;
arg2 = (char *)jarg2;
{
if (arg1->var) delete [] arg1->var;
if (arg2) {
arg1->var = (char *) (new char[strlen((const char *)arg2)+1]);
strcpy((char *)arg1->var, (const char *)arg2);
} else {
arg1->var = 0;
}
}
}
SWIGEXPORT char * SWIGSTDCALL CSharp_profile_node_t_var_get(void * jarg1) {
char * jresult ;
profile_node_t *arg1 = (profile_node_t *) 0 ;
char *result = 0 ;
arg1 = (profile_node_t *)jarg1;
result = (char *) ((arg1)->var);
jresult = SWIG_csharp_string_callback((const char *)result);
return jresult;
}
SWIGEXPORT void SWIGSTDCALL CSharp_profile_node_t_val_set(void * jarg1, char * jarg2) {
profile_node_t *arg1 = (profile_node_t *) 0 ;
char *arg2 = (char *) 0 ;
arg1 = (profile_node_t *)jarg1;
arg2 = (char *)jarg2;
{
if (arg1->val) delete [] arg1->val;
if (arg2) {
arg1->val = (char *) (new char[strlen((const char *)arg2)+1]);
strcpy((char *)arg1->val, (const char *)arg2);
} else {
arg1->val = 0;
}
}
}
SWIGEXPORT char * SWIGSTDCALL CSharp_profile_node_t_val_get(void * jarg1) {
char * jresult ;
profile_node_t *arg1 = (profile_node_t *) 0 ;
char *result = 0 ;
arg1 = (profile_node_t *)jarg1;
result = (char *) ((arg1)->val);
jresult = SWIG_csharp_string_callback((const char *)result);
return jresult;
}
SWIGEXPORT void SWIGSTDCALL CSharp_profile_node_t_next_set(void * jarg1, void * jarg2) {
profile_node_t *arg1 = (profile_node_t *) 0 ;
profile_node_s *arg2 = (profile_node_s *) 0 ;
arg1 = (profile_node_t *)jarg1;
arg2 = (profile_node_s *)jarg2;
if (arg1) (arg1)->next = arg2;
}
SWIGEXPORT void * SWIGSTDCALL CSharp_profile_node_t_next_get(void * jarg1) {
void * jresult ;
profile_node_t *arg1 = (profile_node_t *) 0 ;
profile_node_s *result = 0 ;
arg1 = (profile_node_t *)jarg1;
result = (profile_node_s *) ((arg1)->next);
jresult = (void *)result;
return jresult;
}
SWIGEXPORT void * SWIGSTDCALL CSharp_new_profile_node_t() {
void * jresult ;
profile_node_t *result = 0 ;
result = (profile_node_t *)new profile_node_t();
jresult = (void *)result;
return jresult;
}
SWIGEXPORT void SWIGSTDCALL CSharp_delete_profile_node_t(void * jarg1) {
profile_node_t *arg1 = (profile_node_t *) 0 ;
arg1 = (profile_node_t *)jarg1;
delete arg1;
}
SWIGEXPORT void SWIGSTDCALL CSharp_switch_caller_profile_username_set(void * jarg1, char * jarg2) {
switch_caller_profile *arg1 = (switch_caller_profile *) 0 ;
char *arg2 = (char *) 0 ;
@@ -13964,6 +14190,28 @@ SWIGEXPORT int SWIGSTDCALL CSharp_switch_caller_profile_direction_get(void * jar
}
SWIGEXPORT void SWIGSTDCALL CSharp_switch_caller_profile_soft_set(void * jarg1, void * jarg2) {
switch_caller_profile *arg1 = (switch_caller_profile *) 0 ;
profile_node_t *arg2 = (profile_node_t *) 0 ;
arg1 = (switch_caller_profile *)jarg1;
arg2 = (profile_node_t *)jarg2;
if (arg1) (arg1)->soft = arg2;
}
SWIGEXPORT void * SWIGSTDCALL CSharp_switch_caller_profile_soft_get(void * jarg1) {
void * jresult ;
switch_caller_profile *arg1 = (switch_caller_profile *) 0 ;
profile_node_t *result = 0 ;
arg1 = (switch_caller_profile *)jarg1;
result = (profile_node_t *) ((arg1)->soft);
jresult = (void *)result;
return jresult;
}
SWIGEXPORT void * SWIGSTDCALL CSharp_new_switch_caller_profile() {
void * jresult ;
switch_caller_profile *result = 0 ;
@@ -23118,6 +23366,26 @@ SWIGEXPORT int SWIGSTDCALL CSharp_switch_channel_set_variable_var_check(void * j
}
SWIGEXPORT int SWIGSTDCALL CSharp_switch_channel_add_variable_var_check(void * jarg1, char * jarg2, char * jarg3, int jarg4, int jarg5) {
int jresult ;
switch_channel_t *arg1 = (switch_channel_t *) 0 ;
char *arg2 = (char *) 0 ;
char *arg3 = (char *) 0 ;
switch_bool_t arg4 ;
switch_stack_t arg5 ;
switch_status_t result;
arg1 = (switch_channel_t *)jarg1;
arg2 = (char *)jarg2;
arg3 = (char *)jarg3;
arg4 = (switch_bool_t)jarg4;
arg5 = (switch_stack_t)jarg5;
result = (switch_status_t)switch_channel_add_variable_var_check(arg1,(char const *)arg2,(char const *)arg3,arg4,arg5);
jresult = result;
return jresult;
}
SWIGEXPORT int SWIGSTDCALL CSharp_switch_channel_set_variable_printf(void * jarg1, char * jarg2, char * jarg3) {
int jresult ;
switch_channel_t *arg1 = (switch_channel_t *) 0 ;
@@ -23261,17 +23529,19 @@ SWIGEXPORT int SWIGSTDCALL CSharp_switch_channel_export_variable_printf(void * j
}
SWIGEXPORT char * SWIGSTDCALL CSharp_switch_channel_get_variable_dup(void * jarg1, char * jarg2, int jarg3) {
SWIGEXPORT char * SWIGSTDCALL CSharp_switch_channel_get_variable_dup(void * jarg1, char * jarg2, int jarg3, int jarg4) {
char * jresult ;
switch_channel_t *arg1 = (switch_channel_t *) 0 ;
char *arg2 = (char *) 0 ;
switch_bool_t arg3 ;
int arg4 ;
char *result = 0 ;
arg1 = (switch_channel_t *)jarg1;
arg2 = (char *)jarg2;
arg3 = (switch_bool_t)jarg3;
result = (char *)switch_channel_get_variable_dup(arg1,(char const *)arg2,arg3);
arg4 = (int)jarg4;
result = (char *)switch_channel_get_variable_dup(arg1,(char const *)arg2,arg3,arg4);
jresult = SWIG_csharp_string_callback((const char *)result);
return jresult;
}
@@ -24577,6 +24847,50 @@ SWIGEXPORT char * SWIGSTDCALL CSharp_switch_event_header_value_get(void * jarg1)
}
SWIGEXPORT void SWIGSTDCALL CSharp_switch_event_header_array_set(void * jarg1, void * jarg2) {
switch_event_header *arg1 = (switch_event_header *) 0 ;
char **arg2 = (char **) 0 ;
arg1 = (switch_event_header *)jarg1;
arg2 = (char **)jarg2;
if (arg1) (arg1)->array = arg2;
}
SWIGEXPORT void * SWIGSTDCALL CSharp_switch_event_header_array_get(void * jarg1) {
void * jresult ;
switch_event_header *arg1 = (switch_event_header *) 0 ;
char **result = 0 ;
arg1 = (switch_event_header *)jarg1;
result = (char **) ((arg1)->array);
jresult = (void *)result;
return jresult;
}
SWIGEXPORT void SWIGSTDCALL CSharp_switch_event_header_idx_set(void * jarg1, int jarg2) {
switch_event_header *arg1 = (switch_event_header *) 0 ;
int arg2 ;
arg1 = (switch_event_header *)jarg1;
arg2 = (int)jarg2;
if (arg1) (arg1)->idx = arg2;
}
SWIGEXPORT int SWIGSTDCALL CSharp_switch_event_header_idx_get(void * jarg1) {
int jresult ;
switch_event_header *arg1 = (switch_event_header *) 0 ;
int result;
arg1 = (switch_event_header *)jarg1;
result = (int) ((arg1)->idx);
jresult = result;
return jresult;
}
SWIGEXPORT void SWIGSTDCALL CSharp_switch_event_header_hash_set(void * jarg1, unsigned long jarg2) {
switch_event_header *arg1 = (switch_event_header *) 0 ;
unsigned long arg2 ;
@@ -25003,15 +25317,31 @@ SWIGEXPORT int SWIGSTDCALL CSharp_switch_event_set_priority(void * jarg1, int ja
}
SWIGEXPORT char * SWIGSTDCALL CSharp_switch_event_get_header(void * jarg1, char * jarg2) {
SWIGEXPORT void * SWIGSTDCALL CSharp_switch_event_get_header_ptr(void * jarg1, char * jarg2) {
void * jresult ;
switch_event_t *arg1 = (switch_event_t *) 0 ;
char *arg2 = (char *) 0 ;
switch_event_header_t *result = 0 ;
arg1 = (switch_event_t *)jarg1;
arg2 = (char *)jarg2;
result = (switch_event_header_t *)switch_event_get_header_ptr(arg1,(char const *)arg2);
jresult = (void *)result;
return jresult;
}
SWIGEXPORT char * SWIGSTDCALL CSharp_switch_event_get_header_idx(void * jarg1, char * jarg2, int jarg3) {
char * jresult ;
switch_event_t *arg1 = (switch_event_t *) 0 ;
char *arg2 = (char *) 0 ;
int arg3 ;
char *result = 0 ;
arg1 = (switch_event_t *)jarg1;
arg2 = (char *)jarg2;
result = (char *)switch_event_get_header(arg1,(char const *)arg2);
arg3 = (int)jarg3;
result = (char *)switch_event_get_header_idx(arg1,(char const *)arg2,arg3);
jresult = SWIG_csharp_string_callback((const char *)result);
return jresult;
}
@@ -25077,6 +25407,22 @@ SWIGEXPORT int SWIGSTDCALL CSharp_switch_event_del_header_val(void * jarg1, char
}
SWIGEXPORT int SWIGSTDCALL CSharp_switch_event_add_array(void * jarg1, char * jarg2, char * jarg3) {
int jresult ;
switch_event_t *arg1 = (switch_event_t *) 0 ;
char *arg2 = (char *) 0 ;
char *arg3 = (char *) 0 ;
int result;
arg1 = (switch_event_t *)jarg1;
arg2 = (char *)jarg2;
arg3 = (char *)jarg3;
result = (int)switch_event_add_array(arg1,(char const *)arg2,(char const *)arg3);
jresult = result;
return jresult;
}
SWIGEXPORT void SWIGSTDCALL CSharp_switch_event_destroy(void * jarg1) {
switch_event_t **arg1 = (switch_event_t **) 0 ;
@@ -30580,6 +30926,22 @@ SWIGEXPORT int SWIGSTDCALL CSharp_switch_xml_locate_user_merged(char * jarg1, ch
}
SWIGEXPORT unsigned long SWIGSTDCALL CSharp_switch_xml_clear_user_cache(char * jarg1, char * jarg2, char * jarg3) {
unsigned long jresult ;
char *arg1 = (char *) 0 ;
char *arg2 = (char *) 0 ;
char *arg3 = (char *) 0 ;
uint32_t result;
arg1 = (char *)jarg1;
arg2 = (char *)jarg2;
arg3 = (char *)jarg3;
result = (uint32_t)switch_xml_clear_user_cache((char const *)arg1,(char const *)arg2,(char const *)arg3);
jresult = (unsigned long)result;
return jresult;
}
SWIGEXPORT void SWIGSTDCALL CSharp_switch_xml_merge_user(void * jarg1, void * jarg2, void * jarg3) {
switch_xml_t arg1 = (switch_xml_t) 0 ;
switch_xml_t arg2 = (switch_xml_t) 0 ;
@@ -5448,6 +5448,38 @@ SWIGEXPORT int SWIGSTDCALL CSharp_switch_regex_match_partial(char * jarg1, char
}
SWIGEXPORT void SWIGSTDCALL CSharp_switch_capture_regex(void * jarg1, int jarg2, char * jarg3, void * jarg4, char * jarg5, void * jarg6, void * jarg7) {
switch_regex_t *arg1 = (switch_regex_t *) 0 ;
int arg2 ;
char *arg3 = (char *) 0 ;
int *arg4 = (int *) 0 ;
char *arg5 = (char *) 0 ;
switch_cap_callback_t arg6 = (switch_cap_callback_t) 0 ;
void *arg7 = (void *) 0 ;
arg1 = (switch_regex_t *)jarg1;
arg2 = (int)jarg2;
arg3 = (char *)jarg3;
arg4 = (int *)jarg4;
arg5 = (char *)jarg5;
arg6 = (switch_cap_callback_t)jarg6;
arg7 = (void *)jarg7;
switch_capture_regex(arg1,arg2,(char const *)arg3,arg4,(char const *)arg5,arg6,arg7);
}
SWIGEXPORT void SWIGSTDCALL CSharp_switch_regex_set_var_callback(char * jarg1, char * jarg2, void * jarg3) {
char *arg1 = (char *) 0 ;
char *arg2 = (char *) 0 ;
void *arg3 = (void *) 0 ;
arg1 = (char *)jarg1;
arg2 = (char *)jarg2;
arg3 = (void *)jarg3;
switch_regex_set_var_callback((char const *)arg1,(char const *)arg2,arg3);
}
SWIGEXPORT int SWIGSTDCALL CSharp_SWITCH_MAX_CORE_THREAD_SESSION_OBJS_get() {
int jresult ;
int result;
@@ -5710,6 +5742,35 @@ SWIGEXPORT char * SWIGSTDCALL CSharp_switch_app_log_arg_get(void * jarg1) {
}
SWIGEXPORT void SWIGSTDCALL CSharp_switch_app_log_stamp_set(void * jarg1, void * jarg2) {
switch_app_log *arg1 = (switch_app_log *) 0 ;
switch_time_t arg2 ;
switch_time_t *argp2 ;
arg1 = (switch_app_log *)jarg1;
argp2 = (switch_time_t *)jarg2;
if (!argp2) {
SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "Attempt to dereference null switch_time_t", 0);
return ;
}
arg2 = *argp2;
if (arg1) (arg1)->stamp = arg2;
}
SWIGEXPORT void * SWIGSTDCALL CSharp_switch_app_log_stamp_get(void * jarg1) {
void * jresult ;
switch_app_log *arg1 = (switch_app_log *) 0 ;
switch_time_t result;
arg1 = (switch_app_log *)jarg1;
result = ((arg1)->stamp);
jresult = new switch_time_t((switch_time_t &)result);
return jresult;
}
SWIGEXPORT void SWIGSTDCALL CSharp_switch_app_log_next_set(void * jarg1, void * jarg2) {
switch_app_log *arg1 = (switch_app_log *) 0 ;
switch_app_log *arg2 = (switch_app_log *) 0 ;
@@ -6926,6 +6987,30 @@ SWIGEXPORT int SWIGSTDCALL CSharp_switch_core_add_state_handler(void * jarg1) {
}
SWIGEXPORT int SWIGSTDCALL CSharp_switch_core_curl_count(void * jarg1) {
int jresult ;
int *arg1 = (int *) 0 ;
int result;
arg1 = (int *)jarg1;
result = (int)switch_core_curl_count(arg1);
jresult = result;
return jresult;
}
SWIGEXPORT int SWIGSTDCALL CSharp_switch_core_ssl_count(void * jarg1) {
int jresult ;
int *arg1 = (int *) 0 ;
int result;
arg1 = (int *)jarg1;
result = (int)switch_core_ssl_count(arg1);
jresult = result;
return jresult;
}
SWIGEXPORT void SWIGSTDCALL CSharp_switch_core_remove_state_handler(void * jarg1) {
switch_state_handler_table_t *arg1 = (switch_state_handler_table_t *) 0 ;
@@ -13455,6 +13540,108 @@ SWIGEXPORT int SWIGSTDCALL CSharp_switch_split_user_domain(char * jarg1, void *
}
SWIGEXPORT void SWIGSTDCALL CSharp_profile_node_t_var_set(void * jarg1, char * jarg2) {
profile_node_t *arg1 = (profile_node_t *) 0 ;
char *arg2 = (char *) 0 ;
arg1 = (profile_node_t *)jarg1;
arg2 = (char *)jarg2;
{
if (arg1->var) delete [] arg1->var;
if (arg2) {
arg1->var = (char *) (new char[strlen((const char *)arg2)+1]);
strcpy((char *)arg1->var, (const char *)arg2);
} else {
arg1->var = 0;
}
}
}
SWIGEXPORT char * SWIGSTDCALL CSharp_profile_node_t_var_get(void * jarg1) {
char * jresult ;
profile_node_t *arg1 = (profile_node_t *) 0 ;
char *result = 0 ;
arg1 = (profile_node_t *)jarg1;
result = (char *) ((arg1)->var);
jresult = SWIG_csharp_string_callback((const char *)result);
return jresult;
}
SWIGEXPORT void SWIGSTDCALL CSharp_profile_node_t_val_set(void * jarg1, char * jarg2) {
profile_node_t *arg1 = (profile_node_t *) 0 ;
char *arg2 = (char *) 0 ;
arg1 = (profile_node_t *)jarg1;
arg2 = (char *)jarg2;
{
if (arg1->val) delete [] arg1->val;
if (arg2) {
arg1->val = (char *) (new char[strlen((const char *)arg2)+1]);
strcpy((char *)arg1->val, (const char *)arg2);
} else {
arg1->val = 0;
}
}
}
SWIGEXPORT char * SWIGSTDCALL CSharp_profile_node_t_val_get(void * jarg1) {
char * jresult ;
profile_node_t *arg1 = (profile_node_t *) 0 ;
char *result = 0 ;
arg1 = (profile_node_t *)jarg1;
result = (char *) ((arg1)->val);
jresult = SWIG_csharp_string_callback((const char *)result);
return jresult;
}
SWIGEXPORT void SWIGSTDCALL CSharp_profile_node_t_next_set(void * jarg1, void * jarg2) {
profile_node_t *arg1 = (profile_node_t *) 0 ;
profile_node_s *arg2 = (profile_node_s *) 0 ;
arg1 = (profile_node_t *)jarg1;
arg2 = (profile_node_s *)jarg2;
if (arg1) (arg1)->next = arg2;
}
SWIGEXPORT void * SWIGSTDCALL CSharp_profile_node_t_next_get(void * jarg1) {
void * jresult ;
profile_node_t *arg1 = (profile_node_t *) 0 ;
profile_node_s *result = 0 ;
arg1 = (profile_node_t *)jarg1;
result = (profile_node_s *) ((arg1)->next);
jresult = (void *)result;
return jresult;
}
SWIGEXPORT void * SWIGSTDCALL CSharp_new_profile_node_t() {
void * jresult ;
profile_node_t *result = 0 ;
result = (profile_node_t *)new profile_node_t();
jresult = (void *)result;
return jresult;
}
SWIGEXPORT void SWIGSTDCALL CSharp_delete_profile_node_t(void * jarg1) {
profile_node_t *arg1 = (profile_node_t *) 0 ;
arg1 = (profile_node_t *)jarg1;
delete arg1;
}
SWIGEXPORT void SWIGSTDCALL CSharp_switch_caller_profile_username_set(void * jarg1, char * jarg2) {
switch_caller_profile *arg1 = (switch_caller_profile *) 0 ;
char *arg2 = (char *) 0 ;
@@ -14336,6 +14523,29 @@ SWIGEXPORT int SWIGSTDCALL CSharp_switch_caller_profile_direction_get(void * jar
}
SWIGEXPORT void SWIGSTDCALL CSharp_switch_caller_profile_soft_set(void * jarg1, void * jarg2) {
switch_caller_profile *arg1 = (switch_caller_profile *) 0 ;
profile_node_t *arg2 = (profile_node_t *) 0 ;
arg1 = (switch_caller_profile *)jarg1;
arg2 = (profile_node_t *)jarg2;
if (arg1) (arg1)->soft = arg2;
}
SWIGEXPORT void * SWIGSTDCALL CSharp_switch_caller_profile_soft_get(void * jarg1) {
void * jresult ;
switch_caller_profile *arg1 = (switch_caller_profile *) 0 ;
profile_node_t *result = 0 ;
arg1 = (switch_caller_profile *)jarg1;
result = (profile_node_t *) ((arg1)->soft);
jresult = (void *)result;
return jresult;
}
SWIGEXPORT void * SWIGSTDCALL CSharp_new_switch_caller_profile() {
void * jresult ;
switch_caller_profile *result = 0 ;
@@ -23813,6 +24023,26 @@ SWIGEXPORT int SWIGSTDCALL CSharp_switch_channel_set_variable_var_check(void * j
}
SWIGEXPORT int SWIGSTDCALL CSharp_switch_channel_add_variable_var_check(void * jarg1, char * jarg2, char * jarg3, int jarg4, int jarg5) {
int jresult ;
switch_channel_t *arg1 = (switch_channel_t *) 0 ;
char *arg2 = (char *) 0 ;
char *arg3 = (char *) 0 ;
switch_bool_t arg4 ;
switch_stack_t arg5 ;
switch_status_t result;
arg1 = (switch_channel_t *)jarg1;
arg2 = (char *)jarg2;
arg3 = (char *)jarg3;
arg4 = (switch_bool_t)jarg4;
arg5 = (switch_stack_t)jarg5;
result = (switch_status_t)switch_channel_add_variable_var_check(arg1,(char const *)arg2,(char const *)arg3,arg4,arg5);
jresult = result;
return jresult;
}
SWIGEXPORT int SWIGSTDCALL CSharp_switch_channel_set_variable_printf(void * jarg1, char * jarg2, char * jarg3) {
int jresult ;
switch_channel_t *arg1 = (switch_channel_t *) 0 ;
@@ -23956,17 +24186,19 @@ SWIGEXPORT int SWIGSTDCALL CSharp_switch_channel_export_variable_printf(void * j
}
SWIGEXPORT char * SWIGSTDCALL CSharp_switch_channel_get_variable_dup(void * jarg1, char * jarg2, int jarg3) {
SWIGEXPORT char * SWIGSTDCALL CSharp_switch_channel_get_variable_dup(void * jarg1, char * jarg2, int jarg3, int jarg4) {
char * jresult ;
switch_channel_t *arg1 = (switch_channel_t *) 0 ;
char *arg2 = (char *) 0 ;
switch_bool_t arg3 ;
int arg4 ;
char *result = 0 ;
arg1 = (switch_channel_t *)jarg1;
arg2 = (char *)jarg2;
arg3 = (switch_bool_t)jarg3;
result = (char *)switch_channel_get_variable_dup(arg1,(char const *)arg2,arg3);
arg4 = (int)jarg4;
result = (char *)switch_channel_get_variable_dup(arg1,(char const *)arg2,arg3,arg4);
jresult = SWIG_csharp_string_callback((const char *)result);
return jresult;
}
@@ -25272,6 +25504,52 @@ SWIGEXPORT char * SWIGSTDCALL CSharp_switch_event_header_value_get(void * jarg1)
}
SWIGEXPORT void SWIGSTDCALL CSharp_switch_event_header_array_set(void * jarg1, void * jarg2) {
switch_event_header *arg1 = (switch_event_header *) 0 ;
char **arg2 = (char **) 0 ;
arg1 = (switch_event_header *)jarg1;
arg2 = (char **)jarg2;
if (arg1) (arg1)->array = arg2;
}
SWIGEXPORT void * SWIGSTDCALL CSharp_switch_event_header_array_get(void * jarg1) {
void * jresult ;
switch_event_header *arg1 = (switch_event_header *) 0 ;
char **result = 0 ;
arg1 = (switch_event_header *)jarg1;
result = (char **) ((arg1)->array);
jresult = (void *)result;
return jresult;
}
SWIGEXPORT void SWIGSTDCALL CSharp_switch_event_header_idx_set(void * jarg1, int jarg2) {
switch_event_header *arg1 = (switch_event_header *) 0 ;
int arg2 ;
arg1 = (switch_event_header *)jarg1;
arg2 = (int)jarg2;
if (arg1) (arg1)->idx = arg2;
}
SWIGEXPORT int SWIGSTDCALL CSharp_switch_event_header_idx_get(void * jarg1) {
int jresult ;
switch_event_header *arg1 = (switch_event_header *) 0 ;
int result;
arg1 = (switch_event_header *)jarg1;
result = (int) ((arg1)->idx);
jresult = result;
return jresult;
}
SWIGEXPORT void SWIGSTDCALL CSharp_switch_event_header_hash_set(void * jarg1, unsigned long jarg2) {
switch_event_header *arg1 = (switch_event_header *) 0 ;
unsigned long arg2 ;
@@ -25711,15 +25989,31 @@ SWIGEXPORT int SWIGSTDCALL CSharp_switch_event_set_priority(void * jarg1, int ja
}
SWIGEXPORT char * SWIGSTDCALL CSharp_switch_event_get_header(void * jarg1, char * jarg2) {
SWIGEXPORT void * SWIGSTDCALL CSharp_switch_event_get_header_ptr(void * jarg1, char * jarg2) {
void * jresult ;
switch_event_t *arg1 = (switch_event_t *) 0 ;
char *arg2 = (char *) 0 ;
switch_event_header_t *result = 0 ;
arg1 = (switch_event_t *)jarg1;
arg2 = (char *)jarg2;
result = (switch_event_header_t *)switch_event_get_header_ptr(arg1,(char const *)arg2);
jresult = (void *)result;
return jresult;
}
SWIGEXPORT char * SWIGSTDCALL CSharp_switch_event_get_header_idx(void * jarg1, char * jarg2, int jarg3) {
char * jresult ;
switch_event_t *arg1 = (switch_event_t *) 0 ;
char *arg2 = (char *) 0 ;
int arg3 ;
char *result = 0 ;
arg1 = (switch_event_t *)jarg1;
arg2 = (char *)jarg2;
result = (char *)switch_event_get_header(arg1,(char const *)arg2);
arg3 = (int)jarg3;
result = (char *)switch_event_get_header_idx(arg1,(char const *)arg2,arg3);
jresult = SWIG_csharp_string_callback((const char *)result);
return jresult;
}
@@ -31332,6 +31626,22 @@ SWIGEXPORT int SWIGSTDCALL CSharp_switch_xml_locate_user_merged(char * jarg1, ch
}
SWIGEXPORT unsigned long SWIGSTDCALL CSharp_switch_xml_clear_user_cache(char * jarg1, char * jarg2, char * jarg3) {
unsigned long jresult ;
char *arg1 = (char *) 0 ;
char *arg2 = (char *) 0 ;
char *arg3 = (char *) 0 ;
uint32_t result;
arg1 = (char *)jarg1;
arg2 = (char *)jarg2;
arg3 = (char *)jarg3;
result = (uint32_t)switch_xml_clear_user_cache((char const *)arg1,(char const *)arg2,(char const *)arg3);
jresult = (unsigned long)result;
return jresult;
}
SWIGEXPORT void SWIGSTDCALL CSharp_switch_xml_merge_user(void * jarg1, void * jarg2, void * jarg3) {
switch_xml_t arg1 = (switch_xml_t) 0 ;
switch_xml_t arg2 = (switch_xml_t) 0 ;
@@ -954,6 +954,14 @@ public class freeswitch {
return ret;
}
public static void switch_capture_regex(SWIGTYPE_p_real_pcre re, int match_count, string field_data, SWIGTYPE_p_int ovector, string var, SWIGTYPE_p_f_p_q_const__char_p_q_const__char_p_void__void callback, SWIGTYPE_p_void user_data) {
freeswitchPINVOKE.switch_capture_regex(SWIGTYPE_p_real_pcre.getCPtr(re), match_count, field_data, SWIGTYPE_p_int.getCPtr(ovector), var, SWIGTYPE_p_f_p_q_const__char_p_q_const__char_p_void__void.getCPtr(callback), SWIGTYPE_p_void.getCPtr(user_data));
}
public static void switch_regex_set_var_callback(string var, string val, SWIGTYPE_p_void user_data) {
freeswitchPINVOKE.switch_regex_set_var_callback(var, val, SWIGTYPE_p_void.getCPtr(user_data));
}
public static void switch_core_session_sched_heartbeat(SWIGTYPE_p_switch_core_session session, uint seconds) {
freeswitchPINVOKE.switch_core_session_sched_heartbeat(SWIGTYPE_p_switch_core_session.getCPtr(session), seconds);
}
@@ -1065,6 +1073,11 @@ public class freeswitch {
return ret;
}
public static switch_status_t switch_core_media_bug_transfer_recordings(SWIGTYPE_p_switch_core_session orig_session, SWIGTYPE_p_switch_core_session new_session) {
switch_status_t ret = (switch_status_t)freeswitchPINVOKE.switch_core_media_bug_transfer_recordings(SWIGTYPE_p_switch_core_session.getCPtr(orig_session), SWIGTYPE_p_switch_core_session.getCPtr(new_session));
return ret;
}
public static switch_status_t switch_core_media_bug_read(SWIGTYPE_p_switch_media_bug bug, switch_frame frame, switch_bool_t fill) {
switch_status_t ret = (switch_status_t)freeswitchPINVOKE.switch_core_media_bug_read(SWIGTYPE_p_switch_media_bug.getCPtr(bug), switch_frame.getCPtr(frame), (int)fill);
return ret;
@@ -1161,6 +1174,16 @@ public class freeswitch {
return ret;
}
public static int switch_core_curl_count(SWIGTYPE_p_int val) {
int ret = freeswitchPINVOKE.switch_core_curl_count(SWIGTYPE_p_int.getCPtr(val));
return ret;
}
public static int switch_core_ssl_count(SWIGTYPE_p_int val) {
int ret = freeswitchPINVOKE.switch_core_ssl_count(SWIGTYPE_p_int.getCPtr(val));
return ret;
}
public static void switch_core_remove_state_handler(switch_state_handler_table state_handler) {
freeswitchPINVOKE.switch_core_remove_state_handler(switch_state_handler_table.getCPtr(state_handler));
}
@@ -3394,6 +3417,11 @@ public class freeswitch {
return ret;
}
public static switch_status_t switch_channel_add_variable_var_check(SWIGTYPE_p_switch_channel channel, string varname, string value, switch_bool_t var_check, switch_stack_t stack) {
switch_status_t ret = (switch_status_t)freeswitchPINVOKE.switch_channel_add_variable_var_check(SWIGTYPE_p_switch_channel.getCPtr(channel), varname, value, (int)var_check, (int)stack);
return ret;
}
public static switch_status_t switch_channel_set_variable_printf(SWIGTYPE_p_switch_channel channel, string varname, string fmt) {
switch_status_t ret = (switch_status_t)freeswitchPINVOKE.switch_channel_set_variable_printf(SWIGTYPE_p_switch_channel.getCPtr(channel), varname, fmt);
return ret;
@@ -3438,8 +3466,8 @@ public class freeswitch {
return ret;
}
public static string switch_channel_get_variable_dup(SWIGTYPE_p_switch_channel channel, string varname, switch_bool_t dup) {
string ret = freeswitchPINVOKE.switch_channel_get_variable_dup(SWIGTYPE_p_switch_channel.getCPtr(channel), varname, (int)dup);
public static string switch_channel_get_variable_dup(SWIGTYPE_p_switch_channel channel, string varname, switch_bool_t dup, int idx) {
string ret = freeswitchPINVOKE.switch_channel_get_variable_dup(SWIGTYPE_p_switch_channel.getCPtr(channel), varname, (int)dup, idx);
return ret;
}
@@ -3902,8 +3930,14 @@ public class freeswitch {
return ret;
}
public static string switch_event_get_header(switch_event arg0, string header_name) {
string ret = freeswitchPINVOKE.switch_event_get_header(switch_event.getCPtr(arg0), header_name);
public static switch_event_header switch_event_get_header_ptr(switch_event arg0, string header_name) {
IntPtr cPtr = freeswitchPINVOKE.switch_event_get_header_ptr(switch_event.getCPtr(arg0), header_name);
switch_event_header ret = (cPtr == IntPtr.Zero) ? null : new switch_event_header(cPtr, false);
return ret;
}
public static string switch_event_get_header_idx(switch_event arg0, string header_name, int idx) {
string ret = freeswitchPINVOKE.switch_event_get_header_idx(switch_event.getCPtr(arg0), header_name, idx);
return ret;
}
@@ -3927,6 +3961,11 @@ public class freeswitch {
return ret;
}
public static int switch_event_add_array(switch_event arg0, string var, string val) {
int ret = freeswitchPINVOKE.switch_event_add_array(switch_event.getCPtr(arg0), var, val);
return ret;
}
public static void switch_event_destroy(SWIGTYPE_p_p_switch_event arg0) {
freeswitchPINVOKE.switch_event_destroy(SWIGTYPE_p_p_switch_event.getCPtr(arg0));
}
@@ -5252,6 +5291,11 @@ public class freeswitch {
return ret;
}
public static uint switch_xml_clear_user_cache(string key, string user_name, string domain_name) {
uint ret = freeswitchPINVOKE.switch_xml_clear_user_cache(key, user_name, domain_name);
return ret;
}
public static void switch_xml_merge_user(switch_xml user, switch_xml domain, switch_xml group) {
freeswitchPINVOKE.switch_xml_merge_user(switch_xml.getCPtr(user), switch_xml.getCPtr(domain), switch_xml.getCPtr(group));
}
@@ -6611,6 +6655,12 @@ class freeswitchPINVOKE {
[DllImport("mod_managed", EntryPoint="CSharp_switch_rtp_numbers_t_flush_packet_count_get")]
public static extern IntPtr switch_rtp_numbers_t_flush_packet_count_get(HandleRef jarg1);
[DllImport("mod_managed", EntryPoint="CSharp_switch_rtp_numbers_t_largest_jb_size_set")]
public static extern void switch_rtp_numbers_t_largest_jb_size_set(HandleRef jarg1, HandleRef jarg2);
[DllImport("mod_managed", EntryPoint="CSharp_switch_rtp_numbers_t_largest_jb_size_get")]
public static extern IntPtr switch_rtp_numbers_t_largest_jb_size_get(HandleRef jarg1);
[DllImport("mod_managed", EntryPoint="CSharp_new_switch_rtp_numbers_t")]
public static extern IntPtr new_switch_rtp_numbers_t();
@@ -7214,6 +7264,12 @@ class freeswitchPINVOKE {
[DllImport("mod_managed", EntryPoint="CSharp_switch_regex_match_partial")]
public static extern int switch_regex_match_partial(string jarg1, string jarg2, HandleRef jarg3);
[DllImport("mod_managed", EntryPoint="CSharp_switch_capture_regex")]
public static extern void switch_capture_regex(HandleRef jarg1, int jarg2, string jarg3, HandleRef jarg4, string jarg5, HandleRef jarg6, HandleRef jarg7);
[DllImport("mod_managed", EntryPoint="CSharp_switch_regex_set_var_callback")]
public static extern void switch_regex_set_var_callback(string jarg1, string jarg2, HandleRef jarg3);
[DllImport("mod_managed", EntryPoint="CSharp_SWITCH_MAX_CORE_THREAD_SESSION_OBJS_get")]
public static extern int SWITCH_MAX_CORE_THREAD_SESSION_OBJS_get();
@@ -7280,6 +7336,12 @@ class freeswitchPINVOKE {
[DllImport("mod_managed", EntryPoint="CSharp_switch_app_log_arg_get")]
public static extern string switch_app_log_arg_get(HandleRef jarg1);
[DllImport("mod_managed", EntryPoint="CSharp_switch_app_log_stamp_set")]
public static extern void switch_app_log_stamp_set(HandleRef jarg1, HandleRef jarg2);
[DllImport("mod_managed", EntryPoint="CSharp_switch_app_log_stamp_get")]
public static extern IntPtr switch_app_log_stamp_get(HandleRef jarg1);
[DllImport("mod_managed", EntryPoint="CSharp_switch_app_log_next_set")]
public static extern void switch_app_log_next_set(HandleRef jarg1, HandleRef jarg2);
@@ -7514,6 +7576,9 @@ class freeswitchPINVOKE {
[DllImport("mod_managed", EntryPoint="CSharp_switch_core_media_bug_enumerate")]
public static extern int switch_core_media_bug_enumerate(HandleRef jarg1, HandleRef jarg2);
[DllImport("mod_managed", EntryPoint="CSharp_switch_core_media_bug_transfer_recordings")]
public static extern int switch_core_media_bug_transfer_recordings(HandleRef jarg1, HandleRef jarg2);
[DllImport("mod_managed", EntryPoint="CSharp_switch_core_media_bug_read")]
public static extern int switch_core_media_bug_read(HandleRef jarg1, HandleRef jarg2, int jarg3);
@@ -7574,6 +7639,12 @@ class freeswitchPINVOKE {
[DllImport("mod_managed", EntryPoint="CSharp_switch_core_add_state_handler")]
public static extern int switch_core_add_state_handler(HandleRef jarg1);
[DllImport("mod_managed", EntryPoint="CSharp_switch_core_curl_count")]
public static extern int switch_core_curl_count(HandleRef jarg1);
[DllImport("mod_managed", EntryPoint="CSharp_switch_core_ssl_count")]
public static extern int switch_core_ssl_count(HandleRef jarg1);
[DllImport("mod_managed", EntryPoint="CSharp_switch_core_remove_state_handler")]
public static extern void switch_core_remove_state_handler(HandleRef jarg1);
@@ -9017,6 +9088,30 @@ class freeswitchPINVOKE {
[DllImport("mod_managed", EntryPoint="CSharp_switch_split_user_domain")]
public static extern int switch_split_user_domain(string jarg1, ref string jarg2, ref string jarg3);
[DllImport("mod_managed", EntryPoint="CSharp_profile_node_t_var_set")]
public static extern void profile_node_t_var_set(HandleRef jarg1, string jarg2);
[DllImport("mod_managed", EntryPoint="CSharp_profile_node_t_var_get")]
public static extern string profile_node_t_var_get(HandleRef jarg1);
[DllImport("mod_managed", EntryPoint="CSharp_profile_node_t_val_set")]
public static extern void profile_node_t_val_set(HandleRef jarg1, string jarg2);
[DllImport("mod_managed", EntryPoint="CSharp_profile_node_t_val_get")]
public static extern string profile_node_t_val_get(HandleRef jarg1);
[DllImport("mod_managed", EntryPoint="CSharp_profile_node_t_next_set")]
public static extern void profile_node_t_next_set(HandleRef jarg1, HandleRef jarg2);
[DllImport("mod_managed", EntryPoint="CSharp_profile_node_t_next_get")]
public static extern IntPtr profile_node_t_next_get(HandleRef jarg1);
[DllImport("mod_managed", EntryPoint="CSharp_new_profile_node_t")]
public static extern IntPtr new_profile_node_t();
[DllImport("mod_managed", EntryPoint="CSharp_delete_profile_node_t")]
public static extern void delete_profile_node_t(HandleRef jarg1);
[DllImport("mod_managed", EntryPoint="CSharp_switch_caller_profile_username_set")]
public static extern void switch_caller_profile_username_set(HandleRef jarg1, string jarg2);
@@ -9221,6 +9316,12 @@ class freeswitchPINVOKE {
[DllImport("mod_managed", EntryPoint="CSharp_switch_caller_profile_direction_get")]
public static extern int switch_caller_profile_direction_get(HandleRef jarg1);
[DllImport("mod_managed", EntryPoint="CSharp_switch_caller_profile_soft_set")]
public static extern void switch_caller_profile_soft_set(HandleRef jarg1, HandleRef jarg2);
[DllImport("mod_managed", EntryPoint="CSharp_switch_caller_profile_soft_get")]
public static extern IntPtr switch_caller_profile_soft_get(HandleRef jarg1);
[DllImport("mod_managed", EntryPoint="CSharp_new_switch_caller_profile")]
public static extern IntPtr new_switch_caller_profile();
@@ -11594,6 +11695,9 @@ class freeswitchPINVOKE {
[DllImport("mod_managed", EntryPoint="CSharp_switch_channel_set_variable_var_check")]
public static extern int switch_channel_set_variable_var_check(HandleRef jarg1, string jarg2, string jarg3, int jarg4);
[DllImport("mod_managed", EntryPoint="CSharp_switch_channel_add_variable_var_check")]
public static extern int switch_channel_add_variable_var_check(HandleRef jarg1, string jarg2, string jarg3, int jarg4, int jarg5);
[DllImport("mod_managed", EntryPoint="CSharp_switch_channel_set_variable_printf")]
public static extern int switch_channel_set_variable_printf(HandleRef jarg1, string jarg2, string jarg3);
@@ -11622,7 +11726,7 @@ class freeswitchPINVOKE {
public static extern int switch_channel_export_variable_printf(HandleRef jarg1, string jarg2, string jarg3, string jarg4);
[DllImport("mod_managed", EntryPoint="CSharp_switch_channel_get_variable_dup")]
public static extern string switch_channel_get_variable_dup(HandleRef jarg1, string jarg2, int jarg3);
public static extern string switch_channel_get_variable_dup(HandleRef jarg1, string jarg2, int jarg3, int jarg4);
[DllImport("mod_managed", EntryPoint="CSharp_switch_channel_get_variables")]
public static extern int switch_channel_get_variables(HandleRef jarg1, HandleRef jarg2);
@@ -11909,6 +12013,18 @@ class freeswitchPINVOKE {
[DllImport("mod_managed", EntryPoint="CSharp_switch_event_header_value_get")]
public static extern string switch_event_header_value_get(HandleRef jarg1);
[DllImport("mod_managed", EntryPoint="CSharp_switch_event_header_array_set")]
public static extern void switch_event_header_array_set(HandleRef jarg1, ref string jarg2);
[DllImport("mod_managed", EntryPoint="CSharp_switch_event_header_array_get")]
public static extern string switch_event_header_array_get(HandleRef jarg1);
[DllImport("mod_managed", EntryPoint="CSharp_switch_event_header_idx_set")]
public static extern void switch_event_header_idx_set(HandleRef jarg1, int jarg2);
[DllImport("mod_managed", EntryPoint="CSharp_switch_event_header_idx_get")]
public static extern int switch_event_header_idx_get(HandleRef jarg1);
[DllImport("mod_managed", EntryPoint="CSharp_switch_event_header_hash_set")]
public static extern void switch_event_header_hash_set(HandleRef jarg1, uint jarg2);
@@ -12017,8 +12133,11 @@ class freeswitchPINVOKE {
[DllImport("mod_managed", EntryPoint="CSharp_switch_event_set_priority")]
public static extern int switch_event_set_priority(HandleRef jarg1, int jarg2);
[DllImport("mod_managed", EntryPoint="CSharp_switch_event_get_header")]
public static extern string switch_event_get_header(HandleRef jarg1, string jarg2);
[DllImport("mod_managed", EntryPoint="CSharp_switch_event_get_header_ptr")]
public static extern IntPtr switch_event_get_header_ptr(HandleRef jarg1, string jarg2);
[DllImport("mod_managed", EntryPoint="CSharp_switch_event_get_header_idx")]
public static extern string switch_event_get_header_idx(HandleRef jarg1, string jarg2, int jarg3);
[DllImport("mod_managed", EntryPoint="CSharp_switch_event_get_body")]
public static extern string switch_event_get_body(HandleRef jarg1);
@@ -12032,6 +12151,9 @@ class freeswitchPINVOKE {
[DllImport("mod_managed", EntryPoint="CSharp_switch_event_del_header_val")]
public static extern int switch_event_del_header_val(HandleRef jarg1, string jarg2, string jarg3);
[DllImport("mod_managed", EntryPoint="CSharp_switch_event_add_array")]
public static extern int switch_event_add_array(HandleRef jarg1, string jarg2, string jarg3);
[DllImport("mod_managed", EntryPoint="CSharp_switch_event_destroy")]
public static extern void switch_event_destroy(HandleRef jarg1);
@@ -13190,6 +13312,9 @@ class freeswitchPINVOKE {
[DllImport("mod_managed", EntryPoint="CSharp_switch_xml_locate_user_merged")]
public static extern int switch_xml_locate_user_merged(string jarg1, string jarg2, string jarg3, string jarg4, HandleRef jarg5, HandleRef jarg6);
[DllImport("mod_managed", EntryPoint="CSharp_switch_xml_clear_user_cache")]
public static extern uint switch_xml_clear_user_cache(string jarg1, string jarg2, string jarg3);
[DllImport("mod_managed", EntryPoint="CSharp_switch_xml_merge_user")]
public static extern void switch_xml_merge_user(HandleRef jarg1, HandleRef jarg2, HandleRef jarg3);
@@ -14472,6 +14597,86 @@ public partial class ManagedSession : CoreSession {
namespace FreeSWITCH.Native {
using System;
using System.Runtime.InteropServices;
public class profile_node_t : IDisposable {
private HandleRef swigCPtr;
protected bool swigCMemOwn;
internal profile_node_t(IntPtr cPtr, bool cMemoryOwn) {
swigCMemOwn = cMemoryOwn;
swigCPtr = new HandleRef(this, cPtr);
}
internal static HandleRef getCPtr(profile_node_t obj) {
return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr;
}
~profile_node_t() {
Dispose();
}
public virtual void Dispose() {
lock(this) {
if (swigCPtr.Handle != IntPtr.Zero) {
if (swigCMemOwn) {
swigCMemOwn = false;
freeswitchPINVOKE.delete_profile_node_t(swigCPtr);
}
swigCPtr = new HandleRef(null, IntPtr.Zero);
}
GC.SuppressFinalize(this);
}
}
public string var {
set {
freeswitchPINVOKE.profile_node_t_var_set(swigCPtr, value);
}
get {
string ret = freeswitchPINVOKE.profile_node_t_var_get(swigCPtr);
return ret;
}
}
public string val {
set {
freeswitchPINVOKE.profile_node_t_val_set(swigCPtr, value);
}
get {
string ret = freeswitchPINVOKE.profile_node_t_val_get(swigCPtr);
return ret;
}
}
public profile_node_t next {
set {
freeswitchPINVOKE.profile_node_t_next_set(swigCPtr, profile_node_t.getCPtr(value));
}
get {
IntPtr cPtr = freeswitchPINVOKE.profile_node_t_next_get(swigCPtr);
profile_node_t ret = (cPtr == IntPtr.Zero) ? null : new profile_node_t(cPtr, false);
return ret;
}
}
public profile_node_t() : this(freeswitchPINVOKE.new_profile_node_t(), true) {
}
}
}
/* ----------------------------------------------------------------------------
* This file was automatically generated by SWIG (http://www.swig.org).
* Version 2.0.1
*
* Do not make changes to this file unless you know what you are doing--modify
* the SWIG interface file instead.
* ----------------------------------------------------------------------------- */
namespace FreeSWITCH.Native {
[System.Flags] public enum session_flag_t {
S_HUP = (1 << 0),
S_FREE = (1 << 1),
@@ -14853,6 +15058,36 @@ namespace FreeSWITCH.Native {
using System;
using System.Runtime.InteropServices;
public class SWIGTYPE_p_f_p_q_const__char_p_q_const__char_p_void__void {
private HandleRef swigCPtr;
internal SWIGTYPE_p_f_p_q_const__char_p_q_const__char_p_void__void(IntPtr cPtr, bool futureUse) {
swigCPtr = new HandleRef(this, cPtr);
}
protected SWIGTYPE_p_f_p_q_const__char_p_q_const__char_p_void__void() {
swigCPtr = new HandleRef(null, IntPtr.Zero);
}
internal static HandleRef getCPtr(SWIGTYPE_p_f_p_q_const__char_p_q_const__char_p_void__void obj) {
return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr;
}
}
}
/* ----------------------------------------------------------------------------
* This file was automatically generated by SWIG (http://www.swig.org).
* Version 2.0.1
*
* Do not make changes to this file unless you know what you are doing--modify
* the SWIG interface file instead.
* ----------------------------------------------------------------------------- */
namespace FreeSWITCH.Native {
using System;
using System.Runtime.InteropServices;
public class SWIGTYPE_p_f_p_q_const__char_p_q_const__char__switch_status_t {
private HandleRef swigCPtr;
@@ -19960,6 +20195,18 @@ public class switch_app_log : IDisposable {
}
}
public SWIGTYPE_p_switch_time_t stamp {
set {
freeswitchPINVOKE.switch_app_log_stamp_set(swigCPtr, SWIGTYPE_p_switch_time_t.getCPtr(value));
if (freeswitchPINVOKE.SWIGPendingException.Pending) throw freeswitchPINVOKE.SWIGPendingException.Retrieve();
}
get {
SWIGTYPE_p_switch_time_t ret = new SWIGTYPE_p_switch_time_t(freeswitchPINVOKE.switch_app_log_stamp_get(swigCPtr), true);
if (freeswitchPINVOKE.SWIGPendingException.Pending) throw freeswitchPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
}
public switch_app_log next {
set {
freeswitchPINVOKE.switch_app_log_next_set(swigCPtr, switch_app_log.getCPtr(value));
@@ -21727,6 +21974,17 @@ public class switch_caller_profile : IDisposable {
}
}
public profile_node_t soft {
set {
freeswitchPINVOKE.switch_caller_profile_soft_set(swigCPtr, profile_node_t.getCPtr(value));
}
get {
IntPtr cPtr = freeswitchPINVOKE.switch_caller_profile_soft_get(swigCPtr);
profile_node_t ret = (cPtr == IntPtr.Zero) ? null : new profile_node_t(cPtr, false);
return ret;
}
}
public switch_caller_profile() : this(freeswitchPINVOKE.new_switch_caller_profile(), true) {
}
@@ -24993,6 +25251,25 @@ public class switch_event_header : IDisposable {
}
}
public string array {
set { freeswitchPINVOKE.switch_event_header_array_set(swigCPtr, ref value); }
get {
return freeswitchPINVOKE.switch_event_header_array_get(swigCPtr);
}
}
public int idx {
set {
freeswitchPINVOKE.switch_event_header_idx_set(swigCPtr, value);
}
get {
int ret = freeswitchPINVOKE.switch_event_header_idx_get(swigCPtr);
return ret;
}
}
public uint hash {
set {
freeswitchPINVOKE.switch_event_header_hash_set(swigCPtr, value);
@@ -29376,6 +29653,18 @@ public class switch_rtp_numbers_t : IDisposable {
}
}
public SWIGTYPE_p_switch_size_t largest_jb_size {
set {
freeswitchPINVOKE.switch_rtp_numbers_t_largest_jb_size_set(swigCPtr, SWIGTYPE_p_switch_size_t.getCPtr(value));
if (freeswitchPINVOKE.SWIGPendingException.Pending) throw freeswitchPINVOKE.SWIGPendingException.Retrieve();
}
get {
SWIGTYPE_p_switch_size_t ret = new SWIGTYPE_p_switch_size_t(freeswitchPINVOKE.switch_rtp_numbers_t_largest_jb_size_get(swigCPtr), true);
if (freeswitchPINVOKE.SWIGPendingException.Pending) throw freeswitchPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
}
public switch_rtp_numbers_t() : this(freeswitchPINVOKE.new_switch_rtp_numbers_t(), true) {
}
@@ -30497,7 +30786,9 @@ namespace FreeSWITCH.Native {
public enum switch_stack_t {
SWITCH_STACK_BOTTOM = (1 << 0),
SWITCH_STACK_TOP = (1 << 1),
SWITCH_STACK_NODUP = (1 << 2)
SWITCH_STACK_NODUP = (1 << 2),
SWITCH_STACK_UNSHIFT = (1 << 3),
SWITCH_STACK_PUSH = (1 << 4)
}
}
+265 -9
View File
@@ -944,6 +944,14 @@ public class freeswitch {
return ret;
}
public static void switch_capture_regex(SWIGTYPE_p_real_pcre re, int match_count, string field_data, SWIGTYPE_p_int ovector, string var, SWIGTYPE_p_f_p_q_const__char_p_q_const__char_p_void__void callback, SWIGTYPE_p_void user_data) {
freeswitchPINVOKE.switch_capture_regex(SWIGTYPE_p_real_pcre.getCPtr(re), match_count, field_data, SWIGTYPE_p_int.getCPtr(ovector), var, SWIGTYPE_p_f_p_q_const__char_p_q_const__char_p_void__void.getCPtr(callback), SWIGTYPE_p_void.getCPtr(user_data));
}
public static void switch_regex_set_var_callback(string var, string val, SWIGTYPE_p_void user_data) {
freeswitchPINVOKE.switch_regex_set_var_callback(var, val, SWIGTYPE_p_void.getCPtr(user_data));
}
public static void switch_core_session_sched_heartbeat(SWIGTYPE_p_switch_core_session session, uint seconds) {
freeswitchPINVOKE.switch_core_session_sched_heartbeat(SWIGTYPE_p_switch_core_session.getCPtr(session), seconds);
}
@@ -1151,6 +1159,16 @@ public class freeswitch {
return ret;
}
public static int switch_core_curl_count(SWIGTYPE_p_int val) {
int ret = freeswitchPINVOKE.switch_core_curl_count(SWIGTYPE_p_int.getCPtr(val));
return ret;
}
public static int switch_core_ssl_count(SWIGTYPE_p_int val) {
int ret = freeswitchPINVOKE.switch_core_ssl_count(SWIGTYPE_p_int.getCPtr(val));
return ret;
}
public static void switch_core_remove_state_handler(switch_state_handler_table state_handler) {
freeswitchPINVOKE.switch_core_remove_state_handler(switch_state_handler_table.getCPtr(state_handler));
}
@@ -3384,6 +3402,11 @@ public class freeswitch {
return ret;
}
public static switch_status_t switch_channel_add_variable_var_check(SWIGTYPE_p_switch_channel channel, string varname, string value, switch_bool_t var_check, switch_stack_t stack) {
switch_status_t ret = (switch_status_t)freeswitchPINVOKE.switch_channel_add_variable_var_check(SWIGTYPE_p_switch_channel.getCPtr(channel), varname, value, (int)var_check, (int)stack);
return ret;
}
public static switch_status_t switch_channel_set_variable_printf(SWIGTYPE_p_switch_channel channel, string varname, string fmt) {
switch_status_t ret = (switch_status_t)freeswitchPINVOKE.switch_channel_set_variable_printf(SWIGTYPE_p_switch_channel.getCPtr(channel), varname, fmt);
return ret;
@@ -3428,8 +3451,8 @@ public class freeswitch {
return ret;
}
public static string switch_channel_get_variable_dup(SWIGTYPE_p_switch_channel channel, string varname, switch_bool_t dup) {
string ret = freeswitchPINVOKE.switch_channel_get_variable_dup(SWIGTYPE_p_switch_channel.getCPtr(channel), varname, (int)dup);
public static string switch_channel_get_variable_dup(SWIGTYPE_p_switch_channel channel, string varname, switch_bool_t dup, int idx) {
string ret = freeswitchPINVOKE.switch_channel_get_variable_dup(SWIGTYPE_p_switch_channel.getCPtr(channel), varname, (int)dup, idx);
return ret;
}
@@ -3892,8 +3915,14 @@ public class freeswitch {
return ret;
}
public static string switch_event_get_header(switch_event arg0, string header_name) {
string ret = freeswitchPINVOKE.switch_event_get_header(switch_event.getCPtr(arg0), header_name);
public static switch_event_header switch_event_get_header_ptr(switch_event arg0, string header_name) {
IntPtr cPtr = freeswitchPINVOKE.switch_event_get_header_ptr(switch_event.getCPtr(arg0), header_name);
switch_event_header ret = (cPtr == IntPtr.Zero) ? null : new switch_event_header(cPtr, false);
return ret;
}
public static string switch_event_get_header_idx(switch_event arg0, string header_name, int idx) {
string ret = freeswitchPINVOKE.switch_event_get_header_idx(switch_event.getCPtr(arg0), header_name, idx);
return ret;
}
@@ -5242,6 +5271,11 @@ public class freeswitch {
return ret;
}
public static uint switch_xml_clear_user_cache(string key, string user_name, string domain_name) {
uint ret = freeswitchPINVOKE.switch_xml_clear_user_cache(key, user_name, domain_name);
return ret;
}
public static void switch_xml_merge_user(switch_xml user, switch_xml domain, switch_xml group) {
freeswitchPINVOKE.switch_xml_merge_user(switch_xml.getCPtr(user), switch_xml.getCPtr(domain), switch_xml.getCPtr(group));
}
@@ -7206,6 +7240,12 @@ class freeswitchPINVOKE {
[DllImport("mod_managed", EntryPoint="CSharp_switch_regex_match_partial")]
public static extern int switch_regex_match_partial(string jarg1, string jarg2, HandleRef jarg3);
[DllImport("mod_managed", EntryPoint="CSharp_switch_capture_regex")]
public static extern void switch_capture_regex(HandleRef jarg1, int jarg2, string jarg3, HandleRef jarg4, string jarg5, HandleRef jarg6, HandleRef jarg7);
[DllImport("mod_managed", EntryPoint="CSharp_switch_regex_set_var_callback")]
public static extern void switch_regex_set_var_callback(string jarg1, string jarg2, HandleRef jarg3);
[DllImport("mod_managed", EntryPoint="CSharp_SWITCH_MAX_CORE_THREAD_SESSION_OBJS_get")]
public static extern int SWITCH_MAX_CORE_THREAD_SESSION_OBJS_get();
@@ -7272,6 +7312,12 @@ class freeswitchPINVOKE {
[DllImport("mod_managed", EntryPoint="CSharp_switch_app_log_arg_get")]
public static extern string switch_app_log_arg_get(HandleRef jarg1);
[DllImport("mod_managed", EntryPoint="CSharp_switch_app_log_stamp_set")]
public static extern void switch_app_log_stamp_set(HandleRef jarg1, HandleRef jarg2);
[DllImport("mod_managed", EntryPoint="CSharp_switch_app_log_stamp_get")]
public static extern IntPtr switch_app_log_stamp_get(HandleRef jarg1);
[DllImport("mod_managed", EntryPoint="CSharp_switch_app_log_next_set")]
public static extern void switch_app_log_next_set(HandleRef jarg1, HandleRef jarg2);
@@ -7566,6 +7612,12 @@ class freeswitchPINVOKE {
[DllImport("mod_managed", EntryPoint="CSharp_switch_core_add_state_handler")]
public static extern int switch_core_add_state_handler(HandleRef jarg1);
[DllImport("mod_managed", EntryPoint="CSharp_switch_core_curl_count")]
public static extern int switch_core_curl_count(HandleRef jarg1);
[DllImport("mod_managed", EntryPoint="CSharp_switch_core_ssl_count")]
public static extern int switch_core_ssl_count(HandleRef jarg1);
[DllImport("mod_managed", EntryPoint="CSharp_switch_core_remove_state_handler")]
public static extern void switch_core_remove_state_handler(HandleRef jarg1);
@@ -9009,6 +9061,30 @@ class freeswitchPINVOKE {
[DllImport("mod_managed", EntryPoint="CSharp_switch_split_user_domain")]
public static extern int switch_split_user_domain(string jarg1, ref string jarg2, ref string jarg3);
[DllImport("mod_managed", EntryPoint="CSharp_profile_node_t_var_set")]
public static extern void profile_node_t_var_set(HandleRef jarg1, string jarg2);
[DllImport("mod_managed", EntryPoint="CSharp_profile_node_t_var_get")]
public static extern string profile_node_t_var_get(HandleRef jarg1);
[DllImport("mod_managed", EntryPoint="CSharp_profile_node_t_val_set")]
public static extern void profile_node_t_val_set(HandleRef jarg1, string jarg2);
[DllImport("mod_managed", EntryPoint="CSharp_profile_node_t_val_get")]
public static extern string profile_node_t_val_get(HandleRef jarg1);
[DllImport("mod_managed", EntryPoint="CSharp_profile_node_t_next_set")]
public static extern void profile_node_t_next_set(HandleRef jarg1, HandleRef jarg2);
[DllImport("mod_managed", EntryPoint="CSharp_profile_node_t_next_get")]
public static extern IntPtr profile_node_t_next_get(HandleRef jarg1);
[DllImport("mod_managed", EntryPoint="CSharp_new_profile_node_t")]
public static extern IntPtr new_profile_node_t();
[DllImport("mod_managed", EntryPoint="CSharp_delete_profile_node_t")]
public static extern void delete_profile_node_t(HandleRef jarg1);
[DllImport("mod_managed", EntryPoint="CSharp_switch_caller_profile_username_set")]
public static extern void switch_caller_profile_username_set(HandleRef jarg1, string jarg2);
@@ -9213,6 +9289,12 @@ class freeswitchPINVOKE {
[DllImport("mod_managed", EntryPoint="CSharp_switch_caller_profile_direction_get")]
public static extern int switch_caller_profile_direction_get(HandleRef jarg1);
[DllImport("mod_managed", EntryPoint="CSharp_switch_caller_profile_soft_set")]
public static extern void switch_caller_profile_soft_set(HandleRef jarg1, HandleRef jarg2);
[DllImport("mod_managed", EntryPoint="CSharp_switch_caller_profile_soft_get")]
public static extern IntPtr switch_caller_profile_soft_get(HandleRef jarg1);
[DllImport("mod_managed", EntryPoint="CSharp_new_switch_caller_profile")]
public static extern IntPtr new_switch_caller_profile();
@@ -11586,6 +11668,9 @@ class freeswitchPINVOKE {
[DllImport("mod_managed", EntryPoint="CSharp_switch_channel_set_variable_var_check")]
public static extern int switch_channel_set_variable_var_check(HandleRef jarg1, string jarg2, string jarg3, int jarg4);
[DllImport("mod_managed", EntryPoint="CSharp_switch_channel_add_variable_var_check")]
public static extern int switch_channel_add_variable_var_check(HandleRef jarg1, string jarg2, string jarg3, int jarg4, int jarg5);
[DllImport("mod_managed", EntryPoint="CSharp_switch_channel_set_variable_printf")]
public static extern int switch_channel_set_variable_printf(HandleRef jarg1, string jarg2, string jarg3);
@@ -11614,7 +11699,7 @@ class freeswitchPINVOKE {
public static extern int switch_channel_export_variable_printf(HandleRef jarg1, string jarg2, string jarg3, string jarg4);
[DllImport("mod_managed", EntryPoint="CSharp_switch_channel_get_variable_dup")]
public static extern string switch_channel_get_variable_dup(HandleRef jarg1, string jarg2, int jarg3);
public static extern string switch_channel_get_variable_dup(HandleRef jarg1, string jarg2, int jarg3, int jarg4);
[DllImport("mod_managed", EntryPoint="CSharp_switch_channel_get_variables")]
public static extern int switch_channel_get_variables(HandleRef jarg1, HandleRef jarg2);
@@ -11901,6 +11986,18 @@ class freeswitchPINVOKE {
[DllImport("mod_managed", EntryPoint="CSharp_switch_event_header_value_get")]
public static extern string switch_event_header_value_get(HandleRef jarg1);
[DllImport("mod_managed", EntryPoint="CSharp_switch_event_header_array_set")]
public static extern void switch_event_header_array_set(HandleRef jarg1, ref string jarg2);
[DllImport("mod_managed", EntryPoint="CSharp_switch_event_header_array_get")]
public static extern string switch_event_header_array_get(HandleRef jarg1);
[DllImport("mod_managed", EntryPoint="CSharp_switch_event_header_idx_set")]
public static extern void switch_event_header_idx_set(HandleRef jarg1, int jarg2);
[DllImport("mod_managed", EntryPoint="CSharp_switch_event_header_idx_get")]
public static extern int switch_event_header_idx_get(HandleRef jarg1);
[DllImport("mod_managed", EntryPoint="CSharp_switch_event_header_hash_set")]
public static extern void switch_event_header_hash_set(HandleRef jarg1, uint jarg2);
@@ -12009,8 +12106,11 @@ class freeswitchPINVOKE {
[DllImport("mod_managed", EntryPoint="CSharp_switch_event_set_priority")]
public static extern int switch_event_set_priority(HandleRef jarg1, int jarg2);
[DllImport("mod_managed", EntryPoint="CSharp_switch_event_get_header")]
public static extern string switch_event_get_header(HandleRef jarg1, string jarg2);
[DllImport("mod_managed", EntryPoint="CSharp_switch_event_get_header_ptr")]
public static extern IntPtr switch_event_get_header_ptr(HandleRef jarg1, string jarg2);
[DllImport("mod_managed", EntryPoint="CSharp_switch_event_get_header_idx")]
public static extern string switch_event_get_header_idx(HandleRef jarg1, string jarg2, int jarg3);
[DllImport("mod_managed", EntryPoint="CSharp_switch_event_get_body")]
public static extern string switch_event_get_body(HandleRef jarg1);
@@ -13182,6 +13282,9 @@ class freeswitchPINVOKE {
[DllImport("mod_managed", EntryPoint="CSharp_switch_xml_locate_user_merged")]
public static extern int switch_xml_locate_user_merged(string jarg1, string jarg2, string jarg3, string jarg4, HandleRef jarg5, HandleRef jarg6);
[DllImport("mod_managed", EntryPoint="CSharp_switch_xml_clear_user_cache")]
public static extern uint switch_xml_clear_user_cache(string jarg1, string jarg2, string jarg3);
[DllImport("mod_managed", EntryPoint="CSharp_switch_xml_merge_user")]
public static extern void switch_xml_merge_user(HandleRef jarg1, HandleRef jarg2, HandleRef jarg3);
@@ -14456,6 +14559,84 @@ public partial class ManagedSession : CoreSession {
namespace FreeSWITCH.Native {
using System;
using System.Runtime.InteropServices;
public class profile_node_t : IDisposable {
private HandleRef swigCPtr;
protected bool swigCMemOwn;
internal profile_node_t(IntPtr cPtr, bool cMemoryOwn) {
swigCMemOwn = cMemoryOwn;
swigCPtr = new HandleRef(this, cPtr);
}
internal static HandleRef getCPtr(profile_node_t obj) {
return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr;
}
~profile_node_t() {
Dispose();
}
public virtual void Dispose() {
lock(this) {
if(swigCPtr.Handle != IntPtr.Zero && swigCMemOwn) {
swigCMemOwn = false;
freeswitchPINVOKE.delete_profile_node_t(swigCPtr);
}
swigCPtr = new HandleRef(null, IntPtr.Zero);
GC.SuppressFinalize(this);
}
}
public string var {
set {
freeswitchPINVOKE.profile_node_t_var_set(swigCPtr, value);
}
get {
string ret = freeswitchPINVOKE.profile_node_t_var_get(swigCPtr);
return ret;
}
}
public string val {
set {
freeswitchPINVOKE.profile_node_t_val_set(swigCPtr, value);
}
get {
string ret = freeswitchPINVOKE.profile_node_t_val_get(swigCPtr);
return ret;
}
}
public profile_node_t next {
set {
freeswitchPINVOKE.profile_node_t_next_set(swigCPtr, profile_node_t.getCPtr(value));
}
get {
IntPtr cPtr = freeswitchPINVOKE.profile_node_t_next_get(swigCPtr);
profile_node_t ret = (cPtr == IntPtr.Zero) ? null : new profile_node_t(cPtr, false);
return ret;
}
}
public profile_node_t() : this(freeswitchPINVOKE.new_profile_node_t(), true) {
}
}
}
/* ----------------------------------------------------------------------------
* This file was automatically generated by SWIG (http://www.swig.org).
* Version 1.3.35
*
* Do not make changes to this file unless you know what you are doing--modify
* the SWIG interface file instead.
* ----------------------------------------------------------------------------- */
namespace FreeSWITCH.Native {
[System.Flags] public enum session_flag_t {
S_HUP = (1 << 0),
S_FREE = (1 << 1),
@@ -14835,6 +15016,36 @@ namespace FreeSWITCH.Native {
using System;
using System.Runtime.InteropServices;
public class SWIGTYPE_p_f_p_q_const__char_p_q_const__char_p_void__void {
private HandleRef swigCPtr;
internal SWIGTYPE_p_f_p_q_const__char_p_q_const__char_p_void__void(IntPtr cPtr, bool futureUse) {
swigCPtr = new HandleRef(this, cPtr);
}
protected SWIGTYPE_p_f_p_q_const__char_p_q_const__char_p_void__void() {
swigCPtr = new HandleRef(null, IntPtr.Zero);
}
internal static HandleRef getCPtr(SWIGTYPE_p_f_p_q_const__char_p_q_const__char_p_void__void obj) {
return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr;
}
}
}
/* ----------------------------------------------------------------------------
* This file was automatically generated by SWIG (http://www.swig.org).
* Version 1.3.35
*
* Do not make changes to this file unless you know what you are doing--modify
* the SWIG interface file instead.
* ----------------------------------------------------------------------------- */
namespace FreeSWITCH.Native {
using System;
using System.Runtime.InteropServices;
public class SWIGTYPE_p_f_p_q_const__char_p_q_const__char__switch_status_t {
private HandleRef swigCPtr;
@@ -19936,6 +20147,18 @@ public class switch_app_log : IDisposable {
}
}
public SWIGTYPE_p_switch_time_t stamp {
set {
freeswitchPINVOKE.switch_app_log_stamp_set(swigCPtr, SWIGTYPE_p_switch_time_t.getCPtr(value));
if (freeswitchPINVOKE.SWIGPendingException.Pending) throw freeswitchPINVOKE.SWIGPendingException.Retrieve();
}
get {
SWIGTYPE_p_switch_time_t ret = new SWIGTYPE_p_switch_time_t(freeswitchPINVOKE.switch_app_log_stamp_get(swigCPtr), true);
if (freeswitchPINVOKE.SWIGPendingException.Pending) throw freeswitchPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
}
public switch_app_log next {
set {
freeswitchPINVOKE.switch_app_log_next_set(swigCPtr, switch_app_log.getCPtr(value));
@@ -21775,6 +21998,17 @@ public class switch_caller_profile : IDisposable {
}
}
public profile_node_t soft {
set {
freeswitchPINVOKE.switch_caller_profile_soft_set(swigCPtr, profile_node_t.getCPtr(value));
}
get {
IntPtr cPtr = freeswitchPINVOKE.switch_caller_profile_soft_get(swigCPtr);
profile_node_t ret = (cPtr == IntPtr.Zero) ? null : new profile_node_t(cPtr, false);
return ret;
}
}
public switch_caller_profile() : this(freeswitchPINVOKE.new_switch_caller_profile(), true) {
}
@@ -24840,7 +25074,8 @@ public class switch_event : IDisposable {
namespace FreeSWITCH.Native {
public enum switch_event_flag_t {
EF_UNIQ_HEADERS = (1 << 0)
EF_UNIQ_HEADERS = (1 << 0),
EF_CONTAINS_ARRAYS = (1 << 1)
}
}
@@ -24905,6 +25140,25 @@ public class switch_event_header : IDisposable {
}
}
public string array {
set { freeswitchPINVOKE.switch_event_header_array_set(swigCPtr, ref value); }
get {
return freeswitchPINVOKE.switch_event_header_array_get(swigCPtr);
}
}
public int idx {
set {
freeswitchPINVOKE.switch_event_header_idx_set(swigCPtr, value);
}
get {
int ret = freeswitchPINVOKE.switch_event_header_idx_get(swigCPtr);
return ret;
}
}
public uint hash {
set {
freeswitchPINVOKE.switch_event_header_hash_set(swigCPtr, value);
@@ -30347,7 +30601,9 @@ namespace FreeSWITCH.Native {
public enum switch_stack_t {
SWITCH_STACK_BOTTOM = (1 << 0),
SWITCH_STACK_TOP = (1 << 1),
SWITCH_STACK_NODUP = (1 << 2)
SWITCH_STACK_NODUP = (1 << 2),
SWITCH_STACK_UNSHIFT = (1 << 3),
SWITCH_STACK_PUSH = (1 << 4)
}
}
+11 -2
View File
@@ -715,10 +715,10 @@ SWITCH_DECLARE(switch_status_t) switch_socket_send(switch_socket_t *sock, const
switch_size_t req = *len, wrote = 0, need = *len;
int to_count = 0;
while ((wrote < req && status == SWITCH_STATUS_SUCCESS) || (need == 0 && status == SWITCH_STATUS_BREAK) || status == 730035) {
while ((wrote < req && status == SWITCH_STATUS_SUCCESS) || (need == 0 && status == SWITCH_STATUS_BREAK) || status == 730035 || status == 35) {
need = req - wrote;
status = apr_socket_send(sock, buf + wrote, &need);
if (status == SWITCH_STATUS_BREAK || status == 730035) {
if (status == SWITCH_STATUS_BREAK || status == 730035 || status == 35) {
if (++to_count > 10000000) {
status = SWITCH_STATUS_FALSE;
break;
@@ -734,6 +734,15 @@ SWITCH_DECLARE(switch_status_t) switch_socket_send(switch_socket_t *sock, const
return status;
}
SWITCH_DECLARE(switch_status_t) switch_socket_send_nonblock(switch_socket_t *sock, const char *buf, switch_size_t *len)
{
if (!sock || !buf || !len) {
return SWITCH_STATUS_GENERR;
}
return apr_socket_send(sock, buf, len);
}
SWITCH_DECLARE(switch_status_t) switch_socket_sendto(switch_socket_t *sock, switch_sockaddr_t *where, int32_t flags, const char *buf,
switch_size_t *len)
{
+16
View File
@@ -224,6 +224,22 @@ SWITCH_DECLARE(switch_size_t) switch_buffer_peek(switch_buffer_t *buffer, void *
return reading;
}
SWITCH_DECLARE(switch_size_t) switch_buffer_peek_zerocopy(switch_buffer_t *buffer, const void **ptr)
{
switch_size_t reading = 0;
if (buffer->used < 1) {
buffer->used = 0;
return 0;
} else {
reading = buffer->used;
}
*ptr = buffer->head;
return reading;
}
SWITCH_DECLARE(switch_size_t) switch_buffer_write(switch_buffer_t *buffer, const void *data, switch_size_t datalen)
{
switch_size_t freespace, actual_freespace;
+144 -9
View File
@@ -131,6 +131,7 @@ struct switch_channel {
const switch_state_handler_table_t *state_handlers[SWITCH_MAX_STATE_HANDLERS];
int state_handler_index;
switch_event_t *variables;
switch_event_t *scope_variables;
switch_hash_t *private_hash;
switch_hash_t *app_flag_hash;
switch_call_cause_t hangup_cause;
@@ -626,6 +627,11 @@ SWITCH_DECLARE(void) switch_channel_perform_presence(switch_channel_t *channel,
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Presence-Calling-File", file);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Presence-Calling-Function", func);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Presence-Calling-Line", "%d", line);
if (switch_true(switch_channel_get_variable(channel, "presence_privacy"))) {
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Presence-Privacy", "true");
}
switch_event_fire(&event);
}
}
@@ -635,7 +641,7 @@ SWITCH_DECLARE(void) switch_channel_mark_hold(switch_channel_t *channel, switch_
switch_event_t *event;
if (!!on == !!switch_channel_test_flag(channel, CF_LEG_HOLDING)) {
return;
goto end;
}
if (on) {
@@ -649,6 +655,18 @@ SWITCH_DECLARE(void) switch_channel_mark_hold(switch_channel_t *channel, switch_
switch_event_fire(&event);
}
end:
if (on) {
if (switch_true(switch_channel_get_variable(channel, "flip_record_on_hold"))) {
switch_core_session_t *other_session;
if (switch_core_session_get_partner(channel->session, &other_session) == SWITCH_STATUS_SUCCESS) {
switch_core_media_bug_transfer_recordings(channel->session, other_session);
switch_core_session_rwunlock(other_session);
}
}
}
}
SWITCH_DECLARE(const char *) switch_channel_get_hold_music(switch_channel_t *channel)
@@ -675,13 +693,69 @@ SWITCH_DECLARE(const char *) switch_channel_get_hold_music_partner(switch_channe
return r;
}
SWITCH_DECLARE(const char *) switch_channel_get_variable_dup(switch_channel_t *channel, const char *varname, switch_bool_t dup)
SWITCH_DECLARE(void) switch_channel_set_scope_variables(switch_channel_t *channel, switch_event_t **event)
{
switch_mutex_lock(channel->profile_mutex);
if (event && *event) { /* push */
(*event)->next = channel->scope_variables;
channel->scope_variables = *event;
*event = NULL;
} else if (channel->scope_variables) { /* pop */
switch_event_t *top_event = channel->scope_variables;
channel->scope_variables = channel->scope_variables->next;
switch_event_destroy(&top_event);
}
switch_mutex_unlock(channel->profile_mutex);
}
SWITCH_DECLARE(switch_status_t) switch_channel_get_scope_variables(switch_channel_t *channel, switch_event_t **event)
{
switch_status_t status = SWITCH_STATUS_FALSE;
switch_event_t *new_event;
switch_mutex_lock(channel->profile_mutex);
if (channel->scope_variables) {
switch_event_t *ep;
switch_event_header_t *hp;
switch_event_create_plain(&new_event, SWITCH_EVENT_CHANNEL_DATA);
status = SWITCH_STATUS_SUCCESS;
*event = new_event;
for (ep = channel->scope_variables; ep; ep = ep->next) {
for (hp = ep->headers; hp; hp = hp->next) {
if (!switch_event_get_header(new_event, hp->value)) {
switch_event_add_header_string(new_event, SWITCH_STACK_BOTTOM, hp->name, hp->value);
}
}
}
}
switch_mutex_unlock(channel->profile_mutex);
return status;
}
SWITCH_DECLARE(const char *) switch_channel_get_variable_dup(switch_channel_t *channel, const char *varname, switch_bool_t dup, int idx)
{
const char *v = NULL, *r = NULL, *vdup = NULL;
switch_assert(channel != NULL);
switch_mutex_lock(channel->profile_mutex);
if (!channel->variables || !(v = switch_event_get_header(channel->variables, varname))) {
if (channel->scope_variables) {
switch_event_t *ep;
for (ep = channel->scope_variables; ep; ep = ep->next) {
if ((v = switch_event_get_header_idx(ep, varname, idx))) {
break;
}
}
}
if (!v && (!channel->variables || !(v = switch_event_get_header_idx(channel->variables, varname, idx)))) {
switch_caller_profile_t *cp = channel->caller_profile;
if (cp) {
@@ -1032,9 +1106,9 @@ SWITCH_DECLARE(switch_status_t) switch_channel_set_variable_var_check(switch_cha
switch_mutex_lock(channel->profile_mutex);
if (channel->variables && !zstr(varname)) {
switch_event_del_header(channel->variables, varname);
if (!zstr(value)) {
if (zstr(value)) {
switch_event_del_header(channel->variables, varname);
} else {
int ok = 1;
if (var_check) {
@@ -1053,6 +1127,38 @@ SWITCH_DECLARE(switch_status_t) switch_channel_set_variable_var_check(switch_cha
return status;
}
SWITCH_DECLARE(switch_status_t) switch_channel_add_variable_var_check(switch_channel_t *channel,
const char *varname, const char *value, switch_bool_t var_check, switch_stack_t stack)
{
switch_status_t status = SWITCH_STATUS_FALSE;
switch_assert(channel != NULL);
switch_mutex_lock(channel->profile_mutex);
if (channel->variables && !zstr(varname)) {
if (zstr(value)) {
switch_event_del_header(channel->variables, varname);
} else {
int ok = 1;
if (var_check) {
ok = !switch_string_var_check_const(value);
}
if (ok) {
switch_event_add_header_string(channel->variables, stack, varname, value);
} else {
switch_log_printf(SWITCH_CHANNEL_CHANNEL_LOG(channel), SWITCH_LOG_CRIT, "Invalid data (${%s} contains a variable)\n", varname);
}
}
status = SWITCH_STATUS_SUCCESS;
}
switch_mutex_unlock(channel->profile_mutex);
return status;
}
switch_status_t switch_event_base_add_header(switch_event_t *event, switch_stack_t stack, const char *header_name, char *data);
SWITCH_DECLARE(switch_status_t) switch_channel_set_variable_printf(switch_channel_t *channel, const char *varname, const char *fmt, ...)
@@ -2080,6 +2186,28 @@ SWITCH_DECLARE(void) switch_channel_event_set_extended_data(switch_channel_t *ch
event->event_id == SWITCH_EVENT_CUSTOM) {
/* Index Variables */
if (channel->scope_variables) {
switch_event_t *ep;
for (ep = channel->scope_variables; ep; ep = ep->next) {
for (hi = ep->headers; hi; hi = hi->next) {
char buf[1024];
char *vvar = NULL, *vval = NULL;
vvar = (char *) hi->name;
vval = (char *) hi->value;
switch_assert(vvar && vval);
switch_snprintf(buf, sizeof(buf), "scope_variable_%s", vvar);
if (!switch_event_get_header(event, buf)) {
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, buf, vval);
}
}
}
}
if (channel->variables) {
for (hi = channel->variables->headers; hi; hi = hi->next) {
char buf[1024];
@@ -3108,12 +3236,14 @@ SWITCH_DECLARE(char *) switch_channel_expand_variables(switch_channel_t *channel
int offset = 0;
int ooffset = 0;
char *ptr;
int idx = -1;
if ((expanded = switch_channel_expand_variables(channel, (char *) vname)) == vname) {
expanded = NULL;
} else {
vname = expanded;
}
if ((ptr = strchr(vname, ':'))) {
*ptr++ = '\0';
offset = atoi(ptr);
@@ -3123,7 +3253,12 @@ SWITCH_DECLARE(char *) switch_channel_expand_variables(switch_channel_t *channel
}
}
if ((sub_val = (char *) switch_channel_get_variable(channel, vname))) {
if ((ptr = strchr(vname, '[')) && strchr(ptr, ']')) {
*ptr++ = '\0';
idx = atoi(ptr);
}
if ((sub_val = (char *) switch_channel_get_variable_dup(channel, vname, SWITCH_TRUE, idx))) {
if (offset || ooffset) {
cloned_sub_val = strdup(sub_val);
switch_assert(cloned_sub_val);
@@ -3592,7 +3727,7 @@ SWITCH_DECLARE(switch_status_t) switch_channel_set_timestamps(switch_channel_t *
switch_snprintf(tmp, sizeof(tmp), "%d", billsec);
switch_channel_set_variable(channel, "billsec", tmp);
switch_snprintf(tmp, sizeof(tmp), "%d", progresssec);
switch_snprintf(tmp, sizeof(tmp), "%"SWITCH_TIME_T_FMT, progresssec);
switch_channel_set_variable(channel, "progresssec", tmp);
switch_snprintf(tmp, sizeof(tmp), "%d", answersec);
@@ -3601,7 +3736,7 @@ SWITCH_DECLARE(switch_status_t) switch_channel_set_timestamps(switch_channel_t *
switch_snprintf(tmp, sizeof(tmp), "%d", waitsec);
switch_channel_set_variable(channel, "waitsec", tmp);
switch_snprintf(tmp, sizeof(tmp), "%d", progress_mediasec);
switch_snprintf(tmp, sizeof(tmp), "%"SWITCH_TIME_T_FMT, progress_mediasec);
switch_channel_set_variable(channel, "progress_mediasec", tmp);
switch_snprintf(tmp, sizeof(tmp), "%d", legbillsec);
+3 -2
View File
@@ -105,7 +105,7 @@ static switch_status_t console_xml_config(void)
for (param = switch_xml_child(settings, "key"); param; param = param->next) {
char *var = (char *) switch_xml_attr_soft(param, "name");
char *val = (char *) switch_xml_attr_soft(param, "value");
int i = atoi(var);
i = atoi(var);
if ((i < 1) || (i > 12)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Keybind %s is invalid, range is from 1 to 12\n", var);
} else {
@@ -913,7 +913,7 @@ static unsigned char console_fnkey_pressed(int i)
{
char *c, *cmd;
assert((i > 0) && (i <= 12));
switch_assert((i > 0) && (i <= 12));
c = console_fnkeys[i - 1];
@@ -1675,6 +1675,7 @@ SWITCH_DECLARE(void) switch_console_sort_matches(switch_console_callback_match_t
sort[3] = sort[2] ? sort[2]->next : NULL;
for (j = 1; j <= (matches->count - i); j++) {
switch_assert(sort[1] && sort[2]);
if (strcmp(sort[1]->val, sort[2]->val) > 0) {
sort[1]->next = sort[3];
sort[2]->next = sort[1];
+4
View File
@@ -36,6 +36,7 @@
#include <switch.h>
#include <switch_ssl.h>
#include <switch_stun.h>
#include <switch_nat.h>
#include <switch_version.h>
@@ -1479,6 +1480,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_init(switch_core_flag_t flags, switc
switch_uuid_get(&uuid);
switch_uuid_format(runtime.uuid_str, &uuid);
switch_ssl_init_ssl_locks();
return SWITCH_STATUS_SUCCESS;
}
@@ -2164,6 +2166,8 @@ SWITCH_DECLARE(switch_status_t) switch_core_destroy(void)
switch_loadable_module_shutdown();
switch_ssl_destroy_ssl_locks();
if (switch_test_flag((&runtime), SCF_USE_SQL)) {
switch_core_sqldb_stop();
}
+47
View File
@@ -96,6 +96,21 @@ SWITCH_DECLARE(switch_status_t) switch_core_hash_insert_locked(switch_hash_t *ha
return SWITCH_STATUS_SUCCESS;
}
SWITCH_DECLARE(switch_status_t) switch_core_hash_insert_wrlock(switch_hash_t *hash, const char *key, const void *data, switch_thread_rwlock_t *rwlock)
{
if (rwlock) {
switch_thread_rwlock_wrlock(rwlock);
}
sqlite3HashInsert(&hash->table, key, (int) strlen(key) + 1, (void *) data);
if (rwlock) {
switch_thread_rwlock_unlock(rwlock);
}
return SWITCH_STATUS_SUCCESS;
}
SWITCH_DECLARE(switch_status_t) switch_core_hash_delete(switch_hash_t *hash, const char *key)
{
sqlite3HashInsert(&hash->table, key, (int) strlen(key) + 1, NULL);
@@ -117,6 +132,21 @@ SWITCH_DECLARE(switch_status_t) switch_core_hash_delete_locked(switch_hash_t *ha
return SWITCH_STATUS_SUCCESS;
}
SWITCH_DECLARE(switch_status_t) switch_core_hash_delete_wrlock(switch_hash_t *hash, const char *key, switch_thread_rwlock_t *rwlock)
{
if (rwlock) {
switch_thread_rwlock_wrlock(rwlock);
}
sqlite3HashInsert(&hash->table, key, (int) strlen(key) + 1, NULL);
if (rwlock) {
switch_thread_rwlock_unlock(rwlock);
}
return SWITCH_STATUS_SUCCESS;
}
SWITCH_DECLARE(switch_status_t) switch_core_hash_delete_multi(switch_hash_t *hash, switch_hash_delete_callback_t callback, void *pData) {
switch_hash_index_t *hi = NULL;
@@ -175,6 +205,23 @@ SWITCH_DECLARE(void *) switch_core_hash_find_locked(switch_hash_t *hash, const c
return val;
}
SWITCH_DECLARE(void *) switch_core_hash_find_rdlock(switch_hash_t *hash, const char *key, switch_thread_rwlock_t *rwlock)
{
void *val;
if (rwlock) {
switch_thread_rwlock_rdlock(rwlock);
}
val = sqlite3HashFind(&hash->table, key, (int) strlen(key) + 1);
if (rwlock) {
switch_thread_rwlock_unlock(rwlock);
}
return val;
}
SWITCH_DECLARE(switch_hash_index_t *) switch_hash_first(char *depricate_me, switch_hash_t *hash)
{
return (switch_hash_index_t *) sqliteHashFirst(&hash->table);
+41
View File
@@ -392,6 +392,47 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_bug_flush_all(switch_core_sess
return SWITCH_STATUS_FALSE;
}
SWITCH_DECLARE(switch_status_t) switch_core_media_bug_transfer_recordings(switch_core_session_t *orig_session, switch_core_session_t *new_session)
{
switch_media_bug_t *bp;
char *list[100] = { 0 };
int stop_times[100] = { 0 };
int i = 0, x = 0;
if (orig_session->bugs) {
switch_channel_t *new_channel = switch_core_session_get_channel(new_session);
const char *save = switch_channel_get_variable(new_channel, "record_append");
switch_thread_rwlock_wrlock(orig_session->bug_rwlock);
switch_channel_set_variable(new_channel, "record_append", "true");
for (bp = orig_session->bugs; bp; bp = bp->next) {
if (!strcmp(bp->function, "session_record")) {
list[x] = switch_core_session_strdup(new_session, bp->target);
if (bp->stop_time > 0) {
stop_times[x] = (int)(bp->stop_time - switch_epoch_time_now(NULL));
}
x++;
}
}
switch_thread_rwlock_unlock(orig_session->bug_rwlock);
for(i = 0; i < x; i++) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(orig_session), SWITCH_LOG_CRIT, "Transfering %s from %s to %s\n", list[i],
switch_core_session_get_name(orig_session), switch_core_session_get_name(new_session));
switch_ivr_stop_record_session(orig_session, list[i]);
switch_ivr_record_session(new_session, list[i], stop_times[i], NULL);
}
switch_channel_set_variable(new_channel, "record_append", save);
}
return x ? SWITCH_STATUS_SUCCESS : SWITCH_STATUS_FALSE;
}
SWITCH_DECLARE(switch_status_t) switch_core_media_bug_enumerate(switch_core_session_t *session, switch_stream_handle_t *stream)
{
switch_media_bug_t *bp;
+34 -3
View File
@@ -616,6 +616,10 @@ static const char *message_names[] = {
"APPLICATION_EXEC_COMPLETE",
"PHONE_EVENT",
"T38_DESCRIPTION"
"UDPTL_MODE",
"CLEAR_PROGRESS",
"JITTER_BUFFER",
"RECOVERY_REFRESH",
"INVALID"
};
@@ -644,8 +648,8 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_perform_receive_message(swit
message->_line = line;
}
if (message->message_id > SWITCH_MESSAGE_INVALID) {
message->message_id = SWITCH_MESSAGE_INVALID;
if (message->message_id > SWITCH_MESSAGE_INVALID-1) {
message->message_id = SWITCH_MESSAGE_INVALID-1;
}
switch_log_printf(SWITCH_CHANNEL_ID_LOG, message->_file, message->_func, message->_line,
@@ -1975,7 +1979,8 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_exec(switch_core_session_t *
char *expanded = NULL;
const char *app;
switch_core_session_message_t msg = { 0 };
char delim = ',';
switch_assert(application_interface);
app = application_interface->interface_name;
@@ -1984,6 +1989,30 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_exec(switch_core_session_t *
expanded = switch_channel_expand_variables(session->channel, arg);
}
if (expanded && *expanded == '%' && (*(expanded+1) == '[' || *(expanded+2) == '[')) {
char *p, *dup;
switch_event_t *ovars = NULL;
p = expanded + 1;
if (*p != '[') {
delim = *p;
p++;
}
dup = strdup(p);
if (expanded != arg) {
switch_safe_free(expanded);
}
switch_event_create_brackets(dup, '[', ']', delim, &ovars, &expanded, SWITCH_TRUE);
free(dup);
switch_channel_set_scope_variables(session->channel, &ovars);
}
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG_CLEAN(session), SWITCH_LOG_DEBUG, "EXECUTE %s %s(%s)\n",
switch_channel_get_name(session->channel), app, switch_str_nil(expanded));
@@ -2062,6 +2091,8 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_exec(switch_core_session_t *
switch_safe_free(expanded);
}
switch_channel_set_scope_variables(session->channel, NULL);
return SWITCH_STATUS_SUCCESS;
}
+359 -65
View File
@@ -727,7 +727,7 @@ SWITCH_DECLARE(switch_status_t) switch_event_set_priority(switch_event_t *event,
return SWITCH_STATUS_SUCCESS;
}
SWITCH_DECLARE(char *) switch_event_get_header(switch_event_t *event, const char *header_name)
SWITCH_DECLARE(switch_event_header_t *) switch_event_get_header_ptr(switch_event_t *event, const char *header_name)
{
switch_event_header_t *hp;
switch_ssize_t hlen = -1;
@@ -742,12 +742,31 @@ SWITCH_DECLARE(char *) switch_event_get_header(switch_event_t *event, const char
for (hp = event->headers; hp; hp = hp->next) {
if ((!hp->hash || hash == hp->hash) && !strcasecmp(hp->name, header_name)) {
return hp->value;
return hp;
}
}
return NULL;
}
SWITCH_DECLARE(char *) switch_event_get_header_idx(switch_event_t *event, const char *header_name, int idx)
{
switch_event_header_t *hp;
if ((hp = switch_event_get_header_ptr(event, header_name))) {
if (idx > -1) {
if (idx < hp->idx) {
return hp->array[idx];
} else {
return NULL;
}
}
return hp->value;
}
return NULL;
}
SWITCH_DECLARE(char *) switch_event_get_body(switch_event_t *event)
{
return (event ? event->body : NULL);
@@ -780,7 +799,19 @@ SWITCH_DECLARE(switch_status_t) switch_event_del_header_val(switch_event_t *even
event->last_header = lp;
}
FREE(hp->name);
if (hp->idx) {
int i = 0;
hp->value = NULL;
for (i = 0; i < hp->idx; i++) {
FREE(hp->array[i]);
}
FREE(hp->array);
}
FREE(hp->value);
memset(hp, 0, sizeof(*hp));
#ifdef SWITCH_EVENT_RECYCLE
if (switch_queue_trypush(EVENT_HEADER_RECYCLE_QUEUE, hp) != SWITCH_STATUS_SUCCESS) {
@@ -798,49 +829,246 @@ SWITCH_DECLARE(switch_status_t) switch_event_del_header_val(switch_event_t *even
return status;
}
switch_status_t switch_event_base_add_header(switch_event_t *event, switch_stack_t stack, const char *header_name, char *data)
static switch_event_header_t *new_header(const char *header_name)
{
switch_event_header_t *header;
#ifdef SWITCH_EVENT_RECYCLE
void *pop;
if (switch_queue_trypop(EVENT_HEADER_RECYCLE_QUEUE, &pop) == SWITCH_STATUS_SUCCESS) {
header = (switch_event_header_t *) pop;
} else {
#endif
header = ALLOC(sizeof(*header));
switch_assert(header);
#ifdef SWITCH_EVENT_RECYCLE
}
#endif
memset(header, 0, sizeof(*header));
header->name = DUP(header_name);
return header;
}
SWITCH_DECLARE(int) switch_event_add_array(switch_event_t *event, const char *var, const char *val)
{
char *data;
char **array;
int max = 0;
int len;
const char *p;
int i;
if (strlen(val) < 8) {
return -1;
}
p = val + 7;
max = 1;
while((p = strstr(p, "|:"))) {
max++;
p += 2;
}
if (!max) {
return -2;
}
data = strdup(val + 7);
len = (sizeof(char *) * max) + 1;
switch_assert(len);
array = malloc(len);
memset(array, 0, len);
switch_separate_string_string(data, "|:", array, max);
for(i = 0; i < max; i++) {
switch_event_add_header_string(event, SWITCH_STACK_PUSH, var, array[i]);
}
free(array);
free(data);
return 0;
}
static switch_status_t switch_event_base_add_header(switch_event_t *event, switch_stack_t stack, const char *header_name, char *data)
{
switch_event_header_t *header = NULL;
switch_ssize_t hlen = -1;
int exists = 0, fly = 0;
char *index_ptr;
int index = 0;
char *real_header_name = NULL;
if ((index_ptr = strchr(header_name, '['))) {
index_ptr++;
index = atoi(index_ptr);
real_header_name = DUP(header_name);
if ((index_ptr = strchr(real_header_name, '['))) {
*index_ptr++ = '\0';
}
header_name = real_header_name;
}
if (index_ptr || (stack & SWITCH_STACK_PUSH) || (stack & SWITCH_STACK_UNSHIFT)) {
if (!(header = switch_event_get_header_ptr(event, header_name)) && index_ptr) {
header = new_header(header_name);
if (switch_test_flag(event, EF_UNIQ_HEADERS)) {
switch_event_del_header(event, header_name);
}
fly++;
}
if ((header = switch_event_get_header_ptr(event, header_name))) {
if (index_ptr) {
if (index > -1 && index <= 4000) {
if (index < header->idx) {
FREE(header->array[index]);
header->array[index] = DUP(data);
} else {
int i;
char **m;
m = realloc(header->array, sizeof(char *) * (index + 1));
switch_assert(m);
header->array = m;
for (i = header->idx; i < index; i++) {
m[i] = DUP("");
}
m[index] = DUP(data);
header->idx = index + 1;
if (!fly) {
exists = 1;
}
goto redraw;
}
}
goto end;
} else {
if ((stack & SWITCH_STACK_PUSH) || (stack & SWITCH_STACK_UNSHIFT)) {
exists++;
stack &= ~(SWITCH_STACK_TOP | SWITCH_STACK_BOTTOM);
} else {
header = NULL;
}
}
}
}
if (!header) {
if (zstr(data)) {
switch_event_del_header(event, header_name);
FREE(data);
goto end;
}
if (switch_test_flag(event, EF_UNIQ_HEADERS)) {
switch_event_del_header(event, header_name);
}
if (strstr(data, "ARRAY::")) {
switch_event_add_array(event, header_name, data);
FREE(data);
goto end;
}
header = new_header(header_name);
}
if ((stack & SWITCH_STACK_PUSH) || (stack & SWITCH_STACK_UNSHIFT)) {
char **m = NULL;
switch_size_t len = 0;
char *hv;
int i = 0, j = 0;
if (header->value && !header->idx) {
m = malloc(sizeof(char *));
switch_assert(m);
m[0] = header->value;
header->value = NULL;
header->array = m;
header->idx++;
m = NULL;
}
i = header->idx + 1;
m = realloc(header->array, sizeof(char *) * i);
switch_assert(m);
if ((stack & SWITCH_STACK_PUSH)) {
m[header->idx] = data;
} else if ((stack & SWITCH_STACK_UNSHIFT)) {
for (j = header->idx; j > 0; j--) {
m[j] = m[j-1];
}
m[0] = data;
}
header->idx++;
header->array = m;
redraw:
len = 0;
for(j = 0; j < header->idx; j++) {
len += strlen(header->array[j]) + 2;
}
if (len) {
len += 8;
hv = realloc(header->value, len);
switch_assert(hv);
header->value = hv;
switch_snprintf(header->value, len, "ARRAY::");
for(j = 0; j < header->idx; j++) {
switch_snprintf(header->value + strlen(header->value), len - strlen(header->value), "%s%s", j == 0 ? "" : "|:", header->array[j]);
}
}
#ifdef SWITCH_EVENT_RECYCLE
void *pop;
if (switch_queue_trypop(EVENT_HEADER_RECYCLE_QUEUE, &pop) == SWITCH_STATUS_SUCCESS) {
header = (switch_event_header_t *) pop;
} else {
#endif
header = ALLOC(sizeof(*header));
switch_assert(header);
#ifdef SWITCH_EVENT_RECYCLE
}
#endif
if (switch_test_flag(event, EF_UNIQ_HEADERS)) {
switch_event_del_header(event, header_name);
header->value = data;
}
memset(header, 0, sizeof(*header));
if (!exists) {
header->hash = switch_ci_hashfunc_default(header->name, &hlen);
header->name = DUP(header_name);
header->value = data;
header->hash = switch_ci_hashfunc_default(header->name, &hlen);
if ((stack & SWITCH_STACK_TOP)) {
header->next = event->headers;
event->headers = header;
if (!event->last_header) {
if ((stack & SWITCH_STACK_TOP)) {
header->next = event->headers;
event->headers = header;
if (!event->last_header) {
event->last_header = header;
}
} else {
if (event->last_header) {
event->last_header->next = header;
} else {
event->headers = header;
header->next = NULL;
}
event->last_header = header;
}
} else {
if (event->last_header) {
event->last_header->next = header;
} else {
event->headers = header;
header->next = NULL;
}
event->last_header = header;
}
end:
switch_safe_free(real_header_name);
return SWITCH_STATUS_SUCCESS;
}
@@ -914,7 +1142,19 @@ SWITCH_DECLARE(void) switch_event_destroy(switch_event_t **event)
this = hp;
hp = hp->next;
FREE(this->name);
if (this->idx) {
int i = 0;
this->value = NULL;
for (i = 0; i < this->idx; i++) {
FREE(this->array[i]);
}
FREE(this->array);
}
FREE(this->value);
#ifdef SWITCH_EVENT_RECYCLE
if (switch_queue_trypush(EVENT_HEADER_RECYCLE_QUEUE, this) != SWITCH_STATUS_SUCCESS) {
FREE(this);
@@ -947,7 +1187,15 @@ SWITCH_DECLARE(void) switch_event_merge(switch_event_t *event, switch_event_t *t
switch_assert(tomerge && event);
for (hp = tomerge->headers; hp; hp = hp->next) {
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, hp->name, hp->value);
if (hp->idx) {
int i;
for(i = 0; i < hp->idx; i++) {
switch_event_add_header_string(event, SWITCH_STACK_PUSH, hp->name, hp->array[i]);
}
} else {
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, hp->name, hp->value);
}
}
}
@@ -967,7 +1215,15 @@ SWITCH_DECLARE(switch_status_t) switch_event_dup(switch_event_t **event, switch_
if (todup->subclass_name && !strcmp(hp->name, "Event-Subclass")) {
continue;
}
switch_event_add_header_string(*event, SWITCH_STACK_BOTTOM, hp->name, hp->value);
if (hp->idx) {
int i;
for (i = 0; i < hp->idx; i++) {
switch_event_add_header_string(*event, SWITCH_STACK_PUSH, hp->name, hp->array[i]);
}
} else {
switch_event_add_header_string(*event, SWITCH_STACK_BOTTOM, hp->name, hp->value);
}
}
if (todup->body) {
@@ -992,13 +1248,12 @@ SWITCH_DECLARE(switch_status_t) switch_event_serialize(switch_event_t *event, ch
dlen = blocksize * 2;
if (!(buf = malloc(dlen))) {
return SWITCH_STATUS_MEMERR;
abort();
}
/* go ahead and give ourselves some space to work with, should save a few reallocs */
if (!(encode_buf = malloc(encode_len))) {
switch_safe_free(buf);
return SWITCH_STATUS_MEMERR;
abort();
}
/* switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "hit serialized!.\n"); */
@@ -1011,45 +1266,47 @@ SWITCH_DECLARE(switch_status_t) switch_event_serialize(switch_event_t *event, ch
* destroying loop.
*/
new_len = (strlen(hp->value) * 3) + 1;
if (hp->idx) {
int i;
new_len = 0;
for(i = 0; i < hp->idx; i++) {
new_len += (strlen(hp->array[i]) * 3) + 1;
}
} else {
new_len = (strlen(hp->value) * 3) + 1;
}
if (encode_len < new_len) {
char *tmp;
/* switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Allocing %d was %d.\n", ((strlen(hp->value) * 3) + 1), encode_len); */
/* we can use realloc for initial alloc as well, if encode_buf is zero it treats it as a malloc */
/* keep track of the size of our allocation */
encode_len = new_len;
if (!(tmp = realloc(encode_buf, encode_len))) {
/* oh boy, ram's gone, give back what little we grabbed and bail */
switch_safe_free(buf);
switch_safe_free(encode_buf);
return SWITCH_STATUS_MEMERR;
abort();
}
encode_buf = tmp;
}
/* handle any bad things in the string like newlines : etc that screw up the serialized format */
if (encode) {
switch_url_encode(hp->value, encode_buf, encode_len);
} else {
switch_snprintf(encode_buf, encode_len, "[%s]", hp->value);
}
llen = strlen(hp->name) + strlen(encode_buf) + 8;
if ((len + llen) > dlen) {
char *m;
char *m = buf;
dlen += (blocksize + (len + llen));
if ((m = realloc(buf, dlen))) {
if (!(buf = realloc(buf, dlen))) {
buf = m;
} else {
/* we seem to be out of memory trying to resize the serialize string, give back what we already have and give up */
switch_safe_free(buf);
switch_safe_free(encode_buf);
return SWITCH_STATUS_MEMERR;
abort();
}
}
@@ -1071,13 +1328,11 @@ SWITCH_DECLARE(switch_status_t) switch_event_serialize(switch_event_t *event, ch
}
if ((len + llen) > dlen) {
char *m;
char *m = buf;
dlen += (blocksize + (len + llen));
if ((m = realloc(buf, dlen))) {
if (!(buf = realloc(buf, dlen))) {
buf = m;
} else {
switch_safe_free(buf);
return SWITCH_STATUS_MEMERR;
abort();
}
}
@@ -1212,19 +1467,31 @@ SWITCH_DECLARE(switch_status_t) switch_event_create_json(switch_event_t **event,
for (cjp = cj->child; cjp; cjp = cjp->next) {
char *name = cjp->string;
char *value = cjp->valuestring;
if (name && value) {
if (!strcasecmp(name, "_body")) {
switch_event_add_body(new_event, value, SWITCH_VA_NONE);
} else {
if (!strcasecmp(name, "event-name")) {
switch_event_del_header(new_event, "event-name");
switch_name_event(value, &new_event->event_id);
}
switch_name_event(value, &new_event->event_id);
switch_event_add_header_string(new_event, SWITCH_STACK_BOTTOM, name, value);
}
} else if (name) {
if (cjp->type == cJSON_Array) {
int i, x = cJSON_GetArraySize(cjp);
for (i = 0; i < x; i++) {
cJSON *item = cJSON_GetArrayItem(cjp, i);
if (item && item->type == cJSON_String && item->valuestring) {
switch_event_add_header_string(new_event, SWITCH_STACK_PUSH, name, item->valuestring);
}
}
}
}
}
@@ -1243,8 +1510,21 @@ SWITCH_DECLARE(switch_status_t) switch_event_serialize_json(switch_event_t *even
cj = cJSON_CreateObject();
for (hp = event->headers; hp; hp = hp->next) {
cJSON_AddItemToObject(cj, hp->name, cJSON_CreateString(hp->value));
}
if (hp->idx) {
cJSON *a = cJSON_CreateArray();
int i;
for(i = 0; i < hp->idx; i++) {
cJSON_AddItemToArray(a, cJSON_CreateString(hp->array[i]));
}
cJSON_AddItemToObject(cj, hp->name, a);
} else {
cJSON_AddItemToObject(cj, hp->name, cJSON_CreateString(hp->value));
}
}
if (event->body) {
int blen = (int) strlen(event->body);
char tmp[25];
@@ -1316,7 +1596,15 @@ SWITCH_DECLARE(switch_xml_t) switch_event_xmlize(switch_event_t *event, const ch
if ((xheaders = switch_xml_add_child_d(xml, "headers", off++))) {
int hoff = 0;
for (hp = event->headers; hp; hp = hp->next) {
add_xml_header(xheaders, hp->name, hp->value, hoff++);
if (hp->idx) {
int i;
for (i = 0; i < hp->idx; i++) {
add_xml_header(xheaders, hp->name, hp->array[i], hoff++);
}
} else {
add_xml_header(xheaders, hp->name, hp->value, hoff++);
}
}
}
@@ -1730,7 +2018,8 @@ SWITCH_DECLARE(char *) switch_event_expand_headers(switch_event_t *event, const
int offset = 0;
int ooffset = 0;
char *ptr;
int idx = -1;
if ((expanded = switch_event_expand_headers(event, (char *) vname)) == vname) {
expanded = NULL;
} else {
@@ -1745,7 +2034,12 @@ SWITCH_DECLARE(char *) switch_event_expand_headers(switch_event_t *event, const
}
}
if (!(sub_val = switch_event_get_header(event, vname))) {
if ((ptr = strchr(vname, '[')) && strchr(ptr, ']')) {
*ptr++ = '\0';
idx = atoi(ptr);
}
if (!(sub_val = switch_event_get_header_idx(event, vname, idx))) {
switch_safe_free(gvar);
if ((gvar = switch_core_get_variable_dup(vname))) {
sub_val = gvar;
+64 -40
View File
@@ -155,7 +155,13 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_sleep(switch_core_session_t *session,
return SWITCH_STATUS_SUCCESS;
}
if (ms > 100 && (var = switch_channel_get_variable(channel, SWITCH_SEND_SILENCE_WHEN_IDLE_VARIABLE)) && (sval = atoi(var))) {
var = switch_channel_get_variable(channel, SWITCH_SEND_SILENCE_WHEN_IDLE_VARIABLE);
if (var) {
sval = atoi(var);
SWITCH_IVR_VERIFY_SILENCE_DIVISOR(sval);
}
if (ms > 100 && sval) {
switch_core_session_get_read_impl(session, &imp);
if (switch_core_codec_init(&codec,
@@ -744,34 +750,6 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_park(switch_core_session_t *session,
unsigned char *abuf = NULL;
switch_codec_implementation_t imp = { 0 };
if ((var = switch_channel_get_variable(channel, SWITCH_SEND_SILENCE_WHEN_IDLE_VARIABLE)) && (sval = atoi(var))) {
switch_core_session_get_read_impl(session, &imp);
if (switch_core_codec_init(&codec,
"L16",
NULL,
imp.samples_per_second,
imp.microseconds_per_packet / 1000,
imp.number_of_channels,
SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL,
switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Codec Error L16@%uhz %u channels %dms\n",
imp.samples_per_second, imp.number_of_channels, imp.microseconds_per_packet / 1000);
return SWITCH_STATUS_FALSE;
}
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Codec Activated L16@%uhz %u channels %dms\n",
imp.samples_per_second, imp.number_of_channels, imp.microseconds_per_packet / 1000);
write_frame.codec = &codec;
switch_zmalloc(abuf, SWITCH_RECOMMENDED_BUFFER_SIZE);
write_frame.data = abuf;
write_frame.buflen = SWITCH_RECOMMENDED_BUFFER_SIZE;
write_frame.datalen = imp.decoded_bytes_per_packet;
write_frame.samples = write_frame.datalen / sizeof(int16_t);
}
if (switch_channel_test_flag(channel, CF_RECOVERED) && switch_channel_test_flag(channel, CF_CONTROLLED)) {
switch_channel_clear_flag(channel, CF_CONTROLLED);
}
@@ -815,6 +793,34 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_park(switch_core_session_t *session,
switch_core_session_get_read_impl(session, &read_impl);
rate = read_impl.actual_samples_per_second;
bpf = read_impl.decoded_bytes_per_packet;
if ((var = switch_channel_get_variable(channel, SWITCH_SEND_SILENCE_WHEN_IDLE_VARIABLE)) && (sval = atoi(var))) {
switch_core_session_get_read_impl(session, &imp);
if (switch_core_codec_init(&codec,
"L16",
NULL,
imp.samples_per_second,
imp.microseconds_per_packet / 1000,
imp.number_of_channels,
SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL,
switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Codec Error L16@%uhz %u channels %dms\n",
imp.samples_per_second, imp.number_of_channels, imp.microseconds_per_packet / 1000);
return SWITCH_STATUS_FALSE;
}
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Codec Activated L16@%uhz %u channels %dms\n",
imp.samples_per_second, imp.number_of_channels, imp.microseconds_per_packet / 1000);
write_frame.codec = &codec;
switch_zmalloc(abuf, SWITCH_RECOMMENDED_BUFFER_SIZE);
write_frame.data = abuf;
write_frame.buflen = SWITCH_RECOMMENDED_BUFFER_SIZE;
write_frame.datalen = imp.decoded_bytes_per_packet;
write_frame.samples = write_frame.datalen / sizeof(int16_t);
}
}
if (rate) {
@@ -839,7 +845,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_park(switch_core_session_t *session,
break;
}
if (write_frame.data) {
if (rate && write_frame.data && sval) {
switch_generate_sln_silence((int16_t *) write_frame.data, write_frame.samples, sval);
switch_core_session_write_frame(session, &write_frame, SWITCH_IO_FLAG_NONE, 0);
}
@@ -1982,25 +1988,43 @@ SWITCH_DECLARE(int) switch_ivr_set_xml_profile_data(switch_xml_t xml, switch_cal
return off;
}
static int switch_ivr_set_xml_chan_var(switch_xml_t xml, const char *var, const char *val, int off)
{
char *data;
switch_size_t dlen = strlen(val) * 3 + 1;
switch_xml_t variable;
if (!zstr(var) && !zstr(val) && ((variable = switch_xml_add_child_d(xml, var, off++)))) {
if ((data = malloc(dlen))) {
memset(data, 0, dlen);
switch_url_encode(val, data, dlen);
switch_xml_set_txt_d(variable, data);
free(data);
} else abort();
}
return off;
}
SWITCH_DECLARE(int) switch_ivr_set_xml_chan_vars(switch_xml_t xml, switch_channel_t *channel, int off)
{
switch_xml_t variable;
switch_event_header_t *hi = switch_channel_variable_first(channel);
if (!hi)
return off;
for (; hi; hi = hi->next) {
if (!zstr(hi->name) && !zstr(hi->value) && ((variable = switch_xml_add_child_d(xml, hi->name, off++)))) {
char *data;
switch_size_t dlen = strlen(hi->value) * 3 + 1;
if ((data = malloc(dlen))) {
memset(data, 0, dlen);
switch_url_encode(hi->value, data, dlen);
switch_xml_set_txt_d(variable, data);
free(data);
if (hi->idx) {
int i;
for (i = 0; i < hi->idx; i++) {
off = switch_ivr_set_xml_chan_var(xml, hi->name, hi->array[i], off);
}
} else {
off = switch_ivr_set_xml_chan_var(xml, hi->name, hi->value, off);
}
}
switch_channel_variable_last(channel);
+41 -9
View File
@@ -936,12 +936,6 @@ static switch_bool_t record_callback(switch_media_bug_t *bug, void *user_data, s
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Stop recording file %s\n", rh->file);
switch_channel_set_private(channel, rh->file, NULL);
if (switch_event_create(&event, SWITCH_EVENT_RECORD_STOP) == SWITCH_STATUS_SUCCESS) {
switch_channel_event_set_data(channel, event);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Record-File-Path", rh->file);
switch_event_fire(&event);
}
if (rh->fh) {
switch_size_t len;
uint8_t data[SWITCH_RECOMMENDED_BUFFER_SIZE];
@@ -970,6 +964,12 @@ static switch_bool_t record_callback(switch_media_bug_t *bug, void *user_data, s
}
}
if (switch_event_create(&event, SWITCH_EVENT_RECORD_STOP) == SWITCH_STATUS_SUCCESS) {
switch_channel_event_set_data(channel, event);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Record-File-Path", rh->file);
switch_event_fire(&event);
}
if ((var = switch_channel_get_variable(channel, "record_post_process_exec_app"))) {
char *app = switch_core_session_strdup(session, var);
char *data;
@@ -1444,7 +1444,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_record_session(switch_core_session_t
int file_flags = SWITCH_FILE_FLAG_WRITE | SWITCH_FILE_DATA_SHORT;
switch_bool_t hangup_on_error = SWITCH_FALSE;
char *file_path = NULL;
if ((p = switch_channel_get_variable(channel, "RECORD_HANGUP_ON_ERROR"))) {
hangup_on_error = switch_true(p);
}
@@ -1463,7 +1463,36 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_record_session(switch_core_session_t
channels = read_impl.number_of_channels;
if ((bug = switch_channel_get_private(channel, file))) {
return switch_ivr_stop_record_session(session, file);
if (switch_true(switch_channel_get_variable(channel, "RECORD_TOGGLE_ON_REPEAT"))) {
return switch_ivr_stop_record_session(session, file);
}
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "Already recording [%s]\n", file);
return SWITCH_STATUS_SUCCESS;
}
if ((p = switch_channel_get_variable(channel, "RECORD_CHECK_BRIDGE")) && switch_true(p)) {
switch_core_session_t *other_session;
int exist = 0;
switch_status_t rstatus = SWITCH_STATUS_SUCCESS;
if (switch_core_session_get_partner(session, &other_session) == SWITCH_STATUS_SUCCESS) {
switch_channel_t *other_channel = switch_core_session_get_channel(other_session);
if ((bug = switch_channel_get_private(other_channel, file))) {
if (switch_true(switch_channel_get_variable(other_channel, "RECORD_TOGGLE_ON_REPEAT"))) {
rstatus = switch_ivr_stop_record_session(other_session, file);
} else {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(other_session), SWITCH_LOG_WARNING, "Already recording [%s]\n", file);
}
exist = 1;
}
switch_core_session_rwunlock(other_session);
}
if (exist) {
return rstatus;
}
}
if (!fh) {
@@ -1615,7 +1644,9 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_record_session(switch_core_session_t
rh->file = switch_core_session_strdup(session, file);
rh->packet_len = read_impl.decoded_bytes_per_packet;
rh->min_sec = 3;
if (file_flags & SWITCH_FILE_WRITE_APPEND) {
rh->min_sec = 3;
}
if ((p = switch_channel_get_variable(channel, "RECORD_MIN_SEC"))) {
int tmp = atoi(p);
@@ -1638,6 +1669,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_record_session(switch_core_session_t
return SWITCH_STATUS_SUCCESS;
}
typedef struct {
SpeexPreprocessState *read_st;
SpeexPreprocessState *write_st;
+17 -9
View File
@@ -910,9 +910,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_wait_for_answer(switch_core_session_t
ringback.silence = atoi(p);
}
}
if (ringback.silence <= 0) {
ringback.silence = 400;
}
SWITCH_IVR_VERIFY_SILENCE_DIVISOR(ringback.silence);
} else {
switch_buffer_create_dynamic(&ringback.audio_buffer, 512, 1024, 0);
switch_buffer_set_loops(ringback.audio_buffer, -1);
@@ -1203,9 +1201,7 @@ static switch_status_t setup_ringback(originate_global_t *oglobals, originate_st
ringback->silence = atoi(c);
}
}
if (ringback->silence <= 0) {
ringback->silence = 400;
}
SWITCH_IVR_VERIFY_SILENCE_DIVISOR(ringback->silence);
} else {
switch_buffer_create_dynamic(&ringback->audio_buffer, 512, 1024, 0);
switch_buffer_set_loops(ringback->audio_buffer, -1);
@@ -2444,7 +2440,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess
switch_event_destroy(&originate_var_event);
if (reason != SWITCH_CAUSE_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Cannot create outgoing channel of type [%s] cause: [%s]\n",
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_NOTICE, "Cannot create outgoing channel of type [%s] cause: [%s]\n",
chan_type, switch_channel_cause2str(reason));
if (local_var_event) switch_event_destroy(&local_var_event);
@@ -2938,7 +2934,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess
oglobals.idx = IDX_CANCEL;
}
if (oglobals.session && (ringback_data || !(switch_channel_test_flag(caller_channel, CF_PROXY_MODE) &&
if (oglobals.session && (ringback_data || !(switch_channel_test_flag(caller_channel, CF_PROXY_MODE) ||
switch_channel_test_flag(caller_channel, CF_PROXY_MEDIA)))) {
switch_core_session_reset(oglobals.session, SWITCH_FALSE, SWITCH_TRUE);
}
@@ -3127,10 +3123,22 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess
switch_core_session_t *holding_session;
if ((holding_session = switch_core_session_locate(holding))) {
switch_channel_set_variable(switch_core_session_get_channel(holding_session), SWITCH_HANGUP_AFTER_BRIDGE_VARIABLE, "true");
switch_channel_t *holding_channel = switch_core_session_get_channel(holding_session);
switch_channel_set_variable(holding_channel, SWITCH_HANGUP_AFTER_BRIDGE_VARIABLE, "true");
if (caller_channel && switch_true(switch_channel_get_variable(caller_channel, "recording_follow_transfer"))) {
switch_core_media_bug_transfer_recordings(session, originate_status[i].peer_session);
}
if (switch_true(switch_channel_get_variable(holding_channel, "recording_follow_transfer"))) {
switch_core_media_bug_transfer_recordings(holding_session, originate_status[i].peer_session);
}
switch_core_session_rwunlock(holding_session);
}
switch_channel_set_flag(originate_status[i].peer_channel, CF_LAZY_ATTENDED_TRANSFER);
switch_ivr_uuid_bridge(holding, switch_core_session_get_uuid(originate_status[i].peer_session));
holding = NULL;
} else {
+30 -2
View File
@@ -129,7 +129,7 @@ SWITCH_DECLARE(void) switch_perform_substitution(switch_regex_t *re, int match_c
char *substituted, switch_size_t len, int *ovector)
{
char index[10] = "";
char replace[1024] = "";
const char *replace = NULL;
switch_size_t x, y = 0, z = 0;
int num = 0;
@@ -154,11 +154,12 @@ SWITCH_DECLARE(void) switch_perform_substitution(switch_regex_t *re, int match_c
num = -1;
}
if (pcre_copy_substring(field_data, ovector, match_count, num, replace, sizeof(replace)) > 0) {
if (pcre_get_substring(field_data, ovector, match_count, num, &replace) > 0) {
switch_size_t r;
for (r = 0; r < strlen(replace); r++) {
substituted[y++] = replace[r];
}
pcre_free_substring(replace);
}
} else {
substituted[y++] = data[x];
@@ -168,6 +169,24 @@ SWITCH_DECLARE(void) switch_perform_substitution(switch_regex_t *re, int match_c
substituted[y++] = '\0';
}
SWITCH_DECLARE(void) switch_capture_regex(switch_regex_t *re, int match_count, const char *field_data,
int *ovector, const char *var, switch_cap_callback_t callback, void *user_data)
{
const char *replace;
int i;
for (i = 0; i < match_count; i++) {
if (pcre_get_substring(field_data, ovector, match_count, i, &replace) > 0) {
callback(var, replace, user_data);
pcre_free_substring(replace);
}
}
}
SWITCH_DECLARE(switch_status_t) switch_regex_match_partial(const char *target, const char *expression, int *partial)
{
const char *error = NULL; /* Used to hold any errors */
@@ -230,6 +249,15 @@ SWITCH_DECLARE(switch_status_t) switch_regex_match(const char *target, const cha
return switch_regex_match_partial(target, expression, &partial);
}
SWITCH_DECLARE_NONSTD(void) switch_regex_set_var_callback(const char *var, const char *val, void *user_data)
{
switch_core_session_t *session = (switch_core_session_t *) user_data;
switch_channel_t *channel = switch_core_session_get_channel(session);
switch_channel_add_variable_var_check(channel, var, val, SWITCH_FALSE, SWITCH_STACK_PUSH);
}
/* For Emacs:
* Local Variables:
* mode:c
+5
View File
@@ -190,6 +190,11 @@ SWITCH_DECLARE(void) switch_generate_sln_silence(int16_t *data, uint32_t samples
assert(divisor);
if (divisor == (uint32_t)-1) {
memset(data, 0, sizeof(*data));
return;
}
for (i = 0; i < samples; i++, sum_rnd = 0) {
for (x = 0; x < 6; x++) {
rnd2 = rnd2 * 31821U + 13849U;
+1 -1
View File
@@ -238,7 +238,7 @@ int fs_switch_ivr_originate(switch_core_session_t *session, switch_core_session_
}
if (switch_ivr_originate(session, &peer_session, &cause, bridgeto, timelimit, NULL, NULL, NULL, NULL, SOF_NONE) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Cannot Create Outgoing Channel!\n");
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_NOTICE, "Cannot Create Outgoing Channel!\n");
switch_channel_hangup(caller_channel, SWITCH_CAUSE_REQUESTED_CHAN_UNAVAIL);
return;
} else {
+1 -1
View File
@@ -2669,7 +2669,7 @@ SWITCH_DECLARE(switch_bool_t) switch_dow_cmp(const char *exp, int val)
/* Save the previous token and move to the next one */
range_start = prev;
} else if (cur == DOW_ERR) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Parse error for [%s] at position %td (%.6s)\n", exp, p - exp, p);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Parse error for [%s] at position %ld (%.6s)\n", exp, (long) (p - exp), p);
break;
} else {
/* Valid day found */
+97 -13
View File
@@ -136,10 +136,12 @@ static switch_memory_pool_t *XML_MEMORY_POOL = NULL;
static switch_thread_rwlock_t *B_RWLOCK = NULL;
static switch_mutex_t *XML_LOCK = NULL;
static switch_mutex_t *CACHE_MUTEX = NULL;
static switch_mutex_t *REFLOCK = NULL;
static switch_mutex_t *FILE_LOCK = NULL;
static switch_mutex_t *XML_GEN_LOCK = NULL;
static switch_hash_t *CACHE_HASH = NULL;
struct xml_section_t {
const char *name;
@@ -1123,12 +1125,12 @@ SWITCH_DECLARE(switch_xml_t) switch_xml_parse_fp(FILE * fp)
do {
len += (l = fread((s + len), 1, SWITCH_XML_BUFSIZE, fp));
if (l == SWITCH_XML_BUFSIZE) {
char *tmp = (char *) realloc(s, len + SWITCH_XML_BUFSIZE);
if (!tmp) {
free(s);
char *tmp = s;
s = (char *) realloc(s, len + SWITCH_XML_BUFSIZE);
if (!s) {
free(tmp);
return NULL;
}
s = tmp;
}
} while (s && l == SWITCH_XML_BUFSIZE);
@@ -1826,15 +1828,90 @@ SWITCH_DECLARE(void) switch_xml_merge_user(switch_xml_t user, switch_xml_t domai
do_merge(user, domain, "variables", "variable");
}
SWITCH_DECLARE(uint32_t) switch_xml_clear_user_cache(const char *key, const char *user_name, const char *domain_name)
{
switch_hash_index_t *hi;
void *val;
const void *var;
char mega_key[1024];
int r = 0;
switch_xml_t lookup;
switch_mutex_lock(CACHE_MUTEX);
if (key && user_name && domain_name) {
switch_snprintf(mega_key, sizeof(mega_key), "%s%s%s", key, user_name, domain_name);
if ((lookup = switch_core_hash_find(CACHE_HASH, mega_key))) {
switch_core_hash_delete(CACHE_HASH, mega_key);
switch_xml_free(lookup);
r++;
}
} else {
while ((hi = switch_hash_first(NULL, CACHE_HASH))) {
switch_hash_this(hi, &var, NULL, &val);
switch_xml_free(val);
switch_core_hash_delete(CACHE_HASH, var);
r++;
}
}
switch_mutex_unlock(CACHE_MUTEX);
return r;
}
static switch_status_t switch_xml_locate_user_cache(const char *key, const char *user_name, const char *domain_name, switch_xml_t *user)
{
char mega_key[1024];
switch_xml_t lookup;
switch_status_t status = SWITCH_STATUS_FALSE;
switch_snprintf(mega_key, sizeof(mega_key), "%s%s%s", key, user_name, domain_name);
switch_mutex_lock(CACHE_MUTEX);
if ((lookup = switch_core_hash_find(CACHE_HASH, mega_key))) {
*user = switch_xml_dup(lookup);
status = SWITCH_STATUS_SUCCESS;
}
switch_mutex_unlock(CACHE_MUTEX);
return status;
}
static void switch_xml_user_cache(const char *key, const char *user_name, const char *domain_name, switch_xml_t user)
{
char mega_key[1024];
switch_xml_t lookup;
switch_snprintf(mega_key, sizeof(mega_key), "%s%s%s", key, user_name, domain_name);
switch_mutex_lock(CACHE_MUTEX);
if ((lookup = switch_core_hash_find(CACHE_HASH, mega_key))) {
switch_core_hash_delete(CACHE_HASH, mega_key);
switch_xml_free(lookup);
}
switch_core_hash_insert(CACHE_HASH, mega_key, switch_xml_dup(user));
switch_mutex_unlock(CACHE_MUTEX);
}
SWITCH_DECLARE(switch_status_t) switch_xml_locate_user_merged(const char *key, const char *user_name, const char *domain_name,
const char *ip, switch_xml_t *user, switch_event_t *params)
{
switch_xml_t xml, domain, group, x_user, x_user_dup;
switch_status_t status = SWITCH_STATUS_FALSE;
if ((status = switch_xml_locate_user(key, user_name, domain_name, ip, &xml, &domain, &x_user, &group, params)) == SWITCH_STATUS_SUCCESS) {
if ((status = switch_xml_locate_user_cache(key, user_name, domain_name, &x_user)) == SWITCH_STATUS_SUCCESS) {
*user = x_user;
} else if ((status = switch_xml_locate_user(key, user_name, domain_name, ip, &xml, &domain, &x_user, &group, params)) == SWITCH_STATUS_SUCCESS) {
x_user_dup = switch_xml_dup(x_user);
switch_xml_merge_user(x_user_dup, domain, group);
if (switch_true(switch_xml_attr(x_user_dup, "cacheable"))) {
switch_xml_user_cache(key, user_name, domain_name, x_user_dup);
}
*user = x_user_dup;
switch_xml_free(xml);
}
@@ -2057,10 +2134,12 @@ SWITCH_DECLARE(switch_status_t) switch_xml_init(switch_memory_pool_t *pool, cons
XML_MEMORY_POOL = pool;
*err = "Success";
switch_mutex_init(&CACHE_MUTEX, SWITCH_MUTEX_NESTED, XML_MEMORY_POOL);
switch_mutex_init(&XML_LOCK, SWITCH_MUTEX_NESTED, XML_MEMORY_POOL);
switch_mutex_init(&REFLOCK, SWITCH_MUTEX_NESTED, XML_MEMORY_POOL);
switch_mutex_init(&FILE_LOCK, SWITCH_MUTEX_NESTED, XML_MEMORY_POOL);
switch_mutex_init(&XML_GEN_LOCK, SWITCH_MUTEX_NESTED, XML_MEMORY_POOL);
switch_core_hash_init(&CACHE_HASH, XML_MEMORY_POOL);
switch_thread_rwlock_create(&B_RWLOCK, XML_MEMORY_POOL);
@@ -2078,6 +2157,7 @@ SWITCH_DECLARE(switch_status_t) switch_xml_destroy(void)
{
switch_status_t status = SWITCH_STATUS_FALSE;
switch_mutex_lock(XML_LOCK);
switch_mutex_lock(REFLOCK);
@@ -2091,6 +2171,10 @@ SWITCH_DECLARE(switch_status_t) switch_xml_destroy(void)
switch_mutex_unlock(XML_LOCK);
switch_mutex_unlock(REFLOCK);
switch_xml_clear_user_cache(NULL, NULL, NULL);
switch_core_hash_destroy(&CACHE_HASH);
return status;
}
@@ -2195,10 +2279,10 @@ static char *switch_xml_toxml_r(switch_xml_t xml, char **s, switch_size_t *len,
*s = switch_xml_ampencode(txt + start, xml->off - start, s, len, max, 0);
while (*len + strlen(xml->name) + 5 + (strlen(XML_INDENT) * (*count)) + 1 > *max) { /* reallocate s */
char *tmp = (char *) realloc(*s, *max += SWITCH_XML_BUFSIZE);
if (!tmp)
return *s;
*s = tmp;
char *tmp = *s;
*s = (char *) realloc(*s, *max += SWITCH_XML_BUFSIZE);
if (!*s)
return tmp;
}
if (*len && *(*s + (*len) - 1) == '>') {
@@ -2251,10 +2335,10 @@ static char *switch_xml_toxml_r(switch_xml_t xml, char **s, switch_size_t *len,
}
while (*len + strlen(xml->name) + 5 + (strlen(XML_INDENT) * (*count)) > *max) { /* reallocate s */
char *tmp = (char *) realloc(*s, *max += SWITCH_XML_BUFSIZE);
if (!tmp)
return *s;
*s = tmp;
char *tmp = *s;
*s = (char *) realloc(*s, *max += SWITCH_XML_BUFSIZE);
if (!*s)
return tmp;
}
if (xml->child || xml->txt) {