...
authoralex <[email protected]>
Thu, 30 Dec 2021 01:12:50 +0000 (17:12 -0800)
committeralex <[email protected]>
Thu, 30 Dec 2021 01:12:50 +0000 (17:12 -0800)
inc/meta.h
src/meta.c
test/unit/test_utils.h

index 3f221788c25ce5a69cd224638c0e866f4d93366f..94f0d1262a8df912859fc73dc82aa7854423a480 100644 (file)
@@ -1,6 +1,13 @@
 #ifndef __META_H_
 #define __META_H_
 
+#define _XOPEN_SOURCE
+#define _POSIX_C_SOURCE 200809L
+#include<time.h>
+
+#include<string.h>
+#include<sys/types.h>
+
 #include<fs.h>
 #include<rss.h>
 
index f920befc59137966c0fe8550f9b720931ee695c3..e0ebd800303ac04ac7a744624406250ffecdfb32 100644 (file)
@@ -22,7 +22,11 @@ int meta_entry(const char *path, struct rss_entry *entry) {
                } else if(strcmp(key,RSS_TAG_LINK)==0) {
                        entry->link = strndup(value,i);
                } else if(strcmp(key,RSS_TAG_PUBDATE)==0) {
-                       return -1;
+                       if(NULL==strptime(
+                               value, /* const char *s */
+                               "%a, %d %b %Y %H:%M:%S %z", /* const char *format */
+                               &(entry->pub_date) /* struct tm *tm */
+                       )) { return -1; }
                } else if(strcmp(key,RSS_TAG_DESCRIPTION)==0) {
                        entry->description = strndup(value,i);
                } else if(strcmp(key,RSS_TAG_GUID)==0) {
@@ -109,7 +113,11 @@ int meta_info(const char *path, struct rss_channel_info *info) {
                } else if(strcmp(key,RSS_TAG_LANGUAGE)==0) {
                        info->language = strndup(value,i);
                } else if(strcmp(key,RSS_TAG_LASTBUILDDATE)==0) {
-                       return -1;
+                       if(NULL==strptime(
+                               value, /* const char *s */
+                               "%a, %d %b %Y %H:%M:%S %z", /* const char *format */
+                               &(info->last_build_date) /* struct tm *tm */
+                       )) { return -1; }
                } else { goto panic; }
        }
 
@@ -157,7 +165,7 @@ static ssize_t next_line(FILE *fp, char **key, char **value, char *buf, size_t b
        (*value) = strchr(buf,'=');
        if(NULL==(*value)) { return -1; }
 
-       (*value) = '\0';
+       (**value) = '\0';
        (*value)++;
        return buf_size - strlen(*key);
 }
index cc429040f4f8ea8a6f94c4c999ff0ec72932d0cb..c7577b23ec350775d1a7e5d9ede3330c58119dcc 100644 (file)
@@ -24,9 +24,9 @@
 #define TEST_FILE_6 PREFIX "/file.torrent"
 #define TEST_FILE_7 PREFIX "/file.feed"
 #define TEST_FILE_8 PREFIX "/test.meta"
-#define TEST_FILE_8_CONTENTS "title=test title\nlink=https://whatisarealink.com\npubDate=0000\ndescription=I wonder if \\n this'll properly be formatted/escaped \\><?\nguid=magnet=asldkfjsldkfjslkdjfldsdjlfkjsdf"
+#define TEST_FILE_8_CONTENTS "title=test title\nlink=https://whatisarealink.com\npubDate=Wed, 29 Dec 2021 12:21:12 +0000\ndescription=I wonder if \\n this'll properly be formatted/escaped \\><?\nguid=magnet=asldkfjsldkfjslkdjfldsdjlfkjsdf"
 #define TEST_FILE_9 PREFIX "/.meta"
-#define TEST_FILE_9_CONTENTS "title=TITLE\nlink=http://test.com\ndescription=what is a description\nlanguage=en-us\nlastBuildDate=0000"
+#define TEST_FILE_9_CONTENTS "title=TITLE\nlink=http://test.com\ndescription=what is a description\nlanguage=en-us\nlastBuilDate=Wed, 29 Dec 2021 12:21:12 +0000"
 
 void clean_env();
 void reset_env();