#include <sys/types.h>
#include <ctype.h>
#include <string.h>
+#include "mime_parser.h"
#include "webcit.h"
#include "child.h"
* 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];
/* 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 ****/
}
* 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;
/* 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);
}
* 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;
/* 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;
}
++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;
#include <stdarg.h>
#include "webcit.h"
#include "child.h"
+#include "mime_parser.h"
int wc_session;
char wc_username[256];
}
+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];
addurls(content);
}
else if (!strncasecmp(ContentType, "multipart", 9)) {
- mime_parser(content, ContentLength, ContentType);
+ mime_parser(content, ContentLength, ContentType,
+ *upload_handler);
}
}
else {