jabberd2  2.3.2
mod_active.c
Go to the documentation of this file.
1 /*
2  * jabberd - Jabber Open Source Server
3  * Copyright (c) 2002-2003 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 
28 #include "sm.h"
29 
30 static int _active_user_load(mod_instance_t mi, user_t user) {
31  os_t os;
32  os_object_t o;
33 
34  /* get their active status */
35  if(storage_get(user->sm->st, "active", jid_user(user->jid), NULL, &os) == st_SUCCESS && os_iter_first(os)) {
36  o = os_iter_object(os);
37  os_object_get_time(os, o, "time", &user->active);
38  os_free(os);
39  } else
40  /* can't load them if they're inactive */
41  return 1;
42 
43  return 0;
44 }
45 
47  time_t t;
48  os_t os;
49  os_object_t o;
50 
51  log_debug(ZONE, "activating user %s", jid_user(jid));
52 
53  t = time(NULL);
54 
55  os = os_new();
56  o = os_object_new(os);
57  os_object_put_time(o, "time", &t);
58  storage_put(mi->sm->st, "active", jid_user(jid), os);
59  os_free(os);
60 
61  return 0;
62 }
63 
65  log_debug(ZONE, "deactivating user %s", jid_user(jid));
66 
67  storage_delete(mi->sm->st, "active", jid_user(jid), NULL);
68 }
69 
70 DLLEXPORT int module_init(mod_instance_t mi, const char *arg) {
71  module_t mod = mi->mod;
72 
73  if(mod->init) return 0;
74 
78 
79  return 0;
80 }
data structures and prototypes for the session manager
const char * jid_user(jid_t jid)
expand and return the user
Definition: jid.c:339
single instance of a module in a chain
Definition: sm.h:445
int init
number of times the module intialiser has been called
Definition: sm.h:415
static void _active_user_delete(mod_instance_t mi, jid_t jid)
Definition: mod_active.c:64
sm_t sm
sm context
Definition: sm.h:236
int(* user_load)(mod_instance_t mi, user_t user)
user-load handler
Definition: sm.h:433
#define DLLEXPORT
Definition: c2s.h:47
static int _active_user_create(mod_instance_t mi, jid_t jid)
Definition: mod_active.c:46
module_t mod
module that this is an instance of
Definition: sm.h:448
int(* user_create)(mod_instance_t mi, jid_t jid)
user-create handler
Definition: sm.h:436
storage_t st
storage subsystem
Definition: sm.h:210
Definition: jid.h:42
#define log_debug(...)
Definition: log.h:65
DLLEXPORT int module_init(mod_instance_t mi, const char *arg)
Definition: mod_active.c:70
void(* user_delete)(mod_instance_t mi, jid_t jid)
user-delete handler
Definition: sm.h:437
jid_t jid
user jid (user@host)
Definition: sm.h:238
#define ZONE
Definition: mio_impl.h:76
data for a single module
Definition: sm.h:402
sm_t sm
sm context
Definition: sm.h:446
static int _active_user_load(mod_instance_t mi, user_t user)
Definition: mod_active.c:30
time_t active
time that user first logged in (ever)
Definition: sm.h:246
data for a single user
Definition: sm.h:233