J'ai pris un à la source pour mod_rewrite (modules / mappeurs / mod_rewrite.c) et il semble qu'il wouldnt être trop difficile d'ajouter un drapeau spécial RewriteCond pour mon but. Ses ennuis sans doute plus de sa valeur sur le long terme si.
Id probablement commencer par ajouter un nouveau drapeau pour mon but.
Heres l'énumération. Ajout d'un indicateur pourrait me forcer à le réécrire si Apache ajoute un nouveau drapeau, plus tard, et je ne sais pas comment définir l'extérieur constante de l'énumération d'un certain nombre hors de portée des conflits s'arrangerait.
/* special pattern types for RewriteCond */
typedef enum {
CONDPAT_REGEX = 0,
CONDPAT_FILE_EXISTS, // -f flag
CONDPAT_FILE_SIZE,
CONDPAT_FILE_LINK,
CONDPAT_FILE_DIR,
CONDPAT_FILE_XBIT,
CONDPAT_LU_URL,
CONDPAT_LU_FILE,
CONDPAT_STR_GT,
CONDPAT_STR_LT,
CONDPAT_STR_EQ
} pattern_type;
- /* special pattern types for RewriteCond */
- typedef enum {
- CONDPAT_REGEX = 0,
- CONDPAT_FILE_EXISTS, // -f flag
- CONDPAT_FILE_SIZE,
- CONDPAT_FILE_LINK,
- CONDPAT_FILE_DIR,
- CONDPAT_FILE_XBIT,
- CONDPAT_LU_URL,
- CONDPAT_LU_FILE,
- CONDPAT_STR_GT,
- CONDPAT_STR_LT,
- CONDPAT_STR_EQ
- } pattern_type;
Puis Id de sauter vers le bas et le travail de mon drapeau dans ici.
Je pourrais rester simple et il suffit d'ajouter un drapeau d'un caractère où il en dur dans les 24 heures Je cherche pour le moment, mais que wouldnt être très utile.
a2 est défini comme «char * A2;" plus tôt dans la fonction, Je ne suis pas sûr que j'aurais pu tirer plus de bytes dans ce que je puisse ajouter un délai à mon drapeau ou non.
/* determine the pattern type */
newcond->ptype = CONDPAT_REGEX;
if (*a2 && a2[1]) {
if (!a2[2] && *a2 == '-') {
switch (a2[1]) {
case 'f': newcond->ptype = CONDPAT_FILE_EXISTS; break;
case 's': newcond->ptype = CONDPAT_FILE_SIZE; break;
case 'l': newcond->ptype = CONDPAT_FILE_LINK; break;
case 'd': newcond->ptype = CONDPAT_FILE_DIR; break;
case 'x': newcond->ptype = CONDPAT_FILE_XBIT; break;
case 'U': newcond->ptype = CONDPAT_LU_URL; break;
case 'F': newcond->ptype = CONDPAT_LU_FILE; break;
}
}
else {
switch (*a2) {
case '>': newcond->ptype = CONDPAT_STR_GT; break;
case '<': newcond->ptype = CONDPAT_STR_LT; break;
case '=': newcond->ptype = CONDPAT_STR_EQ;
/* "" represents an empty string */
if (*++a2 == '"' && a2[1] == '"' && !a2[2]) {
a2 += 2;
}
break;
}
}
}
- /* determine the pattern type */
- newcond->ptype = CONDPAT_REGEX;
- if (*a2 && a2[1]) {
- if (!a2[2] && *a2 == '-') {
- switch (a2[1]) {
- case 'f': newcond->ptype = CONDPAT_FILE_EXISTS; break;
- case 's': newcond->ptype = CONDPAT_FILE_SIZE; break;
- case 'l': newcond->ptype = CONDPAT_FILE_LINK; break;
- case 'd': newcond->ptype = CONDPAT_FILE_DIR; break;
- case 'x': newcond->ptype = CONDPAT_FILE_XBIT; break;
- case 'U': newcond->ptype = CONDPAT_LU_URL; break;
- case 'F': newcond->ptype = CONDPAT_LU_FILE; break;
- }
- }
- else {
- switch (*a2) {
- case '>': newcond->ptype = CONDPAT_STR_GT; break;
- case '<': newcond->ptype = CONDPAT_STR_LT; break;
- case '=': newcond->ptype = CONDPAT_STR_EQ;
- /* "" represents an empty string */
- if (*++a2 == '"' && a2[1] == '"' && !a2[2]) {
- a2 += 2;
- }
- break;
- }
- }
- }
Puis Id nécessité de travailler à la vérification de l'âge du fichier ici.
À première vue, Id deviner que quelque chose comme "sb.mtime" serait disponible à partir apr_stat.
Je ne suis pas sûr de savoir comment je accéder à mon intervalle, quoique peut-être je pourrais le travail de telle sorte que l'analyseur RewriteCond ensemble PType newcond-> à mon intervalle une fois qu'il a déterminé qu'il était de l'utiliser.
Bien que, l'intervalle devrait être secondes pour réduire les chances de conflicing avec les autres constantes, encore, je parie seconde serait la voie à suivre car tout mtime retournée est susceptible d'être un timestamp UNIX. Il serait maladroit d'avoir l'intervalle de prendre plusieurs secondes, et la force d'une restriction que ce soit de plus de 60 secondes pour prévenir les conflits bien. Peut-être ont-elle être définie en utilisant minutes, puis le convertir en secondes dans le module.
static int apply_rewrite_cond(rewritecond_entry *p, rewrite_ctx *ctx)
{
char *input = do_expand(p->input, ctx, NULL);
apr_finfo_t sb;
request_rec *rsub, *r = ctx->r;
ap_regmatch_t regmatch[AP_MAX_REG_MATCH];
int rc = 0;
switch (p->ptype) {
case CONDPAT_FILE_EXISTS:
if ( apr_stat(&sb, input, APR_FINFO_MIN, r->pool) == APR_SUCCESS
&& sb.filetype == APR_REG) {
rc = 1;
}
break;
case CONDPAT_FILE_SIZE:
if ( apr_stat(&sb, input, APR_FINFO_MIN, r->pool) == APR_SUCCESS
&& sb.filetype == APR_REG && sb.size > 0) {
rc = 1;
}
break;
- static int apply_rewrite_cond(rewritecond_entry *p, rewrite_ctx *ctx)
- {
- char *input = do_expand(p->input, ctx, NULL);
- apr_finfo_t sb;
- request_rec *rsub, *r = ctx->r;
- ap_regmatch_t regmatch[AP_MAX_REG_MATCH];
- int rc = 0;
-
- switch (p->ptype) {
- case CONDPAT_FILE_EXISTS:
- if ( apr_stat(&sb, input, APR_FINFO_MIN, r->pool) == APR_SUCCESS
- && sb.filetype == APR_REG) {
- rc = 1;
- }
- break;
-
- case CONDPAT_FILE_SIZE:
- if ( apr_stat(&sb, input, APR_FINFO_MIN, r->pool) == APR_SUCCESS
- && sb.filetype == APR_REG && sb.size > 0) {
- rc = 1;
- }
- break;
-
Strong with this one, the sudo is.