~ubuntu-branches/debian/sid/kamailio/sid

« back to all changes in this revision

Viewing changes to modules/usrloc/urecord.c

  • Committer: Package Import Robot
  • Author(s): Victor Seva
  • Date: 2014-01-06 11:47:13 UTC
  • mfrom: (1.1.5)
  • Revision ID: package-import@ubuntu.com-20140106114713-t8xidp4arzrnyeya
Tags: 4.1.1-1
* New upstream release
* debian/patches:
  - add upstream fixes
* Added tls outbound websocket autheph dnssec modules
  - openssl exception added to their license
* removing sparc and ia64 from supported archs
  for mono module (Closes: #728915)

Show diffs side-by-side

added added

removed removed

Lines of Context:
40
40
#include "../../dprint.h"
41
41
#include "../../ut.h"
42
42
#include "../../hashes.h"
 
43
#include "../../tcp_conn.h"
43
44
#include "ul_mod.h"
44
45
#include "usrloc.h"
45
46
#include "utime.h"
221
222
        free_ucontact(_c);
222
223
}
223
224
 
 
225
static inline int is_valid_tcpconn(ucontact_t *c)
 
226
{
 
227
        if (c->tcpconn_id == -1)
 
228
                return 0; /* tcpconn_id is not present */
 
229
        else
 
230
                return 1; /* valid tcpconn_id */
 
231
}
 
232
 
 
233
static inline int is_tcp_alive(ucontact_t *c)
 
234
{
 
235
        struct tcp_connection *con = NULL;
 
236
        int rc = 0;
 
237
 
 
238
        if ((con = tcpconn_get(c->tcpconn_id, 0, 0, 0, 0))) {
 
239
                tcpconn_put(con); /* refcnt-- */
 
240
                rc = 1;
 
241
        }
 
242
 
 
243
        return rc;
 
244
}
224
245
 
225
246
/*!
226
247
 * \brief Expires timer for NO_DB db_mode
236
257
        ptr = _r->contacts;
237
258
 
238
259
        while(ptr) {
 
260
                if (handle_lost_tcp && is_valid_tcpconn(ptr) && !is_tcp_alive(ptr)) {
 
261
                        LM_DBG("tcp connection has been lost, expiring contact %.*s\n", ptr->c.len, ptr->c.s);
 
262
                        ptr->expires = UL_EXPIRED_TIME;
 
263
                }
 
264
 
239
265
                if (!VALID_CONTACT(ptr, act_time)) {
240
266
                        /* run callbacks for EXPIRE event */
241
267
                        if (exists_ulcb_type(UL_CONTACT_EXPIRE))
296
322
        }
297
323
}
298
324
 
299
 
 
300
325
/*!
301
326
 * \brief Write-back timer, used for WRITE_BACK db_mode
302
327
 *
316
341
        ptr = _r->contacts;
317
342
 
318
343
        while(ptr) {
 
344
                if (handle_lost_tcp && is_valid_tcpconn(ptr) && !is_tcp_alive(ptr)) {
 
345
                        LM_DBG("tcp connection has been lost, expiring contact %.*s\n", ptr->c.len, ptr->c.s);
 
346
                        ptr->expires = UL_EXPIRED_TIME;
 
347
                }
 
348
 
319
349
                if (!VALID_CONTACT(ptr, act_time)) {
320
350
                        /* run callbacks for EXPIRE event */
321
351
                        if (exists_ulcb_type(UL_CONTACT_EXPIRE)) {
335
365
                                if (db_delete_ucontact(t) < 0) {
336
366
                                        LM_ERR("failed to delete contact from the database"
337
367
                                                        " (aor: %.*s)\n",
338
 
                                                        ptr->aor->len, ZSW(ptr->aor->s));
 
368
                                                        t->aor->len, ZSW(t->aor->s));
339
369
                                }
340
370
                        }
341
371
 
387
417
void timer_urecord(urecord_t* _r)
388
418
{
389
419
        switch(db_mode) {
 
420
        case DB_READONLY:
390
421
        case NO_DB:         nodb_timer(_r);
391
422
                                                break;
392
423
        /* use also the write_back timer routine to handle the failed
442
473
 
443
474
 
444
475
/*!
 
476
 * \brief Delete a record from the database based on ruid
 
477
 * \return 0 on success, -1 on failure
 
478
 */
 
479
int db_delete_urecord_by_ruid(str *_table, str *_ruid)
 
480
{
 
481
        db_key_t keys[1];
 
482
        db_val_t vals[1];
 
483
 
 
484
        keys[0] = &ruid_col;
 
485
        vals[0].type = DB1_STR;
 
486
        vals[0].nul = 0;
 
487
        vals[0].val.str_val.s = _ruid->s;
 
488
        vals[0].val.str_val.len = _ruid->len;
 
489
 
 
490
        if (ul_dbf.use_table(ul_dbh, _table) < 0) {
 
491
                LM_ERR("use_table failed\n");
 
492
                return -1;
 
493
        }
 
494
 
 
495
        if (ul_dbf.delete(ul_dbh, keys, 0, vals, 1) < 0) {
 
496
                LM_ERR("failed to delete from database\n");
 
497
                return -1;
 
498
        }
 
499
 
 
500
        if (ul_dbf.affected_rows(ul_dbh) == 0) {
 
501
                return -2;
 
502
        }
 
503
 
 
504
        return 0;
 
505
}
 
506
 
 
507
 
 
508
/*!
445
509
 * \brief Release urecord previously obtained through get_urecord
446
510
 * \warning Failing to calls this function after get_urecord will
447
511
 * result in a memory leak when the DB_ONLY mode is used. When
521
585
}
522
586
 
523
587
 
 
588
int delete_urecord_by_ruid(udomain_t* _d, str *_ruid)
 
589
{
 
590
    if (db_mode != DB_ONLY) {
 
591
        LM_ERR("delete_urecord_by_ruid currently available only in db_mode=3\n");
 
592
        return -1;
 
593
    }
 
594
 
 
595
    return db_delete_urecord_by_ruid(_d->name, _ruid);
 
596
}
 
597
 
 
598
 
524
599
/*!
525
600
 * \brief Match a contact record to a contact string
526
601
 * \param ptr contact record