int parseMultipartFormData()

in src/generic/formdata.c [203:260]


int parseMultipartFormData(RequestData * requestData, Tcl_Interp * interp,
			   char *channelName, char *content_type)
{

    Tcl_Channel channel;
    int mode;
    char *boundary = mimeGetParamFromContDisp(content_type, "boundary");
    int res = 0;
    Tcl_DString translation;
    Tcl_DString encoding;

/*   printf("DBG parseMultipartFormData - starting\n"); fflush(stdout); */

    if (boundary == NULL) {
	LOG_MSG(interp, WRITE_LOG, __FILE__, __LINE__,
		"web::dispatch -postdata", WEBLOG_WARNING,
		"error accessing boundary from\"", content_type, "\"", NULL);
	return TCL_ERROR;
    }

    channel = Web_GetChannelOrVarChannel(interp, channelName, &mode);
    if (channel == NULL) {
	LOG_MSG(interp, WRITE_LOG, __FILE__, __LINE__,
		"web::dispatch -postdata", WEBLOG_WARNING,
		"error getting channel \"", channelName, "\"", NULL);
	WebFreeIfNotNull(boundary);
	return TCL_ERROR;
    }

    if ((mode & TCL_READABLE) == 0) {
	LOG_MSG(interp, WRITE_LOG, __FILE__, __LINE__,
		"web::dispatch -postdata", WEBLOG_WARNING,
		"channel \"", channelName, "\" not open for reading", NULL);

	/* unregister if was a varchannel */
	Web_UnregisterVarChannel(interp, channelName, channel);
	WebFreeIfNotNull(boundary);
	return TCL_ERROR;
    }

    Tcl_DStringInit(&translation);
    Tcl_DStringInit(&encoding);
    Tcl_GetChannelOption(interp, channel, "-translation", &translation);
    Tcl_GetChannelOption(interp, channel, "-encoding", &encoding);
    Tcl_SetChannelOption(interp, channel, "-translation", "binary");

    res = mimeSplitMultipart(interp, channel, boundary, requestData);

    Tcl_SetChannelOption(interp, channel, "-translation", Tcl_DStringValue(&translation));
    Tcl_SetChannelOption(interp, channel, "-encoding", Tcl_DStringValue(&encoding));
    Tcl_DStringFree(&translation);
    Tcl_DStringFree(&encoding);
    /* unregister if was a varchannel */
    Web_UnregisterVarChannel(interp, channelName, channel);

    WebFreeIfNotNull(boundary);
    return res;
}