Example #1
0
ghttp_status
ghttp_recv(ghttp_request *a_request)
{
  int l_rv = 0;

  if (a_request->proc == ghttp_proc_none)
  {
    l_rv = http_resp_read_headers(a_request->resp, a_request->conn);
    if (l_rv == HTTP_TRANS_ERR)
			return ghttp_error;
    if (l_rv == HTTP_TRANS_NOT_DONE)
			return ghttp_not_done;
    if (l_rv == HTTP_TRANS_DONE)
		{
			a_request->proc = ghttp_proc_response;
			return ghttp_not_done;
		}
  }
  if (a_request->proc == ghttp_proc_response)
  {
    l_rv = http_resp_read_body(a_request->resp,
				 a_request->req,
				 a_request->conn);
    if (l_rv == HTTP_TRANS_ERR)
		{
	  /* make sure that the connected flag is fixed and stuff */
#ifdef WIN32 //windows
			if (a_request->conn->sock == INVALID_SOCKET)
#else //linux
			if (a_request->conn->sock == -1)
#endif
				a_request->connected = 0;
			return ghttp_error;
		}
    if (l_rv == HTTP_TRANS_NOT_DONE)
			return ghttp_not_done;
    if (l_rv == HTTP_TRANS_DONE)
		{
	/* make sure that the connected flag is fixed and stuff */
#ifdef WIN32 //windows
			if (a_request->conn->sock == INVALID_SOCKET)
#else //linux
			if (a_request->conn->sock == -1)
#endif
				a_request->connected = 0;
			a_request->proc = ghttp_proc_none;
			return ghttp_done;
		}
  }
  return ghttp_error;
}
Example #2
0
ghttp_status ghttp_process(ghttp_request *a_request)
{
	int l_rv = 0;

	ghttpDebug("=======proc: %d \n", a_request->proc);
	if(a_request->proc == ghttp_proc_done)
		return ghttp_done;
	if (a_request->proc == ghttp_proc_none)
		a_request->proc = ghttp_proc_request;
	if (a_request->proc == ghttp_proc_request)
	{
		if (a_request->connected == 0)
		{
			ghttpDebug("connect ... \n");
			if (http_trans_connect(a_request->conn) < 0)
			{
				if (a_request->conn->error_type == http_trans_err_type_errno)
					a_request->errstr = strerror(a_request->conn->error);
				else if(a_request->conn->error_type == http_trans_err_type_host)
					a_request->errstr = http_trans_get_host_error(h_errno);
				return ghttp_error;
			}
			a_request->connected = 1;
		}

		ghttpDebug("send request ... \n");
		l_rv = http_req_send(a_request->req, a_request->conn);
		if (l_rv == HTTP_TRANS_ERR)
		{
			a_request->errstr = a_request->conn->errstr ? a_request->conn->errstr : GHTTP_ERROR_TRANS_SEND;
			return ghttp_error;
		}
		if (l_rv == HTTP_TRANS_NOT_DONE)
			return ghttp_not_done;
		if (l_rv == HTTP_TRANS_DONE)
		{
			a_request->proc = ghttp_proc_response_hdrs;
			if (a_request->conn->sync == HTTP_TRANS_ASYNC)
				return ghttp_not_done;
		}
	}
	
	if (a_request->proc == ghttp_proc_response_hdrs)
	{
		ghttpDebug("read headers ... \n");
		l_rv = http_resp_read_headers(a_request->resp, a_request->conn);
		if (l_rv == HTTP_TRANS_ERR)
		{
			a_request->errstr = a_request->conn->errstr ? a_request->conn->errstr : GHTTP_ERROR_TRANS_READ_HEAD;
			return ghttp_error;
		}
		if (l_rv == HTTP_TRANS_NOT_DONE)
			return ghttp_not_done;
		if (l_rv == HTTP_TRANS_DONE)
		{
			a_request->proc = ghttp_proc_response;
			if (a_request->conn->sync == HTTP_TRANS_ASYNC)
				return ghttp_not_done;
		}
	}
	
	if (a_request->proc == ghttp_proc_response)
	{
		ghttpDebug("read body ... \n");
		l_rv = http_resp_read_body(a_request->resp, a_request->req, a_request->conn);
		if (l_rv == HTTP_TRANS_ERR)
		{
			a_request->errstr = a_request->conn->errstr ? a_request->conn->errstr : GHTTP_ERROR_TRANS_READ_BODY;
			/* make sure that the connected flag is fixed and stuff */
			if (a_request->conn->sock == -1)
				a_request->connected = 0;
			return ghttp_error;
		}
		if (l_rv == HTTP_TRANS_NEXT)
			return ghttp_next;
		if (l_rv == HTTP_TRANS_NOT_DONE)
			return ghttp_not_done;
		if (l_rv == HTTP_TRANS_DONE)
		{
			/* make sure that the connected flag is fixed and stuff */
			if (a_request->conn->sock == -1)
				a_request->connected = 0;
			a_request->proc = ghttp_proc_done;
			return ghttp_done;
		}
	}
	return ghttp_error;
}
Example #3
0
ghttp_status
ghttp_process(ghttp_request *a_request)
{
  int l_rv = 0;

  if (a_request->proc == ghttp_proc_none)
    a_request->proc = ghttp_proc_request;
  if (a_request->proc == ghttp_proc_request)
    {
      if (a_request->connected == 0)
	{
	  if (http_trans_connect(a_request->conn) < 0)
	    {
	      if (a_request->conn->error_type == http_trans_err_type_errno)
		a_request->errstr = strerror(a_request->conn->error);
	      else if(a_request->conn->error_type == http_trans_err_type_host)
		a_request->errstr = http_trans_get_host_error(h_errno);
	      return ghttp_error;
	    }
	  a_request->connected = 1;
	}
      l_rv = http_req_send(a_request->req, a_request->conn);
      if (l_rv == HTTP_TRANS_ERR)
	return ghttp_error;
      if (l_rv == HTTP_TRANS_NOT_DONE)
	return ghttp_not_done;
      if (l_rv == HTTP_TRANS_DONE)
	{
	  a_request->proc = ghttp_proc_response_hdrs;
	  if (a_request->conn->sync == HTTP_TRANS_ASYNC)
	    return ghttp_not_done;
	}
    }
  if (a_request->proc == ghttp_proc_response_hdrs)
    {
      l_rv = http_resp_read_headers(a_request->resp, a_request->conn);
      if (l_rv == HTTP_TRANS_ERR)
	return ghttp_error;
      if (l_rv == HTTP_TRANS_NOT_DONE)
	return ghttp_not_done;
      if (l_rv == HTTP_TRANS_DONE)
	{
	  a_request->proc = ghttp_proc_response;
	  if (a_request->conn->sync == HTTP_TRANS_ASYNC)
	    return ghttp_not_done;
	}
    }
  if (a_request->proc == ghttp_proc_response)
    {
      l_rv = http_resp_read_body(a_request->resp,
				 a_request->req,
				 a_request->conn);
      if (l_rv == HTTP_TRANS_ERR)
	{
	  /* make sure that the connected flag is fixed and stuff */
	  if (a_request->conn->sock == -1)
	    a_request->connected = 0;
	  return ghttp_error;
	}
      if (l_rv == HTTP_TRANS_NOT_DONE)
	return ghttp_not_done;
      if (l_rv == HTTP_TRANS_DONE)
	{
	/* make sure that the connected flag is fixed and stuff */
	  if (a_request->conn->sock == -1)
	    a_request->connected = 0;
	  a_request->proc = ghttp_proc_none;
	  return ghttp_done;
	}
    }
  return ghttp_error;
}