/**
 * Parse the cdp configuration from str to xml
 * @param filename
 * @return the xmlDocPtr or null on error
 */
xmlDocPtr parse_dp_config_str(str config_str)
{
	xmlDocPtr doc;
	
	char c = config_str.s[config_str.len];
	if (!config_str.len){
		LOG(L_ERR,"ERROR:parse_dp_config_str(): empty string\n");
		goto error;
	}
	parser_init();

	config_str.s[config_str.len] = 0;
	doc = xmlParseDoc((xmlChar*)config_str.s);
	config_str.s[config_str.len] = c;

	if (!doc){
		LOG(L_ERR,"ERR:parse_dp_config_file():  This is not a valid XML string <%.*s>\n",
			config_str.len,config_str.s);
		goto error;
	}
	
	return  doc;
error:
	return 0;		
}
Beispiel #2
0
static int cx_parse_stats_xml(xmlChar* xml, cx_t *db) /* {{{ */
{
  int status;
  xmlDocPtr doc;
  xmlXPathContextPtr xpath_ctx;

  /* Load the XML */
  doc = xmlParseDoc(xml);
  if (doc == NULL)
  {
    ERROR ("curl_xml plugin: Failed to parse the xml document  - %s", xml);
    return (-1);
  }

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

  status = cx_handle_parsed_xml (doc, xpath_ctx, db);
  /* Cleanup */
  xmlXPathFreeContext(xpath_ctx);
  xmlFreeDoc(doc);
  return status;
} /* }}} cx_parse_stats_xml */
Beispiel #3
0
gbDoc *
gb_doc_xml_open_buffer (const gchar    *buffer,
			gbDocXMLStatus *status)
{
	xmlDocPtr  xmldoc;
	gbDoc     *doc;

	gb_debug (DEBUG_XML, "START");

	xmldoc = xmlParseDoc ((xmlChar *) buffer);
	if (!xmldoc) {
		g_warning (_("xmlParseFile error"));
		*status = GB_DOC_XML_ERROR_OPEN_PARSE;
		return NULL;
	}

	doc = xml_to_doc (xmldoc, status);

	if (doc) {
		gb_doc_clear_modified (doc);
	}

	xmlFreeDoc (xmldoc);

	gb_debug (DEBUG_XML, "END");

	return doc;
}
Beispiel #4
0
/**
 * Evaluates an XPath expression on the given XML file.
 * Assumes that every result node is a text node.
 *
 * @param xml_data - the XML data as a string.
 * @param expression - the expressions to evaluate.
 * @param namespaces - a list of namespaces, containing two elements
 *   for every namespace: a prefix, and a href (in that order).
 * @return a wb_str_list containing the results. IMPORTANT: the
 *   returned list must be freed with wb_list_free().
 */
struct wb_str_list *
xpath_eval_expr(const char *xml_data, const char *expression,
	struct wb_str_list *namespaces) {

	struct wb_str_list *results = NULL;
	xmlDocPtr xml_doc;
	xmlXPathObjectPtr results_xpath_object;

	/* Create an XML document from XML data */
	xml_doc = xmlParseDoc(BAD_CAST xml_data);
	if (xml_doc == NULL) {
		return NULL;
	}

	/* Evaluate the XPath expression */
	results_xpath_object = libxml_xpath_eval_expr(xml_doc,
		BAD_CAST expression, namespaces);
	if (results_xpath_object == NULL) {
		xmlFreeDoc(xml_doc);
		return NULL;
	}

	/* Get the result list from the XML object */
	results = xpath_object_to_str_list(results_xpath_object, xml_doc);

	/* Cleanup */
	xmlXPathFreeObject(results_xpath_object);
	xmlFreeDoc(xml_doc);

	return results;
}
Beispiel #5
0
static void
gda_report_engine_set_property (GObject *object,
				guint param_id,
				const GValue *value,
				GParamSpec *pspec)
{
        GdaReportEngine *eng;

        eng = GDA_REPORT_ENGINE (object);
        if (eng->priv) {
                switch (param_id) {
		case PROP_SPEC_NODE: {
			if (eng->priv->spec) {
				xmlFreeNode (eng->priv->spec);
				eng->priv->spec = NULL;
			}
			eng->priv->spec = g_value_get_pointer (value);
			break;
		}
		case PROP_SPEC_STRING: {
			xmlDocPtr doc;
			
			doc = xmlParseDoc (BAD_CAST g_value_get_string (value));
			if (doc) {
				if (eng->priv->spec) 
					xmlFreeNode (eng->priv->spec);
				eng->priv->spec = xmlDocGetRootElement (doc);
				xmlUnlinkNode (eng->priv->spec);
				if (eng->priv->doc)
					xmlFreeDoc (eng->priv->doc);
				eng->priv->doc = doc;
			}
			break;
		}
		case PROP_SPEC_FILE: {
			xmlDocPtr doc;
			
			doc = xmlParseFile (g_value_get_string (value));
			if (doc) {
				if (eng->priv->spec) 
					xmlFreeNode (eng->priv->spec);
				eng->priv->spec = xmlDocGetRootElement (doc);
				xmlUnlinkNode (eng->priv->spec);
				if (eng->priv->doc)
					xmlFreeDoc (eng->priv->doc);
				eng->priv->doc = doc;
			}
			break;
		}
		case PROP_OUTPUT_DIR:
			g_free (eng->priv->output_dir);
			eng->priv->output_dir = g_value_dup_string (value);
			break;
		default:
			G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
			break;
                }
        }
}
Beispiel #6
0
void ExportDialog::accept()
{
    QDialog::accept();

    if (ui->csvRadio->isChecked()) {
        /// Find the CSV filter in the standard filter list
        //[email protected]: good and clean solution
        QStringList defaultFilters = KEduVocDocument::pattern(KEduVocDocument::Writing).split('\n');
        QString filter = defaultFilters.filter(QStringLiteral("csv")).join(QStringLiteral("\n"));
        QUrl filename = getFileName(filter);
        if (filename != QUrl()) {
            m_doc->saveAs(filename);
        }
        return;
    }

    QString xslFile;
    if (ui->flashCardRadio->isChecked()) {
        xslFile = QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("parley/xslt/flashcards.xsl"));
    } else {
        xslFile = QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("parley/xslt/table.xsl"));
    }

    QString filter = "*.html|" + i18n("HTML document");
    QUrl filename = getFileName(filter);
    if (filename.isEmpty()) {
        return;
    }

    qDebug() << "XSLT starting";

    xsltStylesheetPtr cur = NULL;
    xmlDocPtr doc, res;

    xmlSubstituteEntitiesDefault(1);
    xmlLoadExtDtdDefaultValue = 1;
    cur = xsltParseStylesheetFile((const xmlChar*) xslFile.toLatin1().constData());

    doc = xmlParseDoc((const xmlChar*) m_doc->document()->toByteArray(m_doc->document()->generator()).constData());

    res = xsltApplyStylesheet(cur, doc, 0);
    FILE* result = fopen(QFile::encodeName(filename.toLocalFile()).constData(), "w");
    if (result != NULL) {
        xsltSaveResultToFile(result, res, cur);
        fclose(result);
    } else {
        KMessageBox::error(this, i18n("Could not write to file \"%1\"", filename.toLocalFile()));
    }

    xsltFreeStylesheet(cur);
    xmlFreeDoc(res);
    xmlFreeDoc(doc);

    xsltCleanupGlobals();
    xmlCleanupParser();

    qDebug() << "XSLT finished";
}
Beispiel #7
0
/*
 * Valid an xml string against an XML schema
 * Inpired from: http://xml.developpez.com/sources/?page=validation#validate_XSD_CppCLI_2
 * taken from tinyows.org
 */
int msOWSSchemaValidation(const char* xml_schema, const char* xml)
{
  xmlSchemaPtr schema;
  xmlSchemaParserCtxtPtr ctxt;
  xmlSchemaValidCtxtPtr validctxt;
  int ret;
  xmlDocPtr doc;

  if (!xml_schema || !xml)
    return MS_FAILURE;

  xmlInitParser();
  schema = NULL;
  ret = -1;

  /* Open XML Schema File */
  ctxt = xmlSchemaNewParserCtxt(xml_schema);
  /*
  else ctxt = xmlSchemaNewMemParserCtxt(xml_schema);
  */
  /*
  xmlSchemaSetParserErrors(ctxt,
                           (xmlSchemaValidityErrorFunc) libxml2_callback,
                           (xmlSchemaValidityWarningFunc) libxml2_callback, stderr);
  */

  schema = xmlSchemaParse(ctxt);
  xmlSchemaFreeParserCtxt(ctxt);

  /* If XML Schema hasn't been rightly loaded */
  if (schema == NULL) {
    xmlSchemaCleanupTypes();
    xmlMemoryDump();
    xmlCleanupParser();
    return ret;
  }

  doc = xmlParseDoc((xmlChar *)xml);

  if (doc != NULL) {
    /* Loading XML Schema content */
    validctxt = xmlSchemaNewValidCtxt(schema);
    /*
    xmlSchemaSetValidErrors(validctxt,
                            (xmlSchemaValidityErrorFunc) libxml2_callback,
                            (xmlSchemaValidityWarningFunc) libxml2_callback, stderr);
    */
    /* validation */
    ret = xmlSchemaValidateDoc(validctxt, doc);
    xmlSchemaFreeValidCtxt(validctxt);
  }

  xmlSchemaFree(schema);
  xmlFreeDoc(doc);
  xmlCleanupParser();

  return ret;
}
Beispiel #8
0
/* functions */
int verify_file(const char* xmlMessage, const char* key) {
  xmlDocPtr doc = NULL;
  /* Init libxml and libxslt libraries */
  xmlInitParser();
  LIBXML_TEST_VERSION
    xmlLoadExtDtdDefaultValue = XML_DETECT_IDS | XML_COMPLETE_ATTRS;
  xmlSubstituteEntitiesDefault(1);
  doc = xmlParseDoc((xmlChar *) xmlMessage) ;
  return verify_document(doc, key);
}
Beispiel #9
0
int
verify_xml(xmlSecKeysMngrPtr mngr, const char* xml_string, const char* id_attr_name, const char* id_node_name) {
    xmlDocPtr doc = NULL;
    xmlNodePtr node = NULL;
    xmlSecDSigCtxPtr dsigCtx = NULL;
    int res = -1;

    assert(mngr);
    assert(xml_string);

    /* load template */
    doc = xmlParseDoc((xmlChar*)xml_string);
    if ((doc == NULL) || (xmlDocGetRootElement(doc) == NULL)){
        fprintf(stderr, "XmlSecError: unable to parse xml string\n");
        goto done2;
    }

    /* add id */
    if (id_attr_name && id_node_name)
        xmlSecAppAddIDAttr(xmlDocGetRootElement(doc), (xmlChar*)id_attr_name, (xmlChar*)id_node_name, NULL);

    /* find start node */
    node = xmlSecFindNode(xmlDocGetRootElement(doc), xmlSecNodeSignature, xmlSecDSigNs);
    if(node == NULL) {
        fprintf(stderr, "XmlSecError: start node not found in xml string\n");
        goto done2;
    }

    /* create signature context */
    dsigCtx = xmlSecDSigCtxCreate(mngr);
    if(dsigCtx == NULL) {
        fprintf(stderr,"XmlSecError: failed to create signature context\n");
        goto done2;
    }

    /* Verify signature */
    if(xmlSecDSigCtxVerify(dsigCtx, node) < 0) {
        fprintf(stderr,"XmlSecError: signature verify\n");
        goto done2;
    }

    res = (dsigCtx->status == xmlSecDSigStatusSucceeded);

done2:
    /* cleanup */
    if(dsigCtx != NULL) {
        xmlSecDSigCtxDestroy(dsigCtx);
    }

    if(doc != NULL) {
        xmlFreeDoc(doc);
    }
    return(res);
}
Beispiel #10
0
  /// <summary>
  /// Get all widgets represents by XML elements that are children
  /// of the placeholder element specified by path.
  /// </summary>
  /// <param name="path">
  /// A <see cref="System.String"/> representing the path to
  /// the placeholder of interest.
  /// </param>
  /// <returns>
  /// A <see cref="IList`1"/> of Gtk.Widget objects corresponding
  /// to the XML child elements of the placeholder element.
  /// </returns>
  void ActionManager::get_placeholder_children(const std::string & path, 
                                               std::list<Gtk::Widget*> & children) const
  {
    // Wrap the UIManager XML in a root element
    // so that it's real parseable XML.
    std::string xml = "<root>" + m_ui->get_ui() + "</root>";

    xmlDocPtr doc = xmlParseDoc((const xmlChar*)xml.c_str());
    if(doc == NULL) {
      return;
    }
        
    // Get the element name
    std::string placeholderName = sharp::string_substring(path, sharp::string_last_index_of(
                                                            path, "/") + 1);
    DBG_OUT("path = %s placeholdername = %s", path.c_str(), placeholderName.c_str());

    sharp::XmlNodeSet nodes = sharp::xml_node_xpath_find(xmlDocGetRootElement(doc), 
                                                         "//placeholder");
    // Find the placeholder specified in the path
    for(sharp::XmlNodeSet::const_iterator iter = nodes.begin();
        iter != nodes.end(); ++iter) {
      xmlNodePtr placeholderNode = *iter;

      if (placeholderNode->type == XML_ELEMENT_NODE) {

        xmlChar * prop = xmlGetProp(placeholderNode, (const xmlChar*)"name");
        if(!prop) {
          continue;
        }
        if(xmlStrEqual(prop, (const xmlChar*)placeholderName.c_str())) {

          // Return each child element's widget
          for(xmlNodePtr widgetNode = placeholderNode->children;
              widgetNode; widgetNode = widgetNode->next) {

            if(widgetNode->type == XML_ELEMENT_NODE) {

              xmlChar * widgetName = xmlGetProp(widgetNode, (const xmlChar*)"name");
              if(widgetName) {
                children.push_back(get_widget(path + "/"
                                              + (const char*)widgetName));
                xmlFree(widgetName);
              }
            }
          }
        }
        xmlFree(prop);
      }
    }
    xmlFreeDoc(doc);
  }
Beispiel #11
0
  bool LIBXML_DOMDocument::load( std::istream& stream )
  {

    try
    {
      std::stringstream sstream;
      sstream << stream.rdbuf();
      m_pDoc = xmlParseDoc((xmlChar*)sstream.str().c_str());
      return m_pDoc != NULL;
    }
    catch( ... ) { return false; }


  }
Beispiel #12
0
/**
 * Parses the user data XML and copies data into a new ims_subscription structure.
 * @param xml - the input xml
 * @returns the ims_subscription* on success or NULL on error
 */
ims_subscription *parse_user_data(str xml)
{
	xmlDocPtr doc=0;
	xmlNodePtr root=0;
	char c;
	ims_subscription *s;
	if (!ctxtInit) parser_init(scscf_user_data_dtd,scscf_user_data_xsd);	
	doc=0;
	c = xml.s[xml.len];
	xml.s[xml.len]=0;
	doc = xmlParseDoc((unsigned char *)xml.s);
	if (!doc){
		LOG(L_ERR,"ERR:"M_NAME":parse_user_data:  This is not a valid XML <%.*s>\n",
			xml.len,xml.s);
		goto error;
	}
	if (dtdCtxt){
		if (xmlValidateDtd(dtdCtxt,doc,dtd)!=1){
			LOG(L_ERR,"ERR:"M_NAME":parse_user_data:  Verification of XML against DTD failed <%.*s>\n",
				xml.len,xml.s);
			goto error;
		}
	}
	if (xsdCtxt){
		if (xmlSchemaValidateDoc(xsdCtxt,doc)!=0){
			LOG(L_ERR,"ERR:"M_NAME":parse_user_data:  Verification of XML against XSD failed <%.*s>\n",
				xml.len,xml.s);
			goto error;
		}
	}
	root = xmlDocGetRootElement(doc);
	if (!root){
		LOG(L_ERR,"ERR:"M_NAME":parse_user_data:  Empty XML <%.*s>\n",
			xml.len,xml.s);
		goto error;
	}
	s = parse_ims_subscription(doc,root);
	if (!s){
		LOG(L_ERR,"ERR:"M_NAME":parse_user_data:  Error while loading into  ims subscription structure\n");
		goto error;		
	}
	xmlFreeDoc(doc);
//	print_user_data(L_CRIT,s);
	return s;
error:	
	if (doc) xmlFreeDoc(doc);
	xml.s[xml.len]=c;
	return 0;	
}
static void
soup_soap_message_constructed (GObject *object)
{
	SoupSoapMessage *msg = SOUP_SOAP_MESSAGE (object);
	SoupSoapMessagePrivate *priv = msg->priv;

	soup_buffer_free (soup_message_body_flatten (priv->message_body));

	xmlNodePtr current_node, op_node;

	xmlDocPtr doc = xmlParseDoc (BAD_CAST priv->message_body->data);

	if (doc)
	{
		current_node = xmlDocGetRootElement (doc);

		if (current_node &&
		    current_node->name &&
		    xmlStrEqual (current_node->name, BAD_CAST "Envelope"))
		{
			for (current_node = current_node->children;
			     current_node != NULL;
			     current_node = current_node->next)
			{
				if (current_node->type == XML_ELEMENT_NODE)
				{
					if (xmlStrEqual (current_node->name, BAD_CAST "Header"))
						parse_param (priv->header,
						             current_node);
					else if (xmlStrEqual (current_node->name, BAD_CAST "Body"))
					{
						op_node = current_node->children;
						if (op_node)
						{
							soup_soap_param_set_name (SOUP_SOAP_PARAM (priv->body),
							                          (gchar *) op_node->name);
							parse_param (priv->body,
							             op_node);
						}
					}
				}
			}
		}
	}

	xmlFreeDoc (doc);

	G_OBJECT_CLASS (soup_soap_message_parent_class)->constructed (object);
}
Beispiel #14
0
xmlNodePtr GetXmlNodePtrFromString( const string& xml_string ) {	
	xmlNodePtr root_node = 0;
	Xml::DocPtr doc_( xmlParseDoc( BAD_CAST xml_string.c_str() ) );

	if ( doc_ ) {
		root_node = xmlDocGetRootElement( doc_ );
    }
	
	if ( root_node )
	{
		return xmlCopyNode( root_node, 1 );
    }

	return 0;
}
Beispiel #15
0
void wi_p7_message_deserialize(wi_p7_message_t *p7_message) {
	if(p7_message->serialization == WI_P7_BINARY) {
		p7_message->binary_id = wi_read_swap_big_to_host_int32(p7_message->binary_buffer, 0);
		p7_message->name = wi_retain(wi_p7_spec_message_name(p7_message->spec, p7_message->binary_id));
	} else {
		p7_message->xml_doc = xmlParseDoc((xmlChar *) wi_string_cstring(p7_message->xml_string));
		
		if(p7_message->xml_doc) {
			p7_message->xml_root_node = xmlDocGetRootElement(p7_message->xml_doc);
			
			if(p7_message->xml_root_node)
				p7_message->name = wi_retain(wi_p7_xml_string_for_attribute(p7_message->xml_root_node, WI_STR("name")));
		}
	}
}
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);
}
Beispiel #17
0
/**
 * \brief Process startup configuration
 *
 * \param[in] conf plugin configuration structure
 * \param[in] params configuration xml data
 */
void process_startup_xml(plugin_conf *conf, char *params)
{	
	xmlChar *aux_char;
	
	/* Load XML configuration */
	xmlDoc *doc = xmlParseDoc(BAD_CAST params);
	if (!doc) {
		throw std::invalid_argument("Cannot parse config xml");
	}
	
	xmlNode *root = xmlDocGetRootElement(doc);
	if (!root) {
		throw std::invalid_argument("Cannot get document root element!");
	}
	
	/* Set default interval */
	conf->interval = DEFAULT_INTERVAL;

	/* Iterate throught all elements */
	for (xmlNode *node = root->children; node; node = node->next) {
		if (node->type != XML_ELEMENT_NODE) {
			continue;
		}
		
		if (!xmlStrcmp(node->name, (const xmlChar *) "path")) {
			/* Path to RRD files */
			aux_char = xmlNodeListGetString(doc, node->children, 1);
			conf->path = (const char *) aux_char;
			xmlFree(aux_char);
		} else if (!xmlStrcmp(node->name, (const xmlChar *) "interval")) {
			/* Statistics interval */
			aux_char = xmlNodeListGetString(doc, node->children, 1);
			conf->interval = atoi((const char *) aux_char);
			xmlFree(aux_char);
		}
	}
	
	/* Check if we have path to RRD folder */
	if (conf->path.empty()) {
		xmlFreeDoc(doc);
		throw std::invalid_argument("Path to RRD files must be set!");
	}
	
	/* Free resources */
	xmlFreeDoc(doc);
}
Beispiel #18
0
AXIS2_EXTERN axis2_bool_t AXIS2_CALL
savan_xpath_filter_mod_apply(
    savan_filter_mod_t *filtermod,
    const axutil_env_t *env,
    savan_subscriber_t *subscriber,
    axiom_node_t *payload)
{
    axis2_char_t *payload_string = NULL;
    xmlDocPtr payload_doc = NULL;
    xsltStylesheetPtr xslt_template_filter = NULL;
    xmlChar *xfilter = NULL;
    xmlDocPtr result_doc;
    savan_xpath_filter_mod_t *filtermodimpl = NULL;

    filtermodimpl = SAVAN_INTF_TO_IMPL(filtermod);

    AXIS2_LOG_TRACE(env->log, AXIS2_LOG_SI, 
            "[savan] Entry:savan_xpath_filter_mod_apply");

	xfilter = (xmlChar *) savan_subscriber_get_filter(subscriber, env);
	if(!xfilter)
	{
		return AXIS2_FALSE;
	}

    payload_string = axiom_node_to_string(payload, env);
    AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, 
        "[savan] payload_string before applying filter %s:%s", xfilter, payload_string);

    payload_doc = (xmlDocPtr)xmlParseDoc((xmlChar*)payload_string);

    xslt_template_filter = (xsltStylesheetPtr) savan_xpath_filter_mod_get_filter_template(env, 
            filtermodimpl->filter_template_path, xfilter);

    result_doc = (xmlDocPtr)xsltApplyStylesheet(xslt_template_filter, payload_doc, NULL);

    if(result_doc)
    {
        /*free(payload_string);*/ /* In apache freeing this give seg fault:damitha */
	    xmlFreeDoc(result_doc);
        return AXIS2_TRUE;
    }

    AXIS2_LOG_TRACE(env->log, AXIS2_LOG_SI, "[savan] Exit:savan_xpath_filter_mod_apply");
    return AXIS2_FALSE;
}
Beispiel #19
0
xmlelf_t * xmlelf_open_info( elf_t * elf , char * name )
{
   xmlDocPtr  doc;
   xmlelf_t * ret;

   if(!elf||!name)
      error_ret("null args",NULL);

   if(!(ret = calloc(1,sizeof(*ret))))
      perror_die("calloc()",1);

   if(!(doc = xmlParseDoc("1.0"))){
      free(ret);
      error_ret("can't get doc",NULL);
   }
   return(ret);
}
Beispiel #20
0
static int cx_parse_stats_xml(xmlChar* xml, cx_t *db) /* {{{ */
{
  int status;
  xmlDocPtr doc;
  xmlXPathContextPtr xpath_ctx;
  size_t i;

  /* Load the XML */
  doc = xmlParseDoc(xml);
  if (doc == NULL)
  {
    ERROR ("curl_xml plugin: Failed to parse the xml document  - %s", xml);
    return (-1);
  }

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

  for (i = 0; i < db->namespaces_num; i++)
  {
    cx_namespace_t const *ns = db->namespaces + i;
    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);
    }
  }

  status = cx_handle_parsed_xml (doc, xpath_ctx, db);
  /* Cleanup */
  xmlXPathFreeContext(xpath_ctx);
  xmlFreeDoc(doc);
  return status;
} /* }}} cx_parse_stats_xml */
Beispiel #21
0
int test_main(int /*argc*/, char ** /*argv*/)
{
//  std::string markup = "<tags><tag>system:notebook:ggoiiii</tag><tag>system:template</tag></tags>";
  std::string markup = "<tags xmlns=\"http://beatniksoftware.com/tomboy\"><tag>system:notebook:ggoiiii</tag><tag>system:template</tag></tags>";

  xmlDocPtr doc = xmlParseDoc((const xmlChar*)markup.c_str());
  BOOST_CHECK(doc);

  if(doc) {
    std::list<Glib::ustring> tags;
    gnote::NoteBase::parse_tags(xmlDocGetRootElement(doc), tags);
    BOOST_CHECK(!tags.empty());

    xmlFreeDoc(doc);
  }

  return 0;
}
Beispiel #22
0
void parseOhciDB(void)
{
	vendorsFromXML.clear();
	
	xmlDocPtr doc = 0;
	xmlNodePtr cur = 0;
	
	doc = xmlParseDoc((const xmlChar *)ohciDb.memory);
	if (doc == NULL )
	{
		fprintf(stderr,"Document not parsed successfully. \n");
		return;
	}
	
	cur = xmlDocGetRootElement(doc);
	if (cur == NULL)
	{
		fprintf(stderr,"empty document\n");
		xmlFreeDoc(doc);
		return;
	}

	if (xmlStrcmp(cur->name, (const xmlChar *) "ohci1394devices"))
	{
		fprintf(stderr,"document of the wrong type");
		xmlFreeDoc(doc);
		return;
	}
	
	cur = cur->xmlChildrenNode;
	while (cur != NULL)
	{
		if ((!xmlStrcmp(cur->name, (const xmlChar *)"controller")))
		{
			parseController (doc, cur);
		}
		
		cur = cur->next;
	}

	xmlFreeDoc(doc);

    return;
}
Beispiel #23
0
PHP_METHOD(MTF, result){
	char *arg = NULL;
	int arg_len, len;
	char *strg;
	
	zend_update_property_string(object, getThis(), "debug", strlen("debug"), "" TSRMLS_CC);

	array_init(return_value);
	
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &arg, &arg_len) == FAILURE) {
		return;
	}
	xmlDocPtr doc = xmlParseDoc(arg);
	if (doc == NULL ) {
		fprintf(stderr,"Document not parsed successfully. \n");
		return;
	}
	xmlNodePtr cur = xmlDocGetRootElement(doc);
	
	if (cur == NULL) {
		fprintf(stderr,"empty document\n");
		xmlFreeDoc(doc);
		return;
	}
	
	if (xmlStrcmp(cur->name, (const xmlChar *) "Result")) {
		fprintf(stderr,"document of the wrong type, root node != story");
		xmlFreeDoc(doc);
		return;
	}

	if ((!xmlStrcmp(cur->name, (const xmlChar *)"Result"))) {
		//printf("uri: %s\n", xmlGetProp(cur, "Code"));
		xmlAttrPtr attr;
		for(attr = cur->properties; NULL != attr; attr = attr->next){
			//printf("uri: %s\n", xmlGetProp(cur, attr->name));
			add_assoc_string(return_value, attr->name, (char *)xmlGetProp(cur, attr->name), 1);
		}
	}

	xmlFreeDoc(doc);
}
Beispiel #24
0
herror_t
soap_env_new_from_buffer(const char *buffer, SoapEnv ** out)
{
  xmlDocPtr doc;
  herror_t err;

  if (buffer == NULL)
    return herror_new("soap_env_new_from_buffer",
                      GENERAL_INVALID_PARAM, "buffer (first param) is NULL");

  if (!(doc = xmlParseDoc(BAD_CAST buffer)))
    return herror_new("soap_env_new_from_buffer",
                      XML_ERROR_PARSE, "Can not parse xml");

  if ((err = soap_env_new_from_doc(doc, out)) != H_OK)
  {
    xmlFreeDoc(doc);
  }
  return err;
}
Beispiel #25
0
Pvoid_t atom_tokenize(const char * atom) {
	Pvoid_t features = NULL;

	if (atom) {
		xmlDocPtr doc = xmlParseDoc(BAD_CAST atom);
		if (doc) {
			xmlXPathContextPtr context = xmlXPathNewContext(doc);
			xmlXPathRegisterNs(context, BAD_CAST "atom", BAD_CAST "http://www.w3.org/2005/Atom");

			char *html = get_element_value(context, "/atom:entry/atom:content/text()");
			if (html) {
				features = html_tokenize_into_features(html, features);
				xmlFree(html);
			}

			char *title = get_element_value(context, "/atom:entry/atom:title/text()");
			if (title) {
				features = tokenize_text(title, strlen(title), features);
				xmlFree(title);
			}

			char *author = get_element_value(context, "/atom:entry/atom:author/atom:name/text()");
			if (author) {
				features = add_token(author, features);
				xmlFree(author);
			}

			char *link = get_attribute_value(context, "/atom:entry/atom:link[@rel='alternate']", "href");
			if (link) {
				features = tokenize_uri(link, features);
				xmlFree(link);
			}

			xmlXPathFreeContext(context);
		}

		xmlFreeDoc(doc);
	}

	return features;
}
Beispiel #26
0
herror_t
soap_env_new_with_method(const char *urn, const char *method, SoapEnv ** out)
{
  xmlDocPtr env;
  xmlChar buffer[1054];

  log_verbose2("URN = '%s'", urn);
  log_verbose2("Method = '%s'", method);

  if (!strcmp(urn, ""))
  {
#ifdef USE_XMLSTRING
    xmlStrPrintf(buffer, 1054, BAD_CAST _SOAP_MSG_TEMPLATE_EMPTY_TARGET_,
                 soap_env_ns, soap_env_enc, soap_xsi_ns,
                 soap_xsd_ns, BAD_CAST method, BAD_CAST urn, BAD_CAST method);
#else
    sprintf((char *)buffer, _SOAP_MSG_TEMPLATE_EMPTY_TARGET_,
            soap_env_ns, soap_env_enc, soap_xsi_ns,
            soap_xsd_ns, method, urn, method);
#endif
  }
  else
  {
#ifdef USE_XMLSTRING
    xmlStrPrintf(buffer, 1054, BAD_CAST _SOAP_MSG_TEMPLATE_,
                 soap_env_ns, soap_env_enc, soap_xsi_ns,
                 soap_xsd_ns, BAD_CAST method, BAD_CAST urn, BAD_CAST method);
#else
    sprintf((char *)buffer, _SOAP_MSG_TEMPLATE_,
            soap_env_ns, soap_env_enc, soap_xsi_ns,
            soap_xsd_ns, method, urn, method);
#endif

  }

  if (!(env = xmlParseDoc(buffer)))
    return herror_new("soap_env_new_with_method",
                      XML_ERROR_PARSE, "Can not parse xml");

  return soap_env_new_from_doc(env, out);
}
Beispiel #27
0
void SoapExecution::prepareQuery() {
    string xml = "<query xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>";
    xml += getSql();
    xml += "</query>";
    LOG_DEBUG("about to parse");
    xmlDocPtr doc = xmlParseDoc((xmlChar*)xml.c_str());
    xmlNodePtr queryElement = xmlDocGetRootElement(doc);
    xmlNodePtr tmp = queryElement->children;

    xmlNodePtr inputNode = nullptr;
    xmlNodePtr outputNode = nullptr;

    while(tmp) {
        if (tmp->type == XML_ELEMENT_NODE) {
            if (inputNode == nullptr) {
                inputNode = tmp;
            } else {
                outputNode = tmp;
            }
        }
        tmp = tmp->next;
    }

    if (inputNode == nullptr || outputNode == nullptr) {
        THROW_EXC("input or output node missing.");
    }

    LOG_DEBUG("inputNode = " << inputNode->name);
    LOG_DEBUG("outputNode = " << outputNode->name);;

    xmlNodePtr inputQuery = xmlDocCopyNode(inputNode,doc,1);
    xmlNodePtr outputQuery = xmlDocCopyNode(outputNode,doc,1);

    assert(getInPorts().size() == 1);

    inputTemplate.setStylesheet(inputQuery);
    outputTemplate.setStylesheet(outputQuery);

}
Beispiel #28
0
GPInstructProject *
gpinstruct_parser_load_from_string (GPInstructParser *parser,
                                    const gchar *contents,
                                    GError **error)
{
	GPInstructProject *curr_project;

	xmlDocPtr doc = xmlParseDoc (BAD_CAST contents);

	curr_project = create_project_from_xml_document (doc);

	xmlFreeDoc (doc);

	if (!curr_project)
	{
		g_set_error (error, GPINSTRUCT_PARSER_ERROR, GPINSTRUCT_PARSER_ERROR_PARSE,
		             _("Failed to parse file."));
		return NULL;
	}

	return curr_project;
}
video_info* parse_xml(char *xml) {
    int i = 0;
    xmlNode *current;
    xmlDocPtr doc = xmlParseDoc((xmlChar*) xml);
    xmlNode *root = xmlDocGetRootElement(doc);
    video_info *v_info = (video_info*) malloc(sizeof(video_info));
    v_info->id = (char**) malloc(sizeof(char*));
    v_info->titles = (char**) malloc(sizeof(char*));

    for(current = root->children; current; current = current->next) {
        if(!strcmp((char*) current->name, "entry")) {
            xmlNode *current_node;
            for(current_node = current->children; current_node; current_node = current_node->next) {
                if(!strcmp((char*) current_node->name, "title")) {
                    int length = strlen((char*) current_node->children->content);
                    v_info->titles = (char**) realloc(v_info->titles, sizeof(char*) * (i + 1));
                    v_info->titles[i] = (char*) malloc(sizeof(char) * (length + 1));
                    //strncpy to prevent overflow
                    strncpy(v_info->titles[i], (char*) current_node->children->content, length);
                    v_info->titles[i][length] = '\0';
                }
                if(!strcmp((char*) current_node->name, "content")) {
                    v_info->id = (char**) realloc(v_info->id, sizeof(char*) * (i + 1));
                    v_info->id[i] = (char*) malloc(sizeof(char) * (LENGTH + 1));
                    //strncpy to prevent overflow
                    strncpy(v_info->id[i], (char*) current_node->properties->next->children->content + OFFSET, LENGTH);
                    v_info->id[i][LENGTH] = '\0';
                    i++;
                }
            }
        }
    }

    xmlFreeDoc(doc);
    v_info->amount = i;
    return v_info;
}
Beispiel #30
0
/**
 * Parses a notification and creates the r_notification object
 * @param xml - the XML data
 * @returns the new r_notification* or NULL on error
 */
r_notification* r_notification_parse(str xml)
{
	r_notification *n;
	r_registration *r;
	r_regcontact *rc;
	xmlDocPtr doc=0;
	xmlNodePtr root=0,child=0,nephew=0,node=0;
	xmlChar *reginfo_state=0,*x;
	char c=0;
	
	n = pkg_malloc(sizeof(r_notification));
	if (!n) {
		LOG(L_ERR,"ERR:"M_NAME":r_notification_parse: Error allocating %d bytes\n",
			sizeof(r_notification));
		goto error;
	}
	memset(n,0,sizeof(r_notification));

	if (!dtd) parser_init(pcscf_reginfo_dtd);
	doc=0;
	c = xml.s[xml.len];
	xml.s[xml.len]=0;
	doc = xmlParseDoc((unsigned char *)xml.s);
	if (!doc){
		LOG(L_ERR,"ERR:"M_NAME":r_notification_parse:  This is not a valid XML <%.*s>\n",
			xml.len,xml.s);
		goto error;
	}
	if (xmlValidateDtd(&cvp,doc,dtd)!=1){
		LOG(L_ERR,"ERR:"M_NAME":r_notification_parse:  Verification of XML against DTD failed <%.*s>\n",
			xml.len,xml.s);
		goto error;
	}
	root = xmlDocGetRootElement(doc);
	if (!root){
		LOG(L_ERR,"ERR:"M_NAME":r_notification_parse:  Empty XML <%.*s>\n",
			xml.len,xml.s);
		goto error;
	}

	reginfo_state = xmlGetProp(root,(xmlChar*)"state");
	LOG(L_DBG,"DBG:"M_NAME":r_notification_parse: reginfo_state <%s>\n",
			reginfo_state);
	if (reginfo_state[0]=='f'||reginfo_state[0]=='F')
		n->state = IMS_REGINFO_FULL;
	else 
		n->state = IMS_REGINFO_PARTIAL;
	
	for(child = root->children; child; child = child->next)
		if (child->type == XML_ELEMENT_NODE)
	{
		r = pkg_malloc(sizeof(r_registration));
		if (!r){
			LOG(L_ERR,"ERR:"M_NAME":r_notification_parse: Error allocating %d bytes\n",
				sizeof(r_registration));
			goto error;
		}
		memset(r,0,sizeof(r_registration));
		
		x = xmlGetProp(child,(xmlChar*)"id");
		space_trim_dup(&(r->id),(char*)x);
		xmlFree(x);

		x = xmlGetProp(child,(xmlChar*)"aor");
		space_trim_dup(&(r->aor),(char*)x);
		xmlFree(x);
		
		x = xmlGetProp(child,(xmlChar*)"state");
		
		if (x[0]=='a'||x[0]=='A') 
			r->state = IMS_REGINFO_ACTIVE;
		else 
			r->state = IMS_REGINFO_TERMINATED;
		xmlFree(x);

		for(nephew = child->children; nephew; nephew = nephew->next)
				if (nephew->type == XML_ELEMENT_NODE)
		{
			rc = pkg_malloc(sizeof(r_regcontact));
			if (!rc){
				LOG(L_ERR,"ERR:"M_NAME":r_notification_parse: Error allocating %d bytes\n",
					sizeof(r_regcontact));
				goto error;
			}
			memset(rc,0,sizeof(r_regcontact));
			
			x = xmlGetProp(nephew,(xmlChar*)"id");
			space_trim_dup(&(rc->id),(char*)x);
			xmlFree(x);
				
			x = xmlGetProp(nephew,(xmlChar*)"state");
			if (x[0]=='a'||x[0]=='A') 
				rc->state = IMS_REGINFO_ACTIVE;
			else 
				rc->state = IMS_REGINFO_TERMINATED;
			xmlFree(x);
			
			x = xmlGetProp(nephew,(xmlChar*)"event");
			switch(x[0]){
				case 'r':case 'R':
					switch (x[2]){
						case 'g': case 'G':
							rc->event = IMS_REGINFO_CONTACT_REGISTERED;
							break;
						case 'f': case 'F':
							rc->event = IMS_REGINFO_CONTACT_REFRESHED;
							break;						
						case 'j': case 'J':
							rc->event = IMS_REGINFO_CONTACT_REJECTED;
							break;						
						default:
							rc->event = IMS_REGINFO_NONE;
					}
					break;
				case 'c':case 'C':
					rc->event = IMS_REGINFO_CONTACT_CREATED;	
					break;
				case 's':case 'S':
					rc->event = IMS_REGINFO_CONTACT_SHORTENED;	
					break;
				case 'e':case 'E':
					rc->event = IMS_REGINFO_CONTACT_EXPIRED;	
					break;
				case 'd':case 'D':
					rc->event = IMS_REGINFO_CONTACT_DEACTIVATED;	
					break;
				case 'p':case 'P':
					rc->event = IMS_REGINFO_CONTACT_PROBATION;	
					break;
				case 'u':case 'U':
					rc->event = IMS_REGINFO_CONTACT_UNREGISTERED;	
					break;
				default:
					rc->event = IMS_REGINFO_NONE;	
			}
			xmlFree(x);

			x = xmlGetProp(nephew,(xmlChar*)"expires");			
			if (x) {
				rc->expires = atoi((char*)x);
				xmlFree(x);
			}
			
			node = nephew->children;
			while(node && node->type!=XML_ELEMENT_NODE)
				node =node->next;
			if (node) {
				x = xmlNodeGetContent(node);
				space_trim_dup(&(rc->uri),(char*)x);
				xmlFree(x);
			}
			
			rc->next = r->contact;
			r->contact = rc;
		}
		
		r->next = n->registration;
		n->registration = r;
					
	}
			
	if (reginfo_state) xmlFree(reginfo_state);		
	
	if (doc) xmlFreeDoc(doc);
	xml.s[xml.len]=c;
	return n;
error:	
	if (reginfo_state) xmlFree(reginfo_state);		

	if (doc) xmlFreeDoc(doc);
	xml.s[xml.len]=c;
	if (n) r_notification_free(n);
	return 0;
}