int reg_get_crt_max_contacts(void) { int n; sr_xavp_t *vavp=NULL; str vname = {"max_contacts", 12}; n = 0; if(reg_xavp_cfg.s!=NULL) { vavp = xavp_get_child_with_ival(®_xavp_cfg, &vname); if(vavp!=NULL) { n = vavp->val.v.i; LM_DBG("using max contacts value from xavp: %d\n", n); } } if(vavp==NULL) { n = cfg_get(registrar, registrar_cfg, max_contacts); } return n; }
/*! \brief * Calculate contact q value as follows: * 1) If xavp_cfg q has been defined, use it * 2) If q parameter exists in contact, use it * 3) If the parameter doesn't exist in contact, use the default value */ int calc_contact_q(param_t* _q, qvalue_t* _r) { sr_xavp_t *vavp = NULL; str xqname = str_init("q"); if (reg_xavp_cfg.s != NULL) vavp = xavp_get_child_with_ival(®_xavp_cfg, &xqname); if (vavp != NULL) { if ((vavp->val.v.i >= 0) && (vavp->val.v.i <= 1000)) { *_r = vavp->val.v.i; return 0; } else { rerrno = R_INV_Q; /* Invalid q parameter */ LM_ERR("invalid q parameter\n"); return -1; } } if (!_q || (_q->body.len == 0)) { *_r = cfg_get(registrar, registrar_cfg, default_q); } else { if (str2q(_r, _q->body.s, _q->body.len) < 0) { rerrno = R_INV_Q; /* Invalid q parameter */ LM_ERR("invalid q parameter\n"); return -1; } } return 0; }
int rtjson_update_branch(sip_msg_t *msg) { sr_xavp_t *javp = NULL; sr_xavp_t *iavp = NULL; srjson_doc_t tdoc; srjson_t *tj = NULL; srjson_t *nj = NULL; str val; str xname; int i; xname.s = "json"; xname.len = 4; javp = xavp_get_child_with_sval(&_rtjson_xavp_name, &xname); if(javp==NULL || javp->val.v.s.len<=0) { LM_WARN("no json for routing\n"); return -1; } xname.s = "idx"; xname.len = 3; iavp = xavp_get_child_with_ival(&_rtjson_xavp_name, &xname); if(iavp==NULL) { LM_WARN("no idx for routing\n"); return -1; } if(iavp->val.v.i<=0) { LM_WARN("invalid branch idx for routing\n"); return -1; } srjson_InitDoc(&tdoc, NULL); tdoc.root = srjson_Parse(&tdoc, javp->val.v.s.s); if(tdoc.root == NULL) { LM_ERR("invalid json doc [[%s]]\n", javp->val.v.s.s); srjson_DestroyDoc(&tdoc); return -1; } nj = srjson_GetObjectItem(&tdoc, tdoc.root, "routing"); if(nj==NULL || nj->valuestring==NULL) { LM_ERR("missing or invalid routing field\n"); goto error; } val.s = nj->valuestring; val.len = strlen(val.s); if(val.len!=6 || strncmp(val.s, "serial", 6)!=0) { LM_DBG("not serial routing [%.*s]\n", val.len, val.s); goto error; } tj = srjson_GetObjectItem(&tdoc, tdoc.root, "routes"); if(tj==NULL || tj->type!=srjson_Array || tj->child==NULL) { LM_ERR("missing or invalid routes field\n"); goto error; } nj = tj->child; i = 0; /* stop at number of branches - 1 */ while(nj && i<iavp->val.v.i-1) { nj = nj->next; i++; } if(nj==NULL) goto error; if(rtjson_prepare_branch(msg, &tdoc, nj)<0) goto error; srjson_DestroyDoc(&tdoc); return 0; error: srjson_DestroyDoc(&tdoc); return -1; }
int rtjson_push_routes(sip_msg_t *msg) { sr_xavp_t *javp = NULL; sr_xavp_t *iavp = NULL; srjson_doc_t tdoc; srjson_t *nj = NULL; str val; str xname; int ret; xname.s = "json"; xname.len = 4; javp = xavp_get_child_with_sval(&_rtjson_xavp_name, &xname); if(javp==NULL || javp->val.v.s.len<=0) { LM_WARN("no json for routing\n"); return -1; } xname.s = "idx"; xname.len = 3; iavp = xavp_get_child_with_ival(&_rtjson_xavp_name, &xname); if(iavp==NULL) { LM_WARN("no idx for routing\n"); return -1; } srjson_InitDoc(&tdoc, NULL); tdoc.root = srjson_Parse(&tdoc, javp->val.v.s.s); if(tdoc.root == NULL) { LM_ERR("invalid json doc [[%s]]\n", javp->val.v.s.s); srjson_DestroyDoc(&tdoc); return -1; } nj = srjson_GetObjectItem(&tdoc, tdoc.root, "routing"); if(nj==NULL || nj->valuestring==NULL) { LM_ERR("missing or invalid routing field\n"); goto error; } val.s = nj->valuestring; val.len = strlen(val.s); if(val.len==6 && strncmp(val.s, "serial", 6)==0) { LM_DBG("supported routing [%.*s]\n", val.len, val.s); ret = rtjson_init_serial(msg, &tdoc, iavp); } else if(val.len==8 && strncmp(val.s, "parallel", 8)==0) { LM_DBG("supported routing [%.*s]\n", val.len, val.s); ret = rtjson_init_parallel(msg, &tdoc, iavp); } else { LM_ERR("unsupported routing [%.*s]\n", val.len, val.s); goto error; } srjson_DestroyDoc(&tdoc); return ret; error: srjson_DestroyDoc(&tdoc); return -1; }