3 * Copyright 2004 The Apache Software Foundation
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * Module Name: mod_dtrace
19 * Purpose: Apache implements a set of hooks and filters to allow
20 * modules to view and modify requests sent to the server.
21 * This module takes advantage of this architecture to
22 * implement several DTrace hooks.
24 * Notes: To get the most use out of the mod_dtrace Apache module, it will
25 * be useful to familiarize yourself with the Apache request_rec,
26 * server_rec and conn_rec structures. These can be viewed on the
29 * http://docx.webperf.org/httpd_8h-source.html
31 * A basic overview of each structure is included below:
33 * request_rec : Contains all of the attributes (URI, filename,
34 * method, bytes_sent) needed to describe an
37 * conn_rec : Stores the connection attributes including
38 * IP addresses and ports
40 * server_rec : Stores information to describe each virtual server
42 * Last Modified: 02-08-2007
44 * Author: Matty < matty91 at gmail dot com >
50 * 0.3a: Fixed bug due to NULL values -- Sebastien Bouchex Bellomie
52 * 0.2a: Initial release
54 * Build instructions are available at the following site:
55 * http://prefetch.net/projects/apache_modtrace/build.txt
59 #include "ap_config.h"
61 #include "http_config.h"
62 #include "http_connection.h"
63 #include "http_protocol.h"
64 #include "http_request.h"
67 module AP_MODULE_DECLARE_DATA dtrace_module
;
70 * Probe Function Purpoose:
71 * This probe will fire each time a request is send to the server.
73 * arg0 -> address of the request_rec structure
75 int apache_receive_request(request_rec
*r
)
85 * This probe will fire each time the web server invokes the logging handlers.
86 * Since the request_rec, server_rec and conn_rec should be completely filled
87 * in when this probe fires -- this will be a useful probe.
89 * arg0 -> The address of the request_rec structure
91 int apache_log_request(request_rec
*r
)
93 /* apr_table_get will return the value of User-Agent or NULL */
94 const char *userAgent
= NULL
;
95 if (r
->headers_in
!= NULL
)
97 userAgent
= apr_table_get(r
->headers_in
, "User-Agent");
100 /* apr_table_get will return the value of Location or NULL */
101 const char *redirectLocation
= NULL
;
102 if (r
->headers_out
) {
103 redirectLocation
= apr_table_get(r
->headers_out
, "Location");
106 DTRACE_PROBE3(apache
,
116 * This probe will fire each time an httpd child process is created
118 void apache_create_child(apr_pool_t
*p
, server_rec
*s
)
125 * This probe will fire each time a new TCP connection is created
127 * arg0 -> Client's IP address
129 int apache_accept_connection(conn_rec
*c
, void *csd
)
131 DTRACE_PROBE1(apache
,
139 * This probe will fire when the authentication stage is encountered
141 * arg0 -> The address of the request_rec structure
144 int apache_check_user(request_rec
*r
)
146 DTRACE_PROBE1(apache
,
147 check__user__credentials
,
154 * This probe will fire when the access checking stage is encountered
156 * arg0 -> The address of the request_rec structure
159 int apache_check_access(request_rec
*r
)
161 DTRACE_PROBE1(apache
,
169 * This probe will fire when the authorization checking stage is encountered
171 * arg0 -> The address of the request_rec structure
174 int apache_check_authorization(request_rec
*r
)
176 DTRACE_PROBE1(apache
,
177 check__authorization
,
184 * Define the hooks and the functions registered to those hooks
186 void dtrace_register_hooks(apr_pool_t
*p
)
188 ap_hook_post_read_request(apache_receive_request
,NULL
,NULL
,APR_HOOK_MIDDLE
);
189 ap_hook_child_init(apache_create_child
,NULL
, NULL
, APR_HOOK_MIDDLE
);
190 ap_hook_pre_connection(apache_accept_connection
,NULL
, NULL
, APR_HOOK_MIDDLE
);
191 ap_hook_check_user_id(apache_check_user
,NULL
,NULL
,APR_HOOK_MIDDLE
);
192 ap_hook_access_checker(apache_check_access
,NULL
,NULL
,APR_HOOK_MIDDLE
);
193 ap_hook_auth_checker(apache_check_authorization
,NULL
,NULL
,APR_HOOK_MIDDLE
);
194 ap_hook_log_transaction(apache_log_request
,NULL
,NULL
,APR_HOOK_MIDDLE
);
197 module AP_MODULE_DECLARE_DATA dtrace_module
=
199 STANDARD20_MODULE_STUFF
,
205 dtrace_register_hooks