~jan-kneschke/mysql-proxy/packet-tracking-assertions

« back to all changes in this revision

Viewing changes to lib/mysql-proto.c

  • Committer: Kay Roepke
  • Date: 2009-01-20 12:04:47 UTC
  • Revision ID: kay@mysql.com-20090120120447-fkoxq5ovwf9iyk4v
add the wrapper script/makefile fu to start mysql-proxy without having to set the environment variables

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* $%BEGINLICENSE%$
2
 
 Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
 
2
 Copyright (C) 2008 MySQL AB, 2008 Sun Microsystems, Inc
3
3
 
4
 
 This program is free software; you can redistribute it and/or
5
 
 modify it under the terms of the GNU General Public License as
6
 
 published by the Free Software Foundation; version 2 of the
7
 
 License.
 
4
 This program is free software; you can redistribute it and/or modify
 
5
 it under the terms of the GNU General Public License as published by
 
6
 the Free Software Foundation; version 2 of the License.
8
7
 
9
8
 This program is distributed in the hope that it will be useful,
10
9
 but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 
10
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
11
 GNU General Public License for more details.
13
12
 
14
13
 You should have received a copy of the GNU General Public License
15
14
 along with this program; if not, write to the Free Software
16
 
 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
17
 
 02110-1301  USA
 
15
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18
16
 
19
17
 $%ENDLICENSE%$ */
20
18
 
30
28
 
31
29
#include "network-mysqld-proto.h"
32
30
#include "network-mysqld-packet.h"
33
 
#include "network-mysqld-masterinfo.h"
34
31
#include "glib-ext.h"
35
32
#include "lua-env.h"
36
33
 
113
110
        packet = g_string_new(NULL);    
114
111
        network_mysqld_proto_append_err_packet(packet, err_packet);
115
112
 
116
 
        network_mysqld_err_packet_free(err_packet);
117
 
 
118
113
        lua_pushlstring(L, S(packet));
119
114
        
 
115
        network_mysqld_err_packet_free(err_packet);
 
116
 
120
117
        g_string_free(packet, TRUE);
121
118
 
122
119
        return 1;
157
154
        return 1;
158
155
}
159
156
 
160
 
static int lua_proto_get_masterinfo_string (lua_State *L) {
161
 
        size_t packet_len;
162
 
        const char *packet_str = luaL_checklstring(L, 1, &packet_len);
163
 
        network_mysqld_masterinfo_t *info;
164
 
 
165
 
        network_packet packet;
166
 
        GString s;
167
 
        int err = 0;
168
 
 
169
 
        s.str = (char *)packet_str;
170
 
        s.len = packet_len;
171
 
 
172
 
        packet.data = &s;
173
 
        packet.offset = 0;
174
 
 
175
 
        info = network_mysqld_masterinfo_new();
176
 
 
177
 
        err = err || network_mysqld_masterinfo_get(&packet, info);
178
 
        
179
 
        if (err) {
180
 
                network_mysqld_masterinfo_free(info);
181
 
                luaL_error(L, "%s: network_mysqld_masterinfo_get() failed", G_STRLOC);
182
 
                return 0;
183
 
        }
184
 
 
185
 
        lua_newtable(L);
186
 
        
187
 
        LUA_EXPORT_INT(info, master_lines);
188
 
        LUA_EXPORT_STR(info, master_log_file);
189
 
        LUA_EXPORT_INT(info, master_log_pos);
190
 
        LUA_EXPORT_STR(info, master_host);
191
 
        LUA_EXPORT_STR(info, master_user);
192
 
        LUA_EXPORT_STR(info, master_password);
193
 
        LUA_EXPORT_INT(info, master_port);
194
 
        LUA_EXPORT_INT(info, master_connect_retry);
195
 
        LUA_EXPORT_INT(info, master_ssl);
196
 
        LUA_EXPORT_STR(info, master_ssl_ca);
197
 
        LUA_EXPORT_STR(info, master_ssl_capath);
198
 
        LUA_EXPORT_STR(info, master_ssl_cert);
199
 
        LUA_EXPORT_STR(info, master_ssl_cipher);
200
 
        LUA_EXPORT_STR(info, master_ssl_key);
201
 
        if (info->master_lines >= 15) {
202
 
                LUA_EXPORT_INT(info, master_ssl_verify_server_cert);
203
 
        }
204
 
        
205
 
        network_mysqld_masterinfo_free(info);
206
 
 
207
 
        return 1;
208
 
}
209
 
 
210
 
static int lua_proto_append_masterinfo_string (lua_State *L) {
211
 
        GString *packet;
212
 
        network_mysqld_masterinfo_t *info;
213
 
 
214
 
        luaL_checktype(L, 1, LUA_TTABLE);
215
 
 
216
 
        info = network_mysqld_masterinfo_new();
217
 
 
218
 
        LUA_IMPORT_INT(info, master_lines);
219
 
        LUA_IMPORT_STR(info, master_log_file);
220
 
        LUA_IMPORT_INT(info, master_log_pos);
221
 
        LUA_IMPORT_STR(info, master_host);
222
 
        LUA_IMPORT_STR(info, master_user);
223
 
        LUA_IMPORT_STR(info, master_password);
224
 
        LUA_IMPORT_INT(info, master_port);
225
 
        LUA_IMPORT_INT(info, master_connect_retry);
226
 
        LUA_IMPORT_INT(info, master_ssl);
227
 
        LUA_IMPORT_STR(info, master_ssl_ca);
228
 
        LUA_IMPORT_STR(info, master_ssl_capath);
229
 
        LUA_IMPORT_STR(info, master_ssl_cert);
230
 
        LUA_IMPORT_STR(info, master_ssl_cipher);
231
 
        LUA_IMPORT_STR(info, master_ssl_key);
232
 
        LUA_IMPORT_INT(info, master_ssl_verify_server_cert);
233
 
 
234
 
        packet = g_string_new(NULL);
235
 
        network_mysqld_masterinfo_append(packet, info);
236
 
 
237
 
        network_mysqld_masterinfo_free(info);
238
 
 
239
 
        lua_pushlstring(L, S(packet));
240
 
 
241
 
        g_string_free(packet, TRUE);
242
 
 
243
 
        return 1;
244
 
}
245
 
 
246
 
 
247
157
static int lua_proto_append_ok_packet (lua_State *L) {
248
158
        GString *packet;
249
159
        network_mysqld_ok_packet_t *ok_packet;
260
170
        packet = g_string_new(NULL);    
261
171
        network_mysqld_proto_append_ok_packet(packet, ok_packet);
262
172
 
 
173
        lua_pushlstring(L, S(packet));
 
174
        
263
175
        network_mysqld_ok_packet_free(ok_packet);
264
176
        
265
 
        lua_pushlstring(L, S(packet));
266
 
        
267
177
        g_string_free(packet, TRUE);
268
178
 
269
179
        return 1;
316
226
        packet = g_string_new(NULL);    
317
227
        network_mysqld_proto_append_eof_packet(packet, eof_packet);
318
228
 
 
229
        lua_pushlstring(L, S(packet));
 
230
        
319
231
        network_mysqld_eof_packet_free(eof_packet);
320
232
        
321
 
        lua_pushlstring(L, S(packet));
322
 
        
323
233
        g_string_free(packet, TRUE);
324
234
 
325
235
        return 1;
382
292
 
383
293
        if (network_mysqld_proto_append_auth_response(packet, auth_response)) {
384
294
                network_mysqld_auth_response_free(auth_response);
385
 
                g_string_free(packet, TRUE);
386
295
 
387
296
                luaL_error(L, "to_response_packet() failed");
388
 
        g_string_free(packet, TRUE);
389
297
                return 0;
390
298
        }
 
299
 
 
300
        lua_pushlstring(L, S(packet));
391
301
        
392
302
        network_mysqld_auth_response_free(auth_response);
393
303
 
394
 
        lua_pushlstring(L, S(packet));
395
 
        
396
 
        g_string_free(packet, TRUE);
397
 
 
398
304
        return 1;
399
305
}
400
306
 
456
362
 
457
363
        packet = g_string_new(NULL);    
458
364
        network_mysqld_proto_append_auth_challenge(packet, auth_challenge);
 
365
 
 
366
        lua_pushlstring(L, S(packet));
459
367
        
460
368
        network_mysqld_auth_challenge_free(auth_challenge);
461
 
 
462
 
        lua_pushlstring(L, S(packet));
463
 
        
464
369
        g_string_free(packet, TRUE);
465
370
 
466
371
        return 1;
495
400
        {"to_challenge_packet", lua_proto_append_challenge_packet},
496
401
        {"from_response_packet", lua_proto_get_response_packet},
497
402
        {"to_response_packet", lua_proto_append_response_packet},
498
 
        {"from_masterinfo_string", lua_proto_get_masterinfo_string},
499
 
        {"to_masterinfo_string", lua_proto_append_masterinfo_string},
500
403
        {NULL, NULL},
501
404
};
502
405