~ubuntu-branches/ubuntu/vivid/drizzle/vivid-proposed

« back to all changes in this revision

Viewing changes to plugin/json_server/http_handler.h

  • Committer: Package Import Robot
  • Author(s): Tobias Frost
  • Date: 2013-08-22 20:18:31 UTC
  • mto: (20.1.1 sid)
  • mto: This revision was merged to the branch mainline in revision 21.
  • Revision ID: package-import@ubuntu.com-20130822201831-gn3ozsh7o7wmc5tk
Tags: upstream-7.2.3
ImportĀ upstreamĀ versionĀ 7.2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
 
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
 
3
 *
 
4
 *  Copyright (C) 2012 Mohit Srivastava
 
5
 *
 
6
 *  This program is free software; you can redistribute it and/or modify
 
7
 *  it under the terms of the GNU General Public License as published by
 
8
 *  the Free Software Foundation; either version 2 of the License, or
 
9
 *  (at your option) any later version.
 
10
 *
 
11
 *  This program is distributed in the hope that it will be useful,
 
12
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 *  GNU General Public License for more details.
 
15
 *
 
16
 *  You should have received a copy of the GNU General Public License
 
17
 *  along with this program; if not, write to the Free Software
 
18
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
19
 */
 
20
/**
 
21
 * @file Declare a class HTTPHandler which handles the operations related to HTTP request and response. 
 
22
 */
 
23
 
 
24
#pragma once
 
25
 
 
26
#include <config.h>
 
27
#include <evhttp.h>
 
28
#include <plugin/json_server/json/json.h>
 
29
#include <drizzled/plugin.h>
 
30
 
 
31
using namespace std;
 
32
/**
 
33
 *  Drizzle Plugin Namespace
 
34
 */
 
35
namespace drizzle_plugin
 
36
{
 
37
/**
 
38
 *  Json Server Plugin Namespace
 
39
 */
 
40
namespace json_server
 
41
 
42
  /**
 
43
   * a class.
 
44
   * used to handles http request and response. 
 
45
   */
 
46
  class HttpHandler
 
47
  {
 
48
    public:
 
49
      /**
 
50
       * Constructor
 
51
       * 
 
52
       * @param json_out an empty json output object.
 
53
       * @param json_in an empty json input object.
 
54
       * @param req the http request object to parse.
 
55
       */
 
56
      HttpHandler(Json::Value& json_out,Json::Value json_in,struct evhttp_request *req);
 
57
      /**
 
58
       * Parse http request and retrieve various http headers.
 
59
       *
 
60
       * @return false Success
 
61
       * @return true Failure
 
62
       */
 
63
      bool handleRequest();
 
64
      /**
 
65
       * Parse input json query and generate input json object.
 
66
       *
 
67
       * @param default_schema a string.
 
68
       * @param default_table a string.
 
69
       * @param allow_drop_table a boolean value.
 
70
       * @return false Success.
 
71
       * @return true Failure.
 
72
       */
 
73
      bool validate(string &default_schema,string &default_table,bool allow_drop_table);
 
74
      /**
 
75
       * Send http response back.
 
76
       *
 
77
       * @param json_out a Json::Value object.
 
78
       */
 
79
      void sendResponse();
 
80
      /**
 
81
       * Generate a http error when table is null.
 
82
       */
 
83
      void generateHttpError();
 
84
      /**
 
85
       * Generate a error occurs using DROP Table command.
 
86
       */
 
87
      void generateDropTableError();
 
88
      /**
 
89
       * Get schema being used.
 
90
       * @return a constant schema string.
 
91
       */
 
92
      const char* getSchema() const
 
93
      {
 
94
        return _schema;
 
95
      }
 
96
      /**
 
97
       * Get table being used.
 
98
       * 
 
99
       * @return a constant table string.
 
100
       */
 
101
      const char* getTable() const
 
102
      {
 
103
        return _table;
 
104
      }
 
105
      /**
 
106
       * Get query being used.
 
107
       * @return a constant query string.
 
108
       */
 
109
      const string &getQuery() const
 
110
      {
 
111
        return _query;
 
112
      }
 
113
      /**
 
114
       * Get id being used.
 
115
       * @return a constant id string.
 
116
       */
 
117
      const char* getId() const
 
118
      {
 
119
        return _id;
 
120
      }
 
121
      /**
 
122
       * Get output json object.
 
123
       * @return a constant json object.
 
124
       */
 
125
      const Json::Value getOutputJson() const 
 
126
      {
 
127
        return _json_out;
 
128
      }
 
129
      /**
 
130
       * Get input json object.
 
131
       * @return a constant json object.
 
132
       */
 
133
      const Json::Value getInputJson() const 
 
134
      {
 
135
        return _json_in;
 
136
      }
 
137
     /**
 
138
      * Set Output json object.
 
139
      * @param json_out a Json::Value object.
 
140
      */
 
141
      void setOutputJson(Json::Value& json_out)
 
142
      {
 
143
        _json_out=json_out;
 
144
      }
 
145
 
 
146
    private:
 
147
      /**
 
148
       * Stores schema being used.
 
149
       */
 
150
      const char *_schema;
 
151
      /**
 
152
       * Stores table being used.
 
153
       */
 
154
      const char *_table;
 
155
      /**
 
156
       * Stores query being used.
 
157
       */
 
158
      string _query;
 
159
      /**
 
160
       * Stores id primary key for a dcument.
 
161
       */
 
162
      const char *_id;
 
163
      /**
 
164
       * Stores output json object.
 
165
       */
 
166
      Json::Value _json_out;
 
167
      /**
 
168
       * Stores input json object.
 
169
       */
 
170
      Json::Value _json_in;
 
171
      /**
 
172
       * Stores http response code.
 
173
       */
 
174
      int _http_response_code;
 
175
      /**
 
176
       * Stores http response text.
 
177
       */
 
178
      const char *_http_response_text;
 
179
      /**
 
180
       * Stores http request object.
 
181
       */
 
182
      struct evhttp_request *_req;    
 
183
  };
 
184
 
 
185
}
 
186
}