src/standard.c
int url2sa(const char *url, int ulen, struct sockaddr_storage *addr)
{
	const char *curr = url, *cp = url;
	int ret, url_code = 0;
	unsigned int http_code = 0;

	/* Cleanup the room */

	/* FIXME: assume IPv4 only for now */
	((struct sockaddr_in *)addr)->sin_family = AF_INET;
	((struct sockaddr_in *)addr)->sin_addr.s_addr = 0;
	((struct sockaddr_in *)addr)->sin_port = 0;

	/* Firstly, try to find :// pattern */
	while (curr < url+ulen && url_code != 0x3a2f2f) {
		url_code = ((url_code & 0xffff) << 8);
		url_code += (unsigned char)*curr++;
	}

	/* Secondly, if :// pattern is found, verify parsed stuff
	 * before pattern is matching our http pattern.
	 * If so parse ip address and port in uri.
	 * 
	 * WARNING: Current code doesn't support dynamic async dns resolver.
	 */
	if (url_code == 0x3a2f2f) {
		while (cp < curr - 3)
			http_code = (http_code << 8) + *cp++;
		http_code |= 0x20202020;			/* Turn everything to lower case */
		
		/* HTTP url matching */
		if (http_code == 0x68747470) {
			/* We are looking for IP address. If you want to parse and
			 * resolve hostname found in url, you can use str2sa_range(), but
			 * be warned this can slow down global daemon performances
			 * while handling lagging dns responses.
			 */
			ret = url2ipv4(curr, &((struct sockaddr_in *)addr)->sin_addr);
			if (!ret)
				return -1;
			curr += ret;
			((struct sockaddr_in *)addr)->sin_port = (*curr == ':') ? str2uic(++curr) : 80;
			((struct sockaddr_in *)addr)->sin_port = htons(((struct sockaddr_in *)addr)->sin_port);
		}
		return 0;
	}

	return -1;
}
/*
 * Resolve destination server from URL. Convert <str> to a sockaddr_storage*.
 */
Resolve destination server from URL. Convert  to a sockaddr_storage*.
Resolve destination server from URL . Convert to a sockaddr_storage * .
int url2sa(const char *url, int ulen, struct sockaddr_storage *addr)
{
	const char *curr = url, *cp = url;
	int ret, url_code = 0;
	unsigned int http_code = 0;
	((struct sockaddr_in *)addr)->sin_family = AF_INET;
	((struct sockaddr_in *)addr)->sin_addr.s_addr = 0;
	((struct sockaddr_in *)addr)->sin_port = 0;
	while (curr < url+ulen && url_code != 0x3a2f2f) {
		url_code = ((url_code & 0xffff) << 8);
		url_code += (unsigned char)*curr++;
	}
	if (url_code == 0x3a2f2f) {
		while (cp < curr - 3)
			http_code = (http_code << 8) + *cp++;
		http_code |= 0x20202020;			
		if (http_code == 0x68747470) {
			ret = url2ipv4(curr, &((struct sockaddr_in *)addr)->sin_addr);
			if (!ret)
				return -1;
			curr += ret;
			((struct sockaddr_in *)addr)->sin_port = (*curr == ':') ? str2uic(++curr) : 80;
			((struct sockaddr_in *)addr)->sin_port = htons(((struct sockaddr_in *)addr)->sin_port);
		}
		return 0;
	}
	return -1;
}
int url2sa ( const char * url , int ulen , struct sockaddr_storage * addr ) { const char * curr = url , * cp = url ; int ret , url_code = 0 ; unsigned int http_code = 0 ; ( ( struct sockaddr_in * ) addr ) -> sin_family = AF_INET ; ( ( struct sockaddr_in * ) addr ) -> sin_addr . s_addr = 0 ; ( ( struct sockaddr_in * ) addr ) -> sin_port = 0 ; while ( curr < url + ulen && url_code != 0x3a2f2f ) { url_code = ( ( url_code & 0xffff ) << 8 ) ; url_code += ( unsigned char ) * curr ++ ; } if ( url_code == 0x3a2f2f ) { while ( cp < curr - 3 ) http_code = ( http_code << 8 ) + * cp ++ ; http_code |= 0x20202020 ; if ( http_code == 0x68747470 ) { ret = url2ipv4 ( curr , & ( ( struct sockaddr_in * ) addr ) -> sin_addr ) ; if ( ! ret ) return -1 ; curr += ret ; ( ( struct sockaddr_in * ) addr ) -> sin_port = ( * curr == ' ' ) ? str2uic ( ++ curr ) : 80 ; ( ( struct sockaddr_in * ) addr ) -> sin_port = htons ( ( ( struct sockaddr_in * ) addr ) -> sin_port ) ; } return 0 ; } return -1 ; }
Resolve destination server from URL.
Resolve destination server from URL .
/* Cleanup the room */ /* FIXME: assume IPv4 only for now */ /* Firstly, try to find :// pattern */ /* Secondly, if :// pattern is found, verify parsed stuff
	 * before pattern is matching our http pattern.
	 * If so parse ip address and port in uri.
	 * 
	 * WARNING: Current code doesn't support dynamic async dns resolver.
	 */ /* Turn everything to lower case */ /* HTTP url matching */ /* We are looking for IP address. If you want to parse and
			 * resolve hostname found in url, you can use str2sa_range(), but
			 * be warned this can slow down global daemon performances
			 * while handling lagging dns responses.
			 */