[aseek-devel] Small bug fix for sc.c -- patch against 1.2.9pre

From: Matt Sullivan (no email)
Date: Tue Mar 12 2002 - 23:32:21 EST


Hi,

Attached fixes problem where script name has no suffix (exacerbated by addition
of host to script_name) also removes prepending of hostname to script_name (not
removed in mod_aspseek although it should be optional here also).

Script name should be script name.

If hostname addition is desired then this should be an option.

e.g. of problem when forming template filename:

  http://www.hostname.com/cgi-bin/search

    script_name -> http://www.hostname.com/cgi-bin/search
    remove suffix -> http://www.hostname
    remove to '/' -> /www.hostname
    add '.htm' -> /www.hostname.htm

should have been '/search.htm' !!!!

Previously this did not happen since script_name would always have been
calculated as '/cgi-bin/search'.

Matt.

diff -ruN aspseek-1.2.9pre.orig/src/sc.c aspseek-1.2.9pre/src/sc.c
--- aspseek-1.2.9pre.orig/src/sc.c Tue Feb 26 00:33:14 2002
+++ aspseek-1.2.9pre/src/sc.c Wed Mar 13 17:07:06 2002
@@ -121,7 +121,7 @@
 
 char *get_script()
 {
- char *env, *host;
+ char *env;
         
         if (script_cached)
         {
@@ -133,29 +133,15 @@
                 {
                         /* Check Apache internal redirect
                          * via "AddHandler" and "Action" */
- if( (env = getenv("REDIRECT_URL")))
- {
- safe_strcpy(script_name, env);
- }
- else
- {
- safe_strcpy(script_name, "s.cgi");
- }
+ env = getenv("REDIRECT_URL");
+ snprintf(script_name, sizeof(script_name),
+ "%s", env ? env : "");
                 }
                 if (!script_name[0])
                 {
                         env = getenv("SCRIPT_NAME");
- if ((host = getenv("HTTP_HOST")))
- {
- snprintf(script_name, sizeof(script_name),
- "http://%s%s", host,
- env ? env : "/cgi-bin/s.cgi");
- }
- else
- {
- snprintf(script_name, sizeof(script_name),
- "%s", env ? env : "/cgi-bin/s.cgi");
- }
+ snprintf(script_name, sizeof(script_name),
+ "%s", env ? env : "/cgi-bin/s.cgi");
                 }
                 script_cached = 1;
                 return script_name;
@@ -222,7 +208,6 @@
 int main(int argc, char** argv)
 {
         char templ[STRSIZ] = "";
- char host[STRSIZ] = "";
         char *env;
 
         /* Don't forget to init 'arg' static var */
@@ -239,33 +224,28 @@
                 safe_strcpy(templ, env);
         }
 
- if(!templ[0])
- {
- if ((env = getenv("REDIRECT_STATUS")))
- {
- /* Check Apache internal redirect
- * via "AddHandler" and "Action" */
- env = getenv("PATH_TRANSLATED");
- safe_strcpy(templ, env ? env : "");
- }
- }
+ /* Try to determine script name */
+ get_script();
         
- /* Try to determine script name and template name if still not known
- * As for template name, some.cgi should use some.htm */
- safe_strcpy(host, get_script());
-
         if (!templ[0])
         {
- if (host)
+ /* Try to determine template name if still not known */
+ /* As for template name, some.cgi should use some.htm */
+ char sname[STRSIZ] = "";
+ safe_strcpy(sname, get_script());
+ if (sname[0])
                 {
                         /* we got name of CGI */
- char *s;
- /* remove .ext */
- if ((s = strrchr(host, '.')))
- *s = '\0';
+ char *s, *r;
                         /* remove path */
- if (!(s = strrchr(host, '/')))
- s = host;
+ /* We do this FIRST since script_name may not have an extension! -matt */
+ if (!(s = strrchr(sname, '/')))
+ s = sname;
+ if (s[0] == '/')
+ s++;
+ /* remove .ext */
+ if ((r = strrchr(s, '.')))
+ *r = '\0';
                         snprintf(templ, sizeof(templ),
                                 "%s/%s.htm", CONF_DIR, s);
                 }








Hosted Email Solutions

Invaluement Anti-Spam DNSBLs



Powered By FreeBSD   Powered By FreeBSD