Re: How to access client socket from a protocol handler

2010-10-24 Thread Ben Noordhuis
On Sun, Oct 24, 2010 at 11:09, Alexander Farber wrote: > So for content handlers the convention is > to use "SetHandler XXX" in httpd.conf and > then at the runtime they check for that string with > > if (!r->handler || (strcmp(r->handler, "XXX") != 0)) { >    return DECLINED; > } > > But for prot

Re: How to access client socket from a protocol handler

2010-10-24 Thread Alexander Farber
On Sun, Oct 24, 2010 at 12:08 AM, Ben Noordhuis wrote: > On Sun, Oct 24, 2010 at 00:00, Alexander Farber > wrote: >> I've created a module using bb (the source code at the bottom) >> and it suffers from the same problem (hijacks the port 80 too). >> Could it be that "SetHandler" is a wrong direct

Re: How to access client socket from a protocol handler

2010-10-23 Thread Ben Noordhuis
On Sun, Oct 24, 2010 at 00:00, Alexander Farber wrote: > I've created a module using bb (the source code at the bottom) > and it suffers from the same problem (hijacks the port 80 too). > Could it be that "SetHandler" is a wrong directive for protocol handler? The wrong directive, yes. SetHandler

Re: How to access client socket from a protocol handler

2010-10-23 Thread Alexander Farber
No, SetHandler should be ok, because mod_echo works fine. I've added the port number to my logs: ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, conn->base_server, "served socket policy to %s via %d", conn->remote_ip, conn->base_server->port); And now I see in the error_log:

Re: How to access client socket from a protocol handler

2010-10-23 Thread Alexander Farber
Thank you, but - On Sat, Oct 23, 2010 at 10:01 PM, Ben Noordhuis wrote: > Alexander, take a look at mod_echo.c (included in the source tarball). > It's a great example of how a protocol handler should work and it just > might convince you to use bucket brigades after all. :) > > You need to check

Re: How to access client socket from a protocol handler

2010-10-23 Thread Ben Noordhuis
Alexander, take a look at mod_echo.c (included in the source tarball). It's a great example of how a protocol handler should work and it just might convince you to use bucket brigades after all. :) You need to check if your handler is enabled for the current vhost. If it's not, return DECLINED. If

Re: How to access client socket from a protocol handler

2010-10-23 Thread Alexander Farber
Hello Ben, On Sat, Oct 23, 2010 at 2:08 PM, Ben Noordhuis wrote: > On Sat, Oct 23, 2010 at 10:13, Alexander Farber > wrote: > Your connection handler should return DECLINED for vhosts it doesn't > handle (I wager mod_perl did this for you). > > You can get the vhost with conn->base_server and yo

Re: How to access client socket from a protocol handler

2010-10-23 Thread Ben Noordhuis
On Sat, Oct 23, 2010 at 10:13, Alexander Farber wrote: > I wonder why my mod_perl module works and the C one not. Your connection handler should return DECLINED for vhosts it doesn't handle (I wager mod_perl did this for you). You can get the vhost with conn->base_server and your module's per-se

Re: How to access client socket from a protocol handler

2010-10-23 Thread Alexander Farber
On Sat, Oct 23, 2010 at 10:09 AM, Alexander Farber wrote: > http://perl.apache.org/dist/mod_perl-2.0-current/xs/Apache2/Connection/Apache2__Connection.h > >    apr_socket_t *socket = >        ap_get_module_config(c->conn_config, &core_module); > >    if (s) { >        ap_set_module_config(c->conn_

Re: How to access client socket from a protocol handler

2010-10-23 Thread Alexander Farber
Hello again, the http://perl.apache.org/dist/mod_perl-2.0-current/xs/Apache2/Connection/Apache2__Connection.h uses conn_config to get at the client socket as well, but I've also noticed that they pass an additional argument there: apr_socket_t *socket = ap_get_module_config(c->conn_c

Re: How to access client socket from a protocol handler

2010-10-22 Thread Alexander Farber
Hello Ben and others On Sat, Oct 23, 2010 at 12:52 AM, Ben Noordhuis wrote: > On Sat, Oct 23, 2010 at 00:15, Alexander Farber > the conn_config solution is most portable across Apache versions. > >> And what do you mean by &core_module >> in my case (source code below)? > > That's the reference t

Re: How to access client socket from a protocol handler

2010-10-22 Thread Ben Noordhuis
On Sat, Oct 23, 2010 at 00:15, Alexander Farber wrote: > Should I maybe try > apr_socket_t *socket = conn->cs->desc->s > or something similar instead? Probably not, the conn_config solution is most portable across Apache versions. > And what do you mean by &core_module > in my case (source code

Re: How to access client socket from a protocol handler

2010-10-22 Thread Ben Noordhuis
On Sat, Oct 23, 2010 at 00:01, Mike Meyer wrote: > I use that to get the socket so I can poll for it to have data in it, > and do other things while I'm waiting. Is there a better alternative > for that, or is this an exception? You could do it through apr_bucket_read(APR_NONBLOCK_READ) but polli

Re: How to access client socket from a protocol handler

2010-10-22 Thread Alexander Farber
Hi Ben, On Fri, Oct 22, 2010 at 11:54 PM, Ben Noordhuis wrote: > On Fri, Oct 22, 2010 at 23:08, Alexander Farber > wrote: >> but don't know how to get the client socket via conn_rec? > > apr_socket_t *client  = ap_get_module_config(conn->conn_config, &core_module); > > But note that in most case

Re: How to access client socket from a protocol handler

2010-10-22 Thread Ben Noordhuis
On Fri, Oct 22, 2010 at 23:08, Alexander Farber wrote: > Unfortunately there aren't many example for the protocol handlers > on the web or in Nick's book. I've come up with the following, > but don't know how to get the client socket via conn_rec? apr_socket_t *client = ap_get_module_config(conn

How to access client socket from a protocol handler

2010-10-22 Thread Alexander Farber
Hello, I have a simple Perl module (source code at the bottom), which sends a string to clients connecting to port 843. It works ok, but I'd like to rewrite it in C because it seems to use 20m for this simple task at my CentOS 5.5/64 Linux with httpd-2.2.3-43 and mod_perl-2.0.4: PID USER