Beispiel #1
0
static const char *
xfe_netcaster_path(void)

/*
 * description:
 *	Determine a path to tab.htm, which is
 *	loaded into a browser window to start
 *	Netcaster by checking
 *	the following locations in order:
 *		$HOME/.netscape/netcast/tab.htm
 *		$MOZILLA_HOME/netcast/tab.htm
 *		Version Registry via VR_GetPath()
 *		fe_GetProgramDirectory()/netcast/tab.htm
 *
 *  The reason for precedence is as follows:
 *		$HOME first. Preferences set in a user's
 *		$HOME override everything else.
 *		This allows users some chance of running in
 *		the case where the system admin won't install
 *		Netcaster in globally accessible location.
 *		This can also be useful for debugging purposes.
 *
 *		$MOZILLA_HOME is now recommended as the standard
 *		for finding Communicator and related components.
 *		It comes next.
 *
 *		The registry should get set correctly during ASD install.
 *		However the registry's role in tracking versions has
 *		been emphasized over its role in tracking location.
 *		(although you can't have the former without the latter).
 *		Rumor also has it that some people are in the habit
 *		of deleting the registry to fix problems, so it
 *		may not always be available.
 *
 *		Last resort is to do our best effort at determining
 *		where Communicator was invoked by getting the program directory
 *		by looking at the invocation path.
 *
 * returns:
 *	On success returns a path to tab.htm
 *	On failure returns NULL
 *
 ****************************************/
{
  const char * result = 0;
  char * home;
  REGERR code;

  if (!private_xfe_netcaster_path)
	{
	  private_xfe_netcaster_path = (char*)XP_ALLOC(MAXPATHLEN);
	  if (private_xfe_netcaster_path)
		private_xfe_netcaster_path[0] = '\0';
	  else
		return result;
	}

  if (private_xfe_netcaster_path[0])
	{
	  result = private_xfe_netcaster_path;
#ifdef DEBUG_rodt
		  printf("DEBUG_rodt: Netcaster path a %s\n",result);
#endif
	  return result;
	}


  //
  // CHECK $HOME/.netscape
  //
  home = getenv("HOME");
  if (home)
	{
	  XP_STRCPY(private_xfe_netcaster_path, home);
	  if (xfe_last_character(private_xfe_netcaster_path) != '/')
		XP_STRCAT(private_xfe_netcaster_path,"/");
	  XP_STRCAT(private_xfe_netcaster_path,".netscape/");
	  XP_STRCAT(private_xfe_netcaster_path,netcasterTabHtmlPath);
	  if (xfe_path_exists(private_xfe_netcaster_path))
		{
		  result = private_xfe_netcaster_path;
#ifdef DEBUG_rodt
		  printf("DEBUG_rodt: Netcaster path b %s\n",result);
#endif
		  return result;
		}
	}


  //
  // CHECK $MOZILLA_HOME
  //
  home = getenv("MOZILLA_HOME");
  if (home)
	{
	  XP_STRCPY(private_xfe_netcaster_path, home);
	  if (xfe_last_character(private_xfe_netcaster_path) != '/')
		XP_STRCAT(private_xfe_netcaster_path,"/");
	  XP_STRCAT(private_xfe_netcaster_path,netcasterTabHtmlPath);
	  if (xfe_path_exists(private_xfe_netcaster_path))
		{
		  result = private_xfe_netcaster_path;
#ifdef DEBUG_rodt
		  printf("DEBUG_rodt: Netcaster path c %s\n",result);
#endif
		  return result;
		}
	}

  //
  // CHECK THE REGISTRY
  //
  // Could also call VR_InRegistry("Netcaster") but it would be redundant
  // Note that VR_ValidateComponent also calls VR_GetPath() but it doesn't
  // return any path information
  //
  code = VR_GetPath(netcasterTabHtmlRegistryNode, sizeof(private_xfe_netcaster_path)-1, private_xfe_netcaster_path);
  if (code == REGERR_OK)
	{
	  code = VR_ValidateComponent(netcasterTabHtmlRegistryNode);
	  if (code == REGERR_OK
		  && xfe_path_exists(private_xfe_netcaster_path))  // extra check
		{
		  result = private_xfe_netcaster_path;
#ifdef DEBUG_rodt
		  printf("DEBUG_rodt: Netcaster path d %s\n",result);
#endif
		  return result;
		}
	}
  private_xfe_netcaster_path[0] = '\0';

  //
  // CHECK THE PROGRAM DIRECTORY
  //
  fe_GetProgramDirectory(private_xfe_netcaster_path, MAXPATHLEN - 1);
  if (private_xfe_netcaster_path[0])
	{
	  if (xfe_last_character(private_xfe_netcaster_path) != '/')
		XP_STRCAT(private_xfe_netcaster_path,"/");
	  XP_STRCAT(private_xfe_netcaster_path,netcasterTabHtmlPath);
	  if (xfe_path_exists(private_xfe_netcaster_path))
		{
		  result = private_xfe_netcaster_path;
#ifdef DEBUG_rodt
		  printf("DEBUG_rodt: Netcaster path e %s\n",result);
#endif
		  return result;
		}
	}

  private_xfe_netcaster_path[0] = '\0';
#ifdef DEBUG_rodt
  printf("DEBUG_rodt: Netcaster path not found\n");
#endif
  return result;
}
Beispiel #2
0
/* returns a unmalloced static string
 * that is only available for temporary use.
 */
PUBLIC char *
xp_FileName (const char *name, XP_FileType type, char* buf, char* configBuf)
{
    const char *conf_dir = xp_unix_config_directory(configBuf);

    switch (type)
    {
    case xpSARCacheIndex:
    {
        const char *sar_cache_dir = FE_SARCacheDir;
        if (!sar_cache_dir || !*sar_cache_dir)
            sar_cache_dir = conf_dir;
        if (sar_cache_dir [strlen (sar_cache_dir) - 1] == '/')
            sprintf (buf, "%.900sarchive.fat", sar_cache_dir);
        else
            sprintf (buf, "%.900s/archive.fat", sar_cache_dir);

        name = buf;
        break;
    }
    case xpSARCache:
    {
        /* WH_TempName() returns relative pathnames for the cache files,
           so that relative paths get written into the cacheFAT database.
           WH_FileName() converts them to absolute if they aren't already
           so that the logic of XP_FileOpen() and XP_FileRename() and who
           knows what else is simpler.
         */
        if (name != NULL && *name == '/')
            break ;

        {
            char *tmp = FE_SARCacheDir;
            if (!tmp || !*tmp) tmp = "/tmp";
            if (tmp [strlen (tmp) - 1] == '/')
                sprintf (buf, "%.500s%.500s", tmp, name);
            else
                sprintf (buf, "%.500s/%.500s", tmp, name);
            name = buf;
        }
        break;
    }
    case xpCacheFAT:
    {
        const char *cache_dir = FE_CacheDir;
        if (!cache_dir || !*cache_dir)
            cache_dir = conf_dir;
        if (cache_dir [strlen (cache_dir) - 1] == '/')
            sprintf (buf, "%.900sindex.db", cache_dir);
        else
            sprintf (buf, "%.900s/index.db", cache_dir);

        name = buf;
        break;
    }
    case xpCache:
    {
        /* WH_TempName() returns relative pathnames for the cache files,
           so that relative paths get written into the cacheFAT database.
           WH_FileName() converts them to absolute if they aren't already
           so that the logic of XP_FileOpen() and XP_FileRename() and who
           knows what else is simpler.
         */
        if (*name != '/')
        {
            char *tmp = FE_CacheDir;
            if (!tmp || !*tmp) tmp = "/tmp";
            if (tmp [strlen (tmp) - 1] == '/')
                sprintf (buf, "%.500s%.500s", tmp, name);
            else
                sprintf (buf, "%.500s/%.500s", tmp, name);
            name = buf;
        }
        break;
    }

    case xpHTTPCookie:
    {
#ifndef OLD_UNIX_FILES
        sprintf (buf, "%.900s/cookies", conf_dir);
#else  /* OLD_UNIX_FILES */
        sprintf (buf, "%.900s/.netscape-cookies", conf_dir);
#endif /* OLD_UNIX_FILES */
        name = buf;
        break;
    }
    case xpRegistry:
    {
        if ( name == NULL || *name == '\0' ) {
#ifndef OLD_UNIX_FILES
            sprintf (buf, "%.900s/registry", conf_dir);
#else  /* OLD_UNIX_FILES */
            sprintf (buf, "%.900s/.netscape-registry", conf_dir);
#endif /* OLD_UNIX_FILES */
            name = buf;
        }
        else {
            XP_ASSERT( name[0] == '/' );
        }
        break;
    }
    case xpProxyConfig:
    {
        sprintf(buf, "%.900s/proxyconf", conf_dir);
        name = buf;
        break;
    }
    case xpTemporary:
    {
        if (*name != '/')
        {
            char *tmp = FE_TempDir;
            if (!tmp || !*tmp) tmp = "/tmp";
            if (tmp [strlen (tmp) - 1] == '/')
                sprintf (buf, "%.500s%.500s", tmp, name);
            else
                sprintf (buf, "%.500s/%.500s", tmp, name);
            name = buf;
        }
        break;
    }
    case xpNewsRC:
    case xpSNewsRC:
    case xpTemporaryNewsRC:
    {
        /* In this case, `name' is "" or "host" or "host:port". */

        char *home = getenv ("HOME");
        const char *newsrc_dir = ((FE_UserNewsRC && *FE_UserNewsRC)
                                  ? FE_UserNewsRC
                                  : (home ? home : ""));
        const char *basename = (type == xpSNewsRC ? ".snewsrc" : ".newsrc");
        const char *suffix = (type == xpTemporaryNewsRC ? ".tmp" : "");
        if (*name)
            sprintf (buf, "%.800s%.1s%.8s-%.128s%.4s",
                     newsrc_dir,
                     (newsrc_dir[XP_STRLEN(newsrc_dir)-1] == '/' ? "" : "/"),
                     basename, name, suffix);
        else
            sprintf (buf, "%.800s%.1s%.128s%.4s",
                     newsrc_dir,
                     (newsrc_dir[XP_STRLEN(newsrc_dir)-1] == '/' ? "" : "/"),
                     basename, suffix);

        name = buf;
        break;
    }
    case xpNewsgroups:
    case xpSNewsgroups:
    {
#ifndef OLD_UNIX_FILES
        sprintf (buf, "%.800s/%snewsgroups-%.128s",
                 conf_dir,
                 type == xpSNewsgroups ? "s" : "",
                 name);
#else  /* OLD_UNIX_FILES */
        sprintf (buf, "%.800s/.netscape-%snewsgroups-%.128s",
                 conf_dir,
                 type == xpSNewsgroups ? "s" : "",
                 name);
#endif /* OLD_UNIX_FILES */
        name = buf;
        break;
    }

    case xpExtCacheIndex:
#ifndef OLD_UNIX_FILES
        sprintf (buf, "%.900s/cachelist", conf_dir);
#else  /* OLD_UNIX_FILES */
        sprintf (buf, "%.900s/.netscape-cache-list", conf_dir);
#endif /* OLD_UNIX_FILES */
        name = buf;
        break;

    case xpGlobalHistory:
        name = FE_GlobalHist;
        break;

    case xpCertDB:
#ifndef OLD_UNIX_FILES
        if ( name ) {
            sprintf (buf, "%.900s/cert%s.db", conf_dir, name);
        } else {
            sprintf (buf, "%.900s/cert.db", conf_dir);
        }
#else  /* OLD_UNIX_FILES */
        sprintf (buf, "%.900s/.netscape-certdb", conf_dir);
#endif /* OLD_UNIX_FILES */
        name = buf;
        break;
    case xpCertDBNameIDX:
#ifndef OLD_UNIX_FILES
        sprintf (buf, "%.900s/cert-nameidx.db", conf_dir);
#else  /* OLD_UNIX_FILES */
        sprintf (buf, "%.900s/.netscape-certdb-nameidx", conf_dir);
#endif /* OLD_UNIX_FILES */
        name = buf;
        break;
    case xpKeyDB:
#ifndef OLD_UNIX_FILES
        if ( name ) {
            sprintf (buf, "%.900s/key%s.db", conf_dir, name);
        } else {
            sprintf (buf, "%.900s/key.db", conf_dir);
        }
#else  /* OLD_UNIX_FILES */
        sprintf (buf, "%.900s/.netscape-keydb", conf_dir);
#endif /* OLD_UNIX_FILES */
        name = buf;
        break;
    case xpSecModuleDB:
        sprintf (buf, "%.900s/secmodule.db", conf_dir);
        name = buf;
        break;

    case xpSignedAppletDB:
    {
#ifndef OLD_UNIX_FILES
        if ( name ) {
            sprintf (buf, "%.900s/signedapplet%s.db", conf_dir, name);
        } else {
            sprintf (buf, "%.900s./signedapplet.db", conf_dir);
        }
#else  /* OLD_UNIX_FILES */
        sprintf (buf, "%.900s/.netscape-signedappletdb", conf_dir);
#endif /* OLD_UNIX_FILES */
        name = buf;
        break;
    }

    case xpFileToPost:
    case xpSignature:
        /* These are always absolute pathnames.
         * BUT, the user can type in whatever so
         * we can't assert if it doesn't begin
         * with a slash
         */
        break;

    case xpExtCache:
    case xpKeyChain:
    case xpURL:
    case xpHotlist:
    case xpBookmarks:
    case xpMimeTypes:
    case xpSocksConfig:
    case xpMailFolder:
#ifdef BSDI
        /* In bsdi, mkdir fails if the directory name is terminated
         * with a '/'. - dp
         */
        if (name[strlen(name)-1] == '/') {
            strcpy(buf, name);
            buf[strlen(buf)-1] = '\0';
            name = buf;
        }
#endif
#ifndef MCC_PROXY
        /*
         * These are always absolute pathnames for the Navigator.
         * Only the proxy (servers) may have pathnames relative
         * to their current working directory (the servers chdir
         * to their admin/config directory on startup.
         *
         */
        if (name) XP_ASSERT (name[0] == '/');
#endif	/* ! MCC_PROXY */

        break;

    case xpMailFolderSummary:
        /* Convert /a/b/c/foo to /a/b/c/.foo.summary (note leading dot) */
    {
        const char *slash;
        slash = strrchr (name, '/');
        if (name) XP_ASSERT (name[0] == '/');
        XP_ASSERT (slash);
        if (!slash) return 0;
        XP_MEMCPY (buf, name, slash - name + 1);
        buf [slash - name + 1] = '.';
        XP_STRCPY (buf + (slash - name) + 2, slash + 1);
        XP_STRCAT (buf, ".summary");
        name = buf;
        break;
    }

    case xpAddrBookNew:
        /* Convert foo.db to /a/b/c/foo.db */
    {
        if ( name ) {
            sprintf (buf, "%.900s/%s", conf_dir, name);
        } else {
            sprintf (buf, "%.900s/abook.nab", conf_dir);
        }
#if defined(DEBUG_tao)
        printf("\n  xpAddrBookNew, xp_FileName, buf=%s\n", buf);
#endif
        name = buf;

        break;
    }

    case xpAddrBook:
        /* Convert /a/b/c/foo to /a/b/c/foo.db (note leading dot) */
    {
        /* Tao_27jan97
         */
        char *dot = NULL;
        int len = 0;
        const char *base = NULL;

        if (name)
            XP_ASSERT (name[0] == '/');

        dot = XP_STRRCHR(name, '.');
        if (dot) {

            len = dot - name + 1;
            XP_STRNCPY_SAFE(buf, name, len);
        }/* if */

        XP_STRCAT (buf, ".nab");


        /* Tao_02jun97 don't convert addrbook.db
         * reuse len, dot
         */
        base = XP_STRRCHR(name, '/');
        if (base && *base == '/')
            base++;

#if defined(DEBUG_tao)
        printf("\n++++  xpAddrBook, before xp_FileName=%s\n", name);
#endif

        if (!base || XP_STRCMP(base, "addrbook.db"))
            /* not old addrbook.db file
             */
            name = buf;
#if defined(DEBUG_tao)
        printf("\n  xpAddrBook, xp_FileName=%s\n", name);
#endif
        break;
    }

    case xpVCardFile:
        /* Convert /a/b/c/foo to /a/b/c/foo.vcf (note leading dot) */
    {
#if 1
        /* Tao_27jan97
         */
        char *dot = NULL;
        int len = 0;

        if (name)
            XP_ASSERT (name[0] == '/');

        dot = XP_STRRCHR(name, '.');
        if (dot) {
            len = dot - name + 1;
            XP_STRNCPY_SAFE(buf, name, len);
        }/* if */

        XP_STRCAT (buf, ".vcf");
        name = buf;
#if defined(DEBUG_tao_)
        printf("\n  xp_FileName=%s\n", name);
#endif
#else
        const char *slash;
        slash = strrchr (name, '/');
        if (name) XP_ASSERT (name[0] == '/');
        XP_ASSERT (slash);
        if (!slash) return 0;
        XP_MEMCPY (buf, name, slash - name + 1);
        XP_STRCAT (buf, ".vcf");
        name = buf;
#endif
        break;
    }

    case xpLDIFFile:
        /* Convert /a/b/c/foo to /a/b/c/foo.ldif (note leading dot) */
    {
#if 1
        /* Tao_27jan97
         */
        char *dot = NULL;
        int len = 0;

        if (name)
            XP_ASSERT (name[0] == '/');

        dot = XP_STRRCHR(name, '.');
        if (dot) {
            len = dot - name + 1;
            XP_STRNCPY_SAFE(buf, name, len);
        }/* if */

        XP_STRCAT (buf, ".ldif");
        name = buf;
#if defined(DEBUG_tao_)
        printf("\n  xp_FileName=%s\n", name);
#endif

#else
        const char *slash;
        slash = strrchr (name, '/');
        if (name) XP_ASSERT (name[0] == '/');
        XP_ASSERT (slash);
        if (!slash) return 0;
        XP_MEMCPY (buf, name, slash - name + 1);
        XP_STRCAT (buf, ".ldif");
        name = buf;
#endif
        break;
    }

    case xpJSMailFilters:
        sprintf(buf, "%.900s/filters.js", conf_dir);
        name = buf;
        break;

    case xpJSHTMLFilters:
        sprintf(buf, "%.900s/hook.js", conf_dir);
        name = buf;
        break;

    case xpNewsSort:
        sprintf(buf, "%.800s/xover-cache/%.128snetscape-newsrule", conf_dir, name);
        break;
    case xpMailSort:
#ifndef OLD_UNIX_FILES
        sprintf(buf, "%.900s/mailrule", conf_dir);
#else  /* OLD_UNIX_FILES */
        sprintf(buf, "%.900s/.netscape-mailrule", conf_dir);
#endif /* OLD_UNIX_FILES */
        name = buf;
        break;
    case xpMailPopState:
#ifndef OLD_UNIX_FILES
        sprintf(buf, "%.900s/popstate", conf_dir);
#else  /* OLD_UNIX_FILES */
        sprintf(buf, "%.900s/.netscape-popstate", conf_dir);
#endif /* OLD_UNIX_FILES */
        name = buf;
        break;
    case xpMailFilterLog:
        sprintf(buf, "%.900s/.netscape-mailfilterlog", conf_dir);
        name = buf;
        break;
    case xpNewsFilterLog:
        sprintf(buf, "%.900s/.netscape-newsfilterlog", conf_dir);
        name = buf;
        break;
    case xpMailSubdirectory:
    {
        char * pEnd = strrchr(name, '/');
        strcpy(buf, name);

        /* strip off the extension */
        if(!pEnd)
            pEnd = buf;

        pEnd = strchr(pEnd, '.');
        if(pEnd)
            *pEnd = '\0';
        strcat(buf, ".sbd/");
        name = buf;
    }
    break;
    case xpXoverCache:
        sprintf(buf, "%.800s/xover-cache/%.128s", conf_dir, name);
        name = buf;
        break;

    case xpNewsHostDatabase:
        sprintf(buf, "%.800s/newsdb", conf_dir);
        name = buf;
        break;

    case xpImapRootDirectory:
    {
        char prefbuf[1024];
        int len = sizeof prefbuf / sizeof *prefbuf;
        if ((PREF_GetCharPref("mail.imap.root_dir",
                              prefbuf, &len) == PREF_NOERROR)
                && *prefbuf == '/')
            /* guard against assert: line 806, file xp_file.c */
            XP_STRNCPY_SAFE(buf, prefbuf, len);
        /* Copy back to the buffer that was passed in.
         * We couldn't have PREF_GetCharPref() just put it there
         * initially because the size of buf wasn't passed in
         * (it happens to be 1024) and PREF_GetCharPref() insists
         * on having a size. Sigh.
         */
        else
        {
            char *home = getenv ("HOME");
            sprintf(buf, "%s/ns_imap", (home ? home : ""));
        }
        name = buf;
        break;
    }

    case xpImapServerDirectory:
    {
        char prefbuf[1024];
        int len = sizeof prefbuf / sizeof *prefbuf;
        if ((PREF_GetCharPref("mail.imap.root_dir",
                              prefbuf, &len) == PREF_NOERROR)
                && *prefbuf == '/')
            /* guard against assert: line 806, file xp_file.c */
            sprintf(buf, "%s/%s", prefbuf, name);
        else
        {
            char *home = getenv ("HOME");
            sprintf(buf, "%s/ns_imap/%s", (home ? home : ""), name);
        }
        name = buf;
        break;
    }

    case xpFolderCache:
        sprintf (buf, "%s/summary.dat", conf_dir);
        name = buf;
        break;

    case xpCryptoPolicy:
    {
        extern void fe_GetProgramDirectory(char *path, int len);
        char *policyFN = "moz40p3";
        char *mozHome  = getenv("MOZILLA_HOME");
        char *lang     = getenv("LANG");
        int   result;
        char  dirName[1024];

        name = buf;
        if (!xp_unix_sprintf_stat(buf, conf_dir, lang, policyFN))
            break;
        if (!xp_unix_sprintf_stat(buf, mozHome, lang, policyFN))
            break;
        fe_GetProgramDirectory(dirName, sizeof dirName);
        if (!xp_unix_sprintf_stat(buf, dirName, lang, policyFN))
            break;

        /* couldn't find it, but must leave a valid file name in buf */
        sprintf(buf, "%.900s/%s", conf_dir, policyFN);
        break;
    }

    case xpPKCS12File:
        /* Convert /a/b/c/foo to /a/b/c/foo.p12 (note leading dot) */
    {
        int len = 0;

        if(name) {
            XP_ASSERT(name[0] == '/');

            /* only append if there is enough space in the buffer */
            /* this should be changed if the size of the buf changes */
            if((XP_STRLEN(name) + 4) <= 1020) {

                /* include NULL in length */
                len = XP_STRLEN(name) + 1;
                XP_STRNCPY_SAFE(buf, name, len);

                /* we want to concatenate ".p12" if it is not the
                 * last 4 characters of the name already.
                 * If len is less than 5 (including the terminating
                 * NULL), it is not ".p12".
                 * If the len is > 5 it may have the .p12, so we want
                 * to check and only append .p12 if the name
                 * specified does not end in .p12.
                 * only side effect -- this allows for the filename
                 * ".p12" which is fine.
                 */
                if((len >= 5) && XP_STRCASECMP(&(name[len-4-1]), ".p12")) {
                    XP_STRCAT(buf, ".p12");
                } else if(len < 5) {
                    /* can't be ".p12", so we append ".p12" */
                    XP_STRCAT(buf, ".p12");
                }
                name = buf;
            }
        }

        break;
    }

    case xpJSCookieFilters:
    {
        sprintf(buf, "%.900s/cookies.js", conf_dir);
        name = buf;
        break;
    }

    case xpLIPrefs:
    {
        sprintf(buf, "%.900s/liprefs.js", conf_dir);
        name = buf;
        break;
    }

    default:
        abort ();
    }

    return (char *) name;
}