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

lyd_new_path handle json encoded string leaves #2132

Conversation

irfanHaslanded
Copy link
Contributor

According to ietf rfc 8259, strings are always surrounded by double
quotes. This means, for storing within libyang, we must strip input
data of these, and take the value as the stripped portion.

Example: const char * data = ""Great View""; should yield
const char *value = "Great View";

For this, a new option is used LYD_NEW_PATH_JSON_VALUE

@irfanHaslanded irfanHaslanded force-pushed the irfan/gnmi-json-val-new-path branch from d3291a0 to ac37485 Compare November 21, 2023 05:46
 According to ietf rfc 8259, strings are always surrounded by double
 quotes. This means, for storing within libyang, we must strip input
 data of these, and take the value as the stripped portion.

 Example: const char * data = "\"Great View\""; should yield
 const char *value = "Great View";

 For this, a new option is used `LYD_NEW_PATH_JSON_VALUE`
@irfanHaslanded irfanHaslanded force-pushed the irfan/gnmi-json-val-new-path branch from ac37485 to a4d739f Compare November 21, 2023 06:11
@irfanHaslanded irfanHaslanded marked this pull request as ready for review November 21, 2023 06:29
@michalvasko
Copy link
Member

Could you please reference the exact text that mentions this feature?

@irfanHaslanded
Copy link
Contributor Author

Could you please reference the exact text that mentions this feature?

https://datatracker.ietf.org/doc/html/rfc8259#section-7

[7](https://datatracker.ietf.org/doc/html/rfc8259#section-7).  Strings

   The representation of strings is similar to conventions used in the C
   family of programming languages.  A string begins and ends with
   quotation marks.  All Unicode characters may be placed within the
   quotation marks, except for the characters that MUST be escaped:
   quotation mark, reverse solidus, and the control characters (U+0000
   through U+001F).

@michalvasko
Copy link
Member

I read that and, to my understanding, it means the quotation marks should be escaped (and I believe they are), not removed.

@irfanHaslanded
Copy link
Contributor Author

irfanHaslanded commented Nov 21, 2023

I read that and, to my understanding, it means the quotation marks should be escaped (and I believe they are), not removed.

This change addresses this part of the RFC A string begins and ends with quotation marks.

Normally, lyd_new_path would be passed
char *val = "Great View"

but when decoding from gnmi, we would get
char *val = "\"Great View\""

However, we must consider the value as Great View and not "Great View"

@jktjkt
Copy link
Contributor

jktjkt commented Nov 21, 2023

What is the use case for feeding libyang with JSON-encoded string values? How is this different from, say, Base64-encoded string values or RFC2047-style encoded string values? How do you plan to use this, and why is it needed to put this feature into libyang?

@michalvasko
Copy link
Member

Each string value in JSON is encoded as "value", the quotations are simply a part of the data format and it is expected the parser removes it. Similarly with encoded characters and similar format-specific phenomenons. libyang handles only YANG JSON-specific features such as the interpretation of prefixes.

@irfanHaslanded
Copy link
Contributor Author

I understand. Will keep this changeset in gnmi where it should belong.

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

Successfully merging this pull request may close these issues.

3 participants