コード例 #1
0
ファイル: ghttp.c プロジェクト: program-fans/shiyan
void
ghttp_request_destroy(ghttp_request *a_request)
{
  if (!a_request)
    return;
  /* make sure that the socket was shut down. */
  if (a_request->conn->sock >= 0)
    {
      close(a_request->conn->sock);
      a_request->conn->sock = -1;
    }
  /* destroy everything else */
  if (a_request->uri)
    http_uri_destroy(a_request->uri);
  if (a_request->proxy)
    http_uri_destroy(a_request->proxy);
  if (a_request->req)
    http_req_destroy(a_request->req);
  if (a_request->resp)
    http_resp_destroy(a_request->resp);
  if (a_request->conn)
    http_trans_conn_destroy(a_request->conn);
  /* destroy username info. */
  if (a_request->username)
    {
      free(a_request->username);
      a_request->username = NULL;
    }
  if (a_request->password)
    {
      free(a_request->password);
      a_request->password = NULL;
    }
  if (a_request->authtoken)
    {
      free(a_request->authtoken);
      a_request->authtoken = NULL;
    }
  /* destroy proxy authentication */
  if (a_request->proxy_username)
    {
      free(a_request->proxy_username);
      a_request->proxy_username = NULL;
    }
  if (a_request->proxy_password)
    {
      free(a_request->proxy_password);
      a_request->proxy_password = NULL;
    }
  if (a_request->proxy_authtoken)
    {
      free(a_request->proxy_authtoken);
      a_request->proxy_authtoken = NULL;
    }
  if (a_request)
    free(a_request);
  return;
}
コード例 #2
0
ファイル: ghttp.c プロジェクト: program-fans/shiyan
int ghttp_set_uri(ghttp_request *a_request, char *a_uri)
{
	int l_rv = 0;
	http_uri *l_new_uri = NULL;

	if ((!a_request) || (!a_uri))
		return -1;
	/* set the uri */
	l_new_uri = http_uri_new();
	l_rv = http_uri_parse(a_uri, l_new_uri);
	if (l_rv < 0)
	{
		http_uri_destroy(l_new_uri);
		return -1;
	}
	if (a_request->uri)
	{
		/* check to see if this has been set yet. */
		if (a_request->uri->host &&
			a_request->uri->port &&
			a_request->uri->resource)
		{
			/* check to see if we just need to change the resource */
			if ((!strcmp(a_request->uri->host, l_new_uri->host)) &&
				(a_request->uri->port == l_new_uri->port))
			{
				free(a_request->uri->resource);
				/* make a copy since we're about to destroy it */
				a_request->uri->resource = strdup(l_new_uri->resource);
				http_uri_destroy(l_new_uri);
			}
			else
			{
				goto REPLACE_URI;
			}
		}
		else
		{
			goto REPLACE_URI;
		}
	}
	else
		a_request->uri = l_new_uri;
	
	return 0;
	
REPLACE_URI:
	http_uri_destroy(a_request->uri);
	a_request->uri = l_new_uri;
	return 0;
}
コード例 #3
0
ファイル: ghttp.c プロジェクト: violetmoonmm/anelife
void
ghttp_request_destroy(ghttp_request *a_request)
{
  if (!a_request)
    return;
  /* make sure that the socket was shut down. */
#ifdef WIN32 //windows
  if (a_request->conn->sock != INVALID_SOCKET)
    {
		closesocket(a_request->conn->sock);
      a_request->conn->sock = INVALID_SOCKET;
#else //linux
  if (a_request->conn->sock >= 0)
    {
      close(a_request->conn->sock);
      a_request->conn->sock = -1;
#endif
    }
  /* destroy everything else */
  if (a_request->uri)
    http_uri_destroy(a_request->uri);
  if (a_request->proxy)
    http_uri_destroy(a_request->proxy);
  if (a_request->req)
    http_req_destroy(a_request->req);
  if (a_request->resp)
    http_resp_destroy(a_request->resp);
  if (a_request->conn)
    http_trans_conn_destroy(a_request->conn);
  /* destroy username info. */
  if (a_request->username)
    {
      free(a_request->username);
      a_request->username = NULL;
    }
  if (a_request->password)
    {
      free(a_request->password);
      a_request->password = NULL;
    }
  if (a_request->authtoken)
    {
      free(a_request->authtoken);
      a_request->authtoken = NULL;
    }
  /* destroy proxy authentication */
  if (a_request->proxy_username)
    {
      free(a_request->proxy_username);
      a_request->proxy_username = NULL;
    }
  if (a_request->proxy_password)
    {
      free(a_request->proxy_password);
      a_request->proxy_password = NULL;
    }
  if (a_request->proxy_authtoken)
    {
      free(a_request->proxy_authtoken);
      a_request->proxy_authtoken = NULL;
    }
  if (a_request)
    free(a_request);
  return;
}

int
ghttp_uri_validate(char *a_uri)
{
  if (!a_uri)
    return -1;
  /* you can do this... */
  return(http_uri_parse(a_uri, NULL));
}

int
ghttp_set_uri(ghttp_request *a_request, char *a_uri)
{
  int l_rv = 0;
  http_uri *l_new_uri = NULL;

  if ((!a_request) || (!a_uri))
    return -1;
  /* set the uri */
  l_new_uri = http_uri_new();
  l_rv = http_uri_parse(a_uri, l_new_uri);
  if (l_rv < 0)
	{
		http_uri_destroy(l_new_uri);
		return -1;
	}
  if (a_request->uri)
	{
      /* check to see if this has been set yet. */
		if (a_request->uri->host &&
				a_request->uri->port &&
				a_request->uri->resource)
		{
			/* check to see if we just need to change the resource */
			if ((!strcmp(a_request->uri->host, l_new_uri->host)) &&
					(a_request->uri->port == l_new_uri->port))
			{
	      free(a_request->uri->resource);
	      /* make a copy since we're about to destroy it */
	      a_request->uri->resource = strdup(l_new_uri->resource);
	      http_uri_destroy(l_new_uri);
	    }
			else
	    {
	      http_uri_destroy(a_request->uri);
	      a_request->uri = l_new_uri;
	    }
		}
		else
		{
			http_uri_destroy(a_request->uri);
			a_request->uri = l_new_uri;
		}
	}
  return 0;
}