28 assert((
int) (cb != NULL));
37 s->
expat = XML_ParserCreateNS(NULL,
'|');
38 XML_SetReturnNSTriplet(s->
expat, 1);
39 XML_SetUserData(s->
expat, (
void *) s);
45 #ifdef HAVE_XML_STOPPARSER
46 XML_SetEntityDeclHandler(s->
expat, (
void *) _sx_entity_declaration);
48 XML_SetDefaultHandler(s->
expat, NULL);
51 #ifdef HAVE_XML_SETHASHSALT
52 XML_SetHashSalt(s->
expat, clock());
85 if(s->
ns != NULL) free(s->
ns);
95 if(s->
id != NULL) free(s->
id);
108 XML_ParserFree(s->
expat);
122 while(scan != NULL) {
129 while(scan != NULL) {
142 void sx_auth(
sx_t s,
const char *auth_method,
const char *auth_id) {
143 assert((
int) (s != NULL));
145 _sx_debug(
ZONE,
"authenticating stream (method=%s; id=%s)", auth_method, auth_id);
147 if(auth_method != NULL) s->
auth_method = strdup(auth_method);
148 if(auth_id != NULL) s->
auth_id = strdup(auth_id);
190 memcpy(
new, s,
sizeof(
struct _sx_st));
194 memcpy(s,
new,
sizeof(
struct _sx_st));
198 XML_SetUserData(s->
expat, (
void *) s);
232 buf->
data = buf->
heap = (
char *) malloc(
sizeof(
char) * len);
234 memcpy(buf->
data, data, len);
236 memset(buf->
data,
'$', len);
248 if(buf->
heap != NULL)
256 if(buf->
heap != NULL) {
269 assert( before >= 0 );
270 assert( after >= 0 );
273 if (buf->
data == NULL || buf->
len == 0) {
274 if (buf->
heap != NULL)
275 buf->
heap = realloc(buf->
heap, before+after);
277 buf->
heap = malloc(before+after);
282 if (buf->
heap != NULL) {
283 int old_leader = buf->
data - buf->
heap;
285 if (old_leader >= before && old_leader <= (before * 4)) {
286 buf->
heap = realloc(buf->
heap, before + buf->
len + after);
293 new_heap = malloc(before + buf->
len + after);
294 memcpy(new_heap + before, buf->
data, buf->
len);
295 if (buf->
heap != NULL)
297 buf->
heap = new_heap;
298 buf->
data = new_heap + before;
304 if (newheap == NULL) {
308 memcpy(buf->
data, newdata, newlength);
309 buf->
len = newlength;
315 buf->
len = newlength;
320 void __sx_debug(
const char *file,
int line,
const char *msgfmt, ...) {
326 snprintf(message,
MAX_DEBUG,
"sx (%s:%d) ", file, line);
329 for (pos = message; *pos !=
'\0'; pos++);
331 va_start(ap, msgfmt);
332 vsnprintf(pos,
MAX_DEBUG - sz, msgfmt, ap);
334 fprintf(stderr,
"%s", message);
335 fprintf(stderr,
"\n");
342 _sx_debug(file, line,
"tag %d event %d data 0x%x", s->
tag, e, data);
345 ret = (s->
cb)(s, e, data, s->
cb_arg);