+ char *p;
+ int not_host;
+
+ if (port_ptr && strncasecmp(URL_PREFIX, s, strlen(URL_PREFIX)) == 0) {
+ char *path;
+ int hostlen;
+ s += strlen(URL_PREFIX);
+ if ((p = strchr(s, '/')) != NULL) {
+ hostlen = p - s;
+ path = p + 1;
+ } else {
+ hostlen = strlen(s);
+ path = "";
+ }
+ if (*s == '[' && (p = strchr(s, ']')) != NULL) {
+ s++;
+ hostlen = p - s;
+ if (*p == ':')
+ *port_ptr = atoi(p+1);
+ else if (!*port_ptr)
+ *port_ptr = RSYNC_PORT;
+ } else {
+ if ((p = strchr(s, ':')) != NULL) {
+ hostlen = p - s;
+ *port_ptr = atoi(p+1);
+ } else if (!*port_ptr)
+ *port_ptr = RSYNC_PORT;
+ }
+ *host_ptr = new_array(char, hostlen + 1);
+ strlcpy(*host_ptr, s, hostlen + 1);
+ return path;
+ }
+
+ if (*s == '[' && (p = strchr(s, ']')) != NULL && p[1] == ':') {
+ s++;
+ *p = '\0';
+ not_host = strchr(s, '/') || !strchr(s, ':');
+ *p = ']';
+ if (not_host)
+ return NULL;
+ } else {
+ if (!(p = strchr(s, ':')))
+ return NULL;
+ *p = '\0';
+ not_host = strchr(s, '/') != NULL;
+ *p = ':';
+ if (not_host)
+ return NULL;
+ }