32#include <libical/ical.h>
33#include <ne_session.h>
35#include <ne_request.h>
37#include <ne_redirect.h>
52 .description =
"iCalendar .ics calendars",
76 ne_session_destroy(pvt->
session);
79 icalcomponent_free(pvt->
data);
81 ne_uri_free(&pvt->
uri);
99 struct ast_str **response = data;
113static int auth_credentials(
void *userdata,
const char *realm,
int attempts,
char *username,
char *secret)
122 ne_strnzcpy(username, pvt->
user, NE_ABUFSIZ);
133 icalcomponent *comp =
NULL;
145 req = ne_request_create(pvt->
session,
"GET", pvt->
uri.path);
148 ret = ne_request_dispatch(req);
149 ne_request_destroy(req);
174 tm.
tm_mon = time.month - 1;
198 icaltimezone *utc = icaltimezone_get_utc_timezone();
200 icalcomponent *valarm;
202 struct icaltriggertype trigger;
204 if (!(pvt && pvt->
owner)) {
214 start = icalcomponent_get_dtstart(comp);
215 end = icalcomponent_get_dtend(comp);
221 if ((prop = icalcomponent_get_first_property(comp, ICAL_SUMMARY_PROPERTY))) {
225 if ((prop = icalcomponent_get_first_property(comp, ICAL_DESCRIPTION_PROPERTY))) {
229 if ((prop = icalcomponent_get_first_property(comp, ICAL_ORGANIZER_PROPERTY))) {
233 if ((prop = icalcomponent_get_first_property(comp, ICAL_LOCATION_PROPERTY))) {
237 if ((prop = icalcomponent_get_first_property(comp, ICAL_CATEGORIES_PROPERTY))) {
241 if ((prop = icalcomponent_get_first_property(comp, ICAL_PRIORITY_PROPERTY))) {
242 event->priority = icalvalue_get_integer(icalproperty_get_value(prop));
245 if ((prop = icalcomponent_get_first_property(comp, ICAL_UID_PROPERTY))) {
248 ast_log(
LOG_WARNING,
"No UID found, but one is required. Generating, but updates may not be accurate\n");
265 if (icalcomponent_get_first_property(comp, ICAL_RRULE_PROPERTY)
266 || icalcomponent_get_first_property(comp, ICAL_RDATE_PROPERTY)) {
267 icalcompiter comp_iter;
268 icaltimetype span_start = icaltime_from_timet_with_zone(
269 event->start, icaltime_is_date(start), icaltime_get_timezone(start));
271 icaltime_set_timezone(&span_start, icaltime_get_timezone(start));
272 for (comp_iter = icalcomponent_begin_component(pvt->
data, ICAL_VEVENT_COMPONENT);
273 icalcompiter_deref(&comp_iter);
274 icalcompiter_next(&comp_iter)) {
275 icalcomponent *vevent = icalcompiter_deref(&comp_iter);
276 icalproperty *uid = icalcomponent_get_first_property(vevent, ICAL_UID_PROPERTY);
278 if (uid && !strcmp(icalproperty_get_value_as_string(uid),
event->uid)) {
279 icaltimetype recurrence_id = icalcomponent_get_recurrenceid(vevent);
282 icaltime_set_timezone(&recurrence_id, icaltime_get_timezone(start));
284 if (!icaltime_compare(recurrence_id, span_start)
285 && icaltime_is_date(span_start) == icaltime_is_date(recurrence_id)) {
294 for (prop = icalcomponent_get_first_property(comp, ICAL_ATTENDEE_PROPERTY);
295 prop; prop = icalcomponent_get_next_property(comp, ICAL_ATTENDEE_PROPERTY)) {
299 if (!(attendee =
ast_calloc(1,
sizeof(*attendee)))) {
303 data = icalproperty_get_attendee(prop);
316 if (!(valarm = icalcomponent_get_first_component(comp, ICAL_VALARM_COMPONENT))) {
322 if (!(prop = icalcomponent_get_first_property(valarm, ICAL_TRIGGER_PROPERTY))) {
329 trigger = icalproperty_get_trigger(prop);
331 if (icaltriggertype_is_null_trigger(trigger)) {
338 if (!icaltime_is_null_time(trigger.time)) {
339 tmp = icaltime_convert_to_zone(trigger.time, utc);
340 event->alarm = icaltime_as_timet_with_zone(
tmp, utc);
344 tmp = icaltime_add(start, trigger.duration);
345 event->alarm = icaltime_as_timet_with_zone(
tmp, icaltime_get_timezone(start));
356 struct icaltimetype start_time, end_time;
374 start_time = icaltime_current_time_with_zone(icaltimezone_get_utc_timezone());
375 end_time = icaltime_current_time_with_zone(icaltimezone_get_utc_timezone());
377 end_time = icaltime_normalize(end_time);
379 for (iter = icalcomponent_get_first_component(pvt->
data, ICAL_VEVENT_COMPONENT);
381 iter = icalcomponent_get_next_component(pvt->
data, ICAL_VEVENT_COMPONENT))
398 ast_log(
LOG_ERROR,
"You must enable calendar support for res_icalendar to load\n");
420 ast_log(
LOG_ERROR,
"Could not allocate space for fetching events for calendar: %s\n", cal->
name);
436 if (!strcasecmp(v->
name,
"url")) {
438 }
else if (!strcasecmp(v->
name,
"user")) {
440 }
else if (!strcasecmp(v->
name,
"secret")) {
462 pvt->
uri.scheme =
"http";
465 if (pvt->
uri.port == 0) {
466 pvt->
uri.port = ne_uri_defaultport(pvt->
uri.scheme);
469 pvt->
session = ne_session_create(pvt->
uri.scheme, pvt->
uri.host, pvt->
uri.port);
470 ne_redirect_register(pvt->
session);
472 ne_set_useragent(pvt->
session,
"Asterisk");
473 if (!strcasecmp(pvt->
uri.scheme,
"https")) {
474 ne_ssl_trust_default_ca(pvt->
session);
493 struct timespec ts = {0,};
506 ast_debug(10,
"Skipping refresh since we got a shutdown signal\n");
514 icalcomponent_free(pvt->
data);
551 .
requires =
"res_calendar",
Asterisk main include file. File version handling, generic pbx functions.
#define ast_strdup(str)
A wrapper for strdup()
#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.
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_LIST_INSERT_TAIL(head, elm, field)
Appends a list entry to the tail of a list.
struct timeval ast_mktime(struct ast_tm *const tmp, const char *zone)
Timezone-independent version of mktime(3).
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 void icalendar_destructor(void *obj)
static icalcomponent * fetch_icalendar(struct icalendar_pvt *pvt)
static void icalendar_update_events(struct icalendar_pvt *pvt)
static void * ical_load_calendar(void *data)
static void * unref_icalendar(void *obj)
static int auth_credentials(void *userdata, const char *realm, int attempts, char *username, char *secret)
static struct ast_calendar_tech ical_tech
static int fetch_response_reader(void *data, const char *block, size_t len)
static time_t icalfloat_to_timet(icaltimetype time)
static int load_module(void)
static int unload_module(void)
static void icalendar_add_event(icalcomponent *comp, struct icaltime_span *span, void *data)
#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_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.
size_t ast_str_strlen(const struct ast_str *buf)
Returns the current length of the string stored within buf.
struct ast_calendar_attendee * next
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 association categories[]
int ast_time_t_to_string(time_t time, char *buf, size_t length)
Converts to a string representation of a time_t as decimal seconds since the epoch....
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().