httpd-modules-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Souramita Sen" <souramita_...@mindtree.com>
Subject New to module development
Date Tue, 13 Mar 2007 04:27:50 GMT


Hi,

Greetings to All..I am a new member of this list and would like to know the
following :-

1. Suppose i make a demo module named "mod_demo" that would print "Hello
World" once Apache web server is started. I have surfed through different web
sites and jotted down the following steps:
 
   a) Write the corresponding C file mod_demo.c that prints "Hello World"
   b) Compile the module by invoking
           gcc -fPIC -DSHARED_MODULE -I/usr/include/httpd
-I/usr/include/apr-0  -c mod_demo.c

   c) Make a shared object from the object file
           ld -Bshareable -o mod_demo.so mod_demo.o

   d) Copy the file to the apache modules directory:
           cp mod_demo.so /usr/lib/httpd/modules/
           chmod 0755 /usr/lib/httpd/modules/mod_demo.so

   e) Add the line to httpd.conf file for Apache to load the module
           LoadModule myvar_module /usr/lib/httpd/modules/mod_demo.so

   f) Add the following in the httpd.conf file
           <IfModule mod_demo.c>
               DemoEnable On
           </IfModule>

    This will enable the new module.

Now my doubts are:
    a) To enable the module should not I stop the apache server(service httpd
stop) and compile the apache directory again? If yes How do i compile the
apache directory again?
    b) I did not understand the format of how to write the mod_demo.c. It is
not simple C file. Here is what i found in net as contents of some
mod_myvar.c. In the Fedora core Linux distribution the following header files
are not present by default.



-----------------------------------------------------------------------------
---------------

#include "httpd.h"
#include "http_config.h"
#include "http_protocol.h"
#include "http_log.h"
#include "ap_config.h"

module AP_MODULE_DECLARE_DATA myvar_module;

static apr_status_t myvar_cleanup(void *cfgdata) {
   // cleanup code here, if needed
   return APR_SUCCESS;
}

static void myvar_child_init(apr_pool_t *p, server_rec *s) {
   apr_pool_cleanup_register(p, NULL, myvar_cleanup, myvar_cleanup);
}

static int myvar_post_read_request(request_rec *r) {
   char myvar[16] = "CAPTAIN WAS HERE";
   apr_table_set(r->notes, "myvar", myvar); // PHP: apache_notes
   apr_table_set( r->subprocess_env, "myvar", myvar ); // PHP:
HTTP_SERVER_VARS
   return OK;
}

static const char *set_myvar_enable(cmd_parms *cmd, void *dummy, int arg) {
   ap_get_module_config(cmd->server->module_config, &myvar_module);
   return NULL;
}

static const command_rec myvar_cmds[] = {
   AP_INIT_FLAG( "MyVarEnable", set_myvar_enable, NULL, OR_FILEINFO, "Turn on
mod_myvar"),
   {NULL}
};

static void myvar_register_hooks(apr_pool_t *p) {
   ap_hook_post_read_request( myvar_post_read_request, NULL, NULL,
APR_HOOK_MIDDLE );
   ap_hook_child_init(        myvar_child_init,        NULL, NULL,
APR_HOOK_MIDDLE );
}

// API hooks
module AP_MODULE_DECLARE_DATA myvar_module = {
   STANDARD20_MODULE_STUFF, 
   NULL,                        /* create per-dir    config structures */
   NULL,                        /* merge  per-dir    config structures */
   NULL,                        /* create per-server config structures */
   NULL,                        /* merge  per-server config structures */
   myvar_cmds,                  /* table of config file commands       */
   myvar_register_hooks         /* register hooks                      */
};

-----------------------------------------------------------------------------
------------------------ 

Thanks,
Souramita

 


DISCLAIMER:
This message (including attachment if any) is confidential and may be privileged. Before opening
attachments please check them for viruses and defects. MindTree Consulting Limited (MindTree)
will not be responsible for any viruses or defects or any forwarded attachments emanating
either from within MindTree or outside. If you have received this message by mistake please
notify the sender by return  e-mail and delete this message from your system. Any unauthorized
use or dissemination of this message in whole or in part is strictly prohibited.  Please note
that e-mails are susceptible to change and MindTree shall not be liable for any improper,
untimely or incomplete transmission.

Mime
  • Unnamed multipart/mixed (inline, 7-Bit, 0 bytes)
View raw message