From: alex Date: Wed, 29 Dec 2021 01:40:41 +0000 (-0800) Subject: ... X-Git-Url: http://git.infiniteadaptability.org/?a=commitdiff_plain;h=87ef6e83219c39e55f1d2990573cf26504bb9d47;p=seeder ... --- diff --git a/inc/meta.h b/inc/meta.h new file mode 100644 index 0000000..64106e1 --- /dev/null +++ b/inc/meta.h @@ -0,0 +1,11 @@ +#ifndef __META_H_ +#define __META_H_ + +#include + +#define META_MAX_LINE_SIZE 1024 + +int meta_entry(const char*,struct rss_entry*); +int meta_info(const char*,struct rss_channel_info*); + +#endif diff --git a/inc/rss.h b/inc/rss.h index adcbdb0..848b320 100644 --- a/inc/rss.h +++ b/inc/rss.h @@ -21,26 +21,36 @@ struct rss_entry { char *guid; }; -#define RSS_TAG_CHANNEL_START "" -#define RSS_TAG_CHANNEL_END "" -#define RSS_TAG_DESCRIPTION_START "" -#define RSS_TAG_DESCRIPTION_END "" -#define RSS_TAG_GUID_START "" -#define RSS_TAG_GUID_END "" -#define RSS_TAG_ITEM_START "" -#define RSS_TAG_ITEM_END "" -#define RSS_TAG_LANGUAGE_START "" -#define RSS_TAG_LANGUAGE_END "" -#define RSS_TAG_LASTBUILDDATE_START "" -#define RSS_TAG_LASTBUILDDATE_END "" -#define RSS_TAG_LINK_START "" -#define RSS_TAG_LINK_END "" -#define RSS_TAG_PUBDATE_START "" -#define RSS_TAG_PUBDATE_END "" -#define RSS_TAG_RSS_START "" -#define RSS_TAG_RSS_END "" -#define RSS_TAG_TITLE_START "" -#define RSS_TAG_TITLE_END "" +#define RSS_TAG_CHANNEL "channel" +#define RSS_TAG_CHANNEL_START "<" RSS_TAG_CHANNEL ">" +#define RSS_TAG_CHANNEL_END "" +#define RSS_TAG_DESCRIPTION "description" +#define RSS_TAG_DESCRIPTION_START "<" RSS_TAG_DESCRIPTION ">" +#define RSS_TAG_DESCRIPTION_END "" +#define RSS_TAG_GUID "guid" +#define RSS_TAG_GUID_START "<" RSS_TAG_GUID ">" +#define RSS_TAG_GUID_END "" +#define RSS_TAG_ITEM "item" +#define RSS_TAG_ITEM_START "<" RSS_TAG_ITEM ">" +#define RSS_TAG_ITEM_END "" +#define RSS_TAG_LANGUAGE "language" +#define RSS_TAG_LANGUAGE_START "<" RSS_TAG_LANGUAGE ">" +#define RSS_TAG_LANGUAGE_END "" +#define RSS_TAG_LASTBUILDDATE "lastBuildDate" +#define RSS_TAG_LASTBUILDDATE_START "<" RSS_TAG_LASTBUILDDATE ">" +#define RSS_TAG_LASTBUILDDATE_END "" +#define RSS_TAG_LINK "link" +#define RSS_TAG_LINK_START "<" RSS_TAG_LINK ">" +#define RSS_TAG_LINK_END "" +#define RSS_TAG_PUBDATE "pubDate" +#define RSS_TAG_PUBDATE_START "<" RSS_TAG_PUBDATE ">" +#define RSS_TAG_PUBDATE_END "" +#define RSS_TAG_RSS "rss" +#define RSS_TAG_RSS_START "<" RSS_TAG_RSS " version=\"2.0\">" +#define RSS_TAG_RSS_END "" +#define RSS_TAG_TITLE "title" +#define RSS_TAG_TITLE_START "<" RSS_TAG_TITLE ">" +#define RSS_TAG_TITLE_END "" #define RSS_DEFAULT_CHANNEL_DESCRIPTION "" #define RSS_DEFAULT_ENTRY_DESCRIPTION "no description" diff --git a/src/meta.c b/src/meta.c new file mode 100644 index 0000000..561b5ad --- /dev/null +++ b/src/meta.c @@ -0,0 +1,83 @@ +#include + +static int meta_escape(char *buf, size_t buf_size); +static FILE *meta_search(const char*); +static ssize_t next_line(FILE*,char*,size_t); + +int meta_entry(const char *path, struct rss_entry *entry) { + char buf[META_MAX_LINE_SIZE]; + char *key, *value; + FILE *fp; + + fp = meta_search(path); + if(NULL==fp) { return 0; } + + while((i = next_line(fp,&key,buf,META_MAX_SIZE))>0) { + if(strcmp(key,RSS_TAG_TITLE)==0) { + entry->title = strndup(value,i); + } else if(strcmp(key,RSS_TAG_LINK)==0) { + entry->link = strndup(value,i); + } else if(strcmp(key,RSS_TAG_PUBDATE)==0) { + return -1; + } else if(strcmp(key,RSS_TAG_DESCRIPTION)==0) { + entry->description = strndup(value,i); + } else if(strcmp(key,RSS_TAG_GUID)==0) { + entry->guid = strndup(value,i); + } else { goto panic; } + } + + if(i<0) { goto panic; } + + fclose(fp); + + return 1; +panic: + fclose(fp); + return -1; +} + +static int meta_escape(char *buf, size_t buf_size) { + return -1; +} + +int meta_info(const char *path, struct rss_channel_info *info) { + char buf[META_MAX_LINE_SIZE]; + char *key, *value; + FILE *fp; + + fp = meta_search(path); + if(NULL==fp) { return 0; } + + while((i = next_line(fp,&key,&value,buf,META_MAX_SIZE))>0) { + if(strcmp(key,RSS_TAG_TITLE)==0) { + info->title = strndup(value,i); + } else if(strcmp(key,RSS_TAG_LINK)==0) { + info->link = strndup(value,i); + } else if(strcmp(key,RSS_TAG_DESCRIPTION)==0) { + info->description = strndup(value,i); + } else if(strcmp(key,RSS_TAG_LANGUAGE)==0) { + entry->language = strndup(value,i); + } else if(strcmp(key,RSS_TAG_LASTBUILDDATE)==0) { + return -1; + } else { goto panic; } + } + + if(i<0) { goto panic; } + + fclose(fp); + + return 1; +panic: + fclose(fp); + return -1; +} + +static FILE *meta_search(const char *path) { + return NULL; +} + +static ssize_t next_line(FILE *fp, char *buf, size_t buf_size) { + // escape+parse + // + return -1; +}