1 |
edhill |
1.1 |
/* |
2 |
|
|
* Read MIME body-part, stopping on boundaries. |
3 |
|
|
*/ |
4 |
|
|
/* (C) Copyright 1994 by Carnegie Mellon University |
5 |
|
|
* All Rights Reserved. |
6 |
|
|
* |
7 |
|
|
* Permission to use, copy, modify, distribute, and sell this software |
8 |
|
|
* and its documentation for any purpose is hereby granted without |
9 |
|
|
* fee, provided that the above copyright notice appear in all copies |
10 |
|
|
* and that both that copyright notice and this permission notice |
11 |
|
|
* appear in supporting documentation, and that the name of Carnegie |
12 |
|
|
* Mellon University not be used in advertising or publicity |
13 |
|
|
* pertaining to distribution of the software without specific, |
14 |
|
|
* written prior permission. Carnegie Mellon University makes no |
15 |
|
|
* representations about the suitability of this software for any |
16 |
|
|
* purpose. It is provided "as is" without express or implied |
17 |
|
|
* warranty. |
18 |
|
|
* |
19 |
|
|
* CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO |
20 |
|
|
* THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY |
21 |
|
|
* AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE |
22 |
|
|
* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
23 |
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN |
24 |
|
|
* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING |
25 |
|
|
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS |
26 |
|
|
* SOFTWARE. |
27 |
|
|
*/ |
28 |
|
|
|
29 |
|
|
/* Max length of a MIME "boundary", per RFC 1521 */ |
30 |
|
|
#define PART_MAX_BOUNDARY_LEN 70 |
31 |
|
|
|
32 |
|
|
/* Structure describing an input file from which we read MIME */ |
33 |
|
|
struct part { |
34 |
|
|
/* Input file */ |
35 |
|
|
FILE *infile; |
36 |
|
|
|
37 |
|
|
/* Input buffer */ |
38 |
|
|
unsigned char *buf; |
39 |
|
|
int buf_alloc; |
40 |
|
|
unsigned char *ptr; |
41 |
|
|
int cnt; |
42 |
|
|
|
43 |
|
|
/* Boundary information */ |
44 |
|
|
char (*boundary)[PART_MAX_BOUNDARY_LEN+1]; |
45 |
|
|
int *boundary_length; |
46 |
|
|
int boundary_alloc; |
47 |
|
|
int boundary_num; |
48 |
|
|
int boundary_seen; /* Index of boundary last seen, or |
49 |
|
|
* boundary_num if no pending boundary |
50 |
|
|
*/ |
51 |
|
|
}; |
52 |
|
|
|
53 |
|
|
#define part_getc(s) (((s)->cnt-- > 0 && (s)->ptr[0] != '\n') ? (int)*(s)->ptr++ : part_fill(s)) |
54 |
|
|
|
55 |
|
|
#define part_ungetc(c, s) ((s)->cnt++, ((s)->boundary_seen = (s)->boundary_num), (*--(s)->ptr = (c))) |
56 |
|
|
|
57 |
|
|
extern struct part *part_init(FILE *infile); |
58 |
|
|
extern char *part_gets(char *s, int n, struct part *part); |
59 |
|
|
|