summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrederic Peters <fpeters@entrouvert.com>2005-08-12 14:25:44 +0000
committerFrederic Peters <fpeters@entrouvert.com>2005-08-12 14:25:44 +0000
commit6eba7b86f52b923330a4264cb022325e8dbcbc22 (patch)
tree1b2a1bc717da5e5051c9d1a14f82d68cac262a0c
parent3d77fb20f40b5322433052f7e3dee653c4e9b18a (diff)
API after the pp:query has been sent,
server: service = lasso.ProfileService(server) service.processQueryMsg(soap_message) identity = get_identity_by_resource_id(service.request.resourceId) service.resourceData = identity.get_pp_view() service.buildResponseMsg() return service.msgBody client: service.processQueryResponseMsg(soap_answer) service.getAnswer() # or service.getAnswer('/pp:PP/pp:CommonName')
-rw-r--r--lasso/id-wsf/discovery.c6
-rw-r--r--lasso/id-wsf/personal_profile_service.c4
-rw-r--r--lasso/id-wsf/profile_service.c152
-rw-r--r--lasso/id-wsf/profile_service.h7
-rw-r--r--lasso/xml/dst_query.c33
-rw-r--r--lasso/xml/dst_query_response.c34
-rw-r--r--lasso/xml/xml.c3
-rw-r--r--swig/Lasso-wsf.i16
8 files changed, 228 insertions, 27 deletions
diff --git a/lasso/id-wsf/discovery.c b/lasso/id-wsf/discovery.c
index 24853fec..b0c72468 100644
--- a/lasso/id-wsf/discovery.c
+++ b/lasso/id-wsf/discovery.c
@@ -586,6 +586,11 @@ lasso_discovery_process_query_msg(LassoDiscovery *discovery, const gchar *messag
}
+/**
+ * lasso_discovery_build_response_msg
+ * @discovery:
+ *
+ **/
gint
lasso_discovery_build_response_msg(LassoDiscovery *discovery)
{
@@ -595,7 +600,6 @@ lasso_discovery_build_response_msg(LassoDiscovery *discovery)
GList *offerings = NULL;
GList *iter;
-
iter = request->RequestedServiceType;
while (iter) {
LassoDiscoRequestedServiceType *service_type = iter->data;
diff --git a/lasso/id-wsf/personal_profile_service.c b/lasso/id-wsf/personal_profile_service.c
index 9ec3f8f6..4806e52d 100644
--- a/lasso/id-wsf/personal_profile_service.c
+++ b/lasso/id-wsf/personal_profile_service.c
@@ -158,9 +158,7 @@ lasso_personal_profile_service_process_query_response_msg(LassoPersonalProfileSe
g_return_val_if_fail(LASSO_IS_PERSONAL_PROFILE_SERVICE(service) == TRUE, -1);
return lasso_profile_service_process_query_response_msg(LASSO_PROFILE_SERVICE(service),
- LASSO_PP_PREFIX,
- LASSO_PP_HREF,
- soap_msg);
+ soap_msg);
}
gint
diff --git a/lasso/id-wsf/profile_service.c b/lasso/id-wsf/profile_service.c
index 8bdc175f..4253d026 100644
--- a/lasso/id-wsf/profile_service.c
+++ b/lasso/id-wsf/profile_service.c
@@ -265,7 +265,7 @@ lasso_profile_service_init_query(LassoProfileService *service, const char *selec
/**
* lasso_profile_service_process_query_msg:
* @service: a #LassoProfileService
- * @message: the disco query message
+ * @message: the dst query message
*
* Processes a dst:Query message. Rebuilds a request object from the message
* and extracts ResourceID.
@@ -297,6 +297,154 @@ lasso_profile_service_process_query_msg(LassoProfileService *service, const char
return 0;
}
+/**
+ * lasso_discovery_build_response_msg:
+ * @service: a #LassoProfileService
+ *
+ * Return value: 0 on success; or a negative value otherwise.
+ **/
+gint
+lasso_profile_service_build_response_msg(LassoProfileService *service)
+{
+ LassoWsfProfile *profile;
+ LassoDstQuery *query;
+ LassoDstQueryResponse *response;
+ GList *iter;
+ xmlDoc *doc;
+ xmlXPathContext *xpathCtx;
+ xmlXPathObject *xpathObj;
+ LassoSoapEnvelope *envelope;
+
+ profile = LASSO_WSF_PROFILE(service);
+ query = LASSO_DST_QUERY(profile->request);
+
+ response = lasso_dst_query_response_new(lasso_utility_status_new(LASSO_DST_STATUS_CODE_OK));
+ profile->response = LASSO_NODE(response);
+ response->prefixServiceType = g_strdup(query->prefixServiceType);
+ response->hrefServiceType = g_strdup(query->hrefServiceType);
+ envelope = profile->soap_envelope_response;
+ envelope->Body->any = g_list_append(envelope->Body->any, response);
+
+ doc = xmlNewDoc((xmlChar*)"1.0");
+ xmlDocSetRootElement(doc, service->resource_data);
+ xpathCtx = xmlXPathNewContext(doc);
+ xmlXPathRegisterNs(xpathCtx, (xmlChar*)response->prefixServiceType,
+ (xmlChar*)response->hrefServiceType);
+
+ /* XXX: needs another level, since there may be more than one <dst:Query> */
+ iter = query->QueryItem;
+ while (iter) {
+ LassoDstQueryItem *item = iter->data;
+ xpathObj = xmlXPathEvalExpression((xmlChar*)item->Select, xpathCtx);
+ if (xpathObj && xpathObj->nodesetval && xpathObj->nodesetval->nodeNr) {
+ LassoDstData *data;
+ xmlNode *node = xpathObj->nodesetval->nodeTab[0];
+ /* XXX: assuming there is only one matching node */
+ data = lasso_dst_data_new();
+ data->any = g_list_append(data->any, xmlCopyNode(node, 1));
+ if (item->itemID) {
+ data->itemIDRef = g_strdup(item->itemID);
+ }
+ response->Data = g_list_append(response->Data, data);
+ }
+ iter = g_list_next(iter);
+ }
+
+ xmlUnlinkNode(service->resource_data);
+ xmlFreeDoc(doc);
+
+ return lasso_wsf_profile_build_soap_response_msg(profile);
+}
+
+/**
+ * lasso_profile_service_get_answer:
+ * @service: a #LassoProfileService
+ *
+ *
+ *
+ **/
+xmlNode*
+lasso_profile_service_get_answer(LassoProfileService *service, const char *select)
+{
+ LassoDstQueryResponse *response;
+ LassoDstData *data = NULL;
+ GList *iter;
+ char *item_id = NULL;
+
+ response = LASSO_DST_QUERY_RESPONSE(LASSO_WSF_PROFILE(service)->response);
+
+ if (select == NULL) {
+ /* default to first */
+ data = response->Data->data;
+ } else {
+ LassoDstQueryItem *item = NULL;
+ /* lookup select in query to get itemId, then get data with itemIdRef */
+ /* XXX: needs another level, since there may be more than one dst:Query */
+ iter = LASSO_DST_QUERY(LASSO_WSF_PROFILE(service)->request)->QueryItem;
+ while (iter) {
+ item = iter->data;
+ iter = g_list_next(iter);
+ if (strcmp(item->Select, select) == 0) {
+ break;
+ }
+ item = NULL;
+ }
+
+ iter = LASSO_DST_QUERY(LASSO_WSF_PROFILE(service)->request)->QueryItem;
+ if (item == NULL) {
+ /* not found */
+ return NULL;
+ }
+ item_id = item->itemID;
+ if (item_id == NULL) {
+ /* item_id is not mandatory when there is only one item */
+ data = response->Data->data;
+ }
+
+ iter = response->Data;
+ while (iter && item_id) {
+ LassoDstData *t = iter->data;
+ iter = g_list_next(iter);
+ if (strcmp(t->itemIDRef, item_id) == 0) {
+ data = t;
+ break;
+ }
+ }
+ if (data == NULL) {
+ /* not found */
+ return NULL;
+ }
+ }
+
+ /* XXX: there may be more than one xmlnode */
+ return xmlCopyNode(data->any->data, 1);
+}
+
+/**
+ * lasso_profile_service_process_query_response_msg:
+ * @service: a #LassoProfileService
+ * @message: the dst query response message
+ *
+ * ...
+ *
+ * Return value: 0 on success; or a negative value otherwise.
+ **/
+gint
+lasso_profile_service_process_query_response_msg(LassoProfileService *service, const char *message)
+{
+ int rc;
+ LassoDstQueryResponse *response;
+
+ rc = lasso_wsf_profile_process_soap_response_msg(LASSO_WSF_PROFILE(service), message);
+ if (rc) return rc;
+
+ response = LASSO_DST_QUERY_RESPONSE(LASSO_WSF_PROFILE(service)->response);
+ if (strcmp(response->Status->code, "OK") != 0)
+ return LASSO_ERROR_UNDEFINED;
+
+ return 0;
+}
+
xmlNode*
lasso_profile_service_get_xmlNode(LassoProfileService *service,
@@ -399,7 +547,6 @@ lasso_profile_service_process_query_msg(LassoProfileService *service,
return 0;
}
-#endif
gint
lasso_profile_service_process_query_response_msg(LassoProfileService *service,
@@ -421,6 +568,7 @@ lasso_profile_service_process_query_response_msg(LassoProfileService *service,
return 0;
}
+#endif
gint
lasso_profile_service_process_modify_response_msg(LassoProfileService *service,
diff --git a/lasso/id-wsf/profile_service.h b/lasso/id-wsf/profile_service.h
index a1d22e3f..53239fb0 100644
--- a/lasso/id-wsf/profile_service.h
+++ b/lasso/id-wsf/profile_service.h
@@ -98,6 +98,9 @@ LASSO_EXPORT LassoDstModification* lasso_profile_service_init_modify(
LASSO_EXPORT gint lasso_profile_service_init_query(LassoProfileService *service,
const char *select);
+LASSO_EXPORT gint lasso_profile_service_build_response_msg(LassoProfileService *service);
+LASSO_EXPORT xmlNode* lasso_profile_service_get_answer(LassoProfileService *service,
+ const char *select);
LASSO_EXPORT xmlNode* lasso_profile_service_get_xmlNode(LassoProfileService *service,
gchar *itemId);
@@ -116,9 +119,7 @@ LASSO_EXPORT gint lasso_profile_service_process_query_msg(LassoProfileService *s
const char *message);
LASSO_EXPORT gint lasso_profile_service_process_query_response_msg(LassoProfileService *service,
- const gchar *prefix,
- const gchar *href,
- const gchar *soap_msg);
+ const char *message);
LASSO_EXPORT gint lasso_profile_service_validate_modify(LassoProfileService *service,
const gchar *prefix,
diff --git a/lasso/xml/dst_query.c b/lasso/xml/dst_query.c
index 80f51687..91541532 100644
--- a/lasso/xml/dst_query.c
+++ b/lasso/xml/dst_query.c
@@ -91,6 +91,28 @@ get_xmlNode(LassoNode *node, gboolean lasso_dump)
return xmlnode;
}
+static int
+init_from_xml(LassoNode *node, xmlNode *xmlnode)
+{
+ int rc;
+ LassoDstQuery *query = LASSO_DST_QUERY(node);
+
+ rc = parent_class->init_from_xml(node, xmlnode);
+ if (rc) return rc;
+
+ if (strcmp((char*)xmlnode->ns->href, LASSO_PP_HREF) == 0) {
+ query->hrefServiceType = g_strdup(LASSO_PP_HREF);
+ query->prefixServiceType = g_strdup(LASSO_PP_PREFIX);
+ } else if (strcmp((char*)xmlnode->ns->href, LASSO_EP_HREF) == 0) {
+ query->hrefServiceType = g_strdup(LASSO_EP_HREF);
+ query->prefixServiceType = g_strdup(LASSO_EP_PREFIX);
+ } else {
+ /* XXX */
+ }
+
+ return 0;
+}
+
/*****************************************************************************/
/* instance and class init functions */
/*****************************************************************************/
@@ -110,13 +132,14 @@ instance_init(LassoDstQuery *node)
static void
class_init(LassoDstQueryClass *klass)
{
- LassoNodeClass *nodeClass = LASSO_NODE_CLASS(klass);
+ LassoNodeClass *nclass = LASSO_NODE_CLASS(klass);
parent_class = g_type_class_peek_parent(klass);
- nodeClass->get_xmlNode = get_xmlNode;
- nodeClass->node_data = g_new0(LassoNodeClassData, 1);
- lasso_node_class_set_nodename(nodeClass, "Query");
- lasso_node_class_add_snippets(nodeClass, schema_snippets);
+ 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, "Query");
+ lasso_node_class_add_snippets(nclass, schema_snippets);
}
GType
diff --git a/lasso/xml/dst_query_response.c b/lasso/xml/dst_query_response.c
index d26ecc5f..338ea927 100644
--- a/lasso/xml/dst_query_response.c
+++ b/lasso/xml/dst_query_response.c
@@ -95,6 +95,29 @@ get_xmlNode(LassoNode *node, gboolean lasso_dump)
return xmlnode;
}
+
+static int
+init_from_xml(LassoNode *node, xmlNode *xmlnode)
+{
+ int rc;
+ LassoDstQueryResponse *response = LASSO_DST_QUERY_RESPONSE(node);
+
+ rc = parent_class->init_from_xml(node, xmlnode);
+ if (rc) return rc;
+
+ if (strcmp((char*)xmlnode->ns->href, LASSO_PP_HREF) == 0) {
+ response->hrefServiceType = g_strdup(LASSO_PP_HREF);
+ response->prefixServiceType = g_strdup(LASSO_PP_PREFIX);
+ } else if (strcmp((char*)xmlnode->ns->href, LASSO_EP_HREF) == 0) {
+ response->hrefServiceType = g_strdup(LASSO_EP_HREF);
+ response->prefixServiceType = g_strdup(LASSO_EP_PREFIX);
+ } else {
+ /* XXX */
+ }
+
+ return 0;
+}
+
/*****************************************************************************/
/* instance and class init functions */
/*****************************************************************************/
@@ -117,13 +140,14 @@ instance_init(LassoDstQueryResponse *node)
static void
class_init(LassoDstQueryResponseClass *klass)
{
- LassoNodeClass *nodeClass = LASSO_NODE_CLASS(klass);
+ LassoNodeClass *nclass = LASSO_NODE_CLASS(klass);
parent_class = g_type_class_peek_parent(klass);
- nodeClass->get_xmlNode = get_xmlNode;
- nodeClass->node_data = g_new0(LassoNodeClassData, 1);
- lasso_node_class_set_nodename(nodeClass, "QueryResponse");
- lasso_node_class_add_snippets(nodeClass, schema_snippets);
+ nclass->get_xmlNode = get_xmlNode;
+ nclass->node_data = g_new0(LassoNodeClassData, 1);
+ nclass->init_from_xml = init_from_xml;
+ lasso_node_class_set_nodename(nclass, "QueryResponse");
+ lasso_node_class_add_snippets(nclass, schema_snippets);
}
GType
diff --git a/lasso/xml/xml.c b/lasso/xml/xml.c
index 724fed30..43d8b126 100644
--- a/lasso/xml/xml.c
+++ b/lasso/xml/xml.c
@@ -430,7 +430,6 @@ lasso_node_impl_get_xmlNode(LassoNode *node, gboolean lasso_dump)
LassoNode *value_node;
struct XmlSnippet *version_snippet;
-
if (class->node_data == NULL)
return NULL;
@@ -1413,7 +1412,7 @@ xmlDeclareNs(xmlNode *root_node, xmlNode *node)
return;
for (ns = node->nsDef; ns; ns = ns->next)
- if (strcmp((char*)ns->prefix, "xsi") != 0)
+ if (ns->prefix && strcmp((char*)ns->prefix, "xsi") != 0)
xmlNewNs(root_node, ns->href, ns->prefix);
for (t = node->children; t; t = t->next)
if (t->type == XML_ELEMENT_NODE)
diff --git a/swig/Lasso-wsf.i b/swig/Lasso-wsf.i
index 3afb5bac..81b16676 100644
--- a/swig/Lasso-wsf.i
+++ b/swig/Lasso-wsf.i
@@ -4056,10 +4056,6 @@ typedef struct {
int buildRequestMsg();
END_THROW_ERROR
- THROW_ERROR
- int buildResponseMsg();
- END_THROW_ERROR
-
/* Methods */
LassoDstData *addData(char *xmlNodeBuffer);
@@ -4075,6 +4071,13 @@ typedef struct {
char *select);
THROW_ERROR
+ int buildResponseMsg();
+ END_THROW_ERROR
+
+ %newobject getAnswer;
+ char* getAnswer(const char *select = NULL);
+
+ THROW_ERROR
gint initQuery(const char *select);
END_THROW_ERROR
@@ -4093,7 +4096,7 @@ typedef struct {
END_THROW_ERROR
THROW_ERROR
- int processQueryResponseMsg(char *prefix, char *href, char *soap_msg);
+ int processQueryResponseMsg(const char *message);
END_THROW_ERROR
THROW_ERROR
@@ -4169,9 +4172,9 @@ typedef struct {
/* Implementations of methods inherited from WsfProfile */
#define LassoProfileService_buildRequestMsg(self) lasso_wsf_profile_build_soap_request_msg(LASSO_WSF_PROFILE(self))
-#define LassoProfileService_buildResponseMsg(self) lasso_wsf_profile_build_soap_response_msg(LASSO_WSF_PROFILE(self))
/* Methods implementations */
+#define LassoProfileService_buildResponseMsg lasso_profile_service_build_response_msg
#define LassoProfileService_addData lasso_profile_service_add_data
#define LassoProfileService_addModification lasso_profile_service_add_modification
#define LassoProfileService_addQueryItem lasso_profile_service_add_query_item
@@ -4184,6 +4187,7 @@ typedef struct {
#define LassoProfileService_processQueryResponseMsg lasso_profile_service_process_query_response_msg
#define LassoProfileService_validateModify lasso_profile_service_validate_modify
#define LassoProfileService_validateQuery lasso_profile_service_validate_query
+#define LassoProfileService_getAnswer(self,select) get_xml_string(lasso_profile_service_get_answer(self, select))
%}