apache module 小例

来源:互联网 发布:lhgdialog.js 编辑:程序博客网 时间:2024/06/05 18:55
/** * 编译后 * 在 httpd.conf 文件中添加 *  *  * LoadModule access_ctl_module modules/libmod_access_ctl.so *  *  *  *  */#include <assert.h>#include "apr_getopt.h"#include <unistd.h>#include <stdlib.h>#include <stdio.h>#include <string.h>#include <errno.h>#include <sys/types.h>#include <sys/ipc.h>#include <sys/shm.h>#include <openssl/ssl.h>#include <openssl/x509.h>#include <openssl/ossl_typ.h>#include <openssl/asn1.h>#include "httpd.h"#include "http_config.h"#include "http_request.h"#include "http_protocol.h"#include "http_core.h"#include "mod_ssl.h"#include "util_md5.h"#include "scoreboard.h"#define FORB_ERROR_PAGE  "http://www.zggo.com/"/** * void ap_send_response() * request_rec *r:请求 * char *str_url: 错误页面URL *  */static void ap_send_response(request_rec *r, char *str_url){apr_table_setn(r->headers_out, "Http", "302");apr_table_setn(r->headers_out, "Location", str_url);        r->status = HTTP_TEMPORARY_REDIRECT;       ap_send_error_response(r, 0);ap_update_child_status(r->connection->sbh, SERVER_IDLE_KILL, r);ap_run_log_transaction(r);r->connection->aborted= 0;   }static void goto_error(request_rec *r){  if (r->main)r->main->connection->aborted=0;   ap_send_response(r, FORB_ERROR_PAGE); }static int mod_access_ctl_method_handler (request_rec *r){  goto_error(r);    //fflush(stderr);  return DECLINED;}/* * This function is a callback and it declares what other functions * should be called for request processing and configuration requests. * This callback function declares the Handlers for other events. */static void mod_access_ctl_register_hooks (apr_pool_t *p){// I think this is the call to make to register a handler for method calls (GET PUT et. al.).// We will ask to be last so that the comment has a higher tendency to// go at the end.ap_hook_handler(mod_access_ctl_method_handler, NULL, NULL, APR_HOOK_REALLY_FIRST);}/* * Declare and populate the module's data structure.  The * name of this structure ('tut1_module') is important - it * must match the name of the module.  This structure is the * only "glue" between the httpd core and the module. */module AP_MODULE_DECLARE_DATA access_ctl_module ={// Only one callback function is provided.  Real// modules will need to declare callback functions for// server/directory configuration, configuration merging// and other tasks.STANDARD20_MODULE_STUFF,NULL,NULL,NULL,NULL,NULL,mod_access_ctl_register_hooks,/* callback for registering hooks */};

 

保存为 mod_access_ctl.c 编译apxs -c -i -a mod_access_ctl.c

-c 编译 -i 复制文件到apache的modules目录 -a 添加LoadModule到httpd,conf

原创粉丝点击