Commit 4f85f5a5b42cd954637453e8eec084752d796482

separate extracting of socket related info from HTTP req parsing

previously parse_http_request(...) also extracted IP/port information
from the socket; extract this into a separate function, to make this
available to external log message handlers through mg_request_info, even
if the connection setup failed due to an SSL problem
external/mongoose/mongoose.c
(16 / 3)
  
28322832 strncmp(ri->http_version, "HTTP/", 5) == 0) {
28332833 ri->http_version += 5; /* Skip "HTTP/" */
28342834 parse_http_headers(&buf, ri);
2835 ri->remote_port = ntohs(usa->u.sin.sin_port);
2836 (void) memcpy(&ri->remote_ip, &usa->u.sin.sin_addr.s_addr, 4);
2837 ri->remote_ip = ntohl(ri->remote_ip);
28382835 success_code = TRUE;
28392836 }
28402837
28392839}
28402840
28412841/*
2842 * Extract IP/port from connection, fill in mg_request_info structure.
2843 */
2844static void
2845extract_socket_info(struct mg_connection *conn)
2846{
2847 struct mg_request_info *ri = &conn->request_info;
2848 const struct usa *usa = &conn->client.rsa;
2849
2850 ri->remote_port = ntohs(usa->u.sin.sin_port);
2851 (void) memcpy(&ri->remote_ip, &usa->u.sin.sin_addr.s_addr, 4);
2852 ri->remote_ip = ntohl(ri->remote_ip);
2853}
2854
2855/*
28422856 * Keep reading the input (either opened file descriptor fd, or socket sock,
28432857 * or SSL descriptor ssl) into buffer buf, until \r\n\r\n appears in the
28442858 * buffer (which marks the end of HTTP request). Buffer buf may already
45224522 while (get_socket(ctx, &conn.client) == TRUE) {
45234523 conn.birth_time = time(NULL);
45244524 conn.ctx = ctx;
4525
4526 extract_socket_info(&conn);
45254527
45264528 if (conn.client.is_ssl &&
45274529 (conn.ssl = SSL_new(conn.ctx->ssl_ctx)) == NULL) {