You are viewing a plain text version of this content. The canonical link for it is here.
Posted to websh-cvs@tcl.apache.org by da...@apache.org on 2001/11/22 20:46:19 UTC

cvs commit: tcl-websh/src/generic url.c url.h

davidw      01/11/22 11:46:19

  Modified:    src/generic url.c url.h
  Log:
  * generic/url.c (createUrlData): First cut at making cmdurl scheme
  switch between https and http depending on environmental variables.
  
  Revision  Changes    Path
  1.5       +21 -6     tcl-websh/src/generic/url.c
  
  Index: url.c
  ===================================================================
  RCS file: /home/cvs/tcl-websh/src/generic/url.c,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- url.c	2001/11/20 13:55:05	1.4
  +++ url.c	2001/11/22 19:46:19	1.5
  @@ -9,7 +9,7 @@
    * See the file "license.terms" for information on usage and
    * redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
    *
  - * @(#) $Id: url.c,v 1.4 2001/11/20 13:55:05 davidw Exp $
  + * @(#) $Id: url.c,v 1.5 2001/11/22 19:46:19 davidw Exp $
    *
    */
   
  @@ -80,7 +80,7 @@
       /* --------------------------------------------------------------------------
        * new data
        * ----------------------------------------------------------------------- */
  -    urlData = createUrlData();
  +    urlData = createUrlData(interp);
   
       /* --------------------------------------------------------------------------
        * register commands
  @@ -107,7 +107,7 @@
   /* ----------------------------------------------------------------------------
    * create
    * ------------------------------------------------------------------------- */
  -UrlData *createUrlData(void)
  +UrlData *createUrlData(Tcl_Interp *interp)
   {
   
       UrlData *urlData = NULL;
  @@ -115,8 +115,14 @@
       urlData = WebAllocInternalData(UrlData);
   
       if (urlData != NULL) {
  -
  -	WebNewStringObjFromStringIncr(urlData->scheme, WEB_DEFAULT_SCHEME);
  +	char *https = Tcl_GetVar2(interp, "env", "HTTPS", 0);
  +	
  +	if (https == NULL || strcmp(https, "on"))
  +	{
  +	    WebNewStringObjFromStringIncr(urlData->scheme, WEB_DEFAULT_SCHEME);
  +	} else {
  +	    WebNewStringObjFromStringIncr(urlData->scheme, "https");
  +	}
   	/* we want to read port from request if available */
   	/*WebNewStringObjFromStringIncr(urlData->port,WEB_DEFAULT_PORT); */
   	urlData->port = NULL;
  @@ -138,12 +144,21 @@
    * ------------------------------------------------------------------------- */
   int resetUrlData(Tcl_Interp * interp, UrlData * urlData)
   {
  +    char *https;
   
       if ((interp == NULL) || (urlData == NULL))
   	return TCL_ERROR;
   
       WebDecrRefCountIfNotNullAndSetNull(urlData->scheme);
  -    WebNewStringObjFromStringIncr(urlData->scheme, WEB_DEFAULT_SCHEME);
  +    
  +    https = Tcl_GetVar2(interp, "env", "HTTPS", 0);
  +    
  +    if (https == NULL || strcmp(https, "on"))
  +    {
  +	WebNewStringObjFromStringIncr(urlData->scheme, WEB_DEFAULT_SCHEME);
  +    } else {
  +	WebNewStringObjFromStringIncr(urlData->scheme, "https");
  +    }
   
       WebDecrRefCountIfNotNullAndSetNull(urlData->port);
       /* we want to read port from request if available */
  
  
  
  1.4       +2 -2      tcl-websh/src/generic/url.h
  
  Index: url.h
  ===================================================================
  RCS file: /home/cvs/tcl-websh/src/generic/url.h,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- url.h	2001/10/25 17:50:13	1.3
  +++ url.h	2001/11/22 19:46:19	1.4
  @@ -9,7 +9,7 @@
    * See the file "license.terms" for information on usage and
    * redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
    *
  - * @(#) $Id: url.h,v 1.3 2001/10/25 17:50:13 davidw Exp $
  + * @(#) $Id: url.h,v 1.4 2001/11/22 19:46:19 davidw Exp $
    *
    */
   
  @@ -73,7 +73,7 @@
   }
   UrlData;
   
  -UrlData *createUrlData(void);
  +UrlData *createUrlData(Tcl_Interp *interp);
   int resetUrlData(Tcl_Interp * interp, UrlData * urlData);
   void destroyUrlData(ClientData clientData, Tcl_Interp * interp);
   
  
  
  

Re: cvs commit: tcl-websh/src/generic url.c url.h

Posted by "David N. Welton" <da...@dedasys.com>.
I have entered this as a new bug in the bugzilla system...

-- 
David N. Welton
   Consulting: http://www.dedasys.com/
Free Software: http://people.debian.org/~davidw/
   Apache Tcl: http://tcl.apache.org/
     Personal: http://www.efn.org/~davidw/

Re: cvs commit: tcl-websh/src/generic url.c url.h

Posted by "David N. Welton" <da...@dedasys.com>.
davidw@dedasys.com (David N. Welton) writes:

> How about this:
 
> by default, urlData->scheme is not filled in, leaving it as a config
> option, which does fill it in.
 
> At 'runtime' (when cmdurl is run), it then either fills it in with
> 1) the config option (takes precedence) 2) https, if that's found
> amongst the environmental variables, or 3) the default.

> A bit more calculation each time around, but it does keep the code
> simpler in other places, and makes the calculation at the correct
> time for mod_websh (which it wasn't for my original code).

Well, I've written this code, and it does work.  The problem is that

    lappend res [web::cmdurlcfg -scheme]

doesn't work any longer.

So... hrm...we could put some options in there (like 'default') but
that starts to get complicated and messy.

Maybe something like web::cmdurlcfg -schemeswitching on/off ?

-- 
David N. Welton
   Consulting: http://www.dedasys.com/
Free Software: http://people.debian.org/~davidw/
   Apache Tcl: http://tcl.apache.org/
     Personal: http://www.efn.org/~davidw/

Re: cvs commit: tcl-websh/src/generic url.c url.h

Posted by "David N. Welton" <da...@dedasys.com>.
How about this:

by default, urlData->scheme is not filled in, leaving it as a config
option, which does fill it in.

At 'runtime' (when cmdurl is run), it then either fills it in with 1)
the config option (takes precedence) 2) https, if that's found amongst
the environmental variables, or 3) the default.

A bit more calculation each time around, but it does keep the code
simpler in other places, and makes the calculation at the correct time
for mod_websh (which it wasn't for my original code).

Sound ok?
-- 
David N. Welton
   Consulting: http://www.dedasys.com/
Free Software: http://people.debian.org/~davidw/
   Apache Tcl: http://tcl.apache.org/
     Personal: http://www.efn.org/~davidw/

Re: cvs commit: tcl-websh/src/generic url.c url.h

Posted by "David N. Welton" <da...@dedasys.com>.
Simon Hefti <he...@netcetera.ch> writes:

> > That's a good idea, but what's to prevent us from just filling in
> > the 'env' array, so that people can see these variables from the
> > user level as well?  That's what I do in mod_dtcl/rivet, and the
> > NWS guys do as well.
 
> The env array _is_ available, but through the web::request accessor.

Ok.

> Two reasons for this:
> - use common interface (like web::formvar, web::param, ...)
>   no catch {} needed around set foo $env(doesnotexist)
> - make people mod_websh aware

Sure, makes sense...  

So I guess the second thing I see is the whole param* series of
commands.  Is it possible to use this as an API?  Investigating now...

-- 
David N. Welton
   Consulting: http://www.dedasys.com/
Free Software: http://people.debian.org/~davidw/
   Apache Tcl: http://tcl.apache.org/
     Personal: http://www.efn.org/~davidw/

Re: cvs commit: tcl-websh/src/generic url.c url.h

Posted by Simon Hefti <he...@netcetera.ch>.
David,

> That's a good idea, but what's to prevent us from just filling in the
> 'env' array, so that people can see these variables from the user
> level as well?  That's what I do in mod_dtcl/rivet, and the NWS guys
> do as well.

The env array _is_ available, but through the web::request accessor.
Two reasons for this:
- use common interface (like web::formvar, web::param, ...)
  no catch {} needed around set foo $env(doesnotexist)
- make people mod_websh aware

Simon.

------------------------------------------------------------------------
Simon Hefti                                     simon.hefti@netcetera.ch
Netcetera AG, 8040 Zuerich    phone +41 1 247 79 47  fax +41 1 247 70 75



Re: cvs commit: tcl-websh/src/generic url.c url.h

Posted by "David N. Welton" <da...@dedasys.com>.
Simon Hefti <he...@netcetera.ch> writes:

> please keep in mind that with mod_websh, you will not find HTTP
> headers in the environment.

Would it make sense to put them there?  If I were writing an
application that I subsequently decided to run under mod_websh, I
would find the absence of these a bit irritating.

> I think you should use an accessor to be websh/mod_websh
> independent.  I thought that we have such an accessor at C level,
> but that seems not to be true. Just to explain the concept (I assume
> you realized that long ago, but anyway):

> - foo.h     declares the "interface"
> - foo_ap.c  provides the implementation in the mod_websh case
> - foo_cgi.c provides the implementation for the websh case
> - foo.c     implements common parts

> In this example, the method "requestFillRequestValues" is
> implemented both in request_ap.c and request_cgi.c.

> So, I think what we will need is something like
> Tcl_Obj *getHttpHeader(Tcl_Obj *key) {}
> abd use this instead of
> >   +	char *https = Tcl_GetVar2(interp, "env", "HTTPS", 0);

> What do you think ?

That's a good idea, but what's to prevent us from just filling in the
'env' array, so that people can see these variables from the user
level as well?  That's what I do in mod_dtcl/rivet, and the NWS guys
do as well.

-- 
David N. Welton
   Consulting: http://www.dedasys.com/
Free Software: http://people.debian.org/~davidw/
   Apache Tcl: http://tcl.apache.org/
     Personal: http://www.efn.org/~davidw/

Re: cvs commit: tcl-websh/src/generic url.c url.h

Posted by Simon Hefti <he...@netcetera.ch>.
David,

please keep in mind that with mod_websh, you will not find HTTP
headers in the environment.

I think you should use an accessor to be websh/mod_websh independent.
I thought that we have such an accessor at C level, but that seems not
to be true. Just to explain the concept (I assume you realized that
long ago, but anyway):

- foo.h     declares the "interface"
- foo_ap.c  provides the implementation in the mod_websh case
- foo_cgi.c provides the implementation for the websh case
- foo.c     implements common parts

In this example, the method "requestFillRequestValues" is implemented
both in request_ap.c and request_cgi.c.

So, I think what we will need is something like
Tcl_Obj *getHttpHeader(Tcl_Obj *key) {}
abd use this instead of
>   +	char *https = Tcl_GetVar2(interp, "env", "HTTPS", 0);

What do you think ?

Simon.

------------------------------------------------------------------------
Simon Hefti                                     simon.hefti@netcetera.ch
Netcetera AG, 8040 Zuerich    phone +41 1 247 79 47  fax +41 1 247 70 75