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

Function add_carrier

modules/drouting/routing.c:270–342  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

268}
269
270int add_carrier(char *id, int flags, char *sort_alg, char *gwlist, char *attrs,
271 int state, rt_data_t *rd,
272 osips_malloc_f mf, osips_free_f ff, MD5_CTX *hash_ctx)
273{
274 pcr_t *cr;
275 unsigned int i;
276 str key;
277
278 /* allocate a new carrier structure */
279 cr = (pcr_t*)func_malloc(mf, sizeof(pcr_t)+strlen(id)+(attrs?strlen(attrs):0));
280 if (cr==NULL) {
281 LM_ERR("no more shm mem for a new carrier\n");
282 goto error;
283 }
284 memset(cr, 0, sizeof(pcr_t));
285
286 if (gwlist && gwlist[0]!=0 ) {
287 /* parse the list of gateways */
288 if (parse_destination_list( rd, gwlist, &cr->pgwl,&cr->pgwa_len,0, mf)!=0){
289 LM_ERR("failed to parse the destinations\n");
290 goto error;
291 }
292 /* check that all dest to be GW! */
293 for( i=0 ; i<cr->pgwa_len ; i++ ) {
294 if (cr->pgwl[i].is_carrier) {
295 LM_ERR("invalid carrier <%s> definition as points to other "
296 "carrier (%.*s) in destination list\n",id,
297 cr->pgwl[i].dst.carrier->id.len,
298 cr->pgwl[i].dst.carrier->id.s);
299 goto error;
300 }
301 }
302 }
303
304 /* copy integer fields */
305 cr->flags = flags;
306 cr->sort_alg = dr_get_sort_alg(sort_alg[0]);
307
308 /* set state */
309 if (state!=0)
310 /* disabled */
311 cr->flags |= DR_CR_FLAG_IS_OFF;
312 else
313 /* enabled */
314 cr->flags &= ~DR_CR_FLAG_IS_OFF;
315
316 /* copy id */
317 cr->id.s = (char*)(cr+1);
318 cr->id.len = strlen(id);
319 memcpy(cr->id.s,id,cr->id.len);
320 /* copy attributes */
321 if (attrs && strlen(attrs)) {
322 cr->attrs.s = cr->id.s + cr->id.len;
323 cr->attrs.len = strlen(attrs);
324 memcpy(cr->attrs.s,attrs,cr->attrs.len);
325 }
326
327 /* link it */

Callers 1

dr_load_routing_infoFunction · 0.70

Calls 4

parse_destination_listFunction · 0.85
dr_get_sort_algFunction · 0.85
map_putFunction · 0.85
hash_carrierFunction · 0.85

Tested by

no test coverage detected