4 * This is a really bad attempt at writing a parser to handle multipart
5 * messages -- in the case of WebCit, a form containing uploaded files.
12 #include <sys/types.h>
19 * Take a part, figure out its length, and do something with it
21 void process_part(char *content, int part_length) {
25 fprintf(stderr, "MIME: process_part() called with a length o' %d\n",
33 * Main function of parser
35 void mime_parser(char *content, int ContentLength, char *ContentType) {
38 int have_boundary = 0;
42 int bytes_processed = 0;
45 fprintf(stderr, "MIME: ContentLength: %d, ContentType: %s\n",
46 ContentLength, ContentType);
48 /* Figure out what the boundary is */
49 strcpy(boundary, ContentType);
50 for (a=0; a<strlen(boundary); ++a) {
51 if (!strncasecmp(&boundary[a], "boundary=", 9)) {
52 strcpy(boundary, &boundary[a+10]);
55 if ((boundary[a]==13) || (boundary[a]==10)) {
60 /* We can't process multipart messages without a boundary. */
61 if (have_boundary == 0) return;
62 strcpy(endary, boundary);
67 /* Seek to the beginning of the next boundary */
68 while ( (bytes_processed < ContentLength)
69 && (strncasecmp(ptr, boundary, strlen(boundary))) ) {
73 /* See if we're at the end */
74 if (!strncasecmp(ptr, endary, strlen(endary))) {
75 fprintf(stderr, "MIME: the end.\n");
79 /* Seek to the end of the boundary string */
80 if (!strncasecmp(ptr, boundary, strlen(boundary))) {
81 fprintf(stderr, "MIME: founda bounda\n");
82 while ( (bytes_processed < ContentLength)
83 && (strncasecmp(ptr, "\n", 1)) ) {
89 while ( (bytes_processed < ContentLength)
90 && (strncasecmp(ptr, boundary, strlen(boundary))) ) {
95 process_part(beginning, part_length);
96 /* Back off so we can see the next boundary */