jabberd2  2.3.3
env.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 #include "sx.h"
22 
24  sx_env_t env;
25 
26  env = (sx_env_t) calloc(1, sizeof(struct _sx_env_st));
27 
28  return env;
29 }
30 
31 void sx_env_free(sx_env_t env) {
32  int i;
33 
34  assert((int) (env != NULL));
35 
36  /* !!! usage counts */
37 
38  for(i = 0; i < env->nplugins; i++) {
39  if(env->plugins[i]->unload != NULL)
40  (env->plugins[i]->unload)(env->plugins[i]);
41  free(env->plugins[i]);
42  }
43 
44  free(env->plugins);
45  free(env);
46 }
47 
49  sx_plugin_t p;
50  int ret;
51  va_list args;
52 
53  assert((int) (env != NULL));
54  assert((int) (init != NULL));
55 
56  va_start(args, init);
57 
58  p = (sx_plugin_t) calloc(1, sizeof(struct _sx_plugin_st));
59 
60  p->env = env;
61  p->index = env->nplugins;
62 
63  ret = (init)(env, p, args);
64  va_end(args);
65 
66  if(ret != 0) {
67  free(p);
68  return NULL;
69  }
70 
71  env->plugins = (sx_plugin_t *) realloc(env->plugins, sizeof(sx_plugin_t) * (env->nplugins + 1));
72  env->plugins[env->nplugins] = p;
73  env->nplugins++;
74 
75  _sx_debug(ZONE, "plugin initialised (index %d)", p->index);
76 
77  return p;
78 }
void(* unload)(sx_plugin_t p)
Definition: sx.h:375
an environment
Definition: sx.h:379
a plugin
Definition: sx.h:344
sx_env_t sx_env_new(void)
Definition: env.c:23
sx_plugin_t sx_env_plugin(sx_env_t env, sx_plugin_init_t init,...)
load a plugin into the environment
Definition: env.c:48
sx_plugin_t * plugins
Definition: sx.h:380
#define _sx_debug
Definition: sx.h:405
struct _sx_plugin_st * sx_plugin_t
Definition: sx.h:53
sx_env_t env
Definition: sx.h:345
int(* sx_plugin_init_t)(sx_env_t env, sx_plugin_t p, va_list args)
plugin init
Definition: sx.h:90
#define ZONE
Definition: mio_impl.h:76
struct _sx_env_st * sx_env_t
Definition: sx.h:52
int index
Definition: sx.h:349
void sx_env_free(sx_env_t env)
Definition: env.c:31
int nplugins
Definition: sx.h:381