Exemple #1
0
/*
 * Asynchronously create a new http connection for 'Url'
 * We'll set some socket parameters; the rest will be set later
 * when the IP is known.
 * ( Data1 = Web structure )
 * Return value: 0 on success, -1 otherwise
 */
static int Http_get(ChainLink *Info, void *Data1)
{
   SocketData_t *S;
   char *hostname;

   S = a_Klist_get_data(ValidSocks, VOIDP2INT(Info->LocalKey));
   /* Reference Web data */
   S->web = Data1;
   /* Reference Info data */
   S->Info = Info;

   /* Proxy support */
   if (Http_must_use_proxy(S->web->url)) {
      hostname = dStrdup(URL_HOST(HTTP_Proxy));
      S->port = URL_PORT(HTTP_Proxy);
      S->flags |= HTTP_SOCKET_USE_PROXY;
   } else {
      hostname = dStrdup(URL_HOST(S->web->url));
      S->port = URL_PORT(S->web->url);
      S->flags &= ~HTTP_SOCKET_USE_PROXY;
   }

   /* Let the user know what we'll do */
   MSG_BW(S->web, 1, "DNS resolving %s", URL_HOST_(S->web->url));

   /* Let the DNS engine resolve the hostname, and when done,
    * we'll try to connect the socket from the callback function */
   a_Dns_resolve(hostname, Http_dns_cb, Info->LocalKey);

   dFree(hostname);
   return 0;
}
Exemple #2
0
static ret_t
cherokee_url_parse_guts (cherokee_url_t    *url,
			 cherokee_buffer_t *url_buf,
			 cherokee_buffer_t *user_ret,
			 cherokee_buffer_t *password_ret)
{
	ret_t    ret;
	cuint_t  len = 0 ;
	char    *port;
	char    *slash;
	char    *server;
	char    *arroba;
	char    *tmp;

	/* Drop protocol, if exists..
	 */
	ret = parse_protocol (url, url_buf->buf, &len);
	if (unlikely(ret < ret_ok)) return ret_error;

	tmp = url_buf->buf + len;

	/* User (and password)
	 */
	arroba = strchr (tmp, '@');
	if (arroba != NULL) {
		char *sep;

		sep = strchr (tmp, ':');
		if (sep == NULL) {
			cherokee_buffer_clean (user_ret);
			cherokee_buffer_add (user_ret, tmp, arroba - tmp);
		} else {
			cherokee_buffer_clean (user_ret);
			cherokee_buffer_add (user_ret, tmp, sep - tmp);
			sep++;
			cherokee_buffer_clean (password_ret);
			cherokee_buffer_add (password_ret, sep, arroba - sep);
		}

		tmp = arroba + 1;
	}

	/* Split the host/request
	 */
	server = tmp;
	len    = strlen (server);
	slash  = strpbrk (server, "/\\");

	if (slash == NULL) {
		cherokee_buffer_add (&url->request, "/", 1);
		cherokee_buffer_add (&url->host, server, len);
	} else {
		cherokee_buffer_add (&url->request, slash, len-(slash-server));
		cherokee_buffer_add (&url->host, server, slash-server);
	}

	/* Drop up the port, if exists..
	 */
	port = strchr (url->host.buf, ':');
	if (port != NULL) {

		/* Read port number
		 */
		if (slash != NULL) *slash = '\0';
		URL_PORT(url) = atoi (port+1);
		if (slash != NULL) *slash =  '/';

		/* .. and remove it
		 */
		ret = cherokee_buffer_drop_ending (&url->host, strlen(port));
		if (unlikely(ret < ret_ok)) return ret;
	}

#if 0
	cherokee_url_print (url);
#endif

	return ret_ok;
}