#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);
}
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,"<")
+ 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,">")
+ p += 4;
+ break;
+ case '&':
+ if(left<=5) { return -1; }
+ memmove(&(p[5]),p,len);
+ strcpy(p,"&")
+ p += 5;
+ break;
+ default:
+ return -1;
+ }
+
+ p = strpbrk(p,to_escape);
+ }
+
+ return 1;
}
int meta_info(const char *path, struct rss_channel_info *info) {
}
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;
}