You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Robert Mooney <rj...@aboveground.cx> on 2001/11/29 00:55:46 UTC

Failure: ap_popenf() on WIN32

I'm having trouble getting an ap_popenf() to work under WIN32.  It appears
to return an invalid file descriptor.  This does not happen with the UNIX
machines I've tested.

I'm using Apache 1.3.22, installed from .MSI on WIN32.

Under BSD, output is written to the file "output.txt" as expected. 

Under Windows, the file is created, no output is written, and the module 
displays "Bad file descriptor".

Any assistance would be appreciated.  Here is the code; see my comments
inline:

-- cut here --

#include "httpd.h"
#include "http_config.h"
#include "http_core.h"
#include "http_log.h"

#include <limits.h>
#include <stdlib.h>
#include <errno.h>

#ifdef _WIN32
 #include <windows.h>
 #include <io.h>
#endif

/* Initialize the log file */
static void init_config_log(server_rec *s, pool *p)
{
   int fd, nbytes;
   char *fname = ap_server_root_relative (p, "output.txt");

   /* XXX WIN32: the following will create the file, but the descriptor 
    *            returned is invalid. 
    */
   if ((fd = ap_popenf(p,  fname, O_WRONLY|O_APPEND| O_CREAT, 0666)) < 0) {
       fprintf (stderr, "httpd: could not open %s.\n", fname);
       perror("open");
       exit( EXIT_FAILURE );
   }

   /* XXX WIN32: the following will open the file, and allow the write,
    *            however, there is no way to close the descriptor when the 
    *            module is unloaded.  or is there?
    */

   /*
   if ((fd = open( fname, O_WRONLY | O_APPEND | O_CREAT, 0666 )) < 0) {
       fprintf (stderr, "httpd: could not open %s.\n", fname);
       perror("open");
       exit( EXIT_FAILURE );
   }
    */

   /* Dump the FD */
   fprintf(stderr, "fd: %d\n", fd );

   /* Write a test string */
   nbytes = write( fd, "test\n", strlen(" test\n" ));

   /* If the write failed, mention it */
   if ( nbytes < 0 )  fprintf(stderr, "ERROR: %s\n", strerror( errno ));
}

/* Apache Module Dispatch */
module MODULE_VAR_EXPORT test_module =
{
       STANDARD_MODULE_STUFF,
       init_config_log,            /* initializer */
       NULL,                       /* create per-dir config */
       NULL,                       /* merge per-dir config */
       NULL,                       /* server config */
       NULL,			   /* merge server config */
       NULL,                       /* command table */
       NULL,                       /* handlers */
       NULL,                       /* filename translation */
       NULL,                       /* check_user_id */
       NULL,                       /* check auth */
       NULL,                       /* check access */
       NULL,                       /* type_checker */
       NULL,                       /* fixups */
       NULL,                       /* logger */
       NULL,                       /* header parser */
       NULL,                       /* child_init */
       NULL,	                   /* child_exit */
       NULL                        /* post read-request */
};

-- cut here --

- Rob

--
Robert Mooney (rjmooney@aboveground.cx)
www: http://www.aboveground.cx/~rjmooney/ 

Re: Duplicating POST data between modules?

Posted by Ryan Bloom <rb...@covalent.net>.
On Friday 21 December 2001 04:26 am, Eli Marmor wrote:
> Robert Mooney wrote:
> 
> > Is there any way to "peek" at client data from a module?  I.e. read without
> > removing it?  Specifically, I want my module to be able to read any POST
> > data, and allow mod_cgi to process normally.  Using the sample code below,
> > mod_cgi does not read any input from STDIN.
> > ...
> > I was under the impression REQUEST_CHUNK_PASS did what I was looking for, but
> > this is not the case.  mod_cgi can read the POST data until I call ap_get_
> > client_block(), after which... nothing.
> > 
> > I'm using Apache 1.3.22.
> 
> That's the problem;
> Move to 2.0.28, and use Input Filters.

This can be hacked into 1.3.  Whenever you read data, save it to a file on
the disk, and then modify the BUFF structure so that fd_in reads from that
file.  This is a very primitive form of input filtering, but it will work.

Ryan

______________________________________________________________
Ryan Bloom				rbb@apache.org
Covalent Technologies			rbb@covalent.net
--------------------------------------------------------------

Re: Duplicating POST data between modules?

Posted by Eli Marmor <ma...@netmask.it>.
Robert Mooney wrote:

> Is there any way to "peek" at client data from a module?  I.e. read without
> removing it?  Specifically, I want my module to be able to read any POST
> data, and allow mod_cgi to process normally.  Using the sample code below,
> mod_cgi does not read any input from STDIN.
> ...
> I was under the impression REQUEST_CHUNK_PASS did what I was looking for, but
> this is not the case.  mod_cgi can read the POST data until I call ap_get_
> client_block(), after which... nothing.
> 
> I'm using Apache 1.3.22.

That's the problem;
Move to 2.0.28, and use Input Filters.

-- 
Eli Marmor
marmor@netmask.it
CTO, Founder
Netmask (El-Mar) Internet Technologies Ltd.
__________________________________________________________
Tel.:   +972-9-766-1020          8 Yad-Harutzim St.
Fax.:   +972-9-766-1314          P.O.B. 7004
Mobile: +972-50-23-7338          Kfar-Saba 44641, Israel

Duplicating POST data between modules?

Posted by Robert Mooney <rj...@aboveground.cx>.
Is there any way to "peek" at client data from a module?  I.e. read without 
removing it?  Specifically, I want my module to be able to read any POST 
data, and allow mod_cgi to process normally.  Using the sample code below, 
mod_cgi does not read any input from STDIN. 

static int response_handler(request_rec *r)
{
   int result;
   char dumpbuf[HUGE_STRING_LEN];

   if ((result = ap_setup_client_block(r, REQUEST_CHUNK_PASS)) != OK)
      return result;

   if (!ap_should_client_block(r)) return DECLINED;

   while((result = ap_get_client_block(r, dumpbuf, HUGE_STRING_LEN - 1)) > 0)
   {
      dumpbuf[result] = 0;
      fprintf(stderr, "dumpbuf: %s\n", dumpbuf);
   }

   if (result < 0) return HTTP_BAD_REQUEST;

   return DECLINED;
}

I was under the impression REQUEST_CHUNK_PASS did what I was looking for, but
this is not the case.  mod_cgi can read the POST data until I call ap_get_
client_block(), after which... nothing.

I'm using Apache 1.3.22.

Thanks in advance,

- Rob

--
Robert Mooney (rjmooney@aboveground.cx)
www: http://www.aboveground.cx/~rjmooney/