File: echo-backend.c

package info (click to toggle)
mailfront 0.98-2
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 648 kB
  • ctags: 495
  • sloc: ansic: 3,033; sh: 1,487; makefile: 78
file content (60 lines) | stat: -rw-r--r-- 1,178 bytes parent folder | download
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
#include <string.h>
#include <msg/msg.h>
#include "mailfront.h"

static response r = { 250, 0 };
static str tmp;

static unsigned long databytes = 0;

void backend_handle_reset(void)
{
  databytes = 0;
}

const response* backend_handle_sender(str* sender)
{
  str_copys(&tmp, "Sender='");
  str_cat(&tmp, sender);
  str_cats(&tmp, "'.");
  r.message = tmp.s;
  return &r;
}

const response* backend_handle_recipient(str* recipient)
{
  str_copys(&tmp, "Recipient='");
  str_cat(&tmp, recipient);
  str_cats(&tmp, "'.");
  r.message = tmp.s;
  return &r;
}

const response* backend_handle_data_start(void)
{
  return 0;
}

void backend_handle_data_bytes(const char* bytes, unsigned long len)
{
  databytes += len;
  if (databytes == len) {
    /* First line is always Received, log the first two lines. */
    const char* ch;
    ch = strchr(bytes, '\n');
    str_copyb(&tmp, bytes, ch-bytes);
    bytes = ch + 1;
    ch = strchr(bytes, '\n');
    str_catb(&tmp, bytes, ch-bytes);
    msg1(tmp.s);
  }
}

const response* backend_handle_data_end(void)
{
  str_copys(&tmp, "Received ");
  str_catu(&tmp, databytes);
  str_cats(&tmp, " bytes.");
  r.message = tmp.s;
  return &r;
}