示例#1
0
static void check_icu_iter2(void)
{
    UErrorCode status = U_ZERO_ERROR;
    struct icu_chain *chain = 0;
    xmlNode *xml_node;

    const char *xml_str = "<icu locale=\"en\">"
        "<transform rule=\"[:Control:] Any-Remove\"/>"
        "<tokenize rule=\"l\"/>"
        "<tokenize rule=\"w\"/>"
        "<transform rule=\"[[:WhiteSpace:][:Punctuation:]] Remove\"/>"
        "<display/>"
        "<casemap rule=\"l\"/>"
        "</icu>";

    xmlDoc *doc = xmlParseMemory(xml_str, strlen(xml_str));
    YAZ_CHECK(doc);
    if (!doc)
        return;
    xml_node = xmlDocGetRootElement(doc);
    YAZ_CHECK(xml_node);
    if (!xml_node)
        return ;

    chain = icu_chain_xml_config(xml_node, 1, &status);

    xmlFreeDoc(doc);
    YAZ_CHECK(chain);
    if (!chain)
        return;

    YAZ_CHECK(test_iter(chain, "Adobe Acrobat Reader, 1991-1999.",
                        "[adobe][acrobat][reader][1991][][1999][]"));

    YAZ_CHECK(test_iter(chain, "Νόταρης, Γιάννης Σωτ",
                        "[νόταρης][γιάννης][σωτ]"));

    check_iter_threads(chain);

    icu_chain_destroy(chain);
}
示例#2
0
static void cmd_settings(struct http_channel *c)
{
    struct http_response *rs = c->response;
    struct http_request *rq = c->request;
    struct http_session *s = locate_session(c);
    const char *content_type = http_lookup_header(rq->headers, "Content-Type");

    if (!s)
        return;

    if (rq->content_len && content_type &&
            !yaz_strcmp_del("text/xml", content_type, "; "))
    {
        xmlDoc *doc = xmlParseMemory(rq->content_buf, rq->content_len);
        xmlNode *root_n;
        int ret;
        if (!doc)
        {
            error(rs, PAZPAR2_MALFORMED_SETTING, 0);
            release_session(c,s);
            return;
        }
        root_n = xmlDocGetRootElement(doc);
        ret = settings_read_node_x(root_n, s->psession, apply_local_setting);
        xmlFreeDoc(doc);
        if (ret)
        {
            error(rs, PAZPAR2_MALFORMED_SETTING, 0);
            release_session(c,s);
            return;
        }
    }
    if (process_settings(s->psession, rq, rs) < 0)
    {
        release_session(c, s);
        return;
    }
    response_open(c, "settings");
    response_close(c, "settings");
    release_session(c, s);
}
static void php_xml2array_parse(zval* return_value, char * xml_str, long xml_len) {

	xmlKeepBlanksDefault(0);
	xmlDoc *doc = xmlParseMemory(xml_str, xml_len);
	xmlNode *root_element;

	if (doc == NULL) {
		return;
	} else {
		root_element = xmlDocGetRootElement(doc);
		zval *z;
		z = (zval *) php_xml2array_loop(root_element);

		*return_value = *z;

		xmlFreeDoc(doc);;
		efree(z);
	}

	xmlCleanupParser();
}
示例#4
0
char* generate_edit_buddylist_body(int id , const char* name)
{
	char args[] = "<args></args>";
	char ids[128];
	xmlChar *res;
	xmlDocPtr doc;
	xmlNodePtr node;
	doc = xmlParseMemory(args , strlen(args));
	node = xmlDocGetRootElement(doc);
	node = xmlNewChild(node , NULL , BAD_CAST "contacts" , NULL);
	node = xmlNewChild(node , NULL , BAD_CAST "buddy-lists" , NULL);
	node = xmlNewChild(node , NULL , BAD_CAST "buddy-list" , NULL);
	xmlNewProp(node , BAD_CAST "name" , BAD_CAST name);
	memset(ids, 0, sizeof(ids));
	snprintf(ids, sizeof(ids) - 1 , "%d" , id);
	xmlNewProp(node , BAD_CAST "id" , BAD_CAST ids);
	xmlDocDumpMemory(doc , &res , NULL);
	xmlFreeDoc(doc);
	return xml_convert(res);

}
示例#5
0
gretl_bundle *gretl_bundle_read_from_buffer (const char *buf, int len,
					     int *err)
{
    xmlDocPtr doc = NULL;
    gretl_bundle *b;

    b = gretl_bundle_new();
    if (b == NULL) {
	*err = E_ALLOC;
	return NULL;
    }    

    xmlKeepBlanksDefault(0);
    doc = xmlParseMemory(buf, len);

    if (doc == NULL) {
	gretl_errmsg_set(_("xmlParseMemory failed"));
	*err = 1;
    } else {
	xmlNodePtr cur = xmlDocGetRootElement(doc);

	if (cur == NULL) {
	    gretl_errmsg_set(_("xmlDocGetRootElement failed"));
	    *err = 1;
	} else {
	    gretl_push_c_numeric_locale();
	    cur = cur->xmlChildrenNode;
	    *err = load_bundled_items(b, cur, doc);
	    gretl_pop_c_numeric_locale();
	}
	xmlFreeDoc(doc);
    }

    if (*err) {
	gretl_bundle_destroy(b);
	b = NULL;
    }

    return b;
}
示例#6
0
static void check_chain_empty_chain(void)
{
    UErrorCode status = U_ZERO_ERROR;
    struct icu_chain *chain = 0;

    const char *xml_str = "<icu locale=\"en\">"
        "</icu>";

    const char *src8 = "some 5487 weired !¤%&(/& sTuFf";
    char *dest8 = 0;

    xmlDoc *doc = xmlParseMemory(xml_str, strlen(xml_str));
    xmlNode *xml_node = xmlDocGetRootElement(doc);
    YAZ_CHECK(xml_node);

    chain = icu_chain_xml_config(xml_node, 0, &status);

    xmlFreeDoc(doc);
    YAZ_CHECK(chain);

    YAZ_CHECK(icu_chain_assign_cstr(
                  chain,  src8,
                  &status));

    while (icu_chain_next_token(chain, &status))
    {
        ;
        /* printf("%d '%s' '%s'\n",
           icu_chain_token_number(chain),
           icu_chain_token_norm(chain),
           icu_chain_token_display(chain)); */
    }

    YAZ_CHECK_EQ(icu_chain_token_number(chain), 1);

    dest8 = (char *) icu_chain_token_norm(chain);
    YAZ_CHECK_EQ(strcmp(src8, dest8), 0);

    icu_chain_destroy(chain);
}
//---------------------------------------------------------------------------
int XsltPolicy::create_policy_from_mi(const std::string& report)
{
    Xslt s(no_https);
    xmlSetGenericErrorFunc(&s, &s.manage_generic_error);

    xmlDocPtr doc = xmlParseMemory(report.c_str(), report.length());
    xmlSetGenericErrorFunc(NULL, NULL);

    if (!doc)
    {
        // maybe put the errors from s.errors
        error = "The MediaInfo report given cannot be parsed";
        return -1;
    }

    xmlNodePtr root = xmlDocGetRootElement(doc);
    if (!root)
    {
        error = "No root node, leaving";
        xmlFreeDoc(doc);
        return 0;
    }

    for (xmlNodePtr child = root->children; child; child = child->next)
    {
        std::string def("media");
        if (child->type == XML_TEXT_NODE || !child->name || def.compare((const char*)child->name))
            continue;

        if (find_media_track_node(child) < 0)
        {
            xmlFreeDoc(doc);
            return -1;
        }
        break;
    }

    xmlFreeDoc(doc);
    return 0;
}
示例#8
0
文件: xpath.c 项目: HeyMendy/9315ass2
static xmlXPathObjectPtr
pgxml_xpath(text *document, xmlChar *xpath, xpath_workspace *workspace)
{
	int32		docsize = VARSIZE(document) - VARHDRSZ;
	xmlXPathObjectPtr res;
	xmlXPathCompExprPtr comppath;

	workspace->doctree = NULL;
	workspace->ctxt = NULL;
	workspace->res = NULL;

	pgxml_parser_init();

	workspace->doctree = xmlParseMemory((char *) VARDATA(document), docsize);
	if (workspace->doctree == NULL)
		return NULL;			/* not well-formed */

	workspace->ctxt = xmlXPathNewContext(workspace->doctree);
	workspace->ctxt->node = xmlDocGetRootElement(workspace->doctree);

	/* compile the path */
	comppath = xmlXPathCompile(xpath);
	if (comppath == NULL)
	{
		cleanup_workspace(workspace);
		xml_ereport(ERROR, ERRCODE_EXTERNAL_ROUTINE_EXCEPTION,
					"XPath Syntax Error");
	}

	/* Now evaluate the path expression. */
	res = xmlXPathCompiledEval(comppath, workspace->ctxt);
	workspace->res = res;

	xmlXPathFreeCompExpr(comppath);

	if (res == NULL)
		cleanup_workspace(workspace);

	return res;
}
示例#9
0
static void mavlink_parseDoc (char *docname) {
	xmlDocPtr doc;
	xmlNodePtr cur;
	if (strncmp(docname, "./", 2) == 0) {
		docname += 2;
	}
	char *buffer = NULL;
	int len = 0;
	SDL_RWops *ops_file = SDL_RWFromFile(docname, "r");
	if (ops_file == NULL) {
		SDL_Log("map: Document open failed: %s\n", docname);
		return;
	}
	len = SDL_RWseek(ops_file, 0, SEEK_END);
	SDL_RWseek(ops_file, 0, SEEK_SET);
	buffer = malloc(len);
	SDL_RWread(ops_file, buffer, 1, len);
	doc = xmlParseMemory(buffer, len);
	SDL_RWclose(ops_file);
	free(buffer);
	if (doc == NULL) {
		SDL_Log("mavlink: Document parsing failed: %s\n", docname);
		return;
	}
	cur = xmlDocGetRootElement(doc);
	if (cur == NULL) {
		xmlFreeDoc(doc);
		SDL_Log("mavlink: Document is Empty!!!\n");
		return;
	}
	cur = cur->xmlChildrenNode;
	while (cur != NULL) {
		if ((xmlStrcasecmp(cur->name, (const xmlChar *)"text"))) {
			mavlink_parseParams(doc, cur);
		}
		cur = cur->next;
	}
	xmlFreeDoc(doc);
	return;
}
示例#10
0
int 
xmlGetXPathString (const char *str, 
		   const char * expr, 
		   char * rc, 
		   const int len) 
{	
    xmlDocPtr doc;
    xmlNodePtr cur;
    xmlXPathContextPtr ctx;
    xmlXPathObjectPtr path; 
    xmlChar *xmlRC;    
    
    doc = xmlParseMemory(str, strlen(str));
    xmlXPathInit();
    ctx = xmlXPathNewContext(doc);
    path = xmlXPathEvalExpression((const xmlChar *)expr, ctx);
    cur = path->nodesetval->nodeTab[0]; 
    
    if (cur != NULL) {
	xmlRC = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
	snprintf(rc, len, "%s\n", xmlRC);
	xmlFree(xmlRC);
	xmlFreeDoc(doc);
	xmlCleanupParser();
	xmlXPathFreeObject(path);
	xmlXPathFreeContext(ctx); 
	    
        return(0);
    } else {
        fprintf(stderr,"error in obtaining XPath %s\n", expr);
        xmlFreeDoc(doc);
	xmlCleanupParser();
	xmlXPathFreeObject(path);
	xmlXPathFreeContext(ctx); 
	
	rc[0] = 0x00;
        return(1);
    }
}
示例#11
0
static void check_icu_iter3(void)
{
    UErrorCode status = U_ZERO_ERROR;
    struct icu_chain *chain = 0;
    xmlNode *xml_node;

    const char *xml_str =
        "<icu_chain id=\"sort\" locale=\"el\">\n"
        "<transform rule=\"[:Control:] Any-Remove\"/>\n"
        "<transform rule=\"[[:Control:][:WhiteSpace:][:Punctuation:]] Remove\"/>\n"
        "<transform rule=\"NFD; [:Nonspacing Mark:] Remove; NFC\"/>\n"
        "<casemap rule=\"l\"/>\n"
        "<display/>\n"
        "</icu_chain>\n";

    xmlDoc *doc = xmlParseMemory(xml_str, strlen(xml_str));
    YAZ_CHECK(doc);
    if (!doc)
        return;
    xml_node = xmlDocGetRootElement(doc);
    YAZ_CHECK(xml_node);
    if (!xml_node)
        return ;

    chain = icu_chain_xml_config(xml_node, 1, &status);

    xmlFreeDoc(doc);
    YAZ_CHECK(chain);
    if (!chain)
        return;

    YAZ_CHECK(test_iter(chain, "Adobe Acrobat Reader, 1991-1999.",
                        "[adobeacrobatreader19911999]"));

    YAZ_CHECK(test_iter(chain, "Νόταρης, Γιάννης Σωτ",
                        "[νοταρηςγιαννηςσωτ]"));

    icu_chain_destroy(chain);
}
示例#12
0
char *XMLMetadata::initDoc(const char *raw, size_t len)
{
	if (doc)
		xmlFreeDoc(doc);

        doc = xmlParseMemory(raw, len);
        
        if (!doc) {
                fprintf(stderr, "initDoc failed\n");
                return NULL;
        }

	xmlNodePtr root = xmlDocGetRootElement(doc);

	if(!root) { // MOS
	  fprintf(stderr, "initDoc failed - no root element\n");
	  // xmlFreeDoc(doc); // MOS - risk minor leak here
	  return NULL;
	}

        return (char *)root->name;
}
示例#13
0
static void
parse_forecast_xml (GWeatherInfo    *master_info,
		    SoupMessageBody *body)
{
    GWeatherInfoPrivate *priv;
    xmlDocPtr doc;
    xmlXPathContextPtr xpath_ctx;
    xmlXPathObjectPtr xpath_result;
    int i;

    priv = master_info->priv;

    doc = xmlParseMemory (body->data, body->length);
    if (!doc)
	return;

    xpath_ctx = xmlXPathNewContext (doc);
    xmlXPathRegisterNs (xpath_ctx, XC("yweather"), XC("http://xml.weather.yahoo.com/ns/rss/1.0"));
    xpath_result = xmlXPathEval (XC("/rss/channel/item/yweather:forecast"), xpath_ctx);

    if (!xpath_result || xpath_result->type != XPATH_NODESET)
	goto out;

    for (i = 0; i < xpath_result->nodesetval->nodeNr; i++) {
	xmlNodePtr node;
	GWeatherInfo *info;

	node = xpath_result->nodesetval->nodeTab[i];
	info = make_info_from_node (master_info, node);

	priv->forecast_list = g_slist_append (priv->forecast_list, info);
    }

    xmlXPathFreeObject (xpath_result);

 out:
    xmlXPathFreeContext (xpath_ctx);
    xmlFreeDoc (doc);
}
示例#14
0
static xmlDocPtr
get_domain_xml (guestfs_h *g, virDomainPtr dom)
{
  virErrorPtr err;
  xmlDocPtr doc;

  CLEANUP_FREE char *xml = virDomainGetXMLDesc (dom, 0);
  if (!xml) {
    err = virGetLastError ();
    error (g, _("error reading libvirt XML information: %s"), err->message);
    return NULL;
  }

  /* Parse the domain XML into an XML document. */
  doc = xmlParseMemory (xml, strlen (xml));
  if (doc == NULL) {
    error (g, _("unable to parse XML information returned by libvirt"));
    return NULL;
  }

  return doc;
}
示例#15
0
文件: lxpath.c 项目: Sirlsliang/ctags
static xmlDocPtr makeXMLDoc (void)
{
	const unsigned char* data;
	size_t size;
	xmlDocPtr doc = NULL;

	doc = getInputFileUserData ();
	if (doc)
	{
		verbose ("reuse xml doc data\n");
		return doc;
	}

	data = getInpufFileData (&size);
	if (data)
	{
		xmlLineNumbersDefault (1);
		doc = xmlParseMemory((const char*)data, size);
	}

	return doc;
}
示例#16
0
void TrackerConfig::loadConfigFile(const string& sFilename)
{
    // TODO: There is duplicated code here and in Player::loadFile which belongs
    // in a lower-level xml handling class.
    registerDTDEntityLoader("trackerconfig.dtd", g_pTrackerConfigDTD);
    xmlDtdPtr dtd;
    string sDTDFName = "trackerconfig.dtd";
    dtd = xmlParseDTD(NULL, (const xmlChar*) sDTDFName.c_str());
    if (!dtd) {
        AVG_LOG_WARNING("DTD not found at " << sDTDFName 
                << ". Not validating trackerconfig files.");
    }

    // xmlParseFile crashes for some reason under Lion.
    string sFileContents;
    readWholeFile(sFilename, sFileContents);
    m_Doc = xmlParseMemory(sFileContents.c_str(), sFileContents.length());
    if (!m_Doc) {
        AVG_LOG_ERROR("Could not open tracker config file " << sFilename <<
                ". Using defaults which will probably not work.");
        return;
    }

    xmlValidCtxtPtr cvp = xmlNewValidCtxt();
    cvp->error = xmlParserValidityError;
    cvp->warning = xmlParserValidityWarning;
    int isValid = xmlValidateDtd(cvp, m_Doc, dtd);  
    xmlFreeValidCtxt(cvp);
    if (!isValid) {
        throw (Exception(AVG_ERR_XML_PARSE, sFilename + " does not validate."));
    }

    m_pRoot = xmlDocGetRootElement(m_Doc);
    xmlFreeDtd(dtd);
    m_sFilename = sFilename;

    AVG_TRACE(Logger::category::CONFIG, Logger::severity::INFO,
            "Reading Tracker config file from " << sFilename);
}
示例#17
0
static void check_icu_iter1(void)
{
    UErrorCode status = U_ZERO_ERROR;
    struct icu_chain *chain = 0;
    xmlNode *xml_node;
    yaz_icu_iter_t iter;

    const char *xml_str = "<icu locale=\"en\">"
        "<tokenize rule=\"w\"/>"
        "<transform rule=\"[[:WhiteSpace:][:Punctuation:]] Remove\"/>"
        "</icu>";

    xmlDoc *doc = xmlParseMemory(xml_str, strlen(xml_str));
    YAZ_CHECK(doc);
    if (!doc)
        return;
    xml_node = xmlDocGetRootElement(doc);
    YAZ_CHECK(xml_node);
    if (!xml_node)
        return ;

    chain = icu_chain_xml_config(xml_node, 1, &status);

    xmlFreeDoc(doc);
    YAZ_CHECK(chain);

    iter = icu_iter_create(chain);
    icu_iter_first(iter, "a string with 15 tokens and 8 displays");
    YAZ_CHECK(iter);
    if (!iter)
        return;
    while (icu_iter_next(iter))
    {
        yaz_log(YLOG_LOG, "[%s]", icu_iter_get_norm(iter));
    }
    icu_iter_destroy(iter);
    icu_chain_destroy(chain);
}
static void
convert_caja_file (char *file)
{
    GFile *dir;
    char *uri;
    gchar *contents;
    gsize length;
    xmlDocPtr xml;

    if (!g_file_get_contents (file, &contents, &length, NULL))
    {
        if (!quiet)
        {
            g_print ("failed to load %s\n", file);
        }
        return;
    }

    uri = get_uri_from_caja_metafile_name (file);
    if (uri == NULL)
    {
        g_free (contents);
        return;
    }

    dir = g_file_new_for_uri (uri);
    g_free (uri);

    xml = xmlParseMemory (contents, length);
    g_free (contents);
    if (xml == NULL)
    {
        return;
    }

    convert_xml_file (xml, dir);
    xmlFreeDoc (xml);
}
示例#19
0
/** Extracts the md5sum from XML containing only an <entry>.
 *
 *  @xml struct str_t* the string containing the XML
 *
 *  @return a string containing the extracted md5sum.
 */
struct str_t* xml_get_md5sum(const struct str_t* xml)
{
	size_t length;
	xmlNodePtr c1;
	xmlChar *value = NULL;
	struct str_t* ret = NULL;

	const char* iter = strstr(xml->str, "<entry");
	xmlDocPtr xmldoc = xmlParseMemory(iter, xml->len - (iter - xml->str));

	xmlNodePtr node;

	if(xmldoc == NULL || xmldoc->children == NULL || xmldoc->children->children == NULL)
		return NULL;
	for(node = xmldoc->children->children; node != NULL; node = node->next)
	{
		char const *name = node->name;
		switch(*name)
		{
			case 'm':
				if(strcmp(name, "md5Checksum") == 0)
				{
					ret = (struct str_t*) malloc(sizeof(struct str_t));
					if(!ret)
						break;

					value = xmlNodeListGetString(xmldoc, node->children, 1);
					str_init_create(ret, value, 0);
					xmlFree(value);
				}
				break;
			default:
				break;
		}
	}

	return ret;
}
示例#20
0
int check_if_dialog(str body, int *is_dialog)
{
	xmlDocPtr doc;
	xmlNodePtr node;

	doc = xmlParseMemory(body.s, body.len);
	if(doc== NULL)
	{
		LM_ERR("failed to parse xml document\n");
		return -1;
	}

	node = doc->children;
	node = xmlNodeGetChildByName(node, "dialog");

	if(node == NULL)
		*is_dialog = 0;
	else
		*is_dialog = 1;

	xmlFreeDoc(doc);
	return 0;
}
    /*!
     * \brief Construct a XML reader from a filename
     * \param name[in]: Name of the file
     * \param schema[in]: Schema in order to control file (NULL is no schema)
     * \param xslt[in]: xslt engine pointer for transformation (NULL is no xslt)
     * \param usexinclude[in]: use xinclude substitution
     */
    QXmlStreamReaderExt::QXmlStreamReaderExt(const QByteArray &array,
            const QRelaxNGvalidator * schema,
            const QXsltTransformer * xslt,
            bool usexinclude):
        QXmlStreamReader()
    {
        xmlDocPtr doc;

        this->bless();

        doc =  xmlParseMemory(array.constData(), array.size());
        if(doc == NULL) {
            goto cannotparse;
        }

        this->finalize(doc, schema, xslt, usexinclude);
        return;

cannotparse:
        qDebug() << "Can not parse";
        raiseError ("Can not parse");
        return;
    }
示例#22
0
static void fetch_query_search_result(const GEADAsyncHandler *handle, GEADStatus status, gpointer user_data)
{
    Query *q = (Query *)user_data;
    if(status == GEAD_PROGRESS) return;
    if(status == GEAD_DONE)
    {
        struct lyrics_api *api = &(apis[q->index]); 
        xmlDocPtr results_doc;
        goffset size = 0;
        xmlChar *hid = NULL;
        const gchar *data = gmpc_easy_handler_get_data(handle, &size);
        results_doc = xmlParseMemory(data, (int)size);
        /* Get song id */
        hid = (xmlChar *)api->get_id(results_doc, q->song->artist, q->song->title, q->exact_match);
        xmlFreeDoc(results_doc);
        if(hid && strlen((char *)hid) > 0)
        {
            gchar *temp = NULL, *lyrics_url = NULL;
            char *esc_hid = __lyrics_process_string((char *)hid);
            xmlFree(hid);
            hid = NULL;

            temp = g_strdup_printf("%s%s", api->host, api->lyrics_uri);
            lyrics_url = g_strdup_printf(temp, esc_hid);
            g_free(esc_hid);
            g_free(temp);

            if(gmpc_easy_async_downloader(lyrics_url,fetch_query_lyrics_result , q)!= NULL)
            {
                return;
            }
        }
        if(hid) xmlFree(hid);
    }
    q->index++;
    fetch_query_iterate (q);
}
示例#23
0
void _parseDataInBuffer(const char * buffer, int buffer_size)
{   xmlDocPtr weather;
	xmlNodePtr cur;

	weather = xmlParseMemory(buffer, buffer_size);

	if ( !weather )
    {   fprintf(stderr, "Failed to parse weather data\n");
		exit(1);
	}

	cur = xmlDocGetRootElement(weather);

	if ( !cur )
    {   fprintf(stderr, "Weather file is empty\n");
		xmlFreeDoc(weather);
		exit(1);
	}

	if ( xmlStrcmp((const xmlChar * )cur->name, (const xmlChar * )"dwml") )
    {   fprintf(stderr, "Fetched wrong file\nNode named \"%s\"", cur->name);
		xmlFreeDoc(weather);
		exit(1);
	}

	cur = cur->xmlChildrenNode;

	while ( cur )
    {   if ( !xmlStrcmp((const xmlChar * )cur->name, (const xmlChar * )"head") )
		{	_parseData(weather, cur);
		}

		cur = cur->next;
	}

	xmlFreeDoc(weather);
}
示例#24
0
void opml_urlreader::reload() {
	if (offline)
		return;

	urls.clear();
	tags.clear();
	alltags.clear();

	std::string user_agent = utils::get_useragent(cfg);

	std::vector<std::string> urls = utils::tokenize_quoted(this->get_source(), " ");

	for (std::vector<std::string>::iterator it=urls.begin();it!=urls.end();it++) {
		LOG(LOG_DEBUG, "opml_urlreader::reload: downloading `%s'", it->c_str());
		std::string urlcontent = utils::retrieve_url(*it, cfg, this->get_auth());

		xmlDoc * doc = xmlParseMemory(urlcontent.c_str(), urlcontent.length());

		if (doc == NULL) {
			LOG(LOG_ERROR, "opml_urlreader::reload: parsing XML file failed");
			continue;
		}

		xmlNode * root = xmlDocGetRootElement(doc);

		if (root) {
			for (xmlNode * node = root->children; node != NULL; node = node->next) {
				if (strcmp((const char *)node->name, "body")==0) {
					LOG(LOG_DEBUG, "opml_urlreader::reload: found body");
					rec_find_rss_outlines(node->children, "");
				}
			}
		}

		xmlFreeDoc(doc);
	}
}
示例#25
0
文件: xml.cpp 项目: zhenyouluo/GPL
bool gpl::xml::openBufferXPath(const char* buffer, int size /*= -1*/, int blank /*= 1*/)
{
	int len = strlen(buffer);
	if (size == 0 || len < size)
		return false;
	if (size == -1)
	{
		size = len;
	}
	///////////////////////////////////////////////////////  
	if (m_xml->doc != NULL)
		closeXPath();
	xmlLoadExtDtdDefaultValue |= XML_DETECT_IDS;
	xmlLoadExtDtdDefaultValue |= XML_COMPLETE_ATTRS;
	xmlSubstituteEntitiesDefaultValue = 1;
	if (xmlAddEncodingAlias("ISO-8859-2", "GBK") < 0 ||
		xmlAddEncodingAlias("ISO-8859-2", "GB2312") < 0)
		return false;
	xmlKeepBlanksDefault(blank);
	m_xml->doc = xmlParseMemory(buffer, size);
	if (m_xml->doc == NULL)
		return false;

	m_xml->context = xmlXPathNewContext(m_xml->doc);
	m_xml->context->node = xmlDocGetRootElement(m_xml->doc);
	if (m_xml->context->node == NULL)
	{
		xmlFreeDoc(m_xml->doc);
		return false;
	}
	m_xml->resource = NULL;
	m_fileName = "";
	m_xml->isOnlyEntityName = false;

	///////////////////////////////////////////////////////  
	return true;
}
示例#26
0
文件: batxml.c 项目: f7753/monetdb
str
BATXMLisdocument(bat *ret, const bat *bid)
{
	BAT *b, *bn;
	BUN p, q;
	BATiter bi;

	if ((b = BATdescriptor(*bid)) == NULL)
		throw(MAL, "xml.isdocument", INTERNAL_BAT_ACCESS);
	prepareResult(bn, b, TYPE_bit, "isdocument", (void) 0);
	bi = bat_iterator(b);
	BATloop(b, p, q) {
		const char *t = (const char *) BUNtail(bi, p);
		xmlDocPtr doc;
		bit val;

		if (strNil(t)) {
			val = bit_nil;
			bn->T->nonil = 0;
		} else {
			doc = xmlParseMemory(t, (int) strlen(t));
			if (doc == NULL) {
				val = 0;
			} else {
				xmlFreeDoc(doc);
				val = 1;
			}
		}
		bunfastapp(bn, &val);
	}
	finalizeResult(ret, bn, b);
	return MAL_SUCCEED;
  bunins_failed:
	BBPunfix(b->batCacheid);
	BBPunfix(bn->batCacheid);
	throw(MAL, "xml.isdocument", OPERATION_FAILED " During bulk processing");
}
示例#27
0
文件: 01-xmltest.c 项目: myth9499/ups
int main(int argc, char **argv)
{
    xmlDocPtr doc;
    char buf[1024];
    FILE *f;
    size_t l;

    printf("- From file\n");
    doc = xmlParseFile(argv[1]);
    printf("encoding: %s\ncharset: %d\n",
           doc->encoding, doc->charset);
    xmlFreeDoc(doc);

    f = fopen(argv[1], "r");
    l = fread(buf, 1, 1024, f);
    
    printf("- From memory\n");
    doc = xmlParseMemory(buf, l);
    printf("encoding: %s\ncharset: %d\n",
           doc->encoding, doc->charset);
    xmlFreeDoc(doc);

    return 0;
}
示例#28
0
文件: http.c 项目: saiful76/pazpar2
static struct http_buf *http_serialize_response(struct http_channel *c,
        struct http_response *r)
{
    struct http_header *h;

    wrbuf_rewind(c->wrbuf);
    wrbuf_printf(c->wrbuf, "HTTP/%s %s %s\r\n", c->version, r->code, r->msg);
    for (h = r->headers; h; h = h->next)
        wrbuf_printf(c->wrbuf, "%s: %s\r\n", h->name, h->value);
    if (r->payload)
    {
        wrbuf_printf(c->wrbuf, "Content-Length: %d\r\n", r->payload ?
                (int) strlen(r->payload) : 0);
        wrbuf_printf(c->wrbuf, "Content-Type: %s\r\n", r->content_type);
        if (!strcmp(r->content_type, "text/xml"))
        {
            xmlDoc *doc = xmlParseMemory(r->payload, strlen(r->payload));
            if (doc)
            {
                xmlFreeDoc(doc);
            }
            else
            {
                yaz_log(YLOG_WARN, "Sending non-wellformed "
                        "response (bug #1162");
                yaz_log(YLOG_WARN, "payload: %s", r->payload);
            }
        }
    }
    wrbuf_puts(c->wrbuf, "\r\n");

    if (r->payload)
        wrbuf_puts(c->wrbuf, r->payload);

    return http_buf_bywrbuf(c->http_server, c->wrbuf);
}
示例#29
0
文件: xml.cpp 项目: ebos/Epiar
bool XMLFile::Open( const string& filename ) {
	char *buf = NULL;
	long bufSize = 0;
	File xmlfile;

	if( xmlfile.OpenRead( filename ) == false ) {
		LogMsg(ERR, "Could not find file %s", filename.c_str() );
		return( false );
	}

	buf = xmlfile.Read();
	bufSize = xmlfile.GetLength();
	if( buf == NULL ) {
		LogMsg(ERR, "Could not load XML from archive. Buffer failed to allocate." );
		return( NULL );
	}

	xmlPtr = xmlParseMemory( buf, bufSize );
	delete [] buf;

	this->filename.assign( filename );

	return( true );
}
示例#30
0
文件: LastFM.c 项目: emillon/gmpc
static gchar* __lastfm_art_xml_get_artist_bio(const gchar* data , gint size)
{
	xmlDocPtr doc = xmlParseMemory(data,size);
	gchar* info=NULL;
	if(doc)
	{
		xmlNodePtr root = xmlDocGetRootElement(doc);
		/* Todo this is ugly */
		xmlNodePtr bio = get_first_node_by_name(
				get_first_node_by_name(get_first_node_by_name(root,
						BAD_CAST"artist"),
					BAD_CAST"bio"),
				BAD_CAST"content");
		if(bio)
		{
			xmlChar *temp = xmlNodeGetContent(bio);
			info = g_strdup((gchar*) temp);
			xmlFree(temp);
		}
	}
	xmlFreeDoc(doc);

	return info;
}