⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 error.c

📁 这是一个完全开放的
💻 C
字号:
/* * jabberd - Jabber Open Source Server * Copyright (c) 2002 Jeremie Miller, Thomas Muldowney, *                    Ryan Eatmon, Robert Norris * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA02111-1307USA */#include "sx.h"/** if you change these, reflect your changes in the defines in sx.h */static char *_stream_errors[] = {    "bad-format",    "bad-namespace-prefix",    "conflict",    "connection-timeout",    "host-gone",    "host-unknown",    "improper-addressing",    "internal-server-error",    "invalid-from",    "invalid-id",    "invalid-namespace",    "invalid-xml",    "not-authorized",    "policy-violation",    "remote-connection-failed",    "restricted-xml",    "resource-constraint",    "see-other-host",    "system-shutdown",    "undefined-condition",    "unsupported-encoding",    "unsupported-stanza-type",    "unsupported-version",    "xml-not-well-formed",    NULL};/** send an error */void _sx_error(sx_t s, int err, char *text) {    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(text != NULL) len += strlen(uri_STREAM_ERR) + strlen(text) + 22;    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(text == 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 "'/><text xmlns='" uri_STREAM_ERR "'>%s</text></stream:error>", _stream_errors[err], text);    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(sx_t s, int err, char *text) {    assert(s != NULL);    assert(err >= 0 && err < stream_err_LAST);    _sx_error(s, err, text);    _sx_event(s, event_WANT_WRITE, NULL);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -