reSIProcate/stack  9694
Public Types | Public Member Functions | Static Public Member Functions | Private Attributes
resip::DateCategory Class Reference

Represents the "SIP-date" element in the RFC 3261 grammar. More...

#include <DateCategory.hxx>

Inheritance diagram for resip::DateCategory:
Inheritance graph
[legend]
Collaboration diagram for resip::DateCategory:
Collaboration graph
[legend]

List of all members.

Public Types

enum  { commaHandling = NoCommaTokenizing }

Public Member Functions

 DateCategory ()
 DateCategory (time_t datetime)
 DateCategory (const HeaderFieldValue &hfv, Headers::Type type, PoolBase *pool=0)
 DateCategory (const DateCategory &orig, PoolBase *pool=0)
DateCategoryoperator= (const DateCategory &)
virtual bool setDatetime (time_t datetime)
virtual void parse (ParseBuffer &pb)
virtual ParserCategoryclone () const
virtual ParserCategoryclone (void *location) const
virtual ParserCategoryclone (PoolBase *pool) const
virtual EncodeStreamencodeParsed (EncodeStream &str) const
const DayOfWeek & dayOfWeek () const
int & dayOfMonth ()
int dayOfMonth () const
Month & month ()
Month month () const
int & year ()
int year () const
int & hour ()
int hour () const
int & minute ()
int minute () const
int & second ()
int second () const

Static Public Member Functions

static DayOfWeek DayOfWeekFromData (const Data &)
static Month MonthFromData (const Data &)

Private Attributes

enum DayOfWeek mDayOfWeek
int mDayOfMonth
enum Month mMonth
int mYear
int mHour
int mMin
int mSec

Detailed Description

Represents the "SIP-date" element in the RFC 3261 grammar.

Definition at line 47 of file DateCategory.hxx.


Member Enumeration Documentation

anonymous enum
Enumerator:
commaHandling 

Definition at line 50 of file DateCategory.hxx.


Constructor & Destructor Documentation

DateCategory::DateCategory ( )

Definition at line 53 of file DateCategory.cxx.

References DebugLog, resip::Transport::error(), resip::getErrno(), setDatetime(), and strerror().

Referenced by clone().

   : ParserCategory(),
     mDayOfWeek(Sun),
     mDayOfMonth(),
     mMonth(Jan),
     mYear(0),
     mHour(0),
     mMin(0),
     mSec(0)
{
   time_t now;
   time(&now);
   if (now == ((time_t)-1))
   {
      int e = getErrno();
      DebugLog (<< "Failed to get time: " << strerror(e));
      Transport::error(e);
      return;
   }
   
   setDatetime(now);
}

Here is the call graph for this function:

DateCategory::DateCategory ( time_t  datetime)

Definition at line 76 of file DateCategory.cxx.

References setDatetime().

   : ParserCategory(),
     mDayOfWeek(Sun),
     mDayOfMonth(),
     mMonth(Jan),
     mYear(0),
     mHour(0),
     mMin(0),
     mSec(0)
{
   setDatetime(datetime);
}

Here is the call graph for this function:

DateCategory::DateCategory ( const HeaderFieldValue hfv,
Headers::Type  type,
PoolBase pool = 0 
)

Definition at line 89 of file DateCategory.cxx.

   : ParserCategory(hfv, type, pool),
     mDayOfWeek(Sun),
     mDayOfMonth(),
     mMonth(Jan),
     mYear(0),
     mHour(0),
     mMin(0),
     mSec(0)
{}
DateCategory::DateCategory ( const DateCategory orig,
PoolBase pool = 0 
)

Definition at line 102 of file DateCategory.cxx.

   : ParserCategory(rhs, pool),
     mDayOfWeek(rhs.mDayOfWeek),
     mDayOfMonth(rhs.mDayOfMonth),
     mMonth(rhs.mMonth),
     mYear(rhs.mYear),
     mHour(rhs.mHour),
     mMin(rhs.mMin),
     mSec(rhs.mSec)
{}

Member Function Documentation

ParserCategory * DateCategory::clone ( ) const [virtual]

Implements resip::ParserCategory.

Definition at line 566 of file DateCategory.cxx.

References DateCategory().

{
   return new DateCategory(*this);
}

Here is the call graph for this function:

ParserCategory * DateCategory::clone ( void *  location) const [virtual]

Implements resip::ParserCategory.

Definition at line 572 of file DateCategory.cxx.

References DateCategory().

{
   return new (location) DateCategory(*this);
}

Here is the call graph for this function:

ParserCategory * DateCategory::clone ( PoolBase pool) const [virtual]

Implements resip::ParserCategory.

Definition at line 578 of file DateCategory.cxx.

References DateCategory().

{
   return new (pool) DateCategory(*this, pool);
}

Here is the call graph for this function:

int & DateCategory::dayOfMonth ( )

Definition at line 437 of file DateCategory.cxx.

References resip::LazyParser::checkParsed(), and mDayOfMonth.

Referenced by main().

{
   checkParsed();
   return mDayOfMonth;
}

Here is the call graph for this function:

int DateCategory::dayOfMonth ( ) const

Definition at line 444 of file DateCategory.cxx.

References resip::LazyParser::checkParsed(), and mDayOfMonth.

{
   checkParsed();
   return mDayOfMonth;
}

Here is the call graph for this function:

const DayOfWeek & DateCategory::dayOfWeek ( ) const

Definition at line 430 of file DateCategory.cxx.

References resip::LazyParser::checkParsed(), and mDayOfWeek.

Referenced by main(), and parse().

{
   checkParsed();
   return mDayOfWeek;
}

Here is the call graph for this function:

DayOfWeek DateCategory::DayOfWeekFromData ( const Data dow) [static]

Definition at line 274 of file DateCategory.cxx.

References resip::Data::data(), days::day, dayofweek_hash(), len, days::name, and resip::Data::size().

Referenced by parse().

{
   static const unsigned int MIN_WORD_LENGTH = 3;
   static const unsigned int MAX_WORD_LENGTH = 3;
   static const int MAX_HASH_VALUE = 12;

   register const char *str = dow.data();
   register Data::size_type len = dow.size();

   static struct days wordlist[] =
      {
         {""}, {""}, {""},
         {"Tue", Tue},
         {"Fri", Fri},
         {"Sun", Sun},
         {""},
         {"Thu", Thu},
         {"Mon", Mon},
         {""},
         {"Wed", Wed},
         {""},
         {"Sat", Sat}
      };

   if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH)
   {
      register int key = dayofweek_hash (str, (unsigned int)len);
      
      if (key <= MAX_HASH_VALUE && key >= 0)
      {
         register const char *s = wordlist[key].name;
         
         if (*str == *s && !strncmp (str+1, s+1, len-1))
         {
            return wordlist[key].day;
         }
      }
   }
   return Sun;
}

Here is the call graph for this function:

EncodeStream & DateCategory::encodeParsed ( EncodeStream str) const [virtual]

Implements resip::LazyParser.

Definition at line 593 of file DateCategory.cxx.

References resip::Symbols::COLON, resip::Symbols::COMMA, mDayOfMonth, mDayOfWeek, mHour, mMin, mMonth, mSec, mYear, pad2(), and resip::Symbols::SPACE.

{
   str << DayOfWeekData[mDayOfWeek] // Mon
       << Symbols::COMMA[0] << Symbols::SPACE[0];
   
   pad2(mDayOfMonth, str);  //  04

   str << Symbols::SPACE[0]
       << MonthData[mMonth] << Symbols::SPACE[0] // Nov
       << mYear << Symbols::SPACE[0]; // 2002

   pad2(mHour, str);
   str << Symbols::COLON[0];
   pad2(mMin, str);
   str << Symbols::COLON[0];
   pad2(mSec, str);
   str << " GMT";

   return str;
}

Here is the call graph for this function:

int & DateCategory::hour ( )

Definition at line 479 of file DateCategory.cxx.

References resip::LazyParser::checkParsed(), and mHour.

Referenced by main().

{
   checkParsed();
   return mHour;
}

Here is the call graph for this function:

int DateCategory::hour ( ) const

Definition at line 486 of file DateCategory.cxx.

References resip::LazyParser::checkParsed(), and mHour.

{
   checkParsed();
   return mHour;
}

Here is the call graph for this function:

int & DateCategory::minute ( )

Definition at line 493 of file DateCategory.cxx.

References resip::LazyParser::checkParsed(), and mMin.

Referenced by main().

{
   checkParsed();
   return mMin;
}

Here is the call graph for this function:

int DateCategory::minute ( ) const

Definition at line 500 of file DateCategory.cxx.

References resip::LazyParser::checkParsed(), and mMin.

{
   checkParsed();
   return mMin;
}

Here is the call graph for this function:

Month & DateCategory::month ( )

Definition at line 451 of file DateCategory.cxx.

References resip::LazyParser::checkParsed(), and mMonth.

Referenced by main(), and parse().

{
   checkParsed();
   return mMonth;
}

Here is the call graph for this function:

Month DateCategory::month ( ) const

Definition at line 458 of file DateCategory.cxx.

References resip::LazyParser::checkParsed(), and mMonth.

{
   checkParsed();
   return mMonth;
}

Here is the call graph for this function:

Month DateCategory::MonthFromData ( const Data mon) [static]

Definition at line 382 of file DateCategory.cxx.

References resip::Data::data(), len, month_hash(), months::name, resip::Data::size(), and months::type.

Referenced by parse().

{
   static const unsigned int MIN_WORD_LENGTH = 3;
   static const unsigned int MAX_WORD_LENGTH = 3;
   static const int MAX_HASH_VALUE = 33;

   register const char *str = mon.data();
   register Data::size_type len = mon.size();

   static struct months wordlist[] =
      {
         {""}, {""}, {""},
         {"Jun", Jun},
         {""}, {""},
         {"Nov", Nov},
         {"Jul", Jul},
         {"Feb", Feb},
         {""}, {""},
         {"Dec", Dec},
         {"Sep", Sep},
         {"Jan", Jan},
         {""}, {""}, {""},
         {"Oct", Oct},
         {"Apr", Apr},
         {""}, {""}, {""}, {""},
         {"Mar", Mar},
         {""}, {""}, {""}, {""},
         {"Aug", Aug},
         {""}, {""}, {""}, {""},
         {"May", May}
      };

   if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH)
   {
      register int key = month_hash (str, (unsigned int)len);

      if (key <= MAX_HASH_VALUE && key >= 0)
      {
         register const char *s = wordlist[key].name;

         if (*str == *s && !strncmp (str + 1, s + 1, mon.size()-1))
            return wordlist[key].type;
      }
   }
   return Jan;
}

Here is the call graph for this function:

DateCategory & DateCategory::operator= ( const DateCategory rhs)

Definition at line 115 of file DateCategory.cxx.

References mDayOfMonth, mDayOfWeek, mHour, mMin, mMonth, mSec, and mYear.

{
   if (this != &rhs)
   {
      ParserCategory::operator=(rhs);
      mDayOfWeek = rhs.mDayOfWeek;
      mDayOfMonth = rhs.mDayOfMonth;
      mMonth = rhs.mMonth;
      mYear = rhs.mYear;
      mHour = rhs.mHour;
      mMin = rhs.mMin;
      mSec = rhs.mSec;
   }
   return *this;
}
void DateCategory::parse ( ParseBuffer pb) [virtual]
int & DateCategory::second ( )

Definition at line 507 of file DateCategory.cxx.

References resip::LazyParser::checkParsed(), and mSec.

Referenced by main().

{
   checkParsed();
   return mSec;
}

Here is the call graph for this function:

int DateCategory::second ( ) const

Definition at line 514 of file DateCategory.cxx.

References resip::LazyParser::checkParsed(), and mSec.

{
   checkParsed();
   return mSec;
}

Here is the call graph for this function:

bool DateCategory::setDatetime ( time_t  datetime) [virtual]

Definition at line 132 of file DateCategory.cxx.

References DebugLog, resip::Transport::error(), resip::getErrno(), mDayOfMonth, mDayOfWeek, mHour, mMin, mMonth, mSec, mYear, and strerror().

Referenced by DateCategory().

{
   struct tm gmt;
#if defined(WIN32) || defined(__sun)
   struct tm *gmtp = gmtime(&datetime);
   if (gmtp == 0)
   {
        int e = getErrno();
        DebugLog (<< "Failed to convert to gmt: " << strerror(e));
        Transport::error(e);
        return false;
   }
   memcpy(&gmt,gmtp,sizeof(gmt));
#else
  if (gmtime_r(&datetime, &gmt) == 0)
  {
     int e = getErrno();
     DebugLog (<< "Failed to convert to gmt: " << strerror(e));
     Transport::error(e);
     return false;
  }
#endif

   mDayOfWeek = static_cast<DayOfWeek>(gmt.tm_wday);
   mDayOfMonth = gmt.tm_mday;
   mMonth = static_cast<Month>(gmt.tm_mon);
   mYear = gmt.tm_year + 1900;
   mHour = gmt.tm_hour;
   mMin = gmt.tm_min;
   mSec = gmt.tm_sec;
   DebugLog (<< "Set date: day=" << mDayOfWeek 
             << " month=" << mMonth
             << " year=" << mYear
             << " " << mHour << ":" << mMin << ":" << mSec);
   return true;
}

Here is the call graph for this function:

int & DateCategory::year ( )

Definition at line 465 of file DateCategory.cxx.

References resip::LazyParser::checkParsed(), and mYear.

Referenced by main().

{
   checkParsed();
   return mYear;
}

Here is the call graph for this function:

int DateCategory::year ( ) const

Definition at line 472 of file DateCategory.cxx.

References resip::LazyParser::checkParsed(), and mYear.

{
   checkParsed();
   return mYear;
}

Here is the call graph for this function:


Member Data Documentation

Definition at line 89 of file DateCategory.hxx.

Referenced by dayOfMonth(), encodeParsed(), operator=(), parse(), and setDatetime().

enum DayOfWeek resip::DateCategory::mDayOfWeek [private]

Definition at line 88 of file DateCategory.hxx.

Referenced by dayOfWeek(), encodeParsed(), operator=(), parse(), and setDatetime().

Definition at line 92 of file DateCategory.hxx.

Referenced by encodeParsed(), hour(), operator=(), parse(), and setDatetime().

Definition at line 93 of file DateCategory.hxx.

Referenced by encodeParsed(), minute(), operator=(), parse(), and setDatetime().

enum Month resip::DateCategory::mMonth [private]

Definition at line 90 of file DateCategory.hxx.

Referenced by encodeParsed(), month(), operator=(), parse(), and setDatetime().

Definition at line 94 of file DateCategory.hxx.

Referenced by encodeParsed(), operator=(), parse(), second(), and setDatetime().

Definition at line 91 of file DateCategory.hxx.

Referenced by encodeParsed(), operator=(), parse(), setDatetime(), and year().


The documentation for this class was generated from the following files: