mirror of
https://github.com/jorisvink/kore
synced 2025-03-10 04:59:02 -04:00
Merge branch 'master' of github.com:jorisvink/kore
This commit is contained in:
commit
f56938283d
2
LICENSE
2
LICENSE
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2016 Joris Vink <joris@coders.se>
|
||||
* Copyright (c) 2013-2017 Joris Vink <joris@coders.se>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
|
@ -58,6 +58,9 @@ example_load(int state)
|
||||
switch (state) {
|
||||
case KORE_MODULE_LOAD:
|
||||
kore_log(LOG_NOTICE, "module loading");
|
||||
|
||||
/* Set server version */
|
||||
http_server_version("Server/0.1");
|
||||
break;
|
||||
case KORE_MODULE_UNLOAD:
|
||||
kore_log(LOG_NOTICE, "module unloading");
|
||||
|
@ -8,5 +8,6 @@ workers 4
|
||||
domain 127.0.0.1 {
|
||||
certfile cert/server.crt
|
||||
certkey cert/server.key
|
||||
static / page
|
||||
static / page
|
||||
static /shutdown page_shutdown
|
||||
}
|
||||
|
@ -28,6 +28,7 @@
|
||||
|
||||
int init(int);
|
||||
int page(struct http_request *);
|
||||
int page_shutdown(struct http_request *req);
|
||||
void received_message(struct kore_msg *, const void *);
|
||||
|
||||
/* Initialization callback. */
|
||||
@ -73,3 +74,17 @@ page(struct http_request *req)
|
||||
http_response(req, 200, NULL, 0);
|
||||
return (KORE_RESULT_OK);
|
||||
}
|
||||
|
||||
/*
|
||||
* Page request which will send a message to the parent
|
||||
* requesting process shutdown.
|
||||
*/
|
||||
int
|
||||
page_shutdown(struct http_request *req)
|
||||
{
|
||||
/* Send shutdown request to parent. */
|
||||
kore_msg_send(KORE_MSG_PARENT, KORE_MSG_SHUTDOWN, "1", 1);
|
||||
|
||||
http_response(req, 200, NULL, 0);
|
||||
return (KORE_RESULT_OK);
|
||||
}
|
||||
|
@ -221,6 +221,7 @@ void kore_accesslog(struct http_request *);
|
||||
|
||||
void http_init(void);
|
||||
void http_cleanup(void);
|
||||
void http_server_version(const char *);
|
||||
void http_process(void);
|
||||
const char *http_status_text(int);
|
||||
const char *http_method_text(int);
|
||||
|
@ -417,6 +417,7 @@ struct kore_timer {
|
||||
#define KORE_MSG_WEBSOCKET 2
|
||||
#define KORE_MSG_KEYMGR_REQ 3
|
||||
#define KORE_MSG_KEYMGR_RESP 4
|
||||
#define KORE_MSG_SHUTDOWN 5
|
||||
|
||||
/* Predefined message targets. */
|
||||
#define KORE_MSG_PARENT 1000
|
||||
|
38
src/http.c
38
src/http.c
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2016 Joris Vink <joris@coders.se>
|
||||
* Copyright (c) 2013-2017 Joris Vink <joris@coders.se>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
@ -23,6 +23,8 @@
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
|
||||
#include "kore.h"
|
||||
#include "http.h"
|
||||
@ -118,6 +120,19 @@ http_cleanup(void)
|
||||
kore_pool_cleanup(&http_body_path);
|
||||
}
|
||||
|
||||
void
|
||||
http_server_version(const char *version)
|
||||
{
|
||||
int l;
|
||||
|
||||
l = snprintf(http_version, sizeof(http_version),
|
||||
"server: %s\r\n", version);
|
||||
if (l == -1 || (size_t)l >= sizeof(http_version))
|
||||
fatal("http_server_version(): http_version buffer too small");
|
||||
|
||||
http_version_len = l;
|
||||
}
|
||||
|
||||
int
|
||||
http_request_new(struct connection *c, const char *host,
|
||||
const char *method, const char *path, const char *version,
|
||||
@ -132,11 +147,26 @@ http_request_new(struct connection *c, const char *host,
|
||||
kore_debug("http_request_new(%p, %s, %s, %s, %s)", c, host,
|
||||
method, path, version);
|
||||
|
||||
if ((p = strrchr(host, ':')) != NULL)
|
||||
*p = '\0';
|
||||
switch (c->addrtype) {
|
||||
case AF_INET6:
|
||||
if (*host == '[') {
|
||||
if ((p = strrchr(host, ']')) == NULL) {
|
||||
http_error_response(c, 400);
|
||||
return (KORE_RESULT_ERROR);
|
||||
}
|
||||
p++;
|
||||
if (*p == ':')
|
||||
*p = '\0';
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if ((p = strrchr(host, ':')) != NULL)
|
||||
*p = '\0';
|
||||
break;
|
||||
}
|
||||
|
||||
if ((hostlen = strlen(host)) >= KORE_DOMAINNAME_LEN - 1) {
|
||||
http_error_response(c, 500);
|
||||
http_error_response(c, 400);
|
||||
return (KORE_RESULT_ERROR);
|
||||
}
|
||||
|
||||
|
10
src/msg.c
10
src/msg.c
@ -34,6 +34,7 @@ static int msg_recv_packet(struct netbuf *);
|
||||
static int msg_recv_data(struct netbuf *);
|
||||
static void msg_disconnected_parent(struct connection *);
|
||||
static void msg_disconnected_worker(struct connection *);
|
||||
static void msg_type_shutdown(struct kore_msg *msg, const void *data);
|
||||
|
||||
#if !defined(KORE_NO_HTTP)
|
||||
static void msg_type_accesslog(struct kore_msg *, const void *);
|
||||
@ -57,6 +58,8 @@ kore_msg_parent_init(void)
|
||||
kore_msg_parent_add(kw);
|
||||
}
|
||||
|
||||
kore_msg_register(KORE_MSG_SHUTDOWN, msg_type_shutdown);
|
||||
|
||||
#if !defined(KORE_NO_HTTP)
|
||||
kore_msg_register(KORE_MSG_ACCESSLOG, msg_type_accesslog);
|
||||
#endif
|
||||
@ -207,6 +210,13 @@ msg_disconnected_worker(struct connection *c)
|
||||
c->hdlr_extra = NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
msg_type_shutdown(struct kore_msg *msg, const void *data)
|
||||
{
|
||||
kore_log(LOG_NOTICE, "worker requested shutdown");
|
||||
kore_signal(SIGQUIT);
|
||||
}
|
||||
|
||||
#if !defined(KORE_NO_HTTP)
|
||||
static void
|
||||
msg_type_accesslog(struct kore_msg *msg, const void *data)
|
||||
|
Loading…
x
Reference in New Issue
Block a user