MCPcopy Create free account
hub / github.com/OpenSIPS/opensips / add_prefix

Function add_prefix

modules/drouting/prefix_tree.c:255–313  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

253
254
255int
256add_prefix(
257 ptree_t *ptree,
258 str* prefix,
259 rt_info_t *r,
260 unsigned int rg,
261 osips_malloc_f malloc_f,
262 osips_free_f free_f
263)
264{
265 char* tmp=NULL;
266 int res = 0;
267 if(NULL==ptree) {
268 LM_ERR("ptree is null\n");
269 goto err_exit;
270 }
271 tmp = prefix->s;
272 while(tmp < (prefix->s+prefix->len)) {
273 if(NULL == tmp) {
274 LM_ERR("prefix became null\n");
275 goto err_exit;
276 }
277 if( !IS_VALID_PREFIX_CHAR(*tmp) ) {
278 /* unknown character in the prefix string */
279 LM_ERR("%c is not valid char in the prefix\n", *tmp);
280 goto err_exit;
281 }
282 if( tmp == (prefix->s+prefix->len-1) ) {
283 /* last digit in the prefix string */
284 LM_DBG("adding info %p, %d at: "
285 "%p (%d)\n", r, rg, &(ptree->ptnode[UIDX_OF_CHAR(*tmp)]),
286 IDX_OF_CHAR(*tmp));
287 res = add_rt_info(&(ptree->ptnode[UIDX_OF_CHAR(*tmp)]),
288 r,rg, malloc_f, free_f);
289 if(res < 0 ) {
290 LM_ERR("adding rt info doesn't work\n");
291 goto err_exit;
292 }
293 unode++;
294 res = 1;
295 goto ok_exit;
296 }
297 /* process the current digit in the prefix */
298 if(NULL == ptree->ptnode[UIDX_OF_CHAR(*tmp)].next) {
299 /* allocate new node */
300 INIT_PTREE_NODE(malloc_f, ptree,
301 ptree->ptnode[UIDX_OF_CHAR(*tmp)].next);
302 inode+=10;
303 }
304 ptree = ptree->ptnode[UIDX_OF_CHAR(*tmp)].next;
305 tmp++;
306 }
307
308ok_exit:
309 return 0;
310
311err_exit:
312 return -1;

Callers 2

add_ruleFunction · 0.85
add_rule_apiFunction · 0.85

Calls 1

add_rt_infoFunction · 0.85

Tested by

no test coverage detected