git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@416 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Anthony Minessale 2006-01-20 00:40:29 +00:00
parent e528c4df33
commit 42383b1f15
12 changed files with 468 additions and 471 deletions

View File

@ -31,7 +31,8 @@
*/
#include <switch.h>
int main(int argc, char *argv[]) {
int main(int argc, char *argv[])
{
char *err = NULL;
switch_event *event;
@ -47,7 +48,7 @@ int main(int argc, char *argv[]) {
}
}
if(err) {
if (err) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Error: %s", err);
exit(-1);
}
@ -75,5 +76,3 @@ int main(int argc, char *argv[]) {
return 0;
}

View File

@ -41,7 +41,8 @@ SWITCH_DECLARE(switch_status) switch_buffer_create(switch_memory_pool *pool, swi
{
switch_buffer *new_buffer;
if ((new_buffer = switch_core_alloc(pool, sizeof(switch_buffer))) && (new_buffer->data = switch_core_alloc(pool, max_len))) {
if ((new_buffer = switch_core_alloc(pool, sizeof(switch_buffer)))
&& (new_buffer->data = switch_core_alloc(pool, max_len))) {
new_buffer->datalen = max_len;
*buffer = new_buffer;
return SWITCH_STATUS_SUCCESS;
@ -54,7 +55,7 @@ SWITCH_DECLARE(int) switch_buffer_len(switch_buffer *buffer)
assert(buffer != NULL);
return (int)buffer->datalen;
return (int) buffer->datalen;
}
@ -63,14 +64,14 @@ SWITCH_DECLARE(int) switch_buffer_freespace(switch_buffer *buffer)
{
assert(buffer != NULL);
return (int)(buffer->datalen - buffer->used);
return (int) (buffer->datalen - buffer->used);
}
SWITCH_DECLARE(int) switch_buffer_inuse(switch_buffer *buffer)
{
assert(buffer != NULL);
return (int)buffer->used;
return (int) buffer->used;
}
SWITCH_DECLARE(int) switch_buffer_toss(switch_buffer *buffer, size_t datalen)
@ -91,7 +92,7 @@ SWITCH_DECLARE(int) switch_buffer_toss(switch_buffer *buffer, size_t datalen)
memmove(buffer->data, buffer->data + reading, buffer->datalen - reading);
buffer->used -= datalen;
return (int)buffer->datalen;
return (int) buffer->datalen;
}
SWITCH_DECLARE(int) switch_buffer_read(switch_buffer *buffer, void *data, size_t datalen)
@ -115,7 +116,7 @@ SWITCH_DECLARE(int) switch_buffer_read(switch_buffer *buffer, void *data, size_t
memmove(buffer->data, buffer->data + reading, buffer->datalen - reading);
buffer->used -= reading;
//printf("o %d = %d\n", reading, buffer->used);
return (int)reading;
return (int) reading;
}
SWITCH_DECLARE(int) switch_buffer_write(switch_buffer *buffer, void *data, size_t datalen)
@ -135,6 +136,5 @@ SWITCH_DECLARE(int) switch_buffer_write(switch_buffer *buffer, void *data, size_
buffer->used += datalen;
}
//printf("i %d = %d\n", datalen, buffer->used);
return (int)buffer->used;
return (int) buffer->used;
}

View File

@ -36,9 +36,7 @@ SWITCH_DECLARE(switch_caller_profile *) switch_caller_profile_new(switch_core_se
char *caller_id_name,
char *caller_id_number,
char *network_addr,
char *ani,
char *ani2,
char *destination_number)
char *ani, char *ani2, char *destination_number)
{
@ -75,8 +73,8 @@ SWITCH_DECLARE(switch_caller_profile *) switch_caller_profile_clone(switch_core_
return profile;
}
SWITCH_DECLARE(void) switch_caller_profile_event_set_data(switch_caller_profile *caller_profile, char *prefix, switch_event *event)
SWITCH_DECLARE(void) switch_caller_profile_event_set_data(switch_caller_profile *caller_profile, char *prefix,
switch_event *event)
{
char header_name[1024];
@ -112,9 +110,7 @@ SWITCH_DECLARE(void) switch_caller_profile_event_set_data(switch_caller_profile
}
SWITCH_DECLARE(switch_caller_extension *) switch_caller_extension_new(switch_core_session *session,
char *extension_name,
char *extension_number
)
char *extension_name, char *extension_number)
{
switch_caller_extension *caller_extension = NULL;
@ -130,8 +126,7 @@ SWITCH_DECLARE(switch_caller_extension *) switch_caller_extension_new(switch_cor
SWITCH_DECLARE(void) switch_caller_extension_add_application(switch_core_session *session,
switch_caller_extension *caller_extension,
char *application_name,
char *application_data)
char *application_name, char *application_data)
{
switch_caller_application *caller_application = NULL;
@ -142,7 +137,7 @@ SWITCH_DECLARE(void) switch_caller_extension_add_application(switch_core_session
caller_application->application_data = switch_core_session_strdup(session, application_data);
if (!caller_extension->applications) {
caller_extension->applications = caller_application;
} else if(caller_extension->last_application) {
} else if (caller_extension->last_application) {
caller_extension->last_application->next = caller_application;
}
@ -151,6 +146,3 @@ SWITCH_DECLARE(void) switch_caller_extension_add_application(switch_core_session
}
}

View File

@ -71,7 +71,8 @@ SWITCH_DECLARE(switch_status) switch_channel_alloc(switch_channel **channel, swi
return SWITCH_STATUS_SUCCESS;
}
SWITCH_DECLARE(switch_status) switch_channel_set_raw_mode (switch_channel *channel, int freq, int bits, int channels, int ms, int kbps)
SWITCH_DECLARE(switch_status) switch_channel_set_raw_mode(switch_channel *channel, int freq, int bits, int channels,
int ms, int kbps)
{
assert(channel != NULL);
@ -86,7 +87,8 @@ SWITCH_DECLARE(switch_status) switch_channel_set_raw_mode (switch_channel *chann
return SWITCH_STATUS_SUCCESS;
}
SWITCH_DECLARE(switch_status) switch_channel_get_raw_mode (switch_channel *channel, int *freq, int *bits, int *channels, int *ms, int *kbps)
SWITCH_DECLARE(switch_status) switch_channel_get_raw_mode(switch_channel *channel, int *freq, int *bits, int *channels,
int *ms, int *kbps)
{
if (freq) {
*freq = channel->freq;
@ -128,7 +130,7 @@ SWITCH_DECLARE(switch_status) switch_channel_queue_dtmf(switch_channel *channel,
assert(channel != NULL);
switch_mutex_lock(channel->dtmf_mutex);
if (switch_buffer_inuse(channel->dtmf_buffer) + strlen(dtmf) > (size_t)switch_buffer_len(channel->dtmf_buffer)) {
if (switch_buffer_inuse(channel->dtmf_buffer) + strlen(dtmf) > (size_t) switch_buffer_len(channel->dtmf_buffer)) {
switch_buffer_toss(channel->dtmf_buffer, strlen(dtmf));
}
@ -164,8 +166,7 @@ SWITCH_DECLARE(int) switch_channel_dequeue_dtmf(switch_channel *channel, char *d
SWITCH_DECLARE(switch_status) switch_channel_init(switch_channel *channel,
switch_core_session *session,
switch_channel_state state,
switch_channel_flag flags)
switch_channel_state state, switch_channel_flag flags)
{
assert(channel != NULL);
channel->state = state;
@ -277,115 +278,117 @@ SWITCH_DECLARE(switch_channel_state) switch_channel_set_state(switch_channel *ch
}
/* STUB for more dev
case CS_INIT:
switch(state) {
case CS_INIT:
switch(state) {
case CS_NEW:
case CS_INIT:
case CS_LOOPBACK:
case CS_TRANSMIT:
case CS_RING:
case CS_EXECUTE:
case CS_HANGUP:
case CS_DONE:
default:
break;
}
break;
*/
switch (last_state) {
case CS_NEW:
switch (state) {
default:
ok++;
break;
}
break;
case CS_INIT:
switch (state) {
case CS_LOOPBACK:
case CS_TRANSMIT:
case CS_RING:
case CS_EXECUTE:
case CS_HANGUP:
ok++;
default:
break;
}
break;
case CS_LOOPBACK:
switch (state) {
case CS_TRANSMIT:
case CS_RING:
case CS_EXECUTE:
case CS_HANGUP:
ok++;
default:
break;
}
break;
case CS_TRANSMIT:
switch (state) {
case CS_LOOPBACK:
case CS_RING:
case CS_EXECUTE:
case CS_HANGUP:
ok++;
default:
break;
}
break;
case CS_RING:
switch (state) {
case CS_LOOPBACK:
case CS_EXECUTE:
case CS_HANGUP:
case CS_TRANSMIT:
ok++;
default:
break;
}
break;
case CS_EXECUTE:
switch (state) {
case CS_LOOPBACK:
case CS_TRANSMIT:
case CS_RING:
case CS_HANGUP:
ok++;
default:
break;
}
break;
case CS_HANGUP:
case CS_DONE:
switch (state) {
case CS_DONE:
ok++;
default:
break;
}
break;
default:
break;
}
break;
*/
switch(last_state) {
case CS_NEW:
switch(state) {
default:
ok++;
break;
}
break;
case CS_INIT:
switch(state) {
case CS_LOOPBACK:
case CS_TRANSMIT:
case CS_RING:
case CS_EXECUTE:
case CS_HANGUP:
ok++;
default:
break;
}
break;
case CS_LOOPBACK:
switch(state) {
case CS_TRANSMIT:
case CS_RING:
case CS_EXECUTE:
case CS_HANGUP:
ok++;
default:
break;
}
break;
case CS_TRANSMIT:
switch(state) {
case CS_LOOPBACK:
case CS_RING:
case CS_EXECUTE:
case CS_HANGUP:
ok++;
default:
break;
}
break;
case CS_RING:
switch(state) {
case CS_LOOPBACK:
case CS_EXECUTE:
case CS_HANGUP:
case CS_TRANSMIT:
ok++;
default:
break;
}
break;
case CS_EXECUTE:
switch(state) {
case CS_LOOPBACK:
case CS_TRANSMIT:
case CS_RING:
case CS_HANGUP:
ok++;
default:
break;
}
break;
case CS_HANGUP:
switch(state) {
case CS_DONE:
ok++;
default:
break;
}
break;
default:
break;
break;
}
if (ok) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "%s State Change %s -> %s\n", channel->name, state_names[last_state], state_names[state]);
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "%s State Change %s -> %s\n", channel->name,
state_names[last_state], state_names[state]);
channel->state = state;
switch_core_session_signal_state_change(channel->session);
} else {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "%s Invalid State Change %s -> %s\n", channel->name, state_names[last_state], state_names[state]);
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "%s Invalid State Change %s -> %s\n", channel->name,
state_names[last_state], state_names[state]);
//we won't tolerate an invalid state change so we can make sure we are as robust as a nice cup of dark coffee!
if (channel->state < CS_HANGUP) {
@ -399,7 +402,7 @@ default:
SWITCH_DECLARE(void) switch_channel_event_set_data(switch_channel *channel, switch_event *event)
{
switch_caller_profile *caller_profile, *originator_caller_profile, *originatee_caller_profile;
switch_hash_index_t* hi;
switch_hash_index_t *hi;
void *val;
const void *var;
@ -407,12 +410,13 @@ SWITCH_DECLARE(void) switch_channel_event_set_data(switch_channel *channel, swit
originator_caller_profile = switch_channel_get_originator_caller_profile(channel);
originatee_caller_profile = switch_channel_get_originatee_caller_profile(channel);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Channel-State", (char *) switch_channel_state_name(channel->state));
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Channel-State",
(char *) switch_channel_state_name(channel->state));
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Channel-Name", switch_channel_get_name(channel));
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Unique-ID", switch_core_session_get_uuid(channel->session));
/* Index Caller's Profile */
/* Index Caller's Profile */
if (caller_profile) {
switch_caller_profile_event_set_data(caller_profile, "Caller", event);
}
@ -428,7 +432,8 @@ SWITCH_DECLARE(void) switch_channel_event_set_data(switch_channel *channel, swit
}
/* Index Variables */
for (hi = switch_hash_first(switch_core_session_get_pool(channel->session), channel->variables); hi; hi = switch_hash_next(hi)) {
for (hi = switch_hash_first(switch_core_session_get_pool(channel->session), channel->variables); hi;
hi = switch_hash_next(hi)) {
char buf[1024];
switch_event_subclass *subclass;
switch_hash_this(hi, &var, NULL, &val);
@ -453,13 +458,15 @@ SWITCH_DECLARE(switch_caller_profile *) switch_channel_get_caller_profile(switch
return channel->caller_profile;
}
SWITCH_DECLARE(void) switch_channel_set_originator_caller_profile(switch_channel *channel, switch_caller_profile *caller_profile)
SWITCH_DECLARE(void) switch_channel_set_originator_caller_profile(switch_channel *channel,
switch_caller_profile *caller_profile)
{
assert(channel != NULL);
channel->originator_caller_profile = caller_profile;
}
SWITCH_DECLARE(void) switch_channel_set_originatee_caller_profile(switch_channel *channel, switch_caller_profile *caller_profile)
SWITCH_DECLARE(void) switch_channel_set_originatee_caller_profile(switch_channel *channel,
switch_caller_profile *caller_profile)
{
assert(channel != NULL);
channel->originatee_caller_profile = caller_profile;
@ -477,7 +484,8 @@ SWITCH_DECLARE(switch_caller_profile *) switch_channel_get_originatee_caller_pro
return channel->originatee_caller_profile;
}
SWITCH_DECLARE(void) switch_channel_set_event_handlers(switch_channel *channel, const struct switch_event_handler_table *event_handlers)
SWITCH_DECLARE(void) switch_channel_set_event_handlers(switch_channel *channel,
const struct switch_event_handler_table *event_handlers)
{
assert(channel != NULL);
channel->event_handlers = event_handlers;
@ -489,7 +497,8 @@ SWITCH_DECLARE(const struct switch_event_handler_table *) switch_channel_get_eve
return channel->event_handlers;
}
SWITCH_DECLARE(void) switch_channel_set_caller_extension(switch_channel *channel, switch_caller_extension *caller_extension)
SWITCH_DECLARE(void) switch_channel_set_caller_extension(switch_channel *channel,
switch_caller_extension *caller_extension)
{
assert(channel != NULL);
channel->caller_extension = caller_extension;
@ -509,7 +518,7 @@ SWITCH_DECLARE(switch_status) switch_channel_hangup(switch_channel *channel)
assert(channel != NULL);
if (channel->state < CS_HANGUP) {
channel->state = CS_HANGUP;
switch_core_session_signal_state_change(channel->session);
switch_core_session_signal_state_change(channel->session);
}
return channel->state;
}

View File

@ -83,7 +83,7 @@ SWITCH_DECLARE(int) switch_config_next_pair(switch_config *cfg, char **var, char
*var = *val = NULL;
for(;;) {
for (;;) {
cfg->lineno++;
if (!fgets(cfg->buf, sizeof(cfg->buf), cfg->file)) {
@ -154,6 +154,3 @@ SWITCH_DECLARE(int) switch_config_next_pair(switch_config *cfg, char **var, char
return ret;
}

View File

@ -54,15 +54,10 @@ static int switch_console_process(char *cmd)
switch_console_printf(SWITCH_CHANNEL_CONSOLE,
"\n"
"Valid Commands:\n\n"
"version\n"
"help - umm yeah..\n"
"%sshutdown - stop the program\n\n",
perlhelp
);
"version\n" "help - umm yeah..\n" "%sshutdown - stop the program\n\n", perlhelp);
return 1;
}
#ifdef EMBED_PERL
if (!strncmp(cmd, "perl ", 5)) {
cmd += 5;
@ -71,7 +66,7 @@ static int switch_console_process(char *cmd)
return 1;
}
#endif
if ((arg = strchr(cmd, '\r')) || (arg=strchr(cmd, '\n'))) {
if ((arg = strchr(cmd, '\r')) || (arg = strchr(cmd, '\n'))) {
*arg = '\0';
arg = NULL;
}
@ -79,14 +74,16 @@ static int switch_console_process(char *cmd)
*arg++ = '\0';
}
if (switch_api_execute(cmd, arg, retbuf, sizeof(retbuf)) == SWITCH_STATUS_SUCCESS) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, "API CALL [%s(%s)] output:\n%s\n", cmd, arg ? arg : "", retbuf);
switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, "API CALL [%s(%s)] output:\n%s\n", cmd, arg ? arg : "",
retbuf);
} else {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Unknown Command: %s\n", cmd);
}
return 1;
}
SWITCH_DECLARE(void) switch_console_printf(switch_text_channel channel, char *file, const char *func, int line, char *fmt, ...)
SWITCH_DECLARE(void) switch_console_printf(switch_text_channel channel, char *file, const char *func, int line,
char *fmt, ...)
{
char *data;
int ret = 0;
@ -120,18 +117,18 @@ SWITCH_DECLARE(void) switch_console_printf(switch_text_channel channel, char *fi
switch_strftime(date, &retsize, sizeof(date), "%Y-%m-%d %T", &tm);
if (channel == SWITCH_CHANNEL_ID_CONSOLE) {
fprintf(handle, "[%d] %s %s:%d %s() %s", (int)getpid(), date, filep, line, func, data);
fprintf(handle, "[%d] %s %s:%d %s() %s", (int) getpid(), date, filep, line, func, data);
}
else if (channel == SWITCH_CHANNEL_ID_EVENT &&
switch_event_running() == SWITCH_STATUS_SUCCESS &&
switch_event_create(&event, SWITCH_EVENT_LOG) == SWITCH_STATUS_SUCCESS) {
else if (channel == SWITCH_CHANNEL_ID_EVENT &&
switch_event_running() == SWITCH_STATUS_SUCCESS &&
switch_event_create(&event, SWITCH_EVENT_LOG) == SWITCH_STATUS_SUCCESS) {
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Log-Data", "%s", data);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Log-File", "%s", filep);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Log-Function", "%s", func);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Log-Line", "%d", line);
switch_event_fire(&event);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Log-Data", "%s", data);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Log-File", "%s", filep);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Log-Function", "%s", func);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Log-Line", "%d", line);
switch_event_fire(&event);
}
free(data);
}
@ -161,14 +158,14 @@ SWITCH_DECLARE(void) switch_console_loop(void)
}
memset(&cmd, 0, sizeof(cmd));
for (x=0; sizeof(cmd) ;x++) {
for (x = 0; sizeof(cmd); x++) {
cmd[x] = getchar();
if (cmd[x] == '\n') {
cmd[x] = '\0';
break;
}
}
if(cmd[0]) {
if (cmd[0]) {
running = switch_console_process(cmd);
}
}

File diff suppressed because it is too large Load Diff

View File

@ -31,7 +31,7 @@
*/
#include <switch_event.h>
static switch_event_node *EVENT_NODES[SWITCH_EVENT_ALL+1] = {NULL};
static switch_event_node *EVENT_NODES[SWITCH_EVENT_ALL + 1] = { NULL };
static switch_mutex_t *BLOCK = NULL;
static switch_mutex_t *POOL_LOCK = NULL;
static switch_memory_pool *RUNTIME_POOL = NULL;
@ -59,10 +59,10 @@ static void *locked_alloc(size_t len)
void *mem;
switch_mutex_lock(POOL_LOCK);
/* <LOCKED> -----------------------------------------------*/
/* <LOCKED> ----------------------------------------------- */
mem = switch_core_alloc(THRUNTIME_POOL, len);
switch_mutex_unlock(POOL_LOCK);
/* </LOCKED> ----------------------------------------------*/
/* </LOCKED> ---------------------------------------------- */
return mem;
}
@ -72,13 +72,14 @@ static void *locked_dup(char *str)
char *dup;
switch_mutex_lock(POOL_LOCK);
/* <LOCKED> -----------------------------------------------*/
/* <LOCKED> ----------------------------------------------- */
dup = switch_core_strdup(THRUNTIME_POOL, str);
switch_mutex_unlock(POOL_LOCK);
/* </LOCKED> ----------------------------------------------*/
/* </LOCKED> ---------------------------------------------- */
return dup;
}
#define ALLOC(size) locked_alloc(size)
#define DUP(str) locked_dup(str)
#endif
@ -139,7 +140,7 @@ static int switch_events_match(switch_event *event, switch_event_node *node)
return match;
}
static void * SWITCH_THREAD_FUNC switch_event_thread(switch_thread *thread, void *obj)
static void *SWITCH_THREAD_FUNC switch_event_thread(switch_thread *thread, void *obj)
{
switch_event_node *node;
switch_event *out_event = NULL;
@ -149,11 +150,11 @@ static void * SWITCH_THREAD_FUNC switch_event_thread(switch_thread *thread, void
assert(POOL_LOCK != NULL);
assert(RUNTIME_POOL != NULL);
THREAD_RUNNING = 1;
while(THREAD_RUNNING == 1 || switch_queue_size(EVENT_QUEUE)) {
while (THREAD_RUNNING == 1 || switch_queue_size(EVENT_QUEUE)) {
#ifdef MALLOC_EVENTS
switch_mutex_lock(POOL_LOCK);
/* <LOCKED> -----------------------------------------------*/
/* <LOCKED> ----------------------------------------------- */
if (POOL_COUNT >= POOL_COUNT_MAX) {
if (THRUNTIME_POOL == APOOL) {
THRUNTIME_POOL = BPOOL;
@ -164,14 +165,14 @@ static void * SWITCH_THREAD_FUNC switch_event_thread(switch_thread *thread, void
POOL_COUNT = 0;
}
switch_mutex_unlock(POOL_LOCK);
/* </LOCKED> -----------------------------------------------*/
/* </LOCKED> ----------------------------------------------- */
#endif
while (switch_queue_trypop(EVENT_QUEUE, &pop) == SWITCH_STATUS_SUCCESS) {
out_event = pop;
for(e = out_event->event_id;; e = SWITCH_EVENT_ALL) {
for(node = EVENT_NODES[e]; node; node = node->next) {
for (e = out_event->event_id;; e = SWITCH_EVENT_ALL) {
for (node = EVENT_NODES[e]; node; node = node->next) {
if (switch_events_match(out_event, node)) {
out_event->bind_user_data = node->user_data;
node->callback(out_event);
@ -234,7 +235,7 @@ SWITCH_DECLARE(switch_status) switch_event_shutdown(void)
{
THREAD_RUNNING = -1;
while(THREAD_RUNNING) {
while (THREAD_RUNNING) {
switch_yield(1000);
}
return SWITCH_STATUS_SUCCESS;
@ -267,31 +268,26 @@ SWITCH_DECLARE(switch_status) switch_event_init(switch_memory_pool *pool)
switch_mutex_init(&BLOCK, SWITCH_MUTEX_NESTED, RUNTIME_POOL);
switch_mutex_init(&POOL_LOCK, SWITCH_MUTEX_NESTED, RUNTIME_POOL);
switch_core_hash_init(&CUSTOM_HASH, RUNTIME_POOL);
switch_thread_create(&thread,
thd_attr,
switch_event_thread,
NULL,
RUNTIME_POOL
);
switch_thread_create(&thread, thd_attr, switch_event_thread, NULL, RUNTIME_POOL);
while(!THREAD_RUNNING) {
while (!THREAD_RUNNING) {
switch_yield(1000);
}
return SWITCH_STATUS_SUCCESS;
}
SWITCH_DECLARE(switch_status) switch_event_create_subclass(switch_event **event, switch_event_t event_id, char *subclass_name)
SWITCH_DECLARE(switch_status) switch_event_create_subclass(switch_event **event, switch_event_t event_id,
char *subclass_name)
{
if (event_id != SWITCH_EVENT_CUSTOM && subclass_name) {
return SWITCH_STATUS_GENERR;
}
if(!(*event = ALLOC(sizeof(switch_event)))) {
if (!(*event = ALLOC(sizeof(switch_event)))) {
return SWITCH_STATUS_MEMERR;
}
#ifdef MALLOC_EVENTS
memset(*event, 0, sizeof(switch_event));
#endif
@ -309,7 +305,7 @@ SWITCH_DECLARE(char *) switch_event_get_header(switch_event *event, char *header
{
switch_event_header *hp;
if (header_name) {
for(hp = event->headers; hp; hp = hp->next) {
for (hp = event->headers; hp; hp = hp->next) {
if (!strcasecmp(hp->name, header_name)) {
return hp->value;
}
@ -318,7 +314,8 @@ SWITCH_DECLARE(char *) switch_event_get_header(switch_event *event, char *header
return NULL;
}
SWITCH_DECLARE(switch_status) switch_event_add_header(switch_event *event, switch_stack_t stack, char *header_name, char *fmt, ...)
SWITCH_DECLARE(switch_status) switch_event_add_header(switch_event *event, switch_stack_t stack, char *header_name,
char *fmt, ...)
{
int ret = 0;
char data[2048];
@ -459,7 +456,7 @@ SWITCH_DECLARE(switch_status) switch_event_serialize(switch_event *event, char *
}
for (hp = event->headers; hp; hp = hp->next) {
snprintf(buf+len, buflen-len, "%s: %s\n", hp->name, hp->value);
snprintf(buf + len, buflen - len, "%s: %s\n", hp->name, hp->value);
len = strlen(buf);
}
@ -471,14 +468,14 @@ SWITCH_DECLARE(switch_status) switch_event_serialize(switch_event *event, char *
}
if (body) {
int blen = (int)strlen(body);
int blen = (int) strlen(body);
if (blen) {
snprintf(buf+len, buflen-len, "Content-Length: %d\n\n%s", blen, body);
snprintf(buf + len, buflen - len, "Content-Length: %d\n\n%s", blen, body);
} else {
snprintf(buf+len, buflen-len, "\n");
snprintf(buf + len, buflen - len, "\n");
}
} else {
snprintf(buf+len, buflen-len, "\n");
snprintf(buf + len, buflen - len, "\n");
}
if (data) {
@ -489,7 +486,8 @@ SWITCH_DECLARE(switch_status) switch_event_serialize(switch_event *event, char *
}
SWITCH_DECLARE(switch_status) switch_event_fire_detailed(char *file, char *func, int line, switch_event **event, void *user_data)
SWITCH_DECLARE(switch_status) switch_event_fire_detailed(char *file, char *func, int line, switch_event **event,
void *user_data)
{
switch_time_exp_t tm;
@ -535,7 +533,8 @@ SWITCH_DECLARE(switch_status) switch_event_fire_detailed(char *file, char *func,
return SWITCH_STATUS_SUCCESS;
}
SWITCH_DECLARE(switch_status) switch_event_bind(char *id, switch_event_t event, char *subclass_name, switch_event_callback_t callback, void *user_data)
SWITCH_DECLARE(switch_status) switch_event_bind(char *id, switch_event_t event, char *subclass_name,
switch_event_callback_t callback, void *user_data)
{
switch_event_node *event_node;
switch_event_subclass *subclass = NULL;
@ -556,7 +555,7 @@ SWITCH_DECLARE(switch_status) switch_event_bind(char *id, switch_event_t event,
if (event <= SWITCH_EVENT_ALL && (event_node = switch_core_alloc(RUNTIME_POOL, sizeof(switch_event_node)))) {
switch_mutex_lock(BLOCK);
/* <LOCKED> -----------------------------------------------*/
/* <LOCKED> ----------------------------------------------- */
event_node->id = switch_core_strdup(RUNTIME_POOL, id);
event_node->event_id = event;
event_node->subclass = subclass;
@ -569,10 +568,9 @@ SWITCH_DECLARE(switch_status) switch_event_bind(char *id, switch_event_t event,
EVENT_NODES[event] = event_node;
switch_mutex_unlock(BLOCK);
/* </LOCKED> -----------------------------------------------*/
/* </LOCKED> ----------------------------------------------- */
return SWITCH_STATUS_SUCCESS;
}
return SWITCH_STATUS_MEMERR;
}

View File

@ -91,7 +91,8 @@ static void *switch_loadable_module_exec(switch_thread *thread, void *obj)
return NULL;
}
static switch_status switch_loadable_module_load_file(char *filename, switch_memory_pool *pool, switch_loadable_module **new_module)
static switch_status switch_loadable_module_load_file(char *filename, switch_memory_pool *pool,
switch_loadable_module **new_module)
{
switch_loadable_module *module = NULL;
apr_dso_handle_t *dso = NULL;
@ -129,7 +130,7 @@ static switch_status switch_loadable_module_load_file(char *filename, switch_mem
break;
}
if (! (module = switch_core_permenant_alloc( sizeof(switch_loadable_module) ))) {
if (!(module = switch_core_permenant_alloc(sizeof(switch_loadable_module)))) {
err = "Could not allocate memory\n";
break;
}
@ -192,7 +193,7 @@ SWITCH_DECLARE(switch_status) switch_loadable_module_init()
char *ptr;
apr_finfo_t finfo;
apr_dir_t *module_dir_handle;
apr_int32_t finfo_flags = APR_FINFO_DIRENT|APR_FINFO_TYPE|APR_FINFO_NAME;
apr_int32_t finfo_flags = APR_FINFO_DIRENT | APR_FINFO_TYPE | APR_FINFO_NAME;
switch_loadable_module *new_module;
#ifdef WIN32
const char *ext = ".dll";
@ -250,9 +251,7 @@ SWITCH_DECLARE(switch_status) switch_loadable_module_init()
const switch_endpoint_interface *ptr;
for (ptr = new_module->interface->endpoint_interface; ptr; ptr = ptr->next) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Adding Endpoint '%s'\n", ptr->interface_name);
switch_core_hash_insert(loadable_modules.endpoint_hash,
(char *) ptr->interface_name,
(void *) ptr);
switch_core_hash_insert(loadable_modules.endpoint_hash, (char *) ptr->interface_name, (void *) ptr);
}
}
@ -260,76 +259,64 @@ SWITCH_DECLARE(switch_status) switch_loadable_module_init()
const switch_codec_implementation *impl;
const switch_codec_interface *ptr;
for(ptr = new_module->interface->codec_interface; ptr; ptr = ptr->next) {
for(impl = ptr->implementations; impl ; impl = impl->next) {
for (ptr = new_module->interface->codec_interface; ptr; ptr = ptr->next) {
for (impl = ptr->implementations; impl; impl = impl->next) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE,
"Adding Codec '%s' (%s) %dkhz %dms\n",
ptr->iananame,
ptr->interface_name,
impl->samples_per_second,
impl->microseconds_per_frame / 1000);
"Adding Codec '%s' (%s) %dkhz %dms\n",
ptr->iananame,
ptr->interface_name,
impl->samples_per_second, impl->microseconds_per_frame / 1000);
}
switch_core_hash_insert(loadable_modules.codec_hash,
(char *) ptr->iananame,
(void *) ptr);
switch_core_hash_insert(loadable_modules.codec_hash, (char *) ptr->iananame, (void *) ptr);
}
}
if (new_module->interface->dialplan_interface) {
const switch_dialplan_interface *ptr;
for(ptr = new_module->interface->dialplan_interface; ptr; ptr = ptr->next) {
for (ptr = new_module->interface->dialplan_interface; ptr; ptr = ptr->next) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Adding Dialplan '%s'\n", ptr->interface_name);
switch_core_hash_insert(loadable_modules.dialplan_hash,
(char *) ptr->interface_name,
(void *) ptr);
switch_core_hash_insert(loadable_modules.dialplan_hash, (char *) ptr->interface_name, (void *) ptr);
}
}
if (new_module->interface->timer_interface) {
const switch_timer_interface *ptr;
for(ptr = new_module->interface->timer_interface; ptr; ptr = ptr->next) {
for (ptr = new_module->interface->timer_interface; ptr; ptr = ptr->next) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Adding Timer '%s'\n", ptr->interface_name);
switch_core_hash_insert(loadable_modules.timer_hash,
(char *) ptr->interface_name,
(void *) ptr);
switch_core_hash_insert(loadable_modules.timer_hash, (char *) ptr->interface_name, (void *) ptr);
}
}
if (new_module->interface->application_interface) {
const switch_application_interface *ptr;
for(ptr = new_module->interface->application_interface; ptr; ptr = ptr->next) {
for (ptr = new_module->interface->application_interface; ptr; ptr = ptr->next) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Adding Application '%s'\n", ptr->interface_name);
switch_core_hash_insert(loadable_modules.application_hash,
(char *) ptr->interface_name,
(void *) ptr);
(char *) ptr->interface_name, (void *) ptr);
}
}
if (new_module->interface->api_interface) {
const switch_api_interface *ptr;
for(ptr = new_module->interface->api_interface; ptr; ptr = ptr->next) {
for (ptr = new_module->interface->api_interface; ptr; ptr = ptr->next) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Adding API Function '%s'\n", ptr->interface_name);
switch_core_hash_insert(loadable_modules.api_hash,
(char *) ptr->interface_name,
(void *) ptr);
switch_core_hash_insert(loadable_modules.api_hash, (char *) ptr->interface_name, (void *) ptr);
}
}
if (new_module->interface->file_interface) {
const switch_file_interface *ptr;
for(ptr = new_module->interface->file_interface; ptr; ptr = ptr->next) {
for (ptr = new_module->interface->file_interface; ptr; ptr = ptr->next) {
int i;
for (i = 0 ; ptr->extens[i]; i++) {
for (i = 0; ptr->extens[i]; i++) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Adding File Format '%s'\n", ptr->extens[i]);
switch_core_hash_insert(loadable_modules.file_hash,
(char *) ptr->extens[i],
(void *) ptr);
switch_core_hash_insert(loadable_modules.file_hash, (char *) ptr->extens[i], (void *) ptr);
}
}
}
@ -344,7 +331,7 @@ SWITCH_DECLARE(switch_status) switch_loadable_module_init()
SWITCH_DECLARE(void) switch_loadable_module_shutdown(void)
{
switch_hash_index_t* hi;
switch_hash_index_t *hi;
void *val;
switch_loadable_module *module;
@ -397,9 +384,10 @@ SWITCH_DECLARE(switch_file_interface *) switch_loadable_module_get_file_interfac
return switch_core_hash_find(loadable_modules.file_hash, name);
}
SWITCH_DECLARE(int) switch_loadable_module_get_codecs(switch_memory_pool *pool, switch_codec_interface **array, int arraylen)
SWITCH_DECLARE(int) switch_loadable_module_get_codecs(switch_memory_pool *pool, switch_codec_interface **array,
int arraylen)
{
switch_hash_index_t* hi;
switch_hash_index_t *hi;
void *val;
int i = 0;
@ -415,12 +403,13 @@ SWITCH_DECLARE(int) switch_loadable_module_get_codecs(switch_memory_pool *pool,
}
SWITCH_DECLARE(int) switch_loadable_module_get_codecs_sorted(switch_memory_pool *pool, switch_codec_interface **array, int arraylen, char **prefs, int preflen)
SWITCH_DECLARE(int) switch_loadable_module_get_codecs_sorted(switch_memory_pool *pool, switch_codec_interface **array,
int arraylen, char **prefs, int preflen)
{
int x, i = 0;
switch_codec_interface *codec_interface;
for(x = 0; x < preflen; x++) {
for (x = 0; x < preflen; x++) {
if ((codec_interface = switch_loadable_module_get_codec_interface(prefs[x]))) {
array[i++] = codec_interface;
}

View File

@ -31,9 +31,7 @@
*/
#include <switch_mutex.h>
SWITCH_DECLARE(switch_status) switch_mutex_init(switch_mutex_t **lock,
switch_lock_flag flags,
switch_memory_pool *pool)
SWITCH_DECLARE(switch_status) switch_mutex_init(switch_mutex_t **lock, switch_lock_flag flags, switch_memory_pool *pool)
{
return (apr_thread_mutex_create(lock, flags, pool) == APR_SUCCESS) ? SWITCH_STATUS_SUCCESS : SWITCH_STATUS_GENERR;
@ -58,5 +56,3 @@ SWITCH_DECLARE(switch_status) switch_mutex_trylock(switch_mutex_t *lock)
{
return apr_thread_mutex_trylock(lock);
}

View File

@ -49,9 +49,7 @@
SWITCH_DECLARE(switch_status) switch_resample_create(switch_audio_resampler **new_resampler,
int from_rate,
size_t from_size,
int to_rate,
size_t to_size,
switch_memory_pool *pool)
int to_rate, size_t to_size, switch_memory_pool *pool)
{
switch_audio_resampler *resampler;
@ -61,10 +59,11 @@ SWITCH_DECLARE(switch_status) switch_resample_create(switch_audio_resampler **ne
resampler->from_rate = from_rate;
resampler->to_rate = to_rate;
resampler->factor = ((double)resampler->to_rate / (double)resampler->from_rate);
resampler->factor = ((double) resampler->to_rate / (double) resampler->from_rate);
resampler->resampler = resample_open(QUALITY, resampler->factor, resampler->factor);
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Activate Resampler %d->%d %f\n", resampler->from_rate, resampler->to_rate, resampler->factor);
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Activate Resampler %d->%d %f\n", resampler->from_rate,
resampler->to_rate, resampler->factor);
resampler->from_size = from_size;
resampler->from = (float *) switch_core_alloc(pool, resampler->from_size);
resampler->to_size = to_size;
@ -75,14 +74,16 @@ SWITCH_DECLARE(switch_status) switch_resample_create(switch_audio_resampler **ne
}
SWITCH_DECLARE(int) switch_resample_process(switch_audio_resampler *resampler, float *src, int srclen, float *dst, int dstlen, int last)
SWITCH_DECLARE(int) switch_resample_process(switch_audio_resampler *resampler, float *src, int srclen, float *dst,
int dstlen, int last)
{
int o=0, srcused=0, srcpos=0, out=0;
int o = 0, srcused = 0, srcpos = 0, out = 0;
for(;;) {
int srcBlock = MIN(srclen-srcpos, srclen);
int lastFlag = (last && (srcBlock == srclen-srcpos));
o = resample_process(resampler->resampler, resampler->factor, &src[srcpos], srcBlock, lastFlag, &srcused, &dst[out], dstlen-out);
for (;;) {
int srcBlock = MIN(srclen - srcpos, srclen);
int lastFlag = (last && (srcBlock == srclen - srcpos));
o = resample_process(resampler->resampler, resampler->factor, &src[srcpos], srcBlock, lastFlag, &srcused,
&dst[out], dstlen - out);
//printf("resampling %d/%d (%d) %d %f\n", srcpos, srclen, MIN(dstlen-out, dstlen), srcused, factor);
srcpos += srcused;
@ -106,15 +107,17 @@ SWITCH_DECLARE(size_t) switch_float_to_short(float *f, short *s, size_t len)
{
size_t i;
float ft;
for(i=0;i<len;i++) {
for (i = 0; i < len; i++) {
ft = f[i] * NORMFACT;
if(ft >= 0) {
s[i] = (short)(ft+0.5);
if (ft >= 0) {
s[i] = (short) (ft + 0.5);
} else {
s[i] = (short)(ft-0.5);
s[i] = (short) (ft - 0.5);
}
if ((float)s[i] > MAXSAMPLE) s[i] = (short)MAXSAMPLE;
if (s[i] < (short)-MAXSAMPLE) s[i] = (short)-MAXSAMPLE;
if ((float) s[i] > MAXSAMPLE)
s[i] = (short) MAXSAMPLE;
if (s[i] < (short) -MAXSAMPLE)
s[i] = (short) -MAXSAMPLE;
}
return len;
}
@ -124,16 +127,18 @@ SWITCH_DECLARE(int) switch_char_to_float(char *c, float *f, int len)
int i;
if (len % 2) {
return(-1);
return (-1);
}
for(i=1;i<len;i+=2) {
f[(int)(i/2)] = (float)(((c[i])*0x100) + c[i-1]);
f[(int)(i/2)] /= NORMFACT;
if (f[(int)(i/2)] > MAXSAMPLE) f[(int)(i/2)] = MAXSAMPLE;
if (f[(int)(i/2)] < -MAXSAMPLE) f[(int)(i/2)] = -MAXSAMPLE;
for (i = 1; i < len; i += 2) {
f[(int) (i / 2)] = (float) (((c[i]) * 0x100) + c[i - 1]);
f[(int) (i / 2)] /= NORMFACT;
if (f[(int) (i / 2)] > MAXSAMPLE)
f[(int) (i / 2)] = MAXSAMPLE;
if (f[(int) (i / 2)] < -MAXSAMPLE)
f[(int) (i / 2)] = -MAXSAMPLE;
}
return len/2;
return len / 2;
}
SWITCH_DECLARE(int) switch_float_to_char(float *f, char *c, int len)
@ -141,25 +146,25 @@ SWITCH_DECLARE(int) switch_float_to_char(float *f, char *c, int len)
int i;
float ft;
long l;
for(i=0;i<len;i++) {
for (i = 0; i < len; i++) {
ft = f[i] * NORMFACT;
if (ft >= 0) {
l = (long)(ft+0.5);
l = (long) (ft + 0.5);
} else {
l = (long)(ft-0.5);
l = (long) (ft - 0.5);
}
c[i*2] = (unsigned char)((l)&0xff);
c[i*2+1] = (unsigned char)(((l)>>8)&0xff);
c[i * 2] = (unsigned char) ((l) & 0xff);
c[i * 2 + 1] = (unsigned char) (((l) >> 8) & 0xff);
}
return len*2;
return len * 2;
}
SWITCH_DECLARE(int) switch_short_to_float(short *s, float *f, int len)
{
int i;
for(i=0;i<len;i++) {
f[i] = (float)(s[i]) / NORMFACT;
for (i = 0; i < len; i++) {
f[i] = (float) (s[i]) / NORMFACT;
//f[i] = (float) s[i];
}
return len;
@ -170,6 +175,6 @@ SWITCH_DECLARE(void) switch_swap_linear(int16_t *buf, int len)
{
int i;
for (i = 0; i < len; i++) {
buf[i] = ((buf[i] >> 8) & 0x00ff) | ((buf[i] << 8) & 0xff00);
buf[i] = ((buf[i] >> 8) & 0x00ff) | ((buf[i] << 8) & 0xff00);
}
}

View File

@ -73,16 +73,17 @@ SWITCH_DECLARE(char *) switch_cut_path(char *in)
char delims[] = "/\\";
char *i;
for(i = delims; *i; i++) {
for (i = delims; *i; i++) {
p = in;
while((p = strchr(p, *i))) {
while ((p = strchr(p, *i))) {
ret = ++p;
}
}
return ret;
}
SWITCH_DECLARE(switch_status) switch_socket_create_pollfd(switch_pollfd_t *poll, switch_socket_t *sock, unsigned int flags, switch_memory_pool *pool)
SWITCH_DECLARE(switch_status) switch_socket_create_pollfd(switch_pollfd_t *poll, switch_socket_t *sock,
unsigned int flags, switch_memory_pool *pool)
{
switch_pollset_t *pollset;
switch_status status;
@ -102,7 +103,7 @@ SWITCH_DECLARE(switch_status) switch_socket_create_pollfd(switch_pollfd_t *poll,
SWITCH_DECLARE(int) switch_socket_waitfor(switch_pollfd_t *poll, int ms)
{
switch_status status;
switch_status status;
int nsds = 0;
if ((status = switch_poll(poll, 1, &nsds, ms)) != SWITCH_STATUS_SUCCESS) {
@ -117,6 +118,6 @@ SWITCH_DECLARE(int) switch_socket_waitfor(switch_pollfd_t *poll, int ms)
void include_me(void)
{
apr_socket_shutdown(NULL, 0);
apr_socket_recvfrom(NULL , NULL, 0, NULL, NULL);
apr_socket_recvfrom(NULL, NULL, 0, NULL, NULL);
}
#endif