summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar snowdrop2004-06-08 12:54:09 +0000
committerGravatar snowdrop2004-06-08 12:54:09 +0000
commitedef31d0626a510400b9025c559c7d46fb036514 (patch)
tree74736970675c73acf8319c74ace95178a77d3d6b
parente7893b59f9f9c099ff98ba1daf7eef12c6653b32 (diff)
downloadcsoap-edef31d0626a510400b9025c559c7d46fb036514.tar.gz
csoap-edef31d0626a510400b9025c559c7d46fb036514.tar.bz2
added soap_env_add_custom()
-rw-r--r--libcsoap/Makefile.am2
-rw-r--r--libcsoap/soap-env.c103
-rw-r--r--libcsoap/soap-env.h27
3 files changed, 119 insertions, 13 deletions
diff --git a/libcsoap/Makefile.am b/libcsoap/Makefile.am
index bccb8f9..4bb9415 100644
--- a/libcsoap/Makefile.am
+++ b/libcsoap/Makefile.am
@@ -26,7 +26,7 @@ INCLUDES = -I$(top_srcdir) $(LIBXML_CFLAGS)
lib_LTLIBRARIES= libcsoap-1.0.la
libcsoap_1_0_la_SOURCES= $(h_sources) $(cc_sources)
#libexamplelib_1_0_la_LIBADD= sub/libsub.la
-libcsoap_1_0_la_LDFLAGS= -version-info $(GENERIC_LIBRARY_VERSION) -release $(GENERIC_RELEASE) -L$(top_builddir)/nanohttp -lnanohttp-$(GENERIC_API_VERSION)
+libcsoap_1_0_la_LDFLAGS= -version-info $(GENERIC_LIBRARY_VERSION) -release $(GENERIC_RELEASE) -L$(top_builddir)/nanohttp -lnanohttp-$(GENERIC_API_VERSION) $(LIBXML_LIBS)
#libcsoap_1_0_la_CFLAGS= @LIBXML_CCFLAGS@
diff --git a/libcsoap/soap-env.c b/libcsoap/soap-env.c
index 265295b..1e5c8dc 100644
--- a/libcsoap/soap-env.c
+++ b/libcsoap/soap-env.c
@@ -1,5 +1,5 @@
/******************************************************************
- * $Id: soap-env.c,v 1.2 2004/02/03 08:59:22 snowdrop Exp $
+ * $Id: soap-env.c,v 1.3 2004/06/08 12:54:09 snowdrop Exp $
*
* CSOAP Project: A SOAP client/server library in C
* Copyright (C) 2003 Ferhat Ayaz
@@ -23,7 +23,7 @@
******************************************************************/
#include <libcsoap/soap-env.h>
#include <stdarg.h>
-
+#include <string.h>
static char *soap_env_ns = "http://schemas.xmlsoap.org/soap/envelope/";
static char *soap_env_enc = "http://schemas.xmlsoap.org/soap/encoding/";
@@ -51,6 +51,23 @@ static char *soap_xsd_ns = "http://www.w3.org/1999/XMLSchema";
"</SOAP-ENV:Envelope>"
+/* ---------------------------------------------------------------------------- */
+/* XML Serializers (implemented at the and of this document) */
+/* ---------------------------------------------------------------------------- */
+struct XmlNodeHolder { xmlNodePtr node; };
+
+static
+void xmlbuilder_start_element(const char* element_name, int attr_count,
+ char **keys, char **values, void* userData);
+
+static
+void xmlbuilder_characters(const char* element_name,
+ const char* chars, void* userData);
+
+static
+void xmlbuilder_end_element(const char* element_name, void* userData);
+
+/* ---------------------------------------------------------------------------- */
SoapEnv *soap_env_new_with_fault(fault_code_t faultcode,
const char *faultstring,
@@ -99,8 +116,7 @@ SoapEnv *soap_env_new_with_response(SoapEnv* request)
SoapEnv *soap_env_new_with_method(const char *urn, const char *method)
{
- xmlNodePtr env;
- xmlNodePtr node;
+ xmlDocPtr env;
SoapEnv *call;
char buffer[1054];
@@ -152,7 +168,6 @@ soap_env_add_itemf(SoapEnv *call, const char *type,
va_list ap;
char buffer[1054];
- xmlNodePtr newnode;
va_start(ap, format);
@@ -163,6 +178,22 @@ soap_env_add_itemf(SoapEnv *call, const char *type,
}
+void
+soap_env_add_custom(SoapEnv *call, void *obj, XmlSerializerCallback cb,
+ const char *type, const char *name)
+{
+ struct XmlNodeHolder holder;
+
+ holder.node = soap_env_get_method(call);
+
+ cb(obj, name,
+ xmlbuilder_start_element,
+ xmlbuilder_characters,
+ xmlbuilder_end_element, &holder);
+
+}
+
+
xmlNodePtr
soap_env_push_item(SoapEnv *call, const char *type,
const char *name)
@@ -238,7 +269,7 @@ SoapEnv *soap_env_new_from_buffer(const char* buffer)
if (buffer == NULL) return NULL;
- doc = xmlParseDoc(buffer);
+ doc = xmlParseDoc((xmlChar*)buffer);
if (doc == NULL) return NULL;
env = soap_env_new_from_doc(doc);
@@ -300,11 +331,9 @@ soap_env_get_method(SoapEnv* env)
xmlNodePtr
_soap_env_get_body(SoapEnv* env)
{
- xmlNodePtr node, body;
+ xmlNodePtr body;
xmlNodeSetPtr nodeset;
xmlXPathObjectPtr xpathobj;
- char *urn;
- char methodname[150];
if (env == NULL) {
log_error1("env object is NULL");
@@ -330,17 +359,20 @@ _soap_env_get_body(SoapEnv* env)
nodeset = xpathobj->nodesetval;
if (!nodeset) {
log_error1("No Body (nodeset)!");
+ xmlXPathFreeObject(xpathobj);
return NULL;
}
if (nodeset->nodeNr < 1) {
log_error1("No Body (nodeNr)!");
- xmlXPathFreeObject(nodeset);
+ xmlXPathFreeNodeSet (nodeset);
+ xmlXPathFreeObject(xpathobj);
return NULL;
}
body = nodeset->nodeTab[0]; /* body is <Body> */
- xmlXPathFreeObject(nodeset);
+ xmlXPathFreeNodeSet (nodeset);
+ xmlXPathFreeObject(xpathobj);
return body;
}
@@ -402,3 +434,52 @@ int soap_env_find_methodname(SoapEnv *env, char *method)
return 1;
}
+
+
+
+/* ------------------------------------------------------------------ */
+/* XML serializers */
+/* ------------------------------------------------------------------ */
+
+
+static
+void xmlbuilder_start_element(const char* element_name, int attr_count, char **keys, char **values, void* userData)
+{
+ struct XmlNodeHolder *holder = (struct XmlNodeHolder*)userData;
+ xmlNodePtr parent = NULL;
+
+ if (holder == NULL) return;
+ parent = holder->node;
+ if (parent == NULL) return;
+
+ holder->node = xmlNewChild(parent, NULL, element_name, NULL);
+
+}
+
+static
+void xmlbuilder_characters(const char* element_name, const char* chars, void* userData)
+{
+ struct XmlNodeHolder *holder = (struct XmlNodeHolder*)userData;
+ xmlNodePtr parent = NULL;
+
+ if (holder == NULL) return;
+ parent = holder->node;
+ if (parent == NULL) return;
+
+ xmlNewTextChild(parent, NULL, element_name, chars);
+}
+
+static
+void xmlbuilder_end_element(const char* element_name, void* userData)
+{
+
+ struct XmlNodeHolder *holder = (struct XmlNodeHolder*)userData;
+ xmlNodePtr parent = NULL;
+
+ if (holder == NULL) return;
+ parent = holder->node;
+ if (parent == NULL) return;
+
+ holder->node = parent->parent;
+}
+
diff --git a/libcsoap/soap-env.h b/libcsoap/soap-env.h
index 5cb0f57..5f29c14 100644
--- a/libcsoap/soap-env.h
+++ b/libcsoap/soap-env.h
@@ -1,5 +1,5 @@
/******************************************************************
- * $Id: soap-env.h,v 1.4 2004/05/14 09:27:52 snowdrop Exp $
+ * $Id: soap-env.h,v 1.5 2004/06/08 12:54:09 snowdrop Exp $
*
* CSOAP Project: A SOAP client/server library in C
* Copyright (C) 2003 Ferhat Ayaz
@@ -158,6 +158,17 @@ SoapEnv *soap_env_new_from_doc(xmlDocPtr doc);
SoapEnv *soap_env_new_from_buffer(const char* buffer);
+/* --------------------------------------------------- */
+/* XML Serializer functions and typedefs */
+/* --------------------------------------------------- */
+
+typedef void (*XmlSerializerCallback)
+ (void* /*obj*/, const char * /*root_element_name*/,
+ void (*OnStartElement)(const char* element_name, int attr_count, char **keys, char **values, void* userData),
+ void (*OnCharacters)(const char* element_name, const char* chars, void* userData),
+ void (*OnEndElement)(const char* element_name, void* userData),
+ void* /* userdata*/);
+
/* ------------------------------------------------------ */
/* XML build and stack function */
@@ -187,6 +198,17 @@ soap_env_add_item(SoapEnv* env, const char *type,
/**
+ Serialize and adds obj to the envelope.
+ TODO: Document this function !
+ <br>
+ <b>Important: </b>
+
+ */
+void
+soap_env_add_custom(SoapEnv* env, void *obj, XmlSerializerCallback cb,
+ const char *type, const char *name);
+
+/**
Same as soap_env_add_item() with c style arguments
like in printf(). "value" is the format string.
<br>
@@ -284,6 +306,9 @@ int soap_env_find_methodname(SoapEnv *env, char *methodname);
+
+
+
#endif