Re: [PATCH] Add a basic date format check to DIDL-Lite parser



Hi,

On Wed, 2011-07-06 at 14:16 +0300, Santakivi Topi wrote:
> ---
>  libgupnp-av/gupnp-didl-lite-parser.c |   19 +++++++++++++++++++
>  1 files changed, 19 insertions(+), 0 deletions(-)
> 
> diff --git a/libgupnp-av/gupnp-didl-lite-parser.c b/libgupnp-av/gupnp-didl-lite-parser.c
> index aa2d07a..e837b9f 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"
> @@ -48,6 +49,24 @@ static guint signals[SIGNAL_LAST];
>  static gboolean
>  verify_didl_attributes (xmlNode *node)
>  {
> +    GRegex* regex;
> +    const char* content;
> +    gboolean result;
> +
> +    regex = g_regex_new("\\d\\d\\d\\d-\\d\\d-\\d\\d", (GRegexCompileFlags)0, (GRegexMatchFlags)0, NULL);
> +
> +    content = xml_util_get_child_element_content (node, "date");
> +    if (content != NULL)
> +    {
> +        result = g_regex_match(regex, content, G_REGEX_MATCH_ANCHORED, NULL);
> +        if (!result)
> +        {
> +            g_regex_unref(regex);
> +            return FALSE;
> +        }
> +    }
> +    g_regex_unref(regex);
> +
>      return xml_util_verify_attribute_is_boolean (node, "restricted");
>  }
>  

Could we try to keep the DIDL-Lite parser as efficient as possible? It
is already rather slow the way it is implemented right now. This is a
real problem on embedded devices.

For this particular patch I suggest that the GRegex is pre-compiled and
kept with the GUPnPDIDLLiteParser instance.


Sven




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]