A small memory footprint AMQP implimentation

Dependents:   iothub_client_sample_amqp remote_monitoring simplesample_amqp

Revision:
23:1111ee8bcba4
Parent:
20:206846c14c80
Child:
24:2c59c2d43ebf
diff -r 524bded3f7a8 -r 1111ee8bcba4 sasl_plain.c
--- a/sasl_plain.c	Thu Apr 06 14:11:27 2017 -0700
+++ b/sasl_plain.c	Fri Apr 21 14:50:32 2017 -0700
@@ -5,6 +5,7 @@
 #include <string.h>
 #include "azure_c_shared_utility/optimize_size.h"
 #include "azure_c_shared_utility/gballoc.h"
+#include "azure_c_shared_utility/xlogging.h"
 #include "azure_uamqp_c/sasl_plain.h"
 
 typedef struct SASL_PLAIN_INSTANCE_TAG
@@ -30,6 +31,7 @@
 	if (config == NULL)
 	{
 		/* Codes_SRS_SASL_PLAIN_01_003: [If the config argument is NULL, then saslplain_create shall fail and return NULL.] */
+        LogError("NULL config");
 		result = NULL;
 	}
 	else
@@ -40,7 +42,9 @@
 		if ((sasl_plain_config->authcid == NULL) ||
 			(sasl_plain_config->passwd == NULL))
 		{
-			result = NULL;
+            LogError("Bad configuration: authcid = %p, passwd = %p",
+                sasl_plain_config->authcid, sasl_plain_config->passwd);
+            result = NULL;
 		}
 		else
 		{
@@ -55,12 +59,14 @@
 				/* Codes_SRS_SASL_PLAIN_01_022: [   passwd    = 1*SAFE ; MUST accept up to 255 octets] */
 				(passwd_length > 255) || (passwd_length == 0))
 			{
-				result = NULL;
+                LogError("Bad configuration: authcid length = %u, passwd length = %u",
+                    (unsigned int)authcid_length, (unsigned int)passwd_length);
+                result = NULL;
 			}
 			else
 			{
 				/* Codes_SRS_SASL_PLAIN_01_001: [saslplain_create shall return on success a non-NULL handle to a new SASL plain mechanism.] */
-				result = malloc(sizeof(SASL_PLAIN_INSTANCE));
+				result = (SASL_PLAIN_INSTANCE*)malloc(sizeof(SASL_PLAIN_INSTANCE));
 				/* Codes_SRS_SASL_PLAIN_01_002: [If allocating the memory needed for the saslplain instance fails then saslplain_create shall return NULL.] */
 				if (result != NULL)
 				{
@@ -69,7 +75,8 @@
 					if (result->init_bytes == NULL)
 					{
 						/* Codes_SRS_SASL_PLAIN_01_002: [If allocating the memory needed for the saslplain instance fails then saslplain_create shall return NULL.] */
-						free(result);
+                        LogError("Cannot allocate init bytes");
+                        free(result);
 						result = NULL;
 					}
 					else
@@ -102,8 +109,12 @@
 
 void saslplain_destroy(CONCRETE_SASL_MECHANISM_HANDLE sasl_mechanism_concrete_handle)
 {
-	if (sasl_mechanism_concrete_handle != NULL)
-	{
+    if (sasl_mechanism_concrete_handle == NULL)
+    {
+        LogError("NULL sasl_mechanism_concrete_handle");
+    }
+    else
+    {
 		/* Codes_SRS_SASL_PLAIN_01_005: [saslplain_destroy shall free all resources associated with the SASL mechanism.] */
 		SASL_PLAIN_INSTANCE* sasl_plain_instance = (SASL_PLAIN_INSTANCE*)sasl_mechanism_concrete_handle;
 		if (sasl_plain_instance->init_bytes != NULL)
@@ -122,7 +133,9 @@
 	if ((sasl_mechanism_concrete_handle == NULL) ||
 		(init_bytes == NULL))
 	{
-		result = __FAILURE__;
+        LogError("Bad arguments: sasl_mechanism_concrete_handle = %p, init_bytes = %p",
+            sasl_mechanism_concrete_handle, init_bytes);
+        result = __FAILURE__;
 	}
 	else
 	{
@@ -145,7 +158,8 @@
 	if (sasl_mechanism == NULL)
 	{
 		/* Codes_SRS_SASL_PLAIN_01_011: [If the argument concrete_sasl_mechanism is NULL, saslplain_get_mechanism_name shall return NULL.] */
-		result = NULL;
+        LogError("NULL sasl_mechanism");
+        result = NULL;
 	}
 	else
 	{
@@ -166,7 +180,9 @@
 	if ((concrete_sasl_mechanism == NULL) ||
 		(response_bytes == NULL))
 	{
-		result = __FAILURE__;
+        LogError("Bad arguments: concrete_sasl_mechanism = %p, response_bytes = %p",
+            concrete_sasl_mechanism, response_bytes);
+        result = __FAILURE__;
 	}
 	else
 	{