Revision f1f60f52 libavformat/applehttp.c

View differences:

libavformat/applehttp.c
86 86
    return len;
87 87
}
88 88

  
89
static void make_absolute_url(char *buf, int size, const char *base,
90
                              const char *rel)
91
{
92
    char *sep;
93
    /* Absolute path, relative to the current server */
94
    if (base && strstr(base, "://") && rel[0] == '/') {
95
        if (base != buf)
96
            av_strlcpy(buf, base, size);
97
        sep = strstr(buf, "://");
98
        if (sep) {
99
            sep += 3;
100
            sep = strchr(sep, '/');
101
            if (sep)
102
                *sep = '\0';
103
        }
104
        av_strlcat(buf, rel, size);
105
        return;
106
    }
107
    /* If rel actually is an absolute url, just copy it */
108
    if (!base || strstr(rel, "://") || rel[0] == '/') {
109
        av_strlcpy(buf, rel, size);
110
        return;
111
    }
112
    if (base != buf)
113
        av_strlcpy(buf, base, size);
114
    /* Remove the file name from the base url */
115
    sep = strrchr(buf, '/');
116
    if (sep)
117
        sep[1] = '\0';
118
    else
119
        buf[0] = '\0';
120
    while (av_strstart(rel, "../", NULL) && sep) {
121
        /* Remove the path delimiter at the end */
122
        sep[0] = '\0';
123
        sep = strrchr(buf, '/');
124
        /* If the next directory name to pop off is "..", break here */
125
        if (!strcmp(sep ? &sep[1] : buf, "..")) {
126
            /* Readd the slash we just removed */
127
            av_strlcat(buf, "/", size);
128
            break;
129
        }
130
        /* Cut off the directory name */
131
        if (sep)
132
            sep[1] = '\0';
133
        else
134
            buf[0] = '\0';
135
        rel += 3;
136
    }
137
    av_strlcat(buf, rel, size);
138
}
139

  
140 89
static void free_segment_list(struct variant *var)
141 90
{
142 91
    int i;
......
183 132
        return NULL;
184 133
    reset_packet(&var->pkt);
185 134
    var->bandwidth = bandwidth;
186
    make_absolute_url(var->url, sizeof(var->url), base, url);
135
    ff_make_absolute_url(var->url, sizeof(var->url), base, url);
187 136
    dynarray_add(&c->variants, &c->n_variants, var);
188 137
    return var;
189 138
}
......
274 223
                    goto fail;
275 224
                }
276 225
                seg->duration = duration;
277
                make_absolute_url(seg->url, sizeof(seg->url), url, line);
226
                ff_make_absolute_url(seg->url, sizeof(seg->url), url, line);
278 227
                dynarray_add(&var->segments, &var->n_segments, seg);
279 228
                is_segment = 0;
280 229
            }

Also available in: Unified diff