http_log.inc 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743
  1. {* Licensed to the Apache Software Foundation (ASF) under one or more
  2. * contributor license agreements. See the NOTICE file distributed with
  3. * this work for additional information regarding copyright ownership.
  4. * The ASF licenses this file to You under the Apache License, Version 2.0
  5. * (the "License"); you may not use this file except in compliance with
  6. * the License. You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. *}
  16. (**
  17. * @file http_log.h
  18. * @brief Apache Logging library
  19. *
  20. * @defgroup APACHE_CORE_LOG Logging library
  21. * @ingroup APACHE_CORE
  22. * @{
  23. *)
  24. //#ifndef APACHE_HTTP_LOG_H
  25. //#define APACHE_HTTP_LOG_H
  26. //#include "apr_thread_proc.h"
  27. //#include "http_config.h"
  28. //#ifdef HAVE_SYSLOG
  29. //#include <syslog.h>
  30. const
  31. LOG_PRIMASK = 7;
  32. APLOG_EMERG = 0; //* system is unusable */
  33. APLOG_ALERT = 1; //* action must be taken immediately */
  34. APLOG_CRIT = 2; //* critical conditions */
  35. APLOG_ERR = 3; //* error conditions */
  36. APLOG_WARNING = 4; //* warning conditions */
  37. APLOG_NOTICE = 5; //* normal but significant condition */
  38. APLOG_INFO = 6; //* informational */
  39. APLOG_DEBUG = 7; //* debug-level messages */
  40. APLOG_TRACE1 = 8; //* trace-level 1 messages */
  41. APLOG_TRACE2 = 9; //* trace-level 2 messages */
  42. APLOG_TRACE3 =10; //* trace-level 3 messages */
  43. APLOG_TRACE4 =11; //* trace-level 4 messages */
  44. APLOG_TRACE5 =12; //* trace-level 5 messages */
  45. APLOG_TRACE6 =13; //* trace-level 6 messages */
  46. APLOG_TRACE7 =14; //* trace-level 7 messages */
  47. APLOG_TRACE8 =15; //* trace-level 8 messages */
  48. APLOG_LEVELMASK =15; //* mask off the level value */
  49. {* APLOG_NOERRNO is ignored and should not be used. It will be
  50. * removed in a future release of Apache.
  51. *}
  52. APLOG_NOERRNO = (APLOG_LEVELMASK + 1);
  53. {** Use APLOG_TOCLIENT on ap_log_rerror() to give content
  54. * handlers the option of including the error text in the
  55. * ErrorDocument sent back to the client. Setting APLOG_TOCLIENT
  56. * will cause the error text to be saved in the request_rec->notes
  57. * table, keyed to the string "error-notes", if and only if:
  58. * - the severity level of the message is APLOG_WARNING or greater
  59. * - there are no other "error-notes" set in request_rec->notes
  60. * Once error-notes is set, it is up to the content handler to
  61. * determine whether this text should be sent back to the client.
  62. * Note: Client generated text streams sent back to the client MUST
  63. * be escaped to prevent CSS attacks.
  64. *}
  65. APLOG_TOCLIENT = ((APLOG_LEVELMASK + 1) * 2);
  66. //* normal but significant condition on startup, usually printed to stderr */
  67. APLOG_STARTUP = ((APLOG_LEVELMASK + 1) * 4);
  68. DEFAULT_LOGLEVEL = APLOG_WARNING;
  69. {**
  70. * APLOGNO() should be used at the start of the format string passed
  71. * to ap_log_error() and friends. The argument must be a 5 digit decimal
  72. * number. It creates a tag of the form "AH02182: "
  73. * See docs/log-message-tags/README for details.
  74. *}
  75. //#define APLOGNO(n) "AH" #n ": "
  76. {fpc, could be a function ... ignored}
  77. {**
  78. * APLOG_NO_MODULE may be passed as module_index to ap_log_error() and related
  79. * functions if the module causing the log message is not known. Normally this
  80. * should not be used directly. Use ::APLOG_MARK or ::APLOG_MODULE_INDEX
  81. * instead.
  82. *
  83. * @see APLOG_MARK
  84. * @see APLOG_MODULE_INDEX
  85. * @see ap_log_error
  86. *}
  87. APLOG_NO_MODULE = -1;
  88. {
  89. #ifdef __cplusplus
  90. /**
  91. * C++ modules must invoke ::APLOG_USE_MODULE or ::AP_DECLARE_MODULE in
  92. * every file which uses ap_log_* before the first use of ::APLOG_MARK
  93. * or ::APLOG_MODULE_INDEX.
  94. * (C modules *should* do that as well, to enable module-specific log
  95. * levels. C modules need not obey the ordering, though).
  96. */
  97. #else /* __cplusplus */
  98. /**
  99. * Constant to store module_index for the current file.
  100. * Objects with static storage duration are set to NULL if not
  101. * initialized explicitly. This means that if aplog_module_index
  102. * is not initalized using the ::APLOG_USE_MODULE or the
  103. * ::AP_DECLARE_MODULE macro, we can safely fall back to
  104. * use ::APLOG_NO_MODULE. This variable will usually be optimized away.
  105. */
  106. static int * const aplog_module_index;
  107. #endif /* __cplusplus */
  108. }
  109. {**
  110. * APLOG_MODULE_INDEX contains the module_index of the current module if
  111. * it has been set via the ::APLOG_USE_MODULE or ::AP_DECLARE_MODULE macro.
  112. * Otherwise it contains ::APLOG_NO_MODULE (for example in unmodified httpd
  113. * 2.2 modules).
  114. *
  115. * If ::APLOG_MARK is used in ap_log_error() and related functions,
  116. * ::APLOG_MODULE_INDEX will be passed as module_index. In cases where
  117. * ::APLOG_MARK cannot be used, ::APLOG_MODULE_INDEX should normally be passed
  118. * as module_index.
  119. *
  120. * @see APLOG_MARK
  121. * @see ap_log_error
  122. *}
  123. (*
  124. #ifdef __cplusplus
  125. #define APLOG_MODULE_INDEX ( *aplog_module_index)
  126. #else /* __cplusplus */
  127. #define APLOG_MODULE_INDEX \
  128. (aplog_module_index ? *aplog_module_index : APLOG_NO_MODULE)
  129. #endif /* __cplusplus */
  130. /**
  131. * APLOG_MAX_LOGLEVEL can be defined to remove logging above some
  132. * specified level at compile time.
  133. *
  134. * This requires a C99 compiler.
  135. */
  136. #ifdef DOXYGEN
  137. #define APLOG_MAX_LOGLEVEL
  138. #endif
  139. #ifndef APLOG_MAX_LOGLEVEL
  140. #define APLOG_MODULE_IS_LEVEL(s,module_index,level) \
  141. ( (((level)&APLOG_LEVELMASK) <= APLOG_NOTICE) || \
  142. (s == NULL) || \
  143. (ap_get_server_module_loglevel(s, module_index) \
  144. >= ((level)&APLOG_LEVELMASK) ) )
  145. #define APLOG_C_MODULE_IS_LEVEL(c,module_index,level) \
  146. ( (((level)&APLOG_LEVELMASK) <= APLOG_NOTICE) || \
  147. (ap_get_conn_module_loglevel(c, module_index) \
  148. >= ((level)&APLOG_LEVELMASK) ) )
  149. #define APLOG_CS_MODULE_IS_LEVEL(c,s,module_index,level) \
  150. ( (((level)&APLOG_LEVELMASK) <= APLOG_NOTICE) || \
  151. (ap_get_conn_server_module_loglevel(c, s, module_index) \
  152. >= ((level)&APLOG_LEVELMASK) ) )
  153. #define APLOG_R_MODULE_IS_LEVEL(r,module_index,level) \
  154. ( (((level)&APLOG_LEVELMASK) <= APLOG_NOTICE) || \
  155. (ap_get_request_module_loglevel(r, module_index) \
  156. >= ((level)&APLOG_LEVELMASK) ) )
  157. #else
  158. #define APLOG_MODULE_IS_LEVEL(s,module_index,level) \
  159. ( (((level)&APLOG_LEVELMASK) <= APLOG_MAX_LOGLEVEL) && \
  160. ( (((level)&APLOG_LEVELMASK) <= APLOG_NOTICE) || \
  161. (s == NULL) || \
  162. (ap_get_server_module_loglevel(s, module_index) \
  163. >= ((level)&APLOG_LEVELMASK) ) ) )
  164. #define APLOG_CS_MODULE_IS_LEVEL(c,s,module_index,level) \
  165. ( (((level)&APLOG_LEVELMASK) <= APLOG_MAX_LOGLEVEL) && \
  166. ( (((level)&APLOG_LEVELMASK) <= APLOG_NOTICE) || \
  167. (ap_get_conn_server_module_loglevel(c, s, module_index) \
  168. >= ((level)&APLOG_LEVELMASK) ) ) )
  169. #define APLOG_C_MODULE_IS_LEVEL(c,module_index,level) \
  170. ( (((level)&APLOG_LEVELMASK) <= APLOG_MAX_LOGLEVEL) && \
  171. ( (((level)&APLOG_LEVELMASK) <= APLOG_NOTICE) || \
  172. (ap_get_conn_module_loglevel(c, module_index) \
  173. >= ((level)&APLOG_LEVELMASK) ) ) )
  174. #define APLOG_R_MODULE_IS_LEVEL(r,module_index,level) \
  175. ( (((level)&APLOG_LEVELMASK) <= APLOG_MAX_LOGLEVEL) && \
  176. ( (((level)&APLOG_LEVELMASK) <= APLOG_NOTICE) || \
  177. (ap_get_request_module_loglevel(r, module_index) \
  178. >= ((level)&APLOG_LEVELMASK) ) ) )
  179. #endif
  180. #define APLOG_IS_LEVEL(s,level) \
  181. APLOG_MODULE_IS_LEVEL(s,APLOG_MODULE_INDEX,level)
  182. #define APLOG_C_IS_LEVEL(c,level) \
  183. APLOG_C_MODULE_IS_LEVEL(c,APLOG_MODULE_INDEX,level)
  184. #define APLOG_CS_IS_LEVEL(c,s,level) \
  185. APLOG_CS_MODULE_IS_LEVEL(c,s,APLOG_MODULE_INDEX,level)
  186. #define APLOG_R_IS_LEVEL(r,level) \
  187. APLOG_R_MODULE_IS_LEVEL(r,APLOG_MODULE_INDEX,level)
  188. #define APLOGinfo(s) APLOG_IS_LEVEL(s,APLOG_INFO)
  189. #define APLOGdebug(s) APLOG_IS_LEVEL(s,APLOG_DEBUG)
  190. #define APLOGtrace1(s) APLOG_IS_LEVEL(s,APLOG_TRACE1)
  191. #define APLOGtrace2(s) APLOG_IS_LEVEL(s,APLOG_TRACE2)
  192. #define APLOGtrace3(s) APLOG_IS_LEVEL(s,APLOG_TRACE3)
  193. #define APLOGtrace4(s) APLOG_IS_LEVEL(s,APLOG_TRACE4)
  194. #define APLOGtrace5(s) APLOG_IS_LEVEL(s,APLOG_TRACE5)
  195. #define APLOGtrace6(s) APLOG_IS_LEVEL(s,APLOG_TRACE6)
  196. #define APLOGtrace7(s) APLOG_IS_LEVEL(s,APLOG_TRACE7)
  197. #define APLOGtrace8(s) APLOG_IS_LEVEL(s,APLOG_TRACE8)
  198. #define APLOGrinfo(r) APLOG_R_IS_LEVEL(r,APLOG_INFO)
  199. #define APLOGrdebug(r) APLOG_R_IS_LEVEL(r,APLOG_DEBUG)
  200. #define APLOGrtrace1(r) APLOG_R_IS_LEVEL(r,APLOG_TRACE1)
  201. #define APLOGrtrace2(r) APLOG_R_IS_LEVEL(r,APLOG_TRACE2)
  202. #define APLOGrtrace3(r) APLOG_R_IS_LEVEL(r,APLOG_TRACE3)
  203. #define APLOGrtrace4(r) APLOG_R_IS_LEVEL(r,APLOG_TRACE4)
  204. #define APLOGrtrace5(r) APLOG_R_IS_LEVEL(r,APLOG_TRACE5)
  205. #define APLOGrtrace6(r) APLOG_R_IS_LEVEL(r,APLOG_TRACE6)
  206. #define APLOGrtrace7(r) APLOG_R_IS_LEVEL(r,APLOG_TRACE7)
  207. #define APLOGrtrace8(r) APLOG_R_IS_LEVEL(r,APLOG_TRACE8)
  208. #define APLOGcinfo(c) APLOG_C_IS_LEVEL(c,APLOG_INFO)
  209. #define APLOGcdebug(c) APLOG_C_IS_LEVEL(c,APLOG_DEBUG)
  210. #define APLOGctrace1(c) APLOG_C_IS_LEVEL(c,APLOG_TRACE1)
  211. #define APLOGctrace2(c) APLOG_C_IS_LEVEL(c,APLOG_TRACE2)
  212. #define APLOGctrace3(c) APLOG_C_IS_LEVEL(c,APLOG_TRACE3)
  213. #define APLOGctrace4(c) APLOG_C_IS_LEVEL(c,APLOG_TRACE4)
  214. #define APLOGctrace5(c) APLOG_C_IS_LEVEL(c,APLOG_TRACE5)
  215. #define APLOGctrace6(c) APLOG_C_IS_LEVEL(c,APLOG_TRACE6)
  216. #define APLOGctrace7(c) APLOG_C_IS_LEVEL(c,APLOG_TRACE7)
  217. #define APLOGctrace8(c) APLOG_C_IS_LEVEL(c,APLOG_TRACE8)
  218. extern int AP_DECLARE_DATA ap_default_loglevel;
  219. /**
  220. * APLOG_MARK is a convenience macro for use as the first three parameters in
  221. * ap_log_error() and related functions, i.e. file, line, and module_index.
  222. *
  223. * The module_index parameter was introduced in version 2.3.6. Before that
  224. * version, APLOG_MARK only replaced the file and line parameters.
  225. * This means that APLOG_MARK can be used with ap_log_*error in all versions
  226. * of Apache httpd.
  227. *
  228. * @see APLOG_MODULE_INDEX
  229. * @see ap_log_error
  230. * @see ap_log_cerror
  231. * @see ap_log_rerror
  232. * @see ap_log_cserror
  233. */
  234. #define APLOG_MARK __FILE__,__LINE__,APLOG_MODULE_INDEX
  235. *)
  236. {**
  237. * Set up for logging to stderr.
  238. * @param p The pool to allocate out of
  239. *}
  240. procedure ap_open_stderr_log(p: Papr_pool_t);
  241. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  242. external LibHTTPD name LibNamePrefix + 'ap_open_stderr_log' + LibSuff4;
  243. {**
  244. * Replace logging to stderr with logging to the given file.
  245. * @param p The pool to allocate out of
  246. * @param file Name of the file to log stderr output
  247. *}
  248. function ap_replace_stderr_log(p: Papr_pool_t; file_: PChar): apr_status_t;
  249. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  250. external LibHTTPD name LibNamePrefix + 'ap_replace_stderr_log' + LibSuff8;
  251. {**
  252. * Open the error log and replace stderr with it.
  253. * @param pconf Not used
  254. * @param plog The pool to allocate the logs from
  255. * @param ptemp Pool used for temporary allocations
  256. * @param s_main The main server
  257. * @note ap_open_logs isn't expected to be used by modules, it is
  258. * an internal core function
  259. *}
  260. //int ap_open_logs(apr_pool_t *pconf, apr_pool_t *plog,
  261. // apr_pool_t *ptemp, server_rec *s_main);
  262. {**
  263. * Perform special processing for piped loggers in MPM child
  264. * processes.
  265. * @param p Not used
  266. * @param s Not used
  267. * @note ap_logs_child_init is not for use by modules; it is an
  268. * internal core function
  269. *}
  270. //void ap_logs_child_init(apr_pool_t *p, server_rec *s);
  271. {*
  272. * The primary logging functions, ap_log_error, ap_log_rerror, ap_log_cerror,
  273. * and ap_log_perror use a printf style format string to build the log message.
  274. * It is VERY IMPORTANT that you not include any raw data from the network,
  275. * such as the request-URI or request header fields, within the format
  276. * string. Doing so makes the server vulnerable to a denial-of-service
  277. * attack and other messy behavior. Instead, use a simple format string
  278. * like "%s", followed by the string containing the untrusted data.
  279. *}
  280. {**
  281. * ap_log_error() - log messages which are not related to a particular
  282. * request or connection. This uses a printf-like format to log messages
  283. * to the error_log.
  284. * @param file The file in which this function is called
  285. * @param line The line number on which this function is called
  286. * @param module_index The module_index of the module generating this message
  287. * @param level The level of this error message
  288. * @param status The status code from the previous command
  289. * @param s The server on which we are logging
  290. * @param fmt The format string
  291. * @param ... The arguments to use to fill out fmt.
  292. * @note ap_log_error is implemented as a macro
  293. * @note Use APLOG_MARK to fill out file and line
  294. * @note If a request_rec is available, use that with ap_log_rerror()
  295. * in preference to calling this function. Otherwise, if a conn_rec is
  296. * available, use that with ap_log_cerror() in preference to calling
  297. * this function.
  298. * @warning It is VERY IMPORTANT that you not include any raw data from
  299. * the network, such as the request-URI or request header fields, within
  300. * the format string. Doing so makes the server vulnerable to a
  301. * denial-of-service attack and other messy behavior. Instead, use a
  302. * simple format string like "%s", followed by the string containing the
  303. * untrusted data.
  304. *}
  305. (*#ifdef DOXYGEN
  306. AP_DECLARE(void) ap_log_error(const char *file, int line, int module_index,
  307. int level, apr_status_t status,
  308. const server_rec *s, const char *fmt, ...);
  309. #else
  310. #ifdef AP_HAVE_C99
  311. /* need additional step to expand APLOG_MARK first */
  312. #define ap_log_error(...) ap_log_error__(__VA_ARGS__)
  313. /* need server_rec *sr = ... for the case if s is verbatim NULL */
  314. #define ap_log_error__(file, line, mi, level, status, s, ...) \
  315. do { const server_rec *sr__ = s; if (APLOG_MODULE_IS_LEVEL(sr__, mi, level)) \
  316. ap_log_error_(file, line, mi, level, status, sr__, __VA_ARGS__); \
  317. } while(0)
  318. #else
  319. #define ap_log_error ap_log_error_
  320. #endif
  321. AP_DECLARE(void) ap_log_error_(const char *file, int line, int module_index,
  322. int level, apr_status_t status,
  323. const server_rec *s, const char *fmt, ...)
  324. __attribute__((format(printf,7,8)));
  325. #endif
  326. *)
  327. procedure ap_log_error(const file_: PChar;
  328. line,
  329. module_index, //extra parameter from Apache 2.3.x
  330. level: Integer;
  331. status: apr_status_t;
  332. const s: Pserver_rec;
  333. const fmt: PChar;
  334. fmt_args: array of const); cdecl;
  335. external LibHTTPD name 'ap_log_error' + LibSuff_;
  336. {**
  337. * ap_log_perror() - log messages which are not related to a particular
  338. * request, connection, or virtual server. This uses a printf-like
  339. * format to log messages to the error_log.
  340. * @param file The file in which this function is called
  341. * @param line The line number on which this function is called
  342. * @param module_index ignored dummy value for use by APLOG_MARK
  343. * @param level The level of this error message
  344. * @param status The status code from the previous command
  345. * @param p The pool which we are logging for
  346. * @param fmt The format string
  347. * @param ... The arguments to use to fill out fmt.
  348. * @note ap_log_perror is implemented as a macro
  349. * @note Use APLOG_MARK to fill out file, line, and module_index
  350. * @warning It is VERY IMPORTANT that you not include any raw data from
  351. * the network, such as the request-URI or request header fields, within
  352. * the format string. Doing so makes the server vulnerable to a
  353. * denial-of-service attack and other messy behavior. Instead, use a
  354. * simple format string like "%s", followed by the string containing the
  355. * untrusted data.
  356. *}
  357. (*#ifdef DOXYGEN
  358. AP_DECLARE(void) ap_log_perror(const char *file, int line, int module_index,
  359. int level, apr_status_t status, apr_pool_t *p,
  360. const char *fmt, ...);
  361. #else
  362. #if defined(AP_HAVE_C99) && defined(APLOG_MAX_LOGLEVEL)
  363. /* need additional step to expand APLOG_MARK first */
  364. #define ap_log_perror(...) ap_log_perror__(__VA_ARGS__)
  365. #define ap_log_perror__(file, line, mi, level, status, p, ...) \
  366. do { if ((level) <= APLOG_MAX_LOGLEVEL ) \
  367. ap_log_perror_(file, line, mi, level, status, p, \
  368. __VA_ARGS__); } while(0)
  369. #else
  370. #define ap_log_perror ap_log_perror_
  371. #endif
  372. AP_DECLARE(void) ap_log_perror_(const char *file, int line, int module_index,
  373. int level, apr_status_t status, apr_pool_t *p,
  374. const char *fmt, ...)
  375. __attribute__((format(printf,7,8)));
  376. #endif
  377. *)
  378. procedure ap_log_perror(const file_: PChar; line, module_index, level: Integer;
  379. status: apr_status_t; p: Papr_pool_t;
  380. const fmt: PChar; fmt_args: array of const);
  381. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  382. external LibHTTPD name 'ap_log_perror' + LibSuff_;
  383. {**
  384. * ap_log_rerror() - log messages which are related to a particular
  385. * request. This uses a printf-like format to log messages to the
  386. * error_log.
  387. * @param file The file in which this function is called
  388. * @param line The line number on which this function is called
  389. * @param module_index The module_index of the module generating this message
  390. * @param level The level of this error message
  391. * @param status The status code from the previous command
  392. * @param r The request which we are logging for
  393. * @param fmt The format string
  394. * @param ... The arguments to use to fill out fmt.
  395. * @note ap_log_rerror is implemented as a macro
  396. * @note Use APLOG_MARK to fill out file, line, and module_index
  397. * @warning It is VERY IMPORTANT that you not include any raw data from
  398. * the network, such as the request-URI or request header fields, within
  399. * the format string. Doing so makes the server vulnerable to a
  400. * denial-of-service attack and other messy behavior. Instead, use a
  401. * simple format string like "%s", followed by the string containing the
  402. * untrusted data.
  403. *}
  404. (*#ifdef DOXYGEN
  405. AP_DECLARE(void) ap_log_rerror(const char *file, int line, int module_index,
  406. int level, apr_status_t status,
  407. const request_rec *r, const char *fmt, ...);
  408. #else
  409. #ifdef AP_HAVE_C99
  410. /* need additional step to expand APLOG_MARK first */
  411. #define ap_log_rerror(...) ap_log_rerror__(__VA_ARGS__)
  412. #define ap_log_rerror__(file, line, mi, level, status, r, ...) \
  413. do { if (APLOG_R_MODULE_IS_LEVEL(r, mi, level)) \
  414. ap_log_rerror_(file, line, mi, level, status, r, __VA_ARGS__); \
  415. } while(0)
  416. #else
  417. #define ap_log_rerror ap_log_rerror_
  418. #endif
  419. AP_DECLARE(void) ap_log_rerror_(const char *file, int line, int module_index,
  420. int level, apr_status_t status,
  421. const request_rec *r, const char *fmt, ...)
  422. __attribute__((format(printf,7,8)));
  423. #endif
  424. *)
  425. procedure ap_log_rerror(const file_: PChar; line, module_index, level: Integer;
  426. status: apr_status_t; const r: Prequest_rec;
  427. const fmt: PChar; fmt_args: array of const);
  428. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  429. external LibHTTPD name 'ap_log_rerror_' + LibSuff_;
  430. {**
  431. * ap_log_cerror() - log messages which are related to a particular
  432. * connection. This uses a printf-like format to log messages to the
  433. * error_log.
  434. * @param file The file in which this function is called
  435. * @param line The line number on which this function is called
  436. * @param level The level of this error message
  437. * @param module_index The module_index of the module generating this message
  438. * @param status The status code from the previous command
  439. * @param c The connection which we are logging for
  440. * @param fmt The format string
  441. * @param ... The arguments to use to fill out fmt.
  442. * @note ap_log_cerror is implemented as a macro
  443. * @note Use APLOG_MARK to fill out file, line, and module_index
  444. * @note If a request_rec is available, use that with ap_log_rerror()
  445. * in preference to calling this function.
  446. * @warning It is VERY IMPORTANT that you not include any raw data from
  447. * the network, such as the request-URI or request header fields, within
  448. * the format string. Doing so makes the server vulnerable to a
  449. * denial-of-service attack and other messy behavior. Instead, use a
  450. * simple format string like "%s", followed by the string containing the
  451. * untrusted data.
  452. *}
  453. (*#ifdef DOXYGEN
  454. AP_DECLARE(void) ap_log_cerror(const char *file, int line, int module_index,
  455. int level, apr_status_t status,
  456. const conn_rec *c, const char *fmt, ...);
  457. #else
  458. #ifdef AP_HAVE_C99
  459. /* need additional step to expand APLOG_MARK first */
  460. #define ap_log_cerror(...) ap_log_cerror__(__VA_ARGS__)
  461. #define ap_log_cerror__(file, line, mi, level, status, c, ...) \
  462. do { if (APLOG_C_MODULE_IS_LEVEL(c, mi, level)) \
  463. ap_log_cerror_(file, line, mi, level, status, c, __VA_ARGS__); \
  464. } while(0)
  465. #else
  466. #define ap_log_cerror ap_log_cerror_
  467. #endif
  468. AP_DECLARE(void) ap_log_cerror_(const char *file, int line, int module_index,
  469. int level, apr_status_t status,
  470. const conn_rec *c, const char *fmt, ...)
  471. __attribute__((format(printf,7,8)));
  472. #endif
  473. *)
  474. procedure ap_log_cerror(const file_: PChar; line, module_index, level: Integer;
  475. status: apr_status_t; const c: Pconn_rec;
  476. const fmt: PChar; fmt_args: array of const);
  477. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  478. external LibHTTPD name 'ap_log_cerror' + LibSuff_;
  479. {**
  480. * ap_log_cserror() - log messages which are related to a particular
  481. * connection and to a vhost other than c->base_server. This uses a
  482. * printf-like format to log messages to the error_log.
  483. * @param file The file in which this function is called
  484. * @param line The line number on which this function is called
  485. * @param level The level of this error message
  486. * @param module_index The module_index of the module generating this message
  487. * @param status The status code from the previous command
  488. * @param c The connection which we are logging for
  489. * @param s The server which we are logging for
  490. * @param fmt The format string
  491. * @param ... The arguments to use to fill out fmt.
  492. * @note ap_log_cserror is implemented as a macro
  493. * @note Use APLOG_MARK to fill out file, line, and module_index
  494. * @note If a request_rec is available, use that with ap_log_rerror()
  495. * in preference to calling this function. This function is mainly useful for
  496. * modules like mod_ssl to use before the request_rec is created.
  497. * @warning It is VERY IMPORTANT that you not include any raw data from
  498. * the network, such as the request-URI or request header fields, within
  499. * the format string. Doing so makes the server vulnerable to a
  500. * denial-of-service attack and other messy behavior. Instead, use a
  501. * simple format string like "%s", followed by the string containing the
  502. * untrusted data.
  503. *}
  504. (*#ifdef DOXYGEN
  505. AP_DECLARE(void) ap_log_cserror(const char *file, int line, int module_index,
  506. int level, apr_status_t status,
  507. const conn_rec *c, const server_rec *s,
  508. const char *fmt, ...);
  509. #else
  510. #ifdef AP_HAVE_C99
  511. /* need additional step to expand APLOG_MARK first */
  512. #define ap_log_cserror(...) ap_log_cserror__(__VA_ARGS__)
  513. #define ap_log_cserror__(file, line, mi, level, status, c, s, ...) \
  514. do { if (APLOG_CS_MODULE_IS_LEVEL(c, s, mi, level)) \
  515. ap_log_cserror_(file, line, mi, level, status, c, s, \
  516. __VA_ARGS__); \
  517. } while(0)
  518. #else
  519. #define ap_log_cserror ap_log_cserror_
  520. #endif
  521. AP_DECLARE(void) ap_log_cserror_(const char *file, int line, int module_index,
  522. int level, apr_status_t status,
  523. const conn_rec *c, const server_rec *s,
  524. const char *fmt, ...)
  525. __attribute__((format(printf,8,9)));
  526. #endif
  527. *)
  528. procedure ap_log_cserror(const file_: PChar; line, module_index, level: Integer;
  529. status: apr_status_t; const c: Pconn_rec;
  530. const s: Pserver_rec; const fmt: PChar; fmt_args: array of const);
  531. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  532. external LibHTTPD name 'ap_log_cserror' + LibSuff_;
  533. {**
  534. * Convert stderr to the error log
  535. * @param s The current server
  536. *}
  537. //AP_DECLARE(void) ap_error_log2stderr(server_rec *s);
  538. procedure ap_error_log2stderr(s: Pserver_rec);
  539. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  540. external LibHTTPD name LibNamePrefix + 'ap_error_log2stderr' + LibSuff4;
  541. {**
  542. * Log the command line used to start the server.
  543. * @param p The pool to use for logging
  544. * @param s The server_rec whose process's command line we want to log.
  545. * The command line is logged to that server's error log.
  546. *}
  547. //AP_DECLARE(void) ap_log_command_line(apr_pool_t *p, server_rec *s);
  548. procedure ap_log_command_line(p: Papr_pool_t; s: Pserver_rec);
  549. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  550. external LibHTTPD name LibNamePrefix + 'ap_log_command_line' + LibSuff8;
  551. {**
  552. * Log the current pid of the parent process
  553. * @param p The pool to use for processing
  554. * @param fname The name of the file to log to. If the filename is not
  555. * absolute then it is assumed to be relative to ServerRoot.
  556. *}
  557. //AP_DECLARE(void) ap_log_pid(apr_pool_t *p, const char *fname);
  558. procedure ap_log_pid(p: Papr_pool_t; const fname: PChar);
  559. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  560. external LibHTTPD name LibNamePrefix + 'ap_log_pid' + LibSuff8;
  561. {**
  562. * Remove the pidfile.
  563. * @param p The pool to use for processing
  564. * @param fname The name of the pid file to remove. If the filename is not
  565. * absolute then it is assumed to be relative to ServerRoot.
  566. *}
  567. //AP_DECLARE(void) ap_remove_pid(apr_pool_t *p, const char *fname);
  568. procedure ap_remove_pid(p: Papr_pool_t; const fname: PChar);
  569. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  570. external LibHTTPD name LibNamePrefix + 'ap_remove_pid' + LibSuff8;
  571. {**
  572. * Retrieve the pid from a pidfile.
  573. * @param p The pool to use for processing
  574. * @param filename The name of the file containing the pid. If the filename is not
  575. * absolute then it is assumed to be relative to ServerRoot.
  576. * @param mypid Pointer to pid_t (valid only if return APR_SUCCESS)
  577. *}
  578. //AP_DECLARE(apr_status_t) ap_read_pid(apr_pool_t *p, const char *filename, pid_t *mypid);
  579. function ap_read_pid(p: Papr_pool_t; const filename: PChar; mypid: Ppid_t): apr_status_t;
  580. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  581. external LibHTTPD name LibNamePrefix + 'ap_read_pid' + LibSuff12;
  582. {** @see piped_log *}
  583. //typedef struct piped_log piped_log;
  584. {fpc -> need the real definition here because it is not in header files}
  585. {from httpd-2.4.X/server/log.c}
  586. {**
  587. * @brief The piped logging structure.
  588. *
  589. * Piped logs are used to move functionality out of the main server.
  590. * For example, log rotation is done with piped logs.
  591. *}
  592. type
  593. piped_log = record
  594. //** The pool to use for the piped log */
  595. p: Papr_pool_t;
  596. //** The pipe between the server and the logging process */
  597. read_fd, write_fd: Papr_file_t;
  598. {$ifdef AP_HAVE_RELIABLE_PIPED_LOGS}
  599. //** The name of the program the logging process is running */
  600. program_: PChar;
  601. //** The pid of the logging process */
  602. pid: Papr_proc_t;
  603. //** How to reinvoke program when it must be replaced */
  604. cmdtype: apr_cmdtype_e;
  605. {$endif}
  606. end;
  607. Ppiped_log = ^piped_log;
  608. {**
  609. * Open the piped log process
  610. * @param p The pool to allocate out of
  611. * @param program The program to run in the logging process
  612. * @return The piped log structure
  613. * @note The log program is invoked as @p APR_PROGRAM_ENV,
  614. * @see ap_open_piped_log_ex to modify this behavior
  615. *}
  616. //AP_DECLARE(piped_log *) ap_open_piped_log(apr_pool_t *p, const char *program);
  617. function ap_open_piped_log(p: Papr_pool_t; const program_: PChar): Ppiped_log;
  618. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  619. external LibHTTPD name LibNamePrefix + 'ap_open_piped_log' + LibSuff8;
  620. {**
  621. * Open the piped log process specifying the execution choice for program
  622. * @param p The pool to allocate out of
  623. * @param program The program to run in the logging process
  624. * @param cmdtype How to invoke program, e.g. APR_PROGRAM, APR_SHELLCMD_ENV, etc
  625. * @return The piped log structure
  626. *}
  627. //AP_DECLARE(piped_log *) ap_open_piped_log_ex(apr_pool_t *p,
  628. // const char *program,
  629. // apr_cmdtype_e cmdtype);
  630. function ap_open_piped_log_ex(p: Papr_pool_t;
  631. const program_: PChar;
  632. cmdtype: apr_cmdtype_e): Ppiped_log;
  633. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  634. external LibHTTPD name LibNamePrefix + 'ap_open_piped_log_ex' + LibSuff12;
  635. {**
  636. * Close the piped log and kill the logging process
  637. * @param pl The piped log structure
  638. *}
  639. //AP_DECLARE(void) ap_close_piped_log(piped_log *pl);
  640. procedure ap_close_piped_log(pl: Ppiped_log);
  641. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  642. external LibHTTPD name LibNamePrefix + 'ap_close_piped_log' + LibSuff4;
  643. {**
  644. * A function to return the read side of the piped log pipe
  645. * @param pl The piped log structure
  646. * @return The native file descriptor
  647. *}
  648. //AP_DECLARE(apr_file_t *) ap_piped_log_read_fd(piped_log *pl);
  649. procedure ap_piped_log_read_fd(pl: Ppiped_log);
  650. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  651. external LibHTTPD name LibNamePrefix + 'ap_piped_log_read_fd' + LibSuff4;
  652. {**
  653. * A function to return the write side of the piped log pipe
  654. * @param pl The piped log structure
  655. * @return The native file descriptor
  656. *}
  657. //AP_DECLARE(apr_file_t *) ap_piped_log_write_fd(piped_log *pl);
  658. procedure ap_piped_log_write_fd(pl: Ppiped_log);
  659. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  660. external LibHTTPD name LibNamePrefix + 'ap_piped_log_write_fd' + LibSuff4;
  661. {**
  662. * hook method to generate unique id for connection or request
  663. * @ingroup hooks
  664. * @param c the conn_rec of the connections
  665. * @param r the request_req (may be NULL)
  666. * @param id the place where to store the unique id
  667. * @return OK or DECLINE
  668. *}
  669. //AP_DECLARE_HOOK(int, generate_log_id,
  670. // (const conn_rec *c, const request_rec *r, const char **id))
  671. (*macro expanded:
  672. int ap_HOOK_generate_log_id_t (const conn_rec *c, const request_rec *r, const char **id);
  673. void ap_hook_generate_log_id(ap_HOOK_generate_log_id_t *pf, const char * const *aszPre, const char * const *aszSucc, int nOrder);
  674. int ap_run_generate_log_id (const conn_rec *c, const request_rec *r, const char **id);
  675. apr_array_header_t * ap_hook_get_generate_log_id(void);
  676. typedef struct ap_LINK_generate_log_id_t { ap_HOOK_generate_log_id_t *pFunc; const char *szName; const char * const *aszPredecessors; const char * const *aszSuccessors; int nOrder; } ap_LINK_generate_log_id_t;
  677. *)
  678. type
  679. ap_HOOK_generate_log_id_t = function(const c: Pconn_rec;
  680. const r: Prequest_rec;
  681. const id: PPChar): Longint; cdecl;
  682. procedure ap_hook_generate_log_id(pf: ap_hook_generate_log_id_t; const aszPre: PPChar; const aszSucc: PPChar; nOrder: Longint);
  683. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  684. external LibHTTPD name LibNamePrefix + 'ap_hook_generate_log_id' + LibSuff16;
  685. function ap_run_generate_log_id(const c: Pconn_rec; const r: Prequest_rec; const id: PPChar): Longint;
  686. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  687. external LibHTTPD name LibNamePrefix + 'ap_run_generate_log_id' + LibSuff12;
  688. function ap_hook_get_generate_log_id: Papr_array_header_t;
  689. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  690. external LibHTTPD name LibNamePrefix + 'ap_hook_get_generate_log_id' + LibSuff0;
  691. {rest of macro ignored}
  692. //#endif /* !APACHE_HTTP_LOG_H */
  693. (** @} *)