int procReq( unsigned char *ReqBuf, int ReqLen, int RspSock ) { struct application req_stru; char tmp_buf[BUFFSIZE]; unsigned char tmp_mac[16+1]; /* * 将收到的8583包解到请求结构req_stru中 */ memset(&req_stru, 0, sizeof(req_stru)); if ( unpack8583( &req_stru, ReqBuf, ReqLen ) == INVALID_PACK ) { ErrorLog(ERROR, "invalid pack or get channel fail"); return FAIL; } /* * 获取交易类型定义 */ if ( getTransType(&req_stru) != SUCC ) { ErrorLog(TRACE,"获取交易类型定义失败!!"); strcpy( req_stru.return_code, ERR_NOT_SUPPORTED ); rspError(&req_stru, RspSock); DispMoni( &req_stru, NULL ); WebDispMoni( &req_stru, NULL, gszWebIp, gnWebPort ); return FAIL; } /* * 获取终端对应信息 (包括密钥等信息) */ if ( getTermInfo(&req_stru) != SUCC ) { ErrorLog(TRACE,"获取终端对应信息失败!!"); strcpy( req_stru.return_code, ERR_INVALID_TERM ); rspError(&req_stru, RspSock); DispMoni( &req_stru, NULL ); WebDispMoni( &req_stru, NULL, gszWebIp, gnWebPort ); return FAIL; } /* * 检查报文MAC,签到、结算、批上送、参数下载、等交易不检查 */ if( req_stru.trans_type != LOGIN && req_stru.trans_type != LOGOUT && req_stru.trans_type != SETTLE && req_stru.trans_type != SETTLE2 && req_stru.trans_type != BATCHUP && req_stru.trans_type != DOWNLOAD ) { ErrorLog(TRACE,"开始校验MAC..."); /* 计算报文MAC */ memset(tmp_mac, 0, sizeof(tmp_mac)); if( SUCC != unionpay_calc_mac( ReqBuf+11, ReqLen-11-8, req_stru.MacKey, tmp_mac ) ) { ErrorLog(TRACE,"校验MAC失败!"); strcpy( req_stru.return_code, ERR_MAC ); rspError(&req_stru, RspSock); return FAIL; } /* 比较计算结果和上送MAC */ if ( memcmp( tmp_mac, req_stru.mac, 8 ) != 0 ) { ErrorLog(TRACE,"校验MAC失败!"); strcpy( req_stru.return_code, ERR_MAC ); rspError(&req_stru, RspSock); memset(tmp_buf, 0, sizeof(tmp_buf) ); sprintf( tmp_buf, "[%s]POSP数据包MAC校验错,怀疑非法攻击!", req_stru.terminal_id ); SendWarningMsg( TENPAY_ERR_MAC, tmp_buf, gszWarnIp, gnWarnPort ); DispMoni( &req_stru, NULL ); WebDispMoni( &req_stru, NULL, gszWebIp, gnWebPort ); return FAIL; } } /* * 用进程号作为消息类型将请求结构发送到路由进程skernel */ req_stru.source_msgtype = getpid(); if( SUCC != SendRoute(req_stru.source_msgtype, &req_stru) ) { ErrorLog(ERROR, "send to skernel error"); strcpy(req_stru.return_code, ERR_SYSTEM_ERROR); rspError(&req_stru, RspSock); DispMoni( &req_stru, NULL ); WebDispMoni( &req_stru, NULL, gszWebIp, gnWebPort ); return FAIL; } ErrorLog(TRACE, "SendRouter OK..................."); return SUCC; }
void LanguageModel::getTermInfo(const char *term, offset *termFrequency, offset *documentCount) { LocalLock lock(this); getTermInfo(getTermID((char*)term), termFrequency, documentCount); } // end of getTermInfo(char*, offset*, offset*)