Cleanup of the time macros in asn.c to allow expanded use of wolf "struct tm", "time_t" and "gmtime". Cleanup of the io.c socket includes for clarity. Cleanup trailing spaces in io.c and asn.c.

This commit is contained in:
David Garske
2016-01-26 13:47:01 -08:00
parent 02397623be
commit 5c4a3462ee
2 changed files with 102 additions and 122 deletions

View File

@@ -86,8 +86,13 @@
#include <unistd.h> #include <unistd.h>
#endif #endif
#include <fcntl.h> #include <fcntl.h>
#if !(defined(DEVKITPRO) || defined(HAVE_RTP_SYS) || defined(EBSNET)) \
&& !(defined(WOLFSSL_PICOTCP)) #if defined(HAVE_RTP_SYS)
#include <socket.h>
#elif defined(EBSNET)
#include "rtipapi.h" /* errno */
#include "socket.h"
#elif !defined(DEVKITPRO) && !defined(WOLFSSL_PICOTCP)
#include <sys/socket.h> #include <sys/socket.h>
#include <arpa/inet.h> #include <arpa/inet.h>
#include <netinet/in.h> #include <netinet/in.h>
@@ -98,13 +103,6 @@
#include <sys/ioctl.h> #include <sys/ioctl.h>
#endif #endif
#endif #endif
#ifdef HAVE_RTP_SYS
#include <socket.h>
#endif
#ifdef EBSNET
#include "rtipapi.h" /* errno */
#include "socket.h"
#endif
#endif #endif
#endif /* USE_WINDOWS_API */ #endif /* USE_WINDOWS_API */

View File

@@ -95,62 +95,44 @@
#endif #endif
#ifdef HAVE_RTP_SYS #if defined(HAVE_RTP_SYS)
/* uses parital <time.h> structures */ /* uses parital <time.h> structures */
#define XTIME(tl) (0) #define XTIME(tl) (0)
#define XGMTIME(c, t) my_gmtime((c)) #define XGMTIME(c, t) rtpsys_gmtime((c))
#define XVALIDATE_DATE(d, f, t) ValidateDate((d), (f), (t))
#elif defined(MICRIUM) #elif defined(MICRIUM)
#if (NET_SECURE_MGR_CFG_EN == DEF_ENABLED) #if (NET_SECURE_MGR_CFG_EN == DEF_ENABLED)
#define XVALIDATE_DATE(d,f,t) NetSecure_ValidateDateHandler((d),(f),(t)) #define XVALIDATE_DATE(d, f, t) NetSecure_ValidateDateHandler((d), (f), (t))
#else #else
#define XVALIDATE_DATE(d, f, t) (0) #define XVALIDATE_DATE(d, f, t) (0)
#endif #endif
#define NO_TIME_H #define NO_TIME_H
/* since Micrium not defining XTIME or XGMTIME, CERT_GEN not available */ /* since Micrium not defining XTIME or XGMTIME, CERT_GEN not available */
#elif defined(MICROCHIP_TCPIP_V5) || defined(MICROCHIP_TCPIP) #elif defined(MICROCHIP_TCPIP_V5) || defined(MICROCHIP_TCPIP)
#include <time.h> #include <time.h>
#define XTIME(t1) pic32_time((t1)) #define XTIME(t1) pic32_time((t1))
#define XGMTIME(c, t) gmtime((c))
#define XVALIDATE_DATE(d, f, t) ValidateDate((d), (f), (t))
#elif defined(FREESCALE_MQX) || defined(FREESCALE_KSDK_MQX) #elif defined(FREESCALE_MQX) || defined(FREESCALE_KSDK_MQX)
#define XTIME(t1) mqx_time((t1)) #define XTIME(t1) mqx_time((t1))
#define XGMTIME(c, t) mqx_gmtime((c), (t)) #define HAVE_GMTIME_R
#define XVALIDATE_DATE(d, f, t) ValidateDate((d), (f), (t))
#elif defined(FREESCALE_KSDK_BM) || defined(FREESCALE_FREE_RTOS) #elif defined(FREESCALE_KSDK_BM) || defined(FREESCALE_FREE_RTOS)
#include <time.h> #include <time.h>
#define XTIME(t1) ksdk_time((t1)) #define XTIME(t1) ksdk_time((t1))
#define XGMTIME(c, t) gmtime((c))
#define XVALIDATE_DATE(d, f, t) ValidateDate((d), (f), (t))
#elif defined(USER_TIME) #elif defined(USER_TIME)
/* user time, and gmtime compatible functions, there is a gmtime /* user time, and gmtime compatible functions, there is a gmtime
implementation here that WINCE uses, so really just need some ticks implementation here that WINCE uses, so really just need some ticks
since the EPOCH since the EPOCH
*/ */
#define WOLFSSL_GMTIME
struct tm { #define USE_WOLF_TM
int tm_sec; /* seconds after the minute [0-60] */ #define USE_WOLF_TIME_T
int tm_min; /* minutes after the hour [0-59] */
int tm_hour; /* hours since midnight [0-23] */
int tm_mday; /* day of the month [1-31] */
int tm_mon; /* months since January [0-11] */
int tm_year; /* years since 1900 */
int tm_wday; /* days since Sunday [0-6] */
int tm_yday; /* days since January 1 [0-365] */
int tm_isdst; /* Daylight Savings Time flag */
long tm_gmtoff; /* offset from CUT in seconds */
char *tm_zone; /* timezone abbreviation */
};
typedef long time_t;
/* forward declaration */ /* forward declaration */
struct tm* gmtime(const time_t* timer);
extern time_t XTIME(time_t * timer); extern time_t XTIME(time_t * timer);
#define XGMTIME(c, t) gmtime((c))
#define XVALIDATE_DATE(d, f, t) ValidateDate((d), (f), (t))
#ifdef STACK_TRAP #ifdef STACK_TRAP
/* for stack trap tracking, don't call os gmtime on OS X/linux, /* for stack trap tracking, don't call os gmtime on OS X/linux,
uses a lot of stack spce */ uses a lot of stack spce */
@@ -160,13 +142,54 @@
#elif defined(TIME_OVERRIDES) #elif defined(TIME_OVERRIDES)
/* user would like to override time() and gmtime() functionality */ /* user would like to override time() and gmtime() functionality */
#ifndef HAVE_TIME_T_TYPE #ifndef HAVE_TIME_T_TYPE
typedef long time_t; #define USE_WOLF_TIME_T
#endif #endif
extern time_t XTIME(time_t * timer);
#ifndef HAVE_TM_TYPE #ifndef HAVE_TM_TYPE
#define USE_WOLF_TM
#endif
/* forward declarations */
extern time_t XTIME(time_t * timer);
extern struct tm* XGMTIME(const time_t* timer, struct tm* tmp);
#define NEED_TMP_TIME
#elif defined(IDIRECT_DEV_TIME)
/*Gets the timestamp from cloak software owned by VT iDirect
in place of time() from <time.h> */
#include <time.h>
#define XTIME(t1) idirect_time((t1))
#elif defined(_WIN32_WCE)
#include <windows.h>
#define XTIME(t1) windows_time((t1))
#define WOLFSSL_GMTIME
#else
/* default */
/* uses complete <time.h> facility */
#include <time.h>
#endif
/* Map default time functions */
#if !defined(XTIME) && !defined(TIME_OVERRIDES) && !defined(USER_TIME)
#define XTIME(tl) time((tl))
#endif
#if !defined(XGMTIME) && !defined(TIME_OVERRIDES)
#ifdef HAVE_GMTIME_R
#define XGMTIME(c, t) gmtime_r((c), (t))
#define NEED_TMP_TIME
#else
#define XGMTIME(c, t) gmtime((c))
#endif
#endif
#if !defined(XVALIDATE_DATE) && !defined(HAVE_VALIDATE_DATE)
#define USE_WOLF_VALIDDATE
#define XVALIDATE_DATE(d, f, t) ValidateDate((d), (f), (t))
#endif
#if defined(USE_WOLF_TM)
struct tm { struct tm {
int tm_sec; /* seconds after the minute [0-60] */ int tm_sec; /* seconds after the minute [0-60] */
int tm_min; /* minutes after the hour [0-59] */ int tm_min; /* minutes after the hour [0-59] */
@@ -180,43 +203,14 @@
long tm_gmtoff; /* offset from CUT in seconds */ long tm_gmtoff; /* offset from CUT in seconds */
char *tm_zone; /* timezone abbreviation */ char *tm_zone; /* timezone abbreviation */
}; };
#endif #endif /* USE_WOLF_TM */
extern struct tm* XGMTIME(const time_t* timer, struct tm* tmp); #if defined(USE_WOLF_TIME_T)
typedef long time_t;
#ifndef HAVE_VALIDATE_DATE
#define XVALIDATE_DATE(d, f, t) ValidateDate((d), (f), (t))
#endif
#elif defined(IDIRECT_DEV_TIME)
/*Gets the timestamp from cloak software owned by VT iDirect
in place of time() from <time.h> */
#include <time.h>
#define XTIME(t1) idirect_time((t1))
#define XGMTIME(c) gmtime((c))
#define XVALIDATE_DATE(d, f, t) ValidateDate((d), (f), (t))
#else
/* default */
/* uses complete <time.h> facility */
#include <time.h>
#define XTIME(tl) time((tl))
#ifdef HAVE_GMTIME_R
#define XGMTIME(c, t) gmtime_r((c), (t))
#define NEED_TMP_TIME
#else
#define XGMTIME(c, t) gmtime((c))
#endif
#define XVALIDATE_DATE(d, f, t) ValidateDate((d), (f), (t))
#endif #endif
#ifdef _WIN32_WCE #if defined(_WIN32_WCE)
/* no time() or gmtime() even though in time.h header?? */ time_t windows_time(time_t* timer)
#include <windows.h>
time_t time(time_t* timer)
{ {
SYSTEMTIME sysTime; SYSTEMTIME sysTime;
FILETIME fTime; FILETIME fTime;
@@ -238,10 +232,9 @@ time_t time(time_t* timer)
return *timer; return *timer;
} }
#endif /* _WIN32_WCE */ #endif /* _WIN32_WCE */
#if defined( _WIN32_WCE ) || defined( USER_TIME )
#if defined(WOLFSSL_GMTIME)
struct tm* gmtime(const time_t* timer) struct tm* gmtime(const time_t* timer)
{ {
#define YEAR0 1900 #define YEAR0 1900
@@ -289,15 +282,13 @@ struct tm* gmtime(const time_t* timer)
return ret; return ret;
} }
#endif /* WOLFSSL_GMTIME */
#endif /* _WIN32_WCE || USER_TIME */
#ifdef HAVE_RTP_SYS #if defined(HAVE_RTP_SYS)
#define YEAR0 1900 #define YEAR0 1900
struct tm* my_gmtime(const time_t* timer) /* has a gmtime() but hangs */ struct tm* rtpsys_gmtime(const time_t* timer) /* has a gmtime() but hangs */
{ {
static struct tm st_time; static struct tm st_time;
struct tm* ret = &st_time; struct tm* ret = &st_time;
@@ -365,12 +356,6 @@ time_t mqx_time(time_t* timer)
return *timer; return *timer;
} }
/* CodeWarrior GCC toolchain only has gmtime_r(), no gmtime() */
struct tm* mqx_gmtime(const time_t* clock, struct tm* tmpTime)
{
return gmtime_r(clock, tmpTime);
}
#endif /* FREESCALE_MQX */ #endif /* FREESCALE_MQX */
#if defined(FREESCALE_KSDK_BM) || defined(FREESCALE_FREE_RTOS) #if defined(FREESCALE_KSDK_BM) || defined(FREESCALE_FREE_RTOS)
@@ -390,7 +375,7 @@ time_t ksdk_time(time_t* timer)
#endif /* FREESCALE_KSDK_BM */ #endif /* FREESCALE_KSDK_BM */
#ifdef WOLFSSL_TIRTOS #if defined(WOLFSSL_TIRTOS)
time_t XTIME(time_t * timer) time_t XTIME(time_t * timer)
{ {
@@ -406,6 +391,7 @@ time_t XTIME(time_t * timer)
#endif /* WOLFSSL_TIRTOS */ #endif /* WOLFSSL_TIRTOS */
static INLINE word32 btoi(byte b) static INLINE word32 btoi(byte b)
{ {
return b - 0x30; return b - 0x30;
@@ -496,7 +482,7 @@ time_t idirect_time(time_t * timer)
return sec; return sec;
} }
#endif #endif /* IDIRECT_DEV_TIME */
WOLFSSL_LOCAL int GetLength(const byte* input, word32* inOutIdx, int* len, WOLFSSL_LOCAL int GetLength(const byte* input, word32* inOutIdx, int* len,
@@ -2954,7 +2940,7 @@ static int GetName(DecodedCert* cert, int nameType)
} }
#ifndef NO_TIME_H #if !defined(NO_TIME_H) && defined(USE_WOLF_VALIDDATE)
/* to the second */ /* to the second */
static int DateGreaterThan(const struct tm* a, const struct tm* b) static int DateGreaterThan(const struct tm* a, const struct tm* b)
@@ -2992,7 +2978,6 @@ static INLINE int DateLessThan(const struct tm* a, const struct tm* b)
return DateGreaterThan(b,a); return DateGreaterThan(b,a);
} }
/* like atoi but only use first byte */ /* like atoi but only use first byte */
/* Make sure before and after dates are valid */ /* Make sure before and after dates are valid */
int ValidateDate(const byte* date, byte format, int dateType) int ValidateDate(const byte* date, byte format, int dateType)
@@ -3006,8 +2991,7 @@ int ValidateDate(const byte* date, byte format, int dateType)
int diffHH = 0 ; int diffMM = 0 ; int diffHH = 0 ; int diffMM = 0 ;
int diffSign = 0 ; int diffSign = 0 ;
#if defined(FREESCALE_MQX) || defined(FREESCALE_KSDK_MQX) || \ #if defined(NEED_TMP_TIME)
defined(TIME_OVERRIDES) || defined(NEED_TMP_TIME)
struct tm tmpTimeStorage; struct tm tmpTimeStorage;
tmpTime = &tmpTimeStorage; tmpTime = &tmpTimeStorage;
#else #else
@@ -3065,8 +3049,7 @@ int ValidateDate(const byte* date, byte format, int dateType)
return 1; return 1;
} }
#endif /* !NO_TIME_H && USE_WOLF_VALIDDATE */
#endif /* NO_TIME_H */
static int GetDate(DecodedCert* cert, int dateType) static int GetDate(DecodedCert* cert, int dateType)
@@ -6022,8 +6005,7 @@ static int SetValidity(byte* output, int daysValid)
struct tm* tmpTime = NULL; struct tm* tmpTime = NULL;
struct tm local; struct tm local;
#if defined(FREESCALE_MQX) || defined(FREESCALE_KSDK_MQX) || \ #if defined(NEED_TMP_TIME)
defined(TIME_OVERRIDES) || defined(NEED_TMP_TIME)
/* for use with gmtime_r */ /* for use with gmtime_r */
struct tm tmpTimeStorage; struct tm tmpTimeStorage;
tmpTime = &tmpTimeStorage; tmpTime = &tmpTimeStorage;