| 1170 | } |
| 1171 | |
| 1172 | static int process_line(URLContext *h, char *line, int line_count, int *parsed_http_code) |
| 1173 | { |
| 1174 | HTTPContext *s = h->priv_data; |
| 1175 | const char *auto_method = h->flags & AVIO_FLAG_READ ? "POST" : "GET"; |
| 1176 | char *tag, *p, *end, *method, *resource, *version; |
| 1177 | int ret; |
| 1178 | |
| 1179 | /* end of header */ |
| 1180 | if (line[0] == '\0') { |
| 1181 | s->end_header = 1; |
| 1182 | return 0; |
| 1183 | } |
| 1184 | |
| 1185 | p = line; |
| 1186 | if (line_count == 0) { |
| 1187 | if (s->is_connected_server) { |
| 1188 | // HTTP method |
| 1189 | method = p; |
| 1190 | while (*p && !av_isspace(*p)) |
| 1191 | p++; |
| 1192 | if (!av_isspace(*p)) |
| 1193 | return ff_http_averror(400, AVERROR(EIO)); |
| 1194 | *(p++) = '\0'; |
| 1195 | av_log(h, AV_LOG_TRACE, "Received method: %s\n", method); |
| 1196 | if (s->method) { |
| 1197 | if (av_strcasecmp(s->method, method)) { |
| 1198 | av_log(h, AV_LOG_ERROR, "Received and expected HTTP method do not match. (%s expected, %s received)\n", |
| 1199 | s->method, method); |
| 1200 | return ff_http_averror(400, AVERROR(EIO)); |
| 1201 | } |
| 1202 | } else { |
| 1203 | // use autodetected HTTP method to expect |
| 1204 | av_log(h, AV_LOG_TRACE, "Autodetected %s HTTP method\n", auto_method); |
| 1205 | if (av_strcasecmp(auto_method, method)) { |
| 1206 | av_log(h, AV_LOG_ERROR, "Received and autodetected HTTP method did not match " |
| 1207 | "(%s autodetected %s received)\n", auto_method, method); |
| 1208 | return ff_http_averror(400, AVERROR(EIO)); |
| 1209 | } |
| 1210 | if (!(s->method = av_strdup(method))) |
| 1211 | return AVERROR(ENOMEM); |
| 1212 | } |
| 1213 | |
| 1214 | // HTTP resource |
| 1215 | while (av_isspace(*p)) |
| 1216 | p++; |
| 1217 | resource = p; |
| 1218 | while (*p && !av_isspace(*p)) |
| 1219 | p++; |
| 1220 | if (!av_isspace(*p)) |
| 1221 | return ff_http_averror(400, AVERROR(EIO)); |
| 1222 | *(p++) = '\0'; |
| 1223 | av_log(h, AV_LOG_TRACE, "Requested resource: %s\n", resource); |
| 1224 | if (!(s->resource = av_strdup(resource))) |
| 1225 | return AVERROR(ENOMEM); |
| 1226 | |
| 1227 | // HTTP version |
| 1228 | while (av_isspace(*p)) |
| 1229 | p++; |
no test coverage detected