27 assert((
int) (cb != NULL));
36 s->
expat = XML_ParserCreateNS(NULL,
'|');
37 XML_SetReturnNSTriplet(s->
expat, 1);
38 XML_SetUserData(s->
expat, (
void *) s);
44 #ifdef HAVE_XML_STOPPARSER
45 XML_SetEntityDeclHandler(s->
expat, (
void *) _sx_entity_declaration);
47 XML_SetDefaultHandler(s->
expat, NULL);
50 #ifdef HAVE_XML_SETHASHSALT
51 XML_SetHashSalt(s->
expat, rand());
84 if(s->
ns != NULL) free((
void*)s->
ns);
94 if(s->
id != NULL) free((
void*)s->
id);
107 XML_ParserFree(s->
expat);
121 while(scan != NULL) {
128 while(scan != NULL) {
141 void sx_auth(
sx_t s,
const char *auth_method,
const char *auth_id) {
142 assert((
int) (s != NULL));
144 _sx_debug(
ZONE,
"authenticating stream (method=%s; id=%s)", auth_method, auth_id);
146 if(auth_method != NULL) s->
auth_method = strdup(auth_method);
147 if(auth_id != NULL) s->
auth_id = strdup(auth_id);
188 memcpy(
new, s,
sizeof(
struct _sx_st));
192 memcpy(s,
new,
sizeof(
struct _sx_st));
196 XML_SetUserData(s->
expat, (
void *) s);
229 buf->
data = buf->
heap = (
char *) malloc(
sizeof(
char) * len);
231 memcpy(buf->
data, data, len);
233 memset(buf->
data,
'$', len);
245 if(buf->
heap != NULL)
253 if(buf->
heap != NULL) {
266 assert( before >= 0 );
267 assert( after >= 0 );
270 if (buf->
data == NULL || buf->
len == 0) {
271 if (buf->
heap != NULL)
272 buf->
heap = realloc(buf->
heap, before+after);
274 buf->
heap = malloc(before+after);
279 if (buf->
heap != NULL) {
280 int old_leader = buf->
data - buf->
heap;
282 if (old_leader >= before && old_leader <= (before * 4)) {
283 buf->
heap = realloc(buf->
heap, before + buf->
len + after);
290 new_heap = malloc(before + buf->
len + after);
291 memcpy(new_heap + before, buf->
data, buf->
len);
292 if (buf->
heap != NULL)
294 buf->
heap = new_heap;
295 buf->
data = new_heap + before;
301 if (newheap == NULL) {
305 memcpy(buf->
data, newdata, newlength);
306 buf->
len = newlength;
312 buf->
len = newlength;
317 void __sx_debug(
const char *file,
int line,
const char *msgfmt, ...) {
323 snprintf(message,
MAX_DEBUG,
"sx (%s:%d) ", file, line);
326 for (pos = message; *pos !=
'\0'; pos++);
328 va_start(ap, msgfmt);
329 vsnprintf(pos,
MAX_DEBUG - sz, msgfmt, ap);
331 fprintf(stderr,
"%s", message);
332 fprintf(stderr,
"\n");
339 _sx_debug(file, line,
"tag %d event %d data 0x%x", s->
tag, e, data);
342 ret = (s->
cb)(s, e, data, s->
cb_arg);
350 static char flags[256];
352 snprintf(flags,
sizeof(flags),
"%s%s%s",
353 s->
ssf ?
",TLS" :
"",
void(* free)(sx_t s, sx_plugin_t p)
#define _sx_event(s, e, data)
sx_t sx_new(sx_env_t env, int tag, sx_callback_t cb, void *arg)
int(* sx_callback_t)(sx_t s, sx_event_t e, void *data, void *arg)
event callback
void nad_free(nad_t nad)
free that nad
void jqueue_free(jqueue_t q)
void _sx_buffer_alloc_margin(sx_buf_t buf, int before, int after)
utility: ensure a certain amount of allocated space adjacent to buf->data
holds the state for a single stream
void _sx_buffer_free(sx_buf_t buf)
utility: kill a buffer
void(* new)(sx_t s, sx_plugin_t p)
sx_buf_t _sx_buffer_new(const char *data, int len, _sx_notify_t notify, void *notify_arg)
utility: make a new buffer if len>0 but data is NULL, the buffer will contain that many bytes of garb...
#define SX_WEBSOCKET_WRAPPER
struct _sx_buf_st * sx_buf_t
utility: buffer
void _sx_reset(sx_t s)
utility; reset stream state
int __sx_event(const char *file, int line, sx_t s, sx_event_t e, void *data)
helper and internal macro for firing the callback
void(* _sx_notify_t)(sx_t s, void *arg)
prototype for the write notify function
void * jqueue_pull(jqueue_t q)
jqueue_t jqueue_new(void)
void _sx_buffer_clear(sx_buf_t buf)
utility: clear out a buffer, but don't deallocate it
sx_event_t
things that can happen
void _sx_buffer_set(sx_buf_t buf, char *newdata, int newlength, char *newheap)
utility: reset a sx_buf_t's contents.
void __sx_debug(const char *file, int line, const char *msgfmt,...)
debug macro helpers
void sx_auth(sx_t s, const char *auth_method, const char *auth_id)
force advance into auth state
#define SX_COMPRESS_WRAPPER
char * _sx_flags(sx_t s)
show sx flags as string - for logging