Re: [pulseaudio-discuss] [PATCH 6/8] message-params: Allow parameter strings to contain escaped curly braces

2018-08-01 Thread Georg Chini

On 01.08.2018 13:13, Tanu Kaskinen wrote:

On Mon, 2018-07-30 at 13:23 +0200, Georg Chini wrote:

On 30.07.2018 11:18, Tanu Kaskinen wrote:

On Sun, 2018-07-29 at 22:36 +0200, Georg Chini wrote:

On 29.07.2018 21:47, Tanu Kaskinen wrote:

On Fri, 2018-07-27 at 10:51 +0200, Georg Chini wrote:

On 27.07.2018 10:08, Tanu Kaskinen wrote:

On Thu, 2018-07-26 at 18:02 +0200, Georg Chini wrote:

On 26.07.2018 12:37, Tanu Kaskinen wrote:

On Sun, 2018-07-22 at 21:11 +0200, Georg Chini wrote:

On 22.07.2018 17:48, Tanu Kaskinen wrote:

On Sun, 2018-07-22 at 16:02 +0200, Georg Chini wrote:

On 21.07.2018 20:17, Tanu Kaskinen wrote:

On Mon, 2018-04-09 at 19:35 +0200, Georg Chini wrote:

+
+/* Read functions */
+
/* Split the specified string into elements. An element is defined as
 * a sub-string between curly braces. The function is needed to parse
 * the parameters of messages. Each time it is called returns the 
position
 * of the current element in result and the state pointer is advanced to
- * the next list element.
+ * the next list element. On return, the parameter *is_unpacked indicates
+ * if the string is plain text or contains a sub-list. is_unpacked may
+ * be NULL.

is_unpacked looks like unnecessary complexity.
pa_message_params_read_string() should always unescape the value.

This is not about parameter type, it is just to distinguish between
a list and a simple value. One example comes to my mind immediately:
Consider a parameter list that consists of strings and a couple of
arrays. Now you can read this list as an array of strings (patch 8
provides a function for that) and then examine those strings that
contain arrays separately. Having the flag (and using it in read_string())
provides a more flexible and convenient way to parse a parameter list.

The flag may not be strictly necessary at the moment, but I would still
like to keep it.

To continue a familiar theme of my review: if there's a
read_string_array() function, I want that to be used only for string
arrays, not a mishmash of random types. There could be a separate
function split_list_into_array() that does something similar to
what you wanted to do with read_string_array().
split_list_into_array() wouldn't do special string handling,
though, so unescaping would be left to the application. I find that
only logical, since other basic types don't get special handling
either (i.e. floats aren't converted to C floats).

Your use case could be served with a vararg function that instead of
producing a string array would read into separate variables, like this:

pa_message_params_read(c, state,
  PA_TYPE_STRING, ,
  PA_TYPE_FLOAT, ,
  PA_TYPE_RAW, ,
  0);

PA_TYPE_RAW would be useful for reading a list (or anything else) into
a C string without unescaping or other processing. There could be also
PA_TYPE_IGNORE for uninteresting variables, and PA_TYPE_*_ARRAY for
arrays of basic types.

(Now it occurred to me that the 'c' argument name that is used in the
parsing functions is a bit weird and unhelpful. Maybe "param_list"
would be good?)


I still don't see your point. Again, the use of is_unpacked is
transparent for the
user of read_string(), so the user just reads a string without having to
care about
unescaping. The flag does not complicate the API, it simplifies it
because the
unescaping is done automatically.

The flag complicates the split_list() function parameters, but also the
read_string() semantics: you need to explain to the user that unlike
all the other read_foo() functions, read_string() can read any value
and unescaping becomes conditional because of this.

read_string() is not supposed to read any value, it is only supposed
to read strings. Actually, the user does not need to know anything
about escaping, because read_string() and write_string() do the
necessary escaping/unescaping completely transparent for the user.

The is_unpacked flag is at least useful to check if something returned
by split_list() is really a simple type and not a structure or array. I am
currently not using it in the read_foo() functions, but I think I should.

I guess you'd use is_unpacked for catching errors in the read_foo()
functions? That seems reasonable, but I'd like that to be done in an
internal function. You said that maybe split_list() could be made an
internal function, and that seems like a good idea. An alternative
would be to have an internal function for which split_list() would be a
simplified wrapper.


I guess I can make split_list() internal.




Your approach seems unnecessary
complicated to me. A string is a string, even if it contains
sub-structures. Your
split_list_into_array() function would basically return an array of
strings, so what
would be the advantage? It would only make parsing more cumbersome, because
the task of unescaping is given to the user instead of doing it
automatically where
necessary.


Re: [pulseaudio-discuss] [PATCH 6/8] message-params: Allow parameter strings to contain escaped curly braces

2018-08-01 Thread Tanu Kaskinen
On Mon, 2018-07-30 at 13:23 +0200, Georg Chini wrote:
> On 30.07.2018 11:18, Tanu Kaskinen wrote:
> > On Sun, 2018-07-29 at 22:36 +0200, Georg Chini wrote:
> > > On 29.07.2018 21:47, Tanu Kaskinen wrote:
> > > > On Fri, 2018-07-27 at 10:51 +0200, Georg Chini wrote:
> > > > > On 27.07.2018 10:08, Tanu Kaskinen wrote:
> > > > > > On Thu, 2018-07-26 at 18:02 +0200, Georg Chini wrote:
> > > > > > > On 26.07.2018 12:37, Tanu Kaskinen wrote:
> > > > > > > > On Sun, 2018-07-22 at 21:11 +0200, Georg Chini wrote:
> > > > > > > > > On 22.07.2018 17:48, Tanu Kaskinen wrote:
> > > > > > > > > > On Sun, 2018-07-22 at 16:02 +0200, Georg Chini wrote:
> > > > > > > > > > > On 21.07.2018 20:17, Tanu Kaskinen wrote:
> > > > > > > > > > > > On Mon, 2018-04-09 at 19:35 +0200, Georg Chini wrote:
> > > > > > > > > > > > > +
> > > > > > > > > > > > > +/* Read functions */
> > > > > > > > > > > > > +
> > > > > > > > > > > > >/* Split the specified string into elements. 
> > > > > > > > > > > > > An element is defined as
> > > > > > > > > > > > > * a sub-string between curly braces. The 
> > > > > > > > > > > > > function is needed to parse
> > > > > > > > > > > > > * the parameters of messages. Each time it is 
> > > > > > > > > > > > > called returns the position
> > > > > > > > > > > > > * of the current element in result and the 
> > > > > > > > > > > > > state pointer is advanced to
> > > > > > > > > > > > > - * the next list element.
> > > > > > > > > > > > > + * the next list element. On return, the parameter 
> > > > > > > > > > > > > *is_unpacked indicates
> > > > > > > > > > > > > + * if the string is plain text or contains a 
> > > > > > > > > > > > > sub-list. is_unpacked may
> > > > > > > > > > > > > + * be NULL.
> > > > > > > > > > > > 
> > > > > > > > > > > > is_unpacked looks like unnecessary complexity.
> > > > > > > > > > > > pa_message_params_read_string() should always unescape 
> > > > > > > > > > > > the value.
> > > > > 
> > > > > This is not about parameter type, it is just to distinguish between
> > > > > a list and a simple value. One example comes to my mind immediately:
> > > > > Consider a parameter list that consists of strings and a couple of
> > > > > arrays. Now you can read this list as an array of strings (patch 8
> > > > > provides a function for that) and then examine those strings that
> > > > > contain arrays separately. Having the flag (and using it in 
> > > > > read_string())
> > > > > provides a more flexible and convenient way to parse a parameter list.
> > > > > 
> > > > > The flag may not be strictly necessary at the moment, but I would 
> > > > > still
> > > > > like to keep it.
> > > > 
> > > > To continue a familiar theme of my review: if there's a
> > > > read_string_array() function, I want that to be used only for string
> > > > arrays, not a mishmash of random types. There could be a separate
> > > > function split_list_into_array() that does something similar to
> > > > what you wanted to do with read_string_array().
> > > > split_list_into_array() wouldn't do special string handling,
> > > > though, so unescaping would be left to the application. I find that
> > > > only logical, since other basic types don't get special handling
> > > > either (i.e. floats aren't converted to C floats).
> > > > 
> > > > Your use case could be served with a vararg function that instead of
> > > > producing a string array would read into separate variables, like this:
> > > > 
> > > > pa_message_params_read(c, state,
> > > >  PA_TYPE_STRING, ,
> > > >  PA_TYPE_FLOAT, ,
> > > >  PA_TYPE_RAW, ,
> > > >  0);
> > > > 
> > > > PA_TYPE_RAW would be useful for reading a list (or anything else) into
> > > > a C string without unescaping or other processing. There could be also
> > > > PA_TYPE_IGNORE for uninteresting variables, and PA_TYPE_*_ARRAY for
> > > > arrays of basic types.
> > > > 
> > > > (Now it occurred to me that the 'c' argument name that is used in the
> > > > parsing functions is a bit weird and unhelpful. Maybe "param_list"
> > > > would be good?)
> > > > 
> > > 
> > > I still don't see your point. Again, the use of is_unpacked is
> > > transparent for the
> > > user of read_string(), so the user just reads a string without having to
> > > care about
> > > unescaping. The flag does not complicate the API, it simplifies it
> > > because the
> > > unescaping is done automatically.
> > 
> > The flag complicates the split_list() function parameters, but also the
> > read_string() semantics: you need to explain to the user that unlike
> > all the other read_foo() functions, read_string() can read any value
> > and unescaping becomes conditional because of this.
> 
> read_string() is not supposed to read any value, it is only supposed
> to read strings. Actually, the user does not need to know anything
> about escaping, because read_string() and write_string() do 

Re: [pulseaudio-discuss] [PATCH 6/8] message-params: Allow parameter strings to contain escaped curly braces

2018-07-30 Thread Georg Chini

On 30.07.2018 11:18, Tanu Kaskinen wrote:

On Sun, 2018-07-29 at 22:36 +0200, Georg Chini wrote:

On 29.07.2018 21:47, Tanu Kaskinen wrote:

On Fri, 2018-07-27 at 10:51 +0200, Georg Chini wrote:

On 27.07.2018 10:08, Tanu Kaskinen wrote:

On Thu, 2018-07-26 at 18:02 +0200, Georg Chini wrote:

On 26.07.2018 12:37, Tanu Kaskinen wrote:

On Sun, 2018-07-22 at 21:11 +0200, Georg Chini wrote:

On 22.07.2018 17:48, Tanu Kaskinen wrote:

On Sun, 2018-07-22 at 16:02 +0200, Georg Chini wrote:

On 21.07.2018 20:17, Tanu Kaskinen wrote:

On Mon, 2018-04-09 at 19:35 +0200, Georg Chini wrote:

+
+/* Read functions */
+
   /* Split the specified string into elements. An element is defined as
* a sub-string between curly braces. The function is needed to parse
* the parameters of messages. Each time it is called returns the 
position
* of the current element in result and the state pointer is advanced to
- * the next list element.
+ * the next list element. On return, the parameter *is_unpacked indicates
+ * if the string is plain text or contains a sub-list. is_unpacked may
+ * be NULL.

is_unpacked looks like unnecessary complexity.
pa_message_params_read_string() should always unescape the value.



This is not about parameter type, it is just to distinguish between
a list and a simple value. One example comes to my mind immediately:
Consider a parameter list that consists of strings and a couple of
arrays. Now you can read this list as an array of strings (patch 8
provides a function for that) and then examine those strings that
contain arrays separately. Having the flag (and using it in read_string())
provides a more flexible and convenient way to parse a parameter list.

The flag may not be strictly necessary at the moment, but I would still
like to keep it.

To continue a familiar theme of my review: if there's a
read_string_array() function, I want that to be used only for string
arrays, not a mishmash of random types. There could be a separate
function split_list_into_array() that does something similar to
what you wanted to do with read_string_array().
split_list_into_array() wouldn't do special string handling,
though, so unescaping would be left to the application. I find that
only logical, since other basic types don't get special handling
either (i.e. floats aren't converted to C floats).

Your use case could be served with a vararg function that instead of
producing a string array would read into separate variables, like this:

pa_message_params_read(c, state,
 PA_TYPE_STRING, ,
 PA_TYPE_FLOAT, ,
 PA_TYPE_RAW, ,
 0);

PA_TYPE_RAW would be useful for reading a list (or anything else) into
a C string without unescaping or other processing. There could be also
PA_TYPE_IGNORE for uninteresting variables, and PA_TYPE_*_ARRAY for
arrays of basic types.

(Now it occurred to me that the 'c' argument name that is used in the
parsing functions is a bit weird and unhelpful. Maybe "param_list"
would be good?)


I still don't see your point. Again, the use of is_unpacked is
transparent for the
user of read_string(), so the user just reads a string without having to
care about
unescaping. The flag does not complicate the API, it simplifies it
because the
unescaping is done automatically.

The flag complicates the split_list() function parameters, but also the
read_string() semantics: you need to explain to the user that unlike
all the other read_foo() functions, read_string() can read any value
and unescaping becomes conditional because of this.


read_string() is not supposed to read any value, it is only supposed
to read strings. Actually, the user does not need to know anything
about escaping, because read_string() and write_string() do the
necessary escaping/unescaping completely transparent for the user.

The is_unpacked flag is at least useful to check if something returned
by split_list() is really a simple type and not a structure or array. I am
currently not using it in the read_foo() functions, but I think I should.




Your approach seems unnecessary
complicated to me. A string is a string, even if it contains
sub-structures. Your
split_list_into_array() function would basically return an array of
strings, so what
would be the advantage? It would only make parsing more cumbersome, because
the task of unescaping is given to the user instead of doing it
automatically where
necessary.

That's why I came up with the vararg function. I agree that
split_list_into_array() is unlikely to be very useful.


Also there is no "mishmash of random types", they are all strings It is
only the
difference between a "simple" string which needs no further processing and a
"complex" string which needs further parsing.

The API defines types for the parameters. There are no separate
"simple" and "complex" strings in the type system. The string type is
different than the list type. What you call complex 

Re: [pulseaudio-discuss] [PATCH 6/8] message-params: Allow parameter strings to contain escaped curly braces

2018-07-30 Thread Tanu Kaskinen
On Sun, 2018-07-29 at 22:36 +0200, Georg Chini wrote:
> On 29.07.2018 21:47, Tanu Kaskinen wrote:
> > On Fri, 2018-07-27 at 10:51 +0200, Georg Chini wrote:
> > > On 27.07.2018 10:08, Tanu Kaskinen wrote:
> > > > On Thu, 2018-07-26 at 18:02 +0200, Georg Chini wrote:
> > > > > On 26.07.2018 12:37, Tanu Kaskinen wrote:
> > > > > > On Sun, 2018-07-22 at 21:11 +0200, Georg Chini wrote:
> > > > > > > On 22.07.2018 17:48, Tanu Kaskinen wrote:
> > > > > > > > On Sun, 2018-07-22 at 16:02 +0200, Georg Chini wrote:
> > > > > > > > > On 21.07.2018 20:17, Tanu Kaskinen wrote:
> > > > > > > > > > On Mon, 2018-04-09 at 19:35 +0200, Georg Chini wrote:
> > > > > > > > > > > +
> > > > > > > > > > > +/* Read functions */
> > > > > > > > > > > +
> > > > > > > > > > >   /* Split the specified string into elements. An 
> > > > > > > > > > > element is defined as
> > > > > > > > > > >* a sub-string between curly braces. The function 
> > > > > > > > > > > is needed to parse
> > > > > > > > > > >* the parameters of messages. Each time it is 
> > > > > > > > > > > called returns the position
> > > > > > > > > > >* of the current element in result and the state 
> > > > > > > > > > > pointer is advanced to
> > > > > > > > > > > - * the next list element.
> > > > > > > > > > > + * the next list element. On return, the parameter 
> > > > > > > > > > > *is_unpacked indicates
> > > > > > > > > > > + * if the string is plain text or contains a sub-list. 
> > > > > > > > > > > is_unpacked may
> > > > > > > > > > > + * be NULL.
> > > > > > > > > > 
> > > > > > > > > > is_unpacked looks like unnecessary complexity.
> > > > > > > > > > pa_message_params_read_string() should always unescape the 
> > > > > > > > > > value.
> > > > > > > > > 
> > > > > > > > > It may be possible, that the string you read is a list. 
> > > > > > > > > Consider the
> > > > > > > > > following
> > > > > > > > > parameter list: {string1}{some nested structure}{string2}. 
> > > > > > > > > You can now
> > > > > > > > > read this list as three strings and then continue to read the 
> > > > > > > > > elements of
> > > > > > > > > the nested structure from the second string. You might even 
> > > > > > > > > create a
> > > > > > > > > function
> > > > > > > > > that takes a string and outputs a structure. So you are not 
> > > > > > > > > forced to go
> > > > > > > > > to the full depth of nesting on the first pass. This makes it 
> > > > > > > > > much easier
> > > > > > > > > to handle deeply nested parameter lists. For me this behavior 
> > > > > > > > > is an
> > > > > > > > > important
> > > > > > > > > feature and I do not want to drop it. See also my comment on 
> > > > > > > > > why I do
> > > > > > > > > not always want escaping.
> > > > > > > > 
> > > > > > > > Doesn't split_list() already allow this, why do you want to use
> > > > > > > > read_string() to do the same thing as split_list()?
> > > > > > > 
> > > > > > > read_string() and split_list() are very similar and we could live
> > > > > > > without read_string(). It is provided as a counterpart to 
> > > > > > > write_string()
> > > > > > > and for convenience additionally does the unescaping if necessary
> > > > > > > like write_string does the escaping.
> > > > > > > I don't see why this is a problem. It depends on the context which
> > > > > > > is the better function to use.
> > > > > > 
> > > > > > Again, in my mind a structure is not a string, they are different
> > > > > > types, and I think read_string() should only deal with the string 
> > > > > > type.
> > > > > > is_unpacked makes the API more complicated, so I'd like to get rid 
> > > > > > of
> > > > > > it.
> > > > > > 
> > > > > 
> > > > > I don't see your point. is_unpacked is not part of the read_string()
> > > > > arguments
> > > > > or return value. In split_list() it is definitively needed to indicate
> > > > > if the returned
> > > > > string (in the C sense) contains another list. I can imagine many
> > > > > situations where
> > > > > you might either pass an array or just a single value or even NULL.
> > > > > is_unpacked
> > > > > allows to differentiate between the situations.
> > > > 
> > > > Can you give an example? You say is_unpacked is definitely needed, but
> > > > so far the only use case has been read_string(), which you wanted to be
> > > > used for reading not only string values but everything else too. If
> > > > read_string() is changed to only read string values, then it doesn't
> > > > need is_unpacked from split_list().
> > > > 
> > > > The parameter types are known beforehand, so i don't see the need for
> > > > looking at the data to figure out the type. If introspection support is
> > > > desired, then that's a separate project (the is_unpacked flag isn't
> > > > sufficient for proper introspection).
> > > > 
> > > 
> > > This is not about parameter type, it is just to distinguish between
> > > a list and a simple value. One example comes to my mind immediately:
> > > Consider a 

Re: [pulseaudio-discuss] [PATCH 6/8] message-params: Allow parameter strings to contain escaped curly braces

2018-07-29 Thread Georg Chini

On 29.07.2018 21:47, Tanu Kaskinen wrote:

On Fri, 2018-07-27 at 10:51 +0200, Georg Chini wrote:

On 27.07.2018 10:08, Tanu Kaskinen wrote:

On Thu, 2018-07-26 at 18:02 +0200, Georg Chini wrote:

On 26.07.2018 12:37, Tanu Kaskinen wrote:

On Sun, 2018-07-22 at 21:11 +0200, Georg Chini wrote:

On 22.07.2018 17:48, Tanu Kaskinen wrote:

On Sun, 2018-07-22 at 16:02 +0200, Georg Chini wrote:

On 21.07.2018 20:17, Tanu Kaskinen wrote:

On Mon, 2018-04-09 at 19:35 +0200, Georg Chini wrote:

+
+/* Read functions */
+
  /* Split the specified string into elements. An element is defined as
   * a sub-string between curly braces. The function is needed to parse
   * the parameters of messages. Each time it is called returns the position
   * of the current element in result and the state pointer is advanced to
- * the next list element.
+ * the next list element. On return, the parameter *is_unpacked indicates
+ * if the string is plain text or contains a sub-list. is_unpacked may
+ * be NULL.

is_unpacked looks like unnecessary complexity.
pa_message_params_read_string() should always unescape the value.

It may be possible, that the string you read is a list. Consider the
following
parameter list: {string1}{some nested structure}{string2}. You can now
read this list as three strings and then continue to read the elements of
the nested structure from the second string. You might even create a
function
that takes a string and outputs a structure. So you are not forced to go
to the full depth of nesting on the first pass. This makes it much easier
to handle deeply nested parameter lists. For me this behavior is an
important
feature and I do not want to drop it. See also my comment on why I do
not always want escaping.

Doesn't split_list() already allow this, why do you want to use
read_string() to do the same thing as split_list()?

read_string() and split_list() are very similar and we could live
without read_string(). It is provided as a counterpart to write_string()
and for convenience additionally does the unescaping if necessary
like write_string does the escaping.
I don't see why this is a problem. It depends on the context which
is the better function to use.

Again, in my mind a structure is not a string, they are different
types, and I think read_string() should only deal with the string type.
is_unpacked makes the API more complicated, so I'd like to get rid of
it.


I don't see your point. is_unpacked is not part of the read_string()
arguments
or return value. In split_list() it is definitively needed to indicate
if the returned
string (in the C sense) contains another list. I can imagine many
situations where
you might either pass an array or just a single value or even NULL.
is_unpacked
allows to differentiate between the situations.

Can you give an example? You say is_unpacked is definitely needed, but
so far the only use case has been read_string(), which you wanted to be
used for reading not only string values but everything else too. If
read_string() is changed to only read string values, then it doesn't
need is_unpacked from split_list().

The parameter types are known beforehand, so i don't see the need for
looking at the data to figure out the type. If introspection support is
desired, then that's a separate project (the is_unpacked flag isn't
sufficient for proper introspection).


This is not about parameter type, it is just to distinguish between
a list and a simple value. One example comes to my mind immediately:
Consider a parameter list that consists of strings and a couple of
arrays. Now you can read this list as an array of strings (patch 8
provides a function for that) and then examine those strings that
contain arrays separately. Having the flag (and using it in read_string())
provides a more flexible and convenient way to parse a parameter list.

The flag may not be strictly necessary at the moment, but I would still
like to keep it.

To continue a familiar theme of my review: if there's a
read_string_array() function, I want that to be used only for string
arrays, not a mishmash of random types. There could be a separate
function split_list_into_array() that does something similar to what you wanted 
to do with read_string_array(). split_list_into_array() wouldn't do special 
string handling, though, so unescaping would be left to the application. I find 
that only logical, since other basic types don't get special handling either 
(i.e. floats aren't converted to C floats).

Your use case could be served with a vararg function that instead of
producing a string array would read into separate variables, like this:

pa_message_params_read(c, state,
PA_TYPE_STRING, ,
PA_TYPE_FLOAT, ,
PA_TYPE_RAW, ,
0);

PA_TYPE_RAW would be useful for reading a list (or anything else) into
a C string without unescaping or other processing. There could be also
PA_TYPE_IGNORE for 

Re: [pulseaudio-discuss] [PATCH 6/8] message-params: Allow parameter strings to contain escaped curly braces

2018-07-29 Thread Tanu Kaskinen
On Fri, 2018-07-27 at 10:51 +0200, Georg Chini wrote:
> On 27.07.2018 10:08, Tanu Kaskinen wrote:
> > On Thu, 2018-07-26 at 18:02 +0200, Georg Chini wrote:
> > > On 26.07.2018 12:37, Tanu Kaskinen wrote:
> > > > On Sun, 2018-07-22 at 21:11 +0200, Georg Chini wrote:
> > > > > On 22.07.2018 17:48, Tanu Kaskinen wrote:
> > > > > > On Sun, 2018-07-22 at 16:02 +0200, Georg Chini wrote:
> > > > > > > On 21.07.2018 20:17, Tanu Kaskinen wrote:
> > > > > > > > On Mon, 2018-04-09 at 19:35 +0200, Georg Chini wrote:
> > > > > > > > > +
> > > > > > > > > +/* Read functions */
> > > > > > > > > +
> > > > > > > > >  /* Split the specified string into elements. An element 
> > > > > > > > > is defined as
> > > > > > > > >   * a sub-string between curly braces. The function is 
> > > > > > > > > needed to parse
> > > > > > > > >   * the parameters of messages. Each time it is called 
> > > > > > > > > returns the position
> > > > > > > > >   * of the current element in result and the state 
> > > > > > > > > pointer is advanced to
> > > > > > > > > - * the next list element.
> > > > > > > > > + * the next list element. On return, the parameter 
> > > > > > > > > *is_unpacked indicates
> > > > > > > > > + * if the string is plain text or contains a sub-list. 
> > > > > > > > > is_unpacked may
> > > > > > > > > + * be NULL.
> > > > > > > > 
> > > > > > > > is_unpacked looks like unnecessary complexity.
> > > > > > > > pa_message_params_read_string() should always unescape the 
> > > > > > > > value.
> > > > > > > 
> > > > > > > It may be possible, that the string you read is a list. Consider 
> > > > > > > the
> > > > > > > following
> > > > > > > parameter list: {string1}{some nested structure}{string2}. You 
> > > > > > > can now
> > > > > > > read this list as three strings and then continue to read the 
> > > > > > > elements of
> > > > > > > the nested structure from the second string. You might even 
> > > > > > > create a
> > > > > > > function
> > > > > > > that takes a string and outputs a structure. So you are not 
> > > > > > > forced to go
> > > > > > > to the full depth of nesting on the first pass. This makes it 
> > > > > > > much easier
> > > > > > > to handle deeply nested parameter lists. For me this behavior is 
> > > > > > > an
> > > > > > > important
> > > > > > > feature and I do not want to drop it. See also my comment on why 
> > > > > > > I do
> > > > > > > not always want escaping.
> > > > > > 
> > > > > > Doesn't split_list() already allow this, why do you want to use
> > > > > > read_string() to do the same thing as split_list()?
> > > > > 
> > > > > read_string() and split_list() are very similar and we could live
> > > > > without read_string(). It is provided as a counterpart to 
> > > > > write_string()
> > > > > and for convenience additionally does the unescaping if necessary
> > > > > like write_string does the escaping.
> > > > > I don't see why this is a problem. It depends on the context which
> > > > > is the better function to use.
> > > > 
> > > > Again, in my mind a structure is not a string, they are different
> > > > types, and I think read_string() should only deal with the string type.
> > > > is_unpacked makes the API more complicated, so I'd like to get rid of
> > > > it.
> > > > 
> > > 
> > > I don't see your point. is_unpacked is not part of the read_string()
> > > arguments
> > > or return value. In split_list() it is definitively needed to indicate
> > > if the returned
> > > string (in the C sense) contains another list. I can imagine many
> > > situations where
> > > you might either pass an array or just a single value or even NULL.
> > > is_unpacked
> > > allows to differentiate between the situations.
> > 
> > Can you give an example? You say is_unpacked is definitely needed, but
> > so far the only use case has been read_string(), which you wanted to be
> > used for reading not only string values but everything else too. If
> > read_string() is changed to only read string values, then it doesn't
> > need is_unpacked from split_list().
> > 
> > The parameter types are known beforehand, so i don't see the need for
> > looking at the data to figure out the type. If introspection support is
> > desired, then that's a separate project (the is_unpacked flag isn't
> > sufficient for proper introspection).
> > 
> 
> This is not about parameter type, it is just to distinguish between
> a list and a simple value. One example comes to my mind immediately:
> Consider a parameter list that consists of strings and a couple of
> arrays. Now you can read this list as an array of strings (patch 8
> provides a function for that) and then examine those strings that
> contain arrays separately. Having the flag (and using it in read_string())
> provides a more flexible and convenient way to parse a parameter list.
> 
> The flag may not be strictly necessary at the moment, but I would still
> like to keep it.

To continue a familiar theme of my review: if there's a

Re: [pulseaudio-discuss] [PATCH 6/8] message-params: Allow parameter strings to contain escaped curly braces

2018-07-27 Thread Georg Chini

On 27.07.2018 10:08, Tanu Kaskinen wrote:

On Thu, 2018-07-26 at 18:02 +0200, Georg Chini wrote:

On 26.07.2018 12:37, Tanu Kaskinen wrote:

On Sun, 2018-07-22 at 21:11 +0200, Georg Chini wrote:

On 22.07.2018 17:48, Tanu Kaskinen wrote:

On Sun, 2018-07-22 at 16:02 +0200, Georg Chini wrote:

On 21.07.2018 20:17, Tanu Kaskinen wrote:

On Mon, 2018-04-09 at 19:35 +0200, Georg Chini wrote:

The patch adds the possibility to escape curly braces within parameter strings
and introduces several new functions that can be used for writing parameters.

For writing, the structure pa_message_param, which is a wrapper for pa_strbuf
has been created. Following new write functions are available:

pa_message_param_new() - creates a new pa_message_param structure
pa_message_param_to_string() - converts a pa_message_param to string and frees
the structure
The function pa_message_param_write_string()
has a parameter do_escape.

Why not do escaping always?

Because what you are writing as a string may be a list that you have
prepared
previously. Then you will not want escaping. You may for example create
a list
from an array and then insert this list as one string into the final
parameter list
or have a function that converts a certain structure to a parameter
string and
then write the result of this function as one element of the final list.

My mental model is that parameters have types, list type is different
than string type, and write_string() is only meant for writing values
of the string type.

Can you add a write_raw() function?

Yes, this is done in patch 7. But the raw write function differs from what
write_string() is doing. write_string() writes one element of a list,
that is
it encloses the string in braces. The raw write function is intended for
situations where you can't write a complete element with one write, so
it does not add any braces. I am still of the opinion, that a structure
or array converted to a parameter string is a string, so writing something
like this should be done with write_string().

They are different kinds of strings, different abstraction levels. When
you're writing an array "as a string", in that context it's just a C
string. write_string() with escaping deals with strings in the "message
params type system". I don't know if this makes any sense to you.
Probably not... In any case, the do_escape flag seems unnecessary
complexity to me.

The alternative would be a function to write an unescaped string in
addition to the write_raw() function. If you don't like the flag, would
you be OK with a write_unescaped_string() function? I think it is just
more comfortable than using write_raw().

Thanks for the concession, I was afraid we'll get stuck on this point.

By comfortable, do you refer to that write_raw() doesn't add braces
around the value? How about adding an add_braces flag to write_raw()?


Yes, that's a good idea. I'll do that and remove the
do_escape flag from write_string().




+
+/* Read functions */
+
 /* Split the specified string into elements. An element is defined as
  * a sub-string between curly braces. The function is needed to parse
  * the parameters of messages. Each time it is called returns the position
  * of the current element in result and the state pointer is advanced to
- * the next list element.
+ * the next list element. On return, the parameter *is_unpacked indicates
+ * if the string is plain text or contains a sub-list. is_unpacked may
+ * be NULL.

is_unpacked looks like unnecessary complexity.
pa_message_params_read_string() should always unescape the value.

It may be possible, that the string you read is a list. Consider the
following
parameter list: {string1}{some nested structure}{string2}. You can now
read this list as three strings and then continue to read the elements of
the nested structure from the second string. You might even create a
function
that takes a string and outputs a structure. So you are not forced to go
to the full depth of nesting on the first pass. This makes it much easier
to handle deeply nested parameter lists. For me this behavior is an
important
feature and I do not want to drop it. See also my comment on why I do
not always want escaping.

Doesn't split_list() already allow this, why do you want to use
read_string() to do the same thing as split_list()?

read_string() and split_list() are very similar and we could live
without read_string(). It is provided as a counterpart to write_string()
and for convenience additionally does the unescaping if necessary
like write_string does the escaping.
I don't see why this is a problem. It depends on the context which
is the better function to use.

Again, in my mind a structure is not a string, they are different
types, and I think read_string() should only deal with the string type.
is_unpacked makes the API more complicated, so I'd like to get rid of
it.


I don't see your point. is_unpacked is not part of the read_string()
arguments
or return value. In 

Re: [pulseaudio-discuss] [PATCH 6/8] message-params: Allow parameter strings to contain escaped curly braces

2018-07-27 Thread Tanu Kaskinen
On Thu, 2018-07-26 at 18:02 +0200, Georg Chini wrote:
> On 26.07.2018 12:37, Tanu Kaskinen wrote:
> > On Sun, 2018-07-22 at 21:11 +0200, Georg Chini wrote:
> > > On 22.07.2018 17:48, Tanu Kaskinen wrote:
> > > > On Sun, 2018-07-22 at 16:02 +0200, Georg Chini wrote:
> > > > > On 21.07.2018 20:17, Tanu Kaskinen wrote:
> > > > > > On Mon, 2018-04-09 at 19:35 +0200, Georg Chini wrote:
> > > > > > > The patch adds the possibility to escape curly braces within 
> > > > > > > parameter strings
> > > > > > > and introduces several new functions that can be used for writing 
> > > > > > > parameters.
> > > > > > > 
> > > > > > > For writing, the structure pa_message_param, which is a wrapper 
> > > > > > > for pa_strbuf
> > > > > > > has been created. Following new write functions are available:
> > > > > > > 
> > > > > > > pa_message_param_new() - creates a new pa_message_param structure
> > > > > > > pa_message_param_to_string() - converts a pa_message_param to 
> > > > > > > string and frees
> > > > > > > the structure
> > > > > > > The function pa_message_param_write_string()
> > > > > > > has a parameter do_escape.
> > > > > > 
> > > > > > Why not do escaping always?
> > > > > 
> > > > > Because what you are writing as a string may be a list that you have
> > > > > prepared
> > > > > previously. Then you will not want escaping. You may for example 
> > > > > create
> > > > > a list
> > > > > from an array and then insert this list as one string into the final
> > > > > parameter list
> > > > > or have a function that converts a certain structure to a parameter
> > > > > string and
> > > > > then write the result of this function as one element of the final 
> > > > > list.
> > > > 
> > > > My mental model is that parameters have types, list type is different
> > > > than string type, and write_string() is only meant for writing values
> > > > of the string type.
> > > > 
> > > > Can you add a write_raw() function?
> > > 
> > > Yes, this is done in patch 7. But the raw write function differs from what
> > > write_string() is doing. write_string() writes one element of a list,
> > > that is
> > > it encloses the string in braces. The raw write function is intended for
> > > situations where you can't write a complete element with one write, so
> > > it does not add any braces. I am still of the opinion, that a structure
> > > or array converted to a parameter string is a string, so writing something
> > > like this should be done with write_string().
> > 
> > They are different kinds of strings, different abstraction levels. When
> > you're writing an array "as a string", in that context it's just a C
> > string. write_string() with escaping deals with strings in the "message
> > params type system". I don't know if this makes any sense to you.
> > Probably not... In any case, the do_escape flag seems unnecessary
> > complexity to me.
> 
> The alternative would be a function to write an unescaped string in
> addition to the write_raw() function. If you don't like the flag, would
> you be OK with a write_unescaped_string() function? I think it is just
> more comfortable than using write_raw().

Thanks for the concession, I was afraid we'll get stuck on this point.

By comfortable, do you refer to that write_raw() doesn't add braces
around the value? How about adding an add_braces flag to write_raw()?

> > > > > > > +
> > > > > > > +/* Read functions */
> > > > > > > +
> > > > > > > /* Split the specified string into elements. An element is 
> > > > > > > defined as
> > > > > > >  * a sub-string between curly braces. The function is needed 
> > > > > > > to parse
> > > > > > >  * the parameters of messages. Each time it is called returns 
> > > > > > > the position
> > > > > > >  * of the current element in result and the state pointer is 
> > > > > > > advanced to
> > > > > > > - * the next list element.
> > > > > > > + * the next list element. On return, the parameter *is_unpacked 
> > > > > > > indicates
> > > > > > > + * if the string is plain text or contains a sub-list. 
> > > > > > > is_unpacked may
> > > > > > > + * be NULL.
> > > > > > 
> > > > > > is_unpacked looks like unnecessary complexity.
> > > > > > pa_message_params_read_string() should always unescape the value.
> > > > > 
> > > > > It may be possible, that the string you read is a list. Consider the
> > > > > following
> > > > > parameter list: {string1}{some nested structure}{string2}. You can now
> > > > > read this list as three strings and then continue to read the 
> > > > > elements of
> > > > > the nested structure from the second string. You might even create a
> > > > > function
> > > > > that takes a string and outputs a structure. So you are not forced to 
> > > > > go
> > > > > to the full depth of nesting on the first pass. This makes it much 
> > > > > easier
> > > > > to handle deeply nested parameter lists. For me this behavior is an
> > > > > important
> > > > > feature and I do not want to drop it. See also my 

Re: [pulseaudio-discuss] [PATCH 6/8] message-params: Allow parameter strings to contain escaped curly braces

2018-07-26 Thread Georg Chini

On 26.07.2018 12:37, Tanu Kaskinen wrote:

On Sun, 2018-07-22 at 21:11 +0200, Georg Chini wrote:

On 22.07.2018 17:48, Tanu Kaskinen wrote:

On Sun, 2018-07-22 at 16:02 +0200, Georg Chini wrote:

On 21.07.2018 20:17, Tanu Kaskinen wrote:

On Mon, 2018-04-09 at 19:35 +0200, Georg Chini wrote:

The patch adds the possibility to escape curly braces within parameter strings
and introduces several new functions that can be used for writing parameters.

For writing, the structure pa_message_param, which is a wrapper for pa_strbuf
has been created. Following new write functions are available:

pa_message_param_new() - creates a new pa_message_param structure
pa_message_param_to_string() - converts a pa_message_param to string and frees
the structure
The function pa_message_param_write_string()
has a parameter do_escape.

Why not do escaping always?

Because what you are writing as a string may be a list that you have
prepared
previously. Then you will not want escaping. You may for example create
a list
from an array and then insert this list as one string into the final
parameter list
or have a function that converts a certain structure to a parameter
string and
then write the result of this function as one element of the final list.

My mental model is that parameters have types, list type is different
than string type, and write_string() is only meant for writing values
of the string type.

Can you add a write_raw() function?

Yes, this is done in patch 7. But the raw write function differs from what
write_string() is doing. write_string() writes one element of a list,
that is
it encloses the string in braces. The raw write function is intended for
situations where you can't write a complete element with one write, so
it does not add any braces. I am still of the opinion, that a structure
or array converted to a parameter string is a string, so writing something
like this should be done with write_string().

They are different kinds of strings, different abstraction levels. When
you're writing an array "as a string", in that context it's just a C
string. write_string() with escaping deals with strings in the "message
params type system". I don't know if this makes any sense to you.
Probably not... In any case, the do_escape flag seems unnecessary
complexity to me.


The alternative would be a function to write an unescaped string in
addition to the write_raw() function. If you don't like the flag, would
you be OK with a write_unescaped_string() function? I think it is just
more comfortable than using write_raw().




Also writing unescaped strings in situations where escaping is not necessary
saves the overhead of looping over all the characters.


core-util already contains pa_unescape() that does the same thing more
efficiently (if you drop the single quote thing).

pa_unescape() currently does not do the same thing. It removes all
escape characters, while I only want to remove the characters
I actually introduced (those before { or }).
I can however modify pa_unescape() to take the same arguments
as pa_escape().

I don't see the need for being selective when unescaping. Nothing
breaks if all (except escaped) backslashes are stripped.

You are right, if previously all backslashes in the original string
have been escaped, nothing will break. I was still thinking of the
old solution where I did not escape backslashes.



+
+/* Read functions */
+
/* Split the specified string into elements. An element is defined as
 * a sub-string between curly braces. The function is needed to parse
 * the parameters of messages. Each time it is called returns the position
 * of the current element in result and the state pointer is advanced to
- * the next list element.
+ * the next list element. On return, the parameter *is_unpacked indicates
+ * if the string is plain text or contains a sub-list. is_unpacked may
+ * be NULL.

is_unpacked looks like unnecessary complexity.
pa_message_params_read_string() should always unescape the value.

It may be possible, that the string you read is a list. Consider the
following
parameter list: {string1}{some nested structure}{string2}. You can now
read this list as three strings and then continue to read the elements of
the nested structure from the second string. You might even create a
function
that takes a string and outputs a structure. So you are not forced to go
to the full depth of nesting on the first pass. This makes it much easier
to handle deeply nested parameter lists. For me this behavior is an
important
feature and I do not want to drop it. See also my comment on why I do
not always want escaping.

Doesn't split_list() already allow this, why do you want to use
read_string() to do the same thing as split_list()?

read_string() and split_list() are very similar and we could live
without read_string(). It is provided as a counterpart to write_string()
and for convenience additionally does the unescaping if necessary
like write_string does the escaping.
I 

Re: [pulseaudio-discuss] [PATCH 6/8] message-params: Allow parameter strings to contain escaped curly braces

2018-07-26 Thread Tanu Kaskinen
On Sun, 2018-07-22 at 21:11 +0200, Georg Chini wrote:
> On 22.07.2018 17:48, Tanu Kaskinen wrote:
> > On Sun, 2018-07-22 at 16:02 +0200, Georg Chini wrote:
> > > On 21.07.2018 20:17, Tanu Kaskinen wrote:
> > > > On Mon, 2018-04-09 at 19:35 +0200, Georg Chini wrote:
> > > > > The patch adds the possibility to escape curly braces within 
> > > > > parameter strings
> > > > > and introduces several new functions that can be used for writing 
> > > > > parameters.
> > > > > 
> > > > > For writing, the structure pa_message_param, which is a wrapper for 
> > > > > pa_strbuf
> > > > > has been created. Following new write functions are available:
> > > > > 
> > > > > pa_message_param_new() - creates a new pa_message_param structure
> > > > > pa_message_param_to_string() - converts a pa_message_param to string 
> > > > > and frees
> > > > > the structure
> > > > > The function pa_message_param_write_string()
> > > > > has a parameter do_escape.
> > > > 
> > > > Why not do escaping always?
> > > 
> > > Because what you are writing as a string may be a list that you have
> > > prepared
> > > previously. Then you will not want escaping. You may for example create
> > > a list
> > > from an array and then insert this list as one string into the final
> > > parameter list
> > > or have a function that converts a certain structure to a parameter
> > > string and
> > > then write the result of this function as one element of the final list.
> > 
> > My mental model is that parameters have types, list type is different
> > than string type, and write_string() is only meant for writing values
> > of the string type.
> > 
> > Can you add a write_raw() function?
> 
> Yes, this is done in patch 7. But the raw write function differs from what
> write_string() is doing. write_string() writes one element of a list, 
> that is
> it encloses the string in braces. The raw write function is intended for
> situations where you can't write a complete element with one write, so
> it does not add any braces. I am still of the opinion, that a structure
> or array converted to a parameter string is a string, so writing something
> like this should be done with write_string().

They are different kinds of strings, different abstraction levels. When
you're writing an array "as a string", in that context it's just a C
string. write_string() with escaping deals with strings in the "message
params type system". I don't know if this makes any sense to you.
Probably not... In any case, the do_escape flag seems unnecessary
complexity to me.

> Also writing unescaped strings in situations where escaping is not necessary
> saves the overhead of looping over all the characters.
> 
> > > > core-util already contains pa_unescape() that does the same thing more
> > > > efficiently (if you drop the single quote thing).
> > > 
> > > pa_unescape() currently does not do the same thing. It removes all
> > > escape characters, while I only want to remove the characters
> > > I actually introduced (those before { or }).
> > > I can however modify pa_unescape() to take the same arguments
> > > as pa_escape().
> > 
> > I don't see the need for being selective when unescaping. Nothing
> > breaks if all (except escaped) backslashes are stripped.
> 
> You are right, if previously all backslashes in the original string
> have been escaped, nothing will break. I was still thinking of the
> old solution where I did not escape backslashes.
> 
> 
> > 
> > > > > +
> > > > > +/* Read functions */
> > > > > +
> > > > >/* Split the specified string into elements. An element is defined 
> > > > > as
> > > > > * a sub-string between curly braces. The function is needed to 
> > > > > parse
> > > > > * the parameters of messages. Each time it is called returns the 
> > > > > position
> > > > > * of the current element in result and the state pointer is 
> > > > > advanced to
> > > > > - * the next list element.
> > > > > + * the next list element. On return, the parameter *is_unpacked 
> > > > > indicates
> > > > > + * if the string is plain text or contains a sub-list. is_unpacked 
> > > > > may
> > > > > + * be NULL.
> > > > 
> > > > is_unpacked looks like unnecessary complexity.
> > > > pa_message_params_read_string() should always unescape the value.
> > > 
> > > It may be possible, that the string you read is a list. Consider the
> > > following
> > > parameter list: {string1}{some nested structure}{string2}. You can now
> > > read this list as three strings and then continue to read the elements of
> > > the nested structure from the second string. You might even create a
> > > function
> > > that takes a string and outputs a structure. So you are not forced to go
> > > to the full depth of nesting on the first pass. This makes it much easier
> > > to handle deeply nested parameter lists. For me this behavior is an
> > > important
> > > feature and I do not want to drop it. See also my comment on why I do
> > > not always want escaping.
> > 
> > Doesn't 

Re: [pulseaudio-discuss] [PATCH 6/8] message-params: Allow parameter strings to contain escaped curly braces

2018-07-22 Thread Georg Chini

On 22.07.2018 17:48, Tanu Kaskinen wrote:

On Sun, 2018-07-22 at 16:02 +0200, Georg Chini wrote:

On 21.07.2018 20:17, Tanu Kaskinen wrote:

On Mon, 2018-04-09 at 19:35 +0200, Georg Chini wrote:

The patch adds the possibility to escape curly braces within parameter strings
and introduces several new functions that can be used for writing parameters.

For writing, the structure pa_message_param, which is a wrapper for pa_strbuf
has been created. Following new write functions are available:

pa_message_param_new() - creates a new pa_message_param structure
pa_message_param_to_string() - converts a pa_message_param to string and frees
the structure



The function pa_message_param_write_string()
has a parameter do_escape.

Why not do escaping always?

Because what you are writing as a string may be a list that you have
prepared
previously. Then you will not want escaping. You may for example create
a list
from an array and then insert this list as one string into the final
parameter list
or have a function that converts a certain structure to a parameter
string and
then write the result of this function as one element of the final list.

My mental model is that parameters have types, list type is different
than string type, and write_string() is only meant for writing values
of the string type.

Can you add a write_raw() function?


Yes, this is done in patch 7. But the raw write function differs from what
write_string() is doing. write_string() writes one element of a list, 
that is

it encloses the string in braces. The raw write function is intended for
situations where you can't write a complete element with one write, so
it does not add any braces. I am still of the opinion, that a structure
or array converted to a parameter string is a string, so writing something
like this should be done with write_string().
Also writing unescaped strings in situations where escaping is not necessary
saves the overhead of looping over all the characters.


core-util already contains pa_unescape() that does the same thing more
efficiently (if you drop the single quote thing).

pa_unescape() currently does not do the same thing. It removes all
escape characters, while I only want to remove the characters
I actually introduced (those before { or }).
I can however modify pa_unescape() to take the same arguments
as pa_escape().

I don't see the need for being selective when unescaping. Nothing
breaks if all (except escaped) backslashes are stripped.


You are right, if previously all backslashes in the original string
have been escaped, nothing will break. I was still thinking of the
old solution where I did not escape backslashes.





+
+/* Read functions */
+
   /* Split the specified string into elements. An element is defined as
* a sub-string between curly braces. The function is needed to parse
* the parameters of messages. Each time it is called returns the position
* of the current element in result and the state pointer is advanced to
- * the next list element.
+ * the next list element. On return, the parameter *is_unpacked indicates
+ * if the string is plain text or contains a sub-list. is_unpacked may
+ * be NULL.

is_unpacked looks like unnecessary complexity.
pa_message_params_read_string() should always unescape the value.

It may be possible, that the string you read is a list. Consider the
following
parameter list: {string1}{some nested structure}{string2}. You can now
read this list as three strings and then continue to read the elements of
the nested structure from the second string. You might even create a
function
that takes a string and outputs a structure. So you are not forced to go
to the full depth of nesting on the first pass. This makes it much easier
to handle deeply nested parameter lists. For me this behavior is an
important
feature and I do not want to drop it. See also my comment on why I do
not always want escaping.

Doesn't split_list() already allow this, why do you want to use
read_string() to do the same thing as split_list()?


read_string() and split_list() are very similar and we could live
without read_string(). It is provided as a counterpart to write_string()
and for convenience additionally does the unescaping if necessary
like write_string does the escaping.
I don't see why this is a problem. It depends on the context which
is the better function to use.


___
pulseaudio-discuss mailing list
pulseaudio-discuss@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss


Re: [pulseaudio-discuss] [PATCH 6/8] message-params: Allow parameter strings to contain escaped curly braces

2018-07-22 Thread Tanu Kaskinen
On Sun, 2018-07-22 at 16:02 +0200, Georg Chini wrote:
> On 21.07.2018 20:17, Tanu Kaskinen wrote:
> > On Mon, 2018-04-09 at 19:35 +0200, Georg Chini wrote:
> > > The patch adds the possibility to escape curly braces within parameter 
> > > strings
> > > and introduces several new functions that can be used for writing 
> > > parameters.
> > > 
> > > For writing, the structure pa_message_param, which is a wrapper for 
> > > pa_strbuf
> > > has been created. Following new write functions are available:
> > > 
> > > pa_message_param_new() - creates a new pa_message_param structure
> > > pa_message_param_to_string() - converts a pa_message_param to string and 
> > > frees
> > > the structure
> > 
> > I'd like to have the _free suffix in the function name, because for the
> > uninitiated the current name looks like just another "to_string"
> > function with no surprising side effects.
> > 
> > I think we need pa_message_params_free() as well in case an application
> > runs into an error while constructing the parameters and it wants to
> > just get rid of the pa_message_params struct without converting it to a
> > string first.
> > 
> > > pa_message_param_begin_list() - starts a list
> > > pa_message_param_end_list() - ends a list
> > > pa_message_param_write_string() - writes a string to a pa_message_param 
> > > structure
> > > 
> > > For string parameters that contain curly braces, those braces must be 
> > > escaped
> > > by adding a "\" before them. This however means that a trailing backslash 
> > > would
> > > falsely escape the closing bracket. To avoid this, single quotes must be 
> > > added
> > > at start and end of the string.
> > 
> > Why not solve this by the usual method: require escaping of "\" in
> > input with "\\" in output?
> 
> You are right, if I modify pa_unescape() as mentioned further below and then
> use pa_escape()/pa_unescape() the quotes won't be necessary.
> 
> > 
> > > The function pa_message_param_write_string()
> > > has a parameter do_escape.
> > 
> > Why not do escaping always?
> 
> Because what you are writing as a string may be a list that you have 
> prepared
> previously. Then you will not want escaping. You may for example create 
> a list
> from an array and then insert this list as one string into the final 
> parameter list
> or have a function that converts a certain structure to a parameter 
> string and
> then write the result of this function as one element of the final list.

My mental model is that parameters have types, list type is different
than string type, and write_string() is only meant for writing values
of the string type.

Can you add a write_raw() function?

> > 
> > > If true, the necessary escaping is added. Escaping
> > > is only needed if a string might fulfill one of the following conditions:
> > > 
> > > - It contains curly braces
> > > - It contains a trailing "\"
> > > - It is enclosed in single quotes
> > > 
> > > Other strings can be passed without modification.
> > > 
> > > For reading, pa_message_param_read_string() reverts the changes that
> > > pa_message_param_write_string() might have introduced.
> > > 
> > > The patch also adds more restrictions on the object path name. Now only
> > > alphanumeric characters and one of "_", ".", "-" and "/" are allowed.
> > > The path name may not end with a /. If the user specifies a trailing / 
> > > when
> > > sending a message, it will be removed.
> > > ---
> > >   doc/messaging_api.txt   |  34 +++-
> > >   src/Makefile.am |   3 +-
> > >   src/map-file|   5 ++
> > >   src/pulse/message-params.c  | 181 
> > > ++--
> > >   src/pulse/message-params.h  |  23 -
> > >   src/pulsecore/core.c|  20 ++---
> > >   src/pulsecore/message-handler.c |  53 +++-
> > >   src/utils/pactl.c   |   4 +-
> > >   8 files changed, 279 insertions(+), 44 deletions(-)
> > > 
> > > diff --git a/doc/messaging_api.txt b/doc/messaging_api.txt
> > > index 431a5df2..0e6be53f 100644
> > > --- a/doc/messaging_api.txt
> > > +++ b/doc/messaging_api.txt
> > > @@ -14,10 +14,42 @@ look like that:
> > >   {{Integer} {{1st float} {2nd float} ...}}{...}
> > >   Any characters that are not enclosed in curly braces are ignored (all 
> > > characters
> > >   between { and {, between } and } and between } and {). The same syntax 
> > > is used
> > > -to specify message parameters. The following reference lists available 
> > > messages,
> > > +to specify message parameters. The reference further down lists 
> > > available messages,
> > >   their parameters and return values. If a return value is enclosed in 
> > > {}, this
> > >   means that multiple elements of the same type may be returned.
> > >   
> > > +There are several functions that simplify reading and writing message 
> > > parameter
> > > +strings. For writing, the structure pa_message_param can be used. 
> > > Following
> > > +functions are available:
> > 

Re: [pulseaudio-discuss] [PATCH 6/8] message-params: Allow parameter strings to contain escaped curly braces

2018-07-22 Thread Georg Chini

On 21.07.2018 20:17, Tanu Kaskinen wrote:

On Mon, 2018-04-09 at 19:35 +0200, Georg Chini wrote:

The patch adds the possibility to escape curly braces within parameter strings
and introduces several new functions that can be used for writing parameters.

For writing, the structure pa_message_param, which is a wrapper for pa_strbuf
has been created. Following new write functions are available:

pa_message_param_new() - creates a new pa_message_param structure
pa_message_param_to_string() - converts a pa_message_param to string and frees
the structure

I'd like to have the _free suffix in the function name, because for the
uninitiated the current name looks like just another "to_string"
function with no surprising side effects.

I think we need pa_message_params_free() as well in case an application
runs into an error while constructing the parameters and it wants to
just get rid of the pa_message_params struct without converting it to a
string first.


pa_message_param_begin_list() - starts a list
pa_message_param_end_list() - ends a list
pa_message_param_write_string() - writes a string to a pa_message_param 
structure

For string parameters that contain curly braces, those braces must be escaped
by adding a "\" before them. This however means that a trailing backslash would
falsely escape the closing bracket. To avoid this, single quotes must be added
at start and end of the string.

Why not solve this by the usual method: require escaping of "\" in
input with "\\" in output?


You are right, if I modify pa_unescape() as mentioned further below and then
use pa_escape()/pa_unescape() the quotes won't be necessary.




The function pa_message_param_write_string()
has a parameter do_escape.

Why not do escaping always?


Because what you are writing as a string may be a list that you have 
prepared
previously. Then you will not want escaping. You may for example create 
a list
from an array and then insert this list as one string into the final 
parameter list
or have a function that converts a certain structure to a parameter 
string and

then write the result of this function as one element of the final list.




If true, the necessary escaping is added. Escaping
is only needed if a string might fulfill one of the following conditions:

- It contains curly braces
- It contains a trailing "\"
- It is enclosed in single quotes

Other strings can be passed without modification.

For reading, pa_message_param_read_string() reverts the changes that
pa_message_param_write_string() might have introduced.

The patch also adds more restrictions on the object path name. Now only
alphanumeric characters and one of "_", ".", "-" and "/" are allowed.
The path name may not end with a /. If the user specifies a trailing / when
sending a message, it will be removed.
---
  doc/messaging_api.txt   |  34 +++-
  src/Makefile.am |   3 +-
  src/map-file|   5 ++
  src/pulse/message-params.c  | 181 ++--
  src/pulse/message-params.h  |  23 -
  src/pulsecore/core.c|  20 ++---
  src/pulsecore/message-handler.c |  53 +++-
  src/utils/pactl.c   |   4 +-
  8 files changed, 279 insertions(+), 44 deletions(-)

diff --git a/doc/messaging_api.txt b/doc/messaging_api.txt
index 431a5df2..0e6be53f 100644
--- a/doc/messaging_api.txt
+++ b/doc/messaging_api.txt
@@ -14,10 +14,42 @@ look like that:
  {{Integer} {{1st float} {2nd float} ...}}{...}
  Any characters that are not enclosed in curly braces are ignored (all 
characters
  between { and {, between } and } and between } and {). The same syntax is used
-to specify message parameters. The following reference lists available 
messages,
+to specify message parameters. The reference further down lists available 
messages,
  their parameters and return values. If a return value is enclosed in {}, this
  means that multiple elements of the same type may be returned.
  
+There are several functions that simplify reading and writing message parameter

+strings. For writing, the structure pa_message_param can be used. Following
+functions are available:
+pa_message_param_new() - creates a new pa_message_param structure
+pa_message_param_to_string() - converts a pa_message_param to string and frees
+the structure
+pa_message_param_begin_list() - starts a list
+pa_message_param_end_list() - ends a list
+pa_message_param_write_string() - writes a string to a pa_message_param 
structure
+
+For string parameters that contain curly braces, those braces must be escaped
+by adding a "\" before them. This however means that a trailing backslash would
+falsely escape the closing bracket. To avoid this, single quotes must be added
+at start and end of the string. The function pa_message_param_write_string()
+has a parameter do_escape. If true, the necessary escaping is added. Escaping
+is only needed if a string might fulfill one of the following conditions:
+
+- It contains curly 

Re: [pulseaudio-discuss] [PATCH 6/8] message-params: Allow parameter strings to contain escaped curly braces

2018-07-21 Thread Tanu Kaskinen
On Mon, 2018-04-09 at 19:35 +0200, Georg Chini wrote:
> The patch adds the possibility to escape curly braces within parameter strings
> and introduces several new functions that can be used for writing parameters.
> 
> For writing, the structure pa_message_param, which is a wrapper for pa_strbuf
> has been created. Following new write functions are available:
> 
> pa_message_param_new() - creates a new pa_message_param structure
> pa_message_param_to_string() - converts a pa_message_param to string and frees
> the structure

I'd like to have the _free suffix in the function name, because for the
uninitiated the current name looks like just another "to_string"
function with no surprising side effects.

I think we need pa_message_params_free() as well in case an application
runs into an error while constructing the parameters and it wants to
just get rid of the pa_message_params struct without converting it to a
string first.

> pa_message_param_begin_list() - starts a list
> pa_message_param_end_list() - ends a list
> pa_message_param_write_string() - writes a string to a pa_message_param 
> structure
> 
> For string parameters that contain curly braces, those braces must be escaped
> by adding a "\" before them. This however means that a trailing backslash 
> would
> falsely escape the closing bracket. To avoid this, single quotes must be added
> at start and end of the string.

Why not solve this by the usual method: require escaping of "\" in
input with "\\" in output?

> The function pa_message_param_write_string()
> has a parameter do_escape.

Why not do escaping always?

> If true, the necessary escaping is added. Escaping
> is only needed if a string might fulfill one of the following conditions:
> 
> - It contains curly braces
> - It contains a trailing "\"
> - It is enclosed in single quotes
> 
> Other strings can be passed without modification.
> 
> For reading, pa_message_param_read_string() reverts the changes that
> pa_message_param_write_string() might have introduced.
> 
> The patch also adds more restrictions on the object path name. Now only
> alphanumeric characters and one of "_", ".", "-" and "/" are allowed.
> The path name may not end with a /. If the user specifies a trailing / when
> sending a message, it will be removed.
> ---
>  doc/messaging_api.txt   |  34 +++-
>  src/Makefile.am |   3 +-
>  src/map-file|   5 ++
>  src/pulse/message-params.c  | 181 
> ++--
>  src/pulse/message-params.h  |  23 -
>  src/pulsecore/core.c|  20 ++---
>  src/pulsecore/message-handler.c |  53 +++-
>  src/utils/pactl.c   |   4 +-
>  8 files changed, 279 insertions(+), 44 deletions(-)
> 
> diff --git a/doc/messaging_api.txt b/doc/messaging_api.txt
> index 431a5df2..0e6be53f 100644
> --- a/doc/messaging_api.txt
> +++ b/doc/messaging_api.txt
> @@ -14,10 +14,42 @@ look like that:
>  {{Integer} {{1st float} {2nd float} ...}}{...}
>  Any characters that are not enclosed in curly braces are ignored (all 
> characters
>  between { and {, between } and } and between } and {). The same syntax is 
> used
> -to specify message parameters. The following reference lists available 
> messages,
> +to specify message parameters. The reference further down lists available 
> messages,
>  their parameters and return values. If a return value is enclosed in {}, this
>  means that multiple elements of the same type may be returned.
>  
> +There are several functions that simplify reading and writing message 
> parameter
> +strings. For writing, the structure pa_message_param can be used. Following
> +functions are available:
> +pa_message_param_new() - creates a new pa_message_param structure
> +pa_message_param_to_string() - converts a pa_message_param to string and 
> frees
> +the structure
> +pa_message_param_begin_list() - starts a list
> +pa_message_param_end_list() - ends a list
> +pa_message_param_write_string() - writes a string to a pa_message_param 
> structure
> +
> +For string parameters that contain curly braces, those braces must be escaped
> +by adding a "\" before them. This however means that a trailing backslash 
> would
> +falsely escape the closing bracket. To avoid this, single quotes must be 
> added
> +at start and end of the string. The function pa_message_param_write_string()
> +has a parameter do_escape. If true, the necessary escaping is added. Escaping
> +is only needed if a string might fulfill one of the following conditions:
> +
> +- It contains curly braces
> +- It contains a trailing "\"
> +- It is enclosed in single quotes
> +
> +Other strings can be passed without modification.
> +
> +For reading, the following functions are available:
> +pa_message_param_split_list() - parse message parameter string
> +pa_message_param_read_string() - read a string from a parameter list
> +
> +pa_message_param_read_string() also reverts the changes that
> 

[pulseaudio-discuss] [PATCH 6/8] message-params: Allow parameter strings to contain escaped curly braces

2018-04-09 Thread Georg Chini
The patch adds the possibility to escape curly braces within parameter strings
and introduces several new functions that can be used for writing parameters.

For writing, the structure pa_message_param, which is a wrapper for pa_strbuf
has been created. Following new write functions are available:

pa_message_param_new() - creates a new pa_message_param structure
pa_message_param_to_string() - converts a pa_message_param to string and frees
the structure
pa_message_param_begin_list() - starts a list
pa_message_param_end_list() - ends a list
pa_message_param_write_string() - writes a string to a pa_message_param 
structure

For string parameters that contain curly braces, those braces must be escaped
by adding a "\" before them. This however means that a trailing backslash would
falsely escape the closing bracket. To avoid this, single quotes must be added
at start and end of the string. The function pa_message_param_write_string()
has a parameter do_escape. If true, the necessary escaping is added. Escaping
is only needed if a string might fulfill one of the following conditions:

- It contains curly braces
- It contains a trailing "\"
- It is enclosed in single quotes

Other strings can be passed without modification.

For reading, pa_message_param_read_string() reverts the changes that
pa_message_param_write_string() might have introduced.

The patch also adds more restrictions on the object path name. Now only
alphanumeric characters and one of "_", ".", "-" and "/" are allowed.
The path name may not end with a /. If the user specifies a trailing / when
sending a message, it will be removed.
---
 doc/messaging_api.txt   |  34 +++-
 src/Makefile.am |   3 +-
 src/map-file|   5 ++
 src/pulse/message-params.c  | 181 ++--
 src/pulse/message-params.h  |  23 -
 src/pulsecore/core.c|  20 ++---
 src/pulsecore/message-handler.c |  53 +++-
 src/utils/pactl.c   |   4 +-
 8 files changed, 279 insertions(+), 44 deletions(-)

diff --git a/doc/messaging_api.txt b/doc/messaging_api.txt
index 431a5df2..0e6be53f 100644
--- a/doc/messaging_api.txt
+++ b/doc/messaging_api.txt
@@ -14,10 +14,42 @@ look like that:
 {{Integer} {{1st float} {2nd float} ...}}{...}
 Any characters that are not enclosed in curly braces are ignored (all 
characters
 between { and {, between } and } and between } and {). The same syntax is used
-to specify message parameters. The following reference lists available 
messages,
+to specify message parameters. The reference further down lists available 
messages,
 their parameters and return values. If a return value is enclosed in {}, this
 means that multiple elements of the same type may be returned.
 
+There are several functions that simplify reading and writing message parameter
+strings. For writing, the structure pa_message_param can be used. Following
+functions are available:
+pa_message_param_new() - creates a new pa_message_param structure
+pa_message_param_to_string() - converts a pa_message_param to string and frees
+the structure
+pa_message_param_begin_list() - starts a list
+pa_message_param_end_list() - ends a list
+pa_message_param_write_string() - writes a string to a pa_message_param 
structure
+
+For string parameters that contain curly braces, those braces must be escaped
+by adding a "\" before them. This however means that a trailing backslash would
+falsely escape the closing bracket. To avoid this, single quotes must be added
+at start and end of the string. The function pa_message_param_write_string()
+has a parameter do_escape. If true, the necessary escaping is added. Escaping
+is only needed if a string might fulfill one of the following conditions:
+
+- It contains curly braces
+- It contains a trailing "\"
+- It is enclosed in single quotes
+
+Other strings can be passed without modification.
+
+For reading, the following functions are available:
+pa_message_param_split_list() - parse message parameter string
+pa_message_param_read_string() - read a string from a parameter list
+
+pa_message_param_read_string() also reverts the changes that
+pa_message_param_write_string() might have introduced.
+
+Reference:
+
 Object path: /core
 Message: list-handlers
 Parameters: None
diff --git a/src/Makefile.am b/src/Makefile.am
index ccdad8ff..72d8cf22 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -675,6 +675,7 @@ libpulsecommon_@PA_MAJORMINOR@_la_SOURCES = \
pulse/timeval.c pulse/timeval.h \
pulse/rtclock.c pulse/rtclock.h \
pulse/volume.c pulse/volume.h \
+   pulse/message-params.c pulse/message-params.h \
pulsecore/atomic.h \
pulsecore/authkey.c pulsecore/authkey.h \
pulsecore/conf-parser.c pulsecore/conf-parser.h \
@@ -884,6 +885,7 @@ libpulse_la_SOURCES = \
pulse/mainloop-api.c pulse/mainloop-api.h \