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

📄 megacomgc.c

📁 h.248协议源码
💻 C
📖 第 1 页 / 共 5 页
字号:

#if !defined(RV_FILEIO_ANSI)
/* embedded configuration file. Remember to make last item a NULL. */

static char *configtable[] = {
	"rv/79/0  192.168.216.79 7900000",
	"rv/79/1  192.168.216.79 7900001",
	"rv/79/2  192.168.216.79 7900002",
	"rv/79/3  192.168.216.79 7900003",
	"rv/79/4  192.168.216.79 7900004",
	"rv/79/5  192.168.216.79 7900005",
	"rv/79/6  192.168.216.79 7900006",
	"rv/79/7  192.168.216.79 7900007",
	"rv/79/8  192.168.216.79 7900008",
	"rv/79/9  192.168.216.79 7900009",
	NULL
};
#endif

#if defined(RV_IO_ANSI)
#	define RVMGC_PRINT_ERROR(x) printf(x)
#	define RVMGC_PRINT_ERROR2(x,y) printf(x,y)
#else
#	define RVMGC_PRINT_ERROR(x)
#	define RVMGC_PRINT_ERROR2(x,y)
#endif

static void applProtocol(int event);          /* Function prototipes       */
void   destructAppl(void);  
static RvBool findTermInd(const RvMegacoTerminationId *termId, 
                           RvMegacoEntity *entity);
static RvBool findRemoteTermInd(char *dialedPhone);
static int getNextTermInd(RvMegacoEntity *entity);
void   initAppl(void);
void   initLog(void);
int    initTerminations(const char* configFile);
int    RawClbkInit(char *proc_name, char *monIp, int monPort);
RvBool RawSendClbk(RvMegacoStack *s, char *msg_, unsigned int i, void *data);
RvBool RawRecvClbk(RvMegacoStack *s, char *msg_, unsigned int i, void *data);
void  readCodecFile(const char* codecFile);
void   receiveError(RvMegacoEntity *remoteEntity,
                     const RvMegacoErrorDescriptor *error, 
                     void *data);
static void receiveReply(RvMegacoTcb *tcb, 
                          const RvMegacoTransactionReply *reply,
                          void *data,
                          RvTransactionStatus reason);
static void receiveRequest(RvMegacoTcb *tcb, 
                            const RvMegacoTransaction *transaction, 
                            void *data);
static void sdpSaveLocalCodec(RvSdpMediaDescr *sdpMediaDescr); 
static void sdpSwitchCodec(int destTerm, int sourceTerm); 
static void sendReply(int type);
static void sendRequest(int type);
void   setErrorDescription(void);
void   timerExpired(RvTimer *timer, void *data);

/********************************************************************************/
/*  This phone is already in connection (or in setup for the connection) with   */ 
/* the other party. Tell it to the caller                                       */ 
/********************************************************************************/
int applBusySignalResp2(void)  
{
	RvMegacoPackageItem        packageItem1;  
	RvMegacoSignalsDescriptor  signalsDescriptor;
	RvMegacoSignal             signal;
 
	sprintf(dispBuf, "In applBusySignalResp(), termInd %d", termInd);
	rvLogInfo3(&rvLog, dispBuf); 
											  /* Assemble modifyCommand1        */
	applInfo[termInd].modifyCommandPtr = 
		rvAllocAllocate(&rvDefaultAlloc,
						 sizeof(RvMegacoModifyCommand)); 
                                         
	rvMegacoModifyCommandConstruct(applInfo[termInd].modifyCommandPtr, 
									&applInfo[termInd].terminationId);
											  /* Set up signals                 */
	rvMegacoPackageItemConstruct(&packageItem1,/* Construct PackageItem we need*/
								  "cg",       /* Call Progress Tones Package    */
								  "bt");     /* Busy tone signal               */  
	rvMegacoSignalConstruct(&signal, &packageItem1);
	rvMegacoSignalsDescriptorConstruct(&signalsDescriptor);
	rvMegacoSignalsDescriptorAddSignal(&signalsDescriptor, &signal);
	rvMegacoModifyCommandSetSignals(applInfo[termInd].modifyCommandPtr,
									 &signalsDescriptor);
	applInfo[termInd].commandType = RV_MEGACOCOMMANDTYPE_MODIFY;
	sendRequest(SEND_COMMAND);
    
	rvMegacoPackageItemDestruct(&packageItem1);
	rvMegacoSignalDestruct(&signal);    
	rvMegacoSignalsDescriptorDestruct(&signalsDescriptor);
	if (applInfo[termInd].callInProgress == rvTrue)
	{                                     /* If clash, force the caller to  */
		applInfo[termInd].callInProgress = rvFalse;/* disconnect                */
		if (applInfo[termInd].remoteTermInd != -1) /* If remote already involved*/ 
		{
			termInd = applInfo[termInd].remoteTermInd;
			applInfo[termInd].newState = S_WAITING_FOR_LOCAL_SETUP;
			applInfo[termInd].nextEvent = E_ON_HOOK_DISC_IND;  
			return E_STOP_RING_SIGNAL_REQ;    
		}
		else
			return NO_EVENT;
	}
	else
		return NO_EVENT;
}

/********************************************************************************/
/*  This phone is already in connection (or in setup for the connection) with   */ 
/* the other party. Tell it to the caller                                       */
/********************************************************************************/
int  applBusySignalResp3(void)  
{
	RvMegacoPackageItem        packageItem1;  
	RvMegacoSignalsDescriptor  signalsDescriptor;
	RvMegacoSignal             signal;
	RvMegacoContextIdType      type;
 
	sprintf(dispBuf, "In applBusySignalResp(), termInd %d", termInd);
	rvLogInfo3(&rvLog, dispBuf); 
											  /* Assemble modifyCommand1        */
	applInfo[termInd].modifyCommandPtr = 
		rvAllocAllocate(&rvDefaultAlloc,
						 sizeof(RvMegacoModifyCommand)); 
											  /* If a clash on the dialed phone */
	if (applInfo[termInd].callInProgress == rvTrue)
	{
		type = rvMegacoContextIdGetType(&applInfo[termInd].contextId);
		if (type != RV_MEGACOCONTEXTID_NORMAL)
		{
			rvMegacoContextIdDestruct(&applInfo[termInd].contextId);
			rvMegacoContextIdConstructSpecial(&applInfo[termInd].contextId,
											   RV_MEGACOCONTEXTID_ALL); /* '*' */
		}
	}
	rvMegacoModifyCommandConstruct(applInfo[termInd].modifyCommandPtr, 
									&applInfo[termInd].terminationId);
											  /* Set up signals                 */
	rvMegacoPackageItemConstruct(&packageItem1,/* Construct PackageItem we need*/
								  "cg",       /* Call Progress Tones Package    */
								  "bt");     /* Busy tone signal               */  
	rvMegacoSignalConstruct(&signal, &packageItem1);
	rvMegacoSignalsDescriptorConstruct(&signalsDescriptor);
	rvMegacoSignalsDescriptorAddSignal(&signalsDescriptor, &signal);
	rvMegacoModifyCommandSetSignals(applInfo[termInd].modifyCommandPtr,
									 &signalsDescriptor);
	applInfo[termInd].commandType = RV_MEGACOCOMMANDTYPE_MODIFY;
	sendRequest(SEND_COMMAND);

	rvMegacoPackageItemDestruct(&packageItem1);
	rvMegacoSignalDestruct(&signal);    
	rvMegacoSignalsDescriptorDestruct(&signalsDescriptor);
	if (applInfo[termInd].callInProgress == rvTrue)
	{                                     /* If clash, force the caller to  */
		applInfo[termInd].callInProgress = rvFalse; /* disconnect               */ 
		termInd = applInfo[termInd].remoteTermInd;
		applInfo[termInd].newState = S_WAITING_FOR_LOCAL_SETUP;
		return E_ON_HOOK_DISC_IND;             
	}
	else
		return NO_EVENT;
}

/********************************************************************************/
/*  We come here in state 2 when MG notifies us that the caller dialed a number */ 
/* that was checked against the requested dialplan0. Extract the number and     */
/* other related parameters.                                                    */
/********************************************************************************/
int applDialNumberInd(void)   
{
	const RvMegacoParameterValue *parameterValue;
	const char                   *dsValue, *methValue;
	int                           result;

	sprintf(dispBuf, "In applDialNumberInd(), termInd %d", termInd);
	rvLogInfo3(&rvLog, dispBuf); 

	if (applInfo[termInd].callInProgress == rvFalse)
		return E_ILLEGAL;

	parameterValue =
		rvMegacoObservedEventGetParameter(applInfo[termInd].observedEvent,
										   "ds");
	if (!parameterValue)
	{
		sprintf(dispBuf, "No telephone number on termInd %d", termInd);
		rvLogInfo3(&rvLog, dispBuf); 
		sendReply(CREATE_COMMAND_REPLY);     /* Send default reply          */    
		return E_WRONG_NUMBER_REQ; 
	}

	dsValue = rvMegacoParameterValueGetValue(parameterValue);

	parameterValue =
		rvMegacoObservedEventGetParameter(applInfo[termInd].observedEvent,
										   "Meth");
	methValue = rvMegacoParameterValueGetValue(parameterValue);

	if (!rvStrIcmp(methValue, "PM"))  
	{
		sprintf(dispBuf, "Partial telephone number %s on termInd %d", 
			(char *) dsValue, termInd);
		rvLogInfo3(&rvLog, dispBuf); 
		sendReply(CREATE_COMMAND_REPLY);     /* Send default reply          */    
		return E_WRONG_NUMBER_REQ; 
	}

	result = findRemoteTermInd((char *)dsValue);
	switch(result)
	{
	case 0:                               /* All OK                      */
		sendReply(CREATE_COMMAND_REPLY);   /* Send default reply          */  
		return E_LOCAL_CONNECT;                

	case -1:                              /* Wrong number                */                                            
		sprintf(dispBuf, "Invalid telephone number %s on termInd %d", 
				 (char *) dsValue, termInd);
		rvLogInfo3(&rvLog, dispBuf); 
		sendReply(CREATE_COMMAND_REPLY);   /* Send default reply          */    
		return E_WRONG_NUMBER_REQ;                  

	case -2:                             /* The phone is busy           */               
		sendReply(CREATE_COMMAND_REPLY);  
		return E_BUSY_SIGNAL_RESP;    
    
	case -3:                             /* The phone is not in service */                
		sprintf(dispBuf, 
				 "Telephone number %s on termInd %d is not in service", 
				 (char *) dsValue, termInd);
		rvLogInfo3(&rvLog, dispBuf); 
		sendReply(CREATE_COMMAND_REPLY);     
		return E_WRONG_NUMBER_REQ;  

	default:
		exit(1);
	}
	return NO_EVENT;                            /* No actual return here        */ 
}

/********************************************************************************/
/* Do nothing here. State machine will change the state if necessary            */
/********************************************************************************/
int  applDoIpNothing(void)    
{
	sprintf(dispBuf, "In applDoNothing(), termInd %d", termInd);
	rvLogInfo3(&rvLog, dispBuf);
	return NO_EVENT;
}

/********************************************************************************/
/* Do nothing here. State machine will change the state if necessary            */
/********************************************************************************/
int  applDoNothing(void)    
{
	sprintf(dispBuf, "In applDoNothing(), termInd %d", termInd);
	rvLogInfo3(&rvLog, dispBuf);

	applInfo[termInd].callInProgress = rvFalse;
	sendReply(CREATE_COMMAND_REPLY);         /* Send default reply          */
	return NO_EVENT;
}

/********************************************************************************/
/* Remove the signals before subtracting the terminations out of the context    */
/********************************************************************************/
int  applDoCleanup(void)    
{
	RvMegacoPackageItem 	   packageItem1, packageItem2;
	RvMegacoSignalsDescriptor  signalsDescriptor;

⌨️ 快捷键说明

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