/* * 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"); }
int main(int argc, char **argv) { Octstr *os1, *os2; gwlib_init(); os1 = octstr_create(""); octstr_append_from_hex(os1, "411810124550421715161a"); os2 = octstr_duplicate(os1); debug("", 0, "Orginal GSM charset data:"); octstr_dump(os1, 0); charset_gsm_to_utf8(os1); debug("", 0, "Same data mapped to URT-8 charset:"); octstr_dump(os1, 0); charset_utf8_to_gsm(os1); debug("", 0, "Same data mapped back again to GSM charset:"); octstr_dump(os1, 0); if (octstr_compare(os1, os2) != 0) panic(0, "Data is not the same after re-mapping!"); else debug("",0,"Data is same, ok."); octstr_destroy(os1); octstr_destroy(os2); gwlib_shutdown(); return 0; }
static void client_thread(void *arg) { HTTPClient *client; Octstr *body, *url, *ip; List *headers, *resph, *cgivars; HTTPCGIVar *v; Octstr *reply_body, *reply_type; unsigned long n = 0; int status, i; while (run) { client = http_accept_request(port, &ip, &url, &headers, &body, &cgivars); n++; if (client == NULL) break; info(0, "Request for <%s> from <%s>", octstr_get_cstr(url), octstr_get_cstr(ip)); if (verbose) debug("test.http", 0, "CGI vars were"); /* * Don't use gwlist_extract() here, otherwise we don't have a chance * to re-use the cgivars later on. */ for (i = 0; i < gwlist_len(cgivars); i++) { if ((v = gwlist_get(cgivars, i)) != NULL && verbose) { octstr_dump(v->name, 0); octstr_dump(v->value, 0); } } if (arg == NULL) { reply_body = octstr_duplicate(reply_text); reply_type = octstr_create("Content-Type: text/plain; " "charset=\"UTF-8\""); } else { reply_body = octstr_duplicate(arg); reply_type = octstr_create("Content-Type: text/vnd.wap.wml"); } resph = gwlist_create(); gwlist_append(resph, reply_type); status = HTTP_OK; /* check for special URIs and handle those */ if (octstr_compare(url, octstr_imm("/quit")) == 0) { run = 0; } else if (octstr_compare(url, octstr_imm("/whitelist")) == 0) { octstr_destroy(reply_body); if (whitelist != NULL) { if (verbose) { debug("test.http.server", 0, "we send a white list"); octstr_dump(whitelist, 0); } reply_body = octstr_duplicate(whitelist); } else { reply_body = octstr_imm(""); } } else if (octstr_compare(url, octstr_imm("/blacklist")) == 0) { octstr_destroy(reply_body); if (blacklist != NULL) { if (verbose) { debug("test.http.server", 0, "we send a blacklist"); octstr_dump(blacklist, 0); } reply_body = octstr_duplicate(blacklist); } else { reply_body = octstr_imm(""); } } else if (octstr_compare(url, octstr_imm("/save")) == 0) { /* safe the body into a temporary file */ pid_t pid = getpid(); FILE *f = fopen(octstr_get_cstr(octstr_format("/tmp/body.%ld.%ld", pid, n)), "w"); octstr_print(f, body); fclose(f); } else if (octstr_compare(url, octstr_imm("/redirect/")) == 0) { /* provide us with a HTTP 302 redirection response * will return /redirect/<pid> for the location header * and will return /redirect/ if cgivar loop is set to allow looping */ Octstr *redirect_header, *scheme, *uri, *l; pid_t pid = getpid(); uri = ((l = http_cgi_variable(cgivars, "loop")) != NULL) ? octstr_format("%s?loop=%s", octstr_get_cstr(url), octstr_get_cstr(l)) : octstr_format("%s%ld", octstr_get_cstr(url), pid); octstr_destroy(reply_body); reply_body = octstr_imm("Here you got a redirection URL that you should follow."); scheme = ssl ? octstr_imm("https://") : octstr_imm("http://"); redirect_header = octstr_format("Location: %s%s%s", octstr_get_cstr(scheme), octstr_get_cstr(http_header_value(headers, octstr_imm("Host"))), octstr_get_cstr(uri)); gwlist_append(resph, redirect_header); status = HTTP_FOUND; /* will provide 302 */ octstr_destroy(uri); } else if (octstr_compare(url, octstr_imm("/mmsc")) == 0) { /* fake a M-Send.conf PDU which is using MMSEncapsulation as body */ pid_t pid = getpid(); FILE *f; gwlist_destroy(resph, octstr_destroy_item); octstr_destroy(reply_body); reply_type = octstr_create("Content-Type: application/vnd.wap.mms-message"); reply_body = octstr_create(""); octstr_append_from_hex(reply_body, "8c81" /* X-Mms-Message-Type: m-send-conf */ "98632d3862343300" /* X-Mms-Transaction-ID: c-8b43 */ "8d90" /* X-Mms-MMS-Version: 1.0 */ "9280" /* Response-status: Ok */ "8b313331373939353434393639383434313731323400" ); /* Message-Id: 13179954496984417124 */ resph = gwlist_create(); gwlist_append(resph, reply_type); /* safe the M-Send.req body into a temporary file */ f = fopen(octstr_get_cstr(octstr_format("/tmp/mms-body.%ld.%ld", pid, n)), "w"); octstr_print(f, body); fclose(f); } if (verbose) { debug("test.http", 0, "request headers were"); http_header_dump(headers); if (body != NULL) { debug("test.http", 0, "request body was"); octstr_dump(body, 0); } } if (extra_headers != NULL) http_header_combine(resph, extra_headers); /* return response to client */ http_send_reply(client, status, resph, reply_body); octstr_destroy(ip); octstr_destroy(url); octstr_destroy(body); octstr_destroy(reply_body); http_destroy_cgiargs(cgivars); gwlist_destroy(headers, octstr_destroy_item); gwlist_destroy(resph, octstr_destroy_item); } octstr_destroy(whitelist); octstr_destroy(blacklist); debug("test.http", 0, "Working thread 'client_thread' terminates"); http_close_all_ports(); }
/****************************************************************************** * Send a MT message, returns as in smsc_submit_smsmessage in smsc.h */ int cimd_submit_msg(SMSCenter *smsc, Msg *msg) { char *tmpbuff = NULL, *tmptext = NULL; char msgtext[1024]; int ret; int cmd = 0, err = 0; /* Fix these by implementing a could-not-send-because- protocol-does-not-allow in smsc.c or smsgateway.c */ if (octstr_len(msg->sms.msgdata) + octstr_len(msg->sms.udhdata) < 1) { if (msg->sms.msgdata == NULL) msg->sms.msgdata = octstr_create(""); octstr_append_from_hex(msg->sms.msgdata, "20"); } if (octstr_len(msg->sms.sender) < 1) { warning(0, "cimd_submit_smsmessage: ignoring message with 0-length field"); goto okay; /* THIS IS NOT OKAY!!!! XXX */ } if (octstr_len(msg->sms.receiver) < 1) { warning(0, "cimd_submit_smsmessage: ignoring message with 0-length field"); goto okay; /* THIS IS NOT OKAY!!!! XXX */ } tmpbuff = gw_malloc(10 * 1024); tmptext = gw_malloc(10 * 1024); memset(tmpbuff, 0, 10*1024); memset(tmptext, 0, 10*1024); memset(msgtext, 0, sizeof(msgtext)); if (octstr_len(msg->sms.udhdata)) { octstr_get_many_chars(msgtext, msg->sms.udhdata, 0, octstr_len(msg->sms.udhdata)); octstr_get_many_chars(msgtext + octstr_len(msg->sms.udhdata), msg->sms.msgdata, 0, 140 - octstr_len(msg->sms.udhdata)); } else { octstr_get_many_chars(msgtext, msg->sms.msgdata, 0, octstr_len(msg->sms.msgdata)); } /* XXX parse_iso88591_to_cimd should use Octstr * directly, or get a char* and a length, instead of using NUL * terminated strings. */ parse_iso88591_to_cimd(msgtext, tmptext, 10*1024, smsc->alt_charset); /* If messages has UDHs, add the magic number 31 to the right spot */ sprintf(tmpbuff, "%c%s%c%s%c%s%c%s%c%s%c%s%c%s%c%c", 0x02, "03", 0x09, octstr_get_cstr(msg->sms.receiver), 0x09, tmptext, 0x09, "", 0x09, "", 0x09, (octstr_len(msg->sms.udhdata)) ? "31" : "", 0x09, "11", 0x03, 0x0A); ret = write_to_socket(smsc->socket, tmpbuff); if (ret < 0) { debug("bb.sms.cimd", 0, "cimd_submit_smsmessage: socket write error"); goto error; } /* The Nokia SMSC MAY be configured to send delivery information, which we then will HAVE to acknowledge. Naturally the CIMD 1.3 protocol does not include any kind of negotiation mechanism. */ ret = expect_acknowledge(smsc, &cmd, &err); if (ret >= 1) { if (cmd == 4) { send_acknowledge(smsc); goto okay; } else if (cmd == 3) { goto okay; } } else if (ret == 0) { if (cmd == 4) { send_acknowledge(smsc); goto okay; /* FIXME XXX THIS IS BOGUS, FIX SMSGATEWAY.C */ goto error; } else if (cmd == 3) { goto okay; /* FIXME XXX THIS IS BOGUS, FIX SMSGATEWAY.C */ goto error; } else { error(0, "Unexpected behaviour from the CIMD server"); debug("bb.sms.cimd", 0, "cimd_submit_smsmessage: acknowledge was <%i>", ret); debug("bb.sms.cimd", 0, "cimd_submit_smsmessage: buffer==<%s>", smsc->buffer); goto error; } } okay: gw_free(tmpbuff); gw_free(tmptext); return 0; error: debug("bb.sms.cimd", 0, "cimd_submit_smsmessage: returning error"); gw_free(tmpbuff); gw_free(tmptext); return -1; }
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; }
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; }
/* * Our WSP headers: Push Id, PDU type, headers, charset. */ static int ota_pack_push_headers(Msg **msg, Octstr *mime_type, Octstr *sec, Octstr *pin, Octstr *ota_binary) { (*msg)->sms.msgdata = octstr_create(""); if (octstr_case_compare(mime_type, octstr_imm("settings")) == 0) { /* PUSH ID, PDU type, header length, value length */ octstr_append_from_hex((*msg)->sms.msgdata, "01062C1F2A"); /* MIME type for 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"); } else if (octstr_case_compare(mime_type, octstr_imm("bookmarks")) == 0) { /* PUSH ID, PDU type, header length, value length */ octstr_append_from_hex((*msg)->sms.msgdata, "01062D1F2B"); /* MIME type for 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"); } else if (octstr_case_compare(mime_type, octstr_imm("syncsettings")) == 0) { octstr_append_from_hex((*msg)->sms.msgdata, "3406060502020b81EA"); } else if (octstr_case_compare(mime_type, octstr_imm("oma-settings")) == 0) { Octstr *hdr = octstr_create(""), *mac; unsigned char *p; unsigned int mac_len; #ifdef HAVE_LIBSSL unsigned char macbuf[EVP_MAX_MD_SIZE]; #endif /* PUSH ID, PDU type, header length, value length */ octstr_append_from_hex((*msg)->sms.msgdata, "0106"); octstr_append_from_hex(hdr, "1f2db6"); /* Content type + other type + sec param */ wsp_pack_short_integer(hdr, 0x11); if (octstr_case_compare(sec, octstr_imm("netwpin")) == 0) wsp_pack_short_integer(hdr, 0x0); else if (octstr_case_compare(sec, octstr_imm("userpin")) == 0) wsp_pack_short_integer(hdr, 0x01); else if (octstr_case_compare(sec, octstr_imm("usernetwpin")) == 0) wsp_pack_short_integer(hdr, 0x02); else if (octstr_case_compare(sec, octstr_imm("userpinmac")) == 0) wsp_pack_short_integer(hdr, 0x03); /* XXXX Although not quite supported now.*/ else { warning(0, "OMA ProvCont: Unknown SEC pin type '%s'.", octstr_get_cstr(sec)); wsp_pack_short_integer(hdr, 0x01); } wsp_pack_short_integer(hdr, 0x12); /* MAC */ #ifdef HAVE_LIBSSL p = HMAC(EVP_sha1(), octstr_get_cstr(pin), octstr_len(pin), (unsigned char *)octstr_get_cstr(ota_binary), octstr_len(ota_binary), macbuf, &mac_len); #else mac_len = 0; p = ""; warning(0, "OMA ProvCont: No SSL Support, '%s' not supported!", octstr_get_cstr(mime_type)); #endif mac = octstr_create_from_data((char *)p, mac_len); octstr_binary_to_hex(mac, 1); octstr_append(hdr, mac); octstr_append_from_hex(hdr, "00"); octstr_append_uintvar((*msg)->sms.msgdata, octstr_len(hdr)); octstr_append((*msg)->sms.msgdata, hdr); octstr_destroy(hdr); octstr_destroy(mac); } else { warning(0, "Unknown MIME type in OTA request, type '%s' is unsupported.", octstr_get_cstr(mime_type)); return 0; } return 1; }