Commit Graph

101 Commits

Author SHA1 Message Date
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