]> infiniteadaptability.org Git - seeder/commitdiff
...
authoralex <[email protected]>
Wed, 29 Dec 2021 19:48:05 +0000 (11:48 -0800)
committeralex <[email protected]>
Wed, 29 Dec 2021 19:48:05 +0000 (11:48 -0800)
inc/meta.h
src/meta.c

index 64106e13e26679fe253f7e158758d2cb5e09f63f..3f221788c25ce5a69cd224638c0e866f4d93366f 100644 (file)
@@ -1,6 +1,7 @@
 #ifndef __META_H_
 #define __META_H_
 
+#include<fs.h>
 #include<rss.h>
 
 #define META_MAX_LINE_SIZE 1024
index 561b5ad71e2480dd8e955f0ae811cb0c9167acbb..18b74a4958dce58dc6a549463dfece27becdf683 100644 (file)
@@ -1,6 +1,6 @@
 #include<meta.h>
 
-static int meta_escape(char *buf, size_t buf_size);
+static int meta_escape(char*,size_t);
 static FILE *meta_search(const char*);
 static ssize_t next_line(FILE*,char*,size_t);
 
@@ -37,7 +37,50 @@ panic:
 }
 
 static int meta_escape(char *buf, size_t buf_size) {
-       return -1;
+       char *p;
+       size_t len, left;
+
+       const char to_escape[] = "<\\>&";
+
+       p = strpbrk(buf,to_escape);
+       while(NULL!=p) {
+               len = strlen(p);
+               left = buf_size - (p - buf) - len;
+
+               switch(p[0]) {
+                       case '<':
+                               if(left<=4) { return -1; }
+                               memmove(&(p[4]),p,len);
+                               strcpy(p,"&lt;")
+                               p += 4;
+                               break;
+                       case '\\':
+                               if(p[1]=='n') {
+                                       p[0] = '\n';
+                                       memmove(&(p[1]),&(p[2]),len);
+                                       p++;
+                               }
+                               break;
+                       case '>';
+                               if(left<=4) { return -1; }
+                               memmove(&(p[4]),p,len);
+                               strcpy(p,"&gt;")
+                               p += 4;
+                               break;
+                       case '&':
+                               if(left<=5) { return -1; }
+                               memmove(&(p[5]),p,len);
+                               strcpy(p,"&amp;")
+                               p += 5;
+                               break;
+                       default:
+                               return -1;
+               }
+
+               p = strpbrk(p,to_escape);
+       }
+
+       return 1;
 }
 
 int meta_info(const char *path, struct rss_channel_info *info) {
@@ -73,11 +116,33 @@ panic:
 }
 
 static FILE *meta_search(const char *path) {
-       return NULL;
+       char *p;
+       size_t len;
+
+       if(NULL==path) { return NULL; }
+
+       len = strlen(path);
+       if(0==len) { return NULL; }
+
+       if(1==is_directory(path)) {
+               p = concat(path,".meta");
+               if(NULL==p) { return NULL; }
+       } else {
+               p = malloc(sizeof(char)*len);
+               if(NULL==p) { return NULL; }
+
+               strcpy(p,path);
+               strncat(p,".meta",5);
+       }
+
+       fp = fopen(p,"r");
+       return fp;
 }
 
 static ssize_t next_line(FILE *fp, char *buf, size_t buf_size) {
-       // escape+parse
-       //
-       return -1;
+       if(fgets(buf,buf_size,fp)==NULL) { return -1; }
+
+       if(meta_escape(buf,buf_size)<0) { return -1; }
+
+       return 1;
 }