47 http_state->
db.
data =
self->msu_state;
51 log_warn(
"Could not access database!");
58 log(LOG_HTTP_MSU,
"Partial db access, requeuing state %p", http_state);
69 log(LOG_HTTP_MSU,
"Crafting response for url %s", resp->
url);
75 log_error(
"Unknown return code from database access: %d", rtn);
81 log(LOG_HTTP_MSU,
"Clearing state due to received error message");
90 if (read_state->
req_len == -1) {
91 log(LOG_HTTP_MSU,
"Clearing state (fd: %d)", read_state->
conn.
fd);
95 log(LOG_HTTP_MSU,
"Parsing request: %s (fd: %d)", read_state->
req, read_state->
conn.
fd);
107 log(LOG_PARTIAL_READS,
"Got partial request %.*s (fd: %d)",
120 if (http_state == NULL) {
124 memcpy(&http_state->
conn, &read_state->
conn,
sizeof(read_state->
conn));
127 log(LOG_HTTP_MSU,
"Retrieved state %p (status %d)",
131 log(LOG_PARTIAL_READS,
"Recovering partial read state ID: %u",
150 log(LOG_HTTP_MSU,
"got CON_READING");
153 log_error(
"Error processing fd %d, ID %u, retrieved %d", read_state->
conn.
fd,
158 log(LOG_HTTP_MSU,
"got CON_DB_REQUEST");
177 if ((ip = strtok_r(init_data,
" ", &saveptr)) == NULL) {
178 log_error(
"Did not provide IP for DB initialization to http MSU");
182 if ((port_str = strtok_r(NULL,
" ", &saveptr)) == NULL) {
183 log_error(
"Did not provide port for DB initialization to http MSU");
186 int port = atoi(port_str);
188 if ((n_files_str = strtok_r(NULL,
" ", &saveptr)) == NULL) {
189 log_error(
"Did not provide n_files for DB initialization to http MSU");
192 int n_files = atoi(n_files_str);
203 .
name =
"Webserver_HTTP_MSU",
void init_http_state(struct http_state *state, struct connection *conn)
int msu_error(struct local_msu *msu, struct msu_msg_hdr *hdr, int broadcast)
struct parser_state parser
void * allocate_db_memory()
Header for messages passed to MSUs.
Macro for declaring functions or variables as unused to avoid compiler warnings.
static int http_init(struct local_msu *self, struct msu_init_data *data)
void * msu_get_state(struct local_msu *msu, struct msu_msg_key *key, size_t *size)
Gets the state allocated with the given key.
Wrapper functions for epoll to manage event-based communication.
struct msu_type WEBSERVER_HTTP_MSU_TYPE
State storage that is tied to a specific MSU mesasge.
int craft_error_response(char *url, char *response)
struct msu_type WEBSERVER_CACHE_MSU_TYPE
int32_t id
A shorter, often hashed id for the key of fixed length (used in routing)
#define WS_INCOMPLETE_READ
Logging of status messages to the terminal.
struct msu_type WEBSERVER_WRITE_MSU_TYPE
#define WS_INCOMPLETE_WRITE
void * msu_init_state(struct local_msu *msu, struct msu_msg_key *key, size_t size)
Initializes a new MSU state of the given size with the provided key.
struct msu_type WEBSERVER_READ_MSU_TYPE
Declares the methods available for calling an MSU from another MSU.
static void http_destroy(struct local_msu *self)
size_t data_size
Payload size.
void free_db_memory(void *memory)
#define log_error(fmt,...)
Declares the structures and functions applicable to MSUs on the local machine.
int parse_request(char *req, int req_len, struct http_state *state)
struct msu_type WEBSERVER_REGEX_ROUTING_MSU_TYPE
The structure that represents an MSU located on the local machine.
Data with which an MSU is initialized, and the payload for messages of type CTRL_CREATE_MSU.
int access_database(char *url, struct db_state *state)
int call_msu_type(struct local_msu *sender, struct msu_type *dst_type, struct msu_msg_hdr *hdr, size_t data_size, void *data)
Sends an MSU message to a destination of the given type, utilizing the sending MSU's routing function...
void init_db(char *ip, int port, int n_files)
#define RTN_TO_EVT(rtn__)
static int craft_http_response(struct local_msu *self, struct msu_msg *msg)
static int send_error(struct local_msu *self, struct http_state *http_state, struct msu_msg_hdr *hdr)
static int handle_db(struct http_state *http_state, struct local_msu *self, struct msu_msg *msg)
static int clear_state(struct local_msu *self, struct msu_msg *msg)
#define WEBSERVER_HTTP_MSU_TYPE_ID
int msu_monitor_fd(int fd, uint32_t events, struct local_msu *destination, struct msu_msg_hdr *hdr)
#define log(level, fmt,...)
Log at a custom level.
A message that is to be delivered to an instance of an MSU.
void init_response_state(struct response_state *state, struct connection *conn)
int msu_free_state(struct local_msu *msu, struct msu_msg_key *key)
Frees the state assocated with the given MSU and key.
char * name
Name for the msu type.
#define log_warn(fmt,...)
struct msu_msg_key key
Routing/state key.
static int handle_parsing(struct read_state *read_state, struct http_state *http_state, struct local_msu *self, struct msu_msg *msg)
enum webserver_status status