Main Page | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

wap_push_sl_compiler.c File Reference

#include <ctype.h>
#include <libxml/xmlmemory.h>
#include <libxml/tree.h>
#include <libxml/debugXML.h>
#include <libxml/encoding.h>
#include "xml_shared.h"
#include "wap_push_sl_compiler.h"
#include "xml_definitions.h"

Include dependency graph for wap_push_sl_compiler.c:

Include dependency graph

Go to the source code of this file.

Data Structures

struct  sl_2table_t
struct  sl_3table_t

Defines

#define NUMBER_OF_ELEMENTS   sizeof(sl_elements)/sizeof(sl_elements[0])
#define NUMBER_OF_ATTRIBUTES   sizeof(sl_attributes)/sizeof(sl_attributes[0])
#define NUMBER_OF_URL_VALUES   sizeof(sl_url_values)/sizeof(sl_url_values[0])

Typedefs

typedef sl_2table_t sl_2table_t
typedef sl_3table_t sl_3table_t

Functions

int parse_document (xmlDocPtr document, Octstr *charset, simple_binary_t **slbxml)
int parse_node (xmlNodePtr node, simple_binary_t **slbxml)
int parse_element (xmlNodePtr node, simple_binary_t **slbxml)
int parse_attribute (xmlAttrPtr attr, simple_binary_t **slbxml)
int url (int hex)
int action (int hex)
void parse_url_value (Octstr *value, simple_binary_t **slbxml)
int sl_compile (Octstr *sl_doc, Octstr *charset, Octstr **sl_binary)

Variables

sl_2table_t sl_elements []
sl_3table_t sl_attributes []
sl_2table_t sl_url_values []


Define Documentation

#define NUMBER_OF_ATTRIBUTES   sizeof(sl_attributes)/sizeof(sl_attributes[0])
 

Definition at line 126 of file wap_push_sl_compiler.c.

#define NUMBER_OF_ELEMENTS   sizeof(sl_elements)/sizeof(sl_elements[0])
 

Definition at line 108 of file wap_push_sl_compiler.c.

#define NUMBER_OF_URL_VALUES   sizeof(sl_url_values)/sizeof(sl_url_values[0])
 

Definition at line 140 of file wap_push_sl_compiler.c.


Typedef Documentation

typedef struct sl_2table_t sl_2table_t
 

Definition at line 86 of file wap_push_sl_compiler.c.

typedef struct sl_3table_t sl_3table_t
 

Definition at line 98 of file wap_push_sl_compiler.c.


Function Documentation

int action int  hex  )  [static]
 

Definition at line 439 of file wap_push_sl_compiler.c.

Referenced by parse_attribute().

00440 {
00441     switch ((unsigned char) hex) {
00442     case 0x05: case 0x06: /* action execute-low, action execute-high */
00443     case 0x07:            /* action cache */
00444     return 1;
00445     }
00446     return 0;
00447 }

int parse_attribute xmlAttrPtr  attr,
simple_binary_t **  slbxml
[static]
 

Definition at line 353 of file wap_push_sl_compiler.c.

References action(), attr, create_octstr_from_node, debug(), error(), name, octstr_compare(), octstr_create, octstr_delete(), octstr_destroy(), octstr_imm(), octstr_len(), octstr_ncompare(), output_char(), parse_inline_string(), parse_url_value(), sl_attributes, sl_3table_t::token, url(), sl_3table_t::value_part, and warning().

00354 {
00355     Octstr *name,
00356            *value,
00357            *valueos;
00358     unsigned char sl_hex;
00359     size_t i,
00360            value_len;
00361 
00362     name = octstr_create((char *)attr->name);
00363 
00364     if (attr->children != NULL)
00365         value = create_octstr_from_node((char *)attr->children);
00366     else
00367         value = NULL;
00368 
00369     if (value == NULL)
00370         goto error;
00371 
00372     i = 0;
00373     valueos = NULL;
00374     while (i < NUMBER_OF_ATTRIBUTES) {
00375         if (octstr_compare(name, octstr_imm(sl_attributes[i].name)) == 0) {
00376         if (sl_attributes[i].value_part == NULL) {
00377             debug("wap.push.sl.compiler", 0, "value part was NULL");
00378             break; 
00379             } else {
00380                 value_len = octstr_len(valueos = 
00381                     octstr_imm(sl_attributes[i].value_part));
00382             if (octstr_ncompare(value, valueos, value_len) == 0) {
00383             break;
00384                 }
00385             }
00386         }
00387        ++i;
00388     }
00389 
00390     if (i == NUMBER_OF_ATTRIBUTES) {
00391         warning(0, "unknown attribute in SL source");
00392         goto error;
00393     }
00394 
00395     sl_hex = sl_attributes[i].token;
00396     if (action(sl_hex)) {
00397         output_char(sl_hex, slbxml);
00398     } else if (url(sl_hex)) {
00399         output_char(sl_hex, slbxml);
00400         octstr_delete(value, 0, octstr_len(valueos));
00401         parse_url_value(value, slbxml);
00402     } else {
00403         output_char(sl_hex, slbxml);
00404         parse_inline_string(value, slbxml);
00405     } 
00406 
00407     octstr_destroy(name);
00408     octstr_destroy(value);
00409     return 0;
00410 
00411 error:
00412     octstr_destroy(name);
00413     octstr_destroy(value);
00414     return -1;    
00415 }

Here is the call graph for this function:

int parse_document xmlDocPtr  document,
Octstr charset,
simple_binary_t **  slbxml
[static]
 

Definition at line 205 of file wap_push_sl_compiler.c.

References charset, octstr_create, octstr_destroy(), parse_charset(), parse_node(), simple_binary_t::public_id, and simple_binary_t::wbxml_version.

00207 {
00208     xmlNodePtr node;
00209 
00210     (**slbxml).wbxml_version = 0x02; /* WBXML Version number 1.2  */
00211     (**slbxml).public_id = 0x06;  /* SL 1.0 Public ID */
00212     
00213     charset = octstr_create("UTF-8");
00214     (**slbxml).charset = parse_charset(charset);
00215     octstr_destroy(charset);
00216 
00217     node = xmlDocGetRootElement(document);
00218     return parse_node(node, slbxml);
00219 }

Here is the call graph for this function:

int parse_element xmlNodePtr  node,
simple_binary_t **  slbxml
[static]
 

Definition at line 296 of file wap_push_sl_compiler.c.

References element_check_content(), name, octstr_compare(), octstr_create, octstr_destroy(), octstr_duplicate, octstr_get_cstr, octstr_imm(), octstr_len(), output_char(), output_octet_string(), parse_attribute(), parse_end(), sl_elements, sl_2table_t::token, and warning().

00297 {
00298     Octstr *name,
00299            *nameos;
00300     unsigned char status_bits,
00301              sl_hex;
00302     int add_end_tag;
00303     xmlAttrPtr attribute;
00304 
00305     name = octstr_create((char *)node->name);
00306     if (octstr_len(name) == 0) {
00307         octstr_destroy(name);
00308         return -1;
00309     }
00310 
00311     status_bits = 0x00;
00312     sl_hex = 0x00;
00313     add_end_tag = 0;
00314 
00315     if (octstr_compare(name, octstr_imm(sl_elements[0].name)) != 0) {
00316         warning(0, "unknown tag %s in SL source", octstr_get_cstr(name));
00317         sl_hex = WBXML_LITERAL;
00318         if ((status_bits = element_check_content(node)) > 0) {
00319         sl_hex = sl_hex | status_bits;
00320         /* If this node has children, the end tag must be added after 
00321            them. */
00322         if ((status_bits & WBXML_CONTENT_BIT) == WBXML_CONTENT_BIT)
00323         add_end_tag = 1;
00324     }
00325     output_char(sl_hex, slbxml);
00326         output_octet_string(nameos = octstr_duplicate(name), slbxml);
00327         octstr_destroy(nameos);
00328     } else {
00329         sl_hex = sl_elements[0].token;
00330         if ((status_bits = element_check_content(node)) > 0) {
00331         sl_hex = sl_hex | status_bits;
00332         
00333         if ((status_bits & WBXML_CONTENT_BIT) == WBXML_CONTENT_BIT) {
00334             add_end_tag = 1;
00335             }
00336             output_char(sl_hex, slbxml);
00337         }
00338     }
00339 
00340     if (node->properties != NULL) {
00341     attribute = node->properties;
00342     while (attribute != NULL) {
00343         parse_attribute(attribute, slbxml);
00344         attribute = attribute->next;
00345     }
00346     parse_end(slbxml);
00347     }
00348 
00349     octstr_destroy(name);
00350     return add_end_tag;
00351 }

Here is the call graph for this function:

int parse_node xmlNodePtr  node,
simple_binary_t **  slbxml
[static]
 

Definition at line 230 of file wap_push_sl_compiler.c.

References error(), parse_element(), parse_end(), parse_node(), and warning().

00231 {
00232     int status = 0;
00233     
00234     /* Call for the parser function of the node type. */
00235     switch (node->type) {
00236     case XML_ELEMENT_NODE:
00237     status = parse_element(node, slbxml);
00238     break;
00239     case XML_TEXT_NODE:
00240     case XML_COMMENT_NODE:
00241     case XML_PI_NODE:
00242     /* Text nodes, comments and PIs are ignored. */
00243     break;
00244     /*
00245      * XML has also many other node types, these are not needed with 
00246      * SL. Therefore they are assumed to be an error.
00247      */
00248     default:
00249     error(0, "SL COMPILER: Unknown XML node in the SL source.");
00250     return -1;
00251     break;
00252     }
00253 
00254     /* 
00255      * If node is an element with content, it will need an end tag after it's
00256      * children. The status for it is returned by parse_element.
00257      */
00258     switch (status) {
00259     case 0:
00260 
00261     if (node->children != NULL)
00262         if (parse_node(node->children, slbxml) == -1)
00263         return -1;
00264     break;
00265     case 1:
00266     if (node->children != NULL)
00267         if (parse_node(node->children, slbxml) == -1)
00268         return -1;
00269     parse_end(slbxml);
00270     break;
00271 
00272     case -1: /* Something went wrong in the parsing. */
00273     return -1;
00274     default:
00275     warning(0,"SL compiler: undefined return value in a parse function.");
00276     return -1;
00277     break;
00278     }
00279 
00280     if (node->next != NULL)
00281     if (parse_node(node->next, slbxml) == -1)
00282         return -1;
00283 
00284     return 0;
00285 }

Here is the call graph for this function:

void parse_url_value Octstr value,
simple_binary_t **  slbxml
[static]
 

Definition at line 456 of file wap_push_sl_compiler.c.

References name, octstr_delete(), octstr_destroy(), octstr_duplicate, octstr_imm(), octstr_len(), octstr_search(), output_char(), parse_inline_string(), sl_url_values, and token.

Referenced by parse_attribute().

00457 {
00458     size_t i;
00459     long pos;
00460     Octstr *urlos,
00461            *first_part,
00462        *last_part;
00463     size_t first_part_len;
00464 
00465     i = 0;
00466     first_part_len = 0;
00467     first_part = NULL;
00468     last_part = NULL;
00469     while (i < NUMBER_OF_URL_VALUES) {
00470         pos = octstr_search(value, 
00471             urlos = octstr_imm(sl_url_values[i].name), 0);
00472         if (pos >= 0) {
00473         first_part = octstr_duplicate(value);
00474             octstr_delete(first_part, pos, octstr_len(first_part) - pos);
00475             first_part_len = octstr_len(first_part);
00476             parse_inline_string(first_part, slbxml);
00477             output_char(sl_url_values[i].token, slbxml);
00478             last_part = octstr_duplicate(value);
00479             octstr_delete(last_part, 0, first_part_len + octstr_len(urlos));
00480             parse_inline_string(last_part, slbxml);
00481         octstr_destroy(first_part);
00482             octstr_destroy(last_part);
00483             break;
00484         }
00485         octstr_destroy(urlos);
00486         ++i;
00487     }
00488 
00489     if (pos < 0) 
00490     parse_inline_string(value, slbxml);
00491         
00492 }

Here is the call graph for this function:

int sl_compile Octstr sl_doc,
Octstr charset,
Octstr **  sl_binary
 

Definition at line 162 of file wap_push_sl_compiler.c.

References charset, error(), octstr_create, octstr_destroy(), octstr_get_cstr, octstr_len(), octstr_strip_blanks(), parse_document(), set_charset(), simple_binary_create(), simple_binary_destroy(), simple_binary_output(), and size.

Referenced by convert_sl_to_slc(), and main().

00163 {
00164     simple_binary_t *slbxml;
00165     int ret;
00166     xmlDocPtr pDoc;
00167     size_t size;
00168     char *sl_c_text;
00169 
00170     *sl_binary = octstr_create(""); 
00171     slbxml = simple_binary_create();
00172 
00173     octstr_strip_blanks(sl_doc);
00174     set_charset(sl_doc, charset);
00175     size = octstr_len(sl_doc);
00176     sl_c_text = octstr_get_cstr(sl_doc);
00177     pDoc = xmlParseMemory(sl_c_text, size);
00178 
00179     ret = 0;
00180     if (pDoc) {
00181         ret = parse_document(pDoc, charset, &slbxml);
00182         simple_binary_output(*sl_binary, slbxml);
00183         xmlFreeDoc(pDoc);
00184     } else {
00185         xmlFreeDoc(pDoc);
00186         octstr_destroy(*sl_binary);
00187         simple_binary_destroy(slbxml);
00188         error(0, "SL: No document to parse. Probably an error in SL source");
00189         return -1;
00190     }
00191 
00192     simple_binary_destroy(slbxml);
00193 
00194     return ret;
00195 }

Here is the call graph for this function:

int url int  hex  )  [static]
 

Definition at line 422 of file wap_push_sl_compiler.c.

Referenced by parse_attribute().

00423 {
00424     switch ((unsigned char) hex) {
00425     case 0x08:            /* href */
00426     case 0x09: case 0x0b: /* href http://, href https:// */
00427     case 0x0a: case 0x0c: /* href http://www., href https://www. */
00428     return 1;
00429     }
00430     return 0;
00431 }


Variable Documentation

sl_3table_t sl_attributes[] [static]
 

Initial value:

 {
    { "action", "execute-low", 0x05 }, 
    { "action", "execute-high", 0x06 }, 
    { "action", "cache", 0x07 }, 
    { "href", "http://", 0x09 },
    { "href", "http://www.", 0x0a }, 
    { "href", "https://", 0x0b },    
    { "href", "https://www.", 0x0c },
    { "href", NULL, 0x08 }
}

Definition at line 115 of file wap_push_sl_compiler.c.

Referenced by parse_attribute().

sl_2table_t sl_elements[] [static]
 

Initial value:

 {
    { "sl", 0x05 }
}

Definition at line 104 of file wap_push_sl_compiler.c.

Referenced by parse_element().

sl_2table_t sl_url_values[] [static]
 

Initial value:

 {
    { ".com/", 0x85 },
    { ".edu/", 0x86 },
    { ".net/", 0x87 },
    { ".org/", 0x88 },
}

Definition at line 133 of file wap_push_sl_compiler.c.

Referenced by parse_url_value().

See file LICENSE for details about the license agreement for using, modifying, copying or deriving work from this software.