Esempio n. 1
0
static void display_cert_info(struct SessionHandle *data,
                              CERTCertificate *cert)
{
  char *subject, *issuer, *common_name;
  PRExplodedTime printableTime;
  char timeString[256];
  PRTime notBefore, notAfter;

  subject = CERT_NameToAscii(&cert->subject);
  issuer = CERT_NameToAscii(&cert->issuer);
  common_name = CERT_GetCommonName(&cert->subject);
  infof(data, "\tsubject: %s\n", subject);

  CERT_GetCertTimes(cert, &notBefore, &notAfter);
  PR_ExplodeTime(notBefore, PR_GMTParameters, &printableTime);
  PR_FormatTime(timeString, 256, "%b %d %H:%M:%S %Y GMT", &printableTime);
  infof(data, "\tstart date: %s\n", timeString);
  PR_ExplodeTime(notAfter, PR_GMTParameters, &printableTime);
  PR_FormatTime(timeString, 256, "%b %d %H:%M:%S %Y GMT", &printableTime);
  infof(data, "\texpire date: %s\n", timeString);
  infof(data, "\tcommon name: %s\n", common_name);
  infof(data, "\tissuer: %s\n", issuer);

  PR_Free(subject);
  PR_Free(issuer);
  PR_Free(common_name);
}
Esempio n. 2
0
int main(int argc, char **argv)
#endif
{
    PRTime ct;
    PRExplodedTime et;
    PRStatus rv;
    char *sp1 = "Sat, 1 Jan 3001 00:00:00";  /* no time zone */
    char *sp2 = "Fri, 31 Dec 3000 23:59:60";  /* no time zone, not normalized */

#if _MSC_VER >= 1400 && !defined(WINCE)
    /* Run this test in the US Pacific Time timezone. */
    _putenv_s("TZ", "PST8PDT");
    _tzset();
#endif

    rv = PR_ParseTimeString(sp1, PR_FALSE, &ct);
    printf("rv = %d\n", rv);
    PR_ExplodeTime(ct, PR_GMTParameters, &et);
    PrintExplodedTime(&et);
    printf("\n");

    rv = PR_ParseTimeString(sp2, PR_FALSE, &ct);
    printf("rv = %d\n", rv);
    PR_ExplodeTime(ct, PR_GMTParameters, &et);
    PrintExplodedTime(&et);
    printf("\n");

    return 0;
}
Esempio n. 3
0
/** Returns a string containing a 11-digit random cookie based upon the
 *  current local time and the elapsed execution of the program.
 * @param aCookie  returned cookie string
 * @return NS_OK on success
 */
NS_IMETHODIMP mozXMLTermUtils::RandomCookie(nsString& aCookie)
{
  // Current local time
  PRExplodedTime localTime;
  PR_ExplodeTime(PR_Now(), PR_LocalTimeParameters, &localTime);

  PRInt32        randomNumberA = localTime.tm_sec*1000000+localTime.tm_usec;
  PRIntervalTime randomNumberB = PR_IntervalNow();

  XMLT_LOG(mozXMLTermUtils::RandomCookie,30,("ranA=0x%x, ranB=0x%x\n",
                                        randomNumberA, randomNumberB));
  PR_ASSERT(randomNumberA >= 0);
  PR_ASSERT(randomNumberB >= 0);

  static const char cookieDigits[17] = "0123456789abcdef";
  char cookie[12];
  int j;

  for (j=0; j<6; j++) {
    cookie[j] = cookieDigits[randomNumberA%16];
    randomNumberA = randomNumberA/16;
  }
  for (j=6; j<11; j++) {
    cookie[j] = cookieDigits[randomNumberB%16];
    randomNumberB = randomNumberB/16;
  }
  cookie[11] = '\0';

  aCookie.AssignASCII(cookie);

  return NS_OK;
}
Esempio n. 4
0
int
sv_PrintTime(FILE *out, SECItem *t, char *m)
{
    PRExplodedTime printableTime;
    PRTime time;
    char *timeString;
    int rv;

    rv = DER_DecodeTimeChoice(&time, t);
    if (rv)
        return rv;

    /* Convert to local time */
    PR_ExplodeTime(time, PR_LocalTimeParameters, &printableTime);

    timeString = (char *)PORT_Alloc(256);

    if (timeString) {
        if (PR_FormatTime(timeString, 256, "%a %b %d %H:%M:%S %Y", &printableTime)) {
            fprintf(out, "%s%s\n", m, timeString);
        }
        PORT_Free(timeString);
        return 0;
    }
    return SECFailure;
}
Esempio n. 5
0
static int
__pmCertificateTimestamp(SECItem *vtime, char *buffer, size_t size)
{
    PRExplodedTime exploded;
    SECStatus secsts;
    int64 itime;

    switch (vtime->type) {
    case siUTCTime:
	secsts = DER_UTCTimeToTime(&itime, vtime);
	break;
    case siGeneralizedTime:
	secsts = DER_GeneralizedTimeToTime(&itime, vtime);
	break;
    default:
	return -EINVAL;
    }
    if (secsts != SECSuccess)
	return __pmSecureSocketsError(PR_GetError());

    /* Convert to local time */
    PR_ExplodeTime(itime, PR_GMTParameters, &exploded);
    if (!PR_FormatTime(buffer, size, "%a %b %d %H:%M:%S %Y", &exploded))
	return __pmSecureSocketsError(PR_GetError());
    return 0;
}
Esempio n. 6
0
void calDateTime::PRTimeToIcaltime(PRTime time, bool isdate,
                                   icaltimezone const* tz,
                                   icaltimetype * icalt)
{
    PRExplodedTime et;
    PR_ExplodeTime(time, PR_GMTParameters, &et);

    icalt->year   = et.tm_year;
    icalt->month  = et.tm_month + 1;
    icalt->day    = et.tm_mday;

    if (isdate) {
        icalt->hour    = 0;
        icalt->minute  = 0;
        icalt->second  = 0;
        icalt->is_date = 1;
    } else {
        icalt->hour   = et.tm_hour;
        icalt->minute = et.tm_min;
        icalt->second = et.tm_sec;
        icalt->is_date = 0;
    }

    icalt->zone = tz;
    icalt->is_utc = ((tz && tz == icaltimezone_get_utc_timezone()) ? 1 : 0);
    icalt->is_daylight = 0;
    // xxx todo: discuss/investigate is_daylight
//     if (tz) {
//         icaltimezone_get_utc_offset(tz, icalt, &icalt->is_daylight);
//     }
}
Esempio n. 7
0
static void PrintTimeString(char *buf, PRUint32 bufsize, PRUint32 t_sec)
{
    PRExplodedTime et;
    PRTime t_usec = SecondsToPRTime(t_sec);
    PR_ExplodeTime(t_usec, PR_LocalTimeParameters, &et);
    PR_FormatTime(buf, bufsize, "%Y-%m-%d %H:%M:%S", &et);
}
Esempio n. 8
0
  void Print(const char* aName, LogLevel aLevel, const char* aFmt, va_list aArgs)
  {
    const size_t kBuffSize = 1024;
    char buff[kBuffSize];

    char* buffToWrite = buff;

    // For backwards compat we need to use the NSPR format string versions
    // of sprintf and friends and then hand off to printf.
    va_list argsCopy;
    va_copy(argsCopy, aArgs);
    size_t charsWritten = PR_vsnprintf(buff, kBuffSize, aFmt, argsCopy);
    va_end(argsCopy);

    if (charsWritten == kBuffSize - 1) {
      // We may have maxed out, allocate a buffer instead.
      buffToWrite = PR_vsmprintf(aFmt, aArgs);
      charsWritten = strlen(buffToWrite);
    }

    // Determine if a newline needs to be appended to the message.
    const char* newline = "";
    if (charsWritten == 0 || buffToWrite[charsWritten - 1] != '\n') {
      newline = "\n";
    }

    FILE* out = mOutFile ? mOutFile : stderr;

    // This differs from the NSPR format in that we do not output the
    // opaque system specific thread pointer (ie pthread_t) cast
    // to a long. The address of the current PR_Thread continues to be
    // prefixed.
    //
    // Additionally we prefix the output with the abbreviated log level
    // and the module name.
    if (!mAddTimestamp) {
      fprintf_stderr(out,
                     "[%p]: %s/%s %s%s",
                     PR_GetCurrentThread(), ToLogStr(aLevel),
                     aName, buffToWrite, newline);
    } else {
      PRExplodedTime now;
      PR_ExplodeTime(PR_Now(), PR_GMTParameters, &now);
      fprintf_stderr(
          out,
          "%04d-%02d-%02d %02d:%02d:%02d.%06d UTC - [%p]: %s/%s %s%s",
          now.tm_year, now.tm_month + 1, now.tm_mday,
          now.tm_hour, now.tm_min, now.tm_sec, now.tm_usec,
          PR_GetCurrentThread(), ToLogStr(aLevel),
          aName, buffToWrite, newline);
    }

    if (mIsSync) {
      fflush(out);
    }

    if (buffToWrite != buff) {
      PR_smprintf_free(buffToWrite);
    }
  }
Esempio n. 9
0
//Framework logging - always log
void aptCoreTrace::LogF(eLogLevel eLevel, const char* str, const char* from)
{
    if (!mCanLog) return;
    size_t nlen = strlen(str) + 100;
    char *msg = new char[nlen];

    if (!msg)
    {
        // no memory
        return;
    }

    PRTime curTime = PR_Now();
	PRExplodedTime localTime;
	PR_ExplodeTime(curTime, PR_LocalTimeParameters, &localTime);

	PRUint32 nWritten = PR_snprintf(msg, nlen,
			"%02d:%02d:%02d %02d/%02d/%04d [%6d] [%s] [%s] %s%s", // XXX i18n!
			localTime.tm_hour, localTime.tm_min, localTime.tm_sec,
			localTime.tm_month+1, localTime.tm_mday, localTime.tm_year,
			mPid, gsLogLevel[eLevel], from, str,
#ifdef _WIN32
   
            "\r\n"
#else
            "\n"
#endif
            );
   
    mLC->WriteNewedLog(msg, nWritten);
}
Esempio n. 10
0
/*
 * Log url access audit message to local audit log file.
 *
 */
void Log::doLocalAuditLog(ModuleId module,
        Level level,
        const char* auditLogMsg,
        bool localAuditLogRotate,
        long localAuditFileSize)
throw () {
    if (initialized) {

        // get time.
        PRExplodedTime now;
        PR_ExplodeTime(PR_Now(), PR_LocalTimeParameters, &now);

        // format header and msg.
        PRUint32 len;
        char hdr[100];
        len = PR_snprintf(hdr, sizeof (hdr),
                "%d-%02d-%02d %02d:%02d:%02d.%03d"
                "%8s %u:%p %s: %%s\n",
                now.tm_year, now.tm_month + 1, now.tm_mday,
                now.tm_hour, now.tm_min, now.tm_sec,
                now.tm_usec / 1000,
                "Info",
                getpid(), PR_GetCurrentThread(),
                "LocalAuditLog");
        if (len > 0) {

            if (localAuditLogRotate) {
                if ((currentAuditLogFileSize + 1000) < 
                        localAuditFileSize) {
                    std::fprintf(auditLogFile, hdr, auditLogMsg);
                    std::fflush(auditLogFile);
                } else {
                    ScopeLock scopeLock(*lockPtr);
                    currentAuditLogFileSize = ftell(auditLogFile);
                    if ((currentAuditLogFileSize + 1000) > 
                            localAuditFileSize) {
                        // Open a new log file
                        if (!setAuditLogFile(auditLogFileName,
                                              localAuditLogRotate,
                                              localAuditFileSize)) {
                            log(ALL_MODULES, LOG_ERROR,
                                    "Unable to open audit log file: "
                                    "'%s', errno = %d",
                                    auditLogFileName.c_str(), errno);
                        }
                    }
                    std::fprintf(auditLogFile, hdr, auditLogMsg);
                    std::fflush(auditLogFile);
                }
                currentAuditLogFileSize = ftell(auditLogFile);
            } else {
                std::fprintf(auditLogFile, hdr, auditLogMsg);
                std::fflush(auditLogFile);
            }
        }
    }

    return;
}
Esempio n. 11
0
void xptiAutoLog::WriteTimestamp(PRFileDesc* fd, const char* msg)
{
    PRExplodedTime expTime;
    PR_ExplodeTime(PR_Now(), PR_LocalTimeParameters, &expTime);
    char time[128];
    PR_FormatTimeUSEnglish(time, 128, "%Y-%m-%d-%H:%M:%S", &expTime);
    PR_fprintf(fd, "\n%s %s\n\n", msg, time);
}
Esempio n. 12
0
NS_IMETHODIMP nsDiskinfo::AddCleanupItem(PRUint32 key, PRTime date) {
  msg_hdr_t *hdr = g_new0(msg_hdr_t, 1);
  hdr->key = key;
  PR_ExplodeTime(date, PR_GMTParameters, &(hdr->date));
  this->m_MsgList = g_slist_append(this->m_MsgList, hdr);

  return NS_OK;
}
Esempio n. 13
0
/****************************************************************
 *
 * J z i p O p e n
 *
 * Opens a new ZIP file and creates a new ZIPfile structure to
 * control the process of installing files into a zip.
 */
ZIPfile *
JzipOpen(char *filename, char *comment)
{
    ZIPfile *zipfile;
    PRExplodedTime prtime;

    zipfile = PORT_ZAlloc(sizeof(ZIPfile));
    if (!zipfile)
        out_of_memory();

    /* Construct time and date */
    PR_ExplodeTime(PR_Now(), PR_LocalTimeParameters, &prtime);
    zipfile->date = ((prtime.tm_year - 1980) << 9) |
                    ((prtime.tm_month + 1) << 5) |
                    prtime.tm_mday;
    zipfile->time = (prtime.tm_hour << 11) |
                    (prtime.tm_min << 5) |
                    (prtime.tm_sec & 0x3f);

    zipfile->fp = NULL;
    if (filename &&
        (zipfile->fp = PR_Open(filename,
                               PR_WRONLY |
                                   PR_CREATE_FILE |
                                   PR_TRUNCATE,
                               0777)) == NULL) {
        char *nsprErr;
        if (PR_GetErrorTextLength()) {
            nsprErr = PR_Malloc(PR_GetErrorTextLength() + 1);
            PR_GetErrorText(nsprErr);
        } else {
            nsprErr = NULL;
        }
        PR_fprintf(errorFD, "%s: can't open output jar, %s.%s\n",
                   PROGRAM_NAME,
                   filename, nsprErr ? nsprErr : "");
        if (nsprErr)
            PR_Free(nsprErr);
        errorCount++;
        exit(ERRX);
    }

    zipfile->list = NULL;
    if (filename) {
        zipfile->filename = PORT_ZAlloc(strlen(filename) + 1);
        if (!zipfile->filename)
            out_of_memory();
        PORT_Strcpy(zipfile->filename, filename);
    }
    if (comment) {
        zipfile->comment = PORT_ZAlloc(strlen(comment) + 1);
        if (!zipfile->comment)
            out_of_memory();
        PORT_Strcpy(zipfile->comment, comment);
    }

    return zipfile;
}
Esempio n. 14
0
static void display_conn_info(struct connectdata *conn, PRFileDesc *sock)
{
  SSLChannelInfo channel;
  SSLCipherSuiteInfo suite;
  CERTCertificate *cert;
  char *subject, *issuer, *common_name;
  PRExplodedTime printableTime;
  char timeString[256];
  PRTime notBefore, notAfter;

  if(SSL_GetChannelInfo(sock, &channel, sizeof channel) ==
     SECSuccess && channel.length == sizeof channel &&
     channel.cipherSuite) {
    if(SSL_GetCipherSuiteInfo(channel.cipherSuite,
                              &suite, sizeof suite) == SECSuccess) {
      infof(conn->data, "SSL connection using %s\n", suite.cipherSuiteName);
    }
  }

  infof(conn->data, "Server certificate:\n");

  cert = SSL_PeerCertificate(sock);
  subject = CERT_NameToAscii(&cert->subject);
  issuer = CERT_NameToAscii(&cert->issuer);
  common_name = CERT_GetCommonName(&cert->subject);
  infof(conn->data, "\tsubject: %s\n", subject);

  CERT_GetCertTimes(cert, &notBefore, &notAfter);
  PR_ExplodeTime(notBefore, PR_GMTParameters, &printableTime);
  PR_FormatTime(timeString, 256, "%b %d %H:%M:%S %Y GMT", &printableTime);
  infof(conn->data, "\tstart date: %s\n", timeString);
  PR_ExplodeTime(notAfter, PR_GMTParameters, &printableTime);
  PR_FormatTime(timeString, 256, "%b %d %H:%M:%S %Y GMT", &printableTime);
  infof(conn->data, "\texpire date: %s\n", timeString);
  infof(conn->data, "\tcommon name: %s\n", common_name);
  infof(conn->data, "\tissuer: %s\n", issuer);

  PR_Free(subject);
  PR_Free(issuer);
  PR_Free(common_name);

  CERT_DestroyCertificate(cert);

  return;
}
Esempio n. 15
0
static void
testParseTimeString(PRTime t)
{
    PRExplodedTime et;
    PRTime t2;
    char timeString[128];
    char buf[128];
    PRInt32 totalOffset;
    PRInt32 hourOffset, minOffset;
    const char *sign;
    PRInt64 usec_per_sec;

    /* Truncate the microsecond part of PRTime */
    LL_I2L(usec_per_sec, PR_USEC_PER_SEC);
    LL_DIV(t, t, usec_per_sec);
    LL_MUL(t, t, usec_per_sec);

    PR_ExplodeTime(t, PR_LocalTimeParameters, &et);

    /* Print day of the week, month, day, hour, minute, and second */
    PR_snprintf(timeString, 128, "%s %s %ld %02ld:%02ld:%02ld ",
	    dayOfWeek[et.tm_wday], month[et.tm_month], et.tm_mday,
	    et.tm_hour, et.tm_min, et.tm_sec);
    /* Print time zone */
    totalOffset = et.tm_params.tp_gmt_offset + et.tm_params.tp_dst_offset;
    if (totalOffset == 0) {
	strcat(timeString, "GMT ");  /* I wanted to use "UTC" here, but
                                      * PR_ParseTimeString doesn't 
                                      * understand "UTC".  */
    } else {
        sign = "+";
        if (totalOffset < 0) {
	    totalOffset = -totalOffset;
	    sign = "-";
        }
        hourOffset = totalOffset / 3600;
        minOffset = (totalOffset % 3600) / 60;
        PR_snprintf(buf, 128, "%s%02ld%02ld ", sign, hourOffset, minOffset);
	strcat(timeString, buf);
    }
    /* Print year */
    PR_snprintf(buf, 128, "%hd", et.tm_year);
    strcat(timeString, buf);

    if (PR_ParseTimeString(timeString, PR_FALSE, &t2) == PR_FAILURE) {
	fprintf(stderr, "PR_ParseTimeString() failed\n");
	exit(1);
    }
    if (LL_NE(t, t2)) {
	fprintf(stderr, "PR_ParseTimeString() incorrect\n");
	PR_snprintf(buf, 128, "t is %lld, t2 is %lld, time string is %s\n",
                t, t2, timeString);
	fprintf(stderr, "%s\n", buf);
	exit(1);
    }
}
Esempio n. 16
0
NS_IMETHODIMP
jxMySQL50Statement::BindDatetimeParameter(PRUint32 aParamIndex, PRUint32 aSecond)
{
    if (mConnection == nsnull)
    {
        SET_ERROR_RETURN (JX_MYSQL50_ERROR_NOT_CONNECTED);
    }

    if (mSTMT == nsnull)
    {
        SET_ERROR_RETURN (JX_MYSQL50_ERROR_STMT_NULL);
    }

    if (aParamIndex < 0 || aParamIndex >= mIn.mCount)
    {
        SET_ERROR_RETURN (JX_MYSQL50_ERROR_ILLEGAL_VALUE);
    }
    

    if (mIn.mBindArrayBufferTYPE_DATE[aParamIndex] == nsnull)
        mIn.mBindArrayBufferTYPE_DATE[aParamIndex] = static_cast<MYSQL_TIME*>(nsMemory::Alloc(sizeof(MYSQL_TIME)));
    if (mIn.mBindArrayBufferTYPE_DATE[aParamIndex] == nsnull)
    {
        SET_ERROR_RETURN (JX_MYSQL50_ERROR_OUT_OF_MEMORY);
    }

    time_t t = (time_t) aSecond;
    struct tm *tmptm = gmtime(&t);
    // struct tm *tmpltm = localtime(&t);

#if 0
    PRTime t = aSecond * 1000;
    PRExplodedTime prtime;
    PR_ExplodeTime(t, PR_LocalTimeParameters, &prtime);
#endif

    MYSQL_TIME*  mysqlTime = mIn.mBindArrayBufferTYPE_DATE[aParamIndex];
	mysqlTime->year 		= tmptm->tm_year + 1900;
	mysqlTime->month 		= tmptm->tm_mon + 1;
	mysqlTime->day 			= tmptm->tm_mday;
	mysqlTime->hour 		= tmptm->tm_hour;
	mysqlTime->minute 		= tmptm->tm_min;
	mysqlTime->second 		= tmptm->tm_sec;
	mysqlTime->second_part 	= 0;	/* mic's not supported in MySQL yet */
	mysqlTime->neg 			= 0;
	mysqlTime->time_type 	= MYSQL_TIMESTAMP_DATETIME;

	mIn.mBIND[aParamIndex].buffer_type = MYSQL_TYPE_DATETIME;
	mIn.mBIND[aParamIndex].buffer 	 = mIn.mBindArrayBufferTYPE_DATE[aParamIndex];
	mIn.mBIND[aParamIndex].length 	 = 0;
	mIn.mBIND[aParamIndex].length_value 	 = lenOfMySQL_TIME;
	mIn.mBIND[aParamIndex].buffer_length = lenOfMySQL_TIME;

    return NS_OK;
}
Esempio n. 17
0
// performs a locale sensitive date formatting operation on the PRTime parameter
/*static*/ nsresult
DateTimeFormat::FormatPRTime(const nsDateFormatSelector aDateFormatSelector,
                             const nsTimeFormatSelector aTimeFormatSelector,
                             const PRTime aPrTime,
                             nsAString& aStringOut)
{
  PRExplodedTime explodedTime;
  PR_ExplodeTime(aPrTime, PR_LocalTimeParameters, &explodedTime);

  return FormatPRExplodedTime(aDateFormatSelector, aTimeFormatSelector, &explodedTime, aStringOut);
}
static void TimeOfDayMessage(const char *msg, PRThread* me)
{
    char buffer[100];
    PRExplodedTime tod;
    PR_ExplodeTime(PR_Now(), PR_LocalTimeParameters, &tod);
    (void)PR_FormatTime(buffer, sizeof(buffer), "%H:%M:%S", &tod);

    TEST_LOG(
        cltsrv_log_file, TEST_LOG_ALWAYS,
        ("%s(0x%p): %s\n", msg, me, buffer));
}  /* TimeOfDayMessage */
Esempio n. 19
0
// performs a locale sensitive date formatting operation on the PRTime parameter
nsresult nsDateTimeFormatMac::FormatPRTime(nsILocale* locale, 
                                           const nsDateFormatSelector  dateFormatSelector, 
                                           const nsTimeFormatSelector timeFormatSelector, 
                                           const PRTime  prTime, 
                                           nsAString& stringOut)
{
  PRExplodedTime explodedTime;
  PR_ExplodeTime(prTime, PR_LocalTimeParameters, &explodedTime);

  return FormatPRExplodedTime(locale, dateFormatSelector, timeFormatSelector, &explodedTime, stringOut);
}
Esempio n. 20
0
void 
nsCertTree::CmpInitCriterion(nsIX509Cert *cert, CompareCacheHashEntry *entry,
                             sortCriterion crit, PRInt32 level)
{
  NS_ENSURE_TRUE( (cert!=0 && entry!=0), RETURN_NOTHING );

  entry->mCritInit[level] = true;
  nsXPIDLString &str = entry->mCrit[level];
  
  switch (crit) {
    case sort_IssuerOrg:
      cert->GetIssuerOrganization(str);
      if (str.IsEmpty())
        cert->GetCommonName(str);
      break;
    case sort_Org:
      cert->GetOrganization(str);
      break;
    case sort_Token:
      cert->GetTokenName(str);
      break;
    case sort_CommonName:
      cert->GetCommonName(str);
      break;
    case sort_IssuedDateDescending:
      {
        nsresult rv;
        nsCOMPtr<nsIX509CertValidity> validity;
        PRTime notBefore;

        rv = cert->GetValidity(getter_AddRefs(validity));
        if (NS_SUCCEEDED(rv)) {
          rv = validity->GetNotBefore(&notBefore);
        }

        if (NS_SUCCEEDED(rv)) {
          PRExplodedTime explodedTime;
          PR_ExplodeTime(notBefore, PR_GMTParameters, &explodedTime);
          char datebuf[20]; // 4 + 2 + 2 + 2 + 2 + 2 + 1 = 15
          if (0 != PR_FormatTime(datebuf, sizeof(datebuf), "%Y%m%d%H%M%S", &explodedTime)) {
            str = NS_ConvertASCIItoUTF16(nsDependentCString(datebuf));
          }
        }
      }
      break;
    case sort_Email:
      cert->GetEmailAddress(str);
      break;
    case sort_None:
    default:
      break;
  }
}
void nsOEAddressIterator::SetBirthDay(nsIMdbRow *newRow, PRTime& birthDay)
{
  PRExplodedTime exploded;
  PR_ExplodeTime(birthDay, PR_LocalTimeParameters, &exploded);

  char stringValue[5];
  PR_snprintf(stringValue, sizeof(stringValue), "%04d", exploded.tm_year);
  m_database->AddBirthYear(newRow, stringValue);
  PR_snprintf(stringValue, sizeof(stringValue), "%02d", exploded.tm_month + 1);
  m_database->AddBirthMonth(newRow, stringValue);
  PR_snprintf(stringValue, sizeof(stringValue), "%02d", exploded.tm_mday);
  m_database->AddBirthDay(newRow, stringValue);
}
Esempio n. 22
0
std::string
CommandEventHandler::systime()
{
  PRTime now = PR_Now();
  PRExplodedTime ts;
  PR_ExplodeTime(now, PR_LocalTimeParameters, &ts);

  char buffer[BUFSIZE];
  sprintf(buffer, "%d/%02d/%02d %02d:%02d:%02d:%03d", ts.tm_year, ts.tm_month,
    ts.tm_mday, ts.tm_hour, ts.tm_min, ts.tm_sec, ts.tm_usec / 1000);

  return std::string(buffer);
}
Esempio n. 23
0
PRInt32
AlarmHalService::GetTimezoneOffset(bool aIgnoreDST)
{
  PRExplodedTime prTime;
  PR_ExplodeTime(PR_Now(), PR_LocalTimeParameters, &prTime);

  PRInt32 offset = prTime.tm_params.tp_gmt_offset;
  if (!aIgnoreDST) {
    offset += prTime.tm_params.tp_dst_offset;
  }

  return -(offset / 60);
}
Esempio n. 24
0
nsresult
nsX509CertValidity::FormatTime(const PRTime& aTimeDate,
                               PRTimeParamFn aParamFn,
                               const nsTimeFormatSelector aTimeFormatSelector,
                               nsAString& aFormattedTimeDate)
{
  if (!mTimesInitialized)
    return NS_ERROR_FAILURE;

  PRExplodedTime explodedTime;
  PR_ExplodeTime(const_cast<PRTime&>(aTimeDate), aParamFn, &explodedTime);
  return mozilla::DateTimeFormat::FormatPRExplodedTime(kDateFormatLong,
                                                       aTimeFormatSelector,
                                                       &explodedTime, aFormattedTimeDate);
}
Esempio n. 25
0
int main()
{
    char buffer[256];
    PRTime now;
    PRExplodedTime tod;

    now = PR_Now();
    PR_ExplodeTime(now, PR_LocalTimeParameters, &tod);
    (void)PR_FormatTime(buffer, sizeof(buffer),
                        "%a %b %d %H:%M:%S %Z %Y", &tod);
    printf("%s\n", buffer);
    (void)PR_FormatTimeUSEnglish(buffer, sizeof(buffer),
                                 "%a %b %d %H:%M:%S %Z %Y", &tod);
    printf("%s\n", buffer);
    return 0;
}
Esempio n. 26
0
void aptCoreTrace::LogBytes(eLogLevel eLevel, const char* data, size_t len)
{
    // Extra spaces for Date, PID, EOL etc
#ifdef _WIN32
    static const int nEXTRA = 34;
#else
    static const int nEXTRA = 33;
#endif
    if (!mCanLog) return;

    if (eLevel < mCoreLogLevel) return;
    
	PRTime curTime = PR_Now();
	PRExplodedTime localTime;
	PR_ExplodeTime(curTime, PR_LocalTimeParameters, &localTime);
    int nTotal = len + nEXTRA + strlen(gsLogLevel[eLevel]);

    char *buf = new char[nTotal];
    if (!buf) return;

    PRUint32 nWritten = PR_snprintf(buf, nTotal,
			"%02d:%02d:%02d %02d/%02d/%04d [%6d] [%s] ", // XXX i18n!
			localTime.tm_hour, localTime.tm_min, localTime.tm_sec,
			localTime.tm_month+1, localTime.tm_mday, localTime.tm_year,
			mPid, gsLogLevel[eLevel]);


    memcpy(buf+nWritten, data, len);

    nWritten += len;

#ifdef _WIN32
    buf[nWritten++] = '\r';
#endif
    buf[nWritten++] = '\n';
    
#ifdef _DEBUG
    if (nWritten != nTotal)
    {
        char tmp[50];
        sprintf(tmp, "nW=%d nT=%d\n", nWritten, nTotal);
        mLC->WriteLog(tmp, strlen(tmp));
    }
#endif

    mLC->WriteNewedLog(buf, nWritten);
}
Esempio n. 27
0
/* 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;
    }

    dst->len = 13;
    if (arenaOpt) {
        dst->data = d = (unsigned char*) PORT_ArenaAlloc(arenaOpt, dst->len);
    } else {
        dst->data = d = (unsigned char*) PORT_Alloc(dst->len);
    }
    dst->type = siUTCTime;
    if (!d) {
	return SECFailure;
    }

    /* Convert an int64 time to a printable format.  */
    PR_ExplodeTime(gmttime, PR_GMTParameters, &printableTime);

    /* The month in UTC time is base one */
    printableTime.tm_month++;

    /* remove the century since it's added to the tm_year by the 
       PR_ExplodeTime routine, but is not needed for UTC time */
    printableTime.tm_year %= 100; 

    d[0] = HIDIGIT(printableTime.tm_year);
    d[1] = LODIGIT(printableTime.tm_year);
    d[2] = HIDIGIT(printableTime.tm_month);
    d[3] = LODIGIT(printableTime.tm_month);
    d[4] = HIDIGIT(printableTime.tm_mday);
    d[5] = LODIGIT(printableTime.tm_mday);
    d[6] = HIDIGIT(printableTime.tm_hour);
    d[7] = LODIGIT(printableTime.tm_hour);
    d[8] = HIDIGIT(printableTime.tm_min);
    d[9] = LODIGIT(printableTime.tm_min);
    d[10] = HIDIGIT(printableTime.tm_sec);
    d[11] = LODIGIT(printableTime.tm_sec);
    d[12] = 'Z';
    return SECSuccess;
}
Esempio n. 28
0
NS_IMETHODIMP nsX509CertValidity::GetNotAfterLocalDay(nsAString &aNotAfterLocalDay)
{
  if (!mTimesInitialized)
    return NS_ERROR_FAILURE;

  nsresult rv;
  nsCOMPtr<nsIDateTimeFormat> dateFormatter =
     do_CreateInstance(NS_DATETIMEFORMAT_CONTRACTID, &rv);
  if (NS_FAILED(rv)) return rv;

  nsAutoString date;
  PRExplodedTime explodedTime;
  PR_ExplodeTime(mNotAfter, PR_LocalTimeParameters, &explodedTime);
  dateFormatter->FormatPRExplodedTime(nsnull, kDateFormatShort, kTimeFormatNone,
                                      &explodedTime, date);
  aNotAfterLocalDay = date;
  return NS_OK;
}
Esempio n. 29
0
NS_IMETHODIMP nsX509CertValidity::GetNotBeforeGMT(nsAString &aNotBeforeGMT)
{
  if (!mTimesInitialized)
    return NS_ERROR_FAILURE;

  nsresult rv;
  nsCOMPtr<nsIDateTimeFormat> dateFormatter =
     do_CreateInstance(NS_DATETIMEFORMAT_CONTRACTID, &rv);
  if (NS_FAILED(rv)) return rv;

  nsAutoString date;
  PRExplodedTime explodedTime;
  PR_ExplodeTime(mNotBefore, PR_GMTParameters, &explodedTime);
  dateFormatter->FormatPRExplodedTime(nullptr, kDateFormatShort, kTimeFormatSecondsForce24Hour,
                                      &explodedTime, date);
  aNotBeforeGMT = date;
  return NS_OK;
}
Esempio n. 30
0
/*
   gmttime must contains UTC time in micro-seconds unit.
   Note: the caller should make sure that Generalized time
   should only be used for certifiate validities after the
   year 2049.  Otherwise, UTC time should be used.  This routine
   does not check this case, since it can be used to encode
   certificate extension, which does not have this restriction. 
 */
SECStatus
DER_TimeToGeneralizedTimeArena(PRArenaPool* arenaOpt, SECItem *dst, int64 gmttime)
{
    PRExplodedTime printableTime;
    unsigned char *d;

    if ( (gmttime<January1st1) || (gmttime>=January1st10000) ) {
        PORT_SetError(SEC_ERROR_INVALID_ARGS);
        return SECFailure;
    }
    dst->len = 15;
    if (arenaOpt) {
        dst->data = d = (unsigned char*) PORT_ArenaAlloc(arenaOpt, dst->len);
    } else {
        dst->data = d = (unsigned char*) PORT_Alloc(dst->len);
    }
    dst->type = siGeneralizedTime;
    if (!d) {
	return SECFailure;
    }

    /* Convert an int64 time to a printable format.  */
    PR_ExplodeTime(gmttime, PR_GMTParameters, &printableTime);

    /* The month in Generalized time is base one */
    printableTime.tm_month++;

    d[0] = (printableTime.tm_year /1000) + '0';
    d[1] = ((printableTime.tm_year % 1000) / 100) + '0';
    d[2] = ((printableTime.tm_year % 100) / 10) + '0';
    d[3] = (printableTime.tm_year % 10) + '0';
    d[4] = HIDIGIT(printableTime.tm_month);
    d[5] = LODIGIT(printableTime.tm_month);
    d[6] = HIDIGIT(printableTime.tm_mday);
    d[7] = LODIGIT(printableTime.tm_mday);
    d[8] = HIDIGIT(printableTime.tm_hour);
    d[9] = LODIGIT(printableTime.tm_hour);
    d[10] = HIDIGIT(printableTime.tm_min);
    d[11] = LODIGIT(printableTime.tm_min);
    d[12] = HIDIGIT(printableTime.tm_sec);
    d[13] = LODIGIT(printableTime.tm_sec);
    d[14] = 'Z';
    return SECSuccess;
}