Lucas Tanio / http_server

Dependents:   Socket-Server-TCP

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers http_server.h Source File

http_server.h

00001 /*********************************************************************
00002 *
00003 * HTTP_SERVER.h
00004 * 
00005 * Mauricio Martins Donatti
00006 * mauricio.donatti@lnls.br
00007 *
00008 * Electronics Instrumentation Group - GIE
00009 * Brazilian Synchrotron Light Laboratory (LNLS)
00010 * Brazilian Center for Research in Energy and Materials (CNPEM)
00011 *
00012 * March 2020
00013 *
00014 *******************************************************************/
00015 
00016 #ifndef HTTP_SERVER_H
00017 #define HTTP_SERVER_H
00018 
00019 #include "mbed.h"
00020 #include "EthernetInterface.h"
00021 #include <string>
00022 
00023 #define MAX_BUFFER_SIZE         1024
00024 #define WEBSERVERPORT           80
00025 #define QUEUED_REQUESTS         3
00026 #define DEVICE_NAME             "LNLS_4CH_001\0"
00027 #define WEBSERVER_TIMEOUT_MS    1500
00028 
00029 
00030 #define DEBUG
00031 
00032 #ifdef DEBUG
00033 
00034 extern Serial pc;
00035 #define HTTP_PRINTF(fmt, ...)       pc.printf("HTTP: " fmt "\r\n", ##__VA_ARGS__)
00036 
00037 #else
00038 
00039 #define HTTP_PRINTF(fmt, ...)           __NOP()
00040 
00041 #endif //Config enabled DEBUG
00042 
00043 
00044 
00045 using namespace std;
00046 
00047 // HttpServer class
00048 //
00049 // This is the class to make a mbed a simple HTTP Server.
00050 class HttpServer
00051 {
00052 public:
00053     HttpServer();
00054     ~HttpServer();
00055     
00056     // HTTP SERVER Initialization.
00057     //
00058     //  This function should be called first of all.
00059     //  @return result of init() as boolean.
00060     //  @retval TRUE SACCESS
00061     //  @retval FALSE
00062     //
00063     bool init(EthernetInterface* eth,char *file,int file_size);
00064     
00065     // Run the surver service while listening flag is true.
00066     //
00067     //  @return state ending.
00068     //  @retval TRUE at error end.
00069     //  @retval FALSE at normal end.
00070     //
00071     bool run();
00072     
00073     char *html_file;                //Pointer to HTML file
00074     int html_size;
00075     
00076     char buffer[MAX_BUFFER_SIZE];   //receive and transmit buffer
00077     int n_recv;
00078     int buf_len;
00079     int status_code;                //http status code
00080     char reason_phrase[30];         //http reason phrase
00081     
00082     char httpmethod[20];            //http method
00083     char filepath[40];              //file requested
00084     char http_ver[20];              //http version
00085 
00086     //  Handlers
00087     TCPSocket socket;               //  TCP server
00088     TCPSocket* client;              //  TCP server connection clerk
00089     
00090     nsapi_error_t status;
00091 };
00092 
00093 #endif