axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dami...@apache.org
Subject cvs commit: ws-axis/c/src/common AxisTime.cpp
Date Wed, 14 Jan 2004 05:57:22 GMT
damitha     2004/01/13 21:57:22

  Modified:    c/include/axis/common AxisTime.h
               c/src/client/samples/interoptests/base InteropBaseClient.cpp
                        InteropTestPortType.cpp
               c/src/common AxisTime.cpp
  Log:
  
  
  Revision  Changes    Path
  1.6       +23 -18    ws-axis/c/include/axis/common/AxisTime.h
  
  Index: AxisTime.h
  ===================================================================
  RCS file: /home/cvs/ws-axis/c/include/axis/common/AxisTime.h,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- AxisTime.h	24 Oct 2003 12:14:59 -0000	1.5
  +++ AxisTime.h	14 Jan 2004 05:57:22 -0000	1.6
  @@ -53,11 +53,8 @@
    * <http://www.apache.org/>.
    *
    *
  - *
  - *
  - * @author Damitha Kumarage (damitha@opensource.lk, damitha@jkcsworld.com)
  - *
    */
  + 
   #ifndef __AXISTIME_H_INCLUDED_
   #define __AXISTIME_H_INCLUDED_
   
  @@ -70,14 +67,22 @@
   
   typedef struct
   {
  -    long years;
  -    int months;
  -    int days;
  -    int hours;
  -    int mins;
  +    time_t years;
  +    time_t months;
  +    time_t days;
  +    time_t hours;
  +    time_t mins;
       double secs;
   } uDuration;
   
  +
  +/**
  +    @class AxisTime
  +    @brief time manipulating helper class
  +
  +    
  +    @author Damitha Kumarage (damitha@opensource.lk, damitha@jkcsworld.com)    
  +*/
   class AxisTime
   {
       public:
  @@ -95,7 +100,7 @@
           struct tm getDateTime();
           struct tm getDate();
           struct tm getTime();
  -        void mkCTime();
  +        int mkCTime();
   		static struct tm Deserialize(const AxisChar* strValue, XSDTYPE type);
   		static long DeserializeDuration(const AxisChar* strValue, XSDTYPE type);
   
  @@ -112,16 +117,16 @@
           AxisString strHours;
           AxisString strMins;
           AxisString strSecs;
  -        int m_intYears;
  -        int m_intMonths;
  -        int m_intDays;
  -        int m_intHours;
  -        int m_intMins;
  -        int m_intSecs;
  +        time_t m_intYears;
  +        time_t m_intMonths;
  +        time_t m_intDays;
  +        time_t m_intHours;
  +        time_t m_intMins;
  +        time_t m_intSecs;
           AxisString strZone;
           uDuration duration;
  -        long m_longYears;
  -        long m_Duration;
  +        time_t m_longYears;
  +        time_t m_Duration;
           //string strXSDDuration;
           AxisString strXSDDuration;
           AxisString strXSDDate;
  
  
  
  1.9       +29 -35    ws-axis/c/src/client/samples/interoptests/base/InteropBaseClient.cpp
  
  Index: InteropBaseClient.cpp
  ===================================================================
  RCS file: /home/cvs/ws-axis/c/src/client/samples/interoptests/base/InteropBaseClient.cpp,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- InteropBaseClient.cpp	13 Jan 2004 07:19:51 -0000	1.8
  +++ InteropBaseClient.cpp	14 Jan 2004 05:57:22 -0000	1.9
  @@ -1,15 +1,18 @@
  +// InteropBaseClient.cpp : Defines the entry point for the console application.
  +//
  +
   #include "InteropTestPortType.h" 
   
  -#define ARRAYSIZE 1
  -#define LOOPFOR 1
  +#define ARRAYSIZE 2
   
   int main(int argc, char* argv[])
   {
   	int x;
   	char buffer1[100];
  -	
  +	char buffer2[100];
  +
   	InteropTestPortType ws;
  -/*	printf("invoking echoString...\n");
  +	printf("invoking echoString...\n");
   	//testing echoString 
   	if (0 == strcmp(ws.echoString("hello world"), "hello world"))
   		printf("successful\n");
  @@ -19,37 +22,26 @@
   	ArrayOfstring arrstr;
   	arrstr.m_Array = new char*[ARRAYSIZE];
   	arrstr.m_Size = ARRAYSIZE;
  -	for (x=0;x<ARRAYSIZE;x++)
  +	sprintf(buffer1, "%dth element of string array", 0);
  +	//sprintf(buffer2, "%dth element of string array", 1);
  +	for(int i=0; i< ARRAYSIZE; i++)
   	{
  -	//	sprintf(buffer1, "sdth element o sas fjas asl jasldjf asldg aladlg ajg alds lajsfd
jasdfj asdjfa sjfda jdsflaflakjdsfaljs fajsfj asflajs jasdfj asdfjasdjf asldjfalsjd fasdjf
jsadfsaj asjf asljdfasdkf asjfsaj asdkjf hjas galgjfdgas dkjasdtring array", x); //< >>>
&& &&''''' \" \" ><<<<&&& 7&777 7&&^f
  -		arrstr.m_Array[x] = strdup("a sjda slfkas jlfj asldfjafj");
  +		arrstr.m_Array[i] = buffer1;
   	}
  +	//arrstr.m_Array[1] = buffer2;
   	printf("invoking echoStringArray...\n");
  -	for(int ix=0;ix<LOOPFOR; ix++)
  -	{
  -		ArrayOfstring retarrstr = ws.echoStringArray(arrstr);
  -		if ((retarrstr.m_Array != NULL) && (retarrstr.m_Size == ARRAYSIZE)) {
  -			for (x=0;x<ARRAYSIZE;x++)
  -			{
  -				printf("%s\n", retarrstr.m_Array[x]);
  -				free(retarrstr.m_Array[x]);
  -			}
  -			free(retarrstr.m_Array);
  -			//printf("successful\n");
  -		
  -		}
  -		else
  -			printf("failed\n");
  -	}
  -	printf("Done\n");
  -*/	// testing echoInteger 
  +	if (ws.echoStringArray(arrstr).m_Array != NULL)
  +		printf("successful\n");
  +	else
  +		printf("failed\n");
  +	// testing echoInteger 
   	printf("invoking echoInteger...\n");
   	if (ws.echoInteger(56) == 56)
   		printf("successful\n");
   	else
   		printf("failed\n");
   	// testing echoIntegerArray 
  -/*	ArrayOfint arrint;
  +	ArrayOfint arrint;
   	arrint.m_Array = new int[ARRAYSIZE];
   	arrint.m_Size = ARRAYSIZE;
   	for (x=0;x<ARRAYSIZE;x++)
  @@ -62,7 +54,7 @@
   	else
   		printf("failed\n");
   	// testing echoFloat 
  -	printf("invoking echoFloat...\n");
  +/*	printf("invoking echoFloat...\n");
   	if (ws.echoFloat(1.4214) > 1.42)
   		printf("successful\n");
   	else
  @@ -84,7 +76,7 @@
   	SOAPStruct stct;
   	stct.varFloat = 12345.7346345;
   	stct.varInt = 5000;
  -	stct.varString = "This is string in SOAPStruct";
  +	stct.varString = strdup("This is string in SOAPStruct");
   	printf("invoking echoStruct...\n");
   	if (ws.echoStruct(&stct) != NULL)
   		printf("successful\n");
  @@ -99,7 +91,7 @@
   		arrstct.m_Array[x].varFloat = 1.1111*x;
   		arrstct.m_Array[x].varInt = x;
   		sprintf(buffer1, "varString of %dth element of SOAPStruct array", x);
  -		arrstct.m_Array[x].varString = strdup(buffer1);
  +		arrstct.m_Array[x].varString = buffer1;
   	}
   	//testing echo Struct Array
   	printf("invoking echoStructArray...\n");
  @@ -112,13 +104,14 @@
   	ws.echoVoid();
   	printf("successful\n");
   	//testing echo base 64 binary
  -	printf("invoking echoBase64...\n");
  +*/
  +/*	printf("invoking echoBase64...\n");
   	if (0 == strcmp(ws.echoBase64("BCDF675E234242WHRTKMJDGKGUEJ898636JFJFHEJDGWTDHFJRURYGBCDHTWRSG"),
   		"BCDF675E234242WHRTKMJDGKGUEJ898636JFJFHEJDGWTDHFJRURYGBCDHTWRSG"))
   		printf("successful\n");
   	else
   		printf("failed\n");
  -	time_t tim;
  +*/	time_t tim;
   	time(&tim);
   	tm* lt = gmtime(&tim);
   	printf("invoking echoDate...\n");
  @@ -127,13 +120,14 @@
   	else
   		printf("failed\n");
   	//testing echo hex binary
  -	printf("invoking echoHexBinary...\n");
  +
  +/*	printf("invoking echoHexBinary...\n");
   	if (0 == strcmp(ws.echoHexBinary("CCCFFA46552BC7D5A09BC5F23DE9E0FE7862AD45BC87D02FEE"),
   		"CCCFFA46552BC7D5A09BC5F23DE9E0FE7862AD45BC87D02FEE"))
   		printf("successful\n");
   	else
   		printf("failed\n");
  -	//testing echo decimal
  +*/	//testing echo decimal
   	printf("invoking echoDecimal...\n");
   	if (ws.echoDecimal(1234.567890) > 1234.56)
   		printf("successful\n");
  @@ -145,7 +139,7 @@
   		printf("successful\n");
   	else
   		printf("failed\n");
  -*/	getchar();
  +		
  +	getchar();
   	return 0;
   }
  -
  
  
  
  1.12      +1 -1      ws-axis/c/src/client/samples/interoptests/base/InteropTestPortType.cpp
  
  Index: InteropTestPortType.cpp
  ===================================================================
  RCS file: /home/cvs/ws-axis/c/src/client/samples/interoptests/base/InteropTestPortType.cpp,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- InteropTestPortType.cpp	13 Jan 2004 07:19:51 -0000	1.11
  +++ InteropTestPortType.cpp	14 Jan 2004 05:57:22 -0000	1.12
  @@ -18,7 +18,7 @@
   {
   	m_pCall = new Call();
   	m_pCall->SetProtocol(APTHTTP);
  -	m_pCall->SetEndpointURI("http://localhost:5555/axis/InteropBase");
  +	m_pCall->SetEndpointURI("http://localhost/axis/InteropBase");
   }
   
   InteropTestPortType::~InteropTestPortType()
  
  
  
  1.12      +237 -226  ws-axis/c/src/common/AxisTime.cpp
  
  Index: AxisTime.cpp
  ===================================================================
  RCS file: /home/cvs/ws-axis/c/src/common/AxisTime.cpp,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- AxisTime.cpp	24 Oct 2003 12:14:59 -0000	1.11
  +++ AxisTime.cpp	14 Jan 2004 05:57:22 -0000	1.12
  @@ -63,6 +63,8 @@
   #include <axis/common/AxisTime.h>
   #include <axis/common/AxisUtils.h>
   
  +#define TIMEBUFFSIZE 80
  +
   AxisTime::AxisTime()
   {
   
  @@ -175,17 +177,17 @@
       switch(nType)
       {
           case XSD_DATETIME:
  -            strftime(buf1, 80, "%Y-%m-%dT%H:%M:%SZ", &tValue);
  +            strftime(buf1, TIMEBUFFSIZE, "%Y-%m-%dT%H:%M:%SZ", &tValue);
               strXSDDate = buf1;
               //AxisUtils::convert(strXSDDate, buf1);
               break;
           case XSD_DATE:
  -            strftime(buf1, 80, "%Y-%m-%dZ", &tValue);
  +            strftime(buf1, TIMEBUFFSIZE, "%Y-%m-%dZ", &tValue);
               strXSDDate = buf1;
               //AxisUtils::convert(strXSDDate, buf1);
               break;
           case XSD_TIME:
  -            strftime(buf1, 80, "%H:%M:%SZ", &tValue);
  +            strftime(buf1, TIMEBUFFSIZE, "T%H:%M:%SZ", &tValue);
               strXSDDate = buf1;
               //AxisUtils::convert(strXSDDate, buf1);
               break;
  @@ -200,11 +202,18 @@
   * This function deserialize the xml datetime type into a c type
   * tm struct. The struct tm created will contain the UTC time
   */
  -void AxisTime::mkCTime()
  +int AxisTime::mkCTime()
   {
   //    AxisChar* endptr;
  +    AxisChar* cUtc;
  +    AxisChar* cTemp;
  +    AxisChar* cTemp2;
  +    AxisChar* cTemp3;
  +    int intLen = 0;
  +    int intHours = 0;
  +    int intMins = 0;
  +    int intSecs = 0;
       unsigned int intPos, intPos1, intPos2, intPos3, intPos4, intPos5, intPos6;
  -    AxisChar buff[4] = {0};
       time_t now;
       struct tm result1, result2;
   	struct tm* pTm;
  @@ -214,6 +223,8 @@
   	pTm = localtime(&now);
   	memcpy(&result2, pTm, sizeof(tm));
       time_t d = mktime(&result1) - mktime(&result2);
  +    if(d == -1)
  +        return AXIS_FAIL;
   
       switch(m_Type)
       {
  @@ -267,95 +278,76 @@
                   CCYY(-)MM(-)DDThh:mm:ss.ss...Z OR
                   CCYY(-)MM(-)DDThh:mm:ss.ss...+/-<UTC TIME DIFFERENCE>
               */
  -            strYears = m_sValue.substr(0,4);
  -            m_intYears = atoi(strYears.c_str()) - 1900;
  -            //m_intYears = wcstol(strYears.c_str(), &endptr, 10) - 1900;
  -            //sprintf((char*)buff,"%d", m_intYears);
  -            AxisSprintf(buff, 4, "%d", m_intYears);
  -            strYears = buff;
  -            intPos = m_sValue.find_first_of("-");
  -            /* date is of the format CCYY-MM-DD */
  -            if(intPos != std::string::npos && intPos<=7)
  -            {
  -                strMonths = m_sValue.substr(5,2);
  -                strDays = m_sValue.substr(8,2);
  -                strHours = m_sValue.substr(11,2);
  -                strMins = m_sValue.substr(14,2);
  -                /*Decimal fraction of the second is omitted*/
  -                strSecs = m_sValue.substr(17,2);
  -                strZone = m_sValue.substr(19,m_sValue.length()-19);
  -            }
  -            /* date is of the format CCYYMMDD */
  -            else if((intPos == std::string::npos) || (intPos != std::string::npos &&
intPos > 7))
  -            {
  -                strMonths = m_sValue.substr(4,2);
  -                strMonths = m_sValue.substr(6,2);
  -                strHours = m_sValue.substr(9,2);
  -                strMins = m_sValue.substr(12,2);
  -                /*Decimal fraction of the second is omitted*/
  -                strSecs = m_sValue.substr(15,2);
  -                strZone = m_sValue.substr(17,m_sValue.length()-17);
  -            }
  +            if(sscanf(m_sValue.c_str(), "%d-%d-%dT%d:%d:%d",
  +                &m_TM.tm_year,
  +                &m_TM.tm_mon,
  +                &m_TM.tm_mday,
  +                &m_TM.tm_hour,
  +                &m_TM.tm_min,
  +                &m_TM.tm_sec) != 6) return AXIS_FAIL;/*invalid data format*/
  +
   
  -            m_TM.tm_year = atoi(strYears.c_str());
  -            //m_TM.tm_year = wcstol(strYears.c_str(), &endptr, 10);
  -            m_TM.tm_mon = atoi(strMonths.c_str());
  -            //m_TM.tm_mon = wcstol(strMonths.c_str(), &endptr, 10);
  -            m_TM.tm_mday = atoi(strDays.c_str());
  -            //m_TM.tm_mday = wcstol(strDays.c_str(), &endptr, 10);
  -            m_TM.tm_hour = atoi(strHours.c_str());
  -            //m_TM.tm_hour = wcstol(strHours.c_str(), &endptr, 10);
  -            m_TM.tm_min = atoi(strMins.c_str());
  -            //m_TM.tm_min = wcstol(strMins.c_str(), &endptr, 10);
  -            m_TM.tm_sec = atoi(strSecs.c_str());
  -            //m_TM.tm_sec = wcstol(strSecs.c_str(), &endptr, 10);
  +
  +            m_TM.tm_year -= 1900;
  +            m_TM.tm_mon--;
  +            m_TM.tm_isdst = -1;
  +#ifndef WIN32
  +            m_TM.tm_zone = NULL;
  +            m_TM.tm_gmtoff = -1;
  +#endif
  +            cTemp2 = strpbrk(m_sValue.c_str(), "T");
  +            cTemp3 = strrchr(cTemp2, ':');
  +            cTemp3[0] = '\0';
  +            intLen = strlen(cTemp2);
  +            cTemp3[0] = ':';
   
               /*if the timezone is represented adding 'Z' at the end*/
  -            if(strZone.substr(0,1) == "Z")
  +            if((cTemp = strpbrk(m_sValue.c_str(), "Z")) != NULL)
               {
  -                time_t timeInSecs = mktime(&m_TM);
  -				pTm = localtime(&timeInSecs);
  -				memcpy(&m_TMUTC, pTm, sizeof(tm));
  +                time_t temp = mktime(&m_TM);
  +                if(temp == -1)
  +                    return AXIS_FAIL;
  +                pTm = localtime(&temp);
  +                memcpy(&m_TMUTC, pTm, sizeof(tm));
               }
               /*if the timezone is represented using +/-hh:mm format*/
  -            else if(strZone.substr(0,1) == "+" ||strZone.substr(0,1) == "-")
  -            {
  -                time_t timeInSecs = mktime(&m_TM);
  -				pTm = localtime(&timeInSecs);
  -				memcpy(&m_TMUTC, pTm, sizeof(tm));
  -                m_intHours = atoi(strZone.substr(1,2).c_str());
  -                //m_intHours = wcstol(strZone.substr(1,2).c_str(), &endptr, 10);
  -                m_intMins = atoi(strZone.substr(3,2).c_str());
  -                //m_intMins = wcstol(strZone.substr(3,2).c_str(), &endptr, 10);
  -                m_intSecs = m_intHours * 60 * 60 + m_intMins * 60;
  -                if(strZone.substr(0,1) == "+")
  -                {
  -                    timeInSecs += m_intSecs;
  -					pTm = localtime(&timeInSecs);
  -					memcpy(&m_TM, pTm, sizeof(tm));
  -                    time_t t = mktime(&m_TM);
  -                    t = abs(t - d);
  -					pTm = gmtime(&t);
  -					memcpy(&m_TMUTC, pTm, sizeof(tm));
  -                }
  -                else if(strZone.substr(0,1) == "-")
  -                {
   
  -                    timeInSecs -= m_intSecs;
  -					pTm = localtime(&timeInSecs);
  -					memcpy(&m_TM, pTm, sizeof(tm));
  -
  -                    time_t t = mktime(&m_TM);
  -                    t = abs(t - d);
  -					pTm = gmtime(&t);
  -					memcpy(&m_TMUTC, pTm, sizeof(tm));
  -                }
  -            }
  +           else if(intLen > (sizeof(char) * 6))
  +           {
  +               cUtc = strpbrk(cTemp2, "+");
  +               if(cUtc == NULL)
  +                   cUtc = strpbrk(cTemp2, "-");
  +               time_t timeInSecs = mktime(&m_TM);
  +               if(timeInSecs == -1)
  +                   return AXIS_FAIL;
  +               //pTm = localtime(&timeInSecs);
  +               if(sscanf(cUtc + 1, "%d:%d", &intHours, &intMins) != 2)
  +               return AXIS_FAIL;
  +               intSecs = intHours * 60 * 60 + intMins * 60;
  +               if((cTemp = strpbrk((cUtc), "+")) != NULL )
  +               {
  +                   timeInSecs += intSecs;    
  +               }
  +               else
  +               {
  +                   timeInSecs -= intSecs;               
  +               }
  +               pTm = localtime(&timeInSecs);
  +               memcpy(&m_TM, pTm, sizeof(tm));
  +               time_t t = mktime(&m_TM);
  +               if(t == -1)
  +                   return AXIS_FAIL;
  +               t = abs(t - d);
  +               pTm = gmtime(&t);
  +               memcpy(&m_TMUTC, pTm, sizeof(tm));
  +           }
               /*if the zone is not represented in the date*/
               else
               {
                   /*else it is assumed that the sent time is localtime*/
                   time_t timeInSecs = mktime(&m_TM);
  +                if(timeInSecs == -1)
  +                    return AXIS_FAIL;
   				pTm = gmtime(&timeInSecs);
   				memcpy(&m_TMUTC, pTm, sizeof(tm));
               }
  @@ -368,79 +360,69 @@
                   CCYY(-)MM(-)DDZ OR
                   CCYY(-)MM(-)DD+/-<UTC TIME DIFFERENCE>
               */
  -            strYears = m_sValue.substr(0,4);
  -            m_intYears = atoi(strYears.c_str()) - 1900;
  -            //m_intYears = wcstol(strYears.c_str(), &endptr, 10) - 1900;
  -            //sprintf((char*)buff,"%d", m_intYears);
  -            AxisSprintf(buff, 4, "%d", m_intYears);
  -            strYears = buff;
  -            intPos = m_sValue.find_first_of("-");
  -            /* date is of the format CCYY-MM-DD */
  -            if(intPos != std::string::npos && intPos <= 7)
  -            {
  -                strMonths = m_sValue.substr(5,2);
  -                strDays = m_sValue.substr(8,2);
  -                strZone = m_sValue.substr(10,m_sValue.length() - 10);
  -            }
  -            /* date is of the format CCYYMMDD */
  -            else if((intPos == std::string::npos) || (intPos != std::string::npos &&
intPos > 7))
  -            {
  -                strMonths = m_sValue.substr(4,2);
  -                strMonths = m_sValue.substr(6,2);
  -                strZone = m_sValue.substr(8,m_sValue.length() - 8);
  -            }
  -
  -            m_TM.tm_year = atoi(strYears.c_str());
  -            //m_TM.tm_year= wcstol(strYears.c_str(), &endptr, 10);
  -            m_TM.tm_mon = atoi(strMonths.c_str());
  -            //m_TM.tm_mon = wcstol(strMonths.c_str(), &endptr, 10);
  -            m_TM.tm_mday = atoi(strDays.c_str());
  -            //m_TM.tm_mday = wcstol(strDays.c_str(), &endptr, 10);
  +            if(sscanf(m_sValue.c_str(), "%d-%d-%d",
  +                &m_TM.tm_year,
  +                &m_TM.tm_mon,
  +                &m_TM.tm_mday
  +                ) != 3) return AXIS_FAIL;/*invalid data format*/
  +
  +            m_TM.tm_year -= 1900;
  +            m_TM.tm_mon--;
  +            m_TM.tm_hour = 0;
  +            m_TM.tm_min = 0;
  +            m_TM.tm_sec = 0;
  +            m_TM.tm_isdst = -1;
  +#ifndef WIN32
  +            m_TM.tm_zone = NULL;
  +            m_TM.tm_gmtoff = -1;
  +#endif            
  +            cTemp3 = strpbrk(m_sValue.c_str(), ":");
   
               /*if the timezone is represented adding 'Z' at the end*/
  -            if(strZone.substr(0,1) == "Z")
  +            if((cTemp = strpbrk(m_sValue.c_str(), "Z")) != NULL)
               {
                   time_t timeInSecs = mktime(&m_TM);
  +                if(timeInSecs == -1)
  +                    return AXIS_FAIL;
   				pTm = localtime(&timeInSecs);
   				memcpy(&m_TMUTC, pTm, sizeof(tm));
               }
  -            /*if the timezone is represented using +/-hh:mm format*/
  -            else if(strZone.substr(0,1) == "+" ||strZone.substr(0,1) == "-")
  +            else if(cTemp3 != NULL )
  +
               {
  +                cUtc = strrchr(m_sValue.c_str(), '+');
  +                if(cUtc == NULL)
  +                    cUtc = strrchr(m_sValue.c_str(), '-');
                   time_t timeInSecs = mktime(&m_TM);
  -				pTm = localtime(&timeInSecs);
  -				memcpy(&m_TMUTC, pTm, sizeof(tm));
  -                m_intHours = atoi(strZone.substr(1,2).c_str());
  -                //m_intHours = wcstol(strZone.substr(1,2).c_str(), &endptr, 10);
  -                m_intMins = atoi(strZone.substr(3,2).c_str());
  -                //m_intMins = wcstol(strZone.substr(3,2).c_str(), &endptr, 10);
  -                m_intSecs = m_intHours * 60 * 60 + m_intMins * 60;
  -                if(strZone.substr(0,1) == "+")
  +                if(timeInSecs == -1)
  +                    return AXIS_FAIL;
  +                if(sscanf(cUtc + 1, "%d:%d", &intHours, &intMins) != 2)
  +                return AXIS_FAIL;
  +                intSecs = intHours * 60 * 60 + intMins * 60;
  +                if((cTemp = strpbrk((cUtc), "+")) != NULL )
                   {
  -                    timeInSecs += m_intSecs;
  -					pTm = localtime(&timeInSecs);
  -					memcpy(&m_TM, pTm, sizeof(tm));
  -                    time_t t = mktime(&m_TM);
  -                    t = abs(t - d);
  -					pTm = gmtime(&t);
  -					memcpy(&m_TMUTC, pTm, sizeof(tm));
  +                    timeInSecs += intSecs;
                   }
  -                else if(strZone.substr(0,1) == "-")
  +                else
                   {
  -                    timeInSecs -= m_intSecs;
  -					pTm = localtime(&timeInSecs);
  -					memcpy(&m_TM, pTm, sizeof(tm));
  -                    time_t t = mktime(&m_TM);
  -                    t = abs(t - d);
  -					pTm = gmtime(&t);
  -					memcpy(&m_TMUTC, pTm, sizeof(tm));
  +                    timeInSecs -= intSecs;
                   }
  +                pTm = localtime(&timeInSecs);
  +				memcpy(&m_TM, pTm, sizeof(tm));
  +                time_t t = mktime(&m_TM);
  +                if(t == -1)
  +                    return AXIS_FAIL;
  +                t = abs(t - d);
  +				pTm = gmtime(&t);
  +				memcpy(&m_TMUTC, pTm, sizeof(tm));
               }
               /*if the zone is not represented in the date*/
               else
               {
                   /*else it is assumed that the sent time is localtime*/
                   time_t timeInSecs = mktime(&m_TM);
  +                if(timeInSecs == -1)
  +                    return AXIS_FAIL;
   				pTm = gmtime(&timeInSecs);
   				memcpy(&m_TMUTC, pTm, sizeof(tm));
               }
  @@ -453,68 +435,83 @@
                   hh:mm:ss.ss...Z OR
                   hh:mm:ss.ss...+/-<UTC TIME DIFFERENCE>
               */
  -            strHours = m_sValue.substr(0,2);
  -            strMins = m_sValue.substr(3,2);
  -            /*Decimal fraction of the second is omitted*/
  -            strSecs = m_sValue.substr(6,2);
  -            strZone = m_sValue.substr(8,m_sValue.length() - 8);
  -
  -            m_TM.tm_hour = atoi(strHours.c_str());
  -            //m_TM.tm_hour = wcstol(strHours.c_str(), &endptr, 10);
  -            m_TM.tm_min = atoi(strMins.c_str());
  -            //m_TM.tm_min = wcstol(strMins.c_str(), &endptr, 10);
  -            m_TM.tm_sec = atoi(strSecs.c_str());
  -            //m_TM.tm_sec = wcstol(strSecs.c_str(), &endptr, 10);
  +            if(sscanf(m_sValue.c_str(), "T%d:%d:%d",
  +                &m_TM.tm_hour,
  +                &m_TM.tm_min,
  +                &m_TM.tm_sec) != 3) return AXIS_FAIL;/*invalid data format*/
  +
  +            m_TM.tm_year = 70;
  +            m_TM.tm_mon = 0;
  +            m_TM.tm_mday = 0;
  +            m_TM.tm_isdst = -1;
  +#ifndef WIN32
  +            m_TM.tm_zone = NULL;
  +            m_TM.tm_gmtoff = -1;
  +#endif
  +            printf("m_sValue:%s\n", m_sValue.c_str());
  +
  +            cTemp2 = strpbrk(m_sValue.c_str(), "T");
  +            printf("cTemp2:%s\n", cTemp2);
  +            cTemp3 = strrchr(cTemp2, ':');
  +            printf("cTemp3:%s\n", cTemp3);
  +            cTemp3[0] = '\0';
  +            intLen = strlen(cTemp2);
  +            cTemp3[0] = ':';
   
               /*if the timezone is represented adding 'Z' at the end*/
  -            if(strZone.substr(0,1) == "Z")
  +            if((cTemp = strpbrk(m_sValue.c_str(), "Z")) != NULL)
               {
  -                time_t timeInSecs = mktime(&m_TM);
  -				pTm = localtime(&timeInSecs);
  -				memcpy(&m_TMUTC, pTm, sizeof(tm));
  +                time_t temp = mktime(&m_TM);
  +                if(temp == -1)
  +                    return AXIS_FAIL;
  +                pTm = localtime(&temp);
  +                memcpy(&m_TMUTC, pTm, sizeof(tm));
               }
               /*if the timezone is represented using +/-hh:mm format*/
  -            else if(strZone.substr(0,1) == "+" ||strZone.substr(0,1) == "-")
  -            {
  -                time_t timeInSecs = mktime(&m_TM);
  -				pTm = localtime(&timeInSecs);
  -				memcpy(&m_TMUTC, pTm, sizeof(tm));
  -                m_intHours = atoi(strZone.substr(1,2).c_str());
  -                //m_intHours = wcstol(strZone.substr(1,2).c_str(), &endptr, 10);
  -                m_intMins = atoi(strZone.substr(3,2).c_str());
  -                //m_intMins = wcstol(strZone.substr(3,2).c_str(), &endptr, 10);
  -                m_intSecs = m_intHours * 60 * 60 + m_intMins * 60;
  -                if(strZone.substr(0,1) == "+")
  -                {
  -                    timeInSecs += m_intSecs;
  -					pTm = localtime(&timeInSecs);
  -					memcpy(&m_TM, pTm, sizeof(tm));
  -                    time_t t = mktime(&m_TM);
  -                    t = abs(t - d);
  -					pTm = gmtime(&t);
  -					memcpy(&m_TMUTC, pTm, sizeof(tm));
  -                }
  -                else if(strZone.substr(0,1) == "-")
  -                {
  -                    timeInSecs -= m_intSecs;
  -					pTm = localtime(&timeInSecs);
  -					memcpy(&m_TM, pTm, sizeof(tm));
  -                    time_t t = mktime(&m_TM);
  -                    t = abs(t - d);
  -					pTm = gmtime(&t);
  -					memcpy(&m_TMUTC, pTm, sizeof(tm));
  -                }
  -            }
  +
  +           else if(intLen > (sizeof(char) * 6))
  +           {
  +               cUtc = strpbrk(cTemp2, "+");
  +               if(cUtc == NULL)
  +                   cUtc = strpbrk(cTemp2, "-");
  +               time_t timeInSecs = mktime(&m_TM);
  +               if(timeInSecs == -1)
  +                    return AXIS_FAIL;
  +               //pTm = localtime(&timeInSecs);
  +               if(sscanf(cUtc + 1, "%d:%d", &intHours, &intMins) != 2)
  +               return AXIS_FAIL;
  +               intSecs = intHours * 60 * 60 + intMins * 60;
  +               if((cTemp = strpbrk((cUtc), "+")) != NULL )
  +               {
  +                   timeInSecs += intSecs;
  +               }
  +               else
  +               {
  +                   timeInSecs -= intSecs;
  +               }
  +               pTm = localtime(&timeInSecs);
  +               memcpy(&m_TM, pTm, sizeof(tm));
  +               time_t t = mktime(&m_TM);
  +               if(t == -1)
  +                    return AXIS_FAIL;
  +               t = abs(t - d);
  +               pTm = gmtime(&t);
  +               memcpy(&m_TMUTC, pTm, sizeof(tm));
  +           }
               /*if the zone is not represented in the date*/
               else
               {
                   /*else it is assumed that the sent time is localtime*/
  +				//memcpy(&m_TMUTC, &m_TM, sizeof(tm));
                   time_t timeInSecs = mktime(&m_TM);
  +                if(timeInSecs == -1)
  +                    return AXIS_FAIL;
   				pTm = gmtime(&timeInSecs);
   				memcpy(&m_TMUTC, pTm, sizeof(tm));
               }
   
               break;
  +
           default:;
       }
   }
  @@ -558,57 +555,71 @@
   	return at.getDuration();
   }
   
  -//int main(int)
  -//{
  -    //AxisTime* objTime = new AxisTime();
  -    //===========================
  -    //objTime->setType(XSD_DATETIME);
  -    /*GMT in Z format*/
  +
  +/*int main2(int)
  +{
  +    AxisTime* objTime = new AxisTime();
  +*/
  +/*    //===========================
  +    objTime->setType(XSD_DATETIME);
  +    //GMT in Z format
       //objTime->setValue("2003-03-24T21:55:56Z");
  -    /*GMT in +/- format*/
  -    //objTime->setValue("2003-03-24T21:55:56+5:30");
  -    /*no timezone specified. assumed localtime*/
  +    //GMT in +/- format
  +    objTime->setValue("2003-03-24T21:55:56-5:30");
  +    //no timezone specified. assumed localtime
       //objTime->setValue("2003-03-24T21:55:56");
  -    //struct tm x;
  -    //x.tm_sec = 20;
  -    //x.tm_min = 55;
  -    //x.tm_hour = 21;
  -    //x.tm_mday = 27;
  -    //x.tm_mon = 11;
  -    //x.tm_year = 103;
  -    //objTime->serialize("", x);
  -    //objTime->mkCTime();
  -    //=============================
   
  +
  +    struct tm tmObj = objTime->getDateTime();
  +    AxisString str = objTime->serialize("", tmObj, XSD_DATETIME);
  +    printf("sent datetime:%s\n", "2003-03-24T21:55:56-5:30");
  +    printf("got  datetime:%s\n", str.c_str());
  +    
  +*/
  +    //=============================
           //===========================
  -    //objTime->setType(XSD_TIME);
  -    /*GMT in Z format*/
  +/*  objTime->setType(XSD_DATE);
  +    //GMT in Z format
       //objTime->setValue("2003-03-24Z");
  -    /*GMT in +/- format*/
  -    //objTime->setValue("2003-03-24+5:30");
  -    /*no timezone specified. assumed localtime*/
  +    //GMT in +/- format
  +    objTime->setValue("2003-03-24+5:30");
  +    //no timezone specified. assumed localtime
       //objTime->setValue("2003-03-24");
  -    //objTime->mkCTime();
  -    //=============================
   
  +
  +    struct tm tmObj = objTime->getDate();
  +    AxisString str = objTime->serialize("", tmObj, XSD_DATE);
  +    printf("sent date:%s\n", "2003-03-24+5:30");
  +    printf("got  date:%s\n", str.c_str());
  +*/
  +    //=============================
           //===========================
  -    //objTime->setType(XSD_TIME);
  -    /*GMT in Z format*/
  -    //objTime->setValue("21:55:56Z");
  -    /*GMT in +/- format*/
  -    //objTime->setValue("T21:55:56+5:30");
  -    /*no timezone specified. assumed localtime*/
  +/*    objTime->setType(XSD_TIME);
  +    //GMT in Z format
  +    //objTime->setValue("T1:3:3");
  +    //GMT in +/- format
  +    objTime->setValue("T21:55:56+5:30");
  +    //no timezone specified. assumed localtime
       //objTime->setValue("T21:55:56");
  -    //objTime->mkCTime();
  -    //===========================
  -
  -    //==========================
  -    //objTime->setType(XSD_DURATION);
  -    /*Duration in PnYnMnDTnHnMnS format*/
  -    //objTime->setValue("P100000Y3M21DT11H33M44S");
  -    //AxisString str = objTime->serialize("", objTime->m_Duration, XSD_DURATION);
  -    //printf("serialized string is: %s\n", str.c_str());
   
  +    struct tm tmObj = objTime->getTime();
  +    AxisString str = objTime->serialize("", tmObj, XSD_TIME);
  +    //printf("sent time:%s\n", "T1:1:1");
  +    printf("got  time:%s\n", str.c_str());
  +*/
  +    //===========================
  +    //==========================*/
  +/*    objTime->setType(XSD_DURATION);
  +    //Duration in PnYnMnDTnHnMnS format
  +    objTime->setValue("P59Y5M1DT11H26M29S");
  +    printf("m_Duration:%d\n", objTime->m_Duration);
  +    AxisString str = objTime->serialize("", objTime->m_Duration, XSD_DURATION);
  +    printf("sent string:%s\n", "P59Y5M1DT11H26M29S");
  +    printf("got  string:%s\n", str.c_str());
  +*/
       //==============================
  -    //return 0;
  -//}
  +/*
  +    return 0;
  +
  +}
  +*/
  \ No newline at end of file
  
  
  

Mime
View raw message