static int charset_processing(Msg *msg) { gw_assert(msg->type == sms); /* URL-decode first */ if (octstr_url_decode(msg->sms.msgdata) == -1) return -1; if (octstr_url_decode(msg->sms.udhdata) == -1) return -1; /* If a specific character encoding has been indicated by the * user, then make sure we convert to our internal representations. */ if (octstr_len(msg->sms.charset)) { if (msg->sms.coding == DC_7BIT) { /* For 7 bit, convert to UTF-8 */ if (charset_convert(msg->sms.msgdata, octstr_get_cstr(msg->sms.charset), "UTF-8") < 0) return -1; } else if (msg->sms.coding == DC_UCS2) { /* For UCS-2, convert to UTF-16BE */ if (charset_convert(msg->sms.msgdata, octstr_get_cstr(msg->sms.charset), "UTF-16BE") < 0) return -1; } } return 0; }
static void start_request(HTTPCaller *caller, List *reqh, long i) { Octstr *url, *content = NULL; long *id; if ((i % 1000) == 0) info(0, "Starting fetch %ld", i); id = gw_malloc(sizeof(long)); *id = i; url = octstr_create(urls[i % num_urls]); if (file) { octstr_append(url, octstr_imm("&text=")); octstr_append(url, msg_text); } /* add the extra headers that have been read from the file */ if (split != NULL) http_header_combine(reqh, split); /* * if a body content file has been specified, then * we assume this should be a POST */ if (content_file != NULL) { content = post_content_create(); method = HTTP_METHOD_POST; } /* * if this is a POST request then pass the required content as body to * the HTTP server, otherwise skip the body, the arguments will be * urlencoded in the URL itself. */ http_start_request(caller, method, url, reqh, content, follow_redirect, id, ssl_client_certkey_file); debug("", 0, "Started request %ld with url:", *id); octstr_url_decode(url); octstr_dump(url, 0); octstr_destroy(url); octstr_destroy(msg_text); octstr_destroy(content); }
static struct dlr_entry *dlr_redis_get(const Octstr *smsc, const Octstr *ts, const Octstr *dst) { Octstr *key, *sql; DBPoolConn *pconn; List *binds = gwlist_create(); List *result = NULL, *row; struct dlr_entry *res = NULL; pconn = dbpool_conn_consume(pool); if (pconn == NULL) { error(0, "DLR: REDIS: No connection available"); gwlist_destroy(binds, NULL); dbpool_conn_produce(pconn); return NULL; } /* If the destination address is not NULL, then * it has been shortened by the abstractive layer. */ key = octstr_format((dst ? "%S:?:?:?" : "%S:?:?"), fields->table); sql = octstr_format("HMGET %S ? ? ? ? ? ?", key); gwlist_append(binds, (Octstr *)smsc); /* key */ gwlist_append(binds, (Octstr *)ts); /* key */ if (dst) gwlist_append(binds, (Octstr *)dst); /* key */ gwlist_append(binds, fields->field_mask); gwlist_append(binds, fields->field_serv); gwlist_append(binds, fields->field_url); gwlist_append(binds, fields->field_src); gwlist_append(binds, fields->field_dst); gwlist_append(binds, fields->field_boxc); if (dbpool_conn_select(pconn, sql, binds, &result) != 0) { error(0, "DLR: REDIS: Failed to fetch DLR for %s", octstr_get_cstr(key)); octstr_destroy(sql); octstr_destroy(key); gwlist_destroy(binds, NULL); dbpool_conn_produce(pconn); return NULL; } dbpool_conn_produce(pconn); octstr_destroy(sql); octstr_destroy(key); gwlist_destroy(binds, NULL); #define LO2CSTR(r, i) octstr_get_cstr(gwlist_get(r, i)) if (gwlist_len(result) > 0) { row = gwlist_extract_first(result); /* * If we get an empty set back from redis, this is * still an array with "" values, representing (nil). * If the mask is empty then this can't be a valid * set, therefore bail out. */ if (octstr_len(gwlist_get(row, 0)) > 0) { res = dlr_entry_create(); gw_assert(res != NULL); res->mask = atoi(octstr_get_cstr(gwlist_get(row, 0))); get_octstr_value(&res->service, row, 1); get_octstr_value(&res->url, row, 2); octstr_url_decode(res->url); get_octstr_value(&res->source, row, 3); get_octstr_value(&res->destination, row, 4); get_octstr_value(&res->boxc_id, row, 5); res->smsc = octstr_duplicate(smsc); octstr_replace(res->source, octstr_imm("__space__"), octstr_imm(" ")); octstr_replace(res->destination, octstr_imm("__space__"), octstr_imm(" ")); } gwlist_destroy(row, octstr_destroy_item); } gwlist_destroy(result, NULL); #undef LO2CSTR return res; }
/* MT related function */ static int brunet_send_sms(SMSCConn *conn, Msg *sms) { ConnData *conndata = conn->data; Octstr *url, *tid, *xser; List *headers; char id[UUID_STR_LEN + 1]; int dcs; /* * Construct TransactionId. * Beware that brunet needs an "clean" octstr representation, * without the dashes in the string. So remove them. */ uuid_unparse(sms->sms.id, id); tid = octstr_create(id); octstr_replace(tid, octstr_imm("-"), octstr_imm("")); /* form the basic URL */ url = octstr_format("%S?MsIsdn=%E&Originator=%E", conndata->send_url, sms->sms.receiver, sms->sms.sender); /* * We use &binfo=<foobar> from sendsms interface to encode * additional paramters. If a mandatory value is not set, * a default value is applied */ if (octstr_len(sms->sms.binfo)) { octstr_url_decode(sms->sms.binfo); octstr_format_append(url, "&%S", sms->sms.binfo); } /* CustomerId */ if (octstr_search(url, octstr_create("CustomerId="), 0) == -1) { octstr_format_append(url, "&CustomerId=%S", conndata->username); } /* TransactionId */ if (octstr_search(url, octstr_create("TransactionId="), 0) == -1) { octstr_format_append(url, "&TransactionId=%S", tid); } /* SMSCount */ if (octstr_search(url, octstr_create("SMSCount="), 0) == -1) { octstr_format_append(url, "&%s", "SMSCount=1"); } /* ActionType */ if (octstr_search(url, octstr_create("ActionType="), 0) == -1) { octstr_format_append(url, "&%s", "ActionType=A"); } /* ServiceDeliveryType */ if (octstr_search(url, octstr_create("ServiceDeliveryType="), 0) == -1) { octstr_format_append(url, "&%s", "ServiceDeliveryType=P"); } /* if coding is not set and UDH exists, assume DC_8BIT * else default to DC_7BIT */ if (sms->sms.coding == DC_UNDEF) sms->sms.coding = octstr_len(sms->sms.udhdata) > 0 ? DC_8BIT : DC_7BIT; if (sms->sms.coding == DC_8BIT) octstr_format_append(url, "&MessageType=B&Text=%H", sms->sms.msgdata); else octstr_format_append(url, "&MessageType=S&Text=%E", sms->sms.msgdata); dcs = fields_to_dcs(sms, (sms->sms.alt_dcs != SMS_PARAM_UNDEFINED ? sms->sms.alt_dcs : 0)); /* XSer processing */ xser = octstr_create(""); /* XSer DCS values */ if (dcs != 0 && dcs != 4) octstr_format_append(xser, "0201%02x", dcs & 0xff); /* add UDH header */ if (octstr_len(sms->sms.udhdata)) { octstr_format_append(xser, "01%02x%H", octstr_len(sms->sms.udhdata), sms->sms.udhdata); } if (octstr_len(xser) > 0) octstr_format_append(url, "&XSer=%S", xser); octstr_destroy(xser); headers = http_create_empty_headers(); debug("smsc.http.brunet", 0, "HTTP[%s]: Sending request <%s>", octstr_get_cstr(conn->id), octstr_get_cstr(url)); /* * Brunet requires an SSL-enabled HTTP client call, this is handled * transparently by the Kannel HTTP layer module. */ http_start_request(conndata->http_ref, HTTP_METHOD_GET, url, headers, NULL, 0, sms, NULL); octstr_destroy(url); octstr_destroy(tid); http_destroy_headers(headers); return 0; }
static void msg_to_bb(SMSCConn *conn, Octstr *line) { long p, p2; Msg *msg; Octstr *type = NULL; /* might be destroyed after error before created */ msg = msg_create(sms); p = octstr_search_char(line, ' ', 0); if (p == -1) goto error; msg->sms.sender = octstr_copy(line, 0, p); p2 = octstr_search_char(line, ' ', p + 1); if (p2 == -1) goto error; msg->sms.receiver = octstr_copy(line, p + 1, p2 - p - 1); p = octstr_search_char(line, ' ', p2 + 1); if (p == -1) goto error; type = octstr_copy(line, p2 + 1, p - p2 - 1); if (!octstr_compare(type, octstr_imm("text"))) { msg->sms.msgdata = octstr_copy(line, p + 1, LONG_MAX); msg->sms.coding = DC_7BIT; } else if (!octstr_compare(type, octstr_imm("data"))) { msg->sms.msgdata = octstr_copy(line, p + 1, LONG_MAX); msg->sms.coding = DC_8BIT; if (octstr_url_decode(msg->sms.msgdata) == -1) warning(0, "smsc_fake: urlcoded data from client looks malformed"); } else if (!octstr_compare(type, octstr_imm("route"))) { p2 = octstr_search_char(line, ' ', p + 1); if (p2 == -1) goto error; msg->sms.boxc_id = octstr_copy(line, p + 1, p2 - p - 1); msg->sms.msgdata = octstr_copy(line, p2 + 1, LONG_MAX); } else if (!octstr_compare(type, octstr_imm("udh"))) { p2 = octstr_search_char(line, ' ', p + 1); if (p2 == -1) goto error; msg->sms.udhdata = octstr_copy(line, p + 1, p2 - p - 1); msg->sms.msgdata = octstr_copy(line, p2 + 1, LONG_MAX); if (msg->sms.coding == DC_UNDEF) msg->sms.coding = DC_8BIT; if (octstr_url_decode(msg->sms.msgdata) == -1 || octstr_url_decode(msg->sms.udhdata) == -1) warning(0, "smsc_fake: urlcoded data from client looks malformed"); } else if (!octstr_compare(type, octstr_imm("dlr-mask"))) { Octstr *tmp; p2 = octstr_search_char(line, ' ', p + 1); if (p2 == -1) goto error; tmp = octstr_copy(line, p + 1, p2 - p - 1); msg->sms.dlr_mask = atoi(octstr_get_cstr(tmp)); octstr_destroy(tmp); msg->sms.msgdata = octstr_copy(line, p2 + 1, LONG_MAX); } else goto error; octstr_destroy(line); octstr_destroy(type); time(&msg->sms.time); msg->sms.smsc_id = octstr_duplicate(conn->id); debug("bb.sms", 0, "smsc_fake: new message received"); /* msg_dump(msg, 0); */ bb_smscconn_receive(conn, msg); return; error: warning(0, "smsc_fake: invalid message syntax from client, ignored"); msg_destroy(msg); octstr_destroy(line); octstr_destroy(type); return; }