Пример #1
0
static void oracle_client_thread(void *arg)
{
    DBPool *pool = arg;
    DBPoolConn *pconn = NULL;
    int i;
    List *result;

    for (i = 1; i <= queries; i++) {
        pconn = dbpool_conn_consume(pool);

        if (pconn == NULL)
            continue;
#if 1 /* selects */
        if (dbpool_conn_select(pconn, sql, NULL, &result) == 0) {
            long i,j;
            for (i=0; i < gwlist_len(result); i++) {
                List *row = gwlist_get(result, i);
                for (j=0; j < gwlist_len(row); j++)
                    debug("", 0, "col = %ld   value = '%s'", j, octstr_get_cstr(gwlist_get(row,j)));
                gwlist_destroy(row, octstr_destroy_item);
            }
        }
        gwlist_destroy(result, NULL);
        dbpool_conn_produce(pconn);
#else /* only updates */
        debug("", 0, "rows processed = %d ", dbpool_conn_update(pconn, sql, NULL));
        dbpool_conn_produce(pconn);
#endif
    }
}
Пример #2
0
static void wtp_event_dump(Msg *msg)
{
    WAPEvent *dgram;
    List *events;
    long i, n;

    dgram = wdp_msg2event(msg);
    if (dgram == NULL)
        error(0, "dgram is null");

    /*
    pdu = wtp_pdu_unpack(dgram->u.T_DUnitdata_Ind.user_data);
    if (pdu == NULL) {
        error(0, "WTP PDU unpacking failed, WAP event is:");
        wap_event_dump(dgram);
    } else {
        wtp_pdu_dump(pdu, 0);
        wtp_pdu_destroy(pdu);
    }
    */

    events = wtp_unpack_wdp_datagram(dgram);
    n = gwlist_len(events);
    debug("wap.proxy",0,"datagram contains %ld events", n);

    i = 1;
    while (gwlist_len(events) > 0) {
        WAPEvent *event;

	    event = gwlist_extract_first(events);
        
        info(0, "WTP: %ld/%ld event %s.", i, n, wap_event_name(event->type));

        if (wtp_event_is_for_responder(event))
            /* wtp_resp_dispatch_event(event); */
            debug("",0,"datagram is for WTP responder");
        else
            /* wtp_initiator_dispatch_event(event); */
            debug("",0,"datagram is for WTP initiator");
 
        wap_event_dump(event);
        /*
        switch (event->type) {
            RcvInvoke:
                debug("",0,"XXX invoke");
                break;
            RcvResult:
                debug("",0,"XXX result");
                break;
            default:
                error(0,"unkown WTP event type while unpacking");
                break;
        }
        */
        i++;
    }   		

    wap_event_destroy(dgram);
    gwlist_destroy(events, NULL);
}
Пример #3
0
Файл: mime.c Проект: frese/mbuni
/*
 * Read some headers, i.e., until the first empty line (read and discard
 * the empty line as well). Return -1 for error, 0 for all headers read.
 */
static int read_mime_headers(ParseContext *context, List *headers)
{
    Octstr *line, *prev;

    if (gwlist_len(headers) == 0)
        prev = NULL;
    else
        prev = gwlist_get(headers, gwlist_len(headers) - 1);

    for (;;) {
        line = parse_get_line(context);
        if (line == NULL) {
	    	return -1;
        }
        if (octstr_len(line) == 0) {
            octstr_destroy(line);
            break;
        }
        if (isspace(octstr_get_char(line, 0)) && prev != NULL) {
            octstr_append(prev, line);
            octstr_destroy(line);
        } else {
            gwlist_append(headers, line);
            prev = line;
        }
    }

    return 0;
}
Пример #4
0
static void main_for_list_add_and_delete(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;

	list = gwlist_create();
	
	for (j = 0; j < num_repeats; ++j)
		for (i = 0; i < num_items; ++i)
			gwlist_append(list, items[i]);
	gwlist_delete_matching(list, items[0], compare_cstr);
	for (i = 0; i < gwlist_len(list); ++i) {
		p = gwlist_get(list, i);
		if (strcmp(p, items[0]) == 0)
			panic(0, "list contains `%s' after deleting it!",
				items[0]);
	}
	
	for (i = 0; i < num_items; ++i)
		gwlist_delete_equal(list, items[i]);
	if (gwlist_len(list) != 0)
		panic(0, "list is not empty after deleting everything");
	
	gwlist_destroy(list, NULL);
}
Пример #5
0
static void expire_cookies(List *cookies)
{
	Cookie *value = NULL;
	time_t now = 0;
	long pos = 0;

	if (cookies == NULL) {
		error(0, "expire_cookies: Null argument(s) - no Cookie list");
		return;
	}

	/* Walk through the cookie cache */

	time(&now);

	if (gwlist_len(cookies) > 0) {
		debug("wap.wsp.http", 0, "expire_cookies: Cookies in cache");
		for (pos = 0; pos < gwlist_len(cookies); pos++) {
			value = gwlist_get(cookies, pos);
			gw_assert(value != NULL);

			if (value->max_age != -1) {		/* Interesting value */
				if (value->max_age + value->birth < now) {
					debug("wap.wsp.http", 0, "expire_cookies: Expired cookie (%s)",
						  octstr_get_cstr(value->name));
					cookie_destroy(value);
					gwlist_delete(cookies, pos, 1);
				}
			}
		}
	} else
		debug("wap.wsp.http", 0, "expire_cookies: No cookies in cache");

	return;
}
Пример #6
0
void mms_cfg_destroy(mCfg *cfg)
{
     List *l;
     int i, n;

     gw_assert(cfg);
     
     for (i = 0, l  = dict_keys(cfg->grps), n = gwlist_len(l); i < n; i++) {
	  Octstr *grpname = gwlist_get(l, i);
	  void *val = dict_get(cfg->grps, grpname);
	  if (is_multigroup(grpname)) { /* item is a list. */
	       List *gl = val;	  
	       int j, m = gwlist_len(gl);	       
	       for (j = 0; j < m; j++)
		    mGrp_destroy(gwlist_get(gl, j));
	       gwlist_destroy(gl, NULL);
	  } else 
	       mGrp_destroy(val);	  
     }
     gwlist_destroy(l, (gwlist_item_destructor_t *)octstr_destroy);
     dict_destroy(cfg->grps);
     octstr_destroy(cfg->file);
     
     if (cfg->xcfg && cfg->cfg_funcs && 
	 cfg->cfg_funcs->destroy)
	  cfg->cfg_funcs->destroy(cfg->xcfg);
     
     gw_free(cfg);
}
Пример #7
0
static void destroy_pushmachines(List *machines) {
	if (gwlist_len(machines) > 0) {
		warning(0, "Destroying WSP session with %ld active pushes\n",
			gwlist_len(machines));
	}

	gwlist_destroy(machines, push_machine_destroy);
}
Пример #8
0
static void destroy_methodmachines(List *machines) {
	if (gwlist_len(machines) > 0) {
		warning(0, "Destroying WSP session with %ld active methods\n",
			gwlist_len(machines));
	}

	gwlist_destroy(machines, method_machine_destroy);
}
Пример #9
0
/* Counts the number of elements produced to any deliver threads (live elements)
 * Used to control how many new queueings to accept.
 * Each of these may use upto 3 filehandles
 * - One for the qf
 * - One for the df file
 * - Delivery notification file
 * Does sockets count as filehandles?
 */
static int mms_queue_live_count() {
	int i,j,count = 0;
	static struct Qthread_t *tlist;
	List *queue_run_thread_groups = dict_keys(tlists);

	for (i = 0; i < gwlist_len(queue_run_thread_groups); i++) {
		tlist = dict_get(tlists, gwlist_get(queue_run_thread_groups, i));
		for (j = 0; j < number_of_threads; j++)
			count += gwlist_len(tlist[j].l);
	}
	gwlist_destroy(queue_run_thread_groups, octstr_destroy_item);

	return count;
}
Пример #10
0
void wsp_cap_dump_list(List *caps_list) {
	long i;

	if (caps_list == NULL) {
		debug("wsp", 0, "NULL capability list");
		return;
	}
	debug("wsp", 0, "Dumping capability list at %p, length %ld",
		caps_list, gwlist_len(caps_list));
	for (i = 0; i < gwlist_len(caps_list); i++) {
		wsp_cap_dump(gwlist_get(caps_list, i));
	}
	debug("wsp", 0, "End of capability list dump");
}
Пример #11
0
/*
 * this thread listens to incoming_wdp list
 * and then routs messages to proper wapbox
 */
static void wdp_to_wapboxes(void *arg)
{
    List *route_info;
    AddrPar *ap;
    Boxc *conn;
    Msg *msg;
    int i;

    gwlist_add_producer(flow_threads);
    gwlist_add_producer(wapbox_list);

    route_info = gwlist_create();

    
    while(bb_status != BB_DEAD) {

	    gwlist_consume(suspended);	/* block here if suspended */

	    if ((msg = gwlist_consume(incoming_wdp)) == NULL)
	         break;

	    gw_assert(msg_type(msg) == wdp_datagram);

	    conn = route_msg(route_info, msg);
	    if (conn == NULL) {
	        warning(0, "Cannot route message, discard it");
	        msg_destroy(msg);
	        continue;
	    }
	    gwlist_produce(conn->incoming, msg);
    }
    debug("bb", 0, "wdp_to_wapboxes: destroying lists");
    while((ap = gwlist_extract_first(route_info)) != NULL)
	ap_destroy(ap);

    gw_assert(gwlist_len(route_info) == 0);
    gwlist_destroy(route_info, NULL);

    gwlist_lock(wapbox_list);
    for(i=0; i < gwlist_len(wapbox_list); i++) {
	    conn = gwlist_get(wapbox_list, i);
	    gwlist_remove_producer(conn->incoming);
	    conn->alive = 0;
    }
    gwlist_unlock(wapbox_list);

    gwlist_remove_producer(wapbox_list);
    gwlist_remove_producer(flow_threads);
}
Пример #12
0
int boxc_incoming_wdp_queue(void)
{
    int i, q = 0;
    Boxc *boxc;
    
    if (wapbox_list) {
	    gwlist_lock(wapbox_list);
	    for(i=0; i < gwlist_len(wapbox_list); i++) {
	        boxc = gwlist_get(wapbox_list, i);
	        q += gwlist_len(boxc->incoming);
	    }
	    gwlist_unlock(wapbox_list);
    }
    return q;
}
Пример #13
0
/*
 * Parse a line in the format: <name=value name=value ...>
 * and return a Dict with the name as key and the value as value,
 * otherwise return NULL if a parsing error occures.
 */
static Dict *brunet_parse_body(Octstr *body)
{
    Dict *param = NULL;
    List *words = NULL;
    long len;
    Octstr *word;

    words = octstr_split_words(body);
    if ((len = gwlist_len(words)) > 0) {
        param = dict_create(4, (void(*)(void *)) octstr_destroy);
        while ((word = gwlist_extract_first(words)) != NULL) {
            List *l = octstr_split(word, octstr_imm("="));
            Octstr *key = gwlist_extract_first(l);
            Octstr *value = gwlist_extract_first(l);
            if (octstr_len(key))
                dict_put(param, key, value);
            octstr_destroy(key);
            octstr_destroy(word);
            gwlist_destroy(l, (void(*)(void *)) octstr_destroy);
        }
    }
    gwlist_destroy(words, (void(*)(void *)) octstr_destroy);

    return param;
}
Пример #14
0
mCfgGrp *mms_get_multi_by_field(mCfg *cfg, Octstr *name, Octstr *field, Octstr *value)
{

     gw_assert(name);         
     gw_assert(is_multigroup(name) == 1);
     
     if (!valid_in_group(name, field))
	  panic(0, "Request for invalid field/variable `%s' in group `%s', unexpected!",
		octstr_get_cstr(field), octstr_get_cstr(name));

     if (cfg->xcfg == NULL) {
	  mCfgGrp *grp;
	  Octstr *val;
	  List *r;
	  int i;	  
	  r = dict_get(cfg->grps, name);     
	  if (r)
	       for (i = 0; i < gwlist_len(r); i++)
		    if ((grp = gwlist_get(r, i)) != NULL && 
			(val = dict_get(grp->fields, field)) != NULL &&
			octstr_compare(val, value) == 0)
			 return grp;     
	  return NULL;
     } else 
	  return cfg->cfg_funcs->get_multi_by_field(cfg->xcfg, name, field, value);

}
Пример #15
0
/* get_matching_translations - iterate over all translations in trans. 
 * for each translation check whether 
 * the translation's keyword has already been interpreted as a regexp. 
 * if not, compile it now,
 * otherwise retrieve compilation result from dictionary.
 *
 * the translations where the word matches the translation's pattern 
 * are returned in a list
 * 
 */
static List *get_matching_translations(URLTranslationList *trans, Octstr *msg) 
{
    List *list;
    long i;
    URLTranslation *t;

    gw_assert(trans != NULL && msg != NULL);

    list = gwlist_create();
    for (i = 0; i < gwlist_len(trans->list); ++i) {
        t = gwlist_get(trans->list, i);
        
        if (t->keyword_regex == NULL)
            continue;

        if (gw_regex_match_pre(t->keyword_regex, msg) == 1) {
            debug("", 0, "match found: %s", octstr_get_cstr(t->name));
            gwlist_append(list, t);
        } else {
            debug("", 0, "no match found: %s", octstr_get_cstr(t->name));
        }
    }

    return list;
}
Пример #16
0
int udp_outgoing_queue(void)
{
    int i, q = 0;
    Udpc *udpc;

    if (!udp_running || udpc_list == NULL)
	return 0;

    gwlist_lock(udpc_list);
    for (i=0; i < gwlist_len(udpc_list); i++) {
	udpc = gwlist_get(udpc_list, i);
	q += gwlist_len(udpc->outgoing_list);
    }
    gwlist_unlock(udpc_list);
    return q;
}
Пример #17
0
static int do_dump(void)
{
    Octstr *key;
    Msg *msg;
    List *sms_list;
    long l;

    if (filename == NULL)
        return 0;

    /* create a new store-file and save all non-acknowledged
     * messages into it
     */
    if (open_file(newfile)==-1)
        return -1;

    sms_list = dict_keys(sms_dict);
    for (l=0; l < gwlist_len(sms_list); l++) {
        key = gwlist_get(sms_list, l);
        msg = dict_get(sms_dict, key);
        if (msg != NULL)
            write_msg(msg);
    }
    fflush(file);
    gwlist_destroy(sms_list, octstr_destroy_item);

    /* rename old storefile as .bak, and then new as regular file
     * without .new ending */

    return rename_store();
}
Пример #18
0
static long dlr_redis_messages(void)
{
    List *result, *row;
    DBPoolConn *conn;
    long msgs = -1;

    conn = dbpool_conn_consume(pool);
    if (conn == NULL)
        return -1;

    if (dbpool_conn_select(conn, octstr_imm("DBSIZE"), NULL, &result) != 0) {
        dbpool_conn_produce(conn);
        return 0;
    }

    dbpool_conn_produce(conn);

    if (gwlist_len(result) > 0) {
        row = gwlist_extract_first(result);
        msgs = atol(octstr_get_cstr(gwlist_get(row, 0)));
        gwlist_destroy(row, octstr_destroy_item);

        while ((row = gwlist_extract_first(result)) != NULL)
            gwlist_destroy(row, octstr_destroy_item);
    }
    gwlist_destroy(result, NULL);

    return msgs;
}
Пример #19
0
/*
 * Input: List of headers containing only X-Wap-Application-Id headers, values
 * being numeric application id codes. (Ppg module does coding of the header 
 * value part of the X-WAP-Application-Id header).
 * Output: Octstr containing them in a byte list (one id per byte). 
 *
 * Returns: Octstr containing headers, if succesfull, otherwise an empty 
 * octstr.
 */
static Octstr *pack_appid_list(List *headers)
{
    Octstr *appid_os,
           *header_name,
           *header_value;
    long i;
    size_t len;

    i = 0;
    appid_os = octstr_create("");
    len = (size_t) gwlist_len(headers);

    gw_assert(len);

    while (i < len) {
        http_header_get(headers, i, &header_name, &header_value);
        gw_assert(octstr_compare(header_name, 
                  octstr_imm("X-WAP-Application-Id")) == 0);
        octstr_format_append(appid_os, "%S", header_value);
        octstr_destroy(header_name);
        octstr_destroy(header_value);
        ++i;
    }
    
    return appid_os;
}
Пример #20
0
static WAPEvent *unpack_ack(WTP_PDU *pdu, WAPAddrTuple *addr_tuple)
{
    WAPEvent *event;
    WTP_TPI *tpi;
    int	i, num_tpis;

    event = wap_event_create(RcvAck);
    event->u.RcvAck.tid = pdu->u.Ack.tid;
    event->u.RcvAck.tid_ok = pdu->u.Ack.tidverify;
    event->u.RcvAck.rid = pdu->u.Ack.rid;
    event->u.RcvAck.addr_tuple = wap_addr_tuple_duplicate(addr_tuple);

    /* Set default to 0 because Ack on 1 piece message has no tpi */
    event->u.RcvAck.psn = 0;
    num_tpis = gwlist_len(pdu->options);

    for (i = 0; i < num_tpis; i++) {
        tpi = gwlist_get(pdu->options, i);
        if (tpi->type == TPI_PSN) {
            event->u.RcvAck.psn = octstr_get_bits(tpi->data,0,8);
            break;
        }
    }

    return event;
}
Пример #21
0
static void wtls_application(WAPEvent * event, WTLSMachine * wtls_machine)
{
   int listLen, i = 0;
   WAPEvent *dgram;
   wtls_Payload *payLoad;

   /* Apply the negotiated decryption/decoding/MAC check to the received data */
   /* Take the userdata and pass it on up to the WTP/WSP, depending on the destination port */

   listLen = gwlist_len(event->u.T_Unitdata_Ind.pdu_list);
   for (; i < listLen; i++) {
      payLoad = gwlist_consume(event->u.T_Unitdata_Ind.pdu_list);
      dgram = wap_event_create(T_DUnitdata_Ind);
      dgram->u.T_DUnitdata_Ind.addr_tuple =
          wap_addr_tuple_create(event->u.T_Unitdata_Ind.addr_tuple->
                 remote->address,
                 event->u.T_Unitdata_Ind.addr_tuple->
                 remote->port,
                 event->u.T_Unitdata_Ind.addr_tuple->
                 local->address,
                 event->u.T_Unitdata_Ind.addr_tuple->
                 local->port);
      dgram->u.T_DUnitdata_Ind.user_data = payLoad->data;
      wap_dispatch_datagram(dgram);
      payLoad->data = NULL;
      wtls_payload_destroy(payLoad);
   }
}
Пример #22
0
static void init_batch(Octstr *cfilename, Octstr *rfilename)
{
    Octstr *receivers;
    long lineno = 0; 

    content = octstr_read_file(octstr_get_cstr(cfilename)); 
    octstr_strip_crlfs(content);
    if (content == NULL) 
        panic(0,"Can not read content file `%s'.", 
              octstr_get_cstr(cfilename));
    info(0,"SMS-Text: <%s>", octstr_get_cstr(content));

    info(0,"Loading receiver list. This may take a while...");
    receivers = octstr_read_file(octstr_get_cstr(rfilename)); 
    if (receivers == NULL) 
        panic(0,"Can not read receivers file `%s'.", 
              octstr_get_cstr(rfilename)); 

    lines = octstr_split(receivers, octstr_imm("\n")); 
    lineno = gwlist_len(lines);
    if (lineno <= 0) 
        panic(0,"Receiver file seems empty!");

    info(0,"Receivers file `%s' contains %ld destination numbers.",
         octstr_get_cstr(rfilename), lineno);

    counter = counter_create();
}
Пример #23
0
static long pack_tpis(Octstr *data, long bitpos, List *tpis) {
	long length;
	WTP_TPI *tpi;
	int i;
	int num_tpis;

	num_tpis = gwlist_len(tpis);
	for (i = 0; i < num_tpis; i++) {
		tpi = gwlist_get(tpis, i);
		length = octstr_len(tpi->data);
		octstr_set_bits(data, bitpos, 1, i + 1 < num_tpis);
		octstr_set_bits(data, bitpos + 1, 4, tpi->type);
		if (length >= 4) {
			/* Long TPI */
			octstr_set_bits(data, bitpos + 5, 1, 1);
			octstr_set_bits(data, bitpos + 8, 8, length);
			bitpos += 16;
		} else {
			/* Short TPI */
			octstr_set_bits(data, bitpos + 5, 1, 0);
			octstr_set_bits(data, bitpos + 6, 2, length);
			bitpos += 8;
		}
		gw_assert(bitpos % 8 == 0);
		octstr_append(data, tpi->data);
		bitpos += 8 * length;
	}

	return bitpos;
}
Пример #24
0
/*
 * Add reroute information to the connection data. Where the priority
 * is in the order: reroute, reroute-smsc-id, reroute-receiver.
 */
static void init_reroute(SMSCConn *conn, CfgGroup *grp)
{
    Octstr *rule;
    long i;

    if (cfg_get_bool(&conn->reroute_dlr, grp, octstr_imm("reroute-dlr")) == -1)
        conn->reroute_dlr = 0;
    info(0, "DLR rerouting for smsc id <%s> %s.", octstr_get_cstr(conn->id), (conn->reroute_dlr?"enabled":"disabled"));

    if (cfg_get_bool(&conn->reroute, grp, octstr_imm("reroute")) != -1) {
        debug("smscconn",0,"Adding general internal routing for smsc id <%s>",
              octstr_get_cstr(conn->id));
        return;
    }

    if ((conn->reroute_to_smsc = cfg_get(grp, octstr_imm("reroute-smsc-id"))) != NULL) {
         /* reroute all messages to a specific smsc-id */
         debug("smscconn",0,"Adding internal routing: smsc id <%s> to smsc id <%s>",
               octstr_get_cstr(conn->id), octstr_get_cstr(conn->reroute_to_smsc));
        return;
    }

    if ((rule = cfg_get(grp, octstr_imm("reroute-receiver"))) != NULL) {
        List *routes;

        /* create hash disctionary for this smsc-id */
        conn->reroute_by_receiver = dict_create(100, (void(*)(void *)) octstr_destroy);

        routes = octstr_split(rule, octstr_imm(";"));
        for (i = 0; i < gwlist_len(routes); i++) {
            Octstr *item = gwlist_get(routes, i);
            Octstr *smsc, *receiver;
            List *receivers;

            /* first word is the smsc-id, all other are the receivers */
            receivers = octstr_split(item, octstr_imm(","));
            smsc = gwlist_extract_first(receivers);
            if (smsc)
                octstr_strip_blanks(smsc);

            while((receiver = gwlist_extract_first(receivers))) {
                octstr_strip_blanks(receiver);
                debug("smscconn",0,"Adding internal routing for smsc id <%s>: "
                          "receiver <%s> to smsc id <%s>",
                          octstr_get_cstr(conn->id), octstr_get_cstr(receiver),
                          octstr_get_cstr(smsc));
                if (!dict_put_once(conn->reroute_by_receiver, receiver, octstr_duplicate(smsc)))
                    panic(0, "Could not set internal routing for smsc id <%s>: "
                              "receiver <%s> to smsc id <%s>, because receiver has already routing entry!",
                              octstr_get_cstr(conn->id), octstr_get_cstr(receiver),
                              octstr_get_cstr(smsc));
                octstr_destroy(receiver);
            }
            octstr_destroy(smsc);
            gwlist_destroy(receivers, octstr_destroy_item);
        }
        octstr_destroy(rule);
        gwlist_destroy(routes, octstr_destroy_item);
    }
}
Пример #25
0
/*
 * Send a message to the bearerbox for delivery to a phone.
 * Return >= 0 for success & count of splitted sms messages, 
 * -1 for failure.  Does not destroy the msg.
 */
static int send_message(Msg *msg)
{
    unsigned long msg_count;
    List *list;
    
    gw_assert(msg != NULL);
    gw_assert(msg_type(msg) == sms);
    
    /* 
     * Encode our smsbox-id to the msg structure.
     * This will allow bearerbox to return specific answers to the
     * same smsbox, mainly for DLRs and SMS proxy modes.
     */
    if (smsbox_id != NULL) {
        msg->sms.boxc_id = octstr_duplicate(smsbox_id);
    }
    
    list = sms_split(msg, NULL, NULL, NULL, NULL, 1, 0, 100, MAX_SMS_OCTETS);
    msg_count = gwlist_len(list);
    gwlist_destroy(list, msg_destroy_item);

    debug("sms", 0, "message length %ld, sending %ld messages", 
          octstr_len(msg->sms.msgdata), msg_count);

    if (delay > 0)
        gwthread_sleep(delay);

    /* pass message to bearerbox */
    if (deliver_to_bearerbox(msg) != 0)
        return -1;
    
    return msg_count;
}
Пример #26
0
static long httpsmsc_queued(SMSCConn *conn)
{
    ConnData *conndata = conn->data;

    return (conndata ? (conn->status != SMSCCONN_DEAD ? 
            gwlist_len(conndata->msg_to_send) : 0) : 0);
}
Пример #27
0
static int mms_queue_update(MmsEnvelope *e)
{
	int i, n = (e && e->to) ? gwlist_len(e->to) : 0;
	int hasrcpt = 0;
	MmsEnvelopeTo *x;

	if (!e) return -1;
	/* FIX: Don't allow expiry to be <= 0 */
	if (e->expiryt <= 0)
		e->expiryt = time(NULL) + DEFAULT_EXPIRE;
	for (i = 0; i < n; i++) {
		if ((x = gwlist_get(e->to, i)) != NULL && x->process) {
			hasrcpt = 1;
			break;
		}
		debug("",0, "e->to[%d]=%p x->process=%d", i, x, x->process);
	}

	if (!hasrcpt) {
		/* The message has been sent to all recipients, so we can safely delete envelope */
		free_envelope(e,1);
		return 1;
	} else 
		return writeenvelope(e, 0); // writeenvelope returns 0 or -1 on error.
}
Пример #28
0
static long dlr_messages_oracle()
{
    List *result, *row;
    Octstr *sql;
    DBPoolConn *conn;
    long msgs = -1;

    conn = dbpool_conn_consume(pool);
    if (conn == NULL)
        return -1;

    sql = octstr_format("SELECT count(*) FROM %S", fields->table);
#if defined(DLR_TRACE)
    debug("dlr.oracle", 0, "sql: %s", octstr_get_cstr(sql));
#endif

    if (dbpool_conn_select(conn, sql, NULL, &result) != 0) {
        octstr_destroy(sql);
        dbpool_conn_produce(conn);
        return -1;
    }
    dbpool_conn_produce(conn);
    octstr_destroy(sql);

    if (gwlist_len(result) > 0) {
        row = gwlist_extract_first(result);
        msgs = strtol(octstr_get_cstr(gwlist_get(row,0)), NULL, 10);
        gwlist_destroy(row, octstr_destroy_item);
    }
    gwlist_destroy(result, NULL);

    return msgs;
}
Пример #29
0
void wap_map_url(Octstr **osp, Octstr **send_msisdn_query, 
                 Octstr **send_msisdn_header, 
                 Octstr **send_msisdn_format, int *accept_cookies)
{
    long i;
    Octstr *newurl, *tmp1, *tmp2;

    newurl = tmp1 = tmp2 = NULL;
    *send_msisdn_query = *send_msisdn_header = *send_msisdn_format = NULL;
    *accept_cookies = -1;

    debug("wsp",0,"WSP: Mapping url <%s>", octstr_get_cstr(*osp));
    for (i = 0; url_map && i < gwlist_len(url_map); i++) {
        struct url_map_struct *entry;
        entry = gwlist_get(url_map, i);

        /* 
        debug("wsp",0,"WSP: matching <%s> with <%s>", 
	          octstr_get_cstr(entry->url), octstr_get_cstr(entry->map_url)); 
        */

        /* DAVI: I only have '*' terminated entry->url implementation for now */
        tmp1 = octstr_duplicate(entry->url);
        octstr_delete(tmp1, octstr_len(tmp1)-1, 1); /* remove last '*' */
        tmp2 = octstr_copy(*osp, 0, octstr_len(tmp1));

        debug("wsp",0,"WSP: Matching <%s> with <%s>", 
              octstr_get_cstr(tmp1), octstr_get_cstr(tmp2));

        if (octstr_case_compare(tmp2, tmp1) == 0) {
            /* rewrite url if configured to do so */
            if (entry->map_url != NULL) {
                if (octstr_get_char(entry->map_url, 
                                    octstr_len(entry->map_url)-1) == '*') {
                    newurl = octstr_duplicate(entry->map_url);
                    octstr_delete(newurl, octstr_len(newurl)-1, 1);
                    octstr_append(newurl, octstr_copy(*osp, 
                    octstr_len(entry->url)-1, 
                    octstr_len(*osp)-octstr_len(entry->url)+1));
                } else {
                    newurl = octstr_duplicate(entry->map_url);
                }
                debug("wsp",0,"WSP: URL Rewriten from <%s> to <%s>", 
                      octstr_get_cstr(*osp), octstr_get_cstr(newurl));
                octstr_destroy(*osp);
                *osp = newurl;
            }
            *accept_cookies = entry->accept_cookies;
            *send_msisdn_query = octstr_duplicate(entry->send_msisdn_query);
            *send_msisdn_header = octstr_duplicate(entry->send_msisdn_header);
            *send_msisdn_format = octstr_duplicate(entry->send_msisdn_format);
            octstr_destroy(tmp1);
            octstr_destroy(tmp2);
            break;
        }
        octstr_destroy(tmp1);
        octstr_destroy(tmp2);
    }
}
Пример #30
0
int set_cookies(List *headers, WSPMachine *sm)
{
	Cookie *value = NULL;
	Octstr *cookie = NULL;
	long pos = 0;

	if (headers == NULL || sm == NULL) {
		error (0, "set_cookies: Null argument(s) - no headers, WSPMachine or both");
		return -1;
	}

	/* Expire cookies that have timed out */
	expire_cookies(sm->cookies);

	/* Walk through the cookie cache, adding the cookie to the request headers */
	if (gwlist_len(sm->cookies) > 0) {
		debug("wap.wsp.http", 0, "set_cookies: Cookies in cache");

		for (pos = 0; pos < gwlist_len(sm->cookies); pos++) {
			value = gwlist_get(sm->cookies, pos);

			cookie = octstr_create("Cookie: ");
			if (value->version) 
			    octstr_append(cookie, value->version);
			octstr_append(cookie, value->name);
			octstr_append_char(cookie, '=');
			octstr_append(cookie, value->value);

			if (value->path) {
				octstr_append_char(cookie, ';');
				octstr_append(cookie, value->path);
			}
			if (value->domain) {
				octstr_append_char(cookie, ';');
				octstr_append(cookie, value->domain);
			}

			gwlist_append(headers, cookie);
			debug("wap.wsp.http", 0, "set_cookies: Added (%s)", octstr_get_cstr (cookie));
		}
	} else
		debug("wap.wsp.http", 0, "set_cookies: No cookies in cache");

	return 0;
}