static rstr_t * ffmpeg_metadata_rstr(AVMetadata *m, const char *key) { AVMetadataTag *tag; int len; rstr_t *ret; const char *str; char *d; if((tag = av_metadata_get(m, key, NULL, AV_METADATA_IGNORE_SUFFIX)) == NULL) return NULL; if(!utf8_verify(tag->value)) return NULL; str = tag->value; len = strlen(str); ret = rstr_allocl(str, len); d = rstr_data(ret); while(len > 0) { len--; if(d[len] <= ' ' || d[len] == '-') d[len] = 0; else break; } if(*d == 0 || !strncasecmp(d, "http://", 7)) { rstr_release(ret); return NULL; } return ret; }
static token_t * lexer_add_token_string(glw_root_t *gr, token_t *prev, rstr_t *f, int line, const char *start, const char *end, token_type_t type) { token_t *t = glw_view_token_alloc(gr); t->t_rstring = rstr_allocl(start, end - start); deescape_cstyle(rstr_data(t->t_rstring)); lexer_link_token(prev, f, line, t, type); return t; }
static int hc_image(http_connection_t *hc, const char *remain, void *opaque, http_cmd_t method) { htsbuf_queue_t out; image_t *img; char errbuf[200]; const char *content; image_meta_t im = {0}; im.im_no_decoding = 1; rstr_t *url; const char *u = http_arg_get_req(hc, "url"); if(u != NULL) { url = rstr_alloc(u); url_deescape(rstr_data(url)); } else { if(remain == NULL) { return 404; } url = rstr_alloc(remain); } img = backend_imageloader(url, &im, NULL, errbuf, sizeof(errbuf), NULL, NULL); rstr_release(url); if(img == NULL) return http_error(hc, 404, "Unable to load image %s : %s", remain, errbuf); const image_component_t *ic = image_find_component(img, IMAGE_CODED); if(ic == NULL) { image_release(img); return http_error(hc, 404, "Unable to load image %s : Original data not available", remain); } const image_component_coded_t *icc = &ic->coded; htsbuf_queue_init(&out, 0); htsbuf_append(&out, buf_cstr(icc->icc_buf), buf_len(icc->icc_buf)); switch(icc->icc_type) { case IMAGE_JPEG: content = "image/jpeg"; break; case IMAGE_PNG: content = "image/png"; break; case IMAGE_GIF: content = "image/gif"; break; default: content = "image"; break; } image_release(img); return http_send_reply(hc, 0, content, NULL, NULL, 0, &out); }