* 20100606.1 (2.3.6-dev) Added extended timestamp formatting via
* ap_recent_ctime_ex().
* 20100609.0 (2.3.6-dev) Dropped ap_args_to_table due to missing constraints.
+ * 20100609.1 (2.3.7-dev) Introduce ap_log_cserror()
*/
#define MODULE_MAGIC_COOKIE 0x41503234UL /* "AP24" */
#ifndef MODULE_MAGIC_NUMBER_MAJOR
#define MODULE_MAGIC_NUMBER_MAJOR 20100609
#endif
-#define MODULE_MAGIC_NUMBER_MINOR 0 /* 0...n */
+#define MODULE_MAGIC_NUMBER_MINOR 1 /* 0...n */
/**
* Determine if the server's current MODULE_MAGIC_NUMBER is at least a
*/
AP_DECLARE(int) ap_get_conn_module_loglevel(const conn_rec *c, int index);
+/**
+ * Generic accessor for modules the module-specific loglevel
+ * @param c The connection from which to get the loglevel.
+ * @param s The server from which to get the loglevel if c does not have a
+ * specific loglevel configuration.
+ * @param index The module_index of the module to get the loglevel for.
+ * @return The module-specific loglevel
+ */
+AP_DECLARE(int) ap_get_conn_server_module_loglevel(const conn_rec *c,
+ const server_rec *s,
+ int index);
+
/**
* Generic accessor for modules to get the module-specific loglevel
* @param r The request from which to get the loglevel.
((c)->log ? (c)->log : \
&(c)->base_server->log)
+#define ap_get_conn_server_logconf(c,s) \
+ ( ( (c)->log != &(c)->base_server->log && (c)->log != NULL ) ? \
+ (c)->log : \
+ &(s)->log )
+
#define ap_get_request_logconf(r) \
((r)->log ? (r)->log : \
(r)->connection->log ? (r)->connection->log : \
#define ap_get_conn_module_loglevel(c,i) \
(ap_get_module_loglevel(ap_get_conn_logconf(c),i))
+#define ap_get_conn_server_module_loglevel(c,s,i) \
+ (ap_get_module_loglevel(ap_get_conn_server_logconf(c,s),i))
+
#define ap_get_request_module_loglevel(r,i) \
(ap_get_module_loglevel(ap_get_request_logconf(r),i))
( (((level)&APLOG_LEVELMASK) <= APLOG_NOTICE) || \
(ap_get_conn_module_loglevel(c, module_index) \
>= ((level)&APLOG_LEVELMASK) ) )
+#define APLOG_CS_MODULE_IS_LEVEL(c,s,module_index,level) \
+ ( (((level)&APLOG_LEVELMASK) <= APLOG_NOTICE) || \
+ (ap_get_conn_server_module_loglevel(c, s, module_index) \
+ >= ((level)&APLOG_LEVELMASK) ) )
#define APLOG_R_MODULE_IS_LEVEL(r,module_index,level) \
( (((level)&APLOG_LEVELMASK) <= APLOG_NOTICE) || \
(ap_get_request_module_loglevel(r, module_index) \
(s == NULL) || \
(ap_get_server_module_loglevel(s, module_index) \
>= ((level)&APLOG_LEVELMASK) ) ) )
+#define APLOG_CS_MODULE_IS_LEVEL(c,s,module_index,level) \
+ ( (((level)&APLOG_LEVELMASK) <= APLOG_MAX_LOGLEVEL) && \
+ ( (((level)&APLOG_LEVELMASK) <= APLOG_NOTICE) || \
+ (ap_get_conn_server_module_loglevel(c, s, module_index) \
+ >= ((level)&APLOG_LEVELMASK) ) ) )
#define APLOG_C_MODULE_IS_LEVEL(c,module_index,level) \
( (((level)&APLOG_LEVELMASK) <= APLOG_MAX_LOGLEVEL) && \
( (((level)&APLOG_LEVELMASK) <= APLOG_NOTICE) || \
APLOG_MODULE_IS_LEVEL(s,APLOG_MODULE_INDEX,level)
#define APLOG_C_IS_LEVEL(c,level) \
APLOG_C_MODULE_IS_LEVEL(c,APLOG_MODULE_INDEX,level)
+#define APLOG_CS_IS_LEVEL(c,s,level) \
+ APLOG_CS_MODULE_IS_LEVEL(c,s,APLOG_MODULE_INDEX,level)
#define APLOG_R_IS_LEVEL(r,level) \
APLOG_R_MODULE_IS_LEVEL(r,APLOG_MODULE_INDEX,level)
/**
* ap_log_rerror() - log messages which are related to a particular
- * request. This uses a a printf-like format to log messages to the
+ * request. This uses a printf-like format to log messages to the
* error_log.
* @param file The file in which this function is called
* @param line The line number on which this function is called
/**
* ap_log_cerror() - log messages which are related to a particular
- * connection. This uses a a printf-like format to log messages to the
+ * connection. This uses a printf-like format to log messages to the
* error_log.
* @param file The file in which this function is called
* @param line The line number on which this function is called
const conn_rec *c, const char *fmt, ...)
__attribute__((format(printf,7,8)));
+/**
+ * ap_log_cserror() - log messages which are related to a particular
+ * connection and to a vhost other than c->base_server. This uses a
+ * printf-like format to log messages to the error_log.
+ * @param file The file in which this function is called
+ * @param line The line number on which this function is called
+ * @param level The level of this error message
+ * @param module_index The module_index of the module generating this message
+ * @param status The status code from the previous command
+ * @param c The connection which we are logging for
+ * @param s The server which we are logging for
+ * @param fmt The format string
+ * @param ... The arguments to use to fill out fmt.
+ * @note Use APLOG_MARK to fill out file and line
+ * @note If a request_rec is available, use that with ap_log_rerror()
+ * in preference to calling this function. This function is mainly useful for
+ * modules like mod_ssl to use before the request_rec is created.
+ * @warning It is VERY IMPORTANT that you not include any raw data from
+ * the network, such as the request-URI or request header fields, within
+ * the format string. Doing so makes the server vulnerable to a
+ * denial-of-service attack and other messy behavior. Instead, use a
+ * simple format string like "%s", followed by the string containing the
+ * untrusted data.
+ */
+#if __STDC_VERSION__ >= 199901L
+/* need additional step to expand APLOG_MARK first */
+#define ap_log_cserror(...) ap_log_cserror__(__VA_ARGS__)
+#define ap_log_cserror__(file, line, mi, level, status, c, s, ...) \
+ do { if (APLOG_CS_MODULE_IS_LEVEL(c, s, mi, level)) \
+ ap_log_cserror_(file, line, mi, level, status, c, s, \
+ __VA_ARGS__); \
+ } while(0)
+#else
+#define ap_log_cserror ap_log_cserror_
+#endif
+AP_DECLARE(void) ap_log_cserror_(const char *file, int line, int module_level,
+ int level, apr_status_t status,
+ const conn_rec *c, const server_rec *s,
+ const char *fmt, ...)
+ __attribute__((format(printf,8,9)));
+
/**
* Convert stderr to the error log
* @param s The current server
SSL_smart_shutdown(ssl);
/* and finally log the fact that we've closed the connection */
- if (APLOG_C_IS_LEVEL(c, loglevel)) {
- ap_log_cerror(APLOG_MARK, loglevel, 0, c,
- "Connection closed to child %ld with %s shutdown "
- "(server %s)",
- c->id, type, ssl_util_vhostid(c->pool, mySrvFromConn(c)));
+ if (APLOG_CS_IS_LEVEL(c, mySrvFromConn(c), loglevel)) {
+ ap_log_cserror(APLOG_MARK, loglevel, 0, c, mySrvFromConn(c),
+ "Connection closed to child %ld with %s shutdown "
+ "(server %s)",
+ c->id, type,
+ ssl_util_vhostid(c->pool, mySrvFromConn(c)));
}
/* deallocate the SSL connection */
apr_pool_cleanup_register(c->pool, (void*)filter_ctx,
ssl_io_filter_cleanup, apr_pool_cleanup_null);
- if (APLOGctrace4(c)) {
+ if (APLOG_CS_IS_LEVEL(c, mySrvFromConn(c), APLOG_TRACE4)) {
BIO_set_callback(SSL_get_rbio(ssl), ssl_io_data_cb);
BIO_set_callback_arg(SSL_get_rbio(ssl), (void *)ssl);
}
if ( cmd == (BIO_CB_WRITE|BIO_CB_RETURN)
|| cmd == (BIO_CB_READ |BIO_CB_RETURN) ) {
if (rc >= 0) {
- ap_log_error(APLOG_MARK, APLOG_TRACE4, 0, s,
+ ap_log_cserror(APLOG_MARK, APLOG_TRACE4, 0, c, s,
"%s: %s %ld/%d bytes %s BIO#%pp [mem: %pp] %s",
SSL_LIBRARY_NAME,
(cmd == (BIO_CB_WRITE|BIO_CB_RETURN) ? "write" : "read"),
rc, argi, (cmd == (BIO_CB_WRITE|BIO_CB_RETURN) ? "to" : "from"),
bio, argp,
(argp != NULL ? "(BIO dump follows)" : "(Oops, no memory buffer?)"));
- if ((argp != NULL) && APLOGctrace7(c))
+ if ((argp != NULL) && APLOG_CS_IS_LEVEL(c, s, APLOG_TRACE7))
ssl_io_data_dump(s, argp, rc);
}
else {
- ap_log_error(APLOG_MARK, APLOG_TRACE4, 0, s,
+ ap_log_cserror(APLOG_MARK, APLOG_TRACE4, 0, c, s,
"%s: I/O error, %d bytes expected to %s on BIO#%pp [mem: %pp]",
SSL_LIBRARY_NAME, argi,
(cmd == (BIO_CB_WRITE|BIO_CB_RETURN) ? "write" : "read"),
* There is one special filter callback, which is set
* very early depending on the base_server's log level.
* If this is not the first vhost we're now selecting
- * (and the first vhost doesn't use APLOG_DEBUG), then
+ * (and the first vhost doesn't use APLOG_TRACE4), then
* we need to set that callback here.
*/
- if (APLOGdebug(s)) {
+ if (APLOGtrace4(s)) {
BIO_set_callback(SSL_get_rbio(ssl), ssl_io_data_cb);
BIO_set_callback_arg(SSL_get_rbio(ssl), (void *)ssl);
}
va_end(args);
}
+AP_DECLARE(void) ap_log_cserror_(const char *file, int line, int module_index,
+ int level, apr_status_t status,
+ const conn_rec *c, const server_rec *s,
+ const char *fmt, ...)
+{
+ va_list args;
+
+ va_start(args, fmt);
+ log_error_core(file, line, module_index, level, status, s, c,
+ NULL, NULL, fmt, args);
+ va_end(args);
+}
+
AP_DECLARE(void) ap_log_cerror_(const char *file, int line, int module_index,
int level, apr_status_t status,
const conn_rec *c, const char *fmt, ...)
return l->module_levels[module_index];
}
+#if defined(ap_get_conn_server_module_loglevel)
+#undef ap_get_conn_server_module_loglevel
+AP_DECLARE(int) ap_get_conn_server_module_loglevel(const conn_rec *c,
+ const server_rec *s,
+ int module_index);
+#endif
+
+AP_DECLARE(int) ap_get_conn_server_module_loglevel(const conn_rec *c,
+ const server_rec *s,
+ int module_index)
+{
+ const struct ap_logconf *l = (c->log && c->log != &c->base_server->log) ?
+ c->log : &s->log;
+ if (module_index < 0 || l->module_levels == NULL ||
+ l->module_levels[module_index] < 0)
+ {
+ return l->level;
+ }
+
+ return l->module_levels[module_index];
+}
+
#if defined(ap_get_request_module_loglevel)
#undef ap_get_request_module_loglevel
AP_DECLARE(int) ap_get_request_module_loglevel(const request_rec *c, int module_index);