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 2002/02/12 10:36:29 UTC
cvs commit: tcl-websh/src/generic url.h url.c
davidw 02/02/12 01:36:29
Modified: src/generic url.h url.c
Log:
* generic/url.c (Web_CmdUrlCfg): Change to use two variables for
'scheme' - one as a config, and one to hold the actual value.
Revision Changes Path
1.5 +3 -2 tcl-websh/src/generic/url.h
Index: url.h
===================================================================
RCS file: /home/cvs/tcl-websh/src/generic/url.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- url.h 22 Nov 2001 19:46:19 -0000 1.4
+++ url.h 12 Feb 2002 09:36:29 -0000 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.h,v 1.4 2001/11/22 19:46:19 davidw Exp $
+ * @(#) $Id: url.h,v 1.5 2002/02/12 09:36:29 davidw Exp $
*
*/
@@ -60,6 +60,7 @@
* ------------------------------------------------------------------- */
typedef struct UrlData
{
+ Tcl_Obj *defaultscheme; /* default scheme to use */
Tcl_Obj *scheme; /* e.g http */
Tcl_Obj *port; /* e.g. 8080 */
Tcl_Obj *host; /* e.g. www.netcetera.ch */
@@ -73,7 +74,7 @@
}
UrlData;
-UrlData *createUrlData(Tcl_Interp *interp);
+UrlData *createUrlData();
int resetUrlData(Tcl_Interp * interp, UrlData * urlData);
void destroyUrlData(ClientData clientData, Tcl_Interp * interp);
1.6 +45 -26 tcl-websh/src/generic/url.c
Index: url.c
===================================================================
RCS file: /home/cvs/tcl-websh/src/generic/url.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- url.c 22 Nov 2001 19:46:19 -0000 1.5
+++ url.c 12 Feb 2002 09:36:29 -0000 1.6
@@ -1,7 +1,7 @@
/*
* url.c -- url generation
* nca-073-9
- *
+ *
* Copyright (c) 1996-2000 by Netcetera AG.
* Copyright (c) 2001 by Apache Software Foundation.
* All rights reserved.
@@ -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.5 2001/11/22 19:46:19 davidw Exp $
+ * @(#) $Id: url.c,v 1.6 2002/02/12 09:36:29 davidw Exp $
*
*/
@@ -80,7 +80,7 @@
/* --------------------------------------------------------------------------
* new data
* ----------------------------------------------------------------------- */
- urlData = createUrlData(interp);
+ urlData = createUrlData();
/* --------------------------------------------------------------------------
* register commands
@@ -107,7 +107,7 @@
/* ----------------------------------------------------------------------------
* create
* ------------------------------------------------------------------------- */
-UrlData *createUrlData(Tcl_Interp *interp)
+UrlData *createUrlData()
{
UrlData *urlData = NULL;
@@ -115,14 +115,8 @@
urlData = WebAllocInternalData(UrlData);
if (urlData != NULL) {
- 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");
- }
+ urlData->defaultscheme = NULL;
+ urlData->scheme = NULL;
/* we want to read port from request if available */
/*WebNewStringObjFromStringIncr(urlData->port,WEB_DEFAULT_PORT); */
urlData->port = NULL;
@@ -144,21 +138,11 @@
* ------------------------------------------------------------------------- */
int resetUrlData(Tcl_Interp * interp, UrlData * urlData)
{
- char *https;
-
if ((interp == NULL) || (urlData == NULL))
return TCL_ERROR;
+ WebDecrRefCountIfNotNullAndSetNull(urlData->defaultscheme);
WebDecrRefCountIfNotNullAndSetNull(urlData->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 */
@@ -191,6 +175,7 @@
urlData = (UrlData *) clientData;
+ WebDecrRefCountIfNotNull(urlData->defaultscheme);
WebDecrRefCountIfNotNull(urlData->scheme);
WebDecrRefCountIfNotNull(urlData->port);
WebDecrRefCountIfNotNull(urlData->host);
@@ -653,9 +638,24 @@
res = Tcl_NewObj();
if ((urlformat & WEB_URL_WITH_SCHEME) != 0) {
- if (urlData->scheme != NULL) {
- Tcl_AppendObjToObj(res, urlData->scheme);
+ if (urlData->defaultscheme != NULL) {
+ Tcl_AppendObjToObj(res, urlData->defaultscheme);
Tcl_AppendToObj(res, WEBURL_SCHEME_SEP, -1);
+ } else {
+ Tcl_Obj *schemeObj = NULL;
+ char *scheme = NULL;
+ if( urlData->requestData != NULL ) {
+ schemeObj = paramListGetObjectByString(interp, urlData->requestData->request, "HTTPS");
+ if (schemeObj != NULL)
+ scheme = Tcl_GetString(schemeObj);
+ }
+ if (!strcmp(scheme, "on")) {
+ Tcl_AppendObjToObj(res, Tcl_NewStringObj("https", -1));
+ Tcl_AppendToObj(res, WEBURL_SCHEME_SEP, -1);
+ } else {
+ Tcl_AppendObjToObj(res, Tcl_NewStringObj(WEB_DEFAULT_SCHEME, -1));
+ Tcl_AppendToObj(res, WEBURL_SCHEME_SEP, -1);
+ }
}
}
@@ -803,7 +803,26 @@
switch ((enum urlElement) opt) {
case SCHEME:
WebAssertObjc(objc > 3, 2, "?value?");
- return handleConfig(interp, &urlData->scheme, tmpObj, 1);
+ if (urlData->defaultscheme != NULL) {
+ Tcl_SetObjResult(interp,
+ Tcl_DuplicateObj(urlData->defaultscheme));
+ if (tmpObj != NULL) {
+ Tcl_DecrRefCount(urlData->defaultscheme);
+ urlData->defaultscheme = Tcl_DuplicateObj(tmpObj);
+ }
+ return TCL_OK;
+ } else {
+ Tcl_SetObjResult(interp,
+ Tcl_NewStringObj(WEB_DEFAULT_SCHEME, -1));
+ if (tmpObj != NULL) {
+ if (!strcmp(Tcl_GetString(tmpObj), "")) {
+ urlData->defaultscheme = NULL;
+ } else {
+ urlData->defaultscheme = Tcl_DuplicateObj(tmpObj);
+ }
+ }
+ return TCL_OK;
+ }
break;
case HOST:
WebAssertObjc(objc > 3, 2, "?value?");
---------------------------------------------------------------------
To unsubscribe, e-mail: websh-cvs-unsubscribe@tcl.apache.org
For additional commands, e-mail: websh-cvs-help@tcl.apache.org