httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael Douglass <miked...@texas.net>
Subject solution to 'mod_rewrite.c wierdness' => mod_dir.c
Date Thu, 22 Jan 1998 05:06:53 GMT

Okay, after spending more time than I should have folloing Brian's
suggestions I finally read what Dead said right here:

> > That redirect isn't going away ... that's the one that makes directories
> > work, it's generated by mod_dir.  Why do you think that redirect is in

In fact, I read this as I was getting ready to ask for a kind finger
pointing me to the offending file that was generating this redirect...
Then I found it. :)  Now, here is what I've done to fix problem I
was having with this redirect--note that it required modifying
mod_dir.c, mod_imap.c, util.c, and httpd.h.

The first thing I had to do was locate the offending redirect.
After I found that I discovered that it was not going to be as
simple as changing that one section of code; but I had to change
a function it was calling.

Now, I'll leave it up to the apache people to decide if this is
worthy of adding to the base; but basically I took the construct_url
function and made it slightly more intelligent so that it will use
r->hostname over r->servername if it is available.  In order to do
this, I had to make construct_url take a request_rec instead of a
server_rec; this wasn't too big of a biggie as only mod_dir and
mod_imap was employing this functionality.

Here's my patch; If anyone can spot anything that they think will
break I'd be very appreciative to know.  And if Dean (et al) would
give it a once over, this is a 'feature' that I really would like
to see incorporated into the mainstream apache.

===================================================================
RCS file: RCS/httpd.h,v
retrieving revision 1.1
diff -c -r1.1 httpd.h
*** /tmp/T0Th2TH_       Wed Jan 21 23:06:20 1998
--- httpd.h     Wed Jan 21 22:55:56 1998
***************
*** 681,687 ****
  #define escape_uri(ppool,path) os_escape_path(ppool,path,1)
  extern char *escape_html(pool *p, const char *s);
  char *construct_server(pool *p, const char *hostname, unsigned port);
! char *construct_url (pool *p, const char *path, const server_rec *s);
  char *escape_shell_cmd (pool *p, const char *s);

  int count_dirs(const char *path);
--- 681,687 ----
  #define escape_uri(ppool,path) os_escape_path(ppool,path,1)
  extern char *escape_html(pool *p, const char *s);
  char *construct_server(pool *p, const char *hostname, unsigned port);
! char *construct_url (pool *p, const char *path, const request_rec *r);
  char *escape_shell_cmd (pool *p, const char *s);

  int count_dirs(const char *path);
===================================================================
RCS file: RCS/mod_dir.c,v
retrieving revision 1.1
diff -c -r1.1 mod_dir.c
*** /tmp/T0Th2TH_       Wed Jan 21 23:06:20 1998
--- mod_dir.c   Wed Jan 21 22:51:52 1998
***************
*** 810,816 ****
                         "/", NULL);

        table_set (r->headers_out, "Location",
!                  construct_url(r->pool, ifile, r->server));
        return HTTP_MOVED_PERMANENTLY;
      }

--- 810,816 ----
                         "/", NULL);

        table_set (r->headers_out, "Location",
!                  construct_url(r->pool, ifile, r));
        return HTTP_MOVED_PERMANENTLY;
      }

===================================================================
RCS file: RCS/mod_imap.c,v
retrieving revision 1.1
diff -c -r1.1 mod_imap.c
*** /tmp/T0Th2TH_       Wed Jan 21 23:06:21 1998
--- mod_imap.c  Wed Jan 21 22:52:25 1998
***************
*** 381,387 ****
      char *my_base;

      if (!strcasecmp(value, "map") || !strcasecmp(value, "menu")) {
!       return construct_url(r->pool, r->uri, r->server);
      }

      if (!strcasecmp(value, "nocontent") || !strcasecmp(value, "error")) {
--- 381,387 ----
      char *my_base;

      if (!strcasecmp(value, "map") || !strcasecmp(value, "menu")) {
!       return construct_url(r->pool, r->uri, r);
      }

      if (!strcasecmp(value, "nocontent") || !strcasecmp(value, "error")) {
***************
*** 417,423 ****
            return pstrdup(r->pool, value); /* no base: use what is given */
          }
        /* no base, no value: pick a simple default */
!       return construct_url(r->pool, "/", r->server);
      }

      /* must be a relative URL to be combined with base */
--- 417,423 ----
            return pstrdup(r->pool, value); /* no base: use what is given */
          }
        /* no base, no value: pick a simple default */
!       return construct_url(r->pool, "/", r);
      }

      /* must be a relative URL to be combined with base */
===================================================================
RCS file: RCS/util.c,v
retrieving revision 1.1
diff -c -r1.1 util.c
*** /tmp/T0Th2TH_       Wed Jan 21 23:06:21 1998
--- util.c      Wed Jan 21 22:51:22 1998
***************
*** 808,816 ****
      }
  }

! char *construct_url(pool *p, const char *uri, const server_rec *s) {
      return pstrcat (p, "http://",
!                   construct_server(p, s->server_hostname, s->port),
                    uri, NULL);
  }

--- 808,818 ----
      }
  }

! char *construct_url(pool *p, const char *uri, const request_rec *r) {
      return pstrcat (p, "http://",
!                   construct_server(p, r->hostname ? r->hostname :
!                                      r->server->server_hostname,
!                                      r->server->port),
                    uri, NULL);
  }


-- 
Michael Douglass
Texas Networking, Inc.

<tnet admin> anyway, I'm off, perl code is making me [a] crosseyed toady

Mime
View raw message