~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to libdrizzle/client.c

Merged in Jay's tree.

Show diffs side-by-side

added added

removed removed

Lines of Context:
320
320
  or packet is an error message
321
321
*****************************************************************************/
322
322
 
323
 
ulong
324
 
cli_safe_read(MYSQL *mysql)
 
323
uint32_t cli_safe_read(MYSQL *mysql)
325
324
{
326
325
  NET *net= &mysql->net;
327
326
  ulong len=0;
403
402
  }
404
403
}
405
404
 
406
 
my_bool
 
405
bool
407
406
cli_advanced_command(MYSQL *mysql, enum enum_server_command command,
408
 
                     const uchar *header, ulong header_length,
409
 
                     const uchar *arg, ulong arg_length, my_bool skip_check)
 
407
                     const unsigned char *header, uint32_t header_length,
 
408
                     const unsigned char *arg, uint32_t arg_length, bool skip_check)
410
409
{
411
410
  NET *net= &mysql->net;
412
411
  my_bool result= 1;
413
412
  init_sigpipe_variables
414
 
  my_bool stmt_skip= FALSE;
 
413
  my_bool stmt_skip= false;
415
414
  DBUG_ENTER("cli_advanced_command");
416
415
 
417
416
  /* Don't give sigpipe errors if the client doesn't want them */
553
552
        (*mysql->methods->flush_use_result)(mysql);
554
553
        mysql->status=MYSQL_STATUS_READY;
555
554
        if (mysql->unbuffered_fetch_owner)
556
 
          *mysql->unbuffered_fetch_owner= TRUE;
 
555
          *mysql->unbuffered_fetch_owner= true;
557
556
      }
558
557
    }
559
558
    free_rows(result->data);
758
757
          options->client_flag|= CLIENT_MULTI_STATEMENTS | CLIENT_MULTI_RESULTS;
759
758
          break;
760
759
        case 30: /* secure-auth */
761
 
          options->secure_auth= TRUE;
 
760
          options->secure_auth= true;
762
761
          break;
763
762
        case 31: /* report-data-truncation */
764
763
          options->report_data_truncation= opt_arg ? test(atoi(opt_arg)) : 1;
780
779
  else the lengths are calculated from the offset between pointers.
781
780
**************************************************************************/
782
781
 
783
 
static void cli_fetch_lengths(ulong *to, MYSQL_ROW column,
784
 
                              unsigned int field_count)
 
782
static void cli_fetch_lengths(uint32_t *to, MYSQL_ROW column, uint32_t field_count)
785
783
786
 
  ulong *prev_length;
 
784
  uint32_t *prev_length;
787
785
  char *start=0;
788
786
  MYSQL_ROW end;
789
787
 
812
810
{
813
811
  MYSQL_ROWS    *row;
814
812
  MYSQL_FIELD   *field,*result;
815
 
  ulong lengths[9];                             /* Max of fields */
 
813
  uint32_t lengths[9];                          /* Max of fields */
816
814
  DBUG_ENTER("unpack_fields");
817
815
 
818
816
  field= result= (MYSQL_FIELD*) alloc_root(alloc,
1016
1014
*/
1017
1015
 
1018
1016
 
1019
 
static int
1020
 
read_one_row(MYSQL *mysql,uint fields,MYSQL_ROW row, ulong *lengths)
 
1017
static int32_t
 
1018
read_one_row(MYSQL *mysql, uint32_t fields, MYSQL_ROW row, uint32_t *lengths)
1021
1019
{
1022
1020
  uint field;
1023
1021
  ulong pkt_len,len;
1104
1102
#endif
1105
1103
 
1106
1104
  mysql->options.methods_to_use= MYSQL_OPT_GUESS_CONNECTION;
1107
 
  mysql->options.report_data_truncation= TRUE;  /* default */
 
1105
  mysql->options.report_data_truncation= true;  /* default */
1108
1106
 
1109
1107
  /*
1110
1108
    By default we don't reconnect because it could silently corrupt data (after
1134
1132
 
1135
1133
#define strdup_if_not_null(A) (A) == 0 ? 0 : my_strdup((A),MYF(MY_WME))
1136
1134
 
1137
 
my_bool STDCALL
1138
 
mysql_ssl_set(MYSQL *mysql __attribute__((unused)) ,
1139
 
              const char *key __attribute__((unused)),
1140
 
              const char *cert __attribute__((unused)),
1141
 
              const char *ca __attribute__((unused)),
1142
 
              const char *capath __attribute__((unused)),
1143
 
              const char *cipher __attribute__((unused)))
1144
 
{
1145
 
  DBUG_ENTER("mysql_ssl_set");
1146
 
  DBUG_RETURN(0);
1147
 
}
1148
 
 
1149
 
 
1150
 
/*
1151
 
  Free strings in the SSL structure and clear 'use_ssl' flag.
1152
 
  NB! Errors are not reported until you do mysql_real_connect.
1153
 
*/
1154
 
 
1155
 
/*
1156
 
  Return the SSL cipher (if any) used for current
1157
 
  connection to the server.
1158
 
 
1159
 
  SYNOPSYS
1160
 
    mysql_get_ssl_cipher()
1161
 
      mysql pointer to the mysql connection
1162
 
 
1163
 
*/
1164
 
 
1165
 
const char * STDCALL
1166
 
mysql_get_ssl_cipher(MYSQL *mysql __attribute__((unused)))
1167
 
{
1168
 
  DBUG_ENTER("mysql_get_ssl_cipher");
1169
 
  DBUG_RETURN(NULL);
1170
 
}
1171
 
 
1172
 
 
1173
 
/*
1174
 
  Check the server's (subject) Common Name against the
1175
 
  hostname we connected to
1176
 
 
1177
 
  SYNOPSIS
1178
 
  ssl_verify_server_cert()
1179
 
    vio              pointer to a SSL connected vio
1180
 
    server_hostname  name of the server that we connected to
1181
 
 
1182
 
  RETURN VALUES
1183
 
   0 Success
1184
 
   1 Failed to validate server
1185
 
 
1186
 
 */
1187
 
 
1188
 
 
1189
1135
/*
1190
1136
  Note that the mysql argument must be initialized with mysql_init()
1191
1137
  before calling mysql_real_connect !
1192
1138
*/
1193
1139
 
1194
 
static my_bool cli_read_query_result(MYSQL *mysql);
 
1140
static bool cli_read_query_result(MYSQL *mysql);
1195
1141
static MYSQL_RES *cli_use_result(MYSQL *mysql);
1196
1142
 
1197
1143
static MYSQL_METHODS client_methods=
1286
1232
MYSQL * STDCALL
1287
1233
CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,const char *host, const char *user,
1288
1234
                       const char *passwd, const char *db,
1289
 
                       uint port, const char *unix_socket,ulong client_flag)
 
1235
                       uint32_t port, const char *unix_socket, uint32_t client_flag)
1290
1236
{
1291
1237
  char          buff[NAME_LEN+USERNAME_LENGTH+100];
1292
1238
  char          *end,*host_info=NULL;
1293
 
  ulong         pkt_length;
 
1239
  uint32_t         pkt_length;
1294
1240
  NET           *net= &mysql->net;
1295
1241
  struct        sockaddr_un UNIXaddr;
1296
1242
  init_sigpipe_variables
1526
1472
    set_mysql_error(mysql, CR_OUT_OF_MEMORY, unknown_sqlstate);
1527
1473
    goto error;
1528
1474
  }
1529
 
  vio_keepalive(net->vio,TRUE);
 
1475
  vio_keepalive(net->vio,true);
1530
1476
 
1531
1477
  /* If user set read_timeout, let it override the default */
1532
1478
  if (mysql->options.read_timeout)
1689
1635
  end= strend(end) + 1;
1690
1636
  if (passwd[0])
1691
1637
  {
1692
 
    if (mysql->server_capabilities & CLIENT_SECURE_CONNECTION)
1693
1638
    {
1694
1639
      *end++= SCRAMBLE_LENGTH;
1695
1640
      scramble(end, mysql->scramble, passwd);
1696
1641
      end+= SCRAMBLE_LENGTH;
1697
1642
    }
1698
 
    else
1699
 
    {
1700
 
      scramble_323(end, mysql->scramble, passwd);
1701
 
      end+= SCRAMBLE_LENGTH_323 + 1;
1702
 
    }
1703
1643
  }
1704
1644
  else
1705
1645
    *end++= '\0';                               /* empty password */
1736
1676
    goto error;
1737
1677
  }
1738
1678
 
1739
 
  if (pkt_length == 1 && net->read_pos[0] == 254 && 
1740
 
      mysql->server_capabilities & CLIENT_SECURE_CONNECTION)
1741
 
  {
1742
 
    /*
1743
 
      By sending this very specific reply server asks us to send scrambled
1744
 
      password in old format.
1745
 
    */
1746
 
    scramble_323(buff, mysql->scramble, passwd);
1747
 
    if (my_net_write(net, (uchar*) buff, SCRAMBLE_LENGTH_323 + 1) ||
1748
 
        net_flush(net))
1749
 
    {
1750
 
      set_mysql_extended_error(mysql, CR_SERVER_LOST, unknown_sqlstate,
1751
 
                               ER(CR_SERVER_LOST_EXTENDED),
1752
 
                               "sending password information",
1753
 
                               errno);
1754
 
      goto error;
1755
 
    }
1756
 
    /* Read what server thinks about out new auth message report */
1757
 
    if (cli_safe_read(mysql) == packet_error)
1758
 
    {
1759
 
      if (mysql->net.last_errno == CR_SERVER_LOST)
1760
 
        set_mysql_extended_error(mysql, CR_SERVER_LOST, unknown_sqlstate,
1761
 
                                 ER(CR_SERVER_LOST_EXTENDED),
1762
 
                                 "reading final connect information",
1763
 
                                 errno);
1764
 
      goto error;
1765
 
    }
1766
 
  }
1767
 
 
1768
1679
  if (client_flag & CLIENT_COMPRESS)            /* We will use compression */
1769
1680
    net->compress=1;
1770
1681
 
1973
1884
}
1974
1885
 
1975
1886
 
1976
 
static my_bool cli_read_query_result(MYSQL *mysql)
 
1887
static bool cli_read_query_result(MYSQL *mysql)
1977
1888
{
1978
1889
  uchar *pos;
1979
1890
  ulong field_count;
2051
1962
  finish processing it.
2052
1963
*/
2053
1964
 
2054
 
int STDCALL
2055
 
mysql_send_query(MYSQL* mysql, const char* query, ulong length)
 
1965
int32_t STDCALL
 
1966
mysql_send_query(MYSQL* mysql, const char* query, uint32_t length)
2056
1967
{
2057
1968
  DBUG_ENTER("mysql_send_query");
2058
1969
  DBUG_RETURN(simple_command(mysql, COM_QUERY, (uchar*) query, length, 1));
2059
1970
}
2060
1971
 
2061
1972
 
2062
 
int STDCALL
2063
 
mysql_real_query(MYSQL *mysql, const char *query, ulong length)
 
1973
int32_t STDCALL
 
1974
mysql_real_query(MYSQL *mysql, const char *query, uint32_t length)
2064
1975
{
2065
1976
  DBUG_ENTER("mysql_real_query");
2066
 
  DBUG_PRINT("enter",("handle: 0x%lx", (long) mysql));
 
1977
  DBUG_PRINT("enter",("handle: 0x%lx", (int32_t) mysql));
2067
1978
  DBUG_PRINT("query",("Query = '%-.4096s'",query));
2068
1979
 
2069
1980
  if (mysql_send_query(mysql,query,length))
2099
2010
    DBUG_RETURN(0);
2100
2011
  }
2101
2012
  result->methods= mysql->methods;
2102
 
  result->eof=1;                                /* Marker for buffered */
2103
 
  result->lengths=(ulong*) (result+1);
 
2013
  result->eof= 1;                               /* Marker for buffered */
 
2014
  result->lengths= (uint32_t*) (result+1);
2104
2015
  if (!(result->data=
2105
2016
        (*mysql->methods->read_rows)(mysql,mysql->fields,mysql->field_count)))
2106
2017
  {
2147
2058
                                      sizeof(ulong)*mysql->field_count,
2148
2059
                                      MYF(MY_WME | MY_ZEROFILL))))
2149
2060
    DBUG_RETURN(0);
2150
 
  result->lengths=(ulong*) (result+1);
 
2061
  result->lengths=(uint32_t*) (result+1);
2151
2062
  result->methods= mysql->methods;
2152
2063
  if (!(result->row=(MYSQL_ROW)
2153
2064
        my_malloc(sizeof(result->row[0])*(mysql->field_count+1), MYF(MY_WME))))
2228
2139
  else the lengths are calculated from the offset between pointers.
2229
2140
**************************************************************************/
2230
2141
 
2231
 
ulong * STDCALL
 
2142
uint32_t * STDCALL
2232
2143
mysql_fetch_lengths(MYSQL_RES *res)
2233
2144
{
2234
2145
  MYSQL_ROW column;
2373
2284
   Signed number > 323000
2374
2285
*/
2375
2286
 
2376
 
ulong STDCALL
 
2287
uint32_t STDCALL
2377
2288
mysql_get_server_version(MYSQL *mysql)
2378
2289
{
2379
2290
  uint major, minor, version;