Kannel: Open Source WAP and SMS gateway  svn-r5335
wml_compiler.h File Reference

Go to the source code of this file.

Functions

int wml_compile (Octstr *wml_text, Octstr *charset, Octstr **wml_binary, Octstr *version)
 
void wml_init (int wml_xml_strict)
 
void wml_shutdown (void)
 

Function Documentation

◆ wml_compile()

int wml_compile ( Octstr wml_text,
Octstr charset,
Octstr **  wml_binary,
Octstr version 
)

Definition at line 360 of file wml_compiler.c.

References charset, debug(), error(), octstr_create, octstr_get_cstr, octstr_len(), octstr_search_char(), octstr_strip_blanks(), parse_document(), parse_entities(), size, wml_binary_create(), wml_binary_destroy(), wml_binary_output(), wml_xml_parser_opt, and xml_error().

Referenced by convert_wml_to_wmlc(), and main().

362 {
363  int ret = 0;
364  size_t size;
365  xmlDocPtr pDoc = NULL;
366  char *wml_c_text;
367  wml_binary_t *wbxml = NULL;
368 
369  *wml_binary = octstr_create("");
370  wbxml = wml_binary_create();
371 
372  /* Remove the extra space from start and the end of the WML Document. */
373  octstr_strip_blanks(wml_text);
374 
375  /* Check the WML-code for \0-characters and for WML entities. Fast patch.
376  -- tuo */
377  parse_entities(wml_text);
378 
379  size = octstr_len(wml_text);
380  wml_c_text = octstr_get_cstr(wml_text);
381 
382  debug("wml_compile",0, "WML: Given charset: %s", octstr_get_cstr(charset));
383 
384  if (octstr_search_char(wml_text, '\0', 0) != -1) {
385  error(0, "WML compiler: Compiling error: "
386  "\\0 character found in the middle of the WML source.");
387  ret = -1;
388  } else {
389  /*
390  * An empty octet string for the binary output is created, the wml
391  * source is parsed into a parsing tree and the tree is then compiled
392  * into binary.
393  */
394 
395  pDoc = xmlReadMemory(wml_c_text, size, NULL, octstr_get_cstr(charset),
397 
398  if (pDoc != NULL) {
399  /*
400  * If we have a set internal encoding, then apply this information
401  * to the XML parsing tree document for later transcoding ability.
402  */
403  if (charset)
404  pDoc->charset = xmlParseCharEncoding(octstr_get_cstr(charset));
405 
406  ret = parse_document(pDoc, charset, &wbxml, version);
407  wml_binary_output(*wml_binary, wbxml);
408  } else {
409  error(0, "WML compiler: Compiling error: "
410  "libxml2 returned a NULL pointer");
411  xml_error();
412  ret = -1;
413  }
414  }
415 
416  wml_binary_destroy(wbxml);
417 
418  if (pDoc)
419  xmlFreeDoc(pDoc);
420 
421  return ret;
422 }
void error(int err, const char *fmt,...)
Definition: log.c:648
int size
Definition: wsasm.c:84
static int parse_document(xmlDocPtr document, Octstr *charset, wml_binary_t **wbxml, Octstr *version)
Definition: wml_compiler.c:571
static void xml_error(void)
Definition: wml_compiler.c:334
static wml_binary_t * wml_binary_create(void)
void octstr_strip_blanks(Octstr *text)
Definition: octstr.c:1346
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
long octstr_search_char(const Octstr *ostr, int ch, long pos)
Definition: octstr.c:1012
Octstr * charset
Definition: test_ota.c:68
static void wml_binary_output(Octstr *ostr, wml_binary_t *wbxml)
#define octstr_create(cstr)
Definition: octstr.h:125
long octstr_len(const Octstr *ostr)
Definition: octstr.c:342
void debug(const char *place, int err, const char *fmt,...)
Definition: log.c:726
static void parse_entities(Octstr *wml_source)
static void wml_binary_destroy(wml_binary_t *wbxml)
int wml_xml_parser_opt
Definition: wml_compiler.c:226

◆ wml_init()

void wml_init ( int  wml_xml_strict)

Definition at line 429 of file wml_compiler.c.

References attr_dict_construct(), attribute_destroy(), dict_create(), dict_put(), gwlist_append(), gwlist_create, hash_create(), hash_destroy(), wml_hash_t::item, text, token, wml_attr_values_list, wml_attribute_values, wml_attributes, wml_attributes_dict, wml_elements, wml_elements_dict, wml_table3_len(), wml_table_len(), wml_URL_values, wml_URL_values_list, wml_xml_parser_opt, and wml_xml_strict.

Referenced by main().

430 {
431  int i = 0, len = 0;
432  wml_hash_t *temp = NULL;
433 
434  /* The wml elements into a hash table. */
437 
438  for (i = 0; i < len; i++) {
440  dict_put(wml_elements_dict, temp->item, temp);
441  }
442 
443  /* Attributes. */
447 
448  /* Attribute values. */
451 
452  for (i = 0; i < len; i++) {
456  }
457 
458  /* URL values. */
461 
462  for (i = 0; i < len; i++) {
465  }
466 
467  /* Strict XML parsing. */
469  (XML_PARSE_NOERROR | XML_PARSE_NONET) :
470  (XML_PARSE_RECOVER | XML_PARSE_NOERROR | XML_PARSE_NONET);
471 }
Dict * dict_create(long size_hint, void(*destroy_value)(void *))
Definition: dict.c:192
static wml_table_t wml_URL_values[]
void dict_put(Dict *dict, Octstr *key, void *value)
Definition: dict.c:240
void gwlist_append(List *list, void *item)
Definition: list.c:179
static void attr_dict_construct(wml_table3_t *attributes, Dict *attr_dict)
static void hash_destroy(void *p)
static void attribute_destroy(void *p)
static wml_hash_t * hash_create(char *text, unsigned char token)
Octstr * item
Definition: wml_compiler.c:195
int token
Definition: wslexer.c:159
List * wml_attr_values_list
Definition: wml_compiler.c:222
char * text
Definition: smsc_cimd2.c:921
static int wml_table3_len(wml_table3_t *table)
static wml_table_t wml_elements[]
Dict * wml_attributes_dict
Definition: wml_compiler.c:220
static int wml_table_len(wml_table_t *table)
static wml_table_t wml_attribute_values[]
Dict * wml_elements_dict
Definition: wml_compiler.c:218
static int wml_xml_strict
Definition: wapbox.c:108
#define gwlist_create()
Definition: list.h:136
List * wml_URL_values_list
Definition: wml_compiler.c:224
static wml_table3_t wml_attributes[]
int wml_xml_parser_opt
Definition: wml_compiler.c:226

◆ wml_shutdown()

void wml_shutdown ( void  )

Definition at line 479 of file wml_compiler.c.

References dict_destroy(), gwlist_destroy(), hash_destroy(), wml_attr_values_list, wml_attributes_dict, wml_elements_dict, and wml_URL_values_list.

Referenced by main().

480 {
485 }
static void hash_destroy(void *p)
List * wml_attr_values_list
Definition: wml_compiler.c:222
Dict * wml_attributes_dict
Definition: wml_compiler.c:220
Dict * wml_elements_dict
Definition: wml_compiler.c:218
void dict_destroy(Dict *dict)
Definition: dict.c:215
List * wml_URL_values_list
Definition: wml_compiler.c:224
void gwlist_destroy(List *list, gwlist_item_destructor_t *destructor)
Definition: list.c:145
See file LICENSE for details about the license agreement for using, modifying, copying or deriving work from this software.