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

  ViewVC Help
Powered by ViewVC 1.1.5