static Eina_Bool _parser_cb(void *data, Eina_Simple_XML_Type type, const char *content, unsigned offset __UNUSED__, unsigned length) { EMap_Route *route = data; double d; struct tm time; time_t timet; char buf[length+1]; if(type == EINA_SIMPLE_XML_OPEN) { if(!strncmp(GPX_NAME, content, strlen(GPX_NAME))) { route->gpx.xml_is_name = EINA_TRUE; } else if(!strncmp(GPX_ELE, content, strlen(GPX_ELE))) { route->gpx.xml_is_ele = EINA_TRUE; } else if(!strncmp(GPX_TIME, content, strlen(GPX_TIME))) { route->gpx.xml_is_time = EINA_TRUE; } else if(!strncmp(GPX_COORDINATES, content, strlen(GPX_COORDINATES))) { EMap_Route_Node *node = emap_route_node_new(eina_list_count(route->nodes)); route->gpx.xml_current_node = node; emap_route_node_add(route, node); const char *tags = eina_simple_xml_tag_attributes_find(content, length); eina_simple_xml_attributes_parse(tags, length - (tags - content), _parser_attributes_cb, node); } } else if(type == EINA_SIMPLE_XML_DATA) { if(route->gpx.xml_is_name) { eina_stringshare_replace_length(&route->name, content, length); route->gpx.xml_is_name = EINA_FALSE; } else if(route->gpx.xml_is_ele) { sscanf(content, "%lf", &d); emap_route_node_elevation_set(route->gpx.xml_current_node, d); route->gpx.xml_is_ele = EINA_FALSE; } else if(route->gpx.xml_is_time) { snprintf(buf, length + 1, content); strptime(buf, "%Y-%m-%dT%H:%M:%S%Z", &time); timet = mktime(&time); emap_route_node_time_set(route->gpx.xml_current_node, timet); route->gpx.xml_is_time = EINA_FALSE; } } return EINA_TRUE; }
static Eina_Bool _etui_epub_container_parse_cb(void *data, Eina_Simple_XML_Type type, const char *content, unsigned offset EINA_UNUSED, unsigned length) { Etui_Provider_Data *pd; pd = (Etui_Provider_Data *)data; if ((type == EINA_SIMPLE_XML_OPEN) || (type == EINA_SIMPLE_XML_OPEN_EMPTY)) { if (strncmp("container", content, strlen("container")) == 0) { if (pd->container.has_container) { return EINA_FALSE; } pd->container.has_container = 1; } else if (strncmp("rootfiles", content, strlen("rootfiles")) == 0) { if (!pd->container.has_container || pd->container.has_rootfiles) { return EINA_FALSE; } pd->container.has_rootfiles = 1; } else if (strncmp("rootfile", content, strlen("rootfile")) == 0) { const char *tags; if (!pd->container.has_container || !pd->container.has_rootfiles) { return EINA_FALSE; } tags = eina_simple_xml_tag_attributes_find(content, length); if (!eina_simple_xml_attributes_parse(tags, length - (tags - content), _etui_epub_container_attr_parse_cb, pd)) { return EINA_FALSE; } } } return EINA_TRUE; }
static Eina_Bool _xml_tag_parse_cb(void *data, Eina_Simple_XML_Type type, const char *content, unsigned offset EINA_UNUSED, unsigned int length) { if (length <= 0) return EINA_FALSE; if (type == EINA_SIMPLE_XML_OPEN) { //Print tag if (!strncmp("Group", content, strlen("Group"))) printf("tag = Group\n"); else if (!strncmp("Label", content, strlen("Label"))) printf("tag = Label\n"); //Print attributes const char *tags = eina_simple_xml_tag_attributes_find(content, length); eina_simple_xml_attributes_parse(tags, length - (tags - content), _xml_attribute_parse_cb, NULL); } return EINA_TRUE; }
static Eina_Bool _eina_simple_xml_node_parse(void *data, Eina_Simple_XML_Type type, const char *content, unsigned offset, unsigned length) { struct eina_simple_xml_node_load_ctxt *ctx = data; switch (type) { case EINA_SIMPLE_XML_OPEN: case EINA_SIMPLE_XML_OPEN_EMPTY: { Eina_Simple_XML_Node_Tag *n; const char *name, *name_end, *attrs; attrs = eina_simple_xml_tag_attributes_find(content, length); if (!attrs) name_end = content + length; else name_end = attrs; name_end = _eina_simple_xml_whitespace_unskip(name_end, content); name = eina_stringshare_add_length(content, name_end - content); n = eina_simple_xml_node_tag_new(ctx->current, name); eina_stringshare_del(name); if (!n) return EINA_FALSE; if (attrs) eina_simple_xml_attributes_parse (attrs, length - (attrs - content), _eina_simple_xml_attrs_parse, n); if (type == EINA_SIMPLE_XML_OPEN) ctx->current = n; } break; case EINA_SIMPLE_XML_CLOSE: if (ctx->current->base.parent) { const char *end = _eina_simple_xml_whitespace_unskip (content + length, content); int len; len = end - content; if ((len == 0) /* </> closes the tag for us. */ || ((eina_stringshare_strlen(ctx->current->name) == len) && (memcmp(ctx->current->name, content, len) == 0))) ctx->current = ctx->current->base.parent; else WRN("closed incorrect tag: '%.*s', '%s' was expected!", len, content, ctx->current->name); } else WRN("closed tag '%.*s' but already at document root!", length, content); break; case EINA_SIMPLE_XML_DATA: return !!eina_simple_xml_node_data_new (ctx->current, content, length); case EINA_SIMPLE_XML_CDATA: return !!eina_simple_xml_node_cdata_new (ctx->current, content, length); case EINA_SIMPLE_XML_PROCESSING: return !!eina_simple_xml_node_processing_new (ctx->current, content, length); case EINA_SIMPLE_XML_DOCTYPE: return !!eina_simple_xml_node_doctype_new (ctx->current, content, length); case EINA_SIMPLE_XML_DOCTYPE_CHILD: return !!eina_simple_xml_node_doctype_child_new (ctx->current, content, length); case EINA_SIMPLE_XML_COMMENT: return !!eina_simple_xml_node_comment_new (ctx->current, content, length); case EINA_SIMPLE_XML_ERROR: ERR("parser error at offset %u-%u: %.*s", offset, length, length, content); break; case EINA_SIMPLE_XML_IGNORED: DBG("ignored contents at offset %u-%u: %.*s", offset, length, length, content); break; } return EINA_TRUE; }
static Eina_Bool _etui_epub_ncx_parse_cb(void *data, Eina_Simple_XML_Type type, const char *content, unsigned offset EINA_UNUSED, unsigned length) { Etui_Provider_Data *pd; pd = (Etui_Provider_Data *)data; if ((type == EINA_SIMPLE_XML_OPEN) || (type == EINA_SIMPLE_XML_OPEN_EMPTY)) { if (strncmp("ncx", content, strlen("ncx")) == 0) { if (pd->ncx.has_ncx) { return EINA_FALSE; } pd->ncx.has_ncx = 1; } else if (strncmp("meta", content, strlen("meta")) == 0) { const char *tags; tags = eina_simple_xml_tag_attributes_find(content, length); eina_simple_xml_attributes_parse(tags, length - (tags - content), _etui_epub_ncx_meta_attr_parse_cb, pd); } else if (strncmp("docTitle", content, strlen("docTitle")) == 0) { if (!pd->ncx.has_ncx || pd->ncx.has_title) { return EINA_FALSE; } pd->ncx.has_title = 1; } else if (strncmp("docAuthor", content, strlen("docAuthor")) == 0) { if (!pd->ncx.has_ncx || pd->ncx.has_author) { return EINA_FALSE; } pd->ncx.has_author = 1; } else if (strncmp("text", content, strlen("text")) == 0) { if (pd->ncx.has_title) pd->ncx.has_title_text = 1; if (pd->ncx.has_author) pd->ncx.has_author_text = 1; if (pd->ncx.has_navpoint) pd->ncx.has_navpoint_text = 1; } else if (strncmp("navMap", content, strlen("navMap")) == 0) { int i; for (i = 0; i < 2; i++) { if (!strcmp(pd->ncx.meta_items[i].name, "dtb:uid")) pd->ncx.uid = pd->ncx.meta_items[i].content; if (!strcmp(pd->ncx.meta_items[i].name, "dtb:depth")) { pd->ncx.depth = atoi(pd->ncx.meta_items[i].content); free(pd->ncx.meta_items[i].content); pd->ncx.meta_item_to_free = 1 - i; } free(pd->ncx.meta_items[i].name); } /* FIXME: use an eina_array instead */ if (pd->ncx.depth == 0) pd->ncx.depth = 10; pd->ncx.stack = (Etui_Epub_Ncx_Toc_Item **)calloc(pd->ncx.depth, sizeof(Etui_Epub_Ncx_Toc_Item *)); } else if (strncmp("navPoint", content, strlen("navPoint")) == 0) { pd->ncx.current_depth++; pd->ncx.stack[pd->ncx.current_depth] = (Etui_Epub_Ncx_Toc_Item *)calloc(1, sizeof(Etui_Epub_Ncx_Toc_Item)); if (pd->ncx.current_depth > 0) { if (pd->ncx.stack[pd->ncx.current_depth - 1]->child == NULL) pd->ncx.stack[pd->ncx.current_depth - 1]->child = eina_array_new(4); } pd->ncx.has_navpoint = 1; } else if (strncmp("content", content, strlen("content")) == 0) { const char *tags; tags = eina_simple_xml_tag_attributes_find(content, length); eina_simple_xml_attributes_parse(tags, length - (tags - content), _etui_epub_ncx_content_attr_parse_cb, pd); } } else if (type == EINA_SIMPLE_XML_DATA) { if (pd->ncx.has_title_text) { pd->ncx.title = (char *)malloc(length + 1); if (pd->ncx.title) { memcpy(pd->ncx.title, content, length); pd->ncx.title[length] = '\0'; } } else if (pd->ncx.has_author_text) { pd->ncx.author = (char *)malloc(length + 1); if (pd->ncx.author) { memcpy(pd->ncx.author, content, length); pd->ncx.author[length] = '\0'; } } else if (pd->ncx.has_navpoint_text) { if (pd->ncx.stack[pd->ncx.current_depth]) { char *label; label = (char *)malloc(length + 1); if (label) { memcpy(label, content, length); label[length] = '\0'; pd->ncx.stack[pd->ncx.current_depth]->label = label; } } } } else if (type == EINA_SIMPLE_XML_CLOSE) { if (strncmp("docTitle", content, strlen("docTitle")) == 0) { pd->ncx.has_title = 0; } else if (strncmp("docAuthor", content, strlen("docAuthor")) == 0) { pd->ncx.has_author = 0; } else if (strncmp("navPoint", content, strlen("navPoint")) == 0) { pd->ncx.has_navpoint = 0; if (pd->ncx.stack[pd->ncx.current_depth]) { if (pd->ncx.current_depth == 0) eina_array_push(&pd->doc.toc, pd->ncx.stack[pd->ncx.current_depth]); else eina_array_push(pd->ncx.stack[pd->ncx.current_depth - 1]->child, pd->ncx.stack[pd->ncx.current_depth]); } pd->ncx.current_depth--; } else if (strncmp("navMap", content, strlen("navMap")) == 0) { free(pd->ncx.stack); pd->ncx.stack = NULL; } else if (strncmp("text", content, strlen("text")) == 0) { if (pd->ncx.has_title) pd->ncx.has_title_text = 0; if (pd->ncx.has_author) pd->ncx.has_author_text = 0; if (pd->ncx.has_navpoint) pd->ncx.has_navpoint_text = 0; } } return EINA_TRUE; }
static Eina_Bool _etui_epub_opf_parse_cb(void *data, Eina_Simple_XML_Type type, const char *content, unsigned offset EINA_UNUSED, unsigned length) { Etui_Provider_Data *pd; pd = (Etui_Provider_Data *)data; if ((type == EINA_SIMPLE_XML_OPEN) || (type == EINA_SIMPLE_XML_OPEN_EMPTY)) { if (strncmp("package", content, strlen("package")) == 0) { if (pd->opf.has_package) { return EINA_FALSE; } pd->opf.has_package = 1; } else if (strncmp("manifest", content, strlen("manifest")) == 0) { if (!pd->opf.has_package || pd->opf.has_manifest) { return EINA_FALSE; } pd->opf.has_manifest = 1; } else if ((strncmp("item", content, strlen("item")) == 0) && (strncmp("itemref", content, strlen("itemref")) != 0)) { Etui_Epub_Opf_Manifest_Item *item; if (!pd->opf.has_package || !pd->opf.has_manifest) { return EINA_FALSE; } item = (Etui_Epub_Opf_Manifest_Item *)calloc(1, sizeof(Etui_Epub_Opf_Manifest_Item)); if (item) { const char *tags; tags = eina_simple_xml_tag_attributes_find(content, length); if (eina_simple_xml_attributes_parse(tags, length - (tags - content), _etui_epub_opf_manifest_item_attr_parse_cb, item)) { eina_hash_add(pd->opf.manifest, item->id, item); } else { if (item->id) free(item->id); if (item->href) free(item->href); if (item->media_type) free(item->media_type); free(item); } } } else if (strncmp("spine", content, strlen("spine")) == 0) { const char *tags; if (!pd->opf.has_package || pd->opf.has_spine) { return EINA_FALSE; } pd->opf.has_spine = 1; tags = eina_simple_xml_tag_attributes_find(content, length); eina_simple_xml_attributes_parse(tags, length - (tags - content), _etui_epub_opf_spine_attr_parse_cb, pd); } else if (strncmp("itemref", content, strlen("itemref")) == 0) { const char *tags; if (!pd->opf.has_package || !pd->opf.has_spine) { return EINA_FALSE; } tags = eina_simple_xml_tag_attributes_find(content, length); eina_simple_xml_attributes_parse(tags, length - (tags - content), _etui_epub_opf_spine_item_attr_parse_cb, pd); } else if (strncmp("dc:title", content, strlen("dc:title")) == 0) { pd->opf.has_dc_title = 1; } else if (strncmp("dc:creator", content, strlen("dc:creator")) == 0) { pd->opf.has_dc_creator = 1; } else if (strncmp("dc:identifier", content, strlen("dc:identifier")) == 0) { pd->opf.has_dc_identifier = 1; } } else if (type == EINA_SIMPLE_XML_DATA) { if (pd->opf.has_dc_title) { pd->opf.title = (char *)malloc(length + 1); if (pd->opf.title) { memcpy(pd->opf.title, content, length); pd->opf.title[length] = '\0'; } } if (pd->opf.has_dc_creator) { pd->opf.author = (char *)malloc(length + 1); if (pd->opf.author) { memcpy(pd->opf.author, content, length); pd->opf.author[length] = '\0'; } } if (pd->opf.has_dc_identifier) { pd->opf.uuid = (char *)malloc(length + 1); if (pd->opf.uuid) { memcpy(pd->opf.uuid, content, length); pd->opf.uuid[length] = '\0'; } } } else if (type == EINA_SIMPLE_XML_CLOSE) { if (pd->opf.has_dc_title) pd->opf.has_dc_title = 0; if (pd->opf.has_dc_creator) pd->opf.has_dc_creator = 0; if (pd->opf.has_dc_identifier) pd->opf.has_dc_identifier = 0; } return EINA_TRUE; }