OSDN Git Service

* adding ChxjConvRule directive with Charset.
[modchxj/mod_chxj.git] / src / chxj_apply_convrule.c
1 /*
2  * Copyright (C) 2005 QSDN,Inc. All rights reserved.
3  * Copyright (C) 2005 Atsushi Konno 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   entries = (chxjconvrule_entry *)convrules->elts;
30   for (ii = 0; ii < convrules->nelts; ii++) {
31     pp = &entries[ii];
32
33     if (r->main != NULL) continue;
34
35     /* Match */
36     if (s_apply_rule(r, pp)) 
37       return pp;
38   }
39   return NULL;
40 }
41
42 static int
43 s_apply_rule(request_rec* r, chxjconvrule_entry* pp) 
44 {
45   char* uri;
46   int   rtn;
47   ap_regmatch_t regmatch[AP_MAX_REG_MATCH];
48
49   uri = r->uri;
50
51   ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "convert rule pattern=[%s] uri=[%s]",
52     pp->pattern, uri);
53
54   rtn = ap_regexec(pp->regexp, uri, AP_MAX_REG_MATCH, regmatch, 0);
55   if (rtn == 0) {
56     /* Match */
57     if (pp->flags & CONVRULE_FLAG_NOTMATCH) {
58       /* not match */
59       return 0;
60     }
61   }
62   else {
63     /* Unmatch */
64     if (!(pp->flags & CONVRULE_FLAG_NOTMATCH)) {
65       /* not match */
66       return 0;
67     }
68   }
69
70   /* Match */
71   return 1;
72 }
73 /*
74  * vim:ts=2 et
75  */