summaryrefslogtreecommitdiffstats
path: root/mbbsd/emaildb.c
blob: 931aee6661de0ba7140f8bbce8528e11e004c13c (plain) (blame)
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/* $Id$ */

#include "bbs.h"
#include "daemons.h"

#ifdef USE_EMAILDB

int emaildb_check_email(const char * email, int email_len)
{
    int count = -1;
    int fd = -1;
    regmaildb_req req = {0};

    // initialize request
    req.cb = sizeof(req);
    req.operation = REGMAILDB_REQ_COUNT;
    strlcpy(req.userid, cuser.userid, sizeof(req.userid));
    strlcpy(req.email,  email,        sizeof(req.email));

    if ( (fd = toconnect(REGMAILD_ADDR)) < 0 )
    {
        // perror("toconnect");
        return -1;
    }

    if (towrite(fd, &req, sizeof(req)) != sizeof(req)) {
        // perror("towrite");
        close(fd);
        return -1;
    }

    if (toread(fd, &count, sizeof(count)) != sizeof(count)) {
        // perror("toread");
        close(fd);
        return -1;
    }

    return count;
}

int emaildb_update_email(const char * userid, int userid_len, const char * email, int email_len)
{
    int result = -1;
    int fd = -1;
    regmaildb_req req = {0};

    // initialize request
    req.cb = sizeof(req);
    req.operation = REGMAILDB_REQ_SET;
    strlcpy(req.userid, userid, sizeof(req.userid));
    strlcpy(req.email,  email,  sizeof(req.email));

    if ( (fd = toconnect(REGMAILD_ADDR)) < 0 )
    {
        // perror("toconnect");
        return -1;
    }

    if (towrite(fd, &req, sizeof(req)) != sizeof(req)) {
        // perror("towrite");
        close(fd);
        return -1;
    }

    if (toread(fd, &result, sizeof(result)) != sizeof(result)) {
        // perror("toread");
        close(fd);
        return -1;
    }

    return result;
}

#endif

#ifdef USE_REGCHECKD

// XXX move to regcheck someday
int regcheck_ambiguous_userid_exist(const char *userid)
{
    int result = -1;
    int fd = -1;
    regmaildb_req req = {0};

    // initialize request
    req.cb = sizeof(req);
    req.operation = REGCHECK_REQ_AMBIGUOUS;
    strlcpy(req.userid, userid, sizeof(req.userid));
    strlcpy(req.email,  "ambiguous@check.non-exist",  sizeof(req.email));

    if ( (fd = toconnect(REGMAILD_ADDR)) < 0 )
    {
        // perror("toconnect");
        return -1;
    }

    if (towrite(fd, &req, sizeof(req)) != sizeof(req)) {
        // perror("towrite");
        close(fd);
        return -1;
    }

    if (toread(fd, &result, sizeof(result)) != sizeof(result)) {
        // perror("toread");
        close(fd);
        return -1;
    }

    return result;
}

#endif

// vim:et