RE: [PATCH] Add a basic date format check to DIDL-Lite parser (v3)
- From: Santakivi Topi <Topi Santakivi digia com>
- To: Sven Neumann <s neumann raumfeld com>
- Cc: "gupnp-list gnome org" <gupnp-list gnome org>
- Subject: RE: [PATCH] Add a basic date format check to DIDL-Lite parser (v3)
- Date: Wed, 6 Jul 2011 16:57:04 +0300
---
libgupnp-av/gupnp-didl-lite-parser.c | 61 +++++++++++++++++++++++++--------
libgupnp-av/gupnp-didl-lite-parser.h | 4 ++-
2 files changed, 49 insertions(+), 16 deletions(-)
diff --git a/libgupnp-av/gupnp-didl-lite-parser.c b/libgupnp-av/gupnp-didl-lite-parser.c
index aa2d07a..a515d5b 100644
--- a/libgupnp-av/gupnp-didl-lite-parser.c
+++ b/libgupnp-av/gupnp-didl-lite-parser.c
@@ -28,6 +28,7 @@
*/
#include <string.h>
+#include <glib/gregex.h>
#include "gupnp-av.h"
#include "gupnp-didl-lite-object-private.h"
#include "xml-util.h"
@@ -36,6 +37,10 @@ G_DEFINE_TYPE (GUPnPDIDLLiteParser,
gupnp_didl_lite_parser,
G_TYPE_OBJECT);
+struct _GUPnPDIDLLiteParserPrivate {
+ GRegex *date_regex;
+};
+
enum {
OBJECT_AVAILABLE,
ITEM_AVAILABLE,
@@ -46,14 +51,36 @@ enum {
static guint signals[SIGNAL_LAST];
static gboolean
-verify_didl_attributes (xmlNode *node)
+verify_didl_attributes (GUPnPDIDLLiteParser *parser, xmlNode *node)
{
- return xml_util_verify_attribute_is_boolean (node, "restricted");
+ const char* content;
+
+ content = xml_util_get_child_element_content (node, "date");
+ if (content != NULL)
+ {
+ if (!g_regex_match(parser->priv->date_regex,
+ content,
+ G_REGEX_MATCH_ANCHORED,
+ NULL)) {
+ return FALSE;
+ }
+ }
+
+ return xml_util_verify_attribute_is_boolean (node, "restricted");
}
static void
gupnp_didl_lite_parser_init (GUPnPDIDLLiteParser *parser)
{
+ parser->priv =
+ G_TYPE_INSTANCE_GET_PRIVATE (parser,
+ GUPNP_TYPE_DIDL_LITE_PARSER,
+ GUPnPDIDLLiteParserPrivate);
+
+ parser->priv->date_regex = g_regex_new("\\d\\d\\d\\d-\\d\\d-\\d\\d",
+ (GRegexCompileFlags)0,
+ (GRegexMatchFlags)0,
+ NULL);
}
static void
@@ -64,6 +91,8 @@ gupnp_didl_lite_parser_dispose (GObject *object)
parser = GUPNP_DIDL_LITE_PARSER (object);
+ g_regex_unref(parser->priv->date_regex);
+
gobject_class = G_OBJECT_CLASS (gupnp_didl_lite_parser_parent_class);
gobject_class->dispose (object);
}
@@ -77,6 +106,8 @@ gupnp_didl_lite_parser_class_init (GUPnPDIDLLiteParserClass *klass)
object_class->dispose = gupnp_didl_lite_parser_dispose;
+ g_type_class_add_private (klass, sizeof (GUPnPDIDLLiteParserPrivate));
+
/**
* GUPnPDIDLLiteParser::object-available
* @parser: The #GUPnPDIDLLiteParser that received the signal
@@ -275,21 +306,21 @@ gupnp_didl_lite_parser_parse_didl (GUPnPDIDLLiteParser *parser,
if (GUPNP_IS_DIDL_LITE_CONTAINER (object))
g_signal_emit (parser,
- signals[CONTAINER_AVAILABLE],
- 0,
- object);
+ signals[CONTAINER_AVAILABLE],
+ 0,
+ object);
else if (GUPNP_IS_DIDL_LITE_ITEM (object)) {
node = gupnp_didl_lite_object_get_xml_node(object);
- if (!verify_didl_attributes(node)) {
- g_object_unref (object);
- g_object_unref (xml_doc);
- g_set_error (error,
- GUPNP_XML_ERROR,
- GUPNP_XML_ERROR_INVALID_ATTRIBUTE,
- "Could not parse DIDL-Lite XML:\n%s",
- didl);
-
- return FALSE;
+ if (!verify_didl_attributes(parser, node)) {
+ g_object_unref (object);
+ g_object_unref (xml_doc);
+ g_set_error (error,
+ GUPNP_XML_ERROR,
+ GUPNP_XML_ERROR_INVALID_ATTRIBUTE,
+ "Could not parse DIDL-Lite XML:\n%s",
+ didl);
+
+ return FALSE;
}
g_signal_emit (parser,
diff --git a/libgupnp-av/gupnp-didl-lite-parser.h b/libgupnp-av/gupnp-didl-lite-parser.h
index debf662..7242277 100644
--- a/libgupnp-av/gupnp-didl-lite-parser.h
+++ b/libgupnp-av/gupnp-didl-lite-parser.h
@@ -52,10 +52,12 @@ gupnp_didl_lite_parser_get_type (void) G_GNUC_CONST;
GUPNP_TYPE_DIDL_LITE_PARSER, \
GUPnPDIDLLiteParserClass))
+typedef struct _GUPnPDIDLLiteParserPrivate GUPnPDIDLLiteParserPrivate;
+
typedef struct {
GObject parent;
- gpointer gupnp_reserved;
+ GUPnPDIDLLiteParserPrivate *priv;
} GUPnPDIDLLiteParser;
typedef struct {
--
1.7.1
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]