Skip to content

Commit

Permalink
Support quoted INI string values
Browse files Browse the repository at this point in the history
Support singly and doubly quoted INI strings, e.g. leading and trailing
spaces in WiFi SSID/PSK field values.
  • Loading branch information
nmschulte authored and danopernis committed Aug 16, 2024
1 parent 1b1071a commit 8a18b05
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions doc/ESP/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ ssid= enter here the SSID of your wireless network
psk= enter here the valid password
```

- Leading and trailing spaces are stripped from the INI field values; a singly (`'`) or doubly (`"`) quoted string can be used to retain such spaces, if necessary.
- Store the `prusa_printer_settings.ini` file in the root folder of the USB flash drive and plug in to the printer
- Run the **Setting-> Load Settings from** command from the printer
- Make sure the **Settings -> Lan setting**s is set to WiFi
Expand Down
13 changes: 13 additions & 0 deletions lib/inih/ini.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,18 @@ static char* lskip(const char* s)
return (char*)s;
}

/* Strip quotes from single and double quoted strings */
static char* unquote(char* s)
{
int l = strlen(s);
if (l && s[0] == s[l - 1] && (s[0] == '\'' || s[0] == '"'))
{
s[l - 1] = '\0';
s++;
}
return s;
}

/* Return pointer to first char (of chars) or inline comment in given string,
or pointer to null at end of string if neither found. Inline comment must
be prefixed by a whitespace character to register as a comment. */
Expand Down Expand Up @@ -194,6 +206,7 @@ int ini_parse_stream(ini_reader reader, void* stream, ini_handler handler,
#endif
value = lskip(value);
rstrip(value);
value = unquote(value);

/* Valid name[=:]value pair found, call handler */
strncpy0(prev_name, name, sizeof(prev_name));
Expand Down

0 comments on commit 8a18b05

Please sign in to comment.