-/* $OpenBSD: http.h,v 1.2 2014/07/11 11:48:50 reyk Exp $ */
+/* $OpenBSD: http.h,v 1.3 2014/07/12 14:34:13 reyk Exp $ */
/*
* Copyright (c) 2012 - 2014 Reyk Floeter <reyk@openbsd.org>
{ HTTP_METHOD_NONE, NULL } \
}
+struct http_error {
+ int error_code;
+ const char *error_name;
+};
+#define HTTP_ERRORS { \
+ { 100, "Continue" }, \
+ { 101, "Switching Protocols" }, \
+ { 200, "OK" }, \
+ { 201, "Created" }, \
+ { 202, "Accepted" }, \
+ { 203, "Non-Authorative Information" }, \
+ { 204, "No Content" }, \
+ { 205, "Reset Content" }, \
+ { 206, "Partial Content" }, \
+ { 300, "Multiple Choices" }, \
+ { 301, "Moved Permanently" }, \
+ { 302, "Moved Temporarily" }, \
+ { 303, "See Other" }, \
+ { 304, "Not Modified" }, \
+ { 307, "Temporary Redirect" }, \
+ { 400, "Bad Request" }, \
+ { 401, "Unauthorized" }, \
+ { 402, "Payment Required" }, \
+ { 403, "Forbidden" }, \
+ { 404, "Not Found" }, \
+ { 405, "Method Not Allowed" }, \
+ { 406, "Not Acceptable" }, \
+ { 407, "Proxy Authentication Required" }, \
+ { 408, "Request Timeout" }, \
+ { 409, "Conflict" }, \
+ { 410, "Gone" }, \
+ { 411, "Length Required" }, \
+ { 412, "Precondition Failed" }, \
+ { 413, "Request Entity Too Large" }, \
+ { 414, "Request-URL Too Long" }, \
+ { 415, "Unsupported Media Type" }, \
+ { 416, "Requested Range Not Satisfiable" }, \
+ { 417, "Expectation Failed" }, \
+ { 500, "Internal Server Error" }, \
+ { 501, "Not Implemented" }, \
+ { 502, "Bad Gateway" }, \
+ { 503, "Service Unavailable" }, \
+ { 504, "Gateway Timeout" }, \
+ { 505, "HTTP Version Not Supported" }, \
+ { 0, NULL } \
+}
+
/* Used during runtime */
struct http_descriptor {
struct kv http_pathquery;
-/* $OpenBSD: log.c,v 1.22 2014/04/18 16:13:02 reyk Exp $ */
+/* $OpenBSD: log.c,v 1.23 2014/07/12 14:34:13 reyk Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
return (buf);
}
-const char *
-print_httperror(u_int code)
-{
- u_int i;
- struct {
- u_int ht_code;
- const char *ht_err;
- } httperr[] = {
- { 100, "Continue" },
- { 101, "Switching Protocols" },
- { 200, "OK" },
- { 201, "Created" },
- { 202, "Accepted" },
- { 203, "Non-Authorative Information" },
- { 204, "No Content" },
- { 205, "Reset Content" },
- { 206, "Partial Content" },
- { 300, "Multiple Choices" },
- { 301, "Moved Permanently" },
- { 302, "Moved Temporarily" },
- { 303, "See Other" },
- { 304, "Not Modified" },
- { 307, "Temporary Redirect" },
- { 400, "Bad Request" },
- { 401, "Unauthorized" },
- { 402, "Payment Required" },
- { 403, "Forbidden" },
- { 404, "Not Found" },
- { 405, "Method Not Allowed" },
- { 406, "Not Acceptable" },
- { 407, "Proxy Authentication Required" },
- { 408, "Request Timeout" },
- { 409, "Conflict" },
- { 410, "Gone" },
- { 411, "Length Required" },
- { 412, "Precondition Failed" },
- { 413, "Request Entity Too Large" },
- { 414, "Request-URL Too Long" },
- { 415, "Unsupported Media Type" },
- { 416, "Requested Range Not Satisfiable" },
- { 417, "Expectation Failed" },
- { 500, "Internal Server Error" },
- { 501, "Not Implemented" },
- { 502, "Bad Gateway" },
- { 503, "Service Unavailable" },
- { 504, "Gateway Timeout" },
- { 505, "HTTP Version Not Supported" },
- { 0 }
- };
-
- for (i = 0; httperr[i].ht_code != 0; i++)
- if (httperr[i].ht_code == code)
- return (httperr[i].ht_err);
- return ("Unknown Error");
-}
-
const char *
printb_flags(const u_int32_t v, const char *bits)
{
-/* $OpenBSD: relay_http.c,v 1.25 2014/07/11 23:11:54 benno Exp $ */
+/* $OpenBSD: relay_http.c,v 1.26 2014/07/12 14:34:13 reyk Exp $ */
/*
* Copyright (c) 2006 - 2014 Reyk Floeter <reyk@openbsd.org>
struct ctl_relay_event *);
void relay_reset_http(struct ctl_relay_event *);
static int relay_httpmethod_cmp(const void *, const void *);
+static int relay_httperror_cmp(const void *, const void *);
int relay_httpquery_test(struct ctl_relay_event *,
struct relay_rule *, struct kvlist *);
int relay_httpheader_test(struct ctl_relay_event *,
static struct relayd *env = NULL;
static struct http_method http_methods[] = HTTP_METHODS;
+static struct http_error http_errors[] = HTTP_ERRORS;
void
relay_http(struct relayd *x_env)
qsort(http_methods, sizeof(http_methods) /
sizeof(http_methods[0]) - 1,
sizeof(http_methods[0]), relay_httpmethod_cmp);
+ qsort(http_errors, sizeof(http_errors) /
+ sizeof(http_errors[0]) - 1,
+ sizeof(http_errors[0]), relay_httperror_cmp);
}
void
{
struct relay *rlay = con->se_relay;
struct bufferevent *bev = con->se_in.bev;
- const char *httperr = print_httperror(code), *text = "";
+ const char *httperr = NULL, *text = "";
char *httpmsg;
time_t t;
struct tm *lt;
char tmbuf[32], hbuf[128];
const char *style, *label = NULL;
+ if ((httperr = relay_httperror_byid(code)) == NULL)
+ httperr = "Unknown Error";
+
if (labelid != 0)
label = label_id2name(labelid);
return (strcmp(ma->method_name, mb->method_name));
}
+const char *
+relay_httperror_byid(u_int id)
+{
+ struct http_error error, *res = NULL;
+
+ /* Set up key */
+ error.error_code = (int)id;
+
+ res = bsearch(&error, http_errors,
+ sizeof(http_errors) / sizeof(http_errors[0]) - 1,
+ sizeof(http_errors[0]), relay_httperror_cmp);
+
+ return (res->error_name);
+}
+
+static int
+relay_httperror_cmp(const void *a, const void *b)
+{
+ const struct http_error *ea = a;
+ const struct http_error *eb = b;
+ return (ea->error_code - eb->error_code);
+}
+
int
relay_httpquery_test(struct ctl_relay_event *cre, struct relay_rule *rule,
struct kvlist *actions)
-/* $OpenBSD: relayd.h,v 1.186 2014/07/11 22:28:44 reyk Exp $ */
+/* $OpenBSD: relayd.h,v 1.187 2014/07/12 14:34:13 reyk Exp $ */
/*
* Copyright (c) 2006 - 2014 Reyk Floeter <reyk@openbsd.org>
const char *print_availability(u_long, u_long);
const char *print_host(struct sockaddr_storage *, char *, size_t);
const char *print_time(struct timeval *, struct timeval *, char *, size_t);
-const char *print_httperror(u_int);
const char *printb_flags(const u_int32_t, const char *);
void getmonotime(struct timeval *);
u_int relay_httpmethod_byname(const char *);
const char
*relay_httpmethod_byid(u_int);
+const char
+ *relay_httperror_byid(u_int);
int relay_httpdesc_init(struct ctl_relay_event *);
/* relay_udp.c */