Example #1
0
static uintmax_t add_iovec(mustache_api_t *api,
                           void *userdata,
                           const char *buffer,
                           uintmax_t buffer_size)
{
	IGNORE_FUNCTION_PARAMETER(api);

	fortune_ctx_t * const fortune_ctx = userdata;
	iovec_list_t *iovec_list = fortune_ctx->iovec_list_iter;
	uintmax_t ret = 1;

	if (iovec_list->iovcnt >= iovec_list->max_iovcnt) {
		const size_t sz = offsetof(iovec_list_t, iov) + MAX_IOVEC * sizeof(h2o_iovec_t);

		iovec_list = h2o_mem_alloc_pool(&fortune_ctx->req->pool, sz);

		if (iovec_list) {
			memset(iovec_list, 0, offsetof(iovec_list_t, iov));
			iovec_list->max_iovcnt = MAX_IOVEC;
			fortune_ctx->iovec_list_iter->l.next = &iovec_list->l;
			fortune_ctx->iovec_list_iter = iovec_list;
		}
		else
			ret = 0;
	}

	if (ret) {
		memset(iovec_list->iov + iovec_list->iovcnt, 0, sizeof(*iovec_list->iov));
		iovec_list->iov[iovec_list->iovcnt].base = (char *) buffer;
		iovec_list->iov[iovec_list->iovcnt++].len = buffer_size;
		fortune_ctx->content_length += buffer_size;
	}

	return ret;
}
static void process_messages(h2o_multithread_receiver_t *receiver, h2o_linklist_t *messages)
{
	IGNORE_FUNCTION_PARAMETER(messages);

	thread_context_t * const ctx = H2O_STRUCT_FROM_MEMBER(thread_context_t,
	                                                      event_loop.h2o_receiver,
	                                                      receiver);

	h2o_socket_read_stop(ctx->event_loop.h2o_socket);
}
Example #3
0
static uintmax_t read_template(mustache_api_t *api,
                               void *userdata,
                               char *buffer,
                               uintmax_t buffer_size)
{
	IGNORE_FUNCTION_PARAMETER(api);

	const template_input_t * const template_input = userdata;

	return fread(buffer, sizeof(*buffer), buffer_size, template_input->input);
}
Example #4
0
static void template_error(mustache_api_t *api,
                           void *userdata,
                           uintmax_t lineno,
                           const char *error)
{
	IGNORE_FUNCTION_PARAMETER(api);

	const template_input_t * const template_input = userdata;

	print_error(template_input->name, lineno, "mustache_compile", error);
}
Example #5
0
int fortunes(struct st_h2o_handler_t *self, h2o_req_t *req)
{
	IGNORE_FUNCTION_PARAMETER(self);

	thread_context_t * const ctx = H2O_STRUCT_FROM_MEMBER(thread_context_t,
	                                                      event_loop.h2o_ctx,
	                                                      req->conn->ctx);
	fortune_ctx_t * const fortune_ctx = h2o_mem_alloc_shared(&req->pool,
	                                                         sizeof(*fortune_ctx),
	                                                         cleanup_fortunes);

	if (fortune_ctx) {
		fortune_t * const fortune = h2o_mem_alloc_pool(&req->pool, sizeof(*fortune));

		if (fortune) {
			memset(fortune, 0, sizeof(*fortune));
			fortune->id.base = NEW_FORTUNE_ID;
			fortune->id.len = sizeof(NEW_FORTUNE_ID) - 1;
			fortune->message.base = NEW_FORTUNE_MESSAGE;
			fortune->message.len = sizeof(NEW_FORTUNE_MESSAGE) - 1;
			memset(fortune_ctx, 0, sizeof(*fortune_ctx));
			fortune_ctx->generator.proceed = complete_fortunes;
			fortune_ctx->num_result = 1;
			fortune_ctx->param.command = FORTUNE_TABLE_NAME;
			fortune_ctx->param.on_error = on_fortune_error;
			fortune_ctx->param.on_result = on_fortune_result;
			fortune_ctx->param.on_timeout = on_fortune_timeout;
			fortune_ctx->param.flags = IS_PREPARED;
			fortune_ctx->req = req;
			fortune_ctx->result = &fortune->l;

			if (execute_query(ctx, &fortune_ctx->param))
				send_service_unavailable_error(DB_REQ_ERROR, req);
		}
		else
			send_error(INTERNAL_SERVER_ERROR, REQ_ERROR, req);
	}
	else
		send_error(INTERNAL_SERVER_ERROR, REQ_ERROR, req);

	return 0;
}
static void process_messages(h2o_multithread_receiver_t *receiver, h2o_linklist_t *messages)
{
	IGNORE_FUNCTION_PARAMETER(messages);

	global_thread_data_t * const global_thread_data = H2O_STRUCT_FROM_MEMBER(global_thread_data_t,
	                                                                         h2o_receiver,
	                                                                         receiver);

	// Close the listening sockets immediately, so that if another instance of
	// the application is started before the current one exits (e.g. when doing
	// an update), it will accept all incoming connections.
	if (global_thread_data->ctx->event_loop.h2o_https_socket) {
		h2o_socket_read_stop(global_thread_data->ctx->event_loop.h2o_https_socket);
		h2o_socket_close(global_thread_data->ctx->event_loop.h2o_https_socket);
		global_thread_data->ctx->event_loop.h2o_https_socket = NULL;
	}

	if (global_thread_data->ctx->event_loop.h2o_socket) {
		h2o_socket_read_stop(global_thread_data->ctx->event_loop.h2o_socket);
		h2o_socket_close(global_thread_data->ctx->event_loop.h2o_socket);
		global_thread_data->ctx->event_loop.h2o_socket = NULL;
	}
}
Example #7
0
static uintmax_t prerender_variable(mustache_api_t *api,
                                    void *userdata,
                                    mustache_token_variable_t *token)
{
	IGNORE_FUNCTION_PARAMETER(api);

	bool * const in_section = userdata;
	uintmax_t ret = 0;

	if (*in_section) {
		if (token->text_length == sizeof(ID_FIELD_NAME) - 1 &&
		    !memcmp(token->text, ID_FIELD_NAME, sizeof(ID_FIELD_NAME) - 1)) {
			token->userdata = (void *) offsetof(fortune_t, id);
			ret = 1;
		}
		else if (token->text_length == sizeof(MESSAGE_FIELD_NAME) - 1 &&
		         !memcmp(token->text, MESSAGE_FIELD_NAME, sizeof(MESSAGE_FIELD_NAME) - 1)) {
			token->userdata = (void *) offsetof(fortune_t, message);
			ret = 1;
		}
	}

	return ret;
}
static int cached_queries(struct st_h2o_handler_t *self, h2o_req_t *req)
{
	IGNORE_FUNCTION_PARAMETER(self);
	return do_multiple_queries(false, true, req);
}