cal: don't crash on HTTP request failure
[siplcs.git] / src / core / sipe-ews.c
blob9fa91ad3504e3fef4d01afdad8538ac5ab2403ea
1 /**
2 * @file sipe-ews.c
4 * pidgin-sipe
6 * Copyright (C) 2010-2013 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 "sipe-backend.h"
53 #include "sipe-common.h"
54 #include "sipe-cal.h"
55 #include "sipe-core.h"
56 #include "sipe-core-private.h"
57 #include "sipe-ews.h"
58 #include "sipe-http.h"
59 #include "sipe-utils.h"
60 #include "sipe-xml.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_AUTODISCOVER_3_FAILURE -3
153 #define SIPE_EWS_STATE_AVAILABILITY_SUCCESS 4
154 #define SIPE_EWS_STATE_AVAILABILITY_FAILURE -4
155 #define SIPE_EWS_STATE_OOF_SUCCESS 5
156 #define SIPE_EWS_STATE_OOF_FAILURE -5
158 char *
159 sipe_ews_get_oof_note(struct sipe_calendar *cal)
161 time_t now = time(NULL);
163 if (!cal || !cal->oof_state) return NULL;
165 if (sipe_strequal(cal->oof_state, "Enabled") ||
166 (sipe_strequal(cal->oof_state, "Scheduled") && now >= cal->oof_start && now <= cal->oof_end))
168 return cal->oof_note;
170 else
172 return NULL;
176 static void
177 sipe_ews_run_state_machine(struct sipe_calendar *cal);
179 static void sipe_ews_process_avail_response(SIPE_UNUSED_PARAMETER struct sipe_core_private *sipe_private,
180 guint status,
181 SIPE_UNUSED_PARAMETER GSList *headers,
182 const gchar *body,
183 gpointer data)
185 struct sipe_calendar *cal = data;
187 SIPE_DEBUG_INFO_NOFORMAT("sipe_ews_process_avail_response: cb started.");
189 cal->request = NULL;
191 if ((status == SIPE_HTTP_STATUS_OK) && body) {
192 const sipe_xml *node;
193 const sipe_xml *resp;
194 /** ref: [MS-OXWAVLS] */
195 sipe_xml *xml = sipe_xml_parse(body, strlen(body));
197 Envelope/Body/GetUserAvailabilityResponse/FreeBusyResponseArray/FreeBusyResponse/ResponseMessage@ResponseClass="Success"
198 Envelope/Body/GetUserAvailabilityResponse/FreeBusyResponseArray/FreeBusyResponse/FreeBusyView/MergedFreeBusy
199 Envelope/Body/GetUserAvailabilityResponse/FreeBusyResponseArray/FreeBusyResponse/FreeBusyView/CalendarEventArray/CalendarEvent
200 Envelope/Body/GetUserAvailabilityResponse/FreeBusyResponseArray/FreeBusyResponse/FreeBusyView/WorkingHours
202 resp = sipe_xml_child(xml, "Body/GetUserAvailabilityResponse/FreeBusyResponseArray/FreeBusyResponse");
203 if (!resp) return; /* rather soap:Fault */
204 if (!sipe_strequal(sipe_xml_attribute(sipe_xml_child(resp, "ResponseMessage"), "ResponseClass"), "Success")) {
205 return; /* Error response */
208 /* MergedFreeBusy */
209 g_free(cal->free_busy);
210 cal->free_busy = sipe_xml_data(sipe_xml_child(resp, "FreeBusyView/MergedFreeBusy"));
212 /* WorkingHours */
213 node = sipe_xml_child(resp, "FreeBusyView/WorkingHours");
214 g_free(cal->working_hours_xml_str);
215 cal->working_hours_xml_str = sipe_xml_stringify(node);
216 SIPE_DEBUG_INFO("sipe_ews_process_avail_response: cal->working_hours_xml_str:\n%s",
217 cal->working_hours_xml_str ? cal->working_hours_xml_str : "");
219 sipe_cal_events_free(cal->cal_events);
220 cal->cal_events = NULL;
221 /* CalendarEvents */
222 for (node = sipe_xml_child(resp, "FreeBusyView/CalendarEventArray/CalendarEvent");
223 node;
224 node = sipe_xml_twin(node))
226 char *tmp;
228 <CalendarEvent>
229 <StartTime>2009-12-07T13:30:00</StartTime>
230 <EndTime>2009-12-07T14:30:00</EndTime>
231 <BusyType>Busy</BusyType>
232 <CalendarEventDetails>
233 <ID>0000000...</ID>
234 <Subject>Lunch</Subject>
235 <Location>Cafe</Location>
236 <IsMeeting>false</IsMeeting>
237 <IsRecurring>true</IsRecurring>
238 <IsException>false</IsException>
239 <IsReminderSet>true</IsReminderSet>
240 <IsPrivate>false</IsPrivate>
241 </CalendarEventDetails>
242 </CalendarEvent>
244 struct sipe_cal_event *cal_event = g_new0(struct sipe_cal_event, 1);
245 cal->cal_events = g_slist_append(cal->cal_events, cal_event);
247 tmp = sipe_xml_data(sipe_xml_child(node, "StartTime"));
248 cal_event->start_time = sipe_utils_str_to_time(tmp);
249 g_free(tmp);
251 tmp = sipe_xml_data(sipe_xml_child(node, "EndTime"));
252 cal_event->end_time = sipe_utils_str_to_time(tmp);
253 g_free(tmp);
255 tmp = sipe_xml_data(sipe_xml_child(node, "BusyType"));
256 if (sipe_strequal("Free", tmp)) {
257 cal_event->cal_status = SIPE_CAL_FREE;
258 } else if (sipe_strequal("Tentative", tmp)) {
259 cal_event->cal_status = SIPE_CAL_TENTATIVE;
260 } else if (sipe_strequal("Busy", tmp)) {
261 cal_event->cal_status = SIPE_CAL_BUSY;
262 } else if (sipe_strequal("OOF", tmp)) {
263 cal_event->cal_status = SIPE_CAL_OOF;
264 } else {
265 cal_event->cal_status = SIPE_CAL_NO_DATA;
267 g_free(tmp);
269 cal_event->subject = sipe_xml_data(sipe_xml_child(node, "CalendarEventDetails/Subject"));
270 cal_event->location = sipe_xml_data(sipe_xml_child(node, "CalendarEventDetails/Location"));
272 tmp = sipe_xml_data(sipe_xml_child(node, "CalendarEventDetails/IsMeeting"));
273 cal_event->is_meeting = tmp ? sipe_strequal(tmp, "true") : TRUE;
274 g_free(tmp);
277 sipe_xml_free(xml);
279 cal->state = SIPE_EWS_STATE_AVAILABILITY_SUCCESS;
280 sipe_ews_run_state_machine(cal);
282 } else {
283 cal->state = SIPE_EWS_STATE_AVAILABILITY_FAILURE;
284 sipe_ews_run_state_machine(cal);
288 static void sipe_ews_process_oof_response(SIPE_UNUSED_PARAMETER struct sipe_core_private *sipe_private,
289 guint status,
290 SIPE_UNUSED_PARAMETER GSList *headers,
291 const gchar *body,
292 gpointer data)
294 struct sipe_calendar *cal = data;
296 SIPE_DEBUG_INFO_NOFORMAT("sipe_ews_process_oof_response: cb started.");
298 cal->request = NULL;
300 if ((status == SIPE_HTTP_STATUS_OK) && body) {
301 char *old_note;
302 const sipe_xml *resp;
303 const sipe_xml *xn_duration;
304 /** ref: [MS-OXWOOF] */
305 sipe_xml *xml = sipe_xml_parse(body, strlen(body));
306 /* Envelope/Body/GetUserOofSettingsResponse/ResponseMessage@ResponseClass="Success"
307 * Envelope/Body/GetUserOofSettingsResponse/OofSettings/OofState=Enabled
308 * Envelope/Body/GetUserOofSettingsResponse/OofSettings/Duration/StartTime
309 * Envelope/Body/GetUserOofSettingsResponse/OofSettings/Duration/EndTime
310 * Envelope/Body/GetUserOofSettingsResponse/OofSettings/InternalReply/Message
312 resp = sipe_xml_child(xml, "Body/GetUserOofSettingsResponse");
313 if (!resp) return; /* rather soap:Fault */
314 if (!sipe_strequal(sipe_xml_attribute(sipe_xml_child(resp, "ResponseMessage"), "ResponseClass"), "Success")) {
315 return; /* Error response */
318 g_free(cal->oof_state);
319 cal->oof_state = sipe_xml_data(sipe_xml_child(resp, "OofSettings/OofState"));
321 old_note = cal->oof_note;
322 cal->oof_note = NULL;
323 if (!sipe_strequal(cal->oof_state, "Disabled")) {
324 char *tmp = sipe_xml_data(
325 sipe_xml_child(resp, "OofSettings/InternalReply/Message"));
326 char *html;
328 /* UTF-8 encoded BOM (0xEF 0xBB 0xBF) as a signature to mark the beginning of a UTF-8 file */
329 if (g_str_has_prefix(tmp, "\xEF\xBB\xBF")) {
330 html = g_strdup(tmp+3);
331 } else {
332 html = g_strdup(tmp);
334 g_free(tmp);
335 tmp = g_strstrip(sipe_backend_markup_strip_html(html));
336 g_free(html);
337 cal->oof_note = g_markup_escape_text(tmp, -1);
338 g_free(tmp);
341 if (sipe_strequal(cal->oof_state, "Scheduled")
342 && (xn_duration = sipe_xml_child(resp, "OofSettings/Duration")))
344 char *tmp = sipe_xml_data(sipe_xml_child(xn_duration, "StartTime"));
345 cal->oof_start = sipe_utils_str_to_time(tmp);
346 g_free(tmp);
348 tmp = sipe_xml_data(sipe_xml_child(xn_duration, "EndTime"));
349 cal->oof_end = sipe_utils_str_to_time(tmp);
350 g_free(tmp);
353 if (!sipe_strequal(old_note, cal->oof_note)) { /* oof note changed */
354 cal->updated = time(NULL);
355 cal->published = FALSE;
357 g_free(old_note);
359 sipe_xml_free(xml);
361 cal->state = SIPE_EWS_STATE_OOF_SUCCESS;
362 sipe_ews_run_state_machine(cal);
364 } else {
365 cal->state = SIPE_EWS_STATE_OOF_FAILURE;
366 sipe_ews_run_state_machine(cal);
370 static void sipe_ews_process_autodiscover(SIPE_UNUSED_PARAMETER struct sipe_core_private *sipe_private,
371 guint status,
372 SIPE_UNUSED_PARAMETER GSList *headers,
373 const gchar *body,
374 gpointer data)
376 struct sipe_calendar *cal = data;
378 SIPE_DEBUG_INFO_NOFORMAT("sipe_ews_process_autodiscover: cb started.");
380 cal->request = NULL;
382 if ((status == SIPE_HTTP_STATUS_OK) && body) {
383 const sipe_xml *node;
384 /** ref: [MS-OXDSCLI] */
385 sipe_xml *xml = sipe_xml_parse(body, strlen(body));
387 /* Autodiscover/Response/User/LegacyDN (trim()) */
388 cal->legacy_dn = sipe_xml_data(sipe_xml_child(xml, "Response/User/LegacyDN"));
389 cal->legacy_dn = cal->legacy_dn ? g_strstrip(cal->legacy_dn) : NULL;
391 /* Protocols */
392 for (node = sipe_xml_child(xml, "Response/Account/Protocol");
393 node;
394 node = sipe_xml_twin(node))
396 char *type = sipe_xml_data(sipe_xml_child(node, "Type"));
397 if (sipe_strequal("EXCH", type)) {
398 cal->as_url = sipe_xml_data(sipe_xml_child(node, "ASUrl"));
399 cal->oof_url = sipe_xml_data(sipe_xml_child(node, "OOFUrl"));
400 cal->oab_url = sipe_xml_data(sipe_xml_child(node, "OABUrl"));
402 SIPE_DEBUG_INFO("sipe_ews_process_autodiscover:as_url %s",
403 cal->as_url ? cal->as_url : "");
404 SIPE_DEBUG_INFO("sipe_ews_process_autodiscover:oof_url %s",
405 cal->oof_url ? cal->oof_url : "");
406 SIPE_DEBUG_INFO("sipe_ews_process_autodiscover:oab_url %s",
407 cal->oab_url ? cal->oab_url : "");
409 g_free(type);
410 break;
411 } else {
412 g_free(type);
413 continue;
417 sipe_xml_free(xml);
419 cal->state = SIPE_EWS_STATE_AUTODISCOVER_SUCCESS;
420 sipe_ews_run_state_machine(cal);
422 } else if ((status == SIPE_HTTP_STATUS_CLIENT_FORBIDDEN) && cal->retry) {
424 * Authentication succeeded but we still weren't allowed to view the page.
425 * At least at our work place this error is temporary, i.e. the next access
426 * with the exact same authentication succeeds. Simply retry once.
428 SIPE_DEBUG_INFO_NOFORMAT("sipe_ews_process_autodiscover: failed, let's retry once.");
429 sipe_ews_run_state_machine(cal);
430 cal->retry = FALSE;
432 } else {
433 switch (cal->auto_disco_method) {
434 case 1:
435 cal->state = SIPE_EWS_STATE_AUTODISCOVER_1_FAILURE; break;
436 case 2:
437 cal->state = SIPE_EWS_STATE_AUTODISCOVER_2_FAILURE; break;
438 case 3:
439 cal->state = SIPE_EWS_STATE_AUTODISCOVER_3_FAILURE; break;
441 sipe_ews_run_state_machine(cal);
445 static void sipe_ews_send_http_request(struct sipe_calendar *cal)
447 if (cal->request) {
448 sipe_cal_http_authentication(cal);
449 sipe_http_request_allow_redirect(cal->request);
450 sipe_http_request_ready(cal->request);
454 static void sipe_ews_do_autodiscover(struct sipe_calendar *cal,
455 const gchar *autodiscover_url)
457 gchar *body;
459 SIPE_DEBUG_INFO("sipe_ews_do_autodiscover: going autodiscover url=%s",
460 autodiscover_url ? autodiscover_url : "");
462 body = g_strdup_printf(SIPE_EWS_AUTODISCOVER_REQUEST, cal->email);
463 cal->request = sipe_http_request_post(cal->sipe_private,
464 autodiscover_url,
465 NULL,
466 body,
467 "text/xml",
468 sipe_ews_process_autodiscover,
469 cal);
470 g_free(body);
472 sipe_ews_send_http_request(cal);
475 static void sipe_ews_do_avail_request(struct sipe_calendar *cal)
477 if (cal->as_url) {
478 char *body;
479 time_t end;
480 time_t now = time(NULL);
481 char *start_str;
482 char *end_str;
483 struct tm *now_tm;
485 SIPE_DEBUG_INFO_NOFORMAT("sipe_ews_do_avail_request: going Availability req.");
487 now_tm = gmtime(&now);
488 /* start -1 day, 00:00:00 */
489 now_tm->tm_sec = 0;
490 now_tm->tm_min = 0;
491 now_tm->tm_hour = 0;
492 cal->fb_start = sipe_mktime_tz(now_tm, "UTC");
493 cal->fb_start -= 24*60*60;
494 /* end = start + 4 days - 1 sec */
495 end = cal->fb_start + SIPE_FREE_BUSY_PERIOD_SEC - 1;
497 start_str = sipe_utils_time_to_str(cal->fb_start);
498 end_str = sipe_utils_time_to_str(end);
500 body = g_strdup_printf(SIPE_EWS_USER_AVAILABILITY_REQUEST, cal->email, start_str, end_str);
501 cal->request = sipe_http_request_post(cal->sipe_private,
502 cal->as_url,
503 NULL,
504 body,
505 "text/xml; charset=UTF-8",
506 sipe_ews_process_avail_response,
507 cal);
508 g_free(body);
509 g_free(start_str);
510 g_free(end_str);
512 sipe_ews_send_http_request(cal);
516 static void sipe_ews_do_oof_request(struct sipe_calendar *cal)
518 if (cal->oof_url) {
519 char *body;
521 SIPE_DEBUG_INFO_NOFORMAT("sipe_ews_do_oof_request: going OOF req.");
523 body = g_strdup_printf(SIPE_EWS_USER_OOF_SETTINGS_REQUEST, cal->email);
524 cal->request = sipe_http_request_post(cal->sipe_private,
525 cal->as_url,
526 NULL,
527 body,
528 "text/xml; charset=UTF-8",
529 sipe_ews_process_oof_response,
530 cal);
531 g_free(body);
533 sipe_ews_send_http_request(cal);
537 static void
538 sipe_ews_run_state_machine(struct sipe_calendar *cal)
540 switch (cal->state) {
541 case SIPE_EWS_STATE_NONE:
543 char *maildomain = strstr(cal->email, "@") + 1;
544 char *autodisc_url = g_strdup_printf("https://Autodiscover.%s/Autodiscover/Autodiscover.xml", maildomain);
546 cal->retry = TRUE;
547 cal->auto_disco_method = 1;
549 sipe_ews_do_autodiscover(cal, autodisc_url);
551 g_free(autodisc_url);
552 break;
554 case SIPE_EWS_STATE_AUTODISCOVER_1_FAILURE:
556 char *maildomain = strstr(cal->email, "@") + 1;
557 char *autodisc_url = g_strdup_printf("http://Autodiscover.%s/Autodiscover/Autodiscover.xml", maildomain);
559 cal->retry = TRUE;
560 cal->auto_disco_method = 2;
562 sipe_ews_do_autodiscover(cal, autodisc_url);
564 g_free(autodisc_url);
565 break;
567 case SIPE_EWS_STATE_AUTODISCOVER_2_FAILURE:
569 char *maildomain = strstr(cal->email, "@") + 1;
570 char *autodisc_url = g_strdup_printf("https://%s/Autodiscover/Autodiscover.xml", maildomain);
572 cal->retry = TRUE;
573 cal->auto_disco_method = 3;
575 sipe_ews_do_autodiscover(cal, autodisc_url);
577 g_free(autodisc_url);
578 break;
580 case SIPE_EWS_STATE_AUTODISCOVER_3_FAILURE:
581 case SIPE_EWS_STATE_AVAILABILITY_FAILURE:
582 case SIPE_EWS_STATE_OOF_FAILURE:
583 cal->is_ews_disabled = TRUE;
584 break;
585 case SIPE_EWS_STATE_AUTODISCOVER_SUCCESS:
586 sipe_ews_do_avail_request(cal);
587 break;
588 case SIPE_EWS_STATE_AVAILABILITY_SUCCESS:
589 sipe_ews_do_oof_request(cal);
590 break;
591 case SIPE_EWS_STATE_OOF_SUCCESS:
593 struct sipe_core_private *sipe_private = cal->sipe_private;
595 cal->state = SIPE_EWS_STATE_AUTODISCOVER_SUCCESS;
596 cal->is_updated = TRUE;
597 sipe_cal_presence_publish(sipe_private, TRUE);
598 break;
603 void
604 sipe_ews_update_calendar(struct sipe_core_private *sipe_private)
606 //char *autodisc_srv = g_strdup_printf("_autodiscover._tcp.%s", maildomain);
607 gboolean has_url;
609 SIPE_DEBUG_INFO_NOFORMAT("sipe_ews_update_calendar: started.");
611 if (sipe_cal_calendar_init(sipe_private, &has_url)) {
612 if (has_url) {
613 sipe_private->calendar->state = SIPE_EWS_STATE_AUTODISCOVER_SUCCESS;
617 if (sipe_private->calendar->is_ews_disabled) {
618 SIPE_DEBUG_INFO_NOFORMAT("sipe_ews_update_calendar: disabled, exiting.");
619 return;
622 sipe_ews_run_state_machine(sipe_private->calendar);
624 SIPE_DEBUG_INFO_NOFORMAT("sipe_ews_update_calendar: finished.");
630 Local Variables:
631 mode: c
632 c-file-style: "bsd"
633 indent-tabs-mode: t
634 tab-width: 8
635 End: