src/core/config/parser.c
/**
 * Read a key from the current parser buffer
 *
 * The parser buffer will be pointing to the beginning of a string something
 * like this:
 *
 * key = value
 *
 * We must pull out the key and then point the buffer to the EQUAL_CHAR
 */
Read a key from the current parser buffer
The parser buffer will be pointing to the beginning of a string something
like this.

key = value

We must pull out the key and then point the buffer to the EQUAL_CHAR
Read a key from the current parser buffer The parser buffer will be pointing to the beginning of a string something like this . key = value We must pull out the key and then point the buffer to the EQUAL_CHAR
enum natwm_error parser_read_key(struct parser *parser, char **result, size_t *length)
{
        enum natwm_error err = GENERIC_ERROR;
        const char *line = parser->buffer + parser->pos;
        if (char_to_token(line[0]) != ALPHA_CHAR) {
                LOG_ERROR(natwm_logger,
                          "Invalid Key: '%c' - Line: %zu Col: %zu",
                          line[0],
                          parser->line_num,
                          parser->col_num);
                return INVALID_INPUT_ERROR;
        }
        size_t equal_pos = 0;
        char *key = NULL;
        err = string_get_delimiter(line, '=', &key, &equal_pos, false);
        if (err != NO_ERROR) {
                LOG_ERROR(natwm_logger, "Missing '=' - Line: %zu", parser->line_num);
                return INVALID_INPUT_ERROR;
        }
        char *stripped_key = NULL;
        size_t stripped_key_length = 0;
        err = string_strip_surrounding_spaces(key, &stripped_key, &stripped_key_length);
        if (err != NO_ERROR) {
                LOG_ERROR(natwm_logger, "Invalid config value - Line %zu", parser->line_num);
                free(key);
                free(stripped_key);
                return INVALID_INPUT_ERROR;
        }
        free(key);
        parser_move(parser, equal_pos);
        *result = stripped_key;
        SET_IF_NON_NULL(length, stripped_key_length);
        return NO_ERROR;
}
enum natwm_error parser_read_key ( struct parser * parser , char * * result , size_t * length ) { enum natwm_error err = GENERIC_ERROR ; const char * line = parser -> buffer + parser -> pos ; if ( char_to_token ( line [ 0 ] ) != ALPHA_CHAR ) { LOG_ERROR ( natwm_logger , " " , line [ 0 ] , parser -> line_num , parser -> col_num ) ; return INVALID_INPUT_ERROR ; } size_t equal_pos = 0 ; char * key = NULL ; err = string_get_delimiter ( line , ' ' , & key , & equal_pos , false ) ; if ( err != NO_ERROR ) { LOG_ERROR ( natwm_logger , " " , parser -> line_num ) ; return INVALID_INPUT_ERROR ; } char * stripped_key = NULL ; size_t stripped_key_length = 0 ; err = string_strip_surrounding_spaces ( key , & stripped_key , & stripped_key_length ) ; if ( err != NO_ERROR ) { LOG_ERROR ( natwm_logger , " " , parser -> line_num ) ; free ( key ) ; free ( stripped_key ) ; return INVALID_INPUT_ERROR ; } free ( key ) ; parser_move ( parser , equal_pos ) ; * result = stripped_key ; SET_IF_NON_NULL ( length , stripped_key_length ) ; return NO_ERROR ; }
Read a key from the current parser buffer
 The parser buffer will be pointing to the beginning of a string something
 like this:
Read a key from the current parser buffer The parser buffer will be pointing to the beginning of a string something like this :
// Find the EQUAL_CHAR which will allows us to know the bounds of the // key // We should now be able to strip the spaces around the key which will // leave us with a valid key // Cleanup the intermediate key // Update the buffer position to the equal pos // Now we can return our valid key and key length