Removing empty spaces.
[libgcal.git] / inc / internal_gcal.h
blob7122fc24c69e90f7e6a386fdf64c9b5060062f7b
1 /*
2 Copyright (c) 2008 Instituto Nokia de Tecnologia
3 All rights reserved.
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.
29 /**
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
38 * gcontact.h.
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/"
60 "contacts/";
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 {
93 /** Memory buffer */
94 char *buffer;
95 /** Its length */
96 size_t length;
97 /** previous length, required when downloading binary data
98 * i.e. contact photo data
100 size_t previous_length;
101 /** gcalendar authorization */
102 char *auth;
103 /** curl data structure */
104 CURL *curl;
105 /** Atom feed URL */
106 char *url;
107 /** The user name */
108 char *user;
109 /** The domain */
110 char *domain;
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 */
114 char has_xml;
115 /** Google service choose, currently Calendar and contacts */
116 char service[3];
117 /** HTTP code status from last request */
118 long http_code;
119 /** CURL error messages */
120 char *curl_msg;
121 /** Internal status from last request */
122 int internal_status;
123 /** Handler to internal logging file */
124 FILE *fout_log;
125 /** Max number of results (google pages its query results) */
126 char *max_results;
127 /** User defined timezone in RFC 3339 format: -/+hh:mm:ss */
128 char *timezone;
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".
133 char *location;
134 /** Control if deleted entries will be returned or not (only
135 * valid for google contacts.
137 int deleted;
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).
147 struct gcal_entry {
148 /** Controls if raw XML data will be stored. */
149 char store_xml;
150 /** Flags if this entry was deleted/canceled */
151 char deleted;
152 /** element ID */
153 char *id;
154 /** Time when the event was updated. */
155 char *updated;
156 /** The 'what' field */
157 char *title;
158 /** The edit URL */
159 char *edit_uri;
160 /** The ETag (required by Google Data API 2.0) */
161 char *etag;
162 /** RAW XML data of this entry */
163 char *xml;
166 /** Library structure, represents each calendar event entry.
168 struct gcal_event {
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 */
173 char *content;
174 /** If the event is recurrent */
175 char *dt_recurrent;
176 /** When/start time */
177 char *dt_start;
178 /** When/end time */
179 char *dt_end;
180 /** Location of event */
181 char *where;
182 /** Event status */
183 char *status;
186 /** Sub structures, e.g. represents each field of gd:structuredPostalAddress or gd:name.
189 struct gcal_structured_subvalues {
190 /* TODO: insert missing documentation here */
191 struct gcal_structured_subvalues *next_field;
192 int field_typenr;
193 char *field_key;
194 char *field_value;
197 /** Contact data type */
198 struct gcal_contact {
199 /** Has the common entry data fields (id, updated, title, edit_uri) */
200 struct gcal_entry common;
201 /* Here starts google contact unique fields */
202 /** Structured name */
203 struct gcal_structured_subvalues *structured_name;
204 /** Number of structured names (it's 1, but let's use it) */
205 int structured_name_nr;
206 /** Contact emails */
207 char **emails_field;
208 /** Contact email types */
209 char **emails_type;
210 /** Number of contact emails */
211 int emails_nr;
212 /** Index of the preferred email */
213 int pref_email;
215 /* Here starts the extra fields */
216 /** Notes about contact */
217 char *content;
218 /** Nickname */
219 char *nickname;
220 /** Homepage */
221 char *homepage;
222 /** Blog */
223 char *blog;
224 /** Company name */
225 char *org_name;
226 /** Job title */
227 char *org_title;
228 /** IM contact */
229 char *im;
230 /** Phone numbers */
231 char **phone_numbers_field;
232 /** Phone number types */
233 char **phone_numbers_type;
234 /** Number of phone numbers */
235 int phone_numbers_nr;
236 /** Address */
237 char *post_address;
238 /** Structured postal address address */
239 struct gcal_structured_subvalues *structured_address;
240 /** Structured postal address types */
241 char **structured_address_type;
242 /** Number of structured postal addressees */
243 int structured_address_nr;
244 /** Google group membership info */
245 char **groupMembership;
246 /** Google group membership info */
247 int groupMembership_nr;
248 /** Birthday */
249 char *birthday;
250 /** Photo edit url */
251 char *photo;
252 /** Photo byte array */
253 unsigned char *photo_data;
254 /** Photo byte length. Values:
255 * 0: no photo
256 * 1: has photo
257 * > 1: has photo data
259 unsigned int photo_length;
263 #endif