audio: fixes for call hangup/resume on both local and remote sides
[siplcs.git] / src / core / sipe-ews.c
blob2e4addf45aded39d69095beb53b3994bb19e40e4
1 /**
2 * @file sipe-ews.c
4 * pidgin-sipe
6 * Copyright (C) 2010 SIPE Project <http://sipe.sourceforge.net/>
7 * Copyright (C) 2010, 2009 pier11 <pier11@operamail.com>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 /**
26 For communication with Exchange 2007/2010 Web Server/Web Services:
28 1) Autodiscover (HTTPS POST request). With redirect support. XML content.
29 1.1) DNS SRV record _autodiscover._tcp.<domain> may also be resolved.
30 2) Availability Web service (SOAP = HTTPS POST + XML) call.
31 3) Out of Office (OOF) Web Service (SOAP = HTTPS POST + XML) call.
32 4) Web server authentication required - NTLM and/or Negotiate (Kerberos).
34 Note: ews - EWS stands for Exchange Web Services.
36 It will be able to retrieve our Calendar information (FreeBusy, WorkingHours,
37 Meetings Subject and Location, Is_Meeting) as well as our Out of Office (OOF) note
38 from Exchange Web Services for subsequent publishing.
40 Ref. for more implementation details:
41 http://sourceforge.net/projects/sipe/forums/forum/688535/topic/3403462
43 Similar functionality for Lotus Notes/Domino, iCalendar/CalDAV/Google would
44 be great to implement too.
47 #include <string.h>
48 #include <time.h>
50 #include <glib.h>
52 #include "http-conn.h"
53 #include "sipe-backend.h"
54 #include "sipe-common.h"
55 #include "sipe-cal.h"
56 #include "sipe-core.h"
57 #include "sipe-ews.h"
58 #include "sipe-utils.h"
59 #include "sipe-xml.h"
60 #include "sipe.h"
62 /**
63 * Autodiscover request for Exchange Web Services
64 * @param email (%s) Ex.: alice@cosmo.local
66 #define SIPE_EWS_AUTODISCOVER_REQUEST \
67 "<?xml version=\"1.0\"?>"\
68 "<Autodiscover xmlns=\"http://schemas.microsoft.com/exchange/autodiscover/outlook/requestschema/2006\">"\
69 "<Request>"\
70 "<EMailAddress>%s</EMailAddress>"\
71 "<AcceptableResponseSchema>"\
72 "http://schemas.microsoft.com/exchange/autodiscover/outlook/responseschema/2006a"\
73 "</AcceptableResponseSchema>"\
74 "</Request>"\
75 "</Autodiscover>"
77 /**
78 * GetUserOofSettingsRequest SOAP request to Exchange Web Services
79 * to obtain our Out-of-office (OOF) information.
80 * @param email (%s) Ex.: alice@cosmo.local
82 #define SIPE_EWS_USER_OOF_SETTINGS_REQUEST \
83 "<?xml version=\"1.0\" encoding=\"utf-8\"?>"\
84 "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"\
85 "<soap:Body>"\
86 "<GetUserOofSettingsRequest xmlns=\"http://schemas.microsoft.com/exchange/services/2006/messages\">"\
87 "<Mailbox xmlns=\"http://schemas.microsoft.com/exchange/services/2006/types\">"\
88 "<Address>%s</Address>"\
89 "</Mailbox>"\
90 "</GetUserOofSettingsRequest>"\
91 "</soap:Body>"\
92 "</soap:Envelope>"
94 /**
95 * GetUserAvailabilityRequest SOAP request to Exchange Web Services
96 * to obtain our Availability (FreeBusy, WorkingHours, Meetings) information.
97 * @param email (%s) Ex.: alice@cosmo.local
98 * @param start_time (%s) Ex.: 2009-12-06T00:00:00
99 * @param end_time (%s) Ex.: 2009-12-09T23:59:59
101 #define SIPE_EWS_USER_AVAILABILITY_REQUEST \
102 "<?xml version=\"1.0\" encoding=\"utf-8\"?>"\
103 "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\""\
104 " xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\""\
105 " xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\""\
106 " xmlns:t=\"http://schemas.microsoft.com/exchange/services/2006/types\">"\
107 "<soap:Body>"\
108 "<GetUserAvailabilityRequest xmlns=\"http://schemas.microsoft.com/exchange/services/2006/messages\""\
109 " xmlns:t=\"http://schemas.microsoft.com/exchange/services/2006/types\">"\
110 "<t:TimeZone xmlns=\"http://schemas.microsoft.com/exchange/services/2006/types\">"\
111 "<Bias>0</Bias>"\
112 "<StandardTime>"\
113 "<Bias>0</Bias>"\
114 "<Time>00:00:00</Time>"\
115 "<DayOrder>0</DayOrder>"\
116 "<Month>0</Month>"\
117 "<DayOfWeek>Sunday</DayOfWeek>"\
118 "</StandardTime>"\
119 "<DaylightTime>"\
120 "<Bias>0</Bias>"\
121 "<Time>00:00:00</Time>"\
122 "<DayOrder>0</DayOrder>"\
123 "<Month>0</Month>"\
124 "<DayOfWeek>Sunday</DayOfWeek>"\
125 "</DaylightTime>"\
126 "</t:TimeZone>"\
127 "<MailboxDataArray>"\
128 "<t:MailboxData>"\
129 "<t:Email>"\
130 "<t:Address>%s</t:Address>"\
131 "</t:Email>"\
132 "<t:AttendeeType>Required</t:AttendeeType>"\
133 "<t:ExcludeConflicts>false</t:ExcludeConflicts>"\
134 "</t:MailboxData>"\
135 "</MailboxDataArray>"\
136 "<t:FreeBusyViewOptions>"\
137 "<t:TimeWindow>"\
138 "<t:StartTime>%s</t:StartTime>"\
139 "<t:EndTime>%s</t:EndTime>"\
140 "</t:TimeWindow>"\
141 "<t:MergedFreeBusyIntervalInMinutes>15</t:MergedFreeBusyIntervalInMinutes>"\
142 "<t:RequestedView>DetailedMerged</t:RequestedView>"\
143 "</t:FreeBusyViewOptions>"\
144 "</GetUserAvailabilityRequest>"\
145 "</soap:Body>"\
146 "</soap:Envelope>"
148 #define SIPE_EWS_STATE_NONE 0
149 #define SIPE_EWS_STATE_AUTODISCOVER_SUCCESS 1
150 #define SIPE_EWS_STATE_AUTODISCOVER_1_FAILURE -1
151 #define SIPE_EWS_STATE_AUTODISCOVER_2_FAILURE -2
152 #define SIPE_EWS_STATE_AVAILABILITY_SUCCESS 3
153 #define SIPE_EWS_STATE_AVAILABILITY_FAILURE -3
154 #define SIPE_EWS_STATE_OOF_SUCCESS 4
155 #define SIPE_EWS_STATE_OOF_FAILURE -4
157 char *
158 sipe_ews_get_oof_note(struct sipe_calendar *cal)
160 time_t now = time(NULL);
162 if (!cal || !cal->oof_state) return NULL;
164 if (sipe_strequal(cal->oof_state, "Enabled") ||
165 (sipe_strequal(cal->oof_state, "Scheduled") && now >= cal->oof_start && now <= cal->oof_end))
167 return cal->oof_note;
169 else
171 return NULL;
175 static void
176 sipe_ews_run_state_machine(struct sipe_calendar *cal);
178 static void
179 sipe_ews_process_avail_response(int return_code,
180 const char *body,
181 SIPE_UNUSED_PARAMETER const char *content_type,
182 HttpConn *conn,
183 void *data)
185 struct sipe_calendar *cal = data;
187 SIPE_DEBUG_INFO_NOFORMAT("sipe_ews_process_avail_response: cb started.");
189 if(!sipe_strequal(cal->as_url, cal->oof_url)) { /* whether reuse conn */
190 http_conn_set_close(conn);
191 cal->http_conn = NULL;
194 if (return_code == 200 && body) {
195 const sipe_xml *node;
196 const sipe_xml *resp;
197 /** ref: [MS-OXWAVLS] */
198 sipe_xml *xml = sipe_xml_parse(body, strlen(body));
200 Envelope/Body/GetUserAvailabilityResponse/FreeBusyResponseArray/FreeBusyResponse/ResponseMessage@ResponseClass="Success"
201 Envelope/Body/GetUserAvailabilityResponse/FreeBusyResponseArray/FreeBusyResponse/FreeBusyView/MergedFreeBusy
202 Envelope/Body/GetUserAvailabilityResponse/FreeBusyResponseArray/FreeBusyResponse/FreeBusyView/CalendarEventArray/CalendarEvent
203 Envelope/Body/GetUserAvailabilityResponse/FreeBusyResponseArray/FreeBusyResponse/FreeBusyView/WorkingHours
205 resp = sipe_xml_child(xml, "Body/GetUserAvailabilityResponse/FreeBusyResponseArray/FreeBusyResponse");
206 if (!resp) return; /* rather soap:Fault */
207 if (!sipe_strequal(sipe_xml_attribute(sipe_xml_child(resp, "ResponseMessage"), "ResponseClass"), "Success")) {
208 return; /* Error response */
211 /* MergedFreeBusy */
212 g_free(cal->free_busy);
213 cal->free_busy = sipe_xml_data(sipe_xml_child(resp, "FreeBusyView/MergedFreeBusy"));
215 /* WorkingHours */
216 node = sipe_xml_child(resp, "FreeBusyView/WorkingHours");
217 g_free(cal->working_hours_xml_str);
218 cal->working_hours_xml_str = sipe_xml_stringify(node);
219 SIPE_DEBUG_INFO("sipe_ews_process_avail_response: cal->working_hours_xml_str:\n%s",
220 cal->working_hours_xml_str ? cal->working_hours_xml_str : "");
222 sipe_cal_events_free(cal->cal_events);
223 cal->cal_events = NULL;
224 /* CalendarEvents */
225 for (node = sipe_xml_child(resp, "FreeBusyView/CalendarEventArray/CalendarEvent");
226 node;
227 node = sipe_xml_twin(node))
229 char *tmp;
231 <CalendarEvent>
232 <StartTime>2009-12-07T13:30:00</StartTime>
233 <EndTime>2009-12-07T14:30:00</EndTime>
234 <BusyType>Busy</BusyType>
235 <CalendarEventDetails>
236 <ID>0000000...</ID>
237 <Subject>Lunch</Subject>
238 <Location>Cafe</Location>
239 <IsMeeting>false</IsMeeting>
240 <IsRecurring>true</IsRecurring>
241 <IsException>false</IsException>
242 <IsReminderSet>true</IsReminderSet>
243 <IsPrivate>false</IsPrivate>
244 </CalendarEventDetails>
245 </CalendarEvent>
247 struct sipe_cal_event *cal_event = g_new0(struct sipe_cal_event, 1);
248 cal->cal_events = g_slist_append(cal->cal_events, cal_event);
250 tmp = sipe_xml_data(sipe_xml_child(node, "StartTime"));
251 cal_event->start_time = sipe_utils_str_to_time(tmp);
252 g_free(tmp);
254 tmp = sipe_xml_data(sipe_xml_child(node, "EndTime"));
255 cal_event->end_time = sipe_utils_str_to_time(tmp);
256 g_free(tmp);
258 tmp = sipe_xml_data(sipe_xml_child(node, "BusyType"));
259 if (sipe_strequal("Free", tmp)) {
260 cal_event->cal_status = SIPE_CAL_FREE;
261 } else if (sipe_strequal("Tentative", tmp)) {
262 cal_event->cal_status = SIPE_CAL_TENTATIVE;
263 } else if (sipe_strequal("Busy", tmp)) {
264 cal_event->cal_status = SIPE_CAL_BUSY;
265 } else if (sipe_strequal("OOF", tmp)) {
266 cal_event->cal_status = SIPE_CAL_OOF;
267 } else {
268 cal_event->cal_status = SIPE_CAL_NO_DATA;
270 g_free(tmp);
272 cal_event->subject = sipe_xml_data(sipe_xml_child(node, "CalendarEventDetails/Subject"));
273 cal_event->location = sipe_xml_data(sipe_xml_child(node, "CalendarEventDetails/Location"));
275 tmp = sipe_xml_data(sipe_xml_child(node, "CalendarEventDetails/IsMeeting"));
276 cal_event->is_meeting = tmp ? sipe_strequal(tmp, "true") : TRUE;
277 g_free(tmp);
280 sipe_xml_free(xml);
282 cal->state = SIPE_EWS_STATE_AVAILABILITY_SUCCESS;
283 sipe_ews_run_state_machine(cal);
285 } else {
286 if (return_code < 0) {
287 cal->http_conn = NULL;
289 cal->state = SIPE_EWS_STATE_AVAILABILITY_FAILURE;
290 sipe_ews_run_state_machine(cal);
294 static void
295 sipe_ews_process_oof_response(int return_code,
296 const char *body,
297 SIPE_UNUSED_PARAMETER const char *content_type,
298 HttpConn *conn,
299 void *data)
301 struct sipe_calendar *cal = data;
303 SIPE_DEBUG_INFO_NOFORMAT("sipe_ews_process_oof_response: cb started.");
305 http_conn_set_close(conn);
306 cal->http_conn = NULL;
308 if (return_code == 200 && body) {
309 char *old_note;
310 const sipe_xml *resp;
311 const sipe_xml *xn_duration;
312 /** ref: [MS-OXWOOF] */
313 sipe_xml *xml = sipe_xml_parse(body, strlen(body));
314 /* Envelope/Body/GetUserOofSettingsResponse/ResponseMessage@ResponseClass="Success"
315 * Envelope/Body/GetUserOofSettingsResponse/OofSettings/OofState=Enabled
316 * Envelope/Body/GetUserOofSettingsResponse/OofSettings/Duration/StartTime
317 * Envelope/Body/GetUserOofSettingsResponse/OofSettings/Duration/EndTime
318 * Envelope/Body/GetUserOofSettingsResponse/OofSettings/InternalReply/Message
320 resp = sipe_xml_child(xml, "Body/GetUserOofSettingsResponse");
321 if (!resp) return; /* rather soap:Fault */
322 if (!sipe_strequal(sipe_xml_attribute(sipe_xml_child(resp, "ResponseMessage"), "ResponseClass"), "Success")) {
323 return; /* Error response */
326 g_free(cal->oof_state);
327 cal->oof_state = sipe_xml_data(sipe_xml_child(resp, "OofSettings/OofState"));
329 old_note = cal->oof_note;
330 cal->oof_note = NULL;
331 if (!sipe_strequal(cal->oof_state, "Disabled")) {
332 char *tmp = sipe_xml_data(
333 sipe_xml_child(resp, "OofSettings/InternalReply/Message"));
334 char *html;
336 /* UTF-8 encoded BOM (0xEF 0xBB 0xBF) as a signature to mark the beginning of a UTF-8 file */
337 if (g_str_has_prefix(tmp, "\xEF\xBB\xBF")) {
338 html = g_strdup(tmp+3);
339 } else {
340 html = g_strdup(tmp);
342 g_free(tmp);
343 tmp = g_strstrip(sipe_backend_markup_strip_html(html));
344 g_free(html);
345 cal->oof_note = g_markup_escape_text(tmp, -1);
346 g_free(tmp);
349 if (sipe_strequal(cal->oof_state, "Scheduled")
350 && (xn_duration = sipe_xml_child(resp, "OofSettings/Duration")))
352 char *tmp = sipe_xml_data(sipe_xml_child(xn_duration, "StartTime"));
353 cal->oof_start = sipe_utils_str_to_time(tmp);
354 g_free(tmp);
356 tmp = sipe_xml_data(sipe_xml_child(xn_duration, "EndTime"));
357 cal->oof_end = sipe_utils_str_to_time(tmp);
358 g_free(tmp);
361 if (!sipe_strequal(old_note, cal->oof_note)) { /* oof note changed */
362 cal->updated = time(NULL);
363 cal->published = FALSE;
365 g_free(old_note);
367 sipe_xml_free(xml);
369 cal->state = SIPE_EWS_STATE_OOF_SUCCESS;
370 sipe_ews_run_state_machine(cal);
372 } else {
373 if (return_code < 0) {
374 cal->http_conn = NULL;
376 cal->state = SIPE_EWS_STATE_OOF_FAILURE;
377 sipe_ews_run_state_machine(cal);
381 static void
382 sipe_ews_process_autodiscover(int return_code,
383 const char *body,
384 SIPE_UNUSED_PARAMETER const char *content_type,
385 HttpConn *conn,
386 void *data)
388 struct sipe_calendar *cal = data;
390 SIPE_DEBUG_INFO_NOFORMAT("sipe_ews_process_autodiscover: cb started.");
392 http_conn_set_close(conn);
393 cal->http_conn = NULL;
395 if (return_code == 200 && body) {
396 const sipe_xml *node;
397 /** ref: [MS-OXDSCLI] */
398 sipe_xml *xml = sipe_xml_parse(body, strlen(body));
400 /* Autodiscover/Response/User/LegacyDN (trim()) */
401 cal->legacy_dn = sipe_xml_data(sipe_xml_child(xml, "Response/User/LegacyDN"));
402 cal->legacy_dn = cal->legacy_dn ? g_strstrip(cal->legacy_dn) : NULL;
404 /* Protocols */
405 for (node = sipe_xml_child(xml, "Response/Account/Protocol");
406 node;
407 node = sipe_xml_twin(node))
409 char *type = sipe_xml_data(sipe_xml_child(node, "Type"));
410 if (sipe_strequal("EXCH", type)) {
411 cal->as_url = sipe_xml_data(sipe_xml_child(node, "ASUrl"));
412 cal->oof_url = sipe_xml_data(sipe_xml_child(node, "OOFUrl"));
413 cal->oab_url = sipe_xml_data(sipe_xml_child(node, "OABUrl"));
415 SIPE_DEBUG_INFO("sipe_ews_process_autodiscover:as_url %s",
416 cal->as_url ? cal->as_url : "");
417 SIPE_DEBUG_INFO("sipe_ews_process_autodiscover:oof_url %s",
418 cal->oof_url ? cal->oof_url : "");
419 SIPE_DEBUG_INFO("sipe_ews_process_autodiscover:oab_url %s",
420 cal->oab_url ? cal->oab_url : "");
422 g_free(type);
423 break;
424 } else {
425 g_free(type);
426 continue;
430 sipe_xml_free(xml);
432 cal->state = SIPE_EWS_STATE_AUTODISCOVER_SUCCESS;
433 sipe_ews_run_state_machine(cal);
435 } else {
436 if (return_code < 0) {
437 cal->http_conn = NULL;
439 switch (cal->auto_disco_method) {
440 case 1:
441 cal->state = SIPE_EWS_STATE_AUTODISCOVER_1_FAILURE; break;
442 case 2:
443 cal->state = SIPE_EWS_STATE_AUTODISCOVER_2_FAILURE; break;
445 sipe_ews_run_state_machine(cal);
449 static void
450 sipe_ews_do_autodiscover(struct sipe_calendar *cal,
451 const char* autodiscover_url)
453 char *body;
455 SIPE_DEBUG_INFO("sipe_ews_do_autodiscover: going autodiscover url=%s", autodiscover_url ? autodiscover_url : "");
457 body = g_strdup_printf(SIPE_EWS_AUTODISCOVER_REQUEST, cal->email);
458 cal->http_conn = http_conn_create(
459 cal->sip->public,
460 NULL, /* HttpSession */
461 HTTP_CONN_POST,
462 HTTP_CONN_SSL,
463 HTTP_CONN_ALLOW_REDIRECT,
464 autodiscover_url,
465 body,
466 "text/xml",
467 cal->auth,
468 sipe_ews_process_autodiscover,
469 cal);
470 g_free(body);
473 static void
474 sipe_ews_do_avail_request(struct sipe_calendar *cal)
476 if (cal->as_url) {
477 char *body;
478 time_t end;
479 time_t now = time(NULL);
480 char *start_str;
481 char *end_str;
482 struct tm *now_tm;
484 SIPE_DEBUG_INFO_NOFORMAT("sipe_ews_do_avail_request: going Availability req.");
486 now_tm = gmtime(&now);
487 /* start -1 day, 00:00:00 */
488 now_tm->tm_sec = 0;
489 now_tm->tm_min = 0;
490 now_tm->tm_hour = 0;
491 cal->fb_start = sipe_mktime_tz(now_tm, "UTC");
492 cal->fb_start -= 24*60*60;
493 /* end = start + 4 days - 1 sec */
494 end = cal->fb_start + SIPE_FREE_BUSY_PERIOD_SEC - 1;
496 start_str = sipe_utils_time_to_str(cal->fb_start);
497 end_str = sipe_utils_time_to_str(end);
499 body = g_strdup_printf(SIPE_EWS_USER_AVAILABILITY_REQUEST, cal->email, start_str, end_str);
500 cal->http_conn = http_conn_create(
501 cal->sip->public,
502 NULL, /* HttpSession */
503 HTTP_CONN_POST,
504 HTTP_CONN_SSL,
505 HTTP_CONN_ALLOW_REDIRECT,
506 cal->as_url,
507 body,
508 "text/xml; charset=UTF-8",
509 cal->auth,
510 sipe_ews_process_avail_response,
511 cal);
512 g_free(body);
513 g_free(start_str);
514 g_free(end_str);
518 static void
519 sipe_ews_do_oof_request(struct sipe_calendar *cal)
521 if (cal->oof_url) {
522 char *body;
523 const char *content_type = "text/xml; charset=UTF-8";
525 SIPE_DEBUG_INFO_NOFORMAT("sipe_ews_do_oof_request: going OOF req.");
527 body = g_strdup_printf(SIPE_EWS_USER_OOF_SETTINGS_REQUEST, cal->email);
528 if (!cal->http_conn || http_conn_is_closed(cal->http_conn)) {
529 cal->http_conn = http_conn_create(cal->sip->public,
530 NULL, /* HttpSession */
531 HTTP_CONN_POST,
532 HTTP_CONN_SSL,
533 HTTP_CONN_ALLOW_REDIRECT,
534 cal->oof_url,
535 body,
536 content_type,
537 cal->auth,
538 sipe_ews_process_oof_response,
539 cal);
540 } else {
541 http_conn_send(cal->http_conn,
542 HTTP_CONN_POST,
543 cal->oof_url,
544 body,
545 content_type,
546 sipe_ews_process_oof_response,
547 cal);
549 g_free(body);
553 static void
554 sipe_ews_run_state_machine(struct sipe_calendar *cal)
556 switch (cal->state) {
557 case SIPE_EWS_STATE_NONE:
559 char *maildomain = strstr(cal->email, "@") + 1;
560 char *autodisc_url = g_strdup_printf("https://Autodiscover.%s/Autodiscover/Autodiscover.xml", maildomain);
562 cal->auto_disco_method = 1;
564 sipe_ews_do_autodiscover(cal, autodisc_url);
566 g_free(autodisc_url);
567 break;
569 case SIPE_EWS_STATE_AUTODISCOVER_1_FAILURE:
571 char *maildomain = strstr(cal->email, "@") + 1;
572 char *autodisc_url = g_strdup_printf("https://%s/Autodiscover/Autodiscover.xml", maildomain);
574 cal->auto_disco_method = 2;
576 sipe_ews_do_autodiscover(cal, autodisc_url);
578 g_free(autodisc_url);
579 break;
581 case SIPE_EWS_STATE_AUTODISCOVER_2_FAILURE:
582 case SIPE_EWS_STATE_AVAILABILITY_FAILURE:
583 case SIPE_EWS_STATE_OOF_FAILURE:
584 cal->is_ews_disabled = TRUE;
585 break;
586 case SIPE_EWS_STATE_AUTODISCOVER_SUCCESS:
587 sipe_ews_do_avail_request(cal);
588 break;
589 case SIPE_EWS_STATE_AVAILABILITY_SUCCESS:
590 sipe_ews_do_oof_request(cal);
591 break;
592 case SIPE_EWS_STATE_OOF_SUCCESS:
593 cal->state = SIPE_EWS_STATE_AUTODISCOVER_SUCCESS;
594 cal->is_updated = TRUE;
595 if (cal->sip->ocs2007) {
596 /* sipe.h */
597 publish_calendar_status_self(cal->sip->private,
598 NULL);
599 } else {
600 /* sipe.h */
601 send_presence_soap(cal->sip, TRUE);
603 break;
607 void
608 sipe_ews_update_calendar(struct sipe_account_data *sip)
610 //char *autodisc_srv = g_strdup_printf("_autodiscover._tcp.%s", maildomain);
611 gboolean has_url;
613 SIPE_DEBUG_INFO_NOFORMAT("sipe_ews_update_calendar: started.");
615 if (sipe_cal_calendar_init(sip, &has_url)) {
616 if (has_url) {
617 sip->cal->state = SIPE_EWS_STATE_AUTODISCOVER_SUCCESS;
621 if (sip->cal->is_ews_disabled) {
622 SIPE_DEBUG_INFO_NOFORMAT("sipe_ews_update_calendar: disabled, exiting.");
623 return;
626 sipe_ews_run_state_machine(sip->cal);
628 SIPE_DEBUG_INFO_NOFORMAT("sipe_ews_update_calendar: finished.");
634 Local Variables:
635 mode: c
636 c-file-style: "bsd"
637 indent-tabs-mode: t
638 tab-width: 8
639 End: