diff --git a/.krazy b/.krazy index 49d211097..04d7bc194 100644 --- a/.krazy +++ b/.krazy @@ -1,2 +1,2 @@ -SKIP /libical.*/|/versit/|/tests/ +SKIP /libical.*/|/tests/ EXTRA kdebug,tipsandthis,defines,qenums,null,camelcase diff --git a/CMakeLists.txt b/CMakeLists.txt index 21c7f2f2d..939b4da16 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,99 +1,91 @@ cmake_minimum_required(VERSION 3.0) set(PIM_VERSION "5.7.40") project(KCalCore VERSION ${PIM_VERSION}) # ECM setup set(KF5_VERSION "5.43.0") find_package(ECM ${KF5_VERSION} CONFIG REQUIRED) set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH} ${KCalCore_SOURCE_DIR}/cmake) include(GenerateExportHeader) include(ECMGenerateHeaders) include(ECMGeneratePriFile) include(CMakePackageConfigHelpers) include(ECMSetupVersion) include(FeatureSummary) include(KDEInstallDirs) include(KDECMakeSettings) include(KDEFrameworkCompilerSettings NO_POLICY_SCOPE) include(ECMQtDeclareLoggingCategory) include(ECMCoverageOption) if(POLICY CMP0053) cmake_policy(SET CMP0053 NEW) endif() set(QT_REQUIRED_VERSION "5.8.0") set(KCALENDARCORE_LIB_VERSION ${PIM_VERSION}) ecm_setup_version(PROJECT VARIABLE_PREFIX KCALCORE VERSION_HEADER "${KCalCore_BINARY_DIR}/kcalcore_version.h" PACKAGE_VERSION_FILE "${KCalCore_BINARY_DIR}/KF5CalendarCoreConfigVersion.cmake" SOVERSION 5 ) ########### Find packages ########### find_package(Qt5 ${QT_REQUIRED_VERSION} CONFIG REQUIRED Core Gui) set(LibIcal_MIN_VERSION "1.0") find_package(LibIcal ${LibIcal_MIN_VERSION}) set_package_properties(LibIcal PROPERTIES TYPE REQUIRED) if(LibIcal_VERSION VERSION_GREATER "2.98") set(HAVE_ICAL_3 TRUE) add_definitions(-DUSE_ICAL_3) endif() -find_package(BISON REQUIRED) -set_package_properties(BISON PROPERTIES - DESCRIPTION "general-purpose parser generator" - URL "http://www.gnu.org/software/bison" - PURPOSE "Required for the Versit parser" - TYPE REQUIRED -) - ########### CMake Config Files ########### set(CMAKECONFIG_INSTALL_DIR "${KDE_INSTALL_CMAKEPACKAGEDIR}/KF5CalendarCore") configure_package_config_file( "${CMAKE_CURRENT_SOURCE_DIR}/KF5CalendarCoreConfig.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/KF5CalendarCoreConfig.cmake" INSTALL_DESTINATION ${CMAKECONFIG_INSTALL_DIR} ) add_definitions(-DQT_NO_CAST_FROM_ASCII -DQT_NO_CAST_TO_ASCII) add_definitions(-DQT_NO_NARROWING_CONVERSIONS_IN_CONNECT) add_definitions(-DQT_NO_URL_CAST_FROM_STRING) add_definitions(-DQT_USE_QSTRINGBUILDER) add_definitions(-DQT_DISABLE_DEPRECATED_BEFORE=0x060000) ########### Targets ########### add_subdirectory(src) if(BUILD_TESTING) find_package(Qt5 ${QT_REQUIRED_VERSION} CONFIG REQUIRED Test) add_subdirectory(autotests) endif() add_subdirectory(cmake) ########### Install Files ########### install(FILES "${CMAKE_CURRENT_BINARY_DIR}/KF5CalendarCoreConfig.cmake" "${CMAKE_CURRENT_BINARY_DIR}/KF5CalendarCoreConfigVersion.cmake" DESTINATION "${CMAKECONFIG_INSTALL_DIR}" COMPONENT Devel ) install(EXPORT KF5CalendarCoreTargets DESTINATION "${CMAKECONFIG_INSTALL_DIR}" FILE KF5CalendarCoreTargets.cmake NAMESPACE KF5:: ) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/kcalcore_version.h DESTINATION ${KDE_INSTALL_INCLUDEDIR_KF5} COMPONENT Devel ) -install( FILES kcalcore.renamecategories kcalcore.categories DESTINATION ${KDE_INSTALL_CONFDIR} ) +install(FILES kcalcore.renamecategories kcalcore.categories DESTINATION ${KDE_INSTALL_CONFDIR}) feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES) diff --git a/cmake/FindLibIcal.cmake b/cmake/FindLibIcal.cmake index e91645c8c..95fa7d320 100644 --- a/cmake/FindLibIcal.cmake +++ b/cmake/FindLibIcal.cmake @@ -1,142 +1,155 @@ #.rst: # FindLibIcal # ----------- # # Try to find the Ical libraries. # # This will define the following variables: # # ``LibIcal_FOUND`` # True if a suitable LibIcal was found # ``LibIcal_INCLUDE_DIRS`` # This should be passed to target_include_directories() if # the target is not used for linking # ``LibIcal_LIBRARIES`` # The Ical libraries (ical + icalss) # This can be passed to target_link_libraries() instead of # the ``LibIcal`` target # # ``LibIcal_VERSION`` # The LibIcal version defined in ical.h # If ``LibIcal_FOUND`` is TRUE, the following imported target # will be available: # # ``LibIcal`` # The Ical libraries # # The following variables are set for compatibility reason and will be # removed in the next major version # ``LibIcal_MAJOR_VERSION`` # The LibIcal major version # ``LibIcal_MINOR_VERSION`` # The LibIcal minor version # # Copyright (c) 2008,2010 Allen Winter # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # 3. The name of the author may not be used to endorse or promote products # derived from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #============================================================================= if(NOT LibIcal_FIND_VERSION) set(LibIcal_FIND_VERSION "0.33") endif() find_package(PkgConfig QUIET) pkg_check_modules(PC_LibIcal QUIET libical) find_path(LibIcal_INCLUDE_DIRS NAMES libical/ical.h HINTS ${PC_LibIcal_INCLUDEDIR} ) find_library(LibIcal_LIBRARY NAMES ical libical HINTS ${PC_LibIcal_LIBDIR} ) + find_library(LibIcalss_LIBRARY NAMES icalss libicalss HINTS ${PC_LibIcal_LIBDIR} ) +find_library(LibIcalvcal_LIBRARY + NAMES icalvcal + HINTS ${PC_LibIcal_LIBDIR} +) + # For backward compatibility set(LibIcal_INCLUDE_DIRS "${LibIcal_INCLUDE_DIRS}" "${LibIcal_INCLUDE_DIRS}/libical") -set(LibIcal_LIBRARIES ${LibIcal_LIBRARY} ${LibIcalss_LIBRARY}) +set(LibIcal_LIBRARIES ${LibIcal_LIBRARY} ${LibIcalss_LIBRARY} ${LibIcalvcal_LIBRARY}) set(LibIcal_VERSION "${PC_LibIcal_VERSION}") if(NOT LibIcal_VERSION) if(EXISTS "${ICAL_H}") file(STRINGS "${ICAL_H}" _ICAL_H_VERSION REGEX "^#define[ ]+ICAL_VERSION[ ]+\"[0-9].[0-9]\"$") string(REGEX REPLACE "^#define[ ]+ICAL_VERSION[ ]+\"([0-9].[0-9])\"$" "\\1" LibIcal_VERSION "${_ICAL_H_VERSION}") file(STRINGS "${ICAL_H}" _ICAL_H_PATCH_VERSION REGEX "^#define[ ]+ICAL_PATCH_VERSION[ ]+\\([0-9]+\\)$") string(REGEX REPLACE "^#define[ ]+ICAL_PATCH_VERSION[ ]+\\(([0-9]+)\\)$" "\\1" LibIcal_PATCH_VERSION "${_ICAL_H_PATCH_VERSION}") unset(_ICAL_H_VERSION) unset(_ICAL_H_PATCH_VERSION) if(LibIcal_PATCH_VERSION) set(LibIcal_VERSION "${LibIcal_VERSION}.${LibIcal_PATCH_VERSION}") endif() endif() endif() # For compatibility string(REGEX REPLACE "^([0-9]).[0-9]$" "\\1" LibIcal_MAJOR_VERSION "${LibIcal_VERSION}") string(REGEX REPLACE "^[0-9].([0-9])$" "\\1" LibIcal_MINOR_VERSION "${LibIcal_VERSION}") if(NOT LibIcal_VERSION VERSION_LESS 0.46) set(USE_ICAL_0_46 TRUE) endif() if(NOT LibIcal_VERSION VERSION_LESS 1.00) set(USE_ICAL_1_0 TRUE) endif() include(FindPackageHandleStandardArgs) find_package_handle_standard_args(LibIcal FOUND_VAR LibIcal_FOUND REQUIRED_VARS LibIcal_LIBRARIES LibIcal_INCLUDE_DIRS VERSION_VAR LibIcal_VERSION ) # Internal if(LibIcal_FOUND AND NOT TARGET LibIcalss) add_library(LibIcalss UNKNOWN IMPORTED) set_target_properties(LibIcalss PROPERTIES IMPORTED_LOCATION "${LibIcalss_LIBRARY}") endif() +if(LibIcal_FOUND AND NOT TARGET LibIcalvcal) + add_library(LibIcalvcal UNKNOWN IMPORTED) + set_target_properties(LibIcalvcal PROPERTIES + IMPORTED_LOCATION "${LibIcalvcal_LIBRARY}") +endif() +# Public Target if(LibIcal_FOUND AND NOT TARGET LibIcal) - add_library(LibIcal UNKNOWN IMPORTED) - set_target_properties(LibIcal PROPERTIES - IMPORTED_LOCATION "${LibIcal_LIBRARY}" - INTERFACE_INCLUDE_DIRECTORIES "${LibIcal_INCLUDE_DIRS}" - INTERFACE_LINK_LIBRARIES LibIcalss) + add_library(LibIcal UNKNOWN IMPORTED) + set_target_properties(LibIcal PROPERTIES + IMPORTED_LOCATION "${LibIcal_LIBRARY}" + INTERFACE_INCLUDE_DIRECTORIES "${LibIcal_INCLUDE_DIRS}" + INTERFACE_LINK_LIBRARIES "LibIcalss;LibIcalvcal" + ) endif() -mark_as_advanced(LibIcal_INCLUDE_DIRS LibIcal_LIBRARY LibIcalss_LIBRARY LibIcal_LIBRARIES) +mark_as_advanced(LibIcal_INCLUDE_DIRS LibIcal_LIBRARY LibIcalss_LIBRARY LibIcalvcal_LIBRARY LibIcal_LIBRARIES) include(FeatureSummary) set_package_properties(LibIcal PROPERTIES URL "https://github.com/libical/libical" DESCRIPTION "Implementation of iCalendar protocols and data formats" ) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 163b2ea10..e72c8e417 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,135 +1,123 @@ ########### next target ############### -bison_target(VersitParser - ${CMAKE_CURRENT_SOURCE_DIR}/versit/vcc.y - ${CMAKE_CURRENT_BINARY_DIR}/vcc-parser.c -) -set_property(SOURCE ${CMAKE_CURRENT_BINARY_DIR}/vcc-parser.h PROPERTY SKIP_AUTOMOC TRUE) # don't run automoc on this file - -set(libversit_SRCS - ${CMAKE_CURRENT_SOURCE_DIR}/versit/vobject.c - ${BISON_VersitParser_OUTPUTS} -) - set(kcalcore_LIB_SRCS - ${libversit_SRCS} alarm.cpp attachment.cpp attendee.cpp calendar.cpp calfilter.cpp calformat.cpp calstorage.cpp compat.cpp customproperties.cpp duration.cpp event.cpp exceptions.cpp filestorage.cpp freebusy.cpp freebusycache.cpp freebusyperiod.cpp icalformat.cpp icalformat_p.cpp icaltimezones.cpp incidence.cpp incidencebase.cpp journal.cpp memorycalendar.cpp occurrenceiterator.cpp period.cpp person.cpp recurrence.cpp recurrencerule.cpp schedulemessage.cpp sorting.cpp todo.cpp utils.cpp vcalformat.cpp visitor.cpp ) ecm_qt_declare_logging_category(kcalcore_LIB_SRCS HEADER kcalcore_debug.h IDENTIFIER KCALCORE_LOG CATEGORY_NAME org.kde.pim.kcalcore) add_library(KF5CalendarCore ${kcalcore_LIB_SRCS}) generate_export_header(KF5CalendarCore BASE_NAME kcalcore) add_library(KF5::CalendarCore ALIAS KF5CalendarCore) target_include_directories(KF5CalendarCore INTERFACE "$") -target_include_directories(KF5CalendarCore PUBLIC "$") +target_include_directories(KF5CalendarCore PUBLIC "$") target_link_libraries(KF5CalendarCore PUBLIC Qt5::Core PRIVATE Qt5::Gui LibIcal ) set_target_properties(KF5CalendarCore PROPERTIES VERSION ${KCALCORE_VERSION_STRING} SOVERSION ${KCALCORE_SOVERSION} EXPORT_NAME CalendarCore ) install(TARGETS KF5CalendarCore EXPORT KF5CalendarCoreTargets ${KF5_INSTALL_TARGETS_DEFAULT_ARGS}) ########### Generate Headers ############### ecm_generate_headers(KCalCore_CamelCase_HEADERS HEADER_NAMES Alarm Attachment Attendee CalFilter CalFormat CalStorage Calendar CustomProperties Duration Event Exceptions # NOTE: Used to be called 'Exception' in KDE4 FileStorage FreeBusy FreeBusyCache FreeBusyPeriod ICalFormat Incidence IncidenceBase Journal MemoryCalendar OccurrenceIterator Period Person Recurrence RecurrenceRule ScheduleMessage SortableList Sorting Todo VCalFormat Visitor PREFIX KCalCore REQUIRED_HEADERS KCalCore_HEADERS ) ########### install files ############### install(FILES ${CMAKE_CURRENT_BINARY_DIR}/kcalcore_export.h ${KCalCore_HEADERS} supertrait.h DESTINATION ${KDE_INSTALL_INCLUDEDIR_KF5}/KCalCore/kcalcore COMPONENT Devel ) install(FILES ${KCalCore_CamelCase_HEADERS} DESTINATION ${KDE_INSTALL_INCLUDEDIR_KF5}/KCalCore/KCalCore COMPONENT Devel ) ecm_generate_pri_file(BASE_NAME KCalCore LIB_NAME KF5CalendarCore DEPS "Core" FILENAME_VAR PRI_FILENAME INCLUDE_INSTALL_DIR ${KDE_INSTALL_INCLUDEDIR_KF5}/KCalCore/KCalCore) install(FILES ${PRI_FILENAME} DESTINATION ${ECM_MKSPECS_INSTALL_DIR}) diff --git a/src/vcalformat.cpp b/src/vcalformat.cpp index aa5c2d774..d360fac2d 100644 --- a/src/vcalformat.cpp +++ b/src/vcalformat.cpp @@ -1,1733 +1,1736 @@ /* This file is part of the kcalcore library. Copyright (c) 1998 Preston Brown Copyright (c) 2001 Cornelius Schumacher This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ /** @file This file is part of the API for handling calendar data and defines the VCalFormat base class. This class implements the vCalendar format. It provides methods for loading/saving/converting vCalendar format data into the internal representation as Calendar and Incidences. @brief vCalendar format implementation. @author Preston Brown \ @author Cornelius Schumacher \ */ #include "vcalformat.h" #include "calendar.h" #include "event.h" #include "exceptions.h" #include "todo.h" #include "utils.h" -#include "versit/vcc.h" -#include "versit/vobject.h" #include "kcalcore_debug.h" +extern "C" { +#include +#include +} + #include #include #include // for .toHtmlEscaped() and Qt::mightBeRichText() #include using namespace KCalCore; /** Private class that helps to provide binary compatibility between releases. @internal */ //@cond PRIVATE template void removeAllVCal(QVector< QSharedPointer > &c, const QSharedPointer &x) { if (c.count() < 1) { return; } int cnt = c.count(x); if (cnt != 1) { qCritical() << "There number of relatedTos for this incidence is " << cnt << " (there must be 1 relatedTo only)"; Q_ASSERT_X(false, "removeAllVCal", "Count is not 1."); return; } c.remove(c.indexOf(x)); } class Q_DECL_HIDDEN KCalCore::VCalFormat::Private { public: Calendar::Ptr mCalendar; Event::List mEventsRelate; // Events with relations Todo::List mTodosRelate; // To-dos with relations QSet mManuallyWrittenExtensionFields; // X- fields that are manually dumped }; //@endcond VCalFormat::VCalFormat() : d(new KCalCore::VCalFormat::Private) { } VCalFormat::~VCalFormat() { delete d; } bool VCalFormat::load(const Calendar::Ptr &calendar, const QString &fileName) { d->mCalendar = calendar; clearException(); // this is not necessarily only 1 vcal. Could be many vcals, or include // a vcard... VObject *vcal = Parse_MIME_FromFileName(const_cast(QFile::encodeName(fileName).data())); if (!vcal) { setException(new Exception(Exception::CalVersionUnknown)); return false; } // any other top-level calendar stuff should be added/initialized here // put all vobjects into their proper places auto savedTimeZoneId = d->mCalendar->timeZoneId(); populate(vcal, false, fileName); d->mCalendar->setTimeZoneId(savedTimeZoneId); // clean up from vcal API stuff cleanVObjects(vcal); cleanStrTbl(); return true; } bool VCalFormat::save(const Calendar::Ptr &calendar, const QString &fileName) { Q_UNUSED(calendar); Q_UNUSED(fileName); qCWarning(KCALCORE_LOG) << "Saving VCAL is not supported"; return false; } bool VCalFormat::fromString(const Calendar::Ptr &calendar, const QString &string, bool deleted, const QString ¬ebook) { return fromRawString(calendar, string.toUtf8(), deleted, notebook); } bool VCalFormat::fromRawString(const Calendar::Ptr &calendar, const QByteArray &string, bool deleted, const QString ¬ebook) { d->mCalendar = calendar; if (!string.size()) { return false; } VObject *vcal = Parse_MIME(string.data(), string.size()); if (!vcal) { return false; } VObjectIterator i; initPropIterator(&i, vcal); // put all vobjects into their proper places auto savedTimeZoneId = d->mCalendar->timeZoneId(); populate(vcal, deleted, notebook); d->mCalendar->setTimeZoneId(savedTimeZoneId); // clean up from vcal API stuff cleanVObjects(vcal); cleanStrTbl(); return true; } QString VCalFormat::toString(const Calendar::Ptr &calendar, const QString ¬ebook, bool deleted) { Q_UNUSED(calendar); Q_UNUSED(notebook); Q_UNUSED(deleted); qCWarning(KCALCORE_LOG) << "Exporting into VCAL is not supported"; return {}; } Todo::Ptr VCalFormat::VTodoToEvent(VObject *vtodo) { VObject *vo = nullptr; VObjectIterator voi; char *s = nullptr; Todo::Ptr anEvent(new Todo); // creation date if ((vo = isAPropertyOf(vtodo, VCDCreatedProp)) != nullptr) { anEvent->setCreated(ISOToQDateTime(QString::fromUtf8(s = fakeCString(vObjectUStringZValue(vo))))); deleteStr(s); } // unique id vo = isAPropertyOf(vtodo, VCUniqueStringProp); // while the UID property is preferred, it is not required. We'll use the // default Event UID if none is given. if (vo) { anEvent->setUid(QString::fromUtf8(s = fakeCString(vObjectUStringZValue(vo)))); deleteStr(s); } // last modification date if ((vo = isAPropertyOf(vtodo, VCLastModifiedProp)) != nullptr) { anEvent->setLastModified(ISOToQDateTime(QString::fromUtf8(s = fakeCString(vObjectUStringZValue(vo))))); deleteStr(s); } else { anEvent->setLastModified(QDateTime::currentDateTimeUtc()); } // organizer // if our extension property for the event's ORGANIZER exists, add it. if ((vo = isAPropertyOf(vtodo, ICOrganizerProp)) != nullptr) { anEvent->setOrganizer(QString::fromUtf8(s = fakeCString(vObjectUStringZValue(vo)))); deleteStr(s); } else { if (d->mCalendar->owner()->name() != QLatin1String("Unknown Name")) { anEvent->setOrganizer(d->mCalendar->owner()); } } // attendees. initPropIterator(&voi, vtodo); while (moreIteration(&voi)) { vo = nextVObject(&voi); if (strcmp(vObjectName(vo), VCAttendeeProp) == 0) { Attendee::Ptr a; VObject *vp; s = fakeCString(vObjectUStringZValue(vo)); QString tmpStr = QString::fromUtf8(s); deleteStr(s); tmpStr = tmpStr.simplified(); int emailPos1; if ((emailPos1 = tmpStr.indexOf(QLatin1Char('<'))) > 0) { // both email address and name int emailPos2 = tmpStr.lastIndexOf(QLatin1Char('>')); a = Attendee::Ptr(new Attendee(tmpStr.left(emailPos1 - 1), tmpStr.mid(emailPos1 + 1, emailPos2 - (emailPos1 + 1)))); } else if (tmpStr.indexOf(QLatin1Char('@')) > 0) { // just an email address a = Attendee::Ptr(new Attendee(QString(), tmpStr)); } else { // just a name // WTF??? Replacing the spaces of a name and using this as email? QString email = tmpStr.replace(QLatin1Char(' '), QLatin1Char('.')); a = Attendee::Ptr(new Attendee(tmpStr, email)); } // is there an RSVP property? if ((vp = isAPropertyOf(vo, VCRSVPProp)) != nullptr) { a->setRSVP(vObjectStringZValue(vp)); } // is there a status property? if ((vp = isAPropertyOf(vo, VCStatusProp)) != nullptr) { a->setStatus(readStatus(vObjectStringZValue(vp))); } // add the attendee anEvent->addAttendee(a); } } // description for todo if ((vo = isAPropertyOf(vtodo, VCDescriptionProp)) != nullptr) { s = fakeCString(vObjectUStringZValue(vo)); anEvent->setDescription(QString::fromUtf8(s), Qt::mightBeRichText(QString::fromUtf8(s))); deleteStr(s); } // summary if ((vo = isAPropertyOf(vtodo, VCSummaryProp))) { s = fakeCString(vObjectUStringZValue(vo)); anEvent->setSummary(QString::fromUtf8(s), Qt::mightBeRichText(QString::fromUtf8(s))); deleteStr(s); } // location if ((vo = isAPropertyOf(vtodo, VCLocationProp)) != nullptr) { s = fakeCString(vObjectUStringZValue(vo)); anEvent->setLocation(QString::fromUtf8(s), Qt::mightBeRichText(QString::fromUtf8(s))); deleteStr(s); } // completed // was: status if ((vo = isAPropertyOf(vtodo, VCStatusProp)) != nullptr) { s = fakeCString(vObjectUStringZValue(vo)); if (s && strcmp(s, "COMPLETED") == 0) { anEvent->setCompleted(true); } else { anEvent->setCompleted(false); } deleteStr(s); } else { anEvent->setCompleted(false); } // completion date if ((vo = isAPropertyOf(vtodo, VCCompletedProp)) != nullptr) { anEvent->setCompleted(ISOToQDateTime(QString::fromUtf8(s = fakeCString(vObjectUStringZValue(vo))))); deleteStr(s); } // priority if ((vo = isAPropertyOf(vtodo, VCPriorityProp))) { s = fakeCString(vObjectUStringZValue(vo)); if (s) { anEvent->setPriority(atoi(s)); deleteStr(s); } } anEvent->setAllDay(false); // due date if ((vo = isAPropertyOf(vtodo, VCDueProp)) != nullptr) { anEvent->setDtDue(ISOToQDateTime(QString::fromUtf8(s = fakeCString(vObjectUStringZValue(vo))))); deleteStr(s); if (anEvent->dtDue().time().hour() == 0 && anEvent->dtDue().time().minute() == 0 && anEvent->dtDue().time().second() == 0) { anEvent->setAllDay(true); } } else { anEvent->setDtDue(QDateTime()); } // start time if ((vo = isAPropertyOf(vtodo, VCDTstartProp)) != nullptr) { anEvent->setDtStart(ISOToQDateTime(QString::fromUtf8(s = fakeCString(vObjectUStringZValue(vo))))); deleteStr(s); if (anEvent->dtStart().time().hour() == 0 && anEvent->dtStart().time().minute() == 0 && anEvent->dtStart().time().second() == 0) { anEvent->setAllDay(true); } } else { anEvent->setDtStart(QDateTime()); } // repeat stuff if ((vo = isAPropertyOf(vtodo, VCRRuleProp)) != nullptr) { QString tmpStr = (QString::fromUtf8(s = fakeCString(vObjectUStringZValue(vo)))); deleteStr(s); tmpStr = tmpStr.simplified(); tmpStr = tmpStr.toUpper(); // first, read the type of the recurrence int typelen = 1; uint type = Recurrence::rNone; if (tmpStr.left(1) == QStringLiteral("D")) { type = Recurrence::rDaily; } else if (tmpStr.left(1) == QStringLiteral("W")) { type = Recurrence::rWeekly; } else { typelen = 2; if (tmpStr.left(2) == QStringLiteral("MP")) { type = Recurrence::rMonthlyPos; } else if (tmpStr.left(2) == QStringLiteral("MD")) { type = Recurrence::rMonthlyDay; } else if (tmpStr.left(2) == QStringLiteral("YM")) { type = Recurrence::rYearlyMonth; } else if (tmpStr.left(2) == QStringLiteral("YD")) { type = Recurrence::rYearlyDay; } } if (type != Recurrence::rNone) { // Immediately after the type is the frequency int index = tmpStr.indexOf(QLatin1Char(' ')); int last = tmpStr.lastIndexOf(QLatin1Char(' ')) + 1; // find last entry int rFreq = tmpStr.midRef(typelen, (index - 1)).toInt(); ++index; // advance to beginning of stuff after freq // Read the type-specific settings switch (type) { case Recurrence::rDaily: anEvent->recurrence()->setDaily(rFreq); break; case Recurrence::rWeekly: { QBitArray qba(7); QString dayStr; if (index == last) { // e.g. W1 #0 qba.setBit(anEvent->dtStart().date().dayOfWeek() - 1); } else { // e.g. W1 SU #0 while (index < last) { dayStr = tmpStr.mid(index, 3); int dayNum = numFromDay(dayStr); if (dayNum >= 0) { qba.setBit(dayNum); } index += 3; // advance to next day, or possibly "#" } } anEvent->recurrence()->setWeekly(rFreq, qba); break; } case Recurrence::rMonthlyPos: { anEvent->recurrence()->setMonthly(rFreq); QBitArray qba(7); short tmpPos; if (index == last) { // e.g. MP1 #0 tmpPos = anEvent->dtStart().date().day() / 7 + 1; if (tmpPos == 5) { tmpPos = -1; } qba.setBit(anEvent->dtStart().date().dayOfWeek() - 1); anEvent->recurrence()->addMonthlyPos(tmpPos, qba); } else { // e.g. MP1 1+ SU #0 while (index < last) { tmpPos = tmpStr.mid(index, 1).toShort(); index += 1; if (tmpStr.mid(index, 1) == QLatin1String("-")) { // convert tmpPos to negative tmpPos = 0 - tmpPos; } index += 2; // advance to day(s) while (numFromDay(tmpStr.mid(index, 3)) >= 0) { int dayNum = numFromDay(tmpStr.mid(index, 3)); qba.setBit(dayNum); index += 3; // advance to next day, or possibly pos or "#" } anEvent->recurrence()->addMonthlyPos(tmpPos, qba); qba.detach(); qba.fill(false); // clear out } // while != "#" } break; } case Recurrence::rMonthlyDay: anEvent->recurrence()->setMonthly(rFreq); if (index == last) { // e.g. MD1 #0 short tmpDay = anEvent->dtStart().date().day(); anEvent->recurrence()->addMonthlyDate(tmpDay); } else { // e.g. MD1 3 #0 while (index < last) { int index2 = tmpStr.indexOf(QLatin1Char(' '), index); if ((tmpStr.mid((index2 - 1), 1) == QLatin1String("-")) || (tmpStr.mid((index2 - 1), 1) == QLatin1String("+"))) { index2 = index2 - 1; } short tmpDay = tmpStr.mid(index, (index2 - index)).toShort(); index = index2; if (tmpStr.mid(index, 1) == QLatin1String("-")) { tmpDay = 0 - tmpDay; } index += 2; // advance the index; anEvent->recurrence()->addMonthlyDate(tmpDay); } // while != # } break; case Recurrence::rYearlyMonth: anEvent->recurrence()->setYearly(rFreq); if (index == last) { // e.g. YM1 #0 short tmpMonth = anEvent->dtStart().date().month(); anEvent->recurrence()->addYearlyMonth(tmpMonth); } else { // e.g. YM1 3 #0 while (index < last) { int index2 = tmpStr.indexOf(QLatin1Char(' '), index); short tmpMonth = tmpStr.mid(index, (index2 - index)).toShort(); index = index2 + 1; anEvent->recurrence()->addYearlyMonth(tmpMonth); } // while != # } break; case Recurrence::rYearlyDay: anEvent->recurrence()->setYearly(rFreq); if (index == last) { // e.g. YD1 #0 short tmpDay = anEvent->dtStart().date().dayOfYear(); anEvent->recurrence()->addYearlyDay(tmpDay); } else { // e.g. YD1 123 #0 while (index < last) { int index2 = tmpStr.indexOf(QLatin1Char(' '), index); short tmpDay = tmpStr.mid(index, (index2 - index)).toShort(); index = index2 + 1; anEvent->recurrence()->addYearlyDay(tmpDay); } // while != # } break; default: break; } // find the last field, which is either the duration or the end date index = last; if (tmpStr.mid(index, 1) == QLatin1String("#")) { // Nr of occurrences index++; int rDuration = tmpStr.midRef(index, tmpStr.length() - index).toInt(); if (rDuration > 0) { anEvent->recurrence()->setDuration(rDuration); } } else if (tmpStr.indexOf(QLatin1Char('T'), index) != -1) { QDateTime rEndDate = ISOToQDateTime(tmpStr.mid(index, tmpStr.length() - index)); anEvent->recurrence()->setEndDateTime(rEndDate); } } else { qCDebug(KCALCORE_LOG) << "we don't understand this type of recurrence!"; } // if known recurrence type } // repeats // recurrence exceptions if ((vo = isAPropertyOf(vtodo, VCExpDateProp)) != nullptr) { s = fakeCString(vObjectUStringZValue(vo)); QStringList exDates = QString::fromUtf8(s).split(QLatin1Char(',')); QStringList::ConstIterator it; for (it = exDates.constBegin(); it != exDates.constEnd(); ++it) { QDateTime exDate = ISOToQDateTime(*it); if (exDate.time().hour() == 0 && exDate.time().minute() == 0 && exDate.time().second() == 0) { anEvent->recurrence()->addExDate(ISOToQDate(*it)); } else { anEvent->recurrence()->addExDateTime(exDate); } } deleteStr(s); } // alarm stuff if ((vo = isAPropertyOf(vtodo, VCDAlarmProp))) { Alarm::Ptr alarm; VObject *a = isAPropertyOf(vo, VCRunTimeProp); VObject *b = isAPropertyOf(vo, VCDisplayStringProp); if (a || b) { alarm = anEvent->newAlarm(); if (a) { alarm->setTime(ISOToQDateTime(QString::fromUtf8(s = fakeCString(vObjectUStringZValue(a))))); deleteStr(s); } alarm->setEnabled(true); if (b) { s = fakeCString(vObjectUStringZValue(b)); alarm->setDisplayAlarm(QString::fromUtf8(s)); deleteStr(s); } else { alarm->setDisplayAlarm(QString()); } } } if ((vo = isAPropertyOf(vtodo, VCAAlarmProp))) { Alarm::Ptr alarm; VObject *a; VObject *b; a = isAPropertyOf(vo, VCRunTimeProp); b = isAPropertyOf(vo, VCAudioContentProp); if (a || b) { alarm = anEvent->newAlarm(); if (a) { alarm->setTime(ISOToQDateTime(QString::fromUtf8(s = fakeCString(vObjectUStringZValue(a))))); deleteStr(s); } alarm->setEnabled(true); if (b) { s = fakeCString(vObjectUStringZValue(b)); alarm->setAudioAlarm(QFile::decodeName(s)); deleteStr(s); } else { alarm->setAudioAlarm(QString()); } } } if ((vo = isAPropertyOf(vtodo, VCPAlarmProp))) { Alarm::Ptr alarm; VObject *a = isAPropertyOf(vo, VCRunTimeProp); VObject *b = isAPropertyOf(vo, VCProcedureNameProp); if (a || b) { alarm = anEvent->newAlarm(); if (a) { alarm->setTime(ISOToQDateTime(QString::fromUtf8(s = fakeCString(vObjectUStringZValue(a))))); deleteStr(s); } alarm->setEnabled(true); if (b) { s = fakeCString(vObjectUStringZValue(b)); alarm->setProcedureAlarm(QFile::decodeName(s)); deleteStr(s); } else { alarm->setProcedureAlarm(QString()); } } } // related todo if ((vo = isAPropertyOf(vtodo, VCRelatedToProp)) != nullptr) { anEvent->setRelatedTo(QString::fromUtf8(s = fakeCString(vObjectUStringZValue(vo)))); deleteStr(s); d->mTodosRelate.append(anEvent); } // secrecy Incidence::Secrecy secrecy = Incidence::SecrecyPublic; if ((vo = isAPropertyOf(vtodo, VCClassProp)) != nullptr) { s = fakeCString(vObjectUStringZValue(vo)); if (s && strcmp(s, "PRIVATE") == 0) { secrecy = Incidence::SecrecyPrivate; } else if (s && strcmp(s, "CONFIDENTIAL") == 0) { secrecy = Incidence::SecrecyConfidential; } deleteStr(s); } anEvent->setSecrecy(secrecy); // categories if ((vo = isAPropertyOf(vtodo, VCCategoriesProp)) != nullptr) { s = fakeCString(vObjectUStringZValue(vo)); QString categories = QString::fromUtf8(s); deleteStr(s); QStringList tmpStrList = categories.split(QLatin1Char(';')); anEvent->setCategories(tmpStrList); } return anEvent; } Event::Ptr VCalFormat::VEventToEvent(VObject *vevent) { VObject *vo = nullptr; VObjectIterator voi; char *s = nullptr; Event::Ptr anEvent(new Event); // creation date if ((vo = isAPropertyOf(vevent, VCDCreatedProp)) != nullptr) { anEvent->setCreated(ISOToQDateTime(QString::fromUtf8(s = fakeCString(vObjectUStringZValue(vo))))); deleteStr(s); } // unique id vo = isAPropertyOf(vevent, VCUniqueStringProp); // while the UID property is preferred, it is not required. We'll use the // default Event UID if none is given. if (vo) { anEvent->setUid(QString::fromUtf8(s = fakeCString(vObjectUStringZValue(vo)))); deleteStr(s); } // revision // again NSCAL doesn't give us much to work with, so we improvise... anEvent->setRevision(0); if ((vo = isAPropertyOf(vevent, VCSequenceProp)) != nullptr) { s = fakeCString(vObjectUStringZValue(vo)); if (s) { anEvent->setRevision(atoi(s)); deleteStr(s); } } // last modification date if ((vo = isAPropertyOf(vevent, VCLastModifiedProp)) != nullptr) { anEvent->setLastModified(ISOToQDateTime(QString::fromUtf8(s = fakeCString(vObjectUStringZValue(vo))))); deleteStr(s); } else { anEvent->setLastModified(QDateTime::currentDateTimeUtc()); } // organizer // if our extension property for the event's ORGANIZER exists, add it. if ((vo = isAPropertyOf(vevent, ICOrganizerProp)) != nullptr) { // FIXME: Also use the full name, not just the email address anEvent->setOrganizer(QString::fromUtf8(s = fakeCString(vObjectUStringZValue(vo)))); deleteStr(s); } else { if (d->mCalendar->owner()->name() != QStringLiteral("Unknown Name")) { anEvent->setOrganizer(d->mCalendar->owner()); } } // deal with attendees. initPropIterator(&voi, vevent); while (moreIteration(&voi)) { vo = nextVObject(&voi); if (strcmp(vObjectName(vo), VCAttendeeProp) == 0) { Attendee::Ptr a; VObject *vp = nullptr; s = fakeCString(vObjectUStringZValue(vo)); QString tmpStr = QString::fromUtf8(s); deleteStr(s); tmpStr = tmpStr.simplified(); int emailPos1; if ((emailPos1 = tmpStr.indexOf(QLatin1Char('<'))) > 0) { // both email address and name int emailPos2 = tmpStr.lastIndexOf(QLatin1Char('>')); a = Attendee::Ptr(new Attendee(tmpStr.left(emailPos1 - 1), tmpStr.mid(emailPos1 + 1, emailPos2 - (emailPos1 + 1)))); } else if (tmpStr.indexOf(QLatin1Char('@')) > 0) { // just an email address a = Attendee::Ptr(new Attendee(QString(), tmpStr)); } else { // just a name QString email = tmpStr.replace(QLatin1Char(' '), QLatin1Char('.')); a = Attendee::Ptr(new Attendee(tmpStr, email)); } // is there an RSVP property? if ((vp = isAPropertyOf(vo, VCRSVPProp)) != nullptr) { a->setRSVP(vObjectStringZValue(vp)); } // is there a status property? if ((vp = isAPropertyOf(vo, VCStatusProp)) != nullptr) { a->setStatus(readStatus(vObjectStringZValue(vp))); } // add the attendee anEvent->addAttendee(a); } } // This isn't strictly true. An event that doesn't have a start time // or an end time isn't all-day, it has an anchor in time but it doesn't // "take up" any time. /*if ((isAPropertyOf(vevent, VCDTstartProp) == 0) || (isAPropertyOf(vevent, VCDTendProp) == 0)) { anEvent->setAllDay(true); } else { }*/ anEvent->setAllDay(false); // start time if ((vo = isAPropertyOf(vevent, VCDTstartProp)) != nullptr) { anEvent->setDtStart(ISOToQDateTime(QString::fromUtf8(s = fakeCString(vObjectUStringZValue(vo))))); deleteStr(s); if (anEvent->dtStart().time().hour() == 0 && anEvent->dtStart().time().minute() == 0 && anEvent->dtStart().time().second() == 0) { anEvent->setAllDay(true); } } // stop time if ((vo = isAPropertyOf(vevent, VCDTendProp)) != nullptr) { anEvent->setDtEnd(ISOToQDateTime(QString::fromUtf8(s = fakeCString(vObjectUStringZValue(vo))))); deleteStr(s); if (anEvent->dtEnd().time().hour() == 0 && anEvent->dtEnd().time().minute() == 0 && anEvent->dtEnd().time().second() == 0) { anEvent->setAllDay(true); } } // at this point, there should be at least a start or end time. // fix up for events that take up no time but have a time associated if (!isAPropertyOf(vevent, VCDTstartProp)) { anEvent->setDtStart(anEvent->dtEnd()); } if (! isAPropertyOf(vevent, VCDTendProp)) { anEvent->setDtEnd(anEvent->dtStart()); } /////////////////////////////////////////////////////////////////////////// // repeat stuff if ((vo = isAPropertyOf(vevent, VCRRuleProp)) != nullptr) { QString tmpStr = (QString::fromUtf8(s = fakeCString(vObjectUStringZValue(vo)))); deleteStr(s); tmpStr = tmpStr.simplified(); tmpStr = tmpStr.toUpper(); // first, read the type of the recurrence int typelen = 1; uint type = Recurrence::rNone; if (tmpStr.left(1) == QLatin1String("D")) { type = Recurrence::rDaily; } else if (tmpStr.left(1) == QLatin1String("W")) { type = Recurrence::rWeekly; } else { typelen = 2; if (tmpStr.left(2) == QLatin1String("MP")) { type = Recurrence::rMonthlyPos; } else if (tmpStr.left(2) == QLatin1String("MD")) { type = Recurrence::rMonthlyDay; } else if (tmpStr.left(2) == QLatin1String("YM")) { type = Recurrence::rYearlyMonth; } else if (tmpStr.left(2) == QLatin1String("YD")) { type = Recurrence::rYearlyDay; } } if (type != Recurrence::rNone) { // Immediately after the type is the frequency int index = tmpStr.indexOf(QLatin1Char(' ')); int last = tmpStr.lastIndexOf(QLatin1Char(' ')) + 1; // find last entry int rFreq = tmpStr.midRef(typelen, (index - 1)).toInt(); ++index; // advance to beginning of stuff after freq // Read the type-specific settings switch (type) { case Recurrence::rDaily: anEvent->recurrence()->setDaily(rFreq); break; case Recurrence::rWeekly: { QBitArray qba(7); QString dayStr; if (index == last) { // e.g. W1 #0 qba.setBit(anEvent->dtStart().date().dayOfWeek() - 1); } else { // e.g. W1 SU #0 while (index < last) { dayStr = tmpStr.mid(index, 3); int dayNum = numFromDay(dayStr); if (dayNum >= 0) { qba.setBit(dayNum); } index += 3; // advance to next day, or possibly "#" } } anEvent->recurrence()->setWeekly(rFreq, qba); break; } case Recurrence::rMonthlyPos: { anEvent->recurrence()->setMonthly(rFreq); QBitArray qba(7); short tmpPos; if (index == last) { // e.g. MP1 #0 tmpPos = anEvent->dtStart().date().day() / 7 + 1; if (tmpPos == 5) { tmpPos = -1; } qba.setBit(anEvent->dtStart().date().dayOfWeek() - 1); anEvent->recurrence()->addMonthlyPos(tmpPos, qba); } else { // e.g. MP1 1+ SU #0 while (index < last) { tmpPos = tmpStr.mid(index, 1).toShort(); index += 1; if (tmpStr.mid(index, 1) == QStringLiteral("-")) { // convert tmpPos to negative tmpPos = 0 - tmpPos; } index += 2; // advance to day(s) while (numFromDay(tmpStr.mid(index, 3)) >= 0) { int dayNum = numFromDay(tmpStr.mid(index, 3)); qba.setBit(dayNum); index += 3; // advance to next day, or possibly pos or "#" } anEvent->recurrence()->addMonthlyPos(tmpPos, qba); qba.detach(); qba.fill(false); // clear out } // while != "#" } break; } case Recurrence::rMonthlyDay: anEvent->recurrence()->setMonthly(rFreq); if (index == last) { // e.g. MD1 #0 short tmpDay = anEvent->dtStart().date().day(); anEvent->recurrence()->addMonthlyDate(tmpDay); } else { // e.g. MD1 3 #0 while (index < last) { int index2 = tmpStr.indexOf(QLatin1Char(' '), index); if ((tmpStr.mid((index2 - 1), 1) == QStringLiteral("-")) || (tmpStr.mid((index2 - 1), 1) == QStringLiteral("+"))) { index2 = index2 - 1; } short tmpDay = tmpStr.mid(index, (index2 - index)).toShort(); index = index2; if (tmpStr.mid(index, 1) == QStringLiteral("-")) { tmpDay = 0 - tmpDay; } index += 2; // advance the index; anEvent->recurrence()->addMonthlyDate(tmpDay); } // while != # } break; case Recurrence::rYearlyMonth: anEvent->recurrence()->setYearly(rFreq); if (index == last) { // e.g. YM1 #0 short tmpMonth = anEvent->dtStart().date().month(); anEvent->recurrence()->addYearlyMonth(tmpMonth); } else { // e.g. YM1 3 #0 while (index < last) { int index2 = tmpStr.indexOf(QLatin1Char(' '), index); short tmpMonth = tmpStr.mid(index, (index2 - index)).toShort(); index = index2 + 1; anEvent->recurrence()->addYearlyMonth(tmpMonth); } // while != # } break; case Recurrence::rYearlyDay: anEvent->recurrence()->setYearly(rFreq); if (index == last) { // e.g. YD1 #0 short tmpDay = anEvent->dtStart().date().dayOfYear(); anEvent->recurrence()->addYearlyDay(tmpDay); } else { // e.g. YD1 123 #0 while (index < last) { int index2 = tmpStr.indexOf(QLatin1Char(' '), index); short tmpDay = tmpStr.mid(index, (index2 - index)).toShort(); index = index2 + 1; anEvent->recurrence()->addYearlyDay(tmpDay); } // while != # } break; default: break; } // find the last field, which is either the duration or the end date index = last; if (tmpStr.mid(index, 1) == QLatin1String("#")) { // Nr of occurrences index++; int rDuration = tmpStr.midRef(index, tmpStr.length() - index).toInt(); if (rDuration > 0) { anEvent->recurrence()->setDuration(rDuration); } } else if (tmpStr.indexOf(QLatin1Char('T'), index) != -1) { QDateTime rEndDate = ISOToQDateTime(tmpStr.mid(index, tmpStr.length() - index)); anEvent->recurrence()->setEndDateTime(rEndDate); } // anEvent->recurrence()->dump(); } else { qCDebug(KCALCORE_LOG) << "we don't understand this type of recurrence!"; } // if known recurrence type } // repeats // recurrence exceptions if ((vo = isAPropertyOf(vevent, VCExpDateProp)) != nullptr) { s = fakeCString(vObjectUStringZValue(vo)); QStringList exDates = QString::fromUtf8(s).split(QLatin1Char(',')); QStringList::ConstIterator it; for (it = exDates.constBegin(); it != exDates.constEnd(); ++it) { QDateTime exDate = ISOToQDateTime(*it); if (exDate.time().hour() == 0 && exDate.time().minute() == 0 && exDate.time().second() == 0) { anEvent->recurrence()->addExDate(ISOToQDate(*it)); } else { anEvent->recurrence()->addExDateTime(exDate); } } deleteStr(s); } // summary if ((vo = isAPropertyOf(vevent, VCSummaryProp))) { s = fakeCString(vObjectUStringZValue(vo)); anEvent->setSummary(QString::fromUtf8(s), Qt::mightBeRichText(QString::fromUtf8(s))); deleteStr(s); } // description if ((vo = isAPropertyOf(vevent, VCDescriptionProp)) != nullptr) { s = fakeCString(vObjectUStringZValue(vo)); bool isRich = Qt::mightBeRichText(QString::fromUtf8(s)); if (!anEvent->description().isEmpty()) { anEvent->setDescription( anEvent->description() + QLatin1Char('\n') + QString::fromUtf8(s), isRich); } else { anEvent->setDescription(QString::fromUtf8(s), isRich); } deleteStr(s); } // location if ((vo = isAPropertyOf(vevent, VCLocationProp)) != nullptr) { s = fakeCString(vObjectUStringZValue(vo)); anEvent->setLocation(QString::fromUtf8(s), Qt::mightBeRichText(QString::fromUtf8(s))); deleteStr(s); } // some stupid vCal exporters ignore the standard and use Description // instead of Summary for the default field. Correct for this. if (anEvent->summary().isEmpty() && !(anEvent->description().isEmpty())) { QString tmpStr = anEvent->description().simplified(); anEvent->setDescription(QString()); anEvent->setSummary(tmpStr); } #if 0 // status if ((vo = isAPropertyOf(vevent, VCStatusProp)) != 0) { QString tmpStr(s = fakeCString(vObjectUStringZValue(vo))); deleteStr(s); // TODO: Define Event status // anEvent->setStatus( tmpStr ); } else { // anEvent->setStatus( "NEEDS ACTION" ); } #endif // secrecy Incidence::Secrecy secrecy = Incidence::SecrecyPublic; if ((vo = isAPropertyOf(vevent, VCClassProp)) != nullptr) { s = fakeCString(vObjectUStringZValue(vo)); if (s && strcmp(s, "PRIVATE") == 0) { secrecy = Incidence::SecrecyPrivate; } else if (s && strcmp(s, "CONFIDENTIAL") == 0) { secrecy = Incidence::SecrecyConfidential; } deleteStr(s); } anEvent->setSecrecy(secrecy); // categories if ((vo = isAPropertyOf(vevent, VCCategoriesProp)) != nullptr) { s = fakeCString(vObjectUStringZValue(vo)); QString categories = QString::fromUtf8(s); deleteStr(s); QStringList tmpStrList = categories.split(QLatin1Char(',')); anEvent->setCategories(tmpStrList); } // attachments initPropIterator(&voi, vevent); while (moreIteration(&voi)) { vo = nextVObject(&voi); if (strcmp(vObjectName(vo), VCAttachProp) == 0) { s = fakeCString(vObjectUStringZValue(vo)); anEvent->addAttachment(Attachment::Ptr(new Attachment(QString::fromUtf8(s)))); deleteStr(s); } } // resources if ((vo = isAPropertyOf(vevent, VCResourcesProp)) != nullptr) { QString resources = (QString::fromUtf8(s = fakeCString(vObjectUStringZValue(vo)))); deleteStr(s); QStringList tmpStrList = resources.split(QLatin1Char(';')); anEvent->setResources(tmpStrList); } // alarm stuff if ((vo = isAPropertyOf(vevent, VCDAlarmProp))) { Alarm::Ptr alarm; VObject *a = isAPropertyOf(vo, VCRunTimeProp); VObject *b = isAPropertyOf(vo, VCDisplayStringProp); if (a || b) { alarm = anEvent->newAlarm(); if (a) { alarm->setTime(ISOToQDateTime(QString::fromUtf8(s = fakeCString(vObjectUStringZValue(a))))); deleteStr(s); } alarm->setEnabled(true); if (b) { s = fakeCString(vObjectUStringZValue(b)); alarm->setDisplayAlarm(QString::fromUtf8(s)); deleteStr(s); } else { alarm->setDisplayAlarm(QString()); } } } if ((vo = isAPropertyOf(vevent, VCAAlarmProp))) { Alarm::Ptr alarm; VObject *a; VObject *b; a = isAPropertyOf(vo, VCRunTimeProp); b = isAPropertyOf(vo, VCAudioContentProp); if (a || b) { alarm = anEvent->newAlarm(); if (a) { alarm->setTime(ISOToQDateTime(QString::fromUtf8(s = fakeCString(vObjectUStringZValue(a))))); deleteStr(s); } alarm->setEnabled(true); if (b) { s = fakeCString(vObjectUStringZValue(b)); alarm->setAudioAlarm(QFile::decodeName(s)); deleteStr(s); } else { alarm->setAudioAlarm(QString()); } } } if ((vo = isAPropertyOf(vevent, VCPAlarmProp))) { Alarm::Ptr alarm; VObject *a; VObject *b; a = isAPropertyOf(vo, VCRunTimeProp); b = isAPropertyOf(vo, VCProcedureNameProp); if (a || b) { alarm = anEvent->newAlarm(); if (a) { alarm->setTime(ISOToQDateTime(QString::fromUtf8(s = fakeCString(vObjectUStringZValue(a))))); deleteStr(s); } alarm->setEnabled(true); if (b) { s = fakeCString(vObjectUStringZValue(b)); alarm->setProcedureAlarm(QFile::decodeName(s)); deleteStr(s); } else { alarm->setProcedureAlarm(QString()); } } } // priority if ((vo = isAPropertyOf(vevent, VCPriorityProp))) { s = fakeCString(vObjectUStringZValue(vo)); if (s) { anEvent->setPriority(atoi(s)); deleteStr(s); } } // transparency if ((vo = isAPropertyOf(vevent, VCTranspProp)) != nullptr) { s = fakeCString(vObjectUStringZValue(vo)); if (s) { int i = atoi(s); anEvent->setTransparency(i == 1 ? Event::Transparent : Event::Opaque); deleteStr(s); } } // related event if ((vo = isAPropertyOf(vevent, VCRelatedToProp)) != nullptr) { anEvent->setRelatedTo(QString::fromUtf8(s = fakeCString(vObjectUStringZValue(vo)))); deleteStr(s); d->mEventsRelate.append(anEvent); } /* Rest of the custom properties */ readCustomProperties(vevent, anEvent); return anEvent; } QString VCalFormat::parseTZ(const QByteArray &timezone) const { // qCDebug(KCALCORE_LOG) << timezone; QString pZone = QString::fromUtf8(timezone.mid(timezone.indexOf("TZID:VCAL") + 9)); return pZone.mid(0, pZone.indexOf(QLatin1Char('\n'))); } QString VCalFormat::parseDst(QByteArray &timezone) const { if (!timezone.contains("BEGIN:DAYLIGHT")) { return QString(); } timezone = timezone.mid(timezone.indexOf("BEGIN:DAYLIGHT")); timezone = timezone.mid(timezone.indexOf("TZNAME:") + 7); QString sStart = QString::fromUtf8(timezone.mid(0, (timezone.indexOf("COMMENT:")))); sStart.chop(2); timezone = timezone.mid(timezone.indexOf("TZOFFSETTO:") + 11); QString sOffset = QString::fromUtf8(timezone.mid(0, (timezone.indexOf("DTSTART:")))); sOffset.chop(2); sOffset.insert(3, QLatin1Char(':')); timezone = timezone.mid(timezone.indexOf("TZNAME:") + 7); QString sEnd = QString::fromUtf8(timezone.mid(0, (timezone.indexOf("COMMENT:")))); sEnd.chop(2); return QStringLiteral("TRUE;") + sOffset + QLatin1Char(';') + sStart + QLatin1Char(';') + sEnd + QLatin1String(";;"); } QString VCalFormat::qDateToISO(const QDate &qd) { QString tmpStr; if (!qd.isValid()) { return QString(); } tmpStr.sprintf("%.2d%.2d%.2d", qd.year(), qd.month(), qd.day()); return tmpStr; } QString VCalFormat::qDateTimeToISO(const QDateTime &dt, bool zulu) { QString tmpStr; if (!dt.isValid()) { return QString(); } QDateTime tmpDT; if (zulu) { tmpDT = dt.toUTC(); } else { tmpDT = dt.toTimeZone(d->mCalendar->timeZone()); } tmpStr.sprintf("%.2d%.2d%.2dT%.2d%.2d%.2d", tmpDT.date().year(), tmpDT.date().month(), tmpDT.date().day(), tmpDT.time().hour(), tmpDT.time().minute(), tmpDT.time().second()); if (zulu || dt.timeZone() == QTimeZone::utc()) { tmpStr += QLatin1Char('Z'); } return tmpStr; } QDateTime VCalFormat::ISOToQDateTime(const QString &dtStr) { QDate tmpDate; QTime tmpTime; QString tmpStr; int year, month, day, hour, minute, second; tmpStr = dtStr; year = tmpStr.leftRef(4).toInt(); month = tmpStr.midRef(4, 2).toInt(); day = tmpStr.midRef(6, 2).toInt(); hour = tmpStr.midRef(9, 2).toInt(); minute = tmpStr.midRef(11, 2).toInt(); second = tmpStr.midRef(13, 2).toInt(); tmpDate.setDate(year, month, day); tmpTime.setHMS(hour, minute, second); if (tmpDate.isValid() && tmpTime.isValid()) { // correct for GMT if string is in Zulu format if (dtStr.at(dtStr.length() - 1) == QLatin1Char('Z')) { return QDateTime(tmpDate, tmpTime, Qt::UTC); } else { return QDateTime(tmpDate, tmpTime, d->mCalendar->timeZone()); } } else { return QDateTime(); } } QDate VCalFormat::ISOToQDate(const QString &dateStr) { int year, month, day; year = dateStr.leftRef(4).toInt(); month = dateStr.midRef(4, 2).toInt(); day = dateStr.midRef(6, 2).toInt(); return QDate(year, month, day); } bool VCalFormat::parseTZOffsetISO8601(const QString &s, int &result) { // ISO8601 format(s): // +- hh : mm // +- hh mm // +- hh // We also accept broken one without + int mod = 1; int v = 0; QString str = s.trimmed(); int ofs = 0; result = 0; // Check for end if (str.size() <= ofs) { return false; } if (str[ofs] == QLatin1Char('-')) { mod = -1; ofs++; } else if (str[ofs] == QLatin1Char('+')) { ofs++; } if (str.size() <= ofs) { return false; } // Make sure next two values are numbers bool ok; if (str.size() < (ofs + 2)) { return false; } v = str.midRef(ofs, 2).toInt(&ok) * 60; if (!ok) { return false; } ofs += 2; if (str.size() > ofs) { if (str[ofs] == QLatin1Char(':')) { ofs++; } if (str.size() > ofs) { if (str.size() < (ofs + 2)) { return false; } v += str.midRef(ofs, 2).toInt(&ok); if (!ok) { return false; } } } result = v * mod * 60; return true; } // take a raw vcalendar (i.e. from a file on disk, clipboard, etc. etc. // and break it down from it's tree-like format into the dictionary format // that is used internally in the VCalFormat. void VCalFormat::populate(VObject *vcal, bool deleted, const QString ¬ebook) { Q_UNUSED(notebook); // this function will populate the caldict dictionary and other event // lists. It turns vevents into Events and then inserts them. VObjectIterator i; VObject *curVO; Event::Ptr anEvent; bool hasTimeZone = false; //The calendar came with a TZ and not UTC QTimeZone previousZone; //If we add a new TZ we should leave the spec as it was before if ((curVO = isAPropertyOf(vcal, ICMethodProp)) != nullptr) { char *methodType = fakeCString(vObjectUStringZValue(curVO)); // qCDebug(KCALCORE_LOG) << "This calendar is an iTIP transaction of type '" << methodType << "'"; deleteStr(methodType); } // warn the user that we might have trouble reading non-known calendar. if ((curVO = isAPropertyOf(vcal, VCProdIdProp)) != nullptr) { char *s = fakeCString(vObjectUStringZValue(curVO)); if (!s || strcmp(productId().toUtf8().constData(), s) != 0) { qCDebug(KCALCORE_LOG) << "This vCalendar file was not created by KOrganizer or" << "any other product we support. Loading anyway..."; } setLoadedProductId(QString::fromUtf8(s)); deleteStr(s); } // warn the user we might have trouble reading this unknown version. if ((curVO = isAPropertyOf(vcal, VCVersionProp)) != nullptr) { char *s = fakeCString(vObjectUStringZValue(curVO)); if (!s || strcmp(_VCAL_VERSION, s) != 0) { qCDebug(KCALCORE_LOG) << "This vCalendar file has version" << s << "We only support" << _VCAL_VERSION; } deleteStr(s); } // set the time zone (this is a property of the view, so just discard!) if ((curVO = isAPropertyOf(vcal, VCTimeZoneProp)) != nullptr) { char *s = fakeCString(vObjectUStringZValue(curVO)); QString ts = QString::fromUtf8(s); QString name = QStringLiteral("VCAL") + ts; deleteStr(s); // TODO: While using the timezone-offset + vcal as timezone is is // most likely unique, we should REALLY actually create something // like vcal-tzoffset-daylightoffsets, or better yet, // vcal-hash QStringList tzList; QString tz; int utcOffset; int utcOffsetDst; if (parseTZOffsetISO8601(ts, utcOffset)) { // qCDebug(KCALCORE_LOG) << "got standard offset" << ts << utcOffset; // standard from tz // starting date for now 01011900 QDateTime dt = QDateTime(QDateTime(QDate(1900, 1, 1), QTime(0, 0, 0))); tz = QStringLiteral("STD;%1;false;%2").arg(QString::number(utcOffset), dt.toString()); tzList.append(tz); // go through all the daylight tags initPropIterator(&i, vcal); while (moreIteration(&i)) { curVO = nextVObject(&i); if (strcmp(vObjectName(curVO), VCDayLightProp) == 0) { char *s = fakeCString(vObjectUStringZValue(curVO)); QString dst = QLatin1String(s); QStringList argl = dst.split(QLatin1Char(',')); deleteStr(s); // Too short -> not interesting if (argl.size() < 4) { continue; } // We don't care about the non-DST periods if (argl[0] != QLatin1String("TRUE")) { continue; } if (parseTZOffsetISO8601(argl[1], utcOffsetDst)) { // qCDebug(KCALCORE_LOG) << "got DST offset" << argl[1] << utcOffsetDst; // standard QString strEndDate = argl[3]; QDateTime endDate = ISOToQDateTime(strEndDate); // daylight QString strStartDate = argl[2]; QDateTime startDate = ISOToQDateTime(strStartDate); QString strRealEndDate = strEndDate; QString strRealStartDate = strStartDate; QDateTime realEndDate = endDate; QDateTime realStartDate = startDate; // if we get dates for some reason in wrong order, earlier is used for dst if (endDate < startDate) { strRealEndDate = strStartDate; strRealStartDate = strEndDate; realEndDate = startDate; realStartDate = endDate; } tz = QStringLiteral("%1;%2;false;%3"). arg(strRealEndDate, QString::number(utcOffset), realEndDate.toString()); tzList.append(tz); tz = QStringLiteral("%1;%2;true;%3"). arg(strRealStartDate, QString::number(utcOffsetDst), realStartDate.toString()); tzList.append(tz); } else { qCDebug(KCALCORE_LOG) << "unable to parse dst" << argl[1]; } } } if (!QTimeZone::isTimeZoneIdAvailable(name.toLatin1())) { qCDebug(KCALCORE_LOG) << "zone is not valid, parsing error" << tzList; } else { previousZone = d->mCalendar->timeZone(); d->mCalendar->setTimeZoneId(name.toUtf8()); hasTimeZone = true; } } else { qCDebug(KCALCORE_LOG) << "unable to parse tzoffset" << ts; } } // Store all events with a relatedTo property in a list for post-processing d->mEventsRelate.clear(); d->mTodosRelate.clear(); initPropIterator(&i, vcal); // go through all the vobjects in the vcal while (moreIteration(&i)) { curVO = nextVObject(&i); /************************************************************************/ // now, check to see that the object is an event or todo. if (strcmp(vObjectName(curVO), VCEventProp) == 0) { if (!isAPropertyOf(curVO, VCDTstartProp) && !isAPropertyOf(curVO, VCDTendProp)) { qCDebug(KCALCORE_LOG) << "found a VEvent with no DTSTART and no DTEND! Skipping..."; goto SKIP; } anEvent = VEventToEvent(curVO); if (anEvent) { if (hasTimeZone && !anEvent->allDay() && anEvent->dtStart().timeZone() == QTimeZone::utc()) { //This sounds stupid but is how others are doing it, so here //we go. If there is a TZ in the VCALENDAR even if the dtStart //and dtend are in UTC, clients interpret it using also the TZ defined //in the Calendar. I know it sounds braindead but oh well int utcOffSet = anEvent->dtStart().offsetFromUtc(); QDateTime dtStart(anEvent->dtStart().addSecs(utcOffSet)); dtStart.setTimeZone(d->mCalendar->timeZone()); QDateTime dtEnd(anEvent->dtEnd().addSecs(utcOffSet)); dtEnd.setTimeZone(d->mCalendar->timeZone()); anEvent->setDtStart(dtStart); anEvent->setDtEnd(dtEnd); } Event::Ptr old = !anEvent->hasRecurrenceId() ? d->mCalendar->event(anEvent->uid()) : d->mCalendar->event(anEvent->uid(), anEvent->recurrenceId()); if (old) { if (deleted) { d->mCalendar->deleteEvent(old); // move old to deleted removeAllVCal(d->mEventsRelate, old); } else if (anEvent->revision() > old->revision()) { d->mCalendar->deleteEvent(old); // move old to deleted removeAllVCal(d->mEventsRelate, old); d->mCalendar->addEvent(anEvent); // and replace it with this one } } else if (deleted) { old = !anEvent->hasRecurrenceId() ? d->mCalendar->deletedEvent(anEvent->uid()) : d->mCalendar->deletedEvent(anEvent->uid(), anEvent->recurrenceId()); if (!old) { d->mCalendar->addEvent(anEvent); // add this one d->mCalendar->deleteEvent(anEvent); // and move it to deleted } } else { d->mCalendar->addEvent(anEvent); // just add this one } } } else if (strcmp(vObjectName(curVO), VCTodoProp) == 0) { Todo::Ptr aTodo = VTodoToEvent(curVO); if (aTodo) { if (hasTimeZone && !aTodo->allDay() && aTodo->dtStart().timeZone() == QTimeZone::utc()) { //This sounds stupid but is how others are doing it, so here //we go. If there is a TZ in the VCALENDAR even if the dtStart //and dtend are in UTC, clients interpret it usint alse the TZ defined //in the Calendar. I know it sounds braindead but oh well int utcOffSet = aTodo->dtStart().offsetFromUtc(); QDateTime dtStart(aTodo->dtStart().addSecs(utcOffSet)); dtStart.setTimeZone(d->mCalendar->timeZone()); aTodo->setDtStart(dtStart); if (aTodo->hasDueDate()) { QDateTime dtDue(aTodo->dtDue().addSecs(utcOffSet)); dtDue.setTimeZone(d->mCalendar->timeZone()); aTodo->setDtDue(dtDue); } } Todo::Ptr old = !aTodo->hasRecurrenceId() ? d->mCalendar->todo(aTodo->uid()) : d->mCalendar->todo(aTodo->uid(), aTodo->recurrenceId()); if (old) { if (deleted) { d->mCalendar->deleteTodo(old); // move old to deleted removeAllVCal(d->mTodosRelate, old); } else if (aTodo->revision() > old->revision()) { d->mCalendar->deleteTodo(old); // move old to deleted removeAllVCal(d->mTodosRelate, old); d->mCalendar->addTodo(aTodo); // and replace it with this one } } else if (deleted) { old = d->mCalendar->deletedTodo(aTodo->uid(), aTodo->recurrenceId()); if (!old) { d->mCalendar->addTodo(aTodo); // add this one d->mCalendar->deleteTodo(aTodo); // and move it to deleted } } else { d->mCalendar->addTodo(aTodo); // just add this one } } } else if ((strcmp(vObjectName(curVO), VCVersionProp) == 0) || (strcmp(vObjectName(curVO), VCProdIdProp) == 0) || (strcmp(vObjectName(curVO), VCTimeZoneProp) == 0)) { // do nothing, we know these properties and we want to skip them. // we have either already processed them or are ignoring them. ; } else if (strcmp(vObjectName(curVO), VCDayLightProp) == 0) { // do nothing daylights are already processed ; } else { qCDebug(KCALCORE_LOG) << "Ignoring unknown vObject \"" << vObjectName(curVO) << "\""; } SKIP: ; } // while // Post-Process list of events with relations, put Event objects in relation Event::List::ConstIterator eIt; for (eIt = d->mEventsRelate.constBegin(); eIt != d->mEventsRelate.constEnd(); ++eIt) { (*eIt)->setRelatedTo((*eIt)->relatedTo()); } Todo::List::ConstIterator tIt; for (tIt = d->mTodosRelate.constBegin(); tIt != d->mTodosRelate.constEnd(); ++tIt) { (*tIt)->setRelatedTo((*tIt)->relatedTo()); } //Now lets put the TZ back as it was if we have changed it. if (hasTimeZone) { d->mCalendar->setTimeZone(previousZone); } } int VCalFormat::numFromDay(const QString &day) { if (day == QLatin1String("MO ")) { return 0; } if (day == QLatin1String("TU ")) { return 1; } if (day == QLatin1String("WE ")) { return 2; } if (day == QLatin1String("TH ")) { return 3; } if (day == QLatin1String("FR ")) { return 4; } if (day == QLatin1String("SA ")) { return 5; } if (day == QLatin1String("SU ")) { return 6; } return -1; // something bad happened. :) } Attendee::PartStat VCalFormat::readStatus(const char *s) const { QString statStr = QString::fromUtf8(s); statStr = statStr.toUpper(); Attendee::PartStat status; if (statStr == QLatin1String("X-ACTION")) { status = Attendee::NeedsAction; } else if (statStr == QLatin1String("NEEDS ACTION")) { status = Attendee::NeedsAction; } else if (statStr == QLatin1String("ACCEPTED")) { status = Attendee::Accepted; } else if (statStr == QLatin1String("SENT")) { status = Attendee::NeedsAction; } else if (statStr == QLatin1String("TENTATIVE")) { status = Attendee::Tentative; } else if (statStr == QLatin1String("CONFIRMED")) { status = Attendee::Accepted; } else if (statStr == QLatin1String("DECLINED")) { status = Attendee::Declined; } else if (statStr == QLatin1String("COMPLETED")) { status = Attendee::Completed; } else if (statStr == QLatin1String("DELEGATED")) { status = Attendee::Delegated; } else { qCDebug(KCALCORE_LOG) << "error setting attendee mStatus, unknown mStatus!"; status = Attendee::NeedsAction; } return status; } QByteArray VCalFormat::writeStatus(Attendee::PartStat status) const { switch (status) { default: case Attendee::NeedsAction: return "NEEDS ACTION"; break; case Attendee::Accepted: return "ACCEPTED"; break; case Attendee::Declined: return "DECLINED"; break; case Attendee::Tentative: return "TENTATIVE"; break; case Attendee::Delegated: return "DELEGATED"; break; case Attendee::Completed: return "COMPLETED"; break; case Attendee::InProcess: return "NEEDS ACTION"; break; } } void VCalFormat::readCustomProperties(VObject *o, const Incidence::Ptr &i) { VObjectIterator iter; char *s; initPropIterator(&iter, o); while (moreIteration(&iter)) { VObject *cur = nextVObject(&iter); const char *curname = vObjectName(cur); Q_ASSERT(curname); if ((curname[0] == 'X' && curname[1] == '-') && strcmp(curname, ICOrganizerProp) != 0) { // TODO - for the time being, we ignore the parameters part // and just do the value handling here i->setNonKDECustomProperty( curname, QString::fromUtf8(s = fakeCString(vObjectUStringZValue(cur)))); deleteStr(s); } } } void VCalFormat::writeCustomProperties(VObject *o, const Incidence::Ptr &i) { const QMap custom = i->customProperties(); for (QMap::ConstIterator c = custom.begin(); c != custom.end(); ++c) { if (d->mManuallyWrittenExtensionFields.contains(c.key()) || c.key().startsWith("X-KDE-VOLATILE")) { //krazy:exclude=strings continue; } addPropValue(o, c.key().constData(), c.value().toUtf8().constData()); } } void VCalFormat::virtual_hook(int id, void *data) { Q_UNUSED(id); Q_UNUSED(data); Q_ASSERT(false); } diff --git a/src/vcalformat.h b/src/vcalformat.h index 72abf84c9..72f3b4be8 100644 --- a/src/vcalformat.h +++ b/src/vcalformat.h @@ -1,226 +1,231 @@ /* This file is part of the kcalcore library. Copyright (c) 1998 Preston Brown Copyright (c) 2001-2003 Cornelius Schumacher This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ /** @file This file is part of the API for handling calendar data and defines the VCalFormat base class. This class implements the vCalendar format. It provides methods for loading/saving/converting vCalendar format data into the internal representation as Calendar and Incidences. @brief vCalendar format implementation. @author Preston Brown \ @author Cornelius Schumacher \ */ #ifndef KCALCORE_VCALFORMAT_H #define KCALCORE_VCALFORMAT_H #include "kcalcore_export.h" #include "attendee.h" #include "calformat.h" #include "event.h" #include "todo.h" #include "journal.h" struct VObject; class QDate; #define _VCAL_VERSION "1.0" +/* extensions for iMIP / iTIP */ +#define ICOrganizerProp "X-ORGANIZER" +#define ICMethodProp "X-METHOD" +#define ICRequestStatusProp "X-REQUEST-STATUS" + namespace KCalCore { class Event; class Todo; /** @brief vCalendar format implementation. This class implements the vCalendar format. It provides methods for loading/saving/converting vCalendar format data into the internal representation as Calendar and Incidences. */ class KCALCORE_EXPORT VCalFormat : public CalFormat { public: /** Constructor a new vCalendar Format object. */ VCalFormat(); /** Destructor. */ ~VCalFormat() override; /** @copydoc CalFormat::load() */ bool load(const Calendar::Ptr &calendar, const QString &fileName) override; /** @copydoc CalFormat::save() */ bool save(const Calendar::Ptr &calendar, const QString &fileName) override; /** @copydoc CalFormat::fromString() */ bool fromString(const Calendar::Ptr &calendar, const QString &string, bool deleted = false, const QString ¬ebook = QString()) override; /** @copydoc CalFormat::toString() */ QString toString(const Calendar::Ptr &calendar, const QString ¬ebook = QString(), bool deleted = false) override; /** @copydoc CalFormat::fromRawString() */ bool fromRawString(const Calendar::Ptr &calendar, const QByteArray &string, bool deleted = false, const QString ¬ebook = QString()) override; protected: /** Translates a VObject of the TODO type into an Event. @param vtodo is a pointer to a valid VObject object. */ Todo::Ptr VTodoToEvent(VObject *vtodo); /** Translates a VObject into a Event and returns a pointer to it. @param vevent is a pointer to a valid VObject object. */ Event::Ptr VEventToEvent(VObject *vevent); /** Parse TZ tag from vtimezone. */ QString parseTZ(const QByteArray &timezone) const; /** Parse DAYLIGHT tag from vtimezone. */ QString parseDst(QByteArray &timezone) const; /** Takes a QDate and returns a string in the format YYYYMMDDTHHMMSS. @param date is the date to format. */ QString qDateToISO(const QDate &date); /** Takes a QDateTime and returns a string in format YYYYMMDDTHHMMSS. @param date is the date to format. @param zulu if true, then shift the date to UTC. */ QString qDateTimeToISO(const QDateTime &date, bool zulu = true); /** Takes a string in YYYYMMDDTHHMMSS format and returns a valid QDateTime. @param dtStr is a QString containing the date to convert. If this value is invalid, then QDateTime() is returned. */ QDateTime ISOToQDateTime(const QString &dtStr); /** Takes a string in the YYYYMMDD format and returns a valid QDate. @param dtStr is a QString containing the date to convert. If this value is invalid, then QDateTime() is returned. */ QDate ISOToQDate(const QString &dtStr); /** Parse one of the myriad of ISO8601 timezone offset formats, e.g. +- hh : mm +- hh mm +- hh @param s string to be parsed. @param result timezone offset in seconds, if parse succeeded. @return Whether the parse succeeded or not. */ bool parseTZOffsetISO8601(const QString &s, int &result); /** Takes a vCalendar tree of VObjects, and puts all of them that have the "event" property into the dictionary, todos in the todo-list, etc. */ void populate(VObject *vcal, bool deleted = false, const QString ¬ebook = QString()); /** Converts a two letter representation of the day (i.e. MO, TU, WE, etc) and returns a number 0-6 corresponding to that ordinal day of the week. @param day is the QString containing the two letter day representation. */ int numFromDay(const QString &day); /** Converts a status string into an Attendee::PartStat. @param s is a null-terminated character string containing the status to convert. @return a valid Attendee::PartStat. If the string provided is empty, null, or the contents are unrecognized, then Attendee::NeedsAction is returned. */ Attendee::PartStat readStatus(const char *s) const; /** Converts an Attendee::PartStat into a QByteArray string. @param status is the Attendee::PartStat to convert. @return a QByteArray containing the status string. */ QByteArray writeStatus(Attendee::PartStat status) const; void readCustomProperties(VObject *o, const Incidence::Ptr &i); void writeCustomProperties(VObject *o, const Incidence::Ptr &i); protected: /** @copydoc IncidenceBase::virtual_hook() */ void virtual_hook(int id, void *data) override; private: //@cond PRIVATE Q_DISABLE_COPY(VCalFormat) class Private; Private *const d; //@endcond }; } #endif diff --git a/src/versit/port.h b/src/versit/port.h deleted file mode 100644 index a4607803c..000000000 --- a/src/versit/port.h +++ /dev/null @@ -1,75 +0,0 @@ -/*************************************************************************** -(C) Copyright 1996 Apple Computer, Inc., AT&T Corp., International -Business Machines Corporation and Siemens Rolm Communications Inc. - -For purposes of this license notice, the term Licensors shall mean, -collectively, Apple Computer, Inc., AT&T Corp., International -Business Machines Corporation and Siemens Rolm Communications Inc. -The term Licensor shall mean any of the Licensors. - -Subject to acceptance of the following conditions, permission is hereby -granted by Licensors without the need for written agreement and without -license or royalty fees, to use, copy, modify and distribute this -software for any purpose. - -The above copyright notice and the following four paragraphs must be -reproduced in all copies of this software and any software including -this software. - -THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS AND NO LICENSOR SHALL HAVE -ANY OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS OR -MODIFICATIONS. - -IN NO EVENT SHALL ANY LICENSOR BE LIABLE TO ANY PARTY FOR DIRECT, -INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOST PROFITS ARISING OUT -OF THE USE OF THIS SOFTWARE EVEN IF ADVISED OF THE POSSIBILITY OF SUCH -DAMAGE. - -EACH LICENSOR SPECIFICALLY DISCLAIMS ANY WARRANTIES, EXPRESS OR IMPLIED, -INCLUDING BUT NOT LIMITED TO ANY WARRANTY OF NONINFRINGEMENT OR THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE. - -The software is provided with RESTRICTED RIGHTS. Use, duplication, or -disclosure by the government are subject to restrictions set forth in -DFARS 252.227-7013 or 48 CFR 52.227-19, as applicable. - -***************************************************************************/ - -#ifndef __PORT_H__ -#define __PORT_H__ 1 - -#if defined(__CPLUSPLUS__) || defined(__cplusplus) -extern "C" { -#endif - -#define vCardClipboardFormat "+//ISBN 1-887687-00-9::versit::PDI//vCard" -#define vCalendarClipboardFormat "+//ISBN 1-887687-00-9::versit::PDI//vCalendar" - - /* The above strings vCardClipboardFormat and vCalendarClipboardFormat - are globally unique IDs which can be used to generate clipboard format - ID's as per the requirements of a specific platform. For example, in - Windows they are used as the parameter in a call to RegisterClipboardFormat. - For example: - - CLIPFORMAT foo = RegisterClipboardFormat(vCardClipboardFormat); - - */ - -#define vCardMimeType "text/x-vCard" -#define vCalendarMimeType "text/x-vCalendar" - -#ifndef FALSE -#define FALSE 0 -#endif -#ifndef TRUE -#define TRUE 1 -#endif - -#define Parse_Debug(t) - -#if defined(__CPLUSPLUS__) || defined(__cplusplus) -} -#endif - -#endif /* __PORT_H__ */ diff --git a/src/versit/readme.txt b/src/versit/readme.txt deleted file mode 100644 index 5f38fe005..000000000 --- a/src/versit/readme.txt +++ /dev/null @@ -1,944 +0,0 @@ -The vCard/vCalendar C interface is implemented in the set -of files as follows: - -vcc.y, yacc source, and vcc.c, the yacc output you will use -implements the core parser - -vobject.c implements an API that insulates the caller from -the parser and changes in the vCard/vCalendar BNF - -port.h defines compilation environment dependent stuff - -vcc.h and vobject.h are header files for their .c counterparts - -vcaltmp.h and vcaltmp.c implement vCalendar "macro" functions -which you may find useful. - -test.c is a standalone test driver that exercises some of -the features of the APIs provided. Invoke test.exe on a -VCARD/VCALENDAR input text file and you will see the pretty -print output of the internal representation (this pretty print -output should give you a good idea of how the internal -representation looks like -- there is one such output in the -following too). Also, a file with the .out suffix is generated -to show that the internal representation can be written back -in the original text format. - ------------------------------------------------------------------ - - - VObject for VCard/VCalendar - -Table of Contents -================= -1. VObject -2. Internal Representations of VCard/VCalendar -3. Iterating Through VObject's Properties or Values -4. Pretty Printing a VObject Tree -5. Building A VObject Representation of A VCard/VCalendar -6. Converting A VObject Representation Into Its Textual Representation -7. Miscellaneous Notes On VObject APIs usages -8. Brief descriptions of each APIs -9. Additional Programming Notes. - -This document is mainly about the VObject and its APIs. The main -use of a VObject is to represent a VCard or a VCalendar inside -a program. However, its use is not limited to aforemention as it -can represent an arbitrary information that makes up of a tree or -forest of properties/values. - -1. VObject - ======= -A VObject can have a name (id) and a list of associated properties and -a value. Each property is itself a VObject. - -2. Internal Representations of VCard/VCalendar - =========================================== -A list of VCard or a VCalendar is represented by a list of VObjects. -The name (id) of the VObjects in the list is either VCCardProp or -VCCalProp. Each of these VObjects can have a list of properties. -Since a property is represented as a VObject, each of these properties -can have a name, a list of properties, and a value. - -For example, the input file "vobject.vcf": - -BEGIN:VCARD -N:Alden;Roland -FN:Roland H. Alden -ORG:AT&T;Versit Project Office -TITLE:Consultant -EMAIL;WORK;PREF;INTERNET:sf!rincon!ralden@alden.attmail.com -EMAIL;INTERNET:ralden@sfgate.com -EMAIL;MCIMail:242-2200 -LABEL;DOM;POSTAL;PARCEL;HOME;WORK;QUOTED-PRINTABLE:Roland H. Alden=0A= -Suite 2208=0A= -One Pine Street=0A= -San Francisco, CA 94111 -LABEL;POSTAL;PARCEL;HOME;WORK;QUOTED-PRINTABLE:Roland H. Alden=0A= -Suite 2208=0A= -One Pine Street=0A= -San Francisco, CA 94111=0A= -U.S.A. -TEL;WORK;PREF;MSG:+1 415 296 9106 -TEL;WORK;FAX:+1 415 296 9016 -TEL;MSG;CELL:+1 415 608 5981 -ADR:;Suite 2208;One Pine Street;San Francisco;CA;94111;U.S.A. -SOUND:ROW-LAND H ALL-DIN -LOGO;GIF;BASE64: - R0lGODdhpgBOAMQAAP///+/v797e3s7Ozr29va2trZycnIyMjHt7e2NjY1JSUkJC - QjExMSEhIRAQEO///87v9973/73n95zW71K13jGl1nvG50Kt3iGc1gCMzq3e94zO - 7xCU1nO952O15wAAACwAAAAApgBOAAAF/yAgjmRpnmiqrmzrvnAsz3Rt33iu73zv - /8CgcEj8QTaeywWTyWCUno2kSK0KI5tLc8vtNi+WiHVMlj0mFK96nalsxOW4fPSw - cNj4tQc+7xcjGh4WExJTJYUTFkp3eU0eEH6RkpOUlTARhRoWm5ydFpCWoS0QEqAu - ARKaHRcVjV0borEoFl0cSre4Sq67FA+yvwAeTU8XHZ7HmxS6u2wVfMCVpAE3pJoW - ylrMptDcOqSF4OHg3eQ5pInInb7lcc86mNbLzBXsZbRfUOn6ucyNHvVWJHCpQFDf - MWwEEzLqx2YCQCqF3OnItClJNmYcJD7cSAKTuI/gtnEcOQKkyVIk6/+ds5CkFcMM - 61LiENikwi1jBnNyuvUSjwWZOS5uIZarqNFcNl32XMMB6I06GgoJ+bZp1ZKeDl8E - +MC1K1cBIhZ4HUu2LAsCZdOWRQDt20lxIlccSHsgrNq7Xc/ixcsWmNu34WKyYJCW - gQjCe9XqTZy2L4pv04gg2sSKSc8OLgTcBSuWsdkVaD2TdXyiQxebFyjo1Gnx6tJm - LuaqrdtZtNfFtruSNmF5IKujwIsmJbjwtRqNJhrcNVw79wcRAgogmE4ArIjQzj/s - JvHAGCFDQR4UqigPK4sBe62XwO51OwADiMcqUG+iOdcFAL+hW20BfAoEexlwAnu6 - mZDAXQ1EVh//WfhxJB5gIbHgwFgOTOiVAgOuVQKAfKFg3weGwSBYFZMp4hpDGKyA - 3lgJKECWgiMQyBVpW+0V4oJjNfhCNkR1IgWEb21QlRK9GdfFCgeOZYBsXgm4noYj - GEBhAQHYh0J8XenoQnFGdrkUciJY6FUAK15ogozakcBhliKsyZWHDMZQ0wWC/Aim - DB6h01KRr/lXQgFxAqDcWDACgCZpUnrVQJtjwTnWjS6MWAYqqfDnSaEkJOlVXQBo - 2pWTMUJ53WgAuPncCR9q6VQMAYjZlXWJmknCoSUM2p4BC+SaKwG88hoZlvfFMM4f - hQh5TXkv+RklWYtC91mopJIAKFkJlDAW/wF25ShnLbeo5gmQ+1FGkJdrKCuCi2OR - BuwHBcwqKgABrMtVAgpem61XkLbAJ7n8uiIpvGVhO4KpH1QLbbpqLheZvQCkGoNL - thSzSTg2UGVBBzbtaxwKsYrmgLvRAlCmWgwMAADD66rKAgR3XlGspcdkZYK8ibU7 - asgEl+XAyB8I7PCqMWiWncGGimpfAgO4ypXSPpOVLwsRCDJxRD2AoyeRRv5kApO5 - fXwzwvfOKLKtaTWtbQxccmGLTZy8xYlVSvXbhbk0M2YzrYfJJ0K8m+V9NgxpyC04 - UycI/aiuiH9Y8NftDUwWp1Wm5UABnAUKwwRsPFGBt4Oc9PZvGvNLwf8JOZt8Arpe - eY23yDovwIDiBX74NAsPVLDJj3Hh4JEExsKcjrlKf9DsCVx3ZfLqAKBuG1s/A90C - z2KjYHjjyPOdG1spz6BBUr+BcUxUb1nDCTa/VZD2Uv+YkLPAKJC9dNEh7628WgqI - ybzlaA+ufxMa6bxC6ciLUQLcx5UGIAAsAkDA6wQkOxrcY39yo4cQMNWCAPTKV1R4 - wPkgaBxzOc8FtMiF1NoGoXBRJjgoPApmPsjCFlbMdzCM4TFy50IXxI2DPcHAv2rY - gghsEIeu8CAPW6ABIPYEFkOsAeaMyIz0JfGJUExBBGRIRX0IMYovWCIT1eBELNpA - i1vcgta8iANPCIQOghzQABl30J0tXqBla4wjFLFQxZzAUY42CIAd5OYBCuKxB2c4 - I0b28EcrQKADgmSKB9RYyDhA4BqCxIBqrtjIMTwoFeCjYSU3KZMQAAA7 - -BEGIN:VCALENDAR -DCREATED:19960523T100522 -PRODID:-//Alden Roland/Hand Crafted In North Carolina//NONSGML Made By Hand//EN -VERSION:0.3 -BEGIN:VEVENT -START:19960523T120000 -END:19960523T130000 -SUBTYPE:PHONE CALL -SUMMARY:VERSIT PDI PR Teleconference/Interview -DESCRIPTION:VERSIT PDI PR Teleconference/Interview With Tom Streeter and Alden Roland -END:VEVENT -BEGIN:VEVENT -START:19960523T113000 -END:19960523T115500 -SUBTYPE:LUNCH -SUMMARY:Eat in the cafeteria today -END:VEVENT -END:VCALENDAR - -END:VCARD - - -will conceptually be be represented as - vcard - VCNameProp - VCFamilyNameProp=Alden - VCGivenNameProp=Roland - VCFullNameProp=Roland H.Alden - .... - -note that - EMAIL;WORK;PREF;INTERNET:sf!rincon!ralden@alden.attmail.com -will be represented as: - VCEmailAddress=sf!rincon!ralden@alden.attmail.com - VCWork - VCPreferred - VCInternet -where the lower level properties are properties of the property -VCEmailAddress. - -Groupings are flattened out in the VObject representation such -that: - a.b:blah - a.c:blahblah -are represented as: - b=blah - VCGrouping=a - c=blahblah - VCGrouping=a -i.e. one can read the above as: - the property "b" has value "blah" and property "VCGrouping" - with the value "a". - the property "c" has value "blahblah" and property "VCGrouping" - with the value "a". -likewise, multi-level groupings are flatten similarly. e.g. - a.b.c:blah - a.b.e:blahblah ---> - c=blah - VCGrouping=b - VCGrouping=a - e=blahblah - VCGrouping=b - VCGrouping=a -which read: - the property "c" has value "blah" and property "VCGrouping" - with the value "b" which has property "VCGrouping" - with value "a". - the property "e" has value "blahblah" and property "VCGrouping" - with the value "b" which has property "VCGrouping" - with value "a". - -3. Iterating Through VObject's Properties or Values - ================================================ -The following is a skeletal form of iterating through -all properties of a vobject, o: - - // assume the object of interest, o, is of type VObject - VObjectIterator i; - initPropIterator(&i,o); - while (moreIteration(&i)) { - VObject *each = nextVObject(&i); - // ... do something with "each" property - } - -Use the API vObjectName() to access a VObject's name. -Use the API vObjectValueType() to determine if a VObject has - a value. For VCard/VCalendar application, you - should not need this function as practically - all values are either of type VCVT_USTRINGZ or - VCVT_RAW (i.e set by setVObjectUStringZValue and - setVObjectAnyValue APIs respectively), and the - value returned by calls to vObjectUStringZValue - and vObjectAnyValue are 0 if a VObject has no - value. (There is a minor exception where VObject with - VCDataSizeProp has value that is set by - setVObjectLongValue). -Use the APIs vObject???Value() to access a VObject's value. - where ??? is the expected type. -Use the APIs setvObject???Value() to set or modify a VObject's value. - where ??? is the expected type. -Use the API isAPropertyOf() to query if a name match the name of - a property of a VObject. Since isAPropertyOf() return - the matching property, we can use that to retrieve - a property and subsequently the value of the property. - -4. Pretty Printing a VObject Tree - ============================== -VObject tree can be pretty printed with the printVObject() function. -The output of pretty printing a VObject representation of the input -test file "vobject.vcf" is shown below. Note that the indentation -indicates the tree hirerarchy where the immediate children nodes -of a parent node is all at the same indentation level and the -immediate children nodes are the immediate properties of the -associated parent nodes. In the following, {N,FN,ORG,TITLE,...} -are immediate properties of VCARD. {F and G} are properties of N -with value {"Alden" and "Roland"} respectively; FN has no property -but has the value "Roland H. Alden"; EMAIL has value and -the properties WORK, PREF, and INTERNET. - - -VCARD - N - F="Alden" - G="Roland" - FN="Roland H. Alden" - ORG - ORGNAME="AT&T" - OUN="Versit Project Office" - TITLE="Consultant" - EMAIL="sf!rincon!ralden@alden.attmail.com" - WORK - PREF - INTERNET - EMAIL="ralden@sfgate.com" - INTERNET - EMAIL="242-2200" - MCIMail - LABEL="Roland H. Alden - Suite 2208 - One Pine Street - San Francisco, CA 94111" - DOM - POSTAL - PARCEL - HOME - WORK - QP - LABEL="Roland H. Alden - Suite 2208 - One Pine Street - San Francisco, CA 94111 - U.S.A." - POSTAL - PARCEL - HOME - WORK - QP - TEL="+1 415 296 9106" - WORK - PREF - MSG - TEL="+1 415 296 9016" - WORK - FAX - TEL="+1 415 608 5981" - MSG - CELL - ADR - EXT ADD="Suite 2208" - STREET="One Pine Street" - L="San Francisco" - R="CA" - PC="94111" - C="U.S.A." - SOUND="ROW-LAND H ALL-DIN" - LOGO=[raw data] - GIF - BASE64 - DataSize=1482 -VCALENDAR - DCREATED="19960523T100522" - PRODID="-//Alden Roland/Hand Crafted In North Carolina//NONSGML Made By Hand//EN" - VERSION="0.3" - VEVENT - START="19960523T120000" - END="19960523T130000" - SUBTYPE="PHONE CALL" - SUMMARY="VERSIT PDI PR Teleconference/Interview" - DESCRIPTION="VERSIT PDI PR Teleconference/Interview With Tom Streeter and Alden Roland" - VEVENT - START="19960523T113000" - END="19960523T115500" - SUBTYPE="LUNCH" - SUMMARY="Eat in the cafeteria today" - -5. Building A VObject Representation of A VCard/VCalendar - ====================================================== -The parser in vcc.y converts an input file with one or more -VCard/VCalendar that is in their textual representation -into their corresponding VObject representation. - -VObject representation of a VCard/VCalendar can also be built -directly with calls to the VObject building APIs. e.g. - - VObject *prop; - VObject *vcard = newVObject(VCCardProp); - prop = addProp(vcard,VCNameProp); - addPropValue(prop,VCFamilyNameProp,"Alden"); - addPropValue(prop,VCGivenNameProp,"Roland"); - addPropValue(vcard,VCFullNameProp,"Roland H. Alden"); - .... - -6. Converting A VObject Representation Into Its Textual Representation - =================================================================== -The VObject representation can be converted back to its textual -representation via the call to writeVObject() or writeMemVObject() -API. e.g. - a. to write to a file: - // assume vcard is of type VObject - FILE *fp = fopen("alden.vcf","w"); - writeVObject(fp,vcard); - a. to write to memory, and let the API allocate the required memory. - char* clipboard = writeVObject(0,0,vcard); - ... do something to clipboard - free(clipboard); - b. to write to a user allocated buffer: - char clipboard[16384]; - int len = 16384; - char *buf = writeVObject(clipboard,&len,vcard); - ... buf will be equal to clipboard if the write - is successful otherwise 0. - -In the case of writing to memory, the memory buffer can be either -allocated by the API or the user. If the user allocate the -memory for the buffer, then the length of the buffer needs to be -communicated to the API via a variable. The variable passed as -the length argument will be overwritten with the actual size -of the text output. A 0 return value from writeMemVObject() -indicates an error which could be caused by overflowing the -size of the buffer or lack of heap memory. - -7. Miscellaneous Notes On VObject APIs usages - ========================================== -a. vcc.h -- contains basic interfaces to the parser: - VObject* Parse_MIME(const char *input, unsigned long len); - VObject* Parse_MIME_FromFile(FILE *file); - -- both of this return a null-terminated list of - VObject that is either a VCARD or VCALENDAR. - To iterate through this list, do - VObject *t, *v; - v = Parse_Mime_FromFile(fp); - while (v) { - // ... do something to v. - t = v; - v = nextVObjectInList(v); - cleanVObject(t); - } - note that call to cleanVObject will release - resource used to represent the VObject. - -b. vobject.h -- contains basic interfaces to the VObject APIs. - see the header for more details. - The structure of VObject is purposely (hiddened) not exposed - to the user. Every access has to be done via - the APIs. This way, if we need to change the - structure or implementation, the client need not - recompile as long as the interfaces remain the - same. - -c. values of a property is determined by the property definition - itself. The vobject APIs does not attempt to enforce - any of such definition. It is the consumer responsibility - to know what value is expected from a property. e.g - most properties have unicode string value, so to access - the value of these type of properties, you will use - the vObjectUStringZValue() to read the value and - setVObjectUStringZValue() to set or modify the value. - Refer to the VCard and VCalendar specifications for - the definition of each property. - -d. properties name (id) are case incensitive. - -8. Brief descriptions of each APIs - =============================== - * the predefined properties' names (id) are listed under vobject.h - each is of the form VC*Prop. e.g. - #define VC7bitProp "7BIT" - #define VCAAlarmProp "AALARM" - .... - - * consumer of a VObject can only define pointers to VObject. - - * a variable of type VObjectIterator, say "i", can be used to iterate - through a VObject's properties, say "o". The APIs related to - VObjectIterator are: - void initPropIterator(VObjectIterator *i, VObject *o); - -- e.g. usage - initPropIterator(&i,o); - int moreIteration(VObjectIterator *i); - -- e.g. usage - while (moreIteration(&i)) { ... } - VObject* nextVObject(VObjectIterator *i); - -- e.g. usage - while (moreIteration(&i)) { - VObject *each = nextVObject(&i); - } - - * VObject can be chained together to form a list. e.g. of such - use is in the parser where the return value of the parser is - a link list of VObject. A link list of VObject can be - built by: - void addList(VObject **o, VObject *p); - and iterated by - VObject* nextVObjectInList(VObject *o); - -- next VObjectInList return 0 if the list - is exhausted. - - * the following APIs are mainly used to construct a VObject tree: - VObject* newVObject(const char *id); - -- used extensively internally by VObject APIs but when - used externally, its use is mainly limited to the - construction of top level object (e.g. an object - with VCCardProp or VCCalendarProp id). - - void deleteVObject(VObject *p); - -- to deallocate single VObject, for most user, use - cleanVObject(VObject *o) instead for freeing all - resources associated with the VObject. - - char* dupStr(const char *s, unsigned int size); - -- duplicate a string s. If size is 0, the string is - assume to be a null-terminated. - - void deleteStr(const char *p); - -- used to deallocate a string allocated by dupStr(); - - void setVObjectName(VObject *o, const char* id); - -- set the id of VObject o. This function is not - normally used by the user. The setting of id - is normally done as part of other APIs (e.g. - addProp()). - - void setVObjectStringZValue(VObject *o, const char *s); - -- set a string value of a VObject. - - void setVObjectUStringZValue(VObject *o, const wchar_t *s); - -- set a Unicode string value of a VObject. - - void setVObjectIntegerValue(VObject *o, unsigned int i); - -- set an integer value of a VObject. - - void setVObjectLongValue(VObject *o, unsigned long l); - -- set an long integer value of a VObject. - - void setVObjectAnyValue(VObject *o, void *t); - -- set any value of a VObject. The value type is - unspecified. - - VObject* setValueWithSize(VObject *prop, void *val, unsigned int size); - -- set a raw data (stream of bytes) value of a VObject - whose size is size. The internal VObject representation - is - this object = val - VCDataSizeProp=size - i.e. the value val will be attached to the VObject prop - and a property of VCDataSize whose value is size - is also added to the object. - - void setVObjectVObjectValue(VObject *o, VObject *p); - -- set a VObject as the value of another VObject. - - const char* vObjectName(VObject *o); - -- retrieve the VObject's Name (i.e. id). - - const char* vObjectStringZValue(VObject *o); - -- retrieve the VObject's value interpreted as - null-terminated string. - - const wchar_t* vObjectUStringZValue(VObject *o); - -- retrieve the VObject's value interpreted as - null-terminated unicode string. - - unsigned int vObjectIntegerValue(VObject *o); - -- retrieve the VObject's value interpreted as - integer. - - unsigned long vObjectLongValue(VObject *o); - -- retrieve the VObject's value interpreted as - long integer. - - void* vObjectAnyValue(VObject *o); - -- retrieve the VObject's value interpreted as - any value. - - VObject* vObjectVObjectValue(VObject *o); - -- retrieve the VObject's value interpreted as - a VObject. - - VObject* addVObjectProp(VObject *o, VObject *p); - -- add a VObject p as a property of VObject o. - (not normally used externally for building a - VObject). - - VObject* addProp(VObject *o, const char *id); - -- add a property whose name is id to VObject o. - - VObject* addPropValue(VObject *o, const char *id, const char *v); - -- add a property whose name is id and whose value - is a null-terminated string to VObject o. - - VObject* addPropSizedValue(VObject *o, const char *id, - const char *v, unsigned int size); - -- add a property whose name is id and whose value - is a stream of bytes of size size, to VObject o. - - VObject* addGroup(VObject *o, const char *g); - -- add a group g to VObject o. - e.g. if g is a.b.c, you will have - o - c - VCGroupingProp=b - VCGroupingProp=a - and the object c is returned. - - VObject* isAPropertyOf(VObject *o, const char *id); - -- query if a property by the name id is in o and - return the VObject that represent that property. - - void printVObject(VObject *o); - -- pretty print VObject o to stdout (for debugging use). - - void writeVObject(FILE *fp, VObject *o); - -- convert VObject o to its textual representation and - write it to file. - - char* writeMemVObject(char *s, int *len, VObject *o); - -- convert VObject o to its textual representation and - write it to memory. If s is 0, then memory required - to hold the textual representation will be allocated - by this API. If a variable len is passed, len will - be overwriten with the byte size of the textual - representation. If s is non-zero, then s has to - be a user allocated buffer whose size has be passed - in len as a variable. Memory allocated by the API - has to be freed with call to free. The return value - of this API is either the user supplied buffer, - the memory allocated by the API, or 0 (in case of - failure). - - void cleanStrTbl(); - -- this function has to be called when all - VObject has been destroyed. - - void cleanVObject(VObject *o); - -- release all resources used by VObject o. - - wchar_t* fakeUnicode(const char *ps, int *bytes); - -- convert char* to wchar_t*. - - extern int uStrLen(const wchar_t *u); - -- length of unicode u. - - char *fakeCString(const wchar_t *u); - -- convert wchar_t to CString (blindly assumes that - this could be done). - -9. Additional Programming Notes - ============================ -In the following notes, please refers to the listing -of Example.vcf and its VObject Representation -(shown at the end of this section). - -* Handling the Return Value of the VCard/VCalendar Parser - The example input text file contains two root VObjects - (a VCalendar and a VCard). The output of the VCard/VCalendar - parser is a null-terminated list of VObjects. For this - particular input file, the list will have two VObjects. - The following shows a template for iterating through the - output of the Parser: - - VObject *t, *v; - v = Parse_Mime_fromFileName("example.vcf"); - while (v) { - // currently, v will either be a VCard or a VCalendar - // do whatever your application need to do to - // v here ... - t = v; - v = nextVObjectInList(v); - cleanVObject(t); - } - -* Iterating Through a VCard/VCalendar VObject - From the VObject APIs point of view, a VCard VObject - is the same as a VCalendar VObject. However, the application - needs to know what are in a VCard or a VCalendar. - For example, A VCalendar VObject can have VCDCreatedProp, - a VCGEOLocationProp, etc, and one or more VCEventProp and - or VCTodoProp. The VCEventProp and VCTodoProp can have - many properties of their own, which in turn could have - more properties (e.g. VCDAlarmProp can be a VCEventProp - VObject's property, and VCRunTimeProp can be a - VCDAlarmProp VObject's property. Because a VObject tree - can be arbitrarily complex, in general, to process all - properties and values of a VObject tree, a recursive walk - is desirable. An example recursive VObject tree walk - can be found in the vobject.c source lines for printVObject* - and writeVObject* APIs. Depending on what the application need - to do with a VCard or a VCalendar, a recursive walk - of the VObject tree may or may not be desirable. An example - template of a non-recursive walk is shown below: - - void processVCardVCalendar(char *inputFile) - { - VObject *t, *v; - v = Parse_Mime_fromFileName(inputFile); - while (v) { - char *n = vObjectName(v); - if (strcmp(n,VCCardProp) == 0) { - do_VCard(v); - } - else if (strcmp(n,VCCalendarProp) == 0) { - do_VCalendar(v); - } - else { - // don't know how to handle anything else! - } - t = v; - v = nextVObjectInList(v); - cleanVObject(t); - } - } - - void do_VCard(VObject *vcard) - { - VObjectIterator t; - initPropIterator(&t,vcard); - while (moreIteration(&t)) { - VObject *eachProp = nextVObject(&t); - // The primarly purpose of this example is to - // show how to iterate through a VCard VObject, - // it is not meant to be efficient at all. - char *n = vObjectName(eachProp); - if (strcmp(n,VCNameProp)==0) { - do_name(eachProp); - } - else if (strcmp(n,VCEmailProp)==0) { - do_email(eachProp); - } - else if (strcmp(n,VCLabelProp)==0) { - do_label(eachProp); - } - else if .... - } - } - - void do_VCalendar(VObject *vcal) - { - VObjectIterator t; - initPropIterator(&t,vcard); - while (moreIteration(&t)) { - VObject *eachProp = nextVObject(&t); - // The primarly purpose of this example is to - // show how to iterate through a VCalendar VObject, - // it is not meant to be efficient at all. - char *n = vObjectName(eachProp); - if (strcmp(n,VCDCreatedProp)==0) { - do_DCreated(eachProp); - } - else if (strcmp(n,VCVersionProp)==0) { - do_Version(eachProp); - } - else if (strcmp(n,VCTodoProp)==0) { - do_Todo(eachProp); - } - else if (strcmp(n,VCEventProp)==0) { - do_Event(eachProp); - } - else if .... - } - } - - void do_Todo(VObject *vtodo) { ... } - - void do_Event(VObject *vevent) { ... } - - ... - -* Property's Values and Properties - The VObject APIs do not attempt to check for the - correctness of the values of a property. Nor do they - will prevent the user from attaching a non-VCard/VCalendar - standard property to a VCard/VCalendar property. Take - the example of line [11] of the example, "O.K" is not - a valid value of VCStatusProp. It is up to the application - to accept or reject the value of a property. - -* Output of printVObject - PrintVObject pretty prints a VObject tree in human - readable form. See the listing at the end of the file - for an example output of printVObject on the example - input file "Example.vcf". - - Note that binary data are not shown in the output of - printVObject. Instead, a note is made ([raw data]) to - indicate that there exists such a binary data. - -* Note on Binary Data - When the value of a property is a binary data, it is only - useful to know the size of the binary data. - - In the case of the VCard/VCalendar parser, it chooses - to represent the size information as a separate property - called VCDataSizeProp whose value is the size of the binary - data. The APIs sequence to construct the VObject subtree - of line [44] of Example.vcf is - - // VObject *vcard; - VObject *p1 = addProp(vcard,VCLogoProp); - (void) addProp(p1,VCGIFProp); - (void) addProp(p1,VCBASE64Prop); - VObject *p2 = addProp(p1,VCDataSizeProp); - (void) setVObjectLongValue(p2,1482); - setVObjectAnyValue(vcard,...pointer to binary data); - - Note the presence of VCBase64Prop will cause the - writeVObject API to output the binary data as BASE64 text. - For VCard/VCalendar application, having the VCBase64Prop - property is pratically always necessary for property with - binary data as its value. - -* Note on Quoted-Printable String - String value with embedded newline are written out as - quoted-prinatable string. It is therefore important - to mark a property with a string value that has - one or more embedded newlines, with the VCQutedPrintableProp - property. e.g. - - // VObject *root; - char *msg="To be\nor\nnot to be"; - VObject *p = addPropValue(root,VCDescriptionProp,msg); - // the following is how you mark a property with - // a property. In this case, the marker is - // VCQuotedPrintableProp - addProp(p,VCQuotedPrintableProp); - -* Note on Unicode - Although, the current parser takes ASCII text file only, - string values are all stored as Unicode in the VObject tree. - For now, when using the VObject APIs to construct a - VObject tree, one should always convert ASCII string value - to a Unicode string value: - - // VObject *root; - VObject *p = addProp(root,VCSomeProp); - setVObjectUStringZValue(p,fakeUnicode(someASCIIStringZvalue)); - - An API is provided to simplify the above process: - - addPropValue(root,VCSomeProp,someASCIIStringZValue); - - Note that someASCIISTringZValue is automatically converted to - Unicode by addPropValue API, where as, the former code - sequence do an explicit call to fakeUnicode. - - To read back the value, one should use the vObjectUStringZValue - API not vObjectStringZValue API. The value returned by the - vObjectUStringZValue API is a Unicode string. If the application - do not know how to handle Unicode string, it can use the - fakeCString API to convert it back to ASCII string (as long - as the conversion is meaningful). - - Note that fakeCString return a heap allocated memory. It is - important to call deleteStr on fakeCString return value if - it is not longer required (or there will be memory leak). - - NOTE: Unfortunately, at the point when this document is written, - there is still no consensus on how Unicode is to be handled - in the textual representation of VCard/VCalendar. So, there - is no version of writeVObject and the parser to output and - input Unicode textual representation of VCard/VCalendar. - - -Example.vcf ------------ -line -number Input Text (example.vcf) ------- ---------- -1 BEGIN:VCALENDAR -2 DCREATED:19961102T100522 -3 GEO:0,0 -4 VERSION:1.0 -5 BEGIN:VEVENT -6 DTSTART:19961103T000000 -7 DTEND:20000101T000000 -8 DESCRIPTION;QUOTED-PRINTABLE:To be =0A= -9 or =0A= -10 not to be -11 STATUS:O.K. -12 X-ACTION:No action required -13 DALARM:19961103T114500;5;3;Enjoy -14 MALARM:19970101T120000;;;johny@nowhere.com;Call Mom. -15 END:VEVENT -16 -17 BEGIN:VTODO -18 DUE:19960614T0173000 -19 DESCRIPTION:Relex. -20 END:VTODO -21 -22 END:VCALENDAR -23 -24 BEGIN:VCARD -25 N:Alden;Roland -26 FN:Roland H. Alden -27 ORG:AT&T;Versit Project Office -28 TITLE:Consultant -29 EMAIL;WORK;PREF;INTERNET:ralden@ralden.com -30 LABEL;DOM;POSTAL;PARCEL;HOME;WORK;QUOTED-PRINTABLE:Roland H. Alden=0A= -31 Suite 2208=0A= -32 One Pine Street=0A= -33 San Francisco, CA 94111 -34 LABEL;POSTAL;PARCEL;HOME;WORK;QUOTED-PRINTABLE:Roland H. Alden=0A= -35 Suite 2208=0A= -36 One Pine Street=0A= -37 San Francisco, CA 94111=0A= -38 U.S.A. -39 TEL;WORK;PREF;MSG:+1 415 296 9106 -40 TEL;WORK;FAX:+1 415 296 9016 -41 TEL;MSG;CELL:+1 415 608 5981 -42 ADR:;Suite 2208;One Pine Street;San Francisco;CA;94111;U.S.A. -43 SOUND:ROW-LAND H ALL-DIN -44 LOGO;GIF;BASE64: -45 R0lGODdhpgBOAMQAAP///+/v797e3s7Ozr29va2trZycnIyMjHt7e2NjY1JSUkJC - ... 30 lines of BASE64 data not shown here. -76 END:VCARD - - -VObject Representation of Example.vcf: -------------------------------------- -line -in -text -file VObject Tree as Printed by printVObject API ----- ------------------------------------------- -1 VCALENDAR -2 DCREATED="19961102T100522" -3 GEO="0,0" -4 VERSION="1.0" -5 VEVENT -6 DTSTART="19961103T000000" -7 DTEND="20000101T000000" -8 DESCRIPTION="To be -9 or -10 not to be" -8 QUOTED-PRINTABLE -11 STATUS="O.K." -12 X-ACTION="No action required" -13 DALARM -13 RUNTIME="19961103T114500" -13 SNOOZETIME="5" -13 REPEATCOUNT="3" -13 DISPLAYSTRING="Enjoy" -14 MALARM -14 RUNTIME="19970101T120000" -14 EMAIL="johny@nowhere.com" -14 NOTE="Call Mom" -17 VTODO -18 DUE="19960614T0173000" -19 DESCRIPTION="Relex." -24 VCARD -25 N -25 F="Alden" -25 G="Roland" -26 FN="Roland H. Alden" -27 ORG -27 ORGNAME="AT&T" -27 OUN="Versit Project Office" -28 TITLE="Consultant" -29 EMAIL="ralden@alden.com" -29 WORK -29 PREF -29 INTERNET -30 LABEL="Roland H. Alden -31 Suite 2208 -32 One Pine Street -33 San Francisco, CA 94111" -30 DOM -30 POSTAL -30 PARCEL -30 HOME -30 WORK -30 QUOTED-PRINTABLE -34 LABEL="Roland H. Alden -35 Suite 2208 -36 One Pine Street -37 San Francisco, CA 94111 -38 U.S.A." -34 POSTAL -34 PARCEL -34 HOME -34 WORK -34 QUOTED-PRINTABLE -39 TEL="+1 415 296 9106" -39 WORK -39 PREF -39 MSG -40 TEL="+1 415 296 9016" -40 WORK -40 FAX -41 TEL="+1 415 608 5981" -41 MSG -41 CELL -42 ADR -42 EXT ADD="Suite 2208" -42 STREET="One Pine Street" -42 L="San Francisco" -42 R="CA" -42 PC="94111" -42 C="U.S.A." -43 SOUND="ROW-LAND H ALL-DIN" -44 LOGO=[raw data] -44 GIF -44 BASE64 -44 DATASIZE=1482 - diff --git a/src/versit/vcc.h b/src/versit/vcc.h deleted file mode 100644 index 86eb602ce..000000000 --- a/src/versit/vcc.h +++ /dev/null @@ -1,73 +0,0 @@ -/*************************************************************************** -(C) Copyright 1996 Apple Computer, Inc., AT&T Corp., International -Business Machines Corporation and Siemens Rolm Communications Inc. - -For purposes of this license notice, the term Licensors shall mean, -collectively, Apple Computer, Inc., AT&T Corp., International -Business Machines Corporation and Siemens Rolm Communications Inc. -The term Licensor shall mean any of the Licensors. - -Subject to acceptance of the following conditions, permission is hereby -granted by Licensors without the need for written agreement and without -license or royalty fees, to use, copy, modify and distribute this -software for any purpose. - -The above copyright notice and the following four paragraphs must be -reproduced in all copies of this software and any software including -this software. - -THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS AND NO LICENSOR SHALL HAVE -ANY OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS OR -MODIFICATIONS. - -IN NO EVENT SHALL ANY LICENSOR BE LIABLE TO ANY PARTY FOR DIRECT, -INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOST PROFITS ARISING OUT -OF THE USE OF THIS SOFTWARE EVEN IF ADVISED OF THE POSSIBILITY OF SUCH -DAMAGE. - -EACH LICENSOR SPECIFICALLY DISCLAIMS ANY WARRANTIES, EXPRESS OR IMPLIED, -INCLUDING BUT NOT LIMITED TO ANY WARRANTY OF NONINFRINGEMENT OR THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE. - -The software is provided with RESTRICTED RIGHTS. Use, duplication, or -disclosure by the government are subject to restrictions set forth in -DFARS 252.227-7013 or 48 CFR 52.227-19, as applicable. - -***************************************************************************/ - -#ifndef __VCC_H__ -#define __VCC_H__ 1 - -#include "vobject.h" - -#if defined(__CPLUSPLUS__) || defined(__cplusplus) -extern "C" { -#endif - - typedef void (*MimeErrorHandler)(const char *); - - extern void registerMimeErrorHandler(MimeErrorHandler); - - extern VObject *Parse_MIME(const char *input, unsigned long len); - extern VObject *Parse_MIME_FromFileName(const char *fname); - - /* NOTE regarding Parse_MIME_FromFile - The function below, Parse_MIME_FromFile, come in two flavors, - neither of which is exported from the DLL. Each version takes - a CFile or FILE* as a parameter, neither of which can be - passed across a DLL interface (at least that is my experience). - If you are linking this code into your build directly then - you may find them a more convenient API that the other flavors - that take a file name. If you use them with the DLL LIB you - will get a link error. - */ - - extern VObject *Parse_MIME_FromFile(FILE *file); - -#if defined(__CPLUSPLUS__) || defined(__cplusplus) -} -#endif - -#endif /* __VCC_H__ */ - diff --git a/src/versit/vcc.y b/src/versit/vcc.y deleted file mode 100644 index d8188eec6..000000000 --- a/src/versit/vcc.y +++ /dev/null @@ -1,1225 +0,0 @@ -%{ - -/*************************************************************************** -(C) Copyright 1996 Apple Computer, Inc., AT&T Corp., International -Business Machines Corporation and Siemens Rolm Communications Inc. - -For purposes of this license notice, the term Licensors shall mean, -collectively, Apple Computer, Inc., AT&T Corp., International -Business Machines Corporation and Siemens Rolm Communications Inc. -The term Licensor shall mean any of the Licensors. - -Subject to acceptance of the following conditions, permission is hereby -granted by Licensors without the need for written agreement and without -license or royalty fees, to use, copy, modify and distribute this -software for any purpose. - -The above copyright notice and the following four paragraphs must be -reproduced in all copies of this software and any software including -this software. - -THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS AND NO LICENSOR SHALL HAVE -ANY OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS OR -MODIFICATIONS. - -IN NO EVENT SHALL ANY LICENSOR BE LIABLE TO ANY PARTY FOR DIRECT, -INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOST PROFITS ARISING OUT -OF THE USE OF THIS SOFTWARE EVEN IF ADVISED OF THE POSSIBILITY OF SUCH -DAMAGE. - -EACH LICENSOR SPECIFICALLY DISCLAIMS ANY WARRANTIES, EXPRESS OR IMPLIED, -INCLUDING BUT NOT LIMITED TO ANY WARRANTY OF NONINFRINGEMENT OR THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE. - -The software is provided with RESTRICTED RIGHTS. Use, duplication, or -disclosure by the government are subject to restrictions set forth in -DFARS 252.227-7013 or 48 CFR 52.227-19, as applicable. - -***************************************************************************/ - -/* - * src: vcc.c - * doc: Parser for vCard and vCalendar. Note that this code is - * generated by a yacc parser generator. Generally it should not - * be edited by hand. The real source is vcc.y. The #line directives - * can be commented out here to make it easier to trace through - * in a debugger. However, if a bug is found it should - * be fixed in vcc.y and this file regenerated. - */ - - -/* debugging utilities */ -#ifdef __DEBUG -#define DBG_(x) printf x -#else -#define DBG_(x) -#endif - -/**** External Functions ****/ - -/* assign local name to parser variables and functions so that - we can use more than one yacc based parser. -*/ - -#define yyparse mime_parse -#define yylex mime_lex -#define yyerror mime_error -#define yychar mime_char -/* #define p_yyval p_mime_val */ -#undef yyval -#define yyval mime_yyval -/* #define p_yylval p_mime_lval */ -#undef yylval -#define yylval mime_yylval -#define yydebug mime_debug -#define yynerrs mime_nerrs -#define yyerrflag mime_errflag -#define yyss mime_ss -#define yyssp mime_ssp -#define yyvs mime_vs -#define yyvsp mime_vsp -#define yylhs mime_lhs -#define yylen mime_len -#define yydefred mime_defred -#define yydgoto mime_dgoto -#define yysindex mime_sindex -#define yyrindex mime_rindex -#define yygindex mime_gindex -#define yytable mime_table -#define yycheck mime_check -#define yyname mime_name -#define yyrule mime_rule -#undef YYPREFIX -#define YYPREFIX "mime_" - - -#ifndef _NO_LINE_FOLDING -#define _SUPPORT_LINE_FOLDING 1 -#endif - -#include -#include -#include -#include -#include "vcc.h" - -#ifdef _WIN32 -#define strncasecmp _strnicmp -#define strcasecmp _stricmp -#endif - -/* The following is a hack that I hope will get things compiling - * on SunOS 4.1.x systems - */ -#ifndef SEEK_SET -#define SEEK_SET 0 /* Seek from beginning of file. */ -#define SEEK_CUR 1 /* Seek from current position. */ -#define SEEK_END 2 /* Seek from end of file. */ -#endif - -/**** Types, Constants ****/ - -#define YYDEBUG 0 /* 1 to compile in some debugging code */ -#define MAXTOKEN 256 /* maximum token (line) length */ -#define YYSTACKSIZE 1000 /* ~unref ? */ -#define MAXLEVEL 10 /* max # of nested objects parseable */ - /* (includes outermost) */ - - -/**** Global Variables ****/ -int mime_lineNum, mime_numErrors; /* yyerror() can use these */ -static VObject* vObjList; -static VObject *curProp; -static VObject *curObj; -static VObject* ObjStack[MAXLEVEL]; -static int ObjStackTop; - - -/* A helpful utility for the rest of the app. */ -#ifdef __CPLUSPLUS__ -extern "C" { -#endif - - /* static void Parse_Debug(const char *s);*/ - static void yyerror(const char *s); - -#ifdef __CPLUSPLUS__ - }; -#endif - -int yyparse(); -static int yylex(); - -static VObject* popVObject(); - - -enum LexMode { - L_NORMAL, - L_VCARD, - L_VCAL, - L_VEVENT, - L_VTODO, - L_VALUES, - L_BASE64, - L_QUOTED_PRINTABLE - }; - -/**** Private Forward Declarations ****/ -static int pushVObject(const char *prop); -static VObject* popVObject(); -char* lexDataFromBase64(); -static void lexPopMode(int top); -static int lexWithinMode(enum LexMode mode); -static void lexPushMode(enum LexMode mode); -static void enterProps(const char *s); -static void enterAttr(const char *s1, const char *s2); -/* static void enterValues(const char *value); */ -static void appendValue(const char *value); -static void mime_error_(const char *s); - -%} - -/***************************************************************************/ -/*** The grammar ****/ -/***************************************************************************/ - -%union { - char *str; - VObject *vobj; - } - -%token - EQ COLON DOT SEMICOLON SPACE HTAB LINESEP NEWLINE - BEGIN_VCARD END_VCARD BEGIN_VCAL END_VCAL - BEGIN_VEVENT END_VEVENT BEGIN_VTODO END_VTODO - ID - -/* - * NEWLINE is the token that would occur outside a vCard, - * while LINESEP is the token that would occur inside a vCard. - */ - -%token - STRING ID - -%type name value - -%type vcard vcal vobject - -%start mime - -%% - - -mime: vobjects - ; - -vobjects: vobject - { addList(&vObjList, $1); curObj = 0; } - vobjects - | vobject - { addList(&vObjList, $1); curObj = 0; } - ; - -vobject: vcard - | vcal - ; - -vcard: - BEGIN_VCARD - { - lexPushMode(L_VCARD); - if (!pushVObject(VCCardProp)) YYERROR; - } - items END_VCARD - { - lexPopMode(0); - $$ = popVObject(); - } - | BEGIN_VCARD - { - lexPushMode(L_VCARD); - if (!pushVObject(VCCardProp)) YYERROR; - } - END_VCARD - { - lexPopMode(0); - $$ = popVObject(); - } - ; - -items: item items - | item - ; - -item: prop COLON - { - lexPushMode(L_VALUES); - } - values LINESEP - { - if (lexWithinMode(L_BASE64) || lexWithinMode(L_QUOTED_PRINTABLE)) - lexPopMode(0); - lexPopMode(0); - } - | error - ; - -prop: name - { - enterProps($1); - } - attr_params - | name - { - enterProps($1); - } - ; - -attr_params: attr_param attr_params - | attr_param - ; - -attr_param: SEMICOLON attr - ; - -attr: name - { - enterAttr($1,0); - } - | name EQ name - { - enterAttr($1,$3); - - } - ; - -name: ID - ; - -values: value SEMICOLON { appendValue($1); } values - | value - { appendValue($1); } - ; - -value: STRING - | - { $$ = 0; } - ; - -vcal: - BEGIN_VCAL - { if (!pushVObject(VCCalProp)) YYERROR; } - calitems - END_VCAL - { $$ = popVObject(); } - | BEGIN_VCAL - { if (!pushVObject(VCCalProp)) YYERROR; } - END_VCAL - { $$ = popVObject(); } - ; - -calitems: calitem calitems - | calitem - ; - -calitem: - eventitem - | todoitem - | items - ; - -eventitem: - BEGIN_VEVENT - { - lexPushMode(L_VEVENT); - if (!pushVObject(VCEventProp)) YYERROR; - } - items - END_VEVENT - { - lexPopMode(0); - popVObject(); - } - | BEGIN_VEVENT - { - lexPushMode(L_VEVENT); - if (!pushVObject(VCEventProp)) YYERROR; - } - END_VEVENT - { - lexPopMode(0); - popVObject(); - } - ; - -todoitem: - BEGIN_VTODO - { - lexPushMode(L_VTODO); - if (!pushVObject(VCTodoProp)) YYERROR; - } - items - END_VTODO - { - lexPopMode(0); - popVObject(); - } - | BEGIN_VTODO - { - lexPushMode(L_VTODO); - if (!pushVObject(VCTodoProp)) YYERROR; - } - END_VTODO - { - lexPopMode(0); - popVObject(); - } - ; - -%% -/****************************************************************************/ -static int pushVObject(const char *prop) - { - VObject *newObj; - if (ObjStackTop == MAXLEVEL) - return FALSE; - - ObjStack[++ObjStackTop] = curObj; - - if (curObj) { - newObj = addProp(curObj,prop); - curObj = newObj; - } - else - curObj = newVObject(prop); - - return TRUE; - } - - -/****************************************************************************/ -/* This pops the recently built vCard off the stack and returns it. */ -static VObject* popVObject() - { - VObject *oldObj; - if (ObjStackTop < 0) { - yyerror("pop on empty Object Stack\n"); - return 0; - } - oldObj = curObj; - curObj = ObjStack[ObjStackTop--]; - - return oldObj; - } - - -/* static void enterValues(const char *value) */ -/* { */ -/* if (fieldedProp && *fieldedProp) { */ -/* if (value) { */ -/* addPropValue(curProp,*fieldedProp,value); */ -/* } */ - /* else this field is empty, advance to next field */ -/* fieldedProp++; */ -/* } */ -/* else { */ -/* if (value) { */ -/* setVObjectUStringZValue_(curProp,fakeUnicode(value,0)); */ -/* } */ -/* } */ -/* deleteStr(value); */ -/* } */ - -static void appendValue(const char *value) -{ - char *p1, *p2; - wchar_t *p3; - int i; - - if (fieldedProp && *fieldedProp) { - if (value) { - addPropValue(curProp, *fieldedProp, value); - } - /* else this field is empty, advance to next field */ - fieldedProp++; - } else { - if (value) { - if (vObjectUStringZValue(curProp)) { - p1 = fakeCString(vObjectUStringZValue(curProp)); - p2 = malloc(sizeof(char *) * (strlen(p1)+strlen(value)+1)); - strcpy(p2, p1); - deleteStr(p1); - - i = strlen(p2); - p2[i] = ','; - p2[i+1] = '\0'; - p2 = strcat(p2, value); - p3 = (wchar_t *) vObjectUStringZValue(curProp); - free(p3); - setVObjectUStringZValue_(curProp,fakeUnicode(p2,0)); - deleteStr(p2); - } else { - setVObjectUStringZValue_(curProp,fakeUnicode(value,0)); - } - } - } - deleteStr(value); -} - - -static void enterProps(const char *s) - { - curProp = addGroup(curObj,s); - deleteStr(s); - } - -static void enterAttr(const char *s1, const char *s2) - { - const char *p1=0L, *p2=0L; - p1 = lookupProp_(s1); - if (s2) { - VObject *a; - p2 = lookupProp_(s2); - a = addProp(curProp,p1); - setVObjectStringZValue(a,p2); - } - else - addProp(curProp,p1); - if (strcasecmp(p1,VCBase64Prop) == 0 || (s2 && strcasecmp(p2,VCBase64Prop)==0)) - lexPushMode(L_BASE64); - else if (strcasecmp(p1,VCQuotedPrintableProp) == 0 - || (s2 && strcasecmp(p2,VCQuotedPrintableProp)==0)) - lexPushMode(L_QUOTED_PRINTABLE); - deleteStr(s1); deleteStr(s2); - } - - -#define MAX_LEX_LOOKAHEAD_0 32 -#define MAX_LEX_LOOKAHEAD 64 -#define MAX_LEX_MODE_STACK_SIZE 10 -#define LEXMODE() (lexBuf.lexModeStack[lexBuf.lexModeStackTop]) - -struct LexBuf { - /* input */ - FILE *inputFile; - char *inputString; - unsigned long curPos; - unsigned long inputLen; - /* lookahead buffer */ - /* -- lookahead buffer is short instead of char so that EOF - / can be represented correctly. - */ - unsigned long len; - short buf[MAX_LEX_LOOKAHEAD]; - unsigned long getPtr; - /* context stack */ - unsigned long lexModeStackTop; - enum LexMode lexModeStack[MAX_LEX_MODE_STACK_SIZE]; - /* token buffer */ - unsigned long maxToken; - char *strs; - unsigned long strsLen; - } lexBuf; - -static void lexPushMode(enum LexMode mode) - { - if (lexBuf.lexModeStackTop == (MAX_LEX_MODE_STACK_SIZE-1)) - yyerror("lexical context stack overflow"); - else { - lexBuf.lexModeStack[++lexBuf.lexModeStackTop] = mode; - } - } - -static void lexPopMode(int top) - { - /* special case of pop for ease of error recovery -- this - version will never underflow */ - if (top) - lexBuf.lexModeStackTop = 0; - else - if (lexBuf.lexModeStackTop > 0) lexBuf.lexModeStackTop--; - } - -static int lexWithinMode(enum LexMode mode) { - unsigned long i; - for (i=0;i 0 && lexBuf.buf[lexBuf.getPtr]!=EOF) { - /* don't skip EOF. */ - lexBuf.getPtr = (lexBuf.getPtr + 1) % MAX_LEX_LOOKAHEAD; - lexBuf.len--; - } - } - -static int lexLookahead() { - int c = (lexBuf.len)? - lexBuf.buf[lexBuf.getPtr]: - lexGeta(); - /* do the \r\n -> \n or \r -> \n translation here */ - if (c == '\r') { - int a = (lexBuf.len>1)? - lexBuf.buf[(lexBuf.getPtr+1)%MAX_LEX_LOOKAHEAD]: - lexGeta_(1); - if (a == '\n') { - lexSkipLookahead(); - } - lexBuf.buf[lexBuf.getPtr] = c = '\n'; - } - else if (c == '\n') { - int a; - if (lexBuf.len > 1) - a = lexBuf.buf[lexBuf.getPtr]; - else - a = lexGeta_(1); - if (a == '\r') { - lexSkipLookahead(); - } - lexBuf.buf[lexBuf.getPtr] = '\n'; - } - return c; - } - -static int lexGetc() { - int c = lexLookahead(); - if (lexBuf.len > 0 && lexBuf.buf[lexBuf.getPtr]!=EOF) { - /* EOF will remain in lookahead buffer */ - lexBuf.getPtr = (lexBuf.getPtr + 1) % MAX_LEX_LOOKAHEAD; - lexBuf.len--; - } - return c; - } - -static void lexSkipLookaheadWord() { - if (lexBuf.strsLen <= lexBuf.len) { - lexBuf.len -= lexBuf.strsLen; - lexBuf.getPtr = (lexBuf.getPtr + lexBuf.strsLen) % MAX_LEX_LOOKAHEAD; - } - } - -static void lexClearToken() - { - lexBuf.strsLen = 0; - } - -static void lexAppendc(int c) - { - /* not sure if I am doing this right to fix purify report -- PGB */ - lexBuf.strs = (char *) realloc(lexBuf.strs, (size_t) lexBuf.strsLen + 1); - lexBuf.strs[lexBuf.strsLen] = c; - /* append up to zero termination */ - if (c == 0) return; - lexBuf.strsLen++; - if (lexBuf.strsLen > lexBuf.maxToken) { - /* double the token string size */ - lexBuf.maxToken <<= 1; - lexBuf.strs = (char*) realloc(lexBuf.strs,(size_t)lexBuf.maxToken); - } - } - -static char* lexStr() { - return dupStr(lexBuf.strs,(size_t)lexBuf.strsLen+1); - } - -static void lexSkipWhite() { - int c = lexLookahead(); - while (c == ' ' || c == '\t') { - lexSkipLookahead(); - c = lexLookahead(); - } - } - -static char* lexGetWord() { - int c; - lexSkipWhite(); - lexClearToken(); - c = lexLookahead(); - /* some "words" have a space in them, like "NEEDS ACTION". - this may be an oversight of the spec, but it is true nevertheless. - while (c != EOF && !strchr("\t\n ;:=",c)) { */ - while (c != EOF && !strchr("\n;:=",c)) { - lexAppendc(c); - lexSkipLookahead(); - c = lexLookahead(); - } - lexAppendc(0); - return lexStr(); - } - -void lexPushLookahead(char *s, int len) { - int putptr; - if (len == 0) len = strlen(s); - putptr = (int)lexBuf.getPtr - len; - /* this function assumes that length of word to push back - / is not greater than MAX_LEX_LOOKAHEAD. - */ - if (putptr < 0) putptr += MAX_LEX_LOOKAHEAD; - lexBuf.getPtr = putptr; - while (*s) { - lexBuf.buf[putptr] = *s++; - putptr = (putptr + 1) % MAX_LEX_LOOKAHEAD; - } - lexBuf.len += len; - } - -static void lexPushLookaheadc(int c) { - int putptr; - /* can't putback EOF, because it never leaves lookahead buffer */ - if (c == EOF) return; - putptr = (int)lexBuf.getPtr - 1; - if (putptr < 0) putptr += MAX_LEX_LOOKAHEAD; - lexBuf.getPtr = putptr; - lexBuf.buf[putptr] = c; - lexBuf.len += 1; - } - -static char* lexLookaheadWord() { - /* this function can lookahead word with max size of MAX_LEX_LOOKAHEAD_0 - / and thing bigger than that will stop the lookahead and return 0; - / leading white spaces are not recoverable. - */ - int c; - int len = 0; - int curgetptr = 0; - lexSkipWhite(); - lexClearToken(); - curgetptr = (int)lexBuf.getPtr; /* remember! */ - while (len < (MAX_LEX_LOOKAHEAD_0)) { - c = lexGetc(); - len++; - if (c == EOF || strchr("\t\n ;:=", c)) { - lexAppendc(0); - /* restore lookahead buf. */ - lexBuf.len += len; - lexBuf.getPtr = curgetptr; - return lexStr(); - } - else - lexAppendc(c); - } - lexBuf.len += len; /* char that has been moved to lookahead buffer */ - lexBuf.getPtr = curgetptr; - return 0; - } - -#ifdef _SUPPORT_LINE_FOLDING -static void handleMoreRFC822LineBreak(int c) { - /* support RFC 822 line break in cases like - * ADR: foo; - * morefoo; - * more foo; - */ - if (c == ';') { - int a; - lexSkipLookahead(); - /* skip white spaces */ - a = lexLookahead(); - while (a == ' ' || a == '\t') { - lexSkipLookahead(); - a = lexLookahead(); - } - if (a == '\n') { - lexSkipLookahead(); - a = lexLookahead(); - if (a == ' ' || a == '\t') { - /* continuation, throw away all the \n and spaces read so - * far - */ - lexSkipWhite(); - lexPushLookaheadc(';'); - } - else { - lexPushLookaheadc('\n'); - lexPushLookaheadc(';'); - } - } - else { - lexPushLookaheadc(';'); - } - } - } - -static char* lexGet1Value() { - int c; - lexSkipWhite(); - c = lexLookahead(); - lexClearToken(); - while (c != EOF && c != ';') { - if (c == '\n') { - int a; - lexSkipLookahead(); - a = lexLookahead(); - if (a == ' ' || a == '\t') { - lexAppendc(' '); - lexSkipLookahead(); - } - else { - lexPushLookaheadc('\n'); - break; - } - } - else { - lexAppendc(c); - lexSkipLookahead(); - } - c = lexLookahead(); - } - lexAppendc(0); - handleMoreRFC822LineBreak(c); - return c==EOF?0:lexStr(); - } -#endif - -char* lexGetStrUntil(char *termset) { - int c = lexLookahead(); - lexClearToken(); - while (c != EOF && !strchr(termset,c)) { - lexAppendc(c); - lexSkipLookahead(); - c = lexLookahead(); - } - lexAppendc(0); - return c==EOF?0:lexStr(); - } - -static int match_begin_name(int end) { - char *n = lexLookaheadWord(); - int token = ID; - if (n) { - if (!strcasecmp(n,"vcard")) token = end?END_VCARD:BEGIN_VCARD; - else if (!strcasecmp(n,"vcalendar")) token = end?END_VCAL:BEGIN_VCAL; - else if (!strcasecmp(n,"vevent")) token = end?END_VEVENT:BEGIN_VEVENT; - else if (!strcasecmp(n,"vtodo")) token = end?END_VTODO:BEGIN_VTODO; - deleteStr(n); - return token; - } - return 0; - } - - -void initLex(const char *inputstring, unsigned long inputlen, FILE *inputfile) - { - /* initialize lex mode stack */ - lexBuf.lexModeStack[lexBuf.lexModeStackTop=0] = L_NORMAL; - - /* iniatialize lex buffer. */ - lexBuf.inputString = (char*) inputstring; - lexBuf.inputLen = inputlen; - lexBuf.curPos = 0; - lexBuf.inputFile = inputfile; - - lexBuf.len = 0; - lexBuf.getPtr = 0; - - lexBuf.maxToken = MAXTOKEN; - lexBuf.strs = (char*)malloc(MAXTOKEN); - lexBuf.strsLen = 0; - - } - -static void finiLex() { - free(lexBuf.strs); - } - - -/****************************************************************************/ -/* This parses and converts the base64 format for binary encoding into - * a decoded buffer (allocated with new). See RFC 1521. - */ -static char * lexGetDataFromBase64() - { - unsigned long bytesLen = 0, bytesMax = 0; - int quadIx = 0, pad = 0; - unsigned long trip = 0; - unsigned char b; - int c; - unsigned char *bytes = NULL; - unsigned char *oldBytes = NULL; - - DBG_(("db: lexGetDataFromBase64\n")); - while (1) { - c = lexGetc(); - if (c == '\n') { - ++mime_lineNum; - if (lexLookahead() == '\n') { - /* a '\n' character by itself means end of data */ - break; - } - else continue; /* ignore '\n' */ - } - else { - if ((c >= 'A') && (c <= 'Z')) - b = (unsigned char)(c - 'A'); - else if ((c >= 'a') && (c <= 'z')) - b = (unsigned char)(c - 'a') + 26; - else if ((c >= '0') && (c <= '9')) - b = (unsigned char)(c - '0') + 52; - else if (c == '+') - b = 62; - else if (c == '/') - b = 63; - else if (c == '=') { - b = 0; - pad++; - } else if ((c == ' ') || (c == '\t')) { - continue; - } else { /* error condition */ - if (bytes) free(bytes); - else if (oldBytes) free(oldBytes); - /* error recovery: skip until 2 adjacent newlines. */ - DBG_(("db: invalid character 0x%x '%c'\n", c,c)); - if (c != EOF) { - c = lexGetc(); - while (c != EOF) { - if (c == '\n' && lexLookahead() == '\n') { - ++mime_lineNum; - break; - } - c = lexGetc(); - } - } - return NULL; - } - trip = (trip << 6) | b; - if (++quadIx == 4) { - unsigned char outBytes[3]; - unsigned int numOut; - int i; - for (i = 0; i < 3; i++) { - outBytes[2-i] = (unsigned char)(trip & 0xFF); - trip >>= 8; - } - numOut = 3 - pad; - if (bytesLen + numOut > bytesMax) { - if (!bytes) { - bytesMax = 1024; - bytes = (unsigned char*)malloc((size_t)bytesMax); - } - else { - bytesMax <<= 2; - oldBytes = bytes; - bytes = (unsigned char*)realloc(bytes,(size_t)bytesMax); - } - if (bytes == 0) { - mime_error("out of memory while processing BASE64 data\n"); - } - } - if (bytes) { - memcpy(bytes + bytesLen, outBytes, numOut); - bytesLen += numOut; - } - trip = 0; - quadIx = 0; - } - } - } /* while */ - DBG_(("db: bytesLen = %d\n", bytesLen)); - /* kludge: all this won't be necessary if we have tree form - representation */ - if (bytes) { - setValueWithSize(curProp,bytes,(unsigned int)bytesLen); - free(bytes); - } - else if (oldBytes) { - setValueWithSize(curProp,oldBytes,(unsigned int)bytesLen); - free(oldBytes); - } - return 0; - } - -static int match_begin_end_name(int end) { - int token; - lexSkipWhite(); - if (lexLookahead() != ':') return ID; - lexSkipLookahead(); - lexSkipWhite(); - token = match_begin_name(end); - if (token == ID) { - lexPushLookaheadc(':'); - DBG_(("db: ID '%s'\n", yylval.str)); - return ID; - } - else if (token != 0) { - lexSkipLookaheadWord(); - deleteStr(yylval.str); - DBG_(("db: begin/end %d\n", token)); - return token; - } - return 0; - } - -static char* lexGetQuotedPrintable() - { - char cur; - - lexClearToken(); - do { - cur = lexGetc(); - switch (cur) { - case '=': { - int c = 0; - int next[2]; - int i; - for (i = 0; i < 2; i++) { - next[i] = lexGetc(); - if (next[i] >= '0' && next[i] <= '9') - c = c * 16 + next[i] - '0'; - else if (next[i] >= 'A' && next[i] <= 'F') - c = c * 16 + next[i] - 'A' + 10; - else - break; - } - if (i == 0) { - /* single '=' follow by LINESEP is continuation sign? */ - if (next[0] == '\n') { - ++mime_lineNum; - } - else { - lexPushLookaheadc('='); - goto EndString; - } - } - else if (i == 1) { - lexPushLookaheadc(next[1]); - lexPushLookaheadc(next[0]); - lexAppendc('='); - } else { - lexAppendc(c); - } - break; - } /* '=' */ - case '\n': { - lexPushLookaheadc('\n'); - goto EndString; - } - case (char)EOF: - break; - default: - lexAppendc(cur); - break; - } /* switch */ - } while (cur != (char)EOF); - -EndString: - lexAppendc(0); - return lexStr(); - } /* LexQuotedPrintable */ - -static int yylex() { - - int lexmode = LEXMODE(); - if (lexmode == L_VALUES) { - int c = lexGetc(); - if (c == ';') { - DBG_(("db: SEMICOLON\n")); - lexPushLookaheadc(c); - handleMoreRFC822LineBreak(c); - lexSkipLookahead(); - return SEMICOLON; - } - else if (strchr("\n",c)) { - ++mime_lineNum; - /* consume all line separator(s) adjacent to each other */ - c = lexLookahead(); - while (strchr("\n",c)) { - lexSkipLookahead(); - c = lexLookahead(); - ++mime_lineNum; - } - DBG_(("db: LINESEP\n")); - return LINESEP; - } - else { - char *p = 0; - lexPushLookaheadc(c); - if (lexWithinMode(L_BASE64)) { - /* get each char and convert to bin on the fly... */ - p = lexGetDataFromBase64(); - yylval.str = p; - return STRING; - } - else if (lexWithinMode(L_QUOTED_PRINTABLE)) { - p = lexGetQuotedPrintable(); - } - else { -#ifdef _SUPPORT_LINE_FOLDING - p = lexGet1Value(); -#else - p = lexGetStrUntil(";\n"); -#endif - } - if (p) { - DBG_(("db: STRING: '%s'\n", p)); - yylval.str = p; - return STRING; - } - else return 0; - } - } - else { - /* normal mode */ - while (1) { - int c = lexGetc(); - switch(c) { - case ':': { - DBG_(("db: COLON\n")); - return COLON; - } - case ';': - DBG_(("db: SEMICOLON\n")); - return SEMICOLON; - case '=': - DBG_(("db: EQ\n")); - return EQ; - /* ignore tabs/newlines in this mode. We can't ignore - * spaces, because values like NEEDS ACTION have a space. */ - case '\t': continue; - case '\n': { - ++mime_lineNum; - continue; - } - case EOF: return 0; - break; - default: { - lexPushLookaheadc(c); - if (isalpha(c) || c == ' ') { - char *t = lexGetWord(); - yylval.str = t; - if (!strcasecmp(t, "begin")) { - return match_begin_end_name(0); - } - else if (!strcasecmp(t,"end")) { - return match_begin_end_name(1); - } - else { - DBG_(("db: ID '%s'\n", t)); - return ID; - } - } - else { - /* unknown token */ - return 0; - } - break; - } - } - } - } - return 0; - } - - -/***************************************************************************/ -/*** Public Functions ****/ -/***************************************************************************/ - -static VObject* Parse_MIMEHelper() - { - ObjStackTop = -1; - mime_numErrors = 0; - mime_lineNum = 1; - vObjList = 0; - curObj = 0; - - if (yyparse() != 0) - return 0; - - finiLex(); - return vObjList; - } - -/****************************************************************************/ -VObject* Parse_MIME(const char *input, unsigned long len) - { - initLex(input, len, 0); - return Parse_MIMEHelper(); - } - - -VObject* Parse_MIME_FromFile(FILE *file) - { - VObject *result; - long startPos; - - initLex(0,(unsigned long)-1,file); - startPos = ftell(file); - if (startPos <0) - return NULL; - if (!(result = Parse_MIMEHelper())) { - fseek(file,startPos,SEEK_SET); - } - return result; - } - -VObject* Parse_MIME_FromFileName(const char *fname) - { - FILE *fp = fopen(fname,"r"); - if (fp) { - VObject* o = Parse_MIME_FromFile(fp); - fclose(fp); - return o; - } - else { - char msg[255]; - sprintf(msg, "can't open file '%s' for reading\n", fname); - mime_error_(msg); - return 0; - } - } - -/****************************************************************************/ - -static MimeErrorHandler mimeErrorHandler; - -void registerMimeErrorHandler(MimeErrorHandler me) - { - mimeErrorHandler = me; - } - -static void mime_error(const char *s) - { - char msg[256]; - if (mimeErrorHandler) { - sprintf(msg,"%s at line %d", s, mime_lineNum); - mimeErrorHandler(msg); - } - } - -static void mime_error_(const char *s) - { - if (mimeErrorHandler) { - mimeErrorHandler(s); - } - } diff --git a/src/versit/vobject.c b/src/versit/vobject.c deleted file mode 100644 index f95f49a25..000000000 --- a/src/versit/vobject.c +++ /dev/null @@ -1,1496 +0,0 @@ -/*************************************************************************** -(C) Copyright 1996 Apple Computer, Inc., AT&T Corp., International -Business Machines Corporation and Siemens Rolm Communications Inc. - -For purposes of this license notice, the term Licensors shall mean, -collectively, Apple Computer, Inc., AT&T Corp., International -Business Machines Corporation and Siemens Rolm Communications Inc. -The term Licensor shall mean any of the Licensors. - -Subject to acceptance of the following conditions, permission is hereby -granted by Licensors without the need for written agreement and without -license or royalty fees, to use, copy, modify and distribute this -software for any purpose. - -The above copyright notice and the following four paragraphs must be -reproduced in all copies of this software and any software including -this software. - -THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS AND NO LICENSOR SHALL HAVE -ANY OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS OR -MODIFICATIONS. - -IN NO EVENT SHALL ANY LICENSOR BE LIABLE TO ANY PARTY FOR DIRECT, -INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOST PROFITS ARISING OUT -OF THE USE OF THIS SOFTWARE EVEN IF ADVISED OF THE POSSIBILITY OF SUCH -DAMAGE. - -EACH LICENSOR SPECIFICALLY DISCLAIMS ANY WARRANTIES, EXPRESS OR IMPLIED, -INCLUDING BUT NOT LIMITED TO ANY WARRANTY OF NONINFRINGEMENT OR THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE. - -The software is provided with RESTRICTED RIGHTS. Use, duplication, or -disclosure by the government are subject to restrictions set forth in -DFARS 252.227-7013 or 48 CFR 52.227-19, as applicable. - -***************************************************************************/ - -/* - * src: vobject.c - * doc: vobject and APIs to construct vobject, APIs pretty print - * vobject, and convert a vobject into its textual representation. - */ - -#include - -#include "vobject.h" -#include -#include - -#ifdef _WIN32 -#define strncasecmp _strnicmp -#define strcasecmp _stricmp -#endif - -#define NAME_OF(o) o->id -#define VALUE_TYPE(o) o->valType -#define STRINGZ_VALUE_OF(o) o->val.strs -#define USTRINGZ_VALUE_OF(o) o->val.ustrs -#define INTEGER_VALUE_OF(o) o->val.i -#define LONG_VALUE_OF(o) o->val.l -#define ANY_VALUE_OF(o) o->val.any -#define VOBJECT_VALUE_OF(o) o->val.vobj - -const char **fieldedProp; - -/*---------------------------------------------------------------------- - The following functions involve with memory allocation: - newVObject - deleteVObject - dupStr - deleteStr - newStrItem - deleteStrItem - ----------------------------------------------------------------------*/ - -VObject *newVObject_(const char *id) -{ - VObject *p = (VObject *)malloc(sizeof(VObject)); - p->next = 0; - p->id = id; - p->prop = 0; - VALUE_TYPE(p) = 0; - ANY_VALUE_OF(p) = 0; - return p; -} - -VObject *newVObject(const char *id) -{ - return newVObject_(lookupStr(id)); -} - -void deleteVObject(VObject *p) -{ - if (!p) { - return; - } - if (p->id) { - unUseStr(p->id); - } - free(p); - p = NULL; -} - -char *dupStr(const char *s, unsigned int size) -{ - char *t; - if (size == 0) { - size = strlen(s); - } - t = (char *)malloc(size + 1); - if (t) { - memcpy(t, s, size); - t[size] = 0; - return t; - } else { - return (char *)0; - } -} - -void deleteStr(const char *p) -{ - if (p) { - free((void *)p); - } - p = NULL; -} - -static StrItem *newStrItem(const char *s, StrItem *next) -{ - StrItem *p = (StrItem *)malloc(sizeof(StrItem)); - p->next = next; - p->s = s; - p->refCnt = 1; - return p; -} - -static void deleteStrItem(StrItem *p) -{ - if (p) { - free((void *)p); - } - p = NULL; -} - -/*---------------------------------------------------------------------- - The following function provide accesses to VObject's value. - ----------------------------------------------------------------------*/ - -const char *vObjectName(VObject *o) -{ - return NAME_OF(o); -} - -void setVObjectName(VObject *o, const char *id) -{ - NAME_OF(o) = id; -} - -const char *vObjectStringZValue(VObject *o) -{ - return STRINGZ_VALUE_OF(o); -} - -void setVObjectStringZValue(VObject *o, const char *s) -{ - STRINGZ_VALUE_OF(o) = dupStr(s, 0); - VALUE_TYPE(o) = VCVT_STRINGZ; -} - -void setVObjectStringZValue_(VObject *o, const char *s) -{ - STRINGZ_VALUE_OF(o) = s; - VALUE_TYPE(o) = VCVT_STRINGZ; -} - -const wchar_t *vObjectUStringZValue(VObject *o) -{ - return USTRINGZ_VALUE_OF(o); -} - -void setVObjectUStringZValue(VObject *o, const wchar_t *s) -{ - USTRINGZ_VALUE_OF(o) = (wchar_t *) dupStr((char *)s, (unsigned)(uStrLen(s) + 1) * 2); - VALUE_TYPE(o) = VCVT_USTRINGZ; -} - -void setVObjectUStringZValue_(VObject *o, const wchar_t *s) -{ - USTRINGZ_VALUE_OF(o) = s; - VALUE_TYPE(o) = VCVT_USTRINGZ; -} - -unsigned int vObjectIntegerValue(VObject *o) -{ - return INTEGER_VALUE_OF(o); -} - -void setVObjectIntegerValue(VObject *o, unsigned int i) -{ - INTEGER_VALUE_OF(o) = i; - VALUE_TYPE(o) = VCVT_UINT; -} - -unsigned long vObjectLongValue(VObject *o) -{ - return LONG_VALUE_OF(o); -} - -void setVObjectLongValue(VObject *o, unsigned long l) -{ - LONG_VALUE_OF(o) = l; - VALUE_TYPE(o) = VCVT_ULONG; -} - -void *vObjectAnyValue(VObject *o) -{ - return ANY_VALUE_OF(o); -} - -void setVObjectAnyValue(VObject *o, void *t) -{ - ANY_VALUE_OF(o) = t; - VALUE_TYPE(o) = VCVT_RAW; -} - -VObject *vObjectVObjectValue(VObject *o) -{ - return VOBJECT_VALUE_OF(o); -} - -void setVObjectVObjectValue(VObject *o, VObject *p) -{ - VOBJECT_VALUE_OF(o) = p; - VALUE_TYPE(o) = VCVT_VOBJECT; -} - -int vObjectValueType(VObject *o) -{ - return VALUE_TYPE(o); -} - -/*---------------------------------------------------------------------- - The following functions can be used to build VObject. - ----------------------------------------------------------------------*/ - -VObject *addVObjectProp(VObject *o, VObject *p) -{ - /* circular link list pointed to tail */ - /* - o {next,id,prop,val} - V - pn {next,id,prop,val} - V - ... - p1 {next,id,prop,val} - V - pn - --> - o {next,id,prop,val} - V - pn {next,id,prop,val} - V - p {next,id,prop,val} - ... - p1 {next,id,prop,val} - V - pn - */ - - VObject *tail = o->prop; - if (tail) { - p->next = tail->next; - o->prop = tail->next = p; - } else { - o->prop = p->next = p; - } - return p; -} - -VObject *addProp(VObject *o, const char *id) -{ - return addVObjectProp(o, newVObject(id)); -} - -VObject *addProp_(VObject *o, const char *id) -{ - return addVObjectProp(o, newVObject_(id)); -} - -void addList(VObject **o, VObject *p) -{ - p->next = 0; - if (*o == 0) { - *o = p; - } else { - VObject *t = *o; - while (t->next) { - t = t->next; - } - t->next = p; - } -} - -VObject *nextVObjectInList(VObject *o) -{ - return o->next; -} - -VObject *setValueWithSize_(VObject *prop, void *val, unsigned int size) -{ - VObject *sizeProp; - setVObjectAnyValue(prop, val); - sizeProp = addProp(prop, VCDataSizeProp); - setVObjectLongValue(sizeProp, size); - return prop; -} - -VObject *setValueWithSize(VObject *prop, void *val, unsigned int size) -{ - void *p = dupStr(val, size); - return setValueWithSize_(prop, p, p ? size : 0); -} - -void initPropIterator(VObjectIterator *i, VObject *o) -{ - i->start = o->prop; - i->next = 0; -} - -void initVObjectIterator(VObjectIterator *i, VObject *o) -{ - i->start = o->next; - i->next = 0; -} - -int moreIteration(VObjectIterator *i) -{ - return (i->start && (i->next == 0 || i->next != i->start)); -} - -VObject *nextVObject(VObjectIterator *i) -{ - if (i->start && i->next != i->start) { - if (i->next == 0) { - i->next = i->start->next; - return i->next; - } else { - i->next = i->next->next; - return i->next; - } - } else { - return (VObject *)0; - } -} - -VObject *isAPropertyOf(VObject *o, const char *id) -{ - VObjectIterator i; - initPropIterator(&i, o); - while (moreIteration(&i)) { - VObject *each = nextVObject(&i); - if (!strcasecmp(id, each->id)) { - return each; - } - } - return (VObject *)0; -} - -VObject *addGroup(VObject *o, const char *g) -{ - /* - a.b.c - --> - prop(c) - prop(VCGrouping=b) - prop(VCGrouping=a) - */ - char *dot = strrchr(g, '.'); - if (dot) { - VObject *p, *t; - char *gs, *n = dot + 1; - gs = dupStr(g, 0); /* so we can write to it. */ - /* used to be - * t = p = addProp_(o,lookupProp_(n)); - */ - t = p = addProp_(o, lookupProp(n)); - dot = strrchr(gs, '.'); - if (dot) { - *dot = 0; - do { - dot = strrchr(gs, '.'); - if (dot) { - n = dot + 1; - *dot = 0; - } else { - n = gs; - } - /* property(VCGroupingProp=n); - * and the value may have VCGrouping property - */ - t = addProp(t, VCGroupingProp); - setVObjectStringZValue(t, lookupProp_(n)); - } while (n != gs); - } else { - t = addProp(t, VCGroupingProp); - setVObjectStringZValue(t, lookupProp_(n)); - } - deleteStr(gs); - return p; - } else { - return addProp_(o, lookupProp(g)); - } -} - -VObject *addPropValue(VObject *o, const char *p, const char *v) -{ - VObject *prop; - prop = addProp(o, p); - setVObjectUStringZValue_(prop, fakeUnicode(v, 0)); - return prop; -} - -VObject *addPropSizedValue_(VObject *o, const char *p, const char *v, - unsigned int size) -{ - VObject *prop; - prop = addProp(o, p); - setValueWithSize_(prop, (void *)v, size); - return prop; -} - -VObject *addPropSizedValue(VObject *o, const char *p, const char *v, - unsigned int size) -{ - return addPropSizedValue_(o, p, dupStr(v, size), size); -} - -/*---------------------------------------------------------------------- - The following pretty print a VObject - ----------------------------------------------------------------------*/ - -static void printVObject_(FILE *fp, VObject *o, int level); - -static void indent(FILE *fp, int level) -{ - int i; - for (i = 0; i < level * 4; i++) { - fputc(' ', fp); - } -} - -static void printValue(FILE *fp, VObject *o, int level) -{ - switch (VALUE_TYPE(o)) { - case VCVT_USTRINGZ: { - char c; - char *t, *s; - s = t = fakeCString(USTRINGZ_VALUE_OF(o)); - fputc('"', fp); - while (c = *t, c) { - fputc(c, fp); - if (c == '\n') { - indent(fp, level + 2); - } - t++; - } - fputc('"', fp); - deleteStr(s); - break; - } - case VCVT_STRINGZ: { - char c; - const char *s = STRINGZ_VALUE_OF(o); - fputc('"', fp); - while (c = *s, c) { - fputc(c, fp); - if (c == '\n') { - indent(fp, level + 2); - } - s++; - } - fputc('"', fp); - break; - } - case VCVT_UINT: - fprintf(fp, "%d", INTEGER_VALUE_OF(o)); break; - case VCVT_ULONG: - fprintf(fp, "%ld", LONG_VALUE_OF(o)); break; - case VCVT_RAW: - fprintf(fp, "[raw data]"); break; - case VCVT_VOBJECT: - fprintf(fp, "[vobject]\n"); - printVObject_(fp, VOBJECT_VALUE_OF(o), level + 1); - break; - case 0: - fprintf(fp, "[none]"); break; - default: - fprintf(fp, "[unknown]"); break; - } -} - -static void printNameValue(FILE *fp, VObject *o, int level) -{ - indent(fp, level); - if (NAME_OF(o)) { - fprintf(fp, "%s", NAME_OF(o)); - } - if (VALUE_TYPE(o)) { - fputc('=', fp); - printValue(fp, o, level); - } - fprintf(fp, "\n"); -} - -static void printVObject_(FILE *fp, VObject *o, int level) -{ - VObjectIterator t; - if (o == 0) { - fprintf(fp, "[NULL]\n"); - return; - } - printNameValue(fp, o, level); - initPropIterator(&t, o); - while (moreIteration(&t)) { - VObject *eachProp = nextVObject(&t); - printVObject_(fp, eachProp, level + 1); - } -} - -void printVObject(FILE *fp, VObject *o) -{ - printVObject_(fp, o, 0); -} - -void printVObjectToFile(char *fname, VObject *o) -{ - FILE *fp = fopen(fname, "w"); - if (fp) { - printVObject(fp, o); - fclose(fp); - } -} - -void printVObjectsToFile(char *fname, VObject *list) -{ - FILE *fp = fopen(fname, "w"); - if (fp) { - while (list) { - printVObject(fp, list); - list = nextVObjectInList(list); - } - fclose(fp); - } -} - -void cleanVObject(VObject *o) -{ - if (o == 0) { - return; - } - if (o->prop) { - /* destroy time: cannot use the iterator here. - Have to break the cycle in the circular link - list and turns it into regular NULL-terminated - list -- since at some point of destruction, - the reference entry for the iterator to work - will not longer be valid. - */ - VObject *p; - p = o->prop->next; - o->prop->next = 0; - do { - VObject *t = p->next; - cleanVObject(p); - p = t; - } while (p); - } - switch (VALUE_TYPE(o)) { - case VCVT_USTRINGZ: - case VCVT_STRINGZ: - case VCVT_RAW: - /* assume they are all allocated by malloc. */ - free((char *)STRINGZ_VALUE_OF(o)); - break; - case VCVT_VOBJECT: - cleanVObject(VOBJECT_VALUE_OF(o)); - break; - } - deleteVObject(o); -} - -void cleanVObjects(VObject *list) -{ - while (list) { - VObject *t = list; - list = nextVObjectInList(list); - cleanVObject(t); - } -} - -/*---------------------------------------------------------------------- - The following is a String Table Facilities. - ----------------------------------------------------------------------*/ - -#define STRTBLSIZE 255 - -static StrItem *strTbl[STRTBLSIZE]; - -static unsigned int hashStr(const char *s) -{ - unsigned int h = 0; - int i; - for (i = 0; s[i]; i++) { - h += s[i] * i; - } - return h % STRTBLSIZE; -} - -const char *lookupStr(const char *s) -{ - char *newS; - - StrItem *t; - unsigned int h = hashStr(s); - if ((t = strTbl[h]) != 0) { - do { - if (strcasecmp(t->s, s) == 0) { - t->refCnt++; - return t->s; - } - t = t->next; - } while (t); - } - newS = dupStr(s, 0); - strTbl[h] = newStrItem(newS, strTbl[h]); - return newS; -} - -void unUseStr(const char *s) -{ - StrItem *cur, *prev; - - unsigned int h = hashStr(s); - cur = strTbl[h]; - prev = cur; - while (cur != 0) { - if (strcasecmp(cur->s, s) == 0) { - cur->refCnt--; - /* if that was the last reference to this string, kill it. */ - if (cur->refCnt == 0) { - if (cur == strTbl[h]) { - strTbl[h] = cur->next; - deleteStr(prev->s); - deleteStrItem(prev); - } else { - prev->next = cur->next; - deleteStr(cur->s); - deleteStrItem(cur); - } - return; - } - } - prev = cur; - cur = cur->next; - } -} - -void cleanStrTbl() -{ - int i; - for (i = 0; i < STRTBLSIZE; i++) { - StrItem *t = strTbl[i]; - while (t) { - StrItem *p; - deleteStr(t->s); - p = t; - t = t->next; - deleteStrItem(p); - } - strTbl[i] = 0; - } -} - -struct PreDefProp { - const char *name; - const char *alias; - const char **fields; - unsigned int flags; -}; - -/* flags in PreDefProp */ -#define PD_BEGIN 0x1 -#define PD_INTERNAL 0x2 - -static const char *const adrFields[] = { - VCPostalBoxProp, - VCExtAddressProp, - VCStreetAddressProp, - VCCityProp, - VCRegionProp, - VCPostalCodeProp, - VCCountryNameProp, - 0 -}; - -static const char *const nameFields[] = { - VCFamilyNameProp, - VCGivenNameProp, - VCAdditionalNamesProp, - VCNamePrefixesProp, - VCNameSuffixesProp, - NULL -}; - -static const char *const orgFields[] = { - VCOrgNameProp, - VCOrgUnitProp, - VCOrgUnit2Prop, - VCOrgUnit3Prop, - VCOrgUnit4Prop, - NULL -}; - -static const char *const AAlarmFields[] = { - VCRunTimeProp, - VCSnoozeTimeProp, - VCRepeatCountProp, - VCAudioContentProp, - 0 -}; - -/* ExDate -- has unnamed fields */ -/* RDate -- has unnamed fields */ - -static const char *const DAlarmFields[] = { - VCRunTimeProp, - VCSnoozeTimeProp, - VCRepeatCountProp, - VCDisplayStringProp, - 0 -}; - -static const char *const MAlarmFields[] = { - VCRunTimeProp, - VCSnoozeTimeProp, - VCRepeatCountProp, - VCEmailAddressProp, - VCNoteProp, - 0 -}; - -static const char *const PAlarmFields[] = { - VCRunTimeProp, - VCSnoozeTimeProp, - VCRepeatCountProp, - VCProcedureNameProp, - 0 -}; - -static const struct PreDefProp propNames[] = { - { VC7bitProp, 0, 0, 0 }, - { VC8bitProp, 0, 0, 0 }, - { VCAAlarmProp, 0, (const char **)AAlarmFields, 0 }, - { VCAdditionalNamesProp, 0, 0, 0 }, - { VCAdrProp, 0, (const char **)adrFields, 0 }, - { VCAgentProp, 0, 0, 0 }, - { VCAIFFProp, 0, 0, 0 }, - { VCAOLProp, 0, 0, 0 }, - { VCAppleLinkProp, 0, 0, 0 }, - { VCAttachProp, 0, 0, 0 }, - { VCAttendeeProp, 0, 0, 0 }, - { VCATTMailProp, 0, 0, 0 }, - { VCAudioContentProp, 0, 0, 0 }, - { VCAVIProp, 0, 0, 0 }, - { VCBase64Prop, 0, 0, 0 }, - { VCBBSProp, 0, 0, 0 }, - { VCBirthDateProp, 0, 0, 0 }, - { VCBMPProp, 0, 0, 0 }, - { VCBodyProp, 0, 0, 0 }, - { VCBusinessRoleProp, 0, 0, 0 }, - { VCCalProp, 0, 0, PD_BEGIN }, - { VCCaptionProp, 0, 0, 0 }, - { VCCardProp, 0, 0, PD_BEGIN }, - { VCCarProp, 0, 0, 0 }, - { VCCategoriesProp, 0, 0, 0 }, - { VCCellularProp, 0, 0, 0 }, - { VCCGMProp, 0, 0, 0 }, - { VCCharSetProp, 0, 0, 0 }, - { VCCIDProp, VCContentIDProp, 0, 0 }, - { VCCISProp, 0, 0, 0 }, - { VCCityProp, 0, 0, 0 }, - { VCClassProp, 0, 0, 0 }, - { VCCommentProp, 0, 0, 0 }, - { VCCompletedProp, 0, 0, 0 }, - { VCContentIDProp, 0, 0, 0 }, - { VCCountryNameProp, 0, 0, 0 }, - { VCDAlarmProp, 0, (const char **)DAlarmFields, 0 }, - { VCDataSizeProp, 0, 0, PD_INTERNAL }, - { VCDayLightProp, 0, 0, 0 }, - { VCDCreatedProp, 0, 0, 0 }, - { VCDeliveryLabelProp, 0, 0, 0 }, - { VCDescriptionProp, 0, 0, 0 }, - { VCDIBProp, 0, 0, 0 }, - { VCDisplayStringProp, 0, 0, 0 }, - { VCDomesticProp, 0, 0, 0 }, - { VCDTendProp, 0, 0, 0 }, - { VCDTstartProp, 0, 0, 0 }, - { VCDueProp, 0, 0, 0 }, - { VCEmailAddressProp, 0, 0, 0 }, - { VCEncodingProp, 0, 0, 0 }, - { VCEndProp, 0, 0, 0 }, - { VCEventProp, 0, 0, PD_BEGIN }, - { VCEWorldProp, 0, 0, 0 }, - { VCExNumProp, 0, 0, 0 }, - { VCExpDateProp, 0, 0, 0 }, - { VCExpectProp, 0, 0, 0 }, - { VCExtAddressProp, 0, 0, 0 }, - { VCFamilyNameProp, 0, 0, 0 }, - { VCFaxProp, 0, 0, 0 }, - { VCFullNameProp, 0, 0, 0 }, - { VCGeoLocationProp, 0, 0, 0 }, - { VCGeoProp, 0, 0, 0 }, - { VCGIFProp, 0, 0, 0 }, - { VCGivenNameProp, 0, 0, 0 }, - { VCGroupingProp, 0, 0, 0 }, - { VCHomeProp, 0, 0, 0 }, - { VCIBMMailProp, 0, 0, 0 }, - { VCInlineProp, 0, 0, 0 }, - { VCInternationalProp, 0, 0, 0 }, - { VCInternetProp, 0, 0, 0 }, - { VCISDNProp, 0, 0, 0 }, - { VCJPEGProp, 0, 0, 0 }, - { VCLanguageProp, 0, 0, 0 }, - { VCLastModifiedProp, 0, 0, 0 }, - { VCLastRevisedProp, 0, 0, 0 }, - { VCLocationProp, 0, 0, 0 }, - { VCLogoProp, 0, 0, 0 }, - { VCMailerProp, 0, 0, 0 }, - { VCMAlarmProp, 0, (const char **)MAlarmFields, 0 }, - { VCMCIMailProp, 0, 0, 0 }, - { VCMessageProp, 0, 0, 0 }, - { VCMETProp, 0, 0, 0 }, - { VCModemProp, 0, 0, 0 }, - { VCMPEG2Prop, 0, 0, 0 }, - { VCMPEGProp, 0, 0, 0 }, - { VCMSNProp, 0, 0, 0 }, - { VCNamePrefixesProp, 0, 0, 0 }, - { VCNameProp, 0, (const char **)nameFields, 0 }, - { VCNameSuffixesProp, 0, 0, 0 }, - { VCNoteProp, 0, 0, 0 }, - { VCOrgNameProp, 0, 0, 0 }, - { VCOrgProp, 0, (const char **)orgFields, 0 }, - { VCOrgUnit2Prop, 0, 0, 0 }, - { VCOrgUnit3Prop, 0, 0, 0 }, - { VCOrgUnit4Prop, 0, 0, 0 }, - { VCOrgUnitProp, 0, 0, 0 }, - { VCPagerProp, 0, 0, 0 }, - { VCPAlarmProp, 0, (const char **)PAlarmFields, 0 }, - { VCParcelProp, 0, 0, 0 }, - { VCPartProp, 0, 0, 0 }, - { VCPCMProp, 0, 0, 0 }, - { VCPDFProp, 0, 0, 0 }, - { VCPGPProp, 0, 0, 0 }, - { VCPhotoProp, 0, 0, 0 }, - { VCPICTProp, 0, 0, 0 }, - { VCPMBProp, 0, 0, 0 }, - { VCPostalBoxProp, 0, 0, 0 }, - { VCPostalCodeProp, 0, 0, 0 }, - { VCPostalProp, 0, 0, 0 }, - { VCPowerShareProp, 0, 0, 0 }, - { VCPreferredProp, 0, 0, 0 }, - { VCPriorityProp, 0, 0, 0 }, - { VCProcedureNameProp, 0, 0, 0 }, - { VCProdIdProp, 0, 0, 0 }, - { VCProdigyProp, 0, 0, 0 }, - { VCPronunciationProp, 0, 0, 0 }, - { VCPSProp, 0, 0, 0 }, - { VCPublicKeyProp, 0, 0, 0 }, - { VCQPProp, VCQuotedPrintableProp, 0, 0 }, - { VCQuickTimeProp, 0, 0, 0 }, - { VCQuotedPrintableProp, 0, 0, 0 }, - { VCRDateProp, 0, 0, 0 }, - { VCRegionProp, 0, 0, 0 }, - { VCRelatedToProp, 0, 0, 0 }, - { VCRepeatCountProp, 0, 0, 0 }, - { VCResourcesProp, 0, 0, 0 }, - { VCRNumProp, 0, 0, 0 }, - { VCRoleProp, 0, 0, 0 }, - { VCRRuleProp, 0, 0, 0 }, - { VCRSVPProp, 0, 0, 0 }, - { VCRunTimeProp, 0, 0, 0 }, - { VCSequenceProp, 0, 0, 0 }, - { VCSnoozeTimeProp, 0, 0, 0 }, - { VCStartProp, 0, 0, 0 }, - { VCStatusProp, 0, 0, 0 }, - { VCStreetAddressProp, 0, 0, 0 }, - { VCSubTypeProp, 0, 0, 0 }, - { VCSummaryProp, 0, 0, 0 }, - { VCTelephoneProp, 0, 0, 0 }, - { VCTIFFProp, 0, 0, 0 }, - { VCTimeZoneProp, 0, 0, 0 }, - { VCTitleProp, 0, 0, 0 }, - { VCTLXProp, 0, 0, 0 }, - { VCTodoProp, 0, 0, PD_BEGIN }, - { VCTranspProp, 0, 0, 0 }, - { VCUniqueStringProp, 0, 0, 0 }, - { VCURLProp, 0, 0, 0 }, - { VCURLValueProp, 0, 0, 0 }, - { VCValueProp, 0, 0, 0 }, - { VCVersionProp, 0, 0, 0 }, - { VCVideoProp, 0, 0, 0 }, - { VCVoiceProp, 0, 0, 0 }, - { VCWAVEProp, 0, 0, 0 }, - { VCWMFProp, 0, 0, 0 }, - { VCWorkProp, 0, 0, 0 }, - { VCX400Prop, 0, 0, 0 }, - { VCX509Prop, 0, 0, 0 }, - { VCXRuleProp, 0, 0, 0 }, - { 0, 0, 0, 0 } -}; - -static struct PreDefProp *lookupPropInfo(const char *str) -{ - /* brute force for now, could use a hash table here. */ - int i; - - for (i = 0; propNames[i].name; i++) - if (strcasecmp(str, propNames[i].name) == 0) { - return (struct PreDefProp *)&propNames[i]; - } - - return 0; -} - -const char *lookupProp_(const char *str) -{ - int i; - - for (i = 0; propNames[i].name; i++) - if (strcasecmp(str, propNames[i].name) == 0) { - const char *s; - s = propNames[i].alias ? propNames[i].alias : propNames[i].name; - return lookupStr(s); - } - return lookupStr(str); -} - -const char *lookupProp(const char *str) -{ - int i; - - for (i = 0; propNames[i].name; i++) - if (strcasecmp(str, propNames[i].name) == 0) { - const char *s; - fieldedProp = propNames[i].fields; - s = propNames[i].alias ? propNames[i].alias : propNames[i].name; - return lookupStr(s); - } - fieldedProp = 0; - return lookupStr(str); -} - -/*---------------------------------------------------------------------- - APIs to Output text form. - ----------------------------------------------------------------------*/ -#define OFILE_REALLOC_SIZE 256 -typedef struct OFile { - FILE *fp; - char *s; - int len; - int limit; - int alloc: 1; - int fail: 1; -} OFile; - -/* vCalendar files need crlf linebreaks. The disabled functions didn't provide - that. */ -#if 0 - -static void appendsOFile(OFile *fp, const char *s) -{ - int slen; - if (fp->fail) { - return; - } - slen = strlen(s); - if (fp->fp) { - fwrite(s, 1, slen, fp->fp); - } else { - stuff: - if (fp->len + slen < fp->limit) { - memcpy(fp->s + fp->len, s, slen); - fp->len += slen; - return; - } else if (fp->alloc) { - fp->limit = fp->limit + OFILE_REALLOC_SIZE; - if (OFILE_REALLOC_SIZE <= slen) { - fp->limit += slen; - } - if (fp->s) { - fp->s = realloc(fp->s, fp->limit); - } else { - fp->s = malloc(fp->limit); - } - if (fp->s) { - goto stuff; - } - } - if (fp->alloc) { - free(fp->s); - } - fp->s = 0; - fp->fail = 1; - } -} - -static void appendcOFile(OFile *fp, char c) -{ - if (fp->fail) { - return; - } - if (fp->fp) { - fputc(c, fp->fp); - } else { - stuff: - if (fp->len + 1 < fp->limit) { - fp->s[fp->len] = c; - fp->len++; - return; - } else if (fp->alloc) { - fp->limit = fp->limit + OFILE_REALLOC_SIZE; - fp->s = realloc(fp->s, fp->limit); - if (fp->s) { - goto stuff; - } - } - if (fp->alloc) { - free(fp->s); - } - fp->s = 0; - fp->fail = 1; - } -} - -#else - -static void appendcOFile_(OFile *fp, char c) -{ - if (fp->fail) { - return; - } - if (fp->fp) { - fputc(c, fp->fp); - } else { - stuff: - if (fp->len + 1 < fp->limit) { - fp->s[fp->len] = c; - fp->len++; - return; - } else if (fp->alloc) { - fp->limit = fp->limit + OFILE_REALLOC_SIZE; - fp->s = realloc(fp->s, (unsigned int)fp->limit); - if (fp->s) { - goto stuff; - } - } - if (fp->alloc) { - free(fp->s); - } - fp->s = 0; - fp->fail = 1; - } -} - -static void appendcOFile(OFile *fp, char c) -{ - if (c == '\n') { - /* write out as */ - appendcOFile_(fp, 0xd); - appendcOFile_(fp, 0xa); - } else { - appendcOFile_(fp, c); - } -} - -static void appendsOFile(OFile *fp, const char *s) -{ - int i, slen; - slen = strlen(s); - for (i = 0; i < slen; i++) { - appendcOFile(fp, s[i]); - } -} - -#endif - -static void initOFile(OFile *fp, FILE *ofp) -{ - fp->fp = ofp; - fp->s = 0; - fp->len = 0; - fp->limit = 0; - fp->alloc = 0; - fp->fail = 0; -} - -static void initMemOFile(OFile *fp, char *s, int len) -{ - fp->fp = 0; - fp->s = s; - fp->len = 0; - fp->limit = s ? len : 0; - fp->alloc = s ? 0 : 1; - fp->fail = 0; -} - -static int writeBase64(OFile *fp, unsigned char *s, unsigned long len) -{ - unsigned long cur = 0; - int i, numQuads = 0; - unsigned long trip; - unsigned char b; - char quad[5]; -#define MAXQUADS 16 - - quad[4] = 0; - - while (cur < len) { - /* collect the triplet of bytes into 'trip' */ - trip = 0; - for (i = 0; i < 3; i++) { - b = (cur < len) ? *(s + cur) : 0; - cur++; - trip = trip << 8 | b; - } - /* fill in 'quad' with the appropriate four characters */ - for (i = 3; i >= 0; i--) { - b = (unsigned char)(trip & 0x3F); - trip = trip >> 6; - if ((unsigned long)(3 - i) < (cur - len)) { - quad[i] = '='; /* pad char */ - } else if (b < 26) { - quad[i] = (char)b + 'A'; - } else if (b < 52) { - quad[i] = (char)(b - 26) + 'a'; - } else if (b < 62) { - quad[i] = (char)(b - 52) + '0'; - } else if (b == 62) { - quad[i] = '+'; - } else { - quad[i] = '/'; - } - } - /* now output 'quad' with appropriate whitespace and line ending */ - appendsOFile(fp, (numQuads == 0 ? " " : "")); - appendsOFile(fp, quad); - appendsOFile(fp, ((cur >= len) ? "\n" : (numQuads == MAXQUADS - 1 ? "\n" : ""))); - numQuads = (numQuads + 1) % MAXQUADS; - } - appendcOFile(fp, '\n'); - - return 1; -} - -/* this function really sucks. Too basic. */ -static void writeQPString(OFile *fp, const char *s, int qp) -{ - const char *p = s; - while (*p) { - if (*p == '\n') { - /* According to VCAL-1.0 doc, CRLF is the correct separator */ - appendsOFile(fp, "=0D=0A="); - /* Continued to also add the \n below */ - } - if (*p == '\r') { - /* NOP, handled above [our own may or may not have \rs] */ - } else if (*p == '=' && qp) { - appendsOFile(fp, "=3D"); - } else { - appendcOFile(fp, *p); - } - p++; - } -} - -static void writeVObject_(OFile *fp, VObject *o); - -static void writeValue(OFile *fp, VObject *o, unsigned long size) -{ - if (o == 0) { - return; - } - switch (VALUE_TYPE(o)) { - case VCVT_USTRINGZ: { - char *s = fakeCString(USTRINGZ_VALUE_OF(o)); - if (isAPropertyOf(o, VCQuotedPrintableProp)) { - writeQPString(fp, s, 1); - } else { - writeQPString(fp, s, 0); - } - deleteStr(s); - break; - } - case VCVT_STRINGZ: { - if (isAPropertyOf(o, VCQuotedPrintableProp)) { - writeQPString(fp, STRINGZ_VALUE_OF(o), 1); - } else { - writeQPString(fp, STRINGZ_VALUE_OF(o), 0); - } - break; - } - case VCVT_UINT: { - char buf[16]; - snprintf(buf, sizeof(buf), "%u", INTEGER_VALUE_OF(o)); - appendsOFile(fp, buf); - break; - } - case VCVT_ULONG: { - char buf[16]; - snprintf(buf, sizeof(buf), "%lu", LONG_VALUE_OF(o)); - appendsOFile(fp, buf); - break; - } - case VCVT_RAW: { - appendcOFile(fp, '\n'); - writeBase64(fp, (unsigned char *)(ANY_VALUE_OF(o)), size); - break; - } - case VCVT_VOBJECT: - appendcOFile(fp, '\n'); - writeVObject_(fp, VOBJECT_VALUE_OF(o)); - break; - } -} - -static void writeAttrValue(OFile *fp, VObject *o) -{ - if (NAME_OF(o)) { - struct PreDefProp *pi; - pi = lookupPropInfo(NAME_OF(o)); - if (pi && ((pi->flags & PD_INTERNAL) != 0)) { - return; - } - appendcOFile(fp, ';'); - appendsOFile(fp, NAME_OF(o)); - } else { - appendcOFile(fp, ';'); - } - if (VALUE_TYPE(o)) { - appendcOFile(fp, '='); - writeValue(fp, o, 0); - } -} - -static void writeGroup(OFile *fp, VObject *o) -{ - char buf1[256]; - char buf2[256]; - strncpy(buf1, NAME_OF(o), 256); - while ((o = isAPropertyOf(o, VCGroupingProp)) != 0) { - strncpy(buf2, STRINGZ_VALUE_OF(o), sizeof(buf2)); - buf2[sizeof(buf2) - 1] = '\0'; - strncat(buf2, ".", sizeof(buf2) - strlen(buf2) - 1); - strncat(buf2, buf1, sizeof(buf2) - strlen(buf2) - 1); - strcpy(buf1, buf2); - } - appendsOFile(fp, buf1); -} - -static int inList(const char **list, const char *s) -{ - if (list == 0) { - return 0; - } - while (*list) { - if (strcasecmp(*list, s) == 0) { - return 1; - } - list++; - } - return 0; -} - -static void writeProp(OFile *fp, VObject *o) -{ - if (NAME_OF(o)) { - struct PreDefProp *pi; - VObjectIterator t; - const char **fields_ = 0; - pi = lookupPropInfo(NAME_OF(o)); - if (pi && ((pi->flags & PD_BEGIN) != 0)) { - writeVObject_(fp, o); - return; - } - if (isAPropertyOf(o, VCGroupingProp)) { - writeGroup(fp, o); - } else { - appendsOFile(fp, NAME_OF(o)); - } - if (pi) { - fields_ = pi->fields; - } - initPropIterator(&t, o); - while (moreIteration(&t)) { - const char *s; - VObject *eachProp = nextVObject(&t); - s = NAME_OF(eachProp); - if (strcasecmp(VCGroupingProp, s) && !inList(fields_, s)) { - writeAttrValue(fp, eachProp); - } - } - if (fields_) { - int i = 0, n = 0; - const char **fields = fields_; - /* output prop as fields */ - appendcOFile(fp, ':'); - while (*fields) { - VObject *tl = isAPropertyOf(o, *fields); - i++; - if (tl) { - n = i; - } - fields++; - } - fields = fields_; - for (i = 0; i < n; i++) { - writeValue(fp, isAPropertyOf(o, *fields), 0); - fields++; - if (i < (n - 1)) { - appendcOFile(fp, ';'); - } - } - } - } - - if (VALUE_TYPE(o)) { - unsigned long size = 0; - VObject *p = isAPropertyOf(o, VCDataSizeProp); - if (p) { - size = LONG_VALUE_OF(p); - } - appendcOFile(fp, ':'); - writeValue(fp, o, size); - } - - appendcOFile(fp, '\n'); -} - -static void writeVObject_(OFile *fp, VObject *o) -{ - if (NAME_OF(o)) { - struct PreDefProp *pi; - pi = lookupPropInfo(NAME_OF(o)); - - if (pi && ((pi->flags & PD_BEGIN) != 0)) { - VObjectIterator t; - const char *begin = NAME_OF(o); - appendsOFile(fp, "BEGIN:"); - appendsOFile(fp, begin); - appendcOFile(fp, '\n'); - initPropIterator(&t, o); - while (moreIteration(&t)) { - VObject *eachProp = nextVObject(&t); - writeProp(fp, eachProp); - } - appendsOFile(fp, "END:"); - appendsOFile(fp, begin); - appendsOFile(fp, "\n\n"); - } - } -} - -void writeVObject(FILE *fp, VObject *o) -{ - OFile ofp; - initOFile(&ofp, fp); - writeVObject_(&ofp, o); -} - -void writeVObjectToFile(char *fname, VObject *o) -{ - FILE *fp = fopen(fname, "w"); - if (fp) { - writeVObject(fp, o); - fclose(fp); - } -} - -void writeVObjectsToFile(char *fname, VObject *list) -{ - FILE *fp = fopen(fname, "w"); - if (fp) { - while (list) { - writeVObject(fp, list); - list = nextVObjectInList(list); - } - fclose(fp); - } -} - -char *writeMemVObject(char *s, int *len, VObject *o) -{ - OFile ofp; - initMemOFile(&ofp, s, len ? *len : 0); - writeVObject_(&ofp, o); - if (len) { - *len = ofp.len; - } - appendcOFile(&ofp, 0); - return ofp.s; -} - -char *writeMemVObjects(char *s, int *len, VObject *list) -{ - OFile ofp; - initMemOFile(&ofp, s, len ? *len : 0); - while (list) { - writeVObject_(&ofp, list); - list = nextVObjectInList(list); - } - if (len) { - *len = ofp.len; - } - appendcOFile(&ofp, 0); - return ofp.s; -} - -/*---------------------------------------------------------------------- - APIs to do fake Unicode stuff. - ----------------------------------------------------------------------*/ -wchar_t *fakeUnicode(const char *ps, int *bytes) -{ - wchar_t *r, *pw; - int len = strlen(ps) + 1; - - pw = r = (wchar_t *)malloc(sizeof(wchar_t) * len); - if (bytes) { - *bytes = len * sizeof(wchar_t); - } - - while (*ps) { - if (*ps == '\n') { - *pw = (wchar_t)0x2028; - } else if (*ps == '\r') { - *pw = (wchar_t)0x2029; - } else { - *pw = (wchar_t)(unsigned char) * ps; - } - ps++; pw++; - } - *pw = (wchar_t)0; - - return r; -} - -unsigned int uStrLen(const wchar_t *u) -{ - int i = 0; - if (u == NULL) { - return 0; - } - - while (*u != (wchar_t)0) { - u++; - i++; - } - return i; -} - -char *fakeCString(const wchar_t *u) -{ - char *s, *t; - unsigned int len; - - if (u == NULL) { - return NULL; - } - - len = uStrLen(u) + 1; - t = s = (char *)malloc(len + 1); - while (*u) { - if (*u == (wchar_t)0x2028) { - *t = '\n'; - } else if (*u == (wchar_t)0x2029) { - *t = '\r'; - } else { - *t = (char) * u; - } - u++; t++; - } - *t = 0; - return s; -} - -/* end of source file vobject.c */ diff --git a/src/versit/vobject.h b/src/versit/vobject.h deleted file mode 100644 index 7166ace47..000000000 --- a/src/versit/vobject.h +++ /dev/null @@ -1,375 +0,0 @@ -/*************************************************************************** -(C) Copyright 1996 Apple Computer, Inc., AT&T Corp., International -Business Machines Corporation and Siemens Rolm Communications Inc. - -For purposes of this license notice, the term Licensors shall mean, -collectively, Apple Computer, Inc., AT&T Corp., International -Business Machines Corporation and Siemens Rolm Communications Inc. -The term Licensor shall mean any of the Licensors. - -Subject to acceptance of the following conditions, permission is hereby -granted by Licensors without the need for written agreement and without -license or royalty fees, to use, copy, modify and distribute this -software for any purpose. - -The above copyright notice and the following four paragraphs must be -reproduced in all copies of this software and any software including -this software. - -THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS AND NO LICENSOR SHALL HAVE -ANY OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS OR -MODIFICATIONS. - -IN NO EVENT SHALL ANY LICENSOR BE LIABLE TO ANY PARTY FOR DIRECT, -INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOST PROFITS ARISING OUT -OF THE USE OF THIS SOFTWARE EVEN IF ADVISED OF THE POSSIBILITY OF SUCH -DAMAGE. - -EACH LICENSOR SPECIFICALLY DISCLAIMS ANY WARRANTIES, EXPRESS OR IMPLIED, -INCLUDING BUT NOT LIMITED TO ANY WARRANTY OF NONINFRINGEMENT OR THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE. - -The software is provided with RESTRICTED RIGHTS. Use, duplication, or -disclosure by the government are subject to restrictions set forth in -DFARS 252.227-7013 or 48 CFR 52.227-19, as applicable. - -***************************************************************************/ - -/* - -The vCard/vCalendar C interface is implemented in the set -of files as follows: - -vcc.y, yacc source, and vcc.c, the yacc output you will use -implements the core parser - -vobject.c implements an API that insulates the caller from -the parser and changes in the vCard/vCalendar BNF - -port.h defines compilation environment dependent stuff - -vcc.h and vobject.h are header files for their .c counterparts - -vcaltmp.h and vcaltmp.c implement vCalendar "macro" functions -which you may find useful. - -test.c is a standalone test driver that exercises some of -the features of the APIs provided. Invoke test.exe on a -VCARD/VCALENDAR input text file and you will see the pretty -print output of the internal representation (this pretty print -output should give you a good idea of how the internal -representation looks like -- there is one such output in the -following too). Also, a file with the .out suffix is generated -to show that the internal representation can be written back -in the original text format. - -For more information on this API see the readme.txt file -which accompanied this distribution. - - Also visit: - - http://www.versit.com - http://www.ralden.com - -*/ - -#ifndef __VOBJECT_H__ -#define __VOBJECT_H__ 1 - -#include "port.h" -#include -#include - -#if defined(__CPLUSPLUS__) || defined(__cplusplus) -extern "C" { -#endif - -#define VC7bitProp "7BIT" -#define VC8bitProp "8BIT" -#define VCAAlarmProp "AALARM" -#define VCAdditionalNamesProp "ADDN" -#define VCAdrProp "ADR" -#define VCAgentProp "AGENT" -#define VCAIFFProp "AIFF" -#define VCAOLProp "AOL" -#define VCAppleLinkProp "APPLELINK" -#define VCAttachProp "ATTACH" -#define VCAttendeeProp "ATTENDEE" -#define VCATTMailProp "ATTMAIL" -#define VCAudioContentProp "AUDIOCONTENT" -#define VCAVIProp "AVI" -#define VCBase64Prop "BASE64" -#define VCBBSProp "BBS" -#define VCBirthDateProp "BDAY" -#define VCBMPProp "BMP" -#define VCBodyProp "BODY" -#define VCBusinessRoleProp "ROLE" -#define VCCalProp "VCALENDAR" -#define VCCaptionProp "CAP" -#define VCCardProp "VCARD" -#define VCCarProp "CAR" -#define VCCategoriesProp "CATEGORIES" -#define VCCellularProp "CELL" -#define VCCGMProp "CGM" -#define VCCharSetProp "CHARSET" -#define VCCIDProp "CID" -#define VCCISProp "CIS" -#define VCCityProp "L" -#define VCClassProp "CLASS" -#define VCCommentProp "NOTE" -#define VCCompletedProp "COMPLETED" -#define VCContentIDProp "CONTENT-ID" -#define VCCountryNameProp "C" -#define VCDAlarmProp "DALARM" -#define VCDataSizeProp "DATASIZE" -#define VCDayLightProp "DAYLIGHT" -#define VCDCreatedProp "DCREATED" -#define VCDeliveryLabelProp "LABEL" -#define VCDescriptionProp "DESCRIPTION" -#define VCDIBProp "DIB" -#define VCDisplayStringProp "DISPLAYSTRING" -#define VCDomesticProp "DOM" -#define VCDTendProp "DTEND" -#define VCDTstartProp "DTSTART" -#define VCDueProp "DUE" -#define VCEmailAddressProp "EMAIL" -#define VCEncodingProp "ENCODING" -#define VCEndProp "END" -#define VCEventProp "VEVENT" -#define VCEWorldProp "EWORLD" -#define VCExNumProp "EXNUM" -#define VCExpDateProp "EXDATE" -#define VCExpectProp "EXPECT" -#define VCExtAddressProp "EXT ADD" -#define VCFamilyNameProp "F" -#define VCFaxProp "FAX" -#define VCFullNameProp "FN" -#define VCGeoProp "GEO" -#define VCGeoLocationProp "GEO" -#define VCGIFProp "GIF" -#define VCGivenNameProp "G" -#define VCGroupingProp "Grouping" -#define VCHomeProp "HOME" -#define VCIBMMailProp "IBMMail" -#define VCInlineProp "INLINE" -#define VCInternationalProp "INTL" -#define VCInternetProp "INTERNET" -#define VCISDNProp "ISDN" -#define VCJPEGProp "JPEG" -#define VCLanguageProp "LANG" -#define VCLastModifiedProp "LAST-MODIFIED" -#define VCLastRevisedProp "REV" -#define VCLocationProp "LOCATION" -#define VCLogoProp "LOGO" -#define VCMailerProp "MAILER" -#define VCMAlarmProp "MALARM" -#define VCMCIMailProp "MCIMAIL" -#define VCMessageProp "MSG" -#define VCMETProp "MET" -#define VCModemProp "MODEM" -#define VCMPEG2Prop "MPEG2" -#define VCMPEGProp "MPEG" -#define VCMSNProp "MSN" -#define VCNamePrefixesProp "NPRE" -#define VCNameProp "N" -#define VCNameSuffixesProp "NSUF" -#define VCNoteProp "NOTE" -#define VCOrgNameProp "ORGNAME" -#define VCOrgProp "ORG" -#define VCOrgUnit2Prop "OUN2" -#define VCOrgUnit3Prop "OUN3" -#define VCOrgUnit4Prop "OUN4" -#define VCOrgUnitProp "OUN" -#define VCPagerProp "PAGER" -#define VCPAlarmProp "PALARM" -#define VCParcelProp "PARCEL" -#define VCPartProp "PART" -#define VCPCMProp "PCM" -#define VCPDFProp "PDF" -#define VCPGPProp "PGP" -#define VCPhotoProp "PHOTO" -#define VCPICTProp "PICT" -#define VCPMBProp "PMB" -#define VCPostalBoxProp "BOX" -#define VCPostalCodeProp "PC" -#define VCPostalProp "POSTAL" -#define VCPowerShareProp "POWERSHARE" -#define VCPreferredProp "PREF" -#define VCPriorityProp "PRIORITY" -#define VCProcedureNameProp "PROCEDURENAME" -#define VCProdIdProp "PRODID" -#define VCProdigyProp "PRODIGY" -#define VCPronunciationProp "SOUND" -#define VCPSProp "PS" -#define VCPublicKeyProp "KEY" -#define VCQPProp "QP" -#define VCQuickTimeProp "QTIME" -#define VCQuotedPrintableProp "QUOTED-PRINTABLE" -#define VCUtf8Prop "utf-8" -#define VCRDateProp "RDATE" -#define VCRegionProp "R" -#define VCRelatedToProp "RELATED-TO" -#define VCRepeatCountProp "REPEATCOUNT" -#define VCResourcesProp "RESOURCES" -#define VCRNumProp "RNUM" -#define VCRoleProp "ROLE" -#define VCRRuleProp "RRULE" -#define VCRSVPProp "RSVP" -#define VCRunTimeProp "RUNTIME" -#define VCSequenceProp "SEQUENCE" -#define VCSnoozeTimeProp "SNOOZETIME" -#define VCStartProp "START" -#define VCStatusProp "STATUS" -#define VCStreetAddressProp "STREET" -#define VCSubTypeProp "SUBTYPE" -#define VCSummaryProp "SUMMARY" -#define VCTelephoneProp "TEL" -#define VCTIFFProp "TIFF" -#define VCTimeZoneProp "TZ" -#define VCTitleProp "TITLE" -#define VCTLXProp "TLX" -#define VCTodoProp "VTODO" -#define VCTranspProp "TRANSP" -#define VCUniqueStringProp "UID" -#define VCURLProp "URL" -#define VCURLValueProp "URLVAL" -#define VCValueProp "VALUE" -#define VCVersionProp "VERSION" -#define VCVideoProp "VIDEO" -#define VCVoiceProp "VOICE" -#define VCWAVEProp "WAVE" -#define VCWMFProp "WMF" -#define VCWorkProp "WORK" -#define VCX400Prop "X400" -#define VCX509Prop "X509" -#define VCXRuleProp "XRULE" - - /* extensions for iMIP / iTIP */ -#define ICOrganizerProp "X-ORGANIZER" -#define ICMethodProp "X-METHOD" -#define ICRequestStatusProp "X-REQUEST-STATUS" - - typedef struct VObject VObject; - - typedef union ValueItem { - const char *strs; - const wchar_t *ustrs; - unsigned int i; - unsigned long l; - void *any; - VObject *vobj; - } ValueItem; - - struct VObject { - VObject *next; - const char *id; - VObject *prop; - unsigned short valType; - ValueItem val; - }; - - typedef struct StrItem StrItem; - - struct StrItem { - StrItem *next; - const char *s; - unsigned int refCnt; - }; - - typedef struct VObjectIterator { - VObject *start; - VObject *next; - } VObjectIterator; - - extern VObject *newVObject(const char *id); - extern void deleteVObject(VObject *p); - extern char *dupStr(const char *s, unsigned int size); - extern void deleteStr(const char *p); - extern void unUseStr(const char *s); - - extern void setVObjectName(VObject *o, const char *id); - extern void setVObjectStringZValue(VObject *o, const char *s); - extern void setVObjectStringZValue_(VObject *o, const char *s); - extern void setVObjectUStringZValue(VObject *o, const wchar_t *s); - extern void setVObjectUStringZValue_(VObject *o, const wchar_t *s); - extern void setVObjectIntegerValue(VObject *o, unsigned int i); - extern void setVObjectLongValue(VObject *o, unsigned long l); - extern void setVObjectAnyValue(VObject *o, void *t); - extern VObject *setValueWithSize(VObject *prop, void *val, unsigned int size); - extern VObject *setValueWithSize_(VObject *prop, void *val, unsigned int size); - - extern const char *vObjectName(VObject *o); - extern const char *vObjectStringZValue(VObject *o); - extern const wchar_t *vObjectUStringZValue(VObject *o); - extern unsigned int vObjectIntegerValue(VObject *o); - extern unsigned long vObjectLongValue(VObject *o); - extern void *vObjectAnyValue(VObject *o); - extern VObject *vObjectVObjectValue(VObject *o); - extern void setVObjectVObjectValue(VObject *o, VObject *p); - - extern VObject *addVObjectProp(VObject *o, VObject *p); - extern VObject *addProp(VObject *o, const char *id); - extern VObject *addProp_(VObject *o, const char *id); - extern VObject *addPropValue(VObject *o, const char *p, const char *v); - extern VObject *addPropSizedValue_(VObject *o, const char *p, const char *v, unsigned int size); - extern VObject *addPropSizedValue(VObject *o, const char *p, const char *v, unsigned int size); - extern VObject *addGroup(VObject *o, const char *g); - extern void addList(VObject **o, VObject *p); - - extern VObject *isAPropertyOf(VObject *o, const char *id); - - extern VObject *nextVObjectInList(VObject *o); - extern void initPropIterator(VObjectIterator *i, VObject *o); - extern int moreIteration(VObjectIterator *i); - extern VObject *nextVObject(VObjectIterator *i); - - extern char *writeMemVObject(char *s, int *len, VObject *o); - extern char *writeMemVObjects(char *s, int *len, VObject *list); - - extern const char *lookupStr(const char *s); - extern void cleanStrTbl(); - - extern void cleanVObject(VObject *o); - extern void cleanVObjects(VObject *list); - - extern const char *lookupProp(const char *str); - extern const char *lookupProp_(const char *str); - - extern wchar_t *fakeUnicode(const char *ps, int *bytes); - extern unsigned int uStrLen(const wchar_t *u); - extern char *fakeCString(const wchar_t *u); - - extern void printVObjectToFile(char *fname, VObject *o); - extern void printVObjectsToFile(char *fname, VObject *list); - extern void writeVObjectToFile(char *fname, VObject *o); - extern void writeVObjectsToFile(char *fname, VObject *list); - - extern int vObjectValueType(VObject *o); - - /* return type of vObjectValueType: */ -#define VCVT_NOVALUE 0 - /* if the VObject has no value associated with it. */ -#define VCVT_STRINGZ 1 - /* if the VObject has value set by setVObjectStringZValue. */ -#define VCVT_USTRINGZ 2 - /* if the VObject has value set by setVObjectUStringZValue. */ -#define VCVT_UINT 3 - /* if the VObject has value set by setVObjectIntegerValue. */ -#define VCVT_ULONG 4 - /* if the VObject has value set by setVObjectLongValue. */ -#define VCVT_RAW 5 - /* if the VObject has value set by setVObjectAnyValue. */ -#define VCVT_VOBJECT 6 - /* if the VObject has value set by setVObjectVObjectValue. */ - - extern const char **fieldedProp; - - extern void printVObject(FILE *fp, VObject *o); - extern void writeVObject(FILE *fp, VObject *o); - -#if defined(__CPLUSPLUS__) || defined(__cplusplus) -} -#endif - -#endif /* __VOBJECT_H__ */