[asterisk-commits] twilson: branch twilson/calendaring r166951 - /team/twilson/calendaring/main/
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Wed Dec 31 12:18:11 CST 2008
Author: twilson
Date: Wed Dec 31 12:18:11 2008
New Revision: 166951
URL: http://svn.digium.com/view/asterisk?view=rev&rev=166951
Log:
rework long bit of code into its own function as per russell on reviewboard
Modified:
team/twilson/calendaring/main/calendar.c
Modified: team/twilson/calendaring/main/calendar.c
URL: http://svn.digium.com/view/asterisk/team/twilson/calendaring/main/calendar.c?view=diff&rev=166951&r1=166950&r2=166951
==============================================================================
--- team/twilson/calendaring/main/calendar.c (original)
+++ team/twilson/calendaring/main/calendar.c Wed Dec 31 12:18:11 2008
@@ -629,15 +629,68 @@
ao2_callback(new_events, OBJ_UNLINK | OBJ_NODATA | OBJ_MULTIPLE, add_new_event_cb, cal->events);
}
+static struct ast_calendar *build_calendar(struct ast_config *cfg, const char *cat, const struct ast_calendar_tech *tech)
+{
+ struct ast_calendar *cal;
+ struct ast_variable *v;
+
+ if (!(cal = ao2_alloc(sizeof(*cal), calendar_destructor))) {
+ ast_log(LOG_ERROR, "Could not allocate calendar structure. Stopping.\n");
+ return NULL;
+ }
+
+ if (!(cal->events = ao2_container_alloc(MAX_BUCKETS, event_hash_fn, event_cmp_fn))) {
+ ast_log(LOG_ERROR, "Could not allocate events container for %s\n", cat);
+ cal = unref_calendar(cal);
+ return NULL;
+ }
+
+ if (ast_string_field_init(cal, 32)) {
+ ast_log(LOG_ERROR, "Couldn't create string fields for %s\n", cat);
+ cal = unref_calendar(cal);
+ return NULL;
+ }
+
+ ast_string_field_set(cal, name, cat);
+ cal->tech = tech;
+
+ cal->refresh = 3600;
+ cal->timeframe = 60;
+
+ for (v = ast_variable_browse(cfg, cat); v; v = v->next) {
+ if (!strcasecmp(v->name, "autoreminder")) {
+ cal->autoreminder = atoi(v->value);
+ } else if (!strcasecmp(v->name, "channel")) {
+ ast_string_field_set(cal, notify_channel, v->value);
+ } else if (!strcasecmp(v->name, "context")) {
+ ast_string_field_set(cal, notify_context, v->value);
+ } else if (!strcasecmp(v->name, "extension")) {
+ ast_string_field_set(cal, notify_extension, v->value);
+ } else if (!strcasecmp(v->name, "waittime")) {
+ cal->notify_waittime = atoi(v->value);
+ } else if (!strcasecmp(v->name, "app")) {
+ ast_string_field_set(cal, notify_app, v->value);
+ } else if (!strcasecmp(v->name, "appdata")) {
+ ast_string_field_set(cal, notify_appdata, v->value);
+ } else if (!strcasecmp(v->name, "refresh")) {
+ cal->refresh = atoi(v->value);
+ } else if (!strcasecmp(v->name, "timeframe")) {
+ cal->timeframe = atoi(v->value);
+ }
+ }
+
+ cal->thread = AST_PTHREADT_NULL;
+ ast_cond_init(&cal->unload, NULL);
+
+ return cal;
+}
+
static int load_config(void *data)
{
struct ast_config *cfg;
const char *cat = NULL;
- struct ast_variable *v;
struct ast_flags config_flags = { 0 };
const char *val;
- struct ast_calendar *cal;
- const struct ast_calendar_tech *tech;
while (!ast_test_flag(&ast_options, AST_OPT_FLAG_FULLY_BOOTED)) {
sleep(1);
@@ -658,7 +711,10 @@
ast_debug(1, "Enabling calendar support\n");
}
} else {
+ struct ast_calendar *cal;
+ const struct ast_calendar_tech *tech;
struct ast_calendar_load_data *load_data;
+ const char *val;
if (!(val = ast_variable_retrieve(cfg, cat, "type"))) {
ast_log(LOG_WARNING, "Calendar '%s' has no type, skipping!\n", cat);
@@ -670,56 +726,10 @@
continue;
}
- if (!(cal = ao2_alloc(sizeof(*cal), calendar_destructor))) {
- ast_log(LOG_ERROR, "Could not allocate calendar structure. Stopping.\n");
+ if (!(cal = build_calendar(cfg, cat, tech))) {
ast_config_destroy(cfg);
return -1;
}
-
- if (!(cal->events = ao2_container_alloc(MAX_BUCKETS, event_hash_fn, event_cmp_fn))) {
- ast_log(LOG_ERROR, "Could not allocate events container for %s\n", cat);
- cal = unref_calendar(cal);
- ast_config_destroy(cfg);
- return -1;
- }
-
- if (ast_string_field_init(cal, 32)) {
- ast_log(LOG_ERROR, "Couldn't create string fields for %s\n", cat);
- cal = unref_calendar(cal);
- ast_config_destroy(cfg);
- return -1;
- }
-
- ast_string_field_set(cal, name, cat);
- cal->tech = tech;
-
- cal->refresh = 3600;
- cal->timeframe = 60;
-
- for (v = ast_variable_browse(cfg, cat); v; v = v->next) {
- if (!strcasecmp(v->name, "autoreminder")) {
- cal->autoreminder = atoi(v->value);
- } else if (!strcasecmp(v->name, "channel")) {
- ast_string_field_set(cal, notify_channel, v->value);
- } else if (!strcasecmp(v->name, "context")) {
- ast_string_field_set(cal, notify_context, v->value);
- } else if (!strcasecmp(v->name, "extension")) {
- ast_string_field_set(cal, notify_extension, v->value);
- } else if (!strcasecmp(v->name, "waittime")) {
- cal->notify_waittime = atoi(v->value);
- } else if (!strcasecmp(v->name, "app")) {
- ast_string_field_set(cal, notify_app, v->value);
- } else if (!strcasecmp(v->name, "appdata")) {
- ast_string_field_set(cal, notify_appdata, v->value);
- } else if (!strcasecmp(v->name, "refresh")) {
- cal->refresh = atoi(v->value);
- } else if (!strcasecmp(v->name, "timeframe")) {
- cal->timeframe = atoi(v->value);
- }
- }
-
- cal->thread = AST_PTHREADT_NULL;
- ast_cond_init(&cal->unload, NULL);
ao2_link(calendars, cal);
More information about the asterisk-commits
mailing list