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 |
| 13 | 13 | |
| 14 | 14 | ServerName 127.0.0.1 |
| 15 | 15 | |
| | 16 | # Aliases: |
| | 17 | # -------- |
| | 18 | # Additional names (aliases) associated with this file's ServerName. |
| | 19 | # |
| | 20 | # Example: |
| | 21 | # Aliases development testing main |
| | 22 | |
| 16 | 23 | # DocumentRoot : |
| 17 | 24 | # ------------- |
| 18 | 25 | # 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
|
b
|
struct host *mk_config_get_host(char *path) |
| 567 | 567 | host->servername = mk_config_section_getval(section, "Servername", |
| 568 | 568 | MK_CONFIG_VAL_STR); |
| 569 | 569 | |
| | 570 | host->aliases = mk_config_section_getval(section, "Aliases", |
| | 571 | MK_CONFIG_VAL_LIST); |
| | 572 | |
| 570 | 573 | /* document root handled by a mk_pointer */ |
| 571 | 574 | host->documentroot.data = mk_config_section_getval(section, |
| 572 | 575 | "DocumentRoot", |
| … |
… |
void mk_config_start_configure(void) |
| 677 | 680 | struct host *mk_config_host_find(mk_pointer host) |
| 678 | 681 | { |
| 679 | 682 | struct host *aux_host; |
| | 683 | struct mk_string_line *alias; |
| 680 | 684 | |
| 681 | 685 | aux_host = config->hosts; |
| 682 | 686 | |
| 683 | 687 | while (aux_host) { |
| 684 | 688 | if (strncasecmp(aux_host->servername, host.data, host.len) == 0) { |
| 685 | 689 | 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 | |
| 687 | 702 | aux_host = aux_host->next; |
| 688 | 703 | } |
| 689 | 704 | |
diff --git a/src/include/config.h b/src/include/config.h
index 624ef0b..202c923 100644
|
a
|
b
|
struct host |
| 128 | 128 | { |
| 129 | 129 | char *file; /* configuration file */ |
| 130 | 130 | char *servername; /* host name */ |
| | 131 | struct mk_string_line *aliases; /* host aliases */ |
| 131 | 132 | mk_pointer documentroot; |
| 132 | 133 | |
| 133 | 134 | char *access_log_path; /* access log file */ |