From 06f8a5a52f95ea2e902072dc70cad013c68c4577 Mon Sep 17 00:00:00 2001 From: alex Date: Wed, 29 Dec 2021 11:48:05 -0800 Subject: [PATCH] ... --- inc/meta.h | 1 + src/meta.c | 77 +++++++++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 72 insertions(+), 6 deletions(-) diff --git a/inc/meta.h b/inc/meta.h index 64106e1..3f22178 100644 --- a/inc/meta.h +++ b/inc/meta.h @@ -1,6 +1,7 @@ #ifndef __META_H_ #define __META_H_ +#include #include #define META_MAX_LINE_SIZE 1024 diff --git a/src/meta.c b/src/meta.c index 561b5ad..18b74a4 100644 --- a/src/meta.c +++ b/src/meta.c @@ -1,6 +1,6 @@ #include -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,"<") + 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) { @@ -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; } -- 2.30.2