~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to examples/proxy.c

  • Committer: lbieber
  • Date: 2010-10-01 12:16:18 UTC
  • mfrom: (1802.1.1 fix-bug-651256)
  • Revision ID: lbieber@orisndriz08-20101001121618-uqcboygpjwbiglem
Merge Vijay - fix bug 651256 - Remove --help-extended

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
 * Copyright (C) 2008 Eric Day (eday@oddments.org)
5
5
 * All rights reserved.
6
6
 *
7
 
 * Redistribution and use in source and binary forms, with or without
8
 
 * modification, are permitted provided that the following conditions are
9
 
 * met:
10
 
 *
11
 
 *     * Redistributions of source code must retain the above copyright
12
 
 * notice, this list of conditions and the following disclaimer.
13
 
 *
14
 
 *     * Redistributions in binary form must reproduce the above
15
 
 * copyright notice, this list of conditions and the following disclaimer
16
 
 * in the documentation and/or other materials provided with the
17
 
 * distribution.
18
 
 *
19
 
 *     * The names of its contributors may not be used to endorse or
20
 
 * promote products derived from this software without specific prior
21
 
 * written permission.
22
 
 *
23
 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24
 
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25
 
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26
 
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27
 
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28
 
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29
 
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30
 
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31
 
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32
 
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33
 
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34
 
 *
 
7
 * Use and distribution licensed under the BSD license.  See
 
8
 * the COPYING.BSD file in the root source directory for full text.
35
9
 */
36
10
 
37
 
 
38
 
#include "config.h"
39
 
 
40
11
#include <errno.h>
41
12
#include <stdio.h>
42
13
#include <stdlib.h>
74
45
  drizzle_verbose_t verbose= DRIZZLE_VERBOSE_NEVER;
75
46
  drizzle_return_t ret;
76
47
  drizzle_st drizzle;
77
 
  drizzle_con_st *con_listen= (drizzle_con_st*)malloc(sizeof(drizzle_con_st));
78
 
  drizzle_con_st *server= (drizzle_con_st*)malloc(sizeof(drizzle_con_st));
79
 
  drizzle_con_st *client= (drizzle_con_st*)malloc(sizeof(drizzle_con_st));
 
48
  drizzle_con_st con_listen;
 
49
  drizzle_con_st server;
 
50
  drizzle_con_st client;
80
51
  drizzle_result_st server_result;
81
52
  drizzle_result_st client_result;
82
53
  drizzle_column_st column;
114
85
      break;
115
86
 
116
87
    case 'v':
117
 
      switch(verbose)
118
 
      {
119
 
      case DRIZZLE_VERBOSE_NEVER:
120
 
        verbose= DRIZZLE_VERBOSE_FATAL;
121
 
        break;
122
 
      case DRIZZLE_VERBOSE_FATAL:
123
 
        verbose= DRIZZLE_VERBOSE_ERROR;
124
 
        break;
125
 
      case DRIZZLE_VERBOSE_ERROR:
126
 
        verbose= DRIZZLE_VERBOSE_INFO;
127
 
        break;
128
 
      case DRIZZLE_VERBOSE_INFO:
129
 
        verbose= DRIZZLE_VERBOSE_DEBUG;
130
 
        break;
131
 
      case DRIZZLE_VERBOSE_DEBUG:
132
 
        verbose= DRIZZLE_VERBOSE_CRAZY;
133
 
        break;
134
 
      case DRIZZLE_VERBOSE_CRAZY:
135
 
      case DRIZZLE_VERBOSE_MAX:
136
 
        break;
137
 
      }
 
88
      verbose++;
138
89
      break;
139
90
 
140
91
    default:
161
112
  drizzle_add_options(&drizzle, DRIZZLE_FREE_OBJECTS);
162
113
  drizzle_set_verbose(&drizzle, verbose);
163
114
 
164
 
  if (drizzle_con_create(&drizzle, con_listen) == NULL)
 
115
  if (drizzle_con_create(&drizzle, &con_listen) == NULL)
165
116
  {
166
117
    printf("drizzle_con_create:NULL\n");
167
118
    return 1;
168
119
  }
169
120
 
170
 
  drizzle_con_add_options(con_listen, DRIZZLE_CON_LISTEN);
171
 
  drizzle_con_set_tcp(con_listen, server_host, server_port);
 
121
  drizzle_con_add_options(&con_listen, DRIZZLE_CON_LISTEN);
 
122
  drizzle_con_set_tcp(&con_listen, server_host, server_port);
172
123
 
173
124
  if (server_mysql)
174
 
    drizzle_con_add_options(con_listen, DRIZZLE_CON_MYSQL);
 
125
    drizzle_con_add_options(&con_listen, DRIZZLE_CON_MYSQL);
175
126
 
176
 
  if (drizzle_con_listen(con_listen) != DRIZZLE_RETURN_OK)
 
127
  if (drizzle_con_listen(&con_listen) != DRIZZLE_RETURN_OK)
177
128
  {
178
129
    printf("drizzle_con_listen:%s\n", drizzle_error(&drizzle));
179
130
    return 1;
181
132
 
182
133
  while (1)
183
134
  {
184
 
    (void)drizzle_con_accept(&drizzle, server, &ret);
 
135
    (void)drizzle_con_accept(&drizzle, &server, &ret);
185
136
    if (ret != DRIZZLE_RETURN_OK)
186
137
    {
187
138
      printf("drizzle_con_accept:%s\n", drizzle_error(&drizzle));
188
139
      return 1;
189
140
    }
190
141
 
191
 
    if (drizzle_con_create(&drizzle, client) == NULL)
 
142
    if (drizzle_con_create(&drizzle, &client) == NULL)
192
143
    {
193
144
      printf("drizzle_con_create:NULL\n");
194
145
      return 1;
195
146
    }
196
147
 
197
 
    drizzle_con_add_options(client,
 
148
    drizzle_con_add_options(&client,
198
149
                            DRIZZLE_CON_RAW_PACKET | DRIZZLE_CON_RAW_SCRAMBLE);
199
150
    if (client_mysql)
200
 
      drizzle_con_add_options(client, DRIZZLE_CON_MYSQL);
201
 
    drizzle_con_set_tcp(client, client_host, client_port);
 
151
      drizzle_con_add_options(&client, DRIZZLE_CON_MYSQL);
 
152
    drizzle_con_set_tcp(&client, client_host, client_port);
202
153
 
203
 
    ret= drizzle_con_connect(client);
 
154
    ret= drizzle_con_connect(&client);
204
155
    if (ret != DRIZZLE_RETURN_OK)
205
156
    {
206
157
      printf("drizzle_con_connect:%s\n", drizzle_error(&drizzle));
207
158
      return 1;
208
159
    }
209
160
 
210
 
    proxy(&drizzle, server, client, &server_result, &client_result, &column);
 
161
    proxy(&drizzle, &server, &client, &server_result, &client_result, &column);
211
162
 
212
 
    drizzle_con_free(client);
213
 
    drizzle_con_free(server);
 
163
    drizzle_con_free(&client);
 
164
    drizzle_con_free(&server);
214
165
 
215
166
    if (count > 0)
216
167
    {
221
172
    }
222
173
  }
223
174
 
224
 
  drizzle_con_free(con_listen);
 
175
  drizzle_con_free(&con_listen);
225
176
  drizzle_free(&drizzle);
226
177
 
227
 
  free(con_listen);
228
 
  free(server);
229
 
  free(client);
230
 
 
231
178
  return 0;
232
179
}
233
180
 
237
184
{
238
185
  drizzle_return_t ret;
239
186
  drizzle_command_t command;
240
 
  uint8_t *data;
 
187
  const uint8_t *data;
241
188
  size_t offset;
242
189
  size_t size;
243
190
  size_t total;
290
237
 
291
238
    while (1)
292
239
    {
293
 
      data= (uint8_t *)drizzle_con_command_read(server, &command, &offset, &size, &total,
 
240
      data= drizzle_con_command_read(server, &command, &offset, &size, &total,
294
241
                                     &ret);
295
242
      if (ret == DRIZZLE_RETURN_LOST_CONNECTION)
296
243
        return;