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

📄 common.h

📁 短信网管的原代码。用于与sp通信
💻 H
字号:
#ifndef _COMMON_H
#define _COMMON_H
#include "stdafx.h"
#include <Winsock2.h>
#include "shlwapi.h"
#include "datadef.h"
#include "constdef.h"

#define _INTECH_SMPP
#define  NET_charS_SEQ
#define  _UC unsigned char

extern  UINT    THESEQ_NO;
#define GET_SEQ_NO THESEQ_NO>0x7FFFFFFF?THESEQ_NO=1:THESEQ_NO++

#include "MainFrm.h"

//声明主框架类的实例,用于别类的显示	
extern	CMainFrame*        g_MainFrame;

//短消息通道信息
extern STRUCT_SMSCINFO	   gStructSmscInfo;
//短信中心发送链路配置
extern STRUCT_TRANSINFO    gStructTransInfo;
//短信中心发送链路配置
extern STRUCT_RECVINFO	   gStructRecvInfo;
//系统模块配置
extern STRUCT_CLIENTINFO  gStructClientInfo;
//监控中心配置
extern STRUCT_WATCHCENTER gStructWatchInfo;
//通道属性配置
extern STRUCT_CHANNEL_INFO gStructChannelInfo;

extern STRUCT_PACKET_LIST  packetList;

extern DWORD  gdw_RcvLinkNetStatus;
extern DWORD  gdw_TransLinkNetStatus;
extern DWORD  gdw_PtLinkNetStatus;
extern DWORD  gdw_CmppLinkNetStatus;

#define e_INAVLID_MESSAGE -1
#define e_QUE_FULL         0
#define DELAY_TIME         5

template <DWORD dwQueSize, DWORD dwQueItemSize>
class T_MSG_QUE
{
        public:
                T_MSG_QUE()
                {
                    ZeroMemory(Que,sizeof(Que));
                    ZeroMemory(dwItemLen,sizeof(dwItemLen)); 
                    dwFirst = 0;
                    dwLast = 0;    
                };

                ~T_MSG_QUE()
                {
                };
        
                int push(char *pMsg, DWORD dwLen)
                {
                        if( dwLen >= dwQueItemSize)//检查消息的合法性
                                return e_INAVLID_MESSAGE;

                        if( ((dwLast + 1)%dwQueSize) == dwFirst)//队列满
                                return e_QUE_FULL;
                        
                        memcpy(Que[dwLast],pMsg,dwLen);
                        dwItemLen[dwLast] = dwLen;
                        dwLast = (dwLast + 1)%dwQueSize ;  
                        return 1;
                };
                
                int pop(char *pMsg)
                {
                   if(dwFirst == dwLast)//队列空
                      return 0;
                   memcpy(pMsg,Que[dwFirst],dwItemLen[dwFirst]);
                   dwFirst = (dwFirst + 1)%dwQueSize ;
                   return 1;
                };
                
        private:
                char  Que[dwQueSize][dwQueItemSize];
                DWORD dwItemLen[dwQueSize];                             
                DWORD dwFirst;
                DWORD dwLast;
};              

class TOutInterface
{
	//内部DEFINE
	#define MyPrintf(x,y) \
			{\
			if(TraceAllMsg == 0) \
			   OutUsage(0,x);\
			g_MainFrame->PrintInput(1,y);}

	#define MyPrintfSkel(x) \
			OutUsage(0,x);

	public:
		TOutInterface()
		{
			TraceOne       = 0;
			TraceAllMsg    = 1;
			iPrintTest     = 1;
		};
		~TOutInterface(){};

		void TraceSingle(char *cIsdn)
		{
			TraceOne =1;
			strncpy(TraceIsdn,cIsdn,20);
		};
		void TraceAll(int enable)
		{
			TraceAllMsg = enable;
		};
		void TraceNone()
		{
			TraceOne =0;
		};
		void MsgCount()
		{
			iMoCount = 0;
			iMtCount = 0;
		};
		void MoCountAdd()
		{
			iMoCount ++;
		};
		void MtCountAdd()
		{
			iMtCount ++;
		};
		void GetCount(int &a, int &b)
		{
			a = iMoCount;
			b = iMtCount;
		};
		void PrintTest(int enable)
		{
			iPrintTest = enable;
		};
		void GetStatus(DWORD &dwPt, DWORD &dwRcv, DWORD &dwTrans)
		{
			dwRcv   = gdw_CmppLinkNetStatus;
			dwTrans = 0;
			dwPt    = gdw_PtLinkNetStatus;
		};
		void SendFakeMsg(char *cBuff, int iLen)
		{
		//	center.TransEntity.SendToTcp(cBuff,iLen);
		};

		void OutPutAll(char *pMsg)
		{
			if(TraceAllMsg == 1)//如果设定跟踪
			{
				//取消息类型
				DWORD dwCommandId=ntohl(*(DWORD *)(pMsg+4));
				switch(dwCommandId )
				{
					//平台接口
					case TRP_SUBMIT://匹配手机号,得到PTID
						STRUCT_SUBMIT *pSubmitMsg;
						pSubmitMsg = (STRUCT_SUBMIT *)pMsg;
						char cTmp[256];
						sprintf(cTmp,"Message TRP_SUBMIT [To:%s] from PT!\r\n",pSubmitMsg->sCMPP12Submit.szDest_terminal_ids);
						MyPrintfSkel(cTmp);
						break;
					case TRP_QUERY://匹配SMC-ID,得到PTID
						MyPrintfSkel("Message TRP_QUERY from PT!\r\n");
						break;
					case TRP_DELIVERY://匹配SMC-SEQID
						MyPrintfSkel("Message TRP_DELIVERY to PT!\r\n");
						break;
					case TRP_MSG_REPORT://匹配SMC-SEQID
						MyPrintfSkel("Message TRP_MSG_REPORT to PT!\r\n");
						break;
					case TRP_UNIDATA_ACK://=TRP_SUBMIT_RSP, 匹配ptID
						MyPrintfSkel("Message TRP_UNIDATA_ACK to PT!\r\n");
						break;

					//SMPP interface
					case CMPP12_SUBMIT:  //匹配ptID
						MyPrintfSkel("Message CMPP12_SUBMIT to SMC!\r\n");
						break;
					case CMPP12_QUERY://匹配ptID
						MyPrintfSkel("Message CMPP12_QUERY to SMC!\r\n");
						break;
					case CMPP12_QUERY_REP://匹配新ptID
						MyPrintfSkel("Message CMPP12_QUERY_REP from SMC!\r\n");
						break;
					case CMPP12_SUBMIT_REP://匹配ptID,取SMC-MsgID
						MyPrintfSkel("Message CMPP12_SUBMIT_REP from SMC!\r\n");
						break;
					case CMPP12_DELIVERY: //根据ISDN,取SMC-SEQI
						{
							STRUCT_CMPP12_DELIVERY *pHead2;
							pHead2 = (STRUCT_CMPP12_DELIVERY *)pMsg;
							char cTmp[256];
							if(pHead2->cRegistered_Delivery == 1)//状态报告
							{sprintf(cTmp,"Message CMPP12_DELIVERY_ST [From:%s] from SMC!\r\n",pHead2->szSrc_terminalID);}
							else
							{sprintf(cTmp,"Message CMPP12_DELIVERY_SM [From:%s] from SMC!\r\n",pHead2->szSrc_terminalID);}
							MyPrintfSkel(cTmp);
						}
						break;
					case CMPP12_DELIVERY_REP://匹配SMC-SEQID
						MyPrintfSkel("Message ESME_DELIVER_SM_RESP to SMC!\r\n");
						break;
					default:
					    break;
					}
				}
				return;
			};
	
		void OutPutSession(char *pMsg)
		{
			char cBuff[2048];
			MsgToHexBuff(cBuff,pMsg);
			if(TraceOne == 1)//如果设定跟踪
			{
				//取消息类型
				DWORD dwCommandId=ntohl(*(DWORD *)(pMsg+4));
				switch(dwCommandId )
				{
					//平台接口
					case TRP_SUBMIT://匹配手机号,得到PTID
						STRUCT_SUBMIT *pSubmitMsg;
						pSubmitMsg = (STRUCT_SUBMIT *)pMsg;
						if(0 == strcmp(TraceIsdn, pSubmitMsg->sCMPP12Submit.szDest_terminal_ids))
						{
							TracePtSeqId = pSubmitMsg->sSubmitHeader.sHeader.dwSeqNo;
							MyPrintf("Message TRP_SUBMIT from PT!\r\n",cBuff);
						}
						break;
					case TRP_QUERY://匹配SMC-ID,得到PTID
						{
							STRUCT_QUERY *pQeryMsg;
							CString a;
							pQeryMsg = (STRUCT_QUERY *)pMsg;
							a = pQeryMsg->sMsgID.szMsgID;
							if( a == TraceMsgId)
							{
								TracePtSeqId = pQeryMsg->sHeader.dwSeqNo;
								MyPrintf("Message TRP_QUERY from PT!\r\n",cBuff);
							}
						}
						break;
					case TRP_DELIVERY://匹配SMC-SEQID
						STRUCT_DELIVERY *pDilivery;
						pDilivery = (STRUCT_DELIVERY *)pMsg;
						if(pDilivery->sDeliveryHeader.sHeader.dwSeqNo == TraceSmcSeqId)
							MyPrintf("Message TRP_DELIVERY to PT!\r\n",cBuff);
						break;
					case TRP_MSG_REPORT://匹配SMC-SEQID
						STRUCT_MSG_REPORT *pMsgReport;
						pMsgReport =(STRUCT_MSG_REPORT *)pMsg;
						if(pMsgReport->sMsgReportToApp.sHeader.dwSeqNo == TraceSmcSeqId)
							MyPrintf("Message TRP_MSG_REPORT to PT!\r\n",cBuff);
						break;
					case TRP_UNIDATA_ACK://=TRP_SUBMIT_RSP, 匹配ptID
						STRUCT_UNIDATA_ACK *pUniDataAck;
						pUniDataAck = (STRUCT_UNIDATA_ACK *)pMsg;
						if(pUniDataAck->sHeader.dwSeqNo == TracePtSeqId)
							MyPrintf("Message TRP_UNIDATA_ACK to PT!\r\n",cBuff);
						break;

					//CMPP interface
					case CMPP12_SUBMIT:  //匹配ptID
						STRUCT_CMPP12_MSG_HEADER *pHead0;
						pHead0 = (STRUCT_CMPP12_MSG_HEADER *)pMsg;
						if(pHead0->dwSequence_ID == TracePtSeqId)
							MyPrintf("Message CMPP12_SUBMIT to SMC!\r\n",cBuff);
						break;
					case CMPP12_QUERY://匹配ptID
						STRUCT_CMPP12_MSG_HEADER *pHead1;
						pHead1 = (STRUCT_CMPP12_MSG_HEADER *)pMsg;
						if(pHead1->dwSequence_ID == TracePtSeqId)
							MyPrintf("Message CMPP12_QUERY to SMC!\r\n",cBuff);
						break;
					case CMPP12_SUBMIT_REP://匹配ptID,取SMC-MsgID
						DWORD dwTmpPtid;
						STRUCT_CMPP12_SUBMIT_REP *pMsgMtRsp;
						pMsgMtRsp = (STRUCT_CMPP12_SUBMIT_REP *)pMsg;
						dwTmpPtid = pMsgMtRsp->sHeader.dwSequence_ID; //PTSeqID
						if(dwTmpPtid == TracePtSeqId)
						{	
							MyPrintf("Message CMPP12_SUBMIT_REP from SMC!\r\n",cBuff);
							TraceMsgId.Format("%d",pMsgMtRsp->Msg_ID);
						}
						break;
					case CMPP12_DELIVERY: //根据ISDN,取SMC-SEQID
						STRUCT_CMPP12_DELIVERY *pMsgDelivery;
						pMsgDelivery = (STRUCT_CMPP12_DELIVERY *)pMsg;
						if(pMsgDelivery->cRegistered_Delivery == 0)//状态报告
						{
							if(NULL != strstr( pMsgDelivery->szDestinationID,TraceIsdn))
							{
								TraceSmcSeqId =pMsgDelivery->sHeader.dwSequence_ID;
								MyPrintf("Message CMPP12_DELIVERY_ST from SMC!\r\n",cBuff);
							}
						}
						else
						{
							if(NULL != strstr(pMsgDelivery->szSrc_terminalID,TraceIsdn))
							{
								TraceSmcSeqId =pMsgDelivery->sHeader.dwSequence_ID;
								MyPrintf("Message CMPP12_DELIVERY_SM from SMC!\r\n",cBuff);
							}
						}
						break;
					case CMPP12_DELIVERY_REP://匹配SMC-SEQID
						{
							STRUCT_CMPP12_DELIVER_REPTag *pDelivRsp;
							CString strTmp;
							pDelivRsp = (STRUCT_CMPP12_DELIVER_REPTag *)pMsg;
							if(TraceSmcSeqId == pDelivRsp->sHeader.dwSequence_ID)
								MyPrintf("Message CMPP12_DELIVERY_REP to SMC!\r\n",cBuff);
						}
						break;
					default:
					    break;
					}
				}
				return;
			};
			
			void  OutUsage(int color,char *s)
			{
				char  cLogInfo[128];
   
				cLogInfo[0]='\0';
				sprintf(cLogInfo,"[%s] %s",CTime::GetCurrentTime().Format("%d-%m %H:%M:%S"),s);
				g_MainFrame->PrintInput(color,cLogInfo);
			};

			void MsgToHexBuff(char *cBuff, char *pMsg)
			{
				BYTE *pTmp = (BYTE *)pMsg;
				int iLen = ntohl(*((DWORD *)pMsg));
				char cUnit[16];

				cBuff[0]='\0';
				if(iLen>1024) 
				{
					strcat(cBuff,"Error message format!\r\n");
					return;
				}

				for(int i=0; i<iLen; i++)
				{
					if((i%16 == 0)&&(i>0))
						strcat(cBuff,"\r\n");
					memset(cUnit,0x00,16);
					sprintf(cUnit,"%x%x_",(*pTmp)/16, (*pTmp)%16);
					strcat(cBuff, cUnit);
					if(strlen(cBuff) > 1020)
						break;
					pTmp++;
				}
				memset(cUnit,0x00,16);
				sprintf(cUnit, "iLen=%d\r\n",iLen);
				strcat(cBuff, cUnit);
			};
		private:
			BOOL      TraceOne;
			BOOL      TraceAllMsg;
			char      TraceIsdn[21];
			DWORD     TracePtSeqId;
			CString   TraceMsgId;
			DWORD     TraceSmcSeqId;
			
			int       iMoCount;
			int       iMtCount;

		public:
			int       iPrintTest;

};

extern TOutInterface Out;
#define LogMsg(s) Out.OutPutAll(s);\
				  Out.OutPutSession(s)    //black then blue
#define LogErr(s) Out.OutUsage(2,s)   //red
#define LogInf(s) Out.OutUsage(0,s)   //black
#define LogInfPara(x,y) \
	    char cTmp[256];\
		cTmp[0]='\0';\
		sprintf(cTmp,x,y);\
		LogInf(cTmp);
#define LogErrPara(x,y) \
	    char cTmp[256];\
		cTmp[0]='\0';\
		sprintf(cTmp,x,y);\
		LogErr(cTmp);
#define LogTest(s) \
		{\
		   if(Out.iPrintTest == 1)\
				LogInf(s);\
		}

#define MoAdd()   Out.MoCountAdd()
#define MtAdd()   Out.MtCountAdd()



BOOL ReadInitFile();
void StrPrintHex(char *pCur, int iLen);
void MakeSmppHeader(char* szbuf,int nTotalLength,int nCommandID);
int  StrnCopy(char* szbuf,int nMaxstrlen,char* szSource);
void convPDUToBin(char *buf, WORD *sm_length);
BYTE strToByte(char szTemp[]);
void convCToUnicode(char *buf, unsigned char *sm_length);
char GetHex(char c);
//PDU码==》PDU串
void byteToStr(char sourcebuf[], BYTE Msg_Length, char *Destbuf);
char * CheckPacketInBuf(char buf[]);
#endif

⌨️ 快捷键说明

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