Revision 682d49f4 libavformat/http.c
libavformat/http.c | ||
---|---|---|
151 | 151 |
return *s->buf_ptr++; |
152 | 152 |
} |
153 | 153 |
|
154 |
static int http_get_line(HTTPContext *s, char *line, int line_size) |
|
155 |
{ |
|
156 |
int ch; |
|
157 |
char *q; |
|
158 |
|
|
159 |
q = line; |
|
160 |
for(;;) { |
|
161 |
ch = http_getc(s); |
|
162 |
if (ch < 0) |
|
163 |
return AVERROR(EIO); |
|
164 |
if (ch == '\n') { |
|
165 |
/* process line */ |
|
166 |
if (q > line && q[-1] == '\r') |
|
167 |
q--; |
|
168 |
*q = '\0'; |
|
169 |
|
|
170 |
return 0; |
|
171 |
} else { |
|
172 |
if ((q - line) < line_size - 1) |
|
173 |
*q++ = ch; |
|
174 |
} |
|
175 |
} |
|
176 |
} |
|
177 |
|
|
154 | 178 |
static int process_line(URLContext *h, char *line, int line_count, |
155 | 179 |
int *new_location) |
156 | 180 |
{ |
... | ... | |
209 | 233 |
const char *auth, int *new_location) |
210 | 234 |
{ |
211 | 235 |
HTTPContext *s = h->priv_data; |
212 |
int post, err, ch;
|
|
213 |
char line[1024], *q;
|
|
236 |
int post, err; |
|
237 |
char line[1024]; |
|
214 | 238 |
char *auth_b64; |
215 | 239 |
int auth_b64_len = (strlen(auth) + 2) / 3 * 4 + 1; |
216 | 240 |
int64_t off = s->off; |
... | ... | |
251 | 275 |
} |
252 | 276 |
|
253 | 277 |
/* wait for header */ |
254 |
q = line; |
|
255 | 278 |
for(;;) { |
256 |
ch = http_getc(s); |
|
257 |
if (ch < 0) |
|
279 |
if (http_get_line(s, line, sizeof(line)) < 0) |
|
258 | 280 |
return AVERROR(EIO); |
259 |
if (ch == '\n') { |
|
260 |
/* process line */ |
|
261 |
if (q > line && q[-1] == '\r') |
|
262 |
q--; |
|
263 |
*q = '\0'; |
|
264 | 281 |
#ifdef DEBUG |
265 | 282 |
printf("header='%s'\n", line); |
266 | 283 |
#endif |
... | ... | |
270 | 287 |
if (err == 0) |
271 | 288 |
break; |
272 | 289 |
s->line_count++; |
273 |
q = line; |
|
274 |
} else { |
|
275 |
if ((q - line) < sizeof(line) - 1) |
|
276 |
*q++ = ch; |
|
277 |
} |
|
278 | 290 |
} |
279 | 291 |
|
280 | 292 |
return (off == s->off) ? 0 : -1; |
Also available in: Unified diff