forked from FFmpeg/FFmpeg
refactor url_split(), preparing for IPv6 support
patch by: Ronald S. Bultje rsbultje a gmail d com thread: "[PATCH] url_split() ipv6 support" at 09/23/07 18:43 Originally committed as revision 10605 to svn://svn.ffmpeg.org/ffmpeg/trunk
This commit is contained in:
parent
9c5755ee73
commit
7e1e297ee3
1 changed files with 39 additions and 58 deletions
|
@ -2878,68 +2878,49 @@ void url_split(char *proto, int proto_size,
|
||||||
char *path, int path_size,
|
char *path, int path_size,
|
||||||
const char *url)
|
const char *url)
|
||||||
{
|
{
|
||||||
const char *p;
|
const char *p, *ls, *at, *col;
|
||||||
char *q;
|
|
||||||
int port;
|
|
||||||
|
|
||||||
port = -1;
|
if (port_ptr) *port_ptr = -1;
|
||||||
|
if (proto_size > 0) proto[0] = 0;
|
||||||
|
if (authorization_size > 0) authorization[0] = 0;
|
||||||
|
if (hostname_size > 0) hostname[0] = 0;
|
||||||
|
if (path_size > 0) path[0] = 0;
|
||||||
|
|
||||||
p = url;
|
/* parse protocol */
|
||||||
q = proto;
|
if ((p = strchr(url, ':'))) {
|
||||||
while (*p != ':' && *p != '\0') {
|
av_strlcpy(proto, url, FFMIN(proto_size, p + 1 - url));
|
||||||
if ((q - proto) < proto_size - 1)
|
p++; /* skip ':' */
|
||||||
*q++ = *p;
|
if (*p == '/') p++;
|
||||||
p++;
|
if (*p == '/') p++;
|
||||||
}
|
|
||||||
if (proto_size > 0)
|
|
||||||
*q = '\0';
|
|
||||||
if (authorization_size > 0)
|
|
||||||
authorization[0] = '\0';
|
|
||||||
if (*p == '\0') {
|
|
||||||
if (proto_size > 0)
|
|
||||||
proto[0] = '\0';
|
|
||||||
if (hostname_size > 0)
|
|
||||||
hostname[0] = '\0';
|
|
||||||
p = url;
|
|
||||||
} else {
|
} else {
|
||||||
char *at,*slash; // PETR: position of '@' character and '/' character
|
/* no protocol means plain filename */
|
||||||
|
av_strlcpy(path, url, path_size);
|
||||||
p++;
|
return;
|
||||||
if (*p == '/')
|
}
|
||||||
p++;
|
|
||||||
if (*p == '/')
|
/* separate path from hostname */
|
||||||
p++;
|
if ((ls = strchr(p, '/')))
|
||||||
at = strchr(p,'@'); // PETR: get the position of '@'
|
av_strlcpy(path, ls, path_size);
|
||||||
slash = strchr(p,'/'); // PETR: get position of '/' - end of hostname
|
else
|
||||||
if (at && slash && at > slash) at = NULL; // PETR: not interested in '@' behind '/'
|
ls = &p[strlen(p)]; // XXX
|
||||||
|
|
||||||
q = at ? authorization : hostname; // PETR: if '@' exists starting with auth.
|
/* the rest is hostname, use that to parse auth/port */
|
||||||
|
if (ls != p) {
|
||||||
while ((at || *p != ':') && *p != '/' && *p != '?' && *p != '\0') { // PETR:
|
/* authorization (user[:pass]@hostname) */
|
||||||
if (*p == '@') { // PETR: passed '@'
|
if ((at = strchr(p, '@')) && at < ls) {
|
||||||
if (authorization_size > 0)
|
av_strlcpy(authorization, p,
|
||||||
*q = '\0';
|
FFMIN(authorization_size, at + 1 - p));
|
||||||
q = hostname;
|
p = at + 1; /* skip '@' */
|
||||||
at = NULL;
|
}
|
||||||
} else if (!at) { // PETR: hostname
|
|
||||||
if ((q - hostname) < hostname_size - 1)
|
/* port */
|
||||||
*q++ = *p;
|
if ((col = strchr(p, ':')) && col < ls) {
|
||||||
} else {
|
ls = col;
|
||||||
if ((q - authorization) < authorization_size - 1)
|
if (port_ptr) *port_ptr = atoi(col + 1); /* skip ':' */
|
||||||
*q++ = *p;
|
}
|
||||||
}
|
|
||||||
p++;
|
av_strlcpy(hostname, p, FFMIN(1 + ls - p, hostname_size));
|
||||||
}
|
|
||||||
if (hostname_size > 0)
|
|
||||||
*q = '\0';
|
|
||||||
if (*p == ':') {
|
|
||||||
p++;
|
|
||||||
port = strtoul(p, (char **)&p, 10);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (port_ptr)
|
|
||||||
*port_ptr = port;
|
|
||||||
av_strlcpy(path, p, path_size);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void av_set_pts_info(AVStream *s, int pts_wrap_bits,
|
void av_set_pts_info(AVStream *s, int pts_wrap_bits,
|
||||||
|
|
Loading…
Add table
Reference in a new issue