// // TAPAPP.C // // TAP // File Transfer Data Sharing // Application Code // Revision 1.10 // // 12/28/94 First created // 4/24/95 Structures aligned with DWORDS // Dynamic extension lists added // Fixed EMERGENCY_CLOSE to use bitwise NOT (~) // #define INCL_DOSERRORS #define INCL_WINSHELLDATA #define INCL_DOS #include #include #include #include #include #include "tapapp.h" // // PTAPAPPENTRY BuildTapAppEntry_TAP(char *szDescription, // char *szProgram, // char *szParams, // PSZ pszExtension[], // ULONG ulNumExtensions); // // This function allocates and builds a TAPAPPENTRY // that should be used to register a TAP application with // the TAP servers. // // Parameters // szDescription // Description, up to 255 characters, of the application. // szProgram // Fully qualified path to the TAP executable. // szParams // Parameters to pass to the TAP program (max: 83 characters) // pszExtension // A pointer to an array of pointers to strings, each // string containing an file extension this application // supports. // ulNumExtensions // Number of extensions the application can handle. // If this is zero, pszExtension may be NULL. // // Returns // A pointer to a TAPAPPENTRY. // // WARNING: The CALLER (that's you) is responsible for // freeing this structure after using it. // This can be done by calling the standard // C function free. // PTAPAPPENTRY BuildTapAppEntry_TAP(char *szDescription, char *szProgram, char *szParams, PSZ pszExtension[], ULONG ulNumExtensions) { PTAPAPPENTRY pTapAppEntry; PEXTENSIONLIST pExtList; ULONG i, ulSize; // Compute the size of the TAPAPPENTRY structure with // the extension list appended for (i = 0, ulSize = sizeof(TAPAPPENTRY); i < ulNumExtensions; i++) ulSize += sizeof(((PEXTENSIONLIST)NULL)->cb) + sizeof(((PEXTENSIONLIST)NULL)->szExtension) + strlen(pszExtension[i]); // Allocate a TAPAPPENTRY structure pTapAppEntry = (PTAPAPPENTRY) malloc (ulSize); // Fill in the TAPAPPENTRY structure pTapAppEntry->cb = ulSize; strcpy(pTapAppEntry -> szDescription, szDescription); strcpy(pTapAppEntry -> szProgram, szProgram); strcpy(pTapAppEntry -> szParams, szParams); pTapAppEntry->ulExtensions = ulNumExtensions; // Set pExtList to point to the memory location immediately // following the TAPAPPENTRY structure pExtList = (PEXTENSIONLIST) ((PBYTE)pTapAppEntry + sizeof(TAPAPPENTRY)); // Fill the memory after TAPPAPPENTRY with variable size EXTENSIONLISTs for (i = 0; i < ulNumExtensions; i++) { pExtList -> cb = sizeof(((PEXTENSIONLIST)NULL)->cb) + sizeof(((PEXTENSIONLIST)NULL)->szExtension) + strlen(pszExtension[i]); strcpy(pExtList->szExtension, pszExtension[i]); // Go to the next EXTENSIONLIST structure pExtList = (PEXTENSIONLIST) ((PBYTE)pExtList + pExtList -> cb); } // Warning, the caller must free this up. return pTapAppEntry; } // // int RegisterApplication_TAP(char *szAppName, // PTAPAPPENTRY pTapAppEntry); // // Registers a TAP Application so that TAP Servers can // find it. This need only be done once. // // Parameters: // szAppName // Name of the TAP Application // pTapAppEntry // A pointer to a structure containing // information about this TAP application. // See TAP.H for the members of this // structure. The TAP application is // responsible for filling this out // completely and correctly. // // Returns: TRUE on success // int RegisterApplication_TAP(char *szAppName, PTAPAPPENTRY pTapAppEntry) { int iRet = TRUE; // Write application data to the INI file iRet = (INT)PrfWriteProfileData(HINI_SYSTEMPROFILE, TAP_INI_APPNAME, szAppName, (PVOID) pTapAppEntry, pTapAppEntry -> cb); return iRet; } // // int DeRegisterApplication_TAP(char *szAppName); // // Deregisters a TAP Application so that it is unavailable // to TAP Servers. // // Parameters: // szAppName // Name of the TAP Application // // Returns: TRUE on success // int DeRegisterApplication_TAP(char *szAppName) { int iRet = TRUE; // Remove application from the INI file iRet = (INT)PrfWriteProfileData(HINI_SYSTEMPROFILE, TAP_INI_APPNAME, szAppName, NULL, 0); return iRet; } // // int OpenFile_TAP(PTAPAPPINFO pTapAppInfo, PHFILE phFile); // // Opens the current file being transferred for // shared reading. // // Parameters: // pTapAppInfo // Pointer to the TAP application's instance data. // phFile // Pointer to an OS/2 file handle. (output) // // Returns: TRUE on success // int OpenFile_TAP(PTAPAPPINFO pTapAppInfo, PHFILE phFile) { APIRET rc; ULONG ActionTaken; int iRet = TRUE; // Request exclusive access DosRequestMutexSem(pTapAppInfo -> hAppMutex, (ULONG)SEM_INDEFINITE_WAIT); // // Open an already existing file for read only access // // As a child process we really already have an // inherited file handle but we're ignoring this fact // rc = DosOpen(pTapAppInfo -> tiCurrent . szFileName, &(pTapAppInfo -> hUserFile), &ActionTaken, 0, FILE_NORMAL, OPEN_ACTION_FAIL_IF_NEW | OPEN_ACTION_OPEN_IF_EXISTS, OPEN_SHARE_DENYNONE | OPEN_ACCESS_READONLY, NULL); if (rc) iRet = FALSE; else // Success, return file handle *phFile = pTapAppInfo -> hUserFile; // Release exclusive access DosReleaseMutexSem(pTapAppInfo -> hAppMutex); return iRet; } // // int CloseFile_TAP(PTAPAPPINFO pTapAppInfo, HFILE hFile) // // Closes a the current file opened with OpenFile_TAP. // // Parameters: // pTapAppInfo // Pointer to the TAP application's instance data. // hFile // OS/2 handle to the file to be closed. // // Returns: TRUE on success // int CloseFile_TAP(PTAPAPPINFO pTapAppInfo, HFILE hFile) { int iRet = TRUE; APIRET rc; // Request exclusive access DosRequestMutexSem(pTapAppInfo -> hAppMutex, (ULONG)SEM_INDEFINITE_WAIT); // Close file rc = DosClose(hFile); if (rc) iRet = FALSE; // Release exclusive access DosReleaseMutexSem(pTapAppInfo -> hAppMutex); return iRet; } // // PTAPAPPINFO InitializeApplication_TAP(int argc, char **argv); // // Initializes the TAP subsystem. This function must be called // as one of the first functions called in the TAP application. // // Parameters: // argc & argv - Standard command line parameters passed // to main on startup // // Returns: A pointer to the TAP instance data on success, // otherwise NULL. A NULL return value most likely means this // program was NOT started from a TAP server as required. // PTAPAPPINFO InitializeApplication_TAP(int argc, char **argv) { PTAPAPPINFO pTapAppInfo = NULL; int cnter; char szPipeName[CCHMAXPATH]; HFILE PipeHandle; ULONG ActionTaken; APIRET rc; // Parse pipe name from the command line for(cnter=0; cnter