summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenjamin Dauvergne <bdauvergne@entrouvert.com>2009-03-27 15:05:19 +0000
committerBenjamin Dauvergne <bdauvergne@entrouvert.com>2009-03-27 15:05:19 +0000
commit580239d23382b8968060fdd49a19a489817c772a (patch)
tree9218398e604c0c451bc73650d2b78cbf215ef38f
parent22feecaffb5307011d0e873a13d80502e9f0acb3 (diff)
downloadlasso-580239d23382b8968060fdd49a19a489817c772a.tar.gz
lasso-580239d23382b8968060fdd49a19a489817c772a.tar.xz
lasso-580239d23382b8968060fdd49a19a489817c772a.zip
Core: move parse xml wrapper from xml.c to tools.c
* lasso/xml/xml.c: remove lasso_xml_parse_memory. * lasso/xml/tools.c: add lasso_xml_parse_memory to wrap xmlParseDocument. * lasso/saml-2.0/name_id_management.c: use lasso_xml_parse_memory
-rw-r--r--lasso/saml-2.0/name_id_management.c2
-rw-r--r--lasso/xml/private.h2
-rw-r--r--lasso/xml/tools.c79
-rw-r--r--lasso/xml/xml.c77
4 files changed, 82 insertions, 78 deletions
diff --git a/lasso/saml-2.0/name_id_management.c b/lasso/saml-2.0/name_id_management.c
index 6c64a12c..6d8a5fec 100644
--- a/lasso/saml-2.0/name_id_management.c
+++ b/lasso/saml-2.0/name_id_management.c
@@ -459,7 +459,7 @@ lasso_name_id_management_new_from_dump(LassoServer *server, const char *dump)
return NULL;
name_id_management = lasso_name_id_management_new(g_object_ref(server));
- doc = xmlParseMemory(dump, strlen(dump));
+ doc = lasso_xml_parse_memory(dump, strlen(dump));
lasso_node_init_from_xml(LASSO_NODE(name_id_management), xmlDocGetRootElement(doc));
lasso_release_doc(doc);
diff --git a/lasso/xml/private.h b/lasso/xml/private.h
index 33488057..fe3da380 100644
--- a/lasso/xml/private.h
+++ b/lasso/xml/private.h
@@ -153,6 +153,8 @@ LassoSaml2EncryptedElement* lasso_node_encrypt(LassoNode *lasso_node,
int lasso_node_decrypt_xmlnode(xmlNode* encrypted_element, GList *encrypted_key,
xmlSecKey *encryption_private_key, LassoNode **output);
+xmlDocPtr lasso_xml_parse_memory(const char *buffer, int size);
+
char* lasso_concat_url_query(char *url, char *query);
xmlDocPtr lasso_xml_parse_memory(const char *buffer, int size);
diff --git a/lasso/xml/tools.c b/lasso/xml/tools.c
index 6d872b22..884b7fd0 100644
--- a/lasso/xml/tools.c
+++ b/lasso/xml/tools.c
@@ -28,6 +28,8 @@
#include <ctype.h>
#include <libxml/uri.h>
+#include <libxml/parser.h>
+#include <libxml/parserInternals.h>
#include <openssl/pem.h>
#include <openssl/sha.h>
@@ -56,6 +58,7 @@
LassoNode* lasso_assertion_encrypt(LassoSaml2Assertion *assertion);
static xmlSecKeyPtr lasso_get_public_key_from_private_key_file(const char *private_key_file);
static gboolean is_base64(const char *message);
+static void xmlDetectSAX2(xmlParserCtxtPtr ctxt);
/**
* lasso_build_random_sequence:
@@ -1385,3 +1388,79 @@ cleanup:
return rc;
}
+
+/**
+ * lasso_xml_parse_memory:
+ * @buffer: an pointer to a char array
+ * @size: the size of the array
+ *
+ * Parse an XML in-memory block and build a tree; exactly like xmlParseMemory
+ * safe two exceptions:
+ * <itemizedlist>
+ * <listitem><para>
+ * it won't download anything from the network (XML_PARSE_NONET)
+ * </listitem></para>
+ * <listitem><para>
+ * it will refuse documents with a DTD (for security reason)
+ * </para></listitem>
+ * </itemizedlist>
+ *
+ * Return value: the resulting document tree
+ **/
+xmlDocPtr
+lasso_xml_parse_memory(const char *buffer, int size)
+{
+ xmlDocPtr ret;
+ xmlParserCtxtPtr ctxt;
+
+ ctxt = xmlCreateMemoryParserCtxt(buffer, size);
+ if (ctxt == NULL) {
+ return NULL;
+ }
+ xmlDetectSAX2(ctxt);
+ if (ctxt->errNo == XML_ERR_NO_MEMORY) {
+ return NULL;
+ }
+ ctxt->recovery = 0;
+ xmlCtxtUseOptions(ctxt, XML_PARSE_NONET);
+
+ xmlParseDocument(ctxt);
+
+ if (ctxt->wellFormed && ctxt->myDoc->intSubset != NULL) {
+ message(G_LOG_LEVEL_WARNING, "Denied message with DTD content");
+ ctxt->wellFormed = 0;
+ }
+
+ if (ctxt->wellFormed) {
+ ret = ctxt->myDoc;
+ } else {
+ ret = NULL;
+ lasso_release_doc(ctxt->myDoc);
+ ctxt->myDoc = NULL;
+ }
+ xmlFreeParserCtxt(ctxt);
+
+ return ret;
+}
+
+/* (almost) straight from libxml2 internal API */
+static void
+xmlDetectSAX2(xmlParserCtxtPtr ctxt) {
+ if (ctxt == NULL) return;
+#ifdef LIBXML_SAX1_ENABLED
+ if ((ctxt->sax != NULL) && (ctxt->sax->initialized == XML_SAX2_MAGIC) &&
+ ((ctxt->sax->startElementNs != NULL) ||
+ (ctxt->sax->endElementNs != NULL)))
+ ctxt->sax2 = 1;
+#else
+ ctxt->sax2 = 1;
+#endif /* LIBXML_SAX1_ENABLED */
+
+ ctxt->str_xml = xmlDictLookup(ctxt->dict, BAD_CAST "xml", 3);
+ ctxt->str_xmlns = xmlDictLookup(ctxt->dict, BAD_CAST "xmlns", 5);
+ ctxt->str_xml_ns = xmlDictLookup(ctxt->dict, XML_XML_NAMESPACE, 36);
+ if ((ctxt->str_xml==NULL) || (ctxt->str_xmlns==NULL) ||
+ (ctxt->str_xml_ns == NULL)) {
+ ctxt->errNo = XML_ERR_NO_MEMORY;
+ }
+}
diff --git a/lasso/xml/xml.c b/lasso/xml/xml.c
index 40bdb282..ceebc451 100644
--- a/lasso/xml/xml.c
+++ b/lasso/xml/xml.c
@@ -138,83 +138,6 @@ lasso_get_prefix_for_idwsf2_dst_service_href(const gchar *href)
return g_strdup(g_hash_table_lookup(idwsf2_dst_services_by_href, href));
}
-/* (almost) straight from libxml2 internal API */
-static void
-xmlDetectSAX2(xmlParserCtxtPtr ctxt) {
- if (ctxt == NULL) return;
-#ifdef LIBXML_SAX1_ENABLED
- if ((ctxt->sax != NULL) && (ctxt->sax->initialized == XML_SAX2_MAGIC) &&
- ((ctxt->sax->startElementNs != NULL) ||
- (ctxt->sax->endElementNs != NULL)))
- ctxt->sax2 = 1;
-#else
- ctxt->sax2 = 1;
-#endif /* LIBXML_SAX1_ENABLED */
-
- ctxt->str_xml = xmlDictLookup(ctxt->dict, BAD_CAST "xml", 3);
- ctxt->str_xmlns = xmlDictLookup(ctxt->dict, BAD_CAST "xmlns", 5);
- ctxt->str_xml_ns = xmlDictLookup(ctxt->dict, XML_XML_NAMESPACE, 36);
- if ((ctxt->str_xml==NULL) || (ctxt->str_xmlns==NULL) ||
- (ctxt->str_xml_ns == NULL)) {
- ctxt->errNo = XML_ERR_NO_MEMORY;
- }
-}
-
-
-/**
- * lasso_xml_parse_memory:
- * @buffer: an pointer to a char array
- * @size: the size of the array
- *
- * Parse an XML in-memory block and build a tree; exactly like xmlParseMemory
- * safe two exceptions:
- * <itemizedlist>
- * <listitem><para>
- * it won't download anything from the network (XML_PARSE_NONET)
- * </listitem></para>
- * <listitem><para>
- * it will refuse documents with a DTD (for security reason)
- * </para></listitem>
- * </itemizedlist>
- *
- * Return value: the resulting document tree
- **/
-xmlDocPtr
-lasso_xml_parse_memory(const char *buffer, int size)
-{
- xmlDocPtr ret;
- xmlParserCtxtPtr ctxt;
-
- ctxt = xmlCreateMemoryParserCtxt(buffer, size);
- if (ctxt == NULL) {
- return NULL;
- }
- xmlDetectSAX2(ctxt);
- if (ctxt->errNo == XML_ERR_NO_MEMORY) {
- return NULL;
- }
- ctxt->recovery = 0;
- xmlCtxtUseOptions(ctxt, XML_PARSE_NONET);
-
- xmlParseDocument(ctxt);
-
- if (ctxt->wellFormed && ctxt->myDoc->intSubset != NULL) {
- message(G_LOG_LEVEL_WARNING, "Denied message with DTD content");
- ctxt->wellFormed = 0;
- }
-
- if (ctxt->wellFormed) {
- ret = ctxt->myDoc;
- } else {
- ret = NULL;
- lasso_release_doc(ctxt->myDoc);
- ctxt->myDoc = NULL;
- }
- xmlFreeParserCtxt(ctxt);
-
- return ret;
-}
-
/*****************************************************************************/
/* virtual public methods */