[asterisk-commits] twilson: branch twilson/calendaring r161491 - in /team/twilson/calendaring: m...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Fri Dec 5 17:03:19 CST 2008
Author: twilson
Date: Fri Dec 5 17:03:18 2008
New Revision: 161491
URL: http://svn.digium.com/view/asterisk?view=rev&rev=161491
Log:
More reviewboard fixes
Modified:
team/twilson/calendaring/main/calendar.c
team/twilson/calendaring/res/res_caldav.c
Modified: team/twilson/calendaring/main/calendar.c
URL: http://svn.digium.com/view/asterisk/team/twilson/calendaring/main/calendar.c?view=diff&rev=161491&r1=161490&r2=161491
==============================================================================
--- team/twilson/calendaring/main/calendar.c (original)
+++ team/twilson/calendaring/main/calendar.c Fri Dec 5 17:03:18 2008
@@ -197,20 +197,24 @@
{
struct caltechlist *caltech_list;
-
+ AST_LIST_LOCK(&techs);
AST_LIST_TRAVERSE(&techs, caltech_list, list) {
if(!strcasecmp(tech->type, caltech_list->tech->type)) {
ast_log(LOG_WARNING, "Already have a handler for calendar type '%s'\n", tech->type);
+ AST_LIST_UNLOCK(&techs);
return -1;
}
}
+ AST_LIST_UNLOCK(&techs);
if (!(caltech_list = ast_calloc(1, sizeof(*caltech_list)))) {
return -1;
}
caltech_list->tech = tech;
+ AST_LIST_LOCK(&techs);
AST_LIST_INSERT_HEAD(&techs, caltech_list, list);
+ AST_LIST_UNLOCK(&techs);
ast_verb(2, "Registered calendar type '%s' (%s)\n", caltech_list->tech->type, caltech_list->tech->description);
@@ -233,7 +237,7 @@
{
struct caltechlist *caltech_list;
-
+ AST_LIST_LOCK(&techs);
AST_LIST_TRAVERSE_SAFE_BEGIN(&techs, caltech_list, list) {
if (caltech_list->tech != tech) {
continue;
@@ -246,6 +250,7 @@
break;
}
AST_LIST_TRAVERSE_SAFE_END;
+ AST_LIST_UNLOCK(&techs);
}
@@ -254,14 +259,14 @@
struct caltechlist *caltech_list;
const struct ast_calendar_tech *ret = NULL;
-
+ AST_LIST_LOCK(&techs);
AST_LIST_TRAVERSE(&techs, caltech_list, list) {
if (!strcasecmp(name, caltech_list->tech->type)) {
ret = caltech_list->tech;
break;
}
}
-
+ AST_LIST_UNLOCK(&techs);
return ret;
}
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=161491&r1=161490&r2=161491
==============================================================================
--- team/twilson/calendaring/res/res_caldav.c (original)
+++ team/twilson/calendaring/res/res_caldav.c Fri Dec 5 17:03:18 2008
@@ -66,22 +66,23 @@
struct ao2_container *events;
};
+static int cb_true(void *user_data, void *arg, int flags)
+{
+ return CMP_MATCH;
+}
+
static void caldav_destructor(void *obj)
{
struct caldav_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);
}
@@ -93,34 +94,14 @@
return NULL;
}
-/*
-static struct ast_str *xml_encode_str(struct ast_str *dst, const char *src)
-{
- char *tmp;
- char buf[7];
-
- for (tmp = (char *)src; *tmp; tmp++) {
- switch (*tmp) {
- case '\"' : strcpy(buf, """); break;
- case '\'' : strcpy(buf, "'"); break;
- case '&' : strcpy(buf, "&"); break;
- case '<' : strcpy(buf, "<"); break;
- case '>' : strcpy(buf, ">"); break;
- default : sprintf(buf, "%c", *tmp);
- }
-
- ast_str_append(&dst, 0, "%s", buf);
- }
-
- return dst;
-}
-*/
static int fetch_response_reader(void *data, const char *block, size_t len)
{
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);
@@ -169,17 +150,6 @@
ne_add_request_header(req, "Content-type", ast_strlen_zero(content_type) ? "text/xml" : content_type);
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));
@@ -243,11 +213,20 @@
if (!ast_strlen_zero(event->location)) {
icalcomponent_add_property(icalevent, icalproperty_new_location(event->location));
}
+
switch (event->busy_state) {
- case AST_CALENDAR_BS_BUSY : icalcomponent_add_property(icalevent, icalproperty_new_status(ICAL_STATUS_CONFIRMED));break;
- case AST_CALENDAR_BS_BUSY_TENTATIVE : icalcomponent_add_property(icalevent, icalproperty_new_status(ICAL_STATUS_TENTATIVE));break;
- default : icalcomponent_add_property(icalevent, icalproperty_new_status(ICAL_STATUS_NONE));break;
- }
+ case AST_CALENDAR_BS_BUSY:
+ icalcomponent_add_property(icalevent, icalproperty_new_status(ICAL_STATUS_CONFIRMED));
+ break;
+
+ case AST_CALENDAR_BS_BUSY_TENTATIVE:
+ icalcomponent_add_property(icalevent, icalproperty_new_status(ICAL_STATUS_TENTATIVE));
+ break;
+
+ default:
+ icalcomponent_add_property(icalevent, icalproperty_new_status(ICAL_STATUS_NONE));
+ }
+
icalcomponent_add_component(calendar, icalevent);
ast_str_append(&body, 0, "%s", icalcomponent_as_ical_string(calendar));
@@ -256,10 +235,17 @@
response = caldav_request(event->owner->tech_pvt, "PUT", body, subdir, "text/calendar");
ret = 0;
+
write_cleanup:
- if (body) ast_free(body);
- if (response) ast_free(response);
- if (subdir) ast_free(subdir);
+ if (body) {
+ ast_free(body);
+ }
+ if (response) {
+ ast_free(response);
+ }
+ if (subdir) {
+ ast_free(subdir);
+ }
return ret;
}
@@ -341,9 +327,16 @@
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;
+ 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