コード例 #1
0
// Gets shell version as packed 64 bit int
PRUint64 nsDragService::GetShellVersion()
{
  PRUint64 lVersion = LL_INIT(0, 0);
  PRUint64 lMinor = lVersion;

  // shell32.dll should be loaded already, so we ae not actually loading the library here
  PRLibrary *libShell = PR_LoadLibrary("shell32.dll");
  if (libShell == NULL)
    return lVersion;

  do
  {
    DLLGETVERSIONPROC versionProc = NULL;
    versionProc = (DLLGETVERSIONPROC)PR_FindFunctionSymbol(libShell, "DllGetVersion");
    if (versionProc == NULL)
      break;

    DLLVERSIONINFO versionInfo;
    ::ZeroMemory(&versionInfo, sizeof(DLLVERSIONINFO));
    versionInfo.cbSize = sizeof(DLLVERSIONINFO);
    if (FAILED(versionProc(&versionInfo)))
      break;

    // why is this?
    LL_UI2L(lVersion, versionInfo.dwMajorVersion);
    LL_SHL(lVersion, lVersion, 32);
    LL_UI2L(lMinor, versionInfo.dwMinorVersion);
    LL_OR2(lVersion, lMinor);
  } while (false);

  PR_UnloadLibrary(libShell);
  libShell = NULL;

  return lVersion;
}
コード例 #2
0
// sets up concept of local time
// initializes the timeoutq and freelist
// fills the freelist with entries
// timeoutq is empty
//
void
init_timeoutq()
{
	int i;

//	then_usec = now_usec();

	timeoutq = (struct event *)&TQ;
	LL_INIT(timeoutq);
	freelist = (struct event *)&FL;
	LL_INIT(freelist);

	for (i=0; i<MAX_EVENTS; i++) {
		struct event *ep = &queue[i];
		LL_PUSH(freelist, ep);
	}

	return;
}
コード例 #3
0
ファイル: TestStrings.cpp プロジェクト: LastRitter/vbox-haiku
PRBool test_appendint64()
  {
    nsCString str;

    PRInt64 max = LL_MaxInt();
    static const char max_expected[] = "9223372036854775807";
    PRInt64 min = LL_MinInt();
    static const char min_expected[] = "-9223372036854775808";
    static const char min_expected_oct[] = "1000000000000000000000";
    PRInt64 maxint_plus1 = LL_INIT(1, 0);
    static const char maxint_plus1_expected[] = "4294967296";
    static const char maxint_plus1_expected_x[] = "100000000";

    str.AppendInt(max);

    if (!str.Equals(max_expected)) {
      fprintf(stderr, "Error appending LL_MaxInt(): Got %s\n", str.get());
      return PR_FALSE;
    }

    str.Truncate();
    str.AppendInt(min);
    if (!str.Equals(min_expected)) {
      fprintf(stderr, "Error appending LL_MinInt(): Got %s\n", str.get());
      return PR_FALSE;
    }
    str.Truncate();
    str.AppendInt(min, 8);
    if (!str.Equals(min_expected_oct)) {
      fprintf(stderr, "Error appending LL_MinInt() (oct): Got %s\n", str.get());
      return PR_FALSE;
    }


    str.Truncate();
    str.AppendInt(maxint_plus1);
    if (!str.Equals(maxint_plus1_expected)) {
      fprintf(stderr, "Error appending PR_UINT32_MAX + 1: Got %s\n", str.get());
      return PR_FALSE;
    }
    str.Truncate();
    str.AppendInt(maxint_plus1, 16);
    if (!str.Equals(maxint_plus1_expected_x)) {
      fprintf(stderr, "Error appending PR_UINT32_MAX + 1 (hex): Got %s\n", str.get());
      return PR_FALSE;
    }


    return PR_TRUE;
  }
コード例 #4
0
 static PLDHashNumber
 HashKey(PLDHashTable *table, const void *key)
 {
     // xor the low 32 bits with the high 32 bits.
     PRTime t = *static_cast<const PRTime *>(key);
     PRInt64 h64, l64;
     LL_USHR(h64, t, 32);
     l64 = LL_INIT(0, 0xffffffff);
     LL_AND(l64, l64, t);
     PRInt32 h32, l32;
     LL_L2I(h32, h64);
     LL_L2I(l32, l64);
     return PLDHashNumber(l32 ^ h32);
 }
コード例 #5
0
//-------------------------------------------------------------------------
nsresult
DataStruct::ReadCache(nsISupports** aData, uint32_t* aDataLen)
{
  // if we don't have a cache filename we are out of luck
  if (!mCacheFileName)
    return NS_ERROR_FAILURE;

  // get the path and file name
  nsCOMPtr<nsIFile> cacheFile ( getter_AddRefs(GetFileSpec(mCacheFileName)) );
  bool exists;
  if ( cacheFile && NS_SUCCEEDED(cacheFile->Exists(&exists)) && exists ) {
    // get the size of the file
    int64_t fileSize;
    int64_t max32(LL_INIT(0, 0xFFFFFFFF));
    cacheFile->GetFileSize(&fileSize);
    if (LL_CMP(fileSize, >, max32))
      return NS_ERROR_OUT_OF_MEMORY;
    uint32_t size;
    LL_L2UI(size, fileSize);

    // create new memory for the large clipboard data
    nsAutoArrayPtr<char> data(new char[size]);
    if ( !data )
      return NS_ERROR_OUT_OF_MEMORY;
      
    // now read it all in
    nsCOMPtr<nsIInputStream> inStr;
    NS_NewLocalFileInputStream( getter_AddRefs(inStr),
                                cacheFile);
    
    if (!cacheFile) return NS_ERROR_FAILURE;

    nsresult rv = inStr->Read(data, fileSize, aDataLen);

    // make sure we got all the data ok
    if (NS_SUCCEEDED(rv) && *aDataLen == size) {
      nsPrimitiveHelpers::CreatePrimitiveForData ( mFlavor.get(), data, fileSize, aData );
      return *aData ? NS_OK : NS_ERROR_FAILURE;
    }

    // zero the return params
    *aData    = nullptr;
    *aDataLen = 0;
  }
コード例 #6
0
ファイル: dertime.c プロジェクト: dimitrianoudi/Jaxer
static long monthToDayInYear[12] = {
    0,
    31,
    31+28,
    31+28+31,
    31+28+31+30,
    31+28+31+30+31,
    31+28+31+30+31+30,
    31+28+31+30+31+30+31,
    31+28+31+30+31+30+31+31,
    31+28+31+30+31+30+31+31+30,
    31+28+31+30+31+30+31+31+30+31,
    31+28+31+30+31+30+31+31+30+31+30,
};

static const PRTime January1st1     = (PRTime) LL_INIT(0xff234001U, 0x00d44000U);
static const PRTime January1st1950  = (PRTime) LL_INIT(0xfffdc1f8U, 0x793da000U);
static const PRTime January1st2050  = LL_INIT(0x0008f81e, 0x1b098000);
static const PRTime January1st10000 = LL_INIT(0x0384440c, 0xcc736000);

/* gmttime must contains UTC time in micro-seconds unit */
SECStatus
DER_TimeToUTCTimeArena(PRArenaPool* arenaOpt, SECItem *dst, int64 gmttime)
{
    PRExplodedTime printableTime;
    unsigned char *d;

    if ( (gmttime < January1st1950) || (gmttime >= January1st2050) ) {
        PORT_SetError(SEC_ERROR_INVALID_ARGS);
        return SECFailure;
    }
コード例 #7
0
ファイル: drbg.c プロジェクト: AOSC-Dev/nss-purified
#include "prtypes.h"
#include "prinit.h"
#include "blapi.h"
#include "blapii.h"
#include "nssilock.h"
#include "secitem.h"
#include "sha_fast.h"
#include "sha256.h"
#include "secrng.h"	/* for RNG_SystemRNG() */
#include "secmpi.h"

/* PRNG_SEEDLEN defined in NIST SP 800-90 section 10.1 
 * for SHA-1, SHA-224, and SHA-256 it's 440 bits.
 * for SHA-384 and SHA-512 it's 888 bits */
#define PRNG_SEEDLEN      (440/PR_BITS_PER_BYTE)
static const PRInt64 PRNG_MAX_ADDITIONAL_BYTES = LL_INIT(0x1, 0x0);
						/* 2^35 bits or 2^32 bytes */
#define PRNG_MAX_REQUEST_SIZE 0x10000		/* 2^19 bits or 2^16 bytes */
#define PRNG_ADDITONAL_DATA_CACHE_SIZE (8*1024) /* must be less than
						 *  PRNG_MAX_ADDITIONAL_BYTES
						 */

/* RESEED_COUNT is how many calls to the prng before we need to reseed 
 * under normal NIST rules, you must return an error. In the NSS case, we
 * self-reseed with RNG_SystemRNG(). Count can be a large number. For code
 * simplicity, we specify count with 2 components: RESEED_BYTE (which is 
 * the same as LOG256(RESEED_COUNT)) and RESEED_VALUE (which is the same as
 * RESEED_COUNT / (256 ^ RESEED_BYTE)). Another way to look at this is
 * RESEED_COUNT = RESEED_VALUE * (256 ^ RESEED_BYTE). For Hash based DRBG
 * we use the maximum count value, 2^48, or RESEED_BYTE=6 and RESEED_VALUE=1
 */
コード例 #8
0
ファイル: logging.c プロジェクト: hnarkaytis/millstone
#define _GNU_SOURCE /* TEMP_FAILURE_RETRY */

#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <signal.h>
#include <execinfo.h>
#include <pthread.h>
#include <string.h>

#include "logging.h"

#define LL_INIT(LEVEL) [LL_##LEVEL] = #LEVEL
static const char * log_level_str[] =
  {
    LL_INIT (ALL),
    LL_INIT (TRACE),
    LL_INIT (DEBUG),
    LL_INIT (INFO),
    LL_INIT (WARN),
    LL_INIT (ERROR),
    LL_INIT (FATAL),
    LL_INIT (OFF),
  };

static log_level_t current_log_level = DEFAULT_LOG_LEVEL;

void
set_log_level (log_level_t log_level)
{
  current_log_level = log_level;
コード例 #9
0
ファイル: ntoh.c プロジェクト: AbrahamJewowich/FreeSWITCH
 * PR_htonll, and PR_ntohll.
 */

#include "prnetdb.h"

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

/* Byte sequence in network byte order */
static unsigned char bytes_n[8] = { 1, 2, 3, 4, 5, 6, 7, 8 };

/* Integers in host byte order */
static PRUint16 s_h = 0x0102;
static PRUint32 l_h = 0x01020304;
static PRUint64 ll_h = LL_INIT(0x01020304, 0x05060708);

int main()
{
    union {
        PRUint16 s;
        PRUint32 l;
        PRUint64 ll;
        unsigned char bytes[8];
    } un;

    un.s = s_h;
    printf("%u %u\n",
        un.bytes[0], un.bytes[1]);
    un.s = PR_htons(un.s);
    printf("%u %u\n",
コード例 #10
0
static void TestLL(void)
{
    static PRInt64 nums[] = {
	LL_INIT(0, 0),
	LL_INIT(0, 1),
	LL_INIT(0xffffffff, 0xffffffff),  /* -1 */
	LL_INIT(0, 10),
	LL_INIT(0xffffffff, 0xfffffff6),  /* -10 */
	LL_INIT(0, 32767),
	LL_INIT(0xffffffff, 0xffff8000),  /* -32768 */
	LL_INIT(0, 0x7fffffff),  /* 2147483647 */
	LL_INIT(0xffffffff, 0x80000000),  /* -2147483648 */
	LL_INIT(0x7fffffff, 0xffffffff),  /* 9223372036854775807 */
	LL_INIT(0x80000000, 0)            /* -9223372036854775808 */
    };

    static char *signs[] = {
	"",
	"0",	"-",	"+", " ",
	"0-",	"0+",	"0 ",	"-0",	"-+",	"- ",
	"+0",	"+-",	"+ ",	" 0",	" -",	" +",
	"0-+",	"0- ",	"0+-",	"0+ ",	"0 -",	"0 +",
	"-0+",	"-0 ",	"-+0",	"-+ ",	"- 0",	"- +",
	"+0-",	"+0 ",	"+-0",	"+- ",	"+ 0",	"+ -",
	" 0-",	" 0+",	" -0",	" -+",	" +0",	" +-",
	"0-+ ",	"0- +",	"0+- ",	"0+ -",	"0 -+",	"0 +-",
	"-0+ ",	"-0 +",	"-+0 ",	"-+ 0",	"- 0+",	"- +0",
	"+0- ",	"+0 -",	"+-0 ",	"+- 0",	"+ 0-",	"+ -0",
	" 0-+",	" 0+-",	" -0+",	" -+0",	" +0-",	" +-0",
    };
    static char *precs[] = {
	"", "3", "5", "43",
	".3", ".43",
	"7.3", "7.5", "7.11", "7.43",
    };
    static char *formats[] = { "lld", "llo", "llx", "llu" };

#if PR_BYTES_PER_LONG == 8
    static char *sformats[] = { "ld", "lo", "lx", "lu" };
#elif defined(WIN16)
    /* Watcom uses the format string "%Ld" instead of "%lld". */
    static char *sformats[] = { "Ld", "Lo", "Lx", "Lu" };
#elif defined(WIN32)
    static char *sformats[] = { "I64d", "I64o", "I64x", "I64u" };
#else
    static char *sformats[] = { "lld", "llo", "llx", "llu" };
#endif

    int f, s, n, p;
    char fmt[40], sfmt[40];

    for (f = 0; f < countof(formats); f++) {
	for (s = 0; s < countof(signs); s++) {
	    for (p = 0; p < countof(precs); p++) {
		fmt[0] = '%';
		fmt[1] = 0;
		if (signs[s]) strcat(fmt, signs[s]);
		if (precs[p]) strcat(fmt, precs[p]);
		strcpy(sfmt, fmt);
		if (formats[f]) strcat(fmt, formats[f]);
		if (sformats[f]) strcat(sfmt, sformats[f]);
		for (n = 0; n < countof(nums); n++) {
		    test_ll(fmt, sfmt, nums[n]);
		}
	    }
	}
    }
}
コード例 #11
0
ファイル: config.c プロジェクト: mmocean/shttpd
/*
 * Initialize shttpd context
 */
static void
initialize_context(struct shttpd_ctx *ctx, const char *config_file,
		int argc, char *argv[], char **tmpvars)
{

	//sizeof(line) = sizeof(char)*FILENAME_MAX;
	
	char			line[FILENAME_MAX], root[FILENAME_MAX],
					var[sizeof(line)], val[sizeof(line)];
	const char		*arg;
	size_t			i;

	//config的数组指针
	const struct opt	*opt;
	FILE 			*fp;

	//时间
	struct tm		*tm;

	//全局变量
	//time(NULL)返回的是整型的偏移量 localtime()是把时间转换成年月日时分秒
	current_time = time(NULL);
	tm = localtime(&current_time);
	tz_offset = 0;
#if 0
	tm->tm_gmtoff - 3600 * (tm->tm_isdst > 0 ? 1 : 0);
#endif

	//ctx是动态分配的
	(void) memset(ctx, 0, sizeof(*ctx));

	ctx->start_time = current_time;

	//unix-like 这是个空的宏定义
	InitializeCriticalSection(&ctx->mutex);

	//初始化核心数据结构的各种双链表头
	//此时各种头应该是0值 并没有实际空间
	LL_INIT(&ctx->connections);
	LL_INIT(&ctx->mime_types);
	LL_INIT(&ctx->registered_uris);
	LL_INIT(&ctx->uri_auths);
	LL_INIT(&ctx->error_handlers);

#if !defined(NO_SSI)
	LL_INIT(&ctx->ssi_funcs);
#endif /* NO_SSI */

	/* First pass: set the defaults */
	//my_strdup 是个字符串的拷贝函数 内部是malloc空间
	//有值的才进行拷贝 opt->def字段
	for (opt = options; opt->sw != 0; opt++)
		if (tmpvars[opt - options] == NULL && opt->def != NULL)
			tmpvars[opt - options] = my_strdup(opt->def);

	/* Second pass: load config file  */
	//  putchar(c); is equivalent to putc(c,stdout).
	//  DBG是个宏 打印到标准输出
	//  有配置文件就读取配置文件,否则读取命令行
	//  config_file默认是个宏 "shttpd.conf"
	//  若没有通过命令行传值 就使用默认的配置文件路径 - 应该和程序处于同一目录
	if (config_file != NULL && (fp = fopen(config_file, "r")) != NULL) {
		DBG(("init_ctx: config file %s", config_file));

		/* Loop through the lines in config file */
		while (fgets(line, sizeof(line), fp) != NULL) {

			/* Skip comments and empty lines */
			if (line[0] == '#' || line[0] == '\n')
				continue;

			/* Trim trailing newline character */
			line[strlen(line) - 1] = '\0';

			//例如:"%[^=]" 读入任意多的字符,直到遇到"="停止
			if (sscanf(line, "%s %[^#\n]", var, val) != 2)
				elog(E_FATAL,0,"init_ctx: bad line: [%s]",line);

			
			//返回最末一个结构体指针或者name匹配的指针
			if ((opt = find_option(0, var)) == NULL)
				elog(E_FATAL, NULL, 
				    "set_option: unknown variable [%s]", var);
			//把default的值去掉,换成文件中的值
			set_option(opt, val, tmpvars);
		}
		(void) fclose(fp);
	}

	/* Third pass: process command line args */
	for (i = 1; i < (size_t) argc && argv[i][0] == '-'; i++)
		if ((opt = find_option(argv[i][1], NULL)) != NULL) {
			arg = argv[i][2] ? &argv[i][2] : argv[++i];
			
			if (arg == NULL)
				usage(argv[0]);

			set_option(opt, arg, tmpvars);
		} else {
			usage(argv[0]);
		}

	/* Call setters functions now */
	//setter 是个函数指针
	// typedef void (*optset_t)(struct shttpd_ctx *, void *ptr, const char *string);
	// void set_str(struct shttpd_ctx *ctx, void *ptr, const char *string)
	// 做一次拷贝,把临时的值拷贝到options数组中
	for (i = 0; i < NELEMS(options); i++)
		if (tmpvars[i] != NULL) {
			options[i].setter(ctx,
			    ((char *) ctx) + options[i].ofs, tmpvars[i]);
			free(tmpvars[i]);
		}

	//默认root目录是程序当前的绝对路径
	/* If document_root is not set, set it to current directory */
	if (ctx->document_root == NULL) {
		//The  getcwd()  function copies an absolute pathname of the current working directory to the array pointed
		//       to by buf, which is of length size.
		(void) my_getcwd(root, sizeof(root));
		ctx->document_root = my_strdup(root);
	}

#ifdef _WIN32
	{WSADATA data;	WSAStartup(MAKEWORD(2,2), &data);}
#endif /* _WIN32 */

	DBG(("init_ctx: initialized context %p", (void *) ctx));
}