Blame mime_util.h

Packit a4aae4
Packit a4aae4
// -*- mode: c++; c-basic-offset:4 -*-
Packit a4aae4
Packit a4aae4
// This file is part of libdap, A C++ implementation of the OPeNDAP Data
Packit a4aae4
// Access Protocol.
Packit a4aae4
Packit a4aae4
// Copyright (c) 2002,2003 OPeNDAP, Inc.
Packit a4aae4
// Author: James Gallagher <jgallagher@opendap.org>
Packit a4aae4
//
Packit a4aae4
// This library is free software; you can redistribute it and/or
Packit a4aae4
// modify it under the terms of the GNU Lesser General Public
Packit a4aae4
// License as published by the Free Software Foundation; either
Packit a4aae4
// version 2.1 of the License, or (at your option) any later version.
Packit a4aae4
//
Packit a4aae4
// This library is distributed in the hope that it will be useful,
Packit a4aae4
// but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit a4aae4
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit a4aae4
// Lesser General Public License for more details.
Packit a4aae4
//
Packit a4aae4
// You should have received a copy of the GNU Lesser General Public
Packit a4aae4
// License along with this library; if not, write to the Free Software
Packit a4aae4
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
Packit a4aae4
//
Packit a4aae4
// You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
Packit a4aae4
Packit a4aae4
// (c) COPYRIGHT URI/MIT 1995-1999
Packit a4aae4
// Please read the full copyright statement in the file COPYRIGHT_URI.
Packit a4aae4
//
Packit a4aae4
// Authors:
Packit a4aae4
//      jhrg,jimg       James Gallagher <jgallagher@gso.uri.edu>
Packit a4aae4
//      reza            Reza Nekovei <reza@intcomm.net>
Packit a4aae4
Packit a4aae4
// External definitions for utility functions used by servers.
Packit a4aae4
//
Packit a4aae4
// 2/22/95 jhrg
Packit a4aae4
Packit a4aae4
#ifndef _mime_util_h
Packit a4aae4
#define _mime_util_h
Packit a4aae4
Packit a4aae4
#include "media_types.h"	// Remove when the deprecated stuff comes out of the library. 11/12/13 jhrg
Packit a4aae4
Packit a4aae4
#ifndef _object_type_h
Packit a4aae4
#include "ObjectType.h"
Packit a4aae4
#endif
Packit a4aae4
Packit a4aae4
#ifndef _encoding_type_h
Packit a4aae4
#include "EncodingType.h"
Packit a4aae4
#endif
Packit a4aae4
Packit a4aae4
#include <string>
Packit a4aae4
Packit a4aae4
namespace libdap
Packit a4aae4
{
Packit a4aae4
Packit a4aae4
/** The CGI utilities include a variety of functions useful to
Packit a4aae4
    programmers developing OPeNDAP CGI filter programs. However, before jumping
Packit a4aae4
    in and using these, look at the class ResponseBuilder. Always choose to use
Packit a4aae4
    that class over these functions if you can. Many of these functions were used
Packit a4aae4
    by the CGI programs that made up the first DAP server; all of those are
Packit a4aae4
    deprecated and the ResponseBuilder class should be used instead. Some of
Packit a4aae4
    the other functions are used by ResponseBuilder and the client-side parsing
Packit a4aae4
    code that needs to identify MIME headers, boundaries, etc.
Packit a4aae4
Packit a4aae4
    @name MIME Utilities
Packit a4aae4
    @brief A collection of useful functions for writing MIME headers for
Packit a4aae4
    OPeNDAP servers.
Packit a4aae4
    @see ResponseBuilder, Connect, DDXParserSAX2
Packit a4aae4
    */
Packit a4aae4
Packit a4aae4
//@{
Packit a4aae4
std::string rfc822_date(const time_t t);
Packit a4aae4
time_t last_modified_time(const std::string &name);
Packit a4aae4
ObjectType get_description_type(const std::string &value);
Packit a4aae4
bool is_boundary(const char *line, const std::string &boundary);
Packit a4aae4
std::string cid_to_header_value(const std::string &cid;;
Packit a4aae4
Packit a4aae4
std::string read_multipart_boundary(std::istream &in, const std::string &boundary = "");
Packit a4aae4
Packit a4aae4
void parse_mime_header(const std::string &header, std::string &name, std::string &value);
Packit a4aae4
std::string name_path(const std::string &path);
Packit a4aae4
std::string get_next_mime_header(std::istream &in);
Packit a4aae4
Packit a4aae4
void read_multipart_headers(std::istream &in, const std::string &content_type,
Packit a4aae4
	const ObjectType object_type, const std::string &cid = "");
Packit a4aae4
Packit a4aae4
// For testing only
Packit a4aae4
void remove_mime_header(std::istream &in);
Packit a4aae4
Packit a4aae4
// All of these are deprecated
Packit a4aae4
std::string read_multipart_boundary(FILE *in, const std::string &boundary = "");
Packit a4aae4
void read_multipart_headers(FILE *in, const std::string &content_type,
Packit a4aae4
	const ObjectType object_type, const std::string &cid = "");
Packit a4aae4
bool do_version(const std::string &script_ver, const std::string &dataset_ver);
Packit a4aae4
void ErrMsgT(const std::string &Msgt);
Packit a4aae4
ObjectType get_type(const std::string &value);
Packit a4aae4
std::string get_next_mime_header(FILE *in);
Packit a4aae4
bool remove_mime_header(FILE *in);
Packit a4aae4
Packit a4aae4
#if 0
Packit a4aae4
bool found_override(std::string name, std::string &doc;;
Packit a4aae4
#endif
Packit a4aae4
//@}
Packit a4aae4
Packit a4aae4
/** These functions are used to create the MIME headers for a message
Packit a4aae4
    from a server to a client. They are public but should not be called
Packit a4aae4
    directly unless absolutely necessary. Use DODSFilter instead.
Packit a4aae4
Packit a4aae4
    NB: These functions actually write both the response status line
Packit a4aae4
    and the header.
Packit a4aae4
Packit a4aae4
    @deprecated Use ResponseBuilder instead.
Packit a4aae4
    @name MIME utility functions
Packit a4aae4
    @see DODSFilter
Packit a4aae4
*/
Packit a4aae4
//@{
Packit a4aae4
void set_mime_text(FILE *out, ObjectType type = unknown_type,
Packit a4aae4
                   const std::string &version = "", EncodingType enc = x_plain,
Packit a4aae4
                   const time_t last_modified = 0);
Packit a4aae4
void set_mime_text(std::ostream &out, ObjectType type = unknown_type,
Packit a4aae4
                   const std::string &version = "", EncodingType enc = x_plain,
Packit a4aae4
                   const time_t last_modified = 0);
Packit a4aae4
void set_mime_text(std::ostream &out, ObjectType type = unknown_type,
Packit a4aae4
                   EncodingType enc = x_plain,
Packit a4aae4
                   const time_t last_modified = 0,
Packit a4aae4
                   const std::string &protocol = "");
Packit a4aae4
Packit a4aae4
void set_mime_html(FILE *out, ObjectType type = unknown_type,
Packit a4aae4
                   const std::string &version = "", EncodingType enc = x_plain,
Packit a4aae4
                   const time_t last_modified = 0);
Packit a4aae4
void set_mime_html(std::ostream &out, ObjectType type = unknown_type,
Packit a4aae4
                   const std::string &version = "", EncodingType enc = x_plain,
Packit a4aae4
                   const time_t last_modified = 0);
Packit a4aae4
void set_mime_html(std::ostream &out, ObjectType type = unknown_type,
Packit a4aae4
                   EncodingType enc = x_plain,
Packit a4aae4
                   const time_t last_modified = 0,
Packit a4aae4
                   const std::string &protocol = "");
Packit a4aae4
Packit a4aae4
void set_mime_binary(FILE *out, ObjectType type = unknown_type,
Packit a4aae4
                     const std::string &version = "", EncodingType enc = x_plain,
Packit a4aae4
                     const time_t last_modified = 0);
Packit a4aae4
void set_mime_binary(std::ostream &out, ObjectType type = unknown_type,
Packit a4aae4
                     const std::string &version = "", EncodingType enc = x_plain,
Packit a4aae4
                     const time_t last_modified = 0);
Packit a4aae4
void set_mime_binary(std::ostream &out, ObjectType type = unknown_type,
Packit a4aae4
                     EncodingType enc = x_plain,
Packit a4aae4
                     const time_t last_modified = 0,
Packit a4aae4
                     const std::string &protocol = "");
Packit a4aae4
Packit a4aae4
void set_mime_multipart(std::ostream &out, const std::string &boundary,
Packit a4aae4
	const std::string &start, ObjectType type = unknown_type,
Packit a4aae4
        const std::string &version = "", EncodingType enc = x_plain,
Packit a4aae4
        const time_t last_modified = 0);
Packit a4aae4
Packit a4aae4
void set_mime_multipart(std::ostream &out, const std::string &boundary,
Packit a4aae4
	const std::string &start, ObjectType type = unknown_type, EncodingType enc = x_plain,
Packit a4aae4
	const time_t last_modified = 0, const std::string &protocol = "",
Packit a4aae4
	const std::string &url = "");
Packit a4aae4
Packit a4aae4
void set_mime_ddx_boundary(std::ostream &out, const std::string &boundary,
Packit a4aae4
	const std::string &start, ObjectType type = unknown_type,
Packit a4aae4
        EncodingType enc = x_plain);
Packit a4aae4
Packit a4aae4
void set_mime_data_boundary(std::ostream &out, const std::string &boundary,
Packit a4aae4
	const std::string &cid, ObjectType type = unknown_type,
Packit a4aae4
        EncodingType enc = x_plain);
Packit a4aae4
Packit a4aae4
void set_mime_error(FILE *out, int code = 404,
Packit a4aae4
                    const std::string &reason = "Dataset not found",
Packit a4aae4
                    const std::string &version = "");
Packit a4aae4
void set_mime_error(std::ostream &out, int code = 404,
Packit a4aae4
                    const std::string &reason = "Dataset not found",
Packit a4aae4
                    const std::string &version = "");
Packit a4aae4
Packit a4aae4
void set_mime_not_modified(FILE *out);
Packit a4aae4
void set_mime_not_modified(std::ostream &out;;
Packit a4aae4
Packit a4aae4
Packit a4aae4
//@}
Packit a4aae4
Packit a4aae4
} // namespace libdap
Packit a4aae4
Packit a4aae4
#endif // _mime_util_h