34 #include <libical/ical.h>
35 #include <ne_session.h>
37 #include <ne_request.h>
39 #include <ne_redirect.h>
54 .description =
"MS Exchange calendars",
87 if ((tmp = strchr(name,
':'))) {
97 if (!strcasecmp(state->
tag,
"response")) {
105 }
else if (!strcasecmp(state->
tag,
"propstat")) {
107 }
else if (!strcasecmp(state->
tag,
"prop")) {
113 if (!strcasecmp(state->
tag,
"response")) {
125 }
else if (!strcasecmp(state->
tag,
"propstat")) {
127 }
else if (!strcasecmp(state->
tag,
"prop")) {
143 for (read = write = mstime; *read; read++) {
149 if (*read ==
'-' || *read ==
':')
155 tt = icaltime_from_string(mstime);
156 return icaltime_as_timet(tt);
161 if (!strcasecmp(msbusy,
"FREE")) {
163 }
else if (!strcasecmp(msbusy,
"TENTATIVE")) {
179 if (str == value + len)
185 memcpy(str, value, len);
192 if (!strcasecmp(state->
tag,
"subject")) {
194 }
else if (!strcasecmp(state->
tag,
"location")) {
196 }
else if (!strcasecmp(state->
tag,
"uid")) {
198 }
else if (!strcasecmp(state->
tag,
"organizer")) {
200 }
else if (!strcasecmp(state->
tag,
"textdescription")) {
202 }
else if (!strcasecmp(state->
tag,
"dtstart")) {
204 }
else if (!strcasecmp(state->
tag,
"dtend")) {
206 }
else if (!strcasecmp(state->
tag,
"busystatus")) {
208 }
else if (!strcasecmp(state->
tag,
"reminderoffset")) {
211 event->alarm =
event->start - atoi(str);
224 ne_session_destroy(pvt->
session);
244 unsigned short val[8];
247 for (x = 0; x < 8; x++) {
250 ast_str_set(&uid, 0,
"%04x%04x-%04x-%04x-%04x-%04x%04x%04x", (
unsigned)val[0],
251 (
unsigned)val[1], (
unsigned)val[2], (
unsigned)val[3], (
unsigned)val[4],
252 (
unsigned)val[5], (
unsigned)val[6], (
unsigned)val[7]);
266 if (i == 8 || i == 13 || i == 18 || i == 23) {
283 for (tmp = src; *tmp; tmp++) {
286 strcpy(buf,
""");
290 strcpy(buf,
"'");
294 strcpy(buf,
"&");
306 sprintf(buf,
"%c", *tmp);
317 icaltimezone *utc = icaltimezone_get_utc_timezone();
318 icaltimetype tt = icaltime_from_timet_with_zone(epoch, 0, utc);
323 for (i = 0; tmp[i]; i++) {
325 if (i == 3 || i == 5)
327 if (i == 10 || i == 12)
356 struct ast_str **response = data;
362 memcpy(tmp, block, len);
379 ne_strnzcpy(username, pvt->
user, NE_ABUFSIZ);
380 ne_strnzcpy(secret, pvt->
secret, NE_ABUFSIZ);
402 snprintf(buf,
sizeof(buf),
"%s%s", pvt->
uri.path, subdir ?
ast_str_buffer(subdir) :
"");
404 req = ne_request_create(pvt->
session, method, buf);
407 ne_add_request_header(req,
"Content-type",
"text/xml");
409 ret = ne_request_dispatch(req);
410 ne_request_destroy(req);
423 struct ast_str *body = NULL, *response = NULL, *subdir = NULL;
424 struct ast_str *uid = NULL, *summary = NULL, *description = NULL, *organizer = NULL,
425 *location = NULL, *start = NULL, *end = NULL, *busystate = NULL;
433 if (!(event->
start && event->
end)) {
462 ast_log(
LOG_WARNING,
"An invalid uid was provided, you may leave this field blank to have one generated for you\n");
475 "<?xml version=\"1.0\"?>\n"
476 "<a:propertyupdate\n"
477 " xmlns:a=\"DAV:\"\n"
478 " xmlns:e=\"http://schemas.microsoft.com/exchange/\"\n"
479 " xmlns:mapi=\"http://schemas.microsoft.com/mapi/\"\n"
480 " xmlns:mapit=\"http://schemas.microsoft.com/mapi/proptag/\"\n"
481 " xmlns:x=\"xml:\" xmlns:cal=\"urn:schemas:calendar:\"\n"
482 " xmlns:dt=\"uuid:%s/\"\n"
483 " xmlns:header=\"urn:schemas:mailheader:\"\n"
484 " xmlns:mail=\"urn:schemas:httpmail:\"\n"
488 " <a:contentclass>urn:content-classes:appointment</a:contentclass>\n"
489 " <e:outlookmessageclass>IPM.Appointment</e:outlookmessageclass>\n"
490 " <mail:subject>%s</mail:subject>\n"
491 " <mail:description>%s</mail:description>\n"
492 " <header:to>%s</header:to>\n"
493 " <cal:location>%s</cal:location>\n"
494 " <cal:dtstart dt:dt=\"dateTime.tz\">%s</cal:dtstart>\n"
495 " <cal:dtend dt:dt=\"dateTime.tz\">%s</cal:dtend>\n"
496 " <cal:instancetype dt:dt=\"int\">0</cal:instancetype>\n"
497 " <cal:busystatus>%s</cal:busystatus>\n"
498 " <cal:meetingstatus>CONFIRMED</cal:meetingstatus>\n"
499 " <cal:alldayevent dt:dt=\"boolean\">0</cal:alldayevent>\n"
500 " <cal:responserequested dt:dt=\"boolean\">0</cal:responserequested>\n"
501 " <mapi:finvited dt:dt=\"boolean\">1</mapi:finvited>\n"
504 "</a:propertyupdate>\n",
553 struct ast_str *body, *response;
554 char start[80], end[80];
555 struct timeval tv = {0,};
558 tv.tv_sec = start_time;
562 tv.tv_sec = end_time;
572 "<?xml version=\"1.0\"?>\n"
573 "<g:searchrequest xmlns:g=\"DAV:\">\n"
574 " <g:sql> SELECT \"urn:schemas:calendar:location\", \"urn:schemas:httpmail:subject\",\n"
575 " \"urn:schemas:calendar:dtstart\", \"urn:schemas:calendar:dtend\",\n"
576 " \"urn:schemas:calendar:busystatus\", \"urn:schemas:calendar:instancetype\",\n"
577 " \"urn:schemas:calendar:uid\", \"urn:schemas:httpmail:textdescription\",\n"
578 " \"urn:schemas:calendar:organizer\", \"urn:schemas:calendar:reminderoffset\"\n"
579 " FROM Scope('SHALLOW TRAVERSAL OF \"%s/Calendar\"')\n"
580 " WHERE NOT \"urn:schemas:calendar:instancetype\" = 1\n"
581 " AND \"DAV:contentclass\" = 'urn:content-classes:appointment'\n"
582 " AND NOT (\"urn:schemas:calendar:dtend\" < '%s'\n"
583 " OR \"urn:schemas:calendar:dtstart\" > '%s')\n"
584 " ORDER BY \"urn:schemas:calendar:dtstart\" ASC\n"
586 "</g:searchrequest>\n", pvt->
url, start, end);
628 ast_log(
LOG_ERROR,
"You must enable calendar support for res_exchangecal to load\n");
643 ast_log(
LOG_ERROR,
"Could not allocate exchangecal_pvt structure for calendar: %s\n", cal->
name);
651 ast_log(
LOG_ERROR,
"Could not allocate space for fetching events for calendar: %s\n", cal->
name);
667 if (!strcasecmp(v->
name,
"url")) {
669 }
else if (!strcasecmp(v->
name,
"user")) {
671 }
else if (!strcasecmp(v->
name,
"secret")) {
685 if (ne_uri_parse(pvt->
url, &pvt->
uri) || pvt->
uri.host == NULL || pvt->
uri.path == NULL) {
692 if (pvt->
uri.scheme == NULL) {
693 pvt->
uri.scheme =
"http";
696 if (pvt->
uri.port == 0) {
697 pvt->
uri.port = ne_uri_defaultport(pvt->
uri.scheme);
700 pvt->
session = ne_session_create(pvt->
uri.scheme, pvt->
uri.host, pvt->
uri.port);
701 ne_redirect_register(pvt->
session);
703 if (!strcasecmp(pvt->
uri.scheme,
"https")) {
704 ne_ssl_trust_default_ca(pvt->
session);
719 struct timespec ts = {0,};
732 ast_debug(10,
"Skipping refresh since we got a shutdown signal\n");
Asterisk locking-related definitions:
int ast_calendar_register(struct ast_calendar_tech *tech)
Register a new calendar technology.
Asterisk main include file. File version handling, generic pbx functions.
#define ao2_link(arg1, arg2)
static int fetch_response_reader(void *data, const char *block, size_t len)
static struct ast_str * xml_encode_str(struct ast_str *dst, const char *src)
static time_t mstime_to_time_t(char *mstime)
static int update_exchangecal(struct exchangecal_pvt *pvt)
struct ast_variable * ast_variable_browse(const struct ast_config *config, const char *category)
Goes through variables.
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
const ast_string_field secret
#define ao2_callback(c, flags, cb_fn, arg)
struct ast_tm * ast_localtime(const struct timeval *timep, struct ast_tm *p_tm, const char *zone)
Timezone-independent version of localtime_r(3).
Structure for variables, used for configurations and for channel variables.
static int unload_module(void)
Configuration File Parser.
int ast_str_append(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Append to a thread local dynamic string.
struct ast_calendar * owner
const ast_string_field uid
enum ast_calendar_busy_state busy_state
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
#define AST_DECLARE_STRING_FIELDS(field_list)
Declare the fields needed in a structure.
struct ast_str * ast_str_create(size_t init_len)
Create a malloc'ed dynamic length string.
#define ast_mutex_lock(a)
#define AST_MODULE_INFO(keystr, flags_to_set, desc, fields...)
const ast_string_field user
static void * unref_exchangecal(void *obj)
static int load_module(void)
const ast_string_field description
#define ast_verb(level,...)
const ast_string_field organizer
struct ast_config * ast_calendar_config_acquire(void)
Grab and lock pointer to the calendar config (read only)
static struct ast_str * bs_to_exchange_bs(struct ast_str *dst, enum ast_calendar_busy_state bs)
int ast_str_set(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Set a dynamic string using variable arguments.
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.
#define ast_debug(level,...)
Log a DEBUG message.
const ast_string_field location
struct exchangecal_pvt * pvt
#define ast_string_field_init(x, size)
Initialize a field pool and fields.
static force_inline int attribute_pure ast_strlen_zero(const char *s)
static int auth_credentials(void *userdata, const char *realm, int attempts, char *username, char *secret)
struct ao2_container * ast_calendar_event_container_alloc(void)
Allocate an astobj2 container for ast_calendar_event objects.
#define AST_STRING_FIELD(name)
Declare a string field.
#define ao2_ref(o, delta)
long int ast_random(void)
A general API for managing calendar events with Asterisk.
const ast_string_field name
static int exchangecal_write_event(struct ast_calendar_event *event)
struct ast_calendar_event * ast_calendar_event_alloc(struct ast_calendar *cal)
Allocate an astobj2 ast_calendar_event object.
struct ast_calendar * owner
static int is_valid_uuid(struct ast_str *uid)
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
static struct ast_calendar_tech exchangecal_tech
static ast_mutex_t refreshlock
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
char * ast_skip_blanks(const char *str)
Gets a pointer to the first non-whitespace character in a string.
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
#define ao2_alloc(data_size, destructor_fn)
static struct ast_str * generate_exchange_uuid(struct ast_str *uid)
struct ast_calendar * owner
static const char * mstime(time_t t, char *buf, size_t buflen)
static int parse_tag(void *data, char *name, char **atts, int type)
static struct ast_str * exchangecal_get_events_between(struct exchangecal_pvt *pvt, time_t start_time, time_t end_time)
struct ao2_container * events
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...
struct ast_calendar_event * ast_calendar_unref_event(struct ast_calendar_event *event)
Unreference an ast_calendar_event.
static struct ast_str * exchangecal_request(struct exchangecal_pvt *pvt, const char *method, struct ast_str *req_body, struct ast_str *subdir)
structure to hold users read from users.conf
#define ast_string_field_build(x, field, fmt, args...)
Set a field to a complex (built) value.
static void * exchangecal_load_calendar(void *data)
void ast_calendar_unregister(struct ast_calendar_tech *tech)
Unregister a new calendar technology.
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.
Individual calendaring technology data.
const ast_string_field url
struct ast_variable * next
static struct adsi_event events[]
#define ast_mutex_init(pmutex)
Asterisk calendar structure.
void ast_calendar_config_release(void)
Release the calendar config.
#define ASTERISK_GPL_KEY
The text the key() function should return.
Asterisk module definitions.
const ast_string_field summary
#define ast_string_field_free_memory(x)
free all memory - to be called before destroying the object
#define ast_cond_timedwait(cond, mutex, time)
static int parse_cdata(void *data, char *value, size_t len)
static enum ast_calendar_busy_state msbusy_to_bs(const char *msbusy)
Structure for mutex and tracking information.
#define ASTERISK_FILE_VERSION(file, version)
Register/unregister a source code file with the core.
#define ast_mutex_unlock(a)
#define ast_string_field_set(x, field, data)
Set a field to a simple string value.
struct ao2_container * events
static struct ast_str * epoch_to_exchange_time(struct ast_str *dst, time_t epoch)
static void exchangecal_destructor(void *obj)