📄 uppackdeal.cpp
字号:
{ time_t Schedule = (int)pUnit->RecvTime + Relay_Interval; tmptime = localtime( &Schedule); sprintf( MtLog.SentTime, "%d%02d%02d%02d%02d%02d", tmptime->tm_year + 1900, tmptime->tm_mon + 1, tmptime->tm_mday, tmptime->tm_hour, tmptime->tm_min, tmptime->tm_sec); //写入下行转发记录缓存表 MyDB->WrMT_Queue(&MtLog, CMPP_PROTOCOL,TAB_MT_Queue); sprintf(sSysEvent,"Warning: A CMPP_Submit to UpNode[%d] is saved to MT_Queue temporarily!",UpNode[NodeNum].NodeID); WrSystemLog->WriteLog(sSysEvent,SYSTEMLOG); } /* if((LOG_DB==0) || (LOG_DB==2)) { //写入Submit_Failed日志文件 if((RetCode = UpNode[NodeNum].WrSubmit_FailLog->WriteLog(&MtLog,CMPP_SUBMIT_LOG))>0) { sprintf(sSysEvent,"Error[%d]: UpCMPPDeal Writing CMPP_Submit_FailLog File!",RetCode); WrSystemLog->WriteLog(sSysEvent,SYSTEMLOG); //写系统日志 break; } }*/ //------------------------------------------------------------ free(SUnit.Pack); //删除包,释放内存 #ifdef DEBUG int UnitNum = UpNode[NodeNum].SentQ.GetSize(); //获取已发送窗口的占用数 printf("\n UpCMPPDeal[%s]: An unsentable CMPP_Submit[%d] is deleted and clean! SentQ_Size=[%d]\n",timebuf,ntohl(pSubmitRsp->Head.Sequence_Id),UnitNum); #endif } break; } }//switch free(pUnit->Pack); //释放接收包所占内存,在TCPsocket::RecvPack()中malloc break; } //================================================================ case CMPP_ACTIVE_TEST_RESP: { CMPP_Active_Test *pActiveTest; pActiveTest = (CMPP_Active_Test *)pUnit->Pack; //从已发送队列中删除对应的等应答的单元,并释放原ActiveTest包所占内存 if(UpNode[NodeNum].SentQ.Clean(ntohl(pActiveTest->Sequence_Id)) == false) { sprintf(sSysEvent," Error: UpCMPPDeal Can't find the corresponding CMPP_ActiveTest Pack[%d]!\n",ntohl(pActiveTest->Sequence_Id)); WrSystemLog->WriteLog(sSysEvent,SYSTEMLOG); } else { #ifdef DEBUG printf("\nUpCMPPDeal[%s]: The corresponding CMPP_ActiveTest[%d] is clean successfully!\n",timebuf,ntohl(pActiveTest->Sequence_Id)); #endif } free(pUnit->Pack); //释放接收包所占内存,在TCPsocket::RecvPack()中malloc break; } //================================================================ case CMPP_ACTIVE_TEST: { #ifdef DEBUG printf("\nUpCMPPDeal: Got an CMPP_ACTIVE_TEST[%x]!\n",Sequence); #endif free(pUnit->Pack); //释放接收包所占内存,在TCPsocket::RecvPack()中malloc break; } //================================================================ case CMPP_TERMINATE: { #ifdef DEBUG printf("\nUpCMPPDeal: Got an CMPP_TERMINATE[%x]!\n",Sequence); #endif free(pUnit->Pack); //释放接收包所占内存,在TCPsocket::RecvPack()中malloc break; } //================================================================ case CMPP_TERMINATE_RESP: { #ifdef DEBUG printf("\nUpCMPPDeal: Got an CMPP_TERMINATE_RESP[%x]!\n",Sequence); #endif free(pUnit->Pack); //释放接收包所占内存,在TCPsocket::RecvPack()中malloc break; } //----------------------- case CMPP_QUERY_RESP: { #ifdef DEBUG printf("\nUpCMPPDeal: Got an CMPP_QUERY_RESP[%x]!\n",Sequence); #endif free(pUnit->Pack); //释放接收包所占内存,在TCPsocket::RecvPack()中malloc break; } case CMPP_CANCEL_RESP: { #ifdef DEBUG printf("\nUpCMPPDeal: Got an CMPP_CANCEL_RESP[%x]!\n",Sequence); #endif free(pUnit->Pack); //释放接收包所占内存,在TCPsocket::RecvPack()中malloc break; } default: { #ifdef DEBUG printf("\nUpCMPPDeal: Got an Unexpected CMPP pack[%x],Sequence=[%x].\n",PackType,Sequence); #endif free(pUnit->Pack); //释放接收包所占内存,在TCPsocket::RecvPack()中malloc break; } }//switch() return 0;}//=====================================================================================//==================================SMGP应答包构造模块=================================//=====================================================================================int CGateWay::UpSMGPDeal(RecvQUnit * pUnit, int NodeNum){ //int RetCode; int PackType; int Sequence; struct tm *tmptime; char timebuf[16]; char sSysEvent[SYS_EVENT_LEN]; CFunc MyFun; WrSystemLog->getTime(timebuf); PackType = ntohl(*(int *)(pUnit->Pack + 4)); Sequence = ntohl(*(int *)(pUnit->Pack + 8)); switch(PackType) { case REQUEST_ID_DELIVER: { #ifdef DEBUG //printf("\nUpSMGPDeal: Got an SMGP_DELIVER!\n"); #endif SMGP_Deliver *pDeliver; pDeliver = (SMGP_Deliver *)pUnit->Pack; /*if(pDeliver->nMsgFormat==8) //编码格式转换Unicode->GBK { pDeliver->nMsgLength = MyFun.CodeConvert("Unicode","GBK",pDeliver->Deliver_Msg.sMsgContent,pDeliver->Deliver_Msg.sMsgContent); }*/ /*if((ShowLog==3) || (ShowLog==1)) //显示收到的Deliver包 { printf("\n==============收到用户发来的短信============\n"); printf("接收时间:%s\n用户手机号:%s\n目的号码:%s\n短信内容:%s",timebuf,pDeliver->sSrcTermId,pDeliver->sDestTermId,pDeliver->sMsgContent); printf("\n============================================ \n"); }*/ if(!pDeliver->nIsReport) { //路由转发 //或者写MO_Queue表,为本地业务提供接口 //if(pDeliver->sDestTermId[strlen(SP_Id)]='0') //目的号码为0204440+'0',则写入本地业务接口表 //{ //MysqlDb-> //} //=====================debug======================== //----------------- form a SMGP_Submit ----------------- SMGP_Submit * sSubmit = (SMGP_Submit *)malloc(sizeof(SMGP_Submit)); memset(sSubmit,0,sizeof(SMGP_Submit)); sSubmit->nMsgType=0; sSubmit->nNeedReport=1; sSubmit->nPriority=0; strcpy(sSubmit->sServerId,"Test"); strcpy(sSubmit->sFeeType,"00"); strcpy(sSubmit->sFeeCode,"0"); strcpy(sSubmit->sFixedFee,"0"); sSubmit->nMsgFormat=15; //sSubmit->sValidTime //sSubmit->sAtTime strcpy(sSubmit->sReplyPath,"0204440"); strcpy(sSubmit->sChargeTermId,pDeliver->sSrcTermId); sSubmit->nDestTermIdCount=1; strcpy(sSubmit->sDestTermId,pDeliver->sSrcTermId); sSubmit->nMsgLength = 42 + pDeliver->nMsgLength; char tmpstr[28]; memset(tmpstr,0,28); if(pDeliver->nMsgLength<=26) strncpy(tmpstr,pDeliver->Deliver_Msg.sMsgContent,pDeliver->nMsgLength); else strncpy(tmpstr,pDeliver->Deliver_Msg.sMsgContent,26); strcpy(sSubmit->sMsgContent,"您好!已收到您的短信‘"); strcat(sSubmit->sMsgContent,tmpstr); strcat(sSubmit->sMsgContent,"’,传动数码测试中!"); sSubmit->msgHead.nPacketLength = htonl(sizeof(SMGP_Submit) - MAX_SM_LEN + sSubmit->nMsgLength); sSubmit->msgHead.nRequestId = htonl(REQUEST_ID_SUBMIT); //------------------------------------------------- sSubmit->msgHead.nSequenceId = htonl(UpNode[NodeNum].GetSequence()); #ifdef DEBUG Sequence = ntohl(sSubmit->msgHead.nSequenceId); #endif UpNode[NodeNum].PutSubmit(sSubmit, UpNode[NodeNum].NodeID, 0); //=====================debug end====================== } else { //路由转发 //改写SMGP_Submit转发日志表中的report内容 #ifdef DEBUG printf("\nUpSMGPDeal: Got a SMGP_report[%x]!\n",Sequence); #endif } break; } case REQUEST_ID_SUBMIT_RESP: { #ifdef DEBUG //printf("\nUpSMGPDeal: Got an SMGP_SUBMIT_RESP[%x]!\n",Sequence); #endif SMGP_SubmitResp *pSubmitRsp; pSubmitRsp = (SMGP_SubmitResp *)pUnit->Pack; //从已发送队列中找出并删除对应的等应答的单元 SendQUnit SUnit; if(UpNode[NodeNum].SentQ.FindDel(ntohl(pSubmitRsp->msgHead.nSequenceId), &SUnit) == false) { sprintf(sSysEvent," Error: UpSMGPDeal Can't find the corresponding SMGP_Submit Pack[%d]!\n",ntohl(pSubmitRsp->msgHead.nSequenceId)); WrSystemLog->WriteLog(sSysEvent,SYSTEMLOG); } //------形成Smgp_Submit_UpLog结构体,再写进日志文件---- Smgp_MT_Log SubmitLog; tmptime = localtime(&SUnit.SrcRecvTime); sprintf( SubmitLog.SrcRecvTime, "%d%02d%02d%02d%02d%02d", tmptime->tm_year + 1900, tmptime->tm_mon + 1, tmptime->tm_mday, tmptime->tm_hour, tmptime->tm_min, tmptime->tm_sec); SubmitLog.SrcNode = SUnit.SrcNode; //SubmitLog.SrcSequence = SUnit.SrcSequence; //转发包流水号 memcpy(&SubmitLog.MsgId_Echo, &SUnit.ID_Relate, sizeof(SubmitLog.MsgId_Echo)); tmptime = localtime(&pUnit->RecvTime); sprintf( SubmitLog.SentTime, "%d%02d%02d%02d%02d%02d", tmptime->tm_year + 1900, tmptime->tm_mon + 1, tmptime->tm_mday, tmptime->tm_hour, tmptime->tm_min, tmptime->tm_sec); //将Msg_ID转换成ASCII码字符串存储(以便写日志文件,计费) MyFun.HexToStr(pSubmitRsp->sMsgId,sizeof(pSubmitRsp->sMsgId),SubmitLog.MsgId); SubmitLog.Result = pSubmitRsp->nResult; SubmitLog.Submit = (SMGP_Submit *)SUnit.Pack; //检查应答状态,决定是否重发 switch(pSubmitRsp->nResult) { case 0://正确应答 { /*if((LOG_DB==0) || (LOG_DB==2)) //写入Submit转发日志文件 { //写入Submit日志文件,按是否转发包写两个日志文件????????? if((RetCode=UpNode[NodeNum].WrSubmitLog->WriteLog(&SubmitLog,SMGP_SUBMIT_LOG))>0) { sprintf(sSysEvent,"Error[%d]: UpSMGPDeal Writing SMGP_Submit pack into Log File!",RetCode); WrSystemLog->WriteLog(sSysEvent,SYSTEMLOG); //写系统日志 break; } }*/ if(LOG_DB > 0) //将Submit转发记录写入数据表 { //写入SMGP_Submit转发日志表??????????? } //------------------------------------------------------------ free(SUnit.Pack); //释放Submit包所占内存 #ifdef DEBUG printf("\n UpSMGPDeal[%s]: A successfully Sent SMGP_Submit[%d] is cleaned from SentQ and writen into Submit_UpLog File!\n",timebuf,ntohl(pSubmitRsp->msgHead.nSequenceId)); #endif break; } case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 8: default: //各种错误响应码 { if(SUnit.iResent) //可重发的请求包,或者发送失败的应答包 { //存到待发送队列 UpNode[NodeNum].SendQ->Wait_Put(SUnit); /*while(UpNode[NodeNum].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 printf("\n UpSMGPDeal[%s]: A SMGP_Submit Pack[%d] is transmited from SentQ to SendQ.\n",timebuf,ntohl(pSubmitRsp->msgHead.nSequenceId)); #endif } else //最大发送次数已满,仍未收到正确的应答包 { /*if((LOG_DB==0) || (LOG_DB==2)) //写入Submit转发日志文件 { //写入Submit_Failed日志文件 if((RetCode = UpNode[NodeNum].WrSubmit_FailLog->WriteLog(&SubmitLog,SMGP_SUBMIT_LOG))>0) { sprintf(sSysEvent,"Error[%d]: UpSMGPDeal Writing SMGP_Submit_FailLog File!",RetCode); WrSystemLog->WriteLog(sSysEvent,SYSTEMLOG); //写系统日志 break; } }*/ if(LOG_DB > 0) //将Submit转发记录写入数据表 { //写入SMGP_Submit_Failed失败日志表??????????? } //------------------------------------------------------------ free(SUnit.Pack); //删除包,释放内存 #ifdef DEBUG int UnitNum = UpNode[NodeNum].SentQ.GetSize(); //获取已发送窗口的占用数 printf("\n UpSMGPDeal[%s]: An unsentable SMGP_Submit[%d] is deleted and clean! SentQ_Size=[%d]\n",timebuf,ntohl(pSubmitRsp->msgHead.nSequenceId),UnitNum); #endif } break; }//default }//switch free(pUnit->Pack); //释放接收包所占内存,在TCPsocket::RecvPack()中malloc break; } case REQUEST_ID_ACTIVE_TEST_RESP: { SMGP_Head *pActiveTest; pActiveTest = (SMGP_Head *)pUnit->Pack; //从已发送队列中删除对应的等应答的单元,并释放原ActiveTest包所占内存 if(UpNode[NodeNum].SentQ.Clean(ntohl(pActiveTest->nSequenceId)) == false) { sprintf(sSysEvent,"\n Error: UpSMGPDeal Can't find the corresponding SMGP_ActiveTest Pack[%d]!\n",ntohl(pActiveTest->nSequenceId)); WrSystemLog->WriteLog(sSysEvent,SYSTEMLOG); } else { #ifdef DEBUG //printf("\nUpSMGPDeal: The corresponding ActiveTest Pack[%d] is clean!\n",ntohl(pActiveTest->nSequenceId)); #endif } #ifdef DEBUG int UnitNum = UpNode[NodeNum].SentQ.GetSize(); //获取已发送窗口的占用数 printf("\n UpSMGPDeal[%s]: A SMGP_ACTIVE_TEST_RESP[%d] is dealed, SentQ_Size=[%d] \n",timebuf,ntohl(pActiveTest->nSequenceId),UnitNum); #endif free(pUnit->Pack); //释放接收包所占内存,在TCPsocket::RecvPack()中malloc break; } case REQUEST_ID_ACTIVE_TEST: { #ifdef DEBUG printf("\nUpSMGPDeal: Got an SMGP_ACTIVE_TEST[%x]!\n",Sequence); #endif free(pUnit->Pack); //释放接收包所占内存,在TCPsocket::RecvPack()中malloc break; } case REQUEST_ID_EXIT_RESP: { #ifdef DEBUG printf("\nUpSMGPDeal: Got an SMGP_EXIT_RESP[%x]!\n",Sequence); #endif free(pUnit->Pack); //释放接收包所占内存,在TCPsocket::RecvPack()中malloc break; } //----------------------- case REQUEST_ID_QUERY_RESP: { #ifdef DEBUG printf("\nUpSMGPDeal: Got an SMGP_QUERY_RESP[%x]!\n",Sequence); #endif free(pUnit->Pack); //释放接收包所占内存,在TCPsocket::RecvPack()中malloc break; } default: { #ifdef DEBUG printf("\nUpSMGPDeal: Got an Unexpected SMGP pack[%x],Sequence=[%x].\n",PackType,Sequence); #endif free(pUnit->Pack); //释放接收包所占内存,在TCPsocket::RecvPack()中malloc break; } }//switch() return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -