On 11/3/07, Sergey Lyubka <[EMAIL PROTECTED]> wrote:
> I presume, this is what happens:
>
> At first request, SHTTPD does usual things and
> your callback gets the HTTP data, as normal.
>
> Then, when you hit refresh, firefox uses the same connection
> to send next request, i.e. keep-alive.
>
> Your callback is called second time for the same connection.
> Although it is a new request, SHTTPD does not know that,
> thinks this is HTTP data. That's why you see full request.
>
> Is that true that firefox does not close the connection
> even though you sent "Connection: close" header ?
>
> sergey
>
I checked if the socket are really  closed , by adding some more debug
statements. (Maybe closesocket shoud be defined as
shutdown(x),close(x) ?)

I got this fixed ( i guess :) ).
First I found out that the arg->in.buf is not null terminated, so I
will need the memcpy.
Second, arg->in.buff contains only the body (no headers).
When I don't have anything to process, I just return from the methodCall.
As for the state, I don't think is really needed.

I posted the code below:



static void methodCall( struct shttpd_arg* arg )
{
        debug("HTTP_XMLRPC: BUFLEN[%d] [%.*s]\n", arg->in.len,
arg->in.len, arg->in.buf);
        char *body=NULL;
        char* rsp=NULL;

        char* req=(char*)malloc( (arg->in.len+1)*sizeof(char) );

        memcpy( req, arg->in.buf, arg->in.len );
        req[arg->in.len]=0;

        body = strstr( req, "\r\n\r\n");
        if( body && *(body+4) =='<' )
        {
            /* Header and BODY. As far as I saw, this won't happend.
             * shttpd will pass me only the body (no headers) */
            debug("HEADER_AND_BODY\n");
            rsp = methodResponse( body+4);
        }else if( body && *(body+4) !='<' )
        {
            /* Just header. */
            debug("JUST_HEADER\n");
            shttpd_printf(arg, "%s", "HTTP/1.1 200 OK\r\n");
            shttpd_printf(arg, "%s", "Content-Type: text/xml\r\n\r\n");
            free(req);
            return ;
        }else if( !body && *(req) == '<' )
        {
            debug("JUST_BODY\n");
            rsp = methodResponse( req);
        }else
        {
            /* Empty rem: 0 []*/
            debug("EMPTY REQUEST. OUTBUF[%s]\n", arg->out.buf);
            free(req);
            return ;
        }

        shttpd_printf( arg, "HTTP/1.1 200 OK\r\n");
        shttpd_printf( arg, "Connection: close\r\n");
        shttpd_printf( arg, "Content-Length: %d\r\n", strlen(rsp));
        shttpd_printf( arg, "Content-Type: text/xml\r\n");
        shttpd_printf( arg, "Server: Seraph Manager 2.0\r\n");
        shttpd_printf(arg, "\r\n");
        shttpd_printf(arg, "%s\r\n", rsp);
        debug("OUTBUF[%s]\n", arg->out.buf);
        arg->flags |= SHTTPD_END_OF_OUTPUT;
        free(req);
}


-- 
Regards, Groleo!

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
shttpd-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/shttpd-general

Reply via email to