This commit was manufactured by cvs2svn to create branch 'fedora'.
[linux-2.6.git] / net / tux / parser.h
1 /*
2  * TUX - Integrated Application Protocols Layer and Object Cache
3  *
4  * Copyright (C) 2000, Ingo Molnar <mingo@redhat.com>
5  *
6  * parser.h: generic parsing routines
7  */
8
9 #define get_c(ptr,left)                                         \
10 ({                                                              \
11         char __ret;                                     \
12                                                                 \
13         if (!left)                                              \
14                 GOTO_INCOMPLETE;                                \
15         left--;                                                 \
16         __ret = *((ptr)++);                                     \
17         if (!__ret)                                             \
18                 GOTO_REDIR;                                     \
19         __ret;                                                  \
20 })
21
22 #define PARSE_TOKEN(ptr,str,left)                               \
23         ({                                                      \
24                 int __ret;                                      \
25                                                                 \
26                 if (!left)                                      \
27                         GOTO_INCOMPLETE;                        \
28                 if (sizeof(str)-1 > left) {                     \
29                         if (memcmp(ptr, str, left))             \
30                                 GOTO_REDIR;                     \
31                         GOTO_INCOMPLETE;                        \
32                 }                                               \
33                                                                 \
34                 if (memcmp(ptr, str, sizeof(str)-1))            \
35                         __ret = 0;                              \
36                 else {                                          \
37                         ptr += sizeof(str)-1;                   \
38                         left -= sizeof(str)-1;                  \
39                         __ret = 1;                              \
40                 }                                               \
41                 __ret;                                          \
42         })
43
44 #define PARSE_METHOD(req,ptr,name,left)                         \
45         ({                                                      \
46                 int __ret;                                      \
47                                                                 \
48                 if (PARSE_TOKEN(ptr,#name" ",left)) {           \
49                         req->method = METHOD_##name;            \
50                         __ret = 1;                              \
51                 } else                                          \
52                         __ret = 0;                              \
53                 __ret;                                          \
54         })
55
56 #define COPY_LINE(ptr,target,left)                              \
57         do {                                                    \
58                 char prev_c = 0, c;                             \
59                 while (((c = get_c(ptr,left))) != '\n') \
60                         *target++ = prev_c = c;                 \
61                 if (prev_c != '\r')                             \
62                         GOTO_REDIR;                             \
63         } while (0)
64
65 #define COPY_LINE_TOLOWER(ptr,target,left,limit)                \
66         do {                                                    \
67                 char prev_c = 0, c;                             \
68                 while (((c = get_c(ptr,left))) != '\n') {       \
69                         if ((c >= 'A') && (c <= 'Z'))           \
70                                 c -= 'A'-'a';                   \
71                         *target++ = prev_c = c;                 \
72                         if (target == (limit))                  \
73                                 GOTO_REDIR;                     \
74                 }                                               \
75                 if (prev_c != '\r')                             \
76                         GOTO_REDIR;                             \
77         } while (0)
78
79 #define COPY_FIELD(ptr,target,left)                             \
80         do {                                                    \
81                 char c;                                         \
82                 while ((c = get_c(ptr,left)) != ' ')            \
83                         *target++ = c;                          \
84         } while (0)
85
86 #define SKIP_LINE(ptr,left)                                     \
87         do {                                                    \
88                 char prev_c = 0, c;                             \
89                 while (((c = get_c(ptr,left))) != '\n')         \
90                         prev_c = c;                             \
91                 if (prev_c != '\r')                             \
92                         GOTO_REDIR;                             \
93         } while (0)
94
95 #define SKIP_WHITESPACE(curr,left)              \
96 do {                                            \
97         while ((left) && (*(curr) == ' '))      \
98                 (curr)++, (left)--;             \
99         if (!(left))                            \
100                 GOTO_REDIR;                     \
101 } while (0)
102