[svn-commits] twilson: branch twilson/calendaring r161533 - /team/twilson/calendaring/main/

SVN commits to the Digium repositories svn-commits at lists.digium.com
Sat Dec 6 01:18:06 CST 2008


Author: twilson
Date: Sat Dec  6 01:18:05 2008
New Revision: 161533

URL: http://svn.digium.com/view/asterisk?view=rev&rev=161533
Log:
Fix an issue where events were getting unreffed to early, and add a couple more CLI commands

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=161533&r1=161532&r2=161533
==============================================================================
--- team/twilson/calendaring/main/calendar.c (original)
+++ team/twilson/calendaring/main/calendar.c Sat Dec  6 01:18:05 2008
@@ -447,6 +447,7 @@
 	if (chan) {
 		ast_channel_free(chan);
 	}
+
 	return res;
 }
 
@@ -528,10 +529,10 @@
 			needs_rescheduled = 1;
 		}
 
-		ao2_unlink(cal->events, old_event);
-		old_event = ast_calendar_unref_event(old_event);
-
 		if (needs_rescheduled) {
+			ao2_unlink(cal->events, old_event);
+			old_event = ast_calendar_unref_event(old_event);
+
 			schedule_calendar_event(cal, new_event);
 
 			/* if an event is moved forward in time, we need to make sure the busy state is updated */
@@ -993,7 +994,6 @@
 	.read = calendar_query_result_exec,
 };
 
-
 static int calendar_write_exec(struct ast_channel *chan, const char *cmd, char *data, const char *value)
 {
 	int i, j, ret = -1;
@@ -1026,7 +1026,6 @@
 		ast_log(LOG_WARNING, "Calendar '%s' has no write function!\n", cal->name);
 		goto write_cleanup;
 	}
-
 
 	if (!(event = ast_calendar_event_alloc(cal))) {
 		ast_log(LOG_ERROR, "Could not allocate memory for event\n");
@@ -1113,33 +1112,126 @@
 /*! \brief CLI command to list available calendars */
 static char *handle_show_calendars(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 {
-#define FORMAT "%-20.20s %-6.6s\n"
+#define FORMAT "%-20.20s %-10.10s %-6.6s\n"
 	struct ao2_iterator i;
 	struct ast_calendar *cal;
 
 	switch(cmd) {
 	case CLI_INIT:
-		e->command = "calendar show";
+		e->command = "calendar show calendars";
 		e->usage =
-			"Usage: calendar show\n"
+			"Usage: calendar show calendars\n"
 			"       Lists all registered calendars.\n";
 		return NULL;
 	case CLI_GENERATE:
 		return NULL;
 	}
 
-	ast_cli(a->fd, FORMAT, "Calendar", "Status");
+	ast_cli(a->fd, FORMAT, "Calendar", "Type", "Status");
+	ast_cli(a->fd, FORMAT, "--------", "----", "------");
 	i = ao2_iterator_init(calendars, 0);
 	while ((cal = ao2_iterator_next(&i))) {
-		ast_cli(a->fd, FORMAT, cal->name, calendar_is_busy(cal) ? "busy" : "free");
+		ast_cli(a->fd, FORMAT, cal->name, cal->tech->type, calendar_is_busy(cal) ? "busy" : "free");
 		cal = unref_calendar(cal);
 	}
 
 	return CLI_SUCCESS;
+#undef FORMAT
+}
+
+static char *handle_show_calendar(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
+{
+#define FORMAT "%-17.17s : %-20.20s\n"
+#define FORMAT2 "%-12.12s: %-40.60s\n"
+	struct ao2_iterator i;
+	struct ast_calendar *cal;
+	struct ast_calendar_event *event;
+	int which = 0;
+	char *ret = NULL;
+
+	switch(cmd) {
+	case CLI_INIT:
+		e->command = "calendar show calendar";
+		e->usage =
+			"Usage: calendar show calendar <calendar name>\n"
+			"       Displays information about a calendar\n";
+		return NULL;
+
+	case CLI_GENERATE:
+		if (a->pos != 3) {
+			return NULL;
+		}
+		i = ao2_iterator_init(calendars, 0);
+		while ((cal = ao2_iterator_next(&i))) {
+			if (!strncasecmp(a->word, cal->name, strlen(a->word)) && ++which > a->n) {
+				ret = ast_strdup(cal->name);
+				cal = unref_calendar(cal);
+				break;
+			}
+			cal = unref_calendar(cal);
+		}
+		return ret;
+	}
+
+	if (a->argc != 4) {
+		return CLI_SHOWUSAGE;
+	}
+
+	if (!(cal = find_calendar(a->argv[3]))) {
+		return NULL;
+	}
+
+	ast_cli(a->fd, FORMAT, "Name", cal->name);
+	ast_cli(a->fd, FORMAT, "Notify channel", cal->notify_channel);
+	ast_cli(a->fd, FORMAT, "Notify context", cal->notify_context);
+	ast_cli(a->fd, FORMAT, "Notify extension", cal->notify_extension);
+	ast_cli(a->fd, FORMAT, "Notify application", cal->notify_app);
+	ast_cli(a->fd, FORMAT, "Notify appdata", cal->notify_appdata);
+	ast_cli(a->fd, "%-17.17s : %d\n", "Refresh time", cal->refresh);
+	ast_cli(a->fd, "%-17.17s : %d\n", "Timeframe", cal->timeframe);
+	ast_cli(a->fd, "%-17.17s : %d\n", "Autoreminder", cal->autoreminder);
+	ast_cli(a->fd, "%s\n", "Events");
+	ast_cli(a->fd, "%s\n", "------");
+
+	i = ao2_iterator_init(cal->events, 0);
+	while ((event = ao2_iterator_next(&i))) {
+		ast_cli(a->fd, FORMAT2, "Summary", event->summary);
+		ast_cli(a->fd, FORMAT2, "Description", event->description);
+		ast_cli(a->fd, FORMAT2, "Organizer", event->organizer);
+		ast_cli(a->fd, FORMAT2, "Location", event->location);
+		ast_cli(a->fd, FORMAT2, "UID", event->uid);
+		ast_cli(a->fd, "\n");
+		event = ast_calendar_unref_event(event);
+	}
+	cal = unref_calendar(cal);
+	return CLI_SUCCESS;
+#undef FORMAT
+#undef FORMAT2
+}
+
+static char *handle_dump_sched(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
+{
+	switch(cmd) {
+	case CLI_INIT:
+		e->command = "calendar dump sched";
+		e->usage =
+			"Usage: calendar dump sched\n"
+			"       Dump the calendar sched context";
+		return NULL;
+
+	case CLI_GENERATE:
+		return NULL;
+	}
+
+	ast_sched_dump(sched);
+
+	return CLI_SUCCESS;
 }
 
 static struct ast_cli_entry calendar_cli[] = {
+	AST_CLI_DEFINE(handle_show_calendar, "Display information about a calendar"),
 	AST_CLI_DEFINE(handle_show_calendars, "Show registered calendars"),
+	AST_CLI_DEFINE(handle_dump_sched, "Dump calendar sched context"),
 };
 
 static int calendar_event_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)




More information about the svn-commits mailing list