diff options
Diffstat (limited to 'stack/xml')
-rw-r--r-- | stack/xml/xml_bld.c | 192 | ||||
-rw-r--r-- | stack/xml/xml_erp.c | 907 | ||||
-rw-r--r-- | stack/xml/xml_flp.c | 971 | ||||
-rw-r--r-- | stack/xml/xml_mlp.c | 1060 | ||||
-rw-r--r-- | stack/xml/xml_parse.c | 1502 | ||||
-rw-r--r-- | stack/xml/xml_vlist.c | 873 |
6 files changed, 0 insertions, 5505 deletions
diff --git a/stack/xml/xml_bld.c b/stack/xml/xml_bld.c deleted file mode 100644 index 57a7347..0000000 --- a/stack/xml/xml_bld.c +++ /dev/null @@ -1,192 +0,0 @@ -/***************************************************************************** -** -** Name: xml_bld_api.c -** -** File: Implements the XML Builder -** -** -** Copyright (c) 2000-2004, WIDCOMM Inc., All Rights Reserved. -** WIDCOMM Bluetooth Core. Proprietary and confidential. -** -*****************************************************************************/ - -#include <string.h> -#include <stdio.h> - -#include "bt_target.h" -#include "xml_bld_api.h" - -/* The XML Builder is dependent on the Object Store. At present -** the object store resides in GOEP and hence the builder is -** dependent on GOEP. The builder only uses the Object Store -** in GOEP, so if the Object Store is separated from GOEP in the -** future, the builder will not be dependent on GOEP. -*/ - -/***************************************************************************** -** Constants -*****************************************************************************/ -#define XML_ST "<" -#define XML_EM "/" -#define XML_SP " " -#define XML_CO ":" -#define XML_EQ "=" -#define XML_GT ">" -#define XML_QT "\"" - -#define XML_LF "\n" /* Line feed */ - -/***************************************************************************** -** Interface functions -*****************************************************************************/ - - -/***************************************************************************** -** -** Function: XML_BufAddTag -** -** Purpose: Write a start or end tag and optional prefix. -** -** Parameters: -** UINT8 **pp_buf reference to the storage to hold the XML object -** GOEP_WriteStore. -** const UINT8* prefix tag prefix (namespace) -** const UINT8* tag tag name -** BOOLEAN start_tag TRUE = start tag, FALSE = end tag -** BOOLEAN has_attr TRUE if the tag contains attributes -** -** Returns: XML_BLD_SUCCESS if success -** -*****************************************************************************/ -tXML_BLD_RESULT XML_BufAddTag (UINT8 **pp_buf, - const UINT8 *prefix, - const UINT8 *tag, - BOOLEAN start_tag, - BOOLEAN has_attr) -{ - UINT16 status = XML_BLD_ERROR; - int n; - - if (tag != NULL) - { - if(start_tag) - n = sprintf((char *)*pp_buf, XML_ST); - else - n = sprintf((char *)*pp_buf, XML_ST XML_EM); - *pp_buf += n; - - if (prefix != NULL) - { - n = sprintf((char *)*pp_buf, "%s" XML_CO, prefix ); - *pp_buf += n; - } - n = sprintf((char *)*pp_buf, "%s" , tag ); - *pp_buf += n; - if(!has_attr) - { - n = sprintf((char *)*pp_buf, XML_GT); - *pp_buf += n; - if (!start_tag) - { - n = sprintf((char *)*pp_buf, XML_LF); - *pp_buf += n; - } - } - - status = XML_BLD_SUCCESS; - } - return status; -} - - - -/***************************************************************************** -** -** Function: XML_BufAddAttribute -** -** Purpose: Write an attribute and optional prefix. -** -** Parameters: -** UINT8 **pp_buf reference to the storage to hold the XML object -** const UINT8* prefix attribute prefix (namespace) -** const UINT8* attr_name attribute name -** const UINT8* attr_value attribute value -** -** Returns: XML_BLD_SUCCESS if success -** -*****************************************************************************/ -tXML_BLD_RESULT XML_BufAddAttribute (UINT8 **pp_buf, - const UINT8 *prefix, - const UINT8 *attr_name, - const UINT8 *attr_value, - tXML_ATTR_END last_attr) -{ - UINT16 status = XML_BLD_ERROR; - int n; - - if (attr_name != NULL && attr_value != NULL) - { - n = sprintf((char *)*pp_buf, XML_SP); - *pp_buf += n; - if (prefix != NULL) - { - n = sprintf((char *)*pp_buf, "%s" XML_CO, prefix ); - *pp_buf += n; - } - n = sprintf((char *)*pp_buf, "%s" XML_EQ XML_QT "%s", attr_name, attr_value ); - *pp_buf += n; - switch(last_attr) - { - case XML_ATTR_CONT: - n = sprintf((char *)*pp_buf, XML_QT ); - break; - case XML_ATTR_LAST: - n = sprintf((char *)*pp_buf, XML_QT XML_GT XML_LF ); - break; - case XML_ATTR_ETAG: - n = sprintf((char *)*pp_buf, XML_QT XML_EM XML_GT XML_LF ); - break; - default: - n = 0; - break; - } - *pp_buf += n; - status = XML_BLD_SUCCESS; - } - else if(last_attr == XML_ATTR_ETAG) - { - /* allow the call to only add the closing attribute */ - n = sprintf((char *)*pp_buf, XML_EM XML_GT XML_LF ); - *pp_buf += n ; - status = XML_BLD_SUCCESS; - } - return status; -} - -/***************************************************************************** -** -** Function: XML_BufAddCharData -** -** Purpose: Write the element content. -** -** Parameters: -** UINT8 **pp_buf reference to the storage to hold the XML object -** const UINT8* content element content -** -** Returns: XML_BLD_SUCCESS if success -** -*****************************************************************************/ -tXML_BLD_RESULT XML_BufAddCharData (UINT8 **pp_buf, const UINT8 *charData) -{ - UINT16 status = XML_BLD_ERROR; - int n; - - if (charData != NULL) - { - n = sprintf((char *)*pp_buf, "%s", charData); - *pp_buf += n; - status = XML_BLD_SUCCESS; - } - return status; -} - diff --git a/stack/xml/xml_erp.c b/stack/xml/xml_erp.c deleted file mode 100644 index 90711e2..0000000 --- a/stack/xml/xml_erp.c +++ /dev/null @@ -1,907 +0,0 @@ -/****************************************************************************** - ** - ** Name: xml_erp.c - ** - ** Description: This module contains xml parser of MAP event report object - ** - ** Copyright (c) 2004-2011, Broadcom Corporation, All Rights Reserved. - ** Broadcom Bluetooth Core. Proprietary and confidential. - ******************************************************************************/ - -#include "bt_target.h" -#include "gki.h" -#include "xml_erp_api.h" - -#include <string.h> -#include <stdlib.h> - -#ifndef EVT_RPT_DEBUG_XML -#define EVT_RPT_DEBUG_XML TRUE -#endif -#define EVT_RPT_DEBUG_LEN 50 -#if (defined(EVT_RPT_DEBUG_XML) && EVT_RPT_DEBUG_XML == TRUE) -#define XML_TRACE_DEBUG0(m) {BT_TRACE_0(TRACE_LAYER_GOEP, TRACE_TYPE_DEBUG, m);} -#define XML_TRACE_DEBUG1(m,p1) {BT_TRACE_1(TRACE_LAYER_GOEP, TRACE_TYPE_DEBUG, m,p1);} -#define XML_TRACE_DEBUG2(m,p1,p2) {BT_TRACE_2(TRACE_LAYER_GOEP, TRACE_TYPE_DEBUG, m,p1,p2);} -#define XML_TRACE_DEBUG3(m,p1,p2,p3) {BT_TRACE_3(TRACE_LAYER_GOEP, TRACE_TYPE_DEBUG, m,p1,p2,p3);} -#define XML_TRACE_DEBUG4(m,p1,p2,p3,p4) {BT_TRACE_4(TRACE_LAYER_GOEP, TRACE_TYPE_DEBUG, m,p1,p2,p3,p4);} -#define XML_TRACE_DEBUG5(m,p1,p2,p3,p4,p5) {BT_TRACE_5(TRACE_LAYER_GOEP, TRACE_TYPE_DEBUG, m,p1,p2,p3,p4,p5);} -#define XML_TRACE_DEBUG6(m,p1,p2,p3,p4,p5,p6) {BT_TRACE_6(TRACE_LAYER_GOEP, TRACE_TYPE_DEBUG, m,p1,p2,p3,p4,p5,p6);} -#else -#define XML_TRACE_DEBUG0(m) -#define XML_TRACE_DEBUG1(m,p1) -#define XML_TRACE_DEBUG2(m,p1,p2) -#define XML_TRACE_DEBUG3(m,p1,p2,p3) -#define XML_TRACE_DEBUG4(m,p1,p2,p3,p4) -#define XML_TRACE_DEBUG5(m,p1,p2,p3,p4,p5) -#define XML_TRACE_DEBUG6(m,p1,p2,p3,p4,p5,p6) -#endif - -#define XML_PERM_LEN_MAX 4 - -/***************************************************************************** -** Constants -*****************************************************************************/ - -const UINT8 xml_evt_rpt_elem[] = "MAP-event-report"; -const UINT8 xml_evt_rpt_event_elem[] = "event"; -const UINT8 xml_evt_rpt_type_attr[] = "type"; -const UINT8 xml_evt_rpt_handle_attr[] = "handle"; -const UINT8 xml_evt_rpt_folder_attr[] = "folder"; -const UINT8 xml_evt_rpt_old_folder_attr[] = "old_folder"; -const UINT8 xml_evt_rpt_msg_type_attr[] = "msg_type"; -const UINT8 xml_evt_rpt_version_attr[] = "version"; -const UINT8 xml_evt_rpt_unknown[] = "unknown"; - -#define XML_EVT_RPT_ELEM_ID 0x01 -#define XML_EVT_RPT_EVT_ELEM_ID 0x02 -#define XML_EVT_RPT_MAX_OBJ_TAG_ID XML_EVT_RPT_ELEM_ID -#define XML_EVT_RPT_TYPE_ATTR_ID 0x03 -#define XML_EVT_RPT_HANDLE_ATTR_ID 0x04 -#define XML_EVT_RPT_FOLDER_ATTR_ID 0x05 -#define XML_EVT_RPT_OLD_FOLDER_ATTR_ID 0x06 -#define XML_EVT_RPT_MSG_TYPE_ATTR_ID 0x07 -#define XML_EVT_RPT_VERSION_ATTR_ID 0x08 -#define XML_EVT_RPT_UNKNOWN_ID 0x09 -#define XML_EVT_RPT_MAX_ID 0x0a /* keep in sync with above */ -#define XML_EVT_RPT_TAG_END_ID 0x0b /* closing tag found end=true */ -#define XML_EVT_RPT_PAUSE_ID 0x0c /* closing tag found end=false */ - - -#define XML_EVT_RPT_TTBL_SIZE (XML_EVT_RPT_MAX_ID+1) - -/***************************************************************************** -** Type Definitions -*****************************************************************************/ - -typedef struct -{ - const UINT8 *p_name; - UINT8 len; -} tXML_EVT_RPT_TTBL_ELEM; - -typedef tXML_EVT_RPT_TTBL_ELEM tXML_EVT_RPT_TTBL[]; /* Tag Table */ - - -static const tXML_EVT_RPT_TTBL_ELEM xml_erp_ttbl[XML_EVT_RPT_TTBL_SIZE] = -{ /* index (EVT_RPT_XP_*_ID) & name */ - {(UINT8*) "", XML_EVT_RPT_MAX_ID-1}, /* \x00 Number of elements in array */ - /* XML EVT_RPT element (TAG) name */ - {xml_evt_rpt_elem, 16}, /* x01 MAP-event-report */ - {xml_evt_rpt_event_elem, 5}, /* 0x02 event */ - {xml_evt_rpt_type_attr, 4}, /* x03 type */ - {xml_evt_rpt_handle_attr, 6}, /* x04 handle */ - {xml_evt_rpt_folder_attr, 6}, /* x05 folder */ - {xml_evt_rpt_old_folder_attr, 10}, /* x06 old_folder */ - {xml_evt_rpt_msg_type_attr, 8}, /* x07 msg_type */ - {xml_evt_rpt_version_attr, 7}, /* x08 version */ - {xml_evt_rpt_unknown, 7} /* x09 unknown */ -}; - -#define XML_MAP_EVT_RPT_PTBL_SIZE 0x03 -typedef UINT8 * tXML_MAP_EVT_RPT_PTBL_ELEM; - -static const tXML_MAP_EVT_RPT_PTBL_ELEM xml_erp_ptbl[XML_MAP_EVT_RPT_PTBL_SIZE] = -{ - (UINT8 *) "\x01", /* index x00, all valide attributes in above list */ - (UINT8 *) "\x08\x02", /* x01 attributes and sub-tags supported */ - (UINT8 *) "\x03\x04\x05\x06\x07" /* x02: event report attributes */ -}; - - -#if (EVT_RPT_DEBUG_XML == TRUE) -void xml_erp_debug_str(tXML_STR *p_str, UINT8 *p_buf) -{ - int dbg_len; - if ( (p_str == NULL) || (NULL==p_str->p)) - BCM_STRNCPY_S( (char *)p_buf, EVT_RPT_DEBUG_LEN, "(NULL)", EVT_RPT_DEBUG_LEN-1 ); - else - { - dbg_len = p_str->len; - if ( dbg_len >= EVT_RPT_DEBUG_LEN) - dbg_len = EVT_RPT_DEBUG_LEN - 1; - BCM_STRNCPY_S( (char *)p_buf, EVT_RPT_DEBUG_LEN, (char *)p_str->p, dbg_len); - p_buf[dbg_len] = 0; - } -} - -#else -#define xml_erp_debug_str(p_str, p_buf) -#endif - -/***************************************************************************** - ** Function xml_erp_proc_tag - ** Description - ** Parameters - - ** Returns - *****************************************************************************/ -static UINT8 xml_erp_proc_tag( tXML_EVT_RPT_STATE *p_st, tXML_STR *p_name, tXML_STACK *p_stk) -{ - const UINT8 *p_stag; /* sub tag pointer */ - UINT8 curr = p_stk->stack[p_stk->top]; -#if (defined(EVT_RPT_DEBUG_XML) && EVT_RPT_DEBUG_XML == TRUE) - UINT8 dbg_name[EVT_RPT_DEBUG_LEN]; -#endif - - - if (curr < XML_MAP_EVT_RPT_PTBL_SIZE) - { - /* Iterate over allowed sub-tags for the current tag. */ - for (p_stag = xml_erp_ptbl[curr]; p_stag && *p_stag ; p_stag++) - { - if (*p_stag >= XML_EVT_RPT_TTBL_SIZE) - continue; - if (p_name->len == xml_erp_ttbl[*p_stag].len && - strncmp((char *)p_name->p, (char *)xml_erp_ttbl[*p_stag].p_name, p_name->len) == 0) - { - p_stk->top++; - p_stk->stack[p_stk->top] = *p_stag; - - return *p_stag; - } - } - } - -#if (defined(EVT_RPT_DEBUG_XML) && EVT_RPT_DEBUG_XML == TRUE) - xml_erp_debug_str(p_name, dbg_name); - XML_TRACE_DEBUG1("xml_erp_proc_tag: bad name:%s", dbg_name ); -#endif - - return XML_EVT_RPT_UNKNOWN_ID; -} - - -/***************************************************************************** - ** Function xml_erp_proc_attr - ** Description - ** Parameters - - ** Returns - *****************************************************************************/ -static UINT8 xml_erp_proc_attr(tXML_EVT_RPT_STATE *p_st, tXML_STR *p_name, tXML_STACK *p_stk) -{ - const UINT8 *p_stag; /* sub tag pointer */ - UINT8 curr = p_stk->stack[p_stk->top]; -#if (EVT_RPT_DEBUG_XML == TRUE) - UINT8 dbg_name[EVT_RPT_DEBUG_LEN]; -#endif - if (curr < XML_MAP_EVT_RPT_PTBL_SIZE) - { - /* Iterate over allowed sub-tags for the current tag. */ - for (p_stag = xml_erp_ptbl[curr]; p_stag && *p_stag; p_stag++) - { - if (*p_stag >= XML_EVT_RPT_TTBL_SIZE) - continue; - if (p_name->len == xml_erp_ttbl[*p_stag].len && - strncmp((char *)p_name->p, (char *)xml_erp_ttbl[*p_stag].p_name, p_name->len) == 0) - { - p_stk->top++; - p_stk->stack[p_stk->top] = *p_stag; - - return *p_stag; - } - } - } - -#if (defined(EVT_RPT_DEBUG_XML) && EVT_RPT_DEBUG_XML == TRUE) - xml_erp_debug_str(p_name, dbg_name); - XML_TRACE_DEBUG1("xml_erp_proc_attr: bad name:%s", dbg_name); -#endif - return XML_EVT_RPT_UNKNOWN_ID; -} - -/***************************************************************************** - ** Function xml_erp_find_ch_n_copy - ** Description copy any chacter till one char in p_str. Any char in p_str - ** will stop copy pointed by p_begin - ** Parameters - ** Returns - *****************************************************************************/ -static void xml_erp_find_ch_n_copy( tXML_MCOPY *p_copy ) -{ - const UINT8 *p_tmp; - const UINT8 *p_str = (UINT8 *)">"; /* was: ":=/> \t\n\r". i think we should copy till - closing flag */ - unsigned int last = XML_EVT_RPT_CARRY_OVER_LEN; /* maximum carry over len we can support */ - UINT8 *p_last = p_copy->last.p + p_copy->last.len - 1; /* point to the last char of carry - over buffer */ - BOOLEAN found = FALSE; - /* check if the last char in p_last is in p_str */ - for (p_tmp = p_str; *p_tmp; p_tmp++) - { - if (*p_last == *p_tmp) - { - found = TRUE; - break; - } - } /* for */ - - if (found == FALSE) - { - /* if not in p_str, move chars from p_begin to p_last - * until reached last_len or any char in p_str */ - p_last++; - last -= p_copy->last.len; /* calculate the maximum number of chars we can copy */ - while (*(p_copy->p_begin) && last) /* rl: not sure that this buffer is termninated by a 0 */ - { - /* copy from source (new buffer) to carry over. adjust only carry over ptr. */ - *p_last++ = *p_copy->p_begin; - last--; - for (p_tmp = p_str; *p_tmp; p_tmp++) - { - if (*p_copy->p_begin == *p_tmp) - { - p_copy->p_begin++; /* adjust pointer to point to next char to read */ - /* calculate new length of carry over buffer contents */ - p_copy->last.len = XML_EVT_RPT_CARRY_OVER_LEN-last; - *p_last = 0; /* NULL terminate p_last. rl: not really neccessary. */ - return; - } - } /* for */ - p_copy->p_begin++; /* update now to next char. this way abort char is also copied */ - } /* while */ - } /* !found */ -} - -/***************************************************************************** -** Function xml_evt_rpt_cback -** Description -** -** Parameters -** Returns -*****************************************************************************/ -static BOOLEAN xml_evt_rpt_cback( tXML_EVENT event, void *p_event_data, void *p_usr_data) -{ - tXML_MEVT_DATA *p_ed = (tXML_MEVT_DATA*) p_event_data; - tXML_EVT_RPT_STATE *p_st = (tXML_EVT_RPT_STATE *) p_usr_data; - tXML_PROP *p_cp = &p_st->p_prop[p_st->prop_index]; - BOOLEAN ret = TRUE; - UINT8 next; /* next element */ - UINT8 curr = p_ed->stack.stack[p_ed->stack.top]; /* current element */ -#if (EVT_RPT_DEBUG_XML == TRUE) - UINT8 dbg_name[EVT_RPT_DEBUG_LEN]; - UINT8 dbg_prefix[EVT_RPT_DEBUG_LEN]; - UINT8 dbg_value[EVT_RPT_DEBUG_LEN]; -#endif - -#if (EVT_RPT_DEBUG_XML == TRUE) - XML_TRACE_DEBUG1("xml_evt_rpt_cback:%d", event); -#endif - - switch (event) - { - case XML_TAG : /* <tag-name */ - next = xml_erp_proc_tag(p_st, &p_ed->tag.name, &p_ed->stack); -#if (EVT_RPT_DEBUG_XML == TRUE) - xml_erp_debug_str(&p_ed->tag.name, dbg_name); - xml_erp_debug_str(&p_ed->tag.prefix, dbg_prefix); - XML_TRACE_DEBUG2("XML_TAG: p:%s, name:%s", dbg_prefix, dbg_name); - XML_TRACE_DEBUG2("top:x%x, stk:x%x", p_ed->stack.top, p_ed->stack.stack[p_ed->stack.top]); - -#endif - if (next != 0) - { - if (next <= XML_EVT_RPT_MAX_OBJ_TAG_ID) - p_st->obj = next; - - if (p_st->prop_index <p_st->max_num_prop) - { - /* we do not use prefix in FTC */ - p_cp->name = next; - p_cp->p_data = NULL; - p_cp->len = 0; - p_cp->level = p_ed->stack.top; - p_st->prop_index++; - } - else - ret = FALSE; - } - break; - - case XML_ATTRIBUTE : /* attr-name="attr-value" */ - curr = xml_erp_proc_attr(p_st, &p_ed->attr.name, &p_ed->stack); -#if (defined(EVT_RPT_DEBUG_XML) && EVT_RPT_DEBUG_XML == TRUE) - xml_erp_debug_str(&p_ed->attr.name, dbg_name); - xml_erp_debug_str(&p_ed->attr.prefix, dbg_prefix); - xml_erp_debug_str(&p_ed->attr.value, dbg_value); - XML_TRACE_DEBUG4("[xml evt_rpt] XML_ATTRIBUTE: p:%s, name:%s, v:%s, curr:%x", - dbg_prefix, dbg_name, dbg_value, curr ); - XML_TRACE_DEBUG2("top 1:x%x, stk:x%x", p_ed->stack.top, p_ed->stack.stack[p_ed->stack.top]); -#endif - if ((curr != 0) && (curr != XML_EVT_RPT_UNKNOWN_ID)) - { - if (p_st->prop_index <p_st->max_num_prop) - { - p_cp->name = curr; - p_cp->p_data = p_ed->attr.value.p; - p_cp->len = p_ed->attr.value.len; - p_cp->level = p_ed->stack.top; - p_st->prop_index++; - } - else - ret = FALSE; - p_ed->stack.top--; - XML_TRACE_DEBUG2("top 2:x%x, stk:x%x", p_ed->stack.top, p_ed->stack.stack[p_ed->stack.top]); - } - break; - - case XML_CHARDATA : -#if (defined(EVT_RPT_DEBUG_XML) && EVT_RPT_DEBUG_XML == TRUE) - xml_erp_debug_str(&p_ed->ch_data.value, dbg_value); - XML_TRACE_DEBUG2("XML_CHARDATA: v:%s, last:%d", dbg_value, p_ed->ch_data.last); -#endif - break; - - case XML_ETAG : /* </tag-name> */ - if (p_ed->stack.top > 0) - { - p_ed->stack.stack[p_ed->stack.top] = 0; - p_ed->stack.top--; - p_st->ended = (BOOLEAN) (p_ed->stack.top == 0); - } -#if (defined(EVT_RPT_DEBUG_XML) && EVT_RPT_DEBUG_XML == TRUE) - xml_erp_debug_str(&p_ed->etag.name, dbg_name); - xml_erp_debug_str(&p_ed->etag.prefix, dbg_prefix); - XML_TRACE_DEBUG2("[xml evt_rpt] XML_ETAG: p:%s, name:%s", dbg_prefix, dbg_name); - XML_TRACE_DEBUG2("[xml evt_rpt] top:x%x, stk:x%x", p_ed->stack.top, p_ed->stack.stack[p_ed->stack.top]); -#endif - break; - - case XML_TAG_END: /* /> */ - curr = p_ed->stack.stack[p_ed->stack.top]; - - if (p_st->prop_index <p_st->max_num_prop) - { - if (p_ed->empty_elem.end) - p_cp->name = XML_EVT_RPT_TAG_END_ID; - else - p_cp->name = XML_EVT_RPT_PAUSE_ID; - p_cp->p_data = NULL; - p_cp->len = 0; - p_cp->level = p_ed->stack.top; - p_st->prop_index++; - if (p_ed->empty_elem.end && p_ed->stack.top > 0) - { - p_ed->stack.top--; - } - } - else - ret = FALSE; - -#if (defined(EVT_RPT_DEBUG_XML) && EVT_RPT_DEBUG_XML == TRUE) - XML_TRACE_DEBUG4("[xml evt_rpt] XML_TAG_END: %d, top:x%x, stk:x%x, curr:x%x", - p_ed->empty_elem.end, p_ed->stack.top, p_ed->stack.stack[p_ed->stack.top], curr); -#endif - break; - - case XML_PARTIAL: - if (p_st->p_prop[p_st->prop_index-1].name != XML_EVT_RPT_TAG_END_ID) - { - p_ed->stack.top--; -#if (defined(EVT_RPT_DEBUG_XML) && EVT_RPT_DEBUG_XML == TRUE) - XML_TRACE_DEBUG0("[xml evt_rpt] adjust due to XML_PARTIAL"); -#endif - } - break; - - case XML_COPY: - xml_erp_find_ch_n_copy( &p_ed->copy ); - XML_TRACE_DEBUG1("[xml evt_rpt] XML_COPY: %s", p_ed->copy.last.p); - break; - - default : -#if (defined(EVT_RPT_DEBUG_XML) && EVT_RPT_DEBUG_XML == TRUE) - XML_TRACE_DEBUG1("[xml evt_rpt] default: XML event: %d", event); -#endif - break; - } - - return ret; -} - - - - -/********************************************************************************** -** Function xml_erp_int_fill_file_folder -** Description fill in file/folder structure. -** -** Parameters -** Returns xx: > 0 : number of properties scanned, folder entry is added -** = 0 : no end tag found, carry over to next parse -** = -1: no dst_resource avaibale, all prop left to next parse -** = -2: exceed max entry, no folder entry added -**********************************************************************************/ -static INT16 xml_erp_int_fill_evt_rpt( tXML_EVT_RPT_STATE * p_xud, - tXML_PROP *p_prop, - UINT16 *num_prop, - UINT8 **p_dst_data, - UINT16 *dst_len) -{ - INT16 xx; - UINT16 len; - BOOLEAN end = FALSE; - tXML_PROP *cur_prop = p_prop; - UINT8 *p_cur_offset = *p_dst_data; - BOOLEAN copy_attr_info; - BOOLEAN no_buf_left; - UINT8 **p_attr_data = NULL; - UINT16 *p_attr_len = NULL; - - if ( p_xud->current_entry >= p_xud->max_entry ) - return -2; - - for (xx=0; (xx < *num_prop) && !end; xx++, cur_prop++) - { -#if (defined(EVT_RPT_DEBUG_XML) && EVT_RPT_DEBUG_XML == TRUE) - /* XML_TRACE_DEBUG5( "[xml evt_rpt] fill: num_prop:%d, name id: x%x, p_prop: x%x, len: %d p_data:%s", - (*num_prop-xx) , cur_prop->name, cur_prop, cur_prop->len, cur_prop->p_data, ); */ -#endif - copy_attr_info = TRUE; - no_buf_left = FALSE; - len = cur_prop->len; - - switch (cur_prop->name) - { - case XML_EVT_RPT_TYPE_ATTR_ID: - if ((*dst_len - len) > 0) /* enough data buffer available? */ - { - p_attr_data = &(p_xud->p_entry[p_xud->current_entry].type) ; - p_attr_len = &(p_xud->p_entry[p_xud->current_entry].type_len); - } - else /* run out of dst buffer resource */ - no_buf_left = TRUE; - break; - - case XML_EVT_RPT_HANDLE_ATTR_ID: - if ((*dst_len - len) > 0) /* enough data buffer available? */ - { - p_attr_data = &(p_xud->p_entry[p_xud->current_entry].handle) ; - p_attr_len = &(p_xud->p_entry[p_xud->current_entry].handle_len); - } - else /* run out of dst buffer resource */ - no_buf_left = TRUE; - break; - case XML_EVT_RPT_FOLDER_ATTR_ID: - if ((*dst_len - len) > 0) /* enough data buffer available? */ - { - p_attr_data = &(p_xud->p_entry[p_xud->current_entry].folder) ; - p_attr_len = &(p_xud->p_entry[p_xud->current_entry].folder_len); - } - else /* run out of dst buffer resource */ - no_buf_left = TRUE; - break; - case XML_EVT_RPT_OLD_FOLDER_ATTR_ID: - if ((*dst_len - len) > 0) /* enough data buffer available? */ - { - p_attr_data = &(p_xud->p_entry[p_xud->current_entry].old_folder) ; - p_attr_len = &(p_xud->p_entry[p_xud->current_entry].old_folder_len); - } - else /* run out of dst buffer resource */ - no_buf_left = TRUE; - break; - case XML_EVT_RPT_MSG_TYPE_ATTR_ID: - if ((*dst_len - len) > 0) /* enough data buffer available? */ - { - - p_attr_data = &(p_xud->p_entry[p_xud->current_entry].msg_type) ; - p_attr_len = &(p_xud->p_entry[p_xud->current_entry].msg_type_len); - } - else /* run out of dst buffer resource */ - no_buf_left = TRUE; - break; - case XML_EVT_RPT_TAG_END_ID: - /* -------------------- CUSTOMER SPECIFIC ---------------------- */ - p_xud->current_entry++; /* increment only when end tag (/>) found */ - copy_attr_info = FALSE; - XML_TRACE_DEBUG1("[xml ml]: current_entry=%d",p_xud->current_entry); - break; - /* case XML_VERSION_ATTR_ID: */ - default: - copy_attr_info = FALSE; - XML_TRACE_DEBUG1("[xml evt_rpt] unknown attrib: %d", cur_prop->name ); - break; - } - - if (copy_attr_info && p_attr_data && p_attr_len) - { - *p_attr_data = p_cur_offset; - *p_attr_len = len; - - memcpy( (void *)*p_attr_data, - (const void *)cur_prop->p_data, - len ); - (*p_attr_data)[len] = 0; /* null terminate string */ - p_cur_offset += (len + 1); - *dst_len = *dst_len - (len + 1) ; - - #if (defined(EVT_RPT_DEBUG_XML) && EVT_RPT_DEBUG_XML == TRUE) - - XML_TRACE_DEBUG5("[xml evt_rpt]: Attr ID=%d val=[%s] len=%d level=%d dst_len lef=%d", - cur_prop->name, - *p_attr_data, - *p_attr_len, - cur_prop->level, - *dst_len); - #endif - } - - if (no_buf_left) - { - return -1; - } - - } -#if (EVT_RPT_DEBUG_XML == TRUE) - XML_TRACE_DEBUG2("[xml evt_rpt] fill_evt_rpt: end:%d, xx:%d", end, xx); -#endif -#if 0 - /* if end tag not found -> split over two buffers. but parser will still show rest of - found properties. so return still found properties. */ - if (end == FALSE) - xx = 0; -#endif - - /* keep track of current data buffer offset */ - *p_dst_data = p_cur_offset; - return xx; -} /* xml_erp_int_fill_file_evt_rpt() */ - - -/********************************************************************************** -** Function xml_erp_int_fill_evt_data -** -** Description fill in MAP event report structure. -** -** Parameters -** Returns -**********************************************************************************/ -static tXML_EVT_RPT_RES xml_erp_int_fill_evt_data( UINT8 op, - void *p_evt_data, - tXML_PROP **p_prop, - UINT16 *num_prop, - UINT8 **p_dst_data, - UINT16 *dst_len) -{ - tXML_EVT_RPT_STATE *p_xud = (tXML_EVT_RPT_STATE *)p_evt_data; - INT16 inc_prop; - UINT8 prop_name; /* Property name. */ - tXML_PROP *cur_prop = *p_prop; - UINT8 *p_cur_offset = *p_dst_data; - - tXML_EVT_RPT_RES x_res = XML_EVT_RPT_OK; - BOOLEAN x_no_res = FALSE; /* guard dest buffer resource */ - - if ( op == 0 || op > XML_EVT_RPT_MAX_OBJ_TAG_ID || *num_prop == 0) - return XML_EVT_RPT_ERROR; - -#if EVT_RPT_DEBUG_XML - XML_TRACE_DEBUG2( "[xml evt_rpt] xml_erp_int_fill_evt_data op:%d, num_prop:%d", - op, *num_prop); -#endif - - - - while ( *num_prop > 0 && !x_no_res ) - { -#if (defined(EVT_RPT_DEBUG_XML) && EVT_RPT_DEBUG_XML == TRUE) - XML_TRACE_DEBUG2("end_prop:%d, name id: x%x", *num_prop, cur_prop->name); -#endif - prop_name = cur_prop->name; - cur_prop++; - *num_prop -= 1; - - - switch ( prop_name ) - { - case XML_EVT_RPT_ELEM_ID: - XML_TRACE_DEBUG0("[xml evt_rpt] xml_etag_elem"); - /* skip over version attribute which should always be 1.0. this is the top level */ - break; - - case XML_EVT_RPT_EVT_ELEM_ID: - XML_TRACE_DEBUG0("[xml evt_rpt] xml_etag_elem"); - inc_prop = xml_erp_int_fill_evt_rpt( p_xud, - cur_prop, - num_prop, - &p_cur_offset, - dst_len); - if (inc_prop == -1) /* no dst_buf available */ - { - /* backup one more prop to obtain the skipped evt_rpt/file entry header */ - cur_prop --; - *num_prop += 1; - - x_res = XML_EVT_RPT_DST_NO_RES; - x_no_res = TRUE; - } - else if (inc_prop == -2) /* exceed max entry */ - { - x_no_res = TRUE; - x_res = XML_EVT_RPT_OUT_FULL; - } - else /* found evt_rpt entry */ - { - cur_prop += inc_prop; - *num_prop -= inc_prop; - } - break; - - case XML_EVT_RPT_PAUSE_ID: - XML_TRACE_DEBUG0("[xml evt_rpt] xml_etag_elem"); - -#if (EVT_RPT_DEBUG_XML==TRUE) - XML_TRACE_DEBUG0( "[xml evt_rpt] xml_erp_int_fill_evt_data(): XML_EVT_RPT_PAUSE_ID" ); -#endif - break; - - case XML_EVT_RPT_TAG_END_ID: - XML_TRACE_DEBUG0("[xml evt_rpt] xml_etag_elem"); -#if (EVT_RPT_DEBUG_XML==TRUE) - XML_TRACE_DEBUG0( "[xml evt_rpt] xml_erp_int_fill_evt_data(): XML_EVT_RPT_TAG_END_ID" ); -#endif - break; - - default: - XML_TRACE_DEBUG1( "[xml evt_rpt] xml_erp_int_fill_evt_data():unknown element: %d", prop_name ); - break; - } - } - - /* keep track of current filling position, and current available dst buffer */ - *p_prop = cur_prop; - *p_dst_data = p_cur_offset; - - return x_res; -} /* xml_erp_int_fill_evt_data() */ - - -/************************************************************************************** -** Function XML_EvtRptInit -** -** Description Initialize xml parser state machine. -** -** Parameters p_xml_state: address of an xml parser state machine to be initialized, -** allocate an additional space of size XML_EVT_RPT_CARRY_OVER_LEN -** right after *p_xml_state to hold carry over data. -** p_entry : points start of output directory entry. caller needs do -** free this memory -** max_entry : max is 16 bit integer value which is the maximum number -** of evt_rpt entries. - -** -** Returns void -**************************************************************************************/ - -void XML_EvtRptInit( tXML_EVT_RPT_PARSER *p_xml_state, - tXML_EVT_RPT_ENTRY *p_entry, - const UINT16 max_entry ) -{ - XML_TRACE_DEBUG0("[xml evt_rpt] XML_EvtRptInit"); - /* Initialize the generic xml parser state machine.*/ - XML_InitPars( &p_xml_state->xml, xml_evt_rpt_cback, &p_xml_state->xml_user_data ); - - /* User need to allocate an additional space of size XML_EVT_RPT_CARRY_OVER_LEN */ - /* right after *p_xml_state to hold carry over data. */ - /* point to the end of the allocated buffer for p_xml_state, which is the */ - /* beginning of buffer(XML_EVT_RPT_CARRY_OVER_LEN) */ - p_xml_state->xml.last_bfr.p = (UINT8 *)(p_xml_state + 1); - p_xml_state->xml.last_bfr.len = XML_EVT_RPT_CARRY_OVER_LEN; - - /* Initialize user data */ - p_xml_state->xml_user_data.p_entry = p_entry; - p_xml_state->xml_user_data.current_entry = 0; - p_xml_state->xml_user_data.max_name_len = XML_UI_ENTRY_MAX_NAME_LEN + 1; - p_xml_state->xml_user_data.max_entry = (UINT16)max_entry; - p_xml_state->xml_user_data.prop_num = 0; -} - - -/************************************************************************************** -** Function XML_EvtRptParse -** -** Description This function is called to parse the xml data received from OBEX -** into folder entries associated with properties value. It can also be -** used as clean up function to delete left over data from previous parse. -** This clean up function is typically used when application runs out of -** resource and decides to discard extra xml data received. -** -** Parameters p_xml_state: pointer to a xml parser initialized by XML_EvtRptInit(). -** xml_data: valid pointer to OBEX list data in xml format. -** xml_len: length of the package, must be non-zero value. -** dst_data: valid pointer to the buffer for holding converted folder entry name. - When dst_data is NULL, clean up all remaining data in the parser. -** dst_len: pointer to the length of dst_data buffer, its carry out value -** is the number of bytes remaining buffer.When dst_len is NULL, -** it will cause to flush the internal data in the parser. -** num_entries: current number of entries, in the end it is the total number of entries -** -** Returns tXML_EVT_RPT_RES (see xml_erp.h) -** XML_PENDING: parsing not completed -** XML_END_LIST: found /folder-listing but no final flag detected -** XML_EVT_RPT_OUT_FULL: reached max_entry -> do not call parser anymore!!! dump data -** XML_EVT_RPT_DST_NO_RES : run out of dst buffer resource while -** some xml data still remains. - -**************************************************************************************/ -tXML_EVT_RPT_RES XML_EvtRptParse( tXML_EVT_RPT_PARSER *p_xml_state, - UINT8 *xml_data, UINT16 xml_len, - UINT8 *dst_data, UINT16 *dst_len, - UINT16 *num_entries ) -{ - tXML_OS xos; - BOOLEAN is_remain = TRUE; - tXML_MUL_STATE *p_xml = &p_xml_state->xml; - tXML_EVT_RPT_STATE *p_st = &p_xml_state->xml_user_data; - tXML_EVT_RPT_RES x_res = XML_EVT_RPT_OK; - tXML_RESULT res = XML_NO_PROP; - UINT16 max_num_prop = GKI_BUF3_SIZE/sizeof(tXML_PROP); /* i hope this is sufficient for 1 */ - - -#if (defined(EVT_RPT_DEBUG_XML) && EVT_RPT_DEBUG_XML == TRUE) - int xx; - UINT8 dbg_buf[EVT_RPT_DEBUG_LEN]; - tXML_STR str; -#endif - - XML_TRACE_DEBUG0("[xml evt_rpt] XML_EvtRptParse"); - /* if dst_data is NULL, clean up remaining data */ - if (!dst_data || !dst_len) - { - /* clean out remained xml data left over from last parse */ - if (p_xml_state->xml_user_data.p_prop ) - { - GKI_freebuf( p_st->p_prop ); - p_st->p_prop = p_st->offset_prop = NULL; - p_st->prop_num = 0; - } -#if (EVT_RPT_DEBUG_XML == TRUE) - XML_TRACE_DEBUG0( "[xml evt_rpt] XML_EvtRptParse() Clean up left over!"); -#endif - return x_res; - } - - /* if illegal OBEX data or dst buffer pointer received, return ERROR */ - if (xml_len == 0 || !xml_data) - { - return XML_EVT_RPT_ERROR; - } - - /* XML_EvtRptParse receive new xml data, allocate buffer to hold parsed prop */ - if (p_st->offset_prop == NULL) - { - -#if (EVT_RPT_DEBUG_XML == TRUE) - XML_TRACE_DEBUG0( "[xml evt_rpt] XML_EvtRptParse() Receive New Data!"); - XML_TRACE_DEBUG2( "[xml evt_rpt] XML_data start[%x] end [%x]",xml_data, xml_data+xml_len); -#endif - is_remain = FALSE; - if ( NULL!= (p_st->p_prop = (tXML_PROP *)GKI_getbuf( GKI_BUF3_SIZE ) ) ) - { - /* pointing next prop to be converted into file entry */ - p_st->prop_num = 0; - } - else - { - GKI_freebuf( p_xml_state ); - x_res = XML_EVT_RPT_NO_RES; - return x_res; - } - } -#if (EVT_RPT_DEBUG_XML == TRUE) - else - { - XML_TRACE_DEBUG0( "[xml evt_rpt] XML_EvtRptParse(): Keep cleaning up old xml data !"); - } -#endif - /* update the data address */ - xos.p_begin = xml_data; - xos.p_end = xml_data + xml_len; - - while ( res == XML_NO_PROP ) - { - /* if no remaining data in p_st->p_prop, parse new xml data */ - if (!is_remain) - { - p_st->max_num_prop = max_num_prop; - p_st->prop_index = 0; - res = XML_MulParse( p_xml, &xos ); - - -#if (EVT_RPT_DEBUG_XML == TRUE) - XML_TRACE_DEBUG4( "xml_evt_rpt_parse obj: %x, max: %d, num: %d, res: %d", - p_st->obj, max_num_prop, p_st->prop_index, res); - - if (res != 0) - { - XML_TRACE_DEBUG1( "XML_MulParse Parsing: %d !!!", res); - } - - for (xx=0; xx<p_st->prop_index; xx++) - { - if ( p_st->p_prop[xx].name < XML_EVT_RPT_MAX_ID ) - { - str.p = p_st->p_prop[xx].p_data; - str.len = p_st->p_prop[xx].len; - xml_erp_debug_str(&str, dbg_buf); - XML_TRACE_DEBUG5( "[xml evt_rpt] parsed: index[%d]:%d:%s: %s(%d)", p_st->prop_index-xx, p_st->p_prop[xx].level, - xml_erp_ttbl[p_st->p_prop[xx].name].p_name, dbg_buf, p_st->p_prop[xx].len); - } - else - { - XML_TRACE_DEBUG3( "[xml evt_rpt] internal prop: %d:%d:%d", xx, p_st->p_prop[xx].level, - p_st->p_prop[xx].name ); - } - } -#endif - p_st->prop_num = p_st->prop_index ; - p_st->offset_prop = p_st->p_prop; - } - else - { - /* This is left over data, pick up the result from the previous parse */ - res = p_xml->pars_res; - } - - if ( res != XML_OBJ_ST_EMPTY ) - { - x_res = xml_erp_int_fill_evt_data( p_st->obj, p_st, &p_st->offset_prop, &p_st->prop_num, &dst_data, dst_len ); - - if ( (XML_EVT_RPT_OK == x_res) && (XML_NO_END == res) ) - { - /* XML_NO_END means that the xml is not completly finished and fill returns - ok when when partial filling has been ok */ - x_res = XML_EVT_RPT_PENDING; - } - - /* all parsed xml data has been converted into file entry */ - /* or exceed max entry number , break the parsing loop */ - if (XML_EVT_RPT_OUT_FULL != x_res && XML_EVT_RPT_DST_NO_RES != x_res) - { - is_remain = FALSE; - } - else - break; - } - } /* while */ - - /* free property table. at next call a new one is allocated */ - if ((x_res != XML_EVT_RPT_DST_NO_RES && p_st->p_prop) || - XML_EVT_RPT_OUT_FULL == x_res) - { - GKI_freebuf( p_st->p_prop ); - p_st->p_prop = NULL; - p_st->offset_prop = NULL; - } - - if ( x_res != XML_EVT_RPT_DST_NO_RES && p_st->ended) - { - /* this should happen on the same time as final flag in fact */ - x_res = XML_EVT_RPT_END_LIST; /* found closing /evt_rpt-listing */ - } - - - *num_entries = p_st->current_entry; /* report number of entries found. only when ended is true - application really should be interested! */ - return x_res; -} - diff --git a/stack/xml/xml_flp.c b/stack/xml/xml_flp.c deleted file mode 100644 index 688f1b5..0000000 --- a/stack/xml/xml_flp.c +++ /dev/null @@ -1,971 +0,0 @@ -/****************************************************************************** - ** - ** Name: xml_flp.c - ** - ** Description: This module contains xml parser of obex folder listing - ** - ** Copyright (c) 2004-2011, Broadcom Corporation, All Rights Reserved. - ** Broadcom Bluetooth Core. Proprietary and confidential. - ******************************************************************************/ - -#include "bt_target.h" -#include "gki.h" -#include "xml_flp_api.h" - -#include <string.h> -#include <stdlib.h> - -#ifndef FOLDER_DEBUG_XML -#define FOLDER_DEBUG_XML FALSE -#endif -#define FOLDER_DEBUG_LEN 50 -#if (defined(FOLDER_DEBUG_XML) && FOLDER_DEBUG_XML == TRUE) -#define XML_TRACE_DEBUG0(m) {BT_TRACE_0(TRACE_LAYER_FTP, TRACE_TYPE_DEBUG, m);} -#define XML_TRACE_DEBUG1(m,p1) {BT_TRACE_1(TRACE_LAYER_FTP, TRACE_TYPE_DEBUG, m,p1);} -#define XML_TRACE_DEBUG2(m,p1,p2) {BT_TRACE_2(TRACE_LAYER_FTP, TRACE_TYPE_DEBUG, m,p1,p2);} -#define XML_TRACE_DEBUG3(m,p1,p2,p3) {BT_TRACE_3(TRACE_LAYER_FTP, TRACE_TYPE_DEBUG, m,p1,p2,p3);} -#define XML_TRACE_DEBUG4(m,p1,p2,p3,p4) {BT_TRACE_4(TRACE_LAYER_FTP, TRACE_TYPE_DEBUG, m,p1,p2,p3,p4);} -#define XML_TRACE_DEBUG5(m,p1,p2,p3,p4,p5) {BT_TRACE_5(TRACE_LAYER_FTP, TRACE_TYPE_DEBUG, m,p1,p2,p3,p4,p5);} -#define XML_TRACE_DEBUG6(m,p1,p2,p3,p4,p5,p6) {BT_TRACE_6(TRACE_LAYER_FTP, TRACE_TYPE_DEBUG, m,p1,p2,p3,p4,p5,p6);} -#else -#define XML_TRACE_DEBUG0(m) -#define XML_TRACE_DEBUG1(m,p1) -#define XML_TRACE_DEBUG2(m,p1,p2) -#define XML_TRACE_DEBUG3(m,p1,p2,p3) -#define XML_TRACE_DEBUG4(m,p1,p2,p3,p4) -#define XML_TRACE_DEBUG5(m,p1,p2,p3,p4,p5) -#define XML_TRACE_DEBUG6(m,p1,p2,p3,p4,p5,p6) -#endif - -#define XML_PERM_LEN_MAX 4 - -/***************************************************************************** -** Constants -*****************************************************************************/ - -const UINT8 xml_folder_listing_elem[] = "folder-listing"; -const UINT8 xml_file_elem[] = "file"; -const UINT8 xml_folder_elem[] = "folder"; -const UINT8 xml_parent_folder_elem[] = "parent-folder"; -const UINT8 xml_name_attr[] = "name"; -const UINT8 xml_size_attr[] = "size"; -const UINT8 xml_type_attr[] = "type"; -const UINT8 xml_modified_attr[] = "modified"; -const UINT8 xml_created_attr[] = "created"; -const UINT8 xml_accessed_attr[] = "accessed"; -const UINT8 xml_user_perm_attr[] = "user-perm"; -const UINT8 xml_group_perm_attr[] = "group-perm"; -const UINT8 xml_other_perm_attr[] = "other-perm"; -const UINT8 xml_group_attr[] = "group"; -const UINT8 xml_owner_attr[] = "owner"; -const UINT8 xml_version_attr[] = "version"; -const UINT8 xml_lang_attr[] = "xml:lang"; -const UINT8 xml_unknown[] = "unknown"; - -#define XML_FOLDER_LISTING_ELEM_ID 0x01 -#define XML_FILE_ELEM_ID 0x02 -#define XML_FOLDER_ELEM_ID 0x03 -#define XML_PARENT_FOLDER_ELEM_ID 0x04 -#define XML_MAX_OBJ_TAG_ID XML_FOLDER_LISTING_ELEM_ID -#define XML_NAME_ATTR_ID 0x05 -#define XML_SIZE_ATTR_ID 0x06 -#define XML_TYPE_ATTR_ID 0x07 -#define XML_MODIFIED_ATTR_ID 0x08 -#define XML_CREATED_ATTR_ID 0x09 -#define XML_ACCESSED_ATTR_ID 0x0a -#define XML_USER_PERM_ATTR_ID 0x0b -#define XML_GROUP_PERM_ATTR_ID 0x0c -#define XML_OTHER_PERM_ATTR_ID 0x0d -#define XML_GROUP_ATTR_ID 0x0e -#define XML_OWNER_ATTR_ID 0x0f -#define XML_VERSION_ATTR_ID 0x10 -#define XML_LANG_ATTR_ID 0x11 -#define XML_XP_UNKNOWN_ID 0x12 -#define XML_FOLDER_MAX_ID 0x13 /* keep in sync with above */ -#define XML_FOLDER_TAG_END_ID 0x13 /* closing tag found end=true */ -#define XML_FOLDER_PAUSE_ID 0x14 /* closing tag found end=false */ - - -#define XML_FOLDER_TTBL_SIZE (XML_FOLDER_MAX_ID+1) - -/***************************************************************************** -** Type Definitions -*****************************************************************************/ - -typedef struct -{ - const UINT8 *p_name; - UINT8 len; -} tXML_FOLDER_TTBL_ELEM; - -typedef tXML_FOLDER_TTBL_ELEM tXML_FOLDER_TTBL[]; /* Tag Table */ - - -static const tXML_FOLDER_TTBL_ELEM xml_flp_ttbl[XML_FOLDER_TTBL_SIZE] = -{ /* index (FOLDER_XP_*_ID) & name */ - {(UINT8*) "", XML_FOLDER_MAX_ID-1}, /* \x00 Number of elements in array */ - /* XML FOLDER element (TAG) name */ - {xml_folder_listing_elem, 14}, /* x01 folder-listing */ - {xml_file_elem, 4}, /* 0x02 file */ - {xml_folder_elem, 6}, /* x03 folder */ - {xml_parent_folder_elem, 13}, /* x04 parent-folder */ - {xml_name_attr, 4}, /* x05 name */ - {xml_size_attr, 4}, /* x06 size */ - {xml_type_attr, 4}, /* x07 type */ - {xml_modified_attr, 8}, /* x08 modified */ - {xml_created_attr, 7}, /* x09 created */ - {xml_accessed_attr, 8}, /* x0a accessed */ - {xml_user_perm_attr, 9}, /* x0b user-perm */ - {xml_group_perm_attr, 10}, /* x0c group-perm */ - {xml_other_perm_attr, 10}, /* x0d other-perm */ - {xml_group_attr, 5}, /* x0e group */ - {xml_owner_attr, 5}, /* x0f owner */ - {xml_version_attr, 7}, /* x10 version */ - {xml_lang_attr, 8}, /* x11 xml:lang */ - {xml_unknown, 7 } /* x12 unknown */ -}; - -#define XML_FOLDER_PTBL_SIZE 0x10 -typedef UINT8 * tXML_FOLDER_PTBL_ELEM; - -static const tXML_FOLDER_PTBL_ELEM xml_flp_ptbl[XML_FOLDER_PTBL_SIZE] = -{ - (UINT8 *) "\x01\x02\x03\x04", /* index x00, all valide attributes in above list */ - (UINT8 *) "\x10\x02\x03\x04", /* x01 attributes and sub-tags supported */ - (UINT8 *) "\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x11", /* x02: file attributes */ - (UINT8 *) "\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x11", /* x03: folder attributes */ - (UINT8 *) "" /* x04 parent folder has no attributes */ -}; - - -#if (FOLDER_DEBUG_XML == TRUE) -void xml_flp_debug_str(tXML_STR *p_str, UINT8 *p_buf) -{ - int dbg_len; - if ( (p_str == NULL) || (NULL==p_str->p)) - BCM_STRCPY_S( (char *)p_buf, FOLDER_DEBUG_LEN, "(NULL)" ); - else - { - dbg_len = p_str->len; - if ( dbg_len >= FOLDER_DEBUG_LEN) - dbg_len = FOLDER_DEBUG_LEN - 1; - BCM_STRNCPY_S( (char *)p_buf, FOLDER_DEBUG_LEN, (char *)p_str->p, dbg_len); - p_buf[dbg_len] = 0; - } -} - -#else -#define xml_flp_debug_str(p_str, p_buf) -#endif - -/***************************************************************************** - ** Function xml_flp_proc_tag - ** Description - ** Parameters - - ** Returns - *****************************************************************************/ -static UINT8 xml_flp_proc_tag( tXML_FOLDER_STATE *p_st, tXML_STR *p_name, tXML_STACK *p_stk) -{ - const UINT8 *p_stag; /* sub tag pointer */ - UINT8 curr = p_stk->stack[p_stk->top]; -#if (defined(FOLDER_DEBUG_XML) && FOLDER_DEBUG_XML == TRUE) - UINT8 dbg_name[FOLDER_DEBUG_LEN]; -#endif - - if (curr < XML_FOLDER_PTBL_SIZE) - { - /* Iterate over allowed sub-tags for the current tag. */ - for (p_stag = xml_flp_ptbl[curr]; p_stag && *p_stag ; p_stag++) - { - if (*p_stag >= XML_FOLDER_TTBL_SIZE) - continue; - if(p_name->len == xml_flp_ttbl[*p_stag].len && - strncmp((char *)p_name->p, (char *)xml_flp_ttbl[*p_stag].p_name, p_name->len) == 0) - { - p_stk->top++; - p_stk->stack[p_stk->top] = *p_stag; - - return *p_stag; - } - } - } - -#if (defined(FOLDER_DEBUG_XML) && FOLDER_DEBUG_XML == TRUE) - xml_flp_debug_str(p_name, dbg_name); - XML_TRACE_DEBUG1("xml_flp_proc_tag: bad name:%s", dbg_name ); -#endif - - p_stk->top++; - p_stk->stack[p_stk->top] = XML_XP_UNKNOWN_ID; - return XML_XP_UNKNOWN_ID; -} - - -/***************************************************************************** - ** Function xml_flp_proc_attr - ** Description - ** Parameters - - ** Returns - *****************************************************************************/ -static UINT8 xml_flp_proc_attr(tXML_FOLDER_STATE *p_st, tXML_STR *p_name, tXML_STACK *p_stk) -{ - const UINT8 *p_stag; /* sub tag pointer */ - UINT8 curr = p_stk->stack[p_stk->top]; -#if (FOLDER_DEBUG_XML == TRUE) - UINT8 dbg_name[FOLDER_DEBUG_LEN]; -#endif - - if (curr < XML_FOLDER_PTBL_SIZE) - { - /* Iterate over allowed sub-tags for the current tag. */ - for (p_stag = xml_flp_ptbl[curr]; p_stag && *p_stag; p_stag++) - { - if (*p_stag >= XML_FOLDER_TTBL_SIZE) - continue; - if(p_name->len == xml_flp_ttbl[*p_stag].len && - strncmp((char *)p_name->p, (char *)xml_flp_ttbl[*p_stag].p_name, p_name->len) == 0) - { - p_stk->top++; - p_stk->stack[p_stk->top] = *p_stag; - - return *p_stag; - } - } - } - -#if (defined(FOLDER_DEBUG_XML) && FOLDER_DEBUG_XML == TRUE) - xml_flp_debug_str(p_name, dbg_name); - XML_TRACE_DEBUG1("xml_flp_proc_attr: bad name:%s", dbg_name); -#endif - return XML_XP_UNKNOWN_ID; -} -/***************************************************************************** - ** Function xml_flp_get_perm - ** Description Translate permission character into XML_PERM_MASK - ** Returns XML_PERM_MASK: permission mask - *****************************************************************************/ -static XML_PERM_MASK xml_flp_get_perm(char *right, UINT16 len ) -{ - XML_PERM_MASK mask = 0; - UINT8 perm_str[XML_PERM_LEN_MAX] = {0}; - - memcpy(perm_str, right, XML_PERM_LEN_MAX); - perm_str[len] = '\0'; - - if (strchr((char *)perm_str, 'R')) - mask |= XML_PERM_READ_B; - if (strchr((char *)perm_str, 'W')) - mask |= XML_PERM_WRITE_B; - if (strchr((char *)perm_str, 'D')) - mask |= XML_PERM_DELETE_B; - -#if (FOLDER_DEBUG_XML == TRUE) - XML_TRACE_DEBUG2("xml_flp_get_perm [%s] -> %d",perm_str, mask); -#endif - return mask; -} - -/***************************************************************************** - ** Function xml_flp_find_ch_n_copy - ** Description copy any chacter till one char in p_str. Any char in p_str - ** will stop copy pointed by p_begin - ** Parameters - ** Returns - *****************************************************************************/ -static void xml_flp_find_ch_n_copy( tXML_MCOPY *p_copy ) -{ - const UINT8 *p_tmp; - const UINT8 *p_str = (UINT8 *)">"; /* was: ":=/> \t\n\r". i think we should copy till - closing flag */ - unsigned int last = XML_FOLDER_CARRY_OVER_LEN; /* maximum carry over len we can support */ - UINT8 *p_last = p_copy->last.p + p_copy->last.len - 1; /* point to the last char of carry - over buffer */ - BOOLEAN found = FALSE; - - /* check if the last char in p_last is in p_str */ - for (p_tmp = p_str; *p_tmp; p_tmp++) - { - if (*p_last == *p_tmp) - { - found = TRUE; - break; - } - } /* for */ - - if (found == FALSE) - { - /* if not in p_str, move chars from p_begin to p_last - * until reached last_len or any char in p_str */ - p_last++; - last -= p_copy->last.len; /* calculate the maximum number of chars we can copy */ - while (*(p_copy->p_begin) && last) /* rl: not sure that this buffer is termninated by a 0 */ - { - /* copy from source (new buffer) to carry over. adjust only carry over ptr. */ - *p_last++ = *p_copy->p_begin; - last--; - for (p_tmp = p_str; *p_tmp; p_tmp++) - { - if (*p_copy->p_begin == *p_tmp) - { - p_copy->p_begin++; /* adjust pointer to point to next char to read */ - /* calculate new length of carry over buffer contents */ - p_copy->last.len = XML_FOLDER_CARRY_OVER_LEN-last; - *p_last = 0; /* NULL terminate p_last. rl: not really neccessary. */ - return; - } - } /* for */ - p_copy->p_begin++; /* update now to next char. this way abort char is also copied */ - } /* while */ - } /* !found */ -} - -/***************************************************************************** -** Function xml_folder_cback -** Description -** -** Parameters -** Returns -*****************************************************************************/ -static BOOLEAN xml_folder_cback( tXML_EVENT event, void *p_event_data, void *p_usr_data) -{ - tXML_MEVT_DATA *p_ed = (tXML_MEVT_DATA*) p_event_data; - tXML_FOLDER_STATE *p_st = (tXML_FOLDER_STATE *) p_usr_data; - tXML_PROP *p_cp = &p_st->p_prop[p_st->prop_index]; - BOOLEAN ret = TRUE; - UINT8 next; /* next element */ - UINT8 curr = p_ed->stack.stack[p_ed->stack.top]; /* current element */ -#if (FOLDER_DEBUG_XML == TRUE) - UINT8 dbg_name[FOLDER_DEBUG_LEN]; - UINT8 dbg_prefix[FOLDER_DEBUG_LEN]; - UINT8 dbg_value[FOLDER_DEBUG_LEN]; -#endif - -#if (FOLDER_DEBUG_XML == TRUE) - XML_TRACE_DEBUG1("xml_folder_cback:%d", event); -#endif - - switch (event) - { - case XML_TAG : /* <tag-name */ - next = xml_flp_proc_tag(p_st, &p_ed->tag.name, &p_ed->stack); -#if (FOLDER_DEBUG_XML == TRUE) - xml_flp_debug_str(&p_ed->tag.name, dbg_name); - xml_flp_debug_str(&p_ed->tag.prefix, dbg_prefix); - XML_TRACE_DEBUG2("XML_TAG: p:%s, name:%s", dbg_prefix, dbg_name); - XML_TRACE_DEBUG2("top:x%x, stk:x%x", p_ed->stack.top, p_ed->stack.stack[p_ed->stack.top]); - -#endif - if (next != 0) - { - if (next <= XML_MAX_OBJ_TAG_ID) - p_st->obj = next; - - if(p_st->prop_index <p_st->max_num_prop) - { - /* we do not use prefix in FTC */ - p_cp->name = next; - p_cp->p_data = NULL; - p_cp->len = 0; - p_cp->level = p_ed->stack.top; - p_st->prop_index++; - } - else - ret = FALSE; - } - break; - - case XML_ATTRIBUTE : /* attr-name="attr-value" */ - curr = xml_flp_proc_attr(p_st, &p_ed->attr.name, &p_ed->stack); -#if (defined(FOLDER_DEBUG_XML) && FOLDER_DEBUG_XML == TRUE) - xml_flp_debug_str(&p_ed->attr.name, dbg_name); - xml_flp_debug_str(&p_ed->attr.prefix, dbg_prefix); - xml_flp_debug_str(&p_ed->attr.value, dbg_value); - XML_TRACE_DEBUG4("[xml folder] XML_ATTRIBUTE: p:%s, name:%s, v:%s, curr:%x", - dbg_prefix, dbg_name, dbg_value, curr); -#endif - if ((curr != 0) && (curr != XML_XP_UNKNOWN_ID)) - { - if(p_st->prop_index <p_st->max_num_prop) - { - p_cp->name = curr; - p_cp->p_data = p_ed->attr.value.p; - p_cp->len = p_ed->attr.value.len; - p_cp->level = p_ed->stack.top; - p_st->prop_index++; - } - else - ret = FALSE; - p_ed->stack.top--; - } - break; - - case XML_CHARDATA : -#if (defined(FOLDER_DEBUG_XML) && FOLDER_DEBUG_XML == TRUE) - xml_flp_debug_str(&p_ed->ch_data.value, dbg_value); - XML_TRACE_DEBUG2("XML_CHARDATA: v:%s, last:%d", dbg_value, p_ed->ch_data.last); -#endif - break; - - case XML_ETAG : /* </tag-name> */ - if(p_ed->stack.top > 0) - { - p_ed->stack.stack[p_ed->stack.top] = 0; - p_ed->stack.top--; - p_st->ended = (BOOLEAN) (p_ed->stack.top == 0); - } -#if (defined(FOLDER_DEBUG_XML) && FOLDER_DEBUG_XML == TRUE) - xml_flp_debug_str(&p_ed->etag.name, dbg_name); - xml_flp_debug_str(&p_ed->etag.prefix, dbg_prefix); - XML_TRACE_DEBUG2("[xml folder] XML_ETAG: p:%s, name:%s", dbg_prefix, dbg_name); - XML_TRACE_DEBUG2("[xml folder] top:x%x, stk:x%x", p_ed->stack.top, p_ed->stack.stack[p_ed->stack.top]); -#endif - break; - - case XML_TAG_END: /* /> */ - curr = p_ed->stack.stack[p_ed->stack.top]; - - if(p_st->prop_index <p_st->max_num_prop) - { - if(p_ed->empty_elem.end) - p_cp->name = XML_FOLDER_TAG_END_ID; - else - p_cp->name = XML_FOLDER_PAUSE_ID; - p_cp->p_data = NULL; - p_cp->len = 0; - p_cp->level = p_ed->stack.top; - p_st->prop_index++; - if(p_ed->empty_elem.end && p_ed->stack.top > 0) - { - p_ed->stack.top--; - } - } - else - ret = FALSE; - -#if (defined(FOLDER_DEBUG_XML) && FOLDER_DEBUG_XML == TRUE) - XML_TRACE_DEBUG4("[xml folder] XML_TAG_END: %d, top:x%x, stk:x%x, curr:x%x", - p_ed->empty_elem.end, p_ed->stack.top, p_ed->stack.stack[p_ed->stack.top], curr); -#endif - break; - - case XML_PARTIAL: - if(p_st->p_prop[p_st->prop_index-1].name != XML_FOLDER_TAG_END_ID) - { - p_ed->stack.top--; -#if (defined(FOLDER_DEBUG_XML) && FOLDER_DEBUG_XML == TRUE) - XML_TRACE_DEBUG0("[xml folder] adjust due to XML_PARTIAL"); -#endif - } - break; - - case XML_COPY: - xml_flp_find_ch_n_copy( &p_ed->copy ); - XML_TRACE_DEBUG1("[xml folder] XML_COPY: %s", p_ed->copy.last.p); - break; - - default : -#if (defined(FOLDER_DEBUG_XML) && FOLDER_DEBUG_XML == TRUE) - XML_TRACE_DEBUG1("[xml folder] XML event: %d", event); -#endif - break; - } - - return ret; -} - -/********************************************************************************** -** Function xml_flp_int_fill_file_folder -** Description fill in file/folder structure. -** -** Parameters -** Returns xx: > 0 : number of properties scanned, folder entry is added -** = 0 : no end tag found, carry over to next parse -** = -1: no dst_resource avaibale, all prop left to next parse -** = -2: exceed max entry, no folder entry added -**********************************************************************************/ -static INT16 xml_flp_int_fill_file_folder( const UINT8 type, - tXML_FOLDER_STATE * p_xud, - tXML_PROP *p_prop, - UINT16 *num_prop, - UINT8 **p_dst_data, - UINT16 *dst_len) -{ - INT16 xx; - UINT16 len; - BOOLEAN end = FALSE; - tXML_PROP *cur_prop = p_prop; - UINT8 *p_cur_offset = *p_dst_data; - - for(xx=0; (xx < *num_prop) && !end; xx++, cur_prop++) - { -#if (defined(FOLDER_DEBUG_XML) && FOLDER_DEBUG_XML == TRUE) - XML_TRACE_DEBUG5( "[xml folder] fill: num_prop:%d, name id: x%x, p_prop: x%x, p_data:%s, len: %d", - (*num_prop-xx) , cur_prop->name, cur_prop, cur_prop->p_data, cur_prop->len); -#endif - switch (cur_prop->name) - { - case XML_NAME_ATTR_ID: - if ( p_xud->current_entry < p_xud->max_entry ) - { - /* as long as we do not exceed the number of entries in the ouput array copy name */ - p_xud->p_entry[p_xud->current_entry].type = type; - /* calculate the max length to copy */ - len = (cur_prop->len<=p_xud->max_name_len) ? cur_prop->len:p_xud->max_name_len; - if ((*dst_len - len) > 0) /* enough data buffer available? */ - { - p_xud->p_entry[p_xud->current_entry].data = p_cur_offset; - p_xud->p_entry[p_xud->current_entry].len = len; - - memcpy( (void *)p_xud->p_entry[p_xud->current_entry].data, - (const void *)cur_prop->p_data, - len ); - p_xud->p_entry[p_xud->current_entry].data[len] = 0; /* null terminate string */ - p_cur_offset += (len + 1); - *dst_len = *dst_len - (len + 1) ; - -#if (defined(FOLDER_DEBUG_XML) && FOLDER_DEBUG_XML == TRUE) - XML_TRACE_DEBUG3("[xml folder]: catch filename [%s] len [%d] dst_len left:[%d]", - p_xud->p_entry[p_xud->current_entry].data, - len, - *dst_len); -#endif - } - else /* run out of dst buffer resource */ - { - xx = -1; - return xx; - } - } - else /* exceed max entry */ - return -2; - - break; - - case XML_SIZE_ATTR_ID: - if ( p_xud->current_entry < p_xud->max_entry ) - { - p_xud->p_entry[p_xud->current_entry].size = atol( (const char *)cur_prop->p_data ); - } - break; - - case XML_USER_PERM_ATTR_ID: - if ( p_xud->current_entry < p_xud->max_entry ) - { - p_xud->p_entry[p_xud->current_entry].user_perm = xml_flp_get_perm( (char *)cur_prop->p_data, cur_prop->len); - } - break; - case XML_TYPE_ATTR_ID: - case XML_MODIFIED_ATTR_ID: - case XML_CREATED_ATTR_ID: - case XML_ACCESSED_ATTR_ID: - case XML_GROUP_PERM_ATTR_ID: - case XML_OTHER_PERM_ATTR_ID: - case XML_GROUP_ATTR_ID: - case XML_OWNER_ATTR_ID: - case XML_LANG_ATTR_ID: - -#if (defined(FOLDER_DEBUG_XML) && FOLDER_DEBUG_XML == TRUE) - XML_TRACE_DEBUG1( "[xml folder] ignored attr: 0x%x", cur_prop->name ); -#endif - break; - - case XML_FOLDER_TAG_END_ID: - /* -------------------- CUSTOMER SPECIFIC ---------------------- */ - p_xud->current_entry++; /* increment only when end tag (/>) found */ - -#if (defined(FOLDER_DEBUG_XML) && FOLDER_DEBUG_XML == TRUE) - XML_TRACE_DEBUG1( "[xml folder] FOUND END TAG: 0x%x", cur_prop->name ); -#endif - - end = TRUE; - break; - - default: - XML_TRACE_DEBUG1("[xml folder] unknown attrib: %d", cur_prop->name ); - break; - } - } -#if (FOLDER_DEBUG_XML == TRUE) - XML_TRACE_DEBUG2("[xml folder] fill_file_folder: end:%d, xx:%d", end, xx); -#endif -#if 0 - /* if end tag not found -> split over two buffers. but parser will still show rest of - found properties. so return still found properties. */ - if(end == FALSE) - xx = 0; -#endif - - /* keep track of current data buffer offset */ - *p_dst_data = p_cur_offset; - return xx; -} /* xml_flp_int_fill_file_folder() */ - - -/********************************************************************************** -** Function xml_flp_int_fill_evt_data -** -** Description fill in file/folder structure. -** -** Parameters -** Returns -**********************************************************************************/ -static tXML_FOLDER_RES xml_flp_int_fill_evt_data( UINT8 op, - void *p_evt_data, - tXML_PROP **p_prop, - UINT16 *num_prop, - UINT8 **p_dst_data, - UINT16 *dst_len) -{ - tXML_FOLDER_STATE *p_xud = (tXML_FOLDER_STATE *)p_evt_data; - INT16 inc_prop; - UINT8 prop_name; /* Property name. */ - UINT8 entry_type; - tXML_PROP *cur_prop = *p_prop; - UINT8 *p_cur_offset = *p_dst_data; - - tXML_FOLDER_RES x_res = XML_FOLDER_OK; - BOOLEAN x_no_res = FALSE; /* guard dest buffer resource */ - - - if ( op == 0 || op > XML_MAX_OBJ_TAG_ID || *num_prop == 0) - return XML_FOLDER_ERROR; - -#if FOLDER_DEBUG_XML - XML_TRACE_DEBUG2( "[xml folder] xml_flp_int_fill_evt_data op:%d, num_prop:%d", - op, *num_prop); -#endif - - - - while ( *num_prop > 0 && !x_no_res ) - { -#if (defined(FOLDER_DEBUG_XML) && FOLDER_DEBUG_XML == TRUE) - XML_TRACE_DEBUG2("end_prop:%d, name id: x%x", *num_prop, cur_prop->name); -#endif - prop_name = cur_prop->name; - cur_prop++; - *num_prop -= 1; - - - switch( prop_name ) - { - case XML_FOLDER_LISTING_ELEM_ID: - /* skip over version attribute which should always be 1.0. this is the top level */ - break; - - case XML_FILE_ELEM_ID: - case XML_FOLDER_ELEM_ID: - /* folder or file: only type is the difference */ - entry_type = (XML_FILE_ELEM_ID==prop_name)?XML_OBX_FILE:XML_OBX_FOLDER; - inc_prop = xml_flp_int_fill_file_folder( entry_type, - p_xud, - cur_prop, - num_prop, - &p_cur_offset, - dst_len); - if (inc_prop == -1) /* no dst_buf available */ - { - /* backup one more prop to obtain the skipped folder/file entry header */ - cur_prop --; - *num_prop += 1; - - x_res = XML_FOLDER_DST_NO_RES; - x_no_res = TRUE; - } - else if (inc_prop == -2) /* exceed max entry */ - { - x_no_res = TRUE; - x_res = XML_FOLDER_OUT_FULL; - } - else /* found folder entry */ - { - cur_prop += inc_prop; - *num_prop -= inc_prop; - } - break; - - case XML_PARENT_FOLDER_ELEM_ID: - if ( p_xud->current_entry < p_xud->max_entry ) - { - /* set type of entry (file, folder) */ - p_xud->p_entry[p_xud->current_entry].type = XML_OBX_FOLDER; - /* copy folder name if dst buffer is big enough, parent folder as ".." */ - if ((*dst_len - strlen(XML_PARENT_FOLDER)) > 0) - { - p_xud->p_entry[p_xud->current_entry].data = p_cur_offset; - p_xud->p_entry[p_xud->current_entry].len = 2; - memcpy( (void *)p_xud->p_entry[p_xud->current_entry].data, - (const void *)XML_PARENT_FOLDER, 2); - p_xud->p_entry[p_xud->current_entry].data[2] = '\0'; /* null terminate */ - p_xud->current_entry ++; - p_cur_offset += 3 ; - *dst_len -= 3; - } - else - { - x_no_res = TRUE; - x_res = XML_FOLDER_DST_NO_RES; - } - } - else - { - x_no_res = TRUE; - x_res = XML_FOLDER_OUT_FULL; - } - break; - - case XML_FOLDER_PAUSE_ID: - -#if (FOLDER_DEBUG_XML==TRUE) - XML_TRACE_DEBUG0( "[xml folder] xml_flp_int_fill_evt_data(): XML_FOLDER_PAUSE_ID" ); -#endif - break; - - case XML_FOLDER_TAG_END_ID: -#if (FOLDER_DEBUG_XML==TRUE) - XML_TRACE_DEBUG0( "[xml folder] xml_flp_int_fill_evt_data(): XML_FOLDER_TAG_END_ID" ); -#endif - break; - - default: - XML_TRACE_DEBUG1( "[xml folder] xml_flp_int_fill_evt_data():unknown element: %d", prop_name ); - break; - } - } - - /* keep track of current filling position, and current available dst buffer */ - *p_prop = cur_prop; - *p_dst_data = p_cur_offset; - - return x_res; -} /* xml_flp_int_fill_evt_data() */ - - -/************************************************************************************** -** Function XML_FolderInit -** -** Description Initialize xml parser state machine. -** -** Parameters p_xml_state: address of an xml parser state machine to be initialized, -** allocate an additional space of size XML_FOLDER_CARRY_OVER_LEN -** right after *p_xml_state to hold carry over data. -** p_entry : points start of output directory entry. caller needs do -** free this memory -** max_entry : max is 16 bit integer value which is the maximum number -** of folder entries. - -** -** Returns void -**************************************************************************************/ - -void XML_FolderInit( tXML_FOLDER_PARSER *p_xml_state, - tXML_FOLDER_ENTRY *p_entry, - const UINT16 max_entry ) -{ - /* Initialize the generic xml parser state machine.*/ - XML_InitPars( &p_xml_state->xml, xml_folder_cback, &p_xml_state->xml_user_data ); - - /* User need to allocate an additional space of size XML_FOLDER_CARRY_OVER_LEN */ - /* right after *p_xml_state to hold carry over data. */ - /* point to the end of the allocated buffer for p_xml_state, which is the */ - /* beginning of buffer(XML_FOLDER_CARRY_OVER_LEN) */ - p_xml_state->xml.last_bfr.p = (UINT8 *)(p_xml_state + 1); - p_xml_state->xml.last_bfr.len = XML_FOLDER_CARRY_OVER_LEN; - - /* Initialize user data */ - p_xml_state->xml_user_data.p_entry = p_entry; - p_xml_state->xml_user_data.current_entry = 0; - p_xml_state->xml_user_data.max_name_len = XML_UI_ENTRY_MAX_NAME_LEN + 1; - p_xml_state->xml_user_data.max_entry = (UINT16)max_entry; - p_xml_state->xml_user_data.prop_num = 0; -} - - -/************************************************************************************** -** Function XML_FolderParse -** -** Description This function is called to parse the xml data received from OBEX -** into folder entries associated with properties value. It can also be -** used as clean up function to delete left over data from previous parse. -** This clean up function is typically used when application runs out of -** resource and decides to discard extra xml data received. -** -** Parameters p_xml_state: pointer to a xml parser initialized by XML_FolderInit(). -** xml_data: valid pointer to OBEX list data in xml format. -** xml_len: length of the package, must be non-zero value. -** dst_data: valid pointer to the buffer for holding converted folder entry name. - When dst_data is NULL, clean up all remaining data in the parser. -** dst_len: pointer to the length of dst_data buffer, its carry out value -** is the number of bytes remaining buffer.When dst_len is NULL, -** it will cause to flush the internal data in the parser. -** num_entries: current number of entries, in the end it is the total number of entries -** -** Returns tXML_FOLDER_RES (see xml_flp.h) -** XML_PENDING: parsing not completed -** XML_END_LIST: found /folder-listing but no final flag detected -** XML_FOLDER_OUT_FULL: reached max_entry -> do not call parser anymore!!! dump data -** XML_FOLDER_DST_NO_RES : run out of dst buffer resource while -** some xml data still remains. - -**************************************************************************************/ -tXML_FOLDER_RES XML_FolderParse( tXML_FOLDER_PARSER *p_xml_state, - UINT8 *xml_data, UINT16 xml_len, - UINT8 *dst_data, UINT16 *dst_len, - UINT16 *num_entries ) -{ - tXML_OS xos; - BOOLEAN is_remain = TRUE; - tXML_MUL_STATE *p_xml = &p_xml_state->xml; - tXML_FOLDER_STATE *p_st = &p_xml_state->xml_user_data; - tXML_FOLDER_RES x_res = XML_FOLDER_OK; - tXML_RESULT res = XML_NO_PROP; - UINT16 max_num_prop = OBX_LRG_DATA_POOL_SIZE/sizeof(tXML_PROP); /* Changed to use the reserved buffer pool */ - - -#if (defined(FOLDER_DEBUG_XML) && FOLDER_DEBUG_XML == TRUE) - int xx; - UINT8 dbg_buf[FOLDER_DEBUG_LEN]; - tXML_STR str; -#endif - - /* if dst_data is NULL, clean up remaining data */ - if (!dst_data || !dst_len) - { - /* clean out remained xml data left over from last parse */ - if (p_xml_state->xml_user_data.p_prop ) - { - GKI_freebuf( p_st->p_prop ); - p_st->p_prop = p_st->offset_prop = NULL; - p_st->prop_num = 0; - } -#if (FOLDER_DEBUG_XML == TRUE) - XML_TRACE_DEBUG0( "[xml folder] XML_FolderParse() Clean up left over!"); -#endif - return x_res; - } - - /* if illegal OBEX data or dst buffer pointer received, return ERROR */ - if (xml_len == 0 || !xml_data) - { - return XML_FOLDER_ERROR; - } - - /* XML_FolderParse receive new xml data, allocate buffer to hold parsed prop */ - if (p_st->offset_prop == NULL) - { - -#if (FOLDER_DEBUG_XML == TRUE) - XML_TRACE_DEBUG0( "[xml folder] XML_FolderParse() Receive New Data!"); - XML_TRACE_DEBUG2( "[xml folder] XML_data start[%x] end [%x]",xml_data, xml_data+xml_len); -#endif - is_remain = FALSE; - if ( NULL!= (p_st->p_prop = (tXML_PROP *)GKI_getpoolbuf( OBX_LRG_DATA_POOL_ID ) ) ) - { - /* pointing next prop to be converted into file entry */ - p_st->prop_num = 0; - } - else - { - GKI_freebuf( p_xml_state ); - x_res = XML_FOLDER_NO_RES; - return x_res; - } - } -#if (FOLDER_DEBUG_XML == TRUE) - else - { - XML_TRACE_DEBUG0( "[xml folder] XML_FolderParse(): Keep cleaning up old xml data !"); - } -#endif - /* update the data address */ - xos.p_begin = xml_data; - xos.p_end = xml_data + xml_len; - - while( res == XML_NO_PROP ) - { - /* if no remaining data in p_st->p_prop, parse new xml data */ - if (!is_remain) - { - p_st->max_num_prop = max_num_prop; - p_st->prop_index = 0; - res = XML_MulParse( p_xml, &xos ); - - -#if (FOLDER_DEBUG_XML == TRUE) - XML_TRACE_DEBUG4( "xml_folder_parse obj: %x, max: %d, num: %d, res: %d", - p_st->obj, max_num_prop, p_st->prop_index, res); - - if (res != 0) - { - XML_TRACE_DEBUG1( "XML_MulParse Parsing: %d !!!", res); - } - - for(xx=0; xx<p_st->prop_index; xx++) - { - if ( p_st->p_prop[xx].name < XML_FOLDER_MAX_ID ) - { - str.p = p_st->p_prop[xx].p_data; - str.len = p_st->p_prop[xx].len; - xml_flp_debug_str(&str, dbg_buf); - XML_TRACE_DEBUG5( "[xml folder] parsed: index[%d]:%d:%s: %s(%d)", p_st->prop_index-xx, p_st->p_prop[xx].level, - xml_flp_ttbl[p_st->p_prop[xx].name].p_name, dbg_buf, p_st->p_prop[xx].len); - } - else - { - XML_TRACE_DEBUG3( "[xml folder] internal prop: %d:%d:%d", xx, p_st->p_prop[xx].level, - p_st->p_prop[xx].name ); - } - } -#endif - p_st->prop_num = p_st->prop_index ; - p_st->offset_prop = p_st->p_prop; - } - else - { - /* This is left over data, pick up the result from the previous parse */ - res = p_xml->pars_res; - } - - if ( res != XML_OBJ_ST_EMPTY ) - { - x_res = xml_flp_int_fill_evt_data( p_st->obj, p_st, &p_st->offset_prop, &p_st->prop_num, &dst_data, dst_len ); - - if ( (XML_FOLDER_OK == x_res) && (XML_NO_END == res) ) - { - /* XML_NO_END means that the xml is not completly finished and fill returns - ok when when partial filling has been ok */ - x_res = XML_FOLDER_PENDING; - } - - /* all parsed xml data has been converted into file entry */ - /* or exceed max entry number , break the parsing loop */ - if (XML_FOLDER_OUT_FULL != x_res && XML_FOLDER_DST_NO_RES != x_res) - { - is_remain = FALSE; - } - else - break; - } - } /* while */ - - /* free property table. at next call a new one is allocated */ - if ((x_res != XML_FOLDER_DST_NO_RES && p_st->p_prop) || - XML_FOLDER_OUT_FULL == x_res) - { - GKI_freebuf( p_st->p_prop ); - p_st->p_prop = NULL; - p_st->offset_prop = NULL; - } - - if ( x_res != XML_FOLDER_DST_NO_RES && p_st->ended) - { - /* this should happen on the same time as final flag in fact */ - x_res = XML_FOLDER_END_LIST; /* found closing /folder-listing */ - } - - - *num_entries = p_st->current_entry; /* report number of entries found. only when ended is true - application really should be interested! */ - return x_res; -} - diff --git a/stack/xml/xml_mlp.c b/stack/xml/xml_mlp.c deleted file mode 100644 index aca0cb5..0000000 --- a/stack/xml/xml_mlp.c +++ /dev/null @@ -1,1060 +0,0 @@ -/****************************************************************************** - ** - ** Name: xml_mlp.c - ** - ** Description: This module contains xml parser of MAP message list object - ** - ** Copyright (c) 2004-2011, Broadcom Corporation, All Rights Reserved. - ** Broadcom Bluetooth Core. Proprietary and confidential. - ******************************************************************************/ - -#include "bt_target.h" -#include "gki.h" -#include "xml_mlp_api.h" - -#include <string.h> -#include <stdlib.h> - -#ifndef ML_DEBUG_XML -#define ML_DEBUG_XML TRUE -#endif -#define ML_DEBUG_LEN 50 -#if (defined(ML_DEBUG_XML) && ML_DEBUG_XML == TRUE) -#define XML_TRACE_DEBUG0(m) {BT_TRACE_0(TRACE_LAYER_GOEP, TRACE_TYPE_DEBUG, m);} -#define XML_TRACE_DEBUG1(m,p1) {BT_TRACE_1(TRACE_LAYER_GOEP, TRACE_TYPE_DEBUG, m,p1);} -#define XML_TRACE_DEBUG2(m,p1,p2) {BT_TRACE_2(TRACE_LAYER_GOEP, TRACE_TYPE_DEBUG, m,p1,p2);} -#define XML_TRACE_DEBUG3(m,p1,p2,p3) {BT_TRACE_3(TRACE_LAYER_GOEP, TRACE_TYPE_DEBUG, m,p1,p2,p3);} -#define XML_TRACE_DEBUG4(m,p1,p2,p3,p4) {BT_TRACE_4(TRACE_LAYER_GOEP, TRACE_TYPE_DEBUG, m,p1,p2,p3,p4);} -#define XML_TRACE_DEBUG5(m,p1,p2,p3,p4,p5) {BT_TRACE_5(TRACE_LAYER_GOEP, TRACE_TYPE_DEBUG, m,p1,p2,p3,p4,p5);} -#define XML_TRACE_DEBUG6(m,p1,p2,p3,p4,p5,p6) {BT_TRACE_6(TRACE_LAYER_GOEP, TRACE_TYPE_DEBUG, m,p1,p2,p3,p4,p5,p6);} -#else -#define XML_TRACE_DEBUG0(m) -#define XML_TRACE_DEBUG1(m,p1) -#define XML_TRACE_DEBUG2(m,p1,p2) -#define XML_TRACE_DEBUG3(m,p1,p2,p3) -#define XML_TRACE_DEBUG4(m,p1,p2,p3,p4) -#define XML_TRACE_DEBUG5(m,p1,p2,p3,p4,p5) -#define XML_TRACE_DEBUG6(m,p1,p2,p3,p4,p5,p6) -#endif - -#define XML_PERM_LEN_MAX 4 - -/***************************************************************************** -** Constants -*****************************************************************************/ -const UINT8 xml_ml_elem[] = "MAP-msg-listing"; -const UINT8 xml_ml_msg_elem[] = "msg"; -const UINT8 xml_ml_handle_attr[] = "handle"; -const UINT8 xml_ml_subject_attr[] = "subject"; -const UINT8 xml_ml_datetime_attr[] = "datetime"; -const UINT8 xml_ml_sender_name_attr[] = "sender_name"; -const UINT8 xml_ml_sender_addressing_attr[] = "sender_addressing"; -const UINT8 xml_ml_replyto_addressing_attr[] = "replyto_addressing"; -const UINT8 xml_ml_recipient_name_attr[] = "recipient_name"; -const UINT8 xml_ml_recipient_addressing_attr[] = "recipient_addressing"; -const UINT8 xml_ml_type_attr[] = "type"; -const UINT8 xml_ml_size_attr[] = "size"; -const UINT8 xml_ml_text_attr[] = "text"; -const UINT8 xml_ml_reception_status_attr[] = "reception_status"; -const UINT8 xml_ml_attachment_size_attr[] = "attachment_size"; -const UINT8 xml_ml_priority_attr[] = "priority"; -const UINT8 xml_ml_read_attr[] = "read"; -const UINT8 xml_ml_sent_attr[] = "sent"; -const UINT8 xml_ml_protected_attr[] = "protected"; -const UINT8 xml_ml_version_attr[] = "version"; -const UINT8 xml_ml_unknown[] = "unknown"; - -#define XML_ML_ELEM_ID 0x01 -#define XML_ML_MSG_ELEM_ID 0x02 -#define XML_ML_MAX_OBJ_TAG_ID XML_ML_ELEM_ID -#define XML_ML_HANDLE_ATTR_ID 0x03 -#define XML_ML_SUBJECT_ATTR_ID 0x04 -#define XML_ML_DATETIME_ATTR_ID 0x05 -#define XML_ML_SENDER_NAME_ATTR_ID 0x06 -#define XML_ML_SENDER_ADDRESSING_ATTR_ID 0x07 -#define XML_ML_REPLYTO_ADDRESSING_ATTR_ID 0x08 -#define XML_ML_RECIPIENT_NAME_ATTR_ID 0x09 -#define XML_ML_RECIPIENT_ADDRESSING_ATTR_ID 0x0a -#define XML_ML_TYPE_ATTR_ID 0x0b -#define XML_ML_SIZE_ATTR_ID 0x0c -#define XML_ML_TEXT_ATTR_ID 0x0d -#define XML_ML_RECEPTION_STATUS_ATTR_ID 0x0e -#define XML_ML_ATTACHMENT_SIZE_ATTR_ID 0x0f -#define XML_ML_PRIORITY_ATTR_ID 0x10 -#define XML_ML_READ_ATTR_ID 0x11 -#define XML_ML_SENT_ATTR_ID 0x12 -#define XML_ML_PROTECTED_ATTR_ID 0x13 -#define XML_ML_VERSION_ATTR_ID 0x14 -#define XML_ML_UNKNOWN_ID 0x15 -#define XML_ML_MAX_ID 0x16 /* keep in sync with above */ -#define XML_ML_TAG_END_ID 0x17 /* closing tag found end=true */ -#define XML_ML_PAUSE_ID 0x18 /* closing tag found end=false */ - -#define XML_ML_TTBL_SIZE (XML_ML_MAX_ID+1) - -/***************************************************************************** -** Type Definitions -*****************************************************************************/ - -typedef struct -{ - const UINT8 *p_name; - UINT8 len; -} tXML_ML_TTBL_ELEM; - -typedef tXML_ML_TTBL_ELEM tXML_ML_TTBL[]; /* Tag Table */ - - -static const tXML_ML_TTBL_ELEM xml_ml_ttbl[XML_ML_TTBL_SIZE] = -{ /* index (ML_XP_*_ID) & name */ - {(UINT8*) "", XML_ML_MAX_ID-1}, /* \x00 Number of elements in array */ - /* XML EVT_RPT element (TAG) name */ - {xml_ml_elem, 15}, /* x01 MAP-msg-listing */ - {xml_ml_msg_elem, 3}, /* x02 msg */ - {xml_ml_handle_attr, 6}, /* x03 handle */ - {xml_ml_subject_attr, 7}, /* x04 subject */ - {xml_ml_datetime_attr, 8}, /* x05 datetime */ - {xml_ml_sender_name_attr, 11}, /* x06 sender_name */ - {xml_ml_sender_addressing_attr, 17}, /* x07 sender_addressing */ - {xml_ml_replyto_addressing_attr, 18}, /* x08 replyto_addressing */ - {xml_ml_recipient_name_attr, 14}, /* x09 recipient_name */ - {xml_ml_recipient_addressing_attr, 20}, /* x0a recipient_addressing */ - {xml_ml_type_attr, 4}, /* x0b type */ - {xml_ml_size_attr, 4}, /* x0c size */ - {xml_ml_text_attr, 4}, /* x0d text */ - {xml_ml_reception_status_attr, 16}, /* x0e reception_status */ - {xml_ml_attachment_size_attr, 15}, /* x0f attachment_size */ - {xml_ml_priority_attr, 8}, /* x10 priority */ - {xml_ml_read_attr, 4}, /* x11 read */ - {xml_ml_sent_attr, 4}, /* x12 sent */ - {xml_ml_protected_attr, 9}, /* x13 protected */ - {xml_ml_version_attr, 7}, /* x14 version */ - {xml_ml_unknown, 7} /* x15 unknown */ -}; - -#define XML_MAP_ML_PTBL_SIZE 0x03 -typedef UINT8 * tXML_MAP_ML_PTBL_ELEM; - -static const tXML_MAP_ML_PTBL_ELEM xml_ml_ptbl[XML_MAP_ML_PTBL_SIZE] = -{ - (UINT8 *) "\x01", /* index x00, all valide attributes in above list */ - (UINT8 *) "\x14\x02", /* x01 attributes and sub-tags supported */ - (UINT8 *) "\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13" -}; - - -#if (ML_DEBUG_XML == TRUE) -void xml_ml_debug_str(tXML_STR *p_str, UINT8 *p_buf) -{ - int dbg_len; - if ( (p_str == NULL) || (NULL==p_str->p)) - BCM_STRNCPY_S( (char *)p_buf, ML_DEBUG_LEN, "(NULL)", ML_DEBUG_LEN-1); - else - { - dbg_len = p_str->len; - if ( dbg_len >= ML_DEBUG_LEN) - dbg_len = ML_DEBUG_LEN - 1; - BCM_STRNCPY_S( (char *)p_buf, ML_DEBUG_LEN, (char *)p_str->p, dbg_len); - p_buf[dbg_len] = 0; - } -} - -#else -#define xml_ml_debug_str(p_str, p_buf) -#endif - -/***************************************************************************** - ** Function xml_ml_proc_tag - ** Description - ** Parameters - - ** Returns - *****************************************************************************/ -static UINT8 xml_ml_proc_tag( tXML_ML_STATE *p_st, tXML_STR *p_name, tXML_STACK *p_stk) -{ - const UINT8 *p_stag; /* sub tag pointer */ - UINT8 curr = p_stk->stack[p_stk->top]; -#if (defined(ML_DEBUG_XML) && ML_DEBUG_XML == TRUE) - UINT8 dbg_name[ML_DEBUG_LEN]; -#endif - - - if (curr < XML_MAP_ML_PTBL_SIZE) - { - /* Iterate over allowed sub-tags for the current tag. */ - for (p_stag = xml_ml_ptbl[curr]; p_stag && *p_stag ; p_stag++) - { - if (*p_stag >= XML_ML_TTBL_SIZE) - continue; - if (p_name->len == xml_ml_ttbl[*p_stag].len && - strncmp((char *)p_name->p, (char *)xml_ml_ttbl[*p_stag].p_name, p_name->len) == 0) - { - p_stk->top++; - p_stk->stack[p_stk->top] = *p_stag; - - return *p_stag; - } - } - } - -#if (defined(ML_DEBUG_XML) && ML_DEBUG_XML == TRUE) - xml_ml_debug_str(p_name, dbg_name); - XML_TRACE_DEBUG1("xml_ml_proc_tag: bad name:%s", dbg_name ); -#endif - - return XML_ML_UNKNOWN_ID; -} - - -/***************************************************************************** - ** Function xml_ml_proc_attr - ** Description - ** Parameters - - ** Returns - *****************************************************************************/ -static UINT8 xml_ml_proc_attr(tXML_ML_STATE *p_st, tXML_STR *p_name, tXML_STACK *p_stk) -{ - const UINT8 *p_stag; /* sub tag pointer */ - UINT8 curr = p_stk->stack[p_stk->top]; -#if (ML_DEBUG_XML == TRUE) - UINT8 dbg_name[ML_DEBUG_LEN]; -#endif - if (curr < XML_MAP_ML_PTBL_SIZE) - { - /* Iterate over allowed sub-tags for the current tag. */ - for (p_stag = xml_ml_ptbl[curr]; p_stag && *p_stag; p_stag++) - { - if (*p_stag >= XML_ML_TTBL_SIZE) - continue; - if (p_name->len == xml_ml_ttbl[*p_stag].len && - strncmp((char *)p_name->p, (char *)xml_ml_ttbl[*p_stag].p_name, p_name->len) == 0) - { - p_stk->top++; - p_stk->stack[p_stk->top] = *p_stag; - - return *p_stag; - } - } - } - -#if (defined(ML_DEBUG_XML) && ML_DEBUG_XML == TRUE) - xml_ml_debug_str(p_name, dbg_name); - XML_TRACE_DEBUG1("xml_ml_proc_attr: bad name:%s", dbg_name); -#endif - return XML_ML_UNKNOWN_ID; -} - -/***************************************************************************** - ** Function xml_ml_find_ch_n_copy - ** Description copy any chacter till one char in p_str. Any char in p_str - ** will stop copy pointed by p_begin - ** Parameters - ** Returns - *****************************************************************************/ -static void xml_ml_find_ch_n_copy( tXML_MCOPY *p_copy ) -{ - const UINT8 *p_tmp; - const UINT8 *p_str = (UINT8 *)">"; /* was: ":=/> \t\n\r". i think we should copy till - closing flag */ - unsigned int last = XML_ML_CARRY_OVER_LEN; /* maximum carry over len we can support */ - UINT8 *p_last = p_copy->last.p + p_copy->last.len - 1; /* point to the last char of carry - over buffer */ - BOOLEAN found = FALSE; - /* check if the last char in p_last is in p_str */ - for (p_tmp = p_str; *p_tmp; p_tmp++) - { - if (*p_last == *p_tmp) - { - found = TRUE; - break; - } - } /* for */ - - if (found == FALSE) - { - /* if not in p_str, move chars from p_begin to p_last - * until reached last_len or any char in p_str */ - p_last++; - last -= p_copy->last.len; /* calculate the maximum number of chars we can copy */ - while (*(p_copy->p_begin) && last) /* rl: not sure that this buffer is termninated by a 0 */ - { - /* copy from source (new buffer) to carry over. adjust only carry over ptr. */ - *p_last++ = *p_copy->p_begin; - last--; - for (p_tmp = p_str; *p_tmp; p_tmp++) - { - if (*p_copy->p_begin == *p_tmp) - { - p_copy->p_begin++; /* adjust pointer to point to next char to read */ - /* calculate new length of carry over buffer contents */ - p_copy->last.len = XML_ML_CARRY_OVER_LEN-last; - *p_last = 0; /* NULL terminate p_last. rl: not really neccessary. */ - return; - } - } /* for */ - p_copy->p_begin++; /* update now to next char. this way abort char is also copied */ - } /* while */ - } /* !found */ -} - -/***************************************************************************** -** Function xml_ml_cback -** Description -** -** Parameters -** Returns -*****************************************************************************/ -static BOOLEAN xml_ml_cback( tXML_EVENT event, void *p_event_data, void *p_usr_data) -{ - tXML_MEVT_DATA *p_ed = (tXML_MEVT_DATA*) p_event_data; - tXML_ML_STATE *p_st = (tXML_ML_STATE *) p_usr_data; - tXML_PROP *p_cp = &p_st->p_prop[p_st->prop_index]; - BOOLEAN ret = TRUE; - UINT8 next; /* next element */ - UINT8 curr = p_ed->stack.stack[p_ed->stack.top]; /* current element */ -#if (ML_DEBUG_XML == TRUE) - UINT8 dbg_name[ML_DEBUG_LEN]; - UINT8 dbg_prefix[ML_DEBUG_LEN]; - UINT8 dbg_value[ML_DEBUG_LEN]; -#endif - -#if (ML_DEBUG_XML == TRUE) - XML_TRACE_DEBUG1("xml_ml_cback:%d", event); -#endif - - switch (event) - { - case XML_TAG : /* <tag-name */ - next = xml_ml_proc_tag(p_st, &p_ed->tag.name, &p_ed->stack); -#if (ML_DEBUG_XML == TRUE) - xml_ml_debug_str(&p_ed->tag.name, dbg_name); - xml_ml_debug_str(&p_ed->tag.prefix, dbg_prefix); - XML_TRACE_DEBUG2("XML_TAG: p:%s, name:%s", dbg_prefix, dbg_name); - XML_TRACE_DEBUG2("top:x%x, stk:x%x", p_ed->stack.top, p_ed->stack.stack[p_ed->stack.top]); - -#endif - if (next != 0) - { - if (next <= XML_ML_MAX_OBJ_TAG_ID) - p_st->obj = next; - - if (p_st->prop_index <p_st->max_num_prop) - { - /* we do not use prefix in FTC */ - p_cp->name = next; - p_cp->p_data = NULL; - p_cp->len = 0; - p_cp->level = p_ed->stack.top; - p_st->prop_index++; - } - else - ret = FALSE; - } - break; - - case XML_ATTRIBUTE : /* attr-name="attr-value" */ - curr = xml_ml_proc_attr(p_st, &p_ed->attr.name, &p_ed->stack); -#if (defined(ML_DEBUG_XML) && ML_DEBUG_XML == TRUE) - xml_ml_debug_str(&p_ed->attr.name, dbg_name); - xml_ml_debug_str(&p_ed->attr.prefix, dbg_prefix); - xml_ml_debug_str(&p_ed->attr.value, dbg_value); - XML_TRACE_DEBUG4("[xml ml] XML_ATTRIBUTE: p:%s, name:%s, v:%s, curr:%x", - dbg_prefix, dbg_name, dbg_value, curr ); - XML_TRACE_DEBUG2("top 1:x%x, stk:x%x", p_ed->stack.top, p_ed->stack.stack[p_ed->stack.top]); -#endif - if ((curr != 0) && (curr != XML_ML_UNKNOWN_ID)) - { - if (p_st->prop_index <p_st->max_num_prop) - { - p_cp->name = curr; - p_cp->p_data = p_ed->attr.value.p; - p_cp->len = p_ed->attr.value.len; - p_cp->level = p_ed->stack.top; - p_st->prop_index++; - } - else - ret = FALSE; - p_ed->stack.top--; - XML_TRACE_DEBUG2("top 2:x%x, stk:x%x", p_ed->stack.top, p_ed->stack.stack[p_ed->stack.top]); - } - break; - - case XML_CHARDATA : -#if (defined(ML_DEBUG_XML) && ML_DEBUG_XML == TRUE) - xml_ml_debug_str(&p_ed->ch_data.value, dbg_value); - XML_TRACE_DEBUG2("XML_CHARDATA: v:%s, last:%d", dbg_value, p_ed->ch_data.last); -#endif - break; - - case XML_ETAG : /* </tag-name> */ - if (p_ed->stack.top > 0) - { - p_ed->stack.stack[p_ed->stack.top] = 0; - p_ed->stack.top--; - p_st->ended = (BOOLEAN) (p_ed->stack.top == 0); - } -#if (defined(ML_DEBUG_XML) && ML_DEBUG_XML == TRUE) - xml_ml_debug_str(&p_ed->etag.name, dbg_name); - xml_ml_debug_str(&p_ed->etag.prefix, dbg_prefix); - XML_TRACE_DEBUG2("[xml ml] XML_ETAG: p:%s, name:%s", dbg_prefix, dbg_name); - XML_TRACE_DEBUG2("[xml ml] top:x%x, stk:x%x", p_ed->stack.top, p_ed->stack.stack[p_ed->stack.top]); -#endif - break; - - case XML_TAG_END: /* /> */ - curr = p_ed->stack.stack[p_ed->stack.top]; - - if (p_st->prop_index <p_st->max_num_prop) - { - if (p_ed->empty_elem.end) - p_cp->name = XML_ML_TAG_END_ID; - else - p_cp->name = XML_ML_PAUSE_ID; - p_cp->p_data = NULL; - p_cp->len = 0; - p_cp->level = p_ed->stack.top; - p_st->prop_index++; - if (p_ed->empty_elem.end && p_ed->stack.top > 0) - { - p_ed->stack.top--; - } - } - else - ret = FALSE; - -#if (defined(ML_DEBUG_XML) && ML_DEBUG_XML == TRUE) - XML_TRACE_DEBUG4("[xml ml] XML_TAG_END: %d, top:x%x, stk:x%x, curr:x%x", - p_ed->empty_elem.end, p_ed->stack.top, p_ed->stack.stack[p_ed->stack.top], curr); -#endif - break; - - case XML_PARTIAL: - if (p_st->p_prop[p_st->prop_index-1].name != XML_ML_TAG_END_ID) - { - p_ed->stack.top--; -#if (defined(ML_DEBUG_XML) && ML_DEBUG_XML == TRUE) - XML_TRACE_DEBUG0("[xml ml] adjust due to XML_PARTIAL"); -#endif - } - break; - - case XML_COPY: - xml_ml_find_ch_n_copy( &p_ed->copy ); - XML_TRACE_DEBUG1("[xml ml] XML_COPY: %s", p_ed->copy.last.p); - break; - - default : -#if (defined(ML_DEBUG_XML) && ML_DEBUG_XML == TRUE) - XML_TRACE_DEBUG1("[xml ml] default: XML event: %d", event); -#endif - break; - } - - return ret; -} - - - - -/********************************************************************************** -** Function xml_ml_int_fill_msg_list -** Description fill in file/folder structure. -** -** Parameters -** Returns xx: > 0 : number of properties scanned, folder entry is added -** = 0 : no end tag found, carry over to next parse -** = -1: no dst_resource avaibale, all prop left to next parse -** = -2: exceed max entry, no folder entry added -**********************************************************************************/ -static INT16 xml_ml_int_fill_msg_list( tXML_ML_STATE * p_xud, - tXML_PROP *p_prop, - UINT16 *num_prop, - UINT8 **p_dst_data, - UINT16 *dst_len) -{ - INT16 xx; - UINT16 len; - BOOLEAN end = FALSE; - tXML_PROP *cur_prop = p_prop; - UINT8 *p_cur_offset = *p_dst_data; - BOOLEAN copy_attr_info; - BOOLEAN no_buf_left; - UINT8 **p_attr_data = NULL; - UINT16 *p_attr_len = NULL; - - if ( p_xud->current_entry >= p_xud->max_entry ) - return -2; - - for (xx=0; (xx < *num_prop) && !end; xx++, cur_prop++) - { -#if (defined(ML_DEBUG_XML) && ML_DEBUG_XML == TRUE) - /* XML_TRACE_DEBUG5( "[xml ml] fill: num_prop:%d, name id: x%x, p_prop: x%x, len: %d p_data:%s", - (*num_prop-xx) , cur_prop->name, cur_prop, cur_prop->len, cur_prop->p_data, ); */ -#endif - copy_attr_info = TRUE; - no_buf_left = FALSE; - len = cur_prop->len; - - switch (cur_prop->name) - { - case XML_ML_HANDLE_ATTR_ID: - if ((*dst_len - len) > 0) /* enough data buffer available? */ - { - p_attr_data = &(p_xud->p_entry[p_xud->current_entry].msg_handle) ; - p_attr_len = &(p_xud->p_entry[p_xud->current_entry].msg_handle_len); - } - else /* run out of dst buffer resource */ - no_buf_left = TRUE; - break; - - case XML_ML_SUBJECT_ATTR_ID: - if ((*dst_len - len) > 0) /* enough data buffer available? */ - { - p_attr_data = &(p_xud->p_entry[p_xud->current_entry].subject) ; - p_attr_len = &(p_xud->p_entry[p_xud->current_entry].subject_len); - } - else /* run out of dst buffer resource */ - no_buf_left = TRUE; - break; - case XML_ML_DATETIME_ATTR_ID: - if ((*dst_len - len) > 0) /* enough data buffer available? */ - { - p_attr_data = &(p_xud->p_entry[p_xud->current_entry].datetime) ; - p_attr_len = &(p_xud->p_entry[p_xud->current_entry].datetime_len); - } - else /* run out of dst buffer resource */ - no_buf_left = TRUE; - break; - case XML_ML_SENDER_NAME_ATTR_ID: - if ((*dst_len - len) > 0) /* enough data buffer available? */ - { - p_attr_data = &(p_xud->p_entry[p_xud->current_entry].sender_name) ; - p_attr_len = &(p_xud->p_entry[p_xud->current_entry].sender_name_len); - } - else /* run out of dst buffer resource */ - no_buf_left = TRUE; - break; - case XML_ML_SENDER_ADDRESSING_ATTR_ID : - if ((*dst_len - len) > 0) /* enough data buffer available? */ - { - - p_attr_data = &(p_xud->p_entry[p_xud->current_entry].sender_addressing) ; - p_attr_len = &(p_xud->p_entry[p_xud->current_entry].sender_addressing_len); - } - else /* run out of dst buffer resource */ - no_buf_left = TRUE; - break; - case XML_ML_REPLYTO_ADDRESSING_ATTR_ID : - if ((*dst_len - len) > 0) /* enough data buffer available? */ - { - - p_attr_data = &(p_xud->p_entry[p_xud->current_entry].replyto_addressing) ; - p_attr_len = &(p_xud->p_entry[p_xud->current_entry].replyto_addressing_len); - } - else /* run out of dst buffer resource */ - no_buf_left = TRUE; - break; - case XML_ML_RECIPIENT_NAME_ATTR_ID : - if ((*dst_len - len) > 0) /* enough data buffer available? */ - { - - p_attr_data = &(p_xud->p_entry[p_xud->current_entry].recipient_name) ; - p_attr_len = &(p_xud->p_entry[p_xud->current_entry].recipient_name_len); - } - else /* run out of dst buffer resource */ - no_buf_left = TRUE; - break; - case XML_ML_RECIPIENT_ADDRESSING_ATTR_ID: - if ((*dst_len - len) > 0) /* enough data buffer available? */ - { - - p_attr_data = &(p_xud->p_entry[p_xud->current_entry].recipient_addressing) ; - p_attr_len = &(p_xud->p_entry[p_xud->current_entry].recipient_addressing_len); - } - else /* run out of dst buffer resource */ - no_buf_left = TRUE; - break; - case XML_ML_TYPE_ATTR_ID : - if ((*dst_len - len) > 0) /* enough data buffer available? */ - { - - p_attr_data = &(p_xud->p_entry[p_xud->current_entry].type) ; - p_attr_len = &(p_xud->p_entry[p_xud->current_entry].type_len); - } - else /* run out of dst buffer resource */ - no_buf_left = TRUE; - break; - - case XML_ML_SIZE_ATTR_ID : - if ((*dst_len - len) > 0) /* enough data buffer available? */ - { - - p_attr_data = &(p_xud->p_entry[p_xud->current_entry].org_msg_size) ; - p_attr_len = &(p_xud->p_entry[p_xud->current_entry].org_msg_size_len); - } - else /* run out of dst buffer resource */ - no_buf_left = TRUE; - break; - case XML_ML_TEXT_ATTR_ID: - if ((*dst_len - len) > 0) /* enough data buffer available? */ - { - - p_attr_data = &(p_xud->p_entry[p_xud->current_entry].text) ; - p_attr_len = &(p_xud->p_entry[p_xud->current_entry].text_len); - } - else /* run out of dst buffer resource */ - no_buf_left = TRUE; - break; - case XML_ML_RECEPTION_STATUS_ATTR_ID: - if ((*dst_len - len) > 0) /* enough data buffer available? */ - { - - p_attr_data = &(p_xud->p_entry[p_xud->current_entry].reception_status) ; - p_attr_len = &(p_xud->p_entry[p_xud->current_entry].reception_status_len); - } - else /* run out of dst buffer resource */ - no_buf_left = TRUE; - break; - case XML_ML_ATTACHMENT_SIZE_ATTR_ID : - if ((*dst_len - len) > 0) /* enough data buffer available? */ - { - - p_attr_data = &(p_xud->p_entry[p_xud->current_entry].attachment_size) ; - p_attr_len = &(p_xud->p_entry[p_xud->current_entry].attachment_size_len); - } - else /* run out of dst buffer resource */ - no_buf_left = TRUE; - break; - case XML_ML_PRIORITY_ATTR_ID : - if ((*dst_len - len) > 0) /* enough data buffer available? */ - { - - p_attr_data = &(p_xud->p_entry[p_xud->current_entry].priority_status) ; - p_attr_len = &(p_xud->p_entry[p_xud->current_entry].priority_status_len); - } - else /* run out of dst buffer resource */ - no_buf_left = TRUE; - break; - case XML_ML_READ_ATTR_ID : - if ((*dst_len - len) > 0) /* enough data buffer available? */ - { - - p_attr_data = &(p_xud->p_entry[p_xud->current_entry].read) ; - p_attr_len = &(p_xud->p_entry[p_xud->current_entry].read_len); - } - else /* run out of dst buffer resource */ - no_buf_left = TRUE; - break; - case XML_ML_SENT_ATTR_ID : - if ((*dst_len - len) > 0) /* enough data buffer available? */ - { - - p_attr_data = &(p_xud->p_entry[p_xud->current_entry].sent) ; - p_attr_len = &(p_xud->p_entry[p_xud->current_entry].sent_len); - } - else /* run out of dst buffer resource */ - no_buf_left = TRUE; - break; - case XML_ML_PROTECTED_ATTR_ID : - if ((*dst_len - len) > 0) /* enough data buffer available? */ - { - p_attr_data = &(p_xud->p_entry[p_xud->current_entry].is_protected) ; - p_attr_len = &(p_xud->p_entry[p_xud->current_entry].is_protected_len); - } - else /* run out of dst buffer resource */ - no_buf_left = TRUE; - break; - - case XML_ML_TAG_END_ID: - /* -------------------- CUSTOMER SPECIFIC ---------------------- */ - p_xud->current_entry++; /* increment only when end tag (/>) found */ - copy_attr_info = FALSE; - XML_TRACE_DEBUG1("[xml ml]: current_entry cnt=%d",p_xud->current_entry); - break; - /* case XML_VERSION_ATTR_ID: */ - default: - copy_attr_info = FALSE; - XML_TRACE_DEBUG1("[xml ml] unknown attrib: %d", cur_prop->name ); - break; - } - - if (copy_attr_info && p_attr_data && p_attr_len) - { - *p_attr_data = p_cur_offset; - *p_attr_len = len; - - memcpy( (void *)*p_attr_data, - (const void *)cur_prop->p_data, - len ); - (*p_attr_data)[len] = 0; /* null terminate string */ - p_cur_offset += (len + 1); - *dst_len = *dst_len - (len + 1) ; - - #if (defined(ML_DEBUG_XML) && ML_DEBUG_XML == TRUE) - - XML_TRACE_DEBUG5("[xml ml]: Attr ID=%d val=[%s] len=%d level=%d dst_len_left=%d", - cur_prop->name, - *p_attr_data, - *p_attr_len, - cur_prop->level, - *dst_len); - #endif - } - - if (no_buf_left) - { - #if (defined(ML_DEBUG_XML) && ML_DEBUG_XML == TRUE) - XML_TRACE_DEBUG0("Error!! No more buffer left to store the parser outputs"); - #endif - return -1; - } - - } -#if (ML_DEBUG_XML == TRUE) - XML_TRACE_DEBUG2("[xml ml] fill_ml: end:%d, xx:%d", end, xx); -#endif -#if 0 - /* if end tag not found -> split over two buffers. but parser will still show rest of - found properties. so return still found properties. */ - if (end == FALSE) - xx = 0; -#endif - - /* keep track of current data buffer offset */ - *p_dst_data = p_cur_offset; - return xx; -} /* xml_ml_int_fill_msg_list() */ - - -/********************************************************************************** -** Function xml_ml_int_fill_evt_data -** -** Description fill in MAP event report structure. -** -** Parameters -** Returns -**********************************************************************************/ -static tXML_ML_RES xml_ml_int_fill_evt_data( UINT8 op, - void *p_evt_data, - tXML_PROP **p_prop, - UINT16 *num_prop, - UINT8 **p_dst_data, - UINT16 *dst_len) -{ - tXML_ML_STATE *p_xud = (tXML_ML_STATE *)p_evt_data; - INT16 inc_prop; - UINT8 prop_name; /* Property name. */ - tXML_PROP *cur_prop = *p_prop; - UINT8 *p_cur_offset = *p_dst_data; - - tXML_ML_RES x_res = XML_ML_OK; - BOOLEAN x_no_res = FALSE; /* guard dest buffer resource */ - - if ( op == 0 || op > XML_ML_MAX_OBJ_TAG_ID || *num_prop == 0) - return XML_ML_ERROR; - -#if ML_DEBUG_XML - XML_TRACE_DEBUG2( "[xml ml] xml_ml_int_fill_evt_data op:%d, num_prop:%d", - op, *num_prop); -#endif - - - - while ( *num_prop > 0 && !x_no_res ) - { -#if (defined(ML_DEBUG_XML) && ML_DEBUG_XML == TRUE) - XML_TRACE_DEBUG2("end_prop:%d, name id: x%x", *num_prop, cur_prop->name); -#endif - prop_name = cur_prop->name; - cur_prop++; - *num_prop -= 1; - - - switch ( prop_name ) - { - case XML_ML_ELEM_ID: - XML_TRACE_DEBUG0("[xml ml] xml_etag_elem"); - /* skip over version attribute which should always be 1.0. this is the top level */ - break; - - case XML_ML_MSG_ELEM_ID: - XML_TRACE_DEBUG0("[xml ml] xml_etag_elem"); - inc_prop = xml_ml_int_fill_msg_list( p_xud, - cur_prop, - num_prop, - &p_cur_offset, - dst_len); - if (inc_prop == -1) /* no dst_buf available */ - { - /* backup one more prop to obtain the skipped ml/file entry header */ - cur_prop --; - *num_prop += 1; - - x_res = XML_ML_DST_NO_RES; - x_no_res = TRUE; - } - else if (inc_prop == -2) /* exceed max entry */ - { - x_no_res = TRUE; - x_res = XML_ML_OUT_FULL; - } - else /* found ml entry */ - { - cur_prop += inc_prop; - *num_prop -= inc_prop; - } - break; - - case XML_ML_PAUSE_ID: -#if (ML_DEBUG_XML==TRUE) - XML_TRACE_DEBUG0( "[xml ml] xml_ml_int_fill_evt_data(): XML_ML_PAUSE_ID" ); -#endif - break; - - case XML_ML_TAG_END_ID: -#if (ML_DEBUG_XML==TRUE) - XML_TRACE_DEBUG0( "[xml ml] xml_ml_int_fill_evt_data(): XML_ML_TAG_END_ID" ); -#endif - break; - - default: - XML_TRACE_DEBUG1( "[xml ml] xml_ml_int_fill_evt_data():unknown element: %d", prop_name ); - break; - } - } - - /* keep track of current filling position, and current available dst buffer */ - *p_prop = cur_prop; - *p_dst_data = p_cur_offset; - - return x_res; -} /* xml_ml_int_fill_evt_data() */ - - -/************************************************************************************** -** Function XML_MlInit -** -** Description Initialize xml parser state machine. -** -** Parameters p_xml_state: address of an xml parser state machine to be initialized, -** allocate an additional space of size XML_ML_CARRY_OVER_LEN -** right after *p_xml_state to hold carry over data. -** p_entry : points start of output directory entry. caller needs do -** free this memory -** max_entry : max is 16 bit integer value which is the maximum number -** of ml entries. - -** -** Returns void -**************************************************************************************/ - -void XML_MlInit( tXML_ML_PARSER *p_xml_state, - tXML_ML_ENTRY *p_entry, - const UINT16 max_entry ) -{ - XML_TRACE_DEBUG0("[xml ml] XML_MlInit"); - /* Initialize the generic xml parser state machine.*/ - XML_InitPars( &p_xml_state->xml, xml_ml_cback, &p_xml_state->xml_user_data ); - - /* User need to allocate an additional space of size XML_ML_CARRY_OVER_LEN */ - /* right after *p_xml_state to hold carry over data. */ - /* point to the end of the allocated buffer for p_xml_state, which is the */ - /* beginning of buffer(XML_ML_CARRY_OVER_LEN) */ - p_xml_state->xml.last_bfr.p = (UINT8 *)(p_xml_state + 1); - p_xml_state->xml.last_bfr.len = XML_ML_CARRY_OVER_LEN; - - /* Initialize user data */ - p_xml_state->xml_user_data.p_entry = p_entry; - p_xml_state->xml_user_data.current_entry = 0; - p_xml_state->xml_user_data.max_name_len = XML_UI_ENTRY_MAX_NAME_LEN + 1; - p_xml_state->xml_user_data.max_entry = (UINT16)max_entry; - p_xml_state->xml_user_data.prop_num = 0; -} - - -/************************************************************************************** -** Function XML_MlParse -** -** Description This function is called to parse the xml data received from OBEX -** into folder entries associated with properties value. It can also be -** used as clean up function to delete left over data from previous parse. -** This clean up function is typically used when application runs out of -** resource and decides to discard extra xml data received. -** -** Parameters p_xml_state: pointer to a xml parser initialized by XML_MlInit(). -** xml_data: valid pointer to OBEX list data in xml format. -** xml_len: length of the package, must be non-zero value. -** dst_data: valid pointer to the buffer for holding converted folder entry name. - When dst_data is NULL, clean up all remaining data in the parser. -** dst_len: pointer to the length of dst_data buffer, its carry out value -** is the number of bytes remaining buffer.When dst_len is NULL, -** it will cause to flush the internal data in the parser. -** num_entries: current number of entries, in the end it is the total number of entries -** -** Returns tXML_ML_RES (see xml_erp.h) -** XML_PENDING: parsing not completed -** XML_END_LIST: found /folder-listing but no final flag detected -** XML_ML_OUT_FULL: reached max_entry -> do not call parser anymore!!! dump data -** XML_ML_DST_NO_RES : run out of dst buffer resource while -** some xml data still remains. - -**************************************************************************************/ -tXML_ML_RES XML_MlParse( tXML_ML_PARSER *p_xml_state, - UINT8 *xml_data, UINT16 xml_len, - UINT8 *dst_data, UINT16 *dst_len, - UINT16 *num_entries ) -{ - tXML_OS xos; - BOOLEAN is_remain = TRUE; - tXML_MUL_STATE *p_xml = &p_xml_state->xml; - tXML_ML_STATE *p_st = &p_xml_state->xml_user_data; - tXML_ML_RES x_res = XML_ML_OK; - tXML_RESULT res = XML_NO_PROP; - UINT16 max_num_prop = GKI_BUF3_SIZE/sizeof(tXML_PROP); /* i hope this is sufficient for 1 */ - - -#if (defined(ML_DEBUG_XML) && ML_DEBUG_XML == TRUE) - int xx; - UINT8 dbg_buf[ML_DEBUG_LEN]; - tXML_STR str; -#endif - - XML_TRACE_DEBUG0("[xml ml] XML_MlParse"); - /* if dst_data is NULL, clean up remaining data */ - if (!dst_data || !dst_len) - { - /* clean out remained xml data left over from last parse */ - if (p_xml_state->xml_user_data.p_prop ) - { - GKI_freebuf( p_st->p_prop ); - p_st->p_prop = p_st->offset_prop = NULL; - p_st->prop_num = 0; - } -#if (ML_DEBUG_XML == TRUE) - XML_TRACE_DEBUG0( "[xml ml] XML_MlParse() Clean up left over!"); -#endif - return x_res; - } - - /* if illegal OBEX data or dst buffer pointer received, return ERROR */ - if (xml_len == 0 || !xml_data) - { - return XML_ML_ERROR; - } - - /* XML_MlParse receive new xml data, allocate buffer to hold parsed prop */ - if (p_st->offset_prop == NULL) - { - -#if (ML_DEBUG_XML == TRUE) - XML_TRACE_DEBUG0( "[xml ml] XML_MlParse() Receive New Data!"); - XML_TRACE_DEBUG2( "[xml ml] XML_data start[%x] end [%x]",xml_data, xml_data+xml_len); -#endif - is_remain = FALSE; - if ( NULL!= (p_st->p_prop = (tXML_PROP *)GKI_getbuf( GKI_BUF3_SIZE ) ) ) - { - /* pointing next prop to be converted into file entry */ - p_st->prop_num = 0; - } - else - { - GKI_freebuf( p_xml_state ); - x_res = XML_ML_NO_RES; - return x_res; - } - } -#if (ML_DEBUG_XML == TRUE) - else - { - XML_TRACE_DEBUG0( "[xml ml] XML_MlParse(): Keep cleaning up old xml data !"); - } -#endif - /* update the data address */ - xos.p_begin = xml_data; - xos.p_end = xml_data + xml_len; - - while ( res == XML_NO_PROP ) - { - /* if no remaining data in p_st->p_prop, parse new xml data */ - if (!is_remain) - { - p_st->max_num_prop = max_num_prop; - p_st->prop_index = 0; - res = XML_MulParse( p_xml, &xos ); - - -#if (ML_DEBUG_XML == TRUE) - XML_TRACE_DEBUG4( "xml_ml_parse obj: %x, max: %d, num: %d, res: %d", - p_st->obj, max_num_prop, p_st->prop_index, res); - if (res != 0) - { - XML_TRACE_DEBUG1( "XML_MulParse Parsing: %d !!!", res); - } - - for (xx=0; xx<p_st->prop_index; xx++) - { - if ( p_st->p_prop[xx].name < XML_ML_MAX_ID ) - { - str.p = p_st->p_prop[xx].p_data; - str.len = p_st->p_prop[xx].len; - xml_ml_debug_str(&str, dbg_buf); - XML_TRACE_DEBUG5( "[xml ml] parsed: index[%d]:%d:%s: %s(%d)", p_st->prop_index-xx, p_st->p_prop[xx].level, - xml_ml_ttbl[p_st->p_prop[xx].name].p_name, dbg_buf, p_st->p_prop[xx].len); - } - else - { - XML_TRACE_DEBUG3( "[xml ml] internal prop: %d:%d:%d", xx, p_st->p_prop[xx].level, - p_st->p_prop[xx].name ); - } - } -#endif - p_st->prop_num = p_st->prop_index ; - p_st->offset_prop = p_st->p_prop; - } - else - { - /* This is left over data, pick up the result from the previous parse */ - res = p_xml->pars_res; - } - - if ( res != XML_OBJ_ST_EMPTY ) - { - x_res = xml_ml_int_fill_evt_data( p_st->obj, p_st, &p_st->offset_prop, &p_st->prop_num, &dst_data, dst_len ); - - if ( (XML_ML_OK == x_res) && (XML_NO_END == res) ) - { - /* XML_NO_END means that the xml is not completly finished and fill returns - ok when when partial filling has been ok */ - x_res = XML_ML_PENDING; - } - - /* all parsed xml data has been converted into file entry */ - /* or exceed max entry number , break the parsing loop */ - if (XML_ML_OUT_FULL != x_res && XML_ML_DST_NO_RES != x_res) - { - is_remain = FALSE; - } - else - break; - } - } /* while */ - - /* free property table. at next call a new one is allocated */ - if ((x_res != XML_ML_DST_NO_RES && p_st->p_prop) || - XML_ML_OUT_FULL == x_res) - { - GKI_freebuf( p_st->p_prop ); - p_st->p_prop = NULL; - p_st->offset_prop = NULL; - } - - if ( x_res != XML_ML_DST_NO_RES && p_st->ended) - { - /* this should happen on the same time as final flag in fact */ - x_res = XML_ML_END_LIST; /* found closing /ml-listing */ - } - - *num_entries = p_st->current_entry; /* report number of entries found. only when ended is true - application really should be interested! */ - return x_res; -} - diff --git a/stack/xml/xml_parse.c b/stack/xml/xml_parse.c deleted file mode 100644 index 3f9e2e1..0000000 --- a/stack/xml/xml_parse.c +++ /dev/null @@ -1,1502 +0,0 @@ -/***************************************************************************** -** -** Name: xml_parse.c -** -** File: XML Parser -** -** Copyright (c) 2000-2011, Broadcom Corp., All Rights Reserved. -** Broadcom Bluetooth Core. Proprietary and confidential. -** -*****************************************************************************/ -#include "bt_target.h" -#include "xml_pars_api.h" -#include "data_types.h" -#include "bt_types.h" -/* The XML Parser is dependent on the Object Store. At present -** the object store resides in GOEP and hence the parser is -** dependent on GOEP. The parser only uses the Object Store -** in GOEP, so if the Object Store is separated from GOEP in the -** future, the parser will not be dependent on GOEP. -*/ - -#include <stdlib.h> -#include <string.h> - -#ifndef BIP_TRACE_XML -#define BIP_TRACE_XML FALSE -#endif - -#if (defined(BIP_TRACE_XML) && BIP_TRACE_XML == TRUE) -#define XML_TRACE_DEBUG0(m) {BT_TRACE_0(TRACE_LAYER_GOEP, TRACE_TYPE_DEBUG, m);} -#define XML_TRACE_DEBUG1(m,p1) {BT_TRACE_1(TRACE_LAYER_GOEP, TRACE_TYPE_DEBUG, m,p1);} -#define XML_TRACE_DEBUG2(m,p1,p2) {BT_TRACE_2(TRACE_LAYER_GOEP, TRACE_TYPE_DEBUG, m,p1,p2);} -#define XML_TRACE_DEBUG3(m,p1,p2,p3) {BT_TRACE_3(TRACE_LAYER_GOEP, TRACE_TYPE_DEBUG, m,p1,p2,p3);} -#define XML_TRACE_DEBUG4(m,p1,p2,p3,p4) {BT_TRACE_4(TRACE_LAYER_GOEP, TRACE_TYPE_DEBUG, m,p1,p2,p3,p4);} -#define XML_TRACE_DEBUG5(m,p1,p2,p3,p4,p5) {BT_TRACE_5(TRACE_LAYER_GOEP, TRACE_TYPE_DEBUG, m,p1,p2,p3,p4,p5);} -#define XML_TRACE_DEBUG6(m,p1,p2,p3,p4,p5,p6) {BT_TRACE_6(TRACE_LAYER_GOEP, TRACE_TYPE_DEBUG, m,p1,p2,p3,p4,p5,p6);} -#else -#define XML_TRACE_DEBUG0(m) -#define XML_TRACE_DEBUG1(m,p1) -#define XML_TRACE_DEBUG2(m,p1,p2) -#define XML_TRACE_DEBUG3(m,p1,p2,p3) -#define XML_TRACE_DEBUG4(m,p1,p2,p3,p4) -#define XML_TRACE_DEBUG5(m,p1,p2,p3,p4,p5) -#define XML_TRACE_DEBUG6(m,p1,p2,p3,p4,p5,p6) -#endif - -/***************************************************************************** -** Constants -*****************************************************************************/ - -#define XML_ST '<' -#define XML_GT '>' -#define XML_QM '?' -#define XML_EX '!' -#define XML_EM '/' /* End Mark */ -#define XML_CO ':' -#define XML_EQ '=' -#define XML_SQ '\'' -#define XML_DQ '"' -#define XML_AM '&' -#define XML_SC ';' -#define XML_PD '#' -#define XML_HX 'x' -#define XML_HY '-' -#define XML_LB '[' - -#define XML_LT_STR "lt" -#define XML_GT_STR "gt" -#define XML_AMP_STR "amp" -#define XML_APOS_STR "apos" -#define XML_QUOT_STR "quot" - -#define XML_QTAG_END_STR "?>" -#define XML_COMM_STR "--" -#define XML_COMM_END_STR "-->" -#define XML_CDS_STR "[CDATA[" -#define XML_CDS_END_STR "]]>" -#define XML_DOCT_STR "<'\"" - -static const UINT8 xml_name_srch[] = ":=/> \t\n\r"; - - -/***************************************************************************** -** Type Definitions -*****************************************************************************/ - -enum -{ - XML_PASS_WS, - XML_SKIP_WS, - XML_NORM_WS -}; -typedef UINT16 tXML_WS_OP; - - - -/***************************************************************************** -** Globals -** -** The global below is used as the buffer set (tXML_BFR_SET) in a local -** variable (of type tXML_MUL_STATE) in XML_Parse. The buffer set memory, is -** separated from the rest of tXML_MUL_STATE to make it easy to change the -** allocation of its memory if found necessary. See xml_alloc_bfr_set. -*****************************************************************************/ - -/***************************************************************************** -** Macro Functions -*****************************************************************************/ - -#define XML_EOS(p_st) ((p_st)->curr_res <= 0) /* End Of Store */ -/* white space: " ", \t, \r, \n */ -#define XML_IS_WS(c) (((c) == 0x20) || ((c) == 0x9) || \ - ((c) == 0xD) || ((c) == 0xA) || \ - ((c) == 0x00) ) - - -/***************************************************************************** -** Function Prototypes -*****************************************************************************/ - -static BOOLEAN xml_get_next(tXML_MUL_STATE *, tXML_WS_OP); - -static BOOLEAN xml_find_ch(tXML_MUL_STATE *, UINT8, tXML_WS_OP); - -static void xml_incr_pars_res(tXML_MUL_STATE *, tXML_RESULT); - -static void xml_set_bfr(tXML_MUL_STATE *, UINT8); - -/* parsing static functions */ - -static BOOLEAN xml_elems(tXML_MUL_STATE *, BOOLEAN); - -static BOOLEAN xml_qm_elem(tXML_MUL_STATE *); - -static BOOLEAN xml_ex_elem(tXML_MUL_STATE *, BOOLEAN); - -static BOOLEAN xml_tag_elem(tXML_MUL_STATE *); - -static BOOLEAN xml_etag_elem(tXML_MUL_STATE *); - -#define XML_SET_CLEAR 0 -#define XML_SET_NAME 1 -#define XML_SET_VALUE 2 - - - - -/***************************************************************************** -** API Functions -*****************************************************************************/ - -void XML_InitPars(tXML_MUL_STATE *p_st, tXML_CBACK xml_cback, void *p_usr_data) -{ - memset(p_st, 0, sizeof(tXML_MUL_STATE)); - p_st->cback = xml_cback; - p_st->p_usr_data = p_usr_data; - - /* by memset() - p_st->p_data_bfr = NULL; - p_st->next_token = 0; - p_st->curr_res = 0; - p_st->pars_res = XML_SUCCESS; - p_st->skip_next_nl = FALSE; - - p_st->prefix.p = NULL; - p_st->name.p = NULL; - p_st->value.p = NULL; - p_st->prefix.len= 0; - p_st->name.len = 0; - p_st->value.len = 0; - - p_st->status = XML_STS_INIT; - */ -} - - - -/***************************************************************************** -** -** Function XML_MulParse -** -** Description -** The current implementation of the xml_pars_api supports only those -** XML-contructs needed in BPP SOAP-messages. The parser must have a -** small footprint and is therefore small and simple. -** -** According to SOAP a message must not contain the doctypedecl construct -** (production) and it must not contain Processing Instructions (PI -** production), i.e. these constructs are not supported. In addition, -** CDATA sections, any external or internal entities and the XML -** Declaration are not supported (not used in BPP). Should any of these -** be included in a message being parsed, they will be reported returning -** a warning code. The parser will then try to find the next tag. -** When the parser reports an XML-event using the callback it will always -** continue, even if the callback returns false. All strings in event -** data passed with the callback are limited to 64 bytes in size, except -** the prefix string which has 32 as max size. Consequtive XML_CHARDATA -** events are not supported. Leading and trailing white space is removed -** from the value string before sending the XML_CHARDATA event. -** -** This function and also all other helping static parsing functions use -** more than one return statement in a function. The reason is that -** a parse error has been found and to exit as soon as possible. -** If one had used only one return in each function, the path -** representing a correct xml syntax had been expressed with very deeply -** nested if-statements. -** -** Parameters -** see h-file -** Returns -** see h-file -*****************************************************************************/ - -tXML_RESULT XML_MulParse(tXML_MUL_STATE *p_st, tXML_OS *p_os) -{ - BOOLEAN found; - BOOLEAN query, partial = FALSE; - BOOLEAN parse_ok = TRUE; - int keep_size; - tXML_RESULT res = XML_SUCCESS; - tXML_RESULT old_pars_res; - - p_st->curr_res = 1; /* not EOS */ - memcpy(&p_st->xml_os, p_os, sizeof(tXML_OS)); - old_pars_res = p_st->pars_res; - p_st->pars_res = XML_SUCCESS; - p_st->prefix.len = 0; - p_st->name.len = 0; - p_st->value.len = 0; - p_st->p_last_stm = 0; - p_st->p_copy = 0; - -#if ((defined (BIP_TRACE_XML) && BIP_TRACE_XML == TRUE) || (defined FOLDER_DEBUG_XML && FOLDER_DEBUG_XML== TRUE)) - XML_TRACE_DEBUG4("XML_MulParse status:%d, pars_res: %d, begin:%x, end:x%x", - p_st->status, old_pars_res, p_os->p_begin, p_os->p_end); -#endif - - /* this do-while(0) loop is to avoid too many return statements in this routine. - * it's easier to "cleanup" with only one return statement */ - if(p_st->status == XML_STS_INIT) - { - - p_st->p_cur = p_os->p_begin; -#if ((defined (BIP_TRACE_XML) && BIP_TRACE_XML == TRUE) || (defined FOLDER_DEBUG_XML && FOLDER_DEBUG_XML== TRUE)) - XML_TRACE_DEBUG1("p_cur:x%x", p_st->p_cur); -#endif - do - { - if (!xml_get_next(p_st, XML_PASS_WS)) /* obj store empty or err */ - { - res = XML_OBJ_ST_EMPTY; - break; - } - - found = FALSE; - while (!XML_EOS(p_st) && !found) - { /* skip all but top element */ - if (!xml_find_ch(p_st, XML_ST, XML_PASS_WS) || - !xml_get_next(p_st, XML_PASS_WS)) - { - res = XML_ERR; - break; - } - - if (p_st->next_token == XML_QM) - { - parse_ok = xml_qm_elem(p_st); - } - else if (p_st->next_token == XML_EX) - { - parse_ok = xml_ex_elem(p_st, TRUE); - } - else if (p_st->next_token == XML_EM) - { - parse_ok = FALSE; - if (!xml_get_next(p_st, XML_PASS_WS)) - { - res = XML_ERR; - break; - } - } - else - { - found = TRUE; - parse_ok = TRUE; - } - - if (!parse_ok) - xml_incr_pars_res(p_st, XML_ERR); - } - } while (0); - p_st->status = XML_STS_1STM; - } - else if(old_pars_res == XML_NO_PROP) - { - } - else - { -#if ((defined (BIP_TRACE_XML) && BIP_TRACE_XML == TRUE) || (defined FOLDER_DEBUG_XML && FOLDER_DEBUG_XML== TRUE)) - XML_TRACE_DEBUG2("p_st->last_bfr.p:x%x, p_st->used_last_bfr:%d", - p_st->last_bfr.p, p_st->used_last_bfr); -#endif - -/* if there was some data left, read it here. */ - if(p_st->partial_st.last_bfr.p && p_st->partial_st.used_last_bfr ) - { - memcpy(p_st->last_bfr.p, p_st->partial_st.last_bfr.p, p_st->partial_st.used_last_bfr); - p_st->used_last_bfr = p_st->partial_st.used_last_bfr; - p_st->last_bfr.p[p_st->partial_st.used_last_bfr] = 0; - p_st->event_data.part.parse = p_st->partial_st.event_data.part.parse; - - /* set length to 0 */ - p_st->partial_st.used_last_bfr = 0; - XML_TRACE_DEBUG1("retrieved PARTIAL data = [%s]\n", p_st->last_bfr.p); - - p_st->p_cur = p_st->last_bfr.p; - /* continuation packet */ - /* read a ch, setup xml_set_bfr */ - xml_get_next(p_st, XML_PASS_WS); - p_st->event_data.copy.p_begin = p_st->xml_os.p_begin; - p_st->event_data.copy.last.p = p_st->last_bfr.p; - p_st->event_data.copy.last.len = p_st->used_last_bfr; - p_st->cback(XML_COPY, &(p_st->event_data), p_st->p_usr_data); - } - else - { - if(p_st->used_last_bfr == 0) - { - p_st->p_cur = p_os->p_begin; - xml_get_next(p_st, XML_PASS_WS); - } - else - return XML_NO_MEM; - } -#if ((defined (BIP_TRACE_XML) && BIP_TRACE_XML == TRUE) || (defined FOLDER_DEBUG_XML && FOLDER_DEBUG_XML== TRUE)) - XML_TRACE_DEBUG1("p_st->p_cur:x%x", p_st->p_cur); -#endif - } - - XML_TRACE_DEBUG0("XML_MulParse end while"); - - if(res == XML_SUCCESS) - { - /* here we found "<(a-z)" */ - if (!XML_EOS(p_st)) - { - if(p_st->status == XML_STS_1STM) - { - /* remeber the beginning position right after '<' in the first line */ - /* if the first line can't be parsed at first round, save it to the second parse */ - p_st->p_copy = p_st->p_cur - 1; - parse_ok = xml_tag_elem(p_st); - } - - /* parsed the first line */ - XML_TRACE_DEBUG0("XML_MulParse exit xml_tag_elem"); - - if (!parse_ok) - { - query = p_st->cback(XML_QUERY, &(p_st->event_data), p_st->p_usr_data); - - /* if first line parsing is not completed while reach the end of stack, ERROR occurs */ - if (query == TRUE) - xml_incr_pars_res(p_st, XML_ERR); - else /* first line parsing to be continued, copy partial data at later point*/ - partial = TRUE; - } - else /* first line is parsed ok, change parsing status */ - p_st->status = XML_STS_1TAG; - - - - if (!XML_EOS(p_st) && parse_ok) - { - parse_ok = xml_elems(p_st, parse_ok); - query = p_st->cback(XML_QUERY, &(p_st->event_data), p_st->p_usr_data); - if (parse_ok == FALSE || query == FALSE) - { - partial = TRUE; - - } - else - p_st->status = XML_STS_DONE; - } - - /* copy partial data if any */ - if (partial) - { - if(p_st->pars_res == XML_NO_PROP) - { - p_st->p_cur = p_st->p_copy; - p_st->event_data.part.parse = p_st->pars_res; - p_st->event_data.part.p_keep = p_st->p_cur; - XML_TRACE_DEBUG1("p_st->p_cur:x%x (last_stm)", p_st->p_cur); - p_st->cback(XML_PARTIAL, &(p_st->event_data), p_st->p_usr_data); - xml_incr_pars_res(p_st, XML_NO_END); - } - else - { - if( p_st->last_bfr.p && - (p_st->p_copy > p_st->xml_os.p_begin) && - (p_st->p_copy < p_st->xml_os.p_end) ) - { - keep_size = p_st->xml_os.p_end - p_st->p_copy; - if(keep_size < p_st->last_bfr.len) - { - /* store the partial data to a temporary buffer, - NOT to the queue of buffers as it would overwrite current ones! */ - if(p_st->partial_st.last_bfr.p ) - { - XML_TRACE_DEBUG0("Store partial data\n"); - BCM_STRNCPY_S((char *)p_st->partial_st.last_bfr.p, 512, (char *)p_st->p_copy, keep_size); - p_st->partial_st.used_last_bfr= keep_size; - p_st->partial_st.last_bfr.p[keep_size] = 0; - p_st->partial_st.event_data.part.parse = p_st->pars_res; - p_st->partial_st.event_data.part.p_keep= p_st->last_bfr.p; - } - else - XML_TRACE_DEBUG0("ERROR to store partial data"); - - p_st->cback(XML_PARTIAL, &(p_st->event_data), p_st->p_usr_data); - xml_incr_pars_res(p_st, XML_NO_END); - } - } - }/* else NO_PROP */ - } /* end of partial */ - } /* end of !XML_EOS(p_st) */ - } /* end of res == XML_SUCCESS */ - - - return p_st->pars_res; -} - - -/***************************************************************************** -** Static Functions -*****************************************************************************/ - - - -/***************************************************************************** -** -** Function xml_set_bfr -** -** Description -** Sets the buffer that is going to be used when tokens are pushed from -** p_st->next_token into some buffer in the buffer set. -** -** Parameters -** p_st (in/out) : the parser state -** p_bfr (in) : the buffer that will get all tokens (characters) -** NULL is allowed in which case no buffer is used. -** bfr_max_ind (in) : the max index into the buffer in which a non-null -** char may be stored -** -** Returns -** - -*****************************************************************************/ -static void xml_set_bfr(tXML_MUL_STATE *p_st, UINT8 set) -{ - switch(set) - { - case XML_SET_NAME: - p_st->name.p = p_st->p_cur - 1; - p_st->p_data_bfr = p_st->name.p; - p_st->name.len = 0; - break; - case XML_SET_VALUE: - p_st->value.p = p_st->p_cur - 1; - p_st->p_data_bfr = p_st->value.p; - p_st->value.len = 0; - break; - default: - p_st->p_data_bfr = NULL; - } -} - - -/***************************************************************************** -** -** Function xml_write_bfr -** -** Description -** Pushes (copies) the character from p_st->next_token to the buffer, if -** any, that has been set calling xml_set_bfr. -** -** Parameters -** p_st (in/out) : the parser state -** -** Returns -** - -*****************************************************************************/ - -static void xml_write_bfr(tXML_MUL_STATE *p_st) -{ - if (p_st->p_data_bfr) - { - if(p_st->p_data_bfr == p_st->name.p) - p_st->name.len++; - else - p_st->value.len++; - } -} - - -/***************************************************************************** -** -** Function xml_incr_pars_res -** -** Description -** Sets the final parsing result if the new_res provided has -** higher rank than the current parsing result. -** -** Parameters -** p_st (in/out) : the parser state -** new_res (in) : the new parsing result -** -** Returns -** - -*****************************************************************************/ - -static void xml_incr_pars_res(tXML_MUL_STATE *p_st, tXML_RESULT new_res) -{ - if (new_res > p_st->pars_res) - { - switch(p_st->pars_res) - { - /* preserve these error messages */ - case XML_OBJ_ST_EMPTY: - case XML_NO_MEM: /* no last_bfr.p, and the tXML_MUL_STATE is not in init */ - case XML_NO_PROP: /* run out of tXML_PROP */ - break; - - default: - /* - case XML_SUCCESS: - case XML_WARNING: - case XML_ERR: - */ - p_st->pars_res = new_res; - break; - } - } -} - - -/***************************************************************************** -** -** Function xml_read_char -** -** Description -*****************************************************************************/ -static void xml_read_char(tXML_MUL_STATE *p_st) -{ - BOOLEAN get_new = FALSE; - - if (p_st->p_cur && p_st->p_cur >= p_st->last_bfr.p && p_st->p_cur < (p_st->last_bfr.p + p_st->used_last_bfr)) - { - /* left over from previous parse */ - p_st->next_token = *p_st->p_cur; - if(p_st->next_token == 0) - { - /* leftover is done, use the new one */ - p_st->p_cur = p_st->xml_os.p_begin; - p_st->last_bfr.p[0] = 0; - p_st->used_last_bfr = 0; - get_new = TRUE; - } - else - { - p_st->p_cur++; - p_st->curr_res = 1; - } - } - else - { - if(p_st->p_cur == (p_st->last_bfr.p + p_st->used_last_bfr)) - { - p_st->used_last_bfr = 0; - p_st->p_cur = p_st->xml_os.p_begin; - } - get_new = TRUE; - } - - if(get_new) - { - if(p_st->p_cur && p_st->p_cur < p_st->xml_os.p_end) - { - /* use buffer given to XML_Parse */ - p_st->next_token = *p_st->p_cur; - p_st->p_cur++; - p_st->curr_res = 1; - } - else - p_st->curr_res = 0; - } - - -/* - XML_TRACE_DEBUG4("xml_read_char p_cur: x%x, curr_res:%d, get_new:%d, token:%c", - p_st->p_cur, p_st->curr_res, get_new, p_st->next_token); -*/ -} - -/***************************************************************************** -** -** Function xml_get_next -** -** Description -** Writes the character in p_st->next_token to the current buffer if set. -** Then the next character is read from the Object Store into -** p_st->next_token. The first time get_next is called, the current -** buffer must be NULL, i.e p_st->data_bfr must be NULL. -** -** xml_get_next handles end-of-line as specified in the xml spec. It -** passes, skips or normalises (p.29 in XML spec) white spaces (ws) -** as specified in the ws_op param. Note, the ws_op applies when -** getting one (or many characters) from Object Store into the -** p_st->next_token. It does not apply when pushing the (initial) -** p_st->next_token to the current buffer. -** -** The characters are read one by one from the Object Store. -** Presently this is not anticipated to cause any problems -** regarding reading speed. Should it become a problem in the -** future, a new buffer could be introduced into which a chunk -** of characters could be put, using one Object Store read call. -** The get_next function would then get the next character from -** the new buffer. -** -** Parameters -** p_st (in/out) : the parser state -** ws_op (in) : the requested white space handling. -** -** Returns -** True if a character was successfully read into p_st->next_token. -** False otherwise. -*****************************************************************************/ - -static BOOLEAN xml_get_next(tXML_MUL_STATE *p_st, tXML_WS_OP ws_op) -{ - xml_write_bfr(p_st); - do - { - xml_read_char(p_st); - } while ((ws_op == XML_SKIP_WS) && XML_IS_WS(p_st->next_token) && - !XML_EOS(p_st)); - - - /* handle end-of-line if any after the do-while above */ - - if (!XML_EOS(p_st) && (p_st->next_token == 0xA) && p_st->skip_next_nl) - { /* we have previously found 0xD (cr) and have set the state var - ** p_st->skip_next_nl,see below - */ - xml_read_char(p_st); - } - p_st->skip_next_nl = FALSE; - - if (XML_EOS(p_st)) - { - p_st->next_token = 0; - return FALSE; - } - - if (p_st->next_token == 0xD) - { - p_st->next_token = 0xA; - p_st->skip_next_nl = TRUE; - } - - if ((ws_op == XML_NORM_WS) && - ((p_st->next_token == 0xA) || (p_st->next_token == 0x9))) - { - p_st->next_token = 0x20; - } - - return TRUE; -} - - -/***************************************************************************** -** -** Function xml_find_ch -** -** Description -** Searches for the character given in ch. It starts searching in -** p_st->next_token and if not found it gets characters from the Object -** Store until ch is in p_st->next_token. -** -** Parameters -** p_st (in/out) : the parser state -** ch (in) : the character to search for -** ws_op (in) : the requested white space handling when getting chars -** -** Returns -** True if the character was found. -** False otherwise. -*****************************************************************************/ - -static BOOLEAN xml_find_ch(tXML_MUL_STATE *p_st, UINT8 ch, tXML_WS_OP ws_op) -{ - while (!XML_EOS(p_st) && (p_st->next_token != ch)) - xml_get_next(p_st, ws_op); - return (BOOLEAN) !XML_EOS(p_st); -} - - -/***************************************************************************** -** -** Function xml_find_ch_n -** -** Description -** Same function as xml_find_ch, except that any character in p_str -** that is found will stop the search. -** -** Parameters -** p_st (in/out) : the parser state -** p_str (in) : the string containing the characters searched for. -** Must not be NULL or an empty string. -** -** Returns -** True if any of the characters in p_str was found. -** Fase otherwise. -*****************************************************************************/ - -static BOOLEAN xml_find_ch_n(tXML_MUL_STATE *p_st, const UINT8 *p_str) -{ - const UINT8 *p_tmp; - - while (!XML_EOS(p_st)) - { - for (p_tmp = p_str; *p_tmp; p_tmp++) - { - if (p_st->next_token == *p_tmp) - return TRUE; - } - xml_get_next(p_st, XML_PASS_WS); - } - return FALSE; -} - - -/***************************************************************************** -** -** Function xml_find_str -** -** Description -** Searches for p_str (i.e the exact sequence of characters in p_str) in -** the input from Object Store. The function ends with the character -** succeeding p_str in the input, (i.e that char is in p_st->next_token -** upon return) or with XML_EOS. -** -** Parameters -** p_st (in/out) : the parser state -** p_str (in) : the string to search for and pass by. -** Must not be NULL or an empty string. -** -** Returns -** True if the string was found. -** False otherwise. -*****************************************************************************/ - -static BOOLEAN xml_find_str(tXML_MUL_STATE *p_st, const UINT8 *p_str) -{ - const UINT8 *p_tmp; - - p_tmp = p_str; - while (*p_tmp && !XML_EOS(p_st)) - { - for (p_tmp = p_str; *p_tmp && !XML_EOS(p_st); p_tmp++) - { - if (p_st->next_token != *p_tmp) - break; - xml_get_next(p_st, XML_PASS_WS); - } - - if ((p_tmp == p_str) && !XML_EOS(p_st)) - { - xml_get_next(p_st, XML_PASS_WS); - } - } - - return (BOOLEAN) (*p_tmp == 0); -} - - -/***************************************************************************** -** -** Function xml_consume_str -** -** Description -** Checks for p_str i.e that the first character from p_str is in -** p_st->next_token and that the successors immediately follows in the -** Object Store. The p_str must not be last in the Object Store. -** -** Parameters -** p_st (in/out) : the parser state -** p_str (in) : the string to check if present next and to pass by -** Must not be NULL. -** -** Returns -** True if the string was found and was not last in the Object Store. -** False otherwise. -*****************************************************************************/ - -static BOOLEAN xml_consume_str(tXML_MUL_STATE *p_st, const UINT8 *p_str) -{ - do - { - if (p_st->next_token != *p_str) - return FALSE; - p_str++; - if (!xml_get_next(p_st, XML_PASS_WS)) - return FALSE; - } while (*p_str); - return TRUE; -} - - -/***************************************************************************** -** -** Function xml_resolve_refs -** -** Description -** Resolves predefined entity references (sect. 4.6 in the XML spec) -** and character references (sect 4.1) that may be found in -** AttValue and content. (According to the XML spec it may also -** be in an EntityValue. However EntityValues are in the -** doctypedecl part which is not supported). -** -** The AttValue and content not beginning with a tag, must be -** stored in the p_st->p_bfr_set->value buffer. -** -** Parameters -** p_st (in/out) : the parser state -** -** Returns -** - -*****************************************************************************/ - -static void xml_resolve_refs(tXML_MUL_STATE *p_st) -{ - UINT8 *p_srch; /* where next search for & starts */ - UINT8 *p_am; /* points to found & */ - UINT8 *p_sc; /* points to found ; and succeeding chars */ - UINT8 *p_start; - UINT8 *p_tmp; - UINT32 ch_code; - UINT32 tmp_code; - INT8 i; - BOOLEAN resolved; - UINT16 len_left; - - p_srch = p_st->value.p; - len_left = p_st->value.len; - do - { - p_start = p_srch; - p_am = (UINT8*) strchr((char*) p_srch, XML_AM); - p_sc = p_am ? (UINT8*) strchr((char*) p_am, XML_SC) : NULL; - /* make sure the ptr does not exceed the end of the value str */ - if(p_sc > (len_left + p_start)) - p_sc = NULL; - - if (p_am && p_sc) - { - resolved = FALSE; - p_tmp = p_am + 1; - *p_sc = 0; /* terminate the ref by replacing ; with 0 */ - if (*p_tmp == XML_PD) /* character ref */ - { - if (p_tmp[1] == XML_HX) - *p_tmp = '0'; - else - { - for(p_tmp++; *p_tmp == '0'; p_tmp++) - { - ; - } - } - - ch_code = strtoul((char*) p_tmp, NULL, 0); - /* skip leading zero bytes */ - for (i = 3; (i >= 0) && !(ch_code >> i * 8); i--) - { - ; - } - p_tmp = p_am; - while (i >= 0) - { - /* mask out one byte and shift it rightmost */ - /* preceding bytes must be zero so shift left first */ - tmp_code = ch_code << ((3-i) * 8); - *p_tmp = (UINT8) (tmp_code >> 24); - p_tmp++; - i--; - } - resolved = TRUE; - } - else if (p_tmp < p_sc) /* check if predefined ref */ - { - resolved = TRUE; - if (strcmp((char*) p_tmp, XML_LT_STR) == 0) - { - *p_am = XML_ST; - p_st->value.len = p_st->value.len - 3; /* remove the length for lt; */ - p_st->p_cur = p_st->p_cur - 3; - } - else if (strcmp((char*) p_tmp, XML_GT_STR) == 0) - { - *p_am = XML_GT; - p_st->value.len = p_st->value.len - 3; /* remove the length for gt; */ - p_st->p_cur = p_st->p_cur - 3; - } - else if (strcmp((char*) p_tmp, XML_AMP_STR) == 0) - { - *p_am = XML_AM; - p_st->value.len = p_st->value.len - 4; /* remove the length for amp; */ - p_st->p_cur = p_st->p_cur - 4; - } - else if (strcmp((char*) p_tmp, XML_APOS_STR) == 0) - { - *p_am = XML_SQ; - p_st->value.len = p_st->value.len - 5; /* remove the length for apos; */ - p_st->p_cur = p_st->p_cur - 5; - } - else if (strcmp((char*) p_tmp, XML_QUOT_STR) == 0) - { - *p_am = XML_DQ; - p_st->value.len = p_st->value.len - 5; /* remove the length for quot; */ - p_st->p_cur = p_st->p_cur - 5; - } - else - resolved = FALSE; - } - - if (resolved) - { - p_srch = p_tmp; /* will contain char after ; */ - p_sc++; - while(*p_sc) - { - *p_tmp++ = *p_sc++; - } - } - else - { - *p_sc = XML_SC; /* restore the ref end */ - p_srch = p_sc + 1; - } - - } /* end if */ - } while (*p_srch && p_am && p_sc); -} - - -/***************************************************************************** -** -** Function xml_remove_trail_ws -** -** Description -** Removes trailing white space from the p_st->p_data_bfr buffer. -** -** Parameters -** p_st (in/out) : the parser state -** -** Returns -** - -*****************************************************************************/ - -static void xml_remove_trail_ws(tXML_MUL_STATE *p_st) -{ - UINT16 xx; - - if(p_st->value.p) - { - xx = p_st->value.len; - while(xx && XML_IS_WS(p_st->value.p[xx-1])) - xx--; - p_st->value.len = xx; - } - -} - - -/***************************************************************************** -** Parsing Static Functions -*****************************************************************************/ - - -/***************************************************************************** -** -** Function xml_name -** -** Description -** Parses a name and its prefix if any. The prefix and name buffers -** are set. -** The functions ends with either white space, -** XML_EQ, XML_EM or XML_GT in p_st->next_token or with XML_EOS. -** -** Parameters -** p_st (in/out) : the parser state -** -** Returns -** True if no error was found. -** False otherwise. -*****************************************************************************/ - -static BOOLEAN xml_name(tXML_MUL_STATE *p_st) -{ - BOOLEAN found = FALSE; - - p_st->prefix.p = NULL; - p_st->prefix.len = 0; - xml_set_bfr(p_st, XML_SET_NAME); - xml_find_ch_n(p_st, xml_name_srch); - if (!XML_EOS(p_st) && (p_st->next_token == XML_CO)) - { - if (p_st->name.len) - { - found = TRUE; - /* p_st->name.len is string size in name buffer, \0 excl. - */ - p_st->prefix.p = p_st->name.p; - p_st->prefix.len = p_st->name.len; - } - xml_get_next(p_st, XML_PASS_WS); - xml_set_bfr(p_st, XML_SET_NAME); - if (!XML_EOS(p_st)) - { - xml_find_ch_n(p_st, xml_name_srch + 1); - } - } - - found = (BOOLEAN) (found || p_st->name.len); - if(found) - xml_set_bfr(p_st, XML_SET_CLEAR); - return found; -} - - -/***************************************************************************** -** -** Function xml_attributes -** -** Description -** Parses an attribute list. -** The functions ends with the XML_GT or XML_EM char or XML_EOS. -** Error is reported if the attribute list is last in the Object -** Store. -** Sends a XML_ATTRIBUTE event in the user callback for each -** attribute found. -** -** Parameters -** p_st (in/out) : the parser state -** -** Returns -** True if no error was found. -** False otherwise. -*****************************************************************************/ - -static BOOLEAN xml_attributes(tXML_MUL_STATE *p_st) -{ - BOOLEAN cb_ret = TRUE; - UINT8 q_ch; - - XML_TRACE_DEBUG1("[xml_parse] xml_attributes: res= %d", p_st->pars_res); - - while ( cb_ret) - { - /* if this is a white space, then the next character is read from the - Object Store into p_st->next_token */ - if( XML_IS_WS(p_st->next_token) ) - { - if (!xml_get_next(p_st, XML_SKIP_WS)) - return FALSE; - } - - if (p_st->next_token == XML_EQ) - return FALSE; - - if ((p_st->next_token == XML_GT) || (p_st->next_token == XML_EM)) - return TRUE; - if (!xml_name(p_st) || XML_EOS(p_st)) - { - return FALSE; - } - if(XML_IS_WS(p_st->next_token)) - { - if (!xml_get_next(p_st, XML_SKIP_WS)) - return FALSE; - } - - if (p_st->next_token != XML_EQ) - return FALSE; - - if (!xml_get_next(p_st, XML_SKIP_WS)) - return FALSE; - - if ((p_st->next_token != XML_SQ) && (p_st->next_token != XML_DQ)) - return FALSE; - - q_ch = p_st->next_token; - if (!xml_get_next(p_st, XML_PASS_WS)) - return FALSE; - - - xml_set_bfr(p_st, XML_SET_VALUE); - if (!xml_find_ch(p_st, q_ch, XML_NORM_WS)) - { - return FALSE; - } - - xml_set_bfr(p_st, XML_SET_CLEAR); - xml_resolve_refs(p_st); - - p_st->event_data.attr.prefix.p = p_st->prefix.p; - p_st->event_data.attr.prefix.len = p_st->prefix.len; - p_st->event_data.attr.name.p = p_st->name.p; - p_st->event_data.attr.name.len = p_st->name.len; - p_st->event_data.attr.value.p = p_st->value.p; - p_st->event_data.attr.value.len = p_st->value.len; - p_st->value.len = 0; - cb_ret = p_st->cback(XML_ATTRIBUTE, &(p_st->event_data), p_st->p_usr_data); - /* chk cback return */ - if(cb_ret == FALSE) - { - xml_incr_pars_res(p_st, XML_NO_PROP); - return FALSE; - } - - if (!xml_get_next(p_st, XML_PASS_WS)) - return FALSE; - } - - return (BOOLEAN) - ((p_st->next_token == XML_GT) || (p_st->next_token == XML_EM)); -} - - -/***************************************************************************** -** -** Function xml_elems -** -** Description -** Parses all elements with all their content.This function is not a -** one-to-one mapped implementation of one production from the XML spec. -** Instead it uses a simplified iterative (as opposed to recursive) -** approach when parsing both the element and content productions. -** -** When a parsing error is found, this function tries to recover by -** searching for the next element (tag). -** -** When char data is found, the function sends the XML_CHARDATA event in -** the user callback. -** -** Other static functions with production names, start their parsing -** from the first character in their production. They might check -** that the first character (token) in the production matches -** p_st->next_token, alternatively they can just get rid of the first -** char in the production by calling get_next_ch. The exceptions to this -** are the xml_qm_elem, xml_ex_elem, xml_etag_elem and the xml_tag_elem -** functions which starts with the XML_QM, XML_EX, XML_EM and the first -** char in the tag name, respectively. -** -** Parameters -** p_st (in/out) : the parser state -** prev_ok (in) : if parsing done before calling this function was -** ok. If not, the functions starts with recovering. -** -** Returns -** True if parsing was successful possibly with successful recoveries. -** False if an error was found from which recovery failed (XML_EOS). -*****************************************************************************/ - -static BOOLEAN xml_elems(tXML_MUL_STATE *p_st, BOOLEAN prev_ok) -{ - BOOLEAN tag_found; - BOOLEAN cb_ret = TRUE; - - while (!XML_EOS(p_st) && prev_ok) - { - /* remove leading ws even if char data */ - if (XML_IS_WS(p_st->next_token)) - { - if (!xml_get_next(p_st, XML_SKIP_WS)) - return TRUE; - } - - tag_found = (BOOLEAN) (p_st->next_token == XML_ST); - if (!tag_found) - { - xml_set_bfr(p_st, XML_SET_VALUE); - tag_found = xml_find_ch(p_st, XML_ST, XML_PASS_WS); - - xml_remove_trail_ws(p_st); - if (p_st->value.len > 0) - { - xml_resolve_refs(p_st); - p_st->event_data.ch_data.value.p = p_st->value.p; - p_st->event_data.ch_data.value.len = p_st->value.len; - p_st->event_data.ch_data.last = TRUE; - p_st->value.len = 0; - cb_ret = p_st->cback(XML_CHARDATA, &(p_st->event_data), p_st->p_usr_data); - /* chk cback return */ - if(cb_ret == FALSE) - { - xml_incr_pars_res(p_st, XML_NO_PROP); - return FALSE; - } - - } - xml_set_bfr(p_st, XML_SET_CLEAR); - - if (!tag_found) - return prev_ok; - } - else - { - p_st->p_last_stm = p_st->p_cur - 1; - - if (p_st->p_cur) - p_st->p_copy = p_st->p_last_stm; - - p_st->cback(XML_TOP, &(p_st->event_data), p_st->p_usr_data); - } - - /* tag was found */ - if (!xml_get_next(p_st, XML_PASS_WS)) - return FALSE; - - - if (p_st->next_token == XML_QM) - prev_ok = xml_qm_elem(p_st); - else if (p_st->next_token == XML_EX) - { - prev_ok = xml_ex_elem(p_st, FALSE); - } - else if (p_st->next_token == XML_EM) - { - prev_ok = xml_etag_elem(p_st); - } - else - prev_ok = xml_tag_elem(p_st); - - - - if (!prev_ok) - xml_incr_pars_res(p_st, XML_ERR); - } - - XML_TRACE_DEBUG1("xml_elems prev_ok:%d", prev_ok); - return prev_ok; -} - - -/***************************************************************************** -** -** Function xml_qm_elem -** -** Description -** Recognises all productions starting with "<?". That is PI and XML decl. -** These productions are skipped and XML_WARNING is set. -** The function starts with the XML_QM as the first char (is in -** p_st->next_token).It ends with the XML_GT successor (is in -** p_st->next_token) or XML_EOS. -** -** Parameters -** p_st (in/out) : the parser state -** -** Returns -** True if no error was found trying to recognise the start and end of -** the productions. False otherwise. -*****************************************************************************/ - -static BOOLEAN xml_qm_elem(tXML_MUL_STATE *p_st) -{ - if (!xml_get_next(p_st, XML_PASS_WS)) - return FALSE; - if (!xml_find_str(p_st, (UINT8*) XML_QTAG_END_STR)) - return FALSE; - xml_incr_pars_res(p_st, XML_WARNING); - return TRUE; -} - - -/***************************************************************************** -** -** Function xml_ex_elem -** -** Description -** Handles all productions starting with "<!". They are Comments, CDSect -** doctypedecl and markupdecl. All are skipped. However, the inpar -** prolog must be set for the function to try to detect the doctypedecl -** and markupdecl beginning. -** -** The function starts with the XML_EX as the first char. -** The function ends with XML_EOS or the char succeeding XML_GT, -** except for doctypedecl and marcupdecl which ends with the next XM_TAG. -** -** Parameters -** p_st (in/out) : the parser state -** prolog (in) : should be set if in prolog in which case the function -** tries to detect (allows) the beginning of doctypedecl -** and markupdecl. -** Returns -** True if no error was found trying to recognise the start and end of -** the productions. False otherwise. -*****************************************************************************/ - -static BOOLEAN xml_ex_elem(tXML_MUL_STATE *p_st, BOOLEAN prolog) -{ - UINT8 q_ch; - - if (!xml_get_next(p_st, XML_PASS_WS)) - return FALSE; - - if (p_st->next_token == XML_HY) /* comment */ - { - if (!xml_consume_str(p_st, (UINT8*) XML_COMM_STR)) - return FALSE; - - if (!xml_find_str(p_st, (UINT8*) XML_COMM_END_STR)) - return FALSE; - } - else if (p_st->next_token == XML_LB) /* CDSect */ - { - if (!xml_consume_str(p_st, (UINT8*) XML_CDS_STR)) - return FALSE; - - if (!xml_find_str(p_st, (UINT8*) XML_CDS_END_STR)) - return FALSE; - - xml_incr_pars_res(p_st, XML_WARNING); - } - else if (prolog) /* doctypedecl or markupdecl */ - { - do - { - if (!xml_find_ch_n(p_st, (UINT8*) XML_DOCT_STR)) - return FALSE; - - if ((p_st->next_token == XML_SQ) || (p_st->next_token == XML_DQ)) - { - q_ch = p_st->next_token; - if (!xml_get_next(p_st, XML_PASS_WS)) - return FALSE; - - if (!xml_find_ch(p_st, q_ch, XML_PASS_WS)) - return FALSE; - - xml_get_next(p_st, XML_PASS_WS); - } - } while (!XML_EOS(p_st) && (p_st->next_token != XML_ST)); - - xml_incr_pars_res(p_st, XML_WARNING); - } - else /* error */ - { - return FALSE; - } - - return TRUE; -} - - -/***************************************************************************** -** -** Function xml_tag_elem -** -** Description -** Parses a tag element. The function starts with the char succeeding the -** XML_ST char. -** The functions ends with the char succeeding the XML_GT char or -** with XML_EOS. -** Sends the XML_TAG and the XML_TAG_END events in a callback each. -** -** Parameters -** p_st (in/out) : the parser state -** -** Returns -** True if no error was found. -** False otherwise. -*****************************************************************************/ - -static BOOLEAN xml_tag_elem(tXML_MUL_STATE *p_st) -{ - BOOLEAN cb_ret = TRUE; - - if (!xml_name(p_st)) - return FALSE; - - p_st->event_data.tag.prefix.p = p_st->prefix.p; - p_st->event_data.tag.name.p = p_st->name.p; - p_st->event_data.tag.prefix.len = p_st->prefix.len; - p_st->event_data.tag.name.len = p_st->name.len; - p_st->event_data.tag.p_last_stm = p_st->p_last_stm; - cb_ret = p_st->cback(XML_TAG, &(p_st->event_data), p_st->p_usr_data); - if(cb_ret == FALSE) - { - xml_incr_pars_res(p_st, XML_NO_PROP); - return FALSE; - } - - /* chk cback return */ - - if (XML_EOS(p_st)) - return FALSE; - - if (XML_IS_WS(p_st->next_token)) - { - if (!xml_attributes(p_st)) - return FALSE; - } - - p_st->event_data.empty_elem.end = (BOOLEAN) (p_st->next_token == XML_EM); - if (p_st->event_data.empty_elem.end) - { - if (!xml_get_next(p_st, XML_PASS_WS)) - return FALSE; - } - - if (p_st->next_token != XML_GT) - return FALSE; - - xml_get_next(p_st, XML_PASS_WS); - - cb_ret = p_st->cback(XML_TAG_END, &(p_st->event_data), p_st->p_usr_data); - - - if(cb_ret == FALSE) - { - xml_incr_pars_res(p_st, XML_NO_PROP); - return FALSE; - } - - p_st->p_copy = p_st->p_cur - 1; - p_st->cback(XML_TOP, &(p_st->event_data), p_st->p_usr_data); - /* chk cback return */ - - return TRUE; -} - - -/***************************************************************************** -** -** Function xml_etag_elem -** -** Description -** Parses an end tag element. The function starts with the XML_EM char. -** The functions ends with the char succeeding the XML_GT char or -** with XML_EOS. Sends the XML_ETAG event in the user callback. -** -** Parameters -** p_st (in/out) : the parser state -** -** Returns -** True if no error was found. -** False otherwise. -*****************************************************************************/ - -static BOOLEAN xml_etag_elem(tXML_MUL_STATE *p_st) -{ - BOOLEAN cb_ret = TRUE; - - if (!xml_get_next(p_st, XML_PASS_WS)) - return FALSE; - - if (!xml_name(p_st)) - return FALSE; - - p_st->event_data.etag.prefix.p = p_st->prefix.p; - p_st->event_data.etag.name.p = p_st->name.p; - p_st->event_data.etag.name.len = p_st->name.len; - p_st->event_data.etag.prefix.len = p_st->prefix.len; - cb_ret = p_st->cback(XML_ETAG, &(p_st->event_data), p_st->p_usr_data); - if(cb_ret == FALSE) - { - xml_incr_pars_res(p_st, XML_NO_PROP); - return FALSE; - } - - p_st->p_copy = (p_st->prefix.p) ? p_st->prefix.p - 2: p_st->name.p - 2; - p_st->cback(XML_TOP, &(p_st->event_data), p_st->p_usr_data); - - /* chk cback return */ - - if (XML_EOS(p_st)) - return FALSE; - - if (XML_IS_WS(p_st->next_token)) - if (!xml_get_next(p_st, XML_SKIP_WS)) - return FALSE; - - if (p_st->next_token != XML_GT) - return FALSE; - - xml_get_next(p_st, XML_PASS_WS); - - return TRUE; -} - diff --git a/stack/xml/xml_vlist.c b/stack/xml/xml_vlist.c deleted file mode 100644 index 2800c12..0000000 --- a/stack/xml/xml_vlist.c +++ /dev/null @@ -1,873 +0,0 @@ -/****************************************************************************** - ** - ** Name: xml_vlist.c - ** - ** Description: This module contains xml parser of VCard listing - ** - ** Copyright (c) 2004-2011, Broadcom Corporation, All Rights Reserved. - ** Broadcom Bluetooth Core. Proprietary and confidential. - ******************************************************************************/ - -#include "bt_target.h" -#include "gki.h" -#include "xml_vlist_api.h" - -#include <string.h> -#include <stdlib.h> - -#ifndef VLIST_DEBUG_XML -#define VLIST_DEBUG_XML FALSE -#endif -#define VLIST_DEBUG_LEN 50 -#if (defined(VLIST_DEBUG_XML) && VLIST_DEBUG_XML == TRUE) -#define XML_TRACE_DEBUG0(m) {BT_TRACE_0(TRACE_LAYER_FTP, TRACE_TYPE_DEBUG, m);} -#define XML_TRACE_DEBUG1(m,p1) {BT_TRACE_1(TRACE_LAYER_FTP, TRACE_TYPE_DEBUG, m,p1);} -#define XML_TRACE_DEBUG2(m,p1,p2) {BT_TRACE_2(TRACE_LAYER_FTP, TRACE_TYPE_DEBUG, m,p1,p2);} -#define XML_TRACE_DEBUG3(m,p1,p2,p3) {BT_TRACE_3(TRACE_LAYER_FTP, TRACE_TYPE_DEBUG, m,p1,p2,p3);} -#define XML_TRACE_DEBUG4(m,p1,p2,p3,p4) {BT_TRACE_4(TRACE_LAYER_FTP, TRACE_TYPE_DEBUG, m,p1,p2,p3,p4);} -#define XML_TRACE_DEBUG5(m,p1,p2,p3,p4,p5) {BT_TRACE_5(TRACE_LAYER_FTP, TRACE_TYPE_DEBUG, m,p1,p2,p3,p4,p5);} -#define XML_TRACE_DEBUG6(m,p1,p2,p3,p4,p5,p6) {BT_TRACE_6(TRACE_LAYER_FTP, TRACE_TYPE_DEBUG, m,p1,p2,p3,p4,p5,p6);} -#else -#define XML_TRACE_DEBUG0(m) -#define XML_TRACE_DEBUG1(m,p1) -#define XML_TRACE_DEBUG2(m,p1,p2) -#define XML_TRACE_DEBUG3(m,p1,p2,p3) -#define XML_TRACE_DEBUG4(m,p1,p2,p3,p4) -#define XML_TRACE_DEBUG5(m,p1,p2,p3,p4,p5) -#define XML_TRACE_DEBUG6(m,p1,p2,p3,p4,p5,p6) -#endif - - -/***************************************************************************** -** Constants -*****************************************************************************/ -const UINT8 xml_vlist_elem[] = "vCard-listing";/* "vCard-listing" */ -const UINT8 xml_card_elem[] = "card"; /* "card" */ -const UINT8 xml_handle_attr[] = "handle"; /* "handle" */ -const UINT8 xml_vlist_name_attr[] = "name"; /* "name" */ -const UINT8 xml_vlist_version_attr[] = "version"; /* "version" */ -const UINT8 xml_vlist_unknown[] = "unknown"; /* "unknown" */ - - -#define XML_VLIST_ELEM_ID 0x01 -#define XML_CARD_ELEM_ID 0x02 -#define XML_MAX_OBJ_TAG_ID XML_VLIST_ELEM_ID -#define XML_HANDLE_ATTR_ID 0x03 -#define XML_NAME_ATTR_ID 0x04 -#define XML_VERSION_ATTR_ID 0x05 -#define XML_XP_UNKNOWN_ID 0x06 -#define XML_VLIST_MAX_ID 0x07 /* keep in sync with above */ -#define XML_VLIST_TAG_END_ID 0x07 /* closing tag found end=true */ -#define XML_VLIST_PAUSE_ID 0x08 /* closing tag found end=false */ - - -#define XML_VLIST_TTBL_SIZE (XML_VLIST_MAX_ID+1) - -/***************************************************************************** -** Type Definitions -*****************************************************************************/ - -typedef struct -{ - const UINT8 *p_name; - UINT8 len; -} tXML_VLIST_TTBL_ELEM; - -typedef tXML_VLIST_TTBL_ELEM tXML_VLIST_TTBL[]; /* Tag Table */ - - -static const tXML_VLIST_TTBL_ELEM xml_vlist_ttbl[XML_VLIST_TTBL_SIZE] = -{ /* index (VLIST_XP_*_ID) & name */ - {(UINT8*) "", XML_VLIST_MAX_ID-1}, /* \x00 Number of elements in array */ - {xml_vlist_elem, 13}, /* \x01 vcard listing */ - {xml_card_elem, 4}, /* \x02 card */ - {xml_handle_attr, 6}, /* \x03 handle */ - {xml_vlist_name_attr, 4}, /* \x04 name */ - {xml_vlist_version_attr, 7}, /* \x05 version */ - {xml_vlist_unknown, 7}, /* \x06 unknown */ -}; - -#define XML_VLIST_PTBL_SIZE 0x03 -typedef UINT8 * tXML_VLIST_PTBL_ELEM; - -static const tXML_VLIST_PTBL_ELEM xml_vlist_ptbl[XML_VLIST_PTBL_SIZE] = -{ - (UINT8*) "\x01", /* \x00 */ - (UINT8*) "\x05\x02", /* \x01 Vcard Listing */ - (UINT8*) "\x03\x04" /* \x02 Card */ -}; - - -#if (VLIST_DEBUG_XML == TRUE) -void xml_vlist_debug_str(tXML_STR *p_str, UINT8 *p_buf) -{ - int dbg_len; - if ( (p_str == NULL) || (NULL==p_str->p)) - BCM_STRCPY_S( (char *)p_buf, VLIST_DEBUG_LEN, "(NULL)" ); - else - { - dbg_len = p_str->len; - if ( dbg_len >= VLIST_DEBUG_LEN) - dbg_len = VLIST_DEBUG_LEN - 1; - BCM_STRNCPY_S( (char *)p_buf, VLIST_DEBUG_LEN, (char *)p_str->p, dbg_len); - p_buf[dbg_len] = 0; - } -} - -#else -#define xml_vlist_debug_str(p_str, p_buf) -#endif - -/***************************************************************************** - ** Function xml_vlist_proc_tag - ** Description - ** Parameters - - ** Returns - *****************************************************************************/ -static UINT8 xml_vlist_proc_tag( tXML_VLIST_STATE *p_st, tXML_STR *p_name, tXML_STACK *p_stk) -{ - const UINT8 *p_stag; /* sub tag pointer */ - UINT8 curr = p_stk->stack[p_stk->top]; -#if (defined(VLIST_DEBUG_XML) && VLIST_DEBUG_XML == TRUE) - UINT8 dbg_name[VLIST_DEBUG_LEN]; -#endif - - if (curr < XML_VLIST_PTBL_SIZE) - { - /* Iterate over allowed sub-tags for the current tag. */ - for (p_stag = xml_vlist_ptbl[curr]; p_stag && *p_stag ; p_stag++) - { - if (*p_stag >= XML_VLIST_TTBL_SIZE) - continue; - if(p_name->len == xml_vlist_ttbl[*p_stag].len && - strncmp((char *)p_name->p, (char *)xml_vlist_ttbl[*p_stag].p_name, p_name->len) == 0) - { - p_stk->top++; - p_stk->stack[p_stk->top] = *p_stag; - - return *p_stag; - } - } - } - -#if (defined(VLIST_DEBUG_XML) && VLIST_DEBUG_XML == TRUE) - xml_vlist_debug_str(p_name, dbg_name); - XML_TRACE_DEBUG1("xml_vlist_proc_tag: bad name:%s", dbg_name ); -#endif - - return XML_XP_UNKNOWN_ID; -} - - -/***************************************************************************** - ** Function xml_vlist_proc_attr - ** Description - ** Parameters - - ** Returns - *****************************************************************************/ -static UINT8 xml_vlist_proc_attr(tXML_VLIST_STATE *p_st, tXML_STR *p_name, tXML_STACK *p_stk) -{ - const UINT8 *p_stag; /* sub tag pointer */ - UINT8 curr = p_stk->stack[p_stk->top]; -#if (VLIST_DEBUG_XML == TRUE) - UINT8 dbg_name[VLIST_DEBUG_LEN]; -#endif - - if (curr < XML_VLIST_PTBL_SIZE) - { - /* Iterate over allowed sub-tags for the current tag. */ - for (p_stag = xml_vlist_ptbl[curr]; p_stag && *p_stag; p_stag++) - { - if (*p_stag >= XML_VLIST_TTBL_SIZE) - continue; - if(p_name->len == xml_vlist_ttbl[*p_stag].len && - strncmp((char *)p_name->p, (char *)xml_vlist_ttbl[*p_stag].p_name, p_name->len) == 0) - { - p_stk->top++; - p_stk->stack[p_stk->top] = *p_stag; - - return *p_stag; - } - } - } - -#if (defined(VLIST_DEBUG_XML) && VLIST_DEBUG_XML == TRUE) - xml_vlist_debug_str(p_name, dbg_name); - XML_TRACE_DEBUG1("xml_vlist_proc_attr: bad name:%s", dbg_name); -#endif - return XML_XP_UNKNOWN_ID; -} - - -/***************************************************************************** - ** Function xml_vlist_find_ch_n_copy - ** Description copy any chacter till one char in p_str. Any char in p_str - ** will stop copy pointed by p_begin - ** Parameters - ** Returns - *****************************************************************************/ -static void xml_vlist_find_ch_n_copy( tXML_MCOPY *p_copy ) -{ - const UINT8 *p_tmp; - const UINT8 *p_str = (UINT8 *)">"; /* was: ":=/> \t\n\r". i think we should copy till - closing flag */ - unsigned int last = XML_VLIST_CARRY_OVER_LEN; /* maximum carry over len we can support */ - UINT8 *p_last = p_copy->last.p + p_copy->last.len - 1; /* point to the last char of carry - over buffer */ - BOOLEAN found = FALSE; - - /* check if the last char in p_last is in p_str */ - for (p_tmp = p_str; *p_tmp; p_tmp++) - { - if (*p_last == *p_tmp) - { - found = TRUE; - break; - } - } /* for */ - - if (found == FALSE) - { - /* if not in p_str, move chars from p_begin to p_last - * until reached last_len or any char in p_str */ - p_last++; - last -= p_copy->last.len; /* calculate the maximum number of chars we can copy */ - while (*(p_copy->p_begin) && last) /* rl: not sure that this buffer is termninated by a 0 */ - { - /* copy from source (new buffer) to carry over. adjust only carry over ptr. */ - *p_last++ = *p_copy->p_begin; - last--; - for (p_tmp = p_str; *p_tmp; p_tmp++) - { - if (*p_copy->p_begin == *p_tmp) - { - p_copy->p_begin++; /* adjust pointer to point to next char to read */ - /* calculate new length of carry over buffer contents */ - p_copy->last.len = XML_VLIST_CARRY_OVER_LEN-last; - *p_last = 0; /* NULL terminate p_last. rl: not really neccessary. */ - return; - } - } /* for */ - p_copy->p_begin++; /* update now to next char. this way abort char is also copied */ - } /* while */ - } /* !found */ -} - -/***************************************************************************** -** Function xml_vlist_cback -** Description -** -** Parameters -** Returns -*****************************************************************************/ -static BOOLEAN xml_vlist_cback( tXML_EVENT event, void *p_event_data, void *p_usr_data) -{ - tXML_MEVT_DATA *p_ed = (tXML_MEVT_DATA*) p_event_data; - tXML_VLIST_STATE *p_st = (tXML_VLIST_STATE *) p_usr_data; - tXML_PROP *p_cp = &p_st->p_prop[p_st->prop_index]; - BOOLEAN ret = TRUE; - UINT8 next; /* next element */ - UINT8 curr = p_ed->stack.stack[p_ed->stack.top]; /* current element */ -#if (VLIST_DEBUG_XML == TRUE) - UINT8 dbg_name[VLIST_DEBUG_LEN]; - UINT8 dbg_prefix[VLIST_DEBUG_LEN]; - UINT8 dbg_value[VLIST_DEBUG_LEN]; -#endif - -#if (VLIST_DEBUG_XML == TRUE) - XML_TRACE_DEBUG1("xml_vlist_cback:%d", event); -#endif - - switch (event) - { - case XML_TAG : /* <tag-name */ - next = xml_vlist_proc_tag(p_st, &p_ed->tag.name, &p_ed->stack); -#if (VLIST_DEBUG_XML == TRUE) - xml_vlist_debug_str(&p_ed->tag.name, dbg_name); - xml_vlist_debug_str(&p_ed->tag.prefix, dbg_prefix); - XML_TRACE_DEBUG2("XML_TAG: p:%s, name:%s", dbg_prefix, dbg_name); - XML_TRACE_DEBUG2("top:x%x, stk:x%x", p_ed->stack.top, p_ed->stack.stack[p_ed->stack.top]); - -#endif - if (next != 0) - { - if (next <= XML_MAX_OBJ_TAG_ID) - p_st->obj = next; - - if(p_st->prop_index <p_st->max_num_prop) - { - p_cp->name = next; - p_cp->p_data = NULL; - p_cp->len = 0; - p_cp->level = p_ed->stack.top; - p_st->prop_index++; - } - else - ret = FALSE; - } - break; - - case XML_ATTRIBUTE : /* attr-name="attr-value" */ - curr = xml_vlist_proc_attr(p_st, &p_ed->attr.name, &p_ed->stack); -#if (defined(VLIST_DEBUG_XML) && VLIST_DEBUG_XML == TRUE) - xml_vlist_debug_str(&p_ed->attr.name, dbg_name); - xml_vlist_debug_str(&p_ed->attr.prefix, dbg_prefix); - xml_vlist_debug_str(&p_ed->attr.value, dbg_value); - XML_TRACE_DEBUG4("[xml vlist] XML_ATTRIBUTE: p:%s, name:%s, v:%s, curr:%x", - dbg_prefix, dbg_name, dbg_value, curr); -#endif - if (curr != 0) - { - if(p_st->prop_index <p_st->max_num_prop) - { - p_cp->name = curr; - p_cp->p_data = p_ed->attr.value.p; - p_cp->len = p_ed->attr.value.len; - p_cp->level = p_ed->stack.top; - p_st->prop_index++; - } - else - ret = FALSE; - p_ed->stack.top--; - } - break; - - case XML_CHARDATA : -#if (defined(VLIST_DEBUG_XML) && VLIST_DEBUG_XML == TRUE) - xml_vlist_debug_str(&p_ed->ch_data.value, dbg_value); - XML_TRACE_DEBUG2("XML_CHARDATA: v:%s, last:%d", dbg_value, p_ed->ch_data.last); -#endif - break; - - case XML_ETAG : /* </tag-name> */ - if(p_ed->stack.top > 0) - { - p_ed->stack.stack[p_ed->stack.top] = 0; - p_ed->stack.top--; - p_st->ended = (BOOLEAN) (p_ed->stack.top == 0); - } -#if (defined(VLIST_DEBUG_XML) && VLIST_DEBUG_XML == TRUE) - xml_vlist_debug_str(&p_ed->etag.name, dbg_name); - xml_vlist_debug_str(&p_ed->etag.prefix, dbg_prefix); - XML_TRACE_DEBUG2("[xml vlist] XML_ETAG: p:%s, name:%s", dbg_prefix, dbg_name); - XML_TRACE_DEBUG2("[xml vlist] top:x%x, stk:x%x", p_ed->stack.top, p_ed->stack.stack[p_ed->stack.top]); -#endif - break; - - case XML_TAG_END: /* /> */ - curr = p_ed->stack.stack[p_ed->stack.top]; - - if(p_st->prop_index <p_st->max_num_prop) - { - if(p_ed->empty_elem.end) - p_cp->name = XML_VLIST_TAG_END_ID; - else - p_cp->name = XML_VLIST_PAUSE_ID; - p_cp->p_data = NULL; - p_cp->len = 0; - p_cp->level = p_ed->stack.top; - p_st->prop_index++; - if(p_ed->empty_elem.end && p_ed->stack.top > 0) - { - p_ed->stack.top--; - } - } - else - ret = FALSE; - -#if (defined(VLIST_DEBUG_XML) && VLIST_DEBUG_XML == TRUE) - XML_TRACE_DEBUG4("[xml vlist] XML_TAG_END: %d, top:x%x, stk:x%x, curr:x%x", - p_ed->empty_elem.end, p_ed->stack.top, p_ed->stack.stack[p_ed->stack.top], curr); -#endif - break; - - case XML_PARTIAL: - if(p_st->p_prop[p_st->prop_index-1].name != XML_VLIST_TAG_END_ID) - { - p_ed->stack.top--; -#if (defined(VLIST_DEBUG_XML) && VLIST_DEBUG_XML == TRUE) - XML_TRACE_DEBUG0("[xml vlist] adjust due to XML_PARTIAL"); -#endif - } - break; - - case XML_COPY: - xml_vlist_find_ch_n_copy( &p_ed->copy ); - XML_TRACE_DEBUG1("[xml vlist] XML_COPY: %s", p_ed->copy.last.p); - break; - - default : -#if (defined(VLIST_DEBUG_XML) && VLIST_DEBUG_XML == TRUE) - XML_TRACE_DEBUG1("[xml vlist] XML event: %d", event); -#endif - break; - } - - return ret; -} - -/********************************************************************************** -** Function xml_vlist_int_fill_attribute -** Description fill in file/folder structure. -** -** Parameters -** Returns xx: > 0 : number of properties scanned, folder entry is added -** = 0 : no end tag found, carry over to next parse -** = -1: no dst_resource avaibale, all prop left to next parse -** = -2: exceed max entry, no folder entry added -**********************************************************************************/ -static INT16 xml_vlist_int_fill_attribute(tXML_VLIST_STATE * p_xud, - tXML_PROP *p_prop, - UINT16 *num_prop, - UINT8 **p_dst_data, - UINT16 *dst_len) -{ - INT16 xx; - UINT16 len; - BOOLEAN end = FALSE; - tXML_PROP *cur_prop = p_prop; - UINT8 *p_cur_offset = *p_dst_data; - - for(xx=0; (xx < *num_prop) && !end; xx++, cur_prop++) - { -#if (defined(VLIST_DEBUG_XML) && VLIST_DEBUG_XML == TRUE) - XML_TRACE_DEBUG5( "[xml vlist] fill: num_prop:%d, name id: x%x, p_prop: x%x, p_data:%s, len: %d", - (*num_prop-xx) , cur_prop->name, cur_prop, cur_prop->p_data, cur_prop->len); -#endif - switch (cur_prop->name) - { - case XML_NAME_ATTR_ID: - if ( p_xud->current_entry < p_xud->max_entry ) - { - /* calculate the max length to copy */ - len = (cur_prop->len<=p_xud->max_name_len) ? cur_prop->len:p_xud->max_name_len; - if ((*dst_len - len) > 0) /* enough data buffer available? */ - { - p_xud->p_entry[p_xud->current_entry].name = p_cur_offset; - p_xud->p_entry[p_xud->current_entry].name_len = len; - - memcpy( (void *)p_xud->p_entry[p_xud->current_entry].name, - (const void *)cur_prop->p_data, - len ); - p_xud->p_entry[p_xud->current_entry].name[len] = 0; /* null terminate string */ - p_cur_offset += (len + 1); - *dst_len = *dst_len - (len + 1) ; - -#if (defined(VLIST_DEBUG_XML) && VLIST_DEBUG_XML == TRUE) - XML_TRACE_DEBUG3("[xml vlist]: catch filename [%s] len [%d] dst_len left:[%d]", - p_xud->p_entry[p_xud->current_entry].name, - len, - *dst_len); -#endif - } - else /* run out of dst buffer resource */ - { - xx = -1; - return xx; - } - } - else /* exceed max entry */ - return -2; - - break; - - case XML_HANDLE_ATTR_ID: - if ( p_xud->current_entry < p_xud->max_entry ) - { - /* as long as we do not exceed the number of entries in the ouput array copy name */ - /* calculate the max length to copy */ - len = (cur_prop->len<=p_xud->max_name_len) ? cur_prop->len:p_xud->max_name_len; - if ((*dst_len - len) > 0) /* enough data buffer available? */ - { - p_xud->p_entry[p_xud->current_entry].handle = p_cur_offset; - p_xud->p_entry[p_xud->current_entry].handle_len = len; - - memcpy( (void *)p_xud->p_entry[p_xud->current_entry].handle, - (const void *)cur_prop->p_data, - len ); - p_xud->p_entry[p_xud->current_entry].handle[len] = 0; /* null terminate string */ - p_cur_offset += (len + 1); - *dst_len = *dst_len - (len + 1) ; - -#if (defined(VLIST_DEBUG_XML) && VLIST_DEBUG_XML == TRUE) - XML_TRACE_DEBUG3("[xml vlist]: catch filename [%s] len [%d] dst_len left:[%d]", - p_xud->p_entry[p_xud->current_entry].handle, - len, - *dst_len); -#endif - } - else /* run out of dst buffer resource */ - { - xx = -1; - return xx; - } - } - else /* exceed max entry */ - return -2; - - break; - - case XML_VLIST_TAG_END_ID: - /* -------------------- CUSTOMER SPECIFIC ---------------------- */ - p_xud->current_entry++; /* increment only when end tag (/>) found */ - -#if (defined(VLIST_DEBUG_XML) && VLIST_DEBUG_XML == TRUE) - XML_TRACE_DEBUG1( "[xml vlist] FOUND END TAG: 0x%x", cur_prop->name ); -#endif - - end = TRUE; - break; - - default: - XML_TRACE_DEBUG1("[xml vlist] unknown attrib: %d", cur_prop->name ); - break; - } - } -#if (VLIST_DEBUG_XML == TRUE) - XML_TRACE_DEBUG2("[xml vlist] fill_attribute: end:%d, xx:%d", end, xx); -#endif -#if 0 - /* if end tag not found -> split over two buffers. but parser will still show rest of - found properties. so return still found properties. */ - if(end == FALSE) - xx = 0; -#endif - - /* keep track of current data buffer offset */ - *p_dst_data = p_cur_offset; - return xx; -} - - -/********************************************************************************** -** Function xml_vlist_int_fill_evt_data -** -** Description fill in file/folder structure. -** -** Parameters -** Returns -**********************************************************************************/ -static tXML_VLIST_RES xml_vlist_int_fill_evt_data( UINT8 op, - void *p_evt_data, - tXML_PROP **p_prop, - UINT16 *num_prop, - UINT8 **p_dst_data, - UINT16 *dst_len) -{ - tXML_VLIST_STATE *p_xud = (tXML_VLIST_STATE *)p_evt_data; - INT16 inc_prop; - UINT8 prop_name; /* Property name. */ - tXML_PROP *cur_prop = *p_prop; - UINT8 *p_cur_offset = *p_dst_data; - - tXML_VLIST_RES x_res = XML_VLIST_OK; - BOOLEAN x_no_res = FALSE; /* guard dest buffer resource */ - - - if ( op == 0 || op > XML_MAX_OBJ_TAG_ID || *num_prop == 0) - return XML_VLIST_ERROR; - -#if VLIST_DEBUG_XML - XML_TRACE_DEBUG2( "[xml vlist] xml_vlist_int_fill_evt_data op:%d, num_prop:%d", - op, *num_prop); -#endif - - - - while ( *num_prop > 0 && !x_no_res ) - { -#if (defined(VLIST_DEBUG_XML) && VLIST_DEBUG_XML == TRUE) - XML_TRACE_DEBUG2("end_prop:%d, name id: x%x", *num_prop, cur_prop->name); -#endif - prop_name = cur_prop->name; - cur_prop++; - *num_prop -= 1; - - - switch( prop_name ) - { - case XML_VLIST_ELEM_ID: - /* skip over version attribute which should always be 1.0. this is the top level */ - break; - - case XML_CARD_ELEM_ID: - inc_prop = xml_vlist_int_fill_attribute(p_xud, - cur_prop, - num_prop, - &p_cur_offset, - dst_len); - if (inc_prop == -1) /* no dst_buf available */ - { - /* backup one more prop to obtain the skipped folder/file entry header */ - cur_prop --; - *num_prop += 1; - - x_res = XML_VLIST_DST_NO_RES; - x_no_res = TRUE; - } - else if (inc_prop == -2) /* exceed max entry */ - { - x_no_res = TRUE; - x_res = XML_VLIST_OUT_FULL; - } - else /* found folder entry */ - { - cur_prop += inc_prop; - *num_prop -= inc_prop; - } - break; - - - case XML_VLIST_PAUSE_ID: - -#if (VLIST_DEBUG_XML==TRUE) - XML_TRACE_DEBUG0( "[xml vlist] xml_vlist_int_fill_evt_data(): XML_VLIST_PAUSE_ID" ); -#endif - break; - - case XML_VLIST_TAG_END_ID: -#if (VLIST_DEBUG_XML==TRUE) - XML_TRACE_DEBUG0( "[xml vlist] xml_vlist_int_fill_evt_data(): XML_VLIST_TAG_END_ID" ); -#endif - break; - - default: - XML_TRACE_DEBUG1( "[xml vlist] xml_vlist_int_fill_evt_data():unknown element: %d", prop_name ); - break; - } - } - - /* keep track of current filling position, and current available dst buffer */ - *p_prop = cur_prop; - *p_dst_data = p_cur_offset; - - return x_res; -} - - -/************************************************************************************** -** Function XML_VlistInit -** -** Description Initialize xml parser state machine. -** -** Parameters p_xml_state: address of an xml parser state machine to be initialized, -** allocate an additional space of size XML_VLIST_CARRY_OVER_LEN -** right after *p_xml_state to hold carry over data. -** p_entry : points start of output vlist entry. caller needs do -** free this memory -** max_entry : max is 16 bit integer value which is the maximum number -** of folder entries. - -** -** Returns void -**************************************************************************************/ - -void XML_VlistInit( tXML_VLIST_PARSER *p_xml_state, - tXML_VLIST_ENTRY *p_entry, - const UINT16 max_entry ) -{ - /* Initialize the generic xml parser state machine.*/ - XML_InitPars( &p_xml_state->xml, xml_vlist_cback, &p_xml_state->xml_user_data ); - - /* User need to allocate an additional space of size XML_VLIST_CARRY_OVER_LEN */ - /* right after *p_xml_state to hold carry over data. */ - /* point to the end of the allocated buffer for p_xml_state, which is the */ - /* beginning of buffer(XML_VLIST_CARRY_OVER_LEN) */ - p_xml_state->xml.last_bfr.p = (UINT8 *)(p_xml_state + 1); - p_xml_state->xml.last_bfr.len = XML_VLIST_CARRY_OVER_LEN; - - /* Initialize user data */ - p_xml_state->xml_user_data.p_entry = p_entry; - p_xml_state->xml_user_data.current_entry = 0; - p_xml_state->xml_user_data.max_name_len = XML_UI_ENTRY_MAX_NAME_LEN + 1; - p_xml_state->xml_user_data.max_entry = (UINT16)max_entry; - p_xml_state->xml_user_data.prop_num = 0; -} - - -/************************************************************************************** -** Function XML_VlistParse -** -** Description This function is called to parse the xml data received from OBEX -** into folder entries associated with properties value. It can also be -** used as clean up function to delete left over data from previous parse. -** This clean up function is typically used when application runs out of -** resource and decides to discard extra xml data received. -** -** Parameters p_xml_state: pointer to a xml parser initialized by XML_VlistInit(). -** xml_data: valid pointer to OBEX list data in xml format. -** xml_len: length of the package, must be non-zero value. -** dst_data: valid pointer to the buffer for holding converted folder entry name. - When dst_data is NULL, clean up all remaining data in the parser. -** dst_len: pointer to the length of dst_data buffer, its carry out value -** is the number of bytes remaining buffer.When dst_len is NULL, -** it will cause to flush the internal data in the parser. -** num_entries: current number of entries, in the end it is the total number of entries -** -** Returns tXML_VLIST_RES (see xml_vlist_api.h) -** XML_PENDING: parsing not completed -** XML_END_LIST: found /VCard-listing but no final flag detected -** XML_VLIST_OUT_FULL: reached max_entry -> do not call parser anymore!!! dump data -** XML_VLIST_DST_NO_RES : run out of dst buffer resource while -** some xml data still remains. - -**************************************************************************************/ -tXML_VLIST_RES XML_VlistParse( tXML_VLIST_PARSER *p_xml_state, - UINT8 *xml_data, UINT16 xml_len, - UINT8 *dst_data, UINT16 *dst_len, - UINT16 *num_entries ) -{ - tXML_OS xos; - BOOLEAN is_remain = TRUE; - tXML_MUL_STATE *p_xml = &p_xml_state->xml; - tXML_VLIST_STATE *p_st = &p_xml_state->xml_user_data; - tXML_VLIST_RES x_res = XML_VLIST_OK; - tXML_RESULT res = XML_NO_PROP; - UINT16 max_num_prop = GKI_BUF3_SIZE/sizeof(tXML_PROP); /* i hope this is sufficient for 1 */ - -#if (defined(VLIST_DEBUG_XML) && VLIST_DEBUG_XML == TRUE) - int xx; - UINT8 dbg_buf[VLIST_DEBUG_LEN]; - tXML_STR str; -#endif - - /* if dst_data is NULL, clean up remaining data */ - if (!dst_data || !dst_len) - { - /* clean out remained xml data left over from last parse */ - if (p_xml_state->xml_user_data.p_prop ) - { - GKI_freebuf( p_st->p_prop ); - p_st->p_prop = p_st->offset_prop = NULL; - p_st->prop_num = 0; - } -#if (VLIST_DEBUG_XML == TRUE) - XML_TRACE_DEBUG0( "[xml vlist] XML_VlistParse() Clean up left over!"); -#endif - return x_res; - } - - /* if illegal OBEX data or dst buffer pointer received, return ERROR */ - if (xml_len == 0 || !xml_data) - { - return XML_VLIST_ERROR; - } - - /* XML_VlistParse receive new xml data, allocate buffer to hold parsed prop */ - if (p_st->offset_prop == NULL) - { - -#if (VLIST_DEBUG_XML == TRUE) - XML_TRACE_DEBUG0( "[xml vlist] XML_VlistParse() Receive New Data!"); - XML_TRACE_DEBUG2( "[xml vlist] XML_data start[%x] end [%x]",xml_data, xml_data+xml_len); -#endif - is_remain = FALSE; - if ( NULL!= (p_st->p_prop = (tXML_PROP *)GKI_getbuf( GKI_BUF3_SIZE ) ) ) - { - xos.p_begin = xml_data; - xos.p_end = xml_data + xml_len; - /* pointing next prop to be converted into file entry */ - p_st->prop_num = 0; - } - else - { - GKI_freebuf( p_xml_state ); - x_res = XML_VLIST_NO_RES; - return x_res; - } - } -#if (VLIST_DEBUG_XML == TRUE) - else - { - XML_TRACE_DEBUG0( "[xml vlist] XML_VlistParse(): Keep cleaning up old xml data !"); - } -#endif - - while( res == XML_NO_PROP ) - { - /* if no remaining data in p_st->p_prop, parse new xml data */ - if (!is_remain) - { - p_st->max_num_prop = max_num_prop; - p_st->prop_index = 0; - res = XML_MulParse( p_xml, &xos ); - - -#if (VLIST_DEBUG_XML == TRUE) - XML_TRACE_DEBUG4( "xml_vlist_parse obj: %x, max: %d, num: %d, res: %d", - p_st->obj, max_num_prop, p_st->prop_index, res); - - if (res != 0) - { - XML_TRACE_DEBUG1( "XML_MulParse Parsing: %d !!!", res); - } - - for(xx=0; xx<p_st->prop_index; xx++) - { - if ( p_st->p_prop[xx].name < XML_VLIST_MAX_ID ) - { - str.p = p_st->p_prop[xx].p_data; - str.len = p_st->p_prop[xx].len; - xml_vlist_debug_str(&str, dbg_buf); - XML_TRACE_DEBUG5( "[xml vlist] parsed: index[%d]:%d:%s: %s(%d)", p_st->prop_index-xx, p_st->p_prop[xx].level, - xml_vlist_ttbl[p_st->p_prop[xx].name].p_name, dbg_buf, p_st->p_prop[xx].len); - } - else - { - XML_TRACE_DEBUG3( "[xml vlist] internal prop: %d:%d:%d", xx, p_st->p_prop[xx].level, - p_st->p_prop[xx].name ); - } - } -#endif - p_st->prop_num = p_st->prop_index ; - p_st->offset_prop = p_st->p_prop; - } - else - { - /* This is left over data, pick up the result from the previous parse */ - res = p_xml->pars_res; - } - - if ( res != XML_OBJ_ST_EMPTY ) - { - x_res = xml_vlist_int_fill_evt_data( p_st->obj, p_st, &p_st->offset_prop, &p_st->prop_num, &dst_data, dst_len ); - - if ( (XML_VLIST_OK == x_res) && (XML_NO_END == res) ) - { - /* XML_NO_END means that the xml is not completly finished and fill returns - ok when when partial filling has been ok */ - x_res = XML_VLIST_PENDING; - } - - /* all parsed xml data has been converted into file entry */ - /* or exceed max entry number , break the parsing loop */ - if (XML_VLIST_OUT_FULL != x_res && XML_VLIST_DST_NO_RES != x_res) - { - is_remain = FALSE; - } - else - break; - } - } /* while */ - - /* free property table. at next call a new one is allocated */ - if ((x_res != XML_VLIST_DST_NO_RES && p_st->p_prop) || - XML_VLIST_OUT_FULL == x_res) - { - GKI_freebuf( p_st->p_prop ); - p_st->p_prop = NULL; - p_st->offset_prop = NULL; - } - - if ( x_res != XML_VLIST_DST_NO_RES && p_st->ended) - { - /* this should happen on the same time as final flag in fact */ - x_res = XML_VLIST_END_LIST; /* found closing /folder-listing */ - } - - - *num_entries = p_st->current_entry; /* report number of entries found. only when ended is true - application really should be interested! */ - return x_res; -} - |