// =========================================================================== // // Description: Pack up IE into PDU. // Input: // mod PDU protocol mode. // Output: // len Length of PDU data string. // Return: char * // NULL Failure. // Other Pointer point to PDU data. // // =========================================================================== char * CPduBase::Output(UINT16& len) { // Packed the PDU in dedicat model. char * pPdu = NULL; len = 0; switch (GetProtocolType( )) { case MOD_JOYIT: case MOD_TUPAPI: case MOD_ISUPAPI: case MOD_Q931API: pPdu = ComposeJoyitApi(len); break; /* case MOD_INTER: // Add 2005-10-26, by Wujianjin. pPdu = ComposeInterApi(len); break; */ default: break; } // End of switch(mod) return pPdu; }
// =========================================================================== // // Description: Unpack the PDU. // Input: // ptr Pointer point to PDU data string. // len Length of PDU data. // mod PDU protocol mode. Mode define please refer to MOD_XXXXX macro. // Output: Null // Return: int // >=0 Success. // -1 Incompleted PDU. // -2 Exceed data in PDU. // // =========================================================================== int CPduBase::Unpacked(char * ptr, UINT16 len) { // Unpacked the PDU octets string. int r = 0; switch (GetProtocolType( )) { case MOD_JOYIT: case MOD_TUPAPI: case MOD_ISUPAPI: case MOD_Q931API: r = DecomposeJoyitApi(ptr, len); break; /* case MOD_INTER: r = DecomposeInterApi(ptr, len); break; */ default: break; } // End of switch(mod) return r; }
char * CQ931Pdu::Output(UINT16& len) { char * pPdu = NULL; len = 0; switch (GetProtocolType( )) { case MOD_JOYIT: case MOD_TUPAPI: case MOD_ISUPAPI: case MOD_Q931API: pPdu = ComposeJoyitApi(len); break; /* case MOD_INTER: // Add 2005-10-26, by Wujianjin. pPdu = ComposeInterApi(len); break; */ case MOD_Q931: pPdu = ComposeQ931Pdu(len); break; default: break; } // End of switch(mod) return pPdu; }
int CQ931Pdu::Unpacked(char * ptr, UINT16 len) { int r = 0; switch (GetProtocolType( )) { case MOD_JOYIT: case MOD_TUPAPI: case MOD_ISUPAPI: case MOD_Q931API: r = DecomposeJoyitApi(ptr, len); break; /* case MOD_INTER: // Add 2005-10-26, by Wujianjin. r = DecomposeInterApi(ptr, len); break; */ case MOD_Q931: r = DecomposeQ931Pdu(ptr, len); break; default: break; } // End of switch(mod) return r; }
INetChannel* CNetClient::AddNetChannel(char *pszRemoteIPAddr, UINT16 uiRemotePort, char *pszBindingIPAddr, UINT16 uiBindingPort) { ISocketChannel* pSockChn = NULL; CNetChannel* pNetChn; INT32 iRet; enumNetProtocolType euPType; INT32 iStatus; if(NULL == m_pSockCli) { return NULL; } if(GetProtocolType() == PROTOCOL_TYPE_TCP) { euPType = NET_PROTOCOL_TCP; } else { euPType = NET_PROTOCOL_UDP; } iRet = m_pSockCli->AddClientChannel(pszRemoteIPAddr, uiRemotePort, pszBindingIPAddr, uiBindingPort, euPType, &pSockChn); if(NULL == pSockChn || iRet != ERROR_BASE_SUCCESS) { iStatus = NET_CHANNEL_STATUS_SHUTDOWN; } else { iStatus = NET_CHANNEL_STATUS_ACTIVE; } pNetChn = InsertNetChannel(pSockChn, iStatus); if(NULL == pNetChn) { if(pSockChn) { pSockChn->CloseChannelEx(); } return NULL; } pNetChn->SetChnType(NET_CHANNEL_TYPE_CLIENT); pNetChn->SetNetService(m_pSockCli); pNetChn->SetRemoteIPAddrString(pszRemoteIPAddr); pNetChn->SetRemotePort(uiRemotePort); pNetChn->SetLocalIPAddrString(pszBindingIPAddr); pNetChn->SetLocalPort(uiBindingPort); //iRet = pNetChn->ConnectServer(pszRemoteIPAddr, uiRemotePort, pszBindingIPAddr, uiBindingPort); return pNetChn; }
// =========================================================================== // // Description: Pack up IE into Joyit API message. // Input: Null // Output: // len Length of Joyit API message. // Return: char * // NULL Failure. // Other Pointer point to Joyit API message. // // =========================================================================== char * CPduBase::ComposeJoyitApi(UINT16& len) { char * pPdu = NULL; char pdu[MAX_MSGLEN] = { 0 }; UINT8 pos = 0; UINT16 l; int i; // Make up API header. memcpy(pdu, Header, sizeof(SInterApiHead)); pos += sizeof(SInterApiHead); // #### Add 2005-10-30, by Wujianjin. ### // Construct the FIX information element first. UINT8 pt = GetProtocolType( ); if ((MOD_TUPAPI == pt) || (MOD_ISUPAPI == pt) || (MOD_Q931API == pt)) { // Construct the fix ie first. // Message index. CIeBase * pIe; pIe = GetIE(PSG_IE_MSGTYPE); if ((pIe != NULL) && (pIe->id != IE_NOT_EXIST)) { pdu[pos++] = pIe->id; pdu[pos++] = pIe->len; memcpy(pdu+pos, pIe->GetIeData(l), pIe->len); pos += pIe->len; } else { // Not exist, I will get it from mType. pdu[pos++] = PSG_IE_MSGTYPE; pdu[pos++] = 2; memcpy(pdu+pos, &mType, 2); pos += 2; } if (pIe != NULL) { DelIE(PSG_IE_MSGTYPE); } // Circuit structure. pIe = GetIE(PSG_IE_CIR_STRUCT); if ((pIe != NULL) && (pIe->id != IE_NOT_EXIST)) { pdu[pos++] = pIe->id; pdu[pos++] = pIe->len; memcpy(pdu+pos, pIe->GetIeData(l), pIe->len); pos += pIe->len; DelIE(PSG_IE_CIR_STRUCT); } else { // Exception handle. return pPdu; } // Circuit group indicator. pIe = GetIE(PSG_IE_CG_IND); if ((pIe != NULL) && (pIe->id != IE_NOT_EXIST)) { pdu[pos++] = pIe->id; pdu[pos++] = pIe->len; memcpy(pdu+pos, pIe->GetIeData(l), pIe->len); pos += pIe->len; } if (pIe != NULL) { DelIE(PSG_IE_CG_IND); } } // ### End 2005-10-30 ### // Make up all other IEs. for (i=0; i<IeCounter; ++i) { pdu[pos++] = IE[i].id; pdu[pos++] = IE[i].len; if ((pos + IE[i].len) >= MAX_MSGLEN) { // Message too long. printf("Joyit API too long. mType:0x%04X\n", mType); break; } memcpy(pdu+pos, IE[i].GetIeData(l), IE[i].len); pos += IE[i].len; } // Allocate memory for this PDU. if (i == IeCounter) { pPdu = new char[pos]; if (pPdu != NULL) { // ((SJoyitApiHead *)pdu)->msgType = mType; /* // Delete 2006-05-11, by Wu jianjin. ((SJoyitApiHead *)pdu)->primType = primType; // Modify 2005-10-27, by Wujianjin. ((SJoyitApiHead *)pdu)->noie = IeCounter; */ // ((SJoyitApiHead *)pdu)->PktLength = pos; // Modify 2006-05-11, by Wu jianjin. ((SInterApiHead *)pdu)->primType = primType; ((SInterApiHead *)pdu)->noie = IeCounter; memcpy(pPdu, pdu, pos); len = pos; } else { // Out of memory. printf("Make up Joyit API out of memory. mType:0x%04X\n", mType); } } return pPdu; }
INT32 CNetChannel::ConnectServer(char* pszRemoteIPAddr, UINT16 uiRemotePort, char* pszBindingIPAddr, UINT16 uiBindingPort) { INT32 iRet; enumNetProtocolType euPType; LOG2_INFO("ChnType(%d) Connect %s:%d bind:%s:%d", GetChnType(), pszRemoteIPAddr, uiRemotePort, pszBindingIPAddr ? pszBindingIPAddr : "0" , uiRemotePort ); if(m_pSocketChn) { LOG2_DEBUG("ChnType(%d) Close Socket: %s:%d => %s:%d .\n", GetChnType(), GetLocalIPAddrString(),GetLocalPort(), GetRemoteIPAddrString(),GetRemotePort()); m_MutexSend.Lock(); ISocketChannel *pSocket = m_pSocketChn; m_pSocketChn = NULL; m_MutexSend.Unlock(); if( pSocket ) { pSocket->CloseChannelEx(); } } if(NULL == m_pSocketChn) { if(m_pNetService) { if(GetProtocolType() == PROTOCOL_TYPE_TCP) { euPType = NET_PROTOCOL_TCP; } else { euPType = NET_PROTOCOL_UDP; } ISocketChannel *pSocket = NULL; iRet = m_pNetService->AddClientChannel(m_szRemoteIPAddr, uiRemotePort, pszBindingIPAddr, uiBindingPort, euPType, &pSocket); if(iRet < 0 || NULL == pSocket) { LOG2_ERROR("ChnType(%d) Connect %s:%d bind:%s:%d protype:%d fail.", GetChnType(), pszRemoteIPAddr, uiRemotePort, pszBindingIPAddr ? pszBindingIPAddr : "0" , uiRemotePort,(int) euPType ); return -1; } SetSocketChn( pSocket, NET_CHANNEL_STATUS_ACTIVE ); LOG2_DEBUG("ChnType(%d) Connect Socket: %s:%d => %s:%d OK.\n", GetChnType(), GetLocalIPAddrString(),GetLocalPort(), GetRemoteIPAddrString(),GetRemotePort()); } else { CMM_ASSERT(0); return -1; } } else { iRet = m_pSocketChn->ReConnect(); } return iRet; }