filestub.c

来自「支持SSL v2/v3, TLS, PKCS #5, PKCS #7, PKCS」· C语言 代码 · 共 1,119 行 · 第 1/3 页

C
1,119
字号
	  sprintf(newName, "%s\\key.db", (const char *)theApp.m_UserDirectory);	}	break;    case xpSecModuleDB:        newName = (char *) XP_ALLOC(_MAX_PATH);	sprintf(newName, "%s\\secmod.db", (const char *)theApp.m_UserDirectory);	break;    case xpSignedAppletDB:        newName = (char *) XP_ALLOC(_MAX_PATH);	if ( name ) {	  sprintf(newName, "%s\\signed%s.db", (const char *)theApp.m_UserDirectory, name);	} else {	  sprintf(newName, "%s\\signed.db", (const char *)theApp.m_UserDirectory);	}		break;#ifndef MOZ_LITE          case xpAddrBook:#ifdef XP_WIN16	if(!name || !strlen(name) )	    newName = WH_TempName(type, NULL);#else	newName = (char *) XP_ALLOC(_MAX_PATH);	strcpy(newName, name);	/* strip off the extension */	{	char * pEnd = max(strrchr(newName, '\\'), strrchr(newName, '/'));	if(!pEnd)	    pEnd = newName;	pEnd = strchr(pEnd, '.');	if(pEnd)	    *pEnd = '\0';	}	strcat(newName, ".nab");#endif        break;    case xpAddrBookNew:	newName = (char *) XP_ALLOC(_MAX_PATH);	sprintf(newName, "%s\\%s", (const char *)theApp.m_UserDirectory, name);	break;    case xpVCardFile:	newName = (char *) XP_ALLOC(_MAX_PATH);	strcpy(newName, name);	/* strip off the extension */	{	char * pEnd = max(strrchr(newName, '\\'), strrchr(newName, '/'));	if(!pEnd)	    pEnd = newName;	pEnd = strchr(pEnd, '.');	if(pEnd)	    *pEnd = '\0';	}			strcat(newName, ".vcf");        break;    case xpLDIFFile:	newName = (char *) XP_ALLOC(_MAX_PATH);	strcpy(newName, name);	/* strip off the extension */	{	char * pEnd = max(strrchr(newName, '\\'), strrchr(newName, '/'));	if(!pEnd)	    pEnd = newName;	pEnd = strchr(pEnd, '.');	if(pEnd)	    *pEnd = '\0';	}		#ifdef XP_WIN16	strcat(newName, ".ldi");#else	strcat(newName, ".ldif");#endif        break;    case xpTemporaryNewsRC:        {            CString csHostName = g_MsgPrefs.m_csNewsDir;            csHostName += "\\news.tmp";            newName = XP_STRDUP((const char *) csHostName);        }        break;#endif /* MOZ_LITE         */    case xpPKCS12File:	newName = (char *) XP_ALLOC(_MAX_PATH);	strcpy(newName, name);	/* strip off the extension */	{	char * pEnd = max(strrchr(newName, '\\'), strrchr(newName, '/'));	if(!pEnd)	    pEnd = newName;	pEnd = strchr(pEnd, '.');	if(pEnd)	    *pEnd = '\0';	}			strcat(newName, ".p12");	break;	    case xpTemporary:        if(!name || !strlen(name) )            newName = WH_TempName(type, NULL);        break;#ifndef MOZ_LITE            case xpMailFolder:	if(!name)	    name = g_MsgPrefs.m_csMailDir;        break;    case xpMailFolderSummary:	newName = (char *) XP_ALLOC(_MAX_PATH);	strcpy(newName, name);	/* strip off the extension */	{	char * pEnd = max(strrchr(newName, '\\'), strrchr(newName, '/'));	if(!pEnd)	    pEnd = newName;#ifdef XP_WIN16	/* backend won't allow '.' in win16 folder names, but just to be safe. */	pEnd = strchr(pEnd, '.');	if(pEnd)	    *pEnd = '\0';#endif	}	strcat(newName, ".snm");	break;    case xpMailSort:        newName = (char *) XP_ALLOC(_MAX_PATH);        sprintf(newName, "%s\\rules.dat", (const char *)g_MsgPrefs.m_csMailDir);	break;    case xpMailFilterLog:	newName = (char *) XP_ALLOC(_MAX_PATH);	sprintf(newName, "%s\\mailfilt.log", (const char *)g_MsgPrefs.m_csMailDir);	break;    case xpNewsFilterLog:	newName = (char *) XP_ALLOC(_MAX_PATH);	sprintf(newName, "%s\\newsfilt.log", (const char *)g_MsgPrefs.m_csNewsDir);	break;    case xpMailPopState:        newName = (char *) XP_ALLOC(_MAX_PATH);        sprintf(newName, "%s\\popstate.dat", (const char *)g_MsgPrefs.m_csMailDir);	break;    case xpMailSubdirectory:	newName = (char *) XP_ALLOC(_MAX_PATH);	strcpy(newName, name);	/* strip off the trailing slash if any */	{	char * pEnd = max(strrchr(newName, '\\'), strrchr(newName, '/'));	if(!pEnd)	    pEnd = newName;	}	strcat(newName, ".sbd");	break;#endif /* MOZ_LITE       */    /* name of global cross-platform registry */    case xpRegistry:        /* eventually need to support arbitrary names; this is the default */        newName = (char *) XP_ALLOC(_MAX_PATH);        if ( newName != NULL ) {            GetWindowsDirectory(newName, _MAX_PATH);            int namelen = strlen(newName);            if ( newName[namelen-1] == '\\' )                namelen--;            strcpy(newName+namelen, "\\nsreg.dat");        }        break;	/* name of news group database  */#ifndef MOZ_LITE       case xpXoverCache:	newName = (char *) XP_ALLOC(_MAX_PATH);	sprintf(newName, "%s\\%s", (const char *)g_MsgPrefs.m_csNewsDir, name);	break;#endif /* MOZ_LITE */    case xpProxyConfig:        newName = (char *) XP_ALLOC(_MAX_PATH);        /*sprintf(newName, "%s\\proxy.cfg", theApp.m_pInstallDir->GetCharValue()); */	sprintf(newName, "%s\\proxy.cfg", (const char *)theApp.m_UserDirectory);	break;    /* add any cases where no modification is necessary here 	 */    /* The name is fine all by itself, no need to modify it  */    case xpFileToPost:    case xpExtCache:    case xpURL:        /* name is OK as it is */	break;#ifndef MOZ_LITE          case xpNewsHostDatabase:	newName = (char *) XP_ALLOC(_MAX_PATH);	sprintf(newName, "%s\\news.db", (const char *)g_MsgPrefs.m_csNewsDir);	break;    case xpImapRootDirectory:	newName = PR_smprintf ("%s\\ImapMail", (const char *)theApp.m_UserDirectory);	break;    case xpImapServerDirectory:	{	int len = 0;	char *tempImapServerDir = XP_STRDUP(name);	char *imapServerDir = tempImapServerDir;#ifdef XP_WIN16	if ((len = XP_STRLEN(imapServerDir)) > 8) {	    imapServerDir = imapServerDir + len - 8;	}#endif	newName = PR_smprintf ("%s\\ImapMail\\%s", (const char *)theApp.m_UserDirectory, imapServerDir);	if (tempImapServerDir) XP_FREE(tempImapServerDir);	}	break;    case xpJSMailFilters:	newName = PR_smprintf("%s\\filters.js", (const char *)g_MsgPrefs.m_csMailDir);	break;#endif /* MOZ_LITE */    case xpFolderCache:	newName = PR_smprintf ("%s\\summary.dat", (const char *)theApp.m_UserDirectory);	break;    case xpCryptoPolicy:	newName = (char *) XP_ALLOC(_MAX_PATH);	FE_GetProgramDirectory(newName, _MAX_PATH);	strcat(newName, "moz40p3");	break;#endif /* CMD_STUB */    default:	ASSERT(0);  /* all types should be covered */        break;    }#ifndef MOZ_LITE        /* make sure we have the correct newsrc file registered for next time */	if((type == xpSNewsRC || type == xpNewsRC) && bNeedToRegister)        NET_RegisterNewsrcFile(newName, (char *)name, (type == xpSNewsRC), FALSE );#endif    /* determine what file we are supposed to load and make sure it looks */    /*   like a DOS pathname and not some unix-like name */    if(newName) {	*myName = XP_NetToDosFileName((const char*)newName);	XP_FREE(newName);     } else {	*myName = XP_NetToDosFileName((const char*)name);    }    if (tempName) XP_FREE(tempName);    if (prefStr) XP_FREE(prefStr);            /* whee, we're done */    return(*myName);}/* *//* Open a file with the given name *//* If a special file type is provided we might need to get the name *//*  out of the preferences list *//* */PUBLIC XP_File XP_FileOpen(const char * name, XP_FileType type, const XP_FilePerm perm){    XP_File fp;    char *filename = WH_FileName(name, type);    if(!filename)	return(NULL);		#ifdef DEBUG_nobody    TRACE("Opening a file type (%d) permissions: %s (%s)\n", type, perm, filename);#endif#ifdef XP_WIN32    if (type == xpURL) {	HANDLE	hFile;	DWORD	dwType;	/* Check if we're trying to open a device. We don't allow this */	hFile = CreateFile(filename, GENERIC_READ, FILE_SHARE_READ, NULL,		OPEN_EXISTING, 0, NULL);	if (hFile != INVALID_HANDLE_VALUE) {	    dwType = GetFileType(hFile);	    CloseHandle(hFile);		    if (dwType != FILE_TYPE_DISK) {		XP_FREE(filename);		return NULL;	    }	}    }#endif#ifdef XP_WIN16    /* Windows uses ANSI codepage, DOS uses OEM codepage,  */    /* fopen takes OEM codepage */    /* That's why we need to do conversion here. */    CString oembuff = filename;    oembuff.AnsiToOem();    fp = fopen(oembuff, (char *) perm);    if (fp && type == xpURL) {	union _REGS	inregs, outregs;	/* Check if we opened a device. Execute an Interrupt 21h to invoke */	/* MS-DOS system call 44h */	inregs.x.ax = 0x4400;	 /* MS-DOS function to get device information */	inregs.x.bx = _fileno(fp);	_int86(0x21, &inregs, &outregs);	if (outregs.x.dx & 0x80) {	    /* It's a device. Don't allow any reading/writing */	    fclose(fp);	    XP_FREE(filename);	    return NULL;	}    }#else	    fp = fopen(filename, (char *) perm);#endif    XP_FREE(filename);    return(fp);}/******************************************************************************//* Thread-safe entry points: */extern PRMonitor* _pr_TempName_lock;#ifndef CMD_STUBchar *WH_TempName(XP_FileType type, const char * prefix){    static char buf[_MAX_PATH];	/* protected by _pr_TempName_lock */    char* result;    if (_pr_TempName_lock == NULL)	_pr_TempName_lock = PR_NewNamedMonitor("TempName-lock");    PR_EnterMonitor(_pr_TempName_lock);    result = XP_STRDUP(xp_TempFileName(type, prefix, NULL, buf));    PR_ExitMonitor(_pr_TempName_lock);    return result;}#endif /* CMD_STUB */PUBLIC char *WH_FileName (const char *name, XP_FileType type){    char* myName;    char* result;    /*    ** I'm not sure this lock is really needed by windows, but just    ** to be safe:    */    /*	XP_ASSERT(_pr_TempName_lock); */    /*	PR_EnterMonitor(_pr_TempName_lock); */    result = xp_FileName(name, type, &myName);    /*	PR_ExitMonitor(_pr_TempName_lock); */    return myName;}#endif /* XP_WIN */

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?