1
/* $Id: expat_erl.c 2000 2009-03-24 23:09:46Z badlop $ */
2
* ejabberd, Copyright (C) 2002-2009 ProcessOne
4
* This program is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU General Public License as
6
* published by the Free Software Foundation; either version 2 of the
7
* License, or (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
* General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
9
#define EI_ENCODE_STRING_BUG
11
#ifdef EI_ENCODE_STRING_BUG
14
* Workaround for EI encode_string bug
17
int x_fix_buff(ei_x_buff* x, int szneeded);
19
#define put8(s,n) do { \
20
(s)[0] = (char)((n) & 0xff); \
24
#define put16be(s,n) do { \
25
(s)[0] = ((n) >> 8) & 0xff; \
26
(s)[1] = (n) & 0xff; \
30
#define put32be(s,n) do { \
31
(s)[0] = ((n) >> 24) & 0xff; \
32
(s)[1] = ((n) >> 16) & 0xff; \
33
(s)[2] = ((n) >> 8) & 0xff; \
34
(s)[3] = (n) & 0xff; \
38
int ei_encode_string_len_fixed(char *buf, int *index, const char *p, int len)
40
char *s = buf + *index;
47
put8(s,ERL_STRING_EXT);
49
memmove(s,p,len); /* unterminated string */
54
if (!buf) s += 6 + (2*len);
56
/* strings longer than 65535 are encoded as lists */
60
for (i=0; i<len; i++) {
61
put8(s,ERL_SMALL_INTEGER_EXT);
74
int ei_encode_string_fixed(char *buf, int *index, const char *p)
76
return ei_encode_string_len_fixed(buf, index, p, strlen(p));
79
int ei_x_encode_string_len_fixed(ei_x_buff* x, const char* s, int len)
82
ei_encode_string_len_fixed(NULL, &i, s, len);
83
if (!x_fix_buff(x, i))
85
return ei_encode_string_len_fixed(x->buff, &x->index, s, len);
88
int ei_x_encode_string_fixed(ei_x_buff* x, const char* s)
90
return ei_x_encode_string_len_fixed(x, s, strlen(s));
95
#define ei_encode_string_len_fixed(buf, index, p, len) \
96
ei_encode_string_len(buf, index, p, len)
97
#define ei_encode_string_fixed(buf, index, p) \
98
ei_encode_string(buf, index, p)
99
#define ei_x_encode_string_len_fixed(x, s, len) \
100
ei_x_encode_string_len(x, s, len)
101
#define ei_x_encode_string_fixed(x, s) \
102
ei_x_encode_string(x, s)
106
29
#define XML_START 0
128
51
ei_x_encode_tuple_header(&event_buf, 2);
129
52
ei_x_encode_long(&event_buf, XML_START);
130
53
ei_x_encode_tuple_header(&event_buf, 2);
131
ei_x_encode_string_fixed(&event_buf, name);
54
ei_x_encode_string(&event_buf, name);
133
56
for (i = 0; atts[i]; i += 2) {}
139
62
for (i = 0; atts[i]; i += 2)
141
64
ei_x_encode_tuple_header(&event_buf, 2);
142
ei_x_encode_string_fixed(&event_buf, atts[i]);
143
ei_x_encode_string_fixed(&event_buf, atts[i+1]);
65
ei_x_encode_string(&event_buf, atts[i]);
66
ei_x_encode_string(&event_buf, atts[i+1]);
155
78
ei_x_encode_list_header(&event_buf, 1);
156
79
ei_x_encode_tuple_header(&event_buf, 2);
157
80
ei_x_encode_long(&event_buf, XML_END);
158
ei_x_encode_string_fixed(&event_buf, name);
81
ei_x_encode_string(&event_buf, name);
225
148
ei_x_encode_long(&event_buf, XML_ERROR);
226
149
ei_x_encode_tuple_header(&event_buf, 2);
227
150
ei_x_encode_long(&event_buf, errcode);
228
ei_x_encode_string_fixed(&event_buf, errstring);
151
ei_x_encode_string(&event_buf, errstring);
231
154
ei_x_encode_empty_list(&event_buf);