A small memory footprint AMQP implimentation

Dependents:   iothub_client_sample_amqp remote_monitoring simplesample_amqp

Committer:
AzureIoTClient
Date:
Tue Jan 24 15:23:52 2017 -0800
Revision:
17:923575db8b2d
Parent:
6:641a9672db08
Child:
19:000ab4e6a2c1
1.1.5

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Azure.IoT Build 0:6ae2f7bca550 1 // Copyright (c) Microsoft. All rights reserved.
Azure.IoT Build 0:6ae2f7bca550 2 // Licensed under the MIT license. See LICENSE file in the project root for full license information.
Azure.IoT Build 0:6ae2f7bca550 3
Azure.IoT Build 0:6ae2f7bca550 4 #include <stdlib.h>
Azure.IoT Build 0:6ae2f7bca550 5 #include <string.h>
Azure.IoT Build 0:6ae2f7bca550 6 #include "azure_uamqp_c/sasl_anonymous.h"
Azure.IoT Build 0:6ae2f7bca550 7 #include "azure_uamqp_c/amqpalloc.h"
Azure.IoT Build 0:6ae2f7bca550 8 #include "azure_c_shared_utility/xlogging.h"
Azure.IoT Build 0:6ae2f7bca550 9
Azure.IoT Build 0:6ae2f7bca550 10 typedef struct SASL_ANONYMOUS_INSTANCE_TAG
Azure.IoT Build 0:6ae2f7bca550 11 {
AzureIoTClient 6:641a9672db08 12 unsigned char dummy;
Azure.IoT Build 0:6ae2f7bca550 13 } SASL_ANONYMOUS_INSTANCE;
Azure.IoT Build 0:6ae2f7bca550 14
Azure.IoT Build 0:6ae2f7bca550 15 /* Codes_SRS_SASL_ANONYMOUS_01_010: [saslanonymous_get_interface shall return a pointer to a SASL_MECHANISM_INTERFACE_DESCRIPTION structure that contains pointers to the functions: saslanonymous_create, saslanonymous_destroy, saslanonymous_get_init_bytes, saslanonymous_get_mechanism_name, saslanonymous_challenge.] */
Azure.IoT Build 0:6ae2f7bca550 16 static const SASL_MECHANISM_INTERFACE_DESCRIPTION saslanonymous_interface =
Azure.IoT Build 0:6ae2f7bca550 17 {
Azure.IoT Build 0:6ae2f7bca550 18 saslanonymous_create,
Azure.IoT Build 0:6ae2f7bca550 19 saslanonymous_destroy,
Azure.IoT Build 0:6ae2f7bca550 20 saslanonymous_get_init_bytes,
Azure.IoT Build 0:6ae2f7bca550 21 saslanonymous_get_mechanism_name,
Azure.IoT Build 0:6ae2f7bca550 22 saslanonymous_challenge
Azure.IoT Build 0:6ae2f7bca550 23 };
Azure.IoT Build 0:6ae2f7bca550 24
Azure.IoT Build 0:6ae2f7bca550 25 /* Codes_SRS_SASL_ANONYMOUS_01_001: [saslanonymous_create shall return on success a non-NULL handle to a new SASL anonymous mechanism.] */
Azure.IoT Build 0:6ae2f7bca550 26 CONCRETE_SASL_MECHANISM_HANDLE saslanonymous_create(void* config)
Azure.IoT Build 0:6ae2f7bca550 27 {
Azure.IoT Build 0:6ae2f7bca550 28 /* Codes_SRS_SASL_ANONYMOUS_01_003: [Since this is the ANONYMOUS SASL mechanism, config shall be ignored.] */
Azure.IoT Build 0:6ae2f7bca550 29 (void)config;
Azure.IoT Build 0:6ae2f7bca550 30
Azure.IoT Build 0:6ae2f7bca550 31 /* Codes_SRS_SASL_ANONYMOUS_01_002: [If allocating the memory needed for the saslanonymous instance fails then saslanonymous_create shall return NULL.] */
Azure.IoT Build 0:6ae2f7bca550 32 return amqpalloc_malloc(sizeof(SASL_ANONYMOUS_INSTANCE));
Azure.IoT Build 0:6ae2f7bca550 33 }
Azure.IoT Build 0:6ae2f7bca550 34
Azure.IoT Build 0:6ae2f7bca550 35 void saslanonymous_destroy(CONCRETE_SASL_MECHANISM_HANDLE sasl_mechanism_concrete_handle)
Azure.IoT Build 0:6ae2f7bca550 36 {
Azure.IoT Build 0:6ae2f7bca550 37 /* Codes_SRS_SASL_ANONYMOUS_01_005: [If the argument concrete_sasl_mechanism is NULL, saslanonymous_destroy shall do nothing.] */
Azure.IoT Build 0:6ae2f7bca550 38 if (sasl_mechanism_concrete_handle != NULL)
Azure.IoT Build 0:6ae2f7bca550 39 {
Azure.IoT Build 0:6ae2f7bca550 40 /* Codes_SRS_SASL_ANONYMOUS_01_004: [saslanonymous_destroy shall free all resources associated with the SASL mechanism.] */
Azure.IoT Build 0:6ae2f7bca550 41 amqpalloc_free(sasl_mechanism_concrete_handle);
Azure.IoT Build 0:6ae2f7bca550 42 }
Azure.IoT Build 0:6ae2f7bca550 43 }
Azure.IoT Build 0:6ae2f7bca550 44
Azure.IoT Build 0:6ae2f7bca550 45 int saslanonymous_get_init_bytes(CONCRETE_SASL_MECHANISM_HANDLE sasl_mechanism_concrete_handle, SASL_MECHANISM_BYTES* init_bytes)
Azure.IoT Build 0:6ae2f7bca550 46 {
Azure.IoT Build 0:6ae2f7bca550 47 int result;
Azure.IoT Build 0:6ae2f7bca550 48
Azure.IoT Build 0:6ae2f7bca550 49 /* Codes_SRS_SASL_ANONYMOUS_01_007: [If the any argument is NULL, saslanonymous_get_init_bytes shall return a non-zero value.] */
Azure.IoT Build 0:6ae2f7bca550 50 if ((sasl_mechanism_concrete_handle == NULL) ||
Azure.IoT Build 0:6ae2f7bca550 51 (init_bytes == NULL))
Azure.IoT Build 0:6ae2f7bca550 52 {
Azure.IoT Build 0:6ae2f7bca550 53 result = __LINE__;
Azure.IoT Build 0:6ae2f7bca550 54 }
Azure.IoT Build 0:6ae2f7bca550 55 else
Azure.IoT Build 0:6ae2f7bca550 56 {
Azure.IoT Build 0:6ae2f7bca550 57 /* Codes_SRS_SASL_ANONYMOUS_01_012: [The bytes field of init_buffer shall be set to NULL.] */
Azure.IoT Build 0:6ae2f7bca550 58 init_bytes->bytes = NULL;
Azure.IoT Build 0:6ae2f7bca550 59 /* Codes_SRS_SASL_ANONYMOUS_01_006: [saslanonymous_get_init_bytes shall validate the concrete_sasl_mechanism argument and set the length of the init_bytes argument to be zero.] */
Azure.IoT Build 0:6ae2f7bca550 60 init_bytes->length = 0;
Azure.IoT Build 0:6ae2f7bca550 61
Azure.IoT Build 0:6ae2f7bca550 62 /* Codes_SRS_SASL_ANONYMOUS_01_011: [On success saslanonymous_get_init_bytes shall return zero.] */
Azure.IoT Build 0:6ae2f7bca550 63 result = 0;
Azure.IoT Build 0:6ae2f7bca550 64 }
Azure.IoT Build 0:6ae2f7bca550 65
Azure.IoT Build 0:6ae2f7bca550 66 return result;
Azure.IoT Build 0:6ae2f7bca550 67 }
Azure.IoT Build 0:6ae2f7bca550 68
Azure.IoT Build 0:6ae2f7bca550 69 const char* saslanonymous_get_mechanism_name(CONCRETE_SASL_MECHANISM_HANDLE sasl_mechanism)
Azure.IoT Build 0:6ae2f7bca550 70 {
Azure.IoT Build 0:6ae2f7bca550 71 const char* result;
Azure.IoT Build 0:6ae2f7bca550 72
Azure.IoT Build 0:6ae2f7bca550 73 /* Codes_SRS_SASL_ANONYMOUS_01_009: [If the argument concrete_sasl_mechanism is NULL, saslanonymous_get_mechanism_name shall return NULL.] */
Azure.IoT Build 0:6ae2f7bca550 74 if (sasl_mechanism == NULL)
Azure.IoT Build 0:6ae2f7bca550 75 {
Azure.IoT Build 0:6ae2f7bca550 76 result = NULL;
Azure.IoT Build 0:6ae2f7bca550 77 }
Azure.IoT Build 0:6ae2f7bca550 78 else
Azure.IoT Build 0:6ae2f7bca550 79 {
Azure.IoT Build 0:6ae2f7bca550 80 /* Codes_SRS_SASL_ANONYMOUS_01_008: [saslanonymous_get_mechanism_name shall validate the argument concrete_sasl_mechanism and on success it shall return a pointer to the string "ANONYMOUS".] */
Azure.IoT Build 0:6ae2f7bca550 81 result = "ANONYMOUS";
Azure.IoT Build 0:6ae2f7bca550 82 }
Azure.IoT Build 0:6ae2f7bca550 83
Azure.IoT Build 0:6ae2f7bca550 84 return result;
Azure.IoT Build 0:6ae2f7bca550 85 }
Azure.IoT Build 0:6ae2f7bca550 86
Azure.IoT Build 0:6ae2f7bca550 87 int saslanonymous_challenge(CONCRETE_SASL_MECHANISM_HANDLE concrete_sasl_mechanism, const SASL_MECHANISM_BYTES* challenge_bytes, SASL_MECHANISM_BYTES* response_bytes)
Azure.IoT Build 0:6ae2f7bca550 88 {
Azure.IoT Build 0:6ae2f7bca550 89 int result;
Azure.IoT Build 0:6ae2f7bca550 90
Azure.IoT Build 0:6ae2f7bca550 91 (void)challenge_bytes;
Azure.IoT Build 0:6ae2f7bca550 92
Azure.IoT Build 0:6ae2f7bca550 93 /* Codes_SRS_SASL_ANONYMOUS_01_015: [If the concrete_sasl_mechanism or response_bytes argument is NULL then saslanonymous_challenge shall fail and return a non-zero value.] */
Azure.IoT Build 0:6ae2f7bca550 94 if ((concrete_sasl_mechanism == NULL) ||
Azure.IoT Build 0:6ae2f7bca550 95 (response_bytes == NULL))
Azure.IoT Build 0:6ae2f7bca550 96 {
Azure.IoT Build 0:6ae2f7bca550 97 result = __LINE__;
Azure.IoT Build 0:6ae2f7bca550 98 }
Azure.IoT Build 0:6ae2f7bca550 99 else
Azure.IoT Build 0:6ae2f7bca550 100 {
Azure.IoT Build 0:6ae2f7bca550 101 /* Codes_SRS_SASL_ANONYMOUS_01_013: [saslanonymous_challenge shall set the response_bytes buffer to NULL and 0 size as the ANONYMOUS SASL mechanism does not implement challenge/response.] */
Azure.IoT Build 0:6ae2f7bca550 102 response_bytes->bytes = NULL;
Azure.IoT Build 0:6ae2f7bca550 103 response_bytes->length = 0;
Azure.IoT Build 0:6ae2f7bca550 104
Azure.IoT Build 0:6ae2f7bca550 105 /* Codes_SRS_SASL_ANONYMOUS_01_014: [On success, saslanonymous_challenge shall return 0.] */
Azure.IoT Build 0:6ae2f7bca550 106 result = 0;
Azure.IoT Build 0:6ae2f7bca550 107 }
Azure.IoT Build 0:6ae2f7bca550 108
Azure.IoT Build 0:6ae2f7bca550 109 return result;
Azure.IoT Build 0:6ae2f7bca550 110 }
Azure.IoT Build 0:6ae2f7bca550 111
Azure.IoT Build 0:6ae2f7bca550 112 const SASL_MECHANISM_INTERFACE_DESCRIPTION* saslanonymous_get_interface(void)
Azure.IoT Build 0:6ae2f7bca550 113 {
Azure.IoT Build 0:6ae2f7bca550 114 return &saslanonymous_interface;
Azure.IoT Build 0:6ae2f7bca550 115 }