Merge branch 'mob' of git+ssh://localhost/srv/git/siplcs into mob
[siplcs.git] / src / core / sipe-ews.c
blobad0501d17d563db29887e9f77e482200a5a16f8d
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.
45 #include <string.h>
47 #include "debug.h"
48 #include "xmlnode.h"
50 #include "sipe.h"
51 /* for xmlnode_get_descendant */
52 #include "sipe-utils.h"
54 #include "sipe-ews.h"
55 #include "sipe-cal.h"
58 /**
59 * Autodiscover request for Exchange Web Services
60 * @param email (%s) Ex.: alice@cosmo.local
62 #define SIPE_EWS_AUTODISCOVER_REQUEST \
63 "<?xml version=\"1.0\"?>"\
64 "<Autodiscover xmlns=\"http://schemas.microsoft.com/exchange/autodiscover/outlook/requestschema/2006\">"\
65 "<Request>"\
66 "<EMailAddress>%s</EMailAddress>"\
67 "<AcceptableResponseSchema>"\
68 "http://schemas.microsoft.com/exchange/autodiscover/outlook/responseschema/2006a"\
69 "</AcceptableResponseSchema>"\
70 "</Request>"\
71 "</Autodiscover>"
73 /**
74 * GetUserOofSettingsRequest SOAP request to Exchange Web Services
75 * to obtain our Out-of-office (OOF) information.
76 * @param email (%s) Ex.: alice@cosmo.local
78 #define SIPE_EWS_USER_OOF_SETTINGS_REQUEST \
79 "<?xml version=\"1.0\" encoding=\"utf-8\"?>"\
80 "<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/\">"\
81 "<soap:Body>"\
82 "<GetUserOofSettingsRequest xmlns=\"http://schemas.microsoft.com/exchange/services/2006/messages\">"\
83 "<Mailbox xmlns=\"http://schemas.microsoft.com/exchange/services/2006/types\">"\
84 "<Address>%s</Address>"\
85 "</Mailbox>"\
86 "</GetUserOofSettingsRequest>"\
87 "</soap:Body>"\
88 "</soap:Envelope>"
90 /**
91 * GetUserAvailabilityRequest SOAP request to Exchange Web Services
92 * to obtain our Availability (FreeBusy, WorkingHours, Meetings) information.
93 * @param email (%s) Ex.: alice@cosmo.local
94 * @param start_time (%s) Ex.: 2009-12-06T00:00:00
95 * @param end_time (%s) Ex.: 2009-12-09T23:59:59
97 #define SIPE_EWS_USER_AVAILABILITY_REQUEST \
98 "<?xml version=\"1.0\" encoding=\"utf-8\"?>"\
99 "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\""\
100 " xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\""\
101 " xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\""\
102 " xmlns:t=\"http://schemas.microsoft.com/exchange/services/2006/types\">"\
103 "<soap:Body>"\
104 "<GetUserAvailabilityRequest xmlns=\"http://schemas.microsoft.com/exchange/services/2006/messages\""\
105 " xmlns:t=\"http://schemas.microsoft.com/exchange/services/2006/types\">"\
106 "<t:TimeZone xmlns=\"http://schemas.microsoft.com/exchange/services/2006/types\">"\
107 "<Bias>0</Bias>"\
108 "<StandardTime>"\
109 "<Bias>0</Bias>"\
110 "<Time>00:00:00</Time>"\
111 "<DayOrder>0</DayOrder>"\
112 "<Month>0</Month>"\
113 "<DayOfWeek>Sunday</DayOfWeek>"\
114 "</StandardTime>"\
115 "<DaylightTime>"\
116 "<Bias>0</Bias>"\
117 "<Time>00:00:00</Time>"\
118 "<DayOrder>0</DayOrder>"\
119 "<Month>0</Month>"\
120 "<DayOfWeek>Sunday</DayOfWeek>"\
121 "</DaylightTime>"\
122 "</t:TimeZone>"\
123 "<MailboxDataArray>"\
124 "<t:MailboxData>"\
125 "<t:Email>"\
126 "<t:Address>%s</t:Address>"\
127 "</t:Email>"\
128 "<t:AttendeeType>Required</t:AttendeeType>"\
129 "<t:ExcludeConflicts>false</t:ExcludeConflicts>"\
130 "</t:MailboxData>"\
131 "</MailboxDataArray>"\
132 "<t:FreeBusyViewOptions>"\
133 "<t:TimeWindow>"\
134 "<t:StartTime>%s</t:StartTime>"\
135 "<t:EndTime>%s</t:EndTime>"\
136 "</t:TimeWindow>"\
137 "<t:MergedFreeBusyIntervalInMinutes>15</t:MergedFreeBusyIntervalInMinutes>"\
138 "<t:RequestedView>DetailedMerged</t:RequestedView>"\
139 "</t:FreeBusyViewOptions>"\
140 "</GetUserAvailabilityRequest>"\
141 "</soap:Body>"\
142 "</soap:Envelope>"
144 #define SIPE_EWS_STATE_NONE 0
145 #define SIPE_EWS_STATE_AUTODISCOVER_SUCCESS 1
146 #define SIPE_EWS_STATE_AUTODISCOVER_1_FAILURE -1
147 #define SIPE_EWS_STATE_AUTODISCOVER_2_FAILURE -2
148 #define SIPE_EWS_STATE_AVAILABILITY_SUCCESS 2
149 #define SIPE_EWS_STATE_OOF_SUCCESS 3
152 static void
153 sipe_ews_cal_events_free(GSList *cal_events)
155 GSList *entry = cal_events;
157 if (!cal_events) return;
159 while (entry) {
160 struct sipe_cal_event *cal_event = entry->data;
161 sipe_cal_event_free(cal_event);
162 entry = entry->next;
165 g_slist_free(cal_events);
168 void
169 sipe_ews_free(struct sipe_ews* ews)
171 g_free(ews->email);
172 g_free(ews->legacy_dn);
173 if (ews->auth) {
174 g_free(ews->auth->domain);
175 g_free(ews->auth->user);
176 g_free(ews->auth->password);
178 g_free(ews->auth);
179 g_free(ews->as_url);
180 g_free(ews->oof_url);
181 g_free(ews->oab_url);
182 g_free(ews->oof_state);
183 g_free(ews->oof_note);
184 g_free(ews->free_busy);
185 g_free(ews->working_hours_xml_str);
187 sipe_ews_cal_events_free(ews->cal_events);
189 g_free(ews);
192 char *
193 sipe_ews_get_oof_note(struct sipe_ews *ews)
195 time_t now = time(NULL);
197 if (!ews || !ews->oof_state) return NULL;
199 if (sipe_strequal(ews->oof_state, "Enabled") ||
200 (sipe_strequal(ews->oof_state, "Scheduled") && now >= ews->oof_start && now <= ews->oof_end))
202 return ews->oof_note;
204 else
206 return NULL;
210 static void
211 sipe_ews_run_state_machine(struct sipe_ews *ews);
213 static void
214 sipe_ews_process_avail_response(int return_code,
215 const char *body,
216 HttpConn *conn,
217 void *data)
219 struct sipe_ews *ews = data;
221 purple_debug_info("sipe", "sipe_ews_process_avail_response: cb started.\n");
223 if(!sipe_strequal(ews->as_url, ews->oof_url)) { /* whether reuse conn */
224 http_conn_set_close(conn);
225 ews->http_conn = NULL;
228 if (return_code == 200 && body) {
229 xmlnode *node;
230 xmlnode *resp;
231 /** ref: [MS-OXWAVLS] */
232 xmlnode *xml = xmlnode_from_str(body, strlen(body));
234 Envelope/Body/GetUserAvailabilityResponse/FreeBusyResponseArray/FreeBusyResponse/ResponseMessage@ResponseClass="Success"
235 Envelope/Body/GetUserAvailabilityResponse/FreeBusyResponseArray/FreeBusyResponse/FreeBusyView/MergedFreeBusy
236 Envelope/Body/GetUserAvailabilityResponse/FreeBusyResponseArray/FreeBusyResponse/FreeBusyView/CalendarEventArray/CalendarEvent
237 Envelope/Body/GetUserAvailabilityResponse/FreeBusyResponseArray/FreeBusyResponse/FreeBusyView/WorkingHours
239 resp = xmlnode_get_descendant(xml, "Body", "GetUserAvailabilityResponse", "FreeBusyResponseArray", "FreeBusyResponse", NULL);
240 if (!resp) return; /* rather soap:Fault */
241 if (!sipe_strequal(xmlnode_get_attrib(xmlnode_get_child(resp, "ResponseMessage"), "ResponseClass"), "Success")) {
242 return; /* Error response */
245 /* MergedFreeBusy */
246 g_free(ews->free_busy);
247 ews->free_busy = xmlnode_get_data(xmlnode_get_descendant(resp, "FreeBusyView", "MergedFreeBusy", NULL));
249 /* WorkingHours */
250 node = xmlnode_get_descendant(resp, "FreeBusyView", "WorkingHours", NULL);
251 g_free(ews->working_hours_xml_str);
252 ews->working_hours_xml_str = xmlnode_to_str(node, NULL);
253 purple_debug_info("sipe", "sipe_ews_process_avail_response: ews->working_hours_xml_str:\n%s\n",
254 ews->working_hours_xml_str ? ews->working_hours_xml_str : "");
256 sipe_ews_cal_events_free(ews->cal_events);
257 ews->cal_events = NULL;
258 /* CalendarEvents */
259 for (node = xmlnode_get_descendant(resp, "FreeBusyView", "CalendarEventArray", "CalendarEvent", NULL);
260 node;
261 node = xmlnode_get_next_twin(node))
263 char *tmp;
265 <CalendarEvent>
266 <StartTime>2009-12-07T13:30:00</StartTime>
267 <EndTime>2009-12-07T14:30:00</EndTime>
268 <BusyType>Busy</BusyType>
269 <CalendarEventDetails>
270 <ID>0000000...</ID>
271 <Subject>Lunch</Subject>
272 <Location>Cafe</Location>
273 <IsMeeting>false</IsMeeting>
274 <IsRecurring>true</IsRecurring>
275 <IsException>false</IsException>
276 <IsReminderSet>true</IsReminderSet>
277 <IsPrivate>false</IsPrivate>
278 </CalendarEventDetails>
279 </CalendarEvent>
281 struct sipe_cal_event *cal_event = g_new0(struct sipe_cal_event, 1);
282 ews->cal_events = g_slist_append(ews->cal_events, cal_event);
284 tmp = xmlnode_get_data(xmlnode_get_child(node, "StartTime"));
285 cal_event->start_time = sipe_utils_str_to_time(tmp);
286 g_free(tmp);
288 tmp = xmlnode_get_data(xmlnode_get_child(node, "EndTime"));
289 cal_event->end_time = sipe_utils_str_to_time(tmp);
290 g_free(tmp);
292 tmp = xmlnode_get_data(xmlnode_get_child(node, "BusyType"));
293 if (sipe_strequal("Free", tmp)) {
294 cal_event->cal_status = SIPE_CAL_FREE;
295 } else if (sipe_strequal("Tentative", tmp)) {
296 cal_event->cal_status = SIPE_CAL_TENTATIVE;
297 } else if (sipe_strequal("Busy", tmp)) {
298 cal_event->cal_status = SIPE_CAL_BUSY;
299 } else if (sipe_strequal("OOF", tmp)) {
300 cal_event->cal_status = SIPE_CAL_OOF;
301 } else {
302 cal_event->cal_status = SIPE_CAL_NO_DATA;
304 g_free(tmp);
306 cal_event->subject = xmlnode_get_data(xmlnode_get_descendant(node, "CalendarEventDetails", "Subject", NULL));
307 cal_event->location = xmlnode_get_data(xmlnode_get_descendant(node, "CalendarEventDetails", "Location", NULL));
309 tmp = xmlnode_get_data(xmlnode_get_descendant(node, "CalendarEventDetails", "IsMeeting", NULL));
310 cal_event->is_meeting = tmp ? sipe_strequal(tmp, "true") : TRUE;
311 g_free(tmp);
314 xmlnode_free(xml);
316 ews->state = SIPE_EWS_STATE_AVAILABILITY_SUCCESS;
317 sipe_ews_run_state_machine(ews);
319 } else if (return_code < 0) {
320 ews->http_conn = NULL;
324 static void
325 sipe_ews_process_oof_response(int return_code,
326 const char *body,
327 HttpConn *conn,
328 void *data)
330 struct sipe_ews *ews = data;
332 purple_debug_info("sipe", "sipe_ews_process_oof_response: cb started.\n");
334 http_conn_set_close(conn);
335 ews->http_conn = NULL;
337 if (return_code == 200 && body) {
338 char *old_note;
339 xmlnode *resp;
340 xmlnode *xn_duration;
341 /** ref: [MS-OXWOOF] */
342 xmlnode *xml = xmlnode_from_str(body, strlen(body));
343 /* Envelope/Body/GetUserOofSettingsResponse/ResponseMessage@ResponseClass="Success"
344 * Envelope/Body/GetUserOofSettingsResponse/OofSettings/OofState=Enabled
345 * Envelope/Body/GetUserOofSettingsResponse/OofSettings/Duration/StartTime
346 * Envelope/Body/GetUserOofSettingsResponse/OofSettings/Duration/EndTime
347 * Envelope/Body/GetUserOofSettingsResponse/OofSettings/InternalReply/Message
349 resp = xmlnode_get_descendant(xml, "Body", "GetUserOofSettingsResponse", NULL);
350 if (!resp) return; /* rather soap:Fault */
351 if (!sipe_strequal(xmlnode_get_attrib(xmlnode_get_child(resp, "ResponseMessage"), "ResponseClass"), "Success")) {
352 return; /* Error response */
355 g_free(ews->oof_state);
356 ews->oof_state = xmlnode_get_data(xmlnode_get_descendant(resp, "OofSettings", "OofState", NULL));
358 old_note = ews->oof_note;
359 ews->oof_note = NULL;
360 if (!sipe_strequal(ews->oof_state, "Disabled")) {
361 char *tmp = xmlnode_get_data(
362 xmlnode_get_descendant(resp, "OofSettings", "InternalReply", "Message", NULL));
363 char *html;
365 /* UTF-8 encoded BOM (0xEF 0xBB 0xBF) as a signature to mark the beginning of a UTF-8 file */
366 if (g_str_has_prefix(tmp, "\xEF\xBB\xBF")) {
367 html = g_strdup(tmp+3);
368 } else {
369 html = g_strdup(tmp);
371 g_free(tmp);
372 tmp = g_strstrip(purple_markup_strip_html(html));
373 g_free(html);
374 ews->oof_note = g_markup_escape_text(tmp, -1);
375 g_free(tmp);
378 if (sipe_strequal(ews->oof_state, "Scheduled")
379 && (xn_duration = xmlnode_get_descendant(resp, "OofSettings", "Duration", NULL)))
381 char *tmp = xmlnode_get_data(xmlnode_get_child(xn_duration, "StartTime"));
382 ews->oof_start = sipe_utils_str_to_time(tmp);
383 g_free(tmp);
385 tmp = xmlnode_get_data(xmlnode_get_child(xn_duration, "EndTime"));
386 ews->oof_end = sipe_utils_str_to_time(tmp);
387 g_free(tmp);
390 if (!sipe_strequal(old_note, ews->oof_note)) { /* oof note changed */
391 ews->updated = time(NULL);
392 ews->published = FALSE;
394 g_free(old_note);
396 xmlnode_free(xml);
398 ews->state = SIPE_EWS_STATE_OOF_SUCCESS;
399 sipe_ews_run_state_machine(ews);
401 } else if (return_code < 0) {
402 ews->http_conn = NULL;
406 static void
407 sipe_ews_process_autodiscover(int return_code,
408 const char *body,
409 HttpConn *conn,
410 void *data)
412 struct sipe_ews *ews = data;
414 purple_debug_info("sipe", "sipe_ews_process_autodiscover: cb started.\n");
416 http_conn_set_close(conn);
417 ews->http_conn = NULL;
419 if (return_code == 200 && body) {
420 xmlnode *node;
421 /** ref: [MS-OXDSCLI] */
422 xmlnode *xml = xmlnode_from_str(body, strlen(body));
424 /* Autodiscover/Response/User/LegacyDN (trim()) */
425 ews->legacy_dn = xmlnode_get_data(xmlnode_get_descendant(xml, "Response", "User", "LegacyDN", NULL));
426 ews->legacy_dn = ews->legacy_dn ? g_strstrip(ews->legacy_dn) : NULL;
428 /* Protocols */
429 for (node = xmlnode_get_descendant(xml, "Response", "Account", "Protocol", NULL);
430 node;
431 node = xmlnode_get_next_twin(node))
433 char *type = xmlnode_get_data(xmlnode_get_child(node, "Type"));
434 if (sipe_strequal("EXCH", type)) {
435 ews->as_url = xmlnode_get_data(xmlnode_get_child(node, "ASUrl"));
436 ews->oof_url = xmlnode_get_data(xmlnode_get_child(node, "OOFUrl"));
437 ews->oab_url = xmlnode_get_data(xmlnode_get_child(node, "OABUrl"));
439 purple_debug_info("sipe", "sipe_ews_process_autodiscover:as_url %s\n",
440 ews->as_url ? ews->as_url : "");
441 purple_debug_info("sipe", "sipe_ews_process_autodiscover:oof_url %s\n",
442 ews->oof_url ? ews->oof_url : "");
443 purple_debug_info("sipe", "sipe_ews_process_autodiscover:oab_url %s\n",
444 ews->oab_url ? ews->oab_url : "");
446 g_free(type);
447 break;
448 } else {
449 g_free(type);
450 continue;
454 xmlnode_free(xml);
456 ews->state = SIPE_EWS_STATE_AUTODISCOVER_SUCCESS;
457 sipe_ews_run_state_machine(ews);
459 } else {
460 if (return_code < 0) {
461 ews->http_conn = NULL;
463 switch (ews->auto_disco_method) {
464 case 1:
465 ews->state = SIPE_EWS_STATE_AUTODISCOVER_1_FAILURE; break;
466 case 2:
467 ews->state = SIPE_EWS_STATE_AUTODISCOVER_2_FAILURE; break;
469 sipe_ews_run_state_machine(ews);
473 static void
474 sipe_ews_do_autodiscover(struct sipe_ews *ews,
475 const char* autodiscover_url)
477 char *body;
479 purple_debug_info("sipe", "sipe_ews_do_autodiscover: going autodiscover url=%s\n", autodiscover_url ? autodiscover_url : "");
481 body = g_strdup_printf(SIPE_EWS_AUTODISCOVER_REQUEST, ews->email);
482 ews->http_conn = http_conn_create(
483 ews->account,
484 HTTP_CONN_SSL,
485 autodiscover_url,
486 body,
487 "text/xml",
488 ews->auth,
489 sipe_ews_process_autodiscover,
490 ews);
491 g_free(body);
494 static void
495 sipe_ews_do_avail_request(struct sipe_ews *ews)
497 if (ews->as_url) {
498 char *body;
499 time_t end;
500 time_t now = time(NULL);
501 char *start_str;
502 char *end_str;
503 struct tm *now_tm;
505 purple_debug_info("sipe", "sipe_ews_do_avail_request: going Availability req.\n");
507 now_tm = gmtime(&now);
508 /* start -1 day, 00:00:00 */
509 now_tm->tm_sec = 0;
510 now_tm->tm_min = 0;
511 now_tm->tm_hour = 0;
512 ews->fb_start = sipe_mktime_tz(now_tm, "UTC");
513 ews->fb_start -= 24*60*60;
514 /* end = start + 4 days - 1 sec */
515 end = ews->fb_start + 4*(24*60*60) - 1;
517 start_str = sipe_utils_time_to_str(ews->fb_start);
518 end_str = sipe_utils_time_to_str(end);
520 body = g_strdup_printf(SIPE_EWS_USER_AVAILABILITY_REQUEST, ews->email, start_str, end_str);
521 ews->http_conn = http_conn_create(
522 ews->account,
523 HTTP_CONN_SSL,
524 ews->as_url,
525 body,
526 "text/xml; charset=UTF-8",
527 ews->auth,
528 sipe_ews_process_avail_response,
529 ews);
530 g_free(body);
531 g_free(start_str);
532 g_free(end_str);
536 static void
537 sipe_ews_do_oof_request(struct sipe_ews *ews)
539 if (ews->oof_url) {
540 char *body;
541 const char *content_type = "text/xml; charset=UTF-8";
543 purple_debug_info("sipe", "sipe_ews_do_oof_request: going OOF req.\n");
545 body = g_strdup_printf(SIPE_EWS_USER_OOF_SETTINGS_REQUEST, ews->email);
546 if (!ews->http_conn) {
547 ews->http_conn = http_conn_create(ews->account,
548 HTTP_CONN_SSL,
549 ews->oof_url,
550 body,
551 content_type,
552 ews->auth,
553 sipe_ews_process_oof_response,
554 ews);
555 } else {
556 http_conn_post(ews->http_conn,
557 ews->oof_url,
558 body,
559 content_type,
560 sipe_ews_process_oof_response,
561 ews);
563 g_free(body);
567 static void
568 sipe_ews_run_state_machine(struct sipe_ews *ews)
570 switch (ews->state) {
571 case SIPE_EWS_STATE_NONE:
573 char *maildomain = strstr(ews->email, "@") + 1;
574 char *autodisc_url = g_strdup_printf("https://Autodiscover.%s/Autodiscover/Autodiscover.xml", maildomain);
576 ews->auto_disco_method = 1;
578 sipe_ews_do_autodiscover(ews, autodisc_url);
580 g_free(autodisc_url);
581 break;
583 case SIPE_EWS_STATE_AUTODISCOVER_1_FAILURE:
585 char *maildomain = strstr(ews->email, "@") + 1;
586 char *autodisc_url = g_strdup_printf("https://%s/Autodiscover/Autodiscover.xml", maildomain);
588 ews->auto_disco_method = 2;
590 sipe_ews_do_autodiscover(ews, autodisc_url);
592 g_free(autodisc_url);
593 break;
595 case SIPE_EWS_STATE_AUTODISCOVER_2_FAILURE:
596 ews->is_disabled = TRUE;
597 break;
598 case SIPE_EWS_STATE_AUTODISCOVER_SUCCESS:
599 sipe_ews_do_avail_request(ews);
600 break;
601 case SIPE_EWS_STATE_AVAILABILITY_SUCCESS:
602 sipe_ews_do_oof_request(ews);
603 break;
604 case SIPE_EWS_STATE_OOF_SUCCESS:
605 ews->state = SIPE_EWS_STATE_AUTODISCOVER_SUCCESS;
606 ews->is_updated = TRUE;
607 if (ews->sip->ocs2007) {
608 /* sipe.h */
609 publish_calendar_status_self(ews->sip);
610 } else {
611 /* sipe.h */
612 send_presence_soap(ews->sip, TRUE);
614 break;
618 void
619 sipe_ews_update_calendar(struct sipe_account_data *sip)
621 //char *autodisc_srv = g_strdup_printf("_autodiscover._tcp.%s", maildomain);
623 purple_debug_info("sipe", "sipe_ews_update_calendar: started.\n");
625 if (!sip->ews) {
626 const char *value;
628 sip->ews = g_new0(struct sipe_ews, 1);
629 sip->ews->sip = sip;
631 sip->ews->account = sip->account;
632 sip->ews->email = g_strdup(sip->email);
634 /* user specified a service URL? */
635 value = purple_account_get_string(sip->account, "email_url", NULL);
636 if (!is_empty(value)) {
637 sip->ews->as_url = g_strdup(value);
638 sip->ews->oof_url = g_strdup(value);
639 sip->ews->state = SIPE_EWS_STATE_AUTODISCOVER_SUCCESS;
642 sip->ews->auth = g_new0(HttpConnAuth, 1);
643 sip->ews->auth->use_negotiate = purple_account_get_bool(sip->account, "krb5", FALSE);
645 /* user specified email login? */
646 value = purple_account_get_string(sip->account, "email_login", NULL);
647 if (!is_empty(value)) {
649 /* user specified email login domain? */
650 const char *tmp = strstr(value, "\\");
651 if (tmp) {
652 sip->ews->auth->domain = g_strndup(value, tmp - value);
653 sip->ews->auth->user = g_strdup(tmp + 1);
654 } else {
655 sip->ews->auth->user = g_strdup(value);
657 sip->ews->auth->password = g_strdup(purple_account_get_string(sip->account, "email_password", NULL));
659 } else {
660 /* re-use SIPE credentials */
661 sip->ews->auth->domain = g_strdup(sip->authdomain);
662 sip->ews->auth->user = g_strdup(sip->authuser);
663 sip->ews->auth->password = g_strdup(sip->password);
667 if(sip->ews->is_disabled) {
668 purple_debug_info("sipe", "sipe_ews_update_calendar: disabled, exiting.\n");
669 return;
672 sipe_ews_run_state_machine(sip->ews);
674 purple_debug_info("sipe", "sipe_ews_update_calendar: finished.\n");
680 Local Variables:
681 mode: c
682 c-file-style: "bsd"
683 indent-tabs-mode: t
684 tab-width: 8
685 End: