Mercurial > libavformat.hg
comparison http.c @ 5007:1d5f8836c8a8 libavformat
Introduce http_get_line and modify http_connect to use http_get_line.
Patch by Peter Holik <$firstname @ $lastname . at>
| author | jai_menon |
|---|---|
| date | Sat, 06 Jun 2009 16:44:21 +0000 |
| parents | b34d9614b887 |
| children | 370160e040d9 |
comparison
equal
deleted
inserted
replaced
| 5006:686de8748c36 | 5007:1d5f8836c8a8 |
|---|---|
| 147 s->buf_ptr = s->buffer; | 147 s->buf_ptr = s->buffer; |
| 148 s->buf_end = s->buffer + len; | 148 s->buf_end = s->buffer + len; |
| 149 } | 149 } |
| 150 } | 150 } |
| 151 return *s->buf_ptr++; | 151 return *s->buf_ptr++; |
| 152 } | |
| 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 } | |
| 152 } | 176 } |
| 153 | 177 |
| 154 static int process_line(URLContext *h, char *line, int line_count, | 178 static int process_line(URLContext *h, char *line, int line_count, |
| 155 int *new_location) | 179 int *new_location) |
| 156 { | 180 { |
| 207 | 231 |
| 208 static int http_connect(URLContext *h, const char *path, const char *hoststr, | 232 static int http_connect(URLContext *h, const char *path, const char *hoststr, |
| 209 const char *auth, int *new_location) | 233 const char *auth, int *new_location) |
| 210 { | 234 { |
| 211 HTTPContext *s = h->priv_data; | 235 HTTPContext *s = h->priv_data; |
| 212 int post, err, ch; | 236 int post, err; |
| 213 char line[1024], *q; | 237 char line[1024]; |
| 214 char *auth_b64; | 238 char *auth_b64; |
| 215 int auth_b64_len = (strlen(auth) + 2) / 3 * 4 + 1; | 239 int auth_b64_len = (strlen(auth) + 2) / 3 * 4 + 1; |
| 216 int64_t off = s->off; | 240 int64_t off = s->off; |
| 217 | 241 |
| 218 | 242 |
| 249 if (post) { | 273 if (post) { |
| 250 return 0; | 274 return 0; |
| 251 } | 275 } |
| 252 | 276 |
| 253 /* wait for header */ | 277 /* wait for header */ |
| 254 q = line; | |
| 255 for(;;) { | 278 for(;;) { |
| 256 ch = http_getc(s); | 279 if (http_get_line(s, line, sizeof(line)) < 0) |
| 257 if (ch < 0) | |
| 258 return AVERROR(EIO); | 280 return AVERROR(EIO); |
| 259 if (ch == '\n') { | |
| 260 /* process line */ | |
| 261 if (q > line && q[-1] == '\r') | |
| 262 q--; | |
| 263 *q = '\0'; | |
| 264 #ifdef DEBUG | 281 #ifdef DEBUG |
| 265 printf("header='%s'\n", line); | 282 printf("header='%s'\n", line); |
| 266 #endif | 283 #endif |
| 267 err = process_line(h, line, s->line_count, new_location); | 284 err = process_line(h, line, s->line_count, new_location); |
| 268 if (err < 0) | 285 if (err < 0) |
| 269 return err; | 286 return err; |
| 270 if (err == 0) | 287 if (err == 0) |
| 271 break; | 288 break; |
| 272 s->line_count++; | 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 return (off == s->off) ? 0 : -1; | 292 return (off == s->off) ? 0 : -1; |
| 281 } | 293 } |
| 282 | 294 |
