Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#244] Allows spaces and comments in configuration parameters #247

Closed
wants to merge 1 commit into from

Conversation

fluca1978
Copy link
Collaborator

This commit refactors the extract_key_value() function to handle
quoted strings as values. A quoted string must start with either '"'
or '''. Everything between the quotes is handled as a value.
If quotes do not match (e.g., "foo') the value is not set, so the line
is ignored at all.
Quoted strings can contain also spaces and comment charaters.
Therefore, the following is a good string:

log_line_prefix = "PGAGROAL #%Y-%m-%d-%H:%M:%S"

Also, quotes can be nested:

log_line_prefix = "'PGAGROAL' #%Y-%m-%d-%H:%M:%S"

Values that do not need a quoting (because of spaces or comment signs)
can be quoted as well, and that will not affect the value parsing. The
following two lines are the same:

log_rotation_size = 1M
log_rotation_size = "1M"

The extract_key_value() function now returns also an integer to
indicate if it has parsed the key and the value correctly. The return
value is not used because there is already a check on the validity of
both key and value in pgagroal_read_configuration(), but to be
coherent the function returns a status.

This commit also allows to use comment-only line that begin with
spaces or tabs, therefore the following are all ignored lines. The
is_comment_line() function has therefore been refactored so that the
following is a valid snippet of configuration:

; comment
; comment
; comment

Last, a comment can be placed on the right side of a configuration
option, so

log_line_prefix = "PGAGROAL #%Y-%m-%d-%H:%M:%S" # the prefix

is a valid line. The trick here is that any space after the option
makes the rest of the line ignored. But now, even without spaces the
comment is ignored:

log_type = create; overwrites the file

Updated also the documentation to reflect the changes.

Close #244

This commit refactors the `extract_key_value()` function to handle
quoted strings as values. A quoted string must start with either '"'
or '\''. Everything between the quotes is handled as a value.
If quotes do not match (e.g., "foo') the value is not set, so the line
is ignored at all.
Quoted strings can contain also spaces and comment charaters.
Therefore, the following is a good string:

  log_line_prefix = "PGAGROAL #%Y-%m-%d-%H:%M:%S"

Also, quotes can be nested:

  log_line_prefix = "'PGAGROAL' #%Y-%m-%d-%H:%M:%S"

Values that do not need a quoting (because of spaces or comment signs)
can be quoted as well, and that will not affect the value parsing. The
following two lines are the same:

   log_rotation_size = 1M
   log_rotation_size = "1M"

The `extract_key_value()` function now returns also an integer to
indicate if it has parsed the key and the value correctly. The return
value is not used because there is already a check on the validity of
both key and value in `pgagroal_read_configuration()`, but to be
coherent the function returns a status.

This commit also allows to use comment-only line that begin with
spaces or tabs, therefore the following are all ignored lines. The
`is_comment_line()` function has therefore been refactored so that the
following is a valid snippet of configuration:

; comment
   ; comment
<tab> ; comment

Last, a comment can be placed on the right side of a configuration
option, so

   log_line_prefix  = "PGAGROAL #%Y-%m-%d-%H:%M:%S" # the prefix

is a valid line. The trick here is that any space after the option
makes the rest of the line ignored. But now, even without spaces the
comment is ignored:

log_type = create; overwrites the file

Updated also the documentation to reflect the changes.

Close agroal#244
@jesperpedersen
Copy link
Collaborator

Merged.

Thanks for your contribution !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow spaces in configuration values
2 participants