/* * caldav.h * * Copyright 2016 Michael Rasmussen * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * MA 02110-1301, USA. */ #ifndef __CALDAV_H__ #define __CALDAV_H__ #include G_BEGIN_DECLS typedef enum { VUNKNOWN, VEVENT, VTODO, VFREEBUSY, VJOURNAL, } Component; typedef struct { guint status; /* Status code from the request */ GSList* headers; /* List of headers in the response */ gpointer data; /* Either gchar* or GSList* (Calendar) or GSList* (options). */ /* If adding or updating a component a successful */ /* request will return the ETag in data */ } CaldavResponse; typedef enum { UNKNOWN, ADDOBJECTS, CALENDARINFO, CHANGEINFO, DELETEOBJECTS, DISCOVER, GETALLOBJECTS, GETOBJECTS, LOCKING, UNLOCKING, OPTIONSINFO, SIMPLEGET, UPDATEOBJECTS, FREEBUSY, } Operation; typedef struct { gchar* href; gchar* data; } HrefData; typedef guint (*Executor)(gpointer runtime); typedef struct { FILE* file; /* Where to write output. If file is NULL only output will be in 'output' */ gchar* username; /* Account to use */ gchar* password; /* Password for the account */ gchar* url; /* URL to caldav server */ gboolean debug; /* Show debug */ Operation* operation; /* Which operation to execute */ CaldavResponse* output; /* Structure containing the response */ Executor executor; /* Function which executes the request */ gboolean default_executor; /* Using default executors or custom executors */ gchar* etag; /* For If-Match */ gchar* component; /* The data for UPDATEOBJECTS or ADDOBJECTS */ GSList* hrefs; /* For GETOBJECTS: list of HrefData */ GSList* options; /* List of supported options by this caldav server */ GDateTime* start; /* Start time interval in ISO 8601 local time. */ /* 2017-01-13T13:13:13. For freebusy or get operations */ GDateTime* finish; /* End time interval in ISO 8601 local time. */ /* 2017-01-13T13:13:13. For freebusy or get operations */ } Runtime; typedef struct { gchar* url; gchar* displayname; gchar* ctag; GSList* components; /* list of Components */ } Calendar; /** * Return a new Runtime structure all zeroed out. * @return NULL or a new Runtime */ Runtime* runtime_new(); /** * Free a previously created Runtime structure. * @param runtime */ void runtime_free(Runtime* runtime); /** * Make a deep copy of a Runtime. * @param runtime * @return Runtime */ Runtime* runtime_copy(Runtime* runtime); /** * Execute the Runtime * @param runtime * @return guint */ guint execute(Runtime* runtime); /** * Make a deep copy of a Calendar structure * @param cal * @return a deep copy of the Calendar */ Calendar* calendar_copy(Calendar* cal); /** * Free previously created Calendar. * @param cal */ void calendar_free(Calendar* cal); /** * Dump Calendar to FILE. * @param file * @param cal */ void calendar_dump(FILE* file, Calendar* cal); /** * Test whether Component is equal to Component * @param value * @param component * @return TRUE or FALSE */ gboolean is_component(const gchar* value, Component component); /** * Convert Component to its string representation * @param component * @return String */ gchar* component_to_string(Component component); /** * Convert a String representation of a component to Component. * @param value * @return Component */ Component string_to_component(const gchar* value); /** * Get error as String from Runtime. * @param runtime * @return String */ gchar* status_str(Runtime* runtime); /** * Deep copy of a GSList containing Strings to another GSList. * @param list * @return GSList */ GSList* slist_copy_gchar(GSList* list); /** * Free a GSList of Strings. * @param list */ void slist_free_gchar(GSList* list); /** * Create a new HrefData structure. * @param href * @param data * @return HrefData */ HrefData* href_data_new(const gchar* href, const gchar* data); /** * Free a HrefData structure. * @param href_data */ void href_data_free(HrefData* href_data); /** * Find HTTP header in GSList of HTTP headers. * @param list * @param header * @return String */ gchar* find_header(GSList* list, const gchar* header); /** * Test whether caldav server supports option. * @param runtime * @param option * @return TRUE or FALSE */ gboolean has_option(Runtime* runtime, const gchar* option); /** * Convert a string representation of an ISO 8601 date to GDateTime. * @param datetime * @return GDateTime */ GDateTime* get_date_time_from_string(const gchar* datetime); G_END_DECLS #endif