kore

An easy to use, scalable and secure web application framework for writing web APIs in C.
Commits | Files | Refs | README | LICENSE | git clone https://git.kore.io/kore.git

commit e7db5ee6b1f3fdf4f187731f33c9da7f4a02b16f
parent 11fca1992320b65dfa5438385fe258869a69820f
Author: Joris Vink <joris@coders.se>
Date:   Tue,  4 Jun 2013 16:30:53 +0200

rename kore_log to kore_debug, and allow one to turn it off.

Diffstat:
includes/kore.h | 10+++++-----
src/config.c | 20++++++++++----------
src/http.c | 26+++++++++++++-------------
src/kore.c | 80++++++++++++++++++++++++++++++++++++++++----------------------------------------
src/module.c | 10+++++-----
src/net.c | 24++++++++++++------------
src/spdy.c | 92++++++++++++++++++++++++++++++++++++++++----------------------------------------
src/utils.c | 22+++++++++++-----------
8 files changed, 142 insertions(+), 142 deletions(-)

diff --git a/includes/kore.h b/includes/kore.h @@ -24,12 +24,12 @@ #define errno_s strerror(errno) #define ssl_errno_s ERR_error_string(ERR_get_error(), NULL) -#define KORE_DEBUG 1 +//#define KORE_DEBUG 1 #if defined(KORE_DEBUG) -#define kore_log(fmt, ...) \ - kore_log_internal(__FILE__, __LINE__, fmt, ##__VA_ARGS__) +#define kore_debug(fmt, ...) \ + kore_debug_internal(__FILE__, __LINE__, fmt, ##__VA_ARGS__) #else -#define kore_log(fmt, ...) +#define kore_debug(fmt, ...) #endif #define NETBUF_RECV 0 @@ -155,7 +155,7 @@ void *kore_module_handler_find(char *, char *); int kore_module_handler_new(char *, char *, char *, int); void fatal(const char *, ...); -void kore_log_internal(char *, int, const char *, ...); +void kore_debug_internal(char *, int, const char *, ...); u_int16_t net_read16(u_int8_t *); u_int32_t net_read32(u_int8_t *); diff --git a/src/config.c b/src/config.c @@ -115,14 +115,14 @@ configure_bind(char **argv) if (argv[1] == NULL || argv[2] == NULL) return (KORE_RESULT_ERROR); if (server_ip != NULL || server_port != 0) { - kore_log("duplicate bind directive seen"); + kore_debug("duplicate bind directive seen"); return (KORE_RESULT_ERROR); } server_ip = kore_strdup(argv[1]); server_port = kore_strtonum(argv[2], 1, 65535, &err); if (err != KORE_RESULT_OK) { - kore_log("%s is an invalid port number", argv[2]); + kore_debug("%s is an invalid port number", argv[2]); return (KORE_RESULT_ERROR); } @@ -146,7 +146,7 @@ configure_onload(char **argv) return (KORE_RESULT_ERROR); if (kore_module_onload != NULL) { - kore_log("duplicate onload directive found"); + kore_debug("duplicate onload directive found"); return (KORE_RESULT_ERROR); } @@ -164,7 +164,7 @@ configure_domain(char **argv) free(current_domain); current_domain = kore_strdup(argv[1]); if (!kore_module_domain_new(current_domain)) { - kore_log("could not create new domain %s", current_domain); + kore_debug("could not create new domain %s", current_domain); return (KORE_RESULT_ERROR); } @@ -177,7 +177,7 @@ configure_handler(char **argv) int type; if (current_domain == NULL) { - kore_log("missing domain for page handler"); + kore_debug("missing domain for page handler"); return (KORE_RESULT_ERROR); } @@ -192,7 +192,7 @@ configure_handler(char **argv) return (KORE_RESULT_ERROR); if (!kore_module_handler_new(argv[1], current_domain, argv[2], type)) { - kore_log("cannot create handler for %s", argv[1]); + kore_debug("cannot create handler for %s", argv[1]); return (KORE_RESULT_ERROR); } @@ -203,7 +203,7 @@ static int configure_chroot(char **argv) { if (chroot_path != NULL) { - kore_log("duplicate chroot path specified"); + kore_debug("duplicate chroot path specified"); return (KORE_RESULT_ERROR); } @@ -218,7 +218,7 @@ static int configure_runas(char **argv) { if (runas_user != NULL) { - kore_log("duplicate runas user specified"); + kore_debug("duplicate runas user specified"); return (KORE_RESULT_ERROR); } @@ -235,7 +235,7 @@ configure_workers(char **argv) int err; if (worker_count != 0) { - kore_log("duplicate worker directive specified"); + kore_debug("duplicate worker directive specified"); return (KORE_RESULT_ERROR); } @@ -244,7 +244,7 @@ configure_workers(char **argv) worker_count = kore_strtonum(argv[1], 1, 255, &err); if (err != KORE_RESULT_OK) { - kore_log("%s is not a correct worker number", argv[1]); + kore_debug("%s is not a correct worker number", argv[1]); return (KORE_RESULT_ERROR); } diff --git a/src/http.c b/src/http.c @@ -59,7 +59,7 @@ http_request_new(struct connection *c, struct spdy_stream *s, char *host, { struct http_request *req; - kore_log("http_request_new(%p, %p, %s, %s, %s)", c, s, + kore_debug("http_request_new(%p, %p, %s, %s, %s)", c, s, host, method, path); req = (struct http_request *)kore_malloc(sizeof(*req)); @@ -79,7 +79,7 @@ http_request_new(struct connection *c, struct spdy_stream *s, char *host, } else if (!strcasecmp(method, "post")) { req->method = HTTP_METHOD_POST; } else { - kore_log("invalid method specified in request: %s", method); + kore_debug("invalid method specified in request: %s", method); http_request_free(req); return (KORE_RESULT_ERROR); } @@ -143,7 +143,7 @@ http_response_header_add(struct http_request *req, char *header, char *value) { struct http_header *hdr; - kore_log("http_response_header_add(%p, %s, %s)", req, header, value); + kore_debug("http_response_header_add(%p, %s, %s)", req, header, value); hdr = (struct http_header *)kore_malloc(sizeof(*hdr)); hdr->header = kore_strdup(header); @@ -200,7 +200,7 @@ http_response(struct http_request *req, int status, u_int8_t *d, u_int32_t len) struct spdy_header_block *hblock; char sbuf[512]; - kore_log("http_response(%p, %d, %p, %d)", req, status, d, len); + kore_debug("http_response(%p, %d, %p, %d)", req, status, d, len); if (req->owner->proto == CONN_PROTO_SPDY) { snprintf(sbuf, sizeof(sbuf), "%d", status); @@ -288,7 +288,7 @@ http_header_recv(struct netbuf *nb) char *p, *headers[HTTP_REQ_HEADER_MAX]; struct connection *c = (struct connection *)nb->owner; - kore_log("http_header_recv(%p)", nb); + kore_debug("http_header_recv(%p)", nb); ch = nb->buf[nb->len]; nb->buf[nb->len] = '\0'; @@ -363,7 +363,7 @@ http_header_recv(struct netbuf *nb) p = strchr(headers[i], ':'); if (p == NULL) { - kore_log("malformed header: '%s'", headers[i]); + kore_debug("malformed header: '%s'", headers[i]); continue; } @@ -378,7 +378,7 @@ http_header_recv(struct netbuf *nb) if (req->method == HTTP_METHOD_POST) { if (!http_request_header_get(req, "content-length", &p)) { - kore_log("POST but no content-length"); + kore_debug("POST but no content-length"); req->flags |= HTTP_REQUEST_DELETE; return (KORE_RESULT_ERROR); } @@ -386,7 +386,7 @@ http_header_recv(struct netbuf *nb) clen = kore_strtonum(p, 0, UINT_MAX, &v); if (v == KORE_RESULT_ERROR) { free(p); - kore_log("content-length invalid: %s", p); + kore_debug("content-length invalid: %s", p); req->flags |= HTTP_REQUEST_DELETE; return (KORE_RESULT_ERROR); } @@ -397,7 +397,7 @@ http_header_recv(struct netbuf *nb) (nb->offset - len)); bytes_left = clen - (nb->offset - len); - kore_log("need %ld more bytes for POST", bytes_left); + kore_debug("need %ld more bytes for POST", bytes_left); net_recv_queue(c, bytes_left, 0, &nnb, http_post_data_recv); nnb->extra = req; } @@ -415,7 +415,7 @@ http_populate_arguments(struct http_request *req) if (req->method == HTTP_METHOD_POST) { query = http_post_data_text(req); } else { - kore_log("HTTP_METHOD_GET not supported for arguments"); + kore_debug("HTTP_METHOD_GET not supported for arguments"); return (0); } @@ -424,7 +424,7 @@ http_populate_arguments(struct http_request *req) for (i = 0; i < v; i++) { c = kore_split_string(args[i], "=", val, 3); if (c != 1 && c != 2) { - kore_log("malformed query argument"); + kore_debug("malformed query argument"); continue; } @@ -479,7 +479,7 @@ http_post_data_text(struct http_request *req) int http_generic_404(struct http_request *req) { - kore_log("http_generic_404(%s, %d, %s)", + kore_debug("http_generic_404(%s, %d, %s)", req->host, req->method, req->path); return (http_response(req, 404, NULL, 0)); @@ -493,7 +493,7 @@ http_post_data_recv(struct netbuf *nb) kore_buf_append(req->post_data, nb->buf, nb->offset); req->flags |= HTTP_REQUEST_COMPLETE; - kore_log("post complete for request %p", req); + kore_debug("post complete for request %p", req); return (KORE_RESULT_OK); } diff --git a/src/kore.c b/src/kore.c @@ -104,7 +104,7 @@ main(int argc, char *argv[]) if ((pw = getpwnam(runas_user)) == NULL) fatal("user '%s' does not exist"); if ((cpu_count = sysconf(_SC_NPROCESSORS_ONLN)) == -1) { - kore_log("could not get number of cpu's falling back to 1"); + kore_debug("could not get number of cpu's falling back to 1"); cpu_count = 1; } @@ -130,7 +130,7 @@ main(int argc, char *argv[]) if (sig_recv == SIGHUP) { TAILQ_FOREACH(kw, &kore_workers, list) { if (kill(kw->pid, SIGHUP) == -1) { - kore_log("kill(%d, SIGHUP): %s", + kore_debug("kill(%d, SIGHUP): %s", kw->pid, errno_s); } } @@ -147,14 +147,14 @@ main(int argc, char *argv[]) for (kw = TAILQ_FIRST(&kore_workers); kw != NULL; kw = next) { next = TAILQ_NEXT(kw, list); if (kill(kw->pid, SIGINT) == -1) - kore_log("kill(%d, SIGINT): %s", kw->pid, errno_s); + kore_debug("kill(%d, SIGINT): %s", kw->pid, errno_s); } - kore_log("waiting for workers to drain and finish"); + kore_debug("waiting for workers to drain and finish"); while (!TAILQ_EMPTY(&kore_workers)) kore_worker_wait(1); - kore_log("server shutting down"); + kore_debug("server shutting down"); close(server.fd); return (0); @@ -164,7 +164,7 @@ void kore_server_disconnect(struct connection *c) { if (c->state != CONN_STATE_DISCONNECTING) { - kore_log("preparing %p for disconnection", c); + kore_debug("preparing %p for disconnection", c); c->state = CONN_STATE_DISCONNECTING; TAILQ_REMOVE(&worker_clients, c, list); TAILQ_INSERT_TAIL(&disconnected, c, list); @@ -174,24 +174,24 @@ kore_server_disconnect(struct connection *c) static int kore_server_sslstart(void) { - kore_log("kore_server_sslstart()"); + kore_debug("kore_server_sslstart()"); SSL_library_init(); SSL_load_error_strings(); ssl_ctx = SSL_CTX_new(SSLv23_server_method()); if (ssl_ctx == NULL) { - kore_log("SSL_ctx_new(): %s", ssl_errno_s); + kore_debug("SSL_ctx_new(): %s", ssl_errno_s); return (KORE_RESULT_ERROR); } if (!SSL_CTX_use_certificate_chain_file(ssl_ctx, "cert/server.crt")) { - kore_log("SSL_CTX_use_certificate_file(): %s", ssl_errno_s); + kore_debug("SSL_CTX_use_certificate_file(): %s", ssl_errno_s); return (KORE_RESULT_ERROR); } if (!SSL_CTX_use_PrivateKey_file(ssl_ctx, "cert/server.key", SSL_FILETYPE_PEM)) { - kore_log("SSL_CTX_use_PrivateKey_file(): %s", ssl_errno_s); + kore_debug("SSL_CTX_use_PrivateKey_file(): %s", ssl_errno_s); return (KORE_RESULT_ERROR); } @@ -208,10 +208,10 @@ kore_server_bind(struct listener *l, const char *ip, int port) { int on; - kore_log("kore_server_bind(%p, %s, %d)", l, ip, port); + kore_debug("kore_server_bind(%p, %s, %d)", l, ip, port); if ((l->fd = socket(AF_INET, SOCK_STREAM, 0)) == -1) { - kore_log("socket(): %s", errno_s); + kore_debug("socket(): %s", errno_s); return (KORE_RESULT_ERROR); } @@ -223,7 +223,7 @@ kore_server_bind(struct listener *l, const char *ip, int port) on = 1; if (setsockopt(l->fd, SOL_SOCKET, SO_REUSEADDR, (const char *)&on, sizeof(on)) == -1) { - kore_log("setsockopt(): %s", errno_s); + kore_debug("setsockopt(): %s", errno_s); close(l->fd); return (KORE_RESULT_ERROR); } @@ -235,13 +235,13 @@ kore_server_bind(struct listener *l, const char *ip, int port) if (bind(l->fd, (struct sockaddr *)&(l->sin), sizeof(l->sin)) == -1) { close(l->fd); - kore_log("bind(): %s", errno_s); + kore_debug("bind(): %s", errno_s); return (KORE_RESULT_ERROR); } if (listen(l->fd, 50) == -1) { close(l->fd); - kore_log("listen(): %s", errno_s); + kore_debug("listen(): %s", errno_s); return (KORE_RESULT_ERROR); } @@ -254,13 +254,13 @@ kore_server_accept(struct listener *l) socklen_t len; struct connection *c; - kore_log("kore_server_accept(%p)", l); + kore_debug("kore_server_accept(%p)", l); len = sizeof(struct sockaddr_in); c = (struct connection *)kore_malloc(sizeof(*c)); if ((c->fd = accept(l->fd, (struct sockaddr *)&(c->sin), &len)) == -1) { free(c); - kore_log("accept(): %s", errno_s); + kore_debug("accept(): %s", errno_s); return (KORE_RESULT_ERROR); } @@ -295,7 +295,7 @@ kore_server_final_disconnect(struct connection *c) struct netbuf *nb, *next; struct spdy_stream *s, *snext; - kore_log("kore_server_final_disconnect(%p)", c); + kore_debug("kore_server_final_disconnect(%p)", c); if (c->ssl != NULL) SSL_free(c->ssl); @@ -344,7 +344,7 @@ kore_connection_handle(struct connection *c, int flags) u_int32_t len; const u_char *data; - kore_log("kore_connection_handle(%p, %d)", c, flags); + kore_debug("kore_connection_handle(%p, %d)", c, flags); if (flags & EPOLLIN) c->flags |= CONN_READ_POSSIBLE; @@ -356,7 +356,7 @@ kore_connection_handle(struct connection *c, int flags) if (c->ssl == NULL) { c->ssl = SSL_new(ssl_ctx); if (c->ssl == NULL) { - kore_log("SSL_new(): %s", ssl_errno_s); + kore_debug("SSL_new(): %s", ssl_errno_s); return (KORE_RESULT_ERROR); } @@ -371,26 +371,26 @@ kore_connection_handle(struct connection *c, int flags) case SSL_ERROR_WANT_WRITE: return (KORE_RESULT_OK); default: - kore_log("SSL_accept(): %s", ssl_errno_s); + kore_debug("SSL_accept(): %s", ssl_errno_s); return (KORE_RESULT_ERROR); } } r = SSL_get_verify_result(c->ssl); if (r != X509_V_OK) { - kore_log("SSL_get_verify_result(): %s", ssl_errno_s); + kore_debug("SSL_get_verify_result(): %s", ssl_errno_s); return (KORE_RESULT_ERROR); } SSL_get0_next_proto_negotiated(c->ssl, &data, &len); if (data) { if (!memcmp(data, "spdy/3", 6)) - kore_log("using SPDY/3"); + kore_debug("using SPDY/3"); c->proto = CONN_PROTO_SPDY; net_recv_queue(c, SPDY_FRAME_SIZE, 0, NULL, spdy_frame_recv); } else { - kore_log("using HTTP/1.1"); + kore_debug("using HTTP/1.1"); c->proto = CONN_PROTO_HTTP; net_recv_queue(c, HTTP_HEADER_MAX_LEN, NETBUF_CALL_CB_ALWAYS, NULL, @@ -413,7 +413,7 @@ kore_connection_handle(struct connection *c, int flags) case CONN_STATE_DISCONNECTING: break; default: - kore_log("unknown state on %d (%d)", c->fd, c->state); + kore_debug("unknown state on %d (%d)", c->fd, c->state); break; } @@ -428,10 +428,10 @@ kore_worker_init(void) if (worker_count == 0) fatal("no workers specified"); - kore_log("kore_worker_init(): system has %d cpu's", cpu_count); - kore_log("kore_worker_init(): starting %d workers", worker_count); + kore_debug("kore_worker_init(): system has %d cpu's", cpu_count); + kore_debug("kore_worker_init(): starting %d workers", worker_count); if (worker_count > cpu_count) - kore_log("kore_worker_init(): more workers then cpu's"); + kore_debug("kore_worker_init(): more workers then cpu's"); cpu = 0; TAILQ_INIT(&kore_workers); @@ -477,7 +477,7 @@ kore_worker_wait(int final) else r = waitid(P_ALL, 0, &info, WEXITED | WNOHANG); if (r == -1) { - kore_log("waitid(): %s", errno_s); + kore_debug("waitid(): %s", errno_s); return; } @@ -491,7 +491,7 @@ kore_worker_wait(int final) cpu = kw->cpu; TAILQ_REMOVE(&kore_workers, kw, list); - kore_log("worker %d (%d)-> status %d (%d)", + kore_debug("worker %d (%d)-> status %d (%d)", kw->id, info.si_pid, info.si_status, info.si_code); free(kw); @@ -501,7 +501,7 @@ kore_worker_wait(int final) if (info.si_code == CLD_EXITED || info.si_code == CLD_KILLED || info.si_code == CLD_DUMPED) { - kore_log("worker gone, respawning new one"); + kore_debug("worker gone, respawning new one"); kore_worker_spawn(cpu); } } @@ -515,9 +515,9 @@ kore_worker_setcpu(struct kore_worker *kw) CPU_ZERO(&cpuset); CPU_SET(kw->cpu, &cpuset); if (sched_setaffinity(0, sizeof(cpu_set_t), &cpuset) == -1) { - kore_log("kore_worker_setcpu(): %s", errno_s); + kore_debug("kore_worker_setcpu(): %s", errno_s); } else { - kore_log("kore_worker_setcpu(): worker %d on cpu %d", + kore_debug("kore_worker_setcpu(): worker %d on cpu %d", kw->id, kw->cpu); } } @@ -577,7 +577,7 @@ kore_worker_entry(struct kore_worker *kw) } if (n > 0) - kore_log("main(): %d sockets available", n); + kore_debug("main(): %d sockets available", n); for (i = 0; i < n; i++) { fd = (int *)events[i].data.ptr; @@ -626,7 +626,7 @@ kore_worker_entry(struct kore_worker *kw) kore_server_final_disconnect(c); } - kore_log("worker %d shutting down", kw->id); + kore_debug("worker %d shutting down", kw->id); exit(0); } @@ -635,16 +635,16 @@ kore_socket_nonblock(int fd) { int flags; - kore_log("kore_socket_nonblock(%d)", fd); + kore_debug("kore_socket_nonblock(%d)", fd); if ((flags = fcntl(fd, F_GETFL, 0)) == -1) { - kore_log("fcntl(): F_GETFL %s", errno_s); + kore_debug("fcntl(): F_GETFL %s", errno_s); return (KORE_RESULT_ERROR); } flags |= O_NONBLOCK; if (fcntl(fd, F_SETFL, flags) == -1) { - kore_log("fcntl(): F_SETFL %s", errno_s); + kore_debug("fcntl(): F_SETFL %s", errno_s); return (KORE_RESULT_ERROR); } @@ -654,7 +654,7 @@ kore_socket_nonblock(int fd) static int kore_ssl_npn_cb(SSL *ssl, const u_char **data, unsigned int *len, void *arg) { - kore_log("kore_ssl_npn_cb(): sending protocols"); + kore_debug("kore_ssl_npn_cb(): sending protocols"); *data = (const unsigned char *)KORE_SSL_PROTO_STRING; *len = strlen(KORE_SSL_PROTO_STRING); @@ -667,7 +667,7 @@ kore_event(int fd, int flags, void *udata) { struct epoll_event evt; - kore_log("kore_event(%d, %d, %p)", fd, flags, udata); + kore_debug("kore_event(%d, %d, %p)", fd, flags, udata); evt.events = flags; evt.data.ptr = udata; diff --git a/src/module.c b/src/module.c @@ -60,7 +60,7 @@ kore_module_load(char *module_name) struct stat st; void (*onload)(void); - kore_log("kore_module_load(%s)", module_name); + kore_debug("kore_module_load(%s)", module_name); if (mod_handle != NULL) fatal("site module already loaded, skipping %s", module_name); @@ -113,7 +113,7 @@ kore_module_reload(void) onload(); } - kore_log("reloaded '%s' module", mod_name); + kore_debug("reloaded '%s' module", mod_name); } int @@ -145,12 +145,12 @@ kore_module_handler_new(char *path, char *domain, char *func, int type) struct module_domain *dom; struct kore_module_handle *hdlr; - kore_log("kore_module_handler_new(%s, %s, %s, %d)", path, + kore_debug("kore_module_handler_new(%s, %s, %s, %d)", path, domain, func, type); addr = dlsym(mod_handle, func); if (addr == NULL) { - kore_log("function '%s' not found", func); + kore_debug("function '%s' not found", func); return (KORE_RESULT_ERROR); } @@ -168,7 +168,7 @@ kore_module_handler_new(char *path, char *domain, char *func, int type) free(hdlr->func); free(hdlr->path); free(hdlr); - kore_log("regcomp() on %s failed", path); + kore_debug("regcomp() on %s failed", path); return (KORE_RESULT_ERROR); } } diff --git a/src/net.c b/src/net.c @@ -44,7 +44,7 @@ net_send_queue(struct connection *c, u_int8_t *data, size_t len, int flags, { struct netbuf *nb; - //kore_log("net_send_queue(%p, %p, %d, %p)", c, data, len, cb); + //kore_debug("net_send_queue(%p, %p, %d, %p)", c, data, len, cb); nb = (struct netbuf *)kore_malloc(sizeof(*nb)); nb->cb = cb; @@ -72,7 +72,7 @@ net_recv_queue(struct connection *c, size_t len, int flags, { struct netbuf *nb; - //kore_log("net_recv_queue(%p, %d, %p)", c, len, cb); + //kore_debug("net_recv_queue(%p, %d, %p)", c, len, cb); nb = (struct netbuf *)kore_malloc(sizeof(*nb)); nb->cb = cb; @@ -92,10 +92,10 @@ int net_recv_expand(struct connection *c, struct netbuf *nb, size_t len, int (*cb)(struct netbuf *)) { - //kore_log("net_recv_expand(%p, %p, %d, %p)", c, nb, len, cb); + //kore_debug("net_recv_expand(%p, %p, %d, %p)", c, nb, len, cb); if (nb->type != NETBUF_RECV) { - kore_log("net_recv_expand(): wrong netbuf type"); + kore_debug("net_recv_expand(): wrong netbuf type"); return (KORE_RESULT_ERROR); } @@ -118,13 +118,13 @@ net_send(struct connection *c) nb = TAILQ_FIRST(&(c->send_queue)); if (nb->len == 0) { - kore_log("net_send(): len is 0"); + kore_debug("net_send(): len is 0"); return (KORE_RESULT_ERROR); } r = SSL_write(c->ssl, (nb->buf + nb->offset), (nb->len - nb->offset)); - kore_log("net_send(%ld/%ld bytes), progress with %d", + kore_debug("net_send(%ld/%ld bytes), progress with %d", nb->offset, nb->len, r); if (r <= 0) { @@ -135,7 +135,7 @@ net_send(struct connection *c) c->flags &= ~CONN_WRITE_POSSIBLE; return (KORE_RESULT_OK); default: - kore_log("SSL_write(): %s", ssl_errno_s); + kore_debug("SSL_write(): %s", ssl_errno_s); return (KORE_RESULT_ERROR); } } @@ -165,7 +165,7 @@ net_send(struct connection *c) int net_send_flush(struct connection *c) { - kore_log("net_send_flush(%p)", c); + kore_debug("net_send_flush(%p)", c); while (!TAILQ_EMPTY(&(c->send_queue)) && (c->flags & CONN_WRITE_POSSIBLE)) { @@ -188,7 +188,7 @@ net_recv(struct connection *c) nb = TAILQ_FIRST(&(c->recv_queue)); r = SSL_read(c->ssl, (nb->buf + nb->offset), (nb->len - nb->offset)); - kore_log("net_recv(%ld/%ld bytes), progress with %d", + kore_debug("net_recv(%ld/%ld bytes), progress with %d", nb->offset, nb->len, r); if (r <= 0) { @@ -199,7 +199,7 @@ net_recv(struct connection *c) c->flags &= ~CONN_READ_POSSIBLE; return (KORE_RESULT_OK); default: - kore_log("SSL_read(): %s", ssl_errno_s); + kore_debug("SSL_read(): %s", ssl_errno_s); return (KORE_RESULT_ERROR); } } @@ -207,7 +207,7 @@ net_recv(struct connection *c) nb->offset += (size_t)r; if (nb->offset == nb->len || (nb->flags & NETBUF_CALL_CB_ALWAYS)) { if (nb->cb == NULL) { - kore_log("kore_read_client(): nb->cb == NULL"); + kore_debug("kore_read_client(): nb->cb == NULL"); return (KORE_RESULT_ERROR); } @@ -231,7 +231,7 @@ net_recv(struct connection *c) int net_recv_flush(struct connection *c) { - kore_log("net_recv_flush(%p)", c); + kore_debug("net_recv_flush(%p)", c); while (!TAILQ_EMPTY(&(c->recv_queue)) && (c->flags & CONN_READ_POSSIBLE)) { diff --git a/src/spdy.c b/src/spdy.c @@ -60,23 +60,23 @@ spdy_frame_recv(struct netbuf *nb) int (*cb)(struct netbuf *), r; struct connection *c = (struct connection *)nb->owner; - kore_log("spdy_frame_recv(%p)", nb); + kore_debug("spdy_frame_recv(%p)", nb); if (SPDY_CONTROL_FRAME(net_read32(nb->buf))) { - kore_log("received control frame"); + kore_debug("received control frame"); ctrl.version = net_read16(nb->buf) & 0x7fff; ctrl.type = net_read16(nb->buf + 2); ctrl.flags = *(u_int8_t *)(nb->buf + 4); ctrl.length = net_read32(nb->buf + 4) & 0xffffff; - kore_log("type is %d", ctrl.type); - kore_log("version is %d", ctrl.version); - kore_log("length is %d", ctrl.length); - kore_log("flags are %d", ctrl.flags); + kore_debug("type is %d", ctrl.type); + kore_debug("version is %d", ctrl.version); + kore_debug("length is %d", ctrl.length); + kore_debug("flags are %d", ctrl.flags); if (ctrl.version != 3) { - kore_log("protocol mismatch (recv version %d)", + kore_debug("protocol mismatch (recv version %d)", ctrl.version); return (KORE_RESULT_ERROR); } @@ -102,16 +102,16 @@ spdy_frame_recv(struct netbuf *nb) if (cb != NULL) { r = net_recv_expand(c, nb, ctrl.length, cb); } else { - kore_log("no callback for type %d", ctrl.type); + kore_debug("no callback for type %d", ctrl.type); r = KORE_RESULT_OK; } } else { data.stream_id = net_read32(nb->buf) & ~(1 << 31); if ((s = spdy_stream_lookup(c, data.stream_id)) == NULL) { - kore_log("received data frame for non existing stream"); + kore_debug("received data frame for non existing stream"); r = KORE_RESULT_ERROR; } else if (s->flags & FLAG_FIN) { - kore_log("received data frame but FLAG_FIN was set"); + kore_debug("received data frame but FLAG_FIN was set"); r = KORE_RESULT_ERROR; } else { data.flags = *(u_int8_t *)(nb->buf + 4); @@ -137,7 +137,7 @@ spdy_frame_send(struct connection *c, u_int16_t type, u_int8_t flags, u_int8_t nb[12]; u_int32_t length; - kore_log("spdy_frame_send(%p, %d, %d, %d, %p, %d)", + kore_debug("spdy_frame_send(%p, %d, %d, %d, %p, %d)", c, type, flags, len, s, misc); length = 0; @@ -194,7 +194,7 @@ spdy_header_block_create(int delayed_alloc) { struct spdy_header_block *hblock; - kore_log("spdy_header_block_create()"); + kore_debug("spdy_header_block_create()"); hblock = (struct spdy_header_block *)kore_malloc(sizeof(*hblock)); if (delayed_alloc == SPDY_HBLOCK_NORMAL) { @@ -218,7 +218,7 @@ spdy_header_block_add(struct spdy_header_block *hblock, char *name, char *value) u_int8_t *p; u_int32_t nlen, vlen; - kore_log("spdy_header_block_add(%p, %s, %s)", hblock, name, value); + kore_debug("spdy_header_block_add(%p, %s, %s)", hblock, name, value); nlen = strlen(name); vlen = strlen(value); @@ -248,7 +248,7 @@ spdy_header_block_release(struct connection *c, { u_int8_t *deflated; - kore_log("spdy_header_block_release(%p, %p)", hblock, len); + kore_debug("spdy_header_block_release(%p, %p)", hblock, len); net_write32(hblock->header_block, hblock->header_pairs); if (!spdy_zlib_deflate(c, hblock->header_block, hblock->header_offset, @@ -271,33 +271,33 @@ spdy_stream_get_header(struct spdy_header_block *s, char *header, char **out) u_int8_t *p, *end; u_int32_t i, nlen, vlen; - kore_log("spdy_stream_get_header(%p, %s) <%d>", s, header, + kore_debug("spdy_stream_get_header(%p, %s) <%d>", s, header, s->header_pairs); p = s->header_block + 4; end = s->header_block + s->header_block_len; if (p >= end) { - kore_log("p >= end when looking for headers"); + kore_debug("p >= end when looking for headers"); return (KORE_RESULT_ERROR); } for (i = 0; i < s->header_pairs; i++) { nlen = net_read32(p); if ((p + nlen + 4) > end) { - kore_log("nlen out of bounds on %d (%d)", i, nlen); + kore_debug("nlen out of bounds on %d (%d)", i, nlen); return (KORE_RESULT_ERROR); } vlen = net_read32(p + nlen + 4); if ((p + nlen + vlen + 8) > end) { - kore_log("vlen out of bounds on %d (%d)", i, vlen); + kore_debug("vlen out of bounds on %d (%d)", i, vlen); return (KORE_RESULT_ERROR); } cmp = (char *)(p + 4); if (!strncasecmp(cmp, header, nlen)) { - kore_log("found %s header", header); + kore_debug("found %s header", header); cmp = (char *)(p + nlen + 8); *out = (char *)kore_malloc(vlen + 1); @@ -305,7 +305,7 @@ spdy_stream_get_header(struct spdy_header_block *s, char *header, char **out) return (KORE_RESULT_OK); } - kore_log("pair name %d bytes, value %d bytes", nlen, vlen); + kore_debug("pair name %d bytes, value %d bytes", nlen, vlen); p += nlen + vlen + 8; } @@ -333,26 +333,26 @@ spdy_ctrl_frame_syn_stream(struct netbuf *nb) syn.prio = net_read16(nb->buf + 16) & 0xe000; syn.slot = net_read16(nb->buf + 16) & 0x7; - kore_log("spdy_ctrl_frame_syn_stream()"); - kore_log("stream_id: %d", syn.stream_id); - kore_log("length : %d", ctrl.length); + kore_debug("spdy_ctrl_frame_syn_stream()"); + kore_debug("stream_id: %d", syn.stream_id); + kore_debug("length : %d", ctrl.length); /* XXX need to send protocol error. */ if ((syn.stream_id % 2) == 0 || syn.stream_id == 0) { - kore_log("client sent incorrect id for SPDY_SYN_STREAM (%d)", + kore_debug("client sent incorrect id for SPDY_SYN_STREAM (%d)", syn.stream_id); return (KORE_RESULT_ERROR); } /* XXX need to send protocol error. */ if (syn.stream_id < c->client_stream_id) { - kore_log("client sent incorrect id SPDY_SYN_STREAM (%d < %d)", + kore_debug("client sent incorrect id SPDY_SYN_STREAM (%d < %d)", syn.stream_id, c->client_stream_id); return (KORE_RESULT_ERROR); } if ((s = spdy_stream_lookup(c, syn.stream_id)) != NULL) { - kore_log("duplicate SPDY_SYN_STREAM (%d)", syn.stream_id); + kore_debug("duplicate SPDY_SYN_STREAM (%d)", syn.stream_id); return (KORE_RESULT_ERROR); } @@ -363,7 +363,7 @@ spdy_ctrl_frame_syn_stream(struct netbuf *nb) s->hblock = spdy_header_block_create(SPDY_HBLOCK_DELAYED_ALLOC); src = (nb->buf + SPDY_FRAME_SIZE + SPDY_SYNFRAME_SIZE); - kore_log("compressed headers are %d bytes long", ctrl.length - 10); + kore_debug("compressed headers are %d bytes long", ctrl.length - 10); if (!spdy_zlib_inflate(c, src, (ctrl.length - SPDY_SYNFRAME_SIZE), &(s->hblock->header_block), &(s->hblock->header_block_len))) { free(s->hblock->header_block); @@ -373,7 +373,7 @@ spdy_ctrl_frame_syn_stream(struct netbuf *nb) } s->hblock->header_pairs = net_read32(s->hblock->header_block); - kore_log("got %d headers", s->hblock->header_pairs); + kore_debug("got %d headers", s->hblock->header_pairs); path = NULL; host = NULL; @@ -384,7 +384,7 @@ spdy_ctrl_frame_syn_stream(struct netbuf *nb) free(s->hblock->header_block); \ free(s->hblock); \ free(s); \ - kore_log("no such header: %s", n); \ + kore_debug("no such header: %s", n); \ if (path != NULL) \ free(path); \ if (host != NULL) \ @@ -415,7 +415,7 @@ spdy_ctrl_frame_syn_stream(struct netbuf *nb) c->client_stream_id = s->stream_id; TAILQ_INSERT_TAIL(&(c->spdy_streams), s, list); - kore_log("SPDY_SYN_STREAM: %d:%d:%d", s->stream_id, s->flags, s->prio); + kore_debug("SPDY_SYN_STREAM: %d:%d:%d", s->stream_id, s->flags, s->prio); return (KORE_RESULT_OK); } @@ -423,7 +423,7 @@ spdy_ctrl_frame_syn_stream(struct netbuf *nb) static int spdy_ctrl_frame_settings(struct netbuf *nb) { - kore_log("SPDY_SETTINGS (to be implemented)"); + kore_debug("SPDY_SETTINGS (to be implemented)"); return (KORE_RESULT_OK); } @@ -435,11 +435,11 @@ spdy_ctrl_frame_ping(struct netbuf *nb) struct connection *c = (struct connection *)nb->owner; id = ntohl(*(u_int32_t *)(nb->buf + SPDY_FRAME_SIZE)); - kore_log("SPDY_PING: %d", id); + kore_debug("SPDY_PING: %d", id); /* XXX todo - check if we sent the ping. */ if ((id % 2) == 0) { - kore_log("received malformed client PING (%d)", id); + kore_debug("received malformed client PING (%d)", id); return (KORE_RESULT_ERROR); } @@ -455,7 +455,7 @@ spdy_ctrl_frame_window(struct netbuf *nb) stream_id = net_read32(nb->buf + SPDY_FRAME_SIZE); window_size = net_read32(nb->buf + SPDY_FRAME_SIZE + 4); - kore_log("SPDY_WINDOW_UPDATE: %d:%d", stream_id, window_size); + kore_debug("SPDY_WINDOW_UPDATE: %d:%d", stream_id, window_size); return (KORE_RESULT_OK); } @@ -470,17 +470,17 @@ spdy_data_frame_recv(struct netbuf *nb) data.stream_id = net_read32(nb->buf) & ~(1 << 31); data.flags = *(u_int8_t *)(nb->buf + 4); data.length = net_read32(nb->buf + 4) & 0xffffff; - kore_log("SPDY_SESSION_DATA: %d:%d:%d", data.stream_id, + kore_debug("SPDY_SESSION_DATA: %d:%d:%d", data.stream_id, data.flags, data.length); if ((s = spdy_stream_lookup(c, data.stream_id)) == NULL) { - kore_log("session data for incorrect stream"); + kore_debug("session data for incorrect stream"); return (KORE_RESULT_OK); } req = (struct http_request *)s->httpreq; if (req->method != HTTP_METHOD_POST) { - kore_log("data frame for non post received"); + kore_debug("data frame for non post received"); return (KORE_RESULT_ERROR); } @@ -500,7 +500,7 @@ spdy_data_frame_recv(struct netbuf *nb) static void spdy_stream_close(struct connection *c, struct spdy_stream *s) { - kore_log("spdy_stream_close(%p, %p) <%d>", c, s, s->stream_id); + kore_debug("spdy_stream_close(%p, %p) <%d>", c, s, s->stream_id); TAILQ_REMOVE(&(c->spdy_streams), s, list); if (s->hblock != NULL) { @@ -520,7 +520,7 @@ spdy_zlib_inflate(struct connection *c, u_int8_t *src, size_t len, int r, ret; u_char inflate_buffer[SPDY_ZLIB_CHUNK]; - kore_log("spdy_zlib_inflate(%p, %p, %d)", c, src, len); + kore_debug("spdy_zlib_inflate(%p, %p, %d)", c, src, len); if (c->inflate_started == 0) { c->z_inflate.avail_in = 0; @@ -528,7 +528,7 @@ spdy_zlib_inflate(struct connection *c, u_int8_t *src, size_t len, c->z_inflate.zalloc = Z_NULL; c->z_inflate.zfree = Z_NULL; if ((r = inflateInit(&(c->z_inflate))) != Z_OK) { - kore_log("inflateInit() failed: %d", r); + kore_debug("inflateInit() failed: %d", r); return (KORE_RESULT_ERROR); } @@ -552,7 +552,7 @@ spdy_zlib_inflate(struct connection *c, u_int8_t *src, size_t len, SPDY_dictionary_txt, SPDY_ZLIB_DICT_SIZE); if (r != Z_OK) { inflateEnd(&(c->z_inflate)); - kore_log("inflateSetDictionary(): %d", r); + kore_debug("inflateSetDictionary(): %d", r); return (KORE_RESULT_ERROR); } @@ -561,7 +561,7 @@ spdy_zlib_inflate(struct connection *c, u_int8_t *src, size_t len, case Z_DATA_ERROR: case Z_MEM_ERROR: ret = KORE_RESULT_ERROR; - kore_log("inflate(): %d", r); + kore_debug("inflate(): %d", r); break; case Z_OK: have = SPDY_ZLIB_CHUNK - c->z_inflate.avail_out; @@ -590,7 +590,7 @@ spdy_zlib_deflate(struct connection *c, u_int8_t *src, size_t len, int r, ret; u_char deflate_buffer[SPDY_ZLIB_CHUNK]; - kore_log("spdy_zlib_deflate(%p, %p, %d)", c, src, len); + kore_debug("spdy_zlib_deflate(%p, %p, %d)", c, src, len); if (c->deflate_started == 0) { c->z_deflate.avail_in = 0; @@ -598,7 +598,7 @@ spdy_zlib_deflate(struct connection *c, u_int8_t *src, size_t len, c->z_deflate.zalloc = Z_NULL; c->z_deflate.zfree = Z_NULL; if ((r = deflateInit(&(c->z_deflate), -1)) != Z_OK) { - kore_log("deflateInit() failed: %d", r); + kore_debug("deflateInit() failed: %d", r); return (KORE_RESULT_ERROR); } @@ -606,7 +606,7 @@ spdy_zlib_deflate(struct connection *c, u_int8_t *src, size_t len, SPDY_ZLIB_DICT_SIZE); if (r != Z_OK) { deflateEnd(&(c->z_deflate)); - kore_log("delfateSetDictionary(): %d", r); + kore_debug("delfateSetDictionary(): %d", r); return (KORE_RESULT_ERROR); } @@ -629,7 +629,7 @@ spdy_zlib_deflate(struct connection *c, u_int8_t *src, size_t len, case Z_DATA_ERROR: case Z_MEM_ERROR: ret = KORE_RESULT_ERROR; - kore_log("deflate(): %d", r); + kore_debug("deflate(): %d", r); break; case Z_OK: have = SPDY_ZLIB_CHUNK - c->z_deflate.avail_out; diff --git a/src/utils.c b/src/utils.c @@ -103,7 +103,7 @@ kore_strdup(const char *str) } void -kore_log_internal(char *file, int line, const char *fmt, ...) +kore_debug_internal(char *file, int line, const char *fmt, ...) { va_list args; char buf[2048]; @@ -196,13 +196,13 @@ kore_date_to_time(char *http_date) t = KORE_RESULT_ERROR; if (kore_split_string(sdup, " ", args, 7) != 6) { - kore_log("misformed http-date: '%s'", http_date); + kore_debug("misformed http-date: '%s'", http_date); goto out; } tm.tm_year = kore_strtonum(args[3], 2013, 2068, &err) - 1900; if (err == KORE_RESULT_ERROR || tm.tm_year < gtm->tm_year) { - kore_log("misformed year in http-date: '%s'", http_date); + kore_debug("misformed year in http-date: '%s'", http_date); goto out; } @@ -214,43 +214,43 @@ kore_date_to_time(char *http_date) } if (month_names[i].name == NULL) { - kore_log("misformed month in http-date: '%s'", http_date); + kore_debug("misformed month in http-date: '%s'", http_date); goto out; } tm.tm_mday = kore_strtonum(args[1], 1, 31, &err); if (err == KORE_RESULT_ERROR) { - kore_log("misformed mday in http-date: '%s'", http_date); + kore_debug("misformed mday in http-date: '%s'", http_date); goto out; } if (kore_split_string(args[4], ":", tbuf, 5) != 3) { - kore_log("misformed HH:MM:SS in http-date: '%s'", http_date); + kore_debug("misformed HH:MM:SS in http-date: '%s'", http_date); goto out; } tm.tm_hour = kore_strtonum(tbuf[0], 1, 23, &err); if (err == KORE_RESULT_ERROR) { - kore_log("misformed hour in http-date: '%s'", http_date); + kore_debug("misformed hour in http-date: '%s'", http_date); goto out; } tm.tm_min = kore_strtonum(tbuf[1], 1, 59, &err); if (err == KORE_RESULT_ERROR) { - kore_log("misformed minutes in http-date: '%s'", http_date); + kore_debug("misformed minutes in http-date: '%s'", http_date); goto out; } tm.tm_sec = kore_strtonum(tbuf[2], 0, 60, &err); if (err == KORE_RESULT_ERROR) { - kore_log("misformed seconds in http-date: '%s'", http_date); + kore_debug("misformed seconds in http-date: '%s'", http_date); goto out; } t = mktime(&tm); if (t == -1) { t = 0; - kore_log("mktime() on '%s' failed", http_date); + kore_debug("mktime() on '%s' failed", http_date); } out: @@ -270,7 +270,7 @@ kore_time_to_date(time_t now) tm = gmtime(&now); if (!strftime(tbuf, sizeof(tbuf), "%a, %d %b %Y %T GMT", tm)) { - kore_log("strftime() gave us NULL (%ld)", now); + kore_debug("strftime() gave us NULL (%ld)", now); return (NULL); } }