2013-04-17 22:34:27 +02:00
|
|
|
/*
|
2022-01-31 22:02:06 +01:00
|
|
|
* Copyright (c) 2013-2022 Joris Vink <joris@coders.se>
|
2013-04-17 22:34:27 +02:00
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __H_KORE_H
|
|
|
|
#define __H_KORE_H
|
|
|
|
|
2014-04-12 18:49:01 +02:00
|
|
|
#if defined(__APPLE__)
|
|
|
|
#define daemon portability_is_king
|
|
|
|
#endif
|
|
|
|
|
2018-11-29 10:31:14 +01:00
|
|
|
#include <sys/param.h>
|
2019-03-14 19:20:46 +01:00
|
|
|
#include <sys/types.h>
|
2016-01-07 09:20:09 +01:00
|
|
|
#include <sys/time.h>
|
2013-07-06 20:55:22 +02:00
|
|
|
#include <sys/queue.h>
|
2023-01-16 21:00:01 +01:00
|
|
|
#include <sys/stat.h>
|
2018-10-07 20:49:16 +02:00
|
|
|
#include <sys/un.h>
|
2013-07-06 20:55:22 +02:00
|
|
|
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <arpa/inet.h>
|
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
#include <regex.h>
|
2016-01-07 09:20:09 +01:00
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
2019-01-11 11:32:33 +01:00
|
|
|
#include <signal.h>
|
2016-01-07 09:20:09 +01:00
|
|
|
#include <string.h>
|
2013-07-06 20:55:22 +02:00
|
|
|
#include <syslog.h>
|
2013-07-09 09:45:16 +02:00
|
|
|
#include <unistd.h>
|
2016-01-22 12:08:13 +01:00
|
|
|
#include <stdarg.h>
|
2013-07-06 20:55:22 +02:00
|
|
|
|
2015-04-01 13:25:10 +02:00
|
|
|
#if defined(__cplusplus)
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2014-04-12 18:49:01 +02:00
|
|
|
#if defined(__APPLE__)
|
|
|
|
#undef daemon
|
|
|
|
extern int daemon(int, int);
|
2018-07-24 19:56:36 +02:00
|
|
|
#define st_mtim st_mtimespec
|
2014-04-12 18:49:01 +02:00
|
|
|
#endif
|
|
|
|
|
2019-09-27 12:22:35 +02:00
|
|
|
#if !defined(KORE_NO_SENDFILE)
|
2018-06-28 13:27:44 +02:00
|
|
|
#if defined(__MACH__) || defined(__FreeBSD_version) || defined(__linux__)
|
|
|
|
#define KORE_USE_PLATFORM_SENDFILE 1
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2018-07-31 06:51:34 +02:00
|
|
|
#if defined(__OpenBSD__)
|
|
|
|
#define KORE_USE_PLATFORM_PLEDGE 1
|
|
|
|
#endif
|
|
|
|
|
2022-02-18 10:47:05 +01:00
|
|
|
#if defined(TLS_BACKEND_OPENSSL)
|
|
|
|
#include <openssl/x509.h>
|
|
|
|
#include <openssl/ssl.h>
|
|
|
|
typedef X509 KORE_X509;
|
|
|
|
typedef SSL KORE_TLS;
|
|
|
|
typedef SSL_CTX KORE_TLS_CTX;
|
|
|
|
typedef X509_NAME KORE_X509_NAMES;
|
2022-02-18 10:50:17 +01:00
|
|
|
typedef EVP_PKEY KORE_PRIVATE_KEY;
|
2022-02-18 10:47:05 +01:00
|
|
|
#else
|
|
|
|
typedef void KORE_X509;
|
|
|
|
typedef void KORE_TLS;
|
|
|
|
typedef void KORE_TLS_CTX;
|
|
|
|
typedef void KORE_X509_NAMES;
|
2022-02-18 10:50:17 +01:00
|
|
|
typedef void KORE_PRIVATE_KEY;
|
2022-02-18 10:47:05 +01:00
|
|
|
#endif
|
|
|
|
|
2019-11-06 19:33:53 +01:00
|
|
|
#define KORE_RSAKEY_BITS 4096
|
|
|
|
|
2022-08-08 11:02:27 +02:00
|
|
|
/* Kore quit reasons. */
|
|
|
|
#define KORE_QUIT_NONE -1
|
|
|
|
#define KORE_QUIT_NORMAL 0
|
|
|
|
#define KORE_QUIT_FATAL 1
|
|
|
|
|
2013-04-17 22:34:27 +02:00
|
|
|
#define KORE_RESULT_ERROR 0
|
|
|
|
#define KORE_RESULT_OK 1
|
2013-05-31 00:40:06 +02:00
|
|
|
#define KORE_RESULT_RETRY 2
|
2013-04-17 22:34:27 +02:00
|
|
|
|
2018-10-29 20:38:58 +01:00
|
|
|
#define KORE_TLS_VERSION_1_3 0
|
|
|
|
#define KORE_TLS_VERSION_1_2 1
|
2015-05-06 10:59:43 +02:00
|
|
|
#define KORE_TLS_VERSION_BOTH 2
|
|
|
|
|
2019-11-06 19:33:53 +01:00
|
|
|
#define KORE_BASE64_RAW 0x0001
|
|
|
|
|
2019-03-21 10:17:08 +01:00
|
|
|
#define KORE_WAIT_INFINITE (u_int64_t)-1
|
2017-02-28 06:28:35 +01:00
|
|
|
#define KORE_RESEED_TIME (1800 * 1000)
|
|
|
|
|
2013-04-17 22:34:27 +02:00
|
|
|
#define errno_s strerror(errno)
|
2013-04-21 20:21:46 +02:00
|
|
|
#define ssl_errno_s ERR_error_string(ERR_get_error(), NULL)
|
2016-06-08 13:55:14 +02:00
|
|
|
#define KORE_DOMAINNAME_LEN 255
|
2014-08-05 13:10:34 +02:00
|
|
|
#define KORE_PIDFILE_DEFAULT "kore.pid"
|
2021-04-21 10:48:00 +02:00
|
|
|
#define KORE_DHPARAM_PATH PREFIX "/share/kore/ffdhe4096.pem"
|
|
|
|
#define KORE_DEFAULT_CIPHER_LIST "AEAD-AES256-GCM-SHA384:AEAD-CHACHA20-POLY1305-SHA256:AEAD-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256"
|
2013-06-04 16:53:30 +02:00
|
|
|
|
2013-10-26 00:48:09 +02:00
|
|
|
#define NETBUF_RECV 0
|
|
|
|
#define NETBUF_SEND 1
|
2014-08-08 14:18:15 +02:00
|
|
|
#define NETBUF_SEND_PAYLOAD_MAX 8192
|
2018-06-28 13:27:44 +02:00
|
|
|
#define SENDFILE_PAYLOAD_MAX (1024 * 1024 * 10)
|
2014-08-08 14:18:15 +02:00
|
|
|
|
|
|
|
#define NETBUF_LAST_CHAIN 0
|
|
|
|
#define NETBUF_BEFORE_CHAIN 1
|
2013-04-21 20:21:46 +02:00
|
|
|
|
2013-05-02 14:47:02 +02:00
|
|
|
#define NETBUF_CALL_CB_ALWAYS 0x01
|
|
|
|
#define NETBUF_FORCE_REMOVE 0x02
|
2014-08-07 10:22:54 +02:00
|
|
|
#define NETBUF_MUST_RESEND 0x04
|
2014-08-07 14:23:26 +02:00
|
|
|
#define NETBUF_IS_STREAM 0x10
|
2018-06-28 13:27:44 +02:00
|
|
|
#define NETBUF_IS_FILEREF 0x20
|
2013-05-02 14:47:02 +02:00
|
|
|
|
2019-11-19 11:09:24 +01:00
|
|
|
#define KORE_X509_COMMON_NAME_ONLY 0x0001
|
2014-03-05 11:38:47 +01:00
|
|
|
|
2019-11-06 19:33:53 +01:00
|
|
|
#define KORE_PEM_CERT_CHAIN 1
|
|
|
|
#define KORE_DER_CERT_DATA 2
|
|
|
|
|
2014-01-14 21:43:45 +01:00
|
|
|
/* XXX hackish. */
|
2015-11-27 16:22:50 +01:00
|
|
|
#if !defined(KORE_NO_HTTP)
|
2014-01-14 21:43:45 +01:00
|
|
|
struct http_request;
|
2020-02-07 06:42:33 +01:00
|
|
|
struct http_redirect;
|
2015-11-27 16:22:50 +01:00
|
|
|
#endif
|
2014-01-14 21:43:45 +01:00
|
|
|
|
2018-06-28 23:00:42 +02:00
|
|
|
#define KORE_FILEREF_SOFT_REMOVED 0x1000
|
|
|
|
|
2018-06-28 13:27:44 +02:00
|
|
|
struct kore_fileref {
|
|
|
|
int cnt;
|
2018-06-28 23:00:42 +02:00
|
|
|
int flags;
|
2019-09-27 12:22:35 +02:00
|
|
|
int ontls;
|
2018-06-28 13:27:44 +02:00
|
|
|
off_t size;
|
|
|
|
char *path;
|
2018-07-24 19:56:36 +02:00
|
|
|
u_int64_t mtime;
|
|
|
|
time_t mtime_sec;
|
2018-06-28 13:27:44 +02:00
|
|
|
u_int64_t expiration;
|
|
|
|
void *base;
|
2018-06-29 05:03:50 +02:00
|
|
|
int fd;
|
2018-06-28 13:27:44 +02:00
|
|
|
TAILQ_ENTRY(kore_fileref) list;
|
|
|
|
};
|
|
|
|
|
2013-04-17 22:34:27 +02:00
|
|
|
struct netbuf {
|
2013-04-28 19:11:44 +02:00
|
|
|
u_int8_t *buf;
|
2016-07-08 10:02:18 +02:00
|
|
|
size_t s_off;
|
|
|
|
size_t b_len;
|
|
|
|
size_t m_len;
|
2013-04-28 23:42:13 +02:00
|
|
|
u_int8_t type;
|
2013-05-02 00:28:49 +02:00
|
|
|
u_int8_t flags;
|
2013-04-28 23:42:13 +02:00
|
|
|
|
2018-06-28 13:27:44 +02:00
|
|
|
struct kore_fileref *file_ref;
|
|
|
|
off_t fd_off;
|
|
|
|
off_t fd_len;
|
2014-01-14 21:43:45 +01:00
|
|
|
|
2019-09-27 12:22:35 +02:00
|
|
|
struct connection *owner;
|
2013-05-03 07:35:11 +02:00
|
|
|
void *extra;
|
2013-04-17 22:34:27 +02:00
|
|
|
int (*cb)(struct netbuf *);
|
|
|
|
|
|
|
|
TAILQ_ENTRY(netbuf) list;
|
|
|
|
};
|
|
|
|
|
2013-10-25 14:22:29 +02:00
|
|
|
TAILQ_HEAD(netbuf_head, netbuf);
|
|
|
|
|
2013-07-27 20:56:15 +02:00
|
|
|
#define KORE_TYPE_LISTENER 1
|
|
|
|
#define KORE_TYPE_CONNECTION 2
|
2014-03-30 23:54:35 +02:00
|
|
|
#define KORE_TYPE_PGSQL_CONN 3
|
2014-06-28 16:17:18 +02:00
|
|
|
#define KORE_TYPE_TASK 4
|
2018-10-15 20:18:54 +02:00
|
|
|
#define KORE_TYPE_PYSOCKET 5
|
2019-04-24 00:10:47 +02:00
|
|
|
#define KORE_TYPE_CURL_HANDLE 6
|
2013-07-27 20:56:15 +02:00
|
|
|
|
2013-05-02 09:10:35 +02:00
|
|
|
#define CONN_STATE_UNKNOWN 0
|
2017-02-11 21:33:09 +01:00
|
|
|
#define CONN_STATE_TLS_SHAKE 1
|
2013-05-02 09:10:35 +02:00
|
|
|
#define CONN_STATE_ESTABLISHED 2
|
|
|
|
#define CONN_STATE_DISCONNECTING 3
|
2013-04-21 20:21:46 +02:00
|
|
|
|
2013-04-21 20:35:47 +02:00
|
|
|
#define CONN_PROTO_UNKNOWN 0
|
2015-11-27 16:22:50 +01:00
|
|
|
#define CONN_PROTO_HTTP 1
|
|
|
|
#define CONN_PROTO_WEBSOCKET 2
|
|
|
|
#define CONN_PROTO_MSG 3
|
2021-01-05 23:25:29 +01:00
|
|
|
#define CONN_PROTO_ACME_ALPN 200
|
2013-04-21 20:35:47 +02:00
|
|
|
|
2018-10-09 19:34:40 +02:00
|
|
|
#define KORE_EVENT_READ 0x01
|
|
|
|
#define KORE_EVENT_WRITE 0x02
|
|
|
|
#define KORE_EVENT_ERROR 0x04
|
|
|
|
|
2021-01-05 23:25:29 +01:00
|
|
|
#define CONN_IDLE_TIMER_ACT 0x0001
|
|
|
|
#define CONN_CLOSE_EMPTY 0x0002
|
|
|
|
#define CONN_WS_CLOSE_SENT 0x0004
|
|
|
|
#define CONN_IS_BUSY 0x0008
|
|
|
|
#define CONN_LOG_TLS_FAILURE 0x0020
|
|
|
|
#define CONN_TLS_ALPN_ACME_SEEN 0x0040
|
|
|
|
#define CONN_TLS_SNI_SEEN 0x0080
|
2013-07-01 12:08:51 +02:00
|
|
|
|
2018-02-14 13:48:49 +01:00
|
|
|
#define KORE_IDLE_TIMER_MAX 5000
|
2013-05-01 13:43:47 +02:00
|
|
|
|
2014-11-24 11:01:12 +01:00
|
|
|
#define WEBSOCKET_OP_CONT 0x00
|
|
|
|
#define WEBSOCKET_OP_TEXT 0x01
|
|
|
|
#define WEBSOCKET_OP_BINARY 0x02
|
|
|
|
#define WEBSOCKET_OP_CLOSE 0x08
|
|
|
|
#define WEBSOCKET_OP_PING 0x09
|
2017-01-30 22:17:47 +01:00
|
|
|
#define WEBSOCKET_OP_PONG 0x0a
|
2014-11-24 11:01:12 +01:00
|
|
|
|
|
|
|
#define WEBSOCKET_BROADCAST_LOCAL 1
|
|
|
|
#define WEBSOCKET_BROADCAST_GLOBAL 2
|
|
|
|
|
2015-04-06 18:54:35 +02:00
|
|
|
#define KORE_TIMER_ONESHOT 0x01
|
2018-10-23 20:44:43 +02:00
|
|
|
#define KORE_TIMER_FLAGS (KORE_TIMER_ONESHOT)
|
2015-04-06 18:54:35 +02:00
|
|
|
|
2015-06-22 21:13:32 +02:00
|
|
|
#define KORE_CONNECTION_PRUNE_DISCONNECT 0
|
|
|
|
#define KORE_CONNECTION_PRUNE_ALL 1
|
|
|
|
|
2018-10-09 19:34:40 +02:00
|
|
|
struct kore_event {
|
|
|
|
int type;
|
|
|
|
int flags;
|
|
|
|
void (*handle)(void *, int);
|
|
|
|
} __attribute__((packed));
|
|
|
|
|
2013-04-17 22:34:27 +02:00
|
|
|
struct connection {
|
2018-10-09 19:34:40 +02:00
|
|
|
struct kore_event evt;
|
2013-04-17 22:34:27 +02:00
|
|
|
int fd;
|
2013-06-27 08:43:07 +02:00
|
|
|
u_int8_t state;
|
|
|
|
u_int8_t proto;
|
2019-09-27 12:22:35 +02:00
|
|
|
struct listener *owner;
|
2022-02-18 10:47:05 +01:00
|
|
|
KORE_TLS *tls;
|
|
|
|
KORE_X509 *tls_cert;
|
2019-11-19 11:09:24 +01:00
|
|
|
char *tls_sni;
|
2016-01-07 09:20:09 +01:00
|
|
|
int tls_reneg;
|
2022-02-18 10:20:28 +01:00
|
|
|
|
2019-11-19 11:09:24 +01:00
|
|
|
u_int16_t flags;
|
2013-08-14 15:56:44 +02:00
|
|
|
void *hdlr_extra;
|
2013-04-17 22:34:27 +02:00
|
|
|
|
2015-12-01 20:55:00 +01:00
|
|
|
int (*handle)(struct connection *);
|
2014-09-17 08:25:45 +02:00
|
|
|
void (*disconnect)(struct connection *);
|
2017-03-16 09:54:46 +01:00
|
|
|
int (*read)(struct connection *, size_t *);
|
|
|
|
int (*write)(struct connection *, size_t, size_t *);
|
2014-09-17 08:25:45 +02:00
|
|
|
|
2018-10-07 20:49:16 +02:00
|
|
|
int family;
|
2013-07-27 20:56:15 +02:00
|
|
|
union {
|
|
|
|
struct sockaddr_in ipv4;
|
|
|
|
struct sockaddr_in6 ipv6;
|
2018-10-07 21:03:12 +02:00
|
|
|
struct sockaddr_un sun;
|
2013-07-27 20:56:15 +02:00
|
|
|
} addr;
|
|
|
|
|
2013-07-01 12:08:51 +02:00
|
|
|
struct {
|
|
|
|
u_int64_t length;
|
|
|
|
u_int64_t start;
|
|
|
|
} idle_timer;
|
|
|
|
|
2014-08-07 10:22:54 +02:00
|
|
|
struct netbuf_head send_queue;
|
2014-08-08 14:18:15 +02:00
|
|
|
struct netbuf *snb;
|
|
|
|
struct netbuf *rnb;
|
2013-04-29 23:35:36 +02:00
|
|
|
|
2015-11-27 16:22:50 +01:00
|
|
|
#if !defined(KORE_NO_HTTP)
|
2019-04-11 20:51:49 +02:00
|
|
|
u_int64_t http_start;
|
|
|
|
u_int64_t http_timeout;
|
2017-01-29 22:57:34 +01:00
|
|
|
struct kore_runtime_call *ws_connect;
|
|
|
|
struct kore_runtime_call *ws_message;
|
|
|
|
struct kore_runtime_call *ws_disconnect;
|
2013-09-09 10:59:56 +02:00
|
|
|
TAILQ_HEAD(, http_request) http_requests;
|
2015-11-27 16:22:50 +01:00
|
|
|
#endif
|
2013-05-02 09:10:35 +02:00
|
|
|
|
|
|
|
TAILQ_ENTRY(connection) list;
|
2013-04-17 22:34:27 +02:00
|
|
|
};
|
|
|
|
|
2014-12-03 20:40:44 +01:00
|
|
|
TAILQ_HEAD(connection_list, connection);
|
2015-06-22 21:13:32 +02:00
|
|
|
extern struct connection_list connections;
|
|
|
|
extern struct connection_list disconnected;
|
2014-12-03 20:40:44 +01:00
|
|
|
|
2017-01-12 23:38:51 +01:00
|
|
|
#define KORE_RUNTIME_NATIVE 0
|
|
|
|
#define KORE_RUNTIME_PYTHON 1
|
2023-01-21 23:41:35 +01:00
|
|
|
#define KORE_RUNTIME_LUA 2
|
2017-01-12 23:38:51 +01:00
|
|
|
|
|
|
|
struct kore_runtime {
|
|
|
|
int type;
|
2023-01-16 21:00:01 +01:00
|
|
|
int (*resolve)(const char *, const struct stat *);
|
2017-01-12 23:38:51 +01:00
|
|
|
#if !defined(KORE_NO_HTTP)
|
|
|
|
int (*http_request)(void *, struct http_request *);
|
2021-12-14 23:15:21 +01:00
|
|
|
void (*http_request_free)(void *, struct http_request *);
|
2021-09-17 19:28:06 +02:00
|
|
|
void (*http_body_chunk)(void *,
|
|
|
|
struct http_request *, const void *, size_t);
|
2018-02-14 13:48:49 +01:00
|
|
|
int (*validator)(void *, struct http_request *, const void *);
|
2017-01-29 22:57:34 +01:00
|
|
|
void (*wsconnect)(void *, struct connection *);
|
|
|
|
void (*wsdisconnect)(void *, struct connection *);
|
|
|
|
void (*wsmessage)(void *, struct connection *,
|
|
|
|
u_int8_t, const void *, size_t);
|
2017-01-12 23:38:51 +01:00
|
|
|
#endif
|
2017-01-26 13:26:55 +01:00
|
|
|
void (*execute)(void *);
|
2017-01-12 23:38:51 +01:00
|
|
|
int (*onload)(void *, int);
|
2021-12-22 09:50:26 +01:00
|
|
|
void (*signal)(void *, int);
|
2017-01-12 23:38:51 +01:00
|
|
|
void (*connect)(void *, struct connection *);
|
2018-04-09 12:51:20 +02:00
|
|
|
void (*configure)(void *, int, char **);
|
2017-01-12 23:38:51 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
struct kore_runtime_call {
|
|
|
|
void *addr;
|
|
|
|
struct kore_runtime *runtime;
|
|
|
|
};
|
|
|
|
|
2021-09-15 11:09:52 +02:00
|
|
|
#if !defined(KORE_NO_HTTP)
|
|
|
|
|
|
|
|
struct kore_route_params {
|
|
|
|
char *name;
|
|
|
|
int flags;
|
|
|
|
u_int8_t method;
|
|
|
|
struct kore_validator *validator;
|
|
|
|
|
|
|
|
TAILQ_ENTRY(kore_route_params) list;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct kore_route {
|
|
|
|
char *path;
|
|
|
|
char *func;
|
|
|
|
int type;
|
|
|
|
int errors;
|
2021-09-15 22:16:22 +02:00
|
|
|
int methods;
|
2021-09-15 11:09:52 +02:00
|
|
|
regex_t rctx;
|
|
|
|
struct kore_domain *dom;
|
|
|
|
struct kore_auth *auth;
|
2021-09-15 22:16:22 +02:00
|
|
|
struct kore_runtime_call *rcall;
|
2021-12-14 23:15:21 +01:00
|
|
|
struct kore_runtime_call *on_free;
|
2021-09-15 22:16:22 +02:00
|
|
|
struct kore_runtime_call *on_headers;
|
|
|
|
struct kore_runtime_call *on_body_chunk;
|
|
|
|
|
2021-09-15 11:09:52 +02:00
|
|
|
TAILQ_HEAD(, kore_route_params) params;
|
|
|
|
TAILQ_ENTRY(kore_route) list;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2019-09-27 12:22:35 +02:00
|
|
|
struct kore_domain {
|
|
|
|
u_int16_t id;
|
|
|
|
int logerr;
|
|
|
|
u_int64_t logwarn;
|
|
|
|
int accesslog;
|
|
|
|
|
|
|
|
char *domain;
|
|
|
|
struct kore_buf *logbuf;
|
2019-09-27 20:00:35 +02:00
|
|
|
struct kore_server *server;
|
2019-09-27 12:22:35 +02:00
|
|
|
|
2019-11-06 19:33:53 +01:00
|
|
|
#if defined(KORE_USE_ACME)
|
|
|
|
int acme;
|
|
|
|
int acme_challenge;
|
|
|
|
void *acme_cert;
|
|
|
|
size_t acme_cert_len;
|
|
|
|
#endif
|
2019-09-27 12:22:35 +02:00
|
|
|
char *cafile;
|
|
|
|
char *crlfile;
|
|
|
|
char *certfile;
|
|
|
|
char *certkey;
|
2022-02-18 10:47:05 +01:00
|
|
|
KORE_TLS_CTX *tls_ctx;
|
2019-09-27 12:22:35 +02:00
|
|
|
int x509_verify_depth;
|
|
|
|
#if !defined(KORE_NO_HTTP)
|
2021-09-15 11:09:52 +02:00
|
|
|
TAILQ_HEAD(, kore_route) routes;
|
2020-02-07 06:42:33 +01:00
|
|
|
TAILQ_HEAD(, http_redirect) redirects;
|
2019-09-27 12:22:35 +02:00
|
|
|
#endif
|
|
|
|
TAILQ_ENTRY(kore_domain) list;
|
|
|
|
};
|
|
|
|
|
|
|
|
TAILQ_HEAD(kore_domain_h, kore_domain);
|
|
|
|
|
2017-01-12 23:38:51 +01:00
|
|
|
extern struct kore_runtime kore_native_runtime;
|
|
|
|
|
2015-11-30 16:23:34 +01:00
|
|
|
struct listener {
|
2018-10-09 19:34:40 +02:00
|
|
|
struct kore_event evt;
|
2017-01-12 23:38:51 +01:00
|
|
|
int fd;
|
2018-10-07 20:49:16 +02:00
|
|
|
int family;
|
2019-09-27 20:00:35 +02:00
|
|
|
char *port;
|
|
|
|
char *host;
|
|
|
|
struct kore_server *server;
|
2017-01-12 23:38:51 +01:00
|
|
|
struct kore_runtime_call *connect;
|
2019-09-27 20:00:35 +02:00
|
|
|
|
|
|
|
LIST_ENTRY(listener) list;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct kore_server {
|
|
|
|
int tls;
|
2019-09-27 12:22:35 +02:00
|
|
|
char *name;
|
|
|
|
struct kore_domain_h domains;
|
2019-09-27 20:00:35 +02:00
|
|
|
LIST_HEAD(, listener) listeners;
|
|
|
|
LIST_ENTRY(kore_server) list;
|
2015-11-30 16:23:34 +01:00
|
|
|
};
|
|
|
|
|
2019-09-27 20:00:35 +02:00
|
|
|
LIST_HEAD(kore_server_list, kore_server);
|
2015-11-30 16:23:34 +01:00
|
|
|
|
2015-11-27 16:22:50 +01:00
|
|
|
#if !defined(KORE_NO_HTTP)
|
|
|
|
|
2018-01-16 18:47:50 +01:00
|
|
|
#define KORE_PARAMS_QUERY_STRING 0x0001
|
|
|
|
|
2014-01-22 22:55:10 +01:00
|
|
|
#define KORE_AUTH_TYPE_COOKIE 1
|
2014-01-22 23:11:52 +01:00
|
|
|
#define KORE_AUTH_TYPE_HEADER 2
|
2014-03-01 19:18:30 +01:00
|
|
|
#define KORE_AUTH_TYPE_REQUEST 3
|
2014-01-22 22:55:10 +01:00
|
|
|
|
|
|
|
struct kore_auth {
|
|
|
|
u_int8_t type;
|
|
|
|
char *name;
|
|
|
|
char *value;
|
|
|
|
char *redirect;
|
|
|
|
struct kore_validator *validator;
|
|
|
|
|
|
|
|
TAILQ_ENTRY(kore_auth) list;
|
|
|
|
};
|
2013-05-01 16:03:48 +02:00
|
|
|
|
2014-01-22 22:55:10 +01:00
|
|
|
#define HANDLER_TYPE_STATIC 1
|
|
|
|
#define HANDLER_TYPE_DYNAMIC 2
|
|
|
|
|
2017-01-12 23:38:51 +01:00
|
|
|
#endif /* !KORE_NO_HTTP */
|
2015-11-27 16:22:50 +01:00
|
|
|
|
|
|
|
#define KORE_MODULE_LOAD 1
|
|
|
|
#define KORE_MODULE_UNLOAD 2
|
|
|
|
|
2023-01-21 23:41:35 +01:00
|
|
|
#define KORE_MODULE_NATIVE KORE_RUNTIME_NATIVE
|
|
|
|
#define KORE_MODULE_PYTHON KORE_RUNTIME_PYTHON
|
|
|
|
#define KORE_MODULE_LUA KORE_RUNTIME_LUA
|
2017-01-12 23:38:51 +01:00
|
|
|
|
|
|
|
struct kore_module;
|
|
|
|
|
|
|
|
struct kore_module_functions {
|
|
|
|
void (*free)(struct kore_module *);
|
|
|
|
void (*reload)(struct kore_module *);
|
|
|
|
int (*callback)(struct kore_module *, int);
|
2018-02-14 13:48:49 +01:00
|
|
|
void (*load)(struct kore_module *);
|
2017-01-12 23:38:51 +01:00
|
|
|
void *(*getsym)(struct kore_module *, const char *);
|
|
|
|
};
|
|
|
|
|
2013-12-15 01:11:56 +01:00
|
|
|
struct kore_module {
|
2017-01-12 23:38:51 +01:00
|
|
|
void *handle;
|
|
|
|
char *path;
|
|
|
|
char *onload;
|
|
|
|
int type;
|
|
|
|
struct kore_runtime_call *ocb;
|
2013-12-21 13:37:34 +01:00
|
|
|
|
2017-01-12 23:38:51 +01:00
|
|
|
struct kore_module_functions *fun;
|
|
|
|
struct kore_runtime *runtime;
|
2013-12-15 01:11:56 +01:00
|
|
|
|
|
|
|
TAILQ_ENTRY(kore_module) list;
|
|
|
|
};
|
|
|
|
|
2018-12-22 09:25:00 +01:00
|
|
|
/*
|
|
|
|
* The workers get a 128KB log buffer per worker, and parent will fetch their
|
|
|
|
* logs when it reached at least 75% of that or if its been > 1 second since
|
|
|
|
* it was last synced.
|
|
|
|
*/
|
2018-12-22 10:52:57 +01:00
|
|
|
#define KORE_ACCESSLOG_BUFLEN 131072U
|
|
|
|
#define KORE_ACCESSLOG_SYNC 98304U
|
2018-12-22 09:25:00 +01:00
|
|
|
|
|
|
|
struct kore_alog_header {
|
|
|
|
u_int16_t domain;
|
|
|
|
u_int16_t loglen;
|
|
|
|
} __attribute__((packed));
|
|
|
|
|
Rework worker startup/privsep config.
Starting with the privsep config, this commit changes the following:
- Removes the root, runas, keymgr_root, keymgr_runas, acme_root and
acme_runas configuration options.
Instead these are now configured via a privsep configuration context:
privsep worker {
root /tmp
runas nobody
}
This is also configurable via Python using the new kore.privsep() method:
kore.privsep("worker", root="/tmp", runas="nobody", skip=["chroot"])
Tied into this we also better handle worker startup:
- Per worker process, wait until it signalled it is ready.
- If a worker fails at startup, display its last log lines more clearly.
- Don't start acme process if no domain requires acme.
- Remove each process its individual startup log message in favour
of a generalized one that displays its PID, root and user.
- At startup, log the kore version and built-ins in a nicer way.
- The worker processes now check things they need to start running
before signaling they are ready (such as access to CA certs for
TLS client authentication).
2021-09-07 21:59:22 +02:00
|
|
|
struct kore_privsep {
|
|
|
|
char *root;
|
|
|
|
char *runas;
|
|
|
|
int skip_runas;
|
|
|
|
int skip_chroot;
|
|
|
|
};
|
|
|
|
|
2013-05-30 19:36:42 +02:00
|
|
|
struct kore_worker {
|
2019-11-06 19:33:53 +01:00
|
|
|
u_int16_t id;
|
|
|
|
u_int16_t cpu;
|
Rework worker startup/privsep config.
Starting with the privsep config, this commit changes the following:
- Removes the root, runas, keymgr_root, keymgr_runas, acme_root and
acme_runas configuration options.
Instead these are now configured via a privsep configuration context:
privsep worker {
root /tmp
runas nobody
}
This is also configurable via Python using the new kore.privsep() method:
kore.privsep("worker", root="/tmp", runas="nobody", skip=["chroot"])
Tied into this we also better handle worker startup:
- Per worker process, wait until it signalled it is ready.
- If a worker fails at startup, display its last log lines more clearly.
- Don't start acme process if no domain requires acme.
- Remove each process its individual startup log message in favour
of a generalized one that displays its PID, root and user.
- At startup, log the kore version and built-ins in a nicer way.
- The worker processes now check things they need to start running
before signaling they are ready (such as access to CA certs for
TLS client authentication).
2021-09-07 21:59:22 +02:00
|
|
|
int ready;
|
2020-01-17 21:48:55 +01:00
|
|
|
int running;
|
2019-10-31 12:52:10 +01:00
|
|
|
#if defined(__linux__)
|
|
|
|
int tracing;
|
|
|
|
#endif
|
2013-06-04 11:55:38 +02:00
|
|
|
pid_t pid;
|
2015-06-22 21:13:32 +02:00
|
|
|
int pipe[2];
|
|
|
|
struct connection *msg[2];
|
2013-06-27 08:43:07 +02:00
|
|
|
u_int8_t has_lock;
|
2018-07-11 09:44:29 +02:00
|
|
|
int restarted;
|
2018-02-14 13:48:49 +01:00
|
|
|
u_int64_t time_locked;
|
2021-09-15 11:09:52 +02:00
|
|
|
struct kore_route *active_route;
|
Rework worker startup/privsep config.
Starting with the privsep config, this commit changes the following:
- Removes the root, runas, keymgr_root, keymgr_runas, acme_root and
acme_runas configuration options.
Instead these are now configured via a privsep configuration context:
privsep worker {
root /tmp
runas nobody
}
This is also configurable via Python using the new kore.privsep() method:
kore.privsep("worker", root="/tmp", runas="nobody", skip=["chroot"])
Tied into this we also better handle worker startup:
- Per worker process, wait until it signalled it is ready.
- If a worker fails at startup, display its last log lines more clearly.
- Don't start acme process if no domain requires acme.
- Remove each process its individual startup log message in favour
of a generalized one that displays its PID, root and user.
- At startup, log the kore version and built-ins in a nicer way.
- The worker processes now check things they need to start running
before signaling they are ready (such as access to CA certs for
TLS client authentication).
2021-09-07 21:59:22 +02:00
|
|
|
struct kore_privsep *ps;
|
2018-12-22 09:25:00 +01:00
|
|
|
|
|
|
|
/* Used by the workers to store accesslogs. */
|
|
|
|
struct {
|
|
|
|
int lock;
|
|
|
|
size_t offset;
|
|
|
|
char buf[KORE_ACCESSLOG_BUFLEN];
|
|
|
|
} lb;
|
2013-05-30 19:36:42 +02:00
|
|
|
};
|
|
|
|
|
2015-11-27 16:22:50 +01:00
|
|
|
#if !defined(KORE_NO_HTTP)
|
|
|
|
|
2013-11-09 16:21:52 +01:00
|
|
|
#define KORE_VALIDATOR_TYPE_REGEX 1
|
|
|
|
#define KORE_VALIDATOR_TYPE_FUNCTION 2
|
|
|
|
|
|
|
|
struct kore_validator {
|
2017-01-12 23:38:51 +01:00
|
|
|
u_int8_t type;
|
|
|
|
char *name;
|
|
|
|
char *arg;
|
|
|
|
regex_t rctx;
|
|
|
|
struct kore_runtime_call *rcall;
|
2013-11-09 16:21:52 +01:00
|
|
|
|
|
|
|
TAILQ_ENTRY(kore_validator) list;
|
|
|
|
};
|
2017-01-12 23:38:51 +01:00
|
|
|
#endif /* !KORE_NO_HTTP */
|
2013-11-09 16:21:52 +01:00
|
|
|
|
2016-07-14 12:41:39 +02:00
|
|
|
#define KORE_BUF_OWNER_API 0x0001
|
2013-05-02 15:14:00 +02:00
|
|
|
|
|
|
|
struct kore_buf {
|
|
|
|
u_int8_t *data;
|
2016-07-14 12:41:39 +02:00
|
|
|
int flags;
|
2016-07-08 10:02:18 +02:00
|
|
|
size_t length;
|
|
|
|
size_t offset;
|
2013-05-02 15:14:00 +02:00
|
|
|
};
|
|
|
|
|
2020-11-19 14:56:17 +01:00
|
|
|
#define KORE_JSON_TYPE_OBJECT 0x0001
|
|
|
|
#define KORE_JSON_TYPE_ARRAY 0x0002
|
|
|
|
#define KORE_JSON_TYPE_STRING 0x0004
|
|
|
|
#define KORE_JSON_TYPE_NUMBER 0x0008
|
|
|
|
#define KORE_JSON_TYPE_LITERAL 0x0010
|
|
|
|
#define KORE_JSON_TYPE_INTEGER 0x0020
|
|
|
|
#define KORE_JSON_TYPE_INTEGER_U64 0x0040
|
Add a full native JSON parser to Kore.
Mostly compliant, ignores \uXXXX in strings for now.
New API functions:
void kore_json_init(struct kore_json *json, const u_int8_t *data, size_t len);
- Prepares JSON data for parsing.
int kore_json_parse(struct kore_json *json)
- Parses the JSON data prepared via kore_json_init. Returns KORE_RESULT_ERROR
if parsing failed or KORE_RESULT_OK if it succeeded.
struct kore_json_item *kore_json_get(struct kore_json *json, const char *path,
int type);
- Try to find the object matching a given search patch and type.
eg, given a JSON structure of:
{
"reasons": {
"strings": [
"first reason",
"second"
]
}
}
one can obtain the second element in the reasons.strings array via:
item = kore_json_get(json, "reasons/strings[0]", KORE_JSON_TYPE_STRING);
Returns NULL if the item was not found or a type mismatch was hit,
otherwise will return the item of that type.
The kore_json_item data structure has a data member that contains the
relevant bits depending on the type:
KORE_JSON_TYPE_ARRAY, KORE_JSON_TYPE_OBJECT:
the data.items member is valid.
KORE_JSON_TYPE_STRING:
the data.string member is valid.
KORE_JSON_TYPE_NUMBER:
the data.number member is valid.
KORE_JSON_TYPE_LITERAL:
the data.literal member is valid.
void kore_json_cleanup(struct kore_json *json);
- Cleanup any resources
const char *kore_json_strerror(struct kore_json *json);
- Return pointer to human readable error string.
2019-10-20 23:22:11 +02:00
|
|
|
|
|
|
|
#define KORE_JSON_FALSE 0
|
|
|
|
#define KORE_JSON_TRUE 1
|
|
|
|
#define KORE_JSON_NULL 2
|
|
|
|
|
|
|
|
#define KORE_JSON_DEPTH_MAX 10
|
|
|
|
|
|
|
|
#define KORE_JSON_ERR_NONE 0
|
|
|
|
#define KORE_JSON_ERR_INVALID_OBJECT 1
|
|
|
|
#define KORE_JSON_ERR_INVALID_ARRAY 2
|
|
|
|
#define KORE_JSON_ERR_INVALID_STRING 3
|
|
|
|
#define KORE_JSON_ERR_INVALID_NUMBER 4
|
|
|
|
#define KORE_JSON_ERR_INVALID_LITERAL 5
|
|
|
|
#define KORE_JSON_ERR_DEPTH 6
|
|
|
|
#define KORE_JSON_ERR_EOF 7
|
|
|
|
#define KORE_JSON_ERR_INVALID_JSON 8
|
|
|
|
#define KORE_JSON_ERR_INVALID_SEARCH 9
|
|
|
|
#define KORE_JSON_ERR_NOT_FOUND 10
|
|
|
|
#define KORE_JSON_ERR_TYPE_MISMATCH 11
|
|
|
|
#define KORE_JSON_ERR_LAST KORE_JSON_ERR_TYPE_MISMATCH
|
|
|
|
|
2019-10-22 23:56:47 +02:00
|
|
|
#define kore_json_find_object(j, p) \
|
|
|
|
kore_json_find(j, p, KORE_JSON_TYPE_OBJECT)
|
Add a full native JSON parser to Kore.
Mostly compliant, ignores \uXXXX in strings for now.
New API functions:
void kore_json_init(struct kore_json *json, const u_int8_t *data, size_t len);
- Prepares JSON data for parsing.
int kore_json_parse(struct kore_json *json)
- Parses the JSON data prepared via kore_json_init. Returns KORE_RESULT_ERROR
if parsing failed or KORE_RESULT_OK if it succeeded.
struct kore_json_item *kore_json_get(struct kore_json *json, const char *path,
int type);
- Try to find the object matching a given search patch and type.
eg, given a JSON structure of:
{
"reasons": {
"strings": [
"first reason",
"second"
]
}
}
one can obtain the second element in the reasons.strings array via:
item = kore_json_get(json, "reasons/strings[0]", KORE_JSON_TYPE_STRING);
Returns NULL if the item was not found or a type mismatch was hit,
otherwise will return the item of that type.
The kore_json_item data structure has a data member that contains the
relevant bits depending on the type:
KORE_JSON_TYPE_ARRAY, KORE_JSON_TYPE_OBJECT:
the data.items member is valid.
KORE_JSON_TYPE_STRING:
the data.string member is valid.
KORE_JSON_TYPE_NUMBER:
the data.number member is valid.
KORE_JSON_TYPE_LITERAL:
the data.literal member is valid.
void kore_json_cleanup(struct kore_json *json);
- Cleanup any resources
const char *kore_json_strerror(struct kore_json *json);
- Return pointer to human readable error string.
2019-10-20 23:22:11 +02:00
|
|
|
|
2019-10-22 23:56:47 +02:00
|
|
|
#define kore_json_find_array(j, p) \
|
|
|
|
kore_json_find(j, p, KORE_JSON_TYPE_ARRAY)
|
Add a full native JSON parser to Kore.
Mostly compliant, ignores \uXXXX in strings for now.
New API functions:
void kore_json_init(struct kore_json *json, const u_int8_t *data, size_t len);
- Prepares JSON data for parsing.
int kore_json_parse(struct kore_json *json)
- Parses the JSON data prepared via kore_json_init. Returns KORE_RESULT_ERROR
if parsing failed or KORE_RESULT_OK if it succeeded.
struct kore_json_item *kore_json_get(struct kore_json *json, const char *path,
int type);
- Try to find the object matching a given search patch and type.
eg, given a JSON structure of:
{
"reasons": {
"strings": [
"first reason",
"second"
]
}
}
one can obtain the second element in the reasons.strings array via:
item = kore_json_get(json, "reasons/strings[0]", KORE_JSON_TYPE_STRING);
Returns NULL if the item was not found or a type mismatch was hit,
otherwise will return the item of that type.
The kore_json_item data structure has a data member that contains the
relevant bits depending on the type:
KORE_JSON_TYPE_ARRAY, KORE_JSON_TYPE_OBJECT:
the data.items member is valid.
KORE_JSON_TYPE_STRING:
the data.string member is valid.
KORE_JSON_TYPE_NUMBER:
the data.number member is valid.
KORE_JSON_TYPE_LITERAL:
the data.literal member is valid.
void kore_json_cleanup(struct kore_json *json);
- Cleanup any resources
const char *kore_json_strerror(struct kore_json *json);
- Return pointer to human readable error string.
2019-10-20 23:22:11 +02:00
|
|
|
|
2019-10-22 23:56:47 +02:00
|
|
|
#define kore_json_find_string(j, p) \
|
|
|
|
kore_json_find(j, p, KORE_JSON_TYPE_STRING)
|
Add a full native JSON parser to Kore.
Mostly compliant, ignores \uXXXX in strings for now.
New API functions:
void kore_json_init(struct kore_json *json, const u_int8_t *data, size_t len);
- Prepares JSON data for parsing.
int kore_json_parse(struct kore_json *json)
- Parses the JSON data prepared via kore_json_init. Returns KORE_RESULT_ERROR
if parsing failed or KORE_RESULT_OK if it succeeded.
struct kore_json_item *kore_json_get(struct kore_json *json, const char *path,
int type);
- Try to find the object matching a given search patch and type.
eg, given a JSON structure of:
{
"reasons": {
"strings": [
"first reason",
"second"
]
}
}
one can obtain the second element in the reasons.strings array via:
item = kore_json_get(json, "reasons/strings[0]", KORE_JSON_TYPE_STRING);
Returns NULL if the item was not found or a type mismatch was hit,
otherwise will return the item of that type.
The kore_json_item data structure has a data member that contains the
relevant bits depending on the type:
KORE_JSON_TYPE_ARRAY, KORE_JSON_TYPE_OBJECT:
the data.items member is valid.
KORE_JSON_TYPE_STRING:
the data.string member is valid.
KORE_JSON_TYPE_NUMBER:
the data.number member is valid.
KORE_JSON_TYPE_LITERAL:
the data.literal member is valid.
void kore_json_cleanup(struct kore_json *json);
- Cleanup any resources
const char *kore_json_strerror(struct kore_json *json);
- Return pointer to human readable error string.
2019-10-20 23:22:11 +02:00
|
|
|
|
2019-10-22 23:56:47 +02:00
|
|
|
#define kore_json_find_number(j, p) \
|
|
|
|
kore_json_find(j, p, KORE_JSON_TYPE_NUMBER)
|
Add a full native JSON parser to Kore.
Mostly compliant, ignores \uXXXX in strings for now.
New API functions:
void kore_json_init(struct kore_json *json, const u_int8_t *data, size_t len);
- Prepares JSON data for parsing.
int kore_json_parse(struct kore_json *json)
- Parses the JSON data prepared via kore_json_init. Returns KORE_RESULT_ERROR
if parsing failed or KORE_RESULT_OK if it succeeded.
struct kore_json_item *kore_json_get(struct kore_json *json, const char *path,
int type);
- Try to find the object matching a given search patch and type.
eg, given a JSON structure of:
{
"reasons": {
"strings": [
"first reason",
"second"
]
}
}
one can obtain the second element in the reasons.strings array via:
item = kore_json_get(json, "reasons/strings[0]", KORE_JSON_TYPE_STRING);
Returns NULL if the item was not found or a type mismatch was hit,
otherwise will return the item of that type.
The kore_json_item data structure has a data member that contains the
relevant bits depending on the type:
KORE_JSON_TYPE_ARRAY, KORE_JSON_TYPE_OBJECT:
the data.items member is valid.
KORE_JSON_TYPE_STRING:
the data.string member is valid.
KORE_JSON_TYPE_NUMBER:
the data.number member is valid.
KORE_JSON_TYPE_LITERAL:
the data.literal member is valid.
void kore_json_cleanup(struct kore_json *json);
- Cleanup any resources
const char *kore_json_strerror(struct kore_json *json);
- Return pointer to human readable error string.
2019-10-20 23:22:11 +02:00
|
|
|
|
2020-11-19 14:56:17 +01:00
|
|
|
#define kore_json_find_integer(j, p) \
|
|
|
|
kore_json_find(j, p, KORE_JSON_TYPE_INTEGER)
|
|
|
|
|
|
|
|
#define kore_json_find_integer_u64(j, p) \
|
|
|
|
kore_json_find(j, p, KORE_JSON_TYPE_INTEGER_U64)
|
|
|
|
|
2019-10-22 23:56:47 +02:00
|
|
|
#define kore_json_find_literal(j, p) \
|
|
|
|
kore_json_find(j, p, KORE_JSON_TYPE_LITERAL)
|
|
|
|
|
|
|
|
#define kore_json_create_object(o, n) \
|
|
|
|
kore_json_create_item(o, n, KORE_JSON_TYPE_OBJECT)
|
|
|
|
|
|
|
|
#define kore_json_create_array(o, n) \
|
|
|
|
kore_json_create_item(o, n, KORE_JSON_TYPE_ARRAY)
|
|
|
|
|
|
|
|
#define kore_json_create_string(o, n, v) \
|
|
|
|
kore_json_create_item(o, n, KORE_JSON_TYPE_STRING, v)
|
|
|
|
|
|
|
|
#define kore_json_create_number(o, n, v) \
|
2022-02-20 20:32:39 +01:00
|
|
|
kore_json_create_item(o, n, KORE_JSON_TYPE_NUMBER, (double)v)
|
2019-10-22 23:56:47 +02:00
|
|
|
|
2020-11-19 14:56:17 +01:00
|
|
|
#define kore_json_create_integer(o, n, v) \
|
2022-02-20 20:32:39 +01:00
|
|
|
kore_json_create_item(o, n, KORE_JSON_TYPE_INTEGER, (int64_t)v)
|
2020-11-19 14:56:17 +01:00
|
|
|
|
|
|
|
#define kore_json_create_integer_u64(o, n, v) \
|
2022-02-20 20:32:39 +01:00
|
|
|
kore_json_create_item(o, n, KORE_JSON_TYPE_INTEGER_U64, (u_int64_t)v)
|
2020-11-19 14:56:17 +01:00
|
|
|
|
2019-10-22 23:56:47 +02:00
|
|
|
#define kore_json_create_literal(o, n, v) \
|
|
|
|
kore_json_create_item(o, n, KORE_JSON_TYPE_LITERAL, v)
|
Add a full native JSON parser to Kore.
Mostly compliant, ignores \uXXXX in strings for now.
New API functions:
void kore_json_init(struct kore_json *json, const u_int8_t *data, size_t len);
- Prepares JSON data for parsing.
int kore_json_parse(struct kore_json *json)
- Parses the JSON data prepared via kore_json_init. Returns KORE_RESULT_ERROR
if parsing failed or KORE_RESULT_OK if it succeeded.
struct kore_json_item *kore_json_get(struct kore_json *json, const char *path,
int type);
- Try to find the object matching a given search patch and type.
eg, given a JSON structure of:
{
"reasons": {
"strings": [
"first reason",
"second"
]
}
}
one can obtain the second element in the reasons.strings array via:
item = kore_json_get(json, "reasons/strings[0]", KORE_JSON_TYPE_STRING);
Returns NULL if the item was not found or a type mismatch was hit,
otherwise will return the item of that type.
The kore_json_item data structure has a data member that contains the
relevant bits depending on the type:
KORE_JSON_TYPE_ARRAY, KORE_JSON_TYPE_OBJECT:
the data.items member is valid.
KORE_JSON_TYPE_STRING:
the data.string member is valid.
KORE_JSON_TYPE_NUMBER:
the data.number member is valid.
KORE_JSON_TYPE_LITERAL:
the data.literal member is valid.
void kore_json_cleanup(struct kore_json *json);
- Cleanup any resources
const char *kore_json_strerror(struct kore_json *json);
- Return pointer to human readable error string.
2019-10-20 23:22:11 +02:00
|
|
|
|
|
|
|
struct kore_json {
|
|
|
|
const u_int8_t *data;
|
|
|
|
int depth;
|
|
|
|
size_t length;
|
|
|
|
size_t offset;
|
|
|
|
|
|
|
|
struct kore_buf tmpbuf;
|
|
|
|
struct kore_json_item *root;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct kore_json_item {
|
2020-11-19 14:56:17 +01:00
|
|
|
u_int32_t type;
|
Add a full native JSON parser to Kore.
Mostly compliant, ignores \uXXXX in strings for now.
New API functions:
void kore_json_init(struct kore_json *json, const u_int8_t *data, size_t len);
- Prepares JSON data for parsing.
int kore_json_parse(struct kore_json *json)
- Parses the JSON data prepared via kore_json_init. Returns KORE_RESULT_ERROR
if parsing failed or KORE_RESULT_OK if it succeeded.
struct kore_json_item *kore_json_get(struct kore_json *json, const char *path,
int type);
- Try to find the object matching a given search patch and type.
eg, given a JSON structure of:
{
"reasons": {
"strings": [
"first reason",
"second"
]
}
}
one can obtain the second element in the reasons.strings array via:
item = kore_json_get(json, "reasons/strings[0]", KORE_JSON_TYPE_STRING);
Returns NULL if the item was not found or a type mismatch was hit,
otherwise will return the item of that type.
The kore_json_item data structure has a data member that contains the
relevant bits depending on the type:
KORE_JSON_TYPE_ARRAY, KORE_JSON_TYPE_OBJECT:
the data.items member is valid.
KORE_JSON_TYPE_STRING:
the data.string member is valid.
KORE_JSON_TYPE_NUMBER:
the data.number member is valid.
KORE_JSON_TYPE_LITERAL:
the data.literal member is valid.
void kore_json_cleanup(struct kore_json *json);
- Cleanup any resources
const char *kore_json_strerror(struct kore_json *json);
- Return pointer to human readable error string.
2019-10-20 23:22:11 +02:00
|
|
|
char *name;
|
|
|
|
struct kore_json_item *parent;
|
|
|
|
|
|
|
|
union {
|
|
|
|
TAILQ_HEAD(, kore_json_item) items;
|
|
|
|
char *string;
|
|
|
|
double number;
|
|
|
|
int literal;
|
2021-03-30 14:19:48 +02:00
|
|
|
int64_t integer;
|
2020-11-19 14:56:17 +01:00
|
|
|
u_int64_t u64;
|
Add a full native JSON parser to Kore.
Mostly compliant, ignores \uXXXX in strings for now.
New API functions:
void kore_json_init(struct kore_json *json, const u_int8_t *data, size_t len);
- Prepares JSON data for parsing.
int kore_json_parse(struct kore_json *json)
- Parses the JSON data prepared via kore_json_init. Returns KORE_RESULT_ERROR
if parsing failed or KORE_RESULT_OK if it succeeded.
struct kore_json_item *kore_json_get(struct kore_json *json, const char *path,
int type);
- Try to find the object matching a given search patch and type.
eg, given a JSON structure of:
{
"reasons": {
"strings": [
"first reason",
"second"
]
}
}
one can obtain the second element in the reasons.strings array via:
item = kore_json_get(json, "reasons/strings[0]", KORE_JSON_TYPE_STRING);
Returns NULL if the item was not found or a type mismatch was hit,
otherwise will return the item of that type.
The kore_json_item data structure has a data member that contains the
relevant bits depending on the type:
KORE_JSON_TYPE_ARRAY, KORE_JSON_TYPE_OBJECT:
the data.items member is valid.
KORE_JSON_TYPE_STRING:
the data.string member is valid.
KORE_JSON_TYPE_NUMBER:
the data.number member is valid.
KORE_JSON_TYPE_LITERAL:
the data.literal member is valid.
void kore_json_cleanup(struct kore_json *json);
- Cleanup any resources
const char *kore_json_strerror(struct kore_json *json);
- Return pointer to human readable error string.
2019-10-20 23:22:11 +02:00
|
|
|
} data;
|
|
|
|
|
2022-02-17 13:45:28 +01:00
|
|
|
int (*parse)(struct kore_json *,
|
|
|
|
struct kore_json_item *);
|
Add a full native JSON parser to Kore.
Mostly compliant, ignores \uXXXX in strings for now.
New API functions:
void kore_json_init(struct kore_json *json, const u_int8_t *data, size_t len);
- Prepares JSON data for parsing.
int kore_json_parse(struct kore_json *json)
- Parses the JSON data prepared via kore_json_init. Returns KORE_RESULT_ERROR
if parsing failed or KORE_RESULT_OK if it succeeded.
struct kore_json_item *kore_json_get(struct kore_json *json, const char *path,
int type);
- Try to find the object matching a given search patch and type.
eg, given a JSON structure of:
{
"reasons": {
"strings": [
"first reason",
"second"
]
}
}
one can obtain the second element in the reasons.strings array via:
item = kore_json_get(json, "reasons/strings[0]", KORE_JSON_TYPE_STRING);
Returns NULL if the item was not found or a type mismatch was hit,
otherwise will return the item of that type.
The kore_json_item data structure has a data member that contains the
relevant bits depending on the type:
KORE_JSON_TYPE_ARRAY, KORE_JSON_TYPE_OBJECT:
the data.items member is valid.
KORE_JSON_TYPE_STRING:
the data.string member is valid.
KORE_JSON_TYPE_NUMBER:
the data.number member is valid.
KORE_JSON_TYPE_LITERAL:
the data.literal member is valid.
void kore_json_cleanup(struct kore_json *json);
- Cleanup any resources
const char *kore_json_strerror(struct kore_json *json);
- Return pointer to human readable error string.
2019-10-20 23:22:11 +02:00
|
|
|
|
|
|
|
TAILQ_ENTRY(kore_json_item) list;
|
|
|
|
};
|
|
|
|
|
2013-07-15 10:13:36 +02:00
|
|
|
struct kore_pool_entry {
|
|
|
|
u_int8_t state;
|
2023-01-05 22:47:29 +01:00
|
|
|
void *uptr;
|
|
|
|
void *canary;
|
|
|
|
struct kore_pool_entry *nextfree;
|
2014-04-18 17:41:56 +02:00
|
|
|
};
|
2013-07-15 10:13:36 +02:00
|
|
|
|
|
|
|
struct kore_pool {
|
2023-01-05 22:47:29 +01:00
|
|
|
size_t memsz;
|
2018-10-30 10:36:18 +01:00
|
|
|
size_t growth;
|
2023-01-05 22:47:29 +01:00
|
|
|
size_t pagesz;
|
|
|
|
size_t elmlen;
|
|
|
|
size_t uselen;
|
|
|
|
u_int64_t canary;
|
2016-07-12 16:29:30 +02:00
|
|
|
volatile int lock;
|
2013-07-15 10:13:36 +02:00
|
|
|
char *name;
|
|
|
|
|
2023-01-05 22:47:29 +01:00
|
|
|
struct kore_pool_entry *freelist;
|
2014-04-18 17:41:56 +02:00
|
|
|
};
|
2013-07-15 10:13:36 +02:00
|
|
|
|
2015-05-15 19:11:10 +02:00
|
|
|
struct kore_timer {
|
|
|
|
u_int64_t nextrun;
|
|
|
|
u_int64_t interval;
|
|
|
|
int flags;
|
|
|
|
void *arg;
|
2015-08-06 08:20:41 +02:00
|
|
|
void (*cb)(void *, u_int64_t);
|
2015-05-15 19:11:10 +02:00
|
|
|
|
|
|
|
TAILQ_ENTRY(kore_timer) list;
|
|
|
|
};
|
|
|
|
|
2019-11-06 19:33:53 +01:00
|
|
|
/*
|
|
|
|
* Keymgr process is worker index 0, but id 2000.
|
|
|
|
* Acme process is worker index 1, but id 2001.
|
|
|
|
*/
|
|
|
|
#define KORE_WORKER_KEYMGR_IDX 0
|
|
|
|
#define KORE_WORKER_ACME_IDX 1
|
|
|
|
#define KORE_WORKER_BASE 2
|
|
|
|
#define KORE_WORKER_KEYMGR 2000
|
|
|
|
#define KORE_WORKER_ACME 2001
|
|
|
|
#define KORE_WORKER_MAX UCHAR_MAX
|
|
|
|
|
2019-03-22 09:49:50 +01:00
|
|
|
#define KORE_WORKER_POLICY_RESTART 1
|
|
|
|
#define KORE_WORKER_POLICY_TERMINATE 2
|
2016-06-08 13:55:14 +02:00
|
|
|
|
2015-06-23 18:17:14 +02:00
|
|
|
/* Reserved message ids, registered on workers. */
|
2018-12-22 09:25:00 +01:00
|
|
|
#define KORE_MSG_WEBSOCKET 1
|
|
|
|
#define KORE_MSG_KEYMGR_REQ 2
|
|
|
|
#define KORE_MSG_KEYMGR_RESP 3
|
|
|
|
#define KORE_MSG_SHUTDOWN 4
|
2018-12-22 10:22:59 +01:00
|
|
|
#define KORE_MSG_ENTROPY_REQ 5
|
2018-12-22 09:25:00 +01:00
|
|
|
#define KORE_MSG_ENTROPY_RESP 6
|
|
|
|
#define KORE_MSG_CERTIFICATE 7
|
|
|
|
#define KORE_MSG_CERTIFICATE_REQ 8
|
2019-01-14 11:41:50 +01:00
|
|
|
#define KORE_MSG_CRL 9
|
2019-03-21 14:03:11 +01:00
|
|
|
#define KORE_MSG_ACCEPT_AVAILABLE 10
|
2019-10-16 12:05:27 +02:00
|
|
|
#define KORE_PYTHON_SEND_OBJ 11
|
2021-09-06 13:28:38 +02:00
|
|
|
#define KORE_MSG_WORKER_LOG 12
|
2022-08-08 11:02:27 +02:00
|
|
|
#define KORE_MSG_FATALX 13
|
2019-11-06 19:33:53 +01:00
|
|
|
#define KORE_MSG_ACME_BASE 100
|
|
|
|
|
|
|
|
/* messages for applications should start at 201. */
|
|
|
|
#define KORE_MSG_APP_BASE 200
|
2015-06-23 18:17:14 +02:00
|
|
|
|
2015-07-06 21:08:36 +02:00
|
|
|
/* Predefined message targets. */
|
|
|
|
#define KORE_MSG_PARENT 1000
|
|
|
|
#define KORE_MSG_WORKER_ALL 1001
|
|
|
|
|
2015-06-22 21:13:32 +02:00
|
|
|
struct kore_msg {
|
|
|
|
u_int8_t id;
|
2015-07-06 21:08:36 +02:00
|
|
|
u_int16_t src;
|
|
|
|
u_int16_t dst;
|
2018-07-11 09:44:29 +02:00
|
|
|
size_t length;
|
2015-06-22 21:13:32 +02:00
|
|
|
};
|
|
|
|
|
2016-06-08 13:55:14 +02:00
|
|
|
struct kore_keyreq {
|
|
|
|
int padding;
|
2019-11-06 19:33:53 +01:00
|
|
|
char domain[KORE_DOMAINNAME_LEN + 1];
|
|
|
|
size_t data_len;
|
2016-06-08 13:55:14 +02:00
|
|
|
u_int8_t data[];
|
|
|
|
};
|
2018-07-11 09:44:29 +02:00
|
|
|
|
|
|
|
struct kore_x509_msg {
|
2019-11-06 19:33:53 +01:00
|
|
|
char domain[KORE_DOMAINNAME_LEN + 1];
|
2018-07-11 09:44:29 +02:00
|
|
|
size_t data_len;
|
|
|
|
u_int8_t data[];
|
|
|
|
};
|
2016-06-08 13:55:14 +02:00
|
|
|
|
2016-07-06 16:16:15 +02:00
|
|
|
#if !defined(KORE_SINGLE_BINARY)
|
|
|
|
extern char *config_file;
|
|
|
|
#endif
|
|
|
|
|
2013-06-26 11:18:32 +02:00
|
|
|
extern pid_t kore_pid;
|
2021-11-03 17:23:05 +01:00
|
|
|
extern int kore_quit;
|
2018-11-15 16:01:37 +01:00
|
|
|
extern int kore_quiet;
|
2013-11-18 00:42:57 +01:00
|
|
|
extern int skip_chroot;
|
2015-05-18 21:34:39 +02:00
|
|
|
extern int skip_runas;
|
2023-01-05 22:47:29 +01:00
|
|
|
extern int kore_mem_guard;
|
2021-01-11 23:35:16 +01:00
|
|
|
extern int kore_foreground;
|
|
|
|
|
2013-06-04 16:53:30 +02:00
|
|
|
extern char *kore_pidfile;
|
2016-01-07 09:20:09 +01:00
|
|
|
|
2018-12-22 09:25:00 +01:00
|
|
|
extern volatile sig_atomic_t sig_recv;
|
|
|
|
|
2022-02-17 13:45:28 +01:00
|
|
|
extern char *kore_rand_file;
|
|
|
|
extern int kore_keymgr_active;
|
Rework worker startup/privsep config.
Starting with the privsep config, this commit changes the following:
- Removes the root, runas, keymgr_root, keymgr_runas, acme_root and
acme_runas configuration options.
Instead these are now configured via a privsep configuration context:
privsep worker {
root /tmp
runas nobody
}
This is also configurable via Python using the new kore.privsep() method:
kore.privsep("worker", root="/tmp", runas="nobody", skip=["chroot"])
Tied into this we also better handle worker startup:
- Per worker process, wait until it signalled it is ready.
- If a worker fails at startup, display its last log lines more clearly.
- Don't start acme process if no domain requires acme.
- Remove each process its individual startup log message in favour
of a generalized one that displays its PID, root and user.
- At startup, log the kore version and built-ins in a nicer way.
- The worker processes now check things they need to start running
before signaling they are ready (such as access to CA certs for
TLS client authentication).
2021-09-07 21:59:22 +02:00
|
|
|
|
|
|
|
extern struct kore_privsep worker_privsep;
|
|
|
|
extern struct kore_privsep keymgr_privsep;
|
|
|
|
extern struct kore_privsep acme_privsep;
|
2013-06-17 23:39:17 +02:00
|
|
|
|
2013-07-27 20:56:15 +02:00
|
|
|
extern u_int8_t nlisteners;
|
2013-06-17 23:39:17 +02:00
|
|
|
extern u_int16_t cpu_count;
|
|
|
|
extern u_int8_t worker_count;
|
2018-06-19 19:05:55 +02:00
|
|
|
extern const char *kore_version;
|
Rework worker startup/privsep config.
Starting with the privsep config, this commit changes the following:
- Removes the root, runas, keymgr_root, keymgr_runas, acme_root and
acme_runas configuration options.
Instead these are now configured via a privsep configuration context:
privsep worker {
root /tmp
runas nobody
}
This is also configurable via Python using the new kore.privsep() method:
kore.privsep("worker", root="/tmp", runas="nobody", skip=["chroot"])
Tied into this we also better handle worker startup:
- Per worker process, wait until it signalled it is ready.
- If a worker fails at startup, display its last log lines more clearly.
- Don't start acme process if no domain requires acme.
- Remove each process its individual startup log message in favour
of a generalized one that displays its PID, root and user.
- At startup, log the kore version and built-ins in a nicer way.
- The worker processes now check things they need to start running
before signaling they are ready (such as access to CA certs for
TLS client authentication).
2021-09-07 21:59:22 +02:00
|
|
|
extern const char *kore_build_date;
|
2019-03-22 09:49:50 +01:00
|
|
|
extern int worker_policy;
|
2015-04-27 10:36:33 +02:00
|
|
|
extern u_int8_t worker_set_affinity;
|
2014-07-31 09:14:03 +02:00
|
|
|
extern u_int32_t worker_rlimit_nofiles;
|
2013-06-26 16:37:22 +02:00
|
|
|
extern u_int32_t worker_max_connections;
|
2013-06-27 00:22:48 +02:00
|
|
|
extern u_int32_t worker_active_connections;
|
2015-05-18 12:20:28 +02:00
|
|
|
extern u_int32_t worker_accept_threshold;
|
2014-11-24 11:01:12 +01:00
|
|
|
extern u_int64_t kore_websocket_maxframe;
|
|
|
|
extern u_int64_t kore_websocket_timeout;
|
2015-04-09 15:29:44 +02:00
|
|
|
extern u_int32_t kore_socket_backlog;
|
2013-06-17 23:39:17 +02:00
|
|
|
|
2013-06-24 09:36:40 +02:00
|
|
|
extern struct kore_worker *worker;
|
2013-07-15 10:13:36 +02:00
|
|
|
extern struct kore_pool nb_pool;
|
2019-09-27 20:00:35 +02:00
|
|
|
extern struct kore_domain *primary_dom;
|
|
|
|
extern struct kore_server_list kore_servers;
|
2013-06-17 23:39:17 +02:00
|
|
|
|
2022-02-17 13:45:28 +01:00
|
|
|
/* kore.c */
|
2013-06-26 11:18:32 +02:00
|
|
|
void kore_signal(int);
|
2018-10-23 19:49:42 +02:00
|
|
|
void kore_shutdown(void);
|
2021-12-22 09:50:26 +01:00
|
|
|
void kore_signal_trap(int);
|
2018-05-25 20:49:02 +02:00
|
|
|
void kore_signal_setup(void);
|
2019-03-29 16:24:14 +01:00
|
|
|
void kore_proctitle(const char *);
|
2020-10-08 13:51:50 +02:00
|
|
|
void kore_default_getopt(int, char **);
|
2019-03-29 16:24:14 +01:00
|
|
|
|
2022-02-17 13:45:28 +01:00
|
|
|
void kore_server_closeall(void);
|
|
|
|
void kore_server_cleanup(void);
|
|
|
|
void kore_server_free(struct kore_server *);
|
|
|
|
void kore_server_finalize(struct kore_server *);
|
2023-01-16 21:00:01 +01:00
|
|
|
void kore_hooks_set(const char *, const char *, const char *);
|
2022-02-17 13:45:28 +01:00
|
|
|
|
|
|
|
struct kore_server *kore_server_create(const char *);
|
|
|
|
struct kore_server *kore_server_lookup(const char *);
|
|
|
|
|
|
|
|
void kore_listener_accept(void *, int);
|
|
|
|
struct listener *kore_listener_lookup(const char *);
|
|
|
|
void kore_listener_free(struct listener *);
|
|
|
|
struct listener *kore_listener_create(struct kore_server *);
|
|
|
|
int kore_listener_init(struct listener *, int, const char *);
|
|
|
|
|
|
|
|
int kore_sockopt(int, int, int);
|
|
|
|
int kore_server_bind_unix(struct kore_server *,
|
|
|
|
const char *, const char *);
|
|
|
|
int kore_server_bind(struct kore_server *,
|
|
|
|
const char *, const char *, const char *);
|
|
|
|
/* worker.c */
|
2019-03-22 09:49:50 +01:00
|
|
|
void kore_worker_reap(void);
|
Rework worker startup/privsep config.
Starting with the privsep config, this commit changes the following:
- Removes the root, runas, keymgr_root, keymgr_runas, acme_root and
acme_runas configuration options.
Instead these are now configured via a privsep configuration context:
privsep worker {
root /tmp
runas nobody
}
This is also configurable via Python using the new kore.privsep() method:
kore.privsep("worker", root="/tmp", runas="nobody", skip=["chroot"])
Tied into this we also better handle worker startup:
- Per worker process, wait until it signalled it is ready.
- If a worker fails at startup, display its last log lines more clearly.
- Don't start acme process if no domain requires acme.
- Remove each process its individual startup log message in favour
of a generalized one that displays its PID, root and user.
- At startup, log the kore version and built-ins in a nicer way.
- The worker processes now check things they need to start running
before signaling they are ready (such as access to CA certs for
TLS client authentication).
2021-09-07 21:59:22 +02:00
|
|
|
int kore_worker_init(void);
|
|
|
|
void kore_worker_privsep(void);
|
|
|
|
void kore_worker_started(void);
|
2018-07-11 18:00:16 +02:00
|
|
|
void kore_worker_make_busy(void);
|
2013-06-26 16:37:22 +02:00
|
|
|
void kore_worker_shutdown(void);
|
|
|
|
void kore_worker_dispatch_signal(int);
|
Rework worker startup/privsep config.
Starting with the privsep config, this commit changes the following:
- Removes the root, runas, keymgr_root, keymgr_runas, acme_root and
acme_runas configuration options.
Instead these are now configured via a privsep configuration context:
privsep worker {
root /tmp
runas nobody
}
This is also configurable via Python using the new kore.privsep() method:
kore.privsep("worker", root="/tmp", runas="nobody", skip=["chroot"])
Tied into this we also better handle worker startup:
- Per worker process, wait until it signalled it is ready.
- If a worker fails at startup, display its last log lines more clearly.
- Don't start acme process if no domain requires acme.
- Remove each process its individual startup log message in favour
of a generalized one that displays its PID, root and user.
- At startup, log the kore version and built-ins in a nicer way.
- The worker processes now check things they need to start running
before signaling they are ready (such as access to CA certs for
TLS client authentication).
2021-09-07 21:59:22 +02:00
|
|
|
int kore_worker_spawn(u_int16_t, u_int16_t, u_int16_t);
|
2019-11-06 19:33:53 +01:00
|
|
|
int kore_worker_keymgr_response_verify(struct kore_msg *,
|
|
|
|
const void *, struct kore_domain **);
|
2015-06-22 21:13:32 +02:00
|
|
|
|
2020-03-25 13:35:02 +01:00
|
|
|
void kore_worker_entry(struct kore_worker *) __attribute__((noreturn));
|
|
|
|
|
2015-06-22 21:13:32 +02:00
|
|
|
struct kore_worker *kore_worker_data(u_int8_t);
|
2022-02-01 10:36:07 +01:00
|
|
|
struct kore_worker *kore_worker_data_byid(u_int16_t);
|
2013-06-26 11:18:32 +02:00
|
|
|
|
2022-02-17 13:45:28 +01:00
|
|
|
/* platform code (linux.c, bsd.c) */
|
2013-07-27 20:56:15 +02:00
|
|
|
void kore_platform_init(void);
|
2019-09-25 14:25:49 +02:00
|
|
|
void kore_platform_sandbox(void);
|
2013-06-26 11:18:32 +02:00
|
|
|
void kore_platform_event_init(void);
|
2016-01-04 22:40:14 +01:00
|
|
|
void kore_platform_event_cleanup(void);
|
2014-03-30 23:54:35 +02:00
|
|
|
void kore_platform_disable_read(int);
|
2018-10-15 20:18:54 +02:00
|
|
|
void kore_platform_disable_write(int);
|
2013-06-26 16:37:22 +02:00
|
|
|
void kore_platform_enable_accept(void);
|
|
|
|
void kore_platform_disable_accept(void);
|
2018-12-22 09:25:00 +01:00
|
|
|
void kore_platform_event_wait(u_int64_t);
|
2014-09-17 08:25:45 +02:00
|
|
|
void kore_platform_event_all(int, void *);
|
2020-08-17 15:15:04 +02:00
|
|
|
void kore_platform_event_level_all(int, void *);
|
|
|
|
void kore_platform_event_level_read(int, void *);
|
2019-11-06 19:33:53 +01:00
|
|
|
void kore_platform_proctitle(const char *);
|
2014-03-30 23:54:35 +02:00
|
|
|
void kore_platform_schedule_read(int, void *);
|
2015-12-09 21:29:44 +01:00
|
|
|
void kore_platform_schedule_write(int, void *);
|
2013-06-26 11:18:32 +02:00
|
|
|
void kore_platform_event_schedule(int, int, int, void *);
|
|
|
|
void kore_platform_worker_setcpu(struct kore_worker *);
|
2023-01-04 11:48:19 +01:00
|
|
|
u_int32_t kore_platform_random_uint32(void);
|
2013-06-26 11:18:32 +02:00
|
|
|
|
2018-06-28 13:27:44 +02:00
|
|
|
#if defined(KORE_USE_PLATFORM_SENDFILE)
|
|
|
|
int kore_platform_sendfile(struct connection *, struct netbuf *);
|
|
|
|
#endif
|
|
|
|
|
2018-07-31 06:51:34 +02:00
|
|
|
#if defined(KORE_USE_PLATFORM_PLEDGE)
|
|
|
|
void kore_platform_pledge(void);
|
|
|
|
void kore_platform_add_pledge(const char *);
|
|
|
|
#endif
|
|
|
|
|
2022-02-17 13:45:28 +01:00
|
|
|
/* tls variants. */
|
|
|
|
#define KORE_X509_NAME_COMMON_NAME 1
|
|
|
|
|
|
|
|
void kore_tls_init(void);
|
|
|
|
void kore_tls_cleanup(void);
|
|
|
|
void kore_tls_dh_check(void);
|
|
|
|
int kore_tls_supported(void);
|
|
|
|
void kore_tls_version_set(int);
|
|
|
|
void kore_tls_keymgr_init(void);
|
2023-01-16 21:00:01 +01:00
|
|
|
void kore_tls_log_version(void);
|
2022-02-17 13:45:28 +01:00
|
|
|
int kore_tls_dh_load(const char *);
|
|
|
|
void kore_tls_seed(const void *, size_t);
|
|
|
|
int kore_tls_ciphersuite_set(const char *);
|
|
|
|
int kore_tls_read(struct connection *, size_t *);
|
|
|
|
void kore_tls_domain_cleanup(struct kore_domain *);
|
|
|
|
int kore_tls_connection_accept(struct connection *);
|
|
|
|
void kore_tls_connection_cleanup(struct connection *);
|
|
|
|
int kore_tls_write(struct connection *, size_t, size_t *);
|
|
|
|
void kore_tls_domain_crl(struct kore_domain *, const void *, size_t);
|
|
|
|
void kore_tls_domain_setup(struct kore_domain *,
|
|
|
|
int, const void *, size_t);
|
|
|
|
|
2022-02-18 10:50:17 +01:00
|
|
|
KORE_PRIVATE_KEY *kore_tls_rsakey_load(const char *);
|
|
|
|
KORE_PRIVATE_KEY *kore_tls_rsakey_generate(const char *);
|
2022-02-17 13:45:28 +01:00
|
|
|
|
2022-02-18 09:14:30 +01:00
|
|
|
int kore_tls_x509_data(struct connection *, u_int8_t **, size_t *);
|
2022-02-18 10:47:05 +01:00
|
|
|
KORE_X509_NAMES *kore_tls_x509_issuer_name(struct connection *);
|
|
|
|
KORE_X509_NAMES *kore_tls_x509_subject_name(struct connection *);
|
|
|
|
int kore_tls_x509name_foreach(KORE_X509_NAMES *, int, void *,
|
2022-02-17 13:45:28 +01:00
|
|
|
int (*)(void *, int, int, const char *,
|
|
|
|
const void *, size_t, int));
|
|
|
|
/* accesslog.c */
|
2018-12-22 09:25:00 +01:00
|
|
|
void kore_accesslog_init(u_int16_t);
|
2013-06-24 09:36:40 +02:00
|
|
|
void kore_accesslog_worker_init(void);
|
2018-12-22 09:25:00 +01:00
|
|
|
void kore_accesslog_run(void *, u_int64_t);
|
|
|
|
void kore_accesslog_gather(void *, u_int64_t, int);
|
2013-07-27 20:56:15 +02:00
|
|
|
|
2015-11-27 16:22:50 +01:00
|
|
|
#if !defined(KORE_NO_HTTP)
|
2022-02-17 13:45:28 +01:00
|
|
|
/* auth.c */
|
2015-04-02 13:45:42 +02:00
|
|
|
int kore_auth_run(struct http_request *, struct kore_auth *);
|
2018-07-19 10:28:38 +02:00
|
|
|
int kore_auth_cookie(struct http_request *, struct kore_auth *);
|
|
|
|
int kore_auth_header(struct http_request *, struct kore_auth *);
|
|
|
|
int kore_auth_request(struct http_request *, struct kore_auth *);
|
2015-04-02 13:45:42 +02:00
|
|
|
void kore_auth_init(void);
|
|
|
|
int kore_auth_new(const char *);
|
2014-08-04 12:40:21 +02:00
|
|
|
struct kore_auth *kore_auth_lookup(const char *);
|
2015-11-27 16:22:50 +01:00
|
|
|
#endif
|
2014-01-22 22:55:10 +01:00
|
|
|
|
2022-02-17 13:45:28 +01:00
|
|
|
/* timer.c */
|
2015-04-06 18:54:35 +02:00
|
|
|
void kore_timer_init(void);
|
2019-03-21 10:17:08 +01:00
|
|
|
void kore_timer_run(u_int64_t);
|
|
|
|
u_int64_t kore_timer_next_run(u_int64_t);
|
2015-05-15 19:11:10 +02:00
|
|
|
void kore_timer_remove(struct kore_timer *);
|
2015-08-06 08:20:41 +02:00
|
|
|
struct kore_timer *kore_timer_add(void (*cb)(void *, u_int64_t),
|
|
|
|
u_int64_t, void *, int);
|
2015-04-06 18:54:35 +02:00
|
|
|
|
2022-02-17 13:45:28 +01:00
|
|
|
/* connection.c */
|
2014-09-17 08:25:45 +02:00
|
|
|
void kore_connection_init(void);
|
2016-01-04 22:40:14 +01:00
|
|
|
void kore_connection_cleanup(void);
|
2015-06-22 21:13:32 +02:00
|
|
|
void kore_connection_prune(int);
|
2014-09-17 08:25:45 +02:00
|
|
|
struct connection *kore_connection_new(void *);
|
2018-10-09 19:34:40 +02:00
|
|
|
void kore_connection_event(void *, int);
|
2015-06-22 22:11:03 +02:00
|
|
|
int kore_connection_nonblock(int, int);
|
2018-02-14 13:48:49 +01:00
|
|
|
void kore_connection_check_timeout(u_int64_t);
|
2014-09-17 08:25:45 +02:00
|
|
|
int kore_connection_handle(struct connection *);
|
|
|
|
void kore_connection_remove(struct connection *);
|
|
|
|
void kore_connection_disconnect(struct connection *);
|
|
|
|
void kore_connection_start_idletimer(struct connection *);
|
|
|
|
void kore_connection_stop_idletimer(struct connection *);
|
|
|
|
void kore_connection_check_idletimer(u_int64_t,
|
|
|
|
struct connection *);
|
|
|
|
int kore_connection_accept(struct listener *,
|
|
|
|
struct connection **);
|
2022-09-05 10:59:06 +02:00
|
|
|
void kore_connection_log(struct connection *,
|
|
|
|
const char *, ...)
|
|
|
|
__attribute__((format (printf, 2, 3)));
|
|
|
|
const char *kore_connection_ip(struct connection *);
|
2013-06-26 11:18:32 +02:00
|
|
|
|
2013-06-04 23:24:47 +02:00
|
|
|
void kore_log_init(void);
|
2021-09-10 13:34:57 +02:00
|
|
|
void kore_log_file(const char *);
|
2013-06-27 08:43:07 +02:00
|
|
|
|
2022-02-17 13:45:28 +01:00
|
|
|
/* config.c */
|
2013-06-26 11:18:32 +02:00
|
|
|
void kore_parse_config(void);
|
2018-04-09 12:51:20 +02:00
|
|
|
void kore_parse_config_file(FILE *);
|
2023-01-21 23:41:35 +01:00
|
|
|
int kore_configure_setting(const char *, char *);
|
2022-02-17 13:45:28 +01:00
|
|
|
|
|
|
|
/* mem.c */
|
|
|
|
void *kore_malloc(size_t);
|
2023-01-05 22:47:29 +01:00
|
|
|
void *kore_mmap_region(size_t);
|
2013-04-17 22:34:27 +02:00
|
|
|
void *kore_calloc(size_t, size_t);
|
|
|
|
void *kore_realloc(void *, size_t);
|
2016-07-12 13:54:14 +02:00
|
|
|
void kore_free(void *);
|
2013-06-27 08:43:07 +02:00
|
|
|
void kore_mem_init(void);
|
2023-03-01 16:26:24 +01:00
|
|
|
void kore_free_zero(void *);
|
2017-02-06 11:39:30 +01:00
|
|
|
void kore_mem_cleanup(void);
|
2017-08-30 11:47:26 +02:00
|
|
|
void kore_mem_untag(void *);
|
|
|
|
void *kore_mem_lookup(u_int32_t);
|
2022-02-18 11:13:01 +01:00
|
|
|
void kore_mem_zero(void *, size_t);
|
2017-08-30 11:47:26 +02:00
|
|
|
void kore_mem_tag(void *, u_int32_t);
|
|
|
|
void *kore_malloc_tagged(size_t, u_int32_t);
|
2013-06-27 08:43:07 +02:00
|
|
|
|
2022-02-17 13:45:28 +01:00
|
|
|
/* pool.c */
|
2013-07-15 10:13:36 +02:00
|
|
|
void *kore_pool_get(struct kore_pool *);
|
|
|
|
void kore_pool_put(struct kore_pool *, void *);
|
2014-08-04 12:40:21 +02:00
|
|
|
void kore_pool_init(struct kore_pool *, const char *,
|
2016-07-12 14:01:02 +02:00
|
|
|
size_t, size_t);
|
2016-01-04 22:40:14 +01:00
|
|
|
void kore_pool_cleanup(struct kore_pool *);
|
2013-07-15 10:13:36 +02:00
|
|
|
|
2022-02-17 13:45:28 +01:00
|
|
|
/* utils.c */
|
2022-08-17 13:16:18 +02:00
|
|
|
void fatal(const char *, ...) __attribute__((noreturn))
|
|
|
|
__attribute__((format (printf, 1, 2)));
|
|
|
|
void fatalx(const char *, ...) __attribute__((noreturn))
|
|
|
|
__attribute__((format (printf, 1, 2)));
|
2022-02-17 13:45:28 +01:00
|
|
|
|
|
|
|
u_int64_t kore_time_ms(void);
|
2013-05-01 21:16:09 +02:00
|
|
|
char *kore_time_to_date(time_t);
|
2013-04-17 22:34:27 +02:00
|
|
|
char *kore_strdup(const char *);
|
2018-06-29 09:56:38 +02:00
|
|
|
time_t kore_date_to_time(const char *);
|
2017-02-06 11:39:30 +01:00
|
|
|
void kore_log(int, const char *, ...)
|
|
|
|
__attribute__((format (printf, 2, 3)));
|
2014-07-21 01:16:03 +02:00
|
|
|
u_int64_t kore_strtonum64(const char *, int, int *);
|
2016-07-04 11:41:37 +02:00
|
|
|
size_t kore_strlcpy(char *, const char *, const size_t);
|
2013-05-01 08:09:04 +02:00
|
|
|
void kore_server_disconnect(struct connection *);
|
2016-10-06 16:50:41 +02:00
|
|
|
int kore_split_string(char *, const char *, char **, size_t);
|
2022-10-19 07:34:14 +02:00
|
|
|
void kore_strip_chars(const char *, const char, char **);
|
2022-08-17 13:16:18 +02:00
|
|
|
int kore_snprintf(char *, size_t, int *, const char *, ...)
|
|
|
|
__attribute__((format (printf, 4, 5)));
|
2013-12-12 00:58:32 +01:00
|
|
|
long long kore_strtonum(const char *, int, long long, long long, int *);
|
2018-05-04 15:55:35 +02:00
|
|
|
double kore_strtodouble(const char *, long double, long double, int *);
|
2017-07-24 08:19:03 +02:00
|
|
|
int kore_base64_encode(const void *, size_t, char **);
|
2018-03-01 12:54:54 +01:00
|
|
|
int kore_base64_decode(const char *, u_int8_t **, size_t *);
|
2019-11-06 19:33:53 +01:00
|
|
|
int kore_base64url_encode(const void *, size_t, char **, int);
|
|
|
|
int kore_base64url_decode(const char *, u_int8_t **, size_t *, int);
|
2022-02-17 13:45:28 +01:00
|
|
|
int kore_x509_issuer_name(struct connection *, char **, int);
|
|
|
|
int kore_x509_subject_name(struct connection *, char **, int);
|
|
|
|
|
2018-07-25 09:54:34 +02:00
|
|
|
void *kore_mem_find(void *, size_t, const void *, size_t);
|
2016-02-01 21:33:51 +01:00
|
|
|
char *kore_text_trim(char *, size_t);
|
2016-02-01 22:10:10 +01:00
|
|
|
char *kore_read_line(FILE *, char *, size_t);
|
2013-05-01 16:03:48 +02:00
|
|
|
|
2015-11-27 16:22:50 +01:00
|
|
|
#if !defined(KORE_NO_HTTP)
|
2022-02-17 13:45:28 +01:00
|
|
|
/* websocket.c */
|
2014-11-24 11:01:12 +01:00
|
|
|
void kore_websocket_handshake(struct http_request *,
|
2017-01-29 22:57:34 +01:00
|
|
|
const char *, const char *, const char *);
|
2018-04-13 07:40:37 +02:00
|
|
|
int kore_websocket_send_clean(struct netbuf *);
|
2014-11-24 11:01:12 +01:00
|
|
|
void kore_websocket_send(struct connection *,
|
2015-06-23 18:17:14 +02:00
|
|
|
u_int8_t, const void *, size_t);
|
2014-11-24 11:01:12 +01:00
|
|
|
void kore_websocket_broadcast(struct connection *,
|
2015-06-23 18:17:14 +02:00
|
|
|
u_int8_t, const void *, size_t, int);
|
2015-11-27 16:22:50 +01:00
|
|
|
#endif
|
2014-11-24 11:01:12 +01:00
|
|
|
|
2022-02-17 13:45:28 +01:00
|
|
|
/* msg.c */
|
2015-06-22 21:13:32 +02:00
|
|
|
void kore_msg_init(void);
|
|
|
|
void kore_msg_worker_init(void);
|
|
|
|
void kore_msg_parent_init(void);
|
2019-10-16 12:05:27 +02:00
|
|
|
void kore_msg_unregister(u_int8_t);
|
2015-06-22 21:13:32 +02:00
|
|
|
void kore_msg_parent_add(struct kore_worker *);
|
|
|
|
void kore_msg_parent_remove(struct kore_worker *);
|
2018-07-11 09:44:29 +02:00
|
|
|
void kore_msg_send(u_int16_t, u_int8_t, const void *, size_t);
|
2015-06-22 21:13:32 +02:00
|
|
|
int kore_msg_register(u_int8_t,
|
2015-06-23 18:17:14 +02:00
|
|
|
void (*cb)(struct kore_msg *, const void *));
|
2015-06-22 21:13:32 +02:00
|
|
|
|
2018-06-28 23:00:42 +02:00
|
|
|
#if !defined(KORE_NO_HTTP)
|
2022-02-17 13:45:28 +01:00
|
|
|
/* filemap.c */
|
2018-06-28 13:27:44 +02:00
|
|
|
void kore_filemap_init(void);
|
2018-07-08 17:51:35 +02:00
|
|
|
void kore_filemap_resolve_paths(void);
|
2018-07-03 19:58:43 +02:00
|
|
|
extern char *kore_filemap_ext;
|
2018-06-28 23:00:42 +02:00
|
|
|
extern char *kore_filemap_index;
|
2022-08-10 10:13:01 +02:00
|
|
|
|
|
|
|
struct kore_route *kore_filemap_create(struct kore_domain *, const char *,
|
|
|
|
const char *, const char *);
|
2018-06-28 23:00:42 +02:00
|
|
|
#endif
|
2018-06-28 13:27:44 +02:00
|
|
|
|
2022-02-17 13:45:28 +01:00
|
|
|
/* fileref.c */
|
2018-06-28 13:27:44 +02:00
|
|
|
void kore_fileref_init(void);
|
2019-09-27 12:22:35 +02:00
|
|
|
struct kore_fileref *kore_fileref_get(const char *, int);
|
2019-09-27 20:00:35 +02:00
|
|
|
struct kore_fileref *kore_fileref_create(struct kore_server *,
|
2019-09-27 12:22:35 +02:00
|
|
|
const char *, int, off_t, struct timespec *);
|
2018-06-28 13:27:44 +02:00
|
|
|
void kore_fileref_release(struct kore_fileref *);
|
|
|
|
|
2022-02-17 13:45:28 +01:00
|
|
|
/* domain.c */
|
2019-09-27 12:22:35 +02:00
|
|
|
struct kore_domain *kore_domain_new(const char *);
|
2022-02-17 13:45:28 +01:00
|
|
|
struct kore_domain *kore_domain_byid(u_int16_t);
|
|
|
|
struct kore_domain *kore_domain_lookup(struct kore_server *, const char *);
|
2019-09-27 12:22:35 +02:00
|
|
|
|
2013-06-24 11:32:45 +02:00
|
|
|
void kore_domain_init(void);
|
2016-02-01 12:30:20 +01:00
|
|
|
void kore_domain_cleanup(void);
|
|
|
|
void kore_domain_free(struct kore_domain *);
|
2013-12-15 01:11:56 +01:00
|
|
|
void kore_module_init(void);
|
2016-06-08 13:55:14 +02:00
|
|
|
void kore_module_cleanup(void);
|
2014-06-29 21:15:23 +02:00
|
|
|
void kore_module_reload(int);
|
|
|
|
void kore_module_onload(void);
|
2013-05-01 16:03:48 +02:00
|
|
|
int kore_module_loaded(void);
|
2013-06-24 11:32:45 +02:00
|
|
|
void kore_domain_closelogs(void);
|
2017-01-12 23:38:51 +01:00
|
|
|
void *kore_module_getsym(const char *, struct kore_runtime **);
|
2014-10-18 02:32:05 +02:00
|
|
|
void kore_domain_load_crl(void);
|
2016-06-08 13:55:14 +02:00
|
|
|
void kore_domain_keymgr_init(void);
|
|
|
|
void kore_domain_callback(void (*cb)(struct kore_domain *));
|
2019-09-27 20:00:35 +02:00
|
|
|
int kore_domain_attach(struct kore_domain *, struct kore_server *);
|
2021-09-15 11:09:52 +02:00
|
|
|
|
2018-07-17 14:28:43 +02:00
|
|
|
#if !defined(KORE_NO_HTTP)
|
2022-02-17 13:45:28 +01:00
|
|
|
/* route.c */
|
2021-09-15 11:09:52 +02:00
|
|
|
void kore_route_reload(void);
|
|
|
|
void kore_route_free(struct kore_route *);
|
|
|
|
void kore_route_callback(struct kore_route *, const char *);
|
|
|
|
|
|
|
|
struct kore_route *kore_route_create(struct kore_domain *,
|
|
|
|
const char *, int);
|
|
|
|
int kore_route_lookup(struct http_request *,
|
|
|
|
struct kore_domain *, int, struct kore_route **);
|
2018-07-17 14:28:43 +02:00
|
|
|
#endif
|
2014-08-04 12:40:21 +02:00
|
|
|
|
2022-02-17 13:45:28 +01:00
|
|
|
/* runtime.c */
|
2023-11-03 12:25:39 +01:00
|
|
|
size_t kore_runtime_count(void);
|
2017-01-12 23:38:51 +01:00
|
|
|
struct kore_runtime_call *kore_runtime_getcall(const char *);
|
2018-10-16 13:16:36 +02:00
|
|
|
struct kore_module *kore_module_load(const char *,
|
|
|
|
const char *, int);
|
2017-01-12 23:38:51 +01:00
|
|
|
|
2017-01-26 13:26:55 +01:00
|
|
|
void kore_runtime_execute(struct kore_runtime_call *);
|
2017-01-12 23:38:51 +01:00
|
|
|
int kore_runtime_onload(struct kore_runtime_call *, int);
|
2021-12-22 09:50:26 +01:00
|
|
|
void kore_runtime_signal(struct kore_runtime_call *, int);
|
2023-01-16 21:00:01 +01:00
|
|
|
void kore_runtime_resolve(const char *, const struct stat *);
|
2018-04-09 12:51:20 +02:00
|
|
|
void kore_runtime_configure(struct kore_runtime_call *, int, char **);
|
2017-01-12 23:38:51 +01:00
|
|
|
void kore_runtime_connect(struct kore_runtime_call *, struct connection *);
|
|
|
|
#if !defined(KORE_NO_HTTP)
|
|
|
|
int kore_runtime_http_request(struct kore_runtime_call *,
|
|
|
|
struct http_request *);
|
2021-12-14 23:15:21 +01:00
|
|
|
void kore_runtime_http_request_free(struct kore_runtime_call *,
|
|
|
|
struct http_request *);
|
2021-09-17 19:28:06 +02:00
|
|
|
void kore_runtime_http_body_chunk(struct kore_runtime_call *,
|
|
|
|
struct http_request *, const void *, size_t);
|
2017-01-12 23:38:51 +01:00
|
|
|
int kore_runtime_validator(struct kore_runtime_call *,
|
2018-02-14 13:48:49 +01:00
|
|
|
struct http_request *, const void *);
|
2017-01-29 22:57:34 +01:00
|
|
|
void kore_runtime_wsconnect(struct kore_runtime_call *, struct connection *);
|
|
|
|
void kore_runtime_wsdisconnect(struct kore_runtime_call *,
|
|
|
|
struct connection *);
|
|
|
|
void kore_runtime_wsmessage(struct kore_runtime_call *,
|
|
|
|
struct connection *, u_int8_t, const void *, size_t);
|
2017-01-12 23:38:51 +01:00
|
|
|
#endif
|
|
|
|
|
2015-11-27 16:22:50 +01:00
|
|
|
#if !defined(KORE_NO_HTTP)
|
2022-02-17 13:45:28 +01:00
|
|
|
/* validator.c */
|
2013-11-09 16:21:52 +01:00
|
|
|
void kore_validator_init(void);
|
2017-08-31 17:11:24 +02:00
|
|
|
void kore_validator_reload(void);
|
2014-08-04 12:40:21 +02:00
|
|
|
int kore_validator_add(const char *, u_int8_t, const char *);
|
|
|
|
int kore_validator_run(struct http_request *, const char *, char *);
|
2014-02-01 17:47:58 +01:00
|
|
|
int kore_validator_check(struct http_request *,
|
2018-02-14 13:48:49 +01:00
|
|
|
struct kore_validator *, const void *);
|
2014-08-04 12:40:21 +02:00
|
|
|
struct kore_validator *kore_validator_lookup(const char *);
|
2015-11-27 16:22:50 +01:00
|
|
|
#endif
|
2013-11-09 16:21:52 +01:00
|
|
|
|
2019-11-06 19:33:53 +01:00
|
|
|
const char *kore_worker_name(int);
|
2013-04-17 22:34:27 +02:00
|
|
|
|
2022-02-17 13:45:28 +01:00
|
|
|
/* net.c */
|
2013-05-01 00:35:33 +02:00
|
|
|
u_int16_t net_read16(u_int8_t *);
|
|
|
|
u_int32_t net_read32(u_int8_t *);
|
2014-11-24 11:01:12 +01:00
|
|
|
u_int64_t net_read64(u_int8_t *);
|
2013-05-01 08:09:04 +02:00
|
|
|
void net_write16(u_int8_t *, u_int16_t);
|
|
|
|
void net_write32(u_int8_t *, u_int32_t);
|
2014-11-24 11:01:12 +01:00
|
|
|
void net_write64(u_int8_t *, u_int64_t);
|
|
|
|
|
2013-07-15 10:13:36 +02:00
|
|
|
void net_init(void);
|
2016-01-04 22:40:14 +01:00
|
|
|
void net_cleanup(void);
|
2018-06-28 13:27:44 +02:00
|
|
|
struct netbuf *net_netbuf_get(void);
|
2013-04-28 19:11:44 +02:00
|
|
|
int net_send(struct connection *);
|
2013-05-01 13:43:47 +02:00
|
|
|
int net_send_flush(struct connection *);
|
|
|
|
int net_recv_flush(struct connection *);
|
2017-03-16 09:54:46 +01:00
|
|
|
int net_read(struct connection *, size_t *);
|
|
|
|
int net_write(struct connection *, size_t, size_t *);
|
2016-07-08 10:02:18 +02:00
|
|
|
void net_recv_reset(struct connection *, size_t,
|
2014-10-22 21:16:49 +02:00
|
|
|
int (*cb)(struct netbuf *));
|
2018-12-22 09:25:00 +01:00
|
|
|
void net_remove_netbuf(struct connection *, struct netbuf *);
|
2016-07-08 10:02:18 +02:00
|
|
|
void net_recv_queue(struct connection *, size_t, int,
|
2014-10-22 21:16:49 +02:00
|
|
|
int (*cb)(struct netbuf *));
|
2016-07-08 10:02:18 +02:00
|
|
|
void net_recv_expand(struct connection *c, size_t,
|
2014-10-22 21:16:49 +02:00
|
|
|
int (*cb)(struct netbuf *));
|
2016-07-08 10:02:18 +02:00
|
|
|
void net_send_queue(struct connection *, const void *, size_t);
|
2014-08-07 14:23:26 +02:00
|
|
|
void net_send_stream(struct connection *, void *,
|
2016-07-08 10:02:18 +02:00
|
|
|
size_t, int (*cb)(struct netbuf *), struct netbuf **);
|
2018-06-28 13:27:44 +02:00
|
|
|
void net_send_fileref(struct connection *, struct kore_fileref *);
|
2013-04-28 19:11:44 +02:00
|
|
|
|
2022-02-17 13:45:28 +01:00
|
|
|
/* buf.c */
|
2013-07-10 15:00:53 +02:00
|
|
|
void kore_buf_free(struct kore_buf *);
|
2016-07-14 12:33:13 +02:00
|
|
|
struct kore_buf *kore_buf_alloc(size_t);
|
2016-07-05 16:48:58 +02:00
|
|
|
void kore_buf_init(struct kore_buf *, size_t);
|
2016-07-08 10:02:18 +02:00
|
|
|
void kore_buf_append(struct kore_buf *, const void *, size_t);
|
|
|
|
u_int8_t *kore_buf_release(struct kore_buf *, size_t *);
|
2016-01-18 11:30:22 +01:00
|
|
|
void kore_buf_reset(struct kore_buf *);
|
2016-07-14 12:33:13 +02:00
|
|
|
void kore_buf_cleanup(struct kore_buf *);
|
2015-06-23 18:17:14 +02:00
|
|
|
|
2016-06-02 07:08:19 +02:00
|
|
|
char *kore_buf_stringify(struct kore_buf *, size_t *);
|
2022-08-17 13:16:18 +02:00
|
|
|
void kore_buf_appendf(struct kore_buf *, const char *, ...)
|
|
|
|
__attribute__((format (printf, 2, 3)));
|
|
|
|
void kore_buf_appendv(struct kore_buf *, const char *, va_list)
|
|
|
|
__attribute__((format (printf, 2, 0)));
|
2018-07-25 09:54:34 +02:00
|
|
|
void kore_buf_replace_string(struct kore_buf *,
|
|
|
|
const char *, const void *, size_t);
|
2013-05-02 15:14:00 +02:00
|
|
|
|
2022-02-17 13:45:28 +01:00
|
|
|
/* json.c */
|
2021-03-30 14:19:48 +02:00
|
|
|
int kore_json_errno(void);
|
Add a full native JSON parser to Kore.
Mostly compliant, ignores \uXXXX in strings for now.
New API functions:
void kore_json_init(struct kore_json *json, const u_int8_t *data, size_t len);
- Prepares JSON data for parsing.
int kore_json_parse(struct kore_json *json)
- Parses the JSON data prepared via kore_json_init. Returns KORE_RESULT_ERROR
if parsing failed or KORE_RESULT_OK if it succeeded.
struct kore_json_item *kore_json_get(struct kore_json *json, const char *path,
int type);
- Try to find the object matching a given search patch and type.
eg, given a JSON structure of:
{
"reasons": {
"strings": [
"first reason",
"second"
]
}
}
one can obtain the second element in the reasons.strings array via:
item = kore_json_get(json, "reasons/strings[0]", KORE_JSON_TYPE_STRING);
Returns NULL if the item was not found or a type mismatch was hit,
otherwise will return the item of that type.
The kore_json_item data structure has a data member that contains the
relevant bits depending on the type:
KORE_JSON_TYPE_ARRAY, KORE_JSON_TYPE_OBJECT:
the data.items member is valid.
KORE_JSON_TYPE_STRING:
the data.string member is valid.
KORE_JSON_TYPE_NUMBER:
the data.number member is valid.
KORE_JSON_TYPE_LITERAL:
the data.literal member is valid.
void kore_json_cleanup(struct kore_json *json);
- Cleanup any resources
const char *kore_json_strerror(struct kore_json *json);
- Return pointer to human readable error string.
2019-10-20 23:22:11 +02:00
|
|
|
int kore_json_parse(struct kore_json *);
|
|
|
|
void kore_json_cleanup(struct kore_json *);
|
2019-10-22 23:56:47 +02:00
|
|
|
void kore_json_item_free(struct kore_json_item *);
|
2020-11-23 10:48:04 +01:00
|
|
|
void kore_json_init(struct kore_json *, const void *, size_t);
|
2019-10-22 23:56:47 +02:00
|
|
|
void kore_json_item_tobuf(struct kore_json_item *, struct kore_buf *);
|
2021-04-08 09:10:58 +02:00
|
|
|
void kore_json_item_attach(struct kore_json_item *, struct kore_json_item *);
|
Add a full native JSON parser to Kore.
Mostly compliant, ignores \uXXXX in strings for now.
New API functions:
void kore_json_init(struct kore_json *json, const u_int8_t *data, size_t len);
- Prepares JSON data for parsing.
int kore_json_parse(struct kore_json *json)
- Parses the JSON data prepared via kore_json_init. Returns KORE_RESULT_ERROR
if parsing failed or KORE_RESULT_OK if it succeeded.
struct kore_json_item *kore_json_get(struct kore_json *json, const char *path,
int type);
- Try to find the object matching a given search patch and type.
eg, given a JSON structure of:
{
"reasons": {
"strings": [
"first reason",
"second"
]
}
}
one can obtain the second element in the reasons.strings array via:
item = kore_json_get(json, "reasons/strings[0]", KORE_JSON_TYPE_STRING);
Returns NULL if the item was not found or a type mismatch was hit,
otherwise will return the item of that type.
The kore_json_item data structure has a data member that contains the
relevant bits depending on the type:
KORE_JSON_TYPE_ARRAY, KORE_JSON_TYPE_OBJECT:
the data.items member is valid.
KORE_JSON_TYPE_STRING:
the data.string member is valid.
KORE_JSON_TYPE_NUMBER:
the data.number member is valid.
KORE_JSON_TYPE_LITERAL:
the data.literal member is valid.
void kore_json_cleanup(struct kore_json *json);
- Cleanup any resources
const char *kore_json_strerror(struct kore_json *json);
- Return pointer to human readable error string.
2019-10-20 23:22:11 +02:00
|
|
|
|
2021-03-30 14:19:48 +02:00
|
|
|
const char *kore_json_strerror(void);
|
2019-10-25 12:27:16 +02:00
|
|
|
struct kore_json_item *kore_json_find(struct kore_json_item *,
|
2020-11-19 14:56:17 +01:00
|
|
|
const char *, u_int32_t);
|
2019-10-22 23:56:47 +02:00
|
|
|
struct kore_json_item *kore_json_create_item(struct kore_json_item *,
|
2020-11-19 14:56:17 +01:00
|
|
|
const char *, u_int32_t, ...);
|
Add a full native JSON parser to Kore.
Mostly compliant, ignores \uXXXX in strings for now.
New API functions:
void kore_json_init(struct kore_json *json, const u_int8_t *data, size_t len);
- Prepares JSON data for parsing.
int kore_json_parse(struct kore_json *json)
- Parses the JSON data prepared via kore_json_init. Returns KORE_RESULT_ERROR
if parsing failed or KORE_RESULT_OK if it succeeded.
struct kore_json_item *kore_json_get(struct kore_json *json, const char *path,
int type);
- Try to find the object matching a given search patch and type.
eg, given a JSON structure of:
{
"reasons": {
"strings": [
"first reason",
"second"
]
}
}
one can obtain the second element in the reasons.strings array via:
item = kore_json_get(json, "reasons/strings[0]", KORE_JSON_TYPE_STRING);
Returns NULL if the item was not found or a type mismatch was hit,
otherwise will return the item of that type.
The kore_json_item data structure has a data member that contains the
relevant bits depending on the type:
KORE_JSON_TYPE_ARRAY, KORE_JSON_TYPE_OBJECT:
the data.items member is valid.
KORE_JSON_TYPE_STRING:
the data.string member is valid.
KORE_JSON_TYPE_NUMBER:
the data.number member is valid.
KORE_JSON_TYPE_LITERAL:
the data.literal member is valid.
void kore_json_cleanup(struct kore_json *json);
- Cleanup any resources
const char *kore_json_strerror(struct kore_json *json);
- Return pointer to human readable error string.
2019-10-20 23:22:11 +02:00
|
|
|
|
2022-02-17 13:45:28 +01:00
|
|
|
/* keymgr.c */
|
2016-06-08 13:55:14 +02:00
|
|
|
void kore_keymgr_run(void);
|
2018-07-11 09:44:29 +02:00
|
|
|
void kore_keymgr_cleanup(int);
|
2016-06-08 13:55:14 +02:00
|
|
|
|
2015-04-01 13:25:10 +02:00
|
|
|
#if defined(__cplusplus)
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-04-17 22:34:27 +02:00
|
|
|
#endif /* !__H_KORE_H */
|