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:
Wed Feb 27 18:06:23 2019 +0000
Revision:
60:d49a346c386f
Parent:
15:581a21c32962
Enable header code 302

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 15:581a21c32962 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 15:581a21c32962 21 * printf("Encoded message is {%s}\r\n", encoded);
WiredHome 15:581a21c32962 22 * @endcode
WiredHome 13:8975d7928678 23 */
WiredHome 12:109bf1558300 24 class Base64
WiredHome 12:109bf1558300 25 {
WiredHome 12:109bf1558300 26 public:
WiredHome 13:8975d7928678 27 /** Constructor
WiredHome 13:8975d7928678 28 *
WiredHome 13:8975d7928678 29 */
WiredHome 12:109bf1558300 30 Base64();
WiredHome 13:8975d7928678 31
WiredHome 13:8975d7928678 32 /** Destructor
WiredHome 13:8975d7928678 33 *
WiredHome 13:8975d7928678 34 * This will release memory that may have been allocated (when the Decode
WiredHome 15:581a21c32962 35 * function was called).
WiredHome 13:8975d7928678 36 */
WiredHome 12:109bf1558300 37 ~Base64();
WiredHome 13:8975d7928678 38
WiredHome 13:8975d7928678 39 /** Encodes a string of information of a defined length
WiredHome 13:8975d7928678 40 *
WiredHome 13:8975d7928678 41 * The encoded information is considered a binary stream, therefore a length is provided
WiredHome 13:8975d7928678 42 * which is used to compute the amount of memory to allocate for the conversion.
WiredHome 13:8975d7928678 43 *
WiredHome 13:8975d7928678 44 * @note The Decode method does not know how you are using it - if it is for text,
WiredHome 13:8975d7928678 45 * it will not apply any null termination, unless that was part of the input.
WiredHome 13:8975d7928678 46 *
WiredHome 13:8975d7928678 47 * @param data is a pointer to the input binary stream.
WiredHome 13:8975d7928678 48 * @param input_length is the number of bytes to process.
WiredHome 13:8975d7928678 49 * @param output_length is a pointer to a size_t value into which is written the
WiredHome 13:8975d7928678 50 * number of bytes in the output.
WiredHome 13:8975d7928678 51 *
WiredHome 13:8975d7928678 52 * @returns a pointer to the allocated block of memory holding the converted results.
WiredHome 13:8975d7928678 53 * @returns NULL if something went very wrong.
WiredHome 13:8975d7928678 54 */
WiredHome 13:8975d7928678 55 char *Encode(const char *data, size_t input_length, size_t *output_length);
WiredHome 13:8975d7928678 56
WiredHome 13:8975d7928678 57 /** Decodes a base64 encoded stream back into the original information.
WiredHome 13:8975d7928678 58 *
WiredHome 13:8975d7928678 59 * The information to decode is considered a base64 encoded stream. A length is
WiredHome 13:8975d7928678 60 * provided which is used to compute the amount of memory to allocate for the conversion.
WiredHome 13:8975d7928678 61 *
WiredHome 13:8975d7928678 62 * @note The Decode method does not know how you are using it - if it is for text,
WiredHome 13:8975d7928678 63 * it will not apply any null termination, unless that was part of the input.
WiredHome 13:8975d7928678 64 *
WiredHome 13:8975d7928678 65 * @param data is a pointer to the encoded data to decode.
WiredHome 13:8975d7928678 66 * @param input_length is the number of bytes to process.
WiredHome 13:8975d7928678 67 * @param output_length is a pointer to a size_t value into which is written the
WiredHome 13:8975d7928678 68 * number of bytes in the output.
WiredHome 13:8975d7928678 69 *
WiredHome 13:8975d7928678 70 * @returns a pointer to the allocated block of memory holding the converted results.
WiredHome 13:8975d7928678 71 * @returns NULL if something went very wrong.
WiredHome 13:8975d7928678 72 */
WiredHome 13:8975d7928678 73 char *Decode(const char *data, size_t input_length, size_t *output_length);
WiredHome 13:8975d7928678 74
WiredHome 12:109bf1558300 75 private:
WiredHome 12:109bf1558300 76 void build_decoding_table();
WiredHome 12:109bf1558300 77 char *decoding_table;
WiredHome 13:8975d7928678 78 };
WiredHome 13:8975d7928678 79
WiredHome 14:19c5f6151319 80 #endif // BASE64_H