Protocol converter module

2012-06-04 Thread Robert Mitschke
Hi everybody,

I am attempting to write a module that implements a binary protocol that is
not http and is not fully request and response based using apache. I have
looked at mode echo and some others and I have Nick Kew's book.

I want my module to convert incoming messages into http requests so that
Apache is going to serve them using normal application server
infrastructure. This is what I, based on the info I have can easily do
using an input and output filter.

What I also need the protocol to be able to do is to send messages to the
client with no incoming data from the client. This may be based on a
timeout or based on a request coming from somewhere else (a tier-2
application server sending me a request on a totally different connection).

>From what I have read so far, I could not find a hook that allows me to do
so. The only way that I could figure out how to do that is to modify
http_core.c and in ap_process_http_sync_connection query for either the
timeout or the separate even to have occured using some shared memory
technique. This however does not feel right to me. I would ideally like to
keep using http_core as it is without touching it.

Is there a way for me to wake up trigger the input filter chain even when
there is no data on the actual connection? I could then create a request
from the context of my persistent connection for a handler that I have
written that triggers the output filter chain to send the correct message.
Or even better is there a way I can trigger the output filter chain? Are
there hooks for this purpose?

I would very much appreciate a hint in the right direction.

Best regards,
Robert


Re: Change Request-Header before mod_rewrite

2012-06-04 Thread Sorin Manolache

On 2012-06-04 22:53, Marc apocalypse17 wrote:

Hi all,

I just developed my first apache module following the tutorial on the apache 
website. The module is responsible for adding one header value to the active 
request which must be checked in a mod_rewrite ReWriteCondition.
The problem is, that this value never reaches the mod_rewrite Rule. The Header 
just behaves the same as the original request. Does anyone know why? What am I 
doing wrong?

My module looks like this:

static int helloworld_handler(request_rec* r){
 if (!r->main) {
 apr_table_setn(r->headers_in, "X-CUSTOM-HEADER", "1");
 }
 return DECLINED;
}

static void register_hooks(apr_pool_t* pool){
 ap_hook_handler(helloworld_handler, NULL, NULL, APR_HOOK_FIRST);
}

module AP_MODULE_DECLARE_DATA helloworld_module = {
 STANDARD20_MODULE_STUFF,
 NULL,
 NULL,
 NULL,
 NULL,
 example_directives,
 register_hooks
};

The .htacces file looks like this:

RewriteEngine on
RewriteCond %{HTTP:X-CUSTOM-HEADER} 1 [NC]
RewriteRule from.html to.html

The Rewrite-Rule is never executes fine. It always show the content of 
from.html.


A server-wide RewriteRule is executed in the translate_name hook.

A directory-wide RewriteRule is executed in the fixups hook.

So you'll have to place a callback on the translate_name or on the 
fixups hook and make sure your callback is executed before mod_rewrite's.


You could also try to set the header using the RequestHeader directive 
of the mod_headers module. Use the option "early". 
http://httpd.apache.org/docs/2.2/mod/mod_headers.html#requestheader


--
Sorin





Thank you in advance,
Marc





Re: Change Request-Header before mod_rewrite

2012-06-04 Thread Daniel Gruno
On 06/04/2012 10:53 PM, Marc apocalypse17 wrote:
> Hi all,
>
> I just developed my first apache module following the tutorial on the apache 
> website. The module is responsible for adding one header value to the active 
> request which must be checked in a mod_rewrite ReWriteCondition.
> The problem is, that this value never reaches the mod_rewrite Rule. The 
> Header just behaves the same as the original request. Does anyone know why? 
> What am I doing wrong?
>
> My module looks like this:
>
> static int helloworld_handler(request_rec* r){
> if (!r->main) {
> apr_table_setn(r->headers_in, "X-CUSTOM-HEADER", "1");
> }
> return DECLINED;
> }
>
> static void register_hooks(apr_pool_t* pool){
> ap_hook_handler(helloworld_handler, NULL, NULL, APR_HOOK_FIRST);
> }
>
> module AP_MODULE_DECLARE_DATA helloworld_module = {
> STANDARD20_MODULE_STUFF,
> NULL,
> NULL,
> NULL,
> NULL,
> example_directives,
> register_hooks
> };
>
> The .htacces file looks like this:
>
> RewriteEngine on
> RewriteCond %{HTTP:X-CUSTOM-HEADER} 1 [NC]
> RewriteRule from.html to.html
>
> The Rewrite-Rule is never executes fine. It always show the content of 
> from.html.
>
>
> Thank you in advance,
> Marc
>
As Ben said, mod_rewrite is invoked far earlier than your handler
(handlers are invoked last), since it hooks onto the translation part of
the http process. If you intend for your module to do the same, you
change your hook function accordingly:

static void register_hooks(apr_pool_t* pool){
ap_hook_translate_name(helloworld_handler, NULL, NULL, APR_HOOK_FIRST-1);
}
 

This will eventually be covered by the module guide in the docs (as soon
as I get some time off to write it)

With regards,
Daniel.


Re: Change Request-Header before mod_rewrite

2012-06-04 Thread Ben Noordhuis
On Mon, Jun 4, 2012 at 10:53 PM, Marc apocalypse17  wrote:
> Hi all,
>
> I just developed my first apache module following the tutorial on the apache 
> website. The module is responsible for adding one header value to the active 
> request which must be checked in a mod_rewrite ReWriteCondition.
> The problem is, that this value never reaches the mod_rewrite Rule. The 
> Header just behaves the same as the original request. Does anyone know why? 
> What am I doing wrong?
>
> My module looks like this:
>
> static int helloworld_handler(request_rec* r){
>    if (!r->main) {
>        apr_table_setn(r->headers_in, "X-CUSTOM-HEADER", "1");
>    }
>    return DECLINED;
> }
>
> static void register_hooks(apr_pool_t* pool){
>    ap_hook_handler(helloworld_handler, NULL, NULL, APR_HOOK_FIRST);
> }
>
> module AP_MODULE_DECLARE_DATA helloworld_module = {
>    STANDARD20_MODULE_STUFF,
>    NULL,
>    NULL,
>    NULL,
>    NULL,
>    example_directives,
>    register_hooks
> };
>
> The .htacces file looks like this:
>
> RewriteEngine on
> RewriteCond %{HTTP:X-CUSTOM-HEADER} 1 [NC]
> RewriteRule from.html to.html
>
> The Rewrite-Rule is never executes fine. It always show the content of 
> from.html.
>
>
> Thank you in advance,
> Marc

mod_rewrite.c does most of the interesting work in a translate_name
hook. By the time your handler hooks run, it's probably too late.


Change Request-Header before mod_rewrite

2012-06-04 Thread Marc apocalypse17
Hi all,

I just developed my first apache module following the tutorial on the apache 
website. The module is responsible for adding one header value to the active 
request which must be checked in a mod_rewrite ReWriteCondition.
The problem is, that this value never reaches the mod_rewrite Rule. The Header 
just behaves the same as the original request. Does anyone know why? What am I 
doing wrong?

My module looks like this:

static int helloworld_handler(request_rec* r){
if (!r->main) {
apr_table_setn(r->headers_in, "X-CUSTOM-HEADER", "1");
}
return DECLINED;
}

static void register_hooks(apr_pool_t* pool){
ap_hook_handler(helloworld_handler, NULL, NULL, APR_HOOK_FIRST);
}

module AP_MODULE_DECLARE_DATA helloworld_module = {
STANDARD20_MODULE_STUFF,
NULL,
NULL,
NULL,
NULL,
example_directives,
register_hooks
};

The .htacces file looks like this:

RewriteEngine on
RewriteCond %{HTTP:X-CUSTOM-HEADER} 1 [NC]
RewriteRule from.html to.html

The Rewrite-Rule is never executes fine. It always show the content of 
from.html.


Thank you in advance,
Marc

-- 
Empfehlen Sie GMX DSL Ihren Freunden und Bekannten und wir
belohnen Sie mit bis zu 50,- Euro! https://freundschaftswerbung.gmx.de