[svn-commits] twilson: trunk r352916 - /trunk/res/
SVN commits to the Digium repositories
svn-commits at lists.digium.com
Fri Jan 27 09:57:46 CST 2012
Author: twilson
Date: Fri Jan 27 09:57:40 2012
New Revision: 352916
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=352916
Log:
Add aresult variable for CALENDAR_WRITE
This patch adds a CALENDAR_SUCCESS=1/0 variable that is set to show whether or
not CALENDAR_WRITE has passed. This patch also adds some debugging for caldav
PUT responses and no longer treats responses with no body as an error (as a PUT
gets a 201 Created with no body).
(closes issue ASTERISK-16903)
Reported by: Clod Patry
Tested by: Terry Wilson
Patches:
calendarstatus.diff uploaded by Clod Patry (License #5138), slightly modified by Terry Wilson
Review: https://reviewboard.asterisk.org/r/1692/
- This line, and those below, will be ignored--
M res/res_calendar.c
M res/res_calendar_exchange.c
M res/res_calendar_caldav.c
Modified:
trunk/res/res_calendar.c
trunk/res/res_calendar_caldav.c
trunk/res/res_calendar_exchange.c
Modified: trunk/res/res_calendar.c
URL: http://svnview.digium.com/svn/asterisk/trunk/res/res_calendar.c?view=diff&rev=352916&r1=352915&r2=352916
==============================================================================
--- trunk/res/res_calendar.c (original)
+++ trunk/res/res_calendar.c Fri Jan 27 09:57:40 2012
@@ -54,7 +54,7 @@
<syntax>
<parameter name="calendar" required="true" />
</syntax>
- <description>
+ <description>
<para>Check the specified calendar's current busy status.</para>
</description>
<see-also>
@@ -186,6 +186,18 @@
<description>
<para>Example: CALENDAR_WRITE(calendar,field1,field2,field3)=val1,val2,val3</para>
<para>The field and value arguments can easily be set/passed using the HASHKEYS() and HASH() functions</para>
+ <variablelist>
+ <variable name="CALENDAR_SUCCESS">
+ <para>The status of the write operation to the calendar</para>
+ <value name="1" >
+ The event was successfully written to the calendar.
+ </value>
+ <value name="0" >
+ The event was not written to the calendar due to network issues, permissions, etc.
+ </value>
+ </variable>
+ </variablelist>
+
</description>
<see-also>
<ref type="function">CALENDAR_BUSY</ref>
@@ -1361,7 +1373,7 @@
if (!(val_dup = ast_strdup(value))) {
ast_log(LOG_ERROR, "Could not allocate memory for values\n");
- return -1;
+ goto write_cleanup;
}
AST_STANDARD_APP_ARGS(fields, data);
@@ -1434,6 +1446,11 @@
}
write_cleanup:
+ if (ret) {
+ pbx_builtin_setvar_helper(chan, "CALENDAR_SUCCESS", "0");
+ } else {
+ pbx_builtin_setvar_helper(chan, "CALENDAR_SUCCESS", "1");
+ }
if (cal) {
cal = unref_calendar(cal);
}
Modified: trunk/res/res_calendar_caldav.c
URL: http://svnview.digium.com/svn/asterisk/trunk/res/res_calendar_caldav.c?view=diff&rev=352916&r1=352915&r2=352916
==============================================================================
--- trunk/res/res_calendar_caldav.c (original)
+++ trunk/res/res_calendar_caldav.c Fri Jan 27 09:57:40 2012
@@ -125,6 +125,15 @@
return 0;
}
+static int debug_response_handler(void *userdata, ne_request *req, const ne_status *st)
+{
+ if (st->code < 200 || st->code > 299) {
+ ast_debug(1, "Unexpected response from server, %d: %s\n", st->code, st->reason_phrase);
+ return 0;
+ }
+ return 1;
+}
+
static struct ast_str *caldav_request(struct caldav_pvt *pvt, const char *method, struct ast_str *req_body, struct ast_str *subdir, const char *content_type)
{
struct ast_str *response;
@@ -145,17 +154,15 @@
snprintf(buf, sizeof(buf), "%s%s", pvt->uri.path, subdir ? ast_str_buffer(subdir) : "");
req = ne_request_create(pvt->session, method, buf);
- ne_add_response_body_reader(req, ne_accept_2xx, fetch_response_reader, &response);
+ ne_add_response_body_reader(req, debug_response_handler, fetch_response_reader, &response);
ne_set_request_body_buffer(req, ast_str_buffer(req_body), ast_str_strlen(req_body));
ne_add_request_header(req, "Content-type", ast_strlen_zero(content_type) ? "text/xml" : content_type);
ret = ne_request_dispatch(req);
ne_request_destroy(req);
- if (ret != NE_OK || !ast_str_strlen(response)) {
- if (ret != NE_OK) {
- ast_log(LOG_WARNING, "Unknown response to CalDAV calendar %s, request %s to %s: %s\n", pvt->owner->name, method, buf, ne_get_error(pvt->session));
- }
+ if (ret != NE_OK) {
+ ast_log(LOG_WARNING, "Unknown response to CalDAV calendar %s, request %s to %s: %s\n", pvt->owner->name, method, buf, ne_get_error(pvt->session));
ast_free(response);
return NULL;
}
@@ -244,9 +251,9 @@
ast_str_append(&body, 0, "%s", icalcomponent_as_ical_string(calendar));
ast_str_set(&subdir, 0, "%s%s.ics", pvt->url[strlen(pvt->url) - 1] == '/' ? "" : "/", event->uid);
- response = caldav_request(pvt, "PUT", body, subdir, "text/calendar");
-
- ret = 0;
+ if ((response = caldav_request(pvt, "PUT", body, subdir, "text/calendar"))) {
+ ret = 0;
+ }
write_cleanup:
if (body) {
@@ -302,6 +309,10 @@
response = caldav_request(pvt, "REPORT", body, NULL, NULL);
ast_free(body);
+ if (response && !ast_str_strlen(response)) {
+ ast_free(response);
+ return NULL;
+ }
return response;
}
Modified: trunk/res/res_calendar_exchange.c
URL: http://svnview.digium.com/svn/asterisk/trunk/res/res_calendar_exchange.c?view=diff&rev=352916&r1=352915&r2=352916
==============================================================================
--- trunk/res/res_calendar_exchange.c (original)
+++ trunk/res/res_calendar_exchange.c Fri Jan 27 09:57:40 2012
@@ -505,9 +505,10 @@
ast_verb(0, "\n\n%s\n\n", ast_str_buffer(body));
ast_str_set(&subdir, 0, "/Calendar/%s.eml", ast_str_buffer(uid));
- response = exchangecal_request(event->owner->tech_pvt, "PROPPATCH", body, subdir);
-
- ret = 0;
+ if ((response = exchangecal_request(event->owner->tech_pvt, "PROPPATCH", body, subdir))) {
+ ret = 0;
+ }
+
write_cleanup:
if (uid) {
ast_free(uid);
More information about the svn-commits
mailing list