summaryrefslogtreecommitdiff
path: root/src/journal-remote/microhttpd-util.c
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2016-09-12 19:33:37 +0100
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2016-09-13 20:10:56 -0400
commitf5e757f1ce84c1d6ae932cf2b604238fb4cedc00 (patch)
tree7638c7e54cb924552f0d01229fddc536633c6a24 /src/journal-remote/microhttpd-util.c
parent1b4cd64683ba057cb3d4c5cd311b1c25e6d8d614 (diff)
microhttpd-util: add the trailing newline automatically
It's prone to error and annoying to have to add it manually. It was missing from a few places.
Diffstat (limited to 'src/journal-remote/microhttpd-util.c')
-rw-r--r--src/journal-remote/microhttpd-util.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/src/journal-remote/microhttpd-util.c b/src/journal-remote/microhttpd-util.c
index 67d97e24ff..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,13 +72,17 @@ 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,
@@ -86,6 +90,7 @@ int mhd_respondf(struct MHD_Connection *connection,
enum MHD_RequestTerminationCode code,
const char *format, ...) {
+ const char *fmt;
char *m;
int r;
va_list ap;
@@ -96,8 +101,9 @@ int mhd_respondf(struct MHD_Connection *connection,
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)