From 3f33ba22de670980b326de744061ab3dc8dc09da Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Thu, 14 Jan 1999 22:15:02 +0000 Subject: [PATCH] * Modified the back end of mime_parser to use callbacks instead of doing something specific. Now we can use it elsewhere. --- webcit/ChangeLog | 4 +++ webcit/Makefile.in | 2 +- webcit/child.h | 2 -- webcit/mime_parser.c | 65 ++++++++++++++++++++++++++++++-------------- webcit/mime_parser.h | 35 ++++++++++++++++++++++++ webcit/webcit.c | 24 +++++++++++++++- 6 files changed, 107 insertions(+), 25 deletions(-) create mode 100644 webcit/mime_parser.h diff --git a/webcit/ChangeLog b/webcit/ChangeLog index 28e8b3f1c..9d7087f25 100644 --- a/webcit/ChangeLog +++ b/webcit/ChangeLog @@ -1,3 +1,7 @@ +Thu Jan 14 17:14:11 EST 1999 Art Cancro + * Modified the back end of mime_parser to use callbacks instead of + doing something specific. Now we can use it elsewhere. + Mon Jan 11 21:53:16 EST 1999 Art Cancro * Fixed the bugs in "Site-wide configuration" * Added a "generic server commands" screen diff --git a/webcit/Makefile.in b/webcit/Makefile.in index bf646162c..a26260b9f 100644 --- a/webcit/Makefile.in +++ b/webcit/Makefile.in @@ -81,7 +81,7 @@ paging.o: paging.c webcit.h child.h sysmsgs.o: sysmsgs.c webcit.h child.h $(CC) $(CFLAGS) $(DEFS) -c sysmsgs.c -mime_parser.o: mime_parser.c webcit.h child.h +mime_parser.o: mime_parser.c webcit.h child.h mime_parser.h $(CC) $(CFLAGS) $(DEFS) -c mime_parser.c cookie_conversion.o: cookie_conversion.c webcit.h child.h diff --git a/webcit/child.h b/webcit/child.h index 043afb697..3e0f84014 100644 --- a/webcit/child.h +++ b/webcit/child.h @@ -71,8 +71,6 @@ void gotoroom(char *gname, int display_name); void confirm_delete_room(void); void delete_room(void); void validate(void); -void mime_parser(char *, int, char *); -void handle_multipart(char *, int, char *); void display_graphics_upload(char *, char *, char *); void do_graphics_upload(char *upl_cmd); void serv_read(char *buf, int bytes); diff --git a/webcit/mime_parser.c b/webcit/mime_parser.c index 5e4a0aead..f9dfee605 100644 --- a/webcit/mime_parser.c +++ b/webcit/mime_parser.c @@ -12,6 +12,7 @@ #include #include #include +#include "mime_parser.h" #include "webcit.h" #include "child.h" @@ -40,8 +41,17 @@ void extract_key(char *target, char *source, char *key) { * The very back end for the component handler * (This function expects to be fed CONTENT ONLY, no headers) */ -void do_something_with_it(char *content, int length, char *content_type, - char *content_disposition) { +void do_something_with_it(char *content, + int length, + char *content_type, + char *content_disposition, + void (*CallBack) + (char *cbname, + char *cbfilename, + char *cbencoding, + void *cbcontent, + size_t cblength) + ) { char name[256]; char filename[256]; @@ -50,22 +60,14 @@ void do_something_with_it(char *content, int length, char *content_type, /* Nested multipart gets recursively fed back into the parser */ if (!strncasecmp(content_type, "multipart", 9)) { - mime_parser(content, length, content_type); + mime_parser(content, length, content_type, CallBack); } - /**** OTHERWISE, HERE'S WHERE WE HANDLE THE STUFF!! **** - * Later we'll want to do this with a callback. We'll also want to - * handle content-transfer-encoding before passing control to callback - * functions. For now, though ... it's just a hardcoded WebCit tie-in. - */ - - else if (strlen(name)>0) { - upload = malloc(length); - if (upload != NULL) { - upload_length = length; - memcpy(upload, content, length); - } - } + /**** OTHERWISE, HERE'S WHERE WE HANDLE THE STUFF!! *****/ + + CallBack(name, filename, "", content, length); + + /**** END OF STUFF-HANDLER ****/ } @@ -74,7 +76,16 @@ void do_something_with_it(char *content, int length, char *content_type, * Take a part, figure out its length, and do something with it * (This function expects to be fed HEADERS+CONTENT) */ -void handle_part(char *content, int part_length, char *supplied_content_type) { +void handle_part(char *content, + int part_length, + char *supplied_content_type, + void (*CallBack) + (char *cbname, + char *cbfilename, + char *cbencoding, + void *cbcontent, + size_t cblength) + ) { char content_type[256]; char content_disposition[256]; char *start; @@ -121,7 +132,7 @@ void handle_part(char *content, int part_length, char *supplied_content_type) { /* Now that we've got this component isolated, what to do with it? */ do_something_with_it(start, actual_length, - content_type, content_disposition); + content_type, content_disposition, CallBack); } @@ -130,7 +141,18 @@ void handle_part(char *content, int part_length, char *supplied_content_type) { * Break out the components of a multipart message * (This function expects to be fed CONTENT ONLY, no headers) */ -void mime_parser(char *content, int ContentLength, char *ContentType) { + + +void mime_parser(char *content, + int ContentLength, + char *ContentType, + void (*CallBack) + (char *cbname, + char *cbfilename, + char *cbencoding, + void *cbcontent, + size_t cblength) + ) { char boundary[256]; char endary[256]; int have_boundary = 0; @@ -142,7 +164,8 @@ void mime_parser(char *content, int ContentLength, char *ContentType) { /* If it's not multipart, don't process it as multipart */ if (strncasecmp(ContentType, "multipart", 9)) { - do_something_with_it(content, ContentLength, ContentType, ""); + do_something_with_it(content, ContentLength, + ContentType, "", CallBack); return; } @@ -197,7 +220,7 @@ void mime_parser(char *content, int ContentLength, char *ContentType) { ++bytes_processed; ++part_length; } - handle_part(beginning, part_length, ""); + handle_part(beginning, part_length, "", CallBack); /* Back off so we can see the next boundary */ --ptr; --bytes_processed; diff --git a/webcit/mime_parser.h b/webcit/mime_parser.h new file mode 100644 index 000000000..579e01a02 --- /dev/null +++ b/webcit/mime_parser.h @@ -0,0 +1,35 @@ +void extract_key(char *target, char *source, char *key); + +void do_something_with_it(char *content, + int length, + char *content_type, + char *content_disposition, + void (*CallBack) + (char *cbname, + char *cbfilename, + char *cbencoding, + void *cbcontent, + size_t cblength) + ); + +void handle_part(char *content, + int part_length, + char *supplied_content_type, + void (*CallBack) + (char *cbname, + char *cbfilename, + char *cbencoding, + void *cbcontent, + size_t cblength) + ); + +void mime_parser(char *content, + int ContentLength, + char *ContentType, + void (*CallBack) + (char *cbname, + char *cbfilename, + char *cbencoding, + void *cbcontent, + size_t cblength) + ); diff --git a/webcit/webcit.c b/webcit/webcit.c index 047be7eda..8efab2467 100644 --- a/webcit/webcit.c +++ b/webcit/webcit.c @@ -20,6 +20,7 @@ #include #include "webcit.h" #include "child.h" +#include "mime_parser.h" int wc_session; char wc_username[256]; @@ -459,6 +460,26 @@ void extract_action(char *actbuf, char *cmdbuf) { } +void upload_handler(char *name, char *filename, char *encoding, + void *content, size_t length) { + + fprintf(stderr, "UPLOAD HANDLER CALLED\n"); + fprintf(stderr, " name = %s\n", name); + fprintf(stderr, "filename = %s\n", filename); + fprintf(stderr, "encoding = %s\n", encoding); + fprintf(stderr, " length = %d\n", length); + + if (strlen(name)>0) { + upload = malloc(length); + if (upload != NULL) { + upload_length = length; + memcpy(upload, content, length); + } + } + + } + + void session_loop(void) { char cmd[256]; char action[256]; @@ -520,7 +541,8 @@ void session_loop(void) { addurls(content); } else if (!strncasecmp(ContentType, "multipart", 9)) { - mime_parser(content, ContentLength, ContentType); + mime_parser(content, ContentLength, ContentType, + *upload_handler); } } else { -- 2.39.2