diff options
Diffstat (limited to 'src/input/http_helper.c')
-rw-r--r-- | src/input/http_helper.c | 41 |
1 files changed, 27 insertions, 14 deletions
diff --git a/src/input/http_helper.c b/src/input/http_helper.c index 4883763b0..eb28140ff 100644 --- a/src/input/http_helper.c +++ b/src/input/http_helper.c @@ -29,8 +29,18 @@ #include "xine_internal.h" #include "http_helper.h" + +const char *_x_url_user_agent (const char *url) +{ + if (!strncasecmp (url, "qthttp://", 9)) + return "QuickTime"; /* needed for Apple trailers */ + return NULL; +} + int _x_parse_url (char *url, char **proto, char** host, int *port, - char **user, char **password, char **uri) { + char **user, char **password, char **uri, + const char **user_agent) +{ char *start = NULL; char *authcolon = NULL; char *at = NULL; @@ -55,14 +65,17 @@ int _x_parse_url (char *url, char **proto, char** host, int *port, *password = NULL; *uri = NULL; - /* proto */ + /* proto */ start = strstr(url, "://"); if (!start || (start == url)) goto error; - + end = start + strlen(start) - 1; *proto = strndup(url, start - url); + if (user_agent) + *user_agent = _x_url_user_agent (url); + /* user:password */ start += 3; at = strchr(start, '@'); @@ -72,10 +85,10 @@ int _x_parse_url (char *url, char **proto, char** host, int *port, semicolon = strchr(start, ';'); if (semicolon && (!slash || (semicolon < slash))) slash = semicolon; - + if (at && slash && (at > slash)) at = NULL; - + if (at) { authcolon = strchr(start, ':'); if(authcolon && authcolon < at) { @@ -166,7 +179,7 @@ int _x_parse_url (char *url, char **proto, char** host, int *port, escapechars++; it++; } - + if ( escapechars == 0 ) *uri = strdup(start); else { @@ -185,14 +198,15 @@ int _x_parse_url (char *url, char **proto, char** host, int *port, } else *it = start[i]; } + *it = '\0'; } } } else { *uri = strdup("/"); } - + return 1; - + error: if (*proto) { free (*proto); @@ -217,7 +231,7 @@ error: free (*uri); *uri = NULL; } - return 0; + return 0; } char *_x_canonicalise_url (const char *base, const char *url) { @@ -240,8 +254,7 @@ char *_x_canonicalise_url (const char *base, const char *url) { ++cut; } base_length = cut ? (size_t)(cut - base) : strlen (base); - ret = malloc (base_length + strlen (url) + 1); - sprintf (ret, "%.*s%s", (int)base_length, base, url); + asprintf (&ret, "%.*s%s", (int)base_length, base, url); return ret; } @@ -254,11 +267,11 @@ static int check_url(char *url, int ok) { char *proto, *host, *user, *password, *uri; int port; int res; - + printf("--------------------------------\n"); printf("url=%s\n", url); res = _x_parse_url (url, - &proto, &host, &port, &user, &password, &uri); + &proto, &host, &port, &user, &password, &uri, NULL); if (res) { printf("proto=%s, host=%s, port=%d, user=%s, password=%s, uri=%s\n", proto, host, port, user, password, uri); @@ -297,7 +310,7 @@ static int check_paste(const char *base, const char *url, const char *ok) { int main(int argc, char** argv) { char *proto, host, port, user, password, uri; int res = 0; - + res += check_url("http://www.toto.com/test1.asx", 1); res += check_url("http://www.toto.com:8080/test2.asx", 1); res += check_url("http://titi:pass@www.toto.com:8080/test3.asx", 1); |