apache module 小例

/**

 * 编译后

 * 在 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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值