4
4
* Copyright (C) 2008 Eric Day (eday@oddments.org)
5
5
* All rights reserved.
7
* Redistribution and use in source and binary forms, with or without
8
* modification, are permitted provided that the following conditions are
11
* * Redistributions of source code must retain the above copyright
12
* notice, this list of conditions and the following disclaimer.
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
19
* * The names of its contributors may not be used to endorse or
20
* promote products derived from this software without specific prior
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.
7
* Use and distribution licensed under the BSD license. See
8
* the COPYING.BSD file in the root source directory for full text.
40
13
#include <stdlib.h>
95
68
drizzle_return_t ret;
96
sqlite_server *server= (sqlite_server*)malloc(sizeof(sqlite_server));
97
drizzle_con_st *con_listen= (drizzle_con_st*)malloc(sizeof(drizzle_con_st));
70
drizzle_con_st con_listen;
100
server->verbose= DRIZZLE_VERBOSE_NEVER;
73
server.verbose= DRIZZLE_VERBOSE_NEVER;
102
75
while((c = getopt(argc, argv, "c:h:mp:v")) != -1)
123
switch(server->verbose)
125
case DRIZZLE_VERBOSE_NEVER:
126
server->verbose= DRIZZLE_VERBOSE_FATAL;
128
case DRIZZLE_VERBOSE_FATAL:
129
server->verbose= DRIZZLE_VERBOSE_ERROR;
131
case DRIZZLE_VERBOSE_ERROR:
132
server->verbose= DRIZZLE_VERBOSE_INFO;
134
case DRIZZLE_VERBOSE_INFO:
135
server->verbose= DRIZZLE_VERBOSE_DEBUG;
137
case DRIZZLE_VERBOSE_DEBUG:
138
server->verbose= DRIZZLE_VERBOSE_CRAZY;
140
case DRIZZLE_VERBOSE_CRAZY:
141
case DRIZZLE_VERBOSE_MAX:
158
sqlite3_open(argv[optind], &(server->db));
159
if (server->db == NULL)
111
sqlite3_open(argv[optind], &(server.db));
112
if (server.db == NULL)
161
114
printf("sqlite3_open: could not open sqlite3 db\n");
165
if (drizzle_create(&(server->drizzle)) == NULL)
118
if (drizzle_create(&server.drizzle) == NULL)
167
120
printf("drizzle_create:NULL\n");
171
drizzle_add_options(&(server->drizzle), DRIZZLE_FREE_OBJECTS);
172
drizzle_set_verbose(&(server->drizzle), server->verbose);
124
drizzle_add_options(&server.drizzle, DRIZZLE_FREE_OBJECTS);
125
drizzle_set_verbose(&server.drizzle, server.verbose);
174
if (drizzle_con_create(&(server->drizzle), con_listen) == NULL)
127
if (drizzle_con_create(&server.drizzle, &con_listen) == NULL)
176
129
printf("drizzle_con_create:NULL\n");
180
drizzle_con_add_options(con_listen, DRIZZLE_CON_LISTEN);
181
drizzle_con_set_tcp(con_listen, host, port);
133
drizzle_con_add_options(&con_listen, DRIZZLE_CON_LISTEN);
134
drizzle_con_set_tcp(&con_listen, host, port);
184
drizzle_con_add_options(con_listen, DRIZZLE_CON_MYSQL);
137
drizzle_con_add_options(&con_listen, DRIZZLE_CON_MYSQL);
186
if (drizzle_con_listen(con_listen) != DRIZZLE_RETURN_OK)
139
if (drizzle_con_listen(&con_listen) != DRIZZLE_RETURN_OK)
188
printf("drizzle_con_listen:%s\n", drizzle_error(&(server->drizzle)));
141
printf("drizzle_con_listen:%s\n", drizzle_error(&server.drizzle));
194
(void)drizzle_con_accept(&(server->drizzle), &(server->con), &ret);
147
(void)drizzle_con_accept(&server.drizzle, &server.con, &ret);
195
148
if (ret != DRIZZLE_RETURN_OK)
197
printf("drizzle_con_accept:%s\n", drizzle_error(&(server->drizzle)));
150
printf("drizzle_con_accept:%s\n", drizzle_error(&server.drizzle));
203
drizzle_con_free(&(server->con));
156
drizzle_con_free(&server.con);
214
drizzle_con_free(con_listen);
215
drizzle_free(&(server->drizzle));
216
sqlite3_close(server->db);
167
drizzle_con_free(&con_listen);
168
drizzle_free(&server.drizzle);
169
sqlite3_close(server.db);
260
211
if (data != NULL)
263
data= (uint8_t *)drizzle_con_command_buffer(&(server->con), &command, &total, &ret);
214
data= drizzle_con_command_buffer(&(server->con), &command, &total, &ret);
264
215
if (ret == DRIZZLE_RETURN_LOST_CONNECTION ||
265
216
(ret == DRIZZLE_RETURN_OK && command == DRIZZLE_COMMAND_QUIT))