apxsによるスケルトン生成
先日の件は、shimookaさんとkenji-uさんによる痛恨の一撃。。。もとい、素敵な連絡によりmod_datetimelimitとmod_maintenanceは一瞬にして闇に葬りさられた訳ですが。(w
こやつらはApacheモジュール作成の練習を兼ねていたのと、誰かが連絡して下さる事を期待していたので(ある意味、想定通りになってくれて)一安心でした。
っていうか、誰からも返信が来なかったら寂しかったっすよ。。。連絡くれてありがとうございます。感謝です。<(_ _)>
一応mod_rewriteとの性能比較をしてみたのですが、性能差に優劣は無かったようです。どちらも素敵という事で。
さて、懲りずに本丸用Apacheモジュールの作成に向けて勉強中です。正確には他の人が作った1.3系統用Apacheモジュールの移植なのですが(改めて調べてみたところ、こやつはmod_rewriteで代替は不可能でした。代替可能であったのは自分が作った練習用Apacheモジュールでした)。
説明するまでもありませんが(むしろ自分が忘れないよう書いているダケ)、apxsを使って1.3系統から2.2系統まで同じ手順でスケルトンを作成する事が出来るようです。
1.3系統と2.0系統のスケルトン内容を比べると結構変わっていますが、2.0系統と2.2系統では大きな差は無いよううです。なる程。
っていうか、かなり詳細にコメントが書いてありますね。相変わらず手際が悪い。。。_| ̄|○
付属しているmod_exampleも参考になりそう。ふむふむ。
「apache モジュール 作成」で検索結果に該当したページは参考になりそうだけど、情報はそれなりに整理しないと駄目そう。頑張るか。
% /usr/local/apache/bin/apxs -g -n masugata13 Creating [DIR] masugata13 Creating [FILE] masugata13/Makefile Creating [FILE] masugata13/mod_masugata13.c % ls -la masugata13/ total 16 drwxr-xr-x 2 masugata php 4096 Oct 22 15:00 . drwxrwxrwx 9 root staff 4096 Oct 22 15:02 .. -rw-r--r-- 1 masugata php 985 Oct 22 15:00 Makefile -rw-r--r-- 1 masugata php 2954 Oct 22 15:00 mod_masugata13.c % less -N masugata13/Makefile 1 ## 2 ## Makefile -- Build procedure for sample masugata13 Apache module 3 ## Autogenerated via ``apxs -n masugata13 -g''. 4 ## 5 6 # the used tools 7 APXS=apxs 8 APACHECTL=apachectl 9 10 # additional user defines, includes and libraries 11 #DEF=-Dmy_define=my_value 12 #INC=-Imy/include/dir 13 #LIB=-Lmy/lib/dir -lmylib 14 15 # the default target 16 all: mod_masugata13.so 17 18 # compile the DSO file 19 mod_masugata13.so: mod_masugata13.c 20 $(APXS) -c $(DEF) $(INC) $(LIB) mod_masugata13.c 21 22 # install the DSO file into the Apache installation 23 # and activate it in the Apache configuration 24 install: all 25 $(APXS) -i -a -n 'masugata13' mod_masugata13.so 26 27 # cleanup 28 clean: 29 -rm -f mod_masugata13.o mod_masugata13.so 30 31 # simple test 32 test: reload 33 lynx -mime_header http://localhost/masugata13 34 35 # reload the module by installing and restarting Apache 36 reload: install restart 37 38 # the general Apache start/restart/stop procedures 39 start: 40 $(APACHECTL) start 41 restart: 42 $(APACHECTL) restart 43 stop: 44 $(APACHECTL) stop 45 % less -N masugata13/mod_masugata13.c 1 /* 2 ** mod_masugata13.c -- Apache sample masugata13 module 3 ** [Autogenerated via ``apxs -n masugata13 -g''] 4 ** 5 ** To play with this sample module, first compile it into a 6 ** DSO file and install it into Apache's libexec directory 7 ** by running: 8 ** 9 ** $ apxs -c -i mod_masugata13.c 10 ** 11 ** Then activate it in Apache's httpd.conf file, for instance 12 ** for the URL /masugata13, as follows: 13 ** 14 ** # httpd.conf 15 ** LoadModule masugata13_module libexec/mod_masugata13.so 16 ** <Location /masugata13> 17 ** SetHandler masugata13 18 ** </Location> 19 ** 20 ** Then after restarting Apache via 21 ** 22 ** $ apachectl restart 23 ** 24 ** you immediately can request the URL /%NAME and watch for the 25 ** output of this module. This can be achieved for instance via: 26 ** 27 ** $ lynx -mime_header http://localhost/masugata13 28 ** 29 ** The output should be similar to the following one: 30 ** 31 ** HTTP/1.1 200 OK 32 ** Date: Tue, 31 Mar 1998 14:42:22 GMT 33 ** Server: Apache/1.3.4 (Unix) 34 ** Connection: close 35 ** Content-Type: text/html 36 ** 37 ** The sample page from mod_masugata13.c 38 */ 39 40 #include "httpd.h" 41 #include "http_config.h" 42 #include "http_protocol.h" 43 #include "ap_config.h" 44 45 /* The sample content handler */ 46 static int masugata13_handler(request_rec *r) 47 { 48 r->content_type = "text/html"; 49 ap_send_http_header(r); 50 if (!r->header_only) 51 ap_rputs("The sample page from mod_masugata13.c\n", r); 52 return OK; 53 } 54 55 /* Dispatch list of content handlers */ 56 static const handler_rec masugata13_handlers[] = { 57 { "masugata13", masugata13_handler }, 58 { NULL, NULL } 59 }; 60 61 /* Dispatch list for API hooks */ 62 module MODULE_VAR_EXPORT masugata13_module = { 63 STANDARD_MODULE_STUFF, 64 NULL, /* module initializer */ 65 NULL, /* create per-dir config structures */ 66 NULL, /* merge per-dir config structures */ 67 NULL, /* create per-server config structures */ 68 NULL, /* merge per-server config structures */ 69 NULL, /* table of config file commands */ 70 masugata13_handlers, /* [#8] MIME-typed-dispatched handlers */ 71 NULL, /* [#1] URI to filename translation */ 72 NULL, /* [#4] validate user id from request */ 73 NULL, /* [#5] check if the user is ok _here_ */ 74 NULL, /* [#3] check access by host address */ 75 NULL, /* [#6] determine MIME type */ 76 NULL, /* [#7] pre-run fixups */ 77 NULL, /* [#9] log a transaction */ 78 NULL, /* [#2] header parser */ 79 NULL, /* child_init */ 80 NULL, /* child_exit */ 81 NULL /* [#0] post read-request */ 82 }; 83 % /usr/local/apache2.0/bin/apxs -g -n masugata20 Creating [DIR] masugata20 Creating [FILE] masugata20/Makefile Creating [FILE] masugata20/modules.mk Creating [FILE] masugata20/mod_masugata20.c Creating [FILE] masugata20/.deps % ls -la masugata20/ total 20 drwxr-xr-x 2 masugata php 4096 Oct 22 15:02 . drwxrwxrwx 9 root staff 4096 Oct 22 15:02 .. -rw-r--r-- 1 masugata php 0 Oct 22 15:02 .deps -rw-r--r-- 1 masugata php 1015 Oct 22 15:02 Makefile -rw-r--r-- 1 masugata php 2156 Oct 22 15:02 mod_masugata20.c -rw-r--r-- 1 masugata php 172 Oct 22 15:02 modules.mk % less -N masugata20/Makefile 1 ## 2 ## Makefile -- Build procedure for sample masugata20 Apache module 3 ## Autogenerated via ``apxs -n masugata20 -g''. 4 ## 5 6 builddir=. 7 top_srcdir=/usr/local/apache2.0 8 top_builddir=/usr/local/apache2.0 9 include /usr/local/apache2.0/build/special.mk 10 11 # the used tools 12 APXS=apxs 13 APACHECTL=apachectl 14 15 # additional defines, includes and libraries 16 #DEFS=-Dmy_define=my_value 17 #INCLUDES=-Imy/include/dir 18 #LIBS=-Lmy/lib/dir -lmylib 19 20 # the default target 21 all: local-shared-build 22 23 # install the shared object file into Apache 24 install: install-modules 25 26 # cleanup 27 clean: 28 -rm -f mod_masugata20.o mod_masugata20.lo mod_masugata20.slo mod_masugata20.la 29 30 # simple test 31 test: reload 32 lynx -mime_header http://localhost/masugata20 33 34 # install and activate shared object by reloading Apache to 35 # force a reload of the shared object file 36 reload: install restart 37 38 # the general Apache start/restart/stop 39 # procedures 40 start: 41 $(APACHECTL) start 42 restart: 43 $(APACHECTL) restart 44 stop: 45 $(APACHECTL) stop 46 % less -N masugata20/modules.mk 1 mod_masugata20.la: mod_masugata20.slo 2 $(SH_LINK) -rpath $(libexecdir) -module -avoid-version mod_masugata20.lo 3 DISTCLEAN_TARGETS = modules.mk 4 shared = mod_masugata20.la % less -N masugata20/mod_masugata20.c 1 /* 2 ** mod_masugata20.c -- Apache sample masugata20 module 3 ** [Autogenerated via ``apxs -n masugata20 -g''] 4 ** 5 ** To play with this sample module first compile it into a 6 ** DSO file and install it into Apache's modules directory 7 ** by running: 8 ** 9 ** $ apxs -c -i mod_masugata20.c 10 ** 11 ** Then activate it in Apache's httpd.conf file for instance 12 ** for the URL /masugata20 in as follows: 13 ** 14 ** # httpd.conf 15 ** LoadModule masugata20_module modules/mod_masugata20.so 16 ** <Location /masugata20> 17 ** SetHandler masugata20 18 ** </Location> 19 ** 20 ** Then after restarting Apache via 21 ** 22 ** $ apachectl restart 23 ** 24 ** you immediately can request the URL /masugata20 and watch for the 25 ** output of this module. This can be achieved for instance via: 26 ** 27 ** $ lynx -mime_header http://localhost/masugata20 28 ** 29 ** The output should be similar to the following one: 30 ** 31 ** HTTP/1.1 200 OK 32 ** Date: Tue, 31 Mar 1998 14:42:22 GMT 33 ** Server: Apache/1.3.4 (Unix) 34 ** Connection: close 35 ** Content-Type: text/html 36 ** 37 ** The sample page from mod_masugata20.c 38 */ 39 40 #include "httpd.h" 41 #include "http_config.h" 42 #include "http_protocol.h" 43 #include "ap_config.h" 44 45 /* The sample content handler */ 46 static int masugata20_handler(request_rec *r) 47 { 48 if (strcmp(r->handler, "masugata20")) { 49 return DECLINED; 50 } 51 r->content_type = "text/html"; 52 53 if (!r->header_only) 54 ap_rputs("The sample page from mod_masugata20.c\n", r); 55 return OK; 56 } 57 58 static void masugata20_register_hooks(apr_pool_t *p) 59 { 60 ap_hook_handler(masugata20_handler, NULL, NULL, APR_HOOK_MIDDLE); 61 } 62 63 /* Dispatch list for API hooks */ 64 module AP_MODULE_DECLARE_DATA masugata20_module = { 65 STANDARD20_MODULE_STUFF, 66 NULL, /* create per-dir config structures */ 67 NULL, /* merge per-dir config structures */ 68 NULL, /* create per-server config structures */ 69 NULL, /* merge per-server config structures */ 70 NULL, /* table of config file commands */ 71 masugata20_register_hooks /* register hooks */ 72 }; 73 % /usr/local/apache2.2/bin/apxs -g -n masugata22 Creating [DIR] masugata22 Creating [FILE] masugata22/Makefile Creating [FILE] masugata22/modules.mk Creating [FILE] masugata22/mod_masugata22.c Creating [FILE] masugata22/.deps % ls -la masugata22/ total 20 drwxr-xr-x 2 masugata php 4096 Oct 22 15:06 . drwxrwxrwx 10 root staff 4096 Oct 22 15:06 .. -rw-r--r-- 1 masugata php 0 Oct 22 15:06 .deps -rw-r--r-- 1 masugata php 1016 Oct 22 15:06 Makefile -rw-r--r-- 1 masugata php 2156 Oct 22 15:06 mod_masugata22.c -rw-r--r-- 1 masugata php 172 Oct 22 15:06 modules.mk % less -N masugata22/Makefile 1 ## 2 ## Makefile -- Build procedure for sample masugata22 Apache module 3 ## Autogenerated via ``apxs -n masugata22 -g''. 4 ## 5 6 builddir=. 7 top_srcdir=/usr/local/apache2.2 8 top_builddir=/usr/local/apache2.2 9 include /usr/local/apache2.2/build/special.mk 10 11 # the used tools 12 APXS=apxs 13 APACHECTL=apachectl 14 15 # additional defines, includes and libraries 16 #DEFS=-Dmy_define=my_value 17 #INCLUDES=-Imy/include/dir 18 #LIBS=-Lmy/lib/dir -lmylib 19 20 # the default target 21 all: local-shared-build 22 23 # install the shared object file into Apache 24 install: install-modules-yes 25 26 # cleanup 27 clean: 28 -rm -f mod_masugata22.o mod_masugata22.lo mod_masugata22.slo mod_masugata22.la 29 30 # simple test 31 test: reload 32 lynx -mime_header http://localhost/masugata22 33 34 # install and activate shared object by reloading Apache to 35 # force a reload of the shared object file 36 reload: install restart 37 38 # the general Apache start/restart/stop 39 # procedures 40 start: 41 $(APACHECTL) start 42 restart: 43 $(APACHECTL) restart 44 stop: 45 $(APACHECTL) stop 46 % less -N masugata22/modules.mk 1 mod_masugata22.la: mod_masugata22.slo 2 $(SH_LINK) -rpath $(libexecdir) -module -avoid-version mod_masugata22.lo 3 DISTCLEAN_TARGETS = modules.mk 4 shared = mod_masugata22.la % less -N masugata22/mod_masugata22.c 1 /* 2 ** mod_masugata22.c -- Apache sample masugata22 module 3 ** [Autogenerated via ``apxs -n masugata22 -g''] 4 ** 5 ** To play with this sample module first compile it into a 6 ** DSO file and install it into Apache's modules directory 7 ** by running: 8 ** 9 ** $ apxs -c -i mod_masugata22.c 10 ** 11 ** Then activate it in Apache's httpd.conf file for instance 12 ** for the URL /masugata22 in as follows: 13 ** 14 ** # httpd.conf 15 ** LoadModule masugata22_module modules/mod_masugata22.so 16 ** <Location /masugata22> 17 ** SetHandler masugata22 18 ** </Location> 19 ** 20 ** Then after restarting Apache via 21 ** 22 ** $ apachectl restart 23 ** 24 ** you immediately can request the URL /masugata22 and watch for the 25 ** output of this module. This can be achieved for instance via: 26 ** 27 ** $ lynx -mime_header http://localhost/masugata22 28 ** 29 ** The output should be similar to the following one: 30 ** 31 ** HTTP/1.1 200 OK 32 ** Date: Tue, 31 Mar 1998 14:42:22 GMT 33 ** Server: Apache/1.3.4 (Unix) 34 ** Connection: close 35 ** Content-Type: text/html 36 ** 37 ** The sample page from mod_masugata22.c 38 */ 39 40 #include "httpd.h" 41 #include "http_config.h" 42 #include "http_protocol.h" 43 #include "ap_config.h" 44 45 /* The sample content handler */ 46 static int masugata22_handler(request_rec *r) 47 { 48 if (strcmp(r->handler, "masugata22")) { 49 return DECLINED; 50 } 51 r->content_type = "text/html"; 52 53 if (!r->header_only) 54 ap_rputs("The sample page from mod_masugata22.c\n", r); 55 return OK; 56 } 57 58 static void masugata22_register_hooks(apr_pool_t *p) 59 { 60 ap_hook_handler(masugata22_handler, NULL, NULL, APR_HOOK_MIDDLE); 61 } 62 63 /* Dispatch list for API hooks */ 64 module AP_MODULE_DECLARE_DATA masugata22_module = { 65 STANDARD20_MODULE_STUFF, 66 NULL, /* create per-dir config structures */ 67 NULL, /* merge per-dir config structures */ 68 NULL, /* create per-server config structures */ 69 NULL, /* merge per-server config structures */ 70 NULL, /* table of config file commands */ 71 masugata22_register_hooks /* register hooks */ 72 }; 73