httpd.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #ifndef HTTPD_H
  2. #define HTTPD_H
  3. #define HTTPDVER "0.3"
  4. #define HTTPD_CGI_MORE 0
  5. #define HTTPD_CGI_DONE 1
  6. #define HTTPD_CGI_NOTFOUND 2
  7. #define HTTPD_CGI_AUTHENTICATED 3
  8. #define HTTPD_METHOD_GET 1
  9. #define HTTPD_METHOD_POST 2
  10. typedef struct HttpdPriv HttpdPriv;
  11. typedef struct HttpdConnData HttpdConnData;
  12. typedef struct HttpdPostData HttpdPostData;
  13. typedef int (* cgiSendCallback)(HttpdConnData *connData);
  14. //A struct describing a http connection. This gets passed to cgi functions.
  15. struct HttpdConnData {
  16. struct espconn *conn;
  17. //int remote_port;
  18. //uint8 remote_ip[4];
  19. uint32 startTime;
  20. char requestType; // HTTP_METHOD_GET | HTTPD_METHOD_POST
  21. char *url;
  22. char *getArgs;
  23. const void *cgiArg;
  24. void *cgiData;
  25. void *cgiPrivData; // Used for streaming handlers storing state between requests
  26. void *cgiResponse; // used for forwarding response to the CGI handler
  27. int32 hash; // authentication cookie
  28. HttpdPriv *priv;
  29. cgiSendCallback cgi;
  30. HttpdPostData *post;
  31. };
  32. //A struct describing the POST data sent inside the http connection. This is used by the CGI functions
  33. struct HttpdPostData {
  34. int len; // POST Content-Length
  35. int buffSize; // The maximum length of the post buffer
  36. int buffLen; // The amount of bytes in the current post buffer
  37. int received; // The total amount of bytes received so far
  38. char *buff; // Actual POST data buffer
  39. char *multipartBoundary;
  40. };
  41. //A struct describing an url. This is the main struct that's used to send different URL requests to
  42. //different routines.
  43. typedef struct {
  44. const char *url;
  45. cgiSendCallback cgiCb;
  46. const void *cgiArg;
  47. char auth;
  48. } HttpdBuiltInUrl;
  49. int ICACHE_FLASH_ATTR cgiRedirect(HttpdConnData *connData);
  50. int ICACHE_FLASH_ATTR httpdSetCookie(HttpdConnData *conn, char *newUrl, uint32 hash);
  51. int ICACHE_FLASH_ATTR httpdSendAuthCookie(HttpdConnData *conn, uint32 hash);
  52. void ICACHE_FLASH_ATTR httpdForbidden(HttpdConnData *conn);
  53. void ICACHE_FLASH_ATTR httpdRedirect(HttpdConnData *conn, char *newUrl);
  54. int httpdUrlDecode(char *val, int valLen, char *ret, int retLen);
  55. int ICACHE_FLASH_ATTR httpdFindArg(char *line, char *arg, char *buff, int buffLen);
  56. void ICACHE_FLASH_ATTR httpdInit(HttpdBuiltInUrl *fixedUrls, char* hostname, int port);
  57. const char *httpdGetMimetype(char *url);
  58. void ICACHE_FLASH_ATTR httpdSetOutputBuffer(HttpdConnData *conn, char *buff, short max);
  59. void ICACHE_FLASH_ATTR httpdStartResponse(HttpdConnData *conn, int code);
  60. void ICACHE_FLASH_ATTR httpdHeader(HttpdConnData *conn, const char *field, const char *val);
  61. void ICACHE_FLASH_ATTR httpdEndHeaders(HttpdConnData *conn);
  62. int ICACHE_FLASH_ATTR httpdGetHeader(HttpdConnData *conn, char *header, char *ret, int retLen);
  63. int ICACHE_FLASH_ATTR httpdSend(HttpdConnData *conn, const char *data, int len);
  64. void ICACHE_FLASH_ATTR httpdFlush(HttpdConnData *conn);
  65. HttpdConnData * ICACHE_FLASH_ATTR httpdLookUpConn(uint8_t * ip, int port);
  66. int ICACHE_FLASH_ATTR httpdSetCGIResponse(HttpdConnData * conn, void *response);
  67. #endif