request_dispatcher.h

00001
00002 /***************************************************************************
00003  *  request_dispatcher.h - Web request dispatcher
00004  *
00005  *  Created: Mon Oct 13 22:44:33 2008
00006  *  Copyright  2006-2008  Tim Niemueller [www.niemueller.de]
00007  *
00008  ****************************************************************************/
00009
00010 /*  This program is free software; you can redistribute it and/or modify
00011  *  it under the terms of the GNU General Public License as published by
00012  *  the Free Software Foundation; either version 2 of the License, or
00013  *  (at your option) any later version.
00014  *
00015  *  This program is distributed in the hope that it will be useful,
00016  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  *  GNU Library General Public License for more details.
00019  *
00020  *  Read the full text in the LICENSE.GPL file in the doc directory.
00021  */
00022
00023 #ifndef __PLUGINS_WEBVIEW_REQUEST_DISPATCHER_H_
00024 #define __PLUGINS_WEBVIEW_REQUEST_DISPATCHER_H_
00025 
00026 #include <string>
00027 #include <map>
00028 #include <stdint.h>
00029
00030 struct MHD_Connection;
00031 class WebRequestProcessor;
00032 class StaticWebReply;
00033
00034 namespace fawkes {
00035   class CacheLogger;
00036 }
00037
00038 class WebRequestDispatcher
00039 {
00040  public:
00041   void add_processor(const char *url_prefix, WebRequestProcessor *processor);
00042   void remove_processor(const char *url_prefix);
00043
00044
00045   static int process_request_cb(void *callback_data,
00046                                 struct MHD_Connection * connection,
00047                                 const char *url,
00048                                 const char *method,
00049                                 const char *version,
00050                                 const char *upload_data,
00051                                 size_t *upload_data_size,
00052                                 void  **session_data);
00053
00054   static int  dynamic_reply_data_cb(void *reply, uint64_t pos, char *buf, int max);
00055   static void dynamic_reply_free_cb(void *reply);
00056
00057   int queue_static_reply(struct MHD_Connection * connection,
00058                          StaticWebReply *sreply);
00059   int process_request(struct MHD_Connection * connection,
00060                       const char *url,
00061                       const char *method,
00062                       const char *version,
00063                       const char *upload_data,
00064                       size_t *upload_data_size,
00065                       void **session_data);
00066
00067  private:
00068   fawkes::CacheLogger *__cache_logger;
00069
00070   std::map<std::string, WebRequestProcessor *>  __processors;
00071   WebRequestProcessor                          *__startpage_processor;
00072 };
00073
00074
00075 #endif