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.
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.
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.
17 * Copyright (C) 1998-1999 The Jabber Team http://jabber.org/
22 char *j_strdup(const char *str
)
30 char *j_strcat(char *dest
, char *txt
)
32 if(!txt
) return(dest
);
41 int j_strcmp(const char *a
, const char *b
)
43 if(a
== NULL
|| b
== NULL
)
49 int j_strcasecmp(const char *a
, const char *b
)
51 if(a
== NULL
|| b
== NULL
)
54 return strcasecmp(a
, b
);
57 int j_strncmp(const char *a
, const char *b
, int i
)
59 if(a
== NULL
|| b
== NULL
)
62 return strncmp(a
, b
, i
);
65 int j_strncasecmp(const char *a
, const char *b
, int i
)
67 if(a
== NULL
|| b
== NULL
)
70 return strncasecmp(a
, b
, i
);
73 int j_strlen(const char *a
)
81 int j_atoi(const char *a
, int def
)
89 spool
spool_new(pool p
)
93 s
= pmalloc(p
, sizeof(struct spool_struct
));
101 void spool_add(spool s
, char *str
)
103 struct spool_node
*sn
;
113 sn
= pmalloc(s
->p
, sizeof(struct spool_node
));
114 sn
->c
= pstrdup(s
->p
, str
);
125 void spooler(spool s
, ...)
135 /* loop till we hit our end flag, the first arg */
138 arg
= va_arg(ap
,char *);
139 if((int)arg
== (int)s
)
148 char *spool_print(spool s
)
151 struct spool_node
*next
;
153 if(s
== NULL
|| s
->len
== 0 || s
->first
== NULL
)
156 ret
= pmalloc(s
->p
, s
->len
+ 1);
163 tmp
= j_strcat(tmp
,next
->c
);
171 char *spools(pool p
, ...)
184 /* loop till we hit our end flag, the first arg */
187 arg
= va_arg(ap
,char *);
188 if((int)arg
== (int)p
)
196 return spool_print(s
);
200 char *strunescape(pool p
, char *buf
)
205 if (p
== NULL
|| buf
== NULL
) return(NULL
);
207 if (strchr(buf
,'&') == NULL
) return(buf
);
209 temp
= pmalloc(p
,strlen(buf
)+1);
211 if (temp
== NULL
) return(NULL
);
213 for(i
=0;i
<strlen(buf
);i
++)
217 if (strncmp(&buf
[i
],"&",5)==0)
221 } else if (strncmp(&buf
[i
],""",6)==0) {
224 } else if (strncmp(&buf
[i
],"'",6)==0) {
227 } else if (strncmp(&buf
[i
],"<",4)==0) {
230 } else if (strncmp(&buf
[i
],">",4)==0) {
244 char *strescape(pool p
, char *buf
)
246 int i
,j
,oldlen
,newlen
;
249 if (p
== NULL
|| buf
== NULL
) return(NULL
);
251 oldlen
= newlen
= strlen(buf
);
252 for(i
=0;i
<oldlen
;i
++)
274 if(oldlen
== newlen
) return buf
;
276 temp
= pmalloc(p
,newlen
+1);
278 if (temp
==NULL
) return(NULL
);
280 for(i
=j
=0;i
<oldlen
;i
++)
285 memcpy(&temp
[j
],"&",5);
289 memcpy(&temp
[j
],"'",6);
293 memcpy(&temp
[j
],""",6);
297 memcpy(&temp
[j
],"<",4);
301 memcpy(&temp
[j
],">",4);
312 char *zonestr(char *file
, int line
)
314 static char buff
[64];
317 i
= snprintf(buff
,63,"%s:%d",file
,line
);
323 void str_b64decode(char* str
)
328 static int table
[256] = {
329 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, /* 00-0F */
330 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, /* 10-1F */
331 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,62,-1,-1,-1,63, /* 20-2F */
332 52,53,54,55,56,57,58,59,60,61,-1,-1,-1,-1,-1,-1, /* 30-3F */
333 -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14, /* 40-4F */
334 15,16,17,18,19,20,21,22,23,24,25,-1,-1,-1,-1,-1, /* 50-5F */
335 -1,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40, /* 60-6F */
336 41,42,43,44,45,46,47,48,49,50,51,-1,-1,-1,-1,-1, /* 70-7F */
337 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, /* 80-8F */
338 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, /* 90-9F */
339 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, /* A0-AF */
340 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, /* B0-BF */
341 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, /* C0-CF */
342 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, /* D0-DF */
343 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, /* E0-EF */
344 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 /* F0-FF */
348 for (cur
= str
; *cur
!= '\0'; ++cur
)
350 d
= table
[(int)*cur
];
359 c
= ((dlast
<< 2) | ((d
& 0x30) >> 4));
364 c
= (((dlast
& 0xf) << 4) | ((d
& 0x3c) >> 2));
369 c
= (((dlast
& 0x03 ) << 6) | d
);