2016-07-10 18:27:27 +00:00
|
|
|
// memmem
|
|
|
|
#define _GNU_SOURCE
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <time.h>
|
|
|
|
|
2016-07-13 13:01:09 +00:00
|
|
|
#include "blaze822.h"
|
|
|
|
#include "blaze822_priv.h"
|
|
|
|
|
2016-07-10 18:27:27 +00:00
|
|
|
#define bufsiz 4096
|
|
|
|
|
|
|
|
static long
|
|
|
|
parse_posint(char **s, size_t minn, size_t maxn)
|
|
|
|
{
|
|
|
|
long n;
|
|
|
|
char *end;
|
|
|
|
|
|
|
|
errno = 0;
|
|
|
|
n = strtol(*s, &end, 10);
|
|
|
|
if (errno) {
|
|
|
|
// perror("strtol");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (n < (long)minn || n > (long)maxn) {
|
|
|
|
// fprintf(stderr, "number outside %zd <= n < %zd\n", minn, maxn);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
*s = end;
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
time_t
|
2016-07-11 12:23:41 +00:00
|
|
|
blaze822_date(char *s) {
|
2016-07-10 18:27:27 +00:00
|
|
|
struct tm tm;
|
|
|
|
int c;
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
#define i4(m) (s[0] && (s[0]|0x20) == m[0] && \
|
|
|
|
s[1] && (s[1]|0x20) == m[1] && \
|
|
|
|
s[2] && (s[2]|0x20) == m[2] && \
|
|
|
|
s[3] && (s[3]|0x20) == m[3] && (s = s+4) )
|
|
|
|
|
|
|
|
#define i3(m) (s[0] && (s[0]|0x20) == m[0] && \
|
|
|
|
s[1] && (s[1]|0x20) == m[1] && \
|
|
|
|
s[2] && (s[2]|0x20) == m[2] && (s = s+3) )
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define i4(m) (((uint32_t) m[0]<<24 | m[1]<<16 | m[2]<<8 | m[3]) == \
|
|
|
|
((uint32_t) s[0]<<24 | s[1]<<16 | s[2]<<8 | s[3] | 0x20202020) \
|
|
|
|
&& (s += 4))
|
|
|
|
|
|
|
|
#define i3(m) (((uint32_t) m[0]<<24 | m[1]<<16 | m[2]<<8) == \
|
|
|
|
((uint32_t) s[0]<<24 | s[1]<<16 | s[2]<<8 | 0x20202000) \
|
|
|
|
&& (s += 3))
|
|
|
|
|
|
|
|
while (iswsp(*s))
|
|
|
|
s++;
|
|
|
|
if (i4("mon,") || i4("tue,") || i4("wed,") || i4("thu,") ||
|
|
|
|
i4("fri,") || i4("sat,") || i4("sun,"))
|
|
|
|
while (iswsp(*s))
|
|
|
|
s++;
|
|
|
|
|
|
|
|
if ((c = parse_posint(&s, 1, 31)) < 0) goto fail;
|
|
|
|
tm.tm_mday = c;
|
|
|
|
|
|
|
|
while (iswsp(*s))
|
|
|
|
s++;
|
|
|
|
|
|
|
|
if (i3("jan")) tm.tm_mon = 0;
|
|
|
|
else if (i3("feb")) tm.tm_mon = 1;
|
|
|
|
else if (i3("mar")) tm.tm_mon = 2;
|
|
|
|
else if (i3("apr")) tm.tm_mon = 3;
|
|
|
|
else if (i3("may")) tm.tm_mon = 4;
|
|
|
|
else if (i3("jul")) tm.tm_mon = 5;
|
|
|
|
else if (i3("jun")) tm.tm_mon = 6;
|
|
|
|
else if (i3("aug")) tm.tm_mon = 7;
|
|
|
|
else if (i3("sep")) tm.tm_mon = 8;
|
|
|
|
else if (i3("oct")) tm.tm_mon = 9;
|
|
|
|
else if (i3("nov")) tm.tm_mon = 10;
|
|
|
|
else if (i3("dec")) tm.tm_mon = 11;
|
|
|
|
else goto fail;
|
|
|
|
|
|
|
|
while (iswsp(*s))
|
|
|
|
s++;
|
|
|
|
|
|
|
|
if ((c = parse_posint(&s, 1000, 9999)) > 0) {
|
|
|
|
tm.tm_year = c - 1900;
|
|
|
|
} else if ((c = parse_posint(&s, 0, 49)) > 0) {
|
|
|
|
tm.tm_year = c + 100;
|
|
|
|
} else if ((c = parse_posint(&s, 50, 99)) > 0) {
|
|
|
|
tm.tm_year = c;
|
|
|
|
} else goto fail;
|
|
|
|
|
|
|
|
while (iswsp(*s))
|
|
|
|
s++;
|
|
|
|
|
|
|
|
if ((c = parse_posint(&s, 0, 24)) < 0) goto fail;
|
|
|
|
tm.tm_hour = c;
|
|
|
|
if (*s++ != ':') goto fail;
|
|
|
|
if ((c = parse_posint(&s, 0, 59)) < 0) goto fail;
|
|
|
|
tm.tm_min = c;
|
|
|
|
if (*s++ == ':') {
|
|
|
|
if ((c = parse_posint(&s, 0, 61)) < 0) goto fail;
|
|
|
|
tm.tm_sec = c;
|
2016-07-12 13:11:01 +00:00
|
|
|
} else {
|
|
|
|
tm.tm_sec = 0;
|
2016-07-10 18:27:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
while (iswsp(*s))
|
|
|
|
s++;
|
|
|
|
|
|
|
|
if (*s == '+' || *s == '-') {
|
|
|
|
int neg = (*s == '-');
|
|
|
|
s++;
|
|
|
|
if ((c = parse_posint(&s, 0, 10000)) < 0) goto fail;
|
|
|
|
if (neg) {
|
|
|
|
tm.tm_hour += c / 100;
|
|
|
|
tm.tm_min += c % 100;
|
|
|
|
} else {
|
|
|
|
tm.tm_hour -= c / 100;
|
|
|
|
tm.tm_min -= c % 100;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
tm.tm_isdst = -1;
|
|
|
|
|
|
|
|
time_t r = mktime(&tm);
|
|
|
|
return r;
|
|
|
|
|
|
|
|
fail:
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *
|
2016-07-11 12:23:41 +00:00
|
|
|
blaze822_addr(char *s, char **dispo, char **addro)
|
2016-07-10 18:27:27 +00:00
|
|
|
{
|
|
|
|
static char disp[1024];
|
|
|
|
static char addr[1024];
|
|
|
|
// char *disp = disp+sizeof disp;
|
|
|
|
// char *addr = addr+sizeof addr;
|
|
|
|
char *c, *e;
|
|
|
|
|
2016-07-11 12:23:41 +00:00
|
|
|
// printf("RAW : |%s|\n", s);
|
2016-07-10 18:27:27 +00:00
|
|
|
|
|
|
|
while (iswsp(*s))
|
|
|
|
s++;
|
|
|
|
|
|
|
|
c = disp;
|
|
|
|
e = disp + sizeof disp;
|
|
|
|
|
|
|
|
*disp = 0;
|
|
|
|
*addr = 0;
|
|
|
|
|
|
|
|
while (*s) {
|
|
|
|
if (*s == '<') {
|
|
|
|
char *c = addr;
|
|
|
|
char *e = addr + sizeof addr;
|
|
|
|
|
|
|
|
s++;
|
|
|
|
while (*s && c < e && *s != '>')
|
|
|
|
*c++ = *s++;
|
|
|
|
if (*s == '>')
|
|
|
|
s++;
|
|
|
|
*c = 0;
|
|
|
|
} else if (*s == '"') {
|
|
|
|
s++;
|
|
|
|
while (*s && c < e && *s != '"')
|
|
|
|
*c++ = *s++;
|
|
|
|
if (*s == '"')
|
|
|
|
s++;
|
|
|
|
} else if (*s == '(') {
|
|
|
|
s++;
|
|
|
|
|
|
|
|
if (!*addr) { // assume: user@host (name)
|
|
|
|
*c-- = 0;
|
|
|
|
while (c > disp && iswsp(*c))
|
|
|
|
*c-- = 0;
|
|
|
|
strcpy(addr, disp);
|
|
|
|
c = disp;
|
|
|
|
*c = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (*s && c < e && *s != ')')
|
|
|
|
*c++ = *s++;
|
|
|
|
if (*s == ')')
|
|
|
|
s++;
|
|
|
|
} else if (*s == ',') {
|
|
|
|
s++;
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
*c++ = *s++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*c-- = 0;
|
|
|
|
// strip trailing ws
|
|
|
|
while (c > disp && iswsp(*c))
|
|
|
|
*c-- = 0;
|
|
|
|
|
|
|
|
if (*disp && !*addr && strchr(disp, '@')) {
|
|
|
|
// just mail address was given
|
|
|
|
strcpy(addr, disp);
|
|
|
|
*disp = 0;
|
|
|
|
}
|
|
|
|
|
2016-07-11 12:23:41 +00:00
|
|
|
// printf("DISP :: |%s|\n", disp);
|
|
|
|
// printf("ADDR :: |%s|\n", addr);
|
2016-07-10 18:27:27 +00:00
|
|
|
|
|
|
|
if (dispo) *dispo = disp;
|
|
|
|
if (addro) *addro = addr;
|
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2016-07-13 21:41:45 +00:00
|
|
|
static void
|
|
|
|
compress_hdr(char *s, char *end)
|
|
|
|
{
|
|
|
|
char *t, *h;
|
|
|
|
|
|
|
|
if ((t = h = strchr(s, '\n'))) {
|
|
|
|
while (h < end && *h) {
|
|
|
|
if (*h == '\n') {
|
|
|
|
*t++ = ' ';
|
|
|
|
while (*h && isfws(*h))
|
|
|
|
h++;
|
|
|
|
}
|
|
|
|
*t++ = *h++;
|
|
|
|
}
|
|
|
|
// zero fill gap
|
|
|
|
while (t < h)
|
|
|
|
*t++ = 0;
|
|
|
|
// remove trailing whitespace
|
|
|
|
t--;
|
|
|
|
while (s < t && isfws(t[-1]))
|
|
|
|
*--t = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-07-13 13:22:47 +00:00
|
|
|
static void
|
|
|
|
unfold_hdr(char *buf, char *end)
|
|
|
|
{
|
2016-07-13 21:41:45 +00:00
|
|
|
char *s, *l;
|
2016-07-13 16:00:09 +00:00
|
|
|
*end = 0;
|
2016-07-13 13:22:47 +00:00
|
|
|
|
2016-07-13 21:41:45 +00:00
|
|
|
// sanitize all nul in message headers, srsly
|
|
|
|
if (memchr(buf, 0, end-buf))
|
|
|
|
for (s = buf; s < end; s++)
|
|
|
|
if (*s == 0)
|
|
|
|
*s = ' ';
|
|
|
|
|
|
|
|
// normalize crlf
|
|
|
|
if (memchr(buf, '\r', end-buf))
|
|
|
|
for (s = buf; s < end; s++)
|
|
|
|
if (*s == '\r') {
|
|
|
|
if (*(s+1) == '\n')
|
|
|
|
*s = '\n';
|
|
|
|
else
|
|
|
|
*s = ' ';
|
|
|
|
}
|
|
|
|
|
|
|
|
l = buf;
|
|
|
|
s = buf;
|
|
|
|
|
|
|
|
while (s < end && *s != ':' && *s != '\n') {
|
2016-07-13 13:22:47 +00:00
|
|
|
*s = lc(*s);
|
|
|
|
s++;
|
|
|
|
}
|
|
|
|
|
2016-07-13 21:41:45 +00:00
|
|
|
while (s < end) {
|
|
|
|
s = memchr(s+1, '\n', end-buf);
|
|
|
|
if (!s)
|
|
|
|
break;
|
2016-07-13 13:22:47 +00:00
|
|
|
|
2016-07-13 21:41:45 +00:00
|
|
|
while (s < end && *s == '\n')
|
2016-07-13 13:22:47 +00:00
|
|
|
s++;
|
2016-07-13 21:41:45 +00:00
|
|
|
if (!iswsp(*s)) {
|
|
|
|
*(s-1) = 0;
|
|
|
|
compress_hdr(l, s-1);
|
|
|
|
l = s;
|
|
|
|
while (s < end && *s != ':' && *s != '\n') {
|
|
|
|
*s = lc(*s);
|
|
|
|
s++;
|
2016-07-13 16:00:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-07-13 13:22:47 +00:00
|
|
|
}
|
|
|
|
|
2016-07-11 12:23:41 +00:00
|
|
|
struct message *
|
2016-07-10 18:27:27 +00:00
|
|
|
blaze822(char *file)
|
|
|
|
{
|
|
|
|
int fd;
|
|
|
|
ssize_t rd;
|
|
|
|
char *buf;
|
|
|
|
ssize_t bufalloc;
|
|
|
|
ssize_t used;
|
|
|
|
char *end;
|
|
|
|
|
2016-07-13 13:22:47 +00:00
|
|
|
struct message *mesg = malloc(sizeof (struct message));
|
|
|
|
if (!mesg)
|
|
|
|
return 0;
|
|
|
|
|
2016-07-10 18:27:27 +00:00
|
|
|
fd = open(file, O_RDONLY);
|
|
|
|
if (fd < 0) {
|
2016-07-11 12:23:41 +00:00
|
|
|
// perror("open");
|
|
|
|
return 0;
|
2016-07-10 18:27:27 +00:00
|
|
|
}
|
|
|
|
|
2016-07-13 13:22:47 +00:00
|
|
|
buf = 0;
|
|
|
|
bufalloc = 0;
|
|
|
|
used = 0;
|
2016-07-10 18:27:27 +00:00
|
|
|
|
|
|
|
while (1) {
|
2016-07-13 13:22:47 +00:00
|
|
|
int overlap = used > 3 ? 3 : 0;
|
|
|
|
|
2016-07-10 18:27:27 +00:00
|
|
|
bufalloc += bufsiz;
|
|
|
|
buf = realloc(buf, bufalloc);
|
2016-07-11 12:23:41 +00:00
|
|
|
if (!buf) {
|
2016-07-13 13:22:47 +00:00
|
|
|
free(mesg);
|
2016-07-11 12:23:41 +00:00
|
|
|
close(fd);
|
|
|
|
return 0;
|
|
|
|
}
|
2016-07-10 18:27:27 +00:00
|
|
|
|
|
|
|
rd = read(fd, buf+used, bufalloc-used);
|
|
|
|
if (rd == 0) {
|
|
|
|
end = buf+used;
|
|
|
|
break;
|
|
|
|
}
|
2016-07-11 12:23:41 +00:00
|
|
|
if (rd < 0) {
|
2016-07-13 13:22:47 +00:00
|
|
|
free(mesg);
|
2016-07-11 12:23:41 +00:00
|
|
|
free(buf);
|
|
|
|
close(fd);
|
|
|
|
return 0;
|
|
|
|
}
|
2016-07-10 18:27:27 +00:00
|
|
|
|
2016-07-13 13:22:47 +00:00
|
|
|
if ((end = memmem(buf-overlap+used, rd+overlap, "\n\n", 2)) ||
|
|
|
|
(end = memmem(buf-overlap+used, rd+overlap, "\r\n\r\n", 4))) {
|
2016-07-10 18:27:27 +00:00
|
|
|
used += rd;
|
2016-07-12 13:00:46 +00:00
|
|
|
end++;
|
2016-07-10 18:27:27 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
used += rd;
|
|
|
|
}
|
|
|
|
close(fd);
|
|
|
|
|
|
|
|
*end = 0; // dereferencing *end is safe
|
|
|
|
|
2016-07-13 13:22:47 +00:00
|
|
|
unfold_hdr(buf, end);
|
2016-07-11 12:23:41 +00:00
|
|
|
|
|
|
|
mesg->msg = buf;
|
|
|
|
mesg->end = end;
|
2016-07-13 13:52:39 +00:00
|
|
|
mesg->body = mesg->bodyend = mesg->bodychunk = 0;
|
2016-07-11 12:23:41 +00:00
|
|
|
|
|
|
|
return mesg;
|
|
|
|
}
|
|
|
|
|
2016-07-13 13:01:38 +00:00
|
|
|
|
|
|
|
struct message *
|
|
|
|
blaze822_mem(char *src, size_t len)
|
|
|
|
{
|
|
|
|
char *buf;
|
|
|
|
char *end;
|
|
|
|
|
2016-07-13 13:22:47 +00:00
|
|
|
struct message *mesg = malloc(sizeof (struct message));
|
|
|
|
if (!mesg)
|
2016-07-13 13:01:38 +00:00
|
|
|
return 0;
|
|
|
|
|
2016-07-13 14:03:35 +00:00
|
|
|
if ((end = memmem(src, len, "\n\n", 2))) {
|
|
|
|
mesg->body = end+2;
|
|
|
|
} else if ((end = memmem(src, len, "\r\n\r\n", 4))) {
|
|
|
|
mesg->body = end+4;
|
|
|
|
} else {
|
2016-07-13 13:52:39 +00:00
|
|
|
end = src + len;
|
2016-07-13 19:35:42 +00:00
|
|
|
mesg->body = end;
|
|
|
|
mesg->bodyend = end;
|
2016-07-13 14:03:35 +00:00
|
|
|
}
|
|
|
|
if (mesg->body)
|
|
|
|
mesg->bodyend = src + len;
|
2016-07-13 13:01:38 +00:00
|
|
|
|
2016-07-13 13:52:39 +00:00
|
|
|
size_t hlen = end - src;
|
2016-07-13 13:01:38 +00:00
|
|
|
|
2016-07-13 13:52:39 +00:00
|
|
|
buf = malloc(hlen+1);
|
2016-07-13 13:22:47 +00:00
|
|
|
if (!buf)
|
|
|
|
return 0;
|
2016-07-13 13:52:39 +00:00
|
|
|
memcpy(buf, src, hlen);
|
2016-07-13 13:01:38 +00:00
|
|
|
|
2016-07-13 15:02:29 +00:00
|
|
|
end = buf+hlen;
|
2016-07-13 13:01:38 +00:00
|
|
|
*end = 0; // dereferencing *end is safe
|
|
|
|
|
2016-07-13 13:22:47 +00:00
|
|
|
unfold_hdr(buf, end);
|
2016-07-13 13:01:38 +00:00
|
|
|
|
|
|
|
mesg->msg = buf;
|
|
|
|
mesg->end = end;
|
2016-07-13 13:52:39 +00:00
|
|
|
mesg->bodychunk = 0; // src is not ours
|
2016-07-13 13:01:38 +00:00
|
|
|
|
|
|
|
return mesg;
|
|
|
|
}
|
|
|
|
|
2016-07-11 12:23:41 +00:00
|
|
|
void
|
|
|
|
blaze822_free(struct message *mesg)
|
|
|
|
{
|
2016-07-13 19:55:17 +00:00
|
|
|
if (!mesg)
|
|
|
|
return;
|
2016-07-11 12:23:41 +00:00
|
|
|
free(mesg->msg);
|
2016-07-13 13:52:39 +00:00
|
|
|
free(mesg->bodychunk);
|
2016-07-11 12:23:41 +00:00
|
|
|
free(mesg);
|
|
|
|
}
|
|
|
|
|
|
|
|
char *
|
2016-07-13 13:01:09 +00:00
|
|
|
blaze822_hdr_(struct message *mesg, const char *hdr, size_t hdrlen)
|
2016-07-11 12:23:41 +00:00
|
|
|
{
|
2016-07-10 18:27:27 +00:00
|
|
|
char *v;
|
|
|
|
|
2016-07-14 11:27:14 +00:00
|
|
|
if (hdrlen == 0 || hdrlen-1 >= (size_t)(mesg->end - mesg->msg))
|
2016-07-13 19:08:05 +00:00
|
|
|
return 0; // header too small for the key, probably empty
|
|
|
|
|
2016-07-13 13:22:47 +00:00
|
|
|
// special case: first header, no leading nul
|
|
|
|
if (memcmp(mesg->msg, hdr+1, hdrlen-1) == 0)
|
|
|
|
v = mesg->msg;
|
|
|
|
else
|
|
|
|
v = memmem(mesg->msg, mesg->end - mesg->msg, hdr, hdrlen);
|
2016-07-11 12:23:41 +00:00
|
|
|
if (!v)
|
|
|
|
return 0;
|
|
|
|
v += hdrlen;
|
|
|
|
while (*v && iswsp(*v))
|
|
|
|
v++;
|
|
|
|
return v;
|
2016-07-10 18:27:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2016-07-11 14:28:22 +00:00
|
|
|
blaze822_loop(int argc, char *argv[], void (*cb)(char *))
|
2016-07-11 12:23:41 +00:00
|
|
|
{
|
2016-07-10 18:27:27 +00:00
|
|
|
char *line = 0;
|
|
|
|
size_t linelen = 0;
|
2016-07-11 14:28:22 +00:00
|
|
|
ssize_t rd;
|
2016-07-10 18:27:27 +00:00
|
|
|
int i = 0;
|
|
|
|
|
2016-07-11 14:28:22 +00:00
|
|
|
if (argc == 0 || (argc == 1 && strcmp(argv[0], "-") == 0)) {
|
|
|
|
while ((rd = getdelim(&line, &linelen, '\n', stdin)) != -1) {
|
|
|
|
if (line[rd-1] == '\n')
|
|
|
|
line[rd-1] = 0;
|
|
|
|
cb(line);
|
2016-07-10 18:27:27 +00:00
|
|
|
i++;
|
|
|
|
}
|
2016-07-13 15:17:18 +00:00
|
|
|
free(line);
|
2016-07-10 18:27:27 +00:00
|
|
|
} else {
|
2016-07-11 14:28:22 +00:00
|
|
|
for (i = 0; i < argc; i++)
|
|
|
|
cb(argv[i]);
|
2016-07-10 18:27:27 +00:00
|
|
|
}
|
|
|
|
|
2016-07-11 14:28:22 +00:00
|
|
|
return i;
|
2016-07-10 18:27:27 +00:00
|
|
|
}
|
2016-07-11 19:50:04 +00:00
|
|
|
|
2016-07-13 13:52:39 +00:00
|
|
|
struct message *
|
|
|
|
blaze822_file(char *file)
|
2016-07-13 13:01:38 +00:00
|
|
|
{
|
|
|
|
int fd = open(file, O_RDONLY);
|
|
|
|
if (fd < 0)
|
2016-07-13 14:03:16 +00:00
|
|
|
return 0;
|
2016-07-13 13:01:38 +00:00
|
|
|
|
|
|
|
struct stat st;
|
|
|
|
if (fstat(fd, &st) < 0)
|
|
|
|
goto error;
|
|
|
|
|
2016-07-13 13:52:39 +00:00
|
|
|
size_t s = st.st_size;
|
2016-07-13 13:01:38 +00:00
|
|
|
|
2016-07-13 13:52:39 +00:00
|
|
|
char *buf = malloc(s+1);
|
|
|
|
if (read(fd, buf, s) < 0) {
|
2016-07-13 13:01:38 +00:00
|
|
|
// XXX handle short reads?
|
|
|
|
perror("read");
|
|
|
|
goto error;
|
|
|
|
}
|
2016-07-13 13:52:39 +00:00
|
|
|
close(fd);
|
2016-07-13 13:01:38 +00:00
|
|
|
|
2016-07-13 13:52:39 +00:00
|
|
|
buf[s] = 0;
|
2016-07-13 13:01:38 +00:00
|
|
|
|
2016-07-13 13:52:39 +00:00
|
|
|
// XXX duplicate header in ram...
|
|
|
|
struct message *mesg = blaze822_mem(buf, s);
|
|
|
|
if (mesg)
|
|
|
|
mesg->bodychunk = buf;
|
|
|
|
return mesg;
|
2016-07-13 13:01:38 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
close(fd);
|
2016-07-13 13:52:39 +00:00
|
|
|
return 0;
|
2016-07-13 13:01:38 +00:00
|
|
|
}
|
|
|
|
|
2016-07-13 13:52:39 +00:00
|
|
|
char *
|
|
|
|
blaze822_body(struct message *mesg)
|
|
|
|
{
|
|
|
|
return mesg->body;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
|
|
|
blaze822_bodylen(struct message *mesg)
|
|
|
|
{
|
|
|
|
if (!mesg->body || !mesg->bodyend)
|
|
|
|
return 0;
|
|
|
|
return mesg->bodyend - mesg->body;
|
|
|
|
}
|