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

Allow spaces in configuration values #244

Closed
fluca1978 opened this issue May 25, 2022 · 0 comments
Closed

Allow spaces in configuration values #244

fluca1978 opened this issue May 25, 2022 · 0 comments
Labels
feature New feature

Comments

@fluca1978
Copy link
Collaborator

The main configuration file pgagroal.conf does not allow spaces within the value of a key.
This means that, for instance, the following:

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

will result effectively as

log_line_prefix  = PGAGROAL

and quoting is not supported, so the following:

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

will result effectively in

log_line_prefix  = "PGAGROAL

It should be possible to change the extrac_key_and_value() function to handle quoted strings and thus spaces in configuratin values.

@fluca1978 fluca1978 added the feature New feature label May 25, 2022
fluca1978 added a commit to fluca1978/pgagroal that referenced this issue May 25, 2022
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
fluca1978 added a commit to fluca1978/pgagroal that referenced this issue May 25, 2022
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
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 a pull request may close this issue.

1 participant