SQLRETURN ODBC::GetDiagField(SQLSMALLINT HandleType, 
				SQLHANDLE Handle,
				SQLSMALLINT RecNumber, 
				SQLSMALLINT DiagIdentifier,
				SQLPOINTER DiagInfo, 
				SQLSMALLINT BufferLength,
				SQLSMALLINT *StringLengthPtr)
{
	SQLRETURN rc;
	DWORD	ErrorMsgLang = 0;
	CConnect* pConnect;
	CStmt* pStmt;
	CDesc* pDesc;
	
	switch (HandleType)
	{
	case SQL_HANDLE_ENV:
		break;
	case SQL_HANDLE_DBC:
		pConnect = (CConnect*)Handle;
		EnterCriticalSection(&pConnect->m_CSObject);
		ErrorMsgLang = pConnect->getErrorMsgLang();
		break;
	case SQL_HANDLE_STMT:
		pStmt = (CStmt *)Handle;
		pConnect = pStmt->getConnectHandle();
		EnterCriticalSection(&pConnect->m_CSObject);
		ErrorMsgLang = pStmt->getErrorMsgLang();
		break;
	case SQL_HANDLE_DESC:
		pDesc = (CDesc *)Handle;
		pConnect = pDesc->getDescConnect();
		EnterCriticalSection(&pConnect->m_CSObject);
		ErrorMsgLang = pDesc->getErrorMsgLang();
		break;
	default:
		return SQL_INVALID_HANDLE;
	}
	__try{
		rc = ((CHandle *)Handle)->GetDiagField(HandleType, Handle, RecNumber, 
					ErrorMsgLang, DiagIdentifier, DiagInfo, BufferLength, StringLengthPtr);
	}
	__finally {
		switch (HandleType)
		{
			case SQL_HANDLE_ENV:
				break;
			case SQL_HANDLE_DBC:
				LeaveCriticalSection(&pConnect->m_CSObject);
				break;
			case SQL_HANDLE_STMT:
				LeaveCriticalSection(&pConnect->m_CSObject);
				break;
			case SQL_HANDLE_DESC:
				LeaveCriticalSection(&pConnect->m_CSObject);
				break;
		}
	}
	return rc;
}
SQLRETURN  ODBC::EndTran(SQLSMALLINT HandleType, 
				SQLHANDLE Handle,
				SQLSMALLINT CompletionType)
{
	SQLRETURN rc;
	DWORD	ErrorMsgLang = 0;
	CConnect* pConnect;

	switch (HandleType)
	{
	case SQL_HANDLE_ENV:	// DM implments by sending SQLEndTran for every active connection
		rc = SQL_INVALID_HANDLE;
		break;
	case SQL_HANDLE_DBC:
		pConnect = (CConnect*)Handle;
		EnterCriticalSection(&pConnect->m_CSObject);
		ErrorMsgLang = pConnect->getErrorMsgLang();
		rc = pConnect->EndTran(CompletionType);
		LeaveCriticalSection(&pConnect->m_CSObject);
		break;
	default:
		return SQL_INVALID_HANDLE;
	}
	return rc;
}
Esempio n. 3
0
void CClient::onError()
{
    QMessageBox::critical(this, "Error", "Couldn't connect to server: " + m_socket->errorString());
    CConnect *c = new CConnect();
    c->show();
    close();
}
SQLRETURN ODBC::Disconnect(SQLHDBC ConnectionHandle)
{

	SQLRETURN rc;
	CConnect	*pConnect;

	if (! gDrvrGlobal.gHandle.validateHandle(SQL_HANDLE_DBC, ConnectionHandle))
		return SQL_INVALID_HANDLE;
	
	pConnect = (CConnect *)ConnectionHandle;
	rc = pConnect->Disconnect();
	return rc;
}
SQLRETURN ODBC::SetConnectAttr(SQLHDBC ConnectionHandle,
           SQLINTEGER Attribute, 
		   SQLPOINTER Value,
           SQLINTEGER StringLength)
{
	SQLRETURN	rc;
	CConnect	*pConnect;

	if (! gDrvrGlobal.gHandle.validateHandle(SQL_HANDLE_DBC, ConnectionHandle))
		return SQL_INVALID_HANDLE;
	pConnect = (CConnect *)ConnectionHandle;
	rc = pConnect->SetConnectAttr(Attribute, Value, StringLength);
	return rc;
}
SQLRETURN ODBC::GetInfo(SQLHDBC ConnectionHandle,
           SQLUSMALLINT InfoType, 
		   SQLPOINTER InfoValuePtr,
           SQLSMALLINT BufferLength,
		   SQLSMALLINT *StringLengthPtr)
{
	SQLRETURN	rc;
	CConnect	*pConnect;

	if (! gDrvrGlobal.gHandle.validateHandle(SQL_HANDLE_DBC, ConnectionHandle))
		return SQL_INVALID_HANDLE;
	pConnect = (CConnect *)ConnectionHandle;
	rc = pConnect->GetInfo(InfoType, InfoValuePtr, BufferLength, StringLengthPtr);
	return rc;
}
// ODBC Standard
SQLRETURN ODBC::BrowseConnect(SQLHDBC  ConnectionHandle,
    SQLCHAR 		  *InConnectionString,
    SQLSMALLINT        StringLength1,
    SQLCHAR 		  *OutConnectionString,
    SQLSMALLINT        BufferLength,
    SQLSMALLINT       *StringLength2Ptr)
{
	SQLRETURN	rc;
	CConnect	*pConnect;

	if (! gDrvrGlobal.gHandle.validateHandle(SQL_HANDLE_DBC, ConnectionHandle))
		return SQL_INVALID_HANDLE;
	pConnect = (CConnect *)ConnectionHandle;
	rc = pConnect->BrowseConnect(InConnectionString, StringLength1, OutConnectionString,
			BufferLength, StringLength2Ptr);
	return rc;
}
extern SQLRETURN ODBC::NativeSql(
    SQLHDBC            ConnectionHandle,
    SQLCHAR 		  *InStatementText,
    SQLINTEGER         TextLength1,
    SQLCHAR 		  *OutStatementText,
    SQLINTEGER         BufferLength,
    SQLINTEGER 		  *TextLength2Ptr)
{
	SQLRETURN		rc = SQL_SUCCESS;
	CConnect		*pConnect;
	SQLINTEGER		InStatementTextLen;
	int  OutStatementTextTransLen;
	char errorMsg[MAX_TRANSLATE_ERROR_MSG_LEN];

	short			InStrLen;
	if (! gDrvrGlobal.gHandle.validateHandle(SQL_HANDLE_DBC, ConnectionHandle))
		return SQL_INVALID_HANDLE;
	
	pConnect = (CConnect *)ConnectionHandle;
		
	InStatementTextLen = pConnect->m_ICUConv->FindStrLength((const char *)InStatementText, TextLength1);
	
	if(pConnect->m_ICUConv->isAppUTF16())
		BufferLength = BufferLength*2;
	
	if (OutStatementText != NULL)
	{
 //SQLRETURN ICUConverter::OutArgTranslationHelper(SQLCHAR* arg, int argLen, char * dest, int destLen, int *transLen, char *errorMsg, bool LengthInUChars)
		if(pConnect->m_ICUConv->m_AppUnicodeType == APP_UNICODE_TYPE_UTF16)
			rc = pConnect->m_ICUConv->InputArgToWCharHelper(InStatementText, InStatementTextLen,
							(UChar*)OutStatementText, BufferLength, &OutStatementTextTransLen, errorMsg);
		else
			rc = pConnect->m_ICUConv->InArgTranslationHelper(InStatementText, InStatementTextLen,
							(char *)OutStatementText, BufferLength, &OutStatementTextTransLen, errorMsg);
		
		if(rc != SQL_ERROR)
		{
			if(rc == SQL_SUCCESS_WITH_INFO)
				pConnect->setDiagRec(DRIVER_ERROR, IDS_01_004);
		}
	}
	if (TextLength2Ptr != NULL)
		*TextLength2Ptr = OutStatementTextTransLen;
	return rc;
}
SQLRETURN ODBC::Connect(SQLHDBC ConnectionHandle,
           SQLCHAR *ServerName, 
		   SQLSMALLINT NameLength1,
           SQLCHAR *UserName, 
		   SQLSMALLINT NameLength2,
           SQLCHAR *Authentication, 
		   SQLSMALLINT NameLength3)
{
	SQLRETURN	rc;
	CConnect	*pConnect;
	if (! gDrvrGlobal.gHandle.validateHandle(SQL_HANDLE_DBC, ConnectionHandle))
		return SQL_INVALID_HANDLE;

	pConnect = (CConnect *)ConnectionHandle;
	rc = pConnect->Connect(ServerName, NameLength1, UserName, NameLength2, Authentication, NameLength3,
		TRUE);
	return rc;
}
SQLRETURN ODBC::DriverConnect(SQLHDBC            ConnectionHandle,
    SQLHWND            WindowHandle,
    SQLCHAR 		  *InConnectionString,
    SQLSMALLINT        StringLength1,
    SQLCHAR           *OutConnectionString,
    SQLSMALLINT        BufferLength,
    SQLSMALLINT 	  *StringLength2Ptr,
    SQLUSMALLINT       DriverCompletion)
{
	
	SQLRETURN	rc;
	CConnect	*pConnect;

	if (! gDrvrGlobal.gHandle.validateHandle(SQL_HANDLE_DBC, ConnectionHandle))
		return SQL_INVALID_HANDLE;
	pConnect = (CConnect *)ConnectionHandle;
	rc = pConnect->DriverConnect(WindowHandle, InConnectionString, StringLength1, OutConnectionString,
			BufferLength, StringLength2Ptr, DriverCompletion);
	return rc;
}
Esempio n. 11
0
SQLRETURN CEnv::AllocHandle(SQLSMALLINT HandleType,SQLHANDLE InputHandle, SQLHANDLE *OutputHandle)
{
	SQLRETURN rc = SQL_SUCCESS;

	CConnect* pConnect = new CConnect(InputHandle);
	if (pConnect != NULL)
	{
		if ((rc = pConnect->initialize()) == SQL_SUCCESS)
			*OutputHandle = pConnect;
		else
		{
			delete pConnect;
			rc = SQL_ERROR;
		}
	}
	else
	{
		setDiagRec(DRIVER_ERROR, IDS_HY_001);
		rc = SQL_ERROR;
	}
	return rc;
}
Esempio n. 12
0
SQLRETURN ODBC::AllocHandle(SQLSMALLINT HandleType,
			SQLHANDLE InputHandle, 
			SQLHANDLE *OutputHandle)
{
	SQLRETURN	rc = SQL_SUCCESS;
	CEnv* pEnv;
	CConnect* pConnect;

	switch (HandleType)
	{
	case SQL_HANDLE_ENV:
		*OutputHandle = new CEnv(InputHandle);
		if (*OutputHandle == NULL)
			rc = SQL_ERROR;
		break;
	case SQL_HANDLE_DBC:
		pEnv = (CEnv*)InputHandle;
		EnterCriticalSection(&pEnv->m_CSObject);
		rc = pEnv->AllocHandle(HandleType,InputHandle,OutputHandle);
		LeaveCriticalSection(&pEnv->m_CSObject);
		break;
	case SQL_HANDLE_STMT:
		pConnect = (CConnect*)InputHandle;
		EnterCriticalSection(&pConnect->m_CSObject);
		rc = pConnect->AllocHandle(HandleType,InputHandle,OutputHandle);
		LeaveCriticalSection(&pConnect->m_CSObject);
		break;
	case SQL_HANDLE_DESC:
		pConnect = (CConnect*)InputHandle;
		EnterCriticalSection(&pConnect->m_CSObject);
		rc = pConnect->AllocHandle(HandleType,InputHandle,OutputHandle);
		LeaveCriticalSection(&pConnect->m_CSObject);
		break;
	default:
		*OutputHandle = SQL_NULL_HANDLE;
		break;
	}
	return rc;
}
Esempio n. 13
0
SQLRETURN ENDTRANSACT(SRVR_CALL_CONTEXT *srvrCallContext)
{
	CEE_status	sts;

    struct odbc_SQLSvc_EndTransaction_exc_ exception_ = {0,0,0};
	ERROR_DESC_LIST_def sqlWarning = {0,0};
	
	UDWORD timerTimeout = srvrCallContext->connectionTimeout;
	CConnect *pConnection = (CConnect *)srvrCallContext->sqlHandle;
	
	if (timerTimeout != 0)
		timerTimeout = (timerTimeout < 180)? 180: timerTimeout;

	sts = odbc_SQLDrvr_EndTransaction_pst_(
									srvrCallContext,
									srvrCallContext->dialogueId,
									srvrCallContext->u.completionType,
                                    &exception_,
                                    &sqlWarning);


	if (sts != CEE_SUCCESS)
	{
		if (sts == CEE_INTERNALFAIL)
			pConnection->setDiagRec(DRIVER_ERROR, IDS_EXCEPTION_MSG,0,"SQL SERVER",
				NULL,SQL_ROW_NUMBER_UNKNOWN,SQL_COLUMN_NUMBER_UNKNOWN,2,"Internal Error","ENDTRANSACT");
		else if (sts == TIMEOUT_EXCEPTION)
				pConnection->setDiagRec(DRIVER_ERROR, IDS_S1_T00, 0, FORMAT_ERROR((long)pConnection->m_srvrTCPIPSystem));
		else if (sts == COMM_LINK_FAIL_EXCEPTION)
				pConnection->setDiagRec(DRIVER_ERROR, IDS_08_S01, 0, FORMAT_ERROR((long)pConnection->m_srvrTCPIPSystem));
		else if (sts == TRANSPORT_ERROR)
				pConnection->setDiagRec(DRIVER_ERROR, IDS_08_S02, 0, FORMAT_ERROR((long)pConnection->m_srvrTCPIPSystem));
		else
			pConnection->setDiagRec(DRIVER_ERROR, IDS_S1_000, sts, FORMAT_ERROR((long)pConnection->m_srvrTCPIPSystem), 
				NULL, SQL_ROW_NUMBER_UNKNOWN, SQL_COLUMN_NUMBER_UNKNOWN, 1,"ENDTRANSACT failed");
		return SQL_ERROR;
	}

    odbc_SQLSvc_EndTransaction_ccf_ (srvrCallContext,
                                     &exception_,
                                     &sqlWarning);

	// 
	// cleanup
	//

	if(exception_.exception_nr == odbc_SQLSvc_EndTransaction_SQLError_exn_ &&
	   exception_.u.SQLError.errorList._length > 0 )
  	      delete[] exception_.u.SQLError.errorList._buffer;

	if(sqlWarning._length > 0)
		delete[] sqlWarning._buffer;


	switch (pConnection->getExceptionNr())
	{
		case CEE_SUCCESS:
			return SQL_SUCCESS;
		case odbc_SQLSvc_EndTransaction_SQLInvalidHandle_exn_:
			return SQL_INVALID_HANDLE;
		default:
			return SQL_ERROR;
	}
} // ENDTRANSACT()
Esempio n. 14
0
// Call Completion function for operation 'odbc_SQLSvc_SetConnectionOption'
extern "C" void odbc_SQLSvc_SetConnectionOption_ccf_ (
	CEE_tag_def cmptag_
  , const struct odbc_SQLSvc_SetConnectionOption_exc_ *exception_
  , const ERROR_DESC_LIST_def *sqlWarning
  )
{
	
	SRVR_CALL_CONTEXT	*srvrCallContext = (SRVR_CALL_CONTEXT *)cmptag_;
	CConnect			*pConnection = (CConnect *)srvrCallContext->sqlHandle;

	pConnection->setExceptionErrors(exception_->exception_nr, exception_->exception_detail);
	switch (exception_->exception_nr)
	{
	case CEE_SUCCESS:
		if (sqlWarning->_length > 0)
			pConnection->setDiagRec(sqlWarning);
		break;
	case odbc_SQLSvc_SetConnectionOption_SQLError_exn_:
		pConnection->setDiagRec(&exception_->u.SQLError);
		break;
	case odbc_SQLSvc_SetConnectionOption_ParamError_exn_:
		pConnection->setDiagRec(SERVER_ERROR, IDS_PROGRAM_ERROR, exception_->exception_nr, 
				exception_->u.ParamError.ParamDesc, NULL, 
				SQL_ROW_NUMBER_UNKNOWN, SQL_COLUMN_NUMBER_UNKNOWN, 1, pConnection->getSrvrIdentity());
		break;
	case odbc_SQLSvc_SetConnectionOption_SQLInvalidHandle_exn_: //This error code is used tempororily
		pConnection->setDiagRec(SERVER_ERROR, IDS_HY_000, 0, " SQL_ATTR_AUTOCOMMIT can not be changed when transaction is in progress");
		break;
	case odbc_SQLSvc_SetConnectionOption_InvalidConnection_exn_:
		pConnection->setDiagRec(SERVER_ERROR, IDS_08_S01);
		break;
	default:
		pConnection->sendCDInfo(exception_->exception_nr);
		pConnection->setDiagRec(exception_->exception_nr, SETCONNECT_PROCNAME,
					pConnection->getSrvrIdentity());
		break;
	}
}
Esempio n. 15
0
SQLRETURN TERMINATE_DIALOG(SRVR_CALL_CONTEXT *srvrCallContext)
{
	CEE_status	sts;
	long timerTimeout;

	odbc_SQLSvc_TerminateDialogue_exc_ exception_;

	CConnect *pConnection = (CConnect *)srvrCallContext->sqlHandle;
	timerTimeout = srvrCallContext->connectionTimeout > 10 ? srvrCallContext->connectionTimeout : 10;
	
	sts = odbc_SQLSvc_TerminateDialogue_(NULL,
		srvrCallContext,
		srvrCallContext->dialogueId,
		&exception_);

	if (sts != CEE_SUCCESS)
	{
		if (sts == CEE_INTERNALFAIL)
		{
			pConnection->setDiagRec(DRIVER_ERROR, IDS_EXCEPTION_MSG,0,"SQL SERVER",
				NULL,SQL_ROW_NUMBER_UNKNOWN,SQL_COLUMN_NUMBER_UNKNOWN,2,"Internal Error","TERMINATE_DIALOG");
			return SQL_ERROR;
		}
		pConnection->setDiagRec(DRIVER_ERROR, IDS_S1_000, sts, FORMAT_ERROR((long)pConnection->m_srvrTCPIPSystem),
			NULL, SQL_ROW_NUMBER_UNKNOWN, SQL_COLUMN_NUMBER_UNKNOWN, 1, "TERMINATE_DIALOG failed");
		return SQL_SUCCESS_WITH_INFO;
	}

	// Start CCF
	pConnection->setExceptionErrors(exception_.exception_nr, exception_.exception_detail);
	switch (exception_.exception_nr) {
	case CEE_SUCCESS:
		pConnection->resetGetObjRefHdlOutput();
		break;
	case odbc_SQLSvc_TerminateDialogue_SQLError_exn_:
		if (exception_.exception_detail == 25000)
			pConnection->setDiagRec(DRIVER_ERROR, IDS_25_000);
		else
			pConnection->setDiagRec(&exception_.u.SQLError);
		break;
	case odbc_SQLSvc_TerminateDialogue_ParamError_exn_:
		pConnection->setDiagRec(SERVER_ERROR, IDS_PROGRAM_ERROR, exception_.exception_nr, 
							exception_.u.ParamError.ParamDesc);
		break;
	case odbc_SQLSvc_TerminateDialogue_InvalidConnection_exn_:
		pConnection->sendCDInfo(exception_.exception_nr);
		pConnection->setDiagRec(SERVER_ERROR, IDS_08_S01);
		break;
	default:
		pConnection->sendCDInfo(exception_.exception_nr);
		pConnection->setDiagRec(exception_.exception_nr, TERMINATE_DIALOG_PROCNAME,
				pConnection->getSrvrIdentity());
		break;
	}
	if (exception_.exception_detail != 25000)
		CloseIO (pConnection->m_srvrTCPIPSystem);
	// Close CCF

	//
	// cleanup
	//
	if(exception_.exception_nr == odbc_SQLSvc_TerminateDialogue_SQLError_exn_ &&
	   exception_.u.SQLError.errorList._length > 0 )
  	      delete[] exception_.u.SQLError.errorList._buffer;



	switch (pConnection->getExceptionNr())
	{
		case CEE_SUCCESS:
			return SQL_SUCCESS;
		default:
	// if transaction is open return SQL_ERROR
			if (pConnection->getExceptionDetail() == 25000)
				return -25000;
			else
	// Any other errors treat them as if it has been disconnected
				return SQL_SUCCESS_WITH_INFO;
	}

} // TERMINATE_DIALOG()
Esempio n. 16
0
SQLRETURN GETOBJREF(SRVR_CALL_CONTEXT *srvrCallContext)
{
	DWORD			dwTimeout = 0;
	DWORD			curTimeout = 0;
	_timeb			time_start;
	_timeb			time_curr;

	SQLRETURN		rc = SQL_SUCCESS;
	CEE_status		sts;
	short			noOfRetries = 0;
	CConnect		*pConnection;
	VERSION_def		version;
	bool			bloop = true;
	int				dwSleep;

	odbcas_ASSvc_GetObjRefHdl_exc_ exception_ = {0,0,0};
	IDL_OBJECT_def		srvrObjRef;
	DIALOGUE_ID_def 	dialogueId = 0;
	SQL_IDENTIFIER_def	dataSource;
    USER_SID_def 		userSid = {0,0};;
    VERSION_LIST_def 	versionList = {0,0};
	long				isoMapping = 0;
	IDL_long			srvrNodeId = -1;
	IDL_long 		    srvrProcessId = -1;
	long long			timestamp = 0;

	IDL_OBJECT_def fwsrvrObjRef;
	char* pTCP;
	char* pIpAddress;
	char* pPortNumber;
	char* pObjectName;
	IDL_OBJECT_def objRef;
	char* pCheckComma;
	char* pCheck;
	char* srvrSegName=NULL;
	int   getObjRefRetryCnt = 0;

	pConnection = (CConnect *)srvrCallContext->sqlHandle;

	dwTimeout = srvrCallContext->u.connectParams.loginTimeout;
	
	if(dwTimeout != 0)
	{
		dwSleep = (dwTimeout / 3) * 1000;
		dwSleep = dwSleep > 5000 ? 5000 : dwSleep;
		dwSleep = dwSleep < 1000 ? 1000 : dwSleep;
	}
	else
		dwSleep = 5000;


	_ftime(&time_start);

TryAgain:

	pConnection->clearError();
		
	sts = odbcas_ASSvc_GetObjRefHdl_(NULL,
								srvrCallContext,
								srvrCallContext->u.connectParams.inContext,
								srvrCallContext->u.connectParams.userDesc,
								CORE_SRVR,
								getObjRefRetryCnt,
								&exception_,
				 				srvrObjRef,
								&dialogueId,
				 				dataSource,
								&userSid,
								&versionList,
								&isoMapping,
								&srvrNodeId,
								&srvrProcessId,
								&timestamp);

	if (sts != CEE_SUCCESS)
	{
		if (sts == CEE_INTERNALFAIL)
			pConnection->setDiagRec(ASSOC_SERVER_ERROR, IDS_EXCEPTION_MSG,0,"ASSOCIATION SERVICE",
				NULL,SQL_ROW_NUMBER_UNKNOWN,SQL_COLUMN_NUMBER_UNKNOWN,2,"Internal Error","GETOBJREF");
		else if (sts == TIMEOUT_EXCEPTION)
			pConnection->setDiagRec(DRIVER_ERROR, IDS_S1_T00, 0, FORMAT_ERROR((long)pConnection->m_asTCPIPSystem));
		else if ((sts == COMM_LINK_FAIL_EXCEPTION) || (sts == TRANSPORT_ERROR))
			pConnection->setDiagRec(ASSOC_SERVER_ERROR, IDS_ASSOC_SRVR_NOT_AVAILABLE,0, FORMAT_ERROR("ASSOCIATION SERVICE",(long)pConnection->m_asTCPIPSystem),
				NULL,SQL_ROW_NUMBER_UNKNOWN,SQL_COLUMN_NUMBER_UNKNOWN,1,"");
		else
			pConnection->setDiagRec(DRIVER_ERROR, IDS_ASSOC_SRVR_NOT_AVAILABLE, sts, FORMAT_ERROR((long)pConnection->m_asTCPIPSystem), 
				NULL, SQL_ROW_NUMBER_UNKNOWN, SQL_COLUMN_NUMBER_UNKNOWN, 1,LAST_ERROR_TO_TEXT());

		if(versionList._buffer != NULL)
			delete versionList._buffer;
		return SQL_ERROR;
	}
	
	/* Starts CCF */
	pConnection->setExceptionErrors(exception_.exception_nr, exception_.exception_detail);

	switch (exception_.exception_nr)
	{
	case CEE_SUCCESS:
		if (srvrObjRef[0] == 0)
		{
			pConnection->setExceptionErrors(odbcas_ASSvc_GetObjRefHdl_ASParamError_exn_,0);
			pConnection->setDiagRec(ASSOC_SERVER_ERROR, IDS_PROGRAM_ERROR, exception_.exception_nr,
					"Invalid Object Reference");
			break;
		}

		pConnection->m_srvrTCPIPSystem->setSwap(pConnection->m_asTCPIPSystem->swap());
		pConnection->setRetSrvrObjRef(srvrObjRef);
		strcpy(fwsrvrObjRef, srvrObjRef);

		strcpy(objRef, srvrObjRef);

		if ((pTCP = strtok(objRef, ":")) != NULL)
		{
			pCheckComma = strchr( srvrObjRef, ',' );
			if (pCheckComma != NULL)
			{
//
// New object ref tcp:\neo0001.$z123,1.2.3.4/18650:ObjectName
//
				pCheck = strtok(NULL,",");
				if (pCheck != NULL)
				{
					if ((pIpAddress = strtok(NULL, "/"))  != NULL)
					{
						if ((pPortNumber = strtok(NULL, ":")) != NULL)
						{
							if ((pObjectName = strtok(NULL, ":")) != NULL)
							{
								sprintf( fwsrvrObjRef, "%s:%s/%s:%s", pTCP,pIpAddress,pPortNumber,pObjectName);
							}
						}
					}
					srvrSegName = strtok(pCheck, ".");
				}
			}
			else
			{
//
// Old object ref tcp:\neo0001.$z123/18650:ObjectName
//
				strcpy(objRef, srvrObjRef);
				pCheck = objRef + 5;
				if ((pIpAddress = strtok(pCheck, ".")) != NULL)
				{
					strtok(NULL, "/");
					if ((pPortNumber = strtok(NULL, ":")) != NULL)
					{
						if ((pObjectName = strtok(NULL, ":")) != NULL)
						{
							sprintf( fwsrvrObjRef, "tcp:%s/%s:%s", pIpAddress,pPortNumber,pObjectName);
						}
					}
					srvrSegName = pIpAddress;
				}
			}
		}
		pConnection->setGetObjRefHdlOutput(fwsrvrObjRef, dialogueId, dataSource, &userSid, &versionList, srvrNodeId, srvrProcessId, timestamp);
		break;
	case odbcas_ASSvc_GetObjRefHdl_ASParamError_exn_ :
	// Added check to see if No CPUs or Invalid CPU list are set for MXCS server to start then return 
	// error back to client as param error then parse the error in client to return proper error message.
		pCheck = strstr(exception_.u.ASParamError.ErrorText, "CPU" );
		if (pCheck == NULL)
			pConnection->setDiagRec(ASSOC_SERVER_ERROR, IDS_PROGRAM_ERROR, exception_.exception_nr,
				exception_.u.ASParamError.ErrorText);
		else
			pConnection->setDiagRec(ASSOC_SERVER_ERROR,IDS_NO_SRVR_AVAILABLE, 0,
				exception_.u.ASNotAvailable.ErrorText);
		break;	
	case odbcas_ASSvc_GetObjRefHdl_LogonUserFailure_exn_ :
		PVOID lpMsgBuf;
		FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
				NULL,
				exception_.u.LogonUserFailure.errorCode,
				MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), // Default language
				(LPTSTR) &lpMsgBuf,
				0,
				NULL);
		pConnection->setDiagRec(ASSOC_SERVER_ERROR, IDS_UNABLE_TO_LOGON,
			exception_.u.LogonUserFailure.errorCode,
			 (char *)lpMsgBuf);
		LocalFree(lpMsgBuf);
		break;
	case odbcas_ASSvc_GetObjRefHdl_ASNotAvailable_exn_ :
		pConnection->setDiagRec(ASSOC_SERVER_ERROR,IDS_ASSOC_SRVR_NOT_AVAILABLE, 0,
			exception_.u.ASNotAvailable.ErrorText);
		break;
	case odbcas_ASSvc_GetObjRefHdl_DSNotAvailable_exn_:
		pConnection->setDiagRec(ASSOC_SERVER_ERROR,IDS_DS_NOT_AVAILABLE,0L,	
			exception_.u.DSNotAvailable.ErrorText);
		break;
	case odbcas_ASSvc_GetObjRefHdl_PortNotAvailable_exn_:
		pConnection->setDiagRec(ASSOC_SERVER_ERROR, IDS_PORT_NOT_AVAILABLE);
		break;
	case odbcas_ASSvc_GetObjRefHdl_InvalidUser_exn_:
		pConnection->setDiagRec(ASSOC_SERVER_ERROR, IDS_28_000);
		break;
	case odbcas_ASSvc_GetObjRefHdl_ASTimeout_exn_ :
		pConnection->setDiagRec(ASSOC_SERVER_ERROR, IDS_S1_T00);
		break;
	case odbcas_ASSvc_GetObjRefHdl_ASNoSrvrHdl_exn_ :
		pConnection->setDiagRec(ASSOC_SERVER_ERROR,IDS_NO_SRVR_AVAILABLE, 0,
			exception_.u.ASNotAvailable.ErrorText);
		break;
	case odbcas_ASSvc_GetObjRefHdl_ASTryAgain_exn_ :
	case -27:
		break;
	case -29:
		break;
	default:
		pConnection->setDiagRec(exception_.exception_nr, GET_OBJECT_REF_PROCNAME,
				pConnection->getSrvrIdentity());
		break;
	}	/* Ends CCF */

	
	switch (pConnection->getExceptionNr())
	{
	case CEE_SUCCESS:
		pConnection->getVersion(&version, NSK_ODBCAS_COMPONENT);
		if (version.componentId != NSK_ODBCAS_COMPONENT ||
			version.majorVersion != NSK_VERSION_MAJOR_1 ||
			version.minorVersion != NSK_VERSION_MINOR_0 )
		{
			char tmp[100];
			IDL_short majorVersion = version.majorVersion;
			IDL_short minorVersion = version.minorVersion;
			majorVersion = (majorVersion > 0)? majorVersion - 1: majorVersion;
			sprintf(tmp,"Incorrect AS version: %d.%d, expected: %d.%d",majorVersion,minorVersion,NSK_VERSION_MAJOR_1 - 1,NSK_VERSION_MINOR_0);
			pConnection->setDiagRec(ASSOC_SERVER_ERROR, IDS_S1_000, 0, tmp,NULL, 0, 0, 1, tmp);
			rc = SQL_ERROR;
		}
		break;
	case odbcas_ASSvc_GetObjRefHdl_ASTryAgain_exn_:
		_ftime(&time_curr);
		curTimeout = (long)(time_curr.time - time_start.time);

		if ((dwTimeout != 0) && (dwTimeout <= curTimeout))
		{
			pConnection->setDiagRec(ASSOC_SERVER_ERROR, IDS_S1_T00);
			rc = SQL_ERROR;
			break;
		}
		else
		{
			if(dwTimeout != 0)
				srvrCallContext->u.connectParams.loginTimeout = dwTimeout - curTimeout;

			Sleep(dwSleep); 
			getObjRefRetryCnt++;
			goto TryAgain;
		}
		break;
	default:
		rc = SQL_ERROR;
		break;
	}

	/*
	 * CleanUp
	 */ 

	if(versionList._buffer != NULL)
		delete versionList._buffer;

	return rc;
}
Esempio n. 17
0
SQLRETURN INITIALIZE_DIALOG(SRVR_CALL_CONTEXT *srvrCallContext)
{
	CEE_status							sts;
	CConnect							*pConnection;
	SQLRETURN							rc = SQL_SUCCESS;
	// RAJANI - for password expiry
	CONNECT_FIELD_ITEMS					connectFieldItems;
	bool								bChangePwd = false;

    odbc_SQLSvc_InitializeDialogue_exc_ exception_ = {0,0,0};
    OUT_CONNECTION_CONTEXT_def outContext;

	pConnection = (CConnect *)srvrCallContext->sqlHandle;
	short retry = 0;

	retryInitializeDialogue:

	do
	{
		sts = odbc_SQLSvc_InitializeDialogue_(NULL,
									srvrCallContext,
									srvrCallContext->u.connectParams.userDesc,
									srvrCallContext->u.connectParams.inContext,
									srvrCallContext->dialogueId,
									&exception_,
									&outContext);
		if (sts == CEE_SUCCESS) break;
		Sleep(100);
	}
	while (sts == COMM_LINK_FAIL_EXCEPTION && retry++ < 3);

	if (sts != CEE_SUCCESS)
	{
		if (sts == CEE_INTERNALFAIL)
			pConnection->setDiagRec(DRIVER_ERROR, IDS_EXCEPTION_MSG,0,"SQL SERVER",
				NULL,SQL_ROW_NUMBER_UNKNOWN,SQL_COLUMN_NUMBER_UNKNOWN,2,"Internal Error","INITIALIZE_DIALOG");
		else if (sts == TIMEOUT_EXCEPTION)
			pConnection->setDiagRec(DRIVER_ERROR, IDS_S1_T00, 0, FORMAT_ERROR((long)pConnection->m_srvrTCPIPSystem));
		else if (sts == COMM_LINK_FAIL_EXCEPTION)
			pConnection->setDiagRec(SERVER_ERROR, IDS_08_S01, 0, FORMAT_ERROR((long)pConnection->m_srvrTCPIPSystem));
		else if (sts == TRANSPORT_ERROR)
			pConnection->setDiagRec(SERVER_ERROR, IDS_08_S02, 0, FORMAT_ERROR((long)pConnection->m_srvrTCPIPSystem));
		else
			pConnection->setDiagRec(DRIVER_ERROR, IDS_S1_000, sts, FORMAT_ERROR((long)pConnection->m_srvrTCPIPSystem), 
				NULL, SQL_ROW_NUMBER_UNKNOWN, SQL_COLUMN_NUMBER_UNKNOWN, 1,"INITIALIZE_DIALOG failed");
		return SQL_ERROR;
	}

	// Start CCF
	pConnection->setExceptionErrors(exception_.exception_nr, exception_.exception_detail);
	
	switch ( exception_.exception_nr) 
	{
	case CEE_SUCCESS:
		pConnection->setOutContext(&outContext);
		break;
	case odbc_SQLSvc_InitializeDialogue_SQLError_exn_:
		if (exception_.exception_detail == 4415) // SECMXO_NO_CERTIFICATE
		{
			try{
				if (pConnection->m_SecPwd->switchCertificate()==SQL_SUCCESS) // successfully switched to the new certificate
					pConnection->setRetryEncryption();
				else // there is no certificate to switch to
					pConnection->setDiagRec(&exception_.u.SQLError);
			}
			catch (SecurityException se) {
				rc= se.getErrCode();
				pConnection->setSecurityError(rc, se.getSQLState(), se.getMsg());
			}
		}
		else
			pConnection->setDiagRec(&exception_.u.SQLError);
		break;
	case odbc_SQLSvc_InitializeDialogue_InvalidUser_exn_:
		if (outContext.outContextOptions1 & OUTCONTEXT_OPT1_DOWNLOAD_CERTIFICATE)
		{
			try {
				pConnection->m_SecPwd->switchCertificate(outContext.outContextOptionString, outContext.outContextOptionStringLen);
			} 
			catch (SecurityException se) {
				rc = se.getErrCode();
				pConnection->setSecurityError(rc, se.getSQLState(), se.getMsg());
			}
			if(rc == SQL_SUCCESS)
				pConnection->setRetryEncryption();
		}
		else if (srvrCallContext->u.connectParams.userDesc->userName != NULL && srvrCallContext->u.connectParams.userDesc->password._buffer != NULL)
			pConnection->setDiagRec(&exception_.u.SQLError);
		break;
	case odbc_SQLSvc_InitializeDialogue_ParamError_exn_:
		pConnection->setDiagRec(SQLMX_ERROR, IDS_28_000, exception_.exception_nr,
			(char*)(LPCTSTR)exception_.u.ParamError.ParamDesc, NULL, 
			SQL_ROW_NUMBER_UNKNOWN, SQL_COLUMN_NUMBER_UNKNOWN, 1, INITIALIZE_DIALOG_PROCNAME);
		break;
	case odbc_SQLSvc_InitializeDialogue_InvalidConnection_exn_:
		pConnection->setDiagRec(SERVER_ERROR, IDS_08_004_01);
		break;
	case odbc_SQLSvc_InitializeDialogue_SQLInvalidHandle_exn_:
		break;
	case odbc_SQLSvc_InitializeDialogue_SQLNeedData_exn_:
		break;
	default:
		pConnection->setDiagRec(exception_.exception_nr, INITIALIZE_DIALOG_PROCNAME,
				pConnection->getSrvrIdentity());
		break;
	}
	// End CCF
	
	switch (pConnection->getExceptionNr())
	{
		case CEE_SUCCESS:
			break;
		case odbc_SQLSvc_InitializeDialogue_SQLInvalidHandle_exn_:
			rc = SQL_INVALID_HANDLE;
			break;
		case odbc_SQLSvc_InitializeDialogue_SQLError_exn_: 
			if(pConnection->getExceptionDetail() == SQL_PASSWORD_EXPIRING || pConnection->getExceptionDetail() == SQL_PASSWORD_GRACEPERIOD)
			{
				pConnection->setOutContext(&outContext);
				rc = SQL_SUCCESS_WITH_INFO;
			}
			else
				rc = SQL_ERROR;
			break;
			//Arvind: When using a dummy username, it would get connected and can perform operations.
		case odbc_SQLSvc_InitializeDialogue_SQLNeedData_exn_:
			rc = SQL_NEED_DATA;
			break;
		default:
			rc = SQL_ERROR;
			break;
	}

	//
	// cleanup
	//
	if(exception_.exception_nr == odbc_SQLSvc_InitializeDialogue_SQLError_exn_ &&
	   exception_.u.SQLError.errorList._length > 0 )
  	      delete[] exception_.u.SQLError.errorList._buffer;
	if(exception_.exception_nr == odbc_SQLSvc_InitializeDialogue_InvalidUser_exn_ &&
	   exception_.u.InvalidUser.errorList._length > 0 )
  	      delete[] exception_.u.InvalidUser.errorList._buffer;
	if(outContext.versionList._length > 0)
		delete [] outContext.versionList._buffer;
	if((outContext.outContextOptions1 & OUTCONTEXT_OPT1_ROLENAME || outContext.outContextOptions1 & OUTCONTEXT_OPT1_DOWNLOAD_CERTIFICATE)
		&& outContext.outContextOptionStringLen > 0)
		delete [] outContext.outContextOptionString;

	return rc;

} // INITIALIZE_DIALOG()
extern "C" CEE_status
odbcas_ASSvc_GetObjRefHdl_(
    /* In    */ const CEE_handle_def *ph_
  , /* In    */ CEE_tag_def tag_
  , /* In    */ const CONNECTION_CONTEXT_def *inContext
  , /* In    */ const USER_DESC_def *userDesc
  , /* In    */ IDL_long srvrType
  , /* In    */ IDL_short retryCount
  , /* Out   */ odbcas_ASSvc_GetObjRefHdl_exc_ *exception_
  , /* Out   */	char 				*srvrObjRef
  , /* Out   */ DIALOGUE_ID_def 	*dialogueId
  , /* Out   */ char 				*dataSource
  , /* Out   */ USER_SID_def 		*userSid
  , /* Out   */ VERSION_LIST_def 	*versionList
  , /* Out   */ IDL_long		 	*isoMapping
  , /* Out   */ IDL_long		 	*srvrNodeId
  , /* Out   */ IDL_long		 	*srvrProcessId
  , /* Out   */ IDL_long_long	 	*timestamp
  )
{
	CEE_status retcode;
	bool sts;
	IDL_long wlength,rlength;
	IDL_char* wbuffer, *rbuffer;
	IDL_char* curptr;

	IDL_long msg_total_length = 0;
	IDL_long exceptionLength = 0;
	IDL_long datasourceLength = 0;
	IDL_long srvrObjRefLength = 0;
	IDL_long userSidLength = 0;
	IDL_long clusternameLength = 0;

	VERSION_def version[4];
	VERSION_def* versionPtr = &version[0];

	char srvrHostName[100] = {0};
	IDL_long srvrHostNameLength = 0;
	char srvrProcessName[100] = {0};
	IDL_long srvrProcessNameLength = 0;
	char srvrIpAddress[100] = {0};
	IDL_long srvrIpAddressLength = 0;
	IDL_long srvrPort = 0;
	
	SRVR_CALL_CONTEXT *srvrCallContext = (SRVR_CALL_CONTEXT *)tag_;
	CConnect *pConnection = (CConnect *)srvrCallContext->sqlHandle;

	pConnection->m_asTCPIPSystem->odbcAPI = AS_API_GETOBJREF;
	pConnection->m_asTCPIPSystem->dialogueId = srvrCallContext->dialogueId;
	pConnection->m_asTCPIPSystem->dwTimeout = srvrCallContext->u.connectParams.loginTimeout;

//
// do marshaling of input parameters
//
	retcode = odbcas_ASSvc_GetObjRefHdl_param_pst_(
		  pConnection->m_asTCPIPSystem
		, wbuffer
		, wlength
		, inContext
		, userDesc
		, srvrType
		, retryCount);

	if (retcode != CEE_SUCCESS)
		return retcode;

	sts = OpenIO (pConnection->m_asTCPIPSystem,pConnection->getAsObjRef());
	if (sts == false)
		return MAP_AS_ERRORS((long)pConnection->m_asTCPIPSystem);

	sts = DoIO (pConnection->m_asTCPIPSystem, wbuffer, wlength, rbuffer, rlength,pConnection);
 	if (sts == false)
		return MAP_AS_ERRORS((long)pConnection->m_asTCPIPSystem);

	CloseIO (pConnection->m_asTCPIPSystem);

//
// process output parameters
//
	char swap = pConnection->m_asTCPIPSystem->swap();

	curptr = rbuffer;
	//
	// copy odbcas_ASSvc_GetObjRefHdl_exc_ *exception_
	//

	exception_->exception_nr = *(IDL_long *)(curptr + msg_total_length);
	msg_total_length += sizeof(exception_->exception_nr);
	LONG_swap(&exception_->exception_nr,swap);

	exception_->exception_detail = *(IDL_long *)(curptr + msg_total_length);
	msg_total_length += sizeof(exception_->exception_detail);
	LONG_swap(&exception_->exception_detail,swap);

	exceptionLength = *(IDL_long *)(curptr + msg_total_length);
	msg_total_length += sizeof(exceptionLength);
	LONG_swap(&exceptionLength,swap);

    if(exceptionLength > 0)
	{
       exception_->u.ASParamError.ErrorText = (IDL_char*)(curptr+msg_total_length);
       msg_total_length += exceptionLength;
	   return CEE_SUCCESS; // no point in continuing
	}

	//
	// copy DIALOGUE_ID_def dialogueId
	//
	*dialogueId = *(IDL_long *) (curptr + msg_total_length);
	msg_total_length += sizeof(*dialogueId);
	LONG_swap(dialogueId,swap);
	//
	// copy IDL_char *dataSource
	//
	datasourceLength = *(IDL_long *)(curptr + msg_total_length);
	msg_total_length += sizeof(datasourceLength);
	LONG_swap(&datasourceLength,swap);
	if (datasourceLength != 0)
	{
		memcpy(dataSource, curptr + msg_total_length, datasourceLength);
		msg_total_length += datasourceLength;
	}

	// copy userSidLength
	userSid->_length = *(IDL_unsigned_long *)(curptr+msg_total_length);
	msg_total_length += sizeof(userSid->_length);
	ULONG_swap(&userSid->_length,swap);

	// copy userSid
	if (userSid->_length != 0)
	{
        userSid->_buffer = (unsigned char *)(IDL_char*)(curptr+msg_total_length);
		msg_total_length += userSid->_length+1;
	}

	// copy VERSION_LIST_def *versionList
	
	versionList->_length = *(IDL_unsigned_long *)(curptr + msg_total_length);
	msg_total_length += sizeof(versionList->_length);
	ULONG_swap(&versionList->_length,swap);

	// Get the versionPtr
	versionList->_buffer = (VERSION_def *)new char[versionList->_length*sizeof(VERSION_def)];
	versionPtr = versionList->_buffer; 
	
	for (int i = 0; i < versionList->_length; i++)
	{
		// copy componentId
		versionPtr->componentId = *(IDL_short *)(curptr + msg_total_length);
		msg_total_length += sizeof(versionPtr->componentId);
		SHORT_swap(&versionPtr->componentId,swap);

		// copy majorVersion
		versionPtr->majorVersion = *(IDL_short *)(curptr + msg_total_length);
		msg_total_length += sizeof(versionPtr->majorVersion);
		SHORT_swap(&versionPtr->majorVersion,swap);

		// copy minorVersion
		versionPtr->minorVersion = *(IDL_short *)(curptr + msg_total_length);
		msg_total_length += sizeof(versionPtr->minorVersion);
		SHORT_swap(&versionPtr->minorVersion,swap);

		// copy buildId
		versionPtr->buildId = *(IDL_unsigned_long *)(curptr + msg_total_length);
		msg_total_length += sizeof(versionPtr->buildId);
		ULONG_swap(&versionPtr->buildId,swap);
		
		// Get the next versionlist values
		versionPtr++;
	}

	//Check whether connected to an R2.3 server
	if (versionList->_buffer->buildId & CHARSET)
	{
		//
		// copy IDL_long isoMapping
		//
		*isoMapping = *(IDL_long *) (curptr + msg_total_length);
		msg_total_length += sizeof(*isoMapping);
	LONG_swap(isoMapping,swap);
	}
	else
		*isoMapping = NON_CHARSET_SYSTEM ; //Connected to an R2.2 system.

	//
	// copy IDL_char *srvrHostName
	//
	srvrHostNameLength = *(IDL_long *)(curptr + msg_total_length);
	msg_total_length += sizeof(srvrHostNameLength);
	LONG_swap(&srvrHostNameLength,swap);
	if (srvrHostNameLength != 0)
	{
		memcpy(srvrHostName, curptr + msg_total_length, srvrHostNameLength);
		msg_total_length += srvrHostNameLength;
	}
	//
	// copy IDL_long srvrNodeId
	//
	*srvrNodeId = *(IDL_long *) (curptr + msg_total_length);
	msg_total_length += sizeof(*srvrNodeId);
	LONG_swap(srvrNodeId,swap);
	//
	// copy IDL_long srvrProcessId
	//
	*srvrProcessId = *(IDL_long *) (curptr + msg_total_length);
	msg_total_length += sizeof(*srvrProcessId);
	LONG_swap(srvrProcessId,swap);
	//
	// copy IDL_char *srvrProcessName
	//
	srvrProcessNameLength = *(IDL_long *)(curptr + msg_total_length);
	msg_total_length += sizeof(srvrProcessNameLength);
	LONG_swap(&srvrProcessNameLength,swap);
	if (srvrProcessNameLength != 0)
	{
		memcpy(srvrProcessName, curptr + msg_total_length, srvrProcessNameLength);
		msg_total_length += srvrProcessNameLength;
	}
	//
	// copy IDL_char *srvrIpAddress
	//
	srvrIpAddressLength = *(IDL_long *)(curptr + msg_total_length);
	msg_total_length += sizeof(srvrIpAddressLength);
	LONG_swap(&srvrIpAddressLength,swap);
	if (srvrProcessNameLength != 0)
	{
		memcpy(srvrIpAddress, curptr + msg_total_length, srvrIpAddressLength);
		msg_total_length += srvrIpAddressLength;
	}
	//
	// copy IDL_long srvrPort
	//
	srvrPort = *(IDL_long *) (curptr + msg_total_length);
	msg_total_length += sizeof(srvrPort);
	LONG_swap(&srvrPort,swap);

	sprintf(srvrObjRef,"TCP:%s:%d.%s,%s/%d:ODBC", srvrHostName, *srvrNodeId, srvrProcessName, srvrIpAddress, srvrPort);


	//Check whether connected to server with password security support
	if (versionList->_buffer->buildId & PASSWORD_SECURITY)
	{
		//
		// copy IDL_long_long timestamp
		//
		*timestamp = *(IDL_long_long *) (curptr + msg_total_length);
		msg_total_length += sizeof(*timestamp);
		LONGLONG_swap(timestamp,swap);

		//
		// copy clustername
		//
		clusternameLength = *(IDL_long *)(curptr + msg_total_length);
		msg_total_length += sizeof(clusternameLength);
		LONG_swap(&clusternameLength,swap);
		if (clusternameLength != 0)
		{
			memcpy(pConnection->m_ClusterName, curptr + msg_total_length, clusternameLength);
			msg_total_length += clusternameLength;
		}

	}
	return CEE_SUCCESS;
}
Esempio n. 19
0
SQLRETURN ODBC::FreeHandle(SQLSMALLINT HandleType, 
			SQLHANDLE Handle)
{
	CEnv* pEnv;
	CConnect* pConnect;
	CStmt* pStmt;
	CDesc* pDesc;

	switch (HandleType)
	{
	case SQL_HANDLE_ENV:
		delete (CEnv *)Handle;
		break;
	case SQL_HANDLE_DBC:
		pConnect = (CConnect *)Handle;
		pEnv = pConnect->getEnvHandle();
		if(TryEnterCriticalSection(&pEnv->m_CSObject))
		{
			if(pEnv->m_CSObject.RecursionCount > 1)
			{
  			    pConnect->setDiagRec(DRIVER_ERROR, IDS_HY_000, 0, "The handle is in use and cannot be freed.");
				LeaveCriticalSection(&pEnv->m_CSObject);
				return SQL_ERROR;
			}
		}
		else
		{
		   EnterCriticalSection(&pEnv->m_CSObject);
		}
		delete pConnect;
		LeaveCriticalSection(&pEnv->m_CSObject);
		break;
	case SQL_HANDLE_STMT:
		pStmt = (CStmt *)Handle;
		pConnect = pStmt->getConnectHandle();
		if(TryEnterCriticalSection(&pConnect->m_CSObject))
		{
			if(pConnect->m_CSObject.RecursionCount > 1)
			{
  			    pStmt->setDiagRec(DRIVER_ERROR, IDS_HY_000, 0, "The handle is in use and cannot be freed.");
				LeaveCriticalSection(&pConnect->m_CSObject);
				return SQL_ERROR;
			}
		}
		else
		{
		   EnterCriticalSection(&pConnect->m_CSObject);
		}
		delete pStmt;
		LeaveCriticalSection(&pConnect->m_CSObject);
		break;
	case SQL_HANDLE_DESC:
		pDesc = (CDesc *)Handle;
		pConnect = pDesc->getDescConnect();
		if(TryEnterCriticalSection(&pConnect->m_CSObject))
		{
			if(pConnect->m_CSObject.RecursionCount > 1)
			{
  			    pDesc->setDiagRec(DRIVER_ERROR, IDS_HY_000, 0, "The handle is in use and cannot be freed.");
				LeaveCriticalSection(&pConnect->m_CSObject);
				return SQL_ERROR;
			}
		}
		else
		{
		   EnterCriticalSection(&pConnect->m_CSObject);
		}
		delete pDesc;
		LeaveCriticalSection(&pConnect->m_CSObject);
		break;
	default:
		return SQL_INVALID_HANDLE;
	}
	return SQL_SUCCESS;

}
Esempio n. 20
0
int _tmain(int argc, _TCHAR* argv[])
{
	bool bReturn = false;
	for(int i = 0;i < 5;++i)
	{
		//std::string host = "10.0.0.218";
		//std::string user = "******";
		//std::string password = "******";
		//std::string dbname = "test";
		//WORD port = MYSQL_PORT;
		CConnect * conn = new CConnect();
		bReturn = false;
		//bReturn = conn->Connect(host, user, password, dbname, port);
		bReturn = conn->Connect("localhost", "root", "tiptop", "test", MYSQL_PORT);
		if (bReturn)
		{
			std::cout<<"连接数据库成功!!!"<<endl;
		}
		else
		{
			std::cout<<"连接数据库失败!!!"<<endl;
		}					
		
		//bReturn = conn->Connect("10.0.0.218", "root", "tiptop", "test", MYSQL_PORT);
		CManagerPool::GetInitInstance().AddConObject(conn);
	}

	CSqlClient client;

	COperMysql store;
	store.SetTransAction(client.GetConnect());

	//先删除数据表
	std::string s_sql = "drop table processingtransactioninterface";//删除表
	if(!store.Exec(s_sql))
	{
		//删除表失败
		std::cout<<"drop table fail"<<endl<<store.What()<<endl;   
	}
	else
	{
		std::cout<<"drop table success"<<endl;
	}

	//创建数据表,字段 actid 设置了自增列属性
	s_sql = "create table processingtransactioninterface(";
	s_sql += "actid integer not null AUTO_INCREMENT,";
	s_sql += "acttype integer not null,resourceid integer not null,";
	s_sql += " subresoureid  integer, actdate varchar(19), actresult integer,";
	s_sql += " memo varchar(50) null,primary key(actid))";
	if(!store.Exec(s_sql))
	{
		//创建表失败
		std::cout<<"create table fail"<<endl;
		return -1;
	}
	else
	{
		std::cout<<"create table success"<<endl;
		std::cout<<s_sql.c_str()<<endl;
	}
	std::cout<<"开始运行线程……"<<endl;

	unsigned long p1 = 0;	
	::CreateThread(0,0,(funcptr)show,0,0,&p1);

	unsigned long p2 = 0;	
	::CreateThread(0,0,(funcptr)update,0,0,&p2);
	
	unsigned long p3 = 0;
	::CreateThread(0,0,(funcptr)insert,0,0,&p3);

	system("pause");
	return 0;
}
Esempio n. 21
0
DWORD WINAPI CNetworkMgr::AcceptThread( void *pParam )
{
	CNetworkMgr *pNetworkSrv = (CNetworkMgr *)pParam;

	HANDLE	hComPort = pNetworkSrv->m_hCompPort;	//完成端口
	SOCKET	sListen = pNetworkSrv->m_socket;		//监听套接字

	SOCKET	sAccept = INVALID_SOCKET;				//接受客户端连接的套接字
	//sockaddr_in	addrClient;		//客户端SOCKET地址

	while ( pNetworkSrv->m_bRunning )
	{
		DWORD dwRet;
		dwRet = WSAWaitForMultipleEvents( 1, &pNetworkSrv->m_hEvent, FALSE, 100, FALSE );	//等待网络事件

		if ( !pNetworkSrv->m_bRunning )				//服务器停止服务
		{
			break;
		}

		if ( dwRet == WSA_WAIT_TIMEOUT )			//函数调用超时
		{
			continue;
		}

		WSANETWORKEVENTS events;
		int nRet = WSAEnumNetworkEvents( pNetworkSrv->m_socket, pNetworkSrv->m_hEvent, &events );

		if ( SOCKET_ERROR == nRet )
		{
			pNetworkSrv->ShowErrorMsg( "WSAEnumNetworkEvents() failed!\n" );
			break;
		}

		if ( events.lNetworkEvents & FD_ACCEPT )
		{
			if ( events.iErrorCode[FD_ACCEPT_BIT] == 0 && pNetworkSrv->m_bRunning)
			{
				sockaddr_in addrClient;
				int addrClientLen = sizeof( addrClient );
				sAccept = WSAAccept( sListen, (LPSOCKADDR)&addrClient, &addrClientLen, NULL, 0 );
				if ( INVALID_SOCKET == sAccept )
				{
					pNetworkSrv->ShowErrorMsg( "WSAAccept() failed!\n" );
					break;
				}

				CConnect *pConnect = new CConnect( sAccept, addrClient );

				if ( CreateIoCompletionPort( (HANDLE)sAccept, hComPort, (DWORD)pConnect, 0 ) == NULL )
				{
					return -1;
				}

				//加入管理客户端链表
				CConnectMgr *pConnectMgr = CConnectMgr::GetInstance();
				pConnectMgr->AddConnect( pConnect );
				if ( !pConnect->AsyncRecvHead() )
				{
					pConnectMgr->DeleteConnect( pConnect );
				}

			}
		}
		
	}

	//释放资源
	CConnectMgr *pConnectMgr = CConnectMgr::GetInstance();
	pConnectMgr->DeleteAllConnect();
	pConnectMgr->Release();

	//Sleep( 10000 );
	printf( "AcceptThread return\n" );

	return 0;
}
Esempio n. 22
0
extern "C" void odbc_SQLSvc_EndTransaction_ccf_ (
    CEE_tag_def cmptag_
  , const struct odbc_SQLSvc_EndTransaction_exc_ *exception_
  , const ERROR_DESC_LIST_def *sqlWarning
  )
{

	SRVR_CALL_CONTEXT	*srvrCallContext = (SRVR_CALL_CONTEXT *)cmptag_;
	CConnect			*pConnection = (CConnect *)srvrCallContext->sqlHandle;

	pConnection->setExceptionErrors(exception_->exception_nr, exception_->exception_detail);
	switch (exception_->exception_nr)
	{
		case CEE_SUCCESS:
			if (sqlWarning->_length > 0)
				pConnection->setDiagRec(sqlWarning);
			break;
		case odbc_SQLSvc_EndTransaction_SQLError_exn_:
			pConnection->setDiagRec(&exception_->u.SQLError);
			break;
		case odbc_SQLSvc_EndTransaction_ParamError_exn_:
			pConnection->setDiagRec(SERVER_ERROR, IDS_PROGRAM_ERROR, exception_->exception_nr, 
					exception_->u.ParamError.ParamDesc, NULL, 
					SQL_ROW_NUMBER_UNKNOWN, SQL_COLUMN_NUMBER_UNKNOWN, 1, pConnection->getSrvrIdentity());
			break;
		case odbc_SQLSvc_EndTransaction_SQLInvalidHandle_exn_:
			break;
		case odbc_SQLSvc_EndTransaction_InvalidConnection_exn_:
			pConnection->setDiagRec(SERVER_ERROR, IDS_08_S01);
			break;
		case odbc_SQLSvc_EndTransaction_TransactionError_exn_:
			char tmpNumBuffer[16];
			_itoa (exception_->exception_detail, tmpNumBuffer, 10);
			pConnection->setDiagRec(SERVER_ERROR, IDS_TRANSACTION_ERROR, exception_->exception_nr,
						tmpNumBuffer, NULL, SQL_ROW_NUMBER_UNKNOWN, SQL_COLUMN_NUMBER_UNKNOWN, 1, pConnection->getSrvrIdentity());
			break;
		default:
			pConnection->sendCDInfo(exception_->exception_nr);
			pConnection->setDiagRec(exception_->exception_nr, ENDTRANSACT_PROCNAME,
					pConnection->getSrvrIdentity());
			break;
	}

} // odbc_SQLSvc_EndTransaction_ccf_()
Esempio n. 23
0
SQLRETURN ODBC::GetDiagRec(SQLSMALLINT HandleType, 
				SQLHANDLE Handle,
				SQLSMALLINT RecNumber,
				SQLWCHAR *Sqlstate,
				SQLINTEGER *NativeError, 
				SQLWCHAR *MessageText,
				SQLSMALLINT BufferLength, 
				SQLSMALLINT *TextLength)
{

	SQLRETURN rc;
	DWORD	ErrorMsgLang = 0;
	CConnect* pConnect;
	CStmt* pStmt;
	CDesc* pDesc;
	
	switch (HandleType)
	{
	case SQL_HANDLE_ENV:
		break;
	case SQL_HANDLE_DBC:
		pConnect = (CConnect*)Handle;
		EnterCriticalSection(&pConnect->m_CSObject);
		ErrorMsgLang = pConnect->getErrorMsgLang();
		break;
	case SQL_HANDLE_STMT:
		pStmt = (CStmt *)Handle;
		pConnect = pStmt->getConnectHandle();
		EnterCriticalSection(&pConnect->m_CSObject);
		ErrorMsgLang = pStmt->getErrorMsgLang();
		break;
	case SQL_HANDLE_DESC:
		pDesc = (CDesc *)Handle;
		pConnect = pDesc->getDescConnect();
		EnterCriticalSection(&pConnect->m_CSObject);
		ErrorMsgLang = pDesc->getErrorMsgLang();
		break;
	default:
		return SQL_INVALID_HANDLE;
	}
	__try{
		rc = ((CHandle *)Handle)->GetDiagRec(HandleType, Handle, 
					RecNumber, ErrorMsgLang, Sqlstate, NativeError, MessageText, BufferLength, TextLength);
	}
	__finally {
		switch (HandleType)
		{
			case SQL_HANDLE_ENV:
				break;
			case SQL_HANDLE_DBC:
				LeaveCriticalSection(&pConnect->m_CSObject);
				break;
			case SQL_HANDLE_STMT:
				LeaveCriticalSection(&pConnect->m_CSObject);
				break;
			case SQL_HANDLE_DESC:
				LeaveCriticalSection(&pConnect->m_CSObject);
				break;
		}
	}
	return rc;
}
/*
 * Synchronous object call for
 * operation 'odbcas_ASSvc_StopSrvr'
 */
extern "C" void
odbcas_ASSvc_StopSrvr(
    /* In    */ const CEE_handle_def *ph_
  , /* Out   */ struct odbcas_ASSvc_StopSrvr_exc_ *exception_
  , /* In    */ DIALOGUE_ID_def dialogueId
  , /* In    */ IDL_long srvrType
  , /* In    */ const IDL_char *srvrObjRef
  , /* In    */ IDL_long StopType
  )
{
	CEE_status retcode;
	bool sts;
	IDL_char *curptr;
	IDL_long  msg_total_len = 0;
	IDL_long  wlength,  rlength;
	IDL_char *wbuffer, *rbuffer;

	SRVR_CALL_CONTEXT *srvrCallContext = (SRVR_CALL_CONTEXT *)ph_;
	CConnect *pConnection = (CConnect *)srvrCallContext->sqlHandle;

	pConnection->m_asTCPIPSystem->odbcAPI = AS_API_STOPSRVR;
	pConnection->m_asTCPIPSystem->dialogueId = srvrCallContext->dialogueId;
	pConnection->m_asTCPIPSystem->dwTimeout = srvrCallContext->u.connectParams.loginTimeout;
//
// do marshaling of input parameters
//
	retcode = odbcas_ASSvc_StopSrvr_param_pst_(
		  pConnection->m_asTCPIPSystem
		, wbuffer
		, wlength
		, dialogueId
		, srvrType
		, srvrObjRef
		, StopType);

	if (retcode != CEE_SUCCESS)
		return;

	sts = OpenIO (pConnection->m_asTCPIPSystem,pConnection->getAsObjRef());
	if (sts == false)
		return;

	sts = DoIO (pConnection->m_asTCPIPSystem, wbuffer, wlength, rbuffer, rlength,pConnection);
	if (sts == false)
		return;

	CloseIO (pConnection->m_asTCPIPSystem);


//
// process output parameters
//

	char swap = pConnection->m_asTCPIPSystem->swap();

    msg_total_len = 0;
	curptr = rbuffer;

//
//  exception_
//

	IDL_long ExceptionLength;

//
//   exception_ ->exception_nr
//
	exception_->exception_nr = *(IDL_long*)(curptr+msg_total_len);
	msg_total_len += sizeof(exception_->exception_nr);
	LONG_swap(&exception_->exception_nr,swap);

//
//   exception_ ->exception_detail
//
	exception_->exception_detail = *(IDL_long*)(curptr+msg_total_len);
	msg_total_len += sizeof(exception_->exception_detail);
	LONG_swap(&exception_->exception_detail,swap);

    ExceptionLength = *(IDL_long*)(curptr+msg_total_len);
    msg_total_len += sizeof(ExceptionLength);
	LONG_swap(&ExceptionLength,swap);

	if(ExceptionLength > 0)
	{
	   exception_->u.ASParamError.ErrorText = (IDL_char*)(curptr+msg_total_len);
	   msg_total_len += ExceptionLength;
	}
  
	return;
}
Esempio n. 25
0
int CYCTYPTrade::P_COMMAND(const TSDLLPosInfo dPosInfo,PYCT_DATA pyct_data ,const unsigned char* infoType,  \
						   const unsigned char* ver, int encryptMethod , int endian , unsigned char* inBuf , int inLen , \
							unsigned char* outBuf, int* outLen)
{
	int sndLen = 0;
	int Len    = 0;
	int iRet   = 0;
	unsigned char headerData[256] = { 0 };					//报文头
	unsigned char bodyData[256] ={0 };						//报文体
	unsigned char sndData[512] = { 0 };						//待发送报文
	unsigned char md5_dig[16] = { 0 };

	CTools::hex_to_byte( infoType , headerData , 4);		//信息类型码
	sndLen += 2;
	CTools::hex_to_byte( ver      ,  headerData+sndLen , 4);//报文版本号
	sndLen += 2;
	headerData[4] = encryptMethod;							//报文体加密算法
	headerData[5] = endian;									//数值内容字节序
	sndLen += 2;

	CTools::hex_to_byte(pyct_data->SHID , bodyData , 16);	//握手流水号
	//memcpy(bodyData,pyct_data->SHID,8);
	Len += 8;
	char seq_NO[10] = { 0 };
	sprintf(seq_NO , "%08X" , pyct_data->yct_sequence_NO);	
	CTools::hex_to_byte( (BYTE*)seq_NO ,  bodyData+Len , 8);//报文序号
	Len += 4;
	memcpy(bodyData + Len , inBuf , inLen);					//报文信息域,传入后直接copy,使用此函数需要注意此处
	Len += inLen;

	//write result message into db

	md5_csum( bodyData , Len ,  md5_dig );
	memcpy(bodyData+Len , md5_dig , 4);

	char encrHandID[30] = { 0 };
	CDes::TripleDesEncrypt((char*)CKEY, (char*)pyct_data->SHID , encrHandID );

	int encrLen = 0;
	unsigned char* encr_packdata =  AESDecryptEx( bodyData+8 , Len - 8 , pyct_data->SKEY , 16, &encrLen );

	char len_tmp[10] = { 0 };
	sprintf( len_tmp , "%04X" , 8 + encrLen);
	CTools::hex_to_byte((unsigned char*)len_tmp  ,  headerData + sndLen , 4);
	sndLen += 2;
	memcpy(sndData , headerData , sndLen);			//报文体准备ok

	CTools::hex_to_byte((BYTE*)encrHandID ,  sndData + sndLen , 16);	//将加密过后的握手流水号转成hex
	sndLen += 8;

	memcpy(sndData + sndLen , encr_packdata , encrLen);
	sndLen += encrLen;

	//通讯羊城通服务器
	CConnect con;
	SOCKET sd;
	iRet = con.conToHost(YCT_IP , YCT_PORT , &sd);
	if (iRet != 0 )
	{
		return 1;
	}
	unsigned char rcvData[256] = { 0 };
	int  rcvLen		  = 0 ;
	iRet = ST_commuWithYCTIC3(dPosInfo, pyct_data , 0 , 0 ,sd , sndData , sndLen ,  rcvData , &rcvLen);
	if (iRet != 0)
	{
		return 1;
	}

	unsigned char header_tag[4] = { 0 };
	CTools::byte_to_hex( rcvData , header_tag , 2);
	if (strcmp((char*)header_tag , "FE04") == 0)
	{
		return 2;									//FE04报文,需要重新签到
	}
	if (rcvData[4] != 0x02)
	{
		return 1;									//暂不支持除0x02 AES-128以外的加密方式
	}

	unsigned char bodyDecrypted[256] = { 0 };		//解密后的报文体
	char tmp_shid[16+2] = { 0 };	
	int pack_len = 0;

	CTools::byte_to_hex( rcvData + 8 , (BYTE*)encrHandID , 8);		//握手流水号
	CDes::TripleDesDec((char*)CKEY , encrHandID , tmp_shid);		//解密握手流水号
	CTools::hex_to_byte((BYTE*)tmp_shid , bodyDecrypted , 16);
	pack_len += 8;

	int encr_len;
	BYTE* des_data = AESDecryptEx( rcvData + 16 , rcvLen - 16 , pyct_data->SKEY , 16 , &encr_len);
	memcpy(bodyDecrypted + pack_len , des_data , encr_len - 4);
	pack_len += encr_len - 4;

	char MAC1[20] = { 0 };
	char MAC2[20] = { 0 };
	memcpy(MAC1 , des_data + (encr_len - 4) , 4);
	md5_csum(bodyDecrypted , pack_len , (BYTE*)MAC2);
	MAC2[4] = 0;

	if (memcmp(MAC1 , MAC2 , 4) != 0 )
	{
		return 1;									//服务器返回MAC校验错误
	}

	memcpy(outBuf , rcvData , 8);					//报文头
	memcpy(outBuf + 8 , bodyDecrypted , pack_len);	//报文体不含校验码
	memcpy(outBuf + 8 + pack_len , MAC2 , 4);		//校验码
	*outLen = 8 + pack_len + 4 ;					//返回长度
	return 0;
}
Esempio n. 26
0
int main() {
	UDTUpDown _udt_;
	CConnect* connection = new CConnect();
	connection->connect_to_server();
	return 0;
}