| 359 | } |
| 360 | |
| 361 | void av_url_split(char *proto, int proto_size, |
| 362 | char *authorization, int authorization_size, |
| 363 | char *hostname, int hostname_size, |
| 364 | int *port_ptr, char *path, int path_size, const char *url) |
| 365 | { |
| 366 | const char *p, *ls, *at, *at2, *col, *brk; |
| 367 | |
| 368 | if (port_ptr) |
| 369 | *port_ptr = -1; |
| 370 | if (proto_size > 0) |
| 371 | proto[0] = 0; |
| 372 | if (authorization_size > 0) |
| 373 | authorization[0] = 0; |
| 374 | if (hostname_size > 0) |
| 375 | hostname[0] = 0; |
| 376 | if (path_size > 0) |
| 377 | path[0] = 0; |
| 378 | |
| 379 | /* parse protocol */ |
| 380 | if ((p = strchr(url, ':'))) { |
| 381 | av_strlcpy(proto, url, FFMIN(proto_size, p + 1 - url)); |
| 382 | p++; /* skip ':' */ |
| 383 | if (*p == '/') |
| 384 | p++; |
| 385 | if (*p == '/') |
| 386 | p++; |
| 387 | } else { |
| 388 | /* no protocol means plain filename */ |
| 389 | av_strlcpy(path, url, path_size); |
| 390 | return; |
| 391 | } |
| 392 | |
| 393 | /* separate path from hostname */ |
| 394 | ls = p + strcspn(p, "/?#"); |
| 395 | av_strlcpy(path, ls, path_size); |
| 396 | |
| 397 | /* the rest is hostname, use that to parse auth/port */ |
| 398 | if (ls != p) { |
| 399 | /* authorization (user[:pass]@hostname) */ |
| 400 | at2 = p; |
| 401 | while ((at = strchr(p, '@')) && at < ls) { |
| 402 | av_strlcpy(authorization, at2, |
| 403 | FFMIN(authorization_size, at + 1 - at2)); |
| 404 | p = at + 1; /* skip '@' */ |
| 405 | } |
| 406 | |
| 407 | if (*p == '[' && (brk = strchr(p, ']')) && brk < ls) { |
| 408 | /* [host]:port */ |
| 409 | av_strlcpy(hostname, p + 1, |
| 410 | FFMIN(hostname_size, brk - p)); |
| 411 | if (brk[1] == ':' && port_ptr) |
| 412 | *port_ptr = atoi(brk + 2); |
| 413 | } else if ((col = strchr(p, ':')) && col < ls) { |
| 414 | av_strlcpy(hostname, p, |
| 415 | FFMIN(col + 1 - p, hostname_size)); |
| 416 | if (port_ptr) |
| 417 | *port_ptr = atoi(col + 1); |
| 418 | } else |