int http_parse_url(http_dest_t *dest, const char *url) { char *d; const char *p, *q; const char *uri; int i; uri = url; if ((p = strstr(url, "://"))) { snprintf(dest->scheme, URL_SCHEME_LEN + 1, "%.*s", (int)(p - uri), uri); uri = p + 3; } else { p = uri; strcpy(dest->scheme, "http"); } if (!*uri || *uri == '/' || *uri == '.') goto nohost; p = strpbrk(uri, "/@"); if (p && *p == '@') { /* username */ for (q = uri, i = 0; (*q != ':') && (*q != '@'); q++) if (i < URL_USER_LEN) { dest->user[i++] = *q; } /* password */ if (*q == ':') for (q++, i = 0; (*q != ':') && (*q != '@'); q++) if (i < URL_PWD_LEN) { dest->password[i++] = *q; } p++; } else { p = uri; } memset(dest->host, 0, MAX_HOST_NAME_LEN+1); for (i = 0; *p && (*p != '/') && (*p != ':'); p++) { if (i < MAX_HOST_NAME_LEN){ dest->host[i++] = *p; } } /* port */ if(strncmp(url, "https:", 6) == 0) { dest->port = 443; } else { dest->port = 80; } if (*p == ':') { dest->port = 0; for (q = ++p; *q && (*q != '/'); q++) if (isdigit(*q)) { dest->port = dest->port * 10 + (*q - '0'); } else { /* invalid port */ return -1; } p = q; } nohost: if (!*p) p = "/"; if (strcasecmp(dest->scheme, "http") == 0 || strcasecmp(dest->scheme, "https") == 0) { const char hexnums[] = "0123456789abcdef"; d = dest->uri; while (*p != '