00001 /* ==================================================================== 00002 * The Kannel Software License, Version 1.0 00003 * 00004 * Copyright (c) 2001-2008 Kannel Group 00005 * Copyright (c) 1998-2001 WapIT Ltd. 00006 * All rights reserved. 00007 * 00008 * Redistribution and use in source and binary forms, with or without 00009 * modification, are permitted provided that the following conditions 00010 * are met: 00011 * 00012 * 1. Redistributions of source code must retain the above copyright 00013 * notice, this list of conditions and the following disclaimer. 00014 * 00015 * 2. Redistributions in binary form must reproduce the above copyright 00016 * notice, this list of conditions and the following disclaimer in 00017 * the documentation and/or other materials provided with the 00018 * distribution. 00019 * 00020 * 3. The end-user documentation included with the redistribution, 00021 * if any, must include the following acknowledgment: 00022 * "This product includes software developed by the 00023 * Kannel Group (http://www.kannel.org/)." 00024 * Alternately, this acknowledgment may appear in the software itself, 00025 * if and wherever such third-party acknowledgments normally appear. 00026 * 00027 * 4. The names "Kannel" and "Kannel Group" must not be used to 00028 * endorse or promote products derived from this software without 00029 * prior written permission. For written permission, please 00030 * contact org@kannel.org. 00031 * 00032 * 5. Products derived from this software may not be called "Kannel", 00033 * nor may "Kannel" appear in their name, without prior written 00034 * permission of the Kannel Group. 00035 * 00036 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED 00037 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00038 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00039 * DISCLAIMED. IN NO EVENT SHALL THE KANNEL GROUP OR ITS CONTRIBUTORS 00040 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 00041 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 00042 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 00043 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 00044 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 00045 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 00046 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00047 * ==================================================================== 00048 * 00049 * This software consists of voluntary contributions made by many 00050 * individuals on behalf of the Kannel Group. For more information on 00051 * the Kannel Group, please see <http://www.kannel.org/>. 00052 * 00053 * Portions of this software are based upon software originally written at 00054 * WapIT Ltd., Helsinki, Finland for the Kannel project. 00055 */ 00056 00057 /* 00058 * wsp_headers.h - WSP PDU headers implementation header 00059 * 00060 * Kalle Marjola <rpr@wapit.com> 00061 */ 00062 00063 #ifndef WSP_HEADERS_H 00064 #define WSP_HEADERS_H 00065 00066 #include "gwlib/gwlib.h" 00067 00068 #define WSP_FIELD_VALUE_NUL_STRING 1 00069 #define WSP_FIELD_VALUE_ENCODED 2 00070 #define WSP_FIELD_VALUE_DATA 3 00071 #define WSP_FIELD_VALUE_NONE 4 /* secondary_field_value only */ 00072 00073 /* The value defined as Quote in 8.4.2.1 */ 00074 #define WSP_QUOTE 127 00075 00076 /* Largest value that will fit in a Short-integer encoding */ 00077 #define MAX_SHORT_INTEGER 127 00078 00079 /* Marker values used in the encoding */ 00080 #define BASIC_AUTHENTICATION 128 00081 #define ABSOLUTE_TIME 128 00082 #define RELATIVE_TIME 129 00083 #define BYTE_RANGE 128 00084 #define SUFFIX_BYTE_RANGE 129 00085 00086 /* Use this value for Expires headers if we can't parse the expiration 00087 * date. It's about one day after the start of the epoch. We don't 00088 * use the exact start of the epoch because some clients have trouble 00089 * with that. */ 00090 #define LONG_AGO_VALUE 100000 00091 00092 /* LIST is a comma-separated list such as is described in the "#rule" 00093 * entry of RFC2616 section 2.1. */ 00094 #define LIST 1 00095 /* BROKEN_LIST is a list of "challenge" or "credentials" elements 00096 * such as described in RFC2617. I call it broken because the 00097 * parameters are separated with commas, instead of with semicolons 00098 * like everywhere else in HTTP. Parsing is more difficult because 00099 * commas are also used to separate list elements. */ 00100 #define BROKEN_LIST 2 00101 00102 #define TABLE_SIZE(table) ((long)(sizeof(table) / sizeof(table[0]))) 00103 00104 struct parameter 00105 { 00106 Octstr *key; 00107 Octstr *value; 00108 }; 00109 typedef struct parameter Parameter; 00110 00111 typedef int header_pack_func_t(Octstr *packed, Octstr *value); 00112 00113 struct headerinfo 00114 { 00115 /* The WSP_HEADER_* enumeration value for this header */ 00116 int header; 00117 header_pack_func_t *func; 00118 /* True if this header type allows multiple elements per 00119 * header on the HTTP side. */ 00120 int allows_list; 00121 }; 00122 00123 /* All WSP packing/unpacking routines that are exported for use within 00124 * external modules, ie. MMS encoding/decoding. 00125 */ 00126 int wsp_field_value(ParseContext *context, int *well_known_value); 00127 void wsp_skip_field_value(ParseContext *context); 00128 int wsp_secondary_field_value(ParseContext *context, long *result); 00129 void parm_destroy_item(void *parm); 00130 List *wsp_strip_parameters(Octstr *value); 00131 /* unpacking */ 00132 Octstr *wsp_unpack_integer_value(ParseContext *context); 00133 Octstr *wsp_unpack_version_value(long value); 00134 void wsp_unpack_all_parameters(ParseContext *context, Octstr *decoded); 00135 Octstr *wsp_unpack_date_value(ParseContext *context); 00136 void wsp_unpack_well_known_field(List *unpacked, int field_type, 00137 ParseContext *context); 00138 void wsp_unpack_app_header(List *unpacked, ParseContext *context); 00139 /* packing */ 00140 void wsp_pack_integer_value(Octstr *packed, unsigned long integer); 00141 int wsp_pack_date(Octstr *packet, Octstr *value); 00142 int wsp_pack_retry_after(Octstr *packet, Octstr *value); 00143 int wsp_pack_text(Octstr *packet, Octstr *value); 00144 int wsp_pack_quoted_text(Octstr *packed, Octstr *text); 00145 int wsp_pack_integer_string(Octstr *packet, Octstr *value); 00146 int wsp_pack_version_value(Octstr *packet, Octstr *value); 00147 int wsp_pack_constrained_value(Octstr *packed, Octstr *text, long value); 00148 void wsp_pack_value(Octstr *packed, Octstr *encoded); 00149 void wsp_pack_parameters(Octstr *packed, List *parms); 00150 int wsp_pack_list(Octstr *packed, long fieldnum, List *elements, int i); 00151 void wsp_pack_short_integer(Octstr *packed, unsigned long integer); 00152 void wsp_pack_separate_content_type(Octstr *packed, List *headers); 00153 Octstr *wsp_unpack_accept_general_form(ParseContext *context); 00154 Octstr *wsp_unpack_accept_charset_general_form(ParseContext *context); 00155 int wsp_pack_content_type(Octstr *packet, Octstr *value); 00156 int wsp_pack_application_header(Octstr *packed, 00157 Octstr *fieldname, Octstr *value); 00158 void wsp_pack_long_integer(Octstr *packed, unsigned long integer); 00159 00160 /* Return an HTTPHeader linked list which must be freed by the caller 00161 * (see http.h for details of HTTPHeaders). Cannot fail. 00162 * The second argument is true if the headers will have a leading 00163 * Content-Type field. Some WSP PDUs encode Content-Type separately 00164 * this way for historical reasons. 00165 */ 00166 List *wsp_headers_unpack(Octstr *headers, int content_type); 00167 00168 /* Take a List of headers, encode them according to the WSP spec, 00169 * and return the encoded headers as an Octstr. 00170 * The second argument is true if the encoded headers should have 00171 * a leading content-type field. See the note for wsp_headers_unpack. */ 00172 Octstr *wsp_headers_pack(List *headers, int separate_content_type, int wsp_version); 00173 00174 #endif