5 /* Note, all routines that are prefixed with "caller_" are
6 implemented by the caller of libical */
8 /* 1 Open a connection to a store. */
10 /* The caller is responsible for getting a socket to the server
11 and negotiating the first stages of the CAP exchange. These can
12 be fairly complex and varied for different operating systems,
13 local vs remote usage, and for different authentication
14 schemes, so the API does not try to simplify them. */
16 int sock = caller_create_socket_to_server();
17 icalcstp *cstp = icalcstp_new(0,sock,sock);
19 caller_authenticate(cstp);
21 icalcsdb *csdb = icalcsdb_new(cstp);
23 /* 2 Create a new calendar for which user Bill can read and user Mary can
24 read and write. See CAP draft 7.2.1.1.1. for the text of this example*/
26 /* This case requires setting up a TARGET, multiple OWNERs and
27 multiple VCARs, so it creates a component and uses CSTP that
28 than the CSDB interface.
30 icalcomponent *create = icalcaputil_new_create();
32 icalcomponent_add_property(create,
33 icalproperty_new_target(
34 strdup("cap://cal.example.com/relcal8")
38 icalcomponent_vanew_vcalendar(
39 icalproperty_new_relcalid(strdup("relcalid")),
40 icalproperty_new_name(strdup("Bill & Mary's cal")),
41 icalproperty_new_owner(strdup("bill")),
42 icalproperty_new_owner(strdup("mary")),
43 icalproperty_new_calmaster(strdup("mailto:bill@example.com")),
44 icalcomponent_vanew_vcar(
45 icalproperty_new_grant(strdup("UPN=bill;ACTION=*;OBJECT=*")),
46 icalproperty_new_grant(strdup("UPN=bill;ACTION=*;OBJECT=*"))
50 error = icalcomponent_add_component(create,cal);
53 error = icalcstp_senddata(cstp,10,create);
56 /* Get the response */
57 icalcstp_response response = icalcstp_get_first_response(cstp);
59 /* Do something with the response*/
61 if(icalenum_reqstat_major(response.code) != 2){
62 /* do something with the error */
65 icalcomponent_free(create);
68 /* 3 Create several new calendars */
70 /* Same as #2, but insert more TARGET properties and read more responses*/
72 /* 4 Delete a calendar */
74 error = icalcsdb_delete(csdb,"uid12345-example.com");
76 /* 5 Change the calid of a calendar */
78 erorr = icalcsdb_move(csdb,"uid12345-old-example.com",
79 "uid12345-new-example.com");
82 /* 6 Delete all calendars belonging to user bob */
85 /* First expand bob's UPN into a set of CALIDs */
86 icalcomponent *calids = icalcsdb_expand_upn("bob@example.com");
88 /* Then, create a message to delete all of them */
89 icalcomponent *delete = icalcaputil_new_create();
92 for(p = icalcomponent_get_first_property(calids,ICAL_CALID_PROPERTY);
94 p = icalcomponent_get_next_property(calids,ICAL_CALID_PROPERTY)){
96 char* = icalproperty_get_calid(p);
98 icalcomponent_add_target(delete,p);
102 /* Send the message */
104 error = icalcstp_senddata(cstp,10,delete);
106 /* Finally, read the responses */
108 for(response = icalcstp_get_first_response(cstp);
109 response.code != ICAL_UNKNOWN_STATUS;
110 response = icalcstp_get_next_response(cstp)){
112 if(icalenum_reqstat_major(response.code) != 2){
113 /* do something with the error */
118 /* 7 Get three new UIDs from the store */
120 /* libical owns the returned memory. Copy before using */
121 char* uid1 = icalcsdb_generateuid(csdb);
122 char* uid2 = icalcsdb_generateuid(csdb);
123 char* uid3 = icalcsdb_generateuid(csdb);
125 /* 8 Store a new VEVENT in the store. */
127 /* Very similar to case #2 */
129 /* 9 Find all components for which the LOCATION is "West Conference
130 Room" and change them to "East Conference Room" */
132 icalcomponent *modify = icalcaputil_new_modify();
134 icalcaputil_modify_add_old_prop(modify,
135 icalproperty_new_location(
136 strdup("West Conference Room")));
138 icalcaputil_modify_add_new_prop(modify,
139 icalproperty_new_location(
140 strdup("East Conference Room")));
142 icalcaputil_add_target(modify,"relcal2");
144 /* Send the component */
145 error = icalcstp_senddata(cstp,10,delete);
147 /* Get the response */
148 icalcstp_response response = icalcstp_get_first_response(cstp);
150 /* Do something with the response*/
152 if(icalenum_reqstat_major(response.code) != 2){
153 /* do something with the error */
156 icalcomponent_free(modify);
158 /* 10 Find the component with UID X and add a GEO property to it. */
161 icalcomponent *modify = icalcaputil_new_modify();
163 icalcaputil_modify_add_query(modify,
164 "SELECT UID FROM VEVENT WHERE UID = 'X'");
166 icalcaputil_modify_add_new_prop(modify,
167 icalproperty_new_geo(
170 icalcaputil_add_target(modify,"relcal2");
172 /* Send the component */
173 error = icalcstp_senddata(cstp,10,delete);
175 /* Get the response */
176 icalcstp_response response = icalcstp_get_first_response(cstp);
178 /* Do something with the response*/
180 if(icalenum_reqstat_major(response.code) != 2){
181 /* do something with the error */
184 icalcomponent_free(modify);
187 /* 11 Delete all VEVENTS which have a METHOD that is not CREATED */
190 /* 12 Retrieve all VEVENTS which have a METHOD that is not CREATED */
192 /* Nearly the same at #11 */
194 /* 13 Retrieve the capabilities of the store */
196 /* 14 Retrieve/Modify/Add/Delete properties of a store */
198 /* 15 Retrieve/Modify/Add/Delete VCARs of a store */
200 /* 16 Retrieve/Modify/Add/Delete VTIMEZONEs of a store */
202 /* 17 Retrieve/Modify/Add/Delete properties of a calendar */
204 /* 18 Retrieve/Modify/Add/Delete VCARs of a calendar */
206 /* 19 Retrieve/Modify/Add/Delete VTIMEZONEs of a calendar */
208 /* 20 Translate a CALID into one or more UPNs */
210 /* 21 Expand a group UPN into all of the members of the group */