summaryrefslogtreecommitdiffstats
path: root/daemon/regmaild/regmailc.c
blob: cd5d2be8ad71a4f32a2aeb28af65d03a2a660120 (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
// $Id$
#include <stdio.h>
#include <string.h>
#include <unistd.h>

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

// standalone client to test fromd

int main(int argc, char *argv[])
{
    int fd, ret = 0;
    int op = 0;
    regmaildb_req req = {0};

    if (argc < 4) {
    fprintf(stderr, "Usage: %s operation userid email\n", argv[0]);
    return 0;
    }

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

    if (strcmp(argv[1], "count") == 0)
    {
    op = REGMAILDB_REQ_COUNT;
    strlcpy(req.userid, argv[2], sizeof(req.userid));
    strlcpy(req.email,  argv[3], sizeof(req.email));
    }
    else if (strcmp(argv[1], "set") == 0)
    {
    op = REGMAILDB_REQ_SET;
    strlcpy(req.userid, argv[2], sizeof(req.userid));
    strlcpy(req.email,  argv[3], sizeof(req.email));
    }
    else
    return 0;

    req.cb = sizeof(req);
    req.operation = op;

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

    if (toread(fd, &ret, sizeof(ret)) != sizeof(ret)) {
    perror("toread");
    return 1;
    }

    printf("count: %d\n", ret);
    return 0;
}