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

ota_compiler.c File Reference

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

Include dependency graph for ota_compiler.c:

Include dependency graph

Go to the source code of this file.

Data Structures

struct  ota_2table_t
struct  ota_3table_t

Defines

#define NUMBER_OF_ELEMENTS   sizeof(ota_elements)/sizeof(ota_elements[0])
#define NUMBER_OF_SYNCSETTINGS_ELEMENTS   sizeof(ota_syncsettings_elements)/sizeof(ota_syncsettings_elements[0])
#define NUMBER_OF_ATTRIBUTES   sizeof(ota_attributes)/sizeof(ota_attributes[0])
#define OMA_VALUE_TAG   0x06
#define NUMBER_OF_OMA_ATTRIBUTES   sizeof(oma_ota_attributes)/sizeof(oma_ota_attributes[0])

Typedefs

typedef ota_2table_t ota_2table_t
typedef ota_3table_t ota_3table_t

Functions

int parse_document (xmlDocPtr document, Octstr *charset, simple_binary_t **ota_binary)
int parse_node (xmlNodePtr node, simple_binary_t **otabxml)
int parse_element (xmlNodePtr node, simple_binary_t **otabxml)
int parse_attribute (xmlAttrPtr attr, simple_binary_t **otabxml)
int ota_compile (Octstr *ota_doc, Octstr *charset, Octstr **ota_binary)
int parse_ota_syncsettings (xmlNodePtr node, simple_binary_t **otabxml)

Variables

ota_2table_t ota_elements []
ota_2table_t ota_syncsettings_elements []
ota_3table_t ota_attributes []
ota_3table_t oma_ota_attributes []


Define Documentation

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

Definition at line 228 of file ota_compiler.c.

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

Definition at line 132 of file ota_compiler.c.

#define NUMBER_OF_OMA_ATTRIBUTES   sizeof(oma_ota_attributes)/sizeof(oma_ota_attributes[0])
 

Definition at line 452 of file ota_compiler.c.

#define NUMBER_OF_SYNCSETTINGS_ELEMENTS   sizeof(ota_syncsettings_elements)/sizeof(ota_syncsettings_elements[0])
 

Definition at line 160 of file ota_compiler.c.

#define OMA_VALUE_TAG   0x06
 

Definition at line 450 of file ota_compiler.c.

Referenced by parse_attribute().


Typedef Documentation

typedef struct ota_2table_t ota_2table_t
 

Definition at line 104 of file ota_compiler.c.

typedef struct ota_3table_t ota_3table_t
 

Definition at line 117 of file ota_compiler.c.

Referenced by parse_attribute().


Function Documentation

int ota_compile Octstr ota_doc,
Octstr charset,
Octstr **  ota_binary
 

Definition at line 472 of file ota_compiler.c.

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

Referenced by main(), and ota_pack_message().

00473 {
00474     simple_binary_t *otabxml;
00475     int ret;
00476     xmlDocPtr pDoc;
00477     size_t size;
00478     char *ota_c_text;
00479 
00480     *ota_binary = octstr_create(""); 
00481     otabxml = simple_binary_create();
00482 
00483     octstr_strip_blanks(ota_doc);
00484     octstr_shrink_blanks(ota_doc);
00485     set_charset(ota_doc, charset);
00486     size = octstr_len(ota_doc);
00487     ota_c_text = octstr_get_cstr(ota_doc);
00488     pDoc = xmlParseMemory(ota_c_text, size);
00489 
00490     ret = 0;
00491     if (pDoc) {
00492         ret = parse_document(pDoc, charset, &otabxml);
00493         simple_binary_output(*ota_binary, otabxml);
00494         xmlFreeDoc(pDoc);
00495     } else {
00496         xmlFreeDoc(pDoc);
00497         octstr_destroy(*ota_binary);
00498         simple_binary_destroy(otabxml);
00499         error(0, "OTA: No document to parse. Probably an error in OTA source");
00500         return -1;
00501     }
00502 
00503     simple_binary_destroy(otabxml);
00504 
00505     return ret;
00506 }

Here is the call graph for this function:

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

Definition at line 748 of file ota_compiler.c.

References attr, ota_3table_t::code_page, create_octstr_from_node, error(), name, octstr_case_compare(), octstr_compare(), octstr_create, octstr_destroy(), octstr_get_cstr, octstr_imm(), OMA_VALUE_TAG, ota_3table_t, output_char(), parse_inline_string(), ota_3table_t::token, ota_3table_t::value, and warning().

00749 {
00750     Octstr *name, *value, *valueos, *nameos;
00751     unsigned char ota_hex;
00752     size_t i, limit;
00753     ota_3table_t *alist;
00754 
00755     name = octstr_create((char *)attr->name);
00756 
00757     if (attr->children != NULL)
00758         value = create_octstr_from_node((char *)attr->children);
00759     else 
00760         value = NULL;
00761 
00762     if (value == NULL)
00763         goto error;
00764 
00765     /* OMA has it's own dedicated public ID, so use this */        
00766     if ((*otabxml)->public_id == 0x0B) { 
00767         alist = oma_ota_attributes;
00768         limit = NUMBER_OF_OMA_ATTRIBUTES;
00769     } else {
00770         alist = ota_attributes;
00771         limit = NUMBER_OF_ATTRIBUTES;
00772     }
00773 
00774     i = 0;
00775     valueos = NULL;
00776     nameos = NULL;
00777     while (i < limit) {
00778         nameos = octstr_imm(alist[i].name);
00779         if (octstr_case_compare(name, nameos) == 0) {
00780             if (alist[i].value != NULL) {
00781                 valueos = octstr_imm(alist[i].value);
00782             }
00783             if (octstr_case_compare(value, valueos) == 0) {
00784                 break;
00785             }
00786             if (octstr_compare(valueos, octstr_imm("INLINE")) == 0) {
00787                 break;
00788             }
00789         }
00790        ++i;
00791     }
00792 
00793     if (i == limit) {
00794         warning(0, "OTA compiler: Unknown attribute '%s' in OTA source, "
00795                    "with value '%s'.", 
00796                 octstr_get_cstr(name), octstr_get_cstr(value));
00797         goto error;
00798     }
00799 
00800     ota_hex = alist[i].token;
00801     /* if not inline used */
00802     if (octstr_compare(valueos, octstr_imm("INLINE")) != 0) {
00803         /* Switch code page. */
00804         if (alist[i].code_page != (*otabxml)->code_page) { 
00805             output_char(0, otabxml);
00806             output_char(alist[i].code_page, otabxml);
00807             (*otabxml)->code_page = alist[i].code_page;
00808         }
00809         /* if OMA add value tag */
00810         if ((*otabxml)->public_id == 0x0B && name 
00811             && octstr_case_compare(name, octstr_imm("value")) == 0)
00812             output_char(OMA_VALUE_TAG, otabxml);
00813         output_char(ota_hex, otabxml);
00814     } else {
00815         /* Switch code page. */
00816         if (alist[i].code_page != (*otabxml)->code_page) {
00817             output_char(0, otabxml);
00818             output_char(alist[i].code_page, otabxml);
00819             (*otabxml)->code_page = alist[i].code_page;
00820         }
00821         output_char(ota_hex, otabxml);
00822         parse_inline_string(value, otabxml);
00823     }  
00824 
00825     octstr_destroy(name);
00826     octstr_destroy(value);
00827     return 0;
00828 
00829 error:
00830     octstr_destroy(name);
00831     octstr_destroy(value);
00832     return -1;
00833 }

Here is the call graph for this function:

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

Definition at line 517 of file ota_compiler.c.

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

00519 {
00520     xmlNodePtr node;
00521 
00522     if (document->intSubset && document->intSubset->ExternalID 
00523         && strcmp((char *)document->intSubset->ExternalID, "-//WAPFORUM//DTD PROV 1.0//EN") == 0) {
00524         /* OMA ProvCont */
00525         (*otabxml)->wbxml_version = 0x03; /* WBXML Version number 1.3  */
00526         (*otabxml)->public_id = 0x0B; /* Public id for this kind of doc */  
00527     } else {
00528         /* OTA */
00529         (*otabxml)->wbxml_version = 0x01; /* WBXML Version number 1.1  */
00530         (*otabxml)->public_id = 0x01; /* Public id for an unknown document type */
00531     }
00532     (*otabxml)->code_page = 0;
00533     
00534     charset = octstr_create("UTF-8");
00535     (*otabxml)->charset = parse_charset(charset);
00536     octstr_destroy(charset);
00537 
00538     node = xmlDocGetRootElement(document);
00539     return parse_node(node, otabxml);
00540 }

Here is the call graph for this function:

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

Definition at line 673 of file ota_compiler.c.

References element_check_content(), name, octstr_case_compare(), octstr_create, octstr_destroy(), octstr_duplicate, octstr_get_cstr, octstr_imm(), octstr_len(), octstr_search_char(), ota_elements, output_char(), output_octet_string(), parse_attribute(), parse_end(), parse_ota_syncsettings(), ota_2table_t::token, and warning().

00674 {
00675     Octstr *name;
00676     size_t i;
00677     unsigned char status_bits, ota_hex;
00678     int add_end_tag, syncstat;
00679     xmlAttrPtr attribute;
00680 
00681     /* if compiling a syncsettings document there's no need to
00682        continue with the parsing of ota or oma tags. */
00683     syncstat = -1;
00684     if (octstr_search_char((**otabxml).binary, 0x55, 0) == 0) {
00685         syncstat = parse_ota_syncsettings(node, otabxml);
00686         if (syncstat >= 0) {
00687             return syncstat;
00688         }
00689     }
00690 
00691     name = octstr_create((char *)node->name);
00692     if (octstr_len(name) == 0) {
00693         octstr_destroy(name);
00694         return -1;
00695     }
00696 
00697     i = 0;
00698     while (i < NUMBER_OF_ELEMENTS) {
00699         if (octstr_case_compare(name, octstr_imm(ota_elements[i].name)) == 0)
00700             break;
00701         ++i;
00702     }
00703 
00704     status_bits = 0x00;
00705     ota_hex = 0x00;
00706     add_end_tag = 0;
00707 
00708     if (i != NUMBER_OF_ELEMENTS) {
00709         ota_hex = ota_elements[i].token;
00710         if ((status_bits = element_check_content(node)) > 0) {
00711             ota_hex = ota_hex | status_bits;
00712             if ((status_bits & WBXML_CONTENT_BIT) == WBXML_CONTENT_BIT)
00713                 add_end_tag = 1;
00714         }
00715         output_char(ota_hex, otabxml);
00716     } else {
00717         warning(0, "OTA compiler: Unknown tag '%s' in OTA source", octstr_get_cstr(name));
00718         ota_hex = WBXML_LITERAL;
00719         if ((status_bits = element_check_content(node)) > 0) {
00720             ota_hex = ota_hex | status_bits;
00721             /* If this node has children, the end tag must be added after them. */
00722             if ((status_bits & WBXML_CONTENT_BIT) == WBXML_CONTENT_BIT)
00723                 add_end_tag = 1;
00724         }
00725         output_char(ota_hex, otabxml);
00726         output_octet_string(octstr_duplicate(name), otabxml);
00727     }
00728 
00729     if (node->properties != NULL) {
00730         attribute = node->properties;
00731         while (attribute != NULL) {
00732             parse_attribute(attribute, otabxml);
00733             attribute = attribute->next;
00734         }
00735         parse_end(otabxml);
00736     }
00737 
00738     octstr_destroy(name);
00739     return add_end_tag;
00740 }

Here is the call graph for this function:

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

Definition at line 549 of file ota_compiler.c.

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

00550 {
00551     int status = 0;
00552     
00553     /* Call for the parser function of the node type. */
00554     switch (node->type) {
00555         case XML_ELEMENT_NODE:
00556             status = parse_element(node, otabxml);
00557             break;
00558         case XML_TEXT_NODE:
00559         case XML_COMMENT_NODE:
00560         case XML_PI_NODE:
00561             /* Text nodes, comments and PIs are ignored. */
00562             break;
00563         /*
00564          * XML has also many other node types, these are not needed with 
00565          * OTA. Therefore they are assumed to be an error.
00566          */
00567         default:
00568             error(0, "OTA compiler: Unknown XML node in the OTA source.");
00569             return -1;
00570             break;
00571     }
00572 
00573     /* 
00574      * If node is an element with content, it will need an end tag after it's
00575      * children. The status for it is returned by parse_element.
00576      */
00577     switch (status) {
00578         case 0:
00579             if (node->children != NULL && parse_node(node->children, otabxml) == -1)
00580                 return -1;
00581             break;
00582         case 1:
00583             if (node->children != NULL && parse_node(node->children, otabxml) == -1)
00584                 return -1;
00585             parse_end(otabxml);
00586             break;
00587         case -1: /* Something went wrong in the parsing. */
00588             return -1;
00589             break;
00590         default:
00591             warning(0,"OTA compiler: Undefined return value in a parse function.");
00592             return -1;
00593             break;
00594     }
00595 
00596     if (node->next != NULL && parse_node(node->next, otabxml) == -1)
00597         return -1;
00598 
00599     return 0;
00600 }

Here is the call graph for this function:

int parse_ota_syncsettings xmlNodePtr  node,
simple_binary_t **  otabxml
[static]
 

Definition at line 609 of file ota_compiler.c.

References element_check_content(), error(), name, octstr_case_compare(), octstr_create, octstr_destroy(), octstr_get_cstr, octstr_imm(), octstr_len(), only_blanks(), ota_syncsettings_elements, output_char(), parse_inline_string(), token, ota_2table_t::token, and warning().

Referenced by parse_element().

00610 {
00611     Octstr *name, *content;
00612     unsigned char status_bits, ota_hex;
00613     int add_end_tag;
00614     size_t i;
00615 
00616     name = NULL;
00617     content = NULL;
00618     name = octstr_create((char *)node->name);
00619     if (octstr_len(name) == 0) {
00620         goto error;
00621     }
00622 
00623     i = 0;
00624     while (i < NUMBER_OF_SYNCSETTINGS_ELEMENTS) {
00625         if (octstr_case_compare(name, octstr_imm(ota_syncsettings_elements[i].name)) == 0)
00626             break;
00627         ++i;
00628     }
00629 
00630     if (i == NUMBER_OF_SYNCSETTINGS_ELEMENTS) {
00631         goto error;
00632     }
00633 
00634     ota_hex = ota_syncsettings_elements[i].token;
00635     output_char(ota_syncsettings_elements[i].token, otabxml);
00636 
00637     /* if the node has CDATA content output it. 
00638      * Else expect child tags */
00639     if (!only_blanks((char *)node->children->content)) {
00640         content = octstr_create((char *)node->children->content);
00641         parse_inline_string(content, otabxml);
00642     }
00643 
00644     add_end_tag = 0;
00645     if ((status_bits = element_check_content(node)) > 0) {
00646         ota_hex = ota_hex | status_bits;
00647         /* If this node has children, the end tag must be added after them. */
00648         if ((status_bits & WBXML_CONTENT_BIT) == WBXML_CONTENT_BIT) {
00649             add_end_tag = 1;
00650         }
00651     }
00652 
00653     octstr_destroy(content);
00654     octstr_destroy(name);
00655     return add_end_tag;
00656 
00657     error:
00658         warning(0, "OTA compiler: Unknown tag '%s' in OTA SyncSettings source",
00659                 octstr_get_cstr(name));
00660         octstr_destroy(content);
00661         octstr_destroy(name);
00662         return -1;
00663 }

Here is the call graph for this function:


Variable Documentation

ota_3table_t oma_ota_attributes[] [static]
 

Definition at line 236 of file ota_compiler.c.

ota_3table_t ota_attributes[] [static]
 

Definition at line 171 of file ota_compiler.c.

ota_2table_t ota_elements[] [static]
 

Initial value:

 {
    { "SYNCSETTINGS", 0x15 },
    { "WAP-PROVISIONINGDOC", 0x05 },
    { "CHARACTERISTIC-LIST", 0x05 },
    { "CHARACTERISTIC", 0x06 },
    { "PARM", 0x07 }
}

Definition at line 124 of file ota_compiler.c.

Referenced by parse_element().

ota_2table_t ota_syncsettings_elements[] [static]
 

Initial value:

 {
    { "Version", 0x58 },
    { "HostAddr", 0x50 },
    { "Port", 0x52 },
    { "RemoteDB", 0x54 },
    { "CTType", 0x4E },
    { "CTVer", 0x4F },
    { "URI", 0x56 },
    { "Name", 0x51 },
    { "Auth", 0x47 },
    { "AuthLevel", 0x48 },
    { "AuthScheme", 0x49 },
    { "Username", 0x57 },
    { "Cred", 0x4D },
    { "ConRef", 0x4B },
    { "ConType", 0x4E },
    { "Bearer", 0x4A },
    { "AddrType", 0x46 },
    { "Addr", 0x45 },
    { "RefID", 0x53 }
}

Definition at line 138 of file ota_compiler.c.

Referenced by parse_ota_syncsettings().

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