summaryrefslogtreecommitdiffabout
authorMichael Krelin <hacker@klever.net>2008-06-29 16:08:01 (UTC)
committer Michael Krelin <hacker@klever.net>2008-06-29 16:11:44 (UTC)
commit12837594b705ad10fdadfd0ba1bfc2249b3b1264 (patch) (unidiff)
treee0502e678b09668ec59828237ebf5972014d0ce0
parent362678728b8232c9490e14ba14ff323d9a92d6be (diff)
downloadlibopkele-12837594b705ad10fdadfd0ba1bfc2249b3b1264.zip
libopkele-12837594b705ad10fdadfd0ba1bfc2249b3b1264.tar.gz
libopkele-12837594b705ad10fdadfd0ba1bfc2249b3b1264.tar.bz2
Fixed w3c to unix timestamp conversion for FreeBSD
Thanks to Göran Löwkrantz for pointing both to the problem and possible solution. Signed-off-by: Michael Krelin <hacker@klever.net>
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--configure.ac1
-rw-r--r--lib/util.cc21
2 files changed, 19 insertions, 3 deletions
diff --git a/configure.ac b/configure.ac
index 3194718..3484146 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1,24 +1,25 @@
1AC_INIT([libopkele], [2.0], [libopkele-bugs@klever.net]) 1AC_INIT([libopkele], [2.0], [libopkele-bugs@klever.net])
2AC_CONFIG_SRCDIR([include/opkele/opkele-config.h]) 2AC_CONFIG_SRCDIR([include/opkele/opkele-config.h])
3AC_CONFIG_HEADERS([config.h include/opkele/acconfig.h]) 3AC_CONFIG_HEADERS([config.h include/opkele/acconfig.h])
4AM_INIT_AUTOMAKE([dist-bzip2]) 4AM_INIT_AUTOMAKE([dist-bzip2])
5 5
6AC_PROG_INSTALL 6AC_PROG_INSTALL
7AC_PROG_CXX 7AC_PROG_CXX
8AC_PROG_CC 8AC_PROG_CC
9AC_PROG_LIBTOOL 9AC_PROG_LIBTOOL
10PKG_PROG_PKG_CONFIG 10PKG_PROG_PKG_CONFIG
11 11
12AC_HEADER_STDC 12AC_HEADER_STDC
13AC_CHECK_FUNCS([timegm])
13 14
14AC_PATH_PROG([XSLTPROC],[xsltproc],[true]) 15AC_PATH_PROG([XSLTPROC],[xsltproc],[true])
15 16
16AC_MSG_CHECKING([for source tree version]) 17AC_MSG_CHECKING([for source tree version])
17if headrev=$(cd $srcdir && git rev-parse --verify HEAD 2>/dev/null) ; then 18if headrev=$(cd $srcdir && git rev-parse --verify HEAD 2>/dev/null) ; then
18 PACKAGE_SRC_VERSION="$(cd $srcdir && git describe --tags $headrev)" 19 PACKAGE_SRC_VERSION="$(cd $srcdir && git describe --tags $headrev)"
19 test "$PACKAGE_SRC_VERSION" = "$PACKAGE_VERSION" \ 20 test "$PACKAGE_SRC_VERSION" = "$PACKAGE_VERSION" \
20 -o "${PACKAGE_SRC_VERSION#${PACKAGE_VERSION}-}" != "$PACKAGE_SRC_VERSION" || PACKAGE_SRC_VERSION="${PACKAGE_VERSION}:${PACKAGE_SRC_VERSION}" 21 -o "${PACKAGE_SRC_VERSION#${PACKAGE_VERSION}-}" != "$PACKAGE_SRC_VERSION" || PACKAGE_SRC_VERSION="${PACKAGE_VERSION}:${PACKAGE_SRC_VERSION}"
21 ( cd $srcdir && git diff-index $headrev | read dirt ) && PACKAGE_SRC_VERSION="${PACKAGE_SRC_VERSION}-dirty" 22 ( cd $srcdir && git diff-index $headrev | read dirt ) && PACKAGE_SRC_VERSION="${PACKAGE_SRC_VERSION}-dirty"
22else 23else
23 PACKAGE_SRC_VERSION="$PACKAGE_VERSION" 24 PACKAGE_SRC_VERSION="$PACKAGE_VERSION"
24fi 25fi
diff --git a/lib/util.cc b/lib/util.cc
index d979502..a46ba2a 100644
--- a/lib/util.cc
+++ b/lib/util.cc
@@ -113,51 +113,66 @@ namespace opkele {
113 */ 113 */
114 114
115 string time_to_w3c(time_t t) { 115 string time_to_w3c(time_t t) {
116 struct tm tm_t; 116 struct tm tm_t;
117 if(!gmtime_r(&t,&tm_t)) 117 if(!gmtime_r(&t,&tm_t))
118 throw failed_conversion(OPKELE_CP_ "failed to BN_dec2bn()"); 118 throw failed_conversion(OPKELE_CP_ "failed to BN_dec2bn()");
119 char rv[25]; 119 char rv[25];
120 if(!strftime(rv,sizeof(rv)-1,"%Y-%m-%dT%H:%M:%SZ",&tm_t)) 120 if(!strftime(rv,sizeof(rv)-1,"%Y-%m-%dT%H:%M:%SZ",&tm_t))
121 throw failed_conversion(OPKELE_CP_ "failed to strftime()"); 121 throw failed_conversion(OPKELE_CP_ "failed to strftime()");
122 return rv; 122 return rv;
123 } 123 }
124 124
125#ifndef HAVE_TIMEGM
126 static time_t timegm(struct tm *t) {
127 char *tz = getenv("TZ");
128 setenv("TZ","",1); tzset();
129 time_t rv = mktime(t);
130 if(tz)
131 setenv("TZ",tz,1);
132 else
133 unsetenv("TZ");
134 tzset();
135 return rv;
136 }
137 #define timegm opkele::util::timegm
138#endif /* HAVE_TIMEGM */
139
125 time_t w3c_to_time(const string& w) { 140 time_t w3c_to_time(const string& w) {
126 int fraction; 141 int fraction;
127 struct tm tm_t; 142 struct tm tm_t;
128 memset(&tm_t,0,sizeof(tm_t)); 143 memset(&tm_t,0,sizeof(tm_t));
129 if( ( 144 if( (
130 sscanf( 145 sscanf(
131 w.c_str(), 146 w.c_str(),
132 "%04d-%02d-%02dT%02d:%02d:%02dZ", 147 "%04d-%02d-%02dT%02d:%02d:%02dZ",
133 &tm_t.tm_year,&tm_t.tm_mon,&tm_t.tm_mday, 148 &tm_t.tm_year,&tm_t.tm_mon,&tm_t.tm_mday,
134 &tm_t.tm_hour,&tm_t.tm_min,&tm_t.tm_sec 149 &tm_t.tm_hour,&tm_t.tm_min,&tm_t.tm_sec
135 ) != 6 150 ) != 6
136 ) && ( 151 ) && (
137 sscanf( 152 sscanf(
138 w.c_str(), 153 w.c_str(),
139 "%04d-%02d-%02dT%02d:%02d:%02d.%03dZ", 154 "%04d-%02d-%02dT%02d:%02d:%02d.%03dZ",
140 &tm_t.tm_year,&tm_t.tm_mon,&tm_t.tm_mday, 155 &tm_t.tm_year,&tm_t.tm_mon,&tm_t.tm_mday,
141 &tm_t.tm_hour,&tm_t.tm_min,&tm_t.tm_sec, 156 &tm_t.tm_hour,&tm_t.tm_min,&tm_t.tm_sec,
142 &fraction 157 &fraction
143 ) != 7 158 ) != 7
144 ) ) 159 ) )
145 throw failed_conversion(OPKELE_CP_ "failed to sscanf()"); 160 throw failed_conversion(OPKELE_CP_ "failed to sscanf()");
146 tm_t.tm_mon--; 161 tm_t.tm_mon--;
147 tm_t.tm_year-=1900; 162 tm_t.tm_year-=1900;
148 time_t rv = mktime(&tm_t); 163 time_t rv = timegm(&tm_t);
149 if(rv==(time_t)-1) 164 if(rv==(time_t)-1)
150 throw failed_conversion(OPKELE_CP_ "failed to mktime()"); 165 throw failed_conversion(OPKELE_CP_ "failed to gmtime()");
151 return rv-timezone; 166 return rv;
152 } 167 }
153 168
154 /* 169 /*
155 * 170 *
156 */ 171 */
157 172
158 static inline bool isrfc3986unreserved(int c) { 173 static inline bool isrfc3986unreserved(int c) {
159 if(c<'-') return false; 174 if(c<'-') return false;
160 if(c<='.') return true; 175 if(c<='.') return true;
161 if(c<'0') return false; if(c<='9') return true; 176 if(c<'0') return false; if(c<='9') return true;
162 if(c<'A') return false; if(c<='Z') return true; 177 if(c<'A') return false; if(c<='Z') return true;
163 if(c<'_') return false; 178 if(c<'_') return false;