* All Rights Reserved, for now.
*/
+#include <stdlib.h>
#include <string.h>
-#include "decoders.h"
+#include "msgproc.h"
-struct qp_state *
-qp_start(struct qp_state *qps)
+struct qp_state {
+ unsigned char c;
+ int state;
+};
+
+static void
+quoted_start(msgproc *m)
{
- bzero(qps, sizeof(*qps));
- return qps;
+ struct qp_state *qps = malloc(sizeof(struct qp_state));
+ if (qps) {
+ bzero(qps, sizeof(*qps));
+ }
+ msgproc_setpriv(m, qps);
}
-void
-qp_stop(struct qp_state *qps)
+static void
+quoted_finish(msgproc *m)
{
- qp_start(qps);
+ struct qp_state *qps = msgproc_getpriv(m);
+ if (qps) free(qps);
+ msgproc_free(m);
}
static inline char
return -1;
}
-int
+static int
qp_decode(struct qp_state *qps, char *s, int len,
char *out, int size, int *olen)
{
return ret;
}
-#ifdef _UNIT_TEST
-#include <unistd.h>
-char *chunks[] = {
- "the quick=20brown=\r",
- "\nfox=3d jumped over\r\n",
- 0
-};
-int main(void) {
- struct qp_state qps;
- char out[80];
- int ret, off = 0, outinc;
- char **c;
+static void
+quoted_process(msgproc *m, char *buf, size_t len)
+{
+ char tmp[2048];
+ int tmplen, ret;
+ struct qp_state *qps = (struct qp_state *)msgproc_getpriv(m);
+ msgproc *next = msgproc_next(m);
- qp_start(&qps);
- for (c=chunks; *c; c++) {
- ret = qp_decode(&qps, *c, strlen(*c), out + off, sizeof(out) - off, &outinc);
- off += outinc;
+ while (len > 0) {
+ ret = qp_decode(qps, buf, len, tmp, sizeof(tmp), &tmplen);
+ if (ret < 1) {
+ /* TODO: handle errors */
+ }
+ msgproc_process(next, tmp, tmplen);
+ buf += ret; len -= ret;
}
-
- write(1,out,off);
- return 0;
}
-#endif
+
+msgproc_module msgproc_quoted = {
+ MSGPROC_QUOTED_PRINTABLE, /* type */
+ NULL, /* module init */
+ NULL, /* set module parameter */
+ quoted_start, /* start module instance */
+ NULL, /* set module instance parameter */
+ quoted_process, /* process data */
+ quoted_finish, /* shut down, free module instance */
+ NULL /* shut down, free module */
+};