1
0
mirror of https://git.kore.io/kore.git synced 2024-11-12 05:10:48 +01:00
Commit Graph

260 Commits

Author SHA1 Message Date
Joris Vink
0e2f478c75 Fix http_argument_get_*() integer functions. 2014-08-03 15:20:20 +02:00
Joris Vink
83f890e89e No longer preallocate worker_max_connections for the http pools.
Instead use 10% of worker_max_connections up to a maximum of 1000.
2014-07-30 13:20:27 +02:00
Joris Vink
cb3322cd9f Make accesslogs optional 2014-07-30 09:11:21 +02:00
Joris Vink
ea07ddef34 Properly send out early HTTP errors via the appropriate SPDY stream 2014-07-27 21:59:25 +02:00
Joris Vink
8c22f0f004 In http_request_free() remove the req from the owner connection. 2014-07-27 21:00:17 +02:00
Joris Vink
d4cec3427e Properly convert 64bit parameters.
Introduces kore_strtonum64() for just this purpose as to
not taint kore_strtonum() too much.
2014-07-21 01:16:03 +02:00
Joris Vink
ac345410dc Add support for fetching parameters as 64bit integers. 2014-07-20 00:43:32 +02:00
Joris Vink
19d146a09e Introduce http_request_sleep() and http_request_wakeup().
These 2 functions can be used to move an HTTP request
from/to the active http_requests list. Effectively
putting them to "sleep" or "waking them up".

Sprinkle this through the pgsql and task code.

If used correctly greatly reduces overhead for
managing sleeping tasks.
2014-07-04 16:51:19 +02:00
Joris Vink
7b6c03ca5b Task improvements.
Synchronize access to state/result properly so one
can access these from inside the task as well.

Introduce KORE_TASK_STATE_ABORT which will be set
when a task needs to be abort. You can use this
to create tasks that run in a loop until aborted.
2014-07-04 11:28:17 +02:00
Joris Vink
2c6b5e6b0f Normalize kore_*.h headers 2014-07-03 22:14:46 +02:00
Joris Vink
2bf43fe5f8 Unfuck boundary snprintf check, broke multipart forms 2014-07-03 20:10:55 +02:00
Joris Vink
723c99b65e Move kore_pgsql.h into includes/ directly.
Much like kore_tasks.h
2014-06-30 08:42:18 +02:00
Joris Vink
b9bd2e9a14 Move tasks away from http_requests.
Instead if a task is used from inside a request
you MUST call kore_task_bind_request() on it.

This way we can move forward for tasks that
don't belong to page handlers.

Also, some bug fixes for removing http_requests
that are indeed linked to a currently running task.
2014-06-29 20:20:13 +02:00
Joris Vink
146a0189ab More work on the background task implementation.
Tasks are now assigned to available threads instead
of a global task list.

You can now pass messages between your page handler
and the created task using the kore_task_channel_*
functions.

Only one task per time can be assigned to a request
but I feel this is probably a bad design choice.

Preferably we'd want to be able to start tasks
regardless of being in a page handler or not,
this not only ads flexibility but seems like
a better choice overall as it opens a lot more
possibilities about how tasks can be used.
2014-06-29 14:15:40 +02:00
Joris Vink
cf700b34f7 Add initial stab at asynchronous background tasks.
More to follow.
2014-06-28 16:17:18 +02:00
Joris Vink
0cb983adc0 Correct snprintf() usage 2014-04-23 16:29:58 +02:00
Joris Vink
fd7f547013 Fix accesslog under SPDY connections 2014-04-23 13:18:37 +02:00
Joris Vink
4f31d53e76 Allow KORE_RESULT_RETRY from authentication blocks 2014-04-22 23:07:24 +02:00
Joris Vink
d6d6f96ca0 Kore pgsql improvements.
Don't wait for a full event loop until we call the page handler
for a received pgsql result. This speeds up page loads using
KORE_PGSQL by quite a lot, especially on a non busy server.
2014-04-17 10:49:48 +02:00
Joris Vink
52a0764812 HTTP Post improvements for handlers.
Don't crash if we get a Content-length:0 on POST and our
handlers call http_populate_arguments().
2014-04-15 21:18:23 +02:00
Joris Vink
41aed45e4f Do not miscalculate end_headers. 2014-04-09 09:21:22 +02:00
Joris Vink
61b6f823c5 Improvements to pgsql contrib code.
Including but not limited to:
- Correctly use PQerrorMessage() in case we cleanup with PQfinish
- If we get a network error, cleanup the connection
- No longer call the page handler from inside kore_pgsql_handle()
  but instead just put it to sleep in case we don't need it.
  This does grow the http_requests list quite a bit with sleeping
  connections and can perhaps be improved later on.
- Allow us to on error return OK from a page handler from inside
  the completetion block for KORE_PGSQL().
- Count the cummulative time for a request to finish instead
  of the latest run time for the handler.
2014-03-31 00:57:00 +02:00
Joris Vink
2f044cc7eb Initial stab at entering postgresql contrib code.
Has support for full async pgsql queries. Most of the logic
is hidden behind a KORE_PGSQL() macro allowing you to insert
these pgsql calls in your page handlers without blocking the
kore worker while the query is going off.

There is place for improvement here, and perhaps KORE_PGSQL won't
stay as I feel this might overcomplicate things instead of making
them simpler as I thought it would.
2014-03-30 23:54:35 +02:00
Joris Vink
cb17c0d610 When returning a 405 append an Allow header as per rfc 2014-02-27 22:24:28 +01:00
Joris Vink
634bb482d6 Pass the http_request responsible for calling the validator. 2014-02-01 17:47:58 +01:00
Joris Vink
f0a9c1fe73 Major improvements to HTTP/1.1 behaviour, error reporting and handling.
This comes with changes to http_response() (no longer returns a result).
2014-01-29 22:48:51 +01:00
Joris Vink
9a8092bf41 Add authentication blocks for Kore.
Using authentication blocks one can define "authentication" mechanisms
in Kore for page handlers.

This can be used to require a session cookie (validated by your own validator)
for certain page handlers, and hopefully in the future provide a framework
for adding more authentication things (like HTTP Auth).

Right now only cookie checking is available.
2014-01-22 22:55:10 +01:00
Joris Vink
7e8371366f Make sure we properly close a SPDY stream if there's no data. 2014-01-14 22:22:26 +01:00
Joris Vink
b64f674db2 Handle SPDY streams better when sending data. 2014-01-14 21:43:45 +01:00
Joris Vink
517de46790 Kore can now do query strings without lots of dynamic handler voodoo.
Any handler can receive query strings, however if you do not specify
parameters allowed in a param {} block Kore will discard them.
2014-01-13 20:21:20 +01:00
Joris Vink
84d2c7fa0d ULONG_MAX -> LONG_MAX 2013-12-16 18:00:33 +01:00
Joris Vink
c7dcdbcd82 Rework the way validation and param extraction works.
- Parameter validation is now done only when http_process_*()
  is called and upon http_argument_add().
- You MUST have defined your params in a param block or they will
  be filtered out.
- http_argument_lookup() is dead, welcome http_argument_get() and
  its brothers and sisters:
	http_argument_get_string()
	http_argument_get_uint16()
	http_argument_get_int16()
	http_argument_get_uint32()
	http_argument_get_int32()

  They will automatically do bounds checking on integers for you
  and return proper integers or a NUL-terminated string.

- The http_argument_get* functions no longer create an additional
  copy of the string which you need to free. Easier going.
- http_multiple_args() is dead, byebye
- Make some stuff we don't want to share with the modules static.
2013-12-12 00:58:32 +01:00
Joris Vink
0f28b4a62d Enter versioning, starting at 1.0-current 2013-12-10 16:43:19 +01:00
Joris Vink
10aa4a28fe Multipart forms are now also validated via params 2013-12-05 20:28:07 +01:00
Joris Vink
269e5cb007 Strip out port from HTTP host request if its present. 2013-11-18 00:53:08 +01:00
Joris Vink
1e250c1473 Kore now supports GET parameters and automatic validation of GET/POST parameters.
Kore will automatically removes invalid parameters as a security measure.

See modules/examples/module.conf for an example of how this works.
2013-11-10 15:17:15 +01:00
Joris Vink
f17242262b Improve on sending data to the client.
- Attempt to chain as much as we can in the send netbufs
  (keeps down the SSL_write calls, silly seeing it go out with 8 bytes)
- Change NETBUF_SEND_PAYLOAD_MAX to 4K
- Call SSL_write() with max NETBUF_SEND_PAYLOAD_MAX in size
- Go back to flushing the send buffers after each request
- No more need for a fixed pool for nb->buf, go back to the heap for now
- Disable Nagle, we're doing the chaining now anyway
2013-10-26 00:48:09 +02:00
Joris Vink
4247d3139c Chain our sending netbufs together. Gives us a lot less SSL_write() calls. 2013-10-25 14:22:29 +02:00
Joris Vink
4922171d96 Change net_send_queue() in preparation for improving send performance.
No longer takes callbacks, flags, or *out arguments.

Update rest of the code that called these callbacks whenever sending
was completed, instead call them right away now.
2013-10-25 11:10:03 +02:00
Joris Vink
e10486fa10 Change urldecode back to 0 2013-10-24 08:56:17 +02:00
Joris Vink
c30ff58b93 control characters have nothing to do inside a URL. 2013-10-18 12:43:20 +02:00
Joris Vink
5d027b7a21 Decode all url encoded components properly. 2013-10-18 12:32:00 +02:00
Joris Vink
c64d3e7854 Add http_keepalive_time configuration parameter.
Allows you to configure maximum amount of seconds an HTTP connection
can stay open (does not affect SPDY connections). If set to 0 it will
disable keep-alive all together.

Add some inttypes fluff.
2013-10-15 11:10:45 +02:00
Joris Vink
8b47863cd4 Add http_hsts_enable (enabled by default with max-age=31536000) to Kore's configuration file.
If enabled Kore adds the HSTS header to every response.

- Additionally, fix some typos in the example configuration.
- Change default SSL cipher list again, no more RC4 and almost PFS for all browsers.
2013-10-15 10:44:56 +02:00
Joris Vink
88c3a3eb98 Add http_header_max and http_postbody_max configuration variables.
- http_header_max:
	Maximum size of HTTP headers (in non SPDY connections).

- http_postbody_max:
	Maximum size of an HTTP POST body (both in SPDY and HTTP mode).

Right now Kore will simply DC the client, ideally we want to send
a 413 (entity too large) to the client however.

See modules/examples/module.conf for more.
2013-09-22 20:05:24 +02:00
Joris Vink
cffe4afb91 properly count amount of arguments parsed 2013-09-10 14:05:02 +02:00
Joris Vink
25e8f93331 Add support for multipart forms.
New API functions (docs need to be updated):
	- http_file_lookup()
	- http_file_add()
	- http_argument_add()
	- kore_strip_chars()
	- kore_mem_find()

- Add an example under the example module on how files can be read.
2013-09-10 11:02:59 +02:00
Joris Vink
c9d4f70298 - Add SPDY RST control frame handler.
- Keep HTTP requests in connection, so we can delete them if the connection
  ends before the requests do (this way we don't leak them).
- When spdy_stream_close() is called, delete the attached http request.
  (This shouldn't hurt to do, so hopefully won't cause major fallout).
- When parsing HTTP, find the first occurence of end-of-headers so uploads
  with multipart/form-data can succeed properly.
- Add a test upload page to the example module.
2013-09-09 10:59:56 +02:00
Joris Vink
9fa9fd7402 remove useless casts 2013-08-26 08:52:56 +02:00
Joris Vink
a8052c7ac4 Add reason phrases and http status constants (HTTP_STATUS_* see includes/http.h)
Based on work from mendor/ymv via github.
2013-08-19 09:11:31 +02:00
Joris Vink
ef9d37e54b free hdlr_extra if its set 2013-08-14 16:09:09 +02:00
Joris Vink
ecefdb18ab cb_extra -> hdlr_extra and add one to struct connection as well for persistent data across requests. 2013-08-14 15:56:44 +02:00
Joris Vink
34f6d088fa set cb_extra to NULL when req is allocated 2013-08-14 15:15:18 +02:00
Joris Vink
bbb245654d Pass the base for strtoll() to kore_strtonum(), breakage ensues if we depend on the "auto" detection that happens when we pass 0 to strtoll() as base. 2013-08-13 16:13:43 +02:00
Joris Vink
3075162855 Add http_argument_urldecode() which takes a string and decodes any url encoding done to it.
Change kore_strtonum() to pass 0 to strtoll by default so we can use it to convert hex numbers (prepended with 0x) as well.
2013-08-13 14:18:47 +02:00
Joris Vink
ef814a677d Add http_argument_multiple_lookup() and http_argument_multiple_free().
Prototypes:
	int	http_argument_multiple_lookup(struct http_req *req,
		    struct http_arg *args);
	void	http_argument_multiple_free(struct http_arg *args);

These functions can be used to lookup arguments in a single call.

args points to an array of struct http_arg elements. Each of them
have the argument name set and its value set to NULL.

The array must have its last element name field set to NULL.

Upon return http_argument_multiple_lookup() gives the caller the
number of arguments that were successfully found. It makes their values
available under the value field in the struct http_arg array passed.

Example:
	int			v;
	struct http_args	args[4];

	memset(args, 0, sizeof(args));
	args[0].name = "email";
	args[1].name = "password1";
	args[2].name = "password2";
	args[3].name = NULL;

	v = http_argument_multiple_lookup(req, args);
	if (v != 3) {
		kore_debug("argument %s was not present", args[v].name);
	} else {
		for (v = 0; args[v].name != NULL; v++)
			kore_debug("%s -> %s", args[v].name, args[v].value);
	}

	http_argument_multiple_free(args);
2013-08-07 14:41:16 +02:00
Joris Vink
2c1352b226 remove versioning numbers, i hate them. 2013-07-16 15:30:20 +02:00
Joris Vink
341172f844 Do not 0 out everything we allocate, and instead fix the behaviour of the code in the appropriate places. 2013-07-16 09:56:36 +02:00
Joris Vink
ae9fabb84f No need to duplicate the received http buffer. 2013-07-16 09:33:46 +02:00
Joris Vink
29fa49ba83 Add fixed size memory pools and use them throughout Kore. 2013-07-15 11:06:36 +02:00
Joris Vink
9c7aaf179f Remove unneeded malloc result casting, annoying habbit of mine but serves no purpose. 2013-07-13 21:08:55 +02:00
Joris Vink
f59e94a7b6 Add spdy_session_teardown() which can properly teardown a SPDY session.
Use this throughout the spdy code to propagate session errors (if any) occur.

At the same time fix BSD's missing CONN_WRITE_BLOCK
2013-07-13 19:56:38 +02:00
Joris Vink
21a44589fc If we already have all the POST data in the netbuf do not try and read more. 2013-07-10 13:34:42 +02:00
Joris Vink
95bacb5690 Kore will now keep track of page handlers that cause workers to die.
This is useful to track down any issues you might have in your module.

A log entry with a page handler causing issues looks like:
Jul  7 14:44:30 devbook kore[18191]: [parent]: worker 1 (18193)-> status 11
Jul  7 14:44:30 devbook kore[18191]: [parent]: worker 1 (pid: 18193) (hdlr: 0x242d9c0) gone
Jul  7 14:44:30 devbook kore[18191]: [parent]: hdlr serve_intro has caused 2 error(s)
2013-07-07 14:48:32 +02:00
Joris Vink
c1723f2db5 Clean up header includes, based on a diff from Ewan Higgs via github.
And while we're messing in it, make sure bsd.c compiles again.
2013-07-06 20:55:22 +02:00
Joris Vink
0c08b57d3e - add idle timer for normal connections (ie: !SPDY), max 20 seconds.
- use idle timer to make sure we don't block SPDY connections indefinately
  when our window size has reached 0.
2013-07-01 12:08:51 +02:00
Joris Vink
51a9e4db9d Implement SPDY WINDOW_UPDATE and SETTINGS. 2013-07-01 11:30:18 +02:00
Joris Vink
b4a0330a96 - Better spread load between all worker processes.
- Introduce own memory management system on top of malloc to keep track
  of all our allocations and free's. Later we should introduce a pooling
  mechanism for fixed size allocations (http_request comes to mind).
- Introduce ssl_cipher in configuration.

Memory usage is kind of high right now, but it seems its OpenSSL
doing it rather then Kore.
2013-06-27 08:43:07 +02:00
Joris Vink
bf1940225a everybody loves to tout their own horn.. so introduce a server response header 2013-06-26 16:58:01 +02:00
Joris Vink
3e5c17b8a3 refactor code quite a bit. 2013-06-26 11:18:32 +02:00
Joris Vink
a1b400c400 Add access logging to Kore. 2013-06-24 09:36:40 +02:00
Joris Vink
c22eebb6d9 for non spdy clients, attempt to keep the connection open as long as possible (aka, send connection: keep-alive and do not close it till client does). 2013-06-22 20:14:10 +02:00
Joris Vink
8b832f0a37 fix off-by-one 2013-06-20 23:30:03 +02:00
Joris Vink
e7db5ee6b1 rename kore_log to kore_debug, and allow one to turn it off. 2013-06-04 16:30:53 +02:00
Joris Vink
8f8ab92521 upon quit time, workers will not accept new connections but will
handle all outstanding http requests.
2013-06-04 13:43:11 +02:00
Joris Vink
0de28488a6 move from multithreads to single threaded worker processes. 2013-06-04 11:55:38 +02:00
Joris Vink
bb4001d119 ok that was wrong, disconnect http clients whne we're done sending or upon error, not immediately after queueing everything. 2013-05-30 21:57:14 +02:00
Joris Vink
ec5ac40706 wake up the workers once in a while to process anything that is waiting. 2013-05-30 20:55:50 +02:00
Joris Vink
9243f409cc move to a worker based threading approach where we delegate http requests to workers in a round robin basis (later this should be swapped to find the laziest worker and assign the request to that instead). 2013-05-30 19:36:42 +02:00
Joris Vink
3b30920a60 for now, until we properly handle a persistent HTTP connection for non spdy clients make sure we close the connection after handling the HTTP request. 2013-05-04 21:03:53 +02:00
Joris Vink
ce729010f7 - simplify header building using kore_buf_appendf() for normal HTTP requests.
- make sure we dont free nb->buf if its NULL. (semantics).
- remove some superfluffy debug.
- make sure we call [inflate|deflate]End when we dc a client that used zlib.
2013-05-04 20:44:16 +02:00
Joris Vink
45adae62f7 q->value should be set to NULL if a query parameter is present but no value was set for it.
introduce kore_buf_appendv() (much like readv()).
introduce kore_buf_appendf() (printf into buffers).
2013-05-04 19:09:07 +02:00
Joris Vink
088d877715 switch dynamic handlers to regex based patterns, much easier. 2013-05-29 14:29:46 +02:00
Joris Vink
1671698f58 increase sbuf length substantially 2013-05-22 12:50:20 +02:00
Joris Vink
a88b8de6a2 add proper query argument parsing, modules must call
http_populate_arguments() before using http_argument_lookup() to lookup a given argument.

population uses the appropriate query string (from GET or POST) automatically.
2013-05-03 09:09:27 +02:00
Joris Vink
b3cdccbc87 add http_post_data_text() which returns the post data NUL-terminated to the caller. 2013-05-03 07:49:40 +02:00
Joris Vink
85aad24af5 do not NUL terminate the post data, for later. 2013-05-03 07:43:53 +02:00
Joris Vink
2401bd1a9f support for POST in both spdy and normal connections 2013-05-03 07:35:11 +02:00
Joris Vink
879b5716d1 req->method is no longer a string, adapt kore_log() 2013-05-03 01:21:09 +02:00
Joris Vink
ba2ed8d954 host header might not come in second.. 2013-05-02 22:35:29 +02:00
Joris Vink
e7feaaba76 properly close a spdy stream once both sides have FLAG_FIN. 2013-05-02 17:30:06 +02:00
Joris Vink
f61bbe8ff4 move buf stuff back into kore.h, wont need it separately 2013-05-02 15:14:00 +02:00
Joris Vink
84428f7133 move buf stuff into its own header, so we can use it in spdy.h 2013-05-02 14:55:57 +02:00
Joris Vink
60ed3e0fd2 the net qeueuing functions don't need to return status codes, simplifies a lot of other code that revolves around those.
prepare for POST support
2013-05-02 14:47:02 +02:00
Joris Vink
807764614b from now on configuration files must specify a domain for the handlers that follow. This allows for easy subdomain configuration.
example:

domain joris.local
static / serve_index

domain .joris.local
static / serve_another_index
2013-05-02 13:30:13 +02:00
Joris Vink
53cbc1a21e make sure we advance the host buffer properly 2013-05-02 12:11:56 +02:00
Joris Vink
c2520b2ebf oops, sending 2 bytes too much. 2013-05-02 09:25:14 +02:00
Joris Vink
364dc58219 rework disconnecting clients and fix bug where spdy ocnnections could segfault after disconnecting 2013-05-02 09:10:35 +02:00
Joris Vink
b98c688429 remove debug 2013-05-02 04:44:52 +02:00
Joris Vink
2cc4505c8c correct offset 2013-05-02 03:52:53 +02:00
Joris Vink
f46bba50ef add very basic support for HTTP/1.1. 2013-05-02 03:51:04 +02:00
Joris Vink
5f983d575b add flags to net_recv_queue() and net_send_queue(),.
NETBUF_CALL_CB_ALWAYS flag, calls the registered cb everytime data has
been received or sent.
2013-05-02 00:28:49 +02:00
Joris Vink
a9ebf37cae allow modules to add headers to the response before calling http_response()
by calling http_response_header_add().

fix wrong overflow check in spdy_stream_get_header().

html_inject now exports last modified timestamp for the files that are
compiled into the module in the format static_mtime_<type>_<name>.

modules can now look into the request headers using http_request_header_get().
2013-05-01 21:16:09 +02:00
Joris Vink
a228cdba0e introduce kore_split_string() to properly split strings apart.
introduce kore_date_to_time() to conver http-date formatted strings to time_t.
2013-05-01 20:10:45 +02:00
Joris Vink
4ecfd81e6e allow us to pass content-type to http_response() 2013-05-01 16:51:34 +02:00
Joris Vink
d9bbb0b1f1 initial module support 2013-05-01 16:03:48 +02:00
Joris Vink
a074258dcc rework the way events trigger and the way we handle them. follow the manual for once, as edge trigger does not refire until we got an EAGAIN.
introduce net_send_flush() and net_recv_flush() for this purpose, we attempt to make as much headway as possible until we reach EAGAIN or until we can simply pickup again later.

should merge all the stuff in http_response() into a single send buffer, **out is in place in net_send_queue() for that purpose.
2013-05-01 13:43:47 +02:00
Joris Vink
d59847c448 SPDY works, we can serve content. Now for dynamic modules so we can
get stuff on the road.

TODO: add plain HTTP support if SPDY isnt working in the browser.
2013-05-01 12:23:21 +02:00
Joris Vink
848704f74b lots of new stuff, including processing of http requests and an attempt
to build an initial spdy response (SYN frame + header block content).
2013-05-01 08:09:04 +02:00
Joris Vink
05156c9a3a properly deflate/inflate of name/value blocks. and add ability
to get headers from them.
2013-05-01 00:35:33 +02:00