A simple web server that can be bound to either the EthernetInterface or the WiflyInterface.

Dependents:   Smart-WiFly-WebServer WattEye X10Svr SSDP_Server

Committer:
WiredHome
Date:
Mon Aug 12 23:03:25 2013 +0000
Revision:
14:19c5f6151319
Parent:
13:8975d7928678
Child:
15:581a21c32962
Refactor the base64 encoder and decoder.; Refactor the http server code to simplify the parsing of the header.;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
WiredHome 13:8975d7928678 1 #ifndef BASE64_H
WiredHome 13:8975d7928678 2 #define BASE64_H
WiredHome 12:109bf1558300 3
WiredHome 13:8975d7928678 4 #include "mbed.h"
WiredHome 12:109bf1558300 5
WiredHome 13:8975d7928678 6 /** Base64 encoder and decoder
WiredHome 13:8975d7928678 7 *
WiredHome 13:8975d7928678 8 * This class provided both encoding and decoding functions. These functions
WiredHome 13:8975d7928678 9 * perform dynamic memory allocations to create space for the translated
WiredHome 13:8975d7928678 10 * response. It is up to the calling function to free the space when
WiredHome 13:8975d7928678 11 * done with the translation.
WiredHome 13:8975d7928678 12 *
WiredHome 13:8975d7928678 13 * This code was derived from code found online that did not have any
WiredHome 13:8975d7928678 14 * copyright or reference to its work.
WiredHome 13:8975d7928678 15 *
WiredHome 13:8975d7928678 16 * @code
WiredHome 13:8975d7928678 17 * Base64 n();
WiredHome 13:8975d7928678 18 *
WiredHome 13:8975d7928678 19 * size_t encodedLen;
WiredHome 13:8975d7928678 20 * char *encoded = n.Encode("This is the message", 20, &encodedLen);
WiredHome 13:8975d7928678 21 *
WiredHome 13:8975d7928678 22 */
WiredHome 12:109bf1558300 23 class Base64
WiredHome 12:109bf1558300 24 {
WiredHome 12:109bf1558300 25 public:
WiredHome 13:8975d7928678 26 /** Constructor
WiredHome 13:8975d7928678 27 *
WiredHome 13:8975d7928678 28 */
WiredHome 12:109bf1558300 29 Base64();
WiredHome 13:8975d7928678 30
WiredHome 13:8975d7928678 31 /** Destructor
WiredHome 13:8975d7928678 32 *
WiredHome 13:8975d7928678 33 * This will release memory that may have been allocated (when the Decode
WiredHome 13:8975d7928678 34 * function is called).
WiredHome 13:8975d7928678 35 */
WiredHome 12:109bf1558300 36 ~Base64();
WiredHome 13:8975d7928678 37
WiredHome 13:8975d7928678 38 /** Encodes a string of information of a defined length
WiredHome 13:8975d7928678 39 *
WiredHome 13:8975d7928678 40 * The encoded information is considered a binary stream, therefore a length is provided
WiredHome 13:8975d7928678 41 * which is used to compute the amount of memory to allocate for the conversion.
WiredHome 13:8975d7928678 42 *
WiredHome 13:8975d7928678 43 * @note The Decode method does not know how you are using it - if it is for text,
WiredHome 13:8975d7928678 44 * it will not apply any null termination, unless that was part of the input.
WiredHome 13:8975d7928678 45 *
WiredHome 13:8975d7928678 46 * @param data is a pointer to the input binary stream.
WiredHome 13:8975d7928678 47 * @param input_length is the number of bytes to process.
WiredHome 13:8975d7928678 48 * @param output_length is a pointer to a size_t value into which is written the
WiredHome 13:8975d7928678 49 * number of bytes in the output.
WiredHome 13:8975d7928678 50 *
WiredHome 13:8975d7928678 51 * @returns a pointer to the allocated block of memory holding the converted results.
WiredHome 13:8975d7928678 52 * @returns NULL if something went very wrong.
WiredHome 13:8975d7928678 53 */
WiredHome 13:8975d7928678 54 char *Encode(const char *data, size_t input_length, size_t *output_length);
WiredHome 13:8975d7928678 55
WiredHome 13:8975d7928678 56 /** Decodes a base64 encoded stream back into the original information.
WiredHome 13:8975d7928678 57 *
WiredHome 13:8975d7928678 58 * The information to decode is considered a base64 encoded stream. A length is
WiredHome 13:8975d7928678 59 * provided which is used to compute the amount of memory to allocate for the conversion.
WiredHome 13:8975d7928678 60 *
WiredHome 13:8975d7928678 61 * @note The Decode method does not know how you are using it - if it is for text,
WiredHome 13:8975d7928678 62 * it will not apply any null termination, unless that was part of the input.
WiredHome 13:8975d7928678 63 *
WiredHome 13:8975d7928678 64 * @param data is a pointer to the encoded data to decode.
WiredHome 13:8975d7928678 65 * @param input_length is the number of bytes to process.
WiredHome 13:8975d7928678 66 * @param output_length is a pointer to a size_t value into which is written the
WiredHome 13:8975d7928678 67 * number of bytes in the output.
WiredHome 13:8975d7928678 68 *
WiredHome 13:8975d7928678 69 * @returns a pointer to the allocated block of memory holding the converted results.
WiredHome 13:8975d7928678 70 * @returns NULL if something went very wrong.
WiredHome 13:8975d7928678 71 */
WiredHome 13:8975d7928678 72 char *Decode(const char *data, size_t input_length, size_t *output_length);
WiredHome 13:8975d7928678 73
WiredHome 12:109bf1558300 74 private:
WiredHome 12:109bf1558300 75 void build_decoding_table();
WiredHome 12:109bf1558300 76 char *decoding_table;
WiredHome 13:8975d7928678 77 };
WiredHome 13:8975d7928678 78
WiredHome 14:19c5f6151319 79 #endif // BASE64_H