File: session_config.c

package info (click to toggle)
prayer 1.3.3-dfsg1-3
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 6,388 kB
  • ctags: 3,280
  • sloc: ansic: 42,985; makefile: 805; sh: 451; perl: 166
file content (84 lines) | stat: -rw-r--r-- 2,566 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/* $Cambridge: hermes/src/prayer/servers/session_config.c,v 1.3 2008/09/16 09:59:57 dpc22 Exp $ */
/************************************************
 *    Prayer - a Webmail Interface              *
 ************************************************/

/* Copyright (c) University of Cambridge 2000 - 2008 */
/* See the file NOTICE for conditions of use and distribution. */

#include "server.h"

/* Config methods applied to running session */

/* session_config_local_domain_open() ***********************************
 *
 * Open local_domain CDB maps.
 ************************************************************************/

BOOL session_config_local_domain_open(struct config *config)
{
    struct list_item *li;

    if (config->local_domain_list == NIL)
        return (T);

    for (li = config->local_domain_list->head; li; li = li->next) {
        struct config_local_domain *cld =
            (struct config_local_domain *) li;

        if (cld->file) {
            if (cld->cdb_map)
                cdb_close(cld->cdb_map);

            if ((cld->cdb_map = cdb_open(cld->file)) == NIL) {
                log_panic("Couldn't open local_domains map file: %s\n",
                          cld->file);
                return (NIL);
            }
            log_debug("Opened CDB map for local domain: %s", cld->name);
        }
    }

    config->local_domain_time = time(NIL);
    return (T);
}

/* session_config_local_domain_ping() ***********************************
 *
 * Reopen local_domain CDB maps at periodic intervals.
 ************************************************************************/

BOOL session_config_local_domain_ping(struct config * config)
{
    struct list_item *li;
    time_t now = time(NIL);

    if (config->local_domain_list == NIL)
        return (T);

    if (config->db_ping_interval == 0)
        return (T);

    if ((config->local_domain_time + config->db_ping_interval) >= now)
        return (T);

    for (li = config->local_domain_list->head; li; li = li->next) {
        struct config_local_domain *cld =
            (struct config_local_domain *) li;

        if (cld->file) {
            if (cld->cdb_map)
                cdb_close(cld->cdb_map);

            if ((cld->cdb_map = cdb_open(cld->file)) == NIL) {
                log_panic("Couldn't open local_domains map file: %s\n",
                          cld->file);
                return (NIL);
            }
            log_debug("Reopened CDB map for local domain: %s", cld->name);
        }
    }

    config->local_domain_time = now;
    return (T);
}