l10n: Updates to Portuguese (Brazilian) (pt_BR) translation
[siplcs.git] / src / core / sipe-ews.c
blob992c95f0d25404655dc7da380db7afbbd578ed43
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"
53 #include "sip-sec.h"
54 #include "sipe-backend.h"
55 #include "sipe-cal.h"
56 #include "sipe-ews.h"
57 #include "sipe-utils.h"
58 #include "sipe-xml.h"
59 #include "http-conn.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 2
153 #define SIPE_EWS_STATE_OOF_SUCCESS 3
156 static void
157 sipe_ews_cal_events_free(GSList *cal_events)
159 GSList *entry = cal_events;
161 if (!cal_events) return;
163 while (entry) {
164 struct sipe_cal_event *cal_event = entry->data;
165 sipe_cal_event_free(cal_event);
166 entry = entry->next;
169 g_slist_free(cal_events);
172 void
173 sipe_ews_free(struct sipe_ews* ews)
175 g_free(ews->email);
176 g_free(ews->legacy_dn);
177 if (ews->auth) {
178 g_free(ews->auth->domain);
179 g_free(ews->auth->user);
180 g_free(ews->auth->password);
182 g_free(ews->auth);
183 g_free(ews->as_url);
184 g_free(ews->oof_url);
185 g_free(ews->oab_url);
186 g_free(ews->oof_state);
187 g_free(ews->oof_note);
188 g_free(ews->free_busy);
189 g_free(ews->working_hours_xml_str);
191 sipe_ews_cal_events_free(ews->cal_events);
193 g_free(ews);
196 char *
197 sipe_ews_get_oof_note(struct sipe_ews *ews)
199 time_t now = time(NULL);
201 if (!ews || !ews->oof_state) return NULL;
203 if (sipe_strequal(ews->oof_state, "Enabled") ||
204 (sipe_strequal(ews->oof_state, "Scheduled") && now >= ews->oof_start && now <= ews->oof_end))
206 return ews->oof_note;
208 else
210 return NULL;
214 static void
215 sipe_ews_run_state_machine(struct sipe_ews *ews);
217 static void
218 sipe_ews_process_avail_response(int return_code,
219 const char *body,
220 HttpConn *conn,
221 void *data)
223 struct sipe_ews *ews = data;
225 SIPE_DEBUG_INFO_NOFORMAT("sipe_ews_process_avail_response: cb started.");
227 if(!sipe_strequal(ews->as_url, ews->oof_url)) { /* whether reuse conn */
228 http_conn_set_close(conn);
229 ews->http_conn = NULL;
232 if (return_code == 200 && body) {
233 const sipe_xml *node;
234 const sipe_xml *resp;
235 /** ref: [MS-OXWAVLS] */
236 sipe_xml *xml = sipe_xml_parse(body, strlen(body));
238 Envelope/Body/GetUserAvailabilityResponse/FreeBusyResponseArray/FreeBusyResponse/ResponseMessage@ResponseClass="Success"
239 Envelope/Body/GetUserAvailabilityResponse/FreeBusyResponseArray/FreeBusyResponse/FreeBusyView/MergedFreeBusy
240 Envelope/Body/GetUserAvailabilityResponse/FreeBusyResponseArray/FreeBusyResponse/FreeBusyView/CalendarEventArray/CalendarEvent
241 Envelope/Body/GetUserAvailabilityResponse/FreeBusyResponseArray/FreeBusyResponse/FreeBusyView/WorkingHours
243 resp = sipe_xml_child(xml, "Body/GetUserAvailabilityResponse/FreeBusyResponseArray/FreeBusyResponse");
244 if (!resp) return; /* rather soap:Fault */
245 if (!sipe_strequal(sipe_xml_attribute(sipe_xml_child(resp, "ResponseMessage"), "ResponseClass"), "Success")) {
246 return; /* Error response */
249 /* MergedFreeBusy */
250 g_free(ews->free_busy);
251 ews->free_busy = sipe_xml_data(sipe_xml_child(resp, "FreeBusyView/MergedFreeBusy"));
253 /* WorkingHours */
254 node = sipe_xml_child(resp, "FreeBusyView/WorkingHours");
255 g_free(ews->working_hours_xml_str);
256 ews->working_hours_xml_str = sipe_xml_stringify(node);
257 SIPE_DEBUG_INFO("sipe_ews_process_avail_response: ews->working_hours_xml_str:\n%s",
258 ews->working_hours_xml_str ? ews->working_hours_xml_str : "");
260 sipe_ews_cal_events_free(ews->cal_events);
261 ews->cal_events = NULL;
262 /* CalendarEvents */
263 for (node = sipe_xml_child(resp, "FreeBusyView/CalendarEventArray/CalendarEvent");
264 node;
265 node = sipe_xml_twin(node))
267 char *tmp;
269 <CalendarEvent>
270 <StartTime>2009-12-07T13:30:00</StartTime>
271 <EndTime>2009-12-07T14:30:00</EndTime>
272 <BusyType>Busy</BusyType>
273 <CalendarEventDetails>
274 <ID>0000000...</ID>
275 <Subject>Lunch</Subject>
276 <Location>Cafe</Location>
277 <IsMeeting>false</IsMeeting>
278 <IsRecurring>true</IsRecurring>
279 <IsException>false</IsException>
280 <IsReminderSet>true</IsReminderSet>
281 <IsPrivate>false</IsPrivate>
282 </CalendarEventDetails>
283 </CalendarEvent>
285 struct sipe_cal_event *cal_event = g_new0(struct sipe_cal_event, 1);
286 ews->cal_events = g_slist_append(ews->cal_events, cal_event);
288 tmp = sipe_xml_data(sipe_xml_child(node, "StartTime"));
289 cal_event->start_time = sipe_utils_str_to_time(tmp);
290 g_free(tmp);
292 tmp = sipe_xml_data(sipe_xml_child(node, "EndTime"));
293 cal_event->end_time = sipe_utils_str_to_time(tmp);
294 g_free(tmp);
296 tmp = sipe_xml_data(sipe_xml_child(node, "BusyType"));
297 if (sipe_strequal("Free", tmp)) {
298 cal_event->cal_status = SIPE_CAL_FREE;
299 } else if (sipe_strequal("Tentative", tmp)) {
300 cal_event->cal_status = SIPE_CAL_TENTATIVE;
301 } else if (sipe_strequal("Busy", tmp)) {
302 cal_event->cal_status = SIPE_CAL_BUSY;
303 } else if (sipe_strequal("OOF", tmp)) {
304 cal_event->cal_status = SIPE_CAL_OOF;
305 } else {
306 cal_event->cal_status = SIPE_CAL_NO_DATA;
308 g_free(tmp);
310 cal_event->subject = sipe_xml_data(sipe_xml_child(node, "CalendarEventDetails/Subject"));
311 cal_event->location = sipe_xml_data(sipe_xml_child(node, "CalendarEventDetails/Location"));
313 tmp = sipe_xml_data(sipe_xml_child(node, "CalendarEventDetails/IsMeeting"));
314 cal_event->is_meeting = tmp ? sipe_strequal(tmp, "true") : TRUE;
315 g_free(tmp);
318 sipe_xml_free(xml);
320 ews->state = SIPE_EWS_STATE_AVAILABILITY_SUCCESS;
321 sipe_ews_run_state_machine(ews);
323 } else if (return_code < 0) {
324 ews->http_conn = NULL;
328 static void
329 sipe_ews_process_oof_response(int return_code,
330 const char *body,
331 HttpConn *conn,
332 void *data)
334 struct sipe_ews *ews = data;
336 SIPE_DEBUG_INFO_NOFORMAT("sipe_ews_process_oof_response: cb started.");
338 http_conn_set_close(conn);
339 ews->http_conn = NULL;
341 if (return_code == 200 && body) {
342 char *old_note;
343 const sipe_xml *resp;
344 const sipe_xml *xn_duration;
345 /** ref: [MS-OXWOOF] */
346 sipe_xml *xml = sipe_xml_parse(body, strlen(body));
347 /* Envelope/Body/GetUserOofSettingsResponse/ResponseMessage@ResponseClass="Success"
348 * Envelope/Body/GetUserOofSettingsResponse/OofSettings/OofState=Enabled
349 * Envelope/Body/GetUserOofSettingsResponse/OofSettings/Duration/StartTime
350 * Envelope/Body/GetUserOofSettingsResponse/OofSettings/Duration/EndTime
351 * Envelope/Body/GetUserOofSettingsResponse/OofSettings/InternalReply/Message
353 resp = sipe_xml_child(xml, "Body/GetUserOofSettingsResponse");
354 if (!resp) return; /* rather soap:Fault */
355 if (!sipe_strequal(sipe_xml_attribute(sipe_xml_child(resp, "ResponseMessage"), "ResponseClass"), "Success")) {
356 return; /* Error response */
359 g_free(ews->oof_state);
360 ews->oof_state = sipe_xml_data(sipe_xml_child(resp, "OofSettings/OofState"));
362 old_note = ews->oof_note;
363 ews->oof_note = NULL;
364 if (!sipe_strequal(ews->oof_state, "Disabled")) {
365 char *tmp = sipe_xml_data(
366 sipe_xml_child(resp, "OofSettings/InternalReply/Message"));
367 char *html;
369 /* UTF-8 encoded BOM (0xEF 0xBB 0xBF) as a signature to mark the beginning of a UTF-8 file */
370 if (g_str_has_prefix(tmp, "\xEF\xBB\xBF")) {
371 html = g_strdup(tmp+3);
372 } else {
373 html = g_strdup(tmp);
375 g_free(tmp);
376 tmp = g_strstrip(sipe_backend_markup_strip_html(html));
377 g_free(html);
378 ews->oof_note = g_markup_escape_text(tmp, -1);
379 g_free(tmp);
382 if (sipe_strequal(ews->oof_state, "Scheduled")
383 && (xn_duration = sipe_xml_child(resp, "OofSettings/Duration")))
385 char *tmp = sipe_xml_data(sipe_xml_child(xn_duration, "StartTime"));
386 ews->oof_start = sipe_utils_str_to_time(tmp);
387 g_free(tmp);
389 tmp = sipe_xml_data(sipe_xml_child(xn_duration, "EndTime"));
390 ews->oof_end = sipe_utils_str_to_time(tmp);
391 g_free(tmp);
394 if (!sipe_strequal(old_note, ews->oof_note)) { /* oof note changed */
395 ews->updated = time(NULL);
396 ews->published = FALSE;
398 g_free(old_note);
400 sipe_xml_free(xml);
402 ews->state = SIPE_EWS_STATE_OOF_SUCCESS;
403 sipe_ews_run_state_machine(ews);
405 } else if (return_code < 0) {
406 ews->http_conn = NULL;
410 static void
411 sipe_ews_process_autodiscover(int return_code,
412 const char *body,
413 HttpConn *conn,
414 void *data)
416 struct sipe_ews *ews = data;
418 SIPE_DEBUG_INFO_NOFORMAT("sipe_ews_process_autodiscover: cb started.");
420 http_conn_set_close(conn);
421 ews->http_conn = NULL;
423 if (return_code == 200 && body) {
424 const sipe_xml *node;
425 /** ref: [MS-OXDSCLI] */
426 sipe_xml *xml = sipe_xml_parse(body, strlen(body));
428 /* Autodiscover/Response/User/LegacyDN (trim()) */
429 ews->legacy_dn = sipe_xml_data(sipe_xml_child(xml, "Response/User/LegacyDN"));
430 ews->legacy_dn = ews->legacy_dn ? g_strstrip(ews->legacy_dn) : NULL;
432 /* Protocols */
433 for (node = sipe_xml_child(xml, "Response/Account/Protocol");
434 node;
435 node = sipe_xml_twin(node))
437 char *type = sipe_xml_data(sipe_xml_child(node, "Type"));
438 if (sipe_strequal("EXCH", type)) {
439 ews->as_url = sipe_xml_data(sipe_xml_child(node, "ASUrl"));
440 ews->oof_url = sipe_xml_data(sipe_xml_child(node, "OOFUrl"));
441 ews->oab_url = sipe_xml_data(sipe_xml_child(node, "OABUrl"));
443 SIPE_DEBUG_INFO("sipe_ews_process_autodiscover:as_url %s",
444 ews->as_url ? ews->as_url : "");
445 SIPE_DEBUG_INFO("sipe_ews_process_autodiscover:oof_url %s",
446 ews->oof_url ? ews->oof_url : "");
447 SIPE_DEBUG_INFO("sipe_ews_process_autodiscover:oab_url %s",
448 ews->oab_url ? ews->oab_url : "");
450 g_free(type);
451 break;
452 } else {
453 g_free(type);
454 continue;
458 sipe_xml_free(xml);
460 ews->state = SIPE_EWS_STATE_AUTODISCOVER_SUCCESS;
461 sipe_ews_run_state_machine(ews);
463 } else {
464 if (return_code < 0) {
465 ews->http_conn = NULL;
467 switch (ews->auto_disco_method) {
468 case 1:
469 ews->state = SIPE_EWS_STATE_AUTODISCOVER_1_FAILURE; break;
470 case 2:
471 ews->state = SIPE_EWS_STATE_AUTODISCOVER_2_FAILURE; break;
473 sipe_ews_run_state_machine(ews);
477 static void
478 sipe_ews_do_autodiscover(struct sipe_ews *ews,
479 const char* autodiscover_url)
481 char *body;
483 SIPE_DEBUG_INFO("sipe_ews_do_autodiscover: going autodiscover url=%s", autodiscover_url ? autodiscover_url : "");
485 body = g_strdup_printf(SIPE_EWS_AUTODISCOVER_REQUEST, ews->email);
486 ews->http_conn = http_conn_create(
487 ews->account,
488 HTTP_CONN_SSL,
489 autodiscover_url,
490 body,
491 "text/xml",
492 ews->auth,
493 sipe_ews_process_autodiscover,
494 ews);
495 g_free(body);
498 static void
499 sipe_ews_do_avail_request(struct sipe_ews *ews)
501 if (ews->as_url) {
502 char *body;
503 time_t end;
504 time_t now = time(NULL);
505 char *start_str;
506 char *end_str;
507 struct tm *now_tm;
509 SIPE_DEBUG_INFO_NOFORMAT("sipe_ews_do_avail_request: going Availability req.");
511 now_tm = gmtime(&now);
512 /* start -1 day, 00:00:00 */
513 now_tm->tm_sec = 0;
514 now_tm->tm_min = 0;
515 now_tm->tm_hour = 0;
516 ews->fb_start = sipe_mktime_tz(now_tm, "UTC");
517 ews->fb_start -= 24*60*60;
518 /* end = start + 4 days - 1 sec */
519 end = ews->fb_start + 4*(24*60*60) - 1;
521 start_str = sipe_utils_time_to_str(ews->fb_start);
522 end_str = sipe_utils_time_to_str(end);
524 body = g_strdup_printf(SIPE_EWS_USER_AVAILABILITY_REQUEST, ews->email, start_str, end_str);
525 ews->http_conn = http_conn_create(
526 ews->account,
527 HTTP_CONN_SSL,
528 ews->as_url,
529 body,
530 "text/xml; charset=UTF-8",
531 ews->auth,
532 sipe_ews_process_avail_response,
533 ews);
534 g_free(body);
535 g_free(start_str);
536 g_free(end_str);
540 static void
541 sipe_ews_do_oof_request(struct sipe_ews *ews)
543 if (ews->oof_url) {
544 char *body;
545 const char *content_type = "text/xml; charset=UTF-8";
547 SIPE_DEBUG_INFO_NOFORMAT("sipe_ews_do_oof_request: going OOF req.");
549 body = g_strdup_printf(SIPE_EWS_USER_OOF_SETTINGS_REQUEST, ews->email);
550 if (!ews->http_conn) {
551 ews->http_conn = http_conn_create(ews->account,
552 HTTP_CONN_SSL,
553 ews->oof_url,
554 body,
555 content_type,
556 ews->auth,
557 sipe_ews_process_oof_response,
558 ews);
559 } else {
560 http_conn_post(ews->http_conn,
561 ews->oof_url,
562 body,
563 content_type,
564 sipe_ews_process_oof_response,
565 ews);
567 g_free(body);
571 static void
572 sipe_ews_run_state_machine(struct sipe_ews *ews)
574 switch (ews->state) {
575 case SIPE_EWS_STATE_NONE:
577 char *maildomain = strstr(ews->email, "@") + 1;
578 char *autodisc_url = g_strdup_printf("https://Autodiscover.%s/Autodiscover/Autodiscover.xml", maildomain);
580 ews->auto_disco_method = 1;
582 sipe_ews_do_autodiscover(ews, autodisc_url);
584 g_free(autodisc_url);
585 break;
587 case SIPE_EWS_STATE_AUTODISCOVER_1_FAILURE:
589 char *maildomain = strstr(ews->email, "@") + 1;
590 char *autodisc_url = g_strdup_printf("https://%s/Autodiscover/Autodiscover.xml", maildomain);
592 ews->auto_disco_method = 2;
594 sipe_ews_do_autodiscover(ews, autodisc_url);
596 g_free(autodisc_url);
597 break;
599 case SIPE_EWS_STATE_AUTODISCOVER_2_FAILURE:
600 ews->is_disabled = TRUE;
601 break;
602 case SIPE_EWS_STATE_AUTODISCOVER_SUCCESS:
603 sipe_ews_do_avail_request(ews);
604 break;
605 case SIPE_EWS_STATE_AVAILABILITY_SUCCESS:
606 sipe_ews_do_oof_request(ews);
607 break;
608 case SIPE_EWS_STATE_OOF_SUCCESS:
609 ews->state = SIPE_EWS_STATE_AUTODISCOVER_SUCCESS;
610 ews->is_updated = TRUE;
611 if (ews->sip->ocs2007) {
612 /* sipe.h */
613 publish_calendar_status_self(ews->sip);
614 } else {
615 /* sipe.h */
616 send_presence_soap(ews->sip, TRUE);
618 break;
622 void
623 sipe_ews_update_calendar(struct sipe_account_data *sip)
625 //char *autodisc_srv = g_strdup_printf("_autodiscover._tcp.%s", maildomain);
627 SIPE_DEBUG_INFO_NOFORMAT("sipe_ews_update_calendar: started.");
629 if (!sip->ews) {
630 const char *value;
632 sip->ews = g_new0(struct sipe_ews, 1);
633 sip->ews->sip = sip;
635 sip->ews->account = sip->account;
636 sip->ews->email = g_strdup(sip->email);
638 /* user specified a service URL? */
639 value = purple_account_get_string(sip->account, "email_url", NULL);
640 if (!is_empty(value)) {
641 sip->ews->as_url = g_strdup(value);
642 sip->ews->oof_url = g_strdup(value);
643 sip->ews->state = SIPE_EWS_STATE_AUTODISCOVER_SUCCESS;
646 sip->ews->auth = g_new0(HttpConnAuth, 1);
647 sip->ews->auth->use_negotiate = purple_account_get_bool(sip->account, "krb5", FALSE);
649 /* user specified email login? */
650 value = purple_account_get_string(sip->account, "email_login", NULL);
651 if (!is_empty(value)) {
653 /* user specified email login domain? */
654 const char *tmp = strstr(value, "\\");
655 if (tmp) {
656 sip->ews->auth->domain = g_strndup(value, tmp - value);
657 sip->ews->auth->user = g_strdup(tmp + 1);
658 } else {
659 sip->ews->auth->user = g_strdup(value);
661 sip->ews->auth->password = g_strdup(purple_account_get_string(sip->account, "email_password", NULL));
663 } else {
664 /* re-use SIPE credentials */
665 sip->ews->auth->domain = g_strdup(sip->authdomain);
666 sip->ews->auth->user = g_strdup(sip->authuser);
667 sip->ews->auth->password = g_strdup(sip->password);
671 if(sip->ews->is_disabled) {
672 SIPE_DEBUG_INFO_NOFORMAT("sipe_ews_update_calendar: disabled, exiting.");
673 return;
676 sipe_ews_run_state_machine(sip->ews);
678 SIPE_DEBUG_INFO_NOFORMAT("sipe_ews_update_calendar: finished.");
684 Local Variables:
685 mode: c
686 c-file-style: "bsd"
687 indent-tabs-mode: t
688 tab-width: 8
689 End: