mirror of
https://github.com/cesanta/mongoose.git
synced 2025-01-15 02:08:08 +08:00
Reverted contributions by jmucchiello
This commit is contained in:
parent
a58e82b301
commit
85209ac4fa
28
mongoose.c
28
mongoose.c
@ -955,8 +955,6 @@ static void send_http_error(struct mg_connection *conn, int status,
|
|||||||
int len = 0;
|
int len = 0;
|
||||||
|
|
||||||
conn->status_code = status;
|
conn->status_code = status;
|
||||||
if (conn->ctx->callbacks.http_error == NULL ||
|
|
||||||
conn->ctx->callbacks.http_error(conn, status)) {
|
|
||||||
buf[0] = '\0';
|
buf[0] = '\0';
|
||||||
|
|
||||||
// Errors 1xx, 204 and 304 MUST NOT send a body
|
// Errors 1xx, 204 and 304 MUST NOT send a body
|
||||||
@ -976,7 +974,6 @@ static void send_http_error(struct mg_connection *conn, int status,
|
|||||||
suggest_connection_header(conn));
|
suggest_connection_header(conn));
|
||||||
conn->num_bytes_sent += mg_printf(conn, "%s", buf);
|
conn->num_bytes_sent += mg_printf(conn, "%s", buf);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
#if defined(_WIN32) && !defined(__SYMBIAN32__)
|
#if defined(_WIN32) && !defined(__SYMBIAN32__)
|
||||||
static int pthread_mutex_init(pthread_mutex_t *mutex, void *unused) {
|
static int pthread_mutex_init(pthread_mutex_t *mutex, void *unused) {
|
||||||
@ -1628,24 +1625,6 @@ int mg_write(struct mg_connection *conn, const void *buf, size_t len) {
|
|||||||
return (int) total;
|
return (int) total;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Alternative alloc_vprintf() for non-compliant C runtimes
|
|
||||||
static int alloc_vprintf2(char **buf, const char *fmt, va_list ap) {
|
|
||||||
va_list ap_copy;
|
|
||||||
int size = MG_BUF_LEN;
|
|
||||||
int len = -1;
|
|
||||||
|
|
||||||
*buf = NULL;
|
|
||||||
while (len == -1) {
|
|
||||||
if (*buf) free(*buf);
|
|
||||||
*buf = malloc(size *= 4);
|
|
||||||
if (!*buf) break;
|
|
||||||
va_copy(ap_copy, ap);
|
|
||||||
len = vsnprintf(*buf, size, fmt, ap_copy);
|
|
||||||
}
|
|
||||||
|
|
||||||
return len;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Print message to buffer. If buffer is large enough to hold the message,
|
// Print message to buffer. If buffer is large enough to hold the message,
|
||||||
// return buffer. If buffer is to small, allocate large enough buffer on heap,
|
// return buffer. If buffer is to small, allocate large enough buffer on heap,
|
||||||
// and return allocated buffer.
|
// and return allocated buffer.
|
||||||
@ -1661,12 +1640,7 @@ static int alloc_vprintf(char **buf, size_t size, const char *fmt, va_list ap) {
|
|||||||
va_copy(ap_copy, ap);
|
va_copy(ap_copy, ap);
|
||||||
len = vsnprintf(NULL, 0, fmt, ap_copy);
|
len = vsnprintf(NULL, 0, fmt, ap_copy);
|
||||||
|
|
||||||
if (len < 0) {
|
if (len > (int) size &&
|
||||||
// C runtime is not standard compliant, vsnprintf() returned -1.
|
|
||||||
// Switch to alternative code path that uses incremental allocations.
|
|
||||||
va_copy(ap_copy, ap);
|
|
||||||
len = alloc_vprintf2(buf, fmt, ap);
|
|
||||||
} else if (len > (int) size &&
|
|
||||||
(size = len + 1) > 0 &&
|
(size = len + 1) > 0 &&
|
||||||
(*buf = (char *) malloc(size)) == NULL) {
|
(*buf = (char *) malloc(size)) == NULL) {
|
||||||
len = -1; // Allocation failed, mark failure
|
len = -1; // Allocation failed, mark failure
|
||||||
|
@ -120,7 +120,6 @@ struct mg_callbacks {
|
|||||||
// Implementing this callback allows to create custom error pages.
|
// Implementing this callback allows to create custom error pages.
|
||||||
// Parameters:
|
// Parameters:
|
||||||
// status: HTTP error status code.
|
// status: HTTP error status code.
|
||||||
int (*http_error)(struct mg_connection *, int status);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Start web server.
|
// Start web server.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user