Shruti Gosavi
Shruti Gosavi

Reputation: 33

How to call executable using system call from apache module type_checker hook?

static int x_post_config(apr_pool_t *pconf, apr_pool_t *plog,
                          apr_pool_t *ptemp, server_rec *s)
{
        system("/home/user/workspace/CheckVideo/Debug/CheckVideo.exe"); 
        return OK;
}


static void register_hooks(apr_pool_t* pool)
{
    ap_hook_post_config(x_post_config, NULL, NULL, APR_HOOK_MIDDLE);
}

module AP_MODULE_DECLARE_DATA MyModule_module = {
    STANDARD20_MODULE_STUFF,
    NULL,
    NULL,
    NULL,
    NULL,
    NULL,
    register_hooks
};

I developed this module in C and integrated it in Apache server using Apache extension tool(apxs). I am able to run executable using system call in background when calling it from post_config hook.

Now I want to change same code to run executable using system call only when particular mime type like .mp4 video is called on Apache. So instead of post_config, I want to run this executable at response phase of Apache. I am trying to execute same system() function for example:

static int My_handler(request_rec* r)
{
   if (strcmp(r->content_type, "video/mp4"))
   {
       system("/home/user/workspace/CheckVideo/Debug/CheckVideo.exe");  
   }
   return DECLINED;
}



static void register_hooks(apr_pool_t* pool)
{
    ap_hook_handler(My_handler, NULL, NULL, APR_HOOK_MIDDLE);
}

module AP_MODULE_DECLARE_DATA My_handler = {
    STANDARD20_MODULE_STUFF,
    NULL,
    NULL,
    NULL,
    NULL,
    NULL,
    register_hooks
};

I want to run this executable continuously in background of video and it should be called only for particular video type. So how can I call executable using system call from Apache module ap_hook_handler?

Upvotes: 2

Views: 203

Answers (0)

Related Questions