⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sipdate.cxx

📁 Vovida 社区开源的 SIP 协议源码
💻 CXX
📖 第 1 页 / 共 2 页
字号:
/* ==================================================================== * The Vovida Software License, Version 1.0  *  * Copyright (c) 2000 Vovida Networks, Inc.  All rights reserved. *  * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: *  * 1. Redistributions of source code must retain the above copyright *    notice, this list of conditions and the following disclaimer. *  * 2. Redistributions in binary form must reproduce the above copyright *    notice, this list of conditions and the following disclaimer in *    the documentation and/or other materials provided with the *    distribution. *  * 3. The names "VOCAL", "Vovida Open Communication Application Library", *    and "Vovida Open Communication Application Library (VOCAL)" must *    not be used to endorse or promote products derived from this *    software without prior written permission. For written *    permission, please contact vocal@vovida.org. * * 4. Products derived from this software may not be called "VOCAL", nor *    may "VOCAL" appear in their name, without prior written *    permission of Vovida Networks, Inc. *  * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND * NON-INFRINGEMENT ARE DISCLAIMED.  IN NO EVENT SHALL VOVIDA * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * DAMAGE. *  * ==================================================================== *  * This software consists of voluntary contributions made by Vovida * Networks, Inc. and many individuals on behalf of Vovida Networks, * Inc.  For more information on Vovida Networks, Inc., please see * <http://www.vovida.org/>. * */static const char* const SipDate_cxx_Version =    "$Id: SipDate.cxx,v 1.33 2002/05/01 22:41:04 jason Exp $";#include "global.h"#include "symbols.hxx"#include "cpLog.h"#include "SipDate.hxx"#include "SipParserMode.hxx"static const char SIP_DATE[] = "Date: ";using namespace Vocal;stringSipDateParserException::getName( void ) const{    return "SipDateParserException";}SipDate::SipDate(){}SipDate::SipDate( const Data& srcData )  :flagDate(false){    try    {        decode(srcData);    }    catch (SipDateParserException&)    {        if (SipParserMode::sipParserMode())        {            cpLog(LOG_ERR, "Failed to Decode in Date Constructor :( ");            throw SipDateParserException(                "failed to decode the Date string",                __FILE__,                __LINE__, DECODE_DATE_FAILED);        }    }}void SipDate::decode(const Data& data){    Data nData = data;    try    {        scanSipDate(nData);    }    catch (SipDateParserException exception)    {        if (SipParserMode::sipParserMode())        {            cpLog(LOG_ERR, "Failed to Decode in Decode of Date :( ");            throw SipDateParserException(                "failed to decode the Date string",                __FILE__,                __LINE__, DECODE_DATE_FAILED);        }    }}voidSipDate::scanSipDate(const Data &tmpdata){    Data newdata = tmpdata ;    Data dateval;    int ret = newdata.match(",", &dateval, true);    if (ret == NOT_FOUND)    {        if (SipParserMode::sipParserMode())        {            cpLog(LOG_ERR, "Failed to Decode in scanSipDate of Date :( ");            throw SipDateParserException(                "failed to decode the Date string",                __FILE__,                __LINE__, DECODE_DATE_FAILED);        }    }    else if (ret == FOUND)    {        setWeekday(dateval);        parseDate(newdata);    }    else if (ret == FIRST)    {        if (SipParserMode::sipParserMode())        {            cpLog(LOG_ERR, "Failed to Decode in scanSipDate of Date :( ");            throw SipDateParserException(                "failed to decode the Date string",                __FILE__,                __LINE__, DECODE_DATE_FAILED);        }    }}voidSipDate::parseDate(const Data & mdata){   flagDate = true;    Data mvalue;    Data mondata = mdata;    int ret = mondata.match(" ", &mvalue, true);    if (ret == FOUND)    {        if (SipParserMode::sipParserMode())        {            cpLog(LOG_ERR, "Failed to Decode in ParseDate of Date :( ");            throw SipDateParserException(                "failed to ParseDate() decode the Date string",                __FILE__,                __LINE__, DECODE_DATE_FAILED);        }    }    else if (ret == NOT_FOUND)    {        if (SipParserMode::sipParserMode())        {            cpLog(LOG_ERR, "Failed to Decode in ParseDate of Date :( ");            throw SipDateParserException(                "failed to ParseDate() decode the Date string",                __FILE__,                __LINE__, DECODE_DATE_FAILED);        }    }    else if (ret == FIRST)    {        Data monvalue;        int retn = mondata.match(" ", &monvalue, true);        if (retn == FOUND)        {            setDay(monvalue);            Data mthvalue;            Data tpdata = mondata;            int retrn = tpdata.match(" ", &mthvalue, true);            if (retrn == FOUND)            {                setMonth(mthvalue);                Data tempdata = tpdata;                Data tempValue;                int rt = tempdata.match(" ", &tempValue, true);                if (rt == FOUND)                {                    setYear(tempValue);                    parseTime(tempdata);                }                else if (rt == NOT_FOUND)                {                    if (SipParserMode::sipParserMode())                    {                        cpLog(LOG_ERR, "Failed to Decode in ParseDate of Date :( ");                        throw SipDateParserException(                            "failed to ParseDate() decode the Date string",                            __FILE__,                            __LINE__, DECODE_DATE_FAILED);                    }                }                else if (rt == FIRST)                {                    if (SipParserMode::sipParserMode())                    {                        cpLog(LOG_ERR, "Failed to Decode in ParseDate of Date :( ");                        throw SipDateParserException(                            "failed to ParseDate() decode the Date string",                            __FILE__,                            __LINE__, DECODE_DATE_FAILED);                    }                }            }            else if (retrn == NOT_FOUND)            {                if (SipParserMode::sipParserMode())                {                    cpLog(LOG_ERR, "Failed to Decode in ParseDate of Date :( ");                    throw SipDateParserException(                        "failed to ParseDate() decode the Date string",                        __FILE__,                        __LINE__, DECODE_DATE_FAILED);                }            }            else if (retrn == FIRST)            {                if (SipParserMode::sipParserMode())                {                    cpLog(LOG_ERR, "Failed to Decode in ParseDate of Date :( ");                    throw SipDateParserException(                        "failed to ParseDate() decode the Date string",                        __FILE__,                        __LINE__, DECODE_DATE_FAILED);                }            }        }        else if (retn == NOT_FOUND)        {            if (SipParserMode::sipParserMode())            {                cpLog(LOG_ERR, "Failed to Decode in ParseDate of Date :( ");                throw SipDateParserException(                    "failed to ParseDate() decode the Date string",                    __FILE__,                    __LINE__, DECODE_DATE_FAILED);            }        }        else if (retn == FIRST)        {            if (SipParserMode::sipParserMode())            {                cpLog(LOG_ERR, "Failed to Decode in ParseDate of Date :( ");                throw SipDateParserException(                    "failed to ParseDate() decode the Date string",                    __FILE__,                    __LINE__, DECODE_DATE_FAILED);            }        }    }}voidSipDate::parseTime(const Data & newdata){    Data timedata = newdata;    Data timevalue;    int ret = timedata.match(":", &timevalue, true);    if (ret == FOUND)    {        setHour(timevalue);        Data timeleftdata = timedata;        Data timeleftvalue;        int retrn = timeleftdata.match(":", &timeleftvalue, true);        if (retrn == FOUND)        {            setMinutes(timeleftvalue);            Data seconddata = timeleftdata;            Data secondvalue;            int rt = seconddata.match(" ", &secondvalue, true);            if (rt == FOUND)            {                setSeconds(secondvalue);                setTimezone(seconddata);            }            else if (rt == NOT_FOUND)            {                if (SipParserMode::sipParserMode())                {                    cpLog(LOG_ERR, "Failed to Decode in Method ParseTime() of Date :( ");                    throw SipDateParserException(                        "failed in Method ParseDate() decode the Date string",                        __FILE__,                        __LINE__, DECODE_DATE_FAILED);                }            }            else if (rt == FIRST)            {                if (SipParserMode::sipParserMode())                {                    cpLog(LOG_ERR, "Failed to Decode in Method ParseTime() of Date :( ");                    throw SipDateParserException(                        "failed in Method ParseDate() decode the Date string",                        __FILE__,                        __LINE__, DECODE_DATE_FAILED);                }            }        }        else if (retrn == NOT_FOUND)        {            if (SipParserMode::sipParserMode())            {                cpLog(LOG_ERR, "Failed to Decode in Method ParseTime() of Date :( ");                throw SipDateParserException(                    "failed in Method ParseDate() decode the Date string",                    __FILE__,                    __LINE__, DECODE_DATE_FAILED);            }        }        else if (retrn == FIRST)        {            if (SipParserMode::sipParserMode())            {                cpLog(LOG_ERR, "Failed to Decode in Method ParseTime() of Date :( ");                throw SipDateParserException(                    "failed in Method ParseDate() decode the Date string",                    __FILE__,                    __LINE__, DECODE_DATE_FAILED);            }        }    }    else if (ret == NOT_FOUND)    {        if (SipParserMode::sipParserMode())        {            cpLog(LOG_ERR, "Failed to Decode in Method ParseTime() of Date :( ");            throw SipDateParserException(                "failed in Method ParseDate() decode the Date string",                __FILE__,                __LINE__, DECODE_DATE_FAILED);        }    }    else if (ret == FIRST)    {        if (SipParserMode::sipParserMode())        {            cpLog(LOG_ERR, "Failed to Decode in Method ParseTime() of Date :( ");            throw SipDateParserException(                "failed in Method ParseDate() decode the Date string",                __FILE__,                __LINE__, DECODE_DATE_FAILED);        }    }}voidSipDate::setMonth(const Data & bdata){    Data monthdata = bdata;    if (monthdata == MONTH1 || monthdata == MONTH2 || monthdata == MONTH3 ||            monthdata == MONTH4 || monthdata == MONTH5 || monthdata == MONTH6 ||            monthdata == MONTH7 || monthdata == MONTH8 || monthdata == MONTH9 ||            monthdata == MONTH10 || monthdata == MONTH11 || monthdata == MONTH12 )    {        month = monthdata;    }    else    {        if (SipParserMode::sipParserMode())        {            cpLog(LOG_ERR, "Failed to Decode in Method setMonth() of Date :( ");            throw SipDateParserException(                "failed in Method setMonth() decode the Date string",                __FILE__,                __LINE__, DECODE_MONTH_FAILED);        }    }}voidSipDate::setWeekday(const Data & newweekday){    Data testdata = newweekday;    if (testdata == WEEKDAY1 || testdata == WEEKDAY2 || testdata == WEEKDAY3 ||            testdata == WEEKDAY4 || testdata == WEEKDAY5 || testdata == WEEKDAY6 ||            testdata == WEEKDAY7)    {        weekday = newweekday;    }    else    {        if (SipParserMode::sipParserMode())        {            cpLog(LOG_ERR, "Failed to Decode in WEEKDAY() of Date :( ");            throw SipDateParserException(                "failed in Method weekday() decode the Date string",                __FILE__,                __LINE__, DECODE_WEEKDAY_FAILED);        }    }}voidSipDate::setHour(const Data & newhour){    string testhour = newhour.convertString();    if (testhour.length() > 2)    {        if (SipParserMode::sipParserMode())        {            cpLog(LOG_ERR, "Failed to Decode in WEEKDAY() of Date :( ");            throw SipDateParserException(

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -