home *** CD-ROM | disk | FTP | other *** search
- /****************************************************************************
- **
- ** Copyright (c) 1982-1997 Pervasive Software Inc. All Rights Reserved.
- **
- ****************************************************************************/
- /****************************************************************************
- FIXPARMS.C
- This module contains fixparms() and unfixparms() to handle the SRB.
-
- ****************************************************************************/
- #include <stdlib.h>
- #include <string.h>
- #include <sqlapi.h>
- #include <sqlconst.h>
- #include <btitypes.h>
- #include <fixparms.h>
- #include <wxqlords.h>
- #include <malloc.h>
- #include <mem.h>
-
- /*
- ** Defines
- */
-
- #define MAX_FCN_PARMS 12 /* max. value in FcnParmCount[] */
- #define LOW_WORD 0xffff
- #define EOF_ERR 9
- #undef NEAR
- #define NEAR
- #undef FAR
- #define FAR
-
- /*
- ** Prototypes
- */
-
- extern BTI_SINT cnvToSeq(
- BTI_ULONG sig,
- BTI_SINT fcnin,
- BTI_SINT *fcnout );
-
- BTI_SINT GetMaxDataSize(
- PARMBLOCK *pb,
- char ***from,
- BTI_SINT fcn,
- BTI_SINT indx,
- BTI_ULONG *dataLen,
- BTI_ULONG *itemCount,
- BTI_ULONG *saveitemCount,
- BTI_SINT *updallParmCount );
-
- BTI_SINT GetSendDataSize(
- PARMBLOCK *pb,
- char ***from,
- BTI_SINT fcn,
- BTI_SINT indx,
- BTI_WORD *dataLen,
- BTI_WORD *itemCount,
- BTI_WORD *saveitemCount,
- BTI_SINT *updallParmCount );
-
- BTI_SINT GetRecvDataSize(
- PARMBLOCK *pb,
- BTI_SINT fcn,
- BTI_SINT indx,
- BTI_WORD *dataLen );
-
- BTI_SINT SetPtrData(
- char ***from,
- char ***to,
- char *dataBuf,
- char **dataBufCrwl,
- BTI_WORD len,
- BTI_SINT indx );
-
- BTI_SINT SetConstData(
- BTI_SINT **from,
- BTI_SINT **to,
- BTI_SINT indx,
- BTI_WORD *dataLen,
- BTI_WORD *itemCount );
-
- BTI_SINT SetLongData(
- BTI_ULONG **from,
- BTI_ULONG **to,
- BTI_SINT indx,
- BTI_ULONG *dataLen,
- BTI_ULONG *itemCount );
-
- BTI_SINT MovPtrData(
- PARMBLOCK *pb,
- char ***from,
- char ***to,
- char *dataBuf,
- BTI_SINT fcn,
- BTI_SINT indx,
- BTI_WORD *dataLen );
-
- BTI_SINT MovConstData(
- BTI_SINT **from,
- BTI_SINT **to,
- BTI_SINT indx,
- BTI_WORD *dataLen );
-
- BTI_SINT MovLongData(
- BTI_ULONG **from,
- BTI_ULONG **to,
- BTI_SINT indx,
- BTI_ULONG *dataLen );
-
- BTI_SINT SendData(
- BTI_SINT indx );
-
- BTI_SINT RetData(
- BTI_SINT indx );
-
- BTI_SINT PtrParm(
- BTI_SINT indx );
-
- BTI_SINT StrParm(
- BTI_SINT indx );
-
- BTI_SINT DataParm(
- BTI_SINT indx );
-
- BTI_SINT ConstParm(
- BTI_SINT indx );
-
- BTI_SINT LongParm(
- BTI_SINT indx );
-
- BTI_SINT LenParm(
- BTI_SINT indx );
-
- BTI_SINT CntParm(
- BTI_SINT indx );
-
- BTI_SINT SpecParm(
- BTI_SINT indx );
-
-
- extern BTI_ULONG startOfRealPtr;
-
- /*
- *****************************************************************************
- ** GetDBufPtr
- **
- ** Prototype:
- **
- ** char *GetDBufPtr(BTI_WORD fcn, PARMBLOCK *pb)
- **
- ** Description:
- **
- ** Returns a pointer to the variable portion of the parameter block.
- **
- ** Preconditions:
- **
- ** None.
- **
- ** Parameters:
- **
- ** fcn: SSQL function number.
- ** <input>
- **
- ** *pb: Pointer to the parameter block.
- ** <input>
- **
- **
- ** Return value:
- **
- ** Pointer to variable portion of the parameter block.
- **
- ** Globals:
- **
- ** None.
- **
- ** Called Functions:
- **
- ** FcnVariableLen[]
- **
- ** Comments:
- **
- ** None.
- **
- **
- *****************************************************************************
- */
- char *GetDBufPtr( BTI_WORD fcn, PARMBLOCK *pb )
- {
- BTI_CHAR_PTR dataBuf;
- BTI_CHAR_PTR unionData;
- BTI_SINT varLen;
-
- varLen = FcnVariableLen[ fcn ];
- unionData = ((BTI_CHAR_PTR) pb) + (PARM_FIXED_LEN);
- dataBuf = unionData + varLen + 2;
-
- return( dataBuf );
-
- } /* end GetDBufPtr */
-
-
-
- /*
- *****************************************************************************
- **
- ** Prototype:
- **
- ** BTI_SINT fixParms(
- ** PARMBLOCK *from,
- ** PARMBLOCK *to)
- **
- ** Description:
- **
- ** This function copies/converts data from "hard to address"
- ** parameter block to "easily addressable" parameter block.
- **
- ** Converts 32-bit pointers in the parameter block to real-mode
- ** pointers. Data is copied to a contiguous block of memory.
- ** The real-mode pointers point to the copied data in the contiguous
- ** block.
- **
- ** Preconditions:
- **
- ** None.
- **
- ** Parameters:
- **
- ** *from: Pointer to the input parameter that contains
- ** <input> 32-bit addresses
- **
- ** *to: Pointer to contiguous block of memory. Pointers
- ** <output> in the parameter block are converted to 16-bit
- ** addresses.
- **
- ** Return value:
- **
- ** SS_SUCCESS
- ** SQL_MEM_M
- **
- **
- ** Globals:
- **
- ** initParmOffsets
- ** ParmOffsets[]
- ** FcnParmCount[]
- **
- ** Called Functions:
- **
- ** malloc()
- ** free()
- ** GetDBufPtr()
- ** GetMaxDataSize()
- ** PtrParm()
- ** SetPtrData()
- ** ConstParm()
- ** SetConstData()
- ** LongParm()
- ** SetLongData()
- **
- ** Comments:
- **
- ** None.
- **
- *****************************************************************************
- */
- BTI_SINT fixParms( PARMBLOCK *from, PARMBLOCK *to )
-
- {
- BTI_WORD i;
- char **tmpFromP;
- BTI_SINT fcn = (BTI_SINT) from->fcn;
- char *beginFromP, *beginTopP;
- char *dataBufCrwl = NULL;
- BTI_SINT updallParmCount;
- BTI_SINT indx;
- BTI_SINT stat = SS_SUCCESS;
- BTI_WORD totalLen, lenArray[MAX_FCN_PARMS];
- BTI_ULONG dataLen, itemCount, saveitemCount;
-
- /*
- ** initialize the ParmOffSets array
- */
- if ( initParmOffsets )
- {
- indx = 0;
- for ( i = 0; i < MAX_SSQL_FUNCTIONS; i++ )
- {
- ParmOffsets[i] = indx;
- indx += FcnParmCount[i];
- }
- initParmOffsets = FALSE;
- }
-
- /*
- ** Convert the function number into a sequenced function number that
- ** will access the information in the parameter tables correctly.
- */
- cnvToSeq( *((BTI_ULONG *) &(from->XQL_ID)), fcn, &fcn );
-
- /* copy the invariant data */
- #if defined(BTI_DOS_16B)
- _fmemcpy( to->XQL_ID, from->XQL_ID, 4 );
- #else
- memcpy( to->XQL_ID, from->XQL_ID, 4 );
- #endif
- to->fcn = fcn;
- to->cursorid = from->cursorid;
- to->stat = from->stat;
- to->sessionid = from->sessionid;
-
- if ( fcn != -1 )
- {
- /*
- ** Initialize dataBufCrwl to point to the start of the variant data
- ** in the parameter block.
- */
- dataBufCrwl = GetDBufPtr( fcn, to );
-
- /*
- ** Some functions (XQLLogout, XQLCursor, XQLFree, etc...) don't have
- ** variant data to copy. Check for that by looking at the number
- ** of parameters in the FcnParmCount array.
- */
- itemCount = 1;
- if ( FcnParmCount[fcn] )
- {
- BTI_WORD len;
-
- totalLen = 0;
- dataLen = 0;
- beginFromP = (char *) &(from->v);
-
- indx = ParmOffsets[ fcn ]; /* starting index into parmFlags */
- for ( i = 0; (i < FcnParmCount[fcn]) && (!stat); i++, indx++ )
- {
- len = GetMaxDataSize(
- from,
- (char ***) &beginFromP,
- fcn,
- indx,
- &dataLen,
- &itemCount,
- &saveitemCount,
- &updallParmCount );
-
- lenArray[i] = len;
- totalLen += len;
-
- /* for mallocing purposes, round up to nearest quad */
- len += 4 - (len % 4);
-
- } /* end for */
-
- /* end if */
-
-
- if ( stat == SS_SUCCESS )
- {
- beginFromP = (char *) &(from->v);
- beginTopP = (char *) &(to->v);
- indx = ParmOffsets[ fcn ]; /* starting index into parmFlags */
- dataLen = 0;
-
- for ( i = 0; (i < FcnParmCount[fcn]) && (!stat); i++, indx++ )
- {
- if ( PtrParm( indx ) )
- {
- stat = SetPtrData(
- (char ***) &beginFromP,
- (char ***) &beginTopP,
- (char *) to, /* Beginning of parameter block */
- (char **) &dataBufCrwl,
- lenArray[i],
- indx );
- }
- else if ( ConstParm( indx ) )
- {
- stat = SetConstData(
- (BTI_SINT **) &beginFromP,
- (BTI_SINT **) &beginTopP,
- indx,
- (BTI_WORD *) &dataLen,
- (BTI_WORD *) &itemCount );
- }
- else if ( LongParm( indx ) )
- {
- stat = SetLongData(
- (BTI_ULONG **) &beginFromP,
- (BTI_ULONG **) &beginTopP,
- indx,
- &dataLen,
- &itemCount );
- } /* end if-else */
- } /* end for */
- } /* end if */
-
- } /* end if */
- }
- return( stat );
-
- } /* end fixParms */
-
- /*
- *****************************************************************************
- ** SetPtrData
- **
- ** Prototype:
- **
- ** BTI_SINT SetPtrData( char ***from, char ***to,
- ** char *dataBuf, char **dataBufCrwl, BTI_WORD len, BTI_SINT indx )
- **
- ** Description:
- **
- ** Copy pointer data from parameter block containing 32-bit pointers
- ** into contiguous memory locations in destination parameter block.
- **
- ** Preconditions:
- **
- ** None.
- **
- ** Parameters:
- **
- ** ***from: Pointer to input parameter block containing
- ** <input/ 32-bit pointers
- ** output>
- **
- ** ***to: Pointer to output parameter block containing
- ** <input/ 16-bit pointers.
- ** output>
- **
- ** *dataBuf: Pointer to start of destination parameter block
- ** <input>
- **
- ** **dataBufCrwl: Pointer to current position in the destination
- ** <input/ parameter block.
- ** output>
- **
- ** len: Maximum length of the data to copy
- ** <input>
- **
- ** indx: Index number of the SSQL parameter.
- ** <input>
- **
- **
- ** Return value:
- **
- ** 0
- **
- ** Globals:
- **
- ** None.
- **
- ** Called Functions:
- **
- ** SendData()
- ** StrParm()
- **
- ** Comments:
- **
- ** None.
- **
- **
- *****************************************************************************
- */
- BTI_SINT SetPtrData( char ***from, char ***to,
- char *dataBuf, char **dataBufCrwl, BTI_WORD len, BTI_SINT indx )
-
- {
- char *tmpFrom;
-
- tmpFrom = **from;
-
- if ( len && ( tmpFrom != NULL ) )
- {
- if ( SendData( indx ) )
- {
- **to = *dataBufCrwl;
- #if defined(BTI_DOS_16B)
- _fmemcpy( **to, tmpFrom, len );
- #else
- memcpy( **to, tmpFrom, len );
- #endif
- if ( StrParm( indx ) )
- {
- /*
- ** note that we reserve one byte for the 0 terminator
- ** for strings in GetMaxDataSize().
- */
-
- *((**to)+len-1) = 0;
- } /* end if */
- } /* end if */
- /*
- ** Calculate the offset of the current position from the beginning
- ** of the block. Then add this value to the address of our real-mode
- ** buffer to calculate the 16-bit addresses.
- */
- **to = (char *) ((BTI_ULONG)(*dataBufCrwl - dataBuf) + startOfRealPtr);
-
- *dataBufCrwl += len;
- }
- else
- {
- **to = NULL;
- } /* end if-else */
-
- /* advance over pointers */
- (*to)++;
- (*from)++;
- return( 0 );
-
- } /* end SetPtrData */
-
-
- /*
- *****************************************************************************
- ** SetConstData
- **
- ** Prototype:
- **
- ** BTI_SINT SetConstData(BTI_SINT **from, BTI_SINT **to, BTI_SINT indx,
- ** BTI_WORD *dataLen, BTI_WORD *itemCount)
- **
- ** Description:
- **
- ** copy two-byte data from "hard to address" parameter block to
- ** "easily addressable" parameter block.
- **
- ** Preconditions:
- **
- ** None.
- **
- ** Parameters:
- **
- ** **from:
- ** <input>
- **
- ** **to:
- ** <input>
- **
- ** indx:
- ** <input>
- **
- ** *dataLen:
- ** <input>
- **
- ** *itemCount:
- ** <input>
- **
- **
- ** Return value:
- **
- ** None.
- **
- ** Globals:
- **
- ** None.
- **
- ** Called Functions:
- **
- ** None.
- **
- ** Comments:
- **
- ** Since SetConstData() is also used while calculating max sizes
- ** to/from (i.e. it needs to be called to set *dataLen or *itemCount)
- ** "to" can be NULL. This needs to be checked for.
- **
- *****************************************************************************
- */
- BTI_SINT SetConstData(BTI_SINT **from, BTI_SINT **to, BTI_SINT indx,
- BTI_WORD *dataLen, BTI_WORD *itemCount)
-
- {
- *itemCount = 1;
- if (SendData(indx))
- {
- if (LenParm(indx))
- {
- *dataLen = **from;
- }
- else if (CntParm(indx))
- {
- *itemCount = **from;
- } /* end if-else */
-
- if (to != NULL)
- {
- **to = **from;
- } /* end if */
- } /* end if */
-
- (*from)++;
-
- if (to != NULL)
- {
- (*to)++;
- } /* end if */
-
- return(0);
- }
-
- /*
- *****************************************************************************
- ** SetLongData
- **
- ** Prototype:
- **
- ** BTI_SINT SetLongData( BTI_ULONG **from, BTI_ULONG **to, BTI_SINT indx,
- ** BTI_ULONG *dataLen, BTI_ULONG *itemCount )
- **
- ** Description:
- **
- ** Copy four byte data from "hard to address" parameter block to
- ** "easily addressable" parameter block.
- **
- ** Preconditions:
- **
- ** None.
- **
- ** Parameters:
- **
- ** **from:
- ** <input>
- **
- ** **to:
- ** <input>
- **
- **
- ** Return value:
- **
- ** None.
- **
- ** Globals:
- **
- ** None.
- **
- ** Called Functions:
- **
- ** SendData()
- ** LenParm()
- ** CntParm()
- **
- ** Comments:
- **
- ** None.
- **
- *****************************************************************************
- */
- BTI_SINT SetLongData( BTI_ULONG **from, BTI_ULONG **to, BTI_SINT indx,
- BTI_ULONG *dataLen, BTI_ULONG *itemCount )
-
- {
- *itemCount = 1;
- if ( SendData( indx ) )
- {
- if ( LenParm( indx ) )
- {
- *dataLen = **from;
- }
- else if ( CntParm( indx ) )
- {
- *itemCount = **from;
- } /* end if-else */
-
- if ( to != NULL )
- {
- **to = **from;
- } /* end if */
- } /* end if */
-
- (*from)++;
-
- if (to != NULL)
- {
- (*to)++;
- } /* end if */
-
- return( 0 );
- }
-
- /*
- *****************************************************************************
- ** GetMaxDataSize
- **
- ** Prototype:
- **
- ** BTI_SINT GetMaxDataSize( PARMBLOCK *pb,
- ** char ***from, BTI_SINT fcn, BTI_SINT indx,
- ** BTI_ULONG *dataLen, BTI_ULONG *itemCount,
- ** BTI_ULONG *saveitemCount, BTI_SINT *updallParmCoun len = pb->v.tddattrData.bufsize;
- else
- len = 0;
- dontCalcLen = TRUE;
- break;
-
- case spDDDrpFcn:
- /*
- ** Set itemCount to indicate that owner name follows index name
- */
- len = parmLength[ indx ];
- *itemCount = 1;
- if ( pb->v.tdddropData.filetype & 0x100 )
- {
- *itemCount = 2;
- len += 9; er
- ** <input>
- **
- ** *dataLen: Length of the data.
- ** <output>
- **
- ** *itemCount: Number of items
- ** <output>
- **
- ** *saveitemCount: Saved item count.
- ** <output>
- **
- ** *updallParmCount: Parameter count for updall function.
- ** <output>
- **
- **
- ** Return value:
- **
- ** None.
- **
- ** Globals:
- **
- ** None.
- **
- ** Called Functions:
- **
- ** PtrParm()
- ** SendData()
- ** GetSendDataSize()
- ** RetData()
- ** GetRecvDataSize()
- ** ConstParm()
- ** SetConstData()
- ** LongParm()
- ** SetLongData()
- **
- **
- ** Comments:
- **
- ** None.
- **
- *****************************************************************************
- */
- BTI_SINT GetMaxDataSize( PARMBLOCK *pb,
- char ***from, BTI_SINT fcn, BTI_SINT indx,
- BTI_ULONG *dataLen, BTI_ULONG *itemCount, BTI_ULONG *saveitemCount,
- BTI_SINT *updallParmCount)
-
- {
- BTI_WORD len, lenSend, lenRecv;
-
- len = lenSend = lenRecv = 0;
-
- /* advance over pointer */
- if ( PtrParm( indx ) )
- {
- if ( SendData( indx ) )
- {
- lenSend = GetSendDataSize(
- pb,
- from,
- fcn,
- indx,
- (BTI_WORD *) dataLen,
- (BTI_WORD *) itemCount,
- (BTI_WORD *) saveitemCount,
- updallParmCount );
- } /* end if */
-
- if ( RetData( indx ) )
- {
- lenRecv = GetRecvDataSize( pb, fcn, indx, (BTI_WORD *)dataLen );
- } /* end if */
-
- (*from)++;
- }
- else if ( ConstParm( indx ) )
- {
- SetConstData( (BTI_SINT **) from, NULL, indx, (BTI_WORD *)dataLen,
- (BTI_WORD *)itemCount );
- }
- else if ( LongParm( indx ) )
- {
- SetLongData(
- (BTI_ULONG **) from,
- NULL,
- indx,
- dataLen,
- itemCount );
- } /* end if-else */
-
- /* take maximum */
- len = max( lenSend, lenRecv );
-
- return( len );
-
- } /* end GetMaxDataSize */
-
-
- /*
- *****************************************************************************
- ** GetSendDataSize
- **
- ** Prototype:
- **
- ** BTI_SINT GetSendDataSize(
- ** PARMBLOCK *pb,
- ** char ***from,
- ** BTI_SINT fcn,
- ** BTI_SINT indx,
- ** BTI_WORD *dataLen,
- ** BTI_WORD *itemCount,
- ** BTI_WORD *saveitemCount,
- ** BTI_SINT *updallParmCount )
- **
- ** Description:
- **
- ** Calculate the size of the current block being sent.
- **
- ** Preconditions:
- **
- ** None.
- **
- ** Parameters:
- **
- ** *pb: Pointer to input parameter block.
- ** <input>
- **
- ** ***from: Pointer to variant data in the parameter block
- ** <input>
- **
- ** fcn: SSQL function number
- ** <input>
- **
- ** indx: SSQL parameter index.
- ** <input>
- **
- ** *dataLen: Contains the length of the data
- ** <output>
- **
- ** *itemCount: Contains the number of items for a count parameter
- ** <output>
- **
- ** *saveitemCount: Saves the item count for a count parameter.
- ** <output>
- **
- ** *updallParmCount: Parameter count for updall
- ** <output>
- **
- **
- ** Return value:
- **
- ** Length of the data.
- **
- **
- ** Globals:
- **
- ** None.
- **
- ** Called Functions:
- **
- ** SpecParm()
- ** StrParm()
- **
- ** Comments:
- **
- ** None.
- **
- *****************************************************************************
- */
- BTI_SINT GetSendDataSize(
- PARMBLOCK *pb,
- char ***from,
- BTI_SINT fcn,
- BTI_SINT indx,
- BTI_WORD *dataLen,
- BTI_WORD *itemCount,
- BTI_WORD *saveitemCount,
- BTI_SINT *updallParmCount )
-
- {
- char *f, *UserP;
- int Count;
- BTI_SINT dontCalcLen = FALSE;
- BTI_SINT i, stat = SS_SUCCESS;
- BTI_SINT len; /* Will contain the number of bytes to copy for this call */
- BTI_SINT maxlen; /* maximum length for individual item */
-
-
- len = 0;
- if ( SpecParm( indx ) )
- {
- switch ( fcn )
- {
- case smCnvFcn:
- case spCnvFcn:
- len = ((pb->v.tcnvData.option & 0xFF) == 0) ?
- pb->v.tcnvData.size : pb->v.tcnvData.dsize;
- if ( len <= 0 )
- stat = SQL_INVALID_DATA_SIZE;
- else
- dontCalcLen = TRUE;
- break;
-
- case spInsertFcn:
- case spUpdateFcn:
- len = 0;
- if ( StrParm( indx ) )
- {
- f = pb->v.teditData.filelist;
-
- if ( f != NULL )
- {
- for (
- indx = len = 0;
- indx < pb->v.teditData.filecount;
- indx++ )
- {
- len += _fstrlen( f ) + sizeof(char);
- f += _fstrlen( f ) + sizeof(char);
- } /* end for */
-
- len++;
- } /* end if */
- }
- else
- { /* count * record size */
- f = pb->v.teditData.buf;
-
- if ( f != NULL )
- {
- for (
- indx = len = 0;
- indx < pb->v.teditData.editcount;
- indx++ )
- {
- BTI_SINT tmp;
-
- tmp = *(BTI_SINT *) f;
-
- len += tmp + sizeof(BTI_SINT);
- f += tmp + sizeof(BTI_SINT);
- } /* end for */
- } /* end if */
- }
- dontCalcLen = TRUE;
- break;
-
- case spDescribeFcn:
- if ( pb->v.tdescData.position == -1 )
- len = *dataLen;
- else
- len = 0;
- dontCalcLen = TRUE;
- break;
-
- case spFetchFcn:
- if ( (pb->v.tfetchData.option & 0x100) ||
- pb->v.tfetchData.option == 6 ||
- pb->v.tfetchData.option == 8 )
- len = *dataLen;
- else
- len = 0;
- dontCalcLen = TRUE;
- break;
-
- case spDDAttrFcn:
- if ( pb->v.tddattrData.fcn < 2 )
- len = pb->v.tddattrData.bufsize;
- else
- len = 0;
- dontCalcLen = TRUE;
- break;
-
- case spDDDrpFcn:
- /*
- ** Set itemCount to indicate that owner name follows index name
- */
- len = parmLength[ indx ];
- *itemCount = 1;
- if ( pb->v.tdddropData.filetype & 0x100 )
- {
- *itemCount = 2;
- len += 9; /* owner name size */
- }
- break;
-
- case spDDFileFcn:
- /*
- ** owner name may be set on input in the output buffer
- */
- len = 9; /* owner name size */
- break;
-
- case spDDCreFcn:
- case spDDModFcn:
- dontCalcLen = TRUE;
-
- if ( ((pb->v.tmodData.option & 0xFF) == 3) ||
- ((pb->v.tmodData.option & 0xFF) == 4))
- len = C20;
- else
- {
- len = parmLength[ indx ];
- len *= *itemCount;
- }
- break;
-
- case spUserFcn:
- if ( (pb->v.tuserData.fcn & 0xFF) == 4 )
- len = C30;
- else
- len = 0;
- dontCalcLen = TRUE;
- break;
-
- case spAccessFcn:
- if ( (pb->v.taccessData.fcn & 0xFF) < 2 )
- len = pb->v.taccessData.buflen;
- else
- len = 0;
- dontCalcLen = TRUE;
- break;
-
- case spStoreFcn:
- len = *dataLen; /* use length from user */
- dontCalcLen = TRUE;
- break;
-
- default:
- break;
- }
- }
- else
- {
- if ( fcn == spUpdallFcn )
- {
- /*
- ** for update field and replace field, item count is the same;
- ** loop below decrements itemCount so save it here, then restore
- ** for second time around.
- */
- (*updallParmCount)++;
- if ( *updallParmCount == 2 )
- *saveitemCount = *itemCount;
- else if ( *updallParmCount == 3 )
- *itemCount = *saveitemCount;
- }
-
- len = parmLength[ indx ]; /* get max length */
- if ( len )
- {
- if ( *itemCount && !StrParm( indx ) )
- {
- len *= *itemCount;
- dontCalcLen = TRUE;
- }
- }
- else
- {
- len = *dataLen; /* use length from user */
- if ( DataParm( indx ) )
- dontCalcLen = TRUE;
- }
- } /* end if-else */
-
- if ( len > 0 )
- {
- if ( !dontCalcLen )
- { /* we've only got an idea of the _max_ that must be copied */
-
- maxlen = len;
- len = 0;
- Count = (int) *itemCount;
-
- UserP = **from;
-
- /*
- ** don't want to copy negative data do we? Also, no sense in
- ** trying to access a NULL pointer.
- */
- if ( (Count < 0) || (UserP == NULL) )
- Count = 0;
-
- while ( Count )
- {
- /*
- ** xOrder fcn has 2 byte flags preceding
- ** each item name
- */
-
- if ( fcn == spOrderFcn )
- {
- UserP += 2;
- len += 2;
- }
-
- i = min( maxlen, _fstrlen( UserP ) );
- UserP += i;
- len += i;
- if ( (i < maxlen) || StrParm( indx ) )
- {
- /* skip over 0 terminator */
- UserP++;
- len++;
- }
-
- Count--;
-
- } /* end while */
- } /* end if */
- }
-
- return( len );
-
- } /* end GetSendDataSize */
-
-
- /*
- *****************************************************************************
- ** GetRecvDataSize
- **
- ** Prototype:
- **
- ** BTI_SINT GetRecvDataSize(
- ** PARMBLOCK *pb,
- ** BTI_SINT fcn,
- ** BTI_SINT indx,
- ** BTI_WORD *dataLen )
- **
- ** Description:
- **
- ** Calculate the size of the current block that could be returned.
- **
- ** Preconditions:
- **
- ** None.
- **
- ** Parameters:
- **
- ** *pb: Pointer to input parameter block.
- ** <input>
- **
- ** fcn: SSQL sequenced function number
- ** <input>
- **
- ** indx: SSQL parameter index
- ** <input>
- **
- ** *dataLen: Length of the data value
- ** <output>
- **
- **
- ** Return value:
- **
- ** Length of the data
- **
- ** Globals:
- **
- ** None.
- **
- ** Called Functions:
- **
- ** None.
- **
- ** Comments:
- **
- ** None.
- **
- *****************************************************************************
- */
- BTI_SINT GetRecvDataSize(
- PARMBLOCK *pb,
- BTI_SINT fcn,
- BTI_SINT indx,
- BTI_WORD *dataLen )
-
- {
- BTI_SINT len;
- BTI_SINT retlen = *dataLen;
-
-
- if ( SpecParm( indx ) )
- {
- switch ( fcn )
- {
- case smCnvFcn:
- case spCnvFcn:
- retlen = ((pb->v.tcnvData.option & 0xFF) == 0) ?
- pb->v.tcnvData.dsize : pb->v.tcnvData.size;
- *dataLen = retlen;
- break;
-
- case spInsertFcn:
- /* what data could we return for an insert? */
- *dataLen = retlen = 0;
- break;
-
- case spFetchFcn:
- if (pb->v.tfetchData.option == 6 ||
- pb->v.tfetchData.option == 8)
- retlen = 0;
- break;
-
- case spDDAttrFcn:
- if (pb->v.tddattrData.fcn == 3)
- retlen = pb->v.tddattrData.bufsize;
- else
- *dataLen = retlen = 0;
- break;
-
- case spDDFileFcn:
- *dataLen = retlen;
- break;
-
- case spUserFcn:
- if ((pb->v.tuserData.fcn & 0xFF) == 3 ||
- (pb->v.tuserData.fcn & 0xFF) >= 5)
- retlen = pb->v.tuserData.buflen;
- else
- *dataLen = retlen = 0;
- break;
-
- case spAccessFcn:
- if (pb->v.taccessData.fcn == 2)
- retlen = pb->v.taccessData.buflen;
- else
- *dataLen = retlen = 0;
- break;
-
- case smStatFcn:
- if (pb->v.xstData.option == 0)
- retlen = 8;
- else if (pb->v.xstData.option != 2)
- /* 2-8-93 rwa */
- retlen = C30;
- else
- retlen = 132;
- *dataLen = retlen;
- break;
-
- default:
- break;
- }
- }
- else
- {
- retlen = parmLength[indx]; /* get max length */
- } /* end if-else */
-
- /* use minimum of returned length vs. requested len */
- len = max( retlen, *dataLen );
-
- return( len );
-
- } /* end GetRecvDataSize */
-
- /*
- *****************************************************************************
- ** unfixParms
- **
- ** Prototype:
- **
- ** BTI_SINT unfixParms( PARMBLOCK *from, PARMBLOCK *to )
- **
- ** Description:
- ** unfixParms copies/converts data from "easily addressable" parameter
- ** block to "hard to address" parameter block.
- **
- ** Preconditions:
- **
- ** None.
- **
- ** Parameters:
- **
- ** *from: Input parameter block
- ** <input>
- **
- ** *to: Output parameter block
- ** <output>
- **
- ** Return value:
- **
- ** None.
- **
- **
- ** Globals:
- **
- ** None.
- **
- ** Called Functions:
- **
- ** PtrParm()
- ** MovPtrData()
- ** ConstParm()
- ** MovConstData()
- ** LongParm()
- ** MovLongData()
- **
- ** Comments:
- **
- ** None.
- **
- *****************************************************************************
- */
- BTI_SINT unfixParms( PARMBLOCK *from, PARMBLOCK *to)
-
- {
- void *beginFromP, *beginToP;
- BTI_SINT fcn = from->fcn;
- BTI_SINT i, j;
- BTI_ULONG dataLen = 0;
- BTI_SINT stat = SS_SUCCESS;
- BTI_SINT XQLstat;
-
- /* copy the invariant data */
- #if defined(BTI_DOS_16B)
- _fmemcpy( to->XQL_ID, from->XQL_ID, 4 );
- #else
- memcpy( to->XQL_ID, from->XQL_ID, 4 );
- #endif
- to->cursorid = from->cursorid;
- to->stat = from->stat;
- to->sessionid = from->sessionid;
-
- if ( fcn != -1 )
- {
- // dataBufCrwl = GetDBufPtr( fcn, from );
-
- /*
- ** Some functions (XQLLogout, XQLCursor, XQLFree, etc...) don't have
- ** variant data to copy. Check for that.
- */
- if ( FcnParmCount[fcn] )
- {
- XQLstat = from->stat;
- beginFromP = (void *) &(from->v);
- beginToP = (void *) &(to->v);
-
- j = ParmOffsets[fcn]; /* starting index into parmFlags */
-
- if ( ( (XQLstat == SQL_BUFFER_TOO_SHORT )
- || (XQLstat == SQL_SHORT_BUF_M )
- || (XQLstat <= 0)
- || (XQLstat == EOF_ERR)
- || (fcn == spDDFileFcn)
- || (fcn == spDDFieldFcn)
- || (fcn == spDDIndexFcn)
- || (fcn == smCompFcn)
- || (XQLstat == SQL_DBNM_END_OF_FILE) )
- && (XQLstat != SQL_DATA_MESSAGE_BUFFER_TOO_SMALL ))
- {
- for ( i = 0;
- (i < FcnParmCount[fcn]) && (stat == SS_SUCCESS);
- i++, j++ )
- {
- if ( PtrParm( j ) )
- {
- stat = MovPtrData(
- from,
- &beginFromP,
- &beginToP,
- (char *) from,
- fcn,
- j,
- (BTI_WORD *) &dataLen );
- }
- else if ( ConstParm( j ) )
- {
- stat = MovConstData(
- &beginFromP,
- &beginToP,
- j,
- (BTI_WORD *) &dataLen );
- }
- else if ( LongParm( j ) )
- {
- stat = MovLongData(
- &beginFromP,
- &beginToP,
- j,
- (BTI_ULONG *) &dataLen );
- }
- }
- }
- } /* end if */
- }
- return( stat );
-
- } /* end unfixParms */
-
-
- /*
- *****************************************************************************
- ** MovPtrData
- **
- ** Prototype:
- **
- ** BTI_SINT MovPtrData( PARMBLOCK *pb, char ***from,
- ** char ***to, char *dataBuf,
- ** BTI_SINT fcn, BTI_SINT indx, BTI_WORD *dataLen)
- **
- ** Description:
- **
- ** Copy pointer data from "easily addressable" parameter block to
- ** "hard to address" parameter block.
- **
- ** Preconditions:
- **
- ** None.
- **
- ** Parameters:
- **
- ** *pb: Pointer to input parameter block
- ** <input>
- **
- ** ***from: Pointer to the pointer data
- ** <input>
- **
- ** ***to: Output parameter block
- ** <output>
- **
- ** *dataBuf: Pointer to the start of the protected mode
- ** <input> parameter block
- **
- ** fcn: SSQL sequenced function number
- ** <input>
- **
- ** indx: SSQL parameter index
- ** <input>
- **
- ** *dataLen: Length of the data.
- ** <output>
- **
- **
- ** Return value:
- **
- ** None.
- **
- **
- ** Globals:
- **
- ** startOfRealPtr
- **
- ** Called Functions:
- **
- ** RetData()
- ** GetRecvDataSize()
- ** _fmemcpy()
- **
- ** Comments:
- **
- ** None.
- **
- **
- *****************************************************************************
- */
- BTI_SINT MovPtrData( PARMBLOCK *pb, char ***from,
- char ***to, char *dataBuf, BTI_SINT fcn, BTI_SINT indx, BTI_WORD *dataLen)
-
- {
- BTI_SINT stat = SS_SUCCESS;
- BTI_SINT len;
- char *tmpFrom, *tmpTo;
-
- /*
- ** Need to split our contiguous parameter block back to the
- ** individual pieces passed in from the user.
- */
- if ( RetData( indx ) )
- {
- /* Calculate the protected mode address of the data */
- **from = (char *) ((BTI_ULONG)(**from - startOfRealPtr) + dataBuf) ;
- tmpFrom = **from;
-
- len = GetRecvDataSize( pb, fcn, indx, dataLen );
- if ( len && (tmpFrom != NULL) )
- #if defined(BTI_DOS_16B)
- _fmemcpy( **to, tmpFrom, len );
- #else
- memcpy( **to, tmpFrom, len );
- #endif
- } /* end if RetData() */
-
- /* advance over pointers */
- (*to)++;
- (*from)++;
-
- return( stat );
-
- } /* end MovPtrData */
-
-
- /*
- *****************************************************************************
- ** MovConstData
- **
- ** Prototype:
- **
- ** BTI_SINT MovConstData(BTI_SINT **from, BTI_SINT **to, BTI_SINT indx,
- ** BTI_WORD *dataLen)
- **
- ** Description:
- **
- ** Copy two byte data from "easily addressable" Parm Block
- ** to "hard to address" Parm block.
- **
- **
- ** Preconditions:
- **
- ** None.
- **
- ** Parameters:
- **
- ** **from: Pointer to input parameter block
- ** <input>
- **
- ** **to: Pointer to output parameter block
- ** <output>
- **
- ** indx: SSQL parameter index
- ** <input>
- **
- ** *dataLen: Length of the data
- ** <output>
- **
- **
- ** Return value:
- **
- ** None.
- **
- **
- ** Globals:
- **
- ** None.
- **
- ** Called Functions:
- **
- ** RetData()
- ** LenParm()
- **
- ** Comments:
- **
- ** None.
- **
- **
- *****************************************************************************
- */
- BTI_SINT MovConstData( BTI_SINT **from, BTI_SINT **to, BTI_SINT indx,
- BTI_WORD *dataLen )
-
- {
- if ( RetData( indx ) )
- {
- if ( LenParm( indx ) )
- {
- *dataLen = **from;
- }
-
- **to = **from;
-
- }
-
- (*to)++;
- (*from)++;
- return( 0 );
- }
-
-
- /*
- *****************************************************************************
- ** MovLongData
- **
- ** Prototype:
- **
- ** BTI_SINT MovLongData( BTI_ULONG **from, BTI_ULONG **to,
- ** BTI_SINT indx, BTI_ULONG *dataLen )
- **
- ** Description:
- **
- ** Copy four byte data from "easily addressable" parameter block
- ** to "hard to address" parameter block.
- **
- ** Preconditions:
- **
- ** None.
- **
- ** Parameters:
- **
- ** **from: Pointer to long data value in input parameter block
- ** <input>
- **
- ** **to: Pointer to long data value in output parameter block
- ** <output>
- **
- **
- ** Return value:
- **
- ** None.
- **
- **
- ** Globals:
- **
- ** None.
- **
- ** Called Functions:
- **
- ** RetData()
- ** LenParm()
- **
- ** Comments:
- **
- ** None.
- **
- *****************************************************************************
- */
- BTI_SINT MovLongData( BTI_ULONG **from, BTI_ULONG **to, BTI_SINT indx,
- BTI_ULONG *dataLen )
-
- {
- if ( RetData( indx ) )
- {
- if ( LenParm( indx ) )
- {
- *dataLen = **from;
- }
-
- **to = **from;
-
- }
- (*to)++;
- (*from)++;
- return( 0 );
- }
-
-
- /*
- ** common functions
- */
-
- BTI_SINT SendData( BTI_SINT indx )
-
- {
- return( (BTI_SINT) parmFlags[indx] & SEND_DATA );
- }
-
- BTI_SINT RetData(BTI_SINT indx)
-
- {
- return((BTI_SINT) parmFlags[indx] & RET_DATA);
- }
-
- BTI_SINT PtrParm(BTI_SINT indx)
-
- {
- return(StrParm(indx) || DataParm(indx));
- }
-
- BTI_SINT StrParm(BTI_SINT indx)
-
- {
- return((BTI_SINT) parmFlags[indx] & STR_PARM);
- }
-
- BTI_SINT DataParm(BTI_SINT indx)
-
- {
- return((BTI_SINT) parmFlags[indx] & DATA_PARM);
- }
-
- BTI_SINT ConstParm(BTI_SINT indx)
-
- {
- return((BTI_SINT) parmFlags[indx] & CONST_VAL);
- }
-
- BTI_SINT LongParm(BTI_SINT indx)
-
- {
- return((BTI_SINT) parmFlags[indx] & LONG_VAL);
- }
-
- BTI_SINT LenParm(BTI_SINT indx)
-
- {
- return((BTI_SINT) parmFlags[indx] & LEN_VAL);
- }
-
- BTI_SINT CntParm(BTI_SINT indx)
-
- {
- return((BTI_SINT) parmFlags[indx] & CNT_VAL);
- }
-
- BTI_SINT SpecParm(BTI_SINT indx)
-
- {
- return((BTI_SINT) parmFlags[indx] & SPEC_PARM);
- }
-
-