Exemple #1
0
/**
 *  Prepare XSLT stylesheet based on command line options
 */
int
selPrepareXslt(xmlDocPtr style, selOptionsPtr ops, xmlChar *ns_arr[],
               int start, int argc, char **argv)
{
    int i, t, ns, use_inputfile = 0, use_value_of = 0;
    xmlNodePtr root, root_template = NULL;
    xmlNsPtr xslns;
    xmlBufferPtr attr_buf;

    root = xmlNewDocRawNode(style, NULL, BAD_CAST "stylesheet", NULL);
    xmlDocSetRootElement(style, root);
    xmlNewProp(root, BAD_CAST "version", BAD_CAST "1.0");
    xslns = xmlNewNs(root, XSLT_NAMESPACE, BAD_CAST "xsl");
    xmlSetNs(root, xslns);

    ns = 0;
    while(ns_arr[ns])
    {
        xmlNewNs(root, ns_arr[ns+1], xmlStrlen(ns_arr[ns])?ns_arr[ns] : NULL);
        ns += 2;
    }
    cleanupNSArr(ns_arr);

    {
        xmlNodePtr output;
        output = xmlNewChild(root, xslns, BAD_CAST "output", NULL);
        xmlNewProp(output, BAD_CAST "omit-xml-declaration",
            BAD_CAST ((ops->no_omit_decl)?"no":"yes"));
        xmlNewProp(output, BAD_CAST "indent",
            BAD_CAST ((ops->indent)?"yes":"no"));
        if (ops->encoding) xmlNewProp(output, BAD_CAST "encoding", ops->encoding);
        if (ops->outText) xmlNewProp(output, BAD_CAST "method", BAD_CAST "text");
    }

    for (i = start, t = 0; i < argc; i++)
        if(!strcmp(argv[i], "-t") || !strcmp(argv[i], "--template"))
            t++;

    /*
     *  At least one -t option must be found
     */
    if (t == 0)
    {
        fprintf(stderr, "error in arguments:");
        fprintf(stderr, " no -t or --template options found\n");
        exit(EXIT_BAD_ARGS);
    }

    if (t > 1)
        root_template = xmlNewChild(root, xslns, BAD_CAST "template", NULL);

    t = 0;
    i = start;
    while(i < argc)
    {
        if(!strcmp(argv[i], "-t") || !strcmp(argv[i], "--template"))
        {
            xmlNodePtr call_template, template;
            int lastTempl = 0;
            t++;
Exemple #2
0
static int processDoc(xmlDoc *doc, lpc2xml_context *ctx) {
	int ret = 0;
	xmlNs *xsi_ns;
	xmlNs *lpc_ns;
	xmlAttr *schemaLocation;
	xmlNode *root_node = xmlNewNode(NULL, (const xmlChar *)"config");
	if(root_node == NULL) {
		lpc2xml_log(ctx, LPC2XML_ERROR, "Can't create \"config\" element");
		return -1;
	}
	lpc_ns = xmlNewNs(root_node, (const xmlChar *)"http://www.linphone.org/xsds/lpconfig.xsd", NULL);
	if(lpc_ns == NULL) {
		lpc2xml_log(ctx, LPC2XML_WARNING, "Can't create lpc namespace");
	} else {
		xmlSetNs(root_node, lpc_ns);
	}
	xsi_ns = xmlNewNs(root_node, (const xmlChar *)"http://www.w3.org/2001/XMLSchema-instance", (const xmlChar *)"xsi");
	if(lpc_ns == NULL) {
		lpc2xml_log(ctx, LPC2XML_WARNING, "Can't create xsi namespace");
	}
	schemaLocation = xmlNewNsProp(root_node, xsi_ns, (const xmlChar *)"schemaLocation", (const xmlChar *)"http://www.linphone.org/xsds/lpconfig.xsd lpconfig.xsd");
	if(schemaLocation == NULL) {
		lpc2xml_log(ctx, LPC2XML_WARNING, "Can't create schemaLocation");
	}
	ret = processConfig(root_node, ctx);
	xmlDocSetRootElement(doc, root_node);
	return ret;
}
Exemple #3
0
static xmlNode*
get_xmlNode(LassoNode *node, gboolean lasso_dump)
{
    xmlNode *xmlnode, *t;

    xmlnode = parent_class->get_xmlNode(node, lasso_dump);

    if (LASSO_SAMLP_RESPONSE(node)->Status &&
            has_lib_status(LASSO_SAMLP_RESPONSE(node)->Status->StatusCode)) {
        /* liberty QName, add liberty namespace */
        xmlNewNs(xmlnode, (xmlChar*)LASSO_LIB_HREF, (xmlChar*)LASSO_LIB_PREFIX);
    }


    for (t = xmlnode->children; t && strcmp((char*)t->name, "Assertion"); t = t->next) ;

    if (t && strcmp((char*)t->ns->href, LASSO_LIB_HREF) == 0) {
        /* liberty nodes are not allowed in samlp nodes */
        xmlSetNs(t, xmlNewNs(xmlnode, (xmlChar*)LASSO_SAML_ASSERTION_HREF,
                             (xmlChar*)LASSO_SAML_ASSERTION_PREFIX));
        if (xmlHasNsProp(t, (xmlChar*)"type", (xmlChar*)LASSO_XSI_HREF) == NULL)
            xmlNewNsProp(t, xmlNewNs(xmlnode,
                                     (xmlChar*)LASSO_XSI_HREF,
                                     (xmlChar*)LASSO_XSI_PREFIX),
                         (xmlChar*)"type", (xmlChar*)"lib:AssertionType");
    }

    return xmlnode;
}
Exemple #4
0
/*
 * Find or construct a (possibly temporary) namespace node
 * for the "func" exslt library and put the given node into
 * that namespace.  We also have to add this as an "extension"
 * namespace.
 */
static xmlNsPtr
slaxSetNs (slax_data_t *sdp, xmlNodePtr nodep,
	   const char *prefix, const xmlChar *uri, int local)
{
    xmlNsPtr nsp;
    xmlNodePtr root = xmlDocGetRootElement(sdp->sd_docp);

    nsp = xmlSearchNs(sdp->sd_docp, root, (const xmlChar *) prefix);
    if (nsp == NULL) {
	nsp = xmlNewNs(root, uri, (const xmlChar *) prefix);
	if (nsp == NULL) {
	    xmlParserError(sdp->sd_ctxt, "%s:%d: out of memory",
			   sdp->sd_filename, sdp->sd_line);
	    return NULL;
	}

	/*
	 * Since we added this namespace, we need to add it to the
	 * list of extension prefixes.
	 */
	slaxNodeAttribExtend(sdp, root,
			     ATT_EXTENSION_ELEMENT_PREFIXES, prefix, NULL);
    }

    if (nodep) {
	/* Add a distinct namespace to the current node */
	nsp = xmlNewNs(nodep, uri, (const xmlChar *) prefix);
	if (local)
	    nodep->ns = nsp;
    }

    return nsp;
}
Exemple #5
0
/**
 * xsltCopyNamespace:
 * @ctxt:  a transformation context
 * @node:  the target node
 * @cur:  the namespace node
 *
 * Do a copy of an namespace node. If @node is non-NULL the
 * new namespaces are added automatically. This handles namespaces
 * aliases
 *
 * Returns: a new xmlNsPtr, or NULL in case of error.
 */
xmlNsPtr
xsltCopyNamespace(xsltTransformContextPtr ctxt, xmlNodePtr node,
	          xmlNsPtr cur) {
    xmlNsPtr ret = NULL;
    const xmlChar *URI;

    if (cur == NULL)
	return(NULL);
    if (cur->type != XML_NAMESPACE_DECL)
	return(NULL);

    /*
     * One can add namespaces only on element nodes
     */
    if ((node != NULL) && (node->type != XML_ELEMENT_NODE))
	node = NULL;

    if (!xmlStrEqual(cur->href, XSLT_NAMESPACE)) {
	URI = (const xmlChar *) xmlHashLookup(ctxt->style->nsAliases,
					      cur->href);
	if (URI != NULL) {
	    ret = xmlNewNs(node, URI, cur->prefix);
	} else {
	    ret = xmlNewNs(node, cur->href, cur->prefix);
	}
    }
    return(ret);
}
int msWFSException11(mapObj *map, const char *locator,
                     const char *exceptionCode, const char *version)
{
  int size = 0;
  char *errorString     = NULL;
  char *errorMessage    = NULL;
  char *schemasLocation = NULL;
  const char *encoding;

  xmlDocPtr  psDoc      = NULL;
  xmlNodePtr psRootNode = NULL;
  xmlNsPtr   psNsOws    = NULL;
  xmlChar *buffer       = NULL;

  if (version == NULL)
    version = "1.1.0";

  psNsOws = xmlNewNs(NULL, BAD_CAST "http://www.opengis.net/ows", BAD_CAST "ows");

  encoding = msOWSLookupMetadata(&(map->web.metadata), "FO", "encoding");

  errorString = msGetErrorString("\n");
  errorMessage = msEncodeHTMLEntities(errorString);
  schemasLocation = msEncodeHTMLEntities(msOWSGetSchemasLocation(map));

  psDoc = xmlNewDoc(BAD_CAST "1.0");

  psRootNode = msOWSCommonExceptionReport(psNsOws, OWS_1_0_0, schemasLocation, version, msOWSGetLanguage(map, "exception"), exceptionCode, locator, errorMessage);

  xmlDocSetRootElement(psDoc, psRootNode);

  xmlNewNs(psRootNode, BAD_CAST "http://www.opengis.net/ows", BAD_CAST "ows");

  if (encoding)
    msIO_setHeader("Content-Type","text/xml; charset=%s", encoding);
  else
    msIO_setHeader("Content-Type","text/xml");
  msIO_sendHeaders();

  xmlDocDumpFormatMemoryEnc(psDoc, &buffer, &size, (encoding ? encoding : "ISO-8859-1"), 1);

  msIO_printf("%s", buffer);

  /*free buffer and the document */
  free(errorString);
  free(errorMessage);
  free(schemasLocation);
  xmlFree(buffer);
  xmlFreeDoc(psDoc);
  xmlFreeNs(psNsOws);

  /* clear error since we have already reported it */
  msResetErrorList();

  return MS_FAILURE;
}
void
soup_soap_message_persist (SoupSoapMessage *msg)
{
	g_return_if_fail (SOUP_SOAP_IS_MESSAGE (msg));

	xmlChar *buffer;
	const gchar *contents;

	SoupSoapMessagePrivate *priv = msg->priv;

	xmlDocPtr doc = xmlNewDoc (BAD_CAST "1.0");


	xmlNodePtr envelope_node = xmlNewNode (NULL, BAD_CAST "Envelope");
	xmlSetNs (envelope_node,
	          xmlNewNs (envelope_node,
	                    BAD_CAST SOAP_ENV_NAMESPACE,
	                    BAD_CAST "SOAP-ENV"));
	xmlNewNs (envelope_node,
	          BAD_CAST XSD_NAMESPACE,
	          BAD_CAST "xsd");
	xmlNewNs (envelope_node,
	          BAD_CAST XSI_NAMESPACE,
	          BAD_CAST "xsi");
	xmlNewNs (envelope_node,
	          BAD_CAST SOAP_ENC_NAMESPACE,
	          BAD_CAST "SOAP-ENC");
	xmlSetProp (envelope_node,
	            BAD_CAST "SOAP-ENV:encodingStyle",
	            BAD_CAST SOAP_ENCODING_STYLE);
	xmlDocSetRootElement (doc, envelope_node);

	create_param_node (doc, SOUP_SOAP_PARAM (priv->header), envelope_node);

	xmlNodePtr body_node = xmlNewChild (envelope_node, NULL, BAD_CAST "Body", NULL);
	create_param_node (doc, SOUP_SOAP_PARAM (priv->body), body_node);


	xmlDocDumpFormatMemoryEnc (doc, &buffer, NULL, "UTF-8", 0);

	contents = (gchar *) buffer;
	soup_message_body_truncate (priv->message_body);
	soup_message_body_append (priv->message_body, SOUP_MEMORY_COPY,
	                          contents, strlen (contents));
	soup_message_body_complete (priv->message_body);

	xmlFree (buffer);


	xmlFreeDoc (doc);


	soup_message_headers_set_content_type (priv->message_headers,
	                                       "text/xml", NULL);
}
Exemple #8
0
void xmpp_ball_start_rolling(struct xmpp_server *xs)
{
	/* F**k it */
	xmpp_printf(xs,"<stream:stream xmlns:stream=\"http://etherx.jabber.org/streams\" xmlns=\"jabber:client\" to=\"%s\" version=\"1.0\">\n", xs->label);
#ifdef CLOWNS
	xmlDocPtr  doc       = NULL;/* document pointer */
	xmlNodePtr root_node = NULL;
	xmlNodePtr node      = NULL;
	xmlNodePtr node1     = NULL;/* node pointers */
	xmlNsPtr   ns_stream = NULL;
	xmlNsPtr   ns_jabber = NULL;

	/* Well commented because libxml2 is a mindfuck */

	/* Starts the document with xml 1.0 */
	doc = xmlNewDoc(BAD_CAST "1.0");

	/* Create the root node */
	root_node = xmlNewNode(NULL, BAD_CAST "stream");

	/* Create the stream namespace */
	ns_stream = xmlNewNs(root_node,
			/* Hardcode OK */
			BAD_CAST "http://etherx.jabber.org/streams",
			/* Hardcode OK */
			BAD_CAST "stream");

	/* Create the jabber namespace */
	ns_jabber = xmlNewNs(root_node,
			/* Hardcode OK */
			BAD_CAST "jabber:client",
			NULL);

	/* Make the node I just created the first node in the document */
	xmlDocSetRootElement(doc, root_node);

	/* Name of the server, should probably go off sslserver or server tag in conf */
	xmlNewProp(root_node, BAD_CAST "to", BAD_CAST xs->label);

	/* I need to meet the requirements of RFC 3920 for this */
	xmlNewProp(root_node, BAD_CAST "version", BAD_CAST "1.0");

	/* Sends XML Packet */
	xmpp_xml_send(xs, doc);

	/* We don't need it anymore */
	xmlFreeDoc(doc);

	return;
#endif /* CLOWNS */
}
Exemple #9
0
/**
 * xsltCopyNamespace:
 * @ctxt:  a transformation context
 * @elem:  the target element node
 * @ns:  the namespace node
 *
 * Copies a namespace node (declaration). If @elem is not NULL,
 * then the new namespace will be declared on @elem.
 *
 * Returns: a new xmlNsPtr, or NULL in case of an error.
 */
xmlNsPtr
xsltCopyNamespace(xsltTransformContextPtr ctxt ATTRIBUTE_UNUSED,
		  xmlNodePtr elem, xmlNsPtr ns)
{
    if ((ns == NULL) || (ns->type != XML_NAMESPACE_DECL))
	return(NULL);
    /*
     * One can add namespaces only on element nodes
     */
    if ((elem != NULL) && (elem->type != XML_ELEMENT_NODE))
	return(xmlNewNs(NULL, ns->href, ns->prefix));
    else
	return(xmlNewNs(elem, ns->href, ns->prefix));
}
Exemple #10
0
static void add_album_art(xmlNodePtr node, int64_t cover_id, query_t * q)
  {
  bg_db_object_t * cover;
  bg_db_object_t * cover_thumb; 
  char * tmp_string;
  xmlNodePtr child;

  cover = bg_db_object_query(q->db, cover_id);
  cover_thumb = bg_db_get_thumbnail(q->db, cover_id, 160, 160, "image/jpeg");

  /* Cover thumbnail */
  if(cover_thumb)
    {
    tmp_string = bg_sprintf("%smedia/%"PRId64, q->dev->url_base, bg_db_object_get_id(cover_thumb));
    child = bg_didl_add_element_string(q->didl, node, "upnp:albumArtURI", tmp_string, NULL);
    free(tmp_string);

    if(child)
      {
      xmlNsPtr dlna_ns;
      dlna_ns = xmlNewNs(child,
                         (xmlChar*)"urn:schemas-dlna-org:metadata-1-0/",
                         (xmlChar*)"dlna");
      xmlSetNsProp(child, dlna_ns, (const xmlChar*)"profileID", (const xmlChar*)"JPEG_TN");
      }
    bg_db_object_unref(cover_thumb);
    }
  /* Original size */
  tmp_string = bg_sprintf("%smedia/%"PRId64, q->dev->url_base, cover_id); 
  child = bg_didl_add_element_string(q->didl, node, "upnp:albumArtURI", tmp_string, NULL);
  free(tmp_string);
  
  if(child)
    {
    const char * dlna_id;
    xmlNsPtr dlna_ns;
    dlna_id = get_dlna_image_profile(cover);
       
    if(dlna_id)
      {
      dlna_ns = xmlNewNs(child,
                         (xmlChar*)"urn:schemas-dlna-org:metadata-1-0/",
                         (xmlChar*)"dlna");
      xmlSetNsProp(child, dlna_ns, (const xmlChar*)"profileID", (const xmlChar*)dlna_id);
      }
    }
  bg_db_object_unref(cover);
  }
Exemple #11
0
 xmlNode* child_node_list::create_element_(const std::string& qname, const std::string& uri)
 {
     // Split QName into prefix and local name.
     std::pair<std::string, std::string> name_pair = detail::split_qname(qname);
     const std::string& prefix = name_pair.first;
     const std::string& name = name_pair.second;
     // Create element without namespace.
     xmlNode* px = xmlNewDocNode( raw_->doc,
                                  0,
                                  detail::to_xml_chars(name.c_str()),
                                  0 );
     if (px == 0)
     {
         std::string what = "fail to create libxml2 element node for " + name;
         throw internal_dom_error(what);
     }
     // Declare XML namespace on the element, and put the element under it.
     xmlNs* ns = xmlNewNs( px,
                           detail::to_xml_chars(uri.c_str()),
                           prefix.empty() ? 0 : detail::to_xml_chars(prefix.c_str()) );
     if (ns == 0)
     {
         // TODO: delete the node.
         std::string what = "fail to create libxml2 namespace for " + prefix + "=" + uri;
         throw internal_dom_error(what);
     }
     xmlSetNs(px, ns);
     // Return the new element.
     return px;
 }
Exemple #12
0
static void
insure_namespace(xmlNode *xmlnode, xmlNs *ns)
{
	/* insure children are kept in saml namespace */
	xmlNode *t;
	xmlNs *xsi_ns;

	t = xmlnode->children;
	while (t) {
		if (t->type != XML_ELEMENT_NODE) {
			t = t->next;
			continue;
		}

		if (xmlnode->ns && strcmp((char*)xmlnode->ns->href, LASSO_LIB_HREF) == 0) {
			char *typename, *gtypename;
			GType gtype;

			typename = g_strdup_printf("lib:%sType", xmlnode->name);
			gtypename = g_strdup_printf("LassoSaml%s", xmlnode->name);
			gtype = g_type_from_name(gtypename);

			if (gtype) {
				xmlSetNs(xmlnode, ns);
				if (xmlHasNsProp(t, (xmlChar*)"type",
							(xmlChar*)LASSO_XSI_HREF) == NULL) {
					xsi_ns = xmlNewNs(xmlnode, (xmlChar*)LASSO_XSI_HREF,
							(xmlChar*)LASSO_XSI_PREFIX);
					xmlNewNsProp(xmlnode, xsi_ns, (xmlChar*)"type",
							(xmlChar*)typename);
				}
			}
			lasso_release(gtypename);
			lasso_release(typename);
		}
static void
gss_config_append_config_file (GString * s)
{
  GList *g;
  xmlNsPtr ns;
  xmlDocPtr doc;

  doc = xmlNewDoc ((xmlChar *) "1.0");

  doc->xmlRootNode = xmlNewDocNode (doc, NULL, (xmlChar *) "oberon", NULL);
  ns = xmlNewNs (doc->xmlRootNode,
      (xmlChar *) "http://entropywave.com/oberon/1.0/", (xmlChar *) "ew");

  for (g = config_list; g; g = g_list_next (g)) {
    GObject *object = g->data;

    gss_config_dump_object (object, ns, doc->xmlRootNode);
  }

  {
    xmlChar *str;
    int len;
    xmlDocDumpFormatMemory (doc, &str, &len, 1);
    g_string_append (s, (char *) str);
    xmlFree (str);
  }

  xmlFreeDoc (doc);
}
Exemple #14
0
/*
 * Create new document and edit document handlers
 */
static int new_xml_doc(lua_State *L) {
	const char *name = lua_tostring(L, 1);
	const char *ns_href = lua_tostring(L, 2);
	xmlNsPtr ns = NULL;

	if (name == NULL) return luaL_error(L, "new_xml_doc needs name of root node.");
	/**
	 * http://www.acooke.org/cute/Usinglibxm0.html was very helpful with this issue
	 */
	xmlDocPtr doc = xmlNewDoc(BAD_CAST "1.0"); //create document
	xmlNodePtr root_node = xmlNewNode(NULL, BAD_CAST name); //create root node

	if (doc == NULL || root_node == NULL) return luaL_error(L, "New document allocation error.");

	if (ns_href != NULL) { //if NS is requested
		ns = xmlNewNs(root_node, BAD_CAST ns_href, NULL);
		if (ns == NULL) return luaL_error(L, "Namespace allocation error.");
		xmlSetNs(root_node, ns);
	}

	struct xmlwrap_object *xml2 = lua_newuserdata(L, sizeof(*xml2));
	luaL_setmetatable(L, WRAP_XMLDOC);

	xml2->doc = doc;
	xmlDocSetRootElement(xml2->doc, root_node);


	return 1;
}
Exemple #15
0
static int node_add_child(lua_State *L) {
	xmlNodePtr node = lua_touserdata(L, 1);
	const char *name = lua_tostring(L, 2);
	const char *ns_href = lua_tostring(L, 3);
	xmlNsPtr ns = NULL;

	if (node == NULL) return luaL_error(L, "add_child: Invalid parent node");
	if (node->type != XML_ELEMENT_NODE) return luaL_error(L, "add_child: Invalid parent node type  (not element node)");
	if (name == NULL) return luaL_error(L, "I can't create node without its name");

	xmlNodePtr child;

	if (ns_href != NULL) { //add namespace requested
		ns = xmlSearchNsByHref(node->doc, node, BAD_CAST ns_href); //try to find ns
	}

	if (ns_href != NULL && ns == NULL) { //ns requested and not found
		child = xmlNewChild(node, ns, BAD_CAST name, NULL); //crete node w/o ns
		ns = xmlNewNs(child, BAD_CAST ns_href, NULL); //create namespace and define it in child
		if (ns == NULL) return luaL_error(L, "Namespace allocation error.");
		xmlSetNs(child, ns); //set new ns to child
	} else {
		child = xmlNewChild(node, ns, BAD_CAST name, NULL); //ns nor requested ir was found... use it
	}

	lua_pushlightuserdata(L, child);
	luaL_setmetatable(L, WRAP_XMLNODE);

	return 1;
}
Exemple #16
0
xmlNodePtr msOWSCommonOperationsMetadataOperation(xmlNsPtr psNsOws, xmlNsPtr psXLinkNs, char *name, int method, char *url)
{
  xmlNodePtr psRootNode      = NULL;
  xmlNodePtr psNode          = NULL;
  xmlNodePtr psSubNode       = NULL;
  xmlNodePtr psSubSubNode    = NULL;

  if (_validateNamespace(psNsOws) == MS_FAILURE)
    psNsOws = xmlNewNs(psRootNode, BAD_CAST MS_OWSCOMMON_OWS_NAMESPACE_URI, BAD_CAST MS_OWSCOMMON_OWS_NAMESPACE_PREFIX);


  psRootNode = xmlNewNode(psNsOws, BAD_CAST "Operation");

  xmlNewProp(psRootNode, BAD_CAST "name", BAD_CAST name);

  psNode = xmlNewChild(psRootNode, psNsOws, BAD_CAST "DCP", NULL);

  psSubNode = xmlNewChild(psNode, psNsOws, BAD_CAST "HTTP", NULL);

  if (method  == OWS_METHOD_GET || method == OWS_METHOD_GETPOST ) {
    psSubSubNode = xmlNewChild(psSubNode, psNsOws, BAD_CAST "Get", NULL);
    xmlNewNsProp(psSubSubNode, psXLinkNs, BAD_CAST "type", BAD_CAST "simple");
    xmlNewNsProp(psSubSubNode, psXLinkNs, BAD_CAST "href", BAD_CAST url);
  }

  if (method == OWS_METHOD_POST || method == OWS_METHOD_GETPOST ) {
    psSubSubNode = xmlNewChild(psSubNode, psNsOws, BAD_CAST "Post", NULL);
    xmlNewNsProp(psSubSubNode, psXLinkNs, BAD_CAST "type", BAD_CAST "simple");
    xmlNewNsProp(psSubSubNode, psXLinkNs, BAD_CAST "href", BAD_CAST url);
  }

  return psRootNode;
}
Exemple #17
0
static xmlNode*
get_xmlNode(LassoNode *node, G_GNUC_UNUSED gboolean lasso_dump)
{
	xmlNode *xmlnode;
	LassoIdentity *identity = LASSO_IDENTITY(node);
#ifdef LASSO_WSF_ENABLED
	xmlNode *t;
#endif

	xmlnode = xmlNewNode(NULL, (xmlChar*)"Identity");
	xmlSetNs(xmlnode, xmlNewNs(xmlnode, (xmlChar*)LASSO_LASSO_HREF, NULL));
	xmlSetProp(xmlnode, (xmlChar*)"Version", (xmlChar*)"2");

	/* Federations */
	if (g_hash_table_size(identity->federations))
		g_hash_table_foreach(identity->federations,
				(GHFunc)add_childnode_from_hashtable, xmlnode);
#ifdef LASSO_WSF_ENABLED
	/* Resource Offerings */
	g_hash_table_foreach(identity->private_data->resource_offerings_map,
			(GHFunc)add_childnode_from_hashtable, xmlnode);

	/* Service Metadatas IDs (svcMDID) */
	if (identity->private_data->svcMDID != NULL) {
		t = xmlNewTextChild(xmlnode, NULL, (xmlChar*)"SvcMDIDs", NULL);
		g_list_foreach(identity->private_data->svcMDID,
				(GFunc)add_text_childnode_from_list, t);
	}
#endif

	return xmlnode;
}
Exemple #18
0
static xmlNodePtr
phone_number_to_xmlnode (GDataEntryPhoneNumber *number)
{

	xmlNodePtr number_node;

	number_node = xmlNewNode(NULL, (xmlChar *)"phoneNumber");
	xmlSetNs (number_node, xmlNewNs (number_node, NULL, (xmlChar *)"gd"));
	if (number->uri)
		xmlSetProp (number_node, (xmlChar *)"uri", (xmlChar *)number->uri);

	if (number->rel)
		xmlSetProp (number_node, (xmlChar *)"rel", (xmlChar *)number->rel);

	if (number->label)
		xmlSetProp (number_node, (xmlChar *)"label", (xmlChar *)number->label);
	
	if (number->primary)
		xmlSetProp (number_node, (xmlChar *)"primary", (xmlChar *)"true");

	if (number->number)
		xmlNodeAddContent(number_node, (xmlChar *)number->number);

	return number_node;
}
Exemple #19
0
xmlNodePtr msOWSCommonWGS84BoundingBox(xmlNsPtr psNsOws, int dimensions, double minx, double miny, double maxx, double maxy)
{
  char LowerCorner[100];
  char UpperCorner[100];
  char dim_string[100];

  xmlNodePtr psRootNode = NULL;

  if (_validateNamespace(psNsOws) == MS_FAILURE)
    psNsOws = xmlNewNs(psRootNode, BAD_CAST MS_OWSCOMMON_OWS_NAMESPACE_URI, BAD_CAST MS_OWSCOMMON_OWS_NAMESPACE_PREFIX);

  /* create element name */
  psRootNode = xmlNewNode(psNsOws, BAD_CAST "WGS84BoundingBox");

  snprintf( dim_string, sizeof(dim_string), "%d", dimensions );
  xmlNewProp(psRootNode, BAD_CAST "dimensions", BAD_CAST dim_string);

  snprintf(LowerCorner, sizeof(LowerCorner), "%.15g %.15g", minx, miny);
  snprintf(UpperCorner, sizeof(UpperCorner), "%.15g %.15g", maxx, maxy);

  /* add child elements */
  xmlNewChild(psRootNode, psNsOws,BAD_CAST "LowerCorner",BAD_CAST LowerCorner);
  xmlNewChild(psRootNode, psNsOws,BAD_CAST "UpperCorner",BAD_CAST UpperCorner);

  return psRootNode;
}
static xmlNodePtr
add_project (GPInstructProject *project)
{
	GPInstructCategory *curr_category;
	GList *categories, *curr_categories;

	xmlNodePtr node = xmlNewNode (NULL, BAD_CAST "project");
	xmlSetProp (node, BAD_CAST "title",
	            BAD_CAST gpinstruct_project_get_title (project));

	xmlSetNs (node, xmlNewNs (node,
	                          BAD_CAST PACKAGE_URL,
	                          BAD_CAST PACKAGE_TARNAME));

	categories = gpinstruct_project_get_categories (project);
	curr_categories = categories;

	while (curr_categories)
	{
		curr_category = GPINSTRUCT_CATEGORY (curr_categories->data);

		add_category (curr_category, node);

		curr_categories = curr_categories->next;
	}

	g_list_free (categories);

	return node;
}
Exemple #21
0
#include "RS_XML.h"
#include <libxml/xpath.h>
#include "Utils.h"



static SEXP
convertNodeSetToR(xmlNodeSetPtr obj, SEXP fun, int encoding, SEXP manageMemory)
{
  SEXP ans, expr = NULL, arg = NULL, ref;
  int i;

  if(!obj)
     return(NULL_USER_OBJECT);

  PROTECT(ans = NEW_LIST(obj->nodeNr));

  if(GET_LENGTH(fun) && (TYPEOF(fun) == CLOSXP || TYPEOF(fun) == BUILTINSXP)) {
    PROTECT(expr = allocVector(LANGSXP, 2));
    SETCAR(expr, fun);
    arg = CDR(expr);
  } else if(TYPEOF(fun) == LANGSXP) {
    expr = fun;
    arg = CDR(expr);
  }

  for(i = 0; i < obj->nodeNr; i++) {
      xmlNodePtr el;
      el = obj->nodeTab[i];
      if(el->type == XML_ATTRIBUTE_NODE) {
#if 0
	  PROTECT(ref = mkString((el->children && el->children->content) ? XMLCHAR_TO_CHAR(el->children->content) : ""));
	  SET_NAMES(ref, mkString(el->name));
#else
	  PROTECT(ref = ScalarString(mkCharCE((el->children && el->children->content) ? XMLCHAR_TO_CHAR(el->children->content) : "", encoding)));
	  SET_NAMES(ref, ScalarString(mkCharCE(el->name, encoding)));
#endif
	  SET_CLASS(ref, mkString("XMLAttributeValue"));
	  UNPROTECT(1);
      } else if(el->type == XML_NAMESPACE_DECL)
	  ref = R_createXMLNsRef((xmlNsPtr) el);
      else
        ref = R_createXMLNodeRef(el, manageMemory);

    if(expr) {
      PROTECT(ref);
      SETCAR(arg, ref);
      PROTECT(ref = Rf_eval(expr, R_GlobalEnv)); /*XXX do we want to catch errors here? Maybe to release the namespaces. */
      SET_VECTOR_ELT(ans, i, ref);
      UNPROTECT(2);
    } else
      SET_VECTOR_ELT(ans, i, ref);
  }

  if(expr) {
    if(TYPEOF(fun) == CLOSXP || TYPEOF(fun) == BUILTINSXP)
      UNPROTECT(1);
  } else
    SET_CLASS(ans, mkString("XMLNodeSet"));

  UNPROTECT(1);

  return(ans);
}

SEXP
convertXPathObjectToR(xmlXPathObjectPtr obj, SEXP fun, int encoding, SEXP manageMemory)
{
  SEXP ans = NULL_USER_OBJECT;

  switch(obj->type) {

    case XPATH_NODESET:
        ans = convertNodeSetToR(obj->nodesetval, fun, encoding, manageMemory);
	break;
    case XPATH_BOOLEAN:
	ans = ScalarLogical(obj->boolval);
	break;
    case XPATH_NUMBER:
	ans = ScalarReal(obj->floatval);
	if(xmlXPathIsInf(obj->floatval))
	    REAL(ans)[0] = xmlXPathIsInf(obj->floatval) < 0 ? R_NegInf : R_PosInf;
        else if(xmlXPathIsNaN(obj->floatval))
	    REAL(ans)[0] = NA_REAL;
	break;
    case XPATH_STRING:
        ans = mkString(XMLCHAR_TO_CHAR(obj->stringval)); //XXX encoding 
	break;
    case XPATH_POINT:
    case XPATH_RANGE:
    case XPATH_LOCATIONSET:
    case XPATH_USERS:
	PROBLEM "currently unsupported xmlXPathObject type %d in convertXPathObjectToR. Please send mail to maintainer.", obj->type
        WARN
    default:
	ans = R_NilValue;
  }

  return(ans);
}


#include <libxml/xpathInternals.h> /* For xmlXPathRegisterNs() */
xmlNsPtr *
R_namespaceArray(SEXP namespaces, xmlXPathContextPtr ctxt)
{
 int i, n;
 SEXP names = GET_NAMES(namespaces);
 xmlNsPtr *els;

 n = GET_LENGTH(namespaces);
 els = xmlMallocAtomic(sizeof(xmlNsPtr) * n); 
 
 if(!els) {
   PROBLEM  "Failed to allocated space for namespaces"
   ERROR;
 }

 for(i = 0; i < n; i++) {
/*XXX who owns these strings. */
   const xmlChar *prefix, *href;
   href = CHAR_TO_XMLCHAR(strdup(CHAR_DEREF(STRING_ELT(namespaces, i))));
   prefix = names == NULL_USER_OBJECT ?  CHAR_TO_XMLCHAR("") /* NULL */ 
                                      :  CHAR_TO_XMLCHAR(strdup(CHAR_DEREF(STRING_ELT(names, i))));
   els[i] = xmlNewNs(NULL, href, prefix);
   if(ctxt) 
       xmlXPathRegisterNs(ctxt, prefix, href);
 }

 return(els);
}
Exemple #22
0
/**
 * xsltGetSpecialNamespace:
 * @ctxt:  a transformation context
 * @cur:  the input node
 * @URI:  the namespace URI
 * @prefix:  the suggested prefix
 * @out:  the output node (or its parent)
 *
 * Find the right namespace value for this URI, if needed create
 * and add a new namespace decalaration on the node
 *
 * Returns the namespace node to use or NULL
 */
xmlNsPtr
xsltGetSpecialNamespace(xsltTransformContextPtr ctxt, xmlNodePtr cur,
		const xmlChar *URI, const xmlChar *prefix, xmlNodePtr out) {
    xmlNsPtr ret;
    static int prefixno = 1;
    char nprefix[10];

    if ((ctxt == NULL) || (cur == NULL) || (out == NULL) || (URI == NULL))
	return(NULL);

    if ((out->parent != NULL) &&
	(out->parent->type == XML_ELEMENT_NODE) &&
	(out->parent->ns != NULL) &&
	(xmlStrEqual(out->parent->ns->href, URI)))
	ret = out->parent->ns;
    else
	ret = xmlSearchNsByHref(out->doc, out, URI);

    if (ret == NULL) {
	if (prefix == NULL) {
	    do {
		sprintf(nprefix, "ns%d", prefixno++);
		ret = xmlSearchNs(out->doc, out, (xmlChar *)nprefix);
	    } while (ret != NULL);
	    prefix = (const xmlChar *) &nprefix[0];
	}
	if (out->type == XML_ELEMENT_NODE)
	    ret = xmlNewNs(out, URI, prefix);
    }
    return(ret);
}
Exemple #23
0
EPUB3_XML_BEGIN_NAMESPACE

Namespace::Namespace(Document * doc, const string &prefix, const string &uri)
{
    xmlDocPtr d = doc->xml();
    _xml = xmlNewNs(reinterpret_cast<xmlNodePtr>(d), uri.utf8(), prefix.utf8());
}
gchar *midgard_core_object_to_xml(GObject *object)
{
	g_assert(object);
	
	xmlDocPtr doc = NULL; 
	xmlNodePtr root_node = NULL;
		
	LIBXML_TEST_VERSION;
		
	doc = xmlNewDoc(BAD_CAST "1.0");
	root_node = xmlNewNode(NULL, 
			BAD_CAST "midgard_object");
	xmlNewNs(root_node,
			BAD_CAST MIDGARD_OBJECT_HREF,
			NULL);
	xmlNodePtr object_node = 
		xmlNewNode(NULL, BAD_CAST G_OBJECT_TYPE_NAME(G_OBJECT(object)));
	/* Add purged info */
	/* We could add this attribute in _write_nodes function 
	 * but this could corrupt xsd compatibility for midgard_metadata nodes.
	 * So it's added here and for every multilingual content */
	xmlNewProp(object_node, BAD_CAST "purge", BAD_CAST "no");
	xmlAddChild(root_node, object_node);
	xmlDocSetRootElement(doc, root_node);
	_write_nodes(G_OBJECT(object), object_node);

	xmlChar *buf;
	gint size;
	xmlDocDumpFormatMemoryEnc(doc, &buf, &size, "UTF-8", 1);
	
	xmlFreeDoc(doc);
	xmlCleanupParser();

	return (gchar*) buf;
}
Exemple #25
0
static inline int ds_sds_compose_component_add_script_content(xmlNode *component, const char *filepath)
{
	FILE* f = fopen(filepath, "r");
	if (!f) {
		oscap_seterr(OSCAP_EFAMILY_GLIBC, "Can't read plain text from file '%s'.", filepath);
		return -1;
	}

	fseek(f, 0, SEEK_END);
	long int length = ftell(f);
	fseek(f, 0, SEEK_SET);
	if (length >= 0) {
		char* buffer = oscap_alloc((length + 1) * sizeof(char));
		if (fread(buffer, length, 1, f) != 1) {
			oscap_seterr(OSCAP_EFAMILY_GLIBC, "Error while reading from file '%s'.", filepath);
			fclose(f);
			oscap_free(buffer);
			return -1;
		}
		fclose(f);
		buffer[length] = '\0';
		xmlNsPtr local_ns = xmlNewNs(component, BAD_CAST sce_xccdf_ns_uri, BAD_CAST "oscap-sce-xccdf-stream");
		xmlNewTextChild(component, local_ns, BAD_CAST "script", BAD_CAST buffer);
		oscap_free(buffer);
		return 0;
	} else {
		oscap_seterr(OSCAP_EFAMILY_GLIBC, "No data read from file '%s'.", filepath);
		fclose(f);
		return -1;
	}
}
Exemple #26
0
static xmlNodePtr
organization_to_xmlnode (GDataEntryOrganization *organization)
{

	xmlNodePtr organization_node;

	organization_node = xmlNewNode(NULL, (xmlChar *)"organization");
	xmlSetNs (organization_node, xmlNewNs (organization_node, NULL, (xmlChar *)"gd"));
	if (organization->rel)
		xmlSetProp (organization_node, (xmlChar *)"rel", (xmlChar *)organization->rel);

	if (organization->label)
		xmlSetProp (organization_node, (xmlChar *)"label", (xmlChar *)organization->label);
	
	if (organization->primary)
		xmlSetProp (organization_node, (xmlChar *)"primary", (xmlChar *)"true");

	if (organization->name)
		xmlNewTextChild (organization_node, NULL, (xmlChar *)"orgName", (xmlChar *)organization->name);

	if (organization->title)
		xmlNewTextChild (organization_node, NULL, (xmlChar *)"orgTitle", (xmlChar *)organization->title);

	return organization_node;
}
Exemple #27
0
xmlNode *oscap_reference_to_dom(struct oscap_reference *ref, xmlNode *parent, xmlDoc *doc, const char *elname)
{
    if (!ref) return NULL;
    xmlNode *ref_node = xmlNewChild(parent, NULL, BAD_CAST elname, NULL);

    if (ref->href != NULL)
        xmlNewProp(ref_node, BAD_CAST "href", BAD_CAST ref->href);

    if (!ref->is_dublincore) {
        xmlNodeAddContent(ref_node, BAD_CAST ref->title);
        return ref_node;
    }
    
    xmlNs *ns_dc = xmlSearchNsByHref(doc, parent, NS_DUBLINCORE);
    if (ns_dc == NULL) // the namespace hasn't been defined in ancestor elements
        ns_dc = xmlNewNs(ref_node, NS_DUBLINCORE, BAD_CAST "dc");

    DC_ITEM_TO_DOM(title);
    DC_ITEM_TO_DOM(creator);
    DC_ITEM_TO_DOM(subject);
    DC_ITEM_TO_DOM(description);
    DC_ITEM_TO_DOM(publisher);
    DC_ITEM_TO_DOM(contributor);
    DC_ITEM_TO_DOM(date);
    DC_ITEM_TO_DOM(type);
    DC_ITEM_TO_DOM(format);
    DC_ITEM_TO_DOM(identifier);
    DC_ITEM_TO_DOM(source);
    DC_ITEM_TO_DOM(language);
    DC_ITEM_TO_DOM(relation);
    DC_ITEM_TO_DOM(coverage);
    DC_ITEM_TO_DOM(rights);

    return ref_node;
}
Exemple #28
0
enum jal_status jal_create_audit_transforms_elem(
    xmlDocPtr doc,
    xmlNodePtr *new_elem)
{
    if (!new_elem || *new_elem || !doc) {
        return JAL_E_XML_CONVERSION;
    }

    xmlChar *namespace_uri = (xmlChar *)JAL_XMLDSIG_URI;

    xmlNodePtr out_elem = xmlNewDocNode(doc, NULL, (xmlChar *) JAL_XML_TRANSFORMS, NULL);
    xmlNsPtr ns = xmlNewNs(out_elem, namespace_uri, NULL);
    xmlSetNs(out_elem, ns);

    xmlNodePtr transform_elem = xmlNewChild(
                                    out_elem, NULL,
                                    (xmlChar *) JAL_XML_TRANSFORM,
                                    NULL);

    xmlSetProp(transform_elem,
               (xmlChar *) JAL_XML_ALGORITHM, (xmlChar *) JAL_XML_WITH_COMMENTS);

    *new_elem = out_elem;

    return JAL_OK;
}
Exemple #29
0
wi_p7_message_t * wi_p7_message_init_with_name(wi_p7_message_t *p7_message, wi_string_t *message_name, wi_p7_socket_t *p7_socket) {
	p7_message = wi_p7_message_init(p7_message, p7_socket);

	if(p7_message->serialization == WI_P7_BINARY) {
		p7_message->binary_capacity	= _WI_P7_MESSAGE_BINARY_BUFFER_INITIAL_SIZE;
		p7_message->binary_buffer	= wi_malloc(p7_message->binary_capacity);
		p7_message->binary_size		= _WI_P7_MESSAGE_BINARY_HEADER_SIZE;
	} else {
		p7_message->xml_doc			= xmlNewDoc((xmlChar *) "1.0");
		p7_message->xml_root_node	= xmlNewNode(NULL, (xmlChar *) "message");

		xmlDocSetRootElement(p7_message->xml_doc, p7_message->xml_root_node);
			
		p7_message->xml_ns = xmlNewNs(p7_message->xml_root_node, (xmlChar *) "http://www.zankasoftware.com/P7/Message", (xmlChar *) "p7");
		xmlSetNs(p7_message->xml_root_node, p7_message->xml_ns);
	}

	if(!wi_p7_message_set_name(p7_message, message_name)) {
		wi_release(p7_message);
		
		return NULL;
	}
	
	return p7_message;
}
Exemple #30
0
enum jal_status jal_create_base64_element(
    xmlDocPtr doc,
    const uint8_t *buffer,
    const size_t buf_len,
    const xmlChar *namespace_uri,
    const xmlChar *elm_name,
    xmlNodePtr *new_elem)
{
    if (!doc || !buffer || (buf_len == 0) || !namespace_uri ||
            !elm_name || !new_elem || *new_elem) {
        return JAL_E_INVAL;
    }
    char *base64_val = NULL;
    xmlChar *xml_base64_val = NULL;

    base64_val = jal_base64_enc(buffer, buf_len);
    if (!base64_val) {
        // this should never actually happen since the input is
        // non-zero in length.
        return JAL_E_INVAL;
    }

    xml_base64_val = (xmlChar *)base64_val;

    xmlNodePtr elm = xmlNewDocNode(doc, NULL, elm_name, NULL);
    xmlNsPtr ns = xmlNewNs(elm, namespace_uri, NULL);
    xmlSetNs(elm, ns);
    xmlNodeAddContent(elm, xml_base64_val);

    free(base64_val);
    *new_elem = elm;
    return JAL_OK;
}