| 25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 26 * POSSIBILITY OF SUCH DAMAGE. |
26 * POSSIBILITY OF SUCH DAMAGE. |
| 27 */ |
27 */ |
| 28 |
28 |
| 29 #include "rewrite.h" |
29 #include "rewrite.h" |
| |
30 |
| |
31 |
| |
32 RewriteRule* rewrite_rule_create(const CxAllocator *a, cxmutstr regex, cxmutstr url) { |
| |
33 regex_t reg; |
| |
34 if(regex.ptr) { |
| |
35 if(regcomp(®, regex.ptr, REG_EXTENDED)) { |
| |
36 log_ereport(LOG_FAILURE, "rewrite: cannot compile regex: %s", regex.ptr); |
| |
37 return NULL; |
| |
38 } |
| |
39 } |
| |
40 |
| |
41 RewriteRule *rule = cxMalloc(a, sizeof(RewriteRule)); |
| |
42 if(!rule) { |
| |
43 return NULL; |
| |
44 } |
| |
45 rule->has_regex = regex.ptr != NULL; |
| |
46 rule->regex = reg; |
| |
47 rule->url = string_template_compile(a, cx_strcast(url)); |
| |
48 if(!rule->url) { |
| |
49 return NULL; |
| |
50 } |
| |
51 |
| |
52 return rule; |
| |
53 } |
| |
54 |
| 30 |
55 |
| 31 typedef struct RVar { |
56 typedef struct RVar { |
| 32 cxstring str; |
57 cxstring str; |
| 33 regmatch_t *match; |
58 regmatch_t *match; |
| 34 int nmatch; |
59 int nmatch; |