--- /tmp/jabberd-2.2.13/sx/error.c 2011-02-23 08:24:34.000000000 -0800 +++ ./jabberd2/sx/error.c 2011-02-24 16:25:21.000000000 -0800 @@ -94,3 +94,48 @@ void sx_error(sx_t s, int err, const cha _sx_event(s, event_WANT_WRITE, NULL); } +//** send an extended error with custom contents other than text */ +// Ideally should be merged with sx_error. sx_error should permit additional content beneath the <stream:error> element, other than a <text> node. +void _sx_error_extended(sx_t s, int err, const char *content) { + int len = 0; + sx_buf_t buf; + + /* build the string */ + if(s->state < state_STREAM) len = strlen(uri_STREAMS) + 61; + len += strlen(uri_STREAMS) + strlen(uri_STREAM_ERR) + strlen(_stream_errors[err]) + 58; + if(content != NULL) len += strlen(content) + strlen(_stream_errors[err]) + 2; + + buf = _sx_buffer_new(NULL, len, NULL, NULL); + len = 0; + + if(s->state < state_STREAM) + len = sprintf(buf->data, "<stream:stream xmlns:stream='" uri_STREAMS "' version='1.0'>"); + + if(content == NULL) + len += sprintf(&(buf->data[len]), "<stream:error xmlns:stream='" uri_STREAMS "'><%s xmlns='" uri_STREAM_ERR "'/></stream:error>", _stream_errors[err]); + else + len += sprintf(&(buf->data[len]), "<stream:error xmlns:stream='" uri_STREAMS "'><%s xmlns='" uri_STREAM_ERR "'>%s</%s></stream:error>", _stream_errors[err], content, _stream_errors[err]); + + if(s->state < state_STREAM) + len += sprintf(&(buf->data[len]), "</stream:stream>"); + + buf->len--; + assert(len == buf->len); + + _sx_debug(ZONE, "prepared error: %.*s", buf->len, buf->data); + + /* go */ + jqueue_push(s->wbufq, buf, 0); + + /* stuff to write */ + s->want_write = 1; +} + +void sx_error_extended(sx_t s, int err, const char *content) { + assert(s != NULL); + assert(err >= 0 && err < stream_err_LAST); + + _sx_error_extended(s, err, content); + + _sx_event(s, event_WANT_WRITE, NULL); +} \ No newline at end of file