Esempio n. 1
0
driver_return_code_t
audio_get_volume_win32ioctl (void *p_user_data, 
			     /*out*/ cdio_audio_volume_t *p_volume)
{
  const _img_private_t *p_env = p_user_data;
  DWORD dw_bytes_returned;

  bool b_success = 
    DeviceIoControl(p_env->h_device_handle, IOCTL_CDROM_GET_VOLUME,
		    NULL, 0, 
		    p_volume, (DWORD) sizeof(cdio_audio_volume_t), 
		    &dw_bytes_returned, NULL);

  if ( ! b_success ) {
    char *psz_msg = NULL;
    long int i_err = GetLastError();
    FORMAT_ERROR(i_err, psz_msg);
    if (psz_msg) 
      cdio_info("Error: %s", psz_msg);
    else 
      cdio_info("Error: %ld", i_err);
    LocalFree(psz_msg);
    return DRIVER_OP_ERROR;
  }
  return DRIVER_OP_SUCCESS;
}
Esempio n. 2
0
/*!
   Reads an audio device using the DeviceIoControl method into data
   starting from lsn.  Returns 0 if no error.
 */
driver_return_code_t
read_audio_sectors_win32ioctl (_img_private_t *p_env, void *data, lsn_t lsn, 
			       unsigned int nblocks) 
{
  DWORD dw_bytes_returned;
  RAW_READ_INFO cdrom_raw;
  
  /* Initialize CDROM_RAW_READ structure */
  cdrom_raw.DiskOffset.QuadPart = (long long) CDIO_CD_FRAMESIZE_RAW * lsn;
  cdrom_raw.SectorCount = nblocks;
  cdrom_raw.TrackMode = CDDA;
  
  if( DeviceIoControl( p_env->h_device_handle,
		       IOCTL_CDROM_RAW_READ, &cdrom_raw,
		       sizeof(RAW_READ_INFO), data,
		       CDIO_CD_FRAMESIZE_RAW * nblocks,
		       &dw_bytes_returned, NULL ) == 0 ) {
    char *psz_msg = NULL;
    long int i_err = GetLastError();
    FORMAT_ERROR(i_err, psz_msg);
    if (psz_msg) {
      cdio_info("Error reading audio-mode lsn %lu\n%s (%ld))", 
		(long unsigned int) lsn, psz_msg, i_err);
    } else {
      cdio_info("Error reading audio-mode lsn %lu\n (%ld))",
		(long unsigned int) lsn, i_err);
    }
    LocalFree(psz_msg);
    return DRIVER_OP_ERROR;
  }
  return DRIVER_OP_SUCCESS;
}
Esempio n. 3
0
/*!
  Playing starting at given MSF through analog output
  
  @param p_cdio the CD object to be acted upon.
*/
driver_return_code_t
audio_play_msf_win32ioctl (void *p_user_data, msf_t *p_start_msf, 
			   msf_t *p_end_msf)
{
  const _img_private_t *p_env = p_user_data;
  CDROM_PLAY_AUDIO_MSF play;
  DWORD dw_bytes_returned;

  play.StartingM = cdio_from_bcd8(p_start_msf->m);
  play.StartingS = cdio_from_bcd8(p_start_msf->s);
  play.StartingF = cdio_from_bcd8(p_start_msf->f);

  play.EndingM   = cdio_from_bcd8(p_end_msf->m);
  play.EndingS   = cdio_from_bcd8(p_end_msf->s);
  play.EndingF   = cdio_from_bcd8(p_end_msf->f);

  bool b_success = 
    DeviceIoControl(p_env->h_device_handle, IOCTL_CDROM_PLAY_AUDIO_MSF,
		    &play, sizeof(play), NULL, 0, &dw_bytes_returned, NULL);
  
  if ( ! b_success ) {
    char *psz_msg = NULL;
    long int i_err = GetLastError();
    FORMAT_ERROR(i_err, psz_msg);
    if (psz_msg) 
      cdio_info("Error: %s", psz_msg);
    else 
      cdio_info("Error: %ld", i_err);
    LocalFree(psz_msg);
    return DRIVER_OP_ERROR;
  }
  return DRIVER_OP_SUCCESS;
  
}
char*
FORMAT_ERROR(long signature)
{
	CError* ierror = GTransport.m_error_list.find_error(signature);
	if (ierror == NULL)
		return "";
	return FORMAT_ERROR(ierror);
}
char*
FORMAT_LAST_ERROR()
{
	CError* ierror = GTransport.m_error_list.find_last_error();
	if (ierror == NULL)
		return "";
	return FORMAT_ERROR(ierror);
}
char* FORMAT_ERROR(char* text, long signature)
{
	char static s_buffer[600];
	CError* ierror = GTransport.m_error_list.find_error(signature);
	if (ierror == NULL)
		return "";
	strcpy(s_buffer, text);
	strcat(s_buffer, " ");
	return strcat(s_buffer, FORMAT_ERROR(ierror));
}
Esempio n. 7
0
/*!
  Read Audio Subchannel information
  
  @param p_cdio the CD object to be acted upon.
  
*/
driver_return_code_t
audio_read_subchannel_win32ioctl (void *p_user_data, 
				  cdio_subchannel_t *p_subchannel)
{
  const _img_private_t *p_env = p_user_data;
  DWORD dw_bytes_returned;
  CDROM_SUB_Q_DATA_FORMAT q_data_format;
  SUB_Q_CHANNEL_DATA q_subchannel_data;
  
  q_data_format.Format = CDIO_SUBCHANNEL_CURRENT_POSITION;
  q_data_format.Track=0; /* Not sure if this has to be set or if so what
			    it should be. */
  
  if( ! DeviceIoControl( p_env->h_device_handle,
		       IOCTL_CDROM_READ_Q_CHANNEL,
		       &q_data_format, sizeof(q_data_format), 
		       &q_subchannel_data, sizeof(q_subchannel_data),
		       &dw_bytes_returned, NULL ) ) {
    char *psz_msg = NULL;
    long int i_err = GetLastError();
    FORMAT_ERROR(i_err, psz_msg);
    if (psz_msg) 
      cdio_info("Error: %s", psz_msg);
    else 
      cdio_info("Error: %ld", i_err);
    LocalFree(psz_msg);
    return DRIVER_OP_ERROR;
  }
  p_subchannel->audio_status = 
    q_subchannel_data.CurrentPosition.Header.AudioStatus;
  p_subchannel->track = 
    q_subchannel_data.CurrentPosition.TrackNumber;
  p_subchannel->index = 
    q_subchannel_data.CurrentPosition.IndexNumber;
  p_subchannel->index = 
    q_subchannel_data.CurrentPosition.IndexNumber;
  p_subchannel->address = q_subchannel_data.CurrentPosition.ADR;
  p_subchannel->control = q_subchannel_data.CurrentPosition.Control;

  { 
    const UCHAR *abs_addr = 
      q_subchannel_data.CurrentPosition.AbsoluteAddress;
    const UCHAR *rel_addr = 
      q_subchannel_data.CurrentPosition.TrackRelativeAddress;

    p_subchannel->abs_addr.m = cdio_to_bcd8(abs_addr[1]);
    p_subchannel->abs_addr.s = cdio_to_bcd8(abs_addr[2]);
    p_subchannel->abs_addr.f = cdio_to_bcd8(abs_addr[3]);
    p_subchannel->rel_addr.m = cdio_to_bcd8(rel_addr[1]);
    p_subchannel->rel_addr.s = cdio_to_bcd8(rel_addr[2]);
    p_subchannel->rel_addr.f = cdio_to_bcd8(rel_addr[3]);
  }

  return DRIVER_OP_SUCCESS;
}
Esempio n. 8
0
/*!
  Close the tray of a CD-ROM
  
  @param p_user_data the CD object to be acted upon.
  
*/
driver_return_code_t 
close_tray_win32ioctl (const char *psz_win32_drive)
{
#ifdef WIN32
  DWORD dw_bytes_returned;
  DWORD dw_access_flags;
  
  OSVERSIONINFO ov;
  HANDLE h_device_handle;
  bool b_success;
  
  memset(&ov,0,sizeof(OSVERSIONINFO));
  ov.dwOSVersionInfoSize=sizeof(OSVERSIONINFO);
  GetVersionEx(&ov);
  
  if((ov.dwPlatformId==VER_PLATFORM_WIN32_NT) &&        
     (ov.dwMajorVersion>4))
    dw_access_flags = GENERIC_READ|GENERIC_WRITE;  /* add gen write on W2k/XP */
  else dw_access_flags = GENERIC_READ;

  h_device_handle = CreateFile( psz_win32_drive, 
				dw_access_flags,
				FILE_SHARE_READ | FILE_SHARE_WRITE, 
				NULL, 
				OPEN_EXISTING,
				FILE_ATTRIBUTE_NORMAL, 
				NULL );

  if( h_device_handle == INVALID_HANDLE_VALUE ) {
    return DRIVER_OP_ERROR;
  }

  b_success = 
    DeviceIoControl(h_device_handle, IOCTL_STORAGE_LOAD_MEDIA2,
		    NULL, (DWORD) 0, NULL, 0, &dw_bytes_returned, NULL);
  

  CloseHandle(h_device_handle);
  
  if ( ! b_success ) {
    char *psz_msg = NULL;
    long int i_err = GetLastError();
    FORMAT_ERROR(i_err, psz_msg);
    if (psz_msg) 
      cdio_info("Error: %s", psz_msg);
    else 
      cdio_info("Error: %ld", i_err);
    LocalFree(psz_msg);
    return DRIVER_OP_ERROR;
  }
  return DRIVER_OP_SUCCESS;
#else 
  return DRIVER_OP_UNSUPPORTED;
#endif
}
Esempio n. 9
0
/*!
  Run a SCSI MMC command. 
 
  env	        private CD structure 
  i_timeout     time in milliseconds we will wait for the command
                to complete. If this value is -1, use the default 
		time-out value.
  p_buf	        Buffer for data, both sending and receiving
  i_buf	        Size of buffer
  e_direction	direction the transfer is to go.
  cdb	        CDB bytes. All values that are needed should be set on 
                input. We'll figure out what the right CDB length should be.

  Return 0 if command completed successfully.
 */
int
run_mmc_cmd_win32ioctl( void *p_user_data, 
			unsigned int i_timeout_ms,
			unsigned int i_cdb, const mmc_cdb_t * p_cdb,
			cdio_mmc_direction_t e_direction, 
			unsigned int i_buf, /*in/out*/ void *p_buf )
{
  const _img_private_t *p_env = p_user_data;
  SCSI_PASS_THROUGH_DIRECT sptd;
  bool b_success;
  DWORD dw_bytes_returned;
  
  sptd.Length  = sizeof(sptd);
  sptd.PathId  = 0;      /* SCSI card ID will be filled in automatically */
  sptd.TargetId= 0;      /* SCSI target ID will also be filled in */
  sptd.Lun=0;            /* SCSI lun ID will also be filled in */
  sptd.CdbLength         = i_cdb;
  sptd.SenseInfoLength   = 0; /* Don't return any sense data */
  sptd.DataIn            = SCSI_MMC_DATA_READ == e_direction ? 
    SCSI_IOCTL_DATA_IN : SCSI_IOCTL_DATA_OUT; 
  sptd.DataTransferLength= i_buf; 
  sptd.TimeOutValue      = msecs2secs(i_timeout_ms);
  sptd.DataBuffer        = (void *) p_buf;
  sptd.SenseInfoOffset   = 0;

  memcpy(sptd.Cdb, p_cdb, i_cdb);

  /* Send the command to drive */
  b_success = DeviceIoControl(p_env->h_device_handle,
			      IOCTL_SCSI_PASS_THROUGH_DIRECT,               
			      (void *)&sptd, 
			      (DWORD)sizeof(SCSI_PASS_THROUGH_DIRECT),
			      NULL, 0,                        
			      &dw_bytes_returned,
			      NULL);

  if ( !b_success ) {
    char *psz_msg = NULL;
    long int i_err = GetLastError();
    FORMAT_ERROR(i_err, psz_msg);
    if (psz_msg) 
      cdio_info("Error: %s", psz_msg);
    else 
      cdio_info("Error: %ld", i_err);
    LocalFree(psz_msg);
    return DRIVER_OP_ERROR;
  }
  return DRIVER_OP_SUCCESS;
}
Esempio n. 10
0
/*!
  Stop playing an audio CD.
  
  @param p_user_data the CD object to be acted upon.
  
*/
driver_return_code_t 
audio_stop_win32ioctl (void *p_user_data)
{
  const _img_private_t *p_env = p_user_data;
  DWORD dw_bytes_returned;
  
  bool b_success = 
    DeviceIoControl(p_env->h_device_handle, IOCTL_CDROM_STOP_AUDIO,
		    NULL, (DWORD) 0, NULL, 0, &dw_bytes_returned, NULL);

  if ( ! b_success ) {
    char *psz_msg = NULL;
    long int i_err = GetLastError();
    FORMAT_ERROR(i_err, psz_msg);
    if (psz_msg) 
      cdio_info("Error: %s", psz_msg);
    else 
      cdio_info("Error: %ld", i_err);
    LocalFree(psz_msg);
    return DRIVER_OP_ERROR;
  }
  return DRIVER_OP_SUCCESS;
}
Esempio n. 11
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. 12
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()
Esempio n. 13
0
bool DoIO (CTCPIPUnixDrvr* pTCPIPSystem, IDL_char* wbuffer, IDL_long write_count, IDL_char*& rbuffer, IDL_long& read_count,CConnect *pConnection, CStmt *pStatement)
{
	bool bok = true;

// write count, read count and temporary count
	long wcount;
	long rcount = 0;
	int tcount = 0;

	char* buffer;
	rbuffer = NULL;
// should the header specify swap
#ifdef BIGE
	HEADER wheader = {0,0,0,0,'N',COMP_12,WRITE_REQUEST_FIRST,SIGNATURE,CLIENT_HEADER_VERSION_BE,PC,TCPIP,SWAP_NO,0,0};
	HEADER rheader = {0,0,0,0,'N',COMP_12,READ_RESPONSE_FIRST,SIGNATURE,CLIENT_HEADER_VERSION_BE,PC,TCPIP,SWAP_NO,0,0};
#else
	HEADER wheader = {0,0,0,0,'N',COMP_12,WRITE_REQUEST_FIRST,SIGNATURE,CLIENT_HEADER_VERSION_LE,PC,TCPIP,SWAP_YES,0,0};
	HEADER rheader = {0,0,0,0,'N',COMP_12,READ_RESPONSE_FIRST,SIGNATURE,CLIENT_HEADER_VERSION_LE,PC,TCPIP,SWAP_YES,0,0};
#endif
	HEADER* prheader,*pwheader;

	if(pTCPIPSystem->odbcAPI == AS_API_GETOBJREF)
	{
		;
	}
	else
	{
		if(pTCPIPSystem->swap() == SWAP_YES)
		{
			wheader.swap = SWAP_YES;
			rheader.swap = SWAP_YES;
		}
		else
		{
			wheader.swap = SWAP_NO;
			rheader.swap = SWAP_NO;
		}
	}

	wheader.operation_id	= pTCPIPSystem->odbcAPI;
	rheader.operation_id	= pTCPIPSystem->odbcAPI;
	wheader.dialogueId		= pTCPIPSystem->dialogueId;
	rheader.dialogueId		= pTCPIPSystem->dialogueId;
	unsigned int timeout	= pTCPIPSystem->dwTimeout;
	memset(&pTCPIPSystem->m_rheader, 0, sizeof(HEADER));

	RESET_ERRORS((long)pTCPIPSystem);

	if (pTCPIPSystem->m_IOCompression > 0 &&
	    pTCPIPSystem->m_IOCompression == 1)
	{
		wheader.compress_ind = COMP_YES;
		//wheader.compress_type = COMP_14; // this should be set in the ::Compress method, based on what compression type the application chooses (right now there is only one COMP_14
		rheader.compress_ind = COMP_YES;
		rheader.compress_type = COMP_14;  // the driver requests that the server use this compression type. this should also be set based on what compression type the application chooses
	}
	else
	{
		wheader.compress_ind = COMP_NO;
		wheader.compress_type = 0;
		rheader.compress_ind = COMP_NO;
		rheader.compress_type = 0;
	}

// send to the server

	wheader.total_length = write_count;
	wheader.hdr_type = WRITE_REQUEST_FIRST;
		wheader.compress_type = 0;

#ifdef TRACE_COMPRESSION
	if(gDrvrGlobal.gTraceCompression)
	{
		printf("sending bytes number: %d\n",write_count);
	}
#endif
	wcount = write_count;

	while (wcount > 0)
	{
		if (wheader.hdr_type == WRITE_REQUEST_FIRST)
		{
			if (wcount > MAX_TCP_BUFFER_LENGTH - sizeof(HEADER))
				tcount = MAX_TCP_BUFFER_LENGTH - sizeof(HEADER);
			else
				tcount = wcount;
		}
		else
		{
			if (wcount > MAX_TCP_BUFFER_LENGTH)
				tcount = MAX_TCP_BUFFER_LENGTH;
			else
				tcount = wcount;
		}

		pwheader = &wheader;
		bok = (gDrvrGlobal.fpTCPIPDoWriteRead)((void*)pTCPIPSystem, pwheader, wbuffer, tcount, timeout);
		if (bok == false)
			goto out;
		wheader.hdr_type = WRITE_REQUEST_NEXT;
		wcount  -= tcount;
		wbuffer += tcount;
	}
// receive from the server

	pTCPIPSystem->cleanup(); //release all temp memory

// read for READ_RESPONSE_FIRST

	tcount = 0;
	rbuffer = NULL;
	rheader.hdr_type = READ_RESPONSE_FIRST;

	prheader = &rheader;
	bok = (gDrvrGlobal.fpTCPIPDoWriteRead)((void*)pTCPIPSystem, prheader, rbuffer, tcount, timeout);

	if(bok == false && pConnection != NULL)
	{
		if(MAP_SRVR_ERRORS(pConnection) == TIMEOUT_EXCEPTION)
		{
			if( pTCPIPSystem->odbcAPI != AS_API_GETOBJREF &&
				pTCPIPSystem->odbcAPI != AS_API_STOPSRVR &&
				pTCPIPSystem->odbcAPI != SRVR_API_SQLCONNECT &&
				pTCPIPSystem->odbcAPI != SRVR_API_SQLDISCONNECT)
			{
			    	odbcas_ASSvc_StopSrvr_exc_ stopSrvrException;
				stopSrvrException.exception_nr=SQL_ERROR;
				if(pStatement != NULL)
				   pStatement->setDiagRec(DRIVER_ERROR, IDS_S1_T00, TIMEOUT_EXCEPTION, FORMAT_ERROR((long)pStatement->getSrvrTCPIPSystem()));
				pConnection->sendStopServer(&stopSrvrException);
				bok = (gDrvrGlobal.fpTCPIPDoWriteRead)((void*)pTCPIPSystem, prheader, rbuffer, tcount, timeout);
			}
		}
	}

	if (bok == false)
		goto out;
		
	if(pTCPIPSystem->odbcAPI == AS_API_GETOBJREF)
	{
		if(prheader->version == SERVER_HEADER_VERSION_LE)
			// we're connected to a Seaquest system
			#if defined(BIGE)
			pTCPIPSystem->setSwap(SWAP_YES);
			#else
			pTCPIPSystem->setSwap(SWAP_NO);
			#endif
		else if(prheader->version == SERVER_HEADER_VERSION_BE)
			// we're connected to a older system
			#if defined(BIGE)
			pTCPIPSystem->setSwap(SWAP_NO);
			#else
			pTCPIPSystem->setSwap(SWAP_YES);
			#endif
		else
Esempio n. 14
0
/*! 
  Read and cache the CD's Track Table of Contents and track info.
  Return true if successful or false if an error.
*/
bool
read_toc_win32ioctl (_img_private_t *p_env) 
{
  CDROM_TOC    cdrom_toc;
  DWORD        dw_bytes_returned;
  unsigned int i, j;
  bool         b_fulltoc_first;  /* Do we do fulltoc or DeviceIoControl 
				    first? */
  if ( ! p_env ) return false;

  /* 
     The MMC5 spec says:
       For media other than CD, information may be fabricated in order
                                            ^^^ ^^
       to emulate a CD structure for the specific media.

     There is no requirement though that it *has* to and some DVD
     drives like one by Thompson for XBOX don't support a
     IOCTL_CDROM_READ_TOC for DVD's. So if we have a DVD we should not
     prefer getting the TOC via MMC.

     But on the other hand in GNU/Linux it is reported that using the
     TOC via MMC gives better information such as for CD DATA Form 2 (used
     in SVCDs). So if we *don't* have a DVD I think we want to try MMC
     first. 

     Is this complicated enough? I could be wrong...

   */
  b_fulltoc_first = (CDIO_DISC_MODE_NO_INFO == dvd_discmode_win32ioctl(p_env));

  if ( b_fulltoc_first && read_fulltoc_win32mmc(p_env) ) return true;

  /* SCSI-MMC READ_TOC (FULTOC) read failed or we don't want to try it
     initiaily.  Try reading TOC via DeviceIoControl... */

  if( DeviceIoControl( p_env->h_device_handle,
		       IOCTL_CDROM_READ_TOC,
		       NULL, 0, &cdrom_toc, sizeof(CDROM_TOC),
		       &dw_bytes_returned, NULL ) == 0 ) {
    char *psz_msg = NULL;
    long int i_err = GetLastError();
    cdio_log_level_t loglevel = b_fulltoc_first 
      ? CDIO_LOG_WARN : CDIO_LOG_DEBUG;

    FORMAT_ERROR(i_err, psz_msg);
    if (psz_msg) {
      cdio_log(loglevel, "could not read TOC (%ld): %s", i_err, psz_msg);
      LocalFree(psz_msg);
    } else 
      cdio_log(loglevel, "could not read TOC (%ld)", i_err);

    if ( !b_fulltoc_first && read_fulltoc_win32mmc(p_env) ) return true;
    return false;
  }
  
  p_env->gen.i_first_track = cdrom_toc.FirstTrack;
  p_env->gen.i_tracks  = cdrom_toc.LastTrack - cdrom_toc.FirstTrack + 1;

  j = p_env->gen.i_first_track;
  for( i = 0 ; i <= p_env->gen.i_tracks ; i++, j++ ) {
    p_env->tocent[ i ].start_lsn = 
      cdio_lba_to_lsn(
		      cdio_msf3_to_lba( cdrom_toc.TrackData[i].Address[1],
					cdrom_toc.TrackData[i].Address[2],
					cdrom_toc.TrackData[i].Address[3] )
		      );
    p_env->tocent[i].Control   = cdrom_toc.TrackData[i].Control;
    p_env->tocent[i].Format    = cdrom_toc.TrackData[i].Adr;

    p_env->gen.track_flags[j].preemphasis = 
      p_env->tocent[i].Control & 0x1 
      ? CDIO_TRACK_FLAG_TRUE : CDIO_TRACK_FLAG_FALSE;

    p_env->gen.track_flags[j].copy_permit = 
      p_env->tocent[i].Control & 0x2 
      ? CDIO_TRACK_FLAG_TRUE : CDIO_TRACK_FLAG_FALSE;
    
    p_env->gen.track_flags[j].channels = 
      p_env->tocent[i].Control & 0x8 ? 4 : 2;
    

    cdio_debug("p_sectors: %i, %lu", i, 
	       (unsigned long int) (p_env->tocent[i].start_lsn));
  }
  p_env->gen.toc_init = true;
  return true;
}
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 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()
bool DoIO (CTCPIPSystemDrvr* pTCPIPSystem, char* wbuffer, long write_count, char*& rbuffer, long& read_count, CConnect *pConnection, CStmt *pStatement)
{
	bool bok = true;

// write count, read count and temporary count
	long wcount;
	long rcount = 0;
	long tcount = 0;

	char* buffer;
	rbuffer = NULL;
//
	HEADER wheader = {0,0,0,0,'N',COMP_12,WRITE_REQUEST_FIRST,SIGNATURE,CLIENT_HEADER_VERSION_LE,PC,TCPIP,SWAP_YES,0,0};
	HEADER rheader = {0,0,0,0,'N',COMP_12,READ_RESPONSE_FIRST,SIGNATURE,CLIENT_HEADER_VERSION_LE,PC,TCPIP,SWAP_YES,0,0};
	HEADER* prheader,*pwheader;

	if(pTCPIPSystem->odbcAPI == AS_API_GETOBJREF)
	{
		// For GetObjRef, the header is always sent in BigEndian form since when establishing a new connection
		// we won't know the system type
		;
	}
	else
	{
		if(pTCPIPSystem->swap() == SWAP_NO)
		{
			// We're connected from a Little Endian Client to a Little Endian Server
			wheader.swap = SWAP_NO;
			rheader.swap = SWAP_NO;
		}
		else
		{
			// We're connected from a Little Endian Client to a Big Endian Server
			;
		}
	}

	wheader.operation_id	= pTCPIPSystem->odbcAPI;
	rheader.operation_id	= pTCPIPSystem->odbcAPI;
	wheader.dialogueId		= pTCPIPSystem->dialogueId;
	rheader.dialogueId		= pTCPIPSystem->dialogueId;
	unsigned int timeout	= pTCPIPSystem->dwTimeout;
	memset(&pTCPIPSystem->m_rheader, 0, sizeof(HEADER));

	RESET_ERRORS((long)pTCPIPSystem);

	if (pTCPIPSystem->m_IOCompression > 0 &&
	    pTCPIPSystem->m_IOCompression == 1)
	{
		wheader.compress_ind = COMP_YES;
		//wheader.compress_type = COMP_14; // this should be set in the ::Compress method, based on what compression type the application chooses (right now there is only one COMP_14
		rheader.compress_ind = COMP_YES;
		rheader.compress_type = COMP_14;  // the driver requests that the server use this compression type. this should also be set based on what compression type the application chooses
	}
	else
	{
		wheader.compress_ind = COMP_NO;
		wheader.compress_type = 0;
		rheader.compress_ind = COMP_NO;
		rheader.compress_type = 0;
	}

// send to the server

	wheader.total_length = write_count;
	wheader.hdr_type = WRITE_REQUEST_FIRST;
		wheader.compress_type = 0;
#if (defined(WIN32)||defined(_WIN64))&&defined(TRACE_COMPRESSION)
	if(gDrvrGlobal.gTraceCompression)
	{
		printf("sending bytes number: %d\n",write_count);
	}
#endif
	wcount = write_count;

	while (wcount > 0)
	{
		if (wheader.hdr_type == WRITE_REQUEST_FIRST)
		{
			if (wcount > MAX_TCP_BUFFER_LENGTH - sizeof(HEADER))
				tcount = MAX_TCP_BUFFER_LENGTH - sizeof(HEADER);
			else
				tcount = wcount;
		}
		else
		{
			if (wcount > MAX_TCP_BUFFER_LENGTH)
				tcount = MAX_TCP_BUFFER_LENGTH;
			else
				tcount = wcount;
		}

		pwheader = &wheader;
		TRACE_TRANSPORT_OUT(wheader.hdr_type, pTCPIPSystem->m_object_ref, pwheader, wbuffer, tcount, timeout);
		bok = (gDrvrGlobal.fpTCPIPDoWriteRead)((void*)pTCPIPSystem, pwheader, wbuffer, tcount, timeout);
		if (bok == false)
			goto out;
		wheader.hdr_type = WRITE_REQUEST_NEXT;
		wcount  -= tcount;
		wbuffer += tcount;
	}
// receive from the server

	pTCPIPSystem->cleanup(); //release all temp memory

// read for READ_RESPONSE_FIRST

	tcount = 0;
	rbuffer = NULL;
	rheader.hdr_type = READ_RESPONSE_FIRST;

	prheader = &rheader;
	bok = (gDrvrGlobal.fpTCPIPDoWriteRead)((void*)pTCPIPSystem, prheader, rbuffer, tcount, timeout);

	if(bok == false)
	{
		if(MAP_SRVR_ERRORS(pConnection) == TIMEOUT_EXCEPTION)
		{
			if( pTCPIPSystem->odbcAPI != AS_API_GETOBJREF &&
				pTCPIPSystem->odbcAPI != AS_API_STOPSRVR &&
				pTCPIPSystem->odbcAPI != SRVR_API_SQLCONNECT &&
				pTCPIPSystem->odbcAPI != SRVR_API_SQLDISCONNECT)
			{
				if(pStatement != NULL)
					pStatement->setDiagRec(DRIVER_ERROR, IDS_S1_T00, TIMEOUT_EXCEPTION, FORMAT_ERROR((long)pStatement->getSrvrTCPIPSystem()));
				pConnection->sendStopServer();
				bok = (gDrvrGlobal.fpTCPIPDoWriteRead)((void*)pTCPIPSystem, prheader, rbuffer, tcount, timeout);
			}
		}
	}

	if (bok == false)
		goto out;

	TRACE_TRANSPORT_IN(READ_RESPONSE_FIRST, pTCPIPSystem->m_object_ref, prheader, rbuffer, tcount, timeout);

	if(pTCPIPSystem->odbcAPI == AS_API_GETOBJREF)
	{
		if(prheader->version == SERVER_HEADER_VERSION_LE)
			pTCPIPSystem->setSwap(SWAP_NO);
		else if(prheader->version == SERVER_HEADER_VERSION_BE)
			pTCPIPSystem->setSwap(SWAP_YES);
		else
			// we're connected to an older system (which will just echo back the version we send)
			pTCPIPSystem->setSwap(SWAP_YES);
	}



// the server returns total length in the header

	memcpy(&pTCPIPSystem->m_rheader, prheader, sizeof(HEADER));
	if (prheader->compress_ind == COMP_YES && prheader->compress_type != 0)
	{
		SET_ERROR((long)pTCPIPSystem, PC, TCPIP, pTCPIPSystem->odbcAPI, E_DRIVER, pTCPIPSystem->m_object_ref, O_DO_WRITE_READ, F_DO_IO, DRVR_ERR_COMPRESS_OPERATION, rcount);
		bok = false;
		goto out;
	}
	else
		rcount = prheader->total_length;

	read_count = rcount;

	buffer = (char*)pTCPIPSystem->r_allocate(rcount);
	if (buffer == NULL)
	{
		SET_ERROR((long)pTCPIPSystem, PC, TCPIP, pTCPIPSystem->odbcAPI, E_DRIVER, pTCPIPSystem->m_object_ref, O_DO_OPERATOR_NEW, F_DO_IO, DRVR_ERR_MEMORY_ALLOCATE, rcount);
		bok = false;
		goto out;
	}

// if there is something beside the header in the IO buffer

	if (tcount > 0)
	{
		memcpy(buffer, rbuffer, tcount);
		rcount -= tcount;
	}

	rbuffer = buffer+ tcount;

// read for READ_RESPONSE_NEXT

	while (rcount > 0){
// we send only a header
		tcount = 0;
		rheader.hdr_type = READ_RESPONSE_NEXT;
		prheader = &rheader;
		bok = (gDrvrGlobal.fpTCPIPDoWriteRead)((void*)pTCPIPSystem, prheader, rbuffer, tcount, timeout);
		if (bok == false)
			goto out;
		TRACE_TRANSPORT_IN(READ_RESPONSE_NEXT, pTCPIPSystem->m_object_ref, prheader, rbuffer, tcount, timeout);
		rcount  -= tcount;
		rbuffer += tcount;
	}

	rbuffer = buffer;
#if (defined(WIN32)||defined(_WIN64))&&defined(TRACE_COMPRESSION)
	if(gDrvrGlobal.gTraceCompression)
	{
		printf("receiving bytes number: %d\n",read_count);
	}
#endif
out:
	return bok;
}