#include "connection.h"
#include "verify.h"
+#include <assert.h>
#include <errno.h>
#include <netdb.h>
#include <poll.h>
}
static void send_bad_request(FILE *client_fd) {
-#define RESPONSE_ERROR "400 Bad Request"
-#define RESPONSE_MSG "Your browser sent an invalid request."
- fprintf(client_fd, HTTP_RESPONSE_FORMAT,
- RESPONSE_ERROR, RESPONSE_ERROR, RESPONSE_ERROR,
- RESPONSE_MSG);
+ const char error[] = "400 Bad Request";
+ const char msg[] = "Your browser sent an invalid request.";
+ fprintf(client_fd, HTTP_RESPONSE_FORMAT, error, error, error, msg);
fflush(client_fd);
-#undef RESPONSE_ERROR
-#undef RESPONSE_MSG
}
static void send_forwarding_failure(FILE *client_fd) {
-#define RESPONSE_ERROR "503 Forwarding failure"
-#define RESPONSE_MSG "Failed to connect to server, check logs."
- fprintf(client_fd, HTTP_RESPONSE_FORMAT,
- RESPONSE_ERROR, RESPONSE_ERROR, RESPONSE_ERROR,
- RESPONSE_MSG);
+ const char error[] = "503 Forwarding failure";
+ const char msg[] = "Failed to connect to server, check logs.";
+ fprintf(client_fd, HTTP_RESPONSE_FORMAT, error, error, error, msg);
fflush(client_fd);
-#undef RESPONSE_ERROR
-#undef RESPONSE_MSG
}
static void tls_send_invalid_cert_message(gnutls_session_t session) {
-#define RESPONSE_ERROR "500 Internal Server Error"
-#define RESPONSE_MSG "Server certificate validation failed, check logs."
+ const char error[] = "500 Internal Server Error";
+ const char msg[] = "Server certificate validation failed, check logs.";
int result;
- char buffer[sizeof(HTTP_RESPONSE_FORMAT) - 1 /* '\0' */
- - 4 * 2 /* four %s */
- + (sizeof(RESPONSE_ERROR) - 1 /* '\0' */) * 3
- + sizeof(RESPONSE_MSG) - 1 /* '\0' */
- + 1 /* '\0' */];
-
- result = snprintf(buffer, sizeof(buffer),
- HTTP_RESPONSE_FORMAT,
- RESPONSE_ERROR, RESPONSE_ERROR, RESPONSE_ERROR,
- RESPONSE_MSG);
- if (result < 0) {
- LOG_PERROR(ERROR,
- "tls_send_invalid_cert_message(): snprintf failed");
- return;
- } else if ((size_t)result >= sizeof(buffer)) {
- LOG(ERROR,
- "tls_send_invalid_cert_message(): snprintf buffer too short");
- return;
- }
+ char buffer[sizeof(HTTP_RESPONSE_FORMAT)
+ + 3 * sizeof(error) + sizeof(msg)];
+
+ result = snprintf(buffer, sizeof(buffer), HTTP_RESPONSE_FORMAT,
+ error, error, error, msg);
+ assert(result > 0 && (size_t)result < sizeof(buffer));
- gnutls_record_send(session, buffer, sizeof(buffer) - 1);
- /* don't send trailing '\0' */
-#undef RESPONSE_ERROR
-#undef RESPONSE_MSG
+ gnutls_record_send(session, buffer, strlen(buffer));
}