axhttp.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /*
  2. * Copyright (c) 2007, Cameron Rich
  3. *
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions are met:
  8. *
  9. * * Redistributions of source code must retain the above copyright notice,
  10. * this list of conditions and the following disclaimer.
  11. * * Redistributions in binary form must reproduce the above copyright notice,
  12. * this list of conditions and the following disclaimer in the documentation
  13. * and/or other materials provided with the distribution.
  14. * * Neither the name of the axTLS project nor the names of its contributors
  15. * may be used to endorse or promote products derived from this software
  16. * without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  19. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  20. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  21. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  22. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  23. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  24. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  25. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  26. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  27. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  28. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. */
  30. #include "ssl.h"
  31. #define BACKLOG 15
  32. #define VERSION "1.0.0"
  33. #ifdef CONFIG_HTTP_HAS_IPV6
  34. #define HAVE_IPV6
  35. #endif
  36. #define MAXPOSTDATASIZE 30000
  37. #define MAXREQUESTLENGTH 256
  38. #define BLOCKSIZE 4096
  39. #define INITIAL_CONNECTION_SLOTS 10
  40. #define CONFIG_HTTP_DEFAULT_SSL_OPTIONS SSL_DISPLAY_CERTS
  41. #define STATE_WANT_TO_READ_HEAD 1
  42. #define STATE_WANT_TO_SEND_HEAD 2
  43. #define STATE_WANT_TO_READ_FILE 3
  44. #define STATE_WANT_TO_SEND_FILE 4
  45. #define STATE_DOING_DIR 5
  46. enum
  47. {
  48. TYPE_GET,
  49. TYPE_HEAD,
  50. TYPE_POST
  51. };
  52. struct connstruct
  53. {
  54. struct connstruct *next;
  55. int state;
  56. int reqtype;
  57. int networkdesc;
  58. int filedesc;
  59. SSL *ssl;
  60. #if defined(CONFIG_HTTP_DIRECTORIES)
  61. #ifdef WIN32
  62. HANDLE dirp;
  63. WIN32_FIND_DATA file_data;
  64. #else
  65. DIR *dirp;
  66. #endif
  67. #endif
  68. time_t timeout;
  69. char actualfile[MAXREQUESTLENGTH];
  70. char filereq[MAXREQUESTLENGTH];
  71. char dirname[MAXREQUESTLENGTH];
  72. char server_name[MAXREQUESTLENGTH];
  73. int numbytes;
  74. char databuf[BLOCKSIZE];
  75. uint8_t is_ssl;
  76. uint8_t close_when_done;
  77. time_t if_modified_since;
  78. #if defined(CONFIG_HTTP_HAS_CGI)
  79. uint8_t is_cgi;
  80. #ifdef CONFIG_HTTP_ENABLE_LUA
  81. uint8_t is_lua;
  82. #endif
  83. int content_length;
  84. char remote_addr[MAXREQUESTLENGTH];
  85. char uri_request[MAXREQUESTLENGTH];
  86. char uri_path_info[MAXREQUESTLENGTH];
  87. char uri_query[MAXREQUESTLENGTH];
  88. char cookie[MAXREQUESTLENGTH];
  89. #endif
  90. #if defined(CONFIG_HTTP_HAS_AUTHORIZATION)
  91. char authorization[MAXREQUESTLENGTH];
  92. #endif
  93. int post_read;
  94. int post_state;
  95. char *post_data;
  96. };
  97. struct serverstruct
  98. {
  99. struct serverstruct *next;
  100. int sd;
  101. int is_ssl;
  102. SSL_CTX *ssl_ctx;
  103. };
  104. #if defined(CONFIG_HTTP_HAS_CGI)
  105. struct cgiextstruct
  106. {
  107. struct cgiextstruct *next;
  108. char *ext;
  109. };
  110. #endif
  111. /* global prototypes */
  112. extern struct serverstruct *servers;
  113. extern struct connstruct *usedconns;
  114. extern struct connstruct *freeconns;
  115. extern const char * const server_version;
  116. #if defined(CONFIG_HTTP_HAS_CGI)
  117. extern struct cgiextstruct *cgiexts;
  118. #endif
  119. /* conn.c prototypes */
  120. void removeconnection(struct connstruct *cn);
  121. /* proc.c prototypes */
  122. void procdodir(struct connstruct *cn);
  123. void procreadhead(struct connstruct *cn);
  124. void procsendhead(struct connstruct *cn);
  125. void procreadfile(struct connstruct *cn);
  126. void procsendfile(struct connstruct *cn);
  127. #if defined(CONFIG_HTTP_HAS_CGI)
  128. void read_post_data(struct connstruct *cn);
  129. #endif
  130. /* misc.c prototypes */
  131. char *my_strncpy(char *dest, const char *src, size_t n);
  132. int isdir(const char *name);
  133. /* tdate prototypes */
  134. void tdate_init(void);
  135. time_t tdate_parse(const char* str);