1
/* Copyright (C) 2000-2004 DRIZZLE AB
3
This program is free software; you can redistribute it and/or modify
4
it under the terms of the GNU General Public License as published by
5
the Free Software Foundation.
7
There are special exceptions to the terms and conditions of the GPL as it
8
is applied to this software. View the full text of the exception in file
9
EXCEPTIONS-CLIENT in the directory of this software distribution.
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.
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
1
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2008 Sun Microsystems, Inc.
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; version 2 of the License.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21
20
#include <drizzled/global.h>
22
#include "libdrizzle.h"
23
#include "libdrizzle_priv.h"
24
24
#include "errmsg.h"
25
#include <vio/violite.h>
26
25
#include <sys/stat.h>
27
26
#include <signal.h>
51
53
#define INADDR_NONE -1
54
#include <sql_common.h>
55
#include "client_settings.h"
56
#include "local_infile.h"
57
#include <drizzled/gettext.h>
59
#define MY_ALIGN(A,L) (((A) + (L) - 1) & ~((L) - 1))
58
61
bool handle_local_infile(DRIZZLE *drizzle, const char *net_filename)
61
uint packet_length=MY_ALIGN(drizzle->net.max_packet-16,IO_SIZE);
64
uint32_t packet_length=MY_ALIGN(drizzle->net.max_packet-16,IO_SIZE);
62
65
NET *net= &drizzle->net;
64
67
void *li_ptr; /* pass state to local_infile functions */
78
81
/* copy filename into local memory and allocate read buffer */
79
82
if (!(buf=malloc(packet_length)))
81
set_drizzle_error(drizzle, CR_OUT_OF_MEMORY, unknown_sqlstate);
84
drizzle_set_error(drizzle, CR_OUT_OF_MEMORY, sqlstate_get_unknown());
86
89
if ((*options->local_infile_init)(&li_ptr, net_filename,
87
90
options->local_infile_userdata))
89
VOID(my_net_write(net,(const uchar*) "",0)); /* Server needs one packet */
92
(void)my_net_write(net,(const unsigned char*) "",0); /* Server needs one packet */
91
strcpy(net->sqlstate, unknown_sqlstate);
94
strcpy(net->sqlstate, sqlstate_get_unknown());
93
96
(*options->local_infile_error)(li_ptr,
101
104
(*options->local_infile_read)(li_ptr, buf,
102
105
packet_length)) > 0)
104
if (my_net_write(net, (uchar*) buf, readcount))
107
if (my_net_write(net, (unsigned char*) buf, readcount))
110
113
/* Send empty packet to mark end of file */
111
if (my_net_write(net, (const uchar*) "", 0) || net_flush(net))
114
if (my_net_write(net, (const unsigned char*) "", 0) || net_flush(net))
113
set_drizzle_error(drizzle, CR_SERVER_LOST, unknown_sqlstate);
116
drizzle_set_error(drizzle, CR_SERVER_LOST, sqlstate_get_unknown());
208
static int default_local_infile_read(void *ptr, char *buf, uint buf_len)
211
static int default_local_infile_read(void *ptr, char *buf, uint32_t buf_len)
211
214
default_local_infile_data*data = (default_local_infile_data *) ptr;
213
if ((count= (int) read(data->fd, (uchar *) buf, buf_len)) < 0)
216
if ((count= (int) read(data->fd, (unsigned char *) buf, buf_len)) < 0)
215
218
data->error_num= 2; /* the errmsg for not entire file read */
216
219
snprintf(data->error_msg, sizeof(data->error_msg)-1,
262
default_local_infile_error(void *ptr, char *error_msg, uint error_msg_len)
265
default_local_infile_error(void *ptr, char *error_msg, uint32_t error_msg_len)
264
267
default_local_infile_data *data = (default_local_infile_data *) ptr;
265
268
if (data) /* If not error on open */
277
280
drizzle_set_local_infile_handler(DRIZZLE *drizzle,
278
281
int (*local_infile_init)(void **, const char *,
280
int (*local_infile_read)(void *, char *, uint),
283
int (*local_infile_read)(void *, char *, uint32_t),
281
284
void (*local_infile_end)(void *),
282
int (*local_infile_error)(void *, char *, uint),
285
int (*local_infile_error)(void *, char *, uint32_t),
285
288
drizzle->options.local_infile_init= local_infile_init;