RE: [PATCH] Add a basic date format check to DIDL-Lite parser
- 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
- Date: Wed, 6 Jul 2011 16:44:07 +0300
---
libgupnp-av/gupnp-didl-lite-parser.c | 40 ++++++++++++++++++++++++++++++++-
libgupnp-av/gupnp-didl-lite-parser.h | 4 ++-
2 files changed, 41 insertions(+), 3 deletions(-)
diff --git a/libgupnp-av/gupnp-didl-lite-parser.c b/libgupnp-av/gupnp-didl-lite-parser.c
index aa2d07a..e229720 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,41 @@ enum {
static guint signals[SIGNAL_LAST];
static gboolean
-verify_didl_attributes (xmlNode *node)
+verify_didl_attributes (GUPnPDIDLLiteParser *parser, xmlNode *node)
{
+ GRegex* regex;
+ const char* content;
+ gboolean result;
+
+ content = xml_util_get_child_element_content (node, "date");
+ if (content != NULL)
+ {
+ result = g_regex_match(parser->priv->date_regex,
+ content,
+ G_REGEX_MATCH_ANCHORED,
+ NULL);
+ if (!result)
+ {
+ g_regex_unref(regex);
+ 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 +96,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 +111,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
@@ -280,7 +316,7 @@ gupnp_didl_lite_parser_parse_didl (GUPnPDIDLLiteParser *parser,
object);
else if (GUPNP_IS_DIDL_LITE_ITEM (object)) {
node = gupnp_didl_lite_object_get_xml_node(object);
- if (!verify_didl_attributes(node)) {
+ if (!verify_didl_attributes(parser, node)) {
g_object_unref (object);
g_object_unref (xml_doc);
g_set_error (error,
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]