71 _sx_debug(
ZONE,
"processing packets sent before stream, naughty them");
78 int tflag = 0, fflag = 0, vflag = 0, len, i, r;
89 r = strlen(name) < i || strncmp(name,
uri_XFRAMING "|open", i) != 0 || (name[i] !=
'\0' && name[i] !=
'|');
92 r = strlen(name) < i || strncmp(name,
uri_STREAMS "|stream", i) != 0 || (name[i] !=
'\0' && name[i] !=
'|');
106 while(attr[0] != NULL) {
107 if(!tflag && strcmp(attr[0],
"to") == 0) {
109 s->
req_to = strdup(attr[1]);
113 if(!fflag && strcmp(attr[0],
"from") == 0) {
118 if(!vflag && strcmp(attr[0],
"version") == 0) {
151 for(i = 0; i < 40; i++) {
152 r = (int) (36.0 * rand() / RAND_MAX);
153 id[i] = (r >= 0 && r <= 9) ? (r + 48) : (r + 87);
168 if(s->
ns != NULL) len += 9 + strlen(s->
ns);
179 strcpy(c,
"<?xml version='1.0'?><stream:stream xmlns:stream='" uri_STREAMS "'");
182 if(s->
ns != NULL) { c = strchr(c,
'\0'); sprintf(c,
" xmlns='%s'", s->
ns); }
183 if(s->
res_to != NULL) { c = strchr(c,
'\0'); sprintf(c,
" to='%s'", s->
res_to); }
184 if(s->
res_from != NULL) { c = strchr(c,
'\0'); sprintf(c,
" from='%s'", s->
res_from); }
187 c = strchr(c,
'\0'); sprintf(c,
" id='%s'",
id);
189 c = strchr(c,
'\0'); strcpy(c,
" />");
191 c = strchr(c,
'\0'); strcpy(c,
">");
193 assert(buf->
len == strlen(buf->
data) + 1);
245 XML_SetStartNamespaceDeclHandler(s->
expat, NULL);
251 assert((
int) (s != NULL));
nad_t nad_new(void)
create a new nad
static void _sx_server_element_start(void *arg, const char *name, const char **atts)
#define _sx_event(s, e, data)
void(* server)(sx_t s, sx_plugin_t p)
static void _sx_server_element_end(void *arg, const char *name)
#define stream_err_UNSUPPORTED_VERSION
int jqueue_size(jqueue_t q)
void(* features)(sx_t s, sx_plugin_t p, nad_t nad)
error info for event_ERROR
int nad_add_namespace(nad_t nad, const char *uri, const char *prefix)
bring a new namespace into scope
static void _sx_server_ns_start(void *arg, const char *prefix, const char *uri)
catch the application namespace so we can get the response right
void sx_server_init(sx_t s, unsigned int flags)
int nad_append_elem(nad_t nad, int ns, const char *name, int depth)
create a new elem on the list
void nad_free(nad_t nad)
free that nad
holds the state for a single stream
void _sx_element_end(void *arg, const char *name)
void jqueue_push(jqueue_t q, void *data, int priority)
void(* stream)(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...
void _sx_process_read(sx_t s, sx_buf_t buf)
handler for read data
#define SX_WEBSOCKET_WRAPPER
void _sx_namespace_start(void *arg, const char *prefix, const char *uri)
void _sx_cdata(void *arg, const char *str, int len)
void _sx_error(sx_t s, int err, const char *text)
send an error
void _sx_element_start(void *arg, const char *name, const char **atts)
primary expat callbacks
#define stream_err_BAD_FORMAT
#define _sx_gen_error(e, c, g, s)
helper macro to populate this struct
static void _sx_server_notify_header(sx_t s, void *arg)
void nad_print(nad_t nad, int elem, const char **xml, int *len)
create a string representation of the given element (and children), point references to it ...
void(* header)(sx_t s, sx_plugin_t p, sx_buf_t buf)
char * _sx_flags(sx_t s)
show sx flags as string - for logging