Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1 | /*- |
| 2 | * Copyright (c) 2003, 2004 Lev Walkin <vlm@lionet.info>. All rights reserved. |
| 3 | * Redistribution and modifications are permitted subject to BSD license. |
| 4 | */ |
Lev Walkin | a460ba3 | 2004-10-20 15:40:04 +0000 | [diff] [blame] | 5 | #define _POSIX_PTHREAD_SEMANTICS /* for Sun */ |
| 6 | #define _REENTRANT /* for Sun */ |
Lev Walkin | a9cc46e | 2004-09-22 16:06:28 +0000 | [diff] [blame] | 7 | #include <asn_internal.h> |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 8 | #include <GeneralizedTime.h> |
| 9 | #include <time.h> |
| 10 | #include <errno.h> |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 11 | |
Lev Walkin | 2a1646d | 2004-09-04 04:43:28 +0000 | [diff] [blame] | 12 | #if defined(WIN32) |
Lev Walkin | a57953d | 2005-06-15 19:01:45 +0000 | [diff] [blame] | 13 | #pragma message( "PLEASE STOP AND READ!") |
| 14 | #pragma message( " localtime_r is implemented via localtime(), which may be not thread-safe.") |
| 15 | #pragma message( " gmtime_r is implemented via gmtime(), which may be not thread-safe.") |
| 16 | #pragma message( " ") |
| 17 | #pragma message( " You must fix the code by inserting appropriate locking") |
| 18 | #pragma message( " if you want to use asn_GT2time() or asn_UT2time().") |
Lev Walkin | c8c2cb5 | 2006-07-13 13:20:19 +0000 | [diff] [blame] | 19 | #pragma message( "PLEASE STOP AND READ!") |
Lev Walkin | 02a3155 | 2004-08-12 03:52:53 +0000 | [diff] [blame] | 20 | |
Lev Walkin | cec43b5 | 2004-09-02 05:20:39 +0000 | [diff] [blame] | 21 | static struct tm *localtime_r(const time_t *tloc, struct tm *result) { |
Lev Walkin | 02a3155 | 2004-08-12 03:52:53 +0000 | [diff] [blame] | 22 | struct tm *tm; |
| 23 | if((tm = localtime(tloc))) |
| 24 | return memcpy(result, tm, sizeof(struct tm)); |
| 25 | return 0; |
| 26 | } |
| 27 | |
Lev Walkin | cec43b5 | 2004-09-02 05:20:39 +0000 | [diff] [blame] | 28 | static struct tm *gmtime_r(const time_t *tloc, struct tm *result) { |
Lev Walkin | 02a3155 | 2004-08-12 03:52:53 +0000 | [diff] [blame] | 29 | struct tm *tm; |
| 30 | if((tm = gmtime(tloc))) |
| 31 | return memcpy(result, tm, sizeof(struct tm)); |
| 32 | return 0; |
| 33 | } |
| 34 | |
Lev Walkin | 93e9fe3 | 2004-09-17 06:46:10 +0000 | [diff] [blame] | 35 | #define tzset() _tzset() |
Lev Walkin | a57953d | 2005-06-15 19:01:45 +0000 | [diff] [blame] | 36 | #define putenv(c) _putenv(c) |
Lev Walkin | 93e9fe3 | 2004-09-17 06:46:10 +0000 | [diff] [blame] | 37 | #define _EMULATE_TIMEGM |
| 38 | |
| 39 | #endif /* WIN32 */ |
| 40 | |
Lev Walkin | c8c2cb5 | 2006-07-13 13:20:19 +0000 | [diff] [blame] | 41 | #if defined(sun) || defined(_sun_) || defined(__solaris__) |
Lev Walkin | a460ba3 | 2004-10-20 15:40:04 +0000 | [diff] [blame] | 42 | #define _EMULATE_TIMEGM |
| 43 | #endif |
| 44 | |
Lev Walkin | 93e9fe3 | 2004-09-17 06:46:10 +0000 | [diff] [blame] | 45 | /* |
| 46 | * Where to look for offset from GMT, Phase I. |
| 47 | * Several platforms are known. |
| 48 | */ |
| 49 | #if defined(__FreeBSD__) \ |
| 50 | || (defined(__GNUC__) && defined(__APPLE_CC__)) \ |
| 51 | || (defined __GLIBC__ && __GLIBC__ >= 2) |
| 52 | #undef HAVE_TM_GMTOFF |
| 53 | #define HAVE_TM_GMTOFF |
| 54 | #endif /* BSDs and newer glibc */ |
| 55 | |
| 56 | /* |
| 57 | * Where to look for offset from GMT, Phase II. |
| 58 | */ |
| 59 | #ifdef HAVE_TM_GMTOFF |
| 60 | #define GMTOFF(tm) ((tm).tm_gmtoff) |
| 61 | #else /* HAVE_TM_GMTOFF */ |
| 62 | #define GMTOFF(tm) (-timezone) |
| 63 | #endif /* HAVE_TM_GMTOFF */ |
| 64 | |
Lev Walkin | c8c2cb5 | 2006-07-13 13:20:19 +0000 | [diff] [blame] | 65 | #if (defined(_EMULATE_TIMEGM) || !defined(HAVE_TM_GMTOFF)) |
| 66 | #warning "PLEASE STOP AND READ!" |
| 67 | #warning " timegm() is implemented via getenv(\"TZ\")/setenv(\"TZ\"), which may be not thread-safe." |
| 68 | #warning " " |
| 69 | #warning " You must fix the code by inserting appropriate locking" |
| 70 | #warning " if you want to use asn_GT2time() or asn_UT2time()." |
| 71 | #warning "PLEASE STOP AND READ!" |
| 72 | #endif /* _EMULATE_TIMEGM */ |
| 73 | |
Lev Walkin | 93e9fe3 | 2004-09-17 06:46:10 +0000 | [diff] [blame] | 74 | /* |
| 75 | * Override our GMTOFF decision for other known platforms. |
| 76 | */ |
| 77 | #ifdef __CYGWIN__ |
| 78 | #undef GMTOFF |
| 79 | static long GMTOFF(struct tm a){ |
| 80 | struct tm *lt; |
| 81 | time_t local_time, gmt_time; |
| 82 | long zone; |
| 83 | |
| 84 | tzset(); |
| 85 | gmt_time = time (NULL); |
| 86 | |
| 87 | lt = gmtime(&gmt_time); |
| 88 | |
| 89 | local_time = mktime(lt); |
| 90 | return (gmt_time - local_time); |
| 91 | } |
| 92 | #define _EMULATE_TIMEGM |
| 93 | |
| 94 | #endif /* __CYGWIN__ */ |
| 95 | |
Lev Walkin | c8c2cb5 | 2006-07-13 13:20:19 +0000 | [diff] [blame] | 96 | #define ATZVARS do { \ |
| 97 | char tzoldbuf[64]; \ |
| 98 | char *tzold |
| 99 | #define ATZSAVETZ do { \ |
| 100 | tzold = getenv("TZ"); \ |
| 101 | if(tzold) { \ |
| 102 | size_t tzlen = strlen(tzold); \ |
| 103 | if(tzlen < sizeof(tzoldbuf)) \ |
| 104 | tzold = memcpy(tzoldbuf, tzold, tzlen + 1); \ |
| 105 | else \ |
| 106 | tzold = strdup(tzold); /* Ignore error */ \ |
| 107 | setenv("TZ", "UTC", 1); \ |
| 108 | } \ |
| 109 | tzset(); \ |
| 110 | } while(0) |
| 111 | #define ATZOLDTZ do { \ |
| 112 | if (tzold) { \ |
| 113 | setenv("TZ", tzold, 1); \ |
| 114 | *tzoldbuf = 0; \ |
| 115 | if(tzold != tzoldbuf) \ |
| 116 | free(tzold); \ |
| 117 | } else { \ |
| 118 | unsetenv("TZ"); \ |
| 119 | } \ |
| 120 | tzset(); \ |
| 121 | } while(0); } while(0); |
| 122 | |
Lev Walkin | 93e9fe3 | 2004-09-17 06:46:10 +0000 | [diff] [blame] | 123 | #ifdef _EMULATE_TIMEGM |
Lev Walkin | db42400 | 2004-08-12 03:58:25 +0000 | [diff] [blame] | 124 | static time_t timegm(struct tm *tm) { |
| 125 | time_t tloc; |
Lev Walkin | c8c2cb5 | 2006-07-13 13:20:19 +0000 | [diff] [blame] | 126 | ATZVARS; |
| 127 | ATZSAVETZ; |
Lev Walkin | db42400 | 2004-08-12 03:58:25 +0000 | [diff] [blame] | 128 | tloc = mktime(tm); |
Lev Walkin | c8c2cb5 | 2006-07-13 13:20:19 +0000 | [diff] [blame] | 129 | ATZOLDTZ; |
Lev Walkin | db42400 | 2004-08-12 03:58:25 +0000 | [diff] [blame] | 130 | return tloc; |
| 131 | } |
Lev Walkin | 93e9fe3 | 2004-09-17 06:46:10 +0000 | [diff] [blame] | 132 | #endif /* _EMULATE_TIMEGM */ |
Lev Walkin | db42400 | 2004-08-12 03:58:25 +0000 | [diff] [blame] | 133 | |
Lev Walkin | 6439972 | 2004-08-11 07:17:22 +0000 | [diff] [blame] | 134 | |
Lev Walkin | 535612a | 2005-07-03 05:32:40 +0000 | [diff] [blame] | 135 | #ifndef __ASN_INTERNAL_TEST_MODE__ |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 136 | |
| 137 | /* |
| 138 | * GeneralizedTime basic type description. |
| 139 | */ |
Lev Walkin | 5e03376 | 2004-09-29 13:26:15 +0000 | [diff] [blame] | 140 | static ber_tlv_tag_t asn_DEF_GeneralizedTime_tags[] = { |
Lev Walkin | 8e8078a | 2004-09-26 13:10:40 +0000 | [diff] [blame] | 141 | (ASN_TAG_CLASS_UNIVERSAL | (24 << 2)), /* [UNIVERSAL 24] IMPLICIT ...*/ |
| 142 | (ASN_TAG_CLASS_UNIVERSAL | (26 << 2)), /* [UNIVERSAL 26] IMPLICIT ...*/ |
| 143 | (ASN_TAG_CLASS_UNIVERSAL | (4 << 2)) /* ... OCTET STRING */ |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 144 | }; |
Lev Walkin | 5e03376 | 2004-09-29 13:26:15 +0000 | [diff] [blame] | 145 | asn_TYPE_descriptor_t asn_DEF_GeneralizedTime = { |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 146 | "GeneralizedTime", |
Lev Walkin | dc06f6b | 2004-10-20 15:50:55 +0000 | [diff] [blame] | 147 | "GeneralizedTime", |
Lev Walkin | a9cc46e | 2004-09-22 16:06:28 +0000 | [diff] [blame] | 148 | OCTET_STRING_free, |
| 149 | GeneralizedTime_print, |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 150 | GeneralizedTime_constraint, /* Check validity of time */ |
| 151 | OCTET_STRING_decode_ber, /* Implemented in terms of OCTET STRING */ |
Lev Walkin | dc06f6b | 2004-10-20 15:50:55 +0000 | [diff] [blame] | 152 | GeneralizedTime_encode_der, |
| 153 | OCTET_STRING_decode_xer_utf8, |
Lev Walkin | a9cc46e | 2004-09-22 16:06:28 +0000 | [diff] [blame] | 154 | GeneralizedTime_encode_xer, |
Lev Walkin | 523de9e | 2006-08-18 01:34:18 +0000 | [diff] [blame] | 155 | 0, 0, |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 156 | 0, /* Use generic outmost tag fetcher */ |
Lev Walkin | 5e03376 | 2004-09-29 13:26:15 +0000 | [diff] [blame] | 157 | asn_DEF_GeneralizedTime_tags, |
| 158 | sizeof(asn_DEF_GeneralizedTime_tags) |
| 159 | / sizeof(asn_DEF_GeneralizedTime_tags[0]) - 2, |
| 160 | asn_DEF_GeneralizedTime_tags, |
| 161 | sizeof(asn_DEF_GeneralizedTime_tags) |
| 162 | / sizeof(asn_DEF_GeneralizedTime_tags[0]), |
Lev Walkin | 59b176e | 2005-11-26 11:25:14 +0000 | [diff] [blame] | 163 | 0, /* No PER visible constraints */ |
Lev Walkin | 449f832 | 2004-08-20 13:23:42 +0000 | [diff] [blame] | 164 | 0, 0, /* No members */ |
Lev Walkin | d9bd775 | 2004-06-05 08:17:50 +0000 | [diff] [blame] | 165 | 0 /* No specifics */ |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 166 | }; |
| 167 | |
Lev Walkin | 535612a | 2005-07-03 05:32:40 +0000 | [diff] [blame] | 168 | #endif /* __ASN_INTERNAL_TEST_MODE__ */ |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 169 | |
| 170 | /* |
| 171 | * Check that the time looks like the time. |
| 172 | */ |
| 173 | int |
Lev Walkin | 5e03376 | 2004-09-29 13:26:15 +0000 | [diff] [blame] | 174 | GeneralizedTime_constraint(asn_TYPE_descriptor_t *td, const void *sptr, |
Lev Walkin | 1eded35 | 2006-07-13 11:19:01 +0000 | [diff] [blame] | 175 | asn_app_constraint_failed_f *ctfailcb, void *app_key) { |
Lev Walkin | c234657 | 2004-08-11 09:07:36 +0000 | [diff] [blame] | 176 | const GeneralizedTime_t *st = (const GeneralizedTime_t *)sptr; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 177 | time_t tloc; |
| 178 | |
| 179 | errno = EPERM; /* Just an unlikely error code */ |
Lev Walkin | 9900636 | 2004-08-07 03:52:26 +0000 | [diff] [blame] | 180 | tloc = asn_GT2time(st, 0, 0); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 181 | if(tloc == -1 && errno != EPERM) { |
Lev Walkin | 1eded35 | 2006-07-13 11:19:01 +0000 | [diff] [blame] | 182 | _ASN_CTFAIL(app_key, td, |
Lev Walkin | 16835b6 | 2004-08-22 13:47:59 +0000 | [diff] [blame] | 183 | "%s: Invalid time format: %s (%s:%d)", |
| 184 | td->name, strerror(errno), __FILE__, __LINE__); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 185 | return -1; |
| 186 | } |
| 187 | |
| 188 | return 0; |
| 189 | } |
| 190 | |
Lev Walkin | a9cc46e | 2004-09-22 16:06:28 +0000 | [diff] [blame] | 191 | asn_enc_rval_t |
Lev Walkin | 535612a | 2005-07-03 05:32:40 +0000 | [diff] [blame] | 192 | GeneralizedTime_encode_der(asn_TYPE_descriptor_t *td, void *sptr, |
Lev Walkin | 9900636 | 2004-08-07 03:52:26 +0000 | [diff] [blame] | 193 | int tag_mode, ber_tlv_tag_t tag, |
| 194 | asn_app_consume_bytes_f *cb, void *app_key) { |
Lev Walkin | 535612a | 2005-07-03 05:32:40 +0000 | [diff] [blame] | 195 | GeneralizedTime_t *st = (GeneralizedTime_t *)sptr; |
Lev Walkin | a9cc46e | 2004-09-22 16:06:28 +0000 | [diff] [blame] | 196 | asn_enc_rval_t erval; |
Lev Walkin | 3a52278 | 2005-07-04 12:21:51 +0000 | [diff] [blame] | 197 | int fv, fd; /* seconds fraction value and number of digits */ |
Lev Walkin | 535612a | 2005-07-03 05:32:40 +0000 | [diff] [blame] | 198 | struct tm tm; |
| 199 | time_t tloc; |
Lev Walkin | 9900636 | 2004-08-07 03:52:26 +0000 | [diff] [blame] | 200 | |
Lev Walkin | 535612a | 2005-07-03 05:32:40 +0000 | [diff] [blame] | 201 | /* |
| 202 | * Encode as a canonical DER. |
| 203 | */ |
| 204 | errno = EPERM; |
Lev Walkin | 3a52278 | 2005-07-04 12:21:51 +0000 | [diff] [blame] | 205 | tloc = asn_GT2time_frac(st, &fv, &fd, &tm, 1); /* Recognize time */ |
Lev Walkin | 535612a | 2005-07-03 05:32:40 +0000 | [diff] [blame] | 206 | if(tloc == -1 && errno != EPERM) |
| 207 | /* Failed to recognize time. Fail completely. */ |
| 208 | _ASN_ENCODE_FAILED; |
Lev Walkin | 9900636 | 2004-08-07 03:52:26 +0000 | [diff] [blame] | 209 | |
Lev Walkin | 3a52278 | 2005-07-04 12:21:51 +0000 | [diff] [blame] | 210 | st = asn_time2GT_frac(0, &tm, fv, fd, 1); /* Save time canonically */ |
Lev Walkin | 535612a | 2005-07-03 05:32:40 +0000 | [diff] [blame] | 211 | if(!st) _ASN_ENCODE_FAILED; /* Memory allocation failure. */ |
Lev Walkin | 9900636 | 2004-08-07 03:52:26 +0000 | [diff] [blame] | 212 | |
| 213 | erval = OCTET_STRING_encode_der(td, st, tag_mode, tag, cb, app_key); |
| 214 | |
Lev Walkin | 535612a | 2005-07-03 05:32:40 +0000 | [diff] [blame] | 215 | FREEMEM(st->buf); |
| 216 | FREEMEM(st); |
Lev Walkin | 9900636 | 2004-08-07 03:52:26 +0000 | [diff] [blame] | 217 | |
| 218 | return erval; |
| 219 | } |
| 220 | |
Lev Walkin | 535612a | 2005-07-03 05:32:40 +0000 | [diff] [blame] | 221 | #ifndef __ASN_INTERNAL_TEST_MODE__ |
| 222 | |
Lev Walkin | a9cc46e | 2004-09-22 16:06:28 +0000 | [diff] [blame] | 223 | asn_enc_rval_t |
Lev Walkin | 5e03376 | 2004-09-29 13:26:15 +0000 | [diff] [blame] | 224 | GeneralizedTime_encode_xer(asn_TYPE_descriptor_t *td, void *sptr, |
Lev Walkin | a9cc46e | 2004-09-22 16:06:28 +0000 | [diff] [blame] | 225 | int ilevel, enum xer_encoder_flags_e flags, |
| 226 | asn_app_consume_bytes_f *cb, void *app_key) { |
Lev Walkin | a9cc46e | 2004-09-22 16:06:28 +0000 | [diff] [blame] | 227 | |
| 228 | if(flags & XER_F_CANONICAL) { |
Lev Walkin | 535612a | 2005-07-03 05:32:40 +0000 | [diff] [blame] | 229 | GeneralizedTime_t *gt; |
| 230 | asn_enc_rval_t rv; |
Lev Walkin | 3a52278 | 2005-07-04 12:21:51 +0000 | [diff] [blame] | 231 | int fv, fd; /* fractional parts */ |
Lev Walkin | a9cc46e | 2004-09-22 16:06:28 +0000 | [diff] [blame] | 232 | struct tm tm; |
Lev Walkin | a9cc46e | 2004-09-22 16:06:28 +0000 | [diff] [blame] | 233 | |
| 234 | errno = EPERM; |
Lev Walkin | 535612a | 2005-07-03 05:32:40 +0000 | [diff] [blame] | 235 | if(asn_GT2time_frac((GeneralizedTime_t *)sptr, |
Lev Walkin | 3a52278 | 2005-07-04 12:21:51 +0000 | [diff] [blame] | 236 | &fv, &fd, &tm, 1) == -1 |
Lev Walkin | a9cc46e | 2004-09-22 16:06:28 +0000 | [diff] [blame] | 237 | && errno != EPERM) |
| 238 | _ASN_ENCODE_FAILED; |
Lev Walkin | a9cc46e | 2004-09-22 16:06:28 +0000 | [diff] [blame] | 239 | |
Lev Walkin | 3a52278 | 2005-07-04 12:21:51 +0000 | [diff] [blame] | 240 | gt = asn_time2GT_frac(0, &tm, fv, fd, 1); |
Lev Walkin | 535612a | 2005-07-03 05:32:40 +0000 | [diff] [blame] | 241 | if(!gt) _ASN_ENCODE_FAILED; |
| 242 | |
| 243 | rv = OCTET_STRING_encode_xer_utf8(td, sptr, ilevel, flags, |
| 244 | cb, app_key); |
Lev Walkin | adcb586 | 2006-03-17 02:11:12 +0000 | [diff] [blame] | 245 | ASN_STRUCT_FREE(asn_DEF_GeneralizedTime, gt); |
Lev Walkin | 535612a | 2005-07-03 05:32:40 +0000 | [diff] [blame] | 246 | return rv; |
| 247 | } else { |
| 248 | return OCTET_STRING_encode_xer_utf8(td, sptr, ilevel, flags, |
| 249 | cb, app_key); |
| 250 | } |
Lev Walkin | a9cc46e | 2004-09-22 16:06:28 +0000 | [diff] [blame] | 251 | } |
| 252 | |
Lev Walkin | 535612a | 2005-07-03 05:32:40 +0000 | [diff] [blame] | 253 | #endif /* __ASN_INTERNAL_TEST_MODE__ */ |
| 254 | |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 255 | int |
Lev Walkin | 5e03376 | 2004-09-29 13:26:15 +0000 | [diff] [blame] | 256 | GeneralizedTime_print(asn_TYPE_descriptor_t *td, const void *sptr, int ilevel, |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 257 | asn_app_consume_bytes_f *cb, void *app_key) { |
Lev Walkin | c234657 | 2004-08-11 09:07:36 +0000 | [diff] [blame] | 258 | const GeneralizedTime_t *st = (const GeneralizedTime_t *)sptr; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 259 | |
Lev Walkin | d9bd775 | 2004-06-05 08:17:50 +0000 | [diff] [blame] | 260 | (void)td; /* Unused argument */ |
| 261 | (void)ilevel; /* Unused argument */ |
| 262 | |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 263 | if(st && st->buf) { |
| 264 | char buf[32]; |
| 265 | struct tm tm; |
| 266 | int ret; |
| 267 | |
| 268 | errno = EPERM; |
Lev Walkin | 9900636 | 2004-08-07 03:52:26 +0000 | [diff] [blame] | 269 | if(asn_GT2time(st, &tm, 1) == -1 && errno != EPERM) |
Lev Walkin | 8e8078a | 2004-09-26 13:10:40 +0000 | [diff] [blame] | 270 | return (cb("<bad-value>", 11, app_key) < 0) ? -1 : 0; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 271 | |
| 272 | ret = snprintf(buf, sizeof(buf), |
Lev Walkin | 535612a | 2005-07-03 05:32:40 +0000 | [diff] [blame] | 273 | "%04d-%02d-%02d %02d:%02d:%02d (GMT)", |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 274 | tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, |
| 275 | tm.tm_hour, tm.tm_min, tm.tm_sec); |
Lev Walkin | d9bd775 | 2004-06-05 08:17:50 +0000 | [diff] [blame] | 276 | assert(ret > 0 && ret < (int)sizeof(buf)); |
Lev Walkin | 8e8078a | 2004-09-26 13:10:40 +0000 | [diff] [blame] | 277 | return (cb(buf, ret, app_key) < 0) ? -1 : 0; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 278 | } else { |
Lev Walkin | 8e8078a | 2004-09-26 13:10:40 +0000 | [diff] [blame] | 279 | return (cb("<absent>", 8, app_key) < 0) ? -1 : 0; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 280 | } |
| 281 | } |
| 282 | |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 283 | time_t |
Lev Walkin | 9900636 | 2004-08-07 03:52:26 +0000 | [diff] [blame] | 284 | asn_GT2time(const GeneralizedTime_t *st, struct tm *ret_tm, int as_gmt) { |
Lev Walkin | 535612a | 2005-07-03 05:32:40 +0000 | [diff] [blame] | 285 | return asn_GT2time_frac(st, 0, 0, ret_tm, as_gmt); |
| 286 | } |
| 287 | |
| 288 | time_t |
Lev Walkin | 3a52278 | 2005-07-04 12:21:51 +0000 | [diff] [blame] | 289 | asn_GT2time_prec(const GeneralizedTime_t *st, int *frac_value, int frac_digits, struct tm *ret_tm, int as_gmt) { |
| 290 | time_t tloc; |
| 291 | int fv, fd = 0; |
| 292 | |
| 293 | if(frac_value) |
| 294 | tloc = asn_GT2time_frac(st, &fv, &fd, ret_tm, as_gmt); |
| 295 | else |
| 296 | return asn_GT2time_frac(st, 0, 0, ret_tm, as_gmt); |
| 297 | if(fd == 0 || frac_digits <= 0) { |
| 298 | *frac_value = 0; |
| 299 | } else { |
| 300 | while(fd > frac_digits) |
| 301 | fv /= 10, fd--; |
| 302 | while(fd < frac_digits) { |
| 303 | int new_fv = fv * 10; |
| 304 | if(new_fv / 10 != fv) { |
| 305 | /* Too long precision request */ |
| 306 | fv = 0; |
| 307 | break; |
| 308 | } |
| 309 | fv = new_fv, fd++; |
| 310 | } |
| 311 | |
| 312 | *frac_value = fv; |
| 313 | } |
| 314 | |
| 315 | return tloc; |
| 316 | } |
| 317 | |
| 318 | time_t |
| 319 | asn_GT2time_frac(const GeneralizedTime_t *st, int *frac_value, int *frac_digits, struct tm *ret_tm, int as_gmt) { |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 320 | struct tm tm_s; |
| 321 | uint8_t *buf; |
| 322 | uint8_t *end; |
Lev Walkin | 9900636 | 2004-08-07 03:52:26 +0000 | [diff] [blame] | 323 | int gmtoff_h = 0; |
| 324 | int gmtoff_m = 0; |
| 325 | int gmtoff = 0; /* h + m */ |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 326 | int offset_specified = 0; |
Lev Walkin | 3a52278 | 2005-07-04 12:21:51 +0000 | [diff] [blame] | 327 | int fvalue = 0; |
| 328 | int fdigits = 0; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 329 | time_t tloc; |
| 330 | |
| 331 | if(!st || !st->buf) { |
| 332 | errno = EINVAL; |
| 333 | return -1; |
| 334 | } else { |
| 335 | buf = st->buf; |
| 336 | end = buf + st->size; |
| 337 | } |
| 338 | |
| 339 | if(st->size < 10) { |
| 340 | errno = EINVAL; |
| 341 | return -1; |
| 342 | } |
| 343 | |
| 344 | /* |
| 345 | * Decode first 10 bytes: "AAAAMMJJhh" |
| 346 | */ |
| 347 | memset(&tm_s, 0, sizeof(tm_s)); |
| 348 | #undef B2F |
| 349 | #undef B2T |
| 350 | #define B2F(var) do { \ |
| 351 | unsigned ch = *buf; \ |
Lev Walkin | c81dab1 | 2006-01-10 08:08:14 +0000 | [diff] [blame] | 352 | if(ch < 0x30 || ch > 0x39) { \ |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 353 | errno = EINVAL; \ |
| 354 | return -1; \ |
| 355 | } else { \ |
| 356 | var = var * 10 + (ch - 0x30); \ |
| 357 | buf++; \ |
| 358 | } \ |
| 359 | } while(0) |
| 360 | #define B2T(var) B2F(tm_s.var) |
| 361 | |
| 362 | B2T(tm_year); /* 1: A */ |
| 363 | B2T(tm_year); /* 2: A */ |
| 364 | B2T(tm_year); /* 3: A */ |
| 365 | B2T(tm_year); /* 4: A */ |
| 366 | B2T(tm_mon); /* 5: M */ |
| 367 | B2T(tm_mon); /* 6: M */ |
| 368 | B2T(tm_mday); /* 7: J */ |
| 369 | B2T(tm_mday); /* 8: J */ |
| 370 | B2T(tm_hour); /* 9: h */ |
| 371 | B2T(tm_hour); /* 0: h */ |
| 372 | |
| 373 | if(buf == end) goto local_finish; |
| 374 | |
| 375 | /* |
| 376 | * Parse [mm[ss[(.|,)ffff]]] |
| 377 | * ^^ |
| 378 | */ |
| 379 | switch(*buf) { |
| 380 | case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: |
| 381 | case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: |
| 382 | tm_s.tm_min = (*buf++) - 0x30; |
| 383 | if(buf == end) { errno = EINVAL; return -1; } |
| 384 | B2T(tm_min); |
| 385 | break; |
| 386 | case 0x2B: case 0x2D: /* +, - */ |
| 387 | goto offset; |
| 388 | case 0x5A: /* Z */ |
| 389 | goto utc_finish; |
| 390 | default: |
| 391 | errno = EINVAL; |
| 392 | return -1; |
| 393 | } |
| 394 | |
| 395 | if(buf == end) goto local_finish; |
| 396 | |
| 397 | /* |
| 398 | * Parse [mm[ss[(.|,)ffff]]] |
| 399 | * ^^ |
| 400 | */ |
| 401 | switch(*buf) { |
| 402 | case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: |
| 403 | case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: |
| 404 | tm_s.tm_sec = (*buf++) - 0x30; |
| 405 | if(buf == end) { errno = EINVAL; return -1; } |
| 406 | B2T(tm_sec); |
| 407 | break; |
| 408 | case 0x2B: case 0x2D: /* +, - */ |
| 409 | goto offset; |
| 410 | case 0x5A: /* Z */ |
| 411 | goto utc_finish; |
| 412 | default: |
| 413 | errno = EINVAL; |
| 414 | return -1; |
| 415 | } |
| 416 | |
| 417 | if(buf == end) goto local_finish; |
| 418 | |
| 419 | /* |
| 420 | * Parse [mm[ss[(.|,)ffff]]] |
| 421 | * ^ ^ |
| 422 | */ |
| 423 | switch(*buf) { |
Lev Walkin | 535612a | 2005-07-03 05:32:40 +0000 | [diff] [blame] | 424 | case 0x2C: case 0x2E: /* (.|,) */ |
| 425 | /* |
| 426 | * Process fractions of seconds. |
| 427 | */ |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 428 | for(buf++; buf < end; buf++) { |
Lev Walkin | 535612a | 2005-07-03 05:32:40 +0000 | [diff] [blame] | 429 | int v = *buf; |
Lev Walkin | 3a52278 | 2005-07-04 12:21:51 +0000 | [diff] [blame] | 430 | int new_fvalue; |
Lev Walkin | 535612a | 2005-07-03 05:32:40 +0000 | [diff] [blame] | 431 | switch(v) { |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 432 | case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: |
| 433 | case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: |
Lev Walkin | 3a52278 | 2005-07-04 12:21:51 +0000 | [diff] [blame] | 434 | new_fvalue = fvalue * 10 + (v - 0x30); |
| 435 | if(new_fvalue / 10 != fvalue) { |
Lev Walkin | 535612a | 2005-07-03 05:32:40 +0000 | [diff] [blame] | 436 | /* Not enough precision, ignore */ |
| 437 | } else { |
Lev Walkin | 3a52278 | 2005-07-04 12:21:51 +0000 | [diff] [blame] | 438 | fvalue = new_fvalue; |
| 439 | fdigits++; |
Lev Walkin | 535612a | 2005-07-03 05:32:40 +0000 | [diff] [blame] | 440 | } |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 441 | continue; |
| 442 | default: |
| 443 | break; |
| 444 | } |
| 445 | break; |
| 446 | } |
| 447 | } |
| 448 | |
| 449 | if(buf == end) goto local_finish; |
| 450 | |
| 451 | switch(*buf) { |
| 452 | case 0x2B: case 0x2D: /* +, - */ |
| 453 | goto offset; |
| 454 | case 0x5A: /* Z */ |
| 455 | goto utc_finish; |
| 456 | default: |
| 457 | errno = EINVAL; |
| 458 | return -1; |
| 459 | } |
| 460 | |
| 461 | |
| 462 | offset: |
| 463 | |
| 464 | if(end - buf < 3) { |
| 465 | errno = EINVAL; |
| 466 | return -1; |
| 467 | } |
| 468 | buf++; |
Lev Walkin | 9900636 | 2004-08-07 03:52:26 +0000 | [diff] [blame] | 469 | B2F(gmtoff_h); |
| 470 | B2F(gmtoff_h); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 471 | if(buf[-3] == 0x2D) /* Negative */ |
Lev Walkin | 9900636 | 2004-08-07 03:52:26 +0000 | [diff] [blame] | 472 | gmtoff = -1; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 473 | else |
Lev Walkin | 9900636 | 2004-08-07 03:52:26 +0000 | [diff] [blame] | 474 | gmtoff = 1; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 475 | |
| 476 | if((end - buf) == 2) { |
Lev Walkin | 9900636 | 2004-08-07 03:52:26 +0000 | [diff] [blame] | 477 | B2F(gmtoff_m); |
| 478 | B2F(gmtoff_m); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 479 | } else if(end != buf) { |
| 480 | errno = EINVAL; |
| 481 | return -1; |
| 482 | } |
| 483 | |
Lev Walkin | 9900636 | 2004-08-07 03:52:26 +0000 | [diff] [blame] | 484 | gmtoff = gmtoff * (3600 * gmtoff_h + 60 * gmtoff_m); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 485 | |
| 486 | /* Fall through */ |
| 487 | utc_finish: |
| 488 | |
| 489 | offset_specified = 1; |
| 490 | |
| 491 | /* Fall through */ |
| 492 | local_finish: |
| 493 | |
| 494 | /* |
| 495 | * Validation. |
| 496 | */ |
| 497 | if((tm_s.tm_mon > 12 || tm_s.tm_mon < 1) |
| 498 | || (tm_s.tm_mday > 31 || tm_s.tm_mday < 1) |
| 499 | || (tm_s.tm_hour > 23) |
| 500 | || (tm_s.tm_sec > 60) |
| 501 | ) { |
| 502 | errno = EINVAL; |
| 503 | return -1; |
| 504 | } |
| 505 | |
| 506 | /* Canonicalize */ |
| 507 | tm_s.tm_mon -= 1; /* 0 - 11 */ |
| 508 | tm_s.tm_year -= 1900; |
| 509 | tm_s.tm_isdst = -1; |
| 510 | |
Lev Walkin | 9900636 | 2004-08-07 03:52:26 +0000 | [diff] [blame] | 511 | tm_s.tm_sec -= gmtoff; |
| 512 | |
| 513 | /*** AT THIS POINT tm_s is either GMT or local (unknown) ****/ |
| 514 | |
Lev Walkin | 02a3155 | 2004-08-12 03:52:53 +0000 | [diff] [blame] | 515 | if(offset_specified) { |
Lev Walkin | 9900636 | 2004-08-07 03:52:26 +0000 | [diff] [blame] | 516 | tloc = timegm(&tm_s); |
Lev Walkin | 02a3155 | 2004-08-12 03:52:53 +0000 | [diff] [blame] | 517 | } else { |
Lev Walkin | 9900636 | 2004-08-07 03:52:26 +0000 | [diff] [blame] | 518 | /* |
Lev Walkin | 5e03376 | 2004-09-29 13:26:15 +0000 | [diff] [blame] | 519 | * Without an offset (or "Z"), |
Lev Walkin | 9900636 | 2004-08-07 03:52:26 +0000 | [diff] [blame] | 520 | * we can only guess that it is a local zone. |
| 521 | * Interpret it in this fashion. |
| 522 | */ |
| 523 | tloc = mktime(&tm_s); |
| 524 | } |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 525 | if(tloc == -1) { |
| 526 | errno = EINVAL; |
| 527 | return -1; |
| 528 | } |
| 529 | |
Lev Walkin | 9900636 | 2004-08-07 03:52:26 +0000 | [diff] [blame] | 530 | if(ret_tm) { |
| 531 | if(as_gmt) { |
| 532 | if(offset_specified) { |
| 533 | *ret_tm = tm_s; |
| 534 | } else { |
| 535 | if(gmtime_r(&tloc, ret_tm) == 0) { |
| 536 | errno = EINVAL; |
| 537 | return -1; |
| 538 | } |
| 539 | } |
| 540 | } else { |
| 541 | if(localtime_r(&tloc, ret_tm) == 0) { |
| 542 | errno = EINVAL; |
| 543 | return -1; |
| 544 | } |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 545 | } |
| 546 | } |
| 547 | |
Lev Walkin | 535612a | 2005-07-03 05:32:40 +0000 | [diff] [blame] | 548 | /* Fractions of seconds */ |
| 549 | if(frac_value) *frac_value = fvalue; |
Lev Walkin | 3a52278 | 2005-07-04 12:21:51 +0000 | [diff] [blame] | 550 | if(frac_digits) *frac_digits = fdigits; |
Lev Walkin | 535612a | 2005-07-03 05:32:40 +0000 | [diff] [blame] | 551 | |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 552 | return tloc; |
| 553 | } |
| 554 | |
Lev Walkin | 9900636 | 2004-08-07 03:52:26 +0000 | [diff] [blame] | 555 | GeneralizedTime_t * |
| 556 | asn_time2GT(GeneralizedTime_t *opt_gt, const struct tm *tm, int force_gmt) { |
Lev Walkin | 535612a | 2005-07-03 05:32:40 +0000 | [diff] [blame] | 557 | return asn_time2GT_frac(opt_gt, tm, 0, 0, force_gmt); |
| 558 | } |
| 559 | |
| 560 | GeneralizedTime_t * |
Lev Walkin | 3a52278 | 2005-07-04 12:21:51 +0000 | [diff] [blame] | 561 | asn_time2GT_frac(GeneralizedTime_t *opt_gt, const struct tm *tm, int frac_value, int frac_digits, int force_gmt) { |
Lev Walkin | 9900636 | 2004-08-07 03:52:26 +0000 | [diff] [blame] | 562 | struct tm tm_s; |
| 563 | long gmtoff; |
Lev Walkin | 535612a | 2005-07-03 05:32:40 +0000 | [diff] [blame] | 564 | const unsigned int buf_size = |
| 565 | 4 + 2 + 2 /* yyyymmdd */ |
| 566 | + 2 + 2 + 2 /* hhmmss */ |
| 567 | + 1 + 6 /* .ffffff */ |
| 568 | + 1 + 4 /* +hhmm */ |
| 569 | + 1 /* '\0' */ |
| 570 | ; |
Lev Walkin | 9900636 | 2004-08-07 03:52:26 +0000 | [diff] [blame] | 571 | char *buf; |
| 572 | char *p; |
| 573 | int size; |
| 574 | |
| 575 | /* Check arguments */ |
| 576 | if(!tm) { |
| 577 | errno = EINVAL; |
| 578 | return 0; |
| 579 | } |
| 580 | |
| 581 | /* Pre-allocate a buffer of sufficient yet small length */ |
Lev Walkin | 8e8078a | 2004-09-26 13:10:40 +0000 | [diff] [blame] | 582 | buf = (char *)MALLOC(buf_size); |
Lev Walkin | 9900636 | 2004-08-07 03:52:26 +0000 | [diff] [blame] | 583 | if(!buf) return 0; |
| 584 | |
| 585 | gmtoff = GMTOFF(*tm); |
| 586 | |
| 587 | if(force_gmt && gmtoff) { |
| 588 | tm_s = *tm; |
| 589 | tm_s.tm_sec -= gmtoff; |
| 590 | timegm(&tm_s); /* Fix the time */ |
Lev Walkin | 9900636 | 2004-08-07 03:52:26 +0000 | [diff] [blame] | 591 | tm = &tm_s; |
Lev Walkin | 659a751 | 2004-08-11 07:35:08 +0000 | [diff] [blame] | 592 | #ifdef HAVE_TM_GMTOFF |
| 593 | assert(!GMTOFF(tm_s)); /* Will fix itself */ |
Lev Walkin | c8c2cb5 | 2006-07-13 13:20:19 +0000 | [diff] [blame] | 594 | #else /* !HAVE_TM_GMTOFF */ |
| 595 | gmtoff = 0; |
Lev Walkin | 659a751 | 2004-08-11 07:35:08 +0000 | [diff] [blame] | 596 | #endif |
Lev Walkin | 9900636 | 2004-08-07 03:52:26 +0000 | [diff] [blame] | 597 | } |
| 598 | |
| 599 | size = snprintf(buf, buf_size, "%04d%02d%02d%02d%02d%02d", |
| 600 | tm->tm_year + 1900, |
| 601 | tm->tm_mon + 1, |
| 602 | tm->tm_mday, |
| 603 | tm->tm_hour, |
| 604 | tm->tm_min, |
| 605 | tm->tm_sec |
| 606 | ); |
Lev Walkin | 535612a | 2005-07-03 05:32:40 +0000 | [diff] [blame] | 607 | if(size != 14) { |
| 608 | /* Could be assert(size == 14); */ |
| 609 | FREEMEM(buf); |
| 610 | errno = EINVAL; |
| 611 | return 0; |
| 612 | } |
Lev Walkin | 9900636 | 2004-08-07 03:52:26 +0000 | [diff] [blame] | 613 | |
| 614 | p = buf + size; |
Lev Walkin | 535612a | 2005-07-03 05:32:40 +0000 | [diff] [blame] | 615 | |
| 616 | /* |
| 617 | * Deal with fractions. |
| 618 | */ |
Lev Walkin | 3a52278 | 2005-07-04 12:21:51 +0000 | [diff] [blame] | 619 | if(frac_value > 0 && frac_digits > 0) { |
Lev Walkin | 535612a | 2005-07-03 05:32:40 +0000 | [diff] [blame] | 620 | char *end = p + 1 + 6; /* '.' + maximum 6 digits */ |
Lev Walkin | 4b4c146 | 2005-07-04 01:44:01 +0000 | [diff] [blame] | 621 | char *z = p; |
Lev Walkin | 3a52278 | 2005-07-04 12:21:51 +0000 | [diff] [blame] | 622 | long fbase; |
Lev Walkin | 4b4c146 | 2005-07-04 01:44:01 +0000 | [diff] [blame] | 623 | *z++ = '.'; |
Lev Walkin | 3a52278 | 2005-07-04 12:21:51 +0000 | [diff] [blame] | 624 | |
| 625 | /* Place bounds on precision */ |
| 626 | while(frac_digits-- > 6) |
| 627 | frac_value /= 10; |
| 628 | |
| 629 | /* emulate fbase = pow(10, frac_digits) */ |
| 630 | for(fbase = 1; frac_digits--;) |
| 631 | fbase *= 10; |
| 632 | |
Lev Walkin | 535612a | 2005-07-03 05:32:40 +0000 | [diff] [blame] | 633 | do { |
Lev Walkin | 3a52278 | 2005-07-04 12:21:51 +0000 | [diff] [blame] | 634 | int digit = frac_value / fbase; |
Lev Walkin | 88e0a77 | 2005-07-04 02:29:36 +0000 | [diff] [blame] | 635 | if(digit > 9) { z = 0; break; } |
Lev Walkin | 4b4c146 | 2005-07-04 01:44:01 +0000 | [diff] [blame] | 636 | *z++ = digit + 0x30; |
Lev Walkin | 3a52278 | 2005-07-04 12:21:51 +0000 | [diff] [blame] | 637 | frac_value %= fbase; |
| 638 | fbase /= 10; |
| 639 | } while(fbase > 0 && frac_value > 0 && z < end); |
| 640 | if(z) { |
Lev Walkin | 88e0a77 | 2005-07-04 02:29:36 +0000 | [diff] [blame] | 641 | for(--z; *z == 0x30; --z); /* Strip zeroes */ |
| 642 | p = z + (*z != '.'); |
| 643 | size = p - buf; |
| 644 | } |
Lev Walkin | 535612a | 2005-07-03 05:32:40 +0000 | [diff] [blame] | 645 | } |
| 646 | |
Lev Walkin | 9900636 | 2004-08-07 03:52:26 +0000 | [diff] [blame] | 647 | if(force_gmt) { |
Lev Walkin | 5e03376 | 2004-09-29 13:26:15 +0000 | [diff] [blame] | 648 | *p++ = 0x5a; /* "Z" */ |
Lev Walkin | 9900636 | 2004-08-07 03:52:26 +0000 | [diff] [blame] | 649 | *p++ = 0; |
| 650 | size++; |
| 651 | } else { |
Lev Walkin | 535612a | 2005-07-03 05:32:40 +0000 | [diff] [blame] | 652 | int ret; |
| 653 | gmtoff %= 86400; |
| 654 | ret = snprintf(p, buf_size - size, "%+03ld%02ld", |
| 655 | gmtoff / 3600, labs(gmtoff % 3600)); |
| 656 | if(ret != 5) { |
| 657 | FREEMEM(buf); |
| 658 | errno = EINVAL; |
| 659 | return 0; |
| 660 | } |
Lev Walkin | 9900636 | 2004-08-07 03:52:26 +0000 | [diff] [blame] | 661 | size += ret; |
| 662 | } |
| 663 | |
| 664 | if(opt_gt) { |
| 665 | if(opt_gt->buf) |
| 666 | FREEMEM(opt_gt->buf); |
| 667 | } else { |
Lev Walkin | 8e8078a | 2004-09-26 13:10:40 +0000 | [diff] [blame] | 668 | opt_gt = (GeneralizedTime_t *)CALLOC(1, sizeof *opt_gt); |
Lev Walkin | 9900636 | 2004-08-07 03:52:26 +0000 | [diff] [blame] | 669 | if(!opt_gt) { free(buf); return 0; } |
| 670 | } |
| 671 | |
Lev Walkin | 4d9528c | 2004-08-11 08:10:13 +0000 | [diff] [blame] | 672 | opt_gt->buf = (unsigned char *)buf; |
Lev Walkin | 9900636 | 2004-08-07 03:52:26 +0000 | [diff] [blame] | 673 | opt_gt->size = size; |
| 674 | |
| 675 | return opt_gt; |
| 676 | } |
| 677 | |
| 678 | |