mturk       2004/07/27 04:42:57

  Added:       ajp/ajplib/test httpd_wrap.h httpd_wrap.c
  Log:
  HTTPD wrapper. Only logging for now.
  
  Revision  Changes    Path
  1.1                  jakarta-tomcat-connectors/ajp/ajplib/test/httpd_wrap.h
  
  Index: httpd_wrap.h
  ===================================================================
  /* Copyright 2000-2004 The Apache Software Foundation
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  
  #ifndef HTTPD_WRAP_H
  #define HTTPD_WRAP_H
  
  #ifdef __cplusplus
  extern "C" {
  #endif
  
  #include "apr.h"
  #include "apr_hooks.h"
  #include "apr_optional_hooks.h"
  #include "apr_thread_proc.h"
  
  /* No WIN32 dll support */
  
  #define AP_DECLARE(type)            type
  #define AP_DECLARE_NONSTD(type)     type
  #define AP_DECLARE_DATA
  
  /** The default string lengths */
  #define MAX_STRING_LEN HUGE_STRING_LEN
  #define HUGE_STRING_LEN 8192
  
  /** The size of the server's internal read-write buffers */
  #define AP_IOBUFSIZE 8192
  
  /* fake structure declarations */
  typedef struct process_rec  process_rec;
  typedef struct request_rec  request_rec;
  typedef struct conn_rec     conn_rec;
  typedef struct server_rec   server_rec;
  
  
  /* fake structure definitions */
  /** A structure that represents one process */
  struct process_rec {
      /** Global pool. Cleared upon normal exit */
      apr_pool_t *pool;
  };
  
  /** A structure that represents the current request */
  struct request_rec {
      /** The pool associated with the request */
      apr_pool_t *pool;
  };
  
  /** Structure to store things which are per connection */
  struct conn_rec {
      /** Pool associated with this connection */
      apr_pool_t *pool;
  };
  
  /** A structure to store information for each virtual server */
  struct server_rec {
      /** The process this server is running in */
      process_rec *process;
  };
  
  /* Apache logging support */
  #define APLOG_EMERG 0   /* system is unusable */
  #define APLOG_ALERT 1   /* action must be taken immediately */
  #define APLOG_CRIT  2   /* critical conditions */
  #define APLOG_ERR   3   /* error conditions */
  #define APLOG_WARNING   4   /* warning conditions */
  #define APLOG_NOTICE    5   /* normal but significant condition */
  #define APLOG_INFO  6   /* informational */
  #define APLOG_DEBUG 7   /* debug-level messages */
  
  #define APLOG_LEVELMASK 7   /* mask off the level value */
  
  
  /* APLOG_NOERRNO is ignored and should not be used.  It will be
   * removed in a future release of Apache.
   */
  #define APLOG_NOERRNO       (APLOG_LEVELMASK + 1)
  
  /* Use APLOG_TOCLIENT on ap_log_rerror() to give content
   * handlers the option of including the error text in the 
   * ErrorDocument sent back to the client. Setting APLOG_TOCLIENT
   * will cause the error text to be saved in the request_rec->notes 
   * table, keyed to the string "error-notes", if and only if:
   * - the severity level of the message is APLOG_WARNING or greater
   * - there are no other "error-notes" set in request_rec->notes
   * Once error-notes is set, it is up to the content handler to
   * determine whether this text should be sent back to the client.
   * Note: Client generated text streams sent back to the client MUST 
   * be escaped to prevent CSS attacks.
   */
  #define APLOG_TOCLIENT          ((APLOG_LEVELMASK + 1) * 2)
  
  /* normal but significant condition on startup, usually printed to stderr */
  #define APLOG_STARTUP           ((APLOG_LEVELMASK + 1) * 4) 
  
  #ifndef DEFAULT_LOGLEVEL
  #define DEFAULT_LOGLEVEL    APLOG_WARNING
  #endif
  
  extern int AP_DECLARE_DATA ap_default_loglevel;
  
  #define APLOG_MARK  __FILE__,__LINE__
  
  
  /**
   * One of the primary logging routines in Apache.  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 status The status code from the previous command
   * @param s The server on which we are logging
   * @param fmt The format string
   * @param ... The arguments to use to fill out fmt.
   * @tip Use APLOG_MARK to fill out file and line
   * @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.
   * @deffunc void ap_log_error(const char *file, int line, int level, apr_status_t 
status, const server_rec *s, const char *fmt, ...) 
   */
  AP_DECLARE(void) ap_log_error(const char *file, int line, int level, 
                               apr_status_t status, const server_rec *s, 
                               const char *fmt, ...)
                  __attribute__((format(printf,6,7)));
  
  /**
   * The second of the primary logging routines in Apache.  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 status The status code from the previous command
   * @param p The pool which we are logging for
   * @param fmt The format string
   * @param ... The arguments to use to fill out fmt.
   * @tip Use APLOG_MARK to fill out file and line
   * @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.
   * @deffunc void ap_log_perror(const char *file, int line, int level, apr_status_t 
status, apr_pool_t *p, const char *fmt, ...) 
   */
  AP_DECLARE(void) ap_log_perror(const char *file, int line, int level, 
                               apr_status_t status, apr_pool_t *p, 
                               const char *fmt, ...)
                  __attribute__((format(printf,6,7)));
  
  /**
   * The last of the primary logging routines in Apache.  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 status The status code from the previous command
   * @param s The request which we are logging for
   * @param fmt The format string
   * @param ... The arguments to use to fill out fmt.
   * @tip Use APLOG_MARK to fill out file and line
   * @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.
   * @deffunc void ap_log_rerror(const char *file, int line, int level, apr_status_t 
status, request_rec *r, const char *fmt, ...) 
   */
  AP_DECLARE(void) ap_log_rerror(const char *file, int line, int level, 
                                 apr_status_t status, const request_rec *r, 
                                 const char *fmt, ...)
                  __attribute__((format(printf,6,7)));
  
  
  
  
  
  
  
  
  #ifdef __cplusplus
  }
  #endif
  
  #endif /* HTTPD_WRAP_H */
  
  
  
  1.1                  jakarta-tomcat-connectors/ajp/ajplib/test/httpd_wrap.c
  
  Index: httpd_wrap.c
  ===================================================================
  /* Copyright 2000-2004 The Apache Software Foundation
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  #include "apr.h"
  #include "apr_lib.h"
  #include "apr_strings.h"
  #include "apr_buckets.h"
  #include "apr_md5.h"
  #include "apr_network_io.h"
  #include "apr_pools.h"
  #include "apr_strings.h"
  #include "apr_uri.h"
  #include "apr_date.h"
  #include "apr_fnmatch.h"
  #define APR_WANT_STRFUNC
  #include "apr_want.h"
   
  #include "apr_hooks.h"
  #include "apr_optional_hooks.h"
  #include "apr_buckets.h"
  
  #include "httpd_wrap.h"
  
  static const char *levels[] = {
      "emerg",
      "alert",
      "crit",
      "error",
      "warn",
      "notice",
      "info",
      "debug",
      NULL
  };
  
  static void log_error_core(const char *file, int line, int level,
                             apr_status_t status,
                             const char *fmt, va_list args)
  {
      FILE *stream;
      char timstr[32];
      char errstr[MAX_STRING_LEN];
  
      if (level < APLOG_WARNING)
          stream = stderr;
      else
          stream = stdout;
      apr_ctime(&timstr[0], apr_time_now());
      fprintf(stream, "[%s] [%s] ", timstr, levels[level]);
      if (file && level == APLOG_DEBUG) {
  #ifndef WIN32
          char *e = strrchr(file, '/');
  #else
          char *e = strrchr(file, '\\');
  #endif
          if (e)
              fprintf(stream, "%s (%d) ", e + 1, line);
      }
  
      if (status != 0) {
          if (status < APR_OS_START_EAIERR) {
              fprintf(stream, "(%d)", status);
          }
          else if (status < APR_OS_START_SYSERR) {
              fprintf(stream, "(EAI %d)", status - APR_OS_START_EAIERR);
          }
          else if (status < 100000 + APR_OS_START_SYSERR) {
              fprintf(stream, "(OS %d)", status - APR_OS_START_SYSERR);
          }
          else {
              fprintf(stream, "os 0x%08x)", status - APR_OS_START_SYSERR);
          }
          apr_strerror(status, errstr, MAX_STRING_LEN);
          fprintf(stream, " %s ", errstr);
      }
  
      apr_vsnprintf(errstr, MAX_STRING_LEN, fmt, args);
      fputs(errstr, stream);
      fputs("\n", stream);    
      if (level < APLOG_WARNING)
          fflush(stream);
  
  }
  
  AP_DECLARE(void) ap_log_error(const char *file, int line, int level,
                                apr_status_t status, const server_rec *s,
                                const char *fmt, ...)
  {
      va_list args;
  
      va_start(args, fmt);
      log_error_core(file, line, level, status, fmt, args);
      va_end(args);
  }
  
  AP_DECLARE(void) ap_log_perror(const char *file, int line, int level,
                                 apr_status_t status, apr_pool_t *p,
                                 const char *fmt, ...)
  {
      va_list args;
  
      va_start(args, fmt);
      log_error_core(file, line, level, status, fmt, args);
      va_end(args);
  }
   
  
  AP_DECLARE(void) ap_log_rerror(const char *file, int line, int level,
                                 apr_status_t status, const request_rec *r,
                                 const char *fmt, ...)
  {
      va_list args;
  
      va_start(args, fmt);
      log_error_core(file, line, level, status, fmt, args);
      va_end(args);
  }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to