Revision f1f60f52 libavformat/applehttpproto.c

View differences:

libavformat/applehttpproto.c
75 75
    return len;
76 76
}
77 77

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

  
129 78
static void free_segment_list(AppleHTTPContext *s)
130 79
{
131 80
    int i;
......
201 150
                    goto fail;
202 151
                }
203 152
                seg->duration = duration;
204
                make_absolute_url(seg->url, sizeof(seg->url), url, line);
153
                ff_make_absolute_url(seg->url, sizeof(seg->url), url, line);
205 154
                dynarray_add(&s->segments, &s->n_segments, seg);
206 155
                is_segment = 0;
207 156
            } else if (is_variant) {
......
211 160
                    goto fail;
212 161
                }
213 162
                var->bandwidth = bandwidth;
214
                make_absolute_url(var->url, sizeof(var->url), url, line);
163
                ff_make_absolute_url(var->url, sizeof(var->url), url, line);
215 164
                dynarray_add(&s->variants, &s->n_variants, var);
216 165
                is_variant = 0;
217 166
            }

Also available in: Unified diff