int dlg_cseq_update(sip_msg_t *msg) { dlg_cell_t *dlg = NULL; unsigned int direction; unsigned int ninc = 0; unsigned int vinc = 0; str nval; str *pval; if(dlg_cseq_prepare_msg(msg)!=0) { goto error; } if(msg->first_line.type==SIP_REPLY) { /* nothing to do for outgoing replies */ goto done; } LM_DBG("initiating cseq updates\n"); direction = DLG_DIR_NONE; dlg = dlg_lookup_msg_dialog(msg, &direction); if(dlg == NULL) { LM_DBG("no dialog for this request\n"); goto done; } /* supported only for downstrem direction */ if(direction != DLG_DIR_DOWNSTREAM) { LM_DBG("request not going downstream (%u)\n", direction); goto done; } ninc = 1; /* take the increment value from dialog */ if((dlg->iflags&DLG_IFLAG_CSEQ_DIFF)==DLG_IFLAG_CSEQ_DIFF) { /* get dialog variable holding cseq diff */ pval = get_dlg_variable(dlg, &_dlg_cseq_diff_var_name); if(pval==NULL || pval->s==NULL || pval->len<=0) { LM_DBG("dialog marked with cseq diff but no variable set yet\n"); goto done; } if(str2int(pval, &vinc)<0) { LM_ERR("invalid dlg cseq diff var value: %.*s\n", pval->len, pval->s); goto done; } } vinc += ninc; if(vinc==0) { LM_DBG("nothing to increment\n"); goto done; } nval.s = int2str(vinc, &nval.len); if(set_dlg_variable(dlg, &_dlg_cseq_diff_var_name, &nval) <0) { LM_ERR("failed to set the dlg cseq diff var\n"); goto done; } str2int(&get_cseq(msg)->number, &ninc); vinc += ninc; nval.s = int2str(vinc, &nval.len); trim(&nval); LM_DBG("adding auth cseq header value: %.*s\n", nval.len, nval.s); parse_headers(msg, HDR_EOH_F, 0); sr_hdr_add_zs(msg, "P-K-Auth-CSeq", &nval); done: if(dlg!=NULL) dlg_release(dlg); return 0; error: if(dlg!=NULL) dlg_release(dlg); return -1; }
int dlg_cseq_refresh(sip_msg_t *msg, dlg_cell_t *dlg, unsigned int direction) { unsigned int ninc = 0; unsigned int vinc = 0; str nval; str *pval; sr_cfgenv_t *cenv = NULL; if(dlg_cseq_prepare_msg(msg)!=0) { goto error; } if(msg->first_line.type==SIP_REPLY) { /* nothing to do for outgoing replies */ goto done; } LM_DBG("initiating cseq refresh\n"); /* supported only for downstrem direction */ if(direction != DLG_DIR_DOWNSTREAM) { LM_DBG("request not going downstream (%u)\n", direction); goto done; } /* take the increment value from dialog */ if(!((dlg->iflags&DLG_IFLAG_CSEQ_DIFF)==DLG_IFLAG_CSEQ_DIFF)) { LM_DBG("no cseq refresh required\n"); goto done; } /* get dialog variable holding cseq diff */ pval = get_dlg_variable(dlg, &_dlg_cseq_diff_var_name); if(pval==NULL || pval->s==NULL || pval->len<=0) { LM_DBG("dialog marked with cseq diff but no variable set yet\n"); goto done; } if(str2int(pval, &vinc)<0) { LM_ERR("invalid dlg cseq diff var value: %.*s\n", pval->len, pval->s); goto done; } if(vinc==0) { LM_DBG("nothing to increment\n"); goto done; } str2int(&get_cseq(msg)->number, &ninc); vinc += ninc; nval.s = int2str(vinc, &nval.len); trim(&nval); LM_DBG("adding cseq refresh header value: %.*s\n", nval.len, nval.s); if(parse_headers(msg, HDR_EOH_F, 0)==-1) { LM_ERR("failed to parse all headers\n"); } cenv = sr_cfgenv_get(); sr_hdr_add_zs(msg, cenv->uac_cseq_refresh.s, &nval); done: return 0; error: return -1; }