summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJorn Baayen <jorn@openedhand.com>2007-06-27 09:58:24 +0000
committerJorn Baayen <jorn@openedhand.com>2007-06-27 09:58:24 +0000
commit04c25b8124a867d6ff00bebba04d11342d3b658b (patch)
treec2fbead9fdee81392d7e45f4d5daff28c1f94649
parent66930a0742832c03011a8de66399a7c98d88cf5d (diff)
downloadgupnp-04c25b8124a867d6ff00bebba04d11342d3b658b.tar.gz
2007-06-27 Jorn Baayen <jorn@openedhand.com>
* libgupnp/Makefile.am: * libgupnp/gupnp-error.h: * libgupnp/gupnp-service.c: (gupnp_service_action_return_error), (query_state_variable), (control_server_handler): * libgupnp/gupnp-service.h: * libgupnp/upnp-protocol.h: More flexible error handling. git-svn-id: https://svn.o-hand.com/repos/gupnp/trunk/gupnp@259 d8cb91d7-bff9-0310-92b9-80b65e4482b2
-rw-r--r--ChangeLog11
-rw-r--r--libgupnp/Makefile.am1
-rw-r--r--libgupnp/gupnp-error.h8
-rw-r--r--libgupnp/gupnp-service.c33
-rw-r--r--libgupnp/gupnp-service.h4
-rw-r--r--libgupnp/upnp-protocol.h41
6 files changed, 33 insertions, 65 deletions
diff --git a/ChangeLog b/ChangeLog
index a121c00..d27b2fd 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,16 @@
2007-06-27 Jorn Baayen <jorn@openedhand.com>
+ * libgupnp/Makefile.am:
+ * libgupnp/gupnp-error.h:
+ * libgupnp/gupnp-service.c: (gupnp_service_action_return_error),
+ (query_state_variable), (control_server_handler):
+ * libgupnp/gupnp-service.h:
+ * libgupnp/upnp-protocol.h:
+
+ More flexible error handling.
+
+2007-06-27 Jorn Baayen <jorn@openedhand.com>
+
* libgupnp/gupnp-service.c: (gupnp_service_action_get_value),
(gupnp_service_action_set_valist),
(gupnp_service_action_set_value), (gupnp_service_action_return),
diff --git a/libgupnp/Makefile.am b/libgupnp/Makefile.am
index 59d89c5..a0ca971 100644
--- a/libgupnp/Makefile.am
+++ b/libgupnp/Makefile.am
@@ -45,7 +45,6 @@ libgupnp_1_0_la_SOURCES = accept-language.c \
xml-util.c \
xml-util.h \
gena-protocol.h \
- upnp-protocol.h \
$(BUILT_SOURCES)
libgupnp_1_0_la_LIBADD = $(LIBGUPNP_LIBS) xdgmime/libxdgmime.la
diff --git a/libgupnp/gupnp-error.h b/libgupnp/gupnp-error.h
index 842078d..3b4f498 100644
--- a/libgupnp/gupnp-error.h
+++ b/libgupnp/gupnp-error.h
@@ -26,14 +26,6 @@
G_BEGIN_DECLS
-typedef enum {
- GUPNP_ACTION_ERROR_INVALID_ACTION,
- GUPNP_ACTION_ERROR_INVALID_ARGS,
- GUPNP_ACTION_ERROR_OUT_OF_SYNC,
- GUPNP_ACTION_ERROR_ACTION_FAILED,
- GUPNP_ACTION_ERROR_LAST
-} GUPnPActionError;
-
GQuark
gupnp_error_quark (void) G_GNUC_CONST;
diff --git a/libgupnp/gupnp-service.c b/libgupnp/gupnp-service.c
index 3cfd672..8009c9d 100644
--- a/libgupnp/gupnp-service.c
+++ b/libgupnp/gupnp-service.c
@@ -37,7 +37,6 @@
#include "gupnp-marshal.h"
#include "accept-language.h"
#include "xml-util.h"
-#include "upnp-protocol.h"
G_DEFINE_TYPE (GUPnPService,
gupnp_service,
@@ -313,19 +312,22 @@ gupnp_service_action_return (GUPnPServiceAction *action)
/**
* gupnp_service_action_return_error
* @action: A #GUPnPServiceAction
- * @error: The #GError
+ * @error_code: The error code
+ * @error_description: The error description
*
- * Return @error.
+ * Return @error_code.
**/
void
gupnp_service_action_return_error (GUPnPServiceAction *action,
- GUPnPActionError error)
+ guint error_code,
+ const char *error_description)
{
xmlNode *node;
xmlNs *ns;
+ char *tmp;
g_return_if_fail (action != NULL);
- g_return_if_fail (error < GUPNP_ACTION_ERROR_LAST);
+ g_return_if_fail (error_description != NULL);
xmlFreeNode (action->response_node);
action->response_node = xmlNewNode (NULL,
@@ -351,15 +353,17 @@ gupnp_service_action_return_error (GUPnPServiceAction *action,
(const xmlChar *) "u");
xmlSetNs (node, ns);
+ tmp = g_strdup_printf ("%u", error_code);
xmlNewTextChild (node,
NULL,
(const xmlChar *) "errorCode",
- (const xmlChar *) upnp_errors[error].code);
+ (const xmlChar *) tmp);
+ g_free (tmp);
xmlNewTextChild (node,
NULL,
(const xmlChar *) "errorDescription",
- (const xmlChar *) upnp_errors[error].description);
+ (const xmlChar *) error_description);
soup_message_set_status (action->msg,
SOUP_STATUS_INTERNAL_SERVER_ERROR);
@@ -414,8 +418,9 @@ query_state_variable (GUPnPService *service,
/* varName */
var_name = xmlNodeGetContent (node);
if (!var_name) {
- gupnp_service_action_return_error
- (action, GUPNP_ACTION_ERROR_INVALID_ARGS);
+ gupnp_service_action_return_error (action,
+ 402,
+ "Invalid Args");
return;
}
@@ -428,8 +433,9 @@ query_state_variable (GUPnPService *service,
&value);
if (!G_IS_VALUE (&value)) {
- gupnp_service_action_return_error
- (action, GUPNP_ACTION_ERROR_INVALID_ARGS);
+ gupnp_service_action_return_error (action,
+ 402,
+ "Invalid Args");
xmlFree (var_name);
@@ -528,8 +534,9 @@ control_server_handler (SoupServerContext *server_context,
/* Was it handled? */
if (msg->status_code == SOUP_STATUS_NONE) {
/* No. */
- gupnp_service_action_return_error
- (action, GUPNP_ACTION_ERROR_INVALID_ACTION);
+ gupnp_service_action_return_error (action,
+ 401,
+ "Invalid Action");
}
}
diff --git a/libgupnp/gupnp-service.h b/libgupnp/gupnp-service.h
index 0392f7e..1d1990e 100644
--- a/libgupnp/gupnp-service.h
+++ b/libgupnp/gupnp-service.h
@@ -25,7 +25,6 @@
#include <stdarg.h>
#include "gupnp-service-info.h"
-#include "gupnp-error.h"
G_BEGIN_DECLS
@@ -121,7 +120,8 @@ gupnp_service_action_return (GUPnPServiceAction *action);
void
gupnp_service_action_return_error (GUPnPServiceAction *action,
- GUPnPActionError error);
+ guint error_code,
+ const char *error_description);
void
gupnp_service_notify (GUPnPService *service,
diff --git a/libgupnp/upnp-protocol.h b/libgupnp/upnp-protocol.h
deleted file mode 100644
index d38ea1f..0000000
--- a/libgupnp/upnp-protocol.h
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Copyright (C) 2007 OpenedHand Ltd.
- *
- * Author: Jorn Baayen <jorn@openedhand.com>
- *
- * 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., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
- */
-
-#ifndef __UPNP_PROTOCOL_H__
-#define __UPNP_PROTOCOL_H__
-
-#include "gupnp-error.h"
-
-G_BEGIN_DECLS
-
-struct {
- const char *code;
- const char *description;
-} upnp_errors[GUPNP_ACTION_ERROR_LAST] = {
- { "401", "Invalid Action" },
- { "402", "Invalid Args" },
- { "403", "Out of Sync" },
- { "501", "Action Failed" }
-};
-
-G_END_DECLS
-
-#endif /* __UPNP_PROTOCOL_H__ */