Kannel: Open Source WAP and SMS gateway  $Revision: 5037 $
wsbc.h
Go to the documentation of this file.
1 /* ====================================================================
2  * The Kannel Software License, Version 1.0
3  *
4  * Copyright (c) 2001-2016 Kannel Group
5  * Copyright (c) 1998-2001 WapIT Ltd.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in
17  * the documentation and/or other materials provided with the
18  * distribution.
19  *
20  * 3. The end-user documentation included with the redistribution,
21  * if any, must include the following acknowledgment:
22  * "This product includes software developed by the
23  * Kannel Group (http://www.kannel.org/)."
24  * Alternately, this acknowledgment may appear in the software itself,
25  * if and wherever such third-party acknowledgments normally appear.
26  *
27  * 4. The names "Kannel" and "Kannel Group" must not be used to
28  * endorse or promote products derived from this software without
29  * prior written permission. For written permission, please
30  * contact org@kannel.org.
31  *
32  * 5. Products derived from this software may not be called "Kannel",
33  * nor may "Kannel" appear in their name, without prior written
34  * permission of the Kannel Group.
35  *
36  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
37  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
38  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
39  * DISCLAIMED. IN NO EVENT SHALL THE KANNEL GROUP OR ITS CONTRIBUTORS
40  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
41  * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
42  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
43  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
44  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
45  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
46  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
47  * ====================================================================
48  *
49  * This software consists of voluntary contributions made by many
50  * individuals on behalf of the Kannel Group. For more information on
51  * the Kannel Group, please see <http://www.kannel.org/>.
52  *
53  * Portions of this software are based upon software originally written at
54  * WapIT Ltd., Helsinki, Finland for the Kannel project.
55  */
56 
57 /*
58  *
59  * wsbc.h
60  *
61  * Author: Markku Rossi <mtr@iki.fi>
62  *
63  * Copyright (c) 1999-2000 WAPIT OY LTD.
64  * All rights reserved.
65  *
66  * Byte-code handling.
67  *
68  */
69 
70 #ifndef WSBC_H
71 #define WSBC_H
72 
73 #include "wsint.h"
74 
75 /********************* Types and defintions *****************************/
76 
77 /* The byte-code version numbers. */
78 #define WS_BC_VERSION_MAJOR 1
79 #define WS_BC_VERSION_MINOR 1
80 #define WS_BC_VERSION (((WS_BC_VERSION_MAJOR - 1) << 4) | WS_BC_VERSION_MINOR)
81 
82 /* The maximum length of the byte-code header: the multi-byte encoded
83  length + one byte for the version information. */
84 #define WS_BC_MAX_HEADER_LEN (WS_MB_UINT32_MAX_ENCODED_LEN + 1)
85 
86 /* The string encoding, used in the byte-code data. These are the
87  MIBEnum values, assigned by IANA. For a complete description of
88  the character sets and values, please see the document
89  `rfc/iana/assignments/character-sets'. */
90 typedef enum
91 {
95 
96 /* Constant types in the BC constants pool. */
97 #define WS_BC_CONST_INT8 0
98 #define WS_BC_CONST_INT16 1
99 #define WS_BC_CONST_INT32 2
100 #define WS_BC_CONST_FLOAT32 3
101 #define WS_BC_CONST_UTF8_STRING 4
102 #define WS_BC_CONST_EMPTY_STRING 5
103 #define WS_BC_CONST_EXT_ENC_STRING 6
104 #define WS_BC_CONST_FIRST_RESERVED 7
105 
106 /* An in-memory byte-code constant. */
107 
108 typedef enum
109 {
118 
120 {
122 
123  union
124  {
128  } u;
129 };
130 
132 
133 /* Pragma types in the BC pragma pool. */
134 #define WS_BC_PRAGMA_ACCESS_DOMAIN 0
135 #define WS_BC_PRAGMA_ACCESS_PATH 1
136 #define WS_BC_PRAGMA_USER_AGENT_PROPERTY 2
137 #define WS_BC_PRAGMA_USER_AGENT_PROPERTY_AND_SCHEME 3
138 #define WS_BC_PRAGMA_FIRST_RESERVED 4
139 
140 /* An in-memory byte-code pragma. */
141 
142 typedef enum
143 {
149 
151 {
153 
157 };
158 
159 typedef struct WsBcPragmaRec WsBcPragma;
160 
161 /* An in-memory byte-code function name. */
163 {
164  /* Index to the function pool. */
166 
167  /* The name of the function as a 7 bit ASCII. This is as-is in the
168  UTF-8 format. */
169  char *name;
170 };
171 
173 
174 /* An in-memory byte-code function. */
176 {
180  unsigned char *code;
181 };
182 
184 
185 /* An in-memory byte-code file. */
186 struct WsBcRec
187 {
188  /* How the strings are encoded in linearization. */
190 
191  /* Constant pool. In this structure, all strings are in UTF-8
192  format. However, they can be converted to different formats - if
193  requested - when linearizing the byte-code. */
196 
197  /* Pragma pool. */
200 
201  /* Function pool. */
202 
205 
208 };
209 
210 typedef struct WsBcRec WsBc;
211 
212 /********************* Manipulating byte-code structure *****************/
213 
214 /* Allocate a new byte-code structure. The argument `string_encoding'
215  specifies the encoding that is used for strings. The function
216  returns NULL if the allocation failed. */
218 
219 /* Free the byte-code structure `bc' and all its internally allocated
220  data structures. The byte-code handle `bc' should not be used
221  after this function. */
222 void ws_bc_free(WsBc *bc);
223 
224 /* Encode the byte-code structure `bc' into a linearized binary
225  byte-code blob. The function returns WS_TRUE if the encoding was
226  successful of WS_FALSE otherwise. The result blob is returned in
227  `data_return' and its length is returned in `data_len_return'. The
228  returned byte-code block must be freed with the ws_bc_data_free()
229  function. You *must* not free it with ws_free() since it will
230  corrupt the heap. */
231 WsBool ws_bc_encode(WsBc *bc, unsigned char **data_return,
232  size_t *data_len_return);
233 
234 /* Free a byte-code data `data', returned by the ws_bc_encode()
235  function. */
236 void ws_bc_data_free(unsigned char *data);
237 
238 /* Decode the byte-code data `data' into an in-memory byte-code
239  structure. The function returns the byte-code structure or NULL if
240  the decoding fails. The argument `data_len' specfies the length of
241  the byte-code data `data'. The returned byte-code structure must
242  be freed with the ws_bc_free() function when it is not needed
243  anymore. */
244 WsBc *ws_bc_decode(const unsigned char *data, size_t data_len);
245 
246 /********************* Adding constant elements *************************/
247 
248 /* Add an integer constant `value' to the constant pool of the
249  byte-code structure `bc'. The index of the constant is returned in
250  `index_return'. The function returns WS_TRUE if the operation was
251  successful or WS_FALSE otherwise (out of memory). */
252 WsBool ws_bc_add_const_int(WsBc *bc, WsUInt16 *index_return,
253  WsInt32 value);
254 
255 /* Add a floating point constant `value' to the constant pool of the
256  byte-code structure `bc'. */
257 WsBool ws_bc_add_const_float(WsBc *bc, WsUInt16 *index_return, WsFloat value);
258 
259 /* Add an UTF-8 encoded string to the constant pool of the byte-code
260  structure `bc'. */
262  const unsigned char *data, size_t len);
263 
264 /* Add an empty string to the constant pool of the byte-code structure
265  `bc'. */
267 
268 /********************* Adding pragmas ***********************************/
269 
270 /* Add an access control specifier pragma to the constant and pragma
271  pools of the byte-code structure `bc'. The argument `domain' has
272  `domain_len' bytes of UTF-8 data specifying the access domain. */
274  const unsigned char *domain,
275  size_t domain_len);
276 
277 /* Add an access control specifier pragma to the constant and pragma
278  pools of the byte-code structure `bc'. The argument `path' has
279  `path_len' bytes of UTF-8 data specifying the access path. */
281  const unsigned char *path,
282  size_t path_len);
283 
284 /* Add a use agent property pragma to the constant and pragma pools of
285  the byte-code structure `bc'. The arguments `name' and `property'
286  are UTF-8 encoded use agent property. */
288  const unsigned char *name,
289  size_t name_len,
290  const unsigned char *property,
291  size_t property_len);
292 
293 /* Add a use agent property pragma to the constant and pragma pools of
294  the byte-code structure `bc'. The arguments `name', `property',
295  and `scheme' are UTF-8 encoded use agent property and scheme. */
297  WsBc *bc,
298  const unsigned char *name,
299  size_t name_len,
300  const unsigned char *property,
301  size_t property_len,
302  const unsigned char *scheme,
303  size_t scheme_len);
304 
305 /********************* Adding functions *********************************/
306 
307 /* Add a new function to the function pool of the byte-code structure
308  `bc'. The argument `name' specifies the name of the function for
309  external functions. For internal functions, the `name' argument
310  must be NULL. The argument `num_arguments' specifies the number of
311  arguments the function takes. The argument `num_locals' specifies
312  how many local variables the function needs. The byte-code of the
313  function is in `code' and it is `code_size' bytes long. The
314  function takes a copy of the byte-code array `code'. The caller
315  can free / modify the original array, pointed by the argument
316  `code', after the function returns. The function returns WS_TRUE
317  if the adding was successful or WS_FALSE otherwise (out of
318  memory). */
319 WsBool ws_bc_add_function(WsBc *bc, WsUInt8 *index_return,
320  char *name, WsUInt8 num_arguments,
321  WsUInt8 num_locals, WsUInt32 code_size,
322  unsigned char *code);
323 
324 #endif /* not WSBC_H */
WsBcConstantType type
Definition: wsbc.h:121
size_t name_len
Definition: wslexer.c:156
WsUInt16 num_constants
Definition: wsbc.h:194
unsigned long WsUInt32
Definition: wsint.h:122
WsBcStringEncoding string_encoding
Definition: wsbc.h:189
WsBc * ws_bc_decode(const unsigned char *data, size_t data_len)
Definition: wsbc.c:457
double WsFloat
Definition: wsint.h:126
WsBcFunction * functions
Definition: wsbc.h:207
int code
Definition: smsc_cimd2.c:346
WsInt32 v_int
Definition: wsbc.h:125
WsUInt8 num_functions
Definition: wsbc.h:206
void ws_bc_free(WsBc *bc)
Definition: wsbc.c:97
WsBool ws_bc_add_const_empty_string(WsBc *bc, WsUInt16 *index_return)
Definition: wsbc.c:951
WsBool ws_bc_add_pragma_user_agent_property(WsBc *bc, const unsigned char *name, size_t name_len, const unsigned char *property, size_t property_len)
Definition: wsbc.c:1011
WsBool ws_bc_add_function(WsBc *bc, WsUInt8 *index_return, char *name, WsUInt8 num_arguments, WsUInt8 num_locals, WsUInt32 code_size, unsigned char *code)
Definition: wsbc.c:1056
WsBcConstant * constants
Definition: wsbc.h:195
WsBcFunctionName * function_names
Definition: wsbc.h:204
WsBool ws_bc_add_const_utf8_string(WsBc *bc, WsUInt16 *index_return, const unsigned char *data, size_t len)
Definition: wsbc.c:912
WsUtf8String v_string
Definition: wsbc.h:127
WsBool ws_bc_add_const_float(WsBc *bc, WsUInt16 *index_return, WsFloat value)
Definition: wsbc.c:881
WsFloat v_float
Definition: wsbc.h:126
WsBool ws_bc_add_pragma_access_domain(WsBc *bc, const unsigned char *domain, size_t domain_len)
Definition: wsbc.c:981
unsigned char WsUInt8
Definition: wsint.h:116
WsUInt8 num_function_names
Definition: wsbc.h:203
void ws_bc_data_free(unsigned char *data)
Definition: wsbc.c:426
WsBcStringEncoding
Definition: wsbc.h:90
unsigned short WsUInt16
Definition: wsint.h:119
WsUInt32 code_size
Definition: wsbc.h:179
WsBcPragma * pragmas
Definition: wsbc.h:199
WsBcPragmaType
Definition: wsbc.h:142
WsUInt16 index_2
Definition: wsbc.h:155
char * name
Definition: smsc_cimd2.c:212
WsUInt16 index_1
Definition: wsbc.h:154
WsBool ws_bc_add_pragma_user_agent_property_and_scheme(WsBc *bc, const unsigned char *name, size_t name_len, const unsigned char *property, size_t property_len, const unsigned char *scheme, size_t scheme_len)
Definition: wsbc.c:1030
WsBcConstantType
Definition: wsbc.h:108
WsBool
Definition: wsint.h:128
WsUInt16 num_pragmas
Definition: wsbc.h:198
union WsBcConstantRec::@116 u
WsUInt8 num_locals
Definition: wsbc.h:178
WsBc * ws_bc_alloc(WsBcStringEncoding string_encoding)
Definition: wsbc.c:84
WsBool ws_bc_encode(WsBc *bc, unsigned char **data_return, size_t *data_len_return)
Definition: wsbc.c:132
signed long WsInt32
Definition: wsint.h:121
unsigned char * code
Definition: wsbc.h:180
WsBool ws_bc_add_pragma_access_path(WsBc *bc, const unsigned char *path, size_t path_len)
Definition: wsbc.c:996
WsUInt16 index_3
Definition: wsbc.h:156
Definition: wsbc.h:186
WsUInt8 num_arguments
Definition: wsbc.h:177
WsBool ws_bc_add_const_int(WsBc *bc, WsUInt16 *index_return, WsInt32 value)
Definition: wsbc.c:850
WsUInt8 index
Definition: wsbc.h:165
WsBcPragmaType type
Definition: wsbc.h:152
See file LICENSE for details about the license agreement for using, modifying, copying or deriving work from this software.