[svn-commits] twilson: branch group/calendaring_ews r264162 - /team/group/calendaring_ews/res/

SVN commits to the Digium repositories svn-commits at lists.digium.com
Wed May 19 11:09:46 CDT 2010


Author: twilson
Date: Wed May 19 11:09:43 2010
New Revision: 264162

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=264162
Log:
Coding guidelines cleanup, debug level adjustment

Modified:
    team/group/calendaring_ews/res/res_calendar_ews.c

Modified: team/group/calendaring_ews/res/res_calendar_ews.c
URL: http://svnview.digium.com/svn/asterisk/team/group/calendaring_ews/res/res_calendar_ews.c?view=diff&rev=264162&r1=264161&r2=264162
==============================================================================
--- team/group/calendaring_ews/res/res_calendar_ews.c (original)
+++ team/group/calendaring_ews/res/res_calendar_ews.c Wed May 19 11:09:43 2010
@@ -120,7 +120,7 @@
 {
 	struct ewscal_pvt *pvt = obj;
 
-	ast_debug(1, "EWS: unref_ewscal()\n");
+	ast_debug(5, "EWS: unref_ewscal()\n");
 	ao2_ref(pvt, -1);
 	return NULL;
 }
@@ -155,7 +155,6 @@
 	struct ast_tm tm;
 	struct timeval tv;
 
-	ast_debug(1, "MSTime: %s\n", mstime);
 	if (ast_strptime(mstime, "%FT%TZ", &tm)) {
 		tv = ast_mktime(&tm, "UTC");
 		return tv.tv_sec;
@@ -165,9 +164,9 @@
 
 static int startelm(void *userdata, int parent, const char *nspace, const char *name, const char **atts)
 {
-	/* ast_debug(1, "EWS: XML: Start: %s\n", name); */
 	struct xml_context *ctx = userdata;
 
+	ast_debug(3, "EWS: XML: Start: %s\n", name);
 	if (ctx->op == XML_OP_CREATE) {
 		return NE_XML_DECLINE;
 	}
@@ -183,27 +182,26 @@
 		!strcmp(name, "Items")
 	) {
 		return 1;
-	}
-
-	/* Get number of events */
-	else if (!strcmp(name, "RootFolder")) {
+	} else if (!strcmp(name, "RootFolder")) {
+		/* Get number of events */
 		int items;
 
-		ast_debug(1, "EWS: XML: <RootFolder>\n");
-		if (sscanf(ne_xml_get_attr(ctx->parser, atts, NULL, "TotalItemsInView"), "%d", &items) != 1) {	/* Couldn't read enything */
+		ast_debug(3, "EWS: XML: <RootFolder>\n");
+		if (sscanf(ne_xml_get_attr(ctx->parser, atts, NULL, "TotalItemsInView"), "%d", &items) != 1) {
+			/* Couldn't read enything */
 			ne_xml_set_error(ctx->parser, "Could't read number of events.");
 			return NE_XML_ABORT;
 		}
-		ast_debug(1, "EWS: %d calendar items to load\n", items);
-		if (items < 1) {	/* Stop processing XML if there are no events */
+
+		ast_debug(3, "EWS: %d calendar items to load\n", items);
+		if (items < 1) {
+			/* Stop processing XML if there are no events */
 			return NE_XML_DECLINE;
 		}
 		return 1;
-	}
-
-	/* Event start */
-	else if (!strcmp(name, "CalendarItem")) {
-		ast_debug(1, "EWS: XML: <CalendarItem>\n");
+	} else if (!strcmp(name, "CalendarItem")) {
+		/* Event start */
+		ast_debug(3, "EWS: XML: <CalendarItem>\n");
 		if (!(ctx->pvt && ctx->pvt->owner)) {
 			ast_log(LOG_ERROR, "Require a private structure with an owner\n");
 			return NE_XML_ABORT;
@@ -222,10 +220,8 @@
 		}
 
 		return 1;
-	}
-
-	/* Event UID */
-	else if (!strcmp(name, "ItemId")) {
+	} else if (!strcmp(name, "ItemId")) {
+		/* Event UID */
 		if (ctx->op == XML_OP_FIND) {
 			struct calendar_id *id;
 			if (!(id = ast_calloc(1, sizeof(id)))) {
@@ -237,49 +233,39 @@
 			}
 			ast_str_set(&id->id, 0, "%s", ne_xml_get_attr(ctx->parser, atts, NULL, "Id"));
 			AST_LIST_INSERT_TAIL(&ctx->ids, id, next);
-			ast_debug(1, "EWS_FIND: XML: UID: %s\n", ast_str_buffer(id->id));
+			ast_debug(3, "EWS_FIND: XML: UID: %s\n", ast_str_buffer(id->id));
 		} else {
-			ast_debug(1, "EWS_GET: XML: UID: %s\n", ne_xml_get_attr(ctx->parser, atts, NULL, "Id"));
+			ast_debug(3, "EWS_GET: XML: UID: %s\n", ne_xml_get_attr(ctx->parser, atts, NULL, "Id"));
 			ast_string_field_set(ctx->event, uid, ne_xml_get_attr(ctx->parser, atts, NULL, "Id"));
 		}
 		return XML_EVENT_NAME;
-	}
-
-	/* Event name */
-	else if (!strcmp(name, "Subject")) {
+	} else if (!strcmp(name, "Subject")) {
+		/* Event name */
 		if (!ctx->cdata) {
 			return NE_XML_ABORT;
 		}
 		ast_str_reset(ctx->cdata);
 		return XML_EVENT_NAME;
-	}
-
-	/* Event start time */
-	else if (!strcmp(name, "Start")) {
+	} else if (!strcmp(name, "Start")) {
+		/* Event start time */
 		return XML_EVENT_START;
-	}
-
-	/* Event end time */
-	else if (!strcmp(name, "End")) {
+	} else if (!strcmp(name, "End")) {
+		/* Event end time */
 		return XML_EVENT_END;
-	}
-
-	/* Event busy state */
-	else if (!strcmp(name, "LegacyFreeBusyStatus")) {
+	} else if (!strcmp(name, "LegacyFreeBusyStatus")) {
+		/* Event busy state */
 		return XML_EVENT_BUSY;
-	}
-
-	/* Event organizer */
-	else if (!strcmp(name, "Organizer") || (parent == XML_EVENT_ORGANIZER && (!strcmp(name, "Mailbox") || !strcmp(name, "Name")))) {
+	} else if (!strcmp(name, "Organizer") ||
+			(parent == XML_EVENT_ORGANIZER && (!strcmp(name, "Mailbox") ||
+			!strcmp(name, "Name")))) {
+		/* Event organizer */
 		if (!ctx->cdata) {
 			return NE_XML_ABORT;
 		}
 		ast_str_reset(ctx->cdata);
 		return XML_EVENT_ORGANIZER;
-	}
-
-	/* Event location */
-	else if (!strcmp(name, "Location")) {
+	} else if (!strcmp(name, "Location")) {
+		/* Event location */
 		if (!ctx->cdata) {
 			return NE_XML_ABORT;
 		}
@@ -333,15 +319,15 @@
 		break;
 	case XML_EVENT_BUSY:
 		if (!strcmp(data, "Busy") || !strcmp(data, "OOF")) {
-			ast_debug(1, "EWS: XML: Busy: yes\n");
+			ast_debug(3, "EWS: XML: Busy: yes\n");
 			ctx->event->busy_state = AST_CALENDAR_BS_BUSY;
 		}
 		else if (!strcmp(data, "Tentative")) {
-			ast_debug(1, "EWS: XML: Busy: tentative\n");
+			ast_debug(3, "EWS: XML: Busy: tentative\n");
 			ctx->event->busy_state = AST_CALENDAR_BS_BUSY_TENTATIVE;
 		}
 		else {
-			ast_debug(1, "EWS: XML: Busy: no\n");
+			ast_debug(3, "EWS: XML: Busy: no\n");
 			ctx->event->busy_state = AST_CALENDAR_BS_FREE;
 		}
 		break;
@@ -349,38 +335,34 @@
 		ast_str_append(&ctx->cdata, 0, "%s", data);
 	}
 
-	ast_debug(1, "EWS: XML: CDATA: %s\n", ast_str_buffer(ctx->cdata));
+	ast_debug(5, "EWS: XML: CDATA: %s\n", ast_str_buffer(ctx->cdata));
 
 	return 0;
 }
 
 static int endelm(void *userdata, int state, const char *nspace, const char *name)
 {
-	/* ast_debug(1, "EWS: XML: End:   %s\n", name); */
 	struct xml_context *ctx = userdata;
 
+	ast_debug(5, "EWS: XML: End:   %s\n", name);
 	if (ctx->op == XML_OP_FIND || ctx->op == XML_OP_CREATE) {
 		return NE_XML_DECLINE;
 	}
 
-	/* Event name end*/
 	if (!strcmp(name, "Subject")) {
+		/* Event name end*/
 		ast_string_field_set(ctx->event, summary, ast_str_buffer(ctx->cdata));
-		ast_debug(1, "EWS: XML: Summary: %s\n", ctx->event->summary);
+		ast_debug(3, "EWS: XML: Summary: %s\n", ctx->event->summary);
 		ast_str_reset(ctx->cdata);
-	}
-
-	/* Event organizer end */
-	else if (!strcmp(name, "Organizer")) {
+	} else if (!strcmp(name, "Organizer")) {
+		/* Event organizer end */
 		ast_string_field_set(ctx->event, organizer, ast_str_buffer(ctx->cdata));
-		ast_debug(1, "EWS: XML: Organizer: %s\n", ctx->event->organizer);
+		ast_debug(3, "EWS: XML: Organizer: %s\n", ctx->event->organizer);
 		ast_str_reset(ctx->cdata);
-	}
-
-	/* Event location end */
-	else if (!strcmp(name, "Location")) {
+	} else if (!strcmp(name, "Location")) {
+		/* Event location end */
 		ast_string_field_set(ctx->event, location, ast_str_buffer(ctx->cdata));
-		ast_debug(1, "EWS: XML: Location: %s\n", ctx->event->location);
+		ast_debug(3, "EWS: XML: Location: %s\n", ctx->event->location);
 		ast_str_reset(ctx->cdata);
 	} else if (state == XML_EVENT_EMAIL_ADDRESS) {
 		struct ast_calendar_attendee *attendee;
@@ -394,13 +376,11 @@
 			attendee->data = ast_strdup(ast_str_buffer(ctx->cdata));
 			AST_LIST_INSERT_TAIL(&ctx->event->attendees, attendee, next);
 		}
-		ast_debug(1, "EWS: XML: attendee address '%s'\n", ast_str_buffer(ctx->cdata));
+		ast_debug(3, "EWS: XML: attendee address '%s'\n", ast_str_buffer(ctx->cdata));
 		ast_str_reset(ctx->cdata);
-	}
-
-	/* Event end */
-	else if (!strcmp(name, "CalendarItem")) {
-		ast_debug(1, "EWS: XML: </CalendarItem>\n");
+	} else if (!strcmp(name, "CalendarItem")) {
+		/* Event end */
+		ast_debug(3, "EWS: XML: </CalendarItem>\n");
 		ast_free(ctx->cdata);
 		if (ctx->event) {
 			ao2_link(ctx->pvt->events, ctx->event);
@@ -409,13 +389,12 @@
 			ast_log(LOG_ERROR, "Event data ended in XML, but event object does not exist!\n");
 			return 1;
 		}
-	}
-
-	/* Events end */
-	else if (!strcmp(name, "Envelope")) {
-		ast_debug(1, "EWS: XML: All events has been parsed, merging…\n");
+	} else if (!strcmp(name, "Envelope")) {
+		/* Events end */
+		ast_debug(3, "EWS: XML: All events has been parsed, merging…\n");
 		ast_calendar_merge_events(ctx->pvt->owner, ctx->pvt->events);
 	}
+
 	return 0;
 }
 
@@ -466,7 +445,7 @@
 	ne_request *req;
 	ne_xml_parser *parser;
 
-	ast_debug(1, "EWS: HTTP request...\n");
+	ast_debug(3, "EWS: HTTP request...\n");
 	if (!(ctx && ctx->pvt)) {
 		ast_log(LOG_ERROR, "There is no private!\n");
 		return -1;
@@ -483,8 +462,8 @@
 	req = ne_request_create(ctx->pvt->session, "POST", ctx->pvt->uri.path);
 	ne_set_request_flag(req, NE_REQFLAG_IDEMPOTENT, 0);
 
-	/* Set headers */
-	ne_add_request_header(req, "Content-Type", "text/xml; charset=utf-8");	/* should be application/soap+xml, but MS… :/ */
+	/* Set headers--should be application/soap+xml, but MS… :/ */
+	ne_add_request_header(req, "Content-Type", "text/xml; charset=utf-8");
 	ne_add_request_header(req, "SOAPAction", get_soap_action(ctx->op));
 
 	/* Set body to SOAP request */
@@ -497,7 +476,7 @@
 
 	/* Dispatch request and parse response as XML */
 	ret = ne_xml_dispatch_request(req, parser);
-	if (ret != NE_OK) {	/* Error handling */
+	if (ret != NE_OK) { /* Error handling */
 		ast_log(LOG_WARNING, "Unable to communicate with Exchange Web Service at '%s': %s\n", ctx->pvt->url, ne_get_error(ctx->pvt->session));
 		ne_request_destroy(req);
 		ast_free(request);
@@ -531,7 +510,7 @@
 		return -1;
 	}
 
-	ast_str_set(&request, 0, 
+	ast_str_set(&request, 0,
 		"<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" "
 			"xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" "
 			"xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" "
@@ -584,12 +563,8 @@
 		.pvt = pvt,
 	};
 
-	ast_debug(1, "EWS: get_ewscal_ids_for()\n");
-
-	/*
-	 * This will perform HTTP request
-	 */
-	ast_debug(1, "EWS: HTTP request...\n");
+	ast_debug(5, "EWS: get_ewscal_ids_for()\n");
+
 	if (!pvt) {
 		ast_log(LOG_ERROR, "There is no private!\n");
 		return NULL;
@@ -607,8 +582,11 @@
 	if (!(request = ast_str_create(512))) {
 		return NULL;
 	}
+
 	ast_str_set(&request, 0,
-		"<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ns1=\"http://schemas.microsoft.com/exchange/services/2006/types\" xmlns:ns2=\"http://schemas.microsoft.com/exchange/services/2006/messages\">"
+		"<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" "
+		"xmlns:ns1=\"http://schemas.microsoft.com/exchange/services/2006/types\" "
+		"xmlns:ns2=\"http://schemas.microsoft.com/exchange/services/2006/messages\">"
 			"<SOAP-ENV:Body>"
 				"<ns2:FindItem Traversal=\"Shallow\">"
 					"<ns2:ItemShape>"
@@ -652,23 +630,25 @@
 	ast_str_set(&request, 0,
 		"<?xml version=\"1.0\" encoding=\"utf-8\"?>"
 		"<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" "
-		  "xmlns:t=\"http://schemas.microsoft.com/exchange/services/2006/types\">"
-		  "<soap:Body>"
+		"xmlns:t=\"http://schemas.microsoft.com/exchange/services/2006/types\">"
+		"<soap:Body>"
 			"<GetItem xmlns=\"http://schemas.microsoft.com/exchange/services/2006/messages\">"
-			  "<ItemShape>"
-				"<t:BaseShape>AllProperties</t:BaseShape>"
-			  "</ItemShape>"
-			  "<ItemIds>"
-				"<t:ItemId Id=\"%s\"/>"
-			  "</ItemIds>"
+				"<ItemShape>"
+					"<t:BaseShape>AllProperties</t:BaseShape>"
+				"</ItemShape>"
+				"<ItemIds>"
+					"<t:ItemId Id=\"%s\"/>"
+				"</ItemIds>"
 			"</GetItem>"
-		  "</soap:Body>"
-		"</soap:Envelope>",
-		id);
+		"</soap:Body>"
+		"</soap:Envelope>", id
+	);
+
 	if (send_ews_request_and_parse(request, &ctx)) {
 		ast_free(request);
 		return -1;
 	}
+
 	ast_free(request);
 
 	return 0;
@@ -700,7 +680,7 @@
 	struct ast_calendar *cal = void_data;
 	ast_mutex_t refreshlock;
 
-	ast_debug(1, "EWS: ewscal_load_calendar()\n");
+	ast_debug(5, "EWS: ewscal_load_calendar()\n");
 
 	if (!(cal && (cfg = ast_calendar_config_acquire()))) {
 		ast_log(LOG_ERROR, "You must enable calendar support for res_ewscal to load\n");
@@ -775,16 +755,17 @@
 		pvt->uri.port = ne_uri_defaultport(pvt->uri.scheme);
 	}
 
-	ast_debug(1, "ne_uri.scheme	= %s\n", pvt->uri.scheme);
-	ast_debug(1, "ne_uri.host	= %s\n", pvt->uri.host);
-	ast_debug(1, "ne_uri.port	= %u\n", pvt->uri.port);
-	ast_debug(1, "ne_uri.path	= %s\n", pvt->uri.path);
-	ast_debug(1, "user		= %s\n", pvt->user);
-	ast_debug(1, "secret		= %s\n", pvt->secret);
+	ast_debug(3, "ne_uri.scheme	= %s\n", pvt->uri.scheme);
+	ast_debug(3, "ne_uri.host	= %s\n", pvt->uri.host);
+	ast_debug(3, "ne_uri.port	= %u\n", pvt->uri.port);
+	ast_debug(3, "ne_uri.path	= %s\n", pvt->uri.path);
+	ast_debug(3, "user		= %s\n", pvt->user);
+	ast_debug(3, "secret		= %s\n", pvt->secret);
 
 	pvt->session = ne_session_create(pvt->uri.scheme, pvt->uri.host, pvt->uri.port);
 	ne_set_server_auth(pvt->session, auth_credentials, pvt);
 	ne_set_useragent(pvt->session, "Asterisk");
+
 	if (!strcasecmp(pvt->uri.scheme, "https")) {
 		ne_ssl_trust_default_ca(pvt->session);
 		ne_ssl_set_verify(pvt->session, ssl_verify, pvt);
@@ -829,25 +810,25 @@
 
 static int load_module(void)
 {
-	ast_debug(1, "EWS: load_module():");
-	if (ne_version_match(0, 29)) {	/* Actualy, 0.29.1 is required (because of NTLM authentication), but this function does not support matching patch version. */
-		ast_debug(1, " AST_MODULE_LOAD_DECLINE\n");
+	/* Actualy, 0.29.1 is required (because of NTLM authentication), but this
+	 * function does not support matching patch version. */
+	if (ne_version_match(0, 29)) {
 		ast_log(LOG_ERROR, "Exchange Web Service calendar module require neon >= 0.29.1, but %s is installed.\n", ne_version_string());
 		return AST_MODULE_LOAD_DECLINE;
 	}
+
 	if (ast_calendar_register(&ewscal_tech) && (ne_sock_init() == 0)) {
-		ast_debug(1, " AST_MODULE_LOAD_DECLINE\n");
 		return AST_MODULE_LOAD_DECLINE;
 	}
-	ast_debug(1, " AST_MODULE_LOAD_SUCCESS\n");
+
 	return AST_MODULE_LOAD_SUCCESS;
 }
 
 static int unload_module(void)
 {
-	ast_debug(1, "EWS: unload_module()\n");
 	ne_sock_exit();
 	ast_calendar_unregister(&ewscal_tech);
+
 	return 0;
 }
 




More information about the svn-commits mailing list