[gupnp/wip/phako/new-api: 11/17] wip: Move helper code into proper file
- From: Jens Georg <jensgeorg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gupnp/wip/phako/new-api: 11/17] wip: Move helper code into proper file
- Date: Sun, 13 Jan 2019 18:14:08 +0000 (UTC)
commit 44f2e0edca213c0003477c071262ba33865c7e87
Author: Jens Georg <mail jensge org>
Date: Sun Jan 13 17:07:40 2019 +0100
wip: Move helper code into proper file
libgupnp/gupnp-service-proxy-action-private.h | 21 ++++
libgupnp/gupnp-service-proxy-action.c | 165 ++++++++++++++++++++++++--
libgupnp/gupnp-service-proxy.c | 154 ------------------------
3 files changed, 174 insertions(+), 166 deletions(-)
---
diff --git a/libgupnp/gupnp-service-proxy-action-private.h b/libgupnp/gupnp-service-proxy-action-private.h
index 26c78de..1dd8b03 100644
--- a/libgupnp/gupnp-service-proxy-action-private.h
+++ b/libgupnp/gupnp-service-proxy-action-private.h
@@ -1,3 +1,24 @@
+/*
+ * Copyright (C) 2018,2019 The GUPnP maintainers.
+ *
+ * Author: Jens Georg <mail jensge org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
#ifndef GUPNP_SERVICE_PROXY_ACTION_H
#define GUPNP_SERVICE_PROXY_ACTION_H
diff --git a/libgupnp/gupnp-service-proxy-action.c b/libgupnp/gupnp-service-proxy-action.c
index 93880e7..4cfb094 100644
--- a/libgupnp/gupnp-service-proxy-action.c
+++ b/libgupnp/gupnp-service-proxy-action.c
@@ -19,25 +19,166 @@
* Boston, MA 02110-1301, USA.
*/
+#include "gupnp-error-private.h"
#include "gupnp-service-proxy.h"
#include "gupnp-service-proxy-private.h"
#include "gupnp-service-proxy-action-private.h"
#include "gvalue-util.h"
#include "xml-util.h"
+/* Reads a value into the parameter name and initialised GValue pair
+ * from @response */
+static void
+read_out_parameter (const char *arg_name,
+ GValue *value,
+ xmlNode *params)
+{
+ xmlNode *param;
+
+ /* Try to find a matching parameter in the response*/
+ param = xml_util_get_element (params,
+ arg_name,
+ NULL);
+ if (!param) {
+ g_warning ("Could not find variable \"%s\" in response",
+ arg_name);
+
+ return;
+ }
+
+ gvalue_util_set_value_from_xml_node (value, param);
+}
+
+
/* Checks an action response for errors and returns the parsed
* xmlDoc object. */
-
-G_GNUC_INTERNAL xmlDoc *
-_check_action_response (G_GNUC_UNUSED GUPnPServiceProxy *proxy,
+static xmlDoc *
+check_action_response (G_GNUC_UNUSED GUPnPServiceProxy *proxy,
GUPnPServiceProxyAction *action,
xmlNode **params,
- GError **error);
+ GError **error)
+{
+ xmlDoc *response;
+ int code;
+
+ /* Check for errors */
+ switch (action->msg->status_code) {
+ case SOUP_STATUS_OK:
+ case SOUP_STATUS_INTERNAL_SERVER_ERROR:
+ break;
+ default:
+ _gupnp_error_set_server_error (error, action->msg);
+
+ return NULL;
+ }
+
+ /* Parse response */
+ response = xmlRecoverMemory (action->msg->response_body->data,
+ action->msg->response_body->length);
+
+ if (!response) {
+ if (action->msg->status_code == SOUP_STATUS_OK) {
+ g_set_error (error,
+ GUPNP_SERVER_ERROR,
+ GUPNP_SERVER_ERROR_INVALID_RESPONSE,
+ "Could not parse SOAP response");
+ } else {
+ g_set_error_literal
+ (error,
+ GUPNP_SERVER_ERROR,
+ GUPNP_SERVER_ERROR_INTERNAL_SERVER_ERROR,
+ action->msg->reason_phrase);
+ }
+
+ return NULL;
+ }
+
+ /* Get parameter list */
+ *params = xml_util_get_element ((xmlNode *) response,
+ "Envelope",
+ NULL);
+ if (*params != NULL)
+ *params = xml_util_real_node ((*params)->children);
+
+ if (*params != NULL) {
+ if (strcmp ((const char *) (*params)->name, "Header") == 0)
+ *params = xml_util_real_node ((*params)->next);
+
+ if (*params != NULL)
+ if (strcmp ((const char *) (*params)->name, "Body") != 0)
+ *params = NULL;
+ }
+
+ if (*params != NULL)
+ *params = xml_util_real_node ((*params)->children);
+
+ if (*params == NULL) {
+ g_set_error (error,
+ GUPNP_SERVER_ERROR,
+ GUPNP_SERVER_ERROR_INVALID_RESPONSE,
+ "Invalid Envelope");
+
+ xmlFreeDoc (response);
+
+ return NULL;
+ }
+
+ /* Check whether we have a Fault */
+ if (action->msg->status_code == SOUP_STATUS_INTERNAL_SERVER_ERROR) {
+ xmlNode *param;
+ char *desc;
+
+ param = xml_util_get_element (*params,
+ "detail",
+ "UPnPError",
+ NULL);
+
+ if (!param) {
+ g_set_error (error,
+ GUPNP_SERVER_ERROR,
+ GUPNP_SERVER_ERROR_INVALID_RESPONSE,
+ "Invalid Fault");
+
+ xmlFreeDoc (response);
+
+ return NULL;
+ }
+
+ /* Code */
+ code = xml_util_get_child_element_content_int
+ (param, "errorCode");
+ if (code == -1) {
+ g_set_error (error,
+ GUPNP_SERVER_ERROR,
+ GUPNP_SERVER_ERROR_INVALID_RESPONSE,
+ "Invalid Fault");
+
+ xmlFreeDoc (response);
+
+ return NULL;
+ }
+
+ /* Description */
+ desc = xml_util_get_child_element_content_glib
+ (param, "errorDescription");
+ if (desc == NULL)
+ desc = g_strdup (action->msg->reason_phrase);
+
+ g_set_error_literal (error,
+ GUPNP_CONTROL_ERROR,
+ code,
+ desc);
+
+ g_free (desc);
+
+ xmlFreeDoc (response);
+
+ return NULL;
+ }
+
+ return response;
+}
-G_GNUC_INTERNAL void
-_read_out_parameter (const char *arg_name,
- GValue *value,
- xmlNode *params);
/* GDestroyNotify for GHashTable holding GValues.
*/
@@ -232,7 +373,7 @@ gupnp_service_proxy_action_get_result_list (GUPnPServiceProxyAction *action,
}
/* Check response for errors and do initial parsing */
- response = _check_action_response (NULL, action, ¶ms, &action->error);
+ response = check_action_response (NULL, action, ¶ms, &action->error);
if (response == NULL) {
g_propagate_error (error, g_error_copy (action->error));
@@ -247,7 +388,7 @@ gupnp_service_proxy_action_get_result_list (GUPnPServiceProxyAction *action,
val = g_new0 (GValue, 1);
g_value_init (val, (GType) types->data);
- _read_out_parameter (names->data, val, params);
+ read_out_parameter (names->data, val, params);
out_values_list = g_list_append (out_values_list, val);
@@ -294,7 +435,7 @@ gupnp_service_proxy_action_get_result_hash (GUPnPServiceProxyAction *action,
}
/* Check response for errors and do initial parsing */
- response = _check_action_response (NULL, action, ¶ms, &action->error);
+ response = check_action_response (NULL, action, ¶ms, &action->error);
if (response == NULL) {
g_propagate_error (error, g_error_copy (action->error));
@@ -302,7 +443,7 @@ gupnp_service_proxy_action_get_result_hash (GUPnPServiceProxyAction *action,
}
/* Read arguments */
- g_hash_table_foreach (hash, (GHFunc) _read_out_parameter, params);
+ g_hash_table_foreach (hash, (GHFunc) read_out_parameter, params);
/* Cleanup */
xmlFreeDoc (response);
diff --git a/libgupnp/gupnp-service-proxy.c b/libgupnp/gupnp-service-proxy.c
index 2541768..7d03f85 100644
--- a/libgupnp/gupnp-service-proxy.c
+++ b/libgupnp/gupnp-service-proxy.c
@@ -38,9 +38,7 @@
#include "gupnp-service-proxy-action-private.h"
#include "gupnp-context-private.h"
#include "gupnp-error.h"
-#include "gupnp-error-private.h"
#include "gupnp-types.h"
-#include "xml-util.h"
#include "gena-protocol.h"
#include "http-headers.h"
#include "gvalue-util.h"
@@ -945,158 +943,6 @@ gupnp_service_proxy_end_action (GUPnPServiceProxy *proxy,
return ret;
}
-/* Checks an action response for errors and returns the parsed
- * xmlDoc object. */
-xmlDoc *
-_check_action_response (G_GNUC_UNUSED GUPnPServiceProxy *proxy,
- GUPnPServiceProxyAction *action,
- xmlNode **params,
- GError **error)
-{
- xmlDoc *response;
- int code;
-
- /* Check for errors */
- switch (action->msg->status_code) {
- case SOUP_STATUS_OK:
- case SOUP_STATUS_INTERNAL_SERVER_ERROR:
- break;
- default:
- _gupnp_error_set_server_error (error, action->msg);
-
- return NULL;
- }
-
- /* Parse response */
- response = xmlRecoverMemory (action->msg->response_body->data,
- action->msg->response_body->length);
-
- if (!response) {
- if (action->msg->status_code == SOUP_STATUS_OK) {
- g_set_error (error,
- GUPNP_SERVER_ERROR,
- GUPNP_SERVER_ERROR_INVALID_RESPONSE,
- "Could not parse SOAP response");
- } else {
- g_set_error_literal
- (error,
- GUPNP_SERVER_ERROR,
- GUPNP_SERVER_ERROR_INTERNAL_SERVER_ERROR,
- action->msg->reason_phrase);
- }
-
- return NULL;
- }
-
- /* Get parameter list */
- *params = xml_util_get_element ((xmlNode *) response,
- "Envelope",
- NULL);
- if (*params != NULL)
- *params = xml_util_real_node ((*params)->children);
-
- if (*params != NULL) {
- if (strcmp ((const char *) (*params)->name, "Header") == 0)
- *params = xml_util_real_node ((*params)->next);
-
- if (*params != NULL)
- if (strcmp ((const char *) (*params)->name, "Body") != 0)
- *params = NULL;
- }
-
- if (*params != NULL)
- *params = xml_util_real_node ((*params)->children);
-
- if (*params == NULL) {
- g_set_error (error,
- GUPNP_SERVER_ERROR,
- GUPNP_SERVER_ERROR_INVALID_RESPONSE,
- "Invalid Envelope");
-
- xmlFreeDoc (response);
-
- return NULL;
- }
-
- /* Check whether we have a Fault */
- if (action->msg->status_code == SOUP_STATUS_INTERNAL_SERVER_ERROR) {
- xmlNode *param;
- char *desc;
-
- param = xml_util_get_element (*params,
- "detail",
- "UPnPError",
- NULL);
-
- if (!param) {
- g_set_error (error,
- GUPNP_SERVER_ERROR,
- GUPNP_SERVER_ERROR_INVALID_RESPONSE,
- "Invalid Fault");
-
- xmlFreeDoc (response);
-
- return NULL;
- }
-
- /* Code */
- code = xml_util_get_child_element_content_int
- (param, "errorCode");
- if (code == -1) {
- g_set_error (error,
- GUPNP_SERVER_ERROR,
- GUPNP_SERVER_ERROR_INVALID_RESPONSE,
- "Invalid Fault");
-
- xmlFreeDoc (response);
-
- return NULL;
- }
-
- /* Description */
- desc = xml_util_get_child_element_content_glib
- (param, "errorDescription");
- if (desc == NULL)
- desc = g_strdup (action->msg->reason_phrase);
-
- g_set_error_literal (error,
- GUPNP_CONTROL_ERROR,
- code,
- desc);
-
- g_free (desc);
-
- xmlFreeDoc (response);
-
- return NULL;
- }
-
- return response;
-}
-
-/* Reads a value into the parameter name and initialised GValue pair
- * from @response */
-void
-_read_out_parameter (const char *arg_name,
- GValue *value,
- xmlNode *params)
-{
- xmlNode *param;
-
- /* Try to find a matching parameter in the response*/
- param = xml_util_get_element (params,
- arg_name,
- NULL);
- if (!param) {
- g_warning ("Could not find variable \"%s\" in response",
- arg_name);
-
- return;
- }
-
- gvalue_util_set_value_from_xml_node (value, param);
-}
-
/**
* gupnp_service_proxy_end_action_valist:
* @proxy: A #GUPnPServiceProxy
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]