1 /* Cookies name-value pairs parser */
11 #include "cookies/parser.h"
12 #include "util/string.h"
15 /* In order to be able to compile parsetst, you should try to use minimum
16 * of foreign stuff here. */
20 debug_cookie_parser(struct cookie_str
*cstr
, unsigned char *pos
, int ws
, int eq
)
22 int namelen
= int_max(cstr
->nam_end
- cstr
->str
, 0);
23 int valuelen
= int_max(cstr
->val_end
- cstr
->val_start
, 0);
25 printf("[%.*s] :: (%.*s) :: %d,%d [%s] %d\n",
27 valuelen
, cstr
->val_start
,
28 ws
, eq
, pos
, cstr
->nam_end
- cstr
->str
);
31 #define debug_cookie_parser(cstr, pos, ws, eq)
35 /* This function parses the starting name/value pair from the cookie string.
36 * The syntax is simply: <name token> [ '=' <value token> ] with possible
37 * spaces between tokens and '='. However spaces in the value token is also
38 * allowed. See bug 174 for a description why. */
39 /* Defined in RFC 2965. */
40 /* Return cstr on success, NULL on failure. */
42 parse_cookie_str(struct cookie_str
*cstr
, unsigned char *str
)
44 memset(cstr
, 0, sizeof(*cstr
));
47 /* Parse name token */
48 while (*str
!= ';' && *str
!= '=' && !isspace(*str
) && *str
)
51 /* Bail out if name token is empty */
52 if (str
== cstr
->str
) return NULL
;
61 /* No value token, so just set to empty value */
62 cstr
->val_start
= str
;
67 /* Map 'a===b' to 'a=b' */
68 do str
++; while (*str
== '=');
72 /* No spaces in the name token is allowed */
78 /* Parse value token */
80 /* Start with empty value, so even 'a=' will work */
81 cstr
->val_start
= str
;
84 for (; *str
!= ';' && *str
; str
++) {
85 /* Allow spaces in the value but leave out ending spaces */
87 cstr
->val_end
= str
+ 1;