jabberd2
2.2.16
|
00001 /* 00002 * jabberd - Jabber Open Source Server 00003 * Copyright (c) 2002 Jeremie Miller, Thomas Muldowney, 00004 * Ryan Eatmon, Robert Norris 00005 * 00006 * This program is free software; you can redistribute it and/or modify 00007 * it under the terms of the GNU General Public License as published by 00008 * the Free Software Foundation; either version 2 of the License, or 00009 * (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this program; if not, write to the Free Software 00018 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA02111-1307USA 00019 */ 00020 00021 /* manage and run the io and nad chains */ 00022 00023 #include "sx.h" 00024 00025 void _sx_chain_io_plugin(sx_t s, sx_plugin_t p) { 00026 _sx_chain_t cn, tail; 00027 00028 _sx_debug(ZONE, "adding io plugin"); 00029 00030 cn = (_sx_chain_t) malloc(sizeof(struct _sx_chain_st)); 00031 cn->p = p; 00032 00033 if(s->wio == NULL) { 00034 s->wio = cn; 00035 cn->wnext = NULL; 00036 } else { 00037 cn->wnext = s->wio; 00038 s->wio = cn; 00039 } 00040 00041 if(s->rio == NULL) 00042 s->rio = cn; 00043 else { 00044 for(tail = s->rio; tail->rnext != NULL; tail = tail->rnext); 00045 tail->rnext = cn; 00046 } 00047 cn->rnext = NULL; 00048 } 00049 00050 void _sx_chain_nad_plugin(sx_t s, sx_plugin_t p) { 00051 _sx_chain_t cn, tail; 00052 00053 _sx_debug(ZONE, "adding nad plugin"); 00054 00055 cn = (_sx_chain_t) malloc(sizeof(struct _sx_chain_st)); 00056 cn->p = p; 00057 00058 if(s->wnad == NULL) { 00059 s->wnad = cn; 00060 cn->wnext = NULL; 00061 } else { 00062 cn->wnext = s->wnad; 00063 s->wnad = cn; 00064 } 00065 00066 if(s->rnad == NULL) 00067 s->rnad = cn; 00068 else { 00069 for(tail = s->rnad; tail->rnext != NULL; tail = tail->rnext); 00070 tail->rnext = cn; 00071 } 00072 cn->rnext = NULL; 00073 } 00074 00075 int _sx_chain_io_write(sx_t s, sx_buf_t buf) { 00076 _sx_chain_t scan; 00077 int ret = 1; 00078 00079 _sx_debug(ZONE, "calling io write chain"); 00080 00081 for(scan = s->wio; scan != NULL; scan = scan->wnext) 00082 if(scan->p->wio != NULL) 00083 if((ret = (scan->p->wio)(s, scan->p, buf)) <= 0) 00084 return ret; 00085 00086 return ret; 00087 } 00088 00089 int _sx_chain_io_read(sx_t s, sx_buf_t buf) { 00090 _sx_chain_t scan; 00091 int ret = 1; 00092 00093 _sx_debug(ZONE, "calling io read chain"); 00094 00095 for(scan = s->rio; scan != NULL; scan = scan->rnext) 00096 if(scan->p->rio != NULL) 00097 if((ret = (scan->p->rio)(s, scan->p, buf)) <= 0) 00098 return ret; 00099 00100 return ret; 00101 } 00102 00103 int _sx_chain_nad_write(sx_t s, nad_t nad, int elem) { 00104 _sx_chain_t scan; 00105 00106 _sx_debug(ZONE, "calling nad write chain"); 00107 00108 for(scan = s->wnad; scan != NULL; scan = scan->wnext) 00109 if(scan->p->wnad != NULL) 00110 if((scan->p->wnad)(s, scan->p, nad, elem) == 0) 00111 return 0; 00112 00113 return 1; 00114 } 00115 00116 int _sx_chain_nad_read(sx_t s, nad_t nad) { 00117 _sx_chain_t scan; 00118 00119 _sx_debug(ZONE, "calling nad read chain"); 00120 00121 for(scan = s->rnad; scan != NULL; scan = scan->rnext) 00122 if(scan->p->rnad != NULL) 00123 if((scan->p->rnad)(s, scan->p, nad) == 0) 00124 return 0; 00125 00126 return 1; 00127 }