~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to examples/proxy.c

  • Committer: Brian Aker
  • Date: 2010-09-12 01:42:27 UTC
  • mto: (1759.2.1 build)
  • mto: This revision was merged to the branch mainline in revision 1762.
  • Revision ID: brian@tangent.org-20100912014227-krt6d9z5ohqrokhb
Add two plugins to handle the string and math functions.

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 file in this directory for full text.
35
9
 */
36
10
 
37
 
 
38
11
#include <errno.h>
39
12
#include <stdio.h>
40
13
#include <stdlib.h>
72
45
  drizzle_verbose_t verbose= DRIZZLE_VERBOSE_NEVER;
73
46
  drizzle_return_t ret;
74
47
  drizzle_st drizzle;
75
 
  drizzle_con_st *con_listen= (drizzle_con_st*)malloc(sizeof(drizzle_con_st));
76
 
  drizzle_con_st *server= (drizzle_con_st*)malloc(sizeof(drizzle_con_st));
77
 
  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;
78
51
  drizzle_result_st server_result;
79
52
  drizzle_result_st client_result;
80
53
  drizzle_column_st column;
139
112
  drizzle_add_options(&drizzle, DRIZZLE_FREE_OBJECTS);
140
113
  drizzle_set_verbose(&drizzle, verbose);
141
114
 
142
 
  if (drizzle_con_create(&drizzle, con_listen) == NULL)
 
115
  if (drizzle_con_create(&drizzle, &con_listen) == NULL)
143
116
  {
144
117
    printf("drizzle_con_create:NULL\n");
145
118
    return 1;
146
119
  }
147
120
 
148
 
  drizzle_con_add_options(con_listen, DRIZZLE_CON_LISTEN);
149
 
  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);
150
123
 
151
124
  if (server_mysql)
152
 
    drizzle_con_add_options(con_listen, DRIZZLE_CON_MYSQL);
 
125
    drizzle_con_add_options(&con_listen, DRIZZLE_CON_MYSQL);
153
126
 
154
 
  if (drizzle_con_listen(con_listen) != DRIZZLE_RETURN_OK)
 
127
  if (drizzle_con_listen(&con_listen) != DRIZZLE_RETURN_OK)
155
128
  {
156
129
    printf("drizzle_con_listen:%s\n", drizzle_error(&drizzle));
157
130
    return 1;
159
132
 
160
133
  while (1)
161
134
  {
162
 
    (void)drizzle_con_accept(&drizzle, server, &ret);
 
135
    (void)drizzle_con_accept(&drizzle, &server, &ret);
163
136
    if (ret != DRIZZLE_RETURN_OK)
164
137
    {
165
138
      printf("drizzle_con_accept:%s\n", drizzle_error(&drizzle));
166
139
      return 1;
167
140
    }
168
141
 
169
 
    if (drizzle_con_create(&drizzle, client) == NULL)
 
142
    if (drizzle_con_create(&drizzle, &client) == NULL)
170
143
    {
171
144
      printf("drizzle_con_create:NULL\n");
172
145
      return 1;
173
146
    }
174
147
 
175
 
    drizzle_con_add_options(client,
 
148
    drizzle_con_add_options(&client,
176
149
                            DRIZZLE_CON_RAW_PACKET | DRIZZLE_CON_RAW_SCRAMBLE);
177
150
    if (client_mysql)
178
 
      drizzle_con_add_options(client, DRIZZLE_CON_MYSQL);
179
 
    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);
180
153
 
181
 
    ret= drizzle_con_connect(client);
 
154
    ret= drizzle_con_connect(&client);
182
155
    if (ret != DRIZZLE_RETURN_OK)
183
156
    {
184
157
      printf("drizzle_con_connect:%s\n", drizzle_error(&drizzle));
185
158
      return 1;
186
159
    }
187
160
 
188
 
    proxy(&drizzle, server, client, &server_result, &client_result, &column);
 
161
    proxy(&drizzle, &server, &client, &server_result, &client_result, &column);
189
162
 
190
 
    drizzle_con_free(client);
191
 
    drizzle_con_free(server);
 
163
    drizzle_con_free(&client);
 
164
    drizzle_con_free(&server);
192
165
 
193
166
    if (count > 0)
194
167
    {
199
172
    }
200
173
  }
201
174
 
202
 
  drizzle_con_free(con_listen);
 
175
  drizzle_con_free(&con_listen);
203
176
  drizzle_free(&drizzle);
204
177
 
205
 
  free(con_listen);
206
 
  free(server);
207
 
  free(client);
208
 
 
209
178
  return 0;
210
179
}
211
180