DWORD WINAPI CaptureARPReplies(LPVOID pScanParams) { pcap_t *lIFCHandle = NULL; char lTemp[1024]; char lFilter[1024]; bpf_u_int32 lNetMask; struct bpf_program lFCode; int lPcapRetVal = 0; PETHDR lEHdr = NULL; PARPHDR lARPHdr = NULL; u_char *lPktData = NULL; struct pcap_pkthdr *lPktHdr = NULL; PSCANPARAMS lScanParams = (PSCANPARAMS) pScanParams; unsigned char lEthDstStr[MAX_MAC_LEN+1]; unsigned char lEthSrcStr[MAX_MAC_LEN+1]; unsigned char lARPEthDstStr[MAX_MAC_LEN+1]; unsigned char lARPEthSrcStr[MAX_MAC_LEN+1]; unsigned char lARPIPDstStr[MAX_IP_LEN+1]; unsigned char lARPIPSrcStr[MAX_IP_LEN+1]; if ((lIFCHandle = pcap_open((char *) lScanParams->IFCString, 65536, PCAP_OPENFLAG_PROMISCUOUS, 1, NULL, lTemp)) != NULL) { ZeroMemory(&lFCode, sizeof(lFCode)); ZeroMemory(lFilter, sizeof(lFilter)); _snprintf(lFilter, sizeof(lFilter) - 1, "arp"); lNetMask = 0xffffff; // "255.255.255.0" // Compile the filter if(pcap_compile(lIFCHandle, &lFCode, (const char *) lFilter, 1, lNetMask) >= 0) { // Set the filter if(pcap_setfilter(lIFCHandle, &lFCode) >= 0) { while ((lPcapRetVal = pcap_next_ex(lIFCHandle, &lPktHdr, (const u_char **) &lPktData)) >= 0) { if (lPcapRetVal == 1) { lEHdr = (PETHDR) lPktData; lARPHdr = (PARPHDR) (lPktData + sizeof(ETHDR)); ZeroMemory(lEthDstStr, sizeof(lEthDstStr)); ZeroMemory(lEthSrcStr, sizeof(lEthSrcStr)); ZeroMemory(lARPEthSrcStr, sizeof(lARPEthSrcStr)); ZeroMemory(lARPEthDstStr, sizeof(lARPEthDstStr)); ZeroMemory(lARPIPDstStr, sizeof(lARPIPDstStr)); ZeroMemory(lARPIPSrcStr, sizeof(lARPIPSrcStr)); MAC2String(lEHdr->ether_shost, lEthSrcStr, sizeof(lEthSrcStr)-1); MAC2String(lEHdr->ether_dhost, lEthDstStr, sizeof(lEthDstStr)-1); MAC2String(lARPHdr->sha, lARPEthSrcStr, sizeof(lARPEthSrcStr)-1); MAC2String(lARPHdr->tha, lARPEthDstStr, sizeof(lARPEthDstStr)-1); IP2String(lARPHdr->tpa, lARPIPDstStr, sizeof(lARPIPDstStr)-1); IP2String(lARPHdr->spa, lARPIPSrcStr, sizeof(lARPIPSrcStr)-1); if (ntohs(lARPHdr->oper) == ARP_REPLY) { ZeroMemory(lTemp, sizeof(lTemp)); snprintf(lTemp, sizeof(lTemp)-1, "\n Operation: %s (%d)\n MAC : %s -> %s\n ARP : %s -> %s\n IP : %s -> %s\n", (ntohs(lARPHdr->oper) == ARP_REQUEST)? "ARP Request" : "ARP Reply", lARPHdr->oper, lEthSrcStr, lEthDstStr, lARPEthSrcStr, lARPEthDstStr, lARPIPSrcStr, lARPIPDstStr); LogMsg(lTemp); } } } } } } return(0); }
/* --------------------------------------------------------- TestSQLExecute --------------------------------------------------------- */ PassFail TestSQLExecute(TestInfo *pTestInfo, int MX_MP_SPECIFIC) { TEST_DECLARE; RETCODE returncode; SQLHANDLE henv; SQLHANDLE hdbc; SQLHANDLE hstmt; TCHAR *ExecStr[15]; TCHAR *szInput[] = {_T("Inst char"),_T("Inst vchar"),_T("1234.56789"),_T("1234.56789"),_T("1200"),_T("12000"),_T("123.45"),_T("123.45"),_T("123.45"),_T("1993-07-01"),_T("09:45:30"),_T("1993-08-02 08:44:31.001"),_T("120000"),_T("1234567890.56789"),_T("1234567890.456789"),_T("1234567890.456789"),_T("0.01234567890123456789"),_T("1234.56789"),_T("1234567890.56789"),_T("12345678901234567890.0123456789"),_T("Inst char"),_T("Inst vchar")}; SQLLEN cbInput = SQL_NTS; SQLUSMALLINT i = 0; SQLSMALLINT Type[] = {SQL_WCHAR,SQL_WVARCHAR,SQL_DECIMAL,SQL_NUMERIC,SQL_SMALLINT,SQL_INTEGER,SQL_REAL,SQL_FLOAT,SQL_DOUBLE,SQL_DATE,SQL_TIME,SQL_TIMESTAMP,SQL_BIGINT,SQL_NUMERIC,SQL_NUMERIC,SQL_NUMERIC,SQL_NUMERIC,SQL_NUMERIC,SQL_NUMERIC,SQL_NUMERIC,SQL_WCHAR,SQL_WVARCHAR}; SQLUINTEGER ColPrec[] = {254,254,10,10,5,10,7,15,15,10,8,26,19,19,19,128,128,10,18,30,254,254}; SQLSMALLINT ColScale[]= {0,0,5,5,0,0,0,0,0,0,0,0,0,0,6,0,128,5,5,10,0,0}; short CCharOutput1,CCharOutput2; SQLLEN OutputLen1,OutputLen2; int actual_insert=0,num_insert=0; SWORD param = 0; //=========================================================================================================== var_list_t *var_list; var_list = load_api_vars(_T("SQLExecute"), charset_file); if (var_list == NULL) return FAILED; //print_list(var_list); ExecStr[0] = var_mapping(_T("SQLExecute_ExecStr_0"), var_list); ExecStr[1] = var_mapping(_T("SQLExecute_ExecStr_1"), var_list); ExecStr[2] = var_mapping(_T("SQLExecute_ExecStr_2"), var_list); ExecStr[3] = var_mapping(_T("SQLExecute_ExecStr_3"), var_list); ExecStr[4] = var_mapping(_T("SQLExecute_ExecStr_4"), var_list); ExecStr[5] = var_mapping(_T("SQLExecute_ExecStr_5"), var_list); ExecStr[6] = var_mapping(_T("SQLExecute_ExecStr_6"), var_list); ExecStr[7] = var_mapping(_T("SQLExecute_ExecStr_7"), var_list); ExecStr[8] = var_mapping(_T("SQLExecute_ExecStr_8"), var_list); ExecStr[9] = var_mapping(_T("SQLExecute_ExecStr_9"), var_list); ExecStr[10] = var_mapping(_T("SQLExecute_ExecStr_10"), var_list); ExecStr[11] = var_mapping(_T("SQLExecute_ExecStr_11"), var_list); ExecStr[12] = var_mapping(_T("SQLExecute_ExecStr_12"), var_list); ExecStr[13] = var_mapping(_T("SQLExecute_ExecStr_13"), var_list); ExecStr[14] = var_mapping(_T("SQLExecute_ExecStr_14"), var_list); //================================================================================================= LogMsg(LINEBEFORE+SHORTTIMESTAMP,_T("Begin testing API => SQLExecute.\n")); TEST_INIT; TESTCASE_BEGIN("Setup for SQLExecute tests\n"); if(!FullConnect(pTestInfo)){ LogMsg(NONE,_T("Unable to connect\n")); TEST_FAILED; TEST_RETURN; } henv = pTestInfo->henv; hdbc = pTestInfo->hdbc; hstmt = (SQLHANDLE)pTestInfo->hstmt; returncode = SQLAllocStmt((SQLHANDLE)hdbc, &hstmt); if(!CHECKRC(SQL_SUCCESS,returncode,"SQLAllocStmt")){ LogAllErrors(henv,hdbc,hstmt); TEST_FAILED; TEST_RETURN; } returncode=SQLExecDirect(hstmt,(SQLTCHAR*)ExecStr[4],SQL_NTS); returncode=SQLExecDirect(hstmt,(SQLTCHAR*)ExecStr[5],SQL_NTS); if(!CHECKRC(SQL_SUCCESS,returncode,"SQLExecDirect")){ LogAllErrors(henv,hdbc,hstmt); TEST_FAILED; TEST_RETURN; } returncode=SQLExecDirect(hstmt,(SQLTCHAR *)ExecStr[6],SQL_NTS); if(!CHECKRC(SQL_SUCCESS,returncode,"SQLExecDirect")){ LogAllErrors(henv,hdbc,hstmt); TEST_FAILED; TEST_RETURN; } returncode=SQLExecDirect(hstmt,(SQLTCHAR*)ExecStr[7],SQL_NTS); if(!CHECKRC(SQL_SUCCESS,returncode,"SQLExecDirect")){ LogAllErrors(henv,hdbc,hstmt); TEST_FAILED; TEST_RETURN; } returncode=SQLExecDirect(hstmt,(SQLTCHAR*)ExecStr[8],SQL_NTS); if(!CHECKRC(SQL_SUCCESS,returncode,"SQLExecDirect")){ LogAllErrors(henv,hdbc,hstmt); TEST_FAILED; TEST_RETURN; } TESTCASE_END; // end of setup TESTCASE_BEGIN("Test #1: Positive Functionality of SQLExecute\n"); returncode = SQLPrepare(hstmt,(SQLTCHAR *)ExecStr[9],SQL_NTS); if(!CHECKRC(SQL_SUCCESS,returncode,"SQLPrepare")){ LogAllErrors(henv,hdbc,hstmt); TEST_FAILED; } returncode = SQLExecute(hstmt); if(!CHECKRC(SQL_SUCCESS,returncode,"SQLExecute")){ LogAllErrors(henv,hdbc,hstmt); TEST_FAILED; } returncode = SQLBindCol(hstmt,1,SQL_C_SHORT,&CCharOutput1,0,&OutputLen1); if(!CHECKRC(SQL_SUCCESS,returncode,"SQLBindCol")){ LogAllErrors(henv,hdbc,hstmt); TEST_FAILED; } returncode = SQLBindCol(hstmt,2,SQL_C_SHORT,&CCharOutput2,0,&OutputLen2); if(!CHECKRC(SQL_SUCCESS,returncode,"SQLBindCol")){ LogAllErrors(henv,hdbc,hstmt); TEST_FAILED; } while (returncode != SQL_NO_DATA_FOUND) { returncode = SQLFetch(hstmt); if (returncode != SQL_NO_DATA_FOUND) { if(!CHECKRC(SQL_SUCCESS,returncode,"SQLFetch")) { TEST_FAILED; LogAllErrors(henv,hdbc,hstmt); } } } SQLFreeStmt(hstmt,SQL_CLOSE); returncode = SQLPrepare(hstmt,(SQLTCHAR *)ExecStr[10],SQL_NTS); if(!CHECKRC(SQL_SUCCESS,returncode,"SQLPrepare")){ LogAllErrors(henv,hdbc,hstmt); TEST_FAILED; } returncode = SQLExecute(hstmt); if(!CHECKRC(SQL_SUCCESS,returncode,"SQLExecute")){ LogAllErrors(henv,hdbc,hstmt); TEST_FAILED; } SQLFreeStmt(hstmt,SQL_CLOSE); SQLExecDirect(hstmt,(SQLTCHAR*)ExecStr[4],SQL_NTS); TESTCASE_END; TESTCASE_BEGIN("Test #2: Positive Functionality of SQLExecute\n"); returncode = SQLExecDirect(hstmt,(SQLTCHAR*)ExecStr[0],_tcslen(ExecStr[0])); /* cleanup */ returncode = SQLPrepare(hstmt,(SQLTCHAR*)ExecStr[1],_tcslen(ExecStr[1])); if(!CHECKRC(SQL_SUCCESS,returncode,"SQLPrepare")){ LogAllErrors(henv,hdbc,hstmt); TEST_FAILED; } returncode = SQLExecute(hstmt); if(!CHECKRC(SQL_SUCCESS,returncode,"SQLExecute")){ LogAllErrors(henv,hdbc,hstmt); TEST_FAILED; } TESTCASE_END; TESTCASE_BEGIN("Test #3: Positive Functionality of SQLExecute with SQL_NTS\n"); returncode = SQLPrepare(hstmt,(SQLTCHAR*)ExecStr[2],SQL_NTS); if(!CHECKRC(SQL_SUCCESS,returncode,"SQLPrepare")){ LogAllErrors(henv,hdbc,hstmt); TEST_FAILED; } returncode = SQLExecute(hstmt); if(!CHECKRC(SQL_SUCCESS,returncode,"SQLExecute")){ LogAllErrors(henv,hdbc,hstmt); TEST_FAILED; } TESTCASE_END; TESTCASE_BEGIN("Test #4: Positive Functionality of SQLPrepare then SQLExecute twice\n"); returncode = SQLPrepare(hstmt,(SQLTCHAR*)ExecStr[2],_tcslen(ExecStr[2])); if(!CHECKRC(SQL_SUCCESS,returncode,"SQLPrepare")){ LogAllErrors(henv,hdbc,hstmt); TEST_FAILED; } returncode = SQLExecute(hstmt); if(!CHECKRC(SQL_SUCCESS,returncode,"SQLExecute")){ LogAllErrors(henv,hdbc,hstmt); TEST_FAILED; } returncode = SQLExecute(hstmt); if(!CHECKRC(SQL_SUCCESS,returncode,"SQLExecute")){ LogAllErrors(henv,hdbc,hstmt); TEST_FAILED; } TESTCASE_END; SQLFreeStmt(hstmt,SQL_CLOSE); SQLFreeStmt(hstmt,SQL_UNBIND); SQLFreeStmt(hstmt,SQL_RESET_PARAMS); TESTCASE_BEGIN("Test #5: Positive Functionality of SQLExecute with params\n"); returncode = SQLPrepare(hstmt,(SQLTCHAR*)ExecStr[3],SQL_NTS); if(!CHECKRC(SQL_SUCCESS,returncode,"SQLPrepare")){ LogAllErrors(henv,hdbc,hstmt); TEST_FAILED; } else{ for (i = 0; i <= 3; i++){ if (i==0) Type[0] = 1; returncode = SQLBindParameter(hstmt,(SWORD)(i+1),SQL_PARAM_INPUT,SQL_C_TCHAR,Type[i],EXEC_LEN,0,szInput[i],0,&cbInput); if(!CHECKRC(SQL_SUCCESS,returncode,"SQLBindParameter")){ LogMsg(NONE,_T("Type[i]: %d \n"),Type[i]); LogAllErrors(henv,hdbc,hstmt); TEST_FAILED; } } returncode = SQLExecute(hstmt); if(!CHECKRC(SQL_SUCCESS,returncode,"SQLExecute")){ LogAllErrors(henv,hdbc,hstmt); TEST_FAILED; } } TESTCASE_END; TESTCASE_BEGIN("Test #6: Negative Functionality of SQLExecute with less params\n"); returncode = SQLFreeStmt(hstmt,SQL_DROP); if(!CHECKRC(SQL_SUCCESS,returncode,"SQLFreeStmt")){ LogAllErrors(henv,hdbc,hstmt); TEST_FAILED; } else{ returncode = SQLAllocStmt((SQLHANDLE)hdbc, &hstmt); if(!CHECKRC(SQL_SUCCESS,returncode,"SQLAllocStmt")){ LogAllErrors(henv,hdbc,hstmt); TEST_FAILED; } else{ returncode = SQLPrepare(hstmt,(SQLTCHAR*)ExecStr[3],SQL_NTS); if(!CHECKRC(SQL_SUCCESS,returncode,"SQLPrepare")){ LogAllErrors(henv,hdbc,hstmt); TEST_FAILED; } else{ returncode = SQLBindParameter(hstmt,1,SQL_PARAM_INPUT,SQL_C_TCHAR,Type[0],EXEC_LEN,0,szInput[0],0,&cbInput); if(!CHECKRC(SQL_SUCCESS,returncode,"SQLBindParameter")){ LogAllErrors(henv,hdbc,hstmt); TEST_FAILED; } else{ returncode = SQLExecute(hstmt); if(!CHECKRC(SQL_ERROR,returncode,"SQLExecute")){ LogAllErrors(henv,hdbc,hstmt); TEST_FAILED; } } } } } TESTCASE_END; TESTCASE_BEGIN("Test #7: Negative Functionality of SQLExecute with not prepared stmt\n"); returncode = SQLFreeStmt(hstmt,SQL_DROP); if(!CHECKRC(SQL_SUCCESS,returncode,"SQLFreeStmt")){ LogAllErrors(henv,hdbc,hstmt); TEST_FAILED; } else{ returncode = SQLAllocStmt((SQLHANDLE)hdbc, &hstmt); if(!CHECKRC(SQL_SUCCESS,returncode,"SQLAllocStmt")){ LogAllErrors(henv,hdbc,hstmt); TEST_FAILED; } else{ returncode = SQLExecute(hstmt); if(!CHECKRC(SQL_ERROR,returncode,"SQLExecute")){ LogAllErrors(henv,hdbc,hstmt); TEST_FAILED; } } } TESTCASE_END; TESTCASE_BEGIN("Test #8: Negative Functionality of SQLExecute with invalid handle\n"); returncode = SQLPrepare(hstmt,(SQLTCHAR*)ExecStr[2],_tcslen(ExecStr[2])); if(!CHECKRC(SQL_SUCCESS,returncode,"SQLPrepare")){ LogAllErrors(henv,hdbc,hstmt); TEST_FAILED; } else{ returncode = SQLExecute((SQLHANDLE)NULL); if(!CHECKRC(SQL_INVALID_HANDLE,returncode,"SQLExecute")){ LogAllErrors(henv,hdbc,hstmt); TEST_FAILED; } } TESTCASE_END; returncode = SQLExecDirect(hstmt,(SQLTCHAR*)ExecStr[0],_tcslen(ExecStr[0])); /* cleanup */ TESTCASE_BEGIN("Test #9: Stress Positive Functionality of SQLExecute.\n"); returncode = SQLExecDirect(hstmt,(SQLTCHAR*)ExecStr[11],SQL_NTS); returncode = SQLExecDirect(hstmt,(SQLTCHAR*)ExecStr[12],SQL_NTS); if(!CHECKRC(SQL_SUCCESS,returncode,"SQLExecDirect")) { TEST_FAILED; LogAllErrors(henv,hdbc,hstmt); } else { returncode = SQLPrepare(hstmt,(SQLTCHAR*)ExecStr[13],SQL_NTS); if(!CHECKRC(SQL_SUCCESS,returncode,"SQLPrepare")) { TEST_FAILED; LogAllErrors(henv,hdbc,hstmt); } else { actual_insert = 0; for (num_insert = 0; num_insert < MAX_INSERTED_ROWS; num_insert++) { returncode = SQLExecute(hstmt); if(!CHECKRC(SQL_SUCCESS,returncode,"SQLExecute")) { TEST_FAILED; LogAllErrors(henv,hdbc,hstmt); } else actual_insert++; } if (actual_insert != MAX_INSERTED_ROWS) { TEST_FAILED; LogMsg(ERRMSG,_T("failed to insert rows actual => %d & excepted => %d.\n"),actual_insert,MAX_INSERTED_ROWS); } } } SQLExecDirect(hstmt,(SQLTCHAR*)ExecStr[11],SQL_NTS); TESTCASE_END; TESTCASE_BEGIN("Test #10: Stress Positive Functionality of SQLExecute with Params.\n"); returncode = SQLExecDirect(hstmt,(SQLTCHAR*)ExecStr[11],SQL_NTS); returncode = SQLExecDirect(hstmt,(SQLTCHAR*)ExecStr[12],SQL_NTS); LogMsg(NONE,_T("ExecStr[12]: %s\n"), ExecStr[12]); if(!CHECKRC(SQL_SUCCESS,returncode,"SQLExecDirect")) { TEST_FAILED; LogAllErrors(henv,hdbc,hstmt); } else { returncode = SQLPrepare(hstmt,(SQLTCHAR*)ExecStr[14],SQL_NTS); if(!CHECKRC(SQL_SUCCESS,returncode,"SQLPrepare")) { TEST_FAILED; LogAllErrors(henv,hdbc,hstmt); } else { actual_insert = 0; returncode = SQLNumParams(hstmt, ¶m); if(!CHECKRC(SQL_SUCCESS,returncode,"SQLNumParams")) { LogAllErrors(henv,hdbc,hstmt); TEST_FAILED; } for (num_insert = 0; num_insert < MAX_INSERTED_ROWS; num_insert++) { for (i = 0; i < param; i++) { if (i==0) Type[0] = 1; if (MX_MP_SPECIFIC == MX_SPECIFIC) { returncode = SQLBindParameter(hstmt,(SWORD)(i+1),SQL_PARAM_INPUT,SQL_C_TCHAR,Type[i],ColPrec[i],ColScale[i],szInput[i],0,&cbInput); } else { returncode = SQLBindParameter(hstmt,(SWORD)(i+1),SQL_PARAM_INPUT,SQL_C_TCHAR,Type[i],ColPrec[i],ColScale[i],szInput[i],300,&cbInput); } if(!CHECKRC(SQL_SUCCESS,returncode,"SQLBindParameter")) { LogAllErrors(henv,hdbc,hstmt); TEST_FAILED; } } returncode = SQLExecute(hstmt); if(!CHECKRC(SQL_SUCCESS,returncode,"SQLExecute")) { TEST_FAILED; LogAllErrors(henv,hdbc,hstmt); } else actual_insert++; } if (actual_insert != MAX_INSERTED_ROWS) { TEST_FAILED; LogMsg(ERRMSG,_T("failed to insert rows actual => %d & excepted => %d.\n"),actual_insert,MAX_INSERTED_ROWS); } } } SQLExecDirect(hstmt,(SQLTCHAR*)ExecStr[11],SQL_NTS); TESTCASE_END; TESTCASE_BEGIN("Test #11: Negative Functionality of SQLExecute with already existing table\n"); returncode = SQLFreeStmt(hstmt,SQL_DROP); if(!CHECKRC(SQL_SUCCESS,returncode,"SQLFreeStmt")) { LogAllErrors(henv,hdbc,hstmt); TEST_FAILED; } else { returncode = SQLAllocStmt((SQLHANDLE)hdbc, &hstmt); if(!CHECKRC(SQL_SUCCESS,returncode,"SQLAllocStmt")) { LogAllErrors(henv,hdbc,hstmt); TEST_FAILED; } else { SQLExecDirect(hstmt,(SQLTCHAR*)ExecStr[0],_tcslen(ExecStr[0])); /* cleanup */ returncode = SQLPrepare(hstmt,(SQLTCHAR*)ExecStr[1],_tcslen(ExecStr[1])); if(!CHECKRC(SQL_SUCCESS,returncode,"SQLPrepare")) { LogAllErrors(henv,hdbc,hstmt); TEST_FAILED; } else { returncode = SQLExecute(hstmt); if(!CHECKRC(SQL_SUCCESS,returncode,"SQLExecute")) { LogAllErrors(henv,hdbc,hstmt); TEST_FAILED; } else { returncode = SQLExecute(hstmt); if(!CHECKRC(SQL_ERROR,returncode,"SQLExecute")) { LogAllErrors(henv,hdbc,hstmt); TEST_FAILED; } } } SQLExecDirect(hstmt,(SQLTCHAR*)ExecStr[0],_tcslen(ExecStr[0])); /* cleanup */ } } TESTCASE_END; //================================================================================================= FullDisconnect(pTestInfo); LogMsg(SHORTTIMESTAMP+LINEAFTER,_T("End testing API => SQLExecute.\n")); free_list(var_list); TEST_RETURN; }
/* --------------------------------------------------------- TestSQLDescribeCol for MP Specific --------------------------------------------------------- */ PassFail TestMXSQLDescribeCol(TestInfo *pTestInfo) { TEST_DECLARE; char Heading[MAX_STRING_SIZE]; RETCODE returncode; SQLHANDLE henv, hdbc, hstmt; UWORD icol; SWORD numcol, st, cs, cnull, cl, colsize = 2; SQLULEN cp; CHAR cn[COLNAME_LEN]; CHAR *colname[21]; CHAR *ExecDirStr[12]; #ifndef _WM SWORD SQLType[] = {SQL_CHAR,SQL_VARCHAR,SQL_DECIMAL,SQL_NUMERIC,SQL_SMALLINT,SQL_INTEGER, SQL_REAL,SQL_DOUBLE,SQL_DOUBLE,SQL_DATE,SQL_TIME,SQL_TIMESTAMP,SQL_LONGVARCHAR,SQL_BIGINT, SQL_NUMERIC,SQL_NUMERIC,SQL_NUMERIC,SQL_NUMERIC,SQL_NUMERIC,SQL_NUMERIC,SQL_NUMERIC}; SQLULEN ColPrec[] = {254,254,18,18,5,10,7,15,15,10,8,26,2000,19,19,19,128,128,10,18,30}; #else SWORD SQLType[] = {SQL_CHAR,SQL_VARCHAR,SQL_DECIMAL,SQL_NUMERIC,SQL_SMALLINT,SQL_INTEGER, SQL_REAL,SQL_DOUBLE,SQL_DOUBLE,SQL_CHAR,SQL_TIME,SQL_TIMESTAMP,SQL_LONGVARCHAR,SQL_BIGINT, SQL_NUMERIC,SQL_NUMERIC,SQL_NUMERIC,SQL_NUMERIC,SQL_NUMERIC,SQL_NUMERIC,SQL_NUMERIC}; SQLULEN ColPrec[] = {254,254,18,18,5,10,7,15,15,8,8,26,2000,19,19,19,128,128,10,18,30}; #endif SWORD ColScale[]= {0, 0, 6, 6, 0,0, 0,0, 0, 0, 0,6, 0, 0, 0, 6, 0, 128,5, 5, 10}; char TempType1[50],TempType2[50]; SWORD ColNullable[] = {SQL_NULLABLE,SQL_NO_NULLS,SQL_NULLABLE}; CHAR *TestCase[] = { "before preparing stmt ", "before preparing & executing stmt ", "before preparing, executing & fetching stmt ", "before execdirect stmt ", "before execdirect & fetching stmt ", "before preparing param stmt ", "before preparing & binding stmt ", "before preparing, binding & executing stmt ", "before preparing, binding, executing & fetching stmt " }; int lend = 9, iend = 3; SQLUSMALLINT i = 0, l = 0; SQLLEN cbIn = SQL_NTS; //=========================================================================================================== var_list_t *var_list; var_list = load_api_vars("SQLDescribeColumns", charset_file); if (var_list == NULL) return FAILED; //================Modified for Longvarchar Changes=========================================================== if(!pTestInfo->bLongOn) { SWORD iNoLong = SQL_VARCHAR; SQLType[12] = iNoLong; } //================Modified for Longvarchar Changes=========================================================== //print_list(var_list); colname[0] = var_mapping("SQLDescribeColumns_colname_1", var_list); colname[1] = var_mapping("SQLDescribeColumns_colname_2", var_list); colname[2] = var_mapping("SQLDescribeColumns_colname_3", var_list); colname[3] = var_mapping("SQLDescribeColumns_colname_4", var_list); colname[4] = var_mapping("SQLDescribeColumns_colname_5", var_list); colname[5] = var_mapping("SQLDescribeColumns_colname_6", var_list); colname[6] = var_mapping("SQLDescribeColumns_colname_7", var_list); colname[7] = var_mapping("SQLDescribeColumns_colname_8", var_list); colname[8] = var_mapping("SQLDescribeColumns_colname_9", var_list); colname[9] = var_mapping("SQLDescribeColumns_colname_10", var_list); colname[10] = var_mapping("SQLDescribeColumns_colname_11", var_list); colname[11] = var_mapping("SQLDescribeColumns_colname_12", var_list); colname[12] = var_mapping("SQLDescribeColumns_colname_13", var_list); colname[13] = var_mapping("SQLDescribeColumns_colname_14", var_list); colname[14] = var_mapping("SQLDescribeColumns_colname_15", var_list); colname[15] = var_mapping("SQLDescribeColumns_colname_16", var_list); colname[16] = var_mapping("SQLDescribeColumns_colname_17", var_list); colname[17] = var_mapping("SQLDescribeColumns_colname_18", var_list); colname[18] = var_mapping("SQLDescribeColumns_colname_19", var_list); colname[19] = var_mapping("SQLDescribeColumns_colname_20", var_list); colname[20] = var_mapping("SQLDescribeColumns_colname_21", var_list); ExecDirStr[0] = var_mapping("SQLDescribeColumns_ExecDirStr_1", var_list); ExecDirStr[1] = var_mapping("SQLDescribeColumns_ExecDirStr_2", var_list); ExecDirStr[2] = var_mapping("SQLDescribeColumns_ExecDirStr_3", var_list); ExecDirStr[3] = var_mapping("SQLDescribeColumns_ExecDirStr_4", var_list); ExecDirStr[4] = var_mapping("SQLDescribeColumns_ExecDirStr_5", var_list); ExecDirStr[5] = var_mapping("SQLDescribeColumns_ExecDirStr_6", var_list); ExecDirStr[6] = var_mapping("SQLDescribeColumns_ExecDirStr_7", var_list); ExecDirStr[7] = var_mapping("SQLDescribeColumns_ExecDirStr_8", var_list); ExecDirStr[8] = var_mapping("SQLDescribeColumns_ExecDirStr_9", var_list); ExecDirStr[9] = var_mapping("SQLDescribeColumns_ExecDirStr_10", var_list); ExecDirStr[10] = var_mapping("SQLDescribeColumns_ExecDirStr_11", var_list); ExecDirStr[11] = var_mapping("SQLDescribeColumns_ExecDirStr_12", var_list); //=========================================================================================================== if(isUCS2) { LogMsg(NONE,"Setup for UCS2 mode testing: ColPrec has to be doubled\n"); ExecDirStr[3] = replace_str(ExecDirStr[3],"$$$","127"); ExecDirStr[4] = replace_str(ExecDirStr[4],"$$$","127"); ExecDirStr[5] = replace_str(ExecDirStr[5],"$$$","127"); l = sizeof(SQLType)/sizeof(SQLType[0]); while((i < l) && isUCS2) { if(SQLType[i] == SQL_CHAR) { //SQLType[i] = SQL_WCHAR; ColPrec[i] *= 2; //--> This is in character, so no need to double } else if (SQLType[i] == SQL_VARCHAR) { //SQLType[i] = SQL_WVARCHAR; } else if (SQLType[i] == SQL_LONGVARCHAR) { //SQLType[i] = SQL_WLONGVARCHAR; ColPrec[i] *= 2; //--> This is in character, so no need to double } else { } i++; } i = 0; l = 0; } else { ExecDirStr[3] = replace_str(ExecDirStr[3],"$$$","254"); ExecDirStr[4] = replace_str(ExecDirStr[4],"$$$","254"); ExecDirStr[5] = replace_str(ExecDirStr[5],"$$$","254"); } //=========================================================================================================== LogMsg(LINEBEFORE+SHORTTIMESTAMP,"Begin testing API => MX Specific SQLDescribeColumns | SQLDescribeColumns | mxdescol.c\n"); TEST_INIT; TESTCASE_BEGIN("Setup for SQLDescribCol tests\n"); if(!FullConnect(pTestInfo)) { LogMsg(NONE,"Unable to connect\n"); TEST_FAILED; TEST_RETURN; } henv = pTestInfo->henv; hdbc = pTestInfo->hdbc; hstmt = (SQLHANDLE)pTestInfo->hstmt; returncode = SQLAllocStmt((SQLHANDLE)hdbc, &hstmt); if(!CHECKRC(SQL_SUCCESS,returncode,"SQLAllocStmt")) { LogAllErrors(henv,hdbc,hstmt); TEST_FAILED; TEST_RETURN; } TESTCASE_END; // end of setup for (l = 0; l < lend; l++) { for (i = 0; i < iend; i++) { //================================================================================== sprintf(Heading,"SQLDescribeCol: Test #%d.%d\n",l,i); TESTCASE_BEGIN(Heading); if ((i != (iend-1)) && (l < 5)) { SQLExecDirect(hstmt,(SQLCHAR*)ExecDirStr[i],SQL_NTS); /* cleanup */ returncode = SQLExecDirect(hstmt,(SQLCHAR*)ExecDirStr[i+iend],SQL_NTS); /* create table */ if(!CHECKRC(SQL_SUCCESS,returncode,"SQLExecDirect")) { LogAllErrors(henv,hdbc,hstmt); TEST_FAILED; } else { returncode = SQLExecDirect(hstmt,(SQLCHAR*)ExecDirStr[i+iend+iend],SQL_NTS); /* insert into table */ if(!CHECKRC(SQL_SUCCESS,returncode,"SQLExecDirect")) { LogAllErrors(henv,hdbc,hstmt); TEST_FAILED; } else { LogMsg(NONE,"SQLDescribeCol: %s\n",TestCase[l]); LogMsg(NONE," %s\n",ExecDirStr[i+iend+iend+iend]); switch( l ) { case 0: returncode = SQLPrepare(hstmt,(SQLCHAR*)ExecDirStr[i+iend+iend+iend], SQL_NTS); if(!CHECKRC(SQL_SUCCESS,returncode,"SQLPrepare")) { LogAllErrors(henv,hdbc,hstmt); TEST_FAILED; } break; case 1 : returncode = SQLPrepare(hstmt,(SQLCHAR*)ExecDirStr[i+iend+iend+iend], SQL_NTS); if(!CHECKRC(SQL_SUCCESS,returncode,"SQLPrepare")) { LogAllErrors(henv,hdbc,hstmt); TEST_FAILED; } else { returncode = SQLExecute(hstmt); if(!CHECKRC(SQL_SUCCESS,returncode,"SQLExecute")) { LogAllErrors(henv,hdbc,hstmt); TEST_FAILED; } } break; case 2 : returncode = SQLPrepare(hstmt,(SQLCHAR*)ExecDirStr[i+iend+iend+iend], SQL_NTS); if(!CHECKRC(SQL_SUCCESS,returncode,"SQLPrepare")) { LogAllErrors(henv,hdbc,hstmt); TEST_FAILED; } else { returncode = SQLExecute(hstmt); if(!CHECKRC(SQL_SUCCESS,returncode,"SQLExecute")) { LogAllErrors(henv,hdbc,hstmt); TEST_FAILED; } else { returncode = SQLFetch(hstmt); if(!CHECKRC(SQL_SUCCESS,returncode,"SQLFetch")) { LogAllErrors(henv,hdbc,hstmt); TEST_FAILED; } } } break; case 3 : returncode = SQLExecDirect(hstmt,(SQLCHAR*)ExecDirStr[i+iend+iend+iend], SQL_NTS); if(!CHECKRC(SQL_SUCCESS,returncode,"SQLExecDirect")) { LogAllErrors(henv,hdbc,hstmt); TEST_FAILED; } break; case 4 : returncode = SQLExecDirect(hstmt,(SQLCHAR*)ExecDirStr[i+iend+iend+iend], SQL_NTS); if(!CHECKRC(SQL_SUCCESS,returncode,"SQLExecDirect")) { LogAllErrors(henv,hdbc,hstmt); TEST_FAILED; } else { returncode = SQLFetch(hstmt); if(!CHECKRC(SQL_SUCCESS,returncode,"SQLFetch")) { LogAllErrors(henv,hdbc,hstmt); TEST_FAILED; } } break; } if (returncode == SQL_SUCCESS) { returncode=SQLNumResultCols(hstmt, &numcol); if(!CHECKRC(SQL_SUCCESS,returncode,"SQLNumResultCols")) { LogAllErrors(henv,hdbc,hstmt); TEST_FAILED; } for (icol = 1; icol <= numcol; icol++) { LogMsg(LINEBEFORE,"SQLDescribeCol: checking Column #%d\n",icol); returncode = SQLDescribeCol(hstmt,icol,(SQLCHAR*)cn,COLNAME_LEN,&cl,&st,&cp,&cs,&cnull); if(!CHECKRC(SQL_SUCCESS,returncode,"SQLDescribeCol")) { TEST_FAILED; LogAllErrors(henv,hdbc,hstmt); } colsize=strlen(colname[icol-1]); if(isCharSet == TRUE) colsize -= 2; if ((cstrcmp(cn,colname[icol-1],FALSE,isCharSet) == 0) && (cl == colsize) && (st == SQLType[icol-1]) && (cp == ColPrec[icol-1]) && (cs == ColScale[icol-1]) && (cnull == ColNullable[i])) { //LogMsg(NONE,"colname expect: %s and actual: %s are matched\n",colname[icol-1],cn); //LogMsg(NONE,"ColNameLen expect: %d and actual: %d are matched\n",colsize,cl); //LogMsg(NONE,"SQLType expect: %s and actual: %s are matched\n", //SQLTypeToChar(SQLType[icol-1],TempType1),SQLTypeToChar(st,TempType2)); //LogMsg(NONE,"ColPrec expect: %d and actual: %d are matched\n",ColPrec[icol-1],cp); //LogMsg(NONE,"ColScale expect: %d and actual: %d are matched\n",ColScale[icol-1],cs); //LogMsg(NONE,"ColNullable expect: %s and actual: %s are matched\n\n", //SQLNullToChar(ColNullable[i],TempType1),SQLNullToChar(cnull,TempType2)); } else { TEST_FAILED; if (cstrcmp(cn,colname[icol-1],FALSE,isCharSet) != 0) LogMsg(ERRMSG,"colname expect: %s and actual: %s are not matched line %d\n",colname[icol-1],cn,__LINE__); if (cl != colsize) LogMsg(ERRMSG,"ColNameLen expect: %d and actual: %d are not matched line %d\n",colsize,cl,__LINE__); if (st != SQLType[icol-1]) LogMsg(ERRMSG,"SQLType expect: %s and actual: %s are not matched line %d\n", SQLTypeToChar(SQLType[icol-1],TempType1),SQLTypeToChar(st,TempType2),__LINE__); if (cp != ColPrec[icol-1]) LogMsg(ERRMSG,"ColPrec expect: %d and actual: %d are not matched line %d\n",ColPrec[icol-1],cp,__LINE__); if (cs != ColScale[icol-1]) LogMsg(ERRMSG,"ColScale expect: %d and actual: %d are not matched line %d\n",ColScale[icol-1],cs,__LINE__); if (cnull != ColNullable[i]) LogMsg(ERRMSG,"ColNullable expect: %s and actual: %s are not matched line %d\n\n", SQLNullToChar(ColNullable[i],TempType1),SQLNullToChar(cnull,TempType2),__LINE__); } } /* end icol loop */ } else { TEST_FAILED; LogAllErrors(henv,hdbc,hstmt); } SQLFreeStmt(hstmt,SQL_CLOSE); SQLExecDirect(hstmt,(SQLCHAR*) ExecDirStr[i],SQL_NTS); /* cleanup */ } } } else if ((i == (iend-1)) && (l >= 5)) { SQLExecDirect(hstmt,(SQLCHAR*)ExecDirStr[i],SQL_NTS); /* cleanup */ returncode = SQLExecDirect(hstmt,(SQLCHAR*)ExecDirStr[i+iend],SQL_NTS); /* create table */ if(!CHECKRC(SQL_SUCCESS,returncode,"SQLExecDirect")) { LogAllErrors(henv,hdbc,hstmt); TEST_FAILED; } else { returncode = SQLExecDirect(hstmt,(SQLCHAR*)ExecDirStr[i+iend+iend],SQL_NTS); /* insert into table */ if(!CHECKRC(SQL_SUCCESS,returncode,"SQLExecDirect")) { LogAllErrors(henv,hdbc,hstmt); TEST_FAILED; } else { LogMsg(NONE,"SQLDescribeCol: %s\n",TestCase[l]); LogMsg(NONE," %s\n",ExecDirStr[i+iend+iend+iend]); switch( l ) { case 5 : returncode = SQLPrepare(hstmt,(SQLCHAR*)ExecDirStr[i+iend+iend+iend], SQL_NTS); if(!CHECKRC(SQL_SUCCESS,returncode,"SQLPrepare")) { LogAllErrors(henv,hdbc,hstmt); TEST_FAILED; } break; case 6 : returncode = SQLPrepare(hstmt,(SQLCHAR*)ExecDirStr[i+iend+iend+iend], SQL_NTS); if(!CHECKRC(SQL_SUCCESS,returncode,"SQLPrepare")) { LogAllErrors(henv,hdbc,hstmt); TEST_FAILED; } else { returncode = SQLBindParameter(hstmt,1,SQL_PARAM_INPUT,SQL_C_CHAR,SQL_CHAR,2000,0,(SQLPOINTER)"0123456789",300,&cbIn); if(!CHECKRC(SQL_SUCCESS,returncode,"SQLBindParameter")) { LogAllErrors(henv,hdbc,hstmt); TEST_FAILED; } returncode = SQLBindParameter(hstmt,2,SQL_PARAM_INPUT,SQL_C_CHAR,SQL_CHAR,2000,0,(SQLPOINTER)"0123456789",300,&cbIn); if(!CHECKRC(SQL_SUCCESS,returncode,"SQLBindParameter")) { LogAllErrors(henv,hdbc,hstmt); TEST_FAILED; } } break; case 7 : returncode = SQLPrepare(hstmt,(SQLCHAR*)ExecDirStr[i+iend+iend+iend], SQL_NTS); if(!CHECKRC(SQL_SUCCESS,returncode,"SQLPrepare")) { LogAllErrors(henv,hdbc,hstmt); TEST_FAILED; } else { returncode = SQLBindParameter(hstmt,1,SQL_PARAM_INPUT,SQL_C_CHAR,SQL_CHAR,2000,0,(SQLPOINTER)"0123456789",300,&cbIn); if(!CHECKRC(SQL_SUCCESS,returncode,"SQLBindParameter")) { LogAllErrors(henv,hdbc,hstmt); TEST_FAILED; } returncode = SQLBindParameter(hstmt,2,SQL_PARAM_INPUT,SQL_C_CHAR,SQL_CHAR,2000,0,(SQLPOINTER)"0123456789",300,&cbIn); if(!CHECKRC(SQL_SUCCESS,returncode,"SQLBindParameter")) { LogAllErrors(henv,hdbc,hstmt); TEST_FAILED; } returncode = SQLExecute(hstmt); if(!CHECKRC(SQL_SUCCESS,returncode,"SQLExecute")) { LogAllErrors(henv,hdbc,hstmt); TEST_FAILED; } } break; case 8 : returncode = SQLPrepare(hstmt,(SQLCHAR*)ExecDirStr[i+iend+iend+iend], SQL_NTS); if(!CHECKRC(SQL_SUCCESS,returncode,"SQLPrepare")) { LogAllErrors(henv,hdbc,hstmt); TEST_FAILED; } else { returncode = SQLBindParameter(hstmt,1,SQL_PARAM_INPUT,SQL_C_CHAR,SQL_CHAR,2000,0,(SQLPOINTER)"0123456789",300,&cbIn); if(!CHECKRC(SQL_SUCCESS,returncode,"SQLBindParameter")) { LogAllErrors(henv,hdbc,hstmt); TEST_FAILED; } returncode = SQLBindParameter(hstmt,2,SQL_PARAM_INPUT,SQL_C_CHAR,SQL_CHAR,2000,0,(SQLPOINTER)"0123456789",300,&cbIn); if(!CHECKRC(SQL_SUCCESS,returncode,"SQLBindParameter")) { LogAllErrors(henv,hdbc,hstmt); TEST_FAILED; } returncode = SQLExecute(hstmt); if(!CHECKRC(SQL_SUCCESS,returncode,"SQLExecute")) { LogAllErrors(henv,hdbc,hstmt); TEST_FAILED; } else { returncode = SQLFetch(hstmt); if(!CHECKRC(SQL_SUCCESS,returncode,"SQLFetch")) { LogAllErrors(henv,hdbc,hstmt); TEST_FAILED; } } } break; } if (returncode == SQL_SUCCESS) { SQLNumResultCols(hstmt, &numcol); if(!CHECKRC(SQL_SUCCESS,returncode,"SQLNumResultCols")) { LogAllErrors(henv,hdbc,hstmt); TEST_FAILED; } for (icol = 1; icol <= numcol; icol++) { LogMsg(LINEBEFORE,"SQLDescribeCol: checking Column #%d\n",icol); returncode = SQLDescribeCol(hstmt,icol,(SQLCHAR*)cn,COLNAME_LEN,&cl,&st,&cp,&cs,&cnull); if(!CHECKRC(SQL_SUCCESS,returncode,"SQLDescribeCol")) { TEST_FAILED; LogAllErrors(henv,hdbc,hstmt); } colsize=strlen(colname[icol-1]); if(isCharSet == TRUE) colsize -= 2; if ((cstrcmp(cn,colname[icol-1],FALSE,isCharSet) == 0) && (cl == colsize) && (st == SQLType[icol-1]) && (cp == ColPrec[icol-1]) && (cs == ColScale[icol-1]) && (cnull == ColNullable[i])) { //LogMsg(NONE,"colname expect: %s and actual: %s are matched\n",colname[icol-1],cn); //LogMsg(NONE,"ColNameLen expect: %d and actual: %d are matched\n",colsize,cl); //LogMsg(NONE,"SQLType expect: %s and actual: %s are matched\n", // SQLTypeToChar(SQLType[icol-1],TempType1),SQLTypeToChar(st,TempType2)); //LogMsg(NONE,"ColPrec expect: %d and actual: %d are matched\n",ColPrec[icol-1],cp); //LogMsg(NONE,"ColScale expect: %d and actual: %d are matched\n",ColScale[icol-1],cs); //LogMsg(NONE,"ColNullable expect: %s and actual: %s are matched\n\n", // SQLNullToChar(ColNullable[i],TempType1),SQLNullToChar(cnull,TempType2)); } else { TEST_FAILED; if (cstrcmp(cn,colname[icol-1],FALSE,isCharSet) != 0) LogMsg(ERRMSG,"colname expect: %s and actual: %s are not matched at line %d\n",colname[icol-1],cn,__LINE__); if (cl != colsize) LogMsg(ERRMSG,"ColNameLen expect: %d and actual: %d are not matched at line %d\n",colsize,cl,__LINE__); if (st != SQLType[icol-1]) LogMsg(ERRMSG,"SQLType expect: %s and actual: %s are not matched at line %d\n", SQLTypeToChar(SQLType[icol-1],TempType1),SQLTypeToChar(st,TempType2),__LINE__); if (cp != ColPrec[icol-1]) LogMsg(ERRMSG,"ColPrec expect: %d and actual: %d are not matched at line %d\n",ColPrec[icol-1],cp,__LINE__); if (cs != ColScale[icol-1]) LogMsg(ERRMSG,"ColScale expect: %d and actual: %d are not matched at line %d\n",ColScale[icol-1],cs,__LINE__); if (cnull != ColNullable[i]) LogMsg(ERRMSG,"ColNullable expect: %s and actual: %s are not matched at line %d\n\n", SQLNullToChar(ColNullable[i],TempType1),SQLNullToChar(cnull,TempType2),__LINE__); } } } } SQLFreeStmt(hstmt,SQL_CLOSE); SQLExecDirect(hstmt,(SQLCHAR*) ExecDirStr[i],SQL_NTS); } } TESTCASE_END; } /* iend loop */ } /* lend loop */ FullDisconnect(pTestInfo); LogMsg(SHORTTIMESTAMP+LINEAFTER,"End testing API => MX Specific SQLDescribeColumns.\n"); free_list(var_list); TEST_RETURN; }
void XMLFile::Set( const string& path, const string& value ) { LogMsg(INFO,"Overriding Option['%s'] from '%s' to '%s'",path.c_str(),Get(path).c_str(),value.c_str()); xmlNodeSetContent(FindNode(path,true), BAD_CAST value.c_str() ); assert( value == Get(path)); }
//-------------------------------------------------------------------------------------------------- // NOTE: We can't set the baud rate programmatically for a SocketCAN device as it may be shared // by multiple applications. It has to be set system wide. COM_DeviceHandle COM_DriverDeviceOpen( const char* deviceName, const char* baudRate ) { if ( eDS_Inactive == gDriverState ) { // Setup driver if this is the first time this routine has been called for ( int32_t i = 0; i < MAX_NUM_DEVICES; i++ ) { gDevices[ i ].mbInUse = false; } gDriverState = eDS_Active; } // Check device name if ( strlen( deviceName ) > IF_NAMESIZE-1 ) { LogMsg( eV_Error, "Device name is to long. Max length is %i\n", IF_NAMESIZE-1 ); return NULL; } // Check to see if the device is already open for ( int32_t i = 0; i < MAX_NUM_DEVICES; i++ ) { if ( gDevices[ i ].mbInUse && strncmp( gDevices[ i ].mName, deviceName, IF_NAMESIZE ) == 0 ) { LogMsg( eV_Error, "%s is already open\n", deviceName ); return NULL; } } // Look for an empty slot int32_t deviceIdx = -1; for ( int32_t i = 0; i < MAX_NUM_DEVICES; i++ ) { if ( !gDevices[ i ].mbInUse ) { deviceIdx = i; break; } } if ( -1 == deviceIdx ) { LogMsg( eV_Error, "Unable to find slot for device. Please increase MAX_NUM_DEVICES\n" ); return NULL; } // Open the device strcpy( gDevices[ deviceIdx ].mName, deviceName ); gDevices[ deviceIdx ].mSocketId = socket( PF_CAN, SOCK_RAW, CAN_RAW ); if ( gDevices[ deviceIdx ].mSocketId < 0 ) { LogMsg( eV_Error, "Unable to open socket\n" ); return NULL; } // Specify non-blocking operation fcntl( gDevices[ deviceIdx ].mSocketId, F_SETFL, O_NONBLOCK ); // Locate the interface we wish to use struct ifreq ifr; strcpy( ifr.ifr_name, deviceName ); // ifr.ifr_ifindex gets filled with that device's index if ( ioctl( gDevices[ deviceIdx ].mSocketId, SIOCGIFINDEX, &ifr ) < 0 ) { LogMsg( eV_Error, "Can't open %s\n", deviceName ); return NULL; } // Select that CAN interface, and bind the socket to it. */ struct sockaddr_can addr; addr.can_family = AF_CAN; addr.can_ifindex = ifr.ifr_ifindex; if ( bind( gDevices[ deviceIdx ].mSocketId, (struct sockaddr*)&addr, sizeof(addr) ) < 0 ) { LogMsg( eV_Error, "Can't bind %s to socket\n", deviceName ); return NULL; } // Setup a rolling buffer to take the incoming data RB_Init( &gDevices[ deviceIdx ].mReadBuffer, gDevices[ deviceIdx ].mReadBufferData, sizeof( gDevices[ deviceIdx ].mReadBufferData ) ); gDevices[ deviceIdx ].mbInUse = true; LogMsg( eV_Info, "Opened channel\n" ); // Success return deviceIdxToHandle( deviceIdx ); }
void SearchController::checkForUpdatesFailed(const QString &reason) { LogMsg(tr("Failed to check for plugin updates: %1").arg(reason), Log::INFO); }
bool XMLFile::Save() { LogMsg(INFO, "Saving XML File '%s'.",filename.c_str() ); xmlSaveFormatFileEnc( filename.c_str(), xmlPtr, "ISO-8859-1", 1); return true; }
/**\brief For parsing XML file into fields. */ bool Model::FromXMLNode( xmlDocPtr doc, xmlNodePtr node ) { xmlNodePtr attr; string value; if( (attr = FirstChildNamed(node,"image")) ){ image = Image::Get( NodeToString(doc,attr) ); Image::Store(name, image); SetPicture(image); } else return false; if( (attr = FirstChildNamed(node,"engine")) ){ defaultEngine = Engines::Instance()->GetEngine( NodeToString(doc,attr) ); } else return false; if( (attr = FirstChildNamed(node,"mass")) ){ value = NodeToString(doc,attr); SetMass( static_cast<float> (atof( value.c_str() ))); } else return false; if( (attr = FirstChildNamed(node,"rotationsPerSecond")) ){ value = NodeToString(doc,attr); SetRotationsPerSecond( static_cast<float>(atof( value.c_str() ))); } else return false; if( (attr = FirstChildNamed(node,"thrustOffset")) ){ value = NodeToString(doc,attr); thrustOffset = static_cast<short>(atoi( value.c_str() )); } else return false; if( (attr = FirstChildNamed(node,"maxSpeed")) ){ value = NodeToString(doc,attr); SetMaxSpeed( static_cast<float>(atof( value.c_str() ))); } else return false; if( (attr = FirstChildNamed(node,"msrp")) ){ value = NodeToString(doc,attr); SetMSRP( (short int)atoi( value.c_str() )); } else return false; if( (attr = FirstChildNamed(node,"cargoSpace")) ){ value = NodeToString(doc,attr); SetCargoSpace( atoi( value.c_str() )); } else return false; if( (attr = FirstChildNamed(node,"hullStrength")) ){ value = NodeToString(doc,attr); SetHullStrength( (short)atoi( value.c_str() )); } else return false; if( (attr = FirstChildNamed(node,"shieldStrength")) ){ value = NodeToString(doc,attr); SetShieldStrength( (short)atoi( value.c_str() )); } else return false; if( (attr = FirstChildNamed(node,"weaponSlots")) ){ // pass the weaponSlots XML node into a handler function ConfigureWeaponSlots( doc, attr ); } else { LogMsg( ERR, "Did not find weapon slot configuration - assuming defaults."); // with no parameters, it sets default values ConfigureWeaponSlots(); } return true; }
void Model::WSDebug(vector<WeaponSlot>& slots){ LogMsg(DEBUG1, "WeaponSlots for Model: %s", GetName().c_str() ); for(unsigned int i = 0; i < slots.size(); i++){ WSDebug(slots[i]); } }
void Model::WSDebug(WeaponSlot slot){ LogMsg(DEBUG1, "WeaponSlots: name=%s x=%f y=%f angle=%f motionAngle=%f content=%s firingGroup=%d", slot.name.c_str(), slot.x, slot.y, slot.angle, slot.motionAngle, slot.content.c_str(), slot.firingGroup); }
// returns -1 if the caller should ignore the result // returns 1 if the record answers the question // returns 0 if the record does not answer the question mDNSexport int AnonInfoAnswersQuestion(const ResourceRecord *const rr, const DNSQuestion *const q) { mDNSexport mDNS mDNSStorage; ResourceRecord *nsec3RR; int i; AnonymousInfo *qai, *rai; mDNSu8 *AnonData; int AnonDataLen; rdataNSEC3 *nsec3; int hlen; const mDNSu8 hashName[NSEC3_MAX_HASH_LEN]; int nxtLength; mDNSu8 *nxtName; debugf("AnonInfoAnswersQuestion: question qname %##s", q->qname.c); // Currently only PTR records can have anonymous information if (q->qtype != kDNSType_PTR) { return -1; } // We allow anonymous questions to be answered by both normal services (without the // anonymous information) and anonymous services that are part of the same set. And // normal questions discover normal services and all anonymous services. // // The three cases have been enumerated clearly even though they all behave the // same way. if (!q->AnonInfo) { debugf("AnonInfoAnswersQuestion: not a anonymous type question"); if (!rr->AnonInfo) { // case 1 return -1; } else { // case 2 debugf("AnonInfoAnswersQuestion: Question %##s not answered using anonymous record %##s", q->qname.c, rr->name->c); return -1; } } else { // case 3 if (!rr->AnonInfo) { debugf("AnonInfoAnswersQuestion: not a anonymous type record"); return -1; } } // case 4: We have the anonymous information both in the question and the record. We need // two sets of information to validate. // // 1) Anonymous data that identifies the set/group // 2) NSEC3 record that contains the hash and the salt // // If the question is a remote one, it does not have the anonymous information to validate (just // the NSEC3 record) and hence the anonymous data should come from the local resource record. If the // question is local, it can come from either of them and if there is a mismatch between the // question and record, it won't validate. qai = q->AnonInfo; rai = rr->AnonInfo; if (qai->AnonData && rai->AnonData) { // Before a cache record is created, if there is a matching question i.e., part // of the same set, then when the cache is created we also set the anonymous // information. Otherwise, the cache record contains just the NSEC3 record and we // won't be here for that case. // // It is also possible that a local question is matched against the local AuthRecord // as that is also the case for which the AnonData would be non-NULL for both. // We match questions against AuthRecords (rather than the cache) for LocalOnly case and // to see whether a .local query should be suppressed or not. The latter never happens // because PTR queries are never suppressed. // If they don't belong to the same anonymous set, then no point in validating. if ((qai->AnonDataLen != rai->AnonDataLen) || mDNSPlatformMemCmp(qai->AnonData, rai->AnonData, qai->AnonDataLen) != 0) { debugf("AnonInfoAnswersQuestion: AnonData mis-match for record %s question %##s ", RRDisplayString(&mDNSStorage, rr), q->qname.c); return 0; } // AnonData matches i.e they belong to the same group and the same service. LogInfo("AnonInfoAnswersQuestion: Answering qname %##s, rname %##s, without validation", q->qname.c, rr->name->c); return 1; } else { debugf("AnonInfoAnswersQuestion: question %p, record %p", qai->AnonData, rai->AnonData); } if (qai->AnonData) { // If there is AnonData, then this is a local question. The // NSEC3 RR comes from the resource record which could be part // of the cache or local auth record. The cache entry could // be from a remote host or created when we heard our own // announcements. In any case, we use that to see if it matches // the question. AnonData = qai->AnonData; AnonDataLen = qai->AnonDataLen; nsec3RR = rai->nsec3RR; } else { // Remote question or hearing our own question back AnonData = rai->AnonData; AnonDataLen = rai->AnonDataLen; nsec3RR = qai->nsec3RR; } if (!AnonData || !nsec3RR) { // AnonData can be NULL for the cache entry and if we are hearing our own question back, AnonData is NULL for // that too and we can end up here for that case. debugf("AnonInfoAnswersQuestion: AnonData %p or nsec3RR %p, NULL for question %##s, record %s", AnonData, nsec3RR, q->qname.c, RRDisplayString(&mDNSStorage, rr)); return 0; } debugf("AnonInfoAnswersQuestion: Validating question %##s, ResourceRecord %s", q->qname.c, RRDisplayString(&mDNSStorage, nsec3RR)); nsec3 = (rdataNSEC3 *)nsec3RR->rdata->u.data; if (!NSEC3HashName(nsec3RR->name, nsec3, AnonData, AnonDataLen, hashName, &hlen)) { LogMsg("AnonInfoAnswersQuestion: NSEC3HashName failed for ##s", nsec3RR->name->c); return mDNSfalse; } if (hlen != SHA1_HASH_LENGTH) { LogMsg("AnonInfoAnswersQuestion: hlen wrong %d", hlen); return mDNSfalse; } NSEC3Parse(nsec3RR, mDNSNULL, &nxtLength, &nxtName, mDNSNULL, mDNSNULL); if (hlen != nxtLength) { LogMsg("AnonInfoAnswersQuestion: ERROR!! hlen %d not same as nxtLength %d", hlen, nxtLength); return mDNSfalse; } for (i = 0; i < nxtLength; i++) { if (nxtName[i] != hashName[i]) { debugf("AnonInfoAnswersQuestion: mismatch output %x, digest %x, i %d", nxtName[i+1], hashName[i], i); return 0; } } LogInfo("AnonInfoAnswersQuestion: ResourceRecord %s matched question %##s (%s)", RRDisplayString(&mDNSStorage, nsec3RR), q->qname.c, DNSTypeName(q->qtype)); return 1; }
void L_ParticleEffect::create_particle(L_REAL in_x, L_REAL in_y, CL_Vec2f* vec_t) { int chosen = choose_particle(); L_Particle* par_new; if (!fl_particle[chosen]) { LogMsg("L_ParticleEffect::create_particle> Can't add invalid particle"); return; } L_NEW_PAR( par_new, *fl_particle[chosen] ); CL_Vec2f vec_t2 = CL_Vec2f(0,0); if(addit_vector_enabled == true) { if(vec_t != NULL) vec_t2 = addit_vector + *vec_t; else vec_t2 = addit_vector; } else { if(vec_t != NULL) vec_t2 = *vec_t; } par_new->set_velocity(vec_t2); if(follow_shooting) { par_new->set_rotation(linear_get_radian(*vec_t)); } else if(par_randrot_on) { par_new->set_rotation2(L_RAND_REAL_2()*L_2PI); } if(size_distortion != 0) { par_new->set_size( par_new->get_ref_size()+rand_size() ); } if(life_distortion != 0) { int distort = rand() % life_distortion + 1; if(rand() % 2 == 0) distort = -distort; par_new->set_life(par_new->get_remaininig_life()+distort); } par_new->x_pos = in_x; par_new->y_pos = in_y; par_new->initialize(); //add to list particle_list.push_back(par_new); }