jabberd2  2.3.3
chain.c
Go to the documentation of this file.
1 /*
2  * jabberd - Jabber Open Source Server
3  * Copyright (c) 2002 Jeremie Miller, Thomas Muldowney,
4  * Ryan Eatmon, Robert Norris
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA02111-1307USA
19  */
20 
21 /* manage and run the io and nad chains */
22 
23 #include "sx.h"
24 
26  _sx_chain_t cn, tail;
27 
28  _sx_debug(ZONE, "adding io plugin");
29 
30  cn = (_sx_chain_t) malloc(sizeof(struct _sx_chain_st));
31  cn->p = p;
32 
33  if(s->wio == NULL) {
34  s->wio = cn;
35  cn->wnext = NULL;
36  } else {
37  cn->wnext = s->wio;
38  s->wio = cn;
39  }
40 
41  if(s->rio == NULL)
42  s->rio = cn;
43  else {
44  for(tail = s->rio; tail->rnext != NULL; tail = tail->rnext);
45  tail->rnext = cn;
46  }
47  cn->rnext = NULL;
48 }
49 
51  _sx_chain_t cn, tail;
52 
53  _sx_debug(ZONE, "adding nad plugin");
54 
55  cn = (_sx_chain_t) malloc(sizeof(struct _sx_chain_st));
56  cn->p = p;
57 
58  if(s->wnad == NULL) {
59  s->wnad = cn;
60  cn->wnext = NULL;
61  } else {
62  cn->wnext = s->wnad;
63  s->wnad = cn;
64  }
65 
66  if(s->rnad == NULL)
67  s->rnad = cn;
68  else {
69  for(tail = s->rnad; tail->rnext != NULL; tail = tail->rnext);
70  tail->rnext = cn;
71  }
72  cn->rnext = NULL;
73 }
74 
76  _sx_chain_t scan;
77  int ret = 1;
78 
79  _sx_debug(ZONE, "calling io write chain");
80 
81  for(scan = s->wio; scan != NULL; scan = scan->wnext)
82  if(scan->p->wio != NULL)
83  if((ret = (scan->p->wio)(s, scan->p, buf)) <= 0)
84  return ret;
85 
86  return ret;
87 }
88 
90  _sx_chain_t scan;
91  int ret = 1;
92 
93  _sx_debug(ZONE, "calling io read chain");
94 
95  for(scan = s->rio; scan != NULL; scan = scan->rnext)
96  if(scan->p->rio != NULL)
97  if((ret = (scan->p->rio)(s, scan->p, buf)) <= 0)
98  return ret;
99 
100  return ret;
101 }
102 
103 int _sx_chain_nad_write(sx_t s, nad_t nad, int elem) {
104  _sx_chain_t scan;
105 
106  _sx_debug(ZONE, "calling nad write chain");
107 
108  for(scan = s->wnad; scan != NULL; scan = scan->wnext)
109  if(scan->p->wnad != NULL)
110  if((scan->p->wnad)(s, scan->p, nad, elem) == 0)
111  return 0;
112 
113  return 1;
114 }
115 
117  _sx_chain_t scan;
118 
119  _sx_debug(ZONE, "calling nad read chain");
120 
121  for(scan = s->rnad; scan != NULL; scan = scan->rnext)
122  if(scan->p->rnad != NULL)
123  if((scan->p->rnad)(s, scan->p, nad) == 0)
124  return 0;
125 
126  return 1;
127 }
int _sx_chain_nad_write(sx_t s, nad_t nad, int elem)
Definition: chain.c:103
int _sx_chain_io_write(sx_t s, sx_buf_t buf)
Definition: chain.c:75
Definition: nad.h:93
Definition: sx.h:113
sx_plugin_t p
Definition: sx.h:244
_sx_chain_t wio
Definition: sx.h:293
void _sx_chain_nad_plugin(sx_t s, sx_plugin_t p)
Definition: chain.c:50
int(* rnad)(sx_t s, sx_plugin_t p, nad_t nad)
Definition: sx.h:365
a plugin
Definition: sx.h:344
_sx_chain_t wnext
Definition: sx.h:246
void _sx_chain_io_plugin(sx_t s, sx_plugin_t p)
Definition: chain.c:25
_sx_chain_t rio
Definition: sx.h:293
int(* wnad)(sx_t s, sx_plugin_t p, nad_t nad, int elem)
Definition: sx.h:364
_sx_chain_t rnad
Definition: sx.h:296
holds the state for a single stream
Definition: sx.h:251
_sx_chain_t rnext
Definition: sx.h:247
_sx_chain_t wnad
Definition: sx.h:296
#define _sx_debug
Definition: sx.h:405
int _sx_chain_nad_read(sx_t s, nad_t nad)
Definition: chain.c:116
int _sx_chain_io_read(sx_t s, sx_buf_t buf)
Definition: chain.c:89
int(* wio)(sx_t s, sx_plugin_t p, sx_buf_t buf)
Definition: sx.h:360
#define ZONE
Definition: mio_impl.h:76
int(* rio)(sx_t s, sx_plugin_t p, sx_buf_t buf)
Definition: sx.h:361
struct _sx_chain_st * _sx_chain_t
read/write plugin chain
Definition: sx.h:242