525
526
free_rows(result->data);
526
527
/* TODO: free result->fields */
528
my_free((uchar*) result->row,MYF(0));
529
my_free((uchar*) result,MYF(0));
533
/****************************************************************************
534
Get options from my.cnf
535
****************************************************************************/
537
static const char *default_options[]=
539
"port","socket","compress","password","pipe", "timeout", "user",
540
"init-command", "host", "database", "return-found-rows",
541
"ssl-key" ,"ssl-cert" ,"ssl-ca" ,"ssl-capath",
542
"character-sets-dir", "default-character-set", "interactive-timeout",
543
"connect-timeout", "local-infile", "disable-local-infile",
544
"ssl-cipher", "max-allowed-packet", "protocol", "shared-memory-base-name",
545
"multi-results", "multi-statements", "multi-queries", "secure-auth",
546
"report-data-truncation",
550
static TYPELIB option_types={array_elements(default_options)-1,
551
"options",default_options, NULL};
553
const char *sql_protocol_names_lib[] =
554
{ "TCP", "SOCKET", "PIPE", "MEMORY", NullS };
555
TYPELIB sql_protocol_typelib = {array_elements(sql_protocol_names_lib)-1,"",
556
sql_protocol_names_lib, NULL};
558
static int add_init_command(struct st_drizzle_options *options, const char *cmd)
562
if (!options->init_commands)
564
options->init_commands= (DYNAMIC_ARRAY*)my_malloc(sizeof(DYNAMIC_ARRAY),
566
init_dynamic_array(options->init_commands,sizeof(char*),0,5 CALLER_INFO);
569
if (!(tmp= my_strdup(cmd,MYF(MY_WME))) ||
570
insert_dynamic(options->init_commands, (uchar*)&tmp))
572
my_free(tmp, MYF(MY_ALLOW_ZERO_PTR));
579
void drizzle_read_default_options(struct st_drizzle_options *options,
580
const char *filename,const char *group)
583
char *argv_buff[1],**argv;
584
const char *groups[3];
586
argc=1; argv=argv_buff; argv_buff[0]= (char*) "client";
587
groups[0]= (char*) "client"; groups[1]= (char*) group; groups[2]=0;
589
load_defaults(filename, groups, &argc, &argv);
590
if (argc != 1) /* If some default option */
595
if (option[0][0] == '-' && option[0][1] == '-')
597
char *end=strrchr(*option,'=');
602
*end=0; /* Remove '=' */
604
/* Change all '_' in variable name to '-' */
605
for (end= *option ; *(end= strrchr(end,'_')) ; )
607
switch (find_type(*option+2,&option_types,2)) {
610
options->port=atoi(opt_arg);
615
my_free(options->unix_socket,MYF(MY_ALLOW_ZERO_PTR));
616
options->unix_socket=my_strdup(opt_arg,MYF(MY_WME));
619
case 3: /* compress */
621
options->client_flag|= CLIENT_COMPRESS;
623
case 4: /* password */
626
my_free(options->password,MYF(MY_ALLOW_ZERO_PTR));
627
options->password=my_strdup(opt_arg,MYF(MY_WME));
630
case 20: /* connect_timeout */
631
case 6: /* timeout */
633
options->connect_timeout=atoi(opt_arg);
638
my_free(options->user,MYF(MY_ALLOW_ZERO_PTR));
639
options->user=my_strdup(opt_arg,MYF(MY_WME));
642
case 8: /* init-command */
643
add_init_command(options,opt_arg);
648
my_free(options->host,MYF(MY_ALLOW_ZERO_PTR));
649
options->host=my_strdup(opt_arg,MYF(MY_WME));
652
case 10: /* database */
655
my_free(options->db,MYF(MY_ALLOW_ZERO_PTR));
656
options->db=my_strdup(opt_arg,MYF(MY_WME));
659
case 12: /* return-found-rows */
660
options->client_flag|=CLIENT_FOUND_ROWS;
662
case 13: /* Ignore SSL options */
668
case 19: /* Interactive-timeout */
669
options->client_flag|= CLIENT_INTERACTIVE;
672
if (!opt_arg || atoi(opt_arg) != 0)
673
options->client_flag|= CLIENT_LOCAL_FILES;
675
options->client_flag&= ~CLIENT_LOCAL_FILES;
678
options->client_flag&= ~CLIENT_LOCAL_FILES;
680
case 24: /* max-allowed-packet */
682
options->max_allowed_packet= atoi(opt_arg);
684
case 25: /* protocol */
685
if ((options->protocol= find_type(opt_arg,
686
&sql_protocol_typelib,0)) <= 0)
688
fprintf(stderr, _("Unknown option to protocol: %s\n"), opt_arg);
692
case 27: /* multi-results */
693
options->client_flag|= CLIENT_MULTI_RESULTS;
695
case 28: /* multi-statements */
696
case 29: /* multi-queries */
697
options->client_flag|= CLIENT_MULTI_STATEMENTS | CLIENT_MULTI_RESULTS;
699
case 30: /* secure-auth */
700
options->secure_auth= true;
702
case 31: /* report-data-truncation */
703
options->report_data_truncation= opt_arg ? test(atoi(opt_arg)) : 1;
529
free((uchar*) result->row);
530
free((uchar*) result);
1326
1109
/* Save connection information */
1327
if (!my_multi_malloc(MYF(0),
1328
&drizzle->host_info, (uint) strlen(host_info)+1,
1329
&drizzle->host, (uint) strlen(host)+1,
1330
&drizzle->unix_socket,unix_socket ?
1331
(uint) strlen(unix_socket)+1 : (uint) 1,
1332
&drizzle->server_version,
1333
(uint) (end - (char*) net->read_pos),
1335
!(drizzle->user=my_strdup(user,MYF(0))) ||
1336
!(drizzle->passwd=my_strdup(passwd,MYF(0))))
1110
if (!(drizzle->host_info= (char *)malloc(strlen(host_info)+1+strlen(host)+1
1111
+(end - (char*) net->read_pos))) ||
1112
!(drizzle->user=strdup(user)) ||
1113
!(drizzle->passwd=strdup(passwd)))
1338
1115
set_drizzle_error(drizzle, CR_OUT_OF_MEMORY, unknown_sqlstate);
1118
drizzle->host= drizzle->host_info+strlen(host_info)+1;
1119
drizzle->server_version= drizzle->host+strlen(host)+1;
1341
1120
strcpy(drizzle->host_info,host_info);
1342
1121
strcpy(drizzle->host,host);
1344
strcpy(drizzle->unix_socket,unix_socket);
1346
drizzle->unix_socket=0;
1347
1122
strcpy(drizzle->server_version,(char*) net->read_pos+1);
1348
1123
drizzle->port=port;
1351
1126
Part 2: format and send client info to the server for access check
1354
1129
client_flag|=drizzle->options.client_flag;
1355
1130
client_flag|=CLIENT_CAPABILITIES;
1356
1131
if (client_flag & CLIENT_MULTI_STATEMENTS)
1543
1296
static void drizzle_close_free_options(DRIZZLE *drizzle)
1545
my_free(drizzle->options.user,MYF(MY_ALLOW_ZERO_PTR));
1546
my_free(drizzle->options.host,MYF(MY_ALLOW_ZERO_PTR));
1547
my_free(drizzle->options.password,MYF(MY_ALLOW_ZERO_PTR));
1548
my_free(drizzle->options.unix_socket,MYF(MY_ALLOW_ZERO_PTR));
1549
my_free(drizzle->options.db,MYF(MY_ALLOW_ZERO_PTR));
1550
my_free(drizzle->options.my_cnf_file,MYF(MY_ALLOW_ZERO_PTR));
1551
my_free(drizzle->options.my_cnf_group,MYF(MY_ALLOW_ZERO_PTR));
1552
my_free(drizzle->options.client_ip,MYF(MY_ALLOW_ZERO_PTR));
1553
if (drizzle->options.init_commands)
1555
DYNAMIC_ARRAY *init_commands= drizzle->options.init_commands;
1556
char **ptr= (char**)init_commands->buffer;
1557
char **end= ptr + init_commands->elements;
1558
for (; ptr<end; ptr++)
1559
my_free(*ptr,MYF(MY_WME));
1560
delete_dynamic(init_commands);
1561
my_free((char*)init_commands,MYF(MY_WME));
1298
if (drizzle->options.user != NULL)
1299
free(drizzle->options.user);
1300
if (drizzle->options.host != NULL)
1301
free(drizzle->options.host);
1302
if (drizzle->options.password != NULL)
1303
free(drizzle->options.password);
1304
if (drizzle->options.db != NULL)
1305
free(drizzle->options.db);
1306
if (drizzle->options.my_cnf_file != NULL)
1307
free(drizzle->options.my_cnf_file);
1308
if (drizzle->options.my_cnf_group != NULL)
1309
free(drizzle->options.my_cnf_group);
1310
if (drizzle->options.client_ip != NULL)
1311
free(drizzle->options.client_ip);
1563
1312
memset(&drizzle->options, 0, sizeof(drizzle->options));
1863
1618
drizzle->options.client_flag&= ~CLIENT_LOCAL_FILES;
1865
case DRIZZLE_INIT_COMMAND:
1866
add_init_command(&drizzle->options,arg);
1868
1620
case DRIZZLE_READ_DEFAULT_FILE:
1869
my_free(drizzle->options.my_cnf_file,MYF(MY_ALLOW_ZERO_PTR));
1870
drizzle->options.my_cnf_file=my_strdup(arg,MYF(MY_WME));
1621
if (drizzle->options.my_cnf_file != NULL)
1622
free(drizzle->options.my_cnf_file);
1623
drizzle->options.my_cnf_file=strdup(arg);
1872
1625
case DRIZZLE_READ_DEFAULT_GROUP:
1873
my_free(drizzle->options.my_cnf_group,MYF(MY_ALLOW_ZERO_PTR));
1874
drizzle->options.my_cnf_group=my_strdup(arg,MYF(MY_WME));
1626
if (drizzle->options.my_cnf_group != NULL)
1627
free(drizzle->options.my_cnf_group);
1628
drizzle->options.my_cnf_group=strdup(arg);
1876
1630
case DRIZZLE_OPT_PROTOCOL:
1877
1631
drizzle->options.protocol= *(const uint*) arg;