static void dlr_update_oracle(const Octstr *smsc, const Octstr *ts, const Octstr *dst, int status) { Octstr *sql, *os_status; DBPoolConn *pconn; List *binds = gwlist_create(); debug("dlr.oracle", 0, "updating DLR status in database"); pconn = dbpool_conn_consume(pool); /* just for sure */ if (pconn == NULL) return; sql = octstr_format("UPDATE %S SET %S=:1 WHERE %S=:2 AND %S=:3 AND %S=:4 AND ROWNUM < 2", fields->table, fields->field_status, 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 */ gwlist_append(binds, (Octstr *)dst); /* :4 */ #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 updating dlr entry for DST<%s>", octstr_get_cstr(dst)); dbpool_conn_produce(pconn); gwlist_destroy(binds, NULL); octstr_destroy(os_status); octstr_destroy(sql); }
static void dispatch_into_queue(Msg *msg) { char id[UUID_STR_LEN + 1]; gw_assert(msg != NULL), gw_assert(msg_type(msg) == sms); switch (msg->sms.sms_type) { case mt_push: case mt_reply: case report_mt: gwlist_append(outgoing_sms, msg); break; case mo: case report_mo: gwlist_append(incoming_sms, msg); break; default: uuid_unparse(msg->sms.id, id); error(0, "Not handled sms_type %ld within store for message ID %s", msg->sms.sms_type, id); msg_destroy(msg); break; } }
void cfg_init(void) { /* make sure we put our own core hooks into the lists */ allowed_hooks = gwlist_create(); single_hooks = gwlist_create(); gwlist_append(allowed_hooks, &core_is_allowed_in_group); gwlist_append(single_hooks, &core_is_single_group); }
static struct dlr_entry* dlr_get_oracle(const Octstr *smsc, const Octstr *ts, const Octstr *dst) { Octstr *sql; DBPoolConn *pconn; List *result = NULL, *row; struct dlr_entry *res = NULL; List *binds = gwlist_create(); pconn = dbpool_conn_consume(pool); if (pconn == NULL) /* should not happens, but sure is sure */ return NULL; sql = octstr_format("SELECT %S, %S, %S, %S, %S, %S FROM %S WHERE %S=:1 AND %S=:2 AND %S=:3 AND ROWNUM < 2", fields->field_mask, fields->field_serv, fields->field_url, fields->field_src, fields->field_dst, fields->field_boxc, fields->table, fields->field_smsc, fields->field_ts, fields->field_dst); gwlist_append(binds, (Octstr *)smsc); /* :1 */ gwlist_append(binds, (Octstr *)ts); /* :2 */ gwlist_append(binds, (Octstr *)dst); /* :3 */ #if defined(DLR_TRACE) debug("dlr.oracle", 0, "sql: %s", octstr_get_cstr(sql)); #endif if (dbpool_conn_select(pconn, sql, binds, &result) != 0) { octstr_destroy(sql); dbpool_conn_produce(pconn); return NULL; } octstr_destroy(sql); gwlist_destroy(binds, NULL); dbpool_conn_produce(pconn); #define LO2CSTR(r, i) octstr_get_cstr(gwlist_get(r, i)) if (gwlist_len(result) > 0) { row = gwlist_extract_first(result); res = dlr_entry_create(); gw_assert(res != NULL); res->mask = atoi(LO2CSTR(row,0)); res->service = octstr_create(LO2CSTR(row, 1)); res->url = octstr_create(LO2CSTR(row,2)); res->source = octstr_create(LO2CSTR(row, 3)); res->destination = octstr_create(LO2CSTR(row, 4)); res->boxc_id = octstr_create(LO2CSTR(row, 5)); gwlist_destroy(row, octstr_destroy_item); res->smsc = octstr_duplicate(smsc); } gwlist_destroy(result, NULL); #undef LO2CSTR return res; }
static void dlr_redis_remove(const Octstr *smsc, const Octstr *ts, const Octstr *dst) { Octstr *key, *sql; DBPoolConn *pconn; List *binds = gwlist_create(); int res; debug("dlr.redis", 0, "Removing DLR from keystore"); pconn = dbpool_conn_consume(pool); /* just for sure */ if (pconn == NULL) { error(0, "DLR: REDIS: No connection available"); gwlist_destroy(binds, NULL); return; } /* octstr_replace(dst, octstr_imm(" "), octstr_imm("")); octstr_replace(ts, octstr_imm(" "), octstr_imm("")); */ key = octstr_format((dst ? "%S:?:?:?" : "%S:?:?"), fields->table); sql = octstr_format("DEL %S", key, fields->table); gwlist_append(binds, (Octstr *)smsc); /* key */ gwlist_append(binds, (Octstr *)ts); /* key */ if (dst) gwlist_append(binds, (Octstr *)dst); /* key */ res = dbpool_conn_update(pconn, sql, binds); /* * Redis DEL returns the number of keys deleted */ if (res != 1) { /* * We may fail to delete a DLR that was successfully retrieved * just above due to race conditions when duplicate message IDs * are received. This happens frequently when testing via the * Logica SMPP emulator due to its duplicate message ID bugs. */ error(0, "DLR: REDIS: Error while removing dlr entry for %s", octstr_get_cstr(key)); } /* We don't perform 'DECR <table>:Count', since we have TTL'ed * expirations, which can't be handled with manual counters. */ dbpool_conn_produce(pconn); octstr_destroy(sql); octstr_destroy(key); gwlist_destroy(binds, NULL); }
/****************************************************************************** * * EXTERNAL FUNCTIONS: * * Handles a possible concatenated message. Creates a list of wap events. */ List *wtp_unpack_wdp_datagram(WAPEvent *datagram) { List *events = NULL; WAPEvent *event = NULL; WAPEvent *subdgram = NULL; Octstr *data = NULL; long pdu_len; gw_assert(datagram->type == T_DUnitdata_Ind); events = gwlist_create(); if (concatenated_message(datagram->u.T_DUnitdata_Ind.user_data)) { data = octstr_duplicate(datagram->u.T_DUnitdata_Ind.user_data); octstr_delete(data, 0, 1); while (octstr_len(data) != 0) { if (octstr_get_bits(data, 0, 1) == 0) { pdu_len = octstr_get_char(data, 0); octstr_delete(data, 0, 1); } else { pdu_len = octstr_get_bits(data, 1, 15); octstr_delete(data, 0, 2); } subdgram = wap_event_duplicate(datagram); octstr_destroy(subdgram->u.T_DUnitdata_Ind.user_data); subdgram->u.T_DUnitdata_Ind.user_data = octstr_copy(data, 0, pdu_len); wap_event_assert(subdgram); if ((event = unpack_wdp_datagram_real(subdgram)) != NULL) { wap_event_assert(event); gwlist_append(events, event); } octstr_delete(data, 0, pdu_len); wap_event_destroy(subdgram); } octstr_destroy(data); } else if ((event = unpack_wdp_datagram_real(datagram)) != NULL) { wap_event_assert(event); gwlist_append(events, event); } else { warning(0, "WTP: Dropping unhandled datagram data:"); octstr_dump(datagram->u.T_DUnitdata_Ind.user_data, 0, GW_WARNING); } return events; }
/* * Checks if body_part contains a Content-Type header. Tranfers this header to * a list content_headers. (Only part before 'boundary'). * Return 1, when Content-Type headers was found, 0 otherwise */ static int check_data_content_type_header(Octstr **body_part, List **content_headers, Octstr *boundary) { long header_pos, next_header_pos; Octstr *content_header; long message_start_pos; header_pos = next_header_pos = -1; content_header = octstr_create("Content-Type"); message_start_pos = octstr_search(*body_part, boundary, 0); if ((header_pos = octstr_case_nsearch(*body_part, content_header, 0, message_start_pos)) < 0) { goto error; } if ((next_header_pos = pass_field_value(body_part, &content_header, header_pos + octstr_len(content_header))) < 0) { goto error; } if ((next_header_pos = parse_terminator(*body_part, next_header_pos)) < 0) { goto error; } octstr_delete(*body_part, header_pos, next_header_pos - header_pos); gwlist_append(*content_headers, octstr_duplicate(content_header)); octstr_destroy(content_header); return 1; error: octstr_destroy(content_header); return 0; }
static WTLSMachine *wtls_machine_create(WAPAddrTuple * tuple) { WTLSMachine *wtls_machine; wtls_machine = gw_malloc(sizeof(WTLSMachine)); #define MACHINE(field) field #define ENUM(name) wtls_machine->name = NULL_STATE; #define ADDRTUPLE(name) wtls_machine->name = NULL; #define INTEGER(name) wtls_machine->name = 0; #define OCTSTR(name) wtls_machine->name = NULL; #define PDULIST(name) wtls_machine->name = NULL; #include "wtls_machine-decl.h" gwlist_append(wtls_machines, wtls_machine); wtls_machine->mid = counter_increase(wtls_machine_id_counter); wtls_machine->addr_tuple = wap_addr_tuple_duplicate(tuple); wtls_machine->server_seq_num = wtls_machine->client_seq_num = -1; wtls_machine->last_refresh = -1; wtls_machine->handshake_data = octstr_create(""); debug("wap.wtls", 0, "WTLS: Created WTLSMachine %ld (0x%p)", wtls_machine->mid, (void *)wtls_machine); return wtls_machine; }
/* 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; }
/* Append a new part to list of body parts. Copy is made * Note that if it was not multipart, this action makes it so! */ void mime_entity_add_part(MIMEEntity *e, MIMEEntity *part) { gw_assert(e != NULL); gw_assert(part != NULL); gwlist_append(e->multiparts, mime_entity_duplicate(part)); }
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); }
/* * 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; }
static WTPInitMachine *init_machine_create(WAPAddrTuple *tuple, unsigned short tid, int tidnew) { WTPInitMachine *init_machine; init_machine = gw_malloc(sizeof(WTPInitMachine)); #define ENUM(name) init_machine->name = INITIATOR_NULL_STATE; #define INTEGER(name) init_machine->name = 0; #define EVENT(name) init_machine->name = NULL; #define TIMER(name) init_machine->name = gwtimer_create(queue); #define ADDRTUPLE(name) init_machine->name = NULL; #define MACHINE(field) field #include "wtp_init_machine.def" gwlist_append(init_machines, init_machine); init_machine->mid = counter_increase(init_machine_id_counter); init_machine->addr_tuple = wap_addr_tuple_duplicate(tuple); init_machine->tid = tid; init_machine->tidnew = tidnew; debug("wap.wtp", 0, "WTP: Created WTPInitMachine %p (%ld)", (void *) init_machine, init_machine->mid); return init_machine; }
static void add_push_application_id(List **push_headers, Octstr *appid_flag, int use_string) { if (use_string) { gwlist_append(*push_headers, appid_string); return; } if (octstr_compare(appid_flag, octstr_imm("any")) == 0) { if (!use_numeric) http_header_add(*push_headers, "X-WAP-Application-Id", "http://www.wiral.com:*"); else http_header_add(*push_headers, "X-WAP-Application-Id", "0"); } else if (octstr_compare(appid_flag, octstr_imm("ua")) == 0) { if (!use_numeric) http_header_add(*push_headers, "X-WAP-Application-Id", "http://www.wiral.com:wml.ua"); else http_header_add(*push_headers, "X-WAP-Application-Id", "2"); } else if (octstr_compare(appid_flag, octstr_imm("mms")) == 0) { if (!use_numeric) http_header_add(*push_headers, "X-WAP-Application-Id", "mms.ua"); else http_header_add(*push_headers, "X-WAP-Application-Id", "4"); } else if (octstr_compare(appid_flag, octstr_imm("scrap")) == 0) { if (!use_numeric) http_header_add(*push_headers, "X-WAP-Application-Id", "no appid at all"); else http_header_add(*push_headers, "X-WAP-Application-Id", "this is not a numeric header"); } }
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); }
static void run_wapbox(void *arg) { Boxc *newconn; List *newlist; long sender; gwlist_add_producer(flow_threads); newconn = arg; newconn->is_wap = 1; /* * create a new incoming list for just that box, * and add it to list of list pointers, so we can start * to route messages to it. */ debug("bb", 0, "setting up systems for new wapbox"); newlist = gwlist_create(); /* this is released by the sender/receiver if it exits */ gwlist_add_producer(newlist); newconn->incoming = newlist; newconn->retry = incoming_wdp; newconn->outgoing = outgoing_wdp; sender = gwthread_create(boxc_sender, newconn); if (sender == -1) { error(0, "Failed to start a new thread, disconnecting client <%s>", octstr_get_cstr(newconn->client_ip)); goto cleanup; } gwlist_append(wapbox_list, newconn); gwlist_add_producer(newconn->outgoing); boxc_receiver(newconn); /* cleanup after receiver has exited */ gwlist_remove_producer(newconn->outgoing); gwlist_lock(wapbox_list); gwlist_delete_equal(wapbox_list, newconn); gwlist_unlock(wapbox_list); while (gwlist_producer_count(newlist) > 0) gwlist_remove_producer(newlist); newconn->alive = 0; gwthread_join(sender); cleanup: gw_assert(gwlist_len(newlist) == 0); gwlist_destroy(newlist, NULL); boxc_destroy(newconn); gwlist_remove_producer(flow_threads); }
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); }
static int add_group(Cfg *cfg, CfgGroup *grp) { Octstr *groupname; Octstr *name; List *names; List *list; groupname = cfg_get(grp, octstr_imm("group")); if (groupname == NULL) { error(0, "Group does not contain variable 'group'."); return -1; } set_group_name(grp, groupname); names = dict_keys(grp->vars); while ((name = gwlist_extract_first(names)) != NULL) { int a = is_allowed_in_group(groupname, name); switch (a) { case 0: error(0, "Group '%s' may not contain field '%s'.", octstr_get_cstr(groupname), octstr_get_cstr(name)); octstr_destroy(name); octstr_destroy(groupname); gwlist_destroy(names, octstr_destroy_item); return -1; break; case -1: error(0, "Group '%s' is no valid group identifier.", octstr_get_cstr(groupname)); octstr_destroy(name); octstr_destroy(groupname); gwlist_destroy(names, octstr_destroy_item); return -1; break; default: octstr_destroy(name); break; } } gwlist_destroy(names, NULL); if (is_single_group(groupname)) { dict_put(cfg->single_groups, groupname, grp); } else { list = dict_get(cfg->multi_groups, groupname); if (list == NULL) { list = gwlist_create(); dict_put(cfg->multi_groups, groupname, list); } gwlist_append(list, grp); } octstr_destroy(groupname); return 0; }
static void add_cookie_to_cache(const WSPMachine *sm, Cookie *value) { gw_assert(sm != NULL); gw_assert(sm->cookies != NULL); gw_assert(value != NULL); gwlist_append(sm->cookies, value); return; }
void wtp_pdu_append_tpi(WTP_PDU *pdu, int type, Octstr *data) { WTP_TPI *tpi; tpi = gw_malloc(sizeof(*tpi)); tpi->type = type; tpi->data = data; if (pdu->options == NULL) pdu->options = gwlist_create(); gwlist_append(pdu->options, tpi); }
/* * Adds an item to the tid cache, one item per every initiator. Initiator is * identified by the address four-tuple, fetched from a wtp responder machine. */ static void add_tid(WTPRespMachine *resp_machine, long tid) { WTPCached_tid *new_item = NULL; new_item = cache_item_create_empty(); new_item->addr_tuple = wap_addr_tuple_duplicate(resp_machine->addr_tuple); new_item->tid = tid; gwlist_append(tid_cache, new_item); }
static void dispatch_into_queue(Msg *msg) { gw_assert(msg != NULL), gw_assert(msg_type(msg) == sms); switch (msg->sms.sms_type) { case mt_push: case mt_reply: case report_mt: gwlist_append(outgoing_sms, msg); break; case mo: case report_mo: gwlist_append(incoming_sms, msg); break; default: panic(0, "Not handled sms_type within store!"); } }
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); }
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); }
/* Generate a refusal for all requested capabilities that are not * replied to. */ static void refuse_unreplied_capabilities(List *caps, List *req) { long i, len; Capability *cap; len = gwlist_len(req); for (i = 0; i < len; i++) { cap = gwlist_get(req, i); if (wsp_cap_count(caps, cap->id, cap->name) == 0) { cap = wsp_cap_create(cap->id, cap->name, NULL); gwlist_append(caps, cap); } } }
/* Make a copy of a mime object. recursively. */ MIMEEntity *mime_entity_duplicate(MIMEEntity *e) { MIMEEntity *copy = mime_entity_create(); int i, n; mime_replace_headers(copy, e->headers); copy->body = e->body ? octstr_duplicate(e->body) : NULL; for (i = 0, n = gwlist_len(e->multiparts); i < n; i++) gwlist_append(copy->multiparts, mime_entity_duplicate(gwlist_get(e->multiparts, i))); return copy; }
static List *parse_string_list(char *buf) { int i = 0; char sbuf[128], *p = buf; List *l = gwlist_create(); while (sscanf(p, "%s%n", sbuf, &i) > 0) { gwlist_append(l, octstr_create(sbuf)); p += i; } return l; }
List *wsp_cap_unpack_list(Octstr *caps) { List *caps_list; long pos, capslen; caps_list = gwlist_create(); if (caps == NULL) return caps_list; capslen = octstr_len(caps); pos = 0; while (pos < capslen) { unsigned long length; int id; Octstr *name; Octstr *data; pos = octstr_extract_uintvar(caps, &length, pos); if (pos < 0 || length == 0) goto error; id = octstr_get_char(caps, pos); if (id >= 0x80) { id &= 0x7f; /* It's encoded as a short-integer */ name = NULL; data = octstr_copy(caps, pos + 1, length - 1); } else { long nullpos; id = -1; /* It's encoded as token-text */ nullpos = octstr_search_char(caps, 0, pos); if (nullpos < 0) goto error; /* check length * FIXME: If it's not allowed that data is empty then change check * to <= . */ if (length < (nullpos + 1 - pos)) goto error; name = octstr_copy(caps, pos, nullpos - pos); data = octstr_copy(caps, nullpos + 1, length - (nullpos + 1 - pos)); } gwlist_append(caps_list, wsp_cap_create(id, name, data)); pos += length; } return caps_list; error: warning(0, "WSP: Error unpacking capabilities"); return caps_list; }
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; }
List *cfg_get_multi_group(Cfg *cfg, Octstr *name) { List *list, *copy; long i; list = dict_get(cfg->multi_groups, name); if (list == NULL) return NULL; copy = gwlist_create(); for (i = 0; i < gwlist_len(list); ++i) gwlist_append(copy, gwlist_get(list, i)); return copy; }