ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/ermyth/src/tokenize.C
Revision: 1.1
Committed: Thu Jul 19 08:24:59 2007 UTC (16 years, 10 months ago) by pippijn
Content type: text/plain
Branch: MAIN
Log Message:
initial import. the most important changes since Atheme are:
- fixed many memory leaks
- fixed many bugs
- converted to C++ and use more STL containers
- added a (not very enhanced yet) perl module
- greatly improved XML-RPC speed
- added a JSON-RPC module with code from json-cpp
- added a valgrind memcheck module to operserv
- added a more object oriented base64 implementation
- added a specialised unit test framework
- improved stability
- use gettimeofday() if available
- reworked adding/removing commands
- MemoServ IGNORE DEL can now remove indices

File Contents

# Content
1 /*
2 * tokenize.C: Tokenization routines.
3 * Rights to this code are documented in doc/LICENSE.
4 *
5 * Copyright © 2005-2007 Atheme Project (http://www.atheme.org)
6 */
7
8 static char const rcsid[] = "$Id";
9
10 #include "atheme.h"
11 #include "pmodule.h"
12
13 int
14 sjtoken (char *message, char delimiter, char **parv)
15 {
16 char *next;
17 unsigned int count;
18
19 if (!message)
20 return 0;
21
22 /* now we take the beginning of the message and find all the spaces...
23 * set them to \0 and use 'next' to go through the string
24 */
25 next = message;
26
27 /* eat any additional delimiters */
28 while (*next == delimiter)
29 next++;
30
31 parv[0] = next;
32 count = 1;
33
34 while (*next)
35 {
36 /* this is fine here, since we don't have a :delimited
37 * parameter like tokenize
38 */
39
40 if (count == 256)
41 {
42 /* we've reached our limit */
43 slog (LG_DEBUG, "sjtokenize(): reached param limit");
44 return count;
45 }
46
47 if (*next == delimiter)
48 {
49 *next = '\0';
50 next++;
51 /* eat any additional delimiters */
52 while (*next == delimiter)
53 next++;
54 /* if it's the end of the string, it's simply
55 ** an extra space at the end. here we break.
56 */
57 if (*next == '\0')
58 break;
59
60 /* if it happens to be a stray \r, break too */
61 if (*next == '\r')
62 break;
63
64 parv[count] = next;
65 count++;
66 }
67 else
68 next++;
69 }
70
71 return count;
72 }
73
74 /* this splits apart a message with origin and command picked off already */
75 int
76 tokenize (char *message, char **parv)
77 {
78 char *pos = NULL;
79 char *next;
80 unsigned int count = 0;
81
82 if (!message)
83 return -1;
84
85 /* first we fid out of there's a : in the message, save that string
86 * somewhere so we can set it to the last param in parv
87 * also make sure there's a space before it... if not then we're screwed
88 */
89 pos = message;
90 while (true)
91 {
92 if ((pos = strchr (pos, ':')))
93 {
94 pos--;
95 if (*pos != ' ')
96 {
97 pos += 2;
98 continue;
99 }
100 *pos = '\0';
101 pos++;
102 *pos = '\0';
103 pos++;
104 break;
105 }
106 else
107 break;
108 }
109
110 /* now we take the beginning of the message and find all the spaces...
111 * set them to \0 and use 'next' to go through the string
112 */
113
114 next = message;
115 parv[0] = message;
116 count = 1;
117
118 while (*next)
119 {
120 if (count == MAXPARC)
121 {
122 /* we've reached one less than our max limit
123 * to handle the parameter we already ripped off
124 */
125 slog (LG_DEBUG, "tokenize(): reached para limit");
126 return count;
127 }
128 if (*next == ' ')
129 {
130 *next = '\0';
131 next++;
132 /* eat any additional spaces */
133 while (*next == ' ')
134 next++;
135 /* if it's the end of the string, it's simply
136 * an extra space before the :parameter. break.
137 */
138 if (*next == '\0')
139 break;
140 parv[count] = next;
141 count++;
142 }
143 else
144 next++;
145 }
146
147 if (pos)
148 {
149 parv[count] = pos;
150 count++;
151 }
152
153 return count;
154 }
155
156 /* vim:cinoptions=>s,e0,n0,f0,{0,}0,^0,=s,ps,t0,c3,+s,(2s,us,)20,*30,gs,hs
157 * vim:ts=8
158 * vim:sw=8
159 * vim:noexpandtab
160 */