From 1950255624d9b77827fa836c4d28b89620aa4575 Mon Sep 17 00:00:00 2001
From: Carlos Ghan <charlie.brown.uy@gmail.com>
Date: Mon, 26 Jul 2010 17:49:49 -0300
Subject: [PATCH] Add virtual-host aliases support

---
 lang/en/sites/default |    7 +++++++
 src/config.c          |   17 ++++++++++++++++-
 src/include/config.h  |    1 +
 3 files changed, 24 insertions(+), 1 deletions(-)

diff --git a/lang/en/sites/default b/lang/en/sites/default
index 649518d..ea276cf 100644
--- a/lang/en/sites/default
+++ b/lang/en/sites/default
@@ -13,6 +13,13 @@ cat > conf/sites/default <<EOF
 
     ServerName 127.0.0.1
 
+    # Aliases:
+    # --------
+    # Additional names (aliases) associated with this file's ServerName.
+    #
+    # Example:
+    #       Aliases development testing main
+
     # DocumentRoot :
     # -------------
     # This variable corresponds to the location of the main server directory
diff --git a/src/config.c b/src/config.c
index 4fa7c46..57c8f34 100644
--- a/src/config.c
+++ b/src/config.c
@@ -567,6 +567,9 @@ struct host *mk_config_get_host(char *path)
     host->servername = mk_config_section_getval(section, "Servername", 
                                                 MK_CONFIG_VAL_STR);
 
+    host->aliases = mk_config_section_getval(section, "Aliases",
+                                                MK_CONFIG_VAL_LIST);
+
     /* document root handled by a mk_pointer */
     host->documentroot.data = mk_config_section_getval(section,
                                                        "DocumentRoot",
@@ -677,13 +680,25 @@ void mk_config_start_configure(void)
 struct host *mk_config_host_find(mk_pointer host)
 {
     struct host *aux_host;
+    struct mk_string_line *alias;
 
     aux_host = config->hosts;
 
     while (aux_host) {
         if (strncasecmp(aux_host->servername, host.data, host.len) == 0) {
             return aux_host;
-        }
+        } else if (aux_host->aliases)
+            for (alias = aux_host->aliases; alias; alias = alias->next) {
+                char *a_name = mk_string_copy_substr(alias->val, 0, alias->len);
+
+                if (strncasecmp(a_name, host.data, host.len) == 0) {
+                    mk_mem_free(a_name);
+                    return aux_host;
+                }
+
+                mk_mem_free(a_name);
+            }
+
         aux_host = aux_host->next;
     }
 
diff --git a/src/include/config.h b/src/include/config.h
index 624ef0b..202c923 100644
--- a/src/include/config.h
+++ b/src/include/config.h
@@ -128,6 +128,7 @@ struct host
 {
     char *file;                 /* configuration file */
     char *servername;           /* host name */
+    struct mk_string_line *aliases;    /* host aliases */
     mk_pointer documentroot;
 
     char *access_log_path;      /* access log file */
-- 
1.7.0.4


