-
Notifications
You must be signed in to change notification settings - Fork 3
/
uri_template_common.c
95 lines (80 loc) · 1.89 KB
/
uri_template_common.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*
+----------------------------------------------------------------------+
| See LICENSE file for further copyright information |
+----------------------------------------------------------------------+
| Authors: Ioseb Dzmanashvili <[email protected]> |
+----------------------------------------------------------------------+
*/
#include "php_uri_template.h"
uri_template_vars *uri_template_vars_create()
{
return ecalloc(1, sizeof(uri_template_vars));
}
void uri_template_vars_free(uri_template_vars *list)
{
uri_template_var *first = list->first;
uri_template_var *prev;
while (first != NULL) {
prev = first;
first = first->next;
uri_template_var_free(prev);
}
efree(list);
}
uri_template_var *uri_template_var_create()
{
return ecalloc(1, sizeof(uri_template_var));
}
void uri_template_var_free(uri_template_var *var)
{
efree(var->name);
efree(var);
}
uri_template_expr *uri_template_expr_create(char operator)
{
uri_template_expr *expr = ecalloc(1, sizeof(uri_template_expr));
expr->op = operator;
expr->sep = ',';
expr->vars = uri_template_vars_create();
switch(operator) {
case '+':
expr->allow = 1;
break;
case '.':
case '/':
case ';':
expr->first = operator;
expr->sep = operator;
expr->named = operator == ';';
break;
case '?':
case '&':
expr->first = operator;
expr->sep = '&';
expr->named = 1;
expr->ifemp = '=';
break;
case '#':
expr->first = operator;
expr->allow = 1;
break;
}
return expr;
}
void uri_template_expr_add_var(uri_template_expr *expr, uri_template_var *var)
{
uri_template_vars *list = expr->vars;
if (list->first == NULL) {
list->first = var;
list->last = var;
} else {
list->last->next = var;
list->last = var;
}
list->count++;
}
void uri_template_expr_free(uri_template_expr *expr)
{
uri_template_vars_free(expr->vars);
efree(expr);
}