MCPcopy Create free account
hub / github.com/apache/httpd / example_handler

Function example_handler

docs/manual/developer/mod_example_2.c:15–122  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

13#include "apr_tables.h"
14
15static int example_handler(request_rec *r)
16{
17 int rc, exists;
18 apr_finfo_t finfo;
19 apr_file_t *file;
20 char *filename;
21 char buffer[256];
22 apr_size_t readBytes;
23 int n;
24 apr_table_t *GET;
25 apr_array_header_t *POST;
26 const char *digestType;
27
28
29 /* Check that the "example-handler" handler is being called. */
30 if (!r->handler || strcmp(r->handler, "example-handler")) return (DECLINED);
31
32 /* Figure out which file is being requested by removing the .sum from it */
33 filename = apr_pstrdup(r->pool, r->filename);
34 filename[strlen(filename)-4] = 0; /* Cut off the last 4 characters. */
35
36 /* Figure out if the file we request a sum on exists and isn't a directory */
37 rc = apr_stat(&finfo, filename, APR_FINFO_MIN, r->pool);
38 if (rc == APR_SUCCESS) {
39 exists =
40 (
41 (finfo.filetype != APR_NOFILE)
42 && !(finfo.filetype & APR_DIR)
43 );
44 if (!exists) return HTTP_NOT_FOUND; /* Return a 404 if not found. */
45 }
46 /* If apr_stat failed, we're probably not allowed to check this file. */
47 else return HTTP_FORBIDDEN;
48
49 /* Parse the GET and, optionally, the POST data sent to us */
50
51 ap_args_to_table(r, &GET);
52 ap_parse_form_data(r, NULL, &POST, -1, 8192);
53
54 /* Set the appropriate content type */
55 ap_set_content_type(r, "text/html");
56
57 /* Print a title and some general information */
58 ap_rprintf(r, "<h2>Information on %s:</h2>", filename);
59 ap_rprintf(r, "<b>Size:</b> %" APR_OFF_T_FMT " bytes<br/>", finfo.size);
60
61 /* Get the digest type the client wants to see */
62 digestType = apr_table_get(GET, "digest");
63 if (!digestType) digestType = "MD5";
64
65
66 rc = apr_file_open(&file, filename, APR_READ, APR_OS_DEFAULT, r->pool);
67 if (rc == APR_SUCCESS) {
68
69 /* Are we trying to calculate the MD5 or the SHA1 digest? */
70 if (!strcasecmp(digestType, "md5")) {
71 /* Calculate the MD5 sum of the file */
72 union {

Callers

nothing calls this directly

Calls 5

ap_args_to_tableFunction · 0.85
ap_parse_form_dataFunction · 0.85
ap_set_content_typeFunction · 0.85
ap_rprintfFunction · 0.85
ap_rputsFunction · 0.85

Tested by

no test coverage detected