Azure IoT common library
Dependents: STM32F746_iothub_client_sample_mqtt f767zi_mqtt iothub_client_sample_amqp iothub_client_sample_http ... more
connection_string_parser.c@18:6d8a413a4d9a, 2017-01-13 (annotated)
- Committer:
- AzureIoTClient
- Date:
- Fri Jan 13 18:41:15 2017 -0800
- Revision:
- 18:6d8a413a4d9a
- Parent:
- 16:18e7ebd42bb2
- Child:
- 21:b92006c5b9ff
1.1.4
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Azure.IoT.Build | 16:18e7ebd42bb2 | 1 | // Copyright (c) Microsoft. All rights reserved. |
Azure.IoT.Build | 16:18e7ebd42bb2 | 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. |
Azure.IoT.Build | 16:18e7ebd42bb2 | 3 | |
Azure.IoT.Build | 16:18e7ebd42bb2 | 4 | #include "azure_c_shared_utility/connection_string_parser.h" |
Azure.IoT.Build | 16:18e7ebd42bb2 | 5 | #include "azure_c_shared_utility/map.h" |
Azure.IoT.Build | 16:18e7ebd42bb2 | 6 | #include "azure_c_shared_utility/strings.h" |
Azure.IoT.Build | 16:18e7ebd42bb2 | 7 | #include "azure_c_shared_utility/string_tokenizer.h" |
Azure.IoT.Build | 16:18e7ebd42bb2 | 8 | #include <stdbool.h> |
Azure.IoT.Build | 16:18e7ebd42bb2 | 9 | #include "azure_c_shared_utility/xlogging.h" |
Azure.IoT.Build | 16:18e7ebd42bb2 | 10 | |
AzureIoTClient | 18:6d8a413a4d9a | 11 | |
AzureIoTClient | 18:6d8a413a4d9a | 12 | MAP_HANDLE connectionstringparser_parse_from_char(const char* connection_string) |
AzureIoTClient | 18:6d8a413a4d9a | 13 | { |
AzureIoTClient | 18:6d8a413a4d9a | 14 | MAP_HANDLE result; |
AzureIoTClient | 18:6d8a413a4d9a | 15 | STRING_HANDLE connString = NULL; |
AzureIoTClient | 18:6d8a413a4d9a | 16 | |
AzureIoTClient | 18:6d8a413a4d9a | 17 | /* Codes_SRS_CONNECTIONSTRINGPARSER_21_020: [connectionstringparser_parse_from_char shall create a STRING_HANDLE from the connection_string passed in as argument and parse it using the connectionstringparser_parse.]*/ |
AzureIoTClient | 18:6d8a413a4d9a | 18 | if ((connString = STRING_construct(connection_string)) == NULL) |
AzureIoTClient | 18:6d8a413a4d9a | 19 | { |
AzureIoTClient | 18:6d8a413a4d9a | 20 | /* Codes_SRS_CONNECTIONSTRINGPARSER_21_021: [If connectionstringparser_parse_from_char get error creating a STRING_HANDLE, it shall return NULL.]*/ |
AzureIoTClient | 18:6d8a413a4d9a | 21 | LogError("Error constructing connection String"); |
AzureIoTClient | 18:6d8a413a4d9a | 22 | result = NULL; |
AzureIoTClient | 18:6d8a413a4d9a | 23 | } |
AzureIoTClient | 18:6d8a413a4d9a | 24 | else |
AzureIoTClient | 18:6d8a413a4d9a | 25 | { |
AzureIoTClient | 18:6d8a413a4d9a | 26 | result = connectionstringparser_parse(connString); |
AzureIoTClient | 18:6d8a413a4d9a | 27 | } |
AzureIoTClient | 18:6d8a413a4d9a | 28 | |
AzureIoTClient | 18:6d8a413a4d9a | 29 | return result; |
AzureIoTClient | 18:6d8a413a4d9a | 30 | } |
AzureIoTClient | 18:6d8a413a4d9a | 31 | |
AzureIoTClient | 18:6d8a413a4d9a | 32 | |
Azure.IoT.Build | 16:18e7ebd42bb2 | 33 | /* Codes_SRS_CONNECTIONSTRINGPARSER_01_001: [connectionstringparser_parse shall parse all key value pairs from the connection_string passed in as argument and return a new map that holds the key/value pairs.] */ |
Azure.IoT.Build | 16:18e7ebd42bb2 | 34 | MAP_HANDLE connectionstringparser_parse(STRING_HANDLE connection_string) |
Azure.IoT.Build | 16:18e7ebd42bb2 | 35 | { |
Azure.IoT.Build | 16:18e7ebd42bb2 | 36 | MAP_HANDLE result; |
Azure.IoT.Build | 16:18e7ebd42bb2 | 37 | |
Azure.IoT.Build | 16:18e7ebd42bb2 | 38 | if (connection_string == NULL) |
Azure.IoT.Build | 16:18e7ebd42bb2 | 39 | { |
Azure.IoT.Build | 16:18e7ebd42bb2 | 40 | /* Codes_SRS_CONNECTIONSTRINGPARSER_01_002: [If connection_string is NULL then connectionstringparser_parse shall fail and return NULL.] */ |
Azure.IoT.Build | 16:18e7ebd42bb2 | 41 | result = NULL; |
AzureIoTClient | 18:6d8a413a4d9a | 42 | LogError("NULL connection string passed to tokenizer."); |
Azure.IoT.Build | 16:18e7ebd42bb2 | 43 | } |
Azure.IoT.Build | 16:18e7ebd42bb2 | 44 | else |
Azure.IoT.Build | 16:18e7ebd42bb2 | 45 | { |
Azure.IoT.Build | 16:18e7ebd42bb2 | 46 | /* Codes_SRS_CONNECTIONSTRINGPARSER_01_003: [connectionstringparser_parse shall create a STRING tokenizer to be used for parsing the connection string, by calling STRING_TOKENIZER_create.] */ |
Azure.IoT.Build | 16:18e7ebd42bb2 | 47 | /* Codes_SRS_CONNECTIONSTRINGPARSER_01_004: [connectionstringparser_parse shall start scanning at the beginning of the connection string.] */ |
Azure.IoT.Build | 16:18e7ebd42bb2 | 48 | STRING_TOKENIZER_HANDLE tokenizer = STRING_TOKENIZER_create(connection_string); |
Azure.IoT.Build | 16:18e7ebd42bb2 | 49 | if (tokenizer == NULL) |
Azure.IoT.Build | 16:18e7ebd42bb2 | 50 | { |
Azure.IoT.Build | 16:18e7ebd42bb2 | 51 | /* Codes_SRS_CONNECTIONSTRINGPARSER_01_015: [If STRING_TOKENIZER_create fails, connectionstringparser_parse shall fail and return NULL.] */ |
Azure.IoT.Build | 16:18e7ebd42bb2 | 52 | result = NULL; |
AzureIoTClient | 18:6d8a413a4d9a | 53 | LogError("Error creating STRING tokenizer."); |
Azure.IoT.Build | 16:18e7ebd42bb2 | 54 | } |
Azure.IoT.Build | 16:18e7ebd42bb2 | 55 | else |
Azure.IoT.Build | 16:18e7ebd42bb2 | 56 | { |
Azure.IoT.Build | 16:18e7ebd42bb2 | 57 | /* Codes_SRS_CONNECTIONSTRINGPARSER_01_016: [2 STRINGs shall be allocated in order to hold the to be parsed key and value tokens.] */ |
Azure.IoT.Build | 16:18e7ebd42bb2 | 58 | STRING_HANDLE token_key_string = STRING_new(); |
Azure.IoT.Build | 16:18e7ebd42bb2 | 59 | if (token_key_string == NULL) |
Azure.IoT.Build | 16:18e7ebd42bb2 | 60 | { |
Azure.IoT.Build | 16:18e7ebd42bb2 | 61 | /* Codes_SRS_CONNECTIONSTRINGPARSER_01_017: [If allocating the STRINGs fails connectionstringparser_parse shall fail and return NULL.] */ |
Azure.IoT.Build | 16:18e7ebd42bb2 | 62 | result = NULL; |
AzureIoTClient | 18:6d8a413a4d9a | 63 | LogError("Error creating key token STRING."); |
Azure.IoT.Build | 16:18e7ebd42bb2 | 64 | } |
Azure.IoT.Build | 16:18e7ebd42bb2 | 65 | else |
Azure.IoT.Build | 16:18e7ebd42bb2 | 66 | { |
Azure.IoT.Build | 16:18e7ebd42bb2 | 67 | STRING_HANDLE token_value_string = STRING_new(); |
Azure.IoT.Build | 16:18e7ebd42bb2 | 68 | if (token_value_string == NULL) |
Azure.IoT.Build | 16:18e7ebd42bb2 | 69 | { |
Azure.IoT.Build | 16:18e7ebd42bb2 | 70 | /* Codes_SRS_CONNECTIONSTRINGPARSER_01_017: [If allocating the STRINGs fails connectionstringparser_parse shall fail and return NULL.] */ |
Azure.IoT.Build | 16:18e7ebd42bb2 | 71 | result = NULL; |
AzureIoTClient | 18:6d8a413a4d9a | 72 | LogError("Error creating value token STRING."); |
Azure.IoT.Build | 16:18e7ebd42bb2 | 73 | } |
Azure.IoT.Build | 16:18e7ebd42bb2 | 74 | else |
Azure.IoT.Build | 16:18e7ebd42bb2 | 75 | { |
Azure.IoT.Build | 16:18e7ebd42bb2 | 76 | result = Map_Create(NULL); |
Azure.IoT.Build | 16:18e7ebd42bb2 | 77 | if (result == NULL) |
Azure.IoT.Build | 16:18e7ebd42bb2 | 78 | { |
Azure.IoT.Build | 16:18e7ebd42bb2 | 79 | /* Codes_SRS_CONNECTIONSTRINGPARSER_01_018: [If creating the result map fails, then connectionstringparser_parse shall return NULL.] */ |
AzureIoTClient | 18:6d8a413a4d9a | 80 | LogError("Error creating Map."); |
Azure.IoT.Build | 16:18e7ebd42bb2 | 81 | } |
Azure.IoT.Build | 16:18e7ebd42bb2 | 82 | else |
Azure.IoT.Build | 16:18e7ebd42bb2 | 83 | { |
Azure.IoT.Build | 16:18e7ebd42bb2 | 84 | /* Codes_SRS_CONNECTIONSTRINGPARSER_01_005: [The following actions shall be repeated until parsing is complete:] */ |
Azure.IoT.Build | 16:18e7ebd42bb2 | 85 | /* Codes_SRS_CONNECTIONSTRINGPARSER_01_006: [connectionstringparser_parse shall find a token (the key of the key/value pair) delimited by the `=` character, by calling STRING_TOKENIZER_get_next_token.] */ |
Azure.IoT.Build | 16:18e7ebd42bb2 | 86 | /* Codes_SRS_CONNECTIONSTRINGPARSER_01_007: [If STRING_TOKENIZER_get_next_token fails, parsing shall be considered complete.] */ |
Azure.IoT.Build | 16:18e7ebd42bb2 | 87 | while (STRING_TOKENIZER_get_next_token(tokenizer, token_key_string, "=") == 0) |
Azure.IoT.Build | 16:18e7ebd42bb2 | 88 | { |
Azure.IoT.Build | 16:18e7ebd42bb2 | 89 | bool is_error = false; |
Azure.IoT.Build | 16:18e7ebd42bb2 | 90 | |
Azure.IoT.Build | 16:18e7ebd42bb2 | 91 | /* Codes_SRS_CONNECTIONSTRINGPARSER_01_008: [connectionstringparser_parse shall find a token (the value of the key/value pair) delimited by the `;` character, by calling STRING_TOKENIZER_get_next_token.] */ |
Azure.IoT.Build | 16:18e7ebd42bb2 | 92 | if (STRING_TOKENIZER_get_next_token(tokenizer, token_value_string, ";") != 0) |
Azure.IoT.Build | 16:18e7ebd42bb2 | 93 | { |
Azure.IoT.Build | 16:18e7ebd42bb2 | 94 | /* Codes_SRS_CONNECTIONSTRINGPARSER_01_009: [If STRING_TOKENIZER_get_next_token fails, connectionstringparser_parse shall fail and return NULL (freeing the allocated result map).] */ |
Azure.IoT.Build | 16:18e7ebd42bb2 | 95 | is_error = true; |
AzureIoTClient | 18:6d8a413a4d9a | 96 | LogError("Error reading value token from the connection string."); |
Azure.IoT.Build | 16:18e7ebd42bb2 | 97 | } |
Azure.IoT.Build | 16:18e7ebd42bb2 | 98 | else |
Azure.IoT.Build | 16:18e7ebd42bb2 | 99 | { |
Azure.IoT.Build | 16:18e7ebd42bb2 | 100 | /* Codes_SRS_CONNECTIONSTRINGPARSER_01_011: [The C strings for the key and value shall be extracted from the previously parsed STRINGs by using STRING_c_str.] */ |
Azure.IoT.Build | 16:18e7ebd42bb2 | 101 | const char* token = STRING_c_str(token_key_string); |
Azure.IoT.Build | 16:18e7ebd42bb2 | 102 | /* Codes_SRS_CONNECTIONSTRINGPARSER_01_013: [If STRING_c_str fails then connectionstringparser_parse shall fail and return NULL (freeing the allocated result map).] */ |
Azure.IoT.Build | 16:18e7ebd42bb2 | 103 | if ((token == NULL) || |
Azure.IoT.Build | 16:18e7ebd42bb2 | 104 | /* Codes_SRS_CONNECTIONSTRINGPARSER_01_019: [If the key length is zero then connectionstringparser_parse shall fail and return NULL (freeing the allocated result map).] */ |
Azure.IoT.Build | 16:18e7ebd42bb2 | 105 | (strlen(token) == 0)) |
Azure.IoT.Build | 16:18e7ebd42bb2 | 106 | { |
Azure.IoT.Build | 16:18e7ebd42bb2 | 107 | is_error = true; |
AzureIoTClient | 18:6d8a413a4d9a | 108 | LogError("The key token is NULL or empty."); |
Azure.IoT.Build | 16:18e7ebd42bb2 | 109 | } |
Azure.IoT.Build | 16:18e7ebd42bb2 | 110 | else |
Azure.IoT.Build | 16:18e7ebd42bb2 | 111 | { |
Azure.IoT.Build | 16:18e7ebd42bb2 | 112 | /* Codes_SRS_CONNECTIONSTRINGPARSER_01_011: [The C strings for the key and value shall be extracted from the previously parsed STRINGs by using STRING_c_str.] */ |
Azure.IoT.Build | 16:18e7ebd42bb2 | 113 | const char* value = STRING_c_str(token_value_string); |
Azure.IoT.Build | 16:18e7ebd42bb2 | 114 | if (value == NULL) |
Azure.IoT.Build | 16:18e7ebd42bb2 | 115 | { |
Azure.IoT.Build | 16:18e7ebd42bb2 | 116 | /* Codes_SRS_CONNECTIONSTRINGPARSER_01_013: [If STRING_c_str fails then connectionstringparser_parse shall fail and return NULL (freeing the allocated result map).] */ |
Azure.IoT.Build | 16:18e7ebd42bb2 | 117 | is_error = true; |
AzureIoTClient | 18:6d8a413a4d9a | 118 | LogError("Could not get C string for value token."); |
Azure.IoT.Build | 16:18e7ebd42bb2 | 119 | } |
Azure.IoT.Build | 16:18e7ebd42bb2 | 120 | else |
Azure.IoT.Build | 16:18e7ebd42bb2 | 121 | { |
Azure.IoT.Build | 16:18e7ebd42bb2 | 122 | /* Codes_SRS_CONNECTIONSTRINGPARSER_01_010: [The key and value shall be added to the result map by using Map_Add.] */ |
Azure.IoT.Build | 16:18e7ebd42bb2 | 123 | if (Map_Add(result, token, value) != 0) |
Azure.IoT.Build | 16:18e7ebd42bb2 | 124 | { |
Azure.IoT.Build | 16:18e7ebd42bb2 | 125 | /* Codes_SRS_CONNECTIONSTRINGPARSER_01_012: [If Map_Add fails connectionstringparser_parse shall fail and return NULL (freeing the allocated result map).] */ |
Azure.IoT.Build | 16:18e7ebd42bb2 | 126 | is_error = true; |
AzureIoTClient | 18:6d8a413a4d9a | 127 | LogError("Could not add the key/value pair to the result map."); |
Azure.IoT.Build | 16:18e7ebd42bb2 | 128 | } |
Azure.IoT.Build | 16:18e7ebd42bb2 | 129 | } |
Azure.IoT.Build | 16:18e7ebd42bb2 | 130 | } |
Azure.IoT.Build | 16:18e7ebd42bb2 | 131 | } |
Azure.IoT.Build | 16:18e7ebd42bb2 | 132 | |
Azure.IoT.Build | 16:18e7ebd42bb2 | 133 | if (is_error) |
Azure.IoT.Build | 16:18e7ebd42bb2 | 134 | { |
AzureIoTClient | 18:6d8a413a4d9a | 135 | LogError("Error parsing connection string."); |
Azure.IoT.Build | 16:18e7ebd42bb2 | 136 | Map_Destroy(result); |
Azure.IoT.Build | 16:18e7ebd42bb2 | 137 | result = NULL; |
Azure.IoT.Build | 16:18e7ebd42bb2 | 138 | break; |
Azure.IoT.Build | 16:18e7ebd42bb2 | 139 | } |
Azure.IoT.Build | 16:18e7ebd42bb2 | 140 | } |
Azure.IoT.Build | 16:18e7ebd42bb2 | 141 | } |
Azure.IoT.Build | 16:18e7ebd42bb2 | 142 | |
Azure.IoT.Build | 16:18e7ebd42bb2 | 143 | STRING_delete(token_value_string); |
Azure.IoT.Build | 16:18e7ebd42bb2 | 144 | } |
Azure.IoT.Build | 16:18e7ebd42bb2 | 145 | |
Azure.IoT.Build | 16:18e7ebd42bb2 | 146 | STRING_delete(token_key_string); |
Azure.IoT.Build | 16:18e7ebd42bb2 | 147 | } |
Azure.IoT.Build | 16:18e7ebd42bb2 | 148 | |
Azure.IoT.Build | 16:18e7ebd42bb2 | 149 | /* Codes_SRS_CONNECTIONSTRINGPARSER_01_014: [After the parsing is complete the previously allocated STRINGs and STRING tokenizer shall be freed by calling STRING_TOKENIZER_destroy.] */ |
Azure.IoT.Build | 16:18e7ebd42bb2 | 150 | STRING_TOKENIZER_destroy(tokenizer); |
Azure.IoT.Build | 16:18e7ebd42bb2 | 151 | } |
Azure.IoT.Build | 16:18e7ebd42bb2 | 152 | } |
Azure.IoT.Build | 16:18e7ebd42bb2 | 153 | |
Azure.IoT.Build | 16:18e7ebd42bb2 | 154 | return result; |
Azure.IoT.Build | 16:18e7ebd42bb2 | 155 | } |
AzureIoTClient | 18:6d8a413a4d9a | 156 | |
AzureIoTClient | 18:6d8a413a4d9a | 157 | /* Codes_SRS_CONNECTIONSTRINGPARSER_21_022: [connectionstringparser_splitHostName_from_char shall split the provided hostName in name and suffix.]*/ |
AzureIoTClient | 18:6d8a413a4d9a | 158 | int connectionstringparser_splitHostName_from_char(const char* hostName, STRING_HANDLE nameString, STRING_HANDLE suffixString) |
AzureIoTClient | 18:6d8a413a4d9a | 159 | { |
AzureIoTClient | 18:6d8a413a4d9a | 160 | int result; |
AzureIoTClient | 18:6d8a413a4d9a | 161 | const char* runHostName = hostName; |
AzureIoTClient | 18:6d8a413a4d9a | 162 | |
AzureIoTClient | 18:6d8a413a4d9a | 163 | if ((hostName == NULL) || ((*hostName) == '\0') || ((*hostName) == '.') || (nameString == NULL) || (suffixString == NULL)) |
AzureIoTClient | 18:6d8a413a4d9a | 164 | { |
AzureIoTClient | 18:6d8a413a4d9a | 165 | /* Codes_SRS_CONNECTIONSTRINGPARSER_21_026: [If the hostName is NULL, connectionstringparser_splitHostName_from_char shall return __LINE__.]*/ |
AzureIoTClient | 18:6d8a413a4d9a | 166 | /* Codes_SRS_CONNECTIONSTRINGPARSER_21_027: [If the hostName is an empty string, connectionstringparser_splitHostName_from_char shall return __LINE__.]*/ |
AzureIoTClient | 18:6d8a413a4d9a | 167 | /* Codes_SRS_CONNECTIONSTRINGPARSER_21_028: [If the nameString is NULL, connectionstringparser_splitHostName_from_char shall return __LINE__.]*/ |
AzureIoTClient | 18:6d8a413a4d9a | 168 | /* Codes_SRS_CONNECTIONSTRINGPARSER_21_029: [If the suffixString is NULL, connectionstringparser_splitHostName_from_char shall return __LINE__.]*/ |
AzureIoTClient | 18:6d8a413a4d9a | 169 | /* Codes_SRS_CONNECTIONSTRINGPARSER_21_030: [If the hostName is not a valid host name, connectionstringparser_splitHostName_from_char shall return __LINE__.]*/ |
AzureIoTClient | 18:6d8a413a4d9a | 170 | result = __LINE__; |
AzureIoTClient | 18:6d8a413a4d9a | 171 | } |
AzureIoTClient | 18:6d8a413a4d9a | 172 | else |
AzureIoTClient | 18:6d8a413a4d9a | 173 | { |
AzureIoTClient | 18:6d8a413a4d9a | 174 | while ((*runHostName) != '\0') |
AzureIoTClient | 18:6d8a413a4d9a | 175 | { |
AzureIoTClient | 18:6d8a413a4d9a | 176 | if ((*runHostName) == '.') |
AzureIoTClient | 18:6d8a413a4d9a | 177 | { |
AzureIoTClient | 18:6d8a413a4d9a | 178 | /* Codes_SRS_CONNECTIONSTRINGPARSER_21_023: [connectionstringparser_splitHostName_from_char shall copy all characters, from the beginning of the hostName to the first `.` to the nameString.]*/ |
AzureIoTClient | 18:6d8a413a4d9a | 179 | /* Codes_SRS_CONNECTIONSTRINGPARSER_21_024: [connectionstringparser_splitHostName_from_char shall copy all characters, from the first `.` to the end of the hostName, to the suffixString.]*/ |
AzureIoTClient | 18:6d8a413a4d9a | 180 | runHostName++; |
AzureIoTClient | 18:6d8a413a4d9a | 181 | break; |
AzureIoTClient | 18:6d8a413a4d9a | 182 | } |
AzureIoTClient | 18:6d8a413a4d9a | 183 | runHostName++; |
AzureIoTClient | 18:6d8a413a4d9a | 184 | } |
AzureIoTClient | 18:6d8a413a4d9a | 185 | |
AzureIoTClient | 18:6d8a413a4d9a | 186 | if ((*runHostName) == '\0') |
AzureIoTClient | 18:6d8a413a4d9a | 187 | { |
AzureIoTClient | 18:6d8a413a4d9a | 188 | /* Codes_SRS_CONNECTIONSTRINGPARSER_21_030: [If the hostName is not a valid host name, connectionstringparser_splitHostName_from_char shall return __LINE__.]*/ |
AzureIoTClient | 18:6d8a413a4d9a | 189 | result = __LINE__; |
AzureIoTClient | 18:6d8a413a4d9a | 190 | } |
AzureIoTClient | 18:6d8a413a4d9a | 191 | else |
AzureIoTClient | 18:6d8a413a4d9a | 192 | { |
AzureIoTClient | 18:6d8a413a4d9a | 193 | /* Codes_SRS_CONNECTIONSTRINGPARSER_21_023: [connectionstringparser_splitHostName_from_char shall copy all characters, from the beginning of the hostName to the first `.` to the nameString.]*/ |
AzureIoTClient | 18:6d8a413a4d9a | 194 | if (STRING_copy_n(nameString, hostName, runHostName - hostName - 1) != 0) |
AzureIoTClient | 18:6d8a413a4d9a | 195 | { |
AzureIoTClient | 18:6d8a413a4d9a | 196 | /* Codes_SRS_CONNECTIONSTRINGPARSER_21_031: [If connectionstringparser_splitHostName_from_char get error copying the name to the nameString, it shall return __LINE__.]*/ |
AzureIoTClient | 18:6d8a413a4d9a | 197 | result = __LINE__; |
AzureIoTClient | 18:6d8a413a4d9a | 198 | } |
AzureIoTClient | 18:6d8a413a4d9a | 199 | /* Codes_SRS_CONNECTIONSTRINGPARSER_21_024: [connectionstringparser_splitHostName_from_char shall copy all characters, from the first `.` to the end of the hostName, to the suffixString.]*/ |
AzureIoTClient | 18:6d8a413a4d9a | 200 | else if (STRING_copy(suffixString, runHostName) != 0) |
AzureIoTClient | 18:6d8a413a4d9a | 201 | { |
AzureIoTClient | 18:6d8a413a4d9a | 202 | /* Codes_SRS_CONNECTIONSTRINGPARSER_21_032: [If connectionstringparser_splitHostName_from_char get error copying the suffix to the suffixString, it shall return __LINE__.]*/ |
AzureIoTClient | 18:6d8a413a4d9a | 203 | result = __LINE__; |
AzureIoTClient | 18:6d8a413a4d9a | 204 | } |
AzureIoTClient | 18:6d8a413a4d9a | 205 | else |
AzureIoTClient | 18:6d8a413a4d9a | 206 | { |
AzureIoTClient | 18:6d8a413a4d9a | 207 | /* Codes_SRS_CONNECTIONSTRINGPARSER_21_025: [If connectionstringparser_splitHostName_from_char get success splitting the hostName, it shall return 0.]*/ |
AzureIoTClient | 18:6d8a413a4d9a | 208 | result = 0; |
AzureIoTClient | 18:6d8a413a4d9a | 209 | } |
AzureIoTClient | 18:6d8a413a4d9a | 210 | } |
AzureIoTClient | 18:6d8a413a4d9a | 211 | } |
AzureIoTClient | 18:6d8a413a4d9a | 212 | |
AzureIoTClient | 18:6d8a413a4d9a | 213 | return result; |
AzureIoTClient | 18:6d8a413a4d9a | 214 | } |
AzureIoTClient | 18:6d8a413a4d9a | 215 | |
AzureIoTClient | 18:6d8a413a4d9a | 216 | |
AzureIoTClient | 18:6d8a413a4d9a | 217 | int connectionstringparser_splitHostName(STRING_HANDLE hostNameString, STRING_HANDLE nameString, STRING_HANDLE suffixString) |
AzureIoTClient | 18:6d8a413a4d9a | 218 | { |
AzureIoTClient | 18:6d8a413a4d9a | 219 | int result; |
AzureIoTClient | 18:6d8a413a4d9a | 220 | |
AzureIoTClient | 18:6d8a413a4d9a | 221 | if (hostNameString == NULL) |
AzureIoTClient | 18:6d8a413a4d9a | 222 | { |
AzureIoTClient | 18:6d8a413a4d9a | 223 | /* Codes_SRS_CONNECTIONSTRINGPARSER_21_034: [If the hostNameString is NULL, connectionstringparser_splitHostName shall return __LINE__.]*/ |
AzureIoTClient | 18:6d8a413a4d9a | 224 | result = __LINE__; |
AzureIoTClient | 18:6d8a413a4d9a | 225 | } |
AzureIoTClient | 18:6d8a413a4d9a | 226 | else |
AzureIoTClient | 18:6d8a413a4d9a | 227 | { |
AzureIoTClient | 18:6d8a413a4d9a | 228 | /* Codes_SRS_CONNECTIONSTRINGPARSER_21_033: [connectionstringparser_splitHostName shall convert the hostNameString to a connection_string passed in as argument, and call connectionstringparser_splitHostName_from_char.]*/ |
AzureIoTClient | 18:6d8a413a4d9a | 229 | result = connectionstringparser_splitHostName_from_char(STRING_c_str(hostNameString), nameString, suffixString); |
AzureIoTClient | 18:6d8a413a4d9a | 230 | } |
AzureIoTClient | 18:6d8a413a4d9a | 231 | |
AzureIoTClient | 18:6d8a413a4d9a | 232 | return result; |
AzureIoTClient | 18:6d8a413a4d9a | 233 | } |