mirror of
https://github.com/moparisthebest/spdylay
synced 2024-12-22 07:38:52 -05:00
Provide timegm replacement and android build fix
This commit is contained in:
parent
61726d5e74
commit
add067ed7e
15
configure.ac
15
configure.ac
@ -85,16 +85,26 @@ LIBS_OLD=$LIBS
|
|||||||
# Search for dlsym function, which is used in tests. Linux needs -ldl,
|
# Search for dlsym function, which is used in tests. Linux needs -ldl,
|
||||||
# but netbsd does not need it.
|
# but netbsd does not need it.
|
||||||
AC_SEARCH_LIBS([dlsym], [dl])
|
AC_SEARCH_LIBS([dlsym], [dl])
|
||||||
TESTS_LIBS=$LIBS $TESTS_LIBS
|
TESTS_LIBS="$LIBS $TESTS_LIBS"
|
||||||
LIBS=$LIBS_OLD
|
LIBS=$LIBS_OLD
|
||||||
|
|
||||||
LIBS_OLD=$LIBS
|
LIBS_OLD=$LIBS
|
||||||
AC_SEARCH_LIBS([clock_gettime], [rt],
|
AC_SEARCH_LIBS([clock_gettime], [rt],
|
||||||
[AC_DEFINE([HAVE_CLOCK_GETTIME], [1],
|
[AC_DEFINE([HAVE_CLOCK_GETTIME], [1],
|
||||||
[Define to 1 if you have the `clock_gettime`.])])
|
[Define to 1 if you have the `clock_gettime`.])])
|
||||||
SRC_LIBS=$LIBS $SRC_LIBS
|
SRC_LIBS="$LIBS $SRC_LIBS"
|
||||||
LIBS=$LIBS_OLD
|
LIBS=$LIBS_OLD
|
||||||
|
|
||||||
|
case "$host" in
|
||||||
|
*android*)
|
||||||
|
# android does not need -pthread, but needs followng 2 libs for C++
|
||||||
|
SRC_LIBS="$SRC_LIBS -lstdc++ -lsupc++"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
SRC_LIBS="$SRC_LIBS -pthread"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
# zlib
|
# zlib
|
||||||
PKG_CHECK_MODULES([ZLIB], [zlib >= 1.2.3])
|
PKG_CHECK_MODULES([ZLIB], [zlib >= 1.2.3])
|
||||||
LIBS="$ZLIB_LIBS $LIBS"
|
LIBS="$ZLIB_LIBS $LIBS"
|
||||||
@ -211,6 +221,7 @@ AC_CHECK_FUNCS([ \
|
|||||||
getpwnam \
|
getpwnam \
|
||||||
memmove \
|
memmove \
|
||||||
memset \
|
memset \
|
||||||
|
timegm \
|
||||||
])
|
])
|
||||||
|
|
||||||
AX_HAVE_EPOLL([have_epoll=yes], [have_epoll=no])
|
AX_HAVE_EPOLL([have_epoll=yes], [have_epoll=no])
|
||||||
|
@ -26,8 +26,8 @@ if ENABLE_SRC
|
|||||||
AM_CFLAGS = -Wall
|
AM_CFLAGS = -Wall
|
||||||
AM_CPPFLAGS = -Wall -I$(srcdir)/../lib/includes -I$(builddir)/../lib/includes \
|
AM_CPPFLAGS = -Wall -I$(srcdir)/../lib/includes -I$(builddir)/../lib/includes \
|
||||||
@OPENSSL_CFLAGS@ @XML_CPPFLAGS@ @LIBEVENT_OPENSSL_CFLAGS@ @DEFS@
|
@OPENSSL_CFLAGS@ @XML_CPPFLAGS@ @LIBEVENT_OPENSSL_CFLAGS@ @DEFS@
|
||||||
AM_LDFLAGS = @OPENSSL_LIBS@ @XML_LIBS@ @LIBEVENT_OPENSSL_LIBS@ @SRC_LIBS@ \
|
AM_LDFLAGS = @OPENSSL_LIBS@ @XML_LIBS@ @LIBEVENT_OPENSSL_LIBS@ @SRC_LIBS@
|
||||||
-pthread
|
|
||||||
LDADD = $(top_builddir)/lib/libspdylay.la
|
LDADD = $(top_builddir)/lib/libspdylay.la
|
||||||
|
|
||||||
bin_PROGRAMS = spdycat spdyd
|
bin_PROGRAMS = spdycat spdyd
|
||||||
@ -38,8 +38,8 @@ if HAVE_LIBEVENT_OPENSSL
|
|||||||
bin_PROGRAMS += shrpx
|
bin_PROGRAMS += shrpx
|
||||||
endif # HAVE_LIBEVENT_OPENSSL
|
endif # HAVE_LIBEVENT_OPENSSL
|
||||||
|
|
||||||
HELPER_OBJECTS = util.cc spdylay_ssl.cc
|
HELPER_OBJECTS = util.cc timegm.c spdylay_ssl.cc
|
||||||
HELPER_HFILES = util.h spdylay_ssl.h spdylay_config.h
|
HELPER_HFILES = util.h timegm.h spdylay_ssl.h spdylay_config.h
|
||||||
|
|
||||||
EVENT_OBJECTS =
|
EVENT_OBJECTS =
|
||||||
EVENT_HFILES = EventPoll.h EventPollEvent.h
|
EVENT_HFILES = EventPoll.h EventPollEvent.h
|
||||||
@ -75,7 +75,7 @@ spdyd_SOURCES = ${HELPER_OBJECTS} ${HELPER_HFILES} \
|
|||||||
|
|
||||||
if HAVE_LIBEVENT_OPENSSL
|
if HAVE_LIBEVENT_OPENSSL
|
||||||
SHRPX_SRCS = \
|
SHRPX_SRCS = \
|
||||||
util.cc util.h base64.h \
|
util.cc util.h timegm.c timegm.h base64.h \
|
||||||
shrpx_config.cc shrpx_config.h \
|
shrpx_config.cc shrpx_config.h \
|
||||||
shrpx_error.h \
|
shrpx_error.h \
|
||||||
shrpx_listen_handler.cc shrpx_listen_handler.h \
|
shrpx_listen_handler.cc shrpx_listen_handler.h \
|
||||||
|
75
src/timegm.c
Normal file
75
src/timegm.c
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
/*
|
||||||
|
* Spdylay - SPDY Library
|
||||||
|
*
|
||||||
|
* Copyright (c) 2013 Tatsuhiro Tsujikawa
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
#include "timegm.h"
|
||||||
|
|
||||||
|
#ifndef HAVE_TIMEGM
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
/* Counter the number of leap year in the range [0, y). The |y| is the
|
||||||
|
year, including century (e.g., 2012) */
|
||||||
|
static int count_leap_year(int y)
|
||||||
|
{
|
||||||
|
y -= 1;
|
||||||
|
return y/4-y/100+y/400;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Returns nonzero if the |y| is the leap year. The |y| is the year,
|
||||||
|
including century (e.g., 2012) */
|
||||||
|
static int is_leap_year(int y)
|
||||||
|
{
|
||||||
|
return y%4 == 0 && (y%100 != 0 || y%400 == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* The number of days before ith month begins */
|
||||||
|
static int daysum[] = {
|
||||||
|
0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Based on the algorithm of Python 2.7 calendar.timegm. */
|
||||||
|
time_t timegm(struct tm *tm)
|
||||||
|
{
|
||||||
|
int days;
|
||||||
|
int num_leap_year;
|
||||||
|
int64_t t;
|
||||||
|
if(tm->tm_mon > 11) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
num_leap_year = count_leap_year(tm->tm_year + 1900) - count_leap_year(1970);
|
||||||
|
days = (tm->tm_year - 70) * 365 +
|
||||||
|
num_leap_year + daysum[tm->tm_mon] + tm->tm_mday-1;
|
||||||
|
if(tm->tm_mon >= 2 && is_leap_year(tm->tm_year + 1900)) {
|
||||||
|
++days;
|
||||||
|
}
|
||||||
|
t = ((int64_t)days * 24 + tm->tm_hour) * 3600 + tm->tm_min * 60 + tm->tm_sec;
|
||||||
|
if(sizeof(time_t) == 4) {
|
||||||
|
if(t < INT32_MIN || t > INT32_MAX) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* !HAVE_TIMEGM */
|
48
src/timegm.h
Normal file
48
src/timegm.h
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
/*
|
||||||
|
* Spdylay - SPDY Library
|
||||||
|
*
|
||||||
|
* Copyright (c) 2013 Tatsuhiro Tsujikawa
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
#ifndef TIMEGM_H
|
||||||
|
#define TIMEGM_H
|
||||||
|
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
# include <config.h>
|
||||||
|
#endif // HAVE_CONFIG_H
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif /* __cplusplus */
|
||||||
|
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
|
#ifndef HAVE_TIMEGM
|
||||||
|
|
||||||
|
time_t timegm(struct tm *tm);
|
||||||
|
|
||||||
|
#endif /* HAVE_TIMEGM */
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif /* __cplusplus */
|
||||||
|
|
||||||
|
#endif /* TIMEGM_H */
|
@ -29,6 +29,8 @@
|
|||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
|
#include "timegm.h"
|
||||||
|
|
||||||
namespace spdylay {
|
namespace spdylay {
|
||||||
|
|
||||||
namespace util {
|
namespace util {
|
||||||
|
Loading…
Reference in New Issue
Block a user