RewriteMap PRG By Example Using C

RewriteMap PRG By Example Using C

am 28.04.2009 20:17:56 von ricardo figueiredo

Hi all,
I'm doing examples with mod_rewrite, I'm using directive RewriteMap
I did a simple program in C

#include
int main() {
int id = 0;
fscanf(stdin, "%d", &id);
switch(id) {
case 1: fprintf(stdout, "/index.html");
break;

case 2: fprintf(stdout, "/new.html");
break;

case 3: fprintf(stdout, "/teste.php?var=4/8");
break;
}
fflush(stdout);
return 0;
}

My httpd.conf:
RewriteEngine on
RewriteLock /usr/local/apache2/logs/file.lock
RewriteMap prgmap prg:/usr/local/apache2/file
RewriteRule ^/(.*) ${prgmap:$1}

My program in C called file
In my folder htdocs I have three files (index.html, new.html and test.php).
When typed in the browser "http//localhost/1" I think that URL is mapped to
address "http://localhost/index.html"

What happen ?? Is test right ??

Thank you

Ricardo
--
View this message in context: http://www.nabble.com/RewriteMap-PRG-By-Example-Using-C-tp23 283305p23283305.html
Sent from the Apache HTTP Server - Users mailing list archive at Nabble.com.


------------------------------------------------------------ ---------
The official User-To-User support forum of the Apache HTTP Server Project.
See for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org

Re: RewriteMap PRG By Example Using C

am 28.04.2009 20:26:58 von Eric Covener

On Tue, Apr 28, 2009 at 2:17 PM, ricardo13 wrote=
:
>
> Hi all,
> I'm doing examples with mod_rewrite, I'm using directive RewriteMap
> I did a simple program in C
>
> #include
> int main() {
> =A0int id =3D 0;
> =A0fscanf(stdin, "%d", &id);
> =A0switch(id) {
> =A0 =A0case 1: fprintf(stdout, "/index.html");
> =A0 =A0break;
>
> =A0 =A0case 2: fprintf(stdout, "/new.html");
> =A0 =A0break;
>
> =A0 =A0case 3: fprintf(stdout, "/teste.php?var=3D4/8");
> =A0 =A0break;
> =A0}
> =A0fflush(stdout);
> =A0return 0;
> }

You need to loop and you probably need to read up until a newline.

>
> My httpd.conf:
> =A0RewriteEngine on
> =A0RewriteLock /usr/local/apache2/logs/file.lock
> =A0RewriteMap prgmap prg:/usr/local/apache2/file
> =A0RewriteRule ^/(.*) ${prgmap:$1}
>
> My program in C called file
> In my folder htdocs I have three files (index.html, new.html and test.php=
).
> When typed in the browser "http//localhost/1" I think that URL is mapped =
to
> address "http://localhost/index.html"
>
> What happen ?? Is test right ??

I don't know, what happened?

--=20
Eric Covener
covener@gmail.com

------------------------------------------------------------ ---------
The official User-To-User support forum of the Apache HTTP Server Project.
See for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org

Re: RewriteMap PRG By Example Using C

am 28.04.2009 20:59:55 von ricardo figueiredo

Hi,

I thought that if I typed "localhost/1" in browser, the program (file) in
mod_rewrite (RewriteMap) mapped from /1 to /index.html

But, Happen 400 Bad Request.

Thank you

Ricardo


Eric Covener wrote:
>=20
> On Tue, Apr 28, 2009 at 2:17 PM, ricardo13
> wrote:
>>
>> Hi all,
>> I'm doing examples with mod_rewrite, I'm using directive RewriteMap
>> I did a simple program in C
>>
>> #include
>> int main() {
>>  int id =3D 0;
>>  fscanf(stdin, "%d", &id);
>>  switch(id) {
>>    case 1: fprintf(stdout, "/index.html");
>>    break;
>>
>>    case 2: fprintf(stdout, "/new.html");
>>    break;
>>
>>    case 3: fprintf(stdout, "/teste.php?var=3D4/8");
>>    break;
>>  }
>>  fflush(stdout);
>>  return 0;
>> }
>=20
> You need to loop and you probably need to read up until a newline.
>=20
>>
>> My httpd.conf:
>>  RewriteEngine on
>>  RewriteLock /usr/local/apache2/logs/file.lock
>>  RewriteMap prgmap prg:/usr/local/apache2/file
>>  RewriteRule ^/(.*) ${prgmap:$1}
>>
>> My program in C called file
>> In my folder htdocs I have three files (index.html, new.html and
>> test.php).
>> When typed in the browser "http//localhost/1" I think that URL is mapped
>> to
>> address "http://localhost/index.html"
>>
>> What happen ?? Is test right ??
>=20
> I don't know, what happened?
>=20
> --=20
> Eric Covener
> covener@gmail.com
>=20
> ------------------------------------------------------------ ---------
> The official User-To-User support forum of the Apache HTTP Server Project=
..
> See for more info.
> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
> " from the digest: users-digest-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org
>=20
>=20
>=20

--=20
View this message in context: http://www.nabble.com/RewriteMap-PRG-By-Examp=
le-Using-C-tp23283305p23283956.html
Sent from the Apache HTTP Server - Users mailing list archive at Nabble.com=
..


------------------------------------------------------------ ---------
The official User-To-User support forum of the Apache HTTP Server Project.
See for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org

Re: RewriteMap PRG By Example Using C

am 29.04.2009 19:25:46 von ricardo figueiredo

Please !!!

Help me !!!!

Somebody has some example of RewriteMap using external program in C !!!
There are some example in=20
http://www.wellho.net/resources/ex.php4?item=3Da603/andy PHP .

Thank You=20

Ricardo


ricardo13 wrote:
>=20
> Hi,
>=20
> I thought that if I typed "localhost/1" in browser, the program (file) in
> mod_rewrite (RewriteMap) mapped from /1 to /index.html
>=20
> But, Happen 400 Bad Request.
>=20
> Thank you
>=20
> Ricardo
>=20
>=20
> Eric Covener wrote:
>>=20
>> On Tue, Apr 28, 2009 at 2:17 PM, ricardo13
>> wrote:
>>>
>>> Hi all,
>>> I'm doing examples with mod_rewrite, I'm using directive RewriteMap
>>> I did a simple program in C
>>>
>>> #include
>>> int main() {
>>>  int id =3D 0;
>>>  fscanf(stdin, "%d", &id);
>>>  switch(id) {
>>>    case 1: fprintf(stdout, "/index.html");
>>>    break;
>>>
>>>    case 2: fprintf(stdout, "/new.html");
>>>    break;
>>>
>>>    case 3: fprintf(stdout, "/teste.php?var=3D4/8");
>>>    break;
>>>  }
>>>  fflush(stdout);
>>>  return 0;
>>> }
>>=20
>> You need to loop and you probably need to read up until a newline.
>>=20
>>>
>>> My httpd.conf:
>>>  RewriteEngine on
>>>  RewriteLock /usr/local/apache2/logs/file.lock
>>>  RewriteMap prgmap prg:/usr/local/apache2/file
>>>  RewriteRule ^/(.*) ${prgmap:$1}
>>>
>>> My program in C called file
>>> In my folder htdocs I have three files (index.html, new.html and
>>> test.php).
>>> When typed in the browser "http//localhost/1" I think that URL is mappe=
d
>>> to
>>> address "http://localhost/index.html"
>>>
>>> What happen ?? Is test right ??
>>=20
>> I don't know, what happened?
>>=20
>> --=20
>> Eric Covener
>> covener@gmail.com
>>=20
>> ------------------------------------------------------------ ---------
>> The official User-To-User support forum of the Apache HTTP Server
>> Project.
>> See for more info.
>> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
>> " from the digest: users-digest-unsubscribe@httpd.apache.org
>> For additional commands, e-mail: users-help@httpd.apache.org
>>=20
>>=20
>>=20
>=20
>=20

--=20
View this message in context: http://www.nabble.com/RewriteMap-PRG-By-Examp=
le-Using-C-tp23283305p23296344.html
Sent from the Apache HTTP Server - Users mailing list archive at Nabble.com=
..


------------------------------------------------------------ ---------
The official User-To-User support forum of the Apache HTTP Server Project.
See for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org

Re: RewriteMap PRG By Example Using C

am 29.04.2009 19:37:16 von Brian Mearns

On Wed, Apr 29, 2009 at 1:25 PM, ricardo13 wrote=
:
>
> Please !!!
>
> Help me !!!!
>
> Somebody has some example of RewriteMap using external program in C !!!
> There are some example in
> http://www.wellho.net/resources/ex.php4?item=3Da603/andy PHP .
>
> Thank You
>
> Ricardo
>
>
> ricardo13 wrote:
>>
>> Hi,
>>
>> I thought that if I typed "localhost/1" in browser, the program (file) i=
n
>> mod_rewrite (RewriteMap) mapped from /1 to /index.html
>>
>> But, Happen 400 Bad Request.
>>
>> Thank you
>>
>> Ricardo
>>
>>
>> Eric Covener wrote:
>>>
>>> On Tue, Apr 28, 2009 at 2:17 PM, ricardo13
>>> wrote:
>>>>
>>>> Hi all,
>>>> I'm doing examples with mod_rewrite, I'm using directive RewriteMap
>>>> I did a simple program in C
>>>>
>>>> #include
>>>> int main() {
>>>> =A0int id =3D 0;
>>>> =A0fscanf(stdin, "%d", &id);
>>>> =A0switch(id) {
>>>> =A0 =A0case 1: fprintf(stdout, "/index.html");
>>>> =A0 =A0break;
>>>>
>>>> =A0 =A0case 2: fprintf(stdout, "/new.html");
>>>> =A0 =A0break;
>>>>
>>>> =A0 =A0case 3: fprintf(stdout, "/teste.php?var=3D4/8");
>>>> =A0 =A0break;
>>>> =A0}
>>>> =A0fflush(stdout);
>>>> =A0return 0;
>>>> }
>>>
>>> You need to loop and you probably need to read up until a newline.
>>>
>>>>
>>>> My httpd.conf:
>>>> =A0RewriteEngine on
>>>> =A0RewriteLock /usr/local/apache2/logs/file.lock
>>>> =A0RewriteMap prgmap prg:/usr/local/apache2/file
>>>> =A0RewriteRule ^/(.*) ${prgmap:$1}
>>>>
>>>> My program in C called file
>>>> In my folder htdocs I have three files (index.html, new.html and
>>>> test.php).
>>>> When typed in the browser "http//localhost/1" I think that URL is mapp=
ed
>>>> to
>>>> address "http://localhost/index.html"
>>>>
>>>> What happen ?? Is test right ??
>>>
>>> I don't know, what happened?
>>>
>>> --
>>> Eric Covener
>>> covener@gmail.com
>>>
>>> ------------------------------------------------------------ ---------
>>> The official User-To-User support forum of the Apache HTTP Server
>>> Project.
>>> See for more info.
>>> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
>>> =A0 =A0" =A0 from the digest: users-digest-unsubscribe@httpd.apache.org
>>> For additional commands, e-mail: users-help@httpd.apache.org
>>>
>>>
>>>
>>
>>
>
> --
> View this message in context: http://www.nabble.com/RewriteMap-PRG-By-Exa=
mple-Using-C-tp23283305p23296344.html
> Sent from the Apache HTTP Server - Users mailing list archive at Nabble.c=
om.
>
>
> ------------------------------------------------------------ ---------
> The official User-To-User support forum of the Apache HTTP Server Project=
..
> See for more info.
> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
> =A0 " =A0 from the digest: users-digest-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org
>
>

Just FYI, that's a horrible way to get help. Most people on this list
don't have the patience to deal with somebody who sounds frantic.

Eric already answered your question. If it's still not working, you
need to provide more details, like what you did, what you got, how you
know it's not correct.

-Brian


--=20
Feel free to contact me using PGP Encryption:
Key Id: 0x3AA70848
Available from: http://keys.gnupg.net

------------------------------------------------------------ ---------
The official User-To-User support forum of the Apache HTTP Server Project.
See for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org

Re: RewriteMap PRG By Example Using C

am 29.04.2009 19:58:46 von ricardo figueiredo

--001e680f10f0b49bc60468b55472
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

Sorry,

Let me explain my situation again.
I'm using directive RewriteMap using external rewriting program.
This program is developed in language C.

When I require a page in the browser is shown an error (Bad Request 400).

My program in C to rewriting URL

#include
int main() {
int id = 0;
fscanf(stdin, "%d", &id);
switch(id) {
case 111: fprintf(stdout, "/index.html"); break;
case 222: fprintf(stdout, "/new.html"); break;
case 333: fprintf(stdout, "/teste.php?var=4/8"); break;
}

fflush(stdout);
return 0;
}

My httpd.conf is:

RewriteEngine on
RewriteLock /usr/local/apache2/logs/file.lock
RewriteMap prgmap prg:/usr/local/apache2/file
RewriteRule ^/(.*) ${prgmap:$1}


My rewritelog:

[localhost/sid#8b4cd68][rid#8ce45a0/initial] (2) init rewrite engine with
requested uri /111
[localhost/sid#8b4cd68][rid#8ce45a0/initial] (3) applying pattern '^/(.*)'
to uri '/111'
[localhost/sid#8b4cd68][rid#8ce45a0/initial] (5) map lookup OK: map=prgmap
key=111 -> val=
[localhost/sid#8b4cd68][rid#8ce45a0/initial] (2) rewrite '/111' -> ''
[localhost/sid#8b4cd68][rid#8ce45a0/initial] (2) local path result:

Why is this error ??

I hope have given all information.

Ricardo



#include
> int main() {
> int id = 0;
> >>>> fscanf(stdin, "%d", &id);
> >>>> switch(id) {
> >>>> case 1: fprintf(stdout, "/index.html");
> >>>> break;
> >>>>
> >>>> case 2: fprintf(stdout, "/new.html");
> >>>> break;
> >>>>
> >>>> case 3: fprintf(stdout, "/teste.php?var=4/8");
> >>>> break;
> >>>> }
> >>>> fflush(stdout);
> >>>> return 0;
> >>>> }
> >>>
> >>> You need to loop and you probably need to read up until a newline.
> >>>
> >>>>
> >>>> My httpd.conf:
> >>>> RewriteEngine on
> >>>> RewriteLock /usr/local/apache2/logs/file.lock
> >>>> RewriteMap prgmap prg:/usr/local/apache2/file
> >>>> RewriteRule ^/(.*) ${prgmap:$1}
> >>>>
> >>>> My program in C called file
> >>>> In my folder htdocs I have three files (index.html, new.html and
> >>>> test.php).
> >>>> When typed in the browser "http//localhost/1" I think that URL is
> mapped
> >>>> to
> >>>> address "http://localhost/index.html"
> >>>>
> >>>> What happen ?? Is test right ??
> >>>
> >>> I don't know, what happened?
> >>>
> >>> --
> >>> Eric Covener
> >>> covener@gmail.com
> >>>
> >>> ------------------------------------------------------------ ---------
> >>> The official User-To-User support forum of the Apache HTTP Server
> >>> Project.
> >>> See for more info.
> >>> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
> >>> " from the digest: users-digest-unsubscribe@httpd.apache.org
> >>> For additional commands, e-mail: users-help@httpd.apache.org
> >>>
> >>>
> >>>
> >>
> >>
> >
> > --
> > View this message in context:
> http://www.nabble.com/RewriteMap-PRG-By-Example-Using-C-tp23 283305p23296344.html
> > Sent from the Apache HTTP Server - Users mailing list archive at
> Nabble.com.
> >
> >
> > ------------------------------------------------------------ ---------
> > The official User-To-User support forum of the Apache HTTP Server
> Project.
> > See for more info.
> > To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
> > " from the digest: users-digest-unsubscribe@httpd.apache.org
> > For additional commands, e-mail: users-help@httpd.apache.org
> >
> >
>
> Just FYI, that's a horrible way to get help. Most people on this list
> don't have the patience to deal with somebody who sounds frantic.
>
> Eric already answered your question. If it's still not working, you
> need to provide more details, like what you did, what you got, how you
> know it's not correct.
>
> -Brian
>
>
> --
> Feel free to contact me using PGP Encryption:
> Key Id: 0x3AA70848
> Available from: http://keys.gnupg.net
>
> ------------------------------------------------------------ ---------
> The official User-To-User support forum of the Apache HTTP Server Project.
> See for more info.
> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
> " from the digest: users-digest-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org
>
>


--
Muito Obrigado

Ricardo

--001e680f10f0b49bc60468b55472
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

Sorry,

Let me explain my situation again.

n: left;" id=3D"result_box" dir=3D"ltr">I'm using directive RewriteMap =
using external rewriting program.
This program is developed in language =
C.


When I require a page in the browser is shown an error (Bad Request 400=
).

My program in C to rewriting URL

#include <stdio.h><=
br>=A0 int main() {

=A0 int id =3D 0;
  =A0
fscanf(stdin, "%d", &id);

=A0 =A0 switch(id) {

=A0 =A0    case 111: fprintf(stdout, "/index.html");=A0 break=
;

=A0 =A0    case 222: fprintf(stdout, "/new.html");=A0 break;<=
br>       case 333: fprintf(stdout, "/teste.php?var=3D4/8&=
quot;); break;
  =A0 }
  =A0

  =A0 fflush(stdout);
  =A0
return 0;

}

My httpd.conf is:

=A0 RewriteEngine on
=A0
RewriteLock /usr/local/apache2/logs/file.lock
=A0
RewriteMap prgmap prg:/usr/local/apache2/file
=A0
RewriteRule ^/(.*) ${prgmap:$1}


My rewritelog:

[localho=
st/sid#8b4cd68][rid#8ce45a0/initial] (2) init rewrite engine with requested=
uri /111
[localhost/sid#8b4cd68][rid#8ce45a0/initial] (3) applying patt=
ern '^/(.*)' to uri '/111'

[localhost/sid#8b4cd68][rid#8ce45a0/initial] (5) map lookup OK: map=3Dprgma=
p key=3D111 -> val=3D
[localhost/sid#8b4cd68][rid#8ce45a0/initial] (2=
) rewrite '/111' -> ''
[localhost/sid#8b4cd68][rid#8c=
e45a0/initial] (2) local path result:


Why is this error ??

I hope have given all information. >
Ricardo



"gmail_quote" style=3D"border-left: 1px solid rgb(204, 204, 204); margin: 0=
pt 0pt 0pt 0.8ex; padding-left: 1ex;">
#include <stdio.h>
=A0 int main() {

=A0 int id =3D 0;

>>>> =A0fscanf(stdin, "%d", &id);

>>>> =A0switch(id) {

>>>> =A0 =A0case 1: fprintf(stdout, "/index.html"); r>
>>>> =A0 =A0break;

>>>>

>>>> =A0 =A0case 2: fprintf(stdout, "/new.html");

>>>> =A0 =A0break;

>>>>

>>>> =A0 =A0case 3: fprintf(stdout, "/teste.php?var=3D4/8&=
quot;);

>>>> =A0 =A0break;

>>>> =A0}

>>>> =A0fflush(stdout);

>>>> =A0return 0;

>>>> }

>>>

>>> You need to loop and you probably need to read up until a newl=
ine.

>>>

>>>>

>>>> My httpd.conf:

>>>> =A0RewriteEngine on

>>>> =A0RewriteLock /usr/local/apache2/logs/file.lock

>>>> =A0RewriteMap prgmap prg:/usr/local/apache2/file

>>>> =A0RewriteRule ^/(.*) ${prgmap:$1}

>>>>

>>>> My program in C called file

>>>> In my folder htdocs I have three files (index.html, new.ht=
ml and

>>>> test.php).

>>>> When typed in the browser "http//localhost/1" I =
think that URL is mapped

>>>> to

>>>> address " et=3D"_blank">http://localhost/index.html"

>>>>

>>>> What happen ?? Is test right ??

>>>

>>> I don't know, what happened?

>>>

>>> --

>>> Eric Covener

>>>

>>>

>>> ------------------------------------------------------------ --=
-------

>>> The official User-To-User support forum of the Apache HTTP Ser=
ver

>>> Project.

>>> See <URL: target=3D"_blank">http://httpd.apache.org/userslist.html> for more =
info.

>>> To unsubscribe, e-mail: tpd.apache.org">users-unsubscribe@httpd.apache.org

>>> =A0 =A0" =A0 from the digest: est-unsubscribe@httpd.apache.org">users-digest-unsubscribe@h ttpd.apache.org=


>>> For additional commands, e-mail: httpd.apache.org">users-help@httpd.apache.org

>>>

>>>

>>>

>>

>>

>

> --

> View this message in context: Map-PRG-By-Example-Using-C-tp23283305p23296344.html" target=3D"_blank">http=
://www.nabble.com/RewriteMap-PRG-By-Example-Using-C-tp232833 05p23296344.htm=
l



> Sent from the Apache HTTP Server - Users mailing list archive at Nabbl=
e.com.

>

>

> ------------------------------------------------------------ ---------<=
br>
> The official User-To-User support forum of the Apache HTTP Server Proj=
ect.

> See <URL: =3D"_blank">http://httpd.apache.org/userslist.html> for more info. r>
> To unsubscribe, e-mail: he.org">users-unsubscribe@httpd.apache.org

> =A0 " =A0 from the digest: ribe@httpd.apache.org">users-digest-unsubscribe@httpd.apache .org

> For additional commands, e-mail: ache.org">users-help@httpd.apache.org

>

>



Just FYI, that's a horrible way to get help. Most people on=
this list

don't have the patience to deal with somebody who sounds frantic.



Eric already answered your question. If it's still not working, you

need to provide more details, like what you did, what you got, how you

know it's not correct.



-Brian





--

Feel free to contact me using PGP Encryption:

Key Id: 0x3AA70848

Available from: http://=
keys.gnupg.net




------------------------------------------------------------ ---------

The official User-To-User support forum of the Apache HTTP Server Project.<=
br>
See <URL: lank">http://httpd.apache.org/userslist.html> for more info.

To unsubscribe, e-mail: g">users-unsubscribe@httpd.apache.org

=A0 " =A0 from the digest: @httpd.apache.org">users-digest-unsubscribe@httpd.apache.org

For additional commands, e-mail: org">users-help@httpd.apache.org






--
Muito Obrig=
ado

Ricardo


--001e680f10f0b49bc60468b55472--

Re: RewriteMap PRG By Example Using C

am 29.04.2009 20:09:56 von Brian Mearns

On Wed, Apr 29, 2009 at 1:58 PM, ricardo figueiredo
wrote:
> Sorry,
>
> Let me explain my situation again.
> I'm using directive RewriteMap using external rewriting program.
> This program is developed in language C.
>
> When I require a page in the browser is shown an error (Bad Request 400).
>
> My program in C to rewriting URL
>
> #include
> =A0 int main() {
> =A0 int id =3D 0;
>   =A0 fscanf(stdin, "%d", &id);
> =A0 =A0 switch(id) {
> =A0 =A0    case 111: fprintf(stdout, "/index.html");=A0 break;
> =A0 =A0    case 222: fprintf(stdout, "/new.html");=A0 break;
>        case 333: fprintf(stdout, "/teste.php?var=3D4/8"); bre=
ak;
>   =A0 }
>
>   =A0 fflush(stdout);
>   =A0 return 0;
> }
>
> My httpd.conf is:
>
> =A0 RewriteEngine on
> =A0 RewriteLock /usr/local/apache2/logs/file.lock
> =A0 RewriteMap prgmap prg:/usr/local/apache2/file
> =A0 RewriteRule ^/(.*) ${prgmap:$1}
>
> My rewritelog:
>
> [localhost/sid#8b4cd68][rid#8ce45a0/initial] (2) init rewrite engine with
> requested uri /111
> [localhost/sid#8b4cd68][rid#8ce45a0/initial] (3) applying pattern '^/(.*)=
'
> to uri '/111'
> [localhost/sid#8b4cd68][rid#8ce45a0/initial] (5) map lookup OK: map=3Dprg=
map
> key=3D111 -> val=3D
> [localhost/sid#8b4cd68][rid#8ce45a0/initial] (2) rewrite '/111' -> ''
> [localhost/sid#8b4cd68][rid#8ce45a0/initial] (2) local path result:
>
> Why is this error ??
>
> I hope have given all information.
>
> Ricardo
>
>

First of all, like Eric said yesterday, you need a loop in your main
function. The program is not invoked every time the rewrite needs to
be applied, it is started once when the Apache server starts, and just
gets a new line of input for each request to be mapped.

Second, you need to terminate your output with a newline. Apparently,
apache gave up waiting for your program to give it a valid output (one
that is terminated by a newline) and decided to go with an empty
value, instead. Using fflush is probably a good idea, but you'll want
to make sure it's inside the loop, so the output gets flushed for
every mapping.

To make this a proper program for this use, it should read an entire
line up to and including the linebreak (which Eric also said). I think
gets or fgets will do the job just fine, and then if you want to use
scanf, you can use sscanf to scan the string that you read with fgets.
Second, you'll want some way to terminate the loop, so it doesn't run
forever. I'm not sure exactly how this is normally handled (or maybe
apache even forcibly kills the program when it's done, but that's
unlikely). My best guess would be if you read an EOF on standard
input, you can quit.

-Brian

--=20
Feel free to contact me using PGP Encryption:
Key Id: 0x3AA70848
Available from: http://keys.gnupg.net

------------------------------------------------------------ ---------
The official User-To-User support forum of the Apache HTTP Server Project.
See for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org

Re: RewriteMap PRG By Example Using C

am 29.04.2009 21:15:33 von ricardo figueiredo

--001e680f16fc52a0bd0468b6670b
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

Hi,

Good explanation !!!

But, How do you improve this C program ?

On Wed, Apr 29, 2009 at 3:09 PM, Brian Mearns wrote:

> On Wed, Apr 29, 2009 at 1:58 PM, ricardo figueiredo
> wrote:
> > Sorry,
> >
> > Let me explain my situation again.
> > I'm using directive RewriteMap using external rewriting program.
> > This program is developed in language C.
> >
> > When I require a page in the browser is shown an error (Bad Request 400).
> >
> > My program in C to rewriting URL
> >
> > #include
> > int main() {
> > int id = 0;
> > fscanf(stdin, "%d", &id);
> > switch(id) {
> > case 111: fprintf(stdout, "/index.html"); break;
> > case 222: fprintf(stdout, "/new.html"); break;
> > case 333: fprintf(stdout, "/teste.php?var=4/8"); break;
> > }
> >
> > fflush(stdout);
> > return 0;
> > }
> >
> > My httpd.conf is:
> >
> > RewriteEngine on
> > RewriteLock /usr/local/apache2/logs/file.lock
> > RewriteMap prgmap prg:/usr/local/apache2/file
> > RewriteRule ^/(.*) ${prgmap:$1}
> >
> > My rewritelog:
> >
> > [localhost/sid#8b4cd68][rid#8ce45a0/initial] (2) init rewrite engine with
> > requested uri /111
> > [localhost/sid#8b4cd68][rid#8ce45a0/initial] (3) applying pattern
> '^/(.*)'
> > to uri '/111'
> > [localhost/sid#8b4cd68][rid#8ce45a0/initial] (5) map lookup OK:
> map=prgmap
> > key=111 -> val=
> > [localhost/sid#8b4cd68][rid#8ce45a0/initial] (2) rewrite '/111' -> ''
> > [localhost/sid#8b4cd68][rid#8ce45a0/initial] (2) local path result:
> >
> > Why is this error ??
> >
> > I hope have given all information.
> >
> > Ricardo
> >
> >
>
> First of all, like Eric said yesterday, you need a loop in your main
> function. The program is not invoked every time the rewrite needs to
> be applied, it is started once when the Apache server starts, and just
> gets a new line of input for each request to be mapped.
>
> Second, you need to terminate your output with a newline. Apparently,
> apache gave up waiting for your program to give it a valid output (one
> that is terminated by a newline) and decided to go with an empty
> value, instead. Using fflush is probably a good idea, but you'll want
> to make sure it's inside the loop, so the output gets flushed for
> every mapping.
>
> To make this a proper program for this use, it should read an entire
> line up to and including the linebreak (which Eric also said). I think
> gets or fgets will do the job just fine, and then if you want to use
> scanf, you can use sscanf to scan the string that you read with fgets.
> Second, you'll want some way to terminate the loop, so it doesn't run
> forever. I'm not sure exactly how this is normally handled (or maybe
> apache even forcibly kills the program when it's done, but that's
> unlikely). My best guess would be if you read an EOF on standard
> input, you can quit.
>
> -Brian
>
> --
> Feel free to contact me using PGP Encryption:
> Key Id: 0x3AA70848
> Available from: http://keys.gnupg.net
>
> ------------------------------------------------------------ ---------
> The official User-To-User support forum of the Apache HTTP Server Project.
> See for more info.
> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
> " from the digest: users-digest-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org
>
>


--
Muito Obrigado

Ricardo

--001e680f16fc52a0bd0468b6670b
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

Hi,

Good explanation !!!

But, How do you improve this C progr=
am ?

On Wed, Apr 29, 2009 at 3:09 PM, Bri=
an Mearns <mearn=
s.b@gmail.com
>
wrote:

204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<=
div class=3D"h5">On Wed, Apr 29, 2009 at 1:58 PM, ricardo figueiredo

<ricardoogrande@gmail.com >> wrote:

> Sorry,

>

> Let me explain my situation again.

> I'm using directive RewriteMap using external rewriting program. r>
> This program is developed in language C.

>

> When I require a page in the browser is shown an error (Bad Request 40=
0).

>

> My program in C to rewriting URL

>

> #include <stdio.h>

> =A0 int main() {

> =A0 int id =3D 0;

>   =A0 fscanf(stdin, "%d", &id);

> =A0 =A0 switch(id) {

> =A0 =A0    case 111: fprintf(stdout, "/index.html");=A0 =
break;

> =A0 =A0    case 222: fprintf(stdout, "/new.html");=A0 br=
eak;

>        case 333: fprintf(stdout, "/teste.php?var=3D4/=
8"); break;

>   =A0 }

>

>   =A0 fflush(stdout);

>   =A0 return 0;

> }

>

> My httpd.conf is:

>

> =A0 RewriteEngine on

> =A0 RewriteLock /usr/local/apache2/logs/file.lock

> =A0 RewriteMap prgmap prg:/usr/local/apache2/file

> =A0 RewriteRule ^/(.*) ${prgmap:$1}

>

> My rewritelog:

>

> [localhost/sid#8b4cd68][rid#8ce45a0/initial] (2) init rewrite engine w=
ith

> requested uri /111

> [localhost/sid#8b4cd68][rid#8ce45a0/initial] (3) applying pattern '=
;^/(.*)'

> to uri '/111'

> [localhost/sid#8b4cd68][rid#8ce45a0/initial] (5) map lookup OK: map=3D=
prgmap

> key=3D111 -> val=3D

> [localhost/sid#8b4cd68][rid#8ce45a0/initial] (2) rewrite '/111'=
; -> ''

> [localhost/sid#8b4cd68][rid#8ce45a0/initial] (2) local path result: >
>

> Why is this error ??

>

> I hope have given all information.

>

> Ricardo

>

>



First of all, like Eric said yesterday, you need a loop in your=
main

function. The program is not invoked every time the rewrite needs to

be applied, it is started once when the Apache server starts, and just

gets a new line of input for each request to be mapped.



Second, you need to terminate your output with a newline. Apparently,

apache gave up waiting for your program to give it a valid output (one

that is terminated by a newline) and decided to go with an empty

value, instead. Using fflush is probably a good idea, but you'll want r>
to make sure it's inside the loop, so the output gets flushed for

every mapping.



To make this a proper program for this use, it should read an entire

line up to and including the linebreak (which Eric also said). I think

gets or fgets will do the job just fine, and then if you want to use

scanf, you can use sscanf to scan the string that you read with fgets.

Second, you'll want some way to terminate the loop, so it doesn't r=
un

forever. I'm not sure exactly how this is normally handled (or maybe >
apache even forcibly kills the program when it's done, but that's r>
unlikely). My best guess would be if you read an EOF on standard

input, you can quit.



-Brian



--

Feel free to contact me using PGP Encryption:

Key Id: 0x3AA70848

Available from:
http://=
keys.gnupg.net




------------------------------------------------------------ ---------

The official User-To-User support forum of the Apache HTTP Server Project.<=
br>
See <URL: lank">http://httpd.apache.org/userslist.html> for more info.

To unsubscribe, e-mail: g">users-unsubscribe@httpd.apache.org

=A0 " =A0 from the digest: @httpd.apache.org">users-digest-unsubscribe@httpd.apache.org

For additional commands, e-mail: org">users-help@httpd.apache.org






--
Muito Obrig=
ado

Ricardo


--001e680f16fc52a0bd0468b6670b--

Re: RewriteMap PRG By Example Using C

am 29.04.2009 21:17:45 von Sean Conner

It was thus said that the Great Brian Mearns once stated:
> On Wed, Apr 29, 2009 at 1:58 PM, ricardo figueiredo
> wrote:
> > Sorry,
> >
> > Let me explain my situation again.
> > I'm using directive RewriteMap using external rewriting program.
> > This program is developed in language C.
> >
> First of all, like Eric said yesterday, you need a loop in your main
> function. The program is not invoked every time the rewrite needs to
> be applied, it is started once when the Apache server starts, and just
> gets a new line of input for each request to be mapped.
>
> Second, you need to terminate your output with a newline. Apparently,
> apache gave up waiting for your program to give it a valid output (one
> that is terminated by a newline) and decided to go with an empty
> value, instead. Using fflush is probably a good idea, but you'll want
> to make sure it's inside the loop, so the output gets flushed for
> every mapping.
>
> To make this a proper program for this use, it should read an entire
> line up to and including the linebreak (which Eric also said). I think
> gets or fgets will do the job just fine, and then if you want to use
> scanf, you can use sscanf to scan the string that you read with fgets.
> Second, you'll want some way to terminate the loop, so it doesn't run
> forever. I'm not sure exactly how this is normally handled (or maybe
> apache even forcibly kills the program when it's done, but that's
> unlikely). My best guess would be if you read an EOF on standard
> input, you can quit.

Avoid gets() and use fgets(). Heck, the program is easy enough:

#include
#include

int main(int argc,char *argv[])
{
char input[BUFSIZ];
int id;

while(fgets(input,BUFSIZ,stdin) != NULL)
{
id = strtol(input,NULL,10);
switch(id)
{
case 111: fputs("/index.html",stdout); break;
case 222: fputs("/new.html",stdout); break;
case 333: fputs("/tests.php?var=4/8"); break;
default: fputs("/bogusrequest.html"); break;
}
fputc('\n',stdout);
fflush(stdout);
}
return EXIT_SUCCESS;
}

fgets() returns NULL on EOF, strtol() will do the conversion for you (I find
it easier to use than scanf() but that's me) and I even added a case for an
unexpected value.

-spc (Hope this helps)


------------------------------------------------------------ ---------
The official User-To-User support forum of the Apache HTTP Server Project.
See for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org

Re: RewriteMap PRG By Example Using C

am 29.04.2009 21:41:36 von ricardo figueiredo

--001e680f11a47353c90468b6c464
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

Hi,

spc (Hope this helps) ----- > Great !!!!

The external program's (in C) working !!!!! Wonderfull !!!

Thank you very much to Brian, Eric and Sean

Ricardo

On Wed, Apr 29, 2009 at 4:17 PM, Sean Conner wrote:

> It was thus said that the Great Brian Mearns once stated:
> > On Wed, Apr 29, 2009 at 1:58 PM, ricardo figueiredo
> > wrote:
> > > Sorry,
> > >
> > > Let me explain my situation again.
> > > I'm using directive RewriteMap using external rewriting program.
> > > This program is developed in language C.
> > >
> > First of all, like Eric said yesterday, you need a loop in your main
> > function. The program is not invoked every time the rewrite needs to
> > be applied, it is started once when the Apache server starts, and just
> > gets a new line of input for each request to be mapped.
> >
> > Second, you need to terminate your output with a newline. Apparently,
> > apache gave up waiting for your program to give it a valid output (one
> > that is terminated by a newline) and decided to go with an empty
> > value, instead. Using fflush is probably a good idea, but you'll want
> > to make sure it's inside the loop, so the output gets flushed for
> > every mapping.
> >
> > To make this a proper program for this use, it should read an entire
> > line up to and including the linebreak (which Eric also said). I think
> > gets or fgets will do the job just fine, and then if you want to use
> > scanf, you can use sscanf to scan the string that you read with fgets.
> > Second, you'll want some way to terminate the loop, so it doesn't run
> > forever. I'm not sure exactly how this is normally handled (or maybe
> > apache even forcibly kills the program when it's done, but that's
> > unlikely). My best guess would be if you read an EOF on standard
> > input, you can quit.
>
> Avoid gets() and use fgets(). Heck, the program is easy enough:
>
> #include
> #include
>
> int main(int argc,char *argv[])
> {
> char input[BUFSIZ];
> int id;
>
> while(fgets(input,BUFSIZ,stdin) != NULL)
> {
> id = strtol(input,NULL,10);
> switch(id)
> {
> case 111: fputs("/index.html",stdout); break;
> case 222: fputs("/new.html",stdout); break;
> case 333: fputs("/tests.php?var=4/8"); break;
> default: fputs("/bogusrequest.html"); break;
> }
> fputc('\n',stdout);
> fflush(stdout);
> }
> return EXIT_SUCCESS;
> }
>
> fgets() returns NULL on EOF, strtol() will do the conversion for you (I
> find
> it easier to use than scanf() but that's me) and I even added a case for an
> unexpected value.
>
> -spc (Hope this helps)
>
>
> ------------------------------------------------------------ ---------
> The official User-To-User support forum of the Apache HTTP Server Project.
> See for more info.
> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
> " from the digest: users-digest-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org
>
>


--
Muito Obrigado

Ricardo

--001e680f11a47353c90468b6c464
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

Hi,

spc (Hope this helps) ----- > Great !!!!

The external =
program's (in C) working !!!!! Wonderfull !!!

Thank you very muc=
h to Brian, Eric and Sean

Ricardo


On Wed, Apr 29, 2009 at 4:17 PM, Sean Conner < =3D"mailto:spc@conman.org">spc@conman.org> wrote:
ote class=3D"gmail_quote" style=3D"border-left: 1px solid rgb(204, 204, 204=
); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
It was thus said that the Great Brian Mearns once stated:

> On Wed, Apr 29, 2009 at 1:58 PM, ricardo figueiredo<=
br>
> <ricardoogrande@gmail.c=
om
> wrote:

> > Sorry,

> >

> > Let me explain my situation again.

> > I'm using directive RewriteMap using external rewriting progr=
am.

> > This program is developed in language C.

> >

> First of all, like Eric said yesterday, you ne=
ed a loop in your main

> function. The program is not invoked every time the rewrite needs to r>
> be applied, it is started once when the Apache server starts, and just=


> gets a new line of input for each request to be mapped.

>

> Second, you need to terminate your output with a newline. Apparently,<=
br>
> apache gave up waiting for your program to give it a valid output (one=


> that is terminated by a newline) and decided to go with an empty

> value, instead. Using fflush is probably a good idea, but you'll w=
ant

> to make sure it's inside the loop, so the output gets flushed for<=
br>
> every mapping.

>

> To make this a proper program for this use, it should read an entire r>
> line up to and including the linebreak (which Eric also said). I think=


> gets or fgets will do the job just fine, and then if you want to use r>
> scanf, you can use sscanf to scan the string that you read with fgets.=


> Second, you'll want some way to terminate the loop, so it doesn=
9;t run

> forever. I'm not sure exactly how this is normally handled (or may=
be

> apache even forcibly kills the program when it's done, but that=
9;s

> unlikely). My best guess would be if you read an EOF on standard

> input, you can quit.



=A0Avoid gets() and use fgets(). =A0Heck, the program is easy enough=
:



#include <stdio.h>

#include <stdlib.h>



int main(int argc,char *argv[])

{

=A0char input[BUFSIZ];

=A0int =A0id;



=A0while(fgets(input,BUFSIZ,stdin) !=3D NULL)

=A0{

=A0 =A0id =3D strtol(input,NULL,10);

=A0 =A0switch(id)

=A0 =A0{

=A0 =A0 =A0case 111: fputs("/index.html",stdout); break;

=A0 =A0 =A0case 222: fputs("/new.html",stdout); break;

=A0 =A0 =A0case 333: fputs("/tests.php?var=3D4/8"); break;

=A0 =A0 =A0default: =A0fputs("/bogusrequest.html"); break;

=A0 =A0}

=A0 =A0fputc('\n',stdout);

=A0 =A0fflush(stdout);

=A0}

=A0return EXIT_SUCCESS;

}



fgets() returns NULL on EOF, strtol() will do the conversion for you (I fin=
d

it easier to use than scanf() but that's me) and I even added a case fo=
r an

unexpected value.



=A0-spc (Hope this helps)





------------------------------------------------------------ ---------

The official User-To-User support forum of the Apache HTTP Server Project.<=
br>
See <URL: lank">http://httpd.apache.org/userslist.html> for more info.

To unsubscribe, e-mail: g">users-unsubscribe@httpd.apache.org

=A0 " =A0 from the digest: @httpd.apache.org">users-digest-unsubscribe@httpd.apache.org

For additional commands, e-mail: org">users-help@httpd.apache.org






--
Muito Obrig=
ado

Ricardo


--001e680f11a47353c90468b6c464--