$(SRC)/hashtable.c \
$(SRC)/hashtable_itr.c \
$(SRC)/zap_io.c \
-$(SRC)/zap_isdn.c \
-$(SRC)/zap_analog.c \
$(SRC)/zap_config.c \
$(SRC)/zap_callerid.c \
$(SRC)/fsk.c \
$(SRC)/libteletone_generate.c \
$(SRC)/zap_buffer.c \
$(SRC)/zap_threadmutex.c \
-$(SRC)/zap_dso.c \
+$(SRC)/zap_dso.c
+
+BOOST_SOURCES=\
+$(SRC)/ozmod/ozmod_ss7_boost/ss7_boost_client.c \
+$(SRC)/ozmod/ozmod_ss7_boost/zap_ss7_boost.c
+
+
+ISDN_SOURCES=\
$(SRC)/isdn/EuroISDNStateNT.c \
$(SRC)/isdn/EuroISDNStateTE.c \
$(SRC)/isdn/mfifo.c \
$(SRC)/isdn/5ESSmes.c \
$(SRC)/isdn/5ESSStateNT.c \
$(SRC)/isdn/5ESSStateTE.c \
-$(SRC)/isdn/Q932mes.c \
-$(SRC)/zap_zt.c \
-$(SRC)/zap_wanpipe.c \
-$(SRC)/ss7_boost_client.c \
-$(SRC)/zap_ss7_boost.c
+$(SRC)/isdn/Q932mes.c
+
OBJS=\
$(SRC)/hashtable.o \
$(SRC)/hashtable_itr.o \
$(SRC)/zap_io.o \
-$(SRC)/zap_isdn.o \
-$(SRC)/zap_analog.o \
$(SRC)/zap_config.o \
$(SRC)/zap_callerid.o \
$(SRC)/fsk.o \
$(SRC)/libteletone_generate.o \
$(SRC)/zap_buffer.o \
$(SRC)/zap_threadmutex.o \
-$(SRC)/zap_dso.o \
+$(SRC)/zap_dso.o
+
+BOOST_OBJS=\
+$(SRC)/ozmod/ozmod_ss7_boost/ss7_boost_client.o
+
+
+ISDN_OBJS=\
$(SRC)/isdn/EuroISDNStateNT.o \
$(SRC)/isdn/EuroISDNStateTE.o \
$(SRC)/isdn/mfifo.o \
$(SRC)/isdn/5ESSmes.o \
$(SRC)/isdn/5ESSStateNT.o \
$(SRC)/isdn/5ESSStateTE.o \
-$(SRC)/isdn/Q932mes.o \
-$(SRC)/zap_zt.o \
-$(SRC)/zap_wanpipe.o \
-$(SRC)/ss7_boost_client.o \
-$(SRC)/zap_ss7_boost.o
+$(SRC)/isdn/Q932mes.o
+
HEADERS= $(SRC)/include/fsk.h \
$(SRC)/include/g711.h \
$(SRC)/include/openzap.h \
$(SRC)/include/sangoma_tdm_api.h \
$(SRC)/include/uart.h \
-$(SRC)/include/wanpipe_tdm_api_iface.h \
-$(SRC)/include/zap_analog.h \
$(SRC)/include/zap_buffer.h \
$(SRC)/include/zap_config.h \
-$(SRC)/include/zap_isdn.h \
-$(SRC)/include/zap_skel.h \
$(SRC)/include/zap_threadmutex.h \
$(SRC)/include/zap_dso.h \
-$(SRC)/include/zap_types.h \
-$(SRC)/include/zap_wanpipe.h \
-$(SRC)/include/zap_ss7_boost.h \
-$(SRC)/include/zap_zt.h \
+$(SRC)/include/zap_types.h
+
+
+ISDN_HEADERS=\
$(SRC)/isdn/include/mfifo.h \
$(SRC)/isdn/include/national.h \
$(SRC)/isdn/include/DMS.h \
$(SRC)/isdn/include/Q931ie.h \
$(SRC)/isdn/include/Q932.h
+
PWD=$(shell pwd)
-INCS=-I$(PWD)/$(SRC)/include -I$(PWD)/$(SRC)/isdn/include
-CFLAGS+= $(INCS) $(ZAP_CFLAGS)
-MYLIB=libopenzap.a
+INCS=-I$(PWD)/$(SRC)/include -I$(PWD)/$(SRC)/isdn/include -I$(PWD)/$(SRC)/ozmod/ozmod_ss7_boost
+CFLAGS+= $(INCS) $(ZAP_CFLAGS) -DZAP_CONFIG_DIR=\"@prefix@/conf\" -DZAP_MOD_DIR=\"@prefix@/mod\"
+MYLIB=libopenzap.so
LIBPRIA=libpri.a
LIBPRI=./libpri
TMP=-I$(LIBPRI) -I$(SRC)/include -I./src -w
+PREFIX=@prefix@
PIKA_DIR=$(shell ls -d /usr/include/pika 2>/dev/null)
PIKA_LIB=$(shell ls /usr/lib/libpikahmpapi.so 2>/dev/null)
-ifneq ($(PIKA_DIR),)
-ifneq ($(PIKA_LIB),)
-OBJS += $(SRC)/zap_pika.o
-CFLAGS += -DZAP_PIKA_SUPPORT -I$(PIKA_DIR)
-ADD_OBJS = $(PIKA_LIB)
-endif
-endif
+#ifneq ($(PIKA_DIR),)
+#ifneq ($(PIKA_LIB),)
+#OBJS += $(SRC)/zap_pika.o
+#CFLAGS += -DZAP_PIKA_SUPPORT -I$(PIKA_DIR)
+#ADD_OBJS = $(PIKA_LIB)
+#endif
+#endif
-all: $(MYLIB)
+all: $(MYLIB) analogmod isdnmod boostmod ztmod wpmod
$(MYLIB): $(OBJS) $(HEADERS) $(SOURCES)
- ar rcs $(MYLIB) $(OBJS) $(ADD_OBJS)
- ranlib $(MYLIB)
+ #ar rcs $(MYLIB) $(OBJS) $(ADD_OBJS)
+ #ranlib $(MYLIB)
+ $(CC) -shared -Wl,-x -o $(MYLIB) $(OBJS) $(ADD_OBJS) -ldl
testapp: $(SRC)/testapp.c $(MYLIB)
$(CC) $(INCS) -L. $(SRC)/testapp.c -o testapp -lopenzap -lm -lpthread
mod_openzap-clean:
@if [ -f mod_openzap/mod_openzap.so ] ; then cd mod_openzap && make clean ; fi
-clean: mod_openzap-clean
- rm -f $(SRC)/*.o $(SRC)/isdn/*.o $(MYLIB) *~ \#* testapp testcid testtones detect_tones detect_dtmf priserver testisdn testboost testanalog
+clean:
+ rm -f $(SRC)/*.o $(SRC)/isdn/*.o $(MYLIB) *~ \#* testapp testcid testtones detect_tones detect_dtmf priserver testisdn testboost testanalog src/ozmod/*/*.o src/ozmod/*/*.so src/ozmod/*/*.dylib src/ozmod/*/*.dll
@if [ -f $(LIBPRI)/$(LIBPRIA) ] ; then cd $(LIBPRI) && make clean ; fi
+
+install: all
+ @mkdir -p $(DESTDIR)$(PREFIX)
+ @[ -d "$(DESTDIR)$(PREFIX)/conf" ] || ( mkdir -p $(DESTDIR)$(PREFIX)/conf)
+ @[ -f "$(DESTDIR)$(PREFIX)/conf/openzap.conf" ] || ( cp conf/*.conf $(DESTDIR)$(PREFIX)/conf)
+ @mkdir -p $(DESTDIR)$(PREFIX)/lib
+ @[ ! -f $(MYLIB) ] || cp -f $(MYLIB) $(DESTDIR)$(PREFIX)/lib
+ @mkdir -p $(DESTDIR)$(PREFIX)/mod
+ @[ ! -f ozmod_* ] || cp -f ozmod_* $(DESTDIR)$(PREFIX)/mod
+ @cp -f src/ozmod/*/*.so $(DESTDIR)$(PREFIX)/mod
+ @echo OpenZAP Installed
+
+uninstall:
+ @rm -fr $(DESTDIR)$(PREFIX)
+
+$(SRC)/ozmod/ozmod_skel/ozmod_skel.so:
+ $(CC) $(INCS) $(ZAP_CFLAGS) -L. $(SRC)/ozmod/ozmod_skel/ozmod_skel.c -o $(SRC)/ozmod/ozmod_skel/ozmod_skel.so -shared -Wl,-x -lm -lpthread -ldl -Wl,--rpath -Wl,$(PREFIX)/lib
+skelmod: $(SRC)/ozmod/ozmod_skel/ozmod_skel.so
+
+
+$(SRC)/ozmod/ozmod_zt/ozmod_zt.so:
+ $(CC) $(INCS) $(ZAP_CFLAGS) -L. $(SRC)/ozmod/ozmod_zt/ozmod_zt.c -o $(SRC)/ozmod/ozmod_zt/ozmod_zt.so -shared -Wl,-x -lm -lpthread -ldl $(MYLIB) -Wl,--rpath -Wl,$(PREFIX)/lib
+ztmod: $(SRC)/ozmod/ozmod_zt/ozmod_zt.so
+
+$(SRC)/ozmod/ozmod_wanpipe/ozmod_wanpipe.so:
+ $(CC) $(INCS) $(ZAP_CFLAGS) -L. $(SRC)/ozmod/ozmod_wanpipe/ozmod_wanpipe.c -o $(SRC)/ozmod/ozmod_wanpipe/ozmod_wanpipe.so -shared -Wl,-x -lm -lpthread -ldl $(MYLIB) -Wl,--rpath -Wl,$(PREFIX)/lib
+wpmod: $(SRC)/ozmod/ozmod_wanpipe/ozmod_wanpipe.so
+
+$(SRC)/ozmod/ozmod_pika/ozmod_pika.so:
+ $(CC) -I$(PIKA_DIR) $(INCS) $(ZAP_CFLAGS) -L. $(SRC)/ozmod/ozmod_pika/ozmod_pika.c -o $(SRC)/ozmod/ozmod_pika/ozmod_pika.so -shared -Wl,-x -lm -lpthread -ldl $(MYLIB) $(PIKA_LIB) -Wl,--rpath -Wl,$(PREFIX)/lib
+
+pikamod: $(SRC)/ozmod/ozmod_pika/ozmod_pika.so
+
+$(ISDN_OBJS): $(ISDN_HEADERS) $(ISDN_SOURCES) $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.c
+
+$(SRC)/ozmod/ozmod_isdn/ozmod_isdn.so: $(MYLIB) $(ISDN_OBJS)
+ $(CC) -I$(SRC)/isdn/include/ $(INCS) $(ZAP_CFLAGS) -L. $(ISDN_OBJS) $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.c -o $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.so -shared -Wl,-x -lm -lpthread -ldl $(MYLIB) -Wl,--rpath -Wl,$(PREFIX)/lib
+isdnmod: $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.so
+
+$(SRC)/ozmod/ozmod_analog/ozmod_analog.so: $(MYLIB) $(ANALOG_OBJS)
+ $(CC) -I$(SRC)/analog/include/ $(INCS) $(ZAP_CFLAGS) -L. $(SRC)/ozmod/ozmod_analog/ozmod_analog.c -o $(SRC)/ozmod/ozmod_analog/ozmod_analog.so -shared -Wl,-x -lm -lpthread -ldl $(MYLIB) -Wl,--rpath -Wl,$(PREFIX)/lib
+analogmod: $(SRC)/ozmod/ozmod_analog/ozmod_analog.so
+
+$(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.so: $(MYLIB) $(BOOST_OBJS)
+ $(CC) -I/ozmod/ozmod_ss7_boost $(INCS) $(ZAP_CFLAGS) -L. $(BOOST_OBJS) $(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c -o $(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.so -shared -Wl,-x -lm -lpthread -ldl $(MYLIB) -Wl,--rpath -Wl,$(PREFIX)/lib
+boostmod: $(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.so
+
+
--- /dev/null
+[modules]
+;load => ozmod_skel
+load => ozmod_zt
+load => ozmod_wanpipe
+;load => ozmod_pika
+load => ozmod_isdn
+load => ozmod_analog
+;load => ozmod_ss7_boost
+
+
+
AC_PROG_MAKE_SET
AC_PROG_RANLIB
+
+AC_PREFIX_DEFAULT(/usr/local/openzap)
+
# Check for com;iler type
AC_DEFUN([AX_COMPILER_VENDOR],
[
BASE=../../..
OZ_DIR=..
VERBOSE=1
-OZA=$(OZ_DIR)/libopenzap.a
+OZSO=$(OZ_DIR)/libopenzap.so
LOCAL_CFLAGS=-I$(OZ_DIR)/src/include -I$(OZ_DIR)/src/isdn/include
-LOCAL_LIBADD=$(OZA)
+LOCAL_LDFLAGS=-L$(OZ_DIR) -lopenzap
include $(BASE)/build/modmake.rules
-local_depend: $(OZA)
+local_depend: $(OZSO)
-$(OZA): $(OZ_DIR)/.update
- cd $(OZ_DIR) && $(MAKE) ZAP_MODS="wanpipe zt" ZAP_CFLAGS="$(ALL_CXXFLAGS)"
+$(OZSO): $(OZ_DIR)/.update
+ cd $(OZ_DIR) && $(MAKE) ZAP_CFLAGS="$(ALL_CXXFLAGS)"
+
+local_install:
+ cd $(OZ_DIR) && $(MAKE) install ZAP_CFLAGS="$(ALL_CXXFLAGS)"
+ [ ! -f $(DESTDIR)$(PREFIX)/conf/autoload_configs/openzap.conf.xml ] || cp -f $(OZ_DIR)/conf/openzap.conf.xml $(DESTDIR)$(PREFIX)/conf/autoload_configs
+
+local_clean:
+ cd $(OZ_DIR) && $(MAKE) clean
*/
#include <switch.h>
#include "openzap.h"
-#include "zap_analog.h"
-#include "zap_isdn.h"
-#include "zap_ss7_boost.h"
#ifndef __FUNCTION__
#define __FUNCTION__ __SWITCH_FUNC__
continue;
}
- if (zap_analog_configure_span(span, tonegroup, to, max, on_analog_signal) != ZAP_SUCCESS) {
+ if (zap_configure_span("analog", span, on_analog_signal,
+ "tonemap", tonegroup,
+ "digit_timeout", &to,
+ "max_dialstr", &max
+ ) != ZAP_SUCCESS) {
zap_log(ZAP_LOG_ERROR, "Error starting OpenZAP span %d\n", span_id);
continue;
}
switch_set_string(SPAN_CONFIG[span->span_id].hold_music, hold_music);
}
switch_copy_string(SPAN_CONFIG[span->span_id].type, "analog", sizeof(SPAN_CONFIG[span->span_id].type));
- zap_analog_start(span);
+ zap_span_start(span);
}
}
char *id = (char *) switch_xml_attr_soft(myspan, "id");
char *context = "default";
char *dialplan = "XML";
- Q921NetUser_t mode = Q931_TE;
- Q931Dialect_t dialect = Q931_Dialect_National;
+ //Q921NetUser_t mode = Q931_TE;
+ //Q931Dialect_t dialect = Q931_Dialect_National;
+ char *mode = NULL;
+ char *dialect = NULL;
uint32_t span_id = 0;
zap_span_t *span = NULL;
char *tonegroup = NULL;
- zap_isdn_opts_t opts = ZAP_ISDN_OPT_NONE;
+ uint32_t opts = 0;
for (param = switch_xml_child(myspan, "param"); param; param = param->next) {
char *var = (char *) switch_xml_attr_soft(param, "name");
if (!strcasecmp(var, "tonegroup")) {
tonegroup = val;
} else if (!strcasecmp(var, "mode")) {
- mode = strcasecmp(val, "net") ? Q931_TE : Q931_NT;
+ mode = val;
} else if (!strcasecmp(var, "dialect")) {
- dialect = q931_str2Q931Dialect_type(val);
- if (dialect == Q931_Dialect_Count) {
- dialect = Q931_Dialect_National;
- }
+ dialect = val;
} else if (!strcasecmp(var, "context")) {
context = val;
} else if (!strcasecmp(var, "suggest-channel") && switch_true(val)) {
- opts |= ZAP_ISDN_OPT_SUGGEST_CHANNEL;
+ opts |= 1;
} else if (!strcasecmp(var, "dialplan")) {
dialplan = val;
}
zap_log(ZAP_LOG_ERROR, "Error finding OpenZAP span %d\n", span_id);
continue;
}
-
- if (zap_isdn_configure_span(span, mode, dialect, opts, on_clear_channel_signal) != ZAP_SUCCESS) {
+
+ if (zap_configure_span("isdn", span, on_clear_channel_signal,
+ "mode", mode,
+ "dialect", dialect
+ ) != ZAP_SUCCESS) {
zap_log(ZAP_LOG_ERROR, "Error starting OpenZAP span %d mode: %d dialect: %d error: %s\n", span_id, mode, dialect, span->last_error);
continue;
}
switch_copy_string(SPAN_CONFIG[span->span_id].dialplan, dialplan, sizeof(SPAN_CONFIG[span->span_id].dialplan));
switch_copy_string(SPAN_CONFIG[span->span_id].type, "isdn", sizeof(SPAN_CONFIG[span->span_id].type));
- zap_isdn_start(span);
+ zap_span_start(span);
}
}
continue;
}
- if (zap_ss7_boost_configure_span(span, local_ip, local_port, remote_ip, remote_port, on_clear_channel_signal) != ZAP_SUCCESS) {
+ if (zap_configure_span("ss7_boost", span, on_clear_channel_signal,
+ "local_ip", local_ip,
+ "local_port", &local_port,
+ "remote_ip", remote_ip,
+ "remote_port", &remote_port
+ ) != ZAP_SUCCESS) {
zap_log(ZAP_LOG_ERROR, "Error starting OpenZAP span %d error: %s\n", span_id, span->last_error);
continue;
}
switch_copy_string(SPAN_CONFIG[span->span_id].context, context, sizeof(SPAN_CONFIG[span->span_id].context));
switch_copy_string(SPAN_CONFIG[span->span_id].dialplan, dialplan, sizeof(SPAN_CONFIG[span->span_id].dialplan));
- zap_ss7_boost_start(span);
+ zap_span_start(span);
switch_copy_string(SPAN_CONFIG[span->span_id].type, "ss7 (boost)", sizeof(SPAN_CONFIG[span->span_id].type));
}
}
free(h);
}
+struct hashtable_iterator *hashtable_next(struct hashtable_iterator *i)
+{
+
+ if (i->e) {
+ if ((i->e = i->e->next)) {
+ return i;
+ } else {
+ i->pos++;
+ }
+ }
+
+ while(i->pos < i->h->tablelength && !i->h->table[i->pos]) {
+ i->pos++;
+ }
+
+ if (i->pos >= i->h->tablelength) {
+ return NULL;
+ }
+
+ if ((i->e = i->h->table[i->pos])) {
+ return i;
+ }
+
+ return NULL;
+}
+
+struct hashtable_iterator *hashtable_first(struct hashtable *h)
+{
+ h->iterator.pos = 0;
+ h->iterator.e = NULL;
+ h->iterator.h = h;
+ return hashtable_next(&h->iterator);
+}
+
+
+
+void hashtable_this(struct hashtable_iterator *i, const void **key, int *klen, void **val)
+{
+ if (i->e) {
+ if (key) {
+ *key = i->e->k;
+ }
+ if (klen) {
+ *klen = strlen(i->e->k);
+ }
+ if (val) {
+ *val = i->e->v;
+ }
+ } else {
+ if (key) {
+ *key = NULL;
+ }
+ if (klen) {
+ *klen = 0;
+ }
+ if (val) {
+ *val = NULL;
+ }
+ }
+}
+
+
/*
* Copyright (c) 2002, Christopher Clark
* All rights reserved.
#endif
struct hashtable;
+struct hashtable_iterator;
/* Example of use:
*
void
hashtable_destroy(struct hashtable *h, int free_keys, int free_values);
+struct hashtable_iterator *hashtable_first(struct hashtable *h);
+struct hashtable_iterator *hashtable_next(struct hashtable_iterator *i);
+void hashtable_this(struct hashtable_iterator *i, const void **key, int *klen, void **val);
+
#endif /* __HASHTABLE_CWC22_H__ */
/*
/*****************************************************************************/
+
struct entry
{
void *k, *v;
struct entry *next;
};
+struct hashtable_iterator {
+ int pos;
+ struct entry *e;
+ struct hashtable *h;
+};
+
struct hashtable {
unsigned int tablelength;
struct entry **table;
unsigned int primeindex;
unsigned int (*hashfn) (void *k);
int (*eqfn) (void *k1, void *k2);
+ struct hashtable_iterator iterator;
};
/*****************************************************************************/
zap_channel_t channels[ZAP_MAX_CHANNELS_SPAN];
zio_channel_outgoing_call_t outgoing_call;
zio_channel_request_t channel_request;
+ zap_span_start_t start;
void *mod_data;
char *type;
int suggest_chan_id;
uint32_t zap_running(void);
zap_status_t zap_channel_complete_state(zap_channel_t *zchan);
zap_status_t zap_channel_init(zap_channel_t *zchan);
+int zap_load_modules(void);
+zap_status_t zap_unload_modules(void);
+zap_status_t zap_configure_span(const char *type, zap_span_t *span, zio_signal_cb_t sig_cb, ...);
+zap_status_t zap_span_start(zap_span_t *span);
ZIO_CODEC_FUNCTION(zio_slin2ulaw);
ZIO_CODEC_FUNCTION(zio_ulaw2slin);
typedef void * zap_dso_lib_t;
void zap_dso_destroy(zap_dso_lib_t *lib);
-zap_dso_lib_t zap_dso_open(const char *path, const char **err);
-zap_func_ptr_t zap_dso_func_sym(zap_dso_lib_t lib, const char *sym, const char **err);
+zap_dso_lib_t zap_dso_open(const char *path, char **err);
+void *zap_dso_func_sym(zap_dso_lib_t lib, const char *sym, char **err);
#endif
+++ /dev/null
-/*
- * Copyright (c) 2007, 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
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
- * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef ZAP_SKEL_H
-#define ZAP_SKEL_H
-#include "openzap.h"
-
-zap_status_t skel_init(zap_software_interface_t **zint);
-zap_status_t skel_destroy(void);
-
-#endif
-
-/* 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 expandtab:
- */
#include <stdint.h>
#include <sys/types.h>
#include <sys/ioctl.h>
+#include <stdarg.h>
typedef int zap_socket_t;
typedef ssize_t zap_ssize_t;
typedef int zap_filehandle_t;
typedef struct zap_sigmsg zap_sigmsg_t;
typedef struct zap_span zap_span_t;
typedef struct zap_caller_data zap_caller_data_t;
+typedef struct zap_io_interface zap_io_interface_t;
#define ZIO_CHANNEL_REQUEST_ARGS (zap_span_t *span, uint32_t chan_id, zap_direction_t direction, zap_caller_data_t *caller_data, zap_channel_t **zchan)
#define ZIO_CHANNEL_OUTGOING_CALL_ARGS (zap_channel_t *zchan)
#define ZIO_GET_ALARMS_ARGS (zap_channel_t *zchan)
#define ZIO_READ_ARGS (zap_channel_t *zchan, void *data, zap_size_t *datalen)
#define ZIO_WRITE_ARGS (zap_channel_t *zchan, void *data, zap_size_t *datalen)
+#define ZIO_IO_LOAD_ARGS (zap_io_interface_t **zio)
+#define ZIO_IO_UNLOAD_ARGS (void)
+#define ZIO_SIG_LOAD_ARGS (void)
+#define ZIO_SIG_CONFIGURE_ARGS (zap_span_t *span, zio_signal_cb_t sig_cb, va_list ap)
+#define ZIO_SIG_UNLOAD_ARGS (void)
typedef zap_status_t (*zio_channel_request_t) ZIO_CHANNEL_REQUEST_ARGS ;
typedef zap_status_t (*zio_channel_outgoing_call_t) ZIO_CHANNEL_OUTGOING_CALL_ARGS ;
typedef zap_status_t (*zio_wait_t) ZIO_WAIT_ARGS ;
typedef zap_status_t (*zio_read_t) ZIO_READ_ARGS ;
typedef zap_status_t (*zio_write_t) ZIO_WRITE_ARGS ;
+typedef zap_status_t (*zio_io_load_t) ZIO_IO_LOAD_ARGS ;
+typedef zap_status_t (*zio_sig_load_t) ZIO_SIG_LOAD_ARGS ;
+typedef zap_status_t (*zio_sig_configure_t) ZIO_SIG_CONFIGURE_ARGS ;
+typedef zap_status_t (*zio_io_unload_t) ZIO_IO_UNLOAD_ARGS ;
+typedef zap_status_t (*zio_sig_unload_t) ZIO_SIG_UNLOAD_ARGS ;
#define ZIO_CHANNEL_REQUEST_FUNCTION(name) zap_status_t name ZIO_CHANNEL_REQUEST_ARGS
#define ZIO_CHANNEL_OUTGOING_CALL_FUNCTION(name) zap_status_t name ZIO_CHANNEL_OUTGOING_CALL_ARGS
#define ZIO_WAIT_FUNCTION(name) zap_status_t name ZIO_WAIT_ARGS
#define ZIO_READ_FUNCTION(name) zap_status_t name ZIO_READ_ARGS
#define ZIO_WRITE_FUNCTION(name) zap_status_t name ZIO_WRITE_ARGS
+#define ZIO_IO_LOAD_FUNCTION(name) zap_status_t name ZIO_IO_LOAD_ARGS
+#define ZIO_SIG_LOAD_FUNCTION(name) zap_status_t name ZIO_SIG_LOAD_ARGS
+#define ZIO_SIG_CONFIGURE_FUNCTION(name) zap_status_t name ZIO_SIG_CONFIGURE_ARGS
+#define ZIO_IO_UNLOAD_FUNCTION(name) zap_status_t name ZIO_IO_UNLOAD_ARGS
+#define ZIO_SIG_UNLOAD_FUNCTION(name) zap_status_t name ZIO_SIG_UNLOAD_ARGS
+
+#include "zap_dso.h"
+
+typedef struct {
+ char name[256];
+ zio_io_load_t io_load;
+ zio_io_unload_t io_unload;
+ zio_sig_load_t sig_load;
+ zio_sig_configure_t sig_configure;
+ zio_sig_unload_t sig_unload;
+ zap_dso_lib_t lib;
+ char path[256];
+} zap_module_t;
#ifndef __FUNCTION__
#define __FUNCTION__ (const char *)__func__
typedef int (*zap_fsk_data_decoder_t)(zap_fsk_data_state_t *state);
typedef zap_status_t (*zap_fsk_write_sample_t)(int16_t *buf, zap_size_t buflen, void *user_data);
typedef void (*zap_logger_t)(const char *file, const char *func, int line, int level, const char *fmt, ...);
-typedef struct zap_io_interface zap_io_interface_t;
typedef struct hashtable zap_hash_t;
-typedef struct hashtable_itr zap_hash_itr_t;
+typedef struct hashtable_iterator zap_hash_iterator_t;
typedef struct key zap_hash_key_t;
typedef struct value zap_hash_val_t;
typedef struct zap_bitstream zap_bitstream_t;
typedef struct zap_fsk_modulator zap_fsk_modulator_t;
+typedef zap_status_t (*zap_span_start_t)(zap_span_t *span);
typedef enum {
ZAP_CAUSE_NONE = 0,
+++ /dev/null
-/*
- * Copyright (c) 2007, 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
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
- * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef ZAP_WANPIPE_H
-#define ZAP_WANPIPE_H
-#include "openzap.h"
-
-zap_status_t wanpipe_init(zap_io_interface_t **zint);
-zap_status_t wanpipe_destroy(void);
-
-#endif
-
-/* 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 expandtab:
- */
-
return ZAP_SUCCESS;
}
-zap_status_t zap_analog_configure_span(zap_span_t *span, char *tonemap, uint32_t digit_timeout, uint32_t max_dialstr, zio_signal_cb_t sig_cb)
+
+static zap_status_t zap_analog_start(zap_span_t *span)
+{
+ zap_analog_data_t *analog_data = span->signal_data;
+ zap_set_flag(analog_data, ZAP_ANALOG_RUNNING);
+ return zap_thread_create_detached(zap_analog_run, span);
+}
+
+static ZIO_SIG_CONFIGURE_FUNCTION(zap_analog_configure_span)
+//zap_status_t zap_analog_configure_span(zap_span_t *span, char *tonemap, uint32_t digit_timeout, uint32_t max_dialstr, zio_signal_cb_t sig_cb)
{
zap_analog_data_t *analog_data;
+ char *tonemap = "us";
+ uint32_t digit_timeout = 10;
+ uint32_t max_dialstr = 11;
+ char *var, *val;
+ int *intval;
+
assert(sig_cb != NULL);
if (span->signal_type) {
memset(analog_data, 0, sizeof(*analog_data));
assert(analog_data != NULL);
+
+ while(var = va_arg(ap, char *)) {
+ if (!strcasecmp(var, "tonemap")) {
+ if (!(val = va_arg(ap, char *))) {
+ break;
+ }
+ tonemap = val;
+ } else if (!strcasecmp(var, "digit_timeout")) {
+ if (!(intval = va_arg(ap, int *))) {
+ break;
+ }
+ digit_timeout = *intval;
+ } else if (!strcasecmp(var, "max_dialstr")) {
+ if (!(intval = va_arg(ap, int *))) {
+ break;
+ }
+ max_dialstr = *intval;
+ }
+ }
+
+ span->start = zap_analog_start;
analog_data->digit_timeout = digit_timeout;
analog_data->max_dialstr = max_dialstr;
analog_data->sig_cb = sig_cb;
}
-zap_status_t zap_analog_start(zap_span_t *span)
+static ZIO_SIG_LOAD_FUNCTION(zap_analog_init)
{
- zap_analog_data_t *analog_data = span->signal_data;
- zap_set_flag(analog_data, ZAP_ANALOG_RUNNING);
- return zap_thread_create_detached(zap_analog_run, span);
+ return ZAP_SUCCESS;
}
+zap_module_t zap_module = {
+ "analog",
+ NULL,
+ NULL,
+ zap_analog_init,
+ zap_analog_configure_span,
+ NULL
+};
+
+
/* For Emacs:
* Local Variables:
* mode:c
ZAP_ANALOG_RUNNING = (1 << 0)
} zap_analog_flag_t;
-
+static void *zap_analog_run(zap_thread_t *me, void *obj);
typedef struct zap_analog_data zap_analog_data_t;
-zap_status_t zap_analog_start(zap_span_t *span);
-zap_status_t zap_analog_configure_span(zap_span_t *span, char *tonemap, uint32_t digit_timeout, uint32_t max_dialstr, zio_signal_cb_t sig_cb);
-
#endif
/* For Emacs:
zap_sigmsg_t sig;
zap_status_t status;
- zap_log(ZAP_LOG_ERROR, "%d:%d STATE [%s]\n",
+ zap_log(ZAP_LOG_DEBUG, "%d:%d STATE [%s]\n",
zchan->span_id, zchan->chan_id, zap_channel_state2str(zchan->state));
memset(&sig, 0, sizeof(sig));
return NULL;
}
-zap_status_t zap_isdn_init(void)
+static ZIO_SIG_LOAD_FUNCTION(zap_isdn_init)
{
Q931Initialize();
return ZAP_SUCCESS;
}
-zap_status_t zap_isdn_start(zap_span_t *span)
-{
- zap_isdn_data_t *isdn_data = span->signal_data;
- zap_set_flag(isdn_data, ZAP_ISDN_RUNNING);
- return zap_thread_create_detached(zap_isdn_run, span);
-}
-
static int q931_rx_32(void *pvt, Q921DLMsg_t ind, L3UCHAR tei, L3UCHAR *msg, L3INT mlen)
{
int offset = 4;
}
};
-zap_status_t zap_isdn_configure_span(zap_span_t *span, Q921NetUser_t mode, Q931Dialect_t dialect, zap_isdn_opts_t opts, zio_signal_cb_t sig_cb)
+static zap_status_t zap_isdn_start(zap_span_t *span)
+{
+ zap_isdn_data_t *isdn_data = span->signal_data;
+ zap_set_flag(isdn_data, ZAP_ISDN_RUNNING);
+ return zap_thread_create_detached(zap_isdn_run, span);
+}
+
+
+
+static ZIO_SIG_CONFIGURE_FUNCTION(zap_isdn_configure_span)
{
uint32_t i, x = 0;
zap_channel_t *dchans[2] = {0};
zap_isdn_data_t *isdn_data;
+ char *var, *val;
+ Q931Dialect_t dialect = Q931_Dialect_National;
+ uint32_t opts = 0;
+
if (span->signal_type) {
snprintf(span->last_error, sizeof(span->last_error), "Span is already configured for signalling [%d].", span->signal_type);
return ZAP_FAIL;
return ZAP_FAIL;
}
-
isdn_data = malloc(sizeof(*isdn_data));
assert(isdn_data != NULL);
memset(isdn_data, 0, sizeof(*isdn_data));
+ isdn_data->mode = Q931_TE;
+ dialect = Q931_Dialect_National;
+
+ while(var = va_arg(ap, char *)) {
+ if (!strcasecmp(var, "mode")) {
+ if (!(val = va_arg(ap, char *))) {
+ break;
+ }
+ isdn_data->mode = strcasecmp(val, "net") ? Q931_TE : Q931_NT;
+ } else if (!strcasecmp(var, "dialect")) {
+ if (!(val = va_arg(ap, char *))) {
+ break;
+ }
+ dialect = q931_str2Q931Dialect_type(val);
+ if (dialect == Q931_Dialect_Count) {
+ dialect = Q931_Dialect_National;
+ }
+ } else if (!strcasecmp(var, "opts")) {
+ int *optp;
+ if (!(optp = va_arg(ap, int *))) {
+ break;
+ }
+ opts = isdn_data->opts = *optp;
+ }
+ }
+
+ span->start = zap_isdn_start;
isdn_data->sig_cb = sig_cb;
isdn_data->dchans[0] = dchans[0];
isdn_data->dchans[1] = dchans[1];
isdn_data->dchan = isdn_data->dchans[0];
- isdn_data->mode = mode;
Q921_InitTrunk(&isdn_data->q921,
0,
0,
- mode,
+ isdn_data->mode,
span->trunk_type == ZAP_TRUNK_BRI_PTMP ? Q921_PTMP : Q921_PTP,
0,
zap_isdn_921_21,
Q931Api_InitTrunk(&isdn_data->q931,
dialect,
- mode,
+ isdn_data->mode,
span->trunk_type,
zap_isdn_931_34,
(Q931Tx32CB_t)q931_rx_32,
span->signal_data = isdn_data;
span->signal_type = ZAP_SIGTYPE_ISDN;
span->outgoing_call = isdn_outgoing_call;
- isdn_data->opts = opts;
+
if ((opts & ZAP_ISDN_OPT_SUGGEST_CHANNEL)) {
span->channel_request = isdn_channel_request;
return ZAP_SUCCESS;
}
+
+zap_module_t zap_module = {
+ "isdn",
+ NULL,
+ NULL,
+ zap_isdn_init,
+ zap_isdn_configure_span,
+ NULL
+};
+
+
/* For Emacs:
* Local Variables:
* mode:c
typedef struct zap_isdn_data zap_isdn_data_t;
-zap_status_t zap_isdn_start(zap_span_t *span);
-zap_status_t zap_isdn_init(void);
-zap_status_t zap_isdn_configure_span(zap_span_t *span, Q921NetUser_t mode, Q931Dialect_t dialect, zap_isdn_opts_t opts, zio_signal_cb_t sig_cb);
-
#endif
/* For Emacs:
static zap_io_interface_t pika_interface;
-zap_status_t pika_init(zap_io_interface_t **zint)
+static ZIO_IO_LOAD_FUNCTION(pika_init)
{
PK_STATUS status;
PKH_TLogMasks m;
TPikaHandle tmpHandle;
- assert(zint != NULL);
+ assert(zio != NULL);
memset(&pika_interface, 0, sizeof(pika_interface));
memset(&globals, 0, sizeof(globals));
globals.general_config.region = PKH_TRUNK_NA;
pika_interface.channel_destroy = pika_channel_destroy;
pika_interface.span_destroy = pika_span_destroy;
pika_interface.get_alarms = pika_get_alarms;
- *zint = &pika_interface;
+ *zio = &pika_interface;
zap_log(ZAP_LOG_INFO, "Dumping Default configs:\n");
return ZAP_SUCCESS;
}
-zap_status_t pika_destroy(void)
+
+static ZIO_IO_UNLOAD_FUNCTION(pika_destroy)
{
uint32_t x;
PK_STATUS status;
return ZAP_SUCCESS;
}
+zap_module_t zap_module = {
+ "pika",
+ pika_init,
+ pika_destroy,
+};
+
/* For Emacs:
* Local Variables:
* mode:c
#define PIKA_SPAN_COMPAND_MODE_STRINGS "MU_LAW", "A_LAW"
ZAP_STR2ENUM_P(pika_str2compand_mode, pika_compand_mode2str, PIKA_TSpanCompandMode)
-
-/* Openzap PIKA hardware interface functions */
-zap_status_t pika_init(zap_io_interface_t **zint);
-zap_status_t pika_destroy(void);
-
#endif
/* For Emacs:
#include "openzap.h"
-#include "zap_skel.h"
+//#include "zap_skel.h"
static ZIO_CONFIGURE_FUNCTION(skel_configure)
{
- ZIO_CONFIGURE_MUZZLE;
return ZAP_FAIL;
}
static ZIO_CONFIGURE_SPAN_FUNCTION(skel_configure_span)
{
-
+ return ZAP_FAIL;
}
static ZIO_OPEN_FUNCTION(skel_open)
{
- ZIO_OPEN_MUZZLE;
return ZAP_FAIL;
}
static ZIO_CLOSE_FUNCTION(skel_close)
{
- ZIO_CLOSE_MUZZLE;
- return ZAP_FAIL;
-}
-
-static ZIO_SET_INTERVAL_FUNCTION(skel_set_interval)
-{
- ZIO_SET_INTERVAL_MUZZLE;
return ZAP_FAIL;
}
static ZIO_WAIT_FUNCTION(skel_wait)
{
- ZIO_WAIT_MUZZLE;
return ZAP_FAIL;
}
static ZIO_READ_FUNCTION(skel_read)
{
- ZIO_READ_MUZZLE;
return ZAP_FAIL;
}
static ZIO_WRITE_FUNCTION(skel_write)
{
- ZIO_WRITE_MUZZLE;
return ZAP_FAIL;
}
return ZAP_FAIL;
}
-static ZIO_CHANNEL_DESTROY_FUNCTION(skel_span_destroy)
+static ZIO_SPAN_DESTROY_FUNCTION(skel_span_destroy)
{
return ZAP_FAIL;
}
static ZIO_GET_ALARMS_FUNCTION(skel_get_alarms)
{
- return zap_fail;
+ return ZAP_FAIL;
}
static zap_io_interface_t skel_interface;
-zap_status_t skel_init(zap_io_interface_t **zint)
+static ZIO_IO_LOAD_FUNCTION(skel_init)
{
- assert(zint != NULL);
+ assert(zio != NULL);
memset(&skel_interface, 0, sizeof(skel_interface));
skel_interface.name = "skel";
skel_interface.channel_destroy = skel_channel_destroy;
skel_interface.span_destroy = skel_span_destroy;
skel_interface.get_alarms = skel_get_alarms;
- *zint = &skel_interface;
+ *zio = &skel_interface;
- return ZAP_FAIL;
+ return ZAP_SUCCESS;
}
-zap_status_t skel_destroy(void)
+static ZIO_IO_UNLOAD_FUNCTION(skel_destroy)
{
- return ZAP_FAIL;
+ return ZAP_SUCCESS;
}
+
+zap_module_t zap_module = {
+ "skel",
+ skel_init,
+ skel_destroy,
+};
+
+
/* For Emacs:
* Local Variables:
* mode:c
return NULL;
}
-zap_status_t zap_ss7_boost_init(void)
+static ZIO_SIG_LOAD_FUNCTION(zap_ss7_boost_init)
{
zap_mutex_create(&request_mutex);
zap_mutex_create(&signal_mutex);
-
+
return ZAP_SUCCESS;
}
-zap_status_t zap_ss7_boost_start(zap_span_t *span)
+static zap_status_t zap_ss7_boost_start(zap_span_t *span)
{
zap_ss7_boost_data_t *ss7_boost_data = span->signal_data;
zap_set_flag(ss7_boost_data, ZAP_SS7_BOOST_RUNNING);
}
};
-zap_status_t zap_ss7_boost_configure_span(zap_span_t *span,
- const char *local_ip, int local_port,
- const char *remote_ip, int remote_port,
- zio_signal_cb_t sig_cb)
+static ZIO_SIG_CONFIGURE_FUNCTION(zap_ss7_boost_configure_span)
{
zap_ss7_boost_data_t *ss7_boost_data = NULL;
-
+ char *local_ip = "127.0.0.65", *remote_ip = "127.0.0.66";
+ int local_port = 5300, remote_port = 5300;
+ char *var, *val;
+ int *intval;
+
+ while(var = va_arg(ap, char *)) {
+ if (!strcasecmp(var, "local_ip")) {
+ if (!(val = va_arg(ap, char *))) {
+ break;
+ }
+ local_ip = val;
+ } else if (!strcasecmp(var, "remote_ip")) {
+ if (!(val = va_arg(ap, char *))) {
+ break;
+ }
+ remote_ip = val;
+ } else if (!strcasecmp(var, "local_port")) {
+ if (!(intval = va_arg(ap, int *))) {
+ break;
+ }
+ local_port = *intval;
+ } else if (!strcasecmp(var, "remote_port")) {
+ if (!(intval = va_arg(ap, int *))) {
+ break;
+ }
+ remote_port = *intval;
+ }
+ }
+
+
if (!local_ip && local_port && remote_ip && remote_port && sig_cb) {
return ZAP_FAIL;
}
zap_set_string(ss7_boost_data->mcon.cfg.remote_ip, remote_ip);
ss7_boost_data->mcon.cfg.remote_port = remote_port;
ss7_boost_data->signal_cb = sig_cb;
-
+ span->start = zap_ss7_boost_start;
span->signal_data = ss7_boost_data;
span->signal_type = ZAP_SIGTYPE_SS7BOOST;
span->outgoing_call = ss7_boost_outgoing_call;
return ZAP_SUCCESS;
}
+
+zap_module_t zap_module = {
+ "analog",
+ NULL,
+ NULL,
+ zap_ss7_boost_init,
+ zap_ss7_boost_configure_span,
+ NULL
+};
+
/* For Emacs:
* Local Variables:
* mode:c
uint32_t flags;
} zap_ss7_boost_data_t;
-zap_status_t zap_ss7_boost_start(zap_span_t *span);
-zap_status_t zap_ss7_boost_init(void);
-zap_status_t zap_ss7_boost_configure_span(zap_span_t *span,
- const char *local_ip, int local_port,
- const char *remote_ip, int remote_port,
- zio_signal_cb_t sig_cb);
-
-
#endif
/* For Emacs:
#include <stropts.h>
#endif
#include "openzap.h"
-#include "zap_wanpipe.h"
#include <poll.h>
#include <sys/socket.h>
-#include <wanpipe_tdm_api_iface.h>
+#include "wanpipe_tdm_api_iface.h"
typedef enum {
WP_RINGING = (1 << 0)
return ZAP_SUCCESS;
}
-zap_status_t wanpipe_init(zap_io_interface_t **zio)
+static ZIO_IO_LOAD_FUNCTION(wanpipe_init)
{
assert(zio != NULL);
memset(&wanpipe_interface, 0, sizeof(wanpipe_interface));
return ZAP_SUCCESS;
}
-zap_status_t wanpipe_destroy(void)
+static ZIO_IO_UNLOAD_FUNCTION(wanpipe_destroy)
{
memset(&wanpipe_interface, 0, sizeof(wanpipe_interface));
return ZAP_SUCCESS;
}
+
+zap_module_t zap_module = {
+ "wanpipe",
+ wanpipe_init,
+ wanpipe_destroy,
+};
+
/* For Emacs:
* Local Variables:
* mode:c
#include "openzap.h"
-#include "zap_zt.h"
+#include "ozmod_zt.h"
static struct {
static zap_io_interface_t zt_interface;
-zap_status_t zt_init(zap_io_interface_t **zio)
+static ZIO_IO_LOAD_FUNCTION(zt_init)
{
assert(zio != NULL);
memset(&zt_interface, 0, sizeof(zt_interface));
return ZAP_SUCCESS;
}
-zap_status_t zt_destroy(void)
+static ZIO_IO_UNLOAD_FUNCTION(zt_destroy)
{
close(CONTROL_FD);
memset(&zt_interface, 0, sizeof(zt_interface));
return ZAP_SUCCESS;
}
+
+zap_module_t zap_module = {
+ "zt",
+ zt_init,
+ zt_destroy,
+};
+
/* For Emacs:
* Local Variables:
* mode:c
#define ZT_ECHOTRAIN _IOW (ZT_CODE, 50, int) /* Control Echo Trainer */
-/* Openzap ZT hardware interface functions */
-zap_status_t zt_init(zap_io_interface_t **zint);
-zap_status_t zt_destroy(void);
-
#endif
/* For Emacs:
#include "openzap.h"
-#include "zap_analog.h"
static void *test_call(zap_thread_t *me, void *obj)
return ZAP_SUCCESS;
}
+static int R = 0;
+static void handle_SIGINT(int sig)
+{
+ if (sig);
+ R = 0;
+ return;
+}
+
int main(int argc, char *argv[])
{
zap_span_t *span;
int span_id;
- zap_analog_data_t *analog_data;
+ int digit_timeout = 2000;
+ int max_dialstr = 11;
if (argc < 2) {
printf("usage %s <spanno>\n", argv[0]);
goto done;
}
- if (zap_analog_configure_span(span, "us", 2000, 11, on_signal) != ZAP_SUCCESS) {
+
+ if (zap_configure_span("analog", span, on_signal,
+ "tonemap", "te",
+ "digit_timeout", &digit_timeout,
+ "max_dialstr", &max_dialstr
+ ) == ZAP_SUCCESS) {
zap_log(ZAP_LOG_ERROR, "Error configuring OpenZAP span\n");
goto done;
}
- analog_data = span->signal_data;
- zap_analog_start(span);
-
- while(zap_test_flag(analog_data, ZAP_ANALOG_RUNNING)) {
+ zap_span_start(span);
+
+ while(zap_running() && R) {
zap_sleep(1 * 1000);
}
-
- done:
+done:
zap_global_destroy();
#include "openzap.h"
-#include "zap_ss7_boost.h"
static ZIO_SIGNAL_CB_FUNCTION(on_signal)
{
return ZAP_FAIL;
}
+static int R = 0;
+static void handle_SIGINT(int sig)
+{
+ if (sig);
+ R = 0;
+ return;
+}
+
int main(int argc, char *argv[])
{
zap_span_t *span;
- zap_ss7_boost_data_t *data;
+ int local_port, remote_port;
+
+ local_port = remote_port = 53000;
zap_global_set_default_logger(ZAP_LOG_LEVEL_DEBUG);
goto done;
}
-
- if (zap_ss7_boost_configure_span(span, "127.0.0.65", 53000, "127.0.0.66", 53000, on_signal) == ZAP_SUCCESS) {
- data = span->signal_data;
- zap_ss7_boost_start(span);
+ if (zap_configure_span("ss7_boost", span, on_signal,
+ "local_ip", "127.0.0.65",
+ "local_port", &local_port,
+ "remote_ip", "127.0.0.66",
+ "remote_port", &remote_port
+ ) == ZAP_SUCCESS) {
+ zap_span_start(span);
} else {
fprintf(stderr, "Error starting SS7_BOOST\n");
goto done;
}
- while(zap_test_flag(data, ZAP_SS7_BOOST_RUNNING)) {
+ while(zap_running() && R) {
zap_sleep(1 * 1000);
}
#include "openzap.h"
-#include "zap_isdn.h"
+#include <signal.h>
+
static ZIO_SIGNAL_CB_FUNCTION(on_signal)
{
return ZAP_FAIL;
}
+static int R = 0;
+static void handle_SIGINT(int sig)
+{
+ if (sig);
+ R = 0;
+ return;
+}
+
int main(int argc, char *argv[])
{
zap_span_t *span;
- zap_isdn_data_t *data;
-
+
zap_global_set_default_logger(ZAP_LOG_LEVEL_DEBUG);
if (argc < 2) {
}
+#if 1
+
+ if (zap_configure_span("isdn", span, on_signal,
+ "mode", "te",
+ "dialect", "national"
+ ) == ZAP_SUCCESS) {
+ zap_span_start(span);
+ } else {
+ fprintf(stderr, "Error starting ISDN D-Channel\n");
+ goto done;
+ }
+#else
if (zap_isdn_configure_span(span, Q931_TE, Q931_Dialect_National, 0, on_signal) == ZAP_SUCCESS) {
- data = span->signal_data;
zap_isdn_start(span);
} else {
fprintf(stderr, "Error starting ISDN D-Channel\n");
goto done;
}
- while(zap_test_flag(data, ZAP_ISDN_RUNNING)) {
+#endif
+
+ signal(SIGINT, handle_SIGINT);
+ R = 1;
+ while(R) {
zap_sleep(1 * 1000);
}
#include <dlfcn.h>
void zap_dso_destroy(zap_dso_lib_t *lib) {
- if (lib) {
- dlclose(lib);
- lib = NULL;
+ if (lib && *lib) {
+ dlclose(*lib);
+ *lib = NULL;
}
}
-zap_dso_lib_t zap_dso_open(const char *path, const char **err) {
+zap_dso_lib_t zap_dso_open(const char *path, char **err) {
void *lib = dlopen(path, RTLD_NOW | RTLD_LOCAL);
if (lib == NULL) {
*err = strdup(dlerror());
return lib;
}
-zap_func_ptr_t zap_dso_func_sym(zap_dso_lib_t lib, const char *sym, const char **err) {
- zap_dso_lib_t func = (zap_dso_lib_t)dlsym(lib, sym);
+void *zap_dso_func_sym(zap_dso_lib_t lib, const char *sym, char **err) {
+ void *func = dlsym(lib, sym);
if (!func) {
*err = strdup(dlerror());
}
*/
#ifndef WIN32
-#define ZAP_ZT_SUPPORT
-#define ZAP_WANPIPE_SUPPORT
#endif
#include "openzap.h"
-#include "zap_isdn.h"
-#include "zap_ss7_boost.h"
+//#include "zap_isdn.h"
+//#include "zap_ss7_boost.h"
#include <stdarg.h>
#ifdef WIN32
#include <io.h>
#endif
-#ifdef ZAP_WANPIPE_SUPPORT
-#include "zap_wanpipe.h"
-#endif
-#ifdef ZAP_ZT_SUPPORT
-#include "zap_zt.h"
-#endif
#ifdef ZAP_PIKA_SUPPORT
#include "zap_pika.h"
#endif
static struct {
zap_hash_t *interface_hash;
+ zap_hash_t *module_hash;
zap_mutex_t *mutex;
struct zap_span spans[ZAP_MAX_SPANS_INTERFACE];
uint32_t span_index;
}
static struct {
- zap_io_interface_t *wanpipe_interface;
- zap_io_interface_t *zt_interface;
zap_io_interface_t *pika_interface;
} interfaces;
return ZAP_SUCCESS;
}
+int zap_load_modules(void)
+{
+ char cfg_name[] = "modules.conf";
+ char path[128] = "";
+ zap_config_t cfg;
+ char *err;
+ char *var, *val;
+ zap_module_t *mod;
+ int count = 0;
+
+#ifdef WIN32
+ const char *ext = ".dll";
+ //const char *EXT = ".DLL";
+#elif defined (MACOSX) || defined (DARWIN)
+ const char *ext = ".dylib";
+ //const char *EXT = ".DYLIB";
+#else
+ const char *ext = ".so";
+ //const char *EXT = ".SO";
+#endif
+
+
+ if (!zap_config_open_file(&cfg, cfg_name)) {
+ return ZAP_FAIL;
+ }
+
+ while (zap_config_next_pair(&cfg, &var, &val)) {
+ if (!strcasecmp(cfg.category, "modules")) {
+ if (!strcasecmp(var, "load")) {
+ zap_dso_lib_t lib;
+ int x = 0;
+
+ if (*val == *ZAP_PATH_SEPARATOR) {
+ snprintf(path, sizeof(path), "%s%s", val, ext);
+ } else {
+ snprintf(path, sizeof(path), "%s%s%s%s", ZAP_MOD_DIR, ZAP_PATH_SEPARATOR, val, ext);
+ }
+
+ if (!(lib = zap_dso_open(path, &err))) {
+ zap_log(ZAP_LOG_ERROR, "Error loading %s [%s]\n", path, err);
+ free(err);
+ continue;
+ }
+
+ if (!(mod = (zap_module_t *) zap_dso_func_sym(lib, "zap_module", &err))) {
+ zap_log(ZAP_LOG_ERROR, "Error loading %s [%s]\n", path, err);
+ free(err);
+ continue;
+ }
+
+ if (mod->io_load) {
+ zap_io_interface_t *interface;
+
+ if (mod->io_load(&interface) != ZAP_SUCCESS || !interface) {
+ zap_log(ZAP_LOG_ERROR, "Error loading %s [%s]\n", path, err);
+ } else {
+ zap_log(ZAP_LOG_INFO, "Loading IO from %s\n", path);
+ zap_mutex_lock(globals.mutex);
+ hashtable_insert(globals.interface_hash, (void *)interface->name, interface);
+ process_module_config(interface);
+ zap_mutex_unlock(globals.mutex);
+ x++;
+ }
+ }
+
+ if (mod->sig_load) {
+ if (mod->sig_load() != ZAP_SUCCESS) {
+ zap_log(ZAP_LOG_ERROR, "Error loading %s [%s]\n", path, err);
+ } else {
+ zap_log(ZAP_LOG_INFO, "Loading SIG from %s\n", path);
+ x++;
+ }
+ }
+
+ if (x) {
+ char *p;
+ mod->lib = lib;
+ zap_set_string(mod->path, path);
+ if (mod->name[0] == '\0') {
+ if (!(p = strrchr(path, *ZAP_PATH_SEPARATOR))) {
+ p = path;
+ }
+ zap_set_string(mod->name, p);
+ }
+
+ hashtable_insert(globals.module_hash, (void *)mod->name, mod);
+ count++;
+ } else {
+ zap_log(ZAP_LOG_ERROR, "Unloading %s\n", path);
+ zap_dso_destroy(&lib);
+ }
+ }
+ }
+ }
+
+ return count;
+}
+
+zap_status_t zap_unload_modules(void)
+{
+ zap_hash_iterator_t *i;
+ zap_dso_lib_t lib;
+
+ for (i = hashtable_first(globals.module_hash); i; i = hashtable_next(i)) {
+ const void *key;
+ void *val;
+
+ hashtable_this(i, &key, NULL, &val);
+
+ if (key && val) {
+ zap_module_t *mod = (zap_module_t *) val;
+
+ if (!mod) {
+ continue;
+ }
+
+ if (mod->io_unload) {
+ if (mod->io_unload() == ZAP_SUCCESS) {
+ zap_log(ZAP_LOG_INFO, "Unloading IO %s\n", mod->name);
+ } else {
+ zap_log(ZAP_LOG_ERROR, "Error unloading IO %s\n", mod->name);
+ }
+ }
+
+ if (mod->sig_unload) {
+ if (mod->sig_unload() == ZAP_SUCCESS) {
+ zap_log(ZAP_LOG_INFO, "Unloading SIG %s\n", mod->name);
+ } else {
+ zap_log(ZAP_LOG_ERROR, "Error unloading SIG %s\n", mod->name);
+ }
+ }
+
+
+ zap_log(ZAP_LOG_INFO, "Unloading %s\n", mod->path);
+ lib = mod->lib;
+ zap_dso_destroy(&lib);
+
+ }
+ }
+
+ return ZAP_SUCCESS;
+}
+
+zap_status_t zap_configure_span(const char *type, zap_span_t *span, zio_signal_cb_t sig_cb, ...)
+{
+ zap_module_t *mod = (zap_module_t *) hashtable_search(globals.module_hash, (void *)type);
+ zap_status_t status = ZAP_FAIL;
+
+ if (mod && mod->sig_configure) {
+ va_list ap;
+ va_start(ap, sig_cb);
+ status = mod->sig_configure(span, sig_cb, ap);
+ va_end(ap);
+ }
+ return status;
+}
+
+zap_status_t zap_span_start(zap_span_t *span)
+{
+ if (span->start) {
+ return span->start(span);
+ }
+
+ return ZAP_FAIL;
+}
+
+
zap_status_t zap_global_init(void)
{
int modcount;
memset(&globals, 0, sizeof(globals));
time_init();
- zap_isdn_init();
- zap_ss7_boost_init();
+ //zap_isdn_init();
+ //zap_ss7_boost_init();
memset(&interfaces, 0, sizeof(interfaces));
globals.interface_hash = create_hashtable(16, zap_hash_hashfromstring, zap_hash_equalkeys);
+ globals.module_hash = create_hashtable(16, zap_hash_hashfromstring, zap_hash_equalkeys);
modcount = 0;
zap_mutex_create(&globals.mutex);
-#ifdef ZAP_WANPIPE_SUPPORT
- if (wanpipe_init(&interfaces.wanpipe_interface) == ZAP_SUCCESS) {
- zap_mutex_lock(globals.mutex);
- hashtable_insert(globals.interface_hash, (void *)interfaces.wanpipe_interface->name, interfaces.wanpipe_interface);
- process_module_config(interfaces.wanpipe_interface);
- zap_mutex_unlock(globals.mutex);
- modcount++;
- } else {
- zap_log(ZAP_LOG_ERROR, "Error initilizing wanpipe.\n");
- }
-#endif
-
-#ifdef ZAP_ZT_SUPPORT
- if (zt_init(&interfaces.zt_interface) == ZAP_SUCCESS) {
- zap_mutex_lock(globals.mutex);
- hashtable_insert(globals.interface_hash, (void *)interfaces.zt_interface->name, interfaces.zt_interface);
- process_module_config(interfaces.zt_interface);
- zap_mutex_unlock(globals.mutex);
- modcount++;
- } else {
- zap_log(ZAP_LOG_ERROR, "Error initilizing zt.\n");
- }
-#endif
-
-#ifdef ZAP_PIKA_SUPPORT
- if (pika_init(&interfaces.pika_interface) == ZAP_SUCCESS) {
- zap_mutex_lock(globals.mutex);
- hashtable_insert(globals.interface_hash, (void *)interfaces.pika_interface->name, interfaces.pika_interface);
- process_module_config(interfaces.pika_interface);
- zap_mutex_unlock(globals.mutex);
- modcount++;
- } else {
- zap_log(ZAP_LOG_ERROR, "Error initilizing pika.\n");
- }
-#endif
+ modcount = zap_load_modules();
if (!modcount) {
zap_log(ZAP_LOG_ERROR, "Error initilizing anything.\n");
}
}
-
-#ifdef ZAP_ZT_SUPPORT
- if (interfaces.zt_interface) {
- zt_destroy();
- }
-#endif
-
-#ifdef ZAP_PIKA_SUPPORT
- if (interfaces.pika_interface) {
- pika_destroy();
- }
-#endif
-
-#ifdef ZAP_WANPIPE_SUPPORT
- if (interfaces.wanpipe_interface) {
- wanpipe_destroy();
- }
-#endif
+ zap_unload_modules();
zap_mutex_lock(globals.mutex);
hashtable_destroy(globals.interface_hash, 0, 0);
+ hashtable_destroy(globals.module_hash, 0, 0);
zap_mutex_unlock(globals.mutex);
zap_mutex_destroy(&globals.mutex);
}
-
/* For Emacs:
* Local Variables:
* mode:c