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

📄 upputpack.cpp

📁 SMS gateway. SMS protocol for CHINA mobile, unicom, lingtong. Using mysql to exchange message.
💻 CPP
字号:
/**********************************************************************  FileName            : UpPutPack.cpp  Description         : 放协议包进下端发送队列的函数集  Version             : 1.0  Date                : 2003年6月27日  Author              : 刘荣辉  Other               : ***********************************************************************/#include "UpNode.h"//int PutActiveTest();//往发送队列中放ActiveTest包//往发送队列中放Submit包,Origin_Seq为被转发的源请求包流水号,若非转发包则为0//int PutSubmit(void * pSubmit, int Origin_Seq);//直接发送Logout包//int SendLogout();//对统一业务测试指令的回复//int CMCCTestRsp(CMPP_Deliver *pDeliver);//=====================================================================================//==============================往发送队列中放ActiveTest包=============================//=====================================================================================int CUpNode::PutActiveTest(){  SendQUnit  SUnit;  char sSysEvent[SYS_EVENT_LEN];  char *ActTest;  int Sequence;  if(Protocol==0)	//CMPP_ActiveTest  {  	(CMPP_Active_Test *)ActTest = (CMPP_Active_Test *)malloc(sizeof(CMPP_Active_Test));  	((CMPP_Active_Test *)ActTest)->Total_Length = htonl(sizeof(CMPP_Active_Test));  	((CMPP_Active_Test *)ActTest)->Command_Id = htonl(CMPP_ACTIVE_TEST);  	Sequence = GetSequence();	((CMPP_Active_Test *)ActTest)->Sequence_Id = htonl(Sequence);  }  else if(Protocol==1)	//SMGP_ActiveTest  {  	(SMGP_Head *)ActTest = (SMGP_Head *)malloc(sizeof(SMGP_Head));  	((SMGP_Head *)ActTest)->nPacketLength = htonl(sizeof(SMGP_Head));  	((SMGP_Head *)ActTest)->nRequestId = htonl(REQUEST_ID_ACTIVE_TEST);  	//Sequence = GetSequence();	Sequence = 0;	//因为中兴小灵通网关返回的ActiveTest_Rsp的流水号全都为0  	((SMGP_Head *)ActTest)->nSequenceId = htonl(Sequence);  }    SUnit.Pack = ActTest;  time_t nowtime;  time(&nowtime);  SUnit.SendTime = nowtime;  SUnit.iResent = 1;  //SUnit.SrcSequence = 0;	//转发包流水号  if(SendQ->Put(SUnit)==false)  {	  sprintf(sSysEvent,"Warning: SendQ of UpNode[%s] is full, ActiveTest is abandon!",NodeCode);	  WrSystemLog->WriteLog(sSysEvent,SYSTEMLOG); 	  return 0;  }  #ifdef DEBUG  char thetime[15];  CFunc::getTime(thetime);  if(Protocol==0)	//CMPP_ActiveTest  {		printf("\n PutActiveTest[%s]: An CMPP_ActiveTest[%d] is put into SendQ of UpNode[%s]! \n",thetime,Sequence,NodeCode);  }  /*else if(Protocol==1)	//SMGP_ActiveTest  {		printf("\n PutActiveTest[%s]: An SMGP_ActiveTest[%d] is put into SendQ of UpNode[%s]! \n",thetime,Sequence,NodeCode);  }*/  #endif  return Sequence;}//=====================================================================================//===============================往发送队列中放Submit包================================//=====================================================================================//往发送队列中放Submit包,Origin_Seq为被转发的源请求包流水号,若非转发包则为0int CUpNode::PutSubmit(void * pSubmit, int SrcNode, int Origin_Seq){  SendQUnit  SUnit;  //char sSysEvent[SYS_EVENT_LEN];    time_t nowtime;  time(&nowtime);  SUnit.SrcRecvTime = nowtime;  SUnit.SendTime = nowtime;  memset(SUnit.ID_Relate,0,sizeof(SUnit.ID_Relate));  SUnit.RelayTimes = 0;  if(Protocol==0)	//CMPP_Submit  {	//把Reserve字段放在紧跟在消息内容后面的8个字节中,否则Reserve字段的内容无法发送出去	int  PackLen;  	PackLen = ntohl( ((CMPP_Submit*)pSubmit)->Head.Total_Length);	memcpy( (((char *)pSubmit)+PackLen-8) ,((CMPP_Submit*)pSubmit)->Reserve ,8);	SUnit.iResent = CMPP_SEND_RETRIES;  }  else if(Protocol==1)	//SMGP_Submit  {	//SUnit.iResent = DEFAULT_RESEND;	#ifdef DEBUG	SUnit.iResent = 1;	#endif  }  SUnit.Pack = (char *)pSubmit;  SUnit.SrcNode = SrcNode;  //SUnit.SrcSequence = Origin_Seq;  SendQ->Wait_Put(SUnit);  /*while(SendQ->Put(SUnit)==false)  {  	sprintf(sSysEvent,"Warning: Send Queue is full!Send_Q_Full_Wait=[%d]!",Send_Q_Full_Wait);	WrSystemLog->WriteLog(sSysEvent,SYSTEMLOG); 	usleep(Send_Q_Full_Wait);  }*/    #ifdef DEBUG  if(Protocol==0)	//CMPP_Submit  {		printf("\n PutSubmit: A CMPP_Submit Pack[%d] is put into SendQ! \n",ntohl( *(unsigned int *)( (char *)pSubmit+8) ) );  }  else if(Protocol==1)	//SMGP_Submit  {	    printf("\n PutSubmit: A SMGP_Submit Pack[%d] is put into SendQ! \n",ntohl( *(unsigned int *)( (char *)pSubmit+8) ) );  }  #endif  return 0;}//===============================================================================//===============================直接发送Logout包================================//===============================================================================int CUpNode::SendLogout(){  char sSysEvent[SYS_EVENT_LEN];  char *Logout;  int PackLen;  if(Protocol==0)	//CMPP_Terminate  {	PackLen = sizeof(CMPP_Terminate);  	(CMPP_Terminate *)Logout = (CMPP_Terminate *)malloc(PackLen);  	((CMPP_Terminate *)Logout)->Total_Length = htonl(PackLen);  	((CMPP_Terminate *)Logout)->Command_Id = htonl(CMPP_TERMINATE);  	((CMPP_Terminate *)Logout)->Sequence_Id = htonl(GetSequence());  	  }  else if(Protocol==1)	//SMGP_Exit  {	PackLen = sizeof(SMGP_Head);  	(SMGP_Head *)Logout = (SMGP_Head *)malloc(PackLen);  	((SMGP_Head *)Logout)->nPacketLength = htonl(PackLen);  	((SMGP_Head *)Logout)->nRequestId = htonl(REQUEST_ID_EXIT);  	((SMGP_Head *)Logout)->nSequenceId = htonl(GetSequence());  }    int RetCode=TcpSock.Writen(Logout,PackLen);  if(RetCode!=PackLen)  {  	sprintf(sSysEvent,"Error: Faild to Send Logout,RetCode=[%d]!",RetCode);	WrSystemLog->WriteLog(sSysEvent,SYSTEMLOG);	return 1;  }  return 0;}//===============================================================================//===============================对统一业务测试指令的回复========================//===============================================================================int CUpNode::CMCCTestRsp(CMPP_Deliver *pDeliver){	CMPP_Submit * pSubmit=(CMPP_Submit *)malloc(sizeof(CMPP_Submit));	memset(pSubmit,0,sizeof(CMPP_Submit));	pSubmit->Registered_Delivery = 0;	pSubmit->Msg_level = 0;	//strncpy(pSubmit->Service_Id, CMCCTEST, sizeof(pSubmit->Service_Id));	strncpy(pSubmit->Service_Id, "MFXX", sizeof(pSubmit->Service_Id));	pSubmit->Fee_UserType = 0;	pSubmit->TP_pId=1;	pSubmit->TP_udhi=0;	pSubmit->Msg_Fmt=15;	strncpy(pSubmit->Msg_src, SP_Id, sizeof(pSubmit->Msg_src));	strncpy(pSubmit->FeeType, "02", sizeof(pSubmit->FeeType));	strncpy(pSubmit->FeeCode, "1", sizeof(pSubmit->FeeCode));	//每条MT收费0.01元	strncpy(pSubmit->Src_Id, SP_Code, sizeof(pSubmit->Src_Id));	pSubmit->DestUsr_tl=1;	strncpy(pSubmit->Dest_terminal_Id, pDeliver->Src_terminal_Id, sizeof(pSubmit->Dest_terminal_Id));	char tmpTime[20];	sprintf(pSubmit->Msg_Content,"%s,%s,%s,%s",\			SP_Name,SP_Code,SP_Id, CFunc::getTime2(tmpTime));	pSubmit->Msg_Length = strlen(pSubmit->Msg_Content);       	pSubmit->Head.Total_Length = htonl(sizeof(CMPP_Submit) - sizeof(pSubmit->Msg_Content) + pSubmit->Msg_Length);	pSubmit->Head.Command_Id = htonl(CMPP_SUBMIT);	pSubmit->Head.Sequence_Id = htonl(GetSequence());	PutSubmit(pSubmit, NodeID, 0);	return 0;}/*/=====================================================================================//===============================往发送队列中放Logout包================================//=====================================================================================int CUpNode::PutLogout(){  SendQUnit  SUnit;  char sSysEvent[SYS_EVENT_LEN];  char *Logout;  if(Protocol==0)	//CMPP_Terminate  {  	(CMPP_Terminate *)Logout = (CMPP_Terminate *)malloc(sizeof(CMPP_Terminate));  	((CMPP_Terminate *)Logout)->Total_Length = htonl(sizeof(CMPP_Terminate));  	((CMPP_Terminate *)Logout)->Command_Id = htonl(CMPP_TERMINATE);  	((CMPP_Terminate *)Logout)->Sequence_Id = htonl(GetSequence());  	  }  else if(Protocol==1)	//SMGP_Exit  {  	(SMGP_Head *)Logout = (SMGP_Head *)malloc(sizeof(SMGP_Head));  	((SMGP_Head *)Logout)->nPacketLength = htonl(sizeof(SMGP_Head));  	((SMGP_Head *)Logout)->nRequestId = htonl(REQUEST_ID_EXIT);  	((SMGP_Head *)Logout)->nSequenceId = htonl(GetSequence());  }    SUnit.Pack = Logout;  time_t nowtime;  time(&nowtime);  SUnit.SendTime = nowtime;  SUnit.iResent = 1;  SUnit.SrcRecvTime = 0;  //SUnit.SrcSequence = 0;  while(SendQ->Put(SUnit)==false)  {  	sprintf(sSysEvent,"Warning: Send Queue is full!Send_Q_Full_Wait=[%d]!",Send_Q_Full_Wait);	WrSystemLog->WriteLog(sSysEvent,SYSTEMLOG); 	usleep(Send_Q_Full_Wait);  }    State = 2;	//将上节点标识为暂时不连接,防止继续往发送队列放数据包??????  return 0;}*/

⌨️ 快捷键说明

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