1 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,70 @@ |
1 |
+#include "del_list.h" |
|
2 |
+#include "../../mem/mem.h" |
|
3 |
+#include "../../dprint.h" |
|
4 |
+#include <string.h> |
|
5 |
+#include "../../db/db.h" |
|
6 |
+#include "ul_mod.h" |
|
7 |
+ |
|
8 |
+ |
|
9 |
+static struct del_itm* del_root = 0; |
|
10 |
+ |
|
11 |
+ |
|
12 |
+int put_on_del_list(struct ucontact* _c) |
|
13 |
+{ |
|
14 |
+ struct del_itm* p; |
|
15 |
+ |
|
16 |
+ p = (struct del_itm*)pkg_malloc(sizeof(struct del_itm) + _c->aor->len + _c->c.len); |
|
17 |
+ if (p == 0) { |
|
18 |
+ LOG(L_ERR, "put_on_del_list(): No memory left"); |
|
19 |
+ return -1; |
|
20 |
+ } |
|
21 |
+ |
|
22 |
+ p->user_len = _c->aor->len; |
|
23 |
+ p->cont_len = _c->c.len; |
|
24 |
+ |
|
25 |
+ memcpy(p->tail, _c->aor->s, p->user_len); |
|
26 |
+ memcpy(p->tail + p->user_len, _c->c.s, p->cont_len); |
|
27 |
+ |
|
28 |
+ p->next = del_root; |
|
29 |
+ del_root = p; |
|
30 |
+ return 0; |
|
31 |
+} |
|
32 |
+ |
|
33 |
+ |
|
34 |
+int process_del_list(str* _d) |
|
35 |
+{ |
|
36 |
+ struct del_itm* p; |
|
37 |
+ char b[256]; |
|
38 |
+ db_key_t keys[2] = {user_col, contact_col}; |
|
39 |
+ db_val_t vals[2]; |
|
40 |
+ |
|
41 |
+ if (del_root) { |
|
42 |
+ /* FIXME */ |
|
43 |
+ memcpy(b, _d->s, _d->len); |
|
44 |
+ b[_d->len] = '\0'; |
|
45 |
+ db_use_table(db, b); |
|
46 |
+ |
|
47 |
+ VAL_TYPE(vals) = VAL_TYPE(vals + 1) = DB_STR; |
|
48 |
+ VAL_NULL(vals) = VAL_NULL(vals + 1) = 0; |
|
49 |
+ } |
|
50 |
+ |
|
51 |
+ while(del_root) { |
|
52 |
+ p = del_root; |
|
53 |
+ del_root = del_root->next; |
|
54 |
+ |
|
55 |
+ VAL_STR(vals).len = p->user_len; |
|
56 |
+ VAL_STR(vals).s = p->tail; |
|
57 |
+ |
|
58 |
+ VAL_STR(vals + 1).len = p->cont_len; |
|
59 |
+ VAL_STR(vals + 1).s = p->tail + p->user_len; |
|
60 |
+ |
|
61 |
+ if (db_delete(db, keys, vals, 2) < 0) { |
|
62 |
+ LOG(L_ERR, "process_del_list(): Error while deleting from database\n"); |
|
63 |
+ return -1; |
|
64 |
+ } |
|
65 |
+ |
|
66 |
+ pkg_free(p); |
|
67 |
+ } |
|
68 |
+ |
|
69 |
+ return 0; |
|
70 |
+} |
0 | 71 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,21 @@ |
1 |
+#ifndef DEL_LIST_H |
|
2 |
+#define DEL_LIST_H |
|
3 |
+ |
|
4 |
+ |
|
5 |
+#include "ucontact.h" |
|
6 |
+ |
|
7 |
+ |
|
8 |
+struct del_itm { |
|
9 |
+ struct del_itm* next; |
|
10 |
+ int user_len; |
|
11 |
+ int cont_len; |
|
12 |
+ char tail[0]; |
|
13 |
+}; |
|
14 |
+ |
|
15 |
+ |
|
16 |
+int put_on_del_list(struct ucontact* _c); |
|
17 |
+ |
|
18 |
+int process_del_list(str* _d); |
|
19 |
+ |
|
20 |
+ |
|
21 |
+#endif /* DEL_LIST_H */ |
0 | 22 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,95 @@ |
1 |
+#include "ins_list.h" |
|
2 |
+#include "../../mem/mem.h" |
|
3 |
+#include <string.h> |
|
4 |
+#include "../../dprint.h" |
|
5 |
+#include "../../db/db.h" |
|
6 |
+#include "ul_mod.h" |
|
7 |
+ |
|
8 |
+ |
|
9 |
+static struct ins_itm* ins_root = 0; |
|
10 |
+ |
|
11 |
+ |
|
12 |
+int put_on_ins_list(struct ucontact* _c) |
|
13 |
+{ |
|
14 |
+ struct ins_itm* p; |
|
15 |
+ |
|
16 |
+ p = (struct ins_itm*)pkg_malloc(sizeof(struct ins_itm) + _c->aor->len + _c->c.len + _c->callid.len); |
|
17 |
+ if (p == 0) { |
|
18 |
+ LOG(L_ERR, "put_on_ins_list(): No memory left"); |
|
19 |
+ return -1; |
|
20 |
+ } |
|
21 |
+ |
|
22 |
+ p->expires = _c->expires; |
|
23 |
+ p->q = _c->q; |
|
24 |
+ p->cseq = _c->cseq; |
|
25 |
+ |
|
26 |
+ p->user_len = _c->aor->len; |
|
27 |
+ p->cont_len = _c->c.len; |
|
28 |
+ p->cid_len = _c->callid.len; |
|
29 |
+ |
|
30 |
+ memcpy(p->tail, _c->aor->s, p->user_len); |
|
31 |
+ memcpy(p->tail + p->user_len, _c->c.s, p->cont_len); |
|
32 |
+ memcpy(p->tail + p->user_len + p->cont_len, _c->callid.s, p->cid_len); |
|
33 |
+ |
|
34 |
+ p->next = ins_root; |
|
35 |
+ ins_root = p; |
|
36 |
+ return 0; |
|
37 |
+} |
|
38 |
+ |
|
39 |
+ |
|
40 |
+int process_ins_list(str* _d) |
|
41 |
+{ |
|
42 |
+ struct ins_itm* p; |
|
43 |
+ char b[256]; |
|
44 |
+ db_key_t keys[] = {user_col, contact_col, expires_col, q_col, callid_col, cseq_col}; |
|
45 |
+ db_val_t vals[6]; |
|
46 |
+ |
|
47 |
+ if (ins_root) { |
|
48 |
+ /* FIXME */ |
|
49 |
+ memcpy(b, _d->s, _d->len); |
|
50 |
+ b[_d->len] = '\0'; |
|
51 |
+ db_use_table(db, b); |
|
52 |
+ |
|
53 |
+ VAL_TYPE(vals) = DB_STR; |
|
54 |
+ VAL_TYPE(vals + 1) = DB_STR; |
|
55 |
+ VAL_TYPE(vals + 2) = DB_DATETIME; |
|
56 |
+ VAL_TYPE(vals + 3) = DB_DOUBLE; |
|
57 |
+ VAL_TYPE(vals + 4) = DB_STR; |
|
58 |
+ VAL_TYPE(vals + 5) = DB_INT; |
|
59 |
+ |
|
60 |
+ VAL_NULL(vals) = 0; |
|
61 |
+ VAL_NULL(vals + 1) = 0; |
|
62 |
+ VAL_NULL(vals + 2) = 0; |
|
63 |
+ VAL_NULL(vals + 3) = 0; |
|
64 |
+ VAL_NULL(vals + 4) = 0; |
|
65 |
+ VAL_NULL(vals + 5) = 0; |
|
66 |
+ } |
|
67 |
+ |
|
68 |
+ while(ins_root) { |
|
69 |
+ p = ins_root; |
|
70 |
+ ins_root = ins_root->next; |
|
71 |
+ |
|
72 |
+ VAL_STR(vals).len = p->user_len; |
|
73 |
+ VAL_STR(vals).s = p->tail; |
|
74 |
+ |
|
75 |
+ VAL_STR(vals + 1).len = p->cont_len; |
|
76 |
+ VAL_STR(vals + 1).s = p->tail + p->user_len; |
|
77 |
+ |
|
78 |
+ VAL_TIME(vals + 2) = p->expires; |
|
79 |
+ VAL_DOUBLE(vals + 3) = p->q; |
|
80 |
+ |
|
81 |
+ VAL_STR(vals + 4).len = p->cid_len; |
|
82 |
+ VAL_STR(vals + 4).s = p->tail + p->user_len + p->cont_len; |
|
83 |
+ |
|
84 |
+ VAL_INT(vals + 5) = p->cseq; |
|
85 |
+ |
|
86 |
+ if (db_insert(db, keys, vals, 6) < 0) { |
|
87 |
+ LOG(L_ERR, "process_ins_list(): Error while deleting from database\n"); |
|
88 |
+ return -1; |
|
89 |
+ } |
|
90 |
+ |
|
91 |
+ pkg_free(p); |
|
92 |
+ } |
|
93 |
+ |
|
94 |
+ return 0; |
|
95 |
+} |
0 | 96 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,25 @@ |
1 |
+#ifndef INS_LIST_H |
|
2 |
+#define INS_LIST_H |
|
3 |
+ |
|
4 |
+#include "ucontact.h" |
|
5 |
+#include "../../str.h" |
|
6 |
+ |
|
7 |
+ |
|
8 |
+struct ins_itm { |
|
9 |
+ struct ins_itm* next; |
|
10 |
+ time_t expires; |
|
11 |
+ float q; |
|
12 |
+ int cseq; |
|
13 |
+ int user_len; |
|
14 |
+ int cont_len; |
|
15 |
+ int cid_len; |
|
16 |
+ char tail[0]; |
|
17 |
+}; |
|
18 |
+ |
|
19 |
+ |
|
20 |
+int put_on_ins_list(struct ucontact* _c); |
|
21 |
+ |
|
22 |
+int process_ins_list(str* _d); |
|
23 |
+ |
|
24 |
+ |
|
25 |
+#endif /* INS_LIST_H */ |
... | ... |
@@ -8,6 +8,8 @@ |
8 | 8 |
#include "../../dprint.h" |
9 | 9 |
#include "../../db/db.h" |
10 | 10 |
#include "ul_mod.h" /* usrloc module parameters */ |
11 |
+#include "del_list.h" |
|
12 |
+#include "ins_list.h" |
|
11 | 13 |
|
12 | 14 |
|
13 | 15 |
/* |
... | ... |
@@ -241,77 +243,6 @@ int preload_udomain(udomain_t* _d) |
241 | 243 |
} |
242 | 244 |
|
243 | 245 |
|
244 |
-/* |
|
245 |
-int preload_udomain(udomain_t* _d) |
|
246 |
-{ |
|
247 |
- char b[256]; |
|
248 |
- db_key_t columns[6] = {user_col, contact_col, expires_col, q_col, callid_col, cseq_col}; |
|
249 |
- db_res_t* res; |
|
250 |
- db_row_t* row; |
|
251 |
- int i, cseq; |
|
252 |
- urecord_t* rec = 0; |
|
253 |
- const char* user, *aor = 0; |
|
254 |
- double q; |
|
255 |
- time_t expires; |
|
256 |
- str s, contact, callid; |
|
257 |
- |
|
258 |
- memcpy(b, _d->name->s, _d->name->len); |
|
259 |
- b[_d->name->len] = '\0'; |
|
260 |
- db_use_table(db, b); |
|
261 |
- if (db_query(db, 0, 0, columns, 0, 6, user_col, &res) < 0) { |
|
262 |
- LOG(L_ERR, "preload_udomain(): Error while doing db_query\n"); |
|
263 |
- return -1; |
|
264 |
- } |
|
265 |
- |
|
266 |
- if (!RES_ROW_N(res)) { |
|
267 |
- DBG("preload_udomain(): Table is empty\n"); |
|
268 |
- db_free_query(db, res); |
|
269 |
- return 0; |
|
270 |
- } |
|
271 |
- |
|
272 |
- for(i = 0; i < RES_ROW_N(res); i++) { |
|
273 |
- row = RES_ROWS(res) + i; |
|
274 |
- user = VAL_STRING(ROW_VALUES(row)); |
|
275 |
- if (i == 0) aor = user; |
|
276 |
- |
|
277 |
- if (strcmp(user, aor) || !i) { |
|
278 |
- DBG("preload_udomain(): Preloading contacts for username \'%s\'\n", user); |
|
279 |
- aor = user; |
|
280 |
- |
|
281 |
- if (rec) release_urecord(rec); |
|
282 |
- |
|
283 |
- s.s = (char*)user; |
|
284 |
- s.len = strlen(user); |
|
285 |
- |
|
286 |
- if (insert_urecord(_d_d->name, &s, &rec) < 0) { |
|
287 |
- LOG(L_ERR, "preload_udomain(): Can't create new record\n"); |
|
288 |
- db_free_query(db, res); |
|
289 |
- return -3; |
|
290 |
- } |
|
291 |
- } |
|
292 |
- |
|
293 |
- |
|
294 |
- if (ins(rec, &contact, expires, q, &callid, cseq) < 0) { |
|
295 |
- LOG(L_ERR, "preload_udomain(): Error while adding contact\n"); |
|
296 |
- db_free_query(db, res); |
|
297 |
- free_urecord(rec); |
|
298 |
- return -3; |
|
299 |
- } |
|
300 |
- } |
|
301 |
- |
|
302 |
- if (rec && (insert_urecord(_d, rec) < 0)) { |
|
303 |
- LOG(L_ERR, "preload_udomain(): Error while inserting record 2\n"); |
|
304 |
- free_urecord(rec); |
|
305 |
- db_free_query(db, res); |
|
306 |
- return -4; |
|
307 |
- } |
|
308 |
- |
|
309 |
- db_free_query(db, res); |
|
310 |
- return 0; |
|
311 |
-} |
|
312 |
-*/ |
|
313 |
- |
|
314 |
- |
|
315 | 246 |
/* |
316 | 247 |
* Insert a new record into domain |
317 | 248 |
*/ |
... | ... |
@@ -372,6 +303,8 @@ int timer_udomain(udomain_t* _d) |
372 | 303 |
} |
373 | 304 |
|
374 | 305 |
unlock_udomain(_d); |
306 |
+ process_del_list(_d->name); |
|
307 |
+ process_ins_list(_d->name); |
|
375 | 308 |
return 0; |
376 | 309 |
} |
377 | 310 |
|
... | ... |
@@ -12,6 +12,8 @@ |
12 | 12 |
#include "../../fastlock.h" |
13 | 13 |
#include "ul_mod.h" |
14 | 14 |
#include "utime.h" |
15 |
+#include "del_list.h" |
|
16 |
+#include "ins_list.h" |
|
15 | 17 |
|
16 | 18 |
|
17 | 19 |
/* |
... | ... |
@@ -128,9 +130,9 @@ int mem_insert_ucontact(urecord_t* _r, str* _c, time_t _e, float _q, |
128 | 130 |
|
129 | 131 |
|
130 | 132 |
/* |
131 |
- * Remove contact from the list |
|
133 |
+ * Remove the contact from lists |
|
132 | 134 |
*/ |
133 |
-void mem_delete_ucontact(urecord_t* _r, ucontact_t* _c) |
|
135 |
+void mem_remove_ucontact(urecord_t* _r, ucontact_t* _c) |
|
134 | 136 |
{ |
135 | 137 |
if (_c->prev) { |
136 | 138 |
_c->prev->next = _c->next; |
... | ... |
@@ -143,7 +145,16 @@ void mem_delete_ucontact(urecord_t* _r, ucontact_t* _c) |
143 | 145 |
_c->next->prev = 0; |
144 | 146 |
} |
145 | 147 |
} |
146 |
- |
|
148 |
+} |
|
149 |
+ |
|
150 |
+ |
|
151 |
+ |
|
152 |
+/* |
|
153 |
+ * Remove contact from the list and delete |
|
154 |
+ */ |
|
155 |
+void mem_delete_ucontact(urecord_t* _r, ucontact_t* _c) |
|
156 |
+{ |
|
157 |
+ mem_remove_ucontact(_r, _c); |
|
147 | 158 |
free_ucontact(_c); |
148 | 159 |
} |
149 | 160 |
|
... | ... |
@@ -233,10 +244,17 @@ static inline int wb_timer(urecord_t* _r) |
233 | 244 |
|
234 | 245 |
/* Should we remove the contact from the database ? */ |
235 | 246 |
if (st_expired_ucontact(t) == 1) { |
247 |
+ if (put_on_del_list(t) < 0) { |
|
248 |
+ LOG(L_ERR, "wb_timer(): Can't put on delete list\n"); |
|
249 |
+ } |
|
250 |
+ |
|
251 |
+ /* |
|
236 | 252 |
if (db_delete_ucontact(t) < 0) { |
237 | 253 |
LOG(L_ERR, "wb_timer(): Error while deleting contact from database\n"); |
238 | 254 |
} |
255 |
+ */ |
|
239 | 256 |
} |
257 |
+ |
|
240 | 258 |
if (t->expires != 0) { |
241 | 259 |
_r->slot->d->expired++; |
242 | 260 |
} |
... | ... |
@@ -251,12 +269,23 @@ static inline int wb_timer(urecord_t* _r) |
251 | 269 |
break; |
252 | 270 |
|
253 | 271 |
case 1: /* insert */ |
272 |
+ if (put_on_ins_list(ptr) < 0) { |
|
273 |
+ LOG(L_ERR, "wb_timer(): Error while putting on ins_list\n"); |
|
274 |
+ } |
|
275 |
+ |
|
276 |
+ /* |
|
254 | 277 |
if (db_insert_ucontact(ptr) < 0) { |
255 | 278 |
LOG(L_ERR, "wb_timer(): Error while inserting contact in db\n"); |
256 | 279 |
} |
280 |
+ */ |
|
257 | 281 |
break; |
258 | 282 |
|
259 | 283 |
case 2: /* update */ |
284 |
+ /* |
|
285 |
+ if (put_on_upd_list(ptr) < 0) { |
|
286 |
+ LOG(L_ERR, "wb_timer(): Error while putting on del_list\n"); |
|
287 |
+ } |
|
288 |
+ */ |
|
260 | 289 |
if (db_update_ucontact(ptr) < 0) { |
261 | 290 |
LOG(L_ERR, "wb_timer(): Error while updating contact in db\n"); |
262 | 291 |
} |
... | ... |
@@ -59,8 +59,15 @@ int mem_insert_ucontact(urecord_t* _r, str* _c, time_t _e, float _q, |
59 | 59 |
str* _cid, int _cs, struct ucontact** _con); |
60 | 60 |
|
61 | 61 |
|
62 |
+ |
|
63 |
+/* |
|
64 |
+ * Remove the contact from lists |
|
65 |
+ */ |
|
66 |
+void mem_remove_ucontact(urecord_t* _r, ucontact_t* _c); |
|
67 |
+ |
|
68 |
+ |
|
62 | 69 |
/* |
63 |
- * Remove contact from the list |
|
70 |
+ * Remove contact from the list and delete |
|
64 | 71 |
*/ |
65 | 72 |
void mem_delete_ucontact(urecord_t* _r, ucontact_t* _c); |
66 | 73 |
|