interface cleanup: decouple header files
[siplcs.git] / src / core / sipe-ews.c
blob88db51030e6480a72cb3d800479cbf9d24bb222c
1 /**
2 * @file sipe-ews.c
4 * pidgin-sipe
6 * Copyright (C) 2010, 2009 pier11 <pier11@operamail.com>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 /**
25 For communication with Exchange 2007/2010 Web Server/Web Services:
27 1) Autodiscover (HTTPS POST request). With redirect support. XML content.
28 1.1) DNS SRV record _autodiscover._tcp.<domain> may also be resolved.
29 2) Availability Web service (SOAP = HTTPS POST + XML) call.
30 3) Out of Office (OOF) Web Service (SOAP = HTTPS POST + XML) call.
31 4) Web server authentication required - NTLM and/or Negotiate (Kerberos).
33 Note: ews - EWS stands for Exchange Web Services.
35 It will be able to retrieve our Calendar information (FreeBusy, WorkingHours,
36 Meetings Subject and Location, Is_Meeting) as well as our Out of Office (OOF) note
37 from Exchange Web Services for subsequent publishing.
39 Ref. for more implementation details:
40 http://sourceforge.net/projects/sipe/forums/forum/688535/topic/3403462
42 Similar functionality for Lotus Notes/Domino, iCalendar/CalDAV/Google would
43 be great to implement too.
46 #include <string.h>
47 #include <time.h>
49 #include <glib.h>
51 #include "account.h"
52 #include "debug.h"
53 #include "util.h"
55 #include "sipe-cal.h"
56 #include "sipe-ews.h"
57 #include "sip-sec.h"
58 #include "sipe-utils.h"
59 #include "sipe-xml.h"
60 #include "http-conn.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 2
154 #define SIPE_EWS_STATE_OOF_SUCCESS 3
157 static void
158 sipe_ews_cal_events_free(GSList *cal_events)
160 GSList *entry = cal_events;
162 if (!cal_events) return;
164 while (entry) {
165 struct sipe_cal_event *cal_event = entry->data;
166 sipe_cal_event_free(cal_event);
167 entry = entry->next;
170 g_slist_free(cal_events);
173 void
174 sipe_ews_free(struct sipe_ews* ews)
176 g_free(ews->email);
177 g_free(ews->legacy_dn);
178 if (ews->auth) {
179 g_free(ews->auth->domain);
180 g_free(ews->auth->user);
181 g_free(ews->auth->password);
183 g_free(ews->auth);
184 g_free(ews->as_url);
185 g_free(ews->oof_url);
186 g_free(ews->oab_url);
187 g_free(ews->oof_state);
188 g_free(ews->oof_note);
189 g_free(ews->free_busy);
190 g_free(ews->working_hours_xml_str);
192 sipe_ews_cal_events_free(ews->cal_events);
194 g_free(ews);
197 char *
198 sipe_ews_get_oof_note(struct sipe_ews *ews)
200 time_t now = time(NULL);
202 if (!ews || !ews->oof_state) return NULL;
204 if (sipe_strequal(ews->oof_state, "Enabled") ||
205 (sipe_strequal(ews->oof_state, "Scheduled") && now >= ews->oof_start && now <= ews->oof_end))
207 return ews->oof_note;
209 else
211 return NULL;
215 static void
216 sipe_ews_run_state_machine(struct sipe_ews *ews);
218 static void
219 sipe_ews_process_avail_response(int return_code,
220 const char *body,
221 HttpConn *conn,
222 void *data)
224 struct sipe_ews *ews = data;
226 purple_debug_info("sipe", "sipe_ews_process_avail_response: cb started.\n");
228 if(!sipe_strequal(ews->as_url, ews->oof_url)) { /* whether reuse conn */
229 http_conn_set_close(conn);
230 ews->http_conn = NULL;
233 if (return_code == 200 && body) {
234 const sipe_xml *node;
235 const sipe_xml *resp;
236 /** ref: [MS-OXWAVLS] */
237 sipe_xml *xml = sipe_xml_parse(body, strlen(body));
239 Envelope/Body/GetUserAvailabilityResponse/FreeBusyResponseArray/FreeBusyResponse/ResponseMessage@ResponseClass="Success"
240 Envelope/Body/GetUserAvailabilityResponse/FreeBusyResponseArray/FreeBusyResponse/FreeBusyView/MergedFreeBusy
241 Envelope/Body/GetUserAvailabilityResponse/FreeBusyResponseArray/FreeBusyResponse/FreeBusyView/CalendarEventArray/CalendarEvent
242 Envelope/Body/GetUserAvailabilityResponse/FreeBusyResponseArray/FreeBusyResponse/FreeBusyView/WorkingHours
244 resp = sipe_xml_child(xml, "Body/GetUserAvailabilityResponse/FreeBusyResponseArray/FreeBusyResponse");
245 if (!resp) return; /* rather soap:Fault */
246 if (!sipe_strequal(sipe_xml_attribute(sipe_xml_child(resp, "ResponseMessage"), "ResponseClass"), "Success")) {
247 return; /* Error response */
250 /* MergedFreeBusy */
251 g_free(ews->free_busy);
252 ews->free_busy = sipe_xml_data(sipe_xml_child(resp, "FreeBusyView/MergedFreeBusy"));
254 /* WorkingHours */
255 node = sipe_xml_child(resp, "FreeBusyView/WorkingHours");
256 g_free(ews->working_hours_xml_str);
257 ews->working_hours_xml_str = sipe_xml_stringify(node);
258 purple_debug_info("sipe", "sipe_ews_process_avail_response: ews->working_hours_xml_str:\n%s\n",
259 ews->working_hours_xml_str ? ews->working_hours_xml_str : "");
261 sipe_ews_cal_events_free(ews->cal_events);
262 ews->cal_events = NULL;
263 /* CalendarEvents */
264 for (node = sipe_xml_child(resp, "FreeBusyView/CalendarEventArray/CalendarEvent");
265 node;
266 node = sipe_xml_twin(node))
268 char *tmp;
270 <CalendarEvent>
271 <StartTime>2009-12-07T13:30:00</StartTime>
272 <EndTime>2009-12-07T14:30:00</EndTime>
273 <BusyType>Busy</BusyType>
274 <CalendarEventDetails>
275 <ID>0000000...</ID>
276 <Subject>Lunch</Subject>
277 <Location>Cafe</Location>
278 <IsMeeting>false</IsMeeting>
279 <IsRecurring>true</IsRecurring>
280 <IsException>false</IsException>
281 <IsReminderSet>true</IsReminderSet>
282 <IsPrivate>false</IsPrivate>
283 </CalendarEventDetails>
284 </CalendarEvent>
286 struct sipe_cal_event *cal_event = g_new0(struct sipe_cal_event, 1);
287 ews->cal_events = g_slist_append(ews->cal_events, cal_event);
289 tmp = sipe_xml_data(sipe_xml_child(node, "StartTime"));
290 cal_event->start_time = sipe_utils_str_to_time(tmp);
291 g_free(tmp);
293 tmp = sipe_xml_data(sipe_xml_child(node, "EndTime"));
294 cal_event->end_time = sipe_utils_str_to_time(tmp);
295 g_free(tmp);
297 tmp = sipe_xml_data(sipe_xml_child(node, "BusyType"));
298 if (sipe_strequal("Free", tmp)) {
299 cal_event->cal_status = SIPE_CAL_FREE;
300 } else if (sipe_strequal("Tentative", tmp)) {
301 cal_event->cal_status = SIPE_CAL_TENTATIVE;
302 } else if (sipe_strequal("Busy", tmp)) {
303 cal_event->cal_status = SIPE_CAL_BUSY;
304 } else if (sipe_strequal("OOF", tmp)) {
305 cal_event->cal_status = SIPE_CAL_OOF;
306 } else {
307 cal_event->cal_status = SIPE_CAL_NO_DATA;
309 g_free(tmp);
311 cal_event->subject = sipe_xml_data(sipe_xml_child(node, "CalendarEventDetails/Subject"));
312 cal_event->location = sipe_xml_data(sipe_xml_child(node, "CalendarEventDetails/Location"));
314 tmp = sipe_xml_data(sipe_xml_child(node, "CalendarEventDetails/IsMeeting"));
315 cal_event->is_meeting = tmp ? sipe_strequal(tmp, "true") : TRUE;
316 g_free(tmp);
319 sipe_xml_free(xml);
321 ews->state = SIPE_EWS_STATE_AVAILABILITY_SUCCESS;
322 sipe_ews_run_state_machine(ews);
324 } else if (return_code < 0) {
325 ews->http_conn = NULL;
329 static void
330 sipe_ews_process_oof_response(int return_code,
331 const char *body,
332 HttpConn *conn,
333 void *data)
335 struct sipe_ews *ews = data;
337 purple_debug_info("sipe", "sipe_ews_process_oof_response: cb started.\n");
339 http_conn_set_close(conn);
340 ews->http_conn = NULL;
342 if (return_code == 200 && body) {
343 char *old_note;
344 const sipe_xml *resp;
345 const sipe_xml *xn_duration;
346 /** ref: [MS-OXWOOF] */
347 sipe_xml *xml = sipe_xml_parse(body, strlen(body));
348 /* Envelope/Body/GetUserOofSettingsResponse/ResponseMessage@ResponseClass="Success"
349 * Envelope/Body/GetUserOofSettingsResponse/OofSettings/OofState=Enabled
350 * Envelope/Body/GetUserOofSettingsResponse/OofSettings/Duration/StartTime
351 * Envelope/Body/GetUserOofSettingsResponse/OofSettings/Duration/EndTime
352 * Envelope/Body/GetUserOofSettingsResponse/OofSettings/InternalReply/Message
354 resp = sipe_xml_child(xml, "Body/GetUserOofSettingsResponse");
355 if (!resp) return; /* rather soap:Fault */
356 if (!sipe_strequal(sipe_xml_attribute(sipe_xml_child(resp, "ResponseMessage"), "ResponseClass"), "Success")) {
357 return; /* Error response */
360 g_free(ews->oof_state);
361 ews->oof_state = sipe_xml_data(sipe_xml_child(resp, "OofSettings/OofState"));
363 old_note = ews->oof_note;
364 ews->oof_note = NULL;
365 if (!sipe_strequal(ews->oof_state, "Disabled")) {
366 char *tmp = sipe_xml_data(
367 sipe_xml_child(resp, "OofSettings/InternalReply/Message"));
368 char *html;
370 /* UTF-8 encoded BOM (0xEF 0xBB 0xBF) as a signature to mark the beginning of a UTF-8 file */
371 if (g_str_has_prefix(tmp, "\xEF\xBB\xBF")) {
372 html = g_strdup(tmp+3);
373 } else {
374 html = g_strdup(tmp);
376 g_free(tmp);
377 tmp = g_strstrip(purple_markup_strip_html(html));
378 g_free(html);
379 ews->oof_note = g_markup_escape_text(tmp, -1);
380 g_free(tmp);
383 if (sipe_strequal(ews->oof_state, "Scheduled")
384 && (xn_duration = sipe_xml_child(resp, "OofSettings/Duration")))
386 char *tmp = sipe_xml_data(sipe_xml_child(xn_duration, "StartTime"));
387 ews->oof_start = sipe_utils_str_to_time(tmp);
388 g_free(tmp);
390 tmp = sipe_xml_data(sipe_xml_child(xn_duration, "EndTime"));
391 ews->oof_end = sipe_utils_str_to_time(tmp);
392 g_free(tmp);
395 if (!sipe_strequal(old_note, ews->oof_note)) { /* oof note changed */
396 ews->updated = time(NULL);
397 ews->published = FALSE;
399 g_free(old_note);
401 sipe_xml_free(xml);
403 ews->state = SIPE_EWS_STATE_OOF_SUCCESS;
404 sipe_ews_run_state_machine(ews);
406 } else if (return_code < 0) {
407 ews->http_conn = NULL;
411 static void
412 sipe_ews_process_autodiscover(int return_code,
413 const char *body,
414 HttpConn *conn,
415 void *data)
417 struct sipe_ews *ews = data;
419 purple_debug_info("sipe", "sipe_ews_process_autodiscover: cb started.\n");
421 http_conn_set_close(conn);
422 ews->http_conn = NULL;
424 if (return_code == 200 && body) {
425 const sipe_xml *node;
426 /** ref: [MS-OXDSCLI] */
427 sipe_xml *xml = sipe_xml_parse(body, strlen(body));
429 /* Autodiscover/Response/User/LegacyDN (trim()) */
430 ews->legacy_dn = sipe_xml_data(sipe_xml_child(xml, "Response/User/LegacyDN"));
431 ews->legacy_dn = ews->legacy_dn ? g_strstrip(ews->legacy_dn) : NULL;
433 /* Protocols */
434 for (node = sipe_xml_child(xml, "Response/Account/Protocol");
435 node;
436 node = sipe_xml_twin(node))
438 char *type = sipe_xml_data(sipe_xml_child(node, "Type"));
439 if (sipe_strequal("EXCH", type)) {
440 ews->as_url = sipe_xml_data(sipe_xml_child(node, "ASUrl"));
441 ews->oof_url = sipe_xml_data(sipe_xml_child(node, "OOFUrl"));
442 ews->oab_url = sipe_xml_data(sipe_xml_child(node, "OABUrl"));
444 purple_debug_info("sipe", "sipe_ews_process_autodiscover:as_url %s\n",
445 ews->as_url ? ews->as_url : "");
446 purple_debug_info("sipe", "sipe_ews_process_autodiscover:oof_url %s\n",
447 ews->oof_url ? ews->oof_url : "");
448 purple_debug_info("sipe", "sipe_ews_process_autodiscover:oab_url %s\n",
449 ews->oab_url ? ews->oab_url : "");
451 g_free(type);
452 break;
453 } else {
454 g_free(type);
455 continue;
459 sipe_xml_free(xml);
461 ews->state = SIPE_EWS_STATE_AUTODISCOVER_SUCCESS;
462 sipe_ews_run_state_machine(ews);
464 } else {
465 if (return_code < 0) {
466 ews->http_conn = NULL;
468 switch (ews->auto_disco_method) {
469 case 1:
470 ews->state = SIPE_EWS_STATE_AUTODISCOVER_1_FAILURE; break;
471 case 2:
472 ews->state = SIPE_EWS_STATE_AUTODISCOVER_2_FAILURE; break;
474 sipe_ews_run_state_machine(ews);
478 static void
479 sipe_ews_do_autodiscover(struct sipe_ews *ews,
480 const char* autodiscover_url)
482 char *body;
484 purple_debug_info("sipe", "sipe_ews_do_autodiscover: going autodiscover url=%s\n", autodiscover_url ? autodiscover_url : "");
486 body = g_strdup_printf(SIPE_EWS_AUTODISCOVER_REQUEST, ews->email);
487 ews->http_conn = http_conn_create(
488 ews->account,
489 HTTP_CONN_SSL,
490 autodiscover_url,
491 body,
492 "text/xml",
493 ews->auth,
494 sipe_ews_process_autodiscover,
495 ews);
496 g_free(body);
499 static void
500 sipe_ews_do_avail_request(struct sipe_ews *ews)
502 if (ews->as_url) {
503 char *body;
504 time_t end;
505 time_t now = time(NULL);
506 char *start_str;
507 char *end_str;
508 struct tm *now_tm;
510 purple_debug_info("sipe", "sipe_ews_do_avail_request: going Availability req.\n");
512 now_tm = gmtime(&now);
513 /* start -1 day, 00:00:00 */
514 now_tm->tm_sec = 0;
515 now_tm->tm_min = 0;
516 now_tm->tm_hour = 0;
517 ews->fb_start = sipe_mktime_tz(now_tm, "UTC");
518 ews->fb_start -= 24*60*60;
519 /* end = start + 4 days - 1 sec */
520 end = ews->fb_start + 4*(24*60*60) - 1;
522 start_str = sipe_utils_time_to_str(ews->fb_start);
523 end_str = sipe_utils_time_to_str(end);
525 body = g_strdup_printf(SIPE_EWS_USER_AVAILABILITY_REQUEST, ews->email, start_str, end_str);
526 ews->http_conn = http_conn_create(
527 ews->account,
528 HTTP_CONN_SSL,
529 ews->as_url,
530 body,
531 "text/xml; charset=UTF-8",
532 ews->auth,
533 sipe_ews_process_avail_response,
534 ews);
535 g_free(body);
536 g_free(start_str);
537 g_free(end_str);
541 static void
542 sipe_ews_do_oof_request(struct sipe_ews *ews)
544 if (ews->oof_url) {
545 char *body;
546 const char *content_type = "text/xml; charset=UTF-8";
548 purple_debug_info("sipe", "sipe_ews_do_oof_request: going OOF req.\n");
550 body = g_strdup_printf(SIPE_EWS_USER_OOF_SETTINGS_REQUEST, ews->email);
551 if (!ews->http_conn) {
552 ews->http_conn = http_conn_create(ews->account,
553 HTTP_CONN_SSL,
554 ews->oof_url,
555 body,
556 content_type,
557 ews->auth,
558 sipe_ews_process_oof_response,
559 ews);
560 } else {
561 http_conn_post(ews->http_conn,
562 ews->oof_url,
563 body,
564 content_type,
565 sipe_ews_process_oof_response,
566 ews);
568 g_free(body);
572 static void
573 sipe_ews_run_state_machine(struct sipe_ews *ews)
575 switch (ews->state) {
576 case SIPE_EWS_STATE_NONE:
578 char *maildomain = strstr(ews->email, "@") + 1;
579 char *autodisc_url = g_strdup_printf("https://Autodiscover.%s/Autodiscover/Autodiscover.xml", maildomain);
581 ews->auto_disco_method = 1;
583 sipe_ews_do_autodiscover(ews, autodisc_url);
585 g_free(autodisc_url);
586 break;
588 case SIPE_EWS_STATE_AUTODISCOVER_1_FAILURE:
590 char *maildomain = strstr(ews->email, "@") + 1;
591 char *autodisc_url = g_strdup_printf("https://%s/Autodiscover/Autodiscover.xml", maildomain);
593 ews->auto_disco_method = 2;
595 sipe_ews_do_autodiscover(ews, autodisc_url);
597 g_free(autodisc_url);
598 break;
600 case SIPE_EWS_STATE_AUTODISCOVER_2_FAILURE:
601 ews->is_disabled = TRUE;
602 break;
603 case SIPE_EWS_STATE_AUTODISCOVER_SUCCESS:
604 sipe_ews_do_avail_request(ews);
605 break;
606 case SIPE_EWS_STATE_AVAILABILITY_SUCCESS:
607 sipe_ews_do_oof_request(ews);
608 break;
609 case SIPE_EWS_STATE_OOF_SUCCESS:
610 ews->state = SIPE_EWS_STATE_AUTODISCOVER_SUCCESS;
611 ews->is_updated = TRUE;
612 if (ews->sip->ocs2007) {
613 /* sipe.h */
614 publish_calendar_status_self(ews->sip);
615 } else {
616 /* sipe.h */
617 send_presence_soap(ews->sip, TRUE);
619 break;
623 void
624 sipe_ews_update_calendar(struct sipe_account_data *sip)
626 //char *autodisc_srv = g_strdup_printf("_autodiscover._tcp.%s", maildomain);
628 purple_debug_info("sipe", "sipe_ews_update_calendar: started.\n");
630 if (!sip->ews) {
631 const char *value;
633 sip->ews = g_new0(struct sipe_ews, 1);
634 sip->ews->sip = sip;
636 sip->ews->account = sip->account;
637 sip->ews->email = g_strdup(sip->email);
639 /* user specified a service URL? */
640 value = purple_account_get_string(sip->account, "email_url", NULL);
641 if (!is_empty(value)) {
642 sip->ews->as_url = g_strdup(value);
643 sip->ews->oof_url = g_strdup(value);
644 sip->ews->state = SIPE_EWS_STATE_AUTODISCOVER_SUCCESS;
647 sip->ews->auth = g_new0(HttpConnAuth, 1);
648 sip->ews->auth->use_negotiate = purple_account_get_bool(sip->account, "krb5", FALSE);
650 /* user specified email login? */
651 value = purple_account_get_string(sip->account, "email_login", NULL);
652 if (!is_empty(value)) {
654 /* user specified email login domain? */
655 const char *tmp = strstr(value, "\\");
656 if (tmp) {
657 sip->ews->auth->domain = g_strndup(value, tmp - value);
658 sip->ews->auth->user = g_strdup(tmp + 1);
659 } else {
660 sip->ews->auth->user = g_strdup(value);
662 sip->ews->auth->password = g_strdup(purple_account_get_string(sip->account, "email_password", NULL));
664 } else {
665 /* re-use SIPE credentials */
666 sip->ews->auth->domain = g_strdup(sip->authdomain);
667 sip->ews->auth->user = g_strdup(sip->authuser);
668 sip->ews->auth->password = g_strdup(sip->password);
672 if(sip->ews->is_disabled) {
673 purple_debug_info("sipe", "sipe_ews_update_calendar: disabled, exiting.\n");
674 return;
677 sipe_ews_run_state_machine(sip->ews);
679 purple_debug_info("sipe", "sipe_ews_update_calendar: finished.\n");
685 Local Variables:
686 mode: c
687 c-file-style: "bsd"
688 indent-tabs-mode: t
689 tab-width: 8
690 End: