jabberd2  2.2.16
sm/mod_active.c
Go to the documentation of this file.
00001 /*
00002  * jabberd - Jabber Open Source Server
00003  * Copyright (c) 2002-2003 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 
00028 #include "sm.h"
00029 
00030 static int _active_user_load(mod_instance_t mi, user_t user) {
00031     os_t os;
00032     os_object_t o;
00033 
00034     /* get their active status */
00035     if(storage_get(user->sm->st, "active", jid_user(user->jid), NULL, &os) == st_SUCCESS && os_iter_first(os)) {
00036         o = os_iter_object(os);
00037         os_object_get_time(os, o, "time", &user->active);
00038         os_free(os);
00039     } else
00040         /* can't load them if they're inactive */
00041         return 1;
00042 
00043     return 0;
00044 }
00045 
00046 static int _active_user_create(mod_instance_t mi, jid_t jid) {
00047     time_t t;
00048     os_t os;
00049     os_object_t o;
00050 
00051     log_debug(ZONE, "activating user %s", jid_user(jid));
00052 
00053     t = time(NULL);
00054 
00055     os = os_new();
00056     o = os_object_new(os);
00057     os_object_put_time(o, "time", &t);
00058     storage_put(mi->sm->st, "active", jid_user(jid), os);
00059     os_free(os);
00060 
00061     return 0;
00062 }
00063 
00064 static void _active_user_delete(mod_instance_t mi, jid_t jid) {
00065     log_debug(ZONE, "deactivating user %s", jid_user(jid));
00066 
00067     storage_delete(mi->sm->st, "active", jid_user(jid), NULL);
00068 }
00069 
00070 DLLEXPORT int module_init(mod_instance_t mi, char *arg) {
00071     module_t mod = mi->mod;
00072 
00073     if(mod->init) return 0;
00074 
00075     mod->user_load = _active_user_load;
00076     mod->user_create = _active_user_create;
00077     mod->user_delete = _active_user_delete;
00078 
00079     return 0;
00080 }