... | ... |
@@ -110,7 +110,9 @@ int new_udomain(str* _n, int _s, udomain_t** _d) |
110 | 110 |
|
111 | 111 |
(*_d)->size = _s; |
112 | 112 |
init_lock((*_d)->lock); |
113 |
- |
|
113 |
+ (*_d)->users = 0; |
|
114 |
+ (*_d)->expired = 0; |
|
115 |
+ |
|
114 | 116 |
return 0; |
115 | 117 |
} |
116 | 118 |
|
... | ... |
@@ -326,6 +328,7 @@ int mem_insert_urecord(udomain_t* _d, str* _aor, struct urecord** _r) |
326 | 328 |
sl = hash_func(_d, _aor->s, _aor->len); |
327 | 329 |
slot_add(&_d->table[sl], *_r); |
328 | 330 |
udomain_add(_d, *_r); |
331 |
+ _d->users++; |
|
329 | 332 |
return 0; |
330 | 333 |
} |
331 | 334 |
|
... | ... |
@@ -338,6 +341,7 @@ void mem_delete_urecord(udomain_t* _d, struct urecord* _r) |
338 | 341 |
udomain_remove(_d, _r); |
339 | 342 |
slot_rem(_r->slot, _r); |
340 | 343 |
free_urecord(_r); |
344 |
+ _d->users--; |
|
341 | 345 |
} |
342 | 346 |
|
343 | 347 |
|
... | ... |
@@ -24,6 +24,8 @@ struct urecord; /* Usrloc record */ |
24 | 24 |
typedef struct udomain { |
25 | 25 |
str* name; /* Domain name */ |
26 | 26 |
int size; /* Hash table size */ |
27 |
+ int users; /* Number of registered users */ |
|
28 |
+ int expired; /* Number of expired contacts */ |
|
27 | 29 |
struct hslot* table; /* Hash table - array of collision slots */ |
28 | 30 |
struct { /* Linked list of all elements in the domain */ |
29 | 31 |
int n; /* Number of element in the linked list */ |
... | ... |
@@ -9,15 +9,27 @@ |
9 | 9 |
#include "ul_fifo.h" |
10 | 10 |
#include <strings.h> |
11 | 11 |
#include <stdio.h> |
12 |
+#include "dlist.h" |
|
13 |
+#include "udomain.h" |
|
12 | 14 |
|
13 | 15 |
|
14 | 16 |
static int print_ul_stats(FILE *reply_file) |
15 | 17 |
{ |
18 |
+ dlist_t* ptr; |
|
19 |
+ |
|
20 |
+ fprintf(reply_file, "Domain Registered Expired\n"); |
|
21 |
+ |
|
22 |
+ ptr = root; |
|
23 |
+ while(ptr) { |
|
24 |
+ |
|
25 |
+ fprintf(reply_file, "\'%.*s\' %d %d\n", |
|
26 |
+ ptr->d->name->len, ptr->d->name->s, |
|
27 |
+ ptr->d->users, |
|
28 |
+ ptr->d->expired |
|
29 |
+ ); |
|
30 |
+ ptr = ptr->next; |
|
31 |
+ } |
|
16 | 32 |
|
17 |
- /* PLACEHOLDER: fill in real things here */ |
|
18 |
- fprintf(reply_file, "registered (now): %d, " |
|
19 |
- "expired (since boot time): %d\n", |
|
20 |
- 0, 0 ); |
|
21 | 33 |
return 1; |
22 | 34 |
} |
23 | 35 |
|
... | ... |
@@ -41,6 +53,8 @@ int static ul_rm( FILE *pipe, char *response_file ) |
41 | 53 |
char user[MAX_USER]; |
42 | 54 |
int tlen, ulen; |
43 | 55 |
FILE *reply_file; |
56 |
+ dlist_t* ptr; |
|
57 |
+ str aor, t; |
|
44 | 58 |
|
45 | 59 |
if (!read_line(table, MAX_TABLE, pipe, &tlen) || tlen==0) { |
46 | 60 |
LOG(L_ERR, "ERROR: ul_rm: table name expected\n"); |
... | ... |
@@ -51,15 +65,46 @@ int static ul_rm( FILE *pipe, char *response_file ) |
51 | 65 |
return -1; |
52 | 66 |
} |
53 | 67 |
/* PLACEHOLDER: fill in real things here */ |
68 |
+ |
|
69 |
+ aor.s = user; |
|
70 |
+ aor.len = strlen(user); |
|
71 |
+ |
|
72 |
+ t.s = table; |
|
73 |
+ t.len = strlen(table); |
|
74 |
+ |
|
75 |
+ ptr = root; |
|
76 |
+ while(ptr) { |
|
77 |
+ if ((ptr->name.len == t.len) && |
|
78 |
+ !memcmp(ptr->name.s, t.s, t.len)) { |
|
79 |
+ break; |
|
80 |
+ } |
|
81 |
+ ptr = ptr->next; |
|
82 |
+ } |
|
83 |
+ |
|
84 |
+ |
|
54 | 85 |
LOG(L_INFO, "INFO: deleting user-loc (%s,%s)\n", |
55 |
- table, user ); |
|
86 |
+ table, user ); |
|
56 | 87 |
reply_file=open_reply_pipe(response_file); |
57 | 88 |
if (reply_file==0) { |
58 | 89 |
LOG(L_ERR, "ERROR: ul_rm: file not opened\n"); |
59 | 90 |
return -1; |
60 | 91 |
} |
61 |
- fprintf(reply_file, "User (%s,%s) deletion not implemented\n", |
|
62 |
- table, user); |
|
92 |
+ |
|
93 |
+ if (ptr) { |
|
94 |
+ lock_udomain(ptr->d); |
|
95 |
+ if (delete_urecord(ptr->d, &aor) < 0) { |
|
96 |
+ LOG(L_ERR, "ul_rm(): Error while deleting user %s\n", user); |
|
97 |
+ fprintf(reply_file, "Error while deleting user (%s, %s)\n", table, user); |
|
98 |
+ unlock_udomain(ptr->d); |
|
99 |
+ fclose(reply_file); |
|
100 |
+ return -1; |
|
101 |
+ } |
|
102 |
+ unlock_udomain(ptr->d); |
|
103 |
+ fprintf(reply_file, "User (%s, %s) deleted\n", table, user); |
|
104 |
+ } else { |
|
105 |
+ fprintf(reply_file, "Table (%s) not found\n", table); |
|
106 |
+ } |
|
107 |
+ |
|
63 | 108 |
fclose(reply_file); |
64 | 109 |
return 1; |
65 | 110 |
} |
... | ... |
@@ -13,6 +13,7 @@ |
13 | 13 |
#include "udomain.h" /* {insert,delete,get,release}_urecord */ |
14 | 14 |
#include "urecord.h" /* {insert,delete,get}_ucontact */ |
15 | 15 |
#include "ucontact.h" /* update_ucontact */ |
16 |
+#include "ul_fifo.h" |
|
16 | 17 |
|
17 | 18 |
|
18 | 19 |
static int mod_init(void); /* Module initialization function */ |
... | ... |
@@ -137,7 +138,8 @@ static int mod_init(void) |
137 | 138 |
printf("usrloc module - initializing\n"); |
138 | 139 |
|
139 | 140 |
register_timer(timer, NULL, timer_interval); |
140 |
- |
|
141 |
+ init_ul_fifo(); |
|
142 |
+ |
|
141 | 143 |
if (db_mode != NO_DB) { |
142 | 144 |
if (bind_dbmod() < 0) { |
143 | 145 |
LOG(L_ERR, "mod_init(): Can't bind database module\n"); |
... | ... |
@@ -169,6 +169,7 @@ static inline int nodb_timer(urecord_t* _r) |
169 | 169 |
ptr = ptr->next; |
170 | 170 |
|
171 | 171 |
mem_delete_ucontact(_r, t); |
172 |
+ _r->slot->d->expired++; |
|
172 | 173 |
} else { |
173 | 174 |
ptr = ptr->next; |
174 | 175 |
} |
... | ... |
@@ -202,6 +203,7 @@ static inline int wt_timer(urecord_t* _r) |
202 | 203 |
LOG(L_ERR, "wt_timer(): Error while deleting contact from database\n"); |
203 | 204 |
} |
204 | 205 |
mem_delete_ucontact(_r, t); |
206 |
+ _r->slot->d->expired++; |
|
205 | 207 |
} else { |
206 | 208 |
ptr = ptr->next; |
207 | 209 |
} |
... | ... |
@@ -234,6 +236,7 @@ static inline int wb_timer(urecord_t* _r) |
234 | 236 |
} |
235 | 237 |
} |
236 | 238 |
mem_delete_ucontact(_r, t); |
239 |
+ _r->slot->d->expired++; |
|
237 | 240 |
} else { |
238 | 241 |
/* Determine the operation we have to do */ |
239 | 242 |
op = st_flush_ucontact(ptr); |