Browse code

is_2rr moved into rr parser to allow its usage from other modules

Vaclav Kubart authored on 24/08/2007 08:29:04
Showing 1 changed files
... ...
@@ -91,5 +91,85 @@ int duplicate_rr(rr_t** _new, rr_t* _r);
91 91
  */
92 92
 int shm_duplicate_rr(rr_t** _new, rr_t* _r);
93 93
 
94
+/*
95
+ * Find out if a URI contains r2 parameter which indicates
96
+ * that we put 2 record routes
97
+ */
98
+static inline int is_2rr(str* _params)
99
+{
100
+	str s;
101
+	int i, state = 0;
102
+
103
+	if (_params->len == 0) return 0;
104
+	s = *_params;
105
+
106
+	for(i = 0; i < s.len; i++) {
107
+		switch(state) {
108
+		case 0:
109
+			switch(s.s[i]) {
110
+			case ' ':
111
+			case '\r':
112
+			case '\n':
113
+			case '\t':           break;
114
+			case 'r':
115
+			case 'R': state = 1; break;
116
+			default:  state = 4; break;
117
+			}
118
+			break;
119
+
120
+		case 1:
121
+			switch(s.s[i]) {
122
+			case '2': state = 2; break;
123
+			default:  state = 4; break;
124
+			}
125
+			break;
126
+
127
+		case 2:
128
+			switch(s.s[i]) {
129
+			case ';':  return 1;
130
+			case '=':  return 1;
131
+			case ' ':
132
+			case '\r':
133
+			case '\n':
134
+			case '\t': state = 3; break;
135
+			default:   state = 4; break;
136
+			}
137
+			break;
138
+
139
+		case 3:
140
+			switch(s.s[i]) {
141
+			case ';':  return 1;
142
+			case '=':  return 1;
143
+			case ' ':
144
+			case '\r':
145
+			case '\n':
146
+			case '\t': break;
147
+			default:   state = 4; break;
148
+			}
149
+			break;
150
+
151
+		case 4:
152
+			switch(s.s[i]) {
153
+			case '\"': state = 5; break;
154
+			case ';':  state = 0; break;
155
+			default:              break;
156
+			}
157
+			break;
158
+
159
+		case 5:
160
+			switch(s.s[i]) {
161
+			case '\\': state = 6; break;
162
+			case '\"': state = 4; break;
163
+			default:              break;
164
+			}
165
+			break;
166
+
167
+		case 6: state = 5; break;
168
+		}
169
+	}
170
+
171
+	if ((state == 2) || (state == 3)) return 1;
172
+	else return 0;
173
+}
94 174
 
95 175
 #endif /* PARSE_RR_H */