2 Copyright (c) 2008 Instituto Nokia de Tecnologia
5 Redistribution and use in source and binary forms, with or without modification,
6 are permitted provided that the following conditions are met:
8 * Redistributions of source code must retain the above copyright notice,
9 this list of conditions and the following disclaimer.
10 * Redistributions in binary form must reproduce the above copyright notice,
11 this list of conditions and the following disclaimer in the documentation
12 and/or other materials provided with the distribution.
13 * Neither the name of the INdT nor the names of its contributors
14 may be used to endorse or promote products derived from this software
15 without specific prior written permission.
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 POSSIBILITY OF SUCH DAMAGE.
30 * @file internal_gcal.h
31 * @author Adenilson Cavalcanti
32 * @date Fri May 30 16:46:00 2008
34 * @brief Internal gcal resource structure and constants definition.
35 * The user shalt not mess with it.
37 * I got to move it to a distinct file to share it between gcal.c and
41 #ifndef __INTERNAL_GCAL__
42 #define __INTERNAL_GCAL__
44 #include <curl/curl.h>
45 #include <libxml/parser.h>
47 /** Abstract type to represent a DOM xml tree (a thin layer over xmlDoc).
49 typedef xmlDoc dom_document
;
51 static const char GCAL_DELIMITER
[] = "%40";
52 static const char GCAL_URL
[] = "https://www.google.com/accounts/ClientLogin";
53 static const char GCAL_LIST
[] = "http://www.google.com/calendar/feeds/"
54 "default/allcalendars/full";
55 /* Google calendar URL for posting new events */
56 static const char GCAL_EDIT_URL
[] = "http://www.google.com/calendar/feeds"
57 "/default/private/full";
58 /* Google contacts URL for posting new contacts */
59 static const char GCONTACT_EDIT_START
[] = "http://www.google.com/m8/feeds/"
61 static const char GCONTACT_EDIT_END
[] = "/full";
63 /* Google calendar query URL */
64 static const char GCAL_EVENT_START
[] = "http://www.google.com/calendar/feeds/";
65 static const char GCAL_EVENT_END
[] = "/private/full";
67 /* Google contact query URL */
68 static const char GCONTACT_START
[] = "http://www.google.com/m8/feeds/contacts/";
69 static const char GCONTACT_END
[] = "/full";
71 /* Google 'pages' results in a range pages of 25 entries. But for downloading
72 * all results its requirement to set a 'good enough' upper limit of range of
73 * entries. A hack to make 'gcal_dump' work.
75 static const char GCAL_UPPER
[] = "max-results=999999999";
77 static const int GCAL_DEFAULT_ANSWER
= 200;
78 static const int GCAL_REDIRECT_ANSWER
= 302;
79 static const int GCAL_EDIT_ANSWER
= 201;
80 static const int GCAL_CONFLICT
= 409;
82 static const char ACCOUNT_TYPE
[] = "accountType=HOSTED_OR_GOOGLE";
83 static const char EMAIL_FIELD
[] = "Email=";
84 static const char PASSWD_FIELD
[] = "Passwd=";
85 static const char SERVICE_FIELD
[] = "service=";
86 static const char CLIENT_SOURCE
[] = "source=libgcal";
87 static const char HEADER_AUTH
[] = "Auth=";
88 static const char HEADER_GET
[] = "Authorization: GoogleLogin auth=";
90 /** Library structure. It holds resources (curl, buffer, etc).
92 struct gcal_resource
{
97 /** previous length, required when downloading binary data
98 * i.e. contact photo data
100 size_t previous_length
;
101 /** gcalendar authorization */
103 /** curl data structure */
111 /** DOM xml tree (an abstract type so I can plug another xml parser) */
112 dom_document
*document
;
113 /** A flag to control if the buffer has XML atom stream */
115 /** Google service choose, currently Calendar and contacts */
117 /** HTTP code status from last request */
119 /** CURL error messages */
121 /** Internal status from last request */
123 /** Handler to internal logging file */
125 /** Max number of results (google pages its query results) */
127 /** User defined timezone in RFC 3339 format: -/+hh:mm:ss */
129 /** User defined location (used to define in which timezone the
130 * results will be returned). The format is
131 * "Continent/City_without_spaces", e.g. "America/Los_Angeles".
134 /** Control if deleted entries will be returned or not (only
135 * valid for google contacts.
138 /** Controls if raw XML entries will be stored inside each
139 * event/contact object.
141 char store_xml_entry
;
144 /** This structure has the common data fields between google services
145 * (calendar and contacts).
148 /** Controls if raw XML data will be stored. */
150 /** Flags if this entry was deleted/canceled */
154 /** Time when the event was updated. */
156 /** The 'what' field */
160 /** The ETag (required by Google Data API 2.0) */
162 /** RAW XML data of this entry */
166 /** Library structure, represents each calendar event entry.
169 /** Has the common entry data fields (id, updated, title, edit_uri) */
170 struct gcal_entry common
;
171 /* Here starts calendar event unique fields */
172 /** The event description */
174 /** If the event is recurrent */
176 /** When/start time */
180 /** Location of event */
186 /** Sub structures, e.g. represents each field of gd:structuredPostalAddress or gd:name.
188 struct gcal_structured_subvalues
{
189 /** Pointer to the next structured field */
190 struct gcal_structured_subvalues
*next_field
;
191 /** Number of address */
193 /** Index key of the entry (e.g. 'street') */
195 /** Value of the entry */
199 /** Contact data type */
200 struct gcal_contact
{
201 /** Has the common entry data fields (id, updated, title, edit_uri) */
202 struct gcal_entry common
;
203 /* Here starts google contact unique fields */
204 /** Structured name */
205 struct gcal_structured_subvalues
*structured_name
;
206 /** Number of structured names (it's 1, but let's use it) */
207 int structured_name_nr
;
208 /** Contact emails */
210 /** Contact email types */
212 /** Number of contact emails */
214 /** Index of the preferred email */
217 /* Here starts the extra fields */
218 /** Notes about contact */
230 /** Occupation/Profession */
233 char **phone_numbers_field
;
234 /** Phone number types */
235 char **phone_numbers_type
;
236 /** Number of phone numbers */
237 int phone_numbers_nr
;
244 /** Number of IM accounts */
246 /** Number of preferred IM account */
250 /** Structured postal address address */
251 struct gcal_structured_subvalues
*structured_address
;
252 /** Structured postal address types */
253 char **structured_address_type
;
254 /** Number of structured postal addressees */
255 int structured_address_nr
;
256 /** Number of preferred structured postal address */
257 int structured_address_pref
;
258 /** Google group membership info */
259 char **groupMembership
;
260 /** Google group membership info */
261 int groupMembership_nr
;
264 /** Photo edit url */
266 /** Photo byte array */
267 unsigned char *photo_data
;
268 /** Photo byte length. Values:
271 * > 1: has photo data
273 unsigned int photo_length
;