⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 transports.cxx

📁 mgcp协议源代码。支持多种编码:g711
💻 CXX
📖 第 1 页 / 共 3 页
字号:
BOOL H323TransportAddress::GetIpAndPort(PIPSocket::Address & ip,                                        WORD & port,                                        const char * proto) const{  if (strncmp(theArray, IpPrefix, 3) != 0) {    PTRACE(2, "H323\tUse of non IP transport address: \"" << *this << '"');    return FALSE;  }  PString host;  PINDEX colon = Find(':', 3);  if (colon == P_MAX_INDEX)    host = Mid(3);  else {    host = Mid(3, colon-3);    port = PIPSocket::GetPortByService(proto, Mid(colon+1));  }  if (host.IsEmpty() || port == 0) {    PTRACE(2, "H323\tIllegal IP transport address: \"" << *this << '"');    return FALSE;  }  if (PIPSocket::GetHostAddress(host, ip))    return TRUE;  PTRACE(1, "H323\tCould not find host : \"" << host << '"');  return FALSE;}PString H323TransportAddress::GetHostName() const{  if (strncmp(theArray, IpPrefix, 3) != 0)    return *this;  PString host;  PINDEX colon = Find(':', 3);  if (colon == P_MAX_INDEX)    host = Mid(3);  else    host = Mid(3, colon-3);  return PIPSocket::GetHostName(host);}H323Transport * H323TransportAddress::CreateTransport(H323EndPoint & endpoint) const{  /*Have transport type name, create the transport object. Hard coded at the    moment but would like to add some sort of "registration" of transport    classes so new transports can be added without changing this source file    every time. As we have one transport type at the moment and may never    actually have another, we hard code it for now.   */  if (strncmp(theArray, IpPrefix, 3) == 0)    return new H323TransportTCP(endpoint);  return NULL;}/////////////////////////////////////////////////////////////////////////////H323Listener::H323Listener(H323EndPoint & end)  : PThread(end.GetListenerThreadStackSize(), NoAutoDeleteThread),    endpoint(end){}/////////////////////////////////////////////////////////////////////////////H323Transport::H323Transport(H323EndPoint & end)  : endpoint(end){  thread = NULL;}H323Transport::~H323Transport(){  PAssert(thread == NULL, PLogicError);}BOOL H323Transport::Close(){  /* Do not use PIndirectChannel::Close() as this deletes the sub-channel     member field crashing the background thread. Just close the base     sub-channel so breaks the threads I/O block.   */  if (IsOpen())    GetBaseReadChannel()->Close();  return TRUE;}H323Connection * H323Transport::HandleFirstSignallingChannelPDU(){  PTRACE(3, "H225\tAwaiting first PDU");  H323SignalPDU pdu;  if (!pdu.Read(*this)) {    PTRACE(1, "H225\tFailed to get initial Q.931 PDU, connection not started.");    return NULL;  }  unsigned callReference = pdu.GetQ931().GetCallReference();  PTRACE(3, "H225\tFirst PDU: callReference=" << callReference);  H323Connection & connection = endpoint.GetConnection(*this, callReference, TRUE);  connection.AttachSignalChannel(this);  if (connection.HandleSignalPDU(pdu))    return &connection;  PTRACE(1, "H225\tSignal channel stopped on first PDU.");  connection.ClearCall(H323Connection::EndedByTransportFail);  return NULL;}BOOL H323Transport::ConnectControlChannel(H323Connection & connection){  if (!Connect())    return FALSE;  new H245TransportThread(endpoint, connection, *this);  return TRUE;}void H323Transport::AttachThread(PThread * thrd){  PAssert(thread == NULL, PLogicError);  thread = thrd;}void H323Transport::CleanUpOnTermination(){  Close();  if (thread != NULL) {    thread->WaitForTermination();    delete thread;    thread = NULL;  }}BOOL H323Transport::IsCompatibleTransport(const H225_TransportAddress & /*pdu*/) const{  PAssertAlways(PUnimplementedFunction);  return FALSE;}void H323Transport::SetUpTransportPDU(H225_TransportAddress & /*pdu*/,                                      BOOL /*localTsap*/) const{  PAssertAlways(PUnimplementedFunction);}void H323Transport::SetUpTransportPDU(H245_TransportAddress & /*pdu*/,                                      unsigned /*port*/) const{  PAssertAlways(PUnimplementedFunction);}BOOL H323Transport::CreateControlChannel(H323Connection & /*connection*/,                                                    H323Transport * & /*transport*/){  PAssertAlways(PUnimplementedFunction);  return FALSE;}BOOL H323Transport::AcceptControlChannel(H323Connection & /*connection*/){  PAssertAlways(PUnimplementedFunction);  return FALSE;}BOOL H323Transport::DiscoverGatekeeper(H323Gatekeeper & /*gk*/,                                       H323RasPDU & /*pdu*/,                                       const H323TransportAddress & /*address*/){  PAssertAlways(PUnimplementedFunction);  return FALSE;}/////////////////////////////////////////////////////////////////////////////H323ListenerTCP::H323ListenerTCP(H323EndPoint & end,                                 PIPSocket::Address binding,                                 WORD port)  : H323Listener(end),    listener(port),    localAddress(binding){}H323ListenerTCP::~H323ListenerTCP(){  Close();}BOOL H323ListenerTCP::Open(){#ifdef _DEBUG  return listener.Listen(localAddress, 5, 0, PSocket::CanReuseAddress);#else  return listener.Listen(localAddress);#endif}BOOL H323ListenerTCP::Close(){  BOOL ok = listener.Close();  PAssert(PThread::Current() != this, PLogicError);  WaitForTermination();  return ok;}static void AppendTransportAddress(H225_ArrayOf_TransportAddress & pdu,                                   const PIPSocket::Address & addr, WORD port){  H225_TransportAddress_ipAddress pduAddr;  PINDEX i;  for (i = 0; i < 4; i++)    pduAddr.m_ip[i] = addr[i];  pduAddr.m_port = port;  PINDEX lastPos = pdu.GetSize();  // Check for already have had that IP address.  for (i = 0; i < lastPos; i++) {    H225_TransportAddress & taddr = pdu[i];    if (taddr.GetTag() == H225_TransportAddress::e_ipAddress) {      H225_TransportAddress_ipAddress & ipAddr = taddr;      if (ipAddr == pduAddr)        return;    }  }  // Put new listener into array  pdu.SetSize(lastPos+1);  H225_TransportAddress & taddr = pdu[lastPos];  taddr.SetTag(H225_TransportAddress::e_ipAddress);  (H225_TransportAddress_ipAddress &)taddr = pduAddr;}void H323ListenerTCP::SetUpTransportPDU(H225_ArrayOf_TransportAddress & pdu,                                        const H225_TransportAddress & first){  WORD port = listener.GetPort();  if (localAddress != INADDR_ANY) {    AppendTransportAddress(pdu, localAddress, port);    return;  }  PIPSocket::InterfaceTable interfaces;  if (!PIPSocket::GetInterfaceTable(interfaces)) {    PIPSocket::Address ipAddr;    PIPSocket::GetHostAddress(ipAddr);    AppendTransportAddress(pdu, ipAddr, port);    return;  }  PIPSocket::Address firstAddress = 0;  if (first.GetTag() == H225_TransportAddress::e_ipAddress) {    const H225_TransportAddress_ipAddress & pduAddr = first;    firstAddress = PIPSocket::Address(pduAddr.m_ip[0],                                      pduAddr.m_ip[1],                                      pduAddr.m_ip[2],                                      pduAddr.m_ip[3]);  }  PINDEX i;  for (i = 0; i < interfaces.GetSize(); i++) {    PIPSocket::Address ipAddr = interfaces[i].GetAddress();    if (ipAddr == firstAddress)      AppendTransportAddress(pdu, ipAddr, port);  }  for (i = 0; i < interfaces.GetSize(); i++) {    PIPSocket::Address ipAddr = interfaces[i].GetAddress();    if (ipAddr != 0 && ipAddr != firstAddress && ipAddr != PIPSocket::Address()) // Ignore 127.0.0.1      AppendTransportAddress(pdu, ipAddr, port);  }}void H323ListenerTCP::Main(){  PTRACE(2, "H323\tAwaiting TCP connections on port " << listener.GetPort());  while (listener.IsOpen()) {    PTCPSocket * signallingChannel = new PTCPSocket;    if (signallingChannel->Accept(listener)) {      H323TransportTCP * transport = new H323TransportTCP(endpoint);      if (transport->Open(signallingChannel))        new H225TransportThread(endpoint, *transport);      else        delete transport;    }    else {      if (signallingChannel->GetErrorCode() != PChannel::Interrupted) {        PTRACE(1, "Q931\t\tAccept error:" << signallingChannel->GetErrorText());        listener.Close();      }      delete signallingChannel;    }  }}/////////////////////////////////////////////////////////////////////////////H323TransportIP::H323TransportIP(H323EndPoint & end, WORD remPort)  : H323Transport(end),    remoteAddress(0){  PIPSocket::GetHostAddress(localAddress);  localPort = 0;  remotePort = remPort;}H323TransportAddress H323TransportIP::GetLocalAddress() const{  return H323TransportAddress(localAddress, localPort);}H323TransportAddress H323TransportIP::GetRemoteAddress() const{  return H323TransportAddress(remoteAddress, remotePort);}BOOL H323TransportIP::IsCompatibleTransport(const H225_TransportAddress & pdu) const{  return pdu.GetTag() == H225_TransportAddress::e_ipAddress;}void H323TransportIP::SetUpTransportPDU(H225_TransportAddress & pdu, BOOL localTsap) const{  pdu.SetTag(H225_TransportAddress::e_ipAddress);  H225_TransportAddress_ipAddress & pduAddr = pdu;  PIPSocket::Address ipAddr = localTsap ? localAddress : remoteAddress;  for (PINDEX i = 0; i < 4; i++)    pduAddr.m_ip[i] = ipAddr[i];  pduAddr.m_port = localTsap ? localPort : remotePort;}void H323TransportIP::SetUpTransportPDU(H245_TransportAddress & pdu, unsigned port) const{  pdu.SetTag(H245_TransportAddress::e_unicastAddress);  H245_UnicastAddress & unicast = pdu;  unicast.SetTag(H245_UnicastAddress::e_iPAddress);  H245_UnicastAddress_iPAddress & addr = unicast;  for (PINDEX i = 0; i < 4; i++)    addr.m_network[i] = localAddress[i];  addr.m_tsapIdentifier = port;}/////////////////////////////////////////////////////////////////////////////

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -