1 /* getsubopt.c --- Parse comma separate list into words, DIGEST-MD5 style.
2 * Copyright (C) 2002, 2003, 2004 Simon Josefsson
3 * Copyright (C) 1996, 1997, 1999 Free Software Foundation, Inc.
4 * From the GNU C Library, under GNU LGPL version 2.1.
5 * Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
6 * Modified for Libgsasl by Simon Josefsson <simon@josefsson.org>
8 * This file is part of GNU SASL Library.
10 * GNU SASL Library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public License
12 * as published by the Free Software Foundation; either version 2.1 of
13 * the License, or (at your option) any later version.
15 * GNU SASL Library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with GNU SASL Library; if not, write to the Free
22 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
23 * Boston, MA 02110-1301, USA.
34 /* Get memchr and memcmp. */
37 /* Parse comma separated suboption from *OPTIONP and match against
38 strings in TOKENS. If found return index and set *VALUEP to
39 optional value introduced by an equal sign. If the suboption is
40 not part of TOKENS return in *VALUEP beginning of unknown
41 suboption. On exit *OPTIONP is set to the beginning of the next
42 token or at the terminating NUL character.
44 This function is NOT identical to standard getsubopt! */
46 digest_md5_getsubopt (char **optionp
,
47 const char *const *tokens
, char **valuep
)
53 if (**optionp
== '\0')
56 /* Find end of next token. */
58 while (*endp
!= '\0' && (inside_quote
|| (!inside_quote
&& *endp
!= ',')))
61 inside_quote
= !inside_quote
;
65 /* Find start of value. */
66 vstart
= memchr (*optionp
, '=', endp
- *optionp
);
70 /* Try to match the characters between *OPTIONP and VSTART against
72 for (cnt
= 0; tokens
[cnt
] != NULL
; ++cnt
)
73 if (memcmp (*optionp
, tokens
[cnt
], vstart
- *optionp
) == 0
74 && tokens
[cnt
][vstart
- *optionp
] == '\0')
76 /* We found the current option in TOKENS. */
77 *valuep
= vstart
!= endp
? vstart
+ 1 : NULL
;
79 while (*valuep
&& (**valuep
== ' ' ||
82 **valuep
== '\n' || **valuep
== '"'))
93 while (*endp
== ' ' ||
95 *endp
== '\r' || *endp
== '\n' || *endp
== '"')
97 while (**optionp
== ' ' ||
98 **optionp
== '\t' || **optionp
== '\r' || **optionp
== '\n')
104 /* The current suboption does not match any option. */
110 while (**optionp
== ' ' ||
111 **optionp
== '\t' || **optionp
== '\r' || **optionp
== '\n')