home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Servidores / apache_2.2.8-win32-x86-no_ssl.msi / Data1.cab / _96ECDBCE47C5CE5D12B63941CE243420 < prev    next >
Text File  |  2006-07-11  |  14KB  |  346 lines

  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. /**
  18.  * @file  http_log.h
  19.  * @brief Apache Logging library
  20.  *
  21.  * @defgroup APACHE_CORE_LOG Logging library
  22.  * @ingroup  APACHE_CORE
  23.  * @{
  24.  */
  25.  
  26. #ifndef APACHE_HTTP_LOG_H
  27. #define APACHE_HTTP_LOG_H
  28.  
  29. #ifdef __cplusplus
  30. extern "C" {
  31. #endif
  32.  
  33. #include "apr_thread_proc.h"
  34.  
  35. #ifdef HAVE_SYSLOG
  36. #include <syslog.h>
  37.  
  38. #ifndef LOG_PRIMASK
  39. #define LOG_PRIMASK 7
  40. #endif
  41.  
  42. #define APLOG_EMERG     LOG_EMERG     /* system is unusable */
  43. #define APLOG_ALERT     LOG_ALERT     /* action must be taken immediately */
  44. #define APLOG_CRIT      LOG_CRIT      /* critical conditions */
  45. #define APLOG_ERR       LOG_ERR       /* error conditions */
  46. #define APLOG_WARNING   LOG_WARNING   /* warning conditions */
  47. #define APLOG_NOTICE    LOG_NOTICE    /* normal but significant condition */
  48. #define APLOG_INFO      LOG_INFO      /* informational */
  49. #define APLOG_DEBUG     LOG_DEBUG     /* debug-level messages */
  50.  
  51. #define APLOG_LEVELMASK LOG_PRIMASK   /* mask off the level value */
  52.  
  53. #else
  54.  
  55. #define    APLOG_EMERG    0    /* system is unusable */
  56. #define    APLOG_ALERT    1    /* action must be taken immediately */
  57. #define    APLOG_CRIT    2    /* critical conditions */
  58. #define    APLOG_ERR    3    /* error conditions */
  59. #define    APLOG_WARNING    4    /* warning conditions */
  60. #define    APLOG_NOTICE    5    /* normal but significant condition */
  61. #define    APLOG_INFO    6    /* informational */
  62. #define    APLOG_DEBUG    7    /* debug-level messages */
  63.  
  64. #define    APLOG_LEVELMASK    7    /* mask off the level value */
  65.  
  66. #endif
  67.  
  68. /* APLOG_NOERRNO is ignored and should not be used.  It will be
  69.  * removed in a future release of Apache.
  70.  */
  71. #define APLOG_NOERRNO        (APLOG_LEVELMASK + 1)
  72.  
  73. /* Use APLOG_TOCLIENT on ap_log_rerror() to give content
  74.  * handlers the option of including the error text in the 
  75.  * ErrorDocument sent back to the client. Setting APLOG_TOCLIENT
  76.  * will cause the error text to be saved in the request_rec->notes 
  77.  * table, keyed to the string "error-notes", if and only if:
  78.  * - the severity level of the message is APLOG_WARNING or greater
  79.  * - there are no other "error-notes" set in request_rec->notes
  80.  * Once error-notes is set, it is up to the content handler to
  81.  * determine whether this text should be sent back to the client.
  82.  * Note: Client generated text streams sent back to the client MUST 
  83.  * be escaped to prevent CSS attacks.
  84.  */
  85. #define APLOG_TOCLIENT          ((APLOG_LEVELMASK + 1) * 2)
  86.  
  87. /* normal but significant condition on startup, usually printed to stderr */
  88. #define APLOG_STARTUP           ((APLOG_LEVELMASK + 1) * 4) 
  89.  
  90. #ifndef DEFAULT_LOGLEVEL
  91. #define DEFAULT_LOGLEVEL    APLOG_WARNING
  92. #endif
  93.  
  94. extern int AP_DECLARE_DATA ap_default_loglevel;
  95.  
  96. #define APLOG_MARK    __FILE__,__LINE__
  97.  
  98. /**
  99.  * Set up for logging to stderr.
  100.  * @param p The pool to allocate out of
  101.  */
  102. AP_DECLARE(void) ap_open_stderr_log(apr_pool_t *p);
  103.  
  104. /**
  105.  * Replace logging to stderr with logging to the given file.
  106.  * @param p The pool to allocate out of
  107.  * @param file Name of the file to log stderr output
  108.  */
  109. AP_DECLARE(apr_status_t) ap_replace_stderr_log(apr_pool_t *p, 
  110.                                                const char *file);
  111.  
  112. /**
  113.  * Open the error log and replace stderr with it.
  114.  * @param pconf Not used
  115.  * @param plog  The pool to allocate the logs from
  116.  * @param ptemp Pool used for temporary allocations
  117.  * @param s_main The main server
  118.  * @note ap_open_logs isn't expected to be used by modules, it is
  119.  * an internal core function 
  120.  */
  121. int ap_open_logs(apr_pool_t *pconf, apr_pool_t *plog, 
  122.                  apr_pool_t *ptemp, server_rec *s_main);
  123.  
  124. #ifdef CORE_PRIVATE
  125.  
  126. /**
  127.  * Perform special processing for piped loggers in MPM child
  128.  * processes.
  129.  * @param p Not used
  130.  * @param s Not used
  131.  * @note ap_logs_child_init is not for use by modules; it is an
  132.  * internal core function
  133.  */
  134. void ap_logs_child_init(apr_pool_t *p, server_rec *s);
  135.  
  136. #endif /* CORE_PRIVATE */
  137.  
  138. /* 
  139.  * The primary logging functions, ap_log_error, ap_log_rerror, ap_log_cerror,
  140.  * and ap_log_perror use a printf style format string to build the log message.  
  141.  * It is VERY IMPORTANT that you not include any raw data from the network, 
  142.  * such as the request-URI or request header fields, within the format 
  143.  * string.  Doing so makes the server vulnerable to a denial-of-service 
  144.  * attack and other messy behavior.  Instead, use a simple format string 
  145.  * like "%s", followed by the string containing the untrusted data.
  146.  */
  147.  
  148. /**
  149.  * ap_log_error() - log messages which are not related to a particular
  150.  * request or connection.  This uses a printf-like format to log messages
  151.  * to the error_log.
  152.  * @param file The file in which this function is called
  153.  * @param line The line number on which this function is called
  154.  * @param level The level of this error message
  155.  * @param status The status code from the previous command
  156.  * @param s The server on which we are logging
  157.  * @param fmt The format string
  158.  * @param ... The arguments to use to fill out fmt.
  159.  * @note Use APLOG_MARK to fill out file and line
  160.  * @note If a request_rec is available, use that with ap_log_rerror()
  161.  * in preference to calling this function.  Otherwise, if a conn_rec is
  162.  * available, use that with ap_log_cerror() in preference to calling
  163.  * this function.
  164.  * @warning It is VERY IMPORTANT that you not include any raw data from 
  165.  * the network, such as the request-URI or request header fields, within 
  166.  * the format string.  Doing so makes the server vulnerable to a 
  167.  * denial-of-service attack and other messy behavior.  Instead, use a 
  168.  * simple format string like "%s", followed by the string containing the 
  169.  * untrusted data.
  170.  */
  171. AP_DECLARE(void) ap_log_error(const char *file, int line, int level, 
  172.                              apr_status_t status, const server_rec *s, 
  173.                              const char *fmt, ...)
  174.                 __attribute__((format(printf,6,7)));
  175.  
  176. /**
  177.  * ap_log_perror() - log messages which are not related to a particular
  178.  * request, connection, or virtual server.  This uses a printf-like
  179.  * format to log messages to the error_log.
  180.  * @param file The file in which this function is called
  181.  * @param line The line number on which this function is called
  182.  * @param level The level of this error message
  183.  * @param status The status code from the previous command
  184.  * @param p The pool which we are logging for
  185.  * @param fmt The format string
  186.  * @param ... The arguments to use to fill out fmt.
  187.  * @note Use APLOG_MARK to fill out file and line
  188.  * @warning It is VERY IMPORTANT that you not include any raw data from 
  189.  * the network, such as the request-URI or request header fields, within 
  190.  * the format string.  Doing so makes the server vulnerable to a 
  191.  * denial-of-service attack and other messy behavior.  Instead, use a 
  192.  * simple format string like "%s", followed by the string containing the 
  193.  * untrusted data.
  194.  */
  195. AP_DECLARE(void) ap_log_perror(const char *file, int line, int level, 
  196.                              apr_status_t status, apr_pool_t *p, 
  197.                              const char *fmt, ...)
  198.                 __attribute__((format(printf,6,7)));
  199.  
  200. /**
  201.  * ap_log_rerror() - log messages which are related to a particular
  202.  * request.  This uses a a printf-like format to log messages to the
  203.  * error_log.
  204.  * @param file The file in which this function is called
  205.  * @param line The line number on which this function is called
  206.  * @param level The level of this error message
  207.  * @param status The status code from the previous command
  208.  * @param r The request which we are logging for
  209.  * @param fmt The format string
  210.  * @param ... The arguments to use to fill out fmt.
  211.  * @note Use APLOG_MARK to fill out file and line
  212.  * @warning It is VERY IMPORTANT that you not include any raw data from 
  213.  * the network, such as the request-URI or request header fields, within 
  214.  * the format string.  Doing so makes the server vulnerable to a 
  215.  * denial-of-service attack and other messy behavior.  Instead, use a 
  216.  * simple format string like "%s", followed by the string containing the 
  217.  * untrusted data.
  218.  */
  219. AP_DECLARE(void) ap_log_rerror(const char *file, int line, int level, 
  220.                                apr_status_t status, const request_rec *r, 
  221.                                const char *fmt, ...)
  222.                 __attribute__((format(printf,6,7)));
  223.  
  224. /**
  225.  * ap_log_cerror() - log messages which are related to a particular
  226.  * connection.  This uses a a printf-like format to log messages to the
  227.  * error_log.
  228.  * @param file The file in which this function is called
  229.  * @param line The line number on which this function is called
  230.  * @param level The level of this error message
  231.  * @param status The status code from the previous command
  232.  * @param c The connection which we are logging for
  233.  * @param fmt The format string
  234.  * @param ... The arguments to use to fill out fmt.
  235.  * @note Use APLOG_MARK to fill out file and line
  236.  * @note If a request_rec is available, use that with ap_log_rerror()
  237.  * in preference to calling this function.
  238.  * @warning It is VERY IMPORTANT that you not include any raw data from 
  239.  * the network, such as the request-URI or request header fields, within 
  240.  * the format string.  Doing so makes the server vulnerable to a 
  241.  * denial-of-service attack and other messy behavior.  Instead, use a 
  242.  * simple format string like "%s", followed by the string containing the 
  243.  * untrusted data.
  244.  */
  245. AP_DECLARE(void) ap_log_cerror(const char *file, int line, int level, 
  246.                                apr_status_t status, const conn_rec *c, 
  247.                                const char *fmt, ...)
  248.                 __attribute__((format(printf,6,7)));
  249.  
  250. /**
  251.  * Convert stderr to the error log
  252.  * @param s The current server
  253.  */
  254. AP_DECLARE(void) ap_error_log2stderr(server_rec *s);
  255.  
  256. /**
  257.  * Log the current pid of the parent process
  258.  * @param p The pool to use for logging
  259.  * @param fname The name of the file to log to
  260.  */
  261. AP_DECLARE(void) ap_log_pid(apr_pool_t *p, const char *fname);
  262.  
  263. /**
  264.  * Retrieve the pid from a pidfile.
  265.  * @param p The pool to use for logging
  266.  * @param filename The name of the file containing the pid
  267.  * @param mypid Pointer to pid_t (valid only if return APR_SUCCESS)
  268.  */
  269. AP_DECLARE(apr_status_t) ap_read_pid(apr_pool_t *p, const char *filename, pid_t *mypid);
  270.  
  271. /** @see piped_log */
  272. typedef struct piped_log piped_log;
  273.  
  274. /**
  275.  * @brief The piped logging structure.  
  276.  *
  277.  * Piped logs are used to move functionality out of the main server.  
  278.  * For example, log rotation is done with piped logs.
  279.  */
  280. struct piped_log {
  281.     /** The pool to use for the piped log */
  282.     apr_pool_t *p;
  283.     /** The pipe between the server and the logging process */
  284.     apr_file_t *fds[2];
  285.     /* XXX - an #ifdef that needs to be eliminated from public view. Shouldn't
  286.      * be hard */
  287. #ifdef AP_HAVE_RELIABLE_PIPED_LOGS
  288.     /** The name of the program the logging process is running */
  289.     char *program;
  290.     /** The pid of the logging process */
  291.     apr_proc_t *pid;
  292. #endif
  293. };
  294.  
  295. /**
  296.  * Open the piped log process
  297.  * @param p The pool to allocate out of
  298.  * @param program The program to run in the logging process
  299.  * @return The piped log structure
  300.  */
  301. AP_DECLARE(piped_log *) ap_open_piped_log(apr_pool_t *p, const char *program);
  302.  
  303. /**
  304.  * Close the piped log and kill the logging process
  305.  * @param pl The piped log structure
  306.  */
  307. AP_DECLARE(void) ap_close_piped_log(piped_log *pl);
  308.  
  309. /**
  310.  * A macro to access the read side of the piped log pipe
  311.  * @param pl The piped log structure
  312.  * @return The native file descriptor
  313.  */
  314. #define ap_piped_log_read_fd(pl)    ((pl)->fds[0])
  315.  
  316. /**
  317.  * A macro to access the write side of the piped log pipe
  318.  * @param pl The piped log structure
  319.  * @return The native file descriptor
  320.  */
  321. #define ap_piped_log_write_fd(pl)    ((pl)->fds[1])
  322.  
  323. /**
  324.  * hook method to log error messages 
  325.  * @ingroup hooks
  326.  * @param file The file in which this function is called
  327.  * @param line The line number on which this function is called
  328.  * @param level The level of this error message
  329.  * @param status The status code from the previous command
  330.  * @param s The server which we are logging for
  331.  * @param r The request which we are logging for
  332.  * @param pool Memory pool to allocate from
  333.  * @param errstr message to log 
  334.  */
  335. AP_DECLARE_HOOK(void, error_log, (const char *file, int line, int level,
  336.                        apr_status_t status, const server_rec *s,
  337.                        const request_rec *r, apr_pool_t *pool,
  338.                        const char *errstr))
  339.  
  340. #ifdef __cplusplus
  341. }
  342. #endif
  343.  
  344. #endif    /* !APACHE_HTTP_LOG_H */
  345. /** @} */
  346.