Mercurial > hg
annotate mcabber/libjabber/str.c @ 430:d03663d2e7d9
Display error messages as specified in RFC3920 (9.3)
If possible, we display the child element corresponding to the stanza
error conditions defined in RFC3920. Error code and error text will
be displayed if available.
author | Mikael Berthe <mikael@lilotux.net> |
---|---|
date | Sun, 11 Sep 2005 22:01:57 +0200 |
parents | c3ae9251c197 |
children | 5f43b532cc37 |
rev | line source |
---|---|
25 | 1 /* |
2 * This program is free software; you can redistribute it and/or modify | |
3 * it under the terms of the GNU General Public License as published by | |
4 * the Free Software Foundation; either version 2 of the License, or | |
5 * (at your option) any later version. | |
6 * | |
7 * This program is distributed in the hope that it will be useful, | |
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
10 * GNU General Public License for more details. | |
11 * | |
12 * You should have received a copy of the GNU General Public License | |
13 * along with this program; if not, write to the Free Software | |
14 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
15 * | |
417
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
401
diff
changeset
|
16 * Copyrights |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
401
diff
changeset
|
17 * |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
401
diff
changeset
|
18 * Portions created by or assigned to Jabber.com, Inc. are |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
401
diff
changeset
|
19 * Copyright (c) 1999-2002 Jabber.com, Inc. All Rights Reserved. Contact |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
401
diff
changeset
|
20 * information for Jabber.com, Inc. is available at http://www.jabber.com/. |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
401
diff
changeset
|
21 * |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
401
diff
changeset
|
22 * Portions Copyright (c) 1998-1999 Jeremie Miller. |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
401
diff
changeset
|
23 * |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
401
diff
changeset
|
24 * Acknowledgements |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
401
diff
changeset
|
25 * |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
401
diff
changeset
|
26 * Special thanks to the Jabber Open Source Contributors for their |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
401
diff
changeset
|
27 * suggestions and support of Jabber. |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
401
diff
changeset
|
28 * |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
401
diff
changeset
|
29 */ |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
401
diff
changeset
|
30 |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
401
diff
changeset
|
31 /** |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
401
diff
changeset
|
32 * @file str.c |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
401
diff
changeset
|
33 * @brief utilities for string handling |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
401
diff
changeset
|
34 * |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
401
diff
changeset
|
35 * This file contains utility functions for string handling: |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
401
diff
changeset
|
36 * - NULL pointer save versions of many functions in string.c |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
401
diff
changeset
|
37 * - string spools |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
401
diff
changeset
|
38 * - functions to (un)escape strings for XML usage |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
401
diff
changeset
|
39 * |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
401
diff
changeset
|
40 * String spools allow to create a string by concatenating several smaller strings |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
401
diff
changeset
|
41 * and the spool implementation is allocating the neccessary memory using memory pools. |
25 | 42 */ |
43 | |
44 #include "libxode.h" | |
45 | |
417
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
401
diff
changeset
|
46 /** |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
401
diff
changeset
|
47 * NULL pointer save version of strdup() |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
401
diff
changeset
|
48 * |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
401
diff
changeset
|
49 * @param str the string the should be duplicated |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
401
diff
changeset
|
50 * @return the duplicated string |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
401
diff
changeset
|
51 */ |
25 | 52 char *j_strdup(const char *str) |
53 { | |
54 if(str == NULL) | |
55 return NULL; | |
56 else | |
57 return strdup(str); | |
58 } | |
59 | |
417
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
401
diff
changeset
|
60 /** |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
401
diff
changeset
|
61 * NULL pointer save version of strcat() |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
401
diff
changeset
|
62 * |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
401
diff
changeset
|
63 * @note the return value of j_strcat() is not compatible with the return value of strcat() |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
401
diff
changeset
|
64 * |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
401
diff
changeset
|
65 * @todo check if the behaviour of the return value is intended |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
401
diff
changeset
|
66 * |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
401
diff
changeset
|
67 * @param dest where to append the string |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
401
diff
changeset
|
68 * @param txt what to append |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
401
diff
changeset
|
69 * @return dest if txt contains a NULL pointer, pointer to the terminating zero byte of the result else |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
401
diff
changeset
|
70 */ |
25 | 71 char *j_strcat(char *dest, char *txt) |
72 { | |
73 if(!txt) return(dest); | |
74 | |
75 while(*txt) | |
76 *dest++ = *txt++; | |
77 *dest = '\0'; | |
78 | |
79 return(dest); | |
80 } | |
81 | |
417
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
401
diff
changeset
|
82 /** |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
401
diff
changeset
|
83 * NULL pointer save version of strcmp |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
401
diff
changeset
|
84 * |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
401
diff
changeset
|
85 * If one of the parameters contains a NULL pointer, the string is considered to be unequal. |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
401
diff
changeset
|
86 * |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
401
diff
changeset
|
87 * @note the return value is not compatible with strcmp() |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
401
diff
changeset
|
88 * |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
401
diff
changeset
|
89 * @param a the one string |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
401
diff
changeset
|
90 * @param b the other string |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
401
diff
changeset
|
91 * @return 0 if the strings are equal, -1 if the strings are not equal |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
401
diff
changeset
|
92 */ |
25 | 93 int j_strcmp(const char *a, const char *b) |
94 { | |
95 if(a == NULL || b == NULL) | |
96 return -1; | |
417
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
401
diff
changeset
|
97 |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
401
diff
changeset
|
98 while(*a == *b && *a != '\0' && *b != '\0'){ a++; b++; } |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
401
diff
changeset
|
99 |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
401
diff
changeset
|
100 if(*a == *b) return 0; |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
401
diff
changeset
|
101 |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
401
diff
changeset
|
102 return -1; |
25 | 103 } |
104 | |
417
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
401
diff
changeset
|
105 /** |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
401
diff
changeset
|
106 * NULL pointer save version of strcasecmp() |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
401
diff
changeset
|
107 * |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
401
diff
changeset
|
108 * If one of the parameters contains a NULL pointer, the string is considered to be unequal |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
401
diff
changeset
|
109 * |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
401
diff
changeset
|
110 * @param a the one string |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
401
diff
changeset
|
111 * @param b the other string |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
401
diff
changeset
|
112 * @return 0 if the strings are equal, non zero else |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
401
diff
changeset
|
113 */ |
25 | 114 int j_strcasecmp(const char *a, const char *b) |
115 { | |
116 if(a == NULL || b == NULL) | |
117 return -1; | |
118 else | |
119 return strcasecmp(a, b); | |
120 } | |
121 | |
417
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
401
diff
changeset
|
122 /** |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
401
diff
changeset
|
123 * NULL pointer save version of strncmp() |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
401
diff
changeset
|
124 * |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
401
diff
changeset
|
125 * If one of the parameters contains a NULL pointer, the string is considered to be unequal |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
401
diff
changeset
|
126 * |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
401
diff
changeset
|
127 * @param a the first string |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
401
diff
changeset
|
128 * @param b the second string |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
401
diff
changeset
|
129 * @param i how many characters to compare at most |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
401
diff
changeset
|
130 * @return 0 if the strings are equal (within the given length limitation), non zero else |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
401
diff
changeset
|
131 */ |
25 | 132 int j_strncmp(const char *a, const char *b, int i) |
133 { | |
134 if(a == NULL || b == NULL) | |
135 return -1; | |
136 else | |
137 return strncmp(a, b, i); | |
138 } | |
139 | |
417
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
401
diff
changeset
|
140 /** |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
401
diff
changeset
|
141 * NULL pointer save version of strncasecmp() |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
401
diff
changeset
|
142 * |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
401
diff
changeset
|
143 * If one of the parameters contains a NULL pointer, the string is considered to be unequal |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
401
diff
changeset
|
144 * |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
401
diff
changeset
|
145 * @param a the first string |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
401
diff
changeset
|
146 * @param b the second string |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
401
diff
changeset
|
147 * @param i how many characters to compare at most |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
401
diff
changeset
|
148 * @return 0 if the strings are equal (within the given length limitation), non zero else |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
401
diff
changeset
|
149 */ |
25 | 150 int j_strncasecmp(const char *a, const char *b, int i) |
151 { | |
152 if(a == NULL || b == NULL) | |
153 return -1; | |
154 else | |
155 return strncasecmp(a, b, i); | |
156 } | |
157 | |
417
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
401
diff
changeset
|
158 /** |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
401
diff
changeset
|
159 * NULL pointer save version of strlen |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
401
diff
changeset
|
160 * |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
401
diff
changeset
|
161 * If the parameter contains a NULL pointer, 0 is returned |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
401
diff
changeset
|
162 * |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
401
diff
changeset
|
163 * @param a the string for which the length should be calculated |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
401
diff
changeset
|
164 * @return 0 if a==NULL, length of the string else |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
401
diff
changeset
|
165 */ |
25 | 166 int j_strlen(const char *a) |
167 { | |
168 if(a == NULL) | |
169 return 0; | |
170 else | |
171 return strlen(a); | |
172 } | |
173 | |
174 int j_atoi(const char *a, int def) | |
175 { | |
176 if(a == NULL) | |
177 return def; | |
178 else | |
179 return atoi(a); | |
180 } | |
181 | |
182 spool spool_new(pool p) | |
183 { | |
184 spool s; | |
185 | |
186 s = pmalloc(p, sizeof(struct spool_struct)); | |
187 s->p = p; | |
188 s->len = 0; | |
189 s->last = NULL; | |
190 s->first = NULL; | |
191 return s; | |
192 } | |
193 | |
194 void spool_add(spool s, char *str) | |
195 { | |
196 struct spool_node *sn; | |
197 int len; | |
198 | |
199 if(str == NULL) | |
200 return; | |
201 | |
202 len = strlen(str); | |
203 if(len == 0) | |
204 return; | |
205 | |
206 sn = pmalloc(s->p, sizeof(struct spool_node)); | |
207 sn->c = pstrdup(s->p, str); | |
208 sn->next = NULL; | |
209 | |
210 s->len += len; | |
211 if(s->last != NULL) | |
212 s->last->next = sn; | |
213 s->last = sn; | |
214 if(s->first == NULL) | |
215 s->first = sn; | |
216 } | |
217 | |
218 void spooler(spool s, ...) | |
219 { | |
220 va_list ap; | |
221 char *arg = NULL; | |
222 | |
223 if(s == NULL) | |
224 return; | |
225 | |
226 va_start(ap, s); | |
227 | |
228 /* loop till we hit our end flag, the first arg */ | |
229 while(1) | |
230 { | |
231 arg = va_arg(ap,char *); | |
417
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
401
diff
changeset
|
232 if((spool)arg == s) |
25 | 233 break; |
234 else | |
235 spool_add(s, arg); | |
236 } | |
237 | |
238 va_end(ap); | |
239 } | |
240 | |
241 char *spool_print(spool s) | |
242 { | |
243 char *ret,*tmp; | |
244 struct spool_node *next; | |
245 | |
246 if(s == NULL || s->len == 0 || s->first == NULL) | |
247 return NULL; | |
248 | |
249 ret = pmalloc(s->p, s->len + 1); | |
250 *ret = '\0'; | |
251 | |
252 next = s->first; | |
253 tmp = ret; | |
254 while(next != NULL) | |
255 { | |
256 tmp = j_strcat(tmp,next->c); | |
257 next = next->next; | |
258 } | |
259 | |
260 return ret; | |
261 } | |
262 | |
263 /* convenience :) */ | |
264 char *spools(pool p, ...) | |
265 { | |
266 va_list ap; | |
267 spool s; | |
268 char *arg = NULL; | |
269 | |
270 if(p == NULL) | |
271 return NULL; | |
272 | |
273 s = spool_new(p); | |
274 | |
275 va_start(ap, p); | |
276 | |
277 /* loop till we hit our end flag, the first arg */ | |
278 while(1) | |
279 { | |
280 arg = va_arg(ap,char *); | |
417
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
401
diff
changeset
|
281 if((pool)arg == p) |
25 | 282 break; |
283 else | |
284 spool_add(s, arg); | |
285 } | |
286 | |
287 va_end(ap); | |
288 | |
289 return spool_print(s); | |
290 } | |
291 | |
292 | |
293 char *strunescape(pool p, char *buf) | |
294 { | |
295 int i,j=0; | |
296 char *temp; | |
297 | |
298 if (p == NULL || buf == NULL) return(NULL); | |
299 | |
300 if (strchr(buf,'&') == NULL) return(buf); | |
301 | |
302 temp = pmalloc(p,strlen(buf)+1); | |
303 | |
304 if (temp == NULL) return(NULL); | |
305 | |
306 for(i=0;i<strlen(buf);i++) | |
307 { | |
308 if (buf[i]=='&') | |
309 { | |
310 if (strncmp(&buf[i],"&",5)==0) | |
311 { | |
312 temp[j] = '&'; | |
313 i += 4; | |
314 } else if (strncmp(&buf[i],""",6)==0) { | |
315 temp[j] = '\"'; | |
316 i += 5; | |
317 } else if (strncmp(&buf[i],"'",6)==0) { | |
318 temp[j] = '\''; | |
319 i += 5; | |
320 } else if (strncmp(&buf[i],"<",4)==0) { | |
321 temp[j] = '<'; | |
322 i += 3; | |
323 } else if (strncmp(&buf[i],">",4)==0) { | |
324 temp[j] = '>'; | |
325 i += 3; | |
326 } | |
327 } else { | |
328 temp[j]=buf[i]; | |
329 } | |
330 j++; | |
331 } | |
332 temp[j]='\0'; | |
333 return(temp); | |
334 } | |
335 | |
336 | |
337 char *strescape(pool p, char *buf) | |
338 { | |
339 int i,j,oldlen,newlen; | |
340 char *temp; | |
341 | |
342 if (p == NULL || buf == NULL) return(NULL); | |
343 | |
344 oldlen = newlen = strlen(buf); | |
345 for(i=0;i<oldlen;i++) | |
346 { | |
347 switch(buf[i]) | |
348 { | |
349 case '&': | |
350 newlen+=5; | |
351 break; | |
352 case '\'': | |
353 newlen+=6; | |
354 break; | |
355 case '\"': | |
356 newlen+=6; | |
357 break; | |
358 case '<': | |
359 newlen+=4; | |
360 break; | |
361 case '>': | |
362 newlen+=4; | |
363 break; | |
364 } | |
365 } | |
366 | |
367 if(oldlen == newlen) return buf; | |
368 | |
369 temp = pmalloc(p,newlen+1); | |
370 | |
371 if (temp==NULL) return(NULL); | |
372 | |
373 for(i=j=0;i<oldlen;i++) | |
374 { | |
375 switch(buf[i]) | |
376 { | |
377 case '&': | |
378 memcpy(&temp[j],"&",5); | |
379 j += 5; | |
380 break; | |
381 case '\'': | |
382 memcpy(&temp[j],"'",6); | |
383 j += 6; | |
384 break; | |
385 case '\"': | |
386 memcpy(&temp[j],""",6); | |
387 j += 6; | |
388 break; | |
389 case '<': | |
390 memcpy(&temp[j],"<",4); | |
391 j += 4; | |
392 break; | |
393 case '>': | |
394 memcpy(&temp[j],">",4); | |
395 j += 4; | |
396 break; | |
397 default: | |
398 temp[j++] = buf[i]; | |
399 } | |
400 } | |
401 temp[j] = '\0'; | |
402 return temp; | |
403 } | |
404 | |
405 char *zonestr(char *file, int line) | |
406 { | |
407 static char buff[64]; | |
408 int i; | |
409 | |
410 i = snprintf(buff,63,"%s:%d",file,line); | |
411 buff[i] = '\0'; | |
412 | |
413 return buff; | |
414 } |