void OdbcMsg::FillMsgStructure (UINT ErrCode, LPSTR lpMsgBuf, ODBCMXMSG_Def *MsgStruc, int actual_len) //************************************************************************ //* //* Function: FillMsgStructure //* //* Input Params: lpMsgBuf - The original message buffer //* //* Output Params: MsgStruc - will contain all message components //* //* Description: It will extract the message components based on the //* columns SQLState, and Message Text. //* it is assumed that the message structure is already clean //* //************************************************************************ { char tempStr[512]; char *szTmp; // verify that the message is long enough, otherwise no clean message to return if (actual_len >= 5) { // from character 1 to character 5 is the SQLCode strncpy(MsgStruc->lpsSQLState, lpMsgBuf, min(5, sizeof(MsgStruc->lpsSQLState)-1)); if (actual_len > 13) { // then we may have the help ID plus something for message text // from character 6 to character 10 is the Help ID // from character 12 on is the message text szTmp = &lpMsgBuf[11]; } else { // we don't have enough text to return sprintf(tempStr, MSG_INCOMPLETE, GetMsgId(ErrCode)); szTmp = tempStr; } } else { // return general SQLCode and error message strcpy(MsgStruc->lpsSQLState, GENERAL_SQLSTATE); sprintf(tempStr, MSG_INCOMPLETE, GetMsgId(ErrCode)); szTmp = tempStr; } MsgStruc->lpsMsgText = szTmp; }
void OdbcMsg::FillMsgStructure (UINT ErrCode, LPSTR lpMsgBuf, ODBCMXMSG_Def *MsgStruc, int actual_len) { char tempStr[MAX_ERROR_TEXT_LEN+1]; char *szTmp; // verify that the message is long enough, otherwise no clean message to return if (actual_len >= 5) { // from character 1 to character 5 is the SQLCode strncpy(MsgStruc->lpsSQLState, lpMsgBuf, min(5, sizeof(MsgStruc->lpsSQLState)-1)); if (actual_len > 13) { // then we may have the help ID plus something for message text // from character 6 to character 10 is the Help ID // from character 12 on is the message text szTmp = &lpMsgBuf[11]; } else { // we don't have enough text to return sprintf(tempStr, MSG_INCOMPLETE, GetMsgId(ErrCode)); szTmp = tempStr; } } else { // return general SQLCode and error message strcpy(MsgStruc->lpsSQLState, GENERAL_SQLSTATE); sprintf(tempStr, MSG_INCOMPLETE, GetMsgId(ErrCode)); szTmp = tempStr; } #ifndef COLLAPSED_CFGLIB MsgStruc->lpsMsgText = szTmp; #else strncpy(MsgStruc->lpsMsgText,szTmp,USER_ERROR_MAX); #endif }
bool CNetManager::Authentication() { LogObject; CConfigManager* pConfig = CConfigManager::GetInstance(); MD5 md5(pConfig->GetStopId().c_str()); string strKey = md5.hexdigest(); transform(strKey.begin(), strKey.end(), strKey.begin(), toupper); tagAuthentication stAuthen; stAuthen.head.command = Message_Login; stAuthen.head.messageType = MT_Dataset; stAuthen.head.strCityCode = pConfig->GetCityCode(); stAuthen.head.strServerIP = pConfig->GetServerIP(); stAuthen.head.strStopID = pConfig->GetStopId(); GetMsgId(stAuthen.head.strMsgID); stAuthen.strKey = strKey; CMessage message; message.SetMessage(Message_Login, (void*)&stAuthen); string strData; CJsonManager json; json.ToJson(message, strData); string strSend; strSend = START_FLAG; int nLen = strData.size(); strSend += nLen; strSend += strData; char *pBuffer = new char[strData.size() + 8]; memcpy(pBuffer, START_FLAG, 4); pBuffer[4] = nLen >> 24; pBuffer[5] = nLen >> 16; pBuffer[6] = nLen >> 8; pBuffer[7] = nLen; for (int ii =8; ii < (int)strData.size() + 8; ii++) { pBuffer[ii] = strData.at(ii - 8); } int nRes = send(m_sock, pBuffer, strSend.size() + 8, 0); if(nRes == SOCKET_ERROR) { DWORD dwError = WSAGetLastError(); std::stringstream sstr; sstr<<"发送登陆失败,SOCKET错误代码:"<<dwError; LogOutError(sstr.str().c_str()); sstr.str() = ""; } delete[] pBuffer; return true; }
// 1 byte msg_sender len + length of msg sender + 1byte msgid length + length of msgid + 4bytes msgparam len + length of msgparam. inline bool CheckMsgId(const std::string& netmsgbus_msgcontent, std::string& msgid) { // if(GetMsgId(netmsgbus_msgcontent, msgid)) { return FilterMgr::FilterByMsgId(msgid); } return false; }
void OdbcMsg::ReportError (ODBCMXMSG_Def * MsgStruc, UINT MessageId, UINT error_code) { char tempStr[512]; LPVOID lpMsgBuf; strcpy(MsgStruc->lpsSQLState, GENERAL_SQLSTATE); sprintf(tempStr, MSG_NOT_FOUND, GetMsgId(MessageId)); #ifndef COLLAPSED_CFGLIB MsgStruc->lpsMsgText = tempStr; #else strncpy(MsgStruc->lpsMsgText,tempStr,USER_ERROR_MAX); #endif return ; }
//************************************************************************ //* //* Function: ReportError //* //* Input Params: MsgStruc - The original message structure //* //* Output Params: MsgStruc - will contain a default error message with data //* //* Description: Empty message buffers //* //************************************************************************ void OdbcMsg::ReportError (ODBCMXMSG_Def * MsgStruc, UINT MessageId, UINT error_code) { char tempStr[512]; #ifdef _DEBUG LPVOID lpMsgBuf; FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, error_code, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language (LPTSTR) &lpMsgBuf, 0, NULL); // printf ("Error:[%s]\n", lpMsgBuf); LocalFree( lpMsgBuf ); #endif // use default error message (with message file message ID) strcpy(MsgStruc->lpsSQLState, GENERAL_SQLSTATE); sprintf(tempStr, MSG_NOT_FOUND, GetMsgId(MessageId)); MsgStruc->lpsMsgText = tempStr; return ; }
void OdbcMsg::FillMsgStructure (UINT ErrCode, LPSTR lpMsgBuf, ODBCMXMSG_Def *MsgStruc, int actual_len) { char tempStr[MAX_ERROR_TEXT_LEN+1]; char *szTmp; int i = 0; int found = 0; // verify that the message is long enough, otherwise no clean message to return if (actual_len >= 12) { // sqlState is the third token in the string while ((found != 2) && (i < actual_len)) { if (lpMsgBuf[i] == ' ') found++; i++; } if ((found == 2) && (i < actual_len)) strncpy(MsgStruc->lpsSQLState, &lpMsgBuf[i], min(5, sizeof(MsgStruc->lpsSQLState)-1)); else strncpy(MsgStruc->lpsSQLState, GENERAL_SQLSTATE, 5); while ((found != 4) && (i < actual_len)) { if (lpMsgBuf[i] == ' ') found++; i++; } // do we have the full text available? if ((found == 4) && (i < actual_len)) { // then we may have the help ID plus something for message text szTmp = &lpMsgBuf[i-1]; } else { // we don't have enough text to return sprintf(tempStr, MSG_INCOMPLETE, GetMsgId(ErrCode)); szTmp = tempStr; } } else { // return general SQLCode and error message strcpy(MsgStruc->lpsSQLState, GENERAL_SQLSTATE); sprintf(tempStr, MSG_INCOMPLETE, GetMsgId(ErrCode)); szTmp = tempStr; } #ifndef COLLAPSED_CFGLIB MsgStruc->lpsMsgText = szTmp; #else strncpy(MsgStruc->lpsMsgText,szTmp,USER_ERROR_MAX); #endif }