/usr/include/libgcal/gcal.h is in libgcal-dev 0.9.6-3.2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 | /*
Copyright (c) 2008 Instituto Nokia de Tecnologia
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the INdT nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 COPYRIGHT OWNER OR CONTRIBUTORS 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.
*/
/**
* @file gcal.h
* @author Adenilson Cavalcanti da Silva <adenilson.silva@indt.org.br>
* @date Mon Mar 3 20:15:09 2008
*
* @brief libgcal header file.
*
* This defines the public functions.
*
*/
#ifndef __GCAL_LIB__
#define __GCAL_LIB__
/* For size_t */
#include <stdlib.h>
/** Set gcal Google service mode */
typedef enum { GCALENDAR, GCONTACT } gservice;
/** Flag to control if deleted entries will be retrieved or not
* (for while, google only implements that for 'contacts').
* Calendar deleted entries will *always* be returned with
* 'eventStatus' set to 'cancelled'.
*
*/
typedef enum { HIDE, SHOW } display_deleted_entries;
/** Upload (being POST or PUT) definition option.
*
* Its used to set behavior in \ref up_entry function.
*/
typedef enum {
/** Code for HTTP POST. */
POST,
/** Code for HTTP PUT */
PUT } HTTP_CMD;
/** Really weird timestamp from RFC 3339 is
* 1937-01-01T12:00:27.87+00:20
* so 30 bytes is enough to have milisecond precision
* in worst case.
*/
static const size_t TIMESTAMP_MAX_SIZE = 30;
/** Minimal timestamp size is
* 1937-01-01T12:00:27.87Z
*/
static const size_t TIMESTAMP_SIZE = 23;
/** Library structure. It holds resources (curl, buffer, etc).
*/
struct gcal_resource;
/** Library structure, represents each calendar event entry.
*/
struct gcal_event;
/** Library structure, represents common data for a google entry (being
* calendar or contact). It has: id, updated, title, edit_uri.
*/
struct gcal_entry;
/** An opaque type for gcal object.
*/
typedef struct gcal_resource * gcal_t;
/** Library structure destructor (use it free its internal resources properly).
*/
void gcal_destroy(struct gcal_resource *gcal_obj);
/** Internal use function, cleans up the internal buffer.
*
* \todo move it to a distinct internal module.
*
* @param gcal_obj Library resource structure pointer.
*/
void clean_buffer(struct gcal_resource *gcal_obj);
/** Library structure constructor, the user can only have pointers to the
* library \ref gcal_resource structure.
*
* Concerning google service type, it defaults to google calendar. You can
* change it using \ref gcal_set_service.
*
* @param mode Service that libgcal will handle (for while, GCALENDAR
* and GCONTACT).
*
* @return A pointer to a newly created object or NULL.
*/
struct gcal_resource *gcal_construct(gservice mode);
/** Sets the google service that user wants to authenticate.
*
* For while, only calendar (cl) and contacts (cp) are supported.
*
* @param gcalobj Pointer to a library resource structure \ref gcal_resource.
*
* @param mode Service type, see \ref gservice.
*
* @return 0 for success, -1 otherwise.
*/
int gcal_set_service(struct gcal_resource *gcalobj, gservice mode);
/** Gets from google an authentication token, using the 'ClientLogin' service.
*
* Use it before getting/setting google calendar events. If you are behind of
* a network proxy, its import to use \ref gcal_set_proxy *before* to set
* the proxy (or all network connections will hang and timeout).
*
* @param gcalobj Pointer to a library resource structure \ref gcal_resource
*
* @param user The user google login account.
*
* @param password User password in plain text
* \todo think in a way to encrypt password
*
* @return Returns 0 on success, -1 otherwise.
*/
int gcal_get_authentication(struct gcal_resource *gcalobj,
char *user, char *password);
/** Dumps events from default calendar to internal buffer.
* \todo Let the library user select which calendar he/she wants
* to get the events. See \ref gcal_calendar_list.
*
* @param gcalobj Pointer to a \ref gcal_resource structure, which has
* previously got the authentication using
* \ref gcal_get_authentication.
*
* @param gdata_version Version of Data API.
*
* @return Returns 0 on success, -1 otherwise.
*/
int gcal_dump(struct gcal_resource *gcalobj, const char *gdata_version);
/** Get a list of users calendars (gcalendar supports multiple calendars
* besides the default calendar).
*
* I think it would be a good idea to let the library user decide which
* calendar to get the events. See too \ref gcal_dump.
*
* \todo Parse the Atom feed and provide easy access to the calendar lists.
*
* @param gcalobj Pointer to a \ref gcal_resource structure, which has
* previously got the authentication using
* \ref gcal_get_authentication.
*
* @return Returns 0 on success, -1 otherwise.
*/
int gcal_calendar_list(struct gcal_resource *gcalobj);
/** Return the number of event entries a calendar has (you should
* had got the atom stream before, using \ref gcal_dump).
*
* @param gcalobj Pointer to a \ref gcal_resource structure, which has
* previously got the authentication using
* \ref gcal_get_authentication.
*
* @return -1 on error, any number >= 0 otherwise.
*/
int gcal_entry_number(struct gcal_resource *gcalobj);
/** Extracts from the atom stream the calendar event entries (you should
* had got the atom stream before, using \ref gcal_dump).
*
* Pay attention that it returns a vector of structures that must be destroyed
* using \ref gcal_destroy_entries.
*
* Since atom XML feeds can get huge, as soon the function creates entries
* vector and copies the data from the internal \ref gcal_resource buffer,
* it will free its internal buffer to save memory.
*
*
* @param gcalobj Pointer to a \ref gcal_resource structure, which has
* previously got the authentication using
* \ref gcal_get_authentication.
*
* @param length Pointer to an unsigned int, it will have the vector length.
*
* @return A pointer on sucess, NULL otherwise.
*/
struct gcal_event *gcal_get_entries(struct gcal_resource *gcalobj,
size_t *length);
/** Always use this to set calendar event structure to a sane state.
*
* You were warned...
*
* @param entry A pointer to a \ref gcal_event.
*/
void gcal_init_event(struct gcal_event *entry);
/** Cleanup memory of 1 entry structure pointer.
*
*
* @param entry A pointer to a \ref gcal_event.
*/
void gcal_destroy_entry(struct gcal_event *entry);
/** Generic HTTP GET function.
*
* Used when getting entries in a feed (or other data that requires
* an authenticated GET).
*
* @param gcalobj Pointer to a \ref gcal_resource structure, which has
* previously got the authentication using
* \ref gcal_get_authentication.
*
* @param url URL string.
*
* @param cb_download Callback used for writing downloaded data. Must
* be of type: size_t()(void *, size_t, size_t, void*)
*
* @param gdata_version Version of Data API.
*
* @return 0 for success, -1 for error.
*/
int get_follow_redirection(struct gcal_resource *gcalobj, const char *url,
void *cb_download, const char *gdata_version);
/** Cleanup the memory of a vector of calendar entries created using
* \ref gcal_get_entries.
*
* @param entries A pointer to a vector of \ref gcal_event structure.
*
* @param length The vector length.
*/
void gcal_destroy_entries(struct gcal_event *entries, size_t length);
/** Posts data to a server URL and checks its result.
*
* I'm not sure if this one should be here, since it is a more an internal
* function (but I need to share it with 'contacts' too).
*
* \todo move it to a distinct internal module.
* @param gcalobj Pointer to a \ref gcal_resource structure, which has
* previously got the authentication using
* \ref gcal_get_authentication.
*
* @param url The server URL.
* @param header First header part.
* @param header2 Second header part (can be NULL).
* @param header3 Third header part (can be NULL).
* @param header4 Third header part (can be NULL). Used for ETag (Google Data
* API 2.0)
* @param post_data The data to post (can be NULL).
* @param length The data length (can be zero).
* @param expected_answer The expected answer code, see GCAL_DEFAULT_ANSWER and
* friends.
*
* @return -1 on error, 0 on success.
*/
int http_post(struct gcal_resource *gcalobj, const char *url,
char *header, char *header2, char *header3,
char *header4,
char *post_data, unsigned int length,
const int expected_answer,
const char *gdata_version);
/** Uploads an entry (calendar or contact) to a server URL
*
* Used by \ref gcal_create_event, \ref gcal_create_contact,
* \ref gcal_edit_event.
*
*
* @param data2post A pointer to string, it will be the body to be posted.
*
* @param length The data length (can be zero).
*
* @param gcalobj Pointer to a \ref gcal_resource structure, which has
* previously got the authentication using
* \ref gcal_get_authentication.
*
* @param url_server The URL of server (one for calendar and other for
* contacts).
*
* @param etag Google Data API 2.0 requires an Etag in HTTP header for some
* operations.
*
* @param up_mode If the upload of data will be using PUT or POST (internally
* it uses 'http_put' and \ref 'http_post').
*
* @param content_type The content type, to use default (application/atom+xml)
* pass NULL.
*
* @param expected_code The expected return code from server (200, 201, etc.)
* See GCAL_DEFAULT_ANSWER and friends.
*
* @return -1 on error, 0 on success.
*/
int up_entry(char *data2post, unsigned int m_length,
struct gcal_resource *gcalobj,
const char *url_server, char *etag,
HTTP_CMD up_mode, char *content_type,
int expected_code);
/** Creates an new calendar event.
*
* You need to first succeed to get an authorization token using
* \ref gcal_get_authentication.
*
* @param gcalobj Pointer to a \ref gcal_resource structure, which has
* previously got the authentication using
* \ref gcal_get_authentication.
*
* @param entries A pointer to an calendar entry event (see \ref gcal_event).
*
* @param updated Pass a pointer to a \ref gcal_event structure if you
* wish to access the newly created contact (i.e. access fields like
* edit_uri and id). If you don't need it, just pass NULL.
*
* @return -1 on error, 0 on success, -2 if operation went correctly but
* cannot return 'updated' entry.
*/
int gcal_create_event(struct gcal_resource *gcalobj,
struct gcal_event *entries,
struct gcal_event *updated);
/** Deletes a calendar event.
*
* You need to first succeed to get an authorization token using
* \ref gcal_get_authentication.
*
* @param gcalobj Pointer to a \ref gcal_resource structure, which has
* previously got the authentication using
* \ref gcal_get_authentication.
*
* @param entry A pointer to one calendar entry event (see \ref gcal_event).
*
* @return -1 on error, 0 on success.
*/
int gcal_delete_event(struct gcal_resource *gcalobj,
struct gcal_event *entry);
/** Edits a calendar event.
*
* It requires the presence of field 'edit_uri' in entry pointer structure
* (see \ref gcal_event).
*
*
* @param gcalobj Pointer to a \ref gcal_resource structure, which has
* previously got the authentication using
* \ref gcal_get_authentication.
*
* @param entry A pointer to an calendar entry event.
*
* @param updated Pass a pointer to a \ref gcal_event structure if you
* wish to access the newly created contact (i.e. access fields like
* edit_uri and id). If you don't need it, just pass NULL.
*
* @return -1 on error, 0 on success, -2 if operation went correctly but
* cannot return 'updated' entry.
*/
int gcal_edit_event(struct gcal_resource *gcalobj,
struct gcal_event *entry,
struct gcal_event *updated);
/** Provides access to internal buffer (e.g. to access the raw Atom stream).
*
* Pay attention that you *must not* mess with its memory, since when deleting
* the gcal_resource pointer with \ref gcal_destroy the memory pointed will
* be freed.
*
* @param gcalobj Pointer to a \ref gcal_resource structure, which has
* previously got the authentication using
* \ref gcal_get_authentication.
*
* @return A pointer to internal gcal_resource buffer.
*/
char *gcal_access_buffer(struct gcal_resource *gcalobj);
/** Function to get the current timestamp (RFC3339) with milisecond
* precision.
*
* @param timestamp A pointer to a buffer to where to write the timestamp.
*
* @param length The buffer length.
*
* @param atimezone A timezone string in format: +/-hh:mm:ss. It will be
* appended to the output timestamp.
*
* @return 0 for success, -1 for failure.
*/
int get_mili_timestamp(char *timestamp, size_t length, char *atimezone);
/** Returns all entries (being calendar or contacts) that are newer
* than a timestamp.
*
* Use it to get updated entries.
*
* @param gcalobj Pointer to a \ref gcal_resource structure, which has
* previously got the authentication using
* \ref gcal_get_authentication.
*
* @param timestamp A timestamp in RFC 3339 format yyyy-mm-ddThh:mm:ss
*(if NULL, this function will use current day, with time set to 06:00AM).
*
* @param gdata_version Version of Data API.
*
* @return -1 on error, 0 on success.
*/
int gcal_query_updated(struct gcal_resource *gcalobj, char *timestamp,
const char *gdata_version);
/** Set a timezone, following the RFC 3339 format +/-hh:mm.
*
* The structure copy the string with the timezone.
*
* @param gcalobj Pointer to a \ref gcal_resource structure, which has
* previously got the authentication using
* \ref gcal_get_authentication.
*
* @param atimezone A pointer to string with the timezone (e.g. for Helsinki
* which is +2GMT it would be "+02:00").
*
* @return -1 on error, 0 on success.
*/
int gcal_set_timezone(struct gcal_resource *gcalobj, char *atimezone);
/** Sets gcal XML store mode.
*
* Use it if you wish to store the RAW google XML entry data inside
* each entry object.
*
* @param gcalobj Pointer to a \ref gcal_resource structure, which has
* previously got the authentication using
* \ref gcal_get_authentication.
*
* @param flag 0 for not store, 1 to activate store mode.
*/
void gcal_set_store_xml(struct gcal_resource *gcalobj, char flag);
/** Sets network proxy.
*
* Use it if you are behind a network proxy and can't directly access
* the google server.
*
* @param gcalobj Pointer to a \ref gcal_resource structure, which has
* previously got the authentication using
* \ref gcal_get_authentication.
*
* @param proxy A null terminated string, must have the hostname (or IP)
* and can have the user+password too (e.g. "user+password@10.10.1.1:8080" or
* simply "http://hostname:port". Remark: I only tested it with
* a proxy that doesn't require authentication.
*
*/
void gcal_set_proxy(struct gcal_resource *gcalobj, char *proxy);
/** Define the location that results should be returned for queries.
*
* Use it to set your current location, otherwise the configured city for
* the user account is used.
* The structure copy the string with the timezone.
*
* @param gcalobj Pointer to a \ref gcal_resource structure, which has
* previously got the authentication using
* \ref gcal_get_authentication.
*
* @param location A pointer to string with the location (e.g. "America/Manaus",
* "Europe/Helsinki", "America/Los_Angeles'). It must not has empty spaces on
* it.
*
* @return -1 on error, 0 on success.
*/
int gcal_set_location(struct gcal_resource *gcalobj, char *location);
/** Use this to set if deleted entries should be returned or not. Pay attention
* that this is implemented only for google contacts (google calendar entries
* doesn't have this query parameter).
*
* @param gcalobj Pointer to a \ref gcal_resource structure, which has
* previously got the authentication using
* \ref gcal_get_authentication.
*
* @param opt Option parameter, enable (SHOW) or not (HIDE) retrieving of
* deleted entries (see \ref display_deleted_entries).
*/
void gcal_deleted(struct gcal_resource *gcalobj, display_deleted_entries opt);
/** Generic query function, use it to do a query to google services.
*
* You can pass a query with multiple parameters, but in just one string.
*
* ATTENTION: querying by name will not work, since its not implemented in
* google contacts. It will give HTTP 403 error.
*
* @param gcalobj Pointer to a \ref gcal_resource structure, which has
* previously got the authentication using
* \ref gcal_get_authentication.
*
* @param parameters A string with the query e.g. for calendar
* gcal_query(gcal, "ctz=America/Los_Angeles&author=Joe");
*
* And for contacts:
* gcal_query(gcal, "updated-min=2008-06-20T06:00:00Z&"
* "alt=atom&max-results=500&showdeleted=true");
*
* @param gdata_version Version of Data API.
*
* @return -1 on error, 0 on success.
*/
int gcal_query(struct gcal_resource *gcalobj, const char *parameters,
const char *gdata_version);
/* Common fields between calendar and contacts are
* of type 'gcal_entry'
*/
/** Access to entry ID.
*
* Each google entry (event/contact) has a unique ID, you can access
* it using this function.
*
* @param entry A data entry pointer, see \ref gcal_entry.
*
* @return A pointer to internal field (*dont* try to free it!).
*/
char *gcal_get_id(struct gcal_entry *entry);
/** Access to last updated timestamp of an entry.
*
* When an operation (being add/edit/delete) is done in an entry, the timestamp
* of it is recorded). You can access it using this function.
*
* @param entry A data entry pointer, see \ref gcal_entry.
*
* @return A pointer to internal field (*dont* try to free it!).
*/
char *gcal_get_updated(struct gcal_entry *entry);
/** Access entry title.
*
* Each entry has a title, being contacts (the contact name) or event
* (meeting title).
*
* @param entry A data entry pointer, see \ref gcal_entry.
*
* @return A pointer to internal field (*dont* try to free it!).
*/
char *gcal_get_title(struct gcal_entry *entry);
/** Access edit url.
*
* Each entry has an edit url (which is the combination of ID + cookie).
* This edit url is required to do operations (edit/delete) and changes
* each time an operation is done.
*
* @param entry A data entry pointer, see \ref gcal_entry.
*
* @return A pointer to internal field (*dont* try to free it!).
*/
char *gcal_get_url(struct gcal_entry *entry);
/** Access ETag.
*
* Each entry has an ETag (Google Data API 2.0).
* This etag is required to do operations (edit/delete) and changes
* each time an operation is done.
*
* @param entry A data entry pointer, see \ref gcal_entry.
*
* @return A pointer to internal field (*dont* try to free it!).
*/
char *gcal_get_etag(struct gcal_entry *entry);
/** Access raw XML.
*
* Even if some fields are parsed from atom stream and directly accessable
* from entry objects, its possible to access the RAW representation of the
* whole entry using this function.
*
* @param entry A data entry pointer, see \ref gcal_entry.
*
* @return A pointer to internal field (*dont* try to free it!).
*/
char *gcal_get_xml(struct gcal_entry *entry);
/** Entry status (deleted: 1, not: 0).
*
* When an entry is deleted, there is a way to known it, being specific for
* the entry type. Events have the gd:eventStatus equal to
* "blah#event.cancelled".
*
* Contacts will have a new field (gd:deleted).
*
* @param entry A data entry pointer, see \ref gcal_entry.
*
* @return 1 for deleted, 0 for not deleted, -1 for error case (f the event
* object is invalid).
*/
char gcal_get_deleted(struct gcal_entry *entry);
/** Global cleanup (use only at end of program)
*
* Cleans up any global variables that the library may use (which currently
* it doesn't use), as well as calls libxml2's xmlCleanupParser().
*
* Rationale: if the linked application is also using libxml and xmlCleanuParser
* is called from within libgcal, it will at very best mess up with the
* other code. Special thanks for Chris Frey for finding this bug and
* fixing.
*/
void gcal_final_cleanup();
#endif
|