Commit Graph
102 Commits
Author SHA1 Message Date
Fred Nicolson c0d103da14 Improved network encoding conversion functions
Now uses optimised/inbuilt functions if available.
2018-03-26 17:34:00 +01:00
Fred Nicolson 4207468ef0 Added the ability to add iterator ranges to packets
So, fr::Packet::add_range(std::begin(container), std::end(container));
2018-03-06 14:31:47 +00:00
Fred Nicolson 2040540e94 Removed use of platform dependant type when dealing with vectors
Previously, fr::Packet would use 'size_t' for dealing with vector sizes. This is not ideal though, as the size of size_t is platform depenant, meaning that fr::Packet's sent on one computer might be incompatible with other systems.
2018-03-05 10:37:09 +00:00
Fred Nicolson addd1cf19b Removed unnecessary copy from fr::Packet:add().
Should improve performance.
2018-03-05 10:28:11 +00:00
Unknown 13f709aebb Added examples for a simple WebSocket client and Server.
Removed automatic ping pong response, and disconnection from fr::WebSocket, as it should be handled by the library user, really.

Updated ReadMe.
2018-03-03 16:02:17 +00:00
Unknown fa843b57c8 Added experimental WebSocket support.
Added Sha1 hash, and Base64 encode implementations which are optionally compiled if websock support is enabled, to assist in the WebSock handshake.

Added WebSocket to manage the WebSock protocol during connections.

Added WebFrame to allow for sending/receiving data through the WebSock protocol easily.
2018-03-01 23:03:05 +00:00
Fred Nicolson 103e0faaae Bug fixes. HTTP parsing improvements. More tests.
Fixed TcpSocket::set_descriptor(nullptr) causing an invalid read from address 0x0.

Improved HTTP response/request parsing so that they report a parse failure if the first few bytes of the HTTP request don't match the expected format rather than continuing to look for an end of header.

Fixed broken fr::Http::url_encode() implementation.

Optimised fr::Http::url_decode() implementation.

Added fr::Http unit tests.
2018-03-01 15:51:57 +00:00
Unknown 62d8b7ba63 Bug fixes. Documentation improvements.
Fixed SSLListener failing to accept SSLSockets properly (not setting the descriptor properly).

TcpSocket::receive_raw and SSLSocket::receive_raw now behave the same, rather than SSLSocket acting more like Socket::receive_all.

Documented specific return values from Socket::receive_all().

Socket::receive_all now returns WouldBlock if the socket is in blocking mode and the first read returns no data, so it doesn't behave like a blocking socket.

Disabled copying/moving of sockets. Copying shouldn't have been enabled, but might add move constructors in the future.

Added Socket::disconnect, which internally just calls close_socket, to allow for protocol-specific disconnect sequences in the future (WebSockets).
2018-02-28 23:44:31 +00:00
Unknown 0840c07e24 Improving build system
Instead of #ifdefing files out, they are no longer included by CMake instead.
2018-02-24 21:14:43 +00:00
Fred Nicolson ff25d11089 Removed socket mutexes. Added more tests. Improved examples.
Socket mutexes are no longer really required, and so have been removed.

Added more tests for network encoding functions, and the URL parser.

The URL parser now returns a path preceeded with a '/' instead of cutting it out. Added get_uri() to URL, for getting the whole URI, so users don't have to concat it themselves from the more specialised functions.

Fixed default socket connect timeout checking for the wrong value.

Fixed request_type_strings not containing all of the possible request types.

Fixed README using old socket close syntax.

Cleaned up the examples a bit.
2018-02-01 11:56:34 +00:00
Fred Nicolson 30354f15bc Added support for connect timeouts.
Both fr::TcpSocket and fr::SSLSocket can have timeouts specified when connecting. This works by putting the socket into non-blocking mode, making a connect, and then selecting on the socket for the requested timeout. If the select times out then we've failed to connect, if it didn't time out then we've connected.
2018-01-10 17:08:16 +00:00
Fred Nicolson b574800a0a Fixed compile warnings and a memory leak
Fixed -fPIC warnings and unused function warnings on GCC. 

Fixed fr::TcpSocket not calling freeaddrinfo() on failure to connect, causing a small leak.
2017-12-01 10:59:00 +00:00
Fred Nicolson c8e03f2df8 Added more tests. Tweaks.
Receiving an http request/response will now return errors like HttpHeaderTooBig, instead of the type being set to that.

Added fr::Socket::status_to_string for converting status values into English strings.
2017-09-25 16:19:47 +01:00
Fred Nicolson abb3655739 Bug fixes and socket improvements
Added the ability to disable certificate verification for SSL sockets which is useful for testing.

Added the ability to specify maximum HTTP request header/body sizes in the CMake build config to prevent a malicious client from causing OOM errors.

Fixed a bug in HttpResponse and HttpRequest parse causing it to abort if the request is invalid in some cases.
2017-09-25 12:29:52 +01:00
Fred Nicolson 987becd8d0 Fixed WSAInit not being called by fr::Listener
This would mean that if a listener was created before a socket, then it would fail to bind.
2017-08-23 11:23:00 +01:00
Fred Nicolson f1db713069 Made POST/GET/HEADER members case insensitive again
It broke things. Bad.
2017-08-22 13:57:08 +01:00
Fred Nicolson fcd97d2829 Added Unprocessable Entity HTTP code to fr::Http 2017-08-04 11:45:36 +01:00
Fred Nicolson 0bd41ec6bd get_remote_address() now works on SSL sockets accepted through SSLListener
Post/get/... data is no longer case insensitive.
2017-08-02 17:32:16 +01:00
Fred Nicolson 0c7d37a8e3 Moved set_remote_address from TcpSocket to Socket
So that SSLSocket has it to. Though the SSLListener still needs to set the remote address after accepting a new connection.
2017-08-01 17:25:53 +01:00
Fred Nicolson cfda0f969e Specified default move/copy constructors/operators to Http/Response/Request 2017-08-01 16:15:43 +01:00
Fred Nicolson dff81f495e Fixed memory leak
fr::SSLSocket did not call mbedtls_net_free. It called mbedtls_ssl_close_notify instead.
2017-07-31 11:58:22 +01:00
Fred Nicolson 84382cad0b Made some changes recommended by Clang-Tidy. 2017-07-20 15:02:43 +01:00
Fred Nicolson f2cebd0847 Work on tests. Bug fixes and tweaks.
Started work on tests for fr::HttpRequest.

Fixed the final POST data variable containing header data it shouldn't (\r\n\r\n).

Fixed fr::Http::header_exists, and family, not converting things to lowercase first.
2017-07-19 17:30:43 +01:00
Fred Nicolson e748fde121 API changes, and lots of fixes.
fr::HttpSocket has been removed.

fr::Sendable has been added. Classes can inherit this if they want to be sendable through sockets. Both fr::Http (which is inherited by fr::HttpRequest and fr::HttpResponse), and fr::Packet inherit this, to allow them to be sent through fr::Socket::send()/fr::Socket::receive().

Fixed broken fr::SocketSelector and fr::SocketReactor, as they no longer accepted fr::Listener's due to fr::Listener no longer inheriting fr::Socket.
2017-07-18 17:34:49 +01:00
Fred Nicolson 7c9dee579f Bug fixes
Fixed HTTP Request receive expecting more bytes than there actually is, and so waiting for more bytes when there is none.
2017-07-12 16:53:34 +01:00
Unknown 93ec4fa999 Bug fixes
Fixed Content-Length header being added to Http responses even if there's a pre-existing one.

Fixed header parsing sometimes adding a carriage return to the header value.

Removed useless copy/move constructors from HttpResponse, causing issues.
2017-07-10 21:47:34 +01:00
Fred Nicolson df509a42f5 Socket and HTTP Response bug fixes
fr::TcpSocket checked if the recv response was greater than 0, which created issues as 0 is a valid result if no data was received and no error occurred.

fr::HttpResponse::construct() now adds in a content-length header.

fr::HttpResponse::parse trims the body if it's larger than content length.

fr::Http::set_uri() now prepends a '/' if one's not provided.

Fixed fr::Http::parse_header from cutting off the end of headers.
2017-07-07 11:05:19 +01:00
Unknown 36f4006343 Added DELETE and PATCH support. 2017-06-19 22:42:37 +01:00
Fred Nicolson 50c62f2c4a Added PUT support 2017-06-16 17:06:34 +01:00
Fred Nicolson aa8509e460 Added move/copy constructors to Http & HttpResponse 2017-06-16 15:16:13 +01:00
Unknown 028677b01a Added tests. Improved error checking. Bug fixes.
Added fr::TcpListener tests.
2017-06-05 20:13:50 +01:00
Unknown eec983c8b7 Added fr::Socket::set_max_packet_size
Can be used to limit the size of packets being received, to prevent malicious attacks.
2017-06-03 14:39:49 +01:00
Fred Nicolson 71874837a0 Added 'WebSocket'.
This is just an abstract class which is inherited by fr::HttpSocket<T>, to allow different web socket types to be stored in a generic container.
2017-06-02 16:38:06 +01:00
Unknown 0778f30d10 Prevented MSVC's inbuild network conversion functions being used
These functions did not play well with the rest of the code, causing float conversion to produce an incorrect value.
2017-05-31 17:02:40 +01:00
Unknown 5778310798 Fixed incompatabilities between GCC and MSCV
Build errors have been fixed, but there are build warnings remaining about unsafe conversions, because Visual C++'s network conversion functions have a differing return type to mine. To be fixed in the future.
2017-05-28 18:09:29 +01:00
Fred Nicolson ae61464aee Removed is_connected flag in fr::Socket
The socket descriptor is now checked, to see if it's greater than 0, instead. This means that the flag doesn't have to be manually updated.
2017-05-25 16:21:39 +01:00
Fred Nicolson e0f68fb037 Added const specifiers to fr::URL members 2017-05-24 13:45:33 +01:00
Fred Nicolson 431f646bae Moved URL class into fr namespace
It should not have been in the global namespace, as it's a part of the library.
2017-05-24 09:54:19 +01:00
Fred Nicolson 7d0edb160e Bug fixes. Added ability to set ai_family on SSL listeners.
fr::Listener's destructor wasn't virtual, so children's destructors weren't being called.

fr::TcpListener did not have a destructor, and so did not close its socket on destruction. 

fr::SSLListener now uses fr::TcpListener's 'listen' function instead of its own, as a temporary hack, as mbedtls does not support setting the address families.

Added get/set functions to the listeners for their socket descriptors.
2017-05-23 21:17:39 +01:00
Fred Nicolson 68c214ef7e Merge pull request #5 from Cloaked9000/Mbedtls_Modified
Mbedtls modified
2017-05-23 20:48:45 +01:00
Fred Nicolson 40f8ccb067 Added URL parsing class
Allows the parsing of full URLs into easy chunks. Added as a helper class for users of the library dealing with URLs, and to potentially replace some of the HTTP parsing code in the future.
2017-05-23 16:52:55 +01:00
Fred Nicolson 60dfd44c0f Fixed errors not returning from SSLContext load crt 2017-05-11 14:09:55 +01:00
Fred Nicolson 9646d72e74 Added ability to set address family for sockets. Improved sslcontext.
Certs can now either be loaded from memory or disk.

You can specify if you want to use ipv4/ipv6/either when connecting or accepting.
2017-05-11 11:43:01 +01:00
Fred Nicolson 7ea87cced8 Added helpers for detecting mimetype
fr::Http::get_mimetype(filename) will return the mimetype of a given filename or file extention. This should be used to set the 'content-type' header when creating fr::HttpResponses.
2017-05-07 10:44:33 +01:00
Fred Nicolson 53ab6e2090 Header names are automatically lower-cased now. 2017-04-11 10:39:23 +01:00
Fred Nicolson 6b1ef27764 Re-wrote HTML request/response parsing
It's now much more robust, supports requests received over multiple recvs. Supports POST variables. Supports 'content-length' header.
2017-04-10 17:24:57 +01:00
Fred Nicolson eaefd93096 Re-arranged things 2017-04-07 09:22:31 +01:00
Fred Nicolson 5757eb776c Preparing to add support for larger HTTP requests 2017-04-06 14:07:03 +01:00
Fred Nicolson 3c6e6ec1b6 Added 'shutdown' to listeners 2017-03-31 14:37:31 +01:00
Fred Nicolson f101dc5718 Added missing access specifier to Listener 2017-03-31 12:28:39 +01:00