コード例 #1
0
ファイル: xmlparser.c プロジェクト: cqm0609/epay_sdyl
/***********************************************
 *  得到记录的总数及记录集                     *
 *  成功返回记录数及记录集                     *
 *  失败则返回0和NULL                          *
 *  resultset用完后请手动free                  *
 ***********************************************/
xmlXPathObjectPtr parserDocByKey(xmlDocPtr doc, byte * keyName, int * num)
{
        *num = 0;
        xmlXPathContextPtr context;
        xmlXPathObjectPtr result;
        xmlNodeSetPtr nodeset;
	
	xmlInitParser();

        context = xmlXPathNewContext(doc);
        if(context == NULL) {
                //xmlFreeDoc(doc);
                ErrorLog(ERROR, "open doc fail, doc content is empty");
                printf("open doc fail, doc content is empty");
                return NULL;
        }
	
        result = xmlXPathEvalExpression((const xmlChar *)keyName, context);
        xmlXPathFreeContext(context);

        if(result == NULL) {
                //xmlFreeDoc(doc);
                ErrorLog(ERROR, "xmlPathEvalExpression return NULL");
                printf("xmlPathEvalExpression return NULL");
                return NULL;
        }

	//print_xpath_nodes(result->nodesetval, stdout);

        nodeset = result->nodesetval;
	if(nodeset == NULL) {
		xmlXPathFreeObject(result);
		ErrorLog(ERROR, "nodeset is null");
		printf("nodeset is null");
		return NULL;
	}

        if(xmlXPathNodeSetIsEmpty(result->nodesetval)) {
		xmlXPathFreeObject(result);
                ErrorLog(ERROR, "nodeset is empty");
                printf("nodeset is empty");
                return NULL;
        }

	*num = nodeset->nodeNr;
        //xmlXPathFreeObject (result);
	xmlCleanupParser();
	return result;
}
コード例 #2
0
ファイル: TrackerConfig.cpp プロジェクト: JohnChu/libavg
xmlXPathObjectPtr TrackerConfig::findConfigNodes(const string& sXPathExpr) const
{
    string sFullPath = string("/trackerconfig"+sXPathExpr);
    xmlXPathContextPtr xpCtx;
    xmlXPathObjectPtr xpElement;

    xpCtx = xmlXPathNewContext(m_Doc);
    if(!xpCtx) {
        AVG_LOG_ERROR("Unable to create new XPath context");
        return NULL;
    }

    xpElement = xmlXPathEvalExpression(BAD_CAST sFullPath.c_str(), xpCtx);
    if(!xpElement) {
        AVG_LOG_ERROR("Unable to evaluate XPath expression '"
            << sFullPath << "'");
        xmlXPathFreeContext(xpCtx);
        return NULL;
    }
    
    xmlXPathFreeContext(xpCtx);

    return xpElement;
}
コード例 #3
0
ファイル: curl_xml.c プロジェクト: EMSL-MSC/collectd
static int cx_parse_xml(cx_t *db, char *xml) /* {{{ */
{
  /* Load the XML */
  xmlDocPtr doc = xmlParseDoc(BAD_CAST xml);
  if (doc == NULL) {
    ERROR("curl_xml plugin: Failed to parse the xml document  - %s", xml);
    return -1;
  }

  xmlXPathContextPtr xpath_ctx = xmlXPathNewContext(doc);
  if (xpath_ctx == NULL) {
    ERROR("curl_xml plugin: Failed to create the xml context");
    xmlFreeDoc(doc);
    return -1;
  }

  for (size_t i = 0; i < db->namespaces_num; i++) {
    cx_namespace_t const *ns = db->namespaces + i;
    int status =
        xmlXPathRegisterNs(xpath_ctx, BAD_CAST ns->prefix, BAD_CAST ns->url);
    if (status != 0) {
      ERROR("curl_xml plugin: "
            "unable to register NS with prefix=\"%s\" and href=\"%s\"\n",
            ns->prefix, ns->url);
      xmlXPathFreeContext(xpath_ctx);
      xmlFreeDoc(doc);
      return status;
    }
  }

  int status = cx_handle_parsed_xml(db, doc, xpath_ctx);
  /* Cleanup */
  xmlXPathFreeContext(xpath_ctx);
  xmlFreeDoc(doc);
  return status;
} /* }}} cx_parse_xml */
コード例 #4
0
ファイル: downloader.cpp プロジェクト: cyclefusion/szarp
bool parse_rss_item(xmlNodePtr node, wxString &url, wxString &version, wxString &md5, wxDateTime &datetime) {
	xmlXPathContextPtr xp_ctx = xmlXPathNewContext(node->doc);
	xp_ctx->node = node;

	int ret;
	ret = xmlXPathRegisterNs(xp_ctx,
			BAD_CAST "media",
			BAD_CAST "http://video.search.yahoo.com/mrss/");
	assert(ret == 0);

	wxString datetime_string;

	wxString* str_array[] = { &md5, &url, &datetime_string };
	const char * xpath_array[] = { "./media:content/media:hash[@algo='md5']", "./link", "./pubDate" };

	for (size_t i = 0; i < sizeof(str_array) / sizeof(str_array[0]); i++) {
		xmlNodePtr _node = uxmlXPathGetNode(BAD_CAST xpath_array[i], xp_ctx);
		if (_node == NULL || _node->xmlChildrenNode == NULL) {
				xmlXPathFreeContext(xp_ctx);
				return false;
		}
		xmlChar* _str = xmlNodeListGetString(_node->doc, _node->xmlChildrenNode, 1);
		*str_array[i] = SC::U2S(_str);
		xmlFree(_str);
	}

	if (datetime.ParseRfc822Date(datetime_string.c_str()) == NULL) {
		xmlXPathFreeContext(xp_ctx);
		return false;
	}

	version = url2version(url);

	return true;

}
コード例 #5
0
ファイル: schematron.c プロジェクト: AllenChanAncA/WiEngine
/**
 * xmlSchematronFreeParserCtxt:
 * @ctxt:  the schema parser context
 *
 * Free the resources associated to the schema parser context
 */
void
xmlSchematronFreeParserCtxt(xmlSchematronParserCtxtPtr ctxt)
{
    if (ctxt == NULL)
        return;
    if (ctxt->doc != NULL && !ctxt->preserve)
        xmlFreeDoc(ctxt->doc);
    if (ctxt->xctxt != NULL) {
        xmlXPathFreeContext(ctxt->xctxt);
    }
    if (ctxt->namespaces != NULL)
        xmlFree((char **) ctxt->namespaces);
    xmlDictFree(ctxt->dict);
    xmlFree(ctxt);
}
コード例 #6
0
ファイル: XaLibDom.cpp プロジェクト: XAllegro/Xaas
void XaLibDom::AddValueElementByXPath(xmlDocPtr XmlDomDoc, string XPathExpr, string ValueValue){

	xmlNodePtr cur;
   	xmlNodePtr OptionsNode;

	xpathCtx = xmlXPathNewContext(XmlDomDoc);
    xpathObj = xmlXPathEvalExpression((const xmlChar *)XPathExpr.c_str(), xpathCtx);

   	cur = xpathObj->nodesetval->nodeTab[0];

	OptionsNode = xmlNewChild(cur, NULL, (const xmlChar *) "value", (const xmlChar *)ValueValue.c_str());	

	xmlXPathFreeObject(xpathObj);
    xmlXPathFreeContext(xpathCtx);
};
コード例 #7
0
ファイル: test3.c プロジェクト: github188/doc-1
xmlXPathObjectPtr getnodeset(xmlDocPtr doc, xmlChar *xpath)
{
	xmlXPathContextPtr context;
	xmlXPathObjectPtr result;

	context = xmlXPathNewContext(doc);
	result = xmlXPathEvalExpression(xpath, context);

	if (xmlXPathNodeSetIsEmpty(result->nodesetval)) {
		printf("No result\n");
		return NULL;
	}
	xmlXPathFreeContext(context);
	return result;
}
コード例 #8
0
ファイル: collections-api.c プロジェクト: Chaduke/bah.mod
/**
 * flickcurl_collections_getTree:
 * @fc: flickcurl context
 * @collection_id: The ID of the collection to fetch a tree for, or zero to fetch the root collection. Defaults to zero. (or NULL)
 * @user_id: The ID of the account to fetch the collection tree for. Deafults to the calling user. (or NULL)
 * 
 * Returns a tree (or sub tree) of collections belonging to a given user.
 *
 * Implements flickr.collections.getTree (1.12)
 * 
 * Return value: a collection or NULL on failure
 **/
flickcurl_collection*
flickcurl_collections_getTree(flickcurl* fc, const char* collection_id,
                              const char* user_id)
{
  const char* parameters[9][2];
  int count = 0;
  xmlDocPtr doc = NULL;
  xmlXPathContextPtr xpathCtx = NULL; 
  flickcurl_collection* collection  =  NULL;
  
  if(collection_id) {
    parameters[count][0]  = "collection_id";
    parameters[count++][1]= collection_id;
  }
  if(user_id) {
    parameters[count][0]  = "user_id";
    parameters[count++][1]= user_id;
  }

  parameters[count][0]  = NULL;

  if(flickcurl_prepare(fc, "flickr.collections.getTree", parameters, count))
    goto tidy;

  doc = flickcurl_invoke(fc);
  if(!doc)
    goto tidy;


  xpathCtx = xmlXPathNewContext(doc);
  if(!xpathCtx) {
    flickcurl_error(fc, "Failed to create XPath context for document");
    fc->failed = 1;
    goto tidy;
  }

  collection = flickcurl_build_collection(fc, xpathCtx,
                                          (const xmlChar*)"/rsp/collections/collection");

  tidy:
  if(xpathCtx)
    xmlXPathFreeContext(xpathCtx);

  if(fc->failed)
    collection = NULL;

  return collection;
}
コード例 #9
0
ファイル: cputest.c プロジェクト: soulxu/libvirt-xuhj
static virCPUDefPtr *
cpuTestLoadMultiXML(const char *arch,
                    const char *name,
                    unsigned int *count)
{
    char *xml = NULL;
    xmlDocPtr doc = NULL;
    xmlXPathContextPtr ctxt = NULL;
    xmlNodePtr *nodes = NULL;
    virCPUDefPtr *cpus = NULL;
    int n;
    int i;

    if (virAsprintf(&xml, "%s/cputestdata/%s-%s.xml", abs_srcdir, arch, name) < 0)
        goto cleanup;

    if (!(doc = virXMLParseFileCtxt(xml, &ctxt)))
        goto error;

    n = virXPathNodeSet("/cpuTest/cpu", ctxt, &nodes);
    if (n <= 0 || !(cpus = calloc(n, sizeof(virCPUDefPtr))))
        goto error;

    for (i = 0; i < n; i++) {
        ctxt->node = nodes[i];
        cpus[i] = virCPUDefParseXML(nodes[i], ctxt, VIR_CPU_TYPE_HOST);
        if (!cpus[i])
            goto error;
    }

    *count = n;

cleanup:
    free(xml);
    free(nodes);
    xmlXPathFreeContext(ctxt);
    xmlFreeDoc(doc);
    return cpus;

error:
    if (cpus) {
        for (i = 0; i < n; i++)
            virCPUDefFree(cpus[i]);
        free(cpus);
        cpus = NULL;
    }
    goto cleanup;
}
コード例 #10
0
ファイル: photos-geo-api.c プロジェクト: Elfy/flickcurl
/**
 * flickcurl_photos_geo_correctLocation:
 * @fc: flickcurl context
 * @photo_id: The ID of the photo whose WOE location is being corrected.
 * @place_id: A Flickr Places ID (or NULL)
 * @woe_id: A Where On Earth (WOE) ID (or NULL)
 * 
 * Correct a photo location.
 *
 * You must pass either a valid Places ID in @place_id or a WOE ID in @woe_id.
 * 
 * Implements flickr.photos.geo.correctLocation (1.8)
 * 
 * Return value: non-0 on failure
 **/
int
flickcurl_photos_geo_correctLocation(flickcurl* fc, const char* photo_id,
                                     const char* place_id, int woe_id)
{
  xmlDocPtr doc = NULL;
  xmlXPathContextPtr xpathCtx = NULL; 
  void* result = NULL;
  char woe_id_str[10];
  
  flickcurl_init_params(fc, 0);

  if(!photo_id)
    return 1;

  flickcurl_add_param(fc, "photo_id", photo_id);
  flickcurl_add_param(fc, "place_id", place_id);
  if(woe_id > 0) {
    sprintf(woe_id_str, "%d", woe_id);
    flickcurl_add_param(fc, "woe_id", woe_id_str);
  }
  flickcurl_end_params(fc);

  if(flickcurl_prepare(fc, "flickr.photos.geo.correctLocation"))
    goto tidy;

  doc = flickcurl_invoke(fc);
  if(!doc)
    goto tidy;


  xpathCtx = xmlXPathNewContext(doc);
  if(!xpathCtx) {
    flickcurl_error(fc, "Failed to create XPath context for document");
    fc->failed = 1;
    goto tidy;
  }

  result = NULL; /* your code here */

  tidy:
  if(xpathCtx)
    xmlXPathFreeContext(xpathCtx);

  if(fc->failed)
    result = NULL;

  return (result == NULL);
}
コード例 #11
0
ファイル: introspect.c プロジェクト: linux-pentest/dbusmap
void list_dbus_properties(xmlDocPtr doc, GDBusConnection *bus, const gchar *dest, const gchar *path, gpointer user)
{
    GHashTable *methods = user;
    xmlXPathContextPtr context;
    xmlXPathObjectPtr result;
    xmlNodeSetPtr nodes;

    context = xmlXPathNewContext(doc);

    result = xmlXPathEvalExpression("/node/interface/property[@name]", context);

    xmlXPathFreeContext(context);

    if (!result) {
        g_debug("xpath query failed for property declarations");
        return;
    }

    if (!result->nodesetval) {
        g_debug("no results for xpath query");
        xmlXPathFreeObject(result);
        return;
    }

    nodes = result->nodesetval;

    for (gint i = 0; i < nodes->nodeNr; i++) {
        xmlAttrPtr attrib = nodes->nodeTab[i]->properties;
        gchar *property;

        // Find the attribute name
        while (g_strcmp0(attrib->name, "name") != 0) {
            attrib = attrib->next;
            g_assert(attrib);
        }

        property = g_strdup_printf("p:%s.%s", nodes->nodeTab[i]->parent->properties->children->content, attrib->children->content);

        if (!g_hash_table_contains(methods, property)) {
            g_hash_table_add(methods, property);
            if (check_access_property(bus, dest, path, nodes->nodeTab[i]->parent->properties->children->content, attrib->children->content))
                g_print("\t%s %s\n", property, path);
        }
    }

    xmlXPathFreeObject(result);
    return;
}
コード例 #12
0
CPLXMLNode* GDALGMLJP2GenerateMetadata(
    const CPLString& osTemplateFile,
    const CPLString& osSourceFile
)
{
    GByte* pabyStr = nullptr;
    if( !VSIIngestFile( nullptr, osTemplateFile, &pabyStr, nullptr, -1 ) )
        return nullptr;
    CPLString osTemplate(reinterpret_cast<char *>(pabyStr));
    CPLFree(pabyStr);

    if( !VSIIngestFile( nullptr, osSourceFile, &pabyStr, nullptr, -1 ) )
        return nullptr;
    CPLString osSource(reinterpret_cast<char *>(pabyStr));
    CPLFree(pabyStr);

    xmlDocPtr pDoc = xmlParseDoc(
        reinterpret_cast<const xmlChar *>(osSource.c_str()));
    if( pDoc == nullptr )
    {
        CPLError(CE_Failure, CPLE_AppDefined, "Cannot parse %s",
                 osSourceFile.c_str());
        return nullptr;
    }

    xmlXPathContextPtr pXPathCtx = xmlXPathNewContext(pDoc);
    if( pXPathCtx == nullptr )
    {
        xmlFreeDoc(pDoc);
        return nullptr;
    }

    xmlXPathRegisterFunc(pXPathCtx, reinterpret_cast<const xmlChar *>("if"),
                         GDALGMLJP2XPathIf);
    xmlXPathRegisterFunc(pXPathCtx, reinterpret_cast<const xmlChar *>("uuid"),
                         GDALGMLJP2XPathUUID);

    pXPathCtx->error = GDALGMLJP2XPathErrorHandler;

    GDALGMLJP2RegisterNamespaces(pXPathCtx, xmlDocGetRootElement(pDoc));

    CPLString osXMLRes = GDALGMLJP2EvalExpr(osTemplate, pXPathCtx, pDoc);

    xmlXPathFreeContext(pXPathCtx);
    xmlFreeDoc(pDoc);

    return CPLParseXMLString(osXMLRes);
}
コード例 #13
0
ファイル: introspect.c プロジェクト: linux-pentest/dbusmap
void list_dbus_methods(xmlDocPtr doc, GDBusConnection *bus, const gchar *dest, const gchar *path, gpointer user)
{
    GHashTable *methods = user;
    xmlXPathContextPtr context;
    xmlXPathObjectPtr result;
    xmlNodeSetPtr nodes;

    context = xmlXPathNewContext(doc);

    result = xmlXPathEvalExpression("/node/interface/method[@name]", context);

    xmlXPathFreeContext(context);

    if (!result) {
        g_debug("xpath query failed for method declarations");
        return;
    }

    if (!result->nodesetval) {
        g_debug("no results for xpath query");
        xmlXPathFreeObject(result);
        return;
    }

    nodes = result->nodesetval;

    for (gint i = 0; i < nodes->nodeNr; i++) {
        xmlAttrPtr attrib = nodes->nodeTab[i]->properties;
        gchar *method;

        method = g_strdup_printf("m:%s.%s", nodes->nodeTab[i]->parent->properties->children->content, attrib->children->content);

        if (!g_hash_table_contains(methods, method)) {
            g_hash_table_add(methods, method);
            if (check_access_method(bus,
                                    dest,
                                    path,
                                    nodes->nodeTab[i]->parent->properties->children->content,
                                    attrib->children->content)) {
                g_print("\t%s %s\n", method, path);
            }
        }
    }

    xmlXPathFreeObject(result);
    return;
}
コード例 #14
0
ファイル: cputest.c プロジェクト: candhare/libvirt
static virCPUDefPtr *
cpuTestLoadMultiXML(const char *arch,
                    const char *name,
                    unsigned int *count)
{
    char *xml = NULL;
    xmlDocPtr doc = NULL;
    xmlXPathContextPtr ctxt = NULL;
    xmlNodePtr *nodes = NULL;
    virCPUDefPtr *cpus = NULL;
    int n;
    size_t i;

    if (virAsprintf(&xml, "%s/cputestdata/%s-%s.xml", abs_srcdir, arch, name) < 0)
        goto cleanup;

    if (!(doc = virXMLParseFileCtxt(xml, &ctxt)))
        goto cleanup;

    n = virXPathNodeSet("/cpuTest/cpu", ctxt, &nodes);
    if (n <= 0 || (VIR_ALLOC_N(cpus, n) < 0)) {
        fprintf(stderr, "\nNo /cpuTest/cpu elements found in %s\n", xml);
        goto cleanup;
    }

    for (i = 0; i < n; i++) {
        ctxt->node = nodes[i];
        cpus[i] = virCPUDefParseXML(nodes[i], ctxt, VIR_CPU_TYPE_HOST);
        if (!cpus[i])
            goto cleanup_cpus;
    }

    *count = n;

 cleanup:
    VIR_FREE(xml);
    VIR_FREE(nodes);
    xmlXPathFreeContext(ctxt);
    xmlFreeDoc(doc);
    return cpus;

 cleanup_cpus:
    for (i = 0; i < n; i++)
        virCPUDefFree(cpus[i]);
    VIR_FREE(cpus);
    goto cleanup;
}
コード例 #15
0
ファイル: msg.c プロジェクト: Creuvard/Creuvux
/* Get Info server */
static void get_server_info(const char *ident)
{
	char *path = NULL;
	char xpath[SIZE];
	xmlXPathContextPtr xml_context = NULL;
	xmlXPathObjectPtr xmlobject;
	long lval;
	char *ep;

	(void)crv_strncpy(xpath, "/database/file[@id='", sizeof(xpath));
	(void)crv_strncat(xpath, ident, sizeof(xpath));
	(void)crv_strncat(xpath, "']/server" , sizeof(xpath));
	path = crv_strdup(xpath);

	xmlXPathInit();
	xml_context = xmlXPathNewContext (xmldoc);
	xmlobject = xmlXPathEval (path, xml_context);
	crv_free(path);

	if ((xmlobject->type == XPATH_NODESET) )
  {
		int j;
		xmlNodePtr node;
		for (j = 0; j < xmlobject->nodesetval->nodeNr; j++)
		{
			node = xmlobject->nodesetval->nodeTab[j];
			xmlChar *Host = xmlGetProp(node, "host");
			if (Host != NULL) {
				server = crv_strdup(Host);
			}

			xmlChar *Port = xmlGetProp(node, "port");
			if (Port != NULL) {
				lval = strtol(Port, &ep, 10);
				if (Port[0] == '\0' || *ep != '\0') {
					fprintf(stderr, "%s%s", Port, " is not a number");
					return;
				}
				port = lval;
			}
			xmlFree (Host);
			xmlFree (Port);
		}
	}
	xmlXPathFreeObject (xmlobject);
  xmlXPathFreeContext (xml_context);
}
コード例 #16
0
ファイル: google.c プロジェクト: maxux/z03
google_search_t * google_search(char *keywords) {
	curl_data_t *curl;
	google_search_t *search;
	xmlDoc *doc = NULL;
	xmlXPathContext *ctx = NULL;
	xmlXPathObject *xpathObj = NULL;
	xmlNode *node = NULL;
	char url[2048];
	int i;
	
	curl = curl_data_new();
	
	snprintf(url, sizeof(url), "%s%s", baseurlen, space_encode(keywords));
	
	if(curl_download_text(url, curl))
		return NULL;
	
	doc = (xmlDoc *) htmlReadMemory(curl->data, strlen(curl->data), "/", "utf-8", HTML_PARSE_NOERROR);
	
	/* creating xpath request */
	ctx = xmlXPathNewContext(doc);
	xpathObj = xmlXPathEvalExpression((const xmlChar *) "//li/div/h3/a", ctx);
	
	search = (google_search_t *) calloc(1, sizeof(google_search_t));
	
	if(!xmlXPathNodeSetIsEmpty(xpathObj->nodesetval)) {
		search->length = xpathObj->nodesetval->nodeNr;
		search->result = (google_result_t *) calloc(1, sizeof(google_result_t) * search->length);
		
		for(i = 0; i < xpathObj->nodesetval->nodeNr; i++) {
			node = xpathObj->nodesetval->nodeTab[i];
			
			if(xmlNodeGetContent(node))
				search->result[i].title = strdup((char *) xmlNodeGetContent(node));
			
			if(xmlGetProp(node, (unsigned char *) "href"))
				search->result[i].url   = strdup((char *) xmlGetProp(node, (unsigned char *) "href"));
		}
	}

	xmlXPathFreeObject(xpathObj);
	xmlXPathFreeContext(ctx);	
	xmlFreeDoc(doc);
	curl_data_free(curl);
	
	return search;
}
コード例 #17
0
ファイル: record_conv.c プロジェクト: dcrossleyau/yaz
static int convert_select(void *vinfo, WRBUF record, WRBUF wr_error)
{
    int ret = 0;
    struct select_info *info = vinfo;

    xmlDocPtr doc = xmlParseMemory(wrbuf_buf(record),
                                   wrbuf_len(record));
    if (!doc)
    {
        wrbuf_printf(wr_error, "xmlParseMemory failed");
        ret = -1;
    }
    else
    {
        xmlXPathContextPtr xpathCtx = xmlXPathNewContext(doc);
        if (xpathCtx && info->xpath_expr)
        {
            xmlXPathObjectPtr xpathObj =
                xmlXPathEvalExpression((const xmlChar *) info->xpath_expr,
                                       xpathCtx);
            if (xpathObj)
            {
                xmlNodeSetPtr nodes = xpathObj->nodesetval;
                if (nodes)
                {
                    int i;
                    if (nodes->nodeNr > 0)
                        wrbuf_rewind(record);
                    for (i = 0; i < nodes->nodeNr; i++)
                    {
                        xmlNode *ptr = nodes->nodeTab[i];
                        if (ptr->type == XML_ELEMENT_NODE)
                            ptr = ptr->children;
                        for (; ptr; ptr = ptr->next)
                            if (ptr->type == XML_TEXT_NODE)
                                wrbuf_puts(record, (const char *) ptr->content);
                    }
                }
                xmlXPathFreeObject(xpathObj);
            }
            xmlXPathFreeContext(xpathCtx);
        }
        xmlFreeDoc(doc);
    }
    return ret;
}
コード例 #18
0
ファイル: photos-geo-api.c プロジェクト: Elfy/flickcurl
/**
 * flickcurl_photos_geo_getPerms:
 * @fc: flickcurl context
 * @photo_id: The id of the photo to get permissions for.
 * 
 * Get permissions for who may view geo data for a photo.
 *
 * Implements flickr.photos.geo.getPerms (0.12)
 * 
 * Return value: non-0 on failure
 **/
flickcurl_perms*
flickcurl_photos_geo_getPerms(flickcurl* fc, const char* photo_id)
{
  xmlDocPtr doc = NULL;
  xmlXPathContextPtr xpathCtx = NULL; 
  flickcurl_perms* perms = NULL;
  
  flickcurl_init_params(fc, 0);

  if(!photo_id)
    return NULL;

  flickcurl_add_param(fc, "photo_id", photo_id);

  flickcurl_end_params(fc);

  if(flickcurl_prepare(fc, "flickr.photos.geo.getPerms"))
    goto tidy;

  doc = flickcurl_invoke(fc);
  if(!doc)
    goto tidy;


  xpathCtx = xmlXPathNewContext(doc);
  if(!xpathCtx) {
    flickcurl_error(fc, "Failed to create XPath context for document");
    fc->failed = 1;
    goto tidy;
  }

  perms = flickcurl_build_perms(fc, xpathCtx,
                              (const xmlChar*)"/rsp/perms");

  tidy:
  if(xpathCtx)
    xmlXPathFreeContext(xpathCtx);

  if(fc->failed) {
    if(perms)
      flickcurl_free_perms(perms);
    perms = NULL;
  }

  return perms;
}
コード例 #19
0
ファイル: photos-geo-api.c プロジェクト: Elfy/flickcurl
/**
 * flickcurl_photos_geo_setContext:
 * @fc: flickcurl context
 * @photo_id: The id of the photo to set context data for.
 * @context: Context is a numeric value representing the photo's geotagginess beyond latitude and longitude. The current values are: 0: not defined, 1: indoors, 2: outdoors.
 * 
 * Indicate the state of a photo's geotagginess beyond latitude and longitude.
 * 
 * Note : photos passed to this method must already be geotagged
 * using the flickcurl_photos_geo_setLocation() method.
 *
 * Implements flickr.photos.geo.setContext (1.8)
 * 
 * Return value: non-0 on failure
 **/
int
flickcurl_photos_geo_setContext(flickcurl* fc, const char* photo_id,
                                int context)
{
  xmlDocPtr doc = NULL;
  xmlXPathContextPtr xpathCtx = NULL; 
  char context_str[3];
  void* result = NULL;
  
  flickcurl_init_params(fc, 1);

  if(!photo_id || context < 0 || context > 2)
    return 1;

  flickcurl_add_param(fc, "photo_id", photo_id);
  sprintf(context_str, "%d", context);
  flickcurl_add_param(fc, "context", context_str);

  flickcurl_end_params(fc);

  if(flickcurl_prepare(fc, "flickr.photos.geo.setContext"))
    goto tidy;

  doc = flickcurl_invoke(fc);
  if(!doc)
    goto tidy;


  xpathCtx = xmlXPathNewContext(doc);
  if(!xpathCtx) {
    flickcurl_error(fc, "Failed to create XPath context for document");
    fc->failed = 1;
    goto tidy;
  }

  result = NULL; /* your code here */

  tidy:
  if(xpathCtx)
    xmlXPathFreeContext(xpathCtx);

  if(fc->failed)
    result = NULL;

  return (result == NULL);
}
コード例 #20
0
/** Parse an RSS feed on the hard drive. This will parse the XML, then find
  all nodes matching the XPath for the title elements and all nodes matching
  the XPath for the links. Then, it will write those to the outfile.
  \param infile The RSS file in.
  */
int parse(char const *infile){
	const xmlChar *titlepath= (xmlChar*)"//item/title";
	const xmlChar *linkpath= (xmlChar*)"//item/link";
	xmlDocPtr doc = xmlParseFile(infile);
	Stopif(!doc, return -1, "Error: unable to parse file \"%s\"\n", infile);
	xmlXPathContextPtr context = xmlXPathNewContext(doc);
	Stopif(!context, return -2, "Error: unable to create new XPath context\n");
	xmlXPathObjectPtr titles = xmlXPathEvalExpression(titlepath, context);
	xmlXPathObjectPtr urls = xmlXPathEvalExpression(linkpath, context);
	Stopif(!titles || !urls, return -3, "either the Xpath '//item/title' or '//item/link' failed.");
	print_to_html(urls, titles);
	xmlXPathFreeObject(titles);
	xmlXPathFreeObject(urls);
	xmlXPathFreeContext(context);
	xmlFreeDoc(doc);
	return 0;
}
コード例 #21
0
ファイル: lxpath.c プロジェクト: Sirlsliang/ctags
extern void findXMLTags (xmlXPathContext *ctx, xmlNode *root,
			 const tagXpathTableTable *xpathTableTable,
			 const kindOption* const kinds,void *userData)
{
	boolean usedAsEnterPoint = FALSE;
	xmlDocPtr doc = NULL;

	if (ctx == NULL)
	{
		usedAsEnterPoint = TRUE;

		findRegexTags ();

		xmlSetGenericErrorFunc (NULL, suppressWarning);

		doc = makeXMLDoc ();

		if (doc == NULL)
		{
			verbose ("could not parse %s as a XML file\n", getInputFileName());
			return;
		}

		ctx = xmlXPathNewContext (doc);
		if (ctx == NULL)
			error (FATAL, "failed to make a new xpath context for %s", getInputFileName());

		root = xmlDocGetRootElement(doc);
		if (root == NULL)
		{
			verbose ("could not get the root node for %s\n", getInputFileName());
			goto out;
		}
	}

	findXMLTagsCore (ctx, root, xpathTableTable, kinds, userData);

out:
	if (usedAsEnterPoint)
	{
		xmlXPathFreeContext (ctx);

		if (doc != getInputFileUserData ())
			xmlFreeDoc (doc);
	}
}
コード例 #22
0
ファイル: collections-api.c プロジェクト: Elfy/flickcurl
/**
 * flickcurl_collections_getInfo:
 * @fc: flickcurl context
 * @collection_id: The ID of the collection to fetch information for.
 * 
 * Returns information for a single collection.  Currently can only
 * be called by the collection owner, this may change.
 *
 * Implements flickr.collections.getInfo (1.12)
 * 
 * Return value: a collection or NULL on failure
 **/
flickcurl_collection*
flickcurl_collections_getInfo(flickcurl* fc, const char* collection_id)
{
  xmlDocPtr doc = NULL;
  xmlXPathContextPtr xpathCtx = NULL; 
  flickcurl_collection* collection = NULL;
  
  flickcurl_init_params(fc, 0);

  if(!collection_id)
    return NULL;

  flickcurl_add_param(fc, "collection_id", collection_id);

  flickcurl_end_params(fc);

  if(flickcurl_prepare(fc, "flickr.collections.getInfo"))
    goto tidy;

  doc = flickcurl_invoke(fc);
  if(!doc)
    goto tidy;


  xpathCtx = xmlXPathNewContext(doc);
  if(!xpathCtx) {
    flickcurl_error(fc, "Failed to create XPath context for document");
    fc->failed = 1;
    goto tidy;
  }

  collection = flickcurl_build_collection(fc, xpathCtx,
                                          (const xmlChar*)"/rsp/collection");

  tidy:
  if(xpathCtx)
    xmlXPathFreeContext(xpathCtx);

  if(fc->failed) {
    if(collection)
      flickcurl_free_collection(collection);
    collection = NULL;
  }

  return collection;
}
コード例 #23
0
ファイル: xml-libxml.c プロジェクト: chleemobile/rossnet
void
rn_xml_end()
{
	if(ctxt)
		xmlXPathFreeContext(ctxt);

	if(document_network)
		xmlFreeDoc(document_network);

	if(document_links)
		xmlFreeDoc(document_links);

	if(document_model)
		xmlFreeDoc(document_model);

	xmlCleanupParser();
}
コード例 #24
0
ファイル: gvimeo.c プロジェクト: GNOME/grilo-plugins
static GHashTable *
get_video (xmlNodePtr node)
{
  gint i;
  gint array_length;
  xmlXPathContextPtr context;
  gchar *video_id;
  GHashTable *video = g_hash_table_new_full (g_str_hash,
                                             g_str_equal,
                                             g_free,
                                             g_free);

  /* Adds the video node's properties */
  add_node (node, video);

  context = xmlXPathNewContext (node->doc);
  video_id = (gchar *) xmlGetProp (node, (xmlChar *) "id");

  array_length = G_N_ELEMENTS (video_info);
  for (i = 0; i < array_length; i++)
  {
    /* Look for the wanted information only under the current video */
    gchar *xpath_name = g_strdup_printf ("//video[@id=%s]//%s",
					 video_id,
					 video_info[i].name);
    xmlNodePtr info_node = xpath_get_node (context, xpath_name);
    if (info_node)
    {
      if (video_info[i].type == EXTENDED) {
	add_node (info_node, video);
      }
      else
      {
	g_hash_table_insert (video,
			     g_strdup ((const gchar *) info_node->name),
			     (gchar *) xmlNodeGetContent (info_node));
      }
    }
    g_free (xpath_name);
  }
  g_free (video_id);

  xmlXPathFreeContext (context);

  return video;
}
コード例 #25
0
ファイル: ajouter_noeud.c プロジェクト: julp/libxml2-examples
/**
 * Retourne le premier produit du catalogue (sinon NULL)
 **/
xmlNodePtr obtenir_premier_produit(xmlDocPtr doc) {
    xmlXPathContextPtr ctxt;
    xmlXPathObjectPtr xpathRes;
    xmlNodePtr n = NULL;

    xmlXPathInit();
    if (NULL != (ctxt = xmlXPathNewContext(doc))) {
        xpathRes = xmlXPathEvalExpression(BAD_CAST "/catalogue/produit[position()=1]", ctxt);
        if (xpathRes && XPATH_NODESET == xpathRes->type && xpathRes->nodesetval->nodeNr == 1) {
            n = xpathRes->nodesetval->nodeTab[0];
        }
        xmlXPathFreeObject(xpathRes);
        xmlXPathFreeContext(ctxt);
    }

    return n;
}
コード例 #26
0
ファイル: sub_subdesc.c プロジェクト: millken/zhuxianB30
/*****************************************************************************
 函 数 名  : subdesc_ana_root
 功能描述  : 分析根元素
 输入参数  : doc xml文档
 输出参数  : root 保存数据
 返 回 值  : ERR_SUCCESS成功 其他失败
 调用函数  :
 被调函数  :
 ============================================================================
 修改历史      :
  1.日    期   : 2008年8月26日
    
    修改内容   : 新生成函数

*****************************************************************************/
static int subdesc_ana_root(xmlDocPtr doc, SUB_ROOT * root)
{
    int i;
    xmlXPathContextPtr xpathCtx;
    static SD_ANA g_ana_root[] =
    {
       /*xpath                     cbfunc                   data offset                     */
       {"/submit/pre_treatment",   subdesc_ana_pre_treatment, SUB_STRUCT_OFF(SUB_ROOT,pre_treatment)},
       {"/submit/action_list",   subdesc_ana_all_action, SUB_STRUCT_OFF(SUB_ROOT,action_list)},
       {"/submit/function_list", subdesc_ana_all_function, SUB_STRUCT_OFF(SUB_ROOT,function_list)},
       {"/submit/config_item_list", subdesc_ana_all_parameter, SUB_STRUCT_OFF(SUB_ROOT,config_item_list)},
       {"/submit/execution_list", subdesc_ana_all_clue, SUB_STRUCT_OFF(SUB_ROOT,execution_list)},
       {"/submit/result", subdesc_ana_other, SUB_STRUCT_OFF(SUB_ROOT,result)},
    };
    static int g_ana_root_len = sizeof(g_ana_root)/sizeof(SD_ANA);

    /* Create xpath evaluation context */
    xpathCtx = xmlXPathNewContext(doc);
    if(xpathCtx == NULL)
    {
        return ERROR_SYSTEM;
    }

    /*通过xpath查找相应的元素,使用回调函数进行解析*/
    for(i=0;i<g_ana_root_len;i++)
    {
        xmlXPathObjectPtr xpathObj;

        /* Evaluate xpath expression */
        xpathObj = xmlXPathEvalExpression((unsigned char*)g_ana_root[i].xpath, xpathCtx);
        if(xpathObj == NULL)
        {
            continue;
        }

        (void)g_ana_root[i].cbfunc(xpathObj->nodesetval,
                (void *)((unsigned long)root+(unsigned long)(g_ana_root[i].dataoff)),
                root);

        xmlXPathFreeObject(xpathObj);
    }

    xmlXPathFreeContext(xpathCtx);

    return ERROR_SUCCESS;
}
コード例 #27
0
ファイル: weather-owm.c プロジェクト: UIKit0/libgweather
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);
    xpath_result = xmlXPathEval (XC("/weatherdata/forecast/time"), 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);

    xpath_result = xmlXPathEval (XC("/weatherdata/credit/link"), xpath_ctx);
    if (!xpath_result || xpath_result->type != XPATH_NODESET)
	goto out;

    priv->forecast_attribution = g_strdup(_("Weather data from the <a href=\"http://openweathermap.org\">Open Weather Map project</a>"));

 out:
    if (xpath_result)
	xmlXPathFreeObject (xpath_result);
    xmlXPathFreeContext (xpath_ctx);
    xmlFreeDoc (doc);
}
コード例 #28
0
bool OSConfigure::saveonestring( std::string path, std::string value )
{
    xmlChar * xpath = ( xmlChar * ) path.c_str ();
    xmlChar *keyword;
    std::string retstring;


    xmlNodeSetPtr nodeset;
    xmlXPathContextPtr context;
    xmlXPathObjectPtr result;

    context = xmlXPathNewContext ( doc );
    if ( context == NULL )
        return "";

    result = xmlXPathEvalExpression ( xpath, context );
    xmlXPathFreeContext ( context );
    if ( result == NULL )
        return false;

    if ( xmlXPathNodeSetIsEmpty ( result->nodesetval ) )
    {
        return false;
    }

    nodeset = result->nodesetval;

    int size;
    int i;
    size = ( nodeset ) ? nodeset->nodeNr : 0;

    for ( i = size - 1; i >= 0; i-- )
    {
        xmlNodeSetContent ( nodeset->nodeTab[ i ], ( xmlChar * ) value.c_str () );

        if ( nodeset->nodeTab[ i ] ->type != XML_NAMESPACE_DECL )
        {
            nodeset->nodeTab[ i ] = NULL;
        }
    }

    xmlXPathFreeObject ( result );

    return true;
}
コード例 #29
0
/**
 * flickcurl_photosets_comments_addComment:
 * @fc: flickcurl context
 * @photoset_id: The id of the photoset to add a comment to.
 * @comment_text: Text of the comment
 * 
 * Add a comment to a photoset.
 *
 * Implements flickr.photosets.comments.addComment (0.10)
 * 
 * Return value: new comment ID or non-NULL on failure
 **/
char*
flickcurl_photosets_comments_addComment(flickcurl* fc,
                                        const char* photoset_id,
                                        const char* comment_text)
{
  xmlDocPtr doc = NULL;
  xmlXPathContextPtr xpathCtx = NULL; 
  char* id = NULL;
  
  flickcurl_init_params(fc, 1);

  if(!photoset_id || !comment_text)
    return NULL;

  flickcurl_add_param(fc, "photoset_id", photoset_id);
  flickcurl_add_param(fc, "comment_text", comment_text);

  flickcurl_end_params(fc);

  if(flickcurl_prepare(fc, "flickr.photosets.comments.addComment"))
    goto tidy;

  doc = flickcurl_invoke(fc);
  if(!doc)
    goto tidy;


  xpathCtx = xmlXPathNewContext(doc);
  if(!xpathCtx) {
    flickcurl_error(fc, "Failed to create XPath context for document");
    fc->failed = 1;
    goto tidy;
  }

  id = flickcurl_xpath_eval(fc, xpathCtx, (const xmlChar*)"/rsp/comment/@id");

  tidy:
  if(xpathCtx)
    xmlXPathFreeContext(xpathCtx);

  if(fc->failed)
    id = NULL;

  return id;
}
コード例 #30
0
ファイル: xpath.c プロジェクト: AzerTyQsdF/osx
/* {{{ proto void DOMXPath::__construct(DOMDocument doc) U */
PHP_METHOD(domxpath, __construct)
{
	zval *id, *doc;
	xmlDocPtr docp = NULL;
	dom_object *docobj;
	dom_xpath_object *intern;
	xmlXPathContextPtr ctx, oldctx;
	zend_error_handling error_handling;

	zend_replace_error_handling(EH_THROW, dom_domexception_class_entry, &error_handling TSRMLS_CC);
	if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "OO", &id, dom_xpath_class_entry, &doc, dom_document_class_entry) == FAILURE) {
		zend_restore_error_handling(&error_handling TSRMLS_CC);
		return;
	}

	zend_restore_error_handling(&error_handling TSRMLS_CC);
	DOM_GET_OBJ(docp, doc, xmlDocPtr, docobj);

	ctx = xmlXPathNewContext(docp);
	if (ctx == NULL) {
		php_dom_throw_error(INVALID_STATE_ERR, 1 TSRMLS_CC);
		RETURN_FALSE;
	}

	intern = (dom_xpath_object *)zend_object_store_get_object(id TSRMLS_CC);
	if (intern != NULL) {
		oldctx = (xmlXPathContextPtr)intern->ptr;
		if (oldctx != NULL) {
			php_libxml_decrement_doc_ref((php_libxml_node_object *)intern TSRMLS_CC);
			xmlXPathFreeContext(oldctx);
		}

		xmlXPathRegisterFuncNS (ctx, (const xmlChar *) "functionString",
					   (const xmlChar *) "http://php.net/xpath",
					   dom_xpath_ext_function_string_php);
		xmlXPathRegisterFuncNS (ctx, (const xmlChar *) "function",
					   (const xmlChar *) "http://php.net/xpath",
					   dom_xpath_ext_function_object_php);

		intern->ptr = ctx;
		ctx->userData = (void *)intern;
		intern->document = docobj->document;
		php_libxml_increment_doc_ref((php_libxml_node_object *)intern, docp TSRMLS_CC);
	}
}