Guest User

Apache module

a guest
Jul 10th, 2015
289
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.62 KB | None | 0 0
  1. /* Include the required headers from httpd */
  2. #include "httpd.h"
  3. #include "http_core.h"
  4. #include "http_protocol.h"
  5. #include "http_request.h"
  6.  
  7. /* Define prototypes of our functions in this module */
  8. static void register_hooks(apr_pool_t *pool);
  9. static int example_handler(request_rec *r);
  10.  
  11. /* Define our module as an entity and assign a function for registering hooks  */
  12.  
  13. module AP_MODULE_DECLARE_DATA   example_module =
  14. {
  15.     STANDARD20_MODULE_STUFF,
  16.     NULL,            // Per-directory configuration handler
  17.     NULL,            // Merge handler for per-directory configurations
  18.     NULL,            // Per-server configuration handler
  19.     NULL,            // Merge handler for per-server configurations
  20.     NULL,            // Any directives we may have for httpd
  21.     register_hooks   // Our hook registering function
  22. };
  23.  
  24.  
  25. /* register_hooks: Adds a hook to the httpd process */
  26. static void register_hooks(apr_pool_t *pool)
  27. {
  28.    
  29.     /* Hook the request handler */
  30.     ap_hook_handler(example_handler, NULL, NULL, APR_HOOK_LAST);
  31. }
  32.  
  33. /* The handler function for our module.
  34.  * This is where all the fun happens!
  35.  */
  36.  
  37. static int example_handler(request_rec *r)
  38. {
  39.     /* First off, we need to check if this is a call for the "example" handler.
  40.      * If it is, we accept it and do our things, it not, we simply return DECLINED,
  41.      * and Apache will try somewhere else.
  42.      */
  43.     if (!r->handler || strcmp(r->handler, "example-handler")) return (DECLINED);
  44.    
  45.     // The first thing we will do is write a simple "Hello, world!" back to the client.
  46.     ap_rputs("Hello, world!<br/>", r);
  47.     return OK;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment