diff --git a/remux.c b/remux.c index 02723c90e52e608e94f1a82641ef6d086890eb53..0eb4c39b58f11f0bfa3ea5406f57874398163762 100644 --- a/remux.c +++ b/remux.c @@ -9,13 +9,12 @@ static AVRational chapter_time_base = {1, 1}; void parse_dict(AVDictionary **d, char *s) { char *val; - char key[JSTR_SIZE], value[JSTR_SIZE]; for (s = jenter(s); s; s = jnext(s)) { - if (val = jstrb(jvalue(s), 0, value)) - av_dict_set(d, jstrb(s, 0, key), val, 0); + if (val = jstr(jvalue(s), 0)) + av_dict_set(d, jstr(s, 0), val, 0); else - av_dict_set_int(d, jstrb(s, 0, key), jint(jvalue(s), 0), 0); + av_dict_set_int(d, jstr(s, 0), jint(jvalue(s), 0), 0); } } diff --git a/thumbnail.c b/thumbnail.c index 0266bcc9f67f4a4dbeec3039188b613c26f20256..047639f0bdccc484a8e48d55ce96812c5109a4bf 100644 --- a/thumbnail.c +++ b/thumbnail.c @@ -25,7 +25,7 @@ AVFrame *scale_frame(AVFrame *frame, enum AVPixelFormat pix_fmt, int main(int argc, char *argv[]) { int err, vidx; - char lectureid[JSTR_SIZE], *src, *tmp, *dest; + char *src, *tmp, *dest; AVFormatContext *demux, *mux; AVCodecContext *dec, *enc; AVPacket pkt; @@ -37,10 +37,10 @@ int main(int argc, char *argv[]) /* Prepare arguments */ jobid = atoi(argv[1]); - jstrb(jlookup(argv[4], "lectureid"), "-1", lectureid); src = mprintf("%s/%s", CONFIG_VIDEOS_RELEASED, jstr(jlookup(argv[4], "path"), "")); tmp = mprintf("%s/.tmp-%i", CONFIG_VIDEOS_TMP, jobid); - dest = mprintf("%s/thumbnail/l_%s.jpg", CONFIG_VIDEOS_RELEASED, lectureid); + dest = mprintf("%s/thumbnail/l_%s.jpg", CONFIG_VIDEOS_RELEASED, + jstr(jlookup(argv[4], "lectureid"), "0")); ping_job(jobid, "running", 0); /* Open src */ diff --git a/util.h b/util.h index 1a86f0ffcd538755445120b8017cc36ef5af0c52..76870b3710e3bad7472c39fa1278bf0f9aa94f3f 100644 --- a/util.h +++ b/util.h @@ -19,11 +19,11 @@ int ping_job(int id, char *state, char *status, ...); void job_failed(char *msg, ...); /* JSON parser */ -#define JSTR_SIZE 100 +#define JSON_KEY_SIZE 100 ssize_t jbin(char *s, char *buf, size_t len); -char *jstrb(char *s, char *err, char *buf); -char *jstr(char *s, char *err); +char *jstrb(char *s, char *err, char *buf, size_t len); +#define jstr(s, e) jstrb(s, e, (char[JSON_KEY_SIZE]){0}, JSON_KEY_SIZE) int jint(char *s, int err); char *jenter(char *s); char *jnext(char *s); diff --git a/util/json.c b/util/json.c index 9fb84e276846e97683168730b10c548b62bc96a9..3eb44597bf2592b777c18ed1001ca8f7d1624629 100644 --- a/util/json.c +++ b/util/json.c @@ -135,22 +135,16 @@ ssize_t jbin(char *s, char *buf, size_t len) return i; } -char *jstrb(char *s, char *err, char *buf) +char *jstrb(char *s, char *err, char *buf, size_t len) { ssize_t res; - res = jbin(s, buf, JSTR_SIZE); - if (res == -1 || res+1 >= JSTR_SIZE) + res = jbin(s, buf, len); + if (res == -1 || res+1 >= len) return err; buf[res] = 0; return buf; } -char *jstr(char *s, char *err) -{ - static __thread char buf[JSTR_SIZE]; - return jstrb(s, err, buf); -} - int jint(char *s, int err) { if (!s) @@ -199,14 +193,14 @@ char *jvalue(char *s) char *jlookup(char *s, char *key) { - static __thread char buf[JSTR_SIZE]; + static __thread char buf[JSON_KEY_SIZE]; if (!s) return 0; s = skip_ws(s); if (*s != '{') return 0; for (s = skip_ws(s+1); s; s = jnext(s)) - if (!strcmp(jstrb(s, "INVALID KEY", buf), key)) + if (!strcmp(jstrb(s, "INVALID KEY", BL(buf)), key)) return jvalue(s); return 0; }