« qmailのSMTPを認証型にする | メイン | URLエンコード »

2007年05月15日

アパッチモジュールつくり

あぱっちのモジュールを作ってみよう!

1、テンプレートの出力
  #/usr/local/apache/bin/apxs -g -n hoge
Creating [DIR] hoge
Creating [FILE] hoge/Makefile
Creating [FILE] hoge/mod_hoge.c
2つのファイルが出来ます。

2、コンパイル
   コンパイルは 
    apxs -c mod_hoge.c
   にてOK

   コンパイルと同時に modules ディレクトリにコピー
     apxs -c -i mod_hoge.c

   自動的にhttpd.conf に組み込む場合は
   apxs -c -i -a mod_hoge.c

※ちなみに今回のテンプレートの中身は
-------------------------------------------------------------------
/* The sample content handler */
static int hoge_handler(request_rec *r)
{
r->content_type = "text/html";
ap_send_http_header(r);
if (!r->header_only)
ap_rputs("The sample page from mod_hoge.c\n", r);
return OK;
}

/* Dispatch list of content handlers */
static const handler_rec hoge_handlers[] = {
{ "hoge", hoge_handler },
{ NULL, NULL }
};
-----------------------------------------------------------------------------

となっており
.htaccess などで

   SetHandler hoge

などとして ハンドラ?に hogeをセットしてあげると
The sample page from mod_hoge.c がHTML表示されます。


static int uri_handler(request_rec *r)
{
r->content_type = "text/html";
ap_send_http_header(r);
if (r->header_only)
return OK;

ap_rputs("oo
",r);
ap_rprintf(r,"url: %s",r->uri);
return OK;

}

投稿者 muuming : 2007年05月15日 15:26

コメント

コメントしてください




保存しますか?