Configuring and Managing MPE/iX Internet Services
> Chapter 9 Apache for MPE/iXSample Module Code (mod_hw) |
||||||||||||||||||||||||
|
mod_hw.cMod_hw.c is a simple Apache module. It calls pow() (in the math library, /lib/libm) and helloworld() in hw.c. This example is designed to illustrate the use of external function calls. shell/iX> cat mod_hw.c #include <stdlib.h> #include <math.h> #include "httpd.h" #include "http_config.h" #include "http_core.h" #include "http_log.h" #include "http_protocol.h" /* here's the content handler */ static int hw_handler(request_rec *r) { double root = 12; double power = 2; r->content_type = "text/html"; ap_send_http_header(r); helloworld(r); ap_rprintf(r, "\nresult of %.2lf**%.2lf is %.2lf", root, power, pow(root,power)); return OK; } /* Make the name of the content handler known to Apache */ static handler_rec hw_handlers[] = { {"hw-handler", hw_handler}, {NULL} }; /* Tell Apache what phases of the transaction we handle */ module MODULE_VAR_EXPORT hw_module = { STANDARD_MODULE_STUFF, NULL, /* module initializer */ NULL, /* per-directory config creator */ NULL, /* dir config merger */ NULL, /* server config creator */ NULL, /* server config merger */ NULL, /* command table */ hw_handlers, /* [7] content handlers */ NULL, /* [2] URI-to-filename translation */ NULL, /* [5] check/validate user_id */ NULL, /* [6] check user_id is valid *here* */ NULL, /* [4] check access by host address */ NULL, /* [7] MIME type checker/setter */ NULL, /* [8] fixups */ NULL, /* [9] logger */ NULL, /* [3] header parser */ NULL, /* process initialization */ NULL, /* process exit/cleanup */ NULL /* [1] post read_request handling */ }; hw.cThis file defines a function called helloworld(). shell/iX> cat hw.c #include "httpd.h" #include "http_config.h" #include "http_core.h" #include "http_log.h" #include "http_protocol.h" helloworld(request_rec *r) { ap_rputs("<HTML>\n", r); ap_rputs("<HEADER>\n", r); ap_rputs("<TITLE>Hello There</TITLE>\n", r); ap_rputs("</HEADER>\n", r); ap_rputs("<BODY>\n", r); ap_rprintf(r, "<H1>Hello World!</H1>\n"); ap_rputs("</BODY>\n", r); ap_rputs("</HTML>\n", r); } APXS Default Makefile (mod_hw)This is the Makefile auto-generated by apxs -g -n hw. ## ## Makefile -- Build procedure for sample hw Apache module ## Autogenerated via ``apxs -n hw -g''. ## # the used tools APXS=apxs APACHECTL=apachectl # additional defines, includes and libraries #DEF=-Dmy_define=my_value #INC=-Imy/include/dir #LIB=-Lmy/lib/dir -lmylib # the default target all: mod_hw.so # compile the shared object file mod_hw.so: mod_hw.c $(APXS) -c $(DEF) $(INC) $(LIB) mod_hw.c # install the shared object file into Apache install: all $(APXS) -i -a -n 'hw' mod_hw.so # cleanup clean: -rm -f mod_hw.o mod_hw.so # simple test test: reload lynx -mime_header http://localhost/hw # install and activate shared object by reloading Apache to # force a reload of the shared object file reload: install restart # the general Apache start/restart/stop # procedures start: $(APACHECTL) start restart: $(APACHECTL) restart stop: $(APACHECTL) stop Modified APXS Makefile (mod_hw)This Makefile is a modified version of the apxs auto-generated Makefile. It shows how to call gcc for compiling and LinkEditor for linking. The APXS variable was also changed to contain a fully qualified path to apxs. Apxs is used for getting the correct defines and includes. It is also used for installing the new module in the libexec/ directory. Make sure to use tabs (instead of spaces) when adding callci and gcc to the MakeFile. shell/iX> cat Makefile ## ## Makefile -- Build procedure for sample hw Apache module ## Autogenerated via ``apxs -n hw -g''. ## ## 3/01 Modified Makefile to replace apxs by gcc and linkedit for ## compile and link the used tools APXS=/APACHE/PUB/bin/apxs APACHECTL=/APACHE/PUB/bin/apachectl # defines, includes and libraries DEF=`$(APXS) -q CFLAGS` INC=-I`$(APXS) -q INCLUDEDIR` LIB=/lib/libm.a,/lib/libc.a # the default target all: mod_hw.so # link the shared object file mod_hw.so: mod_hw.o hw.o callci "linkedit 'buildxl xl=./mod_hw.so;limit=5'" callci "linkedit 'addxl from=./mod_hw.o,./hw.o \ ;to=./mod_hw.so ;rl=$(LIB);merge;share'" # compile the object files mod_hw.o: mod_hw.c gcc -o mod_hw.o $(DEF) $(INC) -c mod_hw.c hw.o: hw.c gcc -o hw.o $(DEF) $(INC) -c hw.c # install the shared object file into Apache install: all $(APXS) -i -a -n 'hw' mod_hw.so # cleanup Extended Apache Programming Interface (EAPI)Apache 1.3.9 and later are built with an extended set of Apache APIs. This means that Apache 1.3.9 and later expects these EAPIs to be built into any DSO they call. This EAPI feature is included in Apache so that a DSO can be used by either Apache or WebWise, since WebWise requires EAPI for its SSL functionality. When creating DSOs, you must compile with the -DEAPI option. This will include the necessary EAPI header files. These header files are distributed with Apache 1.3.9 and later and reside in the /APACHE/PUB/include directory. This include directory also contains the README.EAPI file. The README.EAPI file describes additional functionality that is available with EAPI such as more features in the mod_rewrite, mod_status, and mod_proxy modules. DSOs created with apxs will automatically include the -DEAPI option. DSOs created without -DEAPI may operate successfully but may generate a warning message in the error_log file. TroubleshootingFor any kind of trouble with Apache, first look in the error log. Execute a tail command on the error_log to look at the last few entries. The last entry will be the most recent entry: shell/iX> tail /APACHE/PUB/logs/error_log For troubleshooting Apache at the source code level, the Apache program file can be run with the MPE/iX debugger. It is best to run it with the -X (capital "X") option to prevent the parent Apache process from creating child processes: :run httpd.pub.apache;info="-X";debug Unsupported FunctionalityHP does not support Apache binaries or DSOs built by individuals or organizations outside of HP. HP supports the htpasswd and apxs utilities in the /APACHE/PUB/bin directory but not the other scripts and programs in the bin directory. PerformanceFor best performance, files returned to the user should be in bytestream format. For example; .html, .htm, .shtml, .shtm, .txt, .gif, .jpeg, and .jpg files should be in bytestream format instead of in the MPE/iX type format. Bytestream files are more compatible with Apache and with other POSIX applications than are MPE/iX type files. If a web page calls many images which are not in bytestream format (BA), the page will appear to load all the way with all the content visible, yet the browser will appear hung and the activity icon will keep moving. If any files under the document root (htdocs), or in other locations that are storing and accessing web server content, are MPE/iX fixed ASCII (FA), MPE/iX variable ASCII (VA), or MPE/iX variable binary (VB) files, consider converting them to bytestream files using the "tobyte" utility. Program files (fixed binary (FB) files with an NMPROG filecode) should never be converted. A file's filetype can be determined using either the POSIX file command or the CI listfile command: shell/iX> file index.html index.html: commands text shell/iX> callci listfile ./index.html,2 PATH= /APACHE/PUB/htdocs/ CODE ------------LOGICAL RECORD-------- ----SPACE---- FILENAME SIZE TYP EOF LIMIT R/B SECTORS #X MX 1B BA 1622 2147483647 1 16 1 * index.htmlThe index.html file in the previous example is a bytetream file. The following files are MPE/iX type files: shell/iX> file index*.html index.html: MPE/iX 256-byte variable length binary (filecode: 0) index1.html: MPE/iX 80-byte fixed length ascii (filecode:0) shell/iX>callci listfile ./index.html,2 PATH= /APACHE/PUB/htdocs/ CODE ------------LOGICAL RECORD------- ----SPACE---- FILENAME SIZE TYP EOF LIMIT R/B SECTORS #X MX 128W VB 19 204800 1 32 1 8 index.html 80B FA 54 204800 1 32 1 8 index1.htmlTo convert an ASCII-type file (.htm*, .shtm*, or .txt), use the tobyte utility with the -at option. If it is a binary-type file (such as .jpeg, .jpg, or .gif), do not use the -at option: shell/iX>tobyte -at /APACHE/PUB/htdocs/index.html /APACHE/PUB/htdocs/newindex.htmlFor more information on the "tobyte" utility, consult the POSIX help facility (i.e., man tobyte). If the Apache web server seems slow in responding, you might try running the Apache job stream file, JHTTPD, in the C queue instead of in the default D queue. The changes shown below allow Apache to run in the C queue while keeping the default execution level for jobs in the D queue. The jobpri command can be executed on the console or in a systart file. !job JHTTPD,www.apache;pri=cs;outclass=,2 !jobpri cs Additional DocumentationMuch of the public information available on Apache can be used for administrating Apache on MPE/iX, especially the description and usage of the Apache configuration directives. Sources for additional information include:
|