diff options
| author | Damien Laniel <dlaniel@entrouvert.com> | 2007-06-05 17:36:09 +0000 |
|---|---|---|
| committer | Damien Laniel <dlaniel@entrouvert.com> | 2007-06-05 17:36:09 +0000 |
| commit | 04940cd36250ff87e66a9746ab291406de26c54c (patch) | |
| tree | 62198e2a80b1af4c55ce30f02592d030963e5c88 | |
| parent | bd82a01c17e526bc84a35c498817b02f3823f493 (diff) | |
added service.data and lasso_idwsf2_data_service_build_query_response_msg
| -rw-r--r-- | lasso/id-wsf-2.0/data_service.c | 104 | ||||
| -rw-r--r-- | lasso/id-wsf-2.0/data_service.h | 3 | ||||
| -rw-r--r-- | lasso/xml/id-wsf-2.0/Makefile.am | 4 | ||||
| -rw-r--r-- | lasso/xml/id-wsf-2.0/dstref_query.c | 16 | ||||
| -rw-r--r-- | lasso/xml/id-wsf-2.0/dstref_query_response.c | 41 | ||||
| -rw-r--r-- | lasso/xml/id-wsf-2.0/dstref_query_response.h | 6 | ||||
| -rw-r--r-- | lasso/xml/id-wsf-2.0/util_response.h | 2 | ||||
| -rw-r--r-- | lasso/xml/private.h | 2 | ||||
| -rw-r--r-- | lasso/xml/xml.c | 14 | ||||
| -rw-r--r-- | swig/Lasso-wsf2.i | 20 |
10 files changed, 190 insertions, 22 deletions
diff --git a/lasso/id-wsf-2.0/data_service.c b/lasso/id-wsf-2.0/data_service.c index 9e328ed0..b64c43af 100644 --- a/lasso/id-wsf-2.0/data_service.c +++ b/lasso/id-wsf-2.0/data_service.c @@ -22,15 +22,17 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* #include <libxml/xpath.h> */ +#include <libxml/xpath.h> +#include <libxml/xpathInternals.h> #include <lasso/id-wsf-2.0/discovery.h> #include <lasso/id-wsf-2.0/data_service.h> -#include <lasso/xml/id-wsf-2.0/dstref_query.h> -/* #include <lasso/xml/id-wsf-2.0/dstref_query_response.h> */ - #include <lasso/xml/id-wsf-2.0/disco_service_type.h> +#include <lasso/xml/id-wsf-2.0/dstref_query.h> +#include <lasso/xml/id-wsf-2.0/dstref_query_response.h> +#include <lasso/xml/id-wsf-2.0/dstref_data.h> +#include <lasso/xml/id-wsf-2.0/util_status.h> struct _LassoIdWsf2DataServicePrivate { @@ -143,6 +145,100 @@ lasso_idwsf2_data_service_process_query_msg(LassoIdWsf2DataService *service, con return res; } +/* XXX: Taken from swig/Lasso.i . Should probably be moved to xml.c */ +static gchar* get_xml_string(xmlNode *xmlnode) +{ + xmlOutputBufferPtr buf; + gchar *xmlString; + + if (xmlnode == NULL) { + return NULL; + } + + buf = xmlAllocOutputBuffer(NULL); + if (buf == NULL) { + xmlString = NULL; + } else { + xmlNodeDumpOutput(buf, NULL, xmlnode, 0, 1, NULL); + xmlOutputBufferFlush(buf); + if (buf->conv == NULL) { + xmlString = g_strdup((gchar*)buf->buffer->content); + } else { + xmlString = g_strdup((gchar*)buf->conv->content); + } + xmlOutputBufferClose(buf); + } + xmlFreeNode(xmlnode); + return xmlString; +} + +gint +lasso_idwsf2_data_service_build_query_response_msg(LassoIdWsf2DataService *service) +{ + LassoWsf2Profile *profile = LASSO_WSF2_PROFILE(service); + LassoIdWsf2DstRefQuery *request = LASSO_IDWSF2_DSTREF_QUERY(profile->request); + LassoIdWsf2DstRefQueryResponse *response; + LassoSoapEnvelope *envelope; + xmlDoc *doc; + xmlXPathContext *xpathCtx; + xmlXPathObject *xpathObj; + LassoIdWsf2DstRefQueryItem *item; + LassoIdWsf2DstRefResultQuery *item_result_query; + LassoIdWsf2DstResultQueryBase *item_result_query_base; + LassoIdWsf2DstRefData *data; + LassoIdWsf2DstRefItemData *data_item; + xmlNode *node; + GList *iter; + + /* Response envelope and body */ + envelope = profile->soap_envelope_response; + response = lasso_idwsf2_dstref_query_response_new(); + response->prefixServiceType = g_strdup(request->prefixServiceType); + response->hrefServiceType = g_strdup(request->hrefServiceType); + profile->response = LASSO_NODE(response); + envelope->Body->any = g_list_append(envelope->Body->any, response); + + /* Initialise XML parsing */ + doc = xmlNewDoc((xmlChar*)"1.0"); + xmlDocSetRootElement(doc, service->data); + xpathCtx = xmlXPathNewContext(doc); + xmlXPathRegisterNs(xpathCtx, (xmlChar*)response->prefixServiceType, + (xmlChar*)response->hrefServiceType); + + /* Parse request QueryItems and fill response Data accordingly */ + /* XXX: needs another level, since there may be more than one <dst:Query> */ + for (iter = g_list_first(request->QueryItem); iter != NULL; iter = g_list_next(iter)) { + item = iter->data; + item_result_query = LASSO_IDWSF2_DSTREF_RESULT_QUERY(item); + item_result_query_base = LASSO_IDWSF2_DST_RESULT_QUERY_BASE(item); + xpathObj = xmlXPathEvalExpression((xmlChar*)item_result_query->Select, xpathCtx); + if (xpathObj && xpathObj->nodesetval && xpathObj->nodesetval->nodeNr) { + node = xpathObj->nodesetval->nodeTab[0]; + /* XXX: assuming there is only one matching node */ + data = lasso_idwsf2_dstref_data_new(); + data_item = LASSO_IDWSF2_DSTREF_ITEM_DATA(data); + data_item->content = get_xml_string(node); + if (item_result_query_base->itemID != NULL) { + data_item->itemIDRef = g_strdup(item_result_query_base->itemID); + } + response->Data = g_list_append(response->Data, data); + } + xmlXPathFreeObject(xpathObj); + xpathObj = NULL; + } + + /* Free XML parsing objects */ + xmlUnlinkNode(service->data); + xmlXPathFreeContext(xpathCtx); + xmlFreeDoc(doc); + + /* Response is built without any problem, status code is ok */ + LASSO_IDWSF2_UTIL_RESPONSE(response)->Status = + lasso_util_status_new(LASSO_DST_STATUS_CODE_OK); + + return lasso_wsf2_profile_build_response_msg(profile); +} + /*****************************************************************************/ /* private methods */ /*****************************************************************************/ diff --git a/lasso/id-wsf-2.0/data_service.h b/lasso/id-wsf-2.0/data_service.h index e00e98c8..869e83d1 100644 --- a/lasso/id-wsf-2.0/data_service.h +++ b/lasso/id-wsf-2.0/data_service.h @@ -85,6 +85,9 @@ LASSO_EXPORT gint lasso_idwsf2_data_service_add_query_item( LASSO_EXPORT gint lasso_idwsf2_data_service_process_query_msg(LassoIdWsf2DataService *service, const gchar *message); +LASSO_EXPORT gint lasso_idwsf2_data_service_build_query_response_msg( + LassoIdWsf2DataService *service); + #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/lasso/xml/id-wsf-2.0/Makefile.am b/lasso/xml/id-wsf-2.0/Makefile.am index 12490d1b..98a11404 100644 --- a/lasso/xml/id-wsf-2.0/Makefile.am +++ b/lasso/xml/id-wsf-2.0/Makefile.am @@ -27,6 +27,8 @@ liblasso_xml_id_wsf2_la_SOURCES = \ dst_data_response_base.c \ dst_request.c \ dst_result_query_base.c \ + dstref_data.c \ + dstref_item_data.c \ dstref_query.c \ dstref_query_item.c \ dstref_query_response.c \ @@ -56,6 +58,8 @@ liblassoinclude_HEADERS = \ dst_data_response_base.h \ dst_request.h \ dst_result_query_base.h \ + dstref_data.h \ + dstref_item_data.h \ dstref_query.h \ dstref_query_item.h \ dstref_query_response.h \ diff --git a/lasso/xml/id-wsf-2.0/dstref_query.c b/lasso/xml/id-wsf-2.0/dstref_query.c index 55d5e14b..3746e36c 100644 --- a/lasso/xml/id-wsf-2.0/dstref_query.c +++ b/lasso/xml/id-wsf-2.0/dstref_query.c @@ -56,20 +56,6 @@ static struct XmlSnippet schema_snippets[] = { static LassoNodeClass *parent_class = NULL; -static void -insure_namespace(xmlNode *xmlnode, xmlNs *ns) -{ - xmlNode *t = xmlnode->children; - - xmlSetNs(xmlnode, ns); - while (t) { - if (t->type == XML_ELEMENT_NODE) { - insure_namespace(t, ns); - } - t = t->next; - } -} - static xmlNode* get_xmlNode(LassoNode *node, gboolean lasso_dump) { @@ -79,7 +65,7 @@ get_xmlNode(LassoNode *node, gboolean lasso_dump) xmlnode = parent_class->get_xmlNode(node, lasso_dump); ns = xmlNewNs(xmlnode, (xmlChar*)LASSO_IDWSF2_DSTREF_QUERY(node)->hrefServiceType, (xmlChar*)LASSO_IDWSF2_DSTREF_QUERY(node)->prefixServiceType); - insure_namespace(xmlnode, ns); + xml_insure_namespace(xmlnode, ns, TRUE); return xmlnode; } diff --git a/lasso/xml/id-wsf-2.0/dstref_query_response.c b/lasso/xml/id-wsf-2.0/dstref_query_response.c index 40773991..f497b7fb 100644 --- a/lasso/xml/id-wsf-2.0/dstref_query_response.c +++ b/lasso/xml/id-wsf-2.0/dstref_query_response.c @@ -55,6 +55,40 @@ static struct XmlSnippet schema_snippets[] = { static LassoNodeClass *parent_class = NULL; +static xmlNode* +get_xmlNode(LassoNode *node, gboolean lasso_dump) +{ + xmlNode *xmlnode; + xmlNs *ns; + + xmlnode = parent_class->get_xmlNode(node, lasso_dump); + ns = xmlNewNs(xmlnode, (xmlChar*)LASSO_IDWSF2_DSTREF_QUERY_RESPONSE(node)->hrefServiceType, + (xmlChar*)LASSO_IDWSF2_DSTREF_QUERY_RESPONSE(node)->prefixServiceType); + xml_insure_namespace(xmlnode, ns, TRUE); + + return xmlnode; +} + +static int +init_from_xml(LassoNode *node, xmlNode *xmlnode) +{ + LassoIdWsf2DstRefQueryResponse *response = LASSO_IDWSF2_DSTREF_QUERY_RESPONSE(node); + int res; + + res = parent_class->init_from_xml(node, xmlnode); + if (res) { + return res; + } + + response->hrefServiceType = g_strdup((char*)xmlnode->ns->href); + response->prefixServiceType = lasso_get_prefix_for_dst_service_href( + response->hrefServiceType); + if (response->prefixServiceType == NULL) { + /* XXX: what to do here ? */ + } + + return 0; +} /*****************************************************************************/ /* instance and class init functions */ @@ -65,6 +99,8 @@ instance_init(LassoIdWsf2DstRefQueryResponse *node) { node->TestResult = NULL; node->Data = NULL; + node->prefixServiceType = NULL; + node->hrefServiceType = NULL; } static void @@ -73,6 +109,8 @@ class_init(LassoIdWsf2DstRefQueryResponseClass *klass) LassoNodeClass *nclass = LASSO_NODE_CLASS(klass); parent_class = g_type_class_peek_parent(klass); + nclass->get_xmlNode = get_xmlNode; + nclass->init_from_xml = init_from_xml; nclass->node_data = g_new0(LassoNodeClassData, 1); lasso_node_class_set_nodename(nclass, "QueryResponse"); lasso_node_class_set_ns(nclass, LASSO_IDWSF2_DSTREF_HREF, LASSO_IDWSF2_DSTREF_PREFIX); @@ -110,8 +148,9 @@ lasso_idwsf2_dstref_query_response_get_type() * * Return value: a newly created #LassoIdWsf2DstRefQueryResponse object **/ -LassoNode* +LassoIdWsf2DstRefQueryResponse* lasso_idwsf2_dstref_query_response_new() { return g_object_new(LASSO_TYPE_IDWSF2_DSTREF_QUERY_RESPONSE, NULL); } + diff --git a/lasso/xml/id-wsf-2.0/dstref_query_response.h b/lasso/xml/id-wsf-2.0/dstref_query_response.h index 4058e625..25e571a0 100644 --- a/lasso/xml/id-wsf-2.0/dstref_query_response.h +++ b/lasso/xml/id-wsf-2.0/dstref_query_response.h @@ -65,6 +65,10 @@ struct _LassoIdWsf2DstRefQueryResponse { /* elements */ GList *TestResult; GList *Data; /* of LassoIdWsf2DstRefData */ + + /*< private >*/ + char *prefixServiceType; + char *hrefServiceType; }; @@ -73,7 +77,7 @@ struct _LassoIdWsf2DstRefQueryResponseClass { }; LASSO_EXPORT GType lasso_idwsf2_dstref_query_response_get_type(void); -LASSO_EXPORT LassoNode* lasso_idwsf2_dstref_query_response_new(void); +LASSO_EXPORT LassoIdWsf2DstRefQueryResponse* lasso_idwsf2_dstref_query_response_new(void); diff --git a/lasso/xml/id-wsf-2.0/util_response.h b/lasso/xml/id-wsf-2.0/util_response.h index 8a371991..0934a6c6 100644 --- a/lasso/xml/id-wsf-2.0/util_response.h +++ b/lasso/xml/id-wsf-2.0/util_response.h @@ -62,7 +62,7 @@ struct _LassoIdWsf2UtilResponse { /*< public >*/ /* elements */ - /* XXX */ void *Status; + LassoIdWsf2UtilStatus *Status; GList *Extension; /* of LassoIdWsf2Utilextension */ /* attributes */ char *itemIDRef; diff --git a/lasso/xml/private.h b/lasso/xml/private.h index f6fa60a4..2a239722 100644 --- a/lasso/xml/private.h +++ b/lasso/xml/private.h @@ -119,6 +119,8 @@ int lasso_sign_node(xmlNode *xmlnode, const char *id_attr_name, const char *id_v void xmlCleanNs(xmlNode *root_node); +void xml_insure_namespace(xmlNode *xmlnode, xmlNs *ns, gboolean force); + gchar* lasso_node_build_deflated_query(LassoNode *node); gboolean lasso_node_init_from_deflated_query_part(LassoNode *node, char *deflate_string); diff --git a/lasso/xml/xml.c b/lasso/xml/xml.c index 87d0007b..dde38a39 100644 --- a/lasso/xml/xml.c +++ b/lasso/xml/xml.c @@ -2336,3 +2336,17 @@ xmlCleanNs(xmlNode *root_node) } } +void +xml_insure_namespace(xmlNode *xmlnode, xmlNs *ns, gboolean force) +{ + xmlNode *t = xmlnode->children; + + xmlSetNs(xmlnode, ns); + while (t) { + if (t->type == XML_ELEMENT_NODE && (force == TRUE || t->ns == NULL)) { + xml_insure_namespace(t, ns, force); + } + t = t->next; + } +} + diff --git a/swig/Lasso-wsf2.i b/swig/Lasso-wsf2.i index 0be67c9e..a37bb649 100644 --- a/swig/Lasso-wsf2.i +++ b/swig/Lasso-wsf2.i @@ -323,6 +323,11 @@ typedef struct { %newobject server_get; LassoServer *server; + /* Attributes */ + + %newobject data; + char *data; + /* Constructor, Destructor & Static Methods */ LassoIdWsf2DataService(LassoServer *server); @@ -352,10 +357,15 @@ typedef struct { THROW_ERROR() int addQueryItem(const char *item_xpath, const char *item_id); + END_THROW_ERROR() THROW_ERROR() int processQueryMsg(const char *message); END_THROW_ERROR() + + THROW_ERROR() + int buildQueryResponseMsg(); + END_THROW_ERROR() } %{ @@ -396,6 +406,14 @@ typedef struct { #define LassoIdWsf2DataService_set_server(self, value) set_node((gpointer *) &LASSO_WSF2_PROFILE(self)->server, (value)) #define LassoIdWsf2DataService_server_set(self, value) set_node((gpointer *) &LASSO_WSF2_PROFILE(self)->server, (value)) +/* Attributes */ + +/* data */ +#define LassoIdWsf2DataService_get_data(self) get_xml_string((self)->data) +#define LassoIdWsf2DataService_data_get(self) get_xml_string((self)->data) +#define LassoIdWsf2DataService_set_data(self, value) set_xml_string(&(self)->data, (value)) +#define LassoIdWsf2DataService_data_set(self, value) set_xml_string(&(self)->data, (value)) + /* Constructors, destructors & static methods implementations */ #define new_LassoIdWsf2DataService lasso_idwsf2_data_service_new @@ -414,5 +432,7 @@ typedef struct { #define LassoIdWsf2DataService_initQuery lasso_idwsf2_data_service_init_query #define LassoIdWsf2DataService_addQueryItem lasso_idwsf2_data_service_add_query_item #define LassoIdWsf2DataService_processQueryMsg lasso_idwsf2_data_service_process_query_msg +#define LassoIdWsf2DataService_buildQueryResponseMsg lasso_idwsf2_data_service_build_query_response_msg + %} |
