* Modified the back end of mime_parser to use callbacks instead of
authorArt Cancro <ajc@citadel.org>
Thu, 14 Jan 1999 22:15:02 +0000 (22:15 +0000)
committerArt Cancro <ajc@citadel.org>
Thu, 14 Jan 1999 22:15:02 +0000 (22:15 +0000)
          doing something specific.  Now we can use it elsewhere.

webcit/ChangeLog
webcit/Makefile.in
webcit/child.h
webcit/mime_parser.c
webcit/mime_parser.h [new file with mode: 0644]
webcit/webcit.c

index 28e8b3f1c01b266aa0a268b9eade1074e4ca6fd1..9d7087f251c7ba30020a13871a1138d72491678c 100644 (file)
@@ -1,3 +1,7 @@
+Thu Jan 14 17:14:11 EST 1999 Art Cancro <ajc@uncnsrd.mt-kisco.ny.us>
+       * 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 <ajc@uncnsrd.mt-kisco.ny.us>
        * Fixed the bugs in "Site-wide configuration"
        * Added a "generic server commands" screen
index bf646162c7e82dc2bcf689e1ca10366b417b173f..a26260b9f11e50eb259e9636e987b5b609011297 100644 (file)
@@ -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
index 043afb69702b4933287f014d523fd27be286c136..3e0f840149f86b39c4726ccb1f60398e2604c56b 100644 (file)
@@ -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);
index 5e4a0aeadb1ffd0b36173797004ed1dff29f8cf4..f9dfee6050b60652a3f0dbb962c72507ce3e2853 100644 (file)
@@ -12,6 +12,7 @@
 #include <sys/types.h>
 #include <ctype.h>
 #include <string.h>
+#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 (file)
index 0000000..579e01a
--- /dev/null
@@ -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)
+               );
index 047be7edaf0862d8fc314faf6d3626e6cafa2dfe..8efab2467d95feaa1ffd904499c319318d863c5f 100644 (file)
@@ -20,6 +20,7 @@
 #include <stdarg.h>
 #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 {