ar rcs $(MYLIB) $(OBJS)
ranlib $(MYLIB)
+testapp: testapp.c $(MYLIB)
+ $(CC) -L. -Iinclude testapp.c -o testapp -lopenzap -lm
+
openzap.o: openzap.c
$(CC) $(MOD_CFLAGS) $(CC_CFLAGS) $(CFLAGS) -c $< -o $@
805306457, 1610612741
};
const unsigned int prime_table_length = sizeof(primes)/sizeof(primes[0]);
-const float max_load_factor = 0.65f;
+const float max_load_factor = 0.65;
/*****************************************************************************/
struct hashtable *
create_hashtable(unsigned int minsize,
- unsigned int (*hashf) (const void*),
- int (*eqf) (const void*,const void*))
+ unsigned int (*hashf) (void*),
+ int (*eqf) (void*,void*))
{
struct hashtable *h;
unsigned int pindex, size = primes[0];
/*****************************************************************************/
unsigned int
-hash(struct hashtable *h, const void *k)
+hash(struct hashtable *h, void *k)
{
/* Aim to protect against poor hash functions by adding logic here
* - logic taken from java 1.4 hashtable source */
/*****************************************************************************/
void * /* returns value associated with key */
-hashtable_search(struct hashtable *h, const void *k)
+hashtable_search(struct hashtable *h, void *k)
{
struct entry *e;
unsigned int hashvalue, index;
return itr;
}
+/*****************************************************************************/
+/* key - return the key of the (key,value) pair at the current position */
+/* value - return the value of the (key,value) pair at the current position */
+
+void *
+hashtable_iterator_key(struct hashtable_itr *i)
+{ return i->e->k; }
+
+void *
+hashtable_iterator_value(struct hashtable_itr *i)
+{ return i->e->v; }
+
/*****************************************************************************/
/* advance - advance the iterator to the next element
* returns zero if advanced to end of table */
#ifndef __HASHTABLE_CWC22_H__
#define __HASHTABLE_CWC22_H__
+#ifdef _MSC_VER
+#ifndef __inline__
+#define __inline__ __inline
+#endif
+#endif
struct hashtable;
struct hashtable *
create_hashtable(unsigned int minsize,
- unsigned int (*hashfunction) (const void*),
- int (*key_eq_fn) (const void*,const void*));
+ unsigned int (*hashfunction) (void*),
+ int (*key_eq_fn) (void*,void*));
/*****************************************************************************
* hashtable_insert
*/
void *
-hashtable_search(struct hashtable *h, const void *k);
+hashtable_search(struct hashtable *h, void *k);
#define DEFINE_HASHTABLE_SEARCH(fnname, keytype, valuetype) \
valuetype * fnname (struct hashtable *h, keytype *k) \
/* hashtable_iterator_key
* - return the value of the (key,value) pair at the current position */
-#define hashtable_iterator_key(i) (void *)i->e->k
+extern __inline__ void *
+hashtable_iterator_key(struct hashtable_itr *i)
+{
+ return i->e->k;
+}
/*****************************************************************************/
/* value - return the value of the (key,value) pair at the current position */
-#define hashtable_iterator_value (void *)i->e->v
+extern __inline__ void *
+hashtable_iterator_value(struct hashtable_itr *i)
+{
+ return i->e->v;
+}
/*****************************************************************************/
/* advance - advance the iterator to the next element
#include "hashtable.h"
+
/*****************************************************************************/
struct entry
{
unsigned int entrycount;
unsigned int loadlimit;
unsigned int primeindex;
- unsigned int (*hashfn) (const void *k);
- int (*eqfn) (const void *k1, const void *k2);
+ unsigned int (*hashfn) (void *k);
+ int (*eqfn) (void *k1, void *k2);
};
/*****************************************************************************/
unsigned int
-hash(struct hashtable *h, const void *k);
+hash(struct hashtable *h, void *k);
/*****************************************************************************/
/* indexFor */
-#define indexFor(hashvalue, tablelength) (unsigned int)(hashvalue % tablelength)
+static __inline__ unsigned int
+indexFor(unsigned int tablelength, unsigned int hashvalue) {
+ return (hashvalue % tablelength);
+}
/* Only works if tablelength == 2^N */
/*static inline unsigned int
#define ZINT_WRITE_MUZZLE assert(zchan != NULL); assert(data != NULL); assert(datalen != NULL)
#define ZAP_PRE __FILE__, __FUNCTION__, __LINE__
-#define ZAP_LOG_DEBUG ZAP_PRE, 7
-#define ZAP_LOG_INFO ZAP_PRE, 6
-#define ZAP_LOG_NOTICE ZAP_PRE, 5
-#define ZAP_LOG_WARNING ZAP_PRE, 4
-#define ZAP_LOG_ERROR ZAP_PRE, 3
-#define ZAP_LOG_CRIT ZAP_PRE, 2
-#define ZAP_LOG_ALERT ZAP_PRE, 1
-#define ZAP_LOG_EMERG ZAP_PRE, 0
+
+#define ZAP_LOG_LEVEL_DEBUG 7
+#define ZAP_LOG_LEVEL_INFO 6
+#define ZAP_LOG_LEVEL_NOTICE 5
+#define ZAP_LOG_LEVEL_WARNING 4
+#define ZAP_LOG_LEVEL_ERROR 3
+#define ZAP_LOG_LEVEL_CRIT 2
+#define ZAP_LOG_LEVEL_ALERT 1
+#define ZAP_LOG_LEVEL_EMERG 0
+
+#define ZAP_LOG_DEBUG ZAP_PRE, ZAP_LOG_LEVEL_DEBUG
+#define ZAP_LOG_INFO ZAP_PRE, ZAP_LOG_LEVEL_INFO
+#define ZAP_LOG_NOTICE ZAP_PRE, ZAP_LOG_LEVEL_NOTICE
+#define ZAP_LOG_WARNING ZAP_PRE, ZAP_LOG_LEVEL_WARNING
+#define ZAP_LOG_ERROR ZAP_PRE, ZAP_LOG_LEVEL_ERROR
+#define ZAP_LOG_CRIT ZAP_PRE, ZAP_LOG_LEVEL_CRIT
+#define ZAP_LOG_ALERT ZAP_PRE, ZAP_LOG_LEVEL_ALERT
+#define ZAP_LOG_EMERG ZAP_PRE, ZAP_LOG_LEVEL_EMERG
typedef void (*zap_logger_t)(char *file, const char *func, int line, int level, char *fmt, ...);
-extern zap_logger_t global_logger;
-#define zap_log global_logger;
+extern zap_logger_t zap_log;
struct zap_software_interface {
const char *name;
zap_status_t zap_global_init(void);
zap_status_t zap_global_destroy(void);
void zap_global_set_logger(zap_logger_t logger);
-void zap_global_set_default_logger(void);
+void zap_global_set_default_logger(int level);
typedef struct hashtable zap_hash_t;
static void null_logger(char *file, const char *func, int line, int level, char *fmt, ...)
{
- if (file && func && line && level && fmt) {
- return;
+ if (0) {
+ null_logger(file, func, line, level, fmt, fmt + sizeof(fmt));
}
- return;
}
+static int zap_log_level;
+
static void default_logger(char *file, const char *func, int line, int level, char *fmt, ...)
{
char *fp;
char data[1024];
-
va_list ap;
+
+ if (level < 0 || level > 7) {
+ level = 7;
+ }
+ if (level > zap_log_level) {
+ return;
+ }
fp = cut_path(file);
vsnprintf(data, sizeof(data), fmt, ap);
- if (level < 0 || level > 7) {
- level = 7;
- }
fprintf(stderr, "[%s] %s:%d %s() %s", LEVEL_NAMES[level], file, line, func, data);
}
-zap_logger_t global_logger = null_logger;
+zap_logger_t zap_log = null_logger;
void zap_global_set_logger(zap_logger_t logger)
{
if (logger) {
- global_logger = logger;
+ zap_log = logger;
} else {
- global_logger = null_logger;
+ zap_log = null_logger;
}
}
-void zap_global_set_default_logger(void)
+void zap_global_set_default_logger(int level)
{
- global_logger = default_logger;
+ if (level < 0 || level > 7) {
+ level = 7;
+ }
+
+ zap_log = default_logger;
+ zap_log_level = level;
}
-static int equalkeys(const void *k1, const void *k2)
+static int equalkeys(void *k1, void *k2)
{
return strcmp((char *) k1, (char *) k2) ? 0 : 1;
}
-static unsigned hashfromstring(const void *ky)
+static unsigned hashfromstring(void *ky)
{
unsigned char *str = (unsigned char *) ky;
unsigned hash = 0;
int c;
-
+
while ((c = *str++)) {
hash = c + (hash << 6) + (hash << 16) - hash;
}
-
+
return hash;
}
zap_status_t zap_channel_open(const char *name, unsigned span_id, unsigned chan_id, zap_channel_t **zchan)
{
- zap_software_interface_t *zint = (zap_software_interface_t *) hashtable_search(globals.interface_hash, name);
+ zap_software_interface_t *zint = (zap_software_interface_t *) hashtable_search(globals.interface_hash, (char *)name);
if (span_id < ZAP_MAX_SPANS_INTERFACE && chan_id < ZAP_MAX_CHANNELS_SPAN && zint) {
zap_channel_t *check;
char *var, *val;
unsigned configured = 0;
zap_software_interface_t *zint;
+ int modcount;
globals.interface_hash = create_hashtable(16, hashfromstring, equalkeys);
zint = NULL;
+ modcount = 0;
#ifdef ZAP_WANPIPE_SUPPORT
if (wanpipe_init(&zint) == ZAP_SUCCESS) {
hashtable_insert(globals.interface_hash, (void *)zint->name, zint);
+ modcount++;
+ } else {
+ zap_log(ZAP_LOG_ERROR, "Error initilizing wanpipe.\n");
}
#endif
zint = NULL;
#ifdef ZAP_ZT_SUPPORT
if (zt_init(&zint) == ZAP_SUCCESS) {
hashtable_insert(globals.interface_hash, (void *)zint->name, zint);
+ modcount++;
+ } else {
+ zap_log(ZAP_LOG_ERROR, "Error initilizing zt.\n");
}
#endif
-
- if (!zap_config_open_file(&cfg, "openzap.conf")) {
+ if (!modcount) {
+ zap_log(ZAP_LOG_ERROR, "Error initilizing anything.\n");
return ZAP_FAIL;
}
+ if (!zap_config_open_file(&cfg, "openzap.conf")) {
+ return ZAP_FAIL;
+ }
+
while (zap_config_next_pair(&cfg, &var, &val)) {
if (!strcasecmp(cfg.category, "openzap")) {
if (!strcmp(var, "load")) {
zap_software_interface_t *zint;
-
+
zint = (zap_software_interface_t *) hashtable_search(globals.interface_hash, val);
if (zint) {
if (zint->configure(zint) == ZAP_SUCCESS) {
configured++;
}
+ } else {
+ zap_log(ZAP_LOG_WARNING, "Attempted to load Non-Existant module '%s'\n", val);
}
}
}
zap_config_close_file(&cfg);
- return configured ? ZAP_SUCCESS : ZAP_FAIL;
+ if (configured) {
+ return ZAP_SUCCESS;
+ }
+
+ zap_log(ZAP_LOG_ERROR, "No modules configured!\n");
+ return ZAP_FAIL;
}
zap_status_t zap_global_destroy(void)
--- /dev/null
+#include "openzap.h"
+
+int main(int argc, char *argv[])
+{
+ printf("hello\n");
+
+ zap_global_set_default_logger(ZAP_LOG_LEVEL_DEBUG);
+ zap_global_init();
+}
#include <sdla_front_end.h>
#include <sdla_aft_te1.h>
+static zap_software_interface_t wanpipe_interface;
+
struct wanpipe_channel {
struct zap_channel zchan;
int x;
zap_config_t cfg;
char *var, *val;
int catno = -1;
+ zap_span_t *span = NULL;
ZINT_CONFIGURE_MUZZLE;
+ zap_log(ZAP_LOG_DEBUG, "configuring wanpipe\n");
if (!zap_config_open_file(&cfg, "wanpipe.conf")) {
return ZAP_FAIL;
}
-
+
while (zap_config_next_pair(&cfg, &var, &val)) {
if (!strcasecmp(cfg.category, "span")) {
if (cfg.catno != catno) {
+ zap_log(ZAP_LOG_DEBUG, "found config for span %d\n", cfg.catno);
+ catno = cfg.catno;
+ if (zap_span_create(&wanpipe_interface, &span) == ZAP_SUCCESS) {
+ zap_log(ZAP_LOG_DEBUG, "created span %d\n", span->span_id);
+ } else {
+ zap_log(ZAP_LOG_CRIT, "failure creating span\n");
+ span = NULL;
+ }
+ continue;
+ }
+
+ if (!span) {
+ continue;
}
+
+ zap_log(ZAP_LOG_DEBUG, "span %d [%s]=[%s]\n", span->span_id, var, val);
}
}
zap_config_close_file(&cfg);
return ZAP_FAIL;
}
-static zap_software_interface_t wanpipe_interface;
-
zap_status_t wanpipe_init(zap_software_interface_t **zint)
{
assert(zint != NULL);
wanpipe_interface.write = wanpipe_write;
*zint = &wanpipe_interface;
- return ZAP_FAIL;
+ return ZAP_SUCCESS;
}
zap_status_t wanpipe_destroy(void)