Harald Welte | 92c45f3 | 2010-06-12 18:59:38 +0200 | [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 | |
| 8 | #include <OCTET_STRING.h> |
| 9 | |
| 10 | #ifdef __cplusplus |
| 11 | extern "C" { |
| 12 | #endif |
| 13 | |
| 14 | typedef OCTET_STRING_t GeneralizedTime_t; /* Implemented via OCTET STRING */ |
| 15 | |
| 16 | extern asn_TYPE_descriptor_t asn_DEF_GeneralizedTime; |
| 17 | |
| 18 | asn_struct_print_f GeneralizedTime_print; |
| 19 | asn_constr_check_f GeneralizedTime_constraint; |
| 20 | der_type_encoder_f GeneralizedTime_encode_der; |
| 21 | xer_type_encoder_f GeneralizedTime_encode_xer; |
| 22 | |
| 23 | /*********************** |
| 24 | * Some handy helpers. * |
| 25 | ***********************/ |
| 26 | |
| 27 | struct tm; /* <time.h> */ |
| 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 | |
| 39 | /* A version of the above function also returning the fractions of seconds */ |
| 40 | time_t asn_GT2time_frac(const GeneralizedTime_t *, |
| 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, |
| 51 | struct tm *_optional_tm4fill, int as_gmt); |
| 52 | |
| 53 | /* |
| 54 | * Convert a struct tm into GeneralizedTime. |
| 55 | * If _optional_gt is not given, this function will try to allocate one. |
| 56 | * If force_gmt is given, the resulting GeneralizedTime will be forced |
| 57 | * into a GMT time zone (encoding ends with a "Z"). |
| 58 | * On error, this function returns 0 and sets errno. |
| 59 | */ |
| 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, |
| 63 | const struct tm *, int frac_value, int frac_digits, int force_gmt); |
| 64 | |
| 65 | #ifdef __cplusplus |
| 66 | } |
| 67 | #endif |
| 68 | |
| 69 | #endif /* _GeneralizedTime_H_ */ |