C module

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I’m new to Apache.  I’ve gotten mod_perl, php, cgi and html to do my hello world.
I’m now trying to get a “c” module to print a simple “hello world”.
I know there is something very simple I’m missing.
I’ve read explanations and examples till they all seem to say the same thing.
I’ve copied examples word for word.
I can get it to compile and have the permissions of all the other .so files.

from my httpd.conf
LoadModule example_module libexec/apache2/mod_example.so

For the mod_perl and .cgi I had these lines
AddHandler cgi-script .cgi
AddHandler mod_perl .pl
AddHandler mod_perl .pm

But when the actions you want to take are in the module, how do I call it?
Since my file.c is called mod_example.c and it compiles/installs as mod_example.so
Do I need a bogus file IE mod_example
Then set a handle for mod_example

where mod_example would be a simple
touch mod_example

Then in my .config
AddHandler mod_example mod_example

Then call from Chrome as

http://my_site/mod_example

I tried this, but all I got was a blank screen, no errors of any kind.

Here is my mod_example.c

/* Include the required headers from httpd */
#include "httpd.h"
#include "http_config.h"
#include "http_core.h"
#include "http_protocol.h"
#include "http_request.h"

/* Define prototypes of our functions in this module */
static void register_hooks(apr_pool_t *pool);
static int example_handler(request_rec *r);

/* Define our module as an entity and assign a function for registering hooks  */

module AP_MODULE_DECLARE_DATA   example_module =
{
    STANDARD20_MODULE_STUFF,
    NULL,            // Per-directory configuration handler
    NULL,            // Merge handler for per-directory configurations
    NULL,            // Per-server configuration handler
    NULL,            // Merge handler for per-server configurations
    NULL,            // Any directives we may have for httpd
    register_hooks   // Our hook registering function
};


/* register_hooks: Adds a hook to the httpd process */
static void register_hooks(apr_pool_t *pool)
{

    /* Hook the request handler */
    ap_hook_handler(example_handler, NULL, NULL, APR_HOOK_LAST);
}

/* The handler function for our module.
 * This is where all the fun happens!
 */
static int example_handler(request_rec *r)
{
    /* First off, we need to check if this is a call for the "example-handler" handler.
     * If it is, we accept it and do our things, if not, we simply return DECLINED,
     * and the server will try somewhere else.
     */
    if (!r->handler || strcmp(r->handler, "example-handler")) return (DECLINED);

    /* Now that we are handling this request, we'll write out "Hello, world!" to the client.
     * To do so, we must first set the appropriate content type, followed by our output.
     */
    ap_set_content_type(r, "text/html");
    ap_rprintf(r, "Hello, world!");

    /* Lastly, we must tell the server that we took care of this request and everything went fine.
     * We do so by simply returning the value OK to the server.
     */
    return OK;
}


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@xxxxxxxxxxxxxxxx
For additional commands, e-mail: users-help@xxxxxxxxxxxxxxxx






[Index of Archives]     [Open SSH Users]     [Linux ACPI]     [Linux Kernel]     [Linux Laptop]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Squid]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]

  Powered by Linux