You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modules-dev@httpd.apache.org by Prakash Premkumar <pr...@gmail.com> on 2015/07/06 13:51:53 UTC

read POST parameters in apache module

I'm trying to read POST parameters from an apache c module.

Here's the code I'm using :

/* Include the required headers from httpd */#include
"httpd.h"#include "http_core.h"#include "http_protocol.h"#include
"http_request.h"#include "http_config.h"
#include "apr_strings.h"#include "apr_network_io.h"#include
"apr_dbd.h"#include <apr_file_info.h>#include <apr_file_io.h>#include
<apr_tables.h>#include "util_script.h"


/* Define prototypes of our functions in this module */typedef struct {
    const char *key;
    const char *value;} keyValuePair;
static void register_hooks(apr_pool_t *pool);static int
example_handler(request_rec *r);
keyValuePair *readPost(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.
     * If it is, we accept it and do our things, it not, we simply
return DECLINED,
     * and Apache will try somewhere else.
     */
    if (!r->handler || strcmp(r->handler, "example-handler")) return (DECLINED);

    // The first thing we will do is write a simple "Hello, world!"
back to the client.
    ap_rputs("Hello, world!<br/>", r);
    return OK;}

keyValuePair *readPost(request_rec *r) {
    apr_array_header_t *pairs = NULL;
    apr_off_t len;
    apr_size_t size;
    int res;
    int i = 0;
    char *buffer;
    keyValuePair *kvp;

    res = ap_parse_form_data(r, NULL, &pairs, -1, HUGE_STRING_LEN);
    if (res != OK || !pairs) return NULL; /* Return NULL if we failed
or if there are is no POST data */
    kvp = apr_pcalloc(r->pool, sizeof(keyValuePair) * (pairs->nelts + 1));
    while (pairs && !apr_is_empty_array(pairs)) {
        ap_form_pair_t *pair = (ap_form_pair_t *) apr_array_pop(pairs);
        apr_brigade_length(pair->value, 1, &len);
        size = (apr_size_t) len;
        buffer = apr_palloc(r->pool, size + 1);
        apr_brigade_flatten(pair->value, buffer, &size);
        buffer[len] = 0;
        kvp[i].key = apr_pstrdup(r->pool, pair->name);
        kvp[i].value = buffer;
        ap_rputs(kvp[i].key,r);
        ap_rputs(kvp[i].value,r);
        i++;
    }
    return kvp;}

I have copied the read post function from the apache website:
https://httpd.apache.org/docs/2.4/developer/modguide.html#snippets

I get the following error while trying to compile the module:

mod_example.c:82:9: error: use of undeclared identifier 'ap_form_pair_t'
ap_form_pair_t *pair = (ap_form_pair_t *) apr_array_pop(pairs);

apxs does not recognize ap_form_pair_t. Am I missing any header file ?

Can you please help me resolve this ?

Re: read POST parameters in apache module

Posted by Roman Jurkov <wi...@gmail.com>.
please send email to modules-dev-unsubscribe@httpd.apache.org <ma...@httpd.apache.org> more details can be found here:
http://httpd.apache.org/lists.html#modules-dev <http://httpd.apache.org/lists.html#modules-dev>

-roman.

> On Jul 8, 2015, at 10:24 AM, aupsun <go...@gmail.com> wrote:
> 
> can you tell me how to remove me from this email list?
> 
> On Wed, Jul 8, 2015 at 1:38 PM, Prakash Premkumar <pr...@gmail.com>
> wrote:
> 
>> Thanks a lot Yann. I upgraded to a newer version and the problem is solved
>> now.
>> 
>> On Wed, Jul 8, 2015 at 4:31 AM, Yann Ylavic <yl...@gmail.com> wrote:
>> 
>>> On Mon, Jul 6, 2015 at 1:51 PM, Prakash Premkumar
>>> <pr...@gmail.com> wrote:
>>>> 
>>>> I get the following error while trying to compile the module:
>>>> 
>>>> mod_example.c:82:9: error: use of undeclared identifier
>> 'ap_form_pair_t'
>>>> ap_form_pair_t *pair = (ap_form_pair_t *) apr_array_pop(pairs);
>>>> 
>>>> apxs does not recognize ap_form_pair_t. Am I missing any header file ?
>>> 
>>> Your module may be compiled against an older Apache httpd (2.2.x)
>>> installed on the system ('ap_form_pair_t' being 2.4.x or trunk only).
>>> 
>>> Regards,
>>> Yann.
>>> 
>> 
> 
> 
> 
> -- 
> 
> 孙冠江(Alexander Sun)
> 东软集团股份有限公司
> 联系电话:15941146413


Re: read POST parameters in apache module

Posted by aupsun <go...@gmail.com>.
can you tell me how to remove me from this email list?

On Wed, Jul 8, 2015 at 1:38 PM, Prakash Premkumar <pr...@gmail.com>
wrote:

> Thanks a lot Yann. I upgraded to a newer version and the problem is solved
> now.
>
> On Wed, Jul 8, 2015 at 4:31 AM, Yann Ylavic <yl...@gmail.com> wrote:
>
> > On Mon, Jul 6, 2015 at 1:51 PM, Prakash Premkumar
> > <pr...@gmail.com> wrote:
> > >
> > > I get the following error while trying to compile the module:
> > >
> > > mod_example.c:82:9: error: use of undeclared identifier
> 'ap_form_pair_t'
> > > ap_form_pair_t *pair = (ap_form_pair_t *) apr_array_pop(pairs);
> > >
> > > apxs does not recognize ap_form_pair_t. Am I missing any header file ?
> >
> > Your module may be compiled against an older Apache httpd (2.2.x)
> > installed on the system ('ap_form_pair_t' being 2.4.x or trunk only).
> >
> > Regards,
> > Yann.
> >
>



-- 

孙冠江(Alexander Sun)
东软集团股份有限公司
联系电话:15941146413

Re: read POST parameters in apache module

Posted by Prakash Premkumar <pr...@gmail.com>.
Thanks a lot Yann. I upgraded to a newer version and the problem is solved
now.

On Wed, Jul 8, 2015 at 4:31 AM, Yann Ylavic <yl...@gmail.com> wrote:

> On Mon, Jul 6, 2015 at 1:51 PM, Prakash Premkumar
> <pr...@gmail.com> wrote:
> >
> > I get the following error while trying to compile the module:
> >
> > mod_example.c:82:9: error: use of undeclared identifier 'ap_form_pair_t'
> > ap_form_pair_t *pair = (ap_form_pair_t *) apr_array_pop(pairs);
> >
> > apxs does not recognize ap_form_pair_t. Am I missing any header file ?
>
> Your module may be compiled against an older Apache httpd (2.2.x)
> installed on the system ('ap_form_pair_t' being 2.4.x or trunk only).
>
> Regards,
> Yann.
>

Re: read POST parameters in apache module

Posted by Yann Ylavic <yl...@gmail.com>.
On Mon, Jul 6, 2015 at 1:51 PM, Prakash Premkumar
<pr...@gmail.com> wrote:
>
> I get the following error while trying to compile the module:
>
> mod_example.c:82:9: error: use of undeclared identifier 'ap_form_pair_t'
> ap_form_pair_t *pair = (ap_form_pair_t *) apr_array_pop(pairs);
>
> apxs does not recognize ap_form_pair_t. Am I missing any header file ?

Your module may be compiled against an older Apache httpd (2.2.x)
installed on the system ('ap_form_pair_t' being 2.4.x or trunk only).

Regards,
Yann.