7 static int strstrsplit (
const char *,
const char *,
char **,
char **);
8 static int strchrsplit (
const char *,
const char,
char **,
char **);
9 static int strrchrsplit (
const char *,
const char,
char **,
char **);
10 static int strpchrsplit (
const char *,
const char *,
const char,
char **,
char **);
19 char *tmp1, *tmp2, *tmp3, *tmp4;
22 char *username, *password;
33 if (strstrsplit (url,
"://", &protocol, &tmp1)) {
34 protocol = strdup (
"");
38 if (strchrsplit (tmp1,
'/', &tmp2, &path)) {
43 if (strchrsplit (tmp2,
'@', &tmp3, &tmp4)) {
48 if (strchrsplit (tmp3,
':', &username, &password)) {
49 username = strdup (tmp3);
50 password = strdup (
"");
57 end = strchr (tmp4 + 1,
']');
59 if (strpchrsplit (tmp4, end,
':', &host, &port)) {
64 memmove (host, host + 1, end - tmp4 - 1);
65 host[end - tmp4 - 1] =
'\0';
67 host = strdup (tmp4 + 1);
73 if (strrchrsplit (tmp4,
':', &host, &port)) {
114 static int strstrsplit (
const char *str,
const char *sep,
char **former_result,
char **latter_result)
117 char *former, *latter;
119 split = strstr (str, sep);
124 former = malloc (split - str + 1);
129 strncpy (former, str, split - str);
130 former[split - str] =
'\0';
132 latter = strdup (split + strlen (sep));
134 *former_result = former;
135 *latter_result = latter;
147 static int strchrsplit (
const char *str,
const char sep,
char **former_result,
char **latter_result)
150 char *former, *latter;
152 split = strchr (str, sep);
157 former = malloc (split - str + 1);
162 strncpy (former, str, split - str);
163 former[split - str] =
'\0';
165 latter = strdup (split + 1);
167 *former_result = former;
168 *latter_result = latter;
180 static int strrchrsplit (
const char *str,
const char sep,
char **former_result,
char **latter_result)
183 char *former, *latter;
185 split = strrchr (str, sep);
190 former = malloc (split - str + 1);
195 strncpy (former, str, split - str);
196 former[split - str] =
'\0';
198 latter = strdup (split + 1);
200 *former_result = former;
201 *latter_result = latter;
214 static int strpchrsplit (
const char *str,
const char *pos,
const char sep,
char **former_result,
char **latter_result)
217 char *former, *latter;
219 split = strchr (pos, sep);
224 former = malloc (split - str + 1);
229 strncpy (former, str, split - str);
230 former[split - str] =
'\0';
232 latter = strdup (split + 1);
234 *former_result = former;
235 *latter_result = latter;
void free_url(xmms_url_t *url)
xmms_url_t * parse_url(const char *url)
Split a URL into its respective parts.