📄 test.c
字号:
/****************************************************************************** Copyright(C) 2005,2006 Frank ZHANG All Rights Reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. ****************************************************************************** If you want to distribute this software with modifications under any terms other than the GPL or distribute the software linked with proprietary applications that are not distributed in full compliance with the GNU Public License, a Commercial License is needed. Commercial licensing and support of this software are available at a fee. For more information, See http://www.openmgcp.org ******************************************************************************/#include <windows.h>#include <stdio.h>#include <winsock.h>#include "assert.h"#include "protocalapi.h"void Print_MGCP_CBK_CRCX(MGCP_CBK_CRCX *p){ PS("dwConnectionID"); PN(p->dwConnectionID); PS("dwTransacID"); PN(p->dwTransacID); PS("pcCallId"); PS(p->pcCallId); PS("dwConnectionID"); PN(p->dwConnectionID); PS("pLocalConnecOpt"); if (p->pLocalConnecOpt) PN(p->pLocalConnecOpt->wOptNum); PS("eMode"); PN(p->pMode->eMode); PS("pRemoteConnectDescrpt"); PN(p->pRemoteConnectDescrpt); PS("pSecondEndpoint"); PN(p->pSecondEndpoint); PS("dwSecondConnID"); PN(p->dwSecondConnID); PS("pExperiParamList"); PN(p->pExperiParamList);}LONG Cbk_func(H_ENDPOINT hEndpointHandle, MGCP_CBK_MSG *pCbkMsg, WORD *pwErrorCode){ printf("\nCBK: Handle = %d ", hEndpointHandle); switch (pCbkMsg->eType) { case MGCP_CBK_MSG_CREATRE_CONNECTION: printf("MSG = %s \n", "MGCP_CBK_MSG_CREATRE_CONNECTION"); //Print_MGCP_CBK_CRCX(&pCbkMsg->u.CbkCreateConnection); { CONNECTION_DESCRIPTOR LocalConnecDesc; memset(&LocalConnecDesc, 0, sizeof(CONNECTION_DESCRIPTOR)); LocalConnecDesc.pConnectionField = calloc(1, sizeof(CONNECTION_FIELD)); LocalConnecDesc.pConnectionField->pcNetType = Strdup("IN"); LocalConnecDesc.pConnectionField->pcAddrType = Strdup("IP4"); LocalConnecDesc.pConnectionField->ConnectionAddress.eType = ADDRESS_IPV4; LocalConnecDesc.pConnectionField->ConnectionAddress.pcAddress = Strdup("127.0.0.1"); LocalConnecDesc.wMediaNum = 1; LocalConnecDesc.pMediaDesc = calloc(1, sizeof(MEDIA_DESCRIPTIONS)); LocalConnecDesc.pMediaDesc->MediaField.pcMedia = Strdup("audio"); LocalConnecDesc.pMediaDesc->MediaField.pcPort = Strdup("6166"); LocalConnecDesc.pMediaDesc->MediaField.Protocol.eType = MEDIA_PROTOCOL_RTP; LocalConnecDesc.pMediaDesc->MediaField.wNum = 1; LocalConnecDesc.pMediaDesc->MediaField.ppcFormat = calloc(1, sizeof(char*)); LocalConnecDesc.pMediaDesc->MediaField.ppcFormat[0] = Strdup("0"); MgcpEndpointAcceptCRCX(hEndpointHandle, pCbkMsg->u.CbkCreateConnection.dwConnectionID, &LocalConnecDesc, NULL); ClearSdpConnectionDescriptor(&LocalConnecDesc); } break; case MGCP_CBK_MSG_MODIFY_CONNECTION: printf("MSG = %s \n", "MGCP_CBK_MSG_MODIFY_CONNECTION"); { CONNECTION_DESCRIPTOR LocalConnecDesc; memset(&LocalConnecDesc, 0, sizeof(CONNECTION_DESCRIPTOR)); LocalConnecDesc.pConnectionField = calloc(1, sizeof(CONNECTION_FIELD)); LocalConnecDesc.pConnectionField->pcNetType = Strdup("IN"); LocalConnecDesc.pConnectionField->pcAddrType = Strdup("IP4"); LocalConnecDesc.pConnectionField->ConnectionAddress.eType = ADDRESS_IPV4; LocalConnecDesc.pConnectionField->ConnectionAddress.pcAddress = Strdup("127.0.0.1"); LocalConnecDesc.wMediaNum = 1; LocalConnecDesc.pMediaDesc = calloc(1, sizeof(MEDIA_DESCRIPTIONS)); LocalConnecDesc.pMediaDesc->MediaField.pcMedia = Strdup("audio"); LocalConnecDesc.pMediaDesc->MediaField.pcPort = Strdup("6166"); LocalConnecDesc.pMediaDesc->MediaField.Protocol.eType = MEDIA_PROTOCOL_RTP; LocalConnecDesc.pMediaDesc->MediaField.wNum = 1; LocalConnecDesc.pMediaDesc->MediaField.ppcFormat = calloc(1, sizeof(char*)); LocalConnecDesc.pMediaDesc->MediaField.ppcFormat[0] = Strdup("0"); MgcpEndpointAcceptMDCX(hEndpointHandle, pCbkMsg->u.CbkModifyConnection.dwConnectionID, &LocalConnecDesc, NULL); ClearSdpConnectionDescriptor(&LocalConnecDesc); } break; case MGCP_CBK_MSG_DELETE_CONNECTION: printf("MSG = %s \n", "MGCP_CBK_MSG_DELETE_CONNECTION"); break; case MGCP_CBK_MSG_CONFIG_ENDPOINT: printf("MSG = %s \n", "MGCP_CBK_MSG_CONFIG_ENDPOINT"); break; case MGCP_CBK_MSG_RESTART_STATE: printf("MSG = %s \n",(pCbkMsg->u.CbkRestartState == RESTART_STATE_CONNECTED) ? "RESTART_STATE_CONNECTED" : "RESTART_STATE_DISCONNECTED"); break; case MGCP_CBK_MSG_SIGNAL_REQUEST: printf("MSG = %s \n", "MGCP_CBK_MSG_SIGNAL_REQUEST"); break; case MGCP_CBK_MSG_EXPERIMENTAL_PARM: printf("MSG = %s \n", "MGCP_CBK_MSG_EXPERIMENTAL_PARM"); break; } return OK;}LONG Cbk_Sig_Check(H_ENDPOINT hEndpointHandle, MGCP_EVENT_ID *pSigID, BOOL bEmbeddedRqnt, WORD *pwErrorCode){ return OK;}LONG CBK_CONNEC_PARAMS(H_ENDPOINT hEndpointHandle, DWORD dwConnecID, CONNECTION_PARAMETERS *pConnecParams){ pConnecParams->AverageLatency = 1; return OK;}int main(int arc, char** argv){ H_STACK pStack; LONG iRet = FAIL; unsigned int i; char cmd[256]; H_ENDPOINT pEndpoint = 0; WSADATA wsaData; if(WSAStartup(0x101,&wsaData)) return 0; iRet = MgcpStackCreate(&pStack, Cbk_func,CBK_CONNEC_PARAMS); Assert(iRet == OK); iRet = MgcpStackSetNetwork(pStack, ntohl(inet_addr("127.0.0.1")), 2427); Assert(iRet == OK); iRet = MgcpStackSetDomainName(pStack, "127.0.0.1"); Assert(iRet == OK); printf("Pls input the endpoint Number: "); scanf("%d", &i); for (; i > 0; i--) { char Name[50]; memset(Name, 0, sizeof(Name)); strcpy(Name, "MG"); strcat(Name, Itoa(i-1)); iRet = MgcpStackRegisterEndpoint(pStack, &pEndpoint, Name, Cbk_Sig_Check); Assert(iRet == OK); iRet = MgcpEndpointSetCallAgent(pEndpoint, "127.0.0.1", 2727); Assert(iRet == OK); iRet = MgcpEndpointAddPersistentEvent(pEndpoint, MGCP_PKG_LINE, L_OFF_HOOK_TRANSITION); Assert(iRet == OK); iRet = MgcpEndpointAddPersistentEvent(pEndpoint, MGCP_PKG_LINE, L_ON_HOOK_TRANSITION); Assert(iRet == OK); iRet = MgcpEndpointAddSupportedPackage(pEndpoint, MGCP_PKG_LINE); iRet = MgcpEndpointAddSupportedPackage(pEndpoint, MGCP_PKG_GENERIC_MEDIA); iRet = MgcpEndpointAddSupportedPackage(pEndpoint, MGCP_PKG_DTMF); Assert(iRet == OK); } iRet = MgcpStackStart(pStack); Assert(iRet == OK); Debug_On(LOG_ABNF_MSG); while (1) { scanf("%s", cmd); if (StrCaseCmp("offhk", cmd) == 0) { MGCP_OBSERVED_EVENT pEvent = {MGCP_PKG_LINE, L_OFF_HOOK_TRANSITION, 0}; if (MgcpEndpointNotifyEvent(pEndpoint, &pEvent, NULL) != OK) { printf("\nFial to MgcpEndpointNotifyEvent!"); } } else if (StrCaseCmp("onhk", cmd) == 0) { MGCP_OBSERVED_EVENT pEvent = {MGCP_PKG_LINE, L_ON_HOOK_TRANSITION, 0}; if (MgcpEndpointNotifyEvent(pEndpoint, &pEvent, NULL) != OK) { printf("\nFial to MgcpEndpointNotifyEvent!"); } } else if (*cmd >= '0' && *cmd <= '9') { MGCP_OBSERVED_EVENT pEvent = {MGCP_PKG_DTMF, D_DTMF_0+*cmd-'0', 0}; if (MgcpEndpointNotifyEvent(pEndpoint, &pEvent, NULL) != OK) { printf("\nFial to MgcpEndpointNotifyEvent!"); } } else if (StrCaseCmp("fls", cmd) == 0) { MGCP_OBSERVED_EVENT pEvent = {MGCP_PKG_LINE, L_FLASH_HOOK, 0}; if (MgcpEndpointNotifyEvent(pEndpoint, &pEvent, NULL) != OK) { printf("\nFial to MgcpEndpointNotifyEvent!"); } } else if (StrCaseCmp("exit", cmd) == 0) break; else if (StrCaseCmp("deb_a_on", cmd) == 0) Debug_On(LOG_ABNF_MSG); else if (StrCaseCmp("deb_a_off", cmd) == 0) Debug_Off(LOG_ABNF_MSG); else if (StrCaseCmp("deb_m_on", cmd) == 0) Debug_On(LOG_TASK_MSG); else if (StrCaseCmp("deb_m_off", cmd) == 0) Debug_Off(LOG_TASK_MSG); else if (StrCaseCmp("deb_e_on", cmd) == 0) Debug_On(LOG_ERROR); else if (StrCaseCmp("deb_e_off", cmd) == 0) Debug_Off(LOG_ERROR); else if (StrCaseCmp("?", cmd) == 0 || StrCaseCmp("help", cmd) == 0) { printf("\nHelp:"); printf("\noffhk: Send off-hooke event."); printf("\nonhk: Send on-hooke event."); printf("\nfls: Send flash event."); printf("\n0-9*#: Send DTMF event."); printf("\nexit: Exit the program."); printf("\ndeb_a_on: Switch on the abnf debug."); printf("\ndeb_a_off: Switch off the abnf debug."); printf("\ndeb_m_on: Switch on the mgcp message debug."); printf("\ndeb_m_off: Switch off the mgcp message debug."); printf("\ndeb_e_on: Switch on the error message debug."); printf("\ndeb_e_off: Switch off the error message debug.\n"); } } printf("\nCompleting the stack, Pls wait... "); MgcpStackDestroy(pStack); WSACleanup();}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -