"Fossies" - the Fresh Open Source Software Archive

Member "mod_log_sql-1.101/functions.h" (20 Sep 2004, 6644 Bytes) of package /linux/www/apache_httpd_modules/old/mod_log_sql-1.101.tar.bz2:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 /* $Id: functions.h 151 2004-09-20 02:51:50Z urkle@drip.ws $ */
    2 
    3 /* Begin the individual functions that, given a request r,
    4  * extract the needed information from it and return the
    5  * value to the calling entity.
    6  */
    7 
    8 static const char *extract_remote_host(request_rec *r, char *a)
    9 {
   10     return (char *) ap_get_remote_host(r->connection, r->per_dir_config, REMOTE_NAME, NULL);
   11 }
   12 
   13 static const char *extract_remote_address(request_rec *r, char *a) __attribute__((unused));
   14 
   15 static const char *extract_remote_address(request_rec *r, char *a)
   16 {
   17     return r->connection->remote_ip;
   18 }
   19 
   20 static const char *extract_local_address(request_rec *r, char *a) __attribute__((unused));
   21 
   22 static const char *extract_local_address(request_rec *r, char *a)
   23 {
   24     return r->connection->local_ip;
   25 }
   26 
   27 static const char *extract_remote_logname(request_rec *r, char *a)
   28 {
   29     return (char *) ap_get_remote_logname(r);
   30 }
   31 
   32 static const char *extract_remote_user(request_rec *r, char *a)
   33 {
   34     #ifdef WITH_APACHE13
   35     char *rvalue = r->connection->user;
   36     #else
   37     char *rvalue = r->user;
   38     #endif
   39     if (rvalue == NULL) {
   40         rvalue = "-";
   41     } else if (strlen(rvalue) == 0) {
   42         rvalue = "\"\"";
   43     }
   44     return rvalue;
   45 }
   46 
   47 static const char *extract_request_line(request_rec *r, char *a)
   48 {
   49     /* Upddated to mod_log_config logic */
   50     /* NOTE: If the original request contained a password, we
   51      * re-write the request line here to contain XXXXXX instead:
   52      * (note the truncation before the protocol string for HTTP/0.9 requests)
   53      * (note also that r->the_request contains the unmodified request)
   54      */
   55     return (r->parsed_uri.password) 
   56                 ? apr_pstrcat(r->pool, r->method, " ",
   57                     apr_uri_unparse(r->pool,
   58                         &r->parsed_uri, 0),
   59                     r->assbackwards ? NULL : " ", 
   60                     r->protocol, NULL)
   61                 : r->the_request;
   62 }
   63 
   64 static const char *extract_request_file(request_rec *r, char *a)
   65 {
   66     return r->filename;
   67 }
   68 
   69 static const char *extract_request_uri(request_rec *r, char *a)
   70 {
   71     return r->uri;
   72 }
   73 
   74 static const char *extract_request_method(request_rec *r, char *a)
   75 {
   76     return r->method;
   77 }
   78 
   79 static const char *extract_request_protocol(request_rec *r, char *a)
   80 {
   81     return r->protocol;
   82 }
   83 
   84 static const char *extract_request_query(request_rec *r, char *a)
   85 {
   86     return (r->args) ? apr_pstrcat(r->pool, "?",
   87                         r->args, NULL)
   88                      : "";
   89 }
   90 
   91 static const char *extract_status(request_rec *r, char *a)
   92 {
   93     if (r->status <= 0) {
   94         return "-";
   95     } else {
   96         return apr_psprintf(r->pool, "%d", r->status);
   97     }
   98 }
   99 
  100 static const char *extract_virtual_host(request_rec *r, char *a)
  101 {
  102     return r->server->server_hostname;
  103 }
  104 
  105 static const char *extract_server_name(request_rec *r, char *a)
  106 {
  107     return ap_get_server_name(r);
  108 }
  109 
  110 static const char *extract_machine_id(request_rec *r, char *a)
  111 {
  112     if (!global_config.machid)
  113         return "-";
  114     else
  115         return global_config.machid;
  116 }
  117 
  118 static const char *extract_server_port(request_rec *r, char *a)
  119 {
  120     return apr_psprintf(r->pool, "%u",
  121                         r->server->port ? r->server->port : ap_default_port(r));
  122 }
  123 
  124 /* This respects the setting of UseCanonicalName so that
  125  * the dynamic mass virtual hosting trick works better.
  126  */
  127 static const char *log_server_name(request_rec *r, char *a) __attribute__((unused));
  128 static const char *log_server_name(request_rec *r, char *a)
  129 {
  130     return ap_get_server_name(r);
  131 }
  132 
  133 static const char *extract_child_pid(request_rec *r, char *a)
  134 {
  135     if (*a == '\0' || !strcmp(a, "pid")) {
  136         return apr_psprintf(r->pool, "%" APR_PID_T_FMT, getpid());
  137     }
  138     else if (!strcmp(a, "tid")) {
  139 #if APR_HAS_THREADS
  140         apr_os_thread_t tid = apr_os_thread_current();
  141 #else
  142         int tid = 0; /* APR will format "0" anyway but an arg is needed */
  143 #endif
  144         return apr_psprintf(r->pool, "%pT", &tid);
  145     }
  146     /* bogus format */
  147     return a;
  148 }
  149 
  150 static const char *extract_referer(request_rec *r, char *a)
  151 {
  152     const char *tempref;
  153 
  154     tempref = apr_table_get(r->headers_in, "Referer");
  155     if (!tempref)
  156     {
  157         return "-";
  158     } else {
  159         return tempref;
  160     }
  161 }
  162 
  163 static const char *extract_agent(request_rec *r, char *a)
  164 {
  165     const char *tempag;
  166 
  167     tempag = apr_table_get(r->headers_in, "User-Agent");
  168     if (!tempag)
  169     {
  170         return "-";
  171     } else {
  172         return tempag;
  173     }
  174 }
  175 
  176 static const char *extract_specific_cookie(request_rec *r, char *a)
  177 {
  178     const char *cookiestr;
  179     char *cookieend;
  180     char *isvalid;
  181     char *cookiebuf;
  182 
  183     if (a != NULL) {
  184         log_error(APLOG_MARK,APLOG_DEBUG, 0, r->server,
  185             "watching for cookie '%s'", a);
  186 
  187         /* Fetch out the cookie header */
  188         cookiestr  = (char *)apr_table_get(r->headers_in,  "cookie2");
  189         if (cookiestr != NULL) {
  190             log_error(APLOG_MARK,APLOG_DEBUG, 0, r->server,
  191                 "Cookie2: [%s]", cookiestr);
  192             /* Does the cookie string contain one with our name? */
  193             isvalid = ap_strstr_c(cookiestr, a);
  194             if (isvalid != NULL) {
  195                 /* Move past the cookie name and equal sign */
  196                 isvalid += strlen(a) + 1;
  197                 /* Duplicate it into the pool */
  198                 cookiebuf = apr_pstrdup(r->pool, isvalid);
  199                 /* Segregate just this cookie out of the string
  200                  * with a terminating nul at the first semicolon */
  201                 cookieend = ap_strchr(cookiebuf, ';');
  202                 if (cookieend != NULL)
  203                    *cookieend = '\0';
  204                 return cookiebuf;
  205             }
  206         }
  207 
  208         cookiestr  = (char *)apr_table_get(r->headers_in,  "cookie");
  209         if (cookiestr != NULL) {
  210             log_error(APLOG_MARK,APLOG_DEBUG, 0, r->server,
  211                 "Cookie: [%s]", cookiestr);
  212             isvalid = ap_strstr_c(cookiestr, a);
  213             if (isvalid != NULL) {
  214                 isvalid += strlen(a) + 1;
  215                 cookiebuf = apr_pstrdup(r->pool, isvalid);
  216                 cookieend = ap_strchr(cookiebuf, ';');
  217                 if (cookieend != NULL)
  218                    *cookieend = '\0';
  219                 return cookiebuf;
  220             }
  221         }
  222 
  223         cookiestr = apr_table_get(r->headers_out,  "set-cookie");
  224         if (cookiestr != NULL) {
  225              log_error(APLOG_MARK,APLOG_DEBUG, 0, r->server,
  226                 "Set-Cookie: [%s]", cookiestr);
  227             isvalid = ap_strstr_c(cookiestr, a);
  228             if (isvalid != NULL) {
  229                 isvalid += strlen(a) + 1;
  230                 cookiebuf = apr_pstrdup(r->pool, isvalid);
  231                 cookieend = ap_strchr(cookiebuf, ';');
  232                 if (cookieend != NULL)
  233                    *cookieend = '\0';
  234                 return cookiebuf;
  235             }
  236         }
  237     }
  238 
  239     return "-";
  240 }
  241 
  242 static const char *extract_cookie(request_rec *r, char *a)
  243 {
  244     logsql_state *cls = ap_get_module_config(r->server->module_config,
  245                                             &log_sql_module);
  246 
  247     return extract_specific_cookie(r, (char *)cls->cookie_name);
  248 }
  249 
  250 static const char *extract_unique_id(request_rec *r, char *a)
  251 {
  252     const char *tempid;
  253 
  254     tempid = apr_table_get(r->subprocess_env, "UNIQUE_ID");
  255     if (!tempid)
  256       return "-";
  257     else
  258       return tempid;
  259 }
  260 
  261 /* End declarations of various extract_ functions */