source/MQTTCfgParser.c
/**
 * @brief Parse the config file configurations to the Buffer
 *
 * @param[in] buffer
 *            The buffer containing the configuration file
 *
 * @param[in] bufSize
 *            The size of the buffer (first param)
 * @return CFG_TRUE if configuration file is correct and contains necessary attribute/values
 *
 */
@brief Parse the config file configurations to the Buffer
@param[in] buffer
The buffer containing the configuration file

@param[in] bufSize
The size of the buffer (first param)
@return CFG_TRUE if configuration file is correct and contains necessary attribute/values
@brief Parse the config file configurations to the Buffer @param [ in ] buffer The buffer containing the configuration file @param [ in ] bufSize The size of the buffer ( first param ) @return CFG_TRUE if configuration file is correct and contains necessary attribute / values
static uint8_t MQTTCfgParser_Config(const char *buffer, uint16_t bufSize, uint8_t overwrite) {
	uint16_t IndexAtBuffer = UINT16_C(0);
	uint8_t Result = CFG_TRUE;
	States_T State = STAT_EXP_ATT_NAME;
	int8_t CurrentConfigToSet = INT8_C(0);
	char Token[CFG_MAX_LINE_SIZE] = { 0 };
	uint16_t OutputTokenSize = UINT16_C(0);
	while (CFG_TRUE == Result) {
		OutputTokenSize = CFG_MAX_LINE_SIZE;
		TokensType_T GetTokenType = GetToken(buffer, &IndexAtBuffer, bufSize,
				Token, &OutputTokenSize, State);
		if (GetTokenType == TOKEN_EOF)
			break;
		switch (State) {
		case STAT_EXP_ATT_NAME: {
			if (GetTokenType != TOKEN_ATT_NAME) {
				LOG_AT_ERROR(("MQTTCfgParser: Expecting attname at %u\r\n",
						(uint16_t) (IndexAtBuffer - strlen(Token))));
				Result = CFG_FALSE;
				break;
			}
			for (uint8_t i = UINT8_C(0); i < ATT_IDX_SIZE; i++) {
				if (strcmp(Token, ConfigStructure[i].attName) == UINT8_C(0)) {
					CurrentConfigToSet = i;
					State = STAT_EXP_ATT_EQUAL;
					break;
				}
			}
			break;
		}
		case STAT_EXP_ATT_EQUAL: {
			if (GetTokenType != TOKEN_EQUAL) {
				LOG_AT_ERROR(("MQTTCfgParser: Expecting sign '=' at %u\r\n",
						(uint16_t) (IndexAtBuffer - strlen(Token))));
				Result = CFG_FALSE;
				break;
			}
			State = STAT_EXP_ATT_VALUE;
			break;
		}
		case STAT_EXP_ATT_VALUE: {
			if (GetTokenType != TOKEN_VALUE) {
				LOG_AT_ERROR(("MQTTCfgParser: Expecting value string at %u\r\n",
						(uint16_t) (IndexAtBuffer - strlen(Token))));
				Result = CFG_FALSE;
				break;
			}
			strcpy(ConfigStructure[CurrentConfigToSet].attValue, Token);
			if (ConfigStructure[CurrentConfigToSet].defined == 0 || overwrite) {
				ConfigStructure[CurrentConfigToSet].defined = 1;
				State = STAT_EXP_ATT_NAME;
			} else {
				Result = CFG_FALSE;
				LOG_AT_ERROR(("MQTTCfgParser: Twice definition of attribute %s!\r\n",
						ConfigStructure[CurrentConfigToSet].attName));
			}
			break;
		}
		default:
			LOG_AT_WARNING(("MQTTCfgParser: Unexpected state %d \r\n", State));
			break;
		}
	}
	return Result;
}
static uint8_t MQTTCfgParser_Config ( const char * buffer , uint16_t bufSize , uint8_t overwrite ) { uint16_t IndexAtBuffer = UINT16_C ( 0 ) ; uint8_t Result = CFG_TRUE ; States_T State = STAT_EXP_ATT_NAME ; int8_t CurrentConfigToSet = INT8_C ( 0 ) ; char Token [ CFG_MAX_LINE_SIZE ] = { 0 } ; uint16_t OutputTokenSize = UINT16_C ( 0 ) ; while ( CFG_TRUE == Result ) { OutputTokenSize = CFG_MAX_LINE_SIZE ; TokensType_T GetTokenType = GetToken ( buffer , & IndexAtBuffer , bufSize , Token , & OutputTokenSize , State ) ; if ( GetTokenType == TOKEN_EOF ) break ; switch ( State ) { case STAT_EXP_ATT_NAME : { if ( GetTokenType != TOKEN_ATT_NAME ) { LOG_AT_ERROR ( ( " \r \n " , ( uint16_t ) ( IndexAtBuffer - strlen ( Token ) ) ) ) ; Result = CFG_FALSE ; break ; } for ( uint8_t i = UINT8_C ( 0 ) ; i < ATT_IDX_SIZE ; i ++ ) { if ( strcmp ( Token , ConfigStructure [ i ] . attName ) == UINT8_C ( 0 ) ) { CurrentConfigToSet = i ; State = STAT_EXP_ATT_EQUAL ; break ; } } break ; } case STAT_EXP_ATT_EQUAL : { if ( GetTokenType != TOKEN_EQUAL ) { LOG_AT_ERROR ( ( " \r \n " , ( uint16_t ) ( IndexAtBuffer - strlen ( Token ) ) ) ) ; Result = CFG_FALSE ; break ; } State = STAT_EXP_ATT_VALUE ; break ; } case STAT_EXP_ATT_VALUE : { if ( GetTokenType != TOKEN_VALUE ) { LOG_AT_ERROR ( ( " \r \n " , ( uint16_t ) ( IndexAtBuffer - strlen ( Token ) ) ) ) ; Result = CFG_FALSE ; break ; } strcpy ( ConfigStructure [ CurrentConfigToSet ] . attValue , Token ) ; if ( ConfigStructure [ CurrentConfigToSet ] . defined == 0 || overwrite ) { ConfigStructure [ CurrentConfigToSet ] . defined = 1 ; State = STAT_EXP_ATT_NAME ; } else { Result = CFG_FALSE ; LOG_AT_ERROR ( ( " \r \n " , ConfigStructure [ CurrentConfigToSet ] . attName ) ) ; } break ; } default : LOG_AT_WARNING ( ( " \r \n " , State ) ) ; break ; } } return Result ; }
@brief Parse the config file configurations to the Buffer
 @param[in] buffer
            The buffer containing the configuration file
@brief Parse the config file configurations to the Buffer @param [ in ] buffer The buffer containing the configuration file