|
reSIProcate/stack
9694
|
Represents the "SIP-date" element in the RFC 3261 grammar. More...
#include <DateCategory.hxx>


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) | |
| DateCategory & | operator= (const DateCategory &) |
| virtual bool | setDatetime (time_t datetime) |
| virtual void | parse (ParseBuffer &pb) |
| virtual ParserCategory * | clone () const |
| virtual ParserCategory * | clone (void *location) const |
| virtual ParserCategory * | clone (PoolBase *pool) const |
| virtual EncodeStream & | encodeParsed (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 |
Represents the "SIP-date" element in the RFC 3261 grammar.
Definition at line 47 of file DateCategory.hxx.
| anonymous enum |
Definition at line 50 of file DateCategory.hxx.
| 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); }

| 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); }

| 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) {}
| ParserCategory * DateCategory::clone | ( | ) | const [virtual] |
Implements resip::ParserCategory.
Definition at line 566 of file DateCategory.cxx.
References DateCategory().
{
return new DateCategory(*this);
}

| 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);
}

| 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);
}

| int & DateCategory::dayOfMonth | ( | ) |
Definition at line 437 of file DateCategory.cxx.
References resip::LazyParser::checkParsed(), and mDayOfMonth.
Referenced by main().
{
checkParsed();
return mDayOfMonth;
}

| int DateCategory::dayOfMonth | ( | ) | const |
Definition at line 444 of file DateCategory.cxx.
References resip::LazyParser::checkParsed(), and mDayOfMonth.
{
checkParsed();
return mDayOfMonth;
}

| 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;
}

| 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;
}

| 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;
}

| int & DateCategory::hour | ( | ) |
Definition at line 479 of file DateCategory.cxx.
References resip::LazyParser::checkParsed(), and mHour.
Referenced by main().
{
checkParsed();
return mHour;
}

| int DateCategory::hour | ( | ) | const |
Definition at line 486 of file DateCategory.cxx.
References resip::LazyParser::checkParsed(), and mHour.
{
checkParsed();
return mHour;
}

| int & DateCategory::minute | ( | ) |
Definition at line 493 of file DateCategory.cxx.
References resip::LazyParser::checkParsed(), and mMin.
Referenced by main().
{
checkParsed();
return mMin;
}

| int DateCategory::minute | ( | ) | const |
Definition at line 500 of file DateCategory.cxx.
References resip::LazyParser::checkParsed(), and mMin.
{
checkParsed();
return mMin;
}

| 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;
}

| Month DateCategory::month | ( | ) | const |
Definition at line 458 of file DateCategory.cxx.
References resip::LazyParser::checkParsed(), and mMonth.
{
checkParsed();
return mMonth;
}

| 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;
}

| 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] |
Implements resip::LazyParser.
Definition at line 521 of file DateCategory.cxx.
References resip::ParseBuffer::assertEof(), resip::Symbols::COLON, resip::Symbols::COMMA, resip::ParseBuffer::data(), dayOfWeek(), DayOfWeekFromData(), resip::ParseBuffer::integer(), mDayOfMonth, mDayOfWeek, mHour, mMin, mMonth, month(), MonthFromData(), mSec, mYear, resip::ParseBuffer::skipChar(), resip::ParseBuffer::skipNonWhitespace(), resip::ParseBuffer::skipToChar(), and resip::ParseBuffer::skipWhitespace().
{
// Mon, 04 Nov 2002 17:34:15 GMT
const char* anchor = pb.skipWhitespace();
pb.skipToChar(Symbols::COMMA[0]);
Data dayOfWeek;
pb.data(dayOfWeek, anchor);
mDayOfWeek = DateCategory::DayOfWeekFromData(dayOfWeek);
pb.skipChar(Symbols::COMMA[0]);
pb.skipWhitespace();
mDayOfMonth = pb.integer();
anchor = pb.skipWhitespace();
pb.skipNonWhitespace();
Data month;
pb.data(month, anchor);
mMonth = DateCategory::MonthFromData(month);
pb.skipWhitespace();
mYear = pb.integer();
pb.skipWhitespace();
mHour = pb.integer();
pb.skipChar(Symbols::COLON[0]);
mMin = pb.integer();
pb.skipChar(Symbols::COLON[0]);
mSec = pb.integer();
pb.skipWhitespace();
pb.skipChar('G');
pb.skipChar('M');
pb.skipChar('T');
pb.skipWhitespace();
pb.assertEof();
}

| int & DateCategory::second | ( | ) |
Definition at line 507 of file DateCategory.cxx.
References resip::LazyParser::checkParsed(), and mSec.
Referenced by main().
{
checkParsed();
return mSec;
}

| int DateCategory::second | ( | ) | const |
Definition at line 514 of file DateCategory.cxx.
References resip::LazyParser::checkParsed(), and mSec.
{
checkParsed();
return mSec;
}

| 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;
}

| int & DateCategory::year | ( | ) |
Definition at line 465 of file DateCategory.cxx.
References resip::LazyParser::checkParsed(), and mYear.
Referenced by main().
{
checkParsed();
return mYear;
}

| int DateCategory::year | ( | ) | const |
Definition at line 472 of file DateCategory.cxx.
References resip::LazyParser::checkParsed(), and mYear.
{
checkParsed();
return mYear;
}

int resip::DateCategory::mDayOfMonth [private] |
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().
int resip::DateCategory::mHour [private] |
Definition at line 92 of file DateCategory.hxx.
Referenced by encodeParsed(), hour(), operator=(), parse(), and setDatetime().
int resip::DateCategory::mMin [private] |
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().
int resip::DateCategory::mSec [private] |
Definition at line 94 of file DateCategory.hxx.
Referenced by encodeParsed(), operator=(), parse(), second(), and setDatetime().
int resip::DateCategory::mYear [private] |
Definition at line 91 of file DateCategory.hxx.
Referenced by encodeParsed(), operator=(), parse(), setDatetime(), and year().
1.7.5.1