mess822x 1.23
mess822x
Loading...
Searching...
No Matches
mess822_line.c
Go to the documentation of this file.
1#include "mess822.h"
2#include "case.h"
3#include "str.h"
4
6{
7 h->action = a;
8
9 for (;;) {
10 if (a->value) if (!stralloc_copys(a->value,"")) return 0;
11 if (a->copy) if (!stralloc_copys(a->copy,"")) return 0;
12 if (a->flag) *a->flag = 0;
13 if (a->addr) if (!stralloc_copys(a->addr,"")) return 0;
14 if (a->when) a->when->known = 0;
15
16 if (!a->name) break;
17 ++a;
18 }
19
20 return stralloc_copys(&h->inprogress,"");
21}
22
23static stralloc addrlist = {0};
24static stralloc verbose = {0};
25
27{
29 int wsp, pos, i, j, colon = 0;
30 char ch;
31
32 if (!h->inprogress.len) return 1;
33
34 for (pos = 0; pos < h->inprogress.len; ++pos) {
35 ch = h->inprogress.s[pos];
36 if (ch == ':') {colon = pos; break; } // get first ':' delimitor; pay attention!
37 if (ch < 33) break;
38 if (ch > 126) break;
39 }
40
41 for (a = h->action; a->name; ++a) {
42 j = str_len(a->name);
43 if (!case_diffb(h->inprogress.s,j,a->name)) { // compare length of a->name, not pos of ':'
44 if (!stralloc_copyb(&verbose,h->inprogress.s,colon + 2)) return 0;
45 break;
46 }
47 }
48
49 for (; pos < h->inprogress.len; ++pos) {
50 ch = h->inprogress.s[pos];
51 if ((ch != ' ') && (ch != '\t')) break; // skip potentially included WSP
52 }
53
54 if (pos < h->inprogress.len) {
55 if (h->inprogress.s[pos] == ':') ++pos;
56 if (h->inprogress.s[pos] == ' ') ++pos;
57 }
58
59 /* XXX: allocate all necessary memory before doing anything? */
60
61 if (a->flag)
62 *a->flag = 1;
63
64 if (a->copy)
65 if (!stralloc_cat(a->copy,&h->inprogress)) return 0;
66
67 j = 0;
68 wsp = 0;
69 for (i = pos; i < h->inprogress.len; ++i) { // potentially included \0s
70 ch = h->inprogress.s[i];
71 if (ch == '\r') continue;
72 if (wsp && (ch == ' ' || ch == '\t')) continue;
73 wsp = (ch == ' ' || ch == '\t') ? 1 : 0;
74 if (ch != '\n') {
75 if (!ch) ch = '\n';
76 h->inprogress.s[j++] = ch;
77 }
78 }
79
80 h->inprogress.len = j; // final output len w/o counted \0; done
81 if (!stralloc_0(&h->inprogress)) return 0;
82
83 if (a->value) {
84 if (a->verbose)
85 if (!stralloc_catb(a->value,verbose.s,colon + 2)) return 0;
86 for (i = 0; ch = h->inprogress.s[i]; ++i) {
87 if (ch == '\n') ch = 0;
88 if (!stralloc_append(a->value,&ch)) return 0;
89 }
90 if (!stralloc_append(a->value,"\n")) return 0;
91 }
92
93 /* XXX: tokenize once for both addr and when? */
94
95 if (a->addr) {
96 if (!mess822_addrlist(&addrlist,h->inprogress.s)) return 0;
97 if (!stralloc_cat(a->addr,&addrlist)) return 0;
98 }
99
100 if (a->when)
101 if (!mess822_when(a->when,h->inprogress.s)) return 0;
102
103 h->inprogress.len = 0;
104 return 1;
105}
106
108{
109 if (!s->len) return 1;
110
111 if ((s->s[0] == ' ') || (s->s[0] == '\t')) // WSP => header line is progressing
112 return stralloc_cat(&h->inprogress,s);
113 if (!mess822_end(h)) return 0;
114
115 return stralloc_copy(&h->inprogress,s);
116}
int mess822_begin(mess822_header *h, mess822_action *a)
Definition: mess822_line.c:5
int mess822_end(mess822_header *h)
Definition: mess822_line.c:26
int mess822_line(mess822_header *h, stralloc *s)
Definition: mess822_line.c:107
mess822_action a[]
Definition: 822date.c:25
mess822_header h
Definition: 822date.c:24
int verbose
Definition: 822mimeparts.c:21
stralloc addrlist
Definition: addrlist.c:28
int mess822_when(mess822_time *, char *)
Definition: mess822_when.c:9
int mess822_addrlist(stralloc *, char *)
Definition: mess822_addr.c:119
int known
Definition: mess822.h:9
int * flag
Definition: mess822.h:14
char * name
Definition: mess822.h:13
mess822_time * when
Definition: mess822.h:18
stralloc * copy
Definition: mess822.h:15
stralloc * value
Definition: mess822.h:16
stralloc * addr
Definition: mess822.h:17
mess822_action * action
Definition: mess822.h:24
stralloc inprogress
Definition: mess822.h:23