~drizzle-trunk/drizzle/development

1377.8.42 by Paweł Blokus
authentication plugin tests
1
/* -*- mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
1377.8.40 by Paweł Blokus
minor style fixes
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 *
4
 *  Copyright (C) 2010 Pawel Blokus
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
1377.8.42 by Paweł Blokus
authentication plugin tests
22
#ifndef UNITTESTS_STUB_PLUGIN_STUBS_H
23
#define UNITTESTS_STUB_PLUGIN_STUBS_H
1377.8.40 by Paweł Blokus
minor style fixes
24
 
1377.8.42 by Paweł Blokus
authentication plugin tests
25
#include "config.h"
26
27
#include <cstring>
28
#include <drizzled/plugin/authentication.h>
29
#include <drizzled/plugin/client.h>
30
#include <drizzled/plugin/error_message.h>
31
#include <string>
1377.8.40 by Paweł Blokus
minor style fixes
32
 
33
class ClientStub : public drizzled::plugin::Client
34
{
1377.8.42 by Paweł Blokus
authentication plugin tests
35
protected:
36
  bool store_ret_val;
37
  char *last_call_char_ptr;
38
39
public:
40
41
  ClientStub() :
42
  store_ret_val(false),
43
  last_call_char_ptr(NULL)
44
  {}
45
46
  inline void set_store_ret_val(bool value)
47
  {
48
    store_ret_val= value;
49
  }
50
51
  inline void set_last_call_char_ptr(char *ptr)
52
  {
53
    last_call_char_ptr= ptr;
54
  }
55
56
  virtual ~ClientStub() {}
57
58
  /**
59
  * Get attached session from the client object.
60
  * @retval Session object that is attached, NULL if none.
61
  */
62
  virtual drizzled::Session *getSession(void)
63
  {
64
    return Client::getSession();
65
  }
66
67
  /**
68
  * Attach session to the client object.
69
  * @param[in] session_arg Session object to attach, or NULL to clear.
70
  */
71
  virtual void setSession(drizzled::Session *session_arg)
72
  {
73
    Client::setSession(session_arg);
74
  }
75
76
  /**
77
  * Get file descriptor associated with client object.
78
  * @retval File descriptor that is attached, -1 if none.
79
  */
80
  virtual int getFileDescriptor(void) { return 0; };
81
82
  /**
83
  * Check to see if the client is currently connected.
84
  * @retval Boolean value representing connected state.
85
  */
86
  virtual bool isConnected(void) { return false; };
87
88
  /**
89
  * Check to see if the client is actively reading.
90
  * @retval Boolean value representing reading state.
91
  */
92
  virtual bool isReading(void) { return false; };
93
94
  /**
95
  * Check to see if the client is actively writing.
96
  * @retval Boolean value representing writing state.
97
  */
98
  virtual bool isWriting(void)  { return false; };
99
100
  /**
101
  * Flush all data that has been buffered with store() methods.
102
  * @retval Boolean indicating success or failure.
103
  */
104
  virtual bool flush(void)  { return false; };
105
106
  /**
107
  * Close the client object.
108
  */
109
  virtual void close(void) {};
110
111
  /**
112
  * Perform handshake and authorize client if needed.
113
  */
114
  virtual bool authenticate(void) { return false; };
115
116
  /**
117
  * Read command from client.
118
  */
119
  virtual bool readCommand(char **packet, uint32_t *packet_length)
120
  {
121
    (void)packet;
122
    (void)packet_length;
123
    return false;
124
  };
125
126
  /* Send responses. */
127
  virtual void sendOK(void) {};
128
  virtual void sendEOF(void) {};
129
  virtual void sendError(uint32_t sql_errno, const char *err)
130
  {
131
    (void)sql_errno;
132
    (void)err;
133
  };
134
135
  /**
136
  * Send field list for result set.
137
  */
138
  virtual bool sendFields(drizzled::List<drizzled::Item> *list)
139
  {
140
    (void)list;
141
    return false;
142
  };
143
144
  /* Send result fields in various forms. */
145
  virtual bool store(drizzled::Field *from)
146
  {
147
    (void)from;
148
    return store_ret_val;
149
  };
150
  virtual bool store(void) { return store_ret_val; };
151
  virtual bool store(int32_t from)
152
  {
153
    (void)from;
154
    return store_ret_val;
155
  };
156
  virtual bool store(uint32_t from)
157
  {
158
    (void)from;
159
    return store_ret_val;
160
  };
161
  virtual bool store(int64_t from)
162
  {
163
    (void)from;
164
    return store_ret_val;
165
  };
166
  virtual bool store(uint64_t from)
167
  {
168
    (void)from;
169
    return store_ret_val;
170
  };
171
  virtual bool store(double from, uint32_t decimals, drizzled::String *buffer)
172
  {
173
    (void)from;
174
    (void)decimals;
175
    (void)buffer;
176
    return store_ret_val;
177
  };
178
  virtual bool store(const drizzled::DRIZZLE_TIME *from)
179
  {
180
    return Client::store(from);
181
  }
182
  virtual bool store(const char *from)
183
  {
184
    return Client::store(from);
185
  }
186
  virtual bool store(const char *from, size_t length)
187
  {
188
    strncpy(last_call_char_ptr, from, length);
189
    return store_ret_val;
190
  };
191
  virtual bool store(const std::string &from)
192
  {
193
    return Client::store(from);
194
  }
195
196
  /* Try to remove these. */
197
  virtual bool haveMoreData(void) { return false; };
198
  virtual bool haveError(void) { return false; };
199
  virtual bool wasAborted(void) { return false;};
1377.8.40 by Paweł Blokus
minor style fixes
200
};
201
1377.8.41 by Paweł Blokus
ErrorMessage stub
202
class ErrorMessageStub : public drizzled::plugin::ErrorMessage
203
{
204
1377.8.42 by Paweł Blokus
authentication plugin tests
205
public:
206
  ErrorMessageStub() : ErrorMessage("ErrorMessageStub") {}
207
208
  virtual bool errmsg(drizzled::Session *session, int priority, const char *format, va_list ap)
209
  {
210
    (void)session;
211
    (void)priority;
212
    (void)format;
213
    (void)ap;
214
    return false;
215
  }
216
};
217
218
class AuthenticationStub : public drizzled::plugin::Authentication
219
{
220
private:
221
  bool authenticate_return;
222
223
public:
224
  AuthenticationStub(std::string name_arg)
225
  : Authentication(name_arg),
226
    authenticate_return(false)
227
  {}
228
229
  void set_authenticate_return(bool value)
230
  {
231
    authenticate_return = value;
232
  }
233
234
  virtual bool authenticate(const drizzled::SecurityContext &sctx, const std::string &passwd)
235
  {
236
    (void)sctx;
237
    (void)passwd;
238
    return authenticate_return;
239
  };
1377.8.41 by Paweł Blokus
ErrorMessage stub
240
};
1377.8.40 by Paweł Blokus
minor style fixes
241
242
#endif /* UNITTESTS_STUB_PLUGIN_STUBS_H */