jabberd2  2.2.16
sm/feature.c
Go to the documentation of this file.
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 #include "sm.h"
00022 
00030 /*
00031  * these are simple wrappers around xhash for the moment. perhaps a little
00032  * redundant, but they will give a good abstraction, and make it easier to
00033  * add stuff in the future .. f-neg comes to mind.
00034  */
00035 
00037 void feature_register(sm_t sm, char *feature)
00038 {
00039     log_debug(ZONE, "registering feature %s", feature);
00040 
00041     xhash_put(sm->features, pstrdup(xhash_pool(sm->features), feature), (void *) ((long) xhash_get(sm->features, feature) + 1));
00042 }
00043 
00045 void feature_unregister(sm_t sm, char *feature)
00046 {
00047     int refcount = (int) (long) xhash_get(sm->features, feature);
00048 
00049     log_debug(ZONE, "unregistering feature %s", feature);
00050 
00051     if (refcount == 1) {
00052         xhash_zap(sm->features, feature);
00053     } else if (refcount > 1) {
00054         xhash_put(sm->features, feature, (void *) ((long) refcount - 1));
00055     }
00056 }