7 #ifndef CIVETSERVER_HEADER_INCLUDED 
    8 #define CIVETSERVER_HEADER_INCLUDED 
   17 #ifndef CIVETWEB_CXX_API 
   19 #if defined(CIVETWEB_CXX_DLL_EXPORTS) 
   20 #define CIVETWEB_CXX_API __declspec(dllexport) 
   21 #elif defined(CIVETWEB_CXX_DLL_IMPORTS) 
   22 #define CIVETWEB_CXX_API __declspec(dllimport) 
   24 #define CIVETWEB_CXX_API 
   27 #define CIVETWEB_CXX_API __attribute__((visibility("default"))) 
   29 #define CIVETWEB_CXX_API 
   39 class CIVETWEB_CXX_API CivetException : 
public std::runtime_error
 
   42     CivetException(
const std::string &msg) : std::runtime_error(msg)
 
   51 class CIVETWEB_CXX_API CivetHandler
 
   57     virtual ~CivetHandler()
 
   68     virtual bool handleGet(CivetServer *server, 
struct mg_connection *conn);
 
   78     virtual bool handleGet(CivetServer *server,
 
   79                            struct mg_connection *conn,
 
   89     virtual bool handlePost(CivetServer *server, 
struct mg_connection *conn);
 
   99     virtual bool handlePost(CivetServer *server,
 
  100                             struct mg_connection *conn,
 
  110     virtual bool handleHead(CivetServer *server, 
struct mg_connection *conn);
 
  120     virtual bool handleHead(CivetServer *server,
 
  121                             struct mg_connection *conn,
 
  131     virtual bool handlePut(CivetServer *server, 
struct mg_connection *conn);
 
  141     virtual bool handlePut(CivetServer *server,
 
  142                            struct mg_connection *conn,
 
  152     virtual bool handleDelete(CivetServer *server, 
struct mg_connection *conn);
 
  162     virtual bool handleDelete(CivetServer *server,
 
  163                               struct mg_connection *conn,
 
  173     virtual bool handleOptions(CivetServer *server, 
struct mg_connection *conn);
 
  183     virtual bool handleOptions(CivetServer *server,
 
  184                                struct mg_connection *conn,
 
  194     virtual bool handlePatch(CivetServer *server, 
struct mg_connection *conn);
 
  204     virtual bool handlePatch(CivetServer *server,
 
  205                              struct mg_connection *conn,
 
  213 class CIVETWEB_CXX_API CivetAuthHandler
 
  219     virtual ~CivetAuthHandler()
 
  231     virtual bool authorize(CivetServer *server, 
struct mg_connection *conn) = 0;
 
  238 class CIVETWEB_CXX_API CivetWebSocketHandler
 
  244     virtual ~CivetWebSocketHandler()
 
  256     virtual bool handleConnection(CivetServer *server,
 
  257                                   const struct mg_connection *conn);
 
  266     virtual void handleReadyState(CivetServer *server,
 
  267                                   struct mg_connection *conn);
 
  279     virtual bool handleData(CivetServer *server,
 
  280                             struct mg_connection *conn,
 
  291     virtual void handleClose(CivetServer *server,
 
  292                              const struct mg_connection *conn);
 
  300 struct CIVETWEB_CXX_API CivetCallbacks : 
public mg_callbacks {
 
  309 class CIVETWEB_CXX_API CivetServer
 
  329     CivetServer(
const char **options,
 
  330                 const struct CivetCallbacks *callbacks = 0,
 
  331                 const void *UserContext = 0);
 
  332     CivetServer(
const std::vector<std::string> &options,
 
  333                 const struct CivetCallbacks *callbacks = 0,
 
  334                 const void *UserContext = 0);
 
  339     virtual ~CivetServer();
 
  353     const struct mg_context *
 
  370     void addHandler(
const std::string &uri, CivetHandler *handler);
 
  373     addHandler(
const std::string &uri, CivetHandler &handler)
 
  375         addHandler(uri, &handler);
 
  390     void addWebSocketHandler(
const std::string &uri,
 
  391                              CivetWebSocketHandler *handler);
 
  394     addWebSocketHandler(
const std::string &uri, CivetWebSocketHandler &handler)
 
  396         addWebSocketHandler(uri, &handler);
 
  406     void removeHandler(
const std::string &uri);
 
  415     void removeWebSocketHandler(
const std::string &uri);
 
  428     void addAuthHandler(
const std::string &uri, CivetAuthHandler *handler);
 
  431     addAuthHandler(
const std::string &uri, CivetAuthHandler &handler)
 
  433         addAuthHandler(uri, &handler);
 
  443     void removeAuthHandler(
const std::string &uri);
 
  453     std::vector<int> getListeningPorts();
 
  463     std::vector<struct mg_server_port> getListeningPortsFull();
 
  477     static int getCookie(
struct mg_connection *conn,
 
  478                          const std::string &cookieName,
 
  479                          std::string &cookieValue);
 
  487     static const char *getHeader(
struct mg_connection *conn,
 
  488                                  const std::string &headerName);
 
  495     static const char *getMethod(
struct mg_connection *conn);
 
  520     static bool getParam(
struct mg_connection *conn,
 
  523                          size_t occurrence = 0);
 
  540     getParam(
const std::string &data,
 
  543              size_t occurrence = 0)
 
  545         return getParam(data.c_str(), data.length(), name, dst, occurrence);
 
  563     static bool getParam(
const char *data,
 
  567                          size_t occurrence = 0);
 
  579     static std::string getPostData(
struct mg_connection *conn);
 
  592     urlDecode(
const std::string &src,
 
  594               bool is_form_url_encoded = 
true)
 
  596         urlDecode(src.c_str(), src.length(), dst, is_form_url_encoded);
 
  610     static void urlDecode(
const char *src,
 
  613                           bool is_form_url_encoded = 
true);
 
  625     static void urlDecode(
const char *src,
 
  627                           bool is_form_url_encoded = 
true);
 
  637     urlEncode(
const std::string &src, std::string &dst, 
bool append = 
false)
 
  639         urlEncode(src.c_str(), src.length(), dst, append);
 
  650     urlEncode(
const char *src, std::string &dst, 
bool append = 
false);
 
  660     static void urlEncode(
const char *src,
 
  663                           bool append = 
false);
 
  668     getUserContext()
 const 
  674     class CivetConnection
 
  677         std::vector<char> postData;
 
  680     struct mg_context *context;
 
  681     std::map<const struct mg_connection *, CivetConnection> connections;
 
  685     const void *UserContext;
 
  697     static int requestHandler(
struct mg_connection *conn, 
void *cbdata);
 
  699     static int webSocketConnectionHandler(
const struct mg_connection *conn,
 
  701     static void webSocketReadyHandler(
struct mg_connection *conn, 
void *cbdata);
 
  702     static int webSocketDataHandler(
struct mg_connection *conn,
 
  707     static void webSocketCloseHandler(
const struct mg_connection *conn,
 
  718     static int authHandler(
struct mg_connection *conn, 
void *cbdata);
 
  727     static void closeHandler(
const struct mg_connection *conn);
 
  732     void (*userCloseHandler)(
const struct mg_connection *conn);