Merge branch 'master' of git://git.freeswitch.org/freeswitch

Conflicts:
	conf/autoload_configs/modules.conf.xml
	libs/freetdm/src/ftdm_sched.c
	libs/freetdm/src/ftmod/ftmod_libpri/ftmod_libpri.c
This commit is contained in:
Moises Silva committed 2010-11-09 12:59:48 -05:00
commit 8d66f38212
232 files changed
+57975 -3495

No files matched your search

File diff suppressed because it is too large. Load diff
@@ -42,8 +42,9 @@ typedef enum {
FTMOD_LIBPRI_OPT_SUGGEST_CHANNEL = (1 << 0),
FTMOD_LIBPRI_OPT_OMIT_DISPLAY_IE = (1 << 1),
FTMOD_LIBPRI_OPT_OMIT_REDIRECTING_NUMBER_IE = (1 << 2),
FTMOD_LIBPRI_OPT_MAX = (1 << 3)
FTMOD_LIBPRI_OPT_FACILITY_AOC = (1 << 3),
FTMOD_LIBPRI_OPT_MAX = (1 << 4)
} ftdm_isdn_opts_t;
typedef enum {
@@ -1,23 +1,23 @@
/*
* Copyright (c) 2009, Anthony Minessale II
* All rights reserved.
*
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
*
* * Neither the name of the original author; nor the names of any contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
*
*
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
@@ -35,8 +35,8 @@
#include "private/ftdm_core.h"
#include "lpwrap_pri.h"
#ifndef HAVE_GETTIMEOFDAY
#ifndef HAVE_GETTIMEOFDAY
#ifdef WIN32
#include <mmsystem.h>
@@ -92,7 +92,7 @@ static struct lpwrap_pri_event_list LPWRAP_PRI_EVENT_LIST[] = {
{8, LPWRAP_PRI_EVENT_ANSWER, "ANSWER"},
{9, LPWRAP_PRI_EVENT_HANGUP_ACK, "HANGUP_ACK"},
{10, LPWRAP_PRI_EVENT_RESTART_ACK, "RESTART_ACK"},
{11, LPWRAP_PRI_EVENT_FACNAME, "FACNAME"},
{11, LPWRAP_PRI_EVENT_FACILITY, "FACILITY"},
{12, LPWRAP_PRI_EVENT_INFO_RECEIVED, "INFO_RECEIVED"},
{13, LPWRAP_PRI_EVENT_PROCEEDING, "PROCEEDING"},
{14, LPWRAP_PRI_EVENT_SETUP_ACK, "SETUP_ACK"},
@@ -106,7 +106,10 @@ static struct lpwrap_pri_event_list LPWRAP_PRI_EVENT_LIST[] = {
#define LINE "--------------------------------------------------------------------------------"
const char *lpwrap_pri_event_str(lpwrap_pri_event_t event_id)
{
{
if (event_id < 0 || event_id >= LPWRAP_PRI_EVENT_MAX)
return "";
return LPWRAP_PRI_EVENT_LIST[event_id].name;
}
@@ -114,8 +117,8 @@ static int __pri_lpwrap_read(struct pri *pri, void *buf, int buflen)
{
struct lpwrap_pri *spri = (struct lpwrap_pri *) pri_get_userdata(pri);
ftdm_size_t len = buflen;
int res;
ftdm_status_t zst;
int res;
if ((zst = ftdm_channel_read(spri->dchan, buf, &len)) != FTDM_SUCCESS) {
if (zst == FTDM_FAIL) {
@@ -124,31 +127,31 @@ static int __pri_lpwrap_read(struct pri *pri, void *buf, int buflen)
} else {
ftdm_log(FTDM_LOG_CRIT, "span %d D-READ TIMEOUT\n", spri->span->span_id);
}
ftdm_clear_flag(spri, LPWRAP_PRI_READY);
return -1;
}
spri->errs = 0;
res = (int)len;
memset(&((unsigned char*)buf)[res],0,2);
res+=2;
memset(&((unsigned char*)buf)[res], 0, 2);
res += 2;
#ifdef IODEBUG
{
char bb[2048] = { 0 };
print_hex_bytes(buf, res - 2, bb, sizeof(bb));
ftdm_log(FTDM_LOG_DEBUG, "READ %d\n", res-2);
ftdm_log(FTDM_LOG_DEBUG, "READ %d\n", res - 2);
}
#endif
return res;
}
static int __pri_lpwrap_write(struct pri *pri, void *buf, int buflen)
{
struct lpwrap_pri *spri = (struct lpwrap_pri *) pri_get_userdata(pri);
ftdm_size_t len = buflen -2;
ftdm_size_t len = buflen - 2;
if (ftdm_channel_write(spri->dchan, buf, buflen, &len) != FTDM_SUCCESS) {
ftdm_log(FTDM_LOG_CRIT, "span %d D-WRITE FAIL! [%s]\n", spri->span->span_id, spri->dchan->last_error);
@@ -161,11 +164,10 @@ static int __pri_lpwrap_write(struct pri *pri, void *buf, int buflen)
char bb[2048] = { 0 };
print_hex_bytes(buf, buflen - 2, bb, sizeof(bb));
ftdm_log(FTDM_LOG_DEBUG, "WRITE %d\n", (int)buflen-2);
ftdm_log(FTDM_LOG_DEBUG, "WRITE %d\n", (int)buflen - 2);
}
#endif
return (int) buflen;
return (int)buflen;
}
int lpwrap_init_pri(struct lpwrap_pri *spri, ftdm_span_t *span, ftdm_channel_t *dchan, int swtype, int node, int debug)
@@ -173,21 +175,63 @@ int lpwrap_init_pri(struct lpwrap_pri *spri, ftdm_span_t *span, ftdm_channel_t *
int ret = -1;
memset(spri, 0, sizeof(struct lpwrap_pri));
spri->dchan = dchan;
spri->span = span;
spri->span = span;
if (spri->dchan && (spri->pri = pri_new_cb(spri->dchan->sockfd, node, swtype, __pri_lpwrap_read, __pri_lpwrap_write, spri))){
unsigned char buf[4] = { 0 };
size_t buflen = sizeof(buf), len = 0;
pri_set_debug(spri->pri, debug);
ret = 0;
ftdm_channel_write(spri->dchan, buf, buflen, &len);
} else {
fprintf(stderr, "Unable to create PRI\n");
if (!spri->dchan) {
ftdm_log(FTDM_LOG_ERROR, "No D-Channel available, unable to create PRI\n");
return ret;
}
if ((spri->pri = pri_new_cb(spri->dchan->sockfd, node, swtype, __pri_lpwrap_read, __pri_lpwrap_write, spri))) {
unsigned char buf[4] = { 0 };
size_t buflen = sizeof(buf), len = 0;
pri_set_debug(spri->pri, debug);
#ifdef HAVE_LIBPRI_AOC
pri_aoc_events_enable(spri->pri, 1);
#endif
ftdm_channel_write(spri->dchan, buf, buflen, &len);
ret = 0;
} else {
ftdm_log(FTDM_LOG_ERROR, "Unable to create PRI\n");
}
return ret;
}
int lpwrap_init_bri(struct lpwrap_pri *spri, ftdm_span_t *span, ftdm_channel_t *dchan, int swtype, int node, int ptp, int debug)
{
int ret = -1;
#ifdef HAVE_LIBPRI_BRI
memset(spri, 0, sizeof(struct lpwrap_pri));
spri->dchan = dchan;
spri->span = span;
if (!spri->dchan) {
ftdm_log(FTDM_LOG_ERROR, "No D-Channel available, unable to create BRI\n");
return ret;
}
if ((spri->pri = pri_new_bri_cb(spri->dchan->sockfd, ptp, node, swtype, __pri_lpwrap_read, __pri_lpwrap_write, spri))) {
unsigned char buf[4] = { 0 };
size_t buflen = sizeof(buf), len = 0;
pri_set_debug(spri->pri, debug);
#ifdef HAVE_LIBPRI_AOC
pri_aoc_events_enable(spri->pri, 1);
#endif
ftdm_channel_write(spri->dchan, buf, buflen, &len);
ret = 0;
} else {
ftdm_log(FTDM_LOG_ERROR, "Unable to create BRI\n");
}
#else
ftdm_log(FTDM_LOG_ERROR, "Installed libpri version (%s) has no BRI support\n",
pri_get_version());
#endif
return ret;
}
@@ -195,11 +239,11 @@ int lpwrap_init_pri(struct lpwrap_pri *spri, ftdm_span_t *span, ftdm_channel_t *
int lpwrap_one_loop(struct lpwrap_pri *spri)
{
fd_set rfds, efds;
struct timeval now = {0,0}, *next;
pri_event *event;
struct timeval now = {0,0}, *next = NULL;
pri_event *event = NULL;
event_handler handler;
int sel;
int sel;
if (spri->on_loop) {
if ((sel = spri->on_loop(spri)) < 0) {
return sel;
@@ -231,9 +275,6 @@ int lpwrap_one_loop(struct lpwrap_pri *spri)
now.tv_usec = 100000;
sel = select(pri_fd(spri->pri) + 1, &rfds, NULL, &efds, &now);
event = NULL;
if (!sel) {
if ((next = pri_schedule_next(spri->pri))) {
gettimeofday(&now, NULL);
@@ -248,46 +289,40 @@ int lpwrap_one_loop(struct lpwrap_pri *spri)
if (event) {
/* 0 is catchall event handler */
if ((handler = spri->eventmap[event->e] ? spri->eventmap[event->e] : spri->eventmap[0] ? spri->eventmap[0] : NULL)) {
if (event->e < 0 || event->e >= LPWRAP_PRI_EVENT_MAX) {
handler = spri->eventmap[0];
} else if (spri->eventmap[event->e]) {
handler = spri->eventmap[event->e];
} else {
handler = spri->eventmap[0];
}
if (handler) {
handler(spri, event->e, event);
} else {
ftdm_log(FTDM_LOG_CRIT, "No event handler found for event %d.\n", event->e);
}
}
return sel;
if ((handler = spri->eventmap[LPWRAP_PRI_EVENT_IO_FAIL] ? spri->eventmap[LPWRAP_PRI_EVENT_IO_FAIL] : spri->eventmap[0] ? spri->eventmap[0] : NULL)) {
handler(spri, LPWRAP_PRI_EVENT_IO_FAIL, NULL);
}
return -1;
}
int lpwrap_run_pri(struct lpwrap_pri *spri)
{
int ret = 0;
for (;;){
ret = lpwrap_one_loop(spri);
if (ret < 0) {
for (;;) {
if ((ret = lpwrap_one_loop(spri)) < 0) {
#ifndef WIN32 //This needs to be adressed fror WIN32 still
if (errno == EINTR){
/* Igonore an interrupted system call */
continue;
}
#endif
#endif
ftdm_log(FTDM_LOG_CRIT, "Error = %i [%s]\n", ret, strerror(errno));
break;
}
}
return ret;
}
/* For Emacs:
@@ -300,4 +335,3 @@ int lpwrap_run_pri(struct lpwrap_pri *spri)
* For VIM:
* vim:set softtabstop=4 shiftwidth=4 tabstop=4:
*/
@@ -51,7 +51,11 @@ typedef enum {
LPWRAP_PRI_EVENT_ANSWER = PRI_EVENT_ANSWER,
LPWRAP_PRI_EVENT_HANGUP_ACK = PRI_EVENT_HANGUP_ACK,
LPWRAP_PRI_EVENT_RESTART_ACK = PRI_EVENT_RESTART_ACK,
LPWRAP_PRI_EVENT_FACNAME = PRI_EVENT_FACNAME,
#ifdef PRI_EVENT_FACILITY
LPWRAP_PRI_EVENT_FACILITY = PRI_EVENT_FACILITY,
#else
LPWRAP_PRI_EVENT_FACILITY = PRI_EVENT_FACNAME,
#endif
LPWRAP_PRI_EVENT_INFO_RECEIVED = PRI_EVENT_INFO_RECEIVED,
LPWRAP_PRI_EVENT_PROCEEDING = PRI_EVENT_PROCEEDING,
LPWRAP_PRI_EVENT_SETUP_ACK = PRI_EVENT_SETUP_ACK,
@@ -121,6 +125,8 @@ struct lpwrap_pri_event_list {
const char *lpwrap_pri_event_str(lpwrap_pri_event_t event_id);
int lpwrap_one_loop(struct lpwrap_pri *spri);
int lpwrap_init_pri(struct lpwrap_pri *spri, ftdm_span_t *span, ftdm_channel_t *dchan, int swtype, int node, int debug);
int lpwrap_init_bri(struct lpwrap_pri *spri, ftdm_span_t *span, ftdm_channel_t *dchan, int swtype, int node, int ptp, int debug);
int lpwrap_run_pri(struct lpwrap_pri *spri);
#define lpwrap_run_bri(x) lpwrap_run_pri(x)
#endif