📄 udptransport.cxx
字号:
false ); SendData* stunResponse = new SendData(tuple, response, rlen); mTxFifo.add(stunResponse); } delete[] buffer; buffer = 0; return; }#ifdef USE_SIGCOMP osc::StateChanges *sc = 0;#endif // Attempt to decode SigComp message, if appropriate. if ((buffer[0] & 0xf8) == 0xf8) { if (!mCompression.isEnabled()) { InfoLog(<< "Discarding unexpected SigComp Message"); delete[] buffer; buffer = 0; return; }#ifdef USE_SIGCOMP char* newBuffer = MsgHeaderScanner::allocateBuffer(MaxBufferSize); size_t uncompressedLength = mSigcompStack->uncompressMessage(buffer, len, newBuffer, MaxBufferSize, sc); DebugLog (<< "Uncompressed message from " << len << " bytes to " << uncompressedLength << " bytes"); osc::SigcompMessage *nack = mSigcompStack->getNack(); if (nack) { mTxFifo.add(new SendData(tuple, Data(nack->getDatagramMessage(), nack->getDatagramLength()), Data::Empty, Data::Empty, true) ); delete nack; } delete[] buffer; buffer = newBuffer; len = uncompressedLength;#endif } buffer[len]=0; // null terminate the buffer string just to make debug easier and reduce errors //DebugLog ( << "UDP Rcv : " << len << " b" ); //DebugLog ( << Data(buffer, len).escaped().c_str()); SipMessage* message = new SipMessage(this); // set the received from information into the received= parameter in the // via // It is presumed that UDP Datagrams are arriving atomically and that // each one is a unique SIP message // Save all the info where this message came from tuple.transport = this; tuple.mFlowKey=mTuple.mFlowKey; message->setSource(tuple); //DebugLog (<< "Received from: " << tuple); // Tell the SipMessage about this datagram buffer. message->addBuffer(buffer); mMsgHeaderScanner.prepareForMessage(message); char *unprocessedCharPtr; if (mMsgHeaderScanner.scanChunk(buffer, len, &unprocessedCharPtr) != MsgHeaderScanner::scrEnd) { StackLog(<<"Scanner rejecting datagram as unparsable / fragmented from " << tuple); StackLog(<< Data(buffer, len)); delete message; message=0; return; } // no pp error int used = unprocessedCharPtr - buffer; if (used < len) { // body is present .. add it up. // NB. The Sip Message uses an overlay (again) // for the body. It ALSO expects that the body // will be contiguous (of course). // it doesn't need a new buffer in UDP b/c there // will only be one datagram per buffer. (1:1 strict) message->setBody(buffer+used,len-used); //DebugLog(<<"added " << len-used << " byte body"); } if (!basicCheck(*message)) { delete message; // cannot use it, so, punt on it... // basicCheck queued any response required message = 0; return; } stampReceived(message);#ifdef USE_SIGCOMP if (mCompression.isEnabled() && sc) { const Via &via = message->header(h_Vias).front(); if (message->isRequest()) { // For requests, the compartment ID is read out of the // top via header field; if not present, we use the // TCP connection for identification purposes. if (via.exists(p_sigcompId)) { Data compId = via.param(p_sigcompId); mSigcompStack->provideCompartmentId( sc, compId.data(), compId.size()); } else { mSigcompStack->provideCompartmentId(sc, this, sizeof(this)); } } else { // For responses, the compartment ID is supposed to be // the same as the compartment ID of the request. We // *could* dig down into the transaction layer to try to // figure this out, but that's a royal pain, and a rather // severe layer violation. In practice, we're going to ferret // the ID out of the the Via header field, which is where we // squirreled it away when we sent this request in the first place. Data compId = via.param(p_branch).getSigcompCompartment(); mSigcompStack->provideCompartmentId(sc, compId.data(), compId.size()); } }#endif mStateMachineFifo.add(message); }}void UdpTransport::buildFdSet( FdSet& fdset ){ fdset.setRead(mFd); if (mTxFifo.messageAvailable()) { fdset.setWrite(mFd); }}bool UdpTransport::stunSendTest(const Tuple& dest){ bool changePort=false; bool changeIP=false; StunAtrString username; StunAtrString password; username.sizeValue = 0; password.sizeValue = 0; StunMessage req; memset(&req, 0, sizeof(StunMessage)); stunBuildReqSimple(&req, username, changePort , changeIP , 1); char* buf = new char[STUN_MAX_MESSAGE_SIZE]; int len = STUN_MAX_MESSAGE_SIZE; int rlen = stunEncodeMessage(req, buf, len, password, false); SendData* stunRequest = new SendData(dest, buf, rlen); mTxFifo.add(stunRequest); mStunSuccess = false; return true;}boolUdpTransport::stunResult(Tuple& mappedAddress){ resip::Lock lock(myMutex); if (mStunSuccess) { mappedAddress = mStunMappedAddress; } return mStunSuccess;}/* ==================================================================== * The Vovida Software License, Version 1.0 * * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The names "VOCAL", "Vovida Open Communication Application Library", * and "Vovida Open Communication Application Library (VOCAL)" must * not be used to endorse or promote products derived from this * software without prior written permission. For written * permission, please contact vocal@vovida.org. * * 4. Products derived from this software may not be called "VOCAL", nor * may "VOCAL" appear in their name, without prior written * permission of Vovida Networks, Inc. * * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * DAMAGE. * * ==================================================================== * * This software consists of voluntary contributions made by Vovida * Networks, Inc. and many individuals on behalf of Vovida Networks, * Inc. For more information on Vovida Networks, Inc., please see * <http://www.vovida.org/>. * */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -