~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to libdrizzle/libdrizzle.c

  • Committer: Monty Taylor
  • Date: 2008-09-15 17:24:04 UTC
  • Revision ID: monty@inaugust.com-20080915172404-ygh6hiyu0q7qpa9x
Removed strndup calls.

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) 2008 Sun Microsystems, Inc.
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; version 2 of the License.
9
 
 *
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.
14
 
 *
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
18
 
 */
19
 
 
20
 
#include <config.h>
21
 
#include "libdrizzle_priv.h"
22
 
 
23
 
#include <libdrizzle/libdrizzle.h>
24
 
#include <libdrizzle/pack.h>
25
 
#include <libdrizzle/errmsg.h>
 
1
/* Copyright (C) 2000-2004 DRIZZLE AB
 
2
 
 
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.
 
6
 
 
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.
 
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
19
 
 
20
#include <drizzled/global.h>
 
21
#include "libdrizzle.h"
 
22
#include "errmsg.h"
26
23
#include <sys/stat.h>
27
24
#include <signal.h>
28
25
#include <time.h>
51
48
#define INADDR_NONE  -1
52
49
#endif
53
50
 
54
 
#include <stdlib.h>
55
 
#include <string.h>
 
51
#include <sql_common.h>
 
52
#include <drizzled/version.h>
56
53
 
57
54
/* Borrowed from libicu header */
58
55
 
75
72
uint32_t     net_buffer_length= 8192;
76
73
uint32_t    max_allowed_packet= 1024L*1024L*1024L;
77
74
 
78
 
unsigned int drizzle_port=0;
79
 
 
80
75
#include <errno.h>
 
76
#define SOCKET_ERROR -1
 
77
 
 
78
/*
 
79
  If allowed through some configuration, then this needs to
 
80
  be changed
 
81
*/
 
82
#define MAX_LONG_DATA_LENGTH 8192
 
83
#define unsigned_field(A) ((A)->flags & UNSIGNED_FLAG)
81
84
 
82
85
 
83
86
static DRIZZLE_PARAMETERS drizzle_internal_parameters=
88
91
  return &drizzle_internal_parameters;
89
92
}
90
93
 
91
 
unsigned int drizzle_get_default_port(void)
92
 
{
93
 
  return drizzle_port;
94
 
}
95
 
 
96
 
void drizzle_set_default_port(unsigned int port)
97
 
{
98
 
  drizzle_port= port;
99
 
}
100
 
 
101
94
/*
102
95
  Expand wildcard to a sql string
103
96
*/
173
166
  /* Add character set number. */
174
167
  if (drizzle->server_capabilities & CLIENT_SECURE_CONNECTION)
175
168
  {
176
 
    int2store(end, (uint16_t) 45); // utf8mb4 number from mystrings/ctype-utf8.c
 
169
    int2store(end, (ushort) 45); // utf8mb4 number from mystrings/ctype-utf8.c
177
170
    end+= 2;
178
171
  }
179
172
 
180
173
  /* Write authentication package */
181
 
  (void)simple_command(drizzle,COM_CHANGE_USER, (unsigned char*) buff, (uint32_t) (end-buff), 1);
 
174
  (void)simple_command(drizzle,COM_CHANGE_USER, (uchar*) buff, (uint32_t) (end-buff), 1);
182
175
 
183
176
  rc= (*drizzle->methods->read_change_user_result)(drizzle);
184
177
 
214
207
int
215
208
drizzle_query(DRIZZLE *drizzle, const char *query)
216
209
{
217
 
  return drizzle_real_query(drizzle,query, (uint32_t) strlen(query));
 
210
  return drizzle_real_query(drizzle,query, (uint) strlen(query));
218
211
}
219
212
 
220
213
 
296
289
  if (!(query= cli_read_rows(drizzle,(DRIZZLE_FIELD*) 0, 8)))
297
290
    return NULL;
298
291
 
299
 
  drizzle->field_count= (uint32_t) query->rows;
 
292
  drizzle->field_count= (uint) query->rows;
300
293
  return unpack_fields(query, drizzle->field_count, 1);
301
294
}
302
295
 
319
312
  end= strncpy(end+1, wild ? wild : "", 128) + 128;
320
313
 
321
314
  free_old_query(drizzle);
322
 
  if (simple_command(drizzle, COM_FIELD_LIST, (unsigned char*) buff,
 
315
  if (simple_command(drizzle, COM_FIELD_LIST, (uchar*) buff,
323
316
                     (uint32_t) (end-buff), 1) ||
324
317
      !(fields= (*drizzle->methods->list_fields)(drizzle)))
325
318
    return(NULL);
343
336
drizzle_list_processes(DRIZZLE *drizzle)
344
337
{
345
338
  DRIZZLE_DATA *fields;
346
 
  uint32_t field_count;
347
 
  unsigned char *pos;
 
339
  uint field_count;
 
340
  uchar *pos;
348
341
 
349
342
  if (simple_command(drizzle,COM_PROCESS_INFO,0,0,0))
350
343
    return(0);
351
344
  free_old_query(drizzle);
352
 
  pos=(unsigned char*) drizzle->net.read_pos;
353
 
  field_count=(uint32_t) net_field_length(&pos);
 
345
  pos=(uchar*) drizzle->net.read_pos;
 
346
  field_count=(uint) net_field_length(&pos);
354
347
  if (!(fields = (*drizzle->methods->read_rows)(drizzle,(DRIZZLE_FIELD*) 0, 7)))
355
348
    return(NULL);
356
349
  if (!(drizzle->fields=unpack_fields(fields, field_count, 0)))
362
355
 
363
356
 
364
357
int
365
 
drizzle_shutdown(DRIZZLE *drizzle)
 
358
drizzle_shutdown(DRIZZLE *drizzle, enum drizzle_enum_shutdown_level shutdown_level)
366
359
{
367
 
  return(simple_command(drizzle, COM_SHUTDOWN, 0, 0, 0));
 
360
  uchar level[1];
 
361
  level[0]= (uchar) shutdown_level;
 
362
  return(simple_command(drizzle, COM_SHUTDOWN, level, 1, 0));
368
363
}
369
364
 
370
365
 
371
366
int
372
 
drizzle_refresh(DRIZZLE *drizzle, uint32_t options)
 
367
drizzle_refresh(DRIZZLE *drizzle,uint options)
373
368
{
374
 
  unsigned char bits[1];
375
 
  bits[0]= (unsigned char) options;
 
369
  uchar bits[1];
 
370
  bits[0]= (uchar) options;
376
371
  return(simple_command(drizzle, COM_REFRESH, bits, 1, 0));
377
372
}
378
373
 
380
375
int32_t
381
376
drizzle_kill(DRIZZLE *drizzle, uint32_t pid)
382
377
{
383
 
  unsigned char buff[4];
 
378
  uchar buff[4];
384
379
  int4store(buff,pid);
385
380
  return(simple_command(drizzle,COM_PROCESS_KILL,buff,sizeof(buff),0));
386
381
}
389
384
int
390
385
drizzle_set_server_option(DRIZZLE *drizzle, enum enum_drizzle_set_option option)
391
386
{
392
 
  unsigned char buff[2];
393
 
  int2store(buff, (uint32_t) option);
 
387
  uchar buff[2];
 
388
  int2store(buff, (uint) option);
394
389
  return(simple_command(drizzle, COM_SET_OPTION, buff, sizeof(buff), 0));
395
390
}
396
391
 
400
395
  drizzle->net.read_pos[drizzle->packet_length]=0;  /* End of stat string */
401
396
  if (!drizzle->net.read_pos[0])
402
397
  {
403
 
    drizzle_set_error(drizzle, CR_WRONG_HOST_INFO, sqlstate_get_unknown());
 
398
    set_drizzle_error(drizzle, CR_WRONG_HOST_INFO, unknown_sqlstate);
404
399
    return drizzle->net.last_error;
405
400
  }
406
401
  return (char*) drizzle->net.read_pos;
432
427
}
433
428
 
434
429
 
435
 
uint32_t
 
430
uint
436
431
drizzle_get_proto_info(const DRIZZLE *drizzle)
437
432
{
438
433
  return (drizzle->protocol_version);
441
436
const char *
442
437
drizzle_get_client_info(void)
443
438
{
444
 
  return (char*) VERSION;
 
439
  return (char*) DRIZZLE_SERVER_VERSION;
445
440
}
446
441
 
447
442
uint32_t drizzle_get_client_version(void)
493
488
 
494
489
const char * drizzle_sqlstate(const DRIZZLE *drizzle)
495
490
{
496
 
  return drizzle ? drizzle->net.sqlstate : sqlstate_get_cant_connect();
 
491
  return drizzle ? drizzle->net.sqlstate : cant_connect_sqlstate;
497
492
}
498
493
 
499
494
uint32_t drizzle_warning_count(const DRIZZLE *drizzle)
521
516
 
522
517
void my_net_local_init(NET *net)
523
518
{
524
 
  net->max_packet=   (uint32_t) net_buffer_length;
 
519
  net->max_packet=   (uint) net_buffer_length;
525
520
  my_net_set_read_timeout(net, CLIENT_NET_READ_TIMEOUT);
526
521
  my_net_set_write_timeout(net, CLIENT_NET_WRITE_TIMEOUT);
527
522
  net->retry_count=  1;
528
 
  net->max_packet_size= (net_buffer_length > max_allowed_packet) ?
529
 
    net_buffer_length : max_allowed_packet;
 
523
  net->max_packet_size= max(net_buffer_length, max_allowed_packet);
530
524
}
531
525
 
532
526
/*
705
699
{
706
700
  if (drizzle->status != DRIZZLE_STATUS_READY)
707
701
  {
708
 
    drizzle_set_error(drizzle, CR_COMMANDS_OUT_OF_SYNC, sqlstate_get_unknown());
 
702
    set_drizzle_error(drizzle, CR_COMMANDS_OUT_OF_SYNC, unknown_sqlstate);
709
703
    return(1);
710
704
  }
711
705