[asterisk-commits] twilson: branch twilson/calendaring r161495 - /team/twilson/calendaring/res/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Dec 5 17:29:16 CST 2008


Author: twilson
Date: Fri Dec  5 17:29:15 2008
New Revision: 161495

URL: http://svn.digium.com/view/asterisk?view=rev&rev=161495
Log:
More changes that are similar to the other reviewboard fixes I had to make

Modified:
    team/twilson/calendaring/res/res_caldav.c
    team/twilson/calendaring/res/res_exchangecal.c
    team/twilson/calendaring/res/res_icalendar.c

Modified: team/twilson/calendaring/res/res_caldav.c
URL: http://svn.digium.com/view/asterisk/team/twilson/calendaring/res/res_caldav.c?view=diff&rev=161495&r1=161494&r2=161495
==============================================================================
--- team/twilson/calendaring/res/res_caldav.c (original)
+++ team/twilson/calendaring/res/res_caldav.c Fri Dec  5 17:29:15 2008
@@ -325,8 +325,7 @@
 	event->start = span->start;
 	event->end = span->end;
 
-	switch(icalcomponent_get_status(comp))
-	{
+	switch(icalcomponent_get_status(comp)) {
 	case ICAL_STATUS_CONFIRMED:
 		event->busy_state = AST_CALENDAR_BS_BUSY;
 		break;

Modified: team/twilson/calendaring/res/res_exchangecal.c
URL: http://svn.digium.com/view/asterisk/team/twilson/calendaring/res/res_exchangecal.c?view=diff&rev=161495&r1=161494&r2=161495
==============================================================================
--- team/twilson/calendaring/res/res_exchangecal.c (original)
+++ team/twilson/calendaring/res/res_exchangecal.c Fri Dec  5 17:29:15 2008
@@ -86,40 +86,44 @@
 	state->tag = strdup(tmp);
 
 	switch (type) {
-		case IKS_OPEN:
-			if (!strcasecmp(state->tag, "response")) {
-				struct ast_calendar_event *event;
-
-				state->in_response = 1;
-				event = ast_calendar_event_alloc(state->pvt->owner);
-				state->ptr = event;
-			} else if (!strcasecmp(state->tag, "propstat")) {
-				state->in_propstat = 1;
-			} else if (!strcasecmp(state->tag, "prop")) {
-				state->in_prop = 1;
+	case IKS_OPEN:
+		if (!strcasecmp(state->tag, "response")) {
+			struct ast_calendar_event *event;
+
+			state->in_response = 1;
+			if (!(event = ast_calendar_event_alloc(state->pvt->owner))) {
+				return IKS_NOMEM;
 			}
-			break;
-		case IKS_CLOSE:
-			if (!strcasecmp(state->tag, "response")) {
-				struct ao2_container *events = state->pvt->events;
-				struct ast_calendar_event *event = state->ptr;
-
-				state->in_response = 0;
-				if (ast_strlen_zero(event->uid)) {
-					ast_log(LOG_ERROR, "This event has no UID, something has gone wrong\n");
-					event = ast_calendar_unref_event(event);
-					return IKS_HOOK;
-				}
-				ao2_link(events, event);
+			state->ptr = event;
+		} else if (!strcasecmp(state->tag, "propstat")) {
+			state->in_propstat = 1;
+		} else if (!strcasecmp(state->tag, "prop")) {
+			state->in_prop = 1;
+		}
+		break;
+
+	case IKS_CLOSE:
+		if (!strcasecmp(state->tag, "response")) {
+			struct ao2_container *events = state->pvt->events;
+			struct ast_calendar_event *event = state->ptr;
+
+			state->in_response = 0;
+			if (ast_strlen_zero(event->uid)) {
+				ast_log(LOG_ERROR, "This event has no UID, something has gone wrong\n");
 				event = ast_calendar_unref_event(event);
-			} else if (!strcasecmp(state->tag, "propstat")) {
-				state->in_propstat = 0;
-			} else if (!strcasecmp(state->tag, "prop")) {
-				state->in_prop = 0;
+				return IKS_HOOK;
 			}
-			break;
-		default:
-			return IKS_OK;
+			ao2_link(events, event);
+			event = ast_calendar_unref_event(event);
+		} else if (!strcasecmp(state->tag, "propstat")) {
+			state->in_propstat = 0;
+		} else if (!strcasecmp(state->tag, "prop")) {
+			state->in_prop = 0;
+		}
+		break;
+
+	default:
+		return IKS_OK;
 	}
 
 	return IKS_OK;
@@ -168,7 +172,9 @@
 	if (str == value + len)
 		return IKS_OK;
 
-	str = ast_calloc(1, len + 1);
+	if (!(str = ast_calloc(1, len + 1))) {
+		return IKS_NOMEM;
+	}
 	memcpy(str, value, len);
 	if (!(state->in_response && state->in_propstat && state->in_prop)) {
 		return IKS_OK;
@@ -200,22 +206,23 @@
 	return IKS_OK;
 }
 
+static int cb_true(void *user_data, void *arg, int flags)
+{
+	return CMP_MATCH;
+}
+
 static void exchangecal_destructor(void *obj)
 {
 	struct exchangecal_pvt *pvt = obj;
-	struct ao2_iterator i;
-	struct ast_calendar_event *event;
 
 	ast_debug(1, "Destroying pvt for iCalendar %s\n", pvt->owner->name);
 	if (pvt->session) {
 		ne_session_destroy(pvt->session);
 	}
 	ast_string_field_free_memory(pvt);
-	i = ao2_iterator_init(pvt->events, 0);
-	while ((event = ao2_iterator_next(&i))) {
-		ao2_unlink(pvt->events, event);
-		event = ast_calendar_unref_event(event);
-	}
+
+	ao2_callback(pvt->events, OBJ_UNLINK | OBJ_NODATA | OBJ_MULTIPLE, cb_true, NULL);
+
 	ao2_ref(pvt->events, -1);
 }
 
@@ -269,12 +276,28 @@
 
 	for (tmp = (char *)src; *tmp; tmp++) {
 		switch (*tmp) {
-			case '\"' : strcpy(buf, """); break;
-			case '\'' : strcpy(buf, "'"); break;
-			case '&' : strcpy(buf, "&"); break;
-			case '<' : strcpy(buf, "&lt;"); break;
-			case '>' : strcpy(buf, "&gt;"); break;
-			default  : sprintf(buf, "%c", *tmp);
+		case '\"':
+			strcpy(buf, "&quot;");
+			break;
+
+		case '\'':
+			strcpy(buf, "&apos;");
+			break;
+
+		case '&':
+			strcpy(buf, "&amp;");
+			break;
+
+		case '<':
+			strcpy(buf, "&lt;");
+			break;
+
+		case '>':
+			strcpy(buf, "&gt;");
+			break;
+
+		default:
+			sprintf(buf, "%c", *tmp);
 		}
 
 		ast_str_append(&dst, 0, "%s", buf);
@@ -307,9 +330,16 @@
 static struct ast_str *bs_to_exchange_bs(struct ast_str *dst, enum ast_calendar_busy_state bs)
 {
 	switch (bs) {
-		case AST_CALENDAR_BS_BUSY : ast_str_set(&dst, 0, "%s", "BUSY"); break;
-		case AST_CALENDAR_BS_BUSY_TENTATIVE : ast_str_set(&dst, 0, "%s", "TENTATIVE"); break;
-		default : ast_str_set(&dst, 0, "%s", "FREE"); break;
+	case AST_CALENDAR_BS_BUSY:
+		ast_str_set(&dst, 0, "%s", "BUSY");
+		break;
+
+	case AST_CALENDAR_BS_BUSY_TENTATIVE:
+		ast_str_set(&dst, 0, "%s", "TENTATIVE");
+		break;
+
+	default:
+		ast_str_set(&dst, 0, "%s", "FREE");
 	}
 
 	return dst;
@@ -320,7 +350,9 @@
 	struct ast_str **response = data;
 	unsigned char *tmp;
 
-	tmp = ast_malloc(len + 1);
+	if (!(tmp = ast_malloc(len + 1))) {
+		return -1;
+	}
 	memcpy(tmp, block, len);
 	tmp[len] = '\0';
 	ast_str_append(response, 0, "%s", tmp);
@@ -369,17 +401,6 @@
 	ne_add_request_header(req, "Content-type", "text/xml");
 
 	ret = ne_request_dispatch(req);
-
-#if 0
-	do {
-		void *cursor = NULL;
-		const char *name, *value;
-		while ((cursor = ne_response_header_iterate(req, cursor, &name, &value))) {
-			printf("%s: %s\n", name, value);
-		}
-	} while(0);
-	ast_log(LOG_NOTICE, "status is %d for request to %s\n", ne_get_status(req)->code, pvt->url);
-#endif
 
 	if (ret != NE_OK) {
 		ast_log(LOG_WARNING, "Unknown response to CalDAV calendar %s, request %s to %s: %s\n", pvt->owner->name, method, pvt->url, ne_get_error(pvt->session));

Modified: team/twilson/calendaring/res/res_icalendar.c
URL: http://svn.digium.com/view/asterisk/team/twilson/calendaring/res/res_icalendar.c?view=diff&rev=161495&r1=161494&r2=161495
==============================================================================
--- team/twilson/calendaring/res/res_icalendar.c (original)
+++ team/twilson/calendaring/res/res_icalendar.c Fri Dec  5 17:29:15 2008
@@ -62,11 +62,14 @@
 	struct ao2_container *events;
 };
 
+static int cb_true(void *user_data, void *arg, int flags)
+{
+	return CMP_MATCH;
+}
+
 static void icalendar_destructor(void *obj)
 {
 	struct icalendar_pvt *pvt = obj;
-	struct ao2_iterator i;
-	struct ast_calendar_event *event;
 
 	ast_debug(1, "Destroying pvt for iCalendar %s\n", pvt->owner->name);
 	if (pvt->session) {
@@ -76,11 +79,9 @@
 		icalcomponent_free(pvt->data);
 	}
 	ast_string_field_free_memory(pvt);
-	i = ao2_iterator_init(pvt->events, 0);
-	while ((event = ao2_iterator_next(&i))) {
-		ao2_unlink(pvt->events, event);
-		event = ast_calendar_unref_event(event);
-	}
+
+	ao2_callback(pvt->events, OBJ_UNLINK | OBJ_NODATA | OBJ_MULTIPLE, cb_true, NULL);
+
 	ao2_ref(pvt->events, -1);
 }
 
@@ -97,7 +98,9 @@
 	struct ast_str **response = data;
 	unsigned char *tmp;
 
-	tmp = ast_malloc(len + 1);
+	if (!(tmp = ast_malloc(len + 1))) {
+		return -1;
+	}
 	memcpy(tmp, block, len);
 	tmp[len] = '\0';
 	ast_str_append(response, 0, "%s", tmp);
@@ -186,11 +189,17 @@
 	event->start = span->start;
 	event->end = span->end;
 
-	switch(icalcomponent_get_status(comp))
-	{
-	case ICAL_STATUS_CONFIRMED : event->busy_state = AST_CALENDAR_BS_BUSY;break;
-	case ICAL_STATUS_TENTATIVE : event->busy_state = AST_CALENDAR_BS_BUSY_TENTATIVE;break;
-	default                    : event->busy_state = AST_CALENDAR_BS_FREE;
+	switch(icalcomponent_get_status(comp)) {
+	case ICAL_STATUS_CONFIRMED:
+		event->busy_state = AST_CALENDAR_BS_BUSY;
+		break;
+
+	case ICAL_STATUS_TENTATIVE:
+		event->busy_state = AST_CALENDAR_BS_BUSY_TENTATIVE;
+		break;
+
+	default:
+		event->busy_state = AST_CALENDAR_BS_FREE;
 	}
 
 	if ((prop = icalcomponent_get_first_property(comp, ICAL_SUMMARY_PROPERTY))) {




More information about the asterisk-commits mailing list