certificate: switch from Anon to WinNegotiate port
[siplcs.git] / src / core / sipe-ews.c
blob7be0843c272fc2e3ea73690ee0d35b6541257700
1 /**
2 * @file sipe-ews.c
4 * pidgin-sipe
6 * Copyright (C) 2010-11 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-core-private.h"
58 #include "sipe-ews.h"
59 #include "sipe-utils.h"
60 #include "sipe-xml.h"
61 #include "sipe.h"
63 /**
64 * Autodiscover request for Exchange Web Services
65 * @param email (%s) Ex.: alice@cosmo.local
67 #define SIPE_EWS_AUTODISCOVER_REQUEST \
68 "<?xml version=\"1.0\"?>"\
69 "<Autodiscover xmlns=\"http://schemas.microsoft.com/exchange/autodiscover/outlook/requestschema/2006\">"\
70 "<Request>"\
71 "<EMailAddress>%s</EMailAddress>"\
72 "<AcceptableResponseSchema>"\
73 "http://schemas.microsoft.com/exchange/autodiscover/outlook/responseschema/2006a"\
74 "</AcceptableResponseSchema>"\
75 "</Request>"\
76 "</Autodiscover>"
78 /**
79 * GetUserOofSettingsRequest SOAP request to Exchange Web Services
80 * to obtain our Out-of-office (OOF) information.
81 * @param email (%s) Ex.: alice@cosmo.local
83 #define SIPE_EWS_USER_OOF_SETTINGS_REQUEST \
84 "<?xml version=\"1.0\" encoding=\"utf-8\"?>"\
85 "<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/\">"\
86 "<soap:Body>"\
87 "<GetUserOofSettingsRequest xmlns=\"http://schemas.microsoft.com/exchange/services/2006/messages\">"\
88 "<Mailbox xmlns=\"http://schemas.microsoft.com/exchange/services/2006/types\">"\
89 "<Address>%s</Address>"\
90 "</Mailbox>"\
91 "</GetUserOofSettingsRequest>"\
92 "</soap:Body>"\
93 "</soap:Envelope>"
95 /**
96 * GetUserAvailabilityRequest SOAP request to Exchange Web Services
97 * to obtain our Availability (FreeBusy, WorkingHours, Meetings) information.
98 * @param email (%s) Ex.: alice@cosmo.local
99 * @param start_time (%s) Ex.: 2009-12-06T00:00:00
100 * @param end_time (%s) Ex.: 2009-12-09T23:59:59
102 #define SIPE_EWS_USER_AVAILABILITY_REQUEST \
103 "<?xml version=\"1.0\" encoding=\"utf-8\"?>"\
104 "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\""\
105 " xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\""\
106 " xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\""\
107 " xmlns:t=\"http://schemas.microsoft.com/exchange/services/2006/types\">"\
108 "<soap:Body>"\
109 "<GetUserAvailabilityRequest xmlns=\"http://schemas.microsoft.com/exchange/services/2006/messages\""\
110 " xmlns:t=\"http://schemas.microsoft.com/exchange/services/2006/types\">"\
111 "<t:TimeZone xmlns=\"http://schemas.microsoft.com/exchange/services/2006/types\">"\
112 "<Bias>0</Bias>"\
113 "<StandardTime>"\
114 "<Bias>0</Bias>"\
115 "<Time>00:00:00</Time>"\
116 "<DayOrder>0</DayOrder>"\
117 "<Month>0</Month>"\
118 "<DayOfWeek>Sunday</DayOfWeek>"\
119 "</StandardTime>"\
120 "<DaylightTime>"\
121 "<Bias>0</Bias>"\
122 "<Time>00:00:00</Time>"\
123 "<DayOrder>0</DayOrder>"\
124 "<Month>0</Month>"\
125 "<DayOfWeek>Sunday</DayOfWeek>"\
126 "</DaylightTime>"\
127 "</t:TimeZone>"\
128 "<MailboxDataArray>"\
129 "<t:MailboxData>"\
130 "<t:Email>"\
131 "<t:Address>%s</t:Address>"\
132 "</t:Email>"\
133 "<t:AttendeeType>Required</t:AttendeeType>"\
134 "<t:ExcludeConflicts>false</t:ExcludeConflicts>"\
135 "</t:MailboxData>"\
136 "</MailboxDataArray>"\
137 "<t:FreeBusyViewOptions>"\
138 "<t:TimeWindow>"\
139 "<t:StartTime>%s</t:StartTime>"\
140 "<t:EndTime>%s</t:EndTime>"\
141 "</t:TimeWindow>"\
142 "<t:MergedFreeBusyIntervalInMinutes>15</t:MergedFreeBusyIntervalInMinutes>"\
143 "<t:RequestedView>DetailedMerged</t:RequestedView>"\
144 "</t:FreeBusyViewOptions>"\
145 "</GetUserAvailabilityRequest>"\
146 "</soap:Body>"\
147 "</soap:Envelope>"
149 #define SIPE_EWS_STATE_NONE 0
150 #define SIPE_EWS_STATE_AUTODISCOVER_SUCCESS 1
151 #define SIPE_EWS_STATE_AUTODISCOVER_1_FAILURE -1
152 #define SIPE_EWS_STATE_AUTODISCOVER_2_FAILURE -2
153 #define SIPE_EWS_STATE_AVAILABILITY_SUCCESS 3
154 #define SIPE_EWS_STATE_AVAILABILITY_FAILURE -3
155 #define SIPE_EWS_STATE_OOF_SUCCESS 4
156 #define SIPE_EWS_STATE_OOF_FAILURE -4
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
180 sipe_ews_process_avail_response(int return_code,
181 const char *body,
182 SIPE_UNUSED_PARAMETER const char *content_type,
183 HttpConn *conn,
184 void *data)
186 struct sipe_calendar *cal = data;
188 SIPE_DEBUG_INFO_NOFORMAT("sipe_ews_process_avail_response: cb started.");
190 if(!sipe_strequal(cal->as_url, cal->oof_url)) { /* whether reuse conn */
191 http_conn_set_close(conn);
192 cal->http_conn = NULL;
195 if (return_code == 200 && body) {
196 const sipe_xml *node;
197 const sipe_xml *resp;
198 /** ref: [MS-OXWAVLS] */
199 sipe_xml *xml = sipe_xml_parse(body, strlen(body));
201 Envelope/Body/GetUserAvailabilityResponse/FreeBusyResponseArray/FreeBusyResponse/ResponseMessage@ResponseClass="Success"
202 Envelope/Body/GetUserAvailabilityResponse/FreeBusyResponseArray/FreeBusyResponse/FreeBusyView/MergedFreeBusy
203 Envelope/Body/GetUserAvailabilityResponse/FreeBusyResponseArray/FreeBusyResponse/FreeBusyView/CalendarEventArray/CalendarEvent
204 Envelope/Body/GetUserAvailabilityResponse/FreeBusyResponseArray/FreeBusyResponse/FreeBusyView/WorkingHours
206 resp = sipe_xml_child(xml, "Body/GetUserAvailabilityResponse/FreeBusyResponseArray/FreeBusyResponse");
207 if (!resp) return; /* rather soap:Fault */
208 if (!sipe_strequal(sipe_xml_attribute(sipe_xml_child(resp, "ResponseMessage"), "ResponseClass"), "Success")) {
209 return; /* Error response */
212 /* MergedFreeBusy */
213 g_free(cal->free_busy);
214 cal->free_busy = sipe_xml_data(sipe_xml_child(resp, "FreeBusyView/MergedFreeBusy"));
216 /* WorkingHours */
217 node = sipe_xml_child(resp, "FreeBusyView/WorkingHours");
218 g_free(cal->working_hours_xml_str);
219 cal->working_hours_xml_str = sipe_xml_stringify(node);
220 SIPE_DEBUG_INFO("sipe_ews_process_avail_response: cal->working_hours_xml_str:\n%s",
221 cal->working_hours_xml_str ? cal->working_hours_xml_str : "");
223 sipe_cal_events_free(cal->cal_events);
224 cal->cal_events = NULL;
225 /* CalendarEvents */
226 for (node = sipe_xml_child(resp, "FreeBusyView/CalendarEventArray/CalendarEvent");
227 node;
228 node = sipe_xml_twin(node))
230 char *tmp;
232 <CalendarEvent>
233 <StartTime>2009-12-07T13:30:00</StartTime>
234 <EndTime>2009-12-07T14:30:00</EndTime>
235 <BusyType>Busy</BusyType>
236 <CalendarEventDetails>
237 <ID>0000000...</ID>
238 <Subject>Lunch</Subject>
239 <Location>Cafe</Location>
240 <IsMeeting>false</IsMeeting>
241 <IsRecurring>true</IsRecurring>
242 <IsException>false</IsException>
243 <IsReminderSet>true</IsReminderSet>
244 <IsPrivate>false</IsPrivate>
245 </CalendarEventDetails>
246 </CalendarEvent>
248 struct sipe_cal_event *cal_event = g_new0(struct sipe_cal_event, 1);
249 cal->cal_events = g_slist_append(cal->cal_events, cal_event);
251 tmp = sipe_xml_data(sipe_xml_child(node, "StartTime"));
252 cal_event->start_time = sipe_utils_str_to_time(tmp);
253 g_free(tmp);
255 tmp = sipe_xml_data(sipe_xml_child(node, "EndTime"));
256 cal_event->end_time = sipe_utils_str_to_time(tmp);
257 g_free(tmp);
259 tmp = sipe_xml_data(sipe_xml_child(node, "BusyType"));
260 if (sipe_strequal("Free", tmp)) {
261 cal_event->cal_status = SIPE_CAL_FREE;
262 } else if (sipe_strequal("Tentative", tmp)) {
263 cal_event->cal_status = SIPE_CAL_TENTATIVE;
264 } else if (sipe_strequal("Busy", tmp)) {
265 cal_event->cal_status = SIPE_CAL_BUSY;
266 } else if (sipe_strequal("OOF", tmp)) {
267 cal_event->cal_status = SIPE_CAL_OOF;
268 } else {
269 cal_event->cal_status = SIPE_CAL_NO_DATA;
271 g_free(tmp);
273 cal_event->subject = sipe_xml_data(sipe_xml_child(node, "CalendarEventDetails/Subject"));
274 cal_event->location = sipe_xml_data(sipe_xml_child(node, "CalendarEventDetails/Location"));
276 tmp = sipe_xml_data(sipe_xml_child(node, "CalendarEventDetails/IsMeeting"));
277 cal_event->is_meeting = tmp ? sipe_strequal(tmp, "true") : TRUE;
278 g_free(tmp);
281 sipe_xml_free(xml);
283 cal->state = SIPE_EWS_STATE_AVAILABILITY_SUCCESS;
284 sipe_ews_run_state_machine(cal);
286 } else {
287 if (return_code < 0) {
288 cal->http_conn = NULL;
290 cal->state = SIPE_EWS_STATE_AVAILABILITY_FAILURE;
291 sipe_ews_run_state_machine(cal);
295 static void
296 sipe_ews_process_oof_response(int return_code,
297 const char *body,
298 SIPE_UNUSED_PARAMETER const char *content_type,
299 HttpConn *conn,
300 void *data)
302 struct sipe_calendar *cal = data;
304 SIPE_DEBUG_INFO_NOFORMAT("sipe_ews_process_oof_response: cb started.");
306 http_conn_set_close(conn);
307 cal->http_conn = NULL;
309 if (return_code == 200 && body) {
310 char *old_note;
311 const sipe_xml *resp;
312 const sipe_xml *xn_duration;
313 /** ref: [MS-OXWOOF] */
314 sipe_xml *xml = sipe_xml_parse(body, strlen(body));
315 /* Envelope/Body/GetUserOofSettingsResponse/ResponseMessage@ResponseClass="Success"
316 * Envelope/Body/GetUserOofSettingsResponse/OofSettings/OofState=Enabled
317 * Envelope/Body/GetUserOofSettingsResponse/OofSettings/Duration/StartTime
318 * Envelope/Body/GetUserOofSettingsResponse/OofSettings/Duration/EndTime
319 * Envelope/Body/GetUserOofSettingsResponse/OofSettings/InternalReply/Message
321 resp = sipe_xml_child(xml, "Body/GetUserOofSettingsResponse");
322 if (!resp) return; /* rather soap:Fault */
323 if (!sipe_strequal(sipe_xml_attribute(sipe_xml_child(resp, "ResponseMessage"), "ResponseClass"), "Success")) {
324 return; /* Error response */
327 g_free(cal->oof_state);
328 cal->oof_state = sipe_xml_data(sipe_xml_child(resp, "OofSettings/OofState"));
330 old_note = cal->oof_note;
331 cal->oof_note = NULL;
332 if (!sipe_strequal(cal->oof_state, "Disabled")) {
333 char *tmp = sipe_xml_data(
334 sipe_xml_child(resp, "OofSettings/InternalReply/Message"));
335 char *html;
337 /* UTF-8 encoded BOM (0xEF 0xBB 0xBF) as a signature to mark the beginning of a UTF-8 file */
338 if (g_str_has_prefix(tmp, "\xEF\xBB\xBF")) {
339 html = g_strdup(tmp+3);
340 } else {
341 html = g_strdup(tmp);
343 g_free(tmp);
344 tmp = g_strstrip(sipe_backend_markup_strip_html(html));
345 g_free(html);
346 cal->oof_note = g_markup_escape_text(tmp, -1);
347 g_free(tmp);
350 if (sipe_strequal(cal->oof_state, "Scheduled")
351 && (xn_duration = sipe_xml_child(resp, "OofSettings/Duration")))
353 char *tmp = sipe_xml_data(sipe_xml_child(xn_duration, "StartTime"));
354 cal->oof_start = sipe_utils_str_to_time(tmp);
355 g_free(tmp);
357 tmp = sipe_xml_data(sipe_xml_child(xn_duration, "EndTime"));
358 cal->oof_end = sipe_utils_str_to_time(tmp);
359 g_free(tmp);
362 if (!sipe_strequal(old_note, cal->oof_note)) { /* oof note changed */
363 cal->updated = time(NULL);
364 cal->published = FALSE;
366 g_free(old_note);
368 sipe_xml_free(xml);
370 cal->state = SIPE_EWS_STATE_OOF_SUCCESS;
371 sipe_ews_run_state_machine(cal);
373 } else {
374 if (return_code < 0) {
375 cal->http_conn = NULL;
377 cal->state = SIPE_EWS_STATE_OOF_FAILURE;
378 sipe_ews_run_state_machine(cal);
382 static void
383 sipe_ews_process_autodiscover(int return_code,
384 const char *body,
385 SIPE_UNUSED_PARAMETER const char *content_type,
386 HttpConn *conn,
387 void *data)
389 struct sipe_calendar *cal = data;
391 SIPE_DEBUG_INFO_NOFORMAT("sipe_ews_process_autodiscover: cb started.");
393 http_conn_set_close(conn);
394 cal->http_conn = NULL;
396 if (return_code == 200 && body) {
397 const sipe_xml *node;
398 /** ref: [MS-OXDSCLI] */
399 sipe_xml *xml = sipe_xml_parse(body, strlen(body));
401 /* Autodiscover/Response/User/LegacyDN (trim()) */
402 cal->legacy_dn = sipe_xml_data(sipe_xml_child(xml, "Response/User/LegacyDN"));
403 cal->legacy_dn = cal->legacy_dn ? g_strstrip(cal->legacy_dn) : NULL;
405 /* Protocols */
406 for (node = sipe_xml_child(xml, "Response/Account/Protocol");
407 node;
408 node = sipe_xml_twin(node))
410 char *type = sipe_xml_data(sipe_xml_child(node, "Type"));
411 if (sipe_strequal("EXCH", type)) {
412 cal->as_url = sipe_xml_data(sipe_xml_child(node, "ASUrl"));
413 cal->oof_url = sipe_xml_data(sipe_xml_child(node, "OOFUrl"));
414 cal->oab_url = sipe_xml_data(sipe_xml_child(node, "OABUrl"));
416 SIPE_DEBUG_INFO("sipe_ews_process_autodiscover:as_url %s",
417 cal->as_url ? cal->as_url : "");
418 SIPE_DEBUG_INFO("sipe_ews_process_autodiscover:oof_url %s",
419 cal->oof_url ? cal->oof_url : "");
420 SIPE_DEBUG_INFO("sipe_ews_process_autodiscover:oab_url %s",
421 cal->oab_url ? cal->oab_url : "");
423 g_free(type);
424 break;
425 } else {
426 g_free(type);
427 continue;
431 sipe_xml_free(xml);
433 cal->state = SIPE_EWS_STATE_AUTODISCOVER_SUCCESS;
434 sipe_ews_run_state_machine(cal);
436 } else {
437 if (return_code < 0) {
438 cal->http_conn = NULL;
440 switch (cal->auto_disco_method) {
441 case 1:
442 cal->state = SIPE_EWS_STATE_AUTODISCOVER_1_FAILURE; break;
443 case 2:
444 cal->state = SIPE_EWS_STATE_AUTODISCOVER_2_FAILURE; break;
446 sipe_ews_run_state_machine(cal);
450 static void
451 sipe_ews_do_autodiscover(struct sipe_calendar *cal,
452 const char* autodiscover_url)
454 char *body;
456 SIPE_DEBUG_INFO("sipe_ews_do_autodiscover: going autodiscover url=%s", autodiscover_url ? autodiscover_url : "");
458 body = g_strdup_printf(SIPE_EWS_AUTODISCOVER_REQUEST, cal->email);
459 cal->http_conn = http_conn_create(
460 (struct sipe_core_public *) cal->sipe_private,
461 NULL, /* HttpSession */
462 HTTP_CONN_POST,
463 HTTP_CONN_SSL,
464 HTTP_CONN_ALLOW_REDIRECT,
465 autodiscover_url,
466 body,
467 "text/xml",
468 NULL,
469 cal->auth,
470 sipe_ews_process_autodiscover,
471 cal);
472 g_free(body);
475 static void
476 sipe_ews_do_avail_request(struct sipe_calendar *cal)
478 if (cal->as_url) {
479 char *body;
480 time_t end;
481 time_t now = time(NULL);
482 char *start_str;
483 char *end_str;
484 struct tm *now_tm;
486 SIPE_DEBUG_INFO_NOFORMAT("sipe_ews_do_avail_request: going Availability req.");
488 now_tm = gmtime(&now);
489 /* start -1 day, 00:00:00 */
490 now_tm->tm_sec = 0;
491 now_tm->tm_min = 0;
492 now_tm->tm_hour = 0;
493 cal->fb_start = sipe_mktime_tz(now_tm, "UTC");
494 cal->fb_start -= 24*60*60;
495 /* end = start + 4 days - 1 sec */
496 end = cal->fb_start + SIPE_FREE_BUSY_PERIOD_SEC - 1;
498 start_str = sipe_utils_time_to_str(cal->fb_start);
499 end_str = sipe_utils_time_to_str(end);
501 body = g_strdup_printf(SIPE_EWS_USER_AVAILABILITY_REQUEST, cal->email, start_str, end_str);
502 cal->http_conn = http_conn_create(
503 (struct sipe_core_public *) cal->sipe_private,
504 NULL, /* HttpSession */
505 HTTP_CONN_POST,
506 HTTP_CONN_SSL,
507 HTTP_CONN_ALLOW_REDIRECT,
508 cal->as_url,
509 body,
510 "text/xml; charset=UTF-8",
511 NULL,
512 cal->auth,
513 sipe_ews_process_avail_response,
514 cal);
515 g_free(body);
516 g_free(start_str);
517 g_free(end_str);
521 static void
522 sipe_ews_do_oof_request(struct sipe_calendar *cal)
524 if (cal->oof_url) {
525 char *body;
526 const char *content_type = "text/xml; charset=UTF-8";
528 SIPE_DEBUG_INFO_NOFORMAT("sipe_ews_do_oof_request: going OOF req.");
530 body = g_strdup_printf(SIPE_EWS_USER_OOF_SETTINGS_REQUEST, cal->email);
531 if (!cal->http_conn || http_conn_is_closed(cal->http_conn)) {
532 cal->http_conn = http_conn_create((struct sipe_core_public *)cal->sipe_private,
533 NULL, /* HttpSession */
534 HTTP_CONN_POST,
535 HTTP_CONN_SSL,
536 HTTP_CONN_ALLOW_REDIRECT,
537 cal->oof_url,
538 body,
539 content_type,
540 NULL,
541 cal->auth,
542 sipe_ews_process_oof_response,
543 cal);
544 } else {
545 http_conn_send(cal->http_conn,
546 HTTP_CONN_POST,
547 cal->oof_url,
548 body,
549 content_type,
550 sipe_ews_process_oof_response,
551 cal);
553 g_free(body);
557 static void
558 sipe_ews_run_state_machine(struct sipe_calendar *cal)
560 switch (cal->state) {
561 case SIPE_EWS_STATE_NONE:
563 char *maildomain = strstr(cal->email, "@") + 1;
564 char *autodisc_url = g_strdup_printf("https://Autodiscover.%s/Autodiscover/Autodiscover.xml", maildomain);
566 cal->auto_disco_method = 1;
568 sipe_ews_do_autodiscover(cal, autodisc_url);
570 g_free(autodisc_url);
571 break;
573 case SIPE_EWS_STATE_AUTODISCOVER_1_FAILURE:
575 char *maildomain = strstr(cal->email, "@") + 1;
576 char *autodisc_url = g_strdup_printf("https://%s/Autodiscover/Autodiscover.xml", maildomain);
578 cal->auto_disco_method = 2;
580 sipe_ews_do_autodiscover(cal, autodisc_url);
582 g_free(autodisc_url);
583 break;
585 case SIPE_EWS_STATE_AUTODISCOVER_2_FAILURE:
586 case SIPE_EWS_STATE_AVAILABILITY_FAILURE:
587 case SIPE_EWS_STATE_OOF_FAILURE:
588 cal->is_ews_disabled = TRUE;
589 break;
590 case SIPE_EWS_STATE_AUTODISCOVER_SUCCESS:
591 sipe_ews_do_avail_request(cal);
592 break;
593 case SIPE_EWS_STATE_AVAILABILITY_SUCCESS:
594 sipe_ews_do_oof_request(cal);
595 break;
596 case SIPE_EWS_STATE_OOF_SUCCESS:
598 struct sipe_core_private *sipe_private = cal->sipe_private;
600 cal->state = SIPE_EWS_STATE_AUTODISCOVER_SUCCESS;
601 cal->is_updated = TRUE;
602 sipe_cal_presence_publish(sipe_private, TRUE);
603 break;
608 void
609 sipe_ews_update_calendar(struct sipe_core_private *sipe_private)
611 struct sipe_account_data *sip = SIPE_ACCOUNT_DATA_PRIVATE;
612 //char *autodisc_srv = g_strdup_printf("_autodiscover._tcp.%s", maildomain);
613 gboolean has_url;
615 SIPE_DEBUG_INFO_NOFORMAT("sipe_ews_update_calendar: started.");
617 if (sipe_cal_calendar_init(sipe_private, &has_url)) {
618 if (has_url) {
619 sip->cal->state = SIPE_EWS_STATE_AUTODISCOVER_SUCCESS;
623 if (sip->cal->is_ews_disabled) {
624 SIPE_DEBUG_INFO_NOFORMAT("sipe_ews_update_calendar: disabled, exiting.");
625 return;
628 sipe_ews_run_state_machine(sip->cal);
630 SIPE_DEBUG_INFO_NOFORMAT("sipe_ews_update_calendar: finished.");
636 Local Variables:
637 mode: c
638 c-file-style: "bsd"
639 indent-tabs-mode: t
640 tab-width: 8
641 End: