📄 sipdate.cxx
字号:
"failed in Method Hour() decode the Date string", __FILE__, __LINE__, DECODE_HOUR_FAILED); } } string DIGIT = "0123456789"; int test = testhour.find_first_not_of(DIGIT); if (test == -1) { hour = testhour; } else { if (SipParserMode::sipParserMode()) { cpLog(LOG_ERR, "Failed to Decode in WEEKDAY() of Date :( "); throw SipDateParserException( "failed in Method Hour() decode the Date string", __FILE__, __LINE__, DECODE_HOUR_FAILED); } }}voidSipDate::setSeconds(const Data & newseconds){ string testseconds = newseconds.convertString(); if (testseconds.length() > 2) { if (SipParserMode::sipParserMode()) { cpLog(LOG_ERR, "Failed to Decode in seconds() of Date :( "); throw SipDateParserException("Failed in parsing seconds" , __FILE__, __LINE__, DECODE_SECONDS_FAILED); } } string DIGIT = "0123456789"; int test = testseconds.find_first_not_of(DIGIT); if (test == -1) { seconds = testseconds; } else { if (SipParserMode::sipParserMode()) { cpLog(LOG_ERR, "Failed to Decode in seconds() of Date :( "); throw SipDateParserException("Failed in parsing seconds" , __FILE__, __LINE__, DECODE_SECONDS_FAILED); } }}voidSipDate::setMinutes(const Data & newminutes){ string testminutes = newminutes.convertString(); if (testminutes.length() > 2) { if (SipParserMode::sipParserMode()) { cpLog(LOG_ERR, "Failed to Decode in setMinutes() of Date :( "); throw SipDateParserException("Failed in SetMinutes()" , __FILE__, __LINE__, DECODE_MINS_FAILED); } } string DIGIT = "0123456789"; int test = testminutes.find_first_not_of(DIGIT); if (test == -1) { minutes = testminutes; } else { if (SipParserMode::sipParserMode()) { cpLog(LOG_ERR, "Failed to Decode in setMinutes() of Date :( "); throw SipDateParserException("Failed in setMinutes" , __FILE__, __LINE__, DECODE_MINS_FAILED); } }}voidSipDate::setTimezone(const Data & newtimezone){ string temptimezone = newtimezone.convertString(); Data testvalue; int test1 = temptimezone.find("+"); int test2 = temptimezone.find("-"); if (test1 == 0) { timezone = temptimezone; } else if (test2 == 0) { timezone = temptimezone; } else if (newtimezone.length() >= 1) { string ALPHA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; int testtime = temptimezone.find_first_not_of(ALPHA); if (testtime == -1) { timezone = temptimezone; } else { if (SipParserMode::sipParserMode()) { cpLog(LOG_ERR, "Failed to Decode in setTimeZone of Date :( "); throw SipDateParserException("Failed in setTimeZones" , __FILE__, __LINE__, DECODE_TIMEZONE_FAILED); } } } else if (temptimezone == TIMEZONE1 || temptimezone == TIMEZONE2 || temptimezone == TIMEZONE3 || temptimezone == TIMEZONE4 || temptimezone == TIMEZONE5 || temptimezone == TIMEZONE6 || temptimezone == TIMEZONE7 || temptimezone == TIMEZONE8 || temptimezone == TIMEZONE9 || temptimezone == TIMEZONE10 ) { timezone = temptimezone; } else { if (SipParserMode::sipParserMode()) { cpLog(LOG_ERR, "Failed to Decode in setTimeZone of Date :( "); throw SipDateParserException("Failed in setTimeZones" , __FILE__, __LINE__, DECODE_TIMEZONE_FAILED); } }}voidSipDate::setDay(const Data & newData){ if (newData.length() > 2) { if (SipParserMode::sipParserMode()) { cpLog(LOG_ERR, "Failed to Decode in setDay of Date :( "); throw SipDateParserException("Failed in setDay" , __FILE__, __LINE__, DECODE_DAY_FAILED); } } else { string daytest = newData.convertString(); string DIGIT = "0123456789"; int testday = daytest.find_first_not_of(DIGIT); if (testday == -1) { day = newData; } else { if (SipParserMode::sipParserMode()) { cpLog(LOG_ERR, "Failed to Decode in setDay of Date :( "); throw SipDateParserException("Failed in setDay" , __FILE__, __LINE__, DECODE_DAY_FAILED); } } }}voidSipDate::setYear(const Data & newData){ if (newData.length() < 2 || newData.length() > 4) { if (SipParserMode::sipParserMode()) { cpLog(LOG_ERR, "Failed to Decode in setYear of Date :( "); throw SipDateParserException("Failed in setYear" , __FILE__, __LINE__, DECODE_YEAR_FAILED); } } else { string yeartest = newData.convertString(); string DIGIT = "0123456789"; int testyear = yeartest.find_first_not_of(DIGIT); if (testyear == -1) { year = newData; } else { if (SipParserMode::sipParserMode()) { cpLog(LOG_ERR, "Failed to Decode in setYear of Date :( "); throw SipDateParserException("Failed in setYear" , __FILE__, __LINE__, DECODE_YEAR_FAILED); } } }}SipDate::SipDate( const SipDate& src) : day(src.day), year(src.year), month(src.month), weekday(src.weekday), hour(src.hour), seconds(src.seconds), minutes(src.minutes), timezone(src.timezone), timezonediff(src.timezonediff){}Data SipDate::get(){ Data sipdate; sipdate = encode(); return sipdate;}boolSipDate::operator == (const SipDate& src) const{ cpLog(LOG_DEBUG_STACK, "SipDate == operator"); if ( ( day == src.day) && ( year == src.year) && ( month == src.month) && ( weekday == src.weekday) && ( hour == src.hour ) && ( seconds == src.seconds ) && ( minutes == src.minutes ) && ( timezone == src.timezone ) && ( timezonediff == src.timezonediff) ) { cpLog(LOG_DEBUG_STACK, "SipDate == operator returning true :)"); return true; } else { cpLog(LOG_DEBUG_STACK, "SipDate == operator returning false:("); return false; }}#define IsLess(a, b) if ((a) < (b)) return true; else if ((b) < (a)) return falseboolSipDate::operator <(const SipDate& src) const{ // !dlb! this is certainly wrong -- deal with month names and timezones IsLess(year, src.year); IsLess(month, src.month); IsLess(day, src.day); IsLess(hour, src.hour); IsLess(minutes, src.minutes); IsLess(seconds, src.seconds); IsLess(timezone, src.timezone); IsLess(timezonediff, src.timezonediff); return false;}#undef IsLessconst SipDate&SipDate::operator=( const SipDate& src){ if (&src != this) { day = src.day; year = src.year; month = src.month; weekday = src.weekday; hour = src.hour; seconds = src.seconds; minutes = src.minutes; timezone = src.timezone; timezonediff = src.timezonediff; } return *this;}Data SipDate::encode() const{ Data data; int weeklen = weekday.length(); int daylen = day.length(); int monlen = month.length(); int yearlen = year.length(); int hourlen = hour.length(); int minlen = minutes.length(); int timezonelen = timezone.length(); if ( (weeklen) && (daylen) && (monlen) && (yearlen) && (hourlen) && (minlen) && (timezonelen) ) { data += SIP_DATE; data += SP; data += weekday; data += ","; data += SP; data += day; data += SP; data += month; data += SP; data += year; data += SP; data += hour; data += ":"; data += minutes; data += ":"; data += seconds; data += SP; data += timezone; data += CRLF; } return data;}boolSipDate::getFlagDate() const{ return flagDate;}Data SipDate::getData() const{ Data data; int weeklen = weekday.length(); int daylen = day.length(); int monlen = month.length(); int yearlen = year.length(); int hourlen = hour.length(); int minlen = minutes.length(); int timezonelen = timezone.length(); if ( (weeklen) && (daylen) && (monlen) && (yearlen) && (hourlen) && (minlen) && (timezonelen) ) { data += weekday; data += ","; data += SP; data += day; data += SP; data += month; data += SP; data += year; data += SP; data += hour; data += ":"; data += minutes; data += ":"; data += seconds; data += SP; data += timezone; } return data;}void SipDate::set(const Data& data){ try { decode(data); } catch ( SipDateParserException&) { cpLog(LOG_ERR, "could not decode the date correctly"); }}SipHeader*SipDate::duplicate() const{ return new SipDate(*this);}boolSipDate::compareSipHeader(SipHeader* msg) const{ SipDate* otherMsg = dynamic_cast<SipDate*>(msg); if(otherMsg != 0) { return (*this == *otherMsg); } else { return false; }}/* Local Variables: *//* c-file-style: "stroustrup" *//* indent-tabs-mode: nil *//* c-file-offsets: ((access-label . -) (inclass . ++)) *//* c-basic-offset: 4 *//* End: */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -