25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-12-26 17:38:45 +01:00

* src/expat_erl.c: Removed R9B workaround

SVN Revision: 1286
This commit is contained in:
Alexey Shchepin 2008-04-11 05:19:27 +00:00
parent 367610dd38
commit bd884274c0
2 changed files with 9 additions and 99 deletions

View File

@ -1,3 +1,7 @@
2008-04-11 Alexey Shchepin <alexey@process-one.net>
* src/expat_erl.c: Removed R9B workaround
2008-04-10 Christophe Romain <christophe.romain@process-one.net> 2008-04-10 Christophe Romain <christophe.romain@process-one.net>
* src/mod_pubsub/mod_pubsub.erl: fix identity and database update * src/mod_pubsub/mod_pubsub.erl: fix identity and database update

View File

@ -6,100 +6,6 @@
#include <ei.h> #include <ei.h>
#include <expat.h> #include <expat.h>
#define EI_ENCODE_STRING_BUG
#ifdef EI_ENCODE_STRING_BUG
/*
* Workaround for EI encode_string bug
*/
#define put8(s,n) do { \
(s)[0] = (char)((n) & 0xff); \
(s) += 1; \
} while (0)
#define put16be(s,n) do { \
(s)[0] = ((n) >> 8) & 0xff; \
(s)[1] = (n) & 0xff; \
(s) += 2; \
} while (0)
#define put32be(s,n) do { \
(s)[0] = ((n) >> 24) & 0xff; \
(s)[1] = ((n) >> 16) & 0xff; \
(s)[2] = ((n) >> 8) & 0xff; \
(s)[3] = (n) & 0xff; \
(s) += 4; \
} while (0)
int ei_encode_string_len_fixed(char *buf, int *index, const char *p, int len)
{
char *s = buf + *index;
char *s0 = s;
int i;
if (len <= 0xffff) {
if (!buf) s += 3;
else {
put8(s,ERL_STRING_EXT);
put16be(s,len);
memmove(s,p,len); /* unterminated string */
}
s += len;
}
else {
if (!buf) s += 6 + (2*len);
else {
/* strings longer than 65535 are encoded as lists */
put8(s,ERL_LIST_EXT);
put32be(s,len);
for (i=0; i<len; i++) {
put8(s,ERL_SMALL_INTEGER_EXT);
put8(s,p[i]);
}
put8(s,ERL_NIL_EXT);
}
}
*index += s-s0;
return 0;
}
int ei_encode_string_fixed(char *buf, int *index, const char *p)
{
return ei_encode_string_len_fixed(buf, index, p, strlen(p));
}
int ei_x_encode_string_len_fixed(ei_x_buff* x, const char* s, int len)
{
int i = x->index;
ei_encode_string_len_fixed(NULL, &i, s, len);
if (!x_fix_buff(x, i))
return -1;
return ei_encode_string_len_fixed(x->buff, &x->index, s, len);
}
int ei_x_encode_string_fixed(ei_x_buff* x, const char* s)
{
return ei_x_encode_string_len_fixed(x, s, strlen(s));
}
#else
#define ei_encode_string_len_fixed(buf, index, p, len) \
ei_encode_string_len(buf, index, p, len)
#define ei_encode_string_fixed(buf, index, p) \
ei_encode_string(buf, index, p)
#define ei_x_encode_string_len_fixed(x, s, len) \
ei_x_encode_string_len(x, s, len)
#define ei_x_encode_string_fixed(x, s) \
ei_x_encode_string(x, s)
#endif
#define XML_START 0 #define XML_START 0
#define XML_END 1 #define XML_END 1
@ -126,7 +32,7 @@ void *erlXML_StartElementHandler(expat_data *d,
ei_x_encode_tuple_header(&event_buf, 2); ei_x_encode_tuple_header(&event_buf, 2);
ei_x_encode_long(&event_buf, XML_START); ei_x_encode_long(&event_buf, XML_START);
ei_x_encode_tuple_header(&event_buf, 2); ei_x_encode_tuple_header(&event_buf, 2);
ei_x_encode_string_fixed(&event_buf, name); ei_x_encode_string(&event_buf, name);
for (i = 0; atts[i]; i += 2) {} for (i = 0; atts[i]; i += 2) {}
@ -137,8 +43,8 @@ void *erlXML_StartElementHandler(expat_data *d,
for (i = 0; atts[i]; i += 2) for (i = 0; atts[i]; i += 2)
{ {
ei_x_encode_tuple_header(&event_buf, 2); ei_x_encode_tuple_header(&event_buf, 2);
ei_x_encode_string_fixed(&event_buf, atts[i]); ei_x_encode_string(&event_buf, atts[i]);
ei_x_encode_string_fixed(&event_buf, atts[i+1]); ei_x_encode_string(&event_buf, atts[i+1]);
} }
} }
@ -153,7 +59,7 @@ void *erlXML_EndElementHandler(expat_data *d,
ei_x_encode_list_header(&event_buf, 1); ei_x_encode_list_header(&event_buf, 1);
ei_x_encode_tuple_header(&event_buf, 2); ei_x_encode_tuple_header(&event_buf, 2);
ei_x_encode_long(&event_buf, XML_END); ei_x_encode_long(&event_buf, XML_END);
ei_x_encode_string_fixed(&event_buf, name); ei_x_encode_string(&event_buf, name);
return NULL; return NULL;
} }
@ -223,7 +129,7 @@ static int expat_erl_control(ErlDrvData drv_data,
ei_x_encode_long(&event_buf, XML_ERROR); ei_x_encode_long(&event_buf, XML_ERROR);
ei_x_encode_tuple_header(&event_buf, 2); ei_x_encode_tuple_header(&event_buf, 2);
ei_x_encode_long(&event_buf, errcode); ei_x_encode_long(&event_buf, errcode);
ei_x_encode_string_fixed(&event_buf, errstring); ei_x_encode_string(&event_buf, errstring);
} }
ei_x_encode_empty_list(&event_buf); ei_x_encode_empty_list(&event_buf);