forked from mirrors/tftp-hpa-google
remap: change the mode argument from a boolean to a character
Instead of taking a boolean value for get/put, pass a character; this allows us to extend the number of possibilities in the future. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
This commit is contained in:
parent
e7a7b19483
commit
0b5732e263
3 changed files with 11 additions and 15 deletions
|
@ -30,14 +30,13 @@
|
||||||
#define RULE_EXIT 0x04 /* Exit after matching this rule */
|
#define RULE_EXIT 0x04 /* Exit after matching this rule */
|
||||||
#define RULE_RESTART 0x08 /* Restart at the top after matching this rule */
|
#define RULE_RESTART 0x08 /* Restart at the top after matching this rule */
|
||||||
#define RULE_ABORT 0x10 /* Terminate processing with an error */
|
#define RULE_ABORT 0x10 /* Terminate processing with an error */
|
||||||
#define RULE_GETONLY 0x20 /* Applicable to GET only */
|
#define RULE_INVERSE 0x20 /* Execute if regex *doesn't* match */
|
||||||
#define RULE_PUTONLY 0x40 /* Applicable to PUT only */
|
|
||||||
#define RULE_INVERSE 0x80 /* Execute if regex *doesn't* match */
|
|
||||||
|
|
||||||
struct rule {
|
struct rule {
|
||||||
struct rule *next;
|
struct rule *next;
|
||||||
int nrule;
|
int nrule;
|
||||||
int rule_flags;
|
int rule_flags;
|
||||||
|
char rule_mode;
|
||||||
regex_t rx;
|
regex_t rx;
|
||||||
const char *pattern;
|
const char *pattern;
|
||||||
};
|
};
|
||||||
|
@ -221,15 +220,13 @@ static int parseline(char *line, struct rule *r, int lineno)
|
||||||
case 'i':
|
case 'i':
|
||||||
rxflags |= REG_ICASE;
|
rxflags |= REG_ICASE;
|
||||||
break;
|
break;
|
||||||
case 'G':
|
|
||||||
r->rule_flags |= RULE_GETONLY;
|
|
||||||
break;
|
|
||||||
case 'P':
|
|
||||||
r->rule_flags |= RULE_PUTONLY;
|
|
||||||
break;
|
|
||||||
case '~':
|
case '~':
|
||||||
r->rule_flags |= RULE_INVERSE;
|
r->rule_flags |= RULE_INVERSE;
|
||||||
break;
|
break;
|
||||||
|
case 'G':
|
||||||
|
case 'P':
|
||||||
|
r->rule_mode = *p;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
syslog(LOG_ERR,
|
syslog(LOG_ERR,
|
||||||
"Remap command \"%s\" on line %d contains invalid char \"%c\"",
|
"Remap command \"%s\" on line %d contains invalid char \"%c\"",
|
||||||
|
@ -329,7 +326,7 @@ void freerules(struct rule *r)
|
||||||
|
|
||||||
/* Execute a rule set on a string; returns a malloc'd new string. */
|
/* Execute a rule set on a string; returns a malloc'd new string. */
|
||||||
char *rewrite_string(const char *input, const struct rule *rules,
|
char *rewrite_string(const char *input, const struct rule *rules,
|
||||||
int is_put, match_pattern_callback macrosub,
|
char mode, match_pattern_callback macrosub,
|
||||||
const char **errmsg)
|
const char **errmsg)
|
||||||
{
|
{
|
||||||
char *current = tfstrdup(input);
|
char *current = tfstrdup(input);
|
||||||
|
@ -348,10 +345,8 @@ char *rewrite_string(const char *input, const struct rule *rules,
|
||||||
}
|
}
|
||||||
|
|
||||||
for (ruleptr = rules; ruleptr; ruleptr = ruleptr->next) {
|
for (ruleptr = rules; ruleptr; ruleptr = ruleptr->next) {
|
||||||
if (((ruleptr->rule_flags & RULE_GETONLY) && is_put) ||
|
if (ruleptr->rule_mode && ruleptr->rule_mode != mode)
|
||||||
((ruleptr->rule_flags & RULE_PUTONLY) && !is_put)) {
|
|
||||||
continue; /* Rule not applicable, try next */
|
continue; /* Rule not applicable, try next */
|
||||||
}
|
|
||||||
|
|
||||||
if (!deadman--) {
|
if (!deadman--) {
|
||||||
syslog(LOG_WARNING,
|
syslog(LOG_WARNING,
|
||||||
|
|
|
@ -35,7 +35,7 @@ struct rule *parserulefile(FILE *);
|
||||||
void freerules(struct rule *);
|
void freerules(struct rule *);
|
||||||
|
|
||||||
/* Execute a rule set on a string; returns a malloc'd new string. */
|
/* Execute a rule set on a string; returns a malloc'd new string. */
|
||||||
char *rewrite_string(const char *, const struct rule *, int,
|
char *rewrite_string(const char *, const struct rule *, char,
|
||||||
match_pattern_callback, const char **);
|
match_pattern_callback, const char **);
|
||||||
|
|
||||||
#endif /* WITH_REGEX */
|
#endif /* WITH_REGEX */
|
||||||
|
|
|
@ -1388,7 +1388,8 @@ static char *rewrite_access(char *filename, int mode, const char **msg)
|
||||||
{
|
{
|
||||||
if (rewrite_rules) {
|
if (rewrite_rules) {
|
||||||
char *newname =
|
char *newname =
|
||||||
rewrite_string(filename, rewrite_rules, mode != RRQ,
|
rewrite_string(filename, rewrite_rules,
|
||||||
|
mode != RRQ ? 'P' : 'G',
|
||||||
rewrite_macros, msg);
|
rewrite_macros, msg);
|
||||||
filename = newname;
|
filename = newname;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue