Пример #1
0
/* {{{ proto void DOMDocumentFragment::appendXML(string data); */
PHP_METHOD(domdocumentfragment, appendXML) {
	zval *id;
	xmlNode *nodep;
	dom_object *intern;
	char *data = NULL;
	int data_len = 0;
	int err;
	xmlNodePtr lst;

	if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os", &id, dom_documentfragment_class_entry, &data, &data_len) == FAILURE) {
		return;
	}

	DOM_GET_OBJ(nodep, id, xmlNodePtr, intern);

	if (dom_node_is_read_only(nodep) == SUCCESS) {
		php_dom_throw_error(NO_MODIFICATION_ALLOWED_ERR, dom_get_strict_error(intern->document) TSRMLS_CC);
		RETURN_FALSE;
	}

	if (data) {
		err = xmlParseBalancedChunkMemory(nodep->doc, NULL, NULL, 0, data, &lst);
		if (err != 0) {
			RETURN_FALSE;
		}
		/* Following needed due to bug in libxml2 <= 2.6.14 
		ifdef after next libxml release as bug is fixed in their cvs */
		php_dom_xmlSetTreeDoc(lst, nodep->doc);
		/* End stupid hack */

		xmlAddChildList(nodep,lst);
	}

	RETURN_TRUE;
}
Пример #2
0
void XMLElement::setChildren(const XMLNodeList & list) const
{
    xmlNode *n = list.getRealNode();
    if (n && n->parent != node)
    {
        xmlNode *cpy = xmlCopyNodeList(n);
        xmlUnlinkNode(node->children);
        xmlFreeNodeList(node->children);
        node->children = 0;
        xmlAddChildList(node, cpy);
    }
}
Пример #3
0
void
MetaBlock::call(boost::shared_ptr<Context> ctx, boost::shared_ptr<InvokeContext> invoke_ctx) const throw (std::exception) {
    (void)ctx;
    XmlDocHelper doc(xmlNewDoc((const xmlChar*) "1.0"));
    XmlUtils::throwUnless(NULL != doc.get());

    XmlNodeHelper node(xmlNewNode(NULL, (const xmlChar*)root_name_.c_str()));
    XmlUtils::throwUnless(NULL != node.get());
    if (root_ns_) {
        node->nsDef = xmlCopyNamespace(root_ns_);
        xmlSetNs(node.get(), node->nsDef);
    }

    XmlNodeHelper meta_info = invoke_ctx->meta()->getXml();
    if (NULL != meta_info.get()) {
        xmlAddChildList(node.get(), meta_info.release());
    }

    xmlDocSetRootElement(doc.get(), node.release());
    invoke_ctx->metaDoc(doc);
}
Пример #4
0
static gboolean snippets_import_load_finished_lcb(gpointer data) {
	Tsnippets_import *si = (Tsnippets_import *)data;
	DEBUG_SIG("snippets_import_load_finished_lcb, priority=%d\n",G_PRIORITY_LOW);
	if (si->doc) {
		xmlNodePtr cur;
		cur = xmlDocGetRootElement(si->doc);
		if (cur) {
			if (xmlStrEqual(cur->name, (const xmlChar *) "snippets")) {
				xmlNodePtr newnode;
				/* now import everything below */
				newnode = xmlDocCopyNodeList(snippets_v.doc, cur->children);
				xmlAddChildList(si->parent,newnode);
				reload_tree_from_doc();
				g_idle_add(snippets_store_lcb, NULL);
			}
		}
		xmlFreeDoc(si->doc);
	}
	g_free(si->filename);
	g_free(si);
	return FALSE;
}
Пример #5
0
static ValueStruct *_WriteXML(DBG_Struct *dbg, DBCOMM_CTRL *ctrl,
                              RecordStruct *rec, ValueStruct *args) {
  ValueStruct *ret;
  xmlNodePtr root;
  xmlNodePtr node;
  ret = NULL;
  if (rec->type != RECORD_DB) {
    ctrl->rc = MCP_BAD_ARG;
    return NULL;
  }
  if (XMLDoc == NULL || XMLmode != MODE_WRITE) {
    ctrl->rc = MCP_BAD_OTHER;
    return NULL;
  }
  root = xmlDocGetRootElement(XMLDoc);
  node = Value2XMLNode(NULL, args);
  if (node != NULL) {
    xmlAddChildList(root, node);
  }
  ctrl->rc = MCP_OK;
  return (ret);
}
Пример #6
0
xmlNodePtr users_getxml(xmlNsPtr ns, char** msg)
{
	xmlNodePtr auth_node, user, aux_node;
	struct passwd *pwd;
	struct spwd *spwd;
	const char* value;
	char *path = NULL;

	if (!ncds_feature_isenabled("ietf-system", "local-users")) {
		return (NULL);
	}

	/* authentication */
	auth_node = xmlNewNode(ns, BAD_CAST "authentication");

	/* authentication/user-authentication-order */
	asprintf(&path, "/files/%s/PasswordAuthentication", NETOPEER_SSHD_CONF);
	aug_get(sysaugeas, path, &value);
	free(path);
	if (value != NULL && strcmp(value, "yes") == 0) {
		xmlNewChild(auth_node, auth_node->ns, BAD_CAST "user-authentication-order", BAD_CAST "local-users");
	}

	/* authentication/user[] */
	if (lckpwdf() != 0) {
		*msg = strdup("Failed to acquire shadow file lock.");
		xmlFreeNode(auth_node);
		return (NULL);
	}

	setpwent();

	while ((pwd = getpwent()) != NULL) {
		/* authentication/user */
		user = xmlNewChild(auth_node, auth_node->ns, BAD_CAST "user", NULL);

		/* authentication/user/name */
		xmlNewChild(user, user->ns, BAD_CAST "name", BAD_CAST pwd->pw_name);

		/* authentication/user/passwd */
		if (pwd->pw_passwd[0] == 'x') {
			/* get data from /etc/shadow */
			setspent();
			spwd = getspnam(pwd->pw_name);
			if (spwd != NULL && /* no record, wtf?!? */
					spwd->sp_pwdp[0] != '!' && /* account not initiated or locked */
					spwd->sp_pwdp[0] != '*') { /* login disabled */
				xmlNewChild(user, user->ns, BAD_CAST "password", BAD_CAST spwd->sp_pwdp);
			}
		} else if (pwd->pw_passwd[0] != '*') {
			/* password is stored in /etc/passwd or refers to something else (e.g., NIS server) */
			xmlNewChild(user, user->ns, BAD_CAST "password", BAD_CAST pwd->pw_passwd);
		} /* else password is disabled */

		/* authentication/user/authorized-key[] */
		if ((aux_node = authkey_getxml(pwd->pw_name, user->ns, msg)) != NULL) {
			xmlAddChildList(user, aux_node);
		} else {
			/* ignore failures in this case */
			free(*msg);
			*msg = NULL;
		}
	}

	endspent();
	endpwent();
	ulckpwdf();

	return (auth_node);
}
Пример #7
0
gchar*
xhtml_extract (xmlNodePtr xml, gint xhtmlMode, const gchar *defaultBase)
{
	xmlBufferPtr buf;
	xmlChar *xml_base = NULL;
	gchar *result = NULL;
	xmlNs *ns;

	/* Create the new document and add the div tag*/
	xmlDocPtr newDoc = xmlNewDoc (BAD_CAST "1.0" );
	xmlNodePtr divNode = xmlNewNode (NULL, BAD_CAST "div");
	xmlDocSetRootElement (newDoc, divNode);
	xmlNewNs (divNode, BAD_CAST "http://www.w3.org/1999/xhtml", NULL);

	/* Set the xml:base  of the div tag */
	xml_base = xmlNodeGetBase (xml->doc, xml);
	if (xml_base) {
		xmlNodeSetBase (divNode, xml_base );
		xmlFree (xml_base);
	}
	else if (defaultBase)
		xmlNodeSetBase (divNode, BAD_CAST defaultBase);

	if (xhtmlMode == 0) { /* Read escaped HTML and convert to XHTML, placing in a div tag */
		xmlDocPtr oldDoc;
		xmlNodePtr copiedNodes = NULL;
		xmlChar *escapedhtml;

		/* Parse the HTML into oldDoc*/
		escapedhtml = xmlNodeListGetString (xml->doc, xml->xmlChildrenNode, 1);
		if (escapedhtml) {
			escapedhtml = BAD_CAST g_strstrip ((gchar*) escapedhtml);	/* stripping whitespaces to make empty string detection easier */
			if (*escapedhtml) {						/* never process empty content, xmlDocCopy() doesn't like it... */
				xmlNodePtr body;
				oldDoc = xhtml_parse ((gchar*) escapedhtml, strlen ((gchar*) escapedhtml));
				body = xhtml_find_body (oldDoc);

				/* Copy namespace from original documents root node. This is
				   ro determine additional namespaces for item content. For
				   example to handle RSS 2.0 feeds as provided by LiveJournal:

				   <rss version='2.0' xmlns:lj='http://www.livejournal.org/rss/lj/1.0/'>
				   <channel>
				      ...
				      <item>
	        			 ...
  	        			 <description>... &lt;span class=&apos;ljuser&apos; lj:user=&apos;someone&apos; style=&apos;white-space: nowrap;&apos;&gt;&lt;a href=&apos;http://community.livejournal.com/someone/profile&apos;&gt;&lt;img src=&apos;http://stat.livejournal.com/img/community.gif&apos; alt=&apos;[info]&apos; width=&apos;16&apos; height=&apos;16&apos; style=&apos;vertical-align: bottom; border: 0; padding-right: 2px;&apos; /&gt;&lt;/a&gt;&lt;a href=&apos;http://community.livejournal.com/someone/&apos;&gt;&lt;b&gt;someone&lt;/b&gt;&lt;/a&gt;&lt;/span&gt; ...</description>
					 ...
				      </item>
				      ...
				   </channel>

				   Then we will want to extract <description> and need to
				   honour the xmlns:lj definition...
				*/
				ns = (xmlDocGetRootElement (xml->doc))->nsDef;
				while (ns) {
					xmlNewNs (divNode, ns->href, ns->prefix);
					ns = ns->next;
				}

				if (body) {
					/* Copy in the html tags */
					copiedNodes = xmlDocCopyNodeList (newDoc, body->xmlChildrenNode);
					// FIXME: is the above correct? Why only operate on the first child node?
					// It might be unproblematic because all content is wrapped in a <div>...
					xmlAddChildList (divNode, copiedNodes);
				}
				xmlFreeDoc (oldDoc);
				xmlFree (escapedhtml);
			}
		}
	}
	else if (xhtmlMode == 1 || xhtmlMode == 2) { /* Read multiple XHTML tags and embed in div tag */
		xmlNodePtr copiedNodes = xmlDocCopyNodeList (newDoc, xml->xmlChildrenNode);
		xmlAddChildList (divNode, copiedNodes);
	}

	buf = xmlBufferCreate ();
	xmlNodeDump (buf, newDoc, xmlDocGetRootElement (newDoc), 0, 0 );

	if (xmlBufferLength (buf) > 0)
		result = (gchar*) xmlCharStrdup ((gchar*) xmlBufferContent (buf));

	xmlBufferFree (buf);
	xmlFreeDoc (newDoc);
	return result;
}
Пример #8
0
static xmlNodePtr Value2XMLNode(char *name, ValueStruct *val) {
  xmlNodePtr node;
  xmlNodePtr child;
  int i;

  if (val == NULL) {
    return NULL;
  }
  node = NULL;
  switch (ValueType(val)) {
  case GL_TYPE_INT:
    node = xmlNewNode(NULL, "int");
    xmlNodeAddContent(node, ValueToString(val, NULL));
    break;
  case GL_TYPE_FLOAT:
    node = xmlNewNode(NULL, "float");
    xmlNodeAddContent(node, ValueToString(val, NULL));
    break;
  case GL_TYPE_NUMBER:
    node = xmlNewNode(NULL, "number");
    xmlNodeAddContent(node, ValueToString(val, NULL));
    break;
  case GL_TYPE_BOOL:
    node = xmlNewNode(NULL, "bool");
    xmlNodeAddContent(node, ValueToString(val, NULL));
    break;
  case GL_TYPE_CHAR:
  case GL_TYPE_VARCHAR:
  case GL_TYPE_SYMBOL:
  case GL_TYPE_DBCODE:
  case GL_TYPE_TEXT:
    node = xmlNewNode(NULL, "string");
    xmlNodeAddContent(node, ValueToString(val, NULL));
    break;
  case GL_TYPE_ARRAY:
    node = xmlNewNode(NULL, "array");
    for (i = 0; i < ValueArraySize(val); i++) {
      child = Value2XMLNode(NULL, ValueArrayItem(val, i));
      if (child != NULL) {
        xmlAddChildList(node, child);
      }
    }
    break;
  case GL_TYPE_RECORD:
    node = xmlNewNode(NULL, "record");
    for (i = 0; i < ValueRecordSize(val); i++) {
      if (!strcmp(ValueRecordName(val, i), "mode")) {
        continue;
      }
      child = Value2XMLNode(ValueRecordName(val, i), ValueRecordItem(val, i));
      if (child != NULL) {
        xmlAddChildList(node, child);
      }
    }
    break;
  }
  if (node != NULL && name != NULL && strlen(name) > 0) {
    xmlNewProp(node, "name", name);
  }
  return node;
}