FdoRdbmsSQLDataReader::FdoRdbmsSQLDataReader( FdoIConnection *connection, GdbiQueryResult   *query ):
mQueryResult( query ),
mFdoConnection( NULL ),
mConnection( NULL ),
mHasMoreRows( false ),
mColCount( 0 ),
mColList( NULL ),
mWkbBuffer(NULL),
mWkbBufferLen(0),
mWkbGeomLen(0),
mSprops(NULL),
mGeomIdx(-1),
mUppNameBuffer(NULL),
mUppNameBufferLen(0)
{

    mFdoConnection = dynamic_cast<FdoRdbmsConnection*>(connection);
    if( mFdoConnection )
    {
        mFdoConnection->AddRef();
        mConnection = mFdoConnection->GetDbiConnection();
    }

    mColCount = mQueryResult->GetColumnCount();
    if( mColCount == 0 )
        return;

    mColList = new GdbiColumnDesc[mColCount];

    for ( int i=0; i<mColCount; i++ )
    {
        GdbiColumnDesc* pCol = &mColList[i];
        if( !mQueryResult->GetColumnDesc( i+1, *pCol ) )
            pCol->column[0] = L'\0';
        
        if (*pCol->column == L'\0')
            wcsncpy(pCol->column, L"GENERATEDPROPERTY", 18);

        if (mColMap.find(pCol->column) != mColMap.end())
            GenerateUniqueName(pCol->column, pCol->column);
        mColMap[pCol->column] = std::make_pair(pCol, i);
    }
    mSprops = new StringRec[mColCount];
}
Exemplo n.º 2
0
int JackEngine::ClientCheck(const char* name, int uuid, char* name_res, int protocol, int options, int* status)
{
    // Clear status
    *status = 0;
    strcpy(name_res, name);

    jack_log("Check protocol client = %ld server = %ld", protocol, JACK_PROTOCOL_VERSION);

    if (protocol != JACK_PROTOCOL_VERSION) {
        *status |= (JackFailure | JackVersionError);
        jack_error("JACK protocol mismatch (%d vs %d)", protocol, JACK_PROTOCOL_VERSION);
        return -1;
    }

    std::map<int,std::string>::iterator res = fReservationMap.find(uuid);

    if (res != fReservationMap.end()) {
        strncpy(name_res, res->second.c_str(), JACK_CLIENT_NAME_SIZE);
    } else if (ClientCheckName(name)) {

        *status |= JackNameNotUnique;

        if (options & JackUseExactName) {
            jack_error("cannot create new client; %s already exists", name);
            *status |= JackFailure;
            return -1;
        }

        if (GenerateUniqueName(name_res)) {
            *status |= JackFailure;
            return -1;
        }
    }

    return 0;
}
Exemplo n.º 3
0
static OSErr		
MoveRename(
    const FSSpec *srcFileSpecPtr,   /* Source object. */
    const FSSpec *dstDirSpecPtr,    /* Destination directory. */
    StringPtr copyName)		    /* New name for object in destination 
    				     * directory. */
{
    OSErr err;
    long srcID, dstID;
    Boolean srcIsDir, dstIsDir;
    Str31 tmpName;
    FSSpec dstFileSpec, srcDirSpec, tmpSrcFileSpec, tmpDstFileSpec;
    Boolean locked;
    
    if (srcFileSpecPtr->parID == 1) {
        /*
         * Trying to rename a volume.
         */
          
        return badMovErr;
    }
    if (srcFileSpecPtr->vRefNum != dstDirSpecPtr->vRefNum) {
	/*
	 * Renaming across volumes.
	 */
	 
        return diffVolErr;
    }
    err = FSpGetFLockCompat(srcFileSpecPtr, &locked);
    if (locked) {
        FSpRstFLockCompat(srcFileSpecPtr);
    }
    if (err == noErr) {
	err = FSpGetDirectoryID(dstDirSpecPtr, &dstID, &dstIsDir);
    }
    if (err == noErr) {
        if (srcFileSpecPtr->parID == dstID) {
            /*
             * Renaming object within directory. 
             */
            
            err = FSpRenameCompat(srcFileSpecPtr, copyName);
            goto done; 
        }
        if (Pstrequal(srcFileSpecPtr->name, copyName)) {
	    /*
	     * Moving object to another directory (under same name). 
	     */
	 
	    err = FSpCatMoveCompat(srcFileSpecPtr, dstDirSpecPtr);
	    goto done; 
        } 
        err = FSpGetDirectoryID(srcFileSpecPtr, &srcID, &srcIsDir);
    } 
    if (err == noErr) {
        /*
         * Fullblown: rename source object to temp name, move temp to
         * dest directory, and rename temp to target.
         */
          
        err = GenerateUniqueName(srcFileSpecPtr->vRefNum, 
       		srcFileSpecPtr->parID, dstID, tmpName);
        FSMakeFSSpecCompat(srcFileSpecPtr->vRefNum, srcFileSpecPtr->parID,
         	tmpName, &tmpSrcFileSpec);
        FSMakeFSSpecCompat(dstDirSpecPtr->vRefNum, dstID, tmpName,
         	&tmpDstFileSpec);
    }
    if (err == noErr) {
        err = FSpRenameCompat(srcFileSpecPtr, tmpName);
    }
    if (err == noErr) {
        err = FSpCatMoveCompat(&tmpSrcFileSpec, dstDirSpecPtr);
        if (err == noErr) {
            err = FSpRenameCompat(&tmpDstFileSpec, copyName);
            if (err == noErr) {
                goto done;
            }
            FSMakeFSSpecCompat(srcFileSpecPtr->vRefNum, srcFileSpecPtr->parID,
             	    NULL, &srcDirSpec);
            FSpCatMoveCompat(&tmpDstFileSpec, &srcDirSpec);
        }                 
        FSpRenameCompat(&tmpSrcFileSpec, srcFileSpecPtr->name);
    }
    
    done:
    if (locked != false) {
    	if (err == noErr) {
	    FSMakeFSSpecCompat(dstDirSpecPtr->vRefNum, 
	    	    dstID, copyName, &dstFileSpec);
            FSpSetFLockCompat(&dstFileSpec);
        } else {
            FSpSetFLockCompat(srcFileSpecPtr);
        }
    }
    return err;
}     
Exemplo n.º 4
0
int
TclpCopyDirectory(
    char *src,			/* Pathname of directory to be copied.  */
    char *dst,			/* Pathname of target directory. */
    Tcl_DString *errorPtr)	/* If non-NULL, initialized DString for
				 * error reporting. */
{
    OSErr err, saveErr;
    long srcID, tmpDirID;
    FSSpec srcFileSpec, dstFileSpec, dstDirSpec, tmpDirSpec, tmpFileSpec;
    Boolean srcIsDirectory, srcLocked;
    Boolean dstIsDirectory, dstExists;
    Str31 tmpName;

    err = FSpLocationFromPath(strlen(src), src, &srcFileSpec);
    if (err == noErr) {
    	err = FSpGetDirectoryID(&srcFileSpec, &srcID, &srcIsDirectory);
    }
    if (err == noErr) {
        if (srcIsDirectory == false) {
            err = afpObjectTypeErr;	/* ENOTDIR. */
        }
    }
    if (err == noErr) {
        err = GetFileSpecs(dst, &dstFileSpec, &dstDirSpec, &dstExists,
        	&dstIsDirectory);
    }
    if (dstExists) {
        if (dstIsDirectory == false) {
            err = afpObjectTypeErr;	/* ENOTDIR. */
        } else {
            err = dupFNErr;		/* EEXIST. */
        }
    }
    if (err != noErr) {
        goto done;
    }        
    if ((srcFileSpec.vRefNum == dstFileSpec.vRefNum) &&
    	    (srcFileSpec.parID == dstFileSpec.parID) &&
            (Pstrequal(srcFileSpec.name, dstFileSpec.name) != 0)) {
        /*
         * Copying on top of self.  No-op.
         */
                    
        goto done;
    }

    /*
     * This algorthm will work making a copy of the source directory in
     * the current directory with a new name, in a new directory with the
     * same name, and in a new directory with a new name:
     *
     * 1. Make dstDir/tmpDir.
     * 2. Copy srcDir/src to dstDir/tmpDir/src
     * 3. Rename dstDir/tmpDir/src to dstDir/tmpDir/dst (if necessary).
     * 4. CatMove dstDir/tmpDir/dst to dstDir/dst.
     * 5. Remove dstDir/tmpDir.
     */
                
    err = FSpGetFLockCompat(&srcFileSpec, &srcLocked);
    if (srcLocked) {
        FSpRstFLockCompat(&srcFileSpec);
    }
    if (err == noErr) {
        err = GenerateUniqueName(dstFileSpec.vRefNum, dstFileSpec.parID, 
    	        dstFileSpec.parID, tmpName);
    }
    if (err == noErr) {
        FSMakeFSSpecCompat(dstFileSpec.vRefNum, dstFileSpec.parID,
        	tmpName, &tmpDirSpec);
        err = FSpDirCreateCompat(&tmpDirSpec, smSystemScript, &tmpDirID);
    }
    if (err == noErr) {
	err = FSpDirectoryCopy(&srcFileSpec, &tmpDirSpec, NULL, 0, true,
	    	CopyErrHandler);
    }
    
    /* 
     * Even if the Copy failed, Rename/Move whatever did get copied to the
     * appropriate final destination, if possible.  
     */
     
    saveErr = err;
    err = noErr;
    if (Pstrequal(srcFileSpec.name, dstFileSpec.name) == 0) {
        err = FSMakeFSSpecCompat(tmpDirSpec.vRefNum, tmpDirID, 
        	srcFileSpec.name, &tmpFileSpec);
        if (err == noErr) {
            err = FSpRenameCompat(&tmpFileSpec, dstFileSpec.name);
        }
    }
    if (err == noErr) {
        err = FSMakeFSSpecCompat(tmpDirSpec.vRefNum, tmpDirID,
        	dstFileSpec.name, &tmpFileSpec);
    }
    if (err == noErr) {
        err = FSpCatMoveCompat(&tmpFileSpec, &dstDirSpec);
    }
    if (err == noErr) {
        if (srcLocked) {
            FSpSetFLockCompat(&dstFileSpec);
        }
    }
    
    FSpDeleteCompat(&tmpDirSpec);
    
    if (saveErr != noErr) {
        err = saveErr;
    }
    
    done:
    if (err != noErr) {
        errno = TclMacOSErrorToPosixError(err);
        if (errorPtr != NULL) {
            Tcl_DStringAppend(errorPtr, dst, -1);
        }
        return TCL_ERROR;
    }
    return TCL_OK;
}
Exemplo n.º 5
0
int 
TclpCopyFile(
    char *src,			/* Pathname of file to be copied. */
    char *dst)			/* Pathname of file to copy to. */
{
    OSErr err, dstErr;
    Boolean dstExists, dstIsDirectory, dstLocked;
    FSSpec srcFileSpec, dstFileSpec, dstDirSpec, tmpFileSpec;
    Str31 tmpName;
	
    err = FSpLocationFromPath(strlen(src), src, &srcFileSpec);
    if (err == noErr) {
        err = GetFileSpecs(dst, &dstFileSpec, &dstDirSpec, &dstExists,
        	&dstIsDirectory);
    }
    if (dstExists) {
        if (dstIsDirectory) {
            errno = EISDIR;
            return TCL_ERROR;
        }
        err = FSpGetFLockCompat(&dstFileSpec, &dstLocked);
        if (dstLocked) {
            FSpRstFLockCompat(&dstFileSpec);
        }
        
        /*
         * Backup dest file.
         */
         
        dstErr = GenerateUniqueName(dstFileSpec.vRefNum, dstFileSpec.parID, 
    	        dstFileSpec.parID, tmpName);
        if (dstErr == noErr) {
            dstErr = FSpRenameCompat(&dstFileSpec, tmpName);
        }   
    }
    if (err == noErr) {
    	err = FSpFileCopy(&srcFileSpec, &dstDirSpec, 
    		(StringPtr) dstFileSpec.name, NULL, 0, true);
    }
    if ((dstExists != false) && (dstErr == noErr)) {
        FSMakeFSSpecCompat(dstFileSpec.vRefNum, dstFileSpec.parID,
        	tmpName, &tmpFileSpec);
	if (err == noErr) {
	    /* 
	     * Delete backup file. 
	     */
	     
	    FSpDeleteCompat(&tmpFileSpec);
	} else {
	
	    /* 
	     * Restore backup file.
	     */
	     
	    FSpDeleteCompat(&dstFileSpec);
	    FSpRenameCompat(&tmpFileSpec, dstFileSpec.name);
	    if (dstLocked) {
	        FSpSetFLockCompat(&dstFileSpec);
	    }
	}
    }
    
    if (err != noErr) {
	errno = TclMacOSErrorToPosixError(err);
	return TCL_ERROR;
    }
    return TCL_OK;
}
Exemplo n.º 6
0
int
TclpRenameFile( 
    char *src,    		/* Pathname of file or dir to be renamed. */
    char *dst)     		/* New pathname for file or directory. */
{
    FSSpec srcFileSpec, dstFileSpec, dstDirSpec;
    OSErr err; 
    long srcID, dummy;
    Boolean srcIsDirectory, dstIsDirectory, dstExists, dstLocked;

    err = FSpLocationFromPath(strlen(src), src, &srcFileSpec);
    if (err == noErr) {
	FSpGetDirectoryID(&srcFileSpec, &srcID, &srcIsDirectory);
    }
    if (err == noErr) {
        err = GetFileSpecs(dst, &dstFileSpec, &dstDirSpec, &dstExists, 
        	&dstIsDirectory);
    }
    if (err == noErr) {
	if (dstExists == 0) {
            err = MoveRename(&srcFileSpec, &dstDirSpec, dstFileSpec.name);
            goto end;
        }
        err = FSpGetFLockCompat(&dstFileSpec, &dstLocked);
        if (dstLocked) {
            FSpRstFLockCompat(&dstFileSpec);
        }
    }
    if (err == noErr) {
        if (srcIsDirectory) {
	    if (dstIsDirectory) {
		/*
		 * The following call will remove an empty directory.  If it
		 * fails, it's because it wasn't empty.
		 */
		 
                if (TclpRemoveDirectory(dst, 0, NULL) != TCL_OK) {
                    return TCL_ERROR;
                }
                
                /*
		 * Now that that empty directory is gone, we can try
		 * renaming src.  If that fails, we'll put this empty
		 * directory back, for completeness.
		 */

		err = MoveRename(&srcFileSpec, &dstDirSpec, dstFileSpec.name);
                if (err != noErr) {
		    FSpDirCreateCompat(&dstFileSpec, smSystemScript, &dummy);
		    if (dstLocked) {
		        FSpSetFLockCompat(&dstFileSpec);
		    }
		}
	    } else {
	        errno = ENOTDIR;
	        return TCL_ERROR;
	    }
	} else {   
	    if (dstIsDirectory) {
		errno = EISDIR;
		return TCL_ERROR;
	    } else {                                
		/*
		 * Overwrite existing file by:
		 * 
		 * 1. Rename existing file to temp name.
		 * 2. Rename old file to new name.
		 * 3. If success, delete temp file.  If failure,
		 *    put temp file back to old name.
		 */

	        Str31 tmpName;
	        FSSpec tmpFileSpec;

	        err = GenerateUniqueName(dstFileSpec.vRefNum, 
	        	dstFileSpec.parID, dstFileSpec.parID, tmpName);
	        if (err == noErr) {
	            err = FSpRenameCompat(&dstFileSpec, tmpName);
	        }
	        if (err == noErr) {
	            err = FSMakeFSSpecCompat(dstFileSpec.vRefNum,
	            	    dstFileSpec.parID, tmpName, &tmpFileSpec);
	        }
	        if (err == noErr) {
	            err = MoveRename(&srcFileSpec, &dstDirSpec, 
	            	    dstFileSpec.name);
	        }
	        if (err == noErr) {
		    FSpDeleteCompat(&tmpFileSpec);
		} else {
		    FSpDeleteCompat(&dstFileSpec);
		    FSpRenameCompat(&tmpFileSpec, dstFileSpec.name);
	            if (dstLocked) {
	            	FSpSetFLockCompat(&dstFileSpec);
	            }
	        }
	    }
   	}
    }    

    end:    
    if (err != noErr) {
	errno = TclMacOSErrorToPosixError(err);
	return TCL_ERROR;
    }
    return TCL_OK;
}
Exemplo n.º 7
0
pascal	OSErr	FSpExchangeFilesCompat(const FSSpec *source,
                                       const FSSpec *dest)
{
#if !__MACOSSEVENFIVEORLATER
    if (
#if !__MACOSSEVENORLATER
        !FSHasFSSpecCalls() ||
#endif	/* !__MACOSSEVENORLATER */
        !HasFSpExchangeFilesCompatibilityFix() )
    {
        HParamBlockRec			pb;
        CInfoPBRec				catInfoSource, catInfoDest;
        OSErr					result, result2;
        Str31					unique1, unique2;
        StringPtr				unique1Ptr, unique2Ptr, swapola;
        GetVolParmsInfoBuffer	volInfo;
        long					theSeed, temp;

        /* Make sure the source and destination are on the same volume */
        if ( source->vRefNum != dest->vRefNum )
        {
            result = diffVolErr;
            goto errorExit3;
        }

        /* Try PBExchangeFiles first since it preserves the file ID reference */
        pb.fidParam.ioNamePtr = (StringPtr) &(source->name);
        pb.fidParam.ioVRefNum = source->vRefNum;
        pb.fidParam.ioDestNamePtr = (StringPtr) &(dest->name);
        pb.fidParam.ioDestDirID = dest->parID;
        pb.fidParam.ioSrcDirID = source->parID;

        result = PBExchangeFilesSync(&pb);

        /* Note: The compatibility case won't work for files with *Btree control blocks. */
        /* Right now the only *Btree files are created by the system. */
        if ( result != noErr )
        {
            pb.ioParam.ioNamePtr = NULL;
            pb.ioParam.ioBuffer = (Ptr) &volInfo;
            pb.ioParam.ioReqCount = sizeof(volInfo);
            result2 = PBHGetVolParmsSync(&pb);

            /* continue if volume has no fileID support (or no GetVolParms support) */
            if ( (result2 == noErr) && hasFileIDs(volInfo) )
            {
                goto errorExit3;
            }

            /* Get the catalog information for each file */
            /* and make sure both files are *really* files */
            catInfoSource.hFileInfo.ioVRefNum = source->vRefNum;
            catInfoSource.hFileInfo.ioFDirIndex = 0;
            catInfoSource.hFileInfo.ioNamePtr = (StringPtr) &(source->name);
            catInfoSource.hFileInfo.ioDirID = source->parID;
            catInfoSource.hFileInfo.ioACUser = 0; /* ioACUser used to be filler2 */
            result = PBGetCatInfoSync(&catInfoSource);
            if ( result != noErr )
            {
                goto errorExit3;
            }
            if ( (catInfoSource.hFileInfo.ioFlAttrib & kioFlAttribDirMask) != 0 )
            {
                result = notAFileErr;
                goto errorExit3;
            }

            catInfoDest.hFileInfo.ioVRefNum = dest->vRefNum;
            catInfoDest.hFileInfo.ioFDirIndex = 0;
            catInfoDest.hFileInfo.ioNamePtr = (StringPtr) &(dest->name);
            catInfoDest.hFileInfo.ioDirID = dest->parID;
            catInfoDest.hFileInfo.ioACUser = 0; /* ioACUser used to be filler2 */
            result = PBGetCatInfoSync(&catInfoDest);
            if ( result != noErr )
            {
                goto errorExit3;
            }
            if ( (catInfoDest.hFileInfo.ioFlAttrib & kioFlAttribDirMask) != 0 )
            {
                result = notAFileErr;
                goto errorExit3;
            }

            /* generate 2 filenames that are unique in both directories */
            theSeed = 0x64666A6C;	/* a fine unlikely filename */
            unique1Ptr = (StringPtr)&unique1;
            unique2Ptr = (StringPtr)&unique2;

            result = GenerateUniqueName(source->vRefNum, &theSeed, source->parID, dest->parID, unique1Ptr);
            if ( result != noErr )
            {
                goto errorExit3;
            }

            GenerateUniqueName(source->vRefNum, &theSeed, source->parID, dest->parID, unique2Ptr);
            if ( result != noErr )
            {
                goto errorExit3;
            }

            /* rename source to unique1 */
            pb.fileParam.ioNamePtr = (StringPtr) &(source->name);
            pb.ioParam.ioMisc = (Ptr) unique1Ptr;
            pb.ioParam.ioVersNum = 0;
            result = PBHRenameSync(&pb);
            if ( result != noErr )
            {
                goto errorExit3;
            }

            /* rename dest to unique2 */
            pb.ioParam.ioMisc = (Ptr) unique2Ptr;
            pb.ioParam.ioVersNum = 0;
            pb.fileParam.ioNamePtr = (StringPtr) &(dest->name);
            pb.fileParam.ioDirID = dest->parID;
            result = PBHRenameSync(&pb);
            if ( result != noErr )
            {
                goto errorExit2;	/* back out gracefully by renaming unique1 back to source */
            }

            /* If files are not in same directory, swap their locations */
            if ( source->parID != dest->parID )
            {
                /* move source file to dest directory */
                pb.copyParam.ioNamePtr = unique1Ptr;
                pb.copyParam.ioNewName = NULL;
                pb.copyParam.ioNewDirID = dest->parID;
                pb.copyParam.ioDirID = source->parID;
                result = PBCatMoveSync((CMovePBPtr) &pb);
                if ( result != noErr )
                {
                    goto errorExit1;	/* back out gracefully by renaming both files to original names */
                }

                /* move dest file to source directory */
                pb.copyParam.ioNamePtr = unique2Ptr;
                pb.copyParam.ioNewDirID = source->parID;
                pb.copyParam.ioDirID = dest->parID;
                result = PBCatMoveSync((CMovePBPtr) &pb);
                if ( result != noErr)
                {
                    /* life is very bad.  We'll at least try to move source back */
                    pb.copyParam.ioNamePtr = unique1Ptr;
                    pb.copyParam.ioNewName = NULL;
                    pb.copyParam.ioNewDirID = source->parID;
                    pb.copyParam.ioDirID = dest->parID;
                    (void) PBCatMoveSync((CMovePBPtr) &pb);	/* ignore errors */
                    goto errorExit1;	/* back out gracefully by renaming both files to original names */
                }
            }

            /* Make unique1Ptr point to file in source->parID */
            /* and unique2Ptr point to file in dest->parID */
            /* This lets us fall through to the rename code below */
            swapola = unique1Ptr;
            unique1Ptr = unique2Ptr;
            unique2Ptr = swapola;

            /* At this point, the files are in their new locations (if they were moved) */
            /* Source is named Unique1 (name pointed to by unique2Ptr) and is in dest->parID */
            /* Dest is named Unique2 (name pointed to by unique1Ptr) and is in source->parID */
            /* Need to swap attributes except mod date and swap names */

            /* swap the catalog info by re-aiming the CInfoPB's */
            catInfoSource.hFileInfo.ioNamePtr = unique1Ptr;
            catInfoDest.hFileInfo.ioNamePtr = unique2Ptr;

            catInfoSource.hFileInfo.ioDirID = source->parID;
            catInfoDest.hFileInfo.ioDirID = dest->parID;

            /* Swap the original mod dates with each file */
            temp = catInfoSource.hFileInfo.ioFlMdDat;
            catInfoSource.hFileInfo.ioFlMdDat = catInfoDest.hFileInfo.ioFlMdDat;
            catInfoDest.hFileInfo.ioFlMdDat = temp;

            /* Here's the swap (ignore errors) */
            (void) PBSetCatInfoSync(&catInfoSource);
            (void) PBSetCatInfoSync(&catInfoDest);

            /* rename unique2 back to dest */
errorExit1:
            pb.ioParam.ioMisc = (Ptr) &(dest->name);
            pb.ioParam.ioVersNum = 0;
            pb.fileParam.ioNamePtr = unique2Ptr;
            pb.fileParam.ioDirID = dest->parID;
            (void) PBHRenameSync(&pb);	/* ignore errors */

            /* rename unique1 back to source */
errorExit2:
            pb.ioParam.ioMisc = (Ptr) &(source->name);
            pb.ioParam.ioVersNum = 0;
            pb.fileParam.ioNamePtr = unique1Ptr;
            pb.fileParam.ioDirID = source->parID;
            (void) PBHRenameSync(&pb); /* ignore errors */
        }
errorExit3: {
            /* null statement */
        }
        return ( result );
    }
    else
#endif	/* !__MACOSSEVENFIVEORLATER */
    {
        return ( FSpExchangeFiles(source, dest) );
    }
}