commit - 03a6f52ae9e64345f1b1571c9cab24de5fa869a2
commit + 47628d21f7a30b2113052998b86c24d42631eec8
blob - c85df01c0873425f605da34a290d4fb520a94f6b
blob + 13928bb008fe59896bee77ae7acad601c6ed2b11
--- smtp_proc.c
+++ smtp_proc.c
static void smtp_newline(int, short, void *);
static void smtp_connect(struct smtp_callback *, int, struct timespec *,
uint64_t, uint64_t, char *);
+static void smtp_in_link_disconnect(struct smtp_callback *, int, struct timespec *,
+ uint64_t, char *);
struct smtp_callback {
char *type;
char *phase;
char *direction;
- void (*smtp_parse)(struct smtp_callback *, int, struct timespec *,
- uint64_t, uint64_t, char *);
+ union {
+ void (*smtp_filter)(struct smtp_callback *, int,
+ struct timespec *, uint64_t, uint64_t, char *);
+ void (*smtp_report)(struct smtp_callback *, int,
+ struct timespec *, uint64_t, char *);
+ };
void *cb;
} smtp_callbacks[] = {
- {"filter", "connect", "smtp-in", smtp_connect, NULL}
+ {"filter", "connect", "smtp-in", .smtp_filter = smtp_connect, NULL},
+ {"report", "link-disconnect", "smtp-in",
+ .smtp_report = smtp_in_link_disconnect, NULL}
};
static int ready = 0;
return smtp_register("filter", "connect", "smtp-in", (void *)cb);
}
+int
+smtp_in_register_report_disconnect(void (*cb)(char *, int, struct timespec *,
+ char *, char *, uint64_t))
+{
+ return smtp_register("report", "link-disconnect", "smtp-in", (void *)cb);
+}
+
void
smtp_run(void)
{
if ((start = strchr(phase, '|')) == NULL)
errx(1, "Invalid line received: missing reqid");
start++[0] = '\0';
- reqid = strtoull(start, &end, 16);
- if (start[0] == '|' || end[0] != '|')
+ reqid = strtoull(start, ¶ms, 16);
+ if (start[0] == '|' || (params[0] != '|' & params[0] != '\0'))
errx(1, "Invalid line received: invalid reqid");
- end++[0] = '\0';
- start = end;
- token = strtoull(start, &end, 16);
- if (start[0] == '|' || end[0] != '|')
- errx(1, "Invalid line received: invalid token");
- params = end + 1;
+ params++;
for (i = 0; i < NITEMS(smtp_callbacks); i++) {
if (strcmp(type, smtp_callbacks[i].type) == 0 &&
errx(1, "Invalid line received: received unregistered "
"%s: %s", type, phase);
}
- smtp_callbacks[i].smtp_parse(&(smtp_callbacks[i]), version, &tm,
- reqid, token, params);
+ if (strcmp(type, "filter") == 0) {
+ start = params;
+ token = strtoull(start, ¶ms, 16);
+ if (start[0] == '|' || params[0] != '|')
+ errx(1, "Invalid line received: invalid token");
+ params++;
+ smtp_callbacks[i].smtp_filter(&(smtp_callbacks[i]),
+ version, &tm, reqid, token, params);
+ } else
+ smtp_callbacks[i].smtp_report(&(smtp_callbacks[i]),
+ version, &tm, reqid, params);
}
if (feof(stdin) || (ferror(stdin) && errno != EAGAIN))
event_del(stdinev);
f(cb->type, version, tm, cb->direction, cb->phase, reqid, token,
hostname, &addrx);
}
+static void
+smtp_in_link_disconnect(struct smtp_callback *cb, int version,
+ struct timespec *tm, uint64_t reqid, char *params)
+{
+ void (*f)(char *, int, struct timespec *, char *, char *, uint64_t);
+ f = cb->cb;
+ f(cb->type, version, tm, cb->direction, cb->phase, reqid);
+}
+
void
smtp_filter_proceed(uint64_t reqid, uint64_t token)
{
blob - eb1d00f093efc93ba2f5c600652e21aa9a983230
blob + 43d69e151aac1d3635863d111416bf3586f43395
--- smtp_proc.h
+++ smtp_proc.h
int smtp_register_filter_connect(void (*cb)(char *, int, struct timespec *,
char *, char *, uint64_t, uint64_t, char *, struct inx_addr *));
+int smtp_in_register_report_disconnect(void (*)(char *, int, struct timespec *,
+ char *, char *, uint64_t));
void smtp_filter_proceed(uint64_t, uint64_t);
void smtp_filter_reject(uint64_t, uint64_t, int, const char *, ...)
__attribute__((__format__ (printf, 4, 5)));