Esempio n. 1
0
int main(int argc, char **argv)
{

	FILE *fp = NULL;	
	fp = fopen("conf.txt", "a+");
	get_server_addr(fp, str);
}
Esempio n. 2
0
int redhttp_server_handle_request(redhttp_server_t * server, int socket,
                                  struct sockaddr *sa, size_t sa_len)
{
  redhttp_request_t *request = NULL;
  redhttp_response_t *response = NULL;

  assert(server != NULL);
  assert(socket >= 0);

  request = redhttp_request_new();
  if (!request)
    return -1;
  request->server = server;
  request->socket = fdopen(socket, "r+");;
  if (getnameinfo(sa, sa_len,
                  request->remote_addr, sizeof(request->remote_addr),
                  request->remote_port, sizeof(request->remote_port),
                  NI_NUMERICHOST | NI_NUMERICSERV)) {
    perror("could not get numeric hostname of client");
    redhttp_request_free(request);
    return -1;
  }

  if (get_server_addr(request, socket)) {
    perror("could not get numeric hostname of server");
    redhttp_request_free(request);
    return -1;
  }

  if (redhttp_request_read(request)) {
    // Invalid request
    response = redhttp_response_new_error_page(REDHTTP_BAD_REQUEST, NULL);
  }
  // Dispatch the request
  if (!response)
    response = redhttp_server_dispatch_request(server, request);

  // Send response
  redhttp_response_send(response, request);

  redhttp_request_free(request);
  redhttp_response_free(response);

  // Success
  return 0;
}