Roxen.git / server / etc / modules / Roxen.pmod

version» Context lines:

Roxen.git/server/etc/modules/Roxen.pmod:1:   // This is a roxen pike module. Copyright © 1999 - 2009, Roxen IS.   // - // $Id: Roxen.pmod,v 1.285 2009/12/04 13:59:57 mast Exp $ + // $Id: Roxen.pmod,v 1.286 2010/03/04 15:54:58 grubba Exp $      #include <roxen.h>   #include <config.h>   #include <version.h>   #include <module.h>   #include <stat.h>   #define roxen roxenp()      #ifdef HTTP_DEBUG   # define HTTP_WERR(X) report_debug("HTTP: "+X+"\n");
Roxen.git/server/etc/modules/Roxen.pmod:4629:   //!   //! @note   //! If there is a @[RequestID] object available, you probably want to   //! call @[RequestID.url_base] in it instead, since that function also   //! takes into account information sent by the client and the port the   //! request came from. (It's often faster too.)   {    return c->get_url();   }    + static private array(string) local_addrs; +    string get_world(array(string) urls) {    if(!sizeof(urls)) return 0;       string url = urls[0];    mapping(string:Standards.URI) uris = ([ ]);    foreach (urls, string u)    uris[u] = Standards.URI(u);       foreach( ({"http:","https:","ftp:"}), string p)    foreach(urls, string u)    if (has_prefix(u, p)) {    uris[u]->fragment = 0;    url = (string) uris[u];    uris[url] = uris[u];    break;    }    -  +  Standards.URI uri = uris[url]; +  string server = uri->host; +  if (server == "::") +  server = "*"; +  if (!has_value(server, "*")) return (string)uri; +  +  // The host part of the URL is a glob. +  // Lets find some suitable hostnames and IPs to match it against. +     array hosts=({ gethostname() }), dns; -  +    #ifndef NO_DNS    catch(dns=roxen->gethostbyname(hosts[0]));    if(dns && sizeof(dns))    hosts+=dns[2]+dns[1]; -  +  if (!local_addrs) { +  string ifconfig = +  Process.locate_binary(({ "/sbin", "/usr/sbin", "/bin", "/usr/bin", +  "/etc" }), "ifconfig"); +  local_addrs = dns[1]; +  if (ifconfig) { +  foreach(Process.run(({ ifconfig, "-a" }))->stdout/"\n", string line) { +  int i; +  +  // We need to parse lines with the following formats: +  // +  // IPv4: +  // inet 127.0.0.1 Solaris, MacOS X. +  // inet addr:127.0.0.1 Linux. +  // +  // IPv6: +  // inet6 ::1 MacOS X. +  // inet6 ::1/128 Solaris. +  // inet6 addr: ::1/128 Linux, note the space! +  // inet6 fe80::ffff/10 Solaris. +  // inet6 fe80::ffff%en0 MacOS X, note the suffix! +  // inet6 addr: fe80::ffff/64 Linux, note the space! +  while ((i = search(line, "inet")) >= 0) { +  line = line[i..]; +  string addr; +  if (has_prefix(line, "inet ")) { +  line = line[5..]; +  } else if (has_prefix(line, "inet6 ")) { +  line = line[6..]; +  } +  if (has_prefix(line, "addr: ")) { +  line = line[6..]; +  } else if (has_prefix(line, "addr:")) { +  line = line[5..]; +  } +  sscanf(line, "%[^ ]%s", addr, line); +  if (addr && sizeof(addr)) { +  addr = (addr/"/")[0]; // We don't care about the prefix bits. +  addr = (addr/"%")[0]; // MacOS X. +  local_addrs += ({ addr }); +  } +  } +  } +  local_addrs = Array.uniq(local_addrs); +  } +  foreach(local_addrs, string addr) { +  if ((dns = Protocols.DNS.gethostbyaddr(addr)) && sizeof(dns)) { +  if (dns[0]) { +  hosts += ({ dns[0] }); +  } +  hosts += dns[1] + ({ addr }); +  if ((sizeof(dns[2]) != 1) || (dns[2][0] != addr)) { +  hosts += dns[2]; +  } +  } +  } +  hosts = Array.uniq(hosts); +  // werror("Hosts: %O\n", hosts); +  }   #endif /* !NO_DNS */    -  Standards.URI uri = uris[url]; -  string server = uri->host; -  if (server == "::") -  server = "*"; +     foreach(hosts, string host) -  if (glob(server, host)) +  if (glob(server, host)) {    uri->host = host; -  +  break; +  }    return (string) uri;   }      RoxenModule get_owning_module (object|function thing)   //! Tries to find out which module the thing belongs to, if any. The   //! thing can be e.g. a module object, a Tag object or a simple_tag   //! callback.   {    if (functionp (thing))    thing = function_object (thing);