/[d-i]/people/waldi/packages/cdebconf/src/rfc822.c
ViewVC logotype

Contents of /people/waldi/packages/cdebconf/src/rfc822.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 18435 - (show annotations) (download)
Sun Jul 25 16:35:08 2004 UTC (8 years, 10 months ago) by waldi
File MIME type: text/plain
File size: 2072 byte(s)
* .indent.pro: Add
* src/debconf.h: Remove obselete file.
* src: Reindent.
1 #include <stdio.h>
2 #include <ctype.h>
3
4 #include "common.h"
5 #include "rfc822.h"
6 #include "strutl.h"
7
8
9 static char *unescapestr (const char *in)
10 {
11 static char buf[8192];
12 if (in == 0)
13 return 0;
14 strunescape (in, buf, sizeof (buf), 0);
15 return buf;
16 }
17
18 /*
19 * Function: rfc822db_parse_stanza
20 * Input: a FILE pointer to an open readable file containing a stanza in rfc822
21 * format.
22 * Output: a pointer to a dynamically allocated rfc822_header structure
23 * Description: parse a stanza from file into the returned header struct
24 * Assumptions: no lines are over 8192 bytes long.
25 */
26
27 struct rfc822_header *rfc822_parse_stanza (FILE * file)
28 {
29 struct rfc822_header *head, **tail, *cur;
30 char buf[8192];
31
32 head = NULL;
33 tail = &head;
34 cur = NULL;
35
36 /* fprintf(stderr,"rfc822db_parse_stanza(file)\n"); */
37 while (fgets (buf, sizeof (buf), file))
38 {
39 char *tmp = buf;
40
41 if (*tmp == '\n')
42 break;
43
44 CHOMP (buf);
45
46 if (isspace (*tmp))
47 {
48 /* continuation line, just append it */
49 int len;
50
51 if (cur == NULL)
52 break; /* should report an error here */
53
54 len = strlen (cur->value) + strlen (tmp) + 2;
55
56 cur->value = realloc (cur->value, len);
57 strvacat (cur->value, len, "\n", tmp, NULL);
58 }
59 else
60 {
61 while (*tmp != 0 && *tmp != ':')
62 tmp++;
63 *tmp++ = '\0';
64
65 cur = NEW (struct rfc822_header);
66 if (cur == NULL)
67 return NULL;
68 memset (cur, '\0', sizeof (struct rfc822_header));
69
70 cur->header = strdup (buf);
71
72 while (isspace (*tmp))
73 tmp++;
74
75 cur->value = strdup (unescapestr (tmp));
76
77 *tail = cur;
78 tail = &cur->next;
79 }
80 }
81
82 return head;
83 }
84
85
86 char *rfc822_header_lookup (struct rfc822_header *list, const char *key)
87 {
88 /* fprintf(stderr,"rfc822db_header_lookup(list,key=%s)\n",key);*/
89 while (list && (strcasecmp (key, list->header) != 0))
90 list = list->next;
91 if (!list)
92 return NULL;
93 /* fprintf(stderr,"rfc822db_header_lookup returning: '%s'\n", list->value);*/
94 return list->value;
95 }

  ViewVC Help
Powered by ViewVC 1.1.5