LoginSignup
1
0

More than 5 years have passed since last update.

C/C++ Apache Moduleのひな形ジェネレートの罠

Last updated at Posted at 2018-04-21

Apache ModuleをC/C++で作ろうとして、罠にはまったので情報を残しておきます。

下記のコマンドでひな形をジェネレートすると思うのですが。
/usr/sbin/apxs -g -n hello_world

私は大文字・小文字を混ぜてジェネレートしました。
/usr/sbin/apxs -g -n HelloWorld

そうすると一字一句変わらぬhandlerが生成されます。

/* The sample content handler */
static int HelloWorld_handler(request_rec *r)
{
    if (strcmp(r->handler, "HelloWorld")) {
        return DECLINED;
    }
    r->content_type = "text/html";      

    if (!r->header_only)
        ap_rputs("The sample page from mod_HelloWorld.c\n", r);
    return OK;
}

ビルド方法は他のサイトに紹介があるので割愛させていただきますが
調子よく「httpd.conf」にハンドラの呼び出しを書きます。

<Location /HelloWorld >
Order allow,deny
Allow from all
SetHandler HelloWorld
</Location>

あとは実行するだけなのですが、これが動かない。
原因として分かったのが、ここではねられる。

    if (strcmp(r->handler, "HelloWorld")) {
        return DECLINED;
    }

「r->handler」に来る文字列がなんと、すべて小文字でした。

    if (strcmp(r->handler, "helloworld")) {
        return DECLINED;
    }

これで動いた・・・
ジェネレートの時点で変換するか弾いて欲しいなって思いました。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0