This patch adds two extra kamailio compatibility functions:
* get_branch which allows the caller to obtain the parameters of a
branch using its index
* km_append_branch which is similar to append_branch in sip-router
except that the parameters of the function are slightly different.
... | ... |
@@ -174,6 +174,46 @@ char* next_branch(int* len, qvalue_t* q, char** dst_uri, int* dst_len, struct so |
174 | 174 |
} |
175 | 175 |
|
176 | 176 |
|
177 |
+/** \brief Get a branch from the destination set |
|
178 |
+ * \return Return the 'i' branch from the dset |
|
179 |
+ * array, 0 is returned if there are no |
|
180 |
+ * more branches |
|
181 |
+ */ |
|
182 |
+char* get_branch(unsigned int i, int* len, qvalue_t* q, str* dst_uri, |
|
183 |
+ str* path, unsigned int *flags, struct socket_info** force_socket) |
|
184 |
+{ |
|
185 |
+ if (i < nr_branches) { |
|
186 |
+ *len = branches[i].len; |
|
187 |
+ *q = branches[i].q; |
|
188 |
+ if (dst_uri) { |
|
189 |
+ dst_uri->len = branches[i].dst_uri_len; |
|
190 |
+ dst_uri->s = (dst_uri->len)?branches[i].dst_uri:0; |
|
191 |
+ } |
|
192 |
+ if (path) { |
|
193 |
+ path->len = branches[i].path_len; |
|
194 |
+ path->s = (path->len)?branches[i].path:0; |
|
195 |
+ } |
|
196 |
+ if (force_socket) |
|
197 |
+ *force_socket = branches[i].force_send_socket; |
|
198 |
+ if (flags) |
|
199 |
+ *flags = branches[i].flags; |
|
200 |
+ return branches[i].uri; |
|
201 |
+ } else { |
|
202 |
+ *len = 0; |
|
203 |
+ *q = Q_UNSPECIFIED; |
|
204 |
+ if (dst_uri) { |
|
205 |
+ dst_uri->s = 0; |
|
206 |
+ dst_uri->len = 0; |
|
207 |
+ } |
|
208 |
+ if (force_socket) |
|
209 |
+ *force_socket = 0; |
|
210 |
+ if (flags) |
|
211 |
+ *flags = 0; |
|
212 |
+ return 0; |
|
213 |
+ } |
|
214 |
+} |
|
215 |
+ |
|
216 |
+ |
|
177 | 217 |
/* |
178 | 218 |
* Empty the dset array |
179 | 219 |
*/ |
... | ... |
@@ -244,6 +284,87 @@ int append_branch(struct sip_msg* msg, char* uri, int uri_len, char* dst_uri, in |
244 | 284 |
} |
245 | 285 |
|
246 | 286 |
|
287 |
+/* ! \brief |
|
288 |
+ * Add a new branch to current transaction using str parameters |
|
289 |
+ * Kamailio compatibility version |
|
290 |
+ */ |
|
291 |
+int km_append_branch(struct sip_msg* msg, str* uri, str* dst_uri, str* path, |
|
292 |
+ qvalue_t q, unsigned int flags, struct socket_info* force_socket) |
|
293 |
+{ |
|
294 |
+ str luri; |
|
295 |
+ |
|
296 |
+#ifdef USE_LOCAL_ROUTE |
|
297 |
+ if (dset_state==0) |
|
298 |
+ return -1; |
|
299 |
+#endif |
|
300 |
+ |
|
301 |
+ /* if we have already set up the maximum number |
|
302 |
+ * of branches, don't try new ones |
|
303 |
+ */ |
|
304 |
+ if (nr_branches == MAX_BRANCHES - 1) { |
|
305 |
+ LOG(L_ERR, "max nr of branches exceeded\n"); |
|
306 |
+ ser_error = E_TOO_MANY_BRANCHES; |
|
307 |
+ return -1; |
|
308 |
+ } |
|
309 |
+ |
|
310 |
+ /* if not parameterized, take current uri */ |
|
311 |
+ if (uri==0 || uri->len==0 || uri->s==0) { |
|
312 |
+ if (msg->new_uri.s) |
|
313 |
+ luri = msg->new_uri; |
|
314 |
+ else |
|
315 |
+ luri = msg->first_line.u.request.uri; |
|
316 |
+ } else { |
|
317 |
+ luri = *uri; |
|
318 |
+ } |
|
319 |
+ |
|
320 |
+ if (luri.len > MAX_URI_SIZE - 1) { |
|
321 |
+ LOG(L_ERR, "too long uri: %.*s\n", luri.len, luri.s); |
|
322 |
+ return -1; |
|
323 |
+ } |
|
324 |
+ |
|
325 |
+ /* copy the dst_uri */ |
|
326 |
+ if (dst_uri && dst_uri->len && dst_uri->s) { |
|
327 |
+ if (dst_uri->len > MAX_URI_SIZE - 1) { |
|
328 |
+ LOG(L_ERR, "too long dst_uri: %.*s\n", |
|
329 |
+ dst_uri->len, dst_uri->s); |
|
330 |
+ return -1; |
|
331 |
+ } |
|
332 |
+ memcpy(branches[nr_branches].dst_uri, dst_uri->s, dst_uri->len); |
|
333 |
+ branches[nr_branches].dst_uri[dst_uri->len] = 0; |
|
334 |
+ branches[nr_branches].dst_uri_len = dst_uri->len; |
|
335 |
+ } else { |
|
336 |
+ branches[nr_branches].dst_uri[0] = '\0'; |
|
337 |
+ branches[nr_branches].dst_uri_len = 0; |
|
338 |
+ } |
|
339 |
+ |
|
340 |
+ /* copy the path string */ |
|
341 |
+ if (path && path->len && path->s) { |
|
342 |
+ if (path->len > MAX_PATH_SIZE - 1) { |
|
343 |
+ LOG(L_ERR, "too long path: %.*s\n", path->len, path->s); |
|
344 |
+ return -1; |
|
345 |
+ } |
|
346 |
+ memcpy(branches[nr_branches].path, path->s, path->len); |
|
347 |
+ branches[nr_branches].path[path->len] = 0; |
|
348 |
+ branches[nr_branches].path_len = path->len; |
|
349 |
+ } else { |
|
350 |
+ branches[nr_branches].path[0] = '\0'; |
|
351 |
+ branches[nr_branches].path_len = 0; |
|
352 |
+ } |
|
353 |
+ |
|
354 |
+ /* copy the ruri */ |
|
355 |
+ memcpy(branches[nr_branches].uri, luri.s, luri.len); |
|
356 |
+ branches[nr_branches].uri[luri.len] = 0; |
|
357 |
+ branches[nr_branches].len = luri.len; |
|
358 |
+ branches[nr_branches].q = q; |
|
359 |
+ |
|
360 |
+ branches[nr_branches].force_send_socket = force_socket; |
|
361 |
+ branches[nr_branches].flags = flags; |
|
362 |
+ |
|
363 |
+ nr_branches++; |
|
364 |
+ return 1; |
|
365 |
+} |
|
366 |
+ |
|
367 |
+ |
|
247 | 368 |
/* |
248 | 369 |
* Create a Contact header field from the dset |
249 | 370 |
* array |
... | ... |
@@ -44,6 +44,10 @@ int append_branch(struct sip_msg* msg, char* uri, int uri_len, char* dst_uri, in |
44 | 44 |
qvalue_t q, struct socket_info* force_socket); |
45 | 45 |
|
46 | 46 |
|
47 |
+int km_append_branch(struct sip_msg* msg, str* uri, str* dst_uri, str* path, |
|
48 |
+ qvalue_t q, unsigned int flags, struct socket_info* force_socket); |
|
49 |
+ |
|
50 |
+ |
|
47 | 51 |
/* |
48 | 52 |
* Iterate through the list of transaction branches |
49 | 53 |
*/ |
... | ... |
@@ -56,6 +60,10 @@ void init_branch_iterator(void); |
56 | 60 |
char* next_branch(int* len, qvalue_t* q, char** dst_uri, int* dst_len, struct socket_info** force_socket); |
57 | 61 |
|
58 | 62 |
|
63 |
+char* get_branch( unsigned int i, int* len, qvalue_t* q, str* dst_uri, |
|
64 |
+ str* path, unsigned int *flags, struct socket_info** force_socket); |
|
65 |
+ |
|
66 |
+ |
|
59 | 67 |
/* |
60 | 68 |
* Empty the array of branches |
61 | 69 |
*/ |