33#include <libical/ical.h>
34#include <ne_session.h>
36#include <ne_request.h>
38#include <ne_redirect.h>
55 .description =
"MS Exchange calendars",
88 if ((
tmp = strchr(
name,
':'))) {
98 if (!strcasecmp(
state->tag,
"response")) {
101 state->in_response = 1;
106 }
else if (!strcasecmp(
state->tag,
"propstat")) {
107 state->in_propstat = 1;
108 }
else if (!strcasecmp(
state->tag,
"prop")) {
114 if (!strcasecmp(
state->tag,
"response")) {
118 state->in_response = 0;
126 }
else if (!strcasecmp(
state->tag,
"propstat")) {
127 state->in_propstat = 0;
128 }
else if (!strcasecmp(
state->tag,
"prop")) {
144 for (read = write =
mstime; *read; read++) {
150 if (*read ==
'-' || *read ==
':')
156 tt = icaltime_from_string(
mstime);
157 return icaltime_as_timet(tt);
162 if (!strcasecmp(msbusy,
"FREE")) {
164 }
else if (!strcasecmp(msbusy,
"TENTATIVE")) {
193 if (!strcasecmp(
state->tag,
"subject")) {
195 }
else if (!strcasecmp(
state->tag,
"location")) {
197 }
else if (!strcasecmp(
state->tag,
"uid")) {
199 }
else if (!strcasecmp(
state->tag,
"organizer")) {
201 }
else if (!strcasecmp(
state->tag,
"textdescription")) {
203 }
else if (!strcasecmp(
state->tag,
"dtstart")) {
205 }
else if (!strcasecmp(
state->tag,
"dtend")) {
207 }
else if (!strcasecmp(
state->tag,
"busystatus")) {
209 }
else if (!strcasecmp(
state->tag,
"reminderoffset")) {
212 event->alarm =
event->start - atoi(
str);
225 ne_session_destroy(pvt->
session);
227 ne_uri_free(&pvt->
uri);
273 strcpy(
buf,
""");
277 strcpy(
buf,
"'");
281 strcpy(
buf,
"&");
304 icaltimezone *utc = icaltimezone_get_utc_timezone();
305 icaltimetype tt = icaltime_from_timet_with_zone(epoch, 0, utc);
310 for (i = 0;
tmp[i]; i++) {
312 if (i == 3 || i == 5)
314 if (i == 10 || i == 12)
343 struct ast_str **response = data;
357static int auth_credentials(
void *userdata,
const char *realm,
int attempts,
char *username,
char *secret)
366 ne_strnzcpy(username, pvt->
user, NE_ABUFSIZ);
394 ne_add_request_header(req,
"Content-type",
"text/xml");
396 ret = ne_request_dispatch(req);
397 ne_request_destroy(req);
457 ast_log(
LOG_WARNING,
"An invalid uid was provided, you may leave this field blank to have one generated for you\n");
470 "<?xml version=\"1.0\"?>\n"
471 "<a:propertyupdate\n"
472 " xmlns:a=\"DAV:\"\n"
473 " xmlns:e=\"http://schemas.microsoft.com/exchange/\"\n"
474 " xmlns:mapi=\"http://schemas.microsoft.com/mapi/\"\n"
475 " xmlns:mapit=\"http://schemas.microsoft.com/mapi/proptag/\"\n"
476 " xmlns:x=\"xml:\" xmlns:cal=\"urn:schemas:calendar:\"\n"
477 " xmlns:dt=\"uuid:%s/\"\n"
478 " xmlns:header=\"urn:schemas:mailheader:\"\n"
479 " xmlns:mail=\"urn:schemas:httpmail:\"\n"
483 " <a:contentclass>urn:content-classes:appointment</a:contentclass>\n"
484 " <e:outlookmessageclass>IPM.Appointment</e:outlookmessageclass>\n"
485 " <mail:subject>%s</mail:subject>\n"
486 " <mail:description>%s</mail:description>\n"
487 " <header:to>%s</header:to>\n"
488 " <cal:location>%s</cal:location>\n"
489 " <cal:dtstart dt:dt=\"dateTime.tz\">%s</cal:dtstart>\n"
490 " <cal:dtend dt:dt=\"dateTime.tz\">%s</cal:dtend>\n"
491 " <cal:instancetype dt:dt=\"int\">0</cal:instancetype>\n"
492 " <cal:busystatus>%s</cal:busystatus>\n"
493 " <cal:meetingstatus>CONFIRMED</cal:meetingstatus>\n"
494 " <cal:alldayevent dt:dt=\"boolean\">0</cal:alldayevent>\n"
495 " <cal:responserequested dt:dt=\"boolean\">0</cal:responserequested>\n"
496 " <mapi:finvited dt:dt=\"boolean\">1</mapi:finvited>\n"
499 "</a:propertyupdate>\n",
534 struct ast_str *body, *response;
535 char start[80],
end[80];
536 struct timeval tv = {0,};
539 tv.tv_sec = start_time;
543 tv.tv_sec = end_time;
553 "<?xml version=\"1.0\"?>\n"
554 "<g:searchrequest xmlns:g=\"DAV:\">\n"
555 " <g:sql> SELECT \"urn:schemas:calendar:location\", \"urn:schemas:httpmail:subject\",\n"
556 " \"urn:schemas:calendar:dtstart\", \"urn:schemas:calendar:dtend\",\n"
557 " \"urn:schemas:calendar:busystatus\", \"urn:schemas:calendar:instancetype\",\n"
558 " \"urn:schemas:calendar:uid\", \"urn:schemas:httpmail:textdescription\",\n"
559 " \"urn:schemas:calendar:organizer\", \"urn:schemas:calendar:reminderoffset\"\n"
560 " FROM Scope('SHALLOW TRAVERSAL OF \"%s/Calendar\"')\n"
561 " WHERE NOT \"urn:schemas:calendar:instancetype\" = 1\n"
562 " AND \"DAV:contentclass\" = 'urn:content-classes:appointment'\n"
563 " AND NOT (\"urn:schemas:calendar:dtend\" < '%s'\n"
564 " OR \"urn:schemas:calendar:dtstart\" > '%s')\n"
565 " ORDER BY \"urn:schemas:calendar:dtstart\" ASC\n"
567 "</g:searchrequest>\n", pvt->
url, start,
end);
609 ast_log(
LOG_ERROR,
"You must enable calendar support for res_exchangecal to load\n");
624 ast_log(
LOG_ERROR,
"Could not allocate exchangecal_pvt structure for calendar: %s\n", cal->
name);
632 ast_log(
LOG_ERROR,
"Could not allocate space for fetching events for calendar: %s\n", cal->
name);
648 if (!strcasecmp(v->
name,
"url")) {
650 }
else if (!strcasecmp(v->
name,
"user")) {
652 }
else if (!strcasecmp(v->
name,
"secret")) {
674 pvt->
uri.scheme =
"http";
677 if (pvt->
uri.port == 0) {
678 pvt->
uri.port = ne_uri_defaultport(pvt->
uri.scheme);
681 pvt->
session = ne_session_create(pvt->
uri.scheme, pvt->
uri.host, pvt->
uri.port);
682 ne_redirect_register(pvt->
session);
684 if (!strcasecmp(pvt->
uri.scheme,
"https")) {
685 ne_ssl_trust_default_ca(pvt->
session);
700 struct timespec ts = {0,};
713 ast_debug(10,
"Skipping refresh since we got a shutdown signal\n");
748 .
requires =
"res_calendar",
static const struct adsi_event events[]
Asterisk main include file. File version handling, generic pbx functions.
#define ast_calloc(num, len)
A wrapper for calloc()
#define ast_malloc(len)
A wrapper for malloc()
#define ao2_link(container, obj)
Add an object to a container.
#define ao2_callback(c, flags, cb_fn, arg)
ao2_callback() is a generic function that applies cb_fn() to all objects in a container,...
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
#define ao2_alloc(data_size, destructor_fn)
A general API for managing calendar events with Asterisk.
void ast_calendar_unregister(struct ast_calendar_tech *tech)
Unregister a new calendar technology.
void ast_calendar_merge_events(struct ast_calendar *cal, struct ao2_container *new_events)
Add an event to the list of events for a calendar.
void ast_calendar_config_release(void)
Release the calendar config.
@ AST_CALENDAR_BS_BUSY_TENTATIVE
struct ao2_container * ast_calendar_event_container_alloc(void)
Allocate an astobj2 container for ast_calendar_event objects.
int ast_calendar_register(struct ast_calendar_tech *tech)
Register a new calendar technology.
struct ast_calendar_event * ast_calendar_event_alloc(struct ast_calendar *cal)
Allocate an astobj2 ast_calendar_event object.
struct ast_calendar_event * ast_calendar_unref_event(struct ast_calendar_event *event)
Unreference an ast_calendar_event.
const struct ast_config * ast_calendar_config_acquire(void)
Grab and lock pointer to the calendar config (read only)
General Asterisk PBX channel definitions.
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
Configuration File Parser.
struct ast_variable * ast_variable_browse(const struct ast_config *config, const char *category_name)
#define ast_debug(level,...)
Log a DEBUG message.
#define ast_verb(level,...)
struct ast_tm * ast_localtime(const struct timeval *timep, struct ast_tm *p_tm, const char *zone)
Timezone-independent version of localtime_r(3).
int ast_strftime(char *buf, size_t len, const char *format, const struct ast_tm *tm)
Special version of strftime(3) that handles fractions of a second. Takes the same arguments as strfti...
Asterisk locking-related definitions:
#define ast_cond_timedwait(cond, mutex, time)
#define ast_mutex_init(pmutex)
#define ast_mutex_unlock(a)
#define ast_mutex_lock(a)
Asterisk module definitions.
#define AST_MODULE_INFO(keystr, flags_to_set, desc, fields...)
@ AST_MODPRI_DEVSTATE_PLUGIN
@ AST_MODULE_SUPPORT_EXTENDED
#define ASTERISK_GPL_KEY
The text the key() function should return.
@ AST_MODULE_LOAD_SUCCESS
@ AST_MODULE_LOAD_DECLINE
Module has failed to load, may be in an inconsistent state.
static ast_mutex_t refreshlock
static const char * mstime(time_t t, char *buf, size_t buflen)
static struct ast_str * epoch_to_exchange_time(struct ast_str *dst, time_t epoch)
static void * exchangecal_load_calendar(void *data)
static void exchangecal_destructor(void *obj)
static int update_exchangecal(struct exchangecal_pvt *pvt)
static struct ast_calendar_tech exchangecal_tech
static void * unref_exchangecal(void *obj)
static struct ast_str * generate_exchange_uuid(struct ast_str *uid)
static enum ast_calendar_busy_state msbusy_to_bs(const char *msbusy)
static int exchangecal_write_event(struct ast_calendar_event *event)
static time_t mstime_to_time_t(char *mstime)
static int parse_tag(void *data, char *name, char **atts, int type)
static int is_valid_uuid(struct ast_str *uid)
static struct ast_str * bs_to_exchange_bs(struct ast_str *dst, enum ast_calendar_busy_state bs)
static int parse_cdata(void *data, char *value, size_t len)
static int auth_credentials(void *userdata, const char *realm, int attempts, char *username, char *secret)
static int fetch_response_reader(void *data, const char *block, size_t len)
static struct ast_str * exchangecal_request(struct exchangecal_pvt *pvt, const char *method, struct ast_str *req_body, struct ast_str *subdir)
static int load_module(void)
static int unload_module(void)
static struct ast_str * exchangecal_get_events_between(struct exchangecal_pvt *pvt, time_t start_time, time_t end_time)
static struct ast_str * xml_encode_str(struct ast_str *dst, const char *src)
#define AST_DECLARE_STRING_FIELDS(field_list)
Declare the fields needed in a structure.
#define AST_STRING_FIELD(name)
Declare a string field.
#define ast_string_field_set(x, field, data)
Set a field to a simple string value.
#define ast_string_field_init(x, size)
Initialize a field pool and fields.
#define ast_string_field_build(x, field, fmt, args...)
Set a field to a complex (built) value.
#define ast_string_field_free_memory(x)
free all memory - to be called before destroying the object
int ast_str_append(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Append to a thread local dynamic string.
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
static force_inline int attribute_pure ast_strlen_zero(const char *s)
#define ast_str_create(init_len)
Create a malloc'ed dynamic length string.
int ast_str_set(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Set a dynamic string using variable arguments.
size_t ast_str_strlen(const struct ast_str *buf)
Returns the current length of the string stored within buf.
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
char * ast_skip_blanks(const char *str)
Gets a pointer to the first non-whitespace character in a string.
const ast_string_field uid
const ast_string_field location
const ast_string_field description
const ast_string_field organizer
const ast_string_field summary
Individual calendaring technology data.
Asterisk calendar structure.
const ast_string_field name
Structure for mutex and tracking information.
Support for dynamic strings.
Structure for variables, used for configurations and for channel variables.
struct ast_variable * next
const ast_string_field url
struct ast_calendar * owner
const ast_string_field user
struct ao2_container * events
const ast_string_field secret
structure to hold users read from users.conf
struct exchangecal_pvt * pvt
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
Universally unique identifier support.
struct ast_uuid * ast_str_to_uuid(char *str)
Convert a string to a UUID.
char * ast_uuid_generate_str(char *buf, size_t size)
Generate a UUID string.