<commit_before>/*
 * Copyright (c) 2015-2020 <NAME> <<EMAIL>>
 *
 * 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.
 */

#include <sys/types.h>
#include <sys/socket.h>

#include <signal.h>

#include "kore.h"
#include "http.h"

struct msg_type {
	u_int8_t		id;
	void			(*cb)(struct kore_msg *, const void *);
	TAILQ_ENTRY(msg_type)	list;
};

static struct msg_type	*msg_type_lookup(u_int8_t);
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 *, const void *);

#if !defined(KORE_NO_HTTP)
static void		msg_type_websocket(struct kore_msg *, const void *);
#endif

static TAILQ_HEAD(, msg_type)	msg_types;
static size_t			cacheidx = 0;
static struct connection	**conncache = NULL;

void
kore_msg_init(void)
{
	TAILQ_INIT(&msg_types);
}

void
kore_msg_parent_init(void)
{
	u_int8_t		idx;
	struct kore_worker	*kw;

	for (idx = 0; idx < worker_count; idx++) {
		if (keymgr_active == 0) {
			if (idx == KORE_WORKER_KEYMGR_IDX ||
			    idx == KORE_WORKER_ACME_IDX)
				continue;
		}

		kw = kore_worker_data(idx);
		kore_msg_parent_add(kw);
	}

	kore_msg_register(KORE_MSG_SHUTDOWN, msg_type_shutdown);
}

void
kore_msg_parent_add(struct kore_worker *kw)
{
	kw->msg[0] = kore_connection_new(NULL);
	kw->msg[0]->fd = kw->pipe[0];
	kw->msg[0]->read = net_read;
	kw->msg[0]->write = net_write;
	kw->msg[0]->proto = CONN_PROTO_MSG;
	kw->msg[0]->state = CONN_STATE_ESTABLISHED;<commit_msg>Skip ACME worker process if ACME isnt built-in.<commit_after>/*
 * Copyright (c) 2015-2020 <NAME> <<EMAIL>>
 *
 * 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.
 */

#include <sys/types.h>
#include <sys/socket.h>

#include <signal.h>

#include "kore.h"
#include "http.h"

struct msg_type {
	u_int8_t		id;
	void			(*cb)(struct kore_msg *, const void *);
	TAILQ_ENTRY(msg_type)	list;
};

static struct msg_type	*msg_type_lookup(u_int8_t);
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 *, const void *);

#if !defined(KORE_NO_HTTP)
static void		msg_type_websocket(struct kore_msg *, const void *);
#endif

static TAILQ_HEAD(, msg_type)	msg_types;
static size_t			cacheidx = 0;
static struct connection	**conncache = NULL;

void
kore_msg_init(void)
{
	TAILQ_INIT(&msg_types);
}

void
kore_msg_parent_init(void)
{
	u_int8_t		idx;
	struct kore_worker	*kw;

	for (idx = 0; idx < worker_count; idx++) {
		if (keymgr_active == 0) {
			if (idx == KORE_WORKER_KEYMGR_IDX ||
			    idx == KORE_WORKER_ACME_IDX)
				continue;
		}

#if !defined(KORE_USE_ACME)
		if (idx == KORE_WORKER_ACME_IDX)
			continue;
#endif

		kw = kore_worker_data(idx);
		kore_msg_parent_add(kw);
	}

	kore_msg_register(KORE_MSG_SHUTDOWN, msg_type_shutdown);
}

void
kore_msg_parent_add(struct kore_worker *kw)
{
	kw->msg[0] = kore_connection_new(NULL);
	kw->msg[0]->fd = kw->pipe[0];
	kw->msg[0]->read = net_read;
	kw->msg[0]->write = net_write;
	kw->msg[0]->proto = CONN_PROTO_MSG;
	kw->msg[0]->state = CONN_STATE_ESTABLISHED;
{'fraction_non_alphanumeric': 0.10492227979274611, 'fraction_numerical': 0.009067357512953367, 'mean_word_length': 4.879441624365482, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4835794', 'n_tokens_mistral': 1766, 'n_tokens_neox': 1639, 'n_words': 477}