⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 filestub.c

📁 支持SSL v2/v3, TLS, PKCS #5, PKCS #7, PKCS #11, PKCS #12, S/MIME, X.509v3证书等安全协议或标准的开发库编译用到NSPR
💻 C
📖 第 1 页 / 共 3 页
字号:
/*  * The contents of this file are subject to the Mozilla Public * License Version 1.1 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.mozilla.org/MPL/ *  * Software distributed under the License is distributed on an "AS * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or * implied. See the License for the specific language governing * rights and limitations under the License. *  * The Original Code is the Netscape security libraries. *  * The Initial Developer of the Original Code is Netscape * Communications Corporation.  Portions created by Netscape are  * Copyright (C) 1994-2000 Netscape Communications Corporation.  All * Rights Reserved. *  * Contributor(s): *  * Alternatively, the contents of this file may be used under the * terms of the GNU General Public License Version 2 or later (the * "GPL"), in which case the provisions of the GPL are applicable  * instead of those above.  If you wish to allow use of your  * version of this file only under the terms of the GPL and not to * allow others to use your version of this file under the MPL, * indicate your decision by deleting the provisions above and * replace them with the notice and other provisions required by * the GPL.  If you do not delete the provisions above, a recipient * may use your version of this file under either the MPL or the * GPL. */#define CMD_STUB 1	/* this is just a stub for security/cmd/*  */#define MOZ_LITE 1	/* don't need that other stuff, either */#if 0#include "stdafx.h"#include "dialog.h"#include "mainfrm.h"#include "custom.h"#include "shcut.h"#include "edt.h"#include "prmon.h"#include "fegui.h"#include "prefapi.h"#include <io.h>#include "secrng.h"#include "mailass.h"#include "ipframe.h"#include "mnprefs.h"#else#include <xp_core.h>#include <xp_file.h>#include <xp_mcom.h>#define ASSERT assert#endif#ifdef XP_MAC#include "prpriv.h" /* For PR_NewNamedMonitor */#else#include "private/prpriv.h"#endif#ifdef XP_WIN#ifndef _AFXDLL/* MSVC Debugging new...goes to regular new in release mode */#define new DEBUG_NEW  #endif#ifdef __BORLANDC__    #define _lseek lseek#endif       #define WIDTHBYTES(i) ((i + 31) / 32 * 4)#define MAXREAD 32767       MODULE_PRIVATE char * XP_CacheFileName();#define MAXSTRINGLEN 8192 #ifndef CMD_STUB/* Return a string the same as the In string ** but with all of the \n's replaced with \r\n's  */MODULE_PRIVATE char * FE_Windowsify(const char * In){    char *Out;    char *o, *i;     int32 len;    if(!In)        return NULL;    /* if every character is a \n then new string is twice as long */    len = (int32) XP_STRLEN(In) * 2 + 1;    Out = (char *) XP_ALLOC(len);    if(!Out)        return NULL;  /* Move the characters over one by one.  If the current character is */  /*  a \n replace add a \r before moving the \n over */    for(i = (char *) In, o = Out; i && *i; *o++ = *i++)       if(*i == '\n')            *o++ = '\r';    /* Make sure our new string is NULL terminated */    *o = '\0';    return(Out);}/*  Return some adjusted out full path on the mac. *//*  For windows, we just return what was passed in. *//*  We must provide it in a seperate buffer, otherwise they might change *//*      the original and change also what they believe to be saved. */char *WH_FilePlatformName(const char *pName)    {    if(pName)   {        return XP_STRDUP(pName);    }        return NULL;}char *FE_GetProgramDirectory(char *buffer, int length){    ::GetModuleFileName(theApp.m_hInstance, buffer, length);    /*	Find the trailing slash. */    char *pSlash = ::strrchr(buffer, '\\');    if(pSlash)	{	*(pSlash+1) = '\0';    } else {	buffer[0] = '\0';    }    return (buffer);}char*XP_TempDirName(void){    char *tmp = theApp.m_pTempDir;    if (!tmp)        return XP_STRDUP(".");    return XP_STRDUP(tmp);}/* Windows _tempnam() lets the TMP environment variable override things sent ** in so it look like we're going to have to make a temp name by hand.** The user should *NOT* free the returned string.  ** It is stored in static space ** and so is not valid across multiple calls to this function.** The names generated look like **   c:\netscape\cache\m0.moz **   c:\netscape\cache\m1.moz ** up to... **   c:\netscape\cache\m9999999.moz ** after that if fails ** */PUBLIC char *xp_TempFileName(int type, const char * request_prefix, const char * extension,				char* file_buf){    const char * directory = NULL;     char * ext = NULL;           /* file extension if any */    char * prefix = NULL;        /* file prefix if any */        XP_StatStruct statinfo;    int status;         /* */    /* based on the type of request determine what directory we should be */    /*   looking into */    /*   */    switch(type) {    case xpCache:        directory = theApp.m_pCacheDir;        ext = ".MOZ";        prefix = CACHE_PREFIX;        break;#ifndef MOZ_LITE            case xpSNewsRC:    case xpNewsRC:    case xpNewsgroups:    case xpSNewsgroups:    case xpTemporaryNewsRC:        directory = g_MsgPrefs.m_csNewsDir;        ext = (char *)extension;        prefix = (char *)request_prefix;        break;    case xpMailFolderSummary:    case xpMailFolder:	directory = g_MsgPrefs.m_csMailDir;        ext = (char *)extension;        prefix = (char *)request_prefix;	break;    case xpAddrBook:	/*changed to support multi-profile */	/*directory = theApp.m_pInstallDir->GetCharValue(); */	directory = (const char *)theApp.m_UserDirectory;	if ((request_prefix == 0) || (XP_STRLEN (request_prefix) == 0))		prefix = "abook";	ext = ".nab";	break;#endif /* MOZ_LITE       */    case xpCacheFAT:	directory = theApp.m_pCacheDir;	prefix = "fat";	ext = "db";	break;    case xpJPEGFile:        directory = theApp.m_pTempDir;	ext = ".jpg";        prefix = (char *)request_prefix;	break;    case xpPKCS12File:	directory = theApp.m_pTempDir;	ext = ".p12";	prefix = (char *)request_prefix;	break;    case xpTemporary:    default:        directory = theApp.m_pTempDir;        ext = (char *)extension;        prefix = (char *)request_prefix;        break;    }    if(!directory)        return(NULL);    if(!prefix)        prefix = "X";    if(!ext)        ext = ".TMP";  /*  We need to base our temporary file names on time, and not on sequential */  /*    addition because of the cache not being updated when the user */  /*    crashes and files that have been deleted are over written with */  /*    other files; bad data. */  /*  The 52 valid DOS file name characters are */  /*    0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_^$~!#%&-{}@`'() */  /*  We will only be using the first 32 of the choices. */  /* */  /*  Time name format will be M+++++++.MOZ */  /*    Where M is the single letter prefix (can be longer....) */  /*    Where +++++++ is the 7 character time representation (a full 8.3 */  /*      file name will be made). */  /*    Where .MOZ is the file extension to be used. */  /* */  /*  In the event that the time requested is the same time as the last call */  /*    to this function, then the current time is incremented by one, */  /*    as is the last time called to facilitate unique file names. */  /*  In the event that the invented file name already exists (can't */  /*    really happen statistically unless the clock is messed up or we */  /*    manually incremented the time), then the times are incremented */  /*    until an open name can be found. */  /* */  /*  time_t (the time) has 32 bits, or 4,294,967,296 combinations. */  /*  We will map the 32 bits into the 7 possible characters as follows: */  /*    Starting with the lsb, sets of 5 bits (32 values) will be mapped */  /*      over to the appropriate file name character, and then */  /*      incremented to an approprate file name character. */  /*    The left over 2 bits will be mapped into the seventh file name */  /*      character. */  /* */        int i_letter, i_timechars, i_numtries = 0;    char ca_time[8];    time_t this_call = (time_t)0;        /*  We have to base the length of our time string on the length */    /*    of the incoming prefix.... */    /* */    i_timechars = 8 - strlen(prefix);        /*  Infinite loop until the conditions are satisfied. */    /*  There is no danger, unless every possible file name is used. */    /* */    while(1)    {        /*    We used to use the time to generate this. */        /*    Now, we use some crypto to avoid bug #47027 */        RNG_GenerateGlobalRandomBytes((void *)&this_call, sizeof(this_call));        /*  Convert the time into a 7 character string. */        /*  Strip only the signifigant 5 bits. */        /*  We'll want to reverse the string to make it look coherent */        /*    in a directory of file names. */        /* */        for(i_letter = 0; i_letter < i_timechars; i_letter++) {            ca_time[i_letter] = (char)((this_call >> (i_letter * 5)) & 0x1F);                      /*  Convert any numbers to their equivalent ascii code */          /* */            if(ca_time[i_letter] <= 9)    {                ca_time[i_letter] += '0';            }          /*  Convert the character to it's equivalent ascii code */          /* */            else    {                ca_time[i_letter] += 'A' - 10;            }        }                /*  End the created time string. */        /* */        ca_time[i_letter] = '\0';                /*  Reverse the time string. */        /* */        _strrev(ca_time);                /*  Create the fully qualified path and file name. */        /* */        sprintf(file_buf, "%s\\%s%s%s", directory, prefix, ca_time, ext);        /*  Determine if the file exists, and mark that we've tried yet */        /*    another file name (mark to be used later). */        /*   */        /*  Use the system call instead of XP_Stat since we already */        /*  know the name and we don't want recursion */        /* */        status = _stat(file_buf, &statinfo);        i_numtries++;        /*  If it does not exists, we are successful, return the name. */        /* */        if(status == -1)    {           /* don't generate a directory as part of the cache temp names.    	    * When the cache file name is passed into the other XP_File 	    * functions we will append the cache directory to the name            * to get the complete path.            * This will allow the cache to be moved around            * and for netscape to be used to generate external cache FAT's.                */            if(type == xpCache )		sprintf(file_buf, "%s%s%s", prefix, ca_time, ext);            TRACE("Temp file name is %s\n", file_buf);            return(file_buf);        }                /*  If there is no room for additional characters in the time, */        /*    we'll have to return NULL here, or we go infinite. */        /*    This is a one case scenario where the requested prefix is */        /*    actually 8 letters long!   */        /*  Infinite loops could occur with a 7, 6, 5, etc character prefixes */        /*    if available files are all eaten up (rare to impossible), in */        /*    which case, we should check at some arbitrary frequency of */        /*    tries before we give up instead of attempting to Vulcanize */        /*    this code.  Live long and prosper. */        /* */        if(i_timechars == 0)    {            break;        } else if(i_numtries == 0x00FF) {            break;        }    }

⌨️ 快捷键说明

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