OSDN Git Service

* changed feature.
[modchxj/mod_chxj.git] / src / chxj_apply_convrule.c
1 /*
2  * Copyright (C) 2005-2011 Atsushi Konno All rights reserved.
3  * Copyright (C) 2005 QSDN,Inc. All rights reserved.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 #include "mod_chxj.h"
18 #include "chxj_apply_convrule.h"
19
20 static int s_apply_rule(request_rec *r, chxjconvrule_entry *pp);
21
22 chxjconvrule_entry *
23 chxj_apply_convrule(request_rec *r, apr_array_header_t *convrules)
24 {
25   chxjconvrule_entry *entries;
26   chxjconvrule_entry *pp;
27   int                ii;
28
29
30   if (r->main) 
31     return NULL;
32
33   entries = (chxjconvrule_entry *)convrules->elts;
34   for (ii = 0; ii < convrules->nelts; ii++) {
35     pp = &entries[ii];
36
37
38     /* Match */
39     if (s_apply_rule(r, pp)) 
40       return pp;
41   }
42   return NULL;
43 }
44
45 static int
46 s_apply_rule(request_rec *r, chxjconvrule_entry *pp) 
47 {
48   char  *uri;
49   int   rtn;
50   ap_regmatch_t regmatch[AP_MAX_REG_MATCH];
51
52   uri = r->uri;
53
54   DBG(r,"REQ[%X] convert rule pattern=[%s] uri=[%s]", TO_ADDR(r), pp->pattern, uri);
55
56   rtn = ap_regexec((const ap_regex_t *)pp->regexp, uri, AP_MAX_REG_MATCH, (ap_regmatch_t *)regmatch, 0);
57   if (rtn == 0) {
58     /* Match */
59     if (pp->flags & CONVRULE_FLAG_NOTMATCH) {
60       /* not match */
61       return 0;
62     }
63   }
64   else {
65     /* Unmatch */
66     if (!(pp->flags & CONVRULE_FLAG_NOTMATCH)) {
67       /* not match */
68       return 0;
69     }
70   }
71
72   /* Match */
73   return 1;
74 }
75 /*
76  * vim:ts=2 et
77  */