Commit Graph

522 Commits

Author SHA1 Message Date
Joris Vink 83a16763c8 Always NUL-terminate an asset its data.
This way developers can cast assets to char * without first
having to convert it to a proper C string.

The NUL character is NOT included in the length of the asset.
2014-08-18 13:57:06 +02:00
Joris Vink 105804e325 Make http_status_text() return a const char 2014-08-18 10:37:13 +02:00
Joris Vink 873c68b515 Make http_status_text() available everywhere 2014-08-18 10:34:47 +02:00
Joris Vink 6e6b042388 Add KORE_PGSQL_STATE_WAIT to our example 2014-08-15 12:39:31 +02:00
Joris Vink 8565b47800 Attach tasks/pgsqls to http_requests once more.
This way if an http request is removed while tasks or
pgsqls are still active they are free'd out and cancelled
properly.
2014-08-14 22:05:34 +02:00
Joris Vink f021c8db44 pgsql improvements
* set pgsql->result to NULL when we freed it
* drain the connection pipe just in case in pgsql_conn_release()
2014-08-14 16:43:40 +02:00
Joris Vink 0b3c918ba6 Properly check for connection trouble in the pgsql example 2014-08-14 15:13:47 +02:00
Joris Vink 9ea1e3cb57 Properly release pgsql connection if needed 2014-08-14 14:46:21 +02:00
Joris Vink f93747828c Major pgsql rework.
Gone is the ugly KORE_PGSQL macro that hid an overly complex
state machine for the pgsql api.
Gone is the pgsql array that was attached to http_requests.
Gone are the callback hacks inside the pgsql api.

Instead, I strongly encourage people to use the new state machine
api Kore offers to properly deal with asynchronous queries.

The pgsql example in examples/pgsql has been updated to reflect
these changes.
2014-08-14 14:34:23 +02:00
Joris Vink 856d7b0cb2 Rename HTTP_STATE_OK to HTTP_STATE_CONTINUE 2014-08-14 11:20:04 +02:00
Joris Vink 210fb05a35 Add a hopefully easy to use and optional fsm for page handlers
In order to use this, define states for your page handler:

struct http_state mystates[] = {
	{ "PAGE_STATE_INIT",	page_init },
	{ "PAGE_STATE_RESULT",	page_result },
};

In your page handler you can then simply call http_state_run() with
your states and http_request. This will cause Kore to start calling
your state callbacks beginning at index 0.

State callbacks have the same prototype as page handlers:

int	func(struct http_request *);

However, unlike page handlers they MUST return one of the following:

- HTTP_STATE_OK:	All good, just continue the fsm.
- HTTP_STATE_ERROR:	Abort fsm and return KORE_RESULT_OK to Kore
			(This will cancel the http request).
- HTTP_STATE_RETRY:	Return KORE_RESULT_RETRY to Kore.
			(Kore will retry your page handler next event loop).
- HTTP_STATE_COMPLETE:	The fsm completed, break out cleanly.

Note that using this is completely optional and you can still
use the traditional way of writing page handlers.

The fsm is designed to get rid of the clutter that exists today
in Kore when dealing with non blocking tasks or pgsql calls.
2014-08-13 23:34:30 +02:00
Joris Vink 2e7d6a12a9 closedir() when we're ready traversing it 2014-08-13 14:32:57 +02:00
Joris Vink 29afdd0b21 Make sure opt always contains what we want 2014-08-13 14:32:49 +02:00
Joris Vink e0cdc31c73 Take away the reference to the video if we're not streaming 2014-08-12 09:43:19 +02:00
Joris Vink 0b907312ef let kore build generate certs with a more unique issuer
also fix spacing and asset print information.
2014-08-11 16:11:37 +02:00
Joris Vink d74f039a0c When building assets replace bad characters with an underscore 2014-08-11 13:08:26 +02:00
Joris Vink 7349fab13f Sprinkle kore_snprintf() where appropriate. 2014-08-11 11:02:30 +02:00
Joris Vink 70d9df8896 s/id/user 2014-08-11 11:01:59 +02:00
Joris Vink 97c17f724b Add kore_snprintf() as a wrapper around snprintf(). 2014-08-11 10:45:10 +02:00
Joris Vink 4a4fa4889e Another round of spdy/3.1 improvements.
* Implement flow control window updates if we're receiving data (POSTs)
2014-08-10 21:39:47 +02:00
Joris Vink 1616320490 Add an html5 video streaming example 2014-08-10 19:33:43 +02:00
Joris Vink c665b7d926 Add a callback to http_response_stream().
This way we can get our code called whenever a stream is
completed. This cb handler does stand alone from an http_request
and is passed a netbuf data structure.
2014-08-10 18:46:44 +02:00
Joris Vink 10284d59b6 Another round of spdy/3.1 improvements.
* Always make sure we end the stream properly
* Check for SPDY_FLOW_WINDOW_MAX on window frame updates
* Kill SPDY_STREAM_BLOCKING, once flow control kicks in its per session
2014-08-10 18:18:27 +02:00
Joris Vink 1ef0f3423b Bump to spdy/3.1 2014-08-08 14:48:51 +02:00
Joris Vink 5cca2f1f78 properly implement spdy/3.1 flow control 2014-08-08 14:18:15 +02:00
Joris Vink d2c65b4f62 Change http_response_stream() to only take a base + len 2014-08-07 14:31:45 +02:00
Joris Vink cda09b6065 Add http_response_stream() which can stream data from a buffer to the client. 2014-08-07 14:23:26 +02:00
Joris Vink e3ae1b4e2d Implement some great SPDY improvements.
* Bump spdy announcement to the correct draft version
* When receiving a RST, clean out the netbuf chain of that stream
2014-08-07 10:22:54 +02:00
Joris Vink 966ed3d20d Rename the two functions used to read/set headers.
Rename http_request_header_get() to http_request_header().
Rename http_response_header_add() to http_response_header().
2014-08-05 14:26:31 +02:00
Joris Vink 0413de6a8f fatal if the return value from a page handler isn't what we want. 2014-08-05 14:17:23 +02:00
Joris Vink b27322933b The default pid file is kore.pid so no need to set that explicitely 2014-08-05 13:11:53 +02:00
Joris Vink 891f3454ce Move the default pid file to kore.pid instead of /var/run/kore.pid 2014-08-05 13:10:34 +02:00
Joris Vink 577462379d Deprecate ssl_no_compression config option, its always on. 2014-08-05 13:07:32 +02:00
Joris Vink 79a736fc16 Add a link to yajl repo 2014-08-04 21:06:35 +02:00
Joris Vink 0c5b0d2288 Add an example that parses JSON via yajl 2014-08-04 21:06:02 +02:00
Joris Vink b0700162c4 Make http_post_data_bytes() and http_post_data_text() available 2014-08-04 21:03:26 +02:00
Joris Vink 9b3ff7db53 Lowercase the HTTP headers sent in normal HTTP responses.
SPDY already had this, as required by the spec.
2014-08-04 20:12:31 +02:00
Joris Vink 9dbcf5399f Add headers example 2014-08-04 20:06:59 +02:00
Joris Vink 4010bdd58d Remove kore_cb and its related settings.
After revisiting why this exists in Kore I decided it
does not belong in this platform and instead of letting
it sit there staring at me I rather just kill it.
2014-08-04 19:54:32 +02:00
Joris Vink b3f65ae13f Add a readme to parameters + update some text 2014-08-04 19:02:23 +02:00
Joris Vink 4a7653f195 Add a parameters example.
This example shows how the parameter system in Kore works
and how to use it properly.
2014-08-04 19:00:25 +02:00
Joris Vink 0b36877736 Change kore_buf_appendv() to use vasprintf(). 2014-08-04 18:59:59 +02:00
Joris Vink 7b9b1d5c2c sprinkle more const chars 2014-08-04 12:40:21 +02:00
Joris Vink 31eac77cd2 sprinkle const char where appropriate 2014-08-04 09:48:41 +02:00
Joris Vink 51e1b14271 Do mention we use epoll/kqueue for the less technical readers 2014-08-04 00:12:18 +02:00
Joris Vink d35bb9837d update comment in example tasks.c 2014-08-03 21:47:19 +02:00
Joris Vink 850e39fcfb Add more READMEs 2014-08-03 21:44:14 +02:00
Joris Vink 203fdc139d Examples are now under examples/ 2014-08-03 21:38:07 +02:00
Joris Vink 5c21a120fc s/hello-world/integers 2014-08-03 20:31:40 +02:00
Joris Vink 8f523ecf0c Alter readme a bit 2014-08-03 20:30:39 +02:00