summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Mollekopf <mollekopf@kolabsys.com>2013-09-18 08:25:37 (GMT)
committerChristian Mollekopf <mollekopf@kolabsys.com>2013-09-18 08:25:37 (GMT)
commitdb3731bfcbf49e5f8cbd9a2d2fb7c1d1f3d1b702 (patch)
tree59c68e9a0d82f92885300d441f0a60d53871cbf2
parent5a4ea1decec25183a5e2cdd0a17ddf7f241b8d3b (diff)
downloadlibkolabxml-db3731bfcbf49e5f8cbd9a2d2fb7c1d1f3d1b702.tar.gz
Whitelist valid timezones according to the content of zone.tab.
-rw-r--r--src/objectvalidation.cpp30
-rw-r--r--tests/validationtest.cpp15
-rw-r--r--tests/validationtest.h2
-rw-r--r--tztable.h424
-rwxr-xr-xutils/zonetabconversion.py29
5 files changed, 492 insertions, 8 deletions
diff --git a/src/objectvalidation.cpp b/src/objectvalidation.cpp
index 04cd0b6..eeaa660 100644
--- a/src/objectvalidation.cpp
+++ b/src/objectvalidation.cpp
@@ -24,22 +24,36 @@
#include "kolabconfiguration.h"
#include "kolabfile.h"
#include "utils.h"
+#include "tztable.h"
+#include <boost/unordered_set.hpp>
namespace Kolab {
+static boost::unordered::unordered_set<std::string> initializeTzSet() {
+ boost::unordered::unordered_set<std::string> set;
+ for (int i = 0; i < numOlsonTimezones; i++) {
+ set.insert(olsonTimezones[i]);
+ }
+ return set;
+}
+
+const boost::unordered::unordered_set<std::string> tzSet = initializeTzSet();
+
bool isValid(const cDateTime &datetime)
{
if (!datetime.isValid()) {
return true;
}
const std::string tz = datetime.timezone();
- if (datetime.isUTC() && !tz.empty()) {
- Utils::logMessage("A UTC datetime may not have a timezone", "", 0, Error);
- return false;
- }
- if (tz == "Z") {
- Utils::logMessage("Z is not a valid timezone. Set to UTC instead", "", 0, Error);
- return false;
+ if (!tz.empty()) {
+ if (datetime.isUTC() && !tz.empty()) {
+ Utils::logMessage("A UTC datetime may not have a timezone", "", 0, Error);
+ return false;
+ }
+ if (tzSet.find(tz) == tzSet.end()) {
+ Utils::logMessage("not a valid olson timezone.", "", 0, Error);
+ return false;
+ }
}
return true;
}
@@ -91,7 +105,7 @@ void validate(const Todo& todo)
void validate(const Journal& journal)
{
-
+ ASSERTVALID(journal.start());
}
void validate(const Contact& contact)
diff --git a/tests/validationtest.cpp b/tests/validationtest.cpp
index 5a1aa58..97a928e 100644
--- a/tests/validationtest.cpp
+++ b/tests/validationtest.cpp
@@ -39,6 +39,14 @@ void ValidationTest::testNoErrorOnValidEvent()
QCOMPARE(Kolab::error(), Kolab::NoError);
}
+void ValidationTest::testOlsonTimezone()
+{
+ Event event;
+ event.setStart(cDateTime("Europe/Zurich",2013,1,1,1,1,1));
+ writeEvent(event);
+ QCOMPARE(Kolab::error(), Kolab::NoError);
+}
+
void ValidationTest::testDifferentTimezones()
{
Event event;
@@ -66,6 +74,13 @@ void ValidationTest::testTimezoneZ()
QCOMPARE(Kolab::error(), Kolab::Error);
}
+void ValidationTest::testWindowsTimezone()
+{
+ Event event;
+ event.setStart(cDateTime("Central European Standard Time",2013,1,1,1,1,1));
+ writeEvent(event);
+ QCOMPARE(Kolab::error(), Kolab::Error);
+}
QTEST_MAIN( ValidationTest )
diff --git a/tests/validationtest.h b/tests/validationtest.h
index 3a2c5e1..4751ca0 100644
--- a/tests/validationtest.h
+++ b/tests/validationtest.h
@@ -26,9 +26,11 @@ class ValidationTest: public QObject {
private slots:
void testErrorOnEmptyEvent();
void testNoErrorOnValidEvent();
+ void testOlsonTimezone();
void testDifferentTimezones();
void testUTCwithTimezone();
void testTimezoneZ();
+ void testWindowsTimezone();
};
#endif
diff --git a/tztable.h b/tztable.h
new file mode 100644
index 0000000..f59eb1a
--- /dev/null
+++ b/tztable.h
@@ -0,0 +1,424 @@
+//This file was generated by the zonetabconversion.py script
+static const char* olsonTimezones[] = {
+ "Europe/Andorra",
+ "Asia/Dubai",
+ "Asia/Kabul",
+ "America/Antigua",
+ "America/Anguilla",
+ "Europe/Tirane",
+ "Asia/Yerevan",
+ "Africa/Luanda",
+ "Antarctica/McMurdo",
+ "Antarctica/South_Pole",
+ "Antarctica/Rothera",
+ "Antarctica/Palmer",
+ "Antarctica/Mawson",
+ "Antarctica/Davis",
+ "Antarctica/Casey",
+ "Antarctica/Vostok",
+ "Antarctica/DumontDUrville",
+ "Antarctica/Syowa",
+ "America/Argentina/Buenos_Aires",
+ "America/Argentina/Cordoba",
+ "America/Argentina/Salta",
+ "America/Argentina/Jujuy",
+ "America/Argentina/Tucuman",
+ "America/Argentina/Catamarca",
+ "America/Argentina/La_Rioja",
+ "America/Argentina/San_Juan",
+ "America/Argentina/Mendoza",
+ "America/Argentina/San_Luis",
+ "America/Argentina/Rio_Gallegos",
+ "America/Argentina/Ushuaia",
+ "Pacific/Pago_Pago",
+ "Europe/Vienna",
+ "Australia/Lord_Howe",
+ "Antarctica/Macquarie",
+ "Australia/Hobart",
+ "Australia/Currie",
+ "Australia/Melbourne",
+ "Australia/Sydney",
+ "Australia/Broken_Hill",
+ "Australia/Brisbane",
+ "Australia/Lindeman",
+ "Australia/Adelaide",
+ "Australia/Darwin",
+ "Australia/Perth",
+ "Australia/Eucla",
+ "America/Aruba",
+ "Europe/Mariehamn",
+ "Asia/Baku",
+ "Europe/Sarajevo",
+ "America/Barbados",
+ "Asia/Dhaka",
+ "Europe/Brussels",
+ "Africa/Ouagadougou",
+ "Europe/Sofia",
+ "Asia/Bahrain",
+ "Africa/Bujumbura",
+ "Africa/Porto-Novo",
+ "America/St_Barthelemy",
+ "Atlantic/Bermuda",
+ "Asia/Brunei",
+ "America/La_Paz",
+ "America/Kralendijk",
+ "America/Noronha",
+ "America/Belem",
+ "America/Fortaleza",
+ "America/Recife",
+ "America/Araguaina",
+ "America/Maceio",
+ "America/Bahia",
+ "America/Sao_Paulo",
+ "America/Campo_Grande",
+ "America/Cuiaba",
+ "America/Santarem",
+ "America/Porto_Velho",
+ "America/Boa_Vista",
+ "America/Manaus",
+ "America/Eirunepe",
+ "America/Rio_Branco",
+ "America/Nassau",
+ "Asia/Thimphu",
+ "Africa/Gaborone",
+ "Europe/Minsk",
+ "America/Belize",
+ "America/St_Johns",
+ "America/Halifax",
+ "America/Glace_Bay",
+ "America/Moncton",
+ "America/Goose_Bay",
+ "America/Blanc-Sablon",
+ "America/Montreal",
+ "America/Toronto",
+ "America/Nipigon",
+ "America/Thunder_Bay",
+ "America/Iqaluit",
+ "America/Pangnirtung",
+ "America/Resolute",
+ "America/Atikokan",
+ "America/Rankin_Inlet",
+ "America/Winnipeg",
+ "America/Rainy_River",
+ "America/Regina",
+ "America/Swift_Current",
+ "America/Edmonton",
+ "America/Cambridge_Bay",
+ "America/Yellowknife",
+ "America/Inuvik",
+ "America/Creston",
+ "America/Dawson_Creek",
+ "America/Vancouver",
+ "America/Whitehorse",
+ "America/Dawson",
+ "Indian/Cocos",
+ "Africa/Kinshasa",
+ "Africa/Lubumbashi",
+ "Africa/Bangui",
+ "Africa/Brazzaville",
+ "Europe/Zurich",
+ "Africa/Abidjan",
+ "Pacific/Rarotonga",
+ "America/Santiago",
+ "Pacific/Easter",
+ "Africa/Douala",
+ "Asia/Shanghai",
+ "Asia/Harbin",
+ "Asia/Chongqing",
+ "Asia/Urumqi",
+ "Asia/Kashgar",
+ "America/Bogota",
+ "America/Costa_Rica",
+ "America/Havana",
+ "Atlantic/Cape_Verde",
+ "America/Curacao",
+ "Indian/Christmas",
+ "Asia/Nicosia",
+ "Europe/Prague",
+ "Europe/Berlin",
+ "Europe/Busingen",
+ "Africa/Djibouti",
+ "Europe/Copenhagen",
+ "America/Dominica",
+ "America/Santo_Domingo",
+ "Africa/Algiers",
+ "America/Guayaquil",
+ "Pacific/Galapagos",
+ "Europe/Tallinn",
+ "Africa/Cairo",
+ "Africa/El_Aaiun",
+ "Africa/Asmara",
+ "Europe/Madrid",
+ "Africa/Ceuta",
+ "Atlantic/Canary",
+ "Africa/Addis_Ababa",
+ "Europe/Helsinki",
+ "Pacific/Fiji",
+ "Atlantic/Stanley",
+ "Pacific/Chuuk",
+ "Pacific/Pohnpei",
+ "Pacific/Kosrae",
+ "Atlantic/Faroe",
+ "Europe/Paris",
+ "Africa/Libreville",
+ "Europe/London",
+ "America/Grenada",
+ "Asia/Tbilisi",
+ "America/Cayenne",
+ "Europe/Guernsey",
+ "Africa/Accra",
+ "Europe/Gibraltar",
+ "America/Godthab",
+ "America/Danmarkshavn",
+ "America/Scoresbysund",
+ "America/Thule",
+ "Africa/Banjul",
+ "Africa/Conakry",
+ "America/Guadeloupe",
+ "Africa/Malabo",
+ "Europe/Athens",
+ "Atlantic/South_Georgia",
+ "America/Guatemala",
+ "Pacific/Guam",
+ "Africa/Bissau",
+ "America/Guyana",
+ "Asia/Hong_Kong",
+ "America/Tegucigalpa",
+ "Europe/Zagreb",
+ "America/Port-au-Prince",
+ "Europe/Budapest",
+ "Asia/Jakarta",
+ "Asia/Pontianak",
+ "Asia/Makassar",
+ "Asia/Jayapura",
+ "Europe/Dublin",
+ "Asia/Jerusalem",
+ "Europe/Isle_of_Man",
+ "Asia/Kolkata",
+ "Indian/Chagos",
+ "Asia/Baghdad",
+ "Asia/Tehran",
+ "Atlantic/Reykjavik",
+ "Europe/Rome",
+ "Europe/Jersey",
+ "America/Jamaica",
+ "Asia/Amman",
+ "Asia/Tokyo",
+ "Africa/Nairobi",
+ "Asia/Bishkek",
+ "Asia/Phnom_Penh",
+ "Pacific/Tarawa",
+ "Pacific/Enderbury",
+ "Pacific/Kiritimati",
+ "Indian/Comoro",
+ "America/St_Kitts",
+ "Asia/Pyongyang",
+ "Asia/Seoul",
+ "Asia/Kuwait",
+ "America/Cayman",
+ "Asia/Almaty",
+ "Asia/Qyzylorda",
+ "Asia/Aqtobe",
+ "Asia/Aqtau",
+ "Asia/Oral",
+ "Asia/Vientiane",
+ "Asia/Beirut",
+ "America/St_Lucia",
+ "Europe/Vaduz",
+ "Asia/Colombo",
+ "Africa/Monrovia",
+ "Africa/Maseru",
+ "Europe/Vilnius",
+ "Europe/Luxembourg",
+ "Europe/Riga",
+ "Africa/Tripoli",
+ "Africa/Casablanca",
+ "Europe/Monaco",
+ "Europe/Chisinau",
+ "Europe/Podgorica",
+ "America/Marigot",
+ "Indian/Antananarivo",
+ "Pacific/Majuro",
+ "Pacific/Kwajalein",
+ "Europe/Skopje",
+ "Africa/Bamako",
+ "Asia/Rangoon",
+ "Asia/Ulaanbaatar",
+ "Asia/Hovd",
+ "Asia/Choibalsan",
+ "Asia/Macau",
+ "Pacific/Saipan",
+ "America/Martinique",
+ "Africa/Nouakchott",
+ "America/Montserrat",
+ "Europe/Malta",
+ "Indian/Mauritius",
+ "Indian/Maldives",
+ "Africa/Blantyre",
+ "America/Mexico_City",
+ "America/Cancun",
+ "America/Merida",
+ "America/Monterrey",
+ "America/Matamoros",
+ "America/Mazatlan",
+ "America/Chihuahua",
+ "America/Ojinaga",
+ "America/Hermosillo",
+ "America/Tijuana",
+ "America/Santa_Isabel",
+ "America/Bahia_Banderas",
+ "Asia/Kuala_Lumpur",
+ "Asia/Kuching",
+ "Africa/Maputo",
+ "Africa/Windhoek",
+ "Pacific/Noumea",
+ "Africa/Niamey",
+ "Pacific/Norfolk",
+ "Africa/Lagos",
+ "America/Managua",
+ "Europe/Amsterdam",
+ "Europe/Oslo",
+ "Asia/Kathmandu",
+ "Pacific/Nauru",
+ "Pacific/Niue",
+ "Pacific/Auckland",
+ "Pacific/Chatham",
+ "Asia/Muscat",
+ "America/Panama",
+ "America/Lima",
+ "Pacific/Tahiti",
+ "Pacific/Marquesas",
+ "Pacific/Gambier",
+ "Pacific/Port_Moresby",
+ "Asia/Manila",
+ "Asia/Karachi",
+ "Europe/Warsaw",
+ "America/Miquelon",
+ "Pacific/Pitcairn",
+ "America/Puerto_Rico",
+ "Asia/Gaza",
+ "Asia/Hebron",
+ "Europe/Lisbon",
+ "Atlantic/Madeira",
+ "Atlantic/Azores",
+ "Pacific/Palau",
+ "America/Asuncion",
+ "Asia/Qatar",
+ "Indian/Reunion",
+ "Europe/Bucharest",
+ "Europe/Belgrade",
+ "Europe/Kaliningrad",
+ "Europe/Moscow",
+ "Europe/Volgograd",
+ "Europe/Samara",
+ "Asia/Yekaterinburg",
+ "Asia/Omsk",
+ "Asia/Novosibirsk",
+ "Asia/Novokuznetsk",
+ "Asia/Krasnoyarsk",
+ "Asia/Irkutsk",
+ "Asia/Yakutsk",
+ "Asia/Khandyga",
+ "Asia/Vladivostok",
+ "Asia/Sakhalin",
+ "Asia/Ust-Nera",
+ "Asia/Magadan",
+ "Asia/Kamchatka",
+ "Asia/Anadyr",
+ "Africa/Kigali",
+ "Asia/Riyadh",
+ "Pacific/Guadalcanal",
+ "Indian/Mahe",
+ "Africa/Khartoum",
+ "Europe/Stockholm",
+ "Asia/Singapore",
+ "Atlantic/St_Helena",
+ "Europe/Ljubljana",
+ "Arctic/Longyearbyen",
+ "Europe/Bratislava",
+ "Africa/Freetown",
+ "Europe/San_Marino",
+ "Africa/Dakar",
+ "Africa/Mogadishu",
+ "America/Paramaribo",
+ "Africa/Juba",
+ "Africa/Sao_Tome",
+ "America/El_Salvador",
+ "America/Lower_Princes",
+ "Asia/Damascus",
+ "Africa/Mbabane",
+ "America/Grand_Turk",
+ "Africa/Ndjamena",
+ "Indian/Kerguelen",
+ "Africa/Lome",
+ "Asia/Bangkok",
+ "Asia/Dushanbe",
+ "Pacific/Fakaofo",
+ "Asia/Dili",
+ "Asia/Ashgabat",
+ "Africa/Tunis",
+ "Pacific/Tongatapu",
+ "Europe/Istanbul",
+ "America/Port_of_Spain",
+ "Pacific/Funafuti",
+ "Asia/Taipei",
+ "Africa/Dar_es_Salaam",
+ "Europe/Kiev",
+ "Europe/Uzhgorod",
+ "Europe/Zaporozhye",
+ "Europe/Simferopol",
+ "Africa/Kampala",
+ "Pacific/Johnston",
+ "Pacific/Midway",
+ "Pacific/Wake",
+ "America/New_York",
+ "America/Detroit",
+ "America/Kentucky/Louisville",
+ "America/Kentucky/Monticello",
+ "America/Indiana/Indianapolis",
+ "America/Indiana/Vincennes",
+ "America/Indiana/Winamac",
+ "America/Indiana/Marengo",
+ "America/Indiana/Petersburg",
+ "America/Indiana/Vevay",
+ "America/Chicago",
+ "America/Indiana/Tell_City",
+ "America/Indiana/Knox",
+ "America/Menominee",
+ "America/North_Dakota/Center",
+ "America/North_Dakota/New_Salem",
+ "America/North_Dakota/Beulah",
+ "America/Denver",
+ "America/Boise",
+ "America/Shiprock",
+ "America/Phoenix",
+ "America/Los_Angeles",
+ "America/Anchorage",
+ "America/Juneau",
+ "America/Sitka",
+ "America/Yakutat",
+ "America/Nome",
+ "America/Adak",
+ "America/Metlakatla",
+ "Pacific/Honolulu",
+ "America/Montevideo",
+ "Asia/Samarkand",
+ "Asia/Tashkent",
+ "Europe/Vatican",
+ "America/St_Vincent",
+ "America/Caracas",
+ "America/Tortola",
+ "America/St_Thomas",
+ "Asia/Ho_Chi_Minh",
+ "Pacific/Efate",
+ "Pacific/Wallis",
+ "Pacific/Apia",
+ "Asia/Aden",
+ "Indian/Mayotte",
+ "Africa/Johannesburg",
+ "Africa/Lusaka",
+ "Africa/Harare"
+};
+
+static const int numOlsonTimezones = sizeof olsonTimezones / sizeof *olsonTimezones;
+
diff --git a/utils/zonetabconversion.py b/utils/zonetabconversion.py
new file mode 100755
index 0000000..adb78fd
--- /dev/null
+++ b/utils/zonetabconversion.py
@@ -0,0 +1,29 @@
+#!/bin/python2.7
+
+tztable = open("tztable.h", "w")
+tztable.write("//This file was generated by the zonetabconversion.py script\n");
+tztable.write("static const char* olsonTimezones[] = {\n");
+
+zonefile = open("/usr/share/zoneinfo/zone.tab", "r")
+first = True
+for line in zonefile:
+ # print line
+ if line.startswith('#'):
+ # print "continue"
+ continue
+ else:
+ tz = line.split(None)[2]
+ print tz
+ if first:
+ first = False
+ tztable.write(" \"")
+ else:
+ tztable.write(",\n \"")
+ tztable.write(tz)
+ tztable.write("\"")
+
+tztable.write("\n};\n")
+tztable.write("\n")
+tztable.write("static const int numOlsonTimezones = sizeof olsonTimezones / sizeof *olsonTimezones;\n")
+tztable.write("\n")
+