static PGPError sImportProc( PFLFileSpecRef ref, PGPByte const * data, PGPSize dataSize ) { const ExportedFileSpec * exportedData; MyData * newData = NULL; PGPError err = kPGPError_NoErr; (void) dataSize; exportedData = (const ExportedFileSpec *)data; newData = GetMyData( ref ); err = PGPReallocData( ref->memoryMgr, &newData, sizeof( *newData ), 0 ); if ( IsntPGPError( err ) ) { MyData * myData = (MyData *)newData; ref->data = (PGPByte *)newData; ref->dataSize = sizeof( *newData ); myData->specIsValid = FALSE; CopyPString( exportedData->name, myData->spec.name ); if( exportedData->aliasDataSize != 0 ) { AliasHandle alias; if( PtrToHand( &exportedData->aliasData[0], (Handle *) &alias, exportedData->aliasDataSize ) == noErr ) { FSSpec spec; short aliasCount = 1; Boolean needsUpdate; if( MatchAlias( NULL, kARMNoUI | kARMSearch, alias, &aliasCount, &spec, &needsUpdate, NULL, NULL ) == noErr ) { CInfoPBRec cpb; if( FSpGetCatInfo( &spec, &cpb ) == noErr ) { myData->specIsValid = TRUE; myData->spec.vRefNum = spec.vRefNum; myData->spec.parID = cpb.dirInfo.ioDrDirID; } } DisposeHandle( (Handle) alias ); } } } return( err ); }
static PGPError GetSpec( PFLConstFileSpecRef ref, FSSpec *fileSpec, CInfoPBRec *fileInfo) { MyData *myData; PGPError err = kPGPError_NoErr; PGPValidateParam( ref->type == kPFLFileSpecMacType ); myData = GetMyData( ref ); if( myData->specIsValid ) { *fileSpec = myData->spec; if( fileInfo != NULL ) { OSStatus macErr; macErr = FSpGetCatInfo( fileSpec, fileInfo ); if ( macErr == fnfErr ) { err = kPGPError_FileNotFound; } else if( macErr != noErr ) { err = kPGPError_FileOpFailed; } } } else { err = kPGPError_FileNotFound; } return( err ); }
static OSStatus RunOneServer(InetHost ipAddr) // This routine is the main line of the thread that runs // an HTTP server. ipAddr is the address on which the // server is listening. // // The routine uses a directory whose name is the // dotted decimal string representation of ipAddr as the // root directory of the HTTP server. { OSStatus err; OSStatus junk; Str255 ipAddrString; FSSpec dirSpec; CInfoPBRec cpb; ServerContext *context; MPTaskID junkServerThread; // Allocate a context for the preemptive thread. err = noErr; context = (ServerContext *) MPAllocateAligned(sizeof(*context), kMPAllocateDefaultAligned, kNilOptions); if (context == NULL) { err = memFullErr; } // Fill out the context. We do this here because it needs // to use services that aren't MP-safe. if (err == noErr) { context->ipAddr = ipAddr; // Get ipAddr as a dotted decimal Pascal string. OTInetHostToString(ipAddr, ((char *) ipAddrString) + 1); ipAddrString[0] = OTStrLength(((char *) ipAddrString) + 1); // Find the associated dirID, creating the directory // if necessary. junk = MoreProcGetCurrentProcessFSSpec(&dirSpec); assert(junk == noErr); (void) FSMakeFSSpec(dirSpec.vRefNum, dirSpec.parID, ipAddrString, &dirSpec); context->rootVRefNum = dirSpec.vRefNum; err = FSpGetCatInfo(&dirSpec, 0, &cpb); if (err == noErr && ( (cpb.hFileInfo.ioFlAttrib & (1 << 4)) != 0) ) { context->rootDirID = cpb.hFileInfo.ioDirID; } else { err = FSpDirCreate(&dirSpec, 0, (SInt32 *) &context->rootDirID); } } // Start a preemptive thread to run an HTTP server on the IP address. if (err == noErr) { err = MPCreateTask(HTTPServerProc, context, 65536, kInvalidID, NULL, NULL, kNilOptions, &junkServerThread); if (err == noErr) { context = NULL; // it's now the task's responsibility } } if (context != NULL) { MPFree(context); } return err; }