Set the preferred address entry (gd:structuredPostalAddress).
[libgcal.git] / inc / internal_gcal.h
blobde4500e24770bf918506679975bfec55939933fd
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.
188 struct gcal_structured_subvalues {
189 /** Pointer to the next structured field */
190 struct gcal_structured_subvalues *next_field;
191 /** Number of address */
192 int field_typenr;
193 /** Index key of the entry (e.g. 'street') */
194 char *field_key;
195 /** Value of the entry */
196 char *field_value;
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 */
209 char **emails_field;
210 /** Contact email types */
211 char **emails_type;
212 /** Number of contact emails */
213 int emails_nr;
214 /** Index of the preferred email */
215 int pref_email;
217 /* Here starts the extra fields */
218 /** Notes about contact */
219 char *content;
220 /** Nickname */
221 char *nickname;
222 /** Homepage */
223 char *homepage;
224 /** Blog */
225 char *blog;
226 /** Company name */
227 char *org_name;
228 /** Job title */
229 char *org_title;
230 /** Occupation/Profession */
231 char *occupation;
232 /** Phone numbers */
233 char **phone_numbers_field;
234 /** Phone number types */
235 char **phone_numbers_type;
236 /** Number of phone numbers */
237 int phone_numbers_nr;
238 /** IM address */
239 char **im_address;
240 /** IM protocol */
241 char **im_protocol;
242 /** IM types */
243 char **im_type;
244 /** Number of IM accounts */
245 int im_nr;
246 /** Number of preferred IM account */
247 int im_pref;
248 /** Address */
249 char *post_address;
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;
262 /** Birthday */
263 char *birthday;
264 /** Photo edit url */
265 char *photo;
266 /** Photo byte array */
267 unsigned char *photo_data;
268 /** Photo byte length. Values:
269 * 0: no photo
270 * 1: has photo
271 * > 1: has photo data
273 unsigned int photo_length;
277 #endif