Mercurial > masqmail
annotate src/header.c @ 302:2ffcd38ccf53
improved unused function header_fold()
author | markus schnalke <meillo@marmaro.de> |
---|---|
date | Thu, 09 Dec 2010 17:50:25 -0300 |
parents | 55c530a83d51 |
children | 3e3c280ca5b2 |
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 | |
131 #define MAX_HDR_LEN 72 | |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
132 void |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
133 header_fold(header * hdr) |
0 | 134 { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
135 gint len = strlen(hdr->header); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
136 gchar *p, *q; |
301 | 137 gchar *tmp_hdr; |
138 int valueoffset; | |
139 | |
140 if (len < MAX_HDR_LEN) { | |
141 /* we don't need to do anything */ | |
142 return; | |
143 } | |
144 | |
145 /* the position in hdr->header where the value part starts */ | |
146 valueoffset = hdr->value - hdr->header; | |
147 | |
148 /* TODO: size is only calculated roughly */ | |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
149 /* size is probably overestimated, but so we are on the safe side */ |
301 | 150 /* (as much as we already have + chars inserted per break * number |
151 of breaks + some more) */ | |
152 tmp_hdr = g_malloc(len + 2 * (len/MAX_HDR_LEN) + 10); | |
0 | 153 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
154 p = hdr->header; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
155 q = tmp_hdr; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
156 |
301 | 157 if (p[len - 1] == '\n') { |
15 | 158 p[len - 1] = '\0'; |
301 | 159 } |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
160 |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
161 while (*p) { |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
162 gint i, l; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
163 gchar *pp; |
0 | 164 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
165 /* look forward and find potential break points */ |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
166 i = 0; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
167 l = -1; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
168 pp = p; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
169 while (*pp && (i < MAX_HDR_LEN)) { |
301 | 170 if ((*pp == ' ') || (*pp == '\t')) { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
171 l = i; |
301 | 172 } |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
173 pp++; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
174 i++; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
175 } |
301 | 176 if (!*pp) { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
177 l = pp - p; /* take rest, if EOS found */ |
301 | 178 } |
0 | 179 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
180 if (l == -1) { |
301 | 181 /* no potential break point was found within |
182 MAX_HDR_LEN so advance further until the next */ | |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
183 while (*pp && *pp != ' ' && *pp != '\t') { |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
184 pp++; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
185 i++; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
186 } |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
187 l = i; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
188 } |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
189 |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
190 /* copy */ |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
191 i = 0; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
192 while (i < l) { |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
193 *(q++) = *(p++); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
194 i++; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
195 } |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
196 *(q++) = '\n'; |
15 | 197 *(q++) = *(p++); /* this is either space, tab or 0 */ |
301 | 198 /* *(q++) = '\t'; */ |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
199 } |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
200 |
301 | 201 g_free(hdr->header); |
202 hdr->header = tmp_hdr; | |
203 hdr->value = hdr->header + valueoffset; | |
0 | 204 } |
205 | |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
206 header* |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
207 create_header(header_id id, gchar * fmt, ...) |
0 | 208 { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
209 gchar *p; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
210 header *hdr; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
211 va_list args; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
212 va_start(args, fmt); |
0 | 213 |
301 | 214 /* g_malloc() calls exit on failure */ |
215 hdr = g_malloc(sizeof(header)); | |
0 | 216 |
301 | 217 hdr->id = id; |
218 hdr->header = g_strdup_vprintf(fmt, args); | |
219 hdr->value = NULL; | |
0 | 220 |
301 | 221 /* value shall point to the first non-whitespace char in the |
222 value part of the header line (i.e. after the first colon) */ | |
223 p = strchr(hdr->header, ':'); | |
224 if (p) { | |
225 p++; | |
226 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
|
227 p++; |
301 | 228 } |
229 hdr->value = (*p) ? p : NULL; | |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
230 } |
0 | 231 |
301 | 232 DEBUG(3) debugf("create_header(): hdr: `%s'\n", hdr->header); |
233 DEBUG(3) debugf("create_header(): val: `%s'\n", hdr->value); | |
234 | |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
235 va_end(args); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
236 return hdr; |
0 | 237 } |
238 | |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
239 void |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
240 destroy_header(header * hdr) |
0 | 241 { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
242 if (hdr) { |
301 | 243 if (hdr->header) { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
244 g_free(hdr->header); |
301 | 245 } |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
246 g_free(hdr); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
247 } |
0 | 248 } |
249 | |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
250 header* |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
251 copy_header(header * hdr) |
0 | 252 { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
253 header *new_hdr = NULL; |
0 | 254 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
255 if (hdr) { |
301 | 256 new_hdr = g_malloc(sizeof(header)); |
257 new_hdr->id = hdr->id; | |
258 new_hdr->header = g_strdup(hdr->header); | |
259 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
|
260 } |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
261 return new_hdr; |
0 | 262 } |
263 | |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
264 header* |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
265 get_header(gchar * line) |
0 | 266 { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
267 gchar *p = line; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
268 gchar buf[64], *q = buf; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
269 gint i; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
270 header *hdr; |
0 | 271 |
301 | 272 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
|
273 *(q++) = *(p++); |
301 | 274 } |
15 | 275 *q = '\0'; |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
276 |
301 | 277 if (*p != ':') { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
278 return NULL; |
301 | 279 } |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
280 |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
281 hdr = g_malloc(sizeof(header)); |
0 | 282 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
283 hdr->value = NULL; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
284 p++; |
0 | 285 |
301 | 286 while (*p && (*p == ' ' || *p == '\t')) { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
287 p++; |
301 | 288 } |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
289 hdr->value = p; |
301 | 290 /* Note: an empty value can also mean that it's only the first part |
291 of a folded header line */ | |
0 | 292 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
293 for (i = 0; i < HEAD_NUM_IDS; i++) { |
301 | 294 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
|
295 break; |
301 | 296 } |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
297 } |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
298 hdr->id = (header_id) i; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
299 hdr->header = g_strdup(line); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
300 hdr->value = hdr->header + (hdr->value - line); |
0 | 301 |
235
92063f90f9be
removed additional new lines at the end of debug messages
markus schnalke <meillo@marmaro.de>
parents:
208
diff
changeset
|
302 DEBUG(4) debugf("header: %d = %s", hdr->id, hdr->header); |
301 | 303 /* Note: This only outputs the first line if the header is folded */ |
0 | 304 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
305 return hdr; |
0 | 306 } |