From b485b5bd72412a0d2f0fa093ec8945841f3f1b0a Mon Sep 17 00:00:00 2001 From: Morten Braten Date: Mon, 14 Jan 2019 18:10:28 +0100 Subject: [PATCH] Enhanced iCalendar protocol support --- ora/icalendar_util_pkg.pkb | 78 +++++++++++++++++++++++++++++--------- ora/icalendar_util_pkg.pks | 13 +++++-- 2 files changed, 71 insertions(+), 20 deletions(-) diff --git a/ora/icalendar_util_pkg.pkb b/ora/icalendar_util_pkg.pkb index 101fe21..4bbb452 100755 --- a/ora/icalendar_util_pkg.pkb +++ b/ora/icalendar_util_pkg.pkb @@ -16,7 +16,30 @@ as m_protocol_version constant varchar2(3) := '2.0'; m_date_format constant varchar2(30) := 'YYYYMMDD"T"HH24MISS'; m_line_delimiter constant varchar2(2) := chr(13) || chr(10); + + m_prodid varchar2(2000); + + +procedure set_prodid (p_prodid in varchar2) +as +begin + + /* + Purpose: set prodid (company/product name) + + Remarks: + + Who Date Description + ------ ---------- -------------------------------- + MBR 07.03.2018 Created + + */ + + m_prodid := substr(p_prodid, 1, 2000); + +end set_prodid; + function fmt_date (p_date in date) return varchar2 as @@ -85,6 +108,8 @@ begin */ -- TODO: "Actual line feeds in data items are encoded as a backslash followed by the letter N (the bytes 5C 6E or 5C 4E in UTF-8). " + + -- TODO: Encode text according to https://tools.ietf.org/html/rfc5545#section-3.3.11 l_returnvalue := p_text; @@ -93,8 +118,7 @@ begin end fmt_text; -function add_core_object (p_ical_body in varchar2, - p_prod_id in varchar2 := null) return varchar2 +function add_core_object (p_ical_body in varchar2) return varchar2 as l_returnvalue string_util_pkg.t_max_pl_varchar2; begin @@ -113,7 +137,7 @@ begin l_returnvalue := 'BEGIN:VCALENDAR' || m_line_delimiter || 'VERSION:' || m_protocol_version || m_line_delimiter || - 'PRODID:' || nvl(p_prod_id, '-//My Company//NONSGML My Product//EN') || m_line_delimiter || + 'PRODID:' || nvl(m_prodid, '-//My Company//NONSGML My Product//EN') || m_line_delimiter || p_ical_body || m_line_delimiter || 'END:VCALENDAR'; @@ -122,14 +146,14 @@ begin end add_core_object; -function get_event (p_event in t_event) return varchar2 +function get_event_str (p_event in t_event) return varchar2 as l_returnvalue string_util_pkg.t_max_pl_varchar2; begin /* - Purpose: get event + Purpose: get event string Remarks: @@ -147,20 +171,46 @@ begin 'DTSTART:' || fmt_date(p_event.start_date) || m_line_delimiter || 'DTEND:' || fmt_date(nvl(p_event.end_date, p_event.start_date)) || m_line_delimiter || 'DTSTAMP:' || fmt_date(sysdate) || m_line_delimiter || - 'UID:' || nvl(p_event.uid, rawtohex(sys_guid()) || '@domain.example') || m_line_delimiter || - 'STATUS:NEEDS-ACTION' || m_line_delimiter || + 'UID:' || nvl(p_event.uid, rawtohex(sys_guid()) || chr(64) || 'domain.example') || m_line_delimiter || + 'STATUS:' || nvl(p_event.status, 'CONFIRMED') || m_line_delimiter || 'END:VEVENT'; l_returnvalue := add_core_object (l_returnvalue); return l_returnvalue; -end get_event; +end get_event_str; + +procedure download_event_str (p_event_str in varchar2, + p_filename in varchar2 := null) +as + l_event_str string_util_pkg.t_max_pl_varchar2; +begin + + /* + + Purpose: download event string + + Remarks: + + Who Date Description + ------ ---------- -------------------------------- + MBR 07.03.2018 Created + + */ + + owa_util.mime_header('text/calendar', false); + htp.p('Content-length: ' || length(p_event_str)); + htp.p('Content-Disposition: attachment; filename="' || nvl(p_filename, 'event.ics') || '"'); + owa_util.http_header_close; + + htp.prn (p_event_str); + +end download_event_str; procedure download_event (p_event in t_event) as - l_event_str string_util_pkg.t_max_pl_varchar2; begin /* @@ -172,17 +222,11 @@ begin Who Date Description ------ ---------- -------------------------------- MBR 26.10.2012 Created + MBR 07.03.2018 Refactored */ - l_event_str := get_event (p_event); - - owa_util.mime_header('text/calendar', false); - htp.p('Content-length: ' || length(l_event_str)); - htp.p('Content-Disposition: attachment; filename="' || file_util_pkg.get_filename_str(p_event.summary, 'ics') || '"'); - owa_util.http_header_close; - - htp.prn (l_event_str); + download_event_str (p_event_str => get_event_str (p_event), p_filename => file_util_pkg.get_filename_str(p_event.summary, 'ics')); end download_event; diff --git a/ora/icalendar_util_pkg.pks b/ora/icalendar_util_pkg.pks index 3baf2ad..b3a4416 100755 --- a/ora/icalendar_util_pkg.pks +++ b/ora/icalendar_util_pkg.pks @@ -6,7 +6,7 @@ as Purpose: Package handles the iCalendar protocol (RFC 5545) Remarks: see http://en.wikipedia.org/wiki/ICalendar and http://tools.ietf.org/html/rfc5545 - + Who Date Description ------ ---------- -------------------------------- MBR 26.10.2012 Created @@ -21,13 +21,20 @@ as location varchar2(2000), organizer_name varchar2(2000), organizer_email varchar2(2000), + status varchar2(2000), uid varchar2(2000) ); + -- set prodid (company/product name) + procedure set_prodid (p_prodid in varchar2); - -- get event - function get_event (p_event in t_event) return varchar2; + -- get event string + function get_event_str (p_event in t_event) return varchar2; + -- download event string + procedure download_event_str (p_event_str in varchar2, + p_filename in varchar2 := null); + -- download event procedure download_event (p_event in t_event);