From c6de2889053b47edfab2b87a41c09e9010cb3c10 Mon Sep 17 00:00:00 2001 From: "spider%netscape.com" Date: Fri, 25 Sep 1998 17:58:12 +0000 Subject: [PATCH] Modularized Julian now resided in Zulu --- calendar/modules/core/Makefile | 53 - calendar/modules/core/capi/Makefile | 0 calendar/modules/core/capi/local/Makefile | 0 calendar/modules/core/capi/local/inc/Makefile | 0 calendar/modules/core/capi/local/inc/capi.h | 311 ++ .../modules/core/capi/local/inc/manifest.mn | 0 .../modules/core/capi/local/inc/privcapi.h | 60 + calendar/modules/core/capi/local/manifest.mn | 0 calendar/modules/core/capi/local/src/Makefile | 0 calendar/modules/core/capi/local/src/capi.cpp | 1400 +++++++ .../modules/core/capi/local/src/config.mk | 0 .../modules/core/capi/local/src/manifest.mn | 0 calendar/modules/core/capi/manifest.mn | 0 calendar/modules/core/config.mk | 0 calendar/modules/core/htmlform/Makefile | 0 calendar/modules/core/htmlform/inc/Makefile | 0 calendar/modules/core/htmlform/inc/form.h | 106 + .../modules/core/htmlform/inc/formFactory.h | 530 +++ .../modules/core/htmlform/inc/julianform.h | 166 + .../modules/core/htmlform/inc/manifest.mn | 0 calendar/modules/core/htmlform/manifest.mn | 0 calendar/modules/core/htmlform/src/Makefile | 0 calendar/modules/core/htmlform/src/config.mk | 0 calendar/modules/core/htmlform/src/form.cpp | 920 +++++ .../modules/core/htmlform/src/formFactory.cpp | 2676 ++++++++++++++ .../modules/core/htmlform/src/julianform.c | 127 + .../modules/core/htmlform/src/manifest.mn | 0 calendar/modules/core/ical/Makefile | 0 calendar/modules/core/ical/inc/Makefile | 0 calendar/modules/core/ical/inc/abprprty.h | 0 calendar/modules/core/ical/inc/attendee.h | 756 ++++ calendar/modules/core/ical/inc/bprprty.h | 120 + calendar/modules/core/ical/inc/bydmgntr.h | 124 + calendar/modules/core/ical/inc/bydwgntr.h | 120 + calendar/modules/core/ical/inc/bydygntr.h | 118 + calendar/modules/core/ical/inc/byhgntr.h | 104 + calendar/modules/core/ical/inc/bymdgntr.h | 103 + calendar/modules/core/ical/inc/bymgntr.h | 102 + calendar/modules/core/ical/inc/bymogntr.h | 103 + calendar/modules/core/ical/inc/bywngntr.h | 101 + calendar/modules/core/ical/inc/byydgntr.h | 102 + calendar/modules/core/ical/inc/capiredr.h | 170 + calendar/modules/core/ical/inc/dategntr.h | 166 + calendar/modules/core/ical/inc/deftgntr.h | 110 + calendar/modules/core/ical/inc/dprprty.h | 153 + calendar/modules/core/ical/inc/duprprty.h | 121 + calendar/modules/core/ical/inc/freebusy.h | 435 +++ calendar/modules/core/ical/inc/functbl.h | 124 + calendar/modules/core/ical/inc/icalcomp.h | 516 +++ calendar/modules/core/ical/inc/icalfrdr.h | 108 + calendar/modules/core/ical/inc/icalprm.h | 138 + calendar/modules/core/ical/inc/icalredr.h | 117 + calendar/modules/core/ical/inc/icalsrdr.h | 130 + calendar/modules/core/ical/inc/icompfy.h | 65 + calendar/modules/core/ical/inc/iprprty.h | 121 + calendar/modules/core/ical/inc/jparser.h | 90 + calendar/modules/core/ical/inc/manifest.mn | 0 calendar/modules/core/ical/inc/nscal.h | 820 +++++ .../modules/core/ical/inc/nscalcoreicalexp.h | 30 + calendar/modules/core/ical/inc/orgnzr.h | 273 ++ calendar/modules/core/ical/inc/period.h | 319 ++ calendar/modules/core/ical/inc/pprprty.h | 124 + calendar/modules/core/ical/inc/prprty.h | 411 +++ calendar/modules/core/ical/inc/prprtyfy.h | 67 + calendar/modules/core/ical/inc/rcrrence.h | 530 +++ calendar/modules/core/ical/inc/recid.h | 242 ++ calendar/modules/core/ical/inc/rrday.h | 94 + calendar/modules/core/ical/inc/sdprprty.h | 197 + calendar/modules/core/ical/inc/sprprty.h | 120 + calendar/modules/core/ical/inc/stdafx.h | 23 + calendar/modules/core/ical/inc/tmbevent.h | 955 +++++ calendar/modules/core/ical/inc/tzpart.h | 393 ++ calendar/modules/core/ical/inc/unistrto.h | 108 + calendar/modules/core/ical/inc/uri.h | 101 + calendar/modules/core/ical/inc/valarm.h | 377 ++ calendar/modules/core/ical/inc/vevent.h | 334 ++ calendar/modules/core/ical/inc/vfrbsy.h | 549 +++ calendar/modules/core/ical/inc/vjournal.h | 244 ++ calendar/modules/core/ical/inc/vtimezne.h | 317 ++ calendar/modules/core/ical/inc/vtodo.h | 348 ++ calendar/modules/core/ical/manifest.mn | 0 calendar/modules/core/ical/src/Makefile | 0 calendar/modules/core/ical/src/attendee.cpp | 1140 ++++++ calendar/modules/core/ical/src/bprprty.cpp | 118 + calendar/modules/core/ical/src/bydmgntr.cpp | 188 + calendar/modules/core/ical/src/bydwgntr.cpp | 85 + calendar/modules/core/ical/src/bydygntr.cpp | 173 + calendar/modules/core/ical/src/byhgntr.cpp | 104 + calendar/modules/core/ical/src/bymdgntr.cpp | 100 + calendar/modules/core/ical/src/bymgntr.cpp | 97 + calendar/modules/core/ical/src/bymogntr.cpp | 91 + calendar/modules/core/ical/src/bywngntr.cpp | 89 + calendar/modules/core/ical/src/byydgntr.cpp | 102 + calendar/modules/core/ical/src/capiredr.cpp | 540 +++ calendar/modules/core/ical/src/config.mk | 0 calendar/modules/core/ical/src/dategntr.cpp | 46 + calendar/modules/core/ical/src/deftgntr.cpp | 83 + calendar/modules/core/ical/src/dprprty.cpp | 183 + calendar/modules/core/ical/src/duprprty.cpp | 133 + calendar/modules/core/ical/src/freebusy.cpp | 757 ++++ calendar/modules/core/ical/src/functbl.cpp | 137 + calendar/modules/core/ical/src/icalcomp.cpp | 640 ++++ calendar/modules/core/ical/src/icalfrdr.cpp | 134 + calendar/modules/core/ical/src/icalprm.cpp | 139 + calendar/modules/core/ical/src/icalredr.cpp | 71 + calendar/modules/core/ical/src/icalsrdr.cpp | 213 ++ calendar/modules/core/ical/src/icompfy.cpp | 80 + calendar/modules/core/ical/src/iprprty.cpp | 120 + calendar/modules/core/ical/src/jparser.cpp | 196 + calendar/modules/core/ical/src/manifest.mn | 0 calendar/modules/core/ical/src/nscal.cpp | 2241 ++++++++++++ calendar/modules/core/ical/src/orgnzr.cpp | 374 ++ calendar/modules/core/ical/src/period.cpp | 620 ++++ calendar/modules/core/ical/src/pprprty.cpp | 154 + calendar/modules/core/ical/src/prprty.cpp | 763 ++++ calendar/modules/core/ical/src/prprtyfy.cpp | 74 + calendar/modules/core/ical/src/rcrrence.cpp | 1867 ++++++++++ calendar/modules/core/ical/src/recid.cpp | 260 ++ calendar/modules/core/ical/src/rrday.cpp | 81 + calendar/modules/core/ical/src/sdprprty.cpp | 184 + calendar/modules/core/ical/src/sprpty.cpp | 129 + calendar/modules/core/ical/src/tmbevent.cpp | 3246 +++++++++++++++++ calendar/modules/core/ical/src/tzpart.cpp | 1021 ++++++ calendar/modules/core/ical/src/unistrto.cpp | 110 + calendar/modules/core/ical/src/uri.cpp | 79 + calendar/modules/core/ical/src/valarm.cpp | 1016 ++++++ calendar/modules/core/ical/src/vevent.cpp | 1188 ++++++ calendar/modules/core/ical/src/vfrbsy.cpp | 2101 +++++++++++ calendar/modules/core/ical/src/vjournal.cpp | 426 +++ calendar/modules/core/ical/src/vtimezne.cpp | 811 ++++ calendar/modules/core/ical/src/vtodo.cpp | 1217 ++++++ calendar/modules/core/inc/JulianParser.h | 90 + calendar/modules/core/inc/manifest.mn | 3 + calendar/modules/core/inc/nsCalStreamReader.h | 86 + .../modules/core/inc/nsCapiCallbackReader.h | 170 + calendar/modules/core/manifest.mn | 15 - calendar/modules/core/src/config.mk | 33 - calendar/modules/core/src/manifest.mn | 2 + .../modules/core/src/nsCalStreamReader.cpp | 211 ++ .../modules/core/src/nsCapiCallbackReader.cpp | 401 ++ calendar/modules/network/capi/config.mk | 1 - calendar/modules/network/capi/inc/manifest.mn | 26 - .../modules/network/capi/local/src/config.mk | 26 - calendar/modules/network/capi/manifest.mn | 30 - calendar/modules/network/capi/src/manifest.mn | 28 - calendar/modules/network/config.mk | 32 - calendar/modules/network/itip/Makefile | 0 calendar/modules/network/itip/inc/Makefile | 0 calendar/modules/network/itip/inc/detxnobj.h | 88 + calendar/modules/network/itip/inc/getxnobj.h | 121 + calendar/modules/network/itip/inc/manifest.mn | 0 calendar/modules/network/itip/inc/stdafx.h | 0 calendar/modules/network/itip/inc/sttxnobj.h | 88 + calendar/modules/network/itip/inc/txnengn.h | 0 calendar/modules/network/itip/inc/txnobj.h | 330 ++ calendar/modules/network/itip/inc/txnobjfy.h | 65 + calendar/modules/network/itip/inc/user.h | 162 + calendar/modules/network/itip/manifest.mn | 0 calendar/modules/network/itip/src/Makefile | 0 calendar/modules/network/itip/src/config.mk | 0 .../modules/network/itip/src/detxnobj.cpp | 126 + .../modules/network/itip/src/getxnobj.cpp | 385 ++ calendar/modules/network/itip/src/manifest.mn | 0 .../modules/network/itip/src/sttxnobj.cpp | 177 + calendar/modules/network/itip/src/txnengn.cpp | 0 calendar/modules/network/itip/src/txnobj.cpp | 661 ++++ .../modules/network/itip/src/txnobjfy.cpp | 115 + calendar/modules/network/itip/src/user.cpp | 231 ++ calendar/modules/network/manifest.mn | 23 - calendar/modules/nls/nlsstub/inc/calendar.h | 107 + calendar/modules/nls/nlsstub/inc/datefmt.h | 46 + calendar/modules/nls/nlsstub/inc/gregocal.h | 52 + calendar/modules/nls/nlsstub/inc/hashtab.h | 23 + calendar/modules/nls/nlsstub/inc/locid.h | 38 + calendar/modules/nls/nlsstub/inc/nlsloc.h | 30 + calendar/modules/nls/nlsstub/inc/parsepos.h | 39 + calendar/modules/nls/nlsstub/inc/ptypes.h | 50 + calendar/modules/nls/nlsstub/inc/simpletz.h | 46 + calendar/modules/nls/nlsstub/inc/smpdtfmt.h | 55 + calendar/modules/nls/nlsstub/inc/timezone.h | 40 + calendar/modules/nls/nlsstub/inc/unicode.h | 23 + calendar/modules/nls/nlsstub/inc/unistring.h | 94 + calendar/modules/nls/nlsstub/src/calendar.cpp | 249 ++ calendar/modules/nls/nlsstub/src/datefmt.cpp | 53 + calendar/modules/nls/nlsstub/src/gregocal.cpp | 138 + calendar/modules/nls/nlsstub/src/locid.cpp | 41 + calendar/modules/nls/nlsstub/src/nlsloc.cpp | 30 + calendar/modules/nls/nlsstub/src/parsepos.cpp | 42 + calendar/modules/nls/nlsstub/src/simpletz.cpp | 64 + calendar/modules/nls/nlsstub/src/smpdtfmt.cpp | 80 + calendar/modules/nls/nlsstub/src/timezone.cpp | 46 + .../modules/nls/nlsstub/src/unistring.cpp | 303 ++ calendar/modules/parser/config.mk | 36 - calendar/modules/shell/src/config.mk | 2 +- calendar/modules/test/inc/manifest.mn | 24 - calendar/modules/test/public/manifest.mn | 22 - calendar/modules/test/src/config.mk | 2 - calendar/modules/test/src/manifest.mn | 4 +- calendar/modules/ui/config.mk | 42 - calendar/modules/util/inc/datetime.h | 867 +++++ calendar/modules/util/inc/duration.h | 397 ++ calendar/modules/util/inc/jatom.h | 105 + calendar/modules/util/inc/jdefines.h | 77 + calendar/modules/util/inc/jlog.h | 226 ++ calendar/modules/util/inc/jlogerr.h | 93 + calendar/modules/util/inc/jlogitr.h | 82 + calendar/modules/util/inc/jlogvctr.h | 97 + calendar/modules/util/inc/julnstr.h | 506 +++ calendar/modules/util/inc/jutility.h | 128 + calendar/modules/util/inc/keyword.h | 1430 ++++++++ calendar/modules/util/inc/manifest.mn | 27 - calendar/modules/util/inc/nsCurlParser.h | 4 +- calendar/modules/util/inc/nsX400Parser.h | 4 +- calendar/modules/util/inc/ptrarray.h | 100 + calendar/modules/util/inc/stdafx.h | 0 calendar/modules/util/inc/uidrgntr.h | 67 + calendar/modules/util/public/manifest.mn | 23 - calendar/modules/util/public/nscalutilexp.h | 30 + calendar/modules/util/src/config.mk | 29 - calendar/modules/util/src/datetime.cpp | 1559 ++++++++ calendar/modules/util/src/duration.cpp | 730 ++++ calendar/modules/util/src/jatom.cpp | 54 + calendar/modules/util/src/jlog.cpp | 231 ++ calendar/modules/util/src/jlogerr.cpp | 60 + calendar/modules/util/src/jlogitr.cpp | 101 + calendar/modules/util/src/jlogvctr.cpp | 59 + calendar/modules/util/src/julnstr.cpp | 1046 ++++++ calendar/modules/util/src/jutility.cpp | 173 + calendar/modules/util/src/keyword.cpp | 1255 +++++++ calendar/modules/util/src/manifest.mn | 29 - calendar/modules/util/src/ptrarray.cpp | 381 ++ calendar/modules/util/src/uidrgntr.cpp | 76 + trex.mak | 16 +- trex.mk | 6 - 234 files changed, 56554 insertions(+), 524 deletions(-) create mode 100644 calendar/modules/core/capi/Makefile create mode 100644 calendar/modules/core/capi/local/Makefile create mode 100644 calendar/modules/core/capi/local/inc/Makefile create mode 100644 calendar/modules/core/capi/local/inc/capi.h create mode 100644 calendar/modules/core/capi/local/inc/manifest.mn create mode 100644 calendar/modules/core/capi/local/inc/privcapi.h create mode 100644 calendar/modules/core/capi/local/manifest.mn create mode 100644 calendar/modules/core/capi/local/src/Makefile create mode 100644 calendar/modules/core/capi/local/src/capi.cpp create mode 100644 calendar/modules/core/capi/local/src/config.mk create mode 100644 calendar/modules/core/capi/local/src/manifest.mn create mode 100644 calendar/modules/core/capi/manifest.mn create mode 100644 calendar/modules/core/config.mk create mode 100644 calendar/modules/core/htmlform/Makefile create mode 100644 calendar/modules/core/htmlform/inc/Makefile create mode 100644 calendar/modules/core/htmlform/inc/form.h create mode 100644 calendar/modules/core/htmlform/inc/formFactory.h create mode 100644 calendar/modules/core/htmlform/inc/julianform.h create mode 100644 calendar/modules/core/htmlform/inc/manifest.mn create mode 100644 calendar/modules/core/htmlform/manifest.mn create mode 100644 calendar/modules/core/htmlform/src/Makefile create mode 100644 calendar/modules/core/htmlform/src/config.mk create mode 100644 calendar/modules/core/htmlform/src/form.cpp create mode 100644 calendar/modules/core/htmlform/src/formFactory.cpp create mode 100644 calendar/modules/core/htmlform/src/julianform.c create mode 100644 calendar/modules/core/htmlform/src/manifest.mn create mode 100644 calendar/modules/core/ical/Makefile create mode 100644 calendar/modules/core/ical/inc/Makefile create mode 100644 calendar/modules/core/ical/inc/abprprty.h create mode 100644 calendar/modules/core/ical/inc/attendee.h create mode 100644 calendar/modules/core/ical/inc/bprprty.h create mode 100644 calendar/modules/core/ical/inc/bydmgntr.h create mode 100644 calendar/modules/core/ical/inc/bydwgntr.h create mode 100644 calendar/modules/core/ical/inc/bydygntr.h create mode 100644 calendar/modules/core/ical/inc/byhgntr.h create mode 100644 calendar/modules/core/ical/inc/bymdgntr.h create mode 100644 calendar/modules/core/ical/inc/bymgntr.h create mode 100644 calendar/modules/core/ical/inc/bymogntr.h create mode 100644 calendar/modules/core/ical/inc/bywngntr.h create mode 100644 calendar/modules/core/ical/inc/byydgntr.h create mode 100644 calendar/modules/core/ical/inc/capiredr.h create mode 100644 calendar/modules/core/ical/inc/dategntr.h create mode 100644 calendar/modules/core/ical/inc/deftgntr.h create mode 100644 calendar/modules/core/ical/inc/dprprty.h create mode 100644 calendar/modules/core/ical/inc/duprprty.h create mode 100644 calendar/modules/core/ical/inc/freebusy.h create mode 100644 calendar/modules/core/ical/inc/functbl.h create mode 100644 calendar/modules/core/ical/inc/icalcomp.h create mode 100644 calendar/modules/core/ical/inc/icalfrdr.h create mode 100644 calendar/modules/core/ical/inc/icalprm.h create mode 100644 calendar/modules/core/ical/inc/icalredr.h create mode 100644 calendar/modules/core/ical/inc/icalsrdr.h create mode 100644 calendar/modules/core/ical/inc/icompfy.h create mode 100644 calendar/modules/core/ical/inc/iprprty.h create mode 100644 calendar/modules/core/ical/inc/jparser.h create mode 100644 calendar/modules/core/ical/inc/manifest.mn create mode 100644 calendar/modules/core/ical/inc/nscal.h create mode 100644 calendar/modules/core/ical/inc/nscalcoreicalexp.h create mode 100644 calendar/modules/core/ical/inc/orgnzr.h create mode 100644 calendar/modules/core/ical/inc/period.h create mode 100644 calendar/modules/core/ical/inc/pprprty.h create mode 100644 calendar/modules/core/ical/inc/prprty.h create mode 100644 calendar/modules/core/ical/inc/prprtyfy.h create mode 100644 calendar/modules/core/ical/inc/rcrrence.h create mode 100644 calendar/modules/core/ical/inc/recid.h create mode 100644 calendar/modules/core/ical/inc/rrday.h create mode 100644 calendar/modules/core/ical/inc/sdprprty.h create mode 100644 calendar/modules/core/ical/inc/sprprty.h create mode 100644 calendar/modules/core/ical/inc/stdafx.h create mode 100644 calendar/modules/core/ical/inc/tmbevent.h create mode 100644 calendar/modules/core/ical/inc/tzpart.h create mode 100644 calendar/modules/core/ical/inc/unistrto.h create mode 100644 calendar/modules/core/ical/inc/uri.h create mode 100644 calendar/modules/core/ical/inc/valarm.h create mode 100644 calendar/modules/core/ical/inc/vevent.h create mode 100644 calendar/modules/core/ical/inc/vfrbsy.h create mode 100644 calendar/modules/core/ical/inc/vjournal.h create mode 100644 calendar/modules/core/ical/inc/vtimezne.h create mode 100644 calendar/modules/core/ical/inc/vtodo.h create mode 100644 calendar/modules/core/ical/manifest.mn create mode 100644 calendar/modules/core/ical/src/Makefile create mode 100644 calendar/modules/core/ical/src/attendee.cpp create mode 100644 calendar/modules/core/ical/src/bprprty.cpp create mode 100644 calendar/modules/core/ical/src/bydmgntr.cpp create mode 100644 calendar/modules/core/ical/src/bydwgntr.cpp create mode 100644 calendar/modules/core/ical/src/bydygntr.cpp create mode 100644 calendar/modules/core/ical/src/byhgntr.cpp create mode 100644 calendar/modules/core/ical/src/bymdgntr.cpp create mode 100644 calendar/modules/core/ical/src/bymgntr.cpp create mode 100644 calendar/modules/core/ical/src/bymogntr.cpp create mode 100644 calendar/modules/core/ical/src/bywngntr.cpp create mode 100644 calendar/modules/core/ical/src/byydgntr.cpp create mode 100644 calendar/modules/core/ical/src/capiredr.cpp create mode 100644 calendar/modules/core/ical/src/config.mk create mode 100644 calendar/modules/core/ical/src/dategntr.cpp create mode 100644 calendar/modules/core/ical/src/deftgntr.cpp create mode 100644 calendar/modules/core/ical/src/dprprty.cpp create mode 100644 calendar/modules/core/ical/src/duprprty.cpp create mode 100644 calendar/modules/core/ical/src/freebusy.cpp create mode 100644 calendar/modules/core/ical/src/functbl.cpp create mode 100644 calendar/modules/core/ical/src/icalcomp.cpp create mode 100644 calendar/modules/core/ical/src/icalfrdr.cpp create mode 100644 calendar/modules/core/ical/src/icalprm.cpp create mode 100644 calendar/modules/core/ical/src/icalredr.cpp create mode 100644 calendar/modules/core/ical/src/icalsrdr.cpp create mode 100644 calendar/modules/core/ical/src/icompfy.cpp create mode 100644 calendar/modules/core/ical/src/iprprty.cpp create mode 100644 calendar/modules/core/ical/src/jparser.cpp create mode 100644 calendar/modules/core/ical/src/manifest.mn create mode 100644 calendar/modules/core/ical/src/nscal.cpp create mode 100644 calendar/modules/core/ical/src/orgnzr.cpp create mode 100644 calendar/modules/core/ical/src/period.cpp create mode 100644 calendar/modules/core/ical/src/pprprty.cpp create mode 100644 calendar/modules/core/ical/src/prprty.cpp create mode 100644 calendar/modules/core/ical/src/prprtyfy.cpp create mode 100644 calendar/modules/core/ical/src/rcrrence.cpp create mode 100644 calendar/modules/core/ical/src/recid.cpp create mode 100644 calendar/modules/core/ical/src/rrday.cpp create mode 100644 calendar/modules/core/ical/src/sdprprty.cpp create mode 100644 calendar/modules/core/ical/src/sprpty.cpp create mode 100644 calendar/modules/core/ical/src/tmbevent.cpp create mode 100644 calendar/modules/core/ical/src/tzpart.cpp create mode 100644 calendar/modules/core/ical/src/unistrto.cpp create mode 100644 calendar/modules/core/ical/src/uri.cpp create mode 100644 calendar/modules/core/ical/src/valarm.cpp create mode 100644 calendar/modules/core/ical/src/vevent.cpp create mode 100644 calendar/modules/core/ical/src/vfrbsy.cpp create mode 100644 calendar/modules/core/ical/src/vjournal.cpp create mode 100644 calendar/modules/core/ical/src/vtimezne.cpp create mode 100644 calendar/modules/core/ical/src/vtodo.cpp create mode 100644 calendar/modules/core/inc/JulianParser.h create mode 100644 calendar/modules/core/inc/nsCalStreamReader.h create mode 100644 calendar/modules/core/inc/nsCapiCallbackReader.h create mode 100644 calendar/modules/core/src/nsCalStreamReader.cpp create mode 100644 calendar/modules/core/src/nsCapiCallbackReader.cpp create mode 100644 calendar/modules/network/itip/Makefile create mode 100644 calendar/modules/network/itip/inc/Makefile create mode 100644 calendar/modules/network/itip/inc/detxnobj.h create mode 100644 calendar/modules/network/itip/inc/getxnobj.h create mode 100644 calendar/modules/network/itip/inc/manifest.mn create mode 100644 calendar/modules/network/itip/inc/stdafx.h create mode 100644 calendar/modules/network/itip/inc/sttxnobj.h create mode 100644 calendar/modules/network/itip/inc/txnengn.h create mode 100644 calendar/modules/network/itip/inc/txnobj.h create mode 100644 calendar/modules/network/itip/inc/txnobjfy.h create mode 100644 calendar/modules/network/itip/inc/user.h create mode 100644 calendar/modules/network/itip/manifest.mn create mode 100644 calendar/modules/network/itip/src/Makefile create mode 100644 calendar/modules/network/itip/src/config.mk create mode 100644 calendar/modules/network/itip/src/detxnobj.cpp create mode 100644 calendar/modules/network/itip/src/getxnobj.cpp create mode 100644 calendar/modules/network/itip/src/manifest.mn create mode 100644 calendar/modules/network/itip/src/sttxnobj.cpp create mode 100644 calendar/modules/network/itip/src/txnengn.cpp create mode 100644 calendar/modules/network/itip/src/txnobj.cpp create mode 100644 calendar/modules/network/itip/src/txnobjfy.cpp create mode 100644 calendar/modules/network/itip/src/user.cpp create mode 100644 calendar/modules/nls/nlsstub/inc/calendar.h create mode 100644 calendar/modules/nls/nlsstub/inc/datefmt.h create mode 100644 calendar/modules/nls/nlsstub/inc/gregocal.h create mode 100644 calendar/modules/nls/nlsstub/inc/hashtab.h create mode 100644 calendar/modules/nls/nlsstub/inc/locid.h create mode 100644 calendar/modules/nls/nlsstub/inc/nlsloc.h create mode 100644 calendar/modules/nls/nlsstub/inc/parsepos.h create mode 100644 calendar/modules/nls/nlsstub/inc/ptypes.h create mode 100644 calendar/modules/nls/nlsstub/inc/simpletz.h create mode 100644 calendar/modules/nls/nlsstub/inc/smpdtfmt.h create mode 100644 calendar/modules/nls/nlsstub/inc/timezone.h create mode 100644 calendar/modules/nls/nlsstub/inc/unicode.h create mode 100644 calendar/modules/nls/nlsstub/inc/unistring.h create mode 100644 calendar/modules/nls/nlsstub/src/calendar.cpp create mode 100644 calendar/modules/nls/nlsstub/src/datefmt.cpp create mode 100644 calendar/modules/nls/nlsstub/src/gregocal.cpp create mode 100644 calendar/modules/nls/nlsstub/src/locid.cpp create mode 100644 calendar/modules/nls/nlsstub/src/nlsloc.cpp create mode 100644 calendar/modules/nls/nlsstub/src/parsepos.cpp create mode 100644 calendar/modules/nls/nlsstub/src/simpletz.cpp create mode 100644 calendar/modules/nls/nlsstub/src/smpdtfmt.cpp create mode 100644 calendar/modules/nls/nlsstub/src/timezone.cpp create mode 100644 calendar/modules/nls/nlsstub/src/unistring.cpp create mode 100644 calendar/modules/util/inc/datetime.h create mode 100644 calendar/modules/util/inc/duration.h create mode 100644 calendar/modules/util/inc/jatom.h create mode 100644 calendar/modules/util/inc/jdefines.h create mode 100644 calendar/modules/util/inc/jlog.h create mode 100644 calendar/modules/util/inc/jlogerr.h create mode 100644 calendar/modules/util/inc/jlogitr.h create mode 100644 calendar/modules/util/inc/jlogvctr.h create mode 100644 calendar/modules/util/inc/julnstr.h create mode 100644 calendar/modules/util/inc/jutility.h create mode 100644 calendar/modules/util/inc/keyword.h create mode 100644 calendar/modules/util/inc/ptrarray.h create mode 100644 calendar/modules/util/inc/stdafx.h create mode 100644 calendar/modules/util/inc/uidrgntr.h create mode 100644 calendar/modules/util/public/nscalutilexp.h create mode 100644 calendar/modules/util/src/datetime.cpp create mode 100644 calendar/modules/util/src/duration.cpp create mode 100644 calendar/modules/util/src/jatom.cpp create mode 100644 calendar/modules/util/src/jlog.cpp create mode 100644 calendar/modules/util/src/jlogerr.cpp create mode 100644 calendar/modules/util/src/jlogitr.cpp create mode 100644 calendar/modules/util/src/jlogvctr.cpp create mode 100644 calendar/modules/util/src/julnstr.cpp create mode 100644 calendar/modules/util/src/jutility.cpp create mode 100644 calendar/modules/util/src/keyword.cpp create mode 100644 calendar/modules/util/src/ptrarray.cpp create mode 100644 calendar/modules/util/src/uidrgntr.cpp diff --git a/calendar/modules/core/Makefile b/calendar/modules/core/Makefile index 61267ebf415..e69de29bb2d 100644 --- a/calendar/modules/core/Makefile +++ b/calendar/modules/core/Makefile @@ -1,53 +0,0 @@ -#! gmake -# -# CONFIDENTIAL AND PROPRIETARY SOURCE CODE OF -# NETSCAPE COMMUNICATIONS CORPORATION -# Copyright © 1996, 1997 Netscape Communications Corporation. All Rights -# Reserved. Use of this Source Code is subject to the terms of the -# applicable license agreement from Netscape Communications Corporation. -# The copyright notice(s) in this Source Code does not indicate actual or -# intended publication of this Source Code. -# - -####################################################################### -# (1) Include initial platform-independent assignments (MANDATORY). # -####################################################################### - -include manifest.mn - -####################################################################### -# (2) Include "global" configuration information. (OPTIONAL) # -####################################################################### - -include $(GDEPTH)/gconfig/config.mk - -####################################################################### -# (3) Include "component" configuration information. (OPTIONAL) # -####################################################################### - - - -####################################################################### -# (4) Include "local" platform-dependent assignments (OPTIONAL). # -####################################################################### - - - -####################################################################### -# (5) Execute "global" rules. (OPTIONAL) # -####################################################################### - -include $(GDEPTH)/gconfig/rules.mk - -####################################################################### -# (6) Execute "component" rules. (OPTIONAL) # -####################################################################### - - - -####################################################################### -# (7) Execute "local" rules. (OPTIONAL). # -####################################################################### - - - diff --git a/calendar/modules/core/capi/Makefile b/calendar/modules/core/capi/Makefile new file mode 100644 index 00000000000..e69de29bb2d diff --git a/calendar/modules/core/capi/local/Makefile b/calendar/modules/core/capi/local/Makefile new file mode 100644 index 00000000000..e69de29bb2d diff --git a/calendar/modules/core/capi/local/inc/Makefile b/calendar/modules/core/capi/local/inc/Makefile new file mode 100644 index 00000000000..e69de29bb2d diff --git a/calendar/modules/core/capi/local/inc/capi.h b/calendar/modules/core/capi/local/inc/capi.h new file mode 100644 index 00000000000..0eda310f6a9 --- /dev/null +++ b/calendar/modules/core/capi/local/inc/capi.h @@ -0,0 +1,311 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 +-*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +/* + * capi.h + * + * sman + * 30-Jun-98 + */ + +#ifndef __JULIAN_LOCAL_CAPI_H +#define __JULIAN_LOCAL_CAPI_H + +#include "jdefines.h" +#include +#include "nscore.h" +#include "nscalexport.h" + +typedef void* CAPISession; +typedef void* CAPIHandle; +typedef void* CAPIStream; +typedef long CAPIStatus; + +#define CAPI_THISINSTANCE 1 +#define CAPI_THISANDPRIOR 2 +#define CAPI_THISANDFUTURE 3 + +#define CAPI_CALLBACK_CONTINUE 0 +#define CAPI_CALLBACK_DONE -1 + +#if 0 +#define CAPI_ERR_OK 0 + +#define CAPI_ERR_CALLBACK 1 +#define CAPI_ERR_COMP_NOT_FOUND 2 +#define CAPI_ERR_CORRUPT_HANDLE 3 +#define CAPI_ERR_CORRUPT_SESSION 4 +#define CAPI_ERR_CORRUPT_STREAM 5 +#define CAPI_ERR_DATE 6 +#define CAPI_ERR_DATE_RANGE 7 +#define CAPI_ERR_EXPIRED 8 +#define CAPI_ERR_FLAGS 9 +#define CAPI_ERR_HOST 10 +#define CAPI_ERR_INTERNAL 11 +#define CAPI_ERR_IO 12 +#define CAPI_ERR_NO_MEMORY 13 +#define CAPI_ERR_NOT_IMPLEMENTED 14 +#define CAPI_ERR_NULL_PARAMETER 15 +#define CAPI_ERR_PROPERTIES_BLOCKED 16 +#define CAPI_ERR_REQUIRED_PROPERTY_MISSING 17 +#define CAPI_ERR_SECURITY 18 +#define CAPI_ERR_SERVER 19 +#define CAPI_ERR_UID 20 +#define CAPI_ERR_USERNAME_PASSWORD 21 +#endif + +typedef int (*CAPICallback)( + void* pData, /* i: caller-defined data, the value */ + /* supplied in CAPI_SetStreamCallbacks */ + char* pBuf, /* i: buffer to read or write */ + size_t iSize, /* i: the number of characters in pBuf */ + size_t* piTransferred); /* o: the number of characters from pBuf that */ + + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +NS_CALENDAR CAPIStatus CAPI_Capabilities( + const char** ppsVal, /* o: a string describing the capabilities */ + const char* psHost, /* i: server host */ + long lFlags ); /* i: bit flags (none at this time; set to 0) */ + /* were processed. */ + +NS_CALENDAR CAPIStatus CAPI_DeleteEvent( + CAPISession s, /* i: login session handle */ + CAPIHandle* pH, /* i: list of CAPIHandles for delete */ + int iHandleCount, /* i: number of valid handles in ppH */ + long lFlags, /* i: bit flags (none at this time; set to 0) */ + char* psUID, /* i: UID of the event to delete */ + char* dtRecurrenceID, /* i: recurrence-id, NULL means ignore */ + int iModifier); /* i: one of CAPI_THISINSTANCE, */ + /* CAPI_THISANDPRIOR, CAPI_THISANDFUTURE */ + /* only valid if recurrence-id is non-NULL */ + +NS_CALENDAR CAPIStatus CAPI_DestroyHandles( + CAPISession s, /* i: login session handle */ + CAPIHandle* pHList, /* i: pointer to a list of handles to destroy */ + int iHandleCount, /* i: number of valid handles in pHList */ + long lFlags); /* i: bit flags (none at this time; set to 0) */ + +NS_CALENDAR CAPIStatus CAPI_DestroyStreams( + CAPISession s, /* i: login session handle */ + CAPIStream* pS, /* i: array of streams to destroy */ + int iCount, /* i: number of valid handles in ppH */ + long lFlags); /* i: bit flags (none at this time; set to 0) */ + +NS_CALENDAR CAPIStatus CAPI_FetchEventsByAlarmRange( + CAPISession s, /* i: login session handle */ + CAPIHandle* pH, /* i: list of CAPIHandles for Fetch */ + int iHandleCount, /* i: number of valid handles in ppH */ + long lFlags, /* i: bit flags (none at this time; set to 0) */ + char* dStart, /* i: range start time, ex: "19980704T080000Z" */ + char* dEnd, /* i: range end time, ex: "19980704T180000Z" */ + char** ppsPropList, /* i: list of properties to return in events */ + int iPropCount, /* i: number of properties in *ppsPropList */ + CAPIStream stream); /* i: stream to which solution set will be written */ + +NS_CALENDAR CAPIStatus CAPI_FetchEventsByID( + CAPISession s, /* i: login session handle */ + CAPIHandle h, /* i: calendar from which to fetch events */ + long lFlags, /* i: bit flags (none at this time; set to 0) */ + char* psUID, /* i: UID of the event to fetch */ + char* dtRecurrenceID, /* i: recurrence-id, NULL means ignore */ + int iModifier, /* i: one of CAPI_THISINSTANCE, */ + /* CAPI_THISANDPRIOR, CAPI_THISANDFUTURE */ + /* only valid if recurrence-id is non-NULL */ + char** ppsPropList, /* i: list of properties returned in events */ + int iPropCount, /* i: number of properties in the list */ + CAPIStream stream); /* i: stream to which solution set will be written */ + +NS_CALENDAR CAPIStatus CAPI_FetchEventsByRange( + CAPISession s, /* i: login session handle */ + CAPIHandle* pH, /* i: list of CAPIHandles for fetch */ + int iHandleCount, /* i: number of valid handles in ppH */ + long lFlags, /* i: bit flags (none at this time; set to 0) */ + char* dStart, /* i: range start time */ + char* dEnd, /* i: range end time */ + char** ppsPropList, /* i: list of properties returned in events */ + int iPropCount, /* i: number of properties in the list */ + CAPIStream stream); /* i: stream to which solution set will be written */ + +NS_CALENDAR CAPIStatus CAPI_GetHandle( + CAPISession s, /* i: login session handle */ + char* u, /* i: user as defined in Login */ + long lFlags, /* i: bit flags (none at this time; set to 0) */ + CAPIHandle* pH); /* o: handle */ + +NS_CALENDAR CAPIStatus CAPI_Logoff( + CAPISession* s, /* io: session from login */ + long lFlags); /* i: bit flags (none at this time; set to 0) */ + +NS_CALENDAR CAPIStatus CAPI_Logon( + const char* psUser, /* i: Calendar store (and ":extra" information ) */ + const char* psPassword, /* i: password for sUser */ + const char* psHost, /* i: calendar server host (and :port) */ + long lFlags, /* i: bit flags (none at this time; set to 0) */ + CAPISession* pSession); /* o: the session */ + +NS_CALENDAR CAPIStatus CAPI_SetStreamCallbacks ( + CAPISession s, /* i: login session handle */ + CAPIStream* pStream, /* io: The stream to modify */ + CAPICallback pfnSndCallback,/* i: Snd iCalendar data */ + void* userDataSnd, /* i: a user supplied value */ + CAPICallback pfnRcvCallback,/* i: Rcv iCalendar data */ + void* userDataRcv, /* i: a user supplied value */ + long lFlags ); /* i: bit flags (none at this time; set to 0) */ + +NS_CALENDAR CAPIStatus CAPI_StoreEvent( + CAPISession s, /* i: login session handle */ + CAPIHandle* pH, /* i: list of CAPIHandles for store */ + int iHandleCount, /* i: number of valid handles in pH */ + long lFlags, /* i: bit flags (none at this time; set to 0) */ + CAPIStream stream ); /* i: stream for reading data to store */ + + +/* + * NETSCAPE EXTENSIONS TO CAPI + */ +NS_CALENDAR CAPIStatus CAPI_LogonCurl( + const char* psCurl, /* i: Calendar store (and ":extra" information ) */ + const char* psPassword, /* i: password for sUser */ + long lFlags, /* i: bit flags (none at this time; set to 0) */ + CAPISession* pSession); /* o: the session */ + + +#ifdef __cplusplus +} +#endif + +/* The ok error */ +#define CAPI_ERR_OK ((CAPIStatus) 0x00) + +/* Masks for checking for fields of error codes */ +#define CAPI_ERRMASK_MODE_FIELD ((CAPIStatus) 0xFF << 24) +#define CAPI_ERRMASK_TYPE_FIELD ((CAPIStatus) 0x1F << 19) +#define CAPI_ERRMASK_ERR1_FIELD ((CAPIStatus) 0x1F << 14) +#define CAPI_ERRMASK_ERR2_FIELD ((CAPIStatus) 0x3F << 8) +#define CAPI_ERRMASK_VENDOR_FIELD ((CAPIStatus) 0xFF) + +/* Masks for checking for errors at various levels */ + +#define CAPI_ERRMASK_TYPE ((CAPIStatus) CAPI_ERRMASK_TYPE_FIELD) +#define CAPI_ERRMASK_ERR1 ((CAPIStatus) CAPI_ERRMASK_TYPE + CAPI_ERRMASK_ERR1_FIELD) +#define CAPI_ERRMASK_ERR2 ((CAPIStatus) CAPI_ERRMASK_ERR1 + CAPI_ERRMASK_ERR2_FIELD) +#define CAPI_ERRMASK_VENDOR ((CAPIStatus) CAPI_ERRMASK_ERR2 + CAPI_ERRMASK_VENDOR_FIELD) + +/* The non fatal error bit */ + +#define CAPI_ERRMODE_FATAL ((CAPIStatus) 0x1 << 24)) + +/* The various error types (field 2) */ +#define CAPI_ERRTYPE_DATA ((CAPIStatus) 0x1 << 19) +#define CAPI_ERRTYPE_SERVICE ((CAPIStatus) 0x2 << 19) +#define CAPI_ERRTYPE_API ((CAPIStatus) 0x3 << 19) +#define CAPI_ERRTYPE_SECURITY ((CAPIStatus) 0x4 << 19) +#define CAPI_ERRTYPE_LIBRARY ((CAPIStatus) 0x5 << 19) + +/* Data errors */ + +/* field 3 values */ +#define CAPI_ERR1_ICAL ((CAPIStatus) CAPI_ERRTYPE_DATA + (0x1 << 14 )) +#define CAPI_ERR1_MIME ((CAPIStatus) CAPI_ERRTYPE_DATA + (0x2 << 14 )) +#define CAPI_ERR1_DATE ((CAPIStatus) CAPI_ERRTYPE_DATA + (0x3 << 14 )) +#define CAPI_ERR1_ID ((CAPIStatus) CAPI_ERRTYPE_DATA + (0x4 << 14 )) + +/* field 4 values */ +#define CAPI_ERR2_MIME_NONE ((CAPIStatus) CAPI_ERR1_MIME + (0x1 << 8)) +#define CAPI_ERR2_MIME_NOICAL ((CAPIStatus) CAPI_ERR1_MIME + (0x2 << 8)) + +#define CAPI_ERR2_DATE_RANGE ((CAPIStatus) CAPI_ERR1_DATE + (0x1 << 8)) +#define CAPI_ERR2_DATE_FORMAT ((CAPIStatus) CAPI_ERR1_DATE + (0x2 << 8)) + +#define CAPI_ERR2_ID_USERID ((CAPIStatus) CAPI_ERR1_ID + (0x1 << 8)) +#define CAPI_ERR2_ID_HOSTNAME ((CAPIStatus) CAPI_ERR1_ID + (0x2 << 8)) + +/* field 5 values (Vendor specific errors) */ + +#define CAPI_ERR_IDUSERID_INIFILE ((CAPIStatus) CAPI_ERR2_ID_USERID + 0x01) +#define CAPI_ERR_IDUSERID_FORMAT ((CAPIStatus) CAPI_ERR2_ID_USERID + 0x02) +#define CAPI_ERR_IDUSERID_NONE ((CAPIStatus) CAPI_ERR2_ID_USERID + 0x03) +#define CAPI_ERR_IDUSERID_MANY ((CAPIStatus) CAPI_ERR2_ID_USERID + 0x04) +#define CAPI_ERR_IDUSERID_NODE ((CAPIStatus) CAPI_ERR2_ID_USERID + 0x05) + +/* + * Service errors + */ + +/* field 3 values */ +#define CAPI_ERR1_MEMORY ((CAPIStatus) CAPI_ERRTYPE_SERVICE + (0x1 << 14 )) +#define CAPI_ERR1_FILE ((CAPIStatus) CAPI_ERRTYPE_SERVICE + (0x2 << 14 )) +#define CAPI_ERR1_NETWORK ((CAPIStatus) CAPI_ERRTYPE_SERVICE + (0x3 << 14 )) + +/* field 4 values */ +#define CAPI_ERR2_NETWORK_TIMEOUT ((CAPIStatus) CAPI_ERR1_NETWORK + (0x1 << 8)) + + +/* + * API errors + */ + +/* field 3 values */ +#define CAPI_ERR1_FLAGS ((CAPIStatus) CAPI_ERRTYPE_API + (0x1 << 14)) +#define CAPI_ERR1_NULLPARAM ((CAPIStatus) CAPI_ERRTYPE_API + (0x2 << 14)) +#define CAPI_ERR1_CALLBACK ((CAPIStatus) CAPI_ERRTYPE_API + (0x3 << 14)) +#define CAPI_ERR1_HANDLE ((CAPIStatus) CAPI_ERRTYPE_API + (0x4 << 14)) +#define CAPI_ERR1_SESSION ((CAPIStatus) CAPI_ERRTYPE_API + (0x5 << 14)) +#define CAPI_ERR1_STREAM ((CAPIStatus) CAPI_ERRTYPE_API + (0x6 << 14)) + +/* field 4 values */ +#define CAPI_ERR2_HANDLE_NULL ((CAPIStatus) CAPI_ERR1_HANDLE + (0x1 << 8)) +#define CAPI_ERR2_HANDLE_BAD ((CAPIStatus) CAPI_ERR1_HANDLE + (0x2 << 8)) + +#define CAPI_ERR2_SESSION_NULL ((CAPIStatus) CAPI_ERR1_SESSION + (0x1 << 8)) +#define CAPI_ERR2_SESSION_BAD ((CAPIStatus) CAPI_ERR1_SESSION + (0x2 << 8)) + +#define CAPI_ERR2_STREAM_NULL ((CAPIStatus) CAPI_ERR1_STREAM + (0x1 << 8)) +#define CAPI_ERR2_STREAM_BAD ((CAPIStatus) CAPI_ERR1_STREAM + (0x2 << 8)) + +/* + * Security errors + */ + +/* field 3 values */ +#define CAPI_ERR1_READ ((CAPIStatus) CAPI_ERRTYPE_SECURITY + (0x1 << 14)) +#define CAPI_ERR1_WRITE ((CAPIStatus) CAPI_ERRTYPE_SECURITY + (0x2 << 14)) + +/* field 4 values */ +#define CAPI_ERR2_READ_PROPS ((CAPIStatus) CAPI_ERR1_READ + (0x1 << 8)) + +#define CAPI_ERR2_WRITE_AGENDA ((CAPIStatus) CAPI_ERR1_WRITE + (0x1 << 8)) +#define CAPI_ERR2_WRITE_EVENT ((CAPIStatus) CAPI_ERR1_WRITE + (0x2 << 8)) + + +/* + * Library errors + */ +/* field 3 values */ +#define CAPI_ERR1_INTERNAL ((CAPIStatus) CAPI_ERRTYPE_LIBRARY + (0x1 << 14)) +#define CAPI_ERR1_IMPLENTATION ((CAPIStatus) CAPI_ERRTYPE_LIBRARY + (0x2 << 14)) + +/* field 4 values */ +#define CAPI_ERR2_INTERNALEXPIRY ((CAPIStatus) CAPI_ERR_INTERNAL + (0x1 << 8)) + +#endif /* __JULIAN_LOCAL_CAPI_H */ diff --git a/calendar/modules/core/capi/local/inc/manifest.mn b/calendar/modules/core/capi/local/inc/manifest.mn new file mode 100644 index 00000000000..e69de29bb2d diff --git a/calendar/modules/core/capi/local/inc/privcapi.h b/calendar/modules/core/capi/local/inc/privcapi.h new file mode 100644 index 00000000000..6ece76e03a9 --- /dev/null +++ b/calendar/modules/core/capi/local/inc/privcapi.h @@ -0,0 +1,60 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 +-*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +/** +*** Private CAPI header file. +*** Defines the opaque types. +**/ +#ifndef __JULIAN_PRIVATE_CAPI_H +#define __JULIAN_PRIVATE_CAPI_H + +#include "nsString.h" +#include "xp_mcom.h" +#include "jdefines.h" +#include "julnstr.h" +#include "nspr.h" +#include "plstr.h" +#include "nsCurlParser.h" + +typedef struct +{ + nsCurlParser* pCurl; + char* psUser; /* i: Calendar store (and ":extra" information ) */ + char* psPassword; /* i: password for sUser */ + char* psHost; /* i: calendar server host (and :port) */ +} PCAPISESSION; + +typedef struct +{ + PCAPISESSION *pSession; + char* psFile; + nsCurlParser* pCurl; +} PCAPIHANDLE; + +typedef struct +{ + CAPICallback pfnSndCallback; /* i: Snd iCalendar data */ + void* pCallerSndDataBuf; /* i: Data buffer pointer Snd function */ + void* userDataRcv; /* i: a user supplied value */ + CAPICallback pfnRcvCallback; /* i: Rcv iCalendar data */ + void* userDataSnd; /* i: a user supplied value */ + long lFlags; /* i: bit flags (none at this time; set to 0) */ +} PCAPIStream; + +#endif /* __JULIAN_PRIVATE_CAPI_H */ \ No newline at end of file diff --git a/calendar/modules/core/capi/local/manifest.mn b/calendar/modules/core/capi/local/manifest.mn new file mode 100644 index 00000000000..e69de29bb2d diff --git a/calendar/modules/core/capi/local/src/Makefile b/calendar/modules/core/capi/local/src/Makefile new file mode 100644 index 00000000000..e69de29bb2d diff --git a/calendar/modules/core/capi/local/src/capi.cpp b/calendar/modules/core/capi/local/src/capi.cpp new file mode 100644 index 00000000000..38934b87520 --- /dev/null +++ b/calendar/modules/core/capi/local/src/capi.cpp @@ -0,0 +1,1400 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 +-*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +/**************************************************************** +*** Local CAPI +*** Steve Mansour +*****************************************************************/ +#include "jdefines.h" +#include +#include +#include +#include + +#include "capi.h" /* public capi file */ +#include "privcapi.h" /* private capi implementation */ + + +/* julian includes */ +#include "nscal.h" +#include "icalcomp.h" +#include "icalredr.h" +#include "icalfrdr.h" +#include "ptrarray.h" +#include "jlog.h" + +#ifdef XP_PC +#include "io.h" +#endif + +/**************************************************************** +*** UTILITY ROUTINES +*** In case we want to actually put this code into a dll, +*** this section should contain all the external calls. +*****************************************************************/ +size_t CAPI_strlen(const char * s) +{ + return strlen(s); +} + +char *CAPI_mktemp( char *psTemplate ) +{ +// XXX: Port this +#ifdef XP_PC + return _mktemp(psTemplate); +#endif +} + +int CAPI_access( const char *path, int mode ) +{ + return JXP_ACCESS(path,mode); +} + +void *CAPI_malloc(size_t i) +{ + return malloc( i ); +} + +void CAPI_free(void *p) +{ + if (0 != p) + free(p); +} + +int CAPI_unlink( const char *filename ) +{ +// XXX: Port this +#ifdef XP_PC + int iStatus = _unlink(filename); + if (iStatus < 0) + { + int iError = errno; + //TRACE( _sys_errlist[errno] ); + return iError; + } +#endif + return 0; +} + +char *CAPI_strdup(const char* s) +{ + if (0 != s) + { + char* p = (char *) malloc( 1 + strlen(s) ); + if (0 == p) + return 0; + return strcpy(p,s); + } + return 0; +} + +FILE *CAPI_fopen(const char *psFile, const char *psFlags) +{ + return fopen(psFile,psFlags); +} + +size_t CAPI_fread( void *buffer, size_t size, size_t count, FILE *stream ) +{ + return fread( buffer, size, count, stream ); +} + +size_t CAPI_fwrite( const void *buffer, size_t size, size_t count, FILE *stream ) +{ + return fwrite( buffer, size, count, stream ); +} + +int CAPI_fclose(FILE *pFile ) +{ + return fclose(pFile); +} + +void *CAPI_memcpy( void *dest, const void *src, size_t count ) +{ + return memcpy(dest,src,count); +} + +void *CAPI_memset( void *dest, int c, size_t count ) +{ + return memset(dest,c,count); +} + +/************************************************************************/ + +/** + * This is a useful piece of code but it's in the wrong + * place. Given a path, it ensures that the path exists, creating + * whatever needs to be created. + * @return 0 on success + * file creation errors otherwise. + */ +PRInt32 CAPI_EnsureUserPath( JulianString& sPath ) +{ + JulianString sTmp; + PRInt32 i; + nsCurlParser::ConvertToFileChars(sPath); + for (i = 0; -1 != (i = sPath.Strpbrk(i,"/\\")); i++ ) + { + sTmp = sPath.Left(i); + if (PR_SUCCESS != PR_Access(sTmp.GetBuffer(), PR_ACCESS_EXISTS)) + { + /* + * Try to create it... + */ + if (PR_SUCCESS != PR_MkDir(sTmp.GetBuffer(),PR_RDWR)) + { + PRInt32 iError = PR_GetError(); + return iError; + } + } + } + + /* + * OK, the path was there or it has been created. Now make + * sure we can write to it. + */ + if (PR_SUCCESS != PR_Access(sPath.GetBuffer(), PR_ACCESS_WRITE_OK)) + { + PRInt32 iError = PR_GetError(); + return iError; + } + + return 0; +} + + + +/**************************************************************** +*** MIME / ICAL ASSEMBLY FUNCTIONS +*****************************************************************/ +UnicodeString & createMimeStartHeader(UnicodeString & u) +{ + u = "MIME-Version: 1.0\r\n"; + u += "Content-Type: multipart/text\r\n"; + u += " boundary=\"5ZY4HSUIYKHTPFPN7Q30ROE94YXWQNBI\"\r\n"; + u += "Content-Transfer-Encoding: 7bit\r\n"; + u += "\r\n"; + u += "This is a multipart message in MIME format containing iCalendar data.\r\n"; + return u; +} + +UnicodeString & appendSeperator(UnicodeString & u) +{ + u += "--5ZY4HSUIYKHTPFPN7Q30ROE94YXWQNBI\r\n"; + return u; +} + +UnicodeString & appendMultipartMessageHeader(UnicodeString & u, UnicodeString & filename) +{ + appendSeperator(u); + u += "Content-Type: text/calendar\r\n"; + u += "Content-Disposition: attachment; filename=\""; + u += filename; + u += "\"\r\n"; + u += "Content-Transfer-Encoding: 7-bit\r\n\r\n"; + return u; +} + +UnicodeString & appendBeginVCalendar(UnicodeString & u) +{ + u += "BEGIN:VCALENDAR\r\n"; + return u; +} + +UnicodeString & appendEndVCalendar(UnicodeString & u) +{ + u += "END:VCALENDAR\r\n\r\n"; + return u; +} + + +/**************************************************************** +*** CAPI FUNCTIONS +*****************************************************************/ + +/** + * return the implementation specific information + */ +CAPIStatus CAPI_Capabilities( + const char** ppsVal, /* o: a string describing the capabilities */ + const char* psHost, /* i: server host */ + long lFlags ) /* i: bit flags (none at this time; set to 0) */ +{ + static char* tpsCap = "Vendor: Netscape\n\ +Version: 1.0\n\ +ServerVersion: 1.0 (localhost)\n\ +CAPIVersion: 1.0\n\ +fanout: no\n\ +atomicTransactions: no\n"; + + *ppsVal = tpsCap; + + return CAPI_ERR_OK; +} + +/** + * Delete an event from a list of calendar handles + */ +#define DEL_EXIT(x) {iRetStatus = x; goto DELEVENT_EXIT;} + +CAPIStatus CAPI_DeleteEvent( + CAPISession s, /* i: login session handle */ + CAPIHandle* pHList, /* i: list of CAPIHandles for delete */ + int iHandleCount, /* i: number of valid handles in ppH */ + long lFlags, /* i: bit flags (none at this time; set to 0) */ + char* psUID, /* i: UID of the event to delete */ + char* dtRecurrenceID, /* i: recurrence-id, NULL means ignore */ + int iModifier) /* i: one of CAPI_THISINSTANCE, CAPI_THISANDPRIOR, + CAPI_THISANDFUTURE only valid if recurrence-id + is non-NULL */ +{ + + /* + * Read the entire calendar into an NSCalendar : pCal + * Read the supplied event to delete into another ns calendar : pCalDel + * Search for the event in pCalDel in pCal. + * If found delete it from pCal then save pCal + */ + PCAPISESSION *pSession = (PCAPISESSION*)s; + PCAPIHANDLE* pHandle; + NSCalendar *pCal = 0; + CAPIStatus iRetStatus = CAPI_ERR_OK; + ICalReader * pRedr = 0; + JLog* pLog = 0; + UnicodeString uFilename; + t_bool bWriteStatus; + size_t iHits; + ErrorCode status = ZERO_ERROR; + VEvent *pEvent; + JulianPtrArray* pEventList = 0; + + if (0 == pSession) + return CAPI_ERR2_SESSION_BAD; + if (0 == pHList) + return CAPI_ERR2_HANDLE_BAD; + + for (int i = 0; i < iHandleCount; i++) + { + pHandle = (PCAPIHANDLE*) pHList[i]; + if (0 == pHandle) + DEL_EXIT(CAPI_ERR2_HANDLE_BAD) + + /* + * create an NSCalendar, pCal + */ + pCal = new NSCalendar(pLog); + if (pCal == 0) + DEL_EXIT(CAPI_ERR1_INTERNAL) + + /* + * Try to load pHandle->psFile in pCal. + * If the file doesn't exist, we don't have to create it and + * load it, because we're deleting events anyway. If there's nothing + * there to start with, there's nothing to delete. + */ + if (CAPI_access(pHandle->psFile, 00 /*F_OK*/)) + continue; + pRedr = (ICalReader *) new ICalFileReader(pHandle->psFile, status); + if (pRedr == 0) + DEL_EXIT(CAPI_ERR1_INTERNAL) + if (FAILURE(status)) + DEL_EXIT(CAPI_ERR1_INTERNAL) + + /* + * Load original datastore... + */ + uFilename = pHandle->psFile; + pCal->parse(pRedr, uFilename); + delete pRedr; pRedr = 0; + + /* + * Try to find the event + */ + pEventList = pCal->getEvents(); + if (0 != pEventList) + { + pEvent = 0; + iHits = 0; + for (int j = 0; j < pEventList->GetSize(); j++) + { + pEvent = (VEvent *) pEventList->GetAt(j); + if (0 == pEvent) + continue; + if (0 == (pEvent->getUID().compare(psUID))) + { + /* + * need to check recurrence id here... + */ + iHits++; + pEventList->RemoveAt(j); + delete pEvent; + pEvent = 0; + --j; + } + } + } + + + /* + * Write the updated calendar store out to disk... + */ + if (iHits > 0) + { + pCal->export(pHandle->psFile, bWriteStatus); + if (!bWriteStatus) + DEL_EXIT(CAPI_ERR1_INTERNAL); + } + + delete pCal; + pCal = 0; + + } + + +DELEVENT_EXIT: + if (0 != pCal) + delete pCal; + if (0 != pRedr) + delete pRedr; + + return iRetStatus; +} + +/** + * Destroy a list of handles. + */ +CAPIStatus CAPI_DestroyHandles( + CAPISession s, /* i: login session handle */ + CAPIHandle* pHList, /* i: array of handles to destroy */ + int iHandleCount, /* i: number of valid handles in ppH */ + long lFlags) /* i: bit flags (none at this time; set to 0) */ +{ + PCAPIHANDLE* pHandle; + int i; + for (i = 0; i < iHandleCount; i++ ) + { + pHandle = (PCAPIHANDLE *)pHList[i]; + if (pHandle != 0) + { + if (pHandle->pCurl) + delete pHandle->pCurl; + CAPI_free(pHandle->psFile); + CAPI_free(pHandle); + } + } + return CAPI_ERR_OK; +} + +/** + * Destroy a list of streams + */ +CAPIStatus CAPI_DestroyStreams( + CAPISession s, /* i: login session handle */ + CAPIStream* pS, /* i: array of streams to destroy */ + int iCount, /* i: number of valid handles in ppH */ + long lFlags) /* i: bit flags (none at this time; set to 0) */ +{ + PCAPIStream** paS = (PCAPIStream **) pS; + for (int i = 0; i < iCount; i++) + delete paS[i]; + return CAPI_ERR_OK; +} + +/** + * return events that have alarms set to go off in the supplied time range. + */ +CAPIStatus CAPI_FetchEventsByAlarmRange( + CAPISession s, /* i: login session handle */ + CAPIHandle* pH, /* i: list of CAPIHandles for Fetch */ + int iHandleCount, /* i: number of valid handles in ppH */ + long lFlags, /* i: bit flags (none at this time; set to 0) */ + char* dStart, /* i: range start time, ex: "19980704T080000Z" */ + char* dEnd, /* i: range end time, ex: "19980704T180000Z" */ + char** ppsPropList, /* i: list of properties to return in events */ + int iPropCount, /* i: number of properties in *ppsPropList */ + CAPIStream stream) /* i: stream to which solution set will be written */ +{ + return CAPI_ERR1_IMPLENTATION; +} + +#define FBID_EXIT(x) {iRetStatus = x; goto FBID_EXIT;} +#define FBRANGE_EXIT(x) {iRetStatus = x; goto FBRANGE_EXIT;} +/** + * Fetch an event from the local data store that matches the supplied UID, + * recurrence id, and modifier. + */ +CAPIStatus CAPI_FetchEventsByID( + CAPISession s, /* i: login session handle */ + CAPIHandle h, /* i: calendar from which to fetch events */ + long lFlags, /* i: bit flags (none at this time; set to 0) */ + char* psUID, /* i: UID of the event to fetch */ + char* dtRecurrenceID, /* i: recurrence-id, NULL means ignore */ + int iModifier, /* i: one of CAPI_THISINSTANCE, */ + /* CAPI_THISANDPRIOR, CAPI_THISANDFUTURE */ + /* only valid if recurrence-id is non-NULL */ + char** ppsPropList, /* i: list of properties returned in events */ + int iPropCount, /* i: number of properties in the list */ + CAPIStream str) /* i: stream to which solution set will be written */ +{ + PCAPISESSION *pSession = (PCAPISESSION*)s; + PCAPIHANDLE* pHandle = (PCAPIHANDLE*)h; + PCAPIStream* pStream = (PCAPIStream*)str; + + size_t iLen; + size_t iAmountHandled; + char *p; + CAPIStatus iStatus; + CAPIStatus iRetStatus = CAPI_ERR_OK; + char *pBuf = 0; + size_t iBufSize = BUFSIZ; + NSCalendar * pCal = 0; + ICalReader * pRedr = 0; + JulianPtrArray * evtVctr = 0; + ICalComponent * ic = 0; + JLog * pLog = 0; + UnicodeString usEvt; + UnicodeString u; + UnicodeString uRid; + UnicodeString uModifier; + UnicodeString strFmt; + ErrorCode status = ZERO_ERROR; + int32 i = 0; + UnicodeString uFilename = "calendar.ics"; + char * pCopy = 0; + + if (0 == pSession) + return CAPI_ERR2_SESSION_BAD; + if (0 == pHandle) + return CAPI_ERR2_HANDLE_BAD; + if (0 == pStream) + return CAPI_ERR2_STREAM_BAD; + + /* + * For this trivial implementation, we're going to read + * everything in the file and send it to the handler... + */ + if (0 != pStream->pfnRcvCallback) + { + /* + * We need an NSCalendar to do in-memory manipulations. + */ + pCal = new NSCalendar(pLog); + if (pCal == 0) + return CAPI_ERR1_INTERNAL; + evtVctr = new JulianPtrArray(); + if (evtVctr == 0) + FBID_EXIT(CAPI_ERR1_INTERNAL); + + /* + * Try to load pHandle->psFile in pCal + * if file error, return CAPI_ERR1_INTERNAL + */ + + if (CAPI_access(pHandle->psFile, 00 /*F_OK*/)) + { + FILE *pFile = 0; + if ( 0 == (pFile =CAPI_fopen(pHandle->psFile,"w"))) + FBID_EXIT(CAPI_ERR1_INTERNAL); + + if (0 != CAPI_fclose(pFile)) + FBID_EXIT(CAPI_ERR1_INTERNAL); + } + pRedr = (ICalReader *) new ICalFileReader(pHandle->psFile, status); + if (pRedr == 0) + FBID_EXIT(CAPI_ERR1_INTERNAL); + if (FAILURE(status)) + FBID_EXIT(CAPI_ERR1_INTERNAL); + + /* parse reader */ + uFilename = pHandle->psFile; + pCal->parse(pRedr, uFilename); + + /* + * Apply the filter: + * JulianPtrArray EventVector + * pCal->GetEventsByID(&EventVector, psUID,dtRecurrenceID,iModifier ); + */ + /* TODO: use getEvents(uid, rid, range) */ + + u = psUID; + uRid = dtRecurrenceID; + uModifier = ""; + if (iModifier == CAPI_THISANDPRIOR) + uModifier = "THISANDPRIOR"; + else if (iModifier == CAPI_THISANDFUTURE) + uModifier = "THISANDFUTURE"; + + //pCal->getEvents(evtVctr, u); + pCal->getEventsByComponentID(evtVctr, u, uRid, uModifier); + + /* + * Stream out initialization ICAL: + * MIME header: + * Multipart-mime header: + * BEGIN:VCALENDAR + * separator + * END:VCALENDAR + */ + u = createMimeStartHeader(u); + appendMultipartMessageHeader(u, uFilename); + appendBeginVCalendar(u); + + if (0 == evtVctr->GetSize()) + { + appendEndVCalendar(u); + appendSeperator(u); + pCopy = u.toCString(""); + + if (pCopy != 0) + { + for(p = pCopy, iLen = CAPI_strlen(pCopy);iLen > 0; p += iAmountHandled) + { + iStatus = (*pStream->pfnRcvCallback)(pStream->userDataRcv,p,iLen,&iAmountHandled); + if (CAPI_CALLBACK_CONTINUE != iStatus) + FBID_EXIT(CAPI_ERR1_CALLBACK); + iLen -= iAmountHandled; + } + delete [] pCopy; pCopy = 0; + } + else + { + FBID_EXIT(CAPI_ERR1_CALLBACK); + } + } + + /* + * For each event in EventVector... + * 0. TODO LATER: filter the event string by the supplied property list + * 1. Put an ICAL version of the event into sEvent + * + */ + ICalComponent::makeFormatString(ppsPropList, iPropCount, strFmt); + for (i = 0; i < evtVctr->GetSize(); i++) + { + ic = (ICalComponent *) evtVctr->GetAt(i); + + usEvt = ic->format(ICalComponent::componentToString(ic->GetType()), + strFmt, "", FALSE); + + // prepend MIME header to first event + // append END to last event + if (i == 0) + { + usEvt.insert(0, u); + } + if (i == evtVctr->GetSize() - 1) + { + appendEndVCalendar(usEvt); + appendSeperator(usEvt); + } + pCopy = usEvt.toCString(""); + if (pCopy == 0) + FBID_EXIT(CAPI_ERR1_MEMORY); + + for(p = pCopy, iLen = CAPI_strlen(pCopy);iLen > 0; p += iAmountHandled) + { + iStatus = (*pStream->pfnRcvCallback)(pStream->userDataRcv,p,iLen,&iAmountHandled); + if (CAPI_CALLBACK_CONTINUE != iStatus) + FBID_EXIT(CAPI_ERR1_CALLBACK); + iLen -= iAmountHandled; + } + delete [] pCopy; pCopy = 0; + } + + /* + * Signal the end of transmission... + */ + (*pStream->pfnRcvCallback)(pStream->userDataRcv,p,0,&iAmountHandled); + + +FBID_EXIT: + if (0 != pCal) + delete pCal; + if (0 != evtVctr) + delete evtVctr; + if (0 != pRedr) + delete pRedr; + if (0 != pCopy) + delete [] pCopy; + + } + return iRetStatus; +} + +/** + * Get a list of all the events that overlap a time range. + */ +CAPIStatus CAPI_FetchEventsByRange( + CAPISession s, /* i: login session handle */ + CAPIHandle* pH, /* i: list of CAPIHandles for fetch */ + int iHandleCount, /* i: number of valid handles in ppH */ + long lFlags, /* i: bit flags (none at this time; set to 0) */ + char* dStart, /* i: range start time */ + char* dEnd, /* i: range end time */ + char** ppsPropList, /* i: list of properties returned in events */ + int iPropCount, /* i: number of properties in the list */ + CAPIStream str) /* i: stream to which solution set will be written */ +{ + PCAPISESSION *pSession = (PCAPISESSION*)s; + PCAPIHANDLE* pHandle = (PCAPIHANDLE*)pH; + PCAPIStream* pStream = (PCAPIStream*)str; + + size_t iLen; + size_t iAmountHandled; + char *p; + int i; + CAPIStatus iStatus; + CAPIStatus iRetStatus = CAPI_ERR_OK; + char *pBuf = 0; + size_t iBufSize = BUFSIZ; + + /* julian variables */ + NSCalendar * pCal = 0; + ICalReader * pRedr = 0; + JulianPtrArray * evtVctr = 0; + ICalComponent * ic = 0; + JLog * pLog = 0; + UnicodeString usEvt; + UnicodeString usHeader; + UnicodeString strFmt; + ErrorCode status = ZERO_ERROR; + char * pCopy = 0; + int32 j = 0; + DateTime start; + DateTime end; + UnicodeString uFilename; + UnicodeString uTemp; + + if (0 == pSession) + return CAPI_ERR2_SESSION_BAD; + if (0 == pH) + return CAPI_ERR2_HANDLE_BAD; + if (0 == pStream) + return CAPI_ERR2_STREAM_BAD; + + /* + * For this trivial implementation, we're going to read + * everything in the file and send it to the handler... + */ + if (0 != pStream->pfnRcvCallback) + { + /* + * For each handle, fetch events by range, print out event + * print mime-header if first handle. + * print mime-multipart stuff if first event. + */ + for (i = 0; i < iHandleCount; i++) + { + /*pCal = 0; + evtVctr = 0; + pRedr = 0; + pCopy = 0;*/ + pHandle = (PCAPIHANDLE *) pH[i]; + if (pHandle == 0) + { + return CAPI_ERR2_HANDLE_BAD; + } + + pCal = new NSCalendar(pLog); + if (pCal == 0) + FBRANGE_EXIT(CAPI_ERR1_INTERNAL); + + evtVctr = new JulianPtrArray(); + if (evtVctr == 0) + FBRANGE_EXIT(CAPI_ERR1_INTERNAL); + + /* + * Try to load pHandle->psFile in pCal + * if file error, return CAPI_ERR1_INTERNAL + */ + + if (CAPI_access(pHandle->psFile, 00 /*F_OK*/)) + { + FILE * pFile = 0; + if ( 0 == (pFile =CAPI_fopen(pHandle->psFile,"w"))) + FBRANGE_EXIT(CAPI_ERR1_INTERNAL); + if (0 != CAPI_fclose(pFile)) + FBRANGE_EXIT(CAPI_ERR1_INTERNAL); + } + + pRedr = (ICalReader *) new ICalFileReader(pHandle->psFile, status); + if (pRedr == 0) + FBRANGE_EXIT(CAPI_ERR1_INTERNAL); + if (FAILURE(status)) + FBRANGE_EXIT(CAPI_ERR1_INTERNAL); + + /* parse reader */ + uFilename = pHandle->psFile; + pCal->parse(pRedr, uFilename); + + /* apply filter */ + uTemp = dStart; + start.setTimeString(uTemp); + uTemp = dEnd; + end.setTimeString(uTemp); + pCal->getEventsByRange(evtVctr, start, end); + + /* + * Stream out initialization ICAL: + * Mime headers, Multipart headers, seperator, BEGIN:VCALENDAR, END:VCALENDAR + */ + + /** + * create mime start header if this is the first handle of the list + */ + if (i == 0) + { + usHeader = createMimeStartHeader(usHeader); + } + else + { + usHeader = ""; + } + /** + * append mime-multipart header and BEGIN:VCALENDAR + */ + appendMultipartMessageHeader(usHeader, uFilename); + appendBeginVCalendar(usHeader); + + if (0 == evtVctr->GetSize()) + { + appendEndVCalendar(usHeader); + if (i == iHandleCount - 1) + { + appendSeperator(usHeader); + } + pCopy = usHeader.toCString(""); + + if (pCopy != 0) + { + for(p = pCopy, iLen = CAPI_strlen(pCopy);iLen > 0; p += iAmountHandled) + { + iStatus = (*pStream->pfnRcvCallback)(pStream->userDataRcv,p,iLen,&iAmountHandled); + if (CAPI_CALLBACK_CONTINUE != iStatus) + FBRANGE_EXIT(CAPI_ERR1_CALLBACK); + iLen -= iAmountHandled; + } + delete [] pCopy; pCopy = 0; + } + else + { + FBRANGE_EXIT(CAPI_ERR1_CALLBACK); + } + } + else + { + ICalComponent::makeFormatString(ppsPropList, iPropCount, strFmt); + for (j = 0; j < evtVctr->GetSize(); j++) + { + ic = (ICalComponent *) evtVctr->GetAt(j); + + usEvt = ic->format(ICalComponent::componentToString(ic->GetType()), + strFmt, "", FALSE); + + // prepend mime-header to first handle, first event + // prepend multipart-header to first event, non-first handle + if (j == 0) + { + if (i == 0) + { + usEvt.insert(0, usHeader); + } + else + { + uTemp = ""; + appendMultipartMessageHeader(uTemp, uFilename); + usEvt.insert(0, uTemp); + } + } + // append END:VCALENDAR to last event. + if (j == evtVctr->GetSize() - 1) + { + appendEndVCalendar(usEvt); + if (i == iHandleCount - 1) + { + appendSeperator(usEvt); + } + } + + pCopy = usEvt.toCString(""); + if (pCopy == 0) + FBRANGE_EXIT(CAPI_ERR1_MEMORY); + + for(p = pCopy, iLen = CAPI_strlen(pCopy);iLen > 0; p += iAmountHandled) + { + iStatus = (*pStream->pfnRcvCallback)(pStream->userDataRcv,p,iLen,&iAmountHandled); + if (CAPI_CALLBACK_CONTINUE != iStatus) + FBRANGE_EXIT(CAPI_ERR1_CALLBACK); + iLen -= iAmountHandled; + } + delete [] pCopy; pCopy = 0; + } + } + + /* + * we're paranoid about a path that doesn't delete something + */ + if (0 != pCal) + { + delete pCal; + pCal = 0; + } + if (0 != evtVctr) + { + delete evtVctr; + evtVctr = 0; + } + if (0 != pRedr) + { + delete pRedr; + pRedr = 0; + } + if (0 != pCopy) + { + delete pCopy; + pCopy = 0; + } + } + + /* + * Signal the end of transmission... + */ + (*pStream->pfnRcvCallback)(pStream->userDataRcv,p,0,&iAmountHandled); + + } + +FBRANGE_EXIT: + if (0 != pCal) + delete pCal; + if (0 != evtVctr) + delete evtVctr; + if (0 != pRedr) + delete pRedr; + if (0 != pCopy) + delete pCopy; + + return iRetStatus; +} + +/** + * Return a handle to a specific calendar. In this implementation, + * the "user" should be the name of the file you want to open. + */ +CAPIStatus CAPI_GetHandle( + CAPISession s, /* i: login session handle */ + char* u, /* i: user as defined in Login */ + long lFlags, /* i: bit flags (none at this time; set to 0) */ + CAPIHandle* pH) /* o: handle */ +{ + PCAPISESSION* pSession = (PCAPISESSION *) s; + PCAPIHANDLE* pHandle = (PCAPIHANDLE *) CAPI_malloc(sizeof(PCAPIHANDLE)); + if (0 == pSession) + return CAPI_ERR2_SESSION_NULL; + *pH = 0; + if (0 == pHandle) + return CAPI_ERR1_MEMORY; + + pHandle->pSession = pSession; + pHandle->pCurl = new nsCurlParser(u); + + /* + * For local capi, the user name is a file name. If it is not fully + * qualified, use the Curl in the session to fill in the missing parts. + */ + *pHandle->pCurl |= *pSession->pCurl; + + char* psLocalFile = pHandle->pCurl->ToLocalFile(); + pHandle->psFile = CAPI_strdup(psLocalFile); + PR_Free(psLocalFile); + + JulianString sPath = pHandle->pCurl->CSIDPath(); + if (NS_OK != CAPI_EnsureUserPath( sPath )) + { + // XXX do some error thing here... + // we should probably pop up a file dialog and let + // the user point us to a path to use. + return 1; + } + + *pH = pHandle; + return CAPI_ERR_OK; +} + +/** + * Close a session, release any associated memory. + */ +CAPIStatus CAPI_Logoff( + CAPISession* s, /* io: session from login */ + long lFlags) /* i: bit flags (none at this time; set to 0) */ +{ + if (0 != s) + { + PCAPISESSION* pSession = (PCAPISESSION *) *s; + CAPI_free(pSession->psUser); + CAPI_free(pSession->psPassword); + CAPI_free(pSession->psHost); + delete pSession->pCurl; + CAPI_free(pSession); + *s = 0; + return CAPI_ERR_OK; + } + return CAPI_ERR2_SESSION_NULL; +} + +/** + * Open a session. + */ +CAPIStatus CAPI_Logon( + const char* psUser, /* i: Calendar store (and ":extra" information ) */ + const char* psPassword, /* i: password for sUser */ + const char* psHost, /* i: calendar server host (and :port) */ + long lFlags, /* i: bit flags (none at this time; set to 0) */ + CAPISession* ps) /* io: the session */ +{ + PCAPISESSION* pSession = (PCAPISESSION *) CAPI_malloc(sizeof(PCAPISESSION)); + *ps = 0; + if (0 == pSession) + return CAPI_ERR1_MEMORY; + pSession->psUser = CAPI_strdup(psUser); + pSession->psPassword = CAPI_strdup(psPassword); + pSession->psHost = CAPI_strdup(psHost); + + pSession->pCurl = new nsCurlParser(); + pSession->pCurl->SetHost(psHost); + pSession->pCurl->SetCSID(psUser); + + /* + * TODO: + * find / create the file associated with this user + */ + + *ps = (CAPISession) pSession; + return CAPI_ERR_OK; +} + +/** + * Open a session. + */ +CAPIStatus CAPI_LogonCurl( + const char* psCurl, /* i: the calendar url */ + const char* psPassword, /* i: password for sUser */ + long lFlags, /* i: bit flags (none at this time; set to 0) */ + CAPISession* ps) /* io: the session */ +{ + PCAPISESSION* pSession = (PCAPISESSION *) CAPI_malloc(sizeof(PCAPISESSION)); + *ps = 0; + if (0 == pSession) + return CAPI_ERR1_MEMORY; + pSession->psPassword = CAPI_strdup(psPassword); + + pSession->pCurl = new nsCurlParser(psCurl); + pSession->psUser = CAPI_strdup(pSession->pCurl->GetCSID().GetBuffer()); + pSession->psHost = CAPI_strdup(pSession->pCurl->GetHost().GetBuffer()); + + /* + * TODO: + * find / create the file associated with this user + */ + + *ps = (CAPISession) pSession; + return CAPI_ERR_OK; +} + +/** + * Set CAPI_Stream values + * pOpaqueStream is allocated if it is null. + */ +CAPIStatus CAPI_SetStreamCallbacks ( + CAPISession s, /* i: login session handle */ + CAPIStream* pOpaqueStream, /* io: The stream to modify */ + CAPICallback pfnSndCallback, /* i: Snd iCalendar data */ + void* userDataSnd, /* i: a user supplied value */ + CAPICallback pfnRcvCallback, /* i: Rcv iCalendar data */ + void* userDataRcv, /* i: a user supplied value */ + long lFlags ) /* i: bit flags (none at this time; set to 0) */ +{ + PCAPISESSION *pSession = (PCAPISESSION*)s; + PCAPIStream* pRet = (PCAPIStream *)pOpaqueStream; + + if (0 == *pOpaqueStream) + { + pRet = (PCAPIStream *) CAPI_malloc(sizeof(PCAPIStream)); + if (0 == pRet) + return CAPI_ERR1_MEMORY; + CAPI_memset(pRet,0,sizeof(PCAPIStream)); + } + + pRet->pfnSndCallback = pfnSndCallback; + pRet->userDataSnd = userDataSnd; + pRet->pfnRcvCallback = pfnRcvCallback; + pRet->userDataRcv = userDataRcv; + + *pOpaqueStream = pRet; + + return CAPI_ERR_OK; +} + + +#define STOR_EXIT(x) {iRetStatus = x; goto STOREVENT_EXIT;} +/** + * Store the supplied event stream into the list of calendar stores pointed to + * by the supplied list of handles. + */ +CAPIStatus CAPI_StoreEvent( + CAPISession s, /* i: login session handle */ + CAPIHandle* pHList, /* i: list of CAPIHandles for store */ + int iHandleCount, /* i: number of valid handles in pH */ + long lFlags, /* i: bit flags (none at this time; set to 0) */ + CAPIStream str ) /* i: stream for reading data to store */ +{ + FILE *pFile; + PCAPISESSION *pSession = (PCAPISESSION*)s; + PCAPIHANDLE* pHandle; + PCAPIStream* pStream = (PCAPIStream*)str; + NSCalendar *pCal = 0; + char* pBuf = 0; + size_t iBufSize = BUFSIZ; + CAPIStatus iRetStatus = CAPI_ERR_OK; + CAPIStatus iStatus; + ICalReader * pRedr = 0; + JLog* pLog = 0; + UnicodeString uFilename; + int iTempFileCreated = 0; + int iWorking; + t_bool bWriteStatus; + size_t iLen; + ErrorCode status = ZERO_ERROR; + + if (0 == pSession) + return CAPI_ERR2_SESSION_BAD; + if (0 == pHList) + return CAPI_ERR2_HANDLE_BAD; + if (0 == pStream) + return CAPI_ERR2_STREAM_BAD; + + /* + * import the user supplied stream into pCal. + * In the interest of minimizing development time (ie, we're lazy) + * we're just going to save the user supplied data into a temporary file, + * import it into pCal, and write the result. + */ + + /* + * get a temporary file name... + */ + + char sTemplate[20]; + char* psTempFile; + sprintf(sTemplate,"CAPIXXXXXX"); + psTempFile = CAPI_mktemp( sTemplate ); + if( 0 == psTempFile) + return CAPI_ERR1_INTERNAL; + if( 0 == (pFile = CAPI_fopen(psTempFile,"w"))) + return CAPI_ERR1_INTERNAL; + + iTempFileCreated = 1; + pBuf = (char *) CAPI_malloc(iBufSize); + if (0 == pBuf) + STOR_EXIT(CAPI_ERR1_MEMORY); + + for( iWorking = 1; iWorking != 0; ) + { + iStatus = (*pStream->pfnSndCallback)( + pStream->userDataSnd, /* user data */ + pBuf, /* place to put the supplied data */ + iBufSize, /* the size of the buffer */ + &iLen); /* how much data was put in the buffer */ + if (iStatus > 0) + { + STOR_EXIT(CAPI_ERR1_CALLBACK); + } + else + { + if (iStatus == -1) + iWorking = 0; + if (iLen > 0) + { + if (iLen != CAPI_fwrite(pBuf,1,iLen,pFile)) + STOR_EXIT(CAPI_ERR1_CALLBACK); + } + } + } + + /* + * Temporary file has been written. Close pFile and import its contents into each + * of the caller supplied CAPI_handles + */ + if (0 != CAPI_fclose(pFile)) + STOR_EXIT(CAPI_ERR1_INTERNAL); + pFile = 0; + CAPI_free(pBuf); + pBuf = 0; + + if (0 != pStream->pfnSndCallback) + { + + for (int i = 0; i < iHandleCount; i++) + { + pHandle = (PCAPIHANDLE*) pHList[i]; + if (0 == pHandle) + STOR_EXIT(CAPI_ERR2_HANDLE_BAD); + + /* + * create an NSCalendar, pCal + */ + pCal = new NSCalendar(pLog); + if (pCal == 0) + STOR_EXIT(CAPI_ERR1_INTERNAL); + + /* + * Try to load pHandle->psFile in pCal + * if file error, return CAPI_ERR1_INTERNAL + */ + + if (CAPI_access(pHandle->psFile, 00 /*F_OK*/)) + { + pFile = 0; + if ( 0 == (pFile =CAPI_fopen(pHandle->psFile,"w"))) + STOR_EXIT(CAPI_ERR1_INTERNAL); + + if (0 != CAPI_fclose(pFile)) + STOR_EXIT(CAPI_ERR1_INTERNAL); + pFile = 0; + } + pRedr = (ICalReader *) new ICalFileReader(pHandle->psFile, status); + if (pRedr == 0) + STOR_EXIT(CAPI_ERR1_INTERNAL); + if (FAILURE(status)) + STOR_EXIT(CAPI_ERR1_INTERNAL); + + /* + * Load original datastore... + */ + uFilename = pHandle->psFile; + pCal->parse(pRedr, uFilename); + delete pRedr; pRedr = 0; + + + /* + * Import new event to store + */ + pRedr = (ICalReader *) new ICalFileReader(psTempFile, status); + if (pRedr == 0) + STOR_EXIT(CAPI_ERR1_INTERNAL); + if (FAILURE(status)) + STOR_EXIT(CAPI_ERR1_INTERNAL); + uFilename = pHandle->psFile; + pCal->parse(pRedr, uFilename); + delete pRedr; pRedr = 0; + + /* + * Write the updated calendar store out to disk... + */ + pCal->export(pHandle->psFile, bWriteStatus); + if (!bWriteStatus) + STOR_EXIT(CAPI_ERR1_INTERNAL); + + delete pCal; + pCal = 0; + + } + } + + if (0 != CAPI_unlink(psTempFile)) + STOR_EXIT(CAPI_ERR1_INTERNAL); + iTempFileCreated = 0; + +STOREVENT_EXIT: + if (0 != pFile) + CAPI_fclose(pFile); + if (0 != pCal) + delete pCal; + if (0 != pRedr) + delete pRedr; + if (iTempFileCreated) + CAPI_unlink(psTempFile); + if (0 != pBuf) + CAPI_free(pBuf); + + return iRetStatus; +} + +/*************************************************************************************** +*** Simple test program +****************************************************************************************/ +#if 0 /* define test program */ +typedef struct +{ + char *p; + size_t iSize; +} CAPICTX; + +/** + * Send data to CAPI. This is invoked on calls such as CAPI_StoreEvent. + */ +int SndData(void* pData, char* pBuf, size_t iSize, size_t *piTransferred) +{ + CAPICTX* pCtx = (CAPICTX*)pData; + *piTransferred = (pCtx->iSize > iSize) ? iSize : pCtx->iSize; + CAPI_memcpy(pBuf, pCtx->p, *piTransferred ); + pCtx->iSize -= *piTransferred; + pCtx->p += *piTransferred; + return pCtx->iSize > 0 ? CAPI_CALLBACK_CONTINUE : CAPI_CALLBACK_DONE; +} + +/** + * Receive data from CAPI. This is invoked on calls such as + * CAPI_FetchEventsByID, CAPI_FetchEventsByRange. + */ +int RcvData(void* pData, char* pBuf, size_t iSize, size_t *piTransferred) +{ + CAPICTX* pCtx = (CAPICTX*)pData; + *piTransferred = (pCtx->iSize > iSize) ? iSize : pCtx->iSize; + CAPI_memcpy(pCtx->p, pBuf, *piTransferred ); + + /* + * for now, we're just going to print out whatever we get... + */ + { + char sBuf[2000]; + CAPI_memcpy(sBuf,pCtx->p,*piTransferred); + sBuf[*piTransferred]=0; + printf( "%s", sBuf ); + } + return CAPI_CALLBACK_CONTINUE; /* return values > 0 are error numbers. */ +} + +void main( int argc, char *argv[], char *envp[] ) +{ + char* psCap; + CAPIStatus s; + CAPISession Session; + CAPIHandle Handle; + char sBuf[BUFSIZ]; + CAPIStream SndStream; + CAPIStream RcvStream; + + CAPICTX MyCtx; + + if (CAPI_ERR_OK != (s = CAPI_Capabilities( &psCap, "localhost", 0 ))) + { + fprintf(stderr,"CAPI_Capabilities(): %ld\n", s); + exit(1); + } + + /* + * CAPABILITIES + */ + printf( "CAPI_Capabilities:\n%s\n", psCap ); + + /* + * LOGON + */ + if (CAPI_ERR_OK != (s = CAPI_Logon( "sman", "bla", "localhost", 0L, &Session ))) + { + fprintf(stderr,"CAPI_Logon(): %ld\n", s ); + exit(1); + } + printf("CAPI_Logon(): success\n" ); + + /* + * GET HANDLE + */ + if (CAPI_ERR_OK != (s = CAPI_GetHandle( Session, "c:/temp/junk.txt", 0, &Handle ))) + { + fprintf(stderr,"CAPI_Logon(): %ld\n", s ); + exit(1); + } + printf("CAPI_GetHandle(): success\n" ); + + /* + * STORE EVENT + */ + strcpy(sBuf,"Content-type: text/calendar\n\ +Content-encoding: 7bit\n\ +\n\ +BEGIN:VCALENDAR\n\ +METHOD:PUBLISH\n\ +PRODID:-//ACME/DesktopCalendar//EN\n\ +VERSION:2.0\n\ +BEGIN:VEVENT\n\ +ORGANIZER:mailto:a@example.com\n\ +DTSTART:19970701T200000Z\n\ +DTEND:19970701T220000Z\n\ +DTSTAMP:19970701T180000Z\n\ +SUMMARY:BIG TIME local capi store event\n\ +UID:QQIIDDLL098503945-34059873405-340598340@example.com\n\ +END:VEVENT\n\ +END:VCALENDAR\n" ); + MyCtx.p = sBuf; + MyCtx.iSize = strlen(sBuf); + if ( CAPI_ERR_OK != (s = CAPI_SetStreamCallbacks(Session, &SndStream, SndData, &MyCtx, 0, &MyCtx,0))) + { + fprintf(stderr,"CAPI_SetStreamCallbacks(): %ld\n", s ); + exit(1); + } + if ( CAPI_ERR_OK != (s = CAPI_StoreEvent( Session,&Handle,1,0,&SndStream))) + { + fprintf(stderr,"CAPI_StoreEvent(): %ld\n", s ); + exit(1); + } + + /* + * FETCH EVENT + */ + MyCtx.p = sBuf; + MyCtx.iSize = sizeof(sBuf); + if ( CAPI_ERR_OK != (s = CAPI_SetStreamCallbacks(Session, &RcvStream, 0,0,RcvData, &MyCtx,0))) + { + fprintf(stderr,"CAPI_SetStreamCallbacks(): %ld\n", s ); + exit(1); + } + if ( CAPI_ERR_OK != (s = CAPI_FetchEventsByID( Session,Handle,0,"098503945-34059873405-340598340@example.com",0,0,0,0,&RcvStream))) + { + fprintf(stderr,"CAPI_FetchEventsByID(): %ld\n", s ); + exit(1); + } + + /* + * DESTROY HANDLES + */ + if (CAPI_ERR_OK != (s = CAPI_DestroyHandles(Session, &Handle, 1, 0L))) + { + fprintf(stderr,"CAPI_DestroyHandles(): %ld\n", s ); + exit(1); + } + printf("CAPI_DestroyHandles(): success\n" ); + + /* + * LOGOFF + */ + if (CAPI_ERR_OK != (s = CAPI_Logoff( &Session, 0L))) + { + fprintf(stderr,"CAPI_Logoff(): %ld\n", s ); + exit(1); + } + printf("CAPI_Logoff(): success\n" ); + + if (0 != Session) + { + fprintf(stderr,"Session was not NULL after CAPI_Logoff\n"); + exit(1); + } + printf("CAPI Test Program: normal exit\n" ); +} +#endif /* define test program */ diff --git a/calendar/modules/core/capi/local/src/config.mk b/calendar/modules/core/capi/local/src/config.mk new file mode 100644 index 00000000000..e69de29bb2d diff --git a/calendar/modules/core/capi/local/src/manifest.mn b/calendar/modules/core/capi/local/src/manifest.mn new file mode 100644 index 00000000000..e69de29bb2d diff --git a/calendar/modules/core/capi/manifest.mn b/calendar/modules/core/capi/manifest.mn new file mode 100644 index 00000000000..e69de29bb2d diff --git a/calendar/modules/core/config.mk b/calendar/modules/core/config.mk new file mode 100644 index 00000000000..e69de29bb2d diff --git a/calendar/modules/core/htmlform/Makefile b/calendar/modules/core/htmlform/Makefile new file mode 100644 index 00000000000..e69de29bb2d diff --git a/calendar/modules/core/htmlform/inc/Makefile b/calendar/modules/core/htmlform/inc/Makefile new file mode 100644 index 00000000000..e69de29bb2d diff --git a/calendar/modules/core/htmlform/inc/form.h b/calendar/modules/core/htmlform/inc/form.h new file mode 100644 index 00000000000..8c3814066b6 --- /dev/null +++ b/calendar/modules/core/htmlform/inc/form.h @@ -0,0 +1,106 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +#ifndef _JULIAN_FORMS_H +#define _JULIAN_FORMS_H + +#include "julianform.h" +#include "julnstr.h" + +class JULIAN_PUBLIC JulianServerProxy +{ +public: + ICalComponent* ic; + + JulianServerProxy() {}; + virtual ~JulianServerProxy() {}; + ICalComponent* getByUid(char *uid) { return ic; }; + + void setICal(ICalComponent* i) { ic = i; }; + +}; + +#include "formFactory.h" + +typedef struct +{ + char* type; + char* data; +} form_data_combo; + +class JULIAN_PUBLIC JulianForm +{ +private: + + JulianString htmlForm; + char* mimedata; + char buttonLabel[2048]; + NSCalendar* imipCal; + pJulian_Form_Callback_Struct JulianForm_CallBacks; + /* added 7-7-98 */ + static XP_Bool ms_bFoundNLSDataDirectory; + JulianFormFactory* jff; + +public: + JulianForm(); + virtual ~JulianForm(); + + int32 refcount; /* Who's looking at this */ + int32 formDataCount; /* number of pointers in formData */ + PRMonitor * my_monitor; + + /* number of possible pointers in formData */ + #define formDataIndex 10 + form_data_combo formData[formDataIndex]; /* a pointer to an array of pointers that point to a type/data string */ + + char* contextName; + + XP_Bool StartHTML(); + char* getHTMLForm(XP_Bool Want_Detail, NET_StreamClass *this_stream = nil); + void setMimeData(char *mimedata); + void setCallbacks(pJulian_Form_Callback_Struct callBacks) { JulianForm_CallBacks = callBacks; }; + pJulian_Form_Callback_Struct getCallbacks() { return JulianForm_CallBacks; }; + + void setCalendar(NSCalendar* newCal) { imipCal = newCal; } + NSCalendar * getCalendar() { return imipCal; } + JulianPtrArray * getEvents() { if (imipCal) { return imipCal->getEvents(); } else return 0; } + + /* added 7-7-98 */ + static void setFoundNLSDataDirectory(XP_Bool bFound) { ms_bFoundNLSDataDirectory = bFound; } + static XP_Bool isFoundNLSDataDirectory() { return ms_bFoundNLSDataDirectory; } + + MWContext* getContext() { return (*JulianForm_CallBacks->FindNamedContextInList)((*JulianForm_CallBacks->FindSomeContext)(), contextName); } + + XP_Bool hasComment() { return getComment() != nil; } + char* getComment(); + char* getDelTo(); + + char* getLabel() { return buttonLabel; } + void setLabel(char *newlabel) { if (newlabel) XP_STRCPY(buttonLabel, newlabel); if (getCallbacks() && getCallbacks()->PlusToSpace) (*getCallbacks()->PlusToSpace)(buttonLabel); } +}; + +XP_BEGIN_PROTOS + +JulianForm* jform_CreateNewForm (char *calendar_mime_data, pJulian_Form_Callback_Struct callbacks, XP_Bool bFoundNLSDataDirectory); +void jform_DeleteForm (JulianForm *jf); +char* jform_GetForm (JulianForm *jf); +void jform_CallBack (JulianForm *jf, char *type); + +XP_END_PROTOS +#endif + diff --git a/calendar/modules/core/htmlform/inc/formFactory.h b/calendar/modules/core/htmlform/inc/formFactory.h new file mode 100644 index 00000000000..3c394dccd5d --- /dev/null +++ b/calendar/modules/core/htmlform/inc/formFactory.h @@ -0,0 +1,530 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +#ifndef _JULIAN_FormFactory_H +#define _JULIAN_FormFactory_H + +#include "jdefines.h" +#include "julnstr.h" + +class JulianForm; +#if defined(XP_PC) +#pragma warning ( disable : 4251 ) +#endif + +const int32 jff_clip_events = 50; + +class JULIAN_PUBLIC JulianFormFactory +{ +friend class JulianForm; + +public: + JulianFormFactory(); + JulianFormFactory(NSCalendar& imipCal); + JulianFormFactory(NSCalendar& imipCal, JulianServerProxy* jsp); + JulianFormFactory(NSCalendar& imipCal, JulianForm& hostForm, pJulian_Form_Callback_Struct callbacks); + + /* + ** Call init before calling getHTML() + */ + void init(); + + virtual ~JulianFormFactory(); + + /* + ** Returns a new UnicodeString with html that is intended to be enclosed in a real html file. + ** Call is responable for disposing of the returned UnicodeString. + */ + XP_Bool getHTML(JulianString* htmlstorage, XP_Bool want_detail = FALSE); + XP_Bool getHTML(JulianString* OutString, NET_StreamClass *this_stream, XP_Bool want_detail = FALSE); + + /* + ** Sets the base NSCalendar. + */ + void setNSCalendar(NSCalendar& newCalendar) { firstCalendar = &newCalendar; } + + /* + ** These are the different form button types. The call back url will list + ** as it's first thing the type = the name. + */ + static JulianString Buttons_Details_Type; + static JulianString Buttons_Add_Type; + static JulianString Buttons_Close_Type; + static JulianString Buttons_Accept_Type; + static JulianString Buttons_Decline_Type; + static JulianString Buttons_Tentative_Type; + static JulianString Buttons_SendFB_Type; + static JulianString Buttons_SendRefresh_Type; + static JulianString Buttons_DelTo_Type; + static JulianString CommentsFieldName; + static JulianString DelToFieldName; + static JulianString SubjectSep; + +private: + NSCalendar* firstCalendar; // Base NSCalendar + ICalComponent* thisICalComp; // Current vEnvent or vFreeBusy that is being made into html + ICalComponent* serverICalComp; // Current Database Version vEnvent or vFreeBusy that is being made into html + XP_Bool detail; + JulianString* s; // Holds the html that is being built up. + JulianForm* jf; + JulianServerProxy* ServerProxy; // How to get to the server + int32 maxical; // # of vevetns otr vfreebusy in the array + int32 aref_count; // For muiltevent table of contents + int32 aref2_count; // For muiltevent each form. must be in sync with aref_count + pJulian_Form_Callback_Struct cb;// How to call code to create urls for the buttons + NET_StreamClass *outStream; // Could be streamed output. Optional + XP_Bool do_capi_login; // Default is not to ask for capi login info + + // Use by the freebusy table. In order. + enum FB_State { + Empty_State, + Free_State, + XParam_State, + Busy_State + }; + + Julian_Duration MinutesPerSlot; + int32 SlotsPerHour; + XP_Bool displayTimeZone; + int32 scaleType; // 1 = days 1 to 31, 2 = hours 0 to 24 + int32 slotsacross; + int32 hoursToDisplay; // 1 to 24. default is 24 hours + FB_State state; // For free, busy, skip state + FB_State new_state; + int32 count; + JulianString tz; + JulianString uTemp; + JulianString lineFormat; + char* TimeHour_HTML; + int32 start_hour; + int32 end_hour; + DateTime start; + DateTime end; + TimeZone* default_tz; + Period* p; + Freebusy* fb; + int32 fbIndex; + int32 pIndex; + JulianPtrArray* pv; + JulianPtrArray* fbv; + + // These bools show what types of ical objects are being used in this message + XP_Bool isEvent; + XP_Bool isFreeBusy; + + void SetDetail(XP_Bool newDetail) { detail = newDetail; }; + XP_Bool isDetail() { return detail;}; + XP_Bool isPreProcessed(JulianString& icalpropstr) { return (ICalPreProcess.IndexOf(icalpropstr.GetBuffer(), 0) >= 0); }; + XP_Bool isPostProcessed(JulianString& icalpropstr) { return (ICalPostProcess.IndexOf(icalpropstr.GetBuffer(), 0) >= 0); }; + + JulianString * doARef(JulianString& refText, JulianString& refTarget, JulianString* outputString); + JulianString * doFont(JulianString& fontText, JulianString* outputString); + JulianString * doItalic(JulianString& ItalicText, JulianString* outputString); + JulianString * doBold(JulianString& BoldText, JulianString* outputString); + JulianString * doBold(char* BoldText, JulianString* outputString); + + void doAddHTML(UnicodeString & moreHtml) { char*y = moreHtml.toCString(""); if (y) {*s += y; delete y;} flush_stream(); }; + void doAddHTML(JulianString & moreHtml) { *s += moreHtml; flush_stream();}; + void doAddHTML(JulianString * moreHtml) { *s +=*moreHtml; flush_stream();}; + void doAddHTML(char* moreHtml) { *s += moreHtml; flush_stream();}; + int32 flush_stream(); + + void doPreProcessing(char* icalpropstr); + void doPreProcessingDateTime(JulianString & icalpropstr, XP_Bool allday, DateTime &start, DateTime &end, ICalComponent &ic); + void doPreProcessingAttend(ICalComponent &ic); + void doPreProcessingOrganizer(ICalComponent &ic); + void doDifferenceProcessing(JulianString icalpropstr); + void doDifferenceProcessingAttendees(); + void doHeaderMuiltStart(); + void doHeaderMuilt(); + void doHeaderMuiltEnd(); + + void doProps(int32 labelCount, JulianString labels[], int32 dataCount, JulianString data[]); + void doHeader(JulianString HeaderText); + void doClose(); + void doStatus(); + void doSingleTableLine(JulianString & labelString, JulianString & dataString, XP_Bool addSpacer = TRUE); + void doCommentText(); + JulianString doCreateButton(JulianString InputType, JulianString ButtonName, XP_Bool addtextField = FALSE); + void doAddGroupButton(JulianString GroupButton_HTML); + void doAddButton(JulianString SingleButton_HTML); + void doMakeFreeBusyTable(); + + void HandleError(); + void HandlePublishVEvent(); + void HandlePublishVFreeBusy(XP_Bool isPublish); + void HandleRequestVEvent(); + void HandleRequestVFreeBusy(); + void HandleEventReplyVEvent(); + void HandleEventCancelVEvent(); + void HandleEventRefreshRequestVEvent(); + void HandleEventCounterPropVEvent(); + void HandleDeclineCounterVEvent(); + + char* getJulianErrorString(int32 ErrorNum); + +/* Table Utils Functions */ + void addLegend(); + void addTimeZone(); + void addMajorScale(); + void addMinorScale(); + void addTicksScale(); + /*void emptyRow();*/ + void makeHourFBTable(); + void makeDaysFBTable(); + void DaysLineInc(DateTime* dtTime); + void MonthLineInc(DateTime* dtTime); + void LineInc(DateTime* dtTime); + int32 LineCheck(DateTime& baseTime, DateTime& checkTime, DateTime& checkTimeEnd); + void enterState(FB_State newState, XP_Bool forse); + void checkPeriodBounds(DateTime& startofslot, DateTime& endofslot); + Period* getNextPeriod(); + int32 getFBType(); + + JulianString MoreErrors; + JulianString TooManyEvents; + JulianString error0; + JulianString error1; + JulianString error2; + JulianString error3; + JulianString error4; + JulianString error5; + JulianString error6; + JulianString error7; + + static char* Start_HTML; + static char* End_HTML; + static char* Props_Head_HTML; + static char* Props_HTML_Before_Label; + static char* Props_HTML_After_Label; + static char* Props_HTML_After_Data; + static char* Props_HTML_Empty_Label; + static char* Props_End_HTML; + static char* General_Header_Start_HTML; + static char* General_Header_Status_HTML; + static char* General_Header_End_HTML; + static char* Head2_HTML; + static char* Italic_Start_HTML; + static char* Italic_End_HTML; + static char* Bold_Start_HTML; + static char* Bold_End_HTML; + static char* Aref_Start_HTML; + static char* Aref_End_HTML; + static char* ArefTag_End_HTML; + static char* nbsp; + static char* Accepted_Gif_HTML; + static char* Declined_Gif_HTML; + static char* Delegated_Gif_HTML; + static char* NeedsAction_Gif_HTML; + static char* Question_Gif_HTML; + static char* Line_3_HTML; + static char* Cell_Start_HTML; + static char* Cell_End_HTML; + static char* Font_Fixed_Start_HTML; + static char* Font_Fixed_End_HTML; + static char* Line_Break_HTML; + + static char* Start_Font; + static char* Start_BIG_Font; + static char* End_Font; + + static char* Buttons_Single_Start_HTML; + static char* Buttons_Single_Mid_HTML; + static char* Buttons_Single_End_HTML; + static char* Buttons_Text_End_HTML; + + JulianString Buttons_Details_Label; + JulianString Buttons_Add_Label; + JulianString Buttons_Close_Label; + JulianString Buttons_Accept_Label; + JulianString Buttons_AcceptAll_Label; + JulianString Buttons_Update_Label; + JulianString Buttons_Decline_Label; + JulianString Buttons_Tentative_Label; + JulianString Buttons_SendFB_Label; + JulianString Buttons_SendRefresh_Label; + JulianString Buttons_DelTo_Label; + + static char* Buttons_SaveDel_HTML; + + static char* Buttons_GroupStart_HTML; + static char* Buttons_GroupEnd_HTML; + static char* Buttons_GroupSingleStart_HTML; + static char* Buttons_GroupSingleEnd_HTML; + + static char* Text_Label_Start_HTML; + static JulianString Text_Label; + static char* Text_Label_End_HTML; + static char* Text_Field_HTML; + + static JulianString ICalPreProcess; + static JulianString ICalPostProcess; + + JulianString EventInSchedule; + JulianString EventNotInSchedule; + JulianString EventConflict; + JulianString EventNote; + JulianString EventError; + JulianString EventTest; + JulianString Text_To; + JulianString Text_AllDay; + JulianString Text_StartOn; + JulianString Text_Was; + JulianString MuiltEvent; + JulianString WhenStr; + JulianString WhatStr; + + JulianString MuiltEvent_Header_HTML; + JulianString MuiltFB_Header_HTML; + + char* String_What; + char* String_When; + char* String_Location; + char* String_Organizer; + char* String_Status; + char* String_Priority; + char* String_Categories; + char* String_Resources; + char* String_Attachments ; + char* String_Alarms; + char* String_Created ; + char* String_Last_Modified; + char* String_Sent; + char* String_UID ; + + /* + ** Free/Busy Table + */ + static char* FBT_Start_HTML; + static char* FBT_End_HTML; + static char* FBT_NewRow_HTML; + static char* FBT_EndRow_HTML; + static char* FBT_TimeHead_HTML; + static char* FBT_TimeHeadEnd_HTML; + static char* FBT_TimeHour_HTML; + static char* FBT_TimeHourEnd_HTML; + static char* FBT_TD_HourColor_HTML; + static char* FBT_TD_HourColorEnd_HTML; + static char* FBT_TD_MinuteColor_HTML; + static char* FBT_TD_MinuteColorEnd_HTML; + static char* FBT_TDOffsetCell_HTML; + static char* FBT_TickLong_HTML; + static char* FBT_TickShort_HTML; + static char* FBT_TimeMin_HTML; + static char* FBT_TimeMinEnd_HTML; + static char* FBT_HourStart; + static char* FBT_HourEnd; + + static char* FBT_DayStart_HTML; + static char* FBT_DayEnd_HTML; + static char* FBT_DayEmptyCell_HTML; + static char* FBT_DayFreeCell_HTML; + static char* FBT_DayBusyCell_HTML; + static char* FBT_DayXParamCell_HTML; + static char* FBT_EmptyRow_HTML; + static char* FBT_DayXColFreeCell_HTML; + static char* FBT_DayXColBusyCell_HTML; + static char* FBT_DayXColEmptyCell_HTML; + static char* FBT_DayXXParamCell_HTML; + + static char* FBT_MonthFormat; + static char* FBT_TickDaySetting; + + static char* FBT_Legend_Start_HTML; + static char* FBT_Legend_Text1_HTML; + static char* FBT_Legend_Text2_HTML; + static char* FBT_Legend_Text3_HTML; + static char* FBT_Legend_Text4_HTML; + static char* FBT_Legend_Text5_HTML; + static char* FBT_Legend_TextEnd_HTML; + static char* FBT_Legend_End_HTML; + + JulianString FBT_Legend_Title; + JulianString FBT_Legend_Free; + JulianString FBT_Legend_Busy; + JulianString FBT_Legend_Unknown; + JulianString FBT_Legend_xparam; + + JulianString FBT_AM; + JulianString FBT_PM; + static char* FBT_TickMark1; + static char* FBT_TickMark2; + static char* FBT_TickMark3; + static char* FBT_TickMark4; + static char* FBT_TickSetting; + static char* FBT_TickOffset; + static char* FBT_DayFormat; + + /* + ** Error + */ + char* error_Header_HTML; + static int32 error_Fields_Labels_Length; + static JulianString error_Fields_Labels[]; + static int32 error_Fields_Data_HTML_Length; + static JulianString error_Fields_Data_HTML[]; + static char* error_End_HTML ; + + /* + ** Publish + */ + char* publish_Header_HTML; + static int32 publish_Fields_Labels_Length; + static JulianString publish_Fields_Labels[]; + static int32 publish_Fields_Data_HTML_Length; + static JulianString publish_Fields_Data_HTML[]; + static char* publish_End_HTML; + + /* + ** Publish Detail + */ + static int32 publish_D_Fields_Labels_Length; + static JulianString publish_D_Fields_Labels[]; + static int32 publish_D_Fields_Data_HTML_Length; + static JulianString publish_D_Fields_Data_HTML[]; + + /* + ** Publish VFreeBusy + */ + char* publishFB_Header_HTML; + char* replyFB_Header_HTML; + static int32 publishFB_Fields_Labels_Length; + static JulianString publishFB_Fields_Labels[]; + static int32 publishFB_Fields_Data_HTML_Length; + static JulianString publishFB_Fields_Data_HTML[]; + static char* publishFB_End_HTML; + + /* + ** Publish VFreeBusy Detail + */ + static int32 publishFB_D_Fields_Labels_Length; + static JulianString publishFB_D_Fields_Labels[]; + static int32 publishFB_D_Fields_Data_HTML_Length; + static JulianString publishFB_D_Fields_Data_HTML[]; + + /* + ** Request + */ + char* request_Header_HTML; + static int32 request_Fields_Labels_Length; + static JulianString request_Fields_Labels[]; + static int32 request_Fields_Data_HTML_Length; + static JulianString request_Fields_Data_HTML[]; + static char* request_End_HTML; + + /* + ** Request Detail + */ + static int32 request_D_Fields_Labels_Length; + static JulianString request_D_Fields_Labels[]; + static int32 request_D_Fields_Data_HTML_Length; + static JulianString request_D_Fields_Data_HTML[]; + + /* + ** Request VFreeBusy + */ + char* request_FB_Header_HTML; + static int32 request_FB_Fields_Labels_Length; + static JulianString request_FB_Fields_Labels[]; + static int32 request_FB_Fields_Data_HTML_Length; + static JulianString request_FB_Fields_Data_HTML[]; + static char* request_FB_End_HTML; + + /* + ** Request VFreeBusy Detail + */ + char* request_D_FB_Header_HTML; + static int32 request_D_FB_Fields_Labels_Length; + static JulianString request_D_FB_Fields_Labels[]; + static int32 request_D_FB_Fields_Data_HTML_Length; + static JulianString request_D_FB_Fields_Data_HTML[]; + static char* request_D_FB_End_HTML; + + /* + ** Event Reply + */ + char* eventreply_Header_HTML; + static int32 eventreply_Fields_Labels_Length; + static JulianString eventreply_Fields_Labels[]; + static int32 eventreply_Fields_Data_HTML_Length; + static JulianString eventreply_Fields_Data_HTML[]; + static char* eventreply_End_HTML; + + /* + ** Event Reply Detail + */ + static int32 eventreply_D_Fields_Labels_Length; + static JulianString eventreply_D_Fields_Labels[]; + static int32 eventreply_D_Fields_Data_HTML_Length; + static JulianString eventreply_D_Fields_Data_HTML[]; + + /* + ** Event Cancel + */ + char* eventcancel_Header_HTML; + static int32 eventcancel_Fields_Labels_Length; + static JulianString eventcancel_Fields_Labels[]; + static int32 eventcancel_Fields_Data_HTML_Length; + static JulianString eventcancel_Fields_Data_HTML[]; + static char* eventcancel_End_HTML; + + /* + ** Event Cancel Detail + */ + static int32 eventcancel_D_Fields_Labels_Length; + static JulianString eventcancel_D_Fields_Labels[]; + static int32 eventcancel_D_Fields_Data_HTML_Length; + static JulianString eventcancel_D_Fields_Data_HTML[]; + + /* + ** Event Refresh Request + */ + char* eventrefreshreg_Header_HTML; + static int32 eventrefreshreg_Fields_Labels_Length; + static JulianString eventrefreshreg_Fields_Labels[]; + static int32 eventrefreshreg_Fields_Data_HTML_Length; + static JulianString eventrefreshreg_Fields_Data_HTML[]; + static char* eventrefreshreg_End_HTML; + + /* + ** Event Refresh Request Detail + */ + static int32 eventrefreshreg_D_Fields_Labels_Length; + static JulianString eventrefreshreg_D_Fields_Labels[]; + static int32 eventrefreshreg_D_Fields_Data_HTML_Length; + static JulianString eventrefreshreg_D_Fields_Data_HTML[]; + + /* + ** Event Counter Proposal + */ + char* eventcounterprop_Header_HTML; + + /* + ** Event Deline Counter + */ + char* eventdelinecounter_Header_HTML; + static int32 eventdelinecounter_Fields_Labels_Length; + static JulianString eventdelinecounter_Fields_Labels[]; + static int32 eventdelinecounter_Fields_Data_HTML_Length; + static JulianString eventdelinecounter_Fields_Data_HTML[]; +}; +#if defined(XP_PC) +#pragma warning ( default : 4251 ) +#endif + +#endif diff --git a/calendar/modules/core/htmlform/inc/julianform.h b/calendar/modules/core/htmlform/inc/julianform.h new file mode 100644 index 00000000000..51bbbcc656e --- /dev/null +++ b/calendar/modules/core/htmlform/inc/julianform.h @@ -0,0 +1,166 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +#ifndef _JULIANFORM_H +#define _JULIANFORM_H + +#include "jdefines.h" +#include "netcburl.h" +#include "fe_proto.h" + +XP_BEGIN_PROTOS + +typedef struct Julian_Form_Callback_Struct +{ + /* + ** callbackurl should be set to NET_CallbackURLCreate(), it's + ** in netcburl.h. Can also be set to nil. + */ + char* (*callbackurl)(NET_CallbackURLFunc func, void* closure); + + /* + ** callbackurlfree should be set to NET_CallbackURLFree(), it's + ** in netcburl.h. Can also be set to nil. + */ + int (*callbackurlfree)(NET_CallbackURLFunc func, void* closure); + + /* + ** Should Link to NET_ParseURL() + */ + char* (*ParseURL)(const char *url, int wanted); + + /* + ** Should Link to FE_MakeNewWindow() + */ + MWContext* (*MakeNewWindow)(MWContext *old_context, URL_Struct *url, char *window_name, Chrome *chrome); + + /* + ** Should Link to NET_CreateURLStruct (); + */ + URL_Struct* (*CreateURLStruct) (const char *url, NET_ReloadMethod force_reload); + + /* + ** Should Link to PA_BeginParseMDL() + */ + NET_StreamClass* (*BeginParseMDL) (FO_Present_Types format_out, void *init_data, URL_Struct *anchor, MWContext *window_id); + + /* + ** Should Link to NET_SACopy() + */ + char* (*SACopy) (char **dest, const char *src); + + /* + ** Should Link to NET_SendMessageUnattended(). Added by John Sun 4-22-98. + */ + int (*SendMessageUnattended) (MWContext* context, char* to, char* subject, char* otherheaders, char* body); + + /* + ** Should Link to FE_DestroyWindow. Added by John Sun 4-22-98. + */ + void (*DestroyWindow) (MWContext* context); + + /* + ** Should Link to FE_RaiseWindow. + */ + void (*RaiseWindow) (MWContext* context); + + /* + ** Should Link to Current MWContext. + */ + MWContext* my_context; + + /* + ** Should Link to XP_GetString. + */ + char* (*GetString) (int i); + + /* + ** Should Link to XP_FindSomeContext() + */ + MWContext* (*FindSomeContext)(); + + /* + ** Should Link to XP_FindNamedContextInList() + */ + MWContext* (*FindNamedContextInList)(MWContext* context, char *name); + + /* + ** Should Link to PREF_CopyCharPref() + */ + int (*CopyCharPref)(const char *pref, char ** return_buf); + + /* + ** Should Link to NET_UnEscape() + */ + char* (*UnEscape)(char *str); + + /* + ** Should Link to NET_PlusToSpace() + */ + void (*PlusToSpace)(char *str); + + /* + ** Should Link to PREF_SetCharPref() + */ + int (*SetCharPref)(const char *pref, const char* buf); + + /* + ** Should Link to FE_PromptUsernameAndPassword() + */ + Bool (*PromptUsernameAndPassword)(MWContext* window_id, char* message, char** username, char** password); + + /* + ** Should Link to LO_ProcessTag(). + */ + intn (*ProcessTag)(void *data_object, PA_Tag *tag, intn status); + +#if defined(XP_WIN)||defined(XP_UNIX) + /* + ** Should link to FEU_GetJulianPath. Get the path to the Julian directory. Added by John Sun 5-14-98. + */ + void (*GetJulianPath) (char ** julianPath, void * emptyArg); +#endif + + /* + ** Should Link to PREF_GetBoolPref() + */ + int (*BoolPref)(const char *pref, XP_Bool * return_val); + + /* + ** Should Link to PREF_GetIntPref() + */ + int (*IntPref)(const char *pref, int32 * return_int); + +} Julian_Form_Callback_Struct, *pJulian_Form_Callback_Struct; + +/* +** Caller disposes of callbacks. +*/ +XP_Bool JULIAN_PUBLIC jf_Initialize(pJulian_Form_Callback_Struct callbacks); + +void JULIAN_PUBLIC *jf_New(char *calendar_mime_data, XP_Bool bFoundNLSDataDirectory); +void JULIAN_PUBLIC jf_Destroy(void *instdata); +void JULIAN_PUBLIC jf_Shutdown(void); +char JULIAN_PUBLIC *jf_getForm(void *instdata); +void JULIAN_PUBLIC jf_setDetail(int detail_form); +void JULIAN_PUBLIC jf_callback(void *instdata, char* url, URL_Struct *URL_s); +void JULIAN_PUBLIC jf_detail_callback(void *instdata, char *url, URL_Struct *URL_s); + +XP_END_PROTOS + +#endif diff --git a/calendar/modules/core/htmlform/inc/manifest.mn b/calendar/modules/core/htmlform/inc/manifest.mn new file mode 100644 index 00000000000..e69de29bb2d diff --git a/calendar/modules/core/htmlform/manifest.mn b/calendar/modules/core/htmlform/manifest.mn new file mode 100644 index 00000000000..e69de29bb2d diff --git a/calendar/modules/core/htmlform/src/Makefile b/calendar/modules/core/htmlform/src/Makefile new file mode 100644 index 00000000000..e69de29bb2d diff --git a/calendar/modules/core/htmlform/src/config.mk b/calendar/modules/core/htmlform/src/config.mk new file mode 100644 index 00000000000..e69de29bb2d diff --git a/calendar/modules/core/htmlform/src/form.cpp b/calendar/modules/core/htmlform/src/form.cpp new file mode 100644 index 00000000000..10a97aa3579 --- /dev/null +++ b/calendar/modules/core/htmlform/src/form.cpp @@ -0,0 +1,920 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +#include "jdefines.h" +#include "julnstr.h" + +#include +#include +#include +#include +#include +#include "smpdtfmt.h" +#include +#include "datetime.h" +#include "jutility.h" +#include "duration.h" + +#include "attendee.h" +#include "vevent.h" +#include "icalsrdr.h" +#include "icalfrdr.h" +#include "prprty.h" +#include "icalprm.h" +#include "freebusy.h" +#include "vfrbsy.h" +#include "nscal.h" +#include "keyword.h" + +#include "txnobjfy.h" +#include "user.h" +#include "txnobj.h" + +#include "jlog.h" +#include "uri.h" + +#include "xp.h" +#include "prmon.h" + +#include "form.h" + +static void julian_handle_close(JulianForm *jf); +#ifdef OSF1 + void julian_handle_accept(JulianForm *jf, int newStatus); +#else + void julian_handle_accept(JulianForm *jf, Attendee::STATUS newStatus); +#endif +static void julian_handle_moredetail(JulianForm *jf); +static void julian_send_response(JulianString& subject, JulianPtrArray& recipients, JulianString& LoginName, JulianForm& jf, NSCalendar& calendar); +static void julian_send_response_with_events(JulianString& subject, JulianPtrArray& recipients, JulianString& LoginName, JulianForm& jf, NSCalendar& calendar, JulianPtrArray * events); +static void julian_add_new_event_to_send(JulianPtrArray * vvEventsToSend, TimeBasedEvent * eventToSend); +static XP_Bool julian_events_comments_and_attendees_match(TimeBasedEvent * a, TimeBasedEvent * b); +static void julian_fill_in_delegatedToVector(char * deltonames, JulianPtrArray * vDelegatedToFillIn); + +static void Julian_ClearLoginInfo(); +static int Julian_GetLoginInfo(JulianForm& jf, MWContext* context, char** url, char** password); + +#define julian_pref_name "calendar.login_url" + +XP_Bool JulianForm::ms_bFoundNLSDataDirectory = FALSE; + +JulianForm *jform_CreateNewForm(char *calendar_mime_data, pJulian_Form_Callback_Struct callbacks, + XP_Bool bFoundNLSDataDirectory) +{ + JulianForm *jf = new JulianForm(); + + if (jf) + { + jf->refcount = 1; + jf->setMimeData(calendar_mime_data); + jf->setCallbacks(callbacks); + JulianForm::setFoundNLSDataDirectory(bFoundNLSDataDirectory); + } + return jf; +} + +void jform_DeleteForm(JulianForm *jf) +{ + if (jf) + { + jf->refcount--; + if (jf->refcount == 0) + { + delete jf; + } + } +} + +char* jform_GetForm(JulianForm *jf) +{ + jf->StartHTML(); + return jf->getHTMLForm(FALSE); +} + +void jform_CallBack(JulianForm *jf, char *type) +{ + char* button_type; + char* button_type2; + char* button_data; + form_data_combo fdc; + int32 x; + + PR_EnterMonitor(jf->my_monitor); + /* + ** type contains the html form string for this. + ** The gernal format is ? type = label or name = data + ** The last thing in this list is the button that started + ** this. + */ + button_type = XP_STRCHR(type, '?'); + button_type++; // Skip ?. Now points to type + + while (TRUE) + { + button_type2 = XP_STRCHR(button_type, '='); + if (button_type2) + { + *button_type2++ = '\0'; + button_data = button_type2; // Points to data part + button_type2 = XP_STRCHR(button_type2, '&'); + } else { + button_data = nil; + button_type2 = nil; + } + if (button_type2) + { + *button_type2++ = '\0'; + } + fdc.type = button_type; + fdc.data = button_data; + jf->formData[jf->formDataCount] = fdc; + jf->formDataCount++; + if (!button_type2 || (jf->formDataCount > formDataIndex)) + break; + else + button_type = button_type2; + + } + + for (x=0; x < jf->formDataCount; x++) + { + button_type = jf->formData[x].type; + jf->setLabel( button_data = jf->formData[x].data ); + + if (!JulianFormFactory::Buttons_Details_Type.CompareTo(button_type)) + { + julian_handle_moredetail(jf); + } else + if (!JulianFormFactory::Buttons_Accept_Type.CompareTo(button_type)) + { + julian_handle_accept(jf, Attendee::STATUS_ACCEPTED); + } else + if (!JulianFormFactory::Buttons_Add_Type.CompareTo(button_type)) + { + julian_handle_accept(jf, Attendee::STATUS_ACCEPTED); + } else + if (!JulianFormFactory::Buttons_Close_Type.CompareTo(button_type)) + { + julian_handle_close(jf); + } else + if (!JulianFormFactory::Buttons_Decline_Type.CompareTo(button_type)) + { + julian_handle_accept(jf, Attendee::STATUS_DECLINED); + } else + if (!JulianFormFactory::Buttons_Tentative_Type.CompareTo(button_type)) + { + julian_handle_accept(jf, Attendee::STATUS_TENTATIVE); + } else + if (!JulianFormFactory::Buttons_SendFB_Type.CompareTo(button_type)) + { + } else + if (!JulianFormFactory::Buttons_SendRefresh_Type.CompareTo(button_type)) + { + } else + if (!JulianFormFactory::Buttons_DelTo_Type.CompareTo(button_type)) + { + julian_handle_accept(jf, Attendee::STATUS_DELEGATED); + } + } + + PR_ExitMonitor(jf->my_monitor); +} + +/** +*** JulianForm Class +*** +*** This is the c++ interface to JulianFormFactory +*** +**/ + +JulianForm::JulianForm() +{ + mimedata = nil; + imipCal = nil; + jff = nil; + contextName = "Julian:More Details"; + formDataCount = 0; + my_monitor = PR_NewMonitor(); +} + +JulianForm::~JulianForm() +{ + if (FALSE && imipCal) + { + if (imipCal->getLog()) + delete imipCal->getLog(); + delete imipCal; + imipCal = nil; + } + + if (jff) + { + delete jff; + } + + if (my_monitor) PR_DestroyMonitor(my_monitor); +} + +XP_Bool +JulianForm::StartHTML() +{ + JulianString u; + UnicodeString ust; + if (imipCal == NULL) + { + ICalReader *tfr = (ICalReader *) new ICalStringReader(mimedata); + mimedata = nil; + if (tfr) + { + JLog * log = new JLog(); + if (!ms_bFoundNLSDataDirectory) + { + if (log != 0) + { + // TODO: finish + //log->log("ERROR: Can't find REQUIRED NLS Data Directory\n"); + } + } + imipCal = new NSCalendar(log); + ust = u.GetBuffer(); + if (imipCal) imipCal->parse(tfr, ust); + delete tfr; + } + + return TRUE; + } + + return FALSE; +} + +char* +JulianForm::getHTMLForm(XP_Bool Want_Detail, NET_StreamClass *this_stream) +{ + if (imipCal != nil) + { + if ((jff = new JulianFormFactory(*imipCal, *this, getCallbacks())) != nil) + { + htmlForm = ""; // Empty it + + jff->init(); + jff->getHTML(&htmlForm, this_stream, Want_Detail); + } + } + + char* t2 = (char*) XP_ALLOC(htmlForm.GetStrlen() + 1); + if (t2) strcpy(t2, htmlForm.GetBuffer()); + return t2; +} + +void +JulianForm::setMimeData(char *NewMimeData) +{ + if (NewMimeData) + { + mimedata = NewMimeData; + } +} + +char* +JulianForm::getComment() +{ + for (int32 x=0; x < formDataCount; x++) + { + if (!JulianFormFactory::CommentsFieldName.CompareTo(formData[x].type)) + { + (*getCallbacks()->PlusToSpace)(formData[x].data); + (*getCallbacks()->UnEscape) (formData[x].data); + return formData[x].data; + } + } + + return nil; +} + +char* +JulianForm::getDelTo() +{ + for (int32 x=0; x < formDataCount; x++) + { + char* temp; + + temp = PR_smprintf( "%s", formData[x].type); // Where is a pr_strcpy?? + if (temp) + { + (*getCallbacks()->PlusToSpace)(temp); + if (!XP_STRCMP(jff->Buttons_DelTo_Label.GetBuffer(), temp)) + { + (*getCallbacks()->PlusToSpace)(formData[x].data); + (*getCallbacks()->UnEscape) (formData[x].data); + return formData[x].data; + } + PR_DELETE(temp); + } + } + + return nil; +} + +void +julian_handle_close(JulianForm *jf) +{ + MWContext* cx = nil; + + if ((cx = jf->getContext()) != nil) + { + (*jf->getCallbacks()->DestroyWindow)(cx); + } +} + +void +julian_handle_moredetail(JulianForm *jf) +{ + MWContext* cx = nil; + char* newhtml = NULL; + NET_StreamClass* stream = nil; + URL_Struct* url = nil; + + if (jf->getCallbacks() == nil || + jf->getCallbacks()->CreateURLStruct == nil) + return; + + url = (*jf->getCallbacks()->CreateURLStruct)("internal_url://", NET_RESIZE_RELOAD); + if (url) + { + url->internal_url = TRUE; + (*jf->getCallbacks()->SACopy)(&(url->content_type), TEXT_HTML); + + // Look to see if we already made a window for this + if ((cx = jf->getContext()) != nil) + { + (*jf->getCallbacks()->RaiseWindow)(cx); + } + + // + // If the more details window isn't there, + // make one + // + if (!cx) + { + Chrome* customChrome = XP_NEW_ZAP(Chrome); + + /* make the window */ + if (customChrome) + { + customChrome->show_scrollbar = TRUE; /* TRUE to show scrollbars on window */ + customChrome->allow_resize = TRUE; /* TRUE to allow resize of windows */ + customChrome->allow_close = TRUE; /* TRUE to allow window to be closed */ + customChrome->disable_commands = TRUE; /* TRUE if user has set hot-keys / menus off */ + customChrome->restricted_target = TRUE; /* TRUE if window is off-limits for opening links into */ + } + + cx = (*jf->getCallbacks()->MakeNewWindow)((*jf->getCallbacks()->FindSomeContext)(), nil, jf->contextName, customChrome); + } + + if (cx) + { + static PA_InitData data; + + /* make a netlib stream to display in the window */ + data.output_func = jf->getCallbacks()->ProcessTag; + stream = (*jf->getCallbacks()->BeginParseMDL)(FO_CACHE_AND_VIEW_SOURCE | FO_CACHE_AND_PRESENT_INLINE, &data, url, cx); + if (stream) + { + jf->StartHTML(); + jf->getHTMLForm(TRUE, stream); + (*stream->complete) (stream->data_object); + XP_FREE(stream); + } + } + } +} + +void +julian_send_response_with_events(JulianString& subject, JulianPtrArray& recipients, JulianString& LoginName, JulianForm& jf, NSCalendar& calendar, JulianPtrArray * events) +{ + TransactionObject::ETxnErrorCode txnStatus; + TransactionObject* txnObj; + JulianPtrArray* capiModifiers = 0; + + if (jf.getCallbacks() == nil || + jf.getCallbacks()->FindSomeContext == nil) + return; + + MWContext* this_context = (*jf.getCallbacks()->FindSomeContext)(); + + capiModifiers = new JulianPtrArray(); + + if (capiModifiers) + { + UnicodeString usMeUri = LoginName.GetBuffer(); + URI meUri(usMeUri); + User* uFrom = new User(usMeUri, meUri.getName()); + char *capurl = NULL, *passwd = NULL; + UnicodeString uSubject; + UnicodeString uLoginName; + XP_Bool do_capi_login = FALSE; /* Default is not to ask for capi login info */ + + if (jf.getCallbacks()->BoolPref) + (*jf.getCallbacks()->BoolPref)("calendar.capi.enabled", &do_capi_login); + + if (do_capi_login && + Julian_GetLoginInfo(jf, this_context, &capurl, &passwd) > 0) + { + char* calUser = ""; + char* calHost = ""; + char* calNode = "10000"; + char* temp; + + // Skip pass "capi://", if it is there + if (XP_STRSTR(capurl, "://")) + { + capurl = XP_STRSTR(capurl, "://"); + capurl += 3; + } + + // Break apart the user and host:node parts + temp = XP_STRSTR(capurl, "/"); + if (temp) + { + calUser = temp; + *(calUser) = '\0'; + calUser++; + calHost = capurl; + } + + // Break apart the host and node parts + temp = XP_STRSTR(calHost, ":"); + if (temp) + { + calNode = temp; + *(calNode++) = '\0'; + } + + // Currently the URL login form is as follows: + // capi://host:node/login + // i.e. + // capi://calendar-1.mcom.com:10000/John Sun + // TODO: this may change. + + uFrom->setRealName(calUser); + uFrom->setCAPIInfo(calUser, passwd, calHost, calNode); + if (0) + { + if (passwd) XP_FREE(passwd); + if (capurl) XP_FREE(capurl); + } + } + + uSubject = subject.GetBuffer(); + uLoginName = LoginName.GetBuffer(); + + txnObj = TransactionObjectFactory::Make(calendar, *(events), + *uFrom, recipients, uSubject, *capiModifiers, + &jf, this_context, uLoginName); + if (txnObj != 0) + { + txnObj->execute(0, txnStatus); + delete txnObj; txnObj = 0; + } + + if (uFrom) delete uFrom; + + delete capiModifiers; + } + + // If more details windows, then close it + // Only if there were no problems + if (txnStatus == TransactionObject::TR_OK) + { + if (jf.getContext()) + { + julian_handle_close(&jf); + } + } +} + +void +julian_send_response(JulianString& subject, JulianPtrArray& recipients, JulianString& LoginName, JulianForm& jf, NSCalendar& calendar) +{ + julian_send_response_with_events(subject, recipients, LoginName, jf, calendar, calendar.getEvents()); +} + +void +julian_fill_in_delegatedToVector(char * deltonames, + JulianPtrArray * vDelegatedToFillIn) +{ + if (0 != vDelegatedToFillIn) + { + UnicodeString mailto = "MAILTO:"; + UnicodeString del_name; + char * nextname; + while (*deltonames) + { + del_name = mailto; + nextname = deltonames; + + while (nextname && *nextname && *nextname != ' ') + { + nextname++; + } + + if (*nextname) + { + *nextname = '\0'; + nextname++; + } + + del_name += deltonames; + vDelegatedToFillIn->Add(new UnicodeString(del_name)); + + if (!(*nextname)) + { + // Last one + break; + } + else + { + deltonames = nextname; + } + } + } +} + +XP_Bool +julian_events_comments_and_attendees_match(TimeBasedEvent * a, TimeBasedEvent * b) +{ + if (a != 0 && b != 0) + { + // comments must match and attendees must match + if (a->getComment() != 0 && b->getComment() == 0) + return FALSE; + if (a->getComment() == 0 && b->getComment() != 0) + return FALSE; + if (a->getComment() != 0 && b->getComment() != 0) + { + if (a->getComment()->GetSize() != b->getComment()->GetSize()) + return FALSE; + // only compare 1st comment in vector + if (a->getComment()->GetSize() > 0 && b->getComment()->GetSize() > 0) + { + ICalProperty * iua = 0; + ICalProperty * iub = 0; + UnicodeString ua, ub; + iua = (ICalProperty *) a->getComment()->GetAt(0); + iub = (ICalProperty *) b->getComment()->GetAt(0); + ua = *((UnicodeString *) iua->getValue()); + ub = *((UnicodeString *) iub->getValue()); + if (ua != ub) + return FALSE; + } + } + + if (a->getAttendees() != 0 && b->getAttendees() == 0) + return FALSE; + if (a->getAttendees() == 0 && b->getAttendees() != 0) + return FALSE; + if (a->getAttendees() != 0 && b->getAttendees() != 0) + { + if (a->getAttendees()->GetSize() != b->getAttendees()->GetSize()) + return FALSE; + t_int32 i; + Attendee * attA = 0; + Attendee * attB = 0; + for (i = 0; i < a->getAttendees()->GetSize(); i++) + { + attA = (Attendee *) a->getAttendees()->GetAt(i); + attB = (Attendee *) b->getAttendees()->GetAt(i); + if (attA->getName() != attB->getName()) + return FALSE; + if (attA->getStatus() != attB->getStatus()) + return FALSE; + } + } + return TRUE; + } + return FALSE; +} + +void +julian_add_new_event_to_send(JulianPtrArray * vvEventsToSend, TimeBasedEvent * eventToSend) +{ + + if (vvEventsToSend != 0) + { + XP_Bool bFound = FALSE; + int32 i; + JulianPtrArray * vEventsToSend = 0; + TimeBasedEvent * event; + for (i = 0; i < vvEventsToSend->GetSize(); i++) + { + vEventsToSend = (JulianPtrArray *) vvEventsToSend->GetAt(i); + if (vEventsToSend != 0 && vEventsToSend->GetSize() > 0) + { + event = (TimeBasedEvent *) vEventsToSend->GetAt(0); + if (julian_events_comments_and_attendees_match(event, eventToSend)) + { + vEventsToSend->Add(eventToSend); + bFound = TRUE; + break; + } + } + } + if (!bFound) + { + JulianPtrArray * evtVctrToAdd = new JulianPtrArray(); + if (evtVctrToAdd != 0) + { + evtVctrToAdd->Add(eventToSend); + vvEventsToSend->Add(evtVctrToAdd); + } + } + } +} + +void +#ifdef OSF1 +julian_handle_accept(JulianForm *jf, int newStatus) +#else +julian_handle_accept(JulianForm *jf, Attendee::STATUS newStatus) +#endif +{ + NSCalendar* imipCal = jf->getCalendar(); + ICalComponent* component; + JulianString orgName; + char* name = nil; + JulianString nameU; + JulianString subject = JulianString(jf->getLabel()); + UnicodeString uTemp; + int32 i; + int32 j; + int32 k; + + // this should be set to the logged in user + // TODO: make it efficient + // TRY to minimize number of calls to julian_send_response_with_events. + + if (jf->getCallbacks()->CopyCharPref) + (*jf->getCallbacks()->CopyCharPref)("mail.identity.useremail", &name); + if (name) + { + nameU = "MAILTO:"; + nameU += name; + } + + if (imipCal->getEvents() != 0) + { + XP_Bool firstTime = TRUE; + // process events to send + UnicodeString uName = nameU.GetBuffer(); + JulianPtrArray * vDelegatedTo = 0; + char * deltonames = 0; + char * cOrgName = 0; + char * cSummary = 0; + + XP_Bool bDontSend = FALSE; + JulianPtrArray * recipients = 0; + TimeBasedEvent * tbe; + // The overall strategy + // Create a vector of vector of events (vvEventsToReply). + // This vector is used to minimize the number of send_response calls (which sends email). + // Events with the same comments and attendees(status and name) are placed in the same bucket. + // Events in the same bucket are send in the same email message. + // Thus I minimize the number of sends response calls. + // + // Foreach event in calendar, + // setAttendeeStatus for this user to newStatus + // setComment from comment text-field + // setDTSTAMP + // if (first event in calendar) set subject to its summary. + // add event to vvEventsToReply + // Foreach vector in vvEventsToReply + // send REPLY message to ORGANIZER + // if (delegated status) + // send DELEGATE-REQUEST message to DELEGATEEs + // + JulianPtrArray * vvEventsToReply = new JulianPtrArray(); + + for (i = 0; i < imipCal->getEvents()->GetSize(); i++) + { + component = (ICalComponent *) imipCal->getEvents()->GetAt(i); + + if (component->GetType() == ICalComponent::ICAL_COMPONENT_VEVENT) + { + tbe = (TimeBasedEvent *) component; + // Set org + if (orgName.GetStrlen() == 0) + { + if (tbe->getOrganizer().size() > 0) + { + cOrgName = (tbe->getOrganizer()).toCString(""); + if (0 != cOrgName) + orgName = cOrgName; + } + } + if (newStatus == Attendee::STATUS_DELEGATED) + { + deltonames = jf->getDelTo(); + if ((0 != deltonames) && (XP_STRLEN(deltonames) > 0)) + { + vDelegatedTo = new JulianPtrArray(); + if (0 != vDelegatedTo) + julian_fill_in_delegatedToVector(deltonames, vDelegatedTo); + } + } + tbe->setAttendeeStatusInt(uName, newStatus, vDelegatedTo); + + if (jf->hasComment()) + { + tbe->setNewComments(jf->getComment()); + } + tbe->stamp(); + + if (i == 0) + { + // only print subject once and use first summary. + subject += JulianFormFactory::SubjectSep; + cSummary = (tbe->getSummary()).toCString(""); + subject += cSummary; + } + + julian_add_new_event_to_send(vvEventsToReply, tbe); + + if (vDelegatedTo != 0) + { + ICalComponent::deleteUnicodeStringVector(vDelegatedTo); + delete vDelegatedTo; vDelegatedTo = 0; + } + } + } + JulianPtrArray * vEventsToReply = 0; + JulianPtrArray * replyRecipients = new JulianPtrArray(); + t_int32 method = imipCal->getMethod(); + + // setup reply recipients to contain only organizer + if (replyRecipients != 0) + { + if (method != NSCalendar::METHOD_PUBLISH) + { + UnicodeString usOrgName = orgName.GetBuffer(); + URI orgUri(usOrgName); + User* uToOrg = new User(usOrgName, orgUri.getName()); + replyRecipients->Add(uToOrg); + } + } + for (i = 0; i < vvEventsToReply->GetSize(); i++) + { + vEventsToReply = (JulianPtrArray *) vvEventsToReply->GetAt(i); + + // send reply + recipients = replyRecipients; + imipCal->setMethod(NSCalendar::METHOD_REPLY); + julian_send_response_with_events(subject, *recipients, nameU, *jf, *imipCal, vEventsToReply); + recipients = 0; + + // send delegate request message if necessary + if (newStatus == Attendee::STATUS_DELEGATED && + method == NSCalendar::METHOD_REQUEST) + { + deltonames = jf->getDelTo(); + if ((0 != deltonames) && (XP_STRLEN(deltonames) > 0)) + { + vDelegatedTo = new JulianPtrArray(); + if (0 != vDelegatedTo) + julian_fill_in_delegatedToVector(deltonames, vDelegatedTo); + else + bDontSend = TRUE; + } + else + { + bDontSend = TRUE; + } + if (!bDontSend) + { + recipients = new JulianPtrArray(); + if (recipients != 0) + { + PR_ASSERT(vDelegatedTo != 0 && vDelegatedTo->GetSize() > 0); + User * userDelegate = 0; + for (j = 0; j < vDelegatedTo->GetSize(); j++) + { + uTemp = *((UnicodeString *) vDelegatedTo->GetAt(j)); + URI delUri(uTemp); + userDelegate = new User(uTemp, delUri.getName()); + for (k = 0; k < vEventsToReply->GetSize(); k++) + { + component = (ICalComponent *) vEventsToReply->GetAt(k); +#ifdef OSF1 + ((TimeBasedEvent *)component)->setAttendeeStatusInt(uTemp, 0); +#else + ((TimeBasedEvent *)component)->setAttendeeStatusInt(uTemp, Attendee::STATUS_NEEDSACTION); +#endif + } + recipients->Add(userDelegate); + } + imipCal->setMethod(NSCalendar::METHOD_REQUEST); + + julian_send_response_with_events(subject, *recipients, nameU, *jf, *imipCal, vEventsToReply); + + User::deleteUserVector(recipients); + delete recipients; recipients = 0; + } + } + if (vDelegatedTo != 0) + { + ICalComponent::deleteUnicodeStringVector(vDelegatedTo); + delete vDelegatedTo; vDelegatedTo = 0; + } + } + } + // delete allocated objects. + if (cOrgName != 0) + { + delete [] cOrgName; cOrgName = 0; + } + if (cSummary != 0) + { + delete [] cSummary; cSummary = 0; + } + if (0 != replyRecipients) + { + User::deleteUserVector(replyRecipients); + delete replyRecipients; replyRecipients = 0; + } + for (i = vvEventsToReply->GetSize() -1; i >= 0; i--) + { + vEventsToReply = (JulianPtrArray *) vvEventsToReply->GetAt(i); + ICalComponent::deleteICalComponentVector(vEventsToReply); + delete vEventsToReply; vEventsToReply = 0; + } + delete vvEventsToReply; vvEventsToReply = 0; + } + if (name) XP_FREE(name); +} + +void +Julian_ClearLoginInfo() +{ +} + +int +Julian_GetLoginInfo(JulianForm& jf, MWContext* context, char** url, char** password) { + static char* lastCalPwd = NULL; + char* defaultUrl; + int status = -2; + + if (jf.getCallbacks() && + jf.getCallbacks()->CopyCharPref) + status = (*jf.getCallbacks()->CopyCharPref)(julian_pref_name, &defaultUrl); + // -1 is pref isn't there, which will be a normal case for us + // Any other neg number is some other bad error so bail. + if (status < -1) return status; + + *url = defaultUrl; + *password = NULL; + + if (lastCalPwd != NULL) + { + *password = XP_STRDUP(lastCalPwd); + if (*password == NULL) return 0 /*MK_OUT_OF_MEMORY*/; + + return 1; + } + + if (!(*context->funcs->PromptUsernameAndPassword) + (context, +// XP_GetString(JULIAN_LOGIN_PROMPT), + "Enter capi url and password", + url, + password)) + { + *url = NULL; + *password = NULL; + status = -1; + } else { + if (jf.getCallbacks() && + jf.getCallbacks()->SetCharPref) + { + (*jf.getCallbacks()->SetCharPref)(julian_pref_name, *url); + } + lastCalPwd = XP_STRDUP(*password); + status = 1; + } + XP_FREE(defaultUrl); + return status; +} + diff --git a/calendar/modules/core/htmlform/src/formFactory.cpp b/calendar/modules/core/htmlform/src/formFactory.cpp new file mode 100644 index 00000000000..e4e9e9a24dd --- /dev/null +++ b/calendar/modules/core/htmlform/src/formFactory.cpp @@ -0,0 +1,2676 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +#include "jdefines.h" +#include "julnstr.h" +#include "nscal.h" +#include "keyword.h" + +#include "form.h" +#include "formFactory.h" + +#include "gregocal.h" +#include "time.h" +#include "smpdtfmt.h" +#include "simpletz.h" +#include "datetime.h" +#include "jutility.h" + +#ifndef MOZ_TREX +#include "allxpstr.h" +#endif + +JulianFormFactory::JulianFormFactory() +{ + firstCalendar = nil; + thisICalComp = nil; + serverICalComp = nil; + SetDetail(FALSE); + s = nil; + jf = nil; + ServerProxy = nil; + maxical = 0; + cb = nil; + + SlotsPerHour = 0; + displayTimeZone = FALSE; + scaleType = 0; + slotsacross = 0; + hoursToDisplay = 0; + state = Free_State; + new_state = Free_State; + count = 0; + TimeHour_HTML = nil; + default_tz = TimeZone::createDefault(); + p = nil; + fb = nil; + fbIndex = 0; + pIndex = 0; + pv = nil; + fbv = nil; + aref_count = 0; + aref2_count = 0; + outStream = nil; + + isEvent = FALSE; + isFreeBusy = FALSE; +} + +JulianFormFactory::JulianFormFactory(NSCalendar& imipCal, JulianServerProxy* jsp) +{ + firstCalendar = nil; + thisICalComp = nil; + serverICalComp = nil; + SetDetail(FALSE); + s = nil; + jf = nil; + ServerProxy = nil; + maxical = 0; + cb = nil; + + SlotsPerHour = 0; + displayTimeZone = FALSE; + scaleType = 0; + slotsacross = 0; + hoursToDisplay = 0; + state = Free_State; + new_state = Free_State; + count = 0; + TimeHour_HTML = nil; + default_tz = TimeZone::createDefault(); + p = nil; + fb = nil; + fbIndex = 0; + pIndex = 0; + pv = nil; + fbv = nil; + aref_count = 0; + aref2_count = 0; + outStream = nil; + + isEvent = FALSE; + isFreeBusy = FALSE; + + firstCalendar = &imipCal; + ServerProxy = jsp; +} + +JulianFormFactory::JulianFormFactory(NSCalendar& imipCal, JulianForm& hostForm, pJulian_Form_Callback_Struct callbacks) +{ + firstCalendar = nil; + thisICalComp = nil; + serverICalComp = nil; + SetDetail(FALSE); + s = nil; + jf = nil; + ServerProxy = nil; + maxical = 0; + cb = nil; + + SlotsPerHour = 0; + displayTimeZone = FALSE; + scaleType = 0; + slotsacross = 0; + hoursToDisplay = 0; + state = Free_State; + new_state = Free_State; + count = 0; + TimeHour_HTML = nil; + default_tz = TimeZone::createDefault(); + p = nil; + fb = nil; + fbIndex = 0; + pIndex = 0; + pv = nil; + fbv = nil; + aref_count = 0; + aref2_count = 0; + outStream = nil; + + isEvent = FALSE; + isFreeBusy = FALSE; + + firstCalendar = &imipCal; + jf = &hostForm; + cb = callbacks; +} + +JulianFormFactory::~JulianFormFactory() +{ + // if (default_tz) delete default_tz; + PR_FREEIF(TimeHour_HTML); + +#ifdef LIBJULIAN_USE_XPSTRS + if (cb && cb->GetString) + { + PR_FREEIF(error_Header_HTML); + PR_FREEIF(publish_Header_HTML); + PR_FREEIF(publishFB_Header_HTML); + PR_FREEIF(replyFB_Header_HTML); + PR_FREEIF(request_Header_HTML); + PR_FREEIF(request_FB_Header_HTML); + PR_FREEIF(request_D_FB_Header_HTML); + PR_FREEIF(eventreply_Header_HTML); + PR_FREEIF(eventcancel_Header_HTML); + PR_FREEIF(eventrefreshreg_Header_HTML); + PR_FREEIF(eventcounterprop_Header_HTML); + PR_FREEIF(eventdelinecounter_Header_HTML); + + PR_FREEIF(String_What); + PR_FREEIF(String_When); + PR_FREEIF(String_Location); + PR_FREEIF(String_Organizer); + PR_FREEIF(String_Status); + PR_FREEIF(String_Priority); + PR_FREEIF(String_Categories); + PR_FREEIF(String_Resources); + PR_FREEIF(String_Attachments); + PR_FREEIF(String_Alarms); + PR_FREEIF(String_Created); + PR_FREEIF(String_Last_Modified); + PR_FREEIF(String_Sent); + PR_FREEIF(String_UID); + } +#endif +} + + +XP_Bool +JulianFormFactory::getHTML(JulianString* OutString, NET_StreamClass *this_stream, XP_Bool want_detail) +{ + outStream = this_stream; + return getHTML(OutString, want_detail); +} + +/* +** getHTML +** +** Call after setting firstCalendar. It will produce an Unicode +** string with html that should be inserted into a real html file. +** On any errors an empty string is returened. +** +*/ +XP_Bool +JulianFormFactory::getHTML(JulianString* htmlstorage, XP_Bool want_detail) +{ +JulianString ny("Not Yet"); +JulianString im("Invalid method"); +int32 icalIndex = 0; // Index into venent or vfreebusy array +int32 icalMaxIndex; +char* temp = nil; +char* urlcallback = nil; + + // Set up the storage for the html + s = htmlstorage; + + // Return an empty string on any error. + // This case: firstCalendar isn't set. It's needed to + // find what vevents, freebusy etc to parse. + if (firstCalendar == nil) return TRUE; + + if(!jf->isFoundNLSDataDirectory()) + { + if (0 != firstCalendar->getLog()) + { + // TODO: need to move errorID and comment to XP-Resources + t_int32 errorID; + UnicodeString comment; + errorID = 123456789; + comment = "ERROR: Cannot find NLS Data Directory"; + firstCalendar->getLog()->logError(errorID, comment); + } + } + + JulianPtrArray * e = firstCalendar->getEvents(); + JulianPtrArray * f = firstCalendar->getVFreebusy(); + + // Look for only for one type of ICalComponent. + // Start with vEvents and work down from there. + // There is a bool for each ICalComponent class + // that is handled. + // If there isn't anything good here, set thisICalComp + // to nil. + if (e) + { + if ((maxical = icalMaxIndex = e->GetSize() - 1) >= 0) + isEvent = TRUE; + } else + if (f) + { + if ((maxical = icalMaxIndex = f->GetSize() - 1) >= 0) + isFreeBusy = TRUE; + } else + { + icalMaxIndex = 0; + thisICalComp = nil; + } + + SetDetail(want_detail); + + /* + ** To get callback to work + */ + if (cb && cb->callbackurl) + { + urlcallback = (*cb->callbackurl)((NET_CallbackURLFunc) (want_detail ? jf_detail_callback : jf_callback), (void *)jf); + jf->refcount++; + temp = PR_smprintf(Start_HTML, urlcallback); + } else + temp = Start_HTML; + doAddHTML(temp); + if (cb && cb->callbackurl && temp) + { + // delete temp; + PR_DELETE(temp); + } + + // In the case that the ical was so bad that there isn't any thing left + if (!isEvent && !isFreeBusy) + { + HandleError(); + doAddHTML( End_HTML ); + return TRUE; + } + + if (icalMaxIndex > 0) + { + doHeaderMuiltStart(); + } + + int32 loopcount = icalMaxIndex > 0 && detail ? 2 : 1; + for (int32 loopx = 0; loopx < loopcount; loopx++) + { + int32 ICAL_LoopCount = MIN(icalMaxIndex, jff_clip_events); + icalIndex = 0; + + while (icalIndex <= ICAL_LoopCount) + { + // thisICalComp needs to be set to something. It's a problem if it's nil. + if (isEvent) + { + thisICalComp = (VEvent *)e->GetAt(icalIndex++); + } else + if (isFreeBusy) + { + thisICalComp = (VFreebusy *)f->GetAt(icalIndex++); + } else + icalIndex++; + + // If in detail mode, check to see if there is a server version of this icalcomponent. + // Otherwise set it to nil to show that this is the first time this has been seen. + if (detail && ServerProxy) + { + serverICalComp = ServerProxy->getByUid(nil); + } else { + serverICalComp = nil; + } + + if (icalMaxIndex > 0 && loopx == 0) + { + doHeaderMuilt(); + } + + // Find the right html form based on the method + if ((icalMaxIndex > 0 && loopx == 1) || icalMaxIndex == 0) + switch (firstCalendar->getMethod()) + { + case NSCalendar::METHOD_PUBLISH: + if (isEvent) + { + HandlePublishVEvent(); + } + + if (isFreeBusy) + { + HandlePublishVFreeBusy(TRUE); + } + break; + + case NSCalendar::METHOD_REQUEST: + case NSCalendar::METHOD_ADD: + + if (isEvent) + { + HandleRequestVEvent(); + } + + if (isFreeBusy) + { + HandleRequestVFreeBusy(); + } + break; + + case NSCalendar::METHOD_REPLY: + + if (isEvent) + { + HandleEventReplyVEvent(); + } + + if (isFreeBusy) + { + HandlePublishVFreeBusy(FALSE); + } + + break; + + case NSCalendar::METHOD_CANCEL: + + if (isEvent) + { + HandleEventCancelVEvent(); + } + + break; + + case NSCalendar::METHOD_REFRESH: + + if (isEvent) + { + HandleEventRefreshRequestVEvent(); + } + + if (isFreeBusy) + { + doAddHTML ( ny ); + } + break; + + case NSCalendar::METHOD_COUNTER: + + if (isEvent) + { + HandleEventCounterPropVEvent(); + } + break; + + case NSCalendar::METHOD_DECLINECOUNTER: + + if (isEvent) + { + HandleDeclineCounterVEvent(); + } + break; + + case NSCalendar::METHOD_INVALID: + default: + doAddHTML ( im ); + break; + } + } + + if (icalMaxIndex > 1) + { + doHeaderMuiltEnd(); + doAddGroupButton(doCreateButton(Buttons_Accept_Type, Buttons_Accept_Label)); + if (!detail) + { + doAddGroupButton(doCreateButton(Buttons_Details_Type, Buttons_Details_Label)); + } + } + } + + doAddHTML( End_HTML ); + flush_stream(); + + return TRUE; +} + +int32 +JulianFormFactory::flush_stream() +{ + int32 ret = 0; + + if (outStream && (s->GetStrlen() > 0)) + { + ret = (*(outStream)->put_block)(outStream->data_object, s->GetBuffer(), s->GetStrlen()); + *s = ""; // empty it. + } + + return ret; +} + +void +JulianFormFactory::doHeaderMuiltStart() +{ + char* m1 = nil; + + if (MuiltEvent.GetStrlen() > 0) + { + JulianString tempstring; + + doHeader(MuiltEvent_Header_HTML); + + doAddHTML( nbsp ); + + // Get This messages contains 2 events + m1 = PR_smprintf(MuiltEvent.GetBuffer(), maxical + 1); + + doAddHTML( m1 ); + PR_FREEIF( m1 ); + + if (maxical + 1 > jff_clip_events) + { + m1 = PR_smprintf(TooManyEvents.GetBuffer(), jff_clip_events); + if (m1) + { + doAddHTML( Line_Break_HTML ); + doAddHTML( nbsp ); + doAddHTML( m1 ); + PR_DELETE( m1 ); + } + } + + doAddHTML( Line_3_HTML ); + + doAddHTML( Props_Head_HTML ); + + doAddHTML( FBT_NewRow_HTML ); + doAddHTML( Cell_Start_HTML ); + doAddHTML(*doFont(*doItalic(*doBold(WhenStr , &tempstring ) , &tempstring ) , &tempstring) ); + doAddHTML( Cell_End_HTML ); + + doAddHTML( Cell_Start_HTML ); + doFont(*doItalic(*doBold(WhatStr , &tempstring ) , &tempstring ) , &tempstring ); + doAddHTML( nbsp ); + doAddHTML(tempstring); + doAddHTML( Cell_End_HTML ); + doAddHTML( FBT_EndRow_HTML ); + + } +} + +void +JulianFormFactory::doHeaderMuiltEnd() +{ + doAddHTML( FBT_End_HTML ); +} + + +/* +** Muilable icalcomponents. +*/ +void +JulianFormFactory::doHeaderMuilt() +{ + JulianString tempstring; + char* dtstart_string = "%B"; + char* summary_string = "%S"; + char a_temp[256] = ""; + char a_end_temp[256] = ""; + char* temp; + UnicodeString u; + + doAddHTML( FBT_NewRow_HTML ); + + doAddHTML( Cell_Start_HTML ); + + doAddHTML( Font_Fixed_Start_HTML ); + doPreProcessing(dtstart_string); + doAddHTML( Font_Fixed_End_HTML ); + + doAddHTML( Cell_End_HTML ); + + doAddHTML( Cell_Start_HTML ); + doAddHTML( Start_BIG_Font ); + + if (detail) + { + temp = PR_smprintf(a_temp, aref2_count++); + doAddHTML(temp); + PR_FREEIF(temp); + } + u = summary_string; + uTemp = temp = thisICalComp->toStringFmt(u).toCString(""); + PR_FREEIF(temp); + doAddHTML(uTemp); + if (detail) + { + doAddHTML(a_end_temp); + } + + doAddHTML( End_Font ); + + doAddHTML( Cell_End_HTML ); + + doAddHTML( FBT_EndRow_HTML ); +} + +/* +** Cool "When:" formating. +*/ +void +JulianFormFactory::doPreProcessing(char* icalpropstr) +{ +t_int32 ICalPropChar = (t_int32)(icalpropstr[(TextOffset)1]); + + if (ICalPropChar == ms_cDTStart) + { + DateTime start, end; + XP_Bool allday = isEvent ? (XP_Bool)((TimeBasedEvent *)thisICalComp)->isAllDayEvent() : FALSE; + JulianString temp_js; + + if (isEvent) + { + start = ((VEvent *)thisICalComp)->getDTStart(); + end = ((VEvent *)thisICalComp)->getDTEnd(); + } else + if (isFreeBusy) + { + start = ((VFreebusy *)thisICalComp)->getDTStart(); + end = ((VFreebusy *)thisICalComp)->getDTEnd(); + } + + temp_js = JulianString(icalpropstr); + doPreProcessingDateTime(temp_js, allday, start, end, *thisICalComp); + } else + if (ICalPropChar == ms_cAttendees) + { + doPreProcessingAttend(*thisICalComp); + } else + if ( ICalPropChar == ms_cOrganizer) + { + doPreProcessingOrganizer(*thisICalComp); + } +} + +void +JulianFormFactory::doPreProcessingAttend(ICalComponent& ic) +{ +XP_Bool lastOne = FALSE; +char* temp; +char* uni_comma = ","; +char* uni_AttendName = "%(^N)v"; +char* attendStatusStr = "%(^S)v"; +UnicodeString usAttendStatusStr = attendStatusStr; +UnicodeString usUni_AttendName = uni_AttendName; +char* attendStatus = (ic.toStringFmt(usAttendStatusStr)).toCString(""); +char* attendNames = (ic.toStringFmt(usUni_AttendName)).toCString(""); +UnicodeString usAttendStatus = attendStatus; +UnicodeString usAttendNames = attendNames; + +UnicodeString tempString; +JulianString tempString2; +JulianString tempString3; +JulianString tempStringA; +JulianString tempStringB; +UnicodeString tempString4; +TextOffset status_start = 0, + status_end = 0, + name_start = 0, + name_end = 0; + + // Check that there is something in the attendNames string. + + if (XP_STRLEN(attendNames) == 0) + { + // Should not get here, but just in case don't loop + lastOne = TRUE; + } + + while (!lastOne) + { + status_end = JulianString(attendStatus).IndexOf(uni_comma, (int32)status_start); + name_end = JulianString(attendNames).IndexOf(uni_comma, (int32)name_start); + + // Hit the last name yet? + if (status_end == -1) + { + lastOne = TRUE; + status_end = XP_STRLEN(attendStatus); + name_end = XP_STRLEN(attendNames); + } + + // Add a comma after each name execpt for the last name. + if (status_start > 0) + { + doAddHTML( uni_comma ); + doAddHTML( nbsp ); + } + + usAttendStatus.extractBetween(status_start, status_end, tempString); + if (tempString == JulianKeyword::Instance()->ms_sACCEPTED ) + { + doAddHTML( Accepted_Gif_HTML ); + } else + if (tempString == JulianKeyword::Instance()->ms_sDECLINED ) + { + doAddHTML( Declined_Gif_HTML ); + } else + if (tempString == JulianKeyword::Instance()->ms_sDELEGATED ) + { + doAddHTML( Delegated_Gif_HTML ); + } else + if (tempString == JulianKeyword::Instance()->ms_sVCALNEEDSACTION ) + { + doAddHTML( NeedsAction_Gif_HTML ); + } else + doAddHTML( Question_Gif_HTML ); + + // Get the email address mailto:xxx@yyy.com + // Convert to xxx@yyy.com  + usAttendNames.extractBetween(name_start, name_end, tempString); + tempString.extractBetween(7, tempString.size(), tempString4); + tempStringA = JulianString(temp = tempString4.toCString("")); + if (temp) delete temp; + tempStringB = JulianString(temp = tempString.toCString("")); + if (temp) delete temp; + doAddHTML( + doARef( + *doFont( tempStringA, &tempString2 ), + tempStringB, + &tempString3 ) + ); + + status_start = status_end + 1; + name_start = name_end + 1; + + // Set it to an empty string + tempString2 = ""; + tempString3 = ""; + } + + if (attendNames) delete attendStatus; + if (attendNames) delete attendNames; +} + +void +JulianFormFactory::doPreProcessingOrganizer(ICalComponent& ic) +{ +char* uni_OrgName = "%(^N)J"; +UnicodeString usUni_OrgName = uni_OrgName; +char* temp = ic.toStringFmt(usUni_OrgName).toCString(""); +JulianString attendNames = temp; +JulianString tempString; +JulianString tempString2; +JulianString tempString3; +JulianString tempString4; +TextOffset name_start = 0, + name_end = 0; + + PR_FREEIF(temp); + name_end = attendNames.GetStrlen(); + + // Get the email address mailto:xxx@yyy.com + // Convert to xxx@yyy.com  + tempString = attendNames(name_start, name_end); + tempString4 = tempString(7, tempString.GetStrlen()); + doAddHTML( + doARef( + *doFont( tempString4, &tempString2 ), + tempString, + &tempString3 ) + ); +} + +JulianString* +JulianFormFactory::doARef(JulianString& refText, JulianString& refTarget, JulianString* outputString) +{ + JulianString *Saved_S = s; + s = outputString; + + doAddHTML( Aref_Start_HTML ); + doAddHTML( refTarget ); + doAddHTML( Aref_End_HTML ); + doAddHTML( refText ); + doAddHTML( ArefTag_End_HTML ); + + s = Saved_S; + + return outputString; +} + + +#if 0 +JulianString* +JulianFormFactory::doFontFixed(JulianString& fontText, JulianString* outputString) +{ + JulianString *Saved_S = s; + JulianString out1; + s = &out1; + + doAddHTML( Font_Fixed_Start_HTML ); + doAddHTML( fontText ); + doAddHTML( Font_Fixed_End_HTML ); + + s = Saved_S; + *outputString = out1; + + return outputString; +} +#endif + +JulianString* +JulianFormFactory::doFont(JulianString& fontText, JulianString* outputString) +{ + JulianString *Saved_S = s; + JulianString out1; + s = &out1; + + doAddHTML( Start_Font ); + doAddHTML( fontText ); + doAddHTML( End_Font ); + + s = Saved_S; + *outputString = out1; + + return outputString; +} + +JulianString* +JulianFormFactory::doItalic(JulianString& ItalicText, JulianString* outputString) +{ + JulianString *Saved_S = s; + JulianString out1; + s = &out1; + + doAddHTML( Italic_Start_HTML ); + doAddHTML( ItalicText ); + doAddHTML( Italic_End_HTML ); + + s = Saved_S; + *outputString = out1; + + return outputString; +} + +JulianString* +JulianFormFactory::doBold(JulianString& BoldText, JulianString* outputString) +{ + JulianString *Saved_S = s; + JulianString out1; + s = &out1; + + doAddHTML( Bold_Start_HTML ); + doAddHTML( BoldText ); + doAddHTML( Bold_End_HTML ); + + s = Saved_S; + *outputString = out1; + + return outputString; +} + +JulianString* +JulianFormFactory::doBold(char* BoldText, JulianString* outputString) +{ + JulianString *Saved_S = s; + JulianString out1; + s = &out1; + + doAddHTML( Bold_Start_HTML ); + doAddHTML( BoldText ); + doAddHTML( Bold_End_HTML ); + + s = Saved_S; + *outputString = out1; + + return outputString; +} + +void +JulianFormFactory::doPreProcessingDateTime(JulianString& icalpropstr, XP_Bool allday, DateTime &start, DateTime &end, ICalComponent &ic) +{ + JulianString dtstartI = "%B"; + UnicodeString dtstart = "%(EEE MMM dd, yyyy hh:mm a)B"; + UnicodeString dtend = "%(EEE MMM dd, yyyy hh:mm a z)e"; + + UnicodeString dtstartSD = "%(EEE MMM dd, yyyy hh:mm a)B - "; + UnicodeString dtstartAD = "%(EEE MMM dd, yyyy)B - "; + UnicodeString dtstartMD = "%(EEE MMM dd, yyyy hh:mm a z)B"; + UnicodeString dtendSD = "%(hh:mm a z)e"; + UnicodeString dtdurSD = " ( %D )"; + UnicodeString endstr = ic.toStringFmt(dtend); + UnicodeString uTemp; + + // All Day event. May spane more then the one day + // Display as May 01, 1997 ( Day Event ) + // Note: fix this up for a single day event and for more then one day event + if (allday) + { + uTemp = ic.toStringFmt(dtstartAD); + doAddHTML(uTemp); + + doAddHTML( Text_AllDay ); + } else + // Moment in time date, ie dtstart == dtend? + // Display as Begins on May 01, 1997 12:00 pm + if (start == end) + { + doAddHTML( Text_StartOn ); + + uTemp = ic.toStringFmt(dtstartMD); + doAddHTML(uTemp); + doAddHTML(nbsp); + + } else + // Both dates on the same day? + // Display as May 01, 1997 12:00 pm - 3:00 pm ( 3 Hours ) + if (start.sameDMY(&end, default_tz)) + { + uTemp = ic.toStringFmt(dtstartSD); + doAddHTML(uTemp); + + uTemp = ic.toStringFmt(dtendSD); + doAddHTML(uTemp); + + uTemp = ic.toStringFmt(dtdurSD); + doAddHTML(uTemp); + } + + // Default Case. + // Display both dates in full. ie May 01, 1997 12:00 pm - May 02, 1997 2:00 pm + else + if (icalpropstr.IndexOf(dtstartI.GetBuffer(), (int32)0) >= 0) + { + + uTemp = ic.toStringFmt(dtstart); + doAddHTML(uTemp); + + if (endstr.size() > 6) + { + doAddHTML( Text_To ); + doAddHTML( endstr ); + } + } +} + +/* +** +** Assumed that serverICalComp is good. +*/ +void +JulianFormFactory::doDifferenceProcessingAttendees() +{ +XP_Bool lastOne = FALSE, + need_comma = FALSE; +JulianString uni_comma = ","; +char* uni_x = "%(^N)v"; +UnicodeString usUni_x = uni_x; +char* temp; +char* temp1; +JulianString NewAttendNames = temp = thisICalComp->toStringFmt(usUni_x).toCString(""); +JulianString OldAttendNames = temp1 = serverICalComp->toStringFmt(usUni_x).toCString(""); +JulianString tempString; +JulianString tempString2; +JulianString tempString3; +JulianString tempString4; +TextOffset new_name_start = 0, + new_name_end = 0, + old_name_start = 0, + old_name_end = 0; + +// Work and the "Added" section. These are email address that are in thisICalComp and +// not in serverICalComp. The general idea here is to march down the attends in NewAttendNames +// and see if they are in OldAttendNames + + doAddHTML( Props_HTML_Before_Label ); + doAddHTML( Start_Font ); + doAddHTML( Italic_Start_HTML ); + doAddHTML( " Added: " ); + doAddHTML( Italic_End_HTML ); + doAddHTML( End_Font ); + doAddHTML( Props_HTML_After_Label ); + + while (!lastOne) + { + new_name_end = NewAttendNames.IndexOf(uni_comma.GetBuffer(), (int32)new_name_start); + + // Hit the last name yet? + if (new_name_end == -1) + { + lastOne = TRUE; + new_name_end = NewAttendNames.GetStrlen(); + } + + // Add a comma after each name execpt for the last name. + if (need_comma) + { + doAddHTML( uni_comma ); + doAddHTML( nbsp ); + need_comma = FALSE; + } + + // Get the email address mailto:xxx@yyy.com + // Convert to xxx@yyy.com  + tempString = NewAttendNames(new_name_start, new_name_end); // Get "mailto:xxx@yyy.com" + tempString4 = tempString(7, tempString.GetStrlen()); // Remove "mailto:" + + // tempString4 now holds "xxx@yyy.com". See if it is in OldAttendNames + if (OldAttendNames.IndexOf(tempString4.GetBuffer(), (int32)0) == -1) + { + // Not there so this must be a new one. Format it for output + doAddHTML( doARef( *doFont( tempString4, &tempString2 ), tempString, &tempString3 ) ); + need_comma = TRUE; + } + + new_name_start = new_name_end + 1; + + // Set it to an empty string + tempString2 = ""; + tempString3 = ""; + tempString4 = ""; + } + doAddHTML( Props_HTML_After_Data ); + +// Work and the "Removed" section. These are email address that are in thisICalComp and +// not in serverICalComp. The general idea here is to march down the attends in NewAttendNames +// and see if they are in OldAttendNames + + doAddHTML( Props_HTML_Before_Label ); + doAddHTML( Start_Font ); + doAddHTML( Italic_Start_HTML ); + doAddHTML( " Removed: " ); + doAddHTML( Italic_End_HTML ); + doAddHTML( End_Font ); + doAddHTML( Props_HTML_After_Label ); + + need_comma = lastOne = FALSE; + new_name_start = 0; + while (!lastOne) + { + new_name_end = OldAttendNames.IndexOf(uni_comma.GetBuffer(), (int32)new_name_start); + + // Hit the last name yet? + if (new_name_end == -1) + { + lastOne = TRUE; + new_name_end = OldAttendNames.GetStrlen(); + } + + // Add a comma after each name execpt for the last name. + if (need_comma) + { + doAddHTML( uni_comma ); + doAddHTML( nbsp ); + need_comma = FALSE; + } + + // Get the email address mailto:xxx@yyy.com + // Convert to xxx@yyy.com  + tempString = OldAttendNames(new_name_start, new_name_end); // Get "mailto:xxx@yyy.com" + tempString4 = tempString(7, tempString.GetStrlen()); // Remove "mailto:" + + // tempString4 now holds "xxx@yyy.com". See if it is in OldAttendNames + if (NewAttendNames.IndexOf(tempString4.GetBuffer(), (int32)0) == -1) + { + // Not there so this must be a removed one. Format it for output + doAddHTML( doARef( *doFont( tempString4, &tempString2 ), tempString, &tempString3 ) ); + } + + new_name_start = new_name_end + 1; + + // Set it to an empty string + tempString2 = ""; + tempString3 = ""; + tempString4 = ""; + } + doAddHTML( Props_HTML_After_Data ); + + PR_FREEIF(temp); + PR_FREEIF(temp1); +} + +/* +** Cool diff formating. +*/ +void +JulianFormFactory::doDifferenceProcessing(JulianString icalpropstr) +{ + // First look to see if there is a server version of this. + // Also diff is only useful for events. + if (isEvent && serverICalComp) + { + JulianString itipstr; + JulianString serverstr; + + if (isPreProcessed(icalpropstr)) + { + t_int32 ICalPropChar = (t_int32)((icalpropstr.GetBuffer())[(TextOffset)1]); + + // Attendees are different. Look at each one and see who has been add or deleted. + // Right now do not show anything if just their role has changed. + if (ICalPropChar == ms_cAttendees) + { + doDifferenceProcessingAttendees(); + } else + // Normal case is just diff the string that would be printed. + { + JulianString* Saved_S = s; + ICalComponent* IC_Saved = thisICalComp; + + s = &itipstr; + // Set itipstr to the formated version + doPreProcessing(icalpropstr.GetBuffer()); + + s = &serverstr; + thisICalComp = serverICalComp; + // Set serverstr to the formated version + doPreProcessing(icalpropstr.GetBuffer()); + thisICalComp = IC_Saved; + + s = Saved_S; + } + } else { + char* temp; + UnicodeString usIcalPropStr = icalpropstr.GetBuffer(); + itipstr = JulianString(temp = (thisICalComp->toStringFmt(usIcalPropStr)).toCString("")); + PR_FREEIF(temp); + serverstr = JulianString(temp = (serverICalComp->toStringFmt(usIcalPropStr)).toCString("")); + PR_FREEIF(temp); + } + + if (itipstr != serverstr) + { + doAddHTML( Props_HTML_Before_Label ); + doAddHTML( Start_Font ); + doAddHTML( Italic_Start_HTML ); + doAddHTML( Text_Was ); + doAddHTML( Italic_End_HTML ); + doAddHTML( End_Font ); + + doAddHTML( Props_HTML_After_Label ); + + doAddHTML( Start_Font ); + doAddHTML( Italic_Start_HTML ); + doAddHTML( serverstr ); + doAddHTML( Italic_End_HTML ); + doAddHTML( End_Font ); + doAddHTML( Props_HTML_After_Data ); + } + } +} + +void +JulianFormFactory::doProps(int32 labelCount, JulianString labels[], int32 dataCount, JulianString data[]) +{ + int32 x; + UnicodeString uDataX; + JulianString temp_js; + char* temp; + + doAddHTML( Props_Head_HTML ); + + for (x = 0; x < dataCount; x ++) + { + uDataX = data[x].GetBuffer(); + uTemp = JulianString(temp = (thisICalComp->toStringFmt(uDataX)).toCString("")); + PR_FREEIF(temp); + if (uTemp.GetStrlen() > 0 || isPreProcessed(data[x])) + { + doAddHTML( Props_HTML_Before_Label ); + doAddHTML( Start_Font ); + if (x < labelCount) + doAddHTML( labels[x] ); + else + doAddHTML( Props_HTML_Empty_Label ); + doAddHTML( End_Font ); + doAddHTML( Props_HTML_After_Label ); + doAddHTML( Start_Font ); + temp_js = JulianString(data[x]); + isPreProcessed(temp_js) ? doPreProcessing(data[x].GetBuffer()) : doAddHTML(uTemp); + doAddHTML( End_Font ); + doAddHTML( Props_HTML_After_Data ); + doDifferenceProcessing(data[x]); + } + } +} + +void +JulianFormFactory::doHeader(JulianString HeaderText) +{ + doAddHTML( General_Header_Start_HTML ); + doAddHTML( Start_Font ); + doAddHTML( HeaderText ); + doAddHTML( End_Font ); + + if (detail) + { + char* temp; + char a_temp[256] = ""; + char a_end_temp[256] = ""; + + temp = PR_smprintf(a_temp, aref_count++); + doAddHTML(temp); + doAddHTML(a_end_temp); + doAddHTML( General_Header_Status_HTML ); + doAddHTML( Start_Font ); + // Only can handle new or not new + doAddHTML( serverICalComp ? "(Update)" : "(New)" ); + doAddHTML( End_Font ); + PR_FREEIF(temp); + } + + doAddHTML( General_Header_End_HTML ); +} + +void +JulianFormFactory::doClose() +{ + if (isDetail()) + { + doAddHTML( Head2_HTML ); + doAddButton(doCreateButton(Buttons_Close_Type, Buttons_Close_Label)); + } +} + +char* +JulianFormFactory::getJulianErrorString(int32 ErrorNum) +{ + JulianString* errortext = nil; + + if ((t_int32)ErrorNum == JulianLogErrorMessage::Instance()->ms_iDTEndBeforeDTStart) errortext = &error1; else + if ((t_int32)ErrorNum == JulianLogErrorMessage::Instance()->ms_iInvalidPromptValue) errortext = &error2; else + if ((t_int32)ErrorNum == JulianLogErrorMessage::Instance()->ms_iInvalidTimeStringError) errortext = &error3; else + if ((t_int32)ErrorNum == JulianLogErrorMessage::Instance()->ms_iInvalidRecurrenceError) errortext = &error4; else + if ((t_int32)ErrorNum == JulianLogErrorMessage::Instance()->ms_iInvalidPropertyValue) errortext = &error5; else + if ((t_int32)ErrorNum == JulianLogErrorMessage::Instance()->ms_iInvalidPropertyName) errortext = &error6; else + if ((t_int32)ErrorNum == JulianLogErrorMessage::Instance()->ms_iInvalidParameterName) errortext = &error7; else + errortext = &error0; + + return errortext->GetBuffer(); +} + +void +JulianFormFactory::doStatus() +{ + XP_Bool startSpacer = TRUE; + int32 x = 0; + JulianPtrArray * errors = 0; + char * cjst = 0; + JulianString jst3; + JulianString jst4; + //JulianPtrArray *errorLog = firstCalendar->getLog()->GetErrorVector(); + + // Start with status items that only can happen in detail mode. + // Only suport vevents. + if (isDetail() && isEvent) + { + JulianString temp_js = JulianString(EventNote); + JulianString temp_js1 = JulianString(EventInSchedule); + JulianString temp_js2 = JulianString(EventNotInSchedule); + + // Add event allready on Calendar Server or not. + doSingleTableLine(temp_js, serverICalComp ? temp_js1 : temp_js2, startSpacer); + + // See if it's not on the server, see if it overlaps any other event + // doSingleTableLine(&EventConflict, &EventTest, FALSE); + startSpacer = FALSE; + } + + if (!jf->isFoundNLSDataDirectory()) + { + // XXX: bad hack + t_int32 errorID; + JulianString u; + jst3 = EventError; + errorID = 123456789; + u = "ERROR: Cannot find NLS Data Directory"; + doSingleTableLine(jst3, u, TRUE); + } + errors = thisICalComp ? firstCalendar->getLogVector(thisICalComp) : firstCalendar->getLogVector(); + if (errors != nil) + { + JulianLogError * element; + int32 error_max = MIN(5, errors->GetSize()); + int32 lost_errors = errors->GetSize() - error_max; + JulianString u; + + for (x=0; x < error_max; x++) + { + char* errorprefix; + + element = (JulianLogError *)errors->GetAt(x); + u = ""; + + cjst = element->getShortReturnStatusCode().toCString(""); + if (cjst != 0) + { + u += cjst; + delete [] cjst; cjst = 0; + } + u += " "; + if ((errorprefix = getJulianErrorString(element->getErrorID())) != nil) + { + u += errorprefix; + u += ": "; + } + u += "("; + cjst = element->getOffendingData().toCString(""); + if (cjst != 0) + { + u += cjst; + delete [] cjst; cjst = 0; + } + u += ")"; + jst3 = EventError; + doSingleTableLine(jst3, u, startSpacer); + startSpacer = FALSE; + } + + if (lost_errors > 0) + { + char* temp = PR_smprintf(MoreErrors.GetBuffer(), lost_errors); + + if (temp) + { + jst3 = EventError; + jst4 = temp; + doSingleTableLine(jst3, jst4, startSpacer); + PR_DELETE(temp); + } + } + } + +} + +void +JulianFormFactory::doSingleTableLine(JulianString& labelString, JulianString& dataString, XP_Bool addSpacer) +{ + if (addSpacer) doAddHTML( Head2_HTML ); + doAddHTML( Props_HTML_Before_Label ); + if (labelString.GetStrlen() == 0) // Is empty? + { + doAddHTML( Props_HTML_Empty_Label ); + } else { + doAddHTML( Start_Font ); + doAddHTML( labelString ); + doAddHTML( End_Font ); + } + doAddHTML( Props_HTML_After_Label ); + doAddHTML( Start_Font ); + doAddHTML( dataString ); + doAddHTML( End_Font ); + doAddHTML( Props_HTML_After_Data ); +} + +void +JulianFormFactory::doCommentText() +{ + // Comments Field + doAddHTML( Head2_HTML ); + doAddHTML( Text_Label_Start_HTML ); + doAddHTML( Start_Font ); + doAddHTML( Text_Label ); + doAddHTML( End_Font ); + doAddHTML( Text_Label_End_HTML ); + doAddHTML( Text_Field_HTML ); +} + +// +// To add a group button on it's own line +void +JulianFormFactory::doAddGroupButton(JulianString GroupButton_HTML) +{ + doAddHTML( Start_Font ); + doAddHTML( GroupButton_HTML ); + doAddHTML( End_Font ); +} + +// +// To add a single button on it's own line +void +JulianFormFactory::doAddButton(JulianString SingleButton_HTML) +{ + doAddHTML( Buttons_GroupSingleStart_HTML ); + doAddGroupButton(SingleButton_HTML); + doAddHTML( Buttons_GroupSingleEnd_HTML ); +} + +// +// To add a single button on it's own line +JulianString +JulianFormFactory::doCreateButton(JulianString InputType, JulianString ButtonName, XP_Bool addTextField) +{ + JulianString t = ""; +// char* url_string = cb ? cb->callbackurl( (void *)nil, InputType->toCString("")) : ""; + char* url_string = ""; + char* temp = nil; + char* temp2 = nil; + + if (addTextField && ButtonName.GetStrlen()) + { + char* temp3 = ButtonName.GetBuffer(); + + if (temp3) + { + temp2 = PR_smprintf(Buttons_Text_End_HTML, temp3); + } + } + + temp = PR_smprintf(Buttons_Single_Start_HTML, url_string); + t += Start_Font; + if (temp) t += temp; + t += InputType; + t += Buttons_Single_Mid_HTML; + t += ButtonName; + t += addTextField ? temp2 : Buttons_Single_End_HTML; + t += End_Font; + PR_FREEIF(temp); + PR_FREEIF(temp2); + + return t; +} + +void +JulianFormFactory::addLegend() +{ + doAddHTML(FBT_Legend_Start_HTML); + + doAddHTML(FBT_Legend_Text1_HTML); + doAddHTML(Start_Font); + doAddHTML(FBT_Legend_Title); + doAddHTML(End_Font); + doAddHTML(FBT_Legend_TextEnd_HTML); + + doAddHTML(FBT_Legend_Text2_HTML); + doAddHTML(Start_Font); + doAddHTML(FBT_Legend_Free); + doAddHTML(End_Font); + doAddHTML(FBT_Legend_TextEnd_HTML); + + doAddHTML(FBT_Legend_Text3_HTML); + doAddHTML(Start_Font); + doAddHTML(FBT_Legend_Busy); + doAddHTML(End_Font); + doAddHTML(FBT_Legend_TextEnd_HTML); + + doAddHTML(FBT_Legend_Text4_HTML); + doAddHTML(Start_Font); + doAddHTML(FBT_Legend_Unknown); + doAddHTML(End_Font); + doAddHTML(FBT_Legend_TextEnd_HTML); + + doAddHTML(FBT_Legend_Text5_HTML); + doAddHTML(Start_Font); + doAddHTML(FBT_Legend_xparam); + doAddHTML(End_Font); + doAddHTML(FBT_Legend_TextEnd_HTML); + + doAddHTML(FBT_Legend_End_HTML); +} + +void +JulianFormFactory::addTimeZone() +{ + if (displayTimeZone) + { + doAddHTML( Start_Font ); + doAddHTML(FBT_TimeHead_HTML); + doAddHTML(tz); + doAddHTML(FBT_TimeHeadEnd_HTML); + doAddHTML( End_Font ); + doAddHTML( nbsp ); + } else + doAddHTML( nbsp ); +} + +void +JulianFormFactory::addMajorScale() +{ + int32 x; + char ss[10]; + UnicodeString usTemp; + switch (scaleType) + { + case 1: // Days 1 to 31 + doAddHTML(FBT_TDOffsetCell_HTML); + for (x = 1; x < 32; x++) + { + + sprintf(ss, "%d", x); + doAddHTML(TimeHour_HTML); + doAddHTML(Start_Font); + doAddHTML(FBT_TD_HourColor_HTML); + if (x < 10) doAddHTML(nbsp); + doAddHTML(ss); + doAddHTML(FBT_TD_HourColorEnd_HTML); + doAddHTML(End_Font); + doAddHTML(FBT_TimeHourEnd_HTML); + } + break; + + case 2: + for (x = start_hour; x < end_hour; x++) + { + int32 y = (x == 0) ? 12 : (x > 12) ? (x - 12) : (x); // Translate midnight to 12, convert 24h to 12h + + sprintf(ss, "%d", y); + doAddHTML(TimeHour_HTML); + doAddHTML(Start_Font); + doAddHTML(FBT_TD_HourColor_HTML); + doAddHTML(ss); + switch (x) + { + case 0: doAddHTML(FBT_AM); break; + case 12: doAddHTML(FBT_PM); break; + default: + if ( x == start_hour) + { + char* temps = " a"; + char* temp; + usTemp = temps; + uTemp = JulianString(temp = (start.strftime(usTemp)).toCString("")); + PR_FREEIF(temp); + doAddHTML(uTemp); + }; + } + doAddHTML(FBT_TD_HourColorEnd_HTML); + doAddHTML(End_Font); + doAddHTML(FBT_TimeHourEnd_HTML); + } + break; + } + +// doAddHTML(FBT_TDOffsetCell_HTML); + doAddHTML(FBT_EndRow_HTML); +} + +void +JulianFormFactory::addMinorScale() +{ + int32 x; + + if (scaleType == 2) + { + // Minutes 00 or 30 + doAddHTML(FBT_NewRow_HTML); + + JulianString tickarray[] = {FBT_TickMark1, FBT_TickMark2, FBT_TickMark3, FBT_TickMark4}; + int32 yoffset = (SlotsPerHour == 4) ? 1 : 2; + for (x = start_hour; x < end_hour; x ++) + { + for (int32 y = 0; y < SlotsPerHour; y ++) + { + doAddHTML(FBT_TimeMin_HTML); + doAddHTML(Start_Font); + doAddHTML(FBT_TD_MinuteColor_HTML); + doAddHTML(tickarray[y * yoffset]); + doAddHTML(FBT_TD_MinuteColorEnd_HTML); + doAddHTML(End_Font); + doAddHTML(FBT_TimeMinEnd_HTML); + } + } +// doAddHTML(FBT_TDOffsetCell_HTML); + doAddHTML(FBT_EndRow_HTML); + } else + { + doAddHTML(FBT_NewRow_HTML); + doAddHTML(FBT_EndRow_HTML); + } +} + +void +JulianFormFactory::addTicksScale() +{ +#if 0 + int32 x; + + if (detail && scaleType == 2) + { + doAddHTML(FBT_NewRow_HTML); + doAddHTML(FBT_TDOffsetCell_HTML); + for (x = start_hour; x < end_hour; x ++) + { + for (int32 y = 0; y < SlotsPerHour; y ++) + { + doAddHTML(FBT_TimeMin_HTML); + doAddHTML(Start_Font); + doAddHTML(y & 1 ? FBT_TickShort_HTML : FBT_TickLong_HTML); + doAddHTML(End_Font); + doAddHTML(FBT_TimeMinEnd_HTML); + } + } +// doAddHTML(FBT_TDOffsetCell_HTML); + doAddHTML(FBT_EndRow_HTML); + } +#endif +} + +#if 0 +void +JulianFormFactory::emptyRow() +{ + char* temp; + char* temp2 = FBT_DayXColEmptyCell_HTML.toCString(""); + + doAddHTML(FBT_NewRow_HTML); + doAddHTML(FBT_DayEmptyCell_HTML); // No Title + doAddHTML(FBT_DayEmptyCell_HTML); // offset to first timeslot + + // All of the time slots + temp = PR_smprintf(temp2, slotsacross); + doAddHTML(temp); + doAddHTML(FBT_EndRow_HTML); + PR_FREEIF( temp2 ); + PR_FREEIF( temp ); +} +#endif + +void +JulianFormFactory::LineInc(DateTime* dtTime) +{ + switch (scaleType) + { + case 2: DaysLineInc(dtTime); break; + case 1: MonthLineInc(dtTime); break; + } +} + +void +JulianFormFactory::DaysLineInc(DateTime* dtTime) +{ + dtTime->nextDay(); +} + +void +JulianFormFactory::MonthLineInc(DateTime* dtTime) +{ + dtTime->nextMonth(); + dtTime->setDayOfMonth(1); +} + +// Return TRUE if this line is still within it's time range +int32 +JulianFormFactory::LineCheck(DateTime& baseTime, DateTime& checkTime, DateTime& checkTimeEnd) +{ + + if (checkTime > ((VFreebusy *)thisICalComp)->getDTEnd()) + { + new_state = Empty_State; + return FALSE; + } + + if (checkTimeEnd < start) + { + new_state = Empty_State; + return FALSE; + } + + switch (scaleType) + { + case 1: + if ((baseTime.getMonth(default_tz) != checkTime.getMonth(default_tz))) + new_state = Empty_State; + return (baseTime.getMonth(default_tz) == checkTime.getMonth(default_tz)); + break; + default: + return TRUE; + break; + } + + return TRUE; +} + +void +JulianFormFactory::enterState(FB_State newState, XP_Bool forse = FALSE) +{ + if (!forse && + newState == state) + count++; + else + { + char* temp = nil; + char* temp2; + + switch (state) + { + case Free_State: temp2 = FBT_DayXColFreeCell_HTML; break; + case Busy_State: temp2 = FBT_DayXColBusyCell_HTML; break; + case Empty_State: temp2 = FBT_DayXColEmptyCell_HTML; break; + case XParam_State: temp2 = FBT_DayXXParamCell_HTML; break; + default: temp2 = ""; + } + + state = newState; + + if (count > 0) + { + temp = PR_smprintf(temp2, count); + doAddHTML(temp); + } + + count = forse ? 0 : 1; + + PR_FREEIF(temp); + } +} + +/* +** Set p to the next period. +** +** Returns a Period or nil when there are no more periods +*/ +Period* +JulianFormFactory::getNextPeriod() +{ + if (pIndex >= pv->GetSize()) // Have more periods in this freebusy? + { + // No more periods in this freebusy, try the next freebusy + if (fbIndex >= fbv->GetSize()) + { + p = (Period *)nil; // Ran out of periods and freebusys all togeather + pv = (JulianPtrArray *)nil; + } else + { + fb = (Freebusy *)fbv->GetAt(fbIndex++); + pv = fb->getPeriod(); pIndex = 0; + } + } else { + assert(FALSE); + } + if (pv) p = (Period *)pv->GetAt(pIndex++); + +#ifdef DEBUG_eyork + if (p) + { + char sbuf[1024]; + sprintf(sbuf,"%s", p->toString().toCString("")); + } +#endif + + return p; +} + + +/* +** Return the FB_State of the current Freebusy, fb. +*/ +int32 +JulianFormFactory::getFBType() +{ +int32 x = (int32)Empty_State; + + if (fb) + { + if (fb->getType() == Freebusy::FB_TYPE_BUSY || + fb->getType() == Freebusy::FB_TYPE_BUSY_UNAVAILABLE || + fb->getType() == Freebusy::FB_TYPE_BUSY_TENTATIVE) + x = (int32)Busy_State; + else + if (fb->getType() == Freebusy::FB_TYPE_XPARAMVAL) + x = (int32)XParam_State; + else + x = (int32)Free_State; + } + + return x; +} + +/* +** Look at the current period to see if it's time to go +** onto the next one. +** +** There are three cases here: +** +** 1. The current period didn't expire in the last time slot +** +** 2. The current period did expire in the last time slot +** +** 3. The current period is the last one. +** +** When moving on to the next period, check to see if more then +** one period over laps the next time slot. If so, set status to +** busy if any of them are busy. Set p to the last period. +*/ +void +JulianFormFactory::checkPeriodBounds(DateTime& startofslot, DateTime& endofslot) +{ + if (p) + { + DateTime PeriodEnd; + XP_Bool a = TRUE; + + new_state = (FB_State)getFBType(); // Reset new_state to the state from the last period + + // Check to see if this is the last Period that + // over laps this time slot. The current + // period, p, will be set to the last period + // that over laps. + while (a & (p != nil)) + { + // First case test. See if this time slot has made it + // to this period. May not be the case on the very + // first period. + if (p->getStart() > endofslot) // there yet? + { + new_state = Free_State; + break; + } + + p->getEndingTime(PeriodEnd); + // Is this new slot passed the current period? + if (!endofslot.beforeDateTime(PeriodEnd)) + { + DateTime PeriodStart; + + getNextPeriod(); // need a new period. Changes p and fb. + + if (p) + { + FB_State next_state = (FB_State)getFBType(); + + PeriodStart = p->getStart(); + if ((new_state < next_state) || // Once new_state goes busy in this time slot, it stays that way. + (startofslot.equalsDateTime(PeriodStart))) // But change states if the new period starts right on this startofslot + { + new_state = next_state; + } + } + } else + a = FALSE; + } + } else + new_state = Free_State; // No periods but in time slot range assume free +} + +void +JulianFormFactory::makeHourFBTable() +{ + UnicodeString usFBT_TickSetting = FBT_TickSetting; + MinutesPerSlot = Julian_Duration(usFBT_TickSetting); + SlotsPerHour = (60 / MinutesPerSlot.getMinute()); + displayTimeZone = TRUE; + scaleType = 2; + hoursToDisplay = 24; + slotsacross = SlotsPerHour * hoursToDisplay; + lineFormat = FBT_DayFormat; +} + +void +JulianFormFactory::makeDaysFBTable() +{ + UnicodeString usFBT_TickDaySetting = FBT_TickDaySetting; + MinutesPerSlot = Julian_Duration(usFBT_TickDaySetting); + SlotsPerHour = 1; + displayTimeZone = FALSE; + scaleType = 1; + hoursToDisplay = 0; + slotsacross = 31; + lineFormat = FBT_MonthFormat; +} + +// +// Make a FreeBusy Table +// +void +JulianFormFactory::doMakeFreeBusyTable() +{ + if (isFreeBusy) + { + JulianString timezoneformat = "z"; + Julian_Duration tempdur; + int32 x; + char* temp2 = nil; + char* temp; + UnicodeString usFBT_HourStart; + UnicodeString usFBT_HourEnd; + UnicodeString usTimeZoneFormat; + UnicodeString usFBT_TickOffset; + UnicodeString usLineFormat; + UnicodeString tempuni; + + new_state = Empty_State; + // set start and end (to remove warnings John Sun 5-1-98) + start = ((VFreebusy *)thisICalComp)->getDTStart(); + end = ((VFreebusy *)thisICalComp)->getDTEnd(); + + // normalize end. must stop on an even day/time. + end.setDMY(end.getDate() + 1, end.getMonth(), end.getYear()); + end.set(Calendar::HOUR_OF_DAY, 0); + end.set(Calendar::MINUTE, 0); + end.set(Calendar::SECOND, 0); + + DateTime::getDuration(start, end, tempdur); + + tempdur.getMonth() >= 2 ? makeDaysFBTable() : makeHourFBTable(); + PR_FREEIF(TimeHour_HTML); + TimeHour_HTML = PR_smprintf(temp2 = FBT_TimeHour_HTML, SlotsPerHour); + + // This is the Hour row ie 6am to 7 pm etc + usFBT_HourStart = FBT_HourStart; + usFBT_HourEnd = FBT_HourEnd; + + start_hour = DateTime(usFBT_HourStart).getHour(default_tz); + end_hour = DateTime(usFBT_HourEnd).getHour(default_tz); + usTimeZoneFormat = timezoneformat.GetBuffer(); + + if (DateTime(usFBT_HourEnd).getMinute(default_tz) != 0) end_hour++; // Only show full hours. This is to get 11pm to work + tz = JulianString(temp = (start.strftime(usTimeZoneFormat, default_tz)).toCString("")); + PR_FREEIF(temp); + + // Legend + addLegend(); + + doAddHTML(FBT_Start_HTML); + doAddHTML(FBT_NewRow_HTML); + + // This is the TimeZone Heading + addTimeZone(); + + // Scale + addMajorScale(); + addMinorScale(); + addTicksScale(); + + fbv = isFreeBusy ? ((VFreebusy *)thisICalComp)->getFreebusy() : nil; + pv = nil; + fb = nil; + p = nil; + fbIndex = 0; + pIndex = 0; + + if (fbv) fb = (Freebusy *)fbv->GetAt(fbIndex++); + if (fb) pv = fb->getPeriod(); pIndex = 0; + if (pv) p = (Period *)pv->GetAt(pIndex++); + + usFBT_TickOffset = FBT_TickOffset; + // Each day or month now. So this this each line in the table + for (DateTime currentday = start; currentday < end; LineInc(¤tday)) + { + char* temp; + + Julian_Duration d_offset = Julian_Duration(usFBT_TickOffset); + // int32 slot_count; + DateTime StartOfSlot, EndOfSlot; + + StartOfSlot = DateTime( currentday.getYear(default_tz), + currentday.getMonth(default_tz), + MinutesPerSlot.getDay() > 0 ? 1 : currentday.getDate(default_tz), + MinutesPerSlot.getDay() > 0 ? 0 : start_hour, + 0); + EndOfSlot = DateTime(StartOfSlot); + EndOfSlot.add(MinutesPerSlot); + + doAddHTML(FBT_NewRow_HTML); + doAddHTML(FBT_DayStart_HTML); + + usLineFormat = lineFormat.GetBuffer(); + tempuni = currentday.strftime(usLineFormat); + uTemp = JulianString(temp = tempuni.toCString("")); + PR_FREEIF(temp); + doAddHTML(Start_Font); + doAddHTML(uTemp); + doAddHTML(End_Font); + doAddHTML(FBT_DayEnd_HTML); + + // Loop for the number of timeslots, each slot is 30 minutes or 1 day. + // slot_count = MinutesPerSlot.getDay() > 0 ? 31 : (end_hour - start_hour) * SlotsPerHour; + + // In Free State = 0, Busy State = 1, Empty State = 2 + // This is each column in the table + for (x = 0, state = Free_State, count = 0; x < slotsacross; x++, StartOfSlot.add(MinutesPerSlot), EndOfSlot.add(MinutesPerSlot)) + { +#ifdef DEBUG_eyork + char sbuf[1024]; + sprintf(sbuf,"%s", StartOfSlot.toString().toCString("")); + sprintf(sbuf,"%s", EndOfSlot.toString().toCString("")); +#endif + + // Do either free, busy, or not in this time slot + // First make sure that this slot hasn't left the range for this line. ie Feb 28 should not go to Mar 1 on one line + + // Did the month end on this line? or Still have to finish this line, did go pass dtend? + // Sets new_state if needed + if (LineCheck(currentday, StartOfSlot, EndOfSlot)) + checkPeriodBounds(StartOfSlot, EndOfSlot); + + enterState(new_state); + } + + enterState(state, TRUE); // End of line, force output. + + // Padding at the end of each line, etc + doAddHTML(FBT_DayEnd_HTML); + doAddHTML(FBT_TimeMin_HTML); + // doAddHTML(FBT_DayEmptyCell_HTML); + doAddHTML(FBT_TimeMinEnd_HTML); + doAddHTML(FBT_EndRow_HTML); + + } + + doAddHTML(FBT_End_HTML); + } +} + +void +JulianFormFactory::HandlePublishVEvent() +{ + int32 data_length = isDetail() ? publish_D_Fields_Data_HTML_Length : publish_Fields_Data_HTML_Length; + int32 label_length = isDetail() ? publish_D_Fields_Labels_Length : publish_Fields_Labels_Length; + + doHeader(publish_Header_HTML); + doProps(label_length, isDetail() ? publish_D_Fields_Labels : publish_Fields_Labels, data_length, isDetail() ? publish_D_Fields_Data_HTML : publish_Fields_Data_HTML); + doStatus(); + + if (isDetail()) + { + if (do_capi_login) doAddButton(doCreateButton(Buttons_Add_Type, Buttons_Add_Label)); + doClose(); + } else { + doAddButton(doCreateButton(Buttons_Details_Type, Buttons_Details_Label)); + if (do_capi_login) + { + doAddHTML( Head2_HTML ); + doAddButton(doCreateButton(Buttons_Add_Type, Buttons_Add_Label)); + } + } + doAddHTML( Props_End_HTML ); + doAddHTML( publish_End_HTML ); +} + +void +JulianFormFactory::HandleError() +{ + int32 data_length = error_Fields_Data_HTML_Length; + int32 label_length = error_Fields_Labels_Length; + + doHeader(error_Header_HTML); + doAddHTML(Props_Head_HTML); + doStatus(); + + doAddHTML( Props_End_HTML ); + doAddHTML( error_End_HTML ); +} + +void +JulianFormFactory::HandlePublishVFreeBusy(XP_Bool isPublish) +{ + int32 data_length = isDetail() ? publishFB_D_Fields_Data_HTML_Length : publishFB_Fields_Data_HTML_Length; + int32 label_length = isDetail() ? publishFB_D_Fields_Labels_Length : publishFB_Fields_Labels_Length; + + doHeader(isPublish ? publishFB_Header_HTML : replyFB_Header_HTML); + doProps(label_length, isDetail() ? publishFB_D_Fields_Labels : publishFB_Fields_Labels, data_length, isDetail() ? publishFB_D_Fields_Data_HTML : publishFB_Fields_Data_HTML); + doStatus(); + + if (isDetail()) + { + doClose(); + } else { + doAddButton(doCreateButton(Buttons_Details_Type, Buttons_Details_Label)); + doAddHTML( Head2_HTML ); + } + doAddHTML( Props_End_HTML ); + + doMakeFreeBusyTable(); + + doAddHTML( publishFB_End_HTML ); +} + +void +JulianFormFactory::HandleRequestVEvent() +{ + int32 data_length = isDetail() ? request_D_Fields_Data_HTML_Length : request_Fields_Data_HTML_Length; + int32 label_length = isDetail() ? request_D_Fields_Labels_Length : request_Fields_Labels_Length; + + doHeader(request_Header_HTML); + doProps(label_length, isDetail() ? request_D_Fields_Labels : request_Fields_Labels, data_length, isDetail() ? request_D_Fields_Data_HTML : request_Fields_Data_HTML); + if (!isDetail()) doAddButton(doCreateButton(Buttons_Details_Type, Buttons_Details_Label)); + doStatus(); + doCommentText(); + if (isDetail()) doAddButton(Buttons_SaveDel_HTML); + + doAddHTML( Buttons_GroupStart_HTML ); + doAddGroupButton(doCreateButton(Buttons_Accept_Type, Buttons_Accept_Label)); + doAddGroupButton(doCreateButton(Buttons_Decline_Type, Buttons_Decline_Label)); + if (isDetail()) + { + // Add Save copy here + doAddGroupButton(doCreateButton(Buttons_Tentative_Type, Buttons_Tentative_Label)); + doAddGroupButton(doCreateButton(Buttons_DelTo_Type, Buttons_DelTo_Label, TRUE)); + } else { + doAddGroupButton(doCreateButton(Buttons_DelTo_Type, Buttons_DelTo_Label, TRUE)); + } + doAddHTML( Buttons_GroupEnd_HTML ); + + doClose(); + doAddHTML( Props_End_HTML ); + doAddHTML( request_End_HTML ); +} + +void +JulianFormFactory::HandleRequestVFreeBusy( ) +{ + int32 data_length = isDetail() ? request_D_FB_Fields_Data_HTML_Length : request_FB_Fields_Data_HTML_Length; + int32 label_length = isDetail() ? request_D_FB_Fields_Labels_Length : request_FB_Fields_Labels_Length; + + doHeader(request_FB_Header_HTML); + doProps(label_length, isDetail() ? request_D_FB_Fields_Labels : request_FB_Fields_Labels, data_length, isDetail() ? request_D_FB_Fields_Data_HTML : request_FB_Fields_Data_HTML); + if (!isDetail()) doAddButton(doCreateButton(Buttons_Details_Type, Buttons_Details_Label)); + doStatus(); + + doAddHTML( Head2_HTML ); + if (isDetail()) { doAddHTML( Props_End_HTML ); doMakeFreeBusyTable(); doAddHTML( Props_Head_HTML ); doAddHTML( Head2_HTML ); } + + if (do_capi_login) doAddButton(doCreateButton(Buttons_SendFB_Type, Buttons_SendFB_Label)); + doClose(); + doAddHTML( Props_End_HTML ); + + doAddHTML( request_End_HTML ); +} + +void +JulianFormFactory::HandleEventReplyVEvent() +{ + int32 data_length = isDetail() ? eventreply_D_Fields_Data_HTML_Length : eventreply_Fields_Data_HTML_Length; + int32 label_length = isDetail() ? eventreply_D_Fields_Labels_Length : eventreply_Fields_Labels_Length; + + doHeader(eventreply_Header_HTML); + doProps(label_length, isDetail() ? eventreply_D_Fields_Labels : eventreply_Fields_Labels, data_length, isDetail() ? eventreply_D_Fields_Data_HTML : eventreply_Fields_Data_HTML); + doStatus(); + + if (isDetail()) + { + if (do_capi_login) doAddButton(doCreateButton(Buttons_Add_Type, Buttons_Update_Label)); + doClose(); + } else { + doAddButton(doCreateButton(Buttons_Details_Type, Buttons_Details_Label)); + if (do_capi_login) + { + doAddHTML( Head2_HTML ); + doAddButton(doCreateButton(Buttons_Add_Type, Buttons_Update_Label)); + } + } + doAddHTML( Props_End_HTML ); + doAddHTML( eventreply_End_HTML ); +} + +void +JulianFormFactory::HandleEventCancelVEvent() +{ + int32 data_length = isDetail() ? eventcancel_D_Fields_Data_HTML_Length : eventcancel_Fields_Data_HTML_Length; + int32 label_length = isDetail() ? eventcancel_D_Fields_Labels_Length : eventcancel_Fields_Labels_Length; + + doHeader(eventcancel_Header_HTML); + doProps(label_length, isDetail() ? eventcancel_D_Fields_Labels : eventcancel_Fields_Labels, data_length, isDetail() ? eventcancel_D_Fields_Data_HTML : eventcancel_Fields_Data_HTML); + doStatus(); + + if (isDetail()) + { + if (do_capi_login) doAddButton(doCreateButton(Buttons_Add_Type, Buttons_Add_Label)); + doClose(); + } else { + doAddButton(doCreateButton(Buttons_Details_Type, Buttons_Details_Label)); + if (do_capi_login) + { + doAddHTML( Head2_HTML ); + doAddButton(doCreateButton(Buttons_Add_Type, Buttons_Update_Label)); + } + } + doAddHTML( Props_End_HTML ); + doAddHTML( eventcancel_End_HTML ); +} + +void +JulianFormFactory::HandleEventRefreshRequestVEvent() +{ + int32 data_length = isDetail() ? eventrefreshreg_D_Fields_Data_HTML_Length : eventrefreshreg_Fields_Data_HTML_Length; + int32 label_length = isDetail() ? eventrefreshreg_D_Fields_Labels_Length : eventrefreshreg_Fields_Labels_Length; + + doHeader(eventrefreshreg_Header_HTML); + doProps(label_length, isDetail() ? eventrefreshreg_D_Fields_Labels : eventrefreshreg_Fields_Labels, data_length, isDetail() ? eventrefreshreg_D_Fields_Data_HTML : eventrefreshreg_Fields_Data_HTML); + doStatus(); + doCommentText(); + + if (isDetail()) + { + if (do_capi_login) doAddButton(doCreateButton(Buttons_Add_Type, Buttons_Add_Label)); + if (do_capi_login) doAddButton(doCreateButton(Buttons_SendRefresh_Type, Buttons_SendRefresh_Label)); + doClose(); + } else { + doAddButton(doCreateButton(Buttons_Details_Type, Buttons_Details_Label)); + if (do_capi_login) + { + doAddHTML( Head2_HTML ); + doAddButton(doCreateButton(Buttons_SendRefresh_Type, Buttons_SendRefresh_Label)); + } + } + doAddHTML( Props_End_HTML ); + doAddHTML( eventrefreshreg_End_HTML ); +} + +void +JulianFormFactory::HandleEventCounterPropVEvent() +{ + int32 data_length = isDetail() ? request_D_Fields_Data_HTML_Length : request_Fields_Data_HTML_Length; + int32 label_length = isDetail() ? request_D_Fields_Labels_Length : request_Fields_Labels_Length; + + doHeader(eventcounterprop_Header_HTML); + doProps(label_length, isDetail() ? request_D_Fields_Labels : request_Fields_Labels, data_length, isDetail() ? request_D_Fields_Data_HTML : request_Fields_Data_HTML); + if (!isDetail()) doAddButton(doCreateButton(Buttons_Details_Type, Buttons_Details_Label)); + doStatus(); + doCommentText(); + if (isDetail()) doAddButton(Buttons_SaveDel_HTML); + + doAddHTML( Buttons_GroupStart_HTML ); + doAddGroupButton(doCreateButton(Buttons_Accept_Type, Buttons_Accept_Label)); + doAddGroupButton(doCreateButton(Buttons_Decline_Type, Buttons_Decline_Label)); + doAddHTML( Buttons_GroupEnd_HTML ); + + doClose(); + doAddHTML( Props_End_HTML ); + doAddHTML( request_End_HTML ); +} + +void +JulianFormFactory::HandleDeclineCounterVEvent() +{ + int32 data_length = eventdelinecounter_Fields_Data_HTML_Length; + int32 label_length = eventdelinecounter_Fields_Labels_Length; + + doHeader(eventdelinecounter_Header_HTML); + doProps(label_length, eventdelinecounter_Fields_Labels, data_length, eventdelinecounter_Fields_Data_HTML); + doStatus(); + doAddHTML( Props_End_HTML ); + doAddHTML( request_End_HTML ); +} + +/* +** General HTML +*/ +char* JulianFormFactory::Start_HTML = "

\n"; +char* JulianFormFactory::Props_Head_HTML = "\n"; +char* JulianFormFactory::Props_HTML_Before_Label = "\n"; +char* JulianFormFactory::Props_HTML_Empty_Label = ""; +char* JulianFormFactory::Props_End_HTML = "

"; +char* JulianFormFactory::Props_HTML_After_Label = "  

"; +char* JulianFormFactory::Props_HTML_After_Data = " 
  
 
"; +char* JulianFormFactory::End_HTML = "

"; +char* JulianFormFactory::General_Header_Start_HTML = "
 "; +char* JulianFormFactory::General_Header_Status_HTML = "

"; +char* JulianFormFactory::General_Header_End_HTML = "

\n"; +char* JulianFormFactory::Head2_HTML = "
\n"; +char* JulianFormFactory::Italic_Start_HTML = ""; +char* JulianFormFactory::Italic_End_HTML = ""; +char* JulianFormFactory::Bold_Start_HTML = ""; +char* JulianFormFactory::Bold_End_HTML = ""; +char* JulianFormFactory::Aref_Start_HTML = ""; +char* JulianFormFactory::ArefTag_End_HTML = ""; +char* JulianFormFactory::nbsp = " "; +char* JulianFormFactory::Accepted_Gif_HTML = "+ "; +char* JulianFormFactory::Declined_Gif_HTML = "- "; +char* JulianFormFactory::Delegated_Gif_HTML = "> "; +char* JulianFormFactory::NeedsAction_Gif_HTML = "* "; +char* JulianFormFactory::Question_Gif_HTML = "? "; +char* JulianFormFactory::Line_3_HTML = "
"; +char* JulianFormFactory::Cell_Start_HTML = ""; +char* JulianFormFactory::Cell_End_HTML = ""; +char* JulianFormFactory::Font_Fixed_Start_HTML = ""; +char* JulianFormFactory::Font_Fixed_End_HTML = ""; +char* JulianFormFactory::Line_Break_HTML = "
"; + +/* +** Free/Busy Table +*/ +char* JulianFormFactory::FBT_Start_HTML = "\n"; +char* JulianFormFactory::FBT_End_HTML = "
"; +char* JulianFormFactory::FBT_NewRow_HTML = "\n"; +char* JulianFormFactory::FBT_EndRow_HTML = "\n"; +char* JulianFormFactory::FBT_TimeHead_HTML = "\n"; +char* JulianFormFactory::FBT_TimeHeadEnd_HTML = ""; +char* JulianFormFactory::FBT_TimeHour_HTML = ""; +char* JulianFormFactory::FBT_TimeHourEnd_HTML = "\n"; +char* JulianFormFactory::FBT_TimeMin_HTML = ""; +char* JulianFormFactory::FBT_TimeMinEnd_HTML = "\n"; +char* JulianFormFactory::FBT_TD_HourColor_HTML = ""; +char* JulianFormFactory::FBT_TD_HourColorEnd_HTML = ""; +char* JulianFormFactory::FBT_TD_MinuteColor_HTML = ""; +char* JulianFormFactory::FBT_TD_MinuteColorEnd_HTML = ""; +char* JulianFormFactory::FBT_TDOffsetCell_HTML = " "; +char* JulianFormFactory::FBT_TickLong_HTML = ""; +char* JulianFormFactory::FBT_TickShort_HTML = ""; +char* JulianFormFactory::FBT_HourStart = "19971101T000000"; +char* JulianFormFactory::FBT_HourEnd = "19971101T235959"; + +char* JulianFormFactory::FBT_DayStart_HTML = ""; +char* JulianFormFactory::FBT_DayEnd_HTML = ""; +char* JulianFormFactory::FBT_DayEmptyCell_HTML = "
 
"; +char* JulianFormFactory::FBT_DayFreeCell_HTML = "
 
"; +char* JulianFormFactory::FBT_DayBusyCell_HTML = "
 
"; +char* JulianFormFactory::FBT_DayXParamCell_HTML = "
 
"; +char* JulianFormFactory::FBT_DayXColFreeCell_HTML = "
 
"; +char* JulianFormFactory::FBT_DayXColBusyCell_HTML = "
 
"; +char* JulianFormFactory::FBT_DayXColEmptyCell_HTML = "
 
"; +char* JulianFormFactory::FBT_DayXXParamCell_HTML = "
 
"; +char* JulianFormFactory::FBT_EmptyRow_HTML = " "; + +// Legend +char* JulianFormFactory::FBT_Legend_Start_HTML = ""; +char* JulianFormFactory::FBT_Legend_End_HTML = "
"; +char* JulianFormFactory::FBT_Legend_Text1_HTML = "
"; +char* JulianFormFactory::FBT_Legend_Text2_HTML = "
"; +char* JulianFormFactory::FBT_Legend_Text3_HTML = "
"; +char* JulianFormFactory::FBT_Legend_Text4_HTML = "
"; +char* JulianFormFactory::FBT_Legend_Text5_HTML = "
"; +char* JulianFormFactory::FBT_Legend_TextEnd_HTML = " 
"; + +char* JulianFormFactory::FBT_TickMark1 = "00"; +char* JulianFormFactory::FBT_TickMark2 = "15"; +char* JulianFormFactory::FBT_TickMark3 = "30"; +char* JulianFormFactory::FBT_TickMark4 = "45"; +char* JulianFormFactory::FBT_TickSetting = "PT00H30M"; +char* JulianFormFactory::FBT_TickDaySetting = "P1D"; +char* JulianFormFactory::FBT_TickOffset = "PT00H01M"; +char* JulianFormFactory::FBT_DayFormat = "EEE, MMM dd"; +char* JulianFormFactory::FBT_MonthFormat = "MMM yyyy"; + +/* +** Fonts +*/ +char* JulianFormFactory::Start_Font = ""; +char* JulianFormFactory::End_Font = ""; +char* JulianFormFactory::Start_BIG_Font = ""; + +/* +** Buttons +*/ +char* JulianFormFactory::Buttons_Single_Start_HTML = ""; +char* JulianFormFactory::Buttons_Text_End_HTML = "\"> "; + +JulianString JulianFormFactory::Buttons_Details_Type = "btnNotifySubmitMD"; +JulianString JulianFormFactory::Buttons_Add_Type = "btnNotifySubmitATS"; +JulianString JulianFormFactory::Buttons_Close_Type = "btnNotifySubmitC"; +JulianString JulianFormFactory::Buttons_Accept_Type = "btnNotifySubmitAccept"; +JulianString JulianFormFactory::Buttons_Decline_Type = "btnNotifySubmitDecline"; +JulianString JulianFormFactory::Buttons_Tentative_Type = "btnNotifySubmitTent"; +JulianString JulianFormFactory::Buttons_SendFB_Type = "btnNotifySubmitFB"; +JulianString JulianFormFactory::Buttons_SendRefresh_Type = "btnNotifySubmitERR"; +JulianString JulianFormFactory::Buttons_DelTo_Type = "btnNotifySubmitDelTo"; + +char* JulianFormFactory::Buttons_SaveDel_HTML = " Save copy of delegated event"; + +char* JulianFormFactory::Buttons_GroupStart_HTML = ""; +char* JulianFormFactory::Buttons_GroupEnd_HTML = ""; +char* JulianFormFactory::Buttons_GroupSingleStart_HTML= " \n"; +char* JulianFormFactory::Buttons_GroupSingleEnd_HTML= ""; + +/* +** Text Fields +*/ +char* JulianFormFactory::Text_Label_Start_HTML = ""; +JulianString JulianFormFactory::Text_Label = "Comments (optional): "; +char* JulianFormFactory::Text_Label_End_HTML = ""; +JulianString JulianFormFactory::CommentsFieldName = "txtNotifyComments"; +JulianString JulianFormFactory::DelToFieldName = "btnNotifySubmitDelTo"; +char* JulianFormFactory::Text_Field_HTML = ""; + +/* +** ICalPropDefs +*/ +JulianString JulianFormFactory::ICalPreProcess = "%B%v%J"; +JulianString JulianFormFactory::ICalPostProcess = ""; + +/* +** Error +*/ +int32 JulianFormFactory::error_Fields_Labels_Length = 2; +JulianString JulianFormFactory::error_Fields_Labels[] = { "What:", "When:"}; +int32 JulianFormFactory::error_Fields_Data_HTML_Length = 3; +JulianString JulianFormFactory::error_Fields_Data_HTML[] = { "%S", "%B", "%i" }; +char* JulianFormFactory::error_End_HTML = ""; + +/* +** Publish +*/ +int32 JulianFormFactory::publish_Fields_Labels_Length = 3; +JulianString JulianFormFactory::publish_Fields_Labels[] = { "What:", "When:", "Location:"}; +int32 JulianFormFactory::publish_Fields_Data_HTML_Length = 4; +JulianString JulianFormFactory::publish_Fields_Data_HTML[] = { "%S", "%B", "%L", "%i" }; +char* JulianFormFactory::publish_End_HTML = ""; + +/* +** Publish Detail +*/ +int32 JulianFormFactory::publish_D_Fields_Labels_Length = 14; +JulianString JulianFormFactory::publish_D_Fields_Labels[] = { "What:", "When:", "Location:", "Organizer:", "Status:", "Priority:", "Categories:", "Resources:", "Attachments:", "Alarms:", "Created:", "Last Modified:", "Sent:", "UID:" }; +int32 JulianFormFactory::publish_D_Fields_Data_HTML_Length = 15; +JulianString JulianFormFactory::publish_D_Fields_Data_HTML[] = { "%S", "%B", "%L", "%J", "%g", "%p", "%k", "%r", "%a", "%w", "%t", "%M", "%C", "%U", "%i" }; + +/* +** Publish VFreeBusy +*/ +int32 JulianFormFactory::publishFB_Fields_Labels_Length = 2; +JulianString JulianFormFactory::publishFB_Fields_Labels[] = { "What:", "When:"}; +int32 JulianFormFactory::publishFB_Fields_Data_HTML_Length = 2; +JulianString JulianFormFactory::publishFB_Fields_Data_HTML[] = { "%S", "%B" }; +char* JulianFormFactory::publishFB_End_HTML = ""; + +/* +** Publish VFreeBusy Detail +*/ +int32 JulianFormFactory::publishFB_D_Fields_Labels_Length = 4; +JulianString JulianFormFactory::publishFB_D_Fields_Labels[] = { "What:", "When:", "Created:", "Sent:"}; +int32 JulianFormFactory::publishFB_D_Fields_Data_HTML_Length = 4; +JulianString JulianFormFactory::publishFB_D_Fields_Data_HTML[] = { "%S", "%B", "%t", "%C" }; + +/* +** Reply VFreeBusy +*/ + +/* +** Request VEvent +*/ +int32 JulianFormFactory::request_Fields_Labels_Length = 5; +JulianString JulianFormFactory::request_Fields_Labels[] = { "What:", "When:", "Location:", "Organizer:", "Who:"}; +int32 JulianFormFactory::request_Fields_Data_HTML_Length = 6; +JulianString JulianFormFactory::request_Fields_Data_HTML[] = { "%S", "%B", "%L", "%J", "%v", "%i" }; +char* JulianFormFactory::request_End_HTML = ""; + +/* +** Request Detail VEvent +*/ +int32 JulianFormFactory::request_D_Fields_Labels_Length = 15; +JulianString JulianFormFactory::request_D_Fields_Labels[] = { "What:", "When:", "Location:", "Organizer:", "Who:", "Status:", "Priority:", "Categories:", "Resources:", "Attachments:", "Alarms:", "Created:", "Last Modified:", "Sent:", "UID:"}; +int32 JulianFormFactory::request_D_Fields_Data_HTML_Length = 16; +JulianString JulianFormFactory::request_D_Fields_Data_HTML[]= { "%S", "%B", "%L", "%J", "%v", "%g", "%p", "%k", "%r", "%a", "%w", "%t", "%M", "%C", "%U", "%i" }; + +/* +** Request VFreeBusy +*/ +int32 JulianFormFactory::request_FB_Fields_Labels_Length = 1; +JulianString JulianFormFactory::request_FB_Fields_Labels[] = { "When:"}; +int32 JulianFormFactory::request_FB_Fields_Data_HTML_Length = 1; +JulianString JulianFormFactory::request_FB_Fields_Data_HTML[] = { "%B" }; +char* JulianFormFactory::request_FB_End_HTML = ""; + +/* +** Request VFreeBusy Detail +*/ +int32 JulianFormFactory::request_D_FB_Fields_Labels_Length = 1; +JulianString JulianFormFactory::request_D_FB_Fields_Labels[] = { "When:"}; +int32 JulianFormFactory::request_D_FB_Fields_Data_HTML_Length = 1; +JulianString JulianFormFactory::request_D_FB_Fields_Data_HTML[] = { "%B" }; +char* JulianFormFactory::request_D_FB_End_HTML = ""; + +/* +** Event Reply +*/ +int32 JulianFormFactory::eventreply_Fields_Labels_Length = 2; +JulianString JulianFormFactory::eventreply_Fields_Labels[] = { "Who:", "Status:"}; +int32 JulianFormFactory::eventreply_Fields_Data_HTML_Length = 4; +JulianString JulianFormFactory::eventreply_Fields_Data_HTML[] = { "%v", "%g", "%K", "%i" }; +char* JulianFormFactory::eventreply_End_HTML = ""; + +/* +** Event Reply Detail +*/ +int32 JulianFormFactory::eventreply_D_Fields_Labels_Length= 5; +JulianString JulianFormFactory::eventreply_D_Fields_Labels[] = { "What:", "When:", "Location:", "Who:", "Status:" }; +int32 JulianFormFactory::eventreply_D_Fields_Data_HTML_Length = 6; +JulianString JulianFormFactory::eventreply_D_Fields_Data_HTML[] = { "%S", "%B", "%L", "%v", "%g", "%K", "%i" }; + +/* +** Event Cancel +*/ +int32 JulianFormFactory::eventcancel_Fields_Labels_Length = 2; +JulianString JulianFormFactory::eventcancel_Fields_Labels[] = { "Status:", "UID:"}; +int32 JulianFormFactory::eventcancel_Fields_Data_HTML_Length = 3; +JulianString JulianFormFactory::eventcancel_Fields_Data_HTML[] = { "%g", "%U", "%K" }; +char* JulianFormFactory::eventcancel_End_HTML = ""; + +/* +** Event Cancel Detail +*/ +int32 JulianFormFactory::eventcancel_D_Fields_Labels_Length= 14; +JulianString JulianFormFactory::eventcancel_D_Fields_Labels[] = { "What:", "When:", "Location:", "Organizer:", "Status:", "Priority:", "Categories:", "Resources:", "Attachments:", "Alarms:", "Created:", "Last Modified:", "Sent:", "UID:" }; +int32 JulianFormFactory::eventcancel_D_Fields_Data_HTML_Length = 16; +JulianString JulianFormFactory::eventcancel_D_Fields_Data_HTML[] = { "%S", "%B", "%L", "%J", "%g", "%p", "%k", "%r", "%a", "%w", "%t", "%M", "%C", "%U", "%K", "%i" }; + +/* +** Event Refresh Request +*/ +int32 JulianFormFactory::eventrefreshreg_Fields_Labels_Length = 2; +JulianString JulianFormFactory::eventrefreshreg_Fields_Labels[] = { "Who:", "UID:"}; +int32 JulianFormFactory::eventrefreshreg_Fields_Data_HTML_Length = 2; +JulianString JulianFormFactory::eventrefreshreg_Fields_Data_HTML[] = { "%v", "%U" }; +char* JulianFormFactory::eventrefreshreg_End_HTML = ""; + +/* +** Event Refresh Request Detail +*/ +int32 JulianFormFactory::eventrefreshreg_D_Fields_Labels_Length= 14; +JulianString JulianFormFactory::eventrefreshreg_D_Fields_Labels[] = { "What:", "When:", "Location:", "Organizer:", "Status:", "Priority:", "Categories:", "Resources:", "Attachments:", "Alarms:", "Created:", "Last Modified:", "Sent:", "UID:" }; +int32 JulianFormFactory::eventrefreshreg_D_Fields_Data_HTML_Length = 15; +JulianString JulianFormFactory::eventrefreshreg_D_Fields_Data_HTML[]= { "%S", "%B", "%L", "%J", "%g", "%p", "%k", "%r", "%a", "%w", "%t", "%M", "%C", "%U", "%i" }; + +/* +** Event Counter Proposal +*/ + +/* +** Event Deline Counter +*/ +int32 JulianFormFactory::eventdelinecounter_Fields_Labels_Length= 1; +JulianString JulianFormFactory::eventdelinecounter_Fields_Labels[] = { "What:" }; +int32 JulianFormFactory::eventdelinecounter_Fields_Data_HTML_Length = 3; +JulianString JulianFormFactory::eventdelinecounter_Fields_Data_HTML[]= { "%S", "%K", "%i" }; + +/* +*** +*** String to translate +*** +*/ +JulianString JulianFormFactory::SubjectSep; + +#ifndef LIBJULIAN_USE_XPSTRS +void +JulianFormFactory::init() +{ + do_capi_login = FALSE; /* Default is not to ask for capi login info */ + + if (jf->getCallbacks()->BoolPref) + (*jf->getCallbacks()->BoolPref)("calendar.capi.enabled", &do_capi_login); + + error_Header_HTML = "Error"; + publish_Header_HTML = "Published Event"; + publishFB_Header_HTML = "Published Free/Busy"; + replyFB_Header_HTML = "Reply Free/Busy"; + request_Header_HTML = "Event Request"; + request_FB_Header_HTML = "Free/Busy Time Request"; + request_D_FB_Header_HTML = "Free/Busy Time Request"; + eventreply_Header_HTML = "Event Reply"; + eventcancel_Header_HTML = "Event Cancellation"; + eventrefreshreg_Header_HTML = "Event Refresh Request"; + eventcounterprop_Header_HTML = "Event Counter Proposal"; + eventdelinecounter_Header_HTML = "Decline Counter Proposal"; + + String_What = "What:"; + String_When = "When:"; + String_Location = "Location:"; + String_Organizer = "Organizer:"; + String_Status = "Status:"; + String_Priority = "Priority:"; + String_Categories = "Categories:"; + String_Resources = "Resources:"; + String_Attachments = "Attachments:"; + String_Alarms = "Alarms:"; + String_Created = "Created:"; + String_Last_Modified = "Last Modified:"; + String_Sent = "Sent:"; + String_UID = "UID:"; + + FBT_Legend_Title = "Legend:"; + FBT_Legend_Free = "free"; + FBT_Legend_Busy = "busy"; + FBT_Legend_Unknown = "unknown"; + FBT_Legend_xparam = "undefined"; + + FBT_AM = " AM"; + FBT_PM = " PM"; + + Buttons_Details_Label = "More Details..."; + Buttons_Add_Label = "Add To Schedule"; + Buttons_Close_Label = "Close"; + Buttons_Accept_Label = "Accept"; + Buttons_AcceptAll_Label = "Accept All"; + Buttons_Update_Label = "Update Schedule"; + Buttons_Decline_Label = "Decline"; + Buttons_Tentative_Label = "Tentative"; + Buttons_SendFB_Label = "Send Free/Busy Time Infomation"; + Buttons_SendRefresh_Label = "Send Refresh"; + Buttons_DelTo_Label = "Delegate to"; + +/* +** Status Messages +*/ + EventInSchedule = "This event is already in your schedule\r\n"; + EventNotInSchedule = "This event is not yet in your schedule\r\n"; + EventConflict = "Conflicts:"; + EventNote = "Note:"; + EventError = "Error:"; + EventTest = "Staff meeting 3:30 - 4:30 PM :-("; + Text_To = " to "; + Text_AllDay = " ( Day Event) "; + Text_StartOn = " Begins on "; + Text_Was = "Was"; + +/* +** Muilt Stuff +*/ + MuiltEvent_Header_HTML = "Published Calendar Events"; + MuiltFB_Header_HTML = "Published Calendar Free/Busy"; + MuiltEvent = "This messages contains %d events."; + WhenStr = "When"; + WhatStr = "What"; + SubjectSep = ": "; + +/* +** Error Strings +*/ + MoreErrors = "There are also %d other errors"; + TooManyEvents = "Display limited to the first %d events."; + error0 = "Unknown"; + error1 = "DTEnd before DTStart. Setting DTEnd equal to DTStart"; + error2 = "Prompt value must be ON or OFF"; + error3 = "Cannot parse time/date string"; + error4 = "Recurrence rules are too complicated. Only the first instance was scheduled"; + error5 = "Invalid property value"; + error6 = "Invalid property name"; + error7 = "Invalid parameter name"; + +/* Don't forget What, When etc */ +} +#else +void +JulianFormFactory::init() +{ + do_capi_login = FALSE; /* Default is not to ask for capi login info */ + + if (jf->getCallbacks()->BoolPref) + (*jf->getCallbacks()->BoolPref)("calendar.capi.enabled", &do_capi_login); + + /* + ** char*'s + */ + if (cb && cb->GetString) + { + error_Header_HTML = XP_STRDUP((*cb->GetString)(JULIAN_STRING_ERROR_HEADER)); + publish_Header_HTML = XP_STRDUP((*cb->GetString)(JULIAN_STRING_PUBLISH_HEADER)); + publishFB_Header_HTML = XP_STRDUP((*cb->GetString)(JULIAN_STRING_PUBLISHFB_HEADER)); + replyFB_Header_HTML = XP_STRDUP((*cb->GetString)(JULIAN_STRING_REPLYFB_HEADER)); + request_Header_HTML = XP_STRDUP((*cb->GetString)(JULIAN_STRING_REQUEST_HEADER)); + request_FB_Header_HTML = XP_STRDUP((*cb->GetString)(JULIAN_STRING_REQUESTFB_HEADER)); + request_D_FB_Header_HTML = XP_STRDUP((*cb->GetString)(JULIAN_STRING_REQUESTFB_HEADER)); + eventreply_Header_HTML = XP_STRDUP((*cb->GetString)(JULIAN_STRING_EVENTREPLY_HEADER)); + eventcancel_Header_HTML = XP_STRDUP((*cb->GetString)(JULIAN_STRING_EVENTCANCEL_HEADER)); + eventrefreshreg_Header_HTML = XP_STRDUP((*cb->GetString)(JULIAN_STRING_EVENTREFRESHREG_HEADER)); + eventcounterprop_Header_HTML = XP_STRDUP((*cb->GetString)(JULIAN_STRING_EVENTCOUNTERPROP_HEADER)); + eventdelinecounter_Header_HTML = XP_STRDUP((*cb->GetString)(JULIAN_STRING_EVENTDELINECOUNTER_HEADER)); + + String_What = XP_STRDUP((*cb->GetString)(JULIAN_STRING_WHAT)); + String_When = XP_STRDUP((*cb->GetString)(JULIAN_STRING_WHEN)); + String_Location = XP_STRDUP((*cb->GetString)(JULIAN_STRING_LOCATION)); + String_Organizer = XP_STRDUP((*cb->GetString)(JULIAN_STRING_ORGANIZER)); + String_Status = XP_STRDUP((*cb->GetString)(JULIAN_STRING_STATUS)); + String_Priority = XP_STRDUP((*cb->GetString)(JULIAN_STRING_PRIORITY)); + String_Categories = XP_STRDUP((*cb->GetString)(JULIAN_STRING_CATEGORIES)); + String_Resources = XP_STRDUP((*cb->GetString)(JULIAN_STRING_RESOURCES)); + String_Attachments = XP_STRDUP((*cb->GetString)(JULIAN_STRING_ATTACHMENTS)); + String_Alarms = XP_STRDUP((*cb->GetString)(JULIAN_STRING_ALARMS)); + String_Created = XP_STRDUP((*cb->GetString)(JULIAN_STRING_CREATED)); + String_Last_Modified = XP_STRDUP((*cb->GetString)(JULIAN_STRING_LAST_MODIFIED)); + String_Sent = XP_STRDUP((*cb->GetString)(JULIAN_STRING_SENT)); + String_UID = XP_STRDUP((*cb->GetString)(JULIAN_STRING_UID)); + } + + /* + ** JulianStrings + */ + FBT_Legend_Title.LoadString(JULIAN_FBT_LEGEND_TITLE); + FBT_Legend_Free.LoadString(JULIAN_FBT_LEGEND_FREE); + FBT_Legend_Busy.LoadString(JULIAN_FBT_LEGEND_BUSY); + FBT_Legend_Unknown.LoadString(JULIAN_FBT_LEGEND_UNKNOWN); + FBT_Legend_xparam.LoadString(JULIAN_FBT_LEGEND_XPARAM); + + FBT_AM.LoadString(JULIAN_FBT_AM); + FBT_PM.LoadString(JULIAN_FBT_PM); + + Buttons_Details_Label.LoadString(JULIAN_BUTTONS_DETAILS_LABEL); + Buttons_Add_Label.LoadString(JULIAN_BUTTONS_ADD_LABEL); + Buttons_Close_Label.LoadString(JULIAN_BUTTONS_CLOSE_LABEL); + Buttons_Accept_Label.LoadString(JULIAN_BUTTONS_ACCEPT_LABEL); + Buttons_AcceptAll_Label.LoadString(JULIAN_BUTTONS_ACCEPTALL_LABEL); + Buttons_Update_Label.LoadString(JULIAN_BUTTONS_UPDATE_LABEL); + Buttons_Decline_Label.LoadString(JULIAN_BUTTONS_DECLINE_LABEL); + Buttons_Tentative_Label.LoadString(JULIAN_BUTTONS_TENTATIVE_LABEL); + Buttons_SendFB_Label.LoadString(JULIAN_BUTTONS_SENDFB_LABEL); + Buttons_SendRefresh_Label.LoadString(JULIAN_BUTTONS_SEND_REFRESH_LABEL); + Buttons_DelTo_Label.LoadString(JULIAN_BUTTONS_DELTO_LABEL); + + /* + ** Status Messages + */ + EventInSchedule.LoadString(JULIAN_EVENT_IN_SCHEDULE); + EventNotInSchedule.LoadString(JULIAN_EVENT_NOT_IN_SCHEDULE); + EventConflict.LoadString(JULIAN_EVENT_CONFLICT); + EventNote.LoadString(JULIAN_NOTE); + EventError.LoadString(JULIAN_EVENT_ERROR); + EventTest.LoadString(JULIAN_EVENT_ERROR); + Text_To.LoadString(JULIAN_TEXT_TO); + Text_AllDay.LoadString(JULIAN_TEXT_ALL_DAY); + Text_StartOn.LoadString(JULIAN_TEXT_START_ON); + Text_Was.LoadString(JULIAN_TEXT_WAS); + + /* + ** Muilt Stuff + */ + MuiltEvent_Header_HTML.LoadString(JULIAN_MUILTEVENT_HEADER); + MuiltFB_Header_HTML.LoadString(JULIAN_MUILTFB_HEADER); + MuiltEvent.LoadString(JULIAN_MUILTEVENT); + WhenStr.LoadString(JULIAN_WHENSTR); + WhatStr.LoadString(JULIAN_WHATSTR); + SubjectSep.LoadString(JULIAN_SUBJECTSEP); + + /* + ** Error Strings + */ + MoreErrors.LoadString(JULIAN_MORE_ERRORS); + TooManyEvents.LoadString(JULIAN_TOO_MANY_EVENTS); + error0.LoadString(JULIAN_ERROR_O); + error1.LoadString(JULIAN_ERROR_1); + error2.LoadString(JULIAN_ERROR_2); + error3.LoadString(JULIAN_ERROR_3); + error4.LoadString(JULIAN_ERROR_4); + error5.LoadString(JULIAN_ERROR_5); + error6.LoadString(JULIAN_ERROR_6); + error7.LoadString(JULIAN_ERROR_7); +} +#endif diff --git a/calendar/modules/core/htmlform/src/julianform.c b/calendar/modules/core/htmlform/src/julianform.c new file mode 100644 index 00000000000..3c4af0ec2cb --- /dev/null +++ b/calendar/modules/core/htmlform/src/julianform.c @@ -0,0 +1,127 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +#include +#include "jdefines.h" +#include "julianform.h" +#include "nlsloc.h" + +#ifdef XP_WIN32 +/*#include "stdafx.h"*/ +/*#include "feutil.h"*/ +#endif + +extern void* jform_CreateNewForm(char *, pJulian_Form_Callback_Struct, XP_Bool); +extern void jform_DeleteForm(void *); +extern char* jform_GetForm(void *); +extern void jform_CallBack(void *, void *); + +pJulian_Form_Callback_Struct JulianForm_CallBacks; +XP_Bool bCallbacksSet = PR_FALSE ; + +XP_Bool jf_Initialize(pJulian_Form_Callback_Struct callbacks) +{ + /* for some reason I have to do this little trick to get things to work */ + char * julian = NULL; + char buf[1024]; + julian = &(buf[0]); + + JulianForm_CallBacks = XP_NEW_ZAP(Julian_Form_Callback_Struct); + if (JulianForm_CallBacks && callbacks) + { + *JulianForm_CallBacks = *callbacks; + } + +#if defined(XP_WIN)||defined(XP_UNIX) + if (JulianForm_CallBacks && callbacks && callbacks->GetJulianPath) + { + bCallbacksSet = PR_TRUE ; + + /* set the NLS locale30 path to the location of the locale30 from the registry */ + JulianForm_CallBacks->GetJulianPath(&julian, (void *)sizeof(buf)); + + /* use path if it exist, otherwise you NS_NLS_DATADIRECTORY env var if it exists */ + /* if neither exists return FALSE */ + if (JXP_ACCESS(julian, 0) != -1) + { + NLS_Initialize(NULL, julian); + return TRUE; + } + else + { + char * nlsDDir = getenv("NS_NLS_DATADIRECTORY"); + if (nlsDDir == 0) + return FALSE; + else + { + if (JXP_ACCESS(nlsDDir, 0) == -1) + return FALSE; + else + return TRUE; + } + } + } +#endif + + return FALSE; +} + +void *jf_New(char *calendar_mime_data, XP_Bool bFoundNLSDataDirectory) +{ + return jform_CreateNewForm(calendar_mime_data, JulianForm_CallBacks, bFoundNLSDataDirectory); +} + +void jf_Destroy(void *instdata) +{ + jform_DeleteForm(instdata); +} + +void jf_Shutdown() +{ + XP_FREEIF(JulianForm_CallBacks); +} + +char *jf_getForm(void *instdata) +{ + return jform_GetForm(instdata); +} + +void jf_setDetail(int detail_form) +{ +} + +/* rhp - needed to add third parameter for other mime related calls */ +void jf_callback(void *instdata, char *url, URL_Struct *URL_s) +{ + if (instdata && url) + { + jform_CallBack(instdata, url); + } +} + +/* rhp - needed to add third parameter for other mime related calls */ +/* For some unknown reason there can only be one call back funtion/ +** instdate per button +*/ +void jf_detail_callback(void *instdata, char *url, URL_Struct *URL_s) +{ + if (instdata && url) + { + jform_CallBack(instdata, url); + } +} diff --git a/calendar/modules/core/htmlform/src/manifest.mn b/calendar/modules/core/htmlform/src/manifest.mn new file mode 100644 index 00000000000..e69de29bb2d diff --git a/calendar/modules/core/ical/Makefile b/calendar/modules/core/ical/Makefile new file mode 100644 index 00000000000..e69de29bb2d diff --git a/calendar/modules/core/ical/inc/Makefile b/calendar/modules/core/ical/inc/Makefile new file mode 100644 index 00000000000..e69de29bb2d diff --git a/calendar/modules/core/ical/inc/abprprty.h b/calendar/modules/core/ical/inc/abprprty.h new file mode 100644 index 00000000000..e69de29bb2d diff --git a/calendar/modules/core/ical/inc/attendee.h b/calendar/modules/core/ical/inc/attendee.h new file mode 100644 index 00000000000..8da9ff6addf --- /dev/null +++ b/calendar/modules/core/ical/inc/attendee.h @@ -0,0 +1,756 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +/* + * attendee.h + * John Sun + * 2/6/98 4:33:43 PM + */ + +#ifndef __ATTENDEE_H_ +#define __ATTENDEE_H_ + +#include "ptrarray.h" +#include "icalcomp.h" +#include "prprty.h" +#include "jlog.h" +#include "datetime.h" + +/** + * The Attendee class encapsulates the data in the iCalendar + * ATTENDEE property. This class must implement the interface defined + * by the ICalProperty abstract class. The keyword parameters in Attendee + * are stored as t_int32. Other parameters are stored as UnicodeStrings + * or as JulianPtrArray's of UnicodeStrings. + */ +class Attendee : public ICalProperty +{ +private: + + /** + * For now, hide default constructor. + * Currently must pass in a Log object to create an Attendee. + */ + Attendee(); + + +public: + + /* enums of attendee keywords */ + /** Enumeration of ROLE parameter*/ + enum ROLE { + /*ROLE_ATTENDEE = 0, ROLE_ORGANIZER = 1, ROLE_OWNER = 2, + ROLE_DELEGATE = 3, ROLE_LENGTH = 4, + + ROLE_CHAIR = 0, ROLE_PARTICIPANT = 1, ROLE_NON_PARTICIPANT = 2, + ROLE_LENGTH = 3, ROLE_INVALID = -1*/ + + ROLE_REQ_PARTICIPANT = 0, ROLE_CHAIR = 1, ROLE_OPT_PARTICIPANT = 2, + ROLE_NON_PARTICIPANT = 3, + ROLE_XPARAMVAL = 4, ROLE_LENGTH = 5, ROLE_INVALID = -1 + }; + + /** Enumeration of CUTYPE parameter*/ + enum TYPE { + TYPE_INDIVIDUAL = 0, TYPE_GROUP = 1, + TYPE_RESOURCE = 2, TYPE_ROOM = 3, TYPE_UNKNOWN = 4, + TYPE_XPARAMVAL = 5, + TYPE_LENGTH = 6, TYPE_INVALID = -1 + }; + + /** Enumeration of PARTSTAT parameter*/ + enum STATUS { + /* For VEVENT, VTODO, VJOURNAL */ + STATUS_NEEDSACTION = 0, STATUS_XPARAMVAL = 1, + STATUS_ACCEPTED = 2, STATUS_DECLINED = 3, + + /* For VEVENT and VTODO only */ + STATUS_TENTATIVE = 4, + STATUS_DELEGATED = 5, + + /* For VTODO only */ + STATUS_COMPLETED = 6, STATUS_INPROCESS = 7, + + + STATUS_LENGTH = 8, STATUS_INVALID = -1 + }; + + /** + * Is the status variable valid for this component type. For example, + * if compType is VEVENT and status is INPROCESS, return FALSE. + * But if compType is VTODO and status is INPROCESS, return TRUE. + * @param compType component type + * @param status status + * + * @return TRUE if valid status for compType, FALSE otherwise + */ + static t_bool isValidStatus(ICalComponent::ICAL_COMPONENT compType, Attendee::STATUS status); + + /** Enumeration of RSVP parameter */ + enum RSVP { + RSVP_FALSE = 0, RSVP_TRUE = 1, + RSVP_LENGTH = 2, RSVP_INVALID = -1 + }; + + /** Enumeration of EXPECT parameter */ + enum EXPECT { + EXPECT_FYI = 0, EXPECT_REQUIRE = 1, EXPECT_REQUEST = 2, + /*EXPECT_IMMEDIATE = 3, EXPECT_LENGTH = 4, */ + EXPECT_LENGTH = 3, EXPECT_INVALID = -1 + }; + + + /** Enumeration of all keyword properties in an Attendee */ + enum PROPS { + PROPS_ROLE = 0, PROPS_TYPE = 1, + PROPS_STATUS = 2, PROPS_RSVP = 3, + PROPS_EXPECT = 4 + }; + + /** + * Converts ROLE string to a ROLE enumeration + * @param sRole role string + * + * @return ROLE that represents that string + */ + static Attendee::ROLE stringToRole(UnicodeString & sRole); + + /** + * Converts CUTYPE string to a TYPE enumeration + * @param sType type string + * + * @return TYPE that represents that string + */ + static Attendee::TYPE stringToType(UnicodeString & sType); + + /** + * Converts PARTSTAT string to a AT_PARSTAT enumeration + * @param sStatus status string + * + * @return STATUS that represents that string + */ + static Attendee::STATUS stringToStatus(UnicodeString & sStatus); + + /** + * Converts RSVP string to a RSVP enumeration + * @param sRSVP rsvp string + * + * @return RSVP that represents that string + */ + static Attendee::RSVP stringToRSVP(UnicodeString & sRSVP); + + /** + * Converts EXPECT string to a EXPECT enumeration + * @param sExpect expect string + * + * @return EXPECT that represents that string + */ + static Attendee::EXPECT stringToExpect(UnicodeString & sExpect); + + /** + * Converts ROLE to string. If bad role, return default (REQ_PARTICIPANT). + * @param role ROLE enumeration + * @param out output role string + * + * @return output role string (out) + */ + static UnicodeString & roleToString(Attendee::ROLE role, UnicodeString & out); + + /** + * Converts TYPE to string. If bad type, return default (INDIVIDUAL). + * @param type TYPE enumeration + * @param out output type string + * + * @return output type string (out) + */ + static UnicodeString & typeToString(Attendee::TYPE type, UnicodeString & out); + + /** + * Converts STATUS to string. If bad status, return default (NEEDS-ACTION). + * @param status STATUS enumeration + * @param out output partstat string + * + * @return output partstat string (out) + */ + static UnicodeString & statusToString(Attendee::STATUS status, UnicodeString & out); + + + /** + * Converts RSVP to string. If bad rsvp, return default (FALSE). + * @param rsvp RSVP enumeration + * @param out output rsvp string + * + * @return output rsvp string (out) + */ + static UnicodeString & rsvpToString(Attendee::RSVP rsvp, UnicodeString & out); + + /** + * Converts EXPECT to string. If bad expect, return default (FYI). + * @param expect EXPECT enumeration + * @param out output expect string + * + * @return output expect string (out) + */ + static UnicodeString & expectToString(Attendee::EXPECT expect, UnicodeString & out); + + /** + * Constructor. Also sets log file to write errors to. + * @param ICalComponent::ICAL_COMPONENT componentType + * @param initLog log file to write errors to + */ + Attendee(ICalComponent::ICAL_COMPONENT componentType, JLog * initLog = 0); + + /** + * Destructor + */ + ~Attendee(); + + /** + * Factory method that returns a new default Attendee + * + * @return static Attendee * + */ + static Attendee * getDefault(ICalComponent::ICAL_COMPONENT compType, + JLog * initLog = 0); + + /** + * Given attendee name and parameters, populates Attendee + * data members. + * @param propVal attendee name + * @param parameters attendee parameters + * + */ + void parse(UnicodeString & propVal, JulianPtrArray * parameters = 0); + + /** + * Sets parameter with name paramName with value paramVal. + * For MEMBER, DELEGATED-TO, DELEGATED-FROM, DIR, SENT-BY, the + * double quotes are stripped. THE MAILTO: is not stripped. + * + * @param paramName parameter name to set + * @param paramVal new value of parameter + */ + void setParam(UnicodeString & paramName, UnicodeString & paramVal); + + /** + * convert a character to the content of a parameter in + * human-readable string format + * + * @param c a character represents a parameter + * @return parameter in a human-readable string + */ + UnicodeString toStringChar(t_int32 c); + + + /** + * Return the first attendee in vAttendees with the name matching sAttendee. + * @param vAttendees vector of attendees + * @param sAttendee attendee name to look for + * + * @return first Attendee with name sAttendee, 0 if not found. + */ + static Attendee * getAttendee(JulianPtrArray * vAttendees, UnicodeString sAttendee); + + /*---------- To satisfy ICalProperty interface ----------*/ + /** + * Sets parameters. + * @param parameters vector of parameters to set + * + */ + virtual void setParameters(JulianPtrArray * parameters); + + /** + * Return value of property. Never use. Use getName(). + * + * @return value of property + */ + virtual void * getValue() const { PR_ASSERT(FALSE); return (void*) (&m_sName); } + + /** + * Sets value of property. Never use. Use setName(). + * @param value new value of property + * + */ + virtual void setValue(void * value) { PR_ASSERT(FALSE); if (value) {}} ; + + /** + * Returns a clone of this property. + * @param initLog the log file for clone to write to + * + * @return clone of this ICalProperty object + */ + virtual ICalProperty * clone(JLog * initLog); + + /** + * Checks whether this property is valid or not. Must have MAILTO: in + * front of attendee name to be valid. + * + * @return TRUE if property is valid, FALSE otherwise + */ + virtual t_bool isValid(); + + /** + * Return property to human-readable string. + * @param dateFmt formatting string + * @param out output human-readable string + * + * @return output human-readable string (out) + */ + virtual UnicodeString & toString(UnicodeString & strFmt, UnicodeString & out); + + /** + * Return property to human-readable string. + * @param out output human-readable string + * + * @return output human-readable string (out) + */ + virtual UnicodeString & toString(UnicodeString & out); + + /** + * Return property to iCal property string. + * @param out output iCal string + * + * @return output iCal string (out) + */ + virtual UnicodeString & toICALString(UnicodeString & out); + + /** + * Return property to iCal property string. Inserts sProp to + * front of output string. sProp should be the property name of this + * property. + * @param sProp property name to append to insert at front of out + * @param out output iCal string with sProp in front + * + * @return output iCal string with sProp in front (out) + */ + virtual UnicodeString & toICALString(UnicodeString & sProp, UnicodeString & out); + /*----------End of ICalProperty interface----------*/ + + /* ---- GETTERS AND SETTERS ---- */ + + /** + * Sets Attendee name. + * @param sName new Attendee name + * + */ + void setName(UnicodeString sName); + + /** + * Returns Attendee name. + * + * @return Attendee name + */ + UnicodeString getName() const { return m_sName; } + + /** + * Sets ROLE. + * @param i new ROLE value + * + */ + void setRole(Attendee::ROLE i) { m_iRole = i; } + + /** + * Sets TYPE. + * @param i new TYPE value + * + */ + void setType(Attendee::TYPE i) { m_iType = i; } + + /** + * Sets STATUS. + * @param i new STATUS value + * + */ + void setStatus(Attendee::STATUS i) { m_iStatus = i; } + + /** + * Sets RSVP. + * @param i new RSVP value + * + */ + void setRSVP(Attendee::RSVP i) { m_iRSVP = i; } + + /** + * Sets EXPECT. + * @param i new EXPECT value + * + */ + void setExpect(Attendee::EXPECT i) { m_iExpect = i; } + + /** + * Returns ROLE value. + * + * @return ROLE value + */ + Attendee::ROLE getRole() const { return (Attendee::ROLE) m_iRole; } + + /** + * Returns TYPE value. + * + * @return TYPE value + */ + Attendee::TYPE getType() const { return (Attendee::TYPE) m_iType; } + + /** + * Returns STATUS value. + * + * @return STATUS value + */ + Attendee::STATUS getStatus() const { return (Attendee::STATUS) m_iStatus; } + + /** + * Returns RSVP value. + * + * @return RSVP value + */ + Attendee::RSVP getRSVP() const { return (Attendee::RSVP) m_iRSVP; } + + /** + * Returns EXPECT value. + * + * @return EXPECT value + */ + Attendee::EXPECT getExpect() const { return (Attendee::EXPECT) m_iExpect; } + + /** + * Add a name to the Delegated-To vector. + * @param sDelegatedTo name to add to delegated-to vector + */ + void addDelegatedTo(UnicodeString sDelegatedTo); + + /** + * Add a name to the Delegated-From vector. + * @param sDelegatedFrom name to add to delegated-from vector + */ + void addDelegatedFrom(UnicodeString sDelegatedFrom); + + /** + * Add a name to the Member vector. + * @param sMember name to add to member vector + */ + void addMember(UnicodeString sMember); + + /** + * Return ptr to Delegated-To vector + * + * @return Delegated-To vector + */ + JulianPtrArray * getDelegatedTo() const { return m_vsDelegatedTo; } + + /** + * Return ptr to Delegated-From vector + * + * @return Delegated-From vector + */ + JulianPtrArray * getDelegatedFrom() const { return m_vsDelegatedFrom; } + + /** + * Return ptr to Member vector + * + * @return Member vector + */ + JulianPtrArray * getMember() const { return m_vsMember; } + + /** + * Return CN (common-name) value + * + * @return CN value + */ + UnicodeString getCN() const { return m_CN; } + + /** + * Return Language value + * + * @return Language value + */ + UnicodeString getLanguage() const { return m_Language; } + + /** + * Return DIR (location of directory info) value + * + * @return DIR value + */ + UnicodeString getDir() const { return m_Dir; } + + /** + * Return SENT-BY (calendar user acting on behalf of the attendee) value + * + * @return SENT-BY value + */ + UnicodeString getSentBy() const { return m_SentBy; } + + /** + * Set CN (common-name) value + * @param new CN value + */ + void setCN(UnicodeString u) { m_CN = u; } + + /** + * Set Language value + * @param new Language value + */ + void setLanguage(UnicodeString u) { m_Language = u; } + + /** + * Set DIR (location of directory info) value + * @param new DIR value + */ + void setDir(UnicodeString u) { m_Dir = u; } + + /** + * Set SENT-BY (calendar user acting on behalf of the attendee) value + * @param new SENT-BY value + */ + void setSentBy(UnicodeString u) { m_SentBy = u; } + + void setDTStamp(DateTime d) { m_DTStamp = d; } + void setSequence(t_int32 i) { m_Sequence = i; } + + /* list the default values for properties + (always to 0th element of enumeration) */ + + /** the default ROLE value */ + static const t_int32 ms_iDEFAULT_ROLE; + + /** the default TYPE value */ + static const t_int32 ms_iDEFAULT_TYPE; + + /** the default STATUS value */ + static const t_int32 ms_iDEFAULT_STATUS; + + /** the default RSVP value */ + static const t_int32 ms_iDEFAULT_RSVP; + + /** the default EXPECT value*/ + static const t_int32 ms_iDEFAULT_EXPECT; + + /* ---- END OF PUBLIC STATIC DATA ---- */ +private: + + /** + * Copy constructor + * @param Attendee & that + */ + Attendee(Attendee & that); + + /** + * Fixes data-members are so that they are valid. If properties + * are invalid, then it will set it to defaults. + */ + void selfCheck(); + + /** + * Fixes keyword property so that it is valid. If property is + * invalid (param is out of range), then set property to default value. + * @param prop keyword property to check + * @param t_int32 param current value of keyword property + */ + void selfCheckHelper(Attendee::PROPS prop, t_int32 param); + + /** + * helper in parsing delegated-to, delegated-from, member + */ + void addParamValList(UnicodeString & paramValList, + t_int32 hashCode); + + /** + * format string to print Attendee with PARTSTAT NOT + * set to NEEDS-ACTION. + * @return output formatted iCal Attendee string + */ + UnicodeString formatDoneAction(); + +#if 0 + /** + * format string to print Attendee with PARTSTAT NOT + * set to NEEDS-ACTION and Delegated-To of attendee. + * @return output formatted iCal Attendee string + */ + UnicodeString formatDoneDelegateToOnly(); + + /** + * format string to print Attendee with PARTSTAT NOT + * set to NEEDS-ACTION and Delegated-From of attendee. + * @return output formatted iCal Attendee string + */ + UnicodeString formatDoneDelegateFromOnly(); +#endif + + /* BELOW METHODS ALL ARE NEEDS ACTION */ + /* no need for %S, assumed to be NEEDS-ACTION */ + + /** + * format string to print Attendee with PARTSTAT + * set to NEEDS-ACTION. + * @return output formatted iCal Attendee string + */ + UnicodeString formatNeedsAction(); + +#if 0 + /** + * format string to print Attendee with PARTSTAT + * set to NEEDS-ACTION and Delegated-To of attendee. + * @return output formatted iCal Attendee string + */ + UnicodeString formatDelegateToOnly(); + + /** + * format string to print Attendee with PARTSTAT + * set to NEEDS-ACTION and Delegated-From of attendee. + * @return output formatted iCal Attendee string + */ + UnicodeString formatDelegateFromOnly(); +#endif + + /** + * Method that takes a format string and returns + * the correctly formatted iCal Attendee string + * @param strFmt format string + * + * @return output formatted iCal Attendee string + */ + UnicodeString format(UnicodeString strFmt); + + /** + * Method that takes a character and returns parameter + * in iCal output format. + * @param c character representing parameter to print + * + * @return parameter in iCal output format + */ + UnicodeString formatChar(t_int32 c); + + /** + * Strip double quotest from the beginning and end of string + * if it has double-quotes at beginning and end. + * @param u string to strip double-quotes from + */ + /*static void stripDoubleQuotes(UnicodeString & u);*/ + + /** + * Inserts double quotes at start and end of string if + * string != "". + * @param us string to add double-quotes to + * + * @return string with double-quotes at start, end (us) + */ + /*static UnicodeString & addDoubleQuotes(UnicodeString & us);*/ + + /** + * Prints each element in a vector of MAILTO:'s + * (i.e. member,delegated-to,delegated-from). + * @param propName name of property (i.e. MEMBER) + * @param mailto vector of MAILTO: to print + * @param out output string + * + * @return output string (out) + */ + UnicodeString & printMailToVector(UnicodeString & propName, + JulianPtrArray * mailto, UnicodeString & out); + + /* ---- PRIVATE STATIC DATA ---- */ + + /* characters for printing Attendee parameters */ + static const t_int32 ms_cAttendeeName;/* = 'N';*/ + static const t_int32 ms_cAttendeeRole;/* = 'R';*/ + static const t_int32 ms_cAttendeeStatus;/* = 'S';*/ + static const t_int32 ms_cAttendeeRSVP;/* = 'V';*/ + static const t_int32 ms_cAttendeeType;/* = 'T';*/ + static const t_int32 ms_cAttendeeExpect;/* = 'E';*/ + static const t_int32 ms_cAttendeeDelegatedTo;/* = 'D';*/ + static const t_int32 ms_cAttendeeDelegatedFrom;/* = 'd';*/ + static const t_int32 ms_cAttendeeMember;/* = 'M';*/ + static const t_int32 ms_cAttendeeDir; /* = 'l'; 'el'*/ + static const t_int32 ms_cAttendeeSentBy;/* = 's';*/ + static const t_int32 ms_cAttendeeCN;/* = 'C';*/ + static const t_int32 ms_cAttendeeLanguage;/* = 'm';*/ + static const t_int32 ms_cAttendeeDisplayName;/* = 'z';*/ + + /* ---- END OF PRIVATE STATIC DATA ---- */ + + /* ---- PRIVATE DATA MEMBERS ---- */ + + /** + * the name of the Attendee. Whatever is to the right of the colon + * the name must be a URL. Field must be filled to be valid Attendee. + */ + UnicodeString m_sName; + + /** ptr to log file to write errors to */ + JLog * m_Log; + + /** the attendee's role value. Default is REQ_PARTICIPANT. */ + t_int32 m_iRole; + + /** the attendee's type value. Default is INDIVIDUAL. */ + t_int32 m_iType; + + /** the attendee's status value. Default is NEEDS-ACTION. */ + t_int32 m_iStatus; + + /** the attendee's RSVP value. Default is FALSE. */ + t_int32 m_iRSVP; + + /** the attendee's expect value. Default is FYI.*/ + t_int32 m_iExpect; + + /** + * the list of members the attendee belongs to + * each element in members must be a MAILTO: + */ + JulianPtrArray * m_vsMember; + + /** + * the list of delegated-to attendees. + * each element in delegated-to must be a MAILTO: + */ + JulianPtrArray * m_vsDelegatedTo; + + /** + * the list of delegated-from attendees. + * each element in delegated-from must be a MAILTO: + */ + JulianPtrArray * m_vsDelegatedFrom; + + /* added newer properties 3-23-98 */ + + /** the common name of attendee. Optional, default is "". */ + UnicodeString m_CN; + + /** the language of the common name of the attendee. Optional, default is "". */ + UnicodeString m_Language; + + /** the MAILTO: of a calendar user acting on behalf of the attendee. + * Optional, default is "". + */ + UnicodeString m_SentBy; + + /** the location of the Attendee's directory information. + * Optional, default is "". */ + UnicodeString m_Dir; + + /** the type of the attendee status: STATUS depends on this */ + ICalComponent::ICAL_COMPONENT m_ComponentType; + + DateTime m_DTStamp; + t_int32 m_Sequence; + + /* ---- END OF DATA MEMBERS ---- */ +}; + +#endif /* __ATTENDEE_H_ */ diff --git a/calendar/modules/core/ical/inc/bprprty.h b/calendar/modules/core/ical/inc/bprprty.h new file mode 100644 index 00000000000..c8423835ddb --- /dev/null +++ b/calendar/modules/core/ical/inc/bprprty.h @@ -0,0 +1,120 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +/* + * bprprty.h + * John Sun + * 2/12/98 3:31:14 PM + */ + +#include +#include "sdprprty.h" + +#ifndef __BOOLEANPROPERTY_H_ +#define __BOOLEANPROPERTY_H_ + +/** + * BooleanProperty is a subclass of StandardProperty. It implements the ICalProperty + * interface for ICAL properties with TYPE=BOOLEAN. + */ +class BooleanProperty: public StandardProperty +{ +private: + /** the boolean value of property */ + t_bool m_Boolean; + + /** + * Default constructor + */ + BooleanProperty(); + + /** + * Copy constructor + * @param that property to copy + */ + BooleanProperty(const BooleanProperty & that); +public: + + /** + * Constructor that sets value of property to contents of value + * and makes a copy of the contents of parameters ptr. + * @param value value of property + * @param parameters parameters of property + */ + BooleanProperty(t_bool value, JulianPtrArray * parameters); + + /** + * Destructor + */ + ~BooleanProperty(); + + /** + * Return the value of the property + * @return void * ptr to value of the property + */ + virtual void * getValue() const; + + /** + * Set the value of the property + * @param value the value to set property to + */ + virtual void setValue(void * value); + + /** + * Returns a clone of this property. Clients are responsible for deleting + * the returned object. + * + * @return a clone of this property. + */ + virtual ICalProperty * clone(JLog * initLog); + + /** + * Return TRUE if property is valid, FALSE otherwise + * + * @return TRUE if is valid, FALSE otherwise + */ + virtual t_bool isValid(); + + /** + * Return a string in human-readable form of the property. + * @param out contains output human-readable string + * + * @return the property in its human-readable string format + */ + virtual UnicodeString & toString(UnicodeString & out); + + /** + * Return a string in human-readable form of the property. + * @param dateFmt format string options + * @param out contains output human-readable string + * + * @return the property in its human-readable string format + */ + virtual UnicodeString & toString(UnicodeString & dateFmt, UnicodeString & out); + + /** + * Return the property's string in the ICAL format. + * @param out contains output ICAL string + * + * @return the property in its ICAL string format + */ + virtual UnicodeString & toExportString(UnicodeString & out); +}; + +#endif /* __BOOLEANPROPERTY_H_ */ + diff --git a/calendar/modules/core/ical/inc/bydmgntr.h b/calendar/modules/core/ical/inc/bydmgntr.h new file mode 100644 index 00000000000..1975226f1a4 --- /dev/null +++ b/calendar/modules/core/ical/inc/bydmgntr.h @@ -0,0 +1,124 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +/* + * bydmgntr.h + * John Sun + * 2/3/98 3:06:20 PM + */ + +#ifndef __BYDAYMONTHLYGENERATOR_H_ +#define __BYDAYMONTHLYGENERATOR_H_ + +#include "dategntr.h" +#include "rrday.h" + +/** + * The ByDayMonthlyGenerator class generates dates for the + * BYDAY tag w/ a MONTHLY frequency. + * + * @see DateGenerator + */ +class ByDayMonthlyGenerator : public DateGenerator +{ +public: + + /** + * Default Constructor + */ + ByDayMonthlyGenerator(); + + /** + * Destructor + */ + ~ByDayMonthlyGenerator() {} + + /*---------------------------------------------------------------------*/ + /* --- DateGenerator interface --- */ + + /** + * Returns the interval for which the generator represents. + * @return the interval (DAILY) + */ + virtual t_int32 getInterval() const; + + /** + * Fills in dateVector with DateTime objects that correspond to the + * parameters and start value and the until value. + * DateTime generated should be after start's value and before until's + * value. If until is invalid, ignore it. + * + * @param start the date from which to begin generating recurrences + * @param dateVector storage for the generated dates + * @param until the end date for the recurrence + * + * @return TRUE if until date boundary was reached, FALSE otherwise + */ + virtual t_bool generate(DateTime * start, + JulianPtrArray & dateVector, DateTime * until); + + /** + * Sets the week start parameter. + * @param param the week start value + */ + virtual void setParams(t_int32 param) { m_iWkSt = param; } + + /** + * Sets the RRDay parameters. + * @param params[] the list of RRDay to set to + * @param length the length of params[] + * @see RRDay + */ + virtual void setRDay(RRDay params[], t_int32 length) + { + m_aiParams = params; + m_iParamsLen = length; + } + + /** + * Determines if a generator has been set active. + * Usually tests if parameters have been set or not. + * + * @return TRUE if parameters set, FALSE otherwise. + */ + virtual t_bool active() { return (m_aiParams != 0); } + + /* --- End of DateGenerator interface --- */ + /*---------------------------------------------------------------------*/ + +private: + + /** + * ptr to array of RRDay objects + * @see RRDay + */ + RRDay * m_aiParams; + + /** + * week start value + * @see Calendar + */ + t_int32 m_iWkSt; + +}; + +#endif /* __BYDAYMONTHLYGENERATOR_H_ */ + + + + diff --git a/calendar/modules/core/ical/inc/bydwgntr.h b/calendar/modules/core/ical/inc/bydwgntr.h new file mode 100644 index 00000000000..89063b2b91a --- /dev/null +++ b/calendar/modules/core/ical/inc/bydwgntr.h @@ -0,0 +1,120 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +/* + * bydwgntr.h + * John Sun + * 2/3/98 3:00:42 PM + */ + +#ifndef __BYDAYWEEKLYGENERATOR_H_ +#define __BYDAYWEEKLYGENERATOR_H_ + +#include "dategntr.h" +#include "rrday.h" + +/** + * The ByDayWeeklyGenerator class generates dates for the + * BYDAY tag w/ a Weekly frequency. + * + * @see DateGenerator + */ +class ByDayWeeklyGenerator : public DateGenerator +{ +public: + + /** + * Default Constructor + */ + ByDayWeeklyGenerator(); + + /** + * Destructor + */ + ~ByDayWeeklyGenerator() {} + + /*---------------------------------------------------------------------*/ + /* --- DateGenerator interface --- */ + + /** + * Returns the interval for which the generator represents. + * @return the interval (DAILY) + */ + virtual t_int32 getInterval() const; + + /** + * Fills in dateVector with DateTime objects that correspond to the + * parameters and start value and the until value. + * DateTime generated should be after start's value and before until's + * value. If until is invalid, ignore it. + * + * @param start the date from which to begin generating recurrences + * @param dateVector storage for the generated dates + * @param until the end date for the recurrence + * + * @return TRUE if until date boundary was reached, FALSE otherwise + */ + virtual t_bool generate(DateTime * start, JulianPtrArray & dateVector, DateTime * until); + + /** + * Sets the week start parameter. + * @param param the week start value + */ + virtual void setParams(t_int32 param) { m_iWkSt = param; } + + /** + * Sets the RRDay parameters. + * @param params[] the list of RRDay to set to + * @param length the length of params[] + * @see RRDay + */ + virtual void setRDay(RRDay params[], t_int32 length) + { + m_aiParams = params; + m_iParamsLen = length; + } + + /** + * Determines if a generator has been set active. + * Usually tests if parameters have been set or not. + * + * @return TRUE if parameters set, FALSE otherwise. + */ + virtual t_bool active() { return (m_aiParams != 0); } + + /* --- End of DateGenerator interface --- */ + /*---------------------------------------------------------------------*/ + +private: + + /** + * ptr to array of RRDay objects + * @see RRDay + */ + RRDay * m_aiParams; + + /** + * week start value + * @see Calendar + */ + t_int32 m_iWkSt; + +}; + +#endif /* __BYDAYWEEKLYGENERATOR_H_ */ + diff --git a/calendar/modules/core/ical/inc/bydygntr.h b/calendar/modules/core/ical/inc/bydygntr.h new file mode 100644 index 00000000000..72e440a460f --- /dev/null +++ b/calendar/modules/core/ical/inc/bydygntr.h @@ -0,0 +1,118 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +/* + * bydygntr.h + * John Sun + * 2/3/98 3:10:39 PM + */ + +#ifndef __BYDAYYEARLYGENERATOR_H_ +#define __BYDAYYEARLYGENERATOR_H_ + +#include "dategntr.h" +#include "rrday.h" + + /** + * The ByDayYearlyGenerator class generates dates for the + * BYDAY tag w/ a YEARLY frequency. + * + * @see DateGenerator + */ +class ByDayYearlyGenerator : public DateGenerator +{ +public: + + /** + * Default Constructor + */ + ByDayYearlyGenerator(); + + /** + * Destructor + */ + ~ByDayYearlyGenerator() {} + + /*---------------------------------------------------------------------*/ + /* --- DateGenerator interface --- */ + + /** + * Returns the interval for which the generator represents. + * @return the interval (DAILY) + */ + virtual t_int32 getInterval() const; + + /** + * Fills in dateVector with DateTime objects that correspond to the + * parameters and start value and the until value. + * DateTime generated should be after start's value and before until's + * value. If until is invalid, ignore it. + * + * @param start the date from which to begin generating recurrences + * @param dateVector storage for the generated dates + * @param until the end date for the recurrence + * + * @return TRUE if until date boundary was reached, FALSE otherwise + */ + virtual t_bool generate(DateTime * start, JulianPtrArray & dateVector, DateTime * until); + + /** + * Sets the week start parameter. + * @param param the week start value + */ + void setParams(t_int32 param) { m_iWkSt = param; } + + /** + * Sets the RRDay parameters. + * @param params[] the list of RRDay to set to + * @param length the length of params[] + * @see RRDay + */ + virtual void setRDay(RRDay params[], t_int32 length) + { + m_aiParams = params; + m_iParamsLen = length; + } + + /** + * Determines if a generator has been set active. + * Usually tests if parameters have been set or not. + * + * @return TRUE if parameters set, FALSE otherwise. + */ + virtual t_bool active() { return (m_aiParams != 0); } + + /* --- End of DateGenerator interface --- */ + /*---------------------------------------------------------------------*/ + +private: + + /** + * ptr to array of RRDay objects + * @see RRDay + */ + RRDay * m_aiParams; + + /** + * week start value + * @see Calendar + */ + t_int32 m_iWkSt; +}; + +#endif /* __BYDAYYEARLYGENERATOR_H_ */ diff --git a/calendar/modules/core/ical/inc/byhgntr.h b/calendar/modules/core/ical/inc/byhgntr.h new file mode 100644 index 00000000000..d4db5542790 --- /dev/null +++ b/calendar/modules/core/ical/inc/byhgntr.h @@ -0,0 +1,104 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +/* + * byhgntr.h + * John Sun + * 2/3/98 3:13:16 PM + */ + +#ifndef __BYHOURGENERATOR_H_ +#define __BYHOURGENERATOR_H_ + +#include "dategntr.h" + +/** + * The ByHourGenerator class generates dates for the BYHOUR tag. + * + * @see DateGenerator + */ +class ByHourGenerator : public DateGenerator +{ +public: + + /** + * Default Constructor + */ + ByHourGenerator(); + + /** + * Destructor + */ + ~ByHourGenerator() {} + + /*---------------------------------------------------------------------*/ + /* --- DateGenerator interface --- */ + + /** + * Returns the interval for which the generator represents. + * @return the interval (HOURLY) + */ + virtual t_int32 getInterval() const; + + /** + * Fills in dateVector with DateTime objects that correspond to the + * parameters and start value and the until value. + * DateTime generated should be after start's value and before until's + * value. If until is invalid, ignore it. + * + * @param start the date from which to begin generating recurrences + * @param dateVector storage for the generated dates + * @param until the end date for the recurrence + * + * @return TRUE if until date boundary was reached, FALSE otherwise + */ + virtual t_bool generate(DateTime * start, JulianPtrArray & dateVector, DateTime * until); + + /** + * Sets the hour (i.e. -23 - +23) parameters. + * @param params[] the list of hours to set to + * @param length the length of params[] + */ + virtual void setParamsArray(t_int32 params[], t_int32 length) + { + m_aiParams = params; + m_iParamsLen = length; + } + + /** + * Determines if a generator has been set active. + * Usually tests if parameters have been set or not. + * + * @return TRUE if parameters set, FALSE otherwise. + */ + virtual t_bool active() + { + return (m_aiParams != 0); + } + + /* --- End of DateGenerator interface --- */ + /*---------------------------------------------------------------------*/ + +private: + + /** hour parameters */ + t_int32 * m_aiParams; +}; + +#endif /* __BYHOURGENERATOR_H_ */ + diff --git a/calendar/modules/core/ical/inc/bymdgntr.h b/calendar/modules/core/ical/inc/bymdgntr.h new file mode 100644 index 00000000000..d3556a7f214 --- /dev/null +++ b/calendar/modules/core/ical/inc/bymdgntr.h @@ -0,0 +1,103 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +/* + * bymdgntr.h + * John Sun + * 2/3/98 3:19:58 PM + */ + +#ifndef __BYMONTHDAYGENERATOR_H_ +#define __BYMONTHDAYGENERATOR_H_ + +#include "dategntr.h" + +/** + * The ByMonthDayGenerator class generates dates for the BYMONTHDAY tag. + * + * @see DateGenerator + */ +class ByMonthDayGenerator : public DateGenerator +{ +public: + + /** + * Default Constructor + */ + ByMonthDayGenerator(); + + /** + * Destructor + */ + ~ByMonthDayGenerator() {} + + /*---------------------------------------------------------------------*/ + /* --- DateGenerator interface --- */ + + /** + * Returns the interval for which the generator represents. + * @return the interval (DAILY) + */ + virtual t_int32 getInterval() const; + + /** + * Fills in dateVector with DateTime objects that correspond to the + * parameters and start value and the until value. + * DateTime generated should be after start's value and before until's + * value. If until is invalid, ignore it. + * + * @param start the date from which to begin generating recurrences + * @param dateVector storage for the generated dates + * @param until the end date for the recurrence + * + * @return TRUE if until date boundary was reached, FALSE otherwise + */ + virtual t_bool generate(DateTime * start, JulianPtrArray & dateVector, DateTime * until); + + /** + * Sets the dates in month (i.e. -31 - +31) parameters. + * @param params[] the list of dates in month to set to + * @param length the length of params[] + */ + virtual void setParamsArray(t_int32 params[], t_int32 length) + { + m_aiParams = params; + m_iParamsLen = length; + } + + /** + * Determines if a generator has been set active. + * Usually tests if parameters have been set or not. + * + * @return TRUE if parameters set, FALSE otherwise. + */ + virtual t_bool active() { return (m_aiParams != 0); } + + /* --- End of DateGenerator interface --- */ + /*---------------------------------------------------------------------*/ + +private: + + /** dates in month parameters */ + t_int32 * m_aiParams; + +}; + +#endif /* __BYMONTHDAYGENERATOR_H_ */ + + diff --git a/calendar/modules/core/ical/inc/bymgntr.h b/calendar/modules/core/ical/inc/bymgntr.h new file mode 100644 index 00000000000..6dabb1827de --- /dev/null +++ b/calendar/modules/core/ical/inc/bymgntr.h @@ -0,0 +1,102 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +/* + * bymgntr.h + * John Sun + * 2/3/98 2:59:55 PM + */ + +#ifndef __BYMINUTEGENERATOR_H_ +#define __BYMINUTEGENERATOR_H_ + +#include "dategntr.h" + +/** + * The ByMinuteGenerator class generates dates for the BYMINUTE tag. + * + * @see DateGenerator + */ +class ByMinuteGenerator : public DateGenerator +{ +public: + + /** + * Default Constructor + */ + ByMinuteGenerator(); + + /** + * Destructor + */ + ~ByMinuteGenerator() {} + + /*---------------------------------------------------------------------*/ + /* --- DateGenerator interface --- */ + + /** + * Returns the interval for which the generator represents. + * @return the interval (MINUTELY) + */ + virtual t_int32 getInterval() const; + + /** + * Fills in dateVector with DateTime objects that correspond to the + * parameters and start value and the until value. + * DateTime generated should be after start's value and before until's + * value. If until is invalid, ignore it. + * + * @param start the date from which to begin generating recurrences + * @param dateVector storage for the generated dates + * @param until the end date for the recurrence + * + * @return TRUE if until date boundary was reached, FALSE otherwise + */ + virtual t_bool generate(DateTime * start, JulianPtrArray & dateVector, DateTime * until); + + /** + * Sets the minute (i.e. -59 - +59) parameters. + * @param params[] the list of minutes to set to + * @param length the length of params[] + */ + virtual void setParamsArray(t_int32 params[], t_int32 length) + { + m_aiParams = params; + m_iParamsLen = length; + } + + /** + * Determines if a generator has been set active. + * Usually tests if parameters have been set or not. + * + * @return TRUE if parameters set, FALSE otherwise. + */ + virtual t_bool active() { return (m_aiParams != 0); } + + /* --- End of DateGenerator interface --- */ + /*---------------------------------------------------------------------*/ + +private: + + /** minute parameters */ + t_int32 * m_aiParams; +}; + +#endif /* __BYMINUTEGENERATOR_H_ */ + + diff --git a/calendar/modules/core/ical/inc/bymogntr.h b/calendar/modules/core/ical/inc/bymogntr.h new file mode 100644 index 00000000000..493936acc57 --- /dev/null +++ b/calendar/modules/core/ical/inc/bymogntr.h @@ -0,0 +1,103 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +/* + * bymogntr.h + * John Sun + * 2/3/98 3:19:43 PM + */ + +#ifndef __BYMONTHGENERATOR_H_ +#define __BYMONTHGENERATOR_H_ + +#include "dategntr.h" + +/** + * The ByMonthGenerator class generates dates for the BYMONTH tag. + * + * @see DateGenerator + */ +class ByMonthGenerator : public DateGenerator +{ +public: + + /** + * Default Constructor + */ + ByMonthGenerator(); + + /** + * Destructor + */ + ~ByMonthGenerator() {} + + /*---------------------------------------------------------------------*/ + /* --- DateGenerator interface --- */ + + /** + * Returns the interval for which the generator represents. + * @return the interval (MONTHLY) + */ + virtual t_int32 getInterval() const; + + /** + * Fills in dateVector with DateTime objects that correspond to the + * parameters and start value and the until value. + * DateTime generated should be after start's value and before until's + * value. If until is invalid, ignore it. + * + * @param start the date from which to begin generating recurrences + * @param dateVector storage for the generated dates + * @param until the end date for the recurrence + * + * @return TRUE if until date boundary was reached, FALSE otherwise + */ + virtual t_bool generate(DateTime * start, JulianPtrArray & dateVector, DateTime * until); + + /** + * Sets the month (i.e. -12 - +12) parameters. + * @param params[] the list of months to set to + * @param length the length of params[] + */ + virtual void setParamsArray(t_int32 params[], t_int32 length) + { + m_aiParams = params; + m_iParamsLen = length; + } + + /** + * Determines if a generator has been set active. + * Usually tests if parameters have been set or not. + * + * @return TRUE if parameters set, FALSE otherwise. + */ + virtual t_bool active() { return (m_aiParams != 0); } + + /* --- End of DateGenerator interface --- */ + /*---------------------------------------------------------------------*/ + +private: + + /** month parameters */ + t_int32 * m_aiParams; + +}; + +#endif /* __BYMONTHGENERATOR_H_ */ + + diff --git a/calendar/modules/core/ical/inc/bywngntr.h b/calendar/modules/core/ical/inc/bywngntr.h new file mode 100644 index 00000000000..2b753abb9a3 --- /dev/null +++ b/calendar/modules/core/ical/inc/bywngntr.h @@ -0,0 +1,101 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +/* + * bywngntr.h + * John Sun + * 2/3/98 3:19:13 PM + */ + +#ifndef __BYWEEKNOGENERATOR_H_ +#define __BYWEEKNOGENERATOR_H_ + +#include "dategntr.h" + +/** + * The ByWeekNoGenerator class generates dates for the BYWEEKNO tag. + * + * @see DateGenerator + */ +class ByWeekNoGenerator : public DateGenerator +{ +public: + + /** + * Default Constructor + */ + ByWeekNoGenerator(); + + /** + * Destructor + */ + ~ByWeekNoGenerator() {} + + /*---------------------------------------------------------------------*/ + /* --- DateGenerator interface --- */ + + /** + * Returns the interval for which the generator represents. + * @return the interval (WEEKLY) + */ + virtual t_int32 getInterval() const; + + /** + * Fills in dateVector with DateTime objects that correspond to the + * parameters and start value and the until value. + * DateTime generated should be after start's value and before until's + * value. If until is invalid, ignore it. + * + * @param start the date from which to begin generating recurrences + * @param dateVector storage for the generated dates + * @param until the end date for the recurrence + * + * @return TRUE if until date boundary was reached, FALSE otherwise + */ + virtual t_bool generate(DateTime * start, JulianPtrArray & dateVector, DateTime * until); + + /** + * Sets the week number (i.e. -53 - +53) parameters. + * @param params[] the list of weeks to set to + * @param length the length of params[] + */ + virtual void setParamsArray(t_int32 params[], t_int32 length) + { + m_aiParams = params; + m_iParamsLen = length; + } + + /** + * Determines if a generator has been set active. + * Usually tests if parameters have been set or not. + * + * @return TRUE if parameters set, FALSE otherwise. + */ + virtual t_bool active() { return (m_aiParams != 0); } + + /* --- End of DateGenerator interface --- */ + /*---------------------------------------------------------------------*/ + +private: + + /** week parameters */ + t_int32 * m_aiParams; +}; + +#endif /* __BYWEEKNOGENERATOR_H_ */ + diff --git a/calendar/modules/core/ical/inc/byydgntr.h b/calendar/modules/core/ical/inc/byydgntr.h new file mode 100644 index 00000000000..b50c0738d43 --- /dev/null +++ b/calendar/modules/core/ical/inc/byydgntr.h @@ -0,0 +1,102 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +/* + * byydgntr.h + * John Sun + * 2/3/98 3:41:44 PM + */ + +#ifndef __BYYEARDAYGENERATOR_H_ +#define __BYYEARDAYGENERATOR_H_ + +#include "dategntr.h" + +/** + * The ByYearDayGenerator class generates dates for the BYYEARDAY tag. + * + * @see DateGenerator + */ +class ByYearDayGenerator : public DateGenerator +{ +public: + + /** + * Default Constructor + */ + ByYearDayGenerator(); + + /** + * Destructor + */ + ~ByYearDayGenerator() {} + + /*---------------------------------------------------------------------*/ + /* --- DateGenerator interface --- */ + + /** + * Returns the interval for which the generator represents. + * @return the interval (DAILY) + */ + virtual t_int32 getInterval() const; + + /** + * Fills in dateVector with DateTime objects that correspond to the + * parameters and start value and the until value. + * DateTime generated should be after start's value and before until's + * value. If until is invalid, ignore it. + * + * @param start the date from which to begin generating recurrences + * @param dateVector storage for the generated dates + * @param until the end date for the recurrence + * + * @return TRUE if until date boundary was reached, FALSE otherwise + */ + virtual t_bool generate(DateTime * start, JulianPtrArray & dateVector, DateTime * until); + + /** + * Sets the dates in year (i.e. -366 - +366) parameters. + * @param params[] the list of dates in year to set to + * @param length the length of params[] + */ + virtual void setParamsArray(t_int32 params[], t_int32 length) + { + m_aiParams = params; + m_iParamsLen = length; + } + + /** + * Determines if a generator has been set active. + * Usually tests if parameters have been set or not. + * + * @return TRUE if parameters set, FALSE otherwise. + */ + virtual t_bool active() { return (m_aiParams != 0); } + + /* --- End of DateGenerator interface --- */ + /*---------------------------------------------------------------------*/ + +private: + + /** dates in year parameters */ + t_int32 * m_aiParams; + +}; + +#endif /* __BYYEARDAYGENERATOR_H_ */ + diff --git a/calendar/modules/core/ical/inc/capiredr.h b/calendar/modules/core/ical/inc/capiredr.h new file mode 100644 index 00000000000..14e0a02eddc --- /dev/null +++ b/calendar/modules/core/ical/inc/capiredr.h @@ -0,0 +1,170 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +/* + * capiredr.h + * John Sun + * 4/16/98 3:31:51 PM + */ +#ifndef __ICALCAPIREADER_H_ +#define __ICALCAPIREADER_H_ + +/*#ifdef XP_WIN +#ifndef CAPI_READY +#define CAPI_READY +#endif +#endif*/ + +#include "jdefines.h" +#include +#include "ptrarray.h" +#include "icalredr.h" +#include "prmon.h" +#include "jutility.h" +/** + * ICalCAPIReader is a subclass of ICalReader. It implements + * the ICalReader interface to work with CAPI callback method + * to parse from stream. + * Uses multiple threads. + */ +class ICalCAPIReader +{ +private: + /*----------------------------- + ** MEMBERS + **---------------------------*/ + /* current buffer of iCal information, + * when CAPI has information to return to + * the buffer, it must append to this buffer + * when no more full-lines can be made from the + * buffer, block on the monitor. Will be + * notified when CAPI gets back more information + */ + char * m_Buffer; + t_int32 m_BufferSize; + t_bool m_Init; + t_int32 m_Mark; + t_int32 m_ChunkMark; + t_int32 m_Pos; + t_int32 m_ChunkIndex; + + /** encoding of stream */ + JulianUtility::MimeEncoding m_Encoding; + + JulianPtrArray * m_Chunks; + + static const t_int32 m_MAXBUFFERSIZE; + static const t_int32 m_NOMORECHUNKS; + + /* finished getting input from CAPI callback */ + t_bool m_bFinished; + + PRMonitor * m_Monitor; + /*----------------------------- + ** PRIVATE METHODS + **---------------------------*/ + + UnicodeString & createLine(t_int32 oldPos, t_int32 oldChunkIndex, + t_int32 newPos, t_int32 newChunkIndex, UnicodeString & aLine); + + static void deleteUnicodeStringVector(JulianPtrArray * stringVector); + + ICalCAPIReader(); +public: + /*----------------------------- + ** CONSTRUCTORS and DESTRUCTORS + **---------------------------*/ + ICalCAPIReader(PRMonitor * monitor, + JulianUtility::MimeEncoding encoding = JulianUtility::MimeEncoding_7bit); + virtual ~ICalCAPIReader(); + + /*----------------------------- + ** ACCESSORS (GET AND SET) + **---------------------------*/ + + virtual void * getMonitor() { return m_Monitor; } + + void setFinished() { m_bFinished = TRUE; } + void setEncoding(JulianUtility::MimeEncoding encoding) { m_Encoding = encoding; } + t_bool isFinished() const { return m_bFinished; } + /** + * Sets a the buffer to read from. + * Appends the m_Buffer. + */ + /*virtual void setBuffer(const char * capiChunk);*/ + + + /** + * Don't delete u until this object is deleted. + * @param UnicodeString * u + * + * @return void + */ + void AddChunk(UnicodeString * u); + + /*----------------------------- + ** UTILITIES + **---------------------------*/ + + void mark() { m_Mark = m_Pos; m_ChunkMark = m_ChunkIndex;} + + void reset() { m_Pos = m_Mark; m_ChunkIndex = m_ChunkMark;} + + /** + * Read next character from file. + * + * @param status, return 1 if no more characters + * @return next character of string + */ + virtual t_int8 read(ErrorCode & status); + + + + /** + * Read the next ICAL full line of the file. The definition + * of a full ICAL line can be found in the ICAL spec. + * Basically, a line followed by a CRLF and a space character + * signifies that the next line is a continuation of the previous line. + * Uses the readLine, read methods. + * + * @param aLine, returns next full line of string + * @param status, return 1 if no more lines + * + * @return next full line of string + */ + virtual UnicodeString & readFullLine(UnicodeString & aLine, ErrorCode & status, t_int32 i = 0); + + /** + * Read next line of file. A line is defined to be + * characters terminated by either a '\n', '\r' or "\r\n". + * @param aLine, return next line of string + * @param status, return 1 if no more lines + * + * @return next line of string + */ + virtual UnicodeString & readLine(UnicodeString & aLine, ErrorCode & status); +public: + + /*virtual UnicodeString & readLineZero(UnicodeString & aLine, ErrorCode & status);*/ + + + +}; + +#endif /* __ICALCAPIREADER_H_ */ + diff --git a/calendar/modules/core/ical/inc/dategntr.h b/calendar/modules/core/ical/inc/dategntr.h new file mode 100644 index 00000000000..d7ca3145bf9 --- /dev/null +++ b/calendar/modules/core/ical/inc/dategntr.h @@ -0,0 +1,166 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +/* + * dategntr.h + * John Sun + * 2/3/98 2:57:44 PM + */ + +#ifndef __DATEGENERATOR_H_ +#define __DATEGENERATOR_H_ + +#include +#include "nspr.h" +#include "ptypes.h" +#include "datetime.h" +#include "ptrarray.h" +#include "rrday.h" + +/** + * The DateGenerator class defines an interface that provides a basic + * call structure for a BYxxx tag. + * DateGenerators are combined in the context of a Recurrence object + * to create more specialized and versatile date recurrences. + * + * @see DateGenerator + */ +class DateGenerator +{ +public: + + + /** + * Virtual Destructor. + */ + virtual ~DateGenerator() {} + + /** + * Returns the interval for which the generator spans. + * (i.e. a year, a month, a week, etc) + * + * @return the generator's interval + */ + t_int32 getSpan() const { return m_iSpan; } + + /** + * Sets the generation interval. + * (i.e. minutely, hourly, daily, weekly, monthly, yearly) + * @param span span value to set to. + */ + void setSpan(t_int32 span) { m_iSpan = span; } + + /*---------------------------------------------------------------------*/ + /* --- DateGenerator interface --- */ + + /** + * Pure virtual. Returns the interval for which the generator represents. + * @return the interval (DAILY) + */ + virtual t_int32 getInterval() const { PR_ASSERT(FALSE); return -1;} + + /** + * Pure virtual. Fills in dateVector with DateTime objects that correspond to the + * parameters and start value and the until value. + * DateTime generated should be after start's value and before until's + * value. If until is invalid, ignore it. + * + * @param start the date from which to begin generating recurrences + * @param dateVector storage for the generated dates + * @param until the end date for the recurrence + * + * @return TRUE if until date boundary was reached, FALSE otherwise + */ + virtual t_bool generate(DateTime * startDate, + JulianPtrArray & dateVector, DateTime * until) + { + /* PR_ASSERT(FALSE); */ + if (startDate) {} + if (until) {} + if (dateVector.GetSize() == 0) {} + return FALSE; + } + + /** + * Pure virtual. A general method to set a single parameter. + * Usually sets the week start parameter. + * @param param the week start value + */ + virtual void setParams(t_int32 param) + { + if (param == 0) {} + } + + /** + * Pure virtual. A general method to set a list of parameters. + * @param params[] a list of parameters + * @param length the length of params[] + * + */ + virtual void setParamsArray(t_int32 params[], t_int32 length) + { + if (params != 0) {} + if (length == 0) {} + } + + /** + * A general method to set a list of lists of parameters for a DateGenerator. + */ + virtual void setRDay(RRDay params[], t_int32 length) + { + /* PR_ASSERT(FALSE); */ + if (params != 0) {} + if (length == 0) {} + } + + /** + * Pure virtual. Determines if a generator has been set active. + * Usually tests if parameters have been set or not. + * + * @return TRUE if generator is active, FALSE otherwise. + */ + virtual t_bool active() { PR_ASSERT(FALSE); return FALSE; } + + /* --- End of DateGenerator interface --- */ + /*---------------------------------------------------------------------*/ + +protected: + + /** + * Constructor sets span, parameters length. + * @param span initial span value + * @param paramsLen initial parameters length value + */ + DateGenerator(t_int32 span, t_int32 paramsLen = 0); + + /** span value */ + t_int32 m_iSpan; + + /** parameters length */ + t_int32 m_iParamsLen; + +private: + + /** hide default constructor */ + DateGenerator(); + +}; + +#endif /* __DATEGENERATOR_H_ */ + + diff --git a/calendar/modules/core/ical/inc/deftgntr.h b/calendar/modules/core/ical/inc/deftgntr.h new file mode 100644 index 00000000000..74426ff367e --- /dev/null +++ b/calendar/modules/core/ical/inc/deftgntr.h @@ -0,0 +1,110 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +/* + * deftgntr.h + * John Sun + * 2/3/98 3:46:49 PM + */ + +#ifndef __DEFAULTGENERATOR_H_ +#define __DEFAULTGENERATOR_H_ + +#include "dategntr.h" + +/** + * The DefaultGenerator class generates dates for rules w/o BYxxx tags. + * + * @see DateGenerator + */ +class DefaultGenerator : public DateGenerator +{ +public: + + /** + * Default Constructor + */ + DefaultGenerator(); + + /** + * Destructor + */ + ~DefaultGenerator() {} + + /*---------------------------------------------------------------------*/ + /* --- DateGenerator interface --- */ + + /** + * Returns the interval for which the generator represents. + * @return the interval (MONTHLY) + */ + virtual t_int32 getInterval() const; + + /** + * Fills in dateVector with DateTime objects that correspond to the + * parameters and start value and the until value. + * DateTime generated should be after start's value and before until's + * value. If until is invalid, ignore it. + * + * @param start the date from which to begin generating recurrences + * @param dateVector storage for the generated dates + * @param until the end date for the recurrence + * + * @return TRUE if until date boundary was reached, FALSE otherwise + */ + virtual t_bool generate(DateTime * start, JulianPtrArray & dateVector, DateTime * until); + + /** + * Sets the week start parameter. + * @param param the week start value + */ + virtual void setParams(t_int32 param) { m_iSpan = m_aiParams[2] = param; } + + /** + * Sets the span, count, interval parameters. TODO: move to the .cpp file. + * @param params[] the list of parameters to set to + * @param length the length of params[] + */ + virtual void setParamsArray(t_int32 params[], t_int32 length) + { + isActive = TRUE; + t_int32 i; + for (i = 0; i < length; i++) + m_aiParams[i] = params[i]; + } + /** + * Determines if a generator has been set active. + * + * @return TRUE if isActive in On, FALSE otherwise + */ + virtual t_bool active() { return isActive; } + + /* --- End of DateGenerator interface --- */ + /*---------------------------------------------------------------------*/ + +private: + + /** whether generator's parameters have been set by client */ + t_bool isActive; + + /** contains span, interval, count as parameters */ + t_int32 m_aiParams[3]; +}; + +#endif /* __DEFAULTGENERATOR_H_ */ + diff --git a/calendar/modules/core/ical/inc/dprprty.h b/calendar/modules/core/ical/inc/dprprty.h new file mode 100644 index 00000000000..b722ccabf5a --- /dev/null +++ b/calendar/modules/core/ical/inc/dprprty.h @@ -0,0 +1,153 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +/* + * dprprty.h + * John Sun + * 2/12/98 3:16:32 PM + */ + +#include +#include "sdprprty.h" +#include "datetime.h" + +#ifndef __DATETIMEPROPERTY_H_ +#define __DATETIMEPROPERTY_H_ + +/** + * DateTimeProperty is a subclass of StandardProperty. It implements the ICalProperty + * interface for ICAL properties with TYPE=DATETIME or TYPE=DATE. + */ +class DateTimeProperty: public StandardProperty +{ +private: + + /** the DateTime value of the property */ + DateTime m_DateTime; + + /** + * Default constructor + */ + DateTimeProperty(); + + /** + * Copy constructor + * @param that property to copy + */ + DateTimeProperty(const DateTimeProperty & that); +public: + + /** + * Constructor that sets value of property to contents of value + * and makes a copy of the contents of parameters ptr. + * @param value value of property + * @param parameters parameters of property + */ + DateTimeProperty(DateTime value, JulianPtrArray * parameters); + + /** + * Destructor + */ + ~DateTimeProperty(); + + /** + * Return the value of the property + * @return void * ptr to value of the property + */ + virtual void * getValue() const; + + /** + * Set the value of the property + * @param value the value to set property to + */ + virtual void setValue(void * value); + + /** + * Returns a clone of this property. Clients are responsible for deleting + * the returned object. + * + * @return a clone of this property. + */ + virtual ICalProperty * clone(JLog * initLog); + + /** + * Return TRUE if property is valid, FALSE otherwise + * + * @return TRUE if is valid, FALSE otherwise + */ + virtual t_bool isValid(); + + /** + * Return a string in human-readable form of the property. + * @param out contains output human-readable string + * + * @return the property in its human-readable string format + */ + virtual UnicodeString & toString(UnicodeString & out); + + /** + * Return a string in human-readable form of the property. For DateTimes, + * dateFmt would contain the a DateFormat string (i.e "MM/dd/yy hh:mm:ss a"). + * @param dateFmt format string options + * @param out contains output human-readable string + * + * @return the property in its human-readable string format + */ + virtual UnicodeString & toString(UnicodeString & dateFmt, UnicodeString & out); + + /** + * Return the property's string in the ICAL format. For DateTimes, this + * would be the ISO8601 UTC date format of the datetime (i.e. 19971110T112233Z). + * @param out contains output ICAL string + * + * @return the property in its ICAL string format + */ + virtual UnicodeString & toExportString(UnicodeString & out); + + /** + * Returns the property's ICAL format strings, + * to output string of the form + * :value or ;param1;param2;param3(etc.):value + * ONLY: DateTimeProperty overrides this + * (This is too handle NOT printing VALUE and TZID parameters) + * + * @param out output ICAL string + * + * @return output ICAL string (out) + */ + UnicodeString & toICALString(UnicodeString & out); + + /** + * Returns the property's ICAL format strings, inserting + * sProp (property name) to output string of the form + * sProp:value or sProp;param1;param2;param3(etc.):value + * ONLY: DateTimeProperty overrides this + * (This is too handle NOT printing VALUE and TZID parameters) + * + * @param sProp property name of property + * @param out output ICAL string + * + * @return output ICAL string (out) + */ + UnicodeString & toICALString(UnicodeString & sProp, + UnicodeString & out); +}; + +#endif /* __DATETIMEPROPERTY_H_ */ + + diff --git a/calendar/modules/core/ical/inc/duprprty.h b/calendar/modules/core/ical/inc/duprprty.h new file mode 100644 index 00000000000..35e6f44c444 --- /dev/null +++ b/calendar/modules/core/ical/inc/duprprty.h @@ -0,0 +1,121 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +/* + * duprprty.h + * John Sun + * 2/12/98 3:37:06 PM + */ + +#include +#include "sdprprty.h" +#include "duration.h" + +#ifndef __DURATIONPROPERTY_H_ +#define __DURATIONPROPERTY_H_ + +/** + * DurationProperty is a subclass of StandardProperty. It implements the ICalProperty + * interface for ICAL properties with TYPE=DURATION. + */ +class DurationProperty: public StandardProperty +{ +private: + /** the Julian_Duration value of the property */ + Julian_Duration m_Duration; + + /** + * Default constructor + */ + DurationProperty(); + + /** + * Copy constructor + * @param that property to copy + */ + DurationProperty(const DurationProperty & that); +public: + + /** + * Constructor that sets value of property to contents of value + * and makes a copy of the contents of parameters ptr. + * @param value value of property + * @param parameters parameters of property + */ + DurationProperty(Julian_Duration value, JulianPtrArray * parameters); + + /** + * Destructor + */ + ~DurationProperty(); + + /** + * Return the value of the property + * @return void * ptr to value of the property + */ + virtual void * getValue() const; + + /** + * Set the value of the property + * @param value the value to set property to + */ + virtual void setValue(void * value); + + /** + * Returns a clone of this property. Clients are responsible for deleting + * the returned object. + * + * @return a clone of this property. + */ + virtual ICalProperty * clone(JLog * initLog); + + /** + * Return TRUE if property is valid, FALSE otherwise + * + * @return TRUE if is valid, FALSE otherwise + */ + virtual t_bool isValid(); + + /** + * Return a string in human-readable form of the property. + * @param out contains output human-readable string + * + * @return the property in its human-readable string format + */ + virtual UnicodeString & toString(UnicodeString & out); + + /** + * Return a string in human-readable form of the property. + * @param dateFmt format string options + * @param out contains output human-readable string + * + * @return the property in its human-readable string format + */ + virtual UnicodeString & toString(UnicodeString & dateFmt, UnicodeString & out); + + /** + * Return the property's string in the ICAL format. + * @param out contains output ICAL string + * + * @return the property in its ICAL string format + */ + virtual UnicodeString & toExportString(UnicodeString & out); +}; + +#endif /* __DURATIONPROPERTY_H_ */ + diff --git a/calendar/modules/core/ical/inc/freebusy.h b/calendar/modules/core/ical/inc/freebusy.h new file mode 100644 index 00000000000..00f6a18471e --- /dev/null +++ b/calendar/modules/core/ical/inc/freebusy.h @@ -0,0 +1,435 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +/* + * freebusy.h + * John Sun + * 2/18/98 1:35:51 PM + */ + +#ifndef __FREEBUSY_H_ +#define __FREEBUSY_H_ + +#include +#include "datetime.h" +#include "period.h" +#include "prprty.h" +#include "jlog.h" +#include "julnstr.h" + +/** + * The Freebusy class encapsulates the data in the iCalendar + * FREEBUSY property. A Freebusy contains two parameters, a TYPE and BSTAT + * parameters. These are repesented by the enumerations (FB_TYPE). + * (FB_STATUS ifdef'd out 4-28-98). + * The Freebusy must contain periods, which are contained in a vector of periods. + */ +class Freebusy: public ICalProperty +{ +public: + + /* 4-28-98 combine TYPE and STATUS into just TYPE */ +#if 0 + /** enumeration of TYPE parameters */ + enum FB_TYPE{FB_TYPE_BUSY = 0, FB_TYPE_FREE = 1, + FB_TYPE_LENGTH = 2, FB_TYPE_INVALID = -1 + }; + + /** enumeration of BSTAT parameters */ + enum FB_STATUS{FB_STATUS_BUSY = 0, FB_STATUS_UNAVAILABLE = 1, + FB_STATUS_TENTATIVE = 2, + FB_STATUS_LENGTH = 3, FB_STATUS_INVALID = -1 + }; + + /** list acceptable keywords properties in a FREEBUSY */ + enum FB_PROPS{FB_PROPS_TYPE = 0, FB_PROPS_STATUS}; +#else + /** enumeration of TYPE parameters */ + enum FB_TYPE{FB_TYPE_BUSY = 0, FB_TYPE_FREE = 1, + FB_TYPE_BUSY_UNAVAILABLE = 2, FB_TYPE_BUSY_TENTATIVE = 3, + FB_TYPE_XPARAMVAL = 4, + FB_TYPE_LENGTH = 5, FB_TYPE_INVALID = -1}; + + /** list acceptable keywords properties in a FREEBUSY */ + enum FB_PROPS{FB_PROPS_TYPE = 0}; +#endif + + /** + * Converts TYPE string to a FB_TYPE enumeration value + * @param sType type string + * + * @return FB_TYPE that represents that string + */ + static Freebusy::FB_TYPE stringToType(UnicodeString & sType); + + /** + * Converts FB_TYPE to string. If bad type, return default (BUSY). + * @param type FB_TYPE enumeration value + * @param out output type string + * + * @return output type string (out) + */ + static UnicodeString & typeToString(Freebusy::FB_TYPE type, UnicodeString & out); + +#if 0 + /** + * Converts BSTAT string to a FB_STATUS enumeration + * @param sStatus status string + * + * @return FB_STATUS that represents that string + */ + static Freebusy::FB_STATUS stringToStatus(UnicodeString & sType); + + /** + * Converts FB_STATUS to string. If bad status, return default (BUSY). + * @param attstat FB_STATUS enumeration value + * @param out output BSTAT string + * + * @return output BSTAT string (out) + */ + static UnicodeString & statusToString(Freebusy::FB_STATUS status, UnicodeString & out); +#endif + +private: + +#if 0 + /** default FB_STATUS value */ + static const t_int32 ms_iDEFAULT_STATUS; +#endif + + /** default FB_TYPE value */ + static const t_int32 ms_iDEFAULT_TYPE; + + /* DATA-MEMBERS */ + /* storing type and status as ints instead of strings */ + + /** type value. Default is FB_TYPE_BUSY. */ + t_int32 m_Type; + +#if 0 + /** bstat value. Default is FB_STATUS_BUSY. */ + t_int32 m_Status; +#endif + + /** vector of freebusy periods */ + JulianPtrArray * m_vPeriod; + + /** ptr to log file to write errors to */ + JLog * m_Log; + + JulianString m_sCurl; /* cal url where this curl is stored, may be an empty string */ + + /* characters for printing Freebusy parameters */ + static const t_int32 ms_cFreebusyType;/* = 'T';*/ + static const t_int32 ms_cFreebusyPeriod;/* = 'P';*/ +#if 0 + static const t_int32 ms_cFreebusyStatus;/* = 'S';*/ +#endif + + + /* -- private methods -- */ + + /** + * convert a character to the content of a parameter in + * human-readable string format + * + * @param c a character represents a parameter + * @return parameter in a string + */ + UnicodeString & toStringChar(t_int32 c, UnicodeString & out); + + /** + * Helper method to parse a string of periods. + * @param s string containing periods + * @param vTimeZones vector of timezones (usually 0) + */ + void parsePeriod(UnicodeString & s, JulianPtrArray * vTimeZones); + + /** + * Sets parameter with name paramName with value paramVal. + * @param paramName parameter name to set + * @param paramVal new value of parameter + */ + void setParam(UnicodeString & paramName, UnicodeString & paramVal); + + /** + * Fixes data-members are so that they are valid. If properties + * are invalid, then it will set it to defaults. + */ + void selfCheck(); + + /** + * Sets default value for property + * @param prop property to set default value + */ + void setDefaultProps(Freebusy::FB_PROPS prop); + + /** + * Sort the periods vector by the starting time of periods. + */ + void sortPeriods(); + + /** + * Sort the periods vector by the ending time of the periods. + */ + void sortPeriodsByEndTime(); + +#if 0 + /** + * Default constructor. Hide from clients. + */ + Freebusy(); +#endif + + /** + * Copy constructor. + * @param that Freebusy to copy + */ + Freebusy(Freebusy & that); + +public: + + /** + * Constructor. Also sets log file to write errors to. + * @param initLog log file to write errors to + */ + Freebusy(JLog * initLog = 0); + + /** + * Destructor + */ + ~Freebusy(); + + /*---------- To satisfy ICalProperty interface ----------*/ + /** + * Sets parameters. + * @param parameters vector of parameters to set + * + */ + virtual void setParameters(JulianPtrArray * parameters); + + /** + * Return value of property. Never use. Use getPeriod(). + * + * @return value of property + */ + virtual void * getValue() const { PR_ASSERT(FALSE); return 0; } + + /** + * Sets value of property. Never use. Use addPeriod(). + * @param value new value of property + * + */ + virtual void setValue(void * value) {PR_ASSERT(FALSE); if(value){} } + + /** + * Returns a clone of this property. + * @param initLog the log file for clone to write to + * + * @return clone of this ICalProperty object + */ + virtual ICalProperty * clone(JLog * initLog); + + /** + * Checks whether this property is valid or not. Period vector size + * must be greater than 0 to be TRUE. + * + * @return TRUE if property is valid, FALSE otherwise + */ + virtual t_bool isValid(); + + /** + * Return property to human-readable string. + * @param dateFmt formatting string + * @param out output human-readable string + * + * @return output human-readable string (out) + */ + virtual UnicodeString & toString(UnicodeString & strFmt, UnicodeString & out); + + /** + * Return property to human-readable string. + * @param out output human-readable string + * + * @return output human-readable string (out) + */ + virtual UnicodeString & toString(UnicodeString & out); + + /** + * Return property to iCal property string. + * @param out output iCal string + * + * @return output iCal string (out) + */ + virtual UnicodeString & toICALString(UnicodeString & out); + + /** + * Return property to iCal property string. Inserts sProp to + * front of output string. sProp should be the property name of this + * property. + * @param sProp property name to append to insert at front of out + * @param out output iCal string with sProp in front + * + * @return output iCal string with sProp in front (out) + */ + virtual UnicodeString & toICALString(UnicodeString & sProp, UnicodeString & out); + /*----------End of ICalProperty interface----------*/ + + /** + * Returns FB_TYPE value. + * + * @return FB_TYPE value + */ + Freebusy::FB_TYPE getType() const { return (Freebusy::FB_TYPE) m_Type; } + + /** + * Sets FB_TYPE. + * @param i new FB_TYPE value + * + */ + void setType(FB_TYPE type) {m_Type = type;} + +#if 0 + /** + * Returns FB_STATUS value. + * + * @return FB_STATUS value + */ + Freebusy::FB_STATUS getStatus() const { return (Freebusy::FB_STATUS) m_Status; } + + /** + * Sets FB_STATUS. + * @param i new FB_STATUS value + * + */ + void setStatus(FB_STATUS status) {m_Status = status;} +#endif + + /** + * Return vector of periods. + * + * @return vector of periods + */ + JulianPtrArray * getPeriod() const { return m_vPeriod; } + + + /** + * Adds a period to period vector. It makes a copy of the period. + * So client must delete p. Freebusy does NOT take ownership of p. + * @param p period to add to vector + */ + void addPeriod(Period * p); + + /** + * Adds each period in argument vector to this Freebusy's + * period vector + * @param periods vector of periods to add + */ + void addAllPeriods(JulianPtrArray * periods); + + /* + void removePeriod(Period *p) + { + PR_ASSERT(p != 0); + PR_ASSERT(m_vPeriod != 0); + m_vPeriod->Remove(p); + delete p; + } + */ + + /** + * Return starting time of first period chronologically. + * + * @return starting time of first period. + */ + DateTime startOfFreebusyPeriod(); + + /** + * Return ending time of last period chronologically. + * + * @return starting time of first period. + */ + DateTime endOfFreebusyPeriod(); + + /** + * Parse a Freebusy property line and populate data. + * @param in line to parse. + */ + void parse(UnicodeString & in); + + /** + * Given freebusy period values in string, parameters, and timezones + * populates Freebusy data members. + * @param propVal freebusy period string + * @param parameters freebusy parameters + * @param vTimeZones vector of timezones to adjust dates to + * + */ + void parse(UnicodeString & sPeriods, JulianPtrArray * parameters, + JulianPtrArray * vTimeZones = 0); + + /** + * Compresses overlapping periods in vector. + */ + void normalizePeriods(); + + /** + * Compare method to pass into JulianPtrArray::QuickSort method. + * Currently compares against first period in a vs. first period in b. + * @param a first freebusy + * @param b second freebusy + * + * @return ComparePeriods(a[0], b[0]) + */ + static int CompareFreebusy(const void * a, const void * b); + + /** + * Check if two freebusy objects have the same TYPE and BSTAT. If they + * have the same TYPE and BSTAT, return TRUE, otherwise return FALSE. + * @param f1 first freebusy + * @param f2 second freebusy + * + * @return TRUE if TYPE and BSTAT are same in both freebusy, FALSE otherwise + */ + static t_bool HasSameParams(Freebusy * f1, Freebusy * f2); + + protected: + /** + * Returns the curl associated with this nsCalendar. The + * curl points to the calendar store where components in + * this nsCalendar are to be stored. It is required + * for an nsCalendar to have an associated curl if any + * of its components will be persisted in a calendar store. + * + * @return a JulianString containing the curl + */ + JulianString getCurl() const {return m_sCurl;} + + /** + * Set the default curl for this nsCalendar. + */ + void setCurl(const char* ps) {m_sCurl = ps;} + + /** + * Set the default curl for this nsCalendar. + */ + void setCurl(const JulianString& s) {m_sCurl = s;} + +}; + +#endif /* __FREEBUSY_H_ */ diff --git a/calendar/modules/core/ical/inc/functbl.h b/calendar/modules/core/ical/inc/functbl.h new file mode 100644 index 00000000000..a30e6ac0203 --- /dev/null +++ b/calendar/modules/core/ical/inc/functbl.h @@ -0,0 +1,124 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the 'NPL'); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an 'AS IS' basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ +/* + * functbl.h + * John Sun + * 7/27/98 1:57:12 PM + */ + +#include "valarm.h" +#include "tmbevent.h" +#include "tzpart.h" +#include "vevent.h" +#include "vfrbsy.h" +#include "vtodo.h" + +#ifndef __JULIANFUNCTIONTABLE_H_ +#define __JULIANFUNCTIONTABLE_H_ + +/** + * These structs are used by + * classes that need to contain ICalProperty's to + * quickly find the function to store data-members. + * Its keeps a hashCode and a ptr to a store-property + * function + */ +typedef struct +{ + t_int32 hashCode; + VAlarm::SetOp op; + void set(t_int32 i, VAlarm::SetOp sOp) { hashCode = i; op = sOp; } +} VAlarmStoreTable; + +typedef struct +{ + t_int32 hashCode; + TimeBasedEvent::SetOp op; + void set(t_int32 i, TimeBasedEvent::SetOp sOp) { hashCode = i; op = sOp; } +} TimeBasedEventStoreTable; + +typedef struct +{ + t_int32 hashCode; + TZPart::SetOp op; + void set(t_int32 i, TZPart::SetOp sOp) { hashCode = i; op = sOp; } +} TZPartStoreTable; + +typedef struct +{ + t_int32 hashCode; + VEvent::SetOp op; + void set(t_int32 i, VEvent::SetOp sOp) { hashCode = i; op = sOp; } +} VEventStoreTable; + +typedef struct +{ + t_int32 hashCode; + VFreebusy::SetOp op; + void set(t_int32 i, VFreebusy::SetOp sOp) { hashCode = i; op = sOp; } +} VFreebusyStoreTable; + +typedef struct +{ + t_int32 hashCode; + VTodo::SetOp op; + void set(t_int32 i, VTodo::SetOp sOp) { hashCode = i; op = sOp; } +} VTodoStoreTable; + +class JulianFunctionTable +{ +private: + /*----------------------------- + ** MEMBERS + **---------------------------*/ + static JulianFunctionTable * m_Instance; + /*----------------------------- + ** PRIVATE METHODS + **---------------------------*/ + JulianFunctionTable(); +public: + /*----------------------------- + ** CONSTRUCTORS and DESTRUCTORS + **---------------------------*/ + ~JulianFunctionTable(); + static JulianFunctionTable * Instance(); + + /* VAlarm storeData function table */ + VAlarmStoreTable alarmStoreTable[10]; + TimeBasedEventStoreTable tbeStoreTable[25]; + TZPartStoreTable tzStoreTable[8]; + VEventStoreTable veStoreTable[8]; + /* VFreebusyStoreTable vfStoreTable[16]; */ + VFreebusyStoreTable vfStoreTable[15]; + VTodoStoreTable vtStoreTable[9]; + /*----------------------------- + ** ACCESSORS (GET AND SET) + **---------------------------*/ + /*----------------------------- + ** UTILITIES + **---------------------------*/ + /*----------------------------- + ** STATIC METHODS + **---------------------------*/ + /*----------------------------- + ** OVERLOADED OPERATORS + **---------------------------*/ +}; + +#endif /* __JULIANFUNCTIONTABLE_H_ */ + diff --git a/calendar/modules/core/ical/inc/icalcomp.h b/calendar/modules/core/ical/inc/icalcomp.h new file mode 100644 index 00000000000..0e27806382d --- /dev/null +++ b/calendar/modules/core/ical/inc/icalcomp.h @@ -0,0 +1,516 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +/* + * icalcomp.h + * John Sun + * 2/5/98 2:57:16 PM + */ + +#include +#include "ptrarray.h" +#include "icalredr.h" +#include "prprty.h" +#include "jutility.h" +#include "datetime.h" +#include "jlog.h" +#include "nscalcoreicalexp.h" + +#ifndef __ICALCOMPONENT_H_ +#define __ICALCOMPONENT_H_ + +/** + * ICalComponent defines a Calendar Component in iCal. A calendar + * component can contain iCalendar properties as well as + * other iCalendar components. + * Examples of iCalendar components include VEvent, VTodo, + * VJournal, VFreebusy, VTimeZone, and VAlarms. + * TZPart, althought not an iCal component, subclasses from + * ICalComponent. + */ +class NS_CAL_CORE_ICAL ICalComponent +{ +protected: + + /** + * Constructor. Hide from clients except subclasses. + */ + ICalComponent(); + +public: + + /** + * An enumeration of Calendar Components. TZPart is not + * actually a Calendar component. However, it is useful to add + * it here because it implements this class' interface. + */ + enum ICAL_COMPONENT + { + ICAL_COMPONENT_VEVENT = 0, + ICAL_COMPONENT_VTODO = 1, + ICAL_COMPONENT_VJOURNAL = 2, + ICAL_COMPONENT_VFREEBUSY = 3, + ICAL_COMPONENT_VTIMEZONE = 4, + ICAL_COMPONENT_VALARM = 5, + ICAL_COMPONENT_TZPART = 6 + }; + + + /** + * Converts ICAL_COMPONENT to string. If bad ic, then return "". + * @param ICAL_COMPONENT ic + * + * @return output name of component + */ + static UnicodeString componentToString(ICAL_COMPONENT ic); + + static ICAL_COMPONENT stringToComponent(UnicodeString & s, t_bool & error); + + /** + * Destructor. + * + * @return virtual + */ + virtual ~ICalComponent(); + + + /* -- Start of ICALComponent interface (PURE VIRTUAL METHODS)-- */ + + /** + * The parse method is the standard interface for ICalComponent + * subclasses to parse from an ICalReader object + * and from the ITIP method type (i.e. PUBLISH, REQUEST, CANCEL, etc.). + * The method type can be set to \"\" if there is no method to be loaded. + * Also accepts a vector of VTimeZone objects to apply to + * the DateTime properties of the component. + * TODO: maybe instead of passing a UnicodeString for method, why not a enum METHOD + * 4-2-98: Added bIgnoreBeginError. If desired to start parsing in Component level, + * it is useful to ignore first "BEGIN:". Setting bIgnoreBeginError to TRUE allows for + * this. + * + * @param brFile ICalReader to load from + * @param sMethod method of component (i.e. PUBLISH, REQUEST, REPLY) + * @param parseStatus return parse error status string (normally return "OK") + * @param vTimeZones vector of VTimeZones to apply to datetimes + * @param bIgnoreBeginError TRUE = ignore first "BEGIN:VEVENT", FALSE otherwise + * @param encoding the encoding of the stream, default is 7bit. + * + * @return parse error status string (parseStatus) + */ + virtual UnicodeString & parse(ICalReader * brFile, UnicodeString & sMethod, + UnicodeString & parseStatus, JulianPtrArray * vTimeZones = 0, + t_bool bIgnoreBeginError = FALSE, JulianUtility::MimeEncoding encoding = + JulianUtility::MimeEncoding_7bit) + { + PR_ASSERT(FALSE); + if (brFile != NULL && vTimeZones != NULL + && sMethod.size() > 0 && parseStatus.size() > 0 && bIgnoreBeginError) + {} + return parseStatus; + } + + /** + * Returns a clone of this object + * @param initLog log file to write errors to + * + * @return clone of this object + */ + virtual ICalComponent * clone(JLog * initLog) { PR_ASSERT(FALSE); if (initLog) {} return 0; } + + /** + * Return TRUE if component is valid, FALSE otherwise + * + * @return TRUE if is valid, FALSE otherwise + */ + virtual t_bool isValid() { PR_ASSERT(FALSE); return FALSE; } + + /** + * Print all contents of ICalComponent to iCal export format. + * + * @return string containing iCal export format of ICalComponent + */ + virtual UnicodeString toICALString() { PR_ASSERT(FALSE); return "";} + + /** + * Print all contents of ICalComponent to iCal export format, depending + * on attendee name, attendee delegated-to, and where to include recurrence-id or not + * + * @param method method name (REQUEST,PUBLISH, etc.) + * @param name attendee name to filter with + * @param isRecurring TRUE = no recurrenceid, FALSE = include recurrenceid + * + * @return string containing iCal export format of ICalComponent + */ + virtual UnicodeString toICALString(UnicodeString method, UnicodeString name, + t_bool isRecurring) + { + PR_ASSERT(FALSE); + if (method.size() == 0 && name.size() == 0 && isRecurring) + {} + return ""; + } + + /** + * Print all contents of ICalComponent to human-readable string. + * + * @return string containing human-readable format of ICalComponent + */ + virtual UnicodeString toString() {PR_ASSERT(FALSE); return "";} + + /** + * Depending on character passed in, returns a string that represents + * the ICAL export string of that property that the character represents, if + * other paramaters not null, then print out information is filtered in several ways + * Attendee print out can be filtered so that only attendee with certain name is printed + * also, can print out the relevant attendees in a delegation message + * (ie. owner, delegate-to, delegate-from) + * + * @param c char of what property to print + * @param sFilterAttendee name of attendee to print + * @param bDelegateRequest TRUE if a delegate request, FALSE if not + * @return ICAL export format of that property + */ + virtual UnicodeString formatChar(t_int32 c, + UnicodeString sFilterAttendee, + t_bool delegateRequest = FALSE) + { + PR_ASSERT(FALSE); +#if 0 + if (c == 8 || sFilterAttendee.size() == 0 || delegateRequest) {} +#endif + return ""; + } + + /** + * convert a character to the content of a property in string + * human-readable format + * @param c a character represents a property + * @param dateFmt for formatting datetimes + * + * @return property in human-readable string + */ + virtual UnicodeString toStringChar(t_int32 c, UnicodeString & dateFmt) + { + PR_ASSERT(FALSE); + +#if 0 /* fix HPUX build busgage - this is dead code anyway - alecf 4/30/98 */ + if (c == 8) {} +#endif + return ""; +#if 0 + if (dateFmt.size() > 0) {} +#endif + } + + /** + * Returns the ICAL_COMPONENT enumeration value of this ICalComponent. + * Each ICalComponent subclass must return a unique ICAL_COMPONENT value. + * + * @return ICAL_COMPONENT value of this component + */ + virtual ICAL_COMPONENT GetType() const { PR_ASSERT(FALSE); return ICAL_COMPONENT_VEVENT; } + + /** + * Update the private property data-members with updatedComponent's + * property data-members. + * Usually, overwriting data-members should only occur if updatedComponent + * is more recent than the current component. + * Return TRUE if component was changed, FALSE otherwise + * @param ICalComponent * updatedComponent + * + * @return virtual t_bool + */ + virtual t_bool updateComponent(ICalComponent * updatedComponent) + { + PR_ASSERT(FALSE); + return FALSE; + } + + /* -- End of ICALComponent PURE VIRTUAL interface -- */ + + + /*-------------------------------------------------------------------*/ + /* NOT PURE + * TRYING TO MERGE SIMILARITIES IN VFREEBUSY AND TIMEBASEDEVENT TOGETHER + */ + + /** + * Check if this component matches a UID and a sequence number. + * TimeBasedEvent and VFreebusy should override this method. + * @param sUID uid to look for + * @param iSeqNo sequence number to look for + * + * @return TRUE if match, FALSE otherwise + */ + virtual t_bool MatchUID_seqNO(UnicodeString sUID, t_int32 iSeqNo = -1) + { + /* NOTE: remove later, just to get rid of compiler warnings */ + if (sUID.size() > 0 && iSeqNo > 0) {} + return FALSE; + } + + /** + * Return the UID of this component. TimeBasedEvent and VFreebusy + * should override this method. + * + * @return the UID of this component. + */ + virtual UnicodeString getUID() const { return ""; } + + /** + * Return the sequence number of this component. + * TimeBasedEvent and VFreebusy should override this method. + * + * @return the sequence number of this component. + */ + virtual t_int32 getSequence() const { return -1; } + + /*---------------------------------------------------------------------*/ + + /* -- End of ICALComponent interface -- */ + + + /** + * Given a component name, a component format string, print the component in + * following manner with properties specified by the format string. It does + * this by calling abstract formatChar method. + * (i.e. sComponentName = VEVENT) + * + * BEGIN:VEVENT + * DTSTART:19980331T112233Z (properties dependent on format string) + * ... + * END:VEVENT + * + * Optionally, the caller may pass in an sFilterAttendee and delegateRequest args. + * If sFilterAttendee != "", then filter on sFilterAttendee, meaning that + * only the attendee with the name sFilterAttendee should be printed. If the + * delegateRequest is set to TRUE, + * also print attendees who are delegates or related-to the delegates. + * @param sComponentName name of ICalComponent + * @param strFmt property format string + * @param sFilterAttendee attendee to filter on + * @param delegateRequest whether to print delegates + * + * @return iCal export string of component + */ + UnicodeString format(UnicodeString & sComponentName, UnicodeString & strFmt, + UnicodeString sFilterAttendee, t_bool delegateRequest = FALSE); + + /** + * Given a format string, prints the component to human-readable format + * with properties specified by format string. It does this by calling + * abstract toStringChar method. + * @param strFmt property format string + * + * @return human-readable string of component + */ + UnicodeString toStringFmt(UnicodeString & strFmt); + + /* STATIC METHODS */ + + /** + * Returns the keyletter representing that property + * For example, if propertyName = "DTSTART", outLetter would return 'B' + * and return boolean would be TRUE. + * return FALSE if property not found. + * @param UnicodeString & propertyName + * @param t_int32 & outLetter + * + * @return static t_bool + */ + static t_bool propertyNameToKeyLetter(UnicodeString & propertyName, + t_int32 & outLetter); + + + /** + * Given a ptr to an array of properties strings (char *) and the count + * create the iCal formatting string for those properties and return + * it in out. + * If ppsPropList is null or iPropCount is 0, then + * return the string of all properties and alarms. + * @param char ** ppsPropList + * @param t_int32 iPropCount + * @param UnicodeString & out + * + * @return static UnicodeString + */ + static UnicodeString & makeFormatString(char ** ppsPropList, t_int32 iPropCount, + UnicodeString & out); + + /** + * Cleanup vector of UnicodeString objects. Delete each UnicodeString + * in vector. + * @param strings vector of elements to delete from + */ + static void deleteUnicodeStringVector(JulianPtrArray * stringVector); + + /** + * Cleanup vector of ICalComponent objects. Delete each ICalComponent + * in vector + * @param strings vector of elements to delete from + */ + static void deleteICalComponentVector(JulianPtrArray * componentVector); + + /** + * Clones each ICalComponent element in the toClone vector and put clone in + * the out vector + * @param JulianPtrArray * out + * @param JulianPtrArray * toClone + * + * @return static void + */ + static void cloneICalComponentVector(JulianPtrArray * out, JulianPtrArray * toClone); + +#if 0 + /** + * Sets the ICalProperty in dateTimePropertyPtr to have + * a value on inVal and paramter value on inParameters + * @param ICalProperty ** dateTimePropertyPtr + * @param DateTime inVal + * @param JulianPtrArray * inParameters + * + * @return static void + */ + static void setDateTimeValue(ICalProperty ** dateTimePropertyPtr, + DateTime inVal, JulianPtrArray * inParameters); + + /** + * Return the value of the dateTimePropertyPtr in outVal + * @param ICalProperty ** dateTimePropertyPtr + * @param DateTime & outVal + * + * @return static void + */ + static void getDateTimeValue(ICalProperty ** dateTimePropertyPtr, + DateTime & outVal); + + /** + * Sets the ICalProperty in stringPropertyPtr to have + * a value on inVal and paramter value on inParameters + * @param ICalProperty ** stringPropertyPtr + * @param UnicodeString inVal + * @param JulianPtrArray * inParameters + * + * @return static void + */ + static void setStringValue(ICalProperty ** stringPropertyPtr, + UnicodeString inVal, JulianPtrArray * inParameters); + + /** + * Return the value of the stringPropertyPtr in outVal + * @param ICalProperty ** stringPropertyPtr + * @param UnicodeString & outVal + * + * @return static void + */ + static void getStringValue(ICalProperty ** stringPropertyPtr, + UnicodeString & outVal); + + /** + * Sets the ICalProperty in integerPropertyPtr to have + * a value on inVal and paramter value on inParameters + * @param ICalProperty ** integerTimePropertyPtr + * @param t_int32 inVal + * @param JulianPtrArray * inParameters + * + * @return static void + */ + static void setIntegerValue(ICalProperty ** integerPropertyPtr, + t_int32 inVal, JulianPtrArray * inParameters); + + /** + * Return the value of the integerPropertyPtr in outVal + * @param ICalProperty ** integerPropertyPtr + * @param t_int32 & outVal + * + * @return static void + */ + static void getIntegerValue(ICalProperty ** integerPropertyPtr, + t_int32 & outVal); + +#endif +protected: + /* replace current vector with contents in replaceVctr */ + /* don't overwrite if replaceVctr is empty and bForceOverwriteOnEmpty is FALSE */ + + /** + * Replace the ICalProperty contents of propertyVctrPtr with the ICalProperty + * elements in replaceVctr. This means delete all ICalProperty elements in + * (*propertyVctrPtr), then clone each element in replaceVctr and add to + * (*propertyVctrPtr). If however replaceVctr is empty, don't delete current + * elements unless bForceOverwriteOnEmpty flag is ON. (see below) + * If bAddInsteadOfOverwrite is TRUE, don't delete all ICalProperty elements, + * just add all elements in replaceVctr to propertyVctrPtr + * If bForceOverwriteOnEmpty is TRUE, delete all ICalProperty elements even if + * replaceVctr is empty or NULL. + * @param JulianPtrArray ** propertyVctrPtr + * @param JulianPtrArray * replaceVctr + * @param t_bool bAddInsteadOfOverwrite = FALSE + * @param t_bool bForceOverwriteOnEmpty = FALSE + * + * @return static void + */ + static void internalSetPropertyVctr(JulianPtrArray ** propertyVctrPtr, + JulianPtrArray * replaceVctr, t_bool bAddInsteadOfOverwrite = FALSE, + t_bool bForceOverwriteOnEmpty = FALSE); + + /** + * Replace the XToken contents of xTokensVctrPtr with the XToken + * elements in replaceVctr. This means delete all XToken elements in + * (*xTokensVctrPtr), then clone each element in replaceVctr and add to + * (*xTokensVctrPtr). If however replaceVctr is empty, don't delete current + * elements unless bForceOverwriteOnEmpty flag is ON. (see below) + * If bAddInsteadOfOverwrite is TRUE, don't delete all XToken elements, + * just add all elements in replaceVctr to xTokensVctrPtr + * If bForceOverwriteOnEmpty is TRUE, delete all XToken elements even if + * replaceVctr is empty or NULL. + * @param JulianPtrArray ** xTokensVctrPtr + * @param JulianPtrArray * replaceVctr + * @param t_bool bAddInsteadOfOverwrite = FALSE + * @param t_bool bForceOverwriteOnEmpty = FALSE + * + * @return static void + */ + static void internalSetXTokensVctr(JulianPtrArray ** xTokensVctrPtr, + JulianPtrArray * replaceVctr, t_bool bAddInsteadOfOverwrite = FALSE, + t_bool bForceOverwriteOnEmpty = FALSE); + + + /** + * Replace the ICalProperty in (*propertyPtr) to with replaceProp. + * This means delete the current ICalProperty and cloning replaceProp + * and setting (*propertyPtr) to clone. + * If replaceProp == NULL, don't delete current ICalProperty. + * However, if bForceOverwriteOnEmpty is TRUE, delete current ICalProperty + * even if replaceProp is NULL. + * @param ICalProperty ** propertyPtr + * @param ICalProperty * replaceProp + * @param t_bool bForceOverwriteOnEmpty = FALSE + * + * @return static void + */ + static void internalSetProperty(ICalProperty ** propertyPtr, + ICalProperty * replaceProp, t_bool bForceOverwriteOnEmpty = FALSE); + + + +}; + +#endif /* __ICALCOMPONENT_H_ */ + + diff --git a/calendar/modules/core/ical/inc/icalfrdr.h b/calendar/modules/core/ical/inc/icalfrdr.h new file mode 100644 index 00000000000..07cbdbb1e1a --- /dev/null +++ b/calendar/modules/core/ical/inc/icalfrdr.h @@ -0,0 +1,108 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +/* + * icalfrdr.h + * John Sun + * 2/10/98 11:37:48 PM + */ + +#include +#include +#include +#include "nscalcoreicalexp.h" + +#ifndef __ICALFILEREADER_H_ +#define __ICALFILEREADER_H_ + +/** + * ICalFileReader is a subclass of ICalReader. It implements the + * ICalReader interface to work with files. + * TODO: handle QuotedPrintable + */ +class NS_CAL_CORE_ICAL ICalFileReader +{ +private: + + /** filename of file */ + const char * m_filename; + + /** ptr to file */ + FILE * m_file; + + /** buffer to contain current line, assumed to be less than 1024 bytes */ + char m_pBuffer[1024]; + +private: + + /** + * Default constructor. Made private to hide from clients. + */ + ICalFileReader(); + +public: + + /** + * Constructor. Clients should call this to create ICalFileReader + * objects to read ICAL objects from a file. + * Opens file for reading. + * + * @param filename filename of target file + * @param status set to 1 if can't open file + */ + ICalFileReader(char * filename, ErrorCode & status); + + /** + * Destructor. Also closes file. + */ + virtual ~ICalFileReader(); + + /** + * Read next character from file. + * + * @param status, return 1 if no more characters + * @return next character of string + */ + virtual t_int8 read(ErrorCode & status); + + /** + * Read next line of file. A line is defined to be + * characters terminated by either a '\n', '\r' or "\r\n". + * @param aLine, return next line of string + * @param status, return 1 if no more lines + * + * @return next line of string + */ + virtual UnicodeString & readLine(UnicodeString & aLine, ErrorCode & status); + + /** + * Read the next ICAL full line of the file. The definition + * of a full ICAL line can be found in the ICAL spec. + * Basically, a line followed by a CRLF and a space character + * signifies that the next line is a continuation of the previous line. + * Uses the readLine, read methods. + * + * @param aLine, returns next full line of string + * @param status, return 1 if no more lines + * + * @return next full line of string + */ + virtual UnicodeString & readFullLine(UnicodeString & aLine, ErrorCode & status, t_int32 i = 0); +}; + +#endif /* __ICALFILEREADER_H_ */ diff --git a/calendar/modules/core/ical/inc/icalprm.h b/calendar/modules/core/ical/inc/icalprm.h new file mode 100644 index 00000000000..dec81309405 --- /dev/null +++ b/calendar/modules/core/ical/inc/icalprm.h @@ -0,0 +1,138 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +/* + * icalprm.h + * John Sun + * 2/10/98 3:41:52 PM + */ + +#include +#include "ptrarray.h" + +#ifndef __ICALPARAMETER_H_ +#define __ICALPARAMETER_H_ + +/** + * This is a simple class holding ICAL parameters in an ICalProperty. + * NOTE: this class may eventually become abstract + * since it limits only to have one parameter value, + * so multiple parameter value aren't allowed + * also only allows for string parameter values + */ +class ICalParameter +{ +private: + /** the parameter name of the parameter */ + UnicodeString m_ParameterName; + + /** the parameter value of the parameter */ + UnicodeString m_ParameterValue; +public: + + /** default constructor, returns ("","") */ + ICalParameter(); + + /** + * Copy constructor + * @param that ICalParameter to copy + */ + ICalParameter(ICalParameter & that); + + /** + * Normal constructor + * @param parameterName initial parameter name + * @param parameterValue initial parameter value + */ + ICalParameter(const UnicodeString & parameterName, + const UnicodeString & parameterValue); + + + /** + * Returns a copy of this ICalParameter. Clients responsible + * for de-allocating returned ICalParameter *. + * + * @return a clone of this ICalParameter + */ + ICalParameter * clone(); + + + /** + * Sets the parameter name. + * @param parameterName new parameter name + */ + void setParameterName(const UnicodeString & parameterName); + + /** + * Sets the parameter value. + * @param parameterValue new parameter value + */ + void setParameterValue(const UnicodeString & parameterValue); + + + /** + * Return parameter name + * @param retName return storage for parameter name + * + * @return retName (storage for parameter name) + */ + UnicodeString & getParameterName(UnicodeString & retName) const; + + /** + * Return parameter value + * @param retValue return storage for parameter value + * + * @return retValue (storage for parameter value) + */ + UnicodeString & getParameterValue(UnicodeString & retValue) const; + + + /** + * Returns parameter in string of form ";PARAMETERNAME=PARAMETERVALUE + * @param result output string + * + * @return result (output string) + */ + UnicodeString & toICALString(UnicodeString & result) const; + + /** + * Assignment operator. + * @param d ICalParameter to assign to. + * + * @return + */ + const ICalParameter & operator=(const ICalParameter & d); + + + /** + * Searches parameters for a first occurrence of ICalParameter with + * parameter name equal to paramName. Returns the value of parameter + * in retVal. Returns "", if no match. + * @param paramName parameter name to look for + * @param retVal return value of parameter + * @param parameters parameters to search from + * + * @return retVal (value of parameter) + */ + static UnicodeString & GetParameterFromVector(UnicodeString & paramName, + UnicodeString & retVal, JulianPtrArray * parameters); +}; + +#endif /* __ICALPARAMETER_H_ */ + + diff --git a/calendar/modules/core/ical/inc/icalredr.h b/calendar/modules/core/ical/inc/icalredr.h new file mode 100644 index 00000000000..b948b22cb8e --- /dev/null +++ b/calendar/modules/core/ical/inc/icalredr.h @@ -0,0 +1,117 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +/* + * icalredr.h + * John Sun + * 2/10/98 11:33:55 AM + */ + +#include "jdefines.h" +#include +#include "nscalcoreicalexp.h" + +#ifndef __ICALREADER_H_ +#define __ICALREADER_H_ + +/** + * ICalReader is an abstract class that defines an interface for + * reading iCalendar objects from a data source. All methods in + * this class are defined to be pure virtual methods. Currently, this + * data source can be a string (ICalStringReader) or a file (ICalFileReader). + * The interface defined allows for the reading of a character, a line, and a full-line. + * A full-line is defined by the iCal Content-Line definition. + * For clients, object acts like an input stream of UnicodeString data. + */ +class NS_CAL_CORE_ICAL ICalReader +{ +protected: + + /** + * Hide constructor from clients. + */ + ICalReader(); + +public: + + virtual ~ICalReader() {} + /** + * Pure virtual. Read the next character from the data. + * @param status return status > 0 if failure in reading character + * + * @return next character in data + */ + virtual t_int8 read(ErrorCode & status) + { + PR_ASSERT(FALSE); + if (status == 0) {} + return -1; + } + + /** + * Pure virtual. Read the next line from the data. A line + * is defined to be characters terminated by a '\n', '\r', or '\n\r'. + * @param aLine placeholder to return next line + * @param status return status > 0 if failure in reading line + * + * @return aLine (next line) + */ + virtual UnicodeString & readLine(UnicodeString & aLine, ErrorCode & status) + { + PR_ASSERT(FALSE); + if (status == 0) {} + if (aLine.size() == 0) {} + return aLine; + } + + /** + * Pure virtual. Read the next full-line from the data. A full-line + * is defined by the iCalendar Content-Line definition. + * @param aLine placeholder to return next full-line + * @param status return status > 0 if failure in reading full-line + * + * @return aLine (next full-line) + */ + virtual UnicodeString & readFullLine(UnicodeString & aLine, ErrorCode & status, t_int32 i = 0) + { + PR_ASSERT(FALSE); + if (status == 0) {} + if (aLine.size() == 0) {} + return aLine; + } + + /** + * Sets a the buffer to read from. This method should only be overwritten by + * the ICalCAPIReader class. (4-16-98) + */ + virtual void setBuffer(const char * capiChunk) + { + if (capiChunk != 0) {} + } + + virtual void * getMonitor() { return 0; } + + /* static methods */ + + static t_bool isHex(t_int8 aToken); + static t_int8 convertHex(char fToken, char sToken); +}; + +#endif /* __ICALREADER_H_ */ + + diff --git a/calendar/modules/core/ical/inc/icalsrdr.h b/calendar/modules/core/ical/inc/icalsrdr.h new file mode 100644 index 00000000000..0c9f3f097a0 --- /dev/null +++ b/calendar/modules/core/ical/inc/icalsrdr.h @@ -0,0 +1,130 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +/* + * icalsrdr.h + * John Sun + * 2/10/98 11:37:39 AM + */ + +#include +#include "icalredr.h" +#include "jutility.h" +#include "nscalcoreicalexp.h" + +#ifndef __ICALSTRINGREADER_H_ +#define __ICALSTRINGREADER_H_ + +/** + * ICalStringReader is a subclass of ICalReader. It implements the + * ICalReader interface to work with strings (const char *). + * DO NOT delete the char * object for which the object is constructed with. + TODO: remove Unistring dependency. There is a bug if the + target string is encoded with 2byte character. If so, then the + m_pos and m_length variables are wrong. Currently, I will assume that + all const char * passed in will be us-ascii 8-bit chars +*/ +#if defined(XP_PC) +#pragma warning ( disable : 4275 ) +#endif +class NS_CAL_CORE_ICAL ICalStringReader: public ICalReader +{ +private: + + /** BUG:?? used to extract substring. Dangerous if encoded */ + UnicodeString m_unistring; + + /** string: do not delete outside */ + const char * m_string; + + /** length of string */ + t_int32 m_length; + + /** current position in string */ + t_int32 m_pos; + + /** last marked position of string */ + t_int32 m_mark; + + /** encoding of stream */ + JulianUtility::MimeEncoding m_Encoding; + + /** + * Default constructor. Made private to hide from clients. + */ + ICalStringReader(); + + + +public: + + /** + * Creates object to read ICAL objects from a string. + * @param string string to read from + */ + ICalStringReader(const char * string, + JulianUtility::MimeEncoding encoding = JulianUtility::MimeEncoding_7bit); + + /** + * Mark current position in string + */ + void mark(); + + /** + * Reset position to last mark + */ + void reset(); + + /** + * Read next character of string. + * + * @param status, return 1 if no more characters + * @return next character of string + */ + virtual t_int8 read(ErrorCode & status); + + /** + * Read next line of string. A line is defined to be + * characters terminated by either a '\n', '\r' or "\r\n". + * @param aLine, return next line of string + * @param status, return 1 if no more lines + * + * @return next line of string + */ + virtual UnicodeString & readLine(UnicodeString & aLine, ErrorCode & status); + + + /** + * Read the next ICAL full line of the string. The definition + * of a full ICAL line can be found in the ICAL spec. + * Basically, a line followed by a CRLF and a space character + * signifies that the next line is a continuation of the previous line. + * Uses the readLine, read methods. + * + * @param aLine, returns next full line of string + * @param status, return 1 if no more lines + * + * @return next full line of string + */ + virtual UnicodeString & readFullLine(UnicodeString & aLine, ErrorCode & status, t_int32 i = 0); +}; +#if defined(XP_PC) +#pragma warning ( default : 4275 ) +#endif + +#endif /* __ICALSTRINGREADER_H_ */ diff --git a/calendar/modules/core/ical/inc/icompfy.h b/calendar/modules/core/ical/inc/icompfy.h new file mode 100644 index 00000000000..b61c0ccfb45 --- /dev/null +++ b/calendar/modules/core/ical/inc/icompfy.h @@ -0,0 +1,65 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +/* + * icompfy.h + * John Sun + * 2/20/98 10:44:52 AM + */ + +#include "icalcomp.h" +#include "jlog.h" + +#ifndef __ICALCOMPONENTFACTORY_H_ +#define __ICALCOMPONENTFACTORY_H_ + +/** + * ICalComponentFactory is a factory class that creates + * ICalComponent instances. + * + * @see ICalComponent + */ +class ICalComponentFactory +{ +private: + + /** + * Hide default constructor from use. + */ + ICalComponentFactory(); + +public: + + /** + * Factory method that creates ICalComponent objects. + * Clients are responsible for calling parse method + * to populate the returned ICalComponent. + * Clients are also responsible for de-allocating + * return ICalComponent. + * TODO: instead of passing string, why not pass a enum. + * + * @param name the name of the ICalComponent + * @param initLog the log of the ICalComponent + * + * @return ptr to the newly created ICalComponent object + * @see ICalComponent + */ + static ICalComponent * Make(UnicodeString & name, JLog * initLog); +}; + +#endif /* __ICALCOMPONENTFACTORY_H_ */ diff --git a/calendar/modules/core/ical/inc/iprprty.h b/calendar/modules/core/ical/inc/iprprty.h new file mode 100644 index 00000000000..b308102e20b --- /dev/null +++ b/calendar/modules/core/ical/inc/iprprty.h @@ -0,0 +1,121 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +/* + * iprprty.h + * John Sun + * 2/12/98 3:26:51 PM + */ + +#include +#include "sdprprty.h" + +#ifndef __INTEGERPROPERTY_H_ +#define __INTEGERPROPERTY_H_ + +/** + * IntegerProperty is a subclass of StandardProperty. It implements the ICalProperty + * interface for ICAL properties with TYPE=INTEGER. + */ +class IntegerProperty: public StandardProperty +{ +private: + /** the Integer value of the property */ + t_int32 m_Integer; + + /** + * Default constructor + */ + IntegerProperty(); + + /** + * Copy constructor + * @param that property to copy + */ + IntegerProperty(const IntegerProperty & that); + +public: + + /** + * Constructor that sets value of property to contents of value + * and makes a copy of the contents of parameters ptr. + * @param value value of property + * @param parameters parameters of property + */ + IntegerProperty(t_int32 value, JulianPtrArray * parameters); + + /** + * Destructor + */ + ~IntegerProperty(); + + /** + * Return the value of the property + * @return void * ptr to value of the property + */ + virtual void * getValue() const; + + /** + * Set the value of the property + * @param value the value to set property to + */ + virtual void setValue(void * value); + + /** + * Returns a clone of this property. Clients are responsible for deleting + * the returned object. + * + * @return a clone of this property. + */ + virtual ICalProperty * clone(JLog * initLog); + + /** + * Return TRUE if property is valid, FALSE otherwise + * + * @return TRUE if is valid, FALSE otherwise + */ + virtual t_bool isValid(); + + /** + * Return a string in human-readable form of the property. + * @param out contains output human-readable string + * + * @return the property in its human-readable string format + */ + virtual UnicodeString & toString(UnicodeString & out); + + /** + * Return a string in human-readable form of the property. + * @param dateFmt format string options + * @param out contains output human-readable string + * + * @return the property in its human-readable string format + */ + virtual UnicodeString & toString(UnicodeString & dateFmt, UnicodeString & out); + + /** + * Return the property's string in the ICAL format. + * @param out contains output ICAL string + * + * @return the property in its ICAL string format + */ + virtual UnicodeString & toExportString(UnicodeString & out); +}; +#endif /* __INTEGERPROPERTY_H_ */ + + diff --git a/calendar/modules/core/ical/inc/jparser.h b/calendar/modules/core/ical/inc/jparser.h new file mode 100644 index 00000000000..d7a1d3d02a2 --- /dev/null +++ b/calendar/modules/core/ical/inc/jparser.h @@ -0,0 +1,90 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +/* + * jparser.h + * John Sun + * 4/28/98 10:45:21 AM + */ +#ifndef __JULIANPARSER_H_ +#define __JULIANPARSER_H_ + +#include "ptrarray.h" +#include "icalredr.h" +#include "capiredr.h" +#include "jutility.h" +#include "nspr.h" + +/** + * This class will be removed later. It is a hack I created to + * parse the MIME-message from the CS&T server fetch results. + * I will try to extract the iCalendar information from it. + * I will need to handle multi-threaded parsing somehow as well. + */ +class JulianParser +{ +private: + /*char * m_Buffer;*/ + + static JulianUtility::MimeEncoding stringToEncodingType(UnicodeString & propVal); + + JulianPtrArray * m_OutCalendars; + ICalCAPIReader * m_Reader; + t_bool m_bParseStarted; + t_bool m_bParseFinished; + PRThread * m_Thread; + +public: + JulianParser(); + JulianParser(ICalCAPIReader * reader, JulianPtrArray * outCalendars, + PRThread * thread); + /* + void setBuffer(char * buf) + { + strcat(m_Buffer, buf); + } + */ + + t_bool isParseStarted() const { return m_bParseStarted; } + void setParseStarted() { m_bParseStarted = TRUE; } + + t_bool isParseFinished() const { return m_bParseFinished; } + void setParseFinished() { m_bParseFinished = TRUE; } + + ICalCAPIReader * getReader() const { return m_Reader; } + PRThread * getThread() const { return m_Thread; } + + void ParseCalendars(ICalReader * reader, + JulianPtrArray * outCalendars); + + void ParseCalendars(); + +}; + +#ifdef XP_CPLUSPLUS +extern "C"{ +#endif + + void jparser_ParseCalendarsZero(void * jp, void *); + +#ifdef XP_CPLUSPLUS +} +#endif + +#endif /* __JULIANPARSER_H_ */ + diff --git a/calendar/modules/core/ical/inc/manifest.mn b/calendar/modules/core/ical/inc/manifest.mn new file mode 100644 index 00000000000..e69de29bb2d diff --git a/calendar/modules/core/ical/inc/nscal.h b/calendar/modules/core/ical/inc/nscal.h new file mode 100644 index 00000000000..c037722e11a --- /dev/null +++ b/calendar/modules/core/ical/inc/nscal.h @@ -0,0 +1,820 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +/* + * nscal.h + * John Sun + * 2/18/98 1:35:06 PM + */ +/* + * Updated 9/24/98 sman + * We need to be able to append a list of events: AddEventList + */ + +#ifndef __NSCALENDAR_H_ +#define __NSCALENDAR_H_ + +#include +#include "ptrarray.h" +#include "prprty.h" +#include "icalredr.h" +#include "icalcomp.h" +#include "vevent.h" +#include "vtodo.h" +#include "vjournal.h" +#include "vfrbsy.h" +#include "jutility.h" +#include "julnstr.h" +#include "nscalcoreicalexp.h" + +/** + * NSCalendar encapsulates a iCalendar calendar object. An NSCalendar + * may contain Calendar Components such as VEvent, VTodo, VJournal, + * VFreebusy and VTimeZones. It also contains the METHOD + * PRODID, VERSION, and CALSCALE properties. (NAME, SOURCE removed 4-28-98). + */ +class NS_CAL_CORE_ICAL NSCalendar +{ +private: +#if 0 + + + /** + * Default constructor. Hide from clients. + */ + NSCalendar(); +#endif +public: + /*static const UnicodeString ms_asMETHODS[];*/ + + /** + * An enumeration of ITIP methods. + */ + enum METHOD{METHOD_PUBLISH = 0, METHOD_REQUEST = 1, + METHOD_REPLY = 2, METHOD_CANCEL = 3, METHOD_REFRESH = 4, + METHOD_COUNTER = 5, METHOD_DECLINECOUNTER = 6, METHOD_ADD = 7, + METHOD_LENGTH= 8, METHOD_INVALID = -1}; + + /** + * Converts ITIP method in string to the METHOD enumeration. + * @param UnicodeString & method + * + * @return static NSCalendar::METHOD + */ + static NSCalendar::METHOD stringToMethod(UnicodeString & method); + + /** + * Converts METHOD to string. A method not publish through add + * returns "". (i.e. METHOD_LENGTH, METHOD_INVALID). + * @param NSCalendar::METHOD method + * @param UnicodeString & out + * + * @return static UnicodeString + */ + static UnicodeString & methodToString(NSCalendar::METHOD method, UnicodeString & out); + + enum JOURNAL_METHOD{ + JOURNAL_METHOD_PUBLISH = METHOD_PUBLISH, + JOURNAL_METHOD_CANCEL= METHOD_CANCEL, + JOURNAL_METHOD_REFRESH = METHOD_REFRESH, + JOURNAL_METHOD_LENGTH = 3, JOURNAL_METHOD_INVALID = -1 + }; + + enum FREEBUSY_METHOD{ + + FREEBUSY_METHOD_PUBLISH = METHOD_PUBLISH, + FREEBUSY_METHOD_REQUEST = METHOD_REQUEST, + FREEBUSY_METHOD_REPLY = METHOD_REPLY, + FREEBUSY_METHOD_LENGTH = 3, FREEBUSY_METHOD_INVALID = -1 + }; + + enum SPECIAL_METHOD{ + SPECIAL_METHOD_DELEGATE = 0, + SPECIAL_METHOD_LENGTH = 1, SPECIAL_METHOD_INVALID = -1 + }; + + enum METHOD_PROPS{PROPS_METHOD = 0, PROPS_JOURNAL_METHOD = 1, + PROPS_FREEBUSY_METHOD = 2, PROPS_SPECIAL_METHOD = 3}; + + enum CALSCALE{CALSCALE_GREGORIAN = 0, + CALSCALE_LENGTH = 1, CALSCALE_INVALID = -1}; + + /* -- METHODS -- */ + + /** + * Constructor. Creates NSCalendar with initial logfile initLog. + * @param JLog * initLog = 0 + */ + NSCalendar(JLog * initLog = 0); + /*NSCalendar(User u);*/ + + /** + * Copy constructor + * @param NSCalendar & that + */ + NSCalendar(NSCalendar & that); + + /** + * Destructor + */ + ~NSCalendar(); + + /** + * Export this calendar to a file with filename. If error occurred, + * return false in status boolean. + * TODO: test it + */ + void export(const char * filename, t_bool & status); + + /** + * clone this NSCalendar + * TODO: test it + */ + NSCalendar * clone(JLog * initLog); + + /* CALSCALE */ + UnicodeString getCalScale() const; + void setCalScale(UnicodeString s, JulianPtrArray * parameters = 0); + ICalProperty * getCalScaleProperty() const { return m_CalScale; } + + /* VERSION */ + UnicodeString getVersion() const; + void setVersion(UnicodeString s, JulianPtrArray * parameters = 0); + ICalProperty * getVersionProperty() const { return m_Version; } + + /* PRODID */ + UnicodeString getProdid() const; + void setProdid(UnicodeString s, JulianPtrArray * parameters = 0); + ICalProperty * getProdidProperty() const { return m_Prodid; } + +#if 0 + /* SOURCE */ + UnicodeString getSource() const; + void setSource(UnicodeString s, JulianPtrArray * parameters = 0); + ICalProperty * getSourceProperty() const { return m_Source; } + + /* NAME */ + UnicodeString getName() const; + void setName(UnicodeString s, JulianPtrArray * parameters = 0); + ICalProperty * getNameProperty() const { return m_Name; } +#endif + + /* METHOD: NOTE: Method is not an ICalProperty, but saved as an NSCalendar::METHOD */ + void setMethod(NSCalendar::METHOD i) { m_iMethod = i; } + NSCalendar::METHOD getMethod() const { return (NSCalendar::METHOD) m_iMethod; } + + /* XTOKENS: NOTE: a vector of strings, not a vector of ICalProperties */ + void addXTokens(UnicodeString s); + JulianPtrArray * getXTokens() const { return m_XTokensVctr; } + + /** getter and setter for when events were last updated from server */ + void setEventsLastUpdatedFromServer(DateTime d) { m_EventsLastUpdatedFromServer = d; } + DateTime getEventsLastUpdatedFromServer() { return m_EventsLastUpdatedFromServer; } + + /** getter for when events span */ + DateTime getEventsSpanStart() { return m_EventsSpanStart; } + DateTime getEventsSpanEnd() { return m_EventsSpanEnd; } + + + /** + * Given an ICalReader object, parse the stream to populate this NSCalendar. + * In the process of parsing, the NSCalendar may create subcomponents + * such as VEvent, VTodo, VJournal, VTimeZone, and VFreebusy. + * If stream came from a file, store filename (NOTE: may remove later). + * + * @param brFile ICalReader stream object to parse from + * @param fileName filename of stream if stream is from a file + * @param encoding the encoding of the stream, default is 7bit. + * + */ + void parse(ICalReader * brFile, UnicodeString & fileName, + JulianUtility::MimeEncoding encoding = JulianUtility::MimeEncoding_7bit); + + /** + * Returns the error log. + * + * @return JLog* + */ + JLog* getLog() const { return m_Log; }; + + /** + * Return the vector of JulianLogErrors on this ICalComponent: + * Return 0 if ic is not in this calendar. + * Return 0 if ic has no error vector. + * Do not deallocate returned vector. Returns a ptr to vector, not a new vector. + * @param ICalComponent * ic + * + * @return JulianPtrArray * + */ + JulianPtrArray * getLogVector(ICalComponent * ic); + + /** + * Return the vector of JulianLogErrors on this calendar. + * Return 0 if this calendar has no error vector. + * Do not deallocate returned vector. Returns a ptr to vector, not a new vector. + */ + JulianPtrArray * getLogVector(); + + /** + * Returns the curl associated with this nsCalendar. The + * curl points to the calendar store where components in + * this nsCalendar are to be stored. It is required + * for an nsCalendar to have an associated curl if any + * of its components will be persisted in a calendar store. + * + * @return a JulianString containing the curl + */ + JulianString getCurl() const {return m_sCurl;} + + /** + * Set the default curl for this nsCalendar. + */ + void setCurl(const char* ps) {m_sCurl = ps;} + + /** + * Set the default curl for this nsCalendar. + */ + void setCurl(const JulianString& s) {m_sCurl = s;} + + /** + * Returns calendar in a human-readable format to a string. + * + * @return UnicodeString + */ + UnicodeString toString(); + + /** + * Returns the header information of this calendar in a string reference. The header + * information is defined to be the calendar properties such as + * method, version, prodid, calscale, name, and source. + * @param UnicodeString & sResult + * + * @return UnicodeString & + */ + UnicodeString & createCalendarHeader(UnicodeString & sResult); + + /** + * Returns calendar in ICAL format to a string. + * + * @return UnicodeString + */ + UnicodeString toICALString(); + + /** + * Returns calendar in ICAL format to a string with the component pattern + * specified. + * + * @return UnicodeString + */ + UnicodeString toFilteredICALString(UnicodeString componentPattern); + + /** + * Create a VFreebusy object with the correct freebusy periods + * depending on the current VEvent vector. The start and end time + * of the VFreebusy will defined from the start and end parameters. + * Clients must delete returned object. + * @param start start time of VFreebusy + * @param end end time of VFreebusy + * + * @return new VFreebusy representing freebusy time from [start-end] + */ + VFreebusy * createVFreebusy(DateTime start, DateTime end); + + /** + * Fill in a VFreebusy object with the correct freebusy periods + * depending on the current VEvent vector. The start and end time + * of the VFreebusy will defined from the DTSTART and DTEND values + * of the VFreebusy. + * @param VFreebusy * toFillIn + */ + void calculateVFreebusy(VFreebusy * toFillIn); + + /** + * Return the first VFreebusy with a specified UID and sequence no. + * If sequence number set to -1, just search on UID. + * @param sUID target UID to look for + * @param iSeqNo target seqNo to look for + * + * @return first VFreebusy matching uid, sequence number. + */ + VFreebusy * getVFreebusy(UnicodeString sUID, t_int32 iSeqNo = -1); + /*VFreebusy * getVFreebusy(JulianPtrArray * out, DateTime start, DateTime end);*/ + + /** + * Return the first VEvent with a specified UID and sequence no. + * If sequence number set to -1, just search on UID. + * @param sUID target UID to look for + * @param iSeqNo target seqNo to look for + * + * @return first VEvent matching uid, sequence number. + */ + VEvent * getEvent(UnicodeString sUID, t_int32 iSeqNo = -1); + + /** + * Return the first VTodo with a specified UID and sequence no. + * If sequence number set to -1, just search on UID. + * @param sUID target UID to look for + * @param iSeqNo target seqNo to look for + * + * @return first VTodo matching uid, sequence number. + */ + VTodo * getTodo(UnicodeString sUID, t_int32 iSeqNo = -1); + + /** + * Return the first VJournal with a specified UID and sequence no. + * If sequence number set to -1, just search on UID. + * @param sUID target UID to look for + * @param iSeqNo target seqNo to look for + * + * @return first VJournal matching uid, sequence number. + */ + VJournal * getJournal(UnicodeString sUID, t_int32 iSeqNo = -1); + + /** + * Add the ICalComponent to the vector of Events. + * NOTE: doesn't add clone of v, but actually ptr to v, so don't deallocate + * this may change later + * NOTE: changed from VEvent * v to ICalComponent * v. + * @param v VEvent to add + */ + void addEvent(ICalComponent * v); + + /** + * Append the supplied vector of events to this NSCalendar's + * event list. Note that it does not clone the events. It simply + * adds the pointer to the events to the event list. + * @param pEventList the list of events to add... + */ + void addEventList(JulianPtrArray *pEventList); + + /** + * Add the ICalComponent to the vector of Todos. + * NOTE: doesn't add clone of v, but actually ptr to v, so don't deallocate + * this may change later + * NOTE: changed from VTodo * v to ICalComponent * v. + * @param v VTodo to add + */ + void addTodo(ICalComponent * v); + + /** + * Add the ICalComponent to the vector of Journals. + * NOTE: doesn't add clone of v, but actually ptr to v, so don't deallocate + * this may change later + * NOTE: changed from VJournal * v to ICalComponent * v. + * @param v VJournal to add + */ + void addJournal(ICalComponent * v); + + /** + * Add the ICalComponent to the vector of VFreebusy. + * NOTE: doesn't add clone of v, but actually ptr to v, so don't deallocate + * this may change later + * NOTE: changed from VFreebusy * v to ICalComponent * v. + * @param v VFreebusy to add + */ + void addVFreebusy(ICalComponent * v); + + /** + * Add the ICalComponent to the vector of VTimeZone. + * NOTE: doesn't add clone of v, but actually ptr to v, so don't deallocate + * this may change later + * NOTE: changed from VTimezone * v to ICalComponent * v. + * @param v VTimeZone to add + */ + void addTimeZone(ICalComponent * v); + + /** + * Return ptr to vector of events + * @return ptr to vector of events + */ + JulianPtrArray * getEvents() const { return m_VEventVctr; } + + /** + * XXX: Temp hack. + * This is used to remove the ownership of the vector of events + * from this calendar to nobody. It does this by returning + * the pointer to m_VEventVctr, then setting the internal value + * of m_VEventVctr to 0. Thus when this NSCalendar is destroyed + * the vector of events is not. + * The caller now owns the vector of events and must delete it + * and its VEvent contents. + * This method should be called only when moving events from + * one calendar to another. + * + * @return the pointer to the vector of events + */ + JulianPtrArray * changeEventsOwnership(); + + /** + * Return ptr to vector of vfreebusies + * @return ptr to vector of vfreebusies + */ + JulianPtrArray * getVFreebusy() const { return m_VFreebusyVctr; } + + /** + * Return ptr to vector of todos + * @return ptr to vector of todos + */ + JulianPtrArray * getTodos() const { return m_VTodoVctr; } + + /** + * Return ptr to vector of journals + * @return ptr to vector of journals + */ + JulianPtrArray * getJournals() const { return m_VJournalVctr; } + + /** + * Return ptr to vector of timezones + * @return ptr to vector of timezones + */ + JulianPtrArray * getTimeZones() const { return m_VTimeZoneVctr; } + + /** + * Given a vector of components, and the type of the component, prints + * each component in vector to its default human-readable string value + * Each string is appended to resulting string and is returned in out. + * For debugging uses. + * @param components vector of components to print + * @param sType type of component in string + * @param out resulting output string + * + * @return output string (out) + */ + static UnicodeString & debugPrintComponentVector(JulianPtrArray * components, + const UnicodeString sType, UnicodeString & out); + + /** + * Fills is the vector retUID with a list of unique uids for this component type + * client must delete contents of retUID. + * @param fillin + * + * @return void + */ + void getUniqueUIDs(JulianPtrArray * retUID, ICalComponent::ICAL_COMPONENT type); + + /** + * Fills in out with VEvents with UID equal to sUID, client must + * delete contents of events + * @param XPPtrArray * out + * @param UnicodeString & sUID + * + * @return void + */ + void getEvents(JulianPtrArray * out, UnicodeString & sUID); + + + /** + * Fetch events by (uid, rec-id, modifier). + * set rec-id to "" if no rec-id. set modifier to "" if no + * modifier. + * + * @param JulianPtrArray * out + * @param UnicodeString & sUID + * @param UnicodeString & sRecurrenceID + * @param UnicodeString & sModifier + * + * @return void + */ + void getEventsByComponentID(JulianPtrArray * out, UnicodeString & sUID, + UnicodeString & sRecurrenceID, UnicodeString & sModifier); + + /** + * Get events by date range, adds ptr to out, not clones of ptrs. + */ + void getEventsByRange(JulianPtrArray * out, DateTime start, DateTime end); + + /** + * Fills in out with VTodos with UID equal to sUID, client must + * delete contents of events + * @param XPPtrArray * out + * @param UnicodeString & sUID + * + * @return void + */ + void getTodos(JulianPtrArray * out, UnicodeString & sUID); + + /** + * Fills in out with VJournals with UID equal to sUID, client must + * delete contents of events + * @param XPPtrArray * out + * @param UnicodeString & sUID + * + * @return void + */ + void getJournals(JulianPtrArray * out, UnicodeString & sUID); + + /** + * Sorts vector of components by UID, + * passing in type to decide which vector to sort + * @param type component type of vector (VEVENT, VTODO, etc.) + */ + void sortComponentsByUID(ICalComponent::ICAL_COMPONENT type); + + /** + * Sorts vector of components by DTSTART value, + * passing in type to decide which vector to sort + * @param type component type of vector (VEVENT, VTODO, etc.) + */ + void sortComponentsByDTStart(ICalComponent::ICAL_COMPONENT type); + +protected: + + /** + * Populates property data members. Does this by taking contents of + * property value and storing in appropriate property, with + * parameters also being stored. Basically a big switch statement + * on the property name. + * @param strLine current parsed line + * @param propName property name + * @param propVal property value + * @param parameters parameters of property + * + * @return TRUE (TODO: may remove later) + */ + t_bool storeData(UnicodeString & strLine, UnicodeString & propName, + UnicodeString & propVal, JulianPtrArray * parameters); + + /*void selfCheck();*/ + + /** + * Helper method that expands the VEvent, VTodo, and VJournal + * vectors. + * + * @return void + */ + void expandAllComponents(); + +private: + + + + /** + * Add component with type to correct vector. For example, + * if type == ICAL_COMPONENT_VEVENT, then add to event vector. + * Return TRUE if component was updated with component already in store, + * otherwise return FALSE if component had to be added to store. + * @param ic component to add + * @param type type of component + * @return TRUE if component was updated, FALSE if component was added + */ + t_bool addComponentWithType(ICalComponent * ic, + ICalComponent::ICAL_COMPONENT type); + +#if 0 + /** + * Adds a vector of components with type to correct vector. + * Make sure all elements in components vector have + * component type equal to type. + * @param components vector of components + * @param type type of all components in vector + */ + void addComponentsWithType(JulianPtrArray * components, + ICalComponent::ICAL_COMPONENT type); +#endif + + /** + * Expand each component in vector of TimeBasedEvents + * with component type = type. + * @param v vector of TimeBasedEvents + * @param type type of all components in vector + */ + void expandTBEVector(JulianPtrArray * v, + ICalComponent::ICAL_COMPONENT type); + + + /** + * Expand a TimeBasedEvent with component type = type + * @param e TimeBasedEvent to expand + * @param type component type of TimeBasedEvent + */ + void expandComponent(TimeBasedEvent * e, + ICalComponent::ICAL_COMPONENT type); + + /** + * Helper method sorts ICalComponents by UID. + * Only applicable for VEvent, VTodo, VJournal, VFreebusy + * vectors. + * @param components vector of components to sort + * @param type type of all components in vector + */ + static void sortComponentsByUIDHelper(JulianPtrArray * components, + ICalComponent::ICAL_COMPONENT type); + + /** + * Helper method sorts ICalComponents by DTSTART. + * Only applicable for VEvent, VTodo, VJournal, VFreebusy + * vectors. + * @param components vector of components to sort + * @param type type of all components in vector + */ + static void sortComponentsByDTStartHelper(JulianPtrArray * components, + ICalComponent::ICAL_COMPONENT type); + + /** + * Fills in retUID vector with all unique UIDs found in components vector. + * Does this by sorting components vector by UID, then marching down. + * vector. O(nlogn + n). + * @param retUID fill in with all unique UIDs + * @param components vector of components to look through + * @param type type of all components in vector. + */ + static void getUniqueUIDsHelper(JulianPtrArray * retUID, + JulianPtrArray * components, ICalComponent::ICAL_COMPONENT type); +#if 0 + /** + * Fills in out vector with ICalComponents with UID = uid and + * with GetType() == type. + * @param out fill in with components with uid, type match + * @param uid target UID + * @param type target component type + */ + void getComponentsWithType(JulianPtrArray * out, UnicodeString & uid, + ICalComponent::ICAL_COMPONENT type); +#endif + /** + * Fetch components by (uid, rec-id, modifier). + * set rec-id to "" if no rec-id. set modifier to "" if no + * modifier. + * + * @param JulianPtrArray * out + * @param UnicodeString & sUID + * @param UnicodeString & sRecurrenceID + * @param UnicodeString & sModifier + * + * @return void + */ + void getTBEWithTypeByComponentID(JulianPtrArray * out, UnicodeString & sUID, + UnicodeString & sRecurrenceID, UnicodeString & sModifier, + ICalComponent::ICAL_COMPONENT type); + + /** + * Fills in out with TimeBasedEvents with the following + * if sRecurrenceID.isValid() + * { + * if sModifier == NONE, just get components that match (uid, recid) + * else if sModifier = THISANDPRIOR, get components that match (uid, recid, THISANDPRIOR) + * else if sModifier = THISANDFUTURE, get components that match (uid, recid, THISANDFUTURE) + * + * } + * else + * call getComponents(out, components, sUID); + * + * @param JulianPtrArray * out + * @param JulianPtrArray * component + * @param UnicodeString & sUID + * @param UnicodeString & sRecurrenceID + * @param UnicodeString & sModifier + * + * @return void + */ + void getTBEByComponentID(JulianPtrArray * out, + JulianPtrArray * component, UnicodeString & sUID, + UnicodeString & sRecurrenceID, UnicodeString & sModifier); + + /** + * Fills in out with ICalComponents with UID = sUID. + * NOTE: clients NOT responsible for deleting components (passing actual ptr) + * @param out fill in with components with uid = sUID + * @param components vector of components to look through + * @param sUID target UID + */ + static void getComponents(JulianPtrArray * out, JulianPtrArray * components, + UnicodeString & sUID); + + /** + * return the ICalComponent that matches the uid and sequence # + */ + + /** + * Return the ICalComponent that matches the UID and sequence number. + * If sequence number is -1, then just match on UID. + * @param vTBE vector of components to look through + * @param sUID target UID + * @param iSeqNo target sequence number + * + * @return first ICalComponent matching UID, iSeqNo. + */ + static ICalComponent * getComponent(JulianPtrArray * vTBE, + UnicodeString & sUID, t_int32 iSeqNo = -1); + + + /** + * Prints each component in components vector to ICAL export string + * and append result to out. Resulting output string contains + * all component's iCal export string. + * @param components vector of components to print in ICAL + * @param out output string + * + * @return output string (out) + */ + static UnicodeString & printComponentVector(JulianPtrArray * components, + UnicodeString & out); + + /** + * Prints each component in components vector to ICAL export string + * to file f. Resulting output string contains all component's iCal export string. + * @param components vector of components to print in ICAL + * @param f FILE to print to + * @return TRUE if written OK, FALSE otherwise. + */ + static t_bool printComponentVectorToFile(JulianPtrArray * components, FILE * f); + +public: + /** + * Prints each component in components vector to ICAL export string + * and append result to out. Resulting output string contains + * events with filtered properties depending on strFmt. + * all component's iCal export string. + * @param components vector of components to print in ICAL + * @param strFmt component formatting string to apply + * @param out output string + * + * @return output string (out) + */ + static UnicodeString & printFilteredComponentVector(JulianPtrArray * components, + UnicodeString & strFmt, UnicodeString & out); +private: + /** + * Helper method. Fills in Freebusy object f with periods representing + * free and busy time periods of this calendar from start to end time. + * Calculates periods by looking through event vector and using + * events with TRANSP = OPAQUE. + * @param f Freebusy object to fill in with periods + * @param start start of freebusy period + * @param end end of freebusy period + */ + void createVFreebusyHelper(Freebusy * f, DateTime start, DateTime end); + + /** + * update the m_EventsSpanStart and m_EventsSpanEnd members + * taking into account new VEvent. + */ + void updateEventsRange(VEvent * v); + + + /* -- private data members -- */ + + /* parsing flags */ + static t_bool m_bLoadMultipleCalendars; + static t_bool m_bSmartLoading; + + /* vector of calendar components */ + JulianPtrArray * m_VJournalVctr; + JulianPtrArray * m_VEventVctr; + JulianPtrArray * m_VTodoVctr; + JulianPtrArray * m_VTimeZoneVctr; + JulianPtrArray * m_VFreebusyVctr; + + /* vector of x-tokens */ + JulianPtrArray * m_XTokensVctr; + + /* NSCalendar properties */ + ICalProperty * m_CalScale; + ICalProperty * m_Version; + ICalProperty * m_Prodid; +#if 0 + ICalProperty * m_Source; + ICalProperty * m_Name; +#endif + /*ICalProperty * m_Method; + UnicodeString & m_Method;*/ + + /** method is stored as int */ + t_int32 m_iMethod; + + /* log file pointer */ + JLog * m_Log; + + + /** + * the timestamp of the last time these events were updated + */ + DateTime m_EventsLastUpdatedFromServer; + + /** + * the start of end time range of events. + */ + DateTime m_EventsSpanStart; + DateTime m_EventsSpanEnd; + + JulianString m_sCurl; /* cal url to calendar store for this calendar */ +}; + +#endif /* __NSCALENDAR_H_ */ + + diff --git a/calendar/modules/core/ical/inc/nscalcoreicalexp.h b/calendar/modules/core/ical/inc/nscalcoreicalexp.h new file mode 100644 index 00000000000..89ab933d9e8 --- /dev/null +++ b/calendar/modules/core/ical/inc/nscalcoreicalexp.h @@ -0,0 +1,30 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +#ifndef nscalcoreicalexp_h__ +#define nscalcoreicalexp_h__ + +#include "nscore.h" + +#ifdef _IMPL_NS_CAL_CORE_ICAL +#define NS_CAL_CORE_ICAL NS_EXPORT +#else +#define NS_CAL_CORE_ICAL NS_IMPORT +#endif + +#endif /* nscalcoreicalexp_h__ */ diff --git a/calendar/modules/core/ical/inc/orgnzr.h b/calendar/modules/core/ical/inc/orgnzr.h new file mode 100644 index 00000000000..49baa55ce5f --- /dev/null +++ b/calendar/modules/core/ical/inc/orgnzr.h @@ -0,0 +1,273 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +/* + * orgnzr.h + * John Sun + * 4/7/98 11:16:49 AM + */ + +#ifndef __JULIANORGANIZER_H_ +#define __JULIANORGANIZER_H_ + +#include "jlog.h" +#include "prprty.h" + +/** + * Encapsulates a Calendar Component's organizer. + * Similar to the Attendee property, but doesn't + * have as much state. + */ +class JulianOrganizer : public ICalProperty +{ +private: + /*----------------------------- + ** MEMBERS + **---------------------------*/ + + /** + * the name of the JulianOrganizer. Whatever is to the right of the colon + * the name must be a URL. Field must be filled to be valid Attendee. + */ + UnicodeString m_Name; + + /** the common name of attendee. Optional, default is "". */ + UnicodeString m_CN; + + /** the MAILTO: of a calendar user acting on behalf of the attendee. + * Optional, default is "". + */ + UnicodeString m_SentBy; + + /** the location of the Attendee's directory information. + * Optional, default is "". */ + UnicodeString m_Dir; + + /** the language of the common name of the attendee. Optional, default is "". */ + UnicodeString m_Language; + + /** ptr to log file to write errors to */ + JLog * m_Log; + + static const t_int32 ms_cJulianOrganizerName;/* = 'N';*/ + static const t_int32 ms_cJulianOrganizerDir; /* = 'l'; 'el'*/ + static const t_int32 ms_cJulianOrganizerSentBy;/* = 's';*/ + static const t_int32 ms_cJulianOrganizerCN;/* = 'C';*/ + static const t_int32 ms_cJulianOrganizerLanguage;/* = 'm';*/ + static const t_int32 ms_cJulianOrganizerDisplayName;/* = 'z';*/ + + /*----------------------------- + ** PRIVATE METHODS + **---------------------------*/ + JulianOrganizer(JulianOrganizer & that); + +public: + + /*----------------------------- + ** CONSTRUCTORS and DESTRUCTORS + **---------------------------*/ + JulianOrganizer(JLog * initLog = 0); + ~JulianOrganizer(); + + /*---------- To satisfy ICalProperty interface ----------*/ + /** + * Sets parameters. + * @param parameters vector of parameters to set + * + */ + virtual void setParameters(JulianPtrArray * parameters); + + /** + * Return value of property. Never use. Use getName(). + * + * @return value of property + */ + virtual void * getValue() const; + + /** + * Sets value of property. Never use. Use setName(). + * @param value new value of property + * + */ + virtual void setValue(void * value); + + /** + * Returns a clone of this property. + * @param initLog the log file for clone to write to + * + * @return clone of this ICalProperty object + */ + virtual ICalProperty * clone(JLog * initLog); + + /** + * Checks whether this property is valid or not. Must have MAILTO: in + * front of attendee name to be valid. + * + * @return TRUE if property is valid, FALSE otherwise + */ + virtual t_bool isValid(); + + /** + * Return property to human-readable string. + * @param dateFmt formatting string + * @param out output human-readable string + * + * @return output human-readable string (out) + */ + virtual UnicodeString & toString(UnicodeString & strFmt, UnicodeString & out); + + /** + * Return property to human-readable string. + * @param out output human-readable string + * + * @return output human-readable string (out) + */ + virtual UnicodeString & toString(UnicodeString & out); + + /** + * Return property to iCal property string. + * @param out output iCal string + * + * @return output iCal string (out) + */ + virtual UnicodeString & toICALString(UnicodeString & out); + + /** + * Return property to iCal property string. Inserts sProp to + * front of output string. sProp should be the property name of this + * property. + * @param sProp property name to append to insert at front of out + * @param out output iCal string with sProp in front + * + * @return output iCal string with sProp in front (out) + */ + virtual UnicodeString & toICALString(UnicodeString & sProp, UnicodeString & out); + /*----------End of ICalProperty interface----------*/ + + /*----------------------------- + ** ACCESSORS (GET AND SET) + **---------------------------*/ + + /** + * Sets JulianOrganizer name. + * @param sName new Attendee name + * + */ + void setName(UnicodeString sName); + + /** + * Returns JulianOrganizer name. + * + * @return Attendee name + */ + UnicodeString getName() const { return m_Name; } + + /** + * Set CN (common-name) value + * @param new CN value + */ + void setCN(UnicodeString u) { m_CN = u; } + + /** + * Set Language value + * @param new Language value + */ + void setLanguage(UnicodeString u) { m_Language = u; } + + /** + * Set DIR (location of directory info) value + * @param new DIR value + */ + void setDir(UnicodeString u) { m_Dir = u; } + + /** + * Set SENT-BY (calendar user acting on behalf of the attendee) value + * @param new SENT-BY value + */ + void setSentBy(UnicodeString u) { m_SentBy = u; } + + /** + * Return CN (common-name) value + * + * @return CN value + */ + UnicodeString getCN() const { return m_CN; } + + /** + * Return Language value + * + * @return Language value + */ + UnicodeString getLanguage() const { return m_Language; } + + /** + * Return DIR (location of directory info) value + * + * @return DIR value + */ + UnicodeString getDir() const { return m_Dir; } + + /** + * Return SENT-BY (calendar user acting on behalf of the organizer) value + * + * @return SENT-BY value + */ + UnicodeString getSentBy() const { return m_SentBy; } + + /*----------------------------- + ** UTILITIES + **---------------------------*/ + + /** + * Given attendee name and parameters, populates Attendee + * data members. + * @param propVal attendee name + * @param parameters attendee parameters + * + */ + void parse(UnicodeString & propVal, JulianPtrArray * parameters = 0); + + /** + * Sets parameter with name paramName with value paramVal. + * For MEMBER, DELEGATED-TO, DELEGATED-FROM, DIR, SENT-BY, the + * double quotes are stripped. THE MAILTO: is not stripped. + * + * @param paramName parameter name to set + * @param paramVal new value of parameter + */ + void setParam(UnicodeString & paramName, UnicodeString & paramVal); + + /** + * convert a character to the content of a parameter in + * human-readable string format + * + * @param c a character represents a parameter + * @return parameter in a human-readable string + */ + UnicodeString toStringChar(t_int32 c); + + /*----------------------------- + ** STATIC METHODS + **---------------------------*/ + /*----------------------------- + ** OVERLOADED OPERATORS + **---------------------------*/ +}; + +#endif /* __JULIANORGANIZER_H_ */ + diff --git a/calendar/modules/core/ical/inc/period.h b/calendar/modules/core/ical/inc/period.h new file mode 100644 index 00000000000..e3b6699f90f --- /dev/null +++ b/calendar/modules/core/ical/inc/period.h @@ -0,0 +1,319 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +/* + * period.h + * John Sun + * 1/29/98 11:16:33 AM + */ + +#ifndef __PERIOD_H_ +#define __PERIOD_H_ + +#include "datetime.h" +#include "duration.h" +#include "ptrarray.h" + +class Period +{ +private: + + /*----------------------------- + ** MEMBERS + **---------------------------*/ + + /** the starting time of the period */ + DateTime m_DTStart; + + /** the ending time of the period */ + DateTime m_DTEnd; + + /** the duration of the period */ + Julian_Duration m_Duration; + + /*----------------------------- + ** PRIVATE METHODS + **---------------------------*/ + + /** + * Parses an iCal Period string and + * populates date members. + * @param us iCal Period string + */ + void parse(UnicodeString & us); + + /** checks period's data members */ + void selfCheck(); + + /** create invalid period */ + void createInvalidPeriod(); + + + /** + * Helper method to get a part of period string. + * If bStart is TRUE, get the start string part, + * else get end string part. + * @param sPeriod period string + * @param bStart start or end + * @param out output start or end string + * + * @return output start or end string (out) + */ + static UnicodeString & getTimeString(UnicodeString & sPeriod, + t_bool bStart, UnicodeString & out); +public: + + /** + * Retuns ending time regardless if dtend is invalid. + * If DTEnd is invalid, will then add duration to start to + * get ending time. + * @param d output ending datetime + * + * @return ouptu ending datetime (d) + */ + DateTime & getEndingTime(DateTime & d); + + /** + * Constructor. Creates invalid period. + */ + Period(); + + /** + * Copy constructor. + * @param that period to copy + */ + Period(Period & that); + + /** + * Constructor. Creates period by parsing string. + * @param us string to parse + */ + Period(UnicodeString & us); + + /** + * Destructor. + */ + ~Period(); + + /** + * Return start time. + * + * @return DateTime + */ + DateTime getStart() { return m_DTStart; } + + /** + * Return dtend (may be invalid). + * + * @return DateTime + */ + DateTime getEnd() { return m_DTEnd; } + + /** + * Return duration (may be invalid). + * + * @return Julian_Duration + */ + Julian_Duration getDuration() { return m_Duration; } + + /** + * Set start time + * @param d new start value + */ + void setStart(DateTime d); + + /** + * Set end time + * @param d new end value + */ + void setEnd(DateTime d); + + /** + * Set duration + * @param d new duration value + */ + void setDuration(Julian_Duration d); + + /** + * Set period by passing string. + * @param us string to parse. + */ + void setPeriodString(UnicodeString & us); + + /* UTILITIES */ + + /** + * Return if this period is valid. A valid period must have a + * valid start datetime and a valid end datetime or a valid duration time. + * and the end time must be after the start time. + * + * @return TRUE if valid, FALSE otherwise + */ + t_bool isValid(); + + /** + * Return if this period intersects start, end range + * @param start start of target range + * @param end end of target range + * + * @return TRUE if in range, FALSE otherwise + */ + t_bool isIntersecting(DateTime & start, DateTime & end); + + /** + * Return if this period intersects period range + * @param p target range + * + * @return TRUE if in range, FALSE otherwise + */ + t_bool isIntersecting(Period & p); + + /** + * Return if this period is completely inside start, end range + * @param start start of target range + * @param end end of target range + * + * @return TRUE if completely inside range, FALSE otherwise + */ + t_bool isInside(DateTime & start, DateTime & end); + + /** + * Return if this period is completely inside period range + * @param p target range + * + * @return TRUE if in range, FALSE otherwise + */ + t_bool isInside(Period & p); + + /** + * Returns period in human readable format of "start - end". + * + * @return output string + */ + UnicodeString toString(); + + /** + * Returns period in iCal period format of "start/end", where + * start is UTC ISO8601 datetime format and end is either + * a UTC IS08601 datetime format or an iCal Julian_Duration string. + * + * @return output string + */ + UnicodeString toICALString(); + + /* STATIC METHODS */ + + /** + * Checks whether periods are connected. Connected means that the + * two periods combined form one block of time. Returns TRUE if + * p1 and p2 are connected, FALSE otherwise. + * @param p1 first period + * @param p2 second period + * + * @return TRUE if p1,p2 are connected, FALSE otherwise + */ + static t_bool IsConnectedPeriods(Period & p1, Period & p2); + + /** + * Returns the union of two periods in outPer, if possible. + * If the union of the two-periods is not possible in one period + * (i.e. inPer1, inPer2 are disjoint) then return an invalid period. + * @param inPer1 first period + * @param inPer2 second period + * @param outPer return union of inPer1, inPer2. + * Invalid if inPer1,inPer are disjoint + */ + static void Union(Period & inPer1, Period & inPer2, Period & outPer); + + /** + * Returns the intersection of this period with the range + * (start,end) into outPer if possible. If the + * intersection is null (i.e. inPer1, [start, end) are disjoint) + * then return an invalid period in outPer. + * @param iPer1 a period + * @param start start of range + * @param end end of range + * @param outPer output intersection of iPer1 with (start,end) range + * + */ + static void Intersection(Period & iPer1, DateTime & start, DateTime & end, Period & outPer); + + /** + * Fill in vector out with periods inside inPer that are outside of + * (start, end) range. This simulates logical subtraction of periods + * @param inPer a period + * @param start start of range + * @param end end of range + * @param out output vector of periods inside inPer but outside (start,end) + * + */ + static void SubtractedPeriod(Period & inPer, DateTime & start, DateTime & end, JulianPtrArray * out); + + /** + * Checks to see if u is a parseable iCal Period string. Return TRUE + * if parseable, FALSE otherwise. + * @param u target period string + * + * @return TRUE if parseable iCal Period, FALSE otherwise. + */ + static t_bool IsParseable(UnicodeString & u); + + + /** + * Gets starting time string from sPeriod. + * @param sPeriod input period string + * @param out output starting time string + * + * @return output starting time string (out) + */ + static UnicodeString & getStartTimeString(UnicodeString & sPeriod, UnicodeString & out); + + /** + * Gets ending time string from sPeriod. Ending time maybe a + * duration string or a datetime string + * @param sPeriod input period string + * @param out output ending time string + * + * @return output ending time string (out) + */ + static UnicodeString & getEndTimeString(UnicodeString & sPeriod, UnicodeString & out); + + /** + * Compares periods by their starting time. Used + * to pass into JulianPtrArray::QuickSort method. + * @param a ptr to first period + * @param b ptr to second period + * + * @return compareTo(a.start, b.start) + */ + static int ComparePeriods(const void * a, const void * b); + + /** + * Compares periods by their ending time. Used + * to pass into JulianPtrArray::QuickSort method. + * @param a ptr to first period + * @param b ptr to second period + * + * @return compareTo(a.getEndingTime(), b.getEndingTime()) + */ + static int ComparePeriodsByEndTime(const void * a, const void * b); +}; + +#endif /* __PERIOD_H_ */ + + diff --git a/calendar/modules/core/ical/inc/pprprty.h b/calendar/modules/core/ical/inc/pprprty.h new file mode 100644 index 00000000000..e90e5772b6d --- /dev/null +++ b/calendar/modules/core/ical/inc/pprprty.h @@ -0,0 +1,124 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +/* + * pprprty.h + * John Sun + * 2/12/98 4:20:47 PM + */ + +#include +#include "sdprprty.h" +#include "period.h" + +#ifndef __PERIODPROPERTY_H_ +#define __PERIODPROPERTY_H_ + +/** + * PeriodProperty is a subclass of StandardProperty. It implements the ICalProperty + * interface for ICAL properties with TYPE=PERIOD. + */ +class PeriodProperty: public StandardProperty +{ +private: + /** the Period value of the property */ + Period * m_Period; + + /** + * Default constructor + */ + PeriodProperty(); + + /** + * Copy constructor + * @param that property to copy + */ + PeriodProperty(const PeriodProperty & that); +public: + + /** + * Constructor that sets value of property to contents of value + * and makes a copy of the contents of parameters ptr. + * @param value value of property + * @param parameters parameters of property + */ + PeriodProperty(Period * value, JulianPtrArray * parameters); + + /** + * Destructor + */ + ~PeriodProperty(); + + /** + * Return the value of the property + * @return void * ptr to value of the property + */ + virtual void * getValue() const; + + /** + * Set the value of the property + * @param value the value to set property to + */ + virtual void setValue(void * value); + + /** + * Returns a clone of this property. Clients are responsible for deleting + * the returned object. + * + * @return a clone of this property. + */ + virtual ICalProperty * clone(JLog * initLog); + + /** + * Return TRUE if property is valid, FALSE otherwise + * + * @return TRUE if is valid, FALSE otherwise + */ + virtual t_bool isValid(); + + /** + * Return a string in human-readable form of the property. + * @param out contains output human-readable string + * + * @return the property in its human-readable string format + */ + virtual UnicodeString & toString(UnicodeString & out); + + /** + * Return a string in human-readable form of the property. + * @param dateFmt format string options + * @param out contains output human-readable string + * + * @return the property in its human-readable string format + */ + virtual UnicodeString & toString(UnicodeString & dateFmt, UnicodeString & out); + + /** + * Return the property's string in the ICAL format. + * @param out contains output ICAL string + * + * @return the property in its ICAL string format + */ + virtual UnicodeString & toExportString(UnicodeString & out); +}; + +#endif /* __PERIODPROPERTY_H_ */ + + + + diff --git a/calendar/modules/core/ical/inc/prprty.h b/calendar/modules/core/ical/inc/prprty.h new file mode 100644 index 00000000000..611ec8238d7 --- /dev/null +++ b/calendar/modules/core/ical/inc/prprty.h @@ -0,0 +1,411 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +/* + * prprty.h + * John Sun + * 2/10/98 4:03:56 PM + */ + +#include +#include "jdefines.h" +#include "ptrarray.h" +#include "icalprm.h" +#include "jatom.h" +#include "jlog.h" +#include "nscalcoreicalexp.h" + +#ifndef __ICALPROPERTY_H_ +#define __ICALPROPERTY_H_ + +/** + * The ICalProperty class defines the interface for methods that + * all iCal Calendar properties must implement. Also defines some + * static helper methods. + */ +class NS_CAL_CORE_ICAL ICalProperty +{ +public: + /** Enumeration defines ICalProperty types */ + enum PropertyTypes{TEXT, DATETIME, INTEGER, PERIOD, DURATION, BOOLEAN}; + +protected: + + /** + * Default constructor. Hide from clients. + * Only subclasses allowed to use it. + */ + ICalProperty(); + + /** + * Copy constructor. + * @param that ICalProperty to copy + */ + ICalProperty(ICalProperty & that); + +public: + + /** + * Virtual Destructor. + */ + virtual ~ICalProperty() {} + + /* -- interface of methods that subclasses must implement (pure-virtual) -- */ + + /** + * Sets parameters. + * @param parameters vector of parameters to set + * + */ + virtual void setParameters(JulianPtrArray * parameters) + { PR_ASSERT(FALSE); if (parameters) {} } + + /** + * Return value of property + * + * @return value of property + */ + virtual void * getValue() const { PR_ASSERT(FALSE); return 0;} + + /** + * Sets value of property. + * @param value new value of property + * + */ + virtual void setValue(void * value) { PR_ASSERT(FALSE); if (value != 0) {} ; } + + /** + * Returns a clone of this property. + * @param initLog the log file for clone to write to + * + * @return clone of this ICalProperty object + */ + virtual ICalProperty * clone(JLog * initLog) + { PR_ASSERT(FALSE); if (initLog) {} return 0; } + + /** + * Checks whether this property is valid or not + * + * @return TRUE if property is valid, FALSE otherwise + */ + virtual t_bool isValid() { PR_ASSERT(FALSE); return FALSE; } + + /** + * Return property to human-readable string. + * @param dateFmt formatting string + * @param out output human-readable string + * + * @return output human-readable string (out) + */ + virtual UnicodeString & toString(UnicodeString & dateFmt, + UnicodeString & out) + { PR_ASSERT(FALSE); if (dateFmt.size() > 0) {} ; return out; } + + /** + * Return property to human-readable string. + * @param out output human-readable string + * + * @return output human-readable string (out) + */ + virtual UnicodeString & toString(UnicodeString & out) + { PR_ASSERT(FALSE); return out; } + + + /** + * Return property to iCal property string. + * @param out output iCal string + * + * @return output iCal string (out) + */ + virtual UnicodeString & toICALString(UnicodeString & out) { PR_ASSERT(FALSE); return out; } + + /** + * Return property to iCal property string. Inserts sProp to + * front of output string. sProp should be the property name of this + * property. + * @param sProp property name to append to insert at front of out + * @param out output iCal string with sProp in front + * + * @return output iCal string with sProp in front (out) + */ + virtual UnicodeString & toICALString(UnicodeString & sProp, + UnicodeString & out) + { PR_ASSERT(FALSE); if (sProp.size() > 0) {} return out; } + +#if 0 + virtual UnicodeString & getParameterValue(UnicodeString & paramName, /* IN */ + UnicodeString & paramVal, ErrorCode & status) /* OUT, OUT */ + { + PR_ASSERT(FALSE); if (paramName.size() > 0 && paramVal.size() > 0 && + status) {} + return paramVal; + } + + virtual void setParameter(UnicodeString & paramName, UnicodeString & paramValue) + { + PR_ASSERT(FALSE); if (paramName.size() > 0 && paramValue.size() > 0) {} + } + + void parse(UnicodeString & in) { PR_ASSERT(FALSE); if (in.size() > 0) {}} +#endif + + /* -- END of interface of methods that subclasses must implement (pure-virtual) -- */ + + + /*---------------------------- + ** STATIC METHODS + **--------------------------*/ + + /** + * Given propertyName, propertyValue, and parameters, returns the following string + * - propertyName:parameters[0];parameters[1]...:propertyValue + * @param sProp the property name + * @param sVal the property value + * @param parameters the parameters + * @param retVal the output string + * @return retVal (the output string) + */ + static UnicodeString & propertyToICALString(UnicodeString & sProp, UnicodeString & sVal, + JulianPtrArray * parameters, UnicodeString & retVal); + + /** + * prints string parameters to ICAL export format + * @param sParam parameter name + * @param sVal string parameter value + * @param out output string + * + * @return output string (out) + */ + static UnicodeString & parameterToCalString(UnicodeString sParam, + UnicodeString & sVal, UnicodeString & out); + + /** + * prints string parameters to ICAL export format + * @param sParam parameter name + * @param v vector of strings parameter value + * @param out output string + * + * @return output string (out) + */ + static UnicodeString & parameterVToCalString(UnicodeString param, + JulianPtrArray * v, UnicodeString & out); + + /** + * Prints the property to ICAL format of form + * propName;property.parameters:property.value. + * A null property returns "". + * @param propName property name + * @param property ICalProperty to print + * @param retVal output string + * + * @return output string (retVal) + */ + static UnicodeString & propertyToICALString(UnicodeString & propName, + ICalProperty * property, UnicodeString & retVal); + + /** + * Prints the properties to ICAL format of form + * propName;property1.parameters:property1.value. + * propName;property2.parameters:property2.value. + * propName;property3.parameters:property3.value. + * A null property returns "". + * @param propName property name + * @param properties vector of ICalProperty's to print + * @param retVal output string + * + * @return output string (retVal) + */ + static UnicodeString & propertyVectorToICALString(UnicodeString & propName, + JulianPtrArray * properties, UnicodeString & retVal); + + /** + * Prints the strings to output. Used for printing X-Tokens + * @param strings vector of UnicodeStrings to print + * @param retVal output string + * + * @return output string (retVal) + */ + static UnicodeString & vectorToICALString(JulianPtrArray * strings, UnicodeString & retVal); + + /** + * Prints the property to human-readable format. If property is null return "". + * @param property ICalProperty to print + * @param dateFmt Formatting string to pass to property + * @param retVal output string + * + * @return output string (retVal) + */ + static UnicodeString & propertyToString(ICalProperty * property, UnicodeString & dateFmt, + UnicodeString & retVal); + + /** + * Prints the property to human-readable format. If property is null return "". + * @param property ICalProperty to print + * @param retVal Formatting string to pass to property + * + * @return output string (retVal) + */ + static UnicodeString & propertyToString(ICalProperty * property, UnicodeString & retVal); + + /** + * Prints each ICalProperty in properties to human-readable format. + * @param properties vector of ICalProperty's to print + * @param retVal output string + * + * @return output string (retVal) + */ + static UnicodeString & propertyVectorToString(JulianPtrArray * properties, + UnicodeString & retVal); + + + /** + * Prints each ICalProperty in properties to human-readable format. + * @param properties vector of ICalProperty's to print + * @param dateFmt Formatting string to pass to property + * @param retVal output string + * + * @return static UnicodeString + */ + static UnicodeString & propertyVectorToString(JulianPtrArray * properties, + UnicodeString & dateFmt, UnicodeString & retVal); + +#if 0 + /** + * Given a property name, a parameter name and parameter value, + * make sure that the parameter name is valid for the property. + * Doesn't do anything for the ATTENDEE, FREEBUSY, Recurrence-ID special + * properties. + * @param propName property name + * @param paramName parameter name + * @param paramVal parameter value + * + * @return TRUE if parameter name is valid for property, FALSE otherwise + */ + static t_bool checkParam(UnicodeString & propName, UnicodeString & paramName, + UnicodeString & paramVal); +#endif + + /** + * Given a vector of ICalParameters, an array of valid parameter names, + * and the size of array, return TRUE if all parameters are in the range, + * otherwise return FALSE. + * @param parameters vector of ICalParameter's + * @param validParamNameRange[] array of valid parameter name atoms + * @param validParamNameRangeSize size of validParamNameRange[] + * + * @return TRUE if all parameters in range, FALSE otherwise. + */ + static t_bool CheckParams(JulianPtrArray * parameters, + JAtom validParamNameRange[], + t_int32 validParamNameRangeSize); + + /** + * 7-23-98: TODO: eliminate passing in validValueRange and validValueRangeSize + * now checks for VALUE, ENCOIDNG, RELTYPE values. + * TODO: check RELATED + * given a vector of ICalParameters, an array of valid parameter names, + * and the size of array, an array of valid parameter values for the valueParamName + * type(usually VALUE, but can be RELTYPE), + * return TRUE if all parameters are in the range and the VALUE parameter value + * is in the validValueRange. Otherwise return FALSE; + * @param parameters vector of ICalParameter's + * @param validParamNameRange[] array of valid parameter name atoms + * @param validParamNameRangeSize size of validParamNameRange[] + * @param validValueRange[] array of valid parameter value atoms + * @param validValueRangeSize size of validValudRange[] + * + * @return TRUE if all parameter name and value in range, FALSE otherwise + */ + static t_bool CheckParamsWithValueRangeCheck(JulianPtrArray * parameters, + JAtom validParamNameRange[], + t_int32 validParamNameRangeSize, + JAtom validValueRange[], + t_int32 validValueRangeSize); + + /** + * Parse a line of iCal input and return output into outName, outVal, + * and fill in parameters vector with parsed parameters of line. + * @param aLine input iCal line + * @param outName output property name + * @param outVal output property value + * @param parameters fill-in vector of parameters + */ + static void parsePropertyLine(UnicodeString & aLine, + UnicodeString & outName, UnicodeString & outVal, + JulianPtrArray * parameters); + + + /** + * Trims UnicodeStrings. The UnicodeString::trim() method + * seems to only trim space-separators(ASCII 12 and ' '). + * This method also trims line-seperators(ASCII 13). + * @param string to trim. + * + * @return trimmed string in s + */ + static UnicodeString & Trim(UnicodeString & s); + + /** + * Cleanup method. Deletes each ICalParameter object in vector. + * Doesn't delete actual vector though. + * @param parameters vector of ICalParameter objects + * + */ + static void deleteICalParameterVector(JulianPtrArray * parameters); + + /** + * Cleanup method. Deletes each ICalProperty object in vector. + * Doesn't delete actual vector though. + * @param parameters vector of ICalProperty objects + * + */static void deleteICalPropertyVector(JulianPtrArray * properties); + + /** + * Cleanup method. Deletes each Period object in vector. + * Doesn't delete actual vector though. + * @param parameters vector of Period objects + * + */ + static void deletePeriodVector(JulianPtrArray * periods); + + static UnicodeString & multiLineFormat(UnicodeString & s); + static t_bool IsXToken(UnicodeString & s); + + /** + * Fills out vector with the clone of each ICalProperty in + * the propertiesToClone vector. + * @param propertiesToClone vector of properties to clone + * @param out output vector of clones + * @param initLog log file for clones to write to + * + */ + static void CloneICalPropertyVector(JulianPtrArray * propertiesToClone, JulianPtrArray * out, + JLog * initLog); + + /** + * Fills out vector with the clone of each UnicodeString in + * the stringsToClone vector. + * @param stringsToClone vector of strings to clone + * @param out output vector of clones of strings + * + */ + static void CloneUnicodeStringVector(JulianPtrArray * stringsToClone, JulianPtrArray * out); + +}; + +#endif /* __ICALPROPERTY_H_ */ diff --git a/calendar/modules/core/ical/inc/prprtyfy.h b/calendar/modules/core/ical/inc/prprtyfy.h new file mode 100644 index 00000000000..a2d377d519b --- /dev/null +++ b/calendar/modules/core/ical/inc/prprtyfy.h @@ -0,0 +1,67 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +/* + * prprtyfy.h + * John Sun + * 2/12/98 5:17:48 PM + */ + +#include "prprty.h" + +#ifndef __ICALPROPERTYFACTORY_H_ +#define __ICALPROPERTYFACTORY_H_ + +/** + * ICalPropertyFactory is a factory class that creates + * ICalProperty instances. + * + * @see ICalProperty + */ +class ICalPropertyFactory +{ +private: + + /** + * Hide default constructor from use. + */ + ICalPropertyFactory(); + +public: + + /** + * Factory method that creates ICalProperty objects. + * Clients should call this method to create ICalProperty + * objects. Clients are responsible for de-allocating returned + * object. + * + * @param aType the type of ICALProperty + * @param value the initial value of the property + * @param parameters the initial parameters of the property + * + * @return ptr to the newly created ICalProperty object + * @see ICalProperty + */ + static ICalProperty * Make(ICalProperty::PropertyTypes aType, + void * value, JulianPtrArray * parameters); +}; + +#endif /* __ICALPROPERTYFACTORY_H_ */ + + + diff --git a/calendar/modules/core/ical/inc/rcrrence.h b/calendar/modules/core/ical/inc/rcrrence.h new file mode 100644 index 00000000000..2e3adaae1a1 --- /dev/null +++ b/calendar/modules/core/ical/inc/rcrrence.h @@ -0,0 +1,530 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +/* + * rcrrence.h + * John Sun + * 2/2/98 10:45:13 AM + */ + +#ifndef __RECURRENCE_H_ +#define __RECURRENCE_H_ + +#include "datetime.h" +#include "duration.h" +#include "rrday.h" +#include "ptrarray.h" +#include "jutility.h" +#include "dategntr.h" +#include "bymgntr.h" +#include "byhgntr.h" +#include "bywngntr.h" +#include "byydgntr.h" +#include "bymogntr.h" +#include "bymdgntr.h" +#include "bydygntr.h" +#include "bydwgntr.h" +#include "bydmgntr.h" +#include "deftgntr.h" +#include "jlog.h" + +//#define JULIAN_DEBUGGING_RECURRENCE 1 + +class Recurrence +{ + +public: + + /* moved the Recurrence Type constants to JulianUtility. */ +#if 0 + /** + * Creates a Recurrence object specified by the given string. + * + * @param startDate the start time of the first recurrence + * @param stopDate the end time of the first recurrence + * @param duration the time between start and stopdate + * @param ruleString the recurrence rule string to parse + */ + Recurrence(DateTime startDate, DateTime stopDate, Julian_Duration * duration, + UnicodeString & ruleString); + + /** + * Creates a Recurrence object specified by the given string. + * + * @param startDate the start time of the first recurrence + * @param duration the time between start and stopdate + * @param ruleString the recurrence rule string to parse + */ + Recurrence(DateTime startDate, Julian_Duration * duration, UnicodeString & ruleString); +#endif + /** + * Creates a Recurrence object specified by the given string. + * + * @param startDate the start time of the first recurrence + * @param ruleString the recurrence rule string to parse + */ + Recurrence(DateTime startDate, UnicodeString & ruleString); + + /** + * Destructor + */ + ~Recurrence(); + + /** + * Checks if recurrence rule is valid. Validity is checked during parsing. + * + * @return TRUE if valid rule, FALSE otherwise + */ + t_bool isValid() const; + + + /*static void toPatternOut(JulianPtrArray * srr, JulianPtrArray * ser, + JulianPtrArray * srd, JulianPtrArray * sed);*/ + + /** + * The same functionality as enforce except it works with a vector of strings. + * @param startDate start time of recurrence + * @param srr vector of RRULE strings + * @param ser vector of EXRULE strings + * @param srd vector of RDATE strings + * @param sed vector of EXDATE strings + * @param bound number of dates to be produced + * @param out vector containing generated dates + * + */ + static void stringEnforce(DateTime startDate, JulianPtrArray * srr, + JulianPtrArray * ser, JulianPtrArray * srd, JulianPtrArray * sed, + t_int32 bound, JulianPtrArray * out, JLog * log); + + + /** + * The enforce method handles two lists of recurrences which specifies rules for defining + * occurrence dates and rules for defining exclusion dates. The method appropriately + * generates all the dates and returns a list with all excluded dates removed. + * + * A fearful function that forcefully fathoms the fullness of a few recurrences. + * + * @param rr a vector of recurrence rules (Recurrence objects) + * @param er a vector of exclusion rules (Recurrence objects) + * @param rd a vector of explicit recurrence dates (DateTime objects) + * @param ed a vector of explicit exclusion dates (DateTime objects) + * @param bound number of dates to be produced + */ + static void enforce(JulianPtrArray * rr, JulianPtrArray * er, JulianPtrArray * rd, + JulianPtrArray * ed, t_int32 bound, JulianPtrArray * out, JLog * log); + + + /** + * Unzips a recurrence rule (i.e., produces a set of dates which the recurrence represents) to a certain + * number of dates inside of a given timezone. + * + * @param bound the number of dates to produce + * @param out vector containing generated dates + * @param bAddStartDate always adds first date to out vector + */ + void unzip(t_int32 bound, JulianPtrArray * out, JLog * log, t_bool + bAddStartDate = TRUE); + + + /** + * Converts iCal Recurrence Day string to Calendar::EDaysOfWeek value + * @param s recurrence day string + * @param error output if bad day value + * + * @return the Calendar::EDaysOfWeek value of s + */ + static t_int32 stringToDay(UnicodeString & s, t_bool & error); + + /* index into m_GntrVctr of appropriate generator */ + static const t_int32 ms_iByMinuteGntrIndex; + static const t_int32 ms_iByHourGntrIndex; + static const t_int32 ms_iByWeekNoGntrIndex; + static const t_int32 ms_iByYearDayGntrIndex; + static const t_int32 ms_iByMonthGntrIndex; + static const t_int32 ms_iByMonthDayGntrIndex; + static const t_int32 ms_iByDayYearlyGntrIndex; + static const t_int32 ms_iByDayMonthlyGntrIndex; + static const t_int32 ms_iByDayWeeklyGntrIndex; + static const t_int32 ms_iDefaultGntrIndex; + static const t_int32 ms_iGntrSize; + +private: + + /* Hide default constructor */ + Recurrence(); + + /* The ordering of this array represents the recursive structure through which dates + * will be determined. the first array contains tags which operate over a year, the + * second those which operate over a month, the third a week, etc. + */ + static const t_int32 * ms_aaiGenOrder[]; + + /* Generator order of each span. There are six spans. */ + static const t_int32 ms_aiGenOrderZero[]; + static const t_int32 ms_aiGenOrderOne[]; + static const t_int32 ms_aiGenOrderTwo[]; + static const t_int32 ms_aiGenOrderThree[]; + static const t_int32 ms_aiGenOrderFour[]; + static const t_int32 ms_aiGenOrderFive[]; + + /* length of each generator order array */ + static const t_int32 ms_GenOrderLen; + static const t_int32 ms_GenOrderZeroLen; + static const t_int32 ms_GenOrderOneLen; + static const t_int32 ms_GenOrderTwoLen; + static const t_int32 ms_GenOrderThreeLen; + static const t_int32 ms_GenOrderFourLen; + static const t_int32 ms_GenOrderFiveLen; + + /*----------------------------- + ** MEMBERS + **---------------------------*/ + + /** variable to specify unset value */ + static const t_int32 ms_iUNSET; + + /* Variables that correspond directly to properties defined in the spec */ + t_int32 m_iType; /* init to JulianUtility::RT_NONE */ + Julian_Duration * m_Interval; /* init to NULL */ + t_int32 m_iCount; /* init to ms_iUNSET */ + t_int32 m_iWkSt; /* init to Calendar::MONDAY */ + DateTime m_Until; /* init to Invalid DateTime */ + + /* ByDay contains an array of day, integer pairs. days are specified from the standard Java + calendar object, IE, Calendar.MONDAY. the integer specifies the nth instance of that day + of the week. if all instances are specified (ie, BYDAY=FR), then the integer value is + left to zero. */ + RRDay * m_aaiByDay; + + /* ptr to parameters for each generator */ + t_int32 * m_aiByMinute; + t_int32 * m_aiByHour; + t_int32 * m_aiByMonthDay; + t_int32 * m_aiByYearDay; + t_int32 * m_aiBySetPos; + t_int32 * m_aiByWeekNo; + t_int32 * m_aiByMonth; + + /* the bysetpos length */ + t_int32 m_iBySetPosLen; + + /* vector of generators, order is extremely important! */ + JulianPtrArray * m_GntrVctr; + + /* Individual GENERATORS */ + ByMinuteGenerator * ms_ByMinuteGntr; + ByHourGenerator * ms_ByHourGntr; + ByWeekNoGenerator * ms_ByWeekNoGntr; + ByYearDayGenerator * ms_ByYearDayGntr; + ByMonthGenerator * ms_ByMonthGntr; + ByMonthDayGenerator * ms_ByMonthDayGntr; + ByDayYearlyGenerator * ms_ByDayYearlyGntr; + ByDayMonthlyGenerator * ms_ByDayMonthlyGntr; + ByDayWeeklyGenerator * ms_ByDayWeeklyGntr; + DefaultGenerator * ms_DefaultGntr; + + /* Number of active generators */ + t_int32 m_iActiveGenerators; /* init to 0 */ + + /* Variables for storing DTSTART, DTEND and DURATION */ + DateTime m_StartDate; + DateTime m_StopDate; + Julian_Duration * m_Duration; /* init to NULL */ + + /* cache validity */ + t_bool m_bParseValid; + + /*----------------------------- + ** METHODS + **---------------------------*/ + + /* initializes data */ + void init(); + + /** + * Helper method. Breaks recurrence rule strings into parameters + * and fills parameters vector with parameters. + * @param strLine recurrence rule string + * @param parameters vector to fill in with recurrence parameters + * + */ + void parsePropertyLine(UnicodeString & strLine, JulianPtrArray * parameters); + + /** + * Parses Recurrence rule string, populates data members, generators' + * parameters. Returns TRUE if recurrence parse went OK, FALSE + * if there was a failure. A failure sets m_bParseValid to FALSE. + * @param s recurrence rule string + * + * @return TRUE if rule is valid, FALSE otherwise + */ + t_bool parse(UnicodeString & s); + + /** + * Cleanup method takes vector of dates and make sure output number + * in less than length and start value is included. + * If bAddStartDate = TRUE, always add the start date to the out + * vector, otherwise don't add the start date to the out vector. + * @param vDatesIn input vector of dates + * @param length number of dates to be produced + * @param out output vector of dates + * @param bAddStartDate TRUE = adds first date to out vector + * + */ + void cleanup(JulianPtrArray * vDatesIn, t_int32 length, + JulianPtrArray * out, t_bool bAddStartDate); + + /** + * Sets interval to i, depending on m_iType. For example, + * if m_iType is set to JulianUtility::RT_YEARLY and i is 2, + * then the interval is every 2 years. + * @param i value of interval w/respect to m_iType + */ + void internalSetInterval(t_int32 i); + + + /** + * Used for resetting a date value that is floating somewhere in an + * interval, to the beginning of that interval. Depends upon the + * initial date, the recurrence interval type, the week start date, and + * the state of other active generators. + * + * Example: type = MONTHLY, s = Jul 15, 1997 10:15 PM PDT + * resets to Jul 1, 1997 10:15 PM PDT + * if the BYHOUR and BYMINUTE tags are active it + * will further be clocked back to + * Jul 1, 1997 12:00 AM PDT + * @param t date value to reset + * @param type current interval type + * @param wkSt week start value + * + */ + void reset(DateTime & t, t_int32 type, t_int32 wkSt); + + /** + * Removes dates in vDates that do not follow BYSETPOS rule. + * Usually, this involves deleting almost every date except 1 + * from vDates. + * @param vDates vector of dates. + * + */ + void handleSetPos(JulianPtrArray * vDates); + + /*----------------------------- + ** STATIC METHODS + **---------------------------*/ + + /** + * Tokenizes string with delimeters and puts tokens in vectorToFillIn + * @param s string to tokenize + * @param strDelim string delimeters + * @param vectorToFillIn output vector of tokens to fill in + * + */ + static void parseDelimited(UnicodeString & s, UnicodeString & strDelim, + JulianPtrArray * vectorToFillIn); + + /** + * Verifies that each element in v is within the bounds of + * [lowerBound,upperBound) (inclusive). If bZero is TRUE, then + * 0 is NOT a valid value, otherwise 0 is a valid value. If + * there is an error, log the error message and set bParseError + * to TRUE. Each valid element is added to the output list. + * The return size of the list is retSize + * @param v vector of string element + * @param lowerBound lowerbound of valid range + * @param upperBound upperbound of valid range + * @param error log error message + * @param retSize output size of parameter list + * @param bParseError output parse error boolean + * @param bZero TRUE is 0 OK, FALSE if 0 not OK + * + * @return ptr to t_int32 (list of gntr parameter elements) + */ + static t_int32 * verifyIntList(JulianPtrArray * v, t_int32 lowerBound, + t_int32 upperBound, UnicodeString & error, t_int32 & retSize, + t_bool & bParseError, t_bool bZero = FALSE); + + /** + * Verifies that each element in v is a valid day element. + * A day element is of form (-5MO) where the last two letters + * must be a recurrence day string with a optional modifier in front. + * Depending of the type variable the modifier can be + * from -53 to 53 for type=RT_YEARLY and -5 to 5 for type=RT_MONTHLY. + * Each valid element is added to the output RRDay list. + * The return size of the list is retSize. + * @param v vector of string elements + * @param type interval type + * @param retSize output size of RRDay list + * @param bParseError output parse error boolean + * + * @return ptr to RRDay * (list of RRDay objects) + */ + static RRDay * createByDayList(JulianPtrArray * v, t_int32 type, + t_int32 & retSize, t_bool & bParseError); + + /** + * Helper method gets the day and modifier from the string in. + * @param in string to get day, modifier from + * @param day output Calendar::EDaysOfWeek + * @param modifier output day modifier + * @param bParseError output parse error boolean + * + */ + static void createByDayListHelper(UnicodeString & in, t_int32 & day, + t_int32 & modifier, t_bool & bParseError); + + /** + * Cleanup vector of UnicodeString objects. Delete each UnicodeString + * in vector. + * @param strings vector of elements to delete from + */ + static void deleteUnicodeStringVector(JulianPtrArray * strings); +public: + + /** + * Cleanup vector of DateTime objects. Delete each DateTime in vector. + * @param strings vector of elements to delete from + */ + static void deleteDateTimeVector(JulianPtrArray * datetimes); + + /** + * Cleanup vector of Recurrence objects. Delete each Recurrence + * in vector + * @param strings vector of elements to delete from + */ + static void deleteRecurrenceVector(JulianPtrArray * recurrences); +private: + + /** + * Cleanup vector of vector of DateTime objects. Delete each + * DateTime in each vector in vector + * @param strings vector of elements to delete from + */ + static void deleteDateTimeVectorVector(JulianPtrArray * vDatetimes); + + /** + * Cleanup vector of ICalParameter objects. Delete each ICalParameter + * from vector. + * @param strings vector of elements to delete from + */ + static void deleteICalParameterVector(JulianPtrArray * parameters); + +#if 0 + static void copyDateTimesInto(JulianPtrArray * from, DateTime * to); +#endif + + /** + * Converts frequency string (i.e. YEARLY, WEEKLY, DAILY, etc.) + * to Recurrence type constant. + * @param s input iCal frequency string + * @param bParseError output parse error boolean + * + * @return output recurrence type + */ + static t_int32 stringToType(UnicodeString & s, t_bool & bParseError); + + /** + * Gets the length of the Generator Order Array given an index + * to the array + * @param genOrderIndex index in to generator order array + * + * @return length of m_GntrVctr[genOrderIndex] + */ + static t_int32 getGenOrderIndexLength(t_int32 genOrderIndex); + + /** + * Concatentates a vector of vector of dates into a vector of dates. + * @param vvIn input vector of vector of dates + * @param vOut output vector of dates with vvIn's dates added in + * + */ + static void concat(JulianPtrArray * vvIn, JulianPtrArray * vOut); + + /** + * Replaces the contents of vOut with the contents of vvIn + * @param vvIn input vector of vector of dates + * @param vOut output vector of dates with vvIn's dates replacing old dates + * + * @return static void + */ + static void replace(JulianPtrArray * vvIn, JulianPtrArray * vOut); + + /** + * Removes dates in vDatesOut that are not in vDatesIn. + * @param vDatesOut output vector of dates that are also in vDatesIn + * @param vDatesIn input vector of dates + * + */ + static void intersectOutList(JulianPtrArray * vDatesOut, JulianPtrArray * vDatesIn); + + + /** + * Subtract or intersects date lists. If subtract is TRUE, then + * subtract lists vvDates[1..n] from vvDates[0]. If intersects mode + * intersect lists vvDates[0...n]. Resulting dates vector goes into + * out. + * + * @param vvDates vector of vector of dates + * @param subtract subtract = TRUE or intersect = FALSE mode + * @param out output resulting dates vector + * + */ + static void intersectDateList(JulianPtrArray * vvDates, t_bool subtract, + JulianPtrArray * out); + + /** + * Checks whether datetimes vector contains date. To contain date + * means containing a date with the same year, month, day, hour, minute and second. + * It does not have to have the same millesecond value. + * @param datetimes vector of dates to check for date + * @param date target date to look for + * + * @return TRUE if date is in datetimes, FALSE otherwise. + */ + static t_bool contains(JulianPtrArray * datetimes, DateTime * date); + + /** + * Eliminates duplicate datetime object from datetimes + * @param datetimes vector to remove duplicates from + * + */ + static void eliminateDuplicates(JulianPtrArray * datetimes); + +#if JULIAN_DEBUGGING_RECURRENCE + /** + * DEBUGGING method to print out datetime elements in a vector + * @param x datetime vector + * @param name debug name of vector + * + */ + static void TRACE_DATETIMEVECTOR(JulianPtrArray * x, char * name); + + /** + * DEBUGGING method to print out elements in a vector of vector of datetimes + * @param x vector of vector of datetimes + * @param name debug name of vector + * + */ + static void TRACE_DATETIMEVECTORVECTOR(JulianPtrArray * x, char * name); +#endif + +}; +#endif /* __RECURRENCE_H_ */ + + diff --git a/calendar/modules/core/ical/inc/recid.h b/calendar/modules/core/ical/inc/recid.h new file mode 100644 index 00000000000..98eefc9ab38 --- /dev/null +++ b/calendar/modules/core/ical/inc/recid.h @@ -0,0 +1,242 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +/* + * recid.h + * John Sun + * 3/20/98 5:08:46 PM + */ + +#ifndef __RECURRENCEID_H_ +#define __RECURRENCEID_H_ + +#include +#include "datetime.h" +#include "prprty.h" +#include "jlog.h" + +/** + * JulianRecurrenceID implements the RecurrenceID property. The RecurrenceID + * must have a DateTime value. It can optionally have a RANGE value set to + * THISANDPRIOR or THISANDFUTURE. A RecurrenceID without a RANGE has its + * range value set to NONE. + * The JulianRecurrenceID must implement the ICalProperty interface. + * + * @see ICalProperty + */ +class JulianRecurrenceID : public ICalProperty +{ +public: + /** an enumeration of the RANGE parameter */ + enum RANGE{RANGE_NONE = 0, RANGE_THISANDPRIOR = 1, RANGE_THISANDFUTURE = 2}; +private: + + /*----------------------------- + ** MEMBERS + **---------------------------*/ + + /** range parameter value */ + JulianRecurrenceID::RANGE m_Range; + + /** datetime value */ + DateTime m_DateTime; + + /** log to write errors to */ + JLog * m_Log; + + /*----------------------------- + ** PRIVATE METHODS + **---------------------------*/ + + /** + * Sets parameter with name paramName with value paramVal. + * @param paramName parameter name to set + * @param paramVal new value of parameter + * + */ + void setParam(UnicodeString & paramName, UnicodeString & paramVal); + +#if 0 + /* hide constructor from clients */ + JulianRecurrenceID(); +#endif + + /** + * Copy constructor. + * @param that JulianRecurrenceID to copy + */ + JulianRecurrenceID(JulianRecurrenceID & that); + +public: + + /*----------------------------- + ** CONSTRUCTORS and DESTRUCTORS + **---------------------------*/ + + /** + * Constructor. Create a RecurrenceID with log set to initLog + * @param initLog log file to write errors to + */ + JulianRecurrenceID(JLog * initLog = 0); + + /** + * Constructor. Create a RecurrenceID with log set to initLog + * @param datetime initial DateTime value + * @param initLog log file to write errors to + * @param range initial RANGE value + */ + JulianRecurrenceID(DateTime datetime, JLog * initLog, RANGE range = RANGE_NONE); + + /** + * Destructor + */ + ~JulianRecurrenceID(); + + /*----------------------------- + ** ACCESSORS (GET AND SET) + **---------------------------*/ + + /** + * Returns RANGE value. + * + * @return current RANGE value + */ + JulianRecurrenceID::RANGE getRange() const { return m_Range; } + + /** + * Sets RANGE value + * @param range new range value + * + */ + void setRange(JulianRecurrenceID::RANGE range) { m_Range = range; } + + /** + * Sets DateTime value. + * @param d new DateTime value + * + */ + void setDateTime(DateTime d) { m_DateTime = d; } + + /** + * Returns DateTime value + * + * @return current DateTime value + */ + DateTime getDateTime() { return m_DateTime; } + + /*---------- To satisfy ICalProperty interface ----------*/ + /** + * Sets parameters. + * @param parameters vector of parameters to set + * + */ + virtual void setParameters(JulianPtrArray * parameters); + + /** + * Return value of property. Never use. Use getDateTime(). + * + * @return value of property + */ + virtual void * getValue() const; + + /** + * Sets value of property. Never use. Use setDateTime(). + * @param value new value of property + * + */ + virtual void setValue(void * value); + + /** + * Returns a clone of this property. + * @param initLog the log file for clone to write to + * + * @return clone of this ICalProperty object + */ + virtual ICalProperty * clone(JLog * initLog); + + /** + * Checks whether this property is valid or not. DateTime value + * must be valid in order to be TRUE. + * + * @return TRUE if property is valid, FALSE otherwise + */ + virtual t_bool isValid(); + + /** + * Return property to human-readable string. + * @param dateFmt formatting string + * @param out output human-readable string + * + * @return output human-readable string (out) + */ + virtual UnicodeString & toString(UnicodeString & strFmt, UnicodeString & out); + + /** + * Return property to human-readable string. + * @param out output human-readable string + * + * @return output human-readable string (out) + */ + virtual UnicodeString & toString(UnicodeString & out); + + /** + * Return property to iCal property string. + * @param out output iCal string + * + * @return output iCal string (out) + */ + virtual UnicodeString & toICALString(UnicodeString & out); + + /** + * Return property to iCal property string. Inserts sProp to + * front of output string. sProp should be the property name of this + * property. + * @param sProp property name to append to insert at front of out + * @param out output iCal string with sProp in front + * + * @return output iCal string with sProp in front (out) + */ + virtual UnicodeString & toICALString(UnicodeString & sProp, UnicodeString & out); + /*----------End of ICalProperty interface----------*/ + + /*----------------------------- + ** STATIC METHODS + **---------------------------*/ + + /** + * Converts string to RANGE enumeration. Returns NONE if error. + * @param sRange range string + * + * @return RANGE enumeration value of sRange + */ + static JulianRecurrenceID::RANGE stringToRange(UnicodeString & sRange); + + /** + * Converts RANGE to string. Returns "" for NONE. + * @param range RANGE value + * @param out output range string + * + * @return output range string + */ + static UnicodeString & rangeToString(JulianRecurrenceID::RANGE range, UnicodeString & out); + +}; + +#endif /* __RECURRENCEID_H_ */ + + diff --git a/calendar/modules/core/ical/inc/rrday.h b/calendar/modules/core/ical/inc/rrday.h new file mode 100644 index 00000000000..63cb34862ae --- /dev/null +++ b/calendar/modules/core/ical/inc/rrday.h @@ -0,0 +1,94 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +/* + * rrday.h + * John Sun + * 2/4/98 7:54:41 PM + */ + +#ifndef __RRDAY_H_ +#define __RRDAY_H_ + +#include +#include + +/** + * RRDay encapsulates a day for recurrence handling + * fields[0] is the value of the day (i.e Calendar::SUNDAY, ... + * Calendar::SATURDAY). fields[1] is the number of the day. + * Thus if this is the 1st Sunday, then fields[1] = 1; + * If this is the last Sunday, then fields[1] = -1; + */ +class RRDay +{ +public: + /** the fields */ + t_int32 fields[2]; + + /** Default constructor */ + RRDay(); + + /** Destructor */ + ~RRDay() {} + + + /** + * Constructor. Sets fields to aDay, aModifier + * @param aDay day of week value + * @param aModifier modifier + */ + RRDay(t_int32 aDay, t_int32 aModifier); + + + /** + * Return index into fields. + * @param index index of field to get + * + * @return value of fields[index] + */ + t_int32 operator[](t_int32 index) const; + + + /** + * Assignment operator. + * @param that RRDay to assign to + */ + void operator=(RRDay & that); + + + /** + * Equality operator. + * @param that RRDay to compare to + * + * @return TRUE if equal, FALSE otherwise. + */ + t_bool operator==(RRDay & that); + + /** + * Inequality operator. + * @param that RRDay to compare to + * + * @return TRUE if NOT equal, FALSE otherwise. + */ + t_bool operator!=(RRDay & that); + +}; + +#endif /* __RRDAY_H_ */ + diff --git a/calendar/modules/core/ical/inc/sdprprty.h b/calendar/modules/core/ical/inc/sdprprty.h new file mode 100644 index 00000000000..7d550145742 --- /dev/null +++ b/calendar/modules/core/ical/inc/sdprprty.h @@ -0,0 +1,197 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +/* + * sdprprty.h + * John Sun + * 3/2/98 9:37:03 AM + */ + +#include "prprty.h" +#include "icalprm.h" +#include + +#ifndef __STANDARDPROPERTY_H_ +#define __STANDARDPROPERTY_H_ + +/** + * StandardProperty is an abstract class that encapsulates the similar state of the + * BooleanProperty, DateTimeProperty, DurationProperty, IntegerProperty, + * PeriodProperty, and StringProperty classes. + * This mainly includes holding the ICAL parameters in a JulianPtrArray. + * It also defines a few methods to set, get, print parameters. + */ +class StandardProperty: public ICalProperty +{ +protected: + /** the parameters list of the property */ + JulianPtrArray * m_vParameters; + +#if 0 + /** ptr to log. Don't delete it */ + JLog * m_Log; +#endif + + /** + * Add a parameter to the parameter list + * @param parameter parameter to add + */ + void addParameter(ICalParameter * parameter); + + /** + * Constructor. Hidden from clients. + */ + StandardProperty(); + + /** + * Constructor. Makes copy of parameters. + * @param parameters parameter array to copy + */ + StandardProperty(JulianPtrArray * parameters); +public: + + /** + * Virtual destructor deletes parameters. + */ + virtual ~StandardProperty(); + + /*---------------------------------------------------------------------*/ + /*-- ICALPROPERTY interface --*/ + + /** + * Pure virtual method. Return the value of the property + * @return void * ptr to value of the property + */ + virtual void * getValue() const { PR_ASSERT(FALSE); return 0;} + + /** + * Pure virtual method. Set the value of the property + * @param value the value to set property to + */ + virtual void setValue(void * value) { PR_ASSERT(FALSE); if (value != 0) {} ; } + + /** + * Pure virtual method. Returns a clone of this property. + * Clients are responsible for deleting the returned object. + * + * @return a clone of this property. + */ + virtual ICalProperty * clone(JLog * initLog) { PR_ASSERT(FALSE); if (initLog) {} return 0; } + + /** + * Pure virtual method. Return TRUE if property is valid, FALSE otherwise + * + * @return TRUE if is valid, FALSE otherwise + */ + virtual t_bool isValid() { PR_ASSERT(FALSE); return FALSE; } + + /** + * Pure virtual method. Return a string in human-readable form of the property. + * @param out contains output human-readable string + * + * @return the property in its human-readable string format + */ + virtual UnicodeString & toString(UnicodeString & dateFmt, + UnicodeString & out) + { PR_ASSERT(FALSE); if (dateFmt.size() > 0) {} ; return out; } + + /** + * Pure virtual method. Return a string in human-readable form of the property. + * @param dateFmt format string options + * @param out contains output human-readable string + * + * @return the property in its human-readable string format + */ + virtual UnicodeString & toString(UnicodeString & out) { PR_ASSERT(FALSE); return out; } + + /*-- End of ICALPROPERTY interface --*/ + /*---------------------------------------------------------------------*/ + + /** + * Pure virtual method. Return the property's string in the ICAL format. + * @param out contains output ICAL string + * + * @return the property in its ICAL string format + */ + virtual UnicodeString & toExportString(UnicodeString & out) { PR_ASSERT(FALSE); return out; } + + /** + * Given a parameter name, return the parameter value in paramVal. + * Return a status of 1 if paramName not found in parameters array. + * @param paramName input parameter name + * @param paramVal output parameter value if found + * @param status ZERO_ERROR if OK, 1 is empty parameters, 2 is not found + * + * @return output parameter value (paramVal) + */ + UnicodeString & getParameterValue(UnicodeString & paramName, /* IN */ + UnicodeString & paramVal, ErrorCode & status); /* OUT, OUT */ + + /*void setParameter(UnicodeString & paramName, UnicodeString & paramValue)*/ + + /** + * Parse a line and populate data. + * @param in line to parse. + */ + void parse(UnicodeString & in); + + /** + * Copies contents of parameters into this property's parameters + * array. + * @param parameters parameters to copy + */ + void setParameters(JulianPtrArray * parameters); + + /* + virtual void setParameter(UnicodeString & paramName, UnicodeString & paramValue) + { + PR_ASSERT(FALSE); if (paramName.size() > 0 && paramValue.size() > 0) {} + } + */ + + /** + * Returns the property's ICAL format strings, + * to output string of the form + * :value or ;param1;param2;param3(etc.):value + * ONLY: DateTimeProperty overrides this + * (This is too handle NOT printing VALUE and TZID parameters) + * + * @param out output ICAL string + * + * @return output ICAL string (out) + */ + virtual UnicodeString & toICALString(UnicodeString & out); + + /** + * Returns the property's ICAL format strings, inserting + * sProp (property name) to output string of the form + * sProp:value or sProp;param1;param2;param3(etc.):value + * ONLY: DateTimeProperty overrides this + * (This is too handle NOT printing VALUE and TZID parameters) + * + * @param sProp property name of property + * @param out output ICAL string + * + * @return output ICAL string (out) + */ + virtual UnicodeString & toICALString(UnicodeString & sProp, + UnicodeString & out); +}; + +#endif /* __STANDARDPROPERTY_H_ */ + diff --git a/calendar/modules/core/ical/inc/sprprty.h b/calendar/modules/core/ical/inc/sprprty.h new file mode 100644 index 00000000000..1f3ccc84dc1 --- /dev/null +++ b/calendar/modules/core/ical/inc/sprprty.h @@ -0,0 +1,120 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +/* + * sprprty.h + * John Sun + * 2/10/98 4:53:11 PM + */ + +#include +#include "sdprprty.h" + +#ifndef __STRINGPROPERTY_H_ +#define __STRINGPROPERTY_H_ + +/** + * StringProperty is a subclass of StandardProperty. It implements the ICalProperty + * interface for ICAL properties with TYPE=TEXT. + */ +class StringProperty: public StandardProperty +{ +private: + /** the String value of the property */ + UnicodeString m_string; + + /** + * Default constructor + */ + StringProperty(); + + /** + * Copy constructor + * @param that property to copy + */ + StringProperty(const StringProperty & that); +public: + + /** + * Constructor that sets value of property to contents of value + * and makes a copy of the contents of parameters ptr. + * @param value value of property + * @param parameters parameters of property + */ + StringProperty(UnicodeString value, JulianPtrArray * parameters); + + /** + * Destructor + */ + ~StringProperty(); + + /** + * Return the value of the property + * @return void * ptr to value of the property + */ + virtual void * getValue() const; + + /** + * Set the value of the property + * @param value the value to set property to + */ + virtual void setValue(void * value); + + /** + * Returns a clone of this property. Clients are responsible for deleting + * the returned object. + * + * @return a clone of this property. + */ + virtual ICalProperty * clone(JLog * initLog); + + /** + * Return TRUE if property is valid, FALSE otherwise + * + * @return TRUE if is valid, FALSE otherwise + */ + virtual t_bool isValid(); + + /** + * Return a string in human-readable form of the property. + * @param out contains output human-readable string + * + * @return the property in its human-readable string format + */ + virtual UnicodeString & toString(UnicodeString & out); + + /** + * Return a string in human-readable form of the property. + * @param dateFmt format string options + * @param out contains output human-readable string + * + * @return the property in its human-readable string format + */ + virtual UnicodeString & toString(UnicodeString & dateFmt, UnicodeString & out); + + /** + * Return the property's string in the ICAL format. + * @param out contains output ICAL string + * + * @return the property in its ICAL string format + */ + virtual UnicodeString & toExportString(UnicodeString & out); +}; + +#endif /* __STRINGPROPERTY_H_ */ + diff --git a/calendar/modules/core/ical/inc/stdafx.h b/calendar/modules/core/ical/inc/stdafx.h new file mode 100644 index 00000000000..50f3274bec6 --- /dev/null +++ b/calendar/modules/core/ical/inc/stdafx.h @@ -0,0 +1,23 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +/* This is a dummy file so that we can compile our windows +** projects with precompiled headers... +** +** It must be here, but you can just ignore it. +*/ diff --git a/calendar/modules/core/ical/inc/tmbevent.h b/calendar/modules/core/ical/inc/tmbevent.h new file mode 100644 index 00000000000..a4e24870984 --- /dev/null +++ b/calendar/modules/core/ical/inc/tmbevent.h @@ -0,0 +1,955 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +/* + * tmbevent.h + * John Sun + * 2/6/98 2:59:24 AM + * + * modified: 8/31/98 sman - added curl support + */ + +#ifndef __TIMEBASEDEVENT_H_ +#define __TIMEBASEDEVENT_H_ + +#include "ptrarray.h" +#include "datetime.h" +#include "attendee.h" +#include "icalredr.h" +#include "prprty.h" +#include "duration.h" +#include "jlog.h" +#include "valarm.h" +#include "julnstr.h" +#include "nscalcoreicalexp.h" + +/** + * TimeBasedEvent is the superclass of VEvent, VTodo, and VJournal. + * It encapsulates the similar state between the 3 classes. This + * includes recurrence handling, Alarm handling, as well as containing + * all properties that exist in all three properties. + * NOTE: No ownership taken anymore. (always pass by value) + */ +class NS_CAL_CORE_ICAL TimeBasedEvent : public ICalComponent +{ +protected: +#if 0 + + /** + * Default Constructor. Hide from clients. + */ + TimeBasedEvent(); +#endif + + + /** + * Copy constructor. + * @param that TimeBasedEvent to copy. + */ + TimeBasedEvent(TimeBasedEvent & that); +public: + /*TimeBasedEvent(NSCalendar parent);*/ + + /** + * Returns the curl associated with this nsCalendar. The + * curl points to the calendar store where components in + * this nsCalendar are to be stored. It is required + * for an nsCalendar to have an associated curl if any + * of its components will be persisted in a calendar store. + * + * @return a JulianString containing the curl + */ + JulianString getCurl() const {return m_sCurl;} + + /** + * Set the default curl for this nsCalendar. + */ + void setCurl(const char* ps) {m_sCurl = ps;} + + /** + * Set the default curl for this nsCalendar. + */ + void setCurl(const JulianString& s) {m_sCurl = s;} + + /** + * Constructor. Create TimeBasedEvent with initial log file set to initLog. + * @param initLog initial log file pointer + */ + TimeBasedEvent(JLog * initLog = 0); + + /** + * Destructor. + */ + virtual ~TimeBasedEvent(); + + + /** + * Pure virtual method. Calculate difference from start, end time + * For VEvent, this would be DTEnd - DTStart. + * + * @return virtual Date + */ + virtual Date difference() { PR_ASSERT(FALSE); return 0; } + + /** + * set RSVP on all attendees set to TRUE + */ + /*void rsvpAll();*/ + + /** + * Set each attendee's status parameter to needs action (except owner) + */ + /*void needsAction();*/ + + /*UnicodeString getOrganizer();*/ + /*UnicodeString getOwner();*/ + + /*UnicodeString toString(UnicodeString strFmt);*/ + + /* -- Start of ICALComponent interface -- */ + + /** + * The parse method is the standard interface for ICalComponent + * subclasses to parse from an ICalReader object + * and from the ITIP method type (i.e. PUBLISH, REQUEST, CANCEL, etc.). + * The method type can be set to \"\" if there is no method to be loaded. + * Also accepts a vector of VTimeZone objects to apply to + * the DateTime properties of the component. + * 4-2-98: Added bIgnoreBeginError. If desired to start parsing in Component level, + * it is useful to ignore first "BEGIN:". Setting bIgnoreBeginError to TRUE allows for + * this. + * + * @param brFile ICalReader to load from + * @param sType name of component (i.e. VEVENT, VTODO, VTIMEZONE) + * @param parseStatus return parse error status string (normally return "OK") + * @param vTimeZones vector of VTimeZones to apply to datetimes + * @param bIgnoreBeginError TRUE = ignore first "BEGIN:VEVENT", FALSE otherwise + * @param encoding the encoding of the stream, default is 7bit. + * + * @return parse error status string (parseStatus) + */ + virtual UnicodeString & parse(ICalReader * brFile, UnicodeString & sMethod, + UnicodeString & parseStatus, JulianPtrArray * vTimeZones = 0, + t_bool bIgnoreBeginError = FALSE, JulianUtility::MimeEncoding encoding = + JulianUtility::MimeEncoding_7bit) + { + PR_ASSERT(FALSE); + if (brFile != NULL && vTimeZones != NULL && sMethod.size() > 0 + && parseStatus.size() > 0 && bIgnoreBeginError && encoding > 0) + { + } + return parseStatus; + } + + /** + * Returns a clone of this object + * @param initLog log file to write errors to + * + * @return clone of this object + */ + virtual ICalComponent * clone(JLog * initLog) { PR_ASSERT(FALSE); if (initLog) {} return 0; } + + /** + * Return TRUE if component is valid, FALSE otherwise + * + * @return TRUE if is valid, FALSE otherwise + */ + virtual t_bool isValid(); + + /** + * Print all contents of ICalComponent to iCal export format. + * + * @return string containing iCal export format of ICalComponent + */ + UnicodeString toICALString(); + + /*UnicodeString toICALString(UnicodeString sMethod);*/ + + /** + * Print all contents of ICalComponent to iCal export format, depending + * on attendee name, attendee delegated-to, and where to include recurrence-id or not + * + * @param method method name (REQUEST,PUBLISH, etc.) + * @param name attendee name to filter with + * @param isRecurring TRUE = no recurrenceid, FALSE = include recurrenceid + * + * @return string containing iCal export format of ICalComponent + */ + UnicodeString toICALString(UnicodeString sMethod, + UnicodeString sName, t_bool isRecurring = FALSE); + + /** + * Depending on character passed in, returns a string that represents + * the ICAL export string of that property that the character represents, if + * other paramaters not null, then print out information is filtered in several ways + * Attendee print out can be filtered so that only attendee with certain name is printed + * also, can print out the relevant attendees in a delegation message + * (ie. owner, delegate-to, delegate-from) + * + * @param c char of what property to print + * @param sFilterAttendee name of attendee to print + * @param bDelegateRequest TRUE if a delegate request, FALSE if not + * @return ICAL export format of that property + */ + virtual UnicodeString formatChar(t_int32 c, UnicodeString sFilterAttendee, + t_bool delegateRequest = FALSE); + + /** + * convert a character to the content of a property in string + * human-readable format + * @param c a character represents a property + * @param dateFmt for formatting datetimes + * + * @return property in human-readable string + */ + virtual UnicodeString toStringChar(t_int32 c, UnicodeString & dateFmt); + + /** + * Returns the ICAL_COMPONENT enumeration value of this ICalComponent. + * Each ICalComponent subclass must return a unique ICAL_COMPONENT value. + * + * @return ICAL_COMPONENT value of this component + */ + virtual ICAL_COMPONENT GetType() const { PR_ASSERT(FALSE); return ICAL_COMPONENT_VEVENT; } + + /* OVERRIDES ICalComponent::MatchUID_seqNO */ + /** + * check if this event matches the given UID and sequence number + * @return TRUE if this event matches the given UID and sequence number, FALSE otherwise + */ + virtual t_bool MatchUID_seqNO(UnicodeString uid, t_int32 iSeqNo); + + /* -- Start of ICALComponent interface -- */ + + /** + * Pure virtual method used as wrapper to ICalComponent::format method. + * @param strFmt iCal format string + * @param sFilterAttendee attendee to filter + * @param delegateRequest delegate request = TRUE, FALSE otherwise + * + * @return output iCal formatted export string + */ + virtual UnicodeString formatHelper(UnicodeString & strFmt, + UnicodeString sFilterAttendee, t_bool delegateRequest = FALSE) + { + PR_ASSERT(FALSE); + if (strFmt.size() == 0 && sFilterAttendee.size() == 0 && delegateRequest) {} + return ""; + } + + /** + * Parse the TimeBasedEvent from a ICalReader object, given the component name in sType. + * Takes in a method name since, this affects whether event is valid or not. + * Also takes in vector of timezones to apply to datetimes with TZID values. + * The bIgnoreBeginError flag is used to ignore the first BEGIN:VEVENT(VTODO,VJOURNAL). + * This is useful when this method is called somewhere besides the NSCalendar::parse(). + * For example, when receiving data a from CAPI, it returns events, not calendars. + * So to parse event, the first BEGIN:VEVENT should be ignored. + * If then parse terminates correctly with an END:VEVENT(VTODO, VJOURNAL) then parseStatus + * is set to OK and returned. However is an incorrect termination of parse occurs, + * then parseStatus returns the cause of the incorrect termination. An incorrect + * termination of parse can occur if the parse reaches an "END:VCALENDAR" before and + * "END:VEVENT" for example. In this case, parseStatus would return "END:VCALENDAR". + * Other incorrect termination causes are a "BEGIN:VCALENDAR", or another "BEGIN:VEVENT" + * (TODO: finish incorrect termination handling). + * + * @param sType component name (i.e. VEVENT, VTODO, VJOURNAL) + * @param brFile ICalReader object to parse from + * @param sMethod calendar method name (PUBLISH, REQUEST, etc.) + * @param parseStatus return OK if no error, otherwise an error + * @param vTimeZones vector of timezones to apply to datetimes + * @param bIgnoreBeginError if parsing just a vevent (not from an calendar, set to TRUE) + * @param encoding the encoding of the stream, default is 7bit. + * + * @return parseStatus (OK if no error, otherwise an error) + */ + UnicodeString & parseType(UnicodeString & sType, ICalReader * brFile, + UnicodeString & sMethod, UnicodeString & parseStatus, JulianPtrArray * vTimeZones, + t_bool bIgnoreBeginError = FALSE, + JulianUtility::MimeEncoding encoding = JulianUtility::MimeEncoding_7bit); + + /** + * Prints properties of an CANCEL message, specifically + * + * @return a string with COMMENT, DTSTAMP, STATUS, STATUS=CANCELLED, SEQUENCE, UID properties + */ + virtual UnicodeString cancelMessage() { PR_ASSERT(FALSE); return ""; } + + /** + * Prints properties of an REQUEST message + * @return string with request message required properties + */ + virtual UnicodeString requestMessage() { PR_ASSERT(FALSE); return ""; } + + /** + * Prints properties of an REQUEST message except Recur-id + * @return string with request message required properties + */ + virtual UnicodeString requestRecurMessage() { PR_ASSERT(FALSE); return ""; } + + /** + * Prints properties of an COUNTER message + * @return string with counter message required properties + */ + virtual UnicodeString counterMessage() { PR_ASSERT(FALSE); return ""; } + + /** + * Prints properties of an DECLINECOUNTER message + * @return string with decline-counter message required properties + */ + virtual UnicodeString declineCounterMessage() { PR_ASSERT(FALSE); return ""; } + + /** + * Prints properties of an ADD message + * @return string with add message required properties + */ + virtual UnicodeString addMessage() { PR_ASSERT(FALSE); return ""; } + + /** + * Prints properties of an REFRESH message + * @param sAttendeeFilter name of requestor of refresh + * @return string with refresh message required properties + */ + virtual UnicodeString refreshMessage(UnicodeString sAttendeeFilter) + { + PR_ASSERT(FALSE); + if (sAttendeeFilter.size() > 0) {} return ""; + } + + /** + * Prints properties of an ALL PROPERTIES message (for debugging method) + * @return string with all properties + */ + virtual UnicodeString allMessage() { PR_ASSERT(FALSE); return ""; } + + /** + * Prints properties of an REPLY message + * @param sAttendeeFilter name of replier + * @return string with reply message required properties + */ + virtual UnicodeString replyMessage(UnicodeString sAttendeeFilter) + { + PR_ASSERT(FALSE); + if (sAttendeeFilter.size() > 0) {} return ""; + } + + /** + * Prints properties of an PUBLISH message + * @return string with publish message required properties + */ + virtual UnicodeString publishMessage() { PR_ASSERT(FALSE); return ""; } + + /** + * Prints properties of an PUBLISH message except recur-id + * @return string with publish message required properties + */ + virtual UnicodeString publishRecurMessage() { PR_ASSERT(FALSE); return ""; } + + /* -- delegate methods -- */ + /* + virtual UnicodeString delegateRequestMessage(UnicodeString sAttendeeFilter, + UnicodeString sDelegateTo, t_bool bRecur = FALSE); + */ +/* + { + PR_ASSERT(FALSE); + if (sAttendeeFilter.size() > 0) {return ""; } + if (sDelegateTo.size() > 0 && t_bool) {return ""; } + return ""; + } + */ +/* + virtual UnicodeString delegateRequestRecurMessage(UnicodeString sAttendeeFilter, + UnicodeString sDelegateTo, t_bool bRecur) + { + PR_ASSERT(FALSE); + if (sAttendeeFilter.size() > 0) {return ""; } + return ""; + } + */ + /* + virtual UnicodeString delegateReplyMessage(UnicodeString sAttendeeFilter, + UnicodeString sDelegateTo, t_bool bRecur = FALSE); + */ + /* + { + PR_ASSERT(FALSE); + if (sAttendeeFilter.size() > 0) {return ""; } + if (sDelegateTo.size() > 0 && t_bool) {return ""; } + return ""; + } + */ + /* + virtual UnicodeString delegateReplyRecurMessage(UnicodeString sAttendeeFilter, + UnicodeString sDelegateTo, t_bool bRecur) + { + PR_ASSERT(FALSE); + if (sAttendeeFilter.size() > 0) {return ""; } + return ""; + } + */ + +#if 0 + static void setDateTimeValue(ICalProperty ** dateTimePropertyPtr, + DateTime inVal, JulianPtrArray * inParameters); + static void getDateTimeValue(ICalProperty ** dateTimePropertyPtr, DateTime & outVal); +#endif + + /* -- Getters and Setters -- */ + + /** + * Return TRUE if event is an anniversary event, FALSE otherwise. + * An anniversary event is an event that does not represent a + * scheduled amount of time, but more of a daily reminder. + * During parsing, this is set when the VALUE=DATE is parsed + * on the DTSTART property. An anniversary event can span multiple + * days. See spec for better definition. + * + * @return TRUE if anniversary event, FALSE otherwise + */ + t_bool isAllDayEvent() { return m_bAllDayEvent; } + void setAllDayEvent(t_bool b) { m_bAllDayEvent = b; } + + /* --- Getters and Setters ---*/ + + /* LAST-MODIFIED */ + DateTime getLastModified() const; + void setLastModified(DateTime s, JulianPtrArray * parameters = 0); + ICalProperty * getLastModifiedProperty() const { return m_LastModified; } + + /* CREATED */ + DateTime getCreated() const; + void setCreated(DateTime s, JulianPtrArray * parameters = 0); + ICalProperty * getCreatedProperty() const { return m_Created; } + + /* DTSTAMP */ + DateTime getDTStamp() const; + void setDTStamp(DateTime s, JulianPtrArray * parameters = 0); + ICalProperty * getDTStampProperty() const { return m_DTStamp; } + + /* DTSTART */ + DateTime getDTStart() const; + void setDTStart(DateTime s, JulianPtrArray * parameters = 0); + ICalProperty * getDTStartProperty() const { return m_DTStart; } + + /* DESCRIPTION */ + UnicodeString getDescription() const; + void setDescription(UnicodeString s, JulianPtrArray * parameters = 0); + ICalProperty * getDescriptionProperty() const { return m_Description; } + + /* URL */ + UnicodeString getURL() const; + void setURL(UnicodeString s, JulianPtrArray * parameters = 0); + ICalProperty * getURLProperty() const { return m_URL; } + + /* SUMMARY */ + UnicodeString getSummary() const; + void setSummary(UnicodeString s, JulianPtrArray * parameters = 0); + ICalProperty * getSummaryProperty() const { return m_Summary; } + + /* CLASS */ + UnicodeString getClass() const; + void setClass(UnicodeString s, JulianPtrArray * parameters = 0); + ICalProperty * getClassProperty() const { return m_Class; } + + /* STATUS */ + UnicodeString getStatus() const; + void setStatus(UnicodeString s, JulianPtrArray * parameters = 0); + ICalProperty * getStatusProperty() const { return m_Status; } + + /* REQUESTSTATUS */ + /* UnicodeString getRequestStatus() const; + void setRequestStatus(UnicodeString s, JulianPtrArray * parameters = 0); + ICalProperty * getRequestStatusProperty() const { return m_RequestStatus; }*/ + void addRequestStatus(UnicodeString s, JulianPtrArray * parameters = 0); + void addRequestStatusProperty(ICalProperty * prop); + JulianPtrArray * getRequestStatus() const { return m_RequestStatusVctr; } + + /* UID */ + virtual UnicodeString getUID() const; + void setUID(UnicodeString s, JulianPtrArray * parameters = 0); + ICalProperty * getUIDProperty() const { return m_UID; } + + /* SEQUENCE */ + virtual t_int32 getSequence() const; + void setSequence(t_int32 i, JulianPtrArray * parameters = 0); + ICalProperty * getSequenceProperty() const { return m_Sequence; } + + /* COMMENT */ + void addComment(UnicodeString s, JulianPtrArray * parameters = 0); + void addCommentProperty(ICalProperty * prop); + JulianPtrArray * getComment() const { return m_CommentVctr; } + + /* remove all previous comments, then adds new comment s */ + void setNewComments(UnicodeString s); + + /* ATTACH */ + void addAttach(UnicodeString s, JulianPtrArray * parameters = 0); + void addAttachProperty(ICalProperty * prop); + JulianPtrArray * getAttach() const { return m_AttachVctr; } + + /* RELATED-TO (not a vector anymore, now just a property) */ + void addRelatedTo(UnicodeString s, JulianPtrArray * parameters = 0); + void addRelatedToProperty(ICalProperty * prop); + JulianPtrArray * getRelatedTo() const { return m_RelatedToVctr; } + + /* CONTACT */ + void addContact(UnicodeString s, JulianPtrArray * parameters = 0); + void addContactProperty(ICalProperty * prop); + JulianPtrArray * getContact() const { return m_ContactVctr; } + + /* RDATE */ + void addRDate(UnicodeString s, JulianPtrArray * parameters = 0); + void addRDateProperty(ICalProperty * prop); + JulianPtrArray * getRDates() const { return m_RDateVctr; } + + /* EXDATE */ + void addExDate(UnicodeString s, JulianPtrArray * parameters = 0); + void addExDateProperty(ICalProperty * prop); + JulianPtrArray * getExDates() const { return m_ExDateVctr; } + + /* CATEGORIES */ + void addCategories(UnicodeString s, JulianPtrArray * parameters = 0); + void addCategoriesProperty(ICalProperty * prop); + JulianPtrArray * getCategories() const { return m_CategoriesVctr; } + void addCategoriesPropertyVector(UnicodeString & propVal, JulianPtrArray * parameters); + + /* ORGANIZER */ + UnicodeString getOrganizer() const; + void setOrganizer(UnicodeString s, JulianPtrArray * parameters = 0); + ICalProperty * getOrganizerProperty() const { return m_Organizer; } + + /* RECURRENCEID */ + ICalProperty * getRecurrenceIDProperty() const { return m_RecurrenceID; } + void setRecurrenceID(DateTime d, JulianPtrArray * parameters = 0); + DateTime getRecurrenceID() const; + + /* XTOKENS: NOTE: a vector of strings, not a vector of ICalProperties */ + void addXTokens(UnicodeString s); + JulianPtrArray * getXTokens() const { return m_XTokensVctr; } + + /* EXRULE: NOTE: a vector of strings, not a vector of ICalProperties */ + void addExRuleString(UnicodeString s); + JulianPtrArray * getExRules() const { return m_ExRuleVctr; } + + /* RRULE: NOTE: a vector of strings, not a vector of ICalProperties */ + void addRRuleString(UnicodeString s); + JulianPtrArray * getRRules() const { return m_RRuleVctr; } + + /* ATTENDEE */ + void addAttendee(Attendee * a); + JulianPtrArray * getAttendees() const { return m_AttendeesVctr ; } + + /*---------------------------------------------------------------------*/ + + /* ALARMS */ + JulianPtrArray * getAlarms() const { return m_AlarmsVctr ; } + void addAlarm(VAlarm * a); + + /* ORIGSTART */ + void setOrigStart(DateTime d) { m_origDTStart = d; } + DateTime getOrigStart() { return m_origDTStart; } + + /* MYORIGSTART */ + void setMyOrigStart(DateTime d) { m_origMyDTStart = d; } + DateTime getMyOrigStart() { return m_origMyDTStart; } + + /* METHOD */ + void setMethod(UnicodeString & s); + UnicodeString & getMethod() { return m_sMethod; } + + /* BOUND */ + t_int32 getBound() const { return ms_iBound; } + void setBound(t_int32 i) { ms_iBound = i; } + + /** + * Set DTStamp to current date time. + */ + void stamp(); + + /** + * Return the Attendee in attendee vector with name equal + * to sAttendee. Return 0 if no attendee with that name. + * @param sAttendee name of attendee + * + * @return Attendee whose name is sAttendee, 0 if not found + */ + Attendee * getAttendee(UnicodeString sAttendee); + + /** + * Checks is this component is expandable. An expandable component + * is a component that has something in the RRULE or RDATE vector + * and does NOT have a RecurrenceID. + * + * @return TRUE if is expandable component, FALSE otherwise. + */ + t_bool isExpandableEvent() const; + + /** + * Helper method. Pure virtual method. Used by subclasses to + * populate recurrence-dependent data. For example, a recurring + * VEvent needs to have DTEnd calculated from recurring + * DTStart. VEvent will overwrite method set DTEnd correctly. + * Abstract difference() method is used to calculate ldiff. + * Need to pass vector of RDate periods in case end value must + * be adjusted in RDATE is a PERIOD value. + * @param start recurrence instance starting time + * @param ldiff abstract difference value + * @param vPer vector of RDate periods + */ + virtual void populateDatesHelper(DateTime start, Date ldiff, JulianPtrArray * vPer) + { + PR_ASSERT(FALSE); if(start.getTime() > ldiff && vPer) {} + } + + + /** + * takes the vector of rrule, rdate, exrule, and exdates, dtstart, + * and bound and returns a vector of generated recurrence events in vOut. + * Does this in two parts + * The first part generates a vector of DateTimes that represent + * the dates of the recurrence. + * The second part takes these dates and creates an event with them. + * @param vOut fill-in vector with generated recurrence events + * @param vTimeZones vector of timezones + */ + void createRecurrenceEvents(JulianPtrArray * vOut, + JulianPtrArray * vTimeZones); + + /* + void addDelegate(UnicodeString & sAttendeeFilter, + UnicodeString & sDelegateTo); + */ + + /** + * Sets Attendee with the name sAttendeeFilter to status. + * If the status is Delegated, then adds each element in delegatedTo + * to the delegatedTo vector of that attendee. + * If that attendee does not exist in the attendee list, then add + * a new Attendee to the attendee list with his/her PARTSTAT set to status. + * @param sAttendeeFilter attendee to set status on + * @param status status to set + * @param delegatedTo vector of delegatedTo names to set to + */ + void setAttendeeStatus(UnicodeString & sAttendeeFilter, Attendee::STATUS status, + JulianPtrArray * delegatedTo = 0); + void setAttendeeStatusInt(UnicodeString & sAttendeeFilter, t_int32 status, + JulianPtrArray * delegatedTo = 0); + + /** + * TODO: doesn't do smart overriding for now, does simple overwrite + * Updates this component with the data from the updatedComponent. + * This method must be overridden by subclasses. + * If updatedComponent is older that current compoenent, don't update current component + * How: + * make sure (UID, RecurID) pair are same. + * if sequence number of updatedComponent if greater that this.sequence || + * if sequence numbers are equal and update.DTSTAMP > this.DTSTAMP + * update properties + * else + * do nothing. + * Return TRUE if component was changed, FALSE otherwise + * + */ + t_bool updateComponent(ICalComponent * updatedComponent); + + /** + * Helper method called by updateComponent to actually replace + * the property data-members with updatedComponent's data-members. + * @param ICalComponent * updatedComponent + * + * @return virtual void + */ + virtual void updateComponentHelper(TimeBasedEvent * updatedComponent); + + /** + * Compare TimeBasedEvents by UID. Used by JulianPtrArray::QuickSort method. + * @param a first TimeBasedEvent + * @param b second TimeBasedEvent + * + * @return a.getUID().compareTo(b.getUID()) + */ + static int CompareTimeBasedEventsByUID(const void * a, const void * b); + + /** + * Compare TimeBasedEvents by DTSTART. Used by JulianPtrArray::QuickSort method. + * @param a first TimeBasedEvent + * @param b second TimeBasedEvent + * + * @return a.getDTSTART().compareTo(b.getDTSTART()) + */ + static int CompareTimeBasedEventsByDTStart(const void * a, const void * b); + + +protected: + + /** + * store the data, depending on property name, property value + * parameter names, parameter values, and the current line. + * subclasses should overwrite this method, but call this method + * to handle most properties. If this method returns FALSE, subclass + * then should handles specific properties of that class. + * + * @param strLine current line to process + * @param propName name of property + * @param propVal value of property + * @param parameters property's parameters + * @param vTimeZones vector of timezones + * @return TRUE if line was handled, FALSE otherwise + */ + virtual t_bool storeData(UnicodeString & strLine, + UnicodeString & propName, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones); +public: + typedef void (TimeBasedEvent::*SetOp) (UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones); + + /* Clients should NOT call below methods */ + void storeAttach(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones); + void storeAttendees(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones); + void storeCategories(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones); + void storeClass(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones); + void storeComment(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones); + void storeContact(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones); + void storeCreated(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones); + void storeDescription(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones); + void storeDTStart(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones); + void storeDTStamp(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones); + void storeExDate(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones); + void storeExRule(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones); + void storeLastModified(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones); + void storeOrganizer(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones); + void storeRDate(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones); + void storeRRule(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones); + void storeRecurrenceID(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones); + void storeRelatedTo(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones); + void storeRequestStatus(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones); + void storeSequence(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones); + void storeStatus(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones); + void storeSummary(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones); + void storeUID(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones); + void storeURL(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones); + + void ApplyStoreOp(void (TimeBasedEvent::*op) (UnicodeString & strLine, + UnicodeString & propVal, JulianPtrArray * parameters, JulianPtrArray * vTimeZones), + UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones) + { + (this->*op)(strLine, propVal, parameters, vTimeZones); + } +protected: + /** + * Sets default data. Currently does following: + * 1) Sets Summary to first 60 characters of Description if Summary is empty. + * 2) Sets sequence number to 0 if sequence number is less than 0. + * 3) Sets CLASS to PUBLIC if Class is empty or out of range. + */ + virtual void selfCheck(); + + /* + void checkRecurrence(); + virtual void checkRange(); + void setDefaultProps(UnicodeString sPropName); + */ + +private: + + /** + * Generates vector of DateTimes representing dates of + * recurrence. Does this given starting time, vector of rrule, + * rdate, exrule, exdate and bound. Also takes optional + * timezones vector to adjust rdate, exdate and rrule, exrule + * (TODO: make rrules, exrules use timezones) + * and a log file to log recurrence errors. + * Used by createRecurrenceEvents method. + * @param vOut output vector of dates of recurrence + * @param start starting time of recurrence + * @param vRRules vector of RRULES (UnicodeString) + * @param vExRules vector of EXRULES (UnicodeString) + * @param vRDatesProp vector of RDATES (ICalProperty) + * @param vExDatesProp vector of EXDATES (ICalProperty) + * @param iBound bound value + * @param vTimeZones vector of timezones + * @param log log file + */ + static void generateDates(JulianPtrArray * vOut, DateTime start, + JulianPtrArray * vRRules, JulianPtrArray * vExRules, + JulianPtrArray * vRDatesProp, JulianPtrArray * vExDatesProp, t_int32 iBound, + JulianPtrArray * vTimeZones = 0, JLog * log = 0); + + /** + * Takes in either RDate or ExDate ICalProperty vector, and fills in vOut with + * DateTime strings from vector. Also applies TimeZone information to + * strings when necessary. A flag to check if vector is RDate or ExDate + * is necessary because RDate can have Period, Date info, while ExDate cannot. + * For example, if RDate vector contains RDATE;TZID=America/New-York:19971110T070000, + * then bIsRDate must be TRUE (caller responsible for this), and vOut contains + * the string "19971110T120000Z" (note timezones is applied). + * Used by generateDates method. + * @param vOut output vector of DateTime strings + * @param vDateProp ICalProperty vector to split. + * @param bIsRDate whether vector if RDate or EXDate + * @param vTimeZones vector of timezones + */ + static void splitDates(JulianPtrArray * vOut, + JulianPtrArray * vDateProp, t_bool bIsRDate, + JulianPtrArray * vTimeZones); + + + /* + JulianPtrArray * getPeriodDatesHelper(JulianPtrArray * vDates); + JulianPtrArray * getPeriodDates(JulianPtrArray * vTimeZones); + */ + + /** + * Takes RDate vector and returns all strings of RDates that are + * of PERIOD value. For example if RDATE;VALUE=PERIOD:19971110T112233Z/PT1H, + * return the string "19971110T112233Z/PT1H". + * @param out output vector of strings of PERIOD RDates + */ + void getPeriodRDates(JulianPtrArray * out); + + + /** + * Takes vector of recurrences dates and generates recurrence events in vOut. + * Used by createRecurrenceEvents method. + * @param vOut output vector of recurrence events + * @param dates vector of recurrence dates + * @param origStart starting time of original compressed event + * @param vTimeZones vector of timezones + */ + void populateDates(JulianPtrArray * vOut, JulianPtrArray * dates, + DateTime origStart, JulianPtrArray * vTimeZones); + + /** + * Returns TRUE if this TimeBasedEvent's ID is the same as the component's + * ID. ID is represented as the (UID, RecurrenceID) pair. + * If UID's on this and component do NOT match return FALSE; + * If there is no RecurrenceID on this TBE and component and UID matches, + * return TRUE; + * If there is a RecurrenceID on EITHER this or component, if both have + * RecurrenceID and they MATCH return TRUE. if don't match return FALSE. + * If one has RecurrenceID and other doesn't return FALSE. + * @param TimeBasedEvent * component + * + * @return t_bool + */ + t_bool isExactMatchingID(TimeBasedEvent * component); + +#if 0 + /** + * Returns TRUE if this component is more recent than component. + * Rules To define recent: + * Returns compare(Sequence Num) else if equal + * Returns compare(DTSTAMP) + * + * @param TimeBasedEvent * component + * + * @return t_bool + */ + t_bool isMoreRecent(TimeBasedEvent * component); +#endif + + /* -- DATA MEMBERS */ + +protected: + /* log file ptr */ + JLog * m_Log; + + JulianString m_sCurl; /* the calendar url of this component, identifies its cal store */ + +private: + + /* recurrence bound value */ + static t_int32 ms_iBound; + + /* method name of calendar */ + UnicodeString m_sMethod; + + /* file loaded from */ + UnicodeString m_sFileName; + + /* DTStart of first instance of a recurrence */ + DateTime m_origDTStart; + + /* DTStart of my instance of a recurrence */ + DateTime m_origMyDTStart; + + /* TRUE = Anniversary event, default is FALSE */ + t_bool m_bAllDayEvent; + + /*------------ SUBCOMPONENTS ---------------*/ + JulianPtrArray * m_AlarmsVctr; + /*------------ PROPERTIES --- (VALUE VALUE TYPES in COMMENTS) -------------------------*/ + + JulianPtrArray * m_AttachVctr; /* URL */ + JulianPtrArray * m_AttendeesVctr; /* CAL-ADDRESS */ + JulianPtrArray * m_CategoriesVctr; /* TEXT */ + ICalProperty * m_Class; /* class keyword */ + JulianPtrArray * m_CommentVctr; /* TEXT */ + JulianPtrArray * m_ContactVctr; /* TEXT OR URL */ + ICalProperty * m_Created; /* DATETIME */ + ICalProperty * m_Description; /* TEXT */ + ICalProperty * m_DTStart; /* DATETIME OR DATE */ + ICalProperty * m_DTStamp; /* DATETIME */ + JulianPtrArray * m_ExDateVctr; /* DATETIME */ + JulianPtrArray * m_ExRuleVctr; /* RECURRENCE */ + ICalProperty * m_LastModified; /* DATETIME */ + ICalProperty * m_Organizer; /* CAL-ADDRESS */ + JulianPtrArray * m_RDateVctr; /* DATETIME, DATE, OR PERIOD */ + JulianPtrArray * m_RRuleVctr; /* RECURRENCE */ + ICalProperty * m_RecurrenceID; /* DATETIME */ + JulianPtrArray * m_RelatedToVctr; /* TEXT (must be a UID) */ + /*ICalProperty * m_RequestStatus; */ + JulianPtrArray * m_RequestStatusVctr; /* 3digit number, error Description UnicodeString, optional exception text */ + ICalProperty * m_Sequence; /* INTEGER >= 0 */ + ICalProperty * m_Status; /* status keyword */ + ICalProperty * m_Summary; /* TEXT */ + ICalProperty * m_UID; /* TEXT */ + ICalProperty * m_URL; /* TEXT OR URL */ + JulianPtrArray * m_XTokensVctr; /* TEXT */ + + /*------------ END PROPERTIES ------------------------------------------*/ +}; + +#endif /* __TIMEBASEDEVENT_H_ */ + diff --git a/calendar/modules/core/ical/inc/tzpart.h b/calendar/modules/core/ical/inc/tzpart.h new file mode 100644 index 00000000000..4c495b4b685 --- /dev/null +++ b/calendar/modules/core/ical/inc/tzpart.h @@ -0,0 +1,393 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +/* + * tzpart.h + * John Sun + * 2/24/98 9:48:53 AM + */ + +#ifndef __TZPART_H_ +#define __TZPART_H_ + +#include +#include "icalcomp.h" +#include "datetime.h" + +/** + * Implements the standardc and daylightc parts of an iCal VTimeZone object. + */ +class TZPart: public ICalComponent +{ +private: +#if 0 + /** + * Default constructor. Hide from clients. + */ + TZPart(); +#endif +protected: + /** + * Copy constructor. + * @param that TZPart to copy + */ + TZPart(TZPart & that); + +public: + + /** + * Create TZPart, passing in a logfile. + * @param initLog log file to write errors to + */ + TZPart(JLog * initLog = 0); + + /** + * Destructor + */ + ~TZPart(); + + /* -- Start of ICALComponent interface -- */ + + /** + * The parse method is the standard interface for ICalComponent + * subclasses to parse from an ICalReader object + * and from the ITIP method type (i.e. PUBLISH, REQUEST, CANCEL, etc.). + * The method type can be set to \"\" if there is no method to be loaded. + * Also accepts a vector of VTimeZone objects to apply to + * the DateTime properties of the component. + * 4-2-98: Added bIgnoreBeginError. If desired to start parsing in Component level, + * it is useful to ignore first "BEGIN:". Setting bIgnoreBeginError to TRUE allows for + * this. + * + * @param brFile ICalReader to load from + * @param sType name of component (i.e. VEVENT, VTODO, VTIMEZONE) + * @param parseStatus return parse error status string (normally return "OK") + * @param vTimeZones vector of VTimeZones to apply to datetimes + * @param bIgnoreBeginError TRUE = ignore first "BEGIN:DAYLIGHT(STANDARD)", FALSE otherwise + * @param encoding the encoding of the stream, default is 7bit. + * + * @return parse error status string (parseStatus) + */ + virtual UnicodeString & parse(ICalReader * brFile, UnicodeString & sType, + UnicodeString & parseStatus, JulianPtrArray * vTimeZones = 0, + t_bool bIgnoreBeginError = FALSE, + JulianUtility::MimeEncoding encoding = JulianUtility::MimeEncoding_7bit); + + /** + * Returns a clone of this object + * @param initLog log file to write errors to + * + * @return clone of this object + */ + virtual ICalComponent * clone(JLog * initLog); + + /** + * Return TRUE if component is valid, FALSE otherwise + * + * @return TRUE if is valid, FALSE otherwise + */ + virtual t_bool isValid(); + + /** + * Print all contents of ICalComponent to iCal export format. + * + * @return string containing iCal export format of ICalComponent + */ + virtual UnicodeString toICALString(); + + /** + * Print all contents of ICalComponent to iCal export format, depending + * on attendee name, attendee delegated-to, and where to include recurrence-id or not + * + * @param method method name (REQUEST,PUBLISH, etc.) + * @param name attendee name to filter with + * @param isRecurring TRUE = no recurrenceid, FALSE = include recurrenceid + * + * @return string containing iCal export format of ICalComponent + */ + virtual UnicodeString toICALString(UnicodeString method, UnicodeString name, + t_bool isRecurring); + + /** + * Print all contents of ICalComponent to human-readable string. + * + * @return string containing human-readable format of ICalComponent + */ + virtual UnicodeString toString(); + + /** + * Depending on character passed in, returns a string that represents + * the ICAL export string of that property that the character represents, if + * other paramaters not null, then print out information is filtered in several ways + * Attendee print out can be filtered so that only attendee with certain name is printed + * also, can print out the relevant attendees in a delegation message + * (ie. owner, delegate-to, delegate-from) + * + * @param c char of what property to print + * @param sFilterAttendee name of attendee to print + * @param bDelegateRequest TRUE if a delegate request, FALSE if not + * @return ICAL export format of that property + */ + virtual UnicodeString formatChar(t_int32 c, UnicodeString sFilterAttendee, + t_bool delegateRequest = FALSE); + + /** + * convert a character to the content of a property in string + * human-readable format + * @param c a character represents a property + * @param dateFmt for formatting datetimes + * + * @return property in human-readable string + */ + virtual UnicodeString toStringChar(t_int32 c, UnicodeString & dateFmt); + + /** + * Returns the ICAL_COMPONENT enumeration value of this ICalComponent. + * Each ICalComponent subclass must return a unique ICAL_COMPONENT value. + * + * @return ICAL_COMPONENT value of this component + */ + virtual ICAL_COMPONENT GetType() const { return ICAL_COMPONENT_TZPART; } + + /** + * Update the private property data-members with updatedComponent's + * property data-members. + * Usually, overwriting data-members should only occur if updatedComponent + * is more recent than the current component. + * Return TRUE if component was changed, FALSE otherwise + * @param ICalComponent * updatedComponent + * + * @return virtual t_bool + */ + virtual t_bool updateComponent(ICalComponent * updatedComponent); + + /* -- End of ICALComponent interface -- */ + + /* COMMENT */ + void addComment(UnicodeString s, JulianPtrArray * parameters = 0); + void addCommentProperty(ICalProperty * prop); + JulianPtrArray * getComment() const { return m_CommentVctr; } + + /* TZNAME */ + void addTZName(UnicodeString s, JulianPtrArray * parameters = 0); + void addTZNameProperty(ICalProperty * prop); + JulianPtrArray * getTZName() const { return m_TZNameVctr; } + + /* DTSTART */ + DateTime getDTStart() const; + void setDTStart(DateTime s, JulianPtrArray * parameters = 0); + ICalProperty * getDTStartProperty() const { return m_DTStart; } + + /* RDATE */ + DateTime getRDate() const; + void setRDate(DateTime s, JulianPtrArray * parameters = 0); + ICalProperty * getRDateProperty() const { return m_RDate; } + + /* RRULE */ + UnicodeString getRRule() const; + void setRRule(UnicodeString s, JulianPtrArray * parameters = 0); + ICalProperty * getRRuleProperty() const { return m_RRule; } + + /* TZOFFSETTO */ + UnicodeString getTZOffsetTo() const; + void setTZOffsetTo(UnicodeString s, JulianPtrArray * parameters = 0); + ICalProperty * getTZOffsetToProperty() const { return m_TZOffsetTo; } + + /* TZOFFSETFROM */ + UnicodeString getTZOffsetFrom() const; + void setTZOffsetFrom(UnicodeString s, JulianPtrArray * parameters = 0); + ICalProperty * getTZOffsetFromProperty() const { return m_TZOffsetFrom; } + + /* XTOKENS: NOTE: a vector of strings, not a vector of ICalProperties */ + void addXTokens(UnicodeString s); + JulianPtrArray * getXTokens() const { return m_XTokensVctr; } + + /* NAME (DAYLIGHT OR STANDARD) */ + UnicodeString getName() const { return m_Name; } + void setName(UnicodeString s); + + /** + * Return start month value of timezone part start time. 0-based + * + * @return start month value (0-11) + */ + t_int32 getMonth() const { return m_StartMonth; } + + /** + * Return start day of week in month value of timezone part start time. + * Usually -1 or 1. + * @return start day of week in month (-5 to 5) + */ + t_int32 getDayOfWeekInMonth() const { return m_StartWeek; } + + /** + * Return start day of timezone part start time. + * Usually Calendar::SUNDAY + * @return start day value (Calendar::SUNDAY - Calendar::SATURDAY) + * @see Calendar + */ + t_int32 getDay() const { return m_StartDay; } + + /** + * Return starting time in milliseconds of timezone part start time. + * For example, if start time is 2AM, then return 7200000. + * + * @return start time value in milliseconds + */ + t_int32 getStartTime() const { return m_StartTime; } + + /** + * Return expiration date of TimeZone part, if returned value is + * invalid, then no expiration date. + * + * @return expiration date, invalid means no expiration date + */ + DateTime getUntil() { return m_Until; } + + /* TODO: move later */ + static float UTCOffsetToFloat(UnicodeString & utcOffset); + +private: + + /** + * Helper method called by updateComponent to actually replace + * the property data-members with updatedComponent's data-members. + * @param TZPart * updatedComponent + * + * @return virtual void + */ + void updateComponentHelper(TZPart * updatedComponent); + + /** + * Selfcheck data members. Currently does nothing + */ + void selfCheck(); + + /** + * store the data, depending on property name, property value + * parameter names, parameter values, and the current line + * + * @param strLine current line to process + * @param propName name of property + * @param propVal value of property + * @param parameters property's parameters + * @param vTimeZones vector of timezones + */ + void storeData(UnicodeString & strLine, UnicodeString & propName, + UnicodeString & propVal, JulianPtrArray * parameters); +public: + + typedef void (TZPart::*SetOp) (UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones); + + /* Clients should NOT call below methods */ + void storeComment(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones); + void storeTZName(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones); + void storeDTStart(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones); + void storeRDate(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones); + void storeRRule(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones); + void storeTZOffsetTo(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones); + void storeTZOffsetFrom(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones); + + void ApplyStoreOp(void (TZPart::*op) (UnicodeString & strLine, + UnicodeString & propVal, JulianPtrArray * parameters, JulianPtrArray * vTimeZones), + UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones) + { + (this->*op)(strLine, propVal, parameters, vTimeZones); + } + +private: + + /** + * Takes RRULE value and generates startmonth, startday, startweek, starttime + * and until. Return TRUE if parse went OK, FALSE if error occurred. + * + * @return TRUE if parse went OK, FALSE if error occurred. + */ + t_bool parseRRule(); + + /** + * Takes RDATE value and generates startmonth, startday, startweek. + */ + void parseRDate(); + +#if 0 + /** + * Given data members, generates timezone critical information + * (start month,day,week,time,until). Calls either parseRRule or + * parseRDate to do this. If error in parse, return FALSE, else + * return TRUE. + * + * @return TRUE if parse went OK, FALSE if error occurred + */ + t_bool parseRule(); +#endif + + + /* -- DATA MEMBERS -- */ + + /*static UnicodeString m_strDefaultFmt; + static UnicodeString ms_sAllMessage;*/ + + /* for RRULE timezones */ + t_int32 m_StartMonth; + t_int32 m_StartDay; + t_int32 m_StartWeek; + t_int32 m_StartTime; + + /* used to print out DTStart back */ + t_int32 m_iStartYear; + t_int32 m_iStartMonth; + t_int32 m_iStartDay; + t_int32 m_iStartHour; + t_int32 m_iStartMinute; + t_int32 m_iStartSecond; + + /* used to print out RDate back */ + t_int32 m_iRDateYear; + t_int32 m_iRDateMonth; + t_int32 m_iRDateDay; + t_int32 m_iRDateHour; + t_int32 m_iRDateMinute; + t_int32 m_iRDateSecond; + + DateTime m_Until; + + UnicodeString m_Name; /* STANDARD or DAYLIGHT */ + + JulianPtrArray * m_CommentVctr; + JulianPtrArray * m_TZNameVctr; + ICalProperty * m_DTStart; + ICalProperty * m_RDate; + ICalProperty * m_RRule; + ICalProperty * m_TZOffsetTo; + ICalProperty * m_TZOffsetFrom; + JulianPtrArray * m_XTokensVctr; /* TEXT */ + + JLog * m_Log; +}; + +#endif /* __TZPART_H_ */ diff --git a/calendar/modules/core/ical/inc/unistrto.h b/calendar/modules/core/ical/inc/unistrto.h new file mode 100644 index 00000000000..e503c633fae --- /dev/null +++ b/calendar/modules/core/ical/inc/unistrto.h @@ -0,0 +1,108 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +/* + * unistrto.h + * John Sun + * 2/3/98 12:07:00 PM + */ + +#ifndef __UNICODESTRINGTOKENIZER_H_ +#define __UNICODESTRINGTOKENIZER_H_ + +#include +#include "ptypes.h" + +/** + * A simple string tokenizer class for UnicodeString. + * It is modeled after the java.util.StringTokenizer class + * and uses a similar subset of Java's API. + */ +class UnicodeStringTokenizer +{ +private: + + /** current position in string */ + t_int32 m_CurrentPosition; + + /** maximum position in string */ + t_int32 m_MaxPosition; + + /** the string to tokenize */ + UnicodeString m_String; + + /** the string delimeters for seperating tokens */ + UnicodeString m_StringDelimeters; + + /** Skips delimeters. */ + void skipDelimeters(); + +public: + + /** + * Constructor. + * @param str string to tokenize + * @param delim string delimeters + */ + UnicodeStringTokenizer(UnicodeString & str, UnicodeString & delim); + +#if 0 + /** + * Constructor. Sets default delimeters to whitespace characters. + * Strongly recommend using other constructor. + * @param str string to tokenize + */ + UnicodeStringTokenizer(UnicodeString & str); +#endif + + /** + * Tests if there are more tokens available from this string + * + * @return TRUE if more tokens, FALSE otherwise + */ + t_bool hasMoreTokens(); + + + /** + * Returns next token in out if available. If no more tokens + * status is set to 1. + * @param out next available token output + * @param status status error, 1 is ran-out-of-tokens, 0 is OK + * + * @return next available token (out) + */ + UnicodeString & nextToken(UnicodeString & out, ErrorCode & status); + +#if 0 + /** + * Returns next token in out if available. If no more tokens + * status is set to 1. Also sets delimeters to delim for further tokenizing. + * @param out next available token output + * @param delim the new delimeters + * @param status status error, 1 is ran-out-of-tokens, 0 is OK + * + * @return next available token (out) + */ + UnicodeString & nextToken(UnicodeString & out, UnicodeString & sDelim, ErrorCode & status); +#endif + +}; + +#endif /* __UNICODESTRINGTOKENIZER_H_ */ + + diff --git a/calendar/modules/core/ical/inc/uri.h b/calendar/modules/core/ical/inc/uri.h new file mode 100644 index 00000000000..fc1bd985673 --- /dev/null +++ b/calendar/modules/core/ical/inc/uri.h @@ -0,0 +1,101 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +/* + * uri.h + * John Sun + * 4/3/98 11:27:52 AM + */ +#ifndef __URI_H_ +#define __URI_H_ + +#include + +/** + * URI encapsulates the ICAL URI data-type. The URI data-type + * is used to identify values that contain a uniform resource + * identifier (URI) type of reference to the property value. + */ +class URI +{ +private: + /*----------------------------- + ** MEMBERS + **---------------------------*/ + + /** URL string */ + UnicodeString m_URI; +public: + + /*----------------------------- + ** CONSTRUCTORS and DESTRUCTORS + **---------------------------*/ + + /** + * Default constructor makes string "". + */ + URI(); + + /** creates a URI with full URI */ + URI(UnicodeString fulluri); + + URI(char * fulluri); + /*----------------------------- + ** ACCESSORS (GET AND SET) + **---------------------------*/ + + /** + * returns full uri string + * (i.e. http://host1.com/my-report.txt, mailto:a@acme.com) + * + * @return the full uri string + */ + UnicodeString getFullURI() { return m_URI; } + + /** return protocol name (i.e. Mailto:, http:, ftp:) */ + /*UnicodeString getProtocol();*/ + + /** + * return name (right side of ':' in full uri) + * (i.e. host1.com/my-report.txt, a@acme.com) + * + * @return the return name + */ + UnicodeString getName(); + + /** + * set full uri string + * @param uri new full URI string + */ + void setFullURI(UnicodeString uri) { m_URI = uri; } + + /** + * Checks whether string is a URI. + * For now just checks if a colon exists in string and + * it does not start with a colon. + * Thus: yoadfs:fdsaf is a valid URL. + * @param UnicodeString & s + * + * @return static t_bool + */ + static t_bool IsValidURI(UnicodeString & s); +}; + +#endif /* __URI_H_ */ + + diff --git a/calendar/modules/core/ical/inc/valarm.h b/calendar/modules/core/ical/inc/valarm.h new file mode 100644 index 00000000000..5d45cffd902 --- /dev/null +++ b/calendar/modules/core/ical/inc/valarm.h @@ -0,0 +1,377 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the 'NPL'); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an 'AS IS' basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +/* + * valarm.h + * John Sun + * 7/22/98 10:34:34 AM + */ + +#ifndef __VALARM_H_ +#define __VALARM_H_ + +#include +#include "datetime.h" +#include "ptrarray.h" +#include "jlog.h" +#include "icalcomp.h" +#include "attendee.h" +#include "keyword.h" +#include "nscalcoreicalexp.h" + +class NS_CAL_CORE_ICAL VAlarm: public ICalComponent +{ +public: + /** an enumeration of the ACTION parameter */ + /* default is audio */ + enum ACTION + { + ACTION_AUDIO = 0, + ACTION_DISPLAY = 1, + ACTION_EMAIL = 2, + ACTION_PROCEDURE = 3, + ACTION_INVALID = -1 + }; + +private: + /*----------------------------- + ** MEMBERS + **---------------------------*/ + JLog * m_Log; + + /* -- properties in ALL action types -- */ + /*ICalProperty * m_Action;*/ + ACTION m_Action; + + /* as a duration */ + ICalProperty * m_Trigger; + + /* as a datetime */ + DateTime m_TriggerDateTime; + + /* duration and repeat are optional */ + ICalProperty * m_Duration; + ICalProperty * m_Repeat; + + JulianPtrArray * m_XTokensVctr; + + /* -- end ALL action types properties -- */ + + + /* used in more that one action type but not all */ + JulianPtrArray * m_AttachVctr; + ICalProperty * m_Description; + + /* audio props */ + /* always ONLY one attachment */ + /* NO description */ + + /* display props */ + /* NO attachments */ + /* One description */ + + /* email props */ + /* any number of attachments */ + /* One description */ + /* at least one attendee */ + JulianPtrArray * m_AttendeesVctr; + ICalProperty * m_Summary; + + /* procedure props */ + /* always ONLY one attachment */ + /* Zero or One description */ + + /*----------------------------- + ** PRIVATE METHODS + **---------------------------*/ + /** + * Creates NLS TimeZone from start month,day,week,time,until. + * TODO: possible bug, may need to call everytime before calling getNLSTimeZone(). + */ + void selfCheck(); + + /** + * store the data, depending on property name, property value + * parameter names, parameter values, and the current line. + * + * @param strLine current line to process + * @param propName name of property + * @param propVal value of property + * @param parameters property's parameters + * @param vTimeZones vector of timezones + * @return TRUE if line was handled, FALSE otherwise + */ + void storeData(UnicodeString & strLine, + UnicodeString & propName, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones); + + /** + * Helper method called by updateComponent to actually replace + * the property data-members with updatedComponent's data-members. + * @param VTimeZone * updatedComponent + * + * @return virtual void + */ + void updateComponentHelper(VAlarm * updatedComponent); +public: + typedef void (VAlarm::*SetOp) (UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones); + + /* Clients should not call these methods even though they are not public */ + + void storeAction(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones); + void storeAttach(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones); + void storeAttendee(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones); + void storeDescription(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones); + void storeDuration(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones); + void storeRepeat(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones); + void storeSummary(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones); + void storeTrigger(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones); + + void ApplyStoreOp(void (VAlarm::*op) (UnicodeString & strLine, + UnicodeString & propVal, JulianPtrArray * parameters, JulianPtrArray * vTimeZones), + UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones) + { + (this->*op)(strLine, propVal, parameters, vTimeZones); + } +private: + + + +#if 0 + VAlarm(); +#endif +protected: + + VAlarm(VAlarm & that); + +public: + /*----------------------------- + ** CONSTRUCTORS and DESTRUCTORS + **---------------------------*/ + VAlarm(JLog * initLog = 0); + + virtual ~VAlarm(); + + /* -- Start of ICALComponent interface -- */ + + /** + * The parse method is the standard interface for ICalComponent + * subclasses to parse from an ICalReader object + * and from the ITIP method type (i.e. PUBLISH, REQUEST, CANCEL, etc.). + * The method type can be set to \"\" if there is no method to be loaded. + * Also accepts a vector of VTimeZone objects to apply to + * the DateTime properties of the component. + * 4-2-98: Added bIgnoreBeginError. If desired to start parsing in Component level, + * it is useful to ignore first "BEGIN:". Setting bIgnoreBeginError to TRUE allows for + * this. + * + * @param brFile ICalReader to load from + * @param sType name of component (VTIMEZONE) + * @param parseStatus return parse error status string (normally return "OK") + * @param vTimeZones vector of VTimeZones to apply to datetimes + * @param bIgnoreBeginError TRUE = ignore first "BEGIN:VTIMEZONE", FALSE otherwise + * @param encoding the encoding of the stream, default is 7bit. + * + * @return parse error status string (parseStatus) + */ + virtual UnicodeString & parse(ICalReader * brFile, UnicodeString & sType, + UnicodeString & parseStatus, JulianPtrArray * vTimeZones = 0, + t_bool bIgnoreBeginError = FALSE, + JulianUtility::MimeEncoding encoding = JulianUtility::MimeEncoding_7bit); + + /** + * Returns a clone of this object + * @param initLog log file to write errors to + * + * @return clone of this object + */ + virtual ICalComponent * clone(JLog * initLog); + + /** + * Return TRUE if component is valid, FALSE otherwise + * + * @return TRUE if is valid, FALSE otherwise + */ + virtual t_bool isValid(); + + /** + * Print all contents of ICalComponent to iCal export format. + * + * @return string containing iCal export format of ICalComponent + */ + virtual UnicodeString toICALString(); + + /** + * Print all contents of ICalComponent to iCal export format, depending + * on attendee name, attendee delegated-to, and where to include recurrence-id or not + * + * @param method method name (REQUEST,PUBLISH, etc.) + * @param name attendee name to filter with + * @param isRecurring TRUE = no recurrenceid, FALSE = include recurrenceid + * + * @return string containing iCal export format of ICalComponent + */ + virtual UnicodeString toICALString(UnicodeString method, UnicodeString name, + t_bool isRecurring); + + /** + * Print all contents of ICalComponent to human-readable string. + * + * @return string containing human-readable format of ICalComponent + */ + virtual UnicodeString toString(); + + /** + * Depending on character passed in, returns a string that represents + * the ICAL export string of that property that the character represents, if + * other paramaters not null, then print out information is filtered in several ways + * Attendee print out can be filtered so that only attendee with certain name is printed + * also, can print out the relevant attendees in a delegation message + * (ie. owner, delegate-to, delegate-from) + * + * @param c char of what property to print + * @param sFilterAttendee name of attendee to print + * @param bDelegateRequest TRUE if a delegate request, FALSE if not + * @return ICAL export format of that property + */ + virtual UnicodeString formatChar(t_int32 c, UnicodeString sFilterAttendee, + t_bool delegateRequest = FALSE); + + /** + * convert a character to the content of a property in string + * human-readable format + * @param c a character represents a property + * @param dateFmt for formatting datetimes + * + * @return property in human-readable string + */ + virtual UnicodeString toStringChar(t_int32 c, UnicodeString & dateFmt); + + /** + * Returns the ICAL_COMPONENT enumeration value of this ICalComponent. + * Each ICalComponent subclass must return a unique ICAL_COMPONENT value. + * + * @return ICAL_COMPONENT value of this component + */ + virtual ICAL_COMPONENT GetType() const { return ICAL_COMPONENT_VALARM; } + + /** + * Update the private property data-members with updatedComponent's + * property data-members. + * Usually, overwriting data-members should only occur if updatedComponent + * is more recent than the current component. + * Return TRUE if component was changed, FALSE otherwise + * @param ICalComponent * updatedComponent + * + * @return virtual t_bool + */ + virtual t_bool updateComponent(ICalComponent * updatedComponent); + + /* -- End of ICALComponent interface -- */ + + /*----------------------------- + ** ACCESSORS (GET AND SET) + **---------------------------*/ + VAlarm::ACTION getAction() const { return m_Action; } + void setAction(VAlarm::ACTION action) { m_Action = action; } + + /* Julian_Duration */ + Julian_Duration getDuration() const; + void setDuration(Julian_Duration s, JulianPtrArray * parameters = 0); + ICalProperty * getDurationProperty() const { return m_Duration; } + + /* Repeat */ + t_int32 getRepeat() const; + void setRepeat(t_int32 i, JulianPtrArray * parameters = 0); + ICalProperty * getRepeatProperty() const { return m_Repeat; } + + /* Trigger */ + /* can be date-time or duration */ + Julian_Duration getTriggerAsDuration() const; + void setTriggerAsDuration(Julian_Duration s, JulianPtrArray * parameters = 0); + void setTriggerAsDateTime(DateTime s); + ICalProperty * getTriggerProperty() const { return m_Trigger; } + DateTime getTriggerAsDateTime(DateTime startTime) const; + + /* Description */ + UnicodeString getDescription() const; + void setDescription(UnicodeString s, JulianPtrArray * parameters = 0); + ICalProperty * getDescriptionProperty() const { return m_Description; } + + /* SUMMARY */ + UnicodeString getSummary() const; + void setSummary(UnicodeString s, JulianPtrArray * parameters = 0); + ICalProperty * getSummaryProperty() const { return m_Summary; } + + /* ATTACH */ + void addAttach(UnicodeString s, JulianPtrArray * parameters = 0); + void addAttachProperty(ICalProperty * prop); + JulianPtrArray * getAttach() const { return m_AttachVctr; } + + /* XTOKENS: NOTE: a vector of strings, not a vector of ICalProperties */ + void addXTokens(UnicodeString s); + JulianPtrArray * getXTokens() const { return m_XTokensVctr; } + + /* ATTENDEES */ + void addAttendee(Attendee * a); + JulianPtrArray * getAttendees() const { return m_AttendeesVctr ; } + + /* JLOG */ + JLog * getLog() const { return m_Log; } + + /*----------------------------- + ** UTILITIES + **---------------------------*/ + /*----------------------------- + ** STATIC METHODS + **---------------------------*/ + + /** + * Converts string to ACTION enumeration. Returns AUDIO if error. + * @param sAction action string + * + * @return ACTION enumeration value of sAction + */ + static VAlarm::ACTION stringToAction(UnicodeString & sAction); + + /** + * Converts ACTION to string. + * @param action action value + * @param out output action string + * + * @return output action string + */ + static UnicodeString & actionToString(VAlarm::ACTION action, UnicodeString & out); + + /*----------------------------- + ** OVERLOADED OPERATORS + **---------------------------*/ +}; + +#endif /* __VALARM_H_ */ + diff --git a/calendar/modules/core/ical/inc/vevent.h b/calendar/modules/core/ical/inc/vevent.h new file mode 100644 index 00000000000..c0fb36d9227 --- /dev/null +++ b/calendar/modules/core/ical/inc/vevent.h @@ -0,0 +1,334 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +/* + * vevent.h + * John Sun + * 2/9/98 10:50:22 PM + */ + +#ifndef __VEVENT_H_ +#define __VEVENT_H_ + +#include "datetime.h" +#include "duration.h" +#include "ptrarray.h" +#include "tmbevent.h" +#include "jlog.h" +#include "nscalcoreicalexp.h" + +class NS_CAL_CORE_ICAL VEvent : public TimeBasedEvent +{ +private: +#if 0 + VEvent(); +#endif +protected: + /** + * Copy constructor. + * @param that VEvent to copy. + */ + VEvent(VEvent & that); + +public: + + /** + * Constructor. Create VEvent with initial log file set to initLog. + * @param initLog initial log file pointer + */ + VEvent(JLog * initLog = 0); + + /** + * Destructor. + */ + ~VEvent(); + + /* -- Start of ICALComponent interface -- */ + + /** + * The parse method is the standard interface for ICalComponent + * subclasses to parse from an ICalReader object + * and from the ITIP method type (i.e. PUBLISH, REQUEST, CANCEL, etc.). + * The method type can be set to \"\" if there is no method to be loaded. + * Also accepts a vector of VTimeZone objects to apply to + * the DateTime properties of the component. + * 4-2-98: Added bIgnoreBeginError. If desired to start parsing in Component level, + * it is useful to ignore first "BEGIN:". Setting bIgnoreBeginError to TRUE allows for + * this. + * + * @param brFile ICalReader to load from + * @param sType name of component (i.e. VEVENT, VTODO, VTIMEZONE) + * @param parseStatus return parse error status string (normally return "OK") + * @param vTimeZones vector of VTimeZones to apply to datetimes + * @param bIgnoreBeginError TRUE = ignore first "BEGIN:VEVENT", FALSE otherwise + * @param encoding the encoding of the stream, default is 7bit. + * + * @return parse error status string (parseStatus) + */ + UnicodeString & parse(ICalReader * brFile, UnicodeString & sMethod, + UnicodeString & parseStatus, JulianPtrArray * vTimeZones = 0, + t_bool bIgnoreBeginError = FALSE, + JulianUtility::MimeEncoding encoding = JulianUtility::MimeEncoding_7bit); + + /** + * Returns a clone of this object + * @param initLog log file to write errors to + * + * @return clone of this object + */ + virtual ICalComponent * clone(JLog * initLog); + + /** + * Return TRUE if component is valid, FALSE otherwise + * + * @return TRUE if is valid, FALSE otherwise + */ + t_bool isValid(); + + /** + * Print all contents of ICalComponent to human-readable string. + * + * @return string containing human-readable format of ICalComponent + */ + virtual UnicodeString toString(); + + /** + * Depending on character passed in, returns a string that represents + * the ICAL export string of that property that the character represents, if + * other paramaters not null, then print out information is filtered in several ways + * Attendee print out can be filtered so that only attendee with certain name is printed + * also, can print out the relevant attendees in a delegation message + * (ie. owner, delegate-to, delegate-from) + * + * @param c char of what property to print + * @param sFilterAttendee name of attendee to print + * @param bDelegateRequest TRUE if a delegate request, FALSE if not + * @return ICAL export format of that property + */ + virtual UnicodeString formatChar(t_int32 c, + UnicodeString sFilterAttendee, t_bool delegateRequest = FALSE); + + /** + * convert a character to the content of a property in string + * human-readable format + * @param c a character represents a property + * @param dateFmt for formatting datetimes + * + * @return property in human-readable string + */ + virtual UnicodeString toStringChar(t_int32 c, UnicodeString & dateFmt); + + /** + * Returns the ICAL_COMPONENT enumeration value of this ICalComponent. + * Each ICalComponent subclass must return a unique ICAL_COMPONENT value. + * + * @return ICAL_COMPONENT value of this component + */ + virtual ICAL_COMPONENT GetType() const { return ICAL_COMPONENT_VEVENT ; } + + /* -- End of ICALComponent interface -- */ + + /** + * Overridden virtual method used as wrapper to ICalComponent::format method. + * @param strFmt iCal format string + * @param sFilterAttendee attendee to filter + * @param delegateRequest delegate request = TRUE, FALSE otherwise + * + * @return output iCal formatted export string + */ + virtual UnicodeString formatHelper(UnicodeString & strFmt, + UnicodeString sFilterAttendee, t_bool delegateRequest = FALSE); + + /** + * Helper method. Overriden virtual method. Used by subclasses to + * populate recurrence-dependent data. For example, a recurring + * VEvent needs to have DTEnd calculated from recurring + * DTStart. VEvent will overwrite method set DTEnd correctly. + * Abstract difference() method is used to calculate ldiff. + * Need to pass vector of RDate periods in case end value must + * be adjusted in RDATE is a PERIOD value. + * @param start recurrence instance starting time + * @param ldiff abstract difference value + * @param vPer vector of RDate periods + */ + void populateDatesHelper(DateTime start, Date ldiff, JulianPtrArray * vPer); + + + /* overridden message methods */ + virtual UnicodeString cancelMessage(); + virtual UnicodeString requestMessage(); + virtual UnicodeString requestRecurMessage(); + virtual UnicodeString counterMessage(); + virtual UnicodeString declineCounterMessage(); + virtual UnicodeString addMessage(); + virtual UnicodeString refreshMessage(UnicodeString sAttendeeFilter); + virtual UnicodeString allMessage(); + virtual UnicodeString replyMessage(UnicodeString sAttendeeFilter); + virtual UnicodeString publishMessage(); + virtual UnicodeString publishRecurMessage(); + + /** + * Overridden method. Calculate difference from start, end time + * For VEvent, this would be DTEnd - DTStart. + * For VTodo, this would be Due - DTStart. + * + * @return virtual Date + */ + Date difference(); + + /** + * Sets default human-readable event format pattern to s. + * @param s new event format pattern + */ + static void setDefaultFmt(UnicodeString s); + + /* ------------------------------------ + * SET/GET DATA MEMBER + *-------------------------------------*/ + + /* DTEND */ + DateTime getDTEnd() const; + void setDTEnd(DateTime s, JulianPtrArray * parameters = 0); + ICalProperty * getDTEndProperty() const { return m_DTEnd; } + + /* DURATION */ + Julian_Duration getDuration() const; + void setDuration(Julian_Duration s, JulianPtrArray * parameters = 0); + /*ICalProperty * getDurationProperty() const { return m_Duration; }*/ + + /* GEO */ + UnicodeString getGEO() const; + void setGEO(UnicodeString s, JulianPtrArray * parameters = 0); + ICalProperty * getGEOProperty() const { return m_GEO; } + + /* LOCATION */ + UnicodeString getLocation() const; + void setLocation(UnicodeString s, JulianPtrArray * parameters = 0); + ICalProperty * getLocationProperty() const { return m_Location; } + + /* PRIORITY */ + t_int32 getPriority() const; + void setPriority(t_int32 i, JulianPtrArray * parameters = 0); + ICalProperty * getPriorityProperty() const { return m_Priority; } + + /* TRANSP */ + UnicodeString getTransp() const; + void setTransp(UnicodeString s, JulianPtrArray * parameters = 0); + ICalProperty * getTranspProperty() const { return m_Transp; } + + /* RESOURCES */ + void addResources(UnicodeString s, JulianPtrArray * parameters = 0); + void addResourcesProperty(ICalProperty * prop); + JulianPtrArray * getResources() const { return m_ResourcesVctr; } + void addResourcesPropertyVector(UnicodeString & propVal, JulianPtrArray * parameters); + + /* MYORIGEND */ + void setMyOrigEnd(DateTime d) { m_origMyDTEnd = d; } + DateTime getMyOrigEnd() { return m_origMyDTEnd; } + + /* ORIGEND */ + void setOrigEnd(DateTime d) { m_origDTEnd = d; } + DateTime getOrigEnd() { return m_origDTEnd; } + + virtual void updateComponentHelper(TimeBasedEvent * updatedComponent); + +private: + + /** + * store the data, depending on property name, property value + * parameter names, parameter values, and the current line. + * If this method returns FALSE, property not valid. + * + * @param strLine current line to process + * @param propName name of property + * @param propVal value of property + * @param parameters property's parameters + * @param vTimeZones vector of timezones + * @return TRUE if property handled, FALSE otherwise + */ + t_bool storeData(UnicodeString & strLine, + UnicodeString & propName, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones); +public: + + typedef void (VEvent::*SetOp) (UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones); + + /* Clients should NOT call below methods */ + void storeDTEnd(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones); + void storeDuration(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones); + void storeGEO(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones); + void storeLocation(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones); + void storePriority(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones); + void storeResources(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones); + void storeTransp(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones); + + void ApplyStoreOp(void (VEvent::*op) (UnicodeString & strLine, + UnicodeString & propVal, JulianPtrArray * parameters, JulianPtrArray * vTimeZones), + UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones) + { + (this->*op)(strLine, propVal, parameters, vTimeZones); + } + +private: + + /** + * Sets default data. Currently does following: + * 1) Sets DTEnd to correct value, depending on DURATION, DTSTART + * (see spec on rules) + * 2) Sets TRANSP to TRANSPARENT if anniversary event + */ + void selfCheck(); + + + /*void setDefaultProps(UnicodeString propName);*/ + + /* -- MEMBERS -- */ + + /* DTEnd of first instance of a recurrence */ + DateTime m_origDTEnd; + + /* DTEnd of my instance of a recurrence */ + DateTime m_origMyDTEnd; + + /** used for initial parse only to calculate first DTEnd, then discarded */ + Julian_Duration * m_TempDuration; + + /*------------------------------------------------- + * DATA MEMBER (to augment TimeBasedEvent) + *------------------------------------------------*/ + + ICalProperty * m_DTEnd; /* DATETIME */ + ICalProperty * m_GEO; /* geographic position (two floats)*/ + ICalProperty * m_Location; /* TEXT */ + ICalProperty * m_Priority; /* INTEGER >= 0 */ + JulianPtrArray * m_ResourcesVctr; /* TEXT */ + ICalProperty * m_Transp; /* transparency keyword */ + +}; + +#endif /* __VEVENT_H_ */ + diff --git a/calendar/modules/core/ical/inc/vfrbsy.h b/calendar/modules/core/ical/inc/vfrbsy.h new file mode 100644 index 00000000000..1fdf608ec16 --- /dev/null +++ b/calendar/modules/core/ical/inc/vfrbsy.h @@ -0,0 +1,549 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +/* + * vfrbsy.h + * John Sun + * 2/19/98 4:17:54 PM + */ + +#ifndef __VFREEBUSY_H_ +#define __VFREEBUSY_H_ + +#include +#include "datetime.h" +#include "duration.h" +#include "period.h" +#include "icalcomp.h" +#include "attendee.h" +#include "freebusy.h" +#include "jlog.h" + +class VFreebusy : public ICalComponent +{ +private: +#if 0 + + /** + * Default Constructor. Hide from clients. + */ + VFreebusy(); +#endif +protected: + + /** + * Checks private data members so they are valid. + * Sets default data. Currently does following: + * 1) Sets DTEnd to correct value, depending on DURATION, DTSTART + * (see spec on rules) + */ + void selfCheck(); + + /*public static VFreebusy * createVFreebusy(UnicodeString & string);*/ + + /** + * store the data, depending on property name, property value + * parameter names, parameter values, and the current line. + * If this method returns FALSE, property not valid. + * + * @param strLine current line to process + * @param propName name of property + * @param propVal value of property + * @param parameters property's parameters + * @param vTimeZones vector of timezones + * @return TRUE if property handled, FALSE otherwise + */ + t_bool storeData(UnicodeString & strLine, UnicodeString & propName, + UnicodeString & propVal, JulianPtrArray * parameters, + JulianPtrArray * vTimeZones); +public: + typedef void (VFreebusy::*SetOp) (UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones); + + /* Clients should NOT call below methods */ + void storeAttendees(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones); + void storeComment(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones); + void storeContact(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones); + /* + void storeCreated(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones); + */ + void storeDuration(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones); + void storeDTEnd(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones); + void storeDTStart(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones); + void storeDTStamp(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones); + void storeFreebusy(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones); + void storeLastModified(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones); + void storeOrganizer(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones); + void storeRequestStatus(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones); + void storeSequence(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones); + void storeUID(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones); + void storeURL(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones); + + void ApplyStoreOp(void (VFreebusy::*op) (UnicodeString & strLine, + UnicodeString & propVal, JulianPtrArray * parameters, JulianPtrArray * vTimeZones), + UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones) + { + (this->*op)(strLine, propVal, parameters, vTimeZones); + } + +protected: + UnicodeString formatHelper(UnicodeString & strFmt, + UnicodeString sFilterAttendee); + + /** + * Sorts vector of Freebusy periods by start time. + */ + void sortFreebusy(); + + /** + * Given a vector of Freebusy objects, + * combines freebusy objects that have the same params + * by calling the Freebusy::HasSameParams method. + */ + static void combineSameFreebusies(JulianPtrArray * freebusies); + + /** + * Given a vector of Freebusy objects, + * compress each Freebusy in the vector. + * By compressing, periods with overlapping times and same type + * are combined. Calls Freebusy::normalizePeriods. + */ + static void compressFreebusies(JulianPtrArray * freebusies); + + /** + * Takes freebusy vector + * Merges single-period Freebusy objects that are consecutive + * into one single-period Freebusy objects + * + * Alters the freebusy vector from + * FB1: p1, p2, p3 + * FB2: p4, p5 + * FB3: p6, p7 + * to + * FB1: p1 + * FB2: p2 + * FB3: p3 + * FB4: p4 + * FB5: p5 + * FB6: p6 + * FB7: p7 + * where FB1-7 will be sorted chronologically by start and normalized + */ + void mergeSinglePeriodFreebusies(); + + /** + * Given a vector of Freebusy objects, + * unzips each freebusy object. + * Unzipping means the following + * Given: + * FB1: pA, pB, pC + * FB2: pD, pE, pF + * FB3: pG, pH + * unzipping leads to: + * FB1: pA + * FB2: pB + * FB3: pC + * FB4: pD + * ../etc. + */ + void unzipFreebusies(); + + /** + * Adds extra FREE freebusy objects to fill periods of time + * that specify are not covered by the current freebusy objects + * in the freebusy vector. + */ + void addExtraFreePeriodFreebusies(JulianPtrArray * freebusies); + +#if 0 + /** + * Debug printing of Freebusy vector + */ + static void DEBUG_printFreebusyVector(const char * message, JulianPtrArray * freebusies); +#endif + + /** + * TODO: doesn't do smart overriding for now, does simple overwrite + * Helper method called by updateComponent to actually replace + * the property data-members with updatedComponent's data-members. + * @param VFreebusy * updatedComponent + * + * @return virtual void + */ + void updateComponentHelper(VFreebusy * updatedComponent); + +#if 0 + /** + * Returns TRUE if this component is more recent than component. + * Rules To define recent: + * Returns compare(Sequence Num) else if equal + * Returns compare(DTSTAMP) + * + * @param VFreebusy * component + * + * @return t_bool + */ + t_bool isMoreRecent(VFreebusy * component); +#endif + + /** + * Copy constructor. + * @param that VFreebusy to copy + */ + VFreebusy(VFreebusy & that); + +public: + + /** + * Constructor. Creates VFreebusy with initial log file initLog. + * @param JLog * initLog = 0 + */ + VFreebusy(JLog * initLog = 0); + + /** + * Destructor. + */ + ~VFreebusy(); + + /* -- Start of ICALComponent interface -- */ + + /** + * The parse method is the standard interface for ICalComponent + * subclasses to parse from an ICalReader object + * and from the ITIP method type (i.e. PUBLISH, REQUEST, CANCEL, etc.). + * The method type can be set to \"\" if there is no method to be loaded. + * Also accepts a vector of VTimeZone objects to apply to + * the DateTime properties of the component. + * 4-2-98: Added bIgnoreBeginError. If desired to start parsing in Component level, + * it is useful to ignore first "BEGIN:". Setting bIgnoreBeginError to TRUE allows for + * this. + * + * @param brFile ICalReader to load from + * @param sType name of component (i.e. VEVENT, VTODO, VTIMEZONE) + * @param parseStatus return parse error status string (normally return "OK") + * @param vTimeZones vector of VTimeZones to apply to datetimes + * @param bIgnoreBeginError TRUE = ignore first "BEGIN:VFREEBUSY", FALSE otherwise + * @param encoding the encoding of the stream, default is 7bit. + * + * @return parse error status string (parseStatus) + */ + virtual UnicodeString & parse(ICalReader * brFile, UnicodeString & method, + UnicodeString & parseStatus, JulianPtrArray * vTimeZones = 0, + t_bool bIgnoreBeginError = FALSE, + JulianUtility::MimeEncoding encoding = JulianUtility::MimeEncoding_7bit); + + /** + * Returns a clone of this object + * @param initLog log file to write errors to + * + * @return clone of this object + */ + virtual ICalComponent * clone(JLog * initLog); + + /** + * Return TRUE if component is valid, FALSE otherwise + * + * @return TRUE if is valid, FALSE otherwise + */ + virtual t_bool isValid(); + + /** + * Print all contents of ICalComponent to iCal export format. + * + * @return string containing iCal export format of ICalComponent + */ + virtual UnicodeString toICALString(); + + /** + * Print all contents of ICalComponent to iCal export format, depending + * on attendee name, attendee delegated-to, and where to include recurrence-id or not + * + * @param method method name (REQUEST,PUBLISH, etc.) + * @param name attendee name to filter with + * @param isRecurring TRUE = no recurrenceid, FALSE = include recurrenceid + * + * @return string containing iCal export format of ICalComponent + */ + virtual UnicodeString toICALString(UnicodeString method, UnicodeString name, + t_bool isRecurring = FALSE); + + /** + * Print all contents of ICalComponent to human-readable string. + * + * @return string containing human-readable format of ICalComponent + */ + virtual UnicodeString toString(); + + /** + * Depending on character passed in, returns a string that represents + * the ICAL export string of that property that the character represents, if + * other paramaters not null, then print out information is filtered in several ways + * Attendee print out can be filtered so that only attendee with certain name is printed + * also, can print out the relevant attendees in a delegation message + * (ie. owner, delegate-to, delegate-from) + * + * @param c char of what property to print + * @param sFilterAttendee name of attendee to print + * @param bDelegateRequest TRUE if a delegate request, FALSE if not + * @return ICAL export format of that property + */ + virtual UnicodeString formatChar(t_int32 c, UnicodeString sFilterAttendee, + t_bool delegateRequest = FALSE); + + /** + * convert a character to the content of a property in string + * human-readable format + * @param c a character represents a property + * @param dateFmt for formatting datetimes + * + * @return property in human-readable string + */ + virtual UnicodeString toStringChar(t_int32 c, UnicodeString & dateFmt); + + /** + * Returns the ICAL_COMPONENT enumeration value of this ICalComponent. + * Each ICalComponent subclass must return a unique ICAL_COMPONENT value. + * + * @return ICAL_COMPONENT value of this component + */ + virtual ICAL_COMPONENT GetType() const { return ICAL_COMPONENT_VFREEBUSY; } + + /** + * Update the private property data-members with updatedComponent's + * property data-members. + * Usually, overwriting data-members should only occur if updatedComponent + * is more recent than the current component. + * Return TRUE if component was changed, FALSE otherwise + * @param ICalComponent * updatedComponent + * + * @return virtual t_bool + */ + virtual t_bool updateComponent(ICalComponent * updatedComponent); + + /* OVERRIDES ICalComponent::MatchUID_seqNO */ + virtual t_bool MatchUID_seqNO(UnicodeString uid, t_int32 iSeqNo); + + /* -- End of ICALComponent interface -- */ + + /* -- GETTERS AND SETTERS -- */ + + /* ATTENDEE */ + void addAttendee(Attendee * a); + JulianPtrArray * getAttendees() const { return m_AttendeesVctr ; } + + /* COMMENT */ + void addComment(UnicodeString s, JulianPtrArray * parameters = 0); + void addCommentProperty(ICalProperty * prop); + JulianPtrArray * getComment() const { return m_CommentVctr; } + + /* CREATED */ + /* + DateTime getCreated() const; + void setCreated(DateTime s, JulianPtrArray * parameters = 0); + ICalProperty * getCreatedProperty() const { return m_Created; } + */ + + /* DURATION */ + Julian_Duration getDuration() const; + void setDuration(Julian_Duration s, JulianPtrArray * parameters = 0); + /* ICalProperty * getDurationProperty() const { return m_Duration; } */ + + /* DTSTART */ + DateTime getDTStart() const; + void setDTStart(DateTime s, JulianPtrArray * parameters = 0); + ICalProperty * getDTStartProperty() const { return m_DTStart; } + + /* DTSTAMP */ + DateTime getDTStamp() const; + void setDTStamp(DateTime s, JulianPtrArray * parameters = 0); + ICalProperty * getDTStampProperty() const { return m_DTStamp; } + + /* DTEND */ + DateTime getDTEnd() const; + void setDTEnd(DateTime s, JulianPtrArray * parameters = 0); + ICalProperty * getDTEndProperty() const { return m_DTEnd; } + + /* FREEBUSY */ + void addFreebusy(Freebusy * f); + JulianPtrArray * getFreebusy() const { return m_FreebusyVctr ; } + void removeAllFreebusy(); + + /* LAST-MODIFIED */ + DateTime getLastModified() const; + void setLastModified(DateTime s, JulianPtrArray * parameters = 0); + ICalProperty * getLastModifiedProperty() const { return m_LastModified; } + + /* ORGANIZER */ + UnicodeString getOrganizer() const; + void setOrganizer(UnicodeString s, JulianPtrArray * parameters = 0); + ICalProperty * getOrganizerProperty() const { return m_Organizer; } + + /* RELATED-TO */ + /*void addRelatedTo(UnicodeString s, JulianPtrArray * parameters = 0); + void addRelatedToProperty(ICalProperty * prop); + JulianPtrArray * getRelatedTo() const { return m_RelatedToVctr; }*/ + + /* CONTACT */ + void addContact(UnicodeString s, JulianPtrArray * parameters = 0); + void addContactProperty(ICalProperty * prop); + JulianPtrArray * getContact() const { return m_ContactVctr; } + + /* REQUEST-STATUS */ + /* + UnicodeString getRequestStatus() const; + void setRequestStatus(UnicodeString s, JulianPtrArray * parameters = 0); + ICalProperty * getRequestStatusProperty() const { return m_RequestStatus; } + */ + void addRequestStatus(UnicodeString s, JulianPtrArray * parameters = 0); + void addRequestStatusProperty(ICalProperty * prop); + JulianPtrArray * getRequestStatus() const { return m_RequestStatusVctr; } + + /* SEQUENCE */ + t_int32 getSequence() const; + void setSequence(t_int32 i, JulianPtrArray * parameters = 0); + ICalProperty * getSequenceProperty() const { return m_Sequence; } + + /* UID */ + UnicodeString getUID() const; + void setUID(UnicodeString s, JulianPtrArray * parameters = 0); + ICalProperty * getUIDProperty() const { return m_UID; } + + /* URL */ + /*void addURL(UnicodeString s, JulianPtrArray * parameters = 0); + void addURLProperty(ICalProperty * prop); + JulianPtrArray * getURL() const { return m_URLVctr; }*/ + UnicodeString getURL() const; + void setURL(UnicodeString s, JulianPtrArray * parameters = 0); + ICalProperty * getURLProperty() const { return m_URL; } + + /* XTOKENS: NOTE: a vector of strings, not a vector of ICalProperties */ + void addXTokens(UnicodeString s); + JulianPtrArray * getXTokens() const { return m_XTokensVctr; } + + /* Method */ + void setMethod(UnicodeString & s) { m_sMethod = s; } + UnicodeString & getMethod() { return m_sMethod; } + +#if 0 + /** + * Sets Attendee with the name sAttendeeFilter to status. + * If the status is Delegated, then adds each element in delegatedTo + * to the delegatedTo vector of that attendee. + * If that attendee does not exist in the attendee list, then add + * a new Attendee to the attendee list with his/her PARTSTAT set to status. + * @param sAttendeeFilter attendee to set status on + * @param status status to set + * @param delegatedTo vector of delegatedTo names to set to + */ + void setAttendeeStatus(UnicodeString & sAttendeeFilter, Attendee::STATUS status, + JulianPtrArray * delegatedTo = 0); +#endif + + /** + * Return the Attendee in attendee vector with name equal + * to sAttendee. Return 0 if no attendee with that name. + * @param sAttendee name of attendee + * + * @return Attendee whose name is sAttendee, 0 if not found + */ + Attendee * getAttendee(UnicodeString sAttendee); + + /** + * Sets DTStamp to current time value. + */ + void stamp(); + + /*void update(VFreebusy * vfUpdated);*/ + /*t_bool IsIntersectingTimePeriod(DateTime start, DateTime end);*/ + + + /** + * Takes Freebusy vector and break it up into sorted combined freebusy periods. + */ + void normalize(); + + /** + * Compare VFreebusy by UID. Used by JulianPtrArray::QuickSort method. + * @param a first VFreebusy + * @param b second VFreebusy + * + * @return a.getUID().compareTo(b.getUID()) + */ + static int CompareVFreebusyByUID(const void * a, const void * b); + + /** + * Compare VFreebusy by DTSTART. Used by JulianPtrArray::QuickSort method. + * @param a first VFreebusy + * @param b second VFreebusy + * + * @return a.getDTSTART().compareTo(b.getDTSTART()) + */ + static int CompareVFreebusyByDTStart(const void * a, const void * b); + +private: + UnicodeString m_sMethod; + + /** used for initial parse only to calculate first DTEnd, then discarded */ + Julian_Duration * m_TempDuration; + + /* -- MEMBERS -- */ + JulianPtrArray * m_AttendeesVctr; + JulianPtrArray * m_CommentVctr; + JulianPtrArray * m_ContactVctr; /* TEXT OR URL */ + /*ICalProperty * m_Created;*/ + /*ICalProperty * m_Duration;*/ + ICalProperty * m_DTEnd; + ICalProperty * m_DTStart; + ICalProperty * m_DTStamp; + JulianPtrArray * m_FreebusyVctr; + ICalProperty * m_LastModified; + ICalProperty * m_Organizer; + /*ICalProperty * m_RequestStatus;*/ + JulianPtrArray * m_RequestStatusVctr; + /*JulianPtrArray * m_RelatedToVctr;*/ + ICalProperty * m_Sequence; + ICalProperty * m_UID; + + /*JulianPtrArray * m_URLVctr;*/ + ICalProperty * m_URL; + + JulianPtrArray * m_XTokensVctr; + /*NSCalendar m_Parent;*/ + + JLog * m_Log; + +}; + +#endif /* __VFREEBUSY_H_ */ + diff --git a/calendar/modules/core/ical/inc/vjournal.h b/calendar/modules/core/ical/inc/vjournal.h new file mode 100644 index 00000000000..933f8300076 --- /dev/null +++ b/calendar/modules/core/ical/inc/vjournal.h @@ -0,0 +1,244 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +/* + * vjournal.h + * John Sun + * 4/23/98 10:24:32 AM + */ +#ifndef __VJOURNAL_H_ +#define __VJOURNAL_H_ + +#include "datetime.h" +#include "ptrarray.h" +#include "tmbevent.h" +#include "jlog.h" +#include "nscalcoreicalexp.h" + +class NS_CAL_CORE_ICAL VJournal: public TimeBasedEvent +{ +private: + /*----------------------------- + ** MEMBERS + **---------------------------*/ + /*----------------------------- + ** PRIVATE METHODS + **---------------------------*/ + + /** + * store the data, depending on property name, property value + * parameter names, parameter values, and the current line. + * If this method returns FALSE, property not valid. + * + * @param strLine current line to process + * @param propName name of property + * @param propVal value of property + * @param parameters property's parameters + * @param vTimeZones vector of timezones + * @return TRUE if property handled, FALSE otherwise + */ + t_bool storeData(UnicodeString & strLine, + UnicodeString & propName, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones); + + /** + * Sets default data. Currently does following: + * 1) Sets DTEnd to correct value, depending on DURATION, DTSTART + * (see spec on rules) + * 2) Sets TRANSP to TRANSPARENT if anniversary event + */ + void selfCheck(); + + /** + * Copy constructor. + * @param that VJournal to copy. + */ + VJournal(VJournal & that); + +public: + /*----------------------------- + ** CONSTRUCTORS and DESTRUCTORS + **---------------------------*/ + + /** + * Constructor. Create VJournal with initial log file set to initLog. + * @param initLog initial log file pointer + */ + VJournal(JLog * initLog = 0); + + /** + * Destructor. + */ + ~VJournal(); + + /* -- Start of ICALComponent interface -- */ + + /** + * The parse method is the standard interface for ICalComponent + * subclasses to parse from an ICalReader object + * and from the ITIP method type (i.e. PUBLISH, REQUEST, CANCEL, etc.). + * The method type can be set to \"\" if there is no method to be loaded. + * Also accepts a vector of VTimeZone objects to apply to + * the DateTime properties of the component. + * 4-2-98: Added bIgnoreBeginError. If desired to start parsing in Component level, + * it is useful to ignore first "BEGIN:". Setting bIgnoreBeginError to TRUE allows for + * this. + * + * @param brFile ICalReader to load from + * @param sType name of component (VJOURNAL) + * @param parseStatus return parse error status string (normally return "OK") + * @param vTimeZones vector of VTimeZones to apply to datetimes + * @param bIgnoreBeginError TRUE = ignore first "BEGIN:VJOURNAL", FALSE otherwise + * @param encoding the encoding of the stream, default is 7bit. + * + * @return parse error status string (parseStatus) + */ + UnicodeString & parse(ICalReader * brFile, UnicodeString & sMethod, + UnicodeString & parseStatus, JulianPtrArray * vTimeZones = 0, + t_bool bIgnoreBeginError = FALSE, + JulianUtility::MimeEncoding encoding = JulianUtility::MimeEncoding_7bit); + + /** + * Returns a clone of this object + * @param initLog log file to write errors to + * + * @return clone of this object + */ + virtual ICalComponent * clone(JLog * initLog); + + /** + * Return TRUE if component is valid, FALSE otherwise + * + * @return TRUE if is valid, FALSE otherwise + */ + t_bool isValid(); + + /** + * Print all contents of ICalComponent to human-readable string. + * + * @return string containing human-readable format of ICalComponent + */ + virtual UnicodeString toString(); + + /** + * Depending on character passed in, returns a string that represents + * the ICAL export string of that property that the character represents, if + * other paramaters not null, then print out information is filtered in several ways + * Attendee print out can be filtered so that only attendee with certain name is printed + * also, can print out the relevant attendees in a delegation message + * (ie. owner, delegate-to, delegate-from) + * + * @param c char of what property to print + * @param sFilterAttendee name of attendee to print + * @param bDelegateRequest TRUE if a delegate request, FALSE if not + * @return ICAL export format of that property + */ + virtual UnicodeString formatChar(t_int32 c, + UnicodeString sFilterAttendee, t_bool delegateRequest = FALSE); + + /** + * convert a character to the content of a property in string + * human-readable format + * @param c a character represents a property + * @param dateFmt for formatting datetimes + * + * @return property in human-readable string + */ + virtual UnicodeString toStringChar(t_int32 c, UnicodeString & dateFmt); + + /** + * Returns the ICAL_COMPONENT enumeration value of this ICalComponent. + * Each ICalComponent subclass must return a unique ICAL_COMPONENT value. + * + * @return ICAL_COMPONENT value of this component + */ + virtual ICAL_COMPONENT GetType() const { return ICAL_COMPONENT_VJOURNAL; } + + /* -- End of ICALComponent interface -- */ + + /** + * Overridden virtual method used as wrapper to ICalComponent::format method. + * @param strFmt iCal format string + * @param sFilterAttendee attendee to filter + * @param delegateRequest delegate request = TRUE, FALSE otherwise + * + * @return output iCal formatted export string + */ + virtual UnicodeString formatHelper(UnicodeString & strFmt, + UnicodeString sFilterAttendee, t_bool delegateRequest = FALSE); + + /** + * Helper method. Overriden virtual method. Used by subclasses to + * populate recurrence-dependent data. For example, a recurring + * VJournal needs to have DTEnd calculated from recurring + * DTStart. VJournal will overwrite method set DTEnd correctly. + * Abstract difference() method is used to calculate ldiff. + * Need to pass vector of RDate periods in case end value must + * be adjusted in RDATE is a PERIOD value. + * @param start recurrence instance starting time + * @param ldiff abstract difference value + * @param vPer vector of RDate periods + */ + void populateDatesHelper(DateTime start, Date ldiff, JulianPtrArray * vPer); + + /* overridden message methods */ + virtual UnicodeString cancelMessage(); + virtual UnicodeString requestMessage(); + virtual UnicodeString requestRecurMessage(); + virtual UnicodeString counterMessage(); + virtual UnicodeString declineCounterMessage(); + virtual UnicodeString addMessage(); + virtual UnicodeString refreshMessage(UnicodeString sAttendeeFilter); + virtual UnicodeString allMessage(); + virtual UnicodeString replyMessage(UnicodeString sAttendeeFilter); + virtual UnicodeString publishMessage(); + virtual UnicodeString publishRecurMessage(); + + /** + * Overridden method. Calculate difference from start, end time + * For VJournal, this would 0. + * + * @return virtual Date + */ + Date difference(); + + /** + * Sets default human-readable event format pattern to s. + * @param s new event format pattern + */ + static void setDefaultFmt(UnicodeString s); + + /*----------------------------- + ** ACCESSORS (GET AND SET) + **---------------------------*/ + /*----------------------------- + ** UTILITIES + **---------------------------*/ + + virtual void updateComponentHelper(TimeBasedEvent * updatedComponent); + + /*----------------------------- + ** STATIC METHODS + **---------------------------*/ + /*----------------------------- + ** OVERLOADED OPERATORS + **---------------------------*/ +}; + +#endif /* __VJOURNAL_H_ */ + diff --git a/calendar/modules/core/ical/inc/vtimezne.h b/calendar/modules/core/ical/inc/vtimezne.h new file mode 100644 index 00000000000..92cea8cf91a --- /dev/null +++ b/calendar/modules/core/ical/inc/vtimezne.h @@ -0,0 +1,317 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +/* + * vtimezne.h + * John Sun + * 2/24/98 2:28:21 PM + */ + +#ifndef __VTIMEZONE_H_ +#define __VTIMEZONE_H_ + +#include +#include +#include + +#include "icalcomp.h" +#include "tzpart.h" +#include "jlog.h" + +class VTimeZone : public ICalComponent +{ +private: +#if 0 + + /** + * Default constructor. Hide from clients. + */ + VTimeZone(); +#endif +protected: + + /** + * Copy constructor. + * @param that VTimeZone to copy + */ + VTimeZone(VTimeZone & that); + +public: + + /** + * Constructor. Creates VTimeZone with initial log file initLog. + * @param initLog initial log file pointer + */ + VTimeZone(JLog * initLog = 0); + + /** + * Destructor. + */ + ~VTimeZone(); + + /* -- Start of ICALComponent interface -- */ + + /** + * The parse method is the standard interface for ICalComponent + * subclasses to parse from an ICalReader object + * and from the ITIP method type (i.e. PUBLISH, REQUEST, CANCEL, etc.). + * The method type can be set to \"\" if there is no method to be loaded. + * Also accepts a vector of VTimeZone objects to apply to + * the DateTime properties of the component. + * 4-2-98: Added bIgnoreBeginError. If desired to start parsing in Component level, + * it is useful to ignore first "BEGIN:". Setting bIgnoreBeginError to TRUE allows for + * this. + * + * @param brFile ICalReader to load from + * @param sType name of component (VTIMEZONE) + * @param parseStatus return parse error status string (normally return "OK") + * @param vTimeZones vector of VTimeZones to apply to datetimes + * @param bIgnoreBeginError TRUE = ignore first "BEGIN:VTIMEZONE", FALSE otherwise + * @param encoding the encoding of the stream, default is 7bit. + * + * @return parse error status string (parseStatus) + */ + virtual UnicodeString & parse(ICalReader * brFile, UnicodeString & sType, + UnicodeString & parseStatus, JulianPtrArray * vTimeZones = 0, + t_bool bIgnoreBeginError = FALSE, + JulianUtility::MimeEncoding encoding = JulianUtility::MimeEncoding_7bit); + + /** + * Returns a clone of this object + * @param initLog log file to write errors to + * + * @return clone of this object + */ + virtual ICalComponent * clone(JLog * initLog); + + /** + * Return TRUE if component is valid, FALSE otherwise + * + * @return TRUE if is valid, FALSE otherwise + */ + virtual t_bool isValid(); + + /** + * Print all contents of ICalComponent to iCal export format. + * + * @return string containing iCal export format of ICalComponent + */ + virtual UnicodeString toICALString(); + + /** + * Print all contents of ICalComponent to iCal export format, depending + * on attendee name, attendee delegated-to, and where to include recurrence-id or not + * + * @param method method name (REQUEST,PUBLISH, etc.) + * @param name attendee name to filter with + * @param isRecurring TRUE = no recurrenceid, FALSE = include recurrenceid + * + * @return string containing iCal export format of ICalComponent + */ + virtual UnicodeString toICALString(UnicodeString method, UnicodeString name, + t_bool isRecurring); + + /** + * Print all contents of ICalComponent to human-readable string. + * + * @return string containing human-readable format of ICalComponent + */ + virtual UnicodeString toString(); + + /** + * Depending on character passed in, returns a string that represents + * the ICAL export string of that property that the character represents, if + * other paramaters not null, then print out information is filtered in several ways + * Attendee print out can be filtered so that only attendee with certain name is printed + * also, can print out the relevant attendees in a delegation message + * (ie. owner, delegate-to, delegate-from) + * + * @param c char of what property to print + * @param sFilterAttendee name of attendee to print + * @param bDelegateRequest TRUE if a delegate request, FALSE if not + * @return ICAL export format of that property + */ + virtual UnicodeString formatChar(t_int32 c, UnicodeString sFilterAttendee, + t_bool delegateRequest = FALSE); + + /** + * convert a character to the content of a property in string + * human-readable format + * @param c a character represents a property + * @param dateFmt for formatting datetimes + * + * @return property in human-readable string + */ + virtual UnicodeString toStringChar(t_int32 c, UnicodeString & dateFmt); + + /** + * Returns the ICAL_COMPONENT enumeration value of this ICalComponent. + * Each ICalComponent subclass must return a unique ICAL_COMPONENT value. + * + * @return ICAL_COMPONENT value of this component + */ + virtual ICAL_COMPONENT GetType() const { return ICAL_COMPONENT_VTIMEZONE; } + + /** + * Update the private property data-members with updatedComponent's + * property data-members. + * Usually, overwriting data-members should only occur if updatedComponent + * is more recent than the current component. + * Return TRUE if component was changed, FALSE otherwise + * @param ICalComponent * updatedComponent + * + * @return virtual t_bool + */ + virtual t_bool updateComponent(ICalComponent * updatedComponent); + + /* -- End of ICALComponent interface -- */ + + /* -- GETTERS AND SETTERS -- */ + + /** + * Return the STANDARD TimeZone part of this VTimeZone. + * + * @return ptr to STANDARD TZPart + */ + TZPart * getStandardPart(); + + /** + * Return the DAYLIGHT TimeZone part of this VTimeZone. + * + * @return ptr to DAYLIGHT TZPart + */ + TZPart * getDaylightPart(); + + + /** + * Return pointer to vector of TZParts + * + * @return pointer to vector of TZParts. + */ + JulianPtrArray * getTZParts() const { return m_TZPartVctr; }; + + /* TZPART */ + void addTZPart(TZPart * part); + TZPart * getPart(UnicodeString & u); + + /* TZID */ + UnicodeString getTZID() const; + void setTZID(UnicodeString s, JulianPtrArray * parameters = 0); + ICalProperty * getTZIDProperty() const { return m_TZID; } + + /* LastModified */ + DateTime getLastModified() const; + void setLastModified(DateTime s, JulianPtrArray * parameters = 0); + ICalProperty * getLastModifiedProperty() const { return m_LastModified; } + + /* TZURL */ + UnicodeString getTZURL() const; + void setTZURL(UnicodeString s, JulianPtrArray * parameters = 0); + ICalProperty * getTZURLProperty() const { return m_TZURL; } + + /* XTOKENS: NOTE: a vector of strings, not a vector of ICalProperties */ + void addXTokens(UnicodeString s); + JulianPtrArray * getXTokens() const { return m_XTokensVctr; } + + /** + * Given vector of timezones, search for VTimeZone with TZID equal to id. + * Return 0 if not found. + * @param id TZID to look for + * @param timezones vector of timezones to search through + * + * @return first matching VTimeZone in vector, 0 if not found + */ + static VTimeZone * getTimeZone(UnicodeString & id, JulianPtrArray * timezones); + + + /** + * Given a DateTime string, a vector of timezones, and a vector of + * ICalParameters, apply a timezone to the string if there is a TZID + * in the parameters vector. + * For example, if time = "19971110T112233", timezones has a EST timezone, + * and TZID = EST, then the method would return the datetime for time with + * the EST timezone applied to it. + * @param time datetime string to apply timezone to + * @param vTimeZones vector of timezones + * @param parameters parameters to search for TZID + * + * @return DateTime representing time with timezone applied to it. + */ + static DateTime DateTimeApplyTimeZone(UnicodeString & time, + JulianPtrArray * vTimeZones, JulianPtrArray * parameters); + + /** + * Return the libnls TimeZone that represents this VTimeZone object. + * @return pointer to TimeZone + */ + TimeZone * getNLSTimeZone() const { return (TimeZone *) &*m_NLSTimeZone; } + +private: + + /** + * selfcheck data-members, and calls createNLSTimeZone(). + */ + void selfCheck(); + + /** + * Creates NLS TimeZone from start month,day,week,time,until. + * TODO: possible bug, may need to call everytime before calling getNLSTimeZone(). + */ + void createNLSTimeZone(); + + /** + * store the data, depending on property name, property value + * parameter names, parameter values, and the current line. + * + * @param strLine current line to process + * @param propName name of property + * @param propVal value of property + * @param parameters property's parameters + */ + void storeData(UnicodeString & strLine, UnicodeString & propName, + UnicodeString & propVal, JulianPtrArray * parameters); + + /** + * Helper method called by updateComponent to actually replace + * the property data-members with updatedComponent's data-members. + * @param VTimeZone * updatedComponent + * + * @return virtual void + */ + void updateComponentHelper(VTimeZone * updatedComponent); + + /* whether VTimeZone has more that two parts, currently must + * have exactly two parts (DAYLIGHT AND STANDARD) + */ + static t_bool ms_bMORE_THAN_TWO_TZPARTS; + + /* -- MEMBERS -- */ + /*TimeZone * m_NLSTimeZone;*/ + SimpleTimeZone *m_NLSTimeZone; + + JulianPtrArray * m_TZPartVctr; + ICalProperty * m_TZID; + ICalProperty * m_LastModified; + ICalProperty * m_TZURL; + JulianPtrArray * m_XTokensVctr; /* TEXT */ + + JLog * m_Log; +}; + +#endif /* __VTIMEZONE_H_ */ + diff --git a/calendar/modules/core/ical/inc/vtodo.h b/calendar/modules/core/ical/inc/vtodo.h new file mode 100644 index 00000000000..ed20b299fd3 --- /dev/null +++ b/calendar/modules/core/ical/inc/vtodo.h @@ -0,0 +1,348 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +/* + * vtodo.h + * John Sun + * 4/22/98 3:25:47 PM + */ +#ifndef __VTODO_H_ +#define __VTODO_H_ + +#include "datetime.h" +#include "ptrarray.h" +#include "tmbevent.h" +#include "jlog.h" +#include "nscalcoreicalexp.h" + +class NS_CAL_CORE_ICAL VTodo : public TimeBasedEvent +{ +private: + /*----------------------------- + ** MEMBERS + **---------------------------*/ + + /* Due of first instance of a recurrence */ + DateTime m_origDue; + + /* Due of my instance of a recurrence */ + DateTime m_origMyDue; + + /** used for initial parse only to calculate first Due, then discarded */ + Julian_Duration * m_TempDuration; + + /*------------------------------------------------- + * DATA MEMBER (to augment TimeBasedEvent) + *------------------------------------------------*/ + + ICalProperty * m_Completed; /* DATETIME */ + ICalProperty * m_Due; /* DATETIME */ + ICalProperty * m_GEO; /* geographic position (two floats)*/ + ICalProperty * m_Location; /* TEXT */ + ICalProperty * m_PercentComplete; /* INTEGER [0-100] */ + ICalProperty * m_Priority; /* INTEGER >= 0 */ + JulianPtrArray * m_ResourcesVctr; /* TEXT */ + + /*----------------------------- + ** PRIVATE METHODS + **---------------------------*/ + + /** + * store the data, depending on property name, property value + * parameter names, parameter values, and the current line. + * If this method returns FALSE, property not valid. + * + * @param strLine current line to process + * @param propName name of property + * @param propVal value of property + * @param parameters property's parameters + * @param vTimeZones vector of timezones + * @return TRUE if property handled, FALSE otherwise + */ + t_bool storeData(UnicodeString & strLine, + UnicodeString & propName, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones); +public: + typedef void (VTodo::*SetOp) (UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones); + + void storeCompleted(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones); + void storeDue(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones); + void storeDuration(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones); + void storeGEO(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones); + void storeLocation(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones); + void storePercentComplete(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones); + void storePriority(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones); + void storeResources(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones); + + void ApplyStoreOp(void (VTodo::*op) (UnicodeString & strLine, + UnicodeString & propVal, JulianPtrArray * parameters, JulianPtrArray * vTimeZones), + UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones) + { + (this->*op)(strLine, propVal, parameters, vTimeZones); + } +private: + + /** + * Sets default data. Currently does following: + * 1) Sets DTEnd to correct value, depending on DURATION, DTSTART + * (see spec on rules) + * 2) Sets TRANSP to TRANSPARENT if anniversary event + */ + void selfCheck(); + + /** + * Copy constructor. + * @param that VTodo to copy. + */ + VTodo(VTodo & that); + +public: + + /*----------------------------- + ** CONSTRUCTORS and DESTRUCTORS + **---------------------------*/ + + /** + * Constructor. Create VTodo with initial log file set to initLog. + * @param initLog initial log file pointer + */ + VTodo(JLog * initLog = 0); + + /** + * Destructor. + */ + ~VTodo(); + + /* -- Start of ICALComponent interface -- */ + + /** + * The parse method is the standard interface for ICalComponent + * subclasses to parse from an ICalReader object + * and from the ITIP method type (i.e. PUBLISH, REQUEST, CANCEL, etc.). + * The method type can be set to \"\" if there is no method to be loaded. + * Also accepts a vector of VTimeZone objects to apply to + * the DateTime properties of the component. + * 4-2-98: Added bIgnoreBeginError. If desired to start parsing in Component level, + * it is useful to ignore first "BEGIN:". Setting bIgnoreBeginError to TRUE allows for + * this. + * + * @param brFile ICalReader to load from + * @param sType name of component (VTODO) + * @param parseStatus return parse error status string (normally return "OK") + * @param vTimeZones vector of VTimeZones to apply to datetimes + * @param bIgnoreBeginError TRUE = ignore first "BEGIN:VTODO", FALSE otherwise + * @param encoding the encoding of the stream, default is 7bit. + * + * @return parse error status string (parseStatus) + */ + UnicodeString & parse(ICalReader * brFile, UnicodeString & sMethod, + UnicodeString & parseStatus, JulianPtrArray * vTimeZones = 0, + t_bool bIgnoreBeginError = FALSE, + JulianUtility::MimeEncoding encoding = JulianUtility::MimeEncoding_7bit); + + /** + * Returns a clone of this object + * @param initLog log file to write errors to + * + * @return clone of this object + */ + virtual ICalComponent * clone(JLog * initLog); + + /** + * Return TRUE if component is valid, FALSE otherwise + * + * @return TRUE if is valid, FALSE otherwise + */ + t_bool isValid(); + + /** + * Print all contents of ICalComponent to human-readable string. + * + * @return string containing human-readable format of ICalComponent + */ + virtual UnicodeString toString(); + + /** + * Depending on character passed in, returns a string that represents + * the ICAL export string of that property that the character represents, if + * other paramaters not null, then print out information is filtered in several ways + * Attendee print out can be filtered so that only attendee with certain name is printed + * also, can print out the relevant attendees in a delegation message + * (ie. owner, delegate-to, delegate-from) + * + * @param c char of what property to print + * @param sFilterAttendee name of attendee to print + * @param bDelegateRequest TRUE if a delegate request, FALSE if not + * @return ICAL export format of that property + */ + virtual UnicodeString formatChar(t_int32 c, + UnicodeString sFilterAttendee, t_bool delegateRequest = FALSE); + + /** + * convert a character to the content of a property in string + * human-readable format + * @param c a character represents a property + * @param dateFmt for formatting datetimes + * + * @return property in human-readable string + */ + virtual UnicodeString toStringChar(t_int32 c, UnicodeString & dateFmt); + + /** + * Returns the ICAL_COMPONENT enumeration value of this ICalComponent. + * Each ICalComponent subclass must return a unique ICAL_COMPONENT value. + * + * @return ICAL_COMPONENT value of this component + */ + virtual ICAL_COMPONENT GetType() const { return ICAL_COMPONENT_VTODO ; } + + /* -- End of ICALComponent interface -- */ + + /** + * Overridden virtual method used as wrapper to ICalComponent::format method. + * @param strFmt iCal format string + * @param sFilterAttendee attendee to filter + * @param delegateRequest delegate request = TRUE, FALSE otherwise + * + * @return output iCal formatted export string + */ + virtual UnicodeString formatHelper(UnicodeString & strFmt, + UnicodeString sFilterAttendee, t_bool delegateRequest = FALSE); + + /** + * Helper method. Overriden virtual method. Used by subclasses to + * populate recurrence-dependent data. For example, a recurring + * VTodo needs to have DTEnd calculated from recurring + * DTStart. VTodo will overwrite method set DTEnd correctly. + * Abstract difference() method is used to calculate ldiff. + * Need to pass vector of RDate periods in case end value must + * be adjusted in RDATE is a PERIOD value. + * @param start recurrence instance starting time + * @param ldiff abstract difference value + * @param vPer vector of RDate periods + */ + void populateDatesHelper(DateTime start, Date ldiff, JulianPtrArray * vPer); + + /* overridden message methods */ + virtual UnicodeString cancelMessage(); + virtual UnicodeString requestMessage(); + virtual UnicodeString requestRecurMessage(); + virtual UnicodeString counterMessage(); + virtual UnicodeString declineCounterMessage(); + virtual UnicodeString addMessage(); + virtual UnicodeString refreshMessage(UnicodeString sAttendeeFilter); + virtual UnicodeString allMessage(); + virtual UnicodeString replyMessage(UnicodeString sAttendeeFilter); + virtual UnicodeString publishMessage(); + virtual UnicodeString publishRecurMessage(); + + /** + * Overridden method. Calculate difference from start, end time + * For VTodo, this would be Due - DTStart. + * + * @return virtual Date + */ + Date difference(); + + /** + * Sets default human-readable event format pattern to s. + * @param s new event format pattern + */ + static void setDefaultFmt(UnicodeString s); + + + /*----------------------------- + ** ACCESSORS (GET AND SET) + **---------------------------*/ + + /* COMPLETED */ + DateTime getCompleted() const; + void setCompleted(DateTime s, JulianPtrArray * parameters = 0); + ICalProperty * getCompletedProperty() const { return m_Completed; } + + /* DUE */ + DateTime getDue() const; + void setDue(DateTime s, JulianPtrArray * parameters = 0); + ICalProperty * getDueProperty() const { return m_Due; } + + /* DURATION */ + Julian_Duration getDuration() const; + void setDuration(Julian_Duration s, JulianPtrArray * parameters = 0); + /*ICalProperty * getDurationProperty() const { return m_Duration; }*/ + + /* GEO */ + UnicodeString getGEO() const; + void setGEO(UnicodeString s, JulianPtrArray * parameters = 0); + ICalProperty * getGEOProperty() const { return m_GEO; } + + /* LOCATION */ + UnicodeString getLocation() const; + void setLocation(UnicodeString s, JulianPtrArray * parameters = 0); + ICalProperty * getLocationProperty() const { return m_Location; } + + /* PERCENT-COMPLETE */ + virtual t_int32 getPercentComplete() const; + void setPercentComplete(t_int32 i, JulianPtrArray * parameters = 0); + ICalProperty * getPercentCompleteProperty() const { return m_PercentComplete; } + + /* PRIORITY */ + t_int32 getPriority() const; + void setPriority(t_int32 i, JulianPtrArray * parameters = 0); + ICalProperty * getPriorityProperty() const { return m_Priority; } + + /* RESOURCES */ + void addResources(UnicodeString s, JulianPtrArray * parameters = 0); + void addResourcesProperty(ICalProperty * prop); + JulianPtrArray * getResources() const { return m_ResourcesVctr; } + void addResourcesPropertyVector(UnicodeString & propVal, JulianPtrArray * parameters); + + /* MYORIGDUE */ + void setMyOrigDue(DateTime d) { m_origMyDue = d; } + DateTime getMyOrigDue() { return m_origMyDue; } + + /* ORIGDUE */ + void setOrigDue(DateTime d) { m_origDue = d; } + DateTime getOrigDue() { return m_origDue; } + + + /*----------------------------- + ** UTILITIES + **---------------------------*/ + + virtual void updateComponentHelper(TimeBasedEvent * updatedComponent); + + /*----------------------------- + ** STATIC METHODS + **---------------------------*/ + /*----------------------------- + ** OVERLOADED OPERATORS + **---------------------------*/ +}; + +#endif /* __VTODO_H_ */ + diff --git a/calendar/modules/core/ical/manifest.mn b/calendar/modules/core/ical/manifest.mn new file mode 100644 index 00000000000..e69de29bb2d diff --git a/calendar/modules/core/ical/src/Makefile b/calendar/modules/core/ical/src/Makefile new file mode 100644 index 00000000000..e69de29bb2d diff --git a/calendar/modules/core/ical/src/attendee.cpp b/calendar/modules/core/ical/src/attendee.cpp new file mode 100644 index 00000000000..2abb5aae25f --- /dev/null +++ b/calendar/modules/core/ical/src/attendee.cpp @@ -0,0 +1,1140 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +// attendee.cpp +// John Sun +// 3:21 PM February 6 1998 + +#include "stdafx.h" +#include "jdefines.h" + +#include "icalcomp.h" +#include "attendee.h" +#include "jutility.h" +#include "unistrto.h" +#include "jlog.h" +#include "keyword.h" +#include "uri.h" + +//-------------------------------------------------------------------- +const t_int32 Attendee::ms_iDEFAULT_ROLE = ROLE_REQ_PARTICIPANT; //ROLE_ATTENDEE; +const t_int32 Attendee::ms_iDEFAULT_TYPE= TYPE_INDIVIDUAL; //TYPE_UNKNOWN; +const t_int32 Attendee::ms_iDEFAULT_STATUS= STATUS_NEEDSACTION; +const t_int32 Attendee::ms_iDEFAULT_RSVP= RSVP_FALSE; +const t_int32 Attendee::ms_iDEFAULT_EXPECT= EXPECT_FYI; + +const t_int32 Attendee::ms_cAttendeeName = 'N'; +const t_int32 Attendee::ms_cAttendeeRole = 'R'; +const t_int32 Attendee::ms_cAttendeeStatus = 'S'; +const t_int32 Attendee::ms_cAttendeeRSVP = 'V'; +const t_int32 Attendee::ms_cAttendeeType = 'T'; +const t_int32 Attendee::ms_cAttendeeExpect = 'E'; +const t_int32 Attendee::ms_cAttendeeDelegatedTo = 'D'; +const t_int32 Attendee::ms_cAttendeeDelegatedFrom = 'd'; +const t_int32 Attendee::ms_cAttendeeMember = 'M'; +const t_int32 Attendee::ms_cAttendeeDir = 'l'; // 'el' +const t_int32 Attendee::ms_cAttendeeSentBy = 's'; +const t_int32 Attendee::ms_cAttendeeCN = 'C'; +const t_int32 Attendee::ms_cAttendeeLanguage = 'm'; +const t_int32 Attendee::ms_cAttendeeDisplayName = 'z'; +// ---- END OF STATIC DATA ---- // +//--------------------------------------------------------------------- + +t_bool Attendee::isValidStatus(ICalComponent::ICAL_COMPONENT compType, + Attendee::STATUS status) +{ + if (compType == ICalComponent::ICAL_COMPONENT_VEVENT) + { + if (status >= STATUS_NEEDSACTION && status <= STATUS_DELEGATED) + return TRUE; + else return FALSE; + } + else if (compType == ICalComponent::ICAL_COMPONENT_VTODO) + { + if (status >= STATUS_NEEDSACTION && status <= STATUS_INPROCESS) + return TRUE; + else return FALSE; + } + else + { + // for VJournal and VFreebusy + if (status >= STATUS_NEEDSACTION && status <= STATUS_DECLINED) + return TRUE; + else return FALSE; + } +} + +//--------------------------------------------------------------------- + +Attendee::Attendee() +{ + // private, NEVER use + PR_ASSERT(FALSE); +} + +//--------------------------------------------------------------------- + +Attendee::Attendee(ICalComponent::ICAL_COMPONENT componentType, JLog * initLog) +: m_vsMember(0), m_vsDelegatedTo(0), m_vsDelegatedFrom(0), + m_iRole(-1), m_iType(-1), m_iStatus(-1), m_iRSVP(-1), + m_iExpect(-1), m_Log(initLog), m_ComponentType(componentType) +{ +} + +//--------------------------------------------------------------------- + +Attendee::Attendee(Attendee & that) +: m_vsMember(0), m_vsDelegatedTo(0), m_vsDelegatedFrom(0) +{ + t_int32 i, size; + + m_iRole = that.m_iRole; + m_iType = that.m_iType; + m_iStatus = that.m_iStatus; + m_iRSVP = that.m_iRSVP; + m_iExpect = that.m_iExpect; + + m_CN = that.m_CN; + m_Language = that.m_Language; + m_SentBy = that.m_SentBy; + m_Dir = that.m_Dir; + + m_ComponentType = that.m_ComponentType; + + m_sName = that.m_sName; + + if (that.m_vsMember != 0) + { + m_vsMember = new JulianPtrArray(); PR_ASSERT(m_vsMember != 0); + if (m_vsMember != 0) + { + size = that.m_vsMember->GetSize(); + for (i = 0; i < size; i++) + { + addMember(*((UnicodeString *) that.m_vsMember->GetAt(i))); + } + } + } + + if (that.m_vsDelegatedTo != 0) + { + m_vsDelegatedTo = new JulianPtrArray(); PR_ASSERT(m_vsDelegatedTo != 0); + if (m_vsDelegatedTo != 0) + { + size = that.m_vsDelegatedTo->GetSize(); + for (i = 0; i < size; i++) + { + addDelegatedTo(*((UnicodeString *) that.m_vsDelegatedTo->GetAt(i))); + } + } + } + + if (that.m_vsDelegatedFrom != 0) + { + m_vsDelegatedFrom = new JulianPtrArray(); PR_ASSERT(m_vsDelegatedFrom != 0); + if (m_vsDelegatedFrom != 0) + { + size = that.m_vsDelegatedFrom->GetSize(); + for (i = 0; i < size; i++) + { + addDelegatedFrom(*((UnicodeString *) that.m_vsDelegatedFrom->GetAt(i))); + } + } + } + +} + +//--------------------------------------------------------------------- + +Attendee::~Attendee() +{ + if (m_vsDelegatedTo != 0) + { + ICalComponent::deleteUnicodeStringVector(m_vsDelegatedTo); + delete m_vsDelegatedTo; m_vsDelegatedTo = 0; + } + if (m_vsDelegatedFrom != 0) + { + ICalComponent::deleteUnicodeStringVector(m_vsDelegatedFrom); + delete m_vsDelegatedFrom; m_vsDelegatedFrom = 0; + } + if (m_vsMember != 0) + { + ICalComponent::deleteUnicodeStringVector(m_vsMember); + delete m_vsMember; m_vsMember = 0; + } +} + +//--------------------------------------------------------------------- + +ICalProperty * +Attendee::clone(JLog * initLog) +{ + m_Log = initLog; + return (ICalProperty *) new Attendee(*this); +} + +//--------------------------------------------------------------------- + +Attendee * Attendee::getDefault(ICalComponent::ICAL_COMPONENT compType, + JLog * initLog) +{ + Attendee * a = new Attendee(compType, initLog); PR_ASSERT(a != 0); + if (a != 0) + { + a->setRole((Attendee::ROLE) ms_iDEFAULT_ROLE); + a->setType((Attendee::TYPE) ms_iDEFAULT_TYPE); + a->setStatus((Attendee::STATUS) ms_iDEFAULT_STATUS); + a->setRSVP((Attendee::RSVP) ms_iDEFAULT_RSVP); + a->setExpect((Attendee::EXPECT) ms_iDEFAULT_EXPECT); + } + return a; +} + +//--------------------------------------------------------------------- + +void Attendee::parse(UnicodeString & propVal, + JulianPtrArray * parameters) +{ + t_int32 i; + ICalParameter * param; + UnicodeString pName, pVal; + if (propVal.size() == 0) + { + return; + } + setName(propVal); + if (parameters != 0) + { + for (i = 0; i < parameters->GetSize(); i++) + { + param = (ICalParameter *) parameters->GetAt(i); + + setParam(param->getParameterName(pName), + param->getParameterValue(pVal)); + } + } + selfCheck(); +} + +//--------------------------------------------------------------------- +void Attendee::addParamValList(UnicodeString & paramValList, t_int32 hashCode) +{ + UnicodeStringTokenizer * stMult = new UnicodeStringTokenizer(paramValList, + JulianKeyword::Instance()->ms_sCOMMA_SYMBOL); + PR_ASSERT(stMult != 0); + if (stMult != 0) + { + UnicodeString u; + UnicodeString uNext; + ErrorCode status = ZERO_ERROR; + while (stMult->hasMoreTokens()) + { + if (uNext.size() == 0) + u = stMult->nextToken(u, status); + else + u = uNext; + if ('\"' != u[(TextOffset) (u.size() - 1)]) + { + while (stMult->hasMoreTokens()) + { + uNext = stMult->nextToken(uNext, status); + if ('\"' != uNext[(TextOffset) 0]) + { + u += ','; + u += uNext; + uNext = ""; + } + else + break; + } + } + JulianUtility::stripDoubleQuotes(u); // double quote property + + if (JulianKeyword::Instance()->ms_ATOM_DELEGATED_TO == hashCode) + { + addDelegatedTo(u); + } + else if (JulianKeyword::Instance()->ms_ATOM_DELEGATED_FROM == hashCode) + { + addDelegatedFrom(u); + } + else + { + addMember(u); + } + } + delete stMult; stMult = 0; + } +} + +//--------------------------------------------------------------------- + +void Attendee::setParam(UnicodeString & paramName, + UnicodeString & paramVal) +{ + t_int32 i; + + //if (FALSE) TRACE("(%s, %s)\r\n", paramName.toCString(""), paramVal.toCString("")); + if (paramName.size() == 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iInvalidParameterName, + JulianKeyword::Instance()->ms_sATTENDEE, paramName, 200); + } + else + { + t_int32 hashCode = paramName.hashCode(); + + if (JulianKeyword::Instance()->ms_ATOM_ROLE == hashCode) + { + i = stringToRole(paramVal); + if (i < 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iInvalidParameterValue, + JulianKeyword::Instance()->ms_sATTENDEE, + paramName, paramVal, 200); + } + else + { + if (getRole() >= 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iDuplicatedParameter, + JulianKeyword::Instance()->ms_sATTENDEE, + paramName, 100); + } + setRole((Attendee::ROLE) i); + } + } + else if (JulianKeyword::Instance()->ms_ATOM_CUTYPE == hashCode) + { + i = stringToType(paramVal); + if (i < 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iInvalidParameterValue, + JulianKeyword::Instance()->ms_sATTENDEE, + paramName, paramVal, 200); + } + else + { + if (getType() >= 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iDuplicatedParameter, + JulianKeyword::Instance()->ms_sATTENDEE, + paramName, 100); + } + setType((Attendee::TYPE) i); + } + } + else if (JulianKeyword::Instance()->ms_ATOM_PARTSTAT == hashCode) + { + i = stringToStatus(paramVal); + if (i < 0 || !isValidStatus(m_ComponentType, (Attendee::STATUS) i)) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iInvalidParameterValue, + JulianKeyword::Instance()->ms_sATTENDEE, + paramName, paramVal, 200); + } + else + { + if (getStatus() >= 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iDuplicatedParameter, + JulianKeyword::Instance()->ms_sATTENDEE, + paramName, 100); + } + setStatus((Attendee::STATUS) i); + } + } + else if (JulianKeyword::Instance()->ms_ATOM_EXPECT == hashCode) + { + i = stringToExpect(paramVal); + if (i < 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iInvalidParameterValue, + JulianKeyword::Instance()->ms_sATTENDEE, + paramName, paramVal, 200); + } + else + { + if (getExpect() >= 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iDuplicatedParameter, + JulianKeyword::Instance()->ms_sATTENDEE, + paramName, 100); + } + setExpect((Attendee::EXPECT) i); + } + } + else if (JulianKeyword::Instance()->ms_ATOM_RSVP == hashCode) + { + i = stringToRSVP(paramVal); + if (i < 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iInvalidParameterValue, + JulianKeyword::Instance()->ms_sATTENDEE, + paramName, paramVal, 200); + } + else + { + if (getRSVP() >= 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iDuplicatedParameter, + JulianKeyword::Instance()->ms_sATTENDEE, + paramName, 100); + } + setRSVP((Attendee::RSVP) i); + } + } + else if (JulianKeyword::Instance()->ms_ATOM_DELEGATED_TO == hashCode) + { + addParamValList(paramVal, hashCode); + } + else if (JulianKeyword::Instance()->ms_ATOM_DELEGATED_FROM == hashCode) + { + addParamValList(paramVal, hashCode); + } + else if (JulianKeyword::Instance()->ms_ATOM_MEMBER == hashCode) + { + addParamValList(paramVal, hashCode); + } + + // Newer properties 3-23-98 (cn, sent-by (double-quote), dir (double-quote)) + else if (JulianKeyword::Instance()->ms_ATOM_CN == hashCode) + { + if (getCN().size() != 0) + { + if (m_Log) m_Log->logError(JulianLogErrorMessage::Instance()->ms_iDuplicatedParameter, + JulianKeyword::Instance()->ms_sATTENDEE, paramName, 100); + } + setCN(paramVal); + } + else if (JulianKeyword::Instance()->ms_ATOM_LANGUAGE == hashCode) + { + if (getLanguage().size() != 0) + { + if (m_Log) m_Log->logError(JulianLogErrorMessage::Instance()->ms_iDuplicatedParameter, + JulianKeyword::Instance()->ms_sATTENDEE, paramName, 100); + } + setLanguage(paramVal); + } + else if (JulianKeyword::Instance()->ms_ATOM_SENTBY == hashCode) + { + if (getSentBy().size() != 0) + { + if (m_Log) m_Log->logError(JulianLogErrorMessage::Instance()->ms_iDuplicatedParameter, + JulianKeyword::Instance()->ms_sATTENDEE, paramName, 100); + } + JulianUtility::stripDoubleQuotes(paramVal); // double quote property + setSentBy(paramVal); + } + else if (JulianKeyword::Instance()->ms_ATOM_DIR == hashCode) + { + if (getDir().size() != 0) + { + if (m_Log) m_Log->logError(JulianLogErrorMessage::Instance()->ms_iDuplicatedParameter, + JulianKeyword::Instance()->ms_sATTENDEE, paramName, 100); + } + JulianUtility::stripDoubleQuotes(paramVal); // double quote property + setDir(paramVal); + } + else if (ICalProperty::IsXToken(paramName)) + { + if (m_Log) m_Log->logError(JulianLogErrorMessage::Instance()->ms_iXTokenParamIgnored, + JulianKeyword::Instance()->ms_sATTENDEE, paramName, 100); + } + else + { + if (m_Log) m_Log->logError(JulianLogErrorMessage::Instance()->ms_iInvalidParameterName, + JulianKeyword::Instance()->ms_sATTENDEE, paramName, 200); + } + } +} + +//--------------------------------------------------------------------- + +UnicodeString & Attendee::toICALString(UnicodeString & out) +{ + out = ""; + //UnicodeString sName = getName(); + //UnicodeString sStatus; + //sStatus = statusToString(getStatus(), sStatus); + //JulianPtrArray * vsDelegatedTo = getDelegatedTo(); + //JulianPtrArray * vsDelegatedFrom = getDelegatedFrom(); + + if (getStatus() != STATUS_NEEDSACTION) + { +#if 0 + //if (sStatus.compareIgnoreCase(JulianKeyword::Instance()->ms_sNEEDSACTION) != 0) { + /* + if (vsDelegatedTo != NULL && vsDelegatedTo.contains(sName)) + return formatDoneDelegateFromOnly(); + else if (vsDelegatedFrom != null && vsDelegatedFrom.contains(sName)) + return formatDoneDelegateToOnly(); + else + */ +#endif + out = formatDoneAction(); + } + else + { +#if 0 + /* + if (vsDelegatedTo != null && vsDelegatedTo.contains(sName)) + return formatDelegateFromOnly(); + else if (vsDelegatedFrom != null && vsDelegatedFrom.contains(sName)) + return formatDelegateToOnly(); + else + */ +#endif + out = formatNeedsAction(); + } + return out; +} +//--------------------------------------------------------------------- + +UnicodeString & Attendee::toICALString(UnicodeString & sProp, + UnicodeString & out) +{ + // NOTE: to eliminate stupid warning + if (sProp.size() > 0) {} + return toICALString(out); +} + +//--------------------------------------------------------------------- + +UnicodeString & Attendee::toString(UnicodeString & out) +{ + out = toString(JulianFormatString::Instance()->ms_AttendeeStrDefaultFmt, out); + return out; +} + +//--------------------------------------------------------------------- + +UnicodeString & Attendee::toString(UnicodeString & strFmt, + UnicodeString & out) +{ + if (strFmt.size() == 0 && + JulianFormatString::Instance()->ms_AttendeeStrDefaultFmt.size() > 0) + { + // if empty format string, use default + return toString(out); + } + + UnicodeString into; + t_int32 i,j; + //if (FALSE) TRACE("strFmt = %s\r\n", strFmt.toCString("")); + out = ""; + for ( i = 0; i < strFmt.size(); ) + { + + // NOTE: changed from % to ^ for attendee + /// + /// If there's a special formatting character, + /// handle it. Otherwise, just emit the supplied + /// character. + /// + + j = strFmt.indexOf('^', i); + if ( -1 != j) + { + if (j > i) + { + out += strFmt.extractBetween(i,j,into); + } + i = j + 1; + if ( strFmt.size() > i) + { + out += toStringChar(strFmt[(TextOffset) i]); + i++; + } + } + else + { + out += strFmt.extractBetween(i, strFmt.size(),into); + break; + } + } + return out; +}// end + +//--------------------------------------------------------------------- + +UnicodeString Attendee::toStringChar(t_int32 c) +{ + + UnicodeString u; + switch ( c ) + { + case ms_cAttendeeName: + return getName(); + case ms_cAttendeeRole: + return roleToString((Attendee::ROLE) getRole(), u); + case ms_cAttendeeType: + return typeToString((Attendee::TYPE) getType(), u); + case ms_cAttendeeStatus: + return statusToString((Attendee::STATUS) getStatus(), u); + case ms_cAttendeeExpect: + return expectToString((Attendee::EXPECT) getExpect(), u); + case ms_cAttendeeRSVP: + return rsvpToString((Attendee::RSVP) getRSVP(), u); + case ms_cAttendeeDir: + return m_Dir; + case ms_cAttendeeSentBy: + return m_SentBy; + case ms_cAttendeeCN: + return m_CN; + case ms_cAttendeeLanguage: + return m_Language; + case ms_cAttendeeDisplayName: + // return CN is CN != "", else + // return the AttendeeName after the ':' + if (m_CN.size() > 0) + return m_CN; + else + { + t_int32 i = m_sName.indexOf(':'); + if (i >= 0) + { + u = getName().extractBetween(i + 1, m_sName.size(), u); + return u; + } + else + return ""; + } + default: + return ""; + } +}// end of + +//--------------------------------------------------------------------- + +t_bool Attendee::isValid() +{ + /* + UnicodeString mailto; + if (m_sName.size() < 7) + return FALSE; + // change to URL, must have "MAILTO:" in front + mailto = m_sName.extractBetween(0, 7, mailto); + if (mailto.compareIgnoreCase(JulianKeyword::Instance()->ms_sMAILTO_COLON) != 0) + return FALSE; + else + return TRUE; + */ + return URI::IsValidURI(m_sName); +} + +//--------------------------------------------------------------------- + +void Attendee::selfCheckHelper(Attendee::PROPS prop, t_int32 param) +{ + if (prop == PROPS_ROLE && (param < 0 || param >= ROLE_LENGTH)) + setRole((Attendee::ROLE) ms_iDEFAULT_ROLE); + else if (prop == PROPS_TYPE && (param < 0 || param >= TYPE_LENGTH)) + setType((Attendee::TYPE) ms_iDEFAULT_TYPE); + else if (prop == PROPS_STATUS && (param < 0 || param >= STATUS_LENGTH)) + setStatus((Attendee::STATUS) ms_iDEFAULT_STATUS); + else if (prop == PROPS_EXPECT && (param < 0 || param >= EXPECT_LENGTH)) + setExpect((Attendee::EXPECT) ms_iDEFAULT_EXPECT); + else if (prop == PROPS_RSVP && (param < 0 || param >= RSVP_LENGTH)) + setRSVP((Attendee::RSVP) ms_iDEFAULT_RSVP); +} + +//--------------------------------------------------------------------- + +void Attendee::selfCheck() +{ + selfCheckHelper(PROPS_ROLE, (t_int32) getRole()); + selfCheckHelper(PROPS_TYPE, (t_int32) getType()); + selfCheckHelper(PROPS_STATUS, (t_int32) getStatus()); + selfCheckHelper(PROPS_EXPECT, (t_int32) getExpect()); + selfCheckHelper(PROPS_RSVP, (t_int32) getRSVP()); +} + +//--------------------------------------------------------------------- + +UnicodeString Attendee::format(UnicodeString strFmt) +{ + UnicodeString s, info; + t_int32 i,j; + s += JulianKeyword::Instance()->ms_sATTENDEE; + + for ( i = 0; i < strFmt.size(); ) + { + + /*- + *** If there's a special formatting character, + *** handle it. Otherwise, just emit the supplied + *** character. + **/ + j = strFmt.indexOf('%', i); + if ( -1 != j) + { + if (j > i) + { + s += strFmt.extractBetween(i,j,info); + } + i = j + 1; + if (strFmt.size() > i) + { + s += formatChar(strFmt[(TextOffset) i]); + i++; + } + } + else + { + s += strFmt.extractBetween(i, strFmt.size(),info); + break; + } + } + return s; +} + +//--------------------------------------------------------------------- + +UnicodeString Attendee::formatChar(t_int32 c) +{ + UnicodeString s, u; + JulianPtrArray * xp; + switch ( c ) + { + case ms_cAttendeeName: { + // ALWAYS MUST BE LAST OF PARAMS + s = ":"; //ms_sCOLON_SYMBOL; + s += getName(); + s += JulianKeyword::Instance()->ms_sLINEBREAK; + return s; + } + case ms_cAttendeeRole: + s = roleToString(getRole(), s); + return ICalProperty::parameterToCalString( + JulianKeyword::Instance()->ms_sROLE, s, u); + case ms_cAttendeeStatus: + s = statusToString(getStatus(), s); + return ICalProperty::parameterToCalString( + JulianKeyword::Instance()->ms_sPARTSTAT, s, u); + case ms_cAttendeeRSVP: + s = rsvpToString(getRSVP(), s); + return ICalProperty::parameterToCalString( + JulianKeyword::Instance()->ms_sRSVP, s, u); + case ms_cAttendeeType: + s = typeToString(getType(), s); + return ICalProperty::parameterToCalString( + JulianKeyword::Instance()->ms_sCUTYPE, s, u); + case ms_cAttendeeExpect: + s = expectToString(getExpect(), s); + return ICalProperty::parameterToCalString( + JulianKeyword::Instance()->ms_sEXPECT, s, u); + case ms_cAttendeeDelegatedTo: + xp = getDelegatedTo(); + return printMailToVector( + JulianKeyword::Instance()->ms_sDELEGATED_TO, xp, u); + case ms_cAttendeeDelegatedFrom: + xp = getDelegatedFrom(); + return printMailToVector( + JulianKeyword::Instance()->ms_sDELEGATED_FROM, xp, u); + case ms_cAttendeeMember: + xp = getMember(); + return printMailToVector( + JulianKeyword::Instance()->ms_sMEMBER, xp, u); + case ms_cAttendeeDir: + s = m_Dir; + s = JulianUtility::addDoubleQuotes(s); + return ICalProperty::parameterToCalString( + JulianKeyword::Instance()->ms_sDIR, s, u); + case ms_cAttendeeSentBy: + s = m_SentBy; + s = JulianUtility::addDoubleQuotes(s); + return ICalProperty::parameterToCalString( + JulianKeyword::Instance()->ms_sSENTBY, s, u); + case ms_cAttendeeCN: + return ICalProperty::parameterToCalString( + JulianKeyword::Instance()->ms_sCN, m_CN, u); + case ms_cAttendeeLanguage: + return ICalProperty::parameterToCalString( + JulianKeyword::Instance()->ms_sLANGUAGE, m_Language, u); + default: + return ""; + } +} + +//--------------------------------------------------------------------- + +UnicodeString & +Attendee::printMailToVector(UnicodeString & propName, JulianPtrArray * mailto, + UnicodeString & out) +{ + out = ""; + if (mailto != 0 && mailto->GetSize() > 0) + { + t_int32 i; + out += ';'; + out += propName; + out += '='; + UnicodeString aMailto; + for (i = 0; i < mailto->GetSize(); i++) + { + aMailto = *((UnicodeString *) mailto->GetAt(i)); + out += '\"'; + out += aMailto; + out += '\"'; + if (i < mailto->GetSize() - 1) + { + out += ','; + } + } + } + return out; +} + +//--------------------------------------------------------------------- + +UnicodeString Attendee::formatDoneAction() +{ + return format(JulianFormatString::Instance()->ms_sAttendeeDoneActionMessage); +} + +//--------------------------------------------------------------------- +#if 0 +UnicodeString Attendee::formatDoneDelegateToOnly() +{ + return format(JulianFormatString::Instance()->ms_sAttendeeDoneDelegateToOnly); +} + +//--------------------------------------------------------------------- + +UnicodeString Attendee::formatDoneDelegateFromOnly() +{ + return format(JulianFormatString::Instance()->ms_sAttendeeDoneDelegateFromOnly); +} +#endif +//--------------------------------------------------------------------- +// BELOW METHODS ALL ARE NEEDS ACTION +// no need for %S, assumed to be NEEDS-ACTION +UnicodeString Attendee::formatNeedsAction() +{ + return format(JulianFormatString::Instance()->ms_sAttendeeNeedsActionMessage); +} + +//--------------------------------------------------------------------- +#if 0 +UnicodeString Attendee::formatDelegateToOnly() +{ + return format(JulianFormatString::Instance()->ms_sAttendeeNeedsActionDelegateToOnly); +} + +//--------------------------------------------------------------------- + +UnicodeString Attendee::formatDelegateFromOnly() +{ + return format(JulianFormatString::Instance()->ms_sAttendeeNeedsActionDelegateFromOnly); +} +#endif +//--------------------------------------------------------------------- + +void Attendee::setParameters(JulianPtrArray * parameters) +{ + t_int32 i; + ICalParameter * param; + UnicodeString pName, pVal; + if (parameters != 0) + { + for (i = 0; i < parameters->GetSize(); i++) + { + param = (ICalParameter *) parameters->GetAt(i); + setParam(param->getParameterName(pName), + param->getParameterValue(pVal)); + } + } +} + +//--------------------------------------------------------------------- + +void Attendee::setName(UnicodeString sName) +{ + m_sName = sName; +} + +//--------------------------------------------------------------------- + +void Attendee::addDelegatedTo(UnicodeString sDelegatedTo) +{ + if (m_vsDelegatedTo == 0) + m_vsDelegatedTo = new JulianPtrArray(); + PR_ASSERT(m_vsDelegatedTo != 0); + if (m_vsDelegatedTo != 0) + { + m_vsDelegatedTo->Add(new UnicodeString(sDelegatedTo)); + } +} + +//--------------------------------------------------------------------- + +void Attendee::addDelegatedFrom(UnicodeString sDelegatedFrom) +{ + if (m_vsDelegatedFrom == 0) + m_vsDelegatedFrom = new JulianPtrArray(); + PR_ASSERT(m_vsDelegatedFrom != 0); + if (m_vsDelegatedFrom != 0) + { + m_vsDelegatedFrom->Add(new UnicodeString(sDelegatedFrom)); + } +} + +//--------------------------------------------------------------------- + +void Attendee::addMember(UnicodeString sMember) +{ + if (m_vsMember == 0) + m_vsMember = new JulianPtrArray(); + PR_ASSERT(m_vsMember != 0); + if (m_vsMember != 0) + { + m_vsMember->Add(new UnicodeString(sMember)); + } +} +//--------------------------------------------------------------------- + +Attendee * Attendee::getAttendee(JulianPtrArray * vAttendees, UnicodeString sAttendee) +{ + Attendee * att; + t_int32 i; + if (vAttendees != 0 && vAttendees->GetSize() > 0) + { + for (i = 0; i < vAttendees->GetSize(); i++) + { + att = (Attendee *) vAttendees->GetAt(i); + if ((att->getName()).compareIgnoreCase(sAttendee) == 0) + { + return att; + } + } + } + return 0; +} + +//--------------------------------------------------------------------- + +Attendee::ROLE +Attendee::stringToRole(UnicodeString & sRole) +{ + sRole.toUpper(); + t_int32 hashCode = sRole.hashCode(); + +#if 0 + /* Old keywords */ + if (JulianKeyword::Instance()->ms_ATOM_ATTENDEE == hashCode) return ROLE_ATTENDEE; + else if (JulianKeyword::Instance()->ms_ATOM_ORGANIZER == hashCode) return ROLE_ORGANIZER; + else if (JulianKeyword::Instance()->ms_ATOM_OWNER == hashCode) return ROLE_OWNER; + else if (JulianKeyword::Instance()->ms_ATOM_DELEGATE == hashCode) return ROLE_DELEGATE; +#endif + + if (JulianKeyword::Instance()->ms_ATOM_CHAIR == hashCode) return ROLE_CHAIR; + else if (JulianKeyword::Instance()->ms_ATOM_REQ_PARTICIPANT == hashCode) return ROLE_REQ_PARTICIPANT; + else if (JulianKeyword::Instance()->ms_ATOM_OPT_PARTICIPANT == hashCode) return ROLE_OPT_PARTICIPANT; + else if (JulianKeyword::Instance()->ms_ATOM_NON_PARTICIPANT == hashCode) return ROLE_NON_PARTICIPANT; + else if (ICalProperty::IsXToken(sRole)) return ROLE_XPARAMVAL; + else return ROLE_INVALID; +} + +//--------------------------------------------------------------------- + +Attendee::TYPE +Attendee::stringToType(UnicodeString & sType) +{ + sType.toUpper(); + t_int32 hashCode = sType.hashCode(); + + if (JulianKeyword::Instance()->ms_ATOM_INDIVIDUAL == hashCode) return TYPE_INDIVIDUAL; + else if (JulianKeyword::Instance()->ms_ATOM_GROUP == hashCode) return TYPE_GROUP; + else if (JulianKeyword::Instance()->ms_ATOM_RESOURCE == hashCode) return TYPE_RESOURCE; + else if (JulianKeyword::Instance()->ms_ATOM_ROOM == hashCode) return TYPE_ROOM; + else if (JulianKeyword::Instance()->ms_ATOM_UNKNOWN == hashCode) return TYPE_UNKNOWN; + else if (ICalProperty::IsXToken(sType)) return TYPE_XPARAMVAL; + else return TYPE_INVALID; +} + +//--------------------------------------------------------------------- + +Attendee::STATUS +Attendee::stringToStatus(UnicodeString & sStatus) +{ + sStatus.toUpper(); + t_int32 hashCode = sStatus.hashCode(); + + if (JulianKeyword::Instance()->ms_ATOM_NEEDSACTION == hashCode) return STATUS_NEEDSACTION; + else if (JulianKeyword::Instance()->ms_ATOM_VCALNEEDSACTION == hashCode) return STATUS_NEEDSACTION; + + else if (JulianKeyword::Instance()->ms_ATOM_ACCEPTED == hashCode) return STATUS_ACCEPTED; + else if (JulianKeyword::Instance()->ms_ATOM_DECLINED == hashCode) return STATUS_DECLINED; + else if (JulianKeyword::Instance()->ms_ATOM_TENTATIVE == hashCode) return STATUS_TENTATIVE; + else if (JulianKeyword::Instance()->ms_ATOM_COMPLETED == hashCode) return STATUS_COMPLETED; + else if (JulianKeyword::Instance()->ms_ATOM_INPROCESS == hashCode) return STATUS_INPROCESS; + else if (JulianKeyword::Instance()->ms_ATOM_DELEGATED == hashCode) return STATUS_DELEGATED; + else if (ICalProperty::IsXToken(sStatus)) return STATUS_XPARAMVAL; + else return STATUS_INVALID; +} + +//--------------------------------------------------------------------- + +Attendee::RSVP +Attendee::stringToRSVP(UnicodeString & sRSVP) +{ + sRSVP.toUpper(); + t_int32 hashCode = sRSVP.hashCode(); + + if (JulianKeyword::Instance()->ms_ATOM_FALSE == hashCode) return RSVP_FALSE; + else if (JulianKeyword::Instance()->ms_ATOM_TRUE == hashCode) return RSVP_TRUE; + else return RSVP_INVALID; +} + +//--------------------------------------------------------------------- + +Attendee::EXPECT +Attendee::stringToExpect(UnicodeString & sExpect) +{ + sExpect.toUpper(); + t_int32 hashCode = sExpect.hashCode(); + + if (JulianKeyword::Instance()->ms_ATOM_FYI == hashCode) return EXPECT_FYI; + else if (JulianKeyword::Instance()->ms_ATOM_REQUIRE == hashCode) return EXPECT_REQUIRE; + else if (JulianKeyword::Instance()->ms_ATOM_REQUEST == hashCode) return EXPECT_REQUEST; + else return EXPECT_INVALID; +} + +//--------------------------------------------------------------------- + +UnicodeString & +Attendee::roleToString(Attendee::ROLE role, UnicodeString & out) +{ + switch(role) + { + +#if 0 + /* Old Keywords */ + case ROLE_ATTENDEE: out = JulianKeyword::Instance()->ms_sATTENDEE; break; + case ROLE_ORGANIZER: out = JulianKeyword::Instance()->ms_sORGANIZER; break; + case ROLE_OWNER: out = JulianKeyword::Instance()->ms_sOWNER; break; + case ROLE_DELEGATE: out = JulianKeyword::Instance()->ms_sDELEGATE; break; +#endif + + case ROLE_CHAIR: out = JulianKeyword::Instance()->ms_sCHAIR; break; + case ROLE_REQ_PARTICIPANT: out = JulianKeyword::Instance()->ms_sREQ_PARTICIPANT; break; + case ROLE_OPT_PARTICIPANT: out = JulianKeyword::Instance()->ms_sOPT_PARTICIPANT; break; + case ROLE_NON_PARTICIPANT: out = JulianKeyword::Instance()->ms_sNON_PARTICIPANT; break; + case ROLE_XPARAMVAL: out = JulianKeyword::Instance()->ms_sXPARAMVAL; break; + default: + // default return req participant + out = JulianKeyword::Instance()->ms_sREQ_PARTICIPANT; + break; + } + return out; +} + +//--------------------------------------------------------------------- + +UnicodeString & +Attendee::typeToString(Attendee::TYPE type, UnicodeString & out) +{ + switch(type) + { + case TYPE_INDIVIDUAL: out = JulianKeyword::Instance()->ms_sINDIVIDUAL; break; + case TYPE_GROUP: out = JulianKeyword::Instance()->ms_sGROUP; break; + case TYPE_RESOURCE: out = JulianKeyword::Instance()->ms_sRESOURCE; break; + case TYPE_ROOM: out = JulianKeyword::Instance()->ms_sROOM; break; + case TYPE_UNKNOWN: out = JulianKeyword::Instance()->ms_sUNKNOWN; break; + case TYPE_XPARAMVAL: out = JulianKeyword::Instance()->ms_sXPARAMVAL; break; + default: + // default return individual + out = JulianKeyword::Instance()->ms_sINDIVIDUAL; + break; + } + return out; +} + +//--------------------------------------------------------------------- + +UnicodeString & +Attendee::statusToString(Attendee::STATUS status, UnicodeString & out) +{ + switch(status) + { + case STATUS_NEEDSACTION: out = JulianKeyword::Instance()->ms_sNEEDSACTION; break; + case STATUS_ACCEPTED: out = JulianKeyword::Instance()->ms_sACCEPTED; break; + case STATUS_DECLINED: out = JulianKeyword::Instance()->ms_sDECLINED; break; + case STATUS_TENTATIVE: out = JulianKeyword::Instance()->ms_sTENTATIVE; break; + case STATUS_COMPLETED: out = JulianKeyword::Instance()->ms_sCOMPLETED; break; + case STATUS_DELEGATED: out = JulianKeyword::Instance()->ms_sDELEGATED; break; + case STATUS_INPROCESS: out = JulianKeyword::Instance()->ms_sINPROCESS; break; + case STATUS_XPARAMVAL: out = JulianKeyword::Instance()->ms_sXPARAMVAL; break; + default: + // default return needs-action + out = JulianKeyword::Instance()->ms_sNEEDSACTION; + break; + } + return out; +} + +//--------------------------------------------------------------------- + +UnicodeString & +Attendee::rsvpToString(Attendee::RSVP rsvp, UnicodeString & out) +{ + switch(rsvp) + { + case RSVP_FALSE: out = JulianKeyword::Instance()->ms_sFALSE; break; + case RSVP_TRUE: out = JulianKeyword::Instance()->ms_sTRUE; break; + default: + // default return false + out = JulianKeyword::Instance()->ms_sFALSE; + break; + } + return out; +} + +//--------------------------------------------------------------------- + +UnicodeString & +Attendee::expectToString(Attendee::EXPECT expect, UnicodeString & out) +{ + switch(expect) + { + case EXPECT_FYI: out = JulianKeyword::Instance()->ms_sFYI; break; + case EXPECT_REQUIRE: out = JulianKeyword::Instance()->ms_sREQUIRE; break; + case EXPECT_REQUEST: out = JulianKeyword::Instance()->ms_sREQUEST; break; + default: + // default return fyi + out = JulianKeyword::Instance()->ms_sFYI; + break; + } + return out; +} + +//--------------------------------------------------------------------- + diff --git a/calendar/modules/core/ical/src/bprprty.cpp b/calendar/modules/core/ical/src/bprprty.cpp new file mode 100644 index 00000000000..e9f9f57f63d --- /dev/null +++ b/calendar/modules/core/ical/src/bprprty.cpp @@ -0,0 +1,118 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +// bprprty.cpp +// John Sun +// 3:34 PM February 12 1998 + +#include "stdafx.h" +#include "jdefines.h" + +#include "bprprty.h" +#include "prprty.h" + +//--------------------------------------------------------------------- + +// private never use +BooleanProperty::BooleanProperty() +{ + PR_ASSERT(FALSE); +} + +//--------------------------------------------------------------------- + +BooleanProperty::BooleanProperty(const BooleanProperty & that) +{ + m_Boolean = that.m_Boolean; + setParameters(that.m_vParameters); +} + +//--------------------------------------------------------------------- + +BooleanProperty::BooleanProperty(t_bool value, JulianPtrArray * parameters) +: StandardProperty(parameters) +{ + m_Boolean = value; +} + +//--------------------------------------------------------------------- + +BooleanProperty::~BooleanProperty() +{ +} + +//--------------------------------------------------------------------- + +void * BooleanProperty::getValue() const +{ + return (void *) &m_Boolean; +} + +//--------------------------------------------------------------------- + +void BooleanProperty::setValue(void * value) +{ + PR_ASSERT(value != 0); + if (value != 0) + { + m_Boolean = *((t_bool *) value); + } +} + +//--------------------------------------------------------------------- + +ICalProperty * BooleanProperty::clone(JLog * initLog) +{ + if (initLog) {} // NOTE: Remove later to avoid warnings + return new BooleanProperty(*this); +} + +//--------------------------------------------------------------------- + +t_bool BooleanProperty::isValid() +{ + return TRUE; +} + +//--------------------------------------------------------------------- + +UnicodeString & BooleanProperty::toString(UnicodeString & out) +{ + + if (m_Boolean) + out = "TRUE"; + else + out = "FALSE"; + return out; +} +//--------------------------------------------------------------------- +UnicodeString & +BooleanProperty::toString(UnicodeString & dateFmt, UnicodeString & out) +{ + // NOTE: remove it later, gets rid of compiler warning + if (dateFmt.size() > 0) {} + return toString(out); +} +//--------------------------------------------------------------------- + +UnicodeString & BooleanProperty::toExportString(UnicodeString & out) +{ + return toString(out); +} +//--------------------------------------------------------------------- + diff --git a/calendar/modules/core/ical/src/bydmgntr.cpp b/calendar/modules/core/ical/src/bydmgntr.cpp new file mode 100644 index 00000000000..457b64b681e --- /dev/null +++ b/calendar/modules/core/ical/src/bydmgntr.cpp @@ -0,0 +1,188 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +// bydmgntr.cpp +// John Sun +// 4:08 PM February 3 1998 + +#include "stdafx.h" +#include "jdefines.h" + +#include +#include +#include "bydmgntr.h" +#include "jutility.h" +#include "calendar.h" + + +ByDayMonthlyGenerator::ByDayMonthlyGenerator() +: DateGenerator(JulianUtility::RT_MONTHLY, 0), + m_aiParams(0), + m_iWkSt((t_int32) Calendar::SUNDAY) +{} + +//--------------------------------------------------------------------- + +t_int32 +ByDayMonthlyGenerator::getInterval() const { return JulianUtility::RT_DAILY; } + +//--------------------------------------------------------------------- +// TODO: crash proof it +t_bool +ByDayMonthlyGenerator::generate(DateTime * start, JulianPtrArray & dateVector, + DateTime * until) +{ + DateTime * t, * nextWkSt; + t_int32 i, iMonth = 0, iMonth2 = 0; + t_bool bOldWkSt; + t_int32 temp; + + PR_ASSERT(start != 0); + PR_ASSERT(m_aiParams != 0); + // bulletproof code + if (start == 0 || m_aiParams == 0) + { + return FALSE; + } + + // if (FALSE) TRACE("start = %s\r\n", start->toString().toCString("")); + + t = new DateTime(start->getTime()); PR_ASSERT(t != 0); + // bulletproof code + if (t == 0) + { + return FALSE; + } + nextWkSt = new DateTime(start->getTime()); PR_ASSERT(nextWkSt != 0); + // bulletproof code + if (nextWkSt == 0) + { + if (t != 0) { delete t; t = 0; } + return FALSE; + } + + for (i = 0; i < m_iParamsLen; i++) + { + t->setTime(start->getTime()); + + //if (FALSE) TRACE("t = %s\r\n", t->toString().toCString("")); + //if (FALSE) TRACE("nextWkSt = %s\r\n", nextWkSt->toString().toCString("")); + + if (m_aiParams[i][1] >= 0) + { + t->add(Calendar::DATE, -(t->get(Calendar::DATE)) + 1); + } + else + { + t->findLastDayOfMonth(); + } + + //if (FALSE) TRACE("t = %s\r\n", t->toString().toCString("")); + + iMonth = t->get(Calendar::MONTH); + + if (m_aiParams[i][1] != 0) + { + while (t->get(Calendar::DAY_OF_WEEK) != m_aiParams[i][0]) + t->add(Calendar::DATE, (m_aiParams[i][1] > 0) ? 1 : -1); + + //if (FALSE) TRACE("t = %s\r\n", t->toString().toCString("")); + + // NOTE: so not to call abs (to fix HPUX-compiling problem), replaces below commented out code + temp = m_aiParams[i][1]; + if (temp < 0) + temp = 0 - temp; + + t->add(Calendar::DAY_OF_YEAR, (temp - 1) * + (m_aiParams[i][1] > 0 ? 1 : -1) * 7); + + /// replacing this code with above + //t->add(Calendar::DAY_OF_YEAR, (abs(m_aiParams[i][1]) - 1) * + // (m_aiParams[i][1] > 0 ? 1 : -1) * 7); + + + + //if (FALSE) TRACE("t = %s\r\n", t->toString().toCString("")); + + if (until != 0 && until->isValid() && t->after(until)) + { + delete t; t = 0; + delete nextWkSt; nextWkSt = 0; + return TRUE; + } + else + { + // check also still in same month! + // prevents bug if asking 5MO, but no 5th monday in this month + if ((t->after(start) || t->equals(start)) && + (t->get(Calendar::MONTH) == iMonth) + ) + { + dateVector.Add(new DateTime(t->getTime())); + } + } + } + else + { + nextWkSt->setTime(t->getTime()); + nextWkSt->moveTo(m_iWkSt, 1, TRUE); + + while (t->get(Calendar::MONTH) == iMonth) + { + + //if (FALSE) TRACE("nextWkSt = %s\r\n", nextWkSt->toString().toCString("")); + //if (FALSE) TRACE("t = %s\r\n", t->toString().toCString("")); + + bOldWkSt = TRUE; + if (until != 0 && until->isValid() && t->after(until)) + { + delete t; t = 0; + delete nextWkSt; nextWkSt = 0; + return TRUE; + } + else if (t->get(Calendar::DAY_OF_WEEK) == m_aiParams[i][0] && + (t->after(start) || t->equals(start)) && + !(t->after(nextWkSt))) + { + dateVector.Add(new DateTime(t->getTime())); + nextWkSt->setTime(t->getTime()); + nextWkSt->moveTo(m_iWkSt, 1, TRUE); + } + else if (t->after(nextWkSt)) + { + nextWkSt->setTime(t->getTime()); + nextWkSt->moveTo(m_iWkSt, 1, TRUE); + bOldWkSt = FALSE; + } + if ((bOldWkSt) && (!(t->after(nextWkSt)))) + { + iMonth2 = t->get(Calendar::DAY_OF_MONTH); + t->add(Calendar::DATE, 1); + if (iMonth2 == t->get(Calendar::DAY_OF_MONTH)) + t->add(Calendar::DATE, -1); + } + } + } + } + delete t; t = 0; + delete nextWkSt; nextWkSt = 0; + return FALSE; +} +//--------------------------------------------------------------------- + + diff --git a/calendar/modules/core/ical/src/bydwgntr.cpp b/calendar/modules/core/ical/src/bydwgntr.cpp new file mode 100644 index 00000000000..fc76d589575 --- /dev/null +++ b/calendar/modules/core/ical/src/bydwgntr.cpp @@ -0,0 +1,85 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +// bydwgntr.cpp +// John Sun +// 4:10 PM February 3 1998 + +#include "stdafx.h" +#include "jdefines.h" + +#include +#include "bydwgntr.h" +#include "jutility.h" + +ByDayWeeklyGenerator::ByDayWeeklyGenerator() +: + DateGenerator(JulianUtility::RT_WEEKLY, 0), + m_aiParams(0), + m_iWkSt((t_int32) Calendar::SUNDAY) +{} + +//--------------------------------------------------------------------- + +t_int32 +ByDayWeeklyGenerator::getInterval() const { return JulianUtility::RT_DAILY; } + +//--------------------------------------------------------------------- + +t_bool +ByDayWeeklyGenerator::generate(DateTime * start, JulianPtrArray & dateVector, + DateTime * until) +{ + DateTime * t, * nextWkSt; + t_int32 i; + + PR_ASSERT(start != 0); + PR_ASSERT(m_aiParams != 0); + if (start == 0 || m_aiParams == 0) + { + return FALSE; + } + + t = new DateTime(start->getTime()); PR_ASSERT(t != 0); + nextWkSt = new DateTime(t->getTime()); PR_ASSERT(nextWkSt != 0); + + nextWkSt->moveTo(m_iWkSt, 1, TRUE); + + for (i = 0; i < m_iParamsLen; i++) + { + t->setTime(start->getTime()); + t->moveTo(m_aiParams[i][0], 1, FALSE); + + if (until != 0 && until->isValid() && t->after(until)) + { + delete t; t = 0; + delete nextWkSt; nextWkSt = 0; + return TRUE; + } + if ((t->after(start) || t->equals(start)) && t->before(nextWkSt)) + { + dateVector.Add(new DateTime(t->getTime())); + } + } + delete t; t = 0; + delete nextWkSt; nextWkSt = 0; + return FALSE; +} +//--------------------------------------------------------------------- + + diff --git a/calendar/modules/core/ical/src/bydygntr.cpp b/calendar/modules/core/ical/src/bydygntr.cpp new file mode 100644 index 00000000000..68d0fe8eed8 --- /dev/null +++ b/calendar/modules/core/ical/src/bydygntr.cpp @@ -0,0 +1,173 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +// bydygntr.cpp +// John Sun +// 4:11 PM February 3 1998 + +#include "stdafx.h" +#include "jdefines.h" + +#include +#include +#include "bydygntr.h" +#include "jutility.h" + +ByDayYearlyGenerator::ByDayYearlyGenerator() +: + DateGenerator(JulianUtility::RT_YEARLY, 0), + m_aiParams(0), + m_iWkSt((t_int32) Calendar::SUNDAY) +{} + + +//--------------------------------------------------------------------- + +t_int32 +ByDayYearlyGenerator::getInterval() const { return JulianUtility::RT_DAILY; } + +//--------------------------------------------------------------------- +// TODO: crash proof +t_bool +ByDayYearlyGenerator::generate(DateTime * start, JulianPtrArray & dateVector, + DateTime * until) +{ + DateTime * t, * nextWkSt; + t_int32 i, k, iYear = 0, iDayOfYear = 0; + t_int32 iAbsMod = -1; + t_bool bOldWkSt = FALSE; + t_int32 temp = 0; + + PR_ASSERT(start != 0); + PR_ASSERT(m_aiParams != 0); + + if (start == 0 || m_aiParams == 0) + { + return FALSE; + } + + t = new DateTime(start->getTime()); PR_ASSERT(t != 0); + // bulletproof code + if (t == 0) + { + return FALSE; + } + nextWkSt = new DateTime(start->getTime()); PR_ASSERT(nextWkSt != 0); + // bulletproof code + if (nextWkSt == 0) + { + if (t != 0) { delete t; t = 0; } + return FALSE; + } + + for (i = 0; i < m_iParamsLen; i++) + { + k = 0; + t->setTime(start->getTime()); + + if (m_aiParams[i][1] >= 0) + t->add(Calendar::DAY_OF_YEAR, + -(t->get(Calendar::DAY_OF_YEAR)) + 1); + else + t->findLastDayOfYear(); + + iYear = t->get(Calendar::YEAR); + + if (m_aiParams[i][1] != 0) + { + // NOTE: avoid using abs to fix HPUX compiling problems + temp = m_aiParams[i][1]; + if (temp < 0) + temp = 0 - temp; + iAbsMod = temp - 1; + + // replacing below code with above + //iAbsMod = abs(m_aiParams[i][1]) - 1; + + + while ((k != iAbsMod) || + (t->get(Calendar::DAY_OF_WEEK) != m_aiParams[i][0])) + { + if (t->get(Calendar::DAY_OF_WEEK) == m_aiParams[i][0]) + k++; + + if (m_aiParams[i][1] > 0) + t->add(Calendar::DAY_OF_YEAR, 1); + else + t->add(Calendar::DAY_OF_YEAR, -1); + + if (until != 0 && until->isValid() && t->after(until)) + { + delete t; t = 0; + delete nextWkSt; nextWkSt = 0; + return TRUE; + } + } + + // check also still in same year! + // prevents bug if asking 53MO, but no 53th monday in this year + if ((t->after(start) || t->equals(start)) && + (t->get(Calendar::YEAR) == iYear)) + { + dateVector.Add(new DateTime(t->getTime())); + } + } + else + { + nextWkSt->setTime(start->getTime()); + nextWkSt->moveTo(m_iWkSt, 1, TRUE); + + while (t->get(Calendar::YEAR) == iYear) + { + bOldWkSt = TRUE; + if (until != 0 && until->isValid() && t->after(until)) + { + delete t; t = 0; + delete nextWkSt; nextWkSt = 0; + return TRUE; + } + else if (t->get(Calendar::DAY_OF_WEEK) == m_aiParams[i][0] && + (t->after(start) || t->equals(start)) && + !(t->after(nextWkSt))) + { + dateVector.Add(new DateTime(t->getTime())); + nextWkSt->setTime(t->getTime()); + nextWkSt->moveTo(m_iWkSt, 1, TRUE); + } + else if (t->after(nextWkSt)) + { + nextWkSt->setTime(t->getTime()); + nextWkSt->moveTo(m_iWkSt, 1, TRUE); + bOldWkSt = FALSE; + } + if ((bOldWkSt) && (!t->after(nextWkSt))) + { + iDayOfYear = t->get(Calendar::DAY_OF_YEAR); + t->add(Calendar::DATE, 1); + if (iDayOfYear == t->get(Calendar::DAY_OF_YEAR)) + t->add(Calendar::DAY_OF_YEAR, -1); + } + } + } + } + delete t; t = 0; + delete nextWkSt; nextWkSt = 0; + return FALSE; +} +//--------------------------------------------------------------------- + diff --git a/calendar/modules/core/ical/src/byhgntr.cpp b/calendar/modules/core/ical/src/byhgntr.cpp new file mode 100644 index 00000000000..3d8356d6d0f --- /dev/null +++ b/calendar/modules/core/ical/src/byhgntr.cpp @@ -0,0 +1,104 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +// byhgntr.cpp +// John Sun +// 4:18 PM February 3 1998 + +#include "stdafx.h" +#include "jdefines.h" + +#include +#include "byhgntr.h" +#include "jutility.h" +#include "calendar.h" + +ByHourGenerator::ByHourGenerator() +: + DateGenerator(JulianUtility::RT_DAILY, 0), + m_aiParams(0) +{} + +//--------------------------------------------------------------------- + +t_int32 +ByHourGenerator::getInterval() const { return JulianUtility::RT_HOURLY; } + +//--------------------------------------------------------------------- + +t_bool +ByHourGenerator::generate(DateTime * start, JulianPtrArray & dateVector, + DateTime * until) +{ + DateTime * t; + t_int32 i; + + DateTime dt; + + PR_ASSERT(start != 0); + PR_ASSERT(m_aiParams != 0); + + if (start == 0 || m_aiParams == 0) + { + return FALSE; + } + + t = new DateTime(start->getTime()); PR_ASSERT(t != 0); + + for (i = 0; i < m_iParamsLen; i++) + { + t->setTime(start->getTime()); + + while (start->get((Calendar::EDateFields) m_iSpan) == + t->get((Calendar::EDateFields) m_iSpan)) + { + // only allow 0-23, no negatives allowed, using hour_of_day + // instead of hour since hour does seem to update immediately + t->set(Calendar::HOUR_OF_DAY, m_aiParams[i]); + + /* + // allow negatives (not in spec anymore, so commented out) + + if (m_aiParams[i] > 0) + t->set(Calendar::HOUR_OF_DAY, m_aiParams[i]); + else + t->set(Calendar::HOUR_OF_DAY, 24 + m_aiParams[i]); + */ + + if (until != 0 && until->isValid() && t->after(until)) + { + delete t; t = 0; + return TRUE; + } + else if (t->after(start) || t->equals(start)) + { + //dt = *t; + //dateVector.Add(t); + //delete t; + dateVector.Add(new DateTime(t->getTime())); + } + + t->add(Calendar::DAY_OF_YEAR, 1); + } + } + delete t; t = 0; + return FALSE; +} +//--------------------------------------------------------------------- + + diff --git a/calendar/modules/core/ical/src/bymdgntr.cpp b/calendar/modules/core/ical/src/bymdgntr.cpp new file mode 100644 index 00000000000..dc9e9bd94f1 --- /dev/null +++ b/calendar/modules/core/ical/src/bymdgntr.cpp @@ -0,0 +1,100 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +// bymdgntr.cpp +// John Sun +// 4:08 PM February 3 1998 + +#include "stdafx.h" +#include "jdefines.h" + +#include +#include "bymdgntr.h" +#include "jutility.h" + +ByMonthDayGenerator::ByMonthDayGenerator() +: + DateGenerator(JulianUtility::RT_MONTHLY, 0), + m_aiParams(0) + {} + +//--------------------------------------------------------------------- + +t_int32 +ByMonthDayGenerator::getInterval() const { return JulianUtility::RT_DAILY; } + +//--------------------------------------------------------------------- + +t_bool +ByMonthDayGenerator::generate(DateTime * start, JulianPtrArray & dateVector, + DateTime * until) +{ + DateTime * t; + t_int32 i, iMonth = 0; + + PR_ASSERT(start != 0); + PR_ASSERT(m_aiParams != 0); + + if (start == 0 || m_aiParams == 0) + { + return FALSE; + } + + t = new DateTime(start->getTime()); PR_ASSERT(t != 0); + + //if (FALSE) TRACE("t = %s\r\n", t->toString().toCString("")); + + for (i = 0; i < m_iParamsLen; i++) + { + t->setTime(start->getTime()); + + //if (FALSE) TRACE("t = %s\r\n", t->toString().toCString("")); + + if (m_aiParams[i] > 0) + t->add(Calendar::DATE, - (t->get(Calendar::DATE)) + 1); + else + t->findLastDayOfMonth(); + + //if (FALSE) TRACE("t = %s\r\n", t->toString().toCString("")); + + iMonth = t->get(Calendar::MONTH); + + t->add(Calendar::DATE, + (m_aiParams[i] > 0) ? m_aiParams[i] - 1 : m_aiParams[i] + 1); + + //if (FALSE) TRACE("t = %s\r\n", t->toString().toCString("")); + + if (until != 0 && until->isValid() && t->after(until)) + { + delete t; t = 0; + return TRUE; + } + + // make sure in same month + if ((t->after(start) || t->equals(start)) && + (t->get(Calendar::MONTH) == iMonth)) + { + dateVector.Add(new DateTime(t->getTime())); + } + } + delete t; t = 0; + return FALSE; +} +//--------------------------------------------------------------------- + + diff --git a/calendar/modules/core/ical/src/bymgntr.cpp b/calendar/modules/core/ical/src/bymgntr.cpp new file mode 100644 index 00000000000..b99235fb5c2 --- /dev/null +++ b/calendar/modules/core/ical/src/bymgntr.cpp @@ -0,0 +1,97 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +// bymgntr.cpp +// John Sun +// 12:16 PM February 4 1998 + +#include "stdafx.h" +#include "jdefines.h" + +#include +#include "bymgntr.h" +#include "jutility.h" +#include "calendar.h" + +ByMinuteGenerator::ByMinuteGenerator() +: + DateGenerator(JulianUtility::RT_HOURLY, 0), + m_aiParams(0) +{} + +//--------------------------------------------------------------------- + +t_int32 +ByMinuteGenerator::getInterval() const { return JulianUtility::RT_MINUTELY; } + +//--------------------------------------------------------------------- + +t_bool +ByMinuteGenerator::generate(DateTime * start, JulianPtrArray & dateVector, + DateTime * until) +{ + DateTime * t; + t_int32 i; + + PR_ASSERT(start != 0); + PR_ASSERT(m_aiParams != 0); + + if (start == 0 || m_aiParams == 0) + { + return FALSE; + } + + t = new DateTime(start->getTime()); PR_ASSERT(t != 0); + + for (i = 0; i < m_iParamsLen; i++) + { + t->setTime(start->getTime()); + + while (start->get((Calendar::EDateFields) m_iSpan) == + t->get((Calendar::EDateFields) m_iSpan)) + { + // only allow 0-59, no negatives allowed + + t->set(Calendar::MINUTE, m_aiParams[i]); + + /* + // allow negatives (not in spec anymore, so commented out) + if (m_aiParams[i] >= 0) + t->set(Calendar::MINUTE, m_aiParams[i]); + else + t->set(Calendar::MINUTE, 60 + m_aiParams[i]); + */ + + if (until != 0 && until->isValid() && t->after(until)) + { + delete t; t = 0; + return TRUE; + } + else if (t->after(start) || t->equals(start)) + { + dateVector.Add(new DateTime(t->getTime())); + } + + t->add(Calendar::HOUR, 1); + } + } + delete t; t = 0; + return FALSE; +} +//--------------------------------------------------------------------- + diff --git a/calendar/modules/core/ical/src/bymogntr.cpp b/calendar/modules/core/ical/src/bymogntr.cpp new file mode 100644 index 00000000000..8ac7f0b2134 --- /dev/null +++ b/calendar/modules/core/ical/src/bymogntr.cpp @@ -0,0 +1,91 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +// bymogntr.cpp +// John Sun +// 4:21 PM February 3 1998 + +#include "stdafx.h" +#include "jdefines.h" + +#include +#include "bymogntr.h" +#include "jutility.h" + +ByMonthGenerator::ByMonthGenerator() +: + DateGenerator(JulianUtility::RT_YEARLY, 0), + m_aiParams(0) + {} + +//--------------------------------------------------------------------- + +t_int32 +ByMonthGenerator::getInterval() const { return JulianUtility::RT_MONTHLY; } + +//--------------------------------------------------------------------- + +t_bool +ByMonthGenerator::generate(DateTime * start, JulianPtrArray & dateVector, + DateTime * until) +{ + t_int32 i, iMonth = 0; + DateTime * t; + + PR_ASSERT(start != 0); + PR_ASSERT(m_aiParams != 0); + + if (start == 0 || m_aiParams == 0) + { + return FALSE; + } + + t = new DateTime(start->getTime()); PR_ASSERT(t != 0); + + for (i = 0; i < m_iParamsLen; i++) + { + t->setTime(start->getTime()); + + // negative month don't exist, only [1-12] + //if (FALSE) TRACE("t = %s\r\n", t->toString().toCString("")); + + t->add(Calendar::MONTH, m_aiParams[i] - t->get(Calendar::MONTH) - 1); + t->add(Calendar::DATE, - t->get(Calendar::DATE) + 1); + + //if (FALSE) TRACE("t = %s\r\n", t->toString().toCString("")); + + iMonth = t->get(Calendar::MONTH); + + while (t->get(Calendar::MONTH) == iMonth) + { + if (until != 0 && until->isValid() & t->after(until)) + { + delete t; t = 0; + return TRUE; + } + if (t->after(start) || t->equals(start)) + dateVector.Add(new DateTime(t->getTime())); + + t->add(Calendar::DATE, 1); + } + } + delete t; t = 0; + return FALSE; +} +//--------------------------------------------------------------------- + diff --git a/calendar/modules/core/ical/src/bywngntr.cpp b/calendar/modules/core/ical/src/bywngntr.cpp new file mode 100644 index 00000000000..15dac1c4be8 --- /dev/null +++ b/calendar/modules/core/ical/src/bywngntr.cpp @@ -0,0 +1,89 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +// bywngntr.cpp +// John Sun +// 4:23 PM February 3 1998 + +#include "stdafx.h" +#include "jdefines.h" + +#include +#include "bywngntr.h" +#include "jutility.h" + +ByWeekNoGenerator::ByWeekNoGenerator() +: + DateGenerator(JulianUtility::RT_YEARLY, 0), + m_aiParams(0) + {} + +//--------------------------------------------------------------------- + +t_int32 +ByWeekNoGenerator::getInterval() const { return JulianUtility::RT_WEEKLY; } + +//--------------------------------------------------------------------- + +t_bool +ByWeekNoGenerator::generate(DateTime * start, JulianPtrArray & dateVector, + DateTime * until) +{ + DateTime * t; + t_int32 i, k; + + PR_ASSERT(start != 0); + PR_ASSERT(m_aiParams != 0); + + if (start == 0 || m_aiParams == 0) + { + return FALSE; + } + + t = new DateTime(start->getTime()); PR_ASSERT(t != 0); + + for (i = 0; i < m_iParamsLen; i++) + { + t->setTime(start->getTime()); + + t->setByISOWeek(m_aiParams[i]); + + for (k = 0; k < 7; k++) + { + if (until != 0 && until->isValid() && t->after(until) && i == m_iParamsLen - 1) + { + delete t; t = 0; + return TRUE; + } + else if (until != 0 && until->isValid() && t->after(until)) + { + //delete t; + break; + } + if (t->after(start) || t->equals(start)) + dateVector.Add(new DateTime(t->getTime())); + + t->add(Calendar::DAY_OF_YEAR, 1); + + } + } + delete t; t = 0; + return FALSE; +} +//--------------------------------------------------------------------- + diff --git a/calendar/modules/core/ical/src/byydgntr.cpp b/calendar/modules/core/ical/src/byydgntr.cpp new file mode 100644 index 00000000000..446a8ba0450 --- /dev/null +++ b/calendar/modules/core/ical/src/byydgntr.cpp @@ -0,0 +1,102 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +// byydgntr.cpp +// John Sun +// 4:25 PM February 3 1998 + +#include "stdafx.h" +#include "jdefines.h" + +#include +#include "byydgntr.h" +#include "jutility.h" + +ByYearDayGenerator::ByYearDayGenerator() +: + DateGenerator(JulianUtility::RT_YEARLY, 0), + m_aiParams(0) + {} + +//--------------------------------------------------------------------- + +t_int32 +ByYearDayGenerator::getInterval() const { return JulianUtility::RT_DAILY; } + +//--------------------------------------------------------------------- + +t_bool +ByYearDayGenerator::generate(DateTime * start, JulianPtrArray & dateVector, + DateTime * until) +{ + DateTime * t; + t_int32 i, iYear = 0; + + PR_ASSERT(start != 0); + PR_ASSERT(m_aiParams != 0); + + if (start == 0 || m_aiParams == 0) + { + return FALSE; + } + + t = new DateTime(start->getTime()); PR_ASSERT(t != 0); + + //if (FALSE) TRACE("t = %s\r\n", t->toString().toCString("")); + + for (i = 0; i < m_iParamsLen; i++) + { + t->setTime(start->getTime()); + + if (m_aiParams[i] > 0) + { + t->add(Calendar::DAY_OF_YEAR, + - (t->get(Calendar::DAY_OF_YEAR)) + 1); + } + else + { + t->findLastDayOfYear(); + } + + //if (FALSE) TRACE("t = %s\r\n", t->toString().toCString("")); + + iYear = t->get(Calendar::YEAR); + + t->add(Calendar::DAY_OF_YEAR, + (m_aiParams[i] > 0) ? m_aiParams[i] - 1 : m_aiParams[i] + 1); + + //if (FALSE) TRACE("t = %s\r\n", t->toString().toCString("")); + + if (until != 0 && until->isValid() & t->after(until)) + { + delete t; t = 0; + return TRUE; + } + + // make sure in same year + if ((t->after(start) || t->equals(start)) && + (t->get(Calendar::YEAR) == iYear)) + { + dateVector.Add(new DateTime(t->getTime())); + } + } + delete t; t = 0; + return FALSE; +} +//--------------------------------------------------------------------- + diff --git a/calendar/modules/core/ical/src/capiredr.cpp b/calendar/modules/core/ical/src/capiredr.cpp new file mode 100644 index 00000000000..26ec32273d4 --- /dev/null +++ b/calendar/modules/core/ical/src/capiredr.cpp @@ -0,0 +1,540 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +/* + * capiredr.cpp + * John Sun + * 4/16/98 3:42:19 PM + */ + +#include "stdafx.h" +#include "capiredr.h" +#include "nspr.h" +//#include "xp_mcom.h" + +const t_int32 ICalCAPIReader::m_MAXBUFFERSIZE = 1024; +const t_int32 ICalCAPIReader::m_NOMORECHUNKS = 404; +//--------------------------------------------------------------------- + +ICalCAPIReader::ICalCAPIReader() +{ + PR_ASSERT(FALSE); +} + +//--------------------------------------------------------------------- + +void +ICalCAPIReader::AddChunk(UnicodeString * u) +{ + if (m_Chunks == 0) + m_Chunks = new JulianPtrArray(); + PR_ASSERT(m_Chunks != 0); + if (m_Chunks != 0) + { + m_Chunks->Add(u); + } +} + +//--------------------------------------------------------------------- + +ICalCAPIReader::ICalCAPIReader(PRMonitor * monitor, + JulianUtility::MimeEncoding encoding) +{ + m_Monitor = monitor; + m_bFinished = FALSE; + + m_ChunkIndex = 0; + m_Chunks = 0; + m_Init = TRUE; + m_Pos = 0; + m_Mark = 0; + m_ChunkMark = 0; + m_Encoding = encoding; +} + +//--------------------------------------------------------------------- + +void ICalCAPIReader::deleteUnicodeStringVector(JulianPtrArray * stringVector) +{ + t_int32 i; + if (stringVector != 0) + { + for (i = stringVector->GetSize() - 1; i >= 0; i--) + { + delete ((UnicodeString *) stringVector->GetAt(i)); + } + } +} + +//--------------------------------------------------------------------- + +ICalCAPIReader::~ICalCAPIReader() +{ + if (m_Chunks != 0) + { + deleteUnicodeStringVector(m_Chunks); + delete m_Chunks; m_Chunks = 0; + } + //if (m_Buffer != 0) { delete [] m_Buffer; m_Buffer = 0; } + //PR_Exit(); +} + +//--------------------------------------------------------------------- +/* +void ICalCAPIReader::setBuffer(const char * capiChunk) +{ + if (m_Init) + { + strcpy(m_Buffer, capiChunk); + m_BufferSize = strlen(m_Buffer); + m_Init = FALSE; + } + else + { + strcat(m_Buffer + m_BufferSize, capiChunk); + m_BufferSize += strlen(capiChunk); + } +} +*/ +//--------------------------------------------------------------------- + +t_int8 ICalCAPIReader::read(ErrorCode & status) +{ + t_int32 i = 0; + + while (TRUE) + { + if (m_Chunks == 0 || m_Chunks->GetSize() == 0 || + m_ChunkIndex >= m_Chunks->GetSize()) + { + status = m_NOMORECHUNKS; // no more chunks, should block + return -1; + // block? + } + else + { + // read from linked list of UnicodeString's + // delete front string when finished reading from it + + UnicodeString string = *((UnicodeString *) m_Chunks->GetAt(m_ChunkIndex)); + if (m_Pos < string.size()) + { + // return index of this + status = ZERO_ERROR; + + if (m_Encoding == JulianUtility::MimeEncoding_QuotedPrintable) + { + if ((string)[(TextOffset) m_Pos] == '=') + { + if (string.size() >= m_Pos + 3) + { + if (ICalReader::isHex(string[(TextOffset)(m_Pos + 1)]) && + ICalReader::isHex(string[(TextOffset)(m_Pos + 2)])) + { + t_int8 c; + c = ICalReader::convertHex(string[(TextOffset) (m_Pos + 1)], + string[(TextOffset) (m_Pos + 2)]); + // replace the contents of string + //string/removeBetween(m_Pos, 3); + //char sBuf[1]; + //sBuf[0] = c; + //string->insert(m_Pos, sBuf); + m_Pos += 3; + //m_Pos++; + return c; + } + else + { + return (t_int8) (string)[(TextOffset) m_Pos++]; + } + } + else + { + t_int32 lenDiff = string.size() - m_Pos; + char fToken; + char sToken; + t_bool bSetFToken = FALSE; + t_int32 tempIndex = m_ChunkIndex; + UnicodeString token; + + while (TRUE) + { + + // lenDiff = 1, 2 always + // the =XX spans different chunks + // if last chunk, return out of chunks status + if (tempIndex == m_Chunks->GetSize() - 1) + { + status = m_NOMORECHUNKS; + return -1; + } + else + { + UnicodeString nextstring = *((UnicodeString *) m_Chunks->GetAt(tempIndex + 1)); + tempIndex++; + + if (nextstring.size() >= 2) + { + t_int8 c; + if (lenDiff == 2) + { + + fToken = string[(TextOffset) (string.size() - 1)]; + sToken = nextstring[(TextOffset) 0]; + + if (ICalReader::isHex(fToken) && ICalReader::isHex(sToken)) + { + c = ICalReader::convertHex(fToken, sToken); + + m_Pos = 1; + m_ChunkIndex = tempIndex; + bSetFToken = FALSE; + return c; + } + else + { + return (t_int8) (string)[(TextOffset) m_Pos++]; + } + } + else + { + // lenDiff = 1 + + if (bSetFToken) + { + sToken = nextstring[(TextOffset) 0]; + } + else + { + fToken = nextstring[(TextOffset) 0]; + sToken = nextstring[(TextOffset) 1]; + } + + if (ICalReader::isHex(fToken) && ICalReader::isHex(sToken)) + { + c = ICalReader::convertHex(fToken, sToken); + + m_Pos = 2; + m_ChunkIndex = tempIndex; + bSetFToken = FALSE; + return c; + } + else + { + return (t_int8) (string)[(TextOffset) m_Pos++]; + } + } + } + else + { + if (nextstring.size() > 0) + { + if (!bSetFToken) + { + fToken = nextstring[(TextOffset) 0]; + bSetFToken = TRUE; + + } + else + { + sToken = nextstring[(TextOffset) 0]; + + if (ICalReader::isHex(fToken) && ICalReader::isHex(sToken)) + { + char c; + c = ICalReader::convertHex(fToken, sToken); + + m_Pos = 1; + m_ChunkIndex = tempIndex; + bSetFToken = FALSE; + return c; + } + else + { + return (t_int8) (string)[(TextOffset) m_Pos++]; + } + } + } + } + } + } + + } + } + else + { + return (t_int8) (string)[(TextOffset) m_Pos++]; + } + + } + else + { + return (t_int8) (string)[(TextOffset) m_Pos++]; + } + } + else + { + // delete front string from list, try reading from next chunk + m_Pos = 0; + m_ChunkIndex++; + + //delete ((UnicodeString *) m_Chunks->GetAt(i)); + //m_Chunks->RemoveAt(i); + } + } + } + status = 1; + return -1; + /* + if (m_BufferSize > 0) + { + if (m_Pos >= m_BufferSize) + { + status = 1; + return -1; + } + else + { + status = ZERO_ERROR; + return m_Buffer[m_Pos++]; + } + } + else + { + status = 2; + return -1; + } + */ +} + +//--------------------------------------------------------------------- +UnicodeString & +ICalCAPIReader::createLine(t_int32 oldPos, t_int32 oldChunkIndex, + t_int32 newPos, t_int32 newChunkIndex, + UnicodeString & aLine) +{ + PR_ASSERT(oldChunkIndex <= newChunkIndex); + UnicodeString u; + if (oldChunkIndex == newChunkIndex) + { + u = *((UnicodeString *) m_Chunks->GetAt(oldChunkIndex)); + u.extractBetween(oldPos, newPos, aLine); + return aLine; + } + else { + //(oldChunkIndex < newChunkIndex) + + t_int32 i; + UnicodeString v, temp; + u = *((UnicodeString *) m_Chunks->GetAt(oldChunkIndex)); + u.extractBetween(oldPos, u.size(), aLine); + v = *((UnicodeString *) m_Chunks->GetAt(newChunkIndex)); + v.extractBetween(0, newPos, temp); + i = oldChunkIndex + 1; + while (i < newChunkIndex) + { + v = *((UnicodeString *) m_Chunks->GetAt(i)); + aLine += v; + i++; + } + aLine += temp; + return aLine; + } +} + +//--------------------------------------------------------------------- + +UnicodeString & +ICalCAPIReader::readFullLine(UnicodeString & aLine, ErrorCode & status, t_int32 iTemp) +{ + status = ZERO_ERROR; + t_int32 i; + +#if TESTING_ITIPRIG + if (FALSE) TRACE("ICalCAPIReader: waiting to enter monitor\r\n"); +#endif + + PR_EnterMonitor(m_Monitor); + +#if TESTING_ITIPRIG + if (FALSE) TRACE("ICalCAPIReader: in monitor\r\n"); +#endif + + t_int32 oldpos = m_Pos; + t_int32 oldChunkIndex = m_ChunkIndex; + + readLine(aLine, status); + if (status == m_NOMORECHUNKS) + { + // maybe block on monitor here + //PR_Notify(m_Monitor); +#if CAPI_READY + //PR_Yield(); + if (m_bFinished) + { + // do nothing. + } + else + { +#if TESTING_ITIPRIG + if (FALSE) TRACE("ICalCAPIReader: (1) waiting for writeTOCAPIReader to add more chunks\r\n"); +#endif + PR_Wait(m_Monitor, LL_MAXINT); + //PR_Yield(); + } +#else + return aLine; +#endif + } + UnicodeString aSubLine; + while (TRUE) + { + mark(); + i = read(status); + if (status == m_NOMORECHUNKS) + { + // block()? reset()?; + //PR_Notify(m_Monitor); + //PR_ExitMonitor(m_Monitor); +#if CAPI_READY + if (m_bFinished) + { + // do nothing + break; + } + else + { +#if TESTING_ITIPRIG + if (FALSE) TRACE("ICalCAPIReader: (2) waiting for writeTOCAPIReader to add more chunks\r\n"); +#endif + PR_Wait(m_Monitor, LL_MAXINT); + //PR_Yield(); + } +#else + return aLine; +#endif + } + else if (i == ' ') + { +#if TESTING_ITIPRIG + if (FALSE) TRACE("ICalCAPIReader: recursivecall\r\n"); +#endif + aLine += readLine(aSubLine, status); + //PR_Notify(m_Monitor); + //if (FALSE) TRACE("rfl(2) %s\r\n", aLine.toCString("")); + } + else + { +#if TESTING_ITIPRIG + if (FALSE) TRACE("ICalCAPIReader: reset() break out of loop\r\n"); +#endif + reset(); + break; + } + } +#if TESTING_ITIPRIG + if (FALSE) TRACE("readFullLine returned: ---%s---\r\n", aLine.toCString("")); +#endif +#if TESTING_ITIPRIG + TRACE("ICalCAPIReader: leaving monitor\r\n"); +#endif + PR_ExitMonitor(m_Monitor); + + return aLine; +} + +//--------------------------------------------------------------------- + +UnicodeString & +ICalCAPIReader::readLine(UnicodeString & aLine, ErrorCode & status) +{ + status = ZERO_ERROR; + t_int8 c = 0; + t_int32 oldPos = m_Pos; + t_int32 oldChunkIndex = m_ChunkIndex; + + aLine = ""; + + //PR_EnterMonitor(m_Monitor); + + c = read(status); + while (!(FAILURE(status))) + { + if (status == m_NOMORECHUNKS) + { + // block + break; + } + /* Break on '\n', '\r\n', and '\r' */ + else if (c == '\n') + { + break; + } + else if (c == '\r') + { + mark(); + c = read(status); + if (FAILURE(status)) + { + // block(), reset()? + break; + } + else if (c == '\n') + { + break; + } + else + { + reset(); + break; + } + } +#if 1 + aLine += c; + //if (FALSE) TRACE("aLine = %s: -%c,%d-\r\n", aLine.toCString(""), c, c); +#endif + c = read(status); + + } +#if 0 + createLine(oldPos, oldChunkIndex, m_Pos, m_ChunkIndex, aLine); +#endif + + /* + if (FAILURE(status)) + { + PR_Notify(m_Monitor); + PR_ExitMonitor(m_Monitor); + } + */ + + //if (FALSE) TRACE("\treadLine returned %s\r\n", aLine.toCString("")); + return aLine; + + /* + t_int32 lineSize = m_Pos - oldpos; + char * theLine = new char[lineSize]; + PR_ASSERT(theLine != 0); + strncpy(theLine, m_Buffer + oldpos, lineSize); + aLine = theLine; + return aLine; + */ +} + +//--------------------------------------------------------------------- + diff --git a/calendar/modules/core/ical/src/config.mk b/calendar/modules/core/ical/src/config.mk new file mode 100644 index 00000000000..e69de29bb2d diff --git a/calendar/modules/core/ical/src/dategntr.cpp b/calendar/modules/core/ical/src/dategntr.cpp new file mode 100644 index 00000000000..48bed2a999e --- /dev/null +++ b/calendar/modules/core/ical/src/dategntr.cpp @@ -0,0 +1,46 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +// dategntr.cpp +// John Sun +// 12:30 PM February 4 1998 + + +#include "stdafx.h" +#include "jdefines.h" +#include + +//#include +#include "dategntr.h" +//#include "calendar.h" + +//--------------------------------------------------------------------- + +DateGenerator::DateGenerator() +{ + PR_ASSERT(FALSE); +} + +//--------------------------------------------------------------------- + +DateGenerator::DateGenerator(t_int32 span, t_int32 paramsLen) +: m_iSpan(span), m_iParamsLen(paramsLen) +{ +} + +//--------------------------------------------------------------------- diff --git a/calendar/modules/core/ical/src/deftgntr.cpp b/calendar/modules/core/ical/src/deftgntr.cpp new file mode 100644 index 00000000000..19cd065ab13 --- /dev/null +++ b/calendar/modules/core/ical/src/deftgntr.cpp @@ -0,0 +1,83 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +// deftgntr.cpp +// John Sun +// 4:01 PM Febrary 3 1998 + +#include "stdafx.h" +#include "jdefines.h" + +#include +#include "deftgntr.h" +#include "jutility.h" +#include "duration.h" + +//t_int32 DefaultGenerator::m_iParamsLen = 3; + +DefaultGenerator::DefaultGenerator() +: DateGenerator(JulianUtility::RT_MONTHLY, 3), + isActive(FALSE) +{} + +//--------------------------------------------------------------------- + +t_int32 +DefaultGenerator::getInterval() const { return JulianUtility::RT_MONTHLY; } + +//--------------------------------------------------------------------- + +t_bool +DefaultGenerator::generate(DateTime * start, JulianPtrArray & dateVector, + DateTime * until) +{ + t_int32 i; + DateTime * t; + Julian_Duration * d; + + PR_ASSERT(start != 0); + PR_ASSERT(m_aiParams != 0); + + if (start == 0 || m_aiParams == 0) + { + return FALSE; + } + + t = new DateTime(start->getTime()); PR_ASSERT(t != 0); + d = new Julian_Duration(m_aiParams[0], m_aiParams[1]); PR_ASSERT(d != 0); + + dateVector.Add(new DateTime(t->getTime())); + + for (i = 0; i < m_aiParams[2] - 1; i++) + { + t->add(*d); + if (until != 0 && until->isValid() && t->after(until)) + { + //t = NULL; + delete t; t = 0;// replaced above line + delete d; d = 0; + return TRUE; + } + dateVector.Add(new DateTime(t->getTime())); + } + delete t; t = 0; + delete d; d = 0; + return FALSE; +} +//--------------------------------------------------------------------- + diff --git a/calendar/modules/core/ical/src/dprprty.cpp b/calendar/modules/core/ical/src/dprprty.cpp new file mode 100644 index 00000000000..820d6d224ea --- /dev/null +++ b/calendar/modules/core/ical/src/dprprty.cpp @@ -0,0 +1,183 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +// dprprty.cpp +// John Sun +// 3:15 PM February 12 1998 + +#include "stdafx.h" +#include "jdefines.h" + +#include "dprprty.h" +#include "datetime.h" +#include "prprty.h" +#include "keyword.h" + +//--------------------------------------------------------------------- +// private never use + +DateTimeProperty::DateTimeProperty(): +m_DateTime(-1) +{ + PR_ASSERT(FALSE); +} + +//--------------------------------------------------------------------- + +DateTimeProperty::DateTimeProperty(const DateTimeProperty & that) +{ + setParameters(that.m_vParameters); + m_DateTime = that.m_DateTime; +} + +//--------------------------------------------------------------------- + +DateTimeProperty::DateTimeProperty(DateTime value, JulianPtrArray * parameters) +: StandardProperty(parameters) +{ + //PR_ASSERT(value != 0); + //m_string = *((UnicodeString *) value); + m_DateTime = value; +} +//--------------------------------------------------------------------- + +DateTimeProperty::~DateTimeProperty() +{ + //delete m_DateTime; + //deleteICalParameterVector(m_vParameters); + //delete m_vParameters; m_vParameters = 0; +} + +//--------------------------------------------------------------------- + +void * DateTimeProperty::getValue() const +{ + return (void *) &m_DateTime; +} + +//--------------------------------------------------------------------- + +void DateTimeProperty::setValue(void * value) +{ + PR_ASSERT(value != 0); + if (value != 0) + { + m_DateTime = *((DateTime *) value); + } +} + +//--------------------------------------------------------------------- + +ICalProperty * DateTimeProperty::clone(JLog * initLog) +{ + if (initLog) {} // NOTE: Remove later to avoid warnings + return new DateTimeProperty(*this); +} + +//--------------------------------------------------------------------- + +t_bool DateTimeProperty::isValid() +{ + //if (m_DateTime == 0) + // return FALSE; + //return m_DateTime->isValid(); + return m_DateTime.isValid(); +} + +//--------------------------------------------------------------------- + +UnicodeString & DateTimeProperty::toString(UnicodeString & out) +{ + + //PR_ASSERT(m_DateTime != 0); + + //if (m_DateTime->isValid() + out = m_DateTime.toString(); + //else + // out = "NULL"; + return out; +} +//--------------------------------------------------------------------- + +UnicodeString & +DateTimeProperty::toString(UnicodeString & dateFmt, UnicodeString & out) +{ + out = m_DateTime.strftime(dateFmt); + if (out.size() > 0) + return out; + else + return toString(out); +} + +//--------------------------------------------------------------------- + +UnicodeString & DateTimeProperty::toExportString(UnicodeString & out) +{ + //PR_ASSERT(m_DateTime != 0); + out = m_DateTime.toISO8601(); + return out; +} +//--------------------------------------------------------------------- + +UnicodeString & +DateTimeProperty::toICALString(UnicodeString & out) +{ + UnicodeString name; + return toICALString(name, out); +} + +//--------------------------------------------------------------------- + +UnicodeString & +DateTimeProperty::toICALString(UnicodeString & sProp, + UnicodeString & out) +{ + ICalParameter * aName; + UnicodeString sVal; + sVal = toExportString(sVal); + + out = ""; + t_int32 size = 0; + t_int32 i; + + if (m_vParameters != 0) + size = m_vParameters->GetSize(); + if (sVal.size() > 0) + { + UnicodeString u; + out = sProp; + for (i = 0; i < size; i++) + { + aName = (ICalParameter *) m_vParameters->GetAt(i); + u = aName->getParameterName(u); + + // don't print the TZID and VALUE parameters + // thus it will only print in Z time and VALUE assumed to be DATETIME + if ((u.compareIgnoreCase(JulianKeyword::Instance()->ms_sTZID) != 0) && + (u.compareIgnoreCase(JulianKeyword::Instance()->ms_sVALUE) != 0)) + out += aName->toICALString(u); + + } + out += ':'; out += sVal; out += JulianKeyword::Instance()->ms_sLINEBREAK; + } + //if (FALSE) TRACE("out = %s\r\n", out.toCString("")); + return out; +} + +//--------------------------------------------------------------------- + diff --git a/calendar/modules/core/ical/src/duprprty.cpp b/calendar/modules/core/ical/src/duprprty.cpp new file mode 100644 index 00000000000..02fb5a3f4c9 --- /dev/null +++ b/calendar/modules/core/ical/src/duprprty.cpp @@ -0,0 +1,133 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +// duprprty.cpp +// John Sun +// 3:15 PM February 12 1998 + +#include "stdafx.h" +#include "jdefines.h" + +#include "duprprty.h" +#include "duration.h" +#include "prprty.h" + +//--------------------------------------------------------------------- + +// private never use +DurationProperty::DurationProperty() +{ + PR_ASSERT(FALSE); +} + +//--------------------------------------------------------------------- + +DurationProperty::DurationProperty(const DurationProperty & that) +{ + setParameters(that.m_vParameters); + m_Duration = that.m_Duration; +} + +//--------------------------------------------------------------------- + +DurationProperty::DurationProperty(Julian_Duration value, JulianPtrArray * parameters) +: StandardProperty(parameters) +{ + //PR_ASSERT(value != 0); + //m_string = *((UnicodeString *) value); + m_Duration = value; +} +//--------------------------------------------------------------------- + +DurationProperty::~DurationProperty() +{ + //delete m_Duration; + //deleteICalParameterVector(m_vParameters); + //delete m_vParameters; m_vParameters = 0; +} + +//--------------------------------------------------------------------- + +void * DurationProperty::getValue() const +{ + return (void *) &m_Duration; +} + +//--------------------------------------------------------------------- + +void DurationProperty::setValue(void * value) +{ + PR_ASSERT(value != 0); + if (value != 0) + { + m_Duration = *((Julian_Duration *) value); + } +} + +//--------------------------------------------------------------------- + +ICalProperty * DurationProperty::clone(JLog * initLog) +{ + if (initLog) {} // NOTE: Remove later to avoid warnings + return new DurationProperty(*this); +} + +//--------------------------------------------------------------------- + +t_bool DurationProperty::isValid() +{ + //if (m_Duration == 0) + // return FALSE; + //return m_Duration->isValid(); + return m_Duration.isValid(); +} + +//--------------------------------------------------------------------- + +UnicodeString & DurationProperty::toString(UnicodeString & out) +{ + + //PR_ASSERT(m_Duration != 0); + + //if (m_Duration->isValid() + out = m_Duration.toString(); + //else + // out = "NULL"; + return out; +} + +//--------------------------------------------------------------------- + +UnicodeString & +DurationProperty::toString(UnicodeString & dateFmt, UnicodeString & out) +{ + // NOTE: remove it later, gets rid of compiler warning + if (dateFmt.size() > 0) {} + return toString(out); +} +//--------------------------------------------------------------------- + +UnicodeString & DurationProperty::toExportString(UnicodeString & out) +{ + //PR_ASSERT(m_Duration != 0); + out = m_Duration.toICALString(); + return out; +} +//--------------------------------------------------------------------- + + diff --git a/calendar/modules/core/ical/src/freebusy.cpp b/calendar/modules/core/ical/src/freebusy.cpp new file mode 100644 index 00000000000..31074e40090 --- /dev/null +++ b/calendar/modules/core/ical/src/freebusy.cpp @@ -0,0 +1,757 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +// freebusy.cpp +// John Sun +// 6:35 PM Febuary 18 1998 + +#include "stdafx.h" +#include "jdefines.h" +#include "freebusy.h" +#include "icalcomp.h" +#include "unistrto.h" +#include "jlog.h" +#include "jutility.h" +#include "keyword.h" +//--------------------------------------------------------------------- +const t_int32 Freebusy::ms_cFreebusyType = 'T'; +const t_int32 Freebusy::ms_cFreebusyPeriod = 'P'; +const t_int32 Freebusy::ms_iDEFAULT_TYPE= FB_TYPE_BUSY; + +#if 0 +const t_int32 Freebusy::ms_cFreebusyStatus = 'S'; +const t_int32 Freebusy::ms_iDEFAULT_STATUS= FB_STATUS_BUSY; +#endif + +//UnicodeString Freebusy::m_strDefaultFmt = "\tTYPE= ^T STATUS = ^S ^P\r\n"; +//const UnicodeString Freebusy::JulianKeyword::Instance()->ms_sDEFAULT_TYPE = JulianKeyword::Instance()->ms_sBUSY; +//const UnicodeString Freebusy::JulianKeyword::Instance()->ms_sDEFAULT_STATUS = JulianKeyword::Instance()->ms_sBUSY; +//static UnicodeString s_sComma = JulianKeyword::Instance()->ms_sCOMMA_SYMBOL; + +//--------------------------------------------------------------------- + +Freebusy::FB_TYPE +Freebusy::stringToType(UnicodeString & sType) +{ + t_int32 hashCode = sType.hashCode(); + + if (JulianKeyword::Instance()->ms_ATOM_BUSY == hashCode) return FB_TYPE_BUSY; + else if (JulianKeyword::Instance()->ms_ATOM_FREE == hashCode) return FB_TYPE_FREE; + // added 4-28-98 + else if (JulianKeyword::Instance()->ms_ATOM_BUSY_UNAVAILABLE == hashCode) + return FB_TYPE_BUSY_UNAVAILABLE; + else if (JulianKeyword::Instance()->ms_ATOM_BUSY_TENTATIVE == hashCode) + return FB_TYPE_BUSY_TENTATIVE; + else if (ICalProperty::IsXToken(sType)) + return FB_TYPE_XPARAMVAL; + else return FB_TYPE_INVALID; +} + +//--------------------------------------------------------------------- + +UnicodeString & +Freebusy::typeToString(Freebusy::FB_TYPE type, UnicodeString & out) +{ + switch(type) + { + case FB_TYPE_BUSY: out = JulianKeyword::Instance()->ms_sBUSY; break; + case FB_TYPE_FREE: out = JulianKeyword::Instance()->ms_sFREE; break; + // added 4-28-98 + case FB_TYPE_BUSY_UNAVAILABLE: out = JulianKeyword::Instance()->ms_sBUSY_UNAVAILABLE; break; + case FB_TYPE_BUSY_TENTATIVE: out = JulianKeyword::Instance()->ms_sBUSY_TENTATIVE; break; + case FB_TYPE_XPARAMVAL: out = JulianKeyword::Instance()->ms_sXPARAMVAL; break; + default: + // return default BUSY + out = JulianKeyword::Instance()->ms_sBUSY; + break; + } + return out; +} + +//--------------------------------------------------------------------- +#if 0 +Freebusy::FB_STATUS +Freebusy::stringToStatus(UnicodeString & sStatus) +{ + t_int32 hashCode = sStatus.hashCode(); + + if (JulianKeyword::Instance()->ms_ATOM_BUSY == hashCode) return FB_STATUS_BUSY; + else if (JulianKeyword::Instance()->ms_ATOM_UNAVAILABLE == hashCode) return FB_STATUS_UNAVAILABLE; + else if (JulianKeyword::Instance()->ms_ATOM_TENTATIVE == hashCode) return FB_STATUS_TENTATIVE; + else return FB_STATUS_INVALID; +} + +//--------------------------------------------------------------------- + +UnicodeString & +Freebusy::statusToString(Freebusy::FB_STATUS status, UnicodeString & out) +{ + switch(status) + { + case FB_STATUS_BUSY: out = JulianKeyword::Instance()->ms_sBUSY; break; + case FB_STATUS_UNAVAILABLE: out = JulianKeyword::Instance()->ms_sUNAVAILABLE; break; + case FB_STATUS_TENTATIVE: out = JulianKeyword::Instance()->ms_sTENTATIVE; break; + default: + // return default BUSY + out = JulianKeyword::Instance()->ms_sBUSY; + break; + } + return out; +} +#endif +//--------------------------------------------------------------------- +// TODO: Finish +void Freebusy::parsePeriod(UnicodeString & s, JulianPtrArray * vTimeZones) +{ + UnicodeStringTokenizer * stMult; + //UnicodeString delim = ","; + UnicodeString sPeriod; + //UnicodeString sPeriodStart; + //UnicodeString sPeriodEnd; + Period * p; + ErrorCode status = ZERO_ERROR; + + if (vTimeZones) + { + } + stMult = new UnicodeStringTokenizer(s, + JulianKeyword::Instance()->ms_sCOMMA_SYMBOL); + PR_ASSERT(stMult != 0); + if (stMult != 0) + { + while (stMult->hasMoreTokens()) + { + sPeriod = stMult->nextToken(sPeriod, status); + sPeriod.trim(); + //if (FALSE) TRACE("sPeriod = %s\r\n", sPeriod.toCString("")); + // TODO: check that period start/end always uses UTC + + p = new Period(sPeriod); + PR_ASSERT(p != 0); + if (p != 0) + { + if (!p->isValid()) + { + if (m_Log) m_Log->logError(JulianLogErrorMessage::Instance()->ms_iFreebusyPeriodInvalid, + JulianKeyword::Instance()->ms_sFREEBUSY, sPeriod, 200); + } + else + { + //sPeriodStart = Period::getStartTimeString(sPeriod, sPeriodStart); + //sPeriodEnd = Period::getEndTimeString(sPeriod, sPeriodEnd); + addPeriod(p); + } + delete p; p = 0; + } + } + delete stMult; stMult = 0; + } +} +//--------------------------------------------------------------------- +void Freebusy::setParam(UnicodeString & paramName, UnicodeString & paramVal) +{ + t_int32 i; + if (paramName.size() == 0) + { + if (m_Log) m_Log->logError(JulianLogErrorMessage::Instance()->ms_iInvalidParameterName, + JulianKeyword::Instance()->ms_sFREEBUSY, paramName, 200); + } + else + { + t_int32 hashCode = paramName.hashCode(); + + if (JulianKeyword::Instance()->ms_ATOM_FBTYPE == hashCode) + { + i = Freebusy::stringToType(paramVal); + if (i < 0) + { + if (m_Log) m_Log->logError(JulianLogErrorMessage::Instance()->ms_iInvalidParameterValue, + JulianKeyword::Instance()->ms_sFREEBUSY, paramName, paramVal, 200); + } + else + { + if (getType() >= 0) + { + if (m_Log) m_Log->logError(JulianLogErrorMessage::Instance()->ms_iDuplicatedParameter, + JulianKeyword::Instance()->ms_sFREEBUSY, paramName, 100); + } + setType((Freebusy::FB_TYPE) i); + } + + } +#if 0 + else if (JulianKeyword::Instance()->ms_ATOM_BSTAT == hashCode) + { + i = Freebusy::stringToStatus(paramVal); + if (i < 0) + { + if (m_Log) m_Log->logError(JulianLogErrorMessage::Instance()->ms_iInvalidParameterValue, + JulianKeyword::Instance()->ms_sFREEBUSY, paramName, paramVal, 200); + } + else + { + if (getStatus() >= 0) + { + if (m_Log) m_Log->logError(JulianLogErrorMessage::Instance()->ms_iDuplicatedParameter, + JulianKeyword::Instance()->ms_sFREEBUSY, paramName, 100); + } + setStatus((Freebusy::FB_STATUS) i); + } + } +#endif + else if (ICalProperty::IsXToken(paramName)) + { + if (m_Log) m_Log->logError(JulianLogErrorMessage::Instance()->ms_iXTokenParamIgnored, + JulianKeyword::Instance()->ms_sFREEBUSY, paramName, 100); + } + else + { + // NOTE: what about optional parameters?? THERE ARE NONE. + if (m_Log) m_Log->logError(JulianLogErrorMessage::Instance()->ms_iInvalidParameterName, + JulianKeyword::Instance()->ms_sFREEBUSY, paramName, 200); + } + } +} +//--------------------------------------------------------------------- +void Freebusy::selfCheck() +{ + if (getType() < 0 || getType() > FB_TYPE_LENGTH) + setDefaultProps(FB_PROPS_TYPE); +#if 0 + else if (getStatus() < 0 || getStatus() > FB_STATUS_LENGTH) + setDefaultProps(FB_PROPS_STATUS); +#endif + // NOTE: selfcheck each period???, no need since addPeriod auto checks?? +} +//--------------------------------------------------------------------- +void Freebusy::setDefaultProps(Freebusy::FB_PROPS prop) +{ + switch (prop) + { + case FB_PROPS_TYPE: setType((Freebusy::FB_TYPE) ms_iDEFAULT_TYPE); return; +#if 0 + case FB_PROPS_STATUS: setStatus((Freebusy::FB_STATUS) ms_iDEFAULT_STATUS); return; +#endif + default: return; + } +} +//--------------------------------------------------------------------- +void Freebusy::sortPeriods() +{ + if (m_vPeriod != 0) + m_vPeriod->QuickSort(Period::ComparePeriods); +} +//--------------------------------------------------------------------- +void Freebusy::sortPeriodsByEndTime() +{ + if (m_vPeriod != 0) + m_vPeriod->QuickSort(Period::ComparePeriodsByEndTime); +} +//--------------------------------------------------------------------- + +// private never use +#if 0 +Freebusy::Freebusy() +{ + PR_ASSERT(FALSE); +} +#endif + +//--------------------------------------------------------------------- + +Freebusy::Freebusy(JLog * initLog) +: m_Type(ms_iDEFAULT_TYPE), +#if 0 + m_Status(ms_iDEFAULT_STATUS), +#endif + m_vPeriod(0), m_Log(initLog) +{ + //PR_ASSERT(initLog != 0); +} + +//--------------------------------------------------------------------- +Freebusy::Freebusy(Freebusy & that) +: m_vPeriod(0) +{ + t_int32 i; + + m_Type = that.m_Type; +#if 0 + m_Status = that.m_Status; +#endif + if (that.m_vPeriod != 0) + { + m_vPeriod = new JulianPtrArray(); + PR_ASSERT(m_vPeriod != 0); + if (m_vPeriod != 0) + { + for (i = 0; i < that.m_vPeriod->GetSize(); i++) + { + Period * p = (Period *) (that.m_vPeriod->GetAt(i)); + PR_ASSERT(p != 0); + if (p != 0) + { + addPeriod(p); + } + } + } + } +} +//--------------------------------------------------------------------- +Freebusy::~Freebusy() +{ + if (m_vPeriod != 0) + { + ICalProperty::deletePeriodVector(m_vPeriod); + delete m_vPeriod; m_vPeriod = 0; + } +} + +//--------------------------------------------------------------------- +ICalProperty * +Freebusy::clone(JLog * initLog) +{ + m_Log = initLog; + //PR_ASSERT(m_Log != 0); + return new Freebusy(*this); +} +//--------------------------------------------------------------------- + +void Freebusy::addPeriod(Period * p) +{ + PR_ASSERT(p != 0); + if (m_vPeriod == 0) + m_vPeriod = new JulianPtrArray(); + PR_ASSERT(m_vPeriod != 0); + if (m_vPeriod != 0 && p != 0) + { + m_vPeriod->Add(new Period(*p)); + } +} + +//--------------------------------------------------------------------- +DateTime Freebusy::startOfFreebusyPeriod() +{ + t_int32 i; + DateTime d(-1); + if (m_vPeriod != 0) + { + i = m_vPeriod->GetSize(); + + if (i > 0) + { + sortPeriods(); + Period * p = (Period *) m_vPeriod->GetAt(0); + d = p->getStart(); + return d; + } + else + { + // NOTE: No periods in vector, so returning invalid datetime + return d; + } + } + else + { + // NOTE: No periods in vector, so returning invalid datetime + return d; + } +} +//--------------------------------------------------------------------- +DateTime Freebusy::endOfFreebusyPeriod() +{ + t_int32 i; + DateTime d(-1); + Julian_Duration du(-1, -1, -1, -1, -1, -1, -1); + if (m_vPeriod != 0) + { + i = m_vPeriod->GetSize(); + if (i > 0) + { + sortPeriodsByEndTime(); + Period * p = (Period *) m_vPeriod->GetAt(i - 1); + if (p->getEnd().isValid()) + { + d = p->getEnd(); + return d; + } + else + { + d = p->getStart(); + du = p->getDuration(); + d.add(du); + return d; + } + //return p->getEndingTime(d); + } + else + { + // NOTE: No periods in vector, so returning invalid datetime + return d; + } + } + else + { + // NOTE: No periods in vector, so returning invalid datetime + return d; + } +} +//--------------------------------------------------------------------- +void Freebusy::parse(UnicodeString & in) +{ + UnicodeString propName; + UnicodeString propVal; + JulianPtrArray * parameters = new JulianPtrArray(); + PR_ASSERT(parameters != 0); + if (parameters != 0) + { + ICalProperty::parsePropertyLine(in, propName, propVal, parameters); + + parse(propVal, parameters); + + ICalProperty::deleteICalParameterVector(parameters); + delete parameters; parameters = 0; + } +} +//--------------------------------------------------------------------- +void Freebusy::parse(UnicodeString & sPeriods, JulianPtrArray * parameters, + JulianPtrArray * vTimeZones) +{ + t_int32 i; + ICalParameter * ip; + UnicodeString pName; + UnicodeString pVal; + if (sPeriods.size() == 0) + { + } + else + { + parsePeriod(sPeriods, vTimeZones); + if (parameters != 0) + { + for (i = 0; i < parameters->GetSize(); i++) + { + ip = (ICalParameter *) parameters->GetAt(i); + setParam(ip->getParameterName(pName), ip->getParameterValue(pVal)); + } + } + } + + sortPeriods(); + selfCheck(); +} +//--------------------------------------------------------------------- +void Freebusy::normalizePeriods() +{ + sortPeriodsByEndTime(); + t_int32 size = 0; + t_int32 i; + Period * p1; + Period * p2; + Period * pUnion; + + if (m_vPeriod != 0) + { + size = m_vPeriod->GetSize(); + for (i = size -1; i >= 0; i--) + { + p1 = (Period *) m_vPeriod->GetAt(i); PR_ASSERT(p1 != 0); + if (i - 1 >= 0) + { + p2 = (Period *) m_vPeriod->GetAt(i - 1); PR_ASSERT(p2 != 0); + if (Period::IsConnectedPeriods(*p1, *p2)) + { + pUnion = new Period(); PR_ASSERT(pUnion != 0); + if (pUnion != 0) + { + Period::Union(*p1, *p2, *pUnion); + delete p1; p1 = 0; + m_vPeriod->RemoveAt(i); // remove p1 + delete p2; p2 = 0; + m_vPeriod->RemoveAt(i - 1); // remove p2 + //removePeriod(p1); p1 = 0; + //removePeriod(p2); p2 = 0; + m_vPeriod->InsertAt(i -1, pUnion); + } + } + } + } + } +} + +//--------------------------------------------------------------------- + +t_bool Freebusy::isValid() +{ + if (m_vPeriod == 0 || m_vPeriod->GetSize() == 0) + return FALSE; + return TRUE; +} + +//--------------------------------------------------------------------- + +UnicodeString & Freebusy::toString(UnicodeString & out) +{ + out = toString(JulianFormatString::Instance()->ms_FreebusyStrDefaultFmt, out); + return out; +} + +//--------------------------------------------------------------------- + +UnicodeString & +Freebusy::toString(UnicodeString & strFmt, UnicodeString & out) +{ + if (strFmt.size() == 0 && JulianFormatString::Instance()->ms_FreebusyStrDefaultFmt.size() > 0) + { + // if empty string, use default + return toString(out); + } + + UnicodeString into; + t_int32 i,j; + //char * c = strFmt.toCString(""); + out = ""; + for ( i = 0; i < strFmt.size(); ) + { + + // NOTE: changed from % to ^ for freebusy + /// + /// If there's a special formatting character, + /// handle it. Otherwise, just emit the supplied + /// character. + /// + into = ""; + j = strFmt.indexOf('^', i); + if ( -1 != j) + { + if (j > i) + { + out += strFmt.extractBetween(i,j,into); + } + i = j + 1; + if (strFmt.size() > i) + { + out += toStringChar(strFmt[(TextOffset) i], into); + i++; + } + } + else + { + out += strFmt.extractBetween(i, strFmt.size(),into); + break; + } + } + return out; +} + +//--------------------------------------------------------------------- + +UnicodeString & +Freebusy::toStringChar(t_int32 c, UnicodeString & out) +{ + switch ( c ) + { + case ms_cFreebusyType: + return typeToString(getType(), out); +#if 0 + case ms_cFreebusyStatus: + return statusToString(getStatus(), out); +#endif + case ms_cFreebusyPeriod: + if (m_vPeriod != 0) + { + Period * p; + t_int32 i; + for (i = 0; i < m_vPeriod->GetSize(); i++) + { + p = (Period *) m_vPeriod->GetAt(i); + if (i < m_vPeriod->GetSize() -1) + { + out += p->toString(); + out += ','; + } + else + out += p->toString(); + } + } + return out; + default: + return out; + } +}// end of +//--------------------------------------------------------------------- + +UnicodeString & +Freebusy::toICALString(UnicodeString & sProp, UnicodeString & out) +{ + // NOTE: Remove later, to avoid warning + if (sProp.size() > 0) {} + return toICALString(out); +} + +//--------------------------------------------------------------------- +UnicodeString & Freebusy::toICALString(UnicodeString & out) +{ + UnicodeString s, u; + t_int32 i; + + out = JulianKeyword::Instance()->ms_sFREEBUSY; + s = typeToString(getType(), s); + out += ICalProperty::parameterToCalString(JulianKeyword::Instance()->ms_sFBTYPE, s, u); +#if 0 + s = statusToString(getStatus(), s); + out += ICalProperty::parameterToCalString(JulianKeyword::Instance()->ms_sBSTAT, s, u); +#endif + out += ":"; + if (m_vPeriod != 0) + { + for (i = 0; i < m_vPeriod->GetSize(); i++) + { + Period * p = (Period *) m_vPeriod->GetAt(i); + + if (i < m_vPeriod->GetSize() -1) + { + out += p->toICALString(); + out += JulianKeyword::Instance()->ms_sCOMMA_SYMBOL; + } + else + out += p->toICALString(); + } + } + out += JulianKeyword::Instance()->ms_sLINEBREAK; + out = ICalProperty::multiLineFormat(out); + return out; +} +//--------------------------------------------------------------------- +void Freebusy::setParameters(JulianPtrArray * parameters) +{ + t_int32 i; + ICalParameter * ip; + UnicodeString pName; + UnicodeString pVal; + if (parameters != 0) + { + for (i = 0; i < parameters->GetSize(); i++) + { + ip = (ICalParameter *) parameters->GetAt(i); + setParam(ip->getParameterName(pName), ip->getParameterValue(pVal)); + } + } +} +//--------------------------------------------------------------------- +// NOTE: assumes normalized periods +// TODO: verify it works +/* +t_bool Freebusy::IsInside(DateTime start, DateTime end) +{ + PR_ASSERT(m_vPeriod != 0); + t_int32 i; + Period * p; + if (m_vPeriod != 0) + { + for (i = 0; i < m_vPeriod->GetSize(); i++) + { + p = (Period *) m_vPeriod->GetAt(i); + if (!p->isInside(start, end)) + return FALSE; + } + } + return TRUE; +} +*/ +//--------------------------------------------------------------------- +// TODO: update method +//void update() +//--------------------------------------------------------------------- +// TODO: verify it works +/* +void Freebusy::clipOutOfBounds(DateTime start, DateTime end) +{ + PR_ASSERT(!start.afterDateTime(end)); + Period * p; + Period * pShrunk; + t_int32 i; + + if (m_vPeriod != 0) + { + for (i = m_vPeriod->GetSize() - 1; i >= 0; i--) + { + p = (Period *) m_vPeriod->GetAt(i); + if (!p->isInside(start, end)) + { + if (p->isIntersecting(start, end)) + { + pShrunk = new Period(); PR_ASSERT(pShrunk != 0); + Period::Intersection(*p, start, end, *pShrunk); + addPeriod(pShrunk); + } + removePeriod(p); p = 0; + } + } + } +} +*/ +//--------------------------------------------------------------------- +int Freebusy::CompareFreebusy(const void * a, const void * b) +{ + Freebusy * fa = *(Freebusy **) a; + Freebusy * fb = *(Freebusy **) b; + + PR_ASSERT(fa->isValid() && fb->isValid()); + Period * pA = (Period *) fa->getPeriod()->GetAt(0); + Period * pB = (Period *) fb->getPeriod()->GetAt(0); + return Period::ComparePeriods(&pA, &pB); +} +//--------------------------------------------------------------------- + +t_bool +Freebusy::HasSameParams(Freebusy * f1, Freebusy * f2) +{ + PR_ASSERT(f1 != 0 && f2 != 0); + if (f1 == 0 || f2 == 0) + { + // BOTH null returns FALSE + return FALSE; + } +#if 0 + return ((f1->getType() == f2->getType()) && + (f1->getStatus() == f2->getStatus())); +#else + return (f1->getType() == f2->getType()); +#endif +} + +//--------------------------------------------------------------------- + +void +Freebusy::addAllPeriods(JulianPtrArray * periods) +{ + Period * p; + t_int32 i; + if (periods != 0) + { + for (i = 0; i < periods->GetSize(); i++) + { + p = (Period *) periods->GetAt(i); + addPeriod(p); + } + } +} +//--------------------------------------------------------------------- + + diff --git a/calendar/modules/core/ical/src/functbl.cpp b/calendar/modules/core/ical/src/functbl.cpp new file mode 100644 index 00000000000..26d6d7b8ec6 --- /dev/null +++ b/calendar/modules/core/ical/src/functbl.cpp @@ -0,0 +1,137 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the 'NPL'); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an 'AS IS' basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +/* + * functbl.cpp + * John Sun + * 7/27/98 1:59:53 PM + */ + +#include "stdafx.h" +#include "jdefines.h" + +#include "keyword.h" +#include "functbl.h" +#include "valarm.h" + +//--------------------------------------------------------------------- + +JulianFunctionTable * JulianFunctionTable::m_Instance = 0; + +//--------------------------------------------------------------------- + +JulianFunctionTable::JulianFunctionTable() +{ + + alarmStoreTable[0].set(JulianKeyword::Instance()->ms_ATOM_ACTION.hashCode(), &VAlarm::storeAction); + alarmStoreTable[1].set(JulianKeyword::Instance()->ms_ATOM_ACTION.hashCode(), &VAlarm::storeAction); + alarmStoreTable[2].set(JulianKeyword::Instance()->ms_ATOM_ATTACH.hashCode(), &VAlarm::storeAttach); + alarmStoreTable[3].set(JulianKeyword::Instance()->ms_ATOM_ATTENDEE.hashCode(), &VAlarm::storeAttendee); + alarmStoreTable[4].set(JulianKeyword::Instance()->ms_ATOM_DESCRIPTION.hashCode(), &VAlarm::storeDescription); + alarmStoreTable[5].set(JulianKeyword::Instance()->ms_ATOM_DURATION.hashCode(), &VAlarm::storeDuration); + alarmStoreTable[6].set(JulianKeyword::Instance()->ms_ATOM_REPEAT.hashCode(), &VAlarm::storeRepeat); + alarmStoreTable[7].set(JulianKeyword::Instance()->ms_ATOM_SUMMARY.hashCode(), &VAlarm::storeSummary); + alarmStoreTable[8].set(JulianKeyword::Instance()->ms_ATOM_TRIGGER.hashCode(), &VAlarm::storeTrigger); + alarmStoreTable[9].set(0,0); + + tbeStoreTable[0].set(JulianKeyword::Instance()->ms_ATOM_ATTACH.hashCode(), &TimeBasedEvent::storeAttach); + tbeStoreTable[1].set(JulianKeyword::Instance()->ms_ATOM_ATTENDEE.hashCode(), &TimeBasedEvent::storeAttendees); + tbeStoreTable[2].set(JulianKeyword::Instance()->ms_ATOM_CATEGORIES.hashCode(), &TimeBasedEvent::storeCategories); + tbeStoreTable[3].set(JulianKeyword::Instance()->ms_ATOM_CLASS.hashCode(), &TimeBasedEvent::storeClass); + tbeStoreTable[4].set(JulianKeyword::Instance()->ms_ATOM_COMMENT.hashCode(), &TimeBasedEvent::storeComment); + tbeStoreTable[5].set(JulianKeyword::Instance()->ms_ATOM_CONTACT.hashCode(), &TimeBasedEvent::storeContact); + tbeStoreTable[6].set(JulianKeyword::Instance()->ms_ATOM_CREATED.hashCode(), &TimeBasedEvent::storeCreated); + tbeStoreTable[7].set(JulianKeyword::Instance()->ms_ATOM_DESCRIPTION.hashCode(), &TimeBasedEvent::storeDescription); + tbeStoreTable[8].set(JulianKeyword::Instance()->ms_ATOM_DTSTART.hashCode(), &TimeBasedEvent::storeDTStart); + tbeStoreTable[9].set(JulianKeyword::Instance()->ms_ATOM_DTSTAMP.hashCode(), &TimeBasedEvent::storeDTStamp); + tbeStoreTable[10].set(JulianKeyword::Instance()->ms_ATOM_EXDATE.hashCode(), &TimeBasedEvent::storeExDate); + tbeStoreTable[11].set(JulianKeyword::Instance()->ms_ATOM_EXRULE.hashCode(), &TimeBasedEvent::storeExRule); + tbeStoreTable[12].set(JulianKeyword::Instance()->ms_ATOM_LASTMODIFIED.hashCode(), &TimeBasedEvent::storeLastModified); + tbeStoreTable[13].set(JulianKeyword::Instance()->ms_ATOM_ORGANIZER.hashCode(), &TimeBasedEvent::storeOrganizer); + tbeStoreTable[14].set(JulianKeyword::Instance()->ms_ATOM_RDATE.hashCode(), &TimeBasedEvent::storeRDate); + tbeStoreTable[15].set(JulianKeyword::Instance()->ms_ATOM_RRULE.hashCode(), &TimeBasedEvent::storeRRule); + tbeStoreTable[16].set(JulianKeyword::Instance()->ms_ATOM_RECURRENCEID.hashCode(), &TimeBasedEvent::storeRecurrenceID); + tbeStoreTable[17].set(JulianKeyword::Instance()->ms_ATOM_RELATEDTO.hashCode(), &TimeBasedEvent::storeRelatedTo); + tbeStoreTable[18].set(JulianKeyword::Instance()->ms_ATOM_REQUESTSTATUS.hashCode(), &TimeBasedEvent::storeRequestStatus); + tbeStoreTable[19].set(JulianKeyword::Instance()->ms_ATOM_SEQUENCE.hashCode(), &TimeBasedEvent::storeSequence); + tbeStoreTable[20].set(JulianKeyword::Instance()->ms_ATOM_STATUS.hashCode(), &TimeBasedEvent::storeStatus); + tbeStoreTable[21].set(JulianKeyword::Instance()->ms_ATOM_SUMMARY.hashCode(), &TimeBasedEvent::storeSummary); + tbeStoreTable[22].set(JulianKeyword::Instance()->ms_ATOM_UID.hashCode(), &TimeBasedEvent::storeUID); + tbeStoreTable[23].set(JulianKeyword::Instance()->ms_ATOM_URL.hashCode(), &TimeBasedEvent::storeURL); + tbeStoreTable[24].set(0,0); + + tzStoreTable[0].set(JulianKeyword::Instance()->ms_ATOM_COMMENT.hashCode(), &TZPart::storeComment); + tzStoreTable[1].set(JulianKeyword::Instance()->ms_ATOM_DTSTART.hashCode(), &TZPart::storeDTStart); + tzStoreTable[2].set(JulianKeyword::Instance()->ms_ATOM_RDATE.hashCode(), &TZPart::storeRDate); + tzStoreTable[3].set(JulianKeyword::Instance()->ms_ATOM_RRULE.hashCode(), &TZPart::storeRRule); + tzStoreTable[4].set(JulianKeyword::Instance()->ms_ATOM_TZNAME.hashCode(), &TZPart::storeTZName); + tzStoreTable[5].set(JulianKeyword::Instance()->ms_ATOM_TZOFFSETTO.hashCode(), &TZPart::storeTZOffsetTo); + tzStoreTable[6].set(JulianKeyword::Instance()->ms_ATOM_TZOFFSETFROM.hashCode(), &TZPart::storeTZOffsetFrom); + tzStoreTable[7].set(0,0); + + veStoreTable[0].set(JulianKeyword::Instance()->ms_ATOM_DTEND.hashCode(), &VEvent::storeDTEnd); + veStoreTable[1].set(JulianKeyword::Instance()->ms_ATOM_DURATION.hashCode(), &VEvent::storeDuration); + veStoreTable[2].set(JulianKeyword::Instance()->ms_ATOM_GEO.hashCode(), &VEvent::storeGEO); + veStoreTable[3].set(JulianKeyword::Instance()->ms_ATOM_LOCATION.hashCode(), &VEvent::storeLocation); + veStoreTable[4].set(JulianKeyword::Instance()->ms_ATOM_PRIORITY.hashCode(), &VEvent::storePriority); + veStoreTable[5].set(JulianKeyword::Instance()->ms_ATOM_RESOURCES.hashCode(), &VEvent::storeResources); + veStoreTable[6].set(JulianKeyword::Instance()->ms_ATOM_TRANSP.hashCode(), &VEvent::storeTransp); + veStoreTable[7].set(0,0); + + vfStoreTable[0].set(JulianKeyword::Instance()->ms_ATOM_ATTENDEE.hashCode(), &VFreebusy::storeAttendees); + vfStoreTable[1].set(JulianKeyword::Instance()->ms_ATOM_COMMENT.hashCode(), &VFreebusy::storeComment); + vfStoreTable[2].set(JulianKeyword::Instance()->ms_ATOM_CONTACT.hashCode(), &VFreebusy::storeContact); + /*vfStoreTable[3].set(JulianKeyword::Instance()->ms_ATOM_CREATED.hashCode(), &VFreebusy::storeCreated);*/ + vfStoreTable[3].set(JulianKeyword::Instance()->ms_ATOM_DURATION.hashCode(), &VFreebusy::storeDuration); + vfStoreTable[4].set(JulianKeyword::Instance()->ms_ATOM_DTEND.hashCode(), &VFreebusy::storeDTEnd); + vfStoreTable[5].set(JulianKeyword::Instance()->ms_ATOM_DTSTART.hashCode(), &VFreebusy::storeDTStart); + vfStoreTable[6].set(JulianKeyword::Instance()->ms_ATOM_DTSTAMP.hashCode(), &VFreebusy::storeDTStamp); + vfStoreTable[7].set(JulianKeyword::Instance()->ms_ATOM_FREEBUSY.hashCode(), &VFreebusy::storeFreebusy); + vfStoreTable[8].set(JulianKeyword::Instance()->ms_ATOM_LASTMODIFIED.hashCode(), &VFreebusy::storeLastModified); + vfStoreTable[9].set(JulianKeyword::Instance()->ms_ATOM_ORGANIZER.hashCode(), &VFreebusy::storeOrganizer); + vfStoreTable[10].set(JulianKeyword::Instance()->ms_ATOM_REQUESTSTATUS.hashCode(), &VFreebusy::storeRequestStatus); + vfStoreTable[11].set(JulianKeyword::Instance()->ms_ATOM_SEQUENCE.hashCode(), &VFreebusy::storeSequence); + vfStoreTable[12].set(JulianKeyword::Instance()->ms_ATOM_UID.hashCode(), &VFreebusy::storeUID); + vfStoreTable[13].set(JulianKeyword::Instance()->ms_ATOM_URL.hashCode(), &VFreebusy::storeURL); + vfStoreTable[14].set(0,0); + + vtStoreTable[0].set(JulianKeyword::Instance()->ms_ATOM_COMPLETED.hashCode(), &VTodo::storeCompleted); + vtStoreTable[1].set(JulianKeyword::Instance()->ms_ATOM_DUE.hashCode(), &VTodo::storeDue); + vtStoreTable[2].set(JulianKeyword::Instance()->ms_ATOM_DURATION.hashCode(), &VTodo::storeDuration); + vtStoreTable[3].set(JulianKeyword::Instance()->ms_ATOM_GEO.hashCode(), &VTodo::storeGEO); + vtStoreTable[4].set(JulianKeyword::Instance()->ms_ATOM_LOCATION.hashCode(), &VTodo::storeLocation); + vtStoreTable[5].set(JulianKeyword::Instance()->ms_ATOM_PERCENTCOMPLETE.hashCode(), &VTodo::storePercentComplete); + vtStoreTable[6].set(JulianKeyword::Instance()->ms_ATOM_PRIORITY.hashCode(), &VTodo::storePriority); + vtStoreTable[7].set(JulianKeyword::Instance()->ms_ATOM_RESOURCES.hashCode(), &VTodo::storeResources); + vtStoreTable[8].set(0,0); +} + +//--------------------------------------------------------------------- + +JulianFunctionTable * JulianFunctionTable::Instance() +{ + if (m_Instance == 0) + m_Instance = new JulianFunctionTable(); + PR_ASSERT(m_Instance != 0); + return m_Instance; +} + +//--------------------------------------------------------------------- + + + diff --git a/calendar/modules/core/ical/src/icalcomp.cpp b/calendar/modules/core/ical/src/icalcomp.cpp new file mode 100644 index 00000000000..7460fc0ac7d --- /dev/null +++ b/calendar/modules/core/ical/src/icalcomp.cpp @@ -0,0 +1,640 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +// icalcomp.cpp +// John Sun +// 10:41 AM February 9 1998 + +#include "stdafx.h" +#include "jdefines.h" + +#include +#include "jutility.h" +#include "icalcomp.h" +#include "ptrarray.h" +#include "datetime.h" +#include "prprty.h" +#include "prprtyfy.h" +#include "keyword.h" + +//--------------------------------------------------------------------- + +ICalComponent::ICalComponent() {} + +//--------------------------------------------------------------------- + +ICalComponent::~ICalComponent() {} + +//--------------------------------------------------------------------- + +UnicodeString +ICalComponent::toStringFmt(UnicodeString & strFmt) +{ + UnicodeString s, into, dateFmt; + t_int32 i,j; + t_int32 k, l, m; + //if (FALSE) TRACE("strFmt = -%s-\r\n", strFmt.toCString("")); + + for ( i = 0; i < strFmt.size(); ) + { + + //- + /// If there's a special formatting character, + /// handle it. Otherwise, just emit the supplied + /// character. + /// + j = strFmt.indexOf('%', i); + if ( -1 != j) + { + dateFmt = ""; + if (j > i) + { + s += strFmt.extractBetween(i,j,into); + } + i = j + 1; + if ( strFmt.size() > i) + { + + // BELOW is to handle this + // %(MMMM dddd yyyy)B + //k = l = j; + k = strFmt.indexOf("(", i); l = strFmt.indexOf(")", i); + m = strFmt.indexOf("%", i); + if (k != -1 && l != -1 && + (k < m || m == -1) && k > j && + (l < m || m == -1) && l > j) + { + + if (l > k + 1) + dateFmt = strFmt.extractBetween(k + 1, l, dateFmt); + + i = l + 1; + } + //if (FALSE) TRACE("dateFmt = -%s-\r\n", dateFmt.toCString("")); + + s += toStringChar(strFmt[(TextOffset) i], dateFmt); + i++; + } + //if (FALSE) TRACE("s = -%s-\r\n", s.toCString("")); + } + else + { + s += strFmt.extractBetween(i, strFmt.size(),into); + break; + } + } + return s; +}// end +//--------------------------------------------------------------------- + +UnicodeString +ICalComponent::format(UnicodeString & sComponentName, + UnicodeString & strFmt, + UnicodeString sFilterAttendee, + t_bool delegateRequest) +{ + UnicodeString s, into; + s = JulianKeyword::Instance()->ms_sBEGIN_WITH_COLON; + s += sComponentName; + s += JulianKeyword::Instance()->ms_sLINEBREAK; + + + t_int32 i,j; + //char * c = strFmt.toCString(""); + //if (FALSE) TRACE("%s sComponentName, %s strFmt, %s sFilterAttendee, %d delegateRequest\r\n", sComponentName.toCString(""), strFmt.toCString(""), sFilterAttendee.toCString(""), delegateRequest); + + for ( i = 0; i < strFmt.size(); ) + { + + /*- + *** If there's a special formatting character, + *** handle it. Otherwise, just emit the supplied + *** character. + **/ + j = strFmt.indexOf('%', i); + if ( -1 != j) + { + if (j > i) + { + s += strFmt.extractBetween(i,j,into); + } + i = j + 1; + if (strFmt.size() > i) + { + if (delegateRequest) + { + s += formatChar(strFmt[(TextOffset) i], "", delegateRequest); + } + else if (sFilterAttendee.size() > 0) + { + s += formatChar(strFmt[(TextOffset) i], sFilterAttendee, FALSE); + } + else + { + s += formatChar(strFmt[(TextOffset) i], "", FALSE); + } + i++; + } + } + else + { + s += strFmt.extractBetween(i, strFmt.size(),into); + break; + } + } + s += JulianKeyword::Instance()->ms_sEND_WITH_COLON; + s += sComponentName; + s += JulianKeyword::Instance()->ms_sLINEBREAK; + return s; +}// end + +//--------------------------------------------------------------------- + +UnicodeString +ICalComponent::componentToString(ICAL_COMPONENT ic) +{ + switch (ic) + { + case ICAL_COMPONENT_VEVENT: return JulianKeyword::Instance()->ms_sVEVENT; + case ICAL_COMPONENT_VTODO: return JulianKeyword::Instance()->ms_sVTODO; + case ICAL_COMPONENT_VJOURNAL: return JulianKeyword::Instance()->ms_sVJOURNAL; + case ICAL_COMPONENT_VFREEBUSY: return JulianKeyword::Instance()->ms_sVFREEBUSY; + case ICAL_COMPONENT_VTIMEZONE: return JulianKeyword::Instance()->ms_sVTIMEZONE; + case ICAL_COMPONENT_VALARM: return JulianKeyword::Instance()->ms_sVALARM; + case ICAL_COMPONENT_TZPART: return JulianKeyword::Instance()->ms_sTZPART; + default: + return ""; + } +} + +//--------------------------------------------------------------------- + +ICalComponent::ICAL_COMPONENT +ICalComponent::stringToComponent(UnicodeString & s, t_bool & error) +{ + s.toUpper(); + t_int32 hashCode = s.hashCode(); + error = FALSE; + + if (JulianKeyword::Instance()->ms_ATOM_VEVENT == hashCode) return ICAL_COMPONENT_VEVENT; + else if (JulianKeyword::Instance()->ms_ATOM_VTODO == hashCode) return ICAL_COMPONENT_VTODO; + else if (JulianKeyword::Instance()->ms_ATOM_VJOURNAL == hashCode) return ICAL_COMPONENT_VJOURNAL; + else if (JulianKeyword::Instance()->ms_ATOM_VFREEBUSY == hashCode) return ICAL_COMPONENT_VFREEBUSY; + else if (JulianKeyword::Instance()->ms_ATOM_VTIMEZONE == hashCode) return ICAL_COMPONENT_VTIMEZONE; + else if (JulianKeyword::Instance()->ms_ATOM_VALARM == hashCode) return ICAL_COMPONENT_VALARM; + else if (JulianKeyword::Instance()->ms_ATOM_TZPART == hashCode) return ICAL_COMPONENT_TZPART; + else + { + error = TRUE; + return ICAL_COMPONENT_TZPART; + } +} + +//--------------------------------------------------------------------- + +t_bool ICalComponent::propertyNameToKeyLetter(UnicodeString & propertyName, + t_int32 & outLetter) +{ + propertyName.toUpper(); + t_int32 hashCode = propertyName.hashCode(); + t_bool retStatus = TRUE; + outLetter = ' '; + + if (JulianKeyword::Instance()->ms_ATOM_ATTENDEE == hashCode) outLetter = ms_cAttendees; + else if (JulianKeyword::Instance()->ms_ATOM_ATTACH == hashCode) outLetter = ms_cAttach; + else if (JulianKeyword::Instance()->ms_ATOM_CATEGORIES == hashCode) outLetter = ms_cCategories; + else if (JulianKeyword::Instance()->ms_ATOM_CLASS == hashCode) outLetter = ms_cClass; + else if (JulianKeyword::Instance()->ms_ATOM_COMMENT == hashCode) outLetter = ms_cComment; + else if (JulianKeyword::Instance()->ms_ATOM_COMPLETED == hashCode) outLetter = ms_cCompleted; + else if (JulianKeyword::Instance()->ms_ATOM_CONTACT == hashCode) outLetter = ms_cContact; + else if (JulianKeyword::Instance()->ms_ATOM_CREATED == hashCode) outLetter = ms_cCreated; + else if (JulianKeyword::Instance()->ms_ATOM_DTEND == hashCode) outLetter = ms_cDTEnd; + else if (JulianKeyword::Instance()->ms_ATOM_DTSTART == hashCode) outLetter = ms_cDTStart; + else if (JulianKeyword::Instance()->ms_ATOM_DTSTAMP == hashCode) outLetter = ms_cDTStamp; + else if (JulianKeyword::Instance()->ms_ATOM_DESCRIPTION == hashCode) outLetter = ms_cDescription; + else if (JulianKeyword::Instance()->ms_ATOM_DUE == hashCode) outLetter = ms_cDue; + else if (JulianKeyword::Instance()->ms_ATOM_DURATION == hashCode) outLetter = ms_cDuration; + else if (JulianKeyword::Instance()->ms_ATOM_EXDATE == hashCode) outLetter = ms_cExDate; + else if (JulianKeyword::Instance()->ms_ATOM_EXRULE == hashCode) outLetter = ms_cExRule; + else if (JulianKeyword::Instance()->ms_ATOM_FREEBUSY == hashCode) outLetter = ms_cFreebusy; + else if (JulianKeyword::Instance()->ms_ATOM_GEO == hashCode) outLetter = ms_cGEO; + else if (JulianKeyword::Instance()->ms_ATOM_LASTMODIFIED == hashCode) outLetter = ms_cLastModified; + else if (JulianKeyword::Instance()->ms_ATOM_LOCATION == hashCode) outLetter = ms_cLocation; + else if (JulianKeyword::Instance()->ms_ATOM_ORGANIZER == hashCode) outLetter = ms_cOrganizer; + else if (JulianKeyword::Instance()->ms_ATOM_PERCENTCOMPLETE == hashCode) outLetter = ms_cPercentComplete; + else if (JulianKeyword::Instance()->ms_ATOM_PRIORITY == hashCode) outLetter = ms_cPriority; + else if (JulianKeyword::Instance()->ms_ATOM_RDATE == hashCode) outLetter = ms_cRDate; + else if (JulianKeyword::Instance()->ms_ATOM_RRULE == hashCode) outLetter = ms_cRRule; + else if (JulianKeyword::Instance()->ms_ATOM_RECURRENCEID == hashCode) outLetter = ms_cRecurrenceID; + else if (JulianKeyword::Instance()->ms_ATOM_RELATEDTO == hashCode) outLetter = ms_cRelatedTo; + else if (JulianKeyword::Instance()->ms_ATOM_REPEAT == hashCode) outLetter = ms_cRepeat; + else if (JulianKeyword::Instance()->ms_ATOM_REQUESTSTATUS == hashCode) outLetter = ms_cRequestStatus; + else if (JulianKeyword::Instance()->ms_ATOM_RESOURCES == hashCode) outLetter = ms_cResources; + else if (JulianKeyword::Instance()->ms_ATOM_SEQUENCE == hashCode) outLetter = ms_cSequence; + else if (JulianKeyword::Instance()->ms_ATOM_STATUS == hashCode) outLetter = ms_cStatus; + else if (JulianKeyword::Instance()->ms_ATOM_SUMMARY == hashCode) outLetter = ms_cSummary; + else if (JulianKeyword::Instance()->ms_ATOM_TRANSP == hashCode) outLetter = ms_cTransp; + //else if (JulianKeyword::Instance()->ms_ATOM_TRIGGER == hashCode) outLetter = ms_cTrigger; + else if (JulianKeyword::Instance()->ms_ATOM_UID == hashCode) outLetter = ms_cUID; + else if (JulianKeyword::Instance()->ms_ATOM_URL == hashCode) outLetter = ms_cURL; + //else if (JulianKeyword::Instance()->ms_ATOM_TZOFFSET == hashCode) outLetter = ms_cTZOffset; + else if (JulianKeyword::Instance()->ms_ATOM_TZOFFSETTO == hashCode) outLetter = ms_cTZOffsetTo; + else if (JulianKeyword::Instance()->ms_ATOM_TZOFFSETFROM == hashCode) outLetter = ms_cTZOffsetFrom; + else if (JulianKeyword::Instance()->ms_ATOM_TZNAME == hashCode) outLetter = ms_cTZName; + //else if (JulianKeyword::Instance()->ms_ATOM_DAYLIGHT == hashCode) outLetter = ms_cDayLight; + //else if (JulianKeyword::Instance()->ms_ATOM_STANDARD == hashCode) outLetter = ms_cStandard; + else if (JulianKeyword::Instance()->ms_ATOM_TZURL == hashCode) outLetter = ms_cTZURL; + else if (JulianKeyword::Instance()->ms_ATOM_TZID == hashCode) outLetter = ms_cTZID; + else + { + retStatus = FALSE; + } + return retStatus; +} +//--------------------------------------------------------------------- + +UnicodeString & +ICalComponent::makeFormatString(char ** ppsPropList, t_int32 iPropCount, + UnicodeString & out) +{ + // TODO: figure out what to do if no properties? + t_int32 i = 0; + t_int32 keyLetter = ' '; + t_bool bFoundProperty = FALSE; + char *cProp = 0; + UnicodeString u; + UnicodeString usProp; + + out = ""; + if (iPropCount > 0 && ppsPropList != 0) + { + for (i = 0; i < iPropCount; i++) + { + cProp = ppsPropList[i]; + usProp = cProp; + bFoundProperty = ICalComponent::propertyNameToKeyLetter(usProp, keyLetter); + if (bFoundProperty) + { + out += "%"; + // TODO: dangerous + out += (char) (keyLetter); + } + } + } else + { + // given an empty propList or a zero propCount, + // return all properties + alarms + out = "%v%a%k%c%K%G%H%t%e%B%C%i%F%D%X%E%Y%O%M%L%J%P%p%x%y%R%o%A%T%r%s%g%S%h%U%u%Z%d%f%n%Q%I%V%w"; + } + return out; +} +//--------------------------------------------------------------------- + +void ICalComponent::deleteUnicodeStringVector(JulianPtrArray * stringVector) +{ + t_int32 i; + if (stringVector != 0) + { + for (i = stringVector->GetSize() - 1; i >= 0; i--) + { + delete ((UnicodeString *) stringVector->GetAt(i)); + } + } +} +//--------------------------------------------------------------------- + +void +ICalComponent::deleteICalComponentVector(JulianPtrArray * componentVector) +{ + t_int32 i; + if (componentVector != 0) + { + for (i = componentVector->GetSize() - 1; i >= 0; i--) + { + delete ((ICalComponent *) componentVector->GetAt(i)); + } + } +} + +//--------------------------------------------------------------------- + +void +ICalComponent::cloneICalComponentVector(JulianPtrArray * out, + JulianPtrArray * toClone) +{ + if (out != 0) + { + if (toClone != 0) + { + t_int32 i; + ICalComponent * comp; + ICalComponent * clone; + for (i = 0; i < toClone->GetSize(); i++) + { + comp = (ICalComponent *) toClone->GetAt(i); + clone = comp->clone(0); + out->Add(clone); + } + } + } +} +//--------------------------------------------------------------------- + +#if 0 +void +ICalComponent::setDateTimeValue(ICalProperty ** dateTimePropertyPtr, + DateTime inVal, + JulianPtrArray * inParameters) +{ + PR_ASSERT(dateTimePropertyPtr != 0); + if (dateTimePropertyPtr != 0) + { + if (((ICalProperty *) (*dateTimePropertyPtr)) == 0) + { + ((ICalProperty *) (*dateTimePropertyPtr)) = + ICalPropertyFactory::Make(ICalProperty::DATETIME, + (void *) &inVal, inParameters); + } + else + { + ((ICalProperty *) (*dateTimePropertyPtr))->setValue((void *) &inVal); + ((ICalProperty *) (*dateTimePropertyPtr))->setParameters(inParameters); + } + } +} + +//--------------------------------------------------------------------- + +void ICalComponent::getDateTimeValue(ICalProperty ** dateTimePropertyPtr, + DateTime & outVal) +{ + PR_ASSERT(dateTimePropertyPtr != 0); + if (dateTimePropertyPtr != 0) + { + if ((ICalProperty *)(*dateTimePropertyPtr) == 0) + outVal.setTime(-1); + else + outVal = *((DateTime *) ((ICalProperty *)(*dateTimePropertyPtr))->getValue()); + } + else + { + outVal.setTime(-1); + } +} +//--------------------------------------------------------------------- + +void +ICalComponent::setStringValue(ICalProperty ** stringPropertyPtr, + UnicodeString inVal, + JulianPtrArray * inParameters) +{ + PR_ASSERT(stringPropertyPtr != 0); + if (stringPropertyPtr != 0) + { + if (((ICalProperty *) (*stringPropertyPtr)) == 0) + { + ((ICalProperty *) (*stringPropertyPtr)) = + ICalPropertyFactory::Make(ICalProperty::TEXT, + (void *) &inVal, inParameters); + } + else + { + ((ICalProperty *) (*stringPropertyPtr))->setValue((void *) &inVal); + ((ICalProperty *) (*stringPropertyPtr))->setParameters(inParameters); + } + } +} + +//--------------------------------------------------------------------- + +void +ICalComponent::getStringValue(ICalProperty ** stringPropertyPtr, + UnicodeString & outVal) +{ + PR_ASSERT(stringPropertyPtr != 0); + if (stringPropertyPtr != 0) + { + if ((ICalProperty *)(*stringPropertyPtr) == 0) + outVal = ""; + else + outVal = *((UnicodeString *) ((ICalProperty *)(*stringPropertyPtr))->getValue()); + } + else + { + outVal = ""; + } +} + +//--------------------------------------------------------------------- + +void +ICalComponent::setIntegerValue(ICalProperty ** integerPropertyPtr, + t_int32 inVal, JulianPtrArray * inParameters) +{ + PR_ASSERT(integerPropertyPtr != 0); + if (integerPropertyPtr != 0) + { + if (((ICalProperty *) (*integerPropertyPtr)) == 0) + { + ((ICalProperty *) (*integerPropertyPtr)) = + ICalPropertyFactory::Make(ICalProperty::INTEGER, + (void *) &inVal, inParameters); + } + else + { + ((ICalProperty *) (*integerPropertyPtr))->setValue((void *) &inVal); + ((ICalProperty *) (*integerPropertyPtr))->setParameters(inParameters); + } + } +} + +//--------------------------------------------------------------------- + +void +ICalComponent::getIntegerValue(ICalProperty ** integerPropertyPtr, + t_int32 & outVal) +{ + PR_ASSERT(integerPropertyPtr != 0); + if (integerPropertyPtr != 0) + { + if ((ICalProperty *)(*integerPropertyPtr) == 0) + outVal = -1; + else + outVal = *((t_int32 *) ((ICalProperty *)(*integerPropertyPtr))->getValue()); + } + else + { + outVal = -1; + } +} +#endif /* #if 0 */ +//--------------------------------------------------------------------- + +void ICalComponent::internalSetProperty(ICalProperty ** propertyPtr, + ICalProperty * replaceProp, + t_bool bForceOverwriteOnEmpty) +{ + PR_ASSERT(propertyPtr != 0); + ICalProperty * prop = 0; + prop = (ICalProperty *) (*(propertyPtr)); + t_bool bOverwrite = TRUE; + if (replaceProp == 0 && !bForceOverwriteOnEmpty) + { + bOverwrite = FALSE; + } + if (bOverwrite) + { + if (prop != 0) + { + delete prop; + prop = 0; + (*(propertyPtr)) = 0; + } + if (replaceProp != 0) + { + prop = replaceProp->clone(0); + (*(propertyPtr)) = prop; + } + } +} + +//--------------------------------------------------------------------- + +void ICalComponent::internalSetPropertyVctr(JulianPtrArray ** propertyVctrPtr, + JulianPtrArray * replaceVctr, + t_bool bAddInsteadOfOverwrite, + t_bool bForceOverwriteOnEmpty) +{ + + // delete the contents of the old vector + // delete the old vector + // create a new vector if replaceVctr != 0 + // clone contents of replaceVctr. + + PR_ASSERT(propertyVctrPtr != 0); + JulianPtrArray * propVctr = 0; + propVctr = (JulianPtrArray *) (*(propertyVctrPtr)); + t_bool bOverwrite = TRUE; + + // don't overwrite if overwrite flag is false && replaceVctr is empty or null. + if (bAddInsteadOfOverwrite) + { + bOverwrite = FALSE; + } + else if ((replaceVctr == 0 || replaceVctr->GetSize() == 0) && !bForceOverwriteOnEmpty) + { + bOverwrite = FALSE; + } + if (bOverwrite) + { + if (propVctr != 0) + { + ICalProperty::deleteICalPropertyVector(propVctr); + delete propVctr; + propVctr = 0; + (*(propertyVctrPtr)) = 0; + } + if (replaceVctr != 0) + { + propVctr = new JulianPtrArray(); + PR_ASSERT(propVctr != 0); + (*(propertyVctrPtr)) = propVctr; + ICalProperty::CloneICalPropertyVector(replaceVctr, propVctr, 0); + } + } + else if (bAddInsteadOfOverwrite) + { + t_int32 i; + if (replaceVctr != 0) + { + ICalProperty * ip = 0; + for (i = 0; i < replaceVctr->GetSize(); i++) + { + ip = ((ICalProperty *) replaceVctr->GetAt(i))->clone(0); + if (ip != 0) + { + propVctr->Add(ip); + } + } + } + } +} +//--------------------------------------------------------------------- + +void ICalComponent::internalSetXTokensVctr(JulianPtrArray ** xTokensVctrPtr, + JulianPtrArray * replaceVctr, + t_bool bAddInsteadOfOverwrite, + t_bool bForceOverwriteOnEmpty) +{ + + // delete the contents of the old vector + // delete the old vector + // create a new vector if replaceVctr != 0 + // clone contents of replaceVctr. + + PR_ASSERT(xTokensVctrPtr != 0); + JulianPtrArray * xTokensVctr = 0; + xTokensVctr = (JulianPtrArray *) (*(xTokensVctrPtr)); + t_bool bOverwrite = TRUE; + + // don't overwrite if overwrite flag is false && replaceVctr is empty or null. + if (bAddInsteadOfOverwrite) + { + bOverwrite = FALSE; + } + else if ((replaceVctr == 0 || replaceVctr->GetSize() == 0) && !bForceOverwriteOnEmpty) + { + bOverwrite = FALSE; + } + if (bOverwrite) + { + if (xTokensVctr != 0) + { + ICalComponent::deleteUnicodeStringVector(xTokensVctr); + delete xTokensVctr; + xTokensVctr = 0; + (*(xTokensVctrPtr)) = 0; + } + if (replaceVctr != 0) + { + xTokensVctr = new JulianPtrArray(); + PR_ASSERT(xTokensVctr != 0); + (*(xTokensVctrPtr)) = xTokensVctr; + ICalProperty::CloneUnicodeStringVector(replaceVctr, xTokensVctr); + } + } + else if (bAddInsteadOfOverwrite) + { + t_int32 i; + if (replaceVctr != 0) + { + UnicodeString * us = 0; + UnicodeString u; + for (i = 0; i < replaceVctr->GetSize(); i++) + { + u = *((UnicodeString *) replaceVctr->GetAt(i)); + us = new UnicodeString(u); + if (us != 0) + { + xTokensVctr->Add(us); + } + } + } + } +} + diff --git a/calendar/modules/core/ical/src/icalfrdr.cpp b/calendar/modules/core/ical/src/icalfrdr.cpp new file mode 100644 index 00000000000..7ee4f264896 --- /dev/null +++ b/calendar/modules/core/ical/src/icalfrdr.cpp @@ -0,0 +1,134 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +// icalfrdr.cpp +// John Sun +// 3:03 PM February 10 1998 + +#include +#include + +#include "stdafx.h" +#include "jdefines.h" + +#include "icalfrdr.h" + +//--------------------------------------------------------------------- + +ICalFileReader::ICalFileReader() {} + +//--------------------------------------------------------------------- + +ICalFileReader::ICalFileReader(char * filename, ErrorCode & status) +: m_file(0), m_filename(0) +{ + m_filename = filename; + m_file = fopen(filename, "r"); + + if (m_file == 0) + { +#if 0 + if (FALSE) TRACE("Can't open %s\n", filename); +#endif + status = 1; + } + else + { + status = ZERO_ERROR; + } +} +//--------------------------------------------------------------------- +ICalFileReader::~ICalFileReader() +{ + if (m_file) { fclose(m_file); m_file = 0; } +} + +//--------------------------------------------------------------------- + +t_int8 ICalFileReader::read(ErrorCode & status) +{ + int c = fgetc(m_file); + if (c == EOF) + { + status = 1; + return -1; + } + else + return (t_int8) c; +} +//--------------------------------------------------------------------- +// TODO: handle quoted-printable +UnicodeString & +ICalFileReader::readLine(UnicodeString & aLine, ErrorCode & status) +{ + status = ZERO_ERROR; + aLine = ""; + char * l = 0; + + if ( 0 != (l = fgets(m_pBuffer,1023,m_file)) ) + { + t_int32 iLen = strlen(m_pBuffer); + if (m_pBuffer[iLen-1] == '\n') + m_pBuffer[iLen-1] = 0; + { + aLine = m_pBuffer; + return aLine; + } + } + status = 1; + return aLine; +} +//--------------------------------------------------------------------- +// NOTE: TODO: make faster profiling? +UnicodeString & +ICalFileReader::readFullLine(UnicodeString & aLine, ErrorCode & status, t_int32 iTemp) +{ + status = ZERO_ERROR; + t_int8 i; + + readLine(aLine, status); + //if (FALSE) TRACE("rfl(1) %s\r\n", aLine.toCString("")); + + if (FAILURE(status)) + { + return aLine; + } + UnicodeString aSubLine; + while (TRUE) + { + i = read(status); + if (i != -1 && i == ' ') + { + aLine += readLine(aSubLine, status); + //if (FALSE) TRACE("rfl(2) %s\r\n", aLine.toCString("")); + } + else if (i == -1) + { + return aLine; + } + else + { + ungetc(i, m_file); + break; + } + } + //if (FALSE) TRACE("end of rfl: ---%s---\r\n", aLine.toCString("")); + return aLine; +} +//--------------------------------------------------------------------- + diff --git a/calendar/modules/core/ical/src/icalprm.cpp b/calendar/modules/core/ical/src/icalprm.cpp new file mode 100644 index 00000000000..55cd7d1aa16 --- /dev/null +++ b/calendar/modules/core/ical/src/icalprm.cpp @@ -0,0 +1,139 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +// icalprm.cpp +// John Sun +// 3:41 PM February 10 1998 + +#include "stdafx.h" +#include "jdefines.h" + +#include "icalprm.h" +#include "ptrarray.h" +#include "keyword.h" + +//--------------------------------------------------------------------- + +ICalParameter::ICalParameter() {} + +//--------------------------------------------------------------------- + +ICalParameter::ICalParameter(ICalParameter & that) +{ + m_ParameterName = that.m_ParameterName; + m_ParameterValue = that.m_ParameterValue; +} + +//--------------------------------------------------------------------- + +ICalParameter::ICalParameter(const UnicodeString & parameterName, + const UnicodeString & parameterValue) +{ + m_ParameterName = parameterName; + m_ParameterValue = parameterValue; +} +//--------------------------------------------------------------------- +ICalParameter * ICalParameter::clone() +{ + return new ICalParameter(*this); +} +//--------------------------------------------------------------------- + +void +ICalParameter::setParameterName(const UnicodeString & parameterName) +{ + m_ParameterName = parameterName; +} + +//--------------------------------------------------------------------- + +void +ICalParameter::setParameterValue(const UnicodeString & parameterValue) +{ + m_ParameterValue = parameterValue; +} + +//--------------------------------------------------------------------- + +UnicodeString & +ICalParameter::getParameterName(UnicodeString & retName) const +{ + retName = m_ParameterName; + return retName; +} + +//--------------------------------------------------------------------- + +UnicodeString & +ICalParameter::getParameterValue(UnicodeString & retValue) const +{ + retValue = m_ParameterValue; + return retValue; +} + +//--------------------------------------------------------------------- + +UnicodeString & +ICalParameter::toICALString(UnicodeString & result) const +{ + result = JulianKeyword::Instance()->ms_sSEMICOLON_SYMBOL; + result += m_ParameterName; + result += '='; + result += m_ParameterValue; + return result; +} + +//--------------------------------------------------------------------- + +const ICalParameter & +ICalParameter::operator=(const ICalParameter & d) +{ + if (this != &d) + { + m_ParameterName = d.m_ParameterName; + m_ParameterValue = d.m_ParameterValue; + } + return *this; +} + +//--------------------------------------------------------------------- +UnicodeString & +ICalParameter::GetParameterFromVector(UnicodeString & paramName, + UnicodeString & retVal, + JulianPtrArray * parameters) +{ + t_int32 i; + ICalParameter * ip; + if (parameters != 0) + { + UnicodeString u; + for (i = 0; i < parameters->GetSize(); i++) + { + ip = (ICalParameter *) parameters->GetAt(i); + if (paramName.compareIgnoreCase(ip->getParameterName(u)) == 0) + { + retVal = ip->getParameterValue(retVal); + return retVal; + } + } + } + retVal = ""; + return retVal; +} +//--------------------------------------------------------------------- + diff --git a/calendar/modules/core/ical/src/icalredr.cpp b/calendar/modules/core/ical/src/icalredr.cpp new file mode 100644 index 00000000000..51a09532919 --- /dev/null +++ b/calendar/modules/core/ical/src/icalredr.cpp @@ -0,0 +1,71 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +// icalredr.cpp +// John Sun +// 3/23/98 3:29:47 PM + +#include "stdafx.h" +#include "icalredr.h" + +//--------------------------------------------------------------------- + +ICalReader::ICalReader() {} + +//--------------------------------------------------------------------- + +t_bool ICalReader::isHex(t_int8 aToken) +{ + if (aToken >= '0' && aToken <= '9') + return TRUE; + else if (aToken >= 'A' && aToken <= 'F') + return TRUE; + else if (aToken >= 'a' && aToken <= 'f') + return TRUE; + else + return FALSE; +} + +//--------------------------------------------------------------------- + +t_int8 ICalReader::convertHex(char fToken, + char sToken) +{ + unsigned char c = 0; + if (fToken >= '0' && fToken <= '9') + c = fToken - '0'; + else if (fToken >= 'A' && fToken <= 'F') + c = fToken - ('A' - 10); + //else if (fToken >= 'a' && fToken <= 'f') + else + c = fToken - ('a' - 10); + + /* Second hex digit */ + c = (c << 4); + if (sToken >= '0' && sToken <= '9') + c += sToken - '0'; + else if (sToken >= 'A' && sToken <= 'F') + c += sToken - ('A' - 10); + //else (sToken >= 'a' && sToken <= 'f') + else + c += sToken - ('a' - 10); + + return (t_int8) c; +} + +//--------------------------------------------------------------------- diff --git a/calendar/modules/core/ical/src/icalsrdr.cpp b/calendar/modules/core/ical/src/icalsrdr.cpp new file mode 100644 index 00000000000..6515a2ef52f --- /dev/null +++ b/calendar/modules/core/ical/src/icalsrdr.cpp @@ -0,0 +1,213 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +/* + * icalsrdr.cpp + * John Sun + * 2/10/98 11:37:56 PM + */ + +/* TODO: remove Unistring dependency. There is a bug if the +target string is encoded with 2byte character. If so, then the +m_pos and m_length variables are wrong. Currently, I will assume that +all const char * passed in will be us-ascii 8-bit chars +*/ + +#include "stdafx.h" +#include "jdefines.h" + +#include +#include "ptypes.h" +#include "icalsrdr.h" + +//--------------------------------------------------------------------- + +ICalStringReader::ICalStringReader() {} + +//--------------------------------------------------------------------- + +ICalStringReader::ICalStringReader(const char * string, + JulianUtility::MimeEncoding encoding) +: m_string(string), m_pos(0), m_mark(0) +{ + m_length = strlen(m_string); + m_unistring = m_string; + m_Encoding = encoding; +} + +//--------------------------------------------------------------------- + +t_int8 ICalStringReader::read(ErrorCode & status) +{ + if (m_pos >= m_length) + { + status = 1; + return -1; + } + else + { + status = ZERO_ERROR; + if (m_Encoding == JulianUtility::MimeEncoding_7bit) + { + return m_string[m_pos++]; + } + else + { + // for now only handles quoted-printable + PR_ASSERT(m_Encoding == JulianUtility::MimeEncoding_QuotedPrintable); + if (m_Encoding == JulianUtility::MimeEncoding_QuotedPrintable) + { + if ((m_string[m_pos] == '=') && (m_length >= m_pos + 3)) + { + // TODO: use libmime decoding algorithm instead of this one + if (ICalReader::isHex(m_string[m_pos+1]) && ICalReader::isHex(m_string[m_pos + 2])) + { + t_int8 c; + c = ICalReader::convertHex(m_string[m_pos + 1], m_string[m_pos + 2]); + m_pos += 3; + return c; + } + else + { + return m_string[m_pos++]; + } + } + else + { + return m_string[m_pos++]; + } + } + else + { + // handle like 7bit + return m_string[m_pos++]; + } + } + } +} + +//--------------------------------------------------------------------- + +void ICalStringReader::mark() +{ + m_mark = m_pos; +} + +//--------------------------------------------------------------------- + +void ICalStringReader::reset() +{ + m_pos = m_mark; +} + +//--------------------------------------------------------------------- + +UnicodeString & ICalStringReader::readLine(UnicodeString & aLine, + ErrorCode & status) +{ + status = ZERO_ERROR; + t_int8 c = 0; + t_int32 oldpos = m_pos; + + aLine = ""; + c = read(status); + while (!(FAILURE(status))) + { + /* Break on '\n', '\r\n', and '\r' */ + if (c == '\n') + { + break; + } + else if (c == '\r') + { + mark(); + c = read(status); + if (FAILURE(status)) + break; + else if (c == '\n') + { + break; + } + else + { + reset(); + break; + } + } +#if 1 + aLine += c; +#endif + c = read(status); + } +#if 0 + if (m_pos > oldpos) + m_unistring.extractBetween(oldpos, m_pos - 1, aLine); + else + aLine = ""; +#endif + + + //if (FALSE) TRACE("end of readline:---%s---\r\n", aLine.toCString("")); + return aLine; +} + +//--------------------------------------------------------------------- + +UnicodeString & ICalStringReader::readFullLine(UnicodeString & aLine, + ErrorCode & status, t_int32 iTemp) +{ + status = ZERO_ERROR; + t_int32 i; + + readLine(aLine, status); + //if (FALSE) TRACE("rfl(1) %s\r\n", aLine.toCString("")); + + if (FAILURE(status)) + { + //aLine = ""; + return aLine; + } + + UnicodeString aSubLine; + + while (TRUE) + { + mark(); + i = read(status); + if (i == ' ') + { + aLine += readLine(aSubLine, status); + //if (FALSE) TRACE("rfl(2) %s\r\n", aLine.toCString("")); + } + else if (FAILURE(status)) + { + return aLine; + } + else + { + reset(); + break; + } + } + //if (FALSE) TRACE("end of rfl: ---%s---\r\n", aLine.toCString("")); + return aLine; +} +//--------------------------------------------------------------------- + + + diff --git a/calendar/modules/core/ical/src/icompfy.cpp b/calendar/modules/core/ical/src/icompfy.cpp new file mode 100644 index 00000000000..4c3706603fc --- /dev/null +++ b/calendar/modules/core/ical/src/icompfy.cpp @@ -0,0 +1,80 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +// icompfy.cpp +// John Sun +// 10:46 AM February 20 1998 + +#include "stdafx.h" +#include "jdefines.h" + +#include "icompfy.h" +#include "vevent.h" +#include "vtodo.h" +#include "vjournal.h" +#include "vfrbsy.h" +#include "vtimezne.h" +#include "keyword.h" +//--------------------------------------------------------------------- + +ICalComponentFactory::ICalComponentFactory() +{ +} + +//--------------------------------------------------------------------- + +ICalComponent * +ICalComponentFactory::Make(UnicodeString & name, JLog * initLog) +{ + ICalComponent * ret; + + t_int32 hashCode = name.hashCode(); + + if (JulianKeyword::Instance()->ms_ATOM_VEVENT == hashCode) + { + ret = (ICalComponent *) new VEvent(initLog); + PR_ASSERT(ret != 0); + } + else if (JulianKeyword::Instance()->ms_ATOM_VTODO == hashCode) + { + ret = (ICalComponent *) new VTodo(initLog); + PR_ASSERT(ret != 0); + } + else if (JulianKeyword::Instance()->ms_ATOM_VJOURNAL == hashCode) + { + ret = (ICalComponent *) new VJournal(initLog); + PR_ASSERT(ret != 0); + } + else if (JulianKeyword::Instance()->ms_ATOM_VFREEBUSY == hashCode) + { + ret = (ICalComponent *) new VFreebusy(initLog); + PR_ASSERT(ret != 0); + } + else if (JulianKeyword::Instance()->ms_ATOM_VTIMEZONE == hashCode) + { + ret = (ICalComponent *) new VTimeZone(initLog); + PR_ASSERT(ret != 0); + } + else + { + ret = 0; + } + return ret; +} +//--------------------------------------------------------------------- + diff --git a/calendar/modules/core/ical/src/iprprty.cpp b/calendar/modules/core/ical/src/iprprty.cpp new file mode 100644 index 00000000000..dac60e0d3a5 --- /dev/null +++ b/calendar/modules/core/ical/src/iprprty.cpp @@ -0,0 +1,120 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +// iprprty.cpp +// John Sun +// 3:15 PM February 12 1998 + +#include "stdafx.h" +#include "jdefines.h" + +#include "iprprty.h" +#include "prprty.h" + + +//--------------------------------------------------------------------- +// private never use +IntegerProperty::IntegerProperty() +{ + PR_ASSERT(FALSE); +} + +//--------------------------------------------------------------------- + +IntegerProperty::IntegerProperty(const IntegerProperty & that) +{ + setParameters(that.m_vParameters); + m_Integer = that.m_Integer; +} + +//--------------------------------------------------------------------- + +IntegerProperty::IntegerProperty(t_int32 value, JulianPtrArray * parameters) +: StandardProperty(parameters) +{ + m_Integer = value; +} + +//--------------------------------------------------------------------- + +IntegerProperty::~IntegerProperty() +{ + //deleteICalParameterVector(m_vParameters); + //delete m_vParameters; m_vParameters = 0; +} + +//--------------------------------------------------------------------- + +void * IntegerProperty::getValue() const +{ + return (void *) &m_Integer; +} + +//--------------------------------------------------------------------- + +void IntegerProperty::setValue(void * value) +{ + PR_ASSERT(value != 0); + if (value != 0) + { + m_Integer = *((t_int32 *) value); + } +} + +//--------------------------------------------------------------------- + +ICalProperty * IntegerProperty::clone(JLog * initLog) +{ + if (initLog) {} // NOTE: Remove later to avoid warnings + return new IntegerProperty(*this); +} + +//--------------------------------------------------------------------- + +t_bool IntegerProperty::isValid() +{ + return TRUE; +} + +//--------------------------------------------------------------------- + +UnicodeString & IntegerProperty::toString(UnicodeString & out) +{ + char sBuf[10]; + sprintf(sBuf, "%d", m_Integer); + out = sBuf; + return out; +} + +//--------------------------------------------------------------------- +UnicodeString & +IntegerProperty::toString(UnicodeString & dateFmt, UnicodeString & out) +{ + // NOTE: remove it later, gets rid of compiler warning + if (dateFmt.size() > 0) {} + return toString(out); +} +//--------------------------------------------------------------------- + +UnicodeString & IntegerProperty::toExportString(UnicodeString & out) +{ + return toString(out); +} +//--------------------------------------------------------------------- + + diff --git a/calendar/modules/core/ical/src/jparser.cpp b/calendar/modules/core/ical/src/jparser.cpp new file mode 100644 index 00000000000..faf2173af39 --- /dev/null +++ b/calendar/modules/core/ical/src/jparser.cpp @@ -0,0 +1,196 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +/* + * jparser.cpp + * John Sun + * 4/28/98 10:48:13 AM + */ + +#include "stdafx.h" +#include "jdefines.h" + +#include +#include "jparser.h" +#include "prprty.h" +#include "tmbevent.h" +#include "nscal.h" +#include "jlog.h" +#include "keyword.h" +#include "icalsrdr.h" + +#include "nspr.h" + +//--------------------------------------------------------------------- + +JulianParser::JulianParser() +{ + m_Reader = 0; + m_OutCalendars = 0; + m_Thread = 0; + m_bParseStarted = FALSE; + m_bParseFinished = FALSE; +} + +//--------------------------------------------------------------------- + +JulianParser::JulianParser(ICalCAPIReader * reader, + JulianPtrArray * outCalendars, + PRThread * thread) +{ + m_Reader = reader; + m_OutCalendars = outCalendars; + m_Thread = thread; + m_bParseStarted = FALSE; + m_bParseFinished = FALSE; +} + +//--------------------------------------------------------------------- + +JulianUtility::MimeEncoding +JulianParser::stringToEncodingType(UnicodeString & propVal) +{ + if (propVal.compareIgnoreCase(JulianKeyword::Instance()->ms_s7bit) == 0) + { + return JulianUtility::MimeEncoding_7bit; + } + else if (propVal.compareIgnoreCase(JulianKeyword::Instance()->ms_sQUOTED_PRINTABLE) == 0) + { + return JulianUtility::MimeEncoding_QuotedPrintable; + } + else if (propVal.compareIgnoreCase(JulianKeyword::Instance()->ms_sBase64) == 0) + { + return JulianUtility::MimeEncoding_Base64; + } + else + return JulianUtility::MimeEncoding_7bit; +} + +//--------------------------------------------------------------------- + +void JulianParser::ParseCalendars() +{ + JulianParser::ParseCalendars((ICalReader *) m_Reader, m_OutCalendars); +} + +//--------------------------------------------------------------------- + +void JulianParser::ParseCalendars(ICalReader * reader, + JulianPtrArray * outCalendars) +{ + if (outCalendars == 0) + return; + + JulianPtrArray * parameters = new JulianPtrArray(); + + // TODO: this needs to be changed to capireader later + PR_ASSERT(parameters != 0); + if (parameters != 0) + { + JLog * log = 0; + ErrorCode status = ZERO_ERROR; + UnicodeString strLine, propName, propVal; + JulianUtility::MimeEncoding encoding = JulianUtility::MimeEncoding_7bit; + + ICalCAPIReader * cr = (ICalCAPIReader *) reader; + + while(TRUE) + { + //PR_EnterMonitor((PRMonitor *) cr->getMonitor()); + //reader->readFullLine(strLine, status); + cr->readFullLine(strLine, status); + ICalProperty::Trim(strLine); + +#if TESTING_ITIPRIG + if (FALSE) TRACE("\t--Parser: line (size = %d) = ---%s---\r\n", + strLine.size(), strLine.toCString("")); +#endif + if (FAILURE(status) && strLine.size() == 0) + { + //PR_Notify((PRMonitor *) cr->getMonitor()); + if (cr->isFinished()) + { + break; + } +#if TESTING_ITIPRIG + if (FALSE) TRACE("\t--jParser: yielding\r\n"); +#endif +#ifdef NSPR20 + PR_Sleep(PR_INTERVAL_NO_WAIT); +#else + PR_Yield(); +#endif + //break; + } + + ICalProperty::parsePropertyLine(strLine, propName, + propVal, parameters); + +#if TESTING_ITIPRIG + if (TRUE) TRACE("\t--Parser: propName = --%s--, propVal = --%s--,paramSize = %d\r\n", + propName.toCString(""), propVal.toCString(""), parameters->GetSize()); +#endif + if ((propName.compareIgnoreCase(JulianKeyword::Instance()->ms_sBEGIN) == 0) && + (propVal.compareIgnoreCase(JulianKeyword::Instance()->ms_sVCALENDAR) == 0)) + { + // parse an NSCalendar, add it to outCalendars + NSCalendar * cal = new NSCalendar(log); + UnicodeString fileName; + cal->parse(reader, fileName, encoding); + outCalendars->Add(cal); + } + else if (propName.compareIgnoreCase( + JulianKeyword::Instance()->ms_sCONTENT_TRANSFER_ENCODING) == 0) + { + ICalProperty::Trim(propVal); + encoding = stringToEncodingType(propVal); + cr->setEncoding(encoding); + } + ICalProperty::deleteICalParameterVector(parameters); + parameters->RemoveAll(); + + //PR_ExitMonitor((PRMonitor *)cr->getMonitor()); + } + + ICalProperty::deleteICalParameterVector(parameters); + parameters->RemoveAll(); + delete parameters; parameters = 0; + setParseFinished(); + } +} +//--------------------------------------------------------------------- + +void jparser_ParseCalendarsZero(void * jp, void * nPtr) +{ + //if (FALSE) ("--calling ParseCalendarsZero\r\n"); + JulianParser * julPar = (JulianParser *) jp; + julPar->ParseCalendars(); +#if TESTING_ITIPRIG + TRACE("\t--killing parseThread\r\n"); +#endif +#ifdef NSPR20 + PR_ProcessExit(0); +#else + PR_Exit(); +#endif +} + +//--------------------------------------------------------------------- + + + diff --git a/calendar/modules/core/ical/src/manifest.mn b/calendar/modules/core/ical/src/manifest.mn new file mode 100644 index 00000000000..e69de29bb2d diff --git a/calendar/modules/core/ical/src/nscal.cpp b/calendar/modules/core/ical/src/nscal.cpp new file mode 100644 index 00000000000..c7a7ca9c426 --- /dev/null +++ b/calendar/modules/core/ical/src/nscal.cpp @@ -0,0 +1,2241 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +// nscal.h +// John Sun +// 1:35 PM Febuary 18 1998 + +/* + * Updated 9/24/98 sman + * We need to be able to append a list of events: AddEventList + */ + +#include "stdafx.h" +#include "jdefines.h" + +#include "nscal.h" +#include "prprty.h" +#include "prprtyfy.h" +#include "icalcomp.h" +#include "icompfy.h" +#include "icalredr.h" +#include "vevent.h" +#include "vtodo.h" +#include "vjournal.h" +#include "vfrbsy.h" +#include "vtimezne.h" +#include "jlog.h" +#include "jutility.h" +#include "keyword.h" + +#include "uidrgntr.h" +#include "datetime.h" +#include "period.h" +#include "recid.h" + +/** to work on UNIX */ +//#define TRACE printf + +//--------------------------------------------------------------------- +t_bool NSCalendar::m_bLoadMultipleCalendars = FALSE; +t_bool NSCalendar::m_bSmartLoading = TRUE; +//--------------------------------------------------------------------- + +// never use +#if 0 +NSCalendar::NSCalendar() +{ + PR_ASSERT(FALSE); +} +#endif + +//--------------------------------------------------------------------- + +NSCalendar::NSCalendar(JLog * initLog) +: m_VJournalVctr(0), m_VEventVctr(0), m_VTodoVctr(0), + m_VTimeZoneVctr(0), m_VFreebusyVctr(0), m_XTokensVctr(0), + m_CalScale(0), +#if 0 + m_Source(0), m_Name(0), +#endif + m_Version(0), + m_Prodid(0), m_iMethod(0) +{ + //PR_ASSERT(m_Log != 0); + m_Log = initLog; +} +//--------------------------------------------------------------------- +NSCalendar::NSCalendar(NSCalendar & that) +: m_VJournalVctr(0), m_VEventVctr(0), m_VTodoVctr(0), + m_VTimeZoneVctr(0), m_VFreebusyVctr(0), m_XTokensVctr(0), +#if 0 + m_Source(0), m_Name(0), +#endif + m_CalScale(0), m_Version(0), m_Prodid(0) +{ + m_iMethod = that.m_iMethod; + // copy component vectors + if (that.m_VJournalVctr != 0) + { + m_VJournalVctr = new JulianPtrArray(); PR_ASSERT(m_VJournalVctr != 0); + if (m_VJournalVctr != 0) + { + ICalComponent::cloneICalComponentVector(m_VJournalVctr, that.m_VJournalVctr); + } + } + if (that.m_VEventVctr != 0) + { + m_VEventVctr = new JulianPtrArray(); PR_ASSERT(m_VEventVctr != 0); + if (m_VEventVctr != 0) + { + ICalComponent::cloneICalComponentVector(m_VEventVctr, that.m_VEventVctr); + } + } + if (that.m_VTodoVctr != 0) + { + m_VTodoVctr = new JulianPtrArray(); PR_ASSERT(m_VTodoVctr != 0); + if (m_VTodoVctr != 0) + { + ICalComponent::cloneICalComponentVector(m_VTodoVctr, that.m_VTodoVctr); + } + } + if (that.m_VTimeZoneVctr != 0) + { + m_VTimeZoneVctr = new JulianPtrArray(); PR_ASSERT(m_VTimeZoneVctr != 0); + if (m_VTimeZoneVctr != 0) + { + ICalComponent::cloneICalComponentVector(m_VTimeZoneVctr, that.m_VTimeZoneVctr); + } + } + if (that.m_VFreebusyVctr != 0) + { + m_VFreebusyVctr = new JulianPtrArray(); PR_ASSERT(m_VFreebusyVctr != 0); + if (m_VFreebusyVctr != 0) + { + ICalComponent::cloneICalComponentVector(m_VFreebusyVctr, that.m_VFreebusyVctr); + } + } + // clone xtokens + if (that.m_XTokensVctr != 0) + { + m_XTokensVctr = new JulianPtrArray(); PR_ASSERT(m_XTokensVctr != 0); + if (m_XTokensVctr != 0) + { + ICalProperty::CloneUnicodeStringVector(that.m_XTokensVctr, m_XTokensVctr); + } + } + // clone ICalProperties. + if (that.m_CalScale != 0) + { + m_CalScale = that.m_CalScale->clone(m_Log); + } + if (that.m_Version != 0) + { + m_Version = that.m_Version->clone(m_Log); + } + if (that.m_Prodid != 0) + { + m_Prodid = that.m_Prodid->clone(m_Log); + } +#if 0 + if (that.m_Source != 0) + { + m_Source = that.m_Source->clone(m_Log); + } + if (that.m_Name != 0) + { + m_Name = that.m_Name->clone(m_Log); + } +#endif + + +} +//--------------------------------------------------------------------- +NSCalendar::~NSCalendar() +{ + if (m_VEventVctr != 0) + { + ICalComponent::deleteICalComponentVector(m_VEventVctr); + delete m_VEventVctr; m_VEventVctr = 0; + } + if (m_VFreebusyVctr != 0) + { + ICalComponent::deleteICalComponentVector(m_VFreebusyVctr); + delete m_VFreebusyVctr; m_VFreebusyVctr = 0; + } + if (m_VJournalVctr != 0) + { + ICalComponent::deleteICalComponentVector(m_VJournalVctr); + delete m_VJournalVctr; m_VJournalVctr = 0; + } + if (m_VTodoVctr!= 0) + { + ICalComponent::deleteICalComponentVector(m_VTodoVctr); + delete m_VTodoVctr; m_VTodoVctr = 0; + } + if (m_VTimeZoneVctr!= 0) + { + ICalComponent::deleteICalComponentVector(m_VTimeZoneVctr); + delete m_VTimeZoneVctr; m_VTimeZoneVctr = 0; + } + + if (m_CalScale != 0) + { + delete m_CalScale; m_CalScale = 0; + } + if (m_Prodid != 0) + { + delete m_Prodid; m_Prodid = 0; + } + if (m_Version != 0) + { + delete m_Version; m_Version = 0; + } +#if 0 + if (m_Name != 0) + { + delete m_Name; m_Name = 0; + } + if (m_Source != 0) + { + delete m_Source; m_Source = 0; + } +#endif + + //if (m_Method != 0) { delete m_Method; m_Method = 0; } + + if (m_XTokensVctr != 0) + { + ICalComponent::deleteUnicodeStringVector(m_XTokensVctr); + delete m_XTokensVctr; m_XTokensVctr = 0; + } +} +//--------------------------------------------------------------------- + +/* + * Returns: + * TRUE if export worked + * FALSE if there was a problem + */ +void +NSCalendar::export(const char * filename, t_bool & status) +{ + FILE *f = fopen(filename, "w"); + if (f != 0) + { + char * ucc = 0; +#if 1 + UnicodeString sResult, out; + status = TRUE; + + sResult = JulianKeyword::Instance()->ms_sBEGIN_VCALENDAR; + sResult += JulianKeyword::Instance()->ms_sLINEBREAK; + ucc = sResult.toCString(""); + if (ucc != 0) + { + fprintf(f, ucc); + delete [] ucc; ucc = 0; + } + else + status = FALSE; + + // PRINT Calendar Properties + sResult = createCalendarHeader(out); + ucc = sResult.toCString(""); + if (ucc != 0) + { + fprintf(f, ucc); + delete [] ucc; ucc = 0; + } + else + status = FALSE; + + // PRINT X-TOKENS + sResult = ICalProperty::vectorToICALString(getXTokens(), out); + ucc = sResult.toCString(""); + if (ucc != 0) + { + fprintf(f, ucc); + delete [] ucc; ucc = 0; + } + else + status = FALSE; + + // PRINT Calendar Components + status |= printComponentVectorToFile(getTimeZones(), f); + status |= printComponentVectorToFile(getEvents(), f); + status |= printComponentVectorToFile(getTodos(), f); + status |= printComponentVectorToFile(getJournals(), f); + status |= printComponentVectorToFile(getVFreebusy(), f); + + sResult = JulianKeyword::Instance()->ms_sEND_VCALENDAR; + sResult += JulianKeyword::Instance()->ms_sLINEBREAK; + ucc = sResult.toCString(""); + if (ucc != 0) + { + fprintf(f, ucc); + delete [] ucc; ucc = 0; + } + else + status = FALSE; + +#else + char * ucc = toICALString().toCString(""); + if (ucc != 0) + { + size_t iLen = strlen(ucc); + size_t iCountWritten = fwrite(ucc, iLen, 1, f); + delete [] ucc; ucc = 0; + status = (iCountWritten == 1) ? TRUE : FALSE; + } + else + { + status = FALSE; + } +#endif + int iRet = fclose(f); + if (0 != iRet) + { + //int iError =errno; + status = FALSE; + } + } + else + { + status = FALSE; + } +} + +//--------------------------------------------------------------------- + +NSCalendar * +NSCalendar::clone(JLog * initLog) +{ + m_Log = initLog; + return new NSCalendar(*this); +} + +//--------------------------------------------------------------------- + +void +NSCalendar::parse(ICalReader * brFile, + UnicodeString & fileName, + JulianUtility::MimeEncoding encoding) +{ + + UnicodeString strLine, propName, propVal; + + JulianPtrArray * parameters = new JulianPtrArray(); + PR_ASSERT(parameters != 0 && brFile != 0); + + if (parameters == 0 || brFile == 0) + return; + + t_bool bNextComponent = FALSE; + + ErrorCode status = ZERO_ERROR; + UnicodeString sOK; + UnicodeString u, sName; + ICalComponent * ic; + t_bool bUpdatedComponent; + + UnicodeString uid; +#if 0 + DateTime d; + UnicodeString rid; +#endif + if (fileName.size() > 0) + { + // TODO: set filename + } + while (TRUE) + { + PR_ASSERT(brFile != 0); + brFile->readFullLine(strLine, status); + ICalProperty::Trim(strLine); + + if (FAILURE(status) && strLine.size() == 0) + break; + + ICalProperty::parsePropertyLine(strLine, propName, + propVal, parameters); + + if (strLine.size() == 0) + { + ICalProperty::deleteICalParameterVector(parameters); + parameters->RemoveAll(); + continue; + } + + // break for "END:" line + else if ((propName.compareIgnoreCase(JulianKeyword::Instance()->ms_sEND) == 0) && + (propVal.compareIgnoreCase(JulianKeyword::Instance()->ms_sVCALENDAR) == 0)) + { + ICalProperty::deleteICalParameterVector(parameters); + parameters->RemoveAll(); + + // if parsing of multiple calendars allowed, continue in loop. + if (m_bLoadMultipleCalendars) + continue; + else + break; + } + else + { + if (propName.compareIgnoreCase(JulianKeyword::Instance()->ms_sBEGIN) == 0) + { + ICalProperty::deleteICalParameterVector(parameters); + parameters->RemoveAll(); + + bNextComponent = TRUE; + sName = propVal; + + while (bNextComponent) + { + // TODO: finish + ic = ICalComponentFactory::Make(sName, m_Log); + if (ic != 0) + { + if (m_Log) m_Log->addEventErrorEntry(); + sOK = ic->parse(brFile, methodToString(getMethod(), u), + sOK, getTimeZones()); + + // TODO: finish smart, multiple handling +#if 0 + if (m_bLoadMultipleCalendars) + { + // if multiple calendars can be loaded, + // then I could overwrite events no matter what (lazy) , or check + // if the sequence number is greater and then overwrite (smart) + // TODO: finish + + JulianPtrArray * out = new JulianPtrArray(); + PR_ASSERT(out != 0); + + if (m_bSmartLoading) + { + // Smart multiple handling, overwrite only if component is old + // TODO: make it getMatchingComponents (handle recid) + getComponentsWithType(out, ic->getUID(), ic->GetType()); + if (out->GetSize() == 0) + { + if (ic->isValid()) + { + bUpdatedComponent = addComponentWithType(ic, ic->GetType()); + if (bUpdatedComponent) + { + delete ic; ic = 0; + } + } + else + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iInvalidComponent, 300); + delete ic; ic = 0; + } + } + else + { + if (ic->getSequence() > getMaximumSequence(out) && + (ic->isValid())) + { + removeComponents(out); + bUpdatedComponent = addComponentWithType(ic, ic->GetType()); + if (bUpdatedComponent) + { + delete ic; ic = 0; + } + } + else + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iInvalidComponent, 300); + delete ic; ic = 0; + } + } + } + else + { + // Lazy multiple handling, overwrite if component matches + // TODO: make it getMatchingComponents (handle recid) + getComponentsWithType(out, ic->getUID(), ic->GetType()); + if (out->GetSize() == 0) + { + if (ic->isValid()) + { + bUpdatedComponent = addComponentWithType(ic, ic->GetType()); + if (bUpdatedComponent) + { + delete ic; ic = 0; + } + } + else + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iInvalidComponent, 300); + delete ic; ic = 0; + } + } + else + { + if (ic->isValid()) + { + removeComponents(out); + bUpdatedComponent = addComponentWithType(ic, ic->GetType()); + if (bUpdatedComponent) + { + delete ic; ic = 0; + } + } + else + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iInvalidComponent, 300); + delete ic; ic = 0; + } + } + } + delete out; out = 0; + } + else + { + // not multiple handling + if (ic->isValid()) + { + bUpdatedComponent = addComponentWithType(ic, ic->GetType()); + if (bUpdatedComponent) + { + delete ic; ic = 0; + } + //addComponent(ic, sName); + } + else + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iInvalidComponent, 300); + delete ic; ic = 0; + } + } +#else // #if 0 + + //if (ic->isValid() && ic->getUID().size() > 0) + if (ic->isValid()) + { + //addComponent(ic, sName); + bUpdatedComponent = addComponentWithType(ic, ic->GetType()); + if (m_Log) + { + m_Log->setCurrentEventLogComponentType((JulianLogErrorVector::ECompType) ic->GetType()); + m_Log->setCurrentEventLogValidity(TRUE); + uid = ""; +#if 0 + rid = ""; +#endif + if (ic->GetType() == ICalComponent::ICAL_COMPONENT_VEVENT || + ic->GetType() == ICalComponent::ICAL_COMPONENT_VTODO || + ic->GetType() == ICalComponent::ICAL_COMPONENT_VJOURNAL) + { + uid = ((TimeBasedEvent *) ic)->getUID(); +#if 0 + d = ((TimeBasedEvent *) ic)->getRecurrenceID(); + if (d.isValid()) + rid = d.toISO8601(); +#endif + } + else if (ic->GetType() == ICalComponent::ICAL_COMPONENT_VFREEBUSY) + { + uid = ((VFreebusy *) ic)->getUID(); + } + else if (ic->GetType() == ICalComponent::ICAL_COMPONENT_VTIMEZONE) + { + uid = ((VTimeZone *) ic)->getTZID(); + } +#if 0 + m_Log->setUIDRecurrenceID(uid, rid); +#else + m_Log->setUID(uid); +#endif + } + if (bUpdatedComponent) + { + delete ic; ic = 0; + } + } + else + { + if (m_Log) + { + //m_Log->setCurrentEventLogComponentType((JulianLogErrorVector::ECompType) ic->GetType()); + // make invalid event errors go to NSCALENDAR + m_Log->setCurrentEventLogComponentType(JulianLogErrorVector::ECompType_NSCALENDAR); + m_Log->setCurrentEventLogValidity(FALSE); + uid = ""; +#if 0 + rid = ""; +#endif + if (ic->GetType() == ICalComponent::ICAL_COMPONENT_VEVENT || + ic->GetType() == ICalComponent::ICAL_COMPONENT_VTODO || + ic->GetType() == ICalComponent::ICAL_COMPONENT_VJOURNAL) + { + uid = ((TimeBasedEvent *) ic)->getUID(); +#if 0 + d = ((TimeBasedEvent *) ic)->getRecurrenceID(); + if (d.isValid()) + rid = d.toISO8601(); +#endif + } + else if (ic->GetType() == ICalComponent::ICAL_COMPONENT_VFREEBUSY) + { + uid = ((VFreebusy *) ic)->getUID(); + } + else if (ic->GetType() == ICalComponent::ICAL_COMPONENT_VTIMEZONE) + { + uid = ((VTimeZone *) ic)->getTZID(); + } +#if 0 + m_Log->setUIDRecurrenceID(uid, rid); +#else + m_Log->setUID(uid); +#endif + } + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iInvalidComponent, 300); +#if 0 + if (m_Log) + { + // Print the REQUEST-STATUS of the deleted event. + if (ic->getRequestStatus() != 0) + { + UnicodeString * uPtr; + t_int32 ii; + for (ii = 0; ii < ic->getRequestStatus()->GetSize(); ii++) + { + uPtr = (UnicodeString *) ic->getRequestStatus()->GetAt(ii); + m_Log->logError(*uPtr); + } + } + } +#endif // #if 0 + delete ic; ic = 0; + } +#endif // #else + if (sOK.compareIgnoreCase(JulianKeyword::Instance()->ms_sOK) == 0) + bNextComponent = FALSE; + else + { + if (sOK.startsWith("BEGIN:")) + { + bNextComponent = TRUE; + // TODO: i'm extracting after 6, that means I'm assuming "BEGIN:whatever" + sName = sOK.extractBetween(6, sOK.size(), sName); + } + else + bNextComponent = FALSE; + } + } + else + bNextComponent = FALSE; + + //----- + if (ICalProperty::IsXToken(sName)) + { + ICalProperty::deleteICalParameterVector(parameters); + parameters->RemoveAll(); + if (m_Log) + { + m_Log->addEventErrorEntry(); + //m_Log->setCurrentEventLogComponentType(JulianLogErrorVector::ECompType_XCOMPONENT); + // make x-toekn errors go to NSCALENDAR + m_Log->setCurrentEventLogComponentType(JulianLogErrorVector::ECompType_NSCALENDAR); + } + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iXTokenComponentIgnored, + JulianKeyword::Instance()->ms_sNSCALENDAR, sName, 200); + + // Ignore all lines between BEGIN:X-COMPONENT and END:X-COMPONENT + while (TRUE) + { + brFile->readFullLine(strLine, status); + if (FAILURE(status) && strLine.size() == 0) + break; + ICalProperty::parsePropertyLine(strLine, propName, propVal, parameters); + ICalProperty::deleteICalParameterVector(parameters); + parameters->RemoveAll(); + + if ((propName.compareIgnoreCase(JulianKeyword::Instance()->ms_sEND) == 0) && + (propVal.compareIgnoreCase(sName) == 0)) + { + // correct end of X-Component parsing + break; + } + else if ( + ((propName.compareIgnoreCase(JulianKeyword::Instance()->ms_sEND) == 0) && + (propVal.compareIgnoreCase(JulianKeyword::Instance()->ms_sVCALENDAR) == 0)) || + + ((propName.compareIgnoreCase(JulianKeyword::Instance()->ms_sBEGIN) == 0) && + ((propVal.compareIgnoreCase(JulianKeyword::Instance()->ms_sVCALENDAR) == 0) || + (propVal.compareIgnoreCase(JulianKeyword::Instance()->ms_sVEVENT) == 0) || + (propVal.compareIgnoreCase(JulianKeyword::Instance()->ms_sVTODO) == 0) || + (propVal.compareIgnoreCase(JulianKeyword::Instance()->ms_sVJOURNAL) == 0) || + (propVal.compareIgnoreCase(JulianKeyword::Instance()->ms_sVFREEBUSY) == 0) || + (propVal.compareIgnoreCase(JulianKeyword::Instance()->ms_sVTIMEZONE) == 0) || + (ICalProperty::IsXToken(propVal))))) + + { + // incorrect end of X-Component parsing, log an error + // ends with END:VCALENDAR or BEGIN:VCALENDAR, VEVENT, VTODO, VJOURNAL, VFREEBUSY, VTIMEZONE + // or BEGIN:X-token + + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iAbruptEndOfParsing, + JulianKeyword::Instance()->ms_sNSCALENDAR, strLine, 300); + sOK = propName; + sOK += JulianKeyword::Instance()->ms_sCOLON_SYMBOL; + sOK += propVal; + bNextComponent = TRUE; + sName = propVal; + break; + } + } + } + //----- + //if (ic == 0 || (!bNextComponent)) + if (ic == 0 && (!bNextComponent)) + { + break; + } + } + } + else + { + if (m_Log) m_Log->setCurrentEventLogComponentType(JulianLogErrorVector::ECompType_NSCALENDAR); + storeData(strLine, propName, propVal, parameters); + + ICalProperty::deleteICalParameterVector(parameters); + parameters->RemoveAll(); + } + } + } + ICalProperty::deleteICalParameterVector(parameters); + parameters->RemoveAll(); + delete parameters; parameters = 0; + expandAllComponents(); + //selfCheck(); +} + +//--------------------------------------------------------------------- + +t_bool NSCalendar::storeData(UnicodeString & strLine, UnicodeString & propName, + UnicodeString & propVal, JulianPtrArray * parameters) +{ + t_int32 i; + + t_int32 hashCode = propName.hashCode(); + if (JulianKeyword::Instance()->ms_ATOM_VERSION == hashCode) + { + // no parameters + if (parameters->GetSize() > 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iInvalidOptionalParam, + JulianKeyword::Instance()->ms_sVCALENDAR, strLine, 100); + } + setVersion(propVal, parameters); + return TRUE; + } + else if (JulianKeyword::Instance()->ms_ATOM_PRODID == hashCode) + { + // no parameters + if (parameters->GetSize() > 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iInvalidOptionalParam, + JulianKeyword::Instance()->ms_sVCALENDAR, strLine, 100); + } + setProdid(propVal, parameters); + return TRUE; + } + else if (JulianKeyword::Instance()->ms_ATOM_CALSCALE == hashCode) + { + // no parameters + if (parameters->GetSize() > 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iInvalidOptionalParam, + JulianKeyword::Instance()->ms_sVCALENDAR, strLine, 100); + } + // if propVal != CALSCALE, just log, + // will set to GREGORIAN later. + if (JulianKeyword::Instance()->ms_ATOM_GREGORIAN != propVal.hashCode()) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iInvalidPropertyValue, + JulianKeyword::Instance()->ms_sVCALENDAR, + propName, propVal, 200); + } + + setCalScale(propVal, parameters); + return TRUE; + } + else if (JulianKeyword::Instance()->ms_ATOM_METHOD == hashCode) + { + // no parameters + if (parameters->GetSize() > 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iInvalidOptionalParam, + JulianKeyword::Instance()->ms_sVCALENDAR, strLine, 100); + } + i = stringToMethod(propVal); + if (i < 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iInvalidPropertyValue, + JulianKeyword::Instance()->ms_sVCALENDAR, + propName, propVal, 200); + } + else + { + if (getMethod() >= 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iDuplicatedProperty, + JulianKeyword::Instance()->ms_sVCALENDAR, + propName, propVal, 100); + } + setMethod((NSCalendar::METHOD) i); + } + return TRUE; + } + else if (ICalProperty::IsXToken(propName)) + { + addXTokens(strLine); + + return TRUE; + } +#if 0 + else if (JulianKeyword::Instance()->ms_ATOM_SOURCE == hashCode) + { + // no parameters + if (parameters->GetSize() > 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iInvalidOptionalParam, + JulianKeyword::Instance()->ms_sVCALENDAR, strLine, 100); + } + setSource(propVal, parameters); + return TRUE; + } + else if (JulianKeyword::Instance()->ms_ATOM_NAME == hashCode) + { + // no parameters + if (parameters->GetSize() > 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iInvalidOptionalParam, + JulianKeyword::Instance()->ms_sVCALENDAR, strLine, 100); + } + setName(propVal, parameters); + return TRUE; + } +#endif + else + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iInvalidPropertyName, + JulianKeyword::Instance()->ms_sVCALENDAR, + propName, 200); + + return FALSE; + } +} +//--------------------------------------------------------------------- + +void +NSCalendar::expandAllComponents() +{ + JulianPtrArray * v = 0; + v = getEvents(); + expandTBEVector(v, ICalComponent::ICAL_COMPONENT_VEVENT); + + v = getTodos(); + expandTBEVector(v, ICalComponent::ICAL_COMPONENT_VTODO); + + v = getJournals(); + expandTBEVector(v, ICalComponent::ICAL_COMPONENT_VJOURNAL); +} + +//--------------------------------------------------------------------- + +void +NSCalendar::expandTBEVector(JulianPtrArray * v, + ICalComponent::ICAL_COMPONENT type) +{ + // no need to expand if method is a decline-counter or refresh + if (v != 0 && (m_iMethod != METHOD_DECLINECOUNTER && m_iMethod != METHOD_REFRESH)) + { + t_int32 i; + TimeBasedEvent * tbe = 0; + for (i = v->GetSize() - 1; i >= 0; i--) + { + tbe = (TimeBasedEvent *) v->GetAt(i); + if (tbe->isExpandableEvent()) + { + expandComponent(tbe, type); + + // remove old event + v->RemoveAt(i); + delete tbe; tbe = 0; + } + } + } +} + +//--------------------------------------------------------------------- + +void +NSCalendar::expandComponent(TimeBasedEvent * tbe, + ICalComponent::ICAL_COMPONENT type) +{ + JulianPtrArray * v = new JulianPtrArray(); PR_ASSERT(v != 0); + if (v != 0) + { + // create the components and fill them in v, passing in timezone vector + tbe->createRecurrenceEvents(v, getTimeZones()); + + // add each component to correct vector. + if (v->GetSize() > 0) + { + //UnicodeString uDebug; + //if (FALSE) TRACE("Expandable event\r\n\t%s\n\tbeing expanded", tbe->toString(uDebug).toCString("")); + t_int32 i; + ICalComponent * ic = 0; + t_bool bUpdatedComponent = FALSE; + for (i = 0; i < v->GetSize(); i++) + { + ic = (ICalComponent *) v->GetAt(i); + bUpdatedComponent = addComponentWithType(ic, type); + if (bUpdatedComponent) + { + delete ic; ic = 0; + } + } + } + delete v; v = 0; + } +} + +//--------------------------------------------------------------------- + +JulianPtrArray * +NSCalendar::getLogVector(ICalComponent * ic) +{ + if (m_Log && ic) + { + JulianPtrArray * vvError = 0; + vvError = m_Log->GetErrorVector(); + if (vvError != 0) + { + t_int32 i = 0; + JulianLogErrorVector * lev = 0; + UnicodeString uid; +#if 0 + UnicodeString rid; +#endif + ICalComponent::ICAL_COMPONENT icType; + icType = ic->GetType(); + if (icType == ICalComponent::ICAL_COMPONENT_VEVENT || + icType == ICalComponent::ICAL_COMPONENT_VTODO || + icType == ICalComponent::ICAL_COMPONENT_VJOURNAL) + { +#if 0 + DateTime d; + d = ((TimeBasedEvent *) ic)->getRecurrenceID(); + if (d.isValid()) + rid = d.toISO8601(); +#endif + uid = ((TimeBasedEvent *) ic)->getUID(); + } + else if (icType == ICalComponent::ICAL_COMPONENT_VFREEBUSY) + { + uid = ((VFreebusy *) ic)->getUID(); + } + else if (icType == ICalComponent::ICAL_COMPONENT_VTIMEZONE) + { + uid = ((VTimeZone *) ic)->getTZID(); + } + + for (i = 0; i < vvError->GetSize(); i++) + { + lev = (JulianLogErrorVector *) vvError->GetAt(i); + if ((lev->GetComponentType() == (JulianLogErrorVector::ECompType) ic->GetType()) && + (lev->GetUID() == uid) +#if 0 + && (lev->GetRecurrenceID() == rid) +#endif + ) + return (lev->GetErrors()); + } + } + } + return 0; +} + +//--------------------------------------------------------------------- + +JulianPtrArray * +NSCalendar::getLogVector() +{ + if (m_Log) + { + JulianPtrArray * vvError = 0; + vvError = m_Log->GetErrorVector(); + if (vvError != 0) + { + t_int32 i = 0; + JulianLogErrorVector * lev = 0; + for (i = 0; i < vvError->GetSize(); i++) + { + lev = (JulianLogErrorVector *) vvError->GetAt(i); + if (lev->GetComponentType() == JulianLogErrorVector::ECompType_NSCALENDAR) + return (lev->GetErrors()); + } + } + } + return 0; +} + +//--------------------------------------------------------------------- + +UnicodeString NSCalendar::toString() +{ + UnicodeString sResult, s, out; + s = JulianKeyword::Instance()->ms_sPRODID; + sResult += ICalProperty::propertyToICALString(s, getProdidProperty(), out); + s = JulianKeyword::Instance()->ms_sCALSCALE; + sResult += ICalProperty::propertyToICALString(s, getCalScaleProperty(), out); + s = JulianKeyword::Instance()->ms_sVERSION; + sResult += ICalProperty::propertyToICALString(s, getVersionProperty(), out); +#if 0 + s = JulianKeyword::Instance()->ms_sNAME; + sResult += ICalProperty::propertyToICALString(s, getNameProperty(), out); + s = JulianKeyword::Instance()->ms_sSOURCE; + sResult += ICalProperty::propertyToICALString(s, getSourceProperty(), out); +#endif + // print method + sResult += JulianKeyword::Instance()->ms_sMETHOD; + sResult += JulianKeyword::Instance()->ms_sCOLON_SYMBOL; + sResult += methodToString(getMethod(), out); + + sResult += JulianKeyword::Instance()->ms_sLINEBREAK; + //sResult += ICalProperty::propertyToICALString(s, getMethodProperty(), sResult); + + return sResult; +} + +//--------------------------------------------------------------------- + +UnicodeString & +NSCalendar::createCalendarHeader(UnicodeString & sResult) +{ + UnicodeString s, out; + sResult = ""; + s = JulianKeyword::Instance()->ms_sPRODID; + sResult += ICalProperty::propertyToICALString(s, getProdidProperty(), out); + s = JulianKeyword::Instance()->ms_sCALSCALE; + sResult += ICalProperty::propertyToICALString(s, getCalScaleProperty(), out); + s = JulianKeyword::Instance()->ms_sVERSION; + sResult += ICalProperty::propertyToICALString(s, getVersionProperty(), out); +#if 0 + s = JulianKeyword::Instance()->ms_sNAME; + sResult += ICalProperty::propertyToICALString(s, getNameProperty(), out); + s = JulianKeyword::Instance()->ms_sSOURCE; + sResult += ICalProperty::propertyToICALString(s, getSourceProperty(), out); +#endif + // print method enum + sResult += JulianKeyword::Instance()->ms_sMETHOD; + sResult += JulianKeyword::Instance()->ms_sCOLON_SYMBOL; + sResult += methodToString(getMethod(), out); + sResult += JulianKeyword::Instance()->ms_sLINEBREAK; + //sResult += ICalProperty::propertyToICALString(s, getMethodProperty(), out); + + return sResult; +} + +//--------------------------------------------------------------------- + +UnicodeString NSCalendar::toICALString() +{ + UnicodeString sResult, out; + sResult = JulianKeyword::Instance()->ms_sBEGIN_VCALENDAR; + sResult += JulianKeyword::Instance()->ms_sLINEBREAK; + sResult += createCalendarHeader(out); + sResult += ICalProperty::vectorToICALString(getXTokens(), out); + //if (FALSE) TRACE("out = %s", out.toCString("")); + + // PRINT Calendar Components + sResult += printComponentVector(getTimeZones(), out); + sResult += printComponentVector(getEvents(), out); + sResult += printComponentVector(getVFreebusy(), out); + sResult += printComponentVector(getTodos(), out); + sResult += printComponentVector(getJournals(), out); + sResult += JulianKeyword::Instance()->ms_sEND_VCALENDAR; + sResult += JulianKeyword::Instance()->ms_sLINEBREAK; + return sResult; +} +//--------------------------------------------------------------------- +VEvent * NSCalendar::getEvent(UnicodeString sUID, t_int32 iSeqNo) +{ + return (VEvent *) NSCalendar::getComponent(getEvents(), sUID, iSeqNo); +} +//--------------------------------------------------------------------- +VTodo * NSCalendar::getTodo(UnicodeString sUID, t_int32 iSeqNo) +{ + return (VTodo *) NSCalendar::getComponent(getTodos(), sUID, iSeqNo); +} +//--------------------------------------------------------------------- +VJournal * NSCalendar::getJournal(UnicodeString sUID, t_int32 iSeqNo) +{ + return (VJournal *) NSCalendar::getComponent(getJournals(), sUID, iSeqNo); +} +//--------------------------------------------------------------------- +VFreebusy * NSCalendar::getVFreebusy(UnicodeString sUID, t_int32 iSeqNo) +{ + return (VFreebusy *) NSCalendar::getComponent(getVFreebusy(), sUID, iSeqNo); +} +//--------------------------------------------------------------------- + +ICalComponent * +NSCalendar::getComponent(JulianPtrArray * vTBE, + UnicodeString & sUID, t_int32 iSeqNo) + +{ + ICalComponent * e = 0; + t_int32 i; + if (vTBE != 0 && sUID.size() > 0) + { + if (iSeqNo != -1) { + + for (i = 0; i < vTBE->GetSize(); i++) + { + e = (ICalComponent *) vTBE->GetAt(i); + if (e->MatchUID_seqNO(sUID, iSeqNo)) + return e; + } + } + else + { + for (i = 0; i < vTBE->GetSize(); i++) + { + e = (ICalComponent *) vTBE->GetAt(i); + if (e->getUID().compareIgnoreCase(sUID) == 0) + return e; + } + } + } + return 0; +} +//--------------------------------------------------------------------- +JulianPtrArray * NSCalendar::changeEventsOwnership() +{ + JulianPtrArray * out = m_VEventVctr; + m_VEventVctr = 0; + return out; +} +//--------------------------------------------------------------------- +void NSCalendar::updateEventsRange(VEvent * v) +{ + DateTime start, end; + PR_ASSERT(v->isValid()); + start = v->getDTStart(); + end = v->getDTEnd(); + if (start.isValid()) + { + if (!m_EventsSpanStart.isValid()) + m_EventsSpanStart = start; + else + { + if (m_EventsSpanStart.afterDateTime(start)) + m_EventsSpanStart = start; + } + // set m_EventsSpanEnd to start if end not valid and m_EventsSpanNotSet + if (!m_EventsSpanEnd.isValid() && (!end.isValid())) + { + m_EventsSpanEnd = start; + } + } + if (end.isValid()) + { + if (!m_EventsSpanEnd.isValid()) + m_EventsSpanEnd = end; + else + { + if (m_EventsSpanEnd.beforeDateTime(end)) + m_EventsSpanEnd = end; + } + } +} +//--------------------------------------------------------------------- +void NSCalendar::addEvent(ICalComponent * v) +{ + if (m_VEventVctr == 0) + m_VEventVctr = new JulianPtrArray(); + PR_ASSERT(m_VEventVctr != 0); + if (m_VEventVctr != 0) + { + PR_ASSERT(ICalComponent::ICAL_COMPONENT_VEVENT == v->GetType()); + updateEventsRange((VEvent *) v); + m_VEventVctr->Add(v); + //m_VEventVctr->InsertBinary(v, TimeBasedEvent::CompareTimeBasedEventsByDTStart); + } +} +//--------------------------------------------------------------------- +void NSCalendar::addEventList(JulianPtrArray* pEventList) +{ + int j; + ICalComponent* pEvent; + if (0 != pEventList) + { + for (j = 0; j < pEventList->GetSize(); j++) + { + pEvent = (ICalComponent*)pEventList->GetAt(j); + if (0 != pEvent) + addEvent(pEvent); + } + } +} +//--------------------------------------------------------------------- +void NSCalendar::addTodo(ICalComponent * v) +{ + if (m_VTodoVctr == 0) + m_VTodoVctr = new JulianPtrArray(); + PR_ASSERT(m_VTodoVctr != 0); + if (m_VTodoVctr != 0) + { + m_VTodoVctr->Add(v); + //m_VTodoVctr->InsertBinary(v, TimeBasedEvent::CompareTimeBasedEventsByDTStart); + } +} +//--------------------------------------------------------------------- +void NSCalendar::addJournal(ICalComponent * v) +{ + if (m_VJournalVctr == 0) + m_VJournalVctr = new JulianPtrArray(); + PR_ASSERT(m_VJournalVctr != 0); + if (m_VJournalVctr != 0) + { + m_VJournalVctr->Add(v); + //m_VJournalVctr->InsertBinary(v, TimeBasedEvent::CompareTimeBasedEventsByDTStart); + } +} +//--------------------------------------------------------------------- +void NSCalendar::addVFreebusy(ICalComponent * v) +{ + if (m_VFreebusyVctr == 0) + m_VFreebusyVctr = new JulianPtrArray(); + PR_ASSERT(m_VFreebusyVctr != 0); + if (m_VFreebusyVctr != 0) + { + m_VFreebusyVctr->Add(v); + //m_VFreebusyVctr->InsertBinary(v, VFreebusy::CompareVFreebusyByDTStart); + } +} +//--------------------------------------------------------------------- +void NSCalendar::addTimeZone(ICalComponent * v) +{ + if (m_VTimeZoneVctr == 0) + m_VTimeZoneVctr = new JulianPtrArray(); + PR_ASSERT(m_VTimeZoneVctr != 0); + if (m_VTimeZoneVctr != 0) + { + m_VTimeZoneVctr->Add(v); + } +} +//--------------------------------------------------------------------- + +t_bool NSCalendar::addComponentWithType(ICalComponent * ic, + ICalComponent::ICAL_COMPONENT type) +{ + + ///////////// + // if already have component, just update it + JulianPtrArray * v = 0; + t_bool bUpdatedAnyComponents = FALSE; + + switch(ic->GetType()) + { + case ICalComponent::ICAL_COMPONENT_VEVENT: + v = m_VEventVctr; + break; + case ICalComponent::ICAL_COMPONENT_VTODO: + v = m_VTodoVctr; + break; + case ICalComponent::ICAL_COMPONENT_VJOURNAL: + v = m_VJournalVctr; + break; + case ICalComponent::ICAL_COMPONENT_VTIMEZONE: + v = m_VTimeZoneVctr; + break; + case ICalComponent::ICAL_COMPONENT_VFREEBUSY: + v = m_VFreebusyVctr; + break; + default: + v = 0; + } + if (v != 0) + { + t_bool bUpdated = FALSE; + t_int32 i; + ICalComponent * comp = 0; + for (i = 0; i < v->GetSize(); i++) + { + comp = (ICalComponent *) v->GetAt(i); + bUpdated = comp->updateComponent(ic); + bUpdatedAnyComponents |= bUpdated; + } + } + + if (!bUpdatedAnyComponents) + { + // Add only if not updated. + switch (type) + { + case ICalComponent::ICAL_COMPONENT_VEVENT: + addEvent(ic); + break; + case ICalComponent::ICAL_COMPONENT_VTODO: + addTodo(ic); + break; + case ICalComponent::ICAL_COMPONENT_VJOURNAL: + addJournal(ic); + break; + case ICalComponent::ICAL_COMPONENT_VTIMEZONE: + addTimeZone(ic); + break; + case ICalComponent::ICAL_COMPONENT_VFREEBUSY: + addVFreebusy(ic); + break; + default: + break; + } + } + + return bUpdatedAnyComponents; +} + +//--------------------------------------------------------------------- +#if 0 +void NSCalendar::addComponentsWithType(JulianPtrArray * components, + ICalComponent::ICAL_COMPONENT type) +{ + t_int32 i; + PR_ASSERT(components != 0); + if (components != 0) + { + for (i = 0; i < components->GetSize(); i++) + { + ICalComponent * ic = (ICalComponent *) components->GetAt(i); + addComponentWithType(ic, type); + } + } +} +#endif +//--------------------------------------------------------------------- + +void +NSCalendar::createVFreebusyHelper(Freebusy * f, DateTime start, + DateTime end) +{ + if (f != 0) + { + t_int32 i; + + DateTime startP; + + DateTime endP; + + Period period; + period.setStart(start); + period.setEnd(end); + + VEvent * ev; + + Period * p; + + f->setType(Freebusy::FB_TYPE_BUSY); +#if 0 + f->setStatus(Freebusy::FB_STATUS_BUSY); +#endif + JulianPtrArray * v = getEvents(); + + if (v != 0) + { + for (i = 0; i < v->GetSize(); i++) + { + ev = (VEvent *) v->GetAt(i); + + // must be opaque + if (ev->getTransp() == JulianKeyword::Instance()->ms_sOPAQUE) + { + startP = ev->getDTStart(); + endP = ((ev->isAllDayEvent()) ? start : ev->getDTEnd()); + + if (period.isIntersecting(startP, endP)) + { + startP = ((start > startP) ? start : startP); + + endP = ((end < endP) ? end : endP); + + p = new Period(); PR_ASSERT(p != 0); + if (p != 0) + { + p->setStart(startP); + p->setEnd(endP); + f->addPeriod(p); + delete p; p = 0; + } + } + } + } + } + } +} + +//--------------------------------------------------------------------- + +VFreebusy * +NSCalendar::createVFreebusy(DateTime start, DateTime end) +{ + + // set freebusy type and status to busy + Freebusy * f = new Freebusy(m_Log); PR_ASSERT(f != 0); + createVFreebusyHelper(f, start, end); + + // create the vfreebusy + VFreebusy * vf = new VFreebusy(m_Log); + PR_ASSERT(vf != 0); + if (vf != 0) + { + DateTime dCreated; + /*vf->setCreated(dCreated);*/ + vf->setLastModified(dCreated); + vf->setDTStart(start); + vf->setDTEnd(end); + UnicodeString us = "vfbreply@hostname.com"; + + vf->setUID(JulianUIDRandomGenerator::generate(us)); + vf->setSequence(0); + if (f != 0) + { + vf->addFreebusy(f); + } + vf->normalize(); + } + return vf; +} + +//--------------------------------------------------------------------- + +void NSCalendar::calculateVFreebusy(VFreebusy * toFillIn) +{ + if (toFillIn != 0) + { + DateTime start, end; + start = toFillIn->getDTStart(); + end = toFillIn->getDTEnd(); + + if (start.isValid() && + end.isValid() && + !start.afterDateTime(end)) + { + DateTime currentTime; + + // remove all old freebusy periods + toFillIn->removeAllFreebusy(); + + Freebusy * f = new Freebusy(m_Log); PR_ASSERT(f != 0); + createVFreebusyHelper(f, start, end); + if (f != 0) + { + toFillIn->addFreebusy(f); + } + toFillIn->normalize(); + toFillIn->setLastModified(currentTime); + } + } +} + +//--------------------------------------------------------------------- + +t_bool +NSCalendar::printComponentVectorToFile(JulianPtrArray * components, + FILE * f) +{ + t_bool bWrittenOK = TRUE; + if (components != 0 && f != 0) + { + UnicodeString out; + ICalComponent * ic = 0; + char * occ = 0; + t_int32 i; + for (i = 0; i < components->GetSize(); i++) + { + ic = (ICalComponent *) components->GetAt(i); + out = ic->toICALString(); + occ = out.toCString(""); + if (occ != 0) + { + fprintf(f, occ); + delete [] occ; occ = 0; + } + else + { + bWrittenOK = FALSE; + break; + } + } + } + return bWrittenOK; +} + +//--------------------------------------------------------------------- + +UnicodeString & +NSCalendar::printComponentVector(JulianPtrArray * components, + UnicodeString & out) +{ + out = ""; + + if (components != 0) + { + ICalComponent * ic = 0; + t_int32 i; + for (i = 0; i < components->GetSize(); i++) + { + ic = (ICalComponent *) components->GetAt(i); + out += ic->toICALString(); + } + } + return out; +} + +//--------------------------------------------------------------------- + +UnicodeString & +NSCalendar::printFilteredComponentVector(JulianPtrArray * components, + UnicodeString & strFmt, + UnicodeString & out) +{ + t_int32 i; + out = ""; + + if (components != 0) + { + UnicodeString u; + for (i = 0; i < components->GetSize(); i++) + { + ICalComponent * ic = (ICalComponent *) components->GetAt(i); + u = ICalComponent::componentToString(ic->GetType()); + out += ic->format(u, strFmt, "", FALSE); + } + } + return out; +} + +//--------------------------------------------------------------------- +#if 0 +UnicodeString & +NSCalendar::printFilteredComponentVectorWithProperties(JulianPtrArray * components, + char ** ppsPropList, + t_int32 iPropCount, + UnicodeString & out) +{ + UnicodeString strFmt; + out = ""; + strFmt = ICalComponent::makeFormatString(ppsPropList, iPropCount, strFmt); + out = printFilteredComponentVector(components, strFmt, out); + return out; +} +#endif +//--------------------------------------------------------------------- + +UnicodeString & +NSCalendar::debugPrintComponentVector(JulianPtrArray * components, + const UnicodeString sType, + UnicodeString & out) +{ + t_int32 i; + out = ""; + + if (components != 0) + { + char num[10]; + sprintf(num, "%d", components->GetSize()); + out += "----"; + out += sType; + out += "'s ---- N = "; + out += num; + out += "-------- \r\n"; + + for (i = 0; i < components->GetSize(); i++) + { + ICalComponent * ic = (ICalComponent *) components->GetAt(i); + sprintf(num, "%d", i + 1); + out += num; + out += ")\t"; + out += ic->toString(); + out += JulianKeyword::Instance()->ms_sLINEBREAK; + } + } + else + { + out += "----"; out += sType; out += "'s ---- N = 0 --------\r\n"; + } + return out; +} + +//--------------------------------------------------------------------- + +void +NSCalendar::getUniqueUIDs(JulianPtrArray * retUID, + ICalComponent::ICAL_COMPONENT type) +{ + // only handle VEvent, VTodo, VJournal, VFreebusy + switch (type) + { + case ICalComponent::ICAL_COMPONENT_VEVENT: + getUniqueUIDsHelper(retUID, getEvents(), type); + break; + case ICalComponent::ICAL_COMPONENT_VTODO: + getUniqueUIDsHelper(retUID, getTodos(), type); + break; + case ICalComponent::ICAL_COMPONENT_VJOURNAL: + getUniqueUIDsHelper(retUID, getJournals(), type); + break; + case ICalComponent::ICAL_COMPONENT_VFREEBUSY: + getUniqueUIDsHelper(retUID, getVFreebusy(), type); + break; + default: + break; + } +} + +//--------------------------------------------------------------------- +void NSCalendar::getEventsByRange(JulianPtrArray * out, + DateTime start, DateTime end) +{ + if (out != 0) + { + if (m_VEventVctr != 0) + { + t_int32 i; + VEvent * anEvent; + for (i = 0; i < m_VEventVctr->GetSize(); i++) + { + anEvent = (VEvent *) m_VEventVctr->GetAt(i); + if (!(anEvent->getDTStart().beforeDateTime(start)) && + !(anEvent->getDTStart().afterDateTime(end))) + { + out->Add(anEvent); + } + } + } + } +} +//--------------------------------------------------------------------- +void NSCalendar::getEvents(JulianPtrArray * out, UnicodeString & sUID) +{ + getComponents(out, getEvents(), sUID); +} +//--------------------------------------------------------------------- +void NSCalendar::getEventsByComponentID(JulianPtrArray * out, + UnicodeString & sUID, + UnicodeString & sRecurrenceID, + UnicodeString & sModifier) +{ + getTBEByComponentID(out, getEvents(), sUID, sRecurrenceID, sModifier); +} +//--------------------------------------------------------------------- +void NSCalendar::getTodos(JulianPtrArray * out, UnicodeString & sUID) +{ + getComponents(out, getTodos(), sUID); +} +//--------------------------------------------------------------------- +void NSCalendar::getJournals(JulianPtrArray * out, UnicodeString & sUID) +{ + getComponents(out, getJournals(), sUID); +} +//--------------------------------------------------------------------- + +void +NSCalendar::sortComponentsByUID(ICalComponent::ICAL_COMPONENT type) +{ + switch (type) + { + // only sorts VEvent, VTodo, VJournal, VFreebusy, not VTimeZone + case ICalComponent::ICAL_COMPONENT_VEVENT: + sortComponentsByUIDHelper(getEvents(), type); + break; + case ICalComponent::ICAL_COMPONENT_VTODO: + sortComponentsByUIDHelper(getTodos(), type); + break; + case ICalComponent::ICAL_COMPONENT_VJOURNAL: + sortComponentsByUIDHelper(getJournals(), type); + break; + case ICalComponent::ICAL_COMPONENT_VFREEBUSY: + sortComponentsByUIDHelper(getVFreebusy(), type); + break; + default: + break; + } +} + +//--------------------------------------------------------------------- + +void +NSCalendar::sortComponentsByDTStart(ICalComponent::ICAL_COMPONENT type) +{ + switch (type) + { + // only sort VEvent, VTodo, VJournal, VFreebusy, not VTimeZone + case ICalComponent::ICAL_COMPONENT_VEVENT: + sortComponentsByDTStartHelper(getEvents(), type); + break; + case ICalComponent::ICAL_COMPONENT_VTODO: + sortComponentsByDTStartHelper(getTodos(), type); + break; + case ICalComponent::ICAL_COMPONENT_VJOURNAL: + sortComponentsByDTStartHelper(getJournals(), type); + break; + case ICalComponent::ICAL_COMPONENT_VFREEBUSY: + sortComponentsByDTStartHelper(getVFreebusy(), type); + break; + default: + break; + } +} + +//--------------------------------------------------------------------- + +void +NSCalendar::sortComponentsByUIDHelper(JulianPtrArray * components, + ICalComponent::ICAL_COMPONENT type) +{ + if (components != 0) + { + switch (type) + { + // only sort VEvent, VTodo, VJournal, VFreebusy + case ICalComponent::ICAL_COMPONENT_VEVENT: + case ICalComponent::ICAL_COMPONENT_VTODO: + case ICalComponent::ICAL_COMPONENT_VJOURNAL: + components->QuickSort(TimeBasedEvent::CompareTimeBasedEventsByUID); + break; + case ICalComponent::ICAL_COMPONENT_VFREEBUSY: + components->QuickSort(VFreebusy::CompareVFreebusyByUID); + break; + default: + break; + } + } +} + +//--------------------------------------------------------------------- + +void +NSCalendar::sortComponentsByDTStartHelper(JulianPtrArray * components, + ICalComponent::ICAL_COMPONENT type) +{ + if (components != 0) + { + switch (type) + { + // only sort VEvent, VTodo, VJournal, VFreebusy + case ICalComponent::ICAL_COMPONENT_VEVENT: + case ICalComponent::ICAL_COMPONENT_VTODO: + case ICalComponent::ICAL_COMPONENT_VJOURNAL: + components->QuickSort(TimeBasedEvent::CompareTimeBasedEventsByDTStart); + break; + case ICalComponent::ICAL_COMPONENT_VFREEBUSY: + components->QuickSort(VFreebusy::CompareVFreebusyByDTStart); + break; + default: + break; + } + } +} + +//--------------------------------------------------------------------- + +void +NSCalendar::getUniqueUIDsHelper(JulianPtrArray * retUID, + JulianPtrArray * components, + ICalComponent::ICAL_COMPONENT type) +{ + PR_ASSERT(retUID != 0); + if (components != 0) + { + t_int32 i; + UnicodeString u; + ICalComponent * ic; + sortComponentsByUIDHelper(components, type); + for (i = 0; i < components->GetSize(); i++) + { + ic = (ICalComponent *) components->GetAt(i); + if (i == 0) + { + u = ic->getUID(); + retUID->Add(new UnicodeString(u)); + } + else if (ic->getUID() != u) + { + u = ic->getUID(); + retUID->Add(new UnicodeString(u)); + } + } + } +} + +//--------------------------------------------------------------------- +#if 0 +void +NSCalendar::getComponentsWithType(JulianPtrArray * out, + UnicodeString & uid, + ICalComponent::ICAL_COMPONENT type) +{ + switch (type) + { + case ICalComponent::ICAL_COMPONENT_VEVENT: + getComponents(out, getEvents(), uid); + break; + case ICalComponent::ICAL_COMPONENT_VTODO: + getComponents(out, getTodos(), uid); + break; + case ICalComponent::ICAL_COMPONENT_VJOURNAL: + getComponents(out, getJournals(), uid); + break; + // TODO: add VFreebusy + default: + break; + } +} +#endif +//--------------------------------------------------------------------- + +void +NSCalendar::getTBEWithTypeByComponentID(JulianPtrArray * out, + UnicodeString & uid, + UnicodeString & sRecurrenceID, + UnicodeString & sModifier, + ICalComponent::ICAL_COMPONENT type) +{ + switch (type) + { + case ICalComponent::ICAL_COMPONENT_VEVENT: + getTBEByComponentID(out, getEvents(), uid, sRecurrenceID, sModifier); + break; + case ICalComponent::ICAL_COMPONENT_VTODO: + getTBEByComponentID(out, getTodos(), uid, sRecurrenceID, sModifier); + break; + case ICalComponent::ICAL_COMPONENT_VJOURNAL: + getTBEByComponentID(out, getJournals(), uid, sRecurrenceID, sModifier); + break; + default: + break; + } +} + +//--------------------------------------------------------------------- + +void +NSCalendar::getTBEByComponentID(JulianPtrArray * out, + JulianPtrArray * components, + UnicodeString & sUID, + UnicodeString & sRecurrenceID, + UnicodeString & sModifier) +{ + PR_ASSERT(out != 0); + if (components != 0) + { + t_int32 i; + UnicodeString uid; + TimeBasedEvent * ic; + + // NOTE: if sRecurrence is invalid (i.e. 19691231T235959Z) + // then just call getComponents + DateTime d; + d.setTimeString(sRecurrenceID); + if (!d.isValid()) + { + getComponents(out, components, sUID); + } + else + { + PR_ASSERT(d.isValid()); + JulianRecurrenceID::RANGE aRange = JulianRecurrenceID::RANGE_NONE; + aRange = JulianRecurrenceID::stringToRange(sModifier); + DateTime icrid; + + for (i = 0; i < components->GetSize(); i++) + { + ic = (TimeBasedEvent *) components->GetAt(i); + + uid = ic->getUID(); + icrid = ic->getRecurrenceID(); + if (uid == sUID) + { + if (icrid.isValid()) + { + if (icrid == d) + { + // always add exact match + out->Add(ic); + } + else if (aRange == JulianRecurrenceID::RANGE_THISANDPRIOR && + icrid.beforeDateTime(d)) + { + // also add if THISANDPRIOR and icrid < d + out->Add(ic); + } + else if (aRange == JulianRecurrenceID::RANGE_THISANDFUTURE && + icrid.afterDateTime(d)) + { + // also add if THISANDFUTURE and icrid > d + out->Add(ic); + } + } + } + } + } + } +} + +//--------------------------------------------------------------------- + +void +NSCalendar::getComponents(JulianPtrArray * out, + JulianPtrArray * components, + UnicodeString & sUID) +{ + PR_ASSERT(out != 0); + if (components != 0) + { + t_int32 i; + UnicodeString uid; + ICalComponent * ic; + for (i = 0; i < components->GetSize(); i++) + { + ic = (ICalComponent *) components->GetAt(i); + uid = ic->getUID(); + if (uid == sUID) + { + out->Add(components->GetAt(i)); + } + //if (FALSE) TRACE("uid, sUID = (%s,%s)\r\n", uid.toCString(""), sUID.toCString("")); + } + } +} + +//--------------------------------------------------------------------- + +NSCalendar::METHOD +NSCalendar::stringToMethod(UnicodeString & method) +{ + t_int32 hashCode = method.hashCode(); + + if (JulianKeyword::Instance()->ms_ATOM_PUBLISH == hashCode) return METHOD_PUBLISH; + else if (JulianKeyword::Instance()->ms_ATOM_REQUEST == hashCode) return METHOD_REQUEST; + else if (JulianKeyword::Instance()->ms_ATOM_REPLY == hashCode) return METHOD_REPLY; + else if (JulianKeyword::Instance()->ms_ATOM_CANCEL == hashCode) return METHOD_CANCEL; + else if (JulianKeyword::Instance()->ms_ATOM_REFRESH == hashCode) return METHOD_REFRESH; + else if (JulianKeyword::Instance()->ms_ATOM_COUNTER == hashCode) return METHOD_COUNTER; + else if (JulianKeyword::Instance()->ms_ATOM_DECLINECOUNTER == hashCode) return METHOD_DECLINECOUNTER; + else if (JulianKeyword::Instance()->ms_ATOM_ADD == hashCode) return METHOD_ADD; + else return METHOD_INVALID; +} + +//--------------------------------------------------------------------- +#if 0 +t_bool +NSCalendar::AreStringVectorsEqual(JulianPtrArray * a, JulianPtrArray * b) +{ + // If both are null, then same + // If one is null, other is not then NOT same + // If both NOT null and different size then NOT same + // If both NOT null and same size and same contents then same + // If both NOT null and same size and different contents then NOT same + + if ((a == 0 && b != 0) || (a != 0 && b == 0)) + return FALSE; + else if (a == 0 && b == 0) + return TRUE; + else + { + // a != 0 && b != 0 + + if (a->GetSize() != b->GetSize() ) + { + return FALSE; + } + else + { + // TODO: inefficient O(n^2) + t_int32 i, j; + t_bool bIn = FALSE; + UnicodeString aus, bus; + for (i = 0; i < a->GetSize(); i++) + { + aus = *((UnicodeString *) a->GetAt(i)); + bIn = FALSE; + + // check for aus in b + for (j = 0; j < b->GetSize(); j++) + { + bus = *((UnicodeString *) b->GetAt(i)); + if (aus.compareIgnoreCase(bus) == 0) + { + bIn = TRUE; + break; + } + } + + if (!bIn) + return FALSE; + } + } + } +} +#endif +//--------------------------------------------------------------------- + +UnicodeString & NSCalendar::methodToString(NSCalendar::METHOD method, UnicodeString & out) +{ + switch(method) + { + case METHOD_PUBLISH: out = JulianKeyword::Instance()->ms_sPUBLISH; break; + case METHOD_REQUEST: out = JulianKeyword::Instance()->ms_sREQUEST; break; + case METHOD_REPLY: out = JulianKeyword::Instance()->ms_sREPLY; break; + case METHOD_CANCEL: out = JulianKeyword::Instance()->ms_sCANCEL; break; + case METHOD_REFRESH: out = JulianKeyword::Instance()->ms_sREFRESH; break; + case METHOD_COUNTER: out = JulianKeyword::Instance()->ms_sCOUNTER; break; + case METHOD_DECLINECOUNTER: out = JulianKeyword::Instance()->ms_sDECLINECOUNTER; break; + case METHOD_ADD: out = JulianKeyword::Instance()->ms_sADD; break; + default: + // TODO: Log and error?? + out = ""; + break; + } + return out; +} + +//--------------------------------------------------------------------- +// CalScale +void NSCalendar::setCalScale(UnicodeString s, JulianPtrArray * parameters) +{ +#if 1 + //UnicodeString * s_ptr = new UnicodeString(s); + //PR_ASSERT(s_ptr != 0); + + if (m_CalScale == 0) + m_CalScale = ICalPropertyFactory::Make(ICalProperty::TEXT, + (void *) &s, parameters); + else + { + m_CalScale->setValue((void *) &s); + m_CalScale->setParameters(parameters); + } +#else + ICalComponent::setStringValue(((ICalProperty **) &m_CalScale), s, parameters); +#endif +} +UnicodeString NSCalendar::getCalScale() const +{ +#if 1 + UnicodeString u; + if (m_CalScale == 0) + return ""; + else { + u = *((UnicodeString *) m_CalScale->getValue()); + return u; + } +#else + UnicodeString us; + ICalComponent::getStringValue(((ICalProperty **) &m_CalScale), us); + return us; +#endif +} +//--------------------------------------------------------------------- +#if 0 +// Source +void NSCalendar::setSource(UnicodeString s, JulianPtrArray * parameters) +{ +#if 0 + //UnicodeString * s_ptr = new UnicodeString(s); + //PR_ASSERT(s_ptr != 0); + + if (m_Source == 0) + m_Source = ICalPropertyFactory::Make(ICalProperty::TEXT, + (void *) &s, parameters); + else + { + m_Source->setValue((void *) &s); + m_Source->setParameters(parameters); + } +#else + ICalComponent::setStringValue(((ICalProperty **) &m_Source), s, parameters); +#endif +} +UnicodeString NSCalendar::getSource() const +{ +#if 0 + UnicodeString u; + if (m_Source == 0) + return ""; + else { + u = *((UnicodeString *) m_Source->getValue()); + return u; + } +#else + UnicodeString us; + ICalComponent::getStringValue(((ICalProperty **) &m_Source), us); + return us; +#endif +} +//--------------------------------------------------------------------- +// Name +void NSCalendar::setName(UnicodeString s, JulianPtrArray * parameters) +{ +#if 0 + //UnicodeString * s_ptr = new UnicodeString(s); + //PR_ASSERT(s_ptr != 0); + + if (m_Name == 0) + m_Name = ICalPropertyFactory::Make(ICalProperty::TEXT, + (void *) &s, parameters); + else + { + m_Name->setValue((void *) &s); + m_Name->setParameters(parameters); + } +#else + ICalComponent::setStringValue(((ICalProperty **) &m_Name), s, parameters); +#endif +} +UnicodeString NSCalendar::getName() const +{ +#if 0 + UnicodeString u; + if (m_Name == 0) + return ""; + else { + u = *((UnicodeString *) m_Name->getValue()); + return u; + } +#else + UnicodeString us; + ICalComponent::getStringValue(((ICalProperty **) &m_Name), us); + return us; +#endif +} +#endif /* #if 0 */ +//--------------------------------------------------------------------- +// Version +void NSCalendar::setVersion(UnicodeString s, JulianPtrArray * parameters) +{ +#if 1 + //UnicodeString * s_ptr = new UnicodeString(s); + //PR_ASSERT(s_ptr != 0); + + if (m_Version == 0) + m_Version = ICalPropertyFactory::Make(ICalProperty::TEXT, + (void *) &s, parameters); + else + { + m_Version->setValue((void *) &s); + m_Version->setParameters(parameters); + } +#else + ICalComponent::setStringValue(((ICalProperty **) &m_Version), s, parameters); +#endif +} +UnicodeString NSCalendar::getVersion() const +{ +#if 1 + UnicodeString u; + if (m_Version == 0) + return ""; + else { + u = *((UnicodeString *) m_Version->getValue()); + return u; + } +#else + UnicodeString us; + ICalComponent::getStringValue(((ICalProperty **) &m_Version), us); + return us; +#endif +} +//--------------------------------------------------------------------- +// Prodid +void NSCalendar::setProdid(UnicodeString s, JulianPtrArray * parameters) +{ +#if 1 + //UnicodeString * s_ptr = new UnicodeString(s); + //PR_ASSERT(s_ptr != 0); + + if (m_Prodid == 0) + m_Prodid = ICalPropertyFactory::Make(ICalProperty::TEXT, + (void *) &s, parameters); + else + { + m_Prodid->setValue((void *) &s); + m_Prodid->setParameters(parameters); + } +#else + ICalComponent::setStringValue(((ICalProperty **) &m_Prodid), s, parameters); +#endif +} +UnicodeString NSCalendar::getProdid() const +{ +#if 1 + UnicodeString u; + if (m_Prodid == 0) + return ""; + else { + u = *((UnicodeString *) m_Prodid->getValue()); + return u; + } +#else + UnicodeString us; + ICalComponent::getStringValue(((ICalProperty **) &m_Prodid), us); + return us; +#endif +} +//--------------------------------------------------------------------- +// XTOKENS +void NSCalendar::addXTokens(UnicodeString s) +{ + if (m_XTokensVctr == 0) + m_XTokensVctr = new JulianPtrArray(); + PR_ASSERT(m_XTokensVctr != 0); + if (m_XTokensVctr != 0) + { + m_XTokensVctr->Add(new UnicodeString(s)); + } +} +//--------------------------------------------------------------------- + diff --git a/calendar/modules/core/ical/src/orgnzr.cpp b/calendar/modules/core/ical/src/orgnzr.cpp new file mode 100644 index 00000000000..b2a90c0d565 --- /dev/null +++ b/calendar/modules/core/ical/src/orgnzr.cpp @@ -0,0 +1,374 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +// orgnzr.cpp +// John Sun +// 4/7/98 11:28:26 AM + +#include "stdafx.h" +#include "jdefines.h" + +#include "orgnzr.h" +#include "jutility.h" +#include "keyword.h" +#include "uri.h" +//--------------------------------------------------------------------- + +const t_int32 JulianOrganizer::ms_cJulianOrganizerName = 'N'; +const t_int32 JulianOrganizer::ms_cJulianOrganizerDir = 'l'; // 'el' +const t_int32 JulianOrganizer::ms_cJulianOrganizerSentBy = 's'; +const t_int32 JulianOrganizer::ms_cJulianOrganizerCN = 'C'; +const t_int32 JulianOrganizer::ms_cJulianOrganizerLanguage = 'm'; +const t_int32 JulianOrganizer::ms_cJulianOrganizerDisplayName = 'z'; + +//--------------------------------------------------------------------- + +JulianOrganizer::JulianOrganizer(JLog * initLog) +: m_Log(initLog) +{ +} + +//--------------------------------------------------------------------- + +JulianOrganizer::JulianOrganizer(JulianOrganizer & that) +{ + m_CN = that.m_CN; + m_Language = that.m_Language; + m_SentBy = that.m_SentBy; + m_Dir = that.m_Dir; + + m_Name = that.m_Name; +} + +//--------------------------------------------------------------------- + +JulianOrganizer::~JulianOrganizer() +{ +} + +//--------------------------------------------------------------------- + +ICalProperty * +JulianOrganizer::clone(JLog * initLog) +{ + m_Log = initLog; + //PR_ASSERT(m_Log != 0); + return (ICalProperty *) new JulianOrganizer(*this); +} + +//--------------------------------------------------------------------- + +void JulianOrganizer::parse(UnicodeString & propVal, + JulianPtrArray * parameters) +{ + t_int32 i; + ICalParameter * param; + UnicodeString pName, pVal; + if (propVal.size() == 0) + { + return; + } + setName(propVal); + if (parameters != 0) + { + for (i = 0; i < parameters->GetSize(); i++) + { + param = (ICalParameter *) parameters->GetAt(i); + + setParam(param->getParameterName(pName), + param->getParameterValue(pVal)); + } + } +} + +//--------------------------------------------------------------------- + +void JulianOrganizer::setParam(UnicodeString & paramName, + UnicodeString & paramVal) +{ + ErrorCode status = ZERO_ERROR; + + //if (FALSE) TRACE("(%s, %s)\r\n", paramName.toCString(""), paramVal.toCString("")); + if (paramName.size() == 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iInvalidParameterName, + JulianKeyword::Instance()->ms_sORGANIZER, paramName, 200); + } + else + { + t_int32 hashCode = paramName.hashCode(); + + if (JulianKeyword::Instance()->ms_ATOM_CN == hashCode) + { + if (getCN().size() != 0) + { + if (m_Log) m_Log->logError(JulianLogErrorMessage::Instance()->ms_iDuplicatedParameter, + JulianKeyword::Instance()->ms_sORGANIZER, paramName, 100); + } + setCN(paramVal); + } + else if (JulianKeyword::Instance()->ms_ATOM_LANGUAGE == hashCode) + { + if (getLanguage().size() != 0) + { + if (m_Log) m_Log->logError(JulianLogErrorMessage::Instance()->ms_iDuplicatedParameter, + JulianKeyword::Instance()->ms_sORGANIZER, paramName, 100); + } + setLanguage(paramVal); + } + else if (JulianKeyword::Instance()->ms_ATOM_SENTBY == hashCode) + { + if (getSentBy().size() != 0) + { + if (m_Log) m_Log->logError(JulianLogErrorMessage::Instance()->ms_iDuplicatedParameter, + JulianKeyword::Instance()->ms_sORGANIZER, paramName, 100); + } + JulianUtility::stripDoubleQuotes(paramVal); // double quote property + setSentBy(paramVal); + } + else if (JulianKeyword::Instance()->ms_ATOM_DIR == hashCode) + { + if (getDir().size() != 0) + { + if (m_Log) m_Log->logError(JulianLogErrorMessage::Instance()->ms_iDuplicatedParameter, + JulianKeyword::Instance()->ms_sORGANIZER, paramName, 100); + } + JulianUtility::stripDoubleQuotes(paramVal); // double quote property + setDir(paramVal); + } + else if (ICalProperty::IsXToken(paramName)) + { + if (m_Log) m_Log->logError(JulianLogErrorMessage::Instance()->ms_iXTokenParamIgnored, + JulianKeyword::Instance()->ms_sORGANIZER, paramName, 100); + } + else + { + if (m_Log) m_Log->logError(JulianLogErrorMessage::Instance()->ms_iInvalidParameterName, + JulianKeyword::Instance()->ms_sORGANIZER, paramName, 200); + } + } +} + +//--------------------------------------------------------------------- + +UnicodeString & JulianOrganizer::toICALString(UnicodeString & out) +{ + UnicodeString u; + return toICALString(u, out); +} + +//--------------------------------------------------------------------- + +UnicodeString & JulianOrganizer::toICALString(UnicodeString & sProp, + UnicodeString & out) +{ + out = ""; + out += sProp; + UnicodeString u; + if (m_CN.size() > 0) + { + out += ';'; out += JulianKeyword::Instance()->ms_sCN; + out += '='; out += m_CN; + } + if (m_Language.size() > 0) + { + out += ';'; out += JulianKeyword::Instance()->ms_sLANGUAGE; + out += '='; out += m_Language; + } + if (m_SentBy.size() > 0) + { + // double quote sent-by, dir + u = m_SentBy; + u = JulianUtility::addDoubleQuotes(u); + out += ';'; out += JulianKeyword::Instance()->ms_sSENTBY; + out += '='; out += u; + } + if (m_Dir.size() > 0) + { + // double quote sent-by, dir + u = m_Dir; + u = JulianUtility::addDoubleQuotes(u); + out += ';'; out += JulianKeyword::Instance()->ms_sDIR; + out += '='; out += u; + } + out += ':'; + out += m_Name; + out += JulianKeyword::Instance()->ms_sLINEBREAK; + return out; +} + +//--------------------------------------------------------------------- + +UnicodeString & JulianOrganizer::toString(UnicodeString & out) +{ + out = toString(JulianFormatString::Instance()->ms_OrganizerStrDefaultFmt, out); + return out; +} + +//--------------------------------------------------------------------- + +UnicodeString & JulianOrganizer::toString(UnicodeString & strFmt, + UnicodeString & out) +{ + if (strFmt.size() == 0 && + JulianFormatString::Instance()->ms_OrganizerStrDefaultFmt.size() > 0) + { + // if empty string, use default + return toString(out); + } + + UnicodeString into; + t_int32 i,j; + //if (FALSE) TRACE("strFmt = %s\r\n", strFmt.toCString("")); + out = ""; + for ( i = 0; i < strFmt.size(); ) + { + + // NOTE: changed from % to ^ for attendee + /// + /// If there's a special formatting character, + /// handle it. Otherwise, just emit the supplied + /// character. + /// + + j = strFmt.indexOf('^', i); + if ( -1 != j) + { + if (j > i) + { + out += strFmt.extractBetween(i,j,into); + } + i = j + 1; + if ( strFmt.size() > i) + { + out += toStringChar(strFmt[(TextOffset) i]); + i++; + } + } + else + { + out += strFmt.extractBetween(i, strFmt.size(),into); + break; + } + } + return out; +} + +//--------------------------------------------------------------------- + +UnicodeString JulianOrganizer::toStringChar(t_int32 c) +{ + switch(c) + { + case ms_cJulianOrganizerName: + return getName(); + case ms_cJulianOrganizerDir: + return m_Dir; + case ms_cJulianOrganizerSentBy: + return m_SentBy; + case ms_cJulianOrganizerCN: + return m_CN; + case ms_cJulianOrganizerLanguage: + return m_Language; + case ms_cJulianOrganizerDisplayName: + // return CN is CN != "", else + // return the JulianOrganizerName after the ':' + if (m_CN.size() > 0) + return m_CN; + else + { + UnicodeString u; + t_int32 i = m_Name.indexOf(':'); + if (i >= 0) + { + u = getName().extractBetween(i + 1, getName().size(), u); + return u; + } + else + return ""; + } + default: + return ""; + } +} + +//--------------------------------------------------------------------- + +t_bool JulianOrganizer::isValid() +{ + /* + UnicodeString mailto; + if (getName().size() < 7) + return FALSE; + // change to URL, must have "MAILTO:" in front + mailto = getName().extractBetween(0, 7, mailto); + if (mailto.compareIgnoreCase(JulianKeyword::Instance()->ms_sMAILTO_COLON) != 0) + return FALSE; + else + return TRUE; + */ + return URI::IsValidURI(m_Name); +} + +//--------------------------------------------------------------------- + +void * +JulianOrganizer::getValue() const +{ + return (void *) &m_Name; +} + +//--------------------------------------------------------------------- + +void +JulianOrganizer::setValue(void * value) +{ + PR_ASSERT(value != 0); + if (value != 0) + { + m_Name = *((UnicodeString *) value); + } +} + +//--------------------------------------------------------------------- + +void JulianOrganizer::setParameters(JulianPtrArray * parameters) +{ + t_int32 i; + ICalParameter * param; + UnicodeString pName, pVal; + if (parameters != 0) + { + for (i = 0; i < parameters->GetSize(); i++) + { + param = (ICalParameter *) parameters->GetAt(i); + setParam(param->getParameterName(pName), + param->getParameterValue(pVal)); + } + } +} + +//--------------------------------------------------------------------- + +void JulianOrganizer::setName(UnicodeString sName) +{ + m_Name = sName; +} + +//--------------------------------------------------------------------- diff --git a/calendar/modules/core/ical/src/period.cpp b/calendar/modules/core/ical/src/period.cpp new file mode 100644 index 00000000000..e19f0b08393 --- /dev/null +++ b/calendar/modules/core/ical/src/period.cpp @@ -0,0 +1,620 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +// period.cpp +// John Sun +// 11:37 AM January 29 1998 + +#include "stdafx.h" +#include "jdefines.h" + +#include +#include +#include +#include "datetime.h" +#include "duration.h" + +#include "period.h" + +//static UnicodeString s_sP = "P"; +//static UnicodeString s_sDash = " - "; +//static UnicodeString s_sForwardSlash = "/"; +//static UnicodeString s_sInvalidPeriod = "Invalid Period"; +//static UnicodeString s_sICALInvalidPeriod = "19691231T235959Z/PT-1H"; +//--------------------------------------------------------------------- +////////////////////////////// +// PRIVATE METHODS +////////////////////////////// +//--------------------------------------------------------------------- + +void Period::parse(UnicodeString & us) +{ + //UnicodeString s = us; + UnicodeString sStart, sEnd; + t_int32 indexOfSlash = us.indexOf('/'); + //DateTime start, end; + //Julian_Duration d; + + if (indexOfSlash < 0) + { + // LOG and create invalid period + createInvalidPeriod(); + } + else + { + sStart = us.extractBetween(0, indexOfSlash, sStart); + sEnd = us.extractBetween(indexOfSlash + 1, us.size(), sEnd); + + m_DTStart.setTimeString(sStart); //PR_ASSERT(m_DTStart != 0); + + m_DTEnd.setTimeString(sEnd); + if (!m_DTEnd.isValid()) + { + m_Duration.setDurationString(sEnd); + } + +#if 0 + if (sEnd[(TextOffset) 0] == 'P') //sEnd.startsWith(s_sP)) + { + m_Duration.setDurationString(sEnd); //PR_ASSERT(m_Duration != 0); + } + else + { + m_DTEnd.setTimeString(sEnd); //PR_ASSERT(m_DTEnd != 0); + } +#endif + + } +} +//--------------------------------------------------------------------- + +void Period::selfCheck() +{ + if (!isValid()) + createInvalidPeriod(); +} + +//--------------------------------------------------------------------- + +void Period::createInvalidPeriod() +{ + m_DTStart.setTime(-1); + m_DTEnd.setTime(-1); + m_Duration.set(-1, -1, -1, -1, -1, -1); +} + +//--------------------------------------------------------------------- + +DateTime & Period::getEndingTime(DateTime & d) +{ + PR_ASSERT(isValid()); + if (isValid()) + { + if (getEnd().isValid()) + { + d = m_DTEnd; + return d; + } + else + { + d = m_DTStart; + d.add(m_Duration); + return d; + } + } + else + { + // NOT valid period returns -1 + d.setTime(-1); + return d; + } +} + +//--------------------------------------------------------------------- +////////////////////////////// +// CONSTRUCTORS +////////////////////////////// +//--------------------------------------------------------------------- + +Period::Period() +: + m_DTStart(-1), + m_DTEnd(-1), + m_Duration(-1, -1, -1, -1, -1, -1, -1) + //m_DTStart(0), + //m_DTEnd(0), + //m_Duration(0) +{} + +//--------------------------------------------------------------------- + +Period::Period(Period & that) +{ + + m_DTStart.setTime(that.getStart().getTime()); + m_DTEnd.setTime(that.getEnd().getTime()); + + m_Duration = that.m_Duration; +} + +//--------------------------------------------------------------------- + +Period::Period(UnicodeString & us) +: + m_DTStart(-1), + m_DTEnd(-1), + m_Duration(-1, -1, -1, -1, -1, -1, -1) +{ + parse(us); + selfCheck(); +} + +//--------------------------------------------------------------------- + +////////////////////////////// +// DESTRUCTORS +////////////////////////////// +//--------------------------------------------------------------------- + +Period::~Period() +{ + //if (m_DTStart != 0) { delete m_DTStart; m_DTStart = 0; } + //if (m_DTEnd != 0) { delete m_DTEnd; m_DTEnd = 0; } + //if (m_Duration != 0) { delete m_Duration; m_Duration = 0; } +} + +//--------------------------------------------------------------------- + +////////////////////////////// +// GETTERS and SETTERS +////////////////////////////// +//--------------------------------------------------------------------- + +void Period::setStart(DateTime d) +{ + m_DTStart = d; +} + +//--------------------------------------------------------------------- + +void Period::setEnd(DateTime d) +{ + m_DTEnd = d; +} + +//--------------------------------------------------------------------- + +void Period::setDuration(Julian_Duration d) +{ + m_Duration = d; +} + +//--------------------------------------------------------------------- + +void Period::setPeriodString(UnicodeString & us) +{ + parse(us); +} + +//--------------------------------------------------------------------- + +////////////////////////////// +// UTILITIES +////////////////////////////// + +//--------------------------------------------------------------------- + +t_bool Period::isValid() +{ + //Date d; + + if (!getStart().isValid()) + { + return FALSE; + } + else if (getEnd().isValid()) + { + if (getEnd() < getStart()) + return FALSE; + // assert duration is invalid + PR_ASSERT(!getDuration().isValid()); + return TRUE; + } + else { + if (getDuration().isValid()) + { + if (getDuration().isNegativeDuration()) + return FALSE; + else + return TRUE; + } + return FALSE; + } +} +//--------------------------------------------------------------------- + +t_bool Period::isIntersecting(DateTime & start, DateTime & end) +{ + DateTime pEnd; + + PR_ASSERT(!start.afterDateTime(end)); + PR_ASSERT(isValid()); + // Bad input always returns FALSE + if (start.afterDateTime(end) || !isValid()) + { + return FALSE; + } + + + if (!getStart().beforeDateTime(end)) + return FALSE; + + pEnd = getEndingTime(pEnd); + + if (!pEnd.afterDateTime(start)) + return FALSE; + + return TRUE; +} + +//--------------------------------------------------------------------- + +t_bool Period::isIntersecting(Period & period) +{ + DateTime dS, dE; + dE = period.getEndingTime(dE); + dS = period.getStart(); + return isIntersecting(dS, dE); +} + +//--------------------------------------------------------------------- + +t_bool Period::isInside(DateTime & start, DateTime & end) +{ + DateTime pEnd; + + PR_ASSERT(!start.afterDateTime(end)); + PR_ASSERT(isValid()); + // handle bad input (ALWAYS returns FALSE) + if (start.afterDateTime(end) || !isValid()) + { + return FALSE; + } + pEnd = getEndingTime(pEnd); + if ((!getStart().beforeDateTime(start)) && + (!pEnd.afterDateTime(end))) + return TRUE; + return FALSE; +} + +//--------------------------------------------------------------------- + +t_bool Period::isInside(Period & period) +{ + DateTime dS, dE; + dE = period.getEndingTime(dE); + dS = period.getStart(); + return isInside(dS, dE); +} + +//--------------------------------------------------------------------- + +UnicodeString Period::toString() +{ + if (!isValid()) + { + return "Invalid Period"; + } + else + { + UnicodeString u; + u = getStart().toString(); + u += "-"; + if (getEnd().isValid()) + { + u += getEnd().toString(); + } + else + { + u += getDuration().toString(); + } + return u; + } +} + +//--------------------------------------------------------------------- + +UnicodeString Period::toICALString() +{ + if (!isValid()) + { + return "19691231T235959Z/INVALID_DURATION"; + } + else + { + UnicodeString sOut = getStart().toISO8601(); + sOut += '/'; + if (getEnd().isValid()) + sOut += getEnd().toISO8601(); + else + sOut += getDuration().toICALString(); + return sOut; + } + +} + +//--------------------------------------------------------------------- + +////////////////////////////// +// STATIC METHODS +////////////////////////////// +//--------------------------------------------------------------------- + +t_bool Period::IsConnectedPeriods(Period & p1, Period & p2) +{ + DateTime p1end; + DateTime p2end; + + if (p1.isIntersecting(p2)) + return TRUE; + + // check for back-to-back periods + p1end = p1.getEndingTime(p1end); + p2end = p2.getEndingTime(p2end); + + if (p1.getStart().equalsDateTime(p2end) || + p2.getStart().equalsDateTime(p1end)) + return TRUE; + + return FALSE; +} + +//--------------------------------------------------------------------- + +void Period::Union(Period & inPer1, Period & inPer2, Period & outPer) +{ + DateTime s1, s2; + DateTime p1end; + DateTime p2end; + + PR_ASSERT(inPer1.isValid() && inPer2.isValid()); + // handle bad input (return invalid period) + if (!inPer1.isValid() || !inPer2.isValid()) + { + DateTime d; + d.setTime(-1); + outPer.setStart(d); + outPer.setEnd(d); + return; + } + + if (!IsConnectedPeriods(inPer1, inPer2)) + { + // return an invalid period + outPer.createInvalidPeriod(); + } + else + { + s1 = inPer1.getStart(); + s2 = inPer2.getStart(); + if (s1.beforeDateTime(s2)) + outPer.setStart(s1); + else + outPer.setStart(s2); + + p1end = inPer1.getEndingTime(p1end); + p2end = inPer2.getEndingTime(p2end); + + if (p1end.afterDateTime(p2end)) + outPer.setEnd(p1end); + else + outPer.setEnd(p2end); + } +} + +//--------------------------------------------------------------------- + +void Period::Intersection(Period & inPer, DateTime & start, + DateTime & end, Period & outPer) +{ + DateTime pend; + DateTime pstart; + + PR_ASSERT(inPer.isValid()); + PR_ASSERT(!start.afterDateTime(end)); + // handle bad input (return invalid period) + if (!inPer.isValid() || start.afterDateTime(end)) + { + pstart.setTime(-1); + outPer.setStart(pstart); + outPer.setEnd(pstart); + } + + + if (!inPer.isIntersecting(start, end)) + { + outPer.createInvalidPeriod(); + } + else + { + pstart = inPer.getStart(); + + if (start.afterDateTime(pstart)) + outPer.setStart(start); + else + outPer.setStart(pstart); + + pend = inPer.getEndingTime(pend); + + if (end.beforeDateTime(pend)) + outPer.setEnd(end); + else + outPer.setEnd(pend); + } +} +//--------------------------------------------------------------------- + +void Period::SubtractedPeriod(Period & inPer, DateTime & start, + DateTime & end, JulianPtrArray * out) +{ + Period * pNew = 0; + DateTime pend, pstart; + + PR_ASSERT(!start.afterDateTime(end)); + // handle bad input (add nothing to vector) + if (start.afterDateTime(end)) + { + return; + } + + pstart = inPer.getStart(); + pend = inPer.getEndingTime(pend); + + Period pInt; + Period::Intersection(inPer, start, end, pInt); + if (!pInt.isValid()) + { + // return whole period since no intersection + pNew = new Period(); PR_ASSERT(pNew != 0); + pNew->setStart(pstart); + pNew->setEnd(pend); + out->Add(pNew); + return; + } + + if (pstart.beforeDateTime(start)) + { + pNew = new Period(); PR_ASSERT(pNew != 0); + pNew->setStart(pstart); + pNew->setEnd(start); + out->Add(pNew); + } + + if (pend.afterDateTime(end)) + { + pNew = new Period(); PR_ASSERT(pNew != 0); + pNew->setStart(end); + pNew->setEnd(pend); + out->Add(pNew); + } +} + +//--------------------------------------------------------------------- + +t_bool Period::IsParseable(UnicodeString & s) +{ + UnicodeString sStart, sEnd; + t_int32 indexOfSlash = s.indexOf('/', 0); + + if (indexOfSlash < 0) + return FALSE; + else + { + sStart = s.extractBetween(0, indexOfSlash, sStart); + sEnd = s.extractBetween(indexOfSlash + 1, s.size(), sEnd); + + if (!DateTime::IsParseable(sStart)) + return FALSE; + if (!DateTime::IsParseable(sEnd)) + { + Julian_Duration d(sEnd); //PR_ASSERT(d != 0); + if (!d.isValid()) + return FALSE; + //delete d; d = 0; // nullify after delete + } + } + return TRUE; +} + +//--------------------------------------------------------------------- + +UnicodeString & +Period::getTimeString(UnicodeString & sPeriod, t_bool bStart, + UnicodeString & out) +{ + PR_ASSERT(IsParseable(sPeriod)); + if (!IsParseable(sPeriod)) + { + out = "19691231T235959Z/INVALID_DURATION"; + return out; + } + t_int32 index = sPeriod.indexOf('/'); + PR_ASSERT(index != -1); + if (index == -1) + { + out = "19691231T235959Z/INVALID_DURATION"; + return out; + } + + if (bStart) + { + return sPeriod.extractBetween(0, index, out); + } + else + return sPeriod.extractBetween(index + 1, sPeriod.size(), out); +} +//--------------------------------------------------------------------- + +UnicodeString & +Period::getStartTimeString(UnicodeString & sPeriod, UnicodeString & out) +{ + return getTimeString(sPeriod, TRUE, out); +} + +//--------------------------------------------------------------------- + +UnicodeString & +Period::getEndTimeString(UnicodeString & sPeriod, UnicodeString & out) +{ + return getTimeString(sPeriod, FALSE, out); +} + +//--------------------------------------------------------------------- + +int Period::ComparePeriods(const void * a, const void * b) +{ + DateTime startA, startB; + PR_ASSERT(a != 0 && b != 0); + + Period * dtA = *(Period **) a; + Period * dtB = *(Period **) b; + + startA = dtA->getStart(); + startB = dtB->getStart(); + return (int) startA.compareTo(startB); + //return (int) (DateTime::CompareDateTimes(&startA, &startB)); +} + +//--------------------------------------------------------------------- + +int Period::ComparePeriodsByEndTime(const void * a, const void * b) +{ + DateTime endA, endB; + PR_ASSERT(a != 0 && b != 0); + + Period * dtA = *(Period **) a; + Period * dtB = *(Period **) b; + + endA = dtA->getEndingTime(endA); + endB = dtB->getEndingTime(endB); + return (int) endA.compareTo(endB); + //return (int) (DateTime::CompareDateTimes(&startA, &startB)); +} + +//--------------------------------------------------------------------- + diff --git a/calendar/modules/core/ical/src/pprprty.cpp b/calendar/modules/core/ical/src/pprprty.cpp new file mode 100644 index 00000000000..f3afc835950 --- /dev/null +++ b/calendar/modules/core/ical/src/pprprty.cpp @@ -0,0 +1,154 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +// pprprty.cpp +// John Sun +// 3:15 PM February 12 1998 + +#include "stdafx.h" +#include "jdefines.h" + +#include "pprprty.h" +#include "period.h" +#include "prprty.h" + +//--------------------------------------------------------------------- + +// private never use +PeriodProperty::PeriodProperty() +{ + PR_ASSERT(FALSE); +} + +//--------------------------------------------------------------------- + +PeriodProperty::PeriodProperty(const PeriodProperty & that) +{ + setParameters(that.m_vParameters); + m_Period = that.m_Period; +} + +//--------------------------------------------------------------------- + +PeriodProperty::PeriodProperty(Period * value, JulianPtrArray * parameters) +: StandardProperty(parameters) +{ + PR_ASSERT(value != 0); + //m_string = *((UnicodeString *) value); + if (value != 0) + { + m_Period = value; + } +} +//--------------------------------------------------------------------- + +PeriodProperty::~PeriodProperty() +{ + delete m_Period; m_Period = 0; + //deleteICalParameterVector(m_vParameters); + //delete m_vParameters; m_vParameters = 0; +} + +//--------------------------------------------------------------------- + +void * PeriodProperty::getValue() const +{ + return (void *) m_Period; +} + +//--------------------------------------------------------------------- + +void PeriodProperty::setValue(void * value) +{ + PR_ASSERT(value != 0); + // NOTE: deleting old period + if (value != 0) + { + if (m_Period != 0) { delete m_Period; m_Period = 0; } + m_Period = ((Period *) value); + } +} + +//--------------------------------------------------------------------- + +ICalProperty * PeriodProperty::clone(JLog * initLog) +{ + if (initLog) {} // NOTE: Remove later to avoid warnings + return new PeriodProperty(*this); +} + +//--------------------------------------------------------------------- + +t_bool PeriodProperty::isValid() +{ + if (m_Period == 0) + return FALSE; + return m_Period->isValid(); +} + +//--------------------------------------------------------------------- + +UnicodeString & PeriodProperty::toString(UnicodeString & out) +{ + + PR_ASSERT(m_Period != 0); + + if (m_Period != 0) + { + //if (m_Period->isValid() + out = m_Period->toString(); + //else + // out = "NULL"; + } + else + { + // Bad period return "". + out = ""; + } + return out; +} + +//--------------------------------------------------------------------- + +UnicodeString & +PeriodProperty::toString(UnicodeString & dateFmt, UnicodeString & out) +{ + // NOTE: remove it later, gets rid of compiler warning + if (dateFmt.size() > 0) {} + return toString(out); +} + +//--------------------------------------------------------------------- + +UnicodeString & PeriodProperty::toExportString(UnicodeString & out) +{ + PR_ASSERT(m_Period != 0); + if (m_Period != 0) + { + out = m_Period->toICALString(); + } + else + { + // Bad period return "". + out = ""; + } + return out; +} +//--------------------------------------------------------------------- + + diff --git a/calendar/modules/core/ical/src/prprty.cpp b/calendar/modules/core/ical/src/prprty.cpp new file mode 100644 index 00000000000..59134dfe2aa --- /dev/null +++ b/calendar/modules/core/ical/src/prprty.cpp @@ -0,0 +1,763 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +// prprty.cpp +// John Sun +// 4:11 PM February 10 1998 + +#include "stdafx.h" +#include "jdefines.h" + +#include +#include +#include "unistrto.h" +#include "prprty.h" +#include "ptrarray.h" +#include "icalprm.h" +#include "period.h" +#include "jutility.h" +#include "keyword.h" + +//--------------------------------------------------------------------- + +ICalProperty::ICalProperty() {} +ICalProperty::ICalProperty(ICalProperty & that) { if (&that != 0) {} } + +//--------------------------------------------------------------------- + +UnicodeString & +ICalProperty::propertyToICALString(UnicodeString & sProp, + UnicodeString & sVal, + JulianPtrArray * parameters, + UnicodeString & retVal) +{ + ICalParameter * aName; + retVal = ""; + t_int32 size = 0; + t_int32 i; + + + if (parameters != 0) + size = parameters->GetSize(); + if (sVal.size() > 0) + { + UnicodeString u; + retVal = sProp; + for (i = 0; i < size; i++) + { + aName = (ICalParameter *) parameters->GetAt(i); + retVal += aName->toICALString(u); + } + retVal += ':'; retVal += sVal; retVal += JulianKeyword::Instance()->ms_sLINEBREAK; + } + //if (FALSE) TRACE("retVal = %s\r\n", retVal.toCString("")); + return retVal; +} + +//--------------------------------------------------------------------- +// TRUE = in range, FALSE = out of range. +t_bool ICalProperty::CheckParams(JulianPtrArray * parameters, + JAtom validParamNameRange[], + t_int32 validParamNameRangeSize) +{ + if (parameters == 0 || parameters->GetSize() == 0) + return TRUE; + + // more parameters that range + if (parameters->GetSize() > validParamNameRangeSize) + return FALSE; + + UnicodeString u; + t_int32 i; + ICalParameter * ip; + + for (i = 0; i < parameters->GetSize(); i++) + { + ip = (ICalParameter *) parameters->GetAt(i); + u = ip->getParameterName(u); + + if (!JulianUtility::checkRange(u.hashCode(), validParamNameRange, + validParamNameRangeSize)) + { + return FALSE; + } + } + return TRUE; +} +//--------------------------------------------------------------------- +// TRUE = in range, FALSE = out of range. +t_bool ICalProperty::CheckParamsWithValueRangeCheck(JulianPtrArray * parameters, + JAtom validParamNameRange[], + t_int32 validParamNameRangeSize, + JAtom validValueRange[], + t_int32 validValueRangeSize) +{ + + + // no parameters + if (parameters == 0 || parameters->GetSize() == 0) + return TRUE; + + // more parameters that range + if (parameters->GetSize() > validParamNameRangeSize) + return FALSE; + + UnicodeString u; + ICalParameter * ip; + t_int32 i; + + for (i = 0; i < parameters->GetSize(); i++) + { + ip = (ICalParameter *) parameters->GetAt(i); + u = ip->getParameterName(u); + + if (!JulianUtility::checkRange(u.hashCode(), validParamNameRange, + validParamNameRangeSize)) + { + return FALSE; + } + + if (JulianKeyword::Instance()->ms_ATOM_VALUE == u.hashCode()) + { + u = ip->getParameterValue(u); + if (!JulianUtility::checkRange(u.hashCode(), validValueRange, + validValueRangeSize)) + { + if (!ICalProperty::IsXToken(u)) + return FALSE; + } + } + + else if (JulianKeyword::Instance()->ms_ATOM_ENCODING == u.hashCode()) + { + u = ip->getParameterValue(u); + if (!JulianUtility::checkRange(u.hashCode(), + JulianAtomRange::Instance()->ms_asEncodingRange, + JulianAtomRange::Instance()->ms_iEncodingRangeSize)) + { + if (!ICalProperty::IsXToken(u)) + return FALSE; + } + } + + else if (JulianKeyword::Instance()->ms_ATOM_RELTYPE == u.hashCode()) + { + u = ip->getParameterValue(u); + if (!JulianUtility::checkRange(u.hashCode(), + JulianAtomRange::Instance()->ms_asRelTypeRange, + JulianAtomRange::Instance()->ms_iRelTypeRangeSize)) + { + if (!ICalProperty::IsXToken(u)) + return FALSE; + } + } + + else if (JulianKeyword::Instance()->ms_ATOM_RELATED == u.hashCode()) + { + u = ip->getParameterValue(u); + if (!JulianUtility::checkRange(u.hashCode(), + JulianAtomRange::Instance()->ms_asRelatedRange, + JulianAtomRange::Instance()->ms_iRelatedRangeSize)) + { + return FALSE; + } + } + } + return TRUE; +} + +//--------------------------------------------------------------------- +#if 0 +// return TRUE if error, FALSE otherwise +t_bool ICalProperty::checkParam(UnicodeString & propName, + UnicodeString & paramName, + UnicodeString & paramVal) +{ + t_int32 hashCode = propName.hashCode(); + + if (JulianUtility::checkRange(hashCode, + JulianAtomRange::Instance()->ms_asIrregularProperties, + JulianAtomRange::Instance()->ms_iIrregularPropertiesSize)) + { + // if special property, then don't check parameters + return FALSE; + } + else + { + t_int32 pNHC = paramName.hashCode(); + + // X-TOKEN, no error + if (IsXToken(paramName)) + return FALSE; + + // not a valid parameter for th + if (!JulianUtility::checkRange(pNHC, + JulianAtomRange::Instance()->ms_asParameterRange, + JulianAtomRange::Instance()->ms_iParameterRangeSize)) + return TRUE; + + else + { + t_int32 pVHC = paramVal.hashCode(); + // check parameter name ranges here + // TODO: For now check only VALUE, ENCODING, + // TODO: Check LANGUAGE later + if (JulianKeyword::Instance()->ms_ATOM_VALUE == pNHC) + { + if ((!JulianUtility::checkRange(pVHC, + JulianAtomRange::Instance()->ms_asValueRange, + JulianAtomRange::Instance()->ms_iValueRangeSize)) + && (!IsXToken(paramVal))) + return TRUE; + } + else if (JulianKeyword::Instance()->ms_ATOM_ENCODING == pNHC) + { + if ((!JulianUtility::checkRange(pVHC, + JulianAtomRange::Instance()->ms_asEncodingRange, + JulianAtomRange::Instance()->ms_iEncodingRangeSize)) && (!IsXToken(paramVal))) + return TRUE; + } + return FALSE; + } + } +} +#endif +//--------------------------------------------------------------------- +// checks for parameters here. +// If method encounters a bad parameter, +// then method won't add it to the parameters vector, +// and set parseError to TRUE + +void ICalProperty::parsePropertyLine(UnicodeString & strLine, + UnicodeString & outName, + UnicodeString & outVal, + JulianPtrArray * parameters) +{ + ErrorCode status = ZERO_ERROR; + + t_int32 lineLength = strLine.size(); + // NOTE: won't work with backslashed :, ;. Spec doesn't + // mention any special handling for backslashed :, ;. + t_int32 iColon = strLine.indexOf(':'); + t_int32 iSColon = strLine.indexOf(';'); + t_int32 iDQuote = strLine.indexOf('\"'); + t_int32 i, iEDQuote; + + //if (FALSE) TRACE("strLine = %s\r\n", strLine.toCString("")); + + // Ignore colons, semicolons inside double quotes + while (iDQuote >= 0 && iColon > iDQuote) + { + // get second quote + iEDQuote = strLine.indexOf('\"', iDQuote + 1); + if (iEDQuote > 0 && iColon < iEDQuote) + { + i = strLine.indexOf(':', iEDQuote); + iColon = ((i != -1) ? i : iColon); + } + if (iEDQuote > 0) + { + iDQuote = strLine.indexOf('\"', iEDQuote + 1); + } + else + { + iDQuote = -1; + } + } + + // no parameters + if (iSColon < 0) + { + if (iColon >= 0) + { + outName = strLine.extractBetween(0, iColon, outName).toUpper(); + //outName = strLine.extractBetween(0, iColon, outName); + //outName = JulianUtility::ToUpper(outName); + + outVal = strLine.extractBetween(iColon + 1, lineLength, outVal); + } + else + { + outName = strLine.toUpper(); + //outName = strLine; + //outName = JulianUtility::ToUpper(outName); + + outVal = ""; + } + } + else + { + // has parameters + UnicodeString u; + t_int32 iIndex = -1; + + if (iColon > 0) + { + iIndex = (iColon < iSColon) ? iColon : iSColon; + + outName = strLine.extractBetween(0, iIndex, u).toUpper(); + //outName = strLine.extractBetween(0, iIndex, u); + //outName = JulianUtility::ToUpper(outName); + + outVal = strLine.extractBetween(iColon + 1, lineLength, u); + } + if (iIndex < iColon) + u = strLine.extractBetween(iIndex + 1, iColon, u); + else + u = ""; + + //if (FALSE) TRACE("u = %s\r\n", u.toCString("")); // u = sParams now. + if (u.size() > 0) + { + // NOTE: TODO: This assumes semicolons can't exist between DQUOTE + UnicodeStringTokenizer * st = new UnicodeStringTokenizer(u, + JulianKeyword::Instance()->ms_sSEMICOLON_SYMBOL); + PR_ASSERT(st != 0); + PR_ASSERT(parameters != 0); + + if (st != 0 && parameters != 0) + { + UnicodeString paramName; + UnicodeString paramVal; + t_int32 iEq = -1; + + //t_bool error; + //t_int32 paramsLen = -1; + + while (st->hasMoreTokens()) + { + u = st->nextToken(u, status); + u.trim(); + + //if (FALSE) TRACE("u = %s\r\n", u.toCString("")); + + iEq = u.indexOf('='); + if (iEq < 0) + { + paramName = u.extractBetween(0, u.size(), paramName).toUpper(); + //paramName = u.extractBetween(0, u.size(), paramName); + //paramName = JulianUtility::ToUpper(paramName); + + paramVal = ""; + } + else + { + paramName = u.extractBetween(0, iEq, paramName).toUpper(); + //paramName = u.extractBetween(0, u.size(), paramName); + //paramName = JulianUtility::ToUpper(paramName); + + paramVal = u.extractBetween(iEq + 1, u.size(), paramVal); + } + + //if (FALSE) TRACE("paramName = %s\r\n", paramName.toCString("")); + //if (FALSE) TRACE("paramVal = %s\r\n", paramVal.toCString("")); + + // checking parameters here + // NOTE: moved error checking to the storeData method + //error = checkParam(outName, paramName, paramVal); + //if (!error) + //{ + parameters->Add(new ICalParameter(paramName, paramVal)); + //} + //else + //{ + // parseError = TRUE; + //} + } + delete st; st = 0; + } + } + } + //if (FALSE) TRACE("outName = --%s--, outVal = --%s--, paramSize = %d\r\n", outName.toCString(""), outVal.toCString(""), parameters->GetSize()); + + //return parseError; + //return FALSE; +} + +//--------------------------------------------------------------------- + +void +ICalProperty::deleteICalParameterVector(JulianPtrArray * parameters) +{ + ICalParameter * ip; + t_int32 i; + if (parameters != 0) + { + for (i = parameters->GetSize() - 1; i >= 0; i--) + { + ip = (ICalParameter *) parameters->GetAt(i); + delete ip; ip = 0; + } + } +} + +//--------------------------------------------------------------------- + +// Trims UnicodeStrings. The UnicodeString::trim() method seems to +// only trim space separators (ASCII 12 and ' '). It doesn't trim +// ('\r' ASCII 13). Note assumes only 8-bit string +UnicodeString & +ICalProperty::Trim(UnicodeString & s) +{ + TextOffset endOffset = s.size(); + TextOffset startOffset = 0; + while ((startOffset < endOffset) && + (s[(TextOffset) startOffset] == ' ' || + s[(TextOffset) startOffset] == '\t' || + s[(TextOffset) startOffset] == '\r' || + s[(TextOffset) startOffset] == '\n')) + { + startOffset++; + } + while ((startOffset < endOffset) && + (s[(TextOffset) (endOffset - 1)] == ' ' || + s[(TextOffset) (endOffset - 1)] == '\t' || + s[(TextOffset) (endOffset - 1)] == '\r' || + s[(TextOffset) (endOffset - 1)] == '\n')) + { + endOffset--; + } + if ((startOffset > 0) || (endOffset < s.size())) + s.extractBetween(startOffset, endOffset, s); + return s; +} + +//--------------------------------------------------------------------- + +void +ICalProperty::deleteICalPropertyVector(JulianPtrArray * properties) +{ + ICalProperty * ip; + t_int32 i; + if (properties != 0) + { + for (i = properties->GetSize() - 1; i >= 0; i--) + { + ip = (ICalProperty *) properties->GetAt(i); + delete ip; ip = 0; + } + } +} +//--------------------------------------------------------------------- +void +ICalProperty::deletePeriodVector(JulianPtrArray * periods) +{ + Period * ip; + t_int32 i; + if (periods != 0) + { + for (i = periods->GetSize() - 1; i >= 0; i--) + { + ip = (Period *) periods->GetAt(i); + delete ip; ip = 0; + } + } +} +//--------------------------------------------------------------------- +UnicodeString & +ICalProperty::propertyToString(ICalProperty * property, + UnicodeString & dateFmt, + UnicodeString & retVal) +{ + if (property == 0) + retVal = ""; + else + { + retVal = property->toString(dateFmt, retVal); + } + return retVal; +} + +//--------------------------------------------------------------------- + +UnicodeString & +ICalProperty::propertyToString(ICalProperty * property, + UnicodeString & retVal) +{ + if (property == 0) + retVal = ""; + else + { + retVal = property->toString(retVal); + } + return retVal; +} +//--------------------------------------------------------------------- +UnicodeString & +ICalProperty::propertyVectorToString(JulianPtrArray * properties, + UnicodeString & retVal) +{ + retVal = ""; + if (properties == 0) + { + } + else + { + UnicodeString u; + ICalProperty * prop; + t_int32 i; + + for (i = 0; i < properties->GetSize(); i++) + { + prop = (ICalProperty *) properties->GetAt(i); + PR_ASSERT(prop != 0); + if (prop != 0) + { + retVal += prop->toString(u); + if (i < properties->GetSize() - 1) + retVal += ','; //ms_sCOMMA_SYMBOL; + } + } + } + return retVal; +} +//--------------------------------------------------------------------- +UnicodeString & +ICalProperty::propertyVectorToString(JulianPtrArray * properties, + UnicodeString & dateFmt, + UnicodeString & retVal) +{ + + retVal = ""; + if (properties == 0) + { + } + else + { + t_int32 i; + UnicodeString u; + ICalProperty * prop; + + for (i = 0; i < properties->GetSize(); i++) + { + prop = (ICalProperty *) properties->GetAt(i); + PR_ASSERT(prop != 0); + if (prop != 0) + { + retVal += prop->toString(dateFmt, u); + + if (i < properties->GetSize() - 1) + retVal += ','; //ms_sCOMMA_SYMBOL; + } + } + } + return retVal; +} +//--------------------------------------------------------------------- + +UnicodeString & +ICalProperty::parameterToCalString(UnicodeString sParam, + UnicodeString & sVal, + UnicodeString & out) +{ + out = ""; + if (sVal.size() > 0) + { + out = JulianKeyword::Instance()->ms_sSEMICOLON_SYMBOL; + out += sParam; + out += '='; + out += sVal; + } + return out; +} + +//--------------------------------------------------------------------- + + +UnicodeString & +ICalProperty::parameterVToCalString(UnicodeString sParam, + JulianPtrArray * v, + UnicodeString & out) +{ + UnicodeString ss; + t_int32 i = 0; + out = ""; + if (v != 0) { + + for (i = 0; i < v->GetSize(); i++) + { + ss = *((UnicodeString *) v->GetAt(i)); + if (i == 0) + { + out += ';'; out += sParam; + out += '='; out += ss; + } + else + { + out += ';'; out += ss; + } + } + } + return out; +} + +//--------------------------------------------------------------------- +UnicodeString & +ICalProperty::propertyToICALString(UnicodeString & propName, + ICalProperty * property, + UnicodeString & retVal) +{ + if (property == 0) + retVal = ""; + else + { + UnicodeString out; + out = property->toICALString(propName, retVal); + retVal = multiLineFormat(retVal); + //retVal = multiLineFormat(property->toICALString(propName, retVal)); + } + return retVal; +} +//--------------------------------------------------------------------- +UnicodeString & +ICalProperty::propertyVectorToICALString(UnicodeString & propName, + JulianPtrArray * properties, + UnicodeString & retVal) +{ + t_int32 i; + UnicodeString u; + ICalProperty * prop; + retVal = ""; + if (properties == 0) + { + } + else + { + //retVal = ""; + for (i = 0; i < properties->GetSize(); i++) + { + prop = (ICalProperty *) properties->GetAt(i); + PR_ASSERT(prop != 0); + if (prop != 0) + { + retVal += multiLineFormat(prop->toICALString(propName, u)); + } + } + } + return retVal; +} +//--------------------------------------------------------------------- +UnicodeString & +ICalProperty::vectorToICALString(JulianPtrArray * strings, UnicodeString & retVal) +{ + retVal = ""; + if (strings == 0) + { + } + else + { + t_int32 i; + UnicodeString u; + + for (i = 0; i < strings->GetSize(); i++) + { + u = *((UnicodeString *) strings->GetAt(i)); + u += JulianKeyword::Instance()->ms_sLINEBREAK; + retVal += multiLineFormat(u); + } + } + return retVal; +} + +//--------------------------------------------------------------------- + +UnicodeString & +ICalProperty::multiLineFormat(UnicodeString & s) +{ + t_int32 size = s.size(); + + if (size == 0) + return s; + if (size <= ms_iMAX_LINE_LENGTH) + return s; + else + { + UnicodeString sResult, t; + + sResult = s.extractBetween(0, ms_iMAX_LINE_LENGTH, sResult); + t = s.extractBetween(ms_iMAX_LINE_LENGTH, size, t); + t.insert(0, JulianKeyword::Instance()->ms_sLINEBREAKSPACE); + sResult += multiLineFormat(t); + + // end recursion + size = sResult.size(); + if (sResult.endsWith(JulianKeyword::Instance()->ms_sLINEFEEDSPACE)) + sResult.removeBetween(size - 1, size); + s = sResult; + return s; + } +} + +//--------------------------------------------------------------------- +t_bool +ICalProperty::IsXToken(UnicodeString & s) +{ + if (s.size() == 0) + return FALSE; + if (s.size() < 2) + return FALSE; + if ((s[(TextOffset) 0] != 'X' && s[(TextOffset) 0] != 'x') || + (s[(TextOffset) 1] != '-')) + return FALSE; + else + return TRUE; +} +//--------------------------------------------------------------------- + +void +ICalProperty::CloneICalPropertyVector(JulianPtrArray * propertiesToClone, + JulianPtrArray * out, + JLog * initLog) +{ + if (out == 0 || propertiesToClone == 0) + return; + else + { + t_int32 i; + ICalProperty * ip; + for (i = 0; i < propertiesToClone->GetSize(); i++) + { + ip = ((ICalProperty *) propertiesToClone->GetAt(i))->clone(initLog); + PR_ASSERT(ip != 0); + out->Add(ip); + } + } +} + +//--------------------------------------------------------------------- + +void +ICalProperty::CloneUnicodeStringVector(JulianPtrArray * ustringsToClone, + JulianPtrArray * out) +{ + if (out == 0 || ustringsToClone == 0) + return; + else + { + t_int32 i; + UnicodeString * u; + for (i = 0; i < ustringsToClone->GetSize(); i++) + { + u = new UnicodeString(*((UnicodeString *) ustringsToClone->GetAt(i))); + PR_ASSERT(u != 0); + out->Add(u); + } + } +} +//--------------------------------------------------------------------- + diff --git a/calendar/modules/core/ical/src/prprtyfy.cpp b/calendar/modules/core/ical/src/prprtyfy.cpp new file mode 100644 index 00000000000..af0e88e3c25 --- /dev/null +++ b/calendar/modules/core/ical/src/prprtyfy.cpp @@ -0,0 +1,74 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +// prprtyfy.cpp +// John Sun +// 5:19 PM February 12 1998 + +#include "stdafx.h" +#include "jdefines.h" + +#include "prprtyfy.h" +#include "prprty.h" +#include "dprprty.h" +#include "duprprty.h" +#include "iprprty.h" +#include "sprprty.h" +//#include "bprprty.h" +//#include "pprprty.h" + + +ICalPropertyFactory::ICalPropertyFactory() +{ +} + +//--------------------------------------------------------------------- + +ICalProperty * +ICalPropertyFactory::Make(ICalProperty::PropertyTypes aType, void * value, + JulianPtrArray * parameters) +{ + + PR_ASSERT(value != 0); + if (value != 0) + { + switch (aType) + { + case ICalProperty::TEXT: + return new StringProperty(*((UnicodeString *) value), parameters); + case ICalProperty::DATETIME: + return new DateTimeProperty(*((DateTime *) value), parameters); + case ICalProperty::INTEGER: + return new IntegerProperty(*((t_int32 *) value), parameters); + case ICalProperty::DURATION: + return new DurationProperty(*((Julian_Duration *) value), parameters); + case ICalProperty::PERIOD: + return 0; + //return new PeriodProperty((Period *) value, parameters); + case ICalProperty::BOOLEAN: + return 0; + //return new BooleanProperty(*(t_bool *) value, parameters); + default: + return 0; + } + } + return 0; +} +//--------------------------------------------------------------------- + + diff --git a/calendar/modules/core/ical/src/rcrrence.cpp b/calendar/modules/core/ical/src/rcrrence.cpp new file mode 100644 index 00000000000..7b36484b831 --- /dev/null +++ b/calendar/modules/core/ical/src/rcrrence.cpp @@ -0,0 +1,1867 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +// rcrrence.cpp +// John Sun +// 10:45 AM Febuary 2 1997 + +// TODO: Known bugs in recurrence handling: +// 1) Given a rule WITH a BYMONTH tag and no BYDAY, BYMONTHDAY, BYYEARDAY tag +// I should use dtstart as BYMONTHDAY +// i.e. RRULE:FREQ=YEARLY;COUNT=10;BYMONTH=6,7 -> 6/7/97,7/7/97,6/7/98,7/7/98,6/7/99,7/7/99, etc. +// NOT 6/1-31/97,7/1-31/97,6/1-31/98,7/1-31/98,6/1-31/99,7/1-31/99, etc. as it does now. +// 2) UNTIL BUG +// generator aborts if date gets past until. However some dates may not be produced +// that are actually before certain produced dates. +// 3) BYSETPOS +// start dates affect bySETPOS' first value. This is bad. +// (i.e FREQ=MONTHLY;BYDAY=TU,WE,TH;BYSETPOS=3 with start of 19970904T090000) +// should not produce 9/10, which current code does +// 4) I DON'T HANDLE BYSECOND. or FREQ=SECONDLY +// 5) DON'T HANDLE TZID yet! +// 7) FREQ tag that is lower than span value of BYxxx TAG fail +// (i.e FREQ=MINUTELY;INTERVAL=20;BYHOUR=9,10,11,12,13,14,15,16 FAILS) +#include "stdafx.h" +#include "jdefines.h" + +#include +#include +#include "datetime.h" +#include "duration.h" +#include "rrday.h" +#include "ptrarray.h" +#include "jutility.h" +#include "bydmgntr.h" +#include "bydwgntr.h" +#include "bydygntr.h" +#include "byhgntr.h" +#include "bymgntr.h" +#include "bymdgntr.h" +#include "bymogntr.h" +#include "bywngntr.h" +#include "byydgntr.h" +#include "deftgntr.h" +#include "dategntr.h" +#include "keyword.h" +#include "period.h" +#include "datetime.h" +#include "rcrrence.h" +#include "unistrto.h" +#include "keyword.h" +#include "icalprm.h" +#include "jlog.h" + +//#define DEBUG 1 +//--------------------------------------------------------------------- +//static UnicodeString s_sSemiColonSymbol = ";"; +//static UnicodeString JulianKeyword::Instance()->ms_sCOMMA_SYMBOL = ","; + +/* + * This is a hack so I could get it compiled on unix. We need + * to remove Windows specific code from this file. + * -terry (copying sman's hack) + */ +#define TRACE printf + +#if JULIAN_DEBUGGING_RECURRENCE + +void Recurrence::TRACE_DATETIMEVECTOR(JulianPtrArray * x, char * name) +{ + //if (FALSE) TRACE("Name: %s,", name); + if (x != 0) + { + //if (FALSE) TRACE("Size: %d", x->GetSize()); + t_int32 ii; + for (ii = 0; ii < x->GetSize(); ii++) + { + //if (FALSE) TRACE("\r\n %s[%d] = %s", name, ii, ((DateTime *)x->GetAt(ii))->toISO8601().toCString("")); + } + //if (FALSE) TRACE("\r\n"); + } + else + { + //if (FALSE) TRACE(" is NULL\r\n"); + } +}; +// prints a vector of vector of datetimes +void Recurrence::TRACE_DATETIMEVECTORVECTOR(JulianPtrArray * x, char * name) +{ + //if (FALSE) TRACE("Name: %s,", name); + JulianPtrArray * xi; + if (x != 0) + { + //if (FALSE) TRACE("Size: %d", x->GetSize()); + t_int32 ii; + t_int32 jj; + for (ii = 0; ii < x->GetSize(); ii++) + { + xi = (JulianPtrArray *) x->GetAt(ii); + for (jj = 0; jj < xi->GetSize(); jj++) + { + //if (FALSE) TRACE("\r\n %s[%d][%d] = %s", name, ii, jj,((DateTime *)xi->GetAt(jj))->toISO8601().toCString("")); + } + } + //if (FALSE) RACE("\r\n"); + } + else + { + //if (FALSE) TRACE(" is NULL\r\n"); + } +} + +#endif + +const t_int32 Recurrence::ms_iUNSET = -10000; // should be set to Integer.MIN + +const t_int32 Recurrence::ms_iByMinuteGntrIndex = 0; +const t_int32 Recurrence::ms_iByHourGntrIndex = 1; +const t_int32 Recurrence::ms_iByWeekNoGntrIndex = 2; +const t_int32 Recurrence::ms_iByYearDayGntrIndex = 3; +const t_int32 Recurrence::ms_iByMonthGntrIndex = 4; +const t_int32 Recurrence::ms_iByMonthDayGntrIndex = 5; +const t_int32 Recurrence::ms_iByDayYearlyGntrIndex = 6; +const t_int32 Recurrence::ms_iByDayMonthlyGntrIndex = 7; +const t_int32 Recurrence::ms_iByDayWeeklyGntrIndex = 8; +const t_int32 Recurrence::ms_iDefaultGntrIndex = 9; +const t_int32 Recurrence::ms_iGntrSize = 10; + +const t_int32 Recurrence::ms_aiGenOrderZero[] = +{ + Recurrence::ms_iByWeekNoGntrIndex, + Recurrence::ms_iByYearDayGntrIndex, + Recurrence::ms_iByMonthGntrIndex, + Recurrence::ms_iByDayYearlyGntrIndex + + /* + Recurrence::ms_iByMonthGntrIndex, + Recurrence::ms_iByWeekNoGntrIndex, + Recurrence::ms_iByYearDayGntrIndex, + Recurrence::ms_iByDayYearlyGntrIndex*/ +}; +const t_int32 Recurrence::ms_GenOrderZeroLen = 4; +const t_int32 Recurrence::ms_aiGenOrderOne[] = +{ + Recurrence::ms_iByMonthDayGntrIndex, + Recurrence::ms_iByDayMonthlyGntrIndex +}; +const t_int32 Recurrence::ms_GenOrderOneLen = 2; + +const t_int32 Recurrence::ms_aiGenOrderTwo[] ={Recurrence::ms_iByDayWeeklyGntrIndex}; +const t_int32 Recurrence::ms_GenOrderTwoLen = 1; +const t_int32 Recurrence::ms_aiGenOrderThree[] = {Recurrence::ms_iByHourGntrIndex}; +const t_int32 Recurrence::ms_GenOrderThreeLen = 1; +const t_int32 Recurrence::ms_aiGenOrderFour[] = {Recurrence::ms_iByMinuteGntrIndex}; +const t_int32 Recurrence::ms_GenOrderFourLen = 1; +const t_int32 Recurrence::ms_aiGenOrderFive[] = {Recurrence::ms_iDefaultGntrIndex}; +const t_int32 Recurrence::ms_GenOrderFiveLen = 1; + +const t_int32 * Recurrence::ms_aaiGenOrder[] = +{ + Recurrence::ms_aiGenOrderZero, + Recurrence::ms_aiGenOrderOne, + Recurrence::ms_aiGenOrderTwo, + Recurrence::ms_aiGenOrderThree, + Recurrence::ms_aiGenOrderFour, + Recurrence::ms_aiGenOrderFive, +}; +const t_int32 Recurrence::ms_GenOrderLen = 6; + +//--------------------------------------------------------------------- + +void Recurrence::init() +{ + m_iType = JulianUtility::RT_NONE; + m_Interval = 0; + m_iCount = ms_iUNSET; + m_iWkSt = Calendar::MONDAY; + m_Until.setTime(-1); + m_iBySetPosLen = 0; + + m_aaiByDay = 0; + m_aiByMinute = 0; + m_aiByHour = 0; + m_aiByMonthDay = 0; + m_aiByYearDay = 0; + m_aiBySetPos = 0; + m_aiByWeekNo = 0; + m_aiByMonth = 0; + + m_GntrVctr = new JulianPtrArray(); PR_ASSERT(m_GntrVctr != 0); + + ms_ByMinuteGntr = new ByMinuteGenerator(); PR_ASSERT(ms_ByMinuteGntr != 0); + ms_ByHourGntr = new ByHourGenerator(); PR_ASSERT(ms_ByHourGntr != 0); + ms_ByWeekNoGntr = new ByWeekNoGenerator(); PR_ASSERT(ms_ByWeekNoGntr != 0); + ms_ByYearDayGntr = new ByYearDayGenerator(); PR_ASSERT(ms_ByYearDayGntr != 0); + ms_ByMonthGntr = new ByMonthGenerator(); PR_ASSERT(ms_ByMonthGntr != 0); + ms_ByMonthDayGntr = new ByMonthDayGenerator(); PR_ASSERT(ms_ByMonthDayGntr != 0); + ms_ByDayYearlyGntr = new ByDayYearlyGenerator(); PR_ASSERT(ms_ByDayYearlyGntr != 0); + ms_ByDayMonthlyGntr = new ByDayMonthlyGenerator(); PR_ASSERT(ms_ByDayMonthlyGntr != 0); + ms_ByDayWeeklyGntr = new ByDayWeeklyGenerator(); PR_ASSERT(ms_ByDayWeeklyGntr != 0); + ms_DefaultGntr = new DefaultGenerator(); PR_ASSERT(ms_DefaultGntr != 0); + + + // MUST BE IN THIS ORDER!! + m_GntrVctr->Add(ms_ByMinuteGntr); + m_GntrVctr->Add(ms_ByHourGntr); + m_GntrVctr->Add(ms_ByWeekNoGntr); + m_GntrVctr->Add(ms_ByYearDayGntr); + m_GntrVctr->Add(ms_ByMonthGntr); + m_GntrVctr->Add(ms_ByMonthDayGntr); + m_GntrVctr->Add(ms_ByDayYearlyGntr); + m_GntrVctr->Add(ms_ByDayMonthlyGntr); + m_GntrVctr->Add(ms_ByDayWeeklyGntr); + m_GntrVctr->Add(ms_DefaultGntr); + + m_iActiveGenerators = 0; + +} +//--------------------------------------------------------------------- + +Recurrence::Recurrence() +{ + init(); +} + +//--------------------------------------------------------------------- +#if 0 +Recurrence::Recurrence(DateTime startDate, DateTime stopDate, + Julian_Duration * duration, UnicodeString & ruleString) +{ + init(); + m_StartDate = startDate; + m_StopDate = stopDate; + m_Duration = duration; + + m_bParseValid = parse(ruleString); + +} +//--------------------------------------------------------------------- + +Recurrence::Recurrence(DateTime startDate, Julian_Duration * duration, + UnicodeString & ruleString) +{ + init(); + m_StartDate = startDate; + m_Duration = duration; + + m_StopDate = startDate; + m_StopDate.add(*duration); + + m_bParseValid = parse(ruleString); +} +#endif +//--------------------------------------------------------------------- + +Recurrence::Recurrence(DateTime startDate, UnicodeString & ruleString) +{ + init(); + m_StartDate = startDate; + m_StopDate.setTime(-1); + m_Duration = 0; + + m_bParseValid = parse(ruleString); +} +//--------------------------------------------------------------------- + +Recurrence::~Recurrence() +{ + // delete, generators, then delete parameters. + + t_int32 i; + for (i = m_GntrVctr->GetSize() - 1; i >= 0; i--) + { + delete ((DateGenerator *)m_GntrVctr->GetAt(i)); + } + m_GntrVctr->RemoveAll(); + + if (m_aaiByDay != 0) { delete [] m_aaiByDay; m_aaiByDay = 0; } + if (m_aiByMinute != 0) { delete [] m_aiByMinute; m_aiByMinute = 0; } + if (m_aiByHour != 0) { delete [] m_aiByHour ; m_aiByHour = 0; } + if (m_aiByMonthDay != 0) { delete [] m_aiByMonthDay; m_aiByMonthDay = 0; } + if (m_aiByYearDay != 0) { delete [] m_aiByYearDay ; m_aiByYearDay = 0; } + if (m_aiBySetPos != 0) { delete [] m_aiBySetPos ; m_aiBySetPos = 0; } + if (m_aiByWeekNo != 0) { delete [] m_aiByWeekNo ; m_aiByWeekNo = 0; } + if (m_aiByMonth != 0) { delete [] m_aiByMonth ; m_aiByMonth = 0; } + + if (m_GntrVctr != 0) { delete m_GntrVctr; m_GntrVctr = 0; } + if (m_Interval != 0) { delete m_Interval; m_Interval = 0; } + if (m_Duration != 0) { delete m_Duration; m_Duration = 0; } +} + +//--------------------------------------------------------------------- + +t_bool Recurrence::isValid() const +{ + return m_bParseValid; +} + +//--------------------------------------------------------------------- + +void +Recurrence::parsePropertyLine(UnicodeString & strLine, + JulianPtrArray * parameters) + //Hashtable * properties) +{ + t_int32 iColon = strLine.indexOf(':'); + if (iColon < 0) + { + return; + } + else + { + ErrorCode status = ZERO_ERROR; + UnicodeString u; + + u = strLine.extractBetween(iColon + 1, strLine.size(), u); + + UnicodeStringTokenizer * st = + new UnicodeStringTokenizer(u, JulianKeyword::Instance()->ms_sSEMICOLON_SYMBOL); + + PR_ASSERT(st != 0); + + UnicodeString paramName; + UnicodeString paramVal; + t_int32 iEq = -1; + + while (st->hasMoreTokens()) + { + u = st->nextToken(u, status); + u.trim(); + +#if JULIAN_DEBUGGING_RECURRENCE + //if (FALSE) TRACE("u = %s\r\n", u.toCString("")); +#endif + iEq = u.indexOf('='); + if (iEq < 0) + { + paramName = u.extractBetween(0, u.size(), paramName).toUpper(); + paramVal = ""; + } + else + { + paramName = u.extractBetween(0, iEq, paramName).toUpper(); + paramVal = u.extractBetween(iEq + 1, u.size(), paramVal); + } +#if JULIAN_DEBUGGING_RECURRENCE + //if (FALSE) TRACE("[paramName | paramVal] = [%s | %s]\r\n", paramName.toCString(""), paramVal.toCString("")); +#endif + parameters->Add(new ICalParameter(paramName, paramVal)); + } + delete st; st = 0; + } +} +//--------------------------------------------------------------------- +// TODO: crash proof +t_bool +Recurrence::parse(UnicodeString & s) + +{ + t_bool bParseError = FALSE; + + DateGenerator * dg; + JulianPtrArray * v; + + UnicodeString sErrorMsg = "InvalidByMinuteValue"; + + UnicodeString t, u; + t_int32 tempInterval = ms_iUNSET; + t_int32 iYearSpanConflict = 0; + t_bool bYearDay = FALSE; + t_bool bWeekNo = FALSE; + t_bool bByMonth = FALSE; + t_int32 i, j; + t_int32 retSize; + t_int32 byMonthDaySize = 0; + t_int32 byMonthSize = 0; + t_int32 temp = 0; + + // PARSES THE LINE AND FILLS IN PARAMETERS Vector + JulianPtrArray * parameters = new JulianPtrArray(); PR_ASSERT(parameters != 0); + if (parameters == 0) + { + // Ran out of memory, return FALSE. + return FALSE; + } + Recurrence::parsePropertyLine(s, parameters); + +#if JULIAN_DEBUGGING_RECURRENCE + //if (FALSE) TRACE("\r\n----------------------------------------------------\r\n"); +#endif + + // First get FREQ value + ICalParameter * ip; + t_bool hasFreq = FALSE; + for (i = 0; i < parameters->GetSize(); i++) + { + ip = (ICalParameter *) parameters->GetAt(i); + if (ip->getParameterName(u).compareIgnoreCase(JulianKeyword::Instance()->ms_sFREQ) == 0) + { + t = ip->getParameterValue(t); +#if JULIAN_DEBUGGING_RECURRENCE + //if (FALSE) TRACE("FREQ = %s\r\n", t.toCString("")); +#endif + m_iType = stringToType(t, bParseError); + hasFreq = TRUE; + } + } + + if (bParseError || !hasFreq) + { + // Parse Error: Invalid or Missing Frequency Parameter + // CLEANUP + deleteICalParameterVector(parameters); + delete parameters; + return FALSE; + } + + + v = new JulianPtrArray(); PR_ASSERT(v != 0); + + for (i = 0; i < parameters->GetSize(); i++) + { + ip = (ICalParameter *) parameters->GetAt(i); + u = ip->getParameterName(u); + t = ip->getParameterValue(t); + + if (t.size() == 0) + { + + } + else + { +#if JULIAN_DEBUGGING_RECURRENCE + //if (FALSE) TRACE("(key | value) = (%s | %s)\r\n", u.toCString(""), t.toCString("")); +#endif + //const char * tCharStar = t.toCString(""); + t_int32 tSize = t.size(); + JAtom atomParam(u); + + if (JulianKeyword::Instance()->ms_ATOM_UNTIL == atomParam) + { + // TODO: ONLY accepts UTC time for now + m_Until.setTimeString(t); + // TODO: Log if m_Until is invalid or before start time + } + else if (JulianKeyword::Instance()->ms_ATOM_COUNT == atomParam) + { + char * tcc = t.toCString(""); + PR_ASSERT(tcc != 0); + m_iCount = JulianUtility::atot_int32(tcc, bParseError, tSize); + delete [] tcc; tcc = 0; + } + else if (JulianKeyword::Instance()->ms_ATOM_INTERVAL == atomParam) + { + // TODO: if duration allowed, parse duration, then it to interval + char * tcc = t.toCString(""); + PR_ASSERT(tcc != 0); + tempInterval = JulianUtility::atot_int32(tcc, bParseError, tSize); + delete [] tcc; tcc = 0; + } + else if (JulianKeyword::Instance()->ms_ATOM_WKST == atomParam) + { + m_iWkSt = stringToDay(t, bParseError); + } + else if (JulianKeyword::Instance()->ms_ATOM_BYSETPOS == atomParam) + { + parseDelimited(t, JulianKeyword::Instance()->ms_sCOMMA_SYMBOL, v); + m_aiBySetPos = verifyIntList(v, -366, 366, sErrorMsg, retSize, bParseError, TRUE); + m_iBySetPosLen = retSize; + m_iActiveGenerators++; + } + else if (JulianKeyword::Instance()->ms_ATOM_BYMINUTE == atomParam) + { + dg = (DateGenerator *) m_GntrVctr->GetAt(ms_iByMinuteGntrIndex); + if (dg->getSpan() < m_iType) + { + // error FIMR (FreqIntervalMismatchRecurrence) + bParseError = TRUE; + } + else + { + parseDelimited(t, JulianKeyword::Instance()->ms_sCOMMA_SYMBOL, v); + m_aiByMinute = verifyIntList(v, 0, 59, sErrorMsg, retSize, bParseError); + dg->setParamsArray(m_aiByMinute, retSize); + m_iActiveGenerators++; + } + } + else if (JulianKeyword::Instance()->ms_ATOM_BYHOUR == atomParam) + { + dg = (DateGenerator *) m_GntrVctr->GetAt(ms_iByHourGntrIndex); + if (dg->getSpan() < m_iType) + { + // error FIMR (FreqIntervalMismatchRecurrence) + bParseError = TRUE; + } + else + { + parseDelimited(t, JulianKeyword::Instance()->ms_sCOMMA_SYMBOL, v); + m_aiByHour = verifyIntList(v, 0, 23, sErrorMsg, retSize, bParseError); + dg->setParamsArray(m_aiByHour, retSize); + m_iActiveGenerators++; + } + } + else if (JulianKeyword::Instance()->ms_ATOM_BYMONTHDAY == atomParam) + { + dg = (DateGenerator *) m_GntrVctr->GetAt(ms_iByMonthDayGntrIndex); + if (dg->getSpan() < m_iType) + { + // error FIMR (FreqIntervalMismatchRecurrence) + bParseError = TRUE; + } + else + { + parseDelimited(t, JulianKeyword::Instance()->ms_sCOMMA_SYMBOL, v); + m_aiByMonthDay = verifyIntList(v, -31, 31, sErrorMsg, retSize, bParseError, TRUE); + dg->setParamsArray(m_aiByMonthDay, retSize); + m_iActiveGenerators++; + byMonthDaySize = retSize; + } + } + else if (JulianKeyword::Instance()->ms_ATOM_BYYEARDAY == atomParam) + { + dg = (DateGenerator *) m_GntrVctr->GetAt(ms_iByYearDayGntrIndex); + if (dg->getSpan() < m_iType) + { + // error FIMR (FreqIntervalMismatchRecurrence) + bParseError = TRUE; + } + else + { + parseDelimited(t, JulianKeyword::Instance()->ms_sCOMMA_SYMBOL, v); + m_aiByYearDay = verifyIntList(v, -366, 366, sErrorMsg, retSize, bParseError, TRUE); + dg->setParamsArray(m_aiByYearDay, retSize); + m_iActiveGenerators++; + iYearSpanConflict++; + bYearDay = TRUE; + } + } + else if (JulianKeyword::Instance()->ms_ATOM_BYWEEKNO == atomParam) + { + dg = (DateGenerator *) m_GntrVctr->GetAt(ms_iByWeekNoGntrIndex); + if (dg->getSpan() < m_iType) + { + // error FIMR (FreqIntervalMismatchRecurrence) + bParseError = TRUE; + } + else + { + parseDelimited(t, JulianKeyword::Instance()->ms_sCOMMA_SYMBOL, v); + m_aiByWeekNo = verifyIntList(v, -53, 53, sErrorMsg, retSize, bParseError, TRUE); + dg->setParamsArray(m_aiByWeekNo, retSize); + m_iActiveGenerators++; + iYearSpanConflict++; + bWeekNo = TRUE; + } + } + else if (JulianKeyword::Instance()->ms_ATOM_BYMONTH == atomParam) + { + dg = (DateGenerator *) m_GntrVctr->GetAt(ms_iByMonthGntrIndex); + if (dg->getSpan() < m_iType) + { + // error FIMR (FreqIntervalMismatchRecurrence) + bParseError = TRUE; + } + else + { + parseDelimited(t, JulianKeyword::Instance()->ms_sCOMMA_SYMBOL, v); + m_aiByMonth = verifyIntList(v, 1, 12, sErrorMsg, retSize, bParseError, TRUE); + dg->setParamsArray(m_aiByMonth, retSize); + m_iActiveGenerators++; + iYearSpanConflict++; + bByMonth = TRUE; + byMonthSize = retSize; + } + } + else if (JulianKeyword::Instance()->ms_ATOM_BYDAY == atomParam) + { + switch(m_iType) + { + case JulianUtility::RT_WEEKLY: + dg = (DateGenerator *) m_GntrVctr->GetAt(ms_iByDayWeeklyGntrIndex); + break; + case JulianUtility::RT_MONTHLY: + dg = (DateGenerator *) m_GntrVctr->GetAt(ms_iByDayMonthlyGntrIndex); + break; + case JulianUtility::RT_YEARLY: + dg = (DateGenerator *) m_GntrVctr->GetAt(ms_iByDayYearlyGntrIndex); + break; + default: + bParseError = TRUE; + //return FALSE; + } + PR_ASSERT(dg != 0); + if (dg->getSpan() < m_iType) + { + bParseError = TRUE; + } + else + { + parseDelimited(t, JulianKeyword::Instance()->ms_sCOMMA_SYMBOL, v); + m_aaiByDay = createByDayList(v, m_iType, retSize, bParseError); + dg->setRDay(m_aaiByDay, retSize); + m_iActiveGenerators++; + } + } + + } + deleteUnicodeStringVector(v); + v->RemoveAll(); + } + //delete propEnum; propEnum = 0; + + // Check BYMONTH, BYMONTHDAY mismatch (i.e. BYMONTH=11,BYMONTHDAY=-31 or 31 is error) + // NOTE: TODO: Doesn't account for leap years!!!! + // THUS: (asking for BYMONTH=2,BYMONTHDAY=29 will succeed, even for bad years!!!) + if (m_aiByMonth != 0 && m_aiByMonthDay != 0 && !bParseError) + { + for (i = 0; i < byMonthSize; i++) + { + for (j = 0; j < byMonthDaySize; j++) + { + // NOTE: to fix HPUX compile problems with abs + temp = m_aiByMonthDay[j]; + if (temp < 0) + temp = 0 - temp; + + if (DateTime::getMonthLength(m_aiByMonth[i], 2000) < + //abs(m_aiByMonthDay[j]) // this line is replaced by below + temp) + { + bParseError = TRUE; + break; + } + } + } + } + + if (tempInterval == ms_iUNSET) + { + internalSetInterval(1); + } + else + { + internalSetInterval(tempInterval); + } + // Default Generator + // If there are no active generators, we have no BYxxx tags, so we must install a + // default generator to do the work. + if (m_iActiveGenerators == 0) + { + // NOTE: to make it work on HPUX. + t_int32 params[3]; + params[0] = m_iType; + if (tempInterval == ms_iUNSET) + params[1] = 1; + else + params[1] = tempInterval; + params[2] = m_iCount; + + // commented out line below so HPUX won't die. + //t_int32 params[] = {m_iType, (tempInterval == ms_iUNSET) ? 1 : tempInterval, m_iCount}; + + ((DateGenerator *) m_GntrVctr->GetAt(ms_iDefaultGntrIndex))->setParamsArray(params, 3); + m_iActiveGenerators++; + } + + // TODO: IF there is more than one BY tag with a yearly span, + // make sure they don't conflict. + // If they do, then only the start date should be returned + + + /* + if (iYearSpanConflict > 1) + { + + if (bByMonth && bYearDay) + { + } + + if (bByMonth && bWeekNo) + { + } + + if (bYearDay && bWeekNo) + { + } + } + */ + + if((dg = (DateGenerator *)m_GntrVctr->GetAt(ms_iByDayWeeklyGntrIndex))->active() || + (dg = (DateGenerator *)m_GntrVctr->GetAt(ms_iByDayMonthlyGntrIndex))->active() || + (dg = (DateGenerator *)m_GntrVctr->GetAt(ms_iByDayYearlyGntrIndex))->active()) + { + dg->setParams(m_iWkSt); + } + + // CLEANUP + deleteUnicodeStringVector(v); + v->RemoveAll(); + delete v; v = 0; + + deleteICalParameterVector(parameters); + delete parameters; parameters = 0; + + if (bParseError) + { + // PARSE ERROR ENCOUNTERED +#if JULIAN_DEBUGGING_RECURRENCE + //if (FALSE) TRACE("ERROR: Parse error somewhere\r\n"); +#endif + return FALSE; + } + + return TRUE; + +} + +//--------------------------------------------------------------------- + +void Recurrence::internalSetInterval(t_int32 i) +{ + m_Interval = new Julian_Duration(); + + switch(m_iType) + { + case JulianUtility::RT_MINUTELY: + //m_Interval->setMinute(i); + m_Interval->set(0,0,0,0,i,0); + break; + case JulianUtility::RT_HOURLY: + //m_Interval->setHour(i); + m_Interval->set(0,0,0,i,0,0); + break; + case JulianUtility::RT_DAILY: + //m_Interval->setDay(i); + m_Interval->set(0,0,i,0,0,0); + break; + case JulianUtility::RT_WEEKLY: + //m_Interval->setWeek(i); + m_Interval->set(i); + break; + case JulianUtility::RT_MONTHLY: + //m_Interval->setMonth(i); + m_Interval->set(0,i,0,0,0,0); + break; + case JulianUtility::RT_YEARLY: + //m_Interval->setYear(i); + m_Interval->set(i,0,0,0,0,0); + break; + default: + break; + } +} +//--------------------------------------------------------------------- +// TODO: crash proof +void +Recurrence::stringEnforce(DateTime startDate, JulianPtrArray * srr, + JulianPtrArray * ser, JulianPtrArray * srd, + JulianPtrArray * sed, t_int32 bound, JulianPtrArray * out, + JLog * log) +{ + // rr and er are vector of Recurrence objects + // rd and ed are vector of DateTime objects + + // Vector of Recurrence objects + JulianPtrArray * rr = new JulianPtrArray(); PR_ASSERT(rr != 0); + JulianPtrArray * er = new JulianPtrArray(); PR_ASSERT(er != 0); + + // Vector of DateTimes + JulianPtrArray * rd = new JulianPtrArray(); PR_ASSERT(rd != 0); + JulianPtrArray * ed = new JulianPtrArray(); PR_ASSERT(ed != 0); + + t_int32 i = 0, size = 0; + UnicodeString u, t; + DateTime * dt; + + size = ((srr != 0) ? srr->GetSize() : 0); + if (size > 0) + { + for (i = 0; i < size; i++) + { + u = *((UnicodeString *) srr->GetAt(i)); +#if JULIAN_DEBUGGING_RECURRENCE + //if (FALSE) TRACE("u = -%s-\r\n", u.toCString("")); +#endif + rr->Add(new Recurrence(startDate, u)); + } + } + + size = ((ser != 0) ? ser->GetSize() : 0); + if (size > 0) + { + for (i = 0; i < size; i++) + { + u = *((UnicodeString *) ser->GetAt(i)); +#if JULIAN_DEBUGGING_RECURRENCE + //if (FALSE) TRACE("u = -%s-\r\n", u.toCString("")); +#endif + er->Add(new Recurrence(startDate, u)); + } + } + + size = ((srd != 0) ? srd->GetSize() : 0); + if (size > 0) + { + for (i = 0; i < size; i++) + { + u = * ((UnicodeString *) srd->GetAt(i)); +#if JULIAN_DEBUGGING_RECURRENCE + //if (FALSE) TRACE("u = -%s-\r\n", u.toCString("")); +#endif + t = u; + if (Period::IsParseable(u)) + { + Period * p = new Period(u); PR_ASSERT(p != 0); + if (p != 0) + { + PR_ASSERT(p->isValid()); + DateTime d; + d = p->getStart(); + // create new period + // add the start time of the period to vector only if after start time + if (!(d.beforeDateTime(startDate))) + rd->Add(new DateTime(d)); + delete p; p = 0; + } + } + else if (DateTime::IsParseableDate(u)) + { + t += 'T'; + t += startDate.toISO8601LocalTimeOnly(); +#if JULIAN_DEBUGGING_RECURRENCE + //if (FALSE) TRACE("t = -%s-\r\n", t.toCString("")); +#endif + dt = new DateTime(t); PR_ASSERT(dt != 0); + if (!(dt->beforeDateTime(startDate))) + { + rd->Add(dt); + } + else + { + delete dt; dt = 0; + } + } + else if (DateTime::IsParseableDateTime(u)) + { + dt = new DateTime(t); PR_ASSERT(dt != 0); + if (!(dt->beforeDateTime(startDate))) + { + rd->Add(dt); + } + else + { + delete dt; dt = 0; + } + } + else + { + // log an invalid rdate + if (log != 0) log->logError( + JulianLogErrorMessage::Instance()->ms_iInvalidRDate, 200); + } + } + } + size = ((sed != 0) ? sed->GetSize() : 0); + if (size > 0) + { + for (i = 0; i < size; i++) + { + u = * ((UnicodeString *) sed->GetAt(i)); +#if JULIAN_DEBUGGING_RECURRENCE + //if (FALSE) TRACE("u = -%s-\r\n", u.toCString("")); +#endif + ed->Add(new DateTime(u)); + } + } + // NOTE: rd, ed ownership taken in enforce + enforce(rr, er, rd, ed, bound, out, log); + + // CLEANUP: NOTE: rd, ed are deleted in enforce already + deleteRecurrenceVector(rr); + delete rr; rr = 0; + deleteRecurrenceVector(er); + delete er; er = 0; +} + +//--------------------------------------------------------------------- +// TODO: crash proof +void +Recurrence::enforce(JulianPtrArray * rr, JulianPtrArray * er, + JulianPtrArray * rd, JulianPtrArray * ed, + t_int32 bound, JulianPtrArray * out, JLog * log) +{ + JulianPtrArray * dr = new JulianPtrArray(); // dr is a vector of vectors + PR_ASSERT(dr != 0); + + JulianPtrArray * de = new JulianPtrArray(); // de is a vector of vectors + PR_ASSERT(de != 0); + + JulianPtrArray * dates; + + Recurrence * recur; + t_int32 i; + + PR_ASSERT(rr != 0 && er != 0 && rd != 0 && ed != 0); + + // First, create all dates with instances + for (i = 0; i < rr->GetSize(); i++) + { + dates = new JulianPtrArray(); PR_ASSERT(dates != 0); + recur = (Recurrence *) rr->GetAt(i); + recur->unzip(bound, dates, log, TRUE); + dr->Add(dates); +#if JULIAN_DEBUGGING_RECURRENCE + TRACE_DATETIMEVECTOR(dates, "dates"); +#endif + } + dr->Add(rd); + + // SECOND, create all exception dates + for (i = 0; i < er->GetSize(); i++) + { + dates = new JulianPtrArray(); PR_ASSERT(dates != 0); + recur = (Recurrence *) er->GetAt(i); + recur->unzip(bound, dates, log, FALSE); + de->Add(dates); +#if JULIAN_DEBUGGING_RECURRENCE + TRACE_DATETIMEVECTOR(dates, "dates"); +#endif + } + de->Add(ed); + + // Now, flatten out dates, exdates + JulianPtrArray * sZero = new JulianPtrArray(); + JulianPtrArray * sOne = new JulianPtrArray(); + + concat(dr, sZero); + concat(de, sOne); + + // eliminate duplicates from dates, exdates + eliminateDuplicates(sZero); + eliminateDuplicates(sOne); + + // intersect dates with exdates, add them to out vector + JulianPtrArray * s = new JulianPtrArray(); + s->Add(sZero); + s->Add(sOne); + intersectDateList(s, TRUE, out); + + // cleanup + deleteDateTimeVectorVector(dr); // deletes rd + delete dr; dr = 0; + deleteDateTimeVectorVector(de); // deleted ed + delete de; de = 0; + + deleteDateTimeVectorVector(s); // should delete sZero, and sOne + delete s; s = 0; +} + +//--------------------------------------------------------------------- + +t_int32 Recurrence::getGenOrderIndexLength(t_int32 genOrderIndex) +{ + switch (genOrderIndex) + { + case 0: return ms_GenOrderZeroLen; + case 1: return ms_GenOrderOneLen; + case 2: return ms_GenOrderTwoLen; + case 3: return ms_GenOrderThreeLen; + case 4: return ms_GenOrderFourLen; + case 5: return ms_GenOrderFiveLen; + default: return 0; + } +} + +//--------------------------------------------------------------------- +// TODO: make crash proof +void +Recurrence::unzip(t_int32 bound, JulianPtrArray * out, JLog * log, + t_bool bAddStartDate) +{ + //PR_ASSERT(out != 0); + //PR_ASSERT(isValid()); + // return if only startDate if !isValid + if (!isValid()) + { + if (out != 0) + { + if (bAddStartDate) + out->Add(new DateTime(m_StartDate)); + } + if (log != 0) + { + log->logError( + JulianLogErrorMessage::Instance()->ms_iInvalidRecurrenceError, 200); + } + return; + } + + // u = returnDates, z = genDates, + + t_int32 i, j, k, temp; + t_int32 lastInterval = m_iType; + DateGenerator * dg; + JulianPtrArray * v; // vector of vector of dates for this span type, deleted + JulianPtrArray * genDates; // vector of newly generated dates, deleted with v + t_bool done = FALSE; + DateTime t = m_StartDate; + DateTime * dt; + t_bool bSubGenerate = FALSE; + + // TODO: Known bug in handling UNTIL, if generating dates with UNTIL, + // it's possible that the generator exists the generate() method before + // generating all dates before until. + + t_int32 genOrderIndexLength = 0; + + JulianPtrArray * x = 0; // vector of dates for this interval, deleted + JulianPtrArray * returnDateVector = 0; // vector of dates to return, deleted + + if (m_iCount != ms_iUNSET && (!m_Until.isValid())) + bound = m_iCount; + + // TODO: prevent generator from running if previous generator ran with + // no dates generated + t_bool bPrevGenRan = FALSE; + + // If the default generator is active, twiddle it with the new count value. + + if((dg = (DateGenerator *)m_GntrVctr->GetAt(ms_iDefaultGntrIndex))->active()) + { + dg->setParams(bound); + } + + do + { + x = new JulianPtrArray(); PR_ASSERT(x != 0); + //bPrevGenRan = FALSE; + for (i = 0; i < ms_GenOrderLen; i++) + { + v = new JulianPtrArray(); + + genOrderIndexLength = getGenOrderIndexLength(i); + + for (j = 0; j < genOrderIndexLength; j++) + { + temp = ms_aaiGenOrder[i][j]; dg = (DateGenerator *) m_GntrVctr->GetAt(temp); + + // Make sure we have an active generator, and perform a strange test + // to see if a previous generator ran, but didn't find any dates. + // (If a previous generator ran and went dateless, we don't want to run.) + + if (dg->active() && (!(bPrevGenRan != FALSE && (x->GetSize() == 0)))) + { + genDates = new JulianPtrArray(); PR_ASSERT(genDates != 0); + + dg->setSpan(lastInterval); + // If previous generator has been run and produced dates, then run this test + if (x != 0 && x->GetSize() > 0) + { + for (k = 0; k < x->GetSize(); k++) + { + done = done || dg->generate((DateTime *) x->GetAt(k), *genDates, &m_Until); +#if JULIAN_DEBUGGING_RECURRENCE + //if (FALSE) TRACE("1) i = %d, j = %d, done = %d, genDates = ", i, j, done); + //if (FALSE) TRACE_DATETIMEVECTOR(genDates, "genDates"); +#endif + } + } + else + { + done = done || dg->generate(&t, *genDates, &m_Until); +#if JULIAN_DEBUGGING_RECURRENCE + //if (FALSE) TRACE("2) i = %d, j = %d, done = %d, genDates = ", i, j, done); + //if (FALSE) TRACE_DATETIMEVECTOR(genDates, "genDates"); +#endif + } + + lastInterval = dg->getInterval(); + + v->Add(genDates); + //bPrevGenRan = TRUE; + } + } + bSubGenerate = (i > 2); + + if (v->GetSize() > 0) + { + //bPrevGenRan = TRUE; +#if JULIAN_DEBUGGING_RECURRENCE + TRACE_DATETIMEVECTORVECTOR(v, "v"); + TRACE_DATETIMEVECTOR(x, "x"); +#endif + JulianPtrArray * vFlat = new JulianPtrArray(); + + if (v->GetSize() > 1) + { + if (x->GetSize() == 0) + { + intersectDateList(v, FALSE, x); + } + else + { + intersectDateList(v, FALSE, vFlat); + intersectOutList(x, vFlat); + } + } + else + { + // If no previous dates generated, just cat. + if (x->GetSize() == 0) + { + concat(v, x); + } + else + { + // Hours, Minutes, Seconds can be applied to a any date. + // That is why call replace. + // Day Of Week, Day Of Month, Day Of Year, Week Number + // cannot be applied to any date. Thus must intersect. + if (bSubGenerate) + { + // WORKS FOR BYHOUR, BYMINUTE, ELECTION DAYS FAIL + // replace on byhour, byminute, bysecond + //concat(v, x); + replace(v, x); + } + else + { + // FAILS FOR BYHOUR, BYMINUTE, ELECTION DAYS WORK + // intersect on bymonth, byday, bymonthday, byyearday, byweekno + // Have x. + concat(v, vFlat); + intersectOutList(x, vFlat); // ?? FAILS for BYHOUR, BYMINUTE + } + } + } +#if JULIAN_DEBUGGING_RECURRENCE + //if (FALSE) TRACE_DATETIMEVECTOR(vFlat, "vFlat"); + //if (FALSE) TRACE("After concat: x = "); + //if (FALSE) TRACE_DATETIMEVECTOR(x, "x"); +#endif + deleteDateTimeVector(vFlat); + delete vFlat; vFlat = 0; + } + deleteDateTimeVectorVector(v); // genDates deleted here as well + delete v; v = 0; + } + + // MUST sort before handling SETPOS + x->QuickSort(DateTime::CompareDateTimes); + + handleSetPos(x); + + // ADD newest created dates to overall dateVector + + if (x != 0 && x->GetSize() > 0) + { + t = *((DateTime*)x->GetAt(x->GetSize() - 1)); + + if (returnDateVector == 0) + { + returnDateVector = new JulianPtrArray(); PR_ASSERT(returnDateVector != 0); + } + for (i = 0; i < x->GetSize(); i++) + { + dt = (DateTime *) x->GetAt(i); + returnDateVector->Add(new DateTime(*dt)); + } + } + + if (m_iType == JulianUtility::RT_MONTHLY) + { + t_int32 interval = m_Interval->getMonth(); + while (interval > 0) + { + t.nextMonth(); + interval--; + } + } + else + { + PR_ASSERT(m_Interval != 0); + t.add(*m_Interval); + } + + reset(t, m_iType, m_iWkSt); + + deleteDateTimeVector(x); + delete x; x = 0; // delete x; + + lastInterval = m_iType; + + } + while (!done && (returnDateVector == 0 || returnDateVector->GetSize() < bound)); + cleanup(returnDateVector, bound, out, bAddStartDate); + if (returnDateVector != 0) + { + deleteDateTimeVector(returnDateVector); + delete returnDateVector; returnDateVector = 0; + } + //return; +} + +//--------------------------------------------------------------------- + +void +Recurrence::cleanup(JulianPtrArray * vDatesIn, t_int32 length, + JulianPtrArray * out, t_bool bAddStartDate) +{ + t_bool pushStart = FALSE; + t_int32 i; + t_int32 newLength = 0; + DateTime * dt; + t_int32 size = 0; + if (vDatesIn != 0) + { + size = vDatesIn->GetSize(); + } + if ((vDatesIn == 0 || size == 0) && bAddStartDate) + { + out->Add(new DateTime(m_StartDate)); + return; + } + dt = (DateTime *) vDatesIn->GetAt(0); + if (dt->afterDateTime(m_StartDate) || dt->beforeDateTime(m_StartDate)) + pushStart = TRUE; + + if (size < length) + { + newLength = size + (pushStart ? 1 : 0); + } + else + newLength = length; + + if ((size != length) || pushStart) + { + t_int32 startIndex = 0; + if (pushStart) + { + out->Add(new DateTime(m_StartDate)); + newLength = newLength - 1; + } + for (i = 0; i < newLength; i++) + { + dt = (DateTime *) vDatesIn->GetAt(i); + //if ((!m_Until.isValid()) || (!(dt->afterDateTime(m_Until)))) + //{ + out->Add(new DateTime(*dt)); + //} + } + } + else + { + for (i = 0; i < newLength; i++) + { + dt = (DateTime *) vDatesIn->GetAt(i); + //if ((!m_Until.isValid()) || (!(dt->afterDateTime(m_Until)))) + //{ + out->Add(new DateTime(*dt)); + //} + } + } +} + +//--------------------------------------------------------------------- + +void +Recurrence::reset(DateTime & t, t_int32 type, t_int32 wkSt) +{ + t_int32 temp = 0; + switch(type) + { + case JulianUtility::RT_YEARLY: + t.add(Calendar::DAY_OF_YEAR, -t.get(Calendar::DAY_OF_YEAR) + 1); + break; + case JulianUtility::RT_MONTHLY: + t.add(Calendar::DAY_OF_MONTH, -t.get(Calendar::DAY_OF_MONTH) + 1); + break; + case JulianUtility::RT_WEEKLY: + t.moveTo(wkSt, -1, FALSE); + break; + case JulianUtility::RT_DAILY: + + // this case is purposely empty. a daily rule can only contain a byhour, + // or a byminute tag. or it can have no tags. if it has a tag, then the + // assumed line: t.set(calendar.hour_of_day, 0); will be executed in the + // appropriate code. if it has no tags, then the reset() method will + // never be reached, since a defaultgenerator will be installed and will + //handle all of the work in one run. + break; + case JulianUtility::RT_HOURLY: + t.set(Calendar::MINUTE, 0); + break; + case JulianUtility::RT_MINUTELY: + t.set(Calendar::SECOND, 0); + break; + } + // a given rule either has or doesn't have a BYHOUR and/or BYMINUTE tag. + // if it doesn't, then the specific time in each recurrence is based entirely + // on the time provided in the startDate. if it does then either the hour + // or the minute is based on the parameter to the BYHOUR or BYMINUTE tag. + // thus, if the tags exist, we need to reset those values. in the case of + // the BYMINUTE tag, we must also reset the hourly value, but only if we + // are not in an hourly rule. confusing.. + + temp = ms_iByHourGntrIndex; + if (((DateGenerator *) (m_GntrVctr->GetAt(temp)))->active()) + { + t.set(Calendar::HOUR_OF_DAY, 0); + } + temp = ms_iByMinuteGntrIndex; + if (((DateGenerator *) (m_GntrVctr->GetAt(temp)))->active()) + { + if (type != JulianUtility::RT_HOURLY) + t.set(Calendar::HOUR_OF_DAY, 0); + t.set(Calendar::MINUTE, 0); + } +} + +//--------------------------------------------------------------------- + +void +Recurrence::handleSetPos(JulianPtrArray * vDates) +{ + // If no set pos, just return, leave vDates alone. + if (m_iBySetPosLen == 0) + return; + + t_int32 i; + DateTime * dt; + JulianPtrArray * vBySetPosDates; + t_int32 oldSize = vDates->GetSize(); + t_int32 temp = 0; + + if (vDates != 0 && oldSize > 0) + { + vBySetPosDates = new JulianPtrArray(); + + // First get the dates that satisfy the BYSETPOS tag. + for (i = 0; i < m_iBySetPosLen; i++) + { + if(m_aiBySetPos[i] == 0) + { + // An parse error should already have been thrown. + PR_ASSERT(FALSE); + break; + } + // NOTE: to handle HPUX compile problems with abs + temp = m_aiBySetPos[i]; + if (temp < 0) + temp = 0 - temp; + + // replacing this line with next line to avoid HPUX compile problems + //if(abs(m_aiBySetPos[i]) > oldSize) + if (temp > oldSize) + { + // No such element to add. + continue; + } + if (m_aiBySetPos[i] > 0) + { + temp = m_aiBySetPos[i] - 1; + dt = new DateTime( + *( (DateTime*)vDates->GetAt(temp))); + vBySetPosDates->Add(dt); + } + else + { + dt = new DateTime( + *( (DateTime *)vDates->GetAt(m_aiBySetPos[i] + oldSize))); + vBySetPosDates->Add(dt); + } + } + // delete elements from vDates + deleteDateTimeVector(vDates); + vDates->RemoveAll(); + + // copy elements from vBySetPosDates to vDates. + for (i = 0; i < vBySetPosDates->GetSize(); i++) + { + dt = (DateTime *) vBySetPosDates->GetAt(i); + vDates->Add(dt); + } + delete vBySetPosDates; vBySetPosDates = 0; + } +} + +//--------------------------------------------------------------------- + +t_int32 Recurrence::stringToDay(UnicodeString & s, t_bool & error) +{ + t_int32 i = (t_int32) Calendar::SUNDAY; + + if (s.size() == 0) + { + error = TRUE; + } + else + { + if (s == JulianKeyword::Instance()->ms_sSU) i = Calendar::SUNDAY; + else if (s == JulianKeyword::Instance()->ms_sMO) i = Calendar::MONDAY; + else if (s == JulianKeyword::Instance()->ms_sTU) i = Calendar::TUESDAY; + else if (s == JulianKeyword::Instance()->ms_sWE) i = Calendar::WEDNESDAY; + else if (s == JulianKeyword::Instance()->ms_sTH) i = Calendar::THURSDAY; + else if (s == JulianKeyword::Instance()->ms_sFR) i = Calendar::FRIDAY; + else if (s == JulianKeyword::Instance()->ms_sSA) i = Calendar::SATURDAY; + else + { + error = TRUE; + } + } + return i; +} + +//--------------------------------------------------------------------- + +void +Recurrence::parseDelimited(UnicodeString & us, UnicodeString & strDelim, + JulianPtrArray * vectorToFillIn) +{ + UnicodeStringTokenizer * st = new UnicodeStringTokenizer(us, strDelim); + PR_ASSERT(st != 0); + if (st != 0) + { + UnicodeString u; + ErrorCode status = ZERO_ERROR; + while (st->hasMoreTokens()) + { + u = st->nextToken(u, status); +#if JULIAN_DEBUGGING_RECURRENCE + //if (FALSE) TRACE("u = %s", u.toCString("")); +#endif + vectorToFillIn->Add(new UnicodeString(u)); + } + delete st; st = 0; + } +} +//--------------------------------------------------------------------- + +// replaces contents of vOut with contents of vvIn +void +Recurrence::replace(JulianPtrArray * vvIn, JulianPtrArray * vOut) +{ + deleteDateTimeVector(vOut); + vOut->RemoveAll(); + concat(vvIn, vOut); +} + +//--------------------------------------------------------------------- +/* concatenates a multidimensional array of dates into a single list */ +void +Recurrence::concat(JulianPtrArray * vvIn, JulianPtrArray * vOut) +{ + int i, j; + + JulianPtrArray * vvInIndex; + DateTime * dt; + if (vvIn != 0) + { + PR_ASSERT(vOut != 0); + if (vOut != 0) + { + for(i = 0; i < vvIn->GetSize(); i++) + { + vvInIndex = (JulianPtrArray *) vvIn->GetAt(i); + for (j = 0; j < vvInIndex->GetSize(); j++) + { + dt = (DateTime *) vvInIndex->GetAt(j); + vOut->Add(new DateTime(*dt)); + } + } + } + } +} +//--------------------------------------------------------------------- +void +Recurrence::intersectOutList(JulianPtrArray * vDatesOut, JulianPtrArray * vDatesIn) +{ + t_int32 i; + PR_ASSERT(vDatesOut != 0 && vDatesIn != 0); + DateTime * dt; + t_int32 oldSize = vDatesOut->GetSize(); + + for (i = oldSize - 1; i >= 0; i--) + { + dt = (DateTime *) vDatesOut->GetAt(i); + if (!contains(vDatesIn, dt)) + { + vDatesOut->RemoveAt(i); + delete dt; dt = 0; + } + } +} +//--------------------------------------------------------------------- +// todo: crash proof + /* subtracts or intersects datelists: + * + * subtract mode: subtracts lists 1..n from list 0 + * intersect mode: intersects lists 0..n + */ +void +Recurrence::intersectDateList(JulianPtrArray * vvDates, t_bool subtract, + JulianPtrArray * out) +{ + t_int32 i, j; + DateTime * bi; + PR_ASSERT(vvDates != 0 && out != 0); + PR_ASSERT(vvDates->GetSize() > 0); + + // remove all elements already in out vector + if (out->GetSize() != 0) + { + deleteDateTimeVector(out); + out->RemoveAll(); + } + + PR_ASSERT(out->GetSize() == 0); + JulianPtrArray * vvDatesIndex = ((JulianPtrArray *) vvDates->GetAt(0)); + + for (i = 0; i < vvDatesIndex->GetSize(); i++) + { + for (j = 1; j < vvDates->GetSize(); j++) + { + bi = (DateTime *)vvDatesIndex->GetAt(i); + if (contains((JulianPtrArray *)vvDates->GetAt(j), bi)) + { + if (!subtract) + out->Add(new DateTime(*bi)); + } + else if (subtract) + { + out->Add(new DateTime(*bi)); + } + } + } +} + +//--------------------------------------------------------------------- +// checks to see if date b is in date array a, currently masks out milliseconds when it compares + +t_bool +Recurrence::contains(JulianPtrArray * datetimes, DateTime * date) +{ + t_int32 i; + PR_ASSERT(datetimes != 0 && date != 0); + if (datetimes != 0 && date != 0) + { + DateTime * ai; + for (i = 0; i < datetimes->GetSize(); i++) + { + ai = (DateTime *) datetimes->GetAt(i); + + //if (ai != 0 && ((ai->getTime() - (ai->getTime() % 1000)) == + // date->getTime() - (date->getTime() % 1000))) + if (ai != 0 && + ((ai->getTime() / 1000.0) == (date->getTime() / 1000.0))) + { + return TRUE; + } + } + } + return FALSE; +} + +//--------------------------------------------------------------------- + + +t_int32 Recurrence::stringToType(UnicodeString & s, t_bool & bParseError) +{ + t_int32 iType; + + if (s.size() > 0) + { + if (s == JulianKeyword::Instance()->ms_sMINUTELY) iType = JulianUtility::RT_MINUTELY; + else if (s == JulianKeyword::Instance()->ms_sHOURLY) iType = JulianUtility::RT_HOURLY; + else if (s == JulianKeyword::Instance()->ms_sDAILY) iType = JulianUtility::RT_DAILY; + else if (s == JulianKeyword::Instance()->ms_sWEEKLY) iType = JulianUtility::RT_WEEKLY; + else if (s == JulianKeyword::Instance()->ms_sMONTHLY) iType = JulianUtility::RT_MONTHLY; + else if (s == JulianKeyword::Instance()->ms_sYEARLY) iType = JulianUtility::RT_YEARLY; + else bParseError = TRUE; + } + else + { + bParseError = TRUE; + } + return iType; +} + +//--------------------------------------------------------------------- +// TODO: crash proof +// bZero, allow zero to pass or not? +t_int32 * +Recurrence::verifyIntList(JulianPtrArray * v, t_int32 lowerBound, + t_int32 upperBound, UnicodeString & error, + t_int32 & retSize, t_bool & bParseError, + t_bool bZero) +{ + UnicodeString s, into; + t_int32 * i = new t_int32[v->GetSize()]; + t_int32 j; + t_int32 k; + retSize = 0; + t_int8 bMinusOrPlus = 0; + t_int32 startIndex = 0; + + // NOTE: to remove compiler warning + if (error.size() > 0) {} + + PR_ASSERT(v != 0); + for (j = 0; j < v->GetSize(); j++) + { + s = *((UnicodeString *) v->GetAt(j)); + startIndex = 0; + bMinusOrPlus = 0; + // If minus or plus in front, remove before extracting number + if (s[(TextOffset)0] == '-') + { + bMinusOrPlus = -1; + startIndex = 1; + } + else if (s[(TextOffset)0] == '+') + { + bMinusOrPlus = 1; + startIndex = 1; + } + char * kcc = s.extractBetween(startIndex, s.size(), into).toCString(""); + PR_ASSERT(kcc != 0); + k = JulianUtility::atot_int32(kcc, + bParseError, (s.size() - startIndex)); + delete [] kcc; kcc = 0; + + // if Minus sign, set to inverse + if (bMinusOrPlus < 0) + { + k = 0 - k; + } + //k = JulianUtility::atot_int32(s.toCString(""), bParseError, s.size()); + + if (bZero && k == 0) + bParseError = TRUE; + if ((k <= upperBound) && (k >= lowerBound)) + { + i[j] = k; + retSize++; + } + else + { + // TODO: log and error + bParseError = TRUE; + } + } + + // TODO: remove duplicates and sort int list HERE + + return i; +} + +//--------------------------------------------------------------------- +// TODO: crash proof +RRDay * +Recurrence::createByDayList(JulianPtrArray * v, t_int32 type, + t_int32 & retSize, + t_bool & bParseError) +{ + t_int32 i; + t_int32 day, modifier; + PR_ASSERT(v != 0); + + RRDay * l = new RRDay[v->GetSize()]; + UnicodeString * sPtr; + retSize = v->GetSize(); + + for (i = 0; i < v->GetSize(); i++) + { + sPtr = (UnicodeString *) v->GetAt(i); + + // get the day and modifier from the string + createByDayListHelper(*sPtr, day, modifier, bParseError); + + // if modifier out of bounds, set bParseError to TRUE + if ((type == JulianUtility::RT_YEARLY) && + (modifier < -53 || modifier > 53)) + { + bParseError = TRUE; + } + else if ((type == JulianUtility::RT_MONTHLY) && + (modifier < -5 || modifier > 5)) + { + bParseError = TRUE; + } + l[i].fields[0] = day; + l[i].fields[1] = modifier; + } + return l; +} +//--------------------------------------------------------------------- +void Recurrence::createByDayListHelper(UnicodeString & in, + t_int32 & day, + t_int32 & modifier, + t_bool & bParseError) +{ + if (in.size() < 2) + bParseError = TRUE; + else + { + t_int8 bMinusOrPlus = 0, startIndex = 0; + UnicodeString into; + into = in.extractBetween(in.size() - 2, in.size(), into); + day = stringToDay(into, bParseError); + if (in.size() > 2) + { + // If minus or plus in front, remove before extracting number + if (in[(TextOffset)0] == '-') + { + bMinusOrPlus = -1; + startIndex = 1; + } + else if (in[(TextOffset)0] == '+') + { + bMinusOrPlus = 1; + startIndex = 1; + } + + char * incc = in.extractBetween(startIndex, + in.size() - 2, into).toCString(""); + PR_ASSERT(incc != 0); + modifier = + JulianUtility::atot_int32(incc, + bParseError, (in.size() - 2 - startIndex)); + delete [] incc; incc = 0; + // if Minus sign, set to inverse + if (bMinusOrPlus < 0) + { + modifier = 0 - modifier; + } + } + else + { + modifier = 0; + } + } +} +//--------------------------------------------------------------------- + +void Recurrence::eliminateDuplicates(JulianPtrArray * datetimes) +{ + t_int32 i; + if (datetimes != 0) + { + // NOTE: Order NlogN + N, (sort, then compare consective elements) + datetimes->QuickSort(DateTime::CompareDateTimes); + t_int32 size = datetimes->GetSize(); + DateTime * dt, * dt2; + + for (i = size - 1; i >= 1; i--) + { + dt = (DateTime *) datetimes->GetAt(i); + dt2 = (DateTime *) datetimes->GetAt(i - 1); + if (dt->equalsDateTime(*dt2)) + { + delete dt; dt = 0; + datetimes->RemoveAt(i); + } + } + } +} + +//--------------------------------------------------------------------- +void Recurrence::deleteUnicodeStringVector(JulianPtrArray * strings) +{ + t_int32 i; + if (strings != 0) + { + for (i = strings->GetSize() - 1; i >= 0; i--) + { + delete ((UnicodeString *)strings->GetAt(i)); + } + } +} +//--------------------------------------------------------------------- +void Recurrence::deleteDateTimeVector(JulianPtrArray * datetimes) +{ + t_int32 i; + if (datetimes != 0) + { + for (i = datetimes->GetSize() - 1; i >= 0; i--) + { + delete ((DateTime *)datetimes->GetAt(i)); + } + } +} +//--------------------------------------------------------------------- +void Recurrence::deleteRecurrenceVector(JulianPtrArray * recurrences) +{ + t_int32 i; + if (recurrences != 0) + { + for (i = recurrences->GetSize() - 1; i >= 0; i--) + { + delete ((Recurrence *)recurrences->GetAt(i)); + } + } +} +//--------------------------------------------------------------------- +void +Recurrence::deleteICalParameterVector(JulianPtrArray * parameters) +{ + ICalParameter * ip; + t_int32 i; + if (parameters != 0) + { + for (i = parameters->GetSize() - 1; i >= 0; i--) + { + ip = (ICalParameter *) parameters->GetAt(i); + delete ip; ip = 0; + } + } +} +//--------------------------------------------------------------------- +void Recurrence::deleteDateTimeVectorVector(JulianPtrArray * vDateTimes) +{ + t_int32 i; + JulianPtrArray * xp; + if (vDateTimes != 0) + { + for (i = vDateTimes->GetSize() - 1; i >= 0; i--) + { + xp = (JulianPtrArray *) vDateTimes->GetAt(i); + deleteDateTimeVector(xp); + xp->RemoveAll(); + delete xp; xp = 0; + } + } +} +//--------------------------------------------------------------------- +#if 0 +void +Recurrence::copyDateTimesInto(JulianPtrArray * from, + DateTime * to) +{ + t_int32 i; + PR_ASSERT(to != 0 && from != 0); + DateTime d; + for (i = 0; i < from->GetSize(); i++) + { + d = *((DateTime *) from->GetAt(i)); + to[i] = d; + } +} +#endif +//--------------------------------------------------------------------- + diff --git a/calendar/modules/core/ical/src/recid.cpp b/calendar/modules/core/ical/src/recid.cpp new file mode 100644 index 00000000000..f8c3406366f --- /dev/null +++ b/calendar/modules/core/ical/src/recid.cpp @@ -0,0 +1,260 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +// recid.cpp +// John Sun +// 3/20/98 5:18:34 PM + +#include "stdafx.h" +#include "jdefines.h" +#include "recid.h" +#include "keyword.h" +#include "jlog.h" +//--------------------------------------------------------------------- + +// private never use +#if 0 +JulianRecurrenceID::JulianRecurrenceID() +{ + PR_ASSERT(FALSE); +} +#endif +//--------------------------------------------------------------------- + +JulianRecurrenceID::JulianRecurrenceID(JLog * initLog) +: m_DateTime(-1), m_Range(JulianRecurrenceID::RANGE_NONE), + m_Log(initLog) +{ + //PR_ASSERT(initLog != 0); +} + +//--------------------------------------------------------------------- + +JulianRecurrenceID::JulianRecurrenceID(JulianRecurrenceID & that) +: m_Range(that.m_Range) +{ + m_DateTime = that.m_DateTime; +} + +//--------------------------------------------------------------------- + +JulianRecurrenceID::JulianRecurrenceID(DateTime datetime, + JLog * initLog, + RANGE range) + +: m_Range(range), m_Log(initLog) +{ + m_DateTime = datetime; + //PR_ASSERT(initLog != 0); +} + +//--------------------------------------------------------------------- + +JulianRecurrenceID::~JulianRecurrenceID() {} + +//--------------------------------------------------------------------- + +ICalProperty * JulianRecurrenceID::clone(JLog * initLog) +{ + m_Log = initLog; + //PR_ASSERT(m_Log != 0); + return new JulianRecurrenceID(*this); +} + +//--------------------------------------------------------------------- + +void JulianRecurrenceID::setParameters(JulianPtrArray * parameters) +{ + t_int32 i; + ICalParameter * ip; + UnicodeString pName; + UnicodeString pVal; + if (parameters != 0) + { + for (i = 0; i < parameters->GetSize(); i++) + { + ip = (ICalParameter *) parameters->GetAt(i); + setParam(ip->getParameterName(pName), ip->getParameterValue(pVal)); + } + } +} + +//--------------------------------------------------------------------- + +void JulianRecurrenceID::setParam(UnicodeString & paramName, UnicodeString & paramVal) +{ + t_int32 i; + if (paramName.size() == 0) + { + if (m_Log) m_Log->logError(JulianLogErrorMessage::Instance()->ms_iInvalidParameterName, + JulianKeyword::Instance()->ms_sRECURRENCEID, paramName, 200); + } + else + { + t_int32 hashCode = paramName.hashCode(); + + if (JulianKeyword::Instance()->ms_ATOM_RANGE == hashCode) + { + i = JulianRecurrenceID::stringToRange(paramVal); + if (i < 0) + { + if (m_Log) m_Log->logError(JulianLogErrorMessage::Instance()->ms_iInvalidParameterValue, + JulianKeyword::Instance()->ms_sRECURRENCEID, paramName, paramVal, 200); + } + else + { + if (getRange() >= 0) + { + if (m_Log) m_Log->logError(JulianLogErrorMessage::Instance()->ms_iDuplicatedParameter, + JulianKeyword::Instance()->ms_sRECURRENCEID, paramName, 100); + } + setRange((JulianRecurrenceID::RANGE) i); + } + } + else if (ICalProperty::IsXToken(paramName)) + { + if (m_Log) m_Log->logError(JulianLogErrorMessage::Instance()->ms_iXTokenParamIgnored, + JulianKeyword::Instance()->ms_sRECURRENCEID, paramName, 100); + } + else + { + // NOTE: what about optional parameters?? THERE ARE NONE. + if (m_Log) m_Log->logError(JulianLogErrorMessage::Instance()->ms_iInvalidParameterName, + JulianKeyword::Instance()->ms_sRECURRENCEID, paramName, 200); + } + } +} + +//--------------------------------------------------------------------- + +t_bool JulianRecurrenceID::isValid() +{ + return m_DateTime.isValid(); +} + +//--------------------------------------------------------------------- + +UnicodeString & +JulianRecurrenceID::toString(UnicodeString & strFmt, UnicodeString & out) +{ + // NOTE: Remove later + if (strFmt.size() > 0) {} + + return toString(out); +} + +//--------------------------------------------------------------------- + +void +JulianRecurrenceID::setValue(void * value) +{ + PR_ASSERT(value != 0); + if (value != 0) + { + setDateTime(*((DateTime *) value)); + } +} + +//--------------------------------------------------------------------- + +void * +JulianRecurrenceID::getValue() const +{ + return (void *) &m_DateTime; +} + +//--------------------------------------------------------------------- + +UnicodeString & +JulianRecurrenceID::toString(UnicodeString & out) +{ + UnicodeString u; + out = ""; + out += JulianKeyword::Instance()->ms_sRANGE; + out += JulianKeyword::Instance()->ms_sCOLON_SYMBOL; + out += rangeToString(m_Range, u); + out += JulianKeyword::Instance()->ms_sDATE; + out += JulianKeyword::Instance()->ms_sCOLON_SYMBOL; + out += m_DateTime.toISO8601(); + return out; +} + +//--------------------------------------------------------------------- + +UnicodeString & +JulianRecurrenceID::toICALString(UnicodeString & sProp, UnicodeString & out) +{ + out = ""; + out += sProp; + if (m_Range != JulianRecurrenceID::RANGE_NONE) + { + UnicodeString u; + out += ';'; + out += JulianKeyword::Instance()->ms_sRANGE; + out += '='; + out += rangeToString(m_Range, u); + } + out += ':'; + out += m_DateTime.toISO8601(); + out += JulianKeyword::Instance()->ms_sLINEBREAK; + return out; +} + +//--------------------------------------------------------------------- + +UnicodeString & +JulianRecurrenceID::toICALString(UnicodeString & out) +{ + UnicodeString u; + return toICALString(u, out); +} + +//--------------------------------------------------------------------- + +JulianRecurrenceID::RANGE +JulianRecurrenceID::stringToRange(UnicodeString & sRange) +{ + t_int32 hashCode = sRange.hashCode(); + + if (JulianKeyword::Instance()->ms_ATOM_THISANDPRIOR == hashCode) + return RANGE_THISANDPRIOR; + else if (JulianKeyword::Instance()->ms_ATOM_THISANDFUTURE == hashCode) + return RANGE_THISANDFUTURE; + else return RANGE_NONE; +} + +//--------------------------------------------------------------------- + +UnicodeString & +JulianRecurrenceID::rangeToString(JulianRecurrenceID::RANGE range, + UnicodeString & out) +{ + out = ""; + switch(range) + { + case RANGE_THISANDPRIOR: out = JulianKeyword::Instance()->ms_sTHISANDPRIOR; break; + case RANGE_THISANDFUTURE: out = JulianKeyword::Instance()->ms_sTHISANDFUTURE; break; + default: + // NONE case + out = ""; + } + return out; +} + +//--------------------------------------------------------------------- + diff --git a/calendar/modules/core/ical/src/rrday.cpp b/calendar/modules/core/ical/src/rrday.cpp new file mode 100644 index 00000000000..1dd33deb030 --- /dev/null +++ b/calendar/modules/core/ical/src/rrday.cpp @@ -0,0 +1,81 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +// rrday.cpp +// John Sun +// 7:54 PM February 4 1998 + +#include "stdafx.h" +#include "jdefines.h" + +#include +#include "rrday.h" + +//--------------------------------------------------------------------- + +RRDay::RRDay() +{ + fields[0] = 0; + fields[1] = 0; +} + +//--------------------------------------------------------------------- + +RRDay::RRDay(t_int32 aDay, t_int32 aModifier) +{ + fields[0] = aDay; + fields[1] = aModifier; +} + +//--------------------------------------------------------------------- + +t_int32 RRDay::operator[](t_int32 index) const +{ + PR_ASSERT(index >= 0 && index < 2); + // Pin args in index is invalid + if (index < 0) + index = 0; + else if (index > 1) + index = 1; + + return fields[index]; +} + +//--------------------------------------------------------------------- + +void RRDay::operator=(RRDay & that) +{ + fields[0] = that.fields[0]; + fields[1] = that.fields[1]; +} + +//--------------------------------------------------------------------- + +t_bool RRDay::operator==(RRDay & that) +{ + return (fields[0] == that.fields[0]) && (fields[1] == that.fields[1]); +} + +//--------------------------------------------------------------------- + +t_bool RRDay::operator!=(RRDay & that) +{ + return (fields[0] != that.fields[0]) || (fields[1] != that.fields[1]); +} +//--------------------------------------------------------------------- + diff --git a/calendar/modules/core/ical/src/sdprprty.cpp b/calendar/modules/core/ical/src/sdprprty.cpp new file mode 100644 index 00000000000..0254160841b --- /dev/null +++ b/calendar/modules/core/ical/src/sdprprty.cpp @@ -0,0 +1,184 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +// sdprprty.cpp +// John Sun +// 4:11 PM February 10 1998 + +#include "stdafx.h" +#include "jdefines.h" + +#include "jlog.h" +#include "sdprprty.h" +#include "keyword.h" +#include + +//--------------------------------------------------------------------- +StandardProperty::StandardProperty() +: m_vParameters(0) +{ +} +//--------------------------------------------------------------------- +StandardProperty::StandardProperty(JulianPtrArray * parameters) +: m_vParameters(0) +{ + setParameters(parameters); +} +//--------------------------------------------------------------------- +StandardProperty::~StandardProperty() +{ + if (m_vParameters != 0) + { + ICalProperty::deleteICalParameterVector(m_vParameters); + delete m_vParameters; m_vParameters = 0; + } +} +//--------------------------------------------------------------------- +UnicodeString & +StandardProperty::getParameterValue(UnicodeString & paramName, + UnicodeString & paramValue, + ErrorCode & status) +{ + t_int32 i; + ICalParameter * param; + UnicodeString into; + status = ZERO_ERROR; + if (m_vParameters == 0) + { + status = 1; + paramValue = ""; + return paramValue; + } + else + { + for (i = 0; i < m_vParameters->GetSize(); i++) + { + param = (ICalParameter *) m_vParameters->GetAt(i); + if (param->getParameterName(into).compareIgnoreCase(paramName) == 0) + { + // a match + paramValue = param->getParameterValue(into); + return paramValue; + } + } + status = 2; + paramValue = ""; + return paramValue; + } +} +//--------------------------------------------------------------------- + +void StandardProperty::addParameter(ICalParameter * aParameter) +{ + // TODO: check for duplicates? + m_vParameters->Add(aParameter); +} +//--------------------------------------------------------------------- + +void StandardProperty::parse(UnicodeString & in) +{ +#if 0 + UnicodeString name, value; + + if (m_vParameters != 0) { + ICalProperty::deleteICalParameterVector(m_vParameters); + delete m_vParameters; + } + m_vParameters = 0; + + JulianPtrArray * parameters = new JulianPtrArray(); + PR_ASSERT(parameters != 0); + if (parameters != 0) + { + // parse in a a line, it will fill in vector + parsePropertyLine(in, name, value, parameters); + + // TODO: fix. need to cast value to correct type, but I + // can't find out type here. + setValue((void *) m_vParameters->GetAt(1)); + setParameters(parameters); + + ICalProperty::deleteICalParameterVector(parameters); + delete parameters; parameters = 0; + } +#else + // don't use for now + PR_ASSERT(FALSE); +#endif /* #if 0 */ +} +//--------------------------------------------------------------------- + +void StandardProperty::setParameters(JulianPtrArray * parameters) +{ + if (m_vParameters != 0) + { + ICalProperty::deleteICalParameterVector(m_vParameters); + delete m_vParameters; m_vParameters = 0; + } + + // NOTE: I am making a copy of the parameters + // I am not storing the ptr. + if (parameters != 0) + { + t_int32 i; + ICalParameter * ip, * ip2; + m_vParameters = new JulianPtrArray(); + PR_ASSERT(m_vParameters != 0); + if (m_vParameters != 0) + { + for (i = 0; i < parameters->GetSize(); i++) + { + ip = (ICalParameter *) parameters->GetAt(i); + PR_ASSERT(ip != 0); + if (ip != 0) + { + ip2 = ip->clone(); + PR_ASSERT(ip2 != 0); + if (ip2 != 0) + { + m_vParameters->Add(ip2); + } + } + } + } + } +} + +//--------------------------------------------------------------------- + +UnicodeString & +StandardProperty::toICALString(UnicodeString & out) +{ + UnicodeString u, name; + u = toExportString(u); + return propertyToICALString(name, u, m_vParameters, out); +} + +//--------------------------------------------------------------------- + +UnicodeString & +StandardProperty::toICALString(UnicodeString & sProp, + UnicodeString & out) +{ + UnicodeString u; + u = toExportString(u); + return propertyToICALString(sProp, u, m_vParameters, out); +} + +//--------------------------------------------------------------------- + diff --git a/calendar/modules/core/ical/src/sprpty.cpp b/calendar/modules/core/ical/src/sprpty.cpp new file mode 100644 index 00000000000..4d0409ee2ae --- /dev/null +++ b/calendar/modules/core/ical/src/sprpty.cpp @@ -0,0 +1,129 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +// sprprty.cpp +// John Sun +// 5:10 PM February 10 1998 + +#include "stdafx.h" +#include "jdefines.h" + +#include "sprprty.h" + +//--------------------------------------------------------------------- + +// private never use +StringProperty::StringProperty() +{ + PR_ASSERT(FALSE); +} + +//--------------------------------------------------------------------- + +StringProperty::StringProperty(const StringProperty & that) +{ + setParameters(that.m_vParameters); + m_string = that.m_string; +} + +//--------------------------------------------------------------------- + +//StringProperty::StringProperty(UnicodeString * value, JulianPtrArray * parameters) +StringProperty::StringProperty(UnicodeString value, JulianPtrArray * parameters) +: StandardProperty(parameters) +{ + //PR_ASSERT(value != 0); + //m_string = *((UnicodeString *) value); + m_string = value; +} + +//--------------------------------------------------------------------- + +StringProperty::~StringProperty() +{ + //delete m_string; + ////deleteICalParameterVector(m_vParameters); + ////delete m_vParameters; m_vParameters = 0; +} + +//--------------------------------------------------------------------- + +void * StringProperty::getValue() const +{ + //return (void *) m_string; + return (void *) &m_string; +} + +//--------------------------------------------------------------------- + +void StringProperty::setValue(void * value) +{ + PR_ASSERT(value != 0); + //if (m_string != 0) { delete m_string; m_string = 0; } + //m_string = ((UnicodeString *) value); + if (value != 0) + { + m_string = *(UnicodeString *) value; + } +} + +//--------------------------------------------------------------------- + +ICalProperty * StringProperty::clone(JLog * initLog) +{ + // NOTE: Remove later to avoid warnings + if (initLog) {} + return new StringProperty(*this); +} + +//--------------------------------------------------------------------- + +t_bool StringProperty::isValid() +{ + return TRUE; +} + +//--------------------------------------------------------------------- + +UnicodeString & StringProperty::toString(UnicodeString & out) +{ + //PR_ASSERT(m_string != 0); + //out = *m_string; + out = m_string; + return out; +} + +//--------------------------------------------------------------------- + +UnicodeString & +StringProperty::toString(UnicodeString & dateFmt, UnicodeString & out) +{ + // NOTE: remove it later, gets rid of compiler warning + if (dateFmt.size() > 0) {} + return toString(out); +} + +//--------------------------------------------------------------------- + +UnicodeString & StringProperty::toExportString(UnicodeString & out) +{ + return toString(out); +} +//--------------------------------------------------------------------- + + diff --git a/calendar/modules/core/ical/src/tmbevent.cpp b/calendar/modules/core/ical/src/tmbevent.cpp new file mode 100644 index 00000000000..af35f324f1c --- /dev/null +++ b/calendar/modules/core/ical/src/tmbevent.cpp @@ -0,0 +1,3246 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +// tmbevent.cpp +// John Sun +// 3:21 PM February 6 1998 + +#define TIMING 1 + +#include "stdafx.h" +#include "jdefines.h" + +#include "icalcomp.h" +#include "tmbevent.h" +#include "attendee.h" +#include "jutility.h" +#include "prprty.h" +#include "prprtyfy.h" +#include "unistrto.h" +#include "jlog.h" +#include "vtimezne.h" +#include "keyword.h" + +#include "rcrrence.h" +#include "period.h" +#include "sprprty.h" +#include "recid.h" +#include "orgnzr.h" +#include "valarm.h" + +#include "functbl.h" +//--------------------------------------------------------------------- + +t_int32 TimeBasedEvent::ms_iBound = 60; + +//--------------------------------------------------------------------- + +// private never use +#if 0 +TimeBasedEvent::TimeBasedEvent() +{ + PR_ASSERT(FALSE); +} +#endif + +//--------------------------------------------------------------------- + +TimeBasedEvent::TimeBasedEvent(JLog * initLog) +: m_bAllDayEvent(FALSE), + m_AlarmsVctr(0), m_AttachVctr(0), m_AttendeesVctr(0), + m_CategoriesVctr(0), m_CommentVctr(0), m_Created(0), m_DTStart(0), + m_DTStamp(0), m_ExDateVctr(0), m_ExRuleVctr(0), + m_LastModified(0), m_RDateVctr(0), m_RRuleVctr(0), + m_RecurrenceID(0), + m_RelatedToVctr(0), + m_Sequence(0), m_ContactVctr(0), m_XTokensVctr(0), + m_Description(0), m_Class(0), m_URL(0), m_Summary(0), m_Status(0), + m_RequestStatusVctr(0), m_UID(0), m_Organizer(0), + m_Log(initLog) +{ +} + +//--------------------------------------------------------------------- + +TimeBasedEvent::TimeBasedEvent(TimeBasedEvent & that) +: m_bAllDayEvent(FALSE), + m_AlarmsVctr(0), m_AttachVctr(0), m_AttendeesVctr(0), + m_CategoriesVctr(0), m_CommentVctr(0), m_Created(0), m_DTStart(0), + m_DTStamp(0), m_ExDateVctr(0), m_ExRuleVctr(0), + m_LastModified(0), m_RDateVctr(0), m_RRuleVctr(0), + m_RecurrenceID(0), + m_RelatedToVctr(0), + m_Sequence(0), m_ContactVctr(0), m_XTokensVctr(0), + m_Description(0), m_Class(0), m_URL(0), m_Summary(0), m_Status(0), + m_RequestStatusVctr(0), m_UID(0), m_Organizer(0) +{ + m_sMethod = that.m_sMethod; + m_sFileName = that.m_sFileName; + m_origDTStart = that.m_origDTStart; + m_origMyDTStart = that.m_origMyDTStart; + m_bAllDayEvent = that.m_bAllDayEvent; + + if (that.m_AlarmsVctr != 0) + { + m_AlarmsVctr = new JulianPtrArray(); PR_ASSERT(m_AlarmsVctr != 0); + if (m_AlarmsVctr != 0) + { + ICalComponent::cloneICalComponentVector(m_AlarmsVctr, that.m_AlarmsVctr); + } + } + + // copy properties + if (that.m_AttachVctr != 0) + { + m_AttachVctr = new JulianPtrArray(); PR_ASSERT(m_AttachVctr != 0); + if (m_AttachVctr != 0) + { + ICalProperty::CloneICalPropertyVector(that.m_AttachVctr, m_AttachVctr, m_Log); + } + } + if (that.m_AttendeesVctr != 0) + { + m_AttendeesVctr = new JulianPtrArray(); PR_ASSERT(m_AttendeesVctr != 0); + if (m_AttendeesVctr != 0) + { + ICalProperty::CloneICalPropertyVector(that.m_AttendeesVctr, m_AttendeesVctr, m_Log); + } + } + if (that.m_CategoriesVctr != 0) + { + m_CategoriesVctr = new JulianPtrArray(); PR_ASSERT(m_CategoriesVctr != 0); + if (m_CategoriesVctr != 0) + { + ICalProperty::CloneICalPropertyVector(that.m_CategoriesVctr, m_CategoriesVctr, m_Log); + } + } + if (that.m_Class != 0) { m_Class = that.m_Class->clone(m_Log); } + + if (that.m_CommentVctr != 0) + { + m_CommentVctr = new JulianPtrArray(); PR_ASSERT(m_CommentVctr != 0); + if (m_CommentVctr != 0) + { + ICalProperty::CloneICalPropertyVector(that.m_CommentVctr, m_CommentVctr, m_Log); + } + } + if (that.m_ContactVctr != 0) + { + m_ContactVctr = new JulianPtrArray(); PR_ASSERT(m_ContactVctr != 0); + if (m_ContactVctr != 0) + { + ICalProperty::CloneICalPropertyVector(that.m_ContactVctr, m_ContactVctr, m_Log); + } + } + if (that.m_Created != 0) + { + m_Created = that.m_Created->clone(m_Log); + } + if (that.m_Description != 0) + { + m_Description = that.m_Description->clone(m_Log); + } + if (that.m_DTStart != 0) + { + m_DTStart = that.m_DTStart->clone(m_Log); + } + if (that.m_DTStamp != 0) + { + m_DTStamp = that.m_DTStamp->clone(m_Log); + } + + if (that.m_ExDateVctr != 0) + { + m_ExDateVctr = new JulianPtrArray(); PR_ASSERT(m_ExDateVctr != 0); + if (m_ExDateVctr != 0) + { + ICalProperty::CloneICalPropertyVector(that.m_ExDateVctr, m_ExDateVctr, m_Log); + } + } + if (that.m_ExRuleVctr != 0) + { + m_ExRuleVctr = new JulianPtrArray(); PR_ASSERT(m_ExRuleVctr != 0); + if (m_ExRuleVctr != 0) + { + // note: unicodestring vector not ICALPropertyVector + ICalProperty::CloneUnicodeStringVector(that.m_ExRuleVctr, m_ExRuleVctr); + } + } + + if (that.m_LastModified != 0) + { + m_LastModified = that.m_LastModified->clone(m_Log); + } + if (that.m_Organizer != 0) + { + m_Organizer = that.m_Organizer->clone(m_Log); + } + if (that.m_RecurrenceID != 0) + { + m_RecurrenceID = that.m_RecurrenceID->clone(m_Log); + } + + if (that.m_RDateVctr != 0) + { + m_RDateVctr = new JulianPtrArray(); PR_ASSERT(m_RDateVctr != 0); + if (m_RDateVctr != 0) + { + ICalProperty::CloneICalPropertyVector(that.m_RDateVctr, m_RDateVctr, m_Log); + } + } + if (that.m_RRuleVctr != 0) + { + m_RRuleVctr = new JulianPtrArray(); PR_ASSERT(m_RRuleVctr != 0); + if (m_RRuleVctr != 0) + { + // note: unicodestring vector not ICALPropertyVector + ICalProperty::CloneUnicodeStringVector(that.m_RRuleVctr, m_RRuleVctr); + } + } + if (that.m_RelatedToVctr != 0) + { + m_RelatedToVctr = new JulianPtrArray(); PR_ASSERT(m_RelatedToVctr != 0); + if (m_RelatedToVctr != 0) + { + ICalProperty::CloneICalPropertyVector(that.m_RelatedToVctr, m_RelatedToVctr, m_Log); + } + } + + if (that.m_RequestStatusVctr != 0) + { + m_RequestStatusVctr = new JulianPtrArray(); PR_ASSERT(m_RequestStatusVctr != 0); + if (m_RequestStatusVctr != 0) + { + ICalProperty::CloneICalPropertyVector(that.m_RequestStatusVctr, m_RequestStatusVctr, m_Log); + } + } + if (that.m_Sequence != 0) + { + m_Sequence = that.m_Sequence->clone(m_Log); + } + if (that.m_Status != 0) + { + m_Status = that.m_Status->clone(m_Log); + } + if (that.m_Summary != 0) + { + m_Summary = that.m_Summary->clone(m_Log); + } + if (that.m_UID != 0) + { + m_UID = that.m_UID->clone(m_Log); + } + if (that.m_URL != 0) + { + m_URL = that.m_URL->clone(m_Log); + } + + if (that.m_XTokensVctr != 0) + { + m_XTokensVctr = new JulianPtrArray(); PR_ASSERT(m_XTokensVctr != 0); + if (m_XTokensVctr != 0) + { + ICalProperty::CloneUnicodeStringVector(that.m_XTokensVctr, m_XTokensVctr); + } + } +} +//--------------------------------------------------------------------- + +TimeBasedEvent::~TimeBasedEvent() +{ + if (m_AlarmsVctr != 0) + { + ICalComponent::deleteICalComponentVector(m_AlarmsVctr); + delete m_AlarmsVctr; m_AlarmsVctr = 0; + } + + // datetime properties + if (m_Created != 0) + { + delete m_Created; m_Created = 0; + } + if (m_DTStart != 0) + { + delete m_DTStart; m_DTStart = 0; + } + if (m_DTStamp != 0) + { + delete m_DTStamp; m_DTStamp = 0; + } + if (m_LastModified != 0) + { + delete m_LastModified; m_LastModified = 0; + } + + // string properties + if (m_Description != 0) + { + delete m_Description; m_Description = 0; + } + if (m_Class != 0) + { + delete m_Class ; m_Class = 0; + } + if (m_Summary != 0) + { + delete m_Summary; m_Summary = 0; + } + if (m_Status != 0) + { + delete m_Status; m_Status = 0; + } + if (m_RequestStatusVctr != 0) + { + //delete m_RequestStatus; m_RequestStatus = 0; + ICalProperty::deleteICalPropertyVector(m_RequestStatusVctr); + delete m_RequestStatusVctr; m_RequestStatusVctr = 0; + } + + if (m_UID != 0) + { + delete m_UID; m_UID = 0; + } + if (m_URL != 0) + { + delete m_URL; m_URL = 0; + } + if (m_Organizer != 0) + { + delete m_Organizer; m_Organizer = 0; + } + if (m_RecurrenceID != 0) + { + delete m_RecurrenceID ; m_RecurrenceID = 0; + } + + // integer properties + if (m_Sequence != 0) + { + delete m_Sequence; m_Sequence = 0; + } + + // attendees + if (m_AttendeesVctr != 0) + { + ICalProperty::deleteICalPropertyVector(m_AttendeesVctr); + delete m_AttendeesVctr; m_AttendeesVctr = 0; + } + + // string vectors + if (m_AttachVctr != 0) + { + ICalProperty::deleteICalPropertyVector(m_AttachVctr); + delete m_AttachVctr; m_AttachVctr = 0; + } + if (m_CategoriesVctr != 0) + { + ICalProperty::deleteICalPropertyVector(m_CategoriesVctr); + delete m_CategoriesVctr; m_CategoriesVctr = 0; + } + if (m_CommentVctr != 0) + { + ICalProperty::deleteICalPropertyVector(m_CommentVctr); + delete m_CommentVctr; m_CommentVctr = 0; + } + if (m_ExDateVctr != 0) + { + ICalProperty::deleteICalPropertyVector(m_ExDateVctr); + delete m_ExDateVctr; m_ExDateVctr = 0; + } + if (m_ExRuleVctr != 0) + { + ICalComponent::deleteUnicodeStringVector(m_ExRuleVctr); + delete m_ExRuleVctr; m_ExRuleVctr = 0; + } + if (m_RDateVctr != 0) + { + ICalProperty::deleteICalPropertyVector(m_RDateVctr); + delete m_RDateVctr; m_RDateVctr = 0; + } + if (m_RRuleVctr != 0) + { + ICalComponent::deleteUnicodeStringVector(m_RRuleVctr); + delete m_RRuleVctr; m_RRuleVctr = 0; + } + if (m_RelatedToVctr != 0) + { + ICalProperty::deleteICalPropertyVector(m_RelatedToVctr); + delete m_RelatedToVctr; m_RelatedToVctr = 0; + } + if (m_ContactVctr != 0) + { + ICalProperty::deleteICalPropertyVector(m_ContactVctr); + delete m_ContactVctr; m_ContactVctr = 0; + } + if (m_XTokensVctr != 0) + { + ICalComponent::deleteUnicodeStringVector(m_XTokensVctr); + delete m_XTokensVctr; m_XTokensVctr = 0; + } +} + +//--------------------------------------------------------------------- + + +UnicodeString +TimeBasedEvent::toStringChar(t_int32 c, UnicodeString & dateFmt) +{ + JulianPtrArray * v = 0; + UnicodeString s; + + // TODO: handle x-tokens + // exdate, exrules, rdates, rrules + + switch ( c ) + { + + case ms_cAlarms: + v = getAlarms(); + if (v != 0) + { + VAlarm * va = 0; + t_int32 i; + for (i = 0; i < v->GetSize(); i++) + { + va = (VAlarm *) v->GetAt(i); + s += va->toString(); + } + } + return s; + case ms_cAttach: + return ICalProperty::propertyVectorToString(getAttach(), dateFmt, s); + case ms_cAttendees: + return ICalProperty::propertyVectorToString(getAttendees(), dateFmt, s); + case ms_cCategories: + return ICalProperty::propertyVectorToString(getCategories(), dateFmt, s); + case ms_cComment: + return ICalProperty::propertyVectorToString(getComment(), dateFmt, s); + case ms_cClass: + return ICalProperty::propertyToString(getClassProperty(), dateFmt, s); + case ms_cURL: + return ICalProperty::propertyToString(getURLProperty(), dateFmt, s); + case ms_cCreated: + return ICalProperty::propertyToString(getCreatedProperty(), dateFmt, s); + case ms_cDescription: + return ICalProperty::propertyToString(getDescriptionProperty(), dateFmt, s); + case ms_cDTStart: + return ICalProperty::propertyToString(getDTStartProperty(), dateFmt, s); + case ms_cDTStamp: + return ICalProperty::propertyToString(getDTStampProperty(), dateFmt, s); + case ms_cLastModified: + return ICalProperty::propertyToString(getLastModifiedProperty(), dateFmt, s); + case ms_cRelatedTo: + return ICalProperty::propertyVectorToString(getRelatedTo(), dateFmt, s); + case ms_cRequestStatus: + return ICalProperty::propertyVectorToString(getRequestStatus(), dateFmt, s); + case ms_cSequence: + return ICalProperty::propertyToString(getSequenceProperty(), dateFmt, s); + case ms_cStatus: + return ICalProperty::propertyToString(getStatusProperty(), dateFmt, s); + case ms_cSummary: + return ICalProperty::propertyToString(getSummaryProperty(), dateFmt, s); + case ms_cUID: + return ICalProperty::propertyToString(getUIDProperty(), dateFmt, s); + case ms_cOrganizer: + return ICalProperty::propertyToString(getOrganizerProperty(), dateFmt, s); + case ms_cRecurrenceID: + return ICalProperty::propertyToString(getRecurrenceIDProperty(), dateFmt, s); + case ms_cContact: + return ICalProperty::propertyVectorToString(getContact(), dateFmt, s); + default: + return ""; + } +} + +//--------------------------------------------------------------------- + +UnicodeString +TimeBasedEvent::formatChar(t_int32 c, UnicodeString sFilterAttendee, + t_bool delegateRequest) +{ + UnicodeString sResult, s; + t_int32 i; + JulianPtrArray * v; + + switch ( c ) + { + case ms_cAlarms: + v = getAlarms(); + if (v != 0) + { + VAlarm * va; + for (i = 0; i < v->GetSize(); i++) + { + va = (VAlarm *) v->GetAt(i); + s = va->toICALString(); + sResult += s; + } + } + return sResult; + case ms_cAttach: + s = JulianKeyword::Instance()->ms_sATTACH; + return ICalProperty::propertyVectorToICALString(s, getAttach(), sResult); + case ms_cAttendees: + { + v = getAttendees(); + if (v != 0) + { + if (delegateRequest) + { + for (i = 0; i < v->GetSize(); i++) + { + Attendee * a = (Attendee *) v->GetAt(i); + if (a != 0) + { + if ( + //(a->getRole() == Attendee::ROLE_OWNER) || + //(a->getRole() == Attendee::ROLE_ORGANIZER) || + (a->getStatus() == Attendee::STATUS_DELEGATED) + // || (a->getRole() == Attendee::ROLE_DELEGATE) + ) + { + s = a->toICALString(s); + //sResult += s; + sResult += ICalProperty::multiLineFormat(s); + } + } + } + } + else if (sFilterAttendee.size() > 0) + { + Attendee * a = getAttendee(sFilterAttendee); + if (a != 0) + s = a->toICALString(s); + else + s = ""; + //sResult += s; + sResult += ICalProperty::multiLineFormat(s); + } + else + { + for (i = 0; i < v->GetSize(); i++) + { + s = ((Attendee * ) v->GetAt(i))->toICALString(s); + //sResult += s; + sResult += ICalProperty::multiLineFormat(s); + } + } + } + return sResult; + // return sResult.toString(); + } + case ms_cCategories: + s = JulianKeyword::Instance()->ms_sCATEGORIES; + return ICalProperty::propertyVectorToICALString(s, getCategories(), sResult); + case ms_cClass: + s = JulianKeyword::Instance()->ms_sCLASS; + return ICalProperty::propertyToICALString(s, getClassProperty(), sResult); + case ms_cComment: + s = JulianKeyword::Instance()->ms_sCOMMENT; + return ICalProperty::propertyVectorToICALString(s, getComment(), sResult); + case ms_cURL: + s = JulianKeyword::Instance()->ms_sURL; + return ICalProperty::propertyToICALString(s, getURLProperty(), sResult); + case ms_cCreated: + s = JulianKeyword::Instance()->ms_sCREATED; + return ICalProperty::propertyToICALString(s, getCreatedProperty(), sResult); + case ms_cDescription: + s = JulianKeyword::Instance()->ms_sDESCRIPTION; + return ICalProperty::propertyToICALString(s, getDescriptionProperty(), sResult); + case ms_cDTStart: + s = JulianKeyword::Instance()->ms_sDTSTART; + return ICalProperty::propertyToICALString(s, getDTStartProperty(), sResult); + case ms_cDTStamp: + s = JulianKeyword::Instance()->ms_sDTSTAMP; + return ICalProperty::propertyToICALString(s, getDTStampProperty(), sResult); + case ms_cExDate: + s = JulianKeyword::Instance()->ms_sEXDATE; + return ICalProperty::propertyVectorToICALString(s, getExDates(), sResult); + case ms_cExRule: + if (getExRules() != 0) + { + //s = JulianKeyword::Instance()->ms_sEXRULE; + //return ICalComponent::propertyVToCalString(s, getExRules(), sResult); + return ICalProperty::vectorToICALString(getExRules(), sResult); + } + return ""; + case ms_cLastModified: + s = JulianKeyword::Instance()->ms_sLASTMODIFIED; + return ICalProperty::propertyToICALString(s, getLastModifiedProperty(), sResult); + case ms_cRDate: + s = JulianKeyword::Instance()->ms_sRDATE; + return ICalProperty::propertyVectorToICALString(s, getRDates(), sResult); + case ms_cRRule: + if (getRRules() != 0) + { + //s = JulianKeyword::Instance()->ms_sRRULE; + //return ICalComponent::propertyVToCalString(s, getRRules(), sResult); + return ICalProperty::vectorToICALString(getRRules(), sResult); + } + return ""; + case ms_cRecurrenceID: + s = JulianKeyword::Instance()->ms_sRECURRENCEID; + return ICalProperty::propertyToICALString(s, getRecurrenceIDProperty(), sResult); + case ms_cRelatedTo: + s = JulianKeyword::Instance()->ms_sRELATEDTO; + return ICalProperty::propertyVectorToICALString(s, getRelatedTo(), sResult); + case ms_cRequestStatus: + s = JulianKeyword::Instance()->ms_sREQUESTSTATUS; + return ICalProperty::propertyVectorToICALString(s, getRequestStatus(), sResult); + case ms_cSequence: + s = JulianKeyword::Instance()->ms_sSEQUENCE; + return ICalProperty::propertyToICALString(s, getSequenceProperty(), sResult); + case ms_cStatus: + s = JulianKeyword::Instance()->ms_sSTATUS; + return ICalProperty::propertyToICALString(s, getStatusProperty(), sResult); + case ms_cSummary: + s = JulianKeyword::Instance()->ms_sSUMMARY; + return ICalProperty::propertyToICALString(s, getSummaryProperty(), sResult); + case ms_cUID: + s = JulianKeyword::Instance()->ms_sUID; + return ICalProperty::propertyToICALString(s, getUIDProperty(), sResult); + case ms_cOrganizer: + s = JulianKeyword::Instance()->ms_sORGANIZER; + return ICalProperty::propertyToICALString(s, getOrganizerProperty(), sResult); + case ms_cContact: + s = JulianKeyword::Instance()->ms_sCONTACT; + return ICalProperty::propertyVectorToICALString(s, getContact(), sResult); + case ms_cXTokens: + return ICalProperty::vectorToICALString(getXTokens(), sResult); + default: + return ""; + } +} + +//--------------------------------------------------------------------- +// TODO: make crash proof +UnicodeString & +TimeBasedEvent::parseType(UnicodeString & sType, ICalReader * brFile, + UnicodeString & sMethod, + UnicodeString & parseStatus, + JulianPtrArray * vTimeZones, t_bool bIgnoreBeginError, + JulianUtility::MimeEncoding encoding) +{ + t_bool bNewEvent = FALSE; + t_bool bNextAlarm = FALSE; + + UnicodeString sOK; + t_bool parseError = FALSE; + UnicodeString strLine, propName, propVal; + + JulianPtrArray * parameters = new JulianPtrArray(); + + parseStatus = JulianKeyword::Instance()->ms_sOK; + PR_ASSERT(parameters != 0 && brFile != 0); + if (parameters == 0 || brFile == 0) + { + // Return an invalid event + return parseStatus; + } + //UnicodeString end = JulianKeyword::Instance()->ms_sEND_WITH_COLON; end += sType; + //UnicodeString begin = JulianKeyword::Instance()->ms_sBEGIN_WITH_COLON; begin += sType; + + ErrorCode status = ZERO_ERROR; + + // set method + setMethod(sMethod); + + while (TRUE) + { + PR_ASSERT(brFile != 0); + brFile->readFullLine(strLine, status); + ICalProperty::Trim(strLine); + + if (FAILURE(status) && strLine.size() == 0) + break; + + //////////////////////////////////////////////////////// + // I've made it so parameters are now + // copied. Only need to worry about deleting parameter + // contents here now. The ICalProperty, Attendee, Freebusy + // DO NOT take ownership of parameters pointer + ///////////////////////////////////////////////////////// +//#ifdef TIMING + //clock_t cstart, cfinish; + //cstart = clock(); +//#endif + ICalProperty::parsePropertyLine(strLine, propName, propVal, parameters); + +//#ifdef TIMING + //cfinish = clock(); + //double d = cfinish - cstart; + //if (FALSE) TRACE("parsePropertyLine took %f ms.\r\n", strLine.toCString(""), d); +//#endif + //if (FALSE) TRACE("TMB: propName (size = %d) = --%s--, propVal (size = %d) = --%s--, paramSize = %d\r\n", + // propName.size(), propName.toCString(""), + // propVal.size(), propVal.toCString(""), parameters->GetSize()); + + // TRACE_ICalParameterVector(parameters, FALSE); + // ICalProperty::propertyToICALString(outName, outVal, + // parameters, printOut); + + + if (strLine.size() == 0) + { + ICalProperty::deleteICalParameterVector(parameters); + parameters->RemoveAll(); + + continue; + } + // break on END:type (where type is matching VEVENT, VTODO, VJOURNAL) + if ((propName.compareIgnoreCase(JulianKeyword::Instance()->ms_sEND) == 0) && + (propVal.compareIgnoreCase(sType) == 0)) + { + ICalProperty::deleteICalParameterVector(parameters); + parameters->RemoveAll(); + + break; + } + if ( + ((propName.compareIgnoreCase(JulianKeyword::Instance()->ms_sBEGIN) == 0) && + ((propVal.compareIgnoreCase(sType) == 0) && !bIgnoreBeginError )|| + ((propVal.compareIgnoreCase(JulianKeyword::Instance()->ms_sVCALENDAR) == 0) || + (propVal.compareIgnoreCase(JulianKeyword::Instance()->ms_sVEVENT) == 0) || + (propVal.compareIgnoreCase(JulianKeyword::Instance()->ms_sVTODO) == 0) || + (propVal.compareIgnoreCase(JulianKeyword::Instance()->ms_sVJOURNAL) == 0) || + (propVal.compareIgnoreCase(JulianKeyword::Instance()->ms_sVFREEBUSY) == 0) || + (propVal.compareIgnoreCase(JulianKeyword::Instance()->ms_sVTIMEZONE) == 0) || + (ICalProperty::IsXToken(propVal))) + ) || + ((propName.compareIgnoreCase(JulianKeyword::Instance()->ms_sEND) == 0) && + ( + (propVal.compareIgnoreCase(JulianKeyword::Instance()->ms_sVCALENDAR) == 0) || + (propVal.compareIgnoreCase(JulianKeyword::Instance()->ms_sVFREEBUSY) == 0) || + (propVal.compareIgnoreCase(JulianKeyword::Instance()->ms_sVJOURNAL) == 0) || + (propVal.compareIgnoreCase(JulianKeyword::Instance()->ms_sVEVENT) == 0) || + (propVal.compareIgnoreCase(JulianKeyword::Instance()->ms_sVTODO) == 0) || + (propVal.compareIgnoreCase(JulianKeyword::Instance()->ms_sVTIMEZONE) == 0) || + (ICalProperty::IsXToken(propVal))) + )) + { + // END:VCALENDAR, VFREEBUSY, VJOURNAL, VEVENT, VTODO, VTIMEZONE, x-token + // BEGIN:VEVENT, VTODO, VJOURNAL, VTIMEZONE, VFREEBUSY, x-token, VCALENDAR + ICalProperty::deleteICalParameterVector(parameters); + parameters->RemoveAll(); + + parseStatus = strLine; + + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iAbruptEndOfParsing, + sType, strLine, 300); + + bNewEvent = TRUE; + break; + } + else + { + if ((propName.compareIgnoreCase(JulianKeyword::Instance()->ms_sBEGIN) == 0) && + (propVal.compareIgnoreCase(JulianKeyword::Instance()->ms_sVALARM) == 0)) + { + + ICalProperty::deleteICalParameterVector(parameters); + parameters->RemoveAll(); + + + // only add alarm to alarm-vector if alarm is valid and this + // is a VEVENT or VTODO. + bNextAlarm = TRUE; + VAlarm * alarm = 0; + while (bNextAlarm) + { + alarm = new VAlarm(m_Log); + if (alarm != 0) + { + sOK = alarm->parse(brFile, sMethod, sOK, vTimeZones); + if (alarm->isValid() && (GetType() != ICAL_COMPONENT_VJOURNAL)) + addAlarm(alarm); + else + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iInvalidAlarm, 300); + delete alarm; alarm = 0; + } + } + if (sOK.compareIgnoreCase(JulianKeyword::Instance()->ms_sOK) == 0) + bNextAlarm = FALSE; + else + { + // TODO: make it handle "BEGIN : VALARM"; + if (sOK.compareIgnoreCase("BEGIN:VALARM") == 0) + bNextAlarm = TRUE; + else + bNextAlarm = FALSE; + } + } + if (sOK.compareIgnoreCase(JulianKeyword::Instance()->ms_sOK) != 0) + { + parseStatus = sOK; + break; + } + } + else + { +//#ifdef TIMING + //clock_t start, end; + //start = clock(); +//#endif + storeData(strLine, propName, propVal, parameters, vTimeZones); + ICalProperty::deleteICalParameterVector(parameters); + parameters->RemoveAll(); +//#ifdef TIMING + //end = clock(); + //double d = end - start; + //if (FALSE) TRACE("storeData on %s took %f ms.\r\n", propName.toCString(""), d); +//#endif + } + } + } + ICalProperty::deleteICalParameterVector(parameters); + parameters->RemoveAll(); + delete parameters; parameters = 0; + + selfCheck(); + //checkRecurrence(); + return parseStatus; +} + +//--------------------------------------------------------------------- +void TimeBasedEvent::storeAttach(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones) +{ + // check parameters (binary, uri), todo: checkEncoding range + // todo: check FMTTYPE so it doesn't complain. + t_bool bParamValid = ICalProperty::CheckParamsWithValueRangeCheck(parameters, + JulianAtomRange::Instance()->ms_asEncodingValueFMTTypeParamRange, + JulianAtomRange::Instance()->ms_asEncodingValueFMTTypeParamRangeSize, + JulianAtomRange::Instance()->ms_asBinaryURIValueRange, + JulianAtomRange::Instance()->ms_asBinaryURIValueRangeSize); + if (!bParamValid) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iInvalidOptionalParam, + JulianKeyword::Instance()->ms_sTIMEBASEDEVENT, strLine, 100); + } + addAttach(propVal, parameters); +} +void TimeBasedEvent::storeAttendees(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones) +{ + Attendee * attendee = new Attendee(GetType(), m_Log); + PR_ASSERT(attendee != 0); + if (attendee != 0) + { + attendee->parse(propVal, parameters); + if (!attendee->isValid()) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iInvalidAttendee, 200); + + UnicodeString u; + u = JulianLogErrorMessage::Instance()->ms_sRS202; + u += '.'; u += ' '; + u += strLine; + //setRequestStatus(JulianLogErrorMessage::Instance()->ms_iRS202); + addRequestStatus(u); + delete attendee; attendee = 0; + } + else + { + addAttendee(attendee); + } + } +} +void TimeBasedEvent::storeCategories(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones) +{ + t_bool bParamValid = ICalProperty::CheckParams(parameters, + JulianAtomRange::Instance()->ms_asLanguageParamRange, + JulianAtomRange::Instance()->ms_asLanguageParamRangeSize); + if (!bParamValid) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iInvalidOptionalParam, + JulianKeyword::Instance()->ms_sTIMEBASEDEVENT, strLine, 100); + } + + addCategoriesPropertyVector(propVal, parameters); +} +void TimeBasedEvent::storeClass(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones) +{ + // no parameters + if (parameters->GetSize() > 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iInvalidOptionalParam, + JulianKeyword::Instance()->ms_sTIMEBASEDEVENT, strLine, 100); + } + + if (getClassProperty() != 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iDuplicatedProperty, + JulianKeyword::Instance()->ms_sTIMEBASEDEVENT, + JulianKeyword::Instance()->ms_sCLASS, 100); + } + setClass(propVal, parameters); +} +void TimeBasedEvent::storeComment(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones) +{ + t_bool bParamValid = ICalProperty::CheckParams(parameters, + JulianAtomRange::Instance()->ms_asAltrepLanguageParamRange, + JulianAtomRange::Instance()->ms_asAltrepLanguageParamRangeSize); + + if (!bParamValid) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iInvalidOptionalParam, + JulianKeyword::Instance()->ms_sTIMEBASEDEVENT, strLine, 100); + } + + addComment(propVal, parameters); +} +void TimeBasedEvent::storeContact(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones) +{ + t_bool bParamValid = ICalProperty::CheckParams(parameters, + JulianAtomRange::Instance()->ms_asAltrepLanguageParamRange, + JulianAtomRange::Instance()->ms_asAltrepLanguageParamRangeSize); + if (!bParamValid) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iInvalidOptionalParam, + JulianKeyword::Instance()->ms_sTIMEBASEDEVENT, strLine, 100); + } + + addContact(propVal, parameters); +} +void TimeBasedEvent::storeCreated(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones) +{ + // no parameters (MUST BE IN UTC) + if (parameters->GetSize() > 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iInvalidOptionalParam, + JulianKeyword::Instance()->ms_sTIMEBASEDEVENT, strLine, 100); + } + + if (getCreatedProperty() != 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iDuplicatedProperty, + JulianKeyword::Instance()->ms_sTIMEBASEDEVENT, + JulianKeyword::Instance()->ms_sCREATED, 100); + } + DateTime d; + d = VTimeZone::DateTimeApplyTimeZone(propVal, vTimeZones, parameters); + + setCreated(d, parameters); +} +void TimeBasedEvent::storeDescription(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones) +{ + // check parameters + t_bool bParamValid = ICalProperty::CheckParams(parameters, + JulianAtomRange::Instance()->ms_asAltrepLanguageParamRange, + JulianAtomRange::Instance()->ms_asAltrepLanguageParamRangeSize); + + if (!bParamValid) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iInvalidOptionalParam, + JulianKeyword::Instance()->ms_sTIMEBASEDEVENT, strLine, 100); + } + + // check for duplicates + if (getDescriptionProperty() != 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iDuplicatedProperty, + JulianKeyword::Instance()->ms_sTIMEBASEDEVENT, + JulianKeyword::Instance()->ms_sDESCRIPTION, 100); + } + + setDescription(propVal, parameters); +} +void TimeBasedEvent::storeDTStart(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones) +{ + // check parameters (date, datetime), TZID + t_bool bParamValid = ICalProperty::CheckParamsWithValueRangeCheck(parameters, + JulianAtomRange::Instance()->ms_asTZIDValueParamRange, + JulianAtomRange::Instance()->ms_asTZIDValueParamRangeSize, + JulianAtomRange::Instance()->ms_asDateDateTimeValueRange, + JulianAtomRange::Instance()->ms_asDateDateTimeValueRangeSize); + + if (!bParamValid) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iInvalidOptionalParam, + JulianKeyword::Instance()->ms_sTIMEBASEDEVENT, strLine, 100); + } + + if (getDTStartProperty() != 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iDuplicatedProperty, + JulianKeyword::Instance()->ms_sTIMEBASEDEVENT, + JulianKeyword::Instance()->ms_sDTSTART, 100); + } + + UnicodeString u, out; + u = JulianKeyword::Instance()->ms_sVALUE; + out = ICalParameter::GetParameterFromVector(u, out, parameters); + + t_bool bIsDate = DateTime::IsParseableDate(propVal); + + if (bIsDate) + { + // if there is a VALUE=X parameter, make sure X is DATE + if (out.size() != 0 && (JulianKeyword::Instance()->ms_ATOM_DATE != out.hashCode())) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iPropertyValueTypeMismatch, + JulianKeyword::Instance()->ms_sTIMEBASEDEVENT, strLine, 100); + } + setAllDayEvent(TRUE); + } + else + { + // if there is a VALUE=X parameter, make sure X is DATETIME + if (out.size() != 0 && (JulianKeyword::Instance()->ms_ATOM_DATETIME != out.hashCode())) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iPropertyValueTypeMismatch, + JulianKeyword::Instance()->ms_sTIMEBASEDEVENT, strLine, 100); + } + setAllDayEvent(FALSE); + } + + DateTime d; + //UnicodeString u, out; + d = VTimeZone::DateTimeApplyTimeZone(propVal, vTimeZones, parameters); + + setDTStart(d, parameters); +} +void TimeBasedEvent::storeDTStamp(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones) +{ + // no parameters (MUST BE IN UTC) + if (parameters->GetSize() > 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iInvalidOptionalParam, + JulianKeyword::Instance()->ms_sTIMEBASEDEVENT, strLine, 100); + } + + if (getDTStampProperty() != 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iDuplicatedProperty, + JulianKeyword::Instance()->ms_sTIMEBASEDEVENT, + JulianKeyword::Instance()->ms_sDTSTAMP, 100); + } + DateTime d; + d = VTimeZone::DateTimeApplyTimeZone(propVal, vTimeZones, parameters); + + setDTStamp(d, parameters); +} +void TimeBasedEvent::storeExDate(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones) +{ + // check parameters (date, datetime) + t_bool bParamValid = ICalProperty::CheckParamsWithValueRangeCheck(parameters, + JulianAtomRange::Instance()->ms_asTZIDValueParamRange, + JulianAtomRange::Instance()->ms_asTZIDValueParamRangeSize, + JulianAtomRange::Instance()->ms_asDateDateTimeValueRange, + JulianAtomRange::Instance()->ms_asDateDateTimeValueRangeSize); + if (!bParamValid) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iInvalidOptionalParam, + JulianKeyword::Instance()->ms_sTIMEBASEDEVENT, strLine, 100); + } + // DONE:?TODO: finish + addExDate(propVal, parameters); +} +void TimeBasedEvent::storeExRule(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones) +{ + // no parameters + if (parameters->GetSize() > 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iInvalidOptionalParam, + JulianKeyword::Instance()->ms_sTIMEBASEDEVENT, strLine, 100); + } + // TODO: finish, pass timezones. + addExRuleString(strLine); +} +void TimeBasedEvent::storeLastModified(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones) +{ + // no parameters (MUST BE IN UTC) + if (parameters->GetSize() > 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iInvalidOptionalParam, + JulianKeyword::Instance()->ms_sTIMEBASEDEVENT, strLine, 100); + } + + if (getLastModifiedProperty() != 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iDuplicatedProperty, + JulianKeyword::Instance()->ms_sTIMEBASEDEVENT, + JulianKeyword::Instance()->ms_sLASTMODIFIED, 100); + } + DateTime d; + d = VTimeZone::DateTimeApplyTimeZone(propVal, vTimeZones, parameters); + + setLastModified(d, parameters); +} +void TimeBasedEvent::storeOrganizer(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones) +{ + // check parameters + t_bool bParamValid = ICalProperty::CheckParams(parameters, + JulianAtomRange::Instance()->ms_asSentByParamRange, + JulianAtomRange::Instance()->ms_asSentByParamRangeSize); + if (!bParamValid) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iInvalidOptionalParam, + JulianKeyword::Instance()->ms_sTIMEBASEDEVENT, strLine, 100); + } + + if (getOrganizerProperty() != 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iDuplicatedProperty, + JulianKeyword::Instance()->ms_sTIMEBASEDEVENT, + JulianKeyword::Instance()->ms_sORGANIZER, 100); + } + setOrganizer(propVal, parameters); +} +void TimeBasedEvent::storeRDate(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones) +{ + // check parameters (date, datetime, period) + t_bool bParamValid = ICalProperty::CheckParamsWithValueRangeCheck(parameters, + JulianAtomRange::Instance()->ms_asTZIDValueParamRange, + JulianAtomRange::Instance()->ms_asTZIDValueParamRangeSize, + JulianAtomRange::Instance()->ms_asDateDateTimePeriodValueRange, + JulianAtomRange::Instance()->ms_asDateDateTimePeriodValueRangeSize); + if (!bParamValid) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iInvalidOptionalParam, + JulianKeyword::Instance()->ms_sTIMEBASEDEVENT, strLine, 100); + } + // TODO: finish + addRDate(propVal, parameters); +} +void TimeBasedEvent::storeRRule(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones) +{ + // no parameters + if (parameters->GetSize() > 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iInvalidOptionalParam, + JulianKeyword::Instance()->ms_sTIMEBASEDEVENT, strLine, 100); + } + // TODO: finish, pass timezones. + addRRuleString(strLine); +} +void TimeBasedEvent::storeRecurrenceID(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones) +{ + // TODO: CHECK PARAMETERS + if (getRecurrenceIDProperty() != 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iDuplicatedProperty, + JulianKeyword::Instance()->ms_sTIMEBASEDEVENT, + JulianKeyword::Instance()->ms_sRECURRENCEID, 100); + } + DateTime d(propVal); + + // NOTE: only set recurrenceID if datetime is of a valid datetime format + if (d.isValid()) + { + setRecurrenceID(d, parameters); + } +} +void TimeBasedEvent::storeRelatedTo(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones) +{ + // check parameters: todo: check reltype + t_bool bParamValid = ICalProperty::CheckParams(parameters, + JulianAtomRange::Instance()->ms_asReltypeParamRange, + JulianAtomRange::Instance()->ms_asReltypeParamRangeSize); + if (!bParamValid) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iInvalidOptionalParam, + JulianKeyword::Instance()->ms_sTIMEBASEDEVENT, strLine, 100); + } + + addRelatedTo(propVal, parameters); +} +void TimeBasedEvent::storeRequestStatus(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones) +{ + // check parameters + t_bool bParamValid = ICalProperty::CheckParams(parameters, + JulianAtomRange::Instance()->ms_asLanguageParamRange, + JulianAtomRange::Instance()->ms_asLanguageParamRangeSize); + if (!bParamValid) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iInvalidOptionalParam, + JulianKeyword::Instance()->ms_sTIMEBASEDEVENT, strLine, 100); + } + + /* + if (getRequestStatusProperty() != 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iDuplicatedProperty, + JulianKeyword::Instance()->ms_sTIMEBASEDEVENT, JulianKeyword::Instance()->ms_s, 100); + } + */ + //setRequestStatus(propVal, parameters); + addRequestStatus(propVal, parameters); +} +void TimeBasedEvent::storeSequence(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones) +{ + t_bool bParseError = FALSE; + t_int32 i; + + // no parameters + if (parameters->GetSize() > 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iInvalidOptionalParam, + JulianKeyword::Instance()->ms_sTIMEBASEDEVENT, strLine, 100); + } + + char * pcc = propVal.toCString(""); + PR_ASSERT(pcc != 0); + i = JulianUtility::atot_int32(pcc, bParseError, propVal.size()); + delete [] pcc; pcc = 0; + + if (getSequenceProperty() != 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iDuplicatedProperty, + JulianKeyword::Instance()->ms_sTIMEBASEDEVENT, + JulianKeyword::Instance()->ms_sSEQUENCE, 100); + } + if (!bParseError) + { + setSequence(i, parameters); + } + else + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iInvalidNumberFormat, + JulianKeyword::Instance()->ms_sTIMEBASEDEVENT, + JulianKeyword::Instance()->ms_sSEQUENCE, + propVal, 200); + } +} +void TimeBasedEvent::storeStatus(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones) +{ + // no parameters + if (parameters->GetSize() > 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iInvalidOptionalParam, + JulianKeyword::Instance()->ms_sTIMEBASEDEVENT, strLine, 100); + } + + if (getStatusProperty() != 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iDuplicatedProperty, + JulianKeyword::Instance()->ms_sTIMEBASEDEVENT, + JulianKeyword::Instance()->ms_sSTATUS, 100); + } + setStatus(propVal, parameters); +} +void TimeBasedEvent::storeSummary(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones) +{ + // check parameters + t_bool bParamValid = ICalProperty::CheckParams(parameters, + JulianAtomRange::Instance()->ms_asLanguageParamRange, + JulianAtomRange::Instance()->ms_asLanguageParamRangeSize); + if (!bParamValid) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iInvalidOptionalParam, + JulianKeyword::Instance()->ms_sTIMEBASEDEVENT, strLine, 100); + } + + if (getSummaryProperty() != 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iDuplicatedProperty, + JulianKeyword::Instance()->ms_sTIMEBASEDEVENT, + JulianKeyword::Instance()->ms_sSUMMARY, 100); + } + setSummary(propVal, parameters); +} +void TimeBasedEvent::storeUID(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones) +{ + // no parameters + if (parameters->GetSize() > 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iInvalidOptionalParam, + JulianKeyword::Instance()->ms_sTIMEBASEDEVENT, strLine, 100); + } + + if (getUIDProperty() != 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iDuplicatedProperty, + JulianKeyword::Instance()->ms_sTIMEBASEDEVENT, + JulianKeyword::Instance()->ms_sUID, 100); + } + setUID(propVal, parameters); +} +void TimeBasedEvent::storeURL(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones) +{ + // no parameters + if (parameters->GetSize() > 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iInvalidOptionalParam, + JulianKeyword::Instance()->ms_sTIMEBASEDEVENT, strLine, 100); + } + + if (getURLProperty() != 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iDuplicatedProperty, + JulianKeyword::Instance()->ms_sTIMEBASEDEVENT, + JulianKeyword::Instance()->ms_sURL, 100); + } + + setURL(propVal, parameters); +} +//--------------------------------------------------------------------- +t_bool +TimeBasedEvent::storeData(UnicodeString & strLine, UnicodeString & propName, + UnicodeString & propVal, JulianPtrArray * parameters, + JulianPtrArray * vTimeZones) +{ + t_int32 hashCode = propName.hashCode(); + t_int32 i; + + for (i = 0; 0 != (JulianFunctionTable::Instance()->tbeStoreTable[i]).op; i++) + { + if ((JulianFunctionTable::Instance()->tbeStoreTable[i]).hashCode == hashCode) + { + ApplyStoreOp(((JulianFunctionTable::Instance())->tbeStoreTable[i]).op, + strLine, propVal, parameters, vTimeZones); + return TRUE; + } + } + if (ICalProperty::IsXToken(propName)) + { + addXTokens(strLine); + return TRUE; + } + return FALSE; +} +//--------------------------------------------------------------------- + +t_bool TimeBasedEvent::isValid() +{ + return TRUE; +} + +//--------------------------------------------------------------------- + +UnicodeString TimeBasedEvent::toICALString() +{ + return allMessage(); +} + +//--------------------------------------------------------------------- + +UnicodeString TimeBasedEvent::toICALString(UnicodeString sMethod, UnicodeString sName, + t_bool isRecurring) +{ + UnicodeString s; + + t_int32 hashCode = sMethod.hashCode(); + + if (JulianKeyword::Instance()->ms_ATOM_PUBLISH == hashCode) + s = publishMessage(); + else if (JulianKeyword::Instance()->ms_ATOM_REQUEST == hashCode) + s = requestMessage(); + else if (JulianKeyword::Instance()->ms_ATOM_CANCEL == hashCode) + s = cancelMessage(); + else if (JulianKeyword::Instance()->ms_ATOM_REPLY == hashCode) + s = replyMessage(sName); + else if (JulianKeyword::Instance()->ms_ATOM_REFRESH == hashCode) + s = refreshMessage(sName); + else if (JulianKeyword::Instance()->ms_ATOM_COUNTER == hashCode) + s = counterMessage(); + else if (JulianKeyword::Instance()->ms_ATOM_DECLINECOUNTER == hashCode) + s = declineCounterMessage(); + else if (JulianKeyword::Instance()->ms_ATOM_ADD == hashCode) + s = addMessage(); + /* + else if (JulianKeyword::Instance()->ms_ATOM_DELEGATEREQUEST == hashCode) + s = delegateRequestMessage(sName, sDelegatedTo, isRecurring); + else if (JulianKeyword::Instance()->ms_ATOM_DELEGATEREPLY == hashCode) + s = delegateReplyMessage(sName, sDelegatedTo, isRecurring); + */ + return s; +} + +//--------------------------------------------------------------------- +/* +UnicodeString +TimeBasedEvent::delegateReplyMessage(UnicodeString sAttendeeFilter, + UnicodeString sDelegateTo, t_bool bRecur) +{ + // NOTE: remove later, avoid warning + if (bRecur) {} + addDelegate(sAttendeeFilter, sDelegateTo); + return replyMessage(sAttendeeFilter); +} +*/ +//--------------------------------------------------------------------- +/* +UnicodeString +TimeBasedEvent::delegateRequestMessage(UnicodeString sAttendeeFilter, + UnicodeString sDelegateTo, t_bool bRecur) +{ + // NOTE: remove later, avoid warning + if (bRecur) {} + addDelegate(sAttendeeFilter, sDelegateTo); + return requestMessage(); +} +*/ +//--------------------------------------------------------------------- +/* +void +TimeBasedEvent::addDelegate(UnicodeString & sAttendeeFilter, + UnicodeString & sDelegateTo) +{ + Attendee * me; + me = getAttendee(sAttendeeFilter); + if (me != 0) + { + // set my attendee status to delegated, add delegateTo variable + me->setStatus(Attendee::STATUS_DELEGATED); + me->addDelegatedTo(sDelegateTo); + + // add new attendee, setting name, role = req_part, delfrom = me, + // rsvp = TRUE, expect = request, status = needs-action + Attendee * delegate = Attendee::getDefault(m_Log); + PR_ASSERT(delegate != 0); + if (delegate != 0) + { + delegate->setName(sDelegateTo); + delegate->setRole(Attendee::ROLE_REQ_PARTICIPANT); + delegate->addDelegatedFrom(sAttendeeFilter); + delegate->setRSVP(Attendee::RSVP_TRUE); + delegate->setExpect(Attendee::EXPECT_REQUEST); + delegate->setStatus(Attendee::STATUS_NEEDSACTION); + addAttendee(delegate); + } + } +} +*/ +//--------------------------------------------------------------------- + +void +TimeBasedEvent::setAttendeeStatus(UnicodeString & sAttendeeFilter, + Attendee::STATUS status, + JulianPtrArray * delegatedTo) +{ + Attendee * a; + a = getAttendee(sAttendeeFilter); + if (a == 0) + { + // add a new attendee to this event (a partycrasher) + a = Attendee::getDefault(GetType()); + PR_ASSERT(a != 0); + if (a != 0) + { + a->setName(sAttendeeFilter); + addAttendee(a); + } + } + PR_ASSERT(a != 0); + if (a != 0) + { + a->setStatus(status); + if (status == Attendee::STATUS_DELEGATED) + { + if (delegatedTo != 0) + { + t_int32 i; + UnicodeString u; + // for each new attendee, set name, role = req_part, delfrom = me, + // rsvp = TRUE, expect = request, status = needs-action. + for (i = 0; i < delegatedTo->GetSize(); i++) + { + u = *((UnicodeString *) delegatedTo->GetAt(i)); + a->addDelegatedTo(u); + + Attendee * delegate = Attendee::getDefault(GetType(), m_Log); + PR_ASSERT(delegate != 0); + if (delegate != 0) + { + delegate->setName(u); + delegate->setRole(Attendee::ROLE_REQ_PARTICIPANT); + delegate->addDelegatedFrom(sAttendeeFilter); + delegate->setRSVP(Attendee::RSVP_TRUE); + delegate->setExpect(Attendee::EXPECT_REQUEST); + delegate->setStatus(Attendee::STATUS_NEEDSACTION); + addAttendee(delegate); + } + } + } + } + } +} +//--------------------------------------------------------------------- + +void +TimeBasedEvent::setAttendeeStatusInt(UnicodeString & sAttendeeFilter, + t_int32 status, + JulianPtrArray * delegatedTo) +{ + Attendee::STATUS i; + i = (Attendee::STATUS) status; + setAttendeeStatus(sAttendeeFilter, i, delegatedTo); +} + +//--------------------------------------------------------------------- + +void +TimeBasedEvent::updateComponentHelper(TimeBasedEvent * updatedComponent) +{ + DateTime d; + // update each property + // clear and set attach, attendees, categories, comment, contact, exdate, + // exrule, rdate, rrule, related-to, req-stat, x-token + // no need: created, last-modified, UID, rec-id. + // vectors if different + ICalComponent::internalSetPropertyVctr(&m_AttachVctr, updatedComponent->getAttach()); + ICalComponent::internalSetPropertyVctr(&m_AttendeesVctr, updatedComponent->getAttendees()); + ICalComponent::internalSetPropertyVctr(&m_CategoriesVctr, updatedComponent->getCategories()); + ICalComponent::internalSetPropertyVctr(&m_CommentVctr, updatedComponent->getComment()); + ICalComponent::internalSetPropertyVctr(&m_ContactVctr, updatedComponent->getContact()); + ICalComponent::internalSetPropertyVctr(&m_ExDateVctr, updatedComponent->getExDates()); + ICalComponent::internalSetPropertyVctr(&m_ExRuleVctr, updatedComponent->getExRules()); + ICalComponent::internalSetPropertyVctr(&m_RDateVctr, updatedComponent->getRDates()); + ICalComponent::internalSetPropertyVctr(&m_RRuleVctr, updatedComponent->getRRules()); + ICalComponent::internalSetPropertyVctr(&m_RelatedToVctr, updatedComponent->getRelatedTo()); + //ICalComponent::internalSetAllRequestStatusVctr(updatedComponent->getRequestStatus()); + // set class, created, dtstart, dtstamp, organizer, sequence, url + ICalComponent::internalSetProperty(&m_Class, updatedComponent->m_Class); + ICalComponent::internalSetProperty(&m_Description, updatedComponent->m_Description); + ICalComponent::internalSetProperty(&m_DTStamp, updatedComponent->m_DTStamp); + ICalComponent::internalSetProperty(&m_DTStart, updatedComponent->m_DTStart); + ICalComponent::internalSetProperty(&m_Organizer, updatedComponent->m_Organizer); + ICalComponent::internalSetProperty(&m_Sequence, updatedComponent->m_Sequence); + ICalComponent::internalSetProperty(&m_Status, updatedComponent->m_Status); + ICalComponent::internalSetProperty(&m_Summary, updatedComponent->m_Summary); + ICalComponent::internalSetProperty(&m_URL, updatedComponent->m_URL); + ICalComponent::internalSetXTokensVctr(&m_XTokensVctr, updatedComponent->m_XTokensVctr); + + ICalComponent::internalSetProperty(&m_LastModified, updatedComponent->m_LastModified); + //setLastModified(d); +} + +//--------------------------------------------------------------------- + +t_bool +TimeBasedEvent::updateComponent(ICalComponent * updatedComponent) +{ + // TODO: doesn't do smart overriding for now + if (updatedComponent != 0) + { + ICAL_COMPONENT ucType = updatedComponent->GetType(); + + // only call updateComponentHelper if it's a TimeBasedEvent and + // it is an exact matching ID (uid, recid) and updatedComponent + // is more recent than this component + if (ucType == ICAL_COMPONENT_VEVENT || ucType == ICAL_COMPONENT_VTODO || + ucType == ICAL_COMPONENT_VJOURNAL) + { + // should be a safe cast with check above. + TimeBasedEvent * uctbe = (TimeBasedEvent *) updatedComponent; + + //if (ucType == GetType() && isExactMatchingID(uctbe) && !isMoreRecent(uctbe)) + if (ucType == GetType() && isExactMatchingID(uctbe)) + { + updateComponentHelper(uctbe); + return TRUE; + } + } + } + return FALSE; +} + +//--------------------------------------------------------------------- + +t_bool +TimeBasedEvent::isExactMatchingID(TimeBasedEvent * component) +{ + // component is not NULL + PR_ASSERT(component != 0); + // both have a valid UID + PR_ASSERT(getUID().size() > 0 && component->getUID().size() > 0); + + if (component != 0 && getUID().size() > 0 && component->getUID().size() > 0) + { + if (getUID() != component->getUID()) + { + return FALSE; + } + else + { + if (getRecurrenceIDProperty() == 0 && component->getRecurrenceIDProperty() == 0) + { + return TRUE; + } + else if (getRecurrenceIDProperty() != 0 && component->getRecurrenceIDProperty() != 0) + { + if (getRecurrenceID() == component->getRecurrenceID()) + return TRUE; + } + else + { + // one or the other is missing RecurrenceID. + return FALSE; + } + } + } + // failed assertion + // PR_ASSERT(FALSE); + return FALSE; +} + +//--------------------------------------------------------------------- +#if 0 +t_bool +TimeBasedEvent::isMoreRecent(TimeBasedEvent * component) +{ + // component is not NULL + PR_ASSERT(component != 0); + + if (component != 0) + { + t_bool bHasSeq; + t_bool bHasDTStamp; + + t_int32 iSeq, jSeq; + DateTime idts, jdts; + + iSeq = getSequence(); + idts = getDTStamp(); + + jSeq = component->getSequence(); + jdts = component->getDTStamp(); + + // both components must have sequence and DTSTAMP + bHasSeq = (iSeq >= 0 && jSeq >= 0); + bHasDTStamp = (idts.isValid() && jdts.isValid()); + + PR_ASSERT(bHasSeq); + PR_ASSERT(bHasDTStamp); + + // if iSeq > jSeq return TRUE + // else if iSeq < jSeq return FALSE + // else if iSeq == jSeq + // { + // else if jdts is after idts return FALSE + // else if jdts is before idts return TRUE + // else (dts is equal to idts) return TRUE + // } + + if (component != 0 && bHasSeq && bHasDTStamp) + { + if (iSeq > jSeq) + { + return TRUE; + } + else if (iSeq < jSeq) + { + return FALSE; + } + else + { + return !(jdts.afterDateTime(idts)); + } + } + } + // assert failed + return FALSE; +} +#endif +//--------------------------------------------------------------------- + +int +TimeBasedEvent::CompareTimeBasedEventsByUID(const void * a, + const void * b) +{ + PR_ASSERT(a != 0 && b != 0); + TimeBasedEvent * ta = *(TimeBasedEvent **) a; + TimeBasedEvent * tb = *(TimeBasedEvent **) b; + + return (int) ta->getUID().compare(tb->getUID()); +} + +//--------------------------------------------------------------------- + +int +TimeBasedEvent::CompareTimeBasedEventsByDTStart(const void * a, + const void * b) +{ + PR_ASSERT(a != 0 && b != 0); + TimeBasedEvent * ta = *(TimeBasedEvent **) a; + TimeBasedEvent * tb = *(TimeBasedEvent **) b; + + DateTime da, db; + da = ta->getDTStart(); + db = tb->getDTStart(); + + return (int) (da.compareTo(db)); +} + +//--------------------------------------------------------------------- + +// TODO: make delegate request work +/* +UnicodeString TimeBasedEvent::delegateRequestMessage(UnicodeString TimeBasedEvent::sAttendeeFilter) { + //return delegateRequestMessage(sAttendeeFilter, FALSE); + return ICalComponent::delegateRequestMessage(sAttendeeFilter, FALSE); +} + +//--------------------------------------------------------------------- + +UnicodeString TimeBasedEvent::delegateRecurRequestMessage(UnicodeString TimeBasedEvent::sAttendeeFilter) { + //return delegateRequestMessage(sAttendeeFilter, TRUE); + return ICalComponent::delegateRequestMessage(sAttendeeFilter, TRUE); +} +*/ +/** +* Adds delegate to delegatee attendee list +* Prints properties of an DELEGATE-REQUEST message +* @param sAttendeeFilter name of delegate +* @return string with delegateRequest message required properties +*/ +/* +UnicodeString TimeBasedEvent::delegateRequestMessage(UnicodeString sAttendeeFilter, + t_bool bRecur) +{ + // only required fields + // attendee-R if exists + // comment-R, dtstart?, dtend?, exdate?, exrule?, request-status-R, response-seq-R~0, seq-R~0, summary? + // uid-R, rec-R if exists + + Attendee * me = getAttendee(sAttendeeFilter); + JulianPtrArray * delegateTo; + + ///---PROBABLY SHOULD BE ASSERTIONS----------------- + if (me == 0) { + //LogStream.Instance().println(2, Utility.ErrorMsg("DelegateRequestError")); + //DebugMsg.Instance().println(0,"No such attendee"); + return ""; + } + if (me.getStatus().compareIgnoreCase(JulianKeyword::Instance()->ms_sDELEGATED) != 0) { + //LogStream.Instance().println(2, Utility.ErrorMsg("DelegateRequestError")); + //DebugMsg.Instance().println(0,"I did not delegate yet"); + return ""; + } + delegateTo = me->getDelegatedTo(); + if (delegateTo == 0 || delegateTo->GetSize() == 0) { + + //LogStream.Instance().println(2, Utility.ErrorMsg("DelegateRequestError")); + //DebugMsg.Instance().println(0,"No delegated-to"); + return ""; + } + ///------------------------------------------------- + UnicodeString delegateName; + Attendee * delegate = Attendee.getDefault(); + + // set new attendee's name to last person in delegateTo vector, assuming that last person you delegated to in reply + // will be the next person you call delegate request, thus the request message should immediately be called after the delegation + // takes place + delegateName = *((UnicodeString)delegateTo.lastElement();) + + // according to spec, rsvp, expect should be set to exactly what delegate had + String sRSVP = PropertyKeywords.JulianKeyword::Instance()->ms_sTRUE; + String sExpect = PropertyKeywords.JulianKeyword::Instance()->ms_sREQUEST; + String sRole = PropertyKeywords.JulianKeyword::Instance()->ms_sDELEGATE; + + delegate.setName(delegateName); + delegate.setRole(PropertyKeywords.JulianKeyword::Instance()->ms_sDELEGATE); + delegate.setRSVP(PropertyKeywords.JulianKeyword::Instance()->ms_sTRUE); + delegate.setDelegatedFrom(sAttendeeFilter); + //delegate.load("ATTENDEE;ROLE=DELEGATE;RSVP=" + sRSVP +";EXPECT="+ sExpect +";DELEGATED-FROM=" + sAttendeeFilter + ":" + delegateName); + + System.out.println("delegate.toICALString == "+ delegate.toICALString()); + Attendee * a2 = getAttendee(delegate.getName()); + if (a2 == 0) + addAttendee(delegate); + else { + DebugMsg.Instance().println(0,"Delegating to a person who is already on attendee list"); + } + //String attendeeparams = "%S%D%N"; + // UPDATE ATTENDEE PROPERTIES HERE (attendee status is accepted, declined, delegated) + // what about response-sequence ? (will we keep it) + if (bRecur) + return format(JulianKeyword::Instance()->ms_sRecurDelegateRequestMessage, TRUE); // this is a delegate request + else + return format(JulianKeyword::Instance()->ms_sDelegateRequestMessage, TRUE); // this is a delegate request +} +*/ + +//--------------------------------------------------------------------- + +t_bool TimeBasedEvent::MatchUID_seqNO(UnicodeString sUID, t_int32 iSeqNo) +{ + t_int32 seq = getSequence(); + UnicodeString uid = getUID(); + + if (seq == iSeqNo && uid.compareIgnoreCase(sUID) == 0) + return TRUE; + else + return FALSE; +} + +//--------------------------------------------------------------------- + +Attendee * TimeBasedEvent::getAttendee(UnicodeString sAttendee){ + return Attendee::getAttendee(getAttendees(), sAttendee); +} + +//--------------------------------------------------------------------- + +/** +* return vector of all attendees except organizer +* @param vAttendees vector of attendees +* @return vector of attendees except organizer +*/ +/* +JulianPtrArray * getAttendeesExceptOrganizer() { + JulianPtrArray * attendees = new JulianPtrArray(); + return Attendee.getAttendeesExceptOrganizer(getAttendees(), attendees); +} +*/ + +//--------------------------------------------------------------------- + +void TimeBasedEvent::stamp() +{ + DateTime d; + setDTStamp(d); +} + +//--------------------------------------------------------------------- + +t_bool +TimeBasedEvent::isExpandableEvent() const +{ + DateTime d; + d = getRecurrenceID(); + if (d.isValid()) + { + return FALSE; + } + else if ((getRRules() == 0 || getRRules()->GetSize() == 0) && + (getRDates() == 0 || getRDates()->GetSize() == 0)) + { + return FALSE; + } + else + { + return TRUE; + } +} + +//--------------------------------------------------------------------- + +void +TimeBasedEvent::createRecurrenceEvents(JulianPtrArray * vOut, + JulianPtrArray * vTimeZones) +{ + DateTime start; + start = getDTStart(); + + JulianPtrArray * vRRules = getRRules(); + JulianPtrArray * vExRules = getExRules(); + JulianPtrArray * vRDates = getRDates(); + JulianPtrArray * vExDates = getExDates(); + t_int32 iBound = getBound(); + + if (vRRules == 0 && vExRules == 0 && vRDates == 0 && vExDates == 0) + return; + + JulianPtrArray * dates = new JulianPtrArray(); PR_ASSERT(dates != 0); + + if (dates != 0) + { + // generate dates of instances + generateDates(dates, start, vRRules, vExRules, vRDates, vExDates, + iBound, vTimeZones, m_Log); + + // create events and set start,(end|due) to dates + populateDates(vOut, dates, start, vTimeZones); + + // CLEANUP + Recurrence::deleteDateTimeVector(dates); + delete dates; dates = 0; + } +} + +//--------------------------------------------------------------------- + +void +TimeBasedEvent::generateDates(JulianPtrArray * vOut, DateTime start, + JulianPtrArray * vRRules, + JulianPtrArray * vExRules, + JulianPtrArray * vRDatesProp, + JulianPtrArray * vExDatesProp, + t_int32 iBound, + JulianPtrArray * vTimeZones, JLog * log) +{ + // TODO: SET UNTIL in RRULE, EXRULE to ISO8601 UTC + + JulianPtrArray * vRDates = new JulianPtrArray(); + PR_ASSERT(vRDates != 0); + JulianPtrArray * vExDates = new JulianPtrArray(); + PR_ASSERT(vExDates != 0); + + if (vRDates != 0 && vExDates != 0) + { + // split RDATES, EXDATES properties into vector of Date, DateTime, or Period strings. + splitDates(vRDates, vRDatesProp, TRUE, vTimeZones); + splitDates(vExDates, vExDatesProp, FALSE, vTimeZones); + + Recurrence::stringEnforce(start, vRRules, vExRules, vRDates, + vExDates, iBound, vOut, log); + + ICalComponent::deleteUnicodeStringVector(vRDates); + ICalComponent::deleteUnicodeStringVector(vExDates); + delete vRDates; vRDates = 0; + delete vExDates; vExDates = 0; + } +} + +//--------------------------------------------------------------------- + +// TODO: Make crash proof +void +TimeBasedEvent::splitDates(JulianPtrArray * out, + JulianPtrArray * vDateProp, t_bool isRDate, + JulianPtrArray * vTimeZones) +{ + + if (vDateProp != 0) + { + t_int32 i; + StringProperty * ip; + UnicodeString u, startP, endP; + UnicodeStringTokenizer * st; + Period p; + DateTime d; + t_bool hasTimeZone = FALSE; + ErrorCode status = ZERO_ERROR; + VTimeZone * vtz; + TimeZone * tz; + + for (i = 0; i < vDateProp->GetSize(); i++) + { + ip = (StringProperty *) vDateProp->GetAt(i); + + tz = 0; + + // FIRST, get matching timezone if it exists + // getTZID from date, check for it from VTimezone vector. + // then get the the NLSTimeZone from that VTimeZone + u = ip->getParameterValue( + JulianKeyword::Instance()->ms_sTZID, u, status); + + if (!FAILURE(status)) + { + vtz = VTimeZone::getTimeZone(u, vTimeZones); + if (vtz != 0) + { + tz = vtz->getNLSTimeZone(); + } + } + + // Get string, parse tokens seperated by comma + u = *((UnicodeString *)ip->getValue()); + + st = new UnicodeStringTokenizer(u, + JulianKeyword::Instance()->ms_sCOMMA_SYMBOL); + PR_ASSERT(st != 0); + if (st != 0) + { + while (st->hasMoreTokens()) + { + u = st->nextToken(u, status); + + if (isRDate) + { + if (Period::IsParseable(u)) + { + //adjust for timezones + //according to spec, a VALUE=PERIOD can't have a TZID with it + /* + if (tz != 0) + { + startP = u.extractBetween(0, u.indexOf('/'), + startP); + endP = u.extractBetween(u.indexOf('/') + 1, + u.size(), endP); + d.setTimeString(startP, tz); + startP = d.toISO8601(); + + if (DateTime::IsParseableDateTime(endP)) + { + d.setTimeString(endP, tz); + endP = d.toISO8601(); + } + u = startP; + u += '/'; + u += endP; + } + */ + out->Add(new UnicodeString(u)); + } + else if (DateTime::IsParseableDate(u)) + { + out->Add(new UnicodeString(u)); + } + else if (DateTime::IsParseableDateTime(u)) + { + //adjust for timezones + if (tz != 0) + { + d.setTimeString(u, tz); + u = d.toISO8601(); + } + out->Add(new UnicodeString(u)); + } + else + { + // TODO: Log bad rdate in rdate property vector + } + } + else + { + if (DateTime::IsParseableDateTime(u)) + { + //adjust for timezones + if (tz != 0) + { + d.setTimeString(u, tz); + u = d.toISO8601(); + } + out->Add(new UnicodeString(u)); + } + else + { + // TODO: Log bad exdate in exdate property vector + } + } + } + delete st; st = 0; + } + } + } +} + +//--------------------------------------------------------------------- + +void +TimeBasedEvent::getPeriodRDates(JulianPtrArray * out) +{ + if (getRDates() != 0) + { + t_int32 i; + ICalProperty * ip; + UnicodeString u; + UnicodeStringTokenizer * st; + ErrorCode status = ZERO_ERROR; + + for (i = 0; i < getRDates()->GetSize(); i++) + { + ip = (ICalProperty *) getRDates()->GetAt(i); + u = *((UnicodeString *)ip->getValue()); + st = new UnicodeStringTokenizer(u, + JulianKeyword::Instance()->ms_sCOMMA_SYMBOL); + PR_ASSERT(st != 0); + if (st != 0) + { + while (st->hasMoreTokens()) + { + u = st->nextToken(u, status); + if (Period::IsParseable(u)) + { + out->Add(new UnicodeString(u)); + } + } + delete st; st = 0; + } + } + } +} + +//--------------------------------------------------------------------- +// TODO: remove asserts, make crash proof +void +TimeBasedEvent::populateDates(JulianPtrArray * vOut, + JulianPtrArray * dates, + DateTime origStart, + JulianPtrArray * vTimeZones) +{ + if (dates == 0) + return; + + // NOTE: Remove later, to get rid of warnings + if (vTimeZones) {} + + TimeBasedEvent * tbeClone; + t_int32 i; + Date difference = 0; + DateTime d; + + // vector of strings of period form (i.e. 19980320T112233/PT1H) + JulianPtrArray * vPeriods = new JulianPtrArray(); + PR_ASSERT(vPeriods != 0); + + getPeriodRDates(vPeriods); + + difference = this->difference(); + + // TODO: handle alarms difference + + for (i = 0; i < dates->GetSize(); i++) + { + d = *((DateTime *) dates->GetAt(i)); + + //if (FALSE) TRACE("d = %s\r\n", d.toISO8601().toCString("")); + + tbeClone = (TimeBasedEvent *) this->clone(m_Log); + tbeClone->setDTStart(d); + tbeClone->setOrigStart(origStart); // set origDTStart to recurrence dtstart + tbeClone->setMyOrigStart(d); + tbeClone->populateDatesHelper(d, difference, vPeriods); + tbeClone->setRecurrenceID(d); + + // TODO: set alarms of clone + //if (tbeClone->getAlarms() != 0) + //{ + //} + + vOut->Add(tbeClone); + + } + + ICalComponent::deleteUnicodeStringVector(vPeriods); + delete vPeriods; vPeriods = 0; +} + +//--------------------------------------------------------------------- + +/** +* checks recurrence data (rrules, rdates, exrules, exdates) +* called after loading (postload check) +*/ +/* +void checkRecurrence() +{ + setRRules(Recurrence.rulesCheck(getRRules())); + setExRules(Recurrence.rulesCheck(getExRules())); + + setRDates(dateChecker(getRDates(), TRUE)); + setExDates(dateChecker(getExDates(), FALSE)); +} +*/ + +//--------------------------------------------------------------------- + +/** +* check the range of the property +* @param sPropName property names +* @param sPropValue property value +* @param sRange valid range of property values +*/ +/* +void checkRange(UnicodeString sPropName, UnicodeString sPropValue, UnicodeString sRange[]) { + t_boolean b = FALSE; + + if (sPropName.equalsIgnoreCase(PropertyKeywords.JulianKeyword::Instance()->ms_sCLASS)) { + if (ParserUtil.isXToken(sPropValue)) + return; + else { + b = ParserUtil.checkRange(sPropValue, sRange); + if (!b) { + DebugMsg.Instance().println(0, "Bad value " + sPropValue + " for property " + sPropName); + LogStream.Instance().println(2, Utility.ErrorMsg("InvalidPropertyValue") + + " TimeBasedEvent:" + sPropValue); + setRequestStatus(Utility.ErrorMsg("RS201") + ";" + PropertyKeywords.JulianKeyword::Instance()->ms_sCLASS); + setDefaultProps(sPropName); + } + return; + } + } + else { + b = ParserUtil.checkRange(sPropValue, sRange); + if (!b) { + DebugMsg.Instance().println(0, "Bad value: " + sPropValue + " for property " + sPropName); + LogStream.Instance().println(2, Utility.ErrorMsg("InvalidPropertyValue") + + " TimeBasedEvent:" + sPropValue); + setRequestStatus(Utility.ErrorMsg("RS201") + ";" + sPropName); + setDefaultProps(sPropName); + } + return; + } + } + + */ + +//--------------------------------------------------------------------- + +/** + * sets default of property + * @param sPropName property name + */ + /* +void TimeBasedEvent::setDefaultProps(UnicodeString sPropName) { + + UnicodeString u; + t_int32 hashCode = sPropName.hashCode(); + + if (JulianKeyword::Instance()->ms_ATOM_DESCRIPTION == hashCode) { + //LogStream.Instance().println(0, Utility.ErrorMsg("DefaultTBEDescription")); + // Setting default Description to empty string + //if (getDescription( == hashCode) { + // initializeDescription(); + // Vector vDescLines = new Vector(); + // vDescLines.addElement(""); + // loadDescription(vDescLines); + //} + u = getSummary(); + setDescription(u); + } + else if (JulianKeyword::Instance()->ms_ATOM_CLASS == hashCode) { + //LogStream.Instance().println(0, Utility.ErrorMsg("DefaultTBEClass")); + u = ""; + setClass(u); + } + else if (JulianKeyword::Instance()->ms_ATOM_STATUS == hashCode) { + //LogStream.Instance().println(0, Utility.ErrorMsg("DefaultTBEStatus")); + u = ""; + setStatus(u); + } + //else if (sPropName.equalsIgnoreCase(PropertyKeywords.JulianKeyword::Instance()->ms_sTRANSP)) { + // LogStream.Instance().println(0, Utility.ErrorMsg("DefaultTBETransp")); + // setTransp(PropertyKeywords.JulianKeyword::Instance()->ms_sOPAQUE); + //} + else if (JulianKeyword::Instance()->ms_ATOM_REQUESTSTATUS == hashCode) { + //LogStream.Instance().println(0, Utility.ErrorMsg("DefaultTBERequestStatus")); + u = ""; + setRequestStatus(u); + } +} +*/ +//--------------------------------------------------------------------- + +void TimeBasedEvent::selfCheck() +{ + if (getSummary().size() == 0) + { + // set summary to first 60 characters of description + if (getDescription().size() > 0) + { + UnicodeString u = getDescription(); + if (u.size() > 60) + u = u.removeBetween(60, u.size()); + setSummary(u); + } + } + + // if sequence is null, set to 0. + if (getSequence() == -1) + setSequence(0); + + // NOTE: setting default CLASS to PUBLIC if CLASS is invalid or not in range + if (getClass().size() == 0 || + (getClass().compareIgnoreCase(JulianKeyword::Instance()->ms_sPRIVATE) != 0) && + (getClass().compareIgnoreCase(JulianKeyword::Instance()->ms_sPUBLIC) != 0) && + (getClass().compareIgnoreCase(JulianKeyword::Instance()->ms_sCONFIDENTIAL) != 0)) + + { + setClass(JulianKeyword::Instance()->ms_sPUBLIC); + } +} + +//--------------------------------------------------------------------- +// GETTERS AND SETTERS here +//--------------------------------------------------------------------- +// method +void TimeBasedEvent::setMethod(UnicodeString & s) +{ + m_sMethod = s; +} +//--------------------------------------------------------------------- +// attendees +void TimeBasedEvent::addAttendee(Attendee * a) +{ + if (m_AttendeesVctr == 0) + m_AttendeesVctr = new JulianPtrArray(); + PR_ASSERT(m_AttendeesVctr != 0); + if (m_AttendeesVctr != 0) + { + m_AttendeesVctr->Add(a); + } +} +//--------------------------------------------------------------------- +// alarms +void TimeBasedEvent::addAlarm(VAlarm * a) +{ + if (m_AlarmsVctr == 0) + m_AlarmsVctr = new JulianPtrArray(); + PR_ASSERT(m_AlarmsVctr != 0); + if (m_AlarmsVctr != 0) + { + m_AlarmsVctr->Add(a); + } +} +//--------------------------------------------------------------------- +//LAST-MODIFIED +void TimeBasedEvent::setLastModified(DateTime s, JulianPtrArray * parameters) +{ +#if 1 + if (m_LastModified == 0) + m_LastModified = ICalPropertyFactory::Make(ICalProperty::DATETIME, + (void *) &s, parameters); + else + { + m_LastModified->setValue((void *) &s); + m_LastModified->setParameters(parameters); + } +#else + ICalComponent::setDateTimeValue(((ICalProperty **) &m_LastModified), s, parameters); +#endif +} + +DateTime TimeBasedEvent::getLastModified() const +{ +#if 1 + DateTime d(-1); + if (m_LastModified == 0) + return d; // return 0; + else + { + d = *((DateTime *) m_LastModified->getValue()); + return d; + } +#else + DateTime d(-1); + ICalComponent::getDateTimeValue(((ICalProperty **) &m_LastModified), d); + return d; +#endif +} +//--------------------------------------------------------------------- +//Created +void TimeBasedEvent::setCreated(DateTime s, JulianPtrArray * parameters) +{ +#if 1 + if (m_Created == 0) + m_Created = ICalPropertyFactory::Make(ICalProperty::DATETIME, + (void *) &s, parameters); + else + { + m_Created->setValue((void *) &s); + m_Created->setParameters(parameters); + } +#else + ICalComponent::setDateTimeValue(((ICalProperty **) &m_Created), s, parameters); +#endif +} +DateTime TimeBasedEvent::getCreated() const +{ +#if 1 + DateTime d(-1); + if (m_Created == 0) + return d;//return 0; + else + { + d = *((DateTime *) m_Created->getValue()); + return d; + } +#else + DateTime d(-1); + ICalComponent::getDateTimeValue(((ICalProperty **) &m_Created), d); + return d; +#endif +} +//--------------------------------------------------------------------- +//Organizer +void TimeBasedEvent::setOrganizer(UnicodeString s, JulianPtrArray * parameters) +{ + //UnicodeString * s_ptr = new UnicodeString(s); + //PR_ASSERT(s_ptr != 0); + + if (m_Organizer == 0) + { + //m_Organizer = ICalPropertyFactory::Make(ICalProperty::TEXT, + // (void *) &s, parameters); + + m_Organizer = (ICalProperty *) new JulianOrganizer(m_Log); + PR_ASSERT(m_Organizer != 0); + if (m_Organizer != 0) + { + m_Organizer->setValue((void *) &s); + m_Organizer->setParameters(parameters); + } + } + else + { + m_Organizer->setValue((void *) &s); + m_Organizer->setParameters(parameters); + } +} +UnicodeString TimeBasedEvent::getOrganizer() const +{ + UnicodeString u; + if (m_Organizer == 0) + return ""; + else { + u = *((UnicodeString *) m_Organizer->getValue()); + return u; + } +} +//--------------------------------------------------------------------- + +//RecurrenceID +void TimeBasedEvent::setRecurrenceID(DateTime s, JulianPtrArray * parameters) +{ + if (m_RecurrenceID == 0) + { + m_RecurrenceID = (ICalProperty *) new JulianRecurrenceID(s, m_Log); + PR_ASSERT(m_RecurrenceID != 0); + if (m_RecurrenceID != 0) + { + m_RecurrenceID->setParameters(parameters); + } + } + else + { + m_RecurrenceID->setValue((void *) &s); + m_RecurrenceID->setParameters(parameters); + } +} +DateTime TimeBasedEvent::getRecurrenceID() const +{ + + DateTime d(-1); + if (m_RecurrenceID == 0) + return d;//return 0; + else + { + d = *((DateTime *) m_RecurrenceID->getValue()); + return d; + } +} +//--------------------------------------------------------------------- +//DTStamp +void TimeBasedEvent::setDTStamp(DateTime s, JulianPtrArray * parameters) +{ +#if 1 + if (m_DTStamp == 0) + m_DTStamp = ICalPropertyFactory::Make(ICalProperty::DATETIME, + (void *) &s, parameters); + else + { + m_DTStamp->setValue((void *) &s); + m_DTStamp->setParameters(parameters); + } +#else + ICalComponent::setDateTimeValue(((ICalProperty **) &m_DTStamp), s, parameters); +#endif +} +DateTime TimeBasedEvent::getDTStamp() const +{ +#if 1 + DateTime d(-1); + if (m_DTStamp == 0) + return d;//return 0; + else + { + d = *((DateTime *) m_DTStamp->getValue()); + return d; + } +#else + DateTime d(-1); + ICalComponent::getDateTimeValue(((ICalProperty **) &m_DTStamp), d); + return d; +#endif +} +//--------------------------------------------------------------------- +///DTStart +void TimeBasedEvent::setDTStart(DateTime s, JulianPtrArray * parameters) +{ +#if 1 + if (m_DTStart == 0) + m_DTStart = ICalPropertyFactory::Make(ICalProperty::DATETIME, + (void *) &s, parameters); + else + { + m_DTStart->setValue((void *) &s); + m_DTStart->setParameters(parameters); + } +#else + ICalComponent::setDateTimeValue(((ICalProperty **) &m_DTStart), s, parameters); +#endif +} + +DateTime TimeBasedEvent::getDTStart() const +{ +#if 1 + DateTime d(-1); + if (m_DTStart == 0) + return d; //return 0; + else + { + d = *((DateTime *) m_DTStart->getValue()); + return d; + } +#else + DateTime d(-1); + ICalComponent::getDateTimeValue(((ICalProperty **) &m_DTStart), d); + return d; +#endif +} +//--------------------------------------------------------------------- +//Description +void TimeBasedEvent::setDescription(UnicodeString s, JulianPtrArray * parameters) +{ + //UnicodeString * s_ptr = new UnicodeString(s); + //PR_ASSERT(s_ptr != 0); +#if 1 + if (m_Description == 0) + m_Description = ICalPropertyFactory::Make(ICalProperty::TEXT, + (void *) &s, parameters); + else + { + m_Description->setValue((void *) &s); + m_Description->setParameters(parameters); + } +#else + ICalComponent::setStringValue(((ICalProperty **) &m_Description), s, parameters); +#endif +} +UnicodeString TimeBasedEvent::getDescription() const +{ +#if 1 + if (m_Description == 0) + return ""; + else + { + UnicodeString u; + u = *((UnicodeString *) m_Description->getValue()); + return u; + } +#else + UnicodeString us; + ICalComponent::getStringValue(((ICalProperty **) &m_Description), us); + return us; +#endif +} +//--------------------------------------------------------------------- +//URL +void TimeBasedEvent::setURL(UnicodeString s, JulianPtrArray * parameters) +{ + //UnicodeString * s_ptr = new UnicodeString(s); + //PR_ASSERT(s_ptr != 0); +#if 1 + if (m_URL == 0) + m_URL = ICalPropertyFactory::Make(ICalProperty::TEXT, + (void *) &s, parameters); + else + { + m_URL->setValue((void *) &s); + m_URL->setParameters(parameters); + } +#else + ICalComponent::setStringValue(((ICalProperty **) &m_URL), s, parameters); +#endif +} +UnicodeString TimeBasedEvent::getURL() const +{ +#if 1 + if (m_URL == 0) + return ""; + else + { + UnicodeString u; + u = *((UnicodeString *) m_URL->getValue()); + return u; + } +#else + UnicodeString us; + ICalComponent::getStringValue(((ICalProperty **) &m_URL), us); + return us; +#endif +} +//--------------------------------------------------------------------- +//Summary +void TimeBasedEvent::setSummary(UnicodeString s, JulianPtrArray * parameters) +{ + //UnicodeString * s_ptr = new UnicodeString(s); + //PR_ASSERT(s_ptr != 0); +#if 1 + if (m_Summary == 0) + m_Summary = ICalPropertyFactory::Make(ICalProperty::TEXT, + (void *) &s, parameters); + else + { + m_Summary->setValue((void *) &s); + m_Summary->setParameters(parameters); + } +#else + ICalComponent::setStringValue(((ICalProperty **) &m_Summary), s, parameters); +#endif +} +UnicodeString TimeBasedEvent::getSummary() const +{ +#if 1 + if (m_Summary == 0) + return ""; + else + { + UnicodeString u; + u = *((UnicodeString *) m_Summary->getValue()); + return u; + } +#else + UnicodeString us; + ICalComponent::getStringValue(((ICalProperty **) &m_Summary), us); + return us; +#endif +} +//--------------------------------------------------------------------- +//Class +void TimeBasedEvent::setClass(UnicodeString s, JulianPtrArray * parameters) +{ +#if 1 + //UnicodeString * s_ptr = new UnicodeString(s); + //PR_ASSERT(s_ptr != 0); + + if (m_Class == 0) + m_Class = ICalPropertyFactory::Make(ICalProperty::TEXT, + (void *) &s, parameters); + else + { + m_Class->setValue((void *) &s); + m_Class->setParameters(parameters); + } +#else + ICalComponent::setStringValue(((ICalProperty **) &m_Class), s, parameters); +#endif +} +UnicodeString TimeBasedEvent::getClass() const +{ +#if 1 + if (m_Class == 0) + return ""; + else + { + UnicodeString u; + u = *((UnicodeString *) m_Class->getValue()); + return u; + } +#else + UnicodeString us; + ICalComponent::getStringValue(((ICalProperty **) &m_Class), us); + return us; +#endif +} +//--------------------------------------------------------------------- +//Status +void TimeBasedEvent::setStatus(UnicodeString s, JulianPtrArray * parameters) +{ +#if 1 + //UnicodeString * s_ptr = new UnicodeString(s); + //PR_ASSERT(s_ptr != 0); + + if (m_Status == 0) + m_Status = ICalPropertyFactory::Make(ICalProperty::TEXT, + (void *) &s, parameters); + else + { + m_Status->setValue((void *) &s); + m_Status->setParameters(parameters); + } +#else + ICalComponent::setStringValue(((ICalProperty **) &m_Status), s, parameters); +#endif +} + +UnicodeString TimeBasedEvent::getStatus() const +{ +#if 1 + UnicodeString u; + if (m_Status == 0) + return ""; + else + { + u = *((UnicodeString *) m_Status->getValue()); + return u; + } +#else + UnicodeString us; + ICalComponent::getStringValue(((ICalProperty **) &m_Status), us); + return us; +#endif +} +//--------------------------------------------------------------------- +//RequestStatus +#if 0 +// TODO: become a vector +void TimeBasedEvent::setRequestStatus(UnicodeString s, JulianPtrArray * parameters) +{ + //UnicodeString * s_ptr = new UnicodeString(s); + //PR_ASSERT(s_ptr != 0); + + if (m_RequestStatus == 0) + m_RequestStatus = ICalPropertyFactory::Make(ICalProperty::TEXT, + (void *) &s, parameters); + else + { + m_RequestStatus->setValue((void *) &s); + m_RequestStatus->setParameters(parameters); + } +} +UnicodeString TimeBasedEvent::getRequestStatus() const +{ + UnicodeString u; + if (m_RequestStatus == 0) + return ""; + else + { + u = *((UnicodeString *) m_RequestStatus->getValue()); + return u; + } +} +#endif +void TimeBasedEvent::addRequestStatus(UnicodeString s, JulianPtrArray * parameters) +{ + ICalProperty * prop = ICalPropertyFactory::Make(ICalProperty::TEXT, + (void *) &s, parameters); + addRequestStatusProperty(prop); +} +void TimeBasedEvent::addRequestStatusProperty(ICalProperty * prop) +{ + if (m_RequestStatusVctr == 0) + m_RequestStatusVctr = new JulianPtrArray(); + PR_ASSERT(m_RequestStatusVctr != 0); + if (m_RequestStatusVctr != 0) + { + m_RequestStatusVctr->Add(prop); + } +} +//--------------------------------------------------------------------- +//UID +void TimeBasedEvent::setUID(UnicodeString s, JulianPtrArray * parameters) +{ +#if 1 + //UnicodeString * s_ptr = new UnicodeString(s); + //PR_ASSERT(s_ptr != 0); + + if (m_UID == 0) + m_UID = ICalPropertyFactory::Make(ICalProperty::TEXT, + (void *) &s, parameters); + else + { + m_UID->setValue((void *) &s); + m_UID->setParameters(parameters); + } +#else + ICalComponent::setStringValue(((ICalProperty **) &m_UID), s, parameters); +#endif +} +UnicodeString TimeBasedEvent::getUID() const +{ +#if 1 + UnicodeString u; + if (m_UID == 0) + return ""; + else { + u = *((UnicodeString *) m_UID->getValue()); + return u; + } +#else + UnicodeString us; + ICalComponent::getStringValue(((ICalProperty **) &m_UID), us); + return us; +#endif +} + + +//--------------------------------------------------------------------- +//Sequence +void TimeBasedEvent::setSequence(t_int32 i, JulianPtrArray * parameters) +{ +#if 1 + if (m_Sequence == 0) + m_Sequence = ICalPropertyFactory::Make(ICalProperty::INTEGER, + (void *) &i, parameters); + else + { + m_Sequence->setValue((void *) &i); + m_Sequence->setParameters(parameters); + } +#else + ICalComponent::setIntegerValue(((ICalProperty **) &m_Sequence), i, parameters); +#endif +} +t_int32 TimeBasedEvent::getSequence() const +{ +#if 1 + t_int32 i; + if (m_Sequence == 0) + return -1; + else + { + i = *((t_int32 *) m_Sequence->getValue()); + return i; + } +#else + t_int32 i = -1; + ICalComponent::getIntegerValue(((ICalProperty **) &m_Sequence), i); + return i; +#endif + +} +//--------------------------------------------------------------------- +//comment +void TimeBasedEvent::addComment(UnicodeString s, JulianPtrArray * parameters) +{ + ICalProperty * prop = ICalPropertyFactory::Make(ICalProperty::TEXT, + (void *) &s, parameters); + addCommentProperty(prop); +} +void TimeBasedEvent::addCommentProperty(ICalProperty * prop) +{ + if (m_CommentVctr == 0) + m_CommentVctr = new JulianPtrArray(); + PR_ASSERT(m_CommentVctr != 0); + if (m_CommentVctr != 0) + { + m_CommentVctr->Add(prop); + } +} +void TimeBasedEvent::setNewComments(UnicodeString s) +{ + // first delete old comments + if (m_CommentVctr != 0) + { + ICalProperty::deleteICalPropertyVector(m_CommentVctr); + delete m_CommentVctr; m_CommentVctr = 0; + } + addComment(s); +} +//--------------------------------------------------------------------- +// attach +void TimeBasedEvent::addAttach(UnicodeString s, JulianPtrArray * parameters) +{ + ICalProperty * prop = ICalPropertyFactory::Make(ICalProperty::TEXT, + (void *) &s, parameters); + addAttachProperty(prop); +} +void TimeBasedEvent::addAttachProperty(ICalProperty * prop) +{ + if (m_AttachVctr == 0) + m_AttachVctr = new JulianPtrArray(); + PR_ASSERT(m_AttachVctr != 0); + if (m_AttachVctr != 0) + { + m_AttachVctr->Add(prop); + } +} +//--------------------------------------------------------------------- +// RelatedTo +void TimeBasedEvent::addRelatedTo(UnicodeString s, JulianPtrArray * parameters) +{ + ICalProperty * prop = ICalPropertyFactory::Make(ICalProperty::TEXT, + (void *) &s, parameters); + addRelatedToProperty(prop); +} +void TimeBasedEvent::addRelatedToProperty(ICalProperty * prop) +{ + if (m_RelatedToVctr == 0) + m_RelatedToVctr = new JulianPtrArray(); + PR_ASSERT(m_RelatedToVctr != 0); + if (m_RelatedToVctr != 0) + { + m_RelatedToVctr->Add(prop); + } +} +//void TimeBasedEvent::setRelatedTo(UnicodeString s, JulianPtrArray * parameters) +//{ +// //UnicodeString * s_ptr = new UnicodeString(s); +// //PR_ASSERT(s_ptr != 0); +// +// if (m_RelatedTo == 0) +// m_RelatedTo = ICalPropertyFactory::Make(ICalProperty::TEXT, +// (void *) &s, parameters); +// else +// { +// m_RelatedTo->setValue((void *) &s); +// m_RelatedTo->setParameters(parameters); +// } +//} +//UnicodeString TimeBasedEvent::getRelatedTo() const +//{ +// UnicodeString u; +// if (m_RelatedTo == 0) +// return ""; +// else { +// u = *((UnicodeString *) m_RelatedTo->getValue()); +// return u; +// } +//} +//--------------------------------------------------------------------- +// Contact +void TimeBasedEvent::addContact(UnicodeString s, JulianPtrArray * parameters) +{ + ICalProperty * prop = ICalPropertyFactory::Make(ICalProperty::TEXT, + (void *)&s, parameters); + addContactProperty(prop); +} +void TimeBasedEvent::addContactProperty(ICalProperty * prop) +{ + if (m_ContactVctr == 0) + m_ContactVctr = new JulianPtrArray(); + PR_ASSERT(m_ContactVctr != 0); + if (m_ContactVctr != 0) + { + m_ContactVctr->Add(prop); + } +} +//--------------------------------------------------------------------- +// RDate +void TimeBasedEvent::addRDate(UnicodeString s, JulianPtrArray * parameters) +{ + ICalProperty * prop = ICalPropertyFactory::Make(ICalProperty::TEXT, + (void *)&s, parameters); + addRDateProperty(prop); +} +void TimeBasedEvent::addRDateProperty(ICalProperty * prop) +{ + if (m_RDateVctr == 0) + m_RDateVctr = new JulianPtrArray(); + PR_ASSERT(m_RDateVctr != 0); + if (m_RDateVctr != 0) + { + m_RDateVctr->Add(prop); + } +} +//--------------------------------------------------------------------- +// ExDate +void TimeBasedEvent::addExDate(UnicodeString s, JulianPtrArray * parameters) +{ + ICalProperty * prop = ICalPropertyFactory::Make(ICalProperty::TEXT, + (void *)&s, parameters); + addExDateProperty(prop); +} +void TimeBasedEvent::addExDateProperty(ICalProperty * prop) +{ + if (m_ExDateVctr == 0) + m_ExDateVctr = new JulianPtrArray(); + PR_ASSERT(m_ExDateVctr != 0); + if (m_ExDateVctr != 0) + { + m_ExDateVctr->Add(prop); + } +} +//--------------------------------------------------------------------- +// Categories +void TimeBasedEvent::addCategories(UnicodeString s, JulianPtrArray * parameters) +{ + ICalProperty * prop = ICalPropertyFactory::Make(ICalProperty::TEXT, + (void *)&s, parameters); + addCategoriesProperty(prop); +} +void TimeBasedEvent::addCategoriesProperty(ICalProperty * prop) +{ + if (m_CategoriesVctr == 0) + m_CategoriesVctr = new JulianPtrArray(); + PR_ASSERT(m_CategoriesVctr != 0); + if (m_CategoriesVctr != 0) + { + m_CategoriesVctr->Add(prop); + } +} +//--------------------------------------------------------------------- +// XTOKENS +void TimeBasedEvent::addXTokens(UnicodeString s) +{ + if (m_XTokensVctr == 0) + m_XTokensVctr = new JulianPtrArray(); + PR_ASSERT(m_XTokensVctr != 0); + if (m_XTokensVctr != 0) + { + m_XTokensVctr->Add(new UnicodeString(s)); + } +} +/* +// RDate +void TimeBasedEvent::addRDateString(UnicodeString s) +{ + if (m_RDateVctr == 0) + m_RDateVctr = new JulianPtrArray(); + PR_ASSERT(m_RDateVctr != 0); + m_RDateVctr->Add(new UnicodeString(s)); +} +*/ +// RRule +void TimeBasedEvent::addRRuleString(UnicodeString s) +{ + if (m_RRuleVctr == 0) + m_RRuleVctr = new JulianPtrArray(); + PR_ASSERT(m_RRuleVctr != 0); + if (m_RRuleVctr != 0) + { + m_RRuleVctr->Add(new UnicodeString(s)); + } +} +/* +// ExDate +void TimeBasedEvent::addExDateString(UnicodeString s) +{ + if (m_ExDateVctr == 0) + m_ExDateVctr = new JulianPtrArray(); + PR_ASSERT(m_ExDateVctr != 0); + m_ExDateVctr->Add(new UnicodeString(s)); +} +*/ +// ExRule +void TimeBasedEvent::addExRuleString(UnicodeString s) +{ + if (m_ExRuleVctr == 0) + m_ExRuleVctr = new JulianPtrArray(); + PR_ASSERT(m_ExRuleVctr != 0); + if (m_ExRuleVctr != 0) + { + m_ExRuleVctr->Add(new UnicodeString(s)); + } +} +//--------------------------------------------------------------------- + +/* +void +TimeBasedEvent::setDateTimeValue(ICalProperty ** dateTimePropertyPtr, + DateTime inVal, + JulianPtrArray * inParameters) +{ + PR_ASSERT(dateTimePropertyPtr != 0); + if (dateTimePropertyPtr != 0) + { + if (((ICalProperty *) (*dateTimePropertyPtr)) == 0) + { + ((ICalProperty *) (*dateTimePropertyPtr)) = + ICalPropertyFactory::Make(ICalProperty::DATETIME, + (void *) &inVal, inParameters); + } + else + { + ((ICalProperty *) (*dateTimePropertyPtr))->setValue((void *) &inVal); + ((ICalProperty *) (*dateTimePropertyPtr))->setParameters(inParameters); + } + } + //setDateTimeProperty(dateTimeProperty, s, 0); +} + +void +TimeBasedEvent::setDateTimeProperty(ICalProperty * dateTimeProperty, + DateTime * s, JulianPtrArray * parameters) +{ + if (dateTimeProperty == 0) + dateTimeProperty = ICalPropertyFactory::Make(ICalProperty::DATETIME, + (void *) s, parameters); + else + dateTimeProperty->setValue((void *) s); +} + +void TimeBasedEvent::getDateTimeValue(ICalProperty ** dateTimePropertyPtr, + DateTime & dtOut) +{ + PR_ASSERT(dateTimePropertyPtr != 0); + if (dateTimePropertyPtr != 0) + { + if ((ICalProperty *)(*dateTimePropertyPtr) == 0) + dtOut.setTime(-1); + else + dtOut = *((DateTime *) ((ICalProperty *)(*dateTimePropertyPtr))->getValue()); + } + else + { + dtOut.setTime(-1); + } +} +/* +//--------------------------------------------------------------------- + +void +TimeBasedEvent::setStringValue(ICalProperty * stringProperty, + UnicodeString * s) +{ + setStringProperty(stringProperty, s, 0); +} + +void +TimeBasedEvent::setStringProperty(ICalProperty * stringProperty, + UnicodeString * s, JulianPtrArray * parameters) +{ + if (stringProperty == 0) + stringProperty = ICalPropertyFactory::Make(ICalProperty::TEXT, + (void *) s, parameters); + else + stringProperty->setValue((void *) s); +} + +UnicodeString TimeBasedEvent::getStringValue(ICalProperty * stringProperty) const +{ + if (stringProperty == 0) + return ""; + else + return *((UnicodeString *) stringProperty->getValue()); +} +//--------------------------------------------------------------------- + +void +TimeBasedEvent::setIntegerValue(ICalProperty * integerProperty, + t_int32 i) +{ setIntegerProperty(integerProperty, i, 0); } + +void +TimeBasedEvent::setIntegerProperty(ICalProperty * integerProperty, + t_int32 i, JulianPtrArray * parameters) +{ + if (integerProperty == 0) + integerProperty = ICalPropertyFactory::Make(ICalProperty::INTEGER, + (void *) &i, parameters); + else + integerProperty->setValue((void *) i); +} + +t_int32 TimeBasedEvent::getIntegerValue(ICalProperty * integerProperty) const +{ + if (integerProperty == 0) + return -1; + else + return *((t_int32 *) integerProperty->getValue()); +} +//--------------------------------------------------------------------- +void +TimeBasedEvent::setDurationValue(ICalProperty * durationProperty, + Duration * s) +{ + setDurationProperty(durationProperty, s, 0); +} + +void +TimeBasedEvent::setDurationProperty(ICalProperty * durationProperty, + Duration * s, JulianPtrArray * parameters) +{ + if (durationProperty == 0) + durationProperty = ICalPropertyFactory::Make(ICalProperty::DURATION, + (void *) s, parameters); + else + durationProperty->setValue((void *) s); +} + +Duration * TimeBasedEvent::getDurationValue(ICalProperty * durationProperty) const +{ + if (durationProperty == 0) + return 0; + else + return (Duration *) durationProperty->getValue(); +} +*/ +//--------------------------------------------------------------------- + +void +TimeBasedEvent::addCategoriesPropertyVector(UnicodeString & propVal, + JulianPtrArray * parameters) +{ + //ICalProperty * ip; + + // TODO: trying to break each comma seperated element into own property, but + // having trouble, for now, don't break up + //ip = ICalPropertyFactory::Make(ICalProperty::TEXT, new UnicodeString(propVal), + // parameters); + addCategories(propVal, parameters); + + /* + ErrorCode status = ZERO_ERROR; + UnicodeStringTokenizer * st; + UnicodeString us; + UnicodeString sDelim = ","; + + st = new UnicodeStringTokenizer(propVal, sDelim); + + while (st->hasMoreTokens()) + { + us = st->nextToken(us, status); + us.trim(); + //TRACE("us = %s, status = %d", us.toCString(""), status); + // TODO: if us is in categories range then add, else, log and error, + // should I make copies of parameters or not??? + + ip = ICalPropertyFactory::Make(ICalProperty::TEXT, new UnicodeString(us), + parameters); + PR_ASSERT(ip != 0); + addCategoriesProperty(ip); + ip = 0; + } + delete st; st = 0;; + */ +} +//--------------------------------------------------------------------- + diff --git a/calendar/modules/core/ical/src/tzpart.cpp b/calendar/modules/core/ical/src/tzpart.cpp new file mode 100644 index 00000000000..ac9a1ca72f5 --- /dev/null +++ b/calendar/modules/core/ical/src/tzpart.cpp @@ -0,0 +1,1021 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +// tzpart.cpp +// John Sun +// 10:04 AM February 24 1998 + +#include "stdafx.h" +#include "jdefines.h" + +#include "tzpart.h" +#include "prprtyfy.h" +#include "rcrrence.h" +#include "jlog.h" +#include "keyword.h" + +#include "functbl.h" +//--------------------------------------------------------------------- + +// private never use +#if 0 +TZPart::TZPart() +{ + PR_ASSERT(FALSE); +} +#endif +//--------------------------------------------------------------------- + +TZPart::TZPart(JLog * initLog) +: m_CommentVctr(0), m_DTStart(0), m_TZNameVctr(0), m_TZOffsetTo(0), + m_TZOffsetFrom(0), m_RDate(0), m_RRule(0), + m_StartMonth(-1), m_StartDay(-1), m_StartWeek(0), m_StartTime(0), + m_XTokensVctr(0), + m_iStartYear(0), m_iStartMonth(0), m_iStartDay(0), m_iStartHour(0), m_iStartMinute(0), m_iStartSecond(0), + m_iRDateYear(0), m_iRDateMonth(0), m_iRDateDay(0), m_iRDateHour(0), m_iRDateMinute(0), m_iRDateSecond(0), + m_Log(initLog) +{ + + m_Until.setTime(-1); +} + +//--------------------------------------------------------------------- + +TZPart::TZPart(TZPart & that) +: m_CommentVctr(0), m_DTStart(0), m_TZNameVctr(0), m_TZOffsetTo(0), + m_TZOffsetFrom(0), m_RDate(0), m_RRule(0), + m_iStartYear(0), m_iStartMonth(0), m_iStartDay(0), m_iStartHour(0), m_iStartMinute(0), m_iStartSecond(0), + m_iRDateYear(0), m_iRDateMonth(0), m_iRDateDay(0), m_iRDateHour(0), m_iRDateMinute(0), m_iRDateSecond(0), + m_XTokensVctr(0) +{ + m_StartMonth = that.m_StartMonth; + m_StartDay = that.m_StartDay; + m_StartWeek = that.m_StartWeek; + m_StartTime = that.m_StartTime; + m_Until = that.m_Until; + m_Name = that.m_Name; + + m_iStartYear = that.m_iStartYear; + m_iStartMonth = that.m_iStartMonth; + m_iStartDay = that.m_iStartDay; + m_iStartHour = that.m_iStartHour; + m_iStartMinute = that.m_iStartMinute; + m_iStartSecond = that.m_iStartSecond; + + m_iRDateYear = that.m_iRDateYear; + m_iRDateMonth = that.m_iRDateMonth; + m_iRDateDay = that.m_iRDateDay; + m_iRDateHour = that.m_iRDateHour; + m_iRDateMinute = that.m_iRDateMinute; + m_iRDateSecond = that.m_iRDateSecond; + + if (that.m_CommentVctr != 0) + { + m_CommentVctr = new JulianPtrArray(); PR_ASSERT(m_CommentVctr != 0); + if (m_CommentVctr != 0) + { + ICalProperty::CloneICalPropertyVector(that.m_CommentVctr, m_CommentVctr, m_Log); + } + } + + if (that.m_DTStart != 0) { m_DTStart = that.m_DTStart->clone(m_Log); } + + if (that.m_TZNameVctr != 0) + { + m_TZNameVctr = new JulianPtrArray(); PR_ASSERT(m_TZNameVctr != 0); + if (m_TZNameVctr != 0) + { + ICalProperty::CloneICalPropertyVector(that.m_TZNameVctr, m_TZNameVctr, m_Log); + } + } + if (that.m_TZOffsetTo != 0) + { + m_TZOffsetTo = that.m_TZOffsetTo->clone(m_Log); + } + if (that.m_TZOffsetFrom != 0) + { + m_TZOffsetFrom = that.m_TZOffsetFrom->clone(m_Log); + } + if (that.m_RDate != 0) + { + m_RDate = that.m_RDate->clone(m_Log); + } + if (that.m_RRule != 0) + { + m_RRule = that.m_RRule->clone(m_Log); + } + if (that.m_XTokensVctr != 0) + { + m_XTokensVctr = new JulianPtrArray(); PR_ASSERT(m_XTokensVctr != 0); + if (m_XTokensVctr != 0) + { + ICalProperty::CloneUnicodeStringVector(that.m_XTokensVctr, m_XTokensVctr); + } + } +} +//--------------------------------------------------------------------- +ICalComponent * +TZPart::clone(JLog * initLog) +{ + m_Log = initLog; + //PR_ASSERT(m_Log != 0); + return new TZPart(*this); +} +//--------------------------------------------------------------------- + +TZPart::~TZPart() +{ + if (m_CommentVctr != 0) + { + ICalProperty::deleteICalPropertyVector(m_CommentVctr); + delete m_CommentVctr; m_CommentVctr = 0; + } + if (m_TZNameVctr != 0) + { + ICalProperty::deleteICalPropertyVector(m_TZNameVctr); + delete m_TZNameVctr; m_TZNameVctr = 0; + } + if (m_DTStart != 0) + { + delete m_DTStart; m_DTStart = 0; + } + if (m_RDate != 0) + { + delete m_RDate; m_RDate = 0; + } + if (m_RRule != 0) + { + delete m_RRule; m_RRule = 0; + } + if (m_TZOffsetTo != 0) + { + delete m_TZOffsetTo; m_TZOffsetTo = 0; + } + if (m_TZOffsetFrom != 0) + { + delete m_TZOffsetFrom; m_TZOffsetFrom = 0; + } + if (m_XTokensVctr != 0) + { + ICalComponent::deleteUnicodeStringVector(m_XTokensVctr); + delete m_XTokensVctr; m_XTokensVctr = 0; + } +} + +//--------------------------------------------------------------------- +UnicodeString & +TZPart::parse(ICalReader * brFile, UnicodeString & sType, + UnicodeString & parseStatus, JulianPtrArray * vTimeZones, + t_bool bIgnoreBeginError, + JulianUtility::MimeEncoding encoding) +{ + UnicodeString strLine, propName, propVal; + JulianPtrArray * parameters = new JulianPtrArray(); + parseStatus = JulianKeyword::Instance()->ms_sOK; + + PR_ASSERT(parameters != 0 && brFile != 0); + if (parameters == 0 || brFile == 0) + { + // ran out of memory, return invalid tzpart + return parseStatus; + } + ErrorCode status = ZERO_ERROR; + + setName(sType); + + // NOTE: Remove later to remove a stupid compile warning + if (vTimeZones && bIgnoreBeginError){} + + while (TRUE) + { + PR_ASSERT(brFile != 0); + brFile->readFullLine(strLine, status); + ICalProperty::Trim(strLine); + + if (FAILURE(status) && strLine.size() == 0) + break; + + ICalProperty::parsePropertyLine(strLine, propName, propVal, parameters); + + if (strLine.size() == 0) + { + ICalProperty::deleteICalParameterVector(parameters); + parameters->RemoveAll(); + + continue; + } + // END:STANDARD OR END:DAYLIGHT (sType = daylight or standard) + else if ((propName.compareIgnoreCase(JulianKeyword::Instance()->ms_sEND) == 0) && + (propVal.compareIgnoreCase(sType) == 0)) + { + ICalProperty::deleteICalParameterVector(parameters); + parameters->RemoveAll(); + + break; + } + else if ( + ((propName.compareIgnoreCase(JulianKeyword::Instance()->ms_sEND) == 0) && + ( + (propVal.compareIgnoreCase(JulianKeyword::Instance()->ms_sVTIMEZONE) == 0) || + (propVal.compareIgnoreCase(JulianKeyword::Instance()->ms_sVCALENDAR) == 0) || + (propVal.compareIgnoreCase(JulianKeyword::Instance()->ms_sVEVENT) == 0) || + (propVal.compareIgnoreCase(JulianKeyword::Instance()->ms_sVTODO) == 0) || + (propVal.compareIgnoreCase(JulianKeyword::Instance()->ms_sVJOURNAL) == 0) || + (propVal.compareIgnoreCase(JulianKeyword::Instance()->ms_sVFREEBUSY) == 0) || + (ICalProperty::IsXToken(propVal)) + )) + || + ((propName.compareIgnoreCase(JulianKeyword::Instance()->ms_sBEGIN) == 0) && + ( + (propVal.compareIgnoreCase(JulianKeyword::Instance()->ms_sDAYLIGHT) == 0) || + (propVal.compareIgnoreCase(JulianKeyword::Instance()->ms_sSTANDARD) == 0) || + (propVal.compareIgnoreCase(JulianKeyword::Instance()->ms_sVEVENT) == 0) || + (propVal.compareIgnoreCase(JulianKeyword::Instance()->ms_sVTODO) == 0) || + (propVal.compareIgnoreCase(JulianKeyword::Instance()->ms_sVJOURNAL) == 0) || + (propVal.compareIgnoreCase(JulianKeyword::Instance()->ms_sVFREEBUSY) == 0) || + (propVal.compareIgnoreCase(JulianKeyword::Instance()->ms_sVTIMEZONE) == 0) || + (ICalProperty::IsXToken(propVal)) + ))) + { + // abrupt end + // BEGIN:DAYLIGHT or BEGIN:STANDARD + // BEGIN:VEVENT, VTODO, VJOURNAL, VTIMEZONE, VFREEBUSY, xtoken + // END:VTIMEZONE, END:VCALENDAR + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iAbruptEndOfParsing, + JulianKeyword::Instance()->ms_sTZPART, strLine, 300); + ICalProperty::deleteICalParameterVector(parameters); + parameters->RemoveAll(); + + parseStatus = strLine; + break; + } + else + { + storeData(strLine, propName, propVal, parameters); + ICalProperty::deleteICalParameterVector(parameters); + parameters->RemoveAll(); + } + } + ICalProperty::deleteICalParameterVector(parameters); + parameters->RemoveAll(); + delete parameters; parameters = 0; + + selfCheck(); + return parseStatus; +} + +//--------------------------------------------------------------------- +void TZPart::storeData(UnicodeString & strLine, UnicodeString & propName, + UnicodeString & propVal, JulianPtrArray * parameters) +{ + t_int32 hashCode = propName.hashCode(); + t_int32 i; + for (i = 0; 0 != (JulianFunctionTable::Instance()->tzStoreTable[i]).op; i++) + { + if ((JulianFunctionTable::Instance()->tzStoreTable[i]).hashCode == hashCode) + { + ApplyStoreOp(((JulianFunctionTable::Instance())->tzStoreTable[i]).op, + strLine, propVal, parameters, 0); + return; + } + } + if (ICalProperty::IsXToken(propName)) + { + addXTokens(strLine); + } + else + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iInvalidPropertyName, + JulianKeyword::Instance()->ms_sTZPART, propName, 200); + } +} +//--------------------------------------------------------------------- +void TZPart::storeComment(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones) +{ + // check parameters + t_bool bParamValid = ICalProperty::CheckParams(parameters, + JulianAtomRange::Instance()->ms_asAltrepLanguageParamRange, + JulianAtomRange::Instance()->ms_asAltrepLanguageParamRangeSize); + + if (!bParamValid) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iInvalidOptionalParam, + JulianKeyword::Instance()->ms_sTZPART, strLine, 100); + } + + addComment(propVal, parameters); +} +void TZPart::storeTZName(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones) +{ + // check parameters + t_bool bParamValid = ICalProperty::CheckParams(parameters, + JulianAtomRange::Instance()->ms_asLanguageParamRange, + JulianAtomRange::Instance()->ms_asLanguageParamRangeSize); + if (!bParamValid) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iInvalidOptionalParam, + JulianKeyword::Instance()->ms_sTZPART, strLine, 100); + } + + addTZName(propVal, parameters); +} +void TZPart::storeDTStart(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones) +{ + // assert in local time + // no parameters + if (parameters->GetSize() > 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iInvalidOptionalParam, + JulianKeyword::Instance()->ms_sTZPART, strLine, 100); + } + + if (getDTStartProperty() != 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iDuplicatedProperty, + JulianKeyword::Instance()->ms_sTZPART, + JulianKeyword::Instance()->ms_sDTSTART, 100); + } + DateTime d(propVal); + if (DateTime::IsParseable(propVal, m_iStartYear, m_iStartMonth, m_iStartDay, + m_iStartHour, m_iStartMinute, m_iStartSecond)) + { + m_StartTime = (t_int32) ((m_iStartHour * 3600 + m_iStartMinute * 60) * 1000); // set start time in millis + } + setDTStart(d, parameters); +} +void TZPart::storeRDate(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones) +{ + // assert in local time + // no parameters + if (parameters->GetSize() > 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iInvalidOptionalParam, + JulianKeyword::Instance()->ms_sTZPART, strLine, 100); + } + + if (getRDateProperty() != 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iDuplicatedProperty, + JulianKeyword::Instance()->ms_sTZPART, + JulianKeyword::Instance()->ms_sRDATE, 100); + } + // DONE:?TODO: Finish + DateTime d(propVal); + DateTime::IsParseable(propVal, m_iRDateYear, m_iRDateMonth, m_iRDateDay, + m_iRDateHour, m_iRDateMinute, m_iRDateSecond); + setRDate(d, parameters); +} +void TZPart::storeRRule(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones) +{ + // no parameters + if (parameters->GetSize() > 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iInvalidOptionalParam, + JulianKeyword::Instance()->ms_sTZPART, strLine, 100); + } + + if (getRRuleProperty() != 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iDuplicatedProperty, + JulianKeyword::Instance()->ms_sTZPART, + JulianKeyword::Instance()->ms_sRRULE, 100); + } + setRRule(propVal, parameters); +} +void TZPart::storeTZOffsetTo(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones) +{ + // no parameters + if (parameters->GetSize() > 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iInvalidOptionalParam, + JulianKeyword::Instance()->ms_sTZPART, strLine, 100); + } + + if (getTZOffsetToProperty() != 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iDuplicatedProperty, + JulianKeyword::Instance()->ms_sTZPART, + JulianKeyword::Instance()->ms_sTZOFFSETTO, 100); + } + setTZOffsetTo(propVal, parameters); +} +void TZPart::storeTZOffsetFrom(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones) +{ + // no parameters + if (parameters->GetSize() > 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iInvalidOptionalParam, + JulianKeyword::Instance()->ms_sTZPART, strLine, 100); + } + + if (getTZOffsetFromProperty() != 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iDuplicatedProperty, + JulianKeyword::Instance()->ms_sTZPART, + JulianKeyword::Instance()->ms_sTZOFFSETFROM, 100); + } + setTZOffsetFrom(propVal, parameters); +} +//--------------------------------------------------------------------- +void TZPart::selfCheck() +{ + //if (FALSE) TRACE("starttime = %d, startmonth = %d, startday = %d, startweek = %d\r\n", m_StartTime, m_StartMonth, m_StartDay, m_StartWeek); + // TODO: finish + //parseRule(); +} +//--------------------------------------------------------------------- +t_bool TZPart::isValid() +{ + UnicodeString u; + + // TODO: log that if not parseable TZOFFSETTO:, TZOFFSETFROM: + // required to have valid dtstart, tzoffsetTo, tzoffsetFrom + if (!getDTStart().isValid()) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iMissingStartingTime, + JulianKeyword::Instance()->ms_sTZPART, u, 300); + return FALSE; + } + u = getTZOffsetTo(); + if (!DateTime::IsParseableUTCOffset(u)) + return FALSE; + + u = getTZOffsetFrom(); + if (!DateTime::IsParseableUTCOffset(u)) + return FALSE; + + return TRUE; +} + +//--------------------------------------------------------------------- + +UnicodeString TZPart::toICALString() +{ + return ICalComponent::format(m_Name, JulianFormatString::Instance()->ms_sTZPartAllMessage, ""); +} + +//--------------------------------------------------------------------- + +UnicodeString TZPart::toICALString(UnicodeString method, + UnicodeString name, + t_bool isRecurring) +{ + // NOTE: remove later avoid warnings + if (isRecurring) {} + return toICALString(); +} + +//--------------------------------------------------------------------- +UnicodeString TZPart::formatChar(t_int32 c, UnicodeString sFilterAttendee, + t_bool delegateRequest) +{ + UnicodeString s, sResult; + // NOTE: remove here is get rid of compiler warnings + if (sFilterAttendee.size() > 0 || delegateRequest) + { + } + + switch (c) + { + case ms_cComment: + s = JulianKeyword::Instance()->ms_sCOMMENT; + return ICalProperty::propertyVectorToICALString(s, getComment(), sResult); + case ms_cTZName: + s = JulianKeyword::Instance()->ms_sTZNAME; + return ICalProperty::propertyVectorToICALString(s, getTZName(), sResult); + case ms_cDTStart: +#if 0 + s = JulianKeyword::Instance()->ms_sDTSTART; + return ICalProperty::propertyToICALString(s, getDTStartProperty(), sResult); +#else + if (getDTStartProperty() != 0) + { + sResult += JulianKeyword::Instance()->ms_sDTSTART; + sResult += JulianKeyword::Instance()->ms_sCOLON_SYMBOL; + DateTime::ToISO8601String(m_iStartYear, m_iStartMonth, m_iStartDay, + m_iStartHour, m_iStartMinute, m_iStartSecond, s); + sResult += s; + sResult += JulianKeyword::Instance()->ms_sLINEBREAK; + } + return sResult; +#endif + case ms_cRDate: +#if 0 + s = JulianKeyword::Instance()->ms_sRDATE; + return ICalProperty::propertyToICALString(s, getRDateProperty(), sResult); +#else + if (getRDateProperty() != 0) + { + sResult += JulianKeyword::Instance()->ms_sRDATE; + sResult += JulianKeyword::Instance()->ms_sCOLON_SYMBOL; + DateTime::ToISO8601String(m_iRDateYear, m_iRDateMonth, m_iRDateDay, + m_iRDateHour, m_iRDateMinute, m_iRDateSecond, s); + sResult += s; + sResult += JulianKeyword::Instance()->ms_sLINEBREAK; + } + return sResult; +#endif + case ms_cRRule: + s = JulianKeyword::Instance()->ms_sRRULE; + return ICalProperty::propertyToICALString(s, getRRuleProperty(), sResult); + case ms_cTZOffsetTo: + s = JulianKeyword::Instance()->ms_sTZOFFSETTO; + return ICalProperty::propertyToICALString(s, getTZOffsetToProperty(), sResult); + case ms_cTZOffsetFrom: + s = JulianKeyword::Instance()->ms_sTZOFFSETFROM; + return ICalProperty::propertyToICALString(s, getTZOffsetFromProperty(), sResult); + case ms_cXTokens: + return ICalProperty::vectorToICALString(getXTokens(), sResult); + default: + return ""; + } +} + +//--------------------------------------------------------------------- +UnicodeString TZPart::toStringChar(t_int32 c, UnicodeString & dateFmt) +{ + UnicodeString s; + switch (c) + { + case ms_cComment: + return ICalProperty::propertyVectorToString(getComment(), s); + case ms_cTZName: + return ICalProperty::propertyVectorToString(getTZName(), s); + case ms_cDTStart: + return ICalProperty::propertyToString(getDTStartProperty(), dateFmt, s); + case ms_cRDate: + return ICalProperty::propertyToString(getRDateProperty(), dateFmt, s); + case ms_cRRule: + return ICalProperty::propertyToString(getRRuleProperty(), dateFmt, s); + case ms_cTZOffsetTo: + return ICalProperty::propertyToString(getTZOffsetToProperty(), dateFmt, s); + case ms_cTZOffsetFrom: + return ICalProperty::propertyToString(getTZOffsetFromProperty(), dateFmt, s); + default: + return ""; + } +} +//--------------------------------------------------------------------- + +UnicodeString TZPart::toString() +{ + return ICalComponent::toStringFmt( + JulianFormatString::Instance()->ms_TZPartStrDefaultFmt); +} + +//--------------------------------------------------------------------- +void TZPart::setName(UnicodeString s) +{ + m_Name = s; +} +//--------------------------------------------------------------------- +#if 0 +t_bool TZPart::parseRule() +{ + if (getRDate().isValid()) + { + parseRDate(); + return TRUE; + } + else + { + return parseRRule(); + } +} +#endif +//--------------------------------------------------------------------- +void TZPart::parseRDate() +{ + PR_ASSERT(getRDate().isValid()); + if (getRDate().isValid()) + { + DateTime d; + d = getRDate(); + + m_StartMonth = d.get(Calendar::MONTH); + m_StartWeek = d.get(Calendar::DAY_OF_WEEK_IN_MONTH); + m_StartDay = d.get(Calendar::DAY_OF_WEEK); + } +} +//--------------------------------------------------------------------- +t_bool TZPart::parseRRule() +{ + t_int32 i; + UnicodeString pN, pV, s, strLine; + ICalParameter * ip; + t_bool bParseError = FALSE; + ErrorCode status = ZERO_ERROR; + + // TODO: insert assertion that Recurrence::isValidRRule(getRRule()); + strLine = getRRule(); + //if (FALSE) TRACE("line (size = %d) = ---%s---\r\n", strLine.size(), strLine.toCString("")); + + // manipulating string so I can use the parsePropertyLine method + strLine += ':'; //JulianKeyword::Instance()->ms_sCOLON_SYMBOL; + strLine.insert(0, JulianKeyword::Instance()->ms_sRRULE_WITH_SEMICOLON); + //if (FALSE) TRACE("line (size = %d) = ---%s---\r\n", strLine.size(), strLine.toCString("")); + + JulianPtrArray * parameters = new JulianPtrArray(); + PR_ASSERT(parameters != 0); + if (parameters == 0) + { + return FALSE; + } + + ICalProperty::parsePropertyLine(strLine, pN, pV, parameters); + //if (FALSE) TRACE("pN = --%s--, pV = --%s--, paramSize = %d\r\n", pN.toCString(""), pV.toCString(""), parameters->GetSize()); + + for (i = 0; i < parameters->GetSize(); i++) + { + ip = (ICalParameter *) parameters->GetAt(i); + + pN = ip->getParameterName(pN); + pV = ip->getParameterValue(pV); + //if (FALSE) TRACE("pN = --%s--, pV = --%s--, paramSize = %d\r\n", pN.toCString(""), pV.toCString(""), parameters->GetSize()); + + if (pN.compareIgnoreCase(JulianKeyword::Instance()->ms_sBYMONTH) == 0) + { + // since month is 0-based, must subtract 1 + char * pVcc = pV.toCString(""); + PR_ASSERT(pVcc != 0); + m_StartMonth = JulianUtility::atot_int32(pVcc, bParseError, pV.size()) - 1; + delete [] pVcc; pVcc = 0; + } + else if (pN.compareIgnoreCase(JulianKeyword::Instance()->ms_sBYDAY) == 0) + { + if (pV.size() == 3) + { + // positive week + char * pVcc = pV.toCString(""); + PR_ASSERT(pVcc != 0); + m_StartWeek = JulianUtility::atot_int32(pVcc, bParseError, 1); + delete [] pVcc; pVcc = 0; + m_StartDay = Recurrence::stringToDay(pV.extract(1, 2, s), bParseError); + } + else + { + PR_ASSERT(pV.size() == 4); // note: assumption is pV.size() == 4 + + char * pVcc = pV.toCString(""); + PR_ASSERT(pVcc != 0); + m_StartWeek = JulianUtility::atot_int32(pVcc + 1, bParseError, 1); // (always len = 1) + delete [] pVcc; pVcc = 0; + m_StartDay = Recurrence::stringToDay(pV.extract(2, 2, s), bParseError); // SU, MO, TU, etc. (always len = 2) + + if (pV[(TextOffset) 0] == '-') + m_StartWeek = 0 - m_StartWeek; + else if (pV[(TextOffset) 0] == '+') { } + else { bParseError = TRUE; } + + // ugly way to handle sign handling + //s = pV.extract(0, 1, s); + //if (s == "-") m_StartWeek = - m_StartWeek; + //else if (s == "+") {} + //else { bParseError = TRUE; } + } + } + else if (pN.compareIgnoreCase(JulianKeyword::Instance()->ms_sUNTIL) == 0) + { + m_Until.setTimeString(pV); + } + } + ICalProperty::deleteICalParameterVector(parameters); + delete parameters; parameters = 0; + // if assertion failed return FALSE. + if(!(m_StartMonth != -1 && m_StartDay != -1 && m_StartWeek != 0)) + { + return FALSE; + } + if (bParseError || FAILURE(status)) + { + // BAD RRULE was parsed + m_StartMonth = -1; + m_StartDay = -1; + m_StartWeek = 0; + return FALSE; + } + return TRUE; +} +//--------------------------------------------------------------------- +float TZPart::UTCOffsetToFloat(UnicodeString & utcOffset) +{ + t_int32 hour = 0, minute = 0; + if (DateTime::IsParseableUTCOffset(utcOffset, hour, minute)) + { + return (float) (hour + (minute / 60)); + } + PR_ASSERT(FALSE); // all calls should return from above return statement + return 0; +} + +//--------------------------------------------------------------------- + +void +TZPart::updateComponentHelper(TZPart * updatedComponent) +{ + // no need: TZName + ICalComponent::internalSetProperty(&m_DTStart, updatedComponent->m_DTStart); + ICalComponent::internalSetProperty(&m_RDate, updatedComponent->m_RDate); + ICalComponent::internalSetProperty(&m_RRule, updatedComponent->m_RRule); + ICalComponent::internalSetProperty(&m_TZOffsetTo, updatedComponent->m_TZOffsetTo); + ICalComponent::internalSetProperty(&m_TZOffsetFrom, updatedComponent->m_TZOffsetFrom); + ICalComponent::internalSetXTokensVctr(&m_XTokensVctr, updatedComponent->m_XTokensVctr); +} + +//--------------------------------------------------------------------- + +t_bool +TZPart::updateComponent(ICalComponent * updatedComponent) +{ + if (updatedComponent != 0) + { + ICAL_COMPONENT ucType = updatedComponent->GetType(); + + // only call updateComponentHelper if it's a TZPart and + // it is an exact matching Name (STANDARD or DAYLIGHT) + // basically always overwrite + if (ucType == ICAL_COMPONENT_TZPART) + { + // should be a safe cast with check above. + TZPart * uctzp = (TZPart *) updatedComponent; + + // only if TZID's match and are not empty + if (uctzp->getName().size() > 0 && getName().size() > 0) + { + if (uctzp->getName() == getName()) + { + updateComponentHelper(uctzp); + selfCheck(); + return TRUE; + } + } + } + } + return FALSE; +} +//--------------------------------------------------------------------- + +//Comment +void TZPart::addComment(UnicodeString s, JulianPtrArray * parameters) +{ + //ICalProperty * prop = ICalPropertyFactory::Make(ICalProperty::TEXT, + // new UnicodeString(s), 0); + + ICalProperty * prop = + ICalPropertyFactory::Make(ICalProperty::TEXT, + (void *) &s, parameters); + + addCommentProperty(prop); +} +void TZPart::addCommentProperty(ICalProperty * prop) +{ + if (m_CommentVctr == 0) + m_CommentVctr = new JulianPtrArray(); + PR_ASSERT(m_CommentVctr != 0); + if (m_CommentVctr != 0) + { + m_CommentVctr->Add(prop); + } +} + +//--------------------------------------------------------------------- +//TZName +void TZPart::addTZName(UnicodeString s, JulianPtrArray * parameters) +{ + //ICalProperty * prop = ICalPropertyFactory::Make(ICalProperty::TEXT, + // new UnicodeString(s), 0); + + ICalProperty * prop = + ICalPropertyFactory::Make(ICalProperty::TEXT, + (void *) &s, parameters); + + addTZNameProperty(prop); +} +void TZPart::addTZNameProperty(ICalProperty * prop) +{ + if (m_TZNameVctr == 0) + m_TZNameVctr = new JulianPtrArray(); + PR_ASSERT(m_TZNameVctr != 0); + if (m_TZNameVctr != 0) + { + m_TZNameVctr->Add(prop); + } +} +//--------------------------------------------------------------------- +// DTStart +void TZPart::setDTStart(DateTime s, JulianPtrArray * parameters) +{ +#if 1 + if (m_DTStart == 0) + m_DTStart = ICalPropertyFactory::Make(ICalProperty::DATETIME, + (void *) &s, parameters); + else + { + m_DTStart->setValue((void *) &s); + m_DTStart->setParameters(parameters); + } +#else + ICalComponent::setDateTimeValue(((ICalProperty **) &m_DTStart), s, parameters); +#endif +} + +DateTime TZPart::getDTStart() const +{ +#if 1 + DateTime d(-1); + if (m_DTStart == 0) + return d; //return 0; + else + { + d = *((DateTime *) m_DTStart->getValue()); + return d; + } +#else + DateTime d(-1); + ICalComponent::getDateTimeValue(((ICalProperty **) &m_DTStart), d); + return d; +#endif +} +//--------------------------------------------------------------------- +// RDate +// TODO: become a vector +void TZPart::setRDate(DateTime s, JulianPtrArray * parameters) +{ + if (m_RDate == 0) + m_RDate = ICalPropertyFactory::Make(ICalProperty::DATETIME, + (void *) &s, parameters); + else + { + m_RDate->setValue((void *) &s); + m_RDate->setParameters(parameters); + } + parseRDate(); +} + +DateTime TZPart::getRDate() const +{ + DateTime d(-1); + if (m_RDate == 0) + return d; //return 0; + else + { + d = *((DateTime *) m_RDate->getValue()); + return d; + } +} +//--------------------------------------------------------------------- +//RRule +// TODO: become a vector +void TZPart::setRRule(UnicodeString s, JulianPtrArray * parameters) +{ + //UnicodeString * s_ptr = new UnicodeString(s); + //PR_ASSERT(s_ptr != 0); + + if (m_RRule == 0) + m_RRule = ICalPropertyFactory::Make(ICalProperty::TEXT, + (void *) &s, parameters); + else + { + m_RRule->setValue((void *) &s); + m_RRule->setParameters(parameters); + } + parseRRule(); +} +UnicodeString TZPart::getRRule() const +{ + UnicodeString u; + if (m_RRule == 0) + return ""; + else + { + u = *((UnicodeString *) m_RRule->getValue()); + return u; + } +} +//--------------------------------------------------------------------- +//TZOffsetTo +void TZPart::setTZOffsetTo(UnicodeString s, JulianPtrArray * parameters) +{ +#if 1 + //UnicodeString * s_ptr = new UnicodeString(s); + //PR_ASSERT(s_ptr != 0); + + if (m_TZOffsetTo == 0) + m_TZOffsetTo = ICalPropertyFactory::Make(ICalProperty::TEXT, + (void *) &s, parameters); + else + { + m_TZOffsetTo->setValue((void *) &s); + m_TZOffsetTo->setParameters(parameters); + } +#else + ICalComponent::setStringValue(((ICalProperty **) &m_TZOffsetTo), s, parameters); +#endif +} +UnicodeString TZPart::getTZOffsetTo() const +{ +#if 1 + UnicodeString u; + if (m_TZOffsetTo == 0) + return ""; + else + { + u = *((UnicodeString *) m_TZOffsetTo->getValue()); + return u; + } +#else + UnicodeString us; + ICalComponent::getStringValue(((ICalProperty **) &m_TZOffsetTo), us); + return us; +#endif +} +//--------------------------------------------------------------------- +//TZOffsetFrom +void TZPart::setTZOffsetFrom(UnicodeString s, JulianPtrArray * parameters) +{ +#if 1 + //UnicodeString * s_ptr = new UnicodeString(s); + //PR_ASSERT(s_ptr != 0); + + if (m_TZOffsetFrom == 0) + m_TZOffsetFrom = ICalPropertyFactory::Make(ICalProperty::TEXT, + (void *) &s, parameters); + else + { + m_TZOffsetFrom->setValue((void *) &s); + m_TZOffsetFrom->setParameters(parameters); + } +#else + ICalComponent::setStringValue(((ICalProperty **) &m_TZOffsetFrom), s, parameters); +#endif +} +UnicodeString TZPart::getTZOffsetFrom() const +{ +#if 1 + UnicodeString u; + if (m_TZOffsetFrom == 0) + return ""; + else + { + u = *((UnicodeString *) m_TZOffsetFrom->getValue()); + return u; + } +#else + UnicodeString us; + ICalComponent::getStringValue(((ICalProperty **) &m_TZOffsetFrom), us); + return us; +#endif +} +//--------------------------------------------------------------------- +// XTOKENS +void TZPart::addXTokens(UnicodeString s) +{ + if (m_XTokensVctr == 0) + m_XTokensVctr = new JulianPtrArray(); + PR_ASSERT(m_XTokensVctr != 0); + if (m_XTokensVctr != 0) + { + m_XTokensVctr->Add(new UnicodeString(s)); + } +} +//--------------------------------------------------------------------- + + + diff --git a/calendar/modules/core/ical/src/unistrto.cpp b/calendar/modules/core/ical/src/unistrto.cpp new file mode 100644 index 00000000000..8b9833e192d --- /dev/null +++ b/calendar/modules/core/ical/src/unistrto.cpp @@ -0,0 +1,110 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +/* + * unistrto.cpp + * John Sun + * 2/3/98 12:07:12 PM + */ + +#include "stdafx.h" +#include "jdefines.h" + +#include "unistring.h" +#include "unistrto.h" +#include "keyword.h" + +//static UnicodeString s_DefaultDelims = "\t\n\r"; +//--------------------------------------------------------------------- + +void +UnicodeStringTokenizer::skipDelimeters() +{ + while ((m_CurrentPosition < m_MaxPosition) && + (m_StringDelimeters.indexOf(m_String[(TextOffset)m_CurrentPosition]) >= 0)) + { + m_CurrentPosition++; + } +} +//--------------------------------------------------------------------- + +UnicodeStringTokenizer::UnicodeStringTokenizer(UnicodeString & str, + UnicodeString & delim) +: m_CurrentPosition(0) +{ + m_String = str; + m_MaxPosition = m_String.size(); + m_StringDelimeters = delim; +} +//--------------------------------------------------------------------- +#if 0 +UnicodeStringTokenizer::UnicodeStringTokenizer(UnicodeString & str) +: m_CurrentPosition (0) +{ + m_String = str; + m_MaxPosition = m_String.size(); + m_StringDelimeters = JulianKeyword::Instance()->ms_sDEFAULT_DELIMS; +} +#endif +//--------------------------------------------------------------------- + +t_bool +UnicodeStringTokenizer::hasMoreTokens() +{ + skipDelimeters(); + return (m_CurrentPosition < m_MaxPosition); +} + +//--------------------------------------------------------------------- + +UnicodeString & +UnicodeStringTokenizer::nextToken(UnicodeString & out, + ErrorCode & status) +{ + t_int32 start; + + skipDelimeters(); + if (m_CurrentPosition >= m_MaxPosition) + { + status = 1; + return out; + } + start = m_CurrentPosition; + while ((m_CurrentPosition < m_MaxPosition) && + (m_StringDelimeters.indexOf(m_String[(TextOffset) m_CurrentPosition]) < 0)) + { + m_CurrentPosition++; + } + out = m_String.extractBetween(start, m_CurrentPosition, out); + return out; +} + +//--------------------------------------------------------------------- +#if 0 +UnicodeString & +UnicodeStringTokenizer::nextToken(UnicodeString & out, + UnicodeString & sDelim, + ErrorCode & status) +{ + status = ZERO_ERROR; + m_StringDelimeters = sDelim; + return nextToken(out, status); +} +#endif +//--------------------------------------------------------------------- + diff --git a/calendar/modules/core/ical/src/uri.cpp b/calendar/modules/core/ical/src/uri.cpp new file mode 100644 index 00000000000..d56026eac28 --- /dev/null +++ b/calendar/modules/core/ical/src/uri.cpp @@ -0,0 +1,79 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +/* + * uri.cpp + * John Sun + * 4/3/98 11:33:48 AM + */ + +#include "stdafx.h" +#include "uri.h" +#include "nspr.h" + +//--------------------------------------------------------------------- + +URI::URI() +{ +} + +//--------------------------------------------------------------------- + +URI::URI(UnicodeString fulluri) +{ + m_URI = fulluri; +} + +//--------------------------------------------------------------------- + +URI::URI(char * fulluri) +{ + m_URI = fulluri; +} + +//--------------------------------------------------------------------- + +UnicodeString URI::getName() +{ + t_int32 i; + + i = m_URI.indexOf(':'); + //PR_ASSERT(i != 0); + if (i < 0) + { + return m_URI; + } + else + { + UnicodeString u; + u = m_URI.extractBetween(i + 1, m_URI.size(), u); + return u; + } +} + +//--------------------------------------------------------------------- + +t_bool URI::IsValidURI(UnicodeString & s) +{ + if (s.indexOf(':') > 0) + return PR_TRUE; + else + return PR_FALSE; +} + +//--------------------------------------------------------------------- diff --git a/calendar/modules/core/ical/src/valarm.cpp b/calendar/modules/core/ical/src/valarm.cpp new file mode 100644 index 00000000000..eec3158f470 --- /dev/null +++ b/calendar/modules/core/ical/src/valarm.cpp @@ -0,0 +1,1016 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the 'NPL'); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an 'AS IS' basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ +/* + * valarm.cpp + * John Sun + * 7/22/98 11:15:46 AM + */ + +#include "stdafx.h" +#include "jdefines.h" + +#include "icalredr.h" +#include "valarm.h" +#include "unistrto.h" +#include "keyword.h" +#include "prprtyfy.h" + +#include "functbl.h" +//--------------------------------------------------------------------- + +// private never use +#if 0 +VAlarm::VAlarm() +{ + PR_ASSERT(FALSE); +} +#endif +//--------------------------------------------------------------------- + +VAlarm::VAlarm(JLog * initLog) +: m_Trigger(0), m_Duration(0), m_Repeat(0), + m_XTokensVctr(0), + m_AttachVctr(0), m_Description(0), m_AttendeesVctr(0), + m_Summary(0), + m_Log(initLog) +{ + m_Action = ACTION_INVALID; + m_TriggerDateTime.setTime(-1); +} + +//--------------------------------------------------------------------- + +VAlarm::VAlarm(VAlarm & that) +: m_Trigger(0), m_Duration(0), m_Repeat(0), + m_XTokensVctr(0), + m_AttachVctr(0), m_Description(0), m_AttendeesVctr(0), + m_Summary(0) +{ + m_Action = that.m_Action; + m_TriggerDateTime = that.m_TriggerDateTime; + + if (that.m_Trigger != 0) + { + m_Trigger = that.m_Trigger->clone(m_Log); + } + if (that.m_Duration != 0) + { + m_Duration = that.m_Duration->clone(m_Log); + } + if (that.m_Repeat != 0) + { + m_Repeat = that.m_Repeat->clone(m_Log); + } + if (that.m_XTokensVctr != 0) + { + m_XTokensVctr = new JulianPtrArray(); PR_ASSERT(m_XTokensVctr != 0); + if (m_XTokensVctr != 0) + { + ICalProperty::CloneUnicodeStringVector(that.m_XTokensVctr, m_XTokensVctr); + } + } + if (that.m_AttachVctr != 0) + { + m_AttachVctr = new JulianPtrArray(); PR_ASSERT(m_AttachVctr != 0); + if (m_AttachVctr != 0) + { + ICalProperty::CloneICalPropertyVector(that.m_AttachVctr, m_AttachVctr, m_Log); + } + } + if (that.m_Description != 0) + { + m_Description = that.m_Description->clone(m_Log); + } + if (that.m_AttendeesVctr != 0) + { + m_AttendeesVctr = new JulianPtrArray(); PR_ASSERT(m_AttendeesVctr != 0); + if (m_AttendeesVctr != 0) + { + ICalProperty::CloneICalPropertyVector(that.m_AttendeesVctr, m_AttendeesVctr, m_Log); + } + } + if (that.m_Summary != 0) + { + m_Summary = that.m_Summary->clone(m_Log); + } +} + +//--------------------------------------------------------------------- +ICalComponent * +VAlarm::clone(JLog * initLog) +{ + m_Log = initLog; + return new VAlarm(*this); +} +//--------------------------------------------------------------------- + +VAlarm::~VAlarm() +{ + // trigger, duration, repeat + if (m_Trigger != 0) + { + delete m_Trigger; m_Trigger = 0; + } + if (m_Duration != 0) + { + delete m_Duration; m_Duration = 0; + } + if (m_Repeat != 0) + { + delete m_Repeat; m_Repeat = 0; + } + // x-tokens + if (m_XTokensVctr != 0) + { + ICalComponent::deleteUnicodeStringVector(m_XTokensVctr); + delete m_XTokensVctr; m_XTokensVctr = 0; + } + // attach, description, attendees + if (m_AttachVctr != 0) + { + ICalProperty::deleteICalPropertyVector(m_AttachVctr); + delete m_AttachVctr; m_AttachVctr = 0; + } + if (m_Description != 0) + { + delete m_Description; m_Description = 0; + } + if (m_AttendeesVctr != 0) + { + ICalProperty::deleteICalPropertyVector(m_AttendeesVctr); + delete m_AttendeesVctr; m_AttendeesVctr = 0; + } + if (m_Summary != 0) + { + delete m_Summary; m_Summary = 0; + } +} + +//--------------------------------------------------------------------- + +UnicodeString & +VAlarm::parse(ICalReader * brFile, UnicodeString & sType, + UnicodeString & parseStatus, JulianPtrArray * vTimeZones, + t_bool bIgnoreBeginError, + JulianUtility::MimeEncoding encoding) +{ + UnicodeString strLine, propName, propVal; + JulianPtrArray * parameters = new JulianPtrArray(); + parseStatus = JulianKeyword::Instance()->ms_sOK; + + PR_ASSERT(parameters != 0 && brFile != 0); + if (parameters == 0 || brFile == 0) + { + // ran out of memory, return invalid VAlarm + return parseStatus; + } + ErrorCode status = ZERO_ERROR; + + while (TRUE) + { + PR_ASSERT(brFile != 0); + brFile->readFullLine(strLine, status); + ICalProperty::Trim(strLine); + + if (FAILURE(status) && strLine.size() == 0) + break; + + ICalProperty::parsePropertyLine(strLine, propName, propVal, parameters); + + if (strLine.size() == 0) + { + ICalProperty::deleteICalParameterVector(parameters); + parameters->RemoveAll(); + + continue; + } + // END:STANDARD OR END:DAYLIGHT (sType = daylight or standard) + else if ((propName.compareIgnoreCase(JulianKeyword::Instance()->ms_sEND) == 0) && + (propVal.compareIgnoreCase(JulianKeyword::Instance()->ms_sVALARM) == 0)) + { + ICalProperty::deleteICalParameterVector(parameters); + parameters->RemoveAll(); + + break; + } + else if ( + ((propName.compareIgnoreCase(JulianKeyword::Instance()->ms_sEND) == 0) && + ( (propVal.compareIgnoreCase(JulianKeyword::Instance()->ms_sVEVENT) == 0) || + (propVal.compareIgnoreCase(JulianKeyword::Instance()->ms_sVTODO) == 0) || + (propVal.compareIgnoreCase(JulianKeyword::Instance()->ms_sVCALENDAR) == 0) || + (propVal.compareIgnoreCase(JulianKeyword::Instance()->ms_sVJOURNAL) == 0) || + (propVal.compareIgnoreCase(JulianKeyword::Instance()->ms_sVFREEBUSY) == 0) || + (propVal.compareIgnoreCase(JulianKeyword::Instance()->ms_sVTIMEZONE) == 0) || + (ICalProperty::IsXToken(propVal))) + ) || + ((propName.compareIgnoreCase(JulianKeyword::Instance()->ms_sBEGIN) == 0) && + ((propVal.compareIgnoreCase(JulianKeyword::Instance()->ms_sVEVENT) == 0) || + (propVal.compareIgnoreCase(JulianKeyword::Instance()->ms_sVTODO) == 0) || + (propVal.compareIgnoreCase(JulianKeyword::Instance()->ms_sVJOURNAL) == 0) || + (propVal.compareIgnoreCase(JulianKeyword::Instance()->ms_sVFREEBUSY) == 0) || + (propVal.compareIgnoreCase(JulianKeyword::Instance()->ms_sVTIMEZONE) == 0) || + (propVal.compareIgnoreCase(JulianKeyword::Instance()->ms_sVCALENDAR) == 0) || + (ICalProperty::IsXToken(propVal)) || + (propVal.compareIgnoreCase(JulianKeyword::Instance()->ms_sVALARM) == 0)))) + { + // END:VEVENT, VTODO, VCALENDAR, VJOURNAL, VFREEBUSY, VTIMEZONE, x-token + // BEGIN:VEVENT, VTODO, VJOURNAL, VFREEBUSY, VTIMEZONE, VCALENDAR, VALARM, xtoken + // abrupt end + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iAbruptEndOfParsing, + JulianKeyword::Instance()->ms_sVALARM, strLine, 300); + ICalProperty::deleteICalParameterVector(parameters); + parameters->RemoveAll(); + + parseStatus = strLine; + break; + } + else + { + storeData(strLine, propName, propVal, parameters, vTimeZones); + ICalProperty::deleteICalParameterVector(parameters); + parameters->RemoveAll(); + } + } + ICalProperty::deleteICalParameterVector(parameters); + parameters->RemoveAll(); + delete parameters; parameters = 0; + + selfCheck(); + return parseStatus; +} +//--------------------------------------------------------------------- +void VAlarm::storeAction(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones) +{ + t_int32 i; + if (parameters->GetSize() > 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iInvalidOptionalParam, + JulianKeyword::Instance()->ms_sVALARM, strLine, 100); + } + i = stringToAction(propVal); + if (i < 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iInvalidPropertyValue, + JulianKeyword::Instance()->ms_sVALARM, + JulianKeyword::Instance()->ms_sACTION, propVal, 200); + } + else + { + if (getAction() >= 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iDuplicatedProperty, + JulianKeyword::Instance()->ms_sVALARM, + JulianKeyword::Instance()->ms_sACTION, propVal, 100); + } + setAction((VAlarm::ACTION) i); + } +} +//--------------------------------------------------------------------- + +void VAlarm::storeAttach(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones) +{ + t_bool bParamValid; + bParamValid = ICalProperty::CheckParamsWithValueRangeCheck(parameters, + JulianAtomRange::Instance()->ms_asEncodingValueFMTTypeParamRange, + JulianAtomRange::Instance()->ms_asEncodingValueFMTTypeParamRangeSize, + JulianAtomRange::Instance()->ms_asBinaryURIValueRange, + JulianAtomRange::Instance()->ms_asBinaryURIValueRangeSize); + if (!bParamValid) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iInvalidOptionalParam, + JulianKeyword::Instance()->ms_sVALARM, strLine, 100); + } + addAttach(propVal, parameters); +} +//--------------------------------------------------------------------- + +void VAlarm::storeAttendee(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones) +{ + Attendee * attendee = new Attendee(GetType(), m_Log); + PR_ASSERT(attendee != 0); + if (attendee != 0) + { + attendee->parse(propVal, parameters); + if (!attendee->isValid()) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iInvalidAttendee, 200); + delete attendee; attendee = 0; + } + else + { + addAttendee(attendee); + } + } +} +//--------------------------------------------------------------------- +void VAlarm::storeDescription(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones) +{ + // check parameters + t_bool bParamValid; + bParamValid = ICalProperty::CheckParams(parameters, + JulianAtomRange::Instance()->ms_asAltrepLanguageParamRange, + JulianAtomRange::Instance()->ms_asAltrepLanguageParamRangeSize); + + if (!bParamValid) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iInvalidOptionalParam, + JulianKeyword::Instance()->ms_sVALARM, strLine, 100); + } + + // check for duplicates + if (getDescriptionProperty() != 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iDuplicatedProperty, + JulianKeyword::Instance()->ms_sVALARM, + JulianKeyword::Instance()->ms_sDESCRIPTION, 100); + } + + setDescription(propVal, parameters); +} +//--------------------------------------------------------------------- +void VAlarm::storeDuration(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones) +{ + // no parameters + if (parameters->GetSize() > 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iInvalidOptionalParam, + JulianKeyword::Instance()->ms_sVALARM, strLine, 100); + } + + if (getDurationProperty() != 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iDuplicatedProperty, + JulianKeyword::Instance()->ms_sVALARM, + JulianKeyword::Instance()->ms_sDURATION, 100); + } + Julian_Duration d(propVal); + setDuration(d, parameters); +} +//--------------------------------------------------------------------- +void VAlarm::storeRepeat(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones) +{ + t_bool bParseError = FALSE; + t_int32 i; + + // no parameters + if (parameters->GetSize() > 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iInvalidOptionalParam, + JulianKeyword::Instance()->ms_sVALARM, strLine, 100); + } + + char * pcc = propVal.toCString(""); + PR_ASSERT(pcc != 0); + i = JulianUtility::atot_int32(pcc, bParseError, propVal.size()); + delete [] pcc; pcc = 0; + + if (getRepeatProperty() != 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iDuplicatedProperty, + JulianKeyword::Instance()->ms_sVALARM, + JulianKeyword::Instance()->ms_sREPEAT, 100); + } + if (!bParseError) + { + setRepeat(i, parameters); + } + else + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iInvalidNumberFormat, + JulianKeyword::Instance()->ms_sVALARM, + JulianKeyword::Instance()->ms_sREPEAT, propVal, 200); + } +} +//--------------------------------------------------------------------- +void VAlarm::storeSummary(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones) +{ + // check parameters + t_bool bParamValid; + bParamValid = ICalProperty::CheckParams(parameters, + JulianAtomRange::Instance()->ms_asLanguageParamRange, + JulianAtomRange::Instance()->ms_asLanguageParamRangeSize); + if (!bParamValid) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iInvalidOptionalParam, + JulianKeyword::Instance()->ms_sVALARM, strLine, 100); + } + + if (getSummaryProperty() != 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iDuplicatedProperty, + JulianKeyword::Instance()->ms_sVALARM, + JulianKeyword::Instance()->ms_sSUMMARY, 100); + } + setSummary(propVal, parameters); +} + +//--------------------------------------------------------------------- +void VAlarm::storeTrigger(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones) +{ + // check parameters + t_bool bParamValid; + bParamValid = ICalProperty::CheckParams(parameters, + JulianAtomRange::Instance()->ms_asRelatedValueParamRange, + JulianAtomRange::Instance()->ms_asRelatedValueParamRangeSize); + if (!bParamValid) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iInvalidOptionalParam, + JulianKeyword::Instance()->ms_sVALARM, strLine, 100); + } + // if propVal is a datetime, store trigger as a datetime, otherwise store is as a duration + if (getDurationProperty() != 0 || m_TriggerDateTime.isValid()) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iDuplicatedProperty, + JulianKeyword::Instance()->ms_sVALARM, + JulianKeyword::Instance()->ms_sDURATION, 100); + } + + DateTime dt(propVal); + if (dt.isValid()) + { + setTriggerAsDateTime(dt); + } + else + { + Julian_Duration d(propVal); + setTriggerAsDuration(d, parameters); + } +} + + +//--------------------------------------------------------------------- +void +VAlarm::storeData(UnicodeString & strLine, UnicodeString & propName, + UnicodeString & propVal, JulianPtrArray * parameters, + JulianPtrArray * vTimeZones) +{ + t_int32 hashCode = propName.hashCode(); + t_int32 i; + for (i = 0; 0 != (JulianFunctionTable::Instance()->alarmStoreTable[i]).op; i++) + { + if ((JulianFunctionTable::Instance()->alarmStoreTable[i]).hashCode == hashCode) + { + ApplyStoreOp(((JulianFunctionTable::Instance())->alarmStoreTable[i]).op, + strLine, propVal, parameters, vTimeZones); + return; + } + } + if (ICalProperty::IsXToken(propName)) + { + addXTokens(strLine); + } + else + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iInvalidPropertyName, + JulianKeyword::Instance()->ms_sVALARM, propName, 200); + } +} + +//--------------------------------------------------------------------- +void VAlarm::selfCheck() +{ + UnicodeString u; + + switch(m_Action) + { + case ACTION_AUDIO: + break; + case ACTION_DISPLAY: + + // if display prop, make sure description there. + // if not add a default description + + if (getDescription().size() == 0) + { + // TODO: make this localized; + //u = JulianLogErrorMessage::Instance()->ms_iDefaultAlarmDescriptionString; + u = "DEFAULT"; + setDescription(u); + } + break; + case ACTION_EMAIL: + + // if email prop, make sure description and summary + // if not add a default description and summary + + if (getDescription().size() == 0) + { + // TODO: make this localized; + //u = JulianLogErrorMessage::Instance()->ms_iDefaultAlarmDescriptionString; + u = "DEFAULT"; + setDescription(u); + } + if (getSummary().size() == 0) + { + // TODO: make this localized; + //u = JulianLogErrorMessage::Instance()->ms_iDefaultAlarmSummaryString; + u = "DEFAULT"; + setSummary(u); + } + break; + case ACTION_PROCEDURE: + break; + default: + break; + } +} +//--------------------------------------------------------------------- +t_bool VAlarm::isValid() +{ + + // action must be set to valid value + if (m_Action == ACTION_INVALID) + return FALSE; + + // trigger must be valid duration or datetime. + if (m_Trigger == 0 && !m_TriggerDateTime.isValid()) + return FALSE; + + switch (m_Action) + { + case ACTION_AUDIO: + // if action == audio: must ONLY one attach if it has an attach + if (getAttach() != 0 && getAttach()->GetSize() != 1) + return FALSE; + + // MAKE SURE certain properties are empty. may remove later + if (getDescription().size() > 0) + return FALSE; + if (getSummary().size() > 0) + return FALSE; + if (getAttendees() != 0) + return FALSE; + break; + case ACTION_DISPLAY: + // if action == display: must have description + if (getDescription().size() == 0) + return FALSE; + + // MAKE SURE certain properties are empty. may remove later + if (getSummary().size() > 0) + return FALSE; + if (getAttendees() != 0) + return FALSE; + if (getAttach() != 0) + return FALSE; + break; + case ACTION_EMAIL: + // if action == email: must have description, summary, at least ONE attendee + if (getDescription().size() == 0 || getSummary().size() == 0 || + getAttendees() == 0 || getAttendees()->GetSize() == 0) + return FALSE; + break; + case ACTION_PROCEDURE: + // if action == procedure: must have ONLY one attach + if (getAttach() == 0 || getAttach()->GetSize() != 1) + return FALSE; + + // MAKE SURE certain properties are empty. may remove later + if (getSummary().size() > 0) + return FALSE; + if (getAttendees() != 0) + return FALSE; + break; + default: + return FALSE; + } + + return TRUE; +} +//--------------------------------------------------------------------- +UnicodeString VAlarm::toICALString() +{ + UnicodeString u = JulianKeyword::Instance()->ms_sVALARM; + return ICalComponent::format(u, JulianFormatString::Instance()->ms_sVAlarmAllMessage, ""); +} +//--------------------------------------------------------------------- +UnicodeString VAlarm::toICALString(UnicodeString method, + UnicodeString name, + t_bool isRecurring) +{ + // NOTE: remove later avoid warnings + if (isRecurring) {} + return toICALString(); +} +//--------------------------------------------------------------------- +UnicodeString VAlarm::toString() +{ + return ICalComponent::toStringFmt( + JulianFormatString::Instance()->ms_VAlarmStrDefaultFmt); +} +//--------------------------------------------------------------------- +UnicodeString VAlarm::formatChar(t_int32 c, UnicodeString sFilterAttendee, + t_bool delegateRequest) +{ + UnicodeString s, sResult; + + // NOTE: remove here is get rid of compiler warnings + if (sFilterAttendee.size() > 0 || delegateRequest) + { + } + + switch (c) + { + case ms_cAction: + // print method enum + sResult += JulianKeyword::Instance()->ms_sACTION; + sResult += JulianKeyword::Instance()->ms_sCOLON_SYMBOL; + sResult += actionToString(getAction(), s); + sResult += JulianKeyword::Instance()->ms_sLINEBREAK; + return sResult; + case ms_cAttendees: + s = JulianKeyword::Instance()->ms_sATTENDEE; + return ICalProperty::propertyVectorToICALString(s, getAttendees(), sResult); + case ms_cAttach: + s = JulianKeyword::Instance()->ms_sATTACH; + return ICalProperty::propertyVectorToICALString(s, getAttach(), sResult); + case ms_cDescription: + s = JulianKeyword::Instance()->ms_sDESCRIPTION; + return ICalProperty::propertyToICALString(s, getDescriptionProperty(), sResult); + case ms_cDuration: + s = JulianKeyword::Instance()->ms_sDURATION; + return ICalProperty::propertyToICALString(s, getDurationProperty(), sResult); + case ms_cRepeat: + s = JulianKeyword::Instance()->ms_sREPEAT; + return ICalProperty::propertyToICALString(s, getRepeatProperty(), sResult); + case ms_cTrigger: + s = JulianKeyword::Instance()->ms_sTRIGGER; + if (m_Trigger != 0) + { + return ICalProperty::propertyToICALString(s, getTriggerProperty(), sResult); + } + else + { + s += JulianKeyword::Instance()->ms_sSEMICOLON_SYMBOL; + s += JulianKeyword::Instance()->ms_sVALUE; + s += '='; + s += JulianKeyword::Instance()->ms_sDATETIME; + s += JulianKeyword::Instance()->ms_sCOLON_SYMBOL; + s += m_TriggerDateTime.toISO8601(); + s += JulianKeyword::Instance()->ms_sLINEBREAK; + return s; + } + case ms_cSummary: + s = JulianKeyword::Instance()->ms_sSUMMARY; + return ICalProperty::propertyToICALString(s, getSummaryProperty(), sResult); + case ms_cXTokens: + return ICalProperty::vectorToICALString(getXTokens(), sResult); + default: + return ""; + } +} +//--------------------------------------------------------------------- +UnicodeString VAlarm::toStringChar(t_int32 c, UnicodeString & dateFmt) +{ + UnicodeString s; + switch (c) + { + case ms_cAction: + return actionToString(getAction(), s); + case ms_cAttendees: + return ICalProperty::propertyVectorToString(getAttendees(), dateFmt, s); + case ms_cAttach: + return ICalProperty::propertyVectorToString(getAttach(), dateFmt, s); + case ms_cDescription: + return ICalProperty::propertyToString(getDescriptionProperty(), dateFmt, s); + case ms_cDuration: + return ICalProperty::propertyToString(getDurationProperty(), dateFmt, s); + case ms_cRepeat: + return ICalProperty::propertyToString(getRepeatProperty(), dateFmt, s); + case ms_cTrigger: + if (m_Trigger != 0) + { + return ICalProperty::propertyToString(getTriggerProperty(), dateFmt, s); + } + else + { + return m_TriggerDateTime.toString(); + } + case ms_cSummary: + return ICalProperty::propertyToString(getSummaryProperty(), dateFmt, s); + case ms_cXTokens: + default: + return ""; + } +} +//--------------------------------------------------------------------- + +void +VAlarm::updateComponentHelper(VAlarm * updatedComponent) +{ + // todo: finish +} + +//--------------------------------------------------------------------- + +t_bool +VAlarm::updateComponent(ICalComponent * updatedComponent) +{ + if (updatedComponent != 0) + { + ICAL_COMPONENT ucType = updatedComponent->GetType(); + + // only call updateComponentHelper if it's a VAlarm and + // it is an exact matching Name (STANDARD or DAYLIGHT) + // basically always overwrite + if (ucType == ICAL_COMPONENT_VALARM) + { + // todo: finish + } + } + return FALSE; +} + +//--------------------------------------------------------------------- + +VAlarm::ACTION +VAlarm::stringToAction(UnicodeString & action) +{ + t_int32 hashCode = action.hashCode(); + + if (JulianKeyword::Instance()->ms_ATOM_AUDIO == hashCode) return ACTION_AUDIO; + else if (JulianKeyword::Instance()->ms_ATOM_DISPLAY == hashCode) return ACTION_DISPLAY; + else if (JulianKeyword::Instance()->ms_ATOM_EMAIL == hashCode) return ACTION_EMAIL; + else if (JulianKeyword::Instance()->ms_ATOM_PROCEDURE == hashCode) return ACTION_PROCEDURE; + else return ACTION_INVALID; + // ??? is AUDIO to be default, or should I have invalid state? +} + +//--------------------------------------------------------------------- + +UnicodeString & VAlarm::actionToString(VAlarm::ACTION action, UnicodeString & out) +{ + switch(action) + { + case ACTION_AUDIO: out = JulianKeyword::Instance()->ms_sAUDIO; break; + case ACTION_DISPLAY: out = JulianKeyword::Instance()->ms_sDISPLAY; break; + case ACTION_EMAIL: out = JulianKeyword::Instance()->ms_sEMAIL; break; + case ACTION_PROCEDURE: out = JulianKeyword::Instance()->ms_sPROCEDURE; break; + default: + out = ""; + break; + } + return out; +} +//--------------------------------------------------------------------- +//--------------------------------------------------------------------- +///Julian_Duration +void VAlarm::setDuration(Julian_Duration s, JulianPtrArray * parameters) +{ + if (m_Duration == 0) + m_Duration = ICalPropertyFactory::Make(ICalProperty::DURATION, + (void *) &s, parameters); + else + { + m_Duration->setValue((void *) &s); + m_Duration->setParameters(parameters); + } +} +Julian_Duration VAlarm::getDuration() const +{ + Julian_Duration d; d.set(-1,-1,-1,-1,-1,-1); + if (m_Duration == 0) + return d; // return 0; + else + { + d = *((Julian_Duration *) m_Duration->getValue()); + return d; + } +} +//--------------------------------------------------------------------- +///Trigger +void VAlarm::setTriggerAsDuration(Julian_Duration s, JulianPtrArray * parameters) +{ + if (m_Trigger == 0) + m_Trigger = ICalPropertyFactory::Make(ICalProperty::DURATION, + (void *) &s, parameters); + else + { + m_Trigger->setValue((void *) &s); + m_Trigger->setParameters(parameters); + } +} +Julian_Duration VAlarm::getTriggerAsDuration() const +{ + Julian_Duration d; d.set(-1,-1,-1,-1,-1,-1); + if (m_Trigger == 0) + return d; // return 0; + else + { + d = *((Julian_Duration *) m_Trigger->getValue()); + return d; + } +} +DateTime VAlarm::getTriggerAsDateTime(DateTime start) const +{ + DateTime d; + if (m_Trigger != 0) + { + Julian_Duration du = getTriggerAsDuration(); + start.add(du); + d = start; + } + else + d = m_TriggerDateTime; + return d; +} +void VAlarm::setTriggerAsDateTime(DateTime s) +{ + m_TriggerDateTime = s; + // clear trigger duration if it exists + if (m_Trigger != 0) + { + delete m_Trigger; m_Trigger = 0; + } +} +//--------------------------------------------------------------------- +//Repeat +void VAlarm::setRepeat(t_int32 i, JulianPtrArray * parameters) +{ +#if 1 + if (m_Repeat == 0) + m_Repeat = ICalPropertyFactory::Make(ICalProperty::INTEGER, + (void *) &i, parameters); + else + { + m_Repeat->setValue((void *) &i); + m_Repeat->setParameters(parameters); + } +#else + ICalComponent::setIntegerValue(((ICalProperty **) &m_Repeat), i, parameters); +#endif +} +t_int32 VAlarm::getRepeat() const +{ +#if 1 + t_int32 i; + if (m_Repeat == 0) + return -1; + else + { + i = *((t_int32 *) m_Repeat->getValue()); + return i; + } +#else + t_int32 i = -1; + ICalComponent::getIntegerValue(((ICalProperty **) &m_Repeat), i); + return i; +#endif + +} +//--------------------------------------------------------------------- +//Description +void VAlarm::setDescription(UnicodeString s, JulianPtrArray * parameters) +{ + //UnicodeString * s_ptr = new UnicodeString(s); + //PR_ASSERT(s_ptr != 0); +#if 1 + if (m_Description == 0) + m_Description = ICalPropertyFactory::Make(ICalProperty::TEXT, + (void *) &s, parameters); + else + { + m_Description->setValue((void *) &s); + m_Description->setParameters(parameters); + } +#else + ICalComponent::setStringValue(((ICalProperty **) &m_Description), s, parameters); +#endif +} +UnicodeString VAlarm::getDescription() const +{ +#if 1 + if (m_Description == 0) + return ""; + else + { + UnicodeString u; + u = *((UnicodeString *) m_Description->getValue()); + return u; + } +#else + UnicodeString us; + ICalComponent::getStringValue(((ICalProperty **) &m_Description), us); + return us; +#endif +} +//--------------------------------------------------------------------- +//Summary +void VAlarm::setSummary(UnicodeString s, JulianPtrArray * parameters) +{ + //UnicodeString * s_ptr = new UnicodeString(s); + //PR_ASSERT(s_ptr != 0); +#if 1 + if (m_Summary == 0) + m_Summary = ICalPropertyFactory::Make(ICalProperty::TEXT, + (void *) &s, parameters); + else + { + m_Summary->setValue((void *) &s); + m_Summary->setParameters(parameters); + } +#else + ICalComponent::setStringValue(((ICalProperty **) &m_Summary), s, parameters); +#endif +} +UnicodeString VAlarm::getSummary() const +{ +#if 1 + if (m_Summary == 0) + return ""; + else + { + UnicodeString u; + u = *((UnicodeString *) m_Summary->getValue()); + return u; + } +#else + UnicodeString us; + ICalComponent::getStringValue(((ICalProperty **) &m_Summary), us); + return us; +#endif +} +//--------------------------------------------------------------------- +// attach +void VAlarm::addAttach(UnicodeString s, JulianPtrArray * parameters) +{ + ICalProperty * prop = ICalPropertyFactory::Make(ICalProperty::TEXT, + (void *) &s, parameters); + addAttachProperty(prop); +} +void VAlarm::addAttachProperty(ICalProperty * prop) +{ + if (m_AttachVctr == 0) + m_AttachVctr = new JulianPtrArray(); + PR_ASSERT(m_AttachVctr != 0); + if (m_AttachVctr != 0) + { + m_AttachVctr->Add(prop); + } +} +//--------------------------------------------------------------------- +// attendees +void VAlarm::addAttendee(Attendee * a) +{ + if (m_AttendeesVctr == 0) + m_AttendeesVctr = new JulianPtrArray(); + PR_ASSERT(m_AttendeesVctr != 0); + if (m_AttendeesVctr != 0) + { + m_AttendeesVctr->Add(a); + } +} +//--------------------------------------------------------------------- +// XTOKENS +void VAlarm::addXTokens(UnicodeString s) +{ + if (m_XTokensVctr == 0) + m_XTokensVctr = new JulianPtrArray(); + PR_ASSERT(m_XTokensVctr != 0); + if (m_XTokensVctr != 0) + { + m_XTokensVctr->Add(new UnicodeString(s)); + } +} +//--------------------------------------------------------------------- diff --git a/calendar/modules/core/ical/src/vevent.cpp b/calendar/modules/core/ical/src/vevent.cpp new file mode 100644 index 00000000000..af9e001116d --- /dev/null +++ b/calendar/modules/core/ical/src/vevent.cpp @@ -0,0 +1,1188 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +// vevent.cpp +// John Sun +// 10:50 AM February 9 1998 + +#include "stdafx.h" +#include "jdefines.h" + +#include "jutility.h" +#include "vevent.h" +#include "icalredr.h" +#include "prprtyfy.h" +#include "unistrto.h" +#include "jlog.h" +#include "vtimezne.h" +#include "keyword.h" + +#include "period.h" +#include "datetime.h" + +#include "functbl.h" +//--------------------------------------------------------------------- +void VEvent::setDefaultFmt(UnicodeString s) +{ + JulianFormatString::Instance()->ms_VEventStrDefaultFmt = s; +} +//--------------------------------------------------------------------- + +// never use +#if 0 +VEvent::VEvent() +{ + PR_ASSERT(FALSE); +} +#endif +//--------------------------------------------------------------------- + +VEvent::VEvent(JLog * initLog) +: m_DTEnd(0), + m_TempDuration(0), + m_GEO(0), m_Location(0), m_Priority(0), m_ResourcesVctr(0), + m_Transp(0), + TimeBasedEvent(initLog) +{ +} +//--------------------------------------------------------------------- +VEvent::VEvent(VEvent & that) +: m_DTEnd(0), + m_TempDuration(0), + m_GEO(0), m_Location(0), m_Priority(0), m_ResourcesVctr(0), + m_Transp(0), + TimeBasedEvent(that) +{ + m_origDTEnd = that.m_origDTEnd; + m_origMyDTEnd = that.m_origMyDTEnd; + + if (that.m_DTEnd != 0) + { + m_DTEnd = that.m_DTEnd->clone(m_Log); + } + //if (that.m_Duration != 0) { m_Duration = that.m_Duration->clone(m_Log); } + if (that.m_GEO != 0) + { + m_GEO = that.m_GEO->clone(m_Log); + } + if (that.m_Location != 0) + { + m_Location = that.m_Location->clone(m_Log); + } + if (that.m_Priority != 0) + { + m_Priority = that.m_Priority->clone(m_Log); + } + if (that.m_Transp != 0) + { + m_Transp = that.m_Transp->clone(m_Log); + } + if (that.m_ResourcesVctr != 0) + { + m_ResourcesVctr = new JulianPtrArray(); PR_ASSERT(m_ResourcesVctr != 0); + if (m_ResourcesVctr != 0) + { + ICalProperty::CloneICalPropertyVector(that.m_ResourcesVctr, m_ResourcesVctr, m_Log); + } + } +} +//--------------------------------------------------------------------- +ICalComponent * +VEvent::clone(JLog * initLog) +{ + m_Log = initLog; + //PR_ASSERT(m_Log != 0); + return new VEvent(*this); +} +//--------------------------------------------------------------------- + +VEvent::~VEvent() +{ + if (m_TempDuration != 0) + { + delete m_TempDuration; m_TempDuration = 0; + } + // properties + if (m_DTEnd != 0) + { + delete m_DTEnd; m_DTEnd = 0; + } + //if (m_Duration != 0) { delete m_Duration; m_Duration = 0; } + if (m_GEO != 0) + { + delete m_GEO; m_GEO = 0; + } + if (m_Location!= 0) + { + delete m_Location; m_Location = 0; + } + if (m_Priority!= 0) + { + delete m_Priority; m_Priority = 0; + } + if (m_Transp != 0) + { + delete m_Transp; m_Transp = 0; + } + + // vector of strings + if (m_ResourcesVctr != 0) { + ICalProperty::deleteICalPropertyVector(m_ResourcesVctr); + delete m_ResourcesVctr; m_ResourcesVctr = 0; + } + //delete (TimeBasedEvent *) this; +} + +//--------------------------------------------------------------------- + +UnicodeString & +VEvent::parse(ICalReader * brFile, UnicodeString & sMethod, + UnicodeString & parseStatus, JulianPtrArray * vTimeZones, + t_bool bIgnoreBeginError, JulianUtility::MimeEncoding encoding) +{ + UnicodeString u = JulianKeyword::Instance()->ms_sVEVENT; + return parseType(u, brFile, sMethod, parseStatus, vTimeZones, bIgnoreBeginError, encoding); +} + +//--------------------------------------------------------------------- +#if 0 +t_int8 VEvent::compareTo(VEvent * ve) +{ + PR_ASSERT(ve != 0); + // TODO; + return -1; +} +#endif /* #if 0 */ +//--------------------------------------------------------------------- + +Date VEvent::difference() +{ + if (getDTEnd().getTime() >= 0 && getDTStart().getTime() >= 0) + { + return (getDTEnd().getTime() - getDTStart().getTime()); + } + else return 0; +} + +//--------------------------------------------------------------------- + +void VEvent::selfCheck() +{ + + TimeBasedEvent::selfCheck(); + + // if no dtend, and there is a dtstart and duration, calculate dtend + if (!getDTEnd().isValid()) + { + // calculate DTEnd from duration and dtstart + // TODO: remove memory leaks in m_TempDuration + if (getDTStart().isValid() && m_TempDuration != 0 && m_TempDuration->isValid()) + { + DateTime end; + end = getDTStart(); + end.add(*m_TempDuration); + setDTEnd(end); + delete m_TempDuration; m_TempDuration = 0; // lifetime of variable is only + // after load. + } + else if (!getDTStart().isValid()) + { + if (m_TempDuration != 0) + delete m_TempDuration; m_TempDuration = 0; + } + } + + // if is anniversary event, set transp to TRANSPARENT + if (isAllDayEvent()) + { + setTransp(JulianKeyword::Instance()->ms_sTRANSP); + + // if no dtend, set dtend to end of day of dtstart. + if (!getDTEnd().isValid()) + { + DateTime d; + d = getDTStart(); + d.add(Calendar::DATE, 1); + d.set(Calendar::HOUR_OF_DAY, 0); + d.set(Calendar::MINUTE, 0); + d.set(Calendar::SECOND, 0); + setDTEnd(d); + } + + // If DTEND is before DTSTART, set dtend = dtstart + if (getDTEnd().getTime() < getDTStart().getTime()) + { + DateTime d; + d = getDTStart(); + setDTEnd(d); + + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iDTEndBeforeDTStart, 100); + } + } + else + { + if (!getDTEnd().isValid()) + { + // dtend is same as dtstart + DateTime d; + d = getDTStart(); + if (d.isValid()) + setDTEnd(d); + } + + // If DTEND is before DTSTART, set dtend = dtstart + if (getDTEnd().getTime() < getDTStart().getTime()) + { + DateTime d; + d = getDTStart(); + setDTEnd(d); + + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iDTEndBeforeDTStart, 100); + } + } + if (getStatus().size() > 0) + { + // check if I got a valid status + UnicodeString u = getStatus(); + u.toUpper(); + ICalProperty::Trim(u); + JAtom ua(u); + if ((JulianKeyword::Instance()->ms_ATOM_CONFIRMED != ua) && + (JulianKeyword::Instance()->ms_ATOM_TENTATIVE != ua) && + (JulianKeyword::Instance()->ms_ATOM_CANCELLED != ua)) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iInvalidPropertyValue, + JulianKeyword::Instance()->ms_sVEVENT, + JulianKeyword::Instance()->ms_sSTATUS, u, 200); + + setStatus(""); + } + } +} + +//--------------------------------------------------------------------- +void VEvent::storeDTEnd(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones) +{ + // check parameters + t_bool bParamValid = ICalProperty::CheckParamsWithValueRangeCheck(parameters, + JulianAtomRange::Instance()->ms_asTZIDValueParamRange, + JulianAtomRange::Instance()->ms_asTZIDValueParamRangeSize, + JulianAtomRange::Instance()->ms_asDateDateTimeValueRange, + JulianAtomRange::Instance()->ms_asDateDateTimeValueRangeSize); + if (!bParamValid) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iInvalidOptionalParam, + JulianKeyword::Instance()->ms_sVEVENT, strLine, 100); + } + + if (getDTEndProperty() != 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iDuplicatedProperty, + JulianKeyword::Instance()->ms_sVEVENT, + JulianKeyword::Instance()->ms_sDTEND, 100); + } + UnicodeString u, out; + + u = JulianKeyword::Instance()->ms_sVALUE; + out = ICalParameter::GetParameterFromVector(u, out, parameters); + + t_bool bIsDate = DateTime::IsParseableDate(propVal); + + if (bIsDate) + { + // if there is a VALUE=X parameter, make sure X is DATE + if (out.size() != 0 && (JulianKeyword::Instance()->ms_ATOM_DATE != out.hashCode())) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iPropertyValueTypeMismatch, + JulianKeyword::Instance()->ms_sVEVENT, strLine, 100); + } + } + else + { + // if there is a VALUE=X parameter, make sure X is DATETIME + if (out.size() != 0 && (JulianKeyword::Instance()->ms_ATOM_DATETIME != out.hashCode())) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iPropertyValueTypeMismatch, + JulianKeyword::Instance()->ms_sVEVENT, strLine, 100); + } + } + + DateTime d; + d = VTimeZone::DateTimeApplyTimeZone(propVal, vTimeZones, parameters); + + setDTEnd(d, parameters); +} +void VEvent::storeDuration(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones) +{ + // no parameters + if (parameters->GetSize() > 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iInvalidOptionalParam, + JulianKeyword::Instance()->ms_sVEVENT, strLine, 100); + } + + if (m_TempDuration != 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iDuplicatedProperty, + JulianKeyword::Instance()->ms_sVEVENT, + JulianKeyword::Instance()->ms_sDURATION, 100); + } + //Duration d(propVal); + if (m_TempDuration == 0) + { + m_TempDuration = new Julian_Duration(propVal); + PR_ASSERT(m_TempDuration != 0); + } + else + m_TempDuration->setDurationString(propVal); +} +void VEvent::storeGEO(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones) +{ + // no parameters + if (parameters->GetSize() > 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iInvalidOptionalParam, + JulianKeyword::Instance()->ms_sVEVENT, strLine, 100); + } + + if (getGEOProperty() != 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iDuplicatedProperty, + JulianKeyword::Instance()->ms_sVEVENT, + JulianKeyword::Instance()->ms_sGEO, 100); + } + setGEO(propVal, parameters); +} +void VEvent::storeLocation(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones) +{ + t_bool bParamValid = ICalProperty::CheckParams(parameters, + JulianAtomRange::Instance()->ms_asAltrepLanguageParamRange, + JulianAtomRange::Instance()->ms_asAltrepLanguageParamRangeSize); + + if (!bParamValid) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iInvalidOptionalParam, + JulianKeyword::Instance()->ms_sVEVENT, strLine, 100); + } + + if (getLocationProperty() != 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iDuplicatedProperty, + JulianKeyword::Instance()->ms_sVEVENT, + JulianKeyword::Instance()->ms_sLOCATION, 100); + } + setLocation(propVal, parameters); +} +void VEvent::storePriority(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones) +{ + t_bool bParseError = FALSE; + t_int32 i; + + // no parameters + if (parameters->GetSize() > 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iInvalidOptionalParam, + JulianKeyword::Instance()->ms_sVEVENT, strLine, 100); + } + + char * pcc = propVal.toCString(""); + PR_ASSERT(pcc != 0); + i = JulianUtility::atot_int32(pcc, bParseError, propVal.size()); + delete [] pcc; pcc = 0; + if (getPriorityProperty() != 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iDuplicatedProperty, + JulianKeyword::Instance()->ms_sVEVENT, + JulianKeyword::Instance()->ms_sPRIORITY, 100); + } + if (!bParseError) + { + setPriority(i, parameters); + } + else + { + if (m_Log) m_Log->logError(JulianLogErrorMessage::Instance()->ms_iInvalidNumberFormat, + JulianKeyword::Instance()->ms_sVEVENT, + JulianKeyword::Instance()->ms_sPRIORITY, propVal, 200); + } +} +void VEvent::storeResources(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones) +{ +// check parameters + t_bool bParamValid = ICalProperty::CheckParams(parameters, + JulianAtomRange::Instance()->ms_asLanguageParamRange, + JulianAtomRange::Instance()->ms_asLanguageParamRangeSize); + if (!bParamValid) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iInvalidOptionalParam, + JulianKeyword::Instance()->ms_sVEVENT, strLine, 100); + } + + addResourcesPropertyVector(propVal, parameters); +} +void VEvent::storeTransp(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones) +{ + // no parameters + if (parameters->GetSize() > 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iInvalidOptionalParam, + JulianKeyword::Instance()->ms_sVEVENT, strLine, 100); + } + + if (getTranspProperty() != 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iDuplicatedProperty, + JulianKeyword::Instance()->ms_sVEVENT, + JulianKeyword::Instance()->ms_sTRANSP, 100); + } + setTransp(propVal, parameters); +} +//--------------------------------------------------------------------- +t_bool +VEvent::storeData(UnicodeString & strLine, UnicodeString & propName, + UnicodeString & propVal, JulianPtrArray * parameters, + JulianPtrArray * vTimeZones) +{ + if (TimeBasedEvent::storeData(strLine, propName, propVal, + parameters, vTimeZones)) + return TRUE; + else + { + t_int32 hashCode = propName.hashCode(); + t_int32 i; + for (i = 0; 0 != (JulianFunctionTable::Instance()->veStoreTable[i]).op; i++) + { + if ((JulianFunctionTable::Instance()->veStoreTable[i]).hashCode == hashCode) + { + ApplyStoreOp(((JulianFunctionTable::Instance())->veStoreTable[i]).op, + strLine, propVal, parameters, vTimeZones); + return TRUE; + } + } + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iInvalidPropertyName, + JulianKeyword::Instance()->ms_sVEVENT, propName, 200); + UnicodeString u; + u = JulianLogErrorMessage::Instance()->ms_sRS202; + u += '.'; u += ' '; + u += strLine; + addRequestStatus(u); + return FALSE; + } +} + +//--------------------------------------------------------------------- +/// note: todo: crash proof, bulletproofed +void VEvent::populateDatesHelper(DateTime start, Date ldiff, + JulianPtrArray * vPeriods) +{ + Date diff = ldiff; + Date diff2 = -1; + + if (vPeriods != 0) + { + // Check if period matches this date, if-so, set + // difference to be length of period + // TODO: if multiple periods match this date, choose period + // with longest length + + t_int32 i; + UnicodeString u; + Period p; + DateTime ps, pe; + Date pl; + for (i = 0; i < vPeriods->GetSize(); i++) + { + u = *((UnicodeString *) vPeriods->GetAt(i)); + + //if (FALSE) TRACE("populateDatesHelper(): u = %s\r\n", u.toCString("")); + + p.setPeriodString(u); + PR_ASSERT(p.isValid()); + if (p.isValid()) + { + ps = p.getStart(); + + if (ps.equalsDateTime(start)) + { + pe = p.getEndingTime(pe); + pl = (pe.getTime() - ps.getTime()); + //if (FALSE) TRACE("populateDatesHelper(): pl = %d\r\n", pl); + + diff2 = ((diff2 > pl) ? diff2 : pl); + } + } + } + } + if (diff2 != -1) + diff = diff2; + + DateTime dEnd; + dEnd.setTime(start.getTime() + diff); + setDTEnd(dEnd); + setMyOrigEnd(dEnd); + + DateTime origEnd; + origEnd.setTime(getOrigStart().getTime() + ldiff); + setOrigEnd(origEnd); +} + +//--------------------------------------------------------------------- + +UnicodeString VEvent::formatHelper(UnicodeString & strFmt, + UnicodeString sFilterAttendee, + t_bool delegateRequest) +{ + UnicodeString u = JulianKeyword::Instance()->ms_sVEVENT; + return ICalComponent::format(u, strFmt, sFilterAttendee, delegateRequest); +} + +//--------------------------------------------------------------------- + +UnicodeString VEvent::toString() +{ + return ICalComponent::toStringFmt( + JulianFormatString::Instance()->ms_VEventStrDefaultFmt); +} + +//--------------------------------------------------------------------- + +UnicodeString VEvent::toStringChar(t_int32 c, UnicodeString & dateFmt) +{ + UnicodeString sResult; + switch ( c ) + { + case ms_cDuration: + return getDuration().toString(); + //return ICalProperty::propertyToString(getDurationProperty(), dateFmt, sResult); + case ms_cDTEnd: + return ICalProperty::propertyToString(getDTEndProperty(), dateFmt, sResult); + case ms_cGEO: + return ICalProperty::propertyToString(getGEOProperty(), dateFmt, sResult); + case ms_cLocation: + return ICalProperty::propertyToString(getLocationProperty(), dateFmt, sResult); + case ms_cTransp: + return ICalProperty::propertyToString(getTranspProperty(), dateFmt, sResult); + case ms_cPriority: + return ICalProperty::propertyToString(getPriorityProperty(), dateFmt, sResult); + case ms_cResources: + return ICalProperty::propertyVectorToString(getResources(), dateFmt, sResult); + default: + return TimeBasedEvent::toStringChar(c, dateFmt); + } +} + +//--------------------------------------------------------------------- + +UnicodeString VEvent::formatChar(t_int32 c, UnicodeString sFilterAttendee, + t_bool delegateRequest) +{ + UnicodeString s, sResult; + switch (c) { + case ms_cDTEnd: + s = JulianKeyword::Instance()->ms_sDTEND; + return ICalProperty::propertyToICALString(s, getDTEndProperty(), sResult); + case ms_cDuration: + s = JulianKeyword::Instance()->ms_sDURATION; + s += ':'; + s += getDuration().toICALString(); + s += JulianKeyword::Instance()->ms_sLINEBREAK; + return s; + //return ICalProperty::propertyToICALString(s, getDurationProperty(), sResult); + case ms_cLocation: + s = JulianKeyword::Instance()->ms_sLOCATION; + return ICalProperty::propertyToICALString(s, getLocationProperty(), sResult); + case ms_cPriority: + s = JulianKeyword::Instance()->ms_sPRIORITY; + return ICalProperty::propertyToICALString(s, getPriorityProperty(), sResult); + case ms_cResources: + s = JulianKeyword::Instance()->ms_sRESOURCES; + return ICalProperty::propertyVectorToICALString(s, getResources(), sResult); + case ms_cGEO: + s = JulianKeyword::Instance()->ms_sGEO; + return ICalProperty::propertyToICALString(s, getGEOProperty(), sResult); + case ms_cTransp: + s = JulianKeyword::Instance()->ms_sTRANSP; + return ICalProperty::propertyToICALString(s, getTranspProperty(), sResult); + default: + { + return TimeBasedEvent::formatChar(c, sFilterAttendee, delegateRequest); + } + } +} + +//--------------------------------------------------------------------- + +t_bool VEvent::isValid() +{ + if ((getMethod().compareIgnoreCase(JulianKeyword::Instance()->ms_sPUBLISH) == 0) || + (getMethod().compareIgnoreCase(JulianKeyword::Instance()->ms_sREQUEST) == 0) || + (getMethod().compareIgnoreCase(JulianKeyword::Instance()->ms_sADD) == 0)) + { + // must have dtstart + if ((!getDTStart().isValid())) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iMissingStartingTime, 300); + return FALSE; + } + // If dtend exists, make sure it is not before dtstart + if (getDTEnd().isValid() && getDTEnd() < getDTStart()) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iEndBeforeStartTime, 300); + return FALSE; + } + // must have dtstamp, summary, uid + if (!getDTStamp().isValid()) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iMissingDTStamp, 300); + return FALSE; + } + if (getSummary().size() == 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iMissingSummary, 300); + return FALSE; + } + if (getUID().size() == 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iMissingUID, 300); + return FALSE; + } + + // TODO: must have organizer, comment out for now since CS&T doesn't have ORGANIZER + /* + if (getOrganizer().size() == 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iMissingOrganizer, 300); + return FALSE; + } + */ + // must have sequence >= 0 + if (getSequence() < 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iMissingSeqNo, 300); + return FALSE; + } + if (getMethod().compareIgnoreCase(JulianKeyword::Instance()->ms_sREQUEST) == 0) + { + if (getAttendees() == 0 || getAttendees()->GetSize() == 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iMissingAttendees, 300); + return FALSE; + } + } + } + else if ((getMethod().compareIgnoreCase(JulianKeyword::Instance()->ms_sREPLY) == 0) || + (getMethod().compareIgnoreCase(JulianKeyword::Instance()->ms_sCANCEL) == 0) || + (getMethod().compareIgnoreCase(JulianKeyword::Instance()->ms_sDECLINECOUNTER) == 0)) + { + // must have dtstamp, uid + if (!getDTStamp().isValid()) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iMissingDTStamp, 300); + return FALSE; + } + if (getUID().size() == 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iMissingUID, 300); + return FALSE; + } + + // must have organizer + if (getOrganizer().size() == 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iMissingOrganizer, 300); + return FALSE; + } + // must have sequence >= 0 + if (getSequence() < 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iMissingSeqNo, 300); + return FALSE; + } + if (getMethod().compareIgnoreCase(JulianKeyword::Instance()->ms_sREPLY) == 0) + { + // TODO: attendees are required, commenting out for now + if (getAttendees() == 0 || getAttendees()->GetSize() == 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iMissingAttendees, 300); + return FALSE; + } + } + } + else if ((getMethod().compareIgnoreCase(JulianKeyword::Instance()->ms_sREFRESH) == 0)) + { + // must have dtstamp, uid + if (!getDTStamp().isValid()) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iMissingDTStamp, 300); + return FALSE; + } + if (getUID().size() == 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iMissingUID, 300); + return FALSE; + } + // TODO: attendees required? + } + else if ((getMethod().compareIgnoreCase(JulianKeyword::Instance()->ms_sCOUNTER) == 0)) + { + // must have dtstamp, uid + if (!getDTStamp().isValid()) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iMissingDTStamp, 300); + return FALSE; + } + + if (getUID().size() == 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iMissingUID, 300); + return FALSE; + } + + // must have sequence >= 0 + if (getSequence() < 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iMissingSeqNo, 300); + return FALSE; + } + } + + // check super class isValid method + return TimeBasedEvent::isValid(); +} + +//--------------------------------------------------------------------- +#if 0 +t_bool VEvent::isCriticalInfoSame() +{ + // TODO finish + return FALSE; +} +#endif /* #if 0 */ +//--------------------------------------------------------------------- + +UnicodeString VEvent::cancelMessage() +{ + UnicodeString s = JulianKeyword::Instance()->ms_sCANCELLED; + setStatus(s); + return formatHelper(JulianFormatString::Instance()->ms_sVEventCancelMessage, ""); +} + +//--------------------------------------------------------------------- + +UnicodeString VEvent::requestMessage() +{ + return formatHelper(JulianFormatString::Instance()->ms_sVEventRequestMessage, ""); +} + +//--------------------------------------------------------------------- + +UnicodeString VEvent::requestRecurMessage() +{ + return formatHelper(JulianFormatString::Instance()->ms_sVEventRecurRequestMessage, ""); +} + +//--------------------------------------------------------------------- + +UnicodeString VEvent::counterMessage() +{ + return formatHelper(JulianFormatString::Instance()->ms_sVEventCounterMessage, ""); +} + +//--------------------------------------------------------------------- + +UnicodeString VEvent::declineCounterMessage() +{ + return formatHelper(JulianFormatString::Instance()->ms_sVEventDeclineCounterMessage, ""); +} + +//--------------------------------------------------------------------- + +UnicodeString VEvent::addMessage() +{ + return formatHelper(JulianFormatString::Instance()->ms_sVEventAddMessage, ""); +} + +//--------------------------------------------------------------------- + +UnicodeString VEvent::refreshMessage(UnicodeString sAttendeeFilter) +{ + return formatHelper(JulianFormatString::Instance()->ms_sVEventRefreshMessage, sAttendeeFilter); +} + +//--------------------------------------------------------------------- + +UnicodeString VEvent::allMessage() +{ + return formatHelper(JulianFormatString::Instance()->ms_sVEventAllPropertiesMessage, ""); +} + +//--------------------------------------------------------------------- + +UnicodeString VEvent::replyMessage(UnicodeString sAttendeeFilter) +{ + return formatHelper(JulianFormatString::Instance()->ms_sVEventReplyMessage, sAttendeeFilter); +} + +//--------------------------------------------------------------------- + +UnicodeString VEvent::publishMessage() +{ + return formatHelper(JulianFormatString::Instance()->ms_sVEventPublishMessage, ""); +} + +//--------------------------------------------------------------------- + +UnicodeString VEvent::publishRecurMessage() +{ + return formatHelper(JulianFormatString::Instance()->ms_sVEventRecurPublishMessage, ""); +} + +//--------------------------------------------------------------------- +void +VEvent::updateComponentHelper(TimeBasedEvent * updatedComponent) +{ + //TODO: handle duration, origDTEnd, origMyDTEnd. + TimeBasedEvent::updateComponentHelper(updatedComponent); + if (updatedComponent->GetType() == GetType()) + { + ICalComponent::internalSetPropertyVctr(&m_ResourcesVctr, ((VEvent *) updatedComponent)->getResources()); + ICalComponent::internalSetProperty(&m_DTEnd, ((VEvent *) updatedComponent)->m_DTEnd); + ICalComponent::internalSetProperty(&m_GEO, ((VEvent *) updatedComponent)->m_GEO); + ICalComponent::internalSetProperty(&m_Location, ((VEvent *) updatedComponent)->m_Location); + ICalComponent::internalSetProperty(&m_Priority, ((VEvent *) updatedComponent)->m_Priority); + ICalComponent::internalSetProperty(&m_Transp, ((VEvent *) updatedComponent)->m_Transp); + } +} +//--------------------------------------------------------------------- +///DTEnd +void VEvent::setDTEnd(DateTime s, JulianPtrArray * parameters) +{ +#if 1 + if (m_DTEnd == 0) + m_DTEnd = ICalPropertyFactory::Make(ICalProperty::DATETIME, + (void *) &s, parameters); + else + { + m_DTEnd->setValue((void *) &s); + m_DTEnd->setParameters(parameters); + } + //validateDTEnd(); +#else + ICalComponent::setDateTimeValue(((ICalProperty **) &m_DTEnd), s, parameters); +#endif +} +DateTime VEvent::getDTEnd() const +{ +#if 1 + DateTime d(-1); + if (m_DTEnd == 0) + return d; //return 0; + else + { + d = *((DateTime *) m_DTEnd->getValue()); + return d; + } +#else + DateTime d(-1); + ICalComponent::getDateTimeValue(((ICalProperty **) &m_DTEnd), d); + return d; +#endif +} +//--------------------------------------------------------------------- +///Duration +void VEvent::setDuration(Julian_Duration s, JulianPtrArray * parameters) +{ + /* + if (m_Duration == 0) + m_Duration = ICalPropertyFactory::Make(ICalProperty::DURATION, + (void *) &s, parameters); + else + { + m_Duration->setValue((void *) &s); + m_Duration->setParameters(parameters); + } + //validateDuration(); + */ + // NOTE: remove later, to avoid compiler warnings + if (parameters) + { + } + + + DateTime end; + end = getDTStart(); + end.add(s); + setDTEnd(end); +} +Julian_Duration VEvent::getDuration() const +{ + /* + Duration d; d.setMonth(-1); + if (m_Duration == 0) + return d; // return 0; + else + { + d = *((Duration *) m_Duration->getValue()); + return d; + } + */ + Julian_Duration duration; + DateTime start, end; + start = getDTStart(); + end = getDTEnd(); + DateTime::getDuration(start,end,duration); + return duration; +} +//--------------------------------------------------------------------- +//GEO +void VEvent::setGEO(UnicodeString s, JulianPtrArray * parameters) +{ +#if 1 + //UnicodeString * s_ptr = new UnicodeString(s); + //PR_ASSERT(s_ptr != 0); + + if (m_GEO == 0) + m_GEO = ICalPropertyFactory::Make(ICalProperty::TEXT, + (void *) &s, parameters); + else + { + m_GEO->setValue((void *) &s); + m_GEO->setParameters(parameters); + } +#else + ICalComponent::setStringValue(((ICalProperty **) &m_GEO), s, parameters); +#endif +} +UnicodeString VEvent::getGEO() const +{ +#if 1 + if (m_GEO == 0) + return ""; + else + return *((UnicodeString *) m_GEO->getValue()); +#else + UnicodeString us; + ICalComponent::getStringValue(((ICalProperty **) &m_GEO), us); + return us; +#endif + +} + +//--------------------------------------------------------------------- +//Location +void VEvent::setLocation(UnicodeString s, JulianPtrArray * parameters) +{ +#if 1 + //UnicodeString * s_ptr = new UnicodeString(s); + //PR_ASSERT(s_ptr != 0); + + if (m_Location == 0) + { + m_Location = ICalPropertyFactory::Make(ICalProperty::TEXT, + (void *) &s, parameters); + } + else + { + m_Location->setValue((void *) &s); + m_Location->setParameters(parameters); + } +#else + ICalComponent::setStringValue(((ICalProperty **) &m_Location), s, parameters); +#endif +} +UnicodeString VEvent::getLocation() const +{ +#if 1 + if (m_Location == 0) + return ""; + else + return *((UnicodeString *) m_Location->getValue()); +#else + UnicodeString us; + ICalComponent::getStringValue(((ICalProperty **) &m_Location), us); + return us; +#endif +} +//--------------------------------------------------------------------- +//Priority +void VEvent::setPriority(t_int32 i, JulianPtrArray * parameters) +{ +#if 1 + if (m_Priority == 0) + m_Priority = ICalPropertyFactory::Make(ICalProperty::INTEGER, + (void *) &i, parameters); + else + { + m_Priority->setValue((void *) &i); + m_Priority->setParameters(parameters); + } +#else + ICalComponent::setIntegerValue(((ICalProperty **) &m_Priority), i, parameters); +#endif +} +t_int32 VEvent::getPriority() const +{ +#if 1 + if (m_Priority == 0) + return -1; + else + return *((t_int32 *) m_Priority->getValue()); +#else + t_int32 i = -1; + ICalComponent::getIntegerValue(((ICalProperty **) &m_Priority), i); + return i; +#endif +} +//--------------------------------------------------------------------- +//Transp +void VEvent::setTransp(UnicodeString s, JulianPtrArray * parameters) +{ +#if 1 + //UnicodeString * s_ptr = new UnicodeString(s); + //PR_ASSERT(s_ptr != 0); + + if (m_Transp == 0) + m_Transp = ICalPropertyFactory::Make(ICalProperty::TEXT, + (void *) &s, parameters); + else + { + m_Transp->setValue((void *) &s); + m_Transp->setParameters(parameters); + } +#else + ICalComponent::setStringValue(((ICalProperty **) &m_Transp), s, parameters); +#endif +} +UnicodeString VEvent::getTransp() const +{ +#if 1 + if (m_Transp == 0) + return ""; + else + return *((UnicodeString *) m_Transp->getValue()); +#else + UnicodeString us; + ICalComponent::getStringValue(((ICalProperty **) &m_Transp), us); + return us; +#endif +} +//--------------------------------------------------------------------- +// RESOURCES +void VEvent::addResources(UnicodeString s, JulianPtrArray * parameters) +{ + ICalProperty * prop = ICalPropertyFactory::Make(ICalProperty::TEXT, + (void *) &s, parameters); + addResourcesProperty(prop); +} + +//--------------------------------------------------------------------- + +void VEvent::addResourcesProperty(ICalProperty * prop) +{ + if (m_ResourcesVctr == 0) + m_ResourcesVctr = new JulianPtrArray(); + PR_ASSERT(m_ResourcesVctr != 0); + if (m_ResourcesVctr != 0) + { + m_ResourcesVctr->Add(prop); + } +} + +//--------------------------------------------------------------------- + +void +VEvent::addResourcesPropertyVector(UnicodeString & propVal, + JulianPtrArray * parameters) +{ + //ICalProperty * ip; + + //ip = ICalPropertyFactory::Make(ICalProperty::TEXT, new UnicodeString(propVal), + // parameters); + addResources(propVal, parameters); + //addResourcesProperty(ip); + + +#if 0 + // TODO: see TimeBasedEvent::addCategoriesPropertyVector() + + ErrorCode status = ZERO_ERROR; + UnicodeStringTokenizer * st; + UnicodeString us; + UnicodeString sDelim = ","; + + st = new UnicodeStringTokenizer(propVal, sDelim); + //ICalProperty * ip; + while (st->hasMoreTokens()) + { + us = st->nextToken(us, status); + us.trim(); + //if (FALSE) TRACE("us = %s, status = %d", us.toCString(""), status); + // TODO: if us is in Resources range then add, else, log and error + addResourcesProperty(ICalPropertyFactory::Make(ICalProperty::TEXT, + new UnicodeString(us), parameters)); + } + delete st; st = 0; +#endif + +} +//--------------------------------------------------------------------- + diff --git a/calendar/modules/core/ical/src/vfrbsy.cpp b/calendar/modules/core/ical/src/vfrbsy.cpp new file mode 100644 index 00000000000..9963eaf6ee0 --- /dev/null +++ b/calendar/modules/core/ical/src/vfrbsy.cpp @@ -0,0 +1,2101 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +// vfrbsy.cpp +// John Sun +// 4:46 PM Febuary 19 1998 + +#include "stdafx.h" +#include "jdefines.h" + +#include "vfrbsy.h" +#include "prprty.h" +#include "prprtyfy.h" +#include "freebusy.h" +#include "jutility.h" +#include "jlog.h" +#include "vtimezne.h" +#include "keyword.h" +#include "orgnzr.h" + +#include "functbl.h" +//--------------------------------------------------------------------- +// private never use +#if 0 +VFreebusy::VFreebusy() +{ + PR_ASSERT(FALSE); +} +#endif + +//--------------------------------------------------------------------- + +void VFreebusy::selfCheck() +{ + // if no dtend, and there is a dtstart and duration, calculate dtend + if (!getDTEnd().isValid()) + { + // calculate DTEnd from duration and dtstart + // TODO: remove memory leaks in m_TempDuration + if (getDTStart().isValid() && m_TempDuration != 0 && m_TempDuration->isValid()) + { + DateTime end; + end = getDTStart(); + end.add(*m_TempDuration); + setDTEnd(end); + delete m_TempDuration; m_TempDuration = 0; // lifetime of variable is only + // after load. + } + else if (!getDTStart().isValid()) + { + if (m_TempDuration != 0) + delete m_TempDuration; m_TempDuration = 0; + } + } + + if (getFreebusy() != 0 && getDTStart().isValid() && getDTEnd().isValid()) + normalize(); + // if sequence is null, set to 0. + if (getSequence() == -1) + setSequence(0); +} + +//--------------------------------------------------------------------- + +void VFreebusy::combineSameFreebusies(JulianPtrArray * freebusies) +{ + t_int32 i = 0; + t_int32 j = 0; + Freebusy * f1 = 0; + Freebusy * f2 = 0; + + if (freebusies != 0 && freebusies->GetSize() >= 2) + { + // merge similar freebusy + for (i = 0; i < freebusies->GetSize() - 1; i++) + { + f1 = (Freebusy *) freebusies->GetAt(i); + for (j = i + 1; j < freebusies->GetSize() ; j++) + { + f2 = (Freebusy *) freebusies->GetAt(j); + if (Freebusy::HasSameParams(f1, f2)) + { + // add all periods in f1 into f2 + // remove f1 from freebusies. delete f1 + f1->addAllPeriods(f2->getPeriod()); + delete f2; f2 = 0; + freebusies->RemoveAt(j); + j--; + } + } + } + } +} + +//--------------------------------------------------------------------- +#if 0 +void VFreebusy::DEBUG_printFreebusyVector(const char * message, JulianPtrArray * freebusies) +{ +#if TESTING_ITIPRIG + if (TRUE) TRACE(message); +#endif + + UnicodeString sResult; + if (freebusies != 0) + { + t_int32 i; + UnicodeString s; + for (i = 0; i < freebusies->GetSize(); i++) + { + s = ((Freebusy *) freebusies->GetAt(i))->toICALString(s); + sResult += ICalProperty::multiLineFormat(s); + } + } + +#if TESTING_ITIPRIG + if (TRUE) TRACE("%s\r\n", sResult.toCString("")); +#endif +} +#endif +//--------------------------------------------------------------------- + +void VFreebusy::mergeSinglePeriodFreebusies() +{ + sortFreebusy(); + + // 1) combine same params freebusy + combineSameFreebusies(getFreebusy()); + //DEBUG_printFreebusyVector("after combining\r\n", getFreebusy()); + + // 2) normalize each freebusy (compress overlapping periods) + compressFreebusies(getFreebusy()); + //DEBUG_printFreebusyVector("after compressing\r\n", getFreebusy()); + + // 3) Unzip freebusies + unzipFreebusies(); + //DEBUG_printFreebusyVector("after unzipping\r\n", getFreebusy()); +} + +//--------------------------------------------------------------------- + +void VFreebusy::compressFreebusies(JulianPtrArray * freebusies) +{ + if (freebusies != 0) + { + t_int32 i; + Freebusy * f1 = 0; + for (i = 0; i < freebusies->GetSize(); i++) + { + f1 = (Freebusy *) freebusies->GetAt(i); + f1->normalizePeriods(); + } + } +} +//--------------------------------------------------------------------- + +void VFreebusy::unzipFreebusies() +{ + JulianPtrArray * freebusies = getFreebusy(); + if (freebusies != 0) + { + t_int32 oldSize = freebusies->GetSize(); + t_int32 i = 0; + t_int32 j = 0; + Freebusy * f1 = 0; + Freebusy * f2 = 0; + + for (i = oldSize - 1; i >= 0; i--) + { + f1 = (Freebusy *) freebusies->GetAt(i); + if (f1->getPeriod() != 0) + { + // foreach period in f1, create a new freebusy for it, + // add to freebusy vector + for (j = 0; j < f1->getPeriod()->GetSize(); j++) + { + f2 = new Freebusy(m_Log); + PR_ASSERT(f2 != 0); + if (f2 != 0) + { + f2->setType(f1->getType()); +#if 0 + f2->setStatus(f1->getStatus()); +#endif + f2->addPeriod((Period *) f1->getPeriod()->GetAt(j)); + addFreebusy(f2); + } + } + } + // now delete f1 + delete f1; f1 = 0; + freebusies->RemoveAt(i); + } + } +} + +//--------------------------------------------------------------------- +void VFreebusy::addExtraFreePeriodFreebusies(JulianPtrArray * freebusies) +{ + if (freebusies != 0) + { + Freebusy * fb; + Period *p; + t_int32 i = 0; + t_int32 j = 0; + t_int32 oldSize = freebusies->GetSize(); + if (getDTStart().isValid() && getDTEnd().isValid()) + { + sortFreebusy(); + DateTime startTime, nextTime, endTime; + startTime = getDTStart(); + nextTime = startTime; + + for (i = 0; i < oldSize; i++) + { + fb = (Freebusy *) freebusies->GetAt(i); + + PR_ASSERT(fb != 0 && fb->getPeriod()->GetSize() == 1); + + p = (Period *) fb->getPeriod()->GetAt(0); + + nextTime = p->getEndingTime(nextTime); + endTime = p->getStart(); + + if (startTime < endTime) + { + // add a new freebusy period + fb = new Freebusy(m_Log); PR_ASSERT(fb != 0); + fb->setType(Freebusy::FB_TYPE_FREE); +#if 0 + fb->setStatus(Freebusy::FB_STATUS_TENTATIVE); // for dbg +#endif + p = new Period(); + p->setStart(startTime); + p->setEnd(endTime); + fb->addPeriod(p); // ownership of p not taken, must delete + delete p; p = 0; + freebusies->Add(fb); // fb ownership taken + } + startTime = nextTime; + } + endTime = getDTEnd(); + if (nextTime < endTime) + { + // add final period + // add a new freebusy period + fb = new Freebusy(m_Log); PR_ASSERT(fb != 0); + fb->setType(Freebusy::FB_TYPE_FREE); +#if 0 + fb->setStatus(Freebusy::FB_STATUS_TENTATIVE); // for dbg +#endif + p = new Period(); + p->setStart(nextTime); + p->setEnd(endTime); + fb->addPeriod(p); // ownership of p not taken, must delete + delete p; p = 0; + freebusies->Add(fb); // fb ownership taken + } + sortFreebusy(); + } + } +} + +//--------------------------------------------------------------------- + +void VFreebusy::normalize() +{ + // 1) Can mergeSinglePeriodFreebusies first time + mergeSinglePeriodFreebusies(); + + // 2) I will now add FREE freebusy periods to those periods not already covered. + addExtraFreePeriodFreebusies(getFreebusy()); + //DEBUG_printFreebusyVector("----- after make free 4)\r\n", v); + + // 3) Combine consective free periods. This is OPTIONAL. + mergeSinglePeriodFreebusies(); + //DEBUG_printFreebusyVector("----- after merge-single-period freebusies 5)\r\n", v); + + sortFreebusy(); +} +//--------------------------------------------------------------------- + +void VFreebusy::sortFreebusy() +{ + if (m_FreebusyVctr != 0) + m_FreebusyVctr->QuickSort(Freebusy::CompareFreebusy); +} + +//--------------------------------------------------------------------- + +void VFreebusy::stamp() +{ + DateTime d; + setDTStamp(d); +} + +//--------------------------------------------------------------------- + +VFreebusy::VFreebusy(JLog * initLog) +: m_AttendeesVctr(0), m_CommentVctr(0), + /*m_Created(0), */ + /*m_Duration(0),*/ + m_TempDuration(0), + m_DTEnd(0), m_DTStart(0), m_DTStamp(0), m_FreebusyVctr(0), + m_LastModified(0), + m_Organizer(0), + m_RequestStatusVctr(0), + //m_RelatedToVctr(0), + m_Sequence(0), m_UID(0), + m_URL(0), + //m_URLVctr(0), + m_XTokensVctr(0), + m_ContactVctr(0), + m_Log(initLog) +{ + //PR_ASSERT(initLog != 0); +} + +//--------------------------------------------------------------------- + +VFreebusy::VFreebusy(VFreebusy & that) +: m_AttendeesVctr(0), m_CommentVctr(0), + /*m_Created(0),*/ + //m_Duration(0), + m_TempDuration(0), + m_DTEnd(0), m_DTStart(0), m_DTStamp(0), m_FreebusyVctr(0), + m_LastModified(0), + m_Organizer(0), + m_RequestStatusVctr(0), + //m_RelatedToVctr(0), + m_Sequence(0), m_UID(0), + m_URL(0), + //m_URLVctr(0), + m_ContactVctr(0), + m_XTokensVctr(0) +{ + if (that.m_AttendeesVctr != 0) + { + m_AttendeesVctr = new JulianPtrArray(); PR_ASSERT(m_AttendeesVctr != 0); + if (m_AttendeesVctr != 0) + { + ICalProperty::CloneICalPropertyVector(that.m_AttendeesVctr, m_AttendeesVctr, m_Log); + } + } + if (that.m_CommentVctr != 0) + { + m_CommentVctr = new JulianPtrArray(); PR_ASSERT(m_CommentVctr != 0); + if (m_CommentVctr != 0) + { + ICalProperty::CloneICalPropertyVector(that.m_CommentVctr, m_CommentVctr, m_Log); + } + } + if (that.m_ContactVctr != 0) + { + m_ContactVctr = new JulianPtrArray(); PR_ASSERT(m_ContactVctr != 0); + if (m_ContactVctr != 0) + { + ICalProperty::CloneICalPropertyVector(that.m_ContactVctr, m_ContactVctr, m_Log); + } + } + /* + if (that.m_Created != 0) + { + m_Created = that.m_Created->clone(m_Log); + } + */ + /* + if (that.m_Duration != 0) + { + m_Duration = that.m_Duration->clone(m_Log); + } + */ + if (that.m_DTEnd != 0) + { + m_DTEnd = that.m_DTEnd->clone(m_Log); + } + if (that.m_DTStart != 0) + { + m_DTStart = that.m_DTStart->clone(m_Log); + } + if (that.m_DTStamp != 0) + { + m_DTStamp = that.m_DTStamp->clone(m_Log); + } + if (that.m_FreebusyVctr != 0) + { + m_FreebusyVctr = new JulianPtrArray(); PR_ASSERT(m_FreebusyVctr != 0); + if (m_FreebusyVctr != 0) + { + ICalProperty::CloneICalPropertyVector(that.m_FreebusyVctr, m_FreebusyVctr, m_Log); + } + } + if (that.m_LastModified != 0) + { + m_LastModified = that.m_LastModified->clone(m_Log); + } + if (that.m_Organizer != 0) + { + m_Organizer = that.m_Organizer->clone(m_Log); + } + if (that.m_RequestStatusVctr != 0) + { + //m_RequestStatus = that.m_RequestStatus->clone(m_Log); + m_RequestStatusVctr = new JulianPtrArray(); PR_ASSERT(m_RequestStatusVctr != 0); + if (m_RequestStatusVctr != 0) + { + ICalProperty::CloneICalPropertyVector(that.m_RequestStatusVctr, m_RequestStatusVctr, m_Log); + } + } + if (that.m_Sequence != 0) + { + m_Sequence = that.m_Sequence->clone(m_Log); + } + if (that.m_UID != 0) + { + m_UID = that.m_UID->clone(m_Log); + } + if (that.m_URL != 0) + { + m_URL = that.m_URL->clone(m_Log); + } + if (that.m_XTokensVctr != 0) + { + m_XTokensVctr = new JulianPtrArray(); PR_ASSERT(m_XTokensVctr != 0); + if (m_XTokensVctr != 0) + { + ICalProperty::CloneUnicodeStringVector(that.m_XTokensVctr, m_XTokensVctr); + } + } +} + +//--------------------------------------------------------------------- + +ICalComponent * +VFreebusy::clone(JLog * initLog) +{ + m_Log = initLog; + //PR_ASSERT(m_Log != 0); + return new VFreebusy(*this); +} + +//--------------------------------------------------------------------- +VFreebusy::~VFreebusy() +{ + // datetime properties + /* + if (m_Created != 0) + { + delete m_Created; m_Created = 0; + } + */ + if (m_TempDuration != 0) + { + delete m_TempDuration; m_TempDuration = 0; + } + if (m_DTStart != 0) + { + delete m_DTStart; m_DTStart = 0; + } + if (m_DTStamp != 0) + { + delete m_DTStamp; m_DTStamp = 0; + } + if (m_LastModified != 0) + { + delete m_LastModified; m_LastModified = 0; + } + if (m_DTEnd != 0) + { + delete m_DTEnd; m_DTEnd = 0; + } + /* + if (m_Duration != 0) + { + delete m_Duration; m_Duration = 0; + } + */ + // string properties + if (m_RequestStatusVctr != 0) + { + //delete m_RequestStatus; m_RequestStatus = 0; + ICalProperty::deleteICalPropertyVector(m_RequestStatusVctr); + delete m_RequestStatusVctr; m_RequestStatusVctr = 0; + } + if (m_Organizer != 0) + { + delete m_Organizer; m_Organizer = 0; + } + if (m_UID != 0) + { + delete m_UID; m_UID = 0; + } + if (m_URL != 0) + { + delete m_URL; m_URL = 0; + } + + // integer properties + if (m_Sequence != 0) + { + delete m_Sequence; m_Sequence = 0; + } + + // attendees + if (m_AttendeesVctr != 0) { + ICalProperty::deleteICalPropertyVector(m_AttendeesVctr); + delete m_AttendeesVctr; m_AttendeesVctr = 0; + } + // freebusy + if (m_FreebusyVctr != 0) { + ICalProperty::deleteICalPropertyVector(m_FreebusyVctr); + delete m_FreebusyVctr; m_FreebusyVctr = 0; + } + + // string vectors + if (m_CommentVctr != 0) + { + ICalProperty::deleteICalPropertyVector(m_CommentVctr); + delete m_CommentVctr; m_CommentVctr = 0; + } + //if (m_RelatedToVctr != 0) { ICalProperty::deleteICalPropertyVector(m_RelatedToVctr); + // delete m_RelatedToVctr; m_RelatedToVctr = 0; } + //if (m_URLVctr != 0) { ICalProperty::deleteICalPropertyVector(m_URLVctr); + // delete m_URLVctr; m_URLVctr = 0; } + + if (m_ContactVctr != 0) + { + ICalProperty::deleteICalPropertyVector(m_ContactVctr); + delete m_ContactVctr; m_ContactVctr = 0; + } + if (m_XTokensVctr != 0) { ICalComponent::deleteUnicodeStringVector(m_XTokensVctr); + delete m_XTokensVctr; m_XTokensVctr = 0; + } +} +//--------------------------------------------------------------------- +UnicodeString & +VFreebusy::parse(ICalReader * brFile, UnicodeString & method, + UnicodeString & parseStatus, JulianPtrArray * vTimeZones, + t_bool bIgnoreBeginError, JulianUtility::MimeEncoding encoding) +{ + parseStatus = JulianKeyword::Instance()->ms_sOK; + UnicodeString strLine, propName, propVal; + + JulianPtrArray * parameters = new JulianPtrArray(); + PR_ASSERT(parameters != 0 && brFile != 0); + if (parameters == 0 || brFile == 0) + { + // ran out of memory, return invalid VFreebusy + return parseStatus; + } + + ErrorCode status = ZERO_ERROR; + + setMethod(method); + + while (TRUE) + { + PR_ASSERT(brFile != 0); + brFile->readFullLine(strLine, status); + ICalProperty::Trim(strLine); + + if (FAILURE(status) && strLine.size() == 0) + break; + + ICalProperty::parsePropertyLine(strLine, propName, propVal, parameters); + + if (strLine.size() == 0) + { + ICalProperty::deleteICalParameterVector(parameters); + parameters->RemoveAll(); + + continue; + } + else if ((propName.compareIgnoreCase(JulianKeyword::Instance()->ms_sEND) == 0) && + (propVal.compareIgnoreCase(JulianKeyword::Instance()->ms_sVFREEBUSY) == 0)) + { + ICalProperty::deleteICalParameterVector(parameters); + parameters->RemoveAll(); + + break; + } + else if ( + ((propName.compareIgnoreCase(JulianKeyword::Instance()->ms_sBEGIN) == 0) && + ((propVal.compareIgnoreCase(JulianKeyword::Instance()->ms_sVFREEBUSY) == 0) && !bIgnoreBeginError )|| + ((propVal.compareIgnoreCase(JulianKeyword::Instance()->ms_sVCALENDAR) == 0) || + (propVal.compareIgnoreCase(JulianKeyword::Instance()->ms_sVEVENT) == 0) || + (propVal.compareIgnoreCase(JulianKeyword::Instance()->ms_sVTODO) == 0) || + (propVal.compareIgnoreCase(JulianKeyword::Instance()->ms_sVJOURNAL) == 0) || + (propVal.compareIgnoreCase(JulianKeyword::Instance()->ms_sVTIMEZONE) == 0) || + (ICalProperty::IsXToken(propVal))) + ) || + ((propName.compareIgnoreCase(JulianKeyword::Instance()->ms_sEND) == 0) && + ((propVal.compareIgnoreCase(JulianKeyword::Instance()->ms_sVCALENDAR) == 0) || + (propVal.compareIgnoreCase(JulianKeyword::Instance()->ms_sVEVENT) == 0) || + (propVal.compareIgnoreCase(JulianKeyword::Instance()->ms_sVTODO) == 0) || + (propVal.compareIgnoreCase(JulianKeyword::Instance()->ms_sVJOURNAL) == 0) || + (propVal.compareIgnoreCase(JulianKeyword::Instance()->ms_sVTIMEZONE) == 0) || + (ICalProperty::IsXToken(propVal))) + ) + ) //else if + { + // break on + // END:VCALENDAR, VEVENT, VTODO, VJOURNAL, VTIMEZONE, x-token + // BEGIN:VEVENT, VTODO, VJOURNAL, VFREEBUSY, VTIMEZONE, VCALENDAR, x-token + ICalProperty::deleteICalParameterVector(parameters); + parameters->RemoveAll(); + + parseStatus = strLine; + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iAbruptEndOfParsing, + JulianKeyword::Instance()->ms_sVFREEBUSY, strLine, 300); + break; + } + else + { +//#ifdef TIMING + //clock_t start, end; + //start = clock(); +//#endif + storeData(strLine, propName, propVal, parameters, vTimeZones); +//#ifdef TIMING + //end = clock(); + //double d = end - start; + //if (FALSE) TRACE("storeData on %s took %f ms.\r\n", propName.toCString(""), d); +//#endif + ICalProperty::deleteICalParameterVector(parameters); + parameters->RemoveAll(); + + } + } + ICalProperty::deleteICalParameterVector(parameters); + parameters->RemoveAll(); + delete parameters; parameters = 0; + + selfCheck(); // sorts freebusy vector as well + return parseStatus; +} +//--------------------------------------------------------------------- +t_bool +VFreebusy::storeData(UnicodeString & strLine, UnicodeString & propName, + UnicodeString & propVal, JulianPtrArray * parameters, + JulianPtrArray * vTimeZones) +{ + t_int32 hashCode = propName.hashCode(); + t_int32 i; + for (i = 0; 0 != (JulianFunctionTable::Instance()->vfStoreTable[i]).op; i++) + { + if ((JulianFunctionTable::Instance()->vfStoreTable[i]).hashCode == hashCode) + { + ApplyStoreOp(((JulianFunctionTable::Instance())->vfStoreTable[i]).op, + strLine, propVal, parameters, vTimeZones); + return TRUE; + } + } + if (ICalProperty::IsXToken(propName)) + { + addXTokens(strLine); + return TRUE; + } + else + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iInvalidPropertyName, + JulianKeyword::Instance()->ms_sVFREEBUSY, propName, 200); + UnicodeString u; + u = JulianLogErrorMessage::Instance()->ms_sRS202; + u += '.'; u += ' '; + u += strLine; + //setRequestStatus(JulianLogErrorMessage::Instance()->ms_iRS202); + addRequestStatus(u); + return FALSE; + } + return FALSE; +} +//--------------------------------------------------------------------- +void VFreebusy::storeAttendees(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones) +{ + Attendee * attendee = new Attendee(GetType(), m_Log); + PR_ASSERT(attendee != 0); + if (attendee != 0) + { + attendee->parse(propVal, parameters); + if (!attendee->isValid()) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iInvalidAttendee, + JulianKeyword::Instance()->ms_sVFREEBUSY, propVal, 200); + UnicodeString u; + u = JulianLogErrorMessage::Instance()->ms_sRS202; + u += '.'; u += ' '; + u += strLine; + //setRequestStatus(JulianLogErrorMessage::Instance()->ms_iRS202); + addRequestStatus(u); + delete attendee; attendee = 0; + } + else + { + addAttendee(attendee); + } + } +} +void VFreebusy::storeComment(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones) +{ + // check parameters + t_bool bParamValid = ICalProperty::CheckParams(parameters, + JulianAtomRange::Instance()->ms_asAltrepLanguageParamRange, + JulianAtomRange::Instance()->ms_asAltrepLanguageParamRangeSize); + + if (!bParamValid) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iInvalidOptionalParam, + JulianKeyword::Instance()->ms_sVFREEBUSY, strLine, 100); + } + addComment(propVal, parameters); +} +void VFreebusy::storeContact(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones) +{ + // check parameters + t_bool bParamValid = ICalProperty::CheckParams(parameters, + JulianAtomRange::Instance()->ms_asAltrepLanguageParamRange, + JulianAtomRange::Instance()->ms_asAltrepLanguageParamRangeSize); + if (!bParamValid) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iInvalidOptionalParam, + JulianKeyword::Instance()->ms_sVFREEBUSY, strLine, 100); + } + addContact(propVal, parameters); +} +/* +void VFreebusy::storeCreated(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones) +{ + if (parameters->GetSize() > 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iInvalidOptionalParam, + JulianKeyword::Instance()->ms_sVFREEBUSY, strLine, 100); + } + + if (getCreatedProperty() != 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iDuplicatedProperty, + JulianKeyword::Instance()->ms_sVFREEBUSY, + JulianKeyword::Instance()->ms_sCREATED, 100); + } + DateTime d; + d = VTimeZone::DateTimeApplyTimeZone(propVal, vTimeZones, parameters); + + setCreated(d , parameters); +} +*/ +void VFreebusy::storeDuration(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones) +{ + // no parameters + if (parameters->GetSize() > 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iInvalidOptionalParam, + JulianKeyword::Instance()->ms_sVFREEBUSY, strLine, 100); + } + + if (m_TempDuration != 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iDuplicatedProperty, + JulianKeyword::Instance()->ms_sVFREEBUSY, + JulianKeyword::Instance()->ms_sDURATION, 100); + } + //Duration d(propVal); + if (m_TempDuration == 0) + { + m_TempDuration = new Julian_Duration(propVal); + PR_ASSERT(m_TempDuration != 0); + } + else + m_TempDuration->setDurationString(propVal); +} +void VFreebusy::storeDTEnd(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones) +{ + // no parameters (MUST BE IN UTC) + if (parameters->GetSize() > 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iInvalidOptionalParam, + JulianKeyword::Instance()->ms_sVFREEBUSY, strLine, 100); + } + + // DTEND must be in UTC + if (getDTEndProperty() != 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iDuplicatedProperty, + JulianKeyword::Instance()->ms_sVFREEBUSY, + JulianKeyword::Instance()->ms_sDTEND, 100); + } + DateTime d; + d = VTimeZone::DateTimeApplyTimeZone(propVal, vTimeZones, parameters); + + setDTEnd(d, parameters); +} +void VFreebusy::storeDTStart(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones) +{ + // no parameters (MUST BE IN UTC) + if (parameters->GetSize() > 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iInvalidOptionalParam, + JulianKeyword::Instance()->ms_sVFREEBUSY, strLine, 100); + } + + // DTSTART must be in UTC + if (getDTStartProperty() != 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iDuplicatedProperty, + JulianKeyword::Instance()->ms_sVFREEBUSY, + JulianKeyword::Instance()->ms_sDTSTART, 100); + } + DateTime d; + d = VTimeZone::DateTimeApplyTimeZone(propVal, vTimeZones, parameters); + + setDTStart(d, parameters); +} +void VFreebusy::storeDTStamp(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones) +{ + // no parameters (MUST BE IN UTC) + if (parameters->GetSize() > 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iInvalidOptionalParam, + JulianKeyword::Instance()->ms_sVFREEBUSY, strLine, 100); + } + + if (getDTStampProperty() != 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iDuplicatedProperty, + JulianKeyword::Instance()->ms_sVFREEBUSY, + JulianKeyword::Instance()->ms_sDTSTAMP, 100); + } + DateTime d; + d = VTimeZone::DateTimeApplyTimeZone(propVal, vTimeZones, parameters); + + setDTStamp(d, parameters); +} +void VFreebusy::storeFreebusy(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones) +{ + // Freebusy must be in UTC + Freebusy * freeb = new Freebusy(m_Log); + PR_ASSERT(freeb != 0); + if (freeb != 0) + { + freeb->parse(propVal, parameters, vTimeZones); + if (!freeb->isValid()) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iInvalidFreebusy, 200); + UnicodeString u; + u = JulianLogErrorMessage::Instance()->ms_sRS202; + u += '.'; u += ' '; + u += strLine; + //setRequestStatus(JulianLogErrorMessage::Instance()->ms_iRS202); + addRequestStatus(u); + delete freeb; freeb = 0; + } + else + { + addFreebusy(freeb); + } + } +} +void VFreebusy::storeLastModified(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones) +{ + // no parameters (MUST BE IN UTC) + if (parameters->GetSize() > 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iInvalidOptionalParam, + JulianKeyword::Instance()->ms_sVFREEBUSY, strLine, 100); + } + + if (getLastModified().getTime() >= 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iDuplicatedProperty, + JulianKeyword::Instance()->ms_sVFREEBUSY, + JulianKeyword::Instance()->ms_sLASTMODIFIED, 100); + } + DateTime d; + d = VTimeZone::DateTimeApplyTimeZone(propVal, vTimeZones, parameters); + + setLastModified(d, parameters); +} +void VFreebusy::storeOrganizer(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones) +{ + // check parameters + t_bool bParamValid = ICalProperty::CheckParams(parameters, + JulianAtomRange::Instance()->ms_asSentByParamRange, + JulianAtomRange::Instance()->ms_asSentByParamRangeSize); + if (!bParamValid) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iInvalidOptionalParam, + JulianKeyword::Instance()->ms_sVFREEBUSY, strLine, 100); + } + + if (getOrganizerProperty() != 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iDuplicatedProperty, + JulianKeyword::Instance()->ms_sVFREEBUSY, + JulianKeyword::Instance()->ms_sORGANIZER, 100); + } + setOrganizer(propVal, parameters); +} +void VFreebusy::storeRequestStatus(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones) +{ + // check parameters + t_bool bParamValid = ICalProperty::CheckParams(parameters, + JulianAtomRange::Instance()->ms_asLanguageParamRange, + JulianAtomRange::Instance()->ms_asLanguageParamRangeSize); + if (!bParamValid) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iInvalidOptionalParam, + JulianKeyword::Instance()->ms_sVFREEBUSY, strLine, 100); + } +#if 0 + /* Don't print duplicated property on Request Status */ + if (getRequestStatusProperty() != 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iDuplicatedProperty, + JulianKeyword::Instance()->ms_sVFREEBUSY, + JulianKeyword::Instance()->ms_sREQUESTSTATUS, 100); + } + +#endif + addRequestStatus(propVal, parameters); +} +void VFreebusy::storeSequence(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones) +{ + t_bool bParseError = FALSE; + t_int32 i; + + // no parameters + if (parameters->GetSize() > 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iInvalidOptionalParam, + JulianKeyword::Instance()->ms_sVFREEBUSY, strLine, 100); + } + + char * pcc = propVal.toCString(""); + PR_ASSERT(pcc != 0); + i = JulianUtility::atot_int32(pcc, bParseError, propVal.size()); + delete [] pcc; pcc = 0; + if (getSequenceProperty() != 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iDuplicatedProperty, + JulianKeyword::Instance()->ms_sVFREEBUSY, + JulianKeyword::Instance()->ms_sSEQUENCE, 100); + } + if (!bParseError) + { + setSequence(i, parameters); + } + else + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iInvalidNumberFormat, + JulianKeyword::Instance()->ms_sVFREEBUSY, + JulianKeyword::Instance()->ms_sSEQUENCE, propVal, 200); + } +} +void VFreebusy::storeUID(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones) +{ + // no parameters + if (parameters->GetSize() > 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iInvalidOptionalParam, + JulianKeyword::Instance()->ms_sVFREEBUSY, strLine, 100); + } + if (getUIDProperty() != 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iDuplicatedProperty, + JulianKeyword::Instance()->ms_sVFREEBUSY, + JulianKeyword::Instance()->ms_sUID, 100); + } + setUID(propVal, parameters); +} +void VFreebusy::storeURL(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones) +{ + // no parameters + if (parameters->GetSize() > 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iInvalidOptionalParam, + JulianKeyword::Instance()->ms_sVFREEBUSY, strLine, 100); + } + if (getURLProperty() != 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iDuplicatedProperty, + JulianKeyword::Instance()->ms_sVFREEBUSY, + JulianKeyword::Instance()->ms_sURL, 100); + } + setURL(propVal, parameters); + //addURL(propVal, parameters); +} +//--------------------------------------------------------------------- +t_bool VFreebusy::isValid() +{ + DateTime dS, dE; + dS = getDTStart(); + dE = getDTEnd(); + + // TODO: handle bad method names + + if (getMethod().compareIgnoreCase(JulianKeyword::Instance()->ms_sPUBLISH) == 0) + { + // publish must have dtstamp + if (!getDTStamp().isValid()) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iMissingStartingTime, 300); + return FALSE; + } + + // MUST have organizer + if (getOrganizer().size() == 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iMissingOrganizer, 300); + return FALSE; + } + } + else if (getMethod().compareIgnoreCase(JulianKeyword::Instance()->ms_sREQUEST) == 0) + { + // publish must have dtstamp + if (!getDTStamp().isValid()) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iMissingDTStamp, 300); + return FALSE; + } + // TODO: must have requested attendee address + if (getAttendees() == 0 || getAttendees()->GetSize() == 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iMissingAttendees, 300); + return FALSE; + } + + // must have organizer + if (getOrganizer().size() == 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iMissingOrganizer, 300); + return FALSE; + } + + // must have start, end + if (!dS.isValid()) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iMissingStartingTime, 300); + return FALSE; + } + if (!dE.isValid()) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iMissingEndingTime, 300); + return FALSE; + } + if (dS.afterDateTime(dE)) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iEndBeforeStartTime, 300); + return FALSE; + } + } + else if (getMethod().compareIgnoreCase(JulianKeyword::Instance()->ms_sREPLY) == 0) + { + // both request and reply must have valid dtstamp and a UID + if (!getDTStamp().isValid()) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iMissingDTStamp, 300); + return FALSE; + } + + if (getUID().size() == 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iMissingUID, 300); + return FALSE; + } + + // TODO: must have recipient replying address + if (getAttendees() == 0 || getAttendees()->GetSize() == 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iMissingAttendees, 300); + return FALSE; + } + // must have originator' organizer address + if (getOrganizer().size() == 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iMissingOrganizer, 300); + return FALSE; + } + // must have start, end + if (!dS.isValid()) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iMissingStartingTime, 300); + return FALSE; + } + if (!dE.isValid()) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iMissingEndingTime, 300); + return FALSE; + } + if (dS.afterDateTime(dE)) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iEndBeforeStartTime, 300); + return FALSE; + } + } + + /* + // both request and reply must have valid dtstamp and a UID + if ((!getDTStamp().isValid()) || (getUID().size() == 0)) + return FALSE; + + // sequence must be >= 0 + if (getSequence() < 0) + return FALSE; + + // if a reply + if (dS.isValid() || dE.isValid()) + { + // ds and de must be valid and dS cannot be after dE + if (!dS.isValid() || !dE.isValid() || dS.afterDateTime(dE)) + return FALSE; + } + */ + + return TRUE; +} +//--------------------------------------------------------------------- +UnicodeString VFreebusy::toICALString() +{ + return formatHelper(JulianFormatString::Instance()->ms_sVFreebusyAllMessage, ""); +} +//--------------------------------------------------------------------- +UnicodeString VFreebusy::toICALString(UnicodeString sMethod, + UnicodeString sName, + t_bool isRecurring) +{ + // NOTE: Remove later, to avoid warnings + if (isRecurring) {} + + if (sMethod.compareIgnoreCase(JulianKeyword::Instance()->ms_sPUBLISH) == 0) + return formatHelper(JulianFormatString::Instance()->ms_sVFreebusyPublishMessage, ""); + else if (sMethod.compareIgnoreCase(JulianKeyword::Instance()->ms_sREQUEST) == 0) + return formatHelper(JulianFormatString::Instance()->ms_sVFreebusyRequestMessage, ""); + else if (sMethod.compareIgnoreCase(JulianKeyword::Instance()->ms_sREPLY) == 0) + return formatHelper(JulianFormatString::Instance()->ms_sVFreebusyReplyMessage, sName); + else + return toICALString(); +} +//--------------------------------------------------------------------- +UnicodeString VFreebusy::toString() +{ + return ICalComponent::toStringFmt( + JulianFormatString::Instance()->ms_VFreebusyStrDefaultFmt); +} +//--------------------------------------------------------------------- +UnicodeString VFreebusy::formatHelper(UnicodeString & strFmt, UnicodeString sFilterAttendee) +{ + UnicodeString u = JulianKeyword::Instance()->ms_sVFREEBUSY; + return ICalComponent::format(u, strFmt, sFilterAttendee); +} +//--------------------------------------------------------------------- +UnicodeString +VFreebusy::formatChar(t_int32 c, UnicodeString sFilterAttendee, + t_bool delegateRequest) +{ + UnicodeString sResult, s; + t_int32 i; + JulianPtrArray * v; + + // NOTE: remove later, kept in to remove compiler warning + if (delegateRequest) + { + } + + switch (c) + { + case ms_cAttendees: + { + v = getAttendees(); + if (v != 0) + { + if (sFilterAttendee.size() > 0) + { + Attendee * a = getAttendee(sFilterAttendee); + if (a != 0) + s = a->toICALString(s); + else + s = ""; + sResult += ICalProperty::multiLineFormat(s); + } + else + { + for (i=0; i< v->GetSize(); i++) + { + s = ((Attendee * ) v->GetAt(i))->toICALString(s); + sResult += ICalProperty::multiLineFormat(s); + } + } + } + return sResult; + } + case ms_cFreebusy: + s = JulianKeyword::Instance()->ms_sFREEBUSY; + return ICalProperty::propertyVectorToICALString(s, getFreebusy(), sResult); + case ms_cComment: + s = JulianKeyword::Instance()->ms_sCOMMENT; + return ICalProperty::propertyVectorToICALString(s, getComment(), sResult); + case ms_cContact: + s = JulianKeyword::Instance()->ms_sCONTACT; + return ICalProperty::propertyVectorToICALString(s, getContact(), sResult); + /* + case ms_cCreated: + s = JulianKeyword::Instance()->ms_sCREATED; + return ICalProperty::propertyToICALString(s, getCreatedProperty(), sResult); + */ + case ms_cDTEnd: + s = JulianKeyword::Instance()->ms_sDTEND; + return ICalProperty::propertyToICALString(s, getDTEndProperty(), sResult); + case ms_cDuration: + s = JulianKeyword::Instance()->ms_sDURATION; + s += ':'; + s += getDuration().toICALString(); + s += JulianKeyword::Instance()->ms_sLINEBREAK; + return s; + case ms_cDTStart: + s = JulianKeyword::Instance()->ms_sDTSTART; + return ICalProperty::propertyToICALString(s, getDTStartProperty(), sResult); + case ms_cDTStamp: + s = JulianKeyword::Instance()->ms_sDTSTAMP; + return ICalProperty::propertyToICALString(s, getDTStampProperty(), sResult); + //case ms_cRelatedTo: + // s = JulianKeyword::Instance()->ms_sRELATEDTO; + // return ICalProperty::propertyVectorToICALString(s, getRelatedTo(), sResult); + case ms_cOrganizer: + s = JulianKeyword::Instance()->ms_sORGANIZER; + return ICalProperty::propertyToICALString(s, getOrganizerProperty(), sResult); + case ms_cRequestStatus: + s = JulianKeyword::Instance()->ms_sREQUESTSTATUS; + //return ICalProperty::propertyToICALString(s, getRequestStatusProperty(), sResult); + return ICalProperty::propertyVectorToICALString(s, getRequestStatus(), sResult); + case ms_cSequence: + s = JulianKeyword::Instance()->ms_sSEQUENCE; + return ICalProperty::propertyToICALString(s, getSequenceProperty(), sResult); + case ms_cUID: + s = JulianKeyword::Instance()->ms_sUID; + return ICalProperty::propertyToICALString(s, getUIDProperty(), sResult); + case ms_cURL: + s = JulianKeyword::Instance()->ms_sURL; + //return ICalProperty::propertyVectorToICALString(s, getURL(), sResult); + return ICalProperty::propertyToICALString(s, getURLProperty(), sResult); + case ms_cXTokens: + return ICalProperty::vectorToICALString(getXTokens(), sResult); + default: + { + //DebugMsg.Instance().println(0,"No such member in VFreebusy"); + //sResult = ParserUtil.multiLineFormat(sResult); + return ""; + } + } +} +//--------------------------------------------------------------------- +UnicodeString VFreebusy::toStringChar(t_int32 c, UnicodeString & dateFmt) +{ + + UnicodeString sResult; + + switch(c) + { + case ms_cAttendees: + return ICalProperty::propertyVectorToString(getAttendees(), dateFmt, sResult); + /* + case ms_cCreated: + return ICalProperty::propertyToString(getCreatedProperty(), dateFmt, sResult); + */ + case ms_cContact: + return ICalProperty::propertyVectorToString(getContact(), dateFmt, sResult); + case ms_cDuration: + return getDuration().toString(); + //return ICalProperty::propertyToString(getDurationProperty(), dateFmt, sResult); + case ms_cDTEnd: + return ICalProperty::propertyToString(getDTEndProperty(), dateFmt, sResult); + case ms_cDTStart: + return ICalProperty::propertyToString(getDTStartProperty(), dateFmt, sResult); + case ms_cDTStamp: + return ICalProperty::propertyToString(getDTStampProperty(), dateFmt, sResult); + case ms_cLastModified: + return ICalProperty::propertyToString(getLastModifiedProperty(), dateFmt, sResult); + case ms_cOrganizer: + return ICalProperty::propertyToString(getOrganizerProperty(), dateFmt, sResult); + case ms_cRequestStatus: + //return ICalProperty::propertyToString(getRequestStatusProperty(), dateFmt, sResult); + return ICalProperty::propertyVectorToString(getRequestStatus(), dateFmt, sResult); + case ms_cSequence: + return ICalProperty::propertyToString(getSequenceProperty(), dateFmt, sResult); + case ms_cUID: + return ICalProperty::propertyToString(getUIDProperty(), dateFmt, sResult); + case ms_cURL: + return ICalProperty::propertyToString(getURLProperty(), dateFmt, sResult); + case ms_cFreebusy: + return ICalProperty::propertyVectorToString(getFreebusy(), dateFmt, sResult); + default: + { + return ""; + } + } +} +//--------------------------------------------------------------------- +t_bool VFreebusy::MatchUID_seqNO(UnicodeString sUID, t_int32 iSeqNo) +{ + //t_int32 seq = getSequence(); + //UnicodeString uid = getUID(); + + if (getSequence() == iSeqNo && getUID().compareIgnoreCase(sUID) == 0) + return TRUE; + else + return FALSE; +} + +//--------------------------------------------------------------------- +#if 0 +void +VFreebusy::setAttendeeStatus(UnicodeString & sAttendeeFilter, + Attendee::STATUS status, + JulianPtrArray * delegatedTo) +{ + Attendee * a; + a = getAttendee(sAttendeeFilter); + if (a == 0) + { + // add a new attendee to this event (a partycrasher) + a = Attendee::getDefault(GetType()); + PR_ASSERT(a != 0); + if (a != 0) + { + a->setName(sAttendeeFilter); + addAttendee(a); + } + } + PR_ASSERT(a != 0); + if (a != 0) + { + a->setStatus(status); + if (status == Attendee::STATUS_DELEGATED) + { + if (delegatedTo != 0) + { + t_int32 i; + UnicodeString u; + // for each new attendee, set name, role = req_part, delfrom = me, + // rsvp = TRUE, expect = request, status = needs-action. + for (i = 0; i < delegatedTo->GetSize(); i++) + { + u = *((UnicodeString *) delegatedTo->GetAt(i)); + a->addDelegatedTo(u); + + Attendee * delegate = Attendee::getDefault(GetType(), m_Log); + PR_ASSERT(delegate != 0); + if (delegate != 0) + { + delegate->setName(u); + delegate->setRole(Attendee::ROLE_REQ_PARTICIPANT); + delegate->addDelegatedFrom(sAttendeeFilter); + delegate->setRSVP(Attendee::RSVP_TRUE); + delegate->setExpect(Attendee::EXPECT_REQUEST); + delegate->setStatus(Attendee::STATUS_NEEDSACTION); + addAttendee(delegate); + } + } + } + } + } +} +#endif +//--------------------------------------------------------------------- + +Attendee * +VFreebusy::getAttendee(UnicodeString sAttendee) +{ + return Attendee::getAttendee(getAttendees(), sAttendee); +} + +//--------------------------------------------------------------------- + +int +VFreebusy::CompareVFreebusyByUID(const void * a, + const void * b) +{ + PR_ASSERT(a != 0 && b != 0); + VFreebusy * ta = *(VFreebusy **) a; + VFreebusy * tb = *(VFreebusy **) b; + + return (int) ta->getUID().compare(tb->getUID()); +} + +//--------------------------------------------------------------------- + +int +VFreebusy::CompareVFreebusyByDTStart(const void * a, + const void * b) +{ + PR_ASSERT(a != 0 && b != 0); + VFreebusy * ta = *(VFreebusy **) a; + VFreebusy * tb = *(VFreebusy **) b; + + DateTime da, db; + da = ta->getDTStart(); + db = tb->getDTStart(); + + return (int) (da.compareTo(db)); +} + +//--------------------------------------------------------------------- + +void VFreebusy::removeAllFreebusy() +{ + if (m_FreebusyVctr != 0) + { + ICalProperty::deleteICalPropertyVector(m_FreebusyVctr); + delete m_FreebusyVctr; m_FreebusyVctr = 0; + } +} +//--------------------------------------------------------------------- +#if 0 +t_bool +VFreebusy::isMoreRecent(VFreebusy * component) +{ + // component is not NULL + PR_ASSERT(component != 0); + + if (component != 0) + { + t_bool bHasSeq; + t_bool bHasDTStamp; + + t_int32 iSeq, jSeq; + DateTime idts, jdts; + + iSeq = getSequence(); + idts = getDTStamp(); + + jSeq = component->getSequence(); + jdts = component->getDTStamp(); + + // both components must have sequence and DTSTAMP + bHasSeq = (iSeq >= 0 && jSeq >= 0); + bHasDTStamp = (idts.isValid() && jdts.isValid()); + + PR_ASSERT(bHasSeq); + PR_ASSERT(bHasDTStamp); + + // if iSeq > jSeq return TRUE + // else if iSeq < jSeq return FALSE + // else if iSeq == jSeq + // { + // else if jdts is after idts return FALSE + // else if jdts is before idts return TRUE + // else (dts is equal to idts) return TRUE + // } + + if (component != 0 && bHasSeq && bHasDTStamp) + { + if (iSeq > jSeq) + { + return TRUE; + } + else if (iSeq < jSeq) + { + return FALSE; + } + else + { + return !(jdts.afterDateTime(idts)); + } + } + } + // assert failed + return FALSE; +} +#endif +//--------------------------------------------------------------------- + +void +VFreebusy::updateComponentHelper(VFreebusy * updatedComponent) +{ + // no created, last-modified, UID + DateTime d; + ICalComponent::internalSetPropertyVctr(&m_AttendeesVctr, updatedComponent->getAttendees()); + ICalComponent::internalSetPropertyVctr(&m_CommentVctr, updatedComponent->getComment()); + ICalComponent::internalSetPropertyVctr(&m_ContactVctr, updatedComponent->getContact()); + ICalComponent::internalSetPropertyVctr(&m_FreebusyVctr, updatedComponent->getFreebusy()); + //ICalComponent::internalSetPropertyVctr(&m_RelatedToVctr, updatedComponent->getRelatedTo()); + //ICalComponent::internalSetPropertyVctr(&m_URLVctr, updatedComponent->getURL()); + ICalComponent::internalSetProperty(&m_DTStart, updatedComponent->m_DTStart); + ICalComponent::internalSetProperty(&m_DTEnd, updatedComponent->m_DTEnd); + ICalComponent::internalSetProperty(&m_DTStamp, updatedComponent->m_DTStamp); + ICalComponent::internalSetProperty(&m_Organizer, updatedComponent->m_Organizer); + //ICalComponent::internalSetPropertyVctr(&m_RequestStatusVctr, updatedComponent->getRequestStatus()); + ICalComponent::internalSetProperty(&m_Sequence, updatedComponent->m_Sequence); + ICalComponent::internalSetProperty(&m_URL, updatedComponent->m_URL); + ICalComponent::internalSetXTokensVctr(&m_XTokensVctr, updatedComponent->m_XTokensVctr); + + ICalComponent::internalSetProperty(&m_LastModified, updatedComponent->m_LastModified); + //setLastModified(d); +} + +//--------------------------------------------------------------------- + +t_bool +VFreebusy::updateComponent(ICalComponent * updatedComponent) +{ + if (updatedComponent != 0) + { + ICAL_COMPONENT ucType = updatedComponent->GetType(); + + // only call updateComponentHelper if it's a VFreebusy and + // it is an exact matching UID and updatedComponent + // is more recent than this component + if (ucType == ICAL_COMPONENT_VFREEBUSY) + { + // should be a safe cast with check above. + VFreebusy * ucvf = (VFreebusy *) updatedComponent; + + // only if uid's match and are not empty + if (ucvf->getUID().size() > 0 && getUID().size() > 0) + { + //if (ucvf->getUID() == getUID() && !isMoreRecent(ucvf)) + if (ucvf->getUID() == getUID()) + { + updateComponentHelper(ucvf); + return TRUE; + } + } + } + } + return FALSE; +} +//--------------------------------------------------------------------- +// GETTERS AND SETTERS here +//--------------------------------------------------------------------- +// attendee +void VFreebusy::addAttendee(Attendee * a) +{ + if (m_AttendeesVctr == 0) + m_AttendeesVctr = new JulianPtrArray(); + PR_ASSERT(m_AttendeesVctr != 0); + if (m_AttendeesVctr != 0) + { + m_AttendeesVctr->Add(a); + } +} +//--------------------------------------------------------------------- +// freebusy +void VFreebusy::addFreebusy(Freebusy * f) +{ + if (m_FreebusyVctr == 0) + m_FreebusyVctr = new JulianPtrArray(); + PR_ASSERT(m_FreebusyVctr != 0); + if (m_FreebusyVctr != 0) + { + m_FreebusyVctr->Add(f); + } +} +//--------------------------------------------------------------------- +///DTEnd +void VFreebusy::setDTEnd(DateTime s, JulianPtrArray * parameters) +{ +#if 1 + if (m_DTEnd == 0) + m_DTEnd = ICalPropertyFactory::Make(ICalProperty::DATETIME, + (void *) &s, parameters); + else + { + m_DTEnd->setValue((void *) &s); + m_DTEnd->setParameters(parameters); + } +#else + ICalComponent::setDateTimeValue(((ICalProperty **) &m_DTEnd), s, parameters); +#endif +} +DateTime VFreebusy::getDTEnd() const +{ +#if 1 + DateTime d(-1); + if (m_DTEnd == 0) + return d; //return 0; + else + { + d = *((DateTime *) m_DTEnd->getValue()); + return d; + } +#else + DateTime d(-1); + ICalComponent::getDateTimeValue(((ICalProperty **) &m_DTEnd), d); + return d; +#endif +} +//--------------------------------------------------------------------- +///Julian_Duration +void VFreebusy::setDuration(Julian_Duration s, JulianPtrArray * parameters) +{ + /* + if (m_Duration == 0) + m_Duration = ICalPropertyFactory::Make(ICalProperty::DURATION, + (void *) &s, parameters); + else + { + m_Duration->setValue((void *) &s); + m_Duration->setParameters(parameters); + } + */ + // NOTE: remove later, to avoid compiler warnings + if (parameters) + { + } + + + DateTime end; + end = getDTStart(); + end.add(s); + setDTEnd(end); +} +Julian_Duration VFreebusy::getDuration() const +{ + /* + Julian_Duration d; d.set(-1,-1,-1,-1,-1,-1); + if (m_Duration == 0) + return d; // return 0; + else + { + d = *((Julian_Duration *) m_Duration->getValue()); + return d; + } + */ + Julian_Duration duration; + DateTime start, end; + start = getDTStart(); + end = getDTEnd(); + DateTime::getDuration(start,end,duration); + return duration; +} +//--------------------------------------------------------------------- +//LAST-MODIFIED +void VFreebusy::setLastModified(DateTime s, JulianPtrArray * parameters) +{ +#if 1 + if (m_LastModified == 0) + m_LastModified = ICalPropertyFactory::Make(ICalProperty::DATETIME, + (void *) &s, parameters); + else + { + m_LastModified->setValue((void *) &s); + m_LastModified->setParameters(parameters); + } +#else + ICalComponent::setDateTimeValue(((ICalProperty **) &m_LastModified), s, parameters); +#endif +} + +DateTime VFreebusy::getLastModified() const +{ +#if 1 + DateTime d(-1); + if (m_LastModified == 0) + return d; // return 0; + else + { + d = *((DateTime *) m_LastModified->getValue()); + return d; + } +#else + DateTime d(-1); + ICalComponent::getDateTimeValue(((ICalProperty **) &m_LastModified), d); + return d; +#endif +} +//--------------------------------------------------------------------- +#if 0 +//Created +void VFreebusy::setCreated(DateTime s, JulianPtrArray * parameters) +{ +#if 1 + if (m_Created == 0) + m_Created = ICalPropertyFactory::Make(ICalProperty::DATETIME, + (void *) &s, parameters); + else + { + m_Created->setValue((void *) &s); + m_Created->setParameters(parameters); + } +#else + ICalComponent::setDateTimeValue(((ICalProperty **) &m_Created), s, parameters); +#endif +} +DateTime VFreebusy::getCreated() const +{ +#if 1 + DateTime d(-1); + if (m_Created == 0) + return d;//return 0; + else + { + d = *((DateTime *) m_Created->getValue()); + return d; + } +#else + DateTime d(-1); + ICalComponent::getDateTimeValue(((ICalProperty **) &m_Created), d); + return d; +#endif +} +#endif +//--------------------------------------------------------------------- +//DTStamp +void VFreebusy::setDTStamp(DateTime s, JulianPtrArray * parameters) +{ +#if 1 + if (m_DTStamp == 0) + m_DTStamp = ICalPropertyFactory::Make(ICalProperty::DATETIME, + (void *) &s, parameters); + else + { + m_DTStamp->setValue((void *) &s); + m_DTStamp->setParameters(parameters); + } +#else + ICalComponent::setDateTimeValue(((ICalProperty **) &m_DTStamp), s, parameters); +#endif +} +DateTime VFreebusy::getDTStamp() const +{ +#if 1 + DateTime d(-1); + if (m_DTStamp == 0) + return d;//return 0; + else + { + d = *((DateTime *) m_DTStamp->getValue()); + return d; + } +#else + DateTime d(-1); + ICalComponent::getDateTimeValue(((ICalProperty **) &m_DTStamp), d); + return d; +#endif +} +//--------------------------------------------------------------------- +///DTStart +void VFreebusy::setDTStart(DateTime s, JulianPtrArray * parameters) +{ +#if 1 + if (m_DTStart == 0) + m_DTStart = ICalPropertyFactory::Make(ICalProperty::DATETIME, + (void *) &s, parameters); + else + { + m_DTStart->setValue((void *) &s); + m_DTStart->setParameters(parameters); + } +#else + ICalComponent::setDateTimeValue(((ICalProperty **) &m_DTStart), s, parameters); +#endif +} + +DateTime VFreebusy::getDTStart() const +{ +#if 1 + DateTime d(-1); + if (m_DTStart == 0) + return d; //return 0; + else + { + d = *((DateTime *) m_DTStart->getValue()); + return d; + } +#else + DateTime d(-1); + ICalComponent::getDateTimeValue(((ICalProperty **) &m_DTStart), d); + return d; +#endif +} +//--------------------------------------------------------------------- +//Organizer +void VFreebusy::setOrganizer(UnicodeString s, JulianPtrArray * parameters) +{ + //UnicodeString * s_ptr = new UnicodeString(s); + //PR_ASSERT(s_ptr != 0); + + if (m_Organizer == 0) + { + //m_Organizer = ICalPropertyFactory::Make(ICalProperty::TEXT, + // (void *) &s, parameters); + + m_Organizer = (ICalProperty *) new JulianOrganizer(m_Log); + PR_ASSERT(m_Organizer != 0); + m_Organizer->setValue((void *) &s); + m_Organizer->setParameters(parameters); + } + else + { + m_Organizer->setValue((void *) &s); + m_Organizer->setParameters(parameters); + } +} +UnicodeString VFreebusy::getOrganizer() const +{ + UnicodeString u; + if (m_Organizer == 0) + return ""; + else { + u = *((UnicodeString *) m_Organizer->getValue()); + return u; + } +} +//--------------------------------------------------------------------- +//RequestStatus +#if 0 +void VFreebusy::setRequestStatus(UnicodeString s, JulianPtrArray * parameters) +{ + //UnicodeString * s_ptr = new UnicodeString(s); + //PR_ASSERT(s_ptr != 0); + + if (m_RequestStatus == 0) + m_RequestStatus = ICalPropertyFactory::Make(ICalProperty::TEXT, + (void *) &s, parameters); + else + { + m_RequestStatus->setValue((void *) &s); + m_RequestStatus->setParameters(parameters); + } +} +UnicodeString VFreebusy::getRequestStatus() const +{ + UnicodeString u; + if (m_RequestStatus == 0) + return ""; + else + { + u = *((UnicodeString *) m_RequestStatus->getValue()); + return u; + } +} +#endif +void VFreebusy::addRequestStatus(UnicodeString s, JulianPtrArray * parameters) +{ + ICalProperty * prop = ICalPropertyFactory::Make(ICalProperty::TEXT, + (void *) &s, parameters); + addRequestStatusProperty(prop); +} +void VFreebusy::addRequestStatusProperty(ICalProperty * prop) +{ + if (m_RequestStatusVctr == 0) + m_RequestStatusVctr = new JulianPtrArray(); + PR_ASSERT(m_RequestStatusVctr != 0); + m_RequestStatusVctr->Add(prop); +} +//--------------------------------------------------------------------- +//UID +void VFreebusy::setUID(UnicodeString s, JulianPtrArray * parameters) +{ +#if 1 + //UnicodeString * s_ptr = new UnicodeString(s); + //PR_ASSERT(s_ptr != 0); + + if (m_UID == 0) + m_UID = ICalPropertyFactory::Make(ICalProperty::TEXT, + (void *) &s, parameters); + else + { + m_UID->setValue((void *) &s); + m_UID->setParameters(parameters); + } +#else + ICalComponent::setStringValue(((ICalProperty **) &m_UID), s, parameters); +#endif +} +UnicodeString VFreebusy::getUID() const +{ +#if 1 + UnicodeString u; + if (m_UID == 0) + return ""; + else { + u = *((UnicodeString *) m_UID->getValue()); + return u; + } +#else + UnicodeString us; + ICalComponent::getStringValue(((ICalProperty **) &m_UID), us); + return us; +#endif +} +//--------------------------------------------------------------------- +//Sequence +void VFreebusy::setSequence(t_int32 i, JulianPtrArray * parameters) +{ +#if 1 + if (m_Sequence == 0) + m_Sequence = ICalPropertyFactory::Make(ICalProperty::INTEGER, + (void *) &i, parameters); + else + { + m_Sequence->setValue((void *) &i); + m_Sequence->setParameters(parameters); + } +#else + ICalComponent::setIntegerValue(((ICalProperty **) &m_Sequence), i, parameters); +#endif +} +t_int32 VFreebusy::getSequence() const +{ +#if 1 + t_int32 i; + if (m_Sequence == 0) + return -1; + else + { + i = *((t_int32 *) m_Sequence->getValue()); + return i; + } +#else + t_int32 i = -1; + ICalComponent::getIntegerValue(((ICalProperty **) &m_Sequence), i); + return i; +#endif +} +//--------------------------------------------------------------------- +//comment +void VFreebusy::addComment(UnicodeString s, JulianPtrArray * parameters) +{ + ICalProperty * prop = ICalPropertyFactory::Make(ICalProperty::TEXT, + (void *) &s, parameters); + addCommentProperty(prop); +} +void VFreebusy::addCommentProperty(ICalProperty * prop) +{ + if (m_CommentVctr == 0) + m_CommentVctr = new JulianPtrArray(); + PR_ASSERT(m_CommentVctr != 0); + if (m_CommentVctr != 0) + { + m_CommentVctr->Add(prop); + } +} +//--------------------------------------------------------------------- +// Contact +void VFreebusy::addContact(UnicodeString s, JulianPtrArray * parameters) +{ + ICalProperty * prop = ICalPropertyFactory::Make(ICalProperty::TEXT, + (void *)&s, parameters); + addContactProperty(prop); +} +void VFreebusy::addContactProperty(ICalProperty * prop) +{ + if (m_ContactVctr == 0) + m_ContactVctr = new JulianPtrArray(); + PR_ASSERT(m_ContactVctr != 0); + if (m_ContactVctr != 0) + { + m_ContactVctr->Add(prop); + } +} +//--------------------------------------------------------------------- +// RelatedTo +//void VFreebusy::addRelatedTo(UnicodeString s, JulianPtrArray * parameters) +//{ +// ICalProperty * prop = ICalPropertyFactory::Make(ICalProperty::TEXT, +// (void *) &s, parameters); +// addRelatedToProperty(prop); +//} +//void VFreebusy::addRelatedToProperty(ICalProperty * prop) +//{ +// if (m_RelatedToVctr == 0) +// m_RelatedToVctr = new JulianPtrArray(); +// PR_ASSERT(m_RelatedToVctr != 0); +// m_RelatedToVctr->Add(prop); +//} +//--------------------------------------------------------------------- +// URL +//void VFreebusy::addURL(UnicodeString s, JulianPtrArray * parameters) +//{ +// ICalProperty * prop = ICalPropertyFactory::Make(ICalProperty::TEXT, +// (void *) &s, parameters); +// addURLProperty(prop); +//} +//void VFreebusy::addURLProperty(ICalProperty * prop) +//{ +// if (m_URLVctr == 0) +// m_URLVctr = new JulianPtrArray(); +// PR_ASSERT(m_URLVctr != 0); +// m_URLVctr->Add(prop); +//} +void VFreebusy::setURL(UnicodeString s, JulianPtrArray * parameters) +{ +#if 1 + //UnicodeString * s_ptr = new UnicodeString(s); + //PR_ASSERT(s_ptr != 0); + + if (m_URL == 0) + m_URL = ICalPropertyFactory::Make(ICalProperty::TEXT, + (void *) &s, parameters); + else + { + m_URL->setValue((void *) &s); + m_URL->setParameters(parameters); + } +#else + ICalComponent::setStringValue(((ICalProperty **) &m_URL), s, parameters); +#endif +} +UnicodeString VFreebusy::getURL() const +{ +#if 1 + UnicodeString u; + if (m_URL == 0) + return ""; + else { + u = *((UnicodeString *) m_URL->getValue()); + return u; + } +#else + UnicodeString us; + ICalComponent::getStringValue(((ICalProperty **) &m_URL), us); + return us; +#endif +} +//--------------------------------------------------------------------- +// XTOKENS +void VFreebusy::addXTokens(UnicodeString s) +{ + if (m_XTokensVctr == 0) + m_XTokensVctr = new JulianPtrArray(); + PR_ASSERT(m_XTokensVctr != 0); + if (m_XTokensVctr != 0) + { + m_XTokensVctr->Add(new UnicodeString(s)); + } +} +//--------------------------------------------------------------------- + diff --git a/calendar/modules/core/ical/src/vjournal.cpp b/calendar/modules/core/ical/src/vjournal.cpp new file mode 100644 index 00000000000..e1fc434deb8 --- /dev/null +++ b/calendar/modules/core/ical/src/vjournal.cpp @@ -0,0 +1,426 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +/* + * vjournal.cpp + * John Sun + * 4/23/98 10:33:36 AM + */ + +#include "stdafx.h" +#include "jdefines.h" + +#include "jutility.h" +#include "vjournal.h" +#include "icalredr.h" +#include "prprtyfy.h" +#include "unistrto.h" +#include "jlog.h" +#include "vtimezne.h" +#include "keyword.h" +#include "period.h" +#include "datetime.h" + +//--------------------------------------------------------------------- +void VJournal::setDefaultFmt(UnicodeString s) +{ + JulianFormatString::Instance()->ms_VJournalStrDefaultFmt = s; +} +//--------------------------------------------------------------------- +#if 0 +VJournal::VJournal() +{ + PR_ASSERT(FALSE); +} +#endif +//--------------------------------------------------------------------- + +VJournal::VJournal(JLog * initLog) +: TimeBasedEvent(initLog) +{ +} + +//--------------------------------------------------------------------- + +VJournal::VJournal(VJournal & that) +: TimeBasedEvent(that) +{ +} + +//--------------------------------------------------------------------- + +ICalComponent * +VJournal::clone(JLog * initLog) +{ + m_Log = initLog; + return new VJournal(*this); +} + +//--------------------------------------------------------------------- + +VJournal::~VJournal() +{ + // should call TimeBasedEvent destructor +} + +//--------------------------------------------------------------------- + +UnicodeString & +VJournal::parse(ICalReader * brFile, UnicodeString & sMethod, + UnicodeString & parseStatus, JulianPtrArray * vTimeZones, + t_bool bIgnoreBeginError, JulianUtility::MimeEncoding encoding) +{ + UnicodeString u = JulianKeyword::Instance()->ms_sVJOURNAL; + return parseType(u, brFile, sMethod, parseStatus, vTimeZones, bIgnoreBeginError, encoding); +} + +//--------------------------------------------------------------------- + +Date VJournal::difference() +{ + return 0; +} + +//--------------------------------------------------------------------- + +void VJournal::selfCheck() +{ + TimeBasedEvent::selfCheck(); + if (getStatus().size() > 0) + { + // check if I got a valid status + UnicodeString u = getStatus(); + u.toUpper(); + ICalProperty::Trim(u); + JAtom ua(u); + if ((JulianKeyword::Instance()->ms_ATOM_DRAFT!= ua) && + (JulianKeyword::Instance()->ms_ATOM_FINAL != ua) && + (JulianKeyword::Instance()->ms_ATOM_CANCELLED != ua)) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iInvalidPropertyValue, + JulianKeyword::Instance()->ms_sVJOURNAL, + JulianKeyword::Instance()->ms_sSTATUS, u, 200); + + setStatus(""); + } + } +} + +//--------------------------------------------------------------------- + +t_bool +VJournal::storeData(UnicodeString & strLine, UnicodeString & propName, + UnicodeString & propVal, JulianPtrArray * parameters, + JulianPtrArray * vTimeZones) +{ + if (TimeBasedEvent::storeData(strLine, propName, propVal, + parameters, vTimeZones)) + return TRUE; + else + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iInvalidPropertyName, + JulianKeyword::Instance()->ms_sVJOURNAL, propName, 200); + UnicodeString u; + u = JulianLogErrorMessage::Instance()->ms_sRS202; + u += '.'; u += ' '; + u += strLine; + //setRequestStatus(JulianLogErrorMessage::Instance()->ms_iRS202); + addRequestStatus(u); + return FALSE; + } +} + +//--------------------------------------------------------------------- + +void VJournal::populateDatesHelper(DateTime start, Date ldiff, + JulianPtrArray * vPeriods) +{ +} + +//--------------------------------------------------------------------- + +UnicodeString VJournal::formatHelper(UnicodeString & strFmt, + UnicodeString sFilterAttendee, + t_bool delegateRequest) +{ + UnicodeString u = JulianKeyword::Instance()->ms_sVJOURNAL; + return ICalComponent::format(u, strFmt, sFilterAttendee, delegateRequest); +} + +//--------------------------------------------------------------------- + +UnicodeString VJournal::toString() +{ + return ICalComponent::toStringFmt( + JulianFormatString::Instance()->ms_VJournalStrDefaultFmt); +} + +//--------------------------------------------------------------------- + +UnicodeString VJournal::toStringChar(t_int32 c, UnicodeString & dateFmt) +{ + return TimeBasedEvent::toStringChar(c, dateFmt); +} + +//--------------------------------------------------------------------- + +UnicodeString VJournal::formatChar(t_int32 c, UnicodeString sFilterAttendee, + t_bool delegateRequest) +{ + return TimeBasedEvent::formatChar(c, sFilterAttendee, delegateRequest); +} + +//--------------------------------------------------------------------- + +t_bool VJournal::isValid() +{ + // TODO: finish + if ((getMethod().compareIgnoreCase(JulianKeyword::Instance()->ms_sPUBLISH) == 0) || + (getMethod().compareIgnoreCase(JulianKeyword::Instance()->ms_sREQUEST) == 0) || + (getMethod().compareIgnoreCase(JulianKeyword::Instance()->ms_sADD) == 0)) + { + // must have dtstart + if ((!getDTStart().isValid())) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iMissingStartingTime, 300); + return FALSE; + } + + // If due exists, make sure it is not before dtstart + //if (getDTEnd().isValid() && getDTEnd() < getDTStart()) + // return FALSE; + + // must have dtstamp, summary, uid + if (!getDTStamp().isValid()) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iMissingDTStamp, 300); + return FALSE; + } + if (getSummary().size() == 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iMissingSummary, 300); + return FALSE; + } + if (getUID().size() == 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iMissingUID, 300); + return FALSE; + } + // must have organizer + if (getOrganizer().size() == 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iMissingOrganizer, 300); + return FALSE; + } + // must have sequence >= 0 + if (getSequence() < 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iMissingSeqNo, 300); + return FALSE; + } + if (getMethod().compareIgnoreCase(JulianKeyword::Instance()->ms_sREQUEST) == 0) + { + if (getAttendees() == 0 || getAttendees()->GetSize() == 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iMissingAttendees, 300); + return FALSE; + } + } + } + else if ((getMethod().compareIgnoreCase(JulianKeyword::Instance()->ms_sREPLY) == 0) || + (getMethod().compareIgnoreCase(JulianKeyword::Instance()->ms_sCANCEL) == 0) || + (getMethod().compareIgnoreCase(JulianKeyword::Instance()->ms_sDECLINECOUNTER) == 0)) + { + // must have dtstamp, uid + if (!getDTStamp().isValid()) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iMissingDTStamp, 300); + return FALSE; + } + if (getUID().size() == 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iMissingUID, 300); + return FALSE; + } + // must have organizer + if (getOrganizer().size() == 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iMissingOrganizer, 300); + return FALSE; + } + // must have sequence >= 0 + if (getSequence() < 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iMissingSeqNo, 300); + return FALSE; + } + if (getMethod().compareIgnoreCase(JulianKeyword::Instance()->ms_sREPLY) == 0) + { + if (getAttendees() == 0 || getAttendees()->GetSize() == 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iMissingAttendees, 300); + return FALSE; + } + } + } + else if ((getMethod().compareIgnoreCase(JulianKeyword::Instance()->ms_sREFRESH) == 0)) + { + // must have dtstamp, uid + if (!getDTStamp().isValid()) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iMissingDTStamp, 300); + return FALSE; + } + if (getUID().size() == 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iMissingDTStamp, 300); + return FALSE; + } + // TODO: attendees required? + } + else if ((getMethod().compareIgnoreCase(JulianKeyword::Instance()->ms_sCOUNTER) == 0)) + { + // must have dtstamp, uid + if (!getDTStamp().isValid()) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iMissingDTStamp, 300); + return FALSE; + } + if (getUID().size() == 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iMissingDTStamp, 300); + return FALSE; + } + + // must have sequence >= 0 + if (getSequence() < 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iMissingSeqNo, 300); + return FALSE; + } + } + + // check super class isValid method + return TimeBasedEvent::isValid(); +} + +//--------------------------------------------------------------------- + +UnicodeString VJournal::cancelMessage() +{ + UnicodeString s = JulianKeyword::Instance()->ms_sCANCELLED; + setStatus(s); + return formatHelper(JulianFormatString::Instance()->ms_sVJournalCancelMessage, ""); +} + +//--------------------------------------------------------------------- + +UnicodeString VJournal::requestMessage() +{ + return formatHelper(JulianFormatString::Instance()->ms_sVJournalRequestMessage, ""); +} + +//--------------------------------------------------------------------- + +UnicodeString VJournal::requestRecurMessage() +{ + return formatHelper(JulianFormatString::Instance()->ms_sVJournalRecurRequestMessage, ""); +} + +//--------------------------------------------------------------------- + +UnicodeString VJournal::counterMessage() +{ + return formatHelper(JulianFormatString::Instance()->ms_sVJournalCounterMessage, ""); +} + +//--------------------------------------------------------------------- + +UnicodeString VJournal::declineCounterMessage() +{ + return formatHelper(JulianFormatString::Instance()->ms_sVJournalDeclineCounterMessage, ""); +} + +//--------------------------------------------------------------------- + +UnicodeString VJournal::addMessage() +{ + return formatHelper(JulianFormatString::Instance()->ms_sVJournalAddMessage, ""); +} + +//--------------------------------------------------------------------- + +UnicodeString VJournal::refreshMessage(UnicodeString sAttendeeFilter) +{ + return formatHelper(JulianFormatString::Instance()->ms_sVJournalRefreshMessage, sAttendeeFilter); +} + +//--------------------------------------------------------------------- + +UnicodeString VJournal::allMessage() +{ + return formatHelper(JulianFormatString::Instance()->ms_sVJournalAllPropertiesMessage, ""); +} + +//--------------------------------------------------------------------- + +UnicodeString VJournal::replyMessage(UnicodeString sAttendeeFilter) +{ + return formatHelper(JulianFormatString::Instance()->ms_sVJournalReplyMessage, sAttendeeFilter); +} + +//--------------------------------------------------------------------- + +UnicodeString VJournal::publishMessage() +{ + return formatHelper(JulianFormatString::Instance()->ms_sVJournalPublishMessage, ""); +} + +//--------------------------------------------------------------------- + +UnicodeString VJournal::publishRecurMessage() +{ + return formatHelper(JulianFormatString::Instance()->ms_sVJournalRecurPublishMessage, ""); +} + +//--------------------------------------------------------------------- + +void +VJournal::updateComponentHelper(TimeBasedEvent * updatedComponent) +{ + TimeBasedEvent::updateComponentHelper(updatedComponent); +} diff --git a/calendar/modules/core/ical/src/vtimezne.cpp b/calendar/modules/core/ical/src/vtimezne.cpp new file mode 100644 index 00000000000..a00f92e309f --- /dev/null +++ b/calendar/modules/core/ical/src/vtimezne.cpp @@ -0,0 +1,811 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +// vtimezne.cpp +// John Sun +// 2:40 PM February 24 1998 + +#include "stdafx.h" +#include "jdefines.h" + +#include "icalcomp.h" +#include "prprtyfy.h" +#include "vtimezne.h" +#include "jlog.h" +#include "jutility.h" +#include "keyword.h" +#include + +t_bool VTimeZone::ms_bMORE_THAN_TWO_TZPARTS = FALSE; +//--------------------------------------------------------------------- + +// private never use. +#if 0 +VTimeZone::VTimeZone() +{ + PR_ASSERT(FALSE); +} +#endif + +//--------------------------------------------------------------------- + +VTimeZone::VTimeZone(JLog * initLog) +: m_TZID(0), m_LastModified(0), m_TZURL(0), + m_XTokensVctr(0), + m_TZPartVctr(0), m_NLSTimeZone(0), + m_Log(initLog) +{ + //PR_ASSERT(initLog != 0); +} +//--------------------------------------------------------------------- +VTimeZone::VTimeZone(VTimeZone & that) +: m_TZID(0), m_LastModified(0), m_TZURL(0), + m_XTokensVctr(0), + m_TZPartVctr(0), m_NLSTimeZone(0) +{ + if (that.m_NLSTimeZone != 0) + { + // note: todo: this should be an OK cast, + // but technically it's a bad thing to do. + m_NLSTimeZone = (SimpleTimeZone *) (that.m_NLSTimeZone)->clone(); + } + + if (that.m_TZID != 0) + { + m_TZID = that.m_TZID->clone(m_Log); + } + if (that.m_LastModified != 0) + { + m_LastModified = that.m_LastModified->clone(m_Log); + } + if (that.m_TZURL != 0) + { + m_TZURL = that.m_TZURL->clone(m_Log); + } + if (that.m_XTokensVctr != 0) + { + m_XTokensVctr = new JulianPtrArray(); PR_ASSERT(m_XTokensVctr != 0); + if (m_XTokensVctr != 0) + { + ICalProperty::CloneUnicodeStringVector(that.m_XTokensVctr, m_XTokensVctr); + } + } + if (that.m_TZPartVctr != 0) + { + t_int32 i; + ICalComponent * tzclone; + ICalComponent * ip; + m_TZPartVctr = new JulianPtrArray(); PR_ASSERT(m_TZPartVctr != 0); + if (m_TZPartVctr != 0) + { + for (i = 0; i < that.m_TZPartVctr->GetSize(); i++) + { + ip = (ICalComponent *) that.m_TZPartVctr->GetAt(i); + tzclone = ip->clone(m_Log); + PR_ASSERT(tzclone != 0); + if (tzclone != 0) + { + m_TZPartVctr->Add(tzclone); + } + } + } + } +} +//--------------------------------------------------------------------- +ICalComponent * +VTimeZone::clone(JLog * initLog) +{ + m_Log = initLog; + //PR_ASSERT(m_Log != 0); + return new VTimeZone(*this); +} +//--------------------------------------------------------------------- + +VTimeZone::~VTimeZone() +{ + if (m_TZPartVctr != 0) + { + ICalComponent::deleteICalComponentVector(m_TZPartVctr); + delete m_TZPartVctr; m_TZPartVctr = 0; + } + if (m_LastModified != 0) + { + delete m_LastModified; m_LastModified = 0; + } + if (m_TZID != 0) + { + delete m_TZID; m_TZID = 0; + } + if (m_TZURL != 0) + { + delete m_TZURL; m_TZURL = 0; + } + if (m_XTokensVctr != 0) + { + ICalComponent::deleteUnicodeStringVector(m_XTokensVctr); + delete m_XTokensVctr; m_XTokensVctr = 0; + } + // NOTE: verify this + if (m_NLSTimeZone != 0) + { + delete m_NLSTimeZone; m_NLSTimeZone = 0; + } +} + +//--------------------------------------------------------------------- +UnicodeString & +VTimeZone::parse(ICalReader * brFile, UnicodeString & sType, + UnicodeString & parseStatus, JulianPtrArray * vTimeZones, + t_bool bIgnoreBeginError, JulianUtility::MimeEncoding encoding) +{ + UnicodeString strLine, propName, propVal; + parseStatus = JulianKeyword::Instance()->ms_sOK; + JulianPtrArray * parameters = new JulianPtrArray(); + PR_ASSERT(parameters != 0 && brFile != 0); + if (parameters == 0 || brFile == 0) + { + // ran out of memory, return invalid vtimezone + return parseStatus; + } + + ErrorCode status = ZERO_ERROR; + t_bool parseError = FALSE; + //PR_ASSERT(vTimeZones == 0); + + // NOTE: remove later, to avoid compiler warning + if (sType.size() > 0 && vTimeZones) {} + + while (TRUE) + { + PR_ASSERT(brFile != 0); + brFile->readFullLine(strLine, status); + ICalProperty::Trim(strLine); + + if (FAILURE(status) && strLine.size() == 0) + break; + + ICalProperty::parsePropertyLine(strLine, propName, propVal, parameters); + + if (strLine.size() == 0) + { + ICalProperty::deleteICalParameterVector(parameters); + parameters->RemoveAll(); + + continue; + } + else if ((propName.compareIgnoreCase(JulianKeyword::Instance()->ms_sEND) == 0) && + (propVal.compareIgnoreCase(JulianKeyword::Instance()->ms_sVTIMEZONE) == 0)) + { + ICalProperty::deleteICalParameterVector(parameters); + parameters->RemoveAll(); + + break; + } + else if (((propName.compareIgnoreCase(JulianKeyword::Instance()->ms_sEND) == 0) && + ((propVal.compareIgnoreCase(JulianKeyword::Instance()->ms_sVCALENDAR) == 0) || + (propVal.compareIgnoreCase(JulianKeyword::Instance()->ms_sVEVENT) == 0) || + (propVal.compareIgnoreCase(JulianKeyword::Instance()->ms_sVTODO) == 0) || + (propVal.compareIgnoreCase(JulianKeyword::Instance()->ms_sVJOURNAL) == 0) || + (propVal.compareIgnoreCase(JulianKeyword::Instance()->ms_sVFREEBUSY) == 0) || + (ICalProperty::IsXToken(propVal))) + ) || + ((propName.compareIgnoreCase(JulianKeyword::Instance()->ms_sBEGIN) == 0) && + ((propVal.compareIgnoreCase(JulianKeyword::Instance()->ms_sVTIMEZONE) == 0) && !bIgnoreBeginError) || + (propVal.compareIgnoreCase(JulianKeyword::Instance()->ms_sVEVENT) == 0) || + (propVal.compareIgnoreCase(JulianKeyword::Instance()->ms_sVTODO) == 0) || + (propVal.compareIgnoreCase(JulianKeyword::Instance()->ms_sVJOURNAL) == 0) || + (propVal.compareIgnoreCase(JulianKeyword::Instance()->ms_sVFREEBUSY) == 0) || + (propVal.compareIgnoreCase(JulianKeyword::Instance()->ms_sVCALENDAR) == 0) || + (ICalProperty::IsXToken(propVal)) + )) + + { + // abrupt break of parsing + // Break on END:VCALENDAR, VEVENT, VTODO, VJOURNAL, VFREEBUSY, x-token, + // break on BEGIN:VTIMEZONE (and not first BEGIN:VTIMEZONE) + // break on BEGIN:VEVENT, VTODO, VJOURNAL, VFREEBUSY, VCALENDAR, xtoken + ICalProperty::deleteICalParameterVector(parameters); + parameters->RemoveAll(); + + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iAbruptEndOfParsing, + JulianKeyword::Instance()->ms_sVTIMEZONE, strLine, 300); + + parseStatus = strLine; + break; + } + else if ((propName.compareIgnoreCase(JulianKeyword::Instance()->ms_sBEGIN) == 0) && + ((propVal.compareIgnoreCase(JulianKeyword::Instance()->ms_sDAYLIGHT) == 0) || + (propVal.compareIgnoreCase(JulianKeyword::Instance()->ms_sSTANDARD) == 0))) + { + // Add the DAYLIGHT, STANDARD parts + ICalProperty::deleteICalParameterVector(parameters); + parameters->RemoveAll(); + + TZPart * tzpart = new TZPart(m_Log); + PR_ASSERT(tzpart != 0); + if (tzpart != 0) + { + tzpart->parse(brFile, propVal, parseStatus, 0); + + if (!tzpart->isValid()) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iInvalidTZPart, 200); + delete tzpart; tzpart = 0; + } + else + { + addTZPart(tzpart); + } + } + } + else + { + storeData(strLine, propName, propVal, parameters); + ICalProperty::deleteICalParameterVector(parameters); + parameters->RemoveAll(); + } + } + ICalProperty::deleteICalParameterVector(parameters); + parameters->RemoveAll(); + delete parameters; parameters = 0; + + selfCheck(); + return parseStatus; +} +//--------------------------------------------------------------------- +void VTimeZone::storeData(UnicodeString & strLine, UnicodeString & propName, + UnicodeString & propVal, JulianPtrArray * parameters) +{ + + if (strLine.size() > 0) + { + } + //UnicodeString u; + t_int32 hashCode = propName.hashCode(); + //if (propName.compareIgnoreCase(JulianKeyword::Instance()->ms_sLASTMODIFIED) == 0) + + if (JulianKeyword::Instance()->ms_ATOM_LASTMODIFIED == hashCode) + { + // no parameters + if (parameters->GetSize() > 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iInvalidOptionalParam, + JulianKeyword::Instance()->ms_sVTIMEZONE, strLine, 100); + } + + if (getLastModifiedProperty() != 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iDuplicatedProperty, + JulianKeyword::Instance()->ms_sVTIMEZONE, propName, 100); + } + DateTime d(propVal); + setLastModified(d, parameters); + } + else if (JulianKeyword::Instance()->ms_ATOM_TZID == hashCode) + { + // no parameters + if (parameters->GetSize() > 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iInvalidOptionalParam, + JulianKeyword::Instance()->ms_sVTIMEZONE, strLine, 100); + } + + if (getTZIDProperty() != 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iDuplicatedProperty, + JulianKeyword::Instance()->ms_sVTIMEZONE, propName, 100); + } + setTZID(propVal, parameters); + } + else if (JulianKeyword::Instance()->ms_ATOM_TZURL == hashCode) + { + // no parameters + if (parameters->GetSize() > 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iInvalidOptionalParam, + JulianKeyword::Instance()->ms_sVTIMEZONE, strLine, 100); + } + + if (getTZURLProperty() != 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iDuplicatedProperty, + JulianKeyword::Instance()->ms_sVTIMEZONE, propName, 100); + } + setTZURL(propVal, parameters); + } + else if (ICalProperty::IsXToken(propName)) + { + addXTokens(strLine); + } + else + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iInvalidPropertyName, + JulianKeyword::Instance()->ms_sVTIMEZONE, propName, 200); + } +} +//--------------------------------------------------------------------- + +void VTimeZone::selfCheck() +{ + if (isValid()) + { + // Make the NLS timezone part + createNLSTimeZone(); + } +} + +//--------------------------------------------------------------------- + +void VTimeZone::createNLSTimeZone() +{ + float f1, f2; + t_int32 toOffset; + UnicodeString u; + + if ((0 != getStandardPart()) && 0 != getDaylightPart()) + { + // create a NLSTimeZone with daylight and standard part + u = getStandardPart()->getTZOffsetTo(); + f1 = TZPart::UTCOffsetToFloat(u); + u = getDaylightPart()->getTZOffsetTo(); + f2 = TZPart::UTCOffsetToFloat(u); + + toOffset = (t_int32) ((f2 - f1) * kMillisPerHour); + + if (m_NLSTimeZone != 0) + { + delete m_NLSTimeZone; m_NLSTimeZone = 0; + } + m_NLSTimeZone = new SimpleTimeZone((t_int32) (f1 * kMillisPerHour), getTZID(), + (t_int8) getDaylightPart()->getMonth(), + (t_int8) getDaylightPart()->getDayOfWeekInMonth(), + (t_int8) getDaylightPart()->getDay(), + (t_int32) getDaylightPart()->getStartTime(), + (t_int8) getStandardPart()->getMonth(), + (t_int8) getStandardPart()->getDayOfWeekInMonth(), + (t_int8) getStandardPart()->getDay(), + (t_int32) getStandardPart()->getStartTime(), + (t_int32) toOffset); + + PR_ASSERT(m_NLSTimeZone != 0); + if (m_NLSTimeZone != 0) + { + m_NLSTimeZone->setRawOffset((t_int32) (f1 * kMillisPerHour)); + m_NLSTimeZone->setID(getTZID()); + + m_NLSTimeZone->setStartRule(getDaylightPart()->getMonth(), getDaylightPart()->getDayOfWeekInMonth(), + getDaylightPart()->getDay(), getDaylightPart()->getStartTime()); + + m_NLSTimeZone->setEndRule(getStandardPart()->getMonth(), getStandardPart()->getDayOfWeekInMonth(), + getStandardPart()->getDay(), getStandardPart()->getStartTime()); + } + } + else + { + PR_ASSERT(m_TZPartVctr != 0 && m_TZPartVctr->GetSize() > 0); + if (m_TZPartVctr != 0 && m_TZPartVctr->GetSize() > 0) + { + // use first tzpart to create a single part timezone, + TZPart * tz = (TZPart *) m_TZPartVctr->GetAt(0); + u = tz->getTZOffsetTo(); + f1 = TZPart::UTCOffsetToFloat(u); + + if (m_NLSTimeZone != 0) + { + delete m_NLSTimeZone; m_NLSTimeZone = 0; + } + m_NLSTimeZone = new SimpleTimeZone((t_int32) (f1 * kMillisPerHour), getTZID()); + PR_ASSERT(m_NLSTimeZone != 0); + } + } +} + +//--------------------------------------------------------------------- + +t_bool VTimeZone::isValid() +{ + // TODO: log invalid ID, Daylight, Standard. + /* Must have tzid, standard || daylight part && at most 2 parts. */ + + if (0 == getTZID().size()) + return FALSE; + + // if no parts, return FALSE + if ((0 == getDaylightPart()) && (0 == getStandardPart())) + return FALSE; + + if (!ms_bMORE_THAN_TWO_TZPARTS) + { + if (0 != getTZParts()) + { + if (getTZParts()->GetSize() > 2) + return FALSE; + } + } + return TRUE; +} + +//--------------------------------------------------------------------- +UnicodeString VTimeZone::toICALString() +{ + UnicodeString u = JulianKeyword::Instance()->ms_sVTIMEZONE; + return ICalComponent::format(u, JulianFormatString::Instance()->ms_sVTimeZoneAllMessage, ""); +} +//--------------------------------------------------------------------- +UnicodeString VTimeZone::toICALString(UnicodeString method, + UnicodeString name, + t_bool isRecurring) +{ + // NOTE: remove later avoid warnings + if (isRecurring) {} + return toICALString(); +} +//--------------------------------------------------------------------- +UnicodeString VTimeZone::toString() +{ + return ICalComponent::toStringFmt( + JulianFormatString::Instance()->ms_VTimeZoneStrDefaultFmt); +} +//--------------------------------------------------------------------- +UnicodeString VTimeZone::toStringChar(t_int32 c, UnicodeString & dateFmt) +{ + UnicodeString s; + t_int32 i; + TZPart * tzp; + + switch (c) + { + case ms_cTZParts: + if (getTZParts() != 0) + { + for (i = 0; i < getTZParts()->GetSize(); i++) + { + tzp = (TZPart *) getTZParts()->GetAt(i); + s += tzp->toString(); + } + } + return s; + case ms_cLastModified: + return ICalProperty::propertyToString(getLastModifiedProperty(), dateFmt, s); + case ms_cTZID: + return ICalProperty::propertyToString(getTZIDProperty(), dateFmt, s); + case ms_cTZURL: + return ICalProperty::propertyToString(getTZURLProperty(), dateFmt, s); + default: + return ""; + } +} +//--------------------------------------------------------------------- +UnicodeString VTimeZone::formatChar(t_int32 c, UnicodeString sFilterAttendee, + t_bool delegateRequest) +{ + UnicodeString s, sResult; + t_int32 i; + TZPart * tzp; + + // NOTE: remove here is get rid of compiler warnings + if (sFilterAttendee.size() > 0 || delegateRequest) + { + } + + switch (c) + { + case ms_cTZParts: + if (getTZParts() != 0) + { + for (i = 0; i < getTZParts()->GetSize(); i++) + { + tzp = (TZPart *) getTZParts()->GetAt(i); + s += tzp->toICALString(); + } + } + return s; + case ms_cLastModified: + s = JulianKeyword::Instance()->ms_sLASTMODIFIED; + return ICalProperty::propertyToICALString(s, getLastModifiedProperty(), sResult); + case ms_cTZID: + s = JulianKeyword::Instance()->ms_sTZID; + return ICalProperty::propertyToICALString(s, getTZIDProperty(), sResult); + case ms_cTZURL: + s = JulianKeyword::Instance()->ms_sTZURL; + return ICalProperty::propertyToICALString(s, getTZURLProperty(), sResult); + case ms_cXTokens: + return ICalProperty::vectorToICALString(getXTokens(), sResult); + default: + return ""; + } +} +//--------------------------------------------------------------------- + +void +VTimeZone::updateComponentHelper(VTimeZone * updatedComponent) +{ + DateTime d; + // no need: last-modified, TZID + ICalComponent::internalSetXTokensVctr(&m_XTokensVctr, updatedComponent->m_XTokensVctr); + + // call updateComponentHelper on TZPart's + ICalComponent::internalSetProperty(&m_TZURL, updatedComponent->m_TZURL); + setLastModified(d); + if (m_TZPartVctr != 0 && updatedComponent->getTZParts() != 0) + { + t_int32 i, j; + TZPart * tzp; + TZPart * uctzp; + for (i = 0; i < m_TZPartVctr->GetSize(); i++) + { + tzp = (TZPart *) m_TZPartVctr->GetAt(i); + for (j = 0; j < updatedComponent->getTZParts()->GetSize(); j++) + { + uctzp = (TZPart *) updatedComponent->getTZParts()->GetAt(j); + + tzp->updateComponent(uctzp); + } + } + } +} +//--------------------------------------------------------------------- + +t_bool +VTimeZone::updateComponent(ICalComponent * updatedComponent) +{ + if (updatedComponent != 0) + { + ICAL_COMPONENT ucType = updatedComponent->GetType(); + + // only call updateComponentHelper if it's a VTimeZone and + // it is an exact matching TZID + // basically always overwrite + if (ucType == ICAL_COMPONENT_VTIMEZONE) + { + // should be a safe cast with check above. + VTimeZone * ucvtz = (VTimeZone *) updatedComponent; + + // only if TZID's match and are not empty + if (ucvtz->getTZID().size() > 0 && getTZID().size() > 0) + { + if (ucvtz->getTZID() == getTZID()) + { + updateComponentHelper(ucvtz); + return TRUE; + } + } + } + } + return FALSE; +} +//--------------------------------------------------------------------- +void VTimeZone::addTZPart(TZPart * part) +{ + if (m_TZPartVctr == 0) + m_TZPartVctr = new JulianPtrArray(); + PR_ASSERT(m_TZPartVctr != 0); + PR_ASSERT(part != 0); + if (m_TZPartVctr != 0 && part != 0) + { + m_TZPartVctr->Add(part); + } +} +//--------------------------------------------------------------------- +TZPart * VTimeZone::getPart(UnicodeString & u) +{ + t_int32 i; + TZPart * tzp; + if (getTZParts() != 0) + { + for (i = 0; i < getTZParts()->GetSize(); i++) + { + tzp = (TZPart *) getTZParts()->GetAt(i); + if (tzp->getName().compareIgnoreCase(u) == 0) + { + return tzp; + } + } + } + return 0; +} +//--------------------------------------------------------------------- +TZPart * VTimeZone::getStandardPart() +{ + UnicodeString u = JulianKeyword::Instance()->ms_sSTANDARD; + return getPart(u); +} +//--------------------------------------------------------------------- +TZPart * VTimeZone::getDaylightPart() +{ + UnicodeString u = JulianKeyword::Instance()->ms_sDAYLIGHT; + return getPart(u); +} +//--------------------------------------------------------------------- +VTimeZone * VTimeZone::getTimeZone(UnicodeString & id, + JulianPtrArray * timezones) +{ + t_int32 i; + VTimeZone * vt; + if (timezones != 0) + { + for (i = 0; i < timezones->GetSize(); i++) + { + vt = (VTimeZone *) timezones->GetAt(i); + if (id.compareIgnoreCase(vt->getTZID()) == 0) + { + return vt; + } + } + + } + return 0; +} +//--------------------------------------------------------------------- +//LAST-MODIFIED +void VTimeZone::setLastModified(DateTime s, JulianPtrArray * parameters) +{ +#if 1 + if (m_LastModified == 0) + m_LastModified = ICalPropertyFactory::Make(ICalProperty::DATETIME, + (void *) &s, parameters); + else + { + m_LastModified->setValue((void *) &s); + m_LastModified->setParameters(parameters); + } +#else + ICalComponent::setDateTimeValue(((ICalProperty **) &m_LastModified), s, parameters); +#endif +} + +DateTime VTimeZone::getLastModified() const +{ +#if 1 + DateTime d(-1); + if (m_LastModified == 0) + return d; // return 0; + else + { + d = *((DateTime *) m_LastModified->getValue()); + return d; + } +#else + DateTime d(-1); + ICalComponent::getDateTimeValue(((ICalProperty **) &m_LastModified), d); + return d; +#endif +} +//--------------------------------------------------------------------- +//TZID +void VTimeZone::setTZID(UnicodeString s, JulianPtrArray * parameters) +{ +#if 1 + //UnicodeString * s_ptr = new UnicodeString(s); + //PR_ASSERT(s_ptr != 0); + + if (m_TZID == 0) + m_TZID = ICalPropertyFactory::Make(ICalProperty::TEXT, + (void *) &s, parameters); + else + { + m_TZID->setValue((void *) &s); + m_TZID->setParameters(parameters); + } +#else + ICalComponent::setStringValue(((ICalProperty **) &m_TZID), s, parameters); +#endif +} +UnicodeString VTimeZone::getTZID() const +{ +#if 1 + UnicodeString u; + if (m_TZID == 0) + return ""; + else + { + u = *((UnicodeString *) m_TZID->getValue()); + return u; + } +#else + UnicodeString us; + ICalComponent::getStringValue(((ICalProperty **) &m_TZID), us); + return us; +#endif +} +//--------------------------------------------------------------------- +//TZURL +void VTimeZone::setTZURL(UnicodeString s, JulianPtrArray * parameters) +{ +#if 1 + //UnicodeString * s_ptr = new UnicodeString(s); + //PR_ASSERT(s_ptr != 0); + + if (m_TZURL == 0) + m_TZURL = ICalPropertyFactory::Make(ICalProperty::TEXT, + (void *) &s, parameters); + else + { + m_TZURL->setValue((void *) &s); + m_TZURL->setParameters(parameters); + } +#else + ICalComponent::setStringValue(((ICalProperty **) &m_TZURL), s, parameters); +#endif +} +UnicodeString VTimeZone::getTZURL() const +{ +#if 1 + UnicodeString u; + if (m_TZURL == 0) + return ""; + else + { + u = *((UnicodeString *) m_TZURL->getValue()); + return u; + } +#else + UnicodeString us; + ICalComponent::getStringValue(((ICalProperty **) &m_TZID), us); + return us; +#endif +} +//--------------------------------------------------------------------- +DateTime +VTimeZone::DateTimeApplyTimeZone(UnicodeString & time, + JulianPtrArray * vTimeZones, + JulianPtrArray * parameters) +{ + DateTime d; + UnicodeString out, u; + VTimeZone * vt = 0; + TimeZone *t = 0; + u = JulianKeyword::Instance()->ms_sTZID; + out = ICalParameter::GetParameterFromVector(u, out, parameters); + + //if (FALSE) TRACE("out = %s\r\n", out.toCString("")); + if (out.size() > 0) + { + vt = VTimeZone::getTimeZone(out, vTimeZones); + if (vt != 0) + t = vt->getNLSTimeZone(); + } + if (t != 0) + d.setTimeString(time, t); + else + d.setTimeString(time); + + return d; +} +//--------------------------------------------------------------------- +// XTOKENS +void VTimeZone::addXTokens(UnicodeString s) +{ + if (m_XTokensVctr == 0) + m_XTokensVctr = new JulianPtrArray(); + PR_ASSERT(m_XTokensVctr != 0); + if (m_XTokensVctr != 0) + { + m_XTokensVctr->Add(new UnicodeString(s)); + } +} +//--------------------------------------------------------------------- diff --git a/calendar/modules/core/ical/src/vtodo.cpp b/calendar/modules/core/ical/src/vtodo.cpp new file mode 100644 index 00000000000..c413b54083a --- /dev/null +++ b/calendar/modules/core/ical/src/vtodo.cpp @@ -0,0 +1,1217 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +/* + * vtodo.cpp + * John Sun + * 4/22/98 3:41:09 PM + */ + +#include "stdafx.h" +#include "jdefines.h" + +#include "jutility.h" +#include "vtodo.h" +#include "icalredr.h" +#include "prprtyfy.h" +#include "unistrto.h" +#include "jlog.h" +#include "vtimezne.h" +#include "keyword.h" +#include "period.h" +#include "datetime.h" + +#include "functbl.h" +//--------------------------------------------------------------------- +void VTodo::setDefaultFmt(UnicodeString s) +{ + JulianFormatString::Instance()->ms_VTodoStrDefaultFmt = s; +} +//--------------------------------------------------------------------- +#if 0 +VTodo::VTodo() +{ + PR_ASSERT(FALSE); +} +#endif +//--------------------------------------------------------------------- + +VTodo::VTodo(JLog * initLog) +: m_Due(0), + m_Completed(0), + m_TempDuration(0), + m_GEO(0), + m_Location(0), + m_PercentComplete(0), + m_Priority(0), + m_ResourcesVctr(0), + TimeBasedEvent(initLog) +{ +} + +//--------------------------------------------------------------------- + +VTodo::VTodo(VTodo & that) +: m_Due(0), + m_Completed(0), + m_TempDuration(0), + m_GEO(0), + m_Location(0), + m_PercentComplete(0), + m_Priority(0), + m_ResourcesVctr(0), + TimeBasedEvent(that) +{ + m_origDue = that.m_origDue; + m_origMyDue = that.m_origMyDue; + + if (that.m_Completed != 0) + { + m_Completed = that.m_Completed->clone(m_Log); + } + if (that.m_Due != 0) + { + m_Due = that.m_Due->clone(m_Log); + } + //if (that.m_Duration != 0) { m_Duration = that.m_Duration->clone(m_Log); } + if (that.m_GEO != 0) + { + m_GEO = that.m_GEO->clone(m_Log); + } + if (that.m_Location != 0) + { + m_Location = that.m_Location->clone(m_Log); + } + if (that.m_PercentComplete != 0) + { + m_PercentComplete = that.m_PercentComplete->clone(m_Log); + } + if (that.m_Priority != 0) + { + m_Priority = that.m_Priority->clone(m_Log); + } + if (that.m_ResourcesVctr != 0) + { + m_ResourcesVctr = new JulianPtrArray(); PR_ASSERT(m_ResourcesVctr != 0); + if (m_ResourcesVctr != 0) + { + ICalProperty::CloneICalPropertyVector(that.m_ResourcesVctr, m_ResourcesVctr, m_Log); + } + } +} + +//--------------------------------------------------------------------- + +ICalComponent * +VTodo::clone(JLog * initLog) +{ + m_Log = initLog; + return new VTodo(*this); +} + +//--------------------------------------------------------------------- + +VTodo::~VTodo() +{ + if (m_TempDuration != 0) + { + delete m_TempDuration; m_TempDuration = 0; + } + // properties + if (m_Completed != 0) + { + delete m_Completed; m_Completed = 0; + } + if (m_Due != 0) + { + delete m_Due; m_Due = 0; + } + //if (m_Duration != 0) { delete m_Duration; m_Duration = 0; } + if (m_GEO != 0) + { + delete m_GEO; m_GEO = 0; + } + if (m_Location!= 0) + { + delete m_Location; m_Location = 0; + } + if (m_PercentComplete != 0) + { + delete m_PercentComplete; m_PercentComplete = 0; + } + if (m_Priority!= 0) + { + delete m_Priority; m_Priority = 0; + } + + // vector of strings + if (m_ResourcesVctr != 0) { + ICalProperty::deleteICalPropertyVector(m_ResourcesVctr); + delete m_ResourcesVctr; m_ResourcesVctr = 0; + } + //delete (TimeBasedEvent *) this; +} + +//--------------------------------------------------------------------- + +UnicodeString & +VTodo::parse(ICalReader * brFile, UnicodeString & sMethod, + UnicodeString & parseStatus, JulianPtrArray * vTimeZones, + t_bool bIgnoreBeginError, JulianUtility::MimeEncoding encoding) +{ + UnicodeString u = JulianKeyword::Instance()->ms_sVTODO; + return parseType(u, brFile, sMethod, parseStatus, vTimeZones, bIgnoreBeginError, encoding); +} + +//--------------------------------------------------------------------- + +Date VTodo::difference() +{ + if (getDue().getTime() >= 0 && getDTStart().getTime() >= 0) + { + return (getDue().getTime() - getDTStart().getTime()); + } + else return 0; +} + +//--------------------------------------------------------------------- + +void VTodo::selfCheck() +{ + TimeBasedEvent::selfCheck(); + + // if no due, and there is a dtstart and duration, calculate due + if (!getDue().isValid()) + { + // calculate Due from duration and dtstart + // TODO: remove memory leaks in m_TempDuration + if (getDTStart().isValid() && m_TempDuration != 0 && m_TempDuration->isValid()) + { + DateTime due; + due = getDTStart(); + due.add(*m_TempDuration); + setDue(due); + delete m_TempDuration; m_TempDuration = 0; + } + else if (!getDTStart().isValid()) + { + if (m_TempDuration != 0) + delete m_TempDuration; m_TempDuration = 0; + } + } + if (getStatus().size() > 0) + { + // check if I got a valid status + UnicodeString u = getStatus(); + u.toUpper(); + ICalProperty::Trim(u); + JAtom ua(u); + if ((JulianKeyword::Instance()->ms_ATOM_NEEDSACTION != ua) && + (JulianKeyword::Instance()->ms_ATOM_COMPLETED != ua) && + (JulianKeyword::Instance()->ms_ATOM_INPROCESS != ua) && + (JulianKeyword::Instance()->ms_ATOM_CANCELLED != ua)) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iInvalidPropertyValue, + JulianKeyword::Instance()->ms_sVTODO, + JulianKeyword::Instance()->ms_sSTATUS, u, 200); + + setStatus(""); + } + } +} + +//--------------------------------------------------------------------- +//--------------------------------------------------------------------- +void VTodo::storeCompleted(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones) +{ + // no parameters (MUST BE IN UTC) + if (parameters->GetSize() > 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iInvalidOptionalParam, + JulianKeyword::Instance()->ms_sVTODO, strLine, 100); + } + if (getCompletedProperty() != 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iDuplicatedProperty, + JulianKeyword::Instance()->ms_sVTODO, + JulianKeyword::Instance()->ms_sCOMPLETED, 100); + } + DateTime d; + d = VTimeZone::DateTimeApplyTimeZone(propVal, vTimeZones, parameters); + + setCompleted(d, parameters); +} +void VTodo::storeDue(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones) +{ + // check parameters + t_bool bParamValid = ICalProperty::CheckParamsWithValueRangeCheck(parameters, + JulianAtomRange::Instance()->ms_asTZIDValueParamRange, + JulianAtomRange::Instance()->ms_asTZIDValueParamRangeSize, + JulianAtomRange::Instance()->ms_asDateDateTimeValueRange, + JulianAtomRange::Instance()->ms_asDateDateTimeValueRangeSize); + if (!bParamValid) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iInvalidOptionalParam, + JulianKeyword::Instance()->ms_sVTODO, strLine, 100); + } + + if (getDueProperty() != 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iDuplicatedProperty, + JulianKeyword::Instance()->ms_sVTODO, + JulianKeyword::Instance()->ms_sDUE, 100); + } + UnicodeString u, out; + + u = JulianKeyword::Instance()->ms_sVALUE; + out = ICalParameter::GetParameterFromVector(u, out, parameters); + + t_bool bIsDate = DateTime::IsParseableDate(propVal); + + if (bIsDate) + { + // if there is a VALUE=X parameter, make sure X is DATE + if (out.size() != 0 && (JulianKeyword::Instance()->ms_ATOM_DATE != out.hashCode())) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iPropertyValueTypeMismatch, + JulianKeyword::Instance()->ms_sVTODO, strLine, 100); + } + } + else + { + // if there is a VALUE=X parameter, make sure X is DATETIME + if (out.size() != 0 && (JulianKeyword::Instance()->ms_ATOM_DATETIME != out.hashCode())) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iPropertyValueTypeMismatch, + JulianKeyword::Instance()->ms_sVTODO, strLine, 100); + } + } + + DateTime d; + d = VTimeZone::DateTimeApplyTimeZone(propVal, vTimeZones, parameters); + + setDue(d, parameters); +} +void VTodo::storeDuration(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones) +{ + // no parameters + if (parameters->GetSize() > 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iInvalidOptionalParam, + JulianKeyword::Instance()->ms_sVTODO, strLine, 100); + } + + if (m_TempDuration != 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iDuplicatedProperty, + JulianKeyword::Instance()->ms_sVTODO, + JulianKeyword::Instance()->ms_sDURATION, 100); + } + //Julian_Duration d(propVal); + if (m_TempDuration == 0) + { + m_TempDuration = new Julian_Duration(propVal); + PR_ASSERT(m_TempDuration != 0); + } + else + m_TempDuration->setDurationString(propVal); +} +void VTodo::storeGEO(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones) +{ + // no parameters + if (parameters->GetSize() > 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iInvalidOptionalParam, + JulianKeyword::Instance()->ms_sVTODO, strLine, 100); + } + + if (getGEOProperty() != 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iDuplicatedProperty, + JulianKeyword::Instance()->ms_sVTODO, + JulianKeyword::Instance()->ms_sGEO, 100); + } + setGEO(propVal, parameters); +} +void VTodo::storeLocation(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones) +{ + t_bool bParamValid = ICalProperty::CheckParams(parameters, + JulianAtomRange::Instance()->ms_asAltrepLanguageParamRange, + JulianAtomRange::Instance()->ms_asAltrepLanguageParamRangeSize); + + if (!bParamValid) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iInvalidOptionalParam, + JulianKeyword::Instance()->ms_sVTODO, strLine, 100); + } + + if (getLocationProperty() != 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iDuplicatedProperty, + JulianKeyword::Instance()->ms_sVTODO, + JulianKeyword::Instance()->ms_sLOCATION, 100); + } + setLocation(propVal, parameters); +} +void VTodo::storePercentComplete(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones) +{ + t_bool bParseError = FALSE; + t_int32 i; + + // no parameters + if (parameters->GetSize() > 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iInvalidOptionalParam, + JulianKeyword::Instance()->ms_sVTODO, strLine, 100); + } + + char * pcc = propVal.toCString(""); + PR_ASSERT(pcc != 0); + i = JulianUtility::atot_int32(pcc, bParseError, propVal.size()); + delete [] pcc; pcc = 0; + if (getPercentCompleteProperty() != 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iDuplicatedProperty, + JulianKeyword::Instance()->ms_sVTODO, + JulianKeyword::Instance()->ms_sPERCENTCOMPLETE, 100); + } + if (!bParseError) + { + if (i > 100) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iRoundedPercentCompleteTo100, + JulianKeyword::Instance()->ms_sVTODO, + JulianKeyword::Instance()->ms_sPERCENTCOMPLETE, 100); + i = 100; + } + setPercentComplete(i, parameters); + } + else + { + if (m_Log) m_Log->logError(JulianLogErrorMessage::Instance()->ms_iInvalidNumberFormat, + JulianKeyword::Instance()->ms_sVTODO, + JulianKeyword::Instance()->ms_sPERCENTCOMPLETE, propVal, 200); + } +} +void VTodo::storePriority(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones) +{ + t_bool bParseError = FALSE; + t_int32 i; + + // no parameters + if (parameters->GetSize() > 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iInvalidOptionalParam, + JulianKeyword::Instance()->ms_sVTODO, strLine, 100); + } + + char * pcc = propVal.toCString(""); + PR_ASSERT(pcc != 0); + i = JulianUtility::atot_int32(pcc, bParseError, propVal.size()); + delete [] pcc; pcc = 0; + if (getPriorityProperty() != 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iDuplicatedProperty, + JulianKeyword::Instance()->ms_sVTODO, + JulianKeyword::Instance()->ms_sPRIORITY, 100); + } + if (!bParseError) + { + setPriority(i, parameters); + } + else + { + if (m_Log) m_Log->logError(JulianLogErrorMessage::Instance()->ms_iInvalidNumberFormat, + JulianKeyword::Instance()->ms_sVTODO, + JulianKeyword::Instance()->ms_sPRIORITY, propVal, 200); + } +} +void VTodo::storeResources(UnicodeString & strLine, UnicodeString & propVal, + JulianPtrArray * parameters, JulianPtrArray * vTimeZones) +{ +// check parameters + t_bool bParamValid = ICalProperty::CheckParams(parameters, + JulianAtomRange::Instance()->ms_asLanguageParamRange, + JulianAtomRange::Instance()->ms_asLanguageParamRangeSize); + if (!bParamValid) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iInvalidOptionalParam, + JulianKeyword::Instance()->ms_sVTODO, strLine, 100); + } + + addResourcesPropertyVector(propVal, parameters); +} +//--------------------------------------------------------------------- +t_bool +VTodo::storeData(UnicodeString & strLine, UnicodeString & propName, + UnicodeString & propVal, JulianPtrArray * parameters, + JulianPtrArray * vTimeZones) +{ + if (TimeBasedEvent::storeData(strLine, propName, propVal, + parameters, vTimeZones)) + return TRUE; + else + { + t_int32 hashCode = propName.hashCode(); + t_int32 i; + for (i = 0; 0 != (JulianFunctionTable::Instance()->vtStoreTable[i]).op; i++) + { + if ((JulianFunctionTable::Instance()->vtStoreTable[i]).hashCode == hashCode) + { + ApplyStoreOp(((JulianFunctionTable::Instance())->vtStoreTable[i]).op, + strLine, propVal, parameters, vTimeZones); + return TRUE; + } + } + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iInvalidPropertyName, + JulianKeyword::Instance()->ms_sVTODO, propName, 200); + UnicodeString u; + u = JulianLogErrorMessage::Instance()->ms_sRS202; + u += '.'; u += ' '; + u += strLine; + addRequestStatus(u); + return FALSE; + } +} + +//--------------------------------------------------------------------- + +void VTodo::populateDatesHelper(DateTime start, Date ldiff, + JulianPtrArray * vPeriods) +{ + Date diff = ldiff; + Date diff2 = -1; + + if (vPeriods != 0) + { + // Check if period matches this date, if-so, set + // difference to be length of period + // TODO: if multiple periods match this date, choose period + // with longest length + + t_int32 i; + UnicodeString u; + Period p; + DateTime ps, pe; + Date pl; + for (i = 0; i < vPeriods->GetSize(); i++) + { + u = *((UnicodeString *) vPeriods->GetAt(i)); + + //if (FALSE) TRACE("populateDatesHelper(): u = %s\r\n", u.toCString("")); + + p.setPeriodString(u); + PR_ASSERT(p.isValid()); + if (p.isValid()) + { + ps = p.getStart(); + + if (ps.equalsDateTime(start)) + { + pe = p.getEndingTime(pe); + pl = (pe.getTime() - ps.getTime()); + //if (FALSE) TRACE("populateDatesHelper(): pl = %d\r\n", pl); + + diff2 = ((diff2 > pl) ? diff2 : pl); + } + } + } + } + if (diff2 != -1) + diff = diff2; + + DateTime dDue; + dDue.setTime(start.getTime() + diff); + setDue(dDue); + setMyOrigDue(dDue); + + DateTime origDue; + origDue.setTime(getOrigStart().getTime() + ldiff); + setOrigDue(origDue); +} + +//--------------------------------------------------------------------- + +UnicodeString VTodo::formatHelper(UnicodeString & strFmt, + UnicodeString sFilterAttendee, + t_bool delegateRequest) +{ + UnicodeString u = JulianKeyword::Instance()->ms_sVTODO; + return ICalComponent::format(u, strFmt, sFilterAttendee, delegateRequest); +} + +//--------------------------------------------------------------------- + +UnicodeString VTodo::toString() +{ + return ICalComponent::toStringFmt( + JulianFormatString::Instance()->ms_VTodoStrDefaultFmt); +} + +//--------------------------------------------------------------------- + +UnicodeString VTodo::toStringChar(t_int32 c, UnicodeString & dateFmt) +{ + UnicodeString sResult; + switch ( c ) + { + case ms_cCompleted: + return ICalProperty::propertyToString(getCompletedProperty(), dateFmt, sResult); + case ms_cDue: + return ICalProperty::propertyToString(getDueProperty(), dateFmt, sResult); + case ms_cDuration: + return getDuration().toString(); + //return ICalProperty::propertyToString(getDurationProperty(), dateFmt, sResult); + case ms_cGEO: + return ICalProperty::propertyToString(getGEOProperty(), dateFmt, sResult); + case ms_cLocation: + return ICalProperty::propertyToString(getLocationProperty(), dateFmt, sResult); + case ms_cPercentComplete: + return ICalProperty::propertyToString(getPercentCompleteProperty(), dateFmt, sResult); + case ms_cPriority: + return ICalProperty::propertyToString(getPriorityProperty(), dateFmt, sResult); + case ms_cResources: + return ICalProperty::propertyVectorToString(getResources(), dateFmt, sResult); + default: + return TimeBasedEvent::toStringChar(c, dateFmt); + } +} + +//--------------------------------------------------------------------- + +UnicodeString VTodo::formatChar(t_int32 c, UnicodeString sFilterAttendee, + t_bool delegateRequest) +{ + UnicodeString s, sResult; + switch (c) { + case ms_cCompleted: + s = JulianKeyword::Instance()->ms_sCOMPLETED; + return ICalProperty::propertyToICALString(s, getCompletedProperty(), sResult); + case ms_cDue: + s = JulianKeyword::Instance()->ms_sDUE; + return ICalProperty::propertyToICALString(s, getDueProperty(), sResult); + case ms_cDuration: + s = JulianKeyword::Instance()->ms_sDURATION; + s += ':'; + s += getDuration().toICALString(); + s += JulianKeyword::Instance()->ms_sLINEBREAK; + return s; + //return ICalProperty::propertyToICALString(s, getDurationProperty(), sResult); + case ms_cLocation: + s = JulianKeyword::Instance()->ms_sLOCATION; + return ICalProperty::propertyToICALString(s, getLocationProperty(), sResult); + case ms_cPercentComplete: + s = JulianKeyword::Instance()->ms_sPERCENTCOMPLETE; + return ICalProperty::propertyToICALString(s, getPercentCompleteProperty(), sResult); + case ms_cPriority: + s = JulianKeyword::Instance()->ms_sPRIORITY; + return ICalProperty::propertyToICALString(s, getPriorityProperty(), sResult); + case ms_cResources: + s = JulianKeyword::Instance()->ms_sRESOURCES; + return ICalProperty::propertyVectorToICALString(s, getResources(), sResult); + case ms_cGEO: + s = JulianKeyword::Instance()->ms_sGEO; + return ICalProperty::propertyToICALString(s, getGEOProperty(), sResult); + default: + { + return TimeBasedEvent::formatChar(c, sFilterAttendee, delegateRequest); + } + } +} + +//--------------------------------------------------------------------- + +t_bool VTodo::isValid() +{ + if ((getMethod().compareIgnoreCase(JulianKeyword::Instance()->ms_sPUBLISH) == 0) || + (getMethod().compareIgnoreCase(JulianKeyword::Instance()->ms_sREQUEST) == 0) || + (getMethod().compareIgnoreCase(JulianKeyword::Instance()->ms_sADD) == 0)) + { + // must have dtstart + if ((!getDTStart().isValid())) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iMissingStartingTime, 300); + return FALSE; + } + + // If due exists, make sure it is not before dtstart + //if (getDTEnd().isValid() && getDTEnd() < getDTStart()) + // return FALSE; + + // must have dtstamp, summary, uid + if (!getDTStamp().isValid()) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iMissingDTStamp, 300); + return FALSE; + } + if (getSummary().size() == 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iMissingSummary, 300); + return FALSE; + } + + if (getUID().size() == 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iMissingUID, 300); + return FALSE; + } + // must have organizer + if (getOrganizer().size() == 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iMissingOrganizer, 300); + return FALSE; + } + // must have sequence >= 0 + if (getSequence() < 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iMissingSeqNo, 300); + return FALSE; + } + if (getMethod().compareIgnoreCase(JulianKeyword::Instance()->ms_sREQUEST) == 0) + { + if (getAttendees() == 0 || getAttendees()->GetSize() == 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iMissingAttendees, 300); + return FALSE; + } + } + } + else if ((getMethod().compareIgnoreCase(JulianKeyword::Instance()->ms_sREPLY) == 0) || + (getMethod().compareIgnoreCase(JulianKeyword::Instance()->ms_sCANCEL) == 0) || + (getMethod().compareIgnoreCase(JulianKeyword::Instance()->ms_sDECLINECOUNTER) == 0)) + { + // must have dtstamp, uid + if (!getDTStamp().isValid()) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iMissingDTStamp, 300); + return FALSE; + } + if (getUID().size() == 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iMissingUID, 300); + return FALSE; + } + // must have organizer + if (getOrganizer().size() == 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iMissingOrganizer, 300); + return FALSE; + } + // must have sequence >= 0 + if (getSequence() < 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iMissingSeqNo, 300); + return FALSE; + } + if (getMethod().compareIgnoreCase(JulianKeyword::Instance()->ms_sREPLY) == 0) + { + if (getAttendees() == 0 || getAttendees()->GetSize() == 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iMissingAttendees, 300); + return FALSE; + } + } + } + else if ((getMethod().compareIgnoreCase(JulianKeyword::Instance()->ms_sREFRESH) == 0)) + { + // must have dtstamp, uid + if (!getDTStamp().isValid()) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iMissingDTStamp, 300); + return FALSE; + } + if (getUID().size() == 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iMissingUID, 300); + return FALSE; + } + // TODO: attendees required? + } + else if ((getMethod().compareIgnoreCase(JulianKeyword::Instance()->ms_sCOUNTER) == 0)) + { + // must have dtstamp, uid + if (!getDTStamp().isValid()) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iMissingDTStamp, 300); + return FALSE; + } + if (getUID().size() == 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iMissingUID, 300); + return FALSE; + } + // must have sequence >= 0 + if (getSequence() < 0) + { + if (m_Log) m_Log->logError( + JulianLogErrorMessage::Instance()->ms_iMissingSeqNo, 300); + return FALSE; + } + } + + + // check super class isValid method + return TimeBasedEvent::isValid(); +} + +//--------------------------------------------------------------------- + +UnicodeString VTodo::cancelMessage() +{ + UnicodeString s = JulianKeyword::Instance()->ms_sCANCELLED; + setStatus(s); + return formatHelper(JulianFormatString::Instance()->ms_sVTodoCancelMessage, ""); +} + +//--------------------------------------------------------------------- + +UnicodeString VTodo::requestMessage() +{ + return formatHelper(JulianFormatString::Instance()->ms_sVTodoRequestMessage, ""); +} + +//--------------------------------------------------------------------- + +UnicodeString VTodo::requestRecurMessage() +{ + return formatHelper(JulianFormatString::Instance()->ms_sVTodoRecurRequestMessage, ""); +} + +//--------------------------------------------------------------------- + +UnicodeString VTodo::counterMessage() +{ + return formatHelper(JulianFormatString::Instance()->ms_sVTodoCounterMessage, ""); +} + +//--------------------------------------------------------------------- + +UnicodeString VTodo::declineCounterMessage() +{ + return formatHelper(JulianFormatString::Instance()->ms_sVTodoDeclineCounterMessage, ""); +} + +//--------------------------------------------------------------------- + +UnicodeString VTodo::addMessage() +{ + return formatHelper(JulianFormatString::Instance()->ms_sVTodoAddMessage, ""); +} + +//--------------------------------------------------------------------- + +UnicodeString VTodo::refreshMessage(UnicodeString sAttendeeFilter) +{ + return formatHelper(JulianFormatString::Instance()->ms_sVTodoRefreshMessage, sAttendeeFilter); +} + +//--------------------------------------------------------------------- + +UnicodeString VTodo::allMessage() +{ + return formatHelper(JulianFormatString::Instance()->ms_sVTodoAllPropertiesMessage, ""); +} + +//--------------------------------------------------------------------- + +UnicodeString VTodo::replyMessage(UnicodeString sAttendeeFilter) +{ + return formatHelper(JulianFormatString::Instance()->ms_sVTodoReplyMessage, sAttendeeFilter); +} + +//--------------------------------------------------------------------- + +UnicodeString VTodo::publishMessage() +{ + return formatHelper(JulianFormatString::Instance()->ms_sVTodoPublishMessage, ""); +} + +//--------------------------------------------------------------------- + +UnicodeString VTodo::publishRecurMessage() +{ + return formatHelper(JulianFormatString::Instance()->ms_sVTodoRecurPublishMessage, ""); +} + +//--------------------------------------------------------------------- + +void +VTodo::updateComponentHelper(TimeBasedEvent * updatedComponent) +{ + //TODO: handle duration, origDue, origMyDue. + TimeBasedEvent::updateComponentHelper(updatedComponent); + if (updatedComponent->GetType() == GetType()) + { + ICalComponent::internalSetPropertyVctr(&m_ResourcesVctr, ((VTodo *) updatedComponent)->getResources()); + ICalComponent::internalSetProperty(&m_Completed, ((VTodo *) updatedComponent)->m_Completed); + ICalComponent::internalSetProperty(&m_Due, ((VTodo *) updatedComponent)->m_Due); + ICalComponent::internalSetProperty(&m_GEO, ((VTodo *) updatedComponent)->m_GEO); + ICalComponent::internalSetProperty(&m_Location, ((VTodo *) updatedComponent)->m_Location); + ICalComponent::internalSetProperty(&m_PercentComplete, ((VTodo *) updatedComponent)->m_PercentComplete); + ICalComponent::internalSetProperty(&m_Priority, ((VTodo *) updatedComponent)->m_Priority); + } +} + +//--------------------------------------------------------------------- +///Completed +void VTodo::setCompleted(DateTime s, JulianPtrArray * parameters) +{ +#if 1 + if (m_Completed == 0) + m_Completed = ICalPropertyFactory::Make(ICalProperty::DATETIME, + (void *) &s, parameters); + else + { + m_Completed->setValue((void *) &s); + m_Completed->setParameters(parameters); + } + //validateCompleted(); +#else + ICalComponent::setDateTimeValue(((ICalProperty **) &m_Completed), s, parameters); +#endif +} +DateTime VTodo::getCompleted() const +{ +#if 1 + DateTime d(-1); + if (m_Completed == 0) + return d; //return 0; + else + { + d = *((DateTime *) m_Completed->getValue()); + return d; + } +#else + DateTime d(-1); + ICalComponent::getDateTimeValue(((ICalProperty **) &m_Completed), d); + return d; +#endif +} +//--------------------------------------------------------------------- +///Due +void VTodo::setDue(DateTime s, JulianPtrArray * parameters) +{ +#if 1 + if (m_Due == 0) + m_Due = ICalPropertyFactory::Make(ICalProperty::DATETIME, + (void *) &s, parameters); + else + { + m_Due->setValue((void *) &s); + m_Due->setParameters(parameters); + } + //validateDue(); +#else + ICalComponent::setDateTimeValue(((ICalProperty **) &m_Due), s, parameters); +#endif +} +DateTime VTodo::getDue() const +{ +#if 1 + DateTime d(-1); + if (m_Due == 0) + return d; //return 0; + else + { + d = *((DateTime *) m_Due->getValue()); + return d; + } +#else + DateTime d(-1); + ICalComponent::getDateTimeValue(((ICalProperty **) &m_Due), d); + return d; +#endif +} +//--------------------------------------------------------------------- +///Julian_Duration +void VTodo::setDuration(Julian_Duration s, JulianPtrArray * parameters) +{ + /* + if (m_Duration == 0) + m_Duration = ICalPropertyFactory::Make(ICalProperty::DURATION, + (void *) &s, parameters); + else + { + m_Duration->setValue((void *) &s); + m_Duration->setParameters(parameters); + } + //validateDuration(); + */ + // NOTE: remove later, to avoid compiler warnings + if (parameters) + { + } + + + DateTime due; + due = getDTStart(); + due.add(s); + setDue(due); +} +Julian_Duration VTodo::getDuration() const +{ + /* + Julian_Duration d; d.setMonth(-1); + if (m_Duration == 0) + return d; // return 0; + else + { + d = *((Julian_Duration *) m_Duration->getValue()); + return d; + } + */ + Julian_Duration duration; + DateTime start, due; + start = getDTStart(); + due = getDue(); + DateTime::getDuration(start,due,duration); + return duration; +} +//--------------------------------------------------------------------- +//GEO +void VTodo::setGEO(UnicodeString s, JulianPtrArray * parameters) +{ +#if 1 + //UnicodeString * s_ptr = new UnicodeString(s); + //PR_ASSERT(s_ptr != 0); + + if (m_GEO == 0) + m_GEO = ICalPropertyFactory::Make(ICalProperty::TEXT, + (void *) &s, parameters); + else + { + m_GEO->setValue((void *) &s); + m_GEO->setParameters(parameters); + } +#else + ICalComponent::setStringValue(((ICalProperty **) &m_GEO), s, parameters); +#endif +} +UnicodeString VTodo::getGEO() const +{ +#if 1 + if (m_GEO == 0) + return ""; + else + return *((UnicodeString *) m_GEO->getValue()); +#else + UnicodeString us; + ICalComponent::getStringValue(((ICalProperty **) &m_GEO), us); + return us; +#endif +} + +//--------------------------------------------------------------------- +//Location +void VTodo::setLocation(UnicodeString s, JulianPtrArray * parameters) +{ +#if 1 + //UnicodeString * s_ptr = new UnicodeString(s); + //PR_ASSERT(s_ptr != 0); + + if (m_Location == 0) + { + m_Location = ICalPropertyFactory::Make(ICalProperty::TEXT, + (void *) &s, parameters); + } + else + { + m_Location->setValue((void *) &s); + m_Location->setParameters(parameters); + } +#else + ICalComponent::setStringValue(((ICalProperty **) &m_Location), s, parameters); +#endif +} +UnicodeString VTodo::getLocation() const +{ +#if 1 + if (m_Location == 0) + return ""; + else + return *((UnicodeString *) m_Location->getValue()); +#else + UnicodeString us; + ICalComponent::getStringValue(((ICalProperty **) &m_Location), us); + return us; +#endif +} +//--------------------------------------------------------------------- +//PercentComplete +void VTodo::setPercentComplete(t_int32 i, JulianPtrArray * parameters) +{ +#if 1 + if (m_PercentComplete == 0) + m_PercentComplete = ICalPropertyFactory::Make(ICalProperty::INTEGER, + (void *) &i, parameters); + else + { + m_PercentComplete->setValue((void *) &i); + m_PercentComplete->setParameters(parameters); + } +#else + ICalComponent::setIntegerValue(((ICalProperty **) &m_PercentComplete), i, parameters); +#endif +} +t_int32 VTodo::getPercentComplete() const +{ +#if 1 + if (m_PercentComplete == 0) + return -1; + else + return *((t_int32 *) m_PercentComplete->getValue()); +#else + t_int32 i = -1; + ICalComponent::getIntegerValue(((ICalProperty **) &m_PercentComplete), i); + return i; +#endif +} +//--------------------------------------------------------------------- +//Priority +void VTodo::setPriority(t_int32 i, JulianPtrArray * parameters) +{ +#if 1 + if (m_Priority == 0) + m_Priority = ICalPropertyFactory::Make(ICalProperty::INTEGER, + (void *) &i, parameters); + else + { + m_Priority->setValue((void *) &i); + m_Priority->setParameters(parameters); + } +#else + ICalComponent::setIntegerValue(((ICalProperty **) &m_Priority), i, parameters); +#endif +} +t_int32 VTodo::getPriority() const +{ +#if 1 + if (m_Priority == 0) + return -1; + else + return *((t_int32 *) m_Priority->getValue()); +#else + t_int32 i = -1; + ICalComponent::getIntegerValue(((ICalProperty **) &m_Priority), i); + return i; +#endif +} +//--------------------------------------------------------------------- +// RESOURCES +void VTodo::addResources(UnicodeString s, JulianPtrArray * parameters) +{ + ICalProperty * prop = ICalPropertyFactory::Make(ICalProperty::TEXT, + (void *) &s, parameters); + addResourcesProperty(prop); +} + +//--------------------------------------------------------------------- + +void VTodo::addResourcesProperty(ICalProperty * prop) +{ + if (m_ResourcesVctr == 0) + m_ResourcesVctr = new JulianPtrArray(); + PR_ASSERT(m_ResourcesVctr != 0); + if (m_ResourcesVctr != 0) + { + m_ResourcesVctr->Add(prop); + } +} + +//--------------------------------------------------------------------- + +void +VTodo::addResourcesPropertyVector(UnicodeString & propVal, + JulianPtrArray * parameters) +{ + //ICalProperty * ip; + + //ip = ICalPropertyFactory::Make(ICalProperty::TEXT, new UnicodeString(propVal), + // parameters); + addResources(propVal, parameters); + //addResourcesProperty(ip); + + +#if 0 + // TODO: see TimeBasedEvent::addCategoriesPropertyVector() + + ErrorCode status = ZERO_ERROR; + UnicodeStringTokenizer * st; + UnicodeString us; + UnicodeString sDelim = JulianKeyword::Instance()->ms_sCOMMA_SYMBOL; + + st = new UnicodeStringTokenizer(propVal, sDelim); + //ICalProperty * ip; + while (st->hasMoreTokens()) + { + us = st->nextToken(us, status); + us.trim(); + //if (FALSE) TRACE("us = %s, status = %d", us.toCString(""), status); + // TODO: if us is in Resources range then add, else, log and error + addResourcesProperty(ICalPropertyFactory::Make(ICalProperty::TEXT, + new UnicodeString(us), parameters)); + } + delete st; st = 0; +#endif + +} +//--------------------------------------------------------------------- + diff --git a/calendar/modules/core/inc/JulianParser.h b/calendar/modules/core/inc/JulianParser.h new file mode 100644 index 00000000000..8d4407a716e --- /dev/null +++ b/calendar/modules/core/inc/JulianParser.h @@ -0,0 +1,90 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +/* + * jparser.h + * John Sun + * 4/28/98 10:45:21 AM + */ +#ifndef __NSQQnsCalStreamReader_H_ +#define __NSQQnsCalStreamReader_H_ + +#include "ptrarray.h" +#include "icalredr.h" +#include "nsCapiCallbackReader.h" +#include "jutility.h" +#include "nspr.h" + +/** + * This class will be removed later. It is a hack I created to + * parse the MIME-message from the CS&T server fetch results. + * I will try to extract the iCalendar information from it. + * I will need to handle multi-threaded parsing somehow as well. + */ +class nsCalStreamReader +{ +private: + /*char * m_Buffer;*/ + + static JulianUtility::MimeEncoding stringToEncodingType(UnicodeString & propVal); + + JulianPtrArray * m_OutCalendars; + nsCapiCallbackReader * m_Reader; + t_bool m_bParseStarted; + t_bool m_bParseFinished; + PRThread * m_Thread; + +public: + nsCalStreamReader(); + nsCalStreamReader(nsCapiCallbackReader * reader, JulianPtrArray * outCalendars, + PRThread * thread); + /* + void setBuffer(char * buf) + { + strcat(m_Buffer, buf); + } + */ + + t_bool isParseStarted() const { return m_bParseStarted; } + void setParseStarted() { m_bParseStarted = TRUE; } + + t_bool isParseFinished() const { return m_bParseFinished; } + void setParseFinished() { m_bParseFinished = TRUE; } + + nsCapiCallbackReader * getReader() const { return m_Reader; } + PRThread * getThread() const { return m_Thread; } + + void ParseCalendars(ICalReader * reader, + JulianPtrArray * outCalendars); + + void ParseCalendars(); + +}; + +#ifdef XP_CPLUSPLUS +extern "C"{ +#endif + + void jparser_ParseCalendarsZero(void * jp, void *); + +#ifdef XP_CPLUSPLUS +}; +#endif + +#endif /* __NSQQnsCalStreamReader_H_ */ + diff --git a/calendar/modules/core/inc/manifest.mn b/calendar/modules/core/inc/manifest.mn index f272759b0af..849c6db2664 100644 --- a/calendar/modules/core/inc/manifest.mn +++ b/calendar/modules/core/inc/manifest.mn @@ -26,6 +26,9 @@ PRIVATE_EXPORTS = \ nsCalUserList.h \ nsCalendarUser.h \ nsCalendarModel.h \ + nsCapiCallbackReader.h \ + nsCalStreamReader.h \ + JulianParser.h \ $(NULL) MODULE = trex diff --git a/calendar/modules/core/inc/nsCalStreamReader.h b/calendar/modules/core/inc/nsCalStreamReader.h new file mode 100644 index 00000000000..a6af9cfc8fe --- /dev/null +++ b/calendar/modules/core/inc/nsCalStreamReader.h @@ -0,0 +1,86 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +#ifndef __NSQQnsCalStreamReader_H_ +#define __NSQQnsCalStreamReader_H_ + +#include "nscapiexport.h" +#include "ptrarray.h" +#include "icalredr.h" +#include "nsCapiCallbackReader.h" +#include "jutility.h" +#include "nspr.h" +#include "nscalexport.h" + +/** + * This class will be removed later. It is a hack I created to + * parse the MIME-message from the CS&T server fetch results. + * I will try to extract the iCalendar information from it. + * I will need to handle multi-threaded parsing somehow as well. + */ +class NS_CALENDAR nsCalStreamReader +{ +private: + static JulianUtility::MimeEncoding stringToEncodingType(UnicodeString & propVal); + + + /* dont deallocate these */ + JulianPtrArray * m_OutCalendars; + nsCapiCallbackReader * m_Reader; + t_bool m_bParseStarted; + t_bool m_bParseFinished; + PRThread * m_Thread; + void * m_CallerData; + +public: + nsCalStreamReader(); + ~nsCalStreamReader(); + nsCalStreamReader( + nsCapiCallbackReader * reader, + JulianPtrArray * outCalendars, + PRThread * thread, + void* condvar); + t_bool isParseStarted() const { return m_bParseStarted; } + void setParseStarted() { m_bParseStarted = TRUE; } + + t_bool isParseFinished() const { return m_bParseFinished; } + void setParseFinished() { m_bParseFinished = TRUE; } + + nsCapiCallbackReader * getReader() const { return m_Reader; } + PRThread * getThread() const { return m_Thread; } + void * getCallerData() const { return m_CallerData; } + + void ParseCalendars( + ICalReader * reader, + JulianPtrArray * outCalendars); + + void ParseCalendars(); +}; + +#ifdef XP_CPLUSPLUS +extern "C"{ +#endif + + void NS_CAPIEXPORT main_CalStreamReader(void * jp); + +#ifdef XP_CPLUSPLUS +}; +#endif + +#endif /* __NSQQnsCalStreamReader_H_ */ + diff --git a/calendar/modules/core/inc/nsCapiCallbackReader.h b/calendar/modules/core/inc/nsCapiCallbackReader.h new file mode 100644 index 00000000000..ef748063ef1 --- /dev/null +++ b/calendar/modules/core/inc/nsCapiCallbackReader.h @@ -0,0 +1,170 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +/* + * capiredr.h + * John Sun + * 4/16/98 3:31:51 PM + */ +#ifndef __NSQQnsCapiCallbackReader_H_ +#define __NSQQnsCapiCallbackReader_H_ + +#include "nscapiexport.h" +#include "jdefines.h" +#include +#include "ptrarray.h" +#include "icalredr.h" +#include "prmon.h" +#include "jutility.h" +#include "nscalexport.h" + +/** + * nsCapiBufferStruct is contains the data passed in by the callback in CAPI. + * This struct encapsulates the data in m_pBuf, + * and the size of the passed in data in m_pBufSize. + */ +class NS_CALENDAR nsCapiBufferStruct +{ +public: + char * m_pBuf; + size_t m_pBufSize; +}; + +/** + * nsCapiCallbackReader is a subclass of ICalReader. It implements + * the ICalReader interface to work with CAPI callback method + * to parse from stream. + * Uses multiple threads. + */ +class NS_CALENDAR nsCapiCallbackReader +{ +private: + /*----------------------------- + ** MEMBERS + **---------------------------*/ + + /* current buffer of iCal information, + * when CAPI has information to return to + * the buffer, it must append to this buffer + * when no more full-lines can be made from the + * buffer, block on the monitor. Will be + * notified when CAPI gets back more information + */ + char * m_Buffer; + + t_int32 m_BufferSize; + t_bool m_Init; + t_int32 m_Mark; + t_int32 m_ChunkMark; + t_int32 m_Pos; + t_int32 m_ChunkIndex; + + + /** encoding of stream */ + JulianUtility::MimeEncoding m_Encoding; + + /** need to deallocate */ + JulianPtrArray * m_Chunks; + + static const t_int32 m_MAXBUFFERSIZE; + static const t_int32 m_NOMORECHUNKS; + + /* finished getting input from CAPI callback */ + t_bool m_bFinished; + + /** do not deallocate */ + PRMonitor * m_Monitor; + /*----------------------------- + ** PRIVATE METHODS + **---------------------------*/ + + UnicodeString & createLine(t_int32 oldPos, t_int32 oldChunkIndex, + t_int32 newPos, t_int32 newChunkIndex, UnicodeString & aLine); + + static void deleteCapiBufferStructVector(JulianPtrArray * bufferVector); + + nsCapiCallbackReader(); +public: + /*----------------------------- + ** CONSTRUCTORS and DESTRUCTORS + **---------------------------*/ + nsCapiCallbackReader(PRMonitor * monitor, + JulianUtility::MimeEncoding encoding = JulianUtility::MimeEncoding_7bit); + ~nsCapiCallbackReader(); + + /*----------------------------- + ** ACCESSORS (GET AND SET) + **---------------------------*/ + + virtual void * getMonitor() { return m_Monitor; } + + void setFinished() { m_bFinished = TRUE; } + void setEncoding(JulianUtility::MimeEncoding encoding) { m_Encoding = encoding; } + t_bool isFinished() const { return m_bFinished; } + + /** + * Don't delete u until this object is deleted. + * @param nsCapiBufferStruct * cBuf + * + * @return void + */ + void AddBuffer(nsCapiBufferStruct * cBuf); + /*----------------------------- + ** UTILITIES + **---------------------------*/ + + void mark() { m_Mark = m_Pos; m_ChunkMark = m_ChunkIndex;} + + void reset() { m_Pos = m_Mark; m_ChunkIndex = m_ChunkMark; m_Mark = -1; m_ChunkMark = -1; } + + /** + * Read next character from file. + * + * @param status, return 1 if no more characters + * @return next character of string + */ + virtual t_int8 read(ErrorCode & status); + + /** + * Read the next ICAL full line of the file. The definition + * of a full ICAL line can be found in the ICAL spec. + * Basically, a line followed by a CRLF and a space character + * signifies that the next line is a continuation of the previous line. + * Uses the readLine, read methods. + * + * @param aLine, returns next full line of string + * @param status, return 1 if no more lines + * + * @return next full line of string + */ + virtual UnicodeString & readFullLine(UnicodeString & aLine, ErrorCode & status, t_int32 i = 0); + + /** + * Read next line of file. A line is defined to be + * characters terminated by either a '\n', '\r' or "\r\n". + * @param aLine, return next line of string + * @param status, return 1 if no more lines + * + * @return next line of string + */ + virtual UnicodeString & readLine(UnicodeString & aLine, ErrorCode & status); + +}; + +#endif /* __NSQQnsCapiCallbackReader_H_ */ + diff --git a/calendar/modules/core/manifest.mn b/calendar/modules/core/manifest.mn index 8e4420ee209..e69de29bb2d 100644 --- a/calendar/modules/core/manifest.mn +++ b/calendar/modules/core/manifest.mn @@ -1,15 +0,0 @@ -# -# CONFIDENTIAL AND PROPRIETARY SOURCE CODE OF -# NETSCAPE COMMUNICATIONS CORPORATION -# Copyright (C) 1996 Netscape Communications Corporation. All Rights -# Reserved. Use of this Source Code is subject to the terms of the -# applicable license agreement from Netscape Communications Corporation. -# The copyright notice(s) in this Source Code does not indicate actual or -# intended publication of this Source Code. -# -GDEPTH = ../../.. -DEPTH = ../../.. - -DIRS_EXPORT = public inc -DIRS_LIBS = src - diff --git a/calendar/modules/core/src/config.mk b/calendar/modules/core/src/config.mk index 927b6fc756b..e69de29bb2d 100644 --- a/calendar/modules/core/src/config.mk +++ b/calendar/modules/core/src/config.mk @@ -1,33 +0,0 @@ -# -# CONFIDENTIAL AND PROPRIETARY SOURCE CODE OF -# NETSCAPE COMMUNICATIONS CORPORATION -# Copyright © 1996, 1997 Netscape Communications Corporation. All Rights -# Reserved. Use of this Source Code is subject to the terms of the -# applicable license agreement from Netscape Communications Corporation. -# The copyright notice(s) in this Source Code does not indicate actual or -# intended publication of this Source Code. -# - -# -# Override TARGETS variable so that only static libraries -# are specifed as dependencies within rules.mk. -# - -CFLAGS +=-D_IMPL_NS_CALENDAR -DNSPR20 -I$(GDEPTH)/include - -LD_LIBS += \ - raptorbase \ - raptorhtmlpars \ - $(NATIVE_JULIAN_DLL) \ - xpcom$(MOZ_BITS) \ - $(NATIVE_LIBNLS_LIBS) \ - $(NATIVE_RAPTOR_WIDGET) \ - calcapi10 \ - util10 \ - xpcom$(MOZ_BITS) \ - $(XP_REG_LIB) - -LIBRARY_NAME = calcore -LIBRARY_VERSION = 10 - -EXTRA_LIBS += $(NSPR_LIBS) diff --git a/calendar/modules/core/src/manifest.mn b/calendar/modules/core/src/manifest.mn index c663631d9cd..596dd62a94e 100644 --- a/calendar/modules/core/src/manifest.mn +++ b/calendar/modules/core/src/manifest.mn @@ -30,6 +30,8 @@ CPPSRCS = \ nsCoreFactory.cpp \ nsCalendarUser.cpp \ nsCalendarModel.cpp \ + nsCalStreamReader.cpp \ + nsCapiCallbackReader.cpp \ $(NULL) diff --git a/calendar/modules/core/src/nsCalStreamReader.cpp b/calendar/modules/core/src/nsCalStreamReader.cpp new file mode 100644 index 00000000000..3c637c54561 --- /dev/null +++ b/calendar/modules/core/src/nsCalStreamReader.cpp @@ -0,0 +1,211 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + + +#include "jdefines.h" + +#include +#include "nsCalStreamReader.h" +#include "prprty.h" +#include "tmbevent.h" +#include "nscal.h" +#include "jlog.h" +#include "keyword.h" +#include "icalsrdr.h" + +#include "nspr.h" + +//--------------------------------------------------------------------- + +nsCalStreamReader::nsCalStreamReader() +{ + m_Reader = 0; + m_OutCalendars = 0; + m_Thread = 0; + m_CallerData = 0; + m_bParseStarted = FALSE; + m_bParseFinished = FALSE; +} + +//--------------------------------------------------------------------- + +nsCalStreamReader::~nsCalStreamReader() +{ +} + +//--------------------------------------------------------------------- + +nsCalStreamReader::nsCalStreamReader(nsCapiCallbackReader * reader, + JulianPtrArray * outCalendars, + PRThread * thread, void* condVar) +{ + m_Reader = reader; + m_OutCalendars = outCalendars; + m_Thread = thread; + m_CallerData = condVar; + m_bParseStarted = FALSE; + m_bParseFinished = FALSE; +} + +//--------------------------------------------------------------------- + +JulianUtility::MimeEncoding +nsCalStreamReader::stringToEncodingType(UnicodeString & propVal) +{ + if (propVal.compareIgnoreCase(JulianKeyword::Instance()->ms_s7bit) == 0) + { + return JulianUtility::MimeEncoding_7bit; + } + else if (propVal.compareIgnoreCase(JulianKeyword::Instance()->ms_sQUOTED_PRINTABLE) == 0) + { + return JulianUtility::MimeEncoding_QuotedPrintable; + } + else if (propVal.compareIgnoreCase(JulianKeyword::Instance()->ms_sBase64) == 0) + { + return JulianUtility::MimeEncoding_Base64; + } + else + return JulianUtility::MimeEncoding_7bit; +} + +//--------------------------------------------------------------------- + +void nsCalStreamReader::ParseCalendars() +{ + nsCalStreamReader::ParseCalendars((ICalReader *) m_Reader, m_OutCalendars); +} + +//--------------------------------------------------------------------- + +void nsCalStreamReader::ParseCalendars(ICalReader * reader, + JulianPtrArray * outCalendars) +{ + if (outCalendars == 0) + return; + + JulianPtrArray * parameters = new JulianPtrArray(); + + // TODO: this needs to be changed to capireader later + PR_ASSERT(parameters != 0); + if (parameters != 0) + { + JLog * log = 0; + ErrorCode status = ZERO_ERROR; + UnicodeString strLine, propName, propVal; + JulianUtility::MimeEncoding encoding = JulianUtility::MimeEncoding_7bit; + + nsCapiCallbackReader * cr = (nsCapiCallbackReader *) reader; + + while(TRUE) + { + cr->readFullLine(strLine, status); + ICalProperty::Trim(strLine); + +#if TESTING_ITIPRIG + if (FALSE) TRACE("\t--Parser: line (size = %d) = ---%s---\r\n", + strLine.size(), strLine.toCString("")); +#endif + if (FAILURE(status) && strLine.size() == 0) + { + //PR_Notify((PRMonitor *) cr->getMonitor()); + if (cr->isFinished()) + { + break; + } +#if TESTING_ITIPRIG + if (FALSE) TRACE("\t--jParser: yielding\r\n"); +#endif + PR_Sleep(PR_INTERVAL_NO_WAIT); + //break; + } + + ICalProperty::parsePropertyLine(strLine, propName, + propVal, parameters); + +#if TESTING_ITIPRIG + if (TRUE) TRACE("\t--Parser: propName = --%s--, propVal = --%s--,paramSize = %d\r\n", + propName.toCString(""), propVal.toCString(""), parameters->GetSize()); +#endif + if ((propName.compareIgnoreCase(JulianKeyword::Instance()->ms_sBEGIN) == 0) && + (propVal.compareIgnoreCase(JulianKeyword::Instance()->ms_sVCALENDAR) == 0)) + { + // parse an NSCalendar, add it to outCalendars + NSCalendar * cal = new NSCalendar(log); + UnicodeString fileName; + cal->parse(reader, fileName, encoding); + outCalendars->Add(cal); + } + else if (propName.compareIgnoreCase( + JulianKeyword::Instance()->ms_sCONTENT_TRANSFER_ENCODING) == 0) + { + ICalProperty::Trim(propVal); + encoding = stringToEncodingType(propVal); + cr->setEncoding(encoding); + } + ICalProperty::deleteICalParameterVector(parameters); + parameters->RemoveAll(); + + //PR_ExitMonitor((PRMonitor *)cr->getMonitor()); + } + + ICalProperty::deleteICalParameterVector(parameters); + parameters->RemoveAll(); + delete parameters; parameters = 0; + setParseFinished(); + } +} +//--------------------------------------------------------------------- + +void main_CalStreamReader(void* p) +{ + /* + * We've been started. We must wait until our parent thread + * signals to begin working... + */ + nsCalStreamReader * pStreamReader = (nsCalStreamReader *) p; + PRMonitor * pMon = (PRMonitor*)pStreamReader->getCallerData(); + PR_EnterMonitor(pMon); /* wait until the other thread releases this */ + PR_ExitMonitor(pMon); /* now that we've got it, let both threads run */ + + /* + * We only enter the Monitor when the parent has exited it. So, + * our parent thread has signaled us to begin the work at hand. + */ + pStreamReader->ParseCalendars(); + + /* + * The parent will try to re-enter the monitor when it is waiting for + * this thread to complete parsing the calendars. + */ + PR_EnterMonitor(pMon); + pStreamReader->setParseFinished(); + PR_Notify(pMon); + PR_ExitMonitor(pMon); + + /* + * We're done. + */ +#if 0 + PR_ProcessExit(0); +#endif +} + +//--------------------------------------------------------------------- + + + diff --git a/calendar/modules/core/src/nsCapiCallbackReader.cpp b/calendar/modules/core/src/nsCapiCallbackReader.cpp new file mode 100644 index 00000000000..be00ff732c8 --- /dev/null +++ b/calendar/modules/core/src/nsCapiCallbackReader.cpp @@ -0,0 +1,401 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ +#include "nsCapiCallbackReader.h" +#include "nspr.h" + +const t_int32 nsCapiCallbackReader::m_MAXBUFFERSIZE = 1024; +const t_int32 nsCapiCallbackReader::m_NOMORECHUNKS = 404; +//--------------------------------------------------------------------- +nsCapiCallbackReader::nsCapiCallbackReader() +{ + PR_ASSERT(FALSE); +} +//--------------------------------------------------------------------- + +void +nsCapiCallbackReader::AddBuffer(nsCapiBufferStruct * cBuf) +{ + if (m_Chunks == 0) + m_Chunks = new JulianPtrArray(); + PR_ASSERT(m_Chunks != 0); + if (m_Chunks != 0) + { + m_Chunks->Add(cBuf); + } +} + +//--------------------------------------------------------------------- + +nsCapiCallbackReader::nsCapiCallbackReader(PRMonitor * monitor, + JulianUtility::MimeEncoding encoding) +{ + m_Monitor = monitor; + m_bFinished = FALSE; + + m_ChunkIndex = 0; + m_Chunks = 0; + m_Init = TRUE; + m_Pos = 0; + m_Mark = -1; + m_ChunkMark = -1; + m_Encoding = encoding; +} + +//--------------------------------------------------------------------- + +void nsCapiCallbackReader::deleteCapiBufferStructVector(JulianPtrArray * bufferVector) +{ + t_int32 i; + if (bufferVector != 0) + { + nsCapiBufferStruct * cbBuf; + for (i = bufferVector->GetSize() - 1; i >= 0; i--) + { + cbBuf = (nsCapiBufferStruct *) bufferVector->GetAt(i); + if (0 != cbBuf->m_pBuf) + { + delete [] (cbBuf->m_pBuf); + cbBuf->m_pBuf = 0; + } + delete cbBuf; cbBuf = 0; + } + } +} + +//--------------------------------------------------------------------- + +nsCapiCallbackReader::~nsCapiCallbackReader() +{ + if (m_Chunks != 0) + { + deleteCapiBufferStructVector(m_Chunks); + delete m_Chunks; m_Chunks = 0; + } +} + +//--------------------------------------------------------------------- + +t_int8 nsCapiCallbackReader::read(ErrorCode & status) +{ + t_int32 i = 0; + status = ZERO_ERROR; + + while (TRUE) + { + if (m_Chunks == 0 || m_Chunks->GetSize() == 0 || + m_ChunkIndex >= m_Chunks->GetSize()) + { + status = m_NOMORECHUNKS; // no more chunks, should block + return -1; + } + else + { + // read from linked list of UnicodeString's + // delete front string when finished reading from it + + nsCapiBufferStruct * cbBuf = (nsCapiBufferStruct *) m_Chunks->GetAt(m_ChunkIndex); + char * buf = cbBuf->m_pBuf; + char c; + if ((size_t) m_Pos < cbBuf->m_pBufSize) + { + if (JulianUtility::MimeEncoding_QuotedPrintable == m_Encoding) + { + char * buf = cbBuf->m_pBuf; + c = buf[m_Pos]; + if ('=' == c) + { + if (cbBuf->m_pBufSize >= (size_t) (m_Pos + 3)) + { + if (ICalReader::isHex(buf[m_Pos + 1]) && ICalReader::isHex(buf[m_Pos + 2])) + { + c = ICalReader::convertHex(buf[m_Pos + 1], buf[m_Pos + 2]); + m_Pos += 3; + return c; + } + else + { + return (t_int8) buf[m_Pos++]; + } + } + else + { + PRInt32 lenDiff = cbBuf->m_pBufSize - m_Pos; + char fToken, sToken; + PRBool bSetFToken = FALSE; + PRInt32 tempIndex = m_ChunkIndex; + UnicodeString token; + + while (TRUE) + { + // lenDiff = 1, 2 always + // the =XX spans different chunks + // if last chunk, return out of chunks status + if (tempIndex == m_Chunks->GetSize() - 1) + { + status = m_NOMORECHUNKS; + return -1; + } + else + { + nsCapiBufferStruct * cbNextBuf = (nsCapiBufferStruct *) m_Chunks->GetAt(tempIndex + 1); + char * nextBuf = cbNextBuf->m_pBuf; + tempIndex++; + if (cbNextBuf->m_pBufSize >= 2) + { + if (lenDiff == 2) + { + fToken = buf[cbBuf->m_pBufSize - 1]; + sToken = nextBuf[0]; + if (ICalReader::isHex(fToken) && ICalReader::isHex(sToken)) + { + c = ICalReader::convertHex(fToken, sToken); + + m_Pos = 1; + m_ChunkIndex = tempIndex; + bSetFToken = FALSE; + return c; + } + else + { + return (t_int8) buf[m_Pos++]; + } + } + else + { + // lenDiff = 1 + if (bSetFToken) + { + sToken = nextBuf[0]; + } + else + { + fToken = nextBuf[0]; + sToken = nextBuf[1]; + } + if (ICalReader::isHex(fToken) && ICalReader::isHex(sToken)) + { + c = ICalReader::convertHex(fToken, sToken); + + m_Pos = 2; + m_ChunkIndex = tempIndex; + bSetFToken = FALSE; + return c; + } + else + { + return (t_int8) buf[m_Pos++]; + } + } + } + else + { + if (cbNextBuf->m_pBufSize > 0) + { + if (!bSetFToken) + { + fToken = nextBuf[0]; + bSetFToken = TRUE; + } + else + { + sToken = nextBuf[0]; + if (ICalReader::isHex(fToken) && ICalReader::isHex(sToken)) + { + c = ICalReader::convertHex(fToken, sToken); + + m_Pos = 1; + m_ChunkIndex = tempIndex; + bSetFToken = FALSE; + return c; + } + else + { + return (t_int8) buf[m_Pos++]; + } + } + } + } + } + } + } + } + else + { + return (t_int8) buf[m_Pos++]; + } + } + else + { + return (t_int8) buf[m_Pos++]; + } + } + else + { + m_ChunkIndex++; + m_Pos = 0; + } + } + } + status = 1; + return -1; +} + +//--------------------------------------------------------------------- + +UnicodeString & +nsCapiCallbackReader::createLine(t_int32 oldPos, t_int32 oldChunkIndex, + t_int32 newPos, t_int32 newChunkIndex, + UnicodeString & aLine) +{ + PR_ASSERT(oldChunkIndex <= newChunkIndex); + UnicodeString u; + if (oldChunkIndex == newChunkIndex) + { + u = *((UnicodeString *) m_Chunks->GetAt(oldChunkIndex)); + u.extractBetween(oldPos, newPos, aLine); + return aLine; + } + else { + //(oldChunkIndex < newChunkIndex) + + t_int32 i; + UnicodeString v, temp; + u = *((UnicodeString *) m_Chunks->GetAt(oldChunkIndex)); + u.extractBetween(oldPos, u.size(), aLine); + v = *((UnicodeString *) m_Chunks->GetAt(newChunkIndex)); + v.extractBetween(0, newPos, temp); + i = oldChunkIndex + 1; + while (i < newChunkIndex) + { + v = *((UnicodeString *) m_Chunks->GetAt(i)); + aLine += v; + i++; + } + aLine += temp; + return aLine; + } +} +//--------------------------------------------------------------------- +UnicodeString & +nsCapiCallbackReader::readFullLine(UnicodeString & aLine, ErrorCode & status, t_int32 iTemp) +{ + status = ZERO_ERROR; + t_int32 i; + + PR_EnterMonitor(m_Monitor); + + t_int32 oldpos = m_Pos; + t_int32 oldChunkIndex = m_ChunkIndex; + + readLine(aLine, status); + if (status == m_NOMORECHUNKS) + { + if (m_bFinished) + { + // do nothing. + } + else + { + PR_Wait(m_Monitor,PR_INTERVAL_NO_TIMEOUT); + } + } + + UnicodeString aSubLine; + while (TRUE) + { + mark(); + i = read(status); + if (status == m_NOMORECHUNKS) + { + if (m_bFinished) + { + // do nothing + break; + } + else + { + PR_Wait(m_Monitor,PR_INTERVAL_NO_TIMEOUT); + } + } + else if (i == ' ') + { + aLine += readLine(aSubLine, status); + } + else + { + reset(); + break; + } + } + + PR_ExitMonitor(m_Monitor); + + return aLine; +} +//--------------------------------------------------------------------- +UnicodeString & +nsCapiCallbackReader::readLine(UnicodeString & aLine, ErrorCode & status) +{ + aLine = ""; + + if (m_Chunks == 0 || m_Chunks->GetSize() == 0 || + m_ChunkIndex >= m_Chunks->GetSize()) + { + status = m_NOMORECHUNKS; // no more chunks, should block + return aLine; + } + else + { + nsCapiBufferStruct * cbBuf = + (nsCapiBufferStruct *) m_Chunks->GetAt(m_ChunkIndex); + char * currentBuf = cbBuf->m_pBuf; + char * line = 0; + PRInt32 i; + t_bool bFoundNewLine = FALSE; + for (i = m_Pos; 0 != currentBuf[i] && + ((size_t) i < cbBuf->m_pBufSize); i++) + { + if ('\n' == currentBuf[i]) + { + currentBuf[i] = 0; + bFoundNewLine = TRUE; + break; + } + } + if (!bFoundNewLine) + { + // todo: mark this chunk needs to be saved + if (m_ChunkIndex < m_Chunks->GetSize() - 1) + { + m_ChunkIndex++; + m_Pos = 0; + } + //else + //{ + // status = m_NOMORECHUNKS; + //} + return aLine; + } + line = currentBuf + m_Pos; + m_Pos = i + 1; + aLine = line; + return aLine; + } +} +//--------------------------------------------------------------------- + diff --git a/calendar/modules/network/capi/config.mk b/calendar/modules/network/capi/config.mk index da311865cf6..99aea57be04 100644 --- a/calendar/modules/network/capi/config.mk +++ b/calendar/modules/network/capi/config.mk @@ -18,7 +18,6 @@ CFLAGS +=-D_IMPL_NS_CALENDAR LD_LIBS += \ raptorbase \ $(NATIVE_RAPTOR_WIDGET) \ - $(NATIVE_JULIAN_DLL) \ xpcom$(MOZ_BITS) \ $(NATIVE_LIBNLS_LIBS) \ util10 \ diff --git a/calendar/modules/network/capi/inc/manifest.mn b/calendar/modules/network/capi/inc/manifest.mn index 56888e654ae..e69de29bb2d 100644 --- a/calendar/modules/network/capi/inc/manifest.mn +++ b/calendar/modules/network/capi/inc/manifest.mn @@ -1,26 +0,0 @@ -# -# CONFIDENTIAL AND PROPRIETARY SOURCE CODE OF -# NETSCAPE COMMUNICATIONS CORPORATION -# Copyright (C) 1996 Netscape Communications Corporation. All Rights -# Reserved. Use of this Source Code is subject to the terms of the -# applicable license agreement from Netscape Communications Corporation. -# The copyright notice(s) in this Source Code does not indicate actual or -# intended publication of this Source Code. -# -GDEPTH = ../../../../.. - -EXPORTS = \ - $(NULL) - -PRIVATE_EXPORTS = \ - nsCapiLocal.h \ - nsCapiCST.h \ - JulianParser.h \ - nsCalStreamReader.h \ - nsCapiCallbackReader.h \ - nscapiexport.h \ - $(NULL) - -MODULE = trex - -REQUIRES = raptor diff --git a/calendar/modules/network/capi/local/src/config.mk b/calendar/modules/network/capi/local/src/config.mk index b372cbf9d18..e69de29bb2d 100644 --- a/calendar/modules/network/capi/local/src/config.mk +++ b/calendar/modules/network/capi/local/src/config.mk @@ -1,26 +0,0 @@ -# -# CONFIDENTIAL AND PROPRIETARY SOURCE CODE OF -# NETSCAPE COMMUNICATIONS CORPORATION -# Copyright © 1996, 1997 Netscape Communications Corporation. All Rights -# Reserved. Use of this Source Code is subject to the terms of the -# applicable license agreement from Netscape Communications Corporation. -# The copyright notice(s) in this Source Code does not indicate actual or -# intended publication of this Source Code. -# - -# -# Override TARGETS variable so that only static libraries -# are specifed as dependencies within rules.mk. -# - -CFLAGS +=-D_IMPL_NS_CALENDAR -DNSPR20 -DNLS_DEFINE_STANDARD_TYPES=1 -INCLUDES += -I../inc -I$(GDEPTH)/include - - -LD_LIBS += \ - $(NATIVE_JULIAN_DLL) \ - $(NATIVE_LIBNLS_LIBS) \ - util10 - -EXTRA_LIBS += $(NSPR_LIBS) - diff --git a/calendar/modules/network/capi/manifest.mn b/calendar/modules/network/capi/manifest.mn index 8ce6701d9ee..e69de29bb2d 100644 --- a/calendar/modules/network/capi/manifest.mn +++ b/calendar/modules/network/capi/manifest.mn @@ -1,30 +0,0 @@ -# -# CONFIDENTIAL AND PROPRIETARY SOURCE CODE OF -# NETSCAPE COMMUNICATIONS CORPORATION -# Copyright (C) 1996 Netscape Communications Corporation. All Rights -# Reserved. Use of this Source Code is subject to the terms of the -# applicable license agreement from Netscape Communications Corporation. -# The copyright notice(s) in this Source Code does not indicate actual or -# intended publication of this Source Code. -# -GDEPTH = ../../../.. -DEPTH = ../../../.. - -DIRS = cst local core -DIRS_EXPORT = public inc -DIRS_LIBS = src - -LIBRARY_NAME = calcapi - -EXPORTS = \ - $(NULL) - -PRIVATE_EXPORTS = \ - $(NULL) - - -MODULE = trex - -REQUIRES = xpcom raptor shell trex - - diff --git a/calendar/modules/network/capi/src/manifest.mn b/calendar/modules/network/capi/src/manifest.mn index fb8c4f85dd8..e69de29bb2d 100644 --- a/calendar/modules/network/capi/src/manifest.mn +++ b/calendar/modules/network/capi/src/manifest.mn @@ -1,28 +0,0 @@ -# -# CONFIDENTIAL AND PROPRIETARY SOURCE CODE OF -# NETSCAPE COMMUNICATIONS CORPORATION -# Copyright (C) 1996 Netscape Communications Corporation. All Rights -# Reserved. Use of this Source Code is subject to the terms of the -# applicable license agreement from Netscape Communications Corporation. -# The copyright notice(s) in this Source Code does not indicate actual or -# intended publication of this Source Code. -# -GDEPTH = ../../../../.. - -EXPORTS = \ - $(NULL) - -PRIVATE_EXPORTS = \ - $(NULL) - -MODULE = trex - -CPPSRCS = \ - nsCapiLocal.cpp \ - nsCapiCST.cpp \ - nsCalStreamReader.cpp \ - nsCapiCallbackReader.cpp \ - $(NULL) - -REQUIRES = raptor xpcom trex julian nls - diff --git a/calendar/modules/network/config.mk b/calendar/modules/network/config.mk index 75532c2a988..e69de29bb2d 100644 --- a/calendar/modules/network/config.mk +++ b/calendar/modules/network/config.mk @@ -1,32 +0,0 @@ -# -# CONFIDENTIAL AND PROPRIETARY SOURCE CODE OF -# NETSCAPE COMMUNICATIONS CORPORATION -# Copyright © 1996, 1997 Netscape Communications Corporation. All Rights -# Reserved. Use of this Source Code is subject to the terms of the -# applicable license agreement from Netscape Communications Corporation. -# The copyright notice(s) in this Source Code does not indicate actual or -# intended publication of this Source Code. -# - -# -# Override TARGETS variable so that only static libraries -# are specifed as dependencies within rules.mk. -# - -CFLAGS +=-D_IMPL_NS_CALENDAR - -LD_LIBS += \ - raptorbase \ - $(NATIVE_RAPTOR_WIDGET) \ - $(NATIVE_JULIAN_DLL) \ - xpcom$(MOZ_BITS) \ - $(NATIVE_LIBNLS_LIBS) \ - util10 \ - $(XP_REG_LIB) - -AR_LIBS += \ - stream \ - $(NULL) - -EXTRA_LIBS += $(NSPR_LIBS) - diff --git a/calendar/modules/network/itip/Makefile b/calendar/modules/network/itip/Makefile new file mode 100644 index 00000000000..e69de29bb2d diff --git a/calendar/modules/network/itip/inc/Makefile b/calendar/modules/network/itip/inc/Makefile new file mode 100644 index 00000000000..e69de29bb2d diff --git a/calendar/modules/network/itip/inc/detxnobj.h b/calendar/modules/network/itip/inc/detxnobj.h new file mode 100644 index 00000000000..fb5fc2fc23d --- /dev/null +++ b/calendar/modules/network/itip/inc/detxnobj.h @@ -0,0 +1,88 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +/* + * detxnobj.h + * John Sun + * 4/13/98 11:05:55 AM + */ +#ifndef __DELETETRANSACTIONOBJECT_H_ +#define __DELETETRANSACTIONOBJECT_H_ + +#include "jdefines.h" +#include "txnobj.h" + +class DeleteTransactionObject : public TransactionObject +{ +private: + /*----------------------------- + ** MEMBERS + **---------------------------*/ + /*----------------------------- + ** PRIVATE METHODS + **---------------------------*/ + DeleteTransactionObject(); +public: + /*----------------------------- + ** CONSTRUCTORS and DESTRUCTORS + **---------------------------*/ + DeleteTransactionObject(NSCalendar & cal, JulianPtrArray & components, + User & user, JulianPtrArray & recipients, + UnicodeString & subject, JulianPtrArray & modifiers, + JulianForm * jf, MWContext * context, + UnicodeString & attendeeName); + + virtual ~DeleteTransactionObject() {} + /*----------------------------- + ** ACCESSORS (GET AND SET) + **---------------------------*/ + virtual ETxnType GetType() const { return TransactionObject::ETxnType_DELETE; } + /*----------------------------- + ** UTILITIES + **---------------------------*/ +#if CAPI_READY + /* older CAPI, TODO: remove later */ + virtual CAPIStatus handleCAPI(CAPISession & pS, CAPIHandle * pH, + t_int32 iHandleCount, t_int32 lFlags, + JulianPtrArray * inComponents, NSCalendar * inCal, + JulianPtrArray * modifiers, + JulianPtrArray * outCalendars, TransactionObject::EFetchType & out); + /* + virtual CAPIStatus handleCAPI(CAPISession & pS, CAPIHandle * pH, + t_int32 iHandleCount, t_int32 lFlags, + JulianPtrArray * modifiers, JulianPtrArray * outCalendars, + TransactionObject::EFetchType & out); + */ + + /* TODO: more recent CAPI version */ + /*virtual CAPIStatus executeCAPI(CAPISession * s, CAPIHandle ** ppH, + t_int32 iHandleCount, long lFlags, JulianPtrArray * modifiers, + JulianPtrArray * propList, CAPIStream * stream);*/ + + +#endif /* #if CAPI_READY */ + /*----------------------------- + ** STATIC METHODS + **---------------------------*/ + /*----------------------------- + ** OVERLOADED OPERATORS + **---------------------------*/ +}; + +#endif /* __DELETETRANSACTIONOBJECT_H_ */ + diff --git a/calendar/modules/network/itip/inc/getxnobj.h b/calendar/modules/network/itip/inc/getxnobj.h new file mode 100644 index 00000000000..2a8f522d3e9 --- /dev/null +++ b/calendar/modules/network/itip/inc/getxnobj.h @@ -0,0 +1,121 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +/* + * getxnobj.h + * John Sun + * 4/1/98 5:10:26 PM + */ +#ifndef __GETTRANSACTIONOBJECT_H_ +#define __GETTRANSACTIONOBJECT_H_ + +#include "jdefines.h" +#include "txnobj.h" +#include "nspr.h" + +class GetTransactionObject: public TransactionObject +{ +#if CAPI_READY + /* for debugging only */ +public: + CAPI_CTX myCtx; +#endif + +private: + /*----------------------------- + ** MEMBERS + **---------------------------*/ + /*----------------------------- + ** PRIVATE METHODS + **---------------------------*/ + GetTransactionObject(); + +public: + /*----------------------------- + ** CONSTRUCTORS and DESTRUCTORS + **---------------------------*/ + GetTransactionObject(NSCalendar & cal, JulianPtrArray & components, + User & user, JulianPtrArray & recipients, + UnicodeString & subject, JulianPtrArray & modifiers, + JulianForm * jf, MWContext * context, + UnicodeString & attendeeName, EFetchType type); + + virtual ~GetTransactionObject() {}; + /*----------------------------- + ** ACCESSORS (GET AND SET) + **---------------------------*/ + virtual ETxnType GetType() const { return TransactionObject::ETxnType_GET; } + + /*----------------------------- + ** UTILITIES + **---------------------------*/ +#if CAPI_READY + /* + int writeToCAPIReaderHelper(void * pData, char * pBuf, + int iSize, int * piTransferred); + */ + /* + int writeToCAPIReader(void * pData, char * pBuf, + int iSize, int * piTransferred); + */ + PRMonitor * m_Monitor; +#endif + /* virtual JulianPtrArray * executeCAPI(); */ +#if CAPI_READY + PRMonitor * getMonitor() { return m_Monitor; } + virtual CAPIStatus handleCAPI(CAPISession & pS, CAPIHandle * pH, + t_int32 iHandleCount, t_int32 lFlags, + JulianPtrArray * inComponents, NSCalendar * inCal, + JulianPtrArray * modifiers, + JulianPtrArray * outCalendars, TransactionObject::EFetchType & out); + + /* + virtual CAPIStatus handleCAPI(CAPISession & pS, CAPIHandle * pH, + JulianPtrArray * modifiers, char *** strings, char ** outevent, + t_int32 & numstrings, EFetchType & out); + */ + + /* TODO: more recent CAPI version*/ + /*virtual CAPIStatus executeCAPI(CAPISession * s, CAPIHandle ** ppH, + t_int32 iHandleCount, long lFlags, JulianPtrArray * modifiers, + JulianPtrArray * propList, CAPIStream * stream);*/ + +#endif /* #if CAPI_READY */ + /*----------------------------- + ** STATIC METHODS + **---------------------------*/ + /*----------------------------- + ** OVERLOADED OPERATORS + **---------------------------*/ +}; + +#ifdef XP_CPLUSPLUS +extern "C"{ +#endif + + int getransactionobj_writeToCAPIReader(void *, char *, size_t, size_t *); + +#ifdef XP_CPLUSPLUS +} +#endif + +#endif /* __GETTRANSACTIONNOBJECT_H_ */ + + + + diff --git a/calendar/modules/network/itip/inc/manifest.mn b/calendar/modules/network/itip/inc/manifest.mn new file mode 100644 index 00000000000..e69de29bb2d diff --git a/calendar/modules/network/itip/inc/stdafx.h b/calendar/modules/network/itip/inc/stdafx.h new file mode 100644 index 00000000000..e69de29bb2d diff --git a/calendar/modules/network/itip/inc/sttxnobj.h b/calendar/modules/network/itip/inc/sttxnobj.h new file mode 100644 index 00000000000..5bc63236370 --- /dev/null +++ b/calendar/modules/network/itip/inc/sttxnobj.h @@ -0,0 +1,88 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +/* + * sttxnobj.h + * John Sun + * 4/13/98 10:37:07 AM + */ +#ifndef __STORETRANSACTIONNOBJECT_H_ +#define __STORETRANSACTIONNOBJECT_H_ + +#include "jdefines.h" +#include "txnobj.h" + +class StoreTransactionObject : public TransactionObject +{ +private: + /*----------------------------- + ** MEMBERS + **---------------------------*/ +#if CAPI_READY + CAPI_CTX m_Ctx; +#endif + /*----------------------------- + ** PRIVATE METHODS + **---------------------------*/ + StoreTransactionObject(); +public: + /*----------------------------- + ** CONSTRUCTORS and DESTRUCTORS + **---------------------------*/ + StoreTransactionObject(NSCalendar & cal, JulianPtrArray & components, + User & user, JulianPtrArray & recipients, + UnicodeString & subject, JulianPtrArray & modifiers, + JulianForm * jf, MWContext * context, + UnicodeString & attendeeName); + + virtual ~StoreTransactionObject() {} + /*----------------------------- + ** ACCESSORS (GET AND SET) + **---------------------------*/ + virtual ETxnType GetType() const { return TransactionObject::ETxnType_STORE; } + /*----------------------------- + ** UTILITIES + **---------------------------*/ +#if CAPI_READY + virtual CAPIStatus handleCAPI(CAPISession & pS, CAPIHandle * pH, + t_int32 iHandleCount, t_int32 lFlags, + JulianPtrArray * inComponents, NSCalendar * inCal, + JulianPtrArray * modifiers, + JulianPtrArray * outCalendars, TransactionObject::EFetchType & out); + /* + virtual CAPIStatus handleCAPI(CAPISession & pS, CAPIHandle * pH, + JulianPtrArray * modifiers, char *** strings, char ** outevent, + t_int32 & numstrings, TransactionObject::EFetchType & out); + */ + /* TODO: more recent CAPI version*/ + /*virtual CAPIStatus executeCAPI(CAPISession * s, CAPIHandle ** ppH, + t_int32 iHandleCount, long lFlags, JulianPtrArray * modifiers, + JulianPtrArray * propList, CAPIStream * stream);*/ + + +#endif /* #if CAPI_READY */ + /*----------------------------- + ** STATIC METHODS + **---------------------------*/ + /*----------------------------- + ** OVERLOADED OPERATORS + **---------------------------*/ +}; + +#endif /* __STORETRANSACTIONNOBJECT_H_ */ + diff --git a/calendar/modules/network/itip/inc/txnengn.h b/calendar/modules/network/itip/inc/txnengn.h new file mode 100644 index 00000000000..e69de29bb2d diff --git a/calendar/modules/network/itip/inc/txnobj.h b/calendar/modules/network/itip/inc/txnobj.h new file mode 100644 index 00000000000..c702aed8766 --- /dev/null +++ b/calendar/modules/network/itip/inc/txnobj.h @@ -0,0 +1,330 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +/* + * txnobj.h + * John Sun + * 3/10/98 11:35:47 AM + */ + +#ifndef __TRANSOBJ_H_ +#define __TRANSOBJ_H_ + +#include "nscal.h" +#include "user.h" +#include "form.h" +/*#include "xp.h" +#include "form.h"*/ + +/*#ifdef XP_WIN +#ifndef CAPI_READY +#define CAPI_READY 1 +#endif +#endif*/ + +#if CAPI_READY +#include +#endif /* #if CAPI_READY */ + +#if CAPI_READY +typedef struct +{ + char * p; + int iSize; +} CAPI_CTX; +#endif + +class TransactionObject +{ +public: + enum EFetchType + { + EFetchType_UID = 0, + EFetchType_DateRange = 1, + EFetchType_AlarmRange = 2 + ,EFetchType_NONE = 3 + }; + + /** + * The allowable transport types. + * CAPI, IRIP, IMIP, and FCAPI (local file CAPI). + */ + enum ETransportType + { + ETransportType_CAPI = 0, + ETransportType_IRIP = 1, + ETransportType_IMIP = 2, + ETransportType_FCAPI = 3 + }; + +/* + enum ETXN_TYPE + { + TR_TYPE_CANCEL = 0, + TR_TYPE_COUNTER = 1, + TR_TYPE_DECLINECOUNTER = 2, + TR_TYPE_DELEGATE = 3, + TR_TYPE_FORWARD = 4, + TR_TYPE_GET = 5, + TR_TYPE_REFRESH = 6, + TR_TYPE_REPLY = 7, + TR_TYPE_REQUEST = 8, + TR_TYPE_PUBLISH = 9, + TR_TYPE_INVALID = -1 + }; +*/ + enum ETxnErrorCode + { + TR_OK = 0, + TR_CAPI_LOGIN_FAILED = 100, + TR_CAPI_HANDLE_CAPI_FAILED = 101, + TR_CAPI_LOGOFF_FAILED = 102, + TR_CAPI_FETCH_BAD_ARGS = 103, + TR_IRIP_FAILED = 200, + TR_IMIP_FAILED = 300 + }; + + enum ETxnType + { + ETxnType_STORE = 0, + ETxnType_DELETE = 1, + ETxnType_GET = 2 + }; + +protected: + + /* calendar containing METHOD, other header info */ + NSCalendar * m_Calendar; + + /* vector of components in transaction */ + JulianPtrArray * m_ICalComponentVctr; + + /* capi arguments - (i.e. UIDs, date range values */ + JulianPtrArray * m_Modifiers; + + /* FROM: User - usually the logged in User */ + User * m_User; + + /* TO: Recipients */ + JulianPtrArray * m_Recipients; + + /* Attendee to filter on a reply */ + UnicodeString m_AttendeeName; + + /* subject of mail message */ + UnicodeString m_Subject; + + /* context windows to send to */ + MWContext * m_Context; + + /* julain form which contains function ptrs */ + JulianForm * m_JulianForm; + + /* TODO: move the CAPI stuff somewhere*/ + /* char * m_userxstring; + char * m_password; + char * m_hostname; + char * m_node; + char * m_recipientxstring;*/ + + /* Fetch Type */ + EFetchType m_FetchType; + + /** + * Prints each ICalComponent in the components vector in iCal + * format. The output string will depend on the method name, + * the name of the attendee to filter on, the delegate to + * filter on, and whether to print as recurring or not. + * + * @param components vector of ICalComponent's to print + * @param method ITIP method name of message + * @param name attendee to filter on + * @param isRecurring TRUE = no recid, FALSE = print recid + * @param out output string + * + * @return output string (out) + */ + static UnicodeString & printComponents(JulianPtrArray * components, + UnicodeString & method, UnicodeString & name, + t_bool isRecurring, UnicodeString & out); + + /** hide from clients */ + TransactionObject(); + + UnicodeString & MakeITIPMessage(UnicodeString & out); + +private: + /** + * Run the executeCAPI, executeIMIP, executeIRIP, executeFCAPI + * depending on order of transports. + */ + ETxnErrorCode executeHelper(ETransportType * transports, + t_int32 transportsSize, JulianPtrArray * out); + + + /** + * For each recipient, if status[i] is TRUE, then remove + * recipient[i] from recipients vector. Assumes that + * recipients has same size as statusSize. + * @param JulianPtrArray * recipients + * @param t_bool * status + * @param t_int32 statusSize + * + * @return static void + */ + static void removeSuccessfulUsers(JulianPtrArray * recipients, + t_bool * status, + t_int32 statusSize); + + + /** + * For each boolean in status, set status[i] to FALSE. + */ + static void setStatusToFalse(t_bool * status, t_int32 statusSize); + + + /** + * Creates the content type header for the IMIP message in the form + * Content-Type: text/calendar method=PUBLISH; charset=UTF-8; component=VEVENT + * @param UnicodeString & sMethod + * @param UnicodeString & sCharset + * @param UnicodeString & sComponentType + * @param UnicodeString & sContentTypeHeader + * + * @return static UnicodeString + */ + static UnicodeString & createContentTypeHeader(UnicodeString & sMethod, + UnicodeString & sCharset, UnicodeString & sComponentType, + UnicodeString & sContentTypeHeader); + + +public: + + /* used for debugging only : TODO: remove later*/ + UnicodeString m_DebugITIPMessage; + + /** + * Clients should not delete cal, components, user, recipients, jf, context + * I assume components are processed and ready to go (i.e. DTStamp already set). + * the cal arg should have the calendar that contains calendar information for the + * components. This includes the METHOD, PRODID, and VERSION. + * The components contains the ICalComponents that should be sent. + * The user is the name of the user who sends the transaction. For CAPI, this + * would be who logs in. For IMIP, this would be the FROM: person. + * The recipients vector contains the User object to store the components to. + * For CAPI, this would be the handles to get. For IMIP, this would be the TO: persons. + * The subject contains the subject on an IMIP message. + * The modifiers should contain various information depending on the CAPI call. + * For a DELETE the modifiers should be in the following order + * UID, [Recurrence-ID], [("THISANDPRIOR" or "THISANDFUTURE")] + * For a FETCH by UID, the modifiers should be in the following order + * UID, [Recurrence-ID], [("THISANDPRIOR", or "THISANDFUTURE")] + * For a FETCH by DateRange and a FETCH by AlarmRange, the modifiers should be + * DTSTART, DTEND + * @param NSCalendar & cal + * @param JulianPtrArray & components + * @param User & user + * @param JulianPtrArray & recipients + * @param UnicodeString & subject + * @param JulianPtrArray & modifiers + * @param UnicodeString & attendeeName + */ + TransactionObject(NSCalendar & cal, JulianPtrArray & components, + User & user, JulianPtrArray & recipients, UnicodeString & subject, + JulianPtrArray & modifiers, + JulianForm * jf, MWContext * context, + UnicodeString & attendeeName, EFetchType fetchType = EFetchType_NONE); + + virtual ~TransactionObject(); + + /* execute the transaction. calls the + * executeCAPI, executeIRIP, executeIMIP */ + void execute(JulianPtrArray * out, ETxnErrorCode & status); + + ETxnErrorCode executeIRIP(JulianPtrArray * out, t_bool * outStatus, + t_int32 outStatusSize); + ETxnErrorCode executeIMIP(JulianPtrArray * out, t_bool * outStatus, + t_int32 outStatusSize); + ETxnErrorCode executeFCAPI(JulianPtrArray * out, t_bool * outStatus, + t_int32 outStatusSize); + + virtual ETxnType GetType() const + { + /* Should always assert out, pure virtual method. */ + PR_ASSERT(FALSE); return ETxnType_STORE; + } +#if CAPI_READY + + + static ETxnErrorCode FetchEventsByRange( + User * loggedInUser, /* i: logged in user (use this session) */ + JulianPtrArray * usersToFetchOn, /* i: users to fetch on (use these handles) */ + DateTime dtStart, /* i: start of fetch range */ + DateTime dtEnd, /* i: end of fetch range */ + JulianPtrArray * eventsToFillIn); /* o: fill in vector with events to fetch */ + + ETxnErrorCode executeCAPI(JulianPtrArray * outCalendars, t_bool * outStatus, + t_int32 outStatusSize); + + /* TODO: pure virtual handleCAPI interface needs to be changed to reflect newest CAPI spec */ + virtual CAPIStatus handleCAPI( + CAPISession & pS, + CAPIHandle * pH, + t_int32 iHandleCount, + t_int32 lFlags, + JulianPtrArray * inComponents, + NSCalendar * inCal, + JulianPtrArray * modifiers, + JulianPtrArray * outCalendars, + TransactionObject::EFetchType & out) + { + PR_ASSERT(FALSE); + CAPIStatus foo; + return foo; + } + + /* s = CAPISession + ppH = list of CAPIHandles + iHandleCount = number of valid handles in ppH. + lFlags = bit flags + modifiers should hold following: + for StoreEvent: nothing + for FetchByID: uid, recurrence-ID, range modifier (THISANDPRIOR,THISANDFUTURE,NONE) + for FetchByRange: start, end + for DeleteEvent: uid, recurrence-ID + for FetchByAlarmRange: start,end + -------------------------------- + propList is list of properties to return in events + stream is CAPIStream to read/write data*/ + + /*TODO: newer CAPI interface*/ + /* + virtual CAPIStatus handleCAPI(CAPISession * s, CAPIHandle ** ppH, + t_int32 iHandleCount, long lFlags, JulianPtrArray * modifiers, + JulianPtrArray * propList, CAPIStream * stream); + */ +#if 0 + void setCAPIInfo(char * userxstring, char * password, + char * hostname, char * node, char * recipientxstring); +#endif +#endif /* #if CAPI_READY */ + +}; + +#endif /* __TRANSOBJ_H_ */ + diff --git a/calendar/modules/network/itip/inc/txnobjfy.h b/calendar/modules/network/itip/inc/txnobjfy.h new file mode 100644 index 00000000000..3a081fdbe3b --- /dev/null +++ b/calendar/modules/network/itip/inc/txnobjfy.h @@ -0,0 +1,65 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +/* + * txnobjfy.h + * John Sun + * 4/13/98 10:34:44 AM + */ +#ifndef __TRANSACTIONOBJECTFACTORY_H_ +#define __TRANSACTIONOBJECTFACTORY_H_ + +#include "jdefines.h" +#include "txnobj.h" + +class TransactionObjectFactory +{ +private: + /*----------------------------- + ** MEMBERS + **---------------------------*/ + /*----------------------------- + ** PRIVATE METHODS + **---------------------------*/ + TransactionObjectFactory(); +public: + /*----------------------------- + ** CONSTRUCTORS and DESTRUCTORS + **---------------------------*/ + static TransactionObject * Make(NSCalendar & cal, + JulianPtrArray & components, User & user, JulianPtrArray & recipients, + UnicodeString & subject, JulianPtrArray & modifiers, + JulianForm * jf, MWContext * context, + UnicodeString & attendeeName, + TransactionObject::EFetchType fetchType = TransactionObject::EFetchType_NONE); + /*----------------------------- + ** ACCESSORS (GET AND SET) + **---------------------------*/ + /*----------------------------- + ** UTILITIES + **---------------------------*/ + /*----------------------------- + ** STATIC METHODS + **---------------------------*/ + /*----------------------------- + ** OVERLOADED OPERATORS + **---------------------------*/ +}; + +#endif /*__TRANSACTIONOBJECTFACTORY_H_ */ + diff --git a/calendar/modules/network/itip/inc/user.h b/calendar/modules/network/itip/inc/user.h new file mode 100644 index 00000000000..ea5488ca37b --- /dev/null +++ b/calendar/modules/network/itip/inc/user.h @@ -0,0 +1,162 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +/* + * user.h + * John Sun + * 3/10/98 2:28:01 PM + */ + +#include +#include "ptrarray.h" +#if CAPI_READY +#include +#endif + +#ifndef __USER_H_ +#define __USER_H_ + +class User +{ +private: + /* For now store CAPI, IMIP, IRIP addresses as char **/ + UnicodeString m_CAPIAddress; + t_int32 m_XItemID; + + UnicodeString m_IMIPAddress; /* usually e-mail address*/ + UnicodeString m_IRIPAddress; + + UnicodeString m_RealName; + + /* temporary holding CS&T info, remove when CAP is ready */ + UnicodeString m_LoginName; /* this maybe unrelated to m_RealName */ + UnicodeString m_Password; + UnicodeString m_Hostname; + UnicodeString m_Node; +#if CAPI_READY + CAPISession * m_Session; +#endif + +public: + User(); + User(User & that); + User(UnicodeString realName, UnicodeString imip); + User(UnicodeString realName, UnicodeString imip, + UnicodeString capi, UnicodeString irip, + t_int32 xItemID = -1); + + virtual ~User(); + + User * clone(); + + t_bool IsValidCAPI() const { return (m_CAPIAddress.size() > 0) && (m_XItemID != -1); } + t_bool IsValidIRIP() const { return (m_IRIPAddress.size() > 0); } + t_bool IsValidIMIP() const { return (m_IMIPAddress.size() > 0); } + + UnicodeString getIMIPAddress() const { return m_IMIPAddress; } + UnicodeString getIRIPAddress() const { return m_IRIPAddress; } + UnicodeString getCAPIAddress() const { return m_CAPIAddress; } + t_int32 getXItemID() const { return m_XItemID; } + +#if CAPI_READY + void setCAPISession(CAPISession * s) { m_Session = s; } + CAPISession * getCAPISession() const { return m_Session; } +#endif + + void setRealName(UnicodeString realName) + { + m_RealName = realName; + } + + + /* TODO: temporarily hold CS&T info, remove when CAP is ready */ + void setCAPIInfo(UnicodeString loginName, UnicodeString password, + UnicodeString hostname, UnicodeString node) + { + m_LoginName = loginName; + m_Password = password; + m_Hostname = hostname; + m_Node = node; + } + + UnicodeString getPassword() const { return m_Password; } + UnicodeString getHostname() const { return m_Hostname; } + UnicodeString getNode() const { return m_Node; } + + /* end CS&T info */ + + UnicodeString getRealName() const { return m_RealName; } + + /** + * Prints summary of this User's private data info. + * + * @return UnicodeString + */ + UnicodeString toString(); + + + /** + * Return the CAPI x-string of this User. Uses the MakeXString method. + * + * @return UnicodeString + */ + UnicodeString getXString(); + + UnicodeString getLogonString(); + /** + * Creates the CAPI X-string from the real-name argument in + * the form "S=lastName*'/G=firstName*". The lastName is the defined + * to be all words after the first space. + * Thus if given the name John Van Der Wal, John would be the first + * name and Van Der Wal would be the last name. The generated + * x-string would be "S=Van Der Wal/G=John". It is recommended that + * realname argument not have more than two words in a name. + * An empty real name string returns "S=*'/G=*". + * @param out generated x-string output + * + * @return generated x-string output (out) + */ + static UnicodeString & MakeXString(UnicodeString & realName, UnicodeString & out); + + + /** + * Creates the CAPI logon string from the real-name and node argument into the + * form "S=lastname/G=firstname/ND=node/" + * @param UnicodeString & realName + * @param UnicodeString & node + * @param UnicodeString & out + * + * @return static UnicodeString + */ + static UnicodeString & MakeCAPILogonString(UnicodeString & realName, UnicodeString & node, + UnicodeString & out); + + /* static methods */ + + /** + * Cleanup method. Delete each User element in the vector users. + * @param users vector of users to delete from + */ + static void deleteUserVector(JulianPtrArray * users); + + static void cloneUserVector(JulianPtrArray * toClone, JulianPtrArray * out); +}; +#endif /* __USER_H_ */ + + + diff --git a/calendar/modules/network/itip/manifest.mn b/calendar/modules/network/itip/manifest.mn new file mode 100644 index 00000000000..e69de29bb2d diff --git a/calendar/modules/network/itip/src/Makefile b/calendar/modules/network/itip/src/Makefile new file mode 100644 index 00000000000..e69de29bb2d diff --git a/calendar/modules/network/itip/src/config.mk b/calendar/modules/network/itip/src/config.mk new file mode 100644 index 00000000000..e69de29bb2d diff --git a/calendar/modules/network/itip/src/detxnobj.cpp b/calendar/modules/network/itip/src/detxnobj.cpp new file mode 100644 index 00000000000..2073de8f0ac --- /dev/null +++ b/calendar/modules/network/itip/src/detxnobj.cpp @@ -0,0 +1,126 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +/* + * detxnobj.cpp + * John Sun + * 4/13/98 11:07:45 AM + */ +#include "jdefines.h" +#include "julnstr.h" +#include "detxnobj.h" +#include "txnobj.h" + +#if CAPI_READY +#include +#endif /* CAPI_READY */ + +//--------------------------------------------------------------------- + +DeleteTransactionObject::DeleteTransactionObject() +{ + PR_ASSERT(FALSE); +} + +//--------------------------------------------------------------------- + +DeleteTransactionObject::DeleteTransactionObject(NSCalendar & cal, + JulianPtrArray & components, + User & user, + JulianPtrArray & recipients, + UnicodeString & subject, + JulianPtrArray & modifiers, + JulianForm * jf, + MWContext * context, + UnicodeString & attendeeName) +: TransactionObject(cal, components, user, recipients, subject, + modifiers, + jf, context, + attendeeName) +{ +} + +//--------------------------------------------------------------------- +#if CAPI_READY + +CAPIStatus +DeleteTransactionObject::handleCAPI(CAPISession & pS, CAPIHandle * pH, + t_int32 iHandleCount, t_int32 lFlags, + JulianPtrArray * inComponents, NSCalendar * inCal, + JulianPtrArray * modifiers, + JulianPtrArray * outCalendars, TransactionObject::EFetchType & out) +{ + CAPIStatus status; + t_int32 modifierSize; + + // TODO: finish, don't use for now + //PR_ASSERT(FALSE); + + // + PR_ASSERT(modifiers != 0 && modifiers->GetSize() > 0 && + modifiers->GetSize() <= 3); + PR_ASSERT(iHandleCount >= 1); + if (modifiers != 0 && modifiers->GetSize() > 0 && + modifiers->GetSize() <= 3 && iHandleCount >= 1) + { + char * modifier = 0; + char * uid = 0; + char * rid = 0; + t_int8 modifierInt = CAPI_THISINSTANCE; + modifierSize = modifiers->GetSize(); + // Get the args (uid, rid, rangeModifier) + + uid = ((UnicodeString *) modifiers->GetAt(0))->toCString(""); + PR_ASSERT(uid != 0); + if (modifierSize > 1) + { + rid = ((UnicodeString *) modifiers->GetAt(1))->toCString(""); + PR_ASSERT(rid != 0); + if (modifierSize > 2) + { + modifier = ((UnicodeString *) modifiers->GetAt(2))->toCString(""); + PR_ASSERT(modifier != 0); + if (strcmp(modifier, "THISANDPRIOR") == 0) + modifierInt = CAPI_THISANDPRIOR; + else if (strcmp(modifier, "THISANDFUTURE") == 0) + modifierInt = CAPI_THISANDFUTURE; + else + modifierInt = CAPI_THISINSTANCE; + } + } + status = CAPI_DeleteEvent(pS, pH, iHandleCount, 0, uid, rid, modifierInt); + if (modifier != 0) + { + delete [] modifier; modifier = 0; + } + if (rid != 0) + { + delete [] rid; rid = 0; + } + if (uid != 0) + { + delete [] uid; uid = 0; + } + } + // + return status; +} + +//--------------------------------------------------------------------- + +#endif /* #if CAPI_READY */ diff --git a/calendar/modules/network/itip/src/getxnobj.cpp b/calendar/modules/network/itip/src/getxnobj.cpp new file mode 100644 index 00000000000..48c6f41f268 --- /dev/null +++ b/calendar/modules/network/itip/src/getxnobj.cpp @@ -0,0 +1,385 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +/* + * getxnobj.cpp + * John Sun + * 4/1/98 5:16:29 PM + */ + +#include "jdefines.h" +#include "julnstr.h" +#include "getxnobj.h" +#include "nspr.h" + +#if CAPI_READY +#include +#include "jparser.h" +#include "icalsrdr.h" +#include "nscal.h" +#include "capiredr.h" +//#define TEST_STRINGREADER_PARSE 1 +#endif /* #if CAPI_READY */ + +//PRMonitor * GetTransactionObject::m_Monitor = 0; +//--------------------------------------------------------------------- + +GetTransactionObject::GetTransactionObject() +{ + PR_ASSERT(FALSE); +} + +//--------------------------------------------------------------------- + +GetTransactionObject::GetTransactionObject(NSCalendar & cal, + JulianPtrArray & components, + User & user, + JulianPtrArray & recipients, + UnicodeString & subject, + JulianPtrArray & modifiers, + JulianForm * jf, + MWContext * context, + UnicodeString & attendeeName, + EFetchType type) +: TransactionObject(cal, components, user, recipients, subject, + modifiers, + jf, context, + attendeeName, type) +{ +#if CAPI_READY + m_Monitor = 0; +#endif +} + +//--------------------------------------------------------------------- +#if CAPI_READY + +/* +int writeToCAPIReader(void * pData, char * pBuf, + int iSize, int * piTransferred) +{ + int i; + for(i = 0; i < iSize; i++) + { + // TODO: put each char into new char * in capireader + //putc( *(pBuf++), (void *) pData); + } + *piTransferred = i; + + return CAPI_CALLBACK_CONTINUE; +} +*/ + +//--------------------------------------------------------------------- + +int writeToBufferDebug(void * pData, char * pBuf, + int iSize, int * piTransferred) +{ + CAPI_CTX * pCtx = (CAPI_CTX*)pData; + *piTransferred = (pCtx->iSize > iSize) ? iSize: pCtx->iSize; + memcpy(pCtx->p, pBuf, *piTransferred); + pCtx->iSize -= *piTransferred; + pCtx->p += *piTransferred; + return pCtx->iSize > 0 ? 0 : -1; +} + +//--------------------------------------------------------------------- + +int getransactionobj_writeToCAPIReader(void * pData, char * pBuf, size_t iSize, size_t * piTransferred) +{ + //PR_EnterMonitor(GetTransactionObject::getMonitor()); +#if TESTING_ITIPRIG + TRACE("\t\t--writeToCAPIReader: entered method (transferring %d chars) \r\n", iSize); +#endif + //ICalCAPIReader * pReader = (ICalCAPIReader *) pData; + JulianParser * pJP = (JulianParser *) pData; + ICalCAPIReader * pReader = pJP->getReader(); + //PR_EnterMonitor((PRMonitor *)(pReader->getMonitor())); + if (!pJP->isParseStarted()) + { + PRThread * pThread = pJP->getThread(); + +#if TESTING_ITIPRIG + TRACE("\t\t--writeToCAPIReader: starting parseThread\r\n"); +#endif + pJP->setParseStarted(); + PR_Start(pThread, jparser_ParseCalendarsZero, pJP, NULL); + //PR_Start(parseThread, jparser_ParseCalendars, (void *) (capiReader), (void *) (outCalendars)); + } + + // enter monitor + PR_EnterMonitor((PRMonitor *)pReader->getMonitor()); +#if TESTING_ITIPRIG + TRACE("\t\t--writeToCAPIReader: in monitor\r\n"); +#endif + + *piTransferred = iSize; + // todo: this assumes pBuf is null-terminated + pReader->AddChunk(new UnicodeString(pBuf)); + if (iSize < 500) + { +#if TESTING_ITIPRIG + TRACE("\t\t--writeToCAPIReader: added chunk -%s- \r\n", pBuf); +#endif + + } + else + { +#if TESTING_ITIPRIG + TRACE("\t\t--writeToCAPIReader: added chunk bigger that 500 chars\r\n"); +#endif + } + //PR_Wait((PRMonitor *)(pReader->getMonitor()), LL_MAXINT); + + //if finished, set it to TRUE + if (iSize <= 0) + { + pReader->setFinished(); +#if TESTING_ITIPRIG + TRACE("\t\t--writeToCAPIReader: has no more chunks to add.\r\n"); +#endif + } + + //PR_ExitMonitor((PRMonitor *)(pReader->getMonitor())); + + // notify??? +#if TESTING_ITIPRIG + TRACE("\t\t--writeToCAPIReader: notifying parseThread that more chunks added\r\n"); +#endif + PR_Notify((PRMonitor *)pReader->getMonitor()); + +#if TESTING_ITIPRIG + TRACE("\t\t--writeToCAPIReader: leaving monitor\r\n"); +#endif + PR_ExitMonitor((PRMonitor *)pReader->getMonitor()); +#if TESTING_ITIPRIG + TRACE("\t\t--writeToCAPIReader: yielding\r\n"); +#endif + PR_Yield(); + // exit monitor + return iSize > 0 ? 0 : -1; +} + +//--------------------------------------------------------------------- +/* +int GetTransactionObject::writeToCAPIReader(void * pData, char * pBuf, + int iSize, int * piTransferred) +{ + int retVal; + retVal = writeToCAPIReaderHelper(pData, pBuf, iSize, piTransferred); + /* + PR_ASSERT(m_CAPIReader != 0); + if (m_CAPIReader != 0) + { + m_CAPIReader->addNewChunk(pData, *piTransferred); + } + + return retVal; +} +*/ +//--------------------------------------------------------------------- + +CAPIStatus +GetTransactionObject::handleCAPI(CAPISession & pS, CAPIHandle * pH, + t_int32 iHandleCount, t_int32 lFlags, + JulianPtrArray * inComponents, NSCalendar * inCal, + JulianPtrArray * modifiers, + JulianPtrArray * outCalendars, TransactionObject::EFetchType & out) +{ + CAPIStatus capiStatus; + CAPIStream outStream = NULL; + void * writeData = 0; + +#if TEST_STRINGREADER_PARSE + char debugBuf[20000]; + myCtx.p = debugBuf; + myCtx.iSize = sizeof(debugBuf); + + capiStatus = CAPI_SetStreamCallbacks(&outStream, NULL, NULL, writeToBufferDebug, &myCtx, 0); +#else + PRThread * parseThread; + + PR_ASSERT(outCalendars != 0); + // + + PRThread * mainThread = PR_CurrentThread(); + +#if TESTING_ITIPRIG + TRACE("--main thread running\n"); +#endif + + m_Monitor = PR_NewMonitor(); + PR_ASSERT(m_Monitor != 0); + ICalCAPIReader * capiReader = new ICalCAPIReader(m_Monitor); + PR_ASSERT(capiReader != 0); + // + t_int32 STACK_SIZE = 4096; + t_int32 threadPriority = 5; + t_int32 stackSize = 0; + parseThread = PR_CreateThread("parseThread", threadPriority, stackSize); + JulianParser * jp = new JulianParser(capiReader, outCalendars, parseThread); + + //PR_Start(parseThread, jparser_ParseCalendars, (void *) (capiReader), (void *) (outCalendars)); + + //JulianParser::ParseCalendars(capiReader, outCalendars); + + //capiStatus = CAPI_SetStreamCallbacks(&outStream, NULL, NULL, getransactionobj_writeToCAPIReader, capiReader, 0); + capiStatus = CAPI_SetStreamCallbacks(pS, &outStream, NULL, NULL, getransactionobj_writeToCAPIReader, jp, 0); + + +#endif + + if (capiStatus == CAPI_ERR_OK) + { + t_int32 modifierSize; + switch (m_FetchType) + { + case EFetchType_UID: + PR_ASSERT(modifiers != 0 && modifiers->GetSize() > 0 && + modifiers->GetSize() <= 3); + PR_ASSERT(iHandleCount == 1); + + if (modifiers != 0 && modifiers->GetSize() > 0 && + modifiers->GetSize() <= 3 && iHandleCount == 1) + { + + char * modifier = 0; + char * uid = 0; + char * rid = 0; + t_int8 modifierInt = CAPI_THISINSTANCE; + modifierSize = modifiers->GetSize(); + + // Get the args (uid, rid, rangeModifier) + uid = ((UnicodeString *) modifiers->GetAt(0))->toCString(""); + PR_ASSERT(uid != 0); + if (modifierSize > 1) + { + rid = ((UnicodeString *) modifiers->GetAt(1))->toCString(""); + PR_ASSERT(rid != 0); + if (modifierSize > 2) + { + modifier = ((UnicodeString *) modifiers->GetAt(2))->toCString(""); + PR_ASSERT(modifier != 0); + if (strcmp(modifier, "THISANDPRIOR") == 0) + modifierInt = CAPI_THISANDPRIOR; + else if (strcmp(modifier, "THISANDFUTURE") == 0) + modifierInt = CAPI_THISANDFUTURE; + else + modifierInt = CAPI_THISINSTANCE; + } + } + + // TODO: set the property list to NULL for now, pass in +#ifdef TESTING_ITIPRIG + TRACE("--main thread: fetching by UID:, %s, RID %s, MODIFIER %d\r\n", uid, rid, modifierInt); +#endif +#if 0 + capiStatus = CAPI_FetchEventsByID(pS, *pH, 0, uid, rid, modifierInt, + NULL, 0, outStream); +#endif + if (modifier != 0) + { + delete [] modifier; modifier = 0; + } + if (rid != 0) + { + delete [] rid; rid = 0; + } + if (uid != 0) + { + delete [] uid; uid = 0; + } + } + break; + case EFetchType_DateRange: + PR_ASSERT(modifiers != 0 && modifiers->GetSize() == 2); + PR_ASSERT(iHandleCount >= 1); + if (modifiers != 0 && modifiers->GetSize() == 2 && + iHandleCount >= 1) + { + char * start = 0; + char * end = 0; + start = ((UnicodeString *) modifiers->GetAt(0))->toCString(""); + end = ((UnicodeString *) modifiers->GetAt(1))->toCString(""); + PR_ASSERT(start != 0 && end != 0); + // TODO: set the property list to NULL for now, pass in later +#ifdef TESTING_ITIPRIG + TRACE("--main thread: fetching by DateRange:, START %s, END %s\r\n", start, end); +#endif + capiStatus = CAPI_FetchEventsByRange(pS, &pH[0], iHandleCount, 0, + start, end, NULL, 0, outStream); + if (start != 0) + { + delete [] start; start = 0; + } + if (end != 0) + { + delete [] end; end = 0; + } + } + break; + case EFetchType_AlarmRange: + PR_ASSERT(modifiers != 0 && modifiers->GetSize() == 2); + PR_ASSERT(iHandleCount >= 1); + if (modifiers != 0 && modifiers->GetSize() == 2 && + iHandleCount >= 1) + { + char * start = 0; + char * end = 0; + PR_ASSERT(start != 0 && end != 0); + start = ((UnicodeString *) modifiers->GetAt(0))->toCString(""); + end = ((UnicodeString *) modifiers->GetAt(1))->toCString(""); + + + // TODO: set the property list to NULL for now, pass in later +#ifdef TESTING_ITIPRIG + TRACE("--main thread: fetching by AlarmRange:, START %s, END %s\r\n", start, end); +#endif + capiStatus = CAPI_FetchEventsByAlarmRange(pS, &pH[0], iHandleCount, 0, + start, end, NULL, 0, outStream); + if (start != 0) + { + delete [] start; start = 0; + } + if (end != 0) + { + delete [] end; end = 0; + } + } + break; + } + out = m_FetchType; + } + + //---- + char * c = myCtx.p; + +#if TEST_STRINGREADER_PARSE + ICalReader * ir = (ICalReader *) new ICalStringReader(debugBuf); + if (ir != 0) + { + JulianParser::ParseCalendars(ir, outCalendars); + delete ir; ir = 0; + } +#endif // TEST_STRINGREADER_PARSE + + return capiStatus; + +} + +#endif /* #if CAPI_READY */ diff --git a/calendar/modules/network/itip/src/manifest.mn b/calendar/modules/network/itip/src/manifest.mn new file mode 100644 index 00000000000..e69de29bb2d diff --git a/calendar/modules/network/itip/src/sttxnobj.cpp b/calendar/modules/network/itip/src/sttxnobj.cpp new file mode 100644 index 00000000000..0b0dbc39e62 --- /dev/null +++ b/calendar/modules/network/itip/src/sttxnobj.cpp @@ -0,0 +1,177 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +/* + * sttxnobj.cpp + * John Sun + * 4/13/98 10:38:50 AM + */ + +#include "jdefines.h" +#include "julnstr.h" +#include "sttxnobj.h" +#include "txnobj.h" +#if CAPI_READY +#include +#endif /* CAPI_READY */ + +//--------------------------------------------------------------------- + +StoreTransactionObject::StoreTransactionObject() +{ + PR_ASSERT(FALSE); +} + +//--------------------------------------------------------------------- + +StoreTransactionObject::StoreTransactionObject(NSCalendar & cal, + JulianPtrArray & components, + User & user, + JulianPtrArray & recipients, + UnicodeString & subject, + JulianPtrArray & modifiers, + JulianForm * jf, + MWContext * context, + UnicodeString & attendeeName) +: TransactionObject(cal, components, user, recipients, subject, + modifiers, + jf, context, + attendeeName) +{ +} + +//--------------------------------------------------------------------- +#if CAPI_READY + +int stringRead(void * pData, char * pBuf, size_t iSize, size_t* piTransferred) +{ + CAPI_CTX* pCtx = (CAPI_CTX*)pData; + *piTransferred = (pCtx->iSize > iSize) ? iSize : pCtx->iSize; + memcpy(pBuf,pCtx->p,*piTransferred); + pCtx->iSize -= *piTransferred; + pCtx->p += *piTransferred; + return pCtx->iSize > 0 ? 0 : -1; +} + +//--------------------------------------------------------------------- + +CAPIStatus +StoreTransactionObject::handleCAPI(CAPISession & pS, CAPIHandle * pH, + t_int32 iHandleCount, t_int32 lFlags, + JulianPtrArray * inComponents, NSCalendar * inCal, + JulianPtrArray * modifiers, + JulianPtrArray * outCalendars, TransactionObject::EFetchType & out) +{ + CAPIStatus status; + CAPIStream outStream = NULL; + char ** uids = NULL; + long outSize; + t_int32 i; + char * pBuf = 0; + + PR_ASSERT(inComponents != 0 && inCal != 0); + +#if 0 + + // For now + // first make the MIME-message + //char pBuf[3000]; + + // works + //strcpy(pBuf, "Mime-Version: 1.0\nContent-Type:text/calendar; method=PUBLISH; charset=US-ASCII\nContent-Transfer-Encoding: 7bit\n\nBEGIN:VCALENDAR\r\nMETHOD:PUBLISH\r\nPRODID:-//ACME/DesktopCalendar//EN\r\nVERSION:2.0\r\nBEGIN:VEVENT\r\nORGANIZER:mailto:a@example.com\r\nDTSTART:19980508T200000Z\r\nDTEND:19980508T210000Z\r\nDTSTAMP:19970611T190000Z\r\nSUMMARY:ST. PAUL SAINTS -VS- DULUTH-SUPERIOR DUKES\r\nUID:atestUID19970505T112233Z-303434@jsun.netscape.com\r\nCOMMENT:A comment with no params\r\nEND:VEVENT\r\nEND:VCALENDAR\n"); + + // doesn't work + //strcpy(pBuf, "Mime-Version: 1.0\nContent-Type:text/calendar; method=PUBLISH; charset=US-ASCII\nContent-Transfer-Encoding: 7bit\n\nBEGIN:VCALENDAR\r\nMETHOD:PUBLISH\r\nPRODID:-//ACME/DesktopCalendar//EN\r\nVERSION:2.0\r\nBEGIN:VEVENT\r\nORGANIZER:mailto:a@example.com\r\nDTSTART:19980508T200000Z\r\nDTEND:19980508T210000Z\r\nDTSTAMP:19980611T190000Z\r\nATTENDEE;ROLE=REQ-PARTICIPANT;RSVP=FALSE;EXPECT=FYI;CUTYPE=INDIVIDUAL:MAILTO\r\n :a@acme.com\r\nATTENDEE;ROLE=REQ-PARTICIPANT;RSVP=FALSE;EXPECT=FYI;CUTYPE=INDIVIDUAL:MAILTO\r\n :hello\r\nCLASS:PUBLIC\r\nCOMMENT:A comment with no params\r\nCOMMENT;LANGUAGE=us_en:comment with language only\r\nCOMMENT;VALUE=BINARY:a comment with a bad param\r\nDESCRIPTION:A VEvent with a DTStart having a TZID of America-New_York\r\nDURATION:P0Y0M0DT0H0M0S\r\nRELATED-TO:relatedto1@jdoe.com\r\nRELATED-TO:relatedto2@jdoe.com\r\nREQUEST-STATUS:2.02;Success, invalid property ignored.. ATTENDEE\r\nSEQUENCE:0\r\nSUMMARY:A VEvent with TZID DTStart\r\nUID:001jsun@netscape.com\r\nURL:http://www.ur12.com\r\nEND:VEVENT\r\nEND:VCALENDAR\n"); + + // works + //strcpy(pBuf, "Mime-Version: 1.0\nContent-Type:text/calendar; method=PUBLISH; charset=US-ASCII\nContent-Transfer-Encoding: 7bit\n\nBEGIN:VCALENDAR\r\nMETHOD:PUBLISH\r\nPRODID:-//ACME/DesktopCalendar//EN\r\nVERSION:2.0\r\nBEGIN:VEVENT\r\nATTENDEE:mailto:jsun@netscape.com\r\nORGANIZER:mailto:a@example.com\r\nDTSTART:19980508T200000Z\r\nDTEND:19980508T210000Z\r\nDTSTAMP:19980611T190000Z\r\nSUMMARY:A VEvent with TZID DTStart\r\nUID:001jsun@netscape.com\r\nCLASS:PUBLIC\r\nCOMMENT:A comment with no params\r\nSEQUENCE:0\r\nURL:http://www.ur12.com\r\nEND:VEVENT\r\nEND:VCALENDAR\n"); + + // works + //UnicodeString u = "Mime-Version: 1.0\nContent-Type:text/calendar; method=PUBLISH; charset=US-ASCII\nContent-Transfer-Encoding: 7bit\n\nBEGIN:VCALENDAR\r\nMETHOD:PUBLISH\r\nPRODID:-//ACME/DesktopCalendar//EN\r\nVERSION:2.0\r\nBEGIN:VEVENT\r\nATTENDEE:mailto:jsun@netscape.com\r\nORGANIZER:mailto:a@example.com\r\nDTSTART:19980508T200000Z\r\nDTEND:19980508T210000Z\r\nDTSTAMP:19980611T190000Z\r\nSUMMARY:A VEvent with TZID DTStart\r\nUID:001jsun@netscape.com\r\nCLASS:PUBLIC\r\nCOMMENT:A comment with no params\r\nSEQUENCE:0\r\nURL:http://www.ur12.com\r\nEND:VEVENT\r\nEND:VCALENDAR\n"; + + UnicodeString u = "Mime-Version: 1.0\nContent-Type:text/calendar; method=PUBLISH; charset=US-ASCII\nContent-Transfer-Encoding: 7bit\n\nBEGIN:VCALENDAR\r\nMETHOD:PUBLISH\r\nPRODID:-//ACME/DesktopCalendar//EN\r\nVERSION:2.0\r\nBEGIN:VEVENT\r\nORGANIZER:MAILTO:organizer\r\nCLASS:PRIVATE\r\nCOMMENT:A VEvent\r\nDESCRIPTION:A VEvent with a DTStart having a TZID of America-New_York\r\nDURATION:P0Y0M0DT0H22M33S\r\nDTSTART:19980508T210000Z\r\nDTEND:19980508T212233Z\r\nDTSTAMP:19980303T200000Z\r\nLOCATION:A location\r\nSEQUENCE:0\r\nSUMMARY:A VEvent\r\nUID:002jsun@netscape.com\r\nEND:VEVENT\r\nEND:VCALENDAR\n"; + pBuf = u.toCString(""); + TRACE("u = %s", pBuf); +#else + UnicodeString method, version; + method = "PUBLISH"; + version = "2.0"; + if (inCal != 0) + { + method = NSCalendar::methodToString(inCal->getMethod(), method); + if (inCal->getVersion().size() > 0) + version = inCal->getVersion(); + } + + UnicodeString u2 = "Mime-Version: 1.0\nContent-Type:text/calendar; method="; + u2 += method; + u2 += "; charset=US-ASCII\nContent-Transfer-Encoding: 7bit\n\n"; + u2 += "BEGIN:VCALENDAR\r\nMETHOD:"; + u2 += method; + u2 += "\r\n"; + u2 += "VERSION:"; + u2 += version; + u2 += "\r\n"; + u2 += "PRODID:-//ACME/DesktopCalendar//EN\r\n"; + + // TODO: NOTE: doens't seem to handle DTSTART;TZID=A:19971122T112233 + PR_ASSERT(inComponents != 0); + if (inComponents != 0) + { + for (i = 0; i < inComponents->GetSize(); i++) + { + ICalComponent * ic = (ICalComponent *) inComponents->GetAt(i); + u2 += ic->toICALString(); + } + } + + u2 += "END:VCALENDAR\n"; + pBuf = u2.toCString(""); + //if (FALSE) TRACE("u2 = %s", pBuf); +#endif + + m_Ctx.p = pBuf; + m_Ctx.iSize = strlen(pBuf); + + status = CAPI_SetStreamCallbacks(pS, &outStream, stringRead, &m_Ctx, NULL, NULL, 0); + + // TODO: if server is down, this may take forever!!! + status = CAPI_StoreEvent(pS, pH, iHandleCount, 0, outStream); +#ifdef TESTING_ITIPRIG + if (TRUE) TRACE("CAPI_StoreEvent:%lx\r\n", status); +#endif + //TODO: the store event now has a CS&T UID. What to do with it? + status = CAPI_GetLastStoredUIDs(pS, &uids, &outSize, 0); +#ifdef TESTING_ITIPRIG + if (TRUE) TRACE("Saved %d UIDs.\r\n", outSize); + for (i = 0; i < outSize; i++) + { + if (TRUE) TRACE("%s\r\n", *(uids + i)); + } +#endif + + if (pBuf != 0) + { + delete [] pBuf; pBuf = 0; + } + return status; +} + +//--------------------------------------------------------------------- + +#endif /* #if CAPI_READY */ diff --git a/calendar/modules/network/itip/src/txnengn.cpp b/calendar/modules/network/itip/src/txnengn.cpp new file mode 100644 index 00000000000..e69de29bb2d diff --git a/calendar/modules/network/itip/src/txnobj.cpp b/calendar/modules/network/itip/src/txnobj.cpp new file mode 100644 index 00000000000..5d7c9e4e7b0 --- /dev/null +++ b/calendar/modules/network/itip/src/txnobj.cpp @@ -0,0 +1,661 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +// txnobj.cpp +// John Sun +// 11:36 AM March 10, 1998 + +#include "jdefines.h" +#include "julnstr.h" +#include "txnobj.h" +#include "datetime.h" + +#if CAPI_READY +#include +#endif /* #if CAPI_READY */ + +#include "vevent.h" +#include "jlog.h" +#include "icalsrdr.h" +#include "keyword.h" + +//--------------------------------------------------------------------- + +TransactionObject::TransactionObject() +: m_Calendar(0), m_ICalComponentVctr(0), m_Modifiers(0), m_Recipients(0) +{ +} + +//--------------------------------------------------------------------- + +TransactionObject::TransactionObject(NSCalendar & cal, + JulianPtrArray & components, + User & user, + JulianPtrArray & recipients, + UnicodeString & subject, + JulianPtrArray & modifiers, + JulianForm * jf, + MWContext * context, + UnicodeString & attendeeName, + EFetchType fetchType) +: m_Modifiers(0), m_Recipients(0) +{ + m_Calendar = &cal; + + // assumption is that components are processed. + m_ICalComponentVctr = &components; + m_User = &user; + m_Recipients = &recipients; + m_Subject = subject; + + m_Modifiers = &modifiers; + + m_AttendeeName = attendeeName; + m_FetchType = fetchType; + + // for sending IMIP messages + m_JulianForm = jf; + m_Context = context; +} +//--------------------------------------------------------------------- +TransactionObject::~TransactionObject() +{ + +} +//--------------------------------------------------------------------- + +TransactionObject::ETxnErrorCode +TransactionObject::executeHelper(ETransportType * transports, + t_int32 transportsSize, + JulianPtrArray * out) +{ + t_int32 i = 0; + t_bool * status = 0; + t_int32 statusSize = 0; + PR_ASSERT(transports != 0); + if (transports == 0) + { + + return TR_OK; + } + //PR_ASSERT(m_Recipients != 0 && m_Recipients->GetSize() > 0); + if (m_Recipients == 0 || m_Recipients->GetSize() == 0) + { + // TODO: return the correct error + return TR_OK; + } + // clone recipients + // + JulianPtrArray * tempRecipients = 0; + tempRecipients = new JulianPtrArray(); + if (tempRecipients == 0) + { + // TODO: return the correct error + return TR_OK; + } + User::cloneUserVector(m_Recipients, tempRecipients); + for (i = 0; i < transportsSize; i++) + { + statusSize = tempRecipients->GetSize(); + status = new t_bool[statusSize]; + setStatusToFalse(status, statusSize); + if (status != 0) + { + switch (transports[i]) + { + case ETransportType_CAPI: +#if CAPI_READY + executeCAPI(out, status, statusSize); +#else + executeFCAPI(out, status, statusSize); +#endif + break; + case ETransportType_IRIP: + executeIRIP(out, status, statusSize); + break; + case ETransportType_IMIP: + executeIMIP(out, status, statusSize); + break; + case ETransportType_FCAPI: + executeFCAPI(out, status, statusSize); + break; + } + removeSuccessfulUsers(tempRecipients, status, statusSize); + delete [] status; status = 0; + } + else + { + // TODO: return an error + return TR_IMIP_FAILED; + } + } + + User::deleteUserVector(tempRecipients); + delete tempRecipients; tempRecipients = 0; + return TR_OK; +} +//--------------------------------------------------------------------- + +void +TransactionObject::execute(JulianPtrArray * out, + ETxnErrorCode & status) +{ +#if 0 + PR_ASSERT(m_User != 0 && m_Recipients != 0); + outStatus = TR_OK; + + t_int32 size = 0; + + if (m_Recipients != 0) + { + size = m_Recipients->GetSize(); + } + t_bool * recipientStatus = new t_bool[size]; + +#if CAPI_READY + executeCAPI(out, ouStatus); +#endif + executeIMIP(out, ouStatus); + delete [] recipientStatus; recipientStatus = 0; + +#else /* #if 0 */ + + ETxnErrorCode outStatus = TR_OK; + ETransportType * transports = 0; + t_int32 transportSize = 0; + PR_ASSERT(m_User != 0 && m_Recipients != 0); + +#if CAPI_READY + transportSize = 3; +#else + transportSize = 1; +#endif /* #if CAPI_READY */ + + transports = new ETransportType[transportSize]; + if (transports != 0) + { +#if CAPI_READY + // for now make the order of precedence capi, irip, imip + transports[0] = ETransportType_CAPI; + transports[1] = ETransportType_IRIP; + transports[2] = ETransportType_IMIP; +#else + transports[0] = ETransportType_IMIP; +#endif /* #if CAPI_READY */ + status = executeHelper(transports, transportSize, out); + delete [] transports; transports = 0; + } +#endif /* #if 0 #else */ +} + +//--------------------------------------------------------------------- + +void +TransactionObject::removeSuccessfulUsers(JulianPtrArray * recipients, + t_bool * status, + t_int32 statusSize) +{ + t_int32 i; + User * aUser = 0; + if (recipients == 0) + return; + PR_ASSERT(statusSize == recipients->GetSize()); + for (i = statusSize - 1; i >= 0; i--) + { + if (status[i]) + { + aUser = (User *) recipients->GetAt(i); + delete aUser; + recipients->RemoveAt(i); + } + } +} +//--------------------------------------------------------------------- +void +TransactionObject::setStatusToFalse(t_bool * status, + t_int32 statusSize) +{ + t_int32 i; + for (i = 0; i < statusSize; i++) + status[i] = FALSE; +} +//--------------------------------------------------------------------- +UnicodeString & +TransactionObject::createContentTypeHeader(UnicodeString & sMethod, + UnicodeString & sCharset, + UnicodeString & sComponentType, + UnicodeString & sContentTypeHeader) +{ + sContentTypeHeader = "Content-Type: text/calendar; method="; + sContentTypeHeader += sMethod; + sContentTypeHeader += "; charset="; + sContentTypeHeader += sCharset; + sContentTypeHeader += "; component="; + sContentTypeHeader += sComponentType; + + return sContentTypeHeader; +} + +//--------------------------------------------------------------------- + + +TransactionObject::ETxnErrorCode +TransactionObject::executeIRIP(JulianPtrArray * out, + t_bool * outStatus, + t_int32 outStatusSize) + +{ + //PR_ASSERT(FALSE); + ETxnErrorCode status; + // NOTE: remove later to avoid compiler warnings + if (out != 0 && outStatus != 0); + /* NOT YET DEFINED */ + return status; +} + +//--------------------------------------------------------------------- + +TransactionObject::ETxnErrorCode +TransactionObject::executeFCAPI(JulianPtrArray * out, + t_bool * outStatus, + t_int32 outStatusSize) +{ + //PR_ASSERT(FALSE); + ETxnErrorCode status; + // NOTE: remove later to avoid compiler warnings + if (out != 0 && outStatus != 0); + /* NOT YET DEFINED */ + return status; +} + +//--------------------------------------------------------------------- + +TransactionObject::ETxnErrorCode +TransactionObject::executeIMIP(JulianPtrArray * out, + t_bool * outStatus, + t_int32 outStatusSize) +{ + ETxnErrorCode status = TR_OK; + UnicodeString itipMessage; + UnicodeString sContentTypeHeader; + // prints FROM: User and TO: users + UnicodeString sCharSet = "UTF-8"; + UnicodeString sMethod; + UnicodeString sComponentType; + + t_int32 i; + //User * u; + PR_ASSERT(m_User != 0 && m_Recipients != 0); + if (m_User == 0 || m_Recipients == 0) + { + return TR_IMIP_FAILED; + } + + // Create the body of the message + itipMessage = MakeITIPMessage(itipMessage); + + // Create the content header + PR_ASSERT(m_Calendar != 0); + if (m_Calendar != 0) + { + sMethod = NSCalendar::methodToString(m_Calendar->getMethod(), sMethod); + } + PR_ASSERT(m_ICalComponentVctr != 0 && m_ICalComponentVctr->GetSize() > 0); + if (m_ICalComponentVctr != 0 && m_ICalComponentVctr->GetSize() > 0) + { + // Use first component in m_ICalComponentVctr to get type + sComponentType = + ICalComponent::componentToString(((ICalComponent *)m_ICalComponentVctr->GetAt(0))->GetType()); + } + createContentTypeHeader(sMethod, sCharSet, sComponentType, sContentTypeHeader); + +//#ifdef DEBUG_ITIP + m_DebugITIPMessage = itipMessage; +//#endif /* DEBUG_ITIP */ + + // TODO: send it via mail API here + if (m_JulianForm != 0 && m_Context != 0 && m_Recipients != 0) + { + int iOut; + User * userTo; + UnicodeString uTo; + UnicodeString u; + char * to = 0; + char * from = m_User->getIMIPAddress().toCString(""); + char * subject = m_Subject.toCString(""); + char * body = itipMessage.toCString(""); + char * otherheaders = sContentTypeHeader.toCString(""); + PR_ASSERT(from != 0 && subject != 0 && body != 0 && otherheaders != 0); + + // append the recipients IMIP address to the to string. + // also, if the imip address is null (in this case empty string) + // set outStatus[i] to FALSE. + for (i = 0; i < m_Recipients->GetSize(); i++) + { + userTo = (User *) m_Recipients->GetAt(i); + + if (userTo->getIMIPAddress().size() > 0) + { + outStatus[i] = TRUE; + uTo += userTo->getIMIPAddress(); + if (i < m_Recipients->GetSize() - 1) + uTo += ","; + } + else + outStatus[i] = FALSE; + + } + if (uTo.size() > 0) + to = uTo.toCString(""); + if (to != 0) + { + if (m_JulianForm->getCallbacks()->SendMessageUnattended) + iOut = (*m_JulianForm->getCallbacks()->SendMessageUnattended)(m_Context, to, subject, otherheaders, body); + else + iOut = 0; + delete [] to; + } + if (from != 0) + { + delete [] from; from = 0; + } + if (subject != 0) + { + delete [] subject; subject = 0; + } + if (body != 0) + { + delete [] body; body = 0; + } + if (otherheaders != 0) + { + delete [] otherheaders; otherheaders = 0; + } + + } + return status; +} + +//--------------------------------------------------------------------- + +UnicodeString & +TransactionObject::MakeITIPMessage(UnicodeString & out) +{ + // first print header, then print components + UnicodeString s, sName, sMethod; + t_bool isRecurring = FALSE; + + PR_ASSERT(m_Calendar != 0); + if (m_Calendar != 0) + { + out = "BEGIN:VCALENDAR\r\n"; + out += m_Calendar->createCalendarHeader(s); + sMethod = NSCalendar::methodToString(m_Calendar->getMethod(), sMethod); + + sName = m_AttendeeName; + + out += printComponents(m_ICalComponentVctr, sMethod, + sName, isRecurring, s); + out += "END:VCALENDAR\r\n"; + } + return out; +} +//--------------------------------------------------------------------- + +UnicodeString & +TransactionObject::printComponents(JulianPtrArray * components, + UnicodeString & sMethod, + UnicodeString & sName, + t_bool isRecurring, + UnicodeString & out) +{ + out = ""; + PR_ASSERT(components != 0 && components->GetSize() > 0); + if (components != 0 && components->GetSize() > 0) + { + t_int32 i; + ICalComponent * ic; + DateTime dtStamp; + + for (i = 0; i < components->GetSize(); i++) + { + ic = (ICalComponent *) components->GetAt(i); + out += ic->toICALString(sMethod, sName, isRecurring); + } + } + return out; +} + +//--------------------------------------------------------------------- +#if CAPI_READY +//--------------------------------------------------------------------- +TransactionObject::ETxnErrorCode +TransactionObject::FetchEventsByRange(User * loggedInUser, + JulianPtrArray * usersToFetchOn, + DateTime dtStart, + DateTime dtEnd, + JulianPtrArray * eventsToFillIn) +{ + TransactionObject::ETxnErrorCode status = TR_OK; + if (loggedInUser == 0 || usersToFetchOn == 0) + return TR_CAPI_FETCH_BAD_ARGS; + if (!dtStart.isValid() || !dtEnd.isValid() || dtEnd.beforeDateTime(dtStart)) + return TR_CAPI_FETCH_BAD_ARGS; + if (eventsToFillIn == 0) + return TR_CAPI_FETCH_BAD_ARGS; + + if (loggedInUser->getCAPISession() == 0) + return TR_CAPI_FETCH_BAD_ARGS; + + return status; +} + +//--------------------------------------------------------------------- + +#if 0 +void +TransactionObject::setCAPIInfo(char * userxstring, + char * password, + char * hostname, + char * node, + char * recipientxstring) +{ + m_userxstring = userxstring; + m_password = password; + m_hostname = hostname; + m_node = node; + m_recipientxstring = recipientxstring; +} +#endif +//--------------------------------------------------------------------- + +//void +//TransactionObject::executeCAPI(JulianPtrArray * outCalendars, +// ETxnErrorCode & status) +TransactionObject::ETxnErrorCode +TransactionObject::executeCAPI(JulianPtrArray * outCalendars, + t_bool * outStatus, t_int32 outStatusSize) +{ + CAPISession pS = NULL; + CAPIHandle pH; + char ** strings; + char * eventFetchedByUID; + t_int32 numstrings; + t_int32 i; + + ETxnErrorCode status = TR_OK; + + // Do the following: + // If GetType() is a store or a delete, always try to add m_User to handles. + // Try logging in with m_User information + + // Don't need recipients. + if (m_User != 0) + //if (m_User != 0 && m_Recipients != 0 && m_Recipients->GetSize() > 0) + { + + User * aUser; + char * xstring = 0; + // Execute specific CAPI call (fetch, store, delete) + EFetchType outType; + char sDebugOut[100]; + t_int32 handleCount = 0; + t_int32 recipientCount = 0; + t_int32 extraUserHandle = 0; + CAPIStatus cStat = CAPI_ERR_OK; + + + // On a store or delete set handleCount to 1 (always try to use m_User) + if (GetType() == ETxnType_STORE || + GetType() == ETxnType_DELETE) + { + handleCount = 1; + extraUserHandle = 1; + } + + // If recipients, add size of recipients to handleCount + if (m_Recipients != 0) + { + handleCount += m_Recipients->GetSize(); + recipientCount = m_Recipients->GetSize(); + } + + //PR_ASSERT(outCalendars != 0); + + // TODO: horrible hack, restricting number of handles to 20 + CAPIHandle handles[20]; // wish I could do handles[handleCount] + if (handleCount > 20) + handleCount = 20; + + for (i = 0; i < handleCount; i++) + { + handles[i] = 0; + } + + // Capabilities + //if (FALSE) TRACE("CAPICapabilities:%s\r\n", CAPI_Capabilities((long) 0)); + //sprintf(sDebugOut, "CAPICapabilities:%s\r\n", CAPI_Capabilities((long) 0)); + + // Logon + + // TODO: eventually use the CAPAddress + //char * userxstring = m_User->getXString().toCString(""); + char * userlogonstring = m_User->getLogonString().toCString(""); + char * password = m_User->getPassword().toCString(""); + char * hostname = m_User->getHostname().toCString(""); + char * node = m_User->getNode().toCString(""); + PR_ASSERT(userlogonstring != 0 && password != 0 && hostname != 0 && node != 0); + +#ifdef TESTING_ITIPRIG + if (TRUE) TRACE("logon user: %s,\r\n password: %s,\r\n hostname: %s,\r\n node: %s,\r\n", + userlogonstring, password, hostname, node); +#endif + + cStat = CAPI_Logon(userlogonstring, password, hostname, 0, &pS); + //PR_ASSERT(FALSE); + + //if (FALSE) TRACE("CAPI_Logon:%lx\r\n", foo); + //sprintf(sDebugOut, "CAPI_Logon:%lx\r\n", foo); + + if (cStat != CAPI_ERR_OK && cStat != CAPI_ERR_EXPIRED) + { + status = TR_CAPI_LOGIN_FAILED; + } + else + { + + // On Store or Delete, Handle 0 will always be current user. + // Get Handle for each recipient and user, first m_User in handle[0] + + if (GetType() == ETxnType_STORE || + GetType() == ETxnType_DELETE) + { + xstring = m_User->getXString().toCString(""); + PR_ASSERT(xstring != 0); + CAPI_GetHandle(pS, xstring, 0, &handles[0]); + delete [] xstring; xstring = 0; + } + + if (m_Recipients != 0 && m_Recipients->GetSize() > 0) + { + for (i = 0; i < recipientCount; i++) + { + aUser = (User *) m_Recipients->GetAt(i); + xstring = aUser->getXString().toCString(""); + PR_ASSERT(xstring != 0); + CAPI_GetHandle(pS, xstring, 0, &handles[i + extraUserHandle]); + delete [] xstring; xstring = 0; + } + } + //if (FALSE) TRACE("CAPI_GetHandle:%lx\r\n", foo); + //sprintf(sDebugOut, "CAPI_GetHandle:%lx\r\n", foo); + + // HandleCAPI call + // OLD WAY + //foo = handleCAPI(pS, pH, m_Modifiers, &strings, + // &eventFetchedByUID, numstrings, outType); + // + cStat = handleCAPI(pS, &handles[0], handleCount, 0, m_ICalComponentVctr, m_Calendar, + m_Modifiers, outCalendars, outType); + + if (cStat != CAPI_ERR_OK) + { + if (status == TR_OK) + { + status = TR_CAPI_HANDLE_CAPI_FAILED; + } + } + + // Logoff + cStat = CAPI_Logoff(&pS, (long) 0); + if (cStat != CAPI_ERR_OK) + { + if (status == TR_OK) + { + status = TR_CAPI_LOGOFF_FAILED; + } + } + //if (FALSE) TRACE("CAPI_GetLogoff:%lx\r\n", foo); + //sprintf(sDebugOut, "CAPI_GetLogoff:%lx\r\n", status); + + // Destroy Handle + //foo = CAPI_DestroyHandle(&pH); + CAPI_DestroyHandles(pS, &handles[0], handleCount, 0); + + if (userlogonstring != 0) + { + delete [] userlogonstring; userlogonstring = 0; + } + if (password != 0) + { + delete [] password; password = 0; + } + if (hostname != 0) + { + delete [] hostname; hostname = 0; + } + if (node != 0) + { + delete [] node; node = 0; + } + } + } + return status; +} +#endif /* #if CAPI_READY */ +//--------------------------------------------------------------------- diff --git a/calendar/modules/network/itip/src/txnobjfy.cpp b/calendar/modules/network/itip/src/txnobjfy.cpp new file mode 100644 index 00000000000..04d932a5407 --- /dev/null +++ b/calendar/modules/network/itip/src/txnobjfy.cpp @@ -0,0 +1,115 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +/* + * txnobjfy.cpp + * John Sun + * 4/13/98 11:23:24 AM + */ + +#include "jdefines.h" +#include "julnstr.h" +#include "txnobjfy.h" +#include "sttxnobj.h" +#include "getxnobj.h" +#include "detxnobj.h" +#include "nscal.h" + +//--------------------------------------------------------------------- + +TransactionObjectFactory::TransactionObjectFactory() +{ + PR_ASSERT(FALSE); +} + +//--------------------------------------------------------------------- + +TransactionObject * +TransactionObjectFactory::Make(NSCalendar & cal, + JulianPtrArray & components, + User & user, + JulianPtrArray & recipients, + UnicodeString & subject, + JulianPtrArray & modifiers, + JulianForm * jf, + MWContext * context, + UnicodeString & attendeeName, + TransactionObject::EFetchType fetchType) +{ + TransactionObject * outTxnObj = 0; + + NSCalendar::METHOD method = cal.getMethod(); + + // For fetch type not set to NONE, make GetTransactionType + // ignore method arg + if (fetchType != TransactionObject::EFetchType_NONE) + { + outTxnObj = new GetTransactionObject(cal, components, user, + recipients, subject, modifiers, jf, context, attendeeName, fetchType); + } + else + { + switch (method) + { + case NSCalendar::METHOD_PUBLISH: + // store + outTxnObj = new StoreTransactionObject(cal, components, user, + recipients, subject, modifiers, jf, context, attendeeName); + break; + case NSCalendar::METHOD_REQUEST: + // store + outTxnObj = new StoreTransactionObject(cal, components, user, + recipients, subject, modifiers, jf, context, attendeeName); + break; + case NSCalendar::METHOD_REPLY: + // store + outTxnObj = new StoreTransactionObject(cal, components, user, + recipients, subject, modifiers, jf, context, attendeeName); + break; + case NSCalendar::METHOD_CANCEL: + // delete + outTxnObj = new DeleteTransactionObject(cal, components, user, + recipients, subject, modifiers, jf, context, attendeeName); + break; + case NSCalendar::METHOD_REFRESH: + // ??? store ??? + outTxnObj = new StoreTransactionObject(cal, components, user, + recipients, subject, modifiers, jf, context, attendeeName); + break; + case NSCalendar::METHOD_COUNTER: + // no CAPI, use IRIP, IMIP + outTxnObj = new StoreTransactionObject(cal, components, user, + recipients, subject, modifiers, jf, context, attendeeName); + break; + case NSCalendar::METHOD_DECLINECOUNTER: + // no CAPI, use IRIP, IMIP + outTxnObj = new StoreTransactionObject(cal, components, user, + recipients, subject, modifiers, jf, context, attendeeName); + break; + case NSCalendar::METHOD_ADD: + // store + outTxnObj = new StoreTransactionObject(cal, components, user, + recipients, subject, modifiers, jf, context, attendeeName); + break; + default: + break; + } + } + + return outTxnObj; +} diff --git a/calendar/modules/network/itip/src/user.cpp b/calendar/modules/network/itip/src/user.cpp new file mode 100644 index 00000000000..51529b6d8cb --- /dev/null +++ b/calendar/modules/network/itip/src/user.cpp @@ -0,0 +1,231 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +// user.cpp +// John Sun +// 3/10/98 2:58:33 PM + +#include "stdafx.h" +#include "jdefines.h" +#include "unistrto.h" +#include "user.h" + +//--------------------------------------------------------------------- + +User::User() +{ +#if CAPI_READY + m_Session = 0; +#endif +} + +//--------------------------------------------------------------------- + +User::~User() +{ +} + +//--------------------------------------------------------------------- + +User::User(UnicodeString realName, UnicodeString imip) +{ + m_RealName = realName; + m_IMIPAddress = imip; + m_CAPIAddress = ""; + m_IRIPAddress = ""; + m_XItemID = -1; +#if CAPI_READY + m_Session = 0; +#endif +} + +//--------------------------------------------------------------------- + +User::User(UnicodeString realName, UnicodeString imip, + UnicodeString capi, UnicodeString irip, + t_int32 xItemID) +{ + m_RealName = realName; + m_CAPIAddress = capi; + m_IRIPAddress = irip; + m_IMIPAddress = imip; + m_XItemID = xItemID; +#if CAPI_READY + m_Session = 0; +#endif +} + +//--------------------------------------------------------------------- + +User::User(User & that) +{ + m_CAPIAddress = that.m_CAPIAddress; + m_IMIPAddress = that.m_IMIPAddress; + m_IRIPAddress = that.m_IRIPAddress; + m_RealName = that.m_RealName; + m_LoginName = that.m_LoginName ; + m_Password = that.m_Password; + m_Hostname = that.m_Hostname; + m_Node = that.m_Node; +#if CAPI_READY + m_Session = 0; // can't copy session's +#endif +} +//--------------------------------------------------------------------- + +User * +User::clone() +{ + return new User(*this); +} + +//--------------------------------------------------------------------- + +UnicodeString +User::toString() +{ + char sNum[20]; + sprintf(sNum, "%d", m_XItemID); + UnicodeString out; + out += "realname: "; + out += m_RealName; + out += "\r\nCAPI Addr.: "; + out += m_CAPIAddress; + out += " XItemID: "; + out += sNum; + out += "\r\nIRIP Addr.: "; + out += m_IRIPAddress; + out += "\r\nIMIP Addr.: "; + out += m_IMIPAddress; + return out; +} + +//--------------------------------------------------------------------- + +UnicodeString +User::getXString() +{ + UnicodeString out; + if (m_LoginName.size() > 0) + { + return MakeXString(m_LoginName, out); + } + else + return MakeXString(m_RealName, out); +} + +//--------------------------------------------------------------------- + +UnicodeString +User::getLogonString() +{ + UnicodeString out; + if (m_LoginName.size() > 0) + { + return MakeCAPILogonString(m_LoginName, m_Node, out); + } + else + return MakeCAPILogonString(m_RealName, m_Node, out); +} + +//--------------------------------------------------------------------- + +UnicodeString & +User::MakeXString(UnicodeString & realName, UnicodeString & out) +{ + out = ""; + UnicodeStringTokenizer * st; + UnicodeString u = " "; + st = new UnicodeStringTokenizer(realName, u); + if (st != 0) + { + UnicodeString sirName, givenName; + if (st->hasMoreTokens()) + { + ErrorCode status = ZERO_ERROR; + givenName = st->nextToken(u, status); + while (st->hasMoreTokens()) + { + // last name may have spaces + sirName += st->nextToken(u, status); + } + + } + out += "S="; + out += sirName; + out += "/G="; + out += givenName; + delete st; st = 0; + } + return out; +} + +//--------------------------------------------------------------------- + +UnicodeString & +User::MakeCAPILogonString(UnicodeString & realName, + UnicodeString & node, + UnicodeString & out) +{ + MakeXString(realName, out); + out.insert(0, ":/"); + out += "/ND="; + out += node; + out += "/"; + return out; +} + +//--------------------------------------------------------------------- + +void +User::deleteUserVector(JulianPtrArray * users) +{ + t_int32 i; + if (users != 0) + { + for (i = users->GetSize() - 1; i >= 0; i--) + { + delete ((User *) users->GetAt(i)); + } + } +} + +//--------------------------------------------------------------------- + +void +User::cloneUserVector(JulianPtrArray * toClone, + JulianPtrArray * out) +{ + if (out != 0) + { + if (toClone != 0) + { + t_int32 i; + User * comp; + User * clone; + for (i = 0; i < toClone->GetSize(); i++) + { + comp = (User *) toClone->GetAt(i); + clone = comp->clone(); + out->Add(clone); + } + } + } +} +//--------------------------------------------------------------------- + diff --git a/calendar/modules/network/manifest.mn b/calendar/modules/network/manifest.mn index a1e3a46421f..e69de29bb2d 100644 --- a/calendar/modules/network/manifest.mn +++ b/calendar/modules/network/manifest.mn @@ -1,23 +0,0 @@ -# -# CONFIDENTIAL AND PROPRIETARY SOURCE CODE OF -# NETSCAPE COMMUNICATIONS CORPORATION -# Copyright (C) 1996 Netscape Communications Corporation. All Rights -# Reserved. Use of this Source Code is subject to the terms of the -# applicable license agreement from Netscape Communications Corporation. -# The copyright notice(s) in this Source Code does not indicate actual or -# intended publication of this Source Code. -# -GDEPTH = ../../.. -DEPTH = ../../.. - -DIRS = capi - -EXPORTS = \ - $(NULL) - -PRIVATE_EXPORTS = \ - $(NULL) - -MODULE = trex - -REQUIRES = xpcom raptor shell trex diff --git a/calendar/modules/nls/nlsstub/inc/calendar.h b/calendar/modules/nls/nlsstub/inc/calendar.h new file mode 100644 index 00000000000..55ddc331375 --- /dev/null +++ b/calendar/modules/nls/nlsstub/inc/calendar.h @@ -0,0 +1,107 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +#ifndef calendar_h__ +#define calendar_h__ + +#include "ptypes.h" +#include "parsepos.h" +#include "nspr.h" +#include "prtime.h" +#include "prprf.h" + +class TimeZone; +class ParsePosition; + +class NS_NLS Calendar +{ + +public: + + enum EMonths { + JANUARY, + FEBRUARY, + MARCH, + APRIL, + MAY, + JUNE, + JULY, + AUGUST, + SEPTEMBER, + OCTOBER, + NOVEMBER, + DECEMBER, + UNDECIMBER + }; + + enum EDateFields + { + SECOND, + DAY_OF_WEEK_IN_MONTH, + MINUTE, + HOUR, + DAY_OF_YEAR, + WEEK_OF_YEAR, + MONTH, + DATE, + DAY_OF_WEEK, + DAY_OF_MONTH, + HOUR_OF_DAY, + YEAR + }; + + enum EDaysOfWeek + { + SUNDAY = 1, + MONDAY, + TUESDAY, + WEDNESDAY, + THURSDAY, + FRIDAY, + SATURDAY + }; + +public: + Calendar(); + ~Calendar(); + + static Date getNow(); + void setTimeZone(const TimeZone& aZone); + Date getTime(ErrorCode& aStatus) const; + PRInt32 get(EDateFields aField, ErrorCode& aStatus) const; + void setTime(Date aDate, ErrorCode& aStatus); + void set(EDateFields aField, PRInt32 aValue); + void set(PRInt32 aYear, PRInt32 aMonth, PRInt32 aDate); + void set(PRInt32 aYear, PRInt32 aMonth, PRInt32 aDate, PRInt32 aHour, PRInt32 aMinute); + void set(PRInt32 aYear, PRInt32 aMonth, PRInt32 aDate, PRInt32 aHour, PRInt32 aMinute, PRInt32 aSecond); + virtual void add(EDateFields aField, PRInt32 aAmount, ErrorCode& aStatus) = 0; + + void clear(); + void clear(EDateFields aField); + +public: + PRTime mTime; + PRExplodedTime mExplodedTime; + +private: + TimeZone * mTimeZone ; + + +}; + +#endif diff --git a/calendar/modules/nls/nlsstub/inc/datefmt.h b/calendar/modules/nls/nlsstub/inc/datefmt.h new file mode 100644 index 00000000000..9f3aca5288b --- /dev/null +++ b/calendar/modules/nls/nlsstub/inc/datefmt.h @@ -0,0 +1,46 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +#ifndef datefmt_h__ +#define datefmt_h__ + +#include "prtypes.h" +#include "unistring.h" + +class ParsePosition; +class Format; +class TimeZone; + +class NS_NLS DateFormat +{ + +public: + DateFormat(); + ~DateFormat(); + + virtual void setLenient(PRBool aLenient); + virtual void setTimeZone(const TimeZone& aZone); + virtual Date parse(const UnicodeString& aUnicodeString, ErrorCode& aStatus) const; + virtual Date parse(const UnicodeString& aUnicodeString, ParsePosition& aPosition) const = 0; + + virtual PRBool operator==(const Format& aFormat) const; + +}; + + +#endif diff --git a/calendar/modules/nls/nlsstub/inc/gregocal.h b/calendar/modules/nls/nlsstub/inc/gregocal.h new file mode 100644 index 00000000000..043932ca83c --- /dev/null +++ b/calendar/modules/nls/nlsstub/inc/gregocal.h @@ -0,0 +1,52 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +#ifndef gregocal_h__ +#define gregocal_h__ + +#include "ptypes.h" +#include "calendar.h" + +class TimeZone; +class Locale; + +class NS_NLS GregorianCalendar : public Calendar +{ + +public: + GregorianCalendar(); + ~GregorianCalendar(); + + GregorianCalendar(ErrorCode& aSuccess); + GregorianCalendar(TimeZone* aZoneToAdopt, ErrorCode& aSuccess); + GregorianCalendar(const TimeZone& aZone, ErrorCode& aSuccess); + GregorianCalendar(const Locale& aLocale, ErrorCode& aSuccess); + GregorianCalendar(TimeZone* aZoneToAdopt, const Locale& aLocale, ErrorCode& aSuccess); + GregorianCalendar(const TimeZone& aZone, const Locale& aLocale, ErrorCode& aSuccess); + GregorianCalendar(PRInt32 aYear, PRInt32 aMonth, PRInt32 aDate, ErrorCode& aSuccess); + GregorianCalendar(PRInt32 aYear, PRInt32 aMonth, PRInt32 aDate, PRInt32 aHour, PRInt32 aMinute, ErrorCode& aSuccess); + GregorianCalendar(PRInt32 aYear, PRInt32 aMonth, PRInt32 aDate, PRInt32 aHour, PRInt32 aMinute, PRInt32 aSecond, ErrorCode& aSuccess); + + virtual void add(EDateFields aField, PRInt32 aAmount, ErrorCode& aStatus); + +}; + + + + +#endif diff --git a/calendar/modules/nls/nlsstub/inc/hashtab.h b/calendar/modules/nls/nlsstub/inc/hashtab.h new file mode 100644 index 00000000000..b5b361f07f4 --- /dev/null +++ b/calendar/modules/nls/nlsstub/inc/hashtab.h @@ -0,0 +1,23 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +#ifndef hashtab_h__ +#define hashtab_h__ + + +#endif diff --git a/calendar/modules/nls/nlsstub/inc/locid.h b/calendar/modules/nls/nlsstub/inc/locid.h new file mode 100644 index 00000000000..04263908e92 --- /dev/null +++ b/calendar/modules/nls/nlsstub/inc/locid.h @@ -0,0 +1,38 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +#ifndef locid_h__ +#define locid_h__ + +#include "ptypes.h" + +class UnicodeString; + +class NS_NLS Locale +{ + +public: + Locale(); + ~Locale(); + + static const Locale& getDefault(); + UnicodeString& getName(UnicodeString& aName) const; + +}; + +#endif diff --git a/calendar/modules/nls/nlsstub/inc/nlsloc.h b/calendar/modules/nls/nlsstub/inc/nlsloc.h new file mode 100644 index 00000000000..b4edbab9e6b --- /dev/null +++ b/calendar/modules/nls/nlsstub/inc/nlsloc.h @@ -0,0 +1,30 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +#ifndef nlsloc_h__ +#define nlsloc_h__ + +#include "ptypes.h" + +typedef PRUint32 NLS_ThreadInfo; +typedef PRUint32 NLS_ErrorCode; + +NLS_ErrorCode NS_NLS NLS_Initialize(const NLS_ThreadInfo * aThreadInfo, const char * aDataDirectory); +NLS_ErrorCode NS_NLS NLS_Terminate(void); + +#endif diff --git a/calendar/modules/nls/nlsstub/inc/parsepos.h b/calendar/modules/nls/nlsstub/inc/parsepos.h new file mode 100644 index 00000000000..aed0d20b940 --- /dev/null +++ b/calendar/modules/nls/nlsstub/inc/parsepos.h @@ -0,0 +1,39 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +#ifndef parsepos_h__ +#define parsepos_h__ + +#include "ptypes.h" + +class NS_NLS ParsePosition +{ + +public: + ParsePosition(); + ~ParsePosition(); + + ParsePosition(TextOffset aIndex); + ParsePosition(const ParsePosition& aParsePosition); + + PRBool operator==(const ParsePosition& aParsePosition) const; + +}; + + +#endif diff --git a/calendar/modules/nls/nlsstub/inc/ptypes.h b/calendar/modules/nls/nlsstub/inc/ptypes.h new file mode 100644 index 00000000000..8a75dbc2418 --- /dev/null +++ b/calendar/modules/nls/nlsstub/inc/ptypes.h @@ -0,0 +1,50 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +#ifndef ptypes_h__ +#define ptypes_h__ + +#include "nscore.h" +#include "nspr.h" + +typedef double Date; + +#define ZERO_ERROR 0 + +typedef PRInt32 ErrorCode; +typedef PRInt8 t_int8; +typedef PRInt32 t_int32; +typedef PRBool t_bool; +typedef PRInt32 TextOffset; + +#ifdef _IMPL_NS_NLS +#define NS_NLS NS_EXPORT +#else +#define NS_NLS NS_IMPORT +#endif + + +#define SUCCESS(x) ((x)<=ZERO_ERROR) +#define FAILURE(x) ((x)>ZERO_ERROR) + +#define kMillisPerSecond (PR_INT32(PR_MSEC_PER_SEC)) +#define kMillisPerMinute (PR_INT32(60) * kMillisPerSecond) +#define kMillisPerHour (PR_INT32(60) * kMillisPerMinute) +#define kMillisPerDay (PR_INT32(24) * kMillisPerHour) + +#endif diff --git a/calendar/modules/nls/nlsstub/inc/simpletz.h b/calendar/modules/nls/nlsstub/inc/simpletz.h new file mode 100644 index 00000000000..e864f98f736 --- /dev/null +++ b/calendar/modules/nls/nlsstub/inc/simpletz.h @@ -0,0 +1,46 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +#ifndef simpletz_h__ +#define simpletz_h__ + +#include "timezone.h" + +class NS_NLS SimpleTimeZone : public TimeZone +{ + +public: + SimpleTimeZone(); + ~SimpleTimeZone(); + SimpleTimeZone(PRInt32 aRawOffset, const UnicodeString& aID); + + SimpleTimeZone(PRInt32 aRawOffset, const UnicodeString& aID, + PRInt8 aStartMonth, PRInt8 aStartDayOfWeekInMonth, + PRInt8 aStartDayOfWeek, PRInt32 aStartTime, + PRInt8 aEndMonth, PRInt8 aEndDayOfWeekInMonth, + PRInt8 aEndDayOfWeek, PRInt32 aEndTime, + PRInt32 aDstSavings = kMillisPerHour); + + virtual TimeZone* clone() const; + virtual void setRawOffset(PRInt32 aOffsetMillis); + void setStartRule(PRInt32 aMonth, PRInt32 aDayOfWeekInMonth, PRInt32 aDayOfWeek, PRInt32 aTime); + void setEndRule(PRInt32 aMonth, PRInt32 aDayOfWeekInMonth, PRInt32 aDayOfWeek, PRInt32 aTime); + +}; + +#endif diff --git a/calendar/modules/nls/nlsstub/inc/smpdtfmt.h b/calendar/modules/nls/nlsstub/inc/smpdtfmt.h new file mode 100644 index 00000000000..8109feb2f20 --- /dev/null +++ b/calendar/modules/nls/nlsstub/inc/smpdtfmt.h @@ -0,0 +1,55 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +#ifndef smpdtfmt_h__ +#define smpdtfmt_h__ + +#include "prtypes.h" +#include "datefmt.h" + +class UnicodeString; +class Formattable; +class ParsePosition; +class Format; + +class NS_NLS FieldPosition +{ +public: + FieldPosition(); + ~FieldPosition(); + FieldPosition(PRInt32 aField); +}; + +class NS_NLS SimpleDateFormat : public DateFormat +{ +public: + SimpleDateFormat(); + ~SimpleDateFormat(); + SimpleDateFormat(ErrorCode& aStatus); + + SimpleDateFormat(const UnicodeString& aPattern, const Locale& aLocale, ErrorCode& aStatus); + + virtual UnicodeString& format(Date aDate, UnicodeString& aAppendTo, FieldPosition& aPosition) const; + virtual UnicodeString& format(const Formattable& aObject, UnicodeString& aAppendTo, FieldPosition& aPosition, ErrorCode& aStatus) const; + virtual void applyLocalizedPattern(const UnicodeString& aPattern, ErrorCode& aStatus); + virtual Date parse(const UnicodeString& aUnicodeString, ParsePosition& aPosition) const; + + virtual PRBool operator==(const Format& other) const; + +}; +#endif diff --git a/calendar/modules/nls/nlsstub/inc/timezone.h b/calendar/modules/nls/nlsstub/inc/timezone.h new file mode 100644 index 00000000000..3031db6babf --- /dev/null +++ b/calendar/modules/nls/nlsstub/inc/timezone.h @@ -0,0 +1,40 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +#ifndef timezone_h__ +#define timezone_h__ + +#include "ptypes.h" + +class UnicodeString; + +class NS_NLS TimeZone +{ + +public: + TimeZone(); + ~TimeZone(); + + static TimeZone* createDefault(); + static TimeZone* createTimeZone(const UnicodeString& aID); + void setID(const UnicodeString& aID); + +}; + + +#endif diff --git a/calendar/modules/nls/nlsstub/inc/unicode.h b/calendar/modules/nls/nlsstub/inc/unicode.h new file mode 100644 index 00000000000..522e511e5e1 --- /dev/null +++ b/calendar/modules/nls/nlsstub/inc/unicode.h @@ -0,0 +1,23 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +#ifndef unicode_h__ +#define unicode_h__ + + +#endif diff --git a/calendar/modules/nls/nlsstub/inc/unistring.h b/calendar/modules/nls/nlsstub/inc/unistring.h new file mode 100644 index 00000000000..f78823811af --- /dev/null +++ b/calendar/modules/nls/nlsstub/inc/unistring.h @@ -0,0 +1,94 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +#ifndef unistring_h__ +#define unistring_h__ + +#include "nscore.h" +#include "nsString.h" +#include "nspr.h" +#include "limits.h" + +#include "ptypes.h" + +class Locale; + +class NS_NLS UnicodeString +{ + +public: + UnicodeString(); + ~UnicodeString(); + + UnicodeString(const UnicodeString& aUnicodeString); + UnicodeString(const char * aString); + + PRUint32 size() { return mLength; } + PRInt32 hashCode() const; + + TextOffset indexOf(const UnicodeString& aUnicodeString, TextOffset aFromOffset = 0, PRUint32 aForLength = -1) const; + TextOffset indexOf(PRUnichar aUnichar, TextOffset aFromOffset = 0, PRUint32 aForLength = -1) const; + + UnicodeString& extractBetween(TextOffset aStart, TextOffset aLimit, UnicodeString& aExtractInto) const; + + PRInt32 compareIgnoreCase(const UnicodeString& aUnicodeString) const; + PRInt32 compareIgnoreCase(const PRUnichar* aUnichar, PRInt32 aLength) const; + PRInt32 compareIgnoreCase(const PRUnichar* aUnichar) const; + PRInt32 compareIgnoreCase(const char* aChar, const char* aEncoding) const; + PRInt32 compareIgnoreCase(const char* aChar) const; + UnicodeString& toUpper(); + UnicodeString& toUpper(const Locale& aLocale); + + char* toCString(const char* aEncoding) const; + + UnicodeString& trim(UnicodeString& aUnicodeString) const; + void trim(); + UnicodeString& remove(); + UnicodeString& remove(TextOffset aOffset,PRInt32 aLength = LONG_MAX); + UnicodeString& insert(TextOffset aThisOffset, const UnicodeString& aUnicodeString); + PRBool startsWith(const UnicodeString& aUnicodeString) const; + PRBool endsWith(const UnicodeString& aUnicodeString) const; + UnicodeString& removeBetween(TextOffset aStart = 0, TextOffset aLimit = LONG_MAX); + + + PRInt8 compare(const UnicodeString& aUnicodeString) const; + PRInt8 compare(TextOffset aOffset, PRInt32 aThisLength, const UnicodeString& aUnicodeString, TextOffset aStringOffset, PRInt32 aLength) const; + PRInt8 compare(const PRUnichar* aUnichar) const; + PRInt8 compare(const PRUnichar* aUnichar, PRInt32 aLength) const; + PRInt8 compare(const char* aChar) const; + + UnicodeString& extract(TextOffset aOffset,PRInt32 aLength, UnicodeString& aExtractInto) const; + void extract(TextOffset aOffset, PRInt32 aLength, PRUnichar*aExtractInto) const; + void extract(TextOffset aOffset, PRInt32 aLength, char* aExtractInto) const; + + +public: + PRUnichar operator[](TextOffset aOffset) const; + PRUnichar& operator[](TextOffset aOffset); + UnicodeString& operator+=(const UnicodeString& aUnicodeString); + UnicodeString& operator+=(PRUnichar aUnichar); + PRBool operator==(const UnicodeString& aUnicodeString) const; + PRBool operator!=(const UnicodeString& aUnicodeString) const; + UnicodeString& operator=(const UnicodeString& aUnicodeString); + +public: + PRUint32 mLength; + nsString mString; +}; + +#endif diff --git a/calendar/modules/nls/nlsstub/src/calendar.cpp b/calendar/modules/nls/nlsstub/src/calendar.cpp new file mode 100644 index 00000000000..6924c73a68b --- /dev/null +++ b/calendar/modules/nls/nlsstub/src/calendar.cpp @@ -0,0 +1,249 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + + +#include "nscore.h" +#include "calendar.h" +#include "prtime.h" + +Calendar::Calendar() +{ + mTimeZone = nsnull; + LL_I2L(mTime, 0); + PR_ExplodeTime(mTime, PR_GMTParameters, &mExplodedTime); +} + +Calendar::~Calendar() +{ +} + +Date Calendar::getNow() +{ + Date d; + + PRTime t; + + t = (PRTime) PR_Now(); + + LL_L2D(d,t); + + return ((Date)d); +} + +void Calendar::setTimeZone(const TimeZone& aZone) +{ + mTimeZone = (TimeZone *)(&aZone); + return ; +} + +Date Calendar::getTime(ErrorCode& aStatus) const +{ + Date d; + + LL_L2D(d,mTime); + + return ((Date)d); +} + + +PRInt32 Calendar::get(EDateFields aField, ErrorCode& aStatus) const +{ + PRInt32 field = 0; + + PR_ExplodeTime(mTime, PR_GMTParameters, (PRExplodedTime*)(&mExplodedTime)); + + switch(aField) + { + case SECOND: + field = mExplodedTime.tm_sec; + break; + + case DAY_OF_WEEK_IN_MONTH: + field = 0; + break; + + case MINUTE: + field = mExplodedTime.tm_min; + break; + + case HOUR: + field = mExplodedTime.tm_hour; + break; + + case DAY_OF_YEAR: + field = mExplodedTime.tm_yday; + break; + + case WEEK_OF_YEAR: + field = 0; + break; + + case MONTH: + field = mExplodedTime.tm_month; + break; + + case DATE: + field = mExplodedTime.tm_mday; + break; + + case DAY_OF_WEEK: + field = mExplodedTime.tm_wday; + break; + + case DAY_OF_MONTH: + field = 0; + break; + + case HOUR_OF_DAY: + field = mExplodedTime.tm_hour; + break; + + case YEAR: + field = mExplodedTime.tm_year; + break; + + default: + field = 0; + break; + + } + + return (field); +} + +void Calendar::setTime(Date aDate, ErrorCode& aStatus) +{ + LL_D2L(mTime,aDate); + PR_ExplodeTime(mTime, PR_GMTParameters, &mExplodedTime); + return; +} + +void Calendar::set(EDateFields aField, PRInt32 aValue) +{ + switch(aField) + { + case SECOND: + mExplodedTime.tm_sec = aValue; + break; + + case DAY_OF_WEEK_IN_MONTH: + break; + + case MINUTE: + mExplodedTime.tm_min = aValue; + break; + + case HOUR: + mExplodedTime.tm_hour = aValue; + break; + + case DAY_OF_YEAR: + break; + + case WEEK_OF_YEAR: + break; + + case MONTH: + mExplodedTime.tm_month = aValue; + break; + + case DATE: + mExplodedTime.tm_mday = aValue; + break; + + case DAY_OF_WEEK: + break; + + case DAY_OF_MONTH: + break; + + case HOUR_OF_DAY: + mExplodedTime.tm_hour = aValue; + break; + + case YEAR: + mExplodedTime.tm_year = aValue; + break; + + default: + break; + + } + + mTime = PR_ImplodeTime(&mExplodedTime); + PR_ExplodeTime(mTime, PR_GMTParameters, &mExplodedTime); + + return ; +} + +void Calendar::set(PRInt32 aYear, PRInt32 aMonth, PRInt32 aDate) +{ + mExplodedTime.tm_year = aYear; + mExplodedTime.tm_month = aMonth; + mExplodedTime.tm_mday = aDate; + + mTime = PR_ImplodeTime(&mExplodedTime); + + PR_ExplodeTime(mTime, PR_GMTParameters, &mExplodedTime); + + return ; +} + +void Calendar::set(PRInt32 aYear, PRInt32 aMonth, PRInt32 aDate, PRInt32 aHour, PRInt32 aMinute) +{ + mExplodedTime.tm_year = aYear; + mExplodedTime.tm_month = aMonth; + mExplodedTime.tm_mday = aDate; + mExplodedTime.tm_hour = aHour; + mExplodedTime.tm_min = aMinute; + + mTime = PR_ImplodeTime(&mExplodedTime); + + PR_ExplodeTime(mTime, PR_GMTParameters, &mExplodedTime); + + return ; +} + +void Calendar::set(PRInt32 aYear, PRInt32 aMonth, PRInt32 aDate, PRInt32 aHour, PRInt32 aMinute, PRInt32 aSecond) +{ + mExplodedTime.tm_year = aYear; + mExplodedTime.tm_month = aMonth; + mExplodedTime.tm_mday = aDate; + mExplodedTime.tm_hour = aHour; + mExplodedTime.tm_min = aMinute; + mExplodedTime.tm_sec = aSecond; + + mTime = PR_ImplodeTime(&mExplodedTime); + + PR_ExplodeTime(mTime, PR_GMTParameters, &mExplodedTime); + return ; +} + +void Calendar::clear() +{ + LL_I2L(mTime, 0); + PR_ExplodeTime(mTime, PR_GMTParameters, &mExplodedTime); + return ; +} + +void Calendar::clear(EDateFields aField) +{ + set(aField,0); + return ; +} + diff --git a/calendar/modules/nls/nlsstub/src/datefmt.cpp b/calendar/modules/nls/nlsstub/src/datefmt.cpp new file mode 100644 index 00000000000..7bb432e4eba --- /dev/null +++ b/calendar/modules/nls/nlsstub/src/datefmt.cpp @@ -0,0 +1,53 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +#include "nscore.h" +#include "datefmt.h" +#include "unistring.h" +#include "time.h" + +DateFormat::DateFormat() +{ +} + +DateFormat::~DateFormat() +{ +} + +void DateFormat::setLenient(PRBool aLenient) +{ + return; +} + +void DateFormat::setTimeZone(const TimeZone& aZone) +{ + return; +} + +Date DateFormat::parse(const UnicodeString& aUnicodeString, ErrorCode& aStatus) const +{ + // XXX + time_t t; + time(&t); + return ((Date)t*kMillisPerSecond); +} + +PRBool DateFormat::operator==(const Format& aFormat) const +{ + return (PR_TRUE); +} diff --git a/calendar/modules/nls/nlsstub/src/gregocal.cpp b/calendar/modules/nls/nlsstub/src/gregocal.cpp new file mode 100644 index 00000000000..45d36eea21c --- /dev/null +++ b/calendar/modules/nls/nlsstub/src/gregocal.cpp @@ -0,0 +1,138 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +#include "gregocal.h" + +GregorianCalendar::GregorianCalendar() : Calendar() +{ +} + +GregorianCalendar::~GregorianCalendar() +{ +} + +GregorianCalendar::GregorianCalendar(ErrorCode& aSuccess) : Calendar() +{ +} + +GregorianCalendar::GregorianCalendar(TimeZone* aZoneToAdopt, ErrorCode& aSuccess) : Calendar() +{ + setTimeZone(*aZoneToAdopt); +} + +GregorianCalendar::GregorianCalendar(const TimeZone& aZone, ErrorCode& aSuccess) : Calendar() +{ + setTimeZone(aZone); +} + +GregorianCalendar::GregorianCalendar(const Locale& aLocale, ErrorCode& aSuccess) : Calendar() +{ +} + +GregorianCalendar::GregorianCalendar(TimeZone* aZoneToAdopt, const Locale& aLocale, ErrorCode& aSuccess) : Calendar() +{ + setTimeZone(*aZoneToAdopt); +} + +GregorianCalendar::GregorianCalendar(const TimeZone& aZone, const Locale& aLocale, ErrorCode& aSuccess) + : Calendar() +{ + setTimeZone(aZone); +} + +GregorianCalendar::GregorianCalendar(PRInt32 aYear, PRInt32 aMonth, PRInt32 aDate, ErrorCode& aSuccess) + : Calendar() +{ + set(aYear, aMonth, aDate); +} + +GregorianCalendar::GregorianCalendar(PRInt32 aYear, PRInt32 aMonth, PRInt32 aDate, PRInt32 aHour, PRInt32 aMinute, ErrorCode& aSuccess) + : Calendar() +{ + set(aYear, aMonth, aDate, aHour, aMinute); +} + +GregorianCalendar::GregorianCalendar(PRInt32 aYear, PRInt32 aMonth, PRInt32 aDate, PRInt32 aHour, PRInt32 aMinute, PRInt32 aSecond, ErrorCode& aSuccess) + : Calendar() +{ + set(aYear, aMonth, aDate, aHour, aMinute, aSecond); +} + +void GregorianCalendar::add(EDateFields aField, PRInt32 aAmount, ErrorCode& aStatus) +{ + switch(aField) + { + case SECOND: + mExplodedTime.tm_sec += aAmount; + break; + + case DAY_OF_WEEK_IN_MONTH: + break; + + case MINUTE: + mExplodedTime.tm_min += aAmount; + break; + + case HOUR: + mExplodedTime.tm_hour += aAmount; + break; + + case DAY_OF_YEAR: + mExplodedTime.tm_mday += aAmount; + break; + + case WEEK_OF_YEAR: + break; + + case MONTH: + mExplodedTime.tm_month += aAmount; + break; + + case DATE: + mExplodedTime.tm_mday += aAmount; + break; + + case DAY_OF_WEEK: + break; + + case DAY_OF_MONTH: + break; + + case HOUR_OF_DAY: + mExplodedTime.tm_hour += aAmount; + break; + + case YEAR: + mExplodedTime.tm_year += aAmount; + break; + + default: + break; + + } + + PR_NormalizeTime(&mExplodedTime,PR_GMTParameters); + + mTime = PR_ImplodeTime(&mExplodedTime); + + PR_ExplodeTime(mTime, PR_GMTParameters, &mExplodedTime); + + return; +} + + diff --git a/calendar/modules/nls/nlsstub/src/locid.cpp b/calendar/modules/nls/nlsstub/src/locid.cpp new file mode 100644 index 00000000000..a488849c2de --- /dev/null +++ b/calendar/modules/nls/nlsstub/src/locid.cpp @@ -0,0 +1,41 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +#include "locid.h" +#include "unistring.h" + +static UnicodeString u("Locale Name Goes Here"); +static Locale l; + +Locale::Locale() +{ +} + +Locale::~Locale() +{ +} + +const Locale& Locale::getDefault() +{ + return (l); +} + +UnicodeString& Locale::getName(UnicodeString& aName) const +{ + return (u); +} diff --git a/calendar/modules/nls/nlsstub/src/nlsloc.cpp b/calendar/modules/nls/nlsstub/src/nlsloc.cpp new file mode 100644 index 00000000000..577805c168d --- /dev/null +++ b/calendar/modules/nls/nlsstub/src/nlsloc.cpp @@ -0,0 +1,30 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +#include "nlsloc.h" + +NLS_ErrorCode NLS_Initialize(const NLS_ThreadInfo * aThreadInfo, const char * aDataDirectory) +{ + return 0; +} + +NLS_ErrorCode NLS_Terminate(void) +{ + return 0; +} + diff --git a/calendar/modules/nls/nlsstub/src/parsepos.cpp b/calendar/modules/nls/nlsstub/src/parsepos.cpp new file mode 100644 index 00000000000..6e90f3d536f --- /dev/null +++ b/calendar/modules/nls/nlsstub/src/parsepos.cpp @@ -0,0 +1,42 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +#include "parsepos.h" + +ParsePosition::ParsePosition() +{ +} + +ParsePosition::~ParsePosition() +{ +} + + +ParsePosition::ParsePosition(TextOffset aIndex) +{ +} + +ParsePosition::ParsePosition(const ParsePosition& aParsePosition) +{ +} + +PRBool ParsePosition::operator==(const ParsePosition& aParsePosition) const +{ + return (PR_TRUE); +} + diff --git a/calendar/modules/nls/nlsstub/src/simpletz.cpp b/calendar/modules/nls/nlsstub/src/simpletz.cpp new file mode 100644 index 00000000000..a43fdcacd75 --- /dev/null +++ b/calendar/modules/nls/nlsstub/src/simpletz.cpp @@ -0,0 +1,64 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +#include "nscore.h" +#include "simpletz.h" + +SimpleTimeZone::SimpleTimeZone() : TimeZone() +{ +} + +SimpleTimeZone::~SimpleTimeZone() +{ +} + +SimpleTimeZone::SimpleTimeZone(PRInt32 aRawOffset, const UnicodeString& aID) : TimeZone() +{ +} + +SimpleTimeZone::SimpleTimeZone(PRInt32 aRawOffset, const UnicodeString& aID, + PRInt8 aStartMonth, PRInt8 aStartDayOfWeekInMonth, + PRInt8 aStartDayOfWeek, PRInt32 aStartTime, + PRInt8 aEndMonth, PRInt8 aEndDayOfWeekInMonth, + PRInt8 aEndDayOfWeek, PRInt32 aEndTime, + PRInt32 aDstSavings) : TimeZone() +{ +} + +TimeZone* SimpleTimeZone::clone() const +{ + TimeZone * t = (TimeZone*) new TimeZone(); + return t; +} + +void SimpleTimeZone::setRawOffset(PRInt32 aOffsetMillis) +{ + return ; +} + +void SimpleTimeZone::setStartRule(PRInt32 aMonth, PRInt32 aDayOfWeekInMonth, PRInt32 aDayOfWeek, PRInt32 aTime) +{ + return ; +} + +void SimpleTimeZone::setEndRule(PRInt32 aMonth, PRInt32 aDayOfWeekInMonth, PRInt32 aDayOfWeek, PRInt32 aTime) +{ + return ; +} + + diff --git a/calendar/modules/nls/nlsstub/src/smpdtfmt.cpp b/calendar/modules/nls/nlsstub/src/smpdtfmt.cpp new file mode 100644 index 00000000000..84b7518f899 --- /dev/null +++ b/calendar/modules/nls/nlsstub/src/smpdtfmt.cpp @@ -0,0 +1,80 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +#include "smpdtfmt.h" +#include "time.h" + +static UnicodeString u("06/06/66"); + +FieldPosition::FieldPosition() +{ +} + +FieldPosition::~FieldPosition() +{ +} + +FieldPosition::FieldPosition(PRInt32 aField) +{ +} + + +SimpleDateFormat::SimpleDateFormat() : DateFormat() +{ +} + +SimpleDateFormat::~SimpleDateFormat() +{ +} + +SimpleDateFormat::SimpleDateFormat(ErrorCode& aStatus) : DateFormat() +{ +} + +SimpleDateFormat::SimpleDateFormat(const UnicodeString& aPattern, const Locale& aLocale, ErrorCode& aStatus) : DateFormat() +{ +} + + +UnicodeString& SimpleDateFormat::format(Date aDate, UnicodeString& aAppendTo, FieldPosition& aPosition) const +{ + return (u); +} + +UnicodeString& SimpleDateFormat::format(const Formattable& aObject, UnicodeString& aAppendTo, FieldPosition& aPosition, ErrorCode& aStatus) const +{ + return (u); +} + +void SimpleDateFormat::applyLocalizedPattern(const UnicodeString& aPattern, ErrorCode& aStatus) +{ + return ; +} + +Date SimpleDateFormat::parse(const UnicodeString& aUnicodeString, ParsePosition& aPosition) const +{ + time_t t; + time(&t); + return ((Date)t*kMillisPerSecond); +} + +PRBool SimpleDateFormat::operator==(const Format& other) const +{ + return PR_TRUE; +} + diff --git a/calendar/modules/nls/nlsstub/src/timezone.cpp b/calendar/modules/nls/nlsstub/src/timezone.cpp new file mode 100644 index 00000000000..7a97af99e3b --- /dev/null +++ b/calendar/modules/nls/nlsstub/src/timezone.cpp @@ -0,0 +1,46 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +#include "timezone.h" +#include "unistring.h" + +TimeZone::TimeZone() +{ +} + +TimeZone::~TimeZone() +{ +} + +TimeZone* TimeZone::createDefault() +{ + TimeZone * t = (TimeZone*) new TimeZone(); + return ((TimeZone *)t); +} + +TimeZone* TimeZone::createTimeZone(const UnicodeString& aID) +{ + TimeZone * t = (TimeZone*) new TimeZone(); + return ((TimeZone *)t); +} + +void TimeZone::setID(const UnicodeString& aID) +{ + return; +} + diff --git a/calendar/modules/nls/nlsstub/src/unistring.cpp b/calendar/modules/nls/nlsstub/src/unistring.cpp new file mode 100644 index 00000000000..0b254abf5d9 --- /dev/null +++ b/calendar/modules/nls/nlsstub/src/unistring.cpp @@ -0,0 +1,303 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +#include "unistring.h" +#include "nsCRT.h" + + +UnicodeString::UnicodeString() +{ + mLength = mString.Length(); +} + +UnicodeString::~UnicodeString() +{ +} + +UnicodeString::UnicodeString(const UnicodeString& aUnicodeString) +{ + mString = aUnicodeString.mString; + mLength = mString.Length(); +} + +UnicodeString::UnicodeString(const char * aString) +{ + mString = aString; + mLength = mString.Length(); +} + +PRInt32 UnicodeString::hashCode() const +{ + nsCRT::HashValue(mString.GetUnicode()); + return 0; +} + +TextOffset UnicodeString::indexOf(const UnicodeString& aUnicodeString, TextOffset aFromOffset, PRUint32 aForLength) const +{ + return (mString.FindCharInSet((nsString&)(aUnicodeString.mString), aFromOffset)); +} + +TextOffset UnicodeString::indexOf(PRUnichar aUnichar, TextOffset aFromOffset, PRUint32 aForLength) const +{ + return (mString.Find(aUnichar, aFromOffset)); +} + + +UnicodeString& UnicodeString::extractBetween(TextOffset aStart, TextOffset aLimit, UnicodeString& aExtractInto) const +{ + nsString a = mString; + nsString b; + a.Mid(b,aStart,aLimit); + aExtractInto.mString = b; + return (aExtractInto); +} + + +PRInt32 UnicodeString::compareIgnoreCase(const UnicodeString& aUnicodeString) const +{ + return (mString.Compare(aUnicodeString.mString,PR_TRUE)); +} + +PRInt32 UnicodeString::compareIgnoreCase(const PRUnichar* aUnichar, PRInt32 aLength) const +{ + return (mString.Compare(aUnichar,PR_TRUE),aLength); +} + +PRInt32 UnicodeString::compareIgnoreCase(const PRUnichar* aUnichar) const +{ + return (mString.Compare(aUnichar,PR_TRUE)); +} + +PRInt32 UnicodeString::compareIgnoreCase(const char* aChar, const char* aEncoding) const +{ + return (mString.Compare(aChar,PR_TRUE)); +} + +PRInt32 UnicodeString::compareIgnoreCase(const char* aChar) const +{ + return (mString.Compare(aChar,PR_TRUE)); +} + +UnicodeString& UnicodeString::toUpper() +{ + + mString.ToUpperCase(); + return (*this); +} + +UnicodeString& UnicodeString::toUpper(const Locale& aLocale) +{ + mString.ToUpperCase(); + return (*this); +} + +char* UnicodeString::toCString(const char* aEncoding) const +{ + return (mString.ToNewCString()); +} + +UnicodeString& UnicodeString::trim(UnicodeString& aUnicodeString) const +{ + aUnicodeString.mString.CompressWhitespace(); + return (aUnicodeString); +} + +void UnicodeString::trim() +{ + mString.CompressWhitespace(); + mLength = mString.Length(); + return; +} + +UnicodeString& UnicodeString::remove() +{ + mString.Truncate(); + mLength = mString.Length(); + return (*this); +} + +UnicodeString& UnicodeString::remove(TextOffset aOffset,PRInt32 aLength) +{ + mString.Cut(aOffset,aLength); + mLength = mString.Length(); + return (*this); +} + +UnicodeString& UnicodeString::insert(TextOffset aThisOffset, const UnicodeString& aUnicodeString) +{ + mString.Insert(*(aUnicodeString.mString),aThisOffset); + mLength = mString.Length(); + return (*this); +} + +PRBool UnicodeString::startsWith(const UnicodeString& aUnicodeString) const +{ + if (nsCRT::strncmp(aUnicodeString.mString.GetUnicode(),mString.GetUnicode(),aUnicodeString.mString.Length()) == 0) + return PR_TRUE; + + return PR_FALSE; +} + +PRBool UnicodeString::endsWith(const UnicodeString& aUnicodeString) const +{ + PRUint32 offset = mString.Length() - aUnicodeString.mString.Length(); + PRBool b = PR_FALSE; + + if (offset < 0) + return PR_FALSE; + + char * str1 = mString.ToNewCString(); + char * str2 = aUnicodeString.mString.ToNewCString(); + + if (nsCRT::strncasecmp((char *)(str1+offset),str2,aUnicodeString.mString.Length()) == 0) + b = PR_TRUE; + + delete str1; + delete str2; + + return (b); +} + +UnicodeString& UnicodeString::removeBetween(TextOffset aStart, TextOffset aLimit) +{ + mString.Cut(aStart, aLimit); + mLength = mString.Length(); + return (*this); +} + +PRInt8 UnicodeString::compare(const UnicodeString& aUnicodeString) const +{ + return (mString.Equals(aUnicodeString.mString)); +} + +PRInt8 UnicodeString::compare(TextOffset aOffset, + PRInt32 aThisLength, + const UnicodeString& aUnicodeString, + TextOffset aStringOffset, + PRInt32 aLength) const +{ + + nsString s1 = mString,s2 = aUnicodeString.mString; + + s1.Mid(s1,aOffset,aThisLength); + s2.Mid(s2,aStringOffset,aLength); + + return (s1.Equals(s2)); +} + +PRInt8 UnicodeString::compare(const PRUnichar* aUnichar) const +{ + return (mString.Compare(aUnichar)); +} + +PRInt8 UnicodeString::compare(const PRUnichar* aUnichar, PRInt32 aLength) const +{ + return (mString.Compare(aUnichar,PR_FALSE,aLength)); +} + +PRInt8 UnicodeString::compare(const char* aChar) const +{ + return (mString.Compare(aChar)); +} + +UnicodeString& UnicodeString::extract(TextOffset aOffset,PRInt32 aLength, UnicodeString& aExtractInto) const +{ + nsString str = mString; + str.Mid(aExtractInto.mString,aOffset,aLength); + aExtractInto.mLength = aExtractInto.mString.Length(); + return (aExtractInto); +} + +void UnicodeString::extract(TextOffset aOffset, PRInt32 aLength, PRUnichar*aExtractInto) const +{ + PRUint32 aExtractLength = 0; + nsString str = mString; + + if(((PRInt32)aOffset)<((PRInt32)mLength)) + { + aLength=(PRInt32)(((PRInt32)(aOffset+aLength)<=((PRInt32)mLength)) ? aLength : mLength-aOffset); + + PRUnichar* from = (PRUnichar*)(str.GetUnicode() + aOffset); + PRUnichar* end = (PRUnichar*)(str.GetUnicode() + aOffset + aLength); + + while (from < end) + { + PRUnichar ch = *from; + + aExtractInto[aExtractLength++]=ch; + aExtractInto[aExtractLength]=0; + + from++; + } + } + else + aLength=0; + + return ; +} + +void UnicodeString::extract(TextOffset aOffset, PRInt32 aLength, char* aExtractInto) const +{ + nsString str = mString; + char * p = str.ToNewCString(); + + nsCRT::memcpy(aExtractInto,p+aOffset,aLength); + delete p; + + return; +} + +PRUnichar UnicodeString::operator[](TextOffset aOffset) const +{ + return(mString[aOffset]); +} + +PRUnichar& UnicodeString::operator[](TextOffset aOffset) +{ + return(mString[aOffset]); +} + +UnicodeString& UnicodeString::operator+=(const UnicodeString& aUnicodeString) +{ + mString.Append(aUnicodeString.mString); + return (*this); +} + +UnicodeString& UnicodeString::operator+=(PRUnichar aUnichar) +{ + mString.Append(aUnichar); + return (*this); +} + +PRBool UnicodeString::operator==(const UnicodeString& aUnicodeString) const +{ + return (mString == (aUnicodeString.mString)); +} + +PRBool UnicodeString::operator!=(const UnicodeString& aUnicodeString) const +{ + return (mString != (aUnicodeString.mString)); +} + +UnicodeString& UnicodeString::operator=(const UnicodeString& aUnicodeString) +{ + mString = aUnicodeString.mString; + mLength = mString.Length(); + return (*this); +} + diff --git a/calendar/modules/parser/config.mk b/calendar/modules/parser/config.mk index 45ad7f47986..e69de29bb2d 100644 --- a/calendar/modules/parser/config.mk +++ b/calendar/modules/parser/config.mk @@ -1,36 +0,0 @@ -# -# CONFIDENTIAL AND PROPRIETARY SOURCE CODE OF -# NETSCAPE COMMUNICATIONS CORPORATION -# Copyright © 1996, 1997 Netscape Communications Corporation. All Rights -# Reserved. Use of this Source Code is subject to the terms of the -# applicable license agreement from Netscape Communications Corporation. -# The copyright notice(s) in this Source Code does not indicate actual or -# intended publication of this Source Code. -# - -# -# Override TARGETS variable so that only static libraries -# are specifed as dependencies within rules.mk. -# - -CFLAGS +=-D_IMPL_NS_CALENDAR - -LD_LIBS += \ - raptorbase \ - $(NATIVE_RAPTOR_GFX) \ - raptorhtmlpars \ - $(NATIVE_JULIAN_DLL) \ - xpcom$(MOZ_BITS) \ - $(NATIVE_LIBNLS_LIBS) \ - $(NATIVE_RAPTOR_WIDGET) \ - xpcom$(MOZ_BITS) \ - xpfc10 \ - $(XP_REG_LIB) - -AR_LIBS += \ - core \ - calxml \ - $(NULL) - -EXTRA_LIBS += $(NSPR_LIBS) - diff --git a/calendar/modules/shell/src/config.mk b/calendar/modules/shell/src/config.mk index c2666d8fab9..5b20fb5908d 100644 --- a/calendar/modules/shell/src/config.mk +++ b/calendar/modules/shell/src/config.mk @@ -49,11 +49,11 @@ LD_LIBS += \ $(RAPTOR_GFX) \ $(NATIVE_ZLIB_DLL) \ $(NATIVE_XP_DLL) \ - $(NATIVE_JULIAN_DLL) \ $(NATIVE_LIBNLS_LIBS) \ xpcom$(MOZ_BITS) \ util10 \ calcore10 \ + cal_core_ical10 \ $(XP_REG_LIB) STATIC_LIBS += shell diff --git a/calendar/modules/test/inc/manifest.mn b/calendar/modules/test/inc/manifest.mn index 95b8ab17772..e69de29bb2d 100644 --- a/calendar/modules/test/inc/manifest.mn +++ b/calendar/modules/test/inc/manifest.mn @@ -1,24 +0,0 @@ -# -# CONFIDENTIAL AND PROPRIETARY SOURCE CODE OF -# NETSCAPE COMMUNICATIONS CORPORATION -# Copyright (C) 1996 Netscape Communications Corporation. All Rights -# Reserved. Use of this Source Code is subject to the terms of the -# applicable license agreement from Netscape Communications Corporation. -# The copyright notice(s) in this Source Code does not indicate actual or -# intended publication of this Source Code. -# -GDEPTH = ../../../.. - -EXPORTS = \ - nsTrexTestShell.h \ - $(NULL) - -PRIVATE_EXPORTS = \ - nsTrexTestShell.h \ - nsTrexTestShellCIID.h \ - nsTrexTestShellFactory.h \ - $(NULL) - -MODULE = trextest - -REQUIRES = raptor xpfc diff --git a/calendar/modules/test/public/manifest.mn b/calendar/modules/test/public/manifest.mn index c3068cb83eb..e69de29bb2d 100644 --- a/calendar/modules/test/public/manifest.mn +++ b/calendar/modules/test/public/manifest.mn @@ -1,22 +0,0 @@ -# -# CONFIDENTIAL AND PROPRIETARY SOURCE CODE OF -# NETSCAPE COMMUNICATIONS CORPORATION -# Copyright (C) 1996 Netscape Communications Corporation. All Rights -# Reserved. Use of this Source Code is subject to the terms of the -# applicable license agreement from Netscape Communications Corporation. -# The copyright notice(s) in this Source Code does not indicate actual or -# intended publication of this Source Code. -# -GDEPTH = ../../../.. -DEPTH = ../../../.. - -EXPORTS = \ - nsITrexTestShell.h \ - $(NULL) - -PRIVATE_EXPORTS = \ - $(NULL) - -MODULE = trextest - -REQUIRES = raptor xpfc diff --git a/calendar/modules/test/src/config.mk b/calendar/modules/test/src/config.mk index 2932e22b835..8a8dd64b496 100644 --- a/calendar/modules/test/src/config.mk +++ b/calendar/modules/test/src/config.mk @@ -42,11 +42,9 @@ LD_LIBS += \ netlib \ xpfc10 \ $(NATIVE_RAPTOR_WIDGET) \ - $(NATIVE_JULIAN_DLL) \ $(NATIVE_LIBNLS_LIBS) \ $(NATIVE_RAPTOR_GFX) \ $(RAPTOR_GFX) \ - $(NATIVE_JULIAN_DLL) \ xpcom$(MOZ_BITS) \ $(NATIVE_ZLIB_DLL) \ $(NATIVE_XP_DLL) \ diff --git a/calendar/modules/test/src/manifest.mn b/calendar/modules/test/src/manifest.mn index 727b09117e7..d5f37ac7095 100644 --- a/calendar/modules/test/src/manifest.mn +++ b/calendar/modules/test/src/manifest.mn @@ -15,7 +15,7 @@ EXPORTS = \ PRIVATE_EXPORTS = \ $(NULL) -MODULE = trextest +MODULE = trex CPPSRCS = \ nsTrexTestShell.cpp \ @@ -23,5 +23,5 @@ CPPSRCS = \ $(NULL) -REQUIRES = xpcom raptor julian nls netlib pref js xpfc +REQUIRES = xpcom raptor julian nls netlib pref js xpfc trex diff --git a/calendar/modules/ui/config.mk b/calendar/modules/ui/config.mk index 1a5bb770e42..e69de29bb2d 100644 --- a/calendar/modules/ui/config.mk +++ b/calendar/modules/ui/config.mk @@ -1,42 +0,0 @@ -# -# CONFIDENTIAL AND PROPRIETARY SOURCE CODE OF -# NETSCAPE COMMUNICATIONS CORPORATION -# Copyright © 1996, 1997 Netscape Communications Corporation. All Rights -# Reserved. Use of this Source Code is subject to the terms of the -# applicable license agreement from Netscape Communications Corporation. -# The copyright notice(s) in this Source Code does not indicate actual or -# intended publication of this Source Code. -# - -# -# Override TARGETS variable so that only static libraries -# are specifed as dependencies within rules.mk. -# - -CFLAGS +=-D_IMPL_NS_CALENDAR - -LD_LIBS += \ - raptorbase \ - $(NATIVE_RAPTOR_GFX) \ - $(NATIVE_RAPTOR_WIDGET) \ - $(NATIVE_JULIAN_DLL) \ - xpcom$(MOZ_BITS) \ - $(NATIVE_LIBNLS_LIBS) \ - xpfc10 \ - calcore10 \ - $(XP_REG_LIB) - -AR_LIBS += \ - canvas \ - core \ - context \ - component \ - controller \ - command \ - toolkit \ - $(NULL) - -OS_LIBS += $(GUI_LIBS) $(MATH_LIB) - -EXTRA_LIBS += $(NSPR_LIBS) - diff --git a/calendar/modules/util/inc/datetime.h b/calendar/modules/util/inc/datetime.h new file mode 100644 index 00000000000..9a1023da64a --- /dev/null +++ b/calendar/modules/util/inc/datetime.h @@ -0,0 +1,867 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +/* + * datetime.h + * John Sun + * 1/22/98 9:24:15 AM + */ + +#ifndef __DATETIME_H_ +#define __DATETIME_H_ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "duration.h" +#include "nscalutilexp.h" + +/* + * Helper functions for use with JulianPtrArray + */ +NS_CAL_UTIL int DateTime_SortAscending( const void* v1, const void* v2 ); +NS_CAL_UTIL int DateTime_SortDescending( const void* v1, const void* v2 ); + +class NS_CAL_UTIL DateTime +{ +private: + + /*----------------------------- + ** MEMBERS + **---------------------------*/ + +#if 0 + /* date formatting strings. Moved to JulianFormatString class */ + static UnicodeString ms_asPatterns[]; + static UnicodeString ms_sISO8601Pattern; + static UnicodeString ms_sISO8601LocalPattern; + static UnicodeString ms_sISO8601TimeOnlyPattern; + static UnicodeString ms_sISO8601DateOnlyPattern; + static UnicodeString ms_sDefaultPattern; + + /* hashtable of simpleDateFormats vars and methods */ + /* TODO: use for caching simpledateformats in other locales */ + static SimpleDateFormat kDateFormats[]; + static char* kDateFormatIDs[]; + static const t_int32 kNumDateFormats; + static Hashtable sdfHashtable; /* hashtable of date formats */ + void initHashtable(); + + /* old data structures, used when static */ + /*TimeZone * m_TimeZone;*/ + + static Locale * ms_Locale; + static Locale ms_Locale; + static ResourceBundle * ms_ResourceBundle; + static GregorianCalendar ms_Calendar; + static DateTime * invalidDate; /* singleton instance of an invalid Date */ + static DateFormat ms_GMTISO8601DateFormat; + static SimpleDateFormat * ms_DateFormat; +#endif + + static ErrorCode staticStatus; + static ErrorCode staticStatus2; + static TimeZone * m_kGMTTimeZone; /* was const */ + static TimeZone * m_kDefaultTimeZone; /* was const */ + static TimeZone * ms_TimeZone; + + static GregorianCalendar * ms_Calendar; + static SimpleDateFormat * ms_DateFormat; + + static t_bool m_Init; + Date m_Date; /* like the long in java.util.Date */ + + /*----------------------------- + ** PRIVATE METHODS + **---------------------------*/ + + t_int8 compare(Date d); + + /** + * Checks to see if static member data was initialized correctly. May remove later. + */ + static void CtorCore(); + + /** + * helper method that encapsulates errorcode checking + * while calling a get-field method + * + * @param aField a calendar field to get + * @param timezone timezone returned field should be relevant to + * @return the value of that field + */ + static t_int32 CalendarGetFieldHelper(Calendar::EDateFields aField, + TimeZone * timezone = ms_TimeZone); + + /** + * helper method that encapsulates errorcode checking + * while calling a getTime() + * (like calling ms_Calendar->getTime(ErrorCode);) + * + * @return the Date value of ms_Calendar + */ + static Date CalendarGetTimeHelper(); + /** + * helper method that encapsulates errorcode checking + * while calling a setTime() + * (like calling ms_Calendar->setTime(Date, ErrorCode);) + * + * @param d the Date value to set to ms_Calendar + */ + static void CalendarSetTimeHelper(Date d); + +#if 0 + /** + * parse the date string to get the Date value of the string + * + * @param s the UnicodeString to parse + * @param locale the Locale to parse with + * @return the Date value of the string + */ + static Date parse(UnicodeString & us, Locale & locale); + + /** + * parse the date string to get the Date value of the string relative to a + * a date-format pattern. + * NOTE: Slow since creates new SimpleDateFormat + * + * @param pattern the date-format pattern to parse with + * @param s the UnicodeString to parse + * @param locale the Locale to parse with + * @param timezone the TimeZone of the time string, default to ms_TimeZone + * @return the Date value of the string + */ + static Date parseTime(UnicodeString & pattern, UnicodeString & time, + Locale & locale, TimeZone * timezone = ms_TimeZone); +#endif + + /** + * parse the date string to get the Date value of the string relative to a + * a date-format pattern. + * + * @param pattern the date-format pattern to parse with + * @param s the UnicodeString to parse + * @param timezone the TimeZone of the time string, default to ms_TimeZone + * @return the Date value of the string + */ + static Date parseTime(UnicodeString & pattern, UnicodeString & time, + TimeZone * timezone = ms_TimeZone); /* no locale */ + /*static UnicodeString stringCheck(UnicodeString uc);*/ + +public: + /** + * correctly returns the number of days in a month, given + * the month and a year. The rule for this method is the following: + * Assume rule is Gregorian (pretend all dates after 1582). Use leap-year + * rule every 4 years, except every 100 years, except every 400 years. + * Thus 1700, 1800, 1900, 2100, 2200, 2300 are not leap years. + * But 2000, 1600, 2400 are leap years. Of course, year divisible by 4, + * but not divisible by 100 are leap years. + * + * @param iMonthNum the 1-based month value + * @param iYearNum the year value (i.e. 1998, 1989, 2001) + * @return the number of days in that month + */ + static t_int32 getMonthLength(t_int32 iMonthNum, t_int32 iYearNum); + +private: + + /** + * Given an ISO8601 Date string, parse it to return the Date value. + * Allows for passing in timezones. Thus if string is 19971225T112233 + * and TimeZone is PST, then returned date value will be equal to + * the number of milleseconds since the epoch (Jan 1, 1970 12:00 AM GMT) + * on Dec 25, 1997 11:22:33 AM PST. + * If the string is a UTC string (ends with a Z), the timezone is ignored + * and the string is parsed relevant to the GMT timezone. + * + * Since the Calendar cannot recognize dates, before the epoch, + * parseable DateTime strings with year value before 1970 will be set to 1970 + * Thus a string 19671225T112233 will be changed to 19701225T112233. + * This allows for parsing timezones with a start time before 1970. + * Return -1 if the Date string is bogus. (i.e. bad parse, impossible values) + * Also parses Dates, i.e. 19971110. Date values will have hours, minutes, + * and seconds set to 0 in with respect to the timezone passed in. + * + * + * @param us the UnicodeString to parse + * @param timezone the TimeZone of the datetime is related to + * @return the Date value of the string + * @see IsParseable + */ + static Date parseISO8601(UnicodeString & us, + TimeZone * timezone = ms_TimeZone); + + + /** + * The format workhorse method. Calls the SimpleDateformat + * object to format pattern with respect to timezone + * @param pattern pattern to format datetime to + * @param aTimeZone timezone of datetime to format to + * + * @return UnicodeString + */ + UnicodeString strftimeNoLocale(UnicodeString& pattern, + TimeZone * aTimeZone = ms_TimeZone); +public: + + /*----------------------------- + ** CONSTRUCTORS and DESTRUCTORS + **---------------------------*/ + + /** + * default constructor - set the time to current time + */ + DateTime(); + + /** + * 3 element args constructor - given year, month, and date, + * construct a datetime + * + * @param year the initial year of the datetime + * @param month the initial month of the datetime + * @param date the initial date of the datetime + */ + DateTime(t_int32 year, t_int32 month, t_int32 date); + + /** + * 5 element args constructor - given year, month, date, + * hrs, and mins, construct a datetime + * + * @param year the initial year of the datetime + * @param month the initial month of the datetime + * @param date the initial date of the datetime + * @param hrs the initial hours of the datetime + * @param min the initial minutes of the datetime + */ + DateTime(t_int32 year, t_int32 month, t_int32 date, t_int32 hrs, t_int32 min); + + /** + * 6 element args constructor - given year, month, date, + * hrs, and mins, construct a datetime + * + * @param year the initial year of the datetime + * @param month the initial month of the datetime + * @param date the initial date of the datetime + * @param hrs the initial hours of the datetime + * @param min the initial minutes of the datetime + * @param sec the initial seconds of the datetime + */ + DateTime(t_int32 year, t_int32 month, t_int32 date, t_int32 hrs, t_int32 min, t_int32 sec); + + /** + * constructor that sets date value to Date arg + * + * @param d the initial Date value of the datetime + */ + DateTime(Date d); + + /** + * copy constructor + * @param aDateTime the DateTime to copy + */ + DateTime(DateTime & aDateTime); + + /** + * a constructor that takes a string and converts to datetime. + * ASSUMPTION: us is a ISO8601 Date-Time Format + * + * @param us the UnicodeString to parse, setting Date value + * @param timezone the TimeZone to parse in + */ + DateTime(UnicodeString & us, TimeZone * timezone = ms_TimeZone); + + ~DateTime(); + + /*----------------------------- + ** GETTERS and SETTERS and ADDERS + **---------------------------*/ + + /** + * Returns the value of the Date + * + * @return the current Date value of this DateTime object + */ + Date getTime() const; + + /** + * Sets the value of the Date + * + * @param d the Date arg to set to + */ + void setTime(Date d); + + /** + * Given a string, sets time to string's value if parseable + * NOTE: Currently only accepts ISO8601 strings. + * @param us date-time string to set to + * @param timezone timezone the date-time should be parsed to + * @see parseISO8601 + */ + void setTimeString(UnicodeString & us, + TimeZone * timezone = ms_TimeZone); + + /** + * Set the value of the timezone + * + * @param t the TimeZone arg to set to + */ + /*void setTimeZone(TimeZone * t);*/ + + /** + * Returns a field of the calendar + * + * @param aField the field to return + * @param timezone timezone returned field should be relevant to + * @return the value of the field + * + */ + t_int32 get(Calendar::EDateFields aField, + TimeZone * timezone = ms_TimeZone); + + /** + * @param timezone timezone returned field should be relevant to + * @return the year field value + */ + t_int32 getYear(TimeZone * timezone = ms_TimeZone); + + /** + * @param timezone timezone returned field should be relevant to + * @return the month field value + */ + t_int32 getMonth(TimeZone * timezone = ms_TimeZone); + + /** + * @param timezone timezone returned field should be relevant to + * @return the day-of-month field value + */ + t_int32 getDate(TimeZone * timezone = ms_TimeZone); + + /** + * @param timezone timezone returned field should be relevant to + * @return the hour-of-day(24hrs) field value + */ + t_int32 getHour(TimeZone * timezone = ms_TimeZone); + + /** + * @param timezone timezone returned field should be relevant to + * @return the minute field value + */ + t_int32 getMinute(TimeZone * timezone = ms_TimeZone); + + /** + * @param timezone timezone returned field should be relevant to + * @return the second field value + */ + t_int32 getSecond(TimeZone * timezone = ms_TimeZone); + + /** + * @param timezone timezone returned field should be relevant to + * @return the day-of-week-in-month field value + */ + t_int32 getDayOfWeekInMonth(TimeZone * timezone = ms_TimeZone); + + /** + * Set the day month and year of d2 to the supplied values + * + * @param iDay the desired day of the month + * @param iMonth the desired month of the year + * @param iYear the desired year + * @return the updated DateTime + */ + void setDMY(t_int32 iDay, t_int32 iMonth, t_int32 iYear); + void setDayOfMonth(t_int32 iDay); + + /** + * Sets the value of a calendar field to an amount + * + * @param aField the field to set + * @param amount the amount of the field + */ + void set(Calendar::EDateFields, t_int32 value); + /** + * Adds the an amount to the value of a calendar field + * + * @param aField the field to add + * @param amount the amount of the field + */ + void add(Calendar::EDateFields, t_int32 amount); + + /** + * adds a duration amount to this datetime + * @param d the duration to add + */ + void add(Julian_Duration d); + + /** + * subtracts a duration amount from this datetime + * @param d the duration to subtract + */ + void subtract(Julian_Duration d); + + /** + * given two datetimes, return the duration length between them. + * if end before start, return an invalid duration. + */ + static Julian_Duration & getDuration(DateTime start, DateTime end, Julian_Duration & out); + + /** + * Clears all fields + */ + void clear(); + + /*----------------------------- + ** UTILITIES + **---------------------------*/ + + /** + * A invalid DateTime has a Date value less than 0. + * + * @return TRUE if valid, FALSE otherwise. + */ + t_bool isValid(); + + /** + * Sets this DateTime to the previous day + */ + void prevDay(); + + /** + * Sets this DateTime to a previous number of days + * @param i number of days to go back + */ + void prevDay(t_int32 i); + + /** + * Sets this DateTime to the next day + */ + void nextDay(); + + /** + * Sets this DateTime ahead a number of days + * @param i number of days to go ahead + */ + void nextDay(t_int32 i); + + /** + * Sets this DateTime to the prev week + */ + void prevWeek(); + + /** + * Sets this DateTime to the next week + */ + void nextWeek(); + + /* moves by week */ + void moveTo(t_int32 i, t_int32 direction, t_bool force); + + void setByISOWeek(t_int32 week); + /** + * Sets this DateTime to the previous month + */ + void prevMonth(); + + /** + * Sets this DateTime to a previous number of months + * @param iLim number of months to go back + */ + void prevMonth(t_int32 iLim); + + /** + * Sets this DateTime to the next month + */ + void nextMonth(); + + /** + * Sets this DateTime to advance a number of months + * @param iLim number of months to advance + */ + void nextMonth(t_int32 iLim); + /**--------------------------------------------------------------------- + ** prevDOW + ** + ** This method is useful in determining the beginning of a calendar + ** week. The idea is: you pass in the day of the week the user + ** wants as the first day of the week and this routine finds it. + ** if the date passed in is already the desired day, the same date + ** is returned. Otherwise, it goes backwards until it finds the + ** desired day of the week. + *** + *** @param n back the this date off to the supplied day-of-the-week + *** This parameter must be one of Calendar::SUNDAY through + *** Calendar::SATURDAY. + *** + *** @return the number of days backed off + *** + *** sman@netscape.com + ***--------------------------------------------------------------------*/ + t_int32 prevDOW(t_int32 n); + + /* Boolean check methods */ + + /** + * @param dt DateTime to compare with + * @return -1 if this DateTime is before, 0 if equal, 1 if afte + */ + t_int32 compareTo(DateTime &dt); + + /** + * @param d Date to compare with + * @return TRUE if this DateTime is before a Date, FALSE otherwise + * @deprecated + */ + t_bool beforeDate(Date d); + t_bool beforeDateTime(DateTime dt); + t_bool before(DateTime * dt); + + /** + * @param d Date to compare with + * @return TRUE if this DateTime is after a Date, FALSE otherwise + * @deprecated + */ + t_bool afterDate(Date d); + t_bool afterDateTime(DateTime dt); + t_bool after(DateTime * dt); + + /** + * @param d Date to compare with + * @return TRUE if this DateTime is equals a Date, FALSE otherwise + * @deprecated + */ + t_bool equalsDate(Date d); + t_bool equalsDateTime(DateTime dt); + t_bool equals(DateTime * dt); + + /** + * This method returns TRUE if the supplied date is on the same + * day, month, and year as this date. + * + * @param d datetime to compare against + * @param timezone timezone that d is in + * @return TRUE if day, month and year fields in d and this DateTime match, FALSE otherwise + */ + t_bool sameDMY(DateTime * d, TimeZone * timezone = ms_TimeZone); + + /* PRINT methods */ + + /** + * Returns this DateTime to a localized string + * + * @param timezone timezone to localize to + * @return the localized string of the date + */ + UnicodeString toString(TimeZone * timezone = ms_TimeZone); + + /** + * Returns this DateTime to a the GMT ISO8601 format + * + * @param timezone timezone to localize to + * @return the GMT ISO8601 format of the date + */ + UnicodeString toISO8601Local(TimeZone * timezone = ms_TimeZone); + + /** + * Returns this DateTime to a the localized ISO8601 format + * + * @return the localized ISO8601 format of the date + */ + UnicodeString toISO8601(); + + /** + * Return the Time string in ISO8601 format w/respect to GMT + * For example a DateTime equal to 19981225T013000Z would return + * the string "013000". + * + * @return output time string + */ + UnicodeString toISO8601TimeOnly(); + + /** + * Return the Date string in ISO8601 format w/respect to GMT + * For example a DateTime equal to 19981225T013000Z + * would return the string "19981225". + * + * @return output date string + */ + UnicodeString toISO8601DateOnly(); + + /** + * Return the Time string in ISO8601 format w/respect to timezone argument. + * For example a DateTime equal to 19981225T013000Z, and a timezone arg of EST + * would return the string "193000" since it is 7:30 PM in Eastern Standard Time. + * @param timezone timezone to apply to. + */ + UnicodeString toISO8601LocalTimeOnly(TimeZone * timezone = ms_TimeZone); + + /** + * Return the Time string in ISO8601 format w/respect to timezone argument. + * For example a DateTime equal to 19981225T013000Z, and a timezone arg of EST + * would return the string "19981224" since it is Dec 24th in Eastern Standard Time. + * @param timezone timezone to apply to. + */ + UnicodeString toISO8601LocalDateOnly(TimeZone * timezone = ms_TimeZone); + + /** + * Returns a string representing the formatted string of the datetime + * given a formatting string. Applies result to the timezone passed in. + * For example, if the datetime was 19981225T013000Z and if + * pattern was "MM/dd/yy hh:mm:ss a z" and timezone was + * EST, the returned string would be "12/24/98 07:30:00 PM EST". + * + * @param pattern the date-format pattern + * @param timezone timezone to apply to + * @return the formatted string of this DateTime + */ + UnicodeString strftime(UnicodeString& pattern, + TimeZone * timezone = ms_TimeZone); + + /** + * Returns a string representing the formatted string of the datetime + * given a formatting string. Must create new DateFormat object to + * pass in locale + * NOTE: Slow since creates new SimpleDateFormat + * + * @param pattern the date-format pattern + * @param locale the locale to print in + * @param timezone the timezone to format in (default to 0) + * @return the formatted string of this DateTime + */ + UnicodeString strftime(UnicodeString& pattern, Locale & locale, TimeZone * timezone = 0); + + /** + * Sets this DateTime to the last day of the month of s. + * Thus if s has a month value of March, then this + * DateTime is set to March 31. + * + * @param s a DateTime + */ + void findLastDayOfMonth(); /* go to last day of current month */ + + /** + * Sets this DateTime to the last day of the year of s. + * Thus if s has a year value of 1998, then this + * DateTime is set to Dec 31, 1998. + * + * @param s a DateTime + */ + void findLastDayOfYear(); /* go to last day of current year */ + + /*----------------------------- + ** STATIC METHODS + **---------------------------*/ + + /** + * Given the day of the week indicator, + * return the next day of the week indicator + * + * @param n the day of the week, for example: Calendar::MONDAY + * @return the next day of the week + */ + static t_int32 getPrevDOW(t_int32 n); + + /** + * Given the day of the week indicator, + * return the next day of the week indicator + * + * @param n the day of the week, for example: Calendar.MONDAY + * @return the next day of the week + */ + static t_int32 getNextDOW(t_int32 n); + + /** + * Returns string of dt. + * @param DateTime & dt + * + * @return static UnicodeString + */ + static UnicodeString DateToString(DateTime & dt); + + /** + * Given a string, checks to see whether the string is valid + * ISO8601 DateTime or Date string. + * + * A valid ISO8601 DateTime has the following grammar. + * [year][month][day]'T'[hour][minute][second] + * + * In addition, the DateTime may have an optional 'Z' + * character at the end to signify UTC time. + * + * A valid ISO8601 Date has the following grammar. + * [year][month][day] + * + * The year part contains four numbers. + * The month part contains two numbers comprising a valid month value [01-12]. + * The day part contains two numbers comprising a valid day value [01-31]. + * The day part must also match the month and year values (i.e. + * cannot have month = 02 and day = 31.) + * The hour part contains two numbers comprising a valid hour value [00-23]. + * The minute part contains two numbers comprising a valid minute value [00-59]. + * The second part contains two numbers comprising a valid second value [00-59]. + * + * If the string is a valid ISO8601 DateTime or Date string, then this method + * will correctly fill in the passed in integer variables with their + * appropriate value. For example, if the string was "19971225T123045Z", + * the returned values would be iYear = 1997, iMonth = 12, iDay = 25, iHour = 12, + * iMinute = 30, iSecond = 45. + * @param s string to check if valid + * @param iYear returned year value + * @param iMonth returned month value + * @param iDay returned day value + * @param iHour returned hour value + * @param iMinute returned minute value + * @param iSecond returned second value + * + * @return TRUE if string is a valid ISO8601 DateTime or Date string, FALSE otherwise + */ + static t_bool IsParseable(UnicodeString & s, t_int32 & iYear, t_int32 & iMonth, + t_int32 & iDay, t_int32 & iHour, t_int32 & iMinute, t_int32 & iSecond); + + /** + * Given a string, checks to see whether the string is valid + * ISO8601 DateTime or Date string. + * @param s string to check if valid + * + * @return TRUE if string is a valid ISO8601 DateTime or Date string, FALSE otherwise + */ + static t_bool IsParseable(UnicodeString & s); + + /** + * Given a string, checks to see whether the string is valid + * ISO8601 DateTime string. + * @param s string to check if valid + * + * @return TRUE if string is a valid ISO8601 DateTime, FALSE otherwise + */ + static t_bool IsParseableDateTime(UnicodeString & s); + + /** + * Given a string, checks to see whether the string is valid + * ISO8601 Date string. + * @param s string to check if valid + * + * @return TRUE if string is a valid ISO8601 Date, FALSE otherwise + */ + static t_bool IsParseableDate(UnicodeString & s); + + /** + * Given a string, checks to see whether the string is valid + * ISO8601 UTCOffset string. + * @param s string to check if valid + * + * @return TRUE if string is a valid UTCOffset, FALSE otherwise + */ + static t_bool IsParseableUTCOffset(UnicodeString & s); + + + + /** + * Return the string "19980825T112233" from + * year = 98, month = 8, day = 25, hour = 11, minute = 22, second = 33 + * in sResult. + * @param t_int32 iYear + * @param t_int32 iMonth + * @param t_int32 iDay + * @param t_int32 iHour + * @param t_int32 iMinute + * @param t_int32 iSecond + * @param UnicodeString sResult + * + * @return static UnicodeString + */ + static UnicodeString & ToISO8601String(t_int32 iYear, t_int32 iMonth, t_int32 iDay, + t_int32 iHour, t_int32 iMinute, t_int32 iSecond, UnicodeString & sResult); + + /** + * Given a string, checks to see whether the string is valid + * ISO8601 UTCOffset string. + * + * A valid UTCOffset has the following grammar: + * [+/-][hour][minute] + * + * The first character must be a plus or minus character. + * The hour part contains two numbers comprising a hour offset [0-12] + * The minute part contains two number comprising a minute offset [0-59] + * + * If the string is a valid UTCOffset, then the methods + * will correctly fill in the argument integers with their + * appropriate value. For + * @param s string to check if valid + * @param t_int32 & iHour + * @param t_int32 & iMinute + * + * @return static t_bool + */ + static t_bool IsParseableUTCOffset(UnicodeString & s, t_int32 & iHour, t_int32 & iMinute); + + /* compare method to pass into JulianPtrArray::QuickSort */ + static int CompareDateTimes(const void * a, const void * b); + + /*----------------------------- + ** OVERLOADED OPERATORS + **---------------------------*/ + + /** + * assignment operator + * + * @param that DateTime to copy + * @return a copy of that DateTime + */ + const DateTime &operator=(const DateTime & that); + + /** + * equality operator + * + * @param that DateTime to copy + * @return TRUE if equal, FALSE otherwise + */ + t_bool operator==(const DateTime & that); + + /** + * inequality operator + * + * @param that DateTime to copy + * @return TRUE if NOT equal, FALSE otherwise + */ + t_bool operator!=(const DateTime & that); + + /** + * greater than operator + * + * @param that DateTime to copy + * @return TRUE if after, FALSE otherwise + */ + t_bool operator>(const DateTime & that); + + /** + * less than operator + * + * @param that DateTime to copy + * @return TRUE if befor, FALSE otherwise + */ + t_bool operator<(const DateTime & that); +}; + +#endif /* __DATETIME_H_ */ + diff --git a/calendar/modules/util/inc/duration.h b/calendar/modules/util/inc/duration.h new file mode 100644 index 00000000000..5deb862d7af --- /dev/null +++ b/calendar/modules/util/inc/duration.h @@ -0,0 +1,397 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +/* + * duration.h + * John Sun + * 1/28/98 5:40:22 PM + */ + +#ifndef __DURATION_H_ +#define __DURATION_H_ + +#include +#include +#include "nscalutilexp.h" + +/** + * The Julian_Duration class implements the "duration" data type. + * The "duration" data type is used to identify properties that contain + * a duration of time. + * For example: + * + * P10Y3M15DT5H30M20S + * + * The Julian_Duration class models the duration datatype specified in the iCalendar document. + * Assertion: if week value is not equal is zero, then all other values must be zero + * + */ +class NS_CAL_UTIL Julian_Duration +{ +private: + + /*----------------------------- + ** MEMBERS + **---------------------------*/ + + /** duration year value */ + t_int32 m_iYear; + /** duration month value */ + t_int32 m_iMonth; + /** duration day value */ + t_int32 m_iDay; + /** duration hour value */ + t_int32 m_iHour; + /** duration minute value */ + t_int32 m_iMinute; + /** duration second value */ + t_int32 m_iSecond; + + /** duration week value - NOTE + * if week != 0 then ALL other members = 0 */ + t_int32 m_iWeek; + + /** if duration is negative */ + t_bool m_NegativeDuration; + + /*----------------------------- + ** PRIVATE METHODS + **---------------------------*/ + + /** + * sets values to an invalid duration. This + * internally sets all values to -1. + */ + void setInvalidDuration(); + + /** + * parse an iCal Julian_Duration string and populate the data members + * + * @param us the iCal Duraton string + */ + void parse(UnicodeString & us); + +public: + + /*----------------------------- + ** CONSTRUCTORS and DESTRUCTORS + **---------------------------*/ + + /** + * default constrctor, set duration to 5 min. + */ + Julian_Duration(); + + /** + * Constructs a Julian_Duration object using the grammar + * defined in the iCalendar spec. + * + * @param s String to parse + */ + Julian_Duration(UnicodeString & us); + + /** + * Constructs a copy of a Julian_Duration object. + * + * @param d Julian_Duration to copy + */ + Julian_Duration(Julian_Duration & aDuration); + + /** + * Constructs a Julian_Duration object with a single value set. + * Always yields a positive Duration + * + * @param type the field to set (uses Recurrence type constants) + * @param value value to assign the field + */ + Julian_Duration(t_int32 type, t_int32 value); + + /** + * Constructs a Julian_Duration object with a single value set. + * Always yields a positive Duration + * Setting the week != 0 automatically ignores other param values and sets them to 0. + * Setting any param (year,month,day,hour,min,sec) < 0 automatically creates an invalid Duration. + * + * @param year initial year value + * @param month initial month value + * @param day initial day value + * @param hour initial hour value + * @param min initial min value + * @param sec intiial sec value + * @param week intiial week value + * @param isNegativeDuration TRUE if duration is negative, FALSE otherwise + */ + Julian_Duration(t_int32 year, t_int32 month, t_int32 day, t_int32 hour, t_int32 min, + t_int32 sec, t_int32 week, t_bool bNegativeDuration = FALSE); + /** + * Destructor. + */ + ~Julian_Duration(); + + /*----------------------------- + ** GETTERS and SETTERS + **---------------------------*/ + +#if 0 + /** + * Set year value. + * @param i new year value + */ + void setYear(t_int32 i) { m_iYear = i; } + + /** + * Set year value. + * @param i new year value + */ + void setMonth(t_int32 i) { m_iMonth = i; } + + /** + * Set month value. + * @param i new month value + */ + void setDay(t_int32 i) { m_iDay = i; } + + /** + * Set day value. + * @param i new day value + */ + void setHour(t_int32 i) { m_iHour = i; } + + /** + * Set minute value. + * @param i new minute value + */ + void setMinute(t_int32 i) { m_iMinute = i; } + + /** + * Set second value. + * @param i new second value + */ + void setSecond(t_int32 i) { m_iSecond = i; } + + /** + * Set week value. + * @param i new week value + */ + void setWeek(t_int32 i) { m_iWeek = i; } +#endif + + + /** + * Sets all duration member values except week. + * Sets week value to zero. + * Integer parameters must be POSITIVE. + * Setting any param (year,month,day,hour,min,sec) < 0 automatically creates an invalid Duration. + * If you are trying to set a negative duration, set bNegativeDuration to TRUE. + * @param year new year value + * @param month new month value + * @param day new day value + * @param hour new hour value + * @param min new minute value + * @param sec new second value + * @param isNegativeDuration TRUE if duration is negative, FALSE otherwise + */ + void set(t_int32 year, t_int32 month, t_int32 day, t_int32 hour, + t_int32 min, t_int32 sec, t_bool bNegativeDuration = FALSE); + + /** + * Sets all duration member values except week. + * Setting week < 0 automatically creates an invalid Duration. + * Sets other values to zero. + * Integer parameters must be POSITIVE. + * If you are trying to set a negative duration, set bNegativeDuration to TRUE. + * @param week new week value. + * @param isNegativeDuration TRUE if duration is negative, FALSE otherwise + */ + void set(t_int32 week, t_bool bNegativeDuration = FALSE); + + /** + * Return if TRUE, duration is negative, FALSE otherwise + * + * @return TRUE is duration is negative, FALSE otherwise + */ + t_bool isNegativeDuration() const { return m_NegativeDuration; } + + /** + * Returns current year value. + * Takes negative state into account. + * + * @return current year value + */ + t_int32 getYear() const; + + /** + * Returns current month value + * Takes negative state into account. + * + * @return current month value + */ + t_int32 getMonth() const; + + /** + * Returns current day value + * Takes negative state into account. + * + * @return current day value + */ + t_int32 getDay() const; + + /** + * Returns current hour value + * Takes negative state into account. + * + * @return current hour value + */ + t_int32 getHour() const; + + /** + * Returns current minute value + * Takes negative state into account. + * + * @return current minute value + */ + t_int32 getMinute() const; + + /** + * Returns current second value + * Takes negative state into account. + * + * @return current second value + */ + t_int32 getSecond() const; + + /** + * Returns current week value + * Takes negative state into account. + * + * @return current week value + */ + t_int32 getWeek() const; + + /*----------------------------- + ** UTILITIES + **---------------------------*/ + + /** + * Sets duration members by parsing string input. + * @param s string to parse + */ + void setDurationString(UnicodeString & s); + + /** + * Comparision method. + * @param d Julian_Duration to compare to. + * + * @return -1 if this is shorter, 0 if equal, 1 if longer + * length of duration + */ + t_int32 compareTo(const Julian_Duration &d); + + /** + * Normalizes the current duration. This means rounding off + * values. For example, a duration with values 13 months, + * is normalized to 1 year, 1 month. + */ + void normalize(); + + /** + * Flattens year to 12 months, then a month to 30 days. Not very accurate. + * Used so when I want to print out to iCal, doesn't print months and years, + * but days. + */ + void unnormalize(); + + /** + * Returns TRUE if duration lasts no length of time, otherwise + * returns FALSE + * + * @return TRUE if duration takes no time, FALSE otherwise + */ + t_bool isZeroLength(); + + /** + * returns this Julian_Duration object to a UnicodeString + * + * @return a UnicodeString representing the human-readable format of this Julian_Duration + */ + UnicodeString toString(); + + /** + * returns this Julian_Duration object to a UnicodeString + * + * @return a UnicodeString representing the iCal format of this Julian_Duration + */ + UnicodeString toICALString(); + + /** + * Check whether this duration is valid. A invalid duration will + * have a value of -1 for at least one data member. + * + * @return TRUE if duration is valid, FALSE otherwise + */ + t_bool isValid(); + + /*----------------------------- + ** OVERLOADED OPERATORS + **---------------------------*/ + + /** + * assignment operator + * + * @param d Julian_Duration to copy + * @return a copy of that Julian_Duration + */ + const Julian_Duration &operator=(const Julian_Duration & d); + + /** + * (==) equality operator + * + * @param d Julian_Duration to copy + * @return TRUE if this is equal to d, otherwise FALSE + */ + t_bool operator==(const Julian_Duration & that); + + /** + * (!=) in-equality operator + * + * @param d Julian_Duration to copy + * @return TRUE if this NOT equal to d, otherwise FALSE + */ + t_bool operator!=(const Julian_Duration & that); + + /*-- TODO - make normalize work so that >, < will work correctly */ + + /** + * (>) greater than operator + * + * @param d Julian_Duration to copy + * @return TRUE if this is longer duration than d, otherwise FALSE + */ + t_bool operator>(const Julian_Duration & that); + + /** + * (<) less than operator + * + * @param d Julian_Duration to copy + * @return TRUE if this is shorter duration than d, otherwise FALSE + */ + t_bool operator<(const Julian_Duration & that); +}; + +#endif /* __DURATION_H_ */ + diff --git a/calendar/modules/util/inc/jatom.h b/calendar/modules/util/inc/jatom.h new file mode 100644 index 00000000000..eb7e3b991f5 --- /dev/null +++ b/calendar/modules/util/inc/jatom.h @@ -0,0 +1,105 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +/* + * jatom.h + * John Sun + * 2/27/98 4:35:03 PM + */ + +#include "jdefines.h" +#include + +#ifndef __JATOM_H_ +#define __JATOM_H_ + +#include "nscalutilexp.h" + +/** + * An atom class for UnicodeStrings. Used to speed up + * comparison of strings by calculating hashcode and comparing + * that. + */ +class NS_CAL_UTIL JAtom +{ +private: + /* UnicodeString m_String; */ + + /** strings' hashcode */ + t_int32 m_HashCode; + +public: + + /** default constructor */ + JAtom(); + + /** sets the hashcode variable to string's hashcode value */ + JAtom(const UnicodeString & string); + + /** + * sets the hashcode variable to string's hashcode value + * @param string string to get hashcode from + */ + void setString(const UnicodeString & string); + + + /* UnicodeString toString() const { return m_String; } */ + + /** + * Return the hashcode + * + * @return hashcode to return + */ + t_int32 hashCode() const { return m_HashCode; } + + /** + * Equality comparison with t_int32. + * @param aHashCode hashcode to compare with + * + * @return TRUE if equal, FALSE otherwise + */ + t_bool operator==(t_int32 aHashCode) const { return (m_HashCode == aHashCode); } + + /** + * Equality comparison with atom. + * @param anAtom atom to compare with + * + * @return TRUE if equal, FALSE otherwise + */ + t_bool operator==(JAtom & anAtom) const { return (m_HashCode == anAtom.m_HashCode); } + + /** + * Inequality comparison with t_int32. + * @param aHashCode hashcode to compare with + * + * @return TRUE if NOT equal, FALSE otherwise + */ + t_bool operator!=(t_int32 aHashCode) const { return (m_HashCode != aHashCode); } + + /** + * Inequality comparison with atom. + * @param anAtom atom to compare with + * + * @return TRUE if NOT equal, FALSE otherwise + */ + t_bool operator!=(JAtom & anAtom) const { return (m_HashCode != anAtom.m_HashCode); } + +}; + +#endif /* __JATOM_H_ */ + diff --git a/calendar/modules/util/inc/jdefines.h b/calendar/modules/util/inc/jdefines.h new file mode 100644 index 00000000000..33addd8a108 --- /dev/null +++ b/calendar/modules/util/inc/jdefines.h @@ -0,0 +1,77 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +#ifndef _JULIAN_DEFINES_H +#define _JULIAN_DEFINES_H + +#include "xp_mcom.h" +#include "nspr.h" + +#ifdef PR_ASSERT +#undef PR_ASSERT +#endif + +#define PR_ASSERT(a) assert(a) + +/* create a XP_ACCESS call */ +#ifdef JXP_ACCESS +#undef JXP_ACCESS +#endif + +#define NOT_NULL(X) X + +#define JBOOL XP_Bool + +#if defined(XP_WIN32) +#define JSTRING CString +#define JCOLOR long +#define JXP_ACCESS _access +#elif defined(XP_UNIX) +#define stricmp strcasecmp +#define JXP_ACCESS access +#elif defined(XP_MAC) +#define JSTRING char[] +#define JCOLOR long +#define JXP_ACCESS access +#endif + +/* #define JRGB(r, g ,b) ( (r & 0xfff) | ((g & 0xfff) << 12)) | ((b & 0xfff) << 24))) */ +#define JRGB(r, g ,b) ( (r & 0xff) | ((g & 0xff) << 8) | ((b & 0xff) << 16) ) +#define JCRED(r) ( (r ) & 0xff ) +#define JCGREEN(g) ( (g >> 8 ) & 0xff ) +#define JCBLUE(b) ( (b >> 16) & 0xff ) + +typedef struct +{ + long x; + long y; +} JPOINT; + +typedef struct +{ + int iExternalLeading; +} JTEXTMETRIC; + +/* Turn on capi only for jsun */ +/* #define CAPI_READY 1 */ +#if DEBUG_jsun +/* #define CAPI_READY 1 */ +#endif + +#endif /* _JULIAN_DEFINES_H */ + diff --git a/calendar/modules/util/inc/jlog.h b/calendar/modules/util/inc/jlog.h new file mode 100644 index 00000000000..9147f965b0d --- /dev/null +++ b/calendar/modules/util/inc/jlog.h @@ -0,0 +1,226 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +/* + * jlog.h + * John Sun + * 3/2/98 10:46:48 AM + */ + +#ifndef __JLOG_H_ +#define __JLOG_H_ + +#include +#include "ptrarray.h" +#include "jlogvctr.h" +#include "jlogerr.h" +#include "nscalutilexp.h" + +/** + * The JLog class defines a log file to write to while parsing + * iCal objects. All iCal objects should take a JLog object during + * creation. + * The log currently writes to a file or to a JulianString in memory. + * To write to a file, the logString or log method is called, passing + * in the strings to write to the log, and a priority level of the + * message. If the priority level of the message is greater than + * the current log's internal priority level, then the message is + * written. + * Here is the current priority levels: + * Setting to Defaults = 0 + * Minor parse error: (i.e. Illegal duplicate properties, parameters) = 100 + * Invalid Attendee, Freebusy, property name, property value = 200. + * Invalid Number format = 200. + * Abrupt end of parsing iCal object = 300. + * Invalid Event, Todo, Journal, VFreebusy, VTimeZone = 300. + * 6-22-98. + * Changed from writing from one string to a list of in-memory strings. + */ +class NS_CAL_UTIL JLog +{ +private: + + /** + * Default log level + */ + static const t_int32 m_DEFAULT_LEVEL; + + /** + * Default log filename. + */ + static const char * m_DEFAULT_FILENAME; + + /* data members */ + + /** current log filename */ + const char * m_FileName; + + /** + * vector of vectors (each subvector contains vector of errors) + */ + JulianPtrArray * m_ErrorVctr; + + /** + * current vector of errors that is currently being written to. + */ + JulianLogErrorVector * m_CurrentEventLogVctr; + + /** TRUE = writeToString, FALSE = writeToFile, immutable */ + t_bool m_WriteToString; + + /** current log level */ + t_int32 m_Level; + + /** ptr to File */ + FILE * m_Stream; + + /* if successful addition return TRUE, else FALSE */ + t_bool addErrorToVector(JulianLogError * error); + +public: + + /** + * Constructor defines new log file. Using this constructor + * will write messages to the private string data-member. + * @param t_int32 initLevel = m_DEFAULT_LEVEL + */ + JLog(t_int32 initLevel = m_DEFAULT_LEVEL); + + /** + * Constructor defines new log file. Using this constructor + * will write message to a file. If no initFileName, + * defaults to default filename, If no level, defaults + * to default priority level + * @param initFilename initial filename + * @param initLevel initial priority level + */ + JLog(const char * initFilename, + t_int32 initLevel = m_DEFAULT_LEVEL); + + /** + * Destructor. + */ + ~JLog(); + + /** + * Sets priority level. + * @param level new priority level + * + * @return void + */ + void SetLevel(t_int32 level) { m_Level = level; } + + /** + * Gets priority level. + * + * @return current priority level + */ + t_int32 GetLevel() const { return m_Level; } + + + /** + * Add a new vector of errors to error log. + * This amounts to adding a new event log to the error log. + */ + void addEventErrorEntry(); + + + /** + * Set current event log vector to indicate whether this is a valid or + * invalid event. + * @param t_bool b + * + * @return void + */ + void setCurrentEventLogValidity(t_bool b); + + /** + * Set current event log vector's component type. + Valid types to pass in are + ECompType_VEVENT = VEvent, + ECompType_VTODO = VTodo, + ECompType_VFREEBUSY = VJournal, + ECompType_VTIMEZONE = VTimeZone, + ECompType_VFREEBUSY = VFreebusy, + ECompType_NSCALENDAR = NSCalendar, + ECompType_XCOMPONENT = X-Token Components + For example to setCurrentEventLogComponentType to VEVENT errors, + do the following: + + setCurrentEventLogComponentType(ECompType_VEVENT); + + to set current event log component type to NSCALENDAR errors + do the following: + + setCurrentEventLogComponentType(ECompType_NSCALENDAR); + + + * @param ComponentType + */ + void setCurrentEventLogComponentType(JulianLogErrorVector::ECompType iComponentType); + +#if 0 + void setUIDRecurrenceID(UnicodeString & uid, UnicodeString & rid); +#else + void setUID(UnicodeString & uid); +#endif + /** + * Returns the vector of errors for that event index. Returns 0 for + * invalid index. + */ + JulianPtrArray * getEventErrorLog(t_int32 index) const; + + /** + * Return the vector of log errors. + * + * @return JulianPtrArray * + */ + JulianPtrArray * GetErrorVector() const { return m_ErrorVctr; } + +#if 0 + /** + * @see setCurrentEventLogComponentType + * To create iterator on valid VEVENT errors only do following: + * createIterator(logPtr, ECompType_VEVENT, TRUE) + * To create iterator on invalid VEVENT errors only do following: + * createIterator(logPtr, ECompType_VEVENT, FALSE) + * To create iterator on valid VFREEBUSY errors only do following: + * createIterator(logPtr, ECompType_VFREEBUSY, FALSE) + * To create iterator on NSCALENDAR errors only do following: + * createIterator(logPtr, ECompType_NSCALENDAR, FALSE) + * To create iterator on X-TOKEN COMPONENT errors only do following: + * createIterator(logPtr, ECompType_XCOMPONENT, FALSE) + * + */ + static JulianLogIterator * createIterator(JLog * aLog, JulianLogErrorVector::ECompType iComponentType, t_bool bValid = TRUE); +#endif + + void logError(const t_int32 errorID, t_int32 level = m_DEFAULT_LEVEL); + void logError(const t_int32 errorID, UnicodeString & comment, + t_int32 level = m_DEFAULT_LEVEL); + void logError(const t_int32 errorID, UnicodeString & propName, + UnicodeString & propValue, t_int32 level = m_DEFAULT_LEVEL); + void logError(const t_int32 errorID, UnicodeString & propName, + UnicodeString & paramName, UnicodeString & paramValue, + t_int32 level = m_DEFAULT_LEVEL); + +}; + +#endif /* __JLOG_H_ */ + + diff --git a/calendar/modules/util/inc/jlogerr.h b/calendar/modules/util/inc/jlogerr.h new file mode 100644 index 00000000000..997b6ce7393 --- /dev/null +++ b/calendar/modules/util/inc/jlogerr.h @@ -0,0 +1,93 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the 'NPL'); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an 'AS IS' basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +/* + * jlogerr.h + * John Sun + * 6/22/98 2:13:19 PM + */ +#ifndef __JULIANLOGERROR_H_ +#define __JULIANLOGERROR_H_ + +#include "unistring.h" +#include "ptrarray.h" +#include "nscalutilexp.h" + +/** + * Encapsulates a Log Error Message. A log error message has more than just + * the error string. It also has a priority level and an error log number id. + * TODO: c++doc this + */ +class NS_CAL_UTIL JulianLogError +{ +private: + /*----------------------------- + ** MEMBERS + **---------------------------*/ + /*UnicodeString m_ErrorString;*/ + t_int32 m_Priority; + t_int32 m_ErrorID; + + UnicodeString m_ShortReturnStatusCode; + UnicodeString m_OffendingData; + /*----------------------------- + ** PRIVATE METHODS + **---------------------------*/ + JulianLogError(); +public: + /*----------------------------- + ** CONSTRUCTORS and DESTRUCTORS + **---------------------------*/ +#if 0 + JulianLogError(UnicodeString & errorString, + t_int32 errorPriority); +#endif + JulianLogError(t_int32 errorID, + UnicodeString & shortReturnStatusCode, + UnicodeString & offendingData, t_int32 errorPriority); + + virtual ~JulianLogError() {} + /*----------------------------- + ** ACCESSORS (GET AND SET) + **---------------------------*/ + //UnicodeString getErrorString() const { return m_ErrorString; } + t_int32 getPriority() const { return m_Priority; } + /*t_int32 getID() const { return m_ID; }*/ + + t_int32 getErrorID() const { return m_ErrorID; } + UnicodeString getShortReturnStatusCode() const { return m_ShortReturnStatusCode; } + UnicodeString getOffendingData() const { return m_OffendingData; } + + //void setErrorString(UnicodeString & errorString) { m_ErrorString = errorString; } + //void setPriority(t_int32 i) { m_Priority = i; } + /*void setID(t_int32 i) { m_ID = i; }*/ + /*----------------------------- + ** UTILITIES + **---------------------------*/ + //UnicodeString toString() { return m_ErrorString; } + /*----------------------------- + ** STATIC METHODS + **---------------------------*/ + static void deleteJulianLogErrorVector(JulianPtrArray * errors); + /*----------------------------- + ** OVERLOADED OPERATORS + **---------------------------*/ +}; + +#endif /* __JULIANLOGERROR_H_ */ + diff --git a/calendar/modules/util/inc/jlogitr.h b/calendar/modules/util/inc/jlogitr.h new file mode 100644 index 00000000000..c0341bf992a --- /dev/null +++ b/calendar/modules/util/inc/jlogitr.h @@ -0,0 +1,82 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the 'NPL'); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an 'AS IS' basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ +/* + * jlogitr.h + * John Sun + * 8/17/98 6:16:29 PM + */ + +#ifndef __JULIANLOGITERATOR_H_ +#define __JULIANLOGITERATOR_H_ + +#include "ptrarray.h" +#include "jlogvctr.h" +#include "nscalutilexp.h" + +class NS_CAL_UTIL JulianLogIterator +{ +private: + /*----------------------------- + ** MEMBERS + **---------------------------*/ + JulianPtrArray * m_LogToIterateOver; + JulianLogErrorVector::ECompType m_iComponentType; + t_bool m_bValid; + t_int32 m_iIndex; + + /*----------------------------- + ** PRIVATE METHODS + **---------------------------*/ + + JulianLogIterator(); + JulianLogIterator(JulianPtrArray * toIterate, JulianLogErrorVector::ECompType iComponentType, + t_bool bValid); + + JulianLogErrorVector * findNextElement(t_int32 startIndex); +public: + + + static JulianLogIterator * createIterator(JulianPtrArray * toIterate, + JulianLogErrorVector::ECompType iComponentType, t_bool bValid); + + /** + * Do this to create iterator of VEVENT log messages + t_int32 i; + JulianLogErrorVector * evtErrVctr = 0; + JulianLogError * error = 0; + if (log != 0) + { + JulianLogIterator * itr = log->createIterator((t_int32) ICalComponent::ICAL_COMPONENT_VEVENT) + for (evtErrVctr = itr->firstElement(); evtErrVctr != 0; evtErrVctr = itr->nextElement()) + { + if (evtErrVctr->GetErrors() != 0) + { + for (i = 0; i < evtErrVctr->GetErrors()->GetSize(); i++) + { + error = (JulianLogError *) errVctr->GetErrors()->GetAt(i); + // do what you want. + } + } + } + */ + JulianLogErrorVector * firstElement(); + JulianLogErrorVector * nextElement(); +}; + +#endif /* __JULIANLOGITERATOR_H_ */ + diff --git a/calendar/modules/util/inc/jlogvctr.h b/calendar/modules/util/inc/jlogvctr.h new file mode 100644 index 00000000000..3757147a75b --- /dev/null +++ b/calendar/modules/util/inc/jlogvctr.h @@ -0,0 +1,97 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the 'NPL'); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an 'AS IS' basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ +/* + * jlogvctr.h + * John Sun + * 8/17/98 4:43:51 PM + */ + +#ifndef __JLOGVECTOR_H_ +#define __JLOGVECTOR_H_ + +#include "jlogerr.h" +#include "nscalutilexp.h" + +class NS_CAL_UTIL JulianLogErrorVector +{ +public: + + enum ECompType + { + // these better match the ICalComponent::ICAL_COMPONENT enum + ECompType_VEVENT = 0, + ECompType_VTODO = 1, + ECompType_VJOURNAL = 2, + ECompType_VFREEBUSY = 3, + ECompType_VTIMEZONE = 4, + + ECompType_NSCALENDAR = 5, + ECompType_XCOMPONENT = 6 + }; + +private: + /*----------------------------- + ** MEMBERS + **---------------------------*/ + + ECompType m_ICalComponentType; + JulianPtrArray * m_ErrorVctr; + t_bool m_bValidEvent; + UnicodeString m_UID; +#if 0 + UnicodeString m_RID; +#endif +public: + + /*----------------------------- + ** CONSTRUCTORS and DESTRUCTORS + **---------------------------*/ + + JulianLogErrorVector(); + JulianLogErrorVector(ECompType iICalComponentType); + ~JulianLogErrorVector(); + + /*----------------------------- + ** ACCESSORS (GET AND SET) + **---------------------------*/ + + void SetValid(t_bool b) { m_bValidEvent = b; } + t_bool IsValid() const { return m_bValidEvent; } + + void SetComponentType(ECompType iComponentType) { m_ICalComponentType = iComponentType; } + ECompType GetComponentType() const { return m_ICalComponentType; } + + JulianPtrArray * GetErrors() const { return m_ErrorVctr; } + + const UnicodeString & GetUID() const { return m_UID; } + void SetUID(UnicodeString & uid) { m_UID = uid; } + +#if 0 + void SetRecurrenceID(UnicodeString & rid) { m_RID = rid; } + const UnicodeString & GetRecurrenceID() const { return m_RID; } +#endif + /*----------------------------- + ** UTILITIES + **---------------------------*/ + + void AddError(JulianLogError * error); +}; + + +#endif /* __JLOGVECTOR_H_ */ + diff --git a/calendar/modules/util/inc/julnstr.h b/calendar/modules/util/inc/julnstr.h new file mode 100644 index 00000000000..ee3891f2dd0 --- /dev/null +++ b/calendar/modules/util/inc/julnstr.h @@ -0,0 +1,506 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ +/** + * JulianString.h: interface for the JulianString class. + * + * This class is meant to work with single byte characters and + * null terminated strings. Interpretation of characters is + * accomplished with defines in . + * + * This class assumes 0 terminated strings that do not contain + * embedded null bytes. Methods that assume a character + * set assume the us-ascii characters. If you want I18N support, + * and arbitrary character set support, use UnicodeString. + * + * The character buffer pointer should never be NULL (0). If it + * is NULL, an allocation error has occurred. Since this class + * does not throw exceptions, you'll just have to check by + * calling IsValid(). + * + * Access to the internal character buffer is granted and the + * caller can easily abuse it. A goal of this class is to be + * high performance, so it assumes that anyone who uses the + * pointer to the internal character array will do so + * responsibly. This means: + * + * 1. don't exceed the string's buffer size + * 2. if the string buffer needs to be bigger, call + * Realloc() or ReallocTo() + * 3. if the string length changes or you make any changes + * to the string's contents via its GetBuffer() pointer, + * call DoneWithBuffer() when you're finished. + * + * -sman + */ + +#if !defined(_JULIANSTRING_H__7E478BB1_BFAA_11D1_8E18_0060088A4B1D__INCLUDED_) +#define _JULIANSTRING_H__7E478BB1_BFAA_11D1_8E18_0060088A4B1D__INCLUDED_ + +#include +#include + +#ifdef NSPR20 +#include "plstr.h" +#endif + +#include "julnstr.h" +#include "nscalutilexp.h" + +class NS_CAL_UTIL JulianString +{ + +private: + char* m_pBuf; // pointer to the char buf + size_t m_iBufSize; // size of char buf + size_t m_iStrlen; // length of the string + size_t m_iGrowBy; // resize by this much more than needed + int32 m_HashCode; // something unique + +public: + /** + * Empty constructor: JulianString x; + */ + JulianString(); + + /** + * JulianString x("hello, world"); + * @param p the string to copy as initial value + * @param iGrowBy When resizing, make buffer this much + * larger than needed. Default value is 32. + */ + JulianString(const char* p, size_t iGrowBy=32); + + /** + * JulianString x("hello, world"); + * JulianString y(x); + * @param s The string to copy as an initial value + * @param iGrowBy When resizing, make buffer this much + * larger than needed. Default value is 32. + */ + JulianString(const JulianString& s,size_t iGrowBy=32); + + /** + * Create a new JulianString with a buffer capacity equal to + * the supplied iBufSize. + * + * Example: + * JulianString x(2048); + * + * @param iBufSize Initial buffer size + * @param iGrowBy When resizing, make buffer this much + * larger than needed. Default value is 32. + */ + JulianString(size_t iBufSize,size_t iGrowBy=32); + + /** + * Destroy a JulianString. This deletes the character + * buffer used internally. + */ + virtual ~JulianString(); + + /** + * Copy the supplied null terminated string into *this. + * @param s the character array to be copied. + * @return a reference to *this + */ + JulianString& operator=(const char* s); + + /** + * Copy the supplied JulianString into *this. + * @param s the string to be copied. + * @return a reference to *this + */ + const JulianString& operator=(const JulianString& s); + + /** + * Append the supplied string to *this + * @param s the string to append + * @return a reference to *this + */ + JulianString& operator+=(JulianString&); + + /** + * Append the supplied string to *this + * @param s the string to append + * @return a reference to *this + */ + JulianString& operator+=(const char *); + + /** + * create a substring from the supplied index and count. If the + * index is negative, the characters are indexed from the right + * side of the string. That is: + * + *
+     *   JulianString x("012345");
+     *   x(2,3) returns a JulianString containing "234"
+     *   x(-2,2) returns a JulianString containing "45"
+     * 
+     *
+     * @param iIndex  index of first character of the sub
+     * @param iCount  number of characters to copy
+     * @return        a substring
+     */
+    JulianString operator()(int32 iIndex, int32 iCount);
+
+    /**
+     * return the character at the supplied index. If 
+     * index is negative, the characters are indexed from the right
+     * side of the string.  That is:
+     *
+     * 
+     *   JulianString x("012345");
+     *   x[2] returns '2'
+     *   x[-1] returns '5'
+     * 
+ * + * @param iIndex index of first character of the sub + * @return a character + */ + char operator[](int32 iIndex); + + /** + * return a JulianString that is the substring defined by + * the two supplied indeces. If either index is negative + * the return value is an empty string. If i is greater + * than j the return value is an empty string. If i is + * past the end of the string the return value is an + * empty string. If j is past the end of the string then + * the return value is the string from i to the end of + * the string. Examples: + * + *
+     *   JulianString x("012345");
+     *   x[2,4] returns a JulianString containing "234"
+     * 
+ * + * @param i index of first character of the sub + * @param j index of the last character of the sub + * @return a JulianString + */ + JulianString indexSubstr(int32 iIndex, int32 iCount); + + /** + * Encode illegal characters to something suitable for a URL + */ + void URLEncode(); + + /** + * Decode URLEncoded characters. + */ + void URLDecode(); + + /** + * return the leftmost n characters as a substring. If + * n is < 0 it is the same as calling Right(n). + * + * Examples: + * + *
+     *   JulianString x("012345");
+     *   x.Left(4) returns a JulianString containing "0123"
+     *   x.Left(-4) returns a JulianString containing "2345"
+     * 
+ * + * @param n number of characters to return + * @return a JulianString + */ + JulianString Left(int32 n); + + /** + * return the rightmost n characters as a substring. If + * n is < 0 it is the same as calling Left(n). + * + * Examples: + * + *
+     *   JulianString x("012345");
+     *   x.Right(4) returns a JulianString containing "2345"
+     *   x.Right(-4) returns a JulianString containing "0123"
+     * 
+ * + * @param n number of characters to return + * @return a JulianString + */ + JulianString Right(int32 n); + + /** + * Concatenate two strings and return the result. + * @param s1 one of the strings to concatenate + * @param s2 the other string to concatenate + * @return the concatenated string. + */ + JulianString operator+(JulianString&); + + /** + * compare this string to a char* + * @param x the Julian string + * @param p the string to compare to the JulianString + * @return 1 if they are equal, 0 if not. + */ + int operator==(const char* y); + + /** + * compare this string to another + * @param x one JulianString + * @param y the other JulianString + * @return 1 if they are equal, 0 if not. + */ + int operator==(JulianString& y); + + /** + * compare this string to a char* + * @param x the Julian string + * @param p the string to compare to the JulianString + * @return 0 if they are equal, 1 if not. + */ + int operator!=(const char* y); + + /** + * Compare one JulianString to another + * @param x one string + * @param y the other string + * @return 0 if they are equal, 1 if not. + */ + int operator!=(JulianString& y); + + /** + * Return a pointer to the internal character buffer used + * to maintain the string. If the characters are changed + * in any way, be sure to call DoneWithBuffer(). If the + * buffer needs to be resized, be sure to use Realloc() or + * ReallocTo(). + * @return pointer to the charcter buffer + */ + char* GetBuffer() const { return m_pBuf; } + + /** + * Return a pointer to internal character buffer starting + * at character index i. If the characters are changed + * in any way, be sure to call DoneWithBuffer(). If the + * buffer needs to be resized, be sure to use Realloc() or + * ReallocTo(). + * @return pointer to the charcter buffer + */ + char* GetBuffer(size_t i) const { return &m_pBuf[i]; } + + /** + * @return the length of the string in bytes. + */ + size_t GetStrlen() const { return m_iStrlen; } + + /** + * @return the current size (capacity) of the character buffer. + */ + size_t GetBufSize() const { return m_iBufSize; } + + /** + * @return TRUE if the character buffer is valid, FALSE + * if it is invalid (NULL). + */ + XP_Bool IsValid() const { return (0 == m_pBuf) ? FALSE : TRUE; } + + /** + * When the string length changes, presumably through + * external use of GetBuffer(), the internal string length + * is set by calling this method. Also, the hash code is + * reset since we have no idea what was done to the string. + */ + void DoneWithBuffer(); + + /** + * Verify that there is enough room to hold iLen bytes in + * the current buffer. If not, reallocate the buffer. This + * routine does not copy the old contents into the new buffer. + * + * @param iLen the size of the buffer needed + */ + void ReallocTo(size_t iLen); + + /** + * Verify that there is enough room to hold iLen bytes in + * the current buffer. If not, reallocate the buffer. Copy + * the old contents into the new buffer. + * + * @param iLen the size of the buffer needed + */ + void Realloc(size_t); + + /** + * compare the supplied string to *this + * @param p the string to compare to *this + * @param ic if true ignore case + * @return -1 if the supplied string is lexicographically + * less than *this, 0 if they are equal, and 1 if + * the supplied string is greater than *this. + */ + int32 CompareTo(const char* p, XP_Bool ic=FALSE) const; + + /** + * compare the supplied JulianString to *this + * @param s the JulianString to compare to *this + * @param ic if true ignore case + * @return -1 if the supplied string is lexicographically + * less than *this, 0 if they are equal, and 1 if + * the supplied string is greater than *this. + */ + int32 CompareTo(JulianString& s, XP_Bool ic=FALSE) const; + + /** + * Return the first index of the supplied string. + * @param p the string to look for + * @param iOffset offset within p to begin search + * @return -1 if the string is not found + * the offset if >= 0 + */ + int32 IndexOf(const char* p, int32 iOffset = 0) const; + + /** + * return the hash code. Calculate if needed. + * @return the hash code. + */ + int32 HashCode(); + + /** + * remove leading and trailing whitespace. + */ + void Trim(); + + /** + * Upshift the string. The upshifting is based on toupper() + * in + */ + void ToUpper(); + + /** + * Downshift the string. The downshifting is based on tolower() + * in + */ + void ToLower(); + + /** + * Get the string from application resources + */ + char * GetString(int i); + + /** + * Get the string from application resources and load into this + */ + JulianString& LoadString(int i); + + /** + * Find the first occurrence of a string within this string + * @param p the string to search for + * @param i the offset within this string to begin the search + * @return the index where the string was found. -1 means + * the string was not found. + */ + int32 Find(const char* p, int32 i=0) const; + + /** + * Find the first occurrence of a string within this string + * @param c the character to search for + * @param i the offset within this string to begin the search + * @return the index where the string was found. -1 means + * the string was not found. + */ + int32 Find(char c, int32 iOffset=0) const; + +#ifdef MOZ_TREX + /** + * Find the last occurrence of a string within this string + * @param p the string to search for + * @param i the offset within this string to begin the search + * @return the index where the string was found. -1 means + * the string was not found. + */ + int32 RFind(const char* p, int32 i=0) const; + + /** + * Find the last occurrence of a string within this string + * @param c the character to search for + * @param i the offset within this string to begin the search + * @return the index where the string was found. -1 means + * the string was not found. + */ + int32 RFind(char c, int32 iOffset=0) const; +#endif + + /** + * Prepend the supplied string to this + * @param p string to prepend + * @return *this + */ + JulianString& Prepend(const char* p); + + /** + * Prepend the supplied string to this + * @param p string to prepend + * @return *this + */ + JulianString& Prepend(JulianString& p); + + /** + * Replace the substring from index m to n with the supplied + * string. Any index less than 0 will be snapped to 0. Any + * index > than the last index in the current string will be + * snapped to the last index. If the current string is empty + * or uninitialized, it is simply set to the value of *p. + * If m > n the values are swapped. + * + * @param m starting index of substring + * @param n ending index of substring + * @param p string to insert + * @return *this + */ + JulianString& Replace(int32 m, int32 n, char* p); + + /** + * Replace the substring from index m to n with the supplied + * string. Any index less than 0 will be snapped to 0. Any + * index > than the last index in the current string will be + * snapped to the last index. If the current string is empty + * or uninitialized, it is simply set to the value of *p. + * If m > n the values are swapped. + * + * @param m starting index of substring + * @param n ending index of substring + * @param p string to insert + * @return *this + */ + JulianString& Replace(int32 m, int32 n, JulianString& p); + + /** + * Starting at index i, find the first occurrence of any character + * in p. + * @param i the offset within this string to begin the search + * @param p pointer to a null terminated list of characters + * @return the index where the string was found. -1 means + * the string was not found. + */ + int32 Strpbrk( int32 i, const char *p ) const; + +#if 0 + /* fails on BSD_3861.1 && SunOS4.1.3_U1 comment if 0 for now */ + friend ostream& operator<<(ostream&, JulianString&); + friend istream& operator>>(istream&, JulianString&); +#endif +}; + + +#endif /* !defined(_JULIANSTRING_H__7E478BB1_BFAA_11D1_8E18_0060088A4B1D__INCLUDED_) */ diff --git a/calendar/modules/util/inc/jutility.h b/calendar/modules/util/inc/jutility.h new file mode 100644 index 00000000000..99de5b8d742 --- /dev/null +++ b/calendar/modules/util/inc/jutility.h @@ -0,0 +1,128 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +/* + * jutility.h + * John Sun + * 2/3/98 10:12:32 AM + */ + +#ifndef __JULIANUTILITY_H_ +#define __JULIANUTILITY_H_ + +#include +#include +#include "ptrarray.h" +#include "jatom.h" +#include "nscalutilexp.h" + +/** + * A class that contains static utility methods. + * Also defines the RecurrenceType, which is used by the + * generator and Recurrence classes for defining span and interval lengths. + */ +class NS_CAL_UTIL JulianUtility +{ +private: + + /** + * Hide constructor from clients + */ + JulianUtility(); + +public: + + /** + * Define the Valid Mime-Encoding types for ICAL. + */ + enum MimeEncoding + { + MimeEncoding_7bit = 0, + MimeEncoding_Base64 = 1, + MimeEncoding_QuotedPrintable = 2 + }; + + /** + * Define the types used by Recurrence and generator class for + * defining span and interval lengths. + */ + enum RecurrenceType + { + RT_NONE = 0, + RT_MINUTELY = Calendar::MINUTE, + RT_HOURLY = Calendar::HOUR, + RT_DAILY = Calendar::DAY_OF_YEAR, + RT_WEEKLY = Calendar::WEEK_OF_YEAR, + RT_MONTHLY = Calendar::MONTH, + RT_YEARLY = Calendar::YEAR + }; + +#if 0 + /** + * a wrapper around atoi(or atol). + * @param nPtr the string to translate + * @param bParseError return TRUE if error in parse, otherwise, no -change + * @param size length of string + * @return the value of the string in a 32-bit number + */ + static t_int32 atot_int32(const char * nPtr, t_bool & bParseError, t_int32 size); +#endif + + /** + * a wrapper around atoi(or atol). Faster version. + * @param nPtr the string to translate + * @param bParseError return TRUE if error in parse, otherwise, no -change + * @param size length of string + * @return the value of the string in a 32-bit number + */ + static t_int32 atot_int32(char * nPtr, t_bool & bParseError, t_int32 size); + + + /** + * Checks to see if hashCode value is equal to any element in range. + * @param hashCode hashCode to search for + * @param range[] range of atoms to search from + * @param rangeSize length of range + * + * @return TRUE if hashCode in range, FALSE otherwise + */ + static t_bool checkRange(t_int32 hashCode, JAtom range[], t_int32 rangeSize); + + /*static char * unistrToStr(const UnicodeString & us); + static void TRACE_DateTimeVector(JulianPtrArray & vector); + static const UnicodeString & ToUpper(const UnicodeString & eightBitString);*/ + + /** + * Strip double quotest from the beginning and end of string + * if it has double-quotes at beginning and end. + * @param u string to strip double-quotes from + */ + static void stripDoubleQuotes(UnicodeString & u); + + /** + * Inserts double quotes at start and end of string if + * string != "". + * @param us string to add double-quotes to + * + * @return string with double-quotes at start, end (us) + */ + static UnicodeString & addDoubleQuotes(UnicodeString & us); +}; + +#endif /* __JULIANUTILITY_H_ */ + diff --git a/calendar/modules/util/inc/keyword.h b/calendar/modules/util/inc/keyword.h new file mode 100644 index 00000000000..2d019470664 --- /dev/null +++ b/calendar/modules/util/inc/keyword.h @@ -0,0 +1,1430 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +/* + * keyword.h + * John Sun + * 3/4/98 4:57:30 PM + */ + +#include +#include "jatom.h" +#include "nscalutilexp.h" + +#ifndef __KEYWORD_H_ +#define __KEYWORD_H_ + +/** + * singleton class to contain all ICAL keywords + */ +class NS_CAL_UTIL JulianKeyword +{ +private: + static JulianKeyword * m_Instance; + JulianKeyword(); + +public: + static JulianKeyword * Instance(); + ~JulianKeyword(); + + /* iCALENDAR KEYWORDS*/ + UnicodeString ms_sVCALENDAR; + JAtom ms_ATOM_VCALENDAR; + + /* iCALENDAR COMPONENTS KEYWORDS */ + UnicodeString ms_sVEVENT; + JAtom ms_ATOM_VEVENT; + + UnicodeString ms_sVTODO; + JAtom ms_ATOM_VTODO; + UnicodeString ms_sVJOURNAL; + JAtom ms_ATOM_VJOURNAL; + UnicodeString ms_sVFREEBUSY; + JAtom ms_ATOM_VFREEBUSY; + UnicodeString ms_sVTIMEZONE; + JAtom ms_ATOM_VTIMEZONE; + UnicodeString ms_sVALARM; + JAtom ms_ATOM_VALARM; + UnicodeString ms_sTZPART; + JAtom ms_ATOM_TZPART; + UnicodeString ms_sTIMEBASEDEVENT; + UnicodeString ms_sNSCALENDAR; + + /* iCalendar COMPONENT PROPERTY KEYWORDS */ + UnicodeString ms_sATTENDEE; + JAtom ms_ATOM_ATTENDEE; + + UnicodeString ms_sATTACH; + JAtom ms_ATOM_ATTACH; + + UnicodeString ms_sCATEGORIES; + JAtom ms_ATOM_CATEGORIES; + + UnicodeString ms_sCLASS; + JAtom ms_ATOM_CLASS; + + UnicodeString ms_sCOMMENT; + JAtom ms_ATOM_COMMENT; + + UnicodeString ms_sCOMPLETED; + JAtom ms_ATOM_COMPLETED; + + UnicodeString ms_sCONTACT; + JAtom ms_ATOM_CONTACT; + + UnicodeString ms_sCREATED; + JAtom ms_ATOM_CREATED; + + UnicodeString ms_sDTEND; + JAtom ms_ATOM_DTEND; + + UnicodeString ms_sDTSTART; + JAtom ms_ATOM_DTSTART; + + UnicodeString ms_sDTSTAMP; + JAtom ms_ATOM_DTSTAMP; + + UnicodeString ms_sDESCRIPTION; + JAtom ms_ATOM_DESCRIPTION; + + UnicodeString ms_sDUE; + JAtom ms_ATOM_DUE; + + UnicodeString ms_sDURATION; + JAtom ms_ATOM_DURATION; + + UnicodeString ms_sEXDATE; + JAtom ms_ATOM_EXDATE; + + UnicodeString ms_sEXRULE; + JAtom ms_ATOM_EXRULE; + + UnicodeString ms_sFREEBUSY; + JAtom ms_ATOM_FREEBUSY; + + UnicodeString ms_sGEO; + JAtom ms_ATOM_GEO; + + UnicodeString ms_sLASTMODIFIED; + JAtom ms_ATOM_LASTMODIFIED; + + UnicodeString ms_sLOCATION; + JAtom ms_ATOM_LOCATION; + + UnicodeString ms_sORGANIZER; + JAtom ms_ATOM_ORGANIZER; + + UnicodeString ms_sPERCENTCOMPLETE; + JAtom ms_ATOM_PERCENTCOMPLETE; + + UnicodeString ms_sPRIORITY; + JAtom ms_ATOM_PRIORITY; + + UnicodeString ms_sRDATE; + JAtom ms_ATOM_RDATE; + + UnicodeString ms_sRRULE; + JAtom ms_ATOM_RRULE; + + UnicodeString ms_sRECURRENCEID; + JAtom ms_ATOM_RECURRENCEID; + + /* UnicodeString ms_sRESPONSESEQUENCE = "RESPONSE-SEQUENCE"; */ + /* JAtom ms_ATOM_RESPONSESEQUENCE; */ + + UnicodeString ms_sRELATEDTO; + JAtom ms_ATOM_RELATEDTO; + + UnicodeString ms_sREPEAT; + JAtom ms_ATOM_REPEAT; + + UnicodeString ms_sREQUESTSTATUS; + JAtom ms_ATOM_REQUESTSTATUS; + + UnicodeString ms_sRESOURCES; + JAtom ms_ATOM_RESOURCES; + + UnicodeString ms_sSEQUENCE; + JAtom ms_ATOM_SEQUENCE; + + UnicodeString ms_sSTATUS; + JAtom ms_ATOM_STATUS; + + UnicodeString ms_sSUMMARY; + JAtom ms_ATOM_SUMMARY; + + UnicodeString ms_sTRANSP; + JAtom ms_ATOM_TRANSP; + + UnicodeString ms_sTRIGGER; + JAtom ms_ATOM_TRIGGER; + + UnicodeString ms_sUID; + JAtom ms_ATOM_UID; + + UnicodeString ms_sURL; + JAtom ms_ATOM_URL; + + UnicodeString ms_sTZOFFSET; + JAtom ms_ATOM_TZOFFSET; + + UnicodeString ms_sTZOFFSETTO; + JAtom ms_ATOM_TZOFFSETTO; + + UnicodeString ms_sTZOFFSETFROM; + JAtom ms_ATOM_TZOFFSETFROM; + + UnicodeString ms_sTZNAME; + JAtom ms_ATOM_TZNAME; + + UnicodeString ms_sDAYLIGHT; + JAtom ms_ATOM_DAYLIGHT; + + UnicodeString ms_sSTANDARD; + JAtom ms_ATOM_STANDARD; + + UnicodeString ms_sTZURL; + JAtom ms_ATOM_TZURL; + + UnicodeString ms_sTZID; + JAtom ms_ATOM_TZID; + + /* Boolean value KEYWORDS */ + UnicodeString ms_sTRUE; + JAtom ms_ATOM_TRUE; + + UnicodeString ms_sFALSE; + JAtom ms_ATOM_FALSE; + + /* ITIP METHOD NAME KEYWORDS */ + UnicodeString ms_sPUBLISH; + JAtom ms_ATOM_PUBLISH; + + UnicodeString ms_sREQUEST; + JAtom ms_ATOM_REQUEST; + + UnicodeString ms_sREPLY; + JAtom ms_ATOM_REPLY; + + UnicodeString ms_sCANCEL; + JAtom ms_ATOM_CANCEL; + + UnicodeString ms_sREFRESH; + JAtom ms_ATOM_REFRESH; + + UnicodeString ms_sCOUNTER; + JAtom ms_ATOM_COUNTER; + + UnicodeString ms_sDECLINECOUNTER; + JAtom ms_ATOM_DECLINECOUNTER; + + UnicodeString ms_sADD; + JAtom ms_ATOM_ADD; + + /* not really actual method names */ + UnicodeString ms_sDELEGATEREQUEST; + JAtom ms_ATOM_DELEGATEREQUEST; + + UnicodeString ms_sDELEGATEREPLY; + JAtom ms_ATOM_DELEGATEREPLY; + + /* NSCALENDAR */ + /* NSCalendar PROPERTY NAMES KEYWORDS */ + + UnicodeString ms_sPRODID; + JAtom ms_ATOM_PRODID; + + UnicodeString ms_sVERSION; + JAtom ms_ATOM_VERSION; + + UnicodeString ms_sMETHOD; + JAtom ms_ATOM_METHOD; + + UnicodeString ms_sSOURCE; + JAtom ms_ATOM_SOURCE; + + UnicodeString ms_sCALSCALE; + JAtom ms_ATOM_CALSCALE; + + UnicodeString ms_sNAME; + JAtom ms_ATOM_NAME; + + /* Valid calscale value KEYWORDS, also accepts Iana-scale */ + UnicodeString ms_sGREGORIAN; + JAtom ms_ATOM_GREGORIAN; + + /* End NSCalendar */ + + /* TimeBasedEvent */ + /* CLASS property Keywords */ + + UnicodeString ms_sPUBLIC; + JAtom ms_ATOM_PUBLIC; + + UnicodeString ms_sPRIVATE; + JAtom ms_ATOM_PRIVATE; + + UnicodeString ms_sCONFIDENTIAL; + JAtom ms_ATOM_CONFIDENTIAL; + + /* STATUS property Keywords */ + UnicodeString ms_sNEEDSACTION; + JAtom ms_ATOM_NEEDSACTION; + + /*UnicodeString ms_sCOMPLETED;*/ + /*JAtom ms_ATOM_COMPLETED;*/ + + UnicodeString ms_sINPROCESS; + JAtom ms_ATOM_INPROCESS; + + UnicodeString ms_sTENTATIVE; + JAtom ms_ATOM_TENTATIVE; + + UnicodeString ms_sCONFIRMED; + JAtom ms_ATOM_CONFIRMED; + + UnicodeString ms_sCANCELLED; + JAtom ms_ATOM_CANCELLED; + + UnicodeString ms_sDRAFT; + JAtom ms_ATOM_DRAFT; + + UnicodeString ms_sFINAL; + JAtom ms_ATOM_FINAL; + + + /* TRANSP property Keywords */ + UnicodeString ms_sOPAQUE; + JAtom ms_ATOM_OPAQUE; + + UnicodeString ms_sTRANSPARENT; + JAtom ms_ATOM_TRANSPARENT; + + /* End TimeBasedEvent */ + + /* ATTENDEE */ + /* parameter names as in the input stream. Define for possible future changes */ + UnicodeString ms_sROLE; + JAtom ms_ATOM_ROLE; + + /* replaces TYPE */ + UnicodeString ms_sCUTYPE; + JAtom ms_ATOM_CUTYPE; + + UnicodeString ms_sTYPE; + JAtom ms_ATOM_TYPE; + + UnicodeString ms_sCN; + JAtom ms_ATOM_CN; + + UnicodeString ms_sPARTSTAT; + JAtom ms_ATOM_PARTSTAT; + + UnicodeString ms_sRSVP; + JAtom ms_ATOM_RSVP; + + UnicodeString ms_sEXPECT; + JAtom ms_ATOM_EXPECT; + + UnicodeString ms_sMEMBER; + JAtom ms_ATOM_MEMBER; + + UnicodeString ms_sDELEGATED_TO; + JAtom ms_ATOM_DELEGATED_TO; + + UnicodeString ms_sDELEGATED_FROM; + JAtom ms_ATOM_DELEGATED_FROM; + + UnicodeString ms_sSENTBY; + JAtom ms_ATOM_SENTBY; + + UnicodeString ms_sDIR; + JAtom ms_ATOM_DIR; + + /* ROLE Keywords */ + /*UnicodeString ms_sATTENDEE;*/ + /*JAtom ms_ATOM_ATTENDEE;*/ + /*UnicodeString ms_sORGANIZER;*/ + /*JAtom ms_ATOM_ORGANIZER;*/ + /*UnicodeString ms_sOWNER;*/ + /*JAtom ms_ATOM_OWNER;*/ + /*UnicodeString ms_sDELEGATE;*/ + /*JAtom ms_ATOM_DELEGATE;*/ + UnicodeString ms_sCHAIR; + JAtom ms_ATOM_CHAIR; + + /*UnicodeString ms_sPARTICIPANT;*/ + /*JAtom ms_ATOM_PARTICIPANT;*/ + + UnicodeString ms_sREQ_PARTICIPANT; + JAtom ms_ATOM_REQ_PARTICIPANT; + + UnicodeString ms_sOPT_PARTICIPANT; + JAtom ms_ATOM_OPT_PARTICIPANT; + + UnicodeString ms_sNON_PARTICIPANT; + JAtom ms_ATOM_NON_PARTICIPANT; + + /* TYPE Keywords */ + UnicodeString ms_sUNKNOWN; + JAtom ms_ATOM_UNKNOWN; + + UnicodeString ms_sINDIVIDUAL; + JAtom ms_ATOM_INDIVIDUAL; + + UnicodeString ms_sGROUP; + JAtom ms_ATOM_GROUP; + + UnicodeString ms_sRESOURCE; + JAtom ms_ATOM_RESOURCE; + + UnicodeString ms_sROOM; + JAtom ms_ATOM_ROOM; + + /* STATUS Keywords */ + /*UnicodeString ms_sNEEDSACTION = "NEEDS-ACTION"; */ + /*JAtom ms_ATOM_NEEDSACTION;*/ + + UnicodeString ms_sACCEPTED; + JAtom ms_ATOM_ACCEPTED; + + UnicodeString ms_sDECLINED; + JAtom ms_ATOM_DECLINED; + + /*UnicodeString ms_sTENTATIVE; + JAtom ms_ATOM_TENTATIVE; + + UnicodeString ms_sCONFIRMED; + JAtom ms_ATOM_CONFIRMED; + + UnicodeString ms_sCOMPLETED; + JAtom ms_ATOM_COMPLETED;*/ + + UnicodeString ms_sDELEGATED; + JAtom ms_ATOM_DELEGATED; + + /*UnicodeString ms_sCANCELLED; + JAtom ms_ATOM_CANCELLED;*/ + + UnicodeString ms_sVCALNEEDSACTION; + JAtom ms_ATOM_VCALNEEDSACTION; + + /* RSVP Keywords */ + /*UnicodeString ms_sFALSE; + JAtom ms_ATOM_FALSE; + + UnicodeString ms_sTRUE; + JAtom ms_ATOM_TRUE;*/ + + /* EXPECT Keywords*/ + UnicodeString ms_sFYI; + JAtom ms_ATOM_FYI; + + UnicodeString ms_sREQUIRE; + JAtom ms_ATOM_REQUIRE; + + /*UnicodeString ms_sREQUEST; + JAtom ms_ATOM_REQUEST;*/ + + UnicodeString ms_sIMMEDIATE; + JAtom ms_ATOM_IMMEDIATE; + + /*End ATTENDEE*/ + + /*RecurrenceID*/ + UnicodeString ms_sRANGE; + JAtom ms_ATOM_RANGE; + + UnicodeString ms_sTHISANDPRIOR; + JAtom ms_ATOM_THISANDPRIOR; + + UnicodeString ms_sTHISANDFUTURE; + JAtom ms_ATOM_THISANDFUTURE; + + /*End RecurrenceID*/ + + /* FREEBUSY */ + UnicodeString ms_sFBTYPE; + JAtom ms_ATOM_FBTYPE; + + UnicodeString ms_sBSTAT; /* renamed from status */ + JAtom ms_ATOM_BSTAT; + + UnicodeString ms_sBUSY; + JAtom ms_ATOM_BUSY; + + UnicodeString ms_sFREE; + JAtom ms_ATOM_FREE; + + UnicodeString ms_sBUSY_UNAVAILABLE; + JAtom ms_ATOM_BUSY_UNAVAILABLE; + + UnicodeString ms_sBUSY_TENTATIVE; + JAtom ms_ATOM_BUSY_TENTATIVE; + + UnicodeString ms_sUNAVAILABLE; + JAtom ms_ATOM_UNAVAILABLE; + + /*UnicodeString ms_sTENTATIVE; + JAtom ms_ATOM_TENTATIVE;*/ + + /*End FREEBUSY*/ + + /* ALARM */ + /* Alarm prop keywords */ + UnicodeString ms_sACTION; + JAtom ms_ATOM_ACTION; + + /* Alarm Categories keywords */ + UnicodeString ms_sAUDIO; + JAtom ms_ATOM_AUDIO; + + UnicodeString ms_sDISPLAY; + JAtom ms_ATOM_DISPLAY; + + UnicodeString ms_sEMAIL; + JAtom ms_ATOM_EMAIL; + + UnicodeString ms_sPROCEDURE; + JAtom ms_ATOM_PROCEDURE; + + /* End ALARM */ + /*DESCRIPTION*/ + UnicodeString ms_sENCODING; + JAtom ms_ATOM_ENCODING; + + UnicodeString ms_sCHARSET; + JAtom ms_ATOM_CHARSET; + + UnicodeString ms_sQUOTED_PRINTABLE; + JAtom ms_ATOM_QUOTED_PRINTABLE; + + /* End DESCRIPTION */ + + /* PARAMETER NAME, VALUE KEYWORDS */ + /*UnicodeString ms_sENCODING; + JAtom ms_ATOM_ENCODING;*/ + + UnicodeString ms_sVALUE; + JAtom ms_ATOM_VALUE; + + UnicodeString ms_sLANGUAGE; + JAtom ms_ATOM_LANGUAGE; + + UnicodeString ms_sALTREP; + JAtom ms_ATOM_ALTREP; + + /*UnicodeString ms_sSENTBY; + JAtom ms_ATOM_SENTBY;*/ + + UnicodeString ms_sRELTYPE; + JAtom ms_ATOM_RELTYPE; + + UnicodeString ms_sFMTTYPE; + JAtom ms_ATOM_FMTTYPE; + + UnicodeString ms_sRELATED; + JAtom ms_ATOM_RELATED; + + /*UnicodeString ms_sTZID; + JAtom ms_ATOM_TZID;*/ + + /* Reltype*/ + UnicodeString ms_sPARENT; + JAtom ms_ATOM_PARENT; + + UnicodeString ms_sCHILD; + JAtom ms_ATOM_CHILD; + + UnicodeString ms_sSIBLING; + JAtom ms_ATOM_SIBLING; + + /* Related*/ + UnicodeString ms_sSTART; + JAtom ms_ATOM_START; + + UnicodeString ms_sEND; + JAtom ms_ATOM_END; + + /* Encoding types*/ + UnicodeString ms_s8bit; + JAtom ms_ATOM_8bit; + + UnicodeString ms_sBase64; + JAtom ms_ATOM_Base64; + + UnicodeString ms_s7bit; + JAtom ms_ATOM_7bit; + + UnicodeString ms_sQ; + JAtom ms_ATOM_Q; + + UnicodeString ms_sB; + JAtom ms_ATOM_B; + + + /* Value types*/ + UnicodeString ms_sURI; + JAtom ms_ATOM_URI; + + UnicodeString ms_sTEXT; + JAtom ms_ATOM_TEXT; + + UnicodeString ms_sBINARY; + JAtom ms_ATOM_BINARY; + + UnicodeString ms_sDATE; + JAtom ms_ATOM_DATE; + + UnicodeString ms_sRECUR; + JAtom ms_ATOM_RECUR; + + UnicodeString ms_sTIME; + JAtom ms_ATOM_TIME; + + UnicodeString ms_sDATETIME; + JAtom ms_ATOM_DATETIME; + + UnicodeString ms_sPERIOD; + JAtom ms_ATOM_PERIOD; + + /*UnicodeString ms_sDURATION; + JAtom ms_ATOM_DURATION;*/ + + UnicodeString ms_sBOOLEAN; + JAtom ms_ATOM_BOOLEAN; + + UnicodeString ms_sINTEGER; + JAtom ms_ATOM_INTEGER; + + UnicodeString ms_sFLOAT; + JAtom ms_ATOM_FLOAT; + + UnicodeString ms_sCALADDRESS; + JAtom ms_ATOM_CALADDRESS; + + UnicodeString ms_sUTCOFFSET; + JAtom ms_ATOM_UTCOFFSET; + + /*End PARAMETER NAME, VALUE KEYWORDS*/ + + /*other useful strings*/ + UnicodeString ms_sMAILTO_COLON; + + UnicodeString ms_sBEGIN; + JAtom ms_ATOM_BEGIN; + + UnicodeString ms_sBEGIN_WITH_COLON; + JAtom ms_ATOM_BEGIN_WITH_COLON; + + /*UnicodeString ms_sEND; + JAtom ms_ATOM_END;*/ + + UnicodeString ms_sEND_WITH_COLON; + JAtom ms_ATOM_END_WITH_COLON; + + UnicodeString ms_sBEGIN_VCALENDAR; + JAtom ms_ATOM_BEGIN_VCALENDAR; + + UnicodeString ms_sEND_VCALENDAR; + JAtom ms_ATOM_END_VCALENDAR; + + UnicodeString ms_sBEGIN_VFREEBUSY; + JAtom ms_ATOM_BEGIN_VFREEBUSY; + + UnicodeString ms_sEND_VFREEBUSY; + JAtom ms_ATOM_END_VFREEBUSY; + + UnicodeString ms_sLINEBREAK; + JAtom ms_ATOM_LINEBREAK; + + UnicodeString ms_sOK; + JAtom ms_ATOM_OK; + + UnicodeString ms_sCOMMA_SYMBOL; + JAtom ms_ATOM_COMMA_SYMBOL; + + UnicodeString ms_sCOLON_SYMBOL; + JAtom ms_ATOM_COLON_SYMBOL; + + UnicodeString ms_sDOUBLEQUOTE_SYMBOL; + UnicodeString ms_sSEMICOLON_SYMBOL; + + UnicodeString ms_sRRULE_WITH_SEMICOLON; + + UnicodeString ms_sDEFAULT_DELIMS; + + UnicodeString ms_sLINEBREAKSPACE; + UnicodeString ms_sALTREPQUOTE; + UnicodeString ms_sLINEFEEDSPACE; + + UnicodeString ms_sXPARAMVAL; + /* end other useful strings*/ + + /* recurrence keywords */ + UnicodeString ms_sUNTIL; + JAtom ms_ATOM_UNTIL; + + UnicodeString ms_sCOUNT; + JAtom ms_ATOM_COUNT; + + UnicodeString ms_sINTERVAL; + JAtom ms_ATOM_INTERVAL; + + UnicodeString ms_sFREQ; + JAtom ms_ATOM_FREQ; + + UnicodeString ms_sBYSECOND; + JAtom ms_ATOM_BYSECOND; + + UnicodeString ms_sBYMINUTE; + JAtom ms_ATOM_BYMINUTE; + + UnicodeString ms_sBYHOUR; + JAtom ms_ATOM_BYHOUR; + + UnicodeString ms_sBYDAY; + JAtom ms_ATOM_BYDAY; + + UnicodeString ms_sBYMONTHDAY; + JAtom ms_ATOM_BYMONTHDAY; + + UnicodeString ms_sBYYEARDAY; + JAtom ms_ATOM_BYYEARDAY; + + UnicodeString ms_sBYWEEKNO; + JAtom ms_ATOM_BYWEEKNO; + + UnicodeString ms_sBYMONTH; + JAtom ms_ATOM_BYMONTH; + + UnicodeString ms_sBYSETPOS; + JAtom ms_ATOM_BYSETPOS; + + UnicodeString ms_sWKST; + JAtom ms_ATOM_WKST; + + /* frequency values*/ + + UnicodeString ms_sSECONDLY; + JAtom ms_ATOM_SECONDLY; + UnicodeString ms_sMINUTELY; + JAtom ms_ATOM_MINUTELY; + UnicodeString ms_sHOURLY; + JAtom ms_ATOM_HOURLY; + UnicodeString ms_sDAILY; + JAtom ms_ATOM_DAILY; + UnicodeString ms_sWEEKLY; + JAtom ms_ATOM_WEEKLY; + UnicodeString ms_sMONTHLY; + JAtom ms_ATOM_MONTHLY; + UnicodeString ms_sYEARLY; + JAtom ms_ATOM_YEARLY; + + /* day values */ + + UnicodeString ms_sSU; + JAtom ms_ATOM_SU; + UnicodeString ms_sMO; + JAtom ms_ATOM_MO; + UnicodeString ms_sTU; + JAtom ms_ATOM_TU; + UnicodeString ms_sWE; + JAtom ms_ATOM_WE; + UnicodeString ms_sTH; + JAtom ms_ATOM_TH; + UnicodeString ms_sFR; + JAtom ms_ATOM_FR; + UnicodeString ms_sSA; + JAtom ms_ATOM_SA; + + /* helperUnicodeStrings and atoms*/ + + UnicodeString ms_sBYDAYYEARLY; + JAtom ms_ATOM_BYDAYYEARLY; + UnicodeString ms_sBYDAYMONTHLY; + JAtom ms_ATOM_BYDAYMONTHLY; + UnicodeString ms_sBYDAYWEEKLY; + JAtom ms_ATOM_BYDAYWEEKLY; + UnicodeString ms_sDEFAULT; + JAtom ms_ATOM_DEFAULT; + + /* content-type */ + UnicodeString ms_sCONTENT_TRANSFER_ENCODING; + +}; +/** + * singleton class that contains JAtom ranges for parameter checking. + */ +class NS_CAL_UTIL JulianAtomRange +{ +private: + static JulianAtomRange * m_Instance; + JulianAtomRange(); + +public: + + ~JulianAtomRange(); + static JulianAtomRange * Instance(); + + /* + calscale: x-token + method: x-token + prodid: x-token + version: x-token + attach: value,encoding,fmttype x-token + categories: language x-token + class: x-token + comment: altrep, language x-token + description: altrep, language x-token + geo: x-token + location: altrep, language x-token + percent-complete: x-token + priority: x-token + resources: altrep, language x-token + status: x-token + summary: altrep, language x-token + completed: x-token + dtend: value, tzid x-token + due: value, tzid x-token + dtstart: value, tzid x-token + duration: x-token + freebusy: fbtype x-token + transp: x-token + tzid: x-token + tzname: language x-token + tzoffsetfrom: x-token + tzoffsetto: x-token + tzurl: x-token + attendee: cutype, member,role,partstat,rsvp,delto,delfrom,sentby,cn,dir,language,x-token + contact: altrep, language x-token + organizer: cutype,dir,sentby,language, x-token + recid: value, tzid, range x-token + relatedto: reltype x-token + url: x-token + uid: x-token + exdate: value, tzid x-token + exrule: x-token + rdate: value, tzid x-token + rrule: x-token + action: x-token + repeat: x-token + rdate: value, x-token + created: x-token + dtstamp: x-token + lastmod: x-token + sequence: x-token + request-status: language x-token + */ + + /* ATOM RANGES for PARAMETERS */ + JAtom ms_asAltrepLanguageParamRange[2]; + t_int32 ms_asAltrepLanguageParamRangeSize; + + JAtom ms_asTZIDValueParamRange[2]; + t_int32 ms_asTZIDValueParamRangeSize; + + JAtom ms_asLanguageParamRange[1]; + t_int32 ms_asLanguageParamRangeSize; + + JAtom ms_asEncodingValueParamRange[2]; + t_int32 ms_asEncodingValueParamRangeSize; + + JAtom ms_asEncodingValueFMTTypeParamRange[3]; + t_int32 ms_asEncodingValueFMTTypeParamRangeSize; + + JAtom ms_asSentByParamRange[1]; + t_int32 ms_asSentByParamRangeSize; + + JAtom ms_asReltypeParamRange[1]; + t_int32 ms_asReltypeParamRangeSize; + + JAtom ms_asRelatedValueParamRange[2]; + t_int32 ms_asRelatedValueParamRangeSize; + + JAtom ms_asBinaryURIValueRange[2]; + t_int32 ms_asBinaryURIValueRangeSize; + + JAtom ms_asDateDateTimeValueRange[2]; + t_int32 ms_asDateDateTimeValueRangeSize; + + JAtom ms_asDurationDateTimeValueRange[2]; + t_int32 ms_asDurationDateTimeValueRangeSize; + + JAtom ms_asDateDateTimePeriodValueRange[3]; + t_int32 ms_asDateDateTimePeriodValueRangeSize; + + JAtom ms_asRelTypeRange[3]; + t_int32 ms_iRelTypeRangeSize; + + JAtom ms_asRelatedRange[2]; + t_int32 ms_iRelatedRangeSize; + + JAtom ms_asParameterRange[5]; + t_int32 ms_iParameterRangeSize; + JAtom ms_asIrregularProperties[4]; + t_int32 ms_iIrregularPropertiesSize; + JAtom ms_asValueRange[14]; + t_int32 ms_iValueRangeSize; + JAtom ms_asEncodingRange[2]; + t_int32 ms_iEncodingRangeSize; +}; +/*---------------------------------------------------------------------*/ + +/** + * Singleton class to contain JLog error messages. + * For now, messages are not localized. + * NOTE: TODO: Localize the log error message one day + */ +class NS_CAL_UTIL JulianLogErrorMessage +{ + +private: + static JulianLogErrorMessage * m_Instance; + JulianLogErrorMessage(); + +public: + ~JulianLogErrorMessage(); + static JulianLogErrorMessage * Instance(); + +#if 0 + UnicodeString ms_sDTEndBeforeDTStart; + UnicodeString ms_sExportError; + UnicodeString ms_sNTimeParamError; + UnicodeString ms_sInvalidPromptValue; + UnicodeString ms_sSTimeParamError; + UnicodeString ms_sISO8601ParamError; + UnicodeString ms_sInvalidTimeStringError; + UnicodeString ms_sTimeZoneParamError; + UnicodeString ms_sLocaleParamError; + UnicodeString ms_sLocaleNotFoundError; + UnicodeString ms_sPatternParamError; + UnicodeString ms_sInvalidPatternError; + UnicodeString ms_sRRuleParamError; + UnicodeString ms_sERuleParamError; + UnicodeString ms_sBoundParamError; + UnicodeString ms_sInvalidRecurrenceError; + UnicodeString ms_sUnzipNullError; + UnicodeString ms_sCommandNotFoundError; + UnicodeString ms_sInvalidTimeZoneError; + UnicodeString ms_sFileNotFound; + UnicodeString ms_sInvalidPropertyName; + UnicodeString ms_sInvalidPropertyValue; + UnicodeString ms_sInvalidParameterName; + UnicodeString ms_sInvalidParameterValue; + UnicodeString ms_sMissingStartingTime; + UnicodeString ms_sMissingEndingTime; + UnicodeString ms_sEndBeforeStartTime; + UnicodeString ms_sMissingSeqNo; + UnicodeString ms_sMissingReplySeq; + UnicodeString ms_sMissingURL; + UnicodeString ms_sMissingDTStamp; + UnicodeString ms_sMissingUID; + UnicodeString ms_sMissingDescription; + UnicodeString ms_sMissingMethodProvided; + UnicodeString ms_sMissingOrganizer; + UnicodeString ms_sMissingSummary; + UnicodeString ms_sMissingAttendees; + UnicodeString ms_sInvalidVersionNumber; + UnicodeString ms_sUnknownUID; + UnicodeString ms_sMissingUIDInReply; + UnicodeString ms_sMissingValidDTStamp; + UnicodeString ms_sDeclineCounterCalledByAttendee; + UnicodeString ms_sPublishCalledByAttendee; + UnicodeString ms_sRequestCalledByAttendee; + UnicodeString ms_sCancelCalledByAttendee; + UnicodeString ms_sCounterCalledByOrganizer; + UnicodeString ms_sRefreshCalledByOrganizer; + UnicodeString ms_sReplyCalledByOrganizer; + UnicodeString ms_sAddReplySequenceOutOfRange; + UnicodeString ms_sDuplicatedProperty; + UnicodeString ms_sDuplicatedParameter; + UnicodeString ms_sConflictMethodAndStatus; + UnicodeString ms_sConflictCancelAndConfirmedTentative; + UnicodeString ms_sMissingUIDToMatchEvent; + UnicodeString ms_sInvalidNumberFormat; + UnicodeString ms_sDelegateRequestError; + UnicodeString ms_sInvalidRecurrenceIDRange; + UnicodeString ms_sUnknownRecurrenceID; + UnicodeString ms_sPropertyValueTypeMismatch; + UnicodeString ms_sInvalidRRule; + UnicodeString ms_sInvalidExRule; + UnicodeString ms_sInvalidRDate; + UnicodeString ms_sInvalidExDate; + UnicodeString ms_sInvalidEvent; + UnicodeString ms_sInvalidComponent; + UnicodeString ms_sInvalidAlarm; + UnicodeString ms_sInvalidTZPart; + UnicodeString ms_sInvalidAlarmCategory; + UnicodeString ms_sInvalidAttendee; + UnicodeString ms_sInvalidFreebusy; + UnicodeString ms_sDurationAssertionFailed; + UnicodeString ms_sDurationParseFailed; + UnicodeString ms_sPeriodParseFailed; + UnicodeString ms_sPeriodStartInvalid; + UnicodeString ms_sPeriodEndInvalid; + UnicodeString ms_sPeriodEndBeforeStart; + UnicodeString ms_sPeriodDurationZero; + UnicodeString ms_sFreebusyPeriodInvalid; + UnicodeString ms_sOptParamInvalidPropertyValue; + UnicodeString ms_sOptParamInvalidPropertyName; + UnicodeString ms_sInvalidOptionalParam; + UnicodeString ms_sAbruptEndOfParsing; + UnicodeString ms_sLastModifiedBeforeCreated; + UnicodeString ms_sMultipleOwners; + UnicodeString ms_sMultipleOrganizers; + UnicodeString ms_sMissingOwner; + UnicodeString ms_sMissingDueTime; + UnicodeString ms_sCompletedPercentMismatch; + UnicodeString ms_sMissingFreqTagRecurrence; + UnicodeString ms_sFreqIntervalMismatchRecurrence; + UnicodeString ms_sInvalidPercentCompleteValue; + UnicodeString ms_sInvalidPriorityValue; + UnicodeString ms_sInvalidByHourValue; + UnicodeString ms_sInvalidByMinuteValue; + UnicodeString ms_sByDayFreqIntervalMismatch; + UnicodeString ms_sInvalidByMonthDayValue; + UnicodeString ms_sInvalidByYearDayValue; + UnicodeString ms_sInvalidBySetPosValue; + UnicodeString ms_sInvalidByWeekNoValue; + UnicodeString ms_sInvalidWeekStartValue; + UnicodeString ms_sInvalidByMonthValue; + UnicodeString ms_sInvalidByDayValue; + UnicodeString ms_sInvalidFrequency; + UnicodeString ms_sInvalidDayArg; + UnicodeString ms_sVerifyZeroError; + UnicodeString ms_sRoundedPercentCompleteTo100; + UnicodeString ms_sRS200; + UnicodeString ms_sRS201; + UnicodeString ms_sRS202; + UnicodeString ms_sRS203; + UnicodeString ms_sRS204; + UnicodeString ms_sRS205; + UnicodeString ms_sRS206; + UnicodeString ms_sRS207; + UnicodeString ms_sRS208; + UnicodeString ms_sRS209; + UnicodeString ms_sRS210; + UnicodeString ms_sRS300; + UnicodeString ms_sRS301; + UnicodeString ms_sRS302; + UnicodeString ms_sRS303; + UnicodeString ms_sRS304; + UnicodeString ms_sRS305; + UnicodeString ms_sRS306; + UnicodeString ms_sRS307; + UnicodeString ms_sRS308; + UnicodeString ms_sRS309; + UnicodeString ms_sRS310; + UnicodeString ms_sRS311; + UnicodeString ms_sRS312; + UnicodeString ms_sRS400; + UnicodeString ms_sRS500; + UnicodeString ms_sRS501; + UnicodeString ms_sRS502; + UnicodeString ms_sRS503; + UnicodeString ms_sMissingUIDGenerateDefault; + UnicodeString ms_sMissingStartingTimeGenerateDefault; + UnicodeString ms_sMissingEndingTimeGenerateDefault; + UnicodeString ms_sNegativeSequenceNumberGenerateDefault; + UnicodeString ms_sDefaultTBEDescription; + UnicodeString ms_sDefaultTBEClass; + UnicodeString ms_sDefaultTBEStatus; + UnicodeString ms_sDefaultTBETransp; + UnicodeString ms_sDefaultTBERequestStatus; + UnicodeString ms_sDefaultTBESummary; + UnicodeString ms_sDefaultRecIDRange; + UnicodeString ms_sDefaultAttendeeRole; + UnicodeString ms_sDefaultAttendeeType; + UnicodeString ms_sDefaultAttendeeExpect; + UnicodeString ms_sDefaultAttendeeStatus; + UnicodeString ms_sDefaultAttendeeRSVP; + UnicodeString ms_sDefaultAlarmRepeat; + UnicodeString ms_sDefaultAlarmDuration; + UnicodeString ms_sDefaultAlarmCategories; + UnicodeString ms_sDefaultFreebusyStatus; + UnicodeString ms_sDefaultFreebusyType; + UnicodeString ms_sDefaultDuration; + UnicodeString ms_sDefaultAlarmDescriptionString; + UnicodeString ms_sDefaultAlarmSummaryString; + UnicodeString ms_sXTokenParamIgnored; + UnicodeString ms_sXTokenComponentIgnored; +#endif + UnicodeString ms_sDefaultAlarmDescriptionString; + UnicodeString ms_sDefaultAlarmSummaryString; + UnicodeString ms_sRS202; + + static t_int32 ms_iStaticErrorNumber; + + t_int32 ms_iDTEndBeforeDTStart; + t_int32 ms_iExportError; + t_int32 ms_iNTimeParamError; + t_int32 ms_iInvalidPromptValue; + t_int32 ms_iSTimeParamError; + t_int32 ms_iISO8601ParamError; + t_int32 ms_iInvalidTimeStringError; + t_int32 ms_iTimeZoneParamError; + t_int32 ms_iLocaleParamError; + t_int32 ms_iLocaleNotFoundError; + t_int32 ms_iPatternParamError; + t_int32 ms_iInvalidPatternError; + t_int32 ms_iRRuleParamError; + t_int32 ms_iERuleParamError; + t_int32 ms_iBoundParamError; + t_int32 ms_iInvalidRecurrenceError; + t_int32 ms_iUnzipNullError; + t_int32 ms_iCommandNotFoundError; + t_int32 ms_iInvalidTimeZoneError; + t_int32 ms_iFileNotFound; + t_int32 ms_iInvalidPropertyName; + t_int32 ms_iInvalidPropertyValue; + t_int32 ms_iInvalidParameterName; + t_int32 ms_iInvalidParameterValue; + t_int32 ms_iMissingStartingTime; + t_int32 ms_iMissingEndingTime; + t_int32 ms_iEndBeforeStartTime; + t_int32 ms_iMissingSeqNo; + t_int32 ms_iMissingReplySeq; + t_int32 ms_iMissingURL; + t_int32 ms_iMissingDTStamp; + t_int32 ms_iMissingUID; + t_int32 ms_iMissingDescription; + t_int32 ms_iMissingMethodProvided; + t_int32 ms_iMissingOrganizer; + t_int32 ms_iMissingSummary; + t_int32 ms_iMissingAttendees; + t_int32 ms_iInvalidVersionNumber; + t_int32 ms_iUnknownUID; + t_int32 ms_iMissingUIDInReply; + t_int32 ms_iMissingValidDTStamp; + t_int32 ms_iDeclineCounterCalledByAttendee; + t_int32 ms_iPublishCalledByAttendee; + t_int32 ms_iRequestCalledByAttendee; + t_int32 ms_iCancelCalledByAttendee; + t_int32 ms_iCounterCalledByOrganizer; + t_int32 ms_iRefreshCalledByOrganizer; + t_int32 ms_iReplyCalledByOrganizer; + t_int32 ms_iAddReplySequenceOutOfRange; + t_int32 ms_iDuplicatedProperty; + t_int32 ms_iDuplicatedParameter; + t_int32 ms_iConflictMethodAndStatus; + t_int32 ms_iConflictCancelAndConfirmedTentative; + t_int32 ms_iMissingUIDToMatchEvent; + t_int32 ms_iInvalidNumberFormat; + t_int32 ms_iDelegateRequestError; + t_int32 ms_iInvalidRecurrenceIDRange; + t_int32 ms_iUnknownRecurrenceID; + t_int32 ms_iPropertyValueTypeMismatch; + t_int32 ms_iInvalidRRule; + t_int32 ms_iInvalidExRule; + t_int32 ms_iInvalidRDate; + t_int32 ms_iInvalidExDate; + t_int32 ms_iInvalidEvent; + t_int32 ms_iInvalidComponent; + t_int32 ms_iInvalidAlarm; + t_int32 ms_iInvalidTZPart; + t_int32 ms_iInvalidAlarmCategory; + t_int32 ms_iInvalidAttendee; + t_int32 ms_iInvalidFreebusy; + t_int32 ms_iDurationAssertionFailed; + t_int32 ms_iDurationParseFailed; + t_int32 ms_iPeriodParseFailed; + t_int32 ms_iPeriodStartInvalid; + t_int32 ms_iPeriodEndInvalid; + t_int32 ms_iPeriodEndBeforeStart; + t_int32 ms_iPeriodDurationZero; + t_int32 ms_iFreebusyPeriodInvalid; + t_int32 ms_iOptParamInvalidPropertyValue; + t_int32 ms_iOptParamInvalidPropertyName; + t_int32 ms_iInvalidOptionalParam; + t_int32 ms_iAbruptEndOfParsing; + t_int32 ms_iLastModifiedBeforeCreated; + t_int32 ms_iMultipleOwners; + t_int32 ms_iMultipleOrganizers; + t_int32 ms_iMissingOwner; + t_int32 ms_iMissingDueTime; + t_int32 ms_iCompletedPercentMismatch; + t_int32 ms_iMissingFreqTagRecurrence; + t_int32 ms_iFreqIntervalMismatchRecurrence; + t_int32 ms_iInvalidPercentCompleteValue; + t_int32 ms_iInvalidPriorityValue; + t_int32 ms_iInvalidByHourValue; + t_int32 ms_iInvalidByMinuteValue; + t_int32 ms_iByDayFreqIntervalMismatch; + t_int32 ms_iInvalidByMonthDayValue; + t_int32 ms_iInvalidByYearDayValue; + t_int32 ms_iInvalidBySetPosValue; + t_int32 ms_iInvalidByWeekNoValue; + t_int32 ms_iInvalidWeekStartValue; + t_int32 ms_iInvalidByMonthValue; + t_int32 ms_iInvalidByDayValue; + t_int32 ms_iInvalidFrequency; + t_int32 ms_iInvalidDayArg; + t_int32 ms_iVerifyZeroError; + t_int32 ms_iRoundedPercentCompleteTo100; + t_int32 ms_iRS200; + t_int32 ms_iRS201; + t_int32 ms_iRS202; + t_int32 ms_iRS203; + t_int32 ms_iRS204; + t_int32 ms_iRS205; + t_int32 ms_iRS206; + t_int32 ms_iRS207; + t_int32 ms_iRS208; + t_int32 ms_iRS209; + t_int32 ms_iRS210; + t_int32 ms_iRS300; + t_int32 ms_iRS301; + t_int32 ms_iRS302; + t_int32 ms_iRS303; + t_int32 ms_iRS304; + t_int32 ms_iRS305; + t_int32 ms_iRS306; + t_int32 ms_iRS307; + t_int32 ms_iRS308; + t_int32 ms_iRS309; + t_int32 ms_iRS310; + t_int32 ms_iRS311; + t_int32 ms_iRS312; + t_int32 ms_iRS400; + t_int32 ms_iRS500; + t_int32 ms_iRS501; + t_int32 ms_iRS502; + t_int32 ms_iRS503; + t_int32 ms_iMissingUIDGenerateDefault; + t_int32 ms_iMissingStartingTimeGenerateDefault; + t_int32 ms_iMissingEndingTimeGenerateDefault; + t_int32 ms_iNegativeSequenceNumberGenerateDefault; + t_int32 ms_iDefaultTBEDescription; + t_int32 ms_iDefaultTBEClass; + t_int32 ms_iDefaultTBEStatus; + t_int32 ms_iDefaultTBETransp; + t_int32 ms_iDefaultTBERequestStatus; + t_int32 ms_iDefaultTBESummary; + t_int32 ms_iDefaultRecIDRange; + t_int32 ms_iDefaultAttendeeRole; + t_int32 ms_iDefaultAttendeeType; + t_int32 ms_iDefaultAttendeeExpect; + t_int32 ms_iDefaultAttendeeStatus; + t_int32 ms_iDefaultAttendeeRSVP; + t_int32 ms_iDefaultAlarmRepeat; + t_int32 ms_iDefaultAlarmDuration; + t_int32 ms_iDefaultAlarmCategories; + t_int32 ms_iDefaultFreebusyStatus; + t_int32 ms_iDefaultFreebusyType; + t_int32 ms_iDefaultDuration; + t_int32 ms_iDefaultAlarmDescriptionString; + t_int32 ms_iDefaultAlarmSummaryString; + t_int32 ms_iXTokenParamIgnored; + t_int32 ms_iXTokenComponentIgnored; +}; + +/*---------------------------------------------------------------------*/ + +/** + * Singleton class that contains all formatting strings used + * to print iCalendar object to output. + */ +class NS_CAL_UTIL JulianFormatString +{ + +private: + static JulianFormatString * m_Instance; + JulianFormatString(); + +public: + + static JulianFormatString * Instance(); + ~JulianFormatString(); + + /* DateTime string*/ + UnicodeString ms_asDateTimePatterns[16]; + UnicodeString ms_sDateTimeISO8601Pattern; + UnicodeString ms_sDateTimeISO8601LocalPattern; + UnicodeString ms_sDateTimeISO8601TimeOnlyPattern; + UnicodeString ms_sDateTimeISO8601DateOnlyPattern; + UnicodeString ms_sDateTimeDefaultPattern; + + /* Attendee strings*/ + UnicodeString ms_sAttendeeAllMessage; + UnicodeString ms_sAttendeeDoneActionMessage; + UnicodeString ms_sAttendeeDoneDelegateToOnly; + UnicodeString ms_sAttendeeDoneDelegateFromOnly; + UnicodeString ms_sAttendeeNeedsActionMessage; + UnicodeString ms_sAttendeeNeedsActionDelegateToOnly; + UnicodeString ms_sAttendeeNeedsActionDelegateFromOnly; + + UnicodeString ms_AttendeeStrDefaultFmt; + + /* Organizer strings */ + UnicodeString ms_OrganizerStrDefaultFmt; + + /* Freebusy strings */ + UnicodeString ms_FreebusyStrDefaultFmt; + + /* TZPart strings */ + UnicodeString ms_TZPartStrDefaultFmt; + UnicodeString ms_sTZPartAllMessage; + + /* VAlarm strings */ + UnicodeString ms_VAlarmStrDefaultFmt; + UnicodeString ms_sVAlarmAllMessage; + + /* VEvent strings */ + UnicodeString ms_VEventStrDefaultFmt; + UnicodeString ms_sVEventAllPropertiesMessage; + UnicodeString ms_sVEventCancelMessage; + UnicodeString ms_sVEventRequestMessage; + UnicodeString ms_sVEventRecurRequestMessage; + UnicodeString ms_sVEventCounterMessage; + UnicodeString ms_sVEventDeclineCounterMessage; + UnicodeString ms_sVEventAddMessage; + UnicodeString ms_sVEventRefreshMessage; + UnicodeString ms_sVEventReplyMessage; + UnicodeString ms_sVEventPublishMessage; + UnicodeString ms_sVEventRecurPublishMessage; + UnicodeString ms_sVEventDelegateRequestMessage; + UnicodeString ms_sVEventRecurDelegateRequestMessage; + + /* VFreebusy strings */ + UnicodeString ms_sVFreebusyReplyMessage; + UnicodeString ms_sVFreebusyPublishMessage; + UnicodeString ms_sVFreebusyRequestMessage; + UnicodeString ms_sVFreebusyAllMessage; + UnicodeString ms_VFreebusyStrDefaultFmt; + + /* VJournal strings */ + UnicodeString ms_sVJournalAllPropertiesMessage; + UnicodeString ms_sVJournalCancelMessage; + UnicodeString ms_sVJournalRequestMessage; + UnicodeString ms_sVJournalRecurRequestMessage; + UnicodeString ms_sVJournalCounterMessage; + UnicodeString ms_sVJournalDeclineCounterMessage; + UnicodeString ms_sVJournalAddMessage; + UnicodeString ms_sVJournalRefreshMessage; + UnicodeString ms_sVJournalReplyMessage; + UnicodeString ms_sVJournalPublishMessage; + UnicodeString ms_sVJournalRecurPublishMessage; + UnicodeString ms_VJournalStrDefaultFmt; + + /* VTodo strings */ + UnicodeString ms_sVTodoAllPropertiesMessage; + UnicodeString ms_sVTodoCancelMessage; + UnicodeString ms_sVTodoRequestMessage; + UnicodeString ms_sVTodoRecurRequestMessage; + UnicodeString ms_sVTodoCounterMessage; + UnicodeString ms_sVTodoDeclineCounterMessage; + UnicodeString ms_sVTodoAddMessage; + UnicodeString ms_sVTodoRefreshMessage; + UnicodeString ms_sVTodoReplyMessage; + UnicodeString ms_sVTodoPublishMessage; + UnicodeString ms_sVTodoRecurPublishMessage; + UnicodeString ms_VTodoStrDefaultFmt; + + /* VTimeZone strings */ + UnicodeString ms_VTimeZoneStrDefaultFmt; + UnicodeString ms_sVTimeZoneAllMessage; +}; + + +/*---------------------------------------------------------- +** Key letters used for formatting strings +**----------------------------------------------------------*/ +const t_int32 ms_cAction = 'l'; +const t_int32 ms_cAlarms = 'w'; +const t_int32 ms_cAttach = 'a'; +const t_int32 ms_cAttendees = 'v'; +const t_int32 ms_cCategories = 'k'; +const t_int32 ms_cClass = 'c'; +const t_int32 ms_cComment = 'K'; +const t_int32 ms_cCompleted = 'G'; +const t_int32 ms_cContact = 'H'; +const t_int32 ms_cCreated = 't'; +const t_int32 ms_cDescription = 'i'; +const t_int32 ms_cDuration = 'D'; +const t_int32 ms_cDTEnd = 'e'; +const t_int32 ms_cDTStart = 'B'; +const t_int32 ms_cDTStamp = 'C'; +const t_int32 ms_cDue = 'F'; +const t_int32 ms_cExDate = 'X'; +const t_int32 ms_cExRule = 'E'; +const t_int32 ms_cGEO = 'O'; +const t_int32 ms_cLastModified = 'M'; +const t_int32 ms_cLocation = 'L'; +const t_int32 ms_cOrganizer = 'J'; +const t_int32 ms_cPercentComplete = 'P'; +const t_int32 ms_cPriority = 'p'; +const t_int32 ms_cRDate = 'x'; +const t_int32 ms_cRRule = 'y'; +const t_int32 ms_cRecurrenceID = 'R'; +const t_int32 ms_cRelatedTo = 'o'; +const t_int32 ms_cRepeat = 'A'; +const t_int32 ms_cRequestStatus = 'T'; +const t_int32 ms_cResources = 'r'; +/*const t_int32 ms_cResponseSequence = 'q';*/ +const t_int32 ms_cSequence = 's'; +const t_int32 ms_cStatus = 'g'; +const t_int32 ms_cSummary = 'S'; +const t_int32 ms_cTransp = 'h'; +const t_int32 ms_cTrigger = 'z'; +const t_int32 ms_cUID = 'U'; +const t_int32 ms_cURL = 'u'; +const t_int32 ms_cXTokens = 'Z'; + +const t_int32 ms_cTZOffsetTo = 'd'; +const t_int32 ms_cTZOffsetFrom = 'f'; +const t_int32 ms_cTZName = 'n'; +const t_int32 ms_cTZURL = 'Q'; +const t_int32 ms_cTZID = 'I'; +const t_int32 ms_cTZParts = 'V'; +/*const t_int32 ms_cDAYLIGHT = 'd';*/ + + +const t_int32 ms_cFreebusy = 'Y'; + +/* ATTENDEE ONLY (see attendee.h) */ +/* +const t_int32 ms_cAttendeeName = 'N'; +const t_int32 ms_cAttendeeRole = 'R'; +const t_int32 ms_cAttendeeStatus = 'S'; repeat +const t_int32 ms_cAttendeeRSVP = 'V'; +const t_int32 ms_cAttendeeType = 'T'; +const t_int32 ms_cAttendeeExpect = 'E'; +const t_int32 ms_cAttendeeDelegatedTo = 'D'; +const t_int32 ms_cAttendeeDelegatedFrom = 'd'; +const t_int32 ms_cAttendeeMember = 'M'; +const t_int32 ms_cAttendeeDir = 'l'; 'el' +const t_int32 ms_cAttendeeSentBy = 's'; +const t_int32 ms_cAttendeeCN = 'C'; +const t_int32 ms_cAttendeeDisplayName = 'z'; +*/ + +/* FREEBUSY ONLY (see freebusy.h) */ +/* +const t_int32 ms_cFreebusyType = 'T'; +const t_int32 ms_cFreebusyStatus = 'S'; +const t_int32 ms_cFreebusyPeriod = 'P'; +*/ + +const t_int32 ms_iMAX_LINE_LENGTH = 76; + + +#endif /* __KEYWORD_H_ */ + + + diff --git a/calendar/modules/util/inc/manifest.mn b/calendar/modules/util/inc/manifest.mn index 69956f62ca9..e69de29bb2d 100644 --- a/calendar/modules/util/inc/manifest.mn +++ b/calendar/modules/util/inc/manifest.mn @@ -1,27 +0,0 @@ -# -# CONFIDENTIAL AND PROPRIETARY SOURCE CODE OF -# NETSCAPE COMMUNICATIONS CORPORATION -# Copyright (C) 1996 Netscape Communications Corporation. All Rights -# Reserved. Use of this Source Code is subject to the terms of the -# applicable license agreement from Netscape Communications Corporation. -# The copyright notice(s) in this Source Code does not indicate actual or -# intended publication of this Source Code. -# -GDEPTH = ../../../.. - -EXPORTS = \ - $(NULL) - -PRIVATE_EXPORTS = \ - nsX400Parser.h \ - nsCurlParser.h \ - nsDateTime.h \ - nsDuration.h \ - nsCalUtilCIID.h \ - nscalexport.h \ - nsX400Parser.h \ - $(NULL) - -MODULE = trex - -REQUIRES = raptor diff --git a/calendar/modules/util/inc/nsCurlParser.h b/calendar/modules/util/inc/nsCurlParser.h index 2238a0ca5bf..8077b82dcd9 100644 --- a/calendar/modules/util/inc/nsCurlParser.h +++ b/calendar/modules/util/inc/nsCurlParser.h @@ -56,9 +56,9 @@ #ifndef _NS_CURL_PARSER_H #define _NS_CURL_PARSER_H -#include "nscalexport.h" +#include "nscalutilexp.h" -class NS_CALENDAR nsCurlParser +class NS_CAL_UTIL nsCurlParser { public: enum ePROTOCOL {eUNKNOWN, eCAPI, eIMIP, eIRIP, eFILE, eRESOURCE, diff --git a/calendar/modules/util/inc/nsX400Parser.h b/calendar/modules/util/inc/nsX400Parser.h index 4b8896300c6..20af82453e3 100644 --- a/calendar/modules/util/inc/nsX400Parser.h +++ b/calendar/modules/util/inc/nsX400Parser.h @@ -37,9 +37,9 @@ #ifndef _NS_X400_PARSER_H #define _NS_X400_PARSER_H -#include "nscalexport.h" +#include "nscalutilexp.h" -class NS_CALENDAR nsX400Parser +class NS_CAL_UTIL nsX400Parser { private: JulianString** mppKeys; /* keys are kept here */ diff --git a/calendar/modules/util/inc/ptrarray.h b/calendar/modules/util/inc/ptrarray.h new file mode 100644 index 00000000000..a1d000322e1 --- /dev/null +++ b/calendar/modules/util/inc/ptrarray.h @@ -0,0 +1,100 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +/* Insert copyright and license here 1996 */ +// ptrarray.h +#ifndef JULIAN_PTR_ARRAY_H_ +#define JULIAN_PTR_ARRAY_H_ + +#ifdef XP_UNIX +#define __cdecl +#endif + +/* + * Need to fix this... + */ +#if defined(WIN32) +#define XP_Bool int +#define int32 int +#elif defined(unix) +#define XP_Bool int +#define int32 int +#endif + +typedef int XPCompareFunc(const void *, const void * ); + +#include "nscalutilexp.h" + +class NS_CAL_UTIL JulianPtrArray +{ + +public: + +// Construction + JulianPtrArray(); + +// Attributes + int GetSize() const; + int GetUpperBound() const; + XP_Bool SetSize(int nNewSize, int nGrowBy = -1); + XP_Bool IsValidIndex(int32 nIndex); +// Operations + // Clean up + void FreeExtra(); + void RemoveAll(); + + // Accessing elements + void* GetAt(int nIndex) const; + void SetAt(int nIndex, void* newElement); + void*& ElementAt(int nIndex); + virtual int FindIndex (int nStartIndex, void *pToFind) const; + + // Potentially growing the array + void SetAtGrow(int nIndex, void* newElement); + virtual int Add(void* newElement); + + // overloaded operator helpers + void* operator[](int nIndex) const; + void*& operator[](int nIndex); + + // Operations that move elements around + void InsertAt(int nIndex, void* newElement, int nCount = 1); + void RemoveAt(int nIndex, int nCount = 1); + void InsertAt(int nStartIndex, const JulianPtrArray* pNewArray); + void RemoveAt(int nStartIndex, const JulianPtrArray* pNewArray); + XP_Bool Remove(void *pToRemove); + void QuickSort(XPCompareFunc *compare); + int InsertBinary(void* newElement, XPCompareFunc *compare); + +// Implementation +protected: + void** m_pData; // the actual array of data + int m_nSize; // # of elements (upperBound - 1) + int m_nMaxSize; // max allocated + int m_nGrowBy; // grow amount + +public: + virtual ~JulianPtrArray(); +#ifdef _DEBUG + void AssertValid() const; +#endif + +}; + + +#endif /* JULIAN_PTR_ARRAY_H_ */ diff --git a/calendar/modules/util/inc/stdafx.h b/calendar/modules/util/inc/stdafx.h new file mode 100644 index 00000000000..e69de29bb2d diff --git a/calendar/modules/util/inc/uidrgntr.h b/calendar/modules/util/inc/uidrgntr.h new file mode 100644 index 00000000000..89bd14396ae --- /dev/null +++ b/calendar/modules/util/inc/uidrgntr.h @@ -0,0 +1,67 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +/* + * uidrgntr.h + * John Sun + * 3/19/98 5:35:59 PM + */ + +#ifndef __JULIANUIDRANDOMGENERATOR_H_ +#define __JULIANUIDRANDOMGENERATOR_H_ + +#include +#include "nscalutilexp.h" + +/** + * Class that contains method to generate random UID strings. + */ +class NS_CAL_UTIL JulianUIDRandomGenerator +{ +public: + /** default constructor. It's of no use */ + JulianUIDRandomGenerator(); + + /** destructor. It's of no use */ + ~JulianUIDRandomGenerator(); + + /** + * generates random UID strings by appending + * current date time value is UTC ISO8601 format with + * a random hexadecimal number. + * + * @return new random UID string + */ + static UnicodeString generate(); + + /** + * generates random UID strings by appending + * current date time value is UTC ISO8601 format with + * a random hexadecimal number and input string. + * Usually this input string would be a user@hostname or + * e-mail address. + * + * @param us string to append to output + * + * @return new random UID string + */ + static UnicodeString generate(UnicodeString us); +}; + +#endif /*__JULIANUIDRANDOMGENERATOR_H_ */ + diff --git a/calendar/modules/util/public/manifest.mn b/calendar/modules/util/public/manifest.mn index 88b247eb67e..e69de29bb2d 100644 --- a/calendar/modules/util/public/manifest.mn +++ b/calendar/modules/util/public/manifest.mn @@ -1,23 +0,0 @@ -# -# CONFIDENTIAL AND PROPRIETARY SOURCE CODE OF -# NETSCAPE COMMUNICATIONS CORPORATION -# Copyright (C) 1996 Netscape Communications Corporation. All Rights -# Reserved. Use of this Source Code is subject to the terms of the -# applicable license agreement from Netscape Communications Corporation. -# The copyright notice(s) in this Source Code does not indicate actual or -# intended publication of this Source Code. -# -GDEPTH = ../../../.. -DEPTH = ../../../.. - -EXPORTS = \ - nsIDateTime.h \ - nsIDuration.h \ - $(NULL) - -PRIVATE_EXPORTS = \ - $(NULL) - -MODULE = trex - -REQUIRES = raptor diff --git a/calendar/modules/util/public/nscalutilexp.h b/calendar/modules/util/public/nscalutilexp.h new file mode 100644 index 00000000000..ca27251bdfc --- /dev/null +++ b/calendar/modules/util/public/nscalutilexp.h @@ -0,0 +1,30 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +#ifndef nscalutilexp_h__ +#define nscalutilexp_h__ + +#include "nscore.h" + +#ifdef _IMPL_NS_CAL_UTIL +#define NS_CAL_UTIL NS_EXPORT +#else +#define NS_CAL_UTIL NS_IMPORT +#endif + +#endif /* nscalutilexp_h__ */ diff --git a/calendar/modules/util/src/config.mk b/calendar/modules/util/src/config.mk index 247db923648..e69de29bb2d 100644 --- a/calendar/modules/util/src/config.mk +++ b/calendar/modules/util/src/config.mk @@ -1,29 +0,0 @@ -# -# CONFIDENTIAL AND PROPRIETARY SOURCE CODE OF -# NETSCAPE COMMUNICATIONS CORPORATION -# Copyright © 1996, 1997 Netscape Communications Corporation. All Rights -# Reserved. Use of this Source Code is subject to the terms of the -# applicable license agreement from Netscape Communications Corporation. -# The copyright notice(s) in this Source Code does not indicate actual or -# intended publication of this Source Code. -# - -# -# Override TARGETS variable so that only static libraries -# are specifed as dependencies within rules.mk. -# - -CFLAGS +=-D_IMPL_NS_CALENDAR -DNSPR20 -INCLUDES +=-I../inc -I$(GDEPTH)/include - -LIBRARY_NAME = util -LIBRARY_VERSION = 10 - -LD_LIBS += \ - $(NATIVE_JULIAN_DLL) \ - $(NATIVE_LIBNLS_LIBS) \ - raptorbase \ - xpcom$(MOZ_BITS) \ - $(XP_REG_LIB) - -EXTRA_LIBS += $(NSPR_LIBS) diff --git a/calendar/modules/util/src/datetime.cpp b/calendar/modules/util/src/datetime.cpp new file mode 100644 index 00000000000..5836ee3676c --- /dev/null +++ b/calendar/modules/util/src/datetime.cpp @@ -0,0 +1,1559 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +// datetime.cpp +// John Sun +// 2:39 PM Janaury 21 1997 + +#include "stdafx.h" +#include "jdefines.h" + +#include +#include +#include +#include +#include +#include +#include "datetime.h" +#include "jutility.h" +#include "duration.h" +#include "keyword.h" +//--------------------------------------------------------------------- +//--------------------------- +// STATIC INITIALIZATION +//---------------------------- +//--------------------------------------------------------------------- + +/* + * This is a hack so I could get it compiled on unix. We need + * to remove Windows specific code from this file. + * -sman + */ +//#define TRACE printf + +t_bool DateTime::m_Init = TRUE; + +// static data used for getMonthLength method. +static t_int32 s_shMonthLength[] = +{31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; +static t_int32 s_shMonthLengthLeapYear[] = +{31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30 , 31}; + +/* +UnicodeString DateTime::ms_asPatterns[] = +{ + UnicodeString("yyyy MM dd HH m s z"), + UnicodeString("yyyy MM dd HH m s"), + UnicodeString("EEE MMM dd hh:mm:ss z yyyy"), + UnicodeString("MMM dd, yyyy h:m a"), + UnicodeString("MMM dd, yyyy h:m z"), + UnicodeString("MMM dd, yyyy h:m:s a"), + UnicodeString("MMM dd, yyyy h:m:s z"), + UnicodeString("MMMM dd, yyyy h:m a"), + UnicodeString("MMMM dd, yyyy h:m:s a"), + UnicodeString("dd MMM yyyy h:m:s z"), + UnicodeString("dd MMM yyyy h:m:s z"), + UnicodeString("MM/dd/yy hh:mm:s a"), + UnicodeString("MM/dd/yy hh:mm:s z"), + UnicodeString("MM/dd/yy hh:mm z"), + UnicodeString("MM/dd/yy hh:mm"), + UnicodeString("hh:mm MM/d/y z") +}; +*/ +const t_int32 kPATTERNSIZE = 16; +/* +UnicodeString DateTime::ms_sISO8601Pattern("yyyyMMdd'T'HHmmss'Z'"); +UnicodeString DateTime::ms_sISO8601LocalPattern("yyyyMMdd'T'HHmmss"); +UnicodeString DateTime::ms_sISO8601TimeOnlyPattern("HHmmss"); +UnicodeString DateTime::ms_sISO8601DateOnlyPattern("yyyyMMdd"); +UnicodeString DateTime::ms_sDefaultPattern("MMM dd, yyyy h:mm a z"); +*/ + +ErrorCode DateTime::staticStatus = ZERO_ERROR; +ErrorCode DateTime::staticStatus2= ZERO_ERROR; + +#if 0 + /* Not doing this now: Cache simpledateformats of certain locales */ +Hashtable DateTime::sdfHashtable; + +SimpleDateFormat DateTime::kDateFormats[] = +{ + SimpleDateFormat(DateTime::ms_sDefaultPattern, Locale::US, + DateTime::staticStatus), + SimpleDateFormat(DateTime::ms_sDefaultPattern, Locale::UK, + DateTime::staticStatus), + SimpleDateFormat(DateTime::ms_sDefaultPattern, Locale::FRANCE, + DateTime::staticStatus), + SimpleDateFormat(DateTime::ms_sDefaultPattern, Locale::GERMANY, + DateTime::staticStatus), + SimpleDateFormat(DateTime::ms_sDefaultPattern, Locale::ITALY, + DateTime::staticStatus), + SimpleDateFormat(DateTime::ms_sDefaultPattern, Locale::JAPAN, + DateTime::staticStatus), + SimpleDateFormat(DateTime::ms_sDefaultPattern, Locale::KOREA, + DateTime::staticStatus), + SimpleDateFormat(DateTime::ms_sDefaultPattern, Locale::CHINA, + DateTime::staticStatus), + SimpleDateFormat(DateTime::ms_sDefaultPattern, Locale::TAIWAN, + DateTime::staticStatus), + SimpleDateFormat(DateTime::ms_sDefaultPattern, Locale::CANADA, + DateTime::staticStatus), + SimpleDateFormat(DateTime::ms_sDefaultPattern, Locale::CANADA_FRENCH, + DateTime::staticStatus) +}; +char* DateTime::kDateFormatIDs[] = +{ + "en_US", "en_GB", "fr_FR", "de_DE", "it_IT", "ja_JP", "ko_KR", + "zh_CN", "zh_TW", "en_CA", "fr_CA" +}; + +const t_int32 DateTime::kNumDateFormats = + sizeof(kDateFormats) / sizeof(kDateFormats[0]); + +void DateTime::initHashtable() +{ + UnicodeString temp; + SimpleDateFormat * previous = NULL; + t_int32 i; + + for (i = 0; i < kNumDateFormats; i++) + { + previous = (SimpleDateFormat *) sdfHashtable.put( + new UnicodeStringKey(kDateFormatIDs[i]), &kDateFormats[i]); + // XXX: new UnicodeStringKey(...) would cause memory leaks her + if (previous != 0) delete previous; + } +} +#endif + +//const TimeZone * DateTime::m_kGMTTimeZone = TimeZone::createTimeZone("GMT"); +TimeZone * DateTime::m_kGMTTimeZone = 0; +//const TimeZone * DateTime::m_kDefaultTimeZone = TimeZone::createDefault(); +TimeZone * DateTime::m_kDefaultTimeZone = 0; + +// when timezone was static +TimeZone * DateTime::ms_TimeZone = 0; +//TimeZone * DateTime::ms_TimeZone = TimeZone::createDefault(); +//Locale DateTime::ms_Locale = Locale::getDefault(); +//Locale DateTime::ms_Locale = 0; + +//GregorianCalendar DateTime::ms_Calendar((TimeZone *) m_kDefaultTimeZone, +// ms_Locale, staticStatus); +GregorianCalendar * DateTime::ms_Calendar = 0; + +//SimpleDateFormat DateTime::ms_DateFormat(staticStatus2); + +//SimpleDateFormat * DateTime::ms_DateFormat = +// new SimpleDateFormat(staticStatus2); +//SimpleDateFormat DateTime::ms_DateFormat(staticStatus2); +SimpleDateFormat * DateTime::ms_DateFormat = 0; + +//SimpleDateFormat DateTime::ms_GMTISO8601DateFormat(ms_sISO8601Pattern, +// staticStatus2); + +//--------------------------------------------------------------------- + +/** + * A comparison procedure callable from C + * @param v1 pointer to a pointer to the first date + * @param v2 pointer to a pointer to the second date + * @return -1 if D1 < D2, 0 if D1 == D2, 1 if D1 > D2 + */ +int DateTime_SortAscending( const void* v1, const void* v2 ) +{ + DateTime *pD1 = *(DateTime**)v1; + DateTime *pD2 = *(DateTime**)v2; + + if (*pD1 == *pD2) + return 0; + else if (*pD1 > *pD2) + return 1; + else + return -1; +} + +/** + * A comparison procedure callable from C + * @param v1 pointer to a pointer to the first date + * @param v2 pointer to a pointer to the second date + * @return -1 if D1 > D2, 0 if D1 == D2, 1 if D1 < D2 + */ +int DateTime_SortDescending( const void* v1, const void* v2 ) +{ + DateTime *pD1 = *(DateTime**)v1; + DateTime *pD2 = *(DateTime**)v2; + if (*pD1 == *pD2) + return 0; + else if (*pD1 < *pD2) + return 1; + else + return -1; +} +//---------------------------- +// PRIVATE METHODS +//---------------------------- +//--------------------------------------------------------------------- + +t_int8 DateTime::compare(Date d) +{ + if (m_Date < d) + return -1; + else if (m_Date > d) + return 1; + else return 0; +} + +//--------------------------------------------------------------------- +// initializes core data members + +void DateTime::CtorCore() +{ + //m_kGMTTimeZone = TimeZone::createTimeZone("GMT"); + m_kDefaultTimeZone = TimeZone::createDefault(); + ms_TimeZone = TimeZone::createDefault(); + //ms_Locale = &(Locale::getDefault()); + ms_Calendar = new GregorianCalendar(m_kDefaultTimeZone, Locale::getDefault(), staticStatus); + ms_DateFormat = new SimpleDateFormat(staticStatus2); + + m_kGMTTimeZone = new SimpleTimeZone((t_int32) 0, "Z-time"); + if (m_kGMTTimeZone == 0) + m_kGMTTimeZone = TimeZone::createTimeZone("Africa/Casablanca"); + + if (ms_Calendar == 0 || ms_DateFormat == 0 || + FAILURE(staticStatus) || FAILURE(staticStatus2)) + { + + // FAILED to create GregorianCalendar successfully + //if (FALSE) TRACE("FAILURE in DateTime::CtorCore %d, %d\r\n", + //staticStatus, staticStatus2); + CalendarSetTimeHelper(Calendar::getNow()); + } + m_Init = FALSE; + //m_TimeZone = TimeZone::createDefault(); + //PR_ASSERT(m_TimeZone == 0); + //m_TimeZone = initTimeZone; + //PR_ASSERT(m_TimeZone != 0); + //setTimeZone(m_TimeZone); +} + +//--------------------------------------------------------------------- + +t_int32 DateTime::CalendarGetFieldHelper(Calendar::EDateFields aField, + TimeZone * timezone) +{ + ErrorCode status = ZERO_ERROR; + t_int32 retVal; + + ms_Calendar->setTimeZone(*timezone); + retVal = ms_Calendar->get(aField, status); + ms_Calendar->setTimeZone(*ms_TimeZone); + + //retVal = ms_Calendar->get(aField); + //PR_ASSERT(!FAILURE(status)); + if (FAILURE(status)) + { + //if (FALSE) TRACE("FAILURE in DateTime::CalendarGetFieldHelper %d\r\n", status); + } + return retVal; +} + +//--------------------------------------------------------------------- + +Date DateTime::CalendarGetTimeHelper() +{ + ErrorCode status = ZERO_ERROR; + Date retVal; + + retVal = ms_Calendar->getTime(status); + //PR_ASSERT(!FAILURE(status)); + if (FAILURE(status)) + { + //TRACE("FAILURE in DateTime::CalendarGetTimeHelper %d\r\n", status); + } + return retVal; + +} + +//--------------------------------------------------------------------- + +void DateTime::CalendarSetTimeHelper(Date d) +{ + ErrorCode status = ZERO_ERROR; + + ms_Calendar->setTime(d, status); + if (FAILURE(status)) + { + //if (FALSE) TRACE("FAILURE in DateTime::CalendarSetTimeHelper %d\r\n", status); + } + //ms_Calendar->setTime(d); + //PR_ASSERT(!FAILURE(status)); +} + +//--------------------------------------------------------------------- +#if 0 +Date DateTime::parse(UnicodeString & s, Locale & locale) +{ + Date d = -1; + t_int32 i; + if ((d = parseISO8601(s)) < 0) + { + for (i = 0; i < kPATTERNSIZE; i++) + { + if ((d = parseTime(JulianFormatString::Instance()->ms_asDateTimePatterns[i], s, locale)) > 0) + { + break; + } + } + } + return d; +} + +//--------------------------------------------------------------------- + +Date DateTime::parseTime(UnicodeString & pattern, UnicodeString & time, + Locale & locale, TimeZone * timezone) +{ + ErrorCode status = ZERO_ERROR; + Date date = -1; + + ParsePosition pos(0); + SimpleDateFormat dateFormat(pattern, locale, status); + //ms_DateFormat->applyLocalizedPattern(pattern, status); + + if (FAILURE(status)) + return -1; + + dateFormat.setLenient(FALSE); + dateFormat.setTimeZone(*timezone); + date = dateFormat.parse(time, pos); + //ms_DateFormat->setLenient(FALSE); + //date = ((DateFormat *) ms_DateFormat)->parse(time, status); + + if (FAILURE(status)) + return -1; + + if (pos == 0) + return -1; + + return date; +} +#endif +//--------------------------------------------------------------------- + +Date DateTime::parseTime(UnicodeString & pattern, UnicodeString & time, + TimeZone * timezone) +{ + ErrorCode status = ZERO_ERROR; + ParsePosition pos(0); + Date date = -1; + + //ms_DateFormat->applyLocalizedPattern(pattern, status); + + ms_DateFormat->applyLocalizedPattern(pattern, status); + //ms_DateFormat->applyPattern(pattern); + + if (FAILURE(status)) return -1; + + //ms_DateFormat->setLenient(FALSE); + + ms_DateFormat->setLenient(FALSE); + ms_DateFormat->setTimeZone(*timezone); + //date = ((DateFormat *) ms_DateFormat)->parse(time, status); + + //date = ms_DateFormat->parse(time, pos); + date = ms_DateFormat->parse(time, pos); + //ms_DateFormat.setTimeZone(*ms_TimeZone); + if (pos == 0) + return -1; + //if (FAILURE(status)) return -1; + + return date; +} + +//--------------------------------------------------------------------- + +t_int32 DateTime::getMonthLength(t_int32 iMonthNum, t_int32 iYearNum) +{ + // NOTE: iMonthNum assumed to be 1-based. + // Algorithm assumes GregorianCalendar after 1582. + + if ((iYearNum % 4) != 0) + { + return s_shMonthLength[iMonthNum - 1]; // normal years + } + else if (((iYearNum % 4) == 0) && + (((iYearNum % 100) != 0) || ((iYearNum % 400) == 0))) + { + // normal leap years + 1600, 2000, 2400 + return s_shMonthLengthLeapYear[iMonthNum - 1]; + } + else + { + return s_shMonthLength[iMonthNum - 1]; // 1700, 1800, 1900, 2100, 2200, 2300 + } +} + +//--------------------------------------------------------------------- + +Date DateTime::parseISO8601(UnicodeString & us, TimeZone * timezone) +{ + Date t = 0; + + + // Removed redundant code. Instead, all parsing using the IsParseable method. + + t_int32 iYear = 0, iMonth = 0, iDay = 0, iHour = 0, iMin = 0, iSec = 0; + if (!DateTime::IsParseable(us, iYear, iMonth, iDay, iHour, iMin, iSec)) + { + return -1; + } + else + { + char sBuf[32]; + t_bool bUTC = FALSE; + t_int32 strLength = us.size(); + + if (iYear < 1970) + { + // Dates with year value less than 1970 will be set to 1970 + // So 19671225112233 will become 19701225T112233 + iYear = 1970; + } + + // if length is 16 then GMT time + if (strLength == 16) + { + sprintf(sBuf, "%d %d %d %d %d %d GMT", iYear, iMonth, iDay, iHour, iMin, iSec); + bUTC = TRUE; + } + else + sprintf(sBuf, "%d %d %d %d %d %d", iYear, iMonth, iDay, iHour, iMin, iSec); + + UnicodeString temp = sBuf; + + //if (FALSE) TRACE("temp = %s\r\n", temp.toCString("")); + + if (bUTC) + { + + if ((t = parseTime(JulianFormatString::Instance()->ms_asDateTimePatterns[0], temp, (TimeZone *) m_kGMTTimeZone)) < 0) + { + t = parseTime(JulianFormatString::Instance()->ms_asDateTimePatterns[1], temp, (TimeZone *) m_kGMTTimeZone); + } + } + else + { + if ((t = parseTime(JulianFormatString::Instance()->ms_asDateTimePatterns[0], temp, timezone)) < 0) + { + t = parseTime(JulianFormatString::Instance()->ms_asDateTimePatterns[1], temp, timezone); + } + } + + //if (FALSE) TRACE("t = %f\r\n", t); + + return t; + } +} + +//--------------------------------------------------------------------- + +///////////////////////// +// PUBLIC METHODS +///////////////////////// + +//--------------------------------------------------------------------- + +//---------------------------- +// CONSTRUCTORS +//---------------------------- + +//--------------------------------------------------------------------- + +DateTime::DateTime() : m_Date(Calendar::getNow()) +{ + if (m_Init) + CtorCore(); +} + +//--------------------------------------------------------------------- + +DateTime::DateTime(t_int32 year, t_int32 month, t_int32 date) +{ + if (m_Init) + CtorCore(); + + ms_Calendar->set(year, month, date); + this->setTime(CalendarGetTimeHelper()); +} + +//--------------------------------------------------------------------- + +DateTime::DateTime(t_int32 year, t_int32 month, t_int32 date, + t_int32 hrs, t_int32 min) +{ + if (m_Init) + CtorCore(); + + ms_Calendar->set(year, month, date, hrs, min); + this->setTime(CalendarGetTimeHelper()); +} + +//--------------------------------------------------------------------- + +DateTime::DateTime(t_int32 year, t_int32 month, t_int32 date, + t_int32 hrs, t_int32 min, t_int32 sec) +{ + if (m_Init) + CtorCore(); + + ms_Calendar->set(year, month, date, hrs, min, sec); + this->setTime(CalendarGetTimeHelper()); + +} + +//--------------------------------------------------------------------- + +DateTime::DateTime(Date d) +{ + if (m_Init) + CtorCore(); + + //CalendarSetTimeHelper(d); + //this->setTime(CalendarGetTimeHelper()); + if (d < 0) + d = -1; + this->setTime(d); +} + +//--------------------------------------------------------------------- + +DateTime::DateTime(DateTime & aDateTime) +{ + if (m_Init) + CtorCore(); + //m_TimeZone = 0; + //if (m_TimeZone != 0) + // delete m_TimeZone; + //m_TimeZone = aDateTime.m_TimeZone; + + /* + ms_Calendar->set(aDateTime.getYear(), aDateTime.getMonth(), + aDateTime.getDate(), aDateTime.getHour(), aDateTime.getMinute(), + aDateTime.getSecond()); + */ + //this->setTime(CalendarGetTimeHelper()); + this->setTime(aDateTime.m_Date); +} + +//--------------------------------------------------------------------- + +DateTime::DateTime(UnicodeString & us, TimeZone * timezone) +{ + if (m_Init) + { + CtorCore(); + if (timezone == 0) + timezone = ms_TimeZone; + } + // to accept non-ISO8601 strings + ////CalendarSetTimeHelper(DateTime::parse(us, ms_Locale)); + + // only accept ISO8601 + //CalendarSetTimeHelper(DateTime::parseISO8601(us)); + //this->setTime(CalendarGetTimeHelper()); + + this->setTime(DateTime::parseISO8601(us, timezone)); +} +//--------------------------------------------------------------------- + +//---------------------------- +// DESTRUCTORS +//---------------------------- + +//--------------------------------------------------------------------- + +DateTime::~DateTime() +{ + //if (m_TimeZone != 0) + // delete m_TimeZone; m_TimeZone = 0; +} + +//--------------------------------------------------------------------- + +//---------------------------- +// GETTERS and SETTERS and ADDERS +//---------------------------- + +//--------------------------------------------------------------------- + +Date DateTime::getTime() const +{ + return m_Date; +} + +//--------------------------------------------------------------------- + +void DateTime::setTime(Date d) +{ + m_Date = d; +} + +//--------------------------------------------------------------------- + +void DateTime::setTimeString(UnicodeString & us, TimeZone * timezone) +{ + //setTime(parse(us, ms_Locale)); + setTime(parseISO8601(us, timezone)); +} + +//--------------------------------------------------------------------- +/* +void DateTime::setTimeZone(TimeZone * t) +{ + //if (m_TimeZone != 0) + // delete m_TimeZone; + //m_TimeZone = 0; + ms_TimeZone = t; + PR_ASSERT(ms_TimeZone != 0); + //ms_DateFormat->setTimeZone(*ms_TimeZone); + ms_DateFormat.setTimeZone(*ms_TimeZone); + ms_Calendar->setTimeZone(*ms_TimeZone); +} +*/ +//--------------------------------------------------------------------- + +t_int32 DateTime::get(Calendar::EDateFields aField, + TimeZone * timezone) +{ + t_int32 i = -1; + + PR_ASSERT(timezone != 0); + if (timezone != 0) + { + ms_Calendar->setTimeZone(*timezone); + CalendarSetTimeHelper(this->getTime()); + + i = CalendarGetFieldHelper(aField, timezone); + + ms_Calendar->setTimeZone(*ms_TimeZone); + } + return i; +} + +//--------------------------------------------------------------------- + +t_int32 DateTime::getYear(TimeZone * timezone) +{ + return get(Calendar::YEAR, timezone); +} + +//--------------------------------------------------------------------- + +t_int32 DateTime::getMonth(TimeZone * timezone) +{ + return get(Calendar::MONTH, timezone); +} + +//--------------------------------------------------------------------- + +t_int32 DateTime::getDate(TimeZone * timezone) +{ + return get(Calendar::DATE, timezone); +} + +//--------------------------------------------------------------------- + +t_int32 DateTime::getHour(TimeZone * timezone) +{ + return get(Calendar::HOUR_OF_DAY, timezone); +} + +//--------------------------------------------------------------------- + +t_int32 DateTime::getMinute(TimeZone * timezone) +{ + return get(Calendar::MINUTE, timezone); +} + +//--------------------------------------------------------------------- + +t_int32 DateTime::getSecond(TimeZone * timezone) +{ + return get(Calendar::SECOND, timezone); +} + +//--------------------------------------------------------------------- + +t_int32 DateTime::getDayOfWeekInMonth(TimeZone * timezone) +{ + return get(Calendar::DAY_OF_WEEK_IN_MONTH, timezone); +} + +//--------------------------------------------------------------------- + +void DateTime::setDMY(t_int32 iDay, t_int32 iMonth, t_int32 iYear) +{ + + //ErrorCode status = ZERO_ERROR; + + CalendarSetTimeHelper(this->getTime()); + ms_Calendar->set(iYear, iMonth, iDay); + Date d = CalendarGetTimeHelper(); + this->setTime(d); +} + +//--------------------------------------------------------------------- + +void DateTime::setDayOfMonth(t_int32 iDay) +{ + //ErrorCode status = ZERO_ERROR; + + CalendarSetTimeHelper(this->getTime()); + ms_Calendar->set(this->get(Calendar::YEAR), + this->get(Calendar::MONTH), iDay); + Date d = CalendarGetTimeHelper(); + this->setTime(d); +} + +//--------------------------------------------------------------------- + +void DateTime::set(Calendar::EDateFields aField, t_int32 amount) +{ + CalendarSetTimeHelper(this->getTime()); + + ms_Calendar->set(aField, amount); + + this->setTime(CalendarGetTimeHelper()); +} + +//--------------------------------------------------------------------- + +void DateTime::add(Calendar::EDateFields aField, t_int32 amount) +{ + ErrorCode status = ZERO_ERROR; + + CalendarSetTimeHelper(this->getTime()); + + ms_Calendar->add(aField, amount, status); + //PR_ASSERT(!FAILURE(status)); + if (FAILURE(status)) + { + //if (FALSE) TRACE("FAILURE in DateTime::add %d\r\n", status); + } + this->setTime(CalendarGetTimeHelper()); +} + +//--------------------------------------------------------------------- + +void DateTime::add(Julian_Duration d) +{ + add(Calendar::YEAR, d.getYear()); + add(Calendar::MONTH, d.getMonth()); + add(Calendar::DATE, d.getDay()); + add(Calendar::HOUR_OF_DAY, d.getHour()); + add(Calendar::MINUTE, d.getMinute()); + add(Calendar::SECOND, d.getSecond()); + add(Calendar::WEEK_OF_YEAR, d.getWeek()); +} + +//--------------------------------------------------------------------- + +void DateTime::subtract(Julian_Duration d) +{ + add(Calendar::YEAR, - d.getYear()); + add(Calendar::MONTH, - d.getMonth()); + add(Calendar::DATE, - d.getDay()); + add(Calendar::HOUR_OF_DAY, - d.getHour()); + add(Calendar::MINUTE, - d.getMinute()); + add(Calendar::SECOND, - d.getSecond()); + add(Calendar::WEEK_OF_YEAR, - d.getWeek()); +} + +//--------------------------------------------------------------------- +Julian_Duration & DateTime::getDuration(DateTime start, DateTime end, + Julian_Duration & out) +{ + t_int32 y = 0, mo = 0, d = 0, h = 0, m = 0, s = 0; + t_int32 toNextMonth = 0; + + if (end < start) + { + out.set(-1, -1, -1, -1, -1, -1); + return out; + } + else + { + y = end.get(Calendar::YEAR) - start.get(Calendar::YEAR); + mo = end.get(Calendar::MONTH) - start.get(Calendar::MONTH); + if (mo < 0) + { + y--; + mo += 12; + } + d = end.get(Calendar::DATE) - start.get(Calendar::DATE); + if (d < 0) + { + mo--; + toNextMonth = start.get(Calendar::DATE); + + // count number of days to get to next month + start.findLastDayOfMonth(); + toNextMonth = start.get(Calendar::DATE) - toNextMonth; + start.nextDay(); + toNextMonth++; + + // now start day <= end day + d = end.get(Calendar::DATE) - start.get(Calendar::DATE); + d += toNextMonth; // add number of days to get to next month + } + + h = end.get(Calendar::HOUR_OF_DAY) - start.get(Calendar::HOUR_OF_DAY); + if (h < 0) + { + d--; + h += 24; + } + m = end.get(Calendar::MINUTE) - start.get(Calendar::MINUTE); + if (m < 0) + { + h--; + m += 60; + } + s = end.get(Calendar::SECOND) - start.get(Calendar::SECOND); + if (s < 0) + { + m--; + s += 60; + } + out.set(y, mo, d, h, m, s); + return out; + } +} +//--------------------------------------------------------------------- + +void DateTime::clear() +{ + CalendarSetTimeHelper(this->getTime()); + + ms_Calendar->clear(); + + this->setTime(CalendarGetTimeHelper()); +} +//--------------------------------------------------------------------- + +//---------------------------- +// UTILITIES +//---------------------------- + +//--------------------------------------------------------------------- + +t_bool DateTime::isValid() +{ + if (getTime() < 0) + return FALSE; + return TRUE; +} + +//--------------------------------------------------------------------- + +void DateTime::prevDay() +{ + add(Calendar::DAY_OF_YEAR, -1); +} + +//--------------------------------------------------------------------- + +void DateTime::prevDay(t_int32 i) +{ + add(Calendar::DAY_OF_YEAR, -i); +} + +//--------------------------------------------------------------------- + +void DateTime::nextDay() +{ + add(Calendar::DAY_OF_YEAR, 1); +} + +//--------------------------------------------------------------------- + +void DateTime::nextDay(t_int32 i) +{ + add(Calendar::DAY_OF_YEAR, i); +} + +//--------------------------------------------------------------------- + +void DateTime::prevWeek() +{ + add(Calendar::WEEK_OF_YEAR, -1); +} + +//--------------------------------------------------------------------- + +void DateTime::nextWeek() +{ + add(Calendar::WEEK_OF_YEAR, 1); +} + +//--------------------------------------------------------------------- + +void DateTime::moveTo(t_int32 i, t_int32 direction, t_bool force) +{ + if (force) + add(Calendar::DAY_OF_WEEK, direction); + + while (get(Calendar::DAY_OF_WEEK) != i) + { + add(Calendar::DAY_OF_WEEK, direction); + } +} + +//--------------------------------------------------------------------- + +void DateTime::setByISOWeek(t_int32 week) +{ + PR_ASSERT(week != 0); + if (week > 0) + { + // find the first day of the year + add(Calendar::DAY_OF_YEAR, - get(Calendar::DAY_OF_YEAR) + 1); + + // jump to the first day + moveTo(Calendar::THURSDAY, 1, FALSE); + + // back track to the Monday before the Thursday + moveTo(Calendar::MONDAY, -1, FALSE); + + // we're now on the 1st day of the 1st week + add(Calendar::DAY_OF_YEAR, 7 * (week - 1)); + } + else + { + // find the last day of the year + findLastDayOfYear(); + moveTo(Calendar::THURSDAY, -1, FALSE); + moveTo(Calendar::MONDAY, -1, FALSE); + add(Calendar::DAY_OF_YEAR, 7 * (week + 1)); + } +} +//--------------------------------------------------------------------- + +void DateTime::prevMonth() +{ + add(Calendar::MONTH, -1); +} + +//--------------------------------------------------------------------- + +void DateTime::prevMonth(t_int32 iLim) +{ + t_int32 i; + for (i = 0; i < iLim; i++) + prevMonth(); +} + +//--------------------------------------------------------------------- + +void DateTime::nextMonth() +{ + t_int32 iMonth = get(Calendar::MONTH); + if (iMonth == Calendar::DECEMBER) + iMonth = Calendar::JANUARY; + else + iMonth++; + + add(Calendar::MONTH, 1); + + while ( get(Calendar::MONTH) != iMonth) + add(Calendar::DATE, -1); + +} + +//--------------------------------------------------------------------- + +void DateTime::nextMonth(t_int32 iLim) +{ + t_int32 i; + for (i = 0; i < iLim; i++) + nextMonth(); +} + +//--------------------------------------------------------------------- + +t_int32 DateTime::prevDOW(t_int32 n) +{ + t_int32 iCount = 0; + + CalendarSetTimeHelper(getTime()); + + if (n < Calendar::SUNDAY || n > Calendar::SATURDAY) + return 0; + + while(get(Calendar::DAY_OF_WEEK) != n) + { + prevDay(); + ++iCount; + } + + return iCount; +} + +//--------------------------------------------------------------------- + +t_int32 DateTime::compareTo(DateTime &dt) +{ + Date d = dt.getTime(); + return compare(d); +} + +//--------------------------------------------------------------------- + +t_bool DateTime::beforeDate(Date d) +{ + return m_Date < d; +} + +//--------------------------------------------------------------------- + +t_bool DateTime::beforeDateTime(DateTime dt) +{ + return beforeDate(dt.getTime()); +} + +//--------------------------------------------------------------------- + +t_bool DateTime::before(DateTime * dt) +{ + PR_ASSERT(dt != 0); + return (compareTo(*dt) == -1); +} + +//--------------------------------------------------------------------- + +t_bool DateTime::afterDate(Date d) +{ + return m_Date > d; +} + +//--------------------------------------------------------------------- + +t_bool DateTime::afterDateTime(DateTime dt) +{ + return afterDate(dt.getTime()); +} + +//--------------------------------------------------------------------- + +t_bool DateTime::after(DateTime *dt) +{ + PR_ASSERT(dt != 0); + return (compareTo(*dt) == 1); +} + +//--------------------------------------------------------------------- + +t_bool DateTime::equalsDate(Date d) +{ + return m_Date == d; +} + +//--------------------------------------------------------------------- + +t_bool DateTime::equalsDateTime(DateTime dt) +{ + return equalsDate(dt.getTime()); +} + +//--------------------------------------------------------------------- + +t_bool DateTime::equals(DateTime *dt) +{ + PR_ASSERT(dt != 0); + return (compareTo(*dt) == 0); +} + +//--------------------------------------------------------------------- + +t_bool DateTime::sameDMY(DateTime * d, TimeZone * timezone) +{ + t_bool retVal; + + CalendarSetTimeHelper(this->getTime()); + t_int32 myYear = this->get(Calendar::YEAR, timezone); + t_int32 myMonth = this->get(Calendar::MONTH, timezone); + t_int32 myDate = this->get(Calendar::DATE, timezone); + + CalendarSetTimeHelper(d->getTime()); + + retVal = + ((myDate == CalendarGetFieldHelper(Calendar::DATE, timezone)) && + (myMonth == CalendarGetFieldHelper(Calendar::MONTH, timezone)) && + (myYear == CalendarGetFieldHelper(Calendar::YEAR, timezone))); + + CalendarSetTimeHelper(this->getTime()); // set time back + return retVal; +} + +//--------------------------------------------------------------------- + +UnicodeString DateTime::toString(TimeZone * timezone) +{ + //return strftimeNoLocale(ms_sDefaultPattern, m_TimeZone); + return strftimeNoLocale(JulianFormatString::Instance()->ms_sDateTimeDefaultPattern, timezone); +} +//--------------------------------------------------------------------- + +UnicodeString DateTime::toISO8601Local(TimeZone * timezone) +{ + //return strftimeNoLocale(ms_sISO8601LocalPattern, m_TimeZone); + return strftimeNoLocale(JulianFormatString::Instance()->ms_sDateTimeISO8601LocalPattern, timezone); +} +//--------------------------------------------------------------------- + +UnicodeString DateTime::toISO8601() +{ + return strftimeNoLocale(JulianFormatString::Instance()->ms_sDateTimeISO8601Pattern, + (TimeZone *) m_kGMTTimeZone); +} +//--------------------------------------------------------------------- + +UnicodeString DateTime::toISO8601LocalTimeOnly(TimeZone * timezone) +{ + //return strftimeNoLocale(ms_sISO8601TimeOnlyPattern, m_TimeZone); + return strftimeNoLocale(JulianFormatString::Instance()->ms_sDateTimeISO8601TimeOnlyPattern, timezone); +} + +//--------------------------------------------------------------------- + +UnicodeString DateTime::toISO8601TimeOnly() +{ + return strftimeNoLocale(JulianFormatString::Instance()->ms_sDateTimeISO8601TimeOnlyPattern, + (TimeZone *) m_kGMTTimeZone); +} + +//--------------------------------------------------------------------- + +UnicodeString DateTime::toISO8601LocalDateOnly(TimeZone * timezone) +{ + //return strftimeNoLocale(ms_sISO8601DateOnlyPattern, m_TimeZone); + return strftimeNoLocale(JulianFormatString::Instance()->ms_sDateTimeISO8601DateOnlyPattern, timezone); +} + +//--------------------------------------------------------------------- + +UnicodeString DateTime::toISO8601DateOnly() +{ + return strftimeNoLocale(JulianFormatString::Instance()->ms_sDateTimeISO8601DateOnlyPattern, + (TimeZone *) m_kGMTTimeZone); +} + +//--------------------------------------------------------------------- + +UnicodeString DateTime::strftime(UnicodeString &pattern, TimeZone * timezone) +{ + //return strftimeNoLocale(pattern, m_TimeZone); + return strftimeNoLocale(pattern, timezone); +} + +//--------------------------------------------------------------------- + +UnicodeString DateTime::strftimeNoLocale(UnicodeString &pattern, + TimeZone * aTimeZone) +{ + UnicodeString result; + + //time_t tt, tt2; + //time (&tt); + + FieldPosition pos(0); + ErrorCode status = ZERO_ERROR; + Date d = getTime(); + + //ms_DateFormat->applyLocalizedPattern(pattern, status); + ms_DateFormat->applyLocalizedPattern(pattern, status); + + if (FAILURE(status)) + { + //if (FALSE) TRACE("FAILURE in DateTime::strftimeNoLocale %d\r\n", status); + } + if (aTimeZone != 0) { + //ms_DateFormat->setTimeZone(*aTimeZone); + ms_DateFormat->setTimeZone(*aTimeZone); + } + else { + //ms_DateFormat->setTimeZone(*ms_TimeZone); // assumption: ms_TimeZone is never NULL + ms_DateFormat->setTimeZone(*ms_TimeZone); // assumption: ms_TimeZone is never NULL + } + //return ((DateFormat *) ms_DateFormat)->format(getTime(), result); + //return ms_DateFormat->format(d, result, pos); + + //ms_DateFormat->format(d, result, pos); + ms_DateFormat->format(d, result, pos); + + //time (&tt2); + //if (FALSE) TRACE("%d milleseconds for strftime(1)\r\n", tt2 -tt); + + return result; +} + +//--------------------------------------------------------------------- + +UnicodeString DateTime::strftime(UnicodeString &pattern, Locale & locale, + TimeZone * timezone) +{ + UnicodeString result; + + //time_t tt, tt2; + //time (&tt); + + ErrorCode status = ZERO_ERROR; + FieldPosition pos(0); + Date d = getTime(); + UnicodeString name; + + ///////// PTR /////////// + //SimpleDateFormat * dateFormat; + + //if (sdfHashtable.isEmpty()) initHashtable(); + + UnicodeString ID = locale.getName(name); + //dateFormat = (SimpleDateFormat *) sdfHashtable.get(UnicodeStringKey(ID)); + + // Must split up to avoid LNK4103 + SimpleDateFormat sdf(pattern, locale, status); + if (FAILURE(status)) + { + //if (FALSE) TRACE("FAILURE in DateTime::strftime(3, 1) %d\r\n", status); + } + if (timezone != 0) sdf.setTimeZone(*timezone); + sdf.format(d, result, pos); + return result; + + //} + //else + //{ + // TODO: CACHE SIMPLEDATEFORMATS + /* + ////if (FALSE) TRACE("pattern = %s, locale = %s\r\n", pattern.toCString(""), locale.getName(name).toCString("")); + ////dateFormat->applyLocalizedPattern(pattern, status); + //dateFormat->applyPattern(pattern); + + //if (FAILURE(status)) + // if (FALSE) TRACE("FAILURE in DateTime::strftime(3, 2) :%d errorcode, %s pattern, %s locale\r\n", + // status, pattern.toCString(""), locale.getName(name).toCString("")); + //if (timezone != NULL) dateFormat->setTimeZone(*timezone); // ptr + //dateFormat->format(d, result, pos); //ptr + ////dateFormat->format(d, result); // dateformat ptr + ////delete dateFormat; + */ + //} + + //if (FALSE) TRACE("result = %s", result.toCString("")); + //time (&tt2); + //if (FALSE) TRACE("%d milleseconds for strftime(3)\r\n", tt2 -tt); + //return result; +} + +//--------------------------------------------------------------------- +/* +void DateTime::findLastDayOfMonth(DateTime *s) +{ + set(Calendar::MONTH, (s->get(Calendar::MONTH) + 1) % 12); + add(Calendar::MONTH, 1); + set(Calendar::DATE, 1); + add(Calendar::DATE, -1); +} +*/ +void DateTime::findLastDayOfMonth() +{ + add(Calendar::MONTH, 1); + //set(Calendar::DATE, 1); + add(Calendar::DATE, -get(Calendar::DATE)); +} + +//--------------------------------------------------------------------- +/* +void DateTime::findLastDayOfYear(DateTime *s) +{ + set(Calendar::YEAR, s->get(Calendar::YEAR)); + s->add(Calendar::DAY_OF_YEAR, - (get(Calendar::DAY_OF_YEAR))); +} +*/ +void DateTime::findLastDayOfYear() +{ + add(Calendar::YEAR, 1); + add(Calendar::DAY_OF_YEAR, - (get(Calendar::DAY_OF_YEAR))); +} + +//--------------------------------------------------------------------- + +//---------------------------- +// STATIC METHODS +//---------------------------- + +//--------------------------------------------------------------------- + +t_int32 DateTime::getPrevDOW(t_int32 n) +{ + if (n == Calendar::SATURDAY) + return Calendar::SUNDAY; + else + return n - 1; +} + +//--------------------------------------------------------------------- + +t_int32 DateTime::getNextDOW(t_int32 n) +{ + if (n == Calendar::SATURDAY) + return Calendar::SUNDAY; + else + return n + 1; +} + +//--------------------------------------------------------------------- + +UnicodeString DateTime::DateToString(DateTime & dt) +{ + return dt.toString(); +} + +//--------------------------------------------------------------------- + +t_bool DateTime::IsParseable(UnicodeString & s) +{ + t_int32 year, month, day, hour, min, sec; + return IsParseable(s, year, month, day, hour, min, sec); +} +//--------------------------------------------------------------------- +t_bool +DateTime::IsParseable(UnicodeString & s, t_int32 & iYear, t_int32 & iMonth, + t_int32 & iDay, t_int32 & iHour, t_int32 & iMinute, + t_int32 & iSecond) +{ + t_bool bParseError = FALSE; + //UnicodeString temp; + + if (s.size() < 8) + return FALSE; + else if (s.size() > 8 && s.size() < 15) + return FALSE; + else if (s.size() > 16) + return FALSE; + else if (s.size() == 16 && s[(TextOffset) 15] != 'Z') + return FALSE; + else if (s.size() > 8 && s.indexOf('T', 8, 1) < 0) + return FALSE; + else + { + char * c = s.toCString(""); + PR_ASSERT(c != 0); + + // Looks like it could be formatted OK, try to parse it + //s.trim(); + + /* + // old way, works but slow and leaks + iYear = JulianUtility::atot_int32(s.extract(0, 4, temp).toCString(""), bParseError, 4); + iMonth = JulianUtility::atot_int32(s.extract(4, 2, temp).toCString(""), bParseError, 2); + iDay = JulianUtility::atot_int32(s.extract(6, 2, temp).toCString(""), bParseError, 2); + */ + + // new way is faster, but uses ptr arithmetic + iYear = JulianUtility::atot_int32(c, bParseError, 4); + iMonth = JulianUtility::atot_int32(c + 4, bParseError, 2); + iDay = JulianUtility::atot_int32(c + 6, bParseError, 2); + + if (iMonth > 12 || iDay > 31) + { + bParseError = TRUE; + } + + // more advanced check - check for day mishaps, including leap years + if (iDay > getMonthLength(iMonth, iYear)) + { + bParseError = TRUE; + } + if (s.size() > 8 && !bParseError) + { + /* + // old way, works but slow + iHour = JulianUtility::atot_int32(s.extract(9, 2, temp).toCString(""), bParseError, 2); + iMinute= JulianUtility::atot_int32(s.extract(11, 2, temp).toCString(""), bParseError, 2); + iSecond= JulianUtility::atot_int32(s.extract(13, 2, temp).toCString(""), bParseError, 2); + */ + + // new way is faster, but uses ptr arithmetic + iHour = JulianUtility::atot_int32(c + 9, bParseError, 2); + iMinute = JulianUtility::atot_int32(c + 11, bParseError, 2); + iSecond = JulianUtility::atot_int32(c + 13, bParseError, 2); + + if (iHour > 23 || iMinute > 59 || iSecond > 59) + { + bParseError = TRUE; + } + } + + delete [] c; + + if (bParseError) + return FALSE; + + + return TRUE; + } +} +//--------------------------------------------------------------------- + +t_bool DateTime::IsParseableDateTime(UnicodeString & s) +{ + return (s.size() >= 15 && DateTime::IsParseable(s)); +} +//--------------------------------------------------------------------- + +t_bool DateTime::IsParseableDate(UnicodeString & s) +{ + return (s.size() == 8 && DateTime::IsParseable(s)); +} +//--------------------------------------------------------------------- +t_bool DateTime::IsParseableUTCOffset(UnicodeString & s) +{ + t_int32 hour, minute; + return DateTime::IsParseableUTCOffset(s, hour, minute); +} +//--------------------------------------------------------------------- +t_bool DateTime::IsParseableUTCOffset(UnicodeString & s, + t_int32 & iHour, t_int32 & iMin) +{ + t_bool bParseError = ZERO_ERROR; + char c; + + if (s.size() != 5) + return FALSE; + + UnicodeString u; + //if (FALSE) TRACE("%s, %s\r\n", s.toCString(""), u.toCString("")); + + c = (char) s[(TextOffset) 0]; + if ((c != '+') && (c != '-')) + return FALSE; + + char * cc = s.toCString(""); + PR_ASSERT(cc != 0); + + /* + // old way, works but slow and leaks + iHour = JulianUtility::atot_int32(s.extract(1, 2, u).toCString(""), bParseError, 2); + iMin = JulianUtility::atot_int32(s.extract(3, 2, u).toCString(""), bParseError, 2); + */ + + iHour = JulianUtility::atot_int32(cc + 1, bParseError, 2); + iMin = JulianUtility::atot_int32(cc + 3, bParseError, 2); + + delete [] cc; + + if (bParseError) + return FALSE; + if ((iHour > 23) || (iMin > 59)) + return FALSE; + if (c == '-') + { + iHour = - iHour; + iMin = - iMin; + } + return TRUE; +} + +//--------------------------------------------------------------------- + +int DateTime::CompareDateTimes(const void * a, const void * b) +{ + PR_ASSERT(a != 0 && b != 0); + + DateTime * dtA = *(DateTime **) a; + DateTime * dtB = *(DateTime **) b; + return (int) (*dtA).compareTo(*dtB); +} + +//--------------------------------------------------------------------- + +//----------------------------- +// OVERLOADED OPERATORS +//----------------------------- + +//--------------------------------------------------------------------- + +const DateTime & DateTime::operator=(const DateTime & that) +{ + + // if(m_Init) + //CtorCore(that.m_TimeZone); + //Date d = that.getTime(); + //if (m_TimeZone != 0) + // delete m_TimeZone; + //m_TimeZone = that.m_TimeZone; + + //CalendarSetTimeHelper(d); + //this->setTime(CalendarGetTimeHelper()); + //this->setTimeZone(that.ms_TimeZone); + this->setTime(that.getTime()); + return *this; +} + +//--------------------------------------------------------------------- + +t_bool DateTime::operator==(const DateTime & that) +{ + return compare(that.getTime()) == 0; +} + +//--------------------------------------------------------------------- + +t_bool DateTime::operator!=(const DateTime & that) +{ + return compare(that.getTime()) != 0; +} + +//--------------------------------------------------------------------- + +t_bool DateTime::operator>(const DateTime & that) +{ + return compare(that.getTime()) == 1; +} + +//--------------------------------------------------------------------- + +t_bool DateTime::operator<(const DateTime & that) +{ + return compare(that.getTime()) == -1; +} + +//--------------------------------------------------------------------- + +UnicodeString & +DateTime::ToISO8601String(t_int32 iYear, t_int32 iMonth, t_int32 iDay, + t_int32 iHour, t_int32 iMinute, t_int32 iSecond, + UnicodeString & sResult) +{ + char sBuf[20]; + sResult = ""; + sprintf(sBuf, "%.4d%.2d%.2dT%.2d%.2d%.2d", iYear, iMonth, iDay, iHour, iMinute, iSecond); + sResult += sBuf; + return sResult; +} diff --git a/calendar/modules/util/src/duration.cpp b/calendar/modules/util/src/duration.cpp new file mode 100644 index 00000000000..305d8f9a7c5 --- /dev/null +++ b/calendar/modules/util/src/duration.cpp @@ -0,0 +1,730 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +// duration.cpp +// John Sun +// 5:52 PM January 28 1998 + +#include "stdafx.h" +#include "jdefines.h" + +#include +#include +#include +#include "duration.h" +#include "jutility.h" + +// turn this flag on to allow for parsing of year and month +#define JULIAN_DURATION_PARSING_YEAR_AND_MONTH 1 +//--------------------------------------------------------------------- + +void Julian_Duration::setInvalidDuration() +{ + m_iYear = -1; + m_iMonth = -1; + m_iDay = -1; + m_iHour = -1; + m_iMinute = -1; + m_iSecond = -1; + m_iWeek = -1; +} + +//--------------------------------------------------------------------- + +void Julian_Duration::parse(UnicodeString & us) +{ + // NOTE: use a better algorithm like a regexp scanf or something. + + UnicodeString sVal; + UnicodeString sSection; + + t_bool bErrorInParse = FALSE; + t_int32 startOfParse = 0, indexOfT = 0, endOfParse = 0; + t_int32 day = 0, hour = 0, minute = 0, second = 0, week = 0; +#if JULIAN_DURATION_PARSING_YEAR_AND_MONTH + t_int32 year = 0, month = 0; + t_int32 indexOfY = 0, indexOfMo = 0; +#endif + t_int32 indexOfD = 0; + t_int32 indexOfH = 0, indexOfMi = 0, indexOfS = 0, indexOfW = 0; + + char * cc = 0; + + if (us[(TextOffset) 0] != 'P') //!us.startsWith(s_sP)) + { + if ('-' == us[(TextOffset) 0] && ('P' == us[(TextOffset) 1])) + { + m_NegativeDuration = TRUE; + startOfParse = 1; + } + else if ('+' == us[(TextOffset) 0] && ('P' == us[(TextOffset) 1])) + { + m_NegativeDuration = FALSE; + startOfParse = 1; + } + else + bErrorInParse = TRUE; + } + + if (!bErrorInParse) + { + startOfParse++; + indexOfT = us.indexOf('T'); + endOfParse = us.size(); + indexOfW = us.indexOf('W'); + if (indexOfW == -1) + { + // first parse the date section + if (indexOfT > 0) + { + endOfParse = indexOfT; + } + sSection = us.extractBetween(startOfParse, endOfParse, sSection); + startOfParse = 0; + endOfParse = sSection.size(); + +#if JULIAN_DURATION_PARSING_YEAR_AND_MONTH + indexOfY = sSection.indexOf('Y'); + if (indexOfY >= 0) + { + sVal = sSection.extractBetween(startOfParse, indexOfY, sVal); + cc = sVal.toCString(""); + PR_ASSERT(cc != 0); + year = JulianUtility::atot_int32(cc, + bErrorInParse, sVal.size()); + delete [] cc; + startOfParse = indexOfY + 1; + } + indexOfMo = sSection.indexOf('M'); + if (indexOfMo >= 0) + { + sVal = sSection.extractBetween(startOfParse, indexOfMo, sVal); + cc = sVal.toCString(""); + PR_ASSERT(cc != 0); + month = JulianUtility::atot_int32(cc, + bErrorInParse, sVal.size()); + delete [] cc; + startOfParse = indexOfMo + 1; + } +#endif + indexOfD = sSection.indexOf('D'); + if (indexOfD >= 0) + { + sVal = sSection.extractBetween(startOfParse, indexOfD, sVal); + cc = sVal.toCString(""); + PR_ASSERT(cc != 0); + day = JulianUtility::atot_int32(cc, + bErrorInParse, sVal.size()); + delete [] cc; + startOfParse = indexOfD + 1; + } +#if JULIAN_DURATION_PARSING_YEAR_AND_MONTH + if (sSection.size() >= 1 && indexOfY == -1 && + indexOfMo == -1 && indexOfD == -1) + { + bErrorInParse = TRUE; + } + else if (indexOfY != -1 && indexOfMo != -1 && indexOfY > indexOfMo) + bErrorInParse = TRUE; + else if (indexOfY != -1 && indexOfD != -1 && indexOfY > indexOfD) + bErrorInParse = TRUE; + else if (indexOfMo != -1 && indexOfD != -1 && indexOfMo > indexOfD) + bErrorInParse = TRUE; + else if (indexOfD != -1 && indexOfD != endOfParse -1) + bErrorInParse = TRUE; + else if (indexOfMo != -1 && indexOfD == -1 && indexOfMo != endOfParse -1) + bErrorInParse = TRUE; + else if (indexOfY != -1 && indexOfD == -1 && indexOfMo == -1 && indexOfY != endOfParse -1) + bErrorInParse = TRUE; +#else + if (sSection.size() >= 1 && indexOfD == -1) + { + bErrorInParse = TRUE; + } + else if (indexOfD != -1 && indexOfD != endOfParse -1) + bErrorInParse = TRUE; +#endif + + // now parse time section + if (indexOfT > 0) + { + startOfParse = indexOfT + 1; + endOfParse = us.size(); + sSection = us.extractBetween(startOfParse, endOfParse, sSection); + startOfParse = 0; + endOfParse = sSection.size(); + indexOfH = sSection.indexOf('H'); + if (indexOfH >= 0) { + sVal = sSection.extractBetween(startOfParse, indexOfH, sVal); + cc = sVal.toCString(""); + PR_ASSERT(cc != 0); + hour = JulianUtility::atot_int32(cc, + bErrorInParse, sVal.size()); + delete [] cc; + startOfParse = indexOfH + 1; + } + indexOfMi = sSection.indexOf('M'); + + if (indexOfMi >= 0) { + sVal = sSection.extractBetween(startOfParse, indexOfMi, sVal); + cc = sVal.toCString(""); + PR_ASSERT(cc != 0); + minute = JulianUtility::atot_int32(cc, + bErrorInParse, sVal.size()); + delete [] cc; + startOfParse = indexOfMi + 1; + } + indexOfS = sSection.indexOf('S'); + if (indexOfS >= 0) + { + sVal = sSection.extractBetween(startOfParse, indexOfS, sVal); + cc = sVal.toCString(""); + PR_ASSERT(cc != 0); + second = JulianUtility::atot_int32(cc, + bErrorInParse, sVal.size()); + delete [] cc; + startOfParse = indexOfS + 1; + } + if (sSection.size() > 0 && indexOfH == -1 && + indexOfMi == -1 && indexOfS == -1) + { + bErrorInParse = TRUE; + } + else if (indexOfH != -1 && indexOfMi != -1 && indexOfH > indexOfMi) + bErrorInParse = TRUE; + else if (indexOfH != -1 && indexOfS != -1 && indexOfH > indexOfS) + bErrorInParse = TRUE; + else if (indexOfMi != -1 && indexOfS != -1 && indexOfMi > indexOfS) + bErrorInParse = TRUE; + else if (indexOfS != -1 && indexOfS != endOfParse -1) + bErrorInParse = TRUE; + else if (indexOfMi != -1 && indexOfS == -1 && indexOfMi != endOfParse -1) + bErrorInParse = TRUE; + else if (indexOfH != -1 && indexOfS == -1 && indexOfMi == -1 && indexOfH != endOfParse -1) + bErrorInParse = TRUE; + } + } + else + { + // week parse + if (us.size() - 1 != indexOfW) + bErrorInParse = TRUE; + + sVal = us.extractBetween(1, us.size() - 1, sVal); + cc = sVal.toCString(""); + PR_ASSERT(cc != 0); + week = JulianUtility::atot_int32(cc, + bErrorInParse, sVal.size()); + delete [] cc; + } + } + //if (FALSE) TRACE("parse: %d W, %d Y %d M %d D T %d H %d M %d S\r\n", week, year, month, day, hour, minute, second); +#if JULIAN_DURATION_PARSING_YEAR_AND_MONTH + if (year < 0 || month < 0 || day < 0 || + hour < 0 || minute < 0 || second < 0 || week < 0) + bErrorInParse = TRUE; +#else + if (day < 0 || hour < 0 || minute < 0 || second < 0 || week < 0) + bErrorInParse = TRUE; +#endif + + + if (bErrorInParse) + { + // LOG the error + setInvalidDuration(); + } + else + { +#if JULIAN_DURATION_PARSING_YEAR_AND_MONTH + + m_iYear = year; + m_iMonth = month; +#else + m_iYear = 0; + m_iMonth = 0; +#endif + m_iDay = day; + m_iHour = hour; + m_iMinute = minute; + m_iSecond = second; + m_iWeek = week; + normalize(); + } +} + +//--------------------------------------------------------------------- + +////////////////////////////// +// CONSTRUCTORS +////////////////////////////// + +//--------------------------------------------------------------------- + +Julian_Duration::Julian_Duration() +: + m_iYear(0),m_iMonth(0),m_iDay(0),m_iHour(0), + m_iMinute(0),m_iSecond(0), m_iWeek(0), + m_NegativeDuration(FALSE) +{ +} + +//--------------------------------------------------------------------- + +Julian_Duration::Julian_Duration(UnicodeString & us) +: + m_iYear(0),m_iMonth(0),m_iDay(0),m_iHour(0), + m_iMinute(0),m_iSecond(0), m_iWeek(0), + m_NegativeDuration(FALSE) +{ + parse(us); +} + +//--------------------------------------------------------------------- + +Julian_Duration::Julian_Duration(t_int32 type, t_int32 value) +: + m_iYear(0),m_iMonth(0),m_iDay(0),m_iHour(0), + m_iMinute(0),m_iSecond(0), m_iWeek(0), + m_NegativeDuration(FALSE) +{ + switch (type) + { + case JulianUtility::RT_MINUTELY: + m_iMinute = value; + break; + case JulianUtility::RT_HOURLY: + m_iHour = value; + break; + case JulianUtility::RT_DAILY: + m_iDay = value; + break; + case JulianUtility::RT_WEEKLY: + m_iWeek = value; + break; + case JulianUtility::RT_MONTHLY: + m_iMonth = value; + break; + case JulianUtility::RT_YEARLY: + m_iYear = value; + break; + default: + break; + } +} + +//--------------------------------------------------------------------- + +Julian_Duration::Julian_Duration(Julian_Duration & d) +: + m_iYear(0),m_iMonth(0),m_iDay(0),m_iHour(0), + m_iMinute(0),m_iSecond(0), m_iWeek(0), + m_NegativeDuration(FALSE) +{ + t_bool b; + + m_iYear = d.m_iYear; + m_iMonth = d.m_iMonth; + m_iDay = d.m_iDay; + m_iHour = d.m_iHour; + m_iMinute = d.m_iMinute; + m_iSecond = d.m_iSecond; + m_iWeek = d.m_iWeek; + m_NegativeDuration = d.m_NegativeDuration; + + // check postcondition + b = ((m_iWeek != 0) && (m_iYear != 0 || m_iMonth != 0 || + m_iDay != 0 || m_iHour !=0 || m_iMinute != 0 || + m_iSecond != 0)); + + if (!b) { + //PR_ASSERT(!b); + //JLog::Instance()->logString(ms_sDurationAssertionFailed); + //setInvalidDuration(); + } +} +//--------------------------------------------------------------------- + +Julian_Duration::Julian_Duration(t_int32 year, t_int32 month, t_int32 day, + t_int32 hour, t_int32 min, t_int32 sec, + t_int32 week, t_bool bNegativeDuration) +{ + if (week > 0) + { + set(year, month, day, hour, min, sec, bNegativeDuration); + } + else + { + set(week, bNegativeDuration); + } +} + +//--------------------------------------------------------------------- + +/////////////////////////////////// +// DESTRUCTORS +/////////////////////////////////// + +//--------------------------------------------------------------------- + +Julian_Duration::~Julian_Duration() +{ +} + +//--------------------------------------------------------------------- + +/////////////////////////////////// +// GETTERS AND SETTERS +/////////////////////////////////// +void Julian_Duration::set(t_int32 year, t_int32 month, t_int32 day, + t_int32 hour, t_int32 min, t_int32 sec, t_bool + bNegativeDuration) +{ + m_iYear = year; + m_iMonth = month; + m_iDay = day; + m_iHour = hour; + m_iMinute = min; + m_iSecond = sec; + m_NegativeDuration = bNegativeDuration; + m_iWeek = 0; +} + +void Julian_Duration::set(t_int32 week, t_bool bNegativeDuration) +{ + m_iWeek = week; + m_NegativeDuration = bNegativeDuration; + m_iYear = 0; + m_iMonth = 0; + m_iDay = 0; + m_iHour = 0; + m_iMinute = 0; + m_iSecond = 0; +} + +t_int32 Julian_Duration::getYear() const +{ + if (m_NegativeDuration) + return (0 - m_iYear); + return m_iYear; +} + +t_int32 Julian_Duration::getMonth() const +{ + if (m_NegativeDuration) + return (0 - m_iMonth); + return m_iMonth; +} + +t_int32 Julian_Duration::getDay() const +{ + if (m_NegativeDuration) + return (0 - m_iDay); + return m_iDay; +} + +t_int32 Julian_Duration::getHour() const +{ + if (m_NegativeDuration) + return (0 - m_iHour); + return m_iHour; +} + +t_int32 Julian_Duration::getMinute() const +{ + if (m_NegativeDuration) + return (0 - m_iMinute); + return m_iMinute; +} + +t_int32 Julian_Duration::getSecond() const +{ + if (m_NegativeDuration) + return (0 - m_iSecond); + return m_iSecond; +} + +t_int32 Julian_Duration::getWeek() const +{ + if (m_NegativeDuration) + return (0 - m_iWeek); + return m_iWeek; +} + +//--------------------------------------------------------------------- + +/////////////////////////////////// +// UTILITIES +/////////////////////////////////// + +//--------------------------------------------------------------------- + +void Julian_Duration::setDurationString(UnicodeString & s) +{ + parse(s); +} + +//--------------------------------------------------------------------- + +// TODO - will work if only normalize works +t_int32 Julian_Duration::compareTo(const Julian_Duration & d) +{ + normalize(); + + if (getYear() != d.getYear()) + return ((getYear() > d.getYear()) ? 1 : -1); + if (getMonth() != d.getMonth()) + return ((getMonth() > d.getMonth()) ? 1 : -1); + if (getDay() != d.getDay()) + return ((getDay() > d.getDay()) ? 1 : -1); + if (getHour() != d.getHour()) + return ((getHour() > d.getHour()) ? 1 : -1); + if (getMinute() != d.getMinute()) + return ((getMinute() > d.getMinute()) ? 1 : -1); + if (getSecond() != d.getSecond()) + return ((getSecond() > d.getSecond()) ? 1 : -1); + if (getWeek() != d.getWeek()) + return ((getWeek() > d.getWeek()) ? 1 : -1); + return 0; +} + +//--------------------------------------------------------------------- + +void Julian_Duration::normalize() +{ + // TODO: RISKY, assumes 30 days in a month, 12 months in a year + t_int32 temp1 = 0, temp2 = 0, temp3 = 0, temp4 = 0, temp5 = 0; + if (m_iSecond >= 60) + { + temp1 = m_iSecond / 60; + m_iSecond = m_iSecond % 60; + } + m_iMinute = m_iMinute + temp1; + if (m_iMinute >= 60) { + temp2 = m_iMinute / 60; + m_iMinute = m_iMinute % 60; + } + m_iHour = m_iHour + temp2; + if (m_iHour >= 24) { + temp3 = m_iHour / 24; + m_iHour = m_iHour % 24; + } + m_iDay = m_iDay + temp3; + if (m_iDay >= 30) { + temp4 = m_iDay / 30; + m_iDay = m_iDay % 30; + } + m_iMonth = m_iMonth + temp4; + if (m_iMonth >= 12) { + temp5 = m_iMonth / 12; + m_iMonth = m_iMonth % 12; + } + m_iYear = m_iYear + temp5; +} + +//--------------------------------------------------------------------- + +void Julian_Duration::unnormalize() +{ + // TODO: watch out for overflow + if (m_iYear > 0) + { + m_iMonth += (12 * m_iYear); + m_iYear = 0; + } + if (m_iMonth > 0) + { + m_iDay += (30 * m_iMonth); + m_iMonth = 0; + } +} + +//--------------------------------------------------------------------- + +t_bool +Julian_Duration::isZeroLength() +{ + if (m_iYear <= 0 && m_iMonth <= 0 && m_iDay <= 0 && + m_iHour <= 0 && m_iMinute <= 0 && m_iSecond <= 0 && + m_iWeek <= 0) + return TRUE; + else + return FALSE; +} + +//--------------------------------------------------------------------- + +UnicodeString Julian_Duration::toString() +{ + char sBuf[100]; + char sBuf2[100]; + + sBuf[0] = '\0'; + + if (m_iWeek != 0) + sprintf(sBuf, "%d weeks", getWeek()); + else + { + // Full form + + // eyork Still looking into Libnls to see if strings for year, month, etc are there + if (getYear() != 0) { sprintf(sBuf2, getYear() > 1 ? "%d years " : "%d year ", getYear()); strcat(sBuf, sBuf2); } + if (getMonth() != 0) { sprintf(sBuf2, getMonth() > 1 ? "%d months " : "%d month ", getMonth()); strcat(sBuf, sBuf2); } + if (getDay() != 0) { sprintf(sBuf2, getDay() > 1 ? "%d days " : "%d day ", getDay()); strcat(sBuf, sBuf2); } + if (getHour() != 0) { sprintf(sBuf2, getHour() > 1 ? "%d hours " : "%d hour ", getHour()); strcat(sBuf, sBuf2); } + if (getMinute() != 0) { sprintf(sBuf2, getMinute() > 1 ? "%d minutes " : "%d minute ", getMinute()); strcat(sBuf, sBuf2); } + if (getSecond() != 0) { sprintf(sBuf2, getSecond() > 1 ? "%d seconds " : "%d second ", getSecond()); strcat(sBuf, sBuf2); } + + /* + sprintf(sBuf, + "%d year, %d month , %d day, %d hour, %d mins, %d secs", + m_iYear, m_iMonth, m_iDay, m_iHour, m_iMinute, m_iSecond); + */ + } + return sBuf; + // return toICALString(); +} + +//--------------------------------------------------------------------- + +UnicodeString Julian_Duration::toICALString() +{ + //if (FALSE) TRACE("toString: %d W, %d Y %d M %d D T %d H %d M %d S\r\n", m_iYear, m_iMonth, m_iDay, m_iHour, m_im_iMinute, m_iSecond); + + + if (!isValid()) + { + return "INVALID_DURATION"; + //sOut = "PT-1H"; + //return sOut; + } + else if (m_iWeek != 0) + { + char sNum[20]; + sprintf(sNum, "%sP%dW", ((m_NegativeDuration) ? "-" : ""), m_iWeek); + return sNum; + } + else + { + +#if 1 + // full form + char sNum[100]; +#if JULIAN_DURATION_PARSING_YEAR_AND_MONTH + sprintf(sNum, "%sP%dY%dM%dDT%dH%dM%dS", + ((m_NegativeDuration) ? "-" : ""), m_iYear, m_iMonth, m_iDay, m_iHour, m_iMinute, m_iSecond); +#else + unnormalize(); + sprintf(sNum, "%sP%dDT%dH%dM%dS", + ((m_NegativeDuration) ? "-" : ""), m_iDay, m_iHour, m_iMinute, m_iSecond); +#endif + return sNum; +#else + + // condensed form + UnicodeString sOut; + UnicodeString sDate = "", sTime = ""; + t_int32 aiDate[] = { m_iYear, m_iMonth, m_iDay }; + char asDate[] = { 'Y', 'M', 'D' }; + t_int32 aiTime[] = { m_iHour, m_iMinute, m_iSecond }; + char asTime[] = { 'H', 'M', 'S' }; + t_int32 kSize = 3; + int i; + + for (i = 0; i < kSize ; i++) { + if (aiDate[i] != 0) { + char sNum[20]; + sprintf(sNum, "%d", aiDate[i]); + sDate += sNum; + sDate += asDate[i]; + } + } + for (i = 0; i < kSize ; i++) { + if (aiTime[i] != 0) { + char sNum[20]; + sprintf(sNum, "%d", aiTime[i]); + sTime += sNum; + sTime += asTime[i]; + } + } + if (sTime.size() > 0) { + sTime.insert(0, "T"); + } + sOut = sDate; + sOut += sTime; + + if (sOut.size() > 0) { + sOut.insert(0, "P"); + if (m_NegativeDuration) + sOut.insert(0, "-"); + } + + return sOut; + +#endif + } +} + +//--------------------------------------------------------------------- + +t_bool Julian_Duration::isValid() +{ + if (m_iYear < 0 || m_iMonth < 0 || m_iDay < 0 || + m_iHour < 0 || m_iMinute < 0 || m_iSecond < 0 || + m_iWeek < 0) + return FALSE; + else return TRUE; +} +//--------------------------------------------------------------------- + +//////////////////////////////////// +// OVERLOADED OPERATORS +//////////////////////////////////// + +//--------------------------------------------------------------------- + +const Julian_Duration & Julian_Duration::operator=(const Julian_Duration& d) +{ + m_iYear = d.m_iYear; + m_iMonth = d.m_iMonth; + m_iDay = d.m_iDay; + m_iHour = d.m_iHour; + m_iMinute = d.m_iMinute; + m_iSecond = d.m_iSecond; + m_iWeek = d.m_iWeek; + m_NegativeDuration = d.m_NegativeDuration; + + return *this; +} + +//--------------------------------------------------------------------- + +t_bool Julian_Duration::operator==(const Julian_Duration & that) +{ + return (compareTo(that) == 0); +} + +//--------------------------------------------------------------------- + +t_bool Julian_Duration::operator!=(const Julian_Duration & that) +{ + return (compareTo(that) != 0); +} + +//--------------------------------------------------------------------- + diff --git a/calendar/modules/util/src/jatom.cpp b/calendar/modules/util/src/jatom.cpp new file mode 100644 index 00000000000..9160be4d3bd --- /dev/null +++ b/calendar/modules/util/src/jatom.cpp @@ -0,0 +1,54 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +// jatom.cpp +// John Sun +// 4:37 PM February 27 1998 + + +#include "stdafx.h" +#include "jdefines.h" +#include "jatom.h" + +#include + +//--------------------------------------------------------------------- + +JAtom::JAtom() +{ + m_HashCode = -1; +} + +//--------------------------------------------------------------------- + +void +JAtom::setString(const UnicodeString & string) +{ + //m_String = string; + m_HashCode = string.hashCode(); +} + +//--------------------------------------------------------------------- + +JAtom::JAtom(const UnicodeString & string) +{ + //m_String = string; + m_HashCode = string.hashCode(); +} +//--------------------------------------------------------------------- + diff --git a/calendar/modules/util/src/jlog.cpp b/calendar/modules/util/src/jlog.cpp new file mode 100644 index 00000000000..25b42a10f67 --- /dev/null +++ b/calendar/modules/util/src/jlog.cpp @@ -0,0 +1,231 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +// jlog.cpp +// John Sun +// 10:52 AM March 2 1998 + +#include "stdafx.h" +#include "jdefines.h" +#include +#include "jlog.h" +#include "jlogerr.h" +#include "jlogvctr.h" + +//--------------------------------------------------------------------- + +const t_int32 JLog::m_DEFAULT_LEVEL = 200; +const char * JLog::m_DEFAULT_FILENAME = "JLog.txt"; + +//--------------------------------------------------------------------- +t_bool JLog::addErrorToVector(JulianLogError * error) +{ + t_bool status = FALSE; + if (m_CurrentEventLogVctr == 0) + { + addEventErrorEntry(); + } + if (m_CurrentEventLogVctr != 0) + { + if (error->getPriority() >= m_Level) + { + m_CurrentEventLogVctr->AddError(error); + status = TRUE; + } + } + return status; +} +//--------------------------------------------------------------------- + +JLog::JLog(t_int32 initLevel) : + m_Level(initLevel), + m_FileName(0), + m_WriteToString(TRUE), + m_ErrorVctr(0), + m_CurrentEventLogVctr(0), + m_Stream(0) +{ +} + +//--------------------------------------------------------------------- + +JLog::JLog(const char * initFileName, t_int32 initLevel) : + m_Level(initLevel), + m_FileName(initFileName), + m_WriteToString(FALSE), + m_ErrorVctr(0), + m_CurrentEventLogVctr(0), + m_Stream(0) +{ + m_Stream = fopen(m_FileName, "w"); + assert(m_Stream != 0); +} + +//--------------------------------------------------------------------- + +JLog::~JLog() +{ + if (m_ErrorVctr != 0) + { + JulianLogErrorVector * evtLogVctr = 0; + t_int32 i = 0; + for (i = m_ErrorVctr->GetSize() - 1; i >= 0; i--) + { + evtLogVctr = (JulianLogErrorVector *) m_ErrorVctr->GetAt(i); + delete evtLogVctr; + } + delete m_ErrorVctr; m_ErrorVctr = 0; + } + if (m_Stream != 0) + fclose(m_Stream); +} +//--------------------------------------------------------------------- + +void JLog::addEventErrorEntry() +{ + if (m_ErrorVctr == 0) + { + m_ErrorVctr = new JulianPtrArray(); + } + if (m_ErrorVctr != 0) + { + JulianLogErrorVector * evtVctr = 0; + evtVctr = new JulianLogErrorVector(); + if (evtVctr != 0) + { + m_ErrorVctr->Add(evtVctr); + m_CurrentEventLogVctr = evtVctr; + } + } +} + +//--------------------------------------------------------------------- + +void JLog::setCurrentEventLogValidity(t_bool b) +{ + if (m_CurrentEventLogVctr != 0) + { + m_CurrentEventLogVctr->SetValid(b); + } +} + +//--------------------------------------------------------------------- + +void JLog::setCurrentEventLogComponentType(JulianLogErrorVector::ECompType iComponentType) +{ + if (m_CurrentEventLogVctr != 0) + { + m_CurrentEventLogVctr->SetComponentType(iComponentType); + } +} +//--------------------------------------------------------------------- +#if 0 +void JLog::setUIDRecurrenceID(UnicodeString & uid, UnicodeString & rid) +{ + if (m_CurrentEventLogVctr != 0) + { + m_CurrentEventLogVctr->SetUID(uid); + m_CurrentEventLogVctr->SetRecurrenceID(rid); + } +} +#else +void JLog::setUID(UnicodeString & uid) +{ + if (m_CurrentEventLogVctr != 0) + { + m_CurrentEventLogVctr->SetUID(uid); + } +} +#endif +//--------------------------------------------------------------------- + +JulianPtrArray * +JLog::getEventErrorLog(t_int32 index) const +{ + if (index < 0) + return 0; + else if (m_ErrorVctr == 0) + return 0; + else if (m_ErrorVctr->GetSize() < index) + return 0; + else + return ((JulianPtrArray *) m_ErrorVctr->GetAt(index)); +} + +//--------------------------------------------------------------------- +#if 0 +JulianLogIterator * +JLog::createIterator(JLog * aLog, JulianLogErrorVector::ECompType iComponentType, t_bool bValid) +{ + if (aLog->GetErrorVector() == 0) + return 0; + else + return JulianLogIterator::createIterator(aLog->GetErrorVector(), iComponentType, bValid); +} +#endif +//--------------------------------------------------------------------- +void JLog::logError(const t_int32 errorID, t_int32 level) +{ + UnicodeString u, v, w; + logError(errorID, u, v, w, level); +} + //--------------------------------------------------------------------- + +void JLog::logError(const t_int32 errorID, + UnicodeString & comment, t_int32 level) +{ + UnicodeString u, v; + logError(errorID, comment, u, v, level); +} +//--------------------------------------------------------------------- + +void JLog::logError(const t_int32 errorID, + UnicodeString & propName, UnicodeString & propValue, + t_int32 level) +{ + UnicodeString u; + logError(errorID, propName, propValue, u, level); +} + +//--------------------------------------------------------------------- + +void JLog::logError(const t_int32 errorID, + UnicodeString & propName, + UnicodeString & paramName, + UnicodeString & paramValue, + t_int32 level) +{ + JulianLogError * error = 0; + UnicodeString shortReturnStatus = "3.0"; + UnicodeString offendingData; + + offendingData += propName; offendingData += ':'; offendingData += paramName; + offendingData += ':'; offendingData += paramValue; + error = new JulianLogError(errorID, shortReturnStatus, offendingData, level); + if (error != 0) + { + t_bool bAdded; + bAdded = addErrorToVector(error); + if (!bAdded) + { + delete error; error = 0; + } + } +} + +//--------------------------------------------------------------------- diff --git a/calendar/modules/util/src/jlogerr.cpp b/calendar/modules/util/src/jlogerr.cpp new file mode 100644 index 00000000000..704939c5a5f --- /dev/null +++ b/calendar/modules/util/src/jlogerr.cpp @@ -0,0 +1,60 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the 'NPL'); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an 'AS IS' basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +/* + * jlogerr.cpp + * John Sun + * 6/22/98 2:46:34 PM + */ +#include "stdafx.h" +#include "jdefines.h" +#include "jlogerr.h" + +//--------------------------------------------------------------------- +#if 0 +JulianLogError::JulianLogError(UnicodeString & errorString, + t_int32 errorPriority) +{ + m_ErrorString = errorString; + m_Priority = errorPriority; + //m_ID = errorID; +} +#endif +//--------------------------------------------------------------------- +JulianLogError::JulianLogError(t_int32 errorID, + UnicodeString & shortReturnStatusCode, + UnicodeString & offendingData, + t_int32 errorPriority) +{ + m_ErrorID = errorID; + m_ShortReturnStatusCode = shortReturnStatusCode; + m_OffendingData = offendingData; + m_Priority = errorPriority; +} +//--------------------------------------------------------------------- +void JulianLogError::deleteJulianLogErrorVector(JulianPtrArray * errors) +{ + if (errors != 0) + { + t_int32 i; + for (i = errors->GetSize() - 1; i >= 0; i--) + { + delete ((JulianLogError *) errors->GetAt(i)); + } + } +} diff --git a/calendar/modules/util/src/jlogitr.cpp b/calendar/modules/util/src/jlogitr.cpp new file mode 100644 index 00000000000..bf2499bbbf5 --- /dev/null +++ b/calendar/modules/util/src/jlogitr.cpp @@ -0,0 +1,101 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the 'NPL'); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an 'AS IS' basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ +/* + * jlogitr.cpp + * John Sun + * 8/17/98 6:30:56 PM + */ + +#include "stdafx.h" +#include "jdefines.h" +#include +#include "jlogitr.h" + +//--------------------------------------------------------------------- +JulianLogIterator::JulianLogIterator(JulianPtrArray * toIterate, + JulianLogErrorVector::ECompType iComponentType, + t_bool bValid): +m_LogToIterateOver(toIterate), +m_iComponentType(iComponentType), +m_bValid(bValid) +{ +} +//--------------------------------------------------------------------- + + +JulianLogIterator::JulianLogIterator() +{ +} + +//--------------------------------------------------------------------- + +JulianLogIterator * +JulianLogIterator::createIterator(JulianPtrArray * toIterate, + JulianLogErrorVector::ECompType iComponentType, + t_bool bValid) +{ + if (toIterate == 0) + return 0; + else + return new JulianLogIterator(toIterate, iComponentType, bValid); +} + +//--------------------------------------------------------------------- + +JulianLogErrorVector * +JulianLogIterator::firstElement() +{ + return findNextElement(0); +} + +//--------------------------------------------------------------------- + +JulianLogErrorVector * +JulianLogIterator::nextElement() +{ + return findNextElement(++m_iIndex); +} + +//--------------------------------------------------------------------- + +JulianLogErrorVector * +JulianLogIterator::findNextElement(t_int32 startIndex) +{ + if (m_LogToIterateOver != 0) + { + JulianLogErrorVector * errVctr = 0; + t_int32 i; + for (i = startIndex; i < m_LogToIterateOver->GetSize(); i++) + { + errVctr = (JulianLogErrorVector *) m_LogToIterateOver->GetAt(i); + if ((errVctr->GetComponentType() == m_iComponentType) && + (errVctr->IsValid() == m_bValid)) + { + m_iIndex = i; + return errVctr; + } + } + } + return 0; +} + +//--------------------------------------------------------------------- + + + + diff --git a/calendar/modules/util/src/jlogvctr.cpp b/calendar/modules/util/src/jlogvctr.cpp new file mode 100644 index 00000000000..5c13bec72cf --- /dev/null +++ b/calendar/modules/util/src/jlogvctr.cpp @@ -0,0 +1,59 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the 'NPL'); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an 'AS IS' basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ +/* + * jlogvctr.cpp + * John Sun + * 8/17/98 4:48:46 PM + */ + +#include "stdafx.h" +#include "jdefines.h" +#include "jlogvctr.h" + +//--------------------------------------------------------------------- +JulianLogErrorVector::JulianLogErrorVector() +{ + m_ICalComponentType = ECompType_NSCALENDAR; + m_ErrorVctr = 0; + m_bValidEvent = TRUE; +} +//--------------------------------------------------------------------- +JulianLogErrorVector::JulianLogErrorVector(ECompType iICalComponentType) +{ + m_ICalComponentType = iICalComponentType; + m_ErrorVctr = 0; + m_bValidEvent = TRUE; +} +//--------------------------------------------------------------------- +JulianLogErrorVector::~JulianLogErrorVector() +{ + if (m_ErrorVctr != 0) + { + JulianLogError::deleteJulianLogErrorVector(m_ErrorVctr); + delete m_ErrorVctr; m_ErrorVctr = 0; + } +} +//--------------------------------------------------------------------- +void JulianLogErrorVector::AddError(JulianLogError * error) +{ + if (m_ErrorVctr == 0) + m_ErrorVctr = new JulianPtrArray(); + if (m_ErrorVctr != 0) + m_ErrorVctr->Add(error); +} +//--------------------------------------------------------------------- diff --git a/calendar/modules/util/src/julnstr.cpp b/calendar/modules/util/src/julnstr.cpp new file mode 100644 index 00000000000..48e731d8ade --- /dev/null +++ b/calendar/modules/util/src/julnstr.cpp @@ -0,0 +1,1046 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +/* -*- Mode: C++; tab-width: 4 -*- + * JulianString.cpp: implementation of the JulianString class + * Copyright © 1998 Netscape Communications Corporation, all rights reserved. + * Steve Mansour + */ + +#ifndef MOZ_TREX +#include "xp.h" +#include "fe_proto.h" +#endif + +#include "nspr.h" +#ifdef NSPR20 +#include "plstr.h" +#endif + +#if 0 +/* Breaks SINIX5.4 build */ +#include +#endif +#include "jdefines.h" +#include "julnstr.h" + +#ifndef MOZ_TREX +#include "xp.h" +#include "fe_proto.h" +#include "julianform.h" +#include "xpgetstr.h" +#define WANT_ENUM_STRING_IDS +#include "allxpstr.h" + +#define PL_strncpy strncpy +#define PR_Free XP_FREE +#define PR_Malloc XP_ALLOC +#endif + +#ifndef XP_STRCASECMP + #define XP_STRCASECMP strcasecmp +#endif + +#ifndef XP_MAC + #define XP_ASSERT(a) +#endif +#define NOT_NULL(X) X + +#ifndef MOZ_TREX +extern "C" XP_Bool bCallbacksSet; +extern "C" pJulian_Form_Callback_Struct JulianForm_CallBacks; +#endif + +/* + * Stolen routines (from netparse.c) to keep the containing dll free of dependencies... + */ +static char *PRIVATE_NET_EscapeBytes (const char * str, int32 len, int mask, int32 * out_len); +static int PRIVATE_NET_UnEscapeCnt (char * str); +#define URL_XALPHAS (unsigned char) 1 +#define URL_XPALPHAS (unsigned char) 2 +#define URL_PATH (unsigned char) 4 +#define HEX_ESCAPE '%' +#define UNHEX(C) \ + ((C >= '0' && C <= '9') ? C - '0' : \ + ((C >= 'A' && C <= 'F') ? C - 'A' + 10 : \ + ((C >= 'a' && C <= 'f') ? C - 'a' + 10 : 0))) + +/** + * Empty constructor: JulianString x; + */ +JulianString::JulianString() +{ + m_iStrlen = 0; + m_HashCode = 0; + m_iGrowBy = 32; + m_pBuf = new char[ m_iBufSize = m_iGrowBy ]; + m_pBuf[0] = 0; +} + +/** + * JulianString x("hello, world"); + */ +JulianString::JulianString(const char* p, size_t iGrowBy) +{ + m_iStrlen = XP_STRLEN(p); + m_pBuf = new char[ m_iBufSize = m_iStrlen + 1 + iGrowBy ]; + XP_MEMCPY(m_pBuf,p,m_iStrlen); + m_pBuf[m_iStrlen] = 0; + m_HashCode = 0; + m_iGrowBy = iGrowBy; +} + +/** + * JulianString x("hello, world"); + * JulianString y(x); + */ +JulianString::JulianString( const JulianString& s, size_t iGrowBy ) +{ + m_pBuf = new char[ m_iBufSize = s.m_iBufSize ]; + m_iStrlen = s.m_iStrlen; + XP_MEMCPY(m_pBuf,s.m_pBuf,m_iBufSize); + m_HashCode = 0; + m_iGrowBy = iGrowBy; +} + +/** + * JulianString x(2048); + */ +JulianString::JulianString(size_t iSize, size_t iGrowBy) +{ + m_pBuf = new char[ m_iBufSize = iSize ]; + m_iStrlen = 0; + *m_pBuf = 0; + m_HashCode = 0; + m_iGrowBy = iGrowBy; +} + +JulianString::~JulianString() +{ + delete [] m_pBuf; +} + +/** + * return the character at the supplied index. If + * index is negative, the characters are indexed from the right + * side of the string. That is: + * + *
+ *   JulianString x("012345");
+ *   x[2] returns '2'
+ *   x[-1] returns '5'
+ * 
+ * + * If iIndex is > than the string length, the last character + * will be returned. If iIndex is < the negative of the last + * character, the first character will be returned. + * + * @param iIndex index of first character of the sub + * @return a character + */ +char JulianString::operator[](int32 iIndex) +{ + if (iIndex >= 0) + { + if (iIndex < (int32) m_iStrlen) + return m_pBuf[iIndex]; + iIndex = m_iStrlen-1; + } + else + { + iIndex = m_iStrlen + iIndex; + } + if (iIndex < 0) + iIndex = 0; + return m_pBuf[iIndex]; +} + +/** + * return a JulianString that is the substring defined by + * the two supplied indeces. If either index is negative + * the return value is an empty string. If i is greater + * than j the return value is an empty string. If i is + * past the end of the string the return value is an + * empty string. If j is past the end of the string then + * the return value is the string from i to the end of + * the string. Examples: + * + *
+ *   JulianString x("012345");
+ *   x.indexSubstr(2,4) returns a JulianString containing "234"
+ * 
+ * + * @param i index of first character of the sub + * @param j index of the last character of the sub + * @return a JulianString + */ +JulianString JulianString::indexSubstr(int32 i, int32 j) +{ + if ( i < 0 || j < 0 ) + return ""; + + if ( i > j ) + return ""; + + if (i+1 > (int32)m_iStrlen) + return ""; + + if (j+1 > (int32)m_iStrlen) + j = m_iStrlen -1; + + return (*this)(i,j-i+1); +} + + +/** + * create a substring from the supplied index and count. If the + * index is negative, the characters are indexed from the right + * side of the string. That is: + * + *
+ *   JulianString x("012345");
+ *   x(2,3) returns a JulianString containing "234"
+ *   x(-2,2) returns a JulianString containing "45"
+ *
+ * @param iIndex  index of first character of the sub
+ * @param iCount  number of characters to copy
+ * @return        a substring
+ */
+JulianString JulianString::operator()(int32 iIndex, int32 iCount)
+{
+    /*
+     * Validate args...
+     */
+    if (iIndex >= 0)
+    {
+        XP_ASSERT(iIndex < m_iStrlen);
+        if ((long)iIndex >= (long)m_iStrlen)
+            iIndex = m_iStrlen - 1;
+        XP_ASSERT((long)(iCount + iIndex) <= (long)m_iStrlen);
+        if ((long)(iIndex + iCount) > (long)m_iStrlen)
+            iCount = m_iStrlen - iIndex;
+    }
+    else
+    {
+        XP_ASSERT(iIndex > -(long)m_iStrlen);
+        if ((long)iIndex <= -(long)m_iStrlen)
+            iIndex = 1 - m_iStrlen;
+        XP_ASSERT( 0 >= iCount + iIndex);
+        if (0 < iCount + iIndex )
+            iCount = - iIndex;
+    }
+
+    /*
+     * extract the substring...
+     */
+    char* s1 = m_pBuf;
+    if (iIndex < 0)
+        iIndex += m_iStrlen;
+
+    int32 iNumLeft = m_iStrlen - iIndex;
+    if (iCount > iNumLeft || iCount < 0)
+        iCount = iNumLeft;
+
+    JulianString Str(iCount + 1);
+
+    if (Str.IsValid())
+    {
+        XP_MEMCPY(Str.m_pBuf,s1 + iIndex, iCount);
+        Str.m_pBuf[iCount] = 0;
+        Str.m_iStrlen = iCount;
+    }
+
+    return Str.GetBuffer();
+}
+
+/**
+ *  Replace the substring from index m to n with the supplied
+ *  string. Any index less than 0 will be snapped to 0. Any
+ *  index > than the last index in the current string will be
+ *  snapped to the last index.  If the current string is empty
+ *  or uninitialized, it is simply set to the value of *p.
+ *  If m > n the values are swapped.
+ *
+ *  @param m  starting index of substring
+ *  @param n  ending index of substring
+ *  @param p  string to insert
+ *  @return   *this
+ */
+JulianString& JulianString::Replace(int32 m, int32 n, char* p)
+{
+  /*
+   * A few sanity checks first...
+   */
+  if (m_iStrlen <= 0)
+  {
+    (*this) = p;
+    return *this;
+  }
+  if (m < 0)
+    m = 0;
+  if (n < 0)
+    n = 0;
+  if ((size_t)(m+1) >= m_iStrlen)
+    m = m_iStrlen - 1;
+  if ((size_t)(n+1) >= m_iStrlen)
+    n = m_iStrlen - 1;
+  if (m > n)
+  {
+    int32 t = m;
+    m = n;
+    n = t;
+  }
+
+  /*
+   * Replace from m to n with p
+   */
+  JulianString s = "";
+  JulianString stemp;
+
+  if (m > 0)
+    s = Left(m);
+  s += p;
+  stemp = Right(m_iStrlen - n - 1); /* fixed warning */
+  s += stemp;
+
+  (*this) = s;
+  return *this;
+}
+
+/**
+ *  Replace the substring from index m to n with the supplied
+ *  string. Any index less than 0 will be snapped to 0. Any
+ *  index > than the last index in the current string will be
+ *  snapped to the last index.  If the current string is empty
+ *  or uninitialized, it is simply set to the value of *p.
+ *  If m > n the values are swapped.
+ *
+ *  @param m  starting index of substring
+ *  @param n  ending index of substring
+ *  @param p  string to insert
+ *  @return   *this
+ */
+JulianString& JulianString::Replace(int32 m, int32 n, JulianString& p)
+{
+  return Replace(m,n, p.GetBuffer());
+}
+
+/**
+ * return the leftmost n characters as a substring. If
+ * n is < 0 it is the same as calling Right(n).
+ *
+ * Examples:
+ *
+ * 
+ *   JulianString x("012345");
+ *   x.Left(4) returns a JulianString containing "0123"
+ *   x.Left(-4) returns a JulianString containing "2345"
+ * 
+ * + * @param n number of characters to return + * @return a JulianString + */ +JulianString JulianString::Left(int32 n) +{ + if (n < 0) + return Right(-n); + return (*this)(0,n); +} + +/** + * return the rightmost n characters as a substring. If + * n is < 0 it is the same as calling Left(n). + * + * Examples: + * + *
+ *   JulianString x("012345");
+ *   x.Right(4) returns a JulianString containing "2345"
+ *   x.Right(-4) returns a JulianString containing "0123"
+ * 
+ * + * @param n number of characters to return + * @return a JulianString + */ +JulianString JulianString::Right(int32 n) +{ + if (n < 0) + return Left(-n); + if (0 >= m_iStrlen) + return ""; + if ((size_t)n > m_iStrlen ) + n = m_iStrlen; + + return (*this)(m_iStrlen-n,n); +} + +/** + * Copy the supplied null terminated string into *this. + * @param s the character array to be copied. + * @return a reference to *this + */ +JulianString& JulianString::operator=(const char* s) +{ + m_iStrlen = XP_STRLEN(s); + size_t iLen = m_iStrlen + 1; + if (iLen > m_iBufSize) + ReallocTo(iLen); + if (IsValid()) + { + XP_MEMCPY(m_pBuf,s,iLen); + m_HashCode = 0; + } + return *this; +} + +/** + * Copy the supplied JulianString into *this. + * @param s the string to be copied. + * @return a reference to *this + */ +const JulianString& JulianString::operator=(const JulianString& s) +{ + if (s.m_iStrlen + 1 > m_iBufSize) + ReallocTo(s.m_iStrlen+1); + XP_MEMCPY(m_pBuf,s.m_pBuf,s.m_iStrlen + 1 ); + m_iStrlen = s.m_iStrlen; + m_HashCode = 0; + return *this; +} + +/** + * Verify that there is enough room to hold iLen bytes in + * the current buffer. If not, reallocate the buffer. This + * routine does not copy the old contents into the new buffer. + * + * @param iLen the size of the buffer needed + */ +void JulianString::ReallocTo(size_t iLen) +{ + if (m_iBufSize >= iLen) + return; + delete [] m_pBuf; + m_pBuf = new char[m_iBufSize = iLen + m_iGrowBy]; +} + +/** + * Verify that there is enough room to hold iLen bytes in + * the current buffer. If not, reallocate the buffer. Copy + * the old contents into the new buffer. + * + * @param iLen the size of the buffer needed + */ +void JulianString::Realloc(size_t iLen) +{ + if (m_iBufSize >= iLen) + return; + char* p = new char[m_iBufSize = iLen + m_iGrowBy]; + if (p) + { + XP_MEMCPY(p,m_pBuf,m_iStrlen); + p[m_iStrlen] = 0; + } + else + { + m_iBufSize = m_iStrlen = 0; + } + delete [] m_pBuf; + m_pBuf = p; + m_HashCode = 0; +} + +/** + * When the string length changes, presumably through + * external use of GetBuffer(), the internal string length + * is set by calling this method. Also, the hash code is + * reset since we have no idea what was done to the string. + */ +void JulianString::DoneWithBuffer() +{ + m_iStrlen = XP_STRLEN(m_pBuf); + m_HashCode = 0; +} + +/** + * Find the first occurrence of a string within this string + * @param p the string to search for + * @param i the offset within this string to begin the search + * @return the index where the string was found. -1 means + * the string was not found. + */ +int32 JulianString::Find(const char* p, int32 i) const +{ + char* pRet = XP_STRSTR(&m_pBuf[i],p); + if (0 == pRet) + return -1; + return (int32)(i + pRet - &m_pBuf[i]); +} + +/** + * Find the first occurrence of a character within this string + * @param c the character to search for + * @param i the offset within this string to begin the search + * @return the index where the string was found. -1 means + * the string was not found. + */ +int32 JulianString::Find(char c, int32 i) const +{ + char* pRet = XP_STRCHR(&m_pBuf[i],c); + if (0 == pRet) + return -1; + return (int32)(i + pRet - &m_pBuf[i]); +} + +#ifdef MOZ_TREX +/** + * Find the last occurrence of a character within a string + * @param c the character to search for + * @param i index of the beginning of the string + * @return the index where the string was found. -1 means + * the string was not found. + */ +int32 JulianString::RFind(char c, int32 i) const +{ + char* pRet = PL_strrchr(&m_pBuf[i],c); + if (0 == pRet) + return -1; + return (int32)(i + pRet - &m_pBuf[i]); +} + +/** + * Find the last occurrence of a string within this string + * @param p the string to search for + * @param i the offset within this string to begin the search + * @return the index where the string was found. -1 means + * the string was not found. + */ +int32 JulianString::RFind(const char* p, int32 i) const +{ + char* pRet = PL_strrstr(&m_pBuf[i],p); + if (0 == pRet) + return -1; + return (int32)(i + pRet - &m_pBuf[i]); +} +#endif + +/** + * Concatenate two strings and return the result. + * @param s1 one of the strings to concatenate + * @param s2 the other string to concatenate + * @return the concatenated string. + */ +JulianString JulianString::operator+(JulianString& s2) +{ + JulianString s(m_iStrlen + s2.m_iStrlen + 1); + s = *this; + s += s2; + return s; +} + +/** + * Append the supplied string to *this + * @param s the string to append + * @return a reference to *this + */ +JulianString& JulianString::operator+=(const char* s) +{ + size_t iLen = XP_STRLEN(s); + Realloc(iLen + m_iStrlen + 1); + if (IsValid()) + { + XP_MEMCPY(&m_pBuf[m_iStrlen],s,iLen); + m_iStrlen += iLen; + m_pBuf[m_iStrlen] = 0; + } + else + { + m_iStrlen = m_iBufSize = 0; + } + m_HashCode = 0; + return *this; +} + +/** + * Append the supplied string to *this + * @param s the string to append + * @return a reference to *this + */ +JulianString& JulianString::operator+=(JulianString& s) +{ + Realloc(s.m_iStrlen + m_iStrlen + 1); + XP_MEMCPY(&m_pBuf[m_iStrlen],s.m_pBuf,s.m_iStrlen); + m_iStrlen += s.m_iStrlen; + m_pBuf[m_iStrlen] = 0; + m_HashCode = 0; + return *this; +} + +/** + * Prepend the supplied string to *this + * @param s the string to append + * @return a reference to *this + */ +JulianString& JulianString::Prepend(const char* s) +{ + size_t iLen = XP_STRLEN(s); + Realloc(iLen + m_iStrlen + 1); + if (IsValid()) + { + XP_MEMMOVE(&m_pBuf[iLen],m_pBuf,m_iStrlen); + XP_MEMCPY(m_pBuf,s,iLen); + m_iStrlen += iLen; + m_pBuf[m_iStrlen] = 0; + } + else + { + m_iStrlen = m_iBufSize = 0; + } + m_HashCode = 0; + return *this; +} + +/** + * Prepend the supplied string to *this + * @param s the string to append + * @return a reference to *this + */ +JulianString& JulianString::Prepend(JulianString& s) +{ + return Prepend(s.m_pBuf); +} + +/** + * compare the supplied string to *this + * @param p the string to compare to *this + * @return -1 if the supplied string is lexicographically + * less than *this, 0 if they are equal, and 1 if + * the supplied string is greater than *this. + */ +int32 JulianString::CompareTo(const char* p, XP_Bool iIgnoreCase) const +{ + if (iIgnoreCase) +#ifndef XP_MAC + return strcasecomp(p,m_pBuf); +#else + return XP_STRCMP(p,m_pBuf); +#endif + else + return XP_STRCMP(p,m_pBuf); +} + +int32 JulianString::CompareTo(JulianString& s, XP_Bool iIgnoreCase) const +{ + if (iIgnoreCase) +#ifndef XP_MAC + return strcasecomp(s.m_pBuf,m_pBuf); +#else + return XP_STRCMP(s.m_pBuf,m_pBuf); +#endif + else + return XP_STRCMP(s.m_pBuf,m_pBuf); +} + +/** + * Return the first index of the supplied string. + * @param p the string to look for + * @param iOffset offset within p to begin search + * @return -1 if the string is not found + * the offset if >= 0 + */ +int32 JulianString::IndexOf(const char* p, int32 iOffset) const +{ + char* q = &m_pBuf[iOffset]; + int32 iLen = XP_STRLEN(p); + char* pLoc = XP_STRSTR(q,p); + return (0 == pLoc) ? -1 : pLoc - m_pBuf; +} + +/** + * Starting at index i, find the first occurrence of any character + * in p. + * @param i the offset within this string to begin the search + * @param p pointer to a null terminated list of characters + * @return the index where the string was found. -1 means + * the string was not found. NOTE: the index is relative + * to the begining of the string, not relative to i. + */ +int32 JulianString::Strpbrk( int32 i, const char *p ) const +{ + char* q = &m_pBuf[i]; + char* r = PL_strpbrk( q, p ); + if (0 == r) + return -1; + return (int32)(r - m_pBuf); +} + +/** + * remove leading and trailing whitespace. + */ +void JulianString::Trim() +{ + char* pHead = m_pBuf; + char* pTail; + + if (0 == m_iStrlen) + return; + + for ( pHead = m_pBuf; *pHead && XP_IS_SPACE(*pHead); ++pHead ) + /* do nothing */ ; + + for ( pTail = &m_pBuf[m_iStrlen-1]; + pTail > pHead && XP_IS_SPACE(*pTail); + --pTail ) + /* do nothing */ ; + + pTail[1] = 0; + m_iStrlen = 1 + pTail - pHead; + if (m_pBuf != pHead) + { + XP_MEMMOVE(m_pBuf,pHead,m_iStrlen); + } + m_pBuf[m_iStrlen] = 0; + m_HashCode = 0; +} + +/** + * Upshift the string. The upshifting is based on toupper() + * in + */ +void JulianString::ToUpper() +{ + char* p; + for ( p = m_pBuf; *p; ++p ) + *p = (char) toupper(*p); + m_HashCode = 0; +} + +/** + * Downshift the string. The downshifting is based on tolower() + * in + */ +void JulianString::ToLower() +{ + char* p; + for ( p = m_pBuf; *p; ++p ) + *p = (char) tolower(*p); + m_HashCode = 0; +} + +#ifndef MOZ_TREX +/** + * Get String from Application resources + */ +char* JulianString::GetString(int i) +{ + if (PR_TRUE == bCallbacksSet) + return ((*JulianForm_CallBacks->GetString)(i)); + else + return NULL ; + +} + +/** + * Load String from Application resources into this JulianString + */ +JulianString& JulianString::LoadString(int i) +{ + if (PR_TRUE == bCallbacksSet) + { + JulianString aString((*JulianForm_CallBacks->GetString)(i)) ; + *this = aString ; + } + + return (*this) ; + +} +#endif + +#if 0 +/*Doesn't exist on BSD_3861.1 && SunOS4.1.3_U1 out for now*/ +/* + * stdout-type output + */ +ostream& operator<<(ostream& s, JulianString& x) +{ + return s << x.m_pBuf; +} + +/* + * stdin-type input. we don't really need this method... + */ +istream& operator>>(istream& s, JulianString& x) +{ + char sBuf[1024]; /* DANGER! fixed size buffer... */ + s >> sBuf; + x = sBuf; + return s; +} +#endif + +/** + * compare this string to a const char* + * @param p the string to compare to *this + * @return 1 if they are equal, 0 if not. + */ +int JulianString::operator==(const char* p) +{ + return XP_STRCMP(m_pBuf,p) == 0; +} + +/** + * compare this string to another + * @param p the JulianString to compare to *this + * @return 1 if they are equal, 0 if not. + */ +int JulianString::operator==(JulianString& y) +{ + return XP_STRCMP(m_pBuf,y.m_pBuf) == 0; +} + +/** + * netlib has a general function (netlib\modules\liburl\src\escape.c) + * which does url encoding. Since netlib is not yet available for raptor, + * the following will suffice. Convert space to +, don't convert alphanumeric, + * conver each non alphanumeric char to %XY where XY is the hexadecimal + * equavalent of the binary representation of the character. + */ +void JulianString::URLEncode() +{ + if (m_iStrlen <= 0) + return; + + int32 iNewLen=0; + char* pSave = m_pBuf; + char* p = PRIVATE_NET_EscapeBytes(m_pBuf, m_iStrlen, URL_XPALPHAS, &iNewLen); + if (iNewLen > 0) + { + if (m_iBufSize < (size_t)(iNewLen + 1)) + { + delete [] m_pBuf; + m_iBufSize = iNewLen + 1; + char *m_pBuf = new char[ m_iBufSize ]; + pSave = m_pBuf; + } + m_pBuf = pSave; + PL_strncpy(m_pBuf,p,m_iBufSize-1); + m_pBuf[m_iBufSize-1] = 0; + } + PR_Free(p); +} + +/** + * URLDecode + * @param p the string to compare to *this + * @return 0 if they are equal, 1 if not. + */ +void JulianString::URLDecode() +{ + PRIVATE_NET_UnEscapeCnt(m_pBuf); +} + + +/** + * compare this string to a char* + * @param p the string to compare to *this + * @return 0 if they are equal, 1 if not. + */ +int JulianString::operator!=(const char* y) +{ + return XP_STRCMP(m_pBuf,y) != 0; +} + +/** + * compare this string to a char* + * @param p the string to compare to *this + * @return 0 if they are equal, 1 if not. + */ +int JulianString::operator!=(JulianString& y) +{ + return XP_STRCMP(m_pBuf,y.m_pBuf) != 0; +} + +/** + * return the hash code. Calculate if needed. + * @return the hash code. + */ +int32 JulianString::HashCode() +{ + if (0 == m_iStrlen) + return 0; + + if (0 == m_HashCode) + { + int32 iInc = (m_iStrlen >= 128) ? m_iStrlen/64 : 1; + char* p = m_pBuf; + char* pLimit = &m_pBuf[m_iStrlen]; + + while ( p < pLimit ) + { + m_HashCode = (m_HashCode * 37) + ((int32) *p); + p += iInc; + } + + if (0 == m_HashCode) + ++m_HashCode; + } + + return m_HashCode; +} + +/* + * Lifted from xp_str.c since we are in DLL ... + */ +#if defined(XP_WIN32) || defined(MOZ_TREX) +PUBLIC int +strcasecomp (const char* one, const char* two) +{ + const char* pA; + const char* pB; + + for(pA=one, pB=two; *pA && *pB; pA++, pB++) + { +#ifdef MOZ_TREX + int tmp = tolower(*pA) - tolower(*pB); +#else + int tmp = XP_TO_LOWER(*pA) - XP_TO_LOWER(*pB); +#endif + if (tmp) + return tmp; + } + if (*pA) + return 1; + if (*pB) + return -1; + return 0; +} +#endif + + + + + +/* + * This code was lifted from netparse.c. We don't want a dependency + * on the net code in this class + */ + + +/* encode illegal characters into % escaped hex codes. + * + * mallocs and returns a string that must be freed + */ +static +int netCharType[256] = +/* Bit 0 xalpha -- the alphas +** Bit 1 xpalpha -- as xalpha but +** converts spaces to plus and plus to %20 +** Bit 3 ... path -- as xalphas but doesn't escape '/' +*/ + /* 0 1 2 3 4 5 6 7 8 9 A B C D E F */ + { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x */ + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 1x */ + 0,0,0,0,0,0,0,0,0,0,7,4,0,7,7,4, /* 2x !"#$%&'()*+,-./ */ + 7,7,7,7,7,7,7,7,7,7,0,0,0,0,0,0, /* 3x 0123456789:;<=>? */ + 0,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, /* 4x @ABCDEFGHIJKLMNO */ + /* bits for '@' changed from 7 to 0 so '@' can be escaped */ + /* in usernames and passwords in publishing. */ + 7,7,7,7,7,7,7,7,7,7,7,0,0,0,0,7, /* 5X PQRSTUVWXYZ[\]^_ */ + 0,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, /* 6x `abcdefghijklmno */ + 7,7,7,7,7,7,7,7,7,7,7,0,0,0,0,0, /* 7X pqrstuvwxyz{\}~ DEL */ + 0, }; + +#define IS_OK(C) (netCharType[((unsigned int) (C))] & (mask)) + +static char * +PRIVATE_NET_EscapeBytes (const char * str, int32 len, int mask, int32 * out_len) +{ + unsigned char *src; + unsigned char *dst; + char *result; + int32 i, extra = 0; + char *hexChars = "0123456789ABCDEF"; + + if(!str) + return(0); + + src = (unsigned char *) str; + for(i = 0; i < len; i++) + { + if (!IS_OK(src[i])) + extra+=2; /* the escape, plus an extra byte for each nibble */ + } + + if(!(result = (char *) PR_Malloc(len + extra + 1))) + return(0); + + dst = (unsigned char *) result; + for(i = 0; i < len; i++) + { + unsigned char c = src[i]; + if (IS_OK(c)) + { + *dst+= c; + } + else if(mask == URL_XPALPHAS && c == ' ') + { + *dst++ = '+'; /* convert spaces to pluses */ + } + else + { + *dst++ = HEX_ESCAPE; + *dst++ = hexChars[c >> 4]; /* high nibble */ + *dst++ = hexChars[c & 0x0f]; /* low nibble */ + } + } + + *dst = '\0'; /* tack on eos */ + if(out_len) + *out_len = dst - (unsigned char *) result; + return result; +} + +static int +PRIVATE_NET_UnEscapeCnt (char * str) +{ + register char *src = str; + register char *dst = str; + + while(*src) + if (*src != HEX_ESCAPE) + { + *dst++ = *src++; + } else { + src++; /* walk over escape */ + if (*src) + { + *dst = UNHEX(*src) << 4; + src++; + } + if (*src) + { + *dst = (*dst + UNHEX(*src)); + src++; + } + dst++; + } + + *dst = 0; + + return (int)(dst - str); + +} /* PRIVATE_NET_UnEscapeCnt */ diff --git a/calendar/modules/util/src/jutility.cpp b/calendar/modules/util/src/jutility.cpp new file mode 100644 index 00000000000..56e97a269b6 --- /dev/null +++ b/calendar/modules/util/src/jutility.cpp @@ -0,0 +1,173 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +#include "stdafx.h" + +#include "jdefines.h" +#include +#include "jutility.h" +#include "ptrarray.h" + +//--------------------------------------------------------------------- + +JulianUtility::JulianUtility() {} + +//--------------------------------------------------------------------- + +//t_int32 JulianUtility::atot_int32(const char * nPtr, +t_int32 JulianUtility::atot_int32(char * nPtr, + t_bool & bParseError, + t_int32 size) +{ + t_int32 i; + char * ptr = nPtr; + char c; + for (i = 0; i < size; i++) + { + if (!isdigit(*ptr)) + { + bParseError = TRUE; // or the ERROR to TRUE + break; + } + ptr++; + } + c = nPtr[size]; + nPtr[size] = '\0'; + i = atol(nPtr); + nPtr[size] = c; + return i; +} +//--------------------------------------------------------------------- +#if 0 +t_int32 JulianUtility::atot_int32(const char * nPtr, + t_bool & bParseError, + t_int32 size) +{ + t_int32 i; + const char * ptr = nPtr; + + for (i = 0; i < size; i++) + { + if (!isdigit(*ptr)) + { + bParseError |= TRUE; // or the ERROR to TRUE + break; + } + ptr++; + } + return atol(nPtr); +} +#endif +//--------------------------------------------------------------------- +t_bool JulianUtility::checkRange(t_int32 hashCode, JAtom range[], + t_int32 rangeSize) +{ + t_int32 i; + for (i = 0; i < rangeSize; i++) + { + if (range[i] == hashCode) + return TRUE; + } + return FALSE; +} + +//--------------------------------------------------------------------- + +void +JulianUtility::stripDoubleQuotes(UnicodeString & u) +{ + if (u.size() > 0) + { + if ('\"' == u[(TextOffset) (u.size() - 1)]) + { + u.remove((TextOffset)(u.size() - 1), 1); + } + if (u.size() > 0) + { + if ('\"' == u[(TextOffset) 0]) + { + u.remove(0, 1); + } + } + } +} + +//--------------------------------------------------------------------- + +UnicodeString & +JulianUtility::addDoubleQuotes(UnicodeString & us) +{ + if (us.size() != 0) + { + us += '\"'; + us.insert(0, "\""); + } + return us; +} + +//--------------------------------------------------------------------- +/* +char * JulianUtility::unistrToStr(const UnicodeString & us) +{ + return us.toCString(""); +} +*/ +//--------------------------------------------------------------------- +/* +UnicodeString & JulianUtility::ToUpper(const UnicodeString & eightBitString) +{ + t_int32 i; + // + char c; + for (i = 0; i < eightBitString.size(); i++) + { + c = (char) eightBitString[(TextOffset) i]; + if (islower(c)) + { + c = (char) toupper(c); + eightBitString.replace((TextOffset) i, 1, &c); + } + } + // + char * c = eightBitString.toCString(""); + for (i = 0; i < eightBitString.size(); i++) + { + if (islower(c[i])) + { + c[i] = (char) toupper(c[i]); + } + } + eightBitString = c; + return eightBitString; +} +*/ +//--------------------------------------------------------------------- + +/* +void JulianUtility::TRACE_DateTimeVector(JulianPtrArray & vector) +{ + for (i = 0; i < vector.GetSize(); i++) + { + DateTime * dt = (DateTime *) dateVector.GetAt(i); + if (TRUE) TRACE("dtVec[%d] = %s\r\n", i, dt->toISO8601().toCString("")); + } +} +*/ +//--------------------------------------------------------------------- + + diff --git a/calendar/modules/util/src/keyword.cpp b/calendar/modules/util/src/keyword.cpp new file mode 100644 index 00000000000..db10fe6e0d5 --- /dev/null +++ b/calendar/modules/util/src/keyword.cpp @@ -0,0 +1,1255 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +// keyword.cpp +// John Sun +// 3/19/98 9:49:32 AM + +#include "stdafx.h" +#include "jdefines.h" + +#include "keyword.h" +#include "jatom.h" + + +#ifdef XP_MAC +#pragma global_optimizer off // so that this damn file compiles +#endif + +//--------------------------------------------------------------------- + +JulianKeyword * JulianKeyword::m_Instance = 0; + +//--------------------------------------------------------------------- + +JulianKeyword::JulianKeyword() +{ + ms_sVCALENDAR = "VCALENDAR"; + ms_ATOM_VCALENDAR.setString(ms_sVCALENDAR); + + ms_sVEVENT = "VEVENT"; + ms_ATOM_VEVENT.setString(ms_sVEVENT); + + ms_sVTODO = "VTODO"; + ms_ATOM_VTODO.setString(ms_sVTODO); + + ms_sVJOURNAL = "VJOURNAL"; + ms_ATOM_VJOURNAL.setString(ms_sVJOURNAL); + + ms_sVFREEBUSY = "VFREEBUSY"; + ms_ATOM_VFREEBUSY.setString(ms_sVFREEBUSY); + + ms_sVTIMEZONE = "VTIMEZONE"; + ms_ATOM_VTIMEZONE.setString(ms_sVTIMEZONE); + + ms_sVALARM = "VALARM"; + ms_ATOM_VALARM.setString(ms_sVALARM); + + ms_sTZPART = "TZPART"; + ms_ATOM_TZPART.setString(ms_sTZPART); + + ms_sTIMEBASEDEVENT = "TimeBasedEvent"; + ms_sNSCALENDAR = "NSCalendar"; + + ms_sATTENDEE = "ATTENDEE"; + ms_ATOM_ATTENDEE.setString(ms_sATTENDEE); + + ms_sATTACH = "ATTACH"; + ms_ATOM_ATTACH.setString(ms_sATTACH); + + ms_sCATEGORIES = "CATEGORIES"; + ms_ATOM_CATEGORIES.setString(ms_sCATEGORIES); + + ms_sCLASS = "CLASS"; + ms_ATOM_CLASS.setString(ms_sCLASS); + + ms_sCOMMENT = "COMMENT"; + ms_ATOM_COMMENT.setString(ms_sCOMMENT); + + ms_sCOMPLETED = "COMPLETED"; + ms_ATOM_COMPLETED.setString(ms_sCOMPLETED); + + ms_sCONTACT = "CONTACT"; + ms_ATOM_CONTACT.setString(ms_sCONTACT); + ms_sCREATED = "CREATED"; + ms_ATOM_CREATED.setString(ms_sCREATED); + ms_sDTEND = "DTEND"; + ms_ATOM_DTEND.setString(ms_sDTEND); + + ms_sDTSTART = "DTSTART"; + ms_ATOM_DTSTART.setString(ms_sDTSTART); + ms_sDTSTAMP = "DTSTAMP"; + ms_ATOM_DTSTAMP.setString(ms_sDTSTAMP); + ms_sDESCRIPTION = "DESCRIPTION"; + ms_ATOM_DESCRIPTION.setString(ms_sDESCRIPTION); + ms_sDUE = "DUE"; + ms_ATOM_DUE.setString(ms_sDUE); + ms_sDURATION = "DURATION"; + ms_ATOM_DURATION.setString(ms_sDURATION); + ms_sEXDATE = "EXDATE"; + ms_ATOM_EXDATE.setString(ms_sEXDATE); + ms_sEXRULE = "EXRULE"; + ms_ATOM_EXRULE.setString(ms_sEXRULE); + ms_sFREEBUSY = "FREEBUSY"; + ms_ATOM_FREEBUSY.setString(ms_sFREEBUSY); + ms_sGEO = "GEO"; + ms_ATOM_GEO.setString(ms_sGEO); + ms_sLASTMODIFIED = "LAST-MODIFIED"; + ms_ATOM_LASTMODIFIED.setString(ms_sLASTMODIFIED); + ms_sLOCATION = "LOCATION"; + ms_ATOM_LOCATION.setString(ms_sLOCATION); + ms_sORGANIZER = "ORGANIZER"; + ms_ATOM_ORGANIZER.setString(ms_sORGANIZER); + ms_sPERCENTCOMPLETE = "PERCENT-COMPLETE"; + ms_ATOM_PERCENTCOMPLETE.setString(ms_sPERCENTCOMPLETE); + ms_sPRIORITY = "PRIORITY"; + ms_ATOM_PRIORITY.setString(ms_sPRIORITY); + ms_sRDATE = "RDATE"; + ms_ATOM_RDATE.setString(ms_sRDATE); + ms_sRRULE = "RRULE"; + ms_ATOM_RRULE.setString(ms_sRRULE); + ms_sRECURRENCEID = "RECURRENCE-ID"; + ms_ATOM_RECURRENCEID.setString(ms_sRECURRENCEID); + //ms_sRESPONSESEQUENCE = "RESPONSE-SEQUENCE"; + //ms_ATOM_RESPONSESEQUENCE.setString(ms_sRESPONSESEQUENCE); + ms_sRELATEDTO = "RELATED-TO"; + ms_ATOM_RELATEDTO.setString(ms_sRELATEDTO); + ms_sREPEAT = "REPEAT"; + ms_ATOM_REPEAT.setString(ms_sREPEAT); + ms_sREQUESTSTATUS = "REQUEST-STATUS"; + ms_ATOM_REQUESTSTATUS.setString(ms_sREQUESTSTATUS); + ms_sRESOURCES = "RESOURCES"; + ms_ATOM_RESOURCES.setString(ms_sRESOURCES); + ms_sSEQUENCE = "SEQUENCE"; + ms_ATOM_SEQUENCE.setString(ms_sSEQUENCE); + ms_sSTATUS = "STATUS"; + ms_ATOM_STATUS.setString(ms_sSTATUS); + ms_sSUMMARY = "SUMMARY"; + ms_ATOM_SUMMARY.setString(ms_sSUMMARY); + ms_sTRANSP = "TRANSP"; + ms_ATOM_TRANSP.setString(ms_sTRANSP); + ms_sTRIGGER = "TRIGGER"; + ms_ATOM_TRIGGER.setString(ms_sTRIGGER); + ms_sUID = "UID"; + ms_ATOM_UID.setString(ms_sUID); + ms_sURL = "URL"; + ms_ATOM_URL.setString(ms_sURL); + ms_sTZOFFSET = "TZOFFSET"; + ms_ATOM_TZOFFSET.setString(ms_sTZOFFSET); + ms_sTZOFFSETTO = "TZOFFSETTO"; + ms_ATOM_TZOFFSETTO.setString(ms_sTZOFFSETTO); + ms_sTZOFFSETFROM = "TZOFFSETFROM"; + ms_ATOM_TZOFFSETFROM.setString(ms_sTZOFFSETFROM); + ms_sTZNAME = "TZNAME"; + ms_ATOM_TZNAME.setString(ms_sTZNAME); + ms_sDAYLIGHT = "DAYLIGHT"; + ms_ATOM_DAYLIGHT.setString(ms_sDAYLIGHT); + ms_sSTANDARD = "STANDARD"; + ms_ATOM_STANDARD.setString(ms_sSTANDARD); + ms_sTZURL = "TZURL"; + ms_ATOM_TZURL.setString(ms_sTZURL); + ms_sTZID = "TZID"; + ms_ATOM_TZID.setString(ms_sTZID); + + ms_sTRUE = "TRUE"; + ms_ATOM_TRUE.setString(ms_sTRUE); + ms_sFALSE = "FALSE"; + ms_ATOM_FALSE.setString(ms_sFALSE); + + ms_sPUBLISH = "PUBLISH"; + ms_ATOM_PUBLISH.setString(ms_sPUBLISH); + ms_sREQUEST = "REQUEST"; + ms_ATOM_REQUEST.setString(ms_sREQUEST); + ms_sREPLY = "REPLY"; + ms_ATOM_REPLY.setString(ms_sREPLY); + ms_sCANCEL = "CANCEL"; + ms_ATOM_CANCEL.setString(ms_sCANCEL); + //ms_sRESEND = "RESEND"; + //ms_ATOM_RESEND.setString(ms_sRESEND); + ms_sREFRESH = "REFRESH"; + ms_ATOM_REFRESH.setString(ms_sREFRESH); + ms_sCOUNTER = "COUNTER"; + ms_ATOM_COUNTER.setString(ms_sCOUNTER); + ms_sDECLINECOUNTER = "DECLINECOUNTER"; + ms_ATOM_DECLINECOUNTER.setString(ms_sDECLINECOUNTER); + ms_sADD = "ADD"; + ms_ATOM_ADD.setString(ms_sADD); + ms_sDELEGATEREQUEST= "DELEGATEREQUEST"; + ms_ATOM_DELEGATEREQUEST.setString(ms_sDELEGATEREQUEST); + ms_sDELEGATEREPLY = "DELEGATEREPLY"; + ms_ATOM_DELEGATEREPLY.setString(ms_sDELEGATEREPLY); + //ms_sBUSYREQUEST = "BUSY-REQUEST"; + //ms_ATOM_BUSYREQUEST.setString(ms_sBUSYREQUEST); + //ms_sBUSYREPLY = "BUSY-REPLY"; + //ms_ATOM_BUSYREPLY.setString(ms_sBUSYREPLY); + + ms_sPRODID = "PRODID"; + ms_ATOM_PRODID.setString(ms_sPRODID); + ms_sVERSION = "VERSION"; + ms_ATOM_VERSION.setString(ms_sVERSION); + ms_sMETHOD = "METHOD"; + ms_ATOM_METHOD.setString(ms_sMETHOD); + ms_sSOURCE = "SOURCE"; + ms_ATOM_SOURCE.setString(ms_sSOURCE); + ms_sCALSCALE = "CALSCALE"; + ms_ATOM_CALSCALE.setString(ms_sCALSCALE); + ms_sNAME = "NAME"; + ms_ATOM_NAME.setString(ms_sNAME); + //ms_sPROFILE_VERSION = "PROFILE-VERSION"; + //ms_ATOM_PROFILE_VERSION.setString(ms_sPROFILE_VE + + ms_sGREGORIAN = "GREGORIAN"; + ms_ATOM_GREGORIAN.setString(ms_sGREGORIAN); + + ms_sPUBLIC = "PUBLIC"; + ms_ATOM_PUBLIC.setString(ms_sPUBLIC); + ms_sPRIVATE = "PRIVATE"; + ms_ATOM_PRIVATE.setString(ms_sPRIVATE); + ms_sCONFIDENTIAL = "CONFIDENTIAL"; + ms_ATOM_CONFIDENTIAL.setString(ms_sCONFIDENTIAL); + + ms_sNEEDSACTION = "NEEDS-ACTION"; + ms_ATOM_NEEDSACTION.setString(ms_sNEEDSACTION); + //ms_sCOMPLETED = "COMPLETED"; + //ms_ATOM_COMPLETED.setString(ms_sCOMPLETED); + ms_sINPROCESS = "IN-PROCESS"; + ms_ATOM_INPROCESS.setString(ms_sINPROCESS); + ms_sTENTATIVE = "TENTATIVE"; + ms_ATOM_TENTATIVE.setString(ms_sTENTATIVE); + ms_sCONFIRMED = "CONFIRMED"; + ms_ATOM_CONFIRMED.setString(ms_sCONFIRMED); + ms_sCANCELLED = "CANCELLED"; + ms_ATOM_CANCELLED.setString(ms_sCANCELLED); + ms_sDRAFT = "DRAFT"; + ms_ATOM_DRAFT.setString(ms_sDRAFT); + ms_sFINAL = "FINAL"; + ms_ATOM_FINAL.setString(ms_sFINAL); + + ms_sOPAQUE = "OPAQUE"; + ms_ATOM_OPAQUE.setString(ms_sOPAQUE); + ms_sTRANSPARENT = "TRANSPARENT"; + ms_ATOM_TRANSPARENT.setString(ms_sTRANSPARENT); + + ms_sROLE = "ROLE"; + ms_ATOM_ROLE.setString(ms_sROLE); + ms_sCUTYPE = "CUTYPE"; + ms_ATOM_CUTYPE.setString(ms_sCUTYPE); + ms_sTYPE = "TYPE"; + ms_ATOM_TYPE.setString(ms_sTYPE); + ms_sCN = "CN"; + ms_ATOM_CN.setString(ms_sCN); + ms_sPARTSTAT = "PARTSTAT"; + ms_ATOM_PARTSTAT.setString(ms_sPARTSTAT); + ms_sRSVP = "RSVP"; + ms_ATOM_RSVP.setString(ms_sRSVP); + ms_sEXPECT = "EXPECT"; + ms_ATOM_EXPECT.setString(ms_sEXPECT); + ms_sMEMBER = "MEMBER"; + ms_ATOM_MEMBER.setString(ms_sMEMBER); + ms_sDELEGATED_TO = "DELEGATED-TO"; + ms_ATOM_DELEGATED_TO.setString(ms_sDELEGATED_TO); + ms_sDELEGATED_FROM = "DELEGATED-FROM"; + ms_ATOM_DELEGATED_FROM.setString(ms_sDELEGATED_FROM); + ms_sSENTBY = "SENT-BY"; + ms_ATOM_SENTBY.setString(ms_sSENTBY); + ms_sDIR = "DIR"; + ms_ATOM_DIR.setString(ms_sDIR); + + //ms_sATTENDEE = "ATTENDEE"; + //ms_ATOM_ATTENDEE.setString(ms_sATTENDEE); + //ms_sORGANIZER = "ORGANIZER"; + //ms_ATOM_ORGANIZER.setString(ms_sORGANIZER); + //ms_sOWNER = "OWNER"; + //ms_ATOM_OWNER.setString(ms_sOWNER); + //ms_sDELEGATE = "DELEGATE"; + //ms_ATOM_DELEGATE.setString(ms_sDELEGATE); + ms_sCHAIR = "CHAIR"; + ms_ATOM_CHAIR.setString(ms_sCHAIR); + //ms_sPARTICIPANT = "PARTICIPANT"; + //ms_ATOM_PARTICIPANT.setString(ms_sPARTICIPANT); + ms_sREQ_PARTICIPANT = "REQ-PARTICIPANT"; + ms_ATOM_REQ_PARTICIPANT.setString(ms_sREQ_PARTICIPANT); + ms_sOPT_PARTICIPANT = "OPT-PARTICIPANT"; + ms_ATOM_OPT_PARTICIPANT.setString(ms_sOPT_PARTICIPANT); + ms_sNON_PARTICIPANT = "NON-PARTICIPANT"; + ms_ATOM_NON_PARTICIPANT.setString(ms_sNON_PARTICIPANT); + + + ms_sUNKNOWN = "UNKNOWN"; + ms_ATOM_UNKNOWN.setString(ms_sUNKNOWN); + ms_sINDIVIDUAL = "INDIVIDUAL"; + ms_ATOM_INDIVIDUAL.setString(ms_sINDIVIDUAL); + ms_sGROUP = "GROUP"; + ms_ATOM_GROUP.setString(ms_sGROUP); + ms_sRESOURCE = "RESOURCE"; + ms_ATOM_RESOURCE.setString(ms_sRESOURCE); + ms_sROOM = "ROOM"; + ms_ATOM_ROOM.setString(ms_sROOM); + + + //ms_sNEEDSACTION = "NEEDS-ACTION"; + //ms_ATOM_NEEDSACTION.setString(ms_sNEEDSACTION); + ms_sACCEPTED = "ACCEPTED"; + ms_ATOM_ACCEPTED.setString(ms_sACCEPTED); + ms_sDECLINED = "DECLINED"; + ms_ATOM_DECLINED.setString(ms_sDECLINED); + //ms_sTENTATIVE = "TENTATIVE"; + //ms_ATOM_TENTATIVE.setString(ms_sTENTATIVE); + //ms_sCONFIRMED = "CONFIRMED"; + //ms_ATOM_CONFIRMED.setString(ms_sCONFIRMED); + //ms_sCOMPLETED = "COMPLETED"; + //ms_ATOM_COMPLETED.setString(ms_sCOMPLETED); + ms_sDELEGATED = "DELEGATED"; + ms_ATOM_DELEGATED.setString(ms_sDELEGATED); + //ms_sCANCELLED = "CANCELLED"; + //ms_ATOM_CANCELLED.setString(ms_sCANCELLED); + ms_sVCALNEEDSACTION = "NEEDS ACTION"; + ms_ATOM_VCALNEEDSACTION.setString(ms_sVCALNEEDSACTION); + + //ms_sFALSE = "FALSE"; + //ms_ATOM_FALSE.setString(ms_sFALSE); + //ms_sTRUE = "TRUE"; + //ms_ATOM_TRUE.setString(ms_sTRUE); + + ms_sFYI = "FYI"; + ms_ATOM_FYI.setString(ms_sFYI); + ms_sREQUIRE = "REQUIRE"; + ms_ATOM_REQUIRE.setString(ms_sREQUIRE); + //ms_sREQUEST = "REQUEST"; + //ms_ATOM_REQUEST.setString(ms_sREQUEST); + ms_sIMMEDIATE = "IMMEDIATE"; + ms_ATOM_IMMEDIATE.setString(ms_sIMMEDIATE); + + ms_sRANGE = "RANGE"; + ms_ATOM_RANGE.setString(ms_sRANGE); + ms_sTHISANDPRIOR = "THISANDPRIOR"; + ms_ATOM_THISANDPRIOR.setString(ms_sTHISANDPRIOR); + ms_sTHISANDFUTURE = "THISANDFUTURE"; + ms_ATOM_THISANDFUTURE.setString(ms_sTHISANDFUTURE); + + ms_sFBTYPE = "FBTYPE"; + ms_ATOM_FBTYPE.setString(ms_sFBTYPE); + ms_sBSTAT = "BSTAT"; + ms_ATOM_BSTAT.setString(ms_sBSTAT); + ms_sBUSY = "BUSY"; + ms_ATOM_BUSY.setString(ms_sBUSY); + ms_sFREE = "FREE"; + ms_ATOM_FREE.setString(ms_sFREE); + ms_sBUSY_UNAVAILABLE = "BUSY-UNAVAILABLE"; + ms_ATOM_BUSY_UNAVAILABLE.setString(ms_sBUSY_UNAVAILABLE); + ms_sBUSY_TENTATIVE = "BUSY-TENTATIVE"; + ms_ATOM_BUSY_TENTATIVE.setString(ms_sBUSY_TENTATIVE); + ms_sUNAVAILABLE = "UNAVAILABLE"; + ms_ATOM_UNAVAILABLE.setString(ms_sUNAVAILABLE); + //ms_sTENTATIVE = "TENTATIVE"; + //ms_ATOM_TENTATIVE.setString(ms_sTENTATIVE); + + ms_sACTION = "ACTION"; + ms_ATOM_ACTION.setString(ms_sACTION); + + ms_sAUDIO = "AUDIO"; + ms_ATOM_AUDIO.setString(ms_sAUDIO); + ms_sDISPLAY = "DISPLAY"; + ms_ATOM_DISPLAY.setString(ms_sDISPLAY); + ms_sEMAIL = "EMAIL"; + ms_ATOM_EMAIL.setString(ms_sEMAIL); + ms_sPROCEDURE = "PROCEDURE"; + ms_ATOM_PROCEDURE.setString(ms_sPROCEDURE); + + ms_sENCODING = "ENCODING"; + ms_ATOM_ENCODING.setString(ms_sENCODING); + ms_sCHARSET = "CHARSET"; + ms_ATOM_CHARSET.setString(ms_sCHARSET); + ms_sQUOTED_PRINTABLE = "QUOTED-PRINTABLE"; + ms_ATOM_QUOTED_PRINTABLE.setString(ms_sQUOTED_PRINTABLE); + + //ms_sENCODING = "ENCODING"; + //ms_ATOM_ENCODING.setString(ms_sENCODING); + ms_sVALUE = "VALUE"; + ms_ATOM_VALUE.setString(ms_sVALUE); + ms_sLANGUAGE = "LANGUAGE"; + ms_ATOM_LANGUAGE.setString(ms_sLANGUAGE); + ms_sALTREP = "ALTREP"; + ms_ATOM_ALTREP.setString(ms_sALTREP); + //ms_sSENTBY = "SENT-BY"; + //ms_ATOM_SENTBY.setString(ms_sSENTBY); + ms_sRELTYPE = "RELTYPE"; + ms_ATOM_RELTYPE.setString(ms_sRELTYPE); + ms_sFMTTYPE = "FMTTYPE"; + ms_ATOM_FMTTYPE.setString(ms_sFMTTYPE); + ms_sRELATED = "RELATED"; + ms_ATOM_RELATED.setString(ms_sRELATED); + //ms_sTZID = "TZID"; + //ms_ATOM_TZID.setString(ms_sTZID); + + + ms_sPARENT = "PARENT"; + ms_ATOM_PARENT.setString(ms_sPARENT); + ms_sCHILD = "CHILD"; + ms_ATOM_CHILD.setString(ms_sCHILD); + ms_sSIBLING = "SIBLING"; + ms_ATOM_SIBLING.setString(ms_sSIBLING); + + ms_sSTART = "START"; + ms_ATOM_START.setString(ms_sSTART); + ms_sEND = "END"; + ms_ATOM_END.setString(ms_sEND); + + + ms_s8bit = "8bit"; + ms_ATOM_8bit.setString(ms_s8bit); + ms_sBase64 = "base64"; + ms_ATOM_Base64.setString(ms_sBase64); + ms_s7bit = "7bit"; + ms_ATOM_7bit.setString(ms_s7bit); + ms_sQ = "Q"; + ms_ATOM_Q.setString(ms_sQ); + ms_sB = "B"; + ms_ATOM_B.setString(ms_sB); + + + ms_sURI = "URI"; + ms_ATOM_URI.setString(ms_sURI); + ms_sTEXT = "TEXT"; + ms_ATOM_TEXT.setString(ms_sTEXT); + ms_sBINARY = "BINARY"; + ms_ATOM_BINARY.setString(ms_sBINARY); + ms_sDATE = "DATE"; + ms_ATOM_DATE.setString(ms_sDATE); + ms_sRECUR = "RECUR"; + ms_ATOM_RECUR.setString(ms_sRECUR); + ms_sTIME = "TIME"; + ms_ATOM_TIME.setString(ms_sTIME); + ms_sDATETIME = "DATE-TIME"; + ms_ATOM_DATETIME.setString(ms_sDATETIME); + ms_sPERIOD = "PERIOD"; + ms_ATOM_PERIOD.setString(ms_sPERIOD); + //ms_sDURATION = "DURATION"; + //ms_ATOM_DURATION.setString(ms_sDURATION); + ms_sBOOLEAN = "BOOLEAN"; + ms_ATOM_BOOLEAN.setString(ms_sBOOLEAN); + ms_sINTEGER = "INTEGER"; + ms_ATOM_INTEGER.setString(ms_sINTEGER); + ms_sFLOAT = "FLOAT"; + ms_ATOM_FLOAT.setString(ms_sFLOAT); + ms_sCALADDRESS = "CAL-ADDRESS"; + ms_ATOM_CALADDRESS.setString(ms_sCALADDRESS); + ms_sUTCOFFSET = "UTC-OFFSET"; + ms_ATOM_UTCOFFSET.setString(ms_sUTCOFFSET); + + ms_sMAILTO_COLON = "MAILTO:"; + ms_sBEGIN = "BEGIN"; + ms_ATOM_BEGIN.setString(ms_sBEGIN); + ms_sBEGIN_WITH_COLON = "BEGIN:"; + ms_ATOM_BEGIN_WITH_COLON.setString(ms_sBEGIN_WITH_COLON); + //ms_sEND = "END"; + ms_ATOM_END.setString(ms_sEND); + ms_sEND_WITH_COLON = "END:"; + ms_ATOM_END_WITH_COLON.setString(ms_sEND_WITH_COLON); + ms_sBEGIN_VCALENDAR = "BEGIN:VCALENDAR"; + ms_ATOM_BEGIN_VCALENDAR.setString(ms_sBEGIN_VCALENDAR); + ms_sEND_VCALENDAR= "END:VCALENDAR"; + ms_ATOM_END_VCALENDAR.setString(ms_sEND_VCALENDAR); + ms_sBEGIN_VFREEBUSY = "BEGIN:VFREEBUSY"; + ms_ATOM_BEGIN_VFREEBUSY.setString(ms_sBEGIN_VFREEBUSY); + ms_sEND_VFREEBUSY= "END:VFREEBUSY"; + ms_ATOM_END_VFREEBUSY.setString(ms_sEND_VFREEBUSY); + ms_sLINEBREAK = "\r\n"; + ms_ATOM_LINEBREAK.setString(ms_sLINEBREAK); + ms_sOK = "OK"; + ms_ATOM_OK.setString(ms_sOK); + ms_sCOMMA_SYMBOL = ","; + ms_ATOM_COMMA_SYMBOL.setString(ms_sCOMMA_SYMBOL); + ms_sCOLON_SYMBOL = ":"; + ms_ATOM_COLON_SYMBOL.setString(ms_sCOLON_SYMBOL); + ms_sDOUBLEQUOTE_SYMBOL = "\""; + ms_sSEMICOLON_SYMBOL = ";"; + ms_sDEFAULT_DELIMS = "\t\n\r"; + ms_sLINEBREAKSPACE = "\r\n "; + ms_sALTREPQUOTE = ";ALTREP=\""; + ms_sLINEFEEDSPACE = "\n "; + ms_sXPARAMVAL = "X-PARAM_VALUE"; + + ms_sRRULE_WITH_SEMICOLON = "RRULE;"; + + ms_sUNTIL = "UNTIL"; + ms_ATOM_UNTIL.setString(ms_sUNTIL); + ms_sCOUNT = "COUNT"; + ms_ATOM_COUNT.setString(ms_sCOUNT); + ms_sINTERVAL = "INTERVAL"; + ms_ATOM_INTERVAL.setString(ms_sINTERVAL); + ms_sFREQ = "FREQ"; + ms_ATOM_FREQ.setString(ms_sFREQ); + ms_sBYSECOND = "BYSECOND"; + ms_ATOM_BYSECOND.setString(ms_sBYSECOND); + ms_sBYMINUTE = "BYMINUTE"; + ms_ATOM_BYMINUTE.setString(ms_sBYMINUTE); + ms_sBYHOUR = "BYHOUR"; + ms_ATOM_BYHOUR.setString(ms_sBYHOUR); + ms_sBYDAY = "BYDAY"; + ms_ATOM_BYDAY.setString(ms_sBYDAY); + ms_sBYMONTHDAY = "BYMONTHDAY"; + ms_ATOM_BYMONTHDAY.setString(ms_sBYMONTHDAY); + ms_sBYYEARDAY = "BYYEARDAY"; + ms_ATOM_BYYEARDAY.setString(ms_sBYYEARDAY); + ms_sBYWEEKNO = "BYWEEKNO"; + ms_ATOM_BYWEEKNO.setString(ms_sBYWEEKNO); + ms_sBYMONTH = "BYMONTH"; + ms_ATOM_BYMONTH.setString(ms_sBYMONTH); + ms_sBYSETPOS = "BYSETPOS"; + ms_ATOM_BYSETPOS.setString(ms_sBYSETPOS); + ms_sWKST = "WKST"; + ms_ATOM_WKST.setString(ms_sWKST); + + ms_sSECONDLY = "SECONDLY"; + ms_ATOM_SECONDLY.setString(ms_sSECONDLY); + ms_sMINUTELY = "MINUTELY"; + ms_ATOM_MINUTELY.setString(ms_sMINUTELY); + ms_sHOURLY = "HOURLY"; + ms_ATOM_HOURLY.setString(ms_sHOURLY); + ms_sDAILY = "DAILY"; + ms_ATOM_DAILY.setString(ms_sDAILY); + ms_sWEEKLY = "WEEKLY"; + ms_ATOM_WEEKLY.setString(ms_sWEEKLY); + ms_sMONTHLY = "MONTHLY"; + ms_ATOM_MONTHLY.setString(ms_sMONTHLY); + ms_sYEARLY = "YEARLY"; + ms_ATOM_YEARLY.setString(ms_sYEARLY); + + ms_sSU = "SU"; + ms_ATOM_SU.setString(ms_sSU); + ms_sMO = "MO"; + ms_ATOM_MO.setString(ms_sMO); + ms_sTU = "TU"; + ms_ATOM_TU.setString(ms_sTU); + ms_sWE = "WE"; + ms_ATOM_WE.setString(ms_sWE); + ms_sTH = "TH"; + ms_ATOM_TH.setString(ms_sTH); + ms_sFR = "FR"; + ms_ATOM_FR.setString(ms_sFR); + ms_sSA = "SA"; + ms_ATOM_SA.setString(ms_sSA); + + ms_sBYDAYYEARLY = "BYDAYYEARLY"; + ms_ATOM_BYDAYYEARLY.setString(ms_sBYDAYYEARLY); + ms_sBYDAYMONTHLY = "BYDAYMONTHLY"; + ms_ATOM_BYDAYMONTHLY.setString(ms_sBYDAYMONTHLY); + ms_sBYDAYWEEKLY = "BYDAYWEEKLY"; + ms_ATOM_BYDAYWEEKLY.setString(ms_sBYDAYWEEKLY); + ms_sDEFAULT = "DEFAULT"; + ms_ATOM_DEFAULT.setString(ms_sDEFAULT); + + ms_sCONTENT_TRANSFER_ENCODING = "Content-Transfer-Encoding"; +} + +//--------------------------------------------------------------------- + +JulianKeyword * JulianKeyword::Instance() +{ + if (m_Instance == 0) + m_Instance = new JulianKeyword(); + PR_ASSERT(m_Instance != 0); + return m_Instance; +} + +//--------------------------------------------------------------------- + +JulianKeyword::~JulianKeyword() +{ + /* + if (m_Instance != 0) + { + delete m_Instance; m_Instance = 0; + } + */ +} + +//--------------------------------------------------------------------- +// JulianAtomRange +//--------------------------------------------------------------------- + +JulianAtomRange * JulianAtomRange::m_Instance = 0; + +//--------------------------------------------------------------------- + +JulianAtomRange::~JulianAtomRange() +{ + /* + if (m_Instance != 0) + { + delete m_Instance; m_Instance = 0; + } + */ +} + +//--------------------------------------------------------------------- + +JulianAtomRange * +JulianAtomRange::Instance() +{ + if (m_Instance == 0) + m_Instance = new JulianAtomRange(); + PR_ASSERT(m_Instance != 0); + return m_Instance; +} + +//--------------------------------------------------------------------- + +JulianAtomRange::JulianAtomRange() +{ + // ATOM RANGES + ms_asAltrepLanguageParamRange[0] = JulianKeyword::Instance()->ms_ATOM_ALTREP; + ms_asAltrepLanguageParamRange[1] = JulianKeyword::Instance()->ms_ATOM_LANGUAGE; + ms_asAltrepLanguageParamRangeSize = 2; + + ms_asTZIDValueParamRange[0] = JulianKeyword::Instance()->ms_ATOM_VALUE; + ms_asTZIDValueParamRange[1] = JulianKeyword::Instance()->ms_ATOM_TZID; + ms_asTZIDValueParamRangeSize = 2; + + ms_asLanguageParamRange[0] = JulianKeyword::Instance()->ms_ATOM_LANGUAGE; + ms_asLanguageParamRangeSize = 1; + + ms_asEncodingValueParamRange[0] = JulianKeyword::Instance()->ms_ATOM_ENCODING; + ms_asEncodingValueParamRange[1] = JulianKeyword::Instance()->ms_ATOM_VALUE; + ms_asEncodingValueParamRangeSize = 2; + + ms_asEncodingValueFMTTypeParamRange[0] = JulianKeyword::Instance()->ms_ATOM_ENCODING; + ms_asEncodingValueFMTTypeParamRange[1] = JulianKeyword::Instance()->ms_ATOM_VALUE; + ms_asEncodingValueFMTTypeParamRange[2] = JulianKeyword::Instance()->ms_ATOM_FMTTYPE; + ms_asEncodingValueFMTTypeParamRangeSize = 3; + + ms_asSentByParamRange[0] = JulianKeyword::Instance()->ms_ATOM_SENTBY; + ms_asSentByParamRangeSize = 1; + + ms_asReltypeParamRange[0] = JulianKeyword::Instance()->ms_ATOM_RELTYPE; + ms_asReltypeParamRangeSize = 1; + + ms_asRelatedValueParamRange[0] = JulianKeyword::Instance()->ms_ATOM_VALUE; + ms_asRelatedValueParamRange[1] = JulianKeyword::Instance()->ms_ATOM_RELATED; + ms_asRelatedValueParamRangeSize = 2; + + ms_asBinaryURIValueRange[0] = JulianKeyword::Instance()->ms_ATOM_BINARY; + ms_asBinaryURIValueRange[1] = JulianKeyword::Instance()->ms_ATOM_URI; + ms_asBinaryURIValueRangeSize = 2; + + ms_asDateDateTimeValueRange[0] = JulianKeyword::Instance()->ms_ATOM_DATE; + ms_asDateDateTimeValueRange[1] = JulianKeyword::Instance()->ms_ATOM_DATETIME; + ms_asDateDateTimeValueRangeSize = 2; + + ms_asDurationDateTimeValueRange[0] = JulianKeyword::Instance()->ms_ATOM_DURATION; + ms_asDurationDateTimeValueRange[1] = JulianKeyword::Instance()->ms_ATOM_DATETIME; + ms_asDurationDateTimeValueRangeSize = 2; + + ms_asDateDateTimePeriodValueRange[0] = JulianKeyword::Instance()->ms_ATOM_DATE; + ms_asDateDateTimePeriodValueRange[1] = JulianKeyword::Instance()->ms_ATOM_DATETIME; + ms_asDateDateTimePeriodValueRange[2] = JulianKeyword::Instance()->ms_ATOM_PERIOD; + ms_asDateDateTimePeriodValueRangeSize = 3; + + ms_asRelTypeRange[0] = JulianKeyword::Instance()->ms_ATOM_PARENT; + ms_asRelTypeRange[1] = JulianKeyword::Instance()->ms_ATOM_CHILD; + ms_asRelTypeRange[2] = JulianKeyword::Instance()->ms_ATOM_SIBLING; + ms_iRelTypeRangeSize = 3; + + ms_asRelatedRange[0] = JulianKeyword::Instance()->ms_ATOM_START; + ms_asRelatedRange[1] = JulianKeyword::Instance()->ms_ATOM_END; + ms_iRelatedRangeSize = 2; + + ms_asParameterRange[0] = JulianKeyword::Instance()->ms_ATOM_ALTREP; + ms_asParameterRange[1] = JulianKeyword::Instance()->ms_ATOM_ENCODING; + ms_asParameterRange[2] = JulianKeyword::Instance()->ms_ATOM_LANGUAGE; + ms_asParameterRange[3] = JulianKeyword::Instance()->ms_ATOM_TZID; + ms_asParameterRange[4] = JulianKeyword::Instance()->ms_ATOM_VALUE; + ms_iParameterRangeSize = 5; + + ms_asIrregularProperties[0] = JulianKeyword::Instance()->ms_ATOM_ATTENDEE; + ms_asIrregularProperties[1] = JulianKeyword::Instance()->ms_ATOM_FREEBUSY; + ms_asIrregularProperties[2] = JulianKeyword::Instance()->ms_ATOM_RECURRENCEID; + ms_asIrregularProperties[3] = JulianKeyword::Instance()->ms_ATOM_ORGANIZER; + ms_iIrregularPropertiesSize = 4; + + ms_asValueRange[0] = JulianKeyword::Instance()->ms_ATOM_BINARY; + ms_asValueRange[1] = JulianKeyword::Instance()->ms_ATOM_BOOLEAN; + ms_asValueRange[2] = JulianKeyword::Instance()->ms_ATOM_CALADDRESS; + ms_asValueRange[3] = JulianKeyword::Instance()->ms_ATOM_DATE; + ms_asValueRange[4] = JulianKeyword::Instance()->ms_ATOM_DATETIME; + ms_asValueRange[5] = JulianKeyword::Instance()->ms_ATOM_DURATION; + ms_asValueRange[6] = JulianKeyword::Instance()->ms_ATOM_FLOAT; + ms_asValueRange[7] = JulianKeyword::Instance()->ms_ATOM_INTEGER; + ms_asValueRange[8] = JulianKeyword::Instance()->ms_ATOM_PERIOD; + ms_asValueRange[9] = JulianKeyword::Instance()->ms_ATOM_RECUR; + ms_asValueRange[10] = JulianKeyword::Instance()->ms_ATOM_TEXT; + ms_asValueRange[11] = JulianKeyword::Instance()->ms_ATOM_TIME; + ms_asValueRange[12] = JulianKeyword::Instance()->ms_ATOM_URI; + ms_asValueRange[13] = JulianKeyword::Instance()->ms_ATOM_UTCOFFSET; + ms_iValueRangeSize = 14; + ms_asEncodingRange[0] = JulianKeyword::Instance()->ms_ATOM_8bit; + ms_asEncodingRange[1] = JulianKeyword::Instance()->ms_ATOM_Base64; + ms_iEncodingRangeSize = 2; +}; + +//--------------------------------------------------------------------- +// JulianErrorMessage +//--------------------------------------------------------------------- + +//--------------------------------------------------------------------- + +JulianLogErrorMessage * JulianLogErrorMessage::m_Instance = 0; +t_int32 JulianLogErrorMessage::ms_iStaticErrorNumber = 10000; + +//--------------------------------------------------------------------- + +JulianLogErrorMessage * +JulianLogErrorMessage::Instance() +{ + if (m_Instance == 0) + m_Instance = new JulianLogErrorMessage(); + PR_ASSERT(m_Instance != 0); + return m_Instance; +} + +//--------------------------------------------------------------------- + +JulianLogErrorMessage::~JulianLogErrorMessage() +{ + /* + if (m_Instance != 0) + { + delete m_Instance; m_Instance = 0; + } + */ +} + +//--------------------------------------------------------------------- + +JulianLogErrorMessage::JulianLogErrorMessage() +{ +#if 0 + ms_sDTEndBeforeDTStart = "error: DTEnd before DTStart. Setting DTEnd equal to DTStart."; + + ms_sExportError = "error: error writing to export file"; + ms_sNTimeParamError = "error: ntime requires parameter"; + ms_sInvalidPromptValue = "error: must be ON or OFF"; + ms_sSTimeParamError = "error: stime requires parameter"; + ms_sISO8601ParamError = "error: iso8601 requires a parameter"; + ms_sInvalidTimeStringError = "error: cannot parse time/date string"; + ms_sTimeZoneParamError = "error: timezone requires parameter"; + ms_sLocaleParamError = "error: locale requires parameter"; + ms_sLocaleNotFoundError = "error: locale not found"; + ms_sPatternParamError = "error: param requires parameter"; + ms_sInvalidPatternError = "error: bad format pattern cannot print"; + ms_sRRuleParamError = "error: rrule requires parameter"; + ms_sERuleParamError = "error: erule requires parameter"; + ms_sBoundParamError = "error: bound requires parameter"; + //ms_sInvalidRecurrenceError = "error: bad recurrence cannot unzip"; + ms_sInvalidRecurrenceError = "Recurrence rules are too complicated. Only the first instance was scheduled."; + ms_sUnzipNullError = "error: no recurrence defined"; + ms_sCommandNotFoundError = "error: command not found"; + ms_sInvalidTimeZoneError = "error: bad timezone"; + ms_sFileNotFound = "error: file not found"; + ms_sInvalidPropertyName = "error: invalid property name"; + ms_sInvalidPropertyValue = "error: invalid property value"; + ms_sInvalidParameterName = "error: invalid parameter name"; + ms_sInvalidParameterValue = "error: invalid parameter value"; + ms_sMissingStartingTime = "error: no starting time"; + ms_sMissingEndingTime = "error: no ending time"; + ms_sEndBeforeStartTime = "error: ending time occurs before starting time"; + ms_sMissingSeqNo = "error:invalid or missing sequence NO."; + ms_sMissingReplySeq = "error:no reply sequence NO."; + ms_sMissingURL = "error: no URL"; + ms_sMissingDTStamp = "error: no DTStamp"; + ms_sMissingUID = "error: no UID"; + ms_sMissingDescription = "error: no Description"; + ms_sMissingMethodProvided = "error: no method provided process as publish"; + ms_sMissingOrganizer = "error: no Organizer"; + ms_sMissingSummary = "error: no Summary"; + ms_sMissingAttendees = "error: missing Attendees"; + ms_sInvalidVersionNumber = "error: version number is not 2.0"; + ms_sUnknownUID = "error: UID not related to any event in calendar, ask for resend"; + ms_sMissingUIDInReply = "error: missing UID in reply, abort addReply"; + ms_sMissingValidDTStamp = "error: missing valid DTStamp, abort addReply"; + ms_sDeclineCounterCalledByAttendee = "error: an attendee cannot create an declinecounter message"; + ms_sPublishCalledByAttendee = "error: an attendee cannot create an publish message"; + ms_sRequestCalledByAttendee = "error: an attendee cannot create an request message"; + ms_sCancelCalledByAttendee = "error: an attendee cannot create an cancel message"; + ms_sCounterCalledByOrganizer = "error: an organizer cannot create an counter message"; + ms_sRefreshCalledByOrganizer = "error: an organizer cannot create an resend message"; + ms_sReplyCalledByOrganizer = "error: an organizer cannot create an reply message"; + ms_sAddReplySequenceOutOfRange = "error: the sequence no. of this reply message is either too small or too big"; + ms_sDuplicatedProperty = "error: this property already defined in this component, overriding old property"; + ms_sDuplicatedParameter = "error: this parameter is already defined in this property, overriding old parameter value"; + ms_sConflictMethodAndStatus = "error: the status of this message conflicts with the method type"; + ms_sConflictCancelAndConfirmedTentative = "error: this cancel message does not have status CANCELLED"; + ms_sMissingUIDToMatchEvent = "error: this reply, counter, resend, cancel message has no uid"; + ms_sInvalidNumberFormat = "error: this string cannot be parsed into a number"; + ms_sDelegateRequestError = "error: cannot create delegate request message"; + ms_sInvalidRecurrenceIDRange = "error: recurrence-id range argument is invalid"; + ms_sUnknownRecurrenceID = "error: recurrence-id not found in event list, need to keep all cancel messages referring to it"; + ms_sPropertyValueTypeMismatch = "error: the value type of this property does not match the VALUE parameter value"; + ms_sInvalidRRule = "error: invalid rrule, ignoring rule"; + ms_sInvalidExRule = "error: invalid exrule, ignoring exrule"; + ms_sInvalidRDate = "error: invalid rdate, ignoring rdate"; + ms_sInvalidExDate = "error: invalid rdate, ignoring exdate"; + ms_sInvalidEvent = "error: invalid event, removing from event list"; + ms_sInvalidComponent = "error: invalid calendar component, removing from component list"; + ms_sInvalidAlarm = "error: invalid alarm, removing from alarm list"; + ms_sInvalidTZPart = "error: invalid tzpart, not adding to tzpart list"; + ms_sInvalidAlarmCategory = "error: invalid alarm category"; + ms_sInvalidAttendee = "error: invalid attendee, not adding attendee to list"; + ms_sInvalidFreebusy = "error: invalid freebusy, not adding freebusy to list"; + ms_sDurationAssertionFailed = "error: weeks variable and other date variables are not 0, violating duration assertion"; + ms_sDurationParseFailed = "error: duration parsing failed"; + ms_sPeriodParseFailed = "error: period parsing failed"; + ms_sPeriodStartInvalid = "error: period start date is before epoch"; + ms_sPeriodEndInvalid = "error: period end date is before epoch"; + ms_sPeriodEndBeforeStart = "error: period end date is before start date"; + ms_sPeriodDurationZero = "error: period duration is zero length"; + ms_sFreebusyPeriodInvalid = "error: freebusy period is invalid"; + ms_sOptParamInvalidPropertyValue = "error: invalid property value for optional parameter"; + ms_sOptParamInvalidPropertyName = "error: invalid optional parameter name"; + ms_sInvalidOptionalParam = "error: bad optional parameters"; + ms_sAbruptEndOfParsing = "error: terminated parsing of calendar component before reaching END:"; + ms_sLastModifiedBeforeCreated = "error: last-modified time comes before created"; + ms_sMultipleOwners = "error: more than one owner for this component"; + ms_sMultipleOrganizers = "error: more than one organizer for this component"; + ms_sMissingOwner = "error: no owner for this component"; + ms_sMissingDueTime = "error: due time not set in VTodo component"; + ms_sCompletedPercentMismatch = "error: completed not 100%, or not completed but 100% in VTodo"; + ms_sMissingFreqTagRecurrence = "error: rule must contain FREQ tag"; + ms_sFreqIntervalMismatchRecurrence = "error: frequency/interval inconsitencey"; + ms_sInvalidPercentCompleteValue = "error: setting bad value to percent complete"; + ms_sInvalidPriorityValue = "error: setting bad value to priority"; + ms_sInvalidByHourValue = "error: Invalid BYHOUR entry"; + ms_sInvalidByMinuteValue = "error: Invalid BYMINUTE entry"; + ms_sByDayFreqIntervalMismatch = "error: frequency/interval inconsistency"; + ms_sInvalidByMonthDayValue = "error: Invalid BYMONTHDAY entry"; + ms_sInvalidByYearDayValue = "error: Invalid BYYEARDAY entry"; + ms_sInvalidBySetPosValue = "error: Invalid BYSETPOS entry"; + ms_sInvalidByWeekNoValue = "error: Invalid BYWEEKNO entry"; + ms_sInvalidWeekStartValue = "error: Invalid week start value"; + ms_sInvalidByMonthValue = "error: Invalid BYMONTH entry"; + ms_sInvalidByDayValue = "error: Invalid BYDAY entry"; + ms_sInvalidFrequency = "error: Invalid Frequency type"; + ms_sInvalidDayArg = "error: Invalid Day arg"; + ms_sVerifyZeroError = "error: read in a zero arg in verifyIntList"; + ms_sRoundedPercentCompleteTo100 = "error: rounded percent complete value to 100"; + ms_sRS200 = "2.00;Success."; + ms_sRS201 = "2.01;Success, but fallback taken on one or more property values."; + ms_sRS202 = "2.02;Success, invalid property ignored."; + ms_sRS203 = "2.03;Success, invalid property parameter ignored."; + ms_sRS204 = "2.04;Success, unknown non-standard property ignored."; + ms_sRS205 = "2.05;Success, unknown non-standard property value ignored."; + ms_sRS206 = "2.06;Success, invalid calendar component ignored."; + ms_sRS207 = "2.07;Success, request forwarded to calendar user."; + ms_sRS208 = "2.08;Success, repeating event ignored. Scheduled as a single event."; + ms_sRS209 = "2.09;Success, turncated end date/time to date boundary."; + ms_sRS210 = "2.10;Success, repeating to-do ignored. Scehduled as a single to-do"; + ms_sRS300 = "3.00;Invalid property name."; + ms_sRS301 = "3.01;Invalid property value."; + ms_sRS302 = "3.02;Invalid property parameter."; + ms_sRS303 = "3.03;Invalid property parameter value."; + ms_sRS304 = "3.04;Invalid calendar component sequence."; + ms_sRS305 = "3.05;Invalid date or time."; + ms_sRS306 = "3.06;Invalid rule."; + ms_sRS307 = "3.07;Invalid calendar user."; + ms_sRS308 = "3.08;No authority."; + ms_sRS309 = "3.09;Unsupported Version."; + ms_sRS310 = "3.10;Request entry too large"; + ms_sRS311 = "3.11;Missing required property"; + ms_sRS312 = "3.12;Invalid calendar component;validity failure"; + ms_sRS400 = "4.00;Event conflict. Date/time is busy."; + ms_sRS500 = "5.00;Request not supported."; + ms_sRS501 = "5.01;Service unavailable."; + ms_sRS502 = "5.02;Invalid calendar service."; + ms_sRS503 = "5.03;No-scheduling support for user."; + ms_sMissingUIDGenerateDefault = "default: missing UID, generating new UID"; + ms_sMissingStartingTimeGenerateDefault = "default: missing start time, generating default start time"; + ms_sMissingEndingTimeGenerateDefault = "default: missing UID, generating default end time"; + ms_sNegativeSequenceNumberGenerateDefault = "default: negative or no sequence number, generating default seqence number"; + ms_sDefaultTBEDescription = "default: setting default description property in TimeBasedEvent to \"\""; + ms_sDefaultTBEClass = "default: setting default class property in TimeBasedEvent to \"\""; + ms_sDefaultTBEStatus = "default: setting default status property in TimeBasedEvent \"\""; + ms_sDefaultTBETransp = "default: setting default transp property in TimeBasedEvent to OPAQUE"; + ms_sDefaultTBERequestStatus = "default: setting default request status property in TimeBasedEvent 2.00;Success"; + ms_sDefaultTBESummary = "default: setting default summary property in TimeBasedEvent to DESCRIPTION value"; + ms_sDefaultRecIDRange = "default: setting default range property in Recurrence-ID to \"\""; + ms_sDefaultAttendeeRole = "default: setting default role property in Attendee to ATTENDEE"; + ms_sDefaultAttendeeType = "default: setting default type property in Attendee to UNKNOWN"; + ms_sDefaultAttendeeExpect = "default: setting default expect property in Attendee to FYI"; + ms_sDefaultAttendeeStatus = "default: setting default status property in Attendee to NEEDS-ACTION"; + ms_sDefaultAttendeeRSVP = "default: setting default RSVP property in Attendee to FALSE"; + ms_sDefaultAlarmRepeat = "default: setting default repeat property in Alarm to 1"; + ms_sDefaultAlarmDuration = "default: setting default duration property in Alarm to 15 minutes"; + ms_sDefaultAlarmCategories = "default: setting default categories property in Alarm to DISPLAY,AUDIO"; + ms_sDefaultFreebusyStatus = "default: setting default status property in Freebusy to BUSY"; + ms_sDefaultFreebusyType = "default: setting default type property in Freebusy to BUSY"; + ms_sDefaultDuration = "default: setting duration to zero-length duration (PT0H)"; + ms_sDefaultAlarmDescriptionString = "Default Alarm Description"; + ms_sDefaultAlarmSummaryString = "Default Alarm Summary"; + ms_sXTokenParamIgnored = "ignoring x-token parameter"; + ms_sXTokenComponentIgnored = "2.6;Success, invalid calendar x-component ignored."; +#endif + + ms_sRS202 = "2.02;Success, invalid property ignored."; + ms_sDefaultAlarmDescriptionString = "Default Alarm Description"; + ms_sDefaultAlarmSummaryString = "Default Alarm Summary"; + + + ms_iDTEndBeforeDTStart = ms_iStaticErrorNumber++; + ms_iExportError = ms_iStaticErrorNumber++; + ms_iNTimeParamError = ms_iStaticErrorNumber++; + ms_iInvalidPromptValue = ms_iStaticErrorNumber++; + ms_iSTimeParamError = ms_iStaticErrorNumber++; + ms_iISO8601ParamError = ms_iStaticErrorNumber++; + ms_iInvalidTimeStringError = ms_iStaticErrorNumber++; + ms_iTimeZoneParamError = ms_iStaticErrorNumber++; + ms_iLocaleParamError = ms_iStaticErrorNumber++; + ms_iLocaleNotFoundError = ms_iStaticErrorNumber++; + ms_iPatternParamError = ms_iStaticErrorNumber++; + ms_iInvalidPatternError = ms_iStaticErrorNumber++; + ms_iRRuleParamError = ms_iStaticErrorNumber++; + ms_iERuleParamError = ms_iStaticErrorNumber++; + ms_iBoundParamError = ms_iStaticErrorNumber++; + ms_iInvalidRecurrenceError = ms_iStaticErrorNumber++; + ms_iUnzipNullError = ms_iStaticErrorNumber++; + ms_iCommandNotFoundError = ms_iStaticErrorNumber++; + ms_iInvalidTimeZoneError = ms_iStaticErrorNumber++; + ms_iFileNotFound = ms_iStaticErrorNumber++; + ms_iInvalidPropertyName = ms_iStaticErrorNumber++; + ms_iInvalidPropertyValue = ms_iStaticErrorNumber++; + ms_iInvalidParameterName = ms_iStaticErrorNumber++; + ms_iInvalidParameterValue = ms_iStaticErrorNumber++; + ms_iMissingStartingTime = ms_iStaticErrorNumber++; + ms_iMissingEndingTime = ms_iStaticErrorNumber++; + ms_iEndBeforeStartTime = ms_iStaticErrorNumber++; + ms_iMissingSeqNo = ms_iStaticErrorNumber++; + ms_iMissingReplySeq = ms_iStaticErrorNumber++; + ms_iMissingURL = ms_iStaticErrorNumber++; + ms_iMissingDTStamp = ms_iStaticErrorNumber++; + ms_iMissingUID = ms_iStaticErrorNumber++; + ms_iMissingDescription = ms_iStaticErrorNumber++; + ms_iMissingMethodProvided = ms_iStaticErrorNumber++; + ms_iMissingOrganizer = ms_iStaticErrorNumber++; + ms_iMissingSummary = ms_iStaticErrorNumber++; + ms_iMissingAttendees = ms_iStaticErrorNumber++; + ms_iInvalidVersionNumber = ms_iStaticErrorNumber++; + ms_iUnknownUID = ms_iStaticErrorNumber++; + ms_iMissingUIDInReply = ms_iStaticErrorNumber++; + ms_iMissingValidDTStamp = ms_iStaticErrorNumber++; + ms_iDeclineCounterCalledByAttendee = ms_iStaticErrorNumber++; + ms_iPublishCalledByAttendee = ms_iStaticErrorNumber++; + ms_iRequestCalledByAttendee = ms_iStaticErrorNumber++; + ms_iCancelCalledByAttendee = ms_iStaticErrorNumber++; + ms_iCounterCalledByOrganizer = ms_iStaticErrorNumber++; + ms_iRefreshCalledByOrganizer = ms_iStaticErrorNumber++; + ms_iReplyCalledByOrganizer = ms_iStaticErrorNumber++; + ms_iAddReplySequenceOutOfRange = ms_iStaticErrorNumber++; + ms_iDuplicatedProperty = ms_iStaticErrorNumber++; + ms_iDuplicatedParameter = ms_iStaticErrorNumber++; + ms_iConflictMethodAndStatus = ms_iStaticErrorNumber++; + ms_iConflictCancelAndConfirmedTentative = ms_iStaticErrorNumber++; + ms_iMissingUIDToMatchEvent = ms_iStaticErrorNumber++; + ms_iInvalidNumberFormat = ms_iStaticErrorNumber++; + ms_iDelegateRequestError = ms_iStaticErrorNumber++; + ms_iInvalidRecurrenceIDRange = ms_iStaticErrorNumber++; + ms_iUnknownRecurrenceID = ms_iStaticErrorNumber++; + ms_iPropertyValueTypeMismatch = ms_iStaticErrorNumber++; + ms_iInvalidRRule = ms_iStaticErrorNumber++; + ms_iInvalidExRule = ms_iStaticErrorNumber++; + ms_iInvalidRDate = ms_iStaticErrorNumber++; + ms_iInvalidExDate = ms_iStaticErrorNumber++; + ms_iInvalidEvent = ms_iStaticErrorNumber++; + ms_iInvalidComponent = ms_iStaticErrorNumber++; + ms_iInvalidAlarm = ms_iStaticErrorNumber++; + ms_iInvalidTZPart = ms_iStaticErrorNumber++; + ms_iInvalidAlarmCategory = ms_iStaticErrorNumber++; + ms_iInvalidAttendee = ms_iStaticErrorNumber++; + ms_iInvalidFreebusy = ms_iStaticErrorNumber++; + ms_iDurationAssertionFailed = ms_iStaticErrorNumber++; + ms_iDurationParseFailed = ms_iStaticErrorNumber++; + ms_iPeriodParseFailed = ms_iStaticErrorNumber++; + ms_iPeriodStartInvalid = ms_iStaticErrorNumber++; + ms_iPeriodEndInvalid = ms_iStaticErrorNumber++; + ms_iPeriodEndBeforeStart = ms_iStaticErrorNumber++; + ms_iPeriodDurationZero = ms_iStaticErrorNumber++; + ms_iFreebusyPeriodInvalid = ms_iStaticErrorNumber++; + ms_iOptParamInvalidPropertyValue = ms_iStaticErrorNumber++; + ms_iOptParamInvalidPropertyName = ms_iStaticErrorNumber++; + ms_iInvalidOptionalParam = ms_iStaticErrorNumber++; + ms_iAbruptEndOfParsing = ms_iStaticErrorNumber++; + ms_iLastModifiedBeforeCreated = ms_iStaticErrorNumber++; + ms_iMultipleOwners = ms_iStaticErrorNumber++; + ms_iMultipleOrganizers = ms_iStaticErrorNumber++; + ms_iMissingOwner = ms_iStaticErrorNumber++; + ms_iMissingDueTime = ms_iStaticErrorNumber++; + ms_iCompletedPercentMismatch = ms_iStaticErrorNumber++; + ms_iMissingFreqTagRecurrence = ms_iStaticErrorNumber++; + ms_iFreqIntervalMismatchRecurrence = ms_iStaticErrorNumber++; + ms_iInvalidPercentCompleteValue = ms_iStaticErrorNumber++; + ms_iInvalidPriorityValue = ms_iStaticErrorNumber++; + ms_iInvalidByHourValue = ms_iStaticErrorNumber++; + ms_iInvalidByMinuteValue = ms_iStaticErrorNumber++; + ms_iByDayFreqIntervalMismatch = ms_iStaticErrorNumber++; + ms_iInvalidByMonthDayValue = ms_iStaticErrorNumber++; + ms_iInvalidByYearDayValue = ms_iStaticErrorNumber++; + ms_iInvalidBySetPosValue = ms_iStaticErrorNumber++; + ms_iInvalidByWeekNoValue = ms_iStaticErrorNumber++; + ms_iInvalidWeekStartValue = ms_iStaticErrorNumber++; + ms_iInvalidByMonthValue = ms_iStaticErrorNumber++; + ms_iInvalidByDayValue = ms_iStaticErrorNumber++; + ms_iInvalidFrequency = ms_iStaticErrorNumber++; + ms_iInvalidDayArg = ms_iStaticErrorNumber++; + ms_iVerifyZeroError = ms_iStaticErrorNumber++; + ms_iRoundedPercentCompleteTo100 = ms_iStaticErrorNumber++; + ms_iRS200 = ms_iStaticErrorNumber++; + ms_iRS201 = ms_iStaticErrorNumber++; + ms_iRS202 = ms_iStaticErrorNumber++; + ms_iRS203 = ms_iStaticErrorNumber++; + ms_iRS204 = ms_iStaticErrorNumber++; + ms_iRS205 = ms_iStaticErrorNumber++; + ms_iRS206 = ms_iStaticErrorNumber++; + ms_iRS207 = ms_iStaticErrorNumber++; + ms_iRS208 = ms_iStaticErrorNumber++; + ms_iRS209 = ms_iStaticErrorNumber++; + ms_iRS210 = ms_iStaticErrorNumber++; + ms_iRS300 = ms_iStaticErrorNumber++; + ms_iRS301 = ms_iStaticErrorNumber++; + ms_iRS302 = ms_iStaticErrorNumber++; + ms_iRS303 = ms_iStaticErrorNumber++; + ms_iRS304 = ms_iStaticErrorNumber++; + ms_iRS305 = ms_iStaticErrorNumber++; + ms_iRS306 = ms_iStaticErrorNumber++; + ms_iRS307 = ms_iStaticErrorNumber++; + ms_iRS308 = ms_iStaticErrorNumber++; + ms_iRS309 = ms_iStaticErrorNumber++; + ms_iRS310 = ms_iStaticErrorNumber++; + ms_iRS311 = ms_iStaticErrorNumber++; + ms_iRS312 = ms_iStaticErrorNumber++; + ms_iRS400 = ms_iStaticErrorNumber++; + ms_iRS500 = ms_iStaticErrorNumber++; + ms_iRS501 = ms_iStaticErrorNumber++; + ms_iRS502 = ms_iStaticErrorNumber++; + ms_iRS503 = ms_iStaticErrorNumber++; + ms_iMissingUIDGenerateDefault = ms_iStaticErrorNumber++; + ms_iMissingStartingTimeGenerateDefault = ms_iStaticErrorNumber++; + ms_iMissingEndingTimeGenerateDefault = ms_iStaticErrorNumber++; + ms_iNegativeSequenceNumberGenerateDefault = ms_iStaticErrorNumber++; + ms_iDefaultTBEDescription = ms_iStaticErrorNumber++; + ms_iDefaultTBEClass = ms_iStaticErrorNumber++; + ms_iDefaultTBEStatus = ms_iStaticErrorNumber++; + ms_iDefaultTBETransp = ms_iStaticErrorNumber++; + ms_iDefaultTBERequestStatus = ms_iStaticErrorNumber++; + ms_iDefaultTBESummary = ms_iStaticErrorNumber++; + ms_iDefaultRecIDRange = ms_iStaticErrorNumber++; + ms_iDefaultAttendeeRole = ms_iStaticErrorNumber++; + ms_iDefaultAttendeeType = ms_iStaticErrorNumber++; + ms_iDefaultAttendeeExpect = ms_iStaticErrorNumber++; + ms_iDefaultAttendeeStatus = ms_iStaticErrorNumber++; + ms_iDefaultAttendeeRSVP = ms_iStaticErrorNumber++; + ms_iDefaultAlarmRepeat = ms_iStaticErrorNumber++; + ms_iDefaultAlarmDuration = ms_iStaticErrorNumber++; + ms_iDefaultAlarmCategories = ms_iStaticErrorNumber++; + ms_iDefaultFreebusyStatus = ms_iStaticErrorNumber++; + ms_iDefaultFreebusyType = ms_iStaticErrorNumber++; + ms_iDefaultDuration = ms_iStaticErrorNumber++; + ms_iDefaultAlarmDescriptionString = ms_iStaticErrorNumber++; + ms_iDefaultAlarmSummaryString = ms_iStaticErrorNumber++; + ms_iXTokenParamIgnored = ms_iStaticErrorNumber++; + ms_iXTokenComponentIgnored = ms_iStaticErrorNumber++; +} + +//--------------------------------------------------------------------- + +//--------------------------------------------------------------------- +// JulianFormatString +//--------------------------------------------------------------------- + +JulianFormatString * JulianFormatString::m_Instance = 0; + +//--------------------------------------------------------------------- + +JulianFormatString * +JulianFormatString::Instance() +{ + if (m_Instance == 0) + m_Instance = new JulianFormatString(); + PR_ASSERT(m_Instance != 0); + return m_Instance; +} + +//--------------------------------------------------------------------- + +JulianFormatString::~JulianFormatString() +{ + /* + if (m_Instance != 0) + { + delete m_Instance; m_Instance = 0; + } + */ +} + +//--------------------------------------------------------------------- + +JulianFormatString::JulianFormatString() +{ + ms_sDateTimeISO8601Pattern = "yyyyMMdd'T'HHmmss'Z'"; + ms_sDateTimeISO8601LocalPattern = "yyyyMMdd'T'HHmmss"; + ms_sDateTimeISO8601TimeOnlyPattern = "HHmmss"; + ms_sDateTimeISO8601DateOnlyPattern = "yyyyMMdd"; + ms_sDateTimeDefaultPattern = "MMM dd, yyyy h:mm a z"; + + // added dir, sent-by, cn 3-23-98 + // added language 4-28-98 + ms_sAttendeeAllMessage = "%m%C%s%l%R%S%V%T%E%D%d%M%N"; + ms_sAttendeeDoneActionMessage = "%m%C%s%l%R%S%T%D%d%M%N"; + ms_sAttendeeDoneDelegateToOnly = "%m%C%s%l%R%S%T%D%M%N"; + ms_sAttendeeDoneDelegateFromOnly = "%m%C%s%l%R%S%T%d%M%N"; + ms_sAttendeeNeedsActionMessage = "%m%C%s%l%R%V%E%T%D%d%M%N"; + ms_sAttendeeNeedsActionDelegateToOnly = "%m%C%s%l%R%V%E%T%D%M%N"; + ms_sAttendeeNeedsActionDelegateFromOnly = "%m%C%s%l%R%V%E%T%d%M%N"; + + ms_AttendeeStrDefaultFmt = "^N ^R ^z ^S"; + + ms_OrganizerStrDefaultFmt = "^N ^z"; + + ms_FreebusyStrDefaultFmt = "\tTYPE= ^T ^P\r\n"; + + ms_TZPartStrDefaultFmt = "\r\n\t\t%(EEE MM/dd/yy hh:mm:ss z)B,%x%(EEE MM/dd/yy hh:mm:ss z)y, NAME: %n, FROM: %f, TO: %d, comment: %K"; + ms_sTZPartAllMessage = "%B%x%y%f%d%n%K%Z"; + + ms_VAlarmStrDefaultFmt = "\r\nACTION = %l:DURATION = %z,%D,REPEAT = %A,%i,%S"; + ms_sVAlarmAllMessage = "%l%z%D%A%v%a%i%S%Z"; + + ms_VEventStrDefaultFmt = "[%(EEE MM/dd/yy hh:mm:ss a z)B - %(EEE MM/dd/yy hh:mm:ss a z)e (%D)] UID: %U, SEQ: %s, SUM: %S, LastM: %(EEE MM/dd/yy hh:mm:ss a z)M %(ORG:^z)J\r\n %(\r\n\t^N ^R, ^z ^S)v %w"; + ms_sVEventAllPropertiesMessage = "%J%v%a%k%c%K%H%t%i%D%B%e%C%X%E%O%M%L%p%x%y%R%o%T%r%s%g%S%h%U%u%w%Z"; + ms_sVEventCancelMessage = "%J%K%R%U%s%C%g%Z" ; + ms_sVEventRequestMessage = "%J%v%a%k%c%K%H%t%i%B%e%C%X%E%O%M%L%p%x%y%R%o%r%s%g%S%h%U%u%w%Z"; + ms_sVEventRecurRequestMessage = "%J%v%a%k%c%K%H%t%i%B%e%C%X%E%O%M%L%p%x%y%o%r%s%g%S%h%U%u%w%Z" ; + ms_sVEventCounterMessage = "%v%a%k%c%K%H%t%i%B%e%C%X%E%O%M%L%p%x%y%R%o%r%s%g%S%h%U%u%w%Z"; + ms_sVEventDeclineCounterMessage = "%J%K%R%U%s%T%C%Z"; + ms_sVEventAddMessage = "%J%v%a%k%c%K%H%t%i%B%e%C%X%E%O%M%L%p%x%y%R%o%r%s%g%S%h%U%u%w%Z"; + ms_sVEventRefreshMessage = "%v%R%U%C%K%H%Z"; + ms_sVEventReplyMessage = "%J%v%K%R%U%s%T%C%H%X%E"; + // 3-31-98 no attendees in publish anymore + ms_sVEventPublishMessage = "%J%a%k%c%K%H%t%i%B%e%C%X%E%O%M%L%p%x%y%R%o%r%s%g%S%h%U%u%w%Z"; + ms_sVEventRecurPublishMessage = "%J%a%k%c%K%H%t%i%B%e%C%X%E%O%M%L%p%x%y%o%r%s%g%S%h%U%u%w%Z"; + + ms_sVEventDelegateRequestMessage = "%v%K%B%e%i%R%U%s%C"; + ms_sVEventRecurDelegateRequestMessage = "%v%K%B%e%i%U%s%C"; + + // TODO: finish + ms_VTodoStrDefaultFmt = "[%('START:' EEE MM/dd/yy hh:mm:ss a z)B %('DUE:' EEE MM/dd/yy hh:mm:ss z)F %('COMPLETED:' EEE MM/dd/yy hh:mm:ss z)G] UID: %U, SEQ: %s, SUM: %S, LastM: %(EEE MM/dd/yy hh:mm:ss a z)M %(ORG:^z)J\r\n %(\r\n\t^N ^R, ^z ^S)v %w"; + ms_sVTodoAllPropertiesMessage = "%J%v%a%k%c%K%H%t%i%D%B%F%G%P%C%X%E%O%M%L%p%x%y%R%o%T%r%s%g%S%U%u%w%Z"; + ms_sVTodoCancelMessage = "%J%K%R%U%s%C%g%Z" ; + ms_sVTodoRequestMessage = "%J%v%a%k%c%K%H%t%i%B%F%G%P%C%X%E%O%M%L%p%x%y%R%o%r%s%g%S%U%u%w%Z"; + ms_sVTodoRecurRequestMessage = "%J%v%a%k%c%K%H%t%i%B%F%G5P%C%X%E%O%M%L%p%x%y%o%r%s%g%S%U%u%w%Z" ; + ms_sVTodoCounterMessage = "%v%a%k%c%K%H%t%i%B%F%G%P%C%X%E%O%M%L%p%x%y%R%o%r%s%g%S%U%u%w%Z"; + ms_sVTodoDeclineCounterMessage = "%J%K%R%U%s%T%C%Z"; + ms_sVTodoAddMessage = "%J%v%a%k%c%K%H%t%i%B%F%G%P%C%X%E%O%M%L%p%x%y%R%o%r%s%g%S%U%u%w%Z"; + ms_sVTodoRefreshMessage = "%v%R%U%C%K%H%Z"; + ms_sVTodoReplyMessage = "%J%v%K%R%U%s%T%C%H%X%E"; + // 4-22-98 no attendees in publish anymore + ms_sVTodoPublishMessage = "%J%a%k%c%K%H%t%i%B%F%G%P%C%X%E%O%M%L%p%x%y%R%o%r%s%g%S%U%u%w%Z"; + ms_sVTodoRecurPublishMessage = "%J%a%k%c%K%H%t%i%B%F%G%P%C%X%E%O%M%L%p%x%y%o%r%s%g%S%U%u%w%Z"; + /* + ms_VTodoStrDefaultFmt = "[%(EEE MM/dd/yy hh:mm:ss a z)B - %(EEE MM/dd/yy hh:mm:ss a z)F (%D)] UID: %U, SEQ: %s, SUM: %S, LastM: %(EEE MM/dd/yy hh:mm:ss a z)M %(ORG:^z)J\r\n %(\r\n\t^N ^R, ^z ^S)v %w"; + ms_sVTodoAllPropertiesMessage = "%J%v%a%k%c%K%H%t%i%D%B%F%G%C%X%E%O%M%L%p%x%y%R%o%T%r%s%g%S%P%U%u%w%Z"; + ms_sVTodoCancelMessage = "%J%K%R%U%s%C%g%Z" ; + ms_sVTodoRequestMessage = "%J%v%a%k%c%K%H%t%i%B%F%G%C%X%E%O%M%L%p%x%y%R%o%r%s%g%S%P%U%u%w%Z"; + ms_sVTodoRecurRequestMessage = "%J%v%a%k%c%K%H%t%i%B%F%G%C%X%E%O%M%L%p%x%y%o%r%s%g%S%P%U%u%w%Z" ; + ms_sVTodoCounterMessage = "%v%a%k%c%K%H%t%i%B%F%G%C%X%E%O%M%L%p%x%y%R%o%r%s%g%S%P%U%u%w%Z"; + ms_sVTodoDeclineCounterMessage = "%J%K%R%U%s%T%C%Z"; + ms_sVTodoAddMessage = "%J%v%a%k%c%K%H%t%i%B%F%G%C%X%E%O%M%L%p%x%y%R%o%r%s%g%S%P%U%u%w%Z"; + ms_sVTodoRefreshMessage = "%v%R%U%C%K%H%Z"; + ms_sVTodoReplyMessage = "%J%v%K%R%U%s%T%C%H%X%E"; + // 4-22-98 no attendees in publish anymore + ms_sVTodoPublishMessage = "%J%a%k%c%K%H%t%i%B%F%G%C%X%E%O%M%L%p%x%y%R%o%r%s%g%S%P%U%u%w%Z"; + ms_sVTodoRecurPublishMessage = "%J%a%k%c%K%H%t%i%B%F%G%C%X%E%O%M%L%p%x%y%o%r%s%g%S%P%U%u%w%Z"; +*/ + //ms_sVTodoDelegateRequestMessage = "%v%K%B%F%G%i%R%U%s%C"; + //ms_sVTodoRecurDelegateRequestMessage = "%v%K%B%F%G%i%U%s%C"; + + // TODO: finish + ms_VJournalStrDefaultFmt = "[%(EEE MM/dd/yy hh:mm:ss a z)B] UID: %U, SEQ: %s, SUM: %S, LastM: %(EEE MM/dd/yy hh:mm:ss a z)M %(ORG:^z)J\r\n %(\r\n\t^N ^R, ^z ^S)v %w"; + ms_sVJournalAllPropertiesMessage = "%J%v%a%k%c%K%H%t%i%D%B%C%X%E%O%M%L%p%x%y%R%o%T%r%s%g%S%U%u%w%Z"; + ms_sVJournalCancelMessage = "%J%K%R%U%s%C%g%Z" ; + ms_sVJournalRequestMessage = "%J%v%a%k%c%K%H%t%i%B%C%X%E%O%M%L%p%x%y%R%o%r%s%g%S%U%u%w%Z"; + ms_sVJournalRecurRequestMessage = "%J%v%a%k%c%K%H%t%i%B%C%X%E%O%M%L%p%x%y%o%r%s%g%S%U%u%w%Z" ; + ms_sVJournalCounterMessage = "%v%a%k%c%K%H%t%i%B%C%X%E%O%M%L%p%x%y%R%o%r%s%g%S%U%u%w%Z"; + ms_sVJournalDeclineCounterMessage = "%J%K%R%U%s%T%C%Z"; + ms_sVJournalAddMessage = "%J%v%a%k%c%K%H%t%i%B%C%X%E%O%M%L%p%x%y%R%o%r%s%g%S%U%u%w%Z"; + ms_sVJournalRefreshMessage = "%v%R%U%C%K%H%Z"; + ms_sVJournalReplyMessage = "%J%v%K%R%U%s%T%C%H%X%E"; + // 4-22-98 no attendees in publish anymore + ms_sVJournalPublishMessage = "%J%a%k%c%K%H%t%i%B%C%X%E%O%M%L%p%x%y%R%o%r%s%g%S%U%u%w%Z"; + ms_sVJournalRecurPublishMessage = "%J%a%k%c%K%H%t%i%B%C%X%E%O%M%L%p%x%y%o%r%s%g%S%U%u%w%Z"; + + ms_sVFreebusyReplyMessage = "%J%v%Y%C%B%e%o%T%U%K%t%M%u%Z"; + + // 3-31-98 no attendees in publish anymore + ms_sVFreebusyPublishMessage = "%J%Y%H%B%e%C%o%U%K%t%M%Z"; + + ms_sVFreebusyRequestMessage = "%J%v%C%B%e%s%U%Z"; + ms_sVFreebusyAllMessage = "%J%v%Y%C%B%e%D%o%T%U%K%t%M%u%s%Z"; + ms_VFreebusyStrDefaultFmt = "%[(EEE MM/dd/yy hh:mm:ss z)B - %(EEE MM/dd/yy hh:mm:ss z)e (%D)], \r\n\t %U, %s, \r\n%Y\r\n %(ORG:^z)J\r\n %(\r\n\t^N ^R, ^z ^S)v %w"; + + ms_VTimeZoneStrDefaultFmt = "%I - %(EEE MM/dd/yy hh:mm:ss z)M %Q\t%V"; + ms_sVTimeZoneAllMessage = "%I%M%Q%V%Z"; + + /* + ms_asDateTimePatterns = + { + UnicodeString("yyyy MM dd HH m s z"), + UnicodeString("yyyy MM dd HH m s"), + UnicodeString("EEE MMM dd hh:mm:ss z yyyy"), + UnicodeString("MMM dd, yyyy h:m a"), + UnicodeString("MMM dd, yyyy h:m z"), + UnicodeString("MMM dd, yyyy h:m:s a"), + UnicodeString("MMM dd, yyyy h:m:s z"), + UnicodeString("MMMM dd, yyyy h:m a"), + UnicodeString("MMMM dd, yyyy h:m:s a"), + UnicodeString("dd MMM yyyy h:m:s z"), + UnicodeString("dd MMM yyyy h:m:s z"), + UnicodeString("MM/dd/yy hh:mm:s a"), + UnicodeString("MM/dd/yy hh:mm:s z"), + UnicodeString("MM/dd/yy hh:mm z"), + UnicodeString("MM/dd/yy hh:mm"), + UnicodeString("hh:mm MM/d/y z") + }; + */ + + ms_asDateTimePatterns[0] = "yyyy MM dd HH m s z"; + ms_asDateTimePatterns[1] = "yyyy MM dd HH m s"; + ms_asDateTimePatterns[2] = "EEE MMM dd hh:mm:ss z yyyy"; + ms_asDateTimePatterns[3] = "MMM dd, yyyy h:m a"; + ms_asDateTimePatterns[4] = "MMM dd, yyyy h:m z"; + ms_asDateTimePatterns[5] = "MMM dd, yyyy h:m:s a"; + ms_asDateTimePatterns[6] = "MMM dd, yyyy h:m:s z"; + ms_asDateTimePatterns[7] = "MMMM dd, yyyy h:m a"; + ms_asDateTimePatterns[8] = "MMMM dd, yyyy h:m:s a"; + ms_asDateTimePatterns[9] = "dd MMM yyyy h:m:s z"; + ms_asDateTimePatterns[10] = "dd MMM yyyy h:m:s z"; + ms_asDateTimePatterns[11] = "MM/dd/yy hh:mm:s a"; + ms_asDateTimePatterns[12] = "MM/dd/yy hh:mm:s z"; + ms_asDateTimePatterns[13] = "MM/dd/yy hh:mm z"; + ms_asDateTimePatterns[14] = "MM/dd/yy hh:mm"; + ms_asDateTimePatterns[15] = "hh:mm MM/d/y z"; +} + + diff --git a/calendar/modules/util/src/manifest.mn b/calendar/modules/util/src/manifest.mn index 1db00be6e05..e69de29bb2d 100644 --- a/calendar/modules/util/src/manifest.mn +++ b/calendar/modules/util/src/manifest.mn @@ -1,29 +0,0 @@ -# -# CONFIDENTIAL AND PROPRIETARY SOURCE CODE OF -# NETSCAPE COMMUNICATIONS CORPORATION -# Copyright (C) 1996 Netscape Communications Corporation. All Rights -# Reserved. Use of this Source Code is subject to the terms of the -# applicable license agreement from Netscape Communications Corporation. -# The copyright notice(s) in this Source Code does not indicate actual or -# intended publication of this Source Code. -# -GDEPTH = ../../../.. - -EXPORTS = \ - $(NULL) - -PRIVATE_EXPORTS = \ - $(NULL) - -MODULE = trex - -CPPSRCS = \ - nsCurlParser.cpp \ - nsX400Parser.cpp \ - nsDateTime.cpp \ - nsDuration.cpp \ - nsUtilFactory.cpp \ - $(NULL) - -REQUIRES = xpcom raptor shell trex julian nls - diff --git a/calendar/modules/util/src/ptrarray.cpp b/calendar/modules/util/src/ptrarray.cpp new file mode 100644 index 00000000000..3ab1a78a8dd --- /dev/null +++ b/calendar/modules/util/src/ptrarray.cpp @@ -0,0 +1,381 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +/** + * a pointer array with no external references into the source tree. + * + * With apologies to the original authors + * sman + */ +#include "stdafx.h" +#include "jdefines.h" + +#include +#include + +#include "ptrarray.h" + +#ifndef MAX +#define MAX(a,b) (((a)>(b))?(a):(b)) +#endif + +#ifndef MIN +#define MIN(a,b) (((a)<(b))?(a):(b)) +#endif + + +#ifdef _DEBUG +#undef THIS_FILE +static char THIS_FILE[] = __FILE__; +#endif + +#ifdef XP_WIN16 +#define SIZE_T_MAX 0xFF80 // a little less than 64K, the max alloc size on win16. +#define MAX_ARR_ELEMS SIZE_T_MAX/sizeof(void*) +#endif + +///////////////////////////////////////////////////////////////////////////// + +JulianPtrArray::JulianPtrArray() +{ + m_pData = 0; + m_nSize = m_nMaxSize = m_nGrowBy = 0; +} + +JulianPtrArray::~JulianPtrArray() +{ +// XP_ASSERT_VALID(this); + + delete[] (char*)m_pData; +} + +XP_Bool JulianPtrArray::SetSize(int nNewSize, int nGrowBy) +{ +// XP_ASSERT_VALID(this); +// XP_ASSERT(nNewSize >= 0); + + if (nGrowBy != -1) + m_nGrowBy = nGrowBy; // set new size + + if (nNewSize == 0) + { + // shrink to nothing + delete[] (char*)m_pData; + m_pData = 0; + m_nSize = m_nMaxSize = 0; + } + else if (m_pData == 0) + { + // create one with exact size +#ifdef SIZE_T_MAX +// XP_ASSERT(nNewSize <= SIZE_T_MAX/sizeof(void*)); // no overflow +#endif + m_pData = (void**) new char[nNewSize * sizeof(void*)]; + if (m_pData == 0) + { + m_nSize = 0; + return 0; + } + + memset(m_pData, 0, nNewSize * sizeof(void*)); // zero fill + + m_nSize = m_nMaxSize = nNewSize; + } + else if (nNewSize <= m_nMaxSize) + { + // it fits + if (nNewSize > m_nSize) + { + // initialize the new elements + memset(&m_pData[m_nSize], 0, (nNewSize-m_nSize) * sizeof(void*)); + } + + m_nSize = nNewSize; + } + else + { + // otherwise, grow array + int nGrowBy = m_nGrowBy; + if (nGrowBy == 0) + { + // heuristically determine growth when nGrowBy == 0 + // (this avoids heap fragmentation in many situations) + nGrowBy = MIN(1024, MAX(4, m_nSize / 8)); + } +#ifdef MAX_ARR_ELEMS + if (m_nSize + nGrowBy > MAX_ARR_ELEMS) + nGrowBy = MAX_ARR_ELEMS - m_nSize; +#endif + int nNewMax; + if (nNewSize < m_nMaxSize + nGrowBy) + nNewMax = m_nMaxSize + nGrowBy; // granularity + else + nNewMax = nNewSize; // no slush + +#ifdef SIZE_T_MAX + if (nNewMax >= SIZE_T_MAX/sizeof(void*)) + return 0; +// XP_ASSERT(nNewMax <= SIZE_T_MAX/sizeof(void*)); // no overflow +#endif +// XP_ASSERT(nNewMax >= m_nMaxSize); // no wrap around + void** pNewData = (void**) new char[nNewMax * sizeof(void*)]; + + if (pNewData != 0) + { + // copy new data from old + memcpy(pNewData, m_pData, m_nSize * sizeof(void*)); + + // construct remaining elements +// XP_ASSERT(nNewSize > m_nSize); + + memset(&pNewData[m_nSize], 0, (nNewSize-m_nSize) * sizeof(void*)); + + + // get rid of old stuff (note: no destructors called) + delete[] (char*)m_pData; + m_pData = pNewData; + m_nSize = nNewSize; + m_nMaxSize = nNewMax; + } + else + { + return 0; + } + } + return 1; +} + +void JulianPtrArray::FreeExtra() +{ +// XP_ASSERT_VALID(this); + + if (m_nSize != m_nMaxSize) + { + // shrink to desired size +#ifdef SIZE_T_MAX +// XP_ASSERT(m_nSize <= SIZE_T_MAX/sizeof(void*)); // no overflow +#endif + void** pNewData = 0; + if (m_nSize != 0) + { + pNewData = (void**) new char[m_nSize * sizeof(void*)]; + // copy new data from old + memcpy(pNewData, m_pData, m_nSize * sizeof(void*)); + } + + // get rid of old stuff (note: no destructors called) + delete[] (char*)m_pData; + m_pData = pNewData; + m_nMaxSize = m_nSize; + } +} + +///////////////////////////////////////////////////////////////////////////// + +void JulianPtrArray::SetAtGrow(int nIndex, void* newElement) +{ +// XP_ASSERT_VALID(this); +// XP_ASSERT(nIndex >= 0); + + if (nIndex >= m_nSize) + SetSize(nIndex+1); + m_pData[nIndex] = newElement; +} + +void JulianPtrArray::InsertAt(int nIndex, void* newElement, int nCount) +{ +// XP_ASSERT_VALID(this); +// XP_ASSERT(nIndex >= 0); // will expand to meet need +// XP_ASSERT(nCount > 0); // zero or negative size not allowed + + if (nIndex >= m_nSize) + { + // adding after the end of the array + SetSize(nIndex + nCount); // grow so nIndex is valid + } + else + { + // inserting in the middle of the array + int nOldSize = m_nSize; + SetSize(m_nSize + nCount); // grow it to new size + // shift old data up to fill gap + memmove(&m_pData[nIndex+nCount], &m_pData[nIndex], + (nOldSize-nIndex) * sizeof(void*)); + + // re-init slots we copied from + + memset(&m_pData[nIndex], 0, nCount * sizeof(void*)); + + } + + // insert new value in the gap +// XP_ASSERT(nIndex + nCount <= m_nSize); + while (nCount--) + m_pData[nIndex++] = newElement; +} + +// returns 1 if ptr was found, and therefore removed. +XP_Bool JulianPtrArray::Remove(void *pToRemove) +{ + int index = FindIndex(0, pToRemove); + if (index != -1) + { + RemoveAt(index); + return 1; + } + else + return 0; + +} + +void JulianPtrArray::RemoveAt(int nIndex, int nCount) +{ +// XP_ASSERT_VALID(this); +// XP_ASSERT(nIndex >= 0); +// XP_ASSERT(nCount >= 0); +// XP_ASSERT(nIndex + nCount <= m_nSize); + + // just remove a range + int nMoveCount = m_nSize - (nIndex + nCount); + + if (nMoveCount) + /*XP_MEMMOVE*/ memmove(&m_pData[nIndex], &m_pData[nIndex + nCount], + nMoveCount * sizeof(void*)); + m_nSize -= nCount; +} + +void JulianPtrArray::InsertAt(int nStartIndex, const JulianPtrArray* pNewArray) +{ +// XP_ASSERT_VALID(this); +// XP_ASSERT(pNewArray != 0); +// XP_ASSERT_VALID(pNewArray); +// XP_ASSERT(nStartIndex >= 0); + + if (pNewArray->GetSize() > 0) + { + InsertAt(nStartIndex, pNewArray->GetAt(0), pNewArray->GetSize()); + for (int i = 0; i < pNewArray->GetSize(); i++) + SetAt(nStartIndex + i, pNewArray->GetAt(i)); + } +} + +// Remove all elements in pArray from 'this' +void JulianPtrArray::RemoveAt (int nStartIndex, const JulianPtrArray *pArray) +{ +// XP_ASSERT(pArray!= 0); +// XP_ASSERT(nStartIndex >= 0); + + if (pArray->GetSize() > 0) + for (int i = 0; i < pArray->GetSize(); i++) + { + int index = FindIndex(nStartIndex, pArray->GetAt(i)); + if (index >= 0) + RemoveAt (index); + } +} + +void JulianPtrArray::QuickSort (int ( *compare )(const void *elem1, const void *elem2 )) +{ + if (m_nSize > 1) + /*XP_QSORT*/ qsort(m_pData, m_nSize, sizeof(void*), compare); + +} + +int JulianPtrArray::FindIndex (int nStartIndex, void *pToFind) const +{ + for (int i = nStartIndex; i < GetSize(); i++) + if (m_pData[i] == pToFind) + return i; + return -1; +} + +int JulianPtrArray::GetSize() const { return m_nSize; } +int JulianPtrArray::GetUpperBound() const { return m_nSize-1; } +void JulianPtrArray::RemoveAll() { SetSize(0); } + +void* JulianPtrArray::GetAt(int nIndex) const +{ +// XP_ASSERT(nIndex >= 0 && nIndex < m_nSize); + return m_pData[nIndex]; +} + +void JulianPtrArray::SetAt(int nIndex, void* newElement) +{ +// XP_ASSERT(nIndex >= 0 && nIndex < m_nSize); + m_pData[nIndex] = newElement; +} + +void*& JulianPtrArray::ElementAt(int nIndex) +{ +// XP_ASSERT(nIndex >= 0 && nIndex < m_nSize); + return m_pData[nIndex]; +} + +int JulianPtrArray::Add(void* newElement) +{ + int nIndex = m_nSize; +#ifdef XP_WIN16 + if (nIndex >= 0x10000L / 4L) + { +// XP_ASSERT(0); + return -1; + } +#endif + SetAtGrow(nIndex, newElement); + return nIndex; +} + +void* JulianPtrArray::operator[](int nIndex) const { return GetAt(nIndex); } +void*& JulianPtrArray::operator[](int nIndex) { return ElementAt(nIndex); } + + +XP_Bool JulianPtrArray::IsValidIndex(int32 nIndex) +{ + return (nIndex < GetSize() && nIndex >= 0); +} + +int JulianPtrArray::InsertBinary(void* newElement, int ( *compare )(const void *elem1, const void *elem2 )) +{ + int current = 0; + int left = 0; + int right = GetSize() - 1; + int comparison = 0; + + while (left <= right) + { + current = (left + right) / 2; + + void* pCurrent = GetAt(current); + + comparison = compare(&pCurrent, &newElement); + // comparison = compare(pCurrent, newElement); + + if (comparison == 0) + break; + else if (comparison > 0) + right = current - 1; + else + left = current + 1; + } + + if (comparison < 0) + current += 1; + + JulianPtrArray::InsertAt(current, newElement); + return current; +} diff --git a/calendar/modules/util/src/uidrgntr.cpp b/calendar/modules/util/src/uidrgntr.cpp new file mode 100644 index 00000000000..cd7d5b5ffb9 --- /dev/null +++ b/calendar/modules/util/src/uidrgntr.cpp @@ -0,0 +1,76 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +// uidrgntr.cpp +// John Sun +// 3/19/98 5:41:26 PM + +#include +#include +#include + +#include "stdafx.h" +#include "jdefines.h" + +#include "uidrgntr.h" +#include "datetime.h" + +//--------------------------------------------------------------------- + +JulianUIDRandomGenerator::JulianUIDRandomGenerator() +{ +} + +//--------------------------------------------------------------------- + +JulianUIDRandomGenerator::~JulianUIDRandomGenerator() +{ +} + +//--------------------------------------------------------------------- + +UnicodeString +JulianUIDRandomGenerator::generate(UnicodeString us) +{ +#if 0 + char sBuf[10]; + UnicodeString u; + DateTime d; + u += d.toISO8601(); + u += '-'; + srand((unsigned) time(0)); + sprintf(sBuf, "%.9x", rand()); + u += sBuf; + // TODO: Append hostname or email + u += '-'; + u += us; + return u; +#else + return ""; +#endif +} + +//--------------------------------------------------------------------- + +UnicodeString +JulianUIDRandomGenerator::generate() +{ + return generate(""); +} + +//--------------------------------------------------------------------- diff --git a/trex.mak b/trex.mak index 604d0725737..7ce91632e8b 100644 --- a/trex.mak +++ b/trex.mak @@ -106,9 +106,6 @@ TREX_TREX_DIR = mozilla/calendar LIBNLS_BRANCH = -r libnls_v3_Normandy LIBNLS_DIR = ns/modules/libnls -JULIAN_BRANCH = -JULIAN_DIR = $(MOZ_TOP)/modules/calendar - # $(MOZ_TOP)/LICENSE # $(MOZ_TOP)/LEGAL # $(MOZ_TOP)/lib/liblayer @@ -209,7 +206,6 @@ pull_julian:: cd $(MOZ_SRC)\ns\. -$(CVST) -d config ns/clientconfig cd $(MOZ_SRC)\. - -$(CVS) $(JULIAN_BRANCH) $(JULIAN_DIR) -$(CVST) $(LIBNLS_BRANCH) $(LIBNLS_DIR) cd $(MOZ_SRC)\. @@ -238,10 +234,10 @@ build_platform:: cd $(MOZ_SRC)\. build_julian:: +!if !defined(MOZ_TREX_FREE) cd $(MOZ_SRC)\ns\modules\libnls nmake -f makefile.win - cd $(MOZ_SRC)\mozilla\modules\calendar - nmake -f makefile.win +!endif cd $(MOZ_SRC)\. build_trex:: @@ -259,10 +255,10 @@ depend_dist:: cd $(MOZ_SRC)\. depend_julian:: +!if !defined(MOZ_TREX_FREE) cd $(MOZ_SRC)\ns\modules\libnls nmake -f makefile.win depend - cd $(MOZ_SRC)\$(MOZ_TOP)\modules\calendar - nmake -f makefile.win depend +!endif cd $(MOZ_SRC)\. depend_trex:: @@ -278,9 +274,9 @@ clobber_dist:: cd $(MOZ_SRC)\. clobber_julian:: +!if !defined(MOZ_TREX_FREE) cd $(MOZ_SRC)\ns\modules\libnls - nmake -f makefile.win clobber_all - cd $(MOZ_SRC)\$(MOZ_TOP)\modules\calendar +!endif nmake -f makefile.win clobber_all cd $(MOZ_SRC)\. diff --git a/trex.mk b/trex.mk index ac53ab2fcba..222d3740fc8 100644 --- a/trex.mk +++ b/trex.mk @@ -39,9 +39,6 @@ CVST=cvs -q -d $(CVTREX) co -P LIBNLS_BRANCH = -r libnls_v3_Normandy LIBNLS_DIR = ns/modules/libnls -JULIAN_BRANCH = -JULIAN_DIR = mozilla/modules/calendar - default: pull_all build_all @@ -62,7 +59,6 @@ pull_julian: cd $(MOZ_SRC)/ns/.; \ $(CVST) -d config ns/clientconfig; \ cd $(MOZ_SRC); \ - $(CVS) $(JULIAN_BRANCH) $(JULIAN_DIR); \ $(CVST) $(LIBNLS_BRANCH) $(LIBNLS_DIR); \ cd $(MOZ_SRC) @@ -84,8 +80,6 @@ build_platform: build_julian:: cd $(MOZ_SRC)/ns/modules/libnls; \ gmake; \ - cd $(MOZ_SRC)/mozilla/modules/calendar; \ - gmake; \ cd $(MOZ_SRC)