polipo.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. /*
  2. Copyright (c) 2003-2006 by Juliusz Chroboczek
  3. Permission is hereby granted, free of charge, to any person obtaining a copy
  4. of this software and associated documentation files (the "Software"), to deal
  5. in the Software without restriction, including without limitation the rights
  6. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. copies of the Software, and to permit persons to whom the Software is
  8. furnished to do so, subject to the following conditions:
  9. The above copyright notice and this permission notice shall be included in
  10. all copies or substantial portions of the Software.
  11. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  13. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  14. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  15. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  16. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  17. THE SOFTWARE.
  18. */
  19. #ifndef _GNU_SOURCE
  20. #define _GNU_SOURCE
  21. #endif
  22. #ifndef WIN32
  23. #include <sys/param.h>
  24. #endif
  25. #include <limits.h>
  26. #include <stdlib.h>
  27. #include <stdarg.h>
  28. #include <stdio.h>
  29. #include <errno.h>
  30. #include <string.h>
  31. #include <assert.h>
  32. #ifndef _WIN32
  33. #include <unistd.h>
  34. #include <sys/time.h>
  35. #include <dirent.h>
  36. #else
  37. #include "dirent_compat.h"
  38. #endif
  39. #include <fcntl.h>
  40. #include <time.h>
  41. #include <sys/stat.h>
  42. #ifndef WIN32 /*MINGW*/
  43. #include <sys/mman.h>
  44. #include <sys/socket.h>
  45. #include <netinet/in.h>
  46. #include <netinet/tcp.h>
  47. #include <arpa/inet.h>
  48. #include <netdb.h>
  49. #include <sys/types.h>
  50. #include <sys/uio.h>
  51. #include <poll.h>
  52. #include <sys/wait.h>
  53. #include <sys/ioctl.h>
  54. #include <signal.h>
  55. #endif
  56. #ifdef __MINGW32__
  57. #define MINGW
  58. #endif
  59. #ifndef MAP_ANONYMOUS
  60. #define MAP_ANONYMOUS MAP_ANON
  61. #endif
  62. #if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
  63. /* nothing */
  64. #elif defined(__GNUC__)
  65. #define inline __inline
  66. #if (__GNUC__ >= 3)
  67. #define restrict __restrict
  68. #else
  69. #define restrict /**/
  70. #endif
  71. #else
  72. #define inline /**/
  73. #define restrict /**/
  74. #endif
  75. #if defined(__GNUC__) && (__GNUC__ >= 3)
  76. #define ATTRIBUTE(x) __attribute__(x)
  77. #else
  78. #define ATTRIBUTE(x) /**/
  79. #endif
  80. /* Musl doesn't have a specific test, so assume musl if Linux and neither
  81. __GLIBC__ nor __UCLIBC__ */
  82. #if defined __linux
  83. #define HAVE_TM_GMTOFF
  84. #define HAVE_SETENV
  85. #define HAVE_ASPRINTF
  86. #define HAVE_MEMRCHR
  87. #ifdef __GLIBC__
  88. #define HAVE_FTS
  89. #endif
  90. #ifndef __UCLIBC__
  91. #define HAVE_FFSL
  92. #define HAVE_FFSLL
  93. #define HAVE_TIMEGM
  94. #endif
  95. #endif
  96. #ifdef BSD
  97. #define HAVE_TM_GMTOFF
  98. #define HAVE_FTS
  99. #define HAVE_SETENV
  100. #endif
  101. #ifdef __CYGWIN__
  102. #define HAVE_SETENV
  103. #define HAVE_ASPRINTF
  104. #endif
  105. #ifndef O_BINARY
  106. #define O_BINARY 0
  107. #endif
  108. #define HAVE_TZSET
  109. #if _POSIX_VERSION >= 200112L
  110. #define HAVE_SETENV
  111. #endif
  112. #ifndef NO_IPv6
  113. #ifdef __GLIBC__
  114. #if (__GLIBC__ > 2) || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 2)
  115. #define HAVE_IPv6
  116. #endif
  117. #endif
  118. #ifdef __FreeBSD__
  119. #define HAVE_ASPRINTF
  120. #if __FreeBSD_version >= 400000
  121. #define HAVE_IPv6
  122. #define HAVE_TIMEGM
  123. #endif
  124. #if __FreeBSD_version >= 503001
  125. #define HAVE_FFSL
  126. #endif
  127. #endif
  128. #ifdef __NetBSD__
  129. #if __NetBSD_Version__ >= 105000000
  130. #define HAVE_IPv6
  131. #endif
  132. #if __NetBSD_Version__ >= 200000000
  133. #define HAVE_TIMEGM
  134. #define HAVE_ASPRINTF
  135. #endif
  136. #endif
  137. #ifdef __OpenBSD__
  138. /* OpenBSD 2.3 and later */
  139. #define HAVE_IPv6
  140. #define HAVE_ASPRINTF
  141. #endif
  142. #ifdef __APPLE__
  143. #define HAVE_ASPRINTF
  144. #define HAVE_IPv6
  145. #define HAVE_TIMEGM
  146. #define HAVE_FFSL
  147. #endif
  148. #endif
  149. #if defined(i386) || defined(__mc68020__) || defined(__x86_64__)
  150. #define UNALIGNED_ACCESS
  151. #endif
  152. #ifndef WIN32 /*MINGW*/
  153. #define HAVE_FORK
  154. #ifndef NO_SYSLOG
  155. #define HAVE_SYSLOG
  156. #endif
  157. #define HAVE_READV_WRITEV
  158. #define HAVE_FFS
  159. #define READ(x, y, z) read(x, y, z)
  160. #define WRITE(x, y, z) write(x, y, z)
  161. #define CLOSE(x) close(x)
  162. #else
  163. #ifndef HAVE_REGEX
  164. #define NO_FORBIDDEN
  165. #endif
  166. #ifndef MINGW
  167. #define HAVE_MKGMTIME
  168. #endif
  169. #endif
  170. #ifdef HAVE_READV_WRITEV
  171. #define WRITEV(x, y, z) writev(x, y, z)
  172. #define READV(x, y, z) readv(x, y, z)
  173. #endif
  174. #ifndef HAVE_FORK
  175. #define NO_REDIRECTOR
  176. #endif
  177. #include "mingw.h"
  178. #include "ftsimport.h"
  179. #include "atom.h"
  180. #include "util.h"
  181. #include "config.h"
  182. #include "event.h"
  183. #include "io.h"
  184. #include "socks.h"
  185. #include "chunk.h"
  186. #include "object.h"
  187. #include "dns.h"
  188. #include "http.h"
  189. #include "client.h"
  190. #include "local.h"
  191. #include "diskcache.h"
  192. #include "server.h"
  193. #include "http_parse.h"
  194. #include "parse_time.h"
  195. #include "forbidden.h"
  196. #include "log.h"
  197. #include "auth.h"
  198. #include "tunnel.h"
  199. extern AtomPtr configFile;
  200. extern int daemonise;
  201. extern AtomPtr pidFile;