diff --git a/livesupport/modules/core/include/LiveSupport/Core/TimeConversion.h b/livesupport/modules/core/include/LiveSupport/Core/TimeConversion.h index 465996afa..5537b8556 100644 --- a/livesupport/modules/core/include/LiveSupport/Core/TimeConversion.h +++ b/livesupport/modules/core/include/LiveSupport/Core/TimeConversion.h @@ -21,8 +21,8 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - Author : $Author: maroy $ - Version : $Revision: 1.4 $ + Author : $Author: fgerlits $ + Version : $Revision: 1.5 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/include/LiveSupport/Core/TimeConversion.h,v $ ------------------------------------------------------------------------------*/ @@ -70,8 +70,8 @@ using namespace LiveSupport; /** * A helper object holding static time conversion functions. * - * @author $Author: maroy $ - * @version $Revision: 1.4 $ + * @author $Author: fgerlits $ + * @version $Revision: 1.5 $ */ class TimeConversion { @@ -111,6 +111,17 @@ class TimeConversion tmToPtime(const struct tm *time) throw (std::out_of_range); + /** + * Convert a boost::posix_time::ptime to a struct tm, + * with second precision. + * + * @param time the boost::posix_time::ptime to convert. + * @return a struct tm, holding the same time. + */ + static void + ptimeToTm(Ptr::Ref convertFrom, struct tm & convertTo) + throw (); + /** * Return the current time, with microsecond precision. * diff --git a/livesupport/modules/core/src/TimeConversion.cxx b/livesupport/modules/core/src/TimeConversion.cxx index 9c818ab28..05787e2e2 100644 --- a/livesupport/modules/core/src/TimeConversion.cxx +++ b/livesupport/modules/core/src/TimeConversion.cxx @@ -21,8 +21,8 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - Author : $Author: maroy $ - Version : $Revision: 1.5 $ + Author : $Author: fgerlits $ + Version : $Revision: 1.6 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/src/TimeConversion.cxx,v $ ------------------------------------------------------------------------------*/ @@ -95,6 +95,25 @@ TimeConversion :: tmToPtime(const struct tm *time) } +/*------------------------------------------------------------------------------ + * Convert a boost::ptime to a struct tm + *----------------------------------------------------------------------------*/ +void +TimeConversion :: ptimeToTm(Ptr::Ref convertFrom, struct tm & convertTo) + throw () +{ + date date = convertFrom->date(); + time_duration time = convertFrom->time_of_day(); + + convertTo.tm_year = date.year() - 1900; + convertTo.tm_mon = date.month() - 1; + convertTo.tm_mday = date.day(); + convertTo.tm_hour = time.hours(); + convertTo.tm_min = time.minutes(); + convertTo.tm_sec = time.seconds(); +} + + /*------------------------------------------------------------------------------ * Return the current time. *----------------------------------------------------------------------------*/ diff --git a/livesupport/modules/core/src/TimeConversionTest.cxx b/livesupport/modules/core/src/TimeConversionTest.cxx index 8099b9921..2e8ead667 100644 --- a/livesupport/modules/core/src/TimeConversionTest.cxx +++ b/livesupport/modules/core/src/TimeConversionTest.cxx @@ -21,8 +21,8 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - Author : $Author: maroy $ - Version : $Revision: 1.3 $ + Author : $Author: fgerlits $ + Version : $Revision: 1.4 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/src/TimeConversionTest.cxx,v $ ------------------------------------------------------------------------------*/ @@ -143,6 +143,26 @@ TimeConversionTest :: tmToPtimeTest(void) } +/*------------------------------------------------------------------------------ + * Test the ptimeToTm function + *----------------------------------------------------------------------------*/ +void +TimeConversionTest :: ptimeToTmTest(void) + throw (CPPUNIT_NS::Exception) +{ + struct tm tm; + Ptr::Ref ptime(new ptime(time_from_string("1770-12-17 10:20:30"))); + + TimeConversion::ptimeToTm(ptime, tm); + CPPUNIT_ASSERT(tm.tm_year + 1900 == 1770); + CPPUNIT_ASSERT(tm.tm_mon + 1 == 12); + CPPUNIT_ASSERT(tm.tm_mday == 17); + CPPUNIT_ASSERT(tm.tm_hour == 10); + CPPUNIT_ASSERT(tm.tm_min == 20); + CPPUNIT_ASSERT(tm.tm_sec == 30); +} + + /*------------------------------------------------------------------------------ * Test the now function *----------------------------------------------------------------------------*/ diff --git a/livesupport/modules/core/src/TimeConversionTest.h b/livesupport/modules/core/src/TimeConversionTest.h index aa3fa7a6d..5fbbd29ed 100644 --- a/livesupport/modules/core/src/TimeConversionTest.h +++ b/livesupport/modules/core/src/TimeConversionTest.h @@ -21,8 +21,8 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - Author : $Author: maroy $ - Version : $Revision: 1.3 $ + Author : $Author: fgerlits $ + Version : $Revision: 1.4 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/src/TimeConversionTest.h,v $ ------------------------------------------------------------------------------*/ @@ -57,8 +57,8 @@ namespace Core { /** * Unit test for the TimeConversion class. * - * @author $Author: maroy $ - * @version $Revision: 1.3 $ + * @author $Author: fgerlits $ + * @version $Revision: 1.4 $ * @see TimeConversion */ class TimeConversionTest : public CPPUNIT_NS::TestFixture @@ -66,6 +66,7 @@ class TimeConversionTest : public CPPUNIT_NS::TestFixture CPPUNIT_TEST_SUITE(TimeConversionTest); CPPUNIT_TEST(timevalToPtimeTest); CPPUNIT_TEST(tmToPtimeTest); + CPPUNIT_TEST(ptimeToTmTest); CPPUNIT_TEST(nowTest); CPPUNIT_TEST(sleepTest); CPPUNIT_TEST_SUITE_END(); @@ -88,6 +89,14 @@ class TimeConversionTest : public CPPUNIT_NS::TestFixture void tmToPtimeTest(void) throw (CPPUNIT_NS::Exception); + /** + * Test conversion from ptime to struct tm + * + * @exception CPPUNIT_NS::Exception on test failures. + */ + void + ptimeToTmTest(void) throw (CPPUNIT_NS::Exception); + /** * Test the now function. * diff --git a/livesupport/products/scheduler/src/GetSchedulerTimeMethod.cxx b/livesupport/products/scheduler/src/GetSchedulerTimeMethod.cxx index 9520f1ca9..0a4285faa 100644 --- a/livesupport/products/scheduler/src/GetSchedulerTimeMethod.cxx +++ b/livesupport/products/scheduler/src/GetSchedulerTimeMethod.cxx @@ -22,7 +22,7 @@ Author : $Author: fgerlits $ - Version : $Revision: 1.1 $ + Version : $Revision: 1.2 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/GetSchedulerTimeMethod.cxx,v $ ------------------------------------------------------------------------------*/ @@ -45,6 +45,7 @@ #include "LiveSupport/Core/StorageClientInterface.h" #include "LiveSupport/Storage/StorageClientFactory.h" +#include "LiveSupport/Core/TimeConversion.h" #include "XmlRpcTools.h" #include "GetSchedulerTimeMethod.h" @@ -119,18 +120,8 @@ GetSchedulerTimeMethod :: execute(XmlRpc::XmlRpcValue & rootParameter, // TODO: check whether the session ID is valid - ptime schedulerPTime = second_clock::local_time(); - date schedulerDate = schedulerPTime.date(); - time_duration schedulerTimeOfDay = schedulerPTime.time_of_day(); - + Ptr::Ref schedulerPTime = TimeConversion::now(); struct tm schedulerTime; - schedulerTime.tm_year = schedulerDate.year(); - schedulerTime.tm_mon = schedulerDate.month(); - schedulerTime.tm_mday = schedulerDate.day(); - schedulerTime.tm_hour = schedulerTimeOfDay.hours(); - schedulerTime.tm_min = schedulerTimeOfDay.minutes(); - schedulerTime.tm_sec = schedulerTimeOfDay.seconds(); - - returnValue.clear(); - returnValue["schedulerTime"] = & schedulerTime; + TimeConversion::ptimeToTm(schedulerPTime, schedulerTime); + returnValue["schedulerTime"] = & schedulerTime; } diff --git a/livesupport/products/scheduler/src/GetSchedulerTimeMethodTest.cxx b/livesupport/products/scheduler/src/GetSchedulerTimeMethodTest.cxx index 5a69ea0c5..461b5b33c 100644 --- a/livesupport/products/scheduler/src/GetSchedulerTimeMethodTest.cxx +++ b/livesupport/products/scheduler/src/GetSchedulerTimeMethodTest.cxx @@ -22,7 +22,7 @@ Author : $Author: fgerlits $ - Version : $Revision: 1.1 $ + Version : $Revision: 1.2 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/GetSchedulerTimeMethodTest.cxx,v $ ------------------------------------------------------------------------------*/ @@ -40,6 +40,7 @@ #endif +#include #include #include #include diff --git a/livesupport/products/scheduler/src/XmlRpcTools.h b/livesupport/products/scheduler/src/XmlRpcTools.h index d18877ffd..a5f2470c2 100644 --- a/livesupport/products/scheduler/src/XmlRpcTools.h +++ b/livesupport/products/scheduler/src/XmlRpcTools.h @@ -22,7 +22,7 @@ Author : $Author: fgerlits $ - Version : $Revision: 1.11 $ + Version : $Revision: 1.12 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/Attic/XmlRpcTools.h,v $ ------------------------------------------------------------------------------*/ @@ -74,7 +74,7 @@ using namespace LiveSupport::Core; * in the Scheduler. * * @author $Author: fgerlits $ - * @version $Revision: 1.11 $ + * @version $Revision: 1.12 $ */ class XmlRpcTools { @@ -263,12 +263,16 @@ class XmlRpcTools throw (); /** - * Convert an error code, message pair to an XmlRpcValue + * Convert an error code, message pair to an XML-RPC fault response. + * This is done by throwing an XmlRpc::XmlRpcException. The client + * receives a fault response, and the return value is set to a + * { faultCode, faultString } structure holding the error code and + * message. * * @param errorCode the numerical code of the error. * @param errorMessage a short English description of the error. - * @param xmlRpcValue the output parameter holding the result of - * the conversion. + * @param xmlRpcValue remains here from an earlier version + * TODO: remove this later. */ static void markError(int errorCode, const std::string errorMessage, @@ -398,7 +402,6 @@ class XmlRpcTools extractSessionId(XmlRpc::XmlRpcValue & xmlRpcValue) throw (std::invalid_argument); - }; /* ================================================= external data structures */ diff --git a/livesupport/products/scheduler/src/XmlRpcToolsTest.cxx b/livesupport/products/scheduler/src/XmlRpcToolsTest.cxx index 6e4dd941c..7f3f38f82 100644 --- a/livesupport/products/scheduler/src/XmlRpcToolsTest.cxx +++ b/livesupport/products/scheduler/src/XmlRpcToolsTest.cxx @@ -22,7 +22,7 @@ Author : $Author: fgerlits $ - Version : $Revision: 1.3 $ + Version : $Revision: 1.4 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/Attic/XmlRpcToolsTest.cxx,v $ ------------------------------------------------------------------------------*/ @@ -182,10 +182,13 @@ XmlRpcToolsTest :: errorTest(void) { XmlRpcValue xmlRpcValue; - XmlRpcTools :: markError(42, "this is an error", xmlRpcValue); - CPPUNIT_ASSERT((int) xmlRpcValue["errorCode"] == 42); - CPPUNIT_ASSERT((const std::string) xmlRpcValue["errorMessage"] == - "this is an error"); + try { + XmlRpcTools :: markError(42, "this is an error", xmlRpcValue); + CPPUNIT_FAIL("did not throw exception in markError()"); + } + catch (XmlRpc::XmlRpcException &e) { + CPPUNIT_ASSERT(e.getCode() == 42); + CPPUNIT_ASSERT(e.getMessage() == "this is an error"); + } } - diff --git a/livesupport/products/scheduler/src/XmlRpcToolsTest.h b/livesupport/products/scheduler/src/XmlRpcToolsTest.h index cdf1d6aa7..cc564d177 100644 --- a/livesupport/products/scheduler/src/XmlRpcToolsTest.h +++ b/livesupport/products/scheduler/src/XmlRpcToolsTest.h @@ -22,7 +22,7 @@ Author : $Author: fgerlits $ - Version : $Revision: 1.2 $ + Version : $Revision: 1.3 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/Attic/XmlRpcToolsTest.h,v $ ------------------------------------------------------------------------------*/ @@ -61,13 +61,14 @@ using namespace LiveSupport::Core; * Unit test for the XmlRpcTools class. * * @author $Author: fgerlits $ - * @version $Revision: 1.2 $ + * @version $Revision: 1.3 $ * @see XmlRpcTools */ class XmlRpcToolsTest : public CPPUNIT_NS::TestFixture { CPPUNIT_TEST_SUITE(XmlRpcToolsTest); CPPUNIT_TEST(firstTest); + CPPUNIT_TEST(errorTest); CPPUNIT_TEST_SUITE_END(); private: diff --git a/livesupport/tools/xmlrpc++/xmlrpc++-20040713/bin/install.sh b/livesupport/tools/xmlrpc++/xmlrpc++-20040713/bin/install.sh index a03418fd0..de14ed762 100755 --- a/livesupport/tools/xmlrpc++/xmlrpc++-20040713/bin/install.sh +++ b/livesupport/tools/xmlrpc++/xmlrpc++-20040713/bin/install.sh @@ -22,7 +22,7 @@ # # # Author : $Author: fgerlits $ -# Version : $Revision: 1.4 $ +# Version : $Revision: 1.5 $ # Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/tools/xmlrpc++/xmlrpc++-20040713/bin/Attic/install.sh,v $ #------------------------------------------------------------------------------- #------------------------------------------------------------------------------- @@ -47,6 +47,7 @@ tar xfz $tar cd xmlrpc++ patch -p1 < $etcdir/xmlrpc++-automake.patch patch -p1 < $etcdir/uninitialised_XmlRpcSource_ssl_ssl.patch +patch -p1 < $etcdir/incorrect_XmlRpcValue_struct_tm_conversion.patch sh autogen.sh --prefix=$installdir make install diff --git a/livesupport/tools/xmlrpc++/xmlrpc++-20040713/etc/incorrect_XmlRpcValue_struct_tm_conversion.patch b/livesupport/tools/xmlrpc++/xmlrpc++-20040713/etc/incorrect_XmlRpcValue_struct_tm_conversion.patch new file mode 100644 index 000000000..f0fc4cbf1 --- /dev/null +++ b/livesupport/tools/xmlrpc++/xmlrpc++-20040713/etc/incorrect_XmlRpcValue_struct_tm_conversion.patch @@ -0,0 +1,31 @@ +diff -Nur xmlrpc++/src/XmlRpcValue.cpp x/src/XmlRpcValue.cpp +--- xmlrpc++/src/XmlRpcValue.cpp 2003-06-06 20:13:28.000000000 +0200 ++++ x/src/XmlRpcValue.cpp 2004-12-13 21:02:39.505001617 +0100 +@@ -390,6 +390,7 @@ + return false; + + t.tm_year -= 1900; ++ t.tm_mon -= 1; + t.tm_isdst = -1; + _type = TypeDateTime; + _value.asTime = new struct tm(t); +@@ -402,7 +403,7 @@ + struct tm* t = _value.asTime; + char buf[20]; + snprintf(buf, sizeof(buf)-1, "%04d%02d%02dT%02d:%02d:%02d", +- 1900+t->tm_year,t->tm_mon,t->tm_mday,t->tm_hour,t->tm_min,t->tm_sec); ++ 1900+t->tm_year,1+t->tm_mon,t->tm_mday,t->tm_hour,t->tm_min,t->tm_sec); + buf[sizeof(buf)-1] = 0; + + std::string xml = VALUE_TAG; +@@ -553,8 +554,8 @@ + { + struct tm* t = _value.asTime; + char buf[20]; +- snprintf(buf, sizeof(buf)-1, "%4d%02d%02dT%02d:%02d:%02d", +- t->tm_year,t->tm_mon,t->tm_mday,t->tm_hour,t->tm_min,t->tm_sec); ++ snprintf(buf, sizeof(buf)-1, "%04d%02d%02dT%02d:%02d:%02d", ++ 1900+t->tm_year,1+t->tm_mon,t->tm_mday,t->tm_hour,t->tm_min,t->tm_sec); + buf[sizeof(buf)-1] = 0; + os << buf; + break;