Exemple #1
0
NEOERR* mcs_register_upload_parse_cb(CGI *cgi, void *rock)
{
    NEOERR *err;
    
    err = cgi_register_parse_cb(cgi, "POST", "application/x-www-form-urlencoded",
                                rock, mhttp_upload_parse_cb);
	if (err != STATUS_OK) return nerr_pass(err);

    err = cgi_register_parse_cb(cgi, "POST", "multipart/form-data",
                                rock, mhttp_upload_parse_cb);
	if (err != STATUS_OK) return nerr_pass(err);

    err = cgi_register_parse_cb(cgi, "PUT", "*", rock, mhttp_upload_parse_cb);
    return nerr_pass(err);
}
Exemple #2
0
CGI::CGI(bool process_body) : _GET(_request_queries)
                            , _POST(_request_posts)
                            , _COOKIE(_request_cookies)
                            , _SERVER(_server_variables)
                            , _REQUEST(_request_all)
                            , _FILES(_uploaded_files)
                            , BODY(this)
                            , _request_handled(false)
                            , _header_sent(false)
                            , _body_sent(false)
                            , _buffered(true)
                            , _status(200)
                            , _cgi_handle(NULL)
{
    void **cgiptr = &_cgi_handle;
    ::CGI * &cgi = *reinterpret_cast< ::CGI **>(cgiptr);
    NEOERR *err;

    TranslateEnvvars(&_server_variables);

    err = cgi_init(&cgi, NULL);
    ThrowIfNeoError(err);

    TranslateHDF(cgi, "Cookie", &_request_cookies);
    TranslateHDF(cgi, "Query",  &_request_queries);

    if (!process_body) {
        return;
    }

    err = cgi_register_parse_cb(cgi, "POST", "*", this, Parser::Parse);
    ThrowIfNeoError(err);

    // Purge Query subtree so GET values are gone.
    err = hdf_remove_tree(cgi->hdf, "Query");
    ThrowIfNeoError(err);

    err = cgi_parse(cgi);
    ThrowIfNeoError(err);

    if (_SERVER["REQUEST_METHOD"].compare("POST") == 0) {
        TranslatePost(cgi, &_request_posts, &_uploaded_files);

    } else if (_SERVER["REQUEST_METHOD"].compare("PUT") == 0) {
        TranslatePut(cgi, &_uploaded_files);
    }

    // Now we have both GET and POST data, POST overwrites GET.
    _request_all = _request_queries;
    _request_all.Merge(_request_posts, true);
}