nsprpub/pr/tests/version.c

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

     1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     2 /* This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this
     4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     6 #include "prio.h"
     7 #include "prprf.h"
     8 #include "prlink.h"
     9 #include "prvrsion.h"
    11 #include "plerror.h"
    12 #include "plgetopt.h"
    14 PR_IMPORT(const PRVersionDescription *) libVersionPoint(void);
    16 int main(int argc, char **argv)
    17 {
    18     PRIntn rv = 1;
    19     PLOptStatus os;
    20     PRIntn verbosity = 0;
    21     PRLibrary *runtime = NULL;
    22     const char *library_name = NULL;
    23     const PRVersionDescription *version_info;
    24 	char buffer[100];
    25 	PRExplodedTime exploded;
    26     PLOptState *opt = PL_CreateOptState(argc, argv, "d");
    28     PRFileDesc *err = PR_GetSpecialFD(PR_StandardError);
    30     while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
    31     {
    32         if (PL_OPT_BAD == os) continue;
    33         switch (opt->option)
    34         {
    35         case 0:  /* fully qualified library name */
    36             library_name = opt->value;
    37             break;
    38         case 'd':  /* verbodity */
    39             verbosity += 1;
    40             break;
    41          default:
    42             PR_fprintf(err, "Usage: version [-d] {fully qualified library name}\n");
    43             return 2;  /* but not a lot else */
    44         }
    45     }
    46     PL_DestroyOptState(opt);
    48     if (NULL != library_name)
    49     {
    50         runtime = PR_LoadLibrary(library_name);
    51         if (NULL == runtime) {
    52 			PL_FPrintError(err, "PR_LoadLibrary");
    53 			return 3;
    54 		} else {
    55             versionEntryPointType versionPoint = (versionEntryPointType)
    56                 PR_FindSymbol(runtime, "libVersionPoint");
    57             if (NULL == versionPoint) {
    58 				PL_FPrintError(err, "PR_FindSymbol");
    59 				return 4;
    60 			}	
    61 			version_info = versionPoint();
    62 		}
    63 	} else
    64 		version_info = libVersionPoint();	/* NSPR's version info */
    66 	(void)PR_fprintf(err, "Runtime library version information\n");
    67 	PR_ExplodeTime(
    68 		version_info->buildTime, PR_GMTParameters, &exploded);
    69 	(void)PR_FormatTime(
    70 		buffer, sizeof(buffer), "%d %b %Y %H:%M:%S", &exploded);
    71 	(void)PR_fprintf(err, "  Build time: %s GMT\n", buffer);
    72 	(void)PR_fprintf(
    73 		err, "  Build time: %s\n", version_info->buildTimeString);
    74 	(void)PR_fprintf(
    75 		err, "  %s V%u.%u.%u (%s%s%s)\n",
    76 		version_info->description,
    77 		version_info->vMajor,
    78 		version_info->vMinor,
    79 		version_info->vPatch,
    80 		(version_info->beta ? " beta " : ""),
    81 		(version_info->debug ? " debug " : ""),
    82 		(version_info->special ? " special" : ""));
    83 	(void)PR_fprintf(err, "  filename: %s\n", version_info->filename);
    84 	(void)PR_fprintf(err, "  security: %s\n", version_info->security);
    85 	(void)PR_fprintf(err, "  copyright: %s\n", version_info->copyright);
    86 	(void)PR_fprintf(err, "  comment: %s\n", version_info->comment);
    87 	rv = 0;
    88     return rv;
    89 }
    91 /* version.c */

mercurial