static void send_packet(Octstr *out, int opcode, int sequence, ...) { va_list ap; int parm; unsigned char *value; int checksum; int old_len, new_len; if (activity == ACT_listen) return; old_len = octstr_len(out); octstr_format_append(out, "%c%02d:%03d%c", STX, opcode, sequence, TAB); va_start(ap, sequence); for (parm = va_arg(ap, int); parm != 0; parm = va_arg(ap, int)) { value = va_arg(ap, unsigned char *); octstr_format_append(out, "%03d:%s\11", parm, value); } va_end(ap); /* Calculate checksum */ checksum = 0; for (new_len = octstr_len(out); old_len < new_len; old_len++) { checksum = (checksum + octstr_get_char(out, old_len)) & 0xff; } octstr_format_append(out, "%02X%c", checksum, ETX); }
static void add_delimiter(Octstr **content) { if (octstr_compare(delimiter, octstr_imm("crlf")) == 0) { octstr_format_append(*content, "%c", '\r'); } octstr_format_append(*content, "%c", '\n'); }
/* * Output the wbxml content field after field into octet string os. We add * string table length 0 (meaning no string table) before the content. */ void simple_binary_output(Octstr *os, simple_binary_t *binary) { gw_assert(octstr_len(os) == 0); octstr_format_append(os, "%c", binary->wbxml_version); octstr_format_append(os, "%c", binary->public_id); octstr_append_uintvar(os, binary->charset); octstr_format_append(os, "%c", 0x00); octstr_format_append(os, "%S", binary->binary); }
static Octstr *make_close_delimiter(Octstr *boundary) { Octstr *close_delimiter; close_delimiter = octstr_create(""); add_delimiter(&close_delimiter); octstr_format_append(close_delimiter, "%s", "--"); octstr_append(close_delimiter, boundary); octstr_format_append(close_delimiter, "%s", "--"); /*add_delimiter(&close_delimiter);*/ return close_delimiter; }
/* * 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; }
int main(void) { Octstr *os, *os2, *os3, *os4; gwlib_init(); os = octstr_format("hi, %% %-5.*s, <%*s>, %-5d + %05d = %d, -%5.2f", 3, "world", 3, "", 1, 2, 3, 3.1415927); octstr_dump(os, 0); os2 = octstr_format("<%S>", os); octstr_dump(os2, 0); octstr_format_append(os2, "yeehaa!"); octstr_dump(os2, 0); os3 = octstr_format("NULL=%p &os=%p", (void *) NULL, (void *) &os); octstr_dump(os3, 0); os4 = octstr_format("Encode %E and limited %-10.10E", os, os); octstr_dump(os4, 0); octstr_destroy(os); octstr_destroy(os2); octstr_destroy(os3); gwlib_shutdown(); return 0; }
static Octstr *make_close_delimiter(Octstr *boundary) { Octstr *close_delimiter; close_delimiter = make_part_delimiter(boundary); octstr_format_append(close_delimiter, "%s", "--"); return close_delimiter; }
/* * Add global tokens to the start and to the end of an inline string. */ void parse_inline_string(Octstr *temp, simple_binary_t **binary) { Octstr *startos; octstr_insert(temp, startos = octstr_format("%c", WBXML_STR_I), 0); octstr_destroy(startos); octstr_format_append(temp, "%c", WBXML_STR_END); parse_octet_string(temp, binary); }
/* * Format for port UDH is defined in wdp, appendix A. It is %06%05%04 * %dest port high hex%dest port low%hex source port high hex%source port low * hex. (Unsecure) push client port itself is 2948. */ static Octstr *pack_udhdata(WAPAddrTuple *tuple) { int source_port, dest_port; Octstr *udh; source_port = tuple->local->port; dest_port = tuple->remote->port; udh = octstr_create(""); octstr_format_append(udh, "%c", 6); octstr_format_append(udh, "%c", 5); octstr_format_append(udh, "%c", 4); octstr_format_append(udh, "%c", (dest_port >> 8) & 0xff); octstr_format_append(udh, "%c", dest_port & 0xff); octstr_format_append(udh, "%c", (source_port >> 8) & 0xff); octstr_format_append(udh, "%c", source_port & 0xff); return udh; }
static Octstr *make_part_delimiter(Octstr *boundary) { Octstr *part_delimiter; part_delimiter = octstr_create(""); add_delimiter(&part_delimiter); octstr_format_append(part_delimiter, "%s", "--"); octstr_append(part_delimiter, boundary); add_delimiter(&part_delimiter); return part_delimiter; }
static Octstr *linearise_string_list(List *l, char *sep) { int i, n; Octstr *s = octstr_create(""); for (i = 0, n = gwlist_len(l); i < n; i++) { Octstr *p = gwlist_get(l,i); if (p) octstr_format_append(s, "%s%S", (i == 0) ? "" : sep, p); } return s; }
int ota_pack_message(Msg **msg, Octstr *ota_doc, Octstr *doc_type, Octstr *from, Octstr *phone_number, Octstr *sec, Octstr *pin) { Octstr *ota_binary; *msg = msg_create(sms); (*msg)->sms.sms_type = mt_push; ota_pack_udh(msg, doc_type); if (ota_compile(ota_doc, octstr_imm("UTF-8"), &ota_binary) == -1) goto cerror; if (!ota_pack_push_headers(msg, doc_type, sec, pin, ota_binary)) goto herror; octstr_format_append((*msg)->sms.msgdata, "%S", ota_binary); (*msg)->sms.sender = octstr_duplicate(from); (*msg)->sms.receiver = octstr_duplicate(phone_number); (*msg)->sms.coding = DC_8BIT; (*msg)->sms.time = time(NULL); octstr_dump((*msg)->sms.msgdata, 0); info(0, "/cgi-bin/sendota: XML request for target <%s>", octstr_get_cstr(phone_number)); octstr_destroy(ota_binary); octstr_destroy(ota_doc); octstr_destroy(doc_type); octstr_destroy(from); octstr_destroy(sec); octstr_destroy(pin); return 0; herror: octstr_destroy(ota_binary); octstr_destroy(ota_doc); octstr_destroy(doc_type); octstr_destroy(from); octstr_destroy(sec); octstr_destroy(pin); return -2; cerror: octstr_destroy(ota_doc); octstr_destroy(doc_type); octstr_destroy(from); octstr_destroy(sec); octstr_destroy(pin); return -1; }
/* This function checks that there is a boundary parameter in the headers * for a multipart MIME object. If not, it is inserted and passed back to caller * in the variable boundary_elem. */ static void fix_boundary_element(List *headers, Octstr **boundary_elem) { Octstr *value, *boundary; long len; /* * Check if we have an boundary parameter already in the * Content-Type header. If no, add one, otherwise parse which one * we should use. * XXX this can be abstracted as function in gwlib/http.[ch]. */ value = http_header_value(headers, octstr_imm("Content-Type")); boundary = value ? http_get_header_parameter(value, octstr_imm("boundary")) : NULL; if (value == NULL) { /* we got here because it is multi-part, so... */ value = octstr_create("multipart/mixed"); http_header_add(headers, "Content-Type", "multipart/mixed"); } if (boundary == NULL) { Octstr *v; boundary = octstr_format("_boundary_%d_%ld_%c_%c_bd%d", random(), (long) time(NULL), 'A' + (random() % 26), 'a' + (random() % 26), random()); octstr_format_append(value, "; boundary=%S", boundary); http_header_remove_all(headers, "Content-Type"); http_header_add(headers, "Content-Type", octstr_get_cstr(value)); if ((v = http_header_value(headers, octstr_imm("MIME-Version"))) == NULL) http_header_add(headers, "MIME-Version", "1.0"); else octstr_destroy(v); } else if ((len = octstr_len(boundary)) > 0 && octstr_get_char(boundary, 0) == '"' && octstr_get_char(boundary, len - 1) == '"') { octstr_delete(boundary, 0, 1); octstr_delete(boundary, len - 2, 1); } octstr_destroy(value); if (boundary_elem) *boundary_elem = boundary; else octstr_destroy(boundary); }
static void status_cb(const Octstr *filename, void *d) { struct status *data = d; struct tm tm; char id[UUID_STR_LEN + 1]; Octstr *msg_s; Msg *msg; msg_s = octstr_read_file(octstr_get_cstr(filename)); msg = store_msg_unpack(msg_s); octstr_destroy(msg_s); if (msg == NULL) return; /* transform the time value */ #if LOG_TIMESTAMP_LOCALTIME tm = gw_localtime(msg->sms.time); #else tm = gw_gmtime(msg->sms.time); #endif if (msg->sms.udhdata) octstr_binary_to_hex(msg->sms.udhdata, 1); if (msg->sms.msgdata && (msg->sms.coding == DC_8BIT || msg->sms.coding == DC_UCS2 || (msg->sms.coding == DC_UNDEF && msg->sms.udhdata))) octstr_binary_to_hex(msg->sms.msgdata, 1); uuid_unparse(msg->sms.id, id); octstr_format_append(data->status, data->format, id, (msg->sms.sms_type == mo ? "MO" : msg->sms.sms_type == mt_push ? "MT-PUSH" : msg->sms.sms_type == mt_reply ? "MT-REPLY" : msg->sms.sms_type == report_mo ? "DLR-MO" : msg->sms.sms_type == report_mt ? "DLR-MT" : ""), tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec, (msg->sms.sender ? octstr_get_cstr(msg->sms.sender) : ""), (msg->sms.receiver ? octstr_get_cstr(msg->sms.receiver) : ""), (msg->sms.smsc_id ? octstr_get_cstr(msg->sms.smsc_id) : ""), (msg->sms.boxc_id ? octstr_get_cstr(msg->sms.boxc_id) : ""), (msg->sms.udhdata ? octstr_get_cstr(msg->sms.udhdata) : ""), (msg->sms.msgdata ? octstr_get_cstr(msg->sms.msgdata) : "")); msg_destroy(msg); }
int main(void) { Octstr *os, *os2, *os3, *os4, *os5; unsigned long long n = 18446744073709551615ull; gwlib_init(); os = octstr_format("hi, %% %-5.*s, <%*s>, %-5d + %05d = %d, -%5.2f", 3, "world", 3, "", 1, 2, 3, 3.1415927); octstr_dump(os, 0); os2 = octstr_format("<%S>", os); octstr_dump(os2, 0); octstr_format_append(os2, "yeehaa!"); octstr_dump(os2, 0); os3 = octstr_format("NULL=%p &os=%p", (void *) NULL, (void *) &os); octstr_dump(os3, 0); os4 = octstr_format("Encode %E and limited %-10.10E", os, os); octstr_dump(os4, 0); os5 = octstr_format("Encode %%llu: %llu", n); octstr_dump(os5, 0); octstr_destroy(os); octstr_destroy(os2); octstr_destroy(os3); octstr_destroy(os4); octstr_destroy(os5); gwlib_shutdown(); return 0; }
static void status_cb(Msg *msg, void *d) { struct status *data = d; struct tm tm; char id[UUID_STR_LEN + 1]; if (msg == NULL) return; /* transform the time value */ #if LOG_TIMESTAMP_LOCALTIME tm = gw_localtime(msg->sms.time); #else tm = gw_gmtime(msg->sms.time); #endif uuid_unparse(msg->sms.id, id); octstr_format_append(data->status, data->format, id, (msg->sms.sms_type == mo ? "MO" : msg->sms.sms_type == mt_push ? "MT-PUSH" : msg->sms.sms_type == mt_reply ? "MT-REPLY" : msg->sms.sms_type == report_mo ? "DLR-MO" : msg->sms.sms_type == report_mt ? "DLR-MT" : ""), tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec, (msg->sms.sender ? octstr_get_cstr(msg->sms.sender) : ""), (msg->sms.receiver ? octstr_get_cstr(msg->sms.receiver) : ""), (msg->sms.smsc_id ? octstr_get_cstr(msg->sms.smsc_id) : ""), (msg->sms.boxc_id ? octstr_get_cstr(msg->sms.boxc_id) : ""), msg->sms.mclass, msg->sms.coding, msg->sms.mwi, msg->sms.compress, msg->sms.dlr_mask, (msg->sms.udhdata ? msg->sms.udhdata : octstr_imm("")), (msg->sms.msgdata ? msg->sms.msgdata : octstr_imm(""))); }
int main(int argc, char **argv) { Octstr *mime_content, *pap_content, *push_data, *rdf_content, *boundary, *push_content_file = NULL, *this_header, *pap_osname, *data_osname; List *content_headers, *source_parts; char *pap_content_file, *push_data_file, *rdf_content_file; int ret, std_out, opt, d_file, c_file; FILE *fp1, *fp2, *fp3; gwlib_init(); std_out = 0; d_file = 0; c_file = 0; data_osname = NULL; pap_osname = NULL; while ((opt = getopt(argc, argv, "hd:sc:")) != EOF) { switch(opt) { case 'h': help(); exit(1); break; case 'd': d_file = 1; data_osname = octstr_create(optarg); break; case 'c': c_file = 1; pap_osname = octstr_create(optarg); break; case 's': std_out = 1; break; case '?': default: error(0, "Invalid option %c", opt); help(); panic(0, "Stopping"); break; } } if (optind >= argc) { help(); panic(0, "missing arguments, stopping"); } if (!c_file) pap_content_file = "test/pap.txt"; else pap_content_file = octstr_get_cstr(pap_osname); if (!d_file) push_data_file = "test/data.txt"; else push_data_file = octstr_get_cstr(data_osname); rdf_content_file = "test/rdf.txt"; mime_content = octstr_read_file(argv[optind]); if (mime_content == NULL) { octstr_destroy(mime_content); error(0, "No MIME source"); panic(0, "Stopping"); } source_parts = octstr_split(mime_content, octstr_imm("content=")); if (gwlist_len(source_parts) == 1) { /* a hack to circumvent a bug */ error(0, "Badly formatted source:"); octstr_destroy(mime_content); gwlist_destroy(source_parts, octstr_destroy_item); panic(0, "Stopping"); } boundary = gwlist_extract_first(source_parts); octstr_delete(boundary, 0, octstr_len(octstr_imm("boundary="))); if (skip_tail(&boundary, ';') == 0) { error(0, "Cannot determine boundary, no delimiter; possible"); octstr_dump(boundary, 0); goto no_parse; } octstr_destroy(mime_content); mime_content = gwlist_extract_first(source_parts); if (skip_tail(&mime_content, ';') == 0){ error(0, "Cannot determine mime content, no delimiter"); octstr_dump(mime_content, 0); goto no_parse; } prepend_crlf(&mime_content); add_crs(mime_content); append_crlf(mime_content); ret = mime_parse(boundary, mime_content, &pap_content, &push_data, &content_headers, &rdf_content); if (ret == 0) { error(0, "Mime_parse returned 0, cannot continue"); goto error; } remove_crs(pap_content); if (!std_out) { fp1 = fopen(pap_content_file, "a"); if (fp1 == NULL) { error(0, "Cannot open the file for pap control message"); goto error; } octstr_print(fp1, pap_content); debug("test.mime", 0, "pap control message appended to the file"); fclose(fp1); } else { debug("test.mime", 0, "pap control message was"); octstr_dump(pap_content, 0); } remove_crs(push_data); if (!std_out) { fp2 = fopen(push_data_file, "a"); if (fp2 == NULL) { error(0, "Cannot open the push data file"); goto error; } push_content_file = octstr_create(""); octstr_append(push_content_file, octstr_imm("headers=")); while (gwlist_len(content_headers) > 0) { octstr_append(push_content_file, this_header = gwlist_extract_first(content_headers)); octstr_format_append(push_content_file, "%c", ' '); octstr_destroy(this_header); } octstr_append(push_content_file, octstr_imm(";\n")); octstr_append(push_content_file, octstr_imm("content=")); octstr_append(push_content_file, push_data); octstr_append(push_content_file, octstr_imm(";\n")); octstr_print(fp2, push_content_file); debug("test.mime", 0, "push content appended to the file"); fclose(fp2); } else { debug("test.mime", 0, "Content headers were"); http_header_dump(content_headers); debug("test.mime", 0, "And push content itself"); octstr_dump(push_data, 0); } if (rdf_content != NULL) remove_crs(rdf_content); if (!std_out && rdf_content != NULL) { fp3 = NULL; if (rdf_content != NULL) { fp3 = fopen(rdf_content_file, "a"); if (fp3 == NULL) { error(0, "Cannot open the rdf file"); goto cerror; } octstr_print(fp3, rdf_content); debug("test.mime", 0, "push caps message appended to the file"); fclose(fp3); } } else { if (rdf_content != NULL) { debug("test.mime", 0, "push caps message was"); octstr_dump(rdf_content, 0); } } octstr_destroy(boundary); octstr_destroy(mime_content); octstr_destroy(pap_content); octstr_destroy(push_data); octstr_destroy(rdf_content); octstr_destroy(pap_osname); octstr_destroy(data_osname); http_destroy_headers(content_headers); gwlist_destroy(source_parts, octstr_destroy_item); octstr_destroy(push_content_file); gwlib_shutdown(); info(0, "MIME data parsed successfully"); return 0; no_parse: octstr_destroy(mime_content); octstr_destroy(pap_osname); octstr_destroy(data_osname); gwlist_destroy(source_parts, octstr_destroy_item); octstr_destroy(boundary); gwlib_shutdown(); panic(0, "Stopping"); error: octstr_destroy(mime_content); gwlist_destroy(source_parts, octstr_destroy_item); octstr_destroy(boundary); octstr_destroy(pap_content); octstr_destroy(push_data); octstr_destroy(pap_osname); octstr_destroy(data_osname); http_destroy_headers(content_headers); octstr_destroy(rdf_content); gwlib_shutdown(); panic(0, "Stopping"); cerror: octstr_destroy(mime_content); gwlist_destroy(source_parts, octstr_destroy_item); octstr_destroy(boundary); octstr_destroy(pap_content); octstr_destroy(push_data); octstr_destroy(push_content_file); octstr_destroy(pap_osname); octstr_destroy(data_osname); http_destroy_headers(content_headers); octstr_destroy(rdf_content); gwlib_shutdown(); panic(0, "Stopping"); /* return after panic always required by gcc */ return 1; }
static int kannel_send_sms(SMSCConn *conn, Msg *sms) { ConnData *conndata = conn->data; Octstr *url; List *headers; if (!conndata->no_sep) { url = octstr_format("%S?" "username=%E&password=%E&to=%E&text=%E", conndata->send_url, conndata->username, conndata->password, sms->sms.receiver, sms->sms.msgdata); } else { Octstr *msgdata = octstr_duplicate(sms->sms.msgdata); octstr_binary_to_hex(msgdata, HEX_NOT_UPPERCASE); url = octstr_format("%S?" "username=%E&password=%E&to=%E&text=%S", conndata->send_url, conndata->username, conndata->password, sms->sms.receiver, msgdata); octstr_destroy(msgdata); } if (octstr_len(sms->sms.udhdata)) { if (!conndata->no_sep) { octstr_format_append(url, "&udh=%E", sms->sms.udhdata); } else { Octstr *udhdata = octstr_duplicate(sms->sms.udhdata); octstr_binary_to_hex(udhdata, HEX_NOT_UPPERCASE); octstr_format_append(url, "&udh=%S", udhdata); octstr_destroy(udhdata); } } if (!conndata->no_sender) octstr_format_append(url, "&from=%E", sms->sms.sender); if (sms->sms.mclass != MC_UNDEF) octstr_format_append(url, "&mclass=%d", sms->sms.mclass); if (!conndata->no_coding && sms->sms.coding != DC_UNDEF) octstr_format_append(url, "&coding=%d", sms->sms.coding); /* Obey that smsbox's sendsms HTTP interface is still expecting * WINDOWS-1252 as default charset, while all other internal parts * use UTF-8 as internal encoding. This means, when we pass a SMS * into a next Kannel instance, we need to let the smsbox know which * charset we have in use. * XXX TODO: change smsbox interface to use UTF-8 as default * in next major release. */ if (sms->sms.coding == DC_7BIT) octstr_append_cstr(url, "&charset=UTF-8"); else if (sms->sms.coding == DC_UCS2) octstr_append_cstr(url, "&charset=UTF-16BE"); if (sms->sms.mwi != MWI_UNDEF) octstr_format_append(url, "&mwi=%d", sms->sms.mwi); if (sms->sms.account) /* prepend account with local username */ octstr_format_append(url, "&account=%E:%E", sms->sms.service, sms->sms.account); if (sms->sms.binfo) /* prepend billing info */ octstr_format_append(url, "&binfo=%S", sms->sms.binfo); if (sms->sms.smsc_id) /* proxy the smsc-id to the next instance */ octstr_format_append(url, "&smsc=%S", sms->sms.smsc_id); if (conndata->dlr_url) { char id[UUID_STR_LEN + 1]; Octstr *mid; /* create Octstr from UUID */ uuid_unparse(sms->sms.id, id); mid = octstr_create(id); octstr_format_append(url, "&dlr-url=%E", conndata->dlr_url); /* encapsulate the original DLR-URL, escape code for DLR mask * and message id */ octstr_format_append(url, "%E%E%E%E%E", octstr_imm("&dlr-url="), sms->sms.dlr_url != NULL ? sms->sms.dlr_url : octstr_imm(""), octstr_imm("&dlr-mask=%d"), octstr_imm("&dlr-mid="), mid); octstr_destroy(mid); } else if (sms->sms.dlr_url != NULL) octstr_format_append(url, "&dlr-url=%E", sms->sms.dlr_url); if (sms->sms.dlr_mask != DLR_UNDEFINED && sms->sms.dlr_mask != DLR_NOTHING) octstr_format_append(url, "&dlr-mask=%d", sms->sms.dlr_mask); if (sms->sms.validity != SMS_PARAM_UNDEFINED) octstr_format_append(url, "&validity=%ld", (sms->sms.validity - time(NULL)) / 60); if (sms->sms.deferred != SMS_PARAM_UNDEFINED) octstr_format_append(url, "&deferred=%ld", (sms->sms.deferred - time(NULL)) / 60); headers = gwlist_create(); debug("smsc.http.kannel", 0, "HTTP[%s]: Start request", octstr_get_cstr(conn->id)); http_start_request(conndata->http_ref, HTTP_METHOD_GET, url, headers, NULL, 0, sms, NULL); octstr_destroy(url); http_destroy_headers(headers); return 0; }
Msg *ota_tokenize_bookmarks(CfgGroup *grp, Octstr *from, Octstr *receiver) { Octstr *url, *name; Msg *msg; url = NULL; name = NULL; url = cfg_get(grp, octstr_imm("url")); name = cfg_get(grp, octstr_imm("name")); msg = msg_create(sms); /* * Append the User Data Header (UDH) including the length (UDHL) * WDP layer (start WDP headers) */ msg->sms.sms_type = mt_push; msg->sms.udhdata = octstr_create(""); octstr_append_from_hex(msg->sms.udhdata, "060504C34FC002"); /* WDP layer (end WDP headers) */ /* * WSP layer (start WSP headers) */ msg->sms.msgdata = octstr_create(""); /* PUSH ID, PDU type, header length, value length */ octstr_append_from_hex(msg->sms.msgdata, "01062D1F2B"); /* MIME-type: application/x-wap-prov.browser-bookmarks */ octstr_format_append(msg->sms.msgdata, "%s", "application/x-wap-prov.browser-bookmarks"); octstr_append_from_hex(msg->sms.msgdata, "00"); /* charset UTF-8 */ octstr_append_from_hex(msg->sms.msgdata, "81EA"); /* WSP layer (end WSP headers) */ /* * WSP layer (start WSP data field) */ /* WBXML version 1.1 */ octstr_append_from_hex(msg->sms.msgdata, "0101"); /* charset UTF-8 */ octstr_append_from_hex(msg->sms.msgdata, "6A00"); /* CHARACTERISTIC_LIST */ octstr_append_from_hex(msg->sms.msgdata, "45"); /* CHARACTERISTIC with content and attributes */ octstr_append_from_hex(msg->sms.msgdata, "C6"); /* TYPE=BOOKMARK */ octstr_append_char(msg->sms.msgdata, WBXML_TOK_TYPE_BOOKMARK); octstr_append_char(msg->sms.msgdata, WBXML_TOK_END); /* name */ if (name != NULL) { /* PARM with attributes */ octstr_append_from_hex(msg->sms.msgdata, "87"); /* NAME=PROXY, VALUE, inline string */ octstr_append_char(msg->sms.msgdata, WBXML_TOK_NAME_NAME); octstr_append_char(msg->sms.msgdata, WBXML_TOK_VALUE); octstr_append_char(msg->sms.msgdata, WBXML_TOK_STR_I); octstr_append(msg->sms.msgdata, octstr_duplicate(name)); octstr_append_char(msg->sms.msgdata, WBXML_TOK_END_STR_I); octstr_append_char(msg->sms.msgdata, WBXML_TOK_END); } /* URL */ if (url != NULL) { /* PARM with attributes */ octstr_append_from_hex(msg->sms.msgdata, "87"); /* NAME=PROXY, VALUE, inline string */ octstr_append_char(msg->sms.msgdata, WBXML_TOK_NAME_URL); octstr_append_char(msg->sms.msgdata, WBXML_TOK_VALUE); octstr_append_char(msg->sms.msgdata, WBXML_TOK_STR_I); octstr_append(msg->sms.msgdata, octstr_duplicate(url)); octstr_append_char(msg->sms.msgdata, WBXML_TOK_END_STR_I); octstr_append_char(msg->sms.msgdata, WBXML_TOK_END); } /* end of CHARACTERISTIC */ octstr_append_char(msg->sms.msgdata, WBXML_TOK_END); /* end of CHARACTERISTIC-LIST */ octstr_append_char(msg->sms.msgdata, WBXML_TOK_END); /* WSP layer (end WSP data field) */ msg->sms.sender = from; msg->sms.receiver = octstr_duplicate(receiver); msg->sms.coding = DC_8BIT; msg->sms.time = time(NULL); octstr_destroy(name); octstr_destroy(url); return msg; }
Octstr *boxc_status(int status_type) { Octstr *tmp; char *lb, *ws; int i, boxes, para = 0; time_t orig, t; Boxc *bi; orig = time(NULL); /* * XXX: this will cause segmentation fault if this is called * between 'destroy_list and setting list to NULL calls. * Ok, this has to be fixed, but now I am too tired. */ if ((lb = bb_status_linebreak(status_type))==NULL) return octstr_create("Un-supported format"); if (status_type == BBSTATUS_HTML) ws = " "; else if (status_type == BBSTATUS_TEXT) ws = " "; else ws = ""; if (status_type == BBSTATUS_HTML || status_type == BBSTATUS_WML) para = 1; if (status_type == BBSTATUS_XML) { tmp = octstr_create (""); octstr_append_cstr(tmp, "<boxes>\n\t"); } else tmp = octstr_format("%sBox connections:%s", para ? "<p>" : "", lb); boxes = 0; if (wapbox_list) { gwlist_lock(wapbox_list); for(i=0; i < gwlist_len(wapbox_list); i++) { bi = gwlist_get(wapbox_list, i); if (bi->alive == 0) continue; t = orig - bi->connect_time; if (status_type == BBSTATUS_XML) octstr_format_append(tmp, "<box>\n\t\t<type>wapbox</type>\n\t\t<IP>%s</IP>\n" "\t\t<status>on-line %ldd %ldh %ldm %lds</status>\n" "\t\t<ssl>%s</ssl>\n\t</box>\n", octstr_get_cstr(bi->client_ip), t/3600/24, t/3600%24, t/60%60, t%60, #ifdef HAVE_LIBSSL conn_get_ssl(bi->conn) != NULL ? "yes" : "no" #else "not installed" #endif ); else octstr_format_append(tmp, "%swapbox, IP %s (on-line %ldd %ldh %ldm %lds) %s %s", ws, octstr_get_cstr(bi->client_ip), t/3600/24, t/3600%24, t/60%60, t%60, #ifdef HAVE_LIBSSL conn_get_ssl(bi->conn) != NULL ? "using SSL" : "", #else "", #endif lb); boxes++; } gwlist_unlock(wapbox_list); } if (smsbox_list) { gw_rwlock_rdlock(smsbox_list_rwlock); for(i=0; i < gwlist_len(smsbox_list); i++) { bi = gwlist_get(smsbox_list, i); if (bi->alive == 0) continue; t = orig - bi->connect_time; if (status_type == BBSTATUS_XML) octstr_format_append(tmp, "<box>\n\t\t<type>smsbox</type>\n" "\t\t<id>%s</id>\n\t\t<IP>%s</IP>\n" "\t\t<queue>%ld</queue>\n" "\t\t<status>on-line %ldd %ldh %ldm %lds</status>\n" "\t\t<ssl>%s</ssl>\n\t</box>", (bi->boxc_id ? octstr_get_cstr(bi->boxc_id) : ""), octstr_get_cstr(bi->client_ip), gwlist_len(bi->incoming) + dict_key_count(bi->sent), t/3600/24, t/3600%24, t/60%60, t%60, #ifdef HAVE_LIBSSL conn_get_ssl(bi->conn) != NULL ? "yes" : "no" #else "not installed" #endif ); else octstr_format_append(tmp, "%ssmsbox:%s, IP %s (%ld queued), (on-line %ldd %ldh %ldm %lds) %s %s", ws, (bi->boxc_id ? octstr_get_cstr(bi->boxc_id) : "(none)"), octstr_get_cstr(bi->client_ip), gwlist_len(bi->incoming) + dict_key_count(bi->sent), t/3600/24, t/3600%24, t/60%60, t%60, #ifdef HAVE_LIBSSL conn_get_ssl(bi->conn) != NULL ? "using SSL" : "", #else "", #endif lb); boxes++; } gw_rwlock_unlock(smsbox_list_rwlock); } if (boxes == 0 && status_type != BBSTATUS_XML) { octstr_destroy(tmp); tmp = octstr_format("%sNo boxes connected", para ? "<p>" : ""); } if (para) octstr_append_cstr(tmp, "</p>"); if (status_type == BBSTATUS_XML) octstr_append_cstr(tmp, "</boxes>\n"); else octstr_append_cstr(tmp, "\n\n"); return tmp; }
int operate_single_mime(Octstr *p_psoHdrs, MIMEEntity *p_psoMIME, const char *p_pszWebDir) { int iRetVal = 0; Octstr *psoHdrName = NULL, *psoHdrValue = NULL; Octstr *psoMIMEOStr = NULL, *psoFileName = NULL; List *psoHdrList = NULL; int iFile = -1; if(psoMIMEOStr) { octstr_destroy(psoMIMEOStr); } /* выбираем необходимые заголовки */ psoHdrList = mime_entity_headers(p_psoMIME); /* Content-type */ psoHdrName = octstr_create("Content-type"); psoHdrValue = http_header_value(psoHdrList, psoHdrName); if(0 == strncasecmp("application/smil", octstr_get_cstr(psoHdrValue), 16)) { goto done; } octstr_format_append(p_psoHdrs, "\r\n"); octstr_format_append(p_psoHdrs, "\r\n%S;%S", psoHdrName, psoHdrValue); octstr_truncate(psoHdrName, 0); /* Content-location */ octstr_append_cstr(psoHdrName, "Content-location"); psoHdrValue = http_header_value(psoHdrList, psoHdrName); octstr_format_append(p_psoHdrs, "\r\n%S;%S", psoHdrName, psoHdrValue); octstr_truncate(psoHdrName, 0); /**/ /* формируем имя файла */ psoFileName = octstr_create(p_pszWebDir); if('/' != octstr_get_char(psoFileName, octstr_len(psoFileName) - 1)) { octstr_append_char(psoFileName, '/'); } octstr_append(psoFileName, psoHdrValue); /* создаем файл */ iFile = open(octstr_get_cstr(psoFileName), O_CREAT | O_EXCL | O_WRONLY, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); if(0 > iFile) { if(errno != EEXIST) { iRetVal = 7; goto done; } } psoMIMEOStr = mime_entity_body(p_psoMIME); octstr_base64_to_binary(psoMIMEOStr); if(octstr_len(psoMIMEOStr) != write(iFile, octstr_get_cstr(psoMIMEOStr), octstr_len(psoMIMEOStr))) { iRetVal = 8; goto done; } done: if(psoHdrName) { octstr_destroy(psoHdrName); } if(psoFileName) { octstr_destroy(psoFileName); } if(0 < iFile) { close(iFile); } return iRetVal; }
Octstr *urltrans_fill_escape_codes(Octstr *pattern, Msg *request) { Octstr *enc; Octstr *meta_group, *meta_param; int nextarg, j; struct tm tm; int num_words; List *word_list; Octstr *result; long pattern_len; long pos; int c; long i, k; Octstr *temp; result = octstr_create(""); if (request->sms.msgdata) { word_list = octstr_split_words(request->sms.msgdata); num_words = gwlist_len(word_list); } else { word_list = gwlist_create(); num_words = 0; } pattern_len = octstr_len(pattern); nextarg = 1; pos = 0; for (;;) { while (pos < pattern_len) { c = octstr_get_char(pattern, pos); if (c == '%' && pos + 1 < pattern_len) break; octstr_append_char(result, c); ++pos; } if (pos == pattern_len) break; switch (octstr_get_char(pattern, pos + 1)) { case 'a': for (j = 0; j < num_words; ++j) { enc = octstr_duplicate(gwlist_get(word_list, j)); octstr_url_encode(enc); if (j > 0) octstr_append_char(result, '+'); octstr_append(result, enc); octstr_destroy(enc); } break; case 'A': if (request->sms.msgdata) { enc = octstr_duplicate(request->sms.msgdata); octstr_url_encode(enc); octstr_append(result, enc); octstr_destroy(enc); } break; case 'b': enc = octstr_duplicate(request->sms.msgdata); octstr_url_encode(enc); octstr_append(result, enc); octstr_destroy(enc); break; case 'B': /* billing identifier/information */ if (octstr_len(request->sms.binfo)) { enc = octstr_duplicate(request->sms.binfo); octstr_url_encode(enc); octstr_append(result, enc); octstr_destroy(enc); } break; case 'c': octstr_append_decimal(result, request->sms.coding); break; case 'C': if (octstr_len(request->sms.charset)) { octstr_append(result, request->sms.charset); } else { switch (request->sms.coding) { case DC_UNDEF: case DC_7BIT: octstr_append(result, octstr_imm("UTF-8")); break; case DC_8BIT: octstr_append(result, octstr_imm("8-BIT")); break; case DC_UCS2: octstr_append(result, octstr_imm("UTF-16BE")); break; } } break; case 'd': enc = octstr_create(""); octstr_append_decimal(enc, request->sms.dlr_mask); octstr_url_encode(enc); octstr_append(result, enc); octstr_destroy(enc); break; case 'D': /* meta_data */ if (octstr_len(request->sms.meta_data)) { enc = octstr_duplicate(request->sms.meta_data); octstr_url_encode(enc); octstr_append(result, enc); octstr_destroy(enc); } break; case 'f': /* smsc number*/ if (octstr_len(request->sms.smsc_number)) { enc = octstr_duplicate(request->sms.smsc_number); octstr_url_encode(enc); octstr_append(result, enc); octstr_destroy(enc); } break; case 'F': if (request->sms.foreign_id == NULL) break; enc = octstr_duplicate(request->sms.foreign_id); octstr_url_encode(enc); octstr_append(result, enc); octstr_destroy(enc); break; case 'i': if (request->sms.smsc_id == NULL) break; enc = octstr_duplicate(request->sms.smsc_id); octstr_url_encode(enc); octstr_append(result, enc); octstr_destroy(enc); break; case 'I': if (!uuid_is_null(request->sms.id)) { char id[UUID_STR_LEN + 1]; uuid_unparse(request->sms.id, id); octstr_append_cstr(result, id); } break; case 'k': if (num_words <= 0) break; enc = octstr_duplicate(gwlist_get(word_list, 0)); octstr_url_encode(enc); octstr_append(result, enc); octstr_destroy(enc); break; case 'm': /* mclass - message class */ enc = octstr_create(""); octstr_append_decimal(enc, request->sms.mclass); octstr_url_encode(enc); octstr_append(result, enc); octstr_destroy(enc); break; case 'M': /* mwi - message waiting indicator */ enc = octstr_create(""); octstr_append_decimal(enc, request->sms.mwi); octstr_url_encode(enc); octstr_append(result, enc); octstr_destroy(enc); break; case 'n': if (request->sms.service == NULL) break; enc = octstr_duplicate(request->sms.service); octstr_url_encode(enc); octstr_append(result, enc); octstr_destroy(enc); break; case 'o': /* account information (may be operator id for aggregators */ if (octstr_len(request->sms.account)) { enc = octstr_duplicate(request->sms.account); octstr_url_encode(enc); octstr_append(result, enc); octstr_destroy(enc); } break; case 'O': /* DCS */ { int dcs; dcs = fields_to_dcs(request, request->sms.alt_dcs); octstr_format_append(result, "%02d", dcs); break; } /* NOTE: the sender and receiver is already switched in * message, so that's why we must use 'sender' when * we want original receiver and vice versa */ case 'P': enc = octstr_duplicate(request->sms.sender); octstr_url_encode(enc); octstr_append(result, enc); octstr_destroy(enc); break; case 'p': enc = octstr_duplicate(request->sms.receiver); octstr_url_encode(enc); octstr_append(result, enc); octstr_destroy(enc); break; case 'q': if (strncmp(octstr_get_cstr(request->sms.receiver),"00",2)==0) { enc = octstr_copy(request->sms.receiver, 2, octstr_len(request->sms.receiver)); octstr_url_encode(enc); octstr_format_append(result, "%%2B%S", enc); octstr_destroy(enc); } else { enc = octstr_duplicate(request->sms.receiver); octstr_url_encode(enc); octstr_append(result, enc); octstr_destroy(enc); } break; case 'Q': if (strncmp(octstr_get_cstr(request->sms.sender), "00", 2) == 0) { enc = octstr_copy(request->sms.sender, 2, octstr_len(request->sms.sender)); octstr_url_encode(enc); octstr_format_append(result, "%%2B%S", enc); octstr_destroy(enc); } else { enc = octstr_duplicate(request->sms.sender); octstr_url_encode(enc); octstr_append(result, enc); octstr_destroy(enc); } break; case 'r': for (j = nextarg; j < num_words; ++j) { enc = octstr_duplicate(gwlist_get(word_list, j)); octstr_url_encode(enc); if (j != nextarg) octstr_append_char(result, '+'); octstr_append(result, enc); octstr_destroy(enc); } break; case 'R': /* dlr_url */ if (octstr_len(request->sms.dlr_url)) { enc = octstr_duplicate(request->sms.dlr_url); octstr_url_encode(enc); octstr_append(result, enc); octstr_destroy(enc); } break; case 's': if (nextarg >= num_words) break; enc = octstr_duplicate(gwlist_get(word_list, nextarg)); octstr_url_encode(enc); octstr_append(result, enc); octstr_destroy(enc); ++nextarg; break; case 'S': if (nextarg >= num_words) break; temp = gwlist_get(word_list, nextarg); for (i = 0; i < octstr_len(temp); ++i) { if (octstr_get_char(temp, i) == '*') octstr_append_char(result, '~'); else octstr_append_char(result, octstr_get_char(temp, i)); } ++nextarg; break; case 't': tm = gw_gmtime(request->sms.time); octstr_format_append(result, "%04d-%02d-%02d+%02d:%02d:%02d", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec); break; case 'T': if (request->sms.time == MSG_PARAM_UNDEFINED) break; octstr_format_append(result, "%ld", request->sms.time); break; case 'u': if(octstr_len(request->sms.udhdata)) { enc = octstr_duplicate(request->sms.udhdata); octstr_url_encode(enc); octstr_append(result, enc); octstr_destroy(enc); } break; case 'v': if (request->sms.validity != MSG_PARAM_UNDEFINED) { octstr_format_append(result, "%ld", (request->sms.validity - time(NULL)) / 60); } break; case 'V': if (request->sms.deferred != MSG_PARAM_UNDEFINED) { octstr_format_append(result, "%ld", (request->sms.deferred - time(NULL)) / 60); } break; /* * This allows to pass meta-data individual parameters into urls. * The syntax is as follows: %#group#parameter# * For example: %#smpp#my_param# would be replaced with the value * 'my_param' from the group 'smpp' coming inside the meta_data field. */ case '#': /* ASCII 0x23 == '#' */ k = octstr_search_char(pattern, 0x23, pos + 2); if (k >= 0) { pos += 2; meta_group = octstr_copy(pattern, pos, (k-pos)); pos = k + 1; k = octstr_search_char(pattern, 0x23, pos); if (k >= 0) { meta_param = octstr_copy(pattern, pos, (k-pos)); pos = k - 1; if (request->sms.meta_data != NULL) { enc = meta_data_get_value(request->sms.meta_data, octstr_get_cstr(meta_group), meta_param); octstr_url_encode(enc); octstr_append(result, enc); octstr_destroy(enc); } octstr_destroy(meta_param); } else { pos++; } octstr_destroy(meta_group); } break; /* XXX sms.parameters not present in here: * * pid - will we receive this ? * * alt-dcs - shouldn't be required unless we want to inform * which alt-dcs external server should use back * * compress - if we use compression, probably kannel would * decompress and reset this to 0. not required * * rpi - we don't receive these from smsc * * username, password, dlr-url, account - nonsense to send */ case '%': octstr_format_append(result, "%%"); break; default: octstr_format_append(result, "%%%c", octstr_get_char(pattern, pos + 1)); break; } pos += 2; } gwlist_destroy(word_list, octstr_destroy_item); return result; }
static int sendMsg(MmsEnvelope *e) { MmsMsg *msg = NULL; int i, n; Octstr *otransid = e->hdrs ? http_header_value(e->hdrs, octstr_imm("X-Mbuni-TransactionID")) : NULL; if ((msg = qfs->mms_queue_getdata(e)) == NULL) { mms_error(0, "MM7", NULL, "MMSBox queue error: Failed to load message for queue id [%s]!", e->xqfname); goto done2; } for (i = 0, n = gwlist_len(e->to); i<n; i++) { int res = MMS_SEND_OK; MmsEnvelopeTo *to = gwlist_get(e->to, i); Octstr *err = NULL; time_t tnow = time(NULL); MmscGrp *mmc = NULL; Octstr *new_msgid = NULL; List *errl = NULL; int is_email = 0; if (!to || !to->process) continue; if (e->expiryt != 0 && /* Handle message expiry. */ e->expiryt < tnow) { err = octstr_format("MMSC error: Message expired while sending to %S!", to->rcpt); res = MMS_SEND_ERROR_FATAL; goto done; } else if (e->attempts >= maxsendattempts) { err = octstr_format("MMSBox error: Failed to deliver to " "%S after %ld attempts. (max attempts allowed is %ld)!", to->rcpt, e->attempts, maxsendattempts); res = MMS_SEND_ERROR_FATAL; goto done; } is_email = (octstr_search_char(to->rcpt, '@', 0) > 0); if ((mmc = get_handler_mmc(e->viaproxy, to->rcpt, e->from)) == NULL && !is_email) { err = octstr_format("MMSBox error: Failed to deliver to " "%S. Don't know how to route!", to->rcpt); res = MMS_SEND_ERROR_TRANSIENT; goto done; } if (is_email) { int j = octstr_case_search(e->from, octstr_imm("/TYPE=PLMN"), 0); int k = octstr_case_search(e->from, octstr_imm("/TYPE=IPv"), 0); int len = octstr_len(e->from); Octstr *pfrom; if (j > 0 && j - 1 + sizeof "/TYPE=PLMN" == len) pfrom = octstr_copy(e->from, 0, j); else if (k > 0 && k + sizeof "/TYPE=IPv" == len) pfrom = octstr_copy(e->from, 0, k); else pfrom = octstr_duplicate(e->from); if (octstr_search_char(e->from, '@', 0) < 0) octstr_format_append(pfrom,"@%S", myhostname); res = mms_sendtoemail(pfrom, to->rcpt, e->subject ? e->subject : octstr_imm(""), e->msgId, msg, 0, &err, octstr_get_cstr(sendmail_cmd), myhostname, 0, 0, "", "", 0, e->xqfname, e->hdrs); octstr_destroy(pfrom); } else { res = mms_sendtommsc(mmc, e, to->rcpt, otransid, msg, &new_msgid, &errl); if (errl) err = http_header_value(errl, octstr_imm("X-Mbuni-Error")); } if (mmc) { if (res == MMS_SEND_OK) mmc->mt_pdus++; else mmc->mt_errors++; mmc->last_pdu = time(NULL); return_mmsc_conn(mmc); /* important. */ } done: if (res == MMS_SEND_OK || res == MMS_SEND_QUEUED) { to->process = 0; if (e->msgtype == MMS_MSGTYPE_SEND_REQ || e->msgtype == MMS_MSGTYPE_RETRIEVE_CONF) /* queue dlr as needed. */ queue_dlr(mmc, e->from, to->rcpt, new_msgid, octstr_imm("Forwarded"), "MM7-Out", errl); } else if (res == MMS_SEND_ERROR_FATAL && mmc) { if (e->msgtype == MMS_MSGTYPE_SEND_REQ || e->msgtype == MMS_MSGTYPE_RETRIEVE_CONF) /* queue dlr as needed. */ queue_dlr(mmc, e->from, to->rcpt, e->msgId, (e->expiryt != 0 && e->expiryt < tnow) ? octstr_imm("Expired") : octstr_imm("Rejected"), "MM7-Out", errl); } if (res == MMS_SEND_ERROR_FATAL) to->process = 0; /* No more attempts. */ /* handle CDR */ if (res == MMS_SEND_OK || res == MMS_SEND_QUEUED || res == MMS_SEND_ERROR_FATAL) { Octstr *mclass = mms_get_header_value(msg, octstr_imm("X-Mms-Message-Class")); Octstr *prio = mms_get_header_value(msg, octstr_imm("X-Mms-Priority")); Octstr *mstatus = mms_get_header_value(msg, octstr_imm("X-Mms-Status")); /* Do CDR */ cdrfs->logcdr(e->created, octstr_get_cstr(e->from), octstr_get_cstr(to->rcpt), octstr_get_cstr(e->msgId), mmc ? octstr_get_cstr(mmc->id) : NULL, /* Should we touch mmc here? XXX */ e->src_interface, "MM7", e->msize, (char *)mms_message_type_to_cstr(e->msgtype), prio ? octstr_get_cstr(prio) : NULL, mclass ? octstr_get_cstr(mclass) : NULL, res == MMS_SEND_ERROR_FATAL ? "dropped" : (mstatus ? octstr_get_cstr(mstatus) : "sent"), e->dlr, 0); octstr_destroy(mclass); octstr_destroy(prio); octstr_destroy(mstatus); } if (err == NULL) mms_info(0, "MM7", NULL, "%s MMSBox Outgoing Queue MMS Send: From %s, to %s, msgsize=%ld: msgid=[%s]", SEND_ERROR_STR(res), octstr_get_cstr(e->from), octstr_get_cstr(to->rcpt), e->msize, new_msgid ? octstr_get_cstr(new_msgid) : "N/A"); else mms_error_ex("MT", 0, "MM7", NULL, "%s MMSBox Outgoing Queue MMS Send: From %s, to %s, msgsize=%ld: %s", SEND_ERROR_STR(res), octstr_get_cstr(e->from), octstr_get_cstr(to->rcpt), e->msize, octstr_get_cstr(err)); octstr_destroy(new_msgid); octstr_destroy(err); http_destroy_headers(errl); e->lasttry = tnow; if (qfs->mms_queue_update(e) == 1) { e = NULL; break; /* Queue entry gone. */ } } done2: mms_destroy(msg); octstr_destroy(otransid); if (e) { /* Update the queue if it is still valid (e.g. recipients not handled) * XXX can this happen here??... */ e->lasttry = time(NULL); e->attempts++; /* Update count of number of delivery attempts. */ e->sendt = e->lasttry + mmsbox_send_back_off * e->attempts; if (qfs->mms_queue_update(e) != 1) qfs->mms_queue_free_env(e); } return 1; /* always delete queue entry. */ }
/* * Create one URLTranslation. Return NULL for failure, pointer to it for OK. */ static URLTranslation *create_onetrans(CfgGroup *grp) { URLTranslation *ot; Octstr *url, *post_url, *post_xml, *text, *file, *exec; Octstr *accepted_smsc, *accepted_account, *forced_smsc, *default_smsc; Octstr *grpname; int is_sms_service, regex_flag = REG_EXTENDED; Octstr *accepted_smsc_regex; Octstr *accepted_account_regex; Octstr *allowed_prefix_regex; Octstr *denied_prefix_regex; Octstr *allowed_receiver_prefix_regex; Octstr *denied_receiver_prefix_regex; Octstr *white_list_regex; Octstr *black_list_regex; Octstr *keyword_regex; Octstr *os, *tmp; grpname = cfg_get_group_name(grp); if (grpname == NULL) return NULL; if (octstr_str_compare(grpname, "sms-service") == 0) is_sms_service = 1; else if (octstr_str_compare(grpname, "sendsms-user") == 0) is_sms_service = 0; else { octstr_destroy(grpname); return NULL; } octstr_destroy(grpname); ot = gw_malloc(sizeof(URLTranslation)); memset(ot, 0, sizeof(*ot)); if (is_sms_service) { cfg_get_bool(&ot->catch_all, grp, octstr_imm("catch-all")); ot->dlr_url = cfg_get(grp, octstr_imm("dlr-url")); if (cfg_get_integer(&ot->dlr_mask, grp, octstr_imm("dlr-mask")) == -1) ot->dlr_mask = DLR_UNDEFINED; ot->alt_charset = cfg_get(grp, octstr_imm("alt-charset")); url = cfg_get(grp, octstr_imm("get-url")); if (url == NULL) url = cfg_get(grp, octstr_imm("url")); post_url = cfg_get(grp, octstr_imm("post-url")); post_xml = cfg_get(grp, octstr_imm("post-xml")); file = cfg_get(grp, octstr_imm("file")); text = cfg_get(grp, octstr_imm("text")); exec = cfg_get(grp, octstr_imm("exec")); if (url != NULL) { ot->type = TRANSTYPE_GET_URL; ot->pattern = octstr_duplicate(url); } else if (post_url != NULL) { ot->type = TRANSTYPE_POST_URL; ot->pattern = octstr_duplicate(post_url); ot->catch_all = 1; } else if (post_xml != NULL) { ot->type = TRANSTYPE_POST_XML; ot->pattern = octstr_duplicate(post_xml); ot->catch_all = 1; } else if (file != NULL) { ot->type = TRANSTYPE_FILE; ot->pattern = octstr_duplicate(file); } else if (text != NULL) { ot->type = TRANSTYPE_TEXT; ot->pattern = octstr_duplicate(text); } else if (exec != NULL) { ot->type = TRANSTYPE_EXECUTE; ot->pattern = octstr_duplicate(exec); } else { octstr_destroy(url); octstr_destroy(post_url); octstr_destroy(post_xml); octstr_destroy(file); octstr_destroy(text); octstr_destroy(exec); error(0, "Configuration group `sms-service' " "did not specify get-url, post-url, post-xml, file or text."); goto error; } octstr_destroy(url); octstr_destroy(post_url); octstr_destroy(post_xml); octstr_destroy(file); octstr_destroy(text); octstr_destroy(exec); tmp = cfg_get(grp, octstr_imm("keyword")); keyword_regex = cfg_get(grp, octstr_imm("keyword-regex")); if (tmp == NULL && keyword_regex == NULL) { error(0, "Group 'sms-service' must include either 'keyword' or 'keyword-regex'."); goto error; } if (tmp != NULL && keyword_regex != NULL) { error(0, "Group 'sms-service' may inlcude either 'keyword' or 'keyword-regex'."); octstr_destroy(tmp); octstr_destroy(keyword_regex); goto error; } if (tmp != NULL && octstr_str_compare(tmp, "default") == 0) { /* default sms-service */ ot->keyword_regex = NULL; octstr_destroy(tmp); } else if (tmp != NULL) { Octstr *aliases; /* convert to regex */ regex_flag |= REG_ICASE; keyword_regex = octstr_format("^[ ]*(%S", tmp); octstr_destroy(tmp); aliases = cfg_get(grp, octstr_imm("aliases")); if (aliases != NULL) { long i; List *l; l = octstr_split(aliases, octstr_imm(";")); octstr_destroy(aliases); for (i = 0; i < gwlist_len(l); ++i) { os = gwlist_get(l, i); octstr_format_append(keyword_regex, "|%S", os); } gwlist_destroy(l, octstr_destroy_item); } octstr_append_cstr(keyword_regex, ")[ ]*"); } if (keyword_regex != NULL && (ot->keyword_regex = gw_regex_comp(keyword_regex, regex_flag)) == NULL) { error(0, "Could not compile pattern '%s'", octstr_get_cstr(keyword_regex)); octstr_destroy(keyword_regex); goto error; } ot->name = cfg_get(grp, octstr_imm("name")); if (ot->name == NULL) ot->name = keyword_regex ? octstr_duplicate(keyword_regex) : octstr_create("default"); octstr_destroy(keyword_regex); accepted_smsc = cfg_get(grp, octstr_imm("accepted-smsc")); if (accepted_smsc != NULL) { ot->accepted_smsc = octstr_split(accepted_smsc, octstr_imm(";")); octstr_destroy(accepted_smsc); } accepted_account = cfg_get(grp, octstr_imm("accepted-account")); if (accepted_account != NULL) { ot->accepted_account = octstr_split(accepted_account, octstr_imm(";")); octstr_destroy(accepted_account); } accepted_smsc_regex = cfg_get(grp, octstr_imm("accepted-smsc-regex")); if (accepted_smsc_regex != NULL) { if ( (ot->accepted_smsc_regex = gw_regex_comp(accepted_smsc_regex, REG_EXTENDED)) == NULL) panic(0, "Could not compile pattern '%s'", octstr_get_cstr(accepted_smsc_regex)); octstr_destroy(accepted_smsc_regex); } accepted_account_regex = cfg_get(grp, octstr_imm("accepted-account-regex")); if (accepted_account_regex != NULL) { if ( (ot->accepted_account_regex = gw_regex_comp(accepted_account_regex, REG_EXTENDED)) == NULL) panic(0, "Could not compile pattern '%s'", octstr_get_cstr(accepted_account_regex)); octstr_destroy(accepted_account_regex); } cfg_get_bool(&ot->assume_plain_text, grp, octstr_imm("assume-plain-text")); cfg_get_bool(&ot->accept_x_kannel_headers, grp, octstr_imm("accept-x-kannel-headers")); cfg_get_bool(&ot->strip_keyword, grp, octstr_imm("strip-keyword")); cfg_get_bool(&ot->send_sender, grp, octstr_imm("send-sender")); ot->prefix = cfg_get(grp, octstr_imm("prefix")); ot->suffix = cfg_get(grp, octstr_imm("suffix")); ot->allowed_recv_prefix = cfg_get(grp, octstr_imm("allowed-receiver-prefix")); allowed_receiver_prefix_regex = cfg_get(grp, octstr_imm("allowed-receiver-prefix-regex")); if (allowed_receiver_prefix_regex != NULL) { if ((ot->allowed_receiver_prefix_regex = gw_regex_comp(allowed_receiver_prefix_regex, REG_EXTENDED)) == NULL) panic(0, "Could not compile pattern '%s'", octstr_get_cstr(allowed_receiver_prefix_regex)); octstr_destroy(allowed_receiver_prefix_regex); } ot->allowed_recv_prefix = cfg_get(grp, octstr_imm("allowed-receiver-prefix")); ot->denied_recv_prefix = cfg_get(grp, octstr_imm("denied-receiver-prefix")); denied_receiver_prefix_regex = cfg_get(grp, octstr_imm("denied-receiver-prefix-regex")); if (denied_receiver_prefix_regex != NULL) { if ((ot->denied_receiver_prefix_regex = gw_regex_comp(denied_receiver_prefix_regex, REG_EXTENDED)) == NULL) panic(0, "Could not compile pattern '%s'",octstr_get_cstr(denied_receiver_prefix_regex)); octstr_destroy(denied_receiver_prefix_regex); } ot->args = count_occurences(ot->pattern, octstr_imm("%s")); ot->args += count_occurences(ot->pattern, octstr_imm("%S")); ot->has_catchall_arg = (count_occurences(ot->pattern, octstr_imm("%r")) > 0) || (count_occurences(ot->pattern, octstr_imm("%a")) > 0); } else { ot->type = TRANSTYPE_SENDSMS; ot->pattern = octstr_create(""); ot->args = 0; ot->has_catchall_arg = 0; ot->catch_all = 1; ot->username = cfg_get(grp, octstr_imm("username")); ot->password = cfg_get(grp, octstr_imm("password")); ot->dlr_url = cfg_get(grp, octstr_imm("dlr-url")); grp_dump(grp); if (ot->password == NULL) { error(0, "Password required for send-sms user"); goto error; } ot->name = cfg_get(grp, octstr_imm("name")); if (ot->name == NULL) ot->name = octstr_duplicate(ot->username); forced_smsc = cfg_get(grp, octstr_imm("forced-smsc")); default_smsc = cfg_get(grp, octstr_imm("default-smsc")); if (forced_smsc != NULL) { if (default_smsc != NULL) { info(0, "Redundant default-smsc for send-sms user %s", octstr_get_cstr(ot->username)); } ot->forced_smsc = forced_smsc; octstr_destroy(default_smsc); } else if (default_smsc != NULL) ot->default_smsc = default_smsc; ot->deny_ip = cfg_get(grp, octstr_imm("user-deny-ip")); ot->allow_ip = cfg_get(grp, octstr_imm("user-allow-ip")); ot->default_sender = cfg_get(grp, octstr_imm("default-sender")); } ot->allowed_prefix = cfg_get(grp, octstr_imm("allowed-prefix")); allowed_prefix_regex = cfg_get(grp, octstr_imm("allowed-prefix-regex")); if (allowed_prefix_regex != NULL) { if ((ot->allowed_prefix_regex = gw_regex_comp(allowed_prefix_regex, REG_EXTENDED)) == NULL) panic(0, "Could not compile pattern '%s'", octstr_get_cstr(allowed_prefix_regex)); octstr_destroy(allowed_prefix_regex); } ot->denied_prefix = cfg_get(grp, octstr_imm("denied-prefix")); denied_prefix_regex = cfg_get(grp, octstr_imm("denied-prefix-regex")); if (denied_prefix_regex != NULL) { if ((ot->denied_prefix_regex = gw_regex_comp(denied_prefix_regex, REG_EXTENDED)) == NULL) panic(0, "Could not compile pattern '%s'", octstr_get_cstr(denied_prefix_regex)); octstr_destroy(denied_prefix_regex); } os = cfg_get(grp, octstr_imm("white-list")); if (os != NULL) { ot->white_list = numhash_create(octstr_get_cstr(os)); octstr_destroy(os); } white_list_regex = cfg_get(grp, octstr_imm("white-list-regex")); if (white_list_regex != NULL) { if ((ot->white_list_regex = gw_regex_comp(white_list_regex, REG_EXTENDED)) == NULL) panic(0, "Could not compile pattern '%s'", octstr_get_cstr(white_list_regex)); octstr_destroy(white_list_regex); } os = cfg_get(grp, octstr_imm("black-list")); if (os != NULL) { ot->black_list = numhash_create(octstr_get_cstr(os)); octstr_destroy(os); } black_list_regex = cfg_get(grp, octstr_imm("black-list-regex")); if (black_list_regex != NULL) { if ((ot->black_list_regex = gw_regex_comp(black_list_regex, REG_EXTENDED)) == NULL) panic(0, "Could not compile pattern '%s'", octstr_get_cstr(black_list_regex)); octstr_destroy(black_list_regex); } if (cfg_get_integer(&ot->max_messages, grp, octstr_imm("max-messages")) == -1) ot->max_messages = 1; cfg_get_bool(&ot->concatenation, grp, octstr_imm("concatenation")); cfg_get_bool(&ot->omit_empty, grp, octstr_imm("omit-empty")); ot->header = cfg_get(grp, octstr_imm("header")); ot->footer = cfg_get(grp, octstr_imm("footer")); ot->faked_sender = cfg_get(grp, octstr_imm("faked-sender")); ot->split_chars = cfg_get(grp, octstr_imm("split-chars")); ot->split_suffix = cfg_get(grp, octstr_imm("split-suffix")); if ( (ot->prefix == NULL && ot->suffix != NULL) || (ot->prefix != NULL && ot->suffix == NULL) ) { warning(0, "Service : suffix and prefix are only used" " if both are set."); } if ((ot->prefix != NULL || ot->suffix != NULL) && ot->type != TRANSTYPE_GET_URL) { warning(0, "Service : suffix and prefix are only used" " if type is 'get-url'."); } return ot; error: error(0, "Couldn't create a URLTranslation."); destroy_onetrans(ot); return NULL; }
Msg *ota_tokenize_settings(CfgGroup *grp, Octstr *from, Octstr *receiver) { Octstr *url, *desc, *ipaddr, *phonenum, *username, *passwd; int speed, bearer, calltype, connection, security, authent; Msg *msg; Octstr *p; url = NULL; desc = NULL; ipaddr = NULL; phonenum = NULL; username = NULL; passwd = NULL; bearer = -1; calltype = WBXML_TOK_VALUE_CONN_ISDN; connection = WBXML_TOK_VALUE_PORT_9201; security = 0; authent = WBXML_TOK_VALUE_AUTH_PAP; url = cfg_get(grp, octstr_imm("location")); desc = cfg_get(grp, octstr_imm("service")); ipaddr = cfg_get(grp, octstr_imm("ipaddress")); phonenum = cfg_get(grp, octstr_imm("phonenumber")); p = cfg_get(grp, octstr_imm("bearer")); if (p != NULL) { if (strcasecmp(octstr_get_cstr(p), "data") == 0) bearer = WBXML_TOK_VALUE_GSM_CSD; else bearer = -1; octstr_destroy(p); } p = cfg_get(grp, octstr_imm("calltype")); if (p != NULL) { if (strcasecmp(octstr_get_cstr(p), "analog") == 0) calltype = WBXML_TOK_VALUE_CONN_ANALOGUE; else calltype = WBXML_TOK_VALUE_CONN_ISDN; octstr_destroy(p); } speed = WBXML_TOK_VALUE_SPEED_9600; p = cfg_get(grp, octstr_imm("speed")); if (p != NULL) { if (octstr_compare(p, octstr_imm("14400")) == 0) speed = WBXML_TOK_VALUE_SPEED_14400; octstr_destroy(p); } /* connection mode: UDP (port 9200) or TCP (port 9201)*/ p = cfg_get(grp, octstr_imm("connection")); if (p != NULL) { if (strcasecmp(octstr_get_cstr(p), "temp") == 0) connection = WBXML_TOK_VALUE_PORT_9200; else connection = WBXML_TOK_VALUE_PORT_9201; octstr_destroy(p); } /* dial in security: CHAP or PAP */ p = cfg_get(grp, octstr_imm("pppsecurity")); if (p != NULL) { if (strcasecmp(octstr_get_cstr(p), "on") == 0) authent = WBXML_TOK_VALUE_AUTH_CHAP; else authent = WBXML_TOK_VALUE_AUTH_PAP; octstr_destroy(p); } /* WTLS: for UDP (port 9202) or TCP (port 9203) */ p = cfg_get(grp, octstr_imm("authentication")); if (p != NULL) { if (strcasecmp(octstr_get_cstr(p), "secure") == 0) security = 1; else security = WBXML_TOK_VALUE_PORT_9201; octstr_destroy(p); } if (security == 1) connection = (connection == WBXML_TOK_VALUE_PORT_9201)? WBXML_TOK_VALUE_PORT_9203 : WBXML_TOK_VALUE_PORT_9202; username = cfg_get(grp, octstr_imm("login")); passwd = cfg_get(grp, octstr_imm("secret")); msg = msg_create(sms); /* * Append the User Data Header (UDH) including the length (UDHL) * WDP layer (start WDP headers) */ msg->sms.sms_type = mt_push; msg->sms.udhdata = octstr_create(""); /* * Within OTA spec this is "0B0504C34FC0020003040201", but it works * with the following too?! */ octstr_append_from_hex(msg->sms.udhdata, "060504C34FC002"); /* WDP layer (end WDP headers) */ /* * WSP layer (start WSP headers) */ msg->sms.msgdata = octstr_create(""); /* PUSH ID, PDU type, header length, value length */ octstr_append_from_hex(msg->sms.msgdata, "01062C1F2A"); /* MIME-type: application/x-wap-prov.browser-settings */ octstr_format_append(msg->sms.msgdata, "%s", "application/x-wap-prov.browser-settings"); octstr_append_from_hex(msg->sms.msgdata, "00"); /* charset UTF-8 */ octstr_append_from_hex(msg->sms.msgdata, "81EA"); /* WSP layer (end WSP headers) */ /* * WSP layer (start WSP data field) */ /* WBXML version 1.1 */ octstr_append_from_hex(msg->sms.msgdata, "0101"); /* charset UTF-8 */ octstr_append_from_hex(msg->sms.msgdata, "6A00"); /* CHARACTERISTIC_LIST */ octstr_append_from_hex(msg->sms.msgdata, "45"); /* CHARACTERISTIC with content and attributes */ octstr_append_from_hex(msg->sms.msgdata, "C6"); /* TYPE=ADDRESS */ octstr_append_char(msg->sms.msgdata, WBXML_TOK_TYPE_ADDRESS); octstr_append_char(msg->sms.msgdata, WBXML_TOK_END); /* bearer type */ if (bearer != -1) { /* PARM with attributes */ octstr_append_from_hex(msg->sms.msgdata, "87"); /* NAME=BEARER, VALUE=GSM_CSD */ octstr_append_char(msg->sms.msgdata, WBXML_TOK_NAME_BEARER); octstr_append_char(msg->sms.msgdata, bearer); octstr_append_char(msg->sms.msgdata, WBXML_TOK_END); } /* IP address */ if (ipaddr != NULL) { /* PARM with attributes */ octstr_append_from_hex(msg->sms.msgdata, "87"); /* NAME=PROXY, VALUE, inline string */ octstr_append_char(msg->sms.msgdata, WBXML_TOK_NAME_PROXY); octstr_append_char(msg->sms.msgdata, WBXML_TOK_VALUE); octstr_append_char(msg->sms.msgdata, WBXML_TOK_STR_I); octstr_append(msg->sms.msgdata, octstr_duplicate(ipaddr)); octstr_append_char(msg->sms.msgdata, WBXML_TOK_END_STR_I); octstr_append_char(msg->sms.msgdata, WBXML_TOK_END); } /* connection type */ if (connection != -1) { /* PARM with attributes */ octstr_append_from_hex(msg->sms.msgdata, "87"); /* NAME=PORT, VALUE */ octstr_append_char(msg->sms.msgdata, WBXML_TOK_NAME_PORT); octstr_append_char(msg->sms.msgdata, connection); octstr_append_char(msg->sms.msgdata, WBXML_TOK_END); } /* phone number */ if (phonenum != NULL) { /* PARM with attributes */ octstr_append_from_hex(msg->sms.msgdata, "87"); /* NAME=CSD_DIALSTRING, VALUE, inline string */ octstr_append_char(msg->sms.msgdata, WBXML_TOK_NAME_CSD_DIALSTRING); octstr_append_char(msg->sms.msgdata, WBXML_TOK_VALUE); octstr_append_char(msg->sms.msgdata, WBXML_TOK_STR_I); octstr_append(msg->sms.msgdata, octstr_duplicate(phonenum)); octstr_append_char(msg->sms.msgdata, WBXML_TOK_END_STR_I); octstr_append_char(msg->sms.msgdata, WBXML_TOK_END); } /* authentication */ /* PARM with attributes */ octstr_append_from_hex(msg->sms.msgdata, "87"); /* NAME=PPP_AUTHTYPE, VALUE */ octstr_append_char(msg->sms.msgdata, WBXML_TOK_NAME_PPP_AUTHTYPE); octstr_append_char(msg->sms.msgdata, authent); octstr_append_char(msg->sms.msgdata, WBXML_TOK_END); /* user name */ if (username != NULL) { /* PARM with attributes */ octstr_append_from_hex(msg->sms.msgdata, "87"); /* NAME=PPP_AUTHNAME, VALUE, inline string */ octstr_append_char(msg->sms.msgdata, WBXML_TOK_NAME_PPP_AUTHNAME); octstr_append_char(msg->sms.msgdata, WBXML_TOK_VALUE); octstr_append_char(msg->sms.msgdata, WBXML_TOK_STR_I); octstr_append(msg->sms.msgdata, octstr_duplicate(username)); octstr_append_char(msg->sms.msgdata, WBXML_TOK_END_STR_I); octstr_append_char(msg->sms.msgdata, WBXML_TOK_END); } /* password */ if (passwd != NULL) { /* PARM with attributes */ octstr_append_from_hex(msg->sms.msgdata, "87"); /* NAME=PPP_AUTHSECRET, VALUE, inline string */ octstr_append_char(msg->sms.msgdata, WBXML_TOK_NAME_PPP_AUTHSECRET); octstr_append_char(msg->sms.msgdata, WBXML_TOK_VALUE); octstr_append_char(msg->sms.msgdata, WBXML_TOK_STR_I); octstr_append(msg->sms.msgdata, octstr_duplicate(passwd)); octstr_append_char(msg->sms.msgdata, WBXML_TOK_END_STR_I); octstr_append_char(msg->sms.msgdata, WBXML_TOK_END); } /* data call type */ if (calltype != -1) { /* PARM with attributes */ octstr_append_from_hex(msg->sms.msgdata, "87"); /* NAME=CSD_CALLTYPE, VALUE */ octstr_append_char(msg->sms.msgdata, WBXML_TOK_NAME_CSD_CALLTYPE); octstr_append_char(msg->sms.msgdata, calltype); octstr_append_char(msg->sms.msgdata, WBXML_TOK_END); } /* speed */ /* PARM with attributes */ octstr_append_from_hex(msg->sms.msgdata, "87"); /* NAME=CSD_CALLSPEED, VALUE */ octstr_append_char(msg->sms.msgdata, WBXML_TOK_NAME_CSD_CALLSPEED); octstr_append_char(msg->sms.msgdata, speed); octstr_append_char(msg->sms.msgdata, WBXML_TOK_END); /* end CHARACTERISTIC TYPE=ADDRESS */ octstr_append_char(msg->sms.msgdata, WBXML_TOK_END); /* homepage */ if (url != NULL) { /* CHARACTERISTIC with attributes */ octstr_append_from_hex(msg->sms.msgdata, "86"); /* TYPE=URL */ octstr_append_char(msg->sms.msgdata, WBXML_TOK_TYPE_URL); octstr_append_char(msg->sms.msgdata, WBXML_TOK_VALUE); octstr_append_char(msg->sms.msgdata, WBXML_TOK_STR_I); octstr_append(msg->sms.msgdata, url); octstr_append_char(msg->sms.msgdata, WBXML_TOK_END_STR_I); octstr_append_char(msg->sms.msgdata, WBXML_TOK_END); } /* CHARACTERISTIC with content and attributes */ octstr_append_from_hex(msg->sms.msgdata, "C6"); /* TYPE=NAME */ octstr_append_char(msg->sms.msgdata, WBXML_TOK_TYPE_NAME); octstr_append_char(msg->sms.msgdata, WBXML_TOK_END); /* service description */ if (desc != NULL) { /* PARAM with attributes */ octstr_append_from_hex(msg->sms.msgdata, "87"); /* NAME=NAME, VALUE, inline */ octstr_append_char(msg->sms.msgdata, WBXML_TOK_NAME_NAME); octstr_append_char(msg->sms.msgdata, WBXML_TOK_VALUE); octstr_append_char(msg->sms.msgdata, WBXML_TOK_STR_I); octstr_append(msg->sms.msgdata, desc); octstr_append_char(msg->sms.msgdata, WBXML_TOK_END_STR_I); octstr_append_char(msg->sms.msgdata, WBXML_TOK_END); } /* end of CHARACTERISTIC */ octstr_append_char(msg->sms.msgdata, WBXML_TOK_END); /* end of CHARACTERISTIC-LIST */ octstr_append_char(msg->sms.msgdata, WBXML_TOK_END); /* WSP layer (end WSP data field) */ msg->sms.sender = from; msg->sms.receiver = octstr_duplicate(receiver); msg->sms.coding = DC_8BIT; msg->sms.time = time(NULL); octstr_destroy(url); octstr_destroy(desc); octstr_destroy(ipaddr); octstr_destroy(phonenum); octstr_destroy(username); octstr_destroy(passwd); return msg; }
static Octstr *store_file_status(int status_type) { char *frmt; Octstr *ret, *key; unsigned long l; struct tm tm; Msg *msg; List *keys; char id[UUID_STR_LEN + 1]; ret = octstr_create(""); /* set the type based header */ if (status_type == BBSTATUS_HTML) { octstr_append_cstr(ret, "<table border=1>\n" "<tr><td>SMS ID</td><td>Type</td><td>Time</td><td>Sender</td><td>Receiver</td>" "<td>SMSC ID</td><td>BOX ID</td><td>UDH</td><td>Message</td>" "</tr>\n"); } else if (status_type == BBSTATUS_TEXT) { octstr_append_cstr(ret, "[SMS ID] [Type] [Time] [Sender] [Receiver] [SMSC ID] [BOX ID] [UDH] [Message]\n"); } /* if there is no store-file, then don't loop in sms_store */ if (filename == NULL) goto finish; keys = dict_keys(sms_dict); for (l = 0; l < gwlist_len(keys); l++) { key = gwlist_get(keys, l); msg = dict_get(sms_dict, key); if (msg == NULL) continue; if (msg_type(msg) == sms) { if (status_type == BBSTATUS_HTML) { frmt = "<tr><td>%s</td><td>%s</td>" "<td>%04d-%02d-%02d %02d:%02d:%02d</td>" "<td>%s</td><td>%s</td><td>%s</td>" "<td>%s</td><td>%s</td><td>%s</td></tr>\n"; } else if (status_type == BBSTATUS_XML) { frmt = "<message>\n\t<id>%s</id>\n\t<type>%s</type>\n\t" "<time>%04d-%02d-%02d %02d:%02d:%02d</time>\n\t" "<sender>%s</sender>\n\t" "<receiver>%s</receiver>\n\t<smsc-id>%s</smsc-id>\n\t" "<box-id>%s</box-id>\n\t" "<udh-data>%s</udh-data>\n\t<msg-data>%s</msg-data>\n\t" "</message>\n"; } else { frmt = "[%s] [%s] [%04d-%02d-%02d %02d:%02d:%02d] [%s] [%s] [%s] [%s] [%s] [%s]\n"; } /* transform the time value */ #if LOG_TIMESTAMP_LOCALTIME tm = gw_localtime(msg->sms.time); #else tm = gw_gmtime(msg->sms.time); #endif if (msg->sms.udhdata) octstr_binary_to_hex(msg->sms.udhdata, 1); if (msg->sms.msgdata && (msg->sms.coding == DC_8BIT || msg->sms.coding == DC_UCS2 || (msg->sms.coding == DC_UNDEF && msg->sms.udhdata))) octstr_binary_to_hex(msg->sms.msgdata, 1); uuid_unparse(msg->sms.id, id); octstr_format_append(ret, frmt, id, (msg->sms.sms_type == mo ? "MO" : msg->sms.sms_type == mt_push ? "MT-PUSH" : msg->sms.sms_type == mt_reply ? "MT-REPLY" : msg->sms.sms_type == report_mo ? "DLR-MO" : msg->sms.sms_type == report_mt ? "DLR-MT" : ""), tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec, (msg->sms.sender ? octstr_get_cstr(msg->sms.sender) : ""), (msg->sms.receiver ? octstr_get_cstr(msg->sms.receiver) : ""), (msg->sms.smsc_id ? octstr_get_cstr(msg->sms.smsc_id) : ""), (msg->sms.boxc_id ? octstr_get_cstr(msg->sms.boxc_id) : ""), (msg->sms.udhdata ? octstr_get_cstr(msg->sms.udhdata) : ""), (msg->sms.msgdata ? octstr_get_cstr(msg->sms.msgdata) : "")); if (msg->sms.udhdata) octstr_hex_to_binary(msg->sms.udhdata); if (msg->sms.msgdata && (msg->sms.coding == DC_8BIT || msg->sms.coding == DC_UCS2 || (msg->sms.coding == DC_UNDEF && msg->sms.udhdata))) octstr_hex_to_binary(msg->sms.msgdata); } } gwlist_destroy(keys, octstr_destroy_item); finish: /* set the type based footer */ if (status_type == BBSTATUS_HTML) { octstr_append_cstr(ret,"</table>"); } return ret; }
static void httpd_serve(HTTPClient *client, Octstr *ourl, List *headers, Octstr *body, List *cgivars) { Octstr *reply, *final_reply, *url; char *content_type; char *header, *footer; int status_type; int i; long pos; reply = final_reply = NULL; /* for compiler please */ url = octstr_duplicate(ourl); /* Set default reply format according to client * Accept: header */ if (http_type_accepted(headers, "text/vnd.wap.wml")) { status_type = BBSTATUS_WML; content_type = "text/vnd.wap.wml"; } else if (http_type_accepted(headers, "text/html")) { status_type = BBSTATUS_HTML; content_type = "text/html"; } else if (http_type_accepted(headers, "text/xml")) { status_type = BBSTATUS_XML; content_type = "text/xml"; } else { status_type = BBSTATUS_TEXT; content_type = "text/plain"; } /* kill '/cgi-bin' prefix */ pos = octstr_search(url, octstr_imm("/cgi-bin/"), 0); if (pos != -1) octstr_delete(url, pos, 9); else if (octstr_get_char(url, 0) == '/') octstr_delete(url, 0, 1); /* look for type and kill it */ pos = octstr_search_char(url, '.', 0); if (pos != -1) { Octstr *tmp = octstr_copy(url, pos+1, octstr_len(url) - pos - 1); octstr_delete(url, pos, octstr_len(url) - pos); if (octstr_str_compare(tmp, "txt") == 0) status_type = BBSTATUS_TEXT; else if (octstr_str_compare(tmp, "html") == 0) status_type = BBSTATUS_HTML; else if (octstr_str_compare(tmp, "xml") == 0) status_type = BBSTATUS_XML; else if (octstr_str_compare(tmp, "wml") == 0) status_type = BBSTATUS_WML; octstr_destroy(tmp); } for (i=0; httpd_commands[i].command != NULL; i++) { if (octstr_str_compare(url, httpd_commands[i].command) == 0) { reply = httpd_commands[i].function(cgivars, status_type); break; } } /* check if command found */ if (httpd_commands[i].command == NULL) { char *lb = bb_status_linebreak(status_type); reply = octstr_format("Unknown command `%S'.%sPossible commands are:%s", ourl, lb, lb); for (i=0; httpd_commands[i].command != NULL; i++) octstr_format_append(reply, "%s%s", httpd_commands[i].command, lb); } gw_assert(reply != NULL); if (status_type == BBSTATUS_HTML) { header = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2//EN\">\n" "<html>\n<title>" GW_NAME "</title>\n<body>\n<p>"; footer = "</p>\n</body></html>\n"; content_type = "text/html"; } else if (status_type == BBSTATUS_WML) { header = "<?xml version=\"1.0\"?>\n" "<!DOCTYPE wml PUBLIC \"-//WAPFORUM//DTD WML 1.1//EN\" " "\"http://www.wapforum.org/DTD/wml_1.1.xml\">\n" "\n<wml>\n <card>\n <p>"; footer = " </p>\n </card>\n</wml>\n"; content_type = "text/vnd.wap.wml"; } else if (status_type == BBSTATUS_XML) { header = "<?xml version=\"1.0\"?>\n" "<gateway>\n"; footer = "</gateway>\n"; } else { header = ""; footer = ""; content_type = "text/plain"; } final_reply = octstr_create(header); octstr_append(final_reply, reply); octstr_append_cstr(final_reply, footer); /* debug("bb.http", 0, "Result: '%s'", octstr_get_cstr(final_reply)); */ http_destroy_headers(headers); headers = list_create(); http_header_add(headers, "Content-Type", content_type); http_send_reply(client, HTTP_OK, headers, final_reply); octstr_destroy(url); octstr_destroy(ourl); octstr_destroy(body); octstr_destroy(reply); octstr_destroy(final_reply); http_destroy_headers(headers); http_destroy_cgiargs(cgivars); }
/* 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 Octstr *get_pattern(SMSCConn *conn, Msg *msg, const char *message) { int nextarg, j; struct tm tm; int num_words; List *word_list; Octstr *result; const char *pattern; Octstr *temp, *text, *udh; size_t n; long i; text = msg->sms.msgdata ? octstr_duplicate(msg->sms.msgdata) : octstr_create(""); udh = msg->sms.udhdata ? octstr_duplicate(msg->sms.udhdata) : octstr_create(""); if ((msg->sms.coding == DC_8BIT || msg->sms.coding == DC_UCS2)) octstr_binary_to_hex(text, 1); else octstr_convert_printable(text); octstr_binary_to_hex(udh, 1); if (octstr_len(text)) { word_list = octstr_split_words(text); num_words = gwlist_len(word_list); } else { word_list = gwlist_create(); num_words = 0; } result = octstr_create(""); pattern = octstr_get_cstr(custom_log_format); nextarg = 1; while(*pattern != '\0') { n = strcspn(pattern, "%"); octstr_append_data(result, pattern, n); pattern += n; gw_assert(*pattern == '%' || *pattern == '\0'); if (*pattern == '\0') break; pattern++; switch (*pattern) { case 'k': if (num_words <= 0) break; octstr_append(result, gwlist_get(word_list, 0)); break; case 's': if (nextarg >= num_words) break; octstr_append(result, gwlist_get(word_list, nextarg)); ++nextarg; break; case 'S': if (nextarg >= num_words) break; temp = gwlist_get(word_list, nextarg); for (i = 0; i < octstr_len(temp); ++i) { if (octstr_get_char(temp, i) == '*') octstr_append_char(result, '~'); else octstr_append_char(result, octstr_get_char(temp, i)); } ++nextarg; break; case 'r': for (j = nextarg; j < num_words; ++j) { if (j != nextarg) octstr_append_char(result, '+'); octstr_append(result, gwlist_get(word_list, j)); } break; case 'l': if (message) octstr_append_cstr(result, message); break; case 'P': if (msg->sms.receiver) octstr_append(result, msg->sms.receiver); break; case 'p': if (msg->sms.sender) octstr_append(result, msg->sms.sender); break; case 'a': for (j = 0; j < num_words; ++j) { if (j > 0) octstr_append_char(result, ' '); octstr_append(result, gwlist_get(word_list, j)); } break; case 'b': if (text) octstr_append(result, text); break; case 'L': octstr_append_decimal(result, octstr_len(msg->sms.msgdata)); break; case 't': tm = gw_gmtime(msg->sms.time); octstr_format_append(result, "%04d-%02d-%02d %02d:%02d:%02d", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec); break; case 'T': if (msg->sms.time != MSG_PARAM_UNDEFINED) octstr_format_append(result, "%ld", msg->sms.time); break; case 'i': if (conn && smscconn_id(conn)) octstr_append(result, smscconn_id(conn)); else if (conn && smscconn_name(conn)) octstr_append(result, smscconn_name(conn)); else if (msg->sms.smsc_id) octstr_append(result, msg->sms.smsc_id); break; case 'I': if (!uuid_is_null(msg->sms.id)) { char id[UUID_STR_LEN + 1]; uuid_unparse(msg->sms.id, id); octstr_append_cstr(result, id); } break; case 'n': if (msg->sms.service != NULL) octstr_append(result, msg->sms.service); break; case 'd': octstr_append_decimal(result, msg->sms.dlr_mask); break; case 'c': octstr_append_decimal(result, msg->sms.coding); break; case 'm': octstr_append_decimal(result, msg->sms.mclass); break; case 'C': octstr_append_decimal(result, msg->sms.compress); break; case 'M': octstr_append_decimal(result, msg->sms.mwi); break; case 'u': if (octstr_len(udh)) { octstr_append(result, udh); } break; case 'U': octstr_append_decimal(result, octstr_len(msg->sms.udhdata)); break; case 'B': /* billing identifier/information */ if (octstr_len(msg->sms.binfo)) { octstr_append(result, msg->sms.binfo); } break; case 'A': /* account */ if (octstr_len(msg->sms.account)) { octstr_append(result, msg->sms.account); } break; /* XXX add more here if needed */ case '%': octstr_format_append(result, "%%"); break; default: warning(0, "Unknown escape code (%%%c) within custom-log-format, skipping!", *pattern); octstr_format_append(result, "%%%c", *pattern); break; } /* switch(...) */ pattern++; } /* for ... */ gwlist_destroy(word_list, octstr_destroy_item); return result; }
int create_web_data(char *p_pszFileName, char *p_pszMMSDir, const char *p_pszWebDir) { int iRetVal = 0; MmsEnvelope *psoEnv; MmsMsg *psoMsg = NULL; List *psoHdrList = NULL; Octstr *psoHdrs = NULL, *psoHdrName = NULL, *psoHdrValue = NULL, *psoWebDir = NULL; MIMEEntity *psoMIME, *psoMIMETmp; int iMIMENum, iMIMEInd; int iFile = -1; gwlib_init(); mms_strings_init(); /* формируем имя директрии для вывода результатов */ psoWebDir = octstr_create(p_pszWebDir); if('/' != octstr_get_char(psoWebDir, octstr_len(psoWebDir) - 1)) { octstr_append_char(psoWebDir, '/'); } octstr_append_cstr(psoWebDir, p_pszFileName); /* создаем директорию */ if(mkdir(octstr_get_cstr(psoWebDir), 0777)) { if(errno != EEXIST) { iRetVal = 2; } goto done; } psoEnv = default_qfuncs.mms_queue_readenvelope(p_pszFileName, p_pszMMSDir, 0); if(psoEnv) { psoMsg = default_qfuncs.mms_queue_getdata(psoEnv); default_qfuncs.mms_queue_free_env(psoEnv); } else { iRetVal = 3; goto done; } if(!psoMsg) { iRetVal = 4; goto done; } psoHdrs = octstr_create(""); /* выбираем необходимые заголовки */ psoHdrList = mms_message_headers(psoMsg); /* From */ psoHdrName = octstr_create("From"); psoHdrValue = http_header_value(psoHdrList, psoHdrName); octstr_format_append(psoHdrs, "%S/%S\r\n", psoHdrName, psoHdrValue); octstr_truncate(psoHdrName, 0); /* To */ octstr_append_cstr(psoHdrName, "To"); psoHdrValue = http_header_value(psoHdrList, psoHdrName); octstr_format_append(psoHdrs, "%S/%S\r\n", psoHdrName, psoHdrValue); octstr_truncate(psoHdrName, 0); /* Date */ octstr_append_cstr(psoHdrName, "Date"); psoHdrValue = http_header_value(psoHdrList, psoHdrName); octstr_format_append(psoHdrs, "%S/%S", psoHdrName, psoHdrValue); octstr_truncate(psoHdrName, 0); /**/ psoMIME = mms_tomime(psoMsg, 1); iMIMENum = mime_entity_num_parts(psoMIME); if(psoMIME) { for(iMIMEInd = 0; iMIMEInd < iMIMENum; ++iMIMEInd) { psoMIMETmp = mime_entity_get_part(psoMIME, iMIMEInd); operate_single_mime(psoHdrs, psoMIMETmp, octstr_get_cstr(psoWebDir)); } } /* формируем имя файла для вывода результатов, используем ту же переменную, что и для директории */ if('/' != octstr_get_char(psoWebDir, octstr_len(psoWebDir) - 1)) { octstr_append_char(psoWebDir, '/'); } octstr_append_cstr(psoWebDir, "common"); /* создаем файл */ iFile = open(octstr_get_cstr(psoWebDir), O_CREAT | O_EXCL | O_WRONLY, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); if(0 < iFile) { if(octstr_len(psoHdrs) != write(iFile, octstr_get_cstr(psoHdrs), octstr_len(psoHdrs))) { iRetVal = 5; } close(iFile); } else { if(errno != EEXIST) { iRetVal = 6; } } done: if(psoHdrs) { octstr_destroy(psoHdrs); } if(psoHdrName) { octstr_destroy(psoHdrName); } if(psoWebDir) { octstr_destroy(psoWebDir); } mms_strings_shutdown(); gwlib_shutdown(); return iRetVal; }