cgi /boost/cgi/common/error.hpp

Language C/C++ Header Lines 159
MD5 Hash 00c9510aece61dc86514dd800eefc768 Estimated Cost $2,307 (why?)
Repository git://github.com/darrengarvey/cgi.git View Raw File
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
//                     -- error.hpp --
//
//            Copyright (c) Darren Garvey 2007.
// Distributed under the Boost Software License, Version 1.0.
//    (See accompanying file LICENSE_1_0.txt or copy at
//          http://www.boost.org/LICENSE_1_0.txt)
//
// Abstract:
// ---------
//
// The common errors are defined in here.
//
// **FIXME** This is a mess.
//
////////////////////////////////////////////////////////////////
#ifndef BOOST_COMMON_ERROR_HPP_INCLUDED__
#define BOOST_COMMON_ERROR_HPP_INCLUDED__

#include <string>
#include <boost/system/error_code.hpp>
#include "boost/cgi/config.hpp"

BOOST_CGI_NAMESPACE_BEGIN
 namespace common {
  namespace error {

enum cgi_errors
{
  // Tried to read/write from/to the client associated to a request when it
  // was closed.
  client_closed = 1,

  // A begin_request packet has come in with an existing request id.
  duplicate_request,

  // Calling async_accept on a request that hasn't been closed isn't
  // allowed.
  accepting_on_an_open_request,

  invalid_socket,

  // The CONTENT_TYPE for form data wasn't recognised.
  invalid_form_type,

  // Used in basic_connection<tags::stdio>
  // **FIXME**
  broken_pipe,

  // **TODO** Document
  bad_read,

  // **TODO** Document
  bad_write,

  // A client wasn't able to open.
  client_not_open,
  
  // End of File (read zero bytes)
  eof,
  
  // The first multipart form boundary was not found.
  multipart_form_boundary_not_found,
  
  // The first multipart form boundary was not found.
  multipart_meta_data_not_terminated,
  
  // Expected a boundary marker for a multipart form, but did not find it.
  no_boundary_marker,
  
  already_closed,
  
  // The content length of the file upload is larger than maximum allowed
  // by the BOOST_CGI_POST_MAX macro.
  max_post_exceeded
};

  namespace detail {

class cgi_category
  : public boost::system::error_category
{
public:
  const char* name() const { return "CGI Error"; }
  std::string message(int e) const
  {
    switch(e)
    {
    case client_closed:
      return "Attempting to read from or write to a client that has been"
             " closed.";
    case accepting_on_an_open_request:
      return "`async_accept` called with an open request (ie. it should be"
             " closed first).";
    case multipart_form_boundary_not_found:
      return "The first multipart form boundary was not found.";
    case no_boundary_marker:
      return "Expected a boundary marker for a multipart form, but did not"
             " find it.";
    case invalid_form_type:
      return "The CONTENT_TYPE for form data wasn't recognised.";
    case eof:
      return "End of File.";
    case duplicate_request:
      return "FastCGI: new request received with a duplicate id.";
    case max_post_exceeded:
      return "The content length of the file upload is larger than maximum"
             " allowed by the BOOST_CGI_POST_MAX macro.";
    case already_closed:
      return "Trying to close a request that has already been closed.";
    default:
      return "(CGI) BOOM!!!";
    }
  }
};

  } // namespace detail

inline const boost::system::error_category& get_cgi_category()
{
  static detail::cgi_category instance;
  return instance;
}

static const boost::system::error_category& cgi_category
  = ::BOOST_CGI_NAMESPACE::common::error::get_cgi_category();

  } // namespace error
 } // namespace common
BOOST_CGI_NAMESPACE_END

namespace boost {
  namespace system {

    template<> struct is_error_code_enum<
        ::BOOST_CGI_NAMESPACE::common::error::cgi_errors
      >
    {
      BOOST_STATIC_CONSTANT(bool, value = true);
    };

  } // namespace system
} // namespace boost

BOOST_CGI_NAMESPACE_BEGIN
 namespace common {
  namespace error {
  
    inline boost::system::error_code make_error_code(cgi_errors e)
    {
      return boost::system::error_code(
          static_cast<int>(e), get_cgi_category());
    }

  } // namespace error
 } // namespace common
BOOST_CGI_NAMESPACE_END

#endif // BOOST_COMMON_ERROR_HPP_INCLUDED__
Back to Top