[totem-pl-parser] podcast: Fix detection of XML formats with whitespace separators



commit ddd03be8c14f81617d89637e438de32e50ee91ea
Author: crvi <crvisqr gmail com>
Date:   Tue Apr 6 05:20:30 2021 +0530

    podcast: Fix detection of XML formats with whitespace separators
    
    This includes needle checks for rss / atom / opml docs.

 plparse/totem-pl-parser-podcast.c | 58 +++++++++++++++++++--------------------
 1 file changed, 28 insertions(+), 30 deletions(-)
---
diff --git a/plparse/totem-pl-parser-podcast.c b/plparse/totem-pl-parser-podcast.c
index 4fd9b24..09427b6 100644
--- a/plparse/totem-pl-parser-podcast.c
+++ b/plparse/totem-pl-parser-podcast.c
@@ -35,53 +35,51 @@
 #include "totem-pl-parser-videosite.h"
 #include "totem-pl-parser-private.h"
 
-#define RSS_NEEDLE "<rss "
-#define RSS_NEEDLE2 "<rss\n"
-#define ATOM_NEEDLE "<feed "
-#define OPML_NEEDLE "<opml "
+#define RSS_NEEDLE "<rss"
+#define ATOM_NEEDLE "<feed"
+#define OPML_NEEDLE "<opml"
 
-const char *
-totem_pl_parser_is_rss (const char *data, gsize len)
+static const char *
+totem_pl_parser_is_xml_type (const char *data,
+                            gsize len,
+                            const char *needle,
+                            const char *mimetype)
 {
-       if (len == 0)
-               return FALSE;
+       gchar *found;
+       gchar separator;
+
+       g_return_val_if_fail (len > 0, NULL);
+
        if (len > MIME_READ_CHUNK_SIZE)
                len = MIME_READ_CHUNK_SIZE;
 
-       if (g_strstr_len (data, len, RSS_NEEDLE) != NULL)
-               return RSS_MIME_TYPE;
-       if (g_strstr_len (data, len, RSS_NEEDLE2) != NULL)
-               return RSS_MIME_TYPE;
+       found = g_strstr_len (data, len, needle);
+       if (!found)
+               return NULL;
+
+       separator = *(found + strlen(needle));
+       if (g_ascii_isspace (separator))
+               return mimetype;
 
        return NULL;
 }
 
 const char *
-totem_pl_parser_is_atom (const char *data, gsize len)
+totem_pl_parser_is_rss (const char *data, gsize len)
 {
-       if (len == 0)
-               return FALSE;
-       if (len > MIME_READ_CHUNK_SIZE)
-               len = MIME_READ_CHUNK_SIZE;
-
-       if (g_strstr_len (data, len, ATOM_NEEDLE) != NULL)
-               return ATOM_MIME_TYPE;
+       return totem_pl_parser_is_xml_type (data, len, RSS_NEEDLE, RSS_MIME_TYPE);
+}
 
-       return NULL;
+const char *
+totem_pl_parser_is_atom (const char *data, gsize len)
+{
+       return totem_pl_parser_is_xml_type (data, len, ATOM_NEEDLE, ATOM_MIME_TYPE);
 }
 
 const char *
 totem_pl_parser_is_opml (const char *data, gsize len)
 {
-       if (len == 0)
-               return FALSE;
-       if (len > MIME_READ_CHUNK_SIZE)
-               len = MIME_READ_CHUNK_SIZE;
-
-       if (g_strstr_len (data, len, OPML_NEEDLE) != NULL)
-               return OPML_MIME_TYPE;
-
-       return NULL;
+       return totem_pl_parser_is_xml_type (data, len, OPML_NEEDLE, OPML_MIME_TYPE);
 }
 
 const char *


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