struct sip_msg* get_request_from_tx(struct cell *t) { if (t == NULL) { t = tmb.t_gett(); } if (!t || t == (void*) - 1) { LM_ERR("Reply without transaction\n"); return 0; } if (t) { /* we may need the request message from here on.. if there are headers we need that were not parsed in the original request (which we cannot assume) then we would pollute the shm_msg t->uas.request if we did any parsing on it. Instead, we need to make a private copy of the message and free it when we are done */ if (_pv_treq.label != t->label || _pv_treq.index != t->hash_index) { /* make a copy */ if (_pv_treq.buf == NULL || _pv_treq.buf_size < t->uas.request->len + 1) { if (_pv_treq.buf != NULL) pkg_free(_pv_treq.buf); if (_pv_treq.tmsgp) free_sip_msg(&_pv_treq.msg); _pv_treq.tmsgp = NULL; _pv_treq.index = 0; _pv_treq.label = 0; _pv_treq.buf_size = t->uas.request->len + 1; _pv_treq.buf = (char*) pkg_malloc(_pv_treq.buf_size * sizeof (char)); if (_pv_treq.buf == NULL) { LM_ERR("no more pkg\n"); _pv_treq.buf_size = 0; return 0; } } if (_pv_treq.tmsgp) free_sip_msg(&_pv_treq.msg); memset(&_pv_treq.msg, 0, sizeof (struct sip_msg)); memcpy(_pv_treq.buf, t->uas.request->buf, t->uas.request->len); _pv_treq.buf[t->uas.request->len] = '\0'; _pv_treq.msg.len = t->uas.request->len; _pv_treq.msg.buf = _pv_treq.buf; _pv_treq.tmsgp = t->uas.request; _pv_treq.index = t->hash_index; _pv_treq.label = t->label; if (pv_t_copy_msg(t->uas.request, &_pv_treq.msg) != 0) { pkg_free(_pv_treq.buf); _pv_treq.buf_size = 0; _pv_treq.buf = NULL; _pv_treq.tmsgp = NULL; _pv_treq.index = 0; _pv_treq.label = 0; return 0; } } return &_pv_treq.msg; } else return 0; }
int pv_t_update_inv(struct sip_msg *msg) { struct cell * t; if(msg==NULL) return 1; if (msg->REQ_METHOD!=METHOD_CANCEL) return 1; t = _tmx_tmb.t_lookup_original(msg); if(t==NULL || t==T_UNDEFINED) return 1; if(t->uas.request==NULL) { _tmx_tmb.unref_cell(t); return 1; } if (_pv_tinv.label == t->label && _pv_tinv.index == t->hash_index) goto done; /* make a copy */ if(_pv_tinv.buf==NULL || _pv_tinv.buf_size<t->uas.request->len+1) { if(_pv_tinv.buf!=NULL) pkg_free(_pv_tinv.buf); if(_pv_tinv.tmsgp) free_sip_msg(&_pv_tinv.msg); _pv_tinv.tmsgp = NULL; _pv_tinv.index = 0; _pv_tinv.label = 0; _pv_tinv.buf_size = t->uas.request->len+1; _pv_tinv.buf = (char*)pkg_malloc(_pv_tinv.buf_size*sizeof(char)); if(_pv_tinv.buf==NULL) { LM_ERR("no more pkg\n"); _pv_tinv.buf_size = 0; goto error; } } if(_pv_tinv.tmsgp) free_sip_msg(&_pv_tinv.msg); memset(&_pv_tinv.msg, 0, sizeof(struct sip_msg)); memcpy(_pv_tinv.buf, t->uas.request->buf, t->uas.request->len); _pv_tinv.buf[t->uas.request->len] = '\0'; _pv_tinv.msg.len = t->uas.request->len; _pv_tinv.msg.buf = _pv_tinv.buf; _pv_tinv.tmsgp = t->uas.request; _pv_tinv.index = t->hash_index; _pv_tinv.label = t->label; if(pv_t_copy_msg(t->uas.request, &_pv_tinv.msg)!=0) { pkg_free(_pv_tinv.buf); _pv_tinv.buf_size = 0; _pv_tinv.buf = NULL; _pv_tinv.tmsgp = NULL; _pv_tinv.index = 0; _pv_tinv.label = 0; goto error; } done: _tmx_tmb.unref_cell(t); return 0; error: _tmx_tmb.unref_cell(t); return -1; }
int pv_t_update_req(struct sip_msg *msg) { struct cell * t; int branch; if(msg==NULL) return 1; if(msg!=FAKED_REPLY && msg->first_line.type!=SIP_REPLY) return 1; t = _tmx_tmb.t_gett(); if(t==NULL || t==T_UNDEFINED) { if(msg==FAKED_REPLY) return 1; branch=-1; if (_tmx_tmb.t_check(msg, &branch ) == -1) return 1; t = _tmx_tmb.t_gett(); if ((t == 0) || (t == T_UNDEFINED)) return 1; } if(t->uas.request==NULL) return 1; if (_pv_treq.label == t->label && _pv_treq.index == t->hash_index) return 0; /* make a copy */ if(_pv_treq.buf==NULL || _pv_treq.buf_size<t->uas.request->len+1) { if(_pv_treq.buf!=NULL) pkg_free(_pv_treq.buf); if(_pv_treq.tmsgp) free_sip_msg(&_pv_treq.msg); _pv_treq.tmsgp = NULL; _pv_treq.index = 0; _pv_treq.label = 0; _pv_treq.buf_size = t->uas.request->len+1; _pv_treq.buf = (char*)pkg_malloc(_pv_treq.buf_size*sizeof(char)); if(_pv_treq.buf==NULL) { LM_ERR("no more pkg\n"); _pv_treq.buf_size = 0; return -1; } } if(_pv_treq.tmsgp) free_sip_msg(&_pv_treq.msg); memset(&_pv_treq.msg, 0, sizeof(struct sip_msg)); memcpy(_pv_treq.buf, t->uas.request->buf, t->uas.request->len); _pv_treq.buf[t->uas.request->len] = '\0'; _pv_treq.msg.len = t->uas.request->len; _pv_treq.msg.buf = _pv_treq.buf; _pv_treq.tmsgp = t->uas.request; _pv_treq.index = t->hash_index; _pv_treq.label = t->label; if(pv_t_copy_msg(t->uas.request, &_pv_treq.msg)!=0) { pkg_free(_pv_treq.buf); _pv_treq.buf_size = 0; _pv_treq.buf = NULL; _pv_treq.tmsgp = NULL; _pv_treq.index = 0; _pv_treq.label = 0; return -1; } return 0; }
int pv_t_update_rpl(struct sip_msg *msg) { struct cell * t; int branch; int cancel; if(msg==NULL) return 1; if(msg==FAKED_REPLY || msg->first_line.type!=SIP_REQUEST) return 1; t = _tmx_tmb.t_gett(); if(t==NULL || t==T_UNDEFINED) { if(_tmx_tmb.t_lookup_request(msg, 0, &cancel)<=0) return 1; t = _tmx_tmb.t_gett(); if(t==NULL || t==T_UNDEFINED) return 1; } if ( (branch=_tmx_tmb.t_get_picked_branch())<0 ) return 1; if(t->uac[branch].reply==NULL || t->uac[branch].reply==FAKED_REPLY) return 1; if (_pv_trpl.label == t->label && _pv_trpl.index == t->hash_index && _pv_trpl.branch == branch) return 0; /* make a copy */ if(_pv_trpl.buf==NULL || _pv_trpl.buf_size<t->uac[branch].reply->len+1) { if(_pv_trpl.buf!=NULL) pkg_free(_pv_trpl.buf); if(_pv_trpl.tmsgp) free_sip_msg(&_pv_trpl.msg); _pv_trpl.tmsgp = NULL; _pv_trpl.index = 0; _pv_trpl.label = 0; _pv_trpl.branch = 0; _pv_trpl.buf_size = t->uac[branch].reply->len+1; _pv_trpl.buf = (char*)pkg_malloc(_pv_trpl.buf_size*sizeof(char)); if(_pv_trpl.buf==NULL) { LM_ERR("no more pkg\n"); _pv_trpl.buf_size = 0; return -1; } } if(_pv_trpl.tmsgp) free_sip_msg(&_pv_trpl.msg); memset(&_pv_trpl.msg, 0, sizeof(struct sip_msg)); memcpy(_pv_trpl.buf, t->uac[branch].reply->buf, t->uac[branch].reply->len); _pv_trpl.buf[t->uac[branch].reply->len] = '\0'; _pv_trpl.msg.len = t->uac[branch].reply->len; _pv_trpl.msg.buf = _pv_trpl.buf; _pv_trpl.tmsgp = t->uac[branch].reply; _pv_trpl.index = t->hash_index; _pv_trpl.label = t->label; _pv_trpl.branch = branch; if(pv_t_copy_msg(t->uac[branch].reply, &_pv_trpl.msg)!=0) { pkg_free(_pv_trpl.buf); _pv_trpl.buf_size = 0; _pv_trpl.buf = NULL; _pv_trpl.tmsgp = NULL; _pv_trpl.index = 0; _pv_trpl.label = 0; _pv_trpl.branch = 0; return -1; } return 0; }