1
0
mirror of https://github.com/lammertb/libhttp.git synced 2025-08-09 03:22:45 +03:00

Renamed mg_ to httplib_

This commit is contained in:
Lammert Bies
2016-12-13 17:32:31 +01:00
parent 647139558b
commit d317ce3e82
178 changed files with 2173 additions and 2513 deletions

View File

@@ -27,7 +27,7 @@
#include "httplib_string.h"
/*
* void XX_httplib_handle_cgi_request( struct mg_connection *conn, const char *prog );
* void XX_httplib_handle_cgi_request( struct httplib_connection *conn, const char *prog );
*
* The function XX_httplib_handle_cgi_request() handles a request for a CGI
* resource.
@@ -35,7 +35,7 @@
#if !defined(NO_CGI)
void XX_httplib_handle_cgi_request( struct mg_connection *conn, const char *prog ) {
void XX_httplib_handle_cgi_request( struct httplib_connection *conn, const char *prog ) {
char *buf;
size_t buflen;
@@ -52,7 +52,7 @@ void XX_httplib_handle_cgi_request( struct mg_connection *conn, const char *prog
char *pbuf;
char dir[PATH_MAX];
char *p;
struct mg_request_info ri;
struct httplib_request_info ri;
struct cgi_environment blk;
FILE *in;
FILE *out;
@@ -76,7 +76,7 @@ void XX_httplib_handle_cgi_request( struct mg_connection *conn, const char *prog
XX_httplib_snprintf(conn, &truncated, dir, sizeof(dir), "%s", prog);
if (truncated) {
mg_cry(conn, "Error: CGI program \"%s\": Path too long", prog);
httplib_cry(conn, "Error: CGI program \"%s\": Path too long", prog);
XX_httplib_send_http_error(conn, 500, "Error: %s", "CGI path too long");
goto done;
}
@@ -90,7 +90,7 @@ void XX_httplib_handle_cgi_request( struct mg_connection *conn, const char *prog
if (pipe(fdin) != 0 || pipe(fdout) != 0 || pipe(fderr) != 0) {
status = strerror(ERRNO);
mg_cry(conn, "Error: CGI program \"%s\": Can not create CGI pipes: %s", prog, status);
httplib_cry(conn, "Error: CGI program \"%s\": Can not create CGI pipes: %s", prog, status);
XX_httplib_send_http_error(conn, 500, "Error: Cannot create CGI pipe: %s", status);
goto done;
}
@@ -99,7 +99,7 @@ void XX_httplib_handle_cgi_request( struct mg_connection *conn, const char *prog
if (pid == (pid_t)-1) {
status = strerror(ERRNO);
mg_cry(conn, "Error: CGI program \"%s\": Can not spawn CGI process: %s", prog, status);
httplib_cry(conn, "Error: CGI program \"%s\": Can not spawn CGI process: %s", prog, status);
XX_httplib_send_http_error(conn, 500, "Error: Cannot spawn CGI process [%s]: %s", prog, status);
goto done;
}
@@ -126,21 +126,21 @@ void XX_httplib_handle_cgi_request( struct mg_connection *conn, const char *prog
if ((in = fdopen(fdin[1], "wb")) == NULL) {
status = strerror(ERRNO);
mg_cry(conn, "Error: CGI program \"%s\": Can not open stdin: %s", prog, status);
httplib_cry(conn, "Error: CGI program \"%s\": Can not open stdin: %s", prog, status);
XX_httplib_send_http_error(conn, 500, "Error: CGI can not open fdin\nfopen: %s", status);
goto done;
}
if ((out = fdopen(fdout[0], "rb")) == NULL) {
status = strerror(ERRNO);
mg_cry(conn, "Error: CGI program \"%s\": Can not open stdout: %s", prog, status);
httplib_cry(conn, "Error: CGI program \"%s\": Can not open stdout: %s", prog, status);
XX_httplib_send_http_error(conn, 500, "Error: CGI can not open fdout\nfopen: %s", status);
goto done;
}
if ((err = fdopen(fderr[0], "rb")) == NULL) {
status = strerror(ERRNO);
mg_cry(conn, "Error: CGI program \"%s\": Can not open stderr: %s", prog, status);
httplib_cry(conn, "Error: CGI program \"%s\": Can not open stderr: %s", prog, status);
XX_httplib_send_http_error(conn, 500, "Error: CGI can not open fdout\nfopen: %s", status);
goto done;
}
@@ -154,7 +154,7 @@ void XX_httplib_handle_cgi_request( struct mg_connection *conn, const char *prog
/* This is a POST/PUT request, or another request with body data. */
if (!XX_httplib_forward_body_data(conn, in, INVALID_SOCKET, NULL)) {
/* Error sending the body data */
mg_cry(conn, "Error: CGI program \"%s\": Forward body data failed", prog);
httplib_cry(conn, "Error: CGI program \"%s\": Forward body data failed", prog);
goto done;
}
}
@@ -172,7 +172,7 @@ void XX_httplib_handle_cgi_request( struct mg_connection *conn, const char *prog
buf = (char *)XX_httplib_malloc(buflen);
if (buf == NULL) {
XX_httplib_send_http_error(conn, 500, "Error: Not enough memory for CGI buffer (%u bytes)", (unsigned int)buflen);
mg_cry(conn, "Error: CGI program \"%s\": Not enough memory for buffer (%u " "bytes)", prog, (unsigned int)buflen);
httplib_cry(conn, "Error: CGI program \"%s\": Not enough memory for buffer (%u " "bytes)", prog, (unsigned int)buflen);
goto done;
}
headers_len = XX_httplib_read_request(out, conn, buf, (int)buflen, &data_len);
@@ -182,10 +182,10 @@ void XX_httplib_handle_cgi_request( struct mg_connection *conn, const char *prog
* stderr. */
i = XX_httplib_pull_all(err, conn, buf, (int)buflen);
if (i > 0) {
mg_cry(conn, "Error: CGI program \"%s\" sent error " "message: [%.*s]", prog, i, buf);
httplib_cry(conn, "Error: CGI program \"%s\" sent error " "message: [%.*s]", prog, i, buf);
XX_httplib_send_http_error(conn, 500, "Error: CGI program \"%s\" sent error " "message: [%.*s]", prog, i, buf);
} else {
mg_cry(conn, "Error: CGI program sent malformed or too big " "(>%u bytes) HTTP headers: [%.*s]", (unsigned)buflen, data_len, buf);
httplib_cry(conn, "Error: CGI program sent malformed or too big " "(>%u bytes) HTTP headers: [%.*s]", (unsigned)buflen, data_len, buf);
XX_httplib_send_http_error(conn,
500,
@@ -220,17 +220,16 @@ void XX_httplib_handle_cgi_request( struct mg_connection *conn, const char *prog
if (!XX_httplib_header_has_option(connection_state, "keep-alive")) {
conn->must_close = 1;
}
mg_printf(conn, "HTTP/1.1 %d %s\r\n", conn->status_code, status_text);
httplib_printf(conn, "HTTP/1.1 %d %s\r\n", conn->status_code, status_text);
/* Send headers */
for (i = 0; i < ri.num_headers; i++) {
mg_printf(conn, "%s: %s\r\n", ri.http_headers[i].name, ri.http_headers[i].value);
httplib_printf(conn, "%s: %s\r\n", ri.http_headers[i].name, ri.http_headers[i].value);
}
mg_write(conn, "\r\n", 2);
httplib_write(conn, "\r\n", 2);
/* Send chunk of data that may have been read after the headers */
conn->num_bytes_sent +=
mg_write(conn, buf + headers_len, (size_t)(data_len - headers_len));
conn->num_bytes_sent += httplib_write(conn, buf + headers_len, (size_t)(data_len - headers_len));
/* Read the rest of CGI output and send to the client */
XX_httplib_send_file_data(conn, &fout, 0, INT64_MAX);