Commit graph

39 commits

Author SHA1 Message Date
Andy Green
10da4c1236 fuzzer eliminate hsecond ah free path firing assert sentinel
Signed-off-by: Andy Green <andy.green@linaro.org>
2016-01-20 09:37:49 +08:00
Andy Green
77ec61e44f server check cb return during establish
Signed-off-by: Andy Green <andy.green@linaro.org>
2015-12-18 00:56:31 +08:00
Andy Green
6d64539fcb lws_get_context not _ctx
Signed-off-by: Andy Green <andy.green@linaro.org>
2015-12-17 18:25:25 +08:00
Andy Green
54806b1541 clean internal refactor
- Mainly symbol length reduction
 - Whitespace clean
 - Code refactor for linear flow
 - Audit @Context for API docs vs changes

Signed-off-by: Andy Green <andy.green@linaro.org>
2015-12-17 17:03:59 +08:00
Andy Green
00c6d1579c public api remove context from user callback API BREAK
Since struct lws (wsi) now has his own context pointer,
we were able to remove the need for passing context
almost everywhere in the apis.

In turn, that means there's no real use for context being
passed to every callback; in the rare cases context is
needed user code can get it with lws_get_ctx(wsi)

Signed-off-by: Andy Green <andy.green@linaro.org>
2015-12-17 07:54:44 +08:00
Andy Green
6b5de70f4f refactor needless context with wsi paramater passing
Now we bit the bullet and gave each wsi an lws_context *, many
internal apis that take both a context and wsi parameter only
need the wsi.

Also simplify parser code by making a temp var for
allocated_headers * instead of the longwinded
dereference chain everywhere.

Signed-off-by: Andy Green <andy.green@linaro.org>
2015-12-15 21:15:58 +08:00
Andy Green
40110e84ab whitespace trailing mass cleanout
Signed-off-by: Andy Green <andy.green@linaro.org>
2015-12-14 08:52:03 +08:00
Andy Green
d2ac22c27a make protocols const require explicit context API BREAK
The user protocols struct has not been const until now.

This has been painful for a while because the semantics of the protocols
struct look like it's going to be treated as const.

At context creation, the protocols struct has been getting marked with the context,
and three apis exploited that to only need to be passed a pointer to a protocol to
get access to the context.

This patch removes the two writeable members in the context (these were never directly
used by user code), changes all pointers to protocols to be const, and adds an explicit
first argument to the three affected apis so they can have access to context.

The three affected apis are these

 LWS_VISIBLE LWS_EXTERN int
-lws_callback_on_writable_all_protocol(const struct lws_protocols *protocol);
+lws_callback_on_writable_all_protocol(const struct lws_context *context,
+                                     const struct lws_protocols *protocol);

 LWS_VISIBLE LWS_EXTERN int
-lws_callback_all_protocol(const struct lws_protocols *protocol, int reason);
+lws_callback_all_protocol(struct lws_context *context,
+                         const struct lws_protocols *protocol, int reason);

 LWS_VISIBLE LWS_EXTERN void
-lws_rx_flow_allow_all_protocol(const struct lws_protocols *protocol);
+lws_rx_flow_allow_all_protocol(const struct lws_context *context,
+                              const struct lws_protocols *protocol);

unfortunately the original apis can no longer be emulated and users of them must update.

Signed-off-by: Andy Green <andy.green@linaro.org>
2015-12-14 06:43:26 +08:00
Andy Green
8203be6742 lws_get_ctx conversion
Signed-off-by: Andy Green <andy.green@linaro.org>
2015-12-14 06:43:24 +08:00
Alexander Bruines
8266450ba2 Access to wsi->ssl at LWS_CALLBACK_ESTABLISHED 2015-12-09 07:27:15 +08:00
Andy Green
5c9660da61 clean tidy the worst whitespace alignment probs due to mass token name length changes
Signed-off-by: Andy Green <andy.green@linaro.org>
2015-12-04 11:30:53 +08:00
Andy Green
4b85c1d4ac api rationalization: eliminate all libwebsocket[s]_ prefixes
This nukes all the oldstyle prefixes except in the compatibility code.

struct libwebsockets becomes struct lws too.

The api docs are updated accordingly as are the READMEs that mention
those apis.

Signed-off-by: Andy Green <andy.green@linaro.org>
2015-12-04 11:08:32 +08:00
Andy Green
3ef579b4f9 api rationalization eliminate oldstyle internal api names
Between changing to lws_ a few years ago and the previous two
patches migrating the public apis, there are only a few
internal functions left using libwebsocket_*.

Change those to also use lws_ without regard to compatibility
since they were never visible outside the library.

Signed-off-by: Andy Green <andy.green@linaro.org>
2015-12-04 09:23:56 +08:00
Andy Green
6230476455 api rationalization use new names internally
Change all internal uses of rationalized public apis to reflect the
new names.

Theer are a few things that got changed as side effect of search/replace
matches, but these are almost all internal.  I added a compatibility define
for the public enum that got renamed.

Theoretically existing code should not notice the difference from these
two patches.  And new code will find the new names.

https://github.com/warmcat/libwebsockets/issues/357

Signed-off-by: Andy Green <andy.green@linaro.org>
2015-12-04 08:43:54 +08:00
Andy Green
8fb338f71c parser restrict unknown header paranoia to server methods
Signed-off-by: Andy Green <andy.green@linaro.org>
2015-04-07 08:19:30 +08:00
Alejandro Mery
6ff28248aa Subject: [PATCH] Use custom allocator
Signed-off-by: Alejandro Mery <amery@geeks.cl>
2014-12-05 07:26:26 +08:00
Andy Green
62fe015455 revert 187
Signed-off-by: Andy Green <andy.green@linaro.org>
2014-12-01 19:28:28 +08:00
Andrew Canaday
a19d485b80 Don't free wsi->u.hdr.ah except through lws_free_header_table (exception: server.c frees 'ah' after copying the header pointer and transitioning the union state). 2014-11-07 11:25:36 +08:00
Rene Jager
c0eb2c3e9d Subject: [PATCH] fixes for handling multiple protocols in handshake 2014-10-29 09:39:34 +08:00
Andy Green
024eb6c80c http2 can keep upgraded connection up
Signed-off-by: Andy Green <andy.green@linaro.org>
2014-10-08 12:00:53 +08:00
Andy Green
104316eb8f internal SHA1 users all use libwebsockets_SHA1
Signed-off-by: Andy Green <andy.green@linaro.org>
2014-09-26 05:56:23 +08:00
Andy Green
e7016aae2b fixup no extentsion around last clean
Signed-off-by: Andy Green <andy.green@linaro.org>
2014-04-10 15:15:13 +08:00
Andy Green
d7340c141f clean=various ifdef reduction
Signed-off-by: Andy Green <andy.green@linaro.org>
2014-04-10 14:08:10 +08:00
Andy Green
2c24ec0211 refactor out most NO_EXTENSIONS
Signed-off-by: Andy Green <andy.green@linaro.org>
2014-04-02 19:45:42 +08:00
Andy Green
fc7c5e4539 reflect send completeness in lws_write return
under load, writing packet sizes to the socket that are normally fine
can do partial writes, eg asking to write 4096 may only take 2800 of
it and return 2800 from the actual send.

Until now lws assumed that if it was safe to send, it could take any
size buffer, that's not the case under load.

This patch changes lws_write to return the amount actually taken...
that and the meaning of it becomes tricky when dealing with
compressed links, the amount taken and the amount sent differ.  Also
there is no way to recover at the moment from a protocol-encoded
frame only being partially accepted... however for http file send
content it can and does recover now.

Small frames don't have to take any care about it but large atomic
sends (> 2K) have been seen to fail under load.

Signed-off-by: Andy Green <andy.green@linaro.org>
2013-02-23 10:50:10 +08:00
Andy Green
2af4d5b2e2 remove lws_ensure_user_space from public api change return
The function has a logical problem when the size of the requested
allocation is 0, it will return NULL which is overloaded as
failure.

Actually the whole function is evil as an api, this patch moves
it out of the public API space and fixes it to return 0 for
success or 1 for fail.  Private code does not need to to return
wsi->user_space and public code should only get that from the
callback as discussed on trac recently.

Thanks to Edwin for debugging the problem.

Reported-by: Edwin van den Oetelaar <oetelaar.automatisering@gmail.com>
Signed-off-by: Andy Green <andy.green@linaro.org>
2013-02-18 16:30:10 +08:00
Andy Green
cecf5e73cf eliminate snprintf
The two cases where I introduced snprintf are either already
safe for buffer overflow or can be made so with one extra
statement, allowing sprintf.

Signed-off-by: Andy Green <andy.green@linaro.org>
2013-02-12 10:13:12 +08:00
Joakim Soderberg
63ff120ba5 Fixed compilation on Windows. 2013-02-12 09:58:12 +08:00
Andy Green
b5b23199f6 style cleanup
This brings the library sources into compliance with checkpatch
style except for three or four exceptions like WIN32 related stuff
and one long string constant I don't want to break into multiple
sprintf calls.

There should be no functional or compilability change from all
this (hopefully).

Signed-off-by: Andy Green <andy.green@linaro.org>
2013-02-11 17:13:32 +08:00
Andy Green
16ab3185c4 replace per header mallocs with single malloc 3 level struct
This big patch replaces the malloc / realloc per header
approach used until now with a single three-level struct
that gets malloc'd during the header union phase and freed
in one go when we transition to a different union phase.

It's more expensive in that we malloc a bit more than 4Kbytes,
but it's a lot cheaper in terms of malloc, frees, heap fragmentation,
no reallocs, nothing to configure.  It also moves from arrays of
pointers (8 bytes on x86_64) to unsigned short offsets into the
data array, (2 bytes on all platforms).

The 3-level thing is all in one struct

 - array indexed by the header enum, pointing to first "fragment" index
	(ie, header type to fragment lookup, or 0 for none)

 - array of fragments indexes, enough for 2 x the number of known headers
	(fragment array... note that fragments can point to a "next"
	fragment if the same header is spread across multiple entries)

 - linear char array where the known header payload gets written
	(fragments point into null-terminated strings stored in here,
	only the known header content is stored)

http headers can legally be split over multiple headers of the same
name which should be concatenated.  This scheme does not linearly
conatenate them but uses a linked list in the fragment structs to
link them.  There are apis to get the total length and copy out a
linear, concatenated version to a buffer.

Signed-off-by: Andy Green <andy.green@linaro.org>
2013-02-11 11:10:57 +08:00
Andy Green
60fbc63513 use part of service buffer to make response not malloc
Done with an offset because the encoded key is stored at the
start of service_buffer at this time

Signed-off-by: Andy Green <andy.green@linaro.org>
2013-02-11 10:19:59 +08:00
Andy Green
e48ba315b8 use context service buffer instead of stack for clent_connect
Signed-off-by: Andy Green <andy.green@linaro.org>
2013-02-11 00:34:43 +08:00
Andy Green
5449511d3e remove fixed rx buffer allow definition per protocol
A new protocol member is defined that controls the size of rx
buffer allocation per connection.  For compatibility 0 size
allocates 4096, but you should adapt your protocol definition
array in the user code to declare an appropriate value.

See the changelog for more detail.

The advantage is the rx frame buffer size is now tailored to
what is expected from the protocol, rather than being fixed
to a default of 4096.  If your protocol only sends frames of
a dozen bytes this allows you to only allocate an rx frame
buffer of the same size.

For example the per-connection allocation (excluding headers)
for the test server fell from ~4500 to < 750 bytes with this.

Signed-off-by: Andy Green <andy.green@linaro.org>
2013-02-08 13:16:07 +08:00
Andy Green
68a672bb44 unionize header token array
This reduces the size of struct libwebscocket from 4840 to 4552
on x86_64

There are also big benefits on malloc pool fragmentation and
allocation, the header allocations only exist between the first
peer communication and websocket connection establishment for
both server and client.

Signed-off-by: Andy Green <andy.green@linaro.org>
2013-02-07 20:30:56 +08:00
Andy Green
2b57a34677 headers deleted after websocket established
Signed-off-by: Andy Green <andy.green@linaro.org>
2013-02-07 20:30:56 +08:00
Andy Green
623a98dab0 unionize mutually exclusive wsi members
Large chunks of struct libwebsocket members actually have a mutually
exclusive lifecycle, eg, once the http headers are finished they sit
there unused until the instance is destroyed.

This makes a big improvement in memory efficiency by making four
categories of member: always needed, needed for header processing,
needed for http processing, and needed for ws processing.  The last
three are mutually exclusive and bound into a union inside the wsi.

Care needs taking now at "union transitions", although we zeroed down
the struct at init, the other union siblings have been writing the
same memory by the time later member siblings start to use it.  So
it must be cleared down appropriately when we cross from one
mutually-exclusive use to another.

Signed-off-by: Andy Green <andy.green@linaro.org>
2013-01-21 11:06:34 +08:00
Andy Green
5738c0e838 remove all support for pre v13 protocols
Since v13 was defined as the released ietf version the older versions
are deprecated.  This patch strips out everything to do with the older
versions and gets rid of the option to send stuff unmasked.

The in-tree md5 implementation is then also deleted as nothing needs
it any more, 1280 loc are shed in all

Signed-off-by: Andy Green <andy.green@linaro.org>
2013-01-21 09:53:35 +08:00
Andy Green
3182ece3a4 introduce without extensions
The new --without-extensions config flag completely removes all code
and data related to extensions from the build throughout the library
when given.

Signed-off-by: Andy Green <andy.green@linaro.org>
2013-01-20 17:08:31 +08:00
Andy Green
a1ce6be947 refactor and introduce without server configure option
Move server-only stuff into their own files and make building
that depend on not having --without-server on the configure

Make fragments in other places conditional as well

Remove client-related members from struct libwebscket when
building LWS_NO_CLIENT

Apps:

normal: build test server, client, fraggle, ping
--without-client: build test server
--without-server: build test client, ping

Signed-off-by: Andy Green <andy.green@linaro.org>
2013-01-18 11:43:21 +08:00