Mercurial > masqmail
annotate src/header.c @ 338:75f4a5676808
updated ChangeLog and NEWS
author | markus schnalke <meillo@marmaro.de> |
---|---|
date | Wed, 31 Aug 2011 08:40:24 +0200 |
parents | 01d2f7a17bf0 |
children | 41958685480d |
rev | line source |
---|---|
0 | 1 /* MasqMail |
2 Copyright (C) 2000 Oliver Kurth | |
3 | |
4 This program is free software; you can redistribute it and/or modify | |
5 it under the terms of the GNU General Public License as published by | |
6 the Free Software Foundation; either version 2 of the License, or | |
7 (at your option) any later version. | |
8 | |
9 This program is distributed in the hope that it will be useful, | |
10 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 GNU General Public License for more details. | |
13 | |
14 You should have received a copy of the GNU General Public License | |
15 along with this program; if not, write to the Free Software | |
16 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
17 */ | |
18 #include "masqmail.h" | |
19 | |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
20 header_name header_names[] = { |
15 | 21 {"From", HEAD_FROM,}, |
22 {"Sender", HEAD_SENDER,}, | |
23 {"To", HEAD_TO,}, | |
24 {"Cc", HEAD_CC,}, | |
25 {"Bcc", HEAD_BCC,}, | |
26 {"Date", HEAD_DATE,}, | |
27 {"Message-Id", HEAD_MESSAGE_ID,}, | |
28 {"Reply-To", HEAD_REPLY_TO,}, | |
29 {"Subject", HEAD_SUBJECT,}, | |
30 {"Return-Path", HEAD_RETURN_PATH,}, | |
31 {"Envelope-To", HEAD_ENVELOPE_TO,}, | |
32 {"Received", HEAD_RECEIVED}, | |
0 | 33 }; |
34 | |
35 /* this was borrowed from exim and slightly changed */ | |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
36 gchar* |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
37 rec_timestamp() |
0 | 38 { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
39 static gchar buf[64]; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
40 int len; |
0 | 41 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
42 time_t now = time(NULL); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
43 struct tm *t = localtime(&now); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
44 |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
45 int diff_hour, diff_min; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
46 struct tm local; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
47 struct tm *gmt; |
0 | 48 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
49 memcpy(&local, t, sizeof(struct tm)); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
50 gmt = gmtime(&now); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
51 diff_min = 60 * (local.tm_hour - gmt->tm_hour) + local.tm_min - gmt->tm_min; |
301 | 52 if (local.tm_year != gmt->tm_year) { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
53 diff_min += (local.tm_year > gmt->tm_year) ? 1440 : -1440; |
301 | 54 } else if (local.tm_yday != gmt->tm_yday) { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
55 diff_min += (local.tm_yday > gmt->tm_yday) ? 1440 : -1440; |
301 | 56 } |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
57 diff_hour = diff_min / 60; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
58 diff_min = abs(diff_min - diff_hour * 60); |
0 | 59 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
60 len = strftime(buf, sizeof(buf), "%a, ", &local); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
61 g_snprintf(buf + len, sizeof(buf) - len, "%02d ", local.tm_mday); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
62 len += strlen(buf + len); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
63 len += strftime(buf + len, sizeof(buf) - len, "%b %Y %H:%M:%S", &local); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
64 g_snprintf(buf + len, sizeof(buf) - len, " %+03d%02d", diff_hour, diff_min); |
0 | 65 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
66 return buf; |
0 | 67 } |
68 | |
69 /* finds list of headers matching id | |
70 if id == HEAD_UNKNOWN and header == NULL finds all unknown headers | |
71 else finds all headers matching header | |
72 */ | |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
73 GList* |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
74 find_header(GList * hdr_list, header_id id, gchar * hdr_str) |
0 | 75 { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
76 GList *found_list = NULL; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
77 GList *node; |
0 | 78 |
301 | 79 if ((id != HEAD_UNKNOWN) || !hdr_str) { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
80 foreach(hdr_list, node) { |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
81 header *hdr = (header *) (node->data); |
301 | 82 if (hdr->id == id) { |
83 found_list = g_list_append(found_list, hdr); | |
84 } | |
85 } | |
86 return found_list; | |
87 } | |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
88 |
301 | 89 foreach(hdr_list, node) { |
90 header *hdr = (header *) (node->data); | |
91 gchar buf[64], *q = buf, *p = hdr->header; | |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
92 |
301 | 93 while (*p != ':' && q < buf+sizeof(buf)-1 && *p) { |
94 *(q++) = *(p++); | |
95 } | |
96 *q = '\0'; | |
97 | |
98 if (strcasecmp(buf, hdr_str) == 0) { | |
99 found_list = g_list_append(found_list, hdr); | |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
100 } |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
101 } |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
102 return found_list; |
0 | 103 } |
104 | |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
105 void |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
106 header_unfold(header * hdr) |
0 | 107 { |
302
2ffcd38ccf53
improved unused function header_fold()
markus schnalke <meillo@marmaro.de>
parents:
301
diff
changeset
|
108 char *src = hdr->header; |
2ffcd38ccf53
improved unused function header_fold()
markus schnalke <meillo@marmaro.de>
parents:
301
diff
changeset
|
109 char *dest = src; |
2ffcd38ccf53
improved unused function header_fold()
markus schnalke <meillo@marmaro.de>
parents:
301
diff
changeset
|
110 char *p; |
2ffcd38ccf53
improved unused function header_fold()
markus schnalke <meillo@marmaro.de>
parents:
301
diff
changeset
|
111 |
2ffcd38ccf53
improved unused function header_fold()
markus schnalke <meillo@marmaro.de>
parents:
301
diff
changeset
|
112 p = strchr(src, '\n'); |
2ffcd38ccf53
improved unused function header_fold()
markus schnalke <meillo@marmaro.de>
parents:
301
diff
changeset
|
113 if (!p || !p[1]) { |
2ffcd38ccf53
improved unused function header_fold()
markus schnalke <meillo@marmaro.de>
parents:
301
diff
changeset
|
114 /* no folded header */ |
2ffcd38ccf53
improved unused function header_fold()
markus schnalke <meillo@marmaro.de>
parents:
301
diff
changeset
|
115 return; |
2ffcd38ccf53
improved unused function header_fold()
markus schnalke <meillo@marmaro.de>
parents:
301
diff
changeset
|
116 } |
0 | 117 |
302
2ffcd38ccf53
improved unused function header_fold()
markus schnalke <meillo@marmaro.de>
parents:
301
diff
changeset
|
118 while (*src) { |
2ffcd38ccf53
improved unused function header_fold()
markus schnalke <meillo@marmaro.de>
parents:
301
diff
changeset
|
119 if (*src == '\n') { |
2ffcd38ccf53
improved unused function header_fold()
markus schnalke <meillo@marmaro.de>
parents:
301
diff
changeset
|
120 /* ignore */ |
2ffcd38ccf53
improved unused function header_fold()
markus schnalke <meillo@marmaro.de>
parents:
301
diff
changeset
|
121 src++; |
2ffcd38ccf53
improved unused function header_fold()
markus schnalke <meillo@marmaro.de>
parents:
301
diff
changeset
|
122 } else { |
2ffcd38ccf53
improved unused function header_fold()
markus schnalke <meillo@marmaro.de>
parents:
301
diff
changeset
|
123 /* copy */ |
2ffcd38ccf53
improved unused function header_fold()
markus schnalke <meillo@marmaro.de>
parents:
301
diff
changeset
|
124 *(dest++) = *(src++); |
2ffcd38ccf53
improved unused function header_fold()
markus schnalke <meillo@marmaro.de>
parents:
301
diff
changeset
|
125 } |
2ffcd38ccf53
improved unused function header_fold()
markus schnalke <meillo@marmaro.de>
parents:
301
diff
changeset
|
126 } |
2ffcd38ccf53
improved unused function header_fold()
markus schnalke <meillo@marmaro.de>
parents:
301
diff
changeset
|
127 *(dest++) = '\n'; |
2ffcd38ccf53
improved unused function header_fold()
markus schnalke <meillo@marmaro.de>
parents:
301
diff
changeset
|
128 *(dest++) = '\0'; |
0 | 129 } |
130 | |
303
3e3c280ca5b2
replaced header_fold() with a better implementation
markus schnalke <meillo@marmaro.de>
parents:
302
diff
changeset
|
131 /* |
3e3c280ca5b2
replaced header_fold() with a better implementation
markus schnalke <meillo@marmaro.de>
parents:
302
diff
changeset
|
132 fold the header at maxlen chars (newline excluded) |
3e3c280ca5b2
replaced header_fold() with a better implementation
markus schnalke <meillo@marmaro.de>
parents:
302
diff
changeset
|
133 (We exclude the newline because the RFCs deal with it this way) |
3e3c280ca5b2
replaced header_fold() with a better implementation
markus schnalke <meillo@marmaro.de>
parents:
302
diff
changeset
|
134 */ |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
135 void |
303
3e3c280ca5b2
replaced header_fold() with a better implementation
markus schnalke <meillo@marmaro.de>
parents:
302
diff
changeset
|
136 header_fold(header* hdr, unsigned int maxlen) |
0 | 137 { |
303
3e3c280ca5b2
replaced header_fold() with a better implementation
markus schnalke <meillo@marmaro.de>
parents:
302
diff
changeset
|
138 int len = strlen(hdr->header); |
3e3c280ca5b2
replaced header_fold() with a better implementation
markus schnalke <meillo@marmaro.de>
parents:
302
diff
changeset
|
139 char* src = hdr->header; |
3e3c280ca5b2
replaced header_fold() with a better implementation
markus schnalke <meillo@marmaro.de>
parents:
302
diff
changeset
|
140 char* dest; |
3e3c280ca5b2
replaced header_fold() with a better implementation
markus schnalke <meillo@marmaro.de>
parents:
302
diff
changeset
|
141 char* tmp; |
3e3c280ca5b2
replaced header_fold() with a better implementation
markus schnalke <meillo@marmaro.de>
parents:
302
diff
changeset
|
142 char* p; |
301 | 143 int valueoffset; |
144 | |
303
3e3c280ca5b2
replaced header_fold() with a better implementation
markus schnalke <meillo@marmaro.de>
parents:
302
diff
changeset
|
145 if (len <= maxlen) { |
301 | 146 /* we don't need to do anything */ |
147 return; | |
148 } | |
149 | |
303
3e3c280ca5b2
replaced header_fold() with a better implementation
markus schnalke <meillo@marmaro.de>
parents:
302
diff
changeset
|
150 /* strip trailing whitespace */ |
3e3c280ca5b2
replaced header_fold() with a better implementation
markus schnalke <meillo@marmaro.de>
parents:
302
diff
changeset
|
151 for (p=src+len-1; *p==' '||*p=='\t'||*p=='\n'; p--) { |
3e3c280ca5b2
replaced header_fold() with a better implementation
markus schnalke <meillo@marmaro.de>
parents:
302
diff
changeset
|
152 *p = '\0'; |
3e3c280ca5b2
replaced header_fold() with a better implementation
markus schnalke <meillo@marmaro.de>
parents:
302
diff
changeset
|
153 len--; |
3e3c280ca5b2
replaced header_fold() with a better implementation
markus schnalke <meillo@marmaro.de>
parents:
302
diff
changeset
|
154 printf(" trailing whitespace\n"); |
3e3c280ca5b2
replaced header_fold() with a better implementation
markus schnalke <meillo@marmaro.de>
parents:
302
diff
changeset
|
155 } |
3e3c280ca5b2
replaced header_fold() with a better implementation
markus schnalke <meillo@marmaro.de>
parents:
302
diff
changeset
|
156 printf("stripped len: %d\n", len); |
3e3c280ca5b2
replaced header_fold() with a better implementation
markus schnalke <meillo@marmaro.de>
parents:
302
diff
changeset
|
157 |
3e3c280ca5b2
replaced header_fold() with a better implementation
markus schnalke <meillo@marmaro.de>
parents:
302
diff
changeset
|
158 /* FIXME: would be nice to have a better size calculation */ |
3e3c280ca5b2
replaced header_fold() with a better implementation
markus schnalke <meillo@marmaro.de>
parents:
302
diff
changeset
|
159 /* (the current size + what we insert as break, twice as often as |
3e3c280ca5b2
replaced header_fold() with a better implementation
markus schnalke <meillo@marmaro.de>
parents:
302
diff
changeset
|
160 we have breaks in the optimal case) */ |
3e3c280ca5b2
replaced header_fold() with a better implementation
markus schnalke <meillo@marmaro.de>
parents:
302
diff
changeset
|
161 tmp = malloc(len + 2 * (len/maxlen) * strlen("\n\t")); |
3e3c280ca5b2
replaced header_fold() with a better implementation
markus schnalke <meillo@marmaro.de>
parents:
302
diff
changeset
|
162 dest = tmp; |
3e3c280ca5b2
replaced header_fold() with a better implementation
markus schnalke <meillo@marmaro.de>
parents:
302
diff
changeset
|
163 |
3e3c280ca5b2
replaced header_fold() with a better implementation
markus schnalke <meillo@marmaro.de>
parents:
302
diff
changeset
|
164 /* the position in hdr->header where the value part start */ |
301 | 165 valueoffset = hdr->value - hdr->header; |
166 | |
303
3e3c280ca5b2
replaced header_fold() with a better implementation
markus schnalke <meillo@marmaro.de>
parents:
302
diff
changeset
|
167 while (strlen(src) > maxlen) { |
3e3c280ca5b2
replaced header_fold() with a better implementation
markus schnalke <meillo@marmaro.de>
parents:
302
diff
changeset
|
168 int i, l; |
3e3c280ca5b2
replaced header_fold() with a better implementation
markus schnalke <meillo@marmaro.de>
parents:
302
diff
changeset
|
169 char *pp; |
0 | 170 |
303
3e3c280ca5b2
replaced header_fold() with a better implementation
markus schnalke <meillo@marmaro.de>
parents:
302
diff
changeset
|
171 for (pp=src+maxlen; pp>src; pp--) { |
3e3c280ca5b2
replaced header_fold() with a better implementation
markus schnalke <meillo@marmaro.de>
parents:
302
diff
changeset
|
172 if (*pp==' ' || *pp=='\t' || *p=='\n') { |
3e3c280ca5b2
replaced header_fold() with a better implementation
markus schnalke <meillo@marmaro.de>
parents:
302
diff
changeset
|
173 break; |
3e3c280ca5b2
replaced header_fold() with a better implementation
markus schnalke <meillo@marmaro.de>
parents:
302
diff
changeset
|
174 } |
3e3c280ca5b2
replaced header_fold() with a better implementation
markus schnalke <meillo@marmaro.de>
parents:
302
diff
changeset
|
175 } |
3e3c280ca5b2
replaced header_fold() with a better implementation
markus schnalke <meillo@marmaro.de>
parents:
302
diff
changeset
|
176 |
3e3c280ca5b2
replaced header_fold() with a better implementation
markus schnalke <meillo@marmaro.de>
parents:
302
diff
changeset
|
177 if (src == pp) { |
3e3c280ca5b2
replaced header_fold() with a better implementation
markus schnalke <meillo@marmaro.de>
parents:
302
diff
changeset
|
178 /* no potential break point was found within |
3e3c280ca5b2
replaced header_fold() with a better implementation
markus schnalke <meillo@marmaro.de>
parents:
302
diff
changeset
|
179 maxlen so advance further until the next */ |
3e3c280ca5b2
replaced header_fold() with a better implementation
markus schnalke <meillo@marmaro.de>
parents:
302
diff
changeset
|
180 for (pp=src+maxlen; *pp; pp++) { |
3e3c280ca5b2
replaced header_fold() with a better implementation
markus schnalke <meillo@marmaro.de>
parents:
302
diff
changeset
|
181 if (*pp==' ' || *pp=='\t' || *p=='\n') { |
3e3c280ca5b2
replaced header_fold() with a better implementation
markus schnalke <meillo@marmaro.de>
parents:
302
diff
changeset
|
182 break; |
3e3c280ca5b2
replaced header_fold() with a better implementation
markus schnalke <meillo@marmaro.de>
parents:
302
diff
changeset
|
183 } |
3e3c280ca5b2
replaced header_fold() with a better implementation
markus schnalke <meillo@marmaro.de>
parents:
302
diff
changeset
|
184 } |
3e3c280ca5b2
replaced header_fold() with a better implementation
markus schnalke <meillo@marmaro.de>
parents:
302
diff
changeset
|
185 } |
3e3c280ca5b2
replaced header_fold() with a better implementation
markus schnalke <meillo@marmaro.de>
parents:
302
diff
changeset
|
186 if (!*pp) { |
3e3c280ca5b2
replaced header_fold() with a better implementation
markus schnalke <meillo@marmaro.de>
parents:
302
diff
changeset
|
187 break; |
3e3c280ca5b2
replaced header_fold() with a better implementation
markus schnalke <meillo@marmaro.de>
parents:
302
diff
changeset
|
188 } |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
189 |
303
3e3c280ca5b2
replaced header_fold() with a better implementation
markus schnalke <meillo@marmaro.de>
parents:
302
diff
changeset
|
190 memcpy(dest, src, pp-src); |
3e3c280ca5b2
replaced header_fold() with a better implementation
markus schnalke <meillo@marmaro.de>
parents:
302
diff
changeset
|
191 dest += pp-src; |
3e3c280ca5b2
replaced header_fold() with a better implementation
markus schnalke <meillo@marmaro.de>
parents:
302
diff
changeset
|
192 *(dest++) = '\n'; |
3e3c280ca5b2
replaced header_fold() with a better implementation
markus schnalke <meillo@marmaro.de>
parents:
302
diff
changeset
|
193 *(dest++) = '\t'; |
3e3c280ca5b2
replaced header_fold() with a better implementation
markus schnalke <meillo@marmaro.de>
parents:
302
diff
changeset
|
194 while (*pp == ' ' || *pp == '\t' || *p=='\n') { |
3e3c280ca5b2
replaced header_fold() with a better implementation
markus schnalke <meillo@marmaro.de>
parents:
302
diff
changeset
|
195 pp++; |
3e3c280ca5b2
replaced header_fold() with a better implementation
markus schnalke <meillo@marmaro.de>
parents:
302
diff
changeset
|
196 } |
3e3c280ca5b2
replaced header_fold() with a better implementation
markus schnalke <meillo@marmaro.de>
parents:
302
diff
changeset
|
197 src = pp; |
3e3c280ca5b2
replaced header_fold() with a better implementation
markus schnalke <meillo@marmaro.de>
parents:
302
diff
changeset
|
198 } |
3e3c280ca5b2
replaced header_fold() with a better implementation
markus schnalke <meillo@marmaro.de>
parents:
302
diff
changeset
|
199 memcpy(dest, src, strlen(src)); |
3e3c280ca5b2
replaced header_fold() with a better implementation
markus schnalke <meillo@marmaro.de>
parents:
302
diff
changeset
|
200 dest += strlen(src); |
3e3c280ca5b2
replaced header_fold() with a better implementation
markus schnalke <meillo@marmaro.de>
parents:
302
diff
changeset
|
201 |
3e3c280ca5b2
replaced header_fold() with a better implementation
markus schnalke <meillo@marmaro.de>
parents:
302
diff
changeset
|
202 if (*(dest-1) != '\n') { |
3e3c280ca5b2
replaced header_fold() with a better implementation
markus schnalke <meillo@marmaro.de>
parents:
302
diff
changeset
|
203 *dest = '\n'; |
3e3c280ca5b2
replaced header_fold() with a better implementation
markus schnalke <meillo@marmaro.de>
parents:
302
diff
changeset
|
204 *(dest+1) = '\0'; |
301 | 205 } |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
206 |
303
3e3c280ca5b2
replaced header_fold() with a better implementation
markus schnalke <meillo@marmaro.de>
parents:
302
diff
changeset
|
207 hdr->header = tmp; |
301 | 208 hdr->value = hdr->header + valueoffset; |
0 | 209 } |
210 | |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
211 header* |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
212 create_header(header_id id, gchar * fmt, ...) |
0 | 213 { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
214 gchar *p; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
215 header *hdr; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
216 va_list args; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
217 va_start(args, fmt); |
0 | 218 |
301 | 219 /* g_malloc() calls exit on failure */ |
220 hdr = g_malloc(sizeof(header)); | |
0 | 221 |
301 | 222 hdr->id = id; |
223 hdr->header = g_strdup_vprintf(fmt, args); | |
224 hdr->value = NULL; | |
0 | 225 |
301 | 226 /* value shall point to the first non-whitespace char in the |
227 value part of the header line (i.e. after the first colon) */ | |
228 p = strchr(hdr->header, ':'); | |
229 if (p) { | |
230 p++; | |
231 while (*p == ' ' || *p == '\t' || *p == '\n') { | |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
232 p++; |
301 | 233 } |
234 hdr->value = (*p) ? p : NULL; | |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
235 } |
0 | 236 |
301 | 237 DEBUG(3) debugf("create_header(): hdr: `%s'\n", hdr->header); |
238 DEBUG(3) debugf("create_header(): val: `%s'\n", hdr->value); | |
239 | |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
240 va_end(args); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
241 return hdr; |
0 | 242 } |
243 | |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
244 void |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
245 destroy_header(header * hdr) |
0 | 246 { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
247 if (hdr) { |
301 | 248 if (hdr->header) { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
249 g_free(hdr->header); |
301 | 250 } |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
251 g_free(hdr); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
252 } |
0 | 253 } |
254 | |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
255 header* |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
256 copy_header(header * hdr) |
0 | 257 { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
258 header *new_hdr = NULL; |
0 | 259 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
260 if (hdr) { |
301 | 261 new_hdr = g_malloc(sizeof(header)); |
262 new_hdr->id = hdr->id; | |
263 new_hdr->header = g_strdup(hdr->header); | |
264 new_hdr->value = new_hdr->header + (hdr->value - hdr->header); | |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
265 } |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
266 return new_hdr; |
0 | 267 } |
268 | |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
269 header* |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
270 get_header(gchar * line) |
0 | 271 { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
272 gchar *p = line; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
273 gchar buf[64], *q = buf; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
274 gint i; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
275 header *hdr; |
0 | 276 |
301 | 277 while (*p && (*p != ':') && (q < buf+sizeof(buf)-1)) { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
278 *(q++) = *(p++); |
301 | 279 } |
15 | 280 *q = '\0'; |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
281 |
301 | 282 if (*p != ':') { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
283 return NULL; |
301 | 284 } |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
285 |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
286 hdr = g_malloc(sizeof(header)); |
0 | 287 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
288 hdr->value = NULL; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
289 p++; |
0 | 290 |
301 | 291 while (*p && (*p == ' ' || *p == '\t')) { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
292 p++; |
301 | 293 } |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
294 hdr->value = p; |
301 | 295 /* Note: an empty value can also mean that it's only the first part |
296 of a folded header line */ | |
0 | 297 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
298 for (i = 0; i < HEAD_NUM_IDS; i++) { |
301 | 299 if (strcasecmp(header_names[i].header, buf) == 0) { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
300 break; |
301 | 301 } |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
302 } |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
303 hdr->id = (header_id) i; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
304 hdr->header = g_strdup(line); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
305 hdr->value = hdr->header + (hdr->value - line); |
0 | 306 |
322
01d2f7a17bf0
hinted that the debug output of folded headers prints only the
meillo@marmaro.de
parents:
303
diff
changeset
|
307 DEBUG(4) debugf("header: %d = %s[...]", hdr->id, hdr->header); |
301 | 308 /* Note: This only outputs the first line if the header is folded */ |
0 | 309 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
310 return hdr; |
0 | 311 } |