File: 873964-http

package info (click to toggle)
streamripper 1.64.6-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,904 kB
  • sloc: ansic: 11,699; sh: 8,548; makefile: 421; perl: 34
file content (133 lines) | stat: -rw-r--r-- 4,934 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
Description: Fix parse_error if there is a colon in the uri
 streamripper fails to correctly parse uris with colon in the
 name (such as the target stream name)
 .
Author: Alexander Mueller <XelaRellum@web.de>
Bug-Debian: https://bugs.debian.org/873964

---
Author: Alexander Mueller <XelaRellum@web.de>
Origin: https://github.com/XelaRellum/streamripper/commit/5856bd11fdf12e79890db4e59ed58643382adec3
Bug-Debian: https://bugs.debian.org/873964
Forwarded: (no)
Last-Update: 2024-07-27

index b6c5ddd..627d2eb 100644
--- a/lib/http.c
+++ b/lib/http.c
@@ -36,8 +36,6 @@ http_get_m3u (RIP_MANAGER_INFO* rmi, HSOCKET *sock, SR_HTTP_HEADER *info);
 static error_code
 http_get_sc_header(RIP_MANAGER_INFO* rmi, const char* url, 
 		   HSOCKET *sock, SR_HTTP_HEADER *info);
-static error_code
-http_parse_url(const char *url, URLINFO *urlinfo);
 
 /******************************************************************************
  * Private Vars
@@ -142,53 +140,65 @@ unescape_pct_encoding (char* s)
  * Parse's a url as in http://host:port/path or host/path, etc..
  * and now http://username:password@server:4480
  */
-static error_code
+error_code
 http_parse_url(const char *url, URLINFO *urlinfo)
 { 
     int ret;
     char *s;
-
+    const char *start_path;
+    const char *start_login;
+    const char *start_port;
 
     debug_printf ("http_parse_url: %s\n", url);
 
-    /* if we have a proto, just skip it. should we care about 
+    /* if we have a proto, just skip it. should we care about
        the proto? like fail if it's not http? */
     s = strstr(url, "://");
     if (s) url = s + strlen("://");
     memcpy(urlinfo->path, (void *)"/\0", 2);
 
+    /* the path may contain ':' as well, so
+       check it there is a path */
+    start_path = strchr(url, '/');
+    if (NULL == start_path) {
+        /* no path found, just assume the end of the string */
+        start_path = url + strlen(url);
+    }
+
     /* search for a login '@' token */
-    if (strchr(url, '@') != NULL) {
-	ret = sscanf(url, "%1023[^:]:%1023[^@]", 
-		     urlinfo->username, urlinfo->password);
-	if (ret < 1) {
-	    return SR_ERROR_PARSE_FAILURE;
-	} else if (ret == 1) {
-	    urlinfo->password[0] = '\0';
-	}
-	url = strchr(url, '@') + 1;
-	debug_printf ("Username (escaped): %s\n", urlinfo->username);
-	debug_printf ("Password (escaped): %s\n", urlinfo->password);
-	unescape_pct_encoding (urlinfo->username);
-	unescape_pct_encoding (urlinfo->password);
-	debug_printf ("Username (unescaped): %s\n", urlinfo->username);
-	debug_printf ("Password (unescaped): %s\n", urlinfo->password);
+    start_login = strchr(url, '@');
+    if ((start_login != NULL) && (start_login < start_path)) {
+        ret = sscanf(url, "%1023[^:]:%1023[^@]",
+                     urlinfo->username, urlinfo->password);
+        if (ret < 1) {
+            return SR_ERROR_PARSE_FAILURE;
+        } else if (ret == 1) {
+            urlinfo->password[0] = '\0';
+        }
+        url = start_login + 1;
+        debug_printf ("Username (escaped): %s\n", urlinfo->username);
+        debug_printf ("Password (escaped): %s\n", urlinfo->password);
+        unescape_pct_encoding (urlinfo->username);
+        unescape_pct_encoding (urlinfo->password);
+        debug_printf ("Username (unescaped): %s\n", urlinfo->username);
+        debug_printf ("Password (unescaped): %s\n", urlinfo->password);
     } else {
-	urlinfo->username[0] = '\0';
-	urlinfo->password[0] = '\0';
+        urlinfo->username[0] = '\0';
+        urlinfo->password[0] = '\0';
     }
 
     /* search for a port seperator */
-    if (strchr(url, ':') != NULL) {
-	debug_printf ("Branch 1 (%s)\n", url);
-	ret = sscanf(url, "%511[^:]:%hu/%252s", urlinfo->host, 
-		     (short unsigned int*)&urlinfo->port, urlinfo->path+1);
-	if (urlinfo->port < 1) return SR_ERROR_PARSE_FAILURE;
-	ret -= 1;
+    start_port = strchr(url, ':');
+    if ((start_port != NULL) && (start_port < start_path)) {
+        debug_printf ("Branch 1 (%s)\n", url);
+        ret = sscanf(url, "%511[^:]:%hu/%252s", urlinfo->host,
+                     (short unsigned int*)&urlinfo->port, urlinfo->path+1);
+        if (urlinfo->port < 1) return SR_ERROR_PARSE_FAILURE;
+        ret -= 1;
     } else {
-	debug_printf ("Branch 2 (%s)\n", url);
-	urlinfo->port = 80;
-	ret = sscanf(url, "%511[^/]/%252s", urlinfo->host, urlinfo->path+1);
+        debug_printf ("Branch 2 (%s)\n", url);
+        urlinfo->port = 80;
+        ret = sscanf(url, "%511[^/]/%252s", urlinfo->host, urlinfo->path+1);
     }
     if (ret < 1) return SR_ERROR_INVALID_URL;
 
diff --git a/lib/http.h b/lib/http.h
index b1771fb..1ac8807 100644
--- a/lib/http.h
+++ b/lib/http.h
@@ -17,6 +17,7 @@ error_code http_sc_connect (RIP_MANAGER_INFO* rmi,
 			    const char *proxyurl, 
 			    SR_HTTP_HEADER *info, char *useragent, 
 			    char *if_name);
+error_code http_parse_url(const char *url, URLINFO *urlinfo);
 
 
 #endif //__HTTP_H__