WBXML_DECLARE(WBXMLTreeNode *) wbxml_tree_node_elt_get_from_name(WBXMLTreeNode *node, const char *name, WB_BOOL recurs) { WBXMLTreeNode *current_node = NULL; WB_BOOL node_found = FALSE; if ((node == NULL) || (name == NULL)) return NULL; /** @todo Handle 'recurs' TRUE */ /* Let's go through the tree */ current_node = node; while (current_node != NULL) { /* Is this the Node we searched ? */ if ((current_node->type == WBXML_TREE_ELEMENT_NODE) && (WBXML_STRCMP(wbxml_tag_get_xml_name(current_node->name), name) == 0)) { node_found = TRUE; break; } else { /* Go to next Sibbling Node */ current_node = current_node->next; } } if (node_found) return current_node; return NULL; }
static void wbxml_end_element(void *ctx, WBXMLTag *element, WB_BOOL empty) { if (!empty) { NWbxmlDecoder* t = (NWbxmlDecoder*)ctx; char* tag = (char*)wbxml_tag_get_xml_name(element); int s = nbk_strlen(tag); if (t->dstPos + s + 4 > t->dstMax) grow_buffer((uint8**)&t->dst, &t->dstMax, s, t->page); t->dst[t->dstPos++] = '<'; t->dst[t->dstPos++] = '/'; nbk_strcpy(&t->dst[t->dstPos], tag); t->dstPos += s; t->dst[t->dstPos++] = '>'; } }
static void wbxml_start_element(void *ctx, WBXMLTag *element, WBXMLAttribute **atts, WB_BOOL empty) { NWbxmlDecoder* t = (NWbxmlDecoder*)ctx; char* tag = (char*)wbxml_tag_get_xml_name(element); int s, s2; s = nbk_strlen(tag); if (t->dstPos + s + 4 > t->dstMax) grow_buffer((uint8**)&t->dst, &t->dstMax, s, t->page); t->dst[t->dstPos++] = '<'; nbk_strcpy(&t->dst[t->dstPos], tag); t->dstPos += s; if (atts) { int i = 0; char *name, *value; while (atts[i]) { name = (char*)wbxml_attribute_get_xml_name(atts[i]); value = (char*)wbxml_attribute_get_xml_value(atts[i]); i++; s = nbk_strlen(name); s2 = nbk_strlen(value); if (t->dstPos + s + s2 + 4 > t->dstMax) grow_buffer((uint8**)&t->dst, &t->dstMax, s + s2, t->page); t->dst[t->dstPos++] = ' '; nbk_strcpy(&t->dst[t->dstPos], name); t->dstPos += s; t->dst[t->dstPos++] = '='; t->dst[t->dstPos++] = '"'; nbk_strcpy(&t->dst[t->dstPos], value); t->dstPos += s2; t->dst[t->dstPos++] = '"'; } } if (empty) t->dst[t->dstPos++] = '/'; t->dst[t->dstPos++] = '>'; }
WBXML_DECLARE(WBXMLTreeNode *) wbxml_tree_node_elt_get_from_name(WBXMLTreeNode *node, const char *name, WB_BOOL recurs) { WBXMLTreeNode *current_node = NULL; WBXMLTreeNode *recurs_node = NULL; if ((node == NULL) || (name == NULL)) return NULL; /* Let's go through the tree */ current_node = node; while (current_node != NULL) { /* Is this a normal node? */ if (current_node->type == WBXML_TREE_ELEMENT_NODE) { /* Is this the Node we searched ? */ if (WBXML_STRCMP(wbxml_tag_get_xml_name(current_node->name), name) == 0) { return current_node; } /* Sould we start a recursive search? */ if (recurs && current_node->children) { recurs_node = wbxml_tree_node_elt_get_from_name(current_node->children, name, TRUE); /* Is this the Node we searched ? */ if (recurs_node) { return recurs_node; } } } /* Go to next Sibbling Node */ current_node = current_node->next; } /* A node with the specified name could not be found. */ return NULL; }
WBXML_DECLARE(WBXMLSyncMLDataType) wbxml_tree_node_get_syncml_data_type(WBXMLTreeNode *node) { WBXMLTreeNode *tmp_node = NULL; if (node == NULL) return WBXML_SYNCML_DATA_TYPE_NORMAL; /* Are we in a <Data> ? */ if ((node->type == WBXML_TREE_ELEMENT_NODE) && (node->name != NULL) && (WBXML_STRCMP(wbxml_tag_get_xml_name(node->name), "Data") == 0)) { /* Go to Parent element (or Parent of Parent) and search for <Meta> then <Type> */ if (((node->parent != NULL) && (node->parent->children != NULL) && ((tmp_node = wbxml_tree_node_elt_get_from_name(node->parent->children, "Meta", FALSE)) != NULL) && ((tmp_node = wbxml_tree_node_elt_get_from_name(tmp_node->children, "Type", FALSE)) != NULL)) || (((node->parent != NULL) && (node->parent->parent != NULL) && (node->parent->parent->children != NULL) && ((tmp_node = wbxml_tree_node_elt_get_from_name(node->parent->parent->children, "Meta", FALSE)) != NULL)) && ((tmp_node = wbxml_tree_node_elt_get_from_name(tmp_node->children, "Type", FALSE)) != NULL))) { /* Check <Type> value */ if ((tmp_node->children != NULL) && (tmp_node->children->type == WBXML_TREE_TEXT_NODE)) { /* This function is used by wbxml and xml callbacks. * So content types must be handled for both situations. */ /* application/vnd.syncml-devinf+wbxml */ if (wbxml_buffer_compare_cstr(tmp_node->children->content, "application/vnd.syncml-devinf+wbxml") == 0) { return WBXML_SYNCML_DATA_TYPE_WBXML; } /* application/vnd.syncml-devinf+xml */ if (wbxml_buffer_compare_cstr(tmp_node->children->content, "application/vnd.syncml-devinf+xml") == 0) { return WBXML_SYNCML_DATA_TYPE_NORMAL; } /* application/vnd.syncml.dmtnds+wbxml */ if (wbxml_buffer_compare_cstr(tmp_node->children->content, "application/vnd.syncml.dmtnds+wbxml") == 0) { return WBXML_SYNCML_DATA_TYPE_WBXML; } /* application/vnd.syncml.dmtnds+xml */ if (wbxml_buffer_compare_cstr(tmp_node->children->content, "application/vnd.syncml.dmtnds+xml") == 0) { return WBXML_SYNCML_DATA_TYPE_NORMAL; } /* text/clear */ if (wbxml_buffer_compare_cstr(tmp_node->children->content, "text/clear") == 0) { return WBXML_SYNCML_DATA_TYPE_CLEAR; } /* text/directory;profile=vCard */ if (wbxml_buffer_compare_cstr(tmp_node->children->content, "text/directory;profile=vCard") == 0) { return WBXML_SYNCML_DATA_TYPE_DIRECTORY_VCARD; } /* text/x-vcard */ if (wbxml_buffer_compare_cstr(tmp_node->children->content, "text/x-vcard") == 0) { return WBXML_SYNCML_DATA_TYPE_VCARD; } /* text/x-vcalendar */ if (wbxml_buffer_compare_cstr(tmp_node->children->content, "text/x-vcalendar") == 0) { return WBXML_SYNCML_DATA_TYPE_VCALENDAR; } } } /** * Hack: we assume that any <Data> inside a <Replace> or <Add> Item is a vObject (vCard / vCal / ...). * * This is because when parsing a <Data> content we really need to put a CDATA, event if we don't really * know the content-type. For example when receiving the end of a splitted vObject with Samsung D600, we receive this: * * <Replace> * <CmdID>162</CmdID> * <Item> * <Source> * <LocURI>./690</LocURI> * </Source> * <Data>EF;CELL:0661809055 * TEL;HOME:0299783886 * X-IRMC-LUID:690 * END:VCARD</Data> * </Item> * </Replace> * * There is no <Meta> info to find the content-type of the <Data>. */ if ( (node->parent != NULL) && (node->parent->parent != NULL) && (node->parent->parent->name != NULL) && ((WBXML_STRCMP(wbxml_tag_get_xml_name(node->parent->parent->name), "Add") == 0) || (WBXML_STRCMP(wbxml_tag_get_xml_name(node->parent->parent->name), "Replace") == 0)) ) { return WBXML_SYNCML_DATA_TYPE_VOBJECT; } } return WBXML_SYNCML_DATA_TYPE_NORMAL; }