📄 ota_prov.c
字号:
/* ==================================================================== * The Kannel Software License, Version 1.0 * * Copyright (c) 2001-2004 Kannel Group * Copyright (c) 1998-2001 WapIT Ltd. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by the * Kannel Group (http://www.kannel.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The names "Kannel" and "Kannel Group" must not be used to * endorse or promote products derived from this software without * prior written permission. For written permission, please * contact org@kannel.org. * * 5. Products derived from this software may not be called "Kannel", * nor may "Kannel" appear in their name, without prior written * permission of the Kannel Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE KANNEL GROUP OR ITS CONTRIBUTORS * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Kannel Group. For more information on * the Kannel Group, please see <http://www.kannel.org/>. * * Portions of this software are based upon software originally written at * WapIT Ltd., Helsinki, Finland for the Kannel project. */ /* * ota_prov.c: OTA settings and bookmarks provisioning routines * * This module contains routines for the SMS OTA (auto configuration) message * creation and manipulation for the sendota HTTP interface. * * Official Nokia and Ericsson WAP OTA configuration settings coded * by Stipe Tolj <tolj@wapme-systems.de>, Wapme Systems AG. * * XML compiler by Aarno Syv鋘en <aarno@wiral.com>, Wiral Ltd. */#include <string.h>#include "gwlib/gwlib.h"#include "msg.h"#include "sms.h"#include "ota_prov.h"#include "ota_prov_attr.h"#include "ota_compiler.h"/*************************************************************************** * * Implementation of the internal function *//* * Append the User Data Header (UDH) including the lenght (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){ (*msg)->sms.udhdata = octstr_create(""); octstr_append_from_hex((*msg)->sms.udhdata, "060504C34FC002");}/* * Our WSP headers: Push Id, PDU type, headers, charset. */static int ota_pack_push_headers(Msg **msg, Octstr *mime_type){ (*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"); } 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"); } else { warning(0, "Unknown MIME type in OTA request, type '%s' is unsupported.", octstr_get_cstr(mime_type)); return 0; } /* charset UTF-8 */ octstr_append_from_hex((*msg)->sms.msgdata, "81EA"); return 1;}/*************************************************************************** * * Implementation of the external function */int ota_pack_message(Msg **msg, Octstr *ota_doc, Octstr *doc_type, Octstr *from, Octstr *phone_number){ Octstr *ota_binary; *msg = msg_create(sms); (*msg)->sms.sms_type = mt_push; ota_pack_udh(msg); if (!ota_pack_push_headers(msg, doc_type)) goto herror; if (ota_compile(ota_doc, octstr_imm("UTF-8"), &ota_binary) == -1) goto cerror; 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); return 0;herror: octstr_destroy(ota_doc); octstr_destroy(doc_type); octstr_destroy(from); return -2;cerror: octstr_destroy(ota_doc); octstr_destroy(doc_type); octstr_destroy(from); return -1;}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 = -1; 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), "calltype") == 0) calltype = WBXML_TOK_VALUE_CONN_ISDN; else calltype = -1; 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 lenght (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) */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -