summaryrefslogtreecommitdiff
path: root/include/Action.h
blob: ad71566da20309cfc274bc73245fd070975fa1f9 (plain)
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
/*
 *  Baltisot
 *  Copyright (C) 1999-2008 Nicolas "Pixel" Noble
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#ifndef __ACTION_H__
#define __ACTION_H__

#include <Task.h>
#include <Handle.h>
#include <Variables.h>
#include <Exceptions.h>
#include <HtmlSkinner.h>
#include <Atomic.h>
#include <LockSmith.h>

//! This is the basic HTTP action.
/*!
  This pure virtual class contains the framework to build a basic HTTP action.
*/
class Action : public Base {
  public:
      //! The provided string should contain the url of that action.
      /*!
        If no URL is provided, one will be generated on the fly.
      */
      Action(const String & url = "", HtmlSkinner * = 0);
      virtual ~Action();
    //! Will recursively resolve an URL, and return the corresponding action, or NULL if not found.
    Action * Look4URL(const String &);
    //! This pure virtual method has to be filled. It will be launched if the URL is called.
    /*!
      This method will be called when the URL gets invoked. The vars variable will contain the POST
      or GET variables. The headers is a single list of the HTTP headers. And the out handle will
      be dumped as the output to the brower.
    */
    virtual Task * Do(Variables * vars, Variables * headers, Handle * out) = 0;
    //! This helper will dump the basic HTML headers.
    virtual void SendHead(Handle *);
    //! This helper will dump the basic HTML footers.
    virtual void SendFoot(Handle *);
    //! This helper will display a button.
    /*!
      The button will have the caption provided, and will redirect to the provided url.
    */
    virtual void ShowButton(Handle *, const String & caption = "    Ok    ", const String & url = "start");
    //! This pure virtual method has to gives the page title. Will be used in SendHead.
    virtual String GetTitle(void) = 0;
    //! This returns the recorded URL for that action.
    String GetURL(void);
    //! Mark this action to be erased as soon as the Do method ends.
    void CleanUp(void) { hastoclean = true; }
    //! Skinner accessor.
    HtmlSkinner * GetSkinner() { return skin; }
  
  protected:
    //! Mark this action as beeing accessed.
    void Accessed(void) { accessed = true; }
 
  private:
    static Action * start;
    Action * next, * prev;
    String URL;
    bool hastoclean, accessed;
    HtmlSkinner * skin;
    iLock lock;
};

#endif