Guest User

Simple apache module

a guest
Jun 6th, 2011
284
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.24 KB | None | 0 0
  1. #include <httpd.h>
  2. #include <http_protocol.h>
  3. #include <http_config.h>
  4. #include <util_filter.h>
  5.  
  6. static int getadsldap_handler(request_rec* r) {
  7.     if (!r->handler || strcmp(r->handler, "getadsldap"))
  8.         return DECLINED;
  9.                      
  10.     if (r->method_number != M_GET)
  11.         return HTTP_METHOD_NOT_ALLOWED;
  12.                                        
  13.     apr_table_add(r->subprocess_env, "USER_VAR2", "mytest");
  14.     apr_table_add(r->headers_out, "USER_VAR2", "mytest");
  15.     ap_add_output_filter("add-headers", NULL, r, r->connection);
  16.  
  17.     return OK;
  18. }
  19.  
  20. static apr_status_t getadsldap_filter_out(ap_filter_t *f, apr_bucket_brigade *in) {
  21.     apr_table_addn(f->r->subprocess_env, "USER_VAR2", "mytest");
  22.     apr_table_addn(f->r->headers_in, "REMOTE_VAR2", "mytest");
  23.  
  24.     ap_remove_output_filter(f);
  25.  
  26.     return ap_pass_brigade(f->next,in);
  27. }
  28.  
  29. static void register_hooks(apr_pool_t* pool) {
  30.     ap_hook_handler(getadsldap_handler, NULL, NULL, APR_HOOK_MIDDLE);
  31.     ap_register_output_filter("add-headers", getadsldap_filter_out, NULL, AP_FTYPE_RESOURCE );
  32. }
  33.    
  34. module AP_MODULE_DECLARE_DATA getadsldap_module = {
  35.     STANDARD20_MODULE_STUFF,
  36.     NULL,
  37.     NULL,
  38.     NULL,
  39.     NULL,
  40.     NULL,
  41.     register_hooks
  42. };
Advertisement
Add Comment
Please, Sign In to add comment