diff options
author | Martin Pitt <martin.pitt@ubuntu.com> | 2016-09-14 11:17:58 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-09-14 11:17:58 +0200 |
commit | 2d88def9593b9809c71039bee67bea150ddd3598 (patch) | |
tree | bc03e083cf558d286141b24bc72c1855325efd73 /src/journal-remote/microhttpd-util.c | |
parent | 34210af7c63640fca1fd4a09fc23b01a8cd70bf3 (diff) | |
parent | e031c227cbbe7243212ecb38a6db105a93655eae (diff) |
Merge pull request #4133 from keszybz/strerror-removal
Strerror removal and other janitorial cleanups
Diffstat (limited to 'src/journal-remote/microhttpd-util.c')
-rw-r--r-- | src/journal-remote/microhttpd-util.c | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/src/journal-remote/microhttpd-util.c b/src/journal-remote/microhttpd-util.c index 2f16b02e9a..cae10203c6 100644 --- a/src/journal-remote/microhttpd-util.c +++ b/src/journal-remote/microhttpd-util.c @@ -48,7 +48,7 @@ void microhttpd_logger(void *arg, const char *fmt, va_list ap) { static int mhd_respond_internal(struct MHD_Connection *connection, enum MHD_RequestTerminationCode code, - char *buffer, + const char *buffer, size_t size, enum MHD_ResponseMemoryMode mode) { struct MHD_Response *response; @@ -56,7 +56,7 @@ static int mhd_respond_internal(struct MHD_Connection *connection, assert(connection); - response = MHD_create_response_from_buffer(size, buffer, mode); + response = MHD_create_response_from_buffer(size, (char*) buffer, mode); if (!response) return MHD_NO; @@ -72,19 +72,25 @@ int mhd_respond(struct MHD_Connection *connection, enum MHD_RequestTerminationCode code, const char *message) { + const char *fmt; + + fmt = strjoina(message, "\n"); + return mhd_respond_internal(connection, code, - (char*) message, strlen(message), + fmt, strlen(message) + 1, MHD_RESPMEM_PERSISTENT); } int mhd_respond_oom(struct MHD_Connection *connection) { - return mhd_respond(connection, MHD_HTTP_SERVICE_UNAVAILABLE, "Out of memory.\n"); + return mhd_respond(connection, MHD_HTTP_SERVICE_UNAVAILABLE, "Out of memory."); } int mhd_respondf(struct MHD_Connection *connection, + int error, enum MHD_RequestTerminationCode code, const char *format, ...) { + const char *fmt; char *m; int r; va_list ap; @@ -92,8 +98,12 @@ int mhd_respondf(struct MHD_Connection *connection, assert(connection); assert(format); + if (error < 0) + error = -error; + errno = -error; + fmt = strjoina(format, "\n"); va_start(ap, format); - r = vasprintf(&m, format, ap); + r = vasprintf(&m, fmt, ap); va_end(ap); if (r < 0) |