--- send_request 2006-11-17 15:06:19.000000000 -0600 +++ send_response 2006-11-17 15:05:20.000000000 -0600 @@ -1,41 +1,39 @@ -static int send_request(struct sip_pvt *p, struct sip_request *req, int reliable, int seqno) +static int send_response(struct sip_pvt *p, struct sip_request *req, int reliable, int seqno) { - int res=0; + int res = 0; char iabuf[INET_ADDRSTRLEN]; struct sip_request tmp; char tmpmsg[80]; - sip_rebuild_payload(p, req, 0); - if (stun_active && p->stun_needed == 1) { - opbx_log(LOG_DEBUG,"This call request %s seqno %d really needs STUN - sched %d\n",p->callid,seqno,p->stun_resreq_id); + opbx_log(LOG_DEBUG,"This call response %s seqno %d really needs STUN - sched %d\n",p->callid,seqno,p->stun_resreq_id); struct sip_reqresp *rr; - - rr = malloc(sizeof(struct sip_reqresp)); + rr = malloc(sizeof(struct sip_reqresp)); memset(rr, 0, sizeof(struct sip_reqresp)); - rr->type = 2; + rr->type = 1; rr->reliable = reliable; rr->seqno = seqno; memcpy(&rr->req, req, sizeof(struct sip_request)); memcpy(&rr->callid, p->callid, sizeof(p->callid)); rr->p = p; rr->p->stun_retrans_no = 0; - rr->streq = opbx_udp_stun_bindrequest(sipsock,&stunserver_ip,NULL,NULL); - memcpy(&rr->p->stun_transid,&rr->streq->req_head.id,sizeof(stun_trans_id) ); - if (p->rtp && opbx_rtp_get_stunstate(p->rtp) == 0) + rr->streq = opbx_udp_stun_bindrequest(sipsock, &stunserver_ip, NULL, NULL); + memcpy(&rr->p->stun_transid, &rr->streq->req_head.id, sizeof(stun_trans_id)); + + if (p->rtp && !opbx_rtp_get_stunstate(p->rtp)) { opbx_log(LOG_DEBUG, "Setting NAT on RTP to %d\n", (opbx_test_flag(p, SIP_NAT) & SIP_NAT_ROUTE) && p->stun_needed ); opbx_rtp_setnat(p->rtp, (opbx_test_flag(p, SIP_NAT) & SIP_NAT_ROUTE) && p->stun_needed ); } - if (p->vrtp && opbx_rtp_get_stunstate(p->vrtp) == 0) + if (p->vrtp && !opbx_rtp_get_stunstate(p->vrtp)) { opbx_log(LOG_DEBUG, "Setting NAT on VRTP to %d\n", (opbx_test_flag(p, SIP_NAT) & SIP_NAT_ROUTE) && p->stun_needed ); opbx_rtp_setnat(p->vrtp, (opbx_test_flag(p, SIP_NAT) & SIP_NAT_ROUTE) && p->stun_needed ); } #if T38_SUPPORT - if (p->udptl && opbx_udptl_get_stunstate(p->udptl) == 0) + if (p->udptl && !opbx_udptl_get_stunstate(p->udptl)) { opbx_log(LOG_DEBUG, "Setting NAT on UDPTL to %d\n", (opbx_test_flag(p, SIP_NAT) & SIP_NAT_ROUTE) && p->stun_needed ); opbx_udptl_setnat(p->udptl, (opbx_test_flag(p, SIP_NAT) & SIP_NAT_ROUTE) && p->stun_needed ); @@ -44,8 +42,8 @@ if (rr->streq) { if (stundebug) - opbx_log(LOG_DEBUG,"** Sent STUN packet for request %d\n",rr->streq->req_head.id.id[0]); - rr->p->stun_resreq_id=opbx_sched_add(sched, STUN_WAIT_RETRY_TIME, sip_resend_reqresp, rr); + opbx_log(LOG_DEBUG,"** Sent STUN packet for response %d\n",rr->streq->req_head.id.id[0]); + rr->p->stun_resreq_id = opbx_sched_add(sched, STUN_WAIT_RETRY_TIME, sip_resend_reqresp, rr); return 0; } else @@ -56,13 +54,15 @@ else if (p->stun_needed == 2) { if (stundebug) - opbx_log(LOG_DEBUG,"This transmit request has already a stun %d\n",p->stun_needed); - sip_rebuild_payload(p,req,1); + opbx_log(LOG_DEBUG,"This transmit response has already a stun %d\n",p->stun_needed); + sip_rebuild_payload(p, req, 1); } else { - if (stundebug) opbx_log(LOG_DEBUG,"This transmit request has stun at %d\n",p->stun_needed); - sip_rebuild_payload(p,req,0); + if (stundebug) + opbx_log(LOG_DEBUG,"This transmit response has stun at %d\n",p->stun_needed); + sip_rebuild_payload(p, req, 0); + } if (sip_debug_test_pvt(p)) @@ -72,15 +72,16 @@ else opbx_verbose("%sTransmitting (no NAT) to %s:%d:\n%s\n---\n", reliable ? "Reliably " : "", opbx_inet_ntoa(iabuf, sizeof(iabuf), p->sa.sin_addr), ntohs(p->sa.sin_port), req->data); } + if (reliable) { if (recordhistory) { parse_copy(&tmp, req); snprintf(tmpmsg, sizeof(tmpmsg), "%s / %s", tmp.data, get_header(&tmp, "CSeq")); - append_history(p, "TxReqRel", tmpmsg); + append_history(p, "TxRespRel", tmpmsg); } - res = __sip_reliable_xmit(p, seqno, 0, req->data, req->len, (reliable > 1), req->method); + res = __sip_reliable_xmit(p, seqno, 1, req->data, req->len, (reliable > 1), req->method); } else { @@ -88,11 +89,11 @@ { parse_copy(&tmp, req); snprintf(tmpmsg, sizeof(tmpmsg), "%s / %s", tmp.data, get_header(&tmp, "CSeq")); - append_history(p, "TxReq", tmpmsg); + append_history(p, "TxResp", tmpmsg); } res = __sip_xmit(p, req->data, req->len); } - p->stun_needed=0; + p->stun_needed = 0; sip_dealloc_headsdp_lines(req); return res; }