2013-04-17 22:34:27 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2013 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
|
|
|
|
* 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
|
|
|
|
|
|
|
|
#define KORE_RESULT_ERROR 0
|
|
|
|
#define KORE_RESULT_OK 1
|
|
|
|
|
|
|
|
#define errno_s strerror(errno)
|
2013-04-21 20:21:46 +02:00
|
|
|
#define ssl_errno_s ERR_error_string(ERR_get_error(), NULL)
|
2013-05-30 19:36:42 +02:00
|
|
|
|
|
|
|
#if defined(KORE_DEBUG)
|
2013-04-17 22:34:27 +02:00
|
|
|
#define kore_log(fmt, ...) \
|
|
|
|
kore_log_internal(__FILE__, __LINE__, fmt, ##__VA_ARGS__)
|
2013-05-30 19:36:42 +02:00
|
|
|
#else
|
|
|
|
#define kore_log(fmt, ...)
|
|
|
|
#endif
|
2013-04-17 22:34:27 +02:00
|
|
|
|
2013-04-28 23:42:13 +02:00
|
|
|
#define NETBUF_RECV 0
|
|
|
|
#define NETBUF_SEND 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
|
|
|
|
#define NETBUF_RETAIN 0x04
|
|
|
|
|
2013-04-17 22:34:27 +02:00
|
|
|
struct netbuf {
|
2013-04-28 19:11:44 +02:00
|
|
|
u_int8_t *buf;
|
2013-04-17 22:34:27 +02:00
|
|
|
u_int32_t offset;
|
2013-04-28 19:11:44 +02:00
|
|
|
u_int32_t 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
|
|
|
|
2013-04-17 22:34:27 +02:00
|
|
|
void *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;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct listener {
|
|
|
|
int fd;
|
|
|
|
struct sockaddr_in sin;
|
|
|
|
};
|
|
|
|
|
2013-05-02 09:10:35 +02:00
|
|
|
#define CONN_STATE_UNKNOWN 0
|
|
|
|
#define CONN_STATE_SSL_SHAKE 1
|
|
|
|
#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
|
|
|
|
#define CONN_PROTO_SPDY 1
|
|
|
|
#define CONN_PROTO_HTTP 2
|
|
|
|
|
2013-05-01 13:43:47 +02:00
|
|
|
#define CONN_READ_POSSIBLE 0x01
|
|
|
|
#define CONN_WRITE_POSSIBLE 0x02
|
|
|
|
|
2013-04-17 22:34:27 +02:00
|
|
|
struct connection {
|
|
|
|
int fd;
|
2013-04-21 20:21:46 +02:00
|
|
|
int state;
|
2013-04-21 20:35:47 +02:00
|
|
|
int proto;
|
2013-04-17 22:34:27 +02:00
|
|
|
struct sockaddr_in sin;
|
|
|
|
void *owner;
|
2013-04-21 20:21:46 +02:00
|
|
|
SSL *ssl;
|
2013-05-01 13:43:47 +02:00
|
|
|
int flags;
|
2013-05-30 19:36:42 +02:00
|
|
|
pthread_mutex_t lock;
|
2013-04-17 22:34:27 +02:00
|
|
|
|
2013-05-01 12:23:21 +02:00
|
|
|
u_int8_t inflate_started;
|
|
|
|
z_stream z_inflate;
|
|
|
|
u_int8_t deflate_started;
|
|
|
|
z_stream z_deflate;
|
|
|
|
|
2013-04-17 22:34:27 +02:00
|
|
|
TAILQ_HEAD(, netbuf) send_queue;
|
|
|
|
TAILQ_HEAD(, netbuf) recv_queue;
|
2013-04-29 23:35:36 +02:00
|
|
|
|
2013-05-30 19:36:42 +02:00
|
|
|
u_int32_t client_stream_id;
|
2013-04-29 23:35:36 +02:00
|
|
|
TAILQ_HEAD(, spdy_stream) spdy_streams;
|
2013-05-02 09:10:35 +02:00
|
|
|
|
|
|
|
TAILQ_ENTRY(connection) list;
|
2013-04-17 22:34:27 +02:00
|
|
|
};
|
|
|
|
|
2013-05-01 16:03:48 +02:00
|
|
|
#define HANDLER_TYPE_STATIC 1
|
|
|
|
#define HANDLER_TYPE_DYNAMIC 2
|
|
|
|
|
|
|
|
struct kore_module_handle {
|
2013-05-29 14:29:46 +02:00
|
|
|
char *path;
|
2013-05-03 00:04:06 +02:00
|
|
|
char *func;
|
|
|
|
void *addr;
|
2013-05-01 16:03:48 +02:00
|
|
|
int type;
|
2013-05-29 14:29:46 +02:00
|
|
|
regex_t rctx;
|
2013-05-01 16:03:48 +02:00
|
|
|
|
|
|
|
TAILQ_ENTRY(kore_module_handle) list;
|
|
|
|
};
|
|
|
|
|
2013-05-30 19:36:42 +02:00
|
|
|
struct kore_worker {
|
|
|
|
u_int8_t id;
|
|
|
|
pthread_t pctx;
|
|
|
|
pthread_mutex_t lock;
|
|
|
|
pthread_cond_t cond;
|
|
|
|
u_int32_t load;
|
|
|
|
|
|
|
|
TAILQ_HEAD(, http_request) requests;
|
|
|
|
TAILQ_ENTRY(kore_worker) list;
|
|
|
|
};
|
|
|
|
|
2013-05-02 15:14:00 +02:00
|
|
|
#define KORE_BUF_INITIAL 128
|
|
|
|
#define KORE_BUF_INCREMENT KORE_BUF_INITIAL
|
|
|
|
|
|
|
|
struct kore_buf {
|
|
|
|
u_int8_t *data;
|
|
|
|
u_int32_t length;
|
|
|
|
u_int32_t offset;
|
|
|
|
};
|
|
|
|
|
2013-05-04 19:09:07 +02:00
|
|
|
struct buf_vec {
|
|
|
|
u_int8_t *data;
|
|
|
|
u_int32_t length;
|
|
|
|
};
|
|
|
|
|
2013-05-01 16:03:48 +02:00
|
|
|
extern int server_port;
|
|
|
|
extern char *server_ip;
|
2013-05-04 22:18:27 +02:00
|
|
|
extern char *chroot_path;
|
|
|
|
extern char *runas_user;
|
2013-05-30 19:36:42 +02:00
|
|
|
extern u_int8_t worker_count;
|
2013-05-01 16:03:48 +02:00
|
|
|
|
2013-04-17 22:34:27 +02:00
|
|
|
void *kore_malloc(size_t);
|
|
|
|
void *kore_calloc(size_t, size_t);
|
|
|
|
void *kore_realloc(void *, size_t);
|
2013-05-01 20:10:45 +02:00
|
|
|
time_t kore_date_to_time(char *);
|
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 *);
|
2013-05-01 16:03:48 +02:00
|
|
|
void kore_parse_config(const char *);
|
2013-05-01 00:35:33 +02:00
|
|
|
void kore_strlcpy(char *, const char *, size_t);
|
2013-05-01 08:09:04 +02:00
|
|
|
void kore_server_disconnect(struct connection *);
|
2013-05-01 20:10:45 +02:00
|
|
|
int kore_split_string(char *, char *, char **, size_t);
|
2013-05-01 16:03:48 +02:00
|
|
|
long long kore_strtonum(const char *, long long, long long, int *);
|
|
|
|
|
|
|
|
void kore_module_load(char *);
|
2013-05-03 00:04:06 +02:00
|
|
|
void kore_module_reload(void);
|
2013-05-01 16:03:48 +02:00
|
|
|
int kore_module_loaded(void);
|
2013-05-29 14:29:46 +02:00
|
|
|
int kore_module_domain_new(char *);
|
2013-05-02 13:30:13 +02:00
|
|
|
void *kore_module_handler_find(char *, char *);
|
|
|
|
int kore_module_handler_new(char *, char *, char *, int);
|
2013-04-17 22:34:27 +02:00
|
|
|
|
2013-05-30 19:36:42 +02:00
|
|
|
void kore_worker_delegate(struct http_request *);
|
|
|
|
|
2013-04-17 22:34:27 +02:00
|
|
|
void fatal(const char *, ...);
|
|
|
|
void kore_log_internal(char *, int, const char *, ...);
|
|
|
|
|
2013-05-01 00:35:33 +02:00
|
|
|
u_int16_t net_read16(u_int8_t *);
|
|
|
|
u_int32_t net_read32(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);
|
2013-04-28 19:11:44 +02:00
|
|
|
int net_recv(struct connection *);
|
|
|
|
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 *);
|
2013-05-02 14:47:02 +02:00
|
|
|
void net_recv_queue(struct connection *, size_t, int,
|
2013-05-01 13:43:47 +02:00
|
|
|
struct netbuf **, int (*cb)(struct netbuf *));
|
2013-04-28 23:42:13 +02:00
|
|
|
int net_recv_expand(struct connection *c, struct netbuf *, size_t,
|
2013-04-28 19:11:44 +02:00
|
|
|
int (*cb)(struct netbuf *));
|
2013-05-02 14:47:02 +02:00
|
|
|
void net_send_queue(struct connection *, u_int8_t *, size_t, int,
|
2013-05-01 13:43:47 +02:00
|
|
|
struct netbuf **, int (*cb)(struct netbuf *));
|
2013-04-28 19:11:44 +02:00
|
|
|
|
2013-05-02 15:14:00 +02:00
|
|
|
struct kore_buf *kore_buf_create(u_int32_t);
|
|
|
|
void kore_buf_append(struct kore_buf *, u_int8_t *, u_int32_t);
|
|
|
|
u_int8_t *kore_buf_release(struct kore_buf *, u_int32_t *);
|
2013-05-04 19:09:07 +02:00
|
|
|
void kore_buf_appendf(struct kore_buf *, const char *, ...);
|
|
|
|
void kore_buf_appendv(struct kore_buf *, struct buf_vec *, u_int16_t);
|
2013-05-02 15:14:00 +02:00
|
|
|
|
2013-05-01 12:23:21 +02:00
|
|
|
struct spdy_header_block *spdy_header_block_create(int);
|
2013-05-01 21:16:09 +02:00
|
|
|
struct spdy_stream *spdy_stream_lookup(struct connection *, u_int32_t);
|
|
|
|
int spdy_stream_get_header(struct spdy_header_block *,
|
|
|
|
char *, char **);
|
2013-05-01 12:23:21 +02:00
|
|
|
|
2013-05-01 08:09:04 +02:00
|
|
|
int spdy_frame_recv(struct netbuf *);
|
2013-05-02 14:47:02 +02:00
|
|
|
void spdy_frame_send(struct connection *, u_int16_t,
|
2013-05-02 17:30:06 +02:00
|
|
|
u_int8_t, u_int32_t, struct spdy_stream *, u_int32_t);
|
2013-05-01 12:23:21 +02:00
|
|
|
void spdy_header_block_add(struct spdy_header_block *,
|
|
|
|
char *, char *);
|
|
|
|
u_int8_t *spdy_header_block_release(struct connection *,
|
|
|
|
struct spdy_header_block *, u_int32_t *);
|
2013-04-28 19:11:44 +02:00
|
|
|
|
2013-04-17 22:34:27 +02:00
|
|
|
#endif /* !__H_KORE_H */
|