| 137 | static int alias_matches(const char *uri, const char *alias_fakename); |
| 138 | |
| 139 | static const char *add_alias_internal(cmd_parms *cmd, void *dummy, |
| 140 | const char *fake, const char *real, |
| 141 | int use_regex) |
| 142 | { |
| 143 | server_rec *s = cmd->server; |
| 144 | alias_server_conf *conf = ap_get_module_config(s->module_config, |
| 145 | &alias_module); |
| 146 | alias_entry *new = apr_array_push(conf->aliases); |
| 147 | alias_entry *entries = (alias_entry *)conf->aliases->elts; |
| 148 | int i; |
| 149 | |
| 150 | /* XXX: real can NOT be relative to DocumentRoot here... compat bug. */ |
| 151 | |
| 152 | const char *err = ap_check_cmd_context(cmd, NOT_IN_DIR_CONTEXT); |
| 153 | |
| 154 | if (err != NULL) { |
| 155 | return err; |
| 156 | } |
| 157 | |
| 158 | if (use_regex) { |
| 159 | new->regexp = ap_pregcomp(cmd->pool, fake, AP_REG_EXTENDED); |
| 160 | if (new->regexp == NULL) |
| 161 | return "Regular expression could not be compiled."; |
| 162 | new->real = real; |
| 163 | } |
| 164 | else { |
| 165 | /* XXX This may be optimized, but we must know that new->real |
| 166 | * exists. If so, we can dir merge later, trusing new->real |
| 167 | * and just canonicalizing the remainder. Not till I finish |
| 168 | * cleaning out the old ap_canonical stuff first. |
| 169 | */ |
| 170 | new->real = real; |
| 171 | } |
| 172 | new->fake = fake; |
| 173 | new->handler = cmd->info; |
| 174 | |
| 175 | /* check for overlapping (Script)Alias directives |
| 176 | * and throw a warning if found one |
| 177 | */ |
| 178 | if (!use_regex) { |
| 179 | for (i = 0; i < conf->aliases->nelts - 1; ++i) { |
| 180 | alias_entry *alias = &entries[i]; |
| 181 | |
| 182 | if ( (!alias->regexp && alias_matches(fake, alias->fake) > 0) |
| 183 | || (alias->regexp && !ap_regexec(alias->regexp, fake, 0, NULL, 0))) { |
| 184 | ap_log_error(APLOG_MARK, APLOG_WARNING, 0, cmd->server, APLOGNO(00671) |
| 185 | "The %s directive in %s at line %d will probably " |
| 186 | "never match because it overlaps an earlier " |
| 187 | "%sAlias%s.", |
| 188 | cmd->cmd->name, cmd->directive->filename, |
| 189 | cmd->directive->line_num, |
| 190 | alias->handler ? "Script" : "", |
| 191 | alias->regexp ? "Match" : ""); |
| 192 | |
| 193 | break; /* one warning per alias should be sufficient */ |
| 194 | } |
| 195 | } |
| 196 | } |
no test coverage detected