Ticket #2: Add-virtual-host-aliases-support.patch

File Add-virtual-host-aliases-support.patch, 2.7 KB (added by charlie_brown, 22 months ago)

Add support for aliases

  • lang/en/sites/default

    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 b cat > conf/sites/default <<EOF 
    1313 
    1414    ServerName 127.0.0.1 
    1515 
     16    # Aliases: 
     17    # -------- 
     18    # Additional names (aliases) associated with this file's ServerName. 
     19    # 
     20    # Example: 
     21    #       Aliases development testing main 
     22 
    1623    # DocumentRoot : 
    1724    # ------------- 
    1825    # This variable corresponds to the location of the main server directory 
  • src/config.c

    diff --git a/src/config.c b/src/config.c
    index 4fa7c46..57c8f34 100644
    a b struct host *mk_config_get_host(char *path) 
    567567    host->servername = mk_config_section_getval(section, "Servername",  
    568568                                                MK_CONFIG_VAL_STR); 
    569569 
     570    host->aliases = mk_config_section_getval(section, "Aliases", 
     571                                                MK_CONFIG_VAL_LIST); 
     572 
    570573    /* document root handled by a mk_pointer */ 
    571574    host->documentroot.data = mk_config_section_getval(section, 
    572575                                                       "DocumentRoot", 
    void mk_config_start_configure(void) 
    677680struct host *mk_config_host_find(mk_pointer host) 
    678681{ 
    679682    struct host *aux_host; 
     683    struct mk_string_line *alias; 
    680684 
    681685    aux_host = config->hosts; 
    682686 
    683687    while (aux_host) { 
    684688        if (strncasecmp(aux_host->servername, host.data, host.len) == 0) { 
    685689            return aux_host; 
    686         } 
     690        } else if (aux_host->aliases) 
     691            for (alias = aux_host->aliases; alias; alias = alias->next) { 
     692                char *a_name = mk_string_copy_substr(alias->val, 0, alias->len); 
     693 
     694                if (strncasecmp(a_name, host.data, host.len) == 0) { 
     695                    mk_mem_free(a_name); 
     696                    return aux_host; 
     697                } 
     698 
     699                mk_mem_free(a_name); 
     700            } 
     701 
    687702        aux_host = aux_host->next; 
    688703    } 
    689704 
  • src/include/config.h

    diff --git a/src/include/config.h b/src/include/config.h
    index 624ef0b..202c923 100644
    a b struct host 
    128128{ 
    129129    char *file;                 /* configuration file */ 
    130130    char *servername;           /* host name */ 
     131    struct mk_string_line *aliases;    /* host aliases */ 
    131132    mk_pointer documentroot; 
    132133 
    133134    char *access_log_path;      /* access log file */