vlm | fa67ddc | 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 | */ |
| 5 | #ifndef _GeneralizedTime_H_ |
| 6 | #define _GeneralizedTime_H_ |
| 7 | |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 8 | #include <OCTET_STRING.h> |
| 9 | |
vlm | 3a41758 | 2005-07-24 09:03:44 +0000 | [diff] [blame] | 10 | #ifdef __cplusplus |
| 11 | extern "C" { |
| 12 | #endif |
| 13 | |
vlm | d157958 | 2004-09-24 21:00:50 +0000 | [diff] [blame] | 14 | typedef OCTET_STRING_t GeneralizedTime_t; /* Implemented via OCTET STRING */ |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 15 | |
vlm | ef6355b | 2004-09-29 13:26:15 +0000 | [diff] [blame] | 16 | extern asn_TYPE_descriptor_t asn_DEF_GeneralizedTime; |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 17 | |
vlm | 39ba4c4 | 2004-09-22 16:06:28 +0000 | [diff] [blame] | 18 | asn_struct_print_f GeneralizedTime_print; |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 19 | asn_constr_check_f GeneralizedTime_constraint; |
vlm | 81057a8 | 2004-08-07 03:52:26 +0000 | [diff] [blame] | 20 | der_type_encoder_f GeneralizedTime_encode_der; |
vlm | 39ba4c4 | 2004-09-22 16:06:28 +0000 | [diff] [blame] | 21 | xer_type_encoder_f GeneralizedTime_encode_xer; |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 22 | |
| 23 | /*********************** |
| 24 | * Some handy helpers. * |
| 25 | ***********************/ |
| 26 | |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 27 | struct tm; /* <time.h> */ |
vlm | 81057a8 | 2004-08-07 03:52:26 +0000 | [diff] [blame] | 28 | |
| 29 | /* |
| 30 | * Convert a GeneralizedTime structure into time_t |
| 31 | * and optionally into struct tm. |
| 32 | * If as_gmt is given, the resulting _optional_tm4fill will have a GMT zone, |
| 33 | * instead of default local one. |
| 34 | * On error returns -1 and errno set to EINVAL |
| 35 | */ |
| 36 | time_t asn_GT2time(const GeneralizedTime_t *, struct tm *_optional_tm4fill, |
| 37 | int as_gmt); |
| 38 | |
vlm | 5ea810e | 2005-07-03 05:32:40 +0000 | [diff] [blame] | 39 | /* A version of the above function also returning the fractions of seconds */ |
| 40 | time_t asn_GT2time_frac(const GeneralizedTime_t *, |
vlm | aa11696 | 2005-07-04 12:21:51 +0000 | [diff] [blame] | 41 | int *frac_value, int *frac_digits, /* (value / (10 ^ digits)) */ |
| 42 | struct tm *_optional_tm4fill, int as_gmt); |
| 43 | |
| 44 | /* |
| 45 | * Another version returning fractions with defined precision |
| 46 | * For example, parsing of the time ending with ".1" seconds |
| 47 | * with frac_digits=3 (msec) would yield frac_value = 100. |
| 48 | */ |
| 49 | time_t asn_GT2time_prec(const GeneralizedTime_t *, |
| 50 | int *frac_value, int frac_digits, |
vlm | 5ea810e | 2005-07-03 05:32:40 +0000 | [diff] [blame] | 51 | struct tm *_optional_tm4fill, int as_gmt); |
| 52 | |
vlm | 81057a8 | 2004-08-07 03:52:26 +0000 | [diff] [blame] | 53 | /* |
| 54 | * Convert a struct tm into GeneralizedTime. |
vlm | 5ea810e | 2005-07-03 05:32:40 +0000 | [diff] [blame] | 55 | * If _optional_gt is not given, this function will try to allocate one. |
vlm | 81057a8 | 2004-08-07 03:52:26 +0000 | [diff] [blame] | 56 | * If force_gmt is given, the resulting GeneralizedTime will be forced |
vlm | ef6355b | 2004-09-29 13:26:15 +0000 | [diff] [blame] | 57 | * into a GMT time zone (encoding ends with a "Z"). |
vlm | 81057a8 | 2004-08-07 03:52:26 +0000 | [diff] [blame] | 58 | * On error, this function returns 0 and sets errno. |
| 59 | */ |
vlm | 5ea810e | 2005-07-03 05:32:40 +0000 | [diff] [blame] | 60 | GeneralizedTime_t *asn_time2GT(GeneralizedTime_t *_optional_gt, |
| 61 | const struct tm *, int force_gmt); |
| 62 | GeneralizedTime_t *asn_time2GT_frac(GeneralizedTime_t *_optional_gt, |
vlm | aa11696 | 2005-07-04 12:21:51 +0000 | [diff] [blame] | 63 | const struct tm *, int frac_value, int frac_digits, int force_gmt); |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 64 | |
vlm | 3a41758 | 2005-07-24 09:03:44 +0000 | [diff] [blame] | 65 | #ifdef __cplusplus |
| 66 | } |
| 67 | #endif |
| 68 | |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 69 | #endif /* _GeneralizedTime_H_ */ |