Hi all,

        I figured it out. For anyone looking for the body of a POST
request in mathopd, here's how a function in C to get it easily.

NOTE: This function must be called AFTER process_headers(), preferably in
it's own code module, similar to how imap.c, dump.c, dummy.c, redirect.c
and cgi.c are set up.

<code>
/* get the POST body from the stream */
char *get_post_body (struct request *r)
{
        int rv, size;
        char *buffer;

        size = atoi (r->in_content_length);
        input_buffer = malloc (size);
        fcntl (r->cn->fd, F_SETFL, 0);
        rv = recv (r->cn->fd, input_buffer, size, MSG_PEEK);
        if (rv == -1)
        {
                switch (errno) {
                default:
                        log_d (
                          "get_post_body: error reading from %d",
                          r->cn->ip);
                        lerror ("recv");
                case ECONNRESET:
                        r->cn->action = HC_CLOSING;
                case EAGAIN:
                        return 0;
                }
        }
        if (rv == 0)
        {
                log_d ("get_post_body: body empty");
                r->cn->action = HC_CLOSING;
                return 0;
        }
        fcntl (r->cn->fd, F_SETFL, O_NONBLOCK);
        return buffer;
}
</code>

Hope this helps someone!

<< T o b i a s   D i P a s q u a l e >>
web: http://cbcg.net/
mailto: [EMAIL PROTECTED]
trade: Software Engineer 
skillset: Linux/BSD/UNIX/C/Java/Ruby

On Wed, 27 Mar 2002, Toby DiPasquale wrote:

> Hi all,
> 
>       Where is the data from the client request held? What I mean is,
> where does the data get put to be read from the pool and request structs
> in mathopd? What is the preferred method of reading this data and using
> it? For example, consider the following request:
> 
> === BEGIN request =========================
> POST /RPC2 HTTP/1.0
> User-Agent: Frontier/5.1.2 (WinNT)
> Host: betty.userland.com
> Content-Type: text/xml
> Content-length: 181
> 
> <?xml version="1.0"?>
> <methodCall>
> <methodName>examples.getStateName</methodName>
>  <params>
>   <param>
>    <value><i4>41</i4></value>
>   </param>
>  </params>
> </methodCall>
> 
> === END request =========================
> 
> Where, in mathopd, would the portion of the request starting with "<?xml
> version="1.0"?>" be stored? And what is the preferred method of accessing
> that data without SIGSEGV'ing the process every time one of these requests
> comes in?
> 
> << T o b i a s   D i P a s q u a l e >>
> web: http://cbcg.net/
> mailto: [EMAIL PROTECTED]
> trade: Software Engineer 
> skillset: Linux/BSD/UNIX/C/Java/Ruby
> 
> 

Reply via email to