33 #include <libical/ical.h>
34 #include <ne_session.h>
36 #include <ne_request.h>
38 #include <ne_redirect.h>
52 .description =
"iCalendar .ics calendars",
76 ne_session_destroy(pvt->
session);
79 icalcomponent_free(pvt->
data);
98 struct ast_str **response = data;
104 memcpy(tmp, block, len);
121 ne_strnzcpy(username, pvt->
user, NE_ABUFSIZ);
122 ne_strnzcpy(secret, pvt->
secret, NE_ABUFSIZ);
132 icalcomponent *comp = NULL;
144 req = ne_request_create(pvt->
session,
"GET", pvt->
uri.path);
147 ret = ne_request_dispatch(req);
148 ne_request_destroy(req);
169 tm.
tm_mon = time.month - 1;
193 icaltimezone *utc = icaltimezone_get_utc_timezone();
195 icalcomponent *valarm;
197 struct icaltriggertype trigger;
199 if (!(pvt && pvt->
owner)) {
209 start = icalcomponent_get_dtstart(comp);
210 end = icalcomponent_get_dtend(comp);
216 if ((prop = icalcomponent_get_first_property(comp, ICAL_SUMMARY_PROPERTY))) {
220 if ((prop = icalcomponent_get_first_property(comp, ICAL_DESCRIPTION_PROPERTY))) {
224 if ((prop = icalcomponent_get_first_property(comp, ICAL_ORGANIZER_PROPERTY))) {
228 if ((prop = icalcomponent_get_first_property(comp, ICAL_LOCATION_PROPERTY))) {
232 if ((prop = icalcomponent_get_first_property(comp, ICAL_CATEGORIES_PROPERTY))) {
236 if ((prop = icalcomponent_get_first_property(comp, ICAL_PRIORITY_PROPERTY))) {
237 event->priority = icalvalue_get_integer(icalproperty_get_value(prop));
240 if ((prop = icalcomponent_get_first_property(comp, ICAL_UID_PROPERTY))) {
243 ast_log(
LOG_WARNING,
"No UID found, but one is required. Generating, but updates may not be acurate\n");
248 snprintf(tmp,
sizeof(tmp),
"%ld", event->
start);
254 for (prop = icalcomponent_get_first_property(comp, ICAL_ATTENDEE_PROPERTY);
255 prop; prop = icalcomponent_get_next_property(comp, ICAL_ATTENDEE_PROPERTY)) {
259 if (!(attendee =
ast_calloc(1,
sizeof(*attendee)))) {
263 data = icalproperty_get_attendee(prop);
276 if (!(valarm = icalcomponent_get_first_component(comp, ICAL_VALARM_COMPONENT))) {
282 if (!(prop = icalcomponent_get_first_property(valarm, ICAL_TRIGGER_PROPERTY))) {
289 trigger = icalproperty_get_trigger(prop);
291 if (icaltriggertype_is_null_trigger(trigger)) {
298 if (!icaltime_is_null_time(trigger.time)) {
299 tmp = icaltime_convert_to_zone(trigger.time, utc);
300 event->alarm = icaltime_as_timet_with_zone(tmp, utc);
304 tmp = icaltime_add(start, trigger.duration);
305 event->alarm = icaltime_as_timet_with_zone(tmp, utc);
316 struct icaltimetype start_time, end_time;
334 start_time = icaltime_current_time_with_zone(icaltimezone_get_utc_timezone());
335 end_time = icaltime_current_time_with_zone(icaltimezone_get_utc_timezone());
337 icaltime_normalize(end_time);
339 for (iter = icalcomponent_get_first_component(pvt->
data, ICAL_VEVENT_COMPONENT);
341 iter = icalcomponent_get_next_component(pvt->
data, ICAL_VEVENT_COMPONENT))
358 ast_log(
LOG_ERROR,
"You must enable calendar support for res_icalendar to load\n");
380 ast_log(
LOG_ERROR,
"Could not allocate space for fetching events for calendar: %s\n", cal->
name);
396 if (!strcasecmp(v->
name,
"url")) {
398 }
else if (!strcasecmp(v->
name,
"user")) {
400 }
else if (!strcasecmp(v->
name,
"secret")) {
414 if (ne_uri_parse(pvt->
url, &pvt->
uri) || pvt->
uri.host == NULL || pvt->
uri.path == NULL) {
421 if (pvt->
uri.scheme == NULL) {
422 pvt->
uri.scheme =
"http";
425 if (pvt->
uri.port == 0) {
426 pvt->
uri.port = ne_uri_defaultport(pvt->
uri.scheme);
429 pvt->
session = ne_session_create(pvt->
uri.scheme, pvt->
uri.host, pvt->
uri.port);
430 ne_redirect_register(pvt->
session);
432 if (!strcasecmp(pvt->
uri.scheme,
"https")) {
433 ne_ssl_trust_default_ca(pvt->
session);
452 struct timespec ts = {0,};
465 ast_debug(10,
"Skipping refresh since we got a shutdown signal\n");
473 icalcomponent_free(pvt->
data);
static void * unref_icalendar(void *obj)
struct ast_calendar * owner
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 icalcomponent * fetch_icalendar(struct icalendar_pvt *pvt)
const ast_string_field user
const ast_string_field secret
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.
static void * ical_load_calendar(void *data)
#define ao2_callback(c, flags, cb_fn, arg)
struct ast_calendar_attendee * next
static time_t icalfloat_to_timet(icaltimetype time)
Structure for variables, used for configurations and for channel variables.
static void icalendar_add_event(icalcomponent *comp, struct icaltime_span *span, void *data)
Configuration File Parser.
struct ao2_container * events
int ast_str_append(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Append to a thread local dynamic string.
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...)
static struct ast_calendar_tech ical_tech
static void icalendar_update_events(struct icalendar_pvt *pvt)
struct ast_config * ast_calendar_config_acquire(void)
Grab and lock pointer to the calendar config (read only)
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.
static int fetch_response_reader(void *data, const char *block, size_t len)
static int auth_credentials(void *userdata, const char *realm, int attempts, char *username, char *secret)
static int load_module(void)
#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)
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)
A general API for managing calendar events with Asterisk.
const ast_string_field name
struct ast_calendar_event * ast_calendar_event_alloc(struct ast_calendar *cal)
Allocate an astobj2 ast_calendar_event object.
#define AST_LIST_INSERT_TAIL(head, elm, field)
Appends a list entry to the tail of a list.
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
static ast_mutex_t refreshlock
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
const ast_string_field url
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 void icalendar_destructor(void *obj)
struct ast_calendar_event * ast_calendar_unref_event(struct ast_calendar_event *event)
Unreference an ast_calendar_event.
structure to hold users read from users.conf
struct ast_calendar_event::attendees attendees
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.
struct timeval ast_mktime(struct ast_tm *const tmp, const char *zone)
Timezone-independent version of mktime(3).
Individual calendaring technology data.
struct ast_variable * next
#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)
Structure for mutex and tracking information.
#define ASTERISK_FILE_VERSION(file, version)
Register/unregister a source code file with the core.
static int unload_module(void)
#define ast_mutex_unlock(a)
#define ast_string_field_set(x, field, data)
Set a field to a simple string value.