コード例 #1
0
ファイル: wap_push_ota.c プロジェクト: markjeee/kannel
void wap_push_ota_init(wap_dispatch_func_t *wsp_dispatch,
                       wap_dispatch_func_t *wsp_unit_dispatch)
{
    ota_queue = gwlist_create();
    gwlist_add_producer(ota_queue);

    dispatch_to_wsp = wsp_dispatch;
    dispatch_to_wsp_unit = wsp_unit_dispatch;

    bearerbox = bearerbox_address_create();

    gw_assert(run_status == limbo);
    run_status = running;
    gwthread_create(main_thread, NULL);
}
コード例 #2
0
ファイル: bearerbox.c プロジェクト: markjeee/mbuni
/* helper function for queueing delivery reports. */
static int queue_dlr(MmscGrp *mmc, Octstr *from, Octstr *to, Octstr *msgid, Octstr *status, char *interf, List *errl)
{
     Octstr *mmc_id = NULL, *qdir;
     MmsMsg *m = mms_deliveryreport(msgid, from, to, time(NULL), status);
     List *lto = gwlist_create();
     int ret;
     Octstr *qf, *rr_uri = NULL;
     List *rqh = http_create_empty_headers(); 

     
     if (errl) 
	  http_header_combine(rqh, errl); /* add status stuff. */

     
     gwlist_append(lto, octstr_duplicate(to));

     
     qdir = get_mmsbox_queue_dir(from, lto, mmc, &mmc_id); /* get routing info. */

     rr_uri = mmsbox_get_report_info(m, mmc, mmc_id, "delivery-report", status, rqh, NULL, 0, msgid);     

     qf = qfs->mms_queue_add(from, lto, NULL, 
			     mmc ? mmc->id : NULL, mmc_id,
			     0, time(NULL) + default_msgexpiry, m, NULL, 
			     NULL, NULL,
			     rr_uri, NULL,
			     rqh,
			     0,
			     octstr_get_cstr(qdir), 				  
			     interf,
			     NULL);
     if (qf)  {
	  /* Log to access log */
	  mms_log("Received DLR", from, lto, -1, msgid, status, mmc ? mmc->id : NULL, "MMSBox", NULL, NULL);
	  ret = 0;
     }  else 
	  ret = -1;

     octstr_destroy(qf);
     http_destroy_headers(rqh);     
     octstr_destroy(rr_uri);
     
     gwlist_destroy(lto, (void *)octstr_destroy);
     octstr_destroy(mmc_id);
     mms_destroy(m);

     return ret;
}
コード例 #3
0
ファイル: mms_queue.c プロジェクト: frese/mbuni
static int mms_queue_size(char *dir)
{
	debug("mms_queue_size",0,"running mss_queue_size");
	List *stack = gwlist_create();
	Octstr *xdir = NULL;
	int size = 0;

	gwlist_append(stack, octstr_create(""));
	while (NULL != (xdir = gwlist_extract_first(stack))) {
		size += run_dir_count(dir, octstr_get_cstr(xdir), stack);
		octstr_destroy(xdir);
	}

	gwlist_destroy(stack,octstr_destroy_item);
	return size;
}
コード例 #4
0
List *wsp_cap_duplicate_list(List *caps_list) {
	Capability *cap;
	List *new_list;
	long i;

	new_list = gwlist_create();

	if (caps_list == NULL)
		return new_list;

	for (i = 0; i < gwlist_len(caps_list); i++) {
		cap = gwlist_get(caps_list, i);
		gwlist_append(new_list, wsp_cap_duplicate(cap));
	}
	return new_list;
};
コード例 #5
0
ファイル: xml_shared.c プロジェクト: Jayriq/kannel-gateway
/*
 * Return the character sets supported by the WML compiler, as a List
 * of Octstrs, where each string is the MIME identifier for one charset.
 */
List *wml_charsets(void)
{
    int i;
    List *result;
    Octstr *charset;

    result = gwlist_create();
    for (i = 0; character_sets[i].charset != NULL; i++) {
         charset = octstr_create(character_sets[i].charset);
         octstr_append_char(charset, '-');
         octstr_append(charset, octstr_imm(character_sets[i].nro));
         gwlist_append(result, charset);
    }

    return result;  
}
コード例 #6
0
ファイル: drive_wapbox.c プロジェクト: Phonebooth/kannel
static void initialize_clients(void) {
	long i;

	ready_clients = gwlist_create();

	clients = gw_malloc(max_clients * sizeof(*clients));
	for (i = 0; i < max_clients; i++) {
		clients[i].wtp_invoked = 0;
		clients[i].wtp_tid = 0;
		clients[i].wsp_connected = 0;
		clients[i].wsp_session_id = -1;
		clients[i].pages_fetched = 0;
		clients[i].port = i;
		gwlist_append(ready_clients, &clients[i]);
	}
}
コード例 #7
0
ファイル: dlr_mysql.c プロジェクト: Jayriq/kannel-gateway
static void dlr_mysql_add(struct dlr_entry *entry)
{
    Octstr *sql, *os_mask;
    DBPoolConn *pconn;
    List *binds = gwlist_create();
    int res;

    debug("dlr.mysql", 0, "adding DLR entry into database");

    pconn = dbpool_conn_consume(pool);
    /* just for sure */
    if (pconn == NULL) {
        dlr_entry_destroy(entry);
        return;
    }

    sql = octstr_format("INSERT INTO `%S` (`%S`, `%S`, `%S`, `%S`, `%S`, `%S`, `%S`, `%S`, `%S`) VALUES "
                        "(?, ?, ?, ?, ?, ?, ?, ?, 0)",
                        fields->table, fields->field_smsc, fields->field_ts,
                        fields->field_src, fields->field_dst, fields->field_serv,
                        fields->field_url, fields->field_mask, fields->field_boxc,
                        fields->field_status);
    os_mask = octstr_format("%d", entry->mask);
    gwlist_append(binds, entry->smsc);
    gwlist_append(binds, entry->timestamp);
    gwlist_append(binds, entry->source);
    gwlist_append(binds, entry->destination);
    gwlist_append(binds, entry->service);
    gwlist_append(binds, entry->url);
    gwlist_append(binds, os_mask);
    gwlist_append(binds, entry->boxc_id);

#if defined(DLR_TRACE)
    debug("dlr.mysql", 0, "sql: %s", octstr_get_cstr(sql));
#endif
    if ((res = dbpool_conn_update(pconn, sql, binds)) == -1)
        error(0, "DLR: MYSQL: Error while adding dlr entry for DST<%s>", octstr_get_cstr(entry->destination));
    else if (!res)
        warning(0, "DLR: MYSQL: No dlr inserted for DST<%s>", octstr_get_cstr(entry->destination));

    dbpool_conn_produce(pconn);
    octstr_destroy(sql);
    gwlist_destroy(binds, NULL);
    octstr_destroy(os_mask);
    dlr_entry_destroy(entry);
}
コード例 #8
0
ファイル: gw-rwlock.c プロジェクト: Phonebooth/kannel
RWLock *gw_rwlock_create(void)
{
    RWLock *ret = gw_malloc(sizeof(*ret));
#ifdef HAVE_PTHREAD_RWLOCK
    int rc = pthread_rwlock_init(&ret->rwlock, NULL);
    if (rc != 0)
        panic(rc, "Initialization of RWLock failed.");
#else
    ret->writer = -1;
    ret->rwlock = gwlist_create();
    if (ret->rwlock == NULL)
        panic(0, "Initialization of RWLock failed.");
#endif
    ret->dynamic = 1;

    return ret;
}
コード例 #9
0
ファイル: check_list.c プロジェクト: frese/mbuni
static void main_for_producer_and_consumer(void) {
	List *list;
	int i;
	Item *item;
	struct producer_info tab[NUM_PRODUCERS];
	long p, n, index;
	int errors;
	
	list = gwlist_create();
	init_received();
	
	for (i = 0; i < NUM_PRODUCERS; ++i) {
	    	tab[i].list = list;
		tab[i].start_index = i * NUM_ITEMS_PER_PRODUCER;
	    	gwlist_add_producer(list);
		tab[i].id = gwthread_create(producer, tab + i);
	}
	for (i = 0; i < NUM_CONSUMERS; ++i)
		gwthread_create(consumer, list);
	
    	gwthread_join_every(producer);
    	gwthread_join_every(consumer);

	while (gwlist_len(list) > 0) {
		item = gwlist_get(list, 0);
		gwlist_delete(list, 0, 1);
		warning(0, "main: %ld %ld %ld", (long) item->producer, 
				item->num, item->index);
	}
	
	errors = 0;
	for (p = 0; p < NUM_PRODUCERS; ++p) {
		for (n = 0; n < NUM_ITEMS_PER_PRODUCER; ++n) {
			index = p * NUM_ITEMS_PER_PRODUCER + n;
			if (!received[index]) {
				error(0, "Not received: producer=%ld "
				         "item=%ld index=%ld", 
					 tab[p].id, n, index);
				errors = 1;
			}
		}
	}
	
	if (errors)
		panic(0, "Not all messages were received.");
}
コード例 #10
0
ファイル: mms_queue.c プロジェクト: frese/mbuni
static int mms_queue_flush(char *dir)
{
	List *stack = gwlist_create();
	Octstr *xdir = NULL;

	gwlist_append(stack, octstr_create(""));
	int ret = 0; 

	while (NULL != (xdir = gwlist_extract_first(stack)))  {
		ret += flush_dir(dir, octstr_get_cstr(xdir), stack);
		octstr_destroy(xdir);
	}

	gwlist_destroy(stack,octstr_destroy_item);

	return ret;
}
コード例 #11
0
ファイル: dlr_mysql.c プロジェクト: Jayriq/kannel-gateway
static void dlr_mysql_update(const Octstr *smsc, const Octstr *ts, const Octstr *dst, int status)
{
    Octstr *sql, *os_status, *like;
    DBPoolConn *pconn;
    List *binds = gwlist_create();
    int res;

    debug("dlr.mysql", 0, "updating DLR status in database");

    pconn = dbpool_conn_consume(pool);
    /* just for sure */
    if (pconn == NULL)
        return;

    if (dst)
        like = octstr_format("AND `%S` LIKE CONCAT('%%', ?)", fields->field_dst);
    else
        like = octstr_imm("");

    sql = octstr_format("UPDATE `%S` SET `%S`=? WHERE `%S`=? AND `%S`=? %S LIMIT 1",
                        fields->table, fields->field_status,
                        fields->field_smsc, fields->field_ts,
                        like);

    os_status = octstr_format("%d", status);
    gwlist_append(binds, (Octstr *)os_status);
    gwlist_append(binds, (Octstr *)smsc);
    gwlist_append(binds, (Octstr *)ts);
    if (dst)
        gwlist_append(binds, (Octstr *)dst);

#if defined(DLR_TRACE)
    debug("dlr.mysql", 0, "sql: %s", octstr_get_cstr(sql));
#endif
    if ((res = dbpool_conn_update(pconn, sql, binds)) == -1)
        error(0, "DLR: MYSQL: Error while updating dlr entry for DST<%s>", octstr_get_cstr(dst));
    else if (!res)
       warning(0, "DLR: MYSQL: No dlr found to update for DST<%s>, (status %d)", octstr_get_cstr(dst), status);

    dbpool_conn_produce(pconn);
    gwlist_destroy(binds, NULL);
    octstr_destroy(os_status);
    octstr_destroy(sql);
    octstr_destroy(like);
}
コード例 #12
0
ファイル: mms_cfg.c プロジェクト: markjeee/mbuni
List *mms_cfg_get_multi(mCfg *cfg, Octstr *name)
{
     
     gw_assert(name);         
     gw_assert(is_multigroup(name) == 1);
     
     if (cfg->xcfg == NULL) {
	  List *l = NULL, *r;
	  int i;	  
	  r = dict_get(cfg->grps, name);
	  
	  if (r)
	       for (i = 0, l = gwlist_create(); i < gwlist_len(r); i++)
		    gwlist_append(l, gwlist_get(r,i));	  
	  return l;
     } else 
	  return cfg->cfg_funcs->get_multi(cfg->xcfg, name);
}
コード例 #13
0
ファイル: dlr_sqlite3.c プロジェクト: pwhelan/kannel
static void dlr_update_sqlite3(const Octstr *smsc, const Octstr *ts, const Octstr *dst, int status)
{
    Octstr *sql, *os_status, *like;
    DBPoolConn *pconn;
    List *binds = gwlist_create();
    int res;

    debug("dlr.sqlite3", 0, "updating DLR status in database");

    pconn = dbpool_conn_consume(pool);
    /* just for sure */
    if (pconn == NULL)
        return;

    if (dst)
        like = octstr_format("AND %S LIKE '%?4'", fields->field_dst);
    else
        like = octstr_imm("");

    sql = octstr_format("UPDATE %S SET %S=?1 WHERE ROWID IN (SELECT ROWID FROM %S WHERE %S=?2 AND %S=?3 %S LIMIT 1)",
                        fields->table, fields->field_status, fields->table,
                        fields->field_smsc, fields->field_ts, fields->field_dst);

    os_status = octstr_format("%d", status);
    gwlist_append(binds, (Octstr *)os_status); /* ?1 */
    gwlist_append(binds, (Octstr *)smsc);      /* ?2 */
    gwlist_append(binds, (Octstr *)ts);        /* ?3 */
    if (dst)
        gwlist_append(binds, (Octstr *)dst);   /* ?4 */
    
#if defined(DLR_TRACE)
    debug("dlr.sqlite3", 0, "sql: %s", octstr_get_cstr(sql));
#endif
    if ((res = dbpool_conn_update(pconn, sql, binds)) == -1)
        error(0, "DLR: SQLite3: Error while updating dlr entry for DST<%s>", octstr_get_cstr(dst));
    else if (!res)
        warning(0, "DLR: SQLite3: No dlr found to update for DST<%s> (status: %d)", octstr_get_cstr(dst), status);

    dbpool_conn_produce(pconn);
    gwlist_destroy(binds, NULL);
    octstr_destroy(os_status);
    octstr_destroy(sql);
    octstr_destroy(like);
}
コード例 #14
0
ファイル: check_list.c プロジェクト: frese/mbuni
static void main_for_extract(void) {
	static char *items[] = {
		"one",
		"two",
		"three",
	};
	int num_items = sizeof(items) / sizeof(items[0]);
	int num_repeats = 3;
	int i, j;
	char *p;
	List *list, *extracted;

	list = gwlist_create();
	
	for (j = 0; j < num_repeats; ++j)
		for (i = 0; i < num_items; ++i)
			gwlist_append(list, items[i]);

	for (j = 0; j < num_items; ++j) {
		extracted = gwlist_extract_matching(list, items[j], 
					compare_cstr);
		if (extracted == NULL)
			panic(0, "no extracted elements, should have!");
		for (i = 0; i < gwlist_len(list); ++i) {
			p = gwlist_get(list, i);
			if (strcmp(p, items[j]) == 0)
				panic(0, "list contains `%s' after "
				         "extracting it!",
					items[j]);
		}
		for (i = 0; i < gwlist_len(extracted); ++i) {
			p = gwlist_get(extracted, i);
			if (strcmp(p, items[j]) != 0)
				panic(0, 
				  "extraction returned wrong element!");
		}
		gwlist_destroy(extracted, NULL);
	}
	
	if (gwlist_len(list) != 0)
		panic(0, "list is not empty after extracting everything");
	
	gwlist_destroy(list, NULL);
}
コード例 #15
0
ファイル: dlr_redis.c プロジェクト: Jayriq/kannel-gateway
static void dlr_redis_update(const Octstr *smsc, const Octstr *ts, const Octstr *dst, int status)
{
    Octstr *key, *sql, *os_status;
    DBPoolConn *pconn;
    List *binds = gwlist_create();
    int res;

    debug("dlr.redis", 0, "Updating DLR status in keystore");

    pconn = dbpool_conn_consume(pool);
    /* just for sure */
    if (pconn == NULL) {
        error(0, "DLR: REDIS: No connection available");
        gwlist_destroy(binds, NULL);
        return;
    }

    os_status = octstr_format("%d", status);

    key = octstr_format((dst ? "%S:?:?:?" : "%S:?:?"), fields->table);

    sql = octstr_format("HSET %S %S ?", key, fields->field_status);
    gwlist_append(binds, (Octstr*)smsc);
    gwlist_append(binds, (Octstr*)ts);
    if (dst != NULL)
        gwlist_append(binds, (Octstr*)dst);
    gwlist_append(binds, os_status);

    if ((res = dbpool_conn_update(pconn, sql, binds)) == -1) {
        error(0, "DLR: REDIS: Error while updating dlr entry for %s",
              octstr_get_cstr(key));
    }
    else if (!res) {
        warning(0, "DLR: REDIS: No dlr found to update for %s",
                octstr_get_cstr(key));
    }

    dbpool_conn_produce(pconn);
    octstr_destroy(os_status);
    octstr_destroy(key);
    octstr_destroy(sql);
    gwlist_destroy(binds, NULL);
}
コード例 #16
0
void gwthread_join(long thread)
{
    struct threadinfo *threadinfo;
    pthread_cond_t exit_cond;
    int ret;

    gw_assert(thread >= 0);

    lock();
    threadinfo = THREAD(thread);
    if (threadinfo == NULL || threadinfo->number != thread) {
        /* The other thread has already exited */
        unlock();
        return;
    }

    /* Register our desire to be alerted when that thread exits,
     * and wait for it. */

    ret = pthread_cond_init(&exit_cond, NULL);
    if (ret != 0) {
        warning(ret, "gwthread_join: cannot create condition variable.");
        unlock();
        return;
    }

    if (!threadinfo->joiners)
        threadinfo->joiners = gwlist_create();
    gwlist_append(threadinfo->joiners, &exit_cond);

    /* The wait immediately releases the lock, and reacquires it
     * when the condition is satisfied.  So don't worry, we're not
     * blocking while keeping the table locked. */
    pthread_cleanup_push((void(*)(void*))pthread_mutex_unlock, &threadtable_lock);
    ret = pthread_cond_wait(&exit_cond, &threadtable_lock);
    pthread_cleanup_pop(0);
    unlock();

    if (ret != 0)
        warning(ret, "gwthread_join: error in pthread_cond_wait");

    pthread_cond_destroy(&exit_cond);
}
コード例 #17
0
ファイル: dlr_oracle.c プロジェクト: frese/mbuni
static void dlr_add_oracle(struct dlr_entry *entry)
{
    Octstr *sql, *os_mask;
    DBPoolConn *pconn;
    List *binds = gwlist_create();
    debug("dlr.oracle", 0, "adding DLR entry into database");

    pconn = dbpool_conn_consume(pool);
    /* just for sure */
    if (pconn == NULL) {
        dlr_entry_destroy(entry);
        return;
    }

    sql = octstr_format("INSERT INTO %S (%S, %S, %S, %S, %S, %S, %S, %S, %S) VALUES "
                        "(:1, :2, :3, :4, :5, :6, :7, :8, 0)",
                        fields->table, fields->field_smsc, fields->field_ts,
                        fields->field_src, fields->field_dst, fields->field_serv, 
                        fields->field_url, fields->field_mask, fields->field_boxc,
                        fields->field_status);
    os_mask = octstr_format("%d", entry->mask);
    
    gwlist_append(binds, entry->smsc);         /* :1 */
    gwlist_append(binds, entry->timestamp);    /* :2 */
    gwlist_append(binds, entry->source);       /* :3 */
    gwlist_append(binds, entry->destination);  /* :4 */
    gwlist_append(binds, entry->service);      /* :5 */
    gwlist_append(binds, entry->url);          /* :6 */
    gwlist_append(binds, os_mask);             /* :7 */
    gwlist_append(binds, entry->boxc_id);      /* :8 */
#if defined(DLR_TRACE)
    debug("dlr.oracle", 0, "sql: %s", octstr_get_cstr(sql));
#endif
    if (dbpool_conn_update(pconn, sql, binds) == -1)
        error(0, "DLR: ORACLE: Error while adding dlr entry for DST<%s>", octstr_get_cstr(entry->destination));

    dbpool_conn_produce(pconn);
    octstr_destroy(sql);
    gwlist_destroy(binds, NULL);
    octstr_destroy(os_mask);
    dlr_entry_destroy(entry);
}
コード例 #18
0
ファイル: mms_mmbox.c プロジェクト: frese/mbuni
static List *make_mm_flags(List *oflags, List *flag_cmds)
{
     List *l = oflags ? oflags : gwlist_create();
     int i, n;

     for (i = 0, n = gwlist_len(l); i < n; i++) { /* cleanup list. */
	  Octstr *x = gwlist_get(l,i);
	  int ch = octstr_get_char(x, 0);
	  
	  if (ch == '+' || ch == '-' || ch == '/')
	       octstr_delete(x,0,1);
     }
     
     for (i = 0, n = (flag_cmds ? gwlist_len(flag_cmds) : 0); i<n; i++) {
	  Octstr *x = gwlist_get(flag_cmds,i);
	  int ch = octstr_get_char(x, 0);
	  char *s = octstr_get_cstr(x);
	  int j, m, cmd;
	  
	  if (ch == '+' || ch == '-' || ch == '/') {
	       s++;
	       cmd = ch;
	  } else 
	       cmd = '+';
	  
	  /* Find it in original. If existent, remove it. */
	  for (j = 0, m = gwlist_len(l); j < m; j++) 
	       if (octstr_str_compare(gwlist_get(l,j),s) == 0)  { 
		    Octstr *y = gwlist_get(l,j);
		    gwlist_delete(l,j,1);
		    octstr_destroy(y);
		    j--;
		    m--;
	       } 
	  
	  if (cmd == '+' || cmd == '/')
	       gwlist_append(l, octstr_create(s));
     }     


     return l;
}
コード例 #19
0
ファイル: parse.c プロジェクト: Phonebooth/kannel
int parse_limit(ParseContext *context, long length)
{
    long *elem;

    gw_assert(context != NULL);

    if (context->pos + length > context->limit) {
        context->error = 1;
        return -1;
    }

    if (context->limit_stack == NULL)
        context->limit_stack = gwlist_create();

    elem = gw_malloc(sizeof(*elem));
    *elem = context->limit;
    gwlist_insert(context->limit_stack, 0, elem);
    context->limit = context->pos + length;
    return 0;
}
コード例 #20
0
ファイル: bb_boxc.c プロジェクト: Phonebooth/kannel
int wapbox_start(Cfg *cfg)
{
    CfgGroup *grp;

    if (wapbox_running) return -1;

    debug("bb", 0, "starting wapbox connection module");
    
    grp = cfg_get_single_group(cfg, octstr_imm("core"));
    
    if (cfg_get_integer(&wapbox_port, grp, octstr_imm("wapbox-port")) == -1) {
	    error(0, "Missing wapbox-port variable, cannot start WAP");
	    return -1;
    }
#ifdef HAVE_LIBSSL
    cfg_get_bool(&wapbox_port_ssl, grp, octstr_imm("wapbox-port-ssl"));
#endif /* HAVE_LIBSSL */
  
    box_allow_ip = cfg_get(grp, octstr_imm("box-allow-ip"));
    if (box_allow_ip == NULL)
    	box_allow_ip = octstr_create("");
    box_deny_ip = cfg_get(grp, octstr_imm("box-deny-ip"));
    if (box_deny_ip == NULL)
    	box_deny_ip = octstr_create("");
    if (box_allow_ip != NULL && box_deny_ip == NULL)
	    info(0, "Box connection allowed IPs defined without any denied...");
    
    wapbox_list = gwlist_create();	/* have a list of connections */
    gwlist_add_producer(outgoing_wdp);
    if (!boxid)
        boxid = counter_create();

    if (gwthread_create(wdp_to_wapboxes, NULL) == -1)
 	    panic(0, "Failed to start a new thread for wapbox routing");
 
    if (gwthread_create(wapboxc_run, &wapbox_port) == -1)
	    panic(0, "Failed to start a new thread for wapbox connections");

    wapbox_running = 1;
    return 0;
}
コード例 #21
0
void gwthread_join_every(gwthread_func_t *func)
{
    struct threadinfo *ti;
    pthread_cond_t exit_cond;
    int ret;
    long i;

    ret = pthread_cond_init(&exit_cond, NULL);
    if (ret != 0) {
        warning(ret, "gwthread_join_every: cannot create condition variable.");
        unlock();
        return;
    }

    /*
     * FIXME: To be really safe, this function should keep looping
     * over the table until it does a complete run without having
     * to call pthread_cond_wait.  Otherwise, new threads could
     * start while we wait, and we'll miss them.
     */
    lock();
    for (i = 0; i < THREADTABLE_SIZE; ++i) {
        ti = THREAD(i);
        if (ti == NULL || ti->func != func)
            continue;
        debug("gwlib.gwthread", 0,
              "Waiting for %ld (%s) to terminate",
              ti->number, ti->name);
        if (!ti->joiners)
            ti->joiners = gwlist_create();
        gwlist_append(ti->joiners, &exit_cond);
        pthread_cleanup_push((void(*)(void*))pthread_mutex_unlock, &threadtable_lock);
        ret = pthread_cond_wait(&exit_cond, &threadtable_lock);
        pthread_cleanup_pop(0);
        if (ret != 0)
            warning(ret, "gwthread_join_all: error in pthread_cond_wait");
    }
    unlock();

    pthread_cond_destroy(&exit_cond);
}
コード例 #22
0
ファイル: dlr_sqlite3.c プロジェクト: pwhelan/kannel
static void dlr_remove_sqlite3(const Octstr *smsc, const Octstr *ts, const Octstr *dst)
{
    Octstr *sql, *like;
    DBPoolConn *pconn;
    List *binds = gwlist_create();
    int res;
    debug("dlr.sqlite3", 0, "removing DLR from database");

    pconn = dbpool_conn_consume(pool);
    /* just for sure */
    if (pconn == NULL)
        return;
    
    if (dst)
        like = octstr_format("AND %S LIKE '%?3'", fields->field_dst);
    else
        like = octstr_imm("");

    sql = octstr_format("DELETE FROM %S WHERE ROWID IN (SELECT ROWID FROM %S WHERE %S=?1 AND %S=?2 %S LIMIT 1)",
                        fields->table, fields->table,
                        fields->field_smsc, fields->field_ts, like);

    gwlist_append(binds, (Octstr *)smsc);      /* ?1 */
    gwlist_append(binds, (Octstr *)ts);        /* ?2 */
    if (dst)
        gwlist_append(binds, (Octstr *)dst);   /* ?3 */

#if defined(DLR_TRACE)
    debug("dlr.sqlite3", 0, "sql: %s", octstr_get_cstr(sql));
#endif

    if ((res = dbpool_conn_update(pconn, sql, binds)) == -1)
        error(0, "DLR: SQLite3: Error while removing dlr entry for DST<%s>", octstr_get_cstr(dst));
    else if (!res)
        warning(0, "DLR: SQLite3: No dlr deleted for DST<%s>", octstr_get_cstr(dst));

    dbpool_conn_produce(pconn);
    gwlist_destroy(binds, NULL);
    octstr_destroy(sql);
    octstr_destroy(like);
}
コード例 #23
0
ファイル: semaphore.c プロジェクト: dimimpou/gwlib
Semaphore *semaphore_create(long n)
{
    Semaphore *semaphore;
#ifndef HAVE_SEMAPHORE
    static char item;
#endif
    
    semaphore = gw_malloc(sizeof(*semaphore));

#ifdef HAVE_SEMAPHORE
    if (sem_init(&semaphore->sem, 0, (unsigned int) n) != 0)
        panic(errno, "Could not initialize semaphore.");
#else
    semaphore->list = gwlist_create();
    gwlist_add_producer(semaphore->list);
    while (n-- > 0)
	gwlist_produce(semaphore->list, &item);
#endif

    return semaphore;
}
コード例 #24
0
ファイル: wap-maps.c プロジェクト: tphipps/kannel
void wap_map_add_url(Octstr *name, Octstr *url, Octstr *map_url,
                     Octstr *send_msisdn_query,
                     Octstr *send_msisdn_header,
                     Octstr *send_msisdn_format,
                     int accept_cookies) {
    struct url_map_struct *entry;

    if (url_map == NULL) 
        url_map = gwlist_create();

    entry = gw_malloc(sizeof(*entry));
    entry->name = name;
    entry->url = url;
    entry->map_url = map_url;
    entry->send_msisdn_query = send_msisdn_query;
    entry->send_msisdn_header = send_msisdn_header;
    entry->send_msisdn_format = send_msisdn_format;
    entry->accept_cookies = accept_cookies;
    
    gwlist_append(url_map, entry);
}
コード例 #25
0
ファイル: drive_wapbox.c プロジェクト: Phonebooth/kannel
static void http_thread(void *arg) {
	HTTPClient *client;
	Octstr *ip;
	Octstr *url;
	List *headers;
	Octstr *body;
	List *cgivars;
	Octstr *reply_body = octstr_create(
		"<?xml version=\"1.0\"?>\n"
		"<!DOCTYPE wml PUBLIC \"-//WAPFORUM//DTD WML 1.1//EN\"\n"
		" \"http://www.wapforum.org/DTD/wml_1.1.xml\">\n"
		"<wml>\n"
		"<card id=\"main\" title=\"Hello, world\" newcontext=\"true\">\n"
		"        <p>Hello, world.</p>\n"
		"</card></wml>\n");
	List *reply_headers = gwlist_create();
	int port;

    	port = *(int *) arg;
	gw_free(arg);

	gwlist_append(reply_headers,
		octstr_create("Content-Type: text/vnd.wap.wml"));

	for (;!dying;) {
		client = http_accept_request(port, &ip, &url, &headers, 
		    	    	    	     &body, &cgivars);
		if (client == NULL)
			break;
		http_send_reply(client, HTTP_OK, reply_headers, reply_body);
		http_destroy_headers(headers);
		octstr_destroy(ip);
		octstr_destroy(url);
		octstr_destroy(body);
		http_destroy_cgiargs(cgivars);
	}

	octstr_destroy(reply_body);
    	http_destroy_headers(reply_headers);
}
コード例 #26
0
static void split_headers(Octstr *headers, List **split)
{
    long start;
    long pos;

    *split = gwlist_create();
    start = 0;
    for (pos = 0; pos < octstr_len(headers); pos++) {
        if (octstr_get_char(headers, pos) == '\n') {
            Octstr *line;

            if (pos == start) {
                /* Skip empty lines */
                start = pos + 1;
                continue;
            }
            line = octstr_copy(headers, start, pos - start);
            start = pos + 1;
            gwlist_append(*split, line);
        }
    }
}
コード例 #27
0
ファイル: wtls_pdu.c プロジェクト: frese/mbuni
/* This function will unpack an Octstr and return a list of all PDUs contained
   within that Octstr. If the contents of the packet are garbled in some fashion,
   and one packet fails to be decoded correctly, we will continue regardless, and
   a partial list will be returned. NULL is returned if no PDUs can be successfully
   decoded from the supplied data */
List* wtls_unpack_payloadlist (Octstr *data) {

        List* payloadlist = NULL;
        int offset = 0;
        int dataLength = 0;
        wtls_Payload* tempPayload;
        
        /* Has somebody passed in an unpack of a null pointer ? */
        gw_assert(data != NULL);
        
        /* Initialise our list */
        payloadlist = gwlist_create();
        dataLength = octstr_len(data);
        
        /* While offset is less than the size of the data */
        while( offset < dataLength) {

                debug("wtls:wtls_unpack_payloadlist",0,"Offset is now : %d", offset);
                /* Unpack from the supplied offset. This will bump up the value of offset */
                tempPayload = wtls_payload_unpack_from_offset (data, &offset);
                
                /* If the packet returned is not NULL */
                if (tempPayload != NULL) {
                        /* Add the returned packet to the current list of packets */
                        gwlist_append(payloadlist, (void*) tempPayload);
                }
        }

        debug("wtls:wtls_unpack_payloadlist",0,"Finished, found %d PDUs", gwlist_len(payloadlist));
        
        /* If the length of the list is greater than 0 */
        if (gwlist_len(payloadlist) > 0) {
                /* Return the List */
                return payloadlist;
        }
        
        /* Otherwise return NULL */
        return NULL;
}
コード例 #28
0
int main(void)
{
    List *list;
    char id[UUID_STR_LEN + 1];
    int i;
     
    gwlib_init();

    debug("",0,"List performance test.");
    list = gwlist_create();
        
    /* generate UUIDs and populate the list */
    debug("", 0, "Creating %d UUIDs for the list.", HUGE_SIZE);
    for (i = 0; i < HUGE_SIZE; i++) {
        Octstr *os;
        uuid_t uid;
        uuid_generate(uid);
        uuid_unparse(uid, id);
        os = octstr_create(id);
        gwlist_append(list, os);
        uuid_clear(uid);
    }
    debug("",0,"Objects in the list: %ld", gwlist_len(list));

    /* try to sort */
    debug("",0,"Sorting.");
    gwlist_sort(list, my_sort_cmp);
    debug("",0,"Sorting done.");
    for (i = 0; i < HUGE_SIZE; i++) {
        Octstr *os = gwlist_get(list, i);
        debug("",0,"After sort: %s %d", octstr_get_cstr(os), i);
    }       
    
    gwlist_destroy(list, octstr_destroy_item);

    gwlib_shutdown();
    return 0;
}
コード例 #29
0
ファイル: list.c プロジェクト: LeeVidor/kannel-mongodb
List *gwlist_extract_matching(List *list, void *pat, gwlist_item_matches_t *cmp)
{
    List *new_list;
    long i;

    new_list = gwlist_create();
    lock(list);
    i = 0;
    while (i < list->len) {
        if (cmp(GET(list, i), pat)) {
            gwlist_append(new_list, GET(list, i));
            delete_items_from_list(list, i, 1);
        } else
            ++i;
    }
    unlock(list);

    if (gwlist_len(new_list) == 0) {
        gwlist_destroy(new_list, NULL);
        return NULL;
    }
    return new_list;
}
コード例 #30
0
ファイル: urltrans.c プロジェクト: gburiticato/kannel
int urltrans_add_one(URLTranslationList *trans, CfgGroup *grp)
{
    URLTranslation *ot;
    List *list2;
    
    ot = create_onetrans(grp);
    if (ot == NULL)
	return -1;

    if (ot->type != TRANSTYPE_SENDSMS && ot->keyword_regex == NULL)
        gwlist_append(trans->defaults, ot);
    else 
        gwlist_append(trans->list, ot);
    
    list2 = dict_get(trans->names, ot->name);
    if (list2 == NULL) {
    	list2 = gwlist_create();
	dict_put(trans->names, ot->name, list2);
    }
    gwlist_append(list2, ot);

    return 0;
}