Home > Support > Documentation

ASN1CTime.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 1997-2007 Objective Systems, Inc.
00003  *
00004  * This software is furnished under a license and may be used and copied
00005  * only in accordance with the terms of such license and with the
00006  * inclusion of the above copyright notice. This software or any other
00007  * copies thereof may not be provided or otherwise made available to any
00008  * other person. No title to and ownership of the software is hereby
00009  * transferred.
00010  *
00011  * The information in this software is subject to change without notice
00012  * and should not be construed as a commitment by Objective Systems, Inc.
00013  *
00014  * PROPRIETARY NOTICE
00015  *
00016  * This software is an unpublished work subject to a confidentiality agreement
00017  * and is protected by copyright and trade secret law.  Unauthorized copying,
00018  * redistribution or other use of this work is prohibited.
00019  *
00020  * The above notice of copyright on this source code product does not indicate
00021  * any actual or intended publication of such source code.
00022  *
00023  *****************************************************************************/
00024 
00025 #ifndef __ASN1CTIME_H__
00026 #define __ASN1CTIME_H__
00027 
00028 #ifndef _WIN32_WCE
00029 #include <time.h>
00030 #endif
00031 #include "rtsrc/asn1CppTypes.h"
00032 #include "rtsrc/ASN1TTime.h"
00033 
00051 
00052 //
00053 // ASN1CTime
00054 // 
00055 // ISO 8601 time and date for ITU-T X.680. 
00056 //
00057 // Author Artem Bolgar.
00058 //
00059 #ifndef _NO_UTILS_CLASSES
00060 
00061 #define LOG_TMERR(pctxt,stat) ((pctxt != 0) ? LOG_RTERR (pctxt, stat) : stat)
00062 
00075 class EXTERNRT ASN1CTime : public ASN1CType {
00076  protected:
00077    OSBOOL parsed;
00078    OSBOOL derRules;
00079    
00080    char*& timeStr;
00081    int strSize;
00082 
00083    void checkCapacity();
00084 
00085    /* 
00086    * Returns time string pointer. NULL, if error occurred.
00087    */
00088    char*& getTimeStringPtr ();
00089 
00090    virtual ASN1TTime& getTimeObj () = 0;
00091    virtual const ASN1TTime& getTimeObj () const = 0;
00092 
00093    ASN1CTime(char*& buf, int bufSize, OSBOOL useDerRules); 
00094    ASN1CTime(ASN1VisibleString& buf,  OSBOOL useDerRules); 
00095  private:
00096    char timeStrBuf[MAX_TIMESTR_SIZE];
00097    char* pTimeStr; // placeholder
00098 
00099    void privateInit ();
00100 
00101  public:
00102    enum {
00103       January = 1,   Jan = 1,
00104       February = 2,  Feb = 2,
00105       March = 3,     Mar = 3,
00106       April = 4,     Apr = 4,
00107       May = 5,
00108       June = 6,      Jun = 6,
00109       July = 7,      Jul = 7,
00110       August = 8,    Aug = 8,
00111       September = 9, Sep = 9,
00112       October = 10,  Oct = 10,
00113       November = 11, Nov = 11,
00114       December = 12, Dec = 12
00115    }; 
00116 
00131    ASN1CTime (OSRTMessageBufferIF& msgBuf, char*& buf, int bufSize, 
00132               OSBOOL useDerRules); 
00133 
00149    ASN1CTime (OSRTMessageBufferIF& msgBuf, ASN1VisibleString& buf, 
00150               OSBOOL useDerRules); 
00151    
00152    ASN1CTime (ASN1Context& ctxt, char*& buf, int bufSize, 
00153               OSBOOL useDerRules); 
00154 
00155    ASN1CTime (ASN1Context& ctxt, ASN1VisibleString& buf, 
00156               OSBOOL useDerRules); 
00157    
00164    ASN1CTime (const ASN1CTime& original); 
00165 
00166    ~ASN1CTime();
00167 
00179    virtual int getYear();
00180 
00195    virtual int getMonth();
00196 
00209    virtual int getDay();
00210 
00223    virtual int getHour();
00224 
00236    virtual int getMinute();
00237 
00249    virtual int getSecond();
00250 
00263    virtual int getFraction();
00264 
00276    virtual double getFractionAsDouble();
00277 
00287    virtual int getFractionStr(char* const pBuf, size_t bufSize);
00288 
00297    virtual int getFractionLen();
00298 
00314    virtual int getDiffHour();
00315 
00331    virtual int getDiffMinute();
00332 
00348    virtual int getDiff();
00349 
00359    virtual OSBOOL getUTC();
00360 
00377    virtual time_t getTime();
00378 
00383    void setDER (OSBOOL bvalue) { derRules = bvalue; }
00384 
00396    virtual int setUTC(OSBOOL utc);
00397 
00409    virtual int setYear(int year_);
00410 
00425    virtual int setMonth(int month_);
00426 
00439    virtual int setDay(int day_);
00440 
00453    virtual int setHour(int hour_);
00454 
00466    virtual int setMinute(int minute_);
00467 
00479    virtual int setSecond(int second_);
00480 
00496    virtual int setFraction(int fraction, int fracLen = -1);
00497 
00509    virtual int setFraction (double frac, int fracLen);
00510 
00520    virtual int setFraction (char const* frac);
00521 
00538    virtual int setTime(time_t time, OSBOOL diffTime) = 0;
00539 
00557    virtual int setDiffHour(int dhour);
00558 
00577    virtual int setDiff(int dhour, int dminute);
00578 
00595    virtual int setDiff(int inMinutes);
00596 
00609    virtual int parseString(const char* string);
00610 
00620    virtual void clear();
00621 
00626    virtual int equals (ASN1CTime&);
00627 
00628    /* Returns the length of compiled time string */
00629    size_t getTimeStringLen ();
00630 
00631    /* Copies the compiled time string into specified buffer */
00632    const char* getTimeString (char* pbuf, size_t bufsize);
00633 
00634    const ASN1CTime& operator = (const ASN1CTime& );
00635    virtual OSBOOL operator == (ASN1CTime&);
00636    virtual OSBOOL operator != (ASN1CTime&);
00637    virtual OSBOOL operator > (ASN1CTime&);
00638    virtual OSBOOL operator < (ASN1CTime&);
00639    virtual OSBOOL operator >= (ASN1CTime&);
00640    virtual OSBOOL operator <= (ASN1CTime&);
00641 
00642  protected:
00643    /*
00644    * Compiles new time string accoring X.680 and ISO 8601.
00645    * Returns 0, if succeed, or error code, if error.
00646    */
00647    virtual int compileString() = 0;
00648 
00649 } ;
00650 
00651 #else
00652 typedef class _ASN1CTime : public ASN1CType {
00653  protected:
00654    _ASN1CTime(char*& buf, int bufSize, OSBOOL useDerRules) {}
00655    _ASN1CTime(ASN1VisibleString& buf,  OSBOOL useDerRules) {}
00656  public:
00657    _ASN1CTime (OSRTMessageBufferIF& msgBuf, char*& , int, OSBOOL) :
00658       ASN1CType (msgBuf) {} 
00659    _ASN1CTime (OSRTMessageBufferIF& msgBuf, ASN1VisibleString&, OSBOOL) :
00660       ASN1CType (msgBuf) {} 
00661    _ASN1CTime(ASN1Context& ctxt, char*& buf, int bufSize, 
00662       OSBOOL useDerRules) : ASN1CType (ctxt) {}  
00663    _ASN1CTime(ASN1Context& ctxt, ASN1VisibleString& buf, 
00664       OSBOOL useDerRules) : ASN1CType (ctxt) {}  
00665 } ASN1CTime;
00666 
00667 #endif // _NO_UTILS_CLASSES
00668 
00676 #endif //__ASN1CTIME_H__
00677