A small memory footprint AMQP implimentation
Dependents: iothub_client_sample_amqp remote_monitoring simplesample_amqp
sasl_anonymous.c@20:206846c14c80, 2017-03-10 (annotated)
- Committer:
- AzureIoTClient
- Date:
- Fri Mar 10 11:47:49 2017 -0800
- Revision:
- 20:206846c14c80
- Parent:
- 19:000ab4e6a2c1
- Child:
- 23:1111ee8bcba4
1.1.9
Who changed what in which revision?
User | Revision | Line number | New 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> |
AzureIoTClient | 20:206846c14c80 | 6 | #include "azure_c_shared_utility/optimize_size.h" |
AzureIoTClient | 20:206846c14c80 | 7 | #include "azure_c_shared_utility/gballoc.h" |
Azure.IoT Build | 0:6ae2f7bca550 | 8 | #include "azure_uamqp_c/sasl_anonymous.h" |
Azure.IoT Build | 0:6ae2f7bca550 | 9 | #include "azure_c_shared_utility/xlogging.h" |
Azure.IoT Build | 0:6ae2f7bca550 | 10 | |
Azure.IoT Build | 0:6ae2f7bca550 | 11 | typedef struct SASL_ANONYMOUS_INSTANCE_TAG |
Azure.IoT Build | 0:6ae2f7bca550 | 12 | { |
AzureIoTClient | 6:641a9672db08 | 13 | unsigned char dummy; |
Azure.IoT Build | 0:6ae2f7bca550 | 14 | } SASL_ANONYMOUS_INSTANCE; |
Azure.IoT Build | 0:6ae2f7bca550 | 15 | |
Azure.IoT Build | 0:6ae2f7bca550 | 16 | /* 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 | 17 | static const SASL_MECHANISM_INTERFACE_DESCRIPTION saslanonymous_interface = |
Azure.IoT Build | 0:6ae2f7bca550 | 18 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 19 | saslanonymous_create, |
Azure.IoT Build | 0:6ae2f7bca550 | 20 | saslanonymous_destroy, |
Azure.IoT Build | 0:6ae2f7bca550 | 21 | saslanonymous_get_init_bytes, |
Azure.IoT Build | 0:6ae2f7bca550 | 22 | saslanonymous_get_mechanism_name, |
Azure.IoT Build | 0:6ae2f7bca550 | 23 | saslanonymous_challenge |
Azure.IoT Build | 0:6ae2f7bca550 | 24 | }; |
Azure.IoT Build | 0:6ae2f7bca550 | 25 | |
Azure.IoT Build | 0:6ae2f7bca550 | 26 | /* 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 | 27 | CONCRETE_SASL_MECHANISM_HANDLE saslanonymous_create(void* config) |
Azure.IoT Build | 0:6ae2f7bca550 | 28 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 29 | /* Codes_SRS_SASL_ANONYMOUS_01_003: [Since this is the ANONYMOUS SASL mechanism, config shall be ignored.] */ |
Azure.IoT Build | 0:6ae2f7bca550 | 30 | (void)config; |
Azure.IoT Build | 0:6ae2f7bca550 | 31 | |
Azure.IoT Build | 0:6ae2f7bca550 | 32 | /* Codes_SRS_SASL_ANONYMOUS_01_002: [If allocating the memory needed for the saslanonymous instance fails then saslanonymous_create shall return NULL.] */ |
AzureIoTClient | 20:206846c14c80 | 33 | return malloc(sizeof(SASL_ANONYMOUS_INSTANCE)); |
Azure.IoT Build | 0:6ae2f7bca550 | 34 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 35 | |
Azure.IoT Build | 0:6ae2f7bca550 | 36 | void saslanonymous_destroy(CONCRETE_SASL_MECHANISM_HANDLE sasl_mechanism_concrete_handle) |
Azure.IoT Build | 0:6ae2f7bca550 | 37 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 38 | /* Codes_SRS_SASL_ANONYMOUS_01_005: [If the argument concrete_sasl_mechanism is NULL, saslanonymous_destroy shall do nothing.] */ |
Azure.IoT Build | 0:6ae2f7bca550 | 39 | if (sasl_mechanism_concrete_handle != NULL) |
Azure.IoT Build | 0:6ae2f7bca550 | 40 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 41 | /* Codes_SRS_SASL_ANONYMOUS_01_004: [saslanonymous_destroy shall free all resources associated with the SASL mechanism.] */ |
AzureIoTClient | 20:206846c14c80 | 42 | free(sasl_mechanism_concrete_handle); |
Azure.IoT Build | 0:6ae2f7bca550 | 43 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 44 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 45 | |
Azure.IoT Build | 0:6ae2f7bca550 | 46 | int saslanonymous_get_init_bytes(CONCRETE_SASL_MECHANISM_HANDLE sasl_mechanism_concrete_handle, SASL_MECHANISM_BYTES* init_bytes) |
Azure.IoT Build | 0:6ae2f7bca550 | 47 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 48 | int result; |
Azure.IoT Build | 0:6ae2f7bca550 | 49 | |
Azure.IoT Build | 0:6ae2f7bca550 | 50 | /* 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 | 51 | if ((sasl_mechanism_concrete_handle == NULL) || |
Azure.IoT Build | 0:6ae2f7bca550 | 52 | (init_bytes == NULL)) |
Azure.IoT Build | 0:6ae2f7bca550 | 53 | { |
AzureIoTClient | 19:000ab4e6a2c1 | 54 | result = __FAILURE__; |
Azure.IoT Build | 0:6ae2f7bca550 | 55 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 56 | else |
Azure.IoT Build | 0:6ae2f7bca550 | 57 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 58 | /* Codes_SRS_SASL_ANONYMOUS_01_012: [The bytes field of init_buffer shall be set to NULL.] */ |
Azure.IoT Build | 0:6ae2f7bca550 | 59 | init_bytes->bytes = NULL; |
Azure.IoT Build | 0:6ae2f7bca550 | 60 | /* 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 | 61 | init_bytes->length = 0; |
Azure.IoT Build | 0:6ae2f7bca550 | 62 | |
Azure.IoT Build | 0:6ae2f7bca550 | 63 | /* Codes_SRS_SASL_ANONYMOUS_01_011: [On success saslanonymous_get_init_bytes shall return zero.] */ |
Azure.IoT Build | 0:6ae2f7bca550 | 64 | result = 0; |
Azure.IoT Build | 0:6ae2f7bca550 | 65 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 66 | |
Azure.IoT Build | 0:6ae2f7bca550 | 67 | return result; |
Azure.IoT Build | 0:6ae2f7bca550 | 68 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 69 | |
Azure.IoT Build | 0:6ae2f7bca550 | 70 | const char* saslanonymous_get_mechanism_name(CONCRETE_SASL_MECHANISM_HANDLE sasl_mechanism) |
Azure.IoT Build | 0:6ae2f7bca550 | 71 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 72 | const char* result; |
Azure.IoT Build | 0:6ae2f7bca550 | 73 | |
Azure.IoT Build | 0:6ae2f7bca550 | 74 | /* 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 | 75 | if (sasl_mechanism == NULL) |
Azure.IoT Build | 0:6ae2f7bca550 | 76 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 77 | result = NULL; |
Azure.IoT Build | 0:6ae2f7bca550 | 78 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 79 | else |
Azure.IoT Build | 0:6ae2f7bca550 | 80 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 81 | /* 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 | 82 | result = "ANONYMOUS"; |
Azure.IoT Build | 0:6ae2f7bca550 | 83 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 84 | |
Azure.IoT Build | 0:6ae2f7bca550 | 85 | return result; |
Azure.IoT Build | 0:6ae2f7bca550 | 86 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 87 | |
Azure.IoT Build | 0:6ae2f7bca550 | 88 | 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 | 89 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 90 | int result; |
Azure.IoT Build | 0:6ae2f7bca550 | 91 | |
Azure.IoT Build | 0:6ae2f7bca550 | 92 | (void)challenge_bytes; |
Azure.IoT Build | 0:6ae2f7bca550 | 93 | |
Azure.IoT Build | 0:6ae2f7bca550 | 94 | /* 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 | 95 | if ((concrete_sasl_mechanism == NULL) || |
Azure.IoT Build | 0:6ae2f7bca550 | 96 | (response_bytes == NULL)) |
Azure.IoT Build | 0:6ae2f7bca550 | 97 | { |
AzureIoTClient | 19:000ab4e6a2c1 | 98 | result = __FAILURE__; |
Azure.IoT Build | 0:6ae2f7bca550 | 99 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 100 | else |
Azure.IoT Build | 0:6ae2f7bca550 | 101 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 102 | /* 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 | 103 | response_bytes->bytes = NULL; |
Azure.IoT Build | 0:6ae2f7bca550 | 104 | response_bytes->length = 0; |
Azure.IoT Build | 0:6ae2f7bca550 | 105 | |
Azure.IoT Build | 0:6ae2f7bca550 | 106 | /* Codes_SRS_SASL_ANONYMOUS_01_014: [On success, saslanonymous_challenge shall return 0.] */ |
Azure.IoT Build | 0:6ae2f7bca550 | 107 | result = 0; |
Azure.IoT Build | 0:6ae2f7bca550 | 108 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 109 | |
Azure.IoT Build | 0:6ae2f7bca550 | 110 | return result; |
Azure.IoT Build | 0:6ae2f7bca550 | 111 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 112 | |
Azure.IoT Build | 0:6ae2f7bca550 | 113 | const SASL_MECHANISM_INTERFACE_DESCRIPTION* saslanonymous_get_interface(void) |
Azure.IoT Build | 0:6ae2f7bca550 | 114 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 115 | return &saslanonymous_interface; |
Azure.IoT Build | 0:6ae2f7bca550 | 116 | } |