/* * Append the User Data Header (UDH) including the length (UDHL). Only ports * UDH here - SAR UDH is added when (or if) we split the message. This is our * *specific* WDP layer. */ static void ota_pack_udh(Msg **msg, Octstr *doc_type) { (*msg)->sms.udhdata = octstr_create(""); if (octstr_case_compare(doc_type, octstr_imm("oma-settings")) == 0) octstr_append_from_hex((*msg)->sms.udhdata, "0605040B840B84"); else if (octstr_case_compare(doc_type, octstr_imm("syncsettings")) == 0) { octstr_append_from_hex((*msg)->sms.udhdata, "060504C34CC002"); } else octstr_append_from_hex((*msg)->sms.udhdata, "060504C34FC002"); }
/* * Add boundary value to the multipart header. */ static Octstr *make_multipart_value(const char *boundary) { Octstr *hos; hos = octstr_format("%s", "multipart/related; boundary="); octstr_append(hos, octstr_imm(boundary)); octstr_append(hos, octstr_imm("; type=\"application/xml\"")); return hos; }
static void add_connection_header(List **push_headers, Octstr *connection) { if (!connection) return; if (octstr_compare(connection, octstr_imm("close")) == 0) http_header_add(*push_headers, "Connection", "close"); else if (octstr_compare(connection, octstr_imm("keep-alive")) == 0) http_header_add(*push_headers, "Connection", "keep-alive"); }
static void bearerbox_to_sql(void *arg) { Boxc *conn = (Boxc *)arg; Msg *msg, *mack; while (sqlbox_status == SQL_RUNNING && conn->alive) { msg = read_from_box(conn->bearerbox_connection, conn); if (msg == NULL) { /* garbage/connection lost */ /* tell sqlbox to die */ conn->alive = 0; sqlbox_status = SQL_SHUTDOWN; debug("sqlbox", 0, "bearerbox_to_sql: connection to bearerbox died."); break; } if (msg_type(msg) == heartbeat) { // todo debug("sqlbox", 0, "bearerbox_to_sql: catch an heartbeat - we are alive"); msg_destroy(msg); continue; } /* if this is an identification message from an smsbox instance */ if (msg_type(msg) == admin && msg->admin.command == cmd_shutdown) { /* tell sqlbox to die */ conn->alive = 0; sqlbox_status = SQL_SHUTDOWN; debug("sqlbox", 0, "bearerbox_to_sql: Bearerbox told us to shutdown."); break; } if (msg_type(msg) == sms) { if (msg->sms.sms_type != report_mo) { if (save_mo) { gw_sql_save_msg(msg, octstr_imm("MO")); } } else { if (save_dlr) { gw_sql_save_msg(msg, octstr_imm("DLR")); } } /* create ack message */ mack = msg_create(ack); mack->ack.nack = ack_success; mack->ack.time = msg->sms.time; uuid_copy(mack->ack.id, msg->sms.id); send_msg(conn->bearerbox_connection, conn, mack); msg_destroy(mack); } msg_destroy(msg); } }
static Octstr *get_string_value_or_return_null(Octstr *str) { if (str == NULL) { return octstr_create("NULL"); } else if (octstr_compare(str, octstr_imm("")) == 0) { return octstr_create("NULL"); } octstr_replace(str, octstr_imm("\\"), octstr_imm("\\\\")); octstr_replace(str, octstr_imm("\'"), octstr_imm("\\\'")); return octstr_format("\'%S\'", str); }
static void bearerbox_to_smsbox(void *arg) { Msg *msg, *msg_escaped; Boxc *conn = arg; while (sqlbox_status == SQL_RUNNING && conn->alive) { msg = read_from_box(conn->bearerbox_connection, conn); if (msg == NULL) { /* tell sqlbox to die */ conn->alive = 0; debug("sqlbox", 0, "bearerbox_to_smsbox: connection to bearerbox died."); break; } if (msg_type(msg) == admin) { if (msg->admin.command == cmd_shutdown || msg->admin.command == cmd_restart) { /* tell sqlbox to die */ conn->alive = 0; debug("sqlbox", 0, "bearerbox_to_smsbox: Bearerbox told us to shutdown."); break; } } if (msg_type(msg) == heartbeat) { // todo debug("sqlbox", 0, "bearerbox_to_smsbox: catch an heartbeat - we are alive"); msg_destroy(msg); continue; } if (!conn->alive) { msg_destroy(msg); break; } if (msg_type(msg) == sms) { msg_escaped = msg_duplicate(msg); if (msg->sms.sms_type != report_mo) { if (save_mo) { gw_sql_save_msg(msg_escaped, octstr_imm("MO")); } } else { if (save_dlr) { gw_sql_save_msg(msg_escaped, octstr_imm("DLR")); } } msg_destroy(msg_escaped); } send_msg(conn->smsbox_connection, conn, msg); msg_destroy(msg); } /* the client closes the connection, after that die in receiver */ conn->alive = 0; }
static int sms_to_client(Connection *client, Msg *msg) { Octstr *line; Octstr *msgdata = NULL; /* NULL to allow octstr_destroy */ char *contents; int len; debug("bb.sms", 0, "smsc_fake: sending message to client"); // msg_dump(msg, 0); line = octstr_duplicate(msg->sms.sender); octstr_append_char(line, ' '); octstr_append(line, msg->sms.receiver); if (octstr_len(msg->sms.udhdata)) { octstr_append(line, octstr_imm(" udh ")); msgdata = octstr_duplicate(msg->sms.udhdata); octstr_url_encode(msgdata); octstr_append(line, msgdata); octstr_destroy(msgdata); octstr_append_char(line, ' '); msgdata = octstr_duplicate(msg->sms.msgdata); octstr_url_encode(msgdata); octstr_append(line, msgdata); } else { contents = octstr_get_cstr(msg->sms.msgdata); len = octstr_len(msg->sms.msgdata); while (len > 0) { len--; if (contents[len] < 32 || contents[len] > 126) { octstr_append(line, octstr_imm(" data ")); msgdata = octstr_duplicate(msg->sms.msgdata); octstr_url_encode(msgdata); octstr_append(line, msgdata); goto notelse; /* C lacks "else" clause for while loops */ } } octstr_append(line, octstr_imm(" text ")); octstr_append(line, msg->sms.msgdata); } notelse: octstr_append_char(line, 10); if (conn_write(client, line) == -1) { octstr_destroy(msgdata); octstr_destroy(line); return -1; } octstr_destroy(msgdata); octstr_destroy(line); return 1; }
int smsbox_start(Cfg *cfg) { CfgGroup *grp; if (smsbox_running) return -1; debug("bb", 0, "starting smsbox connection module"); grp = cfg_get_single_group(cfg, octstr_imm("core")); if (cfg_get_integer(&smsbox_port, grp, octstr_imm("smsbox-port")) == -1) { error(0, "Missing smsbox-port variable, cannot start smsboxes"); return -1; } #ifdef HAVE_LIBSSL cfg_get_bool(&smsbox_port_ssl, grp, octstr_imm("smsbox-port-ssl")); #endif /* HAVE_LIBSSL */ if (smsbox_port_ssl) debug("bb", 0, "smsbox connection module is SSL-enabled"); if (cfg_get_integer(&smsbox_max_pending, grp, octstr_imm("smsbox-max-pending")) == -1) { smsbox_max_pending = SMSBOX_MAX_PENDING; info(0, "BOXC: 'smsbox-max-pending' not set, using default (%ld).", smsbox_max_pending); } smsbox_list = gwlist_create(); /* have a list of connections */ smsbox_list_rwlock = gw_rwlock_create(); if (!boxid) boxid = counter_create(); /* the smsbox routing specific inits */ smsbox_by_id = dict_create(10, NULL); /* and a hash directory of identified */ smsbox_by_smsc = dict_create(30, (void(*)(void *)) octstr_destroy); smsbox_by_receiver = dict_create(50, (void(*)(void *)) octstr_destroy); smsbox_by_smsc_receiver = dict_create(50, (void(*)(void *)) octstr_destroy); /* load the defined smsbox routing rules */ init_smsbox_routes(cfg); gwlist_add_producer(outgoing_sms); gwlist_add_producer(smsbox_list); smsbox_running = 1; if ((sms_dequeue_thread = gwthread_create(sms_to_smsboxes, NULL)) == -1) panic(0, "Failed to start a new thread for smsbox routing"); if (gwthread_create(smsboxc_run, &smsbox_port) == -1) panic(0, "Failed to start a new thread for smsbox connections"); return 0; }
static int sms_to_client(Connection *client, Msg *msg) { Octstr *line; Octstr *msgdata = NULL; /* NULL to allow octstr_destroy */ debug("bb.sms", 0, "smsc_fake: sending message to client"); /* msg_dump(msg, 0); */ line = octstr_duplicate(msg->sms.sender); octstr_append_char(line, ' '); octstr_append(line, msg->sms.receiver); if (octstr_len(msg->sms.udhdata)) { octstr_append(line, octstr_imm(" udh ")); msgdata = octstr_duplicate(msg->sms.udhdata); octstr_url_encode(msgdata); octstr_append(line, msgdata); octstr_destroy(msgdata); octstr_append(line, octstr_imm(" data ")); msgdata = octstr_duplicate(msg->sms.msgdata); octstr_url_encode(msgdata); octstr_append(line, msgdata); } else { if (msg->sms.coding == DC_8BIT) { octstr_append(line, octstr_imm(" data ")); msgdata = octstr_duplicate(msg->sms.msgdata); octstr_url_encode(msgdata); octstr_append(line, msgdata); } else if (msg->sms.coding == DC_UCS2) { octstr_append(line, octstr_imm(" ucs-2 ")); msgdata = octstr_duplicate(msg->sms.msgdata); octstr_url_encode(msgdata); octstr_append(line, msgdata); } else { octstr_append(line, octstr_imm(" text ")); octstr_append(line, msg->sms.msgdata); } } octstr_append_char(line, 10); if (conn_write(client, line) == -1) { octstr_destroy(msgdata); octstr_destroy(line); return -1; } octstr_destroy(msgdata); octstr_destroy(line); return 1; }
int cfg_get_bool(int *n, CfgGroup *grp, Octstr *varname) { Octstr *os; os = cfg_get(grp, varname); if (os == NULL) { *n = 0; return -1; } if (octstr_case_compare(os, octstr_imm("true")) == 0 || octstr_case_compare(os, octstr_imm("yes")) == 0 || octstr_case_compare(os, octstr_imm("on")) == 0 || octstr_case_compare(os, octstr_imm("1")) == 0) { *n = 1; } else if (octstr_case_compare(os, octstr_imm("false")) == 0 || octstr_case_compare(os, octstr_imm("no")) == 0 || octstr_case_compare(os, octstr_imm("off")) == 0 || octstr_case_compare(os, octstr_imm("0")) == 0) { *n = 0; } else { *n = 1; warning(0, "bool variable set to strange value, assuming 'true'"); } octstr_destroy(os); return 0; }
/* * Initialize specifically dlr storage. If defined storage is unknown * then panic. */ void dlr_init(Cfg* cfg) { CfgGroup *grp; Octstr *dlr_type; /* check which DLR storage type we are using */ grp = cfg_get_single_group(cfg, octstr_imm("core")); if(grp == NULL) panic(0, "DLR: can't find group core"); dlr_type = cfg_get(grp, octstr_imm("dlr-storage")); /* * assume we are using internal memory in case no directive * has been specified, warn the user anyway */ if (dlr_type == NULL) { dlr_type = octstr_imm("internal"); warning(0, "DLR: using default 'internal' for storage type."); } /* call the sub-init routine */ if (octstr_compare(dlr_type, octstr_imm("mysql")) == 0) { handles = dlr_init_mysql(cfg); } else if (octstr_compare(dlr_type, octstr_imm("sdb")) == 0) { handles = dlr_init_sdb(cfg); } else if (octstr_compare(dlr_type, octstr_imm("oracle")) == 0) { handles = dlr_init_oracle(cfg); } else if (octstr_compare(dlr_type, octstr_imm("internal")) == 0) { handles = dlr_init_mem(cfg); } else if (octstr_compare(dlr_type, octstr_imm("pgsql")) == 0) { handles = dlr_init_pgsql(cfg); } else if (octstr_compare(dlr_type, octstr_imm("mssql")) == 0) { handles = dlr_init_mssql(cfg); } /* * add aditional types here */ if (handles == NULL) { panic(0, "DLR: storage type '%s' is not supported!", octstr_get_cstr(dlr_type)); } /* check needed function pointers */ if (handles->dlr_add == NULL || handles->dlr_get == NULL || handles->dlr_remove == NULL) panic(0, "DLR: storage type '%s' don't implement needed functions", octstr_get_cstr(dlr_type)); /* get info from storage */ info(0, "DLR using storage type: %s", handles->type); /* cleanup */ octstr_destroy(dlr_type); }
/* * 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; }
static void add_content_type(Octstr *content_flag, Octstr **content) { if (*content == NULL) *content = octstr_create(""); if (octstr_compare(content_flag, octstr_imm("wml")) == 0) octstr_append_cstr(*content, "Content-Type: text/vnd.wap.wml\r\n"); else if (octstr_compare(content_flag, octstr_imm("si")) == 0) octstr_append_cstr(*content, "Content-Type: text/vnd.wap.si\r\n"); else if (octstr_compare(content_flag, octstr_imm("sl")) == 0) octstr_append_cstr(*content, "Content-Type: text/vnd.wap.sl\r\n"); else if (octstr_compare(content_flag, octstr_imm("multipart")) == 0) octstr_append_cstr(*content, "Content-Type: multipart/related; boundary=fsahgwruijkfldsa\r\n"); else if (octstr_compare(content_flag, octstr_imm("mms")) == 0) octstr_append_cstr(*content, "Content-Type: application/vnd.wap.mms-message\r\n"); }
/* returns the DLR/RR URL, fills in the queue header info. */ Octstr *mmsbox_get_report_info(MmsMsg *m, MmscGrp *mmsc, Octstr *out_mmc_id, char *report_type, Octstr *status, List *qhdr, Octstr *uaprof, time_t uaprof_tstamp, Octstr *msgid) { Octstr *res; if (mmsc == NULL) res = NULL; else if (out_mmc_id != NULL) { /* internal routing. */ if (m) fixup_relayed_report(m, mmsc, report_type, octstr_imm("")); res = NULL; } else { Octstr *transid = NULL; res = get_dlr_notify_url(msgid, report_type,mmsc->group_id, mmsc->id, status, &transid); http_header_add(qhdr, "X-Mbuni-Mmsc-GroupID", octstr_get_cstr(mmsc->group_id)); if (transid) { http_header_add(qhdr, "X-Mbuni-TransactionID", octstr_get_cstr(transid)); octstr_destroy(transid); } if (uaprof) { Octstr *sx = date_format_http(uaprof_tstamp); http_header_add(qhdr, "X-Mbuni-UAProf", octstr_get_cstr(uaprof)); http_header_add(qhdr, "X-Mbuni-Timestamp", octstr_get_cstr(sx)); octstr_destroy(sx); } } return res; }
static struct smpp_tlv *smpp_tlv_get_by_tag(Octstr *smsc_id, long tag) { struct smpp_tlv *res = NULL; Dict *tmp_dict; Octstr *tmp; if (tlvs_by_tag == NULL) return NULL; tmp = octstr_format("%ld", tag); if (smsc_id != NULL) { tmp_dict = dict_get(tlvs_by_tag, smsc_id); if (tmp_dict != NULL) res = dict_get(tmp_dict, tmp); } if (res == NULL) { /* try default smsc_id */ smsc_id = octstr_imm(DEFAULT_SMSC_ID); tmp_dict = dict_get(tlvs_by_tag, smsc_id); if (tmp_dict != NULL) res = dict_get(tmp_dict, tmp); } octstr_destroy(tmp); return res; }
static int core_is_allowed_in_group(Octstr *group, Octstr *variable) { Octstr *groupstr; groupstr = octstr_imm("group"); #define OCTSTR(name) \ if (octstr_compare(octstr_imm(#name), variable) == 0) \ return 1; #define SINGLE_GROUP(name, fields) \ if (octstr_compare(octstr_imm(#name), group) == 0) { \ if (octstr_compare(groupstr, variable) == 0) \ return 1; \ fields \ return 0; \ } #define MULTI_GROUP(name, fields) \ if (octstr_compare(octstr_imm(#name), group) == 0) { \ if (octstr_compare(groupstr, variable) == 0) \ return 1; \ fields \ return 0; \ } #include "cfg.def" /* unknown group identifier */ return -1; }
static MmsMsg *mms_queue_getdata(MmsEnvelope *e) { Octstr *fname; Octstr *ms; MmsMsg *m; struct qfile_t *qfs; if (!e) return NULL; qfs = e->qfs_data; fname = octstr_format("%s/%s%c%s", qfs->dir, qfs->subdir, MDF, qfs->name + 1); ms = octstr_read_file(octstr_get_cstr(fname)); if (!ms) { error(0, "mms_queue_getdata: Failed to load data file for queue entry %s in %s", qfs->name, qfs->dir); octstr_destroy(fname); return NULL; } m = mms_frombinary(ms, octstr_imm("")); if (!m) { error(0, "mms_queue_getdata: Failed to decode data file for queue entry %s in %s", qfs->name, qfs->dir); octstr_destroy(fname); return NULL; } octstr_destroy(ms); octstr_destroy(fname); return m; }
/* * Returns bearerbox ip address. Resolve it, if the address is localhost. Do * not panic here. Even if we cannot do push, we still can do pull. */ static Octstr *name(Octstr *in) { if (octstr_compare(in, octstr_imm("localhost")) != 0) return octstr_duplicate(in); else return octstr_duplicate(get_official_ip()); }
static void dlr_sdb_update(const Octstr *smsc, const Octstr *ts, const Octstr *dst, int status) { Octstr *sql, *like; int state; debug("dlr.sdb", 0, "SDB: updating DLR status in database"); if (dst) like = octstr_format("AND %S LIKE '%%%S'", fields->field_dst, dst); else like = octstr_imm(""); sql = octstr_format("UPDATE %S SET %S=%d WHERE %S='%S' AND %S='%S' %S %s", fields->table, fields->field_status, status, fields->field_smsc, smsc, fields->field_ts, ts, like, sdb_get_limit_str()); #if defined(DLR_TRACE) debug("dlr.sdb", 0, "SDB: sql: %s", octstr_get_cstr(sql)); #endif state = gw_sdb_query(octstr_get_cstr(sql), NULL, NULL); octstr_destroy(sql); octstr_destroy(like); if (state == -1) error(0, "SDB: error in updating DLR"); else if (!state) warning(0, "SDB: No dlr to update for DST<%s> (status %d)", octstr_get_cstr(dst), status); }
int main(int argc, char **argv) { int cf_index; Octstr *type; gwlib_init(); cf_index = get_and_set_debugs(argc, argv, check_args); if (argv[cf_index] == NULL) { debug("",0,"Usage: %s <store-file>", argv[0]); goto error; } type = octstr_create("file"); /* init store subsystem */ store_init(type, octstr_imm(argv[cf_index]), -1, msg_pack, msg_unpack_wrapper); /* pass every entry in the store to callback print_msg() */ store_load(print_msg); info(0, "Store file contains %d msg entries", counter); info(0, "Shutting down."); error: gwlib_shutdown(); return 1; }
/* * 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) list_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; }
static int cid_matches(List *headers, Octstr *start) { Octstr *cid = http_header_value(headers, octstr_imm("Content-ID")); char *cid_str; int cid_len; int ret; if (cid == NULL) return 0; /* First, strip the <> if any. XXX some mime coders produce such messiness! */ cid_str = octstr_get_cstr(cid); cid_len = octstr_len(cid); if (cid_str[0] == '<') { cid_str+=1; cid_len-=2; } if (start != NULL && cid != NULL && (octstr_compare(start, cid) == 0 || octstr_str_ncompare(start, cid_str, cid_len) == 0)) ret = 1; else ret = 0; octstr_destroy(cid); return ret; }
static int sqlbox_is_allowed_in_group(Octstr *group, Octstr *variable) { Octstr *groupstr; groupstr = octstr_imm("group"); #define OCTSTR(name) \ if (octstr_compare(octstr_imm(#name), variable) == 0) \ return 1; #define SINGLE_GROUP(name, fields) \ if (octstr_compare(octstr_imm(#name), group) == 0) { \ if (octstr_compare(groupstr, variable) == 0) \ return 1; \ fields \ return 0; \ } #define MULTI_GROUP(name, fields) \ if (octstr_compare(octstr_imm(#name), group) == 0) { \ if (octstr_compare(groupstr, variable) == 0) \ return 1; \ fields \ return 0; \ } #include "sqlbox-cfg.def" return 0; }
/* * Control entity headers must contain Content-Type: application/xml headers. * Rfc 2045, Appendix A does not specify the order of entity headers and states * that all rfc 822 headers having a string "Content" in their field-name must * be accepted. Rfc 822 grammar is capitulated in appendix D. * Message starts after the first null line, so only something after it can be * an extension header (or any header). */ static int check_control_headers(Octstr **body_part) { if (check_control_content_type_header(body_part, octstr_imm("\r\n\r\n")) == 0) return 0; if (drop_optional_header(body_part, "Content-Transfer-Encoding:", octstr_imm("\r\n\r\n")) == 0) return 0; if (drop_optional_header(body_part, "Content-ID:", octstr_imm("\r\n\r\n")) == 0) return 0; if (drop_optional_header(body_part, "Content-Description:", octstr_imm("\r\n\r\n")) == 0) return 0; if (drop_extension_headers(body_part, octstr_imm("\r\n\r\n")) == 0) return 0; return 1; }
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; }
static void dlr_remove_mssql(const Octstr *smsc, const Octstr *ts, const Octstr *dst) { Octstr *sql, *like; DBPoolConn *pconn; int res; debug("dlr.mssql", 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 '%%%S'", fields->field_dst, dst); else like = octstr_imm(""); sql = octstr_format("SET ROWCOUNT 1\nDELETE FROM %S WHERE %S='%S' AND " "%S='%S' %S \nSET ROWCOUNT 0", fields->table, fields->field_smsc, smsc, fields->field_ts, ts, like); #if defined(DLR_TRACE) debug("dlr.mssql", 0, "sql: %s", octstr_get_cstr(sql)); #endif if ((res = dbpool_conn_update(pconn, sql, NULL)) == -1) error(0, "DLR: MSSQL: Error while removing dlr entry for DST<%s>", octstr_get_cstr(dst)); else if (!res) warning(0, "DLR: MSSQL: No dlr deleted for DST<%s>", octstr_get_cstr(dst)); dbpool_conn_produce(pconn); octstr_destroy(sql); octstr_destroy(like); }
int main() { Octstr *os; long i; gw_prioqueue_t *queue; gwlib_init(); /* os = octstr_imm("iareanmsgotx"); */ os = octstr_imm("123456789"); queue = gw_prioqueue_create(my_cmp); for (i=0; i < octstr_len(os); i++) { char a[2]; a[0] = octstr_get_char(os, i); a[1] = '\0'; gw_prioqueue_insert(queue, octstr_create(a)); } gw_prioqueue_foreach(queue, my_dump); while ((os = gw_prioqueue_remove(queue))) { debug("", 0, "%s", octstr_get_cstr(os)); octstr_destroy(os); } debug("", 0, "gw_prioqueue_len=%ld", gw_prioqueue_len(queue)); gwlib_shutdown(); return 0; }
static void dlr_update_mssql(const Octstr *smsc, const Octstr *ts, const Octstr *dst, int status) { Octstr *sql, *like; DBPoolConn *pconn; int res; debug("dlr.mssql", 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 '%%%S'", fields->field_dst, dst); else like = octstr_imm(""); sql = octstr_format("SET ROWCOUNT 1\nUPDATE %S SET %S=%d WHERE %S='%S' " "AND %S='%S' %S\nSET ROWCOUNT 0", fields->table, fields->field_status, status, fields->field_smsc, smsc, fields->field_ts, ts, like); #if defined(DLR_TRACE) debug("dlr.mssql", 0, "sql: %s", octstr_get_cstr(sql)); #endif if ((res = dbpool_conn_update(pconn, sql, NULL)) == -1) error(0, "DLR: MSSQL: Error while updating dlr entry for DST<%s>", octstr_get_cstr(dst)); else if (!res) warning(0, "DLR: MSSQL: No dlr found to update for DST<%s> (status: %d)", octstr_get_cstr(dst), status); dbpool_conn_produce(pconn); octstr_destroy(sql); octstr_destroy(like); }
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(); }
/* * Extension headers are defined in rfc 822, Appendix D, as fields. We must * parse all rfc 822 headers containing a string "Content". These headers * are optional, too. For general definition of message parts see chapter 4.1. * Specifically: "everything after first null line is message body". */ static int drop_extension_headers(Octstr **body_part, Octstr *boundary) { long content_pos, next_header_pos; long next_content_part_pos; next_content_part_pos = octstr_case_search(*body_part, boundary, 0); do { if ((content_pos = octstr_case_nsearch(*body_part, octstr_imm("Content"), 0, next_content_part_pos)) < 0) return 1; if ((next_header_pos = parse_field_name(*body_part, content_pos)) < 0) return 0; if ((next_header_pos = parse_field_value(*body_part, next_header_pos)) < 0) return 0; if ((next_header_pos = parse_terminator(*body_part, next_header_pos)) == 0) return 0; } while (islwspchar(octstr_get_char(*body_part, next_header_pos))); octstr_delete(*body_part, content_pos, next_header_pos - content_pos); return 1; }