~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
 
2173.2.1 by Monty Taylor
Fixes incorrect usage of include
25
#include <config.h>
1377.8.42 by Paweł Blokus
authentication plugin tests
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
  /**
57
  * Get attached session from the client object.
58
  * @retval Session object that is attached, NULL if none.
59
  */
60
  virtual drizzled::Session *getSession(void)
61
  {
62
    return Client::getSession();
63
  }
64
65
  /**
66
  * Attach session to the client object.
67
  * @param[in] session_arg Session object to attach, or NULL to clear.
68
  */
69
  virtual void setSession(drizzled::Session *session_arg)
70
  {
71
    Client::setSession(session_arg);
72
  }
73
74
  /**
75
  * Get file descriptor associated with client object.
76
  * @retval File descriptor that is attached, -1 if none.
77
  */
78
  virtual int getFileDescriptor(void) { return 0; };
79
80
  /**
81
  * Check to see if the client is currently connected.
82
  * @retval Boolean value representing connected state.
83
  */
84
  virtual bool isConnected(void) { return false; };
85
86
  /**
87
  * Flush all data that has been buffered with store() methods.
88
  * @retval Boolean indicating success or failure.
89
  */
90
  virtual bool flush(void)  { return false; };
91
92
  /**
93
  * Close the client object.
94
  */
95
  virtual void close(void) {};
96
97
  /**
98
  * Perform handshake and authorize client if needed.
99
  */
100
  virtual bool authenticate(void) { return false; };
101
102
  /**
103
  * Read command from client.
104
  */
105
  virtual bool readCommand(char **packet, uint32_t *packet_length)
106
  {
107
    (void)packet;
108
    (void)packet_length;
109
    return false;
110
  };
111
112
  /* Send responses. */
113
  virtual void sendOK(void) {};
114
  virtual void sendEOF(void) {};
115
  virtual void sendError(uint32_t sql_errno, const char *err)
116
  {
117
    (void)sql_errno;
118
    (void)err;
119
  };
120
121
  /**
122
  * Send field list for result set.
123
  */
124
  virtual bool sendFields(drizzled::List<drizzled::Item> *list)
125
  {
126
    (void)list;
127
    return false;
128
  };
129
130
  /* Send result fields in various forms. */
131
  virtual bool store(drizzled::Field *from)
132
  {
133
    (void)from;
134
    return store_ret_val;
135
  };
136
  virtual bool store(void) { return store_ret_val; };
137
  virtual bool store(int32_t from)
138
  {
139
    (void)from;
140
    return store_ret_val;
141
  };
142
  virtual bool store(uint32_t from)
143
  {
144
    (void)from;
145
    return store_ret_val;
146
  };
147
  virtual bool store(int64_t from)
148
  {
149
    (void)from;
150
    return store_ret_val;
151
  };
152
  virtual bool store(uint64_t from)
153
  {
154
    (void)from;
155
    return store_ret_val;
156
  };
157
  virtual bool store(double from, uint32_t decimals, drizzled::String *buffer)
158
  {
159
    (void)from;
160
    (void)decimals;
161
    (void)buffer;
162
    return store_ret_val;
163
  };
2030.1.5 by Brian Aker
Update for moving DRIZZLE_TIME to type::Time
164
  virtual bool store(const drizzled::type::Time *from)
1377.8.42 by Paweł Blokus
authentication plugin tests
165
  {
166
    return Client::store(from);
167
  }
168
  virtual bool store(const char *from)
169
  {
170
    return Client::store(from);
171
  }
172
  virtual bool store(const char *from, size_t length)
173
  {
174
    strncpy(last_call_char_ptr, from, length);
175
    return store_ret_val;
176
  };
177
  virtual bool store(const std::string &from)
178
  {
179
    return Client::store(from);
180
  }
181
182
  /* Try to remove these. */
183
  virtual bool haveError(void) { return false; };
184
  virtual bool wasAborted(void) { return false;};
1377.8.40 by Paweł Blokus
minor style fixes
185
};
186
1377.8.41 by Paweł Blokus
ErrorMessage stub
187
class ErrorMessageStub : public drizzled::plugin::ErrorMessage
188
{
189
1377.8.42 by Paweł Blokus
authentication plugin tests
190
public:
191
  ErrorMessageStub() : ErrorMessage("ErrorMessageStub") {}
192
193
  virtual bool errmsg(drizzled::Session *session, int priority, const char *format, va_list ap)
194
  {
195
    (void)session;
196
    (void)priority;
197
    (void)format;
198
    (void)ap;
199
    return false;
200
  }
201
};
202
203
class AuthenticationStub : public drizzled::plugin::Authentication
204
{
205
private:
206
  bool authenticate_return;
207
208
public:
209
  AuthenticationStub(std::string name_arg)
210
  : Authentication(name_arg),
211
    authenticate_return(false)
212
  {}
213
214
  void set_authenticate_return(bool value)
215
  {
216
    authenticate_return = value;
217
  }
218
2008.1.1 by Brian Aker
Adding user identifier that makes use of a shared ptr to handle concurrency
219
  virtual bool authenticate(const drizzled::identifier::User &sctx, const std::string &passwd)
1377.8.42 by Paweł Blokus
authentication plugin tests
220
  {
221
    (void)sctx;
222
    (void)passwd;
223
    return authenticate_return;
224
  };
1377.8.41 by Paweł Blokus
ErrorMessage stub
225
};
1377.8.40 by Paweł Blokus
minor style fixes
226
227
#endif /* UNITTESTS_STUB_PLUGIN_STUBS_H */