11//
22// Option routines for CUPS.
33//
4- // Copyright © 2022-2023 by OpenPrinting.
4+ // Copyright © 2022-2024 by OpenPrinting.
55// Copyright © 2007-2017 by Apple Inc.
66// Copyright © 1997-2007 by Easy Software Products.
77//
@@ -201,10 +201,14 @@ cupsGetOption(const char *name, // I - Name of option
201201// intact - use @code cupsParseOptions@ on the value to extract the
202202// collection attributes.
203203//
204+ // The "end" argument, if not `NULL`, receives a pointer to the end of the
205+ // options.
206+ //
204207
205208size_t // O - Number of options found
206209cupsParseOptions (
207210 const char * arg , // I - Argument to parse
211+ const char * * end , // O - Pointer to end of options or `NULL` for "don't care"
208212 size_t num_options , // I - Number of options
209213 cups_option_t * * options ) // O - Options found
210214{
@@ -217,6 +221,9 @@ cupsParseOptions(
217221
218222
219223 // Range check input...
224+ if (end )
225+ * end = NULL ;
226+
220227 if (!arg )
221228 return (num_options );
222229
@@ -231,20 +238,9 @@ cupsParseOptions(
231238 }
232239
233240 if (* copyarg == '{' )
234- {
235- // Remove surrounding {} so we can parse "{name=value ... name=value}"...
236- if ((ptr = copyarg + strlen (copyarg ) - 1 ) > copyarg && * ptr == '}' )
237- {
238- * ptr = '\0' ;
239- ptr = copyarg + 1 ;
240- }
241- else
242- ptr = copyarg ;
243- }
241+ ptr = copyarg + 1 ;
244242 else
245- {
246243 ptr = copyarg ;
247- }
248244
249245 // Skip leading spaces...
250246 while (_cups_isspace (* ptr ))
@@ -262,6 +258,13 @@ cupsParseOptions(
262258 if (ptr == name )
263259 break ;
264260
261+ // End after the closing brace...
262+ if (* ptr == '}' && * copyarg == '{' )
263+ {
264+ ptr ++ ;
265+ break ;
266+ }
267+
265268 // Skip trailing spaces...
266269 while (_cups_isspace (* ptr ))
267270 * ptr ++ = '\0' ;
@@ -356,6 +359,10 @@ cupsParseOptions(
356359 num_options = cupsAddOption (name , value , num_options , options );
357360 }
358361
362+ // Save the progress in the input string...
363+ if (end )
364+ * end = arg + (ptr - copyarg );
365+
359366 // Free the copy of the argument we made and return the number of options found.
360367 free (copyarg );
361368
0 commit comments