static void pnm_get(ByteIOContext *f, char *str, int buf_size) { char *s; int c; /* skip spaces and comments */ for(;;) { c = url_fgetc(f); if (c == '#') { do { c = url_fgetc(f); } while (c != '\n' && c != URL_EOF); } else if (!pnm_space(c)) { break; } } s = str; while (c != URL_EOF && !pnm_space(c)) { if ((s - str) < buf_size - 1) *s++ = c; c = url_fgetc(f); } *s = '\0'; }
static int redir_read_header(AVFormatContext *s, AVFormatParameters *ap) { char buf[4096], *q; int c; AVFormatContext *ic = NULL; ByteIOContext *f = s->pb; /* parse each URL and try to open it */ c = url_fgetc(f); while (c != URL_EOF) { /* skip spaces */ for(;;) { if (!redir_isspace(c)) break; c = url_fgetc(f); } if (c == URL_EOF) break; /* record url */ q = buf; for(;;) { if (c == URL_EOF || redir_isspace(c)) break; if ((q - buf) < sizeof(buf) - 1) *q++ = c; c = url_fgetc(f); } *q = '\0'; //printf("URL='%s'\n", buf); /* try to open the media file */ if (av_open_input_file(&ic, buf, NULL, 0, NULL) == 0) break; } if (!ic) return AVERROR(EIO); *s = *ic; url_fclose(f); return 0; }
/* called from utils.c */ int redir_open(AVFormatContext **ic_ptr, ByteIOContext *f) { char buf[4096], *q; int c; AVFormatContext *ic = NULL; /* parse each URL and try to open it */ c = url_fgetc(f); while (c != URL_EOF) { /* skip spaces */ for(;;) { if (!redir_isspace(c)) break; c = url_fgetc(f); } if (c == URL_EOF) break; /* record url */ q = buf; for(;;) { if (c == URL_EOF || redir_isspace(c)) break; if ((q - buf) < sizeof(buf) - 1) *q++ = c; c = url_fgetc(f); } *q = '\0'; //printf("URL='%s'\n", buf); /* try to open the media file */ if (av_open_input_file(&ic, buf, NULL, 0, NULL) == 0) break; } *ic_ptr = ic; if (!ic) return AVERROR_IO; else return 0; }
static int xspf_list_files(ByteIOContext *b, char ***flist_ptr, int *len_ptr) { int i, j, c; unsigned int buflen; char state; char **flist, **flist_tmp; char buf[1024]; char buf_tag[10] = {0}; const char match_tag[] = "<location>"; flist = NULL; state = buflen = i = j = 0; while ((c = url_fgetc(b))) { if (c == EOF) break; if (state == 0) { memmove(buf_tag, buf_tag+1, 9); buf_tag[9] = c; if (!memcmp(buf_tag, match_tag, 10)) state = 1; } else { if (c == '<') { termfn: buf[i++] = 0; flist_tmp = av_fast_realloc(flist, &buflen, sizeof(*flist) * (j+2)); if (!flist_tmp) { av_log(NULL, AV_LOG_ERROR, "av_realloc error in m3u_list_files\n"); av_free(flist); return AVERROR_NOMEM; } else flist = flist_tmp; flist[j] = av_malloc(i); av_strlcpy(flist[j++], buf, i); i = 0; state = 0; buf_tag[sizeof(buf_tag)-1] = c; continue; } else { buf[i++] = c; if (i >= sizeof(buf)-1) goto termfn; } } } *flist_ptr = flist; *len_ptr = j; if (!flist) // no files have been found return AVERROR_EOF; flist[j] = 0; return 0; }
DataNode *ff_datanode_tree_from_ini(ByteIOContext *p) { int c; char *s; char e; int i, b; DataNode *o; DataNode *d; d = av_malloc(sizeof(*d)); memset(d, 0, sizeof(*d)); o = d; s = d->name; e = 1; i = b = 0; while (1) { c = url_fgetc(p); if (c == 0 || c == EOF) break; if (c == '\n') { d = ff_datanode_mknext(d); i = b = 0; s = d->name; e = 1; continue; } if (!e) { continue; } if (c == '#') { e = 0; continue; } if (c == '[') { if (d->parent) { d = d->parent; } d = ff_datanode_mknext(d); i = b = 0; s = d->name; continue; } if (c == ']') { d = ff_datanode_mkchild(d); i = b = 0; s = d->name; continue; } if (c == '=') { i = b = 0; s = d->value; continue; } if (i >= b-1) { b += DATANODE_STR_BUFSIZE; if (s == d->name) { s = av_realloc(s, b); d->name = s; } else if (s == d->value) { s = av_realloc(s, b); d->value = s; } } s[i++] = c; s[i] = 0; } return o; }
DataNode *ff_datanode_tree_from_xml(ByteIOContext *p) { int c; char *s; char tag; // tag: // 0 = awaiting opening tag // 1 = either in the opening tag or closing parent // 2 = awaiting closing tag // 3 = either in the closing tag or opening child char ncn; // no closing needed if true char quo; // text is in quotes if true char ctg; // this is the closing tag if true int i, b; DataNode *o; DataNode *d; int ctgidx; // current index in ctgbuf int ctgbuflen; // buffer length of ctgbuf char *ctgbuf = 0; // ctgbuf: used to verify that closing tag matches opening tag name d = av_malloc(sizeof(*d)); memset(d, 0, sizeof(*d)); o = d; s = d->name; tag = ncn = quo = ctg = ctgidx = ctgbuflen = i = b = 0; while (1) { c = url_fgetc(p); if (c == 0 || c == EOF) break; parsetag: if (quo) { // we're in quoted text, tag changes don't matter if (c == '"') { // quote closed quo = 0; } goto writeoutput; } else if (c == '"') { // quote opened quo = 1; goto writeoutput; } if (c == '\n' || c == ' ' || c == '\t') continue; if (tag == 0) { // awaiting opening tag if (c == '<') { // opening tag tag = 1; d = ff_datanode_mknext(d); i = b = 0; s = d->name; continue; } } else if (tag == 1) { // in the opening tag if (c == '>') { // opening tag closed if (ncn) { // no closing tag needed ncn = 0; tag = 0; } else tag = 2; i = b = 0; s = d->value; continue; } else if (c == '/') { if (d->name) { // tag closed, no closing tag needed ncn = 1; continue; } else { // closing parent tag = 3; ctg = 1; ctgidx = 0; memset(ctgbuf, 0, ctgbuflen); d = d->parent; s = d->name; continue; } } else if (c == ' ') { // no longer tag name but attributes // ignore attributes by null-terminating string c = 0; } } else if (tag == 2) { // awaiting closing tag if (c == '<') { // closing tag tag = 3; i = b = 0; s = d->name; continue; } } else if (tag == 3) { // either in the closing tag or opening a new one if (ctg) { if (ctgidx >= ctgbuflen-1) { ctgbuflen += DATANODE_STR_BUFSIZE; ctgbuf = av_realloc(ctgbuf, ctgbuflen); } if (c == '>') { if (strncmp(d->name, ctgbuf, strlen(d->name)) || strlen(d->name) != ctgidx) { fprintf(stderr, "malformed closing tag for %s\n", d->name); // closing anyways } // closing tag closed ctg = 0; memset(ctgbuf, 0, ctgbuflen); ctgidx = 0; tag = 0; } else if (c == ' ') { // ignore spaces and material afterwards ctgbuf[ctgidx++] = 0; ctgbuf[ctgidx] = 0; } else { ctgbuf[ctgidx++] = c; ctgbuf[ctgidx] = 0; } continue; } if (c == '/') { // closing tag ctg = 1; continue; } else { // opening child tag tag = 1; d = ff_datanode_mkchild(d); i = b = 0; s = d->name; goto parsetag; } } writeoutput: if (i >= b-1) { b += DATANODE_STR_BUFSIZE; if (s == d->name) { s = av_realloc(s, b); d->name = s; } else if (s == d->value) { s = av_realloc(s, b); d->value = s; } } s[i++] = c; s[i] = 0; } return o; }