~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to examples/proxy.cc

  • Committer: Brian Aker
  • Date: 2011-11-27 01:25:57 UTC
  • mto: This revision was merged to the branch mainline in revision 2465.
  • Revision ID: brian@tangent.org-20111127012557-vxph9h1v32v3m1bz
Move result over to being behind API.

Show diffs side-by-side

added added

removed removed

Lines of Context:
54
54
  return; \
55
55
}
56
56
 
57
 
static void proxy(drizzle_st *drizzle, drizzle_con_st *server,
58
 
                  drizzle_con_st *client, drizzle_result_st *server_result,
59
 
                  drizzle_result_st *client_result, drizzle_column_st *column);
 
57
static void proxy(drizzle_st *drizzle,
 
58
                  drizzle_con_st *server,
 
59
                  drizzle_con_st *client,
 
60
                  drizzle_column_st *column);
60
61
 
61
62
int main(int argc, char *argv[])
62
63
{
71
72
  drizzle_verbose_t verbose= DRIZZLE_VERBOSE_NEVER;
72
73
  drizzle_return_t ret;
73
74
  drizzle_st *drizzle;
74
 
  drizzle_result_st server_result;
75
75
  drizzle_result_st client_result;
76
76
  drizzle_column_st column;
77
77
 
207
207
      return 1;
208
208
    }
209
209
 
210
 
    proxy(drizzle, server, client, &server_result, &client_result, &column);
 
210
    proxy(drizzle, server, client, &column);
211
211
 
212
212
    drizzle_con_free(client);
213
213
    drizzle_con_free(server);
228
228
}
229
229
 
230
230
static void proxy(drizzle_st *drizzle, drizzle_con_st *server,
231
 
                  drizzle_con_st *client, drizzle_result_st *server_result,
232
 
                  drizzle_result_st *client_result, drizzle_column_st *column)
 
231
                  drizzle_con_st *client,
 
232
                  drizzle_column_st *column)
233
233
{
234
234
  drizzle_return_t ret;
235
235
  drizzle_command_t command;
243
243
 
244
244
  /* Handshake packets. */
245
245
  ret= drizzle_handshake_server_read(client);
246
 
  DRIZZLE_RETURN_CHECK(ret, "drizzle_handshake_server_read", drizzle)
 
246
  DRIZZLE_RETURN_CHECK(ret, "drizzle_handshake_server_read", drizzle);
247
247
 
248
248
  drizzle_con_copy_handshake(server, client);
249
249
 
250
250
  ret= drizzle_handshake_server_write(server);
251
 
  DRIZZLE_RETURN_CHECK(ret, "drizzle_handshake_server_write", drizzle)
 
251
  DRIZZLE_RETURN_CHECK(ret, "drizzle_handshake_server_write", drizzle);
252
252
 
253
253
  ret= drizzle_handshake_client_read(server);
254
 
  DRIZZLE_RETURN_CHECK(ret, "drizzle_handshake_client_read", drizzle)
 
254
  DRIZZLE_RETURN_CHECK(ret, "drizzle_handshake_client_read", drizzle);
255
255
 
256
256
  drizzle_con_copy_handshake(client, server);
257
257
 
258
258
  ret= drizzle_handshake_client_write(client);
259
 
  DRIZZLE_RETURN_CHECK(ret, "drizzle_handshake_client_write", drizzle)
 
259
  DRIZZLE_RETURN_CHECK(ret, "drizzle_handshake_client_write", drizzle);
260
260
 
261
 
  (void)drizzle_result_read(client, client_result, &ret);
262
 
  DRIZZLE_RETURN_CHECK(ret, "drizzle_result_read", drizzle)
 
261
  drizzle_result_st *client_result= drizzle_result_read(client, NULL, &ret);
 
262
  DRIZZLE_RETURN_CHECK(ret, "drizzle_result_read", drizzle);
263
263
 
264
264
  drizzle_con_set_status(server, drizzle_con_status(client));
265
265
 
266
 
  if (drizzle_result_clone(server, server_result, client_result) == NULL)
267
 
    DRIZZLE_RETURN_ERROR("drizzle_result_clone", drizzle)
 
266
  drizzle_result_st *server_result;
 
267
  if ((server_result= drizzle_result_clone(server, client_result)) == NULL)
 
268
  {
 
269
    DRIZZLE_RETURN_ERROR("drizzle_result_clone", drizzle);
 
270
  }
268
271
 
269
272
  ret= drizzle_result_write(server, server_result, true);
270
 
  DRIZZLE_RETURN_CHECK(ret, "drizzle_result_write", drizzle)
 
273
  DRIZZLE_RETURN_CHECK(ret, "drizzle_result_write", drizzle);
271
274
 
272
275
  if (drizzle_result_error_code(client_result) != 0 ||
273
276
      drizzle_result_eof(client_result))
286
289
 
287
290
    while (1)
288
291
    {
289
 
      data= (uint8_t *)drizzle_con_command_read(server, &command, &offset, &size, &total,
290
 
                                     &ret);
 
292
      data= (uint8_t *)drizzle_con_command_read(server, &command, &offset, &size, &total, &ret);
291
293
      if (ret == DRIZZLE_RETURN_LOST_CONNECTION)
 
294
      {
292
295
        return;
293
 
 
294
 
      DRIZZLE_RETURN_CHECK(ret, "drizzle_con_command_read", drizzle)
295
 
 
296
 
      (void)drizzle_con_command_write(client, NULL, command, data, size, total,
297
 
                                      &ret);
298
 
      DRIZZLE_RETURN_CHECK(ret, "drizzle_con_command_write", drizzle)
 
296
      }
 
297
 
 
298
      DRIZZLE_RETURN_CHECK(ret, "drizzle_con_command_read", drizzle);
 
299
 
 
300
      (void)drizzle_con_command_write(client, NULL, command, data, size, total, &ret);
 
301
      DRIZZLE_RETURN_CHECK(ret, "drizzle_con_command_write", drizzle);
299
302
 
300
303
      if ((offset + size) == total)
301
304
        break;
302
305
    }
303
306
 
304
307
    if (command == DRIZZLE_COMMAND_QUIT)
 
308
    {
305
309
      return;
 
310
    }
306
311
    else if (command == DRIZZLE_COMMAND_FIELD_LIST)
307
312
    {
308
 
      if (drizzle_result_create(client, client_result) == NULL)
 
313
      if ((client_result= drizzle_result_create(client)) == NULL)
 
314
      {
309
315
        DRIZZLE_RETURN_ERROR("drizzle_result_create", drizzle)
 
316
      }
310
317
 
311
 
      if (drizzle_result_create(server, server_result) == NULL)
312
 
        DRIZZLE_RETURN_ERROR("drizzle_result_create", drizzle)
 
318
      if ((server_result= drizzle_result_create(server)) == NULL)
 
319
      {
 
320
        DRIZZLE_RETURN_ERROR("drizzle_result_create", drizzle);
 
321
      }
313
322
    }
314
323
    else
315
324
    {
316
325
      (void)drizzle_result_read(client, client_result, &ret);
317
 
      DRIZZLE_RETURN_CHECK(ret, "drizzle_result_read", drizzle)
 
326
      DRIZZLE_RETURN_CHECK(ret, "drizzle_result_read", drizzle);
318
327
 
319
328
      drizzle_con_set_status(server, drizzle_con_status(client));
320
 
      if (drizzle_result_clone(server, server_result, client_result) == NULL)
321
 
        DRIZZLE_RETURN_ERROR("drizzle_result_clone", drizzle)
 
329
      if ((server_result= drizzle_result_clone(server, client_result)) == NULL)
 
330
      {
 
331
        DRIZZLE_RETURN_ERROR("drizzle_result_clone", drizzle);
 
332
      }
322
333
 
323
334
      if (drizzle_result_column_count(client_result) == 0)
324
335
      {
325
336
        /* Simple result with no column, row, or field data. */
326
337
        ret= drizzle_result_write(server, server_result, true);
327
 
        DRIZZLE_RETURN_CHECK(ret, "drizzle_result_write", drizzle)
 
338
        DRIZZLE_RETURN_CHECK(ret, "drizzle_result_write", drizzle);
328
339
 
329
340
        continue;
330
341
      }
331
342
 
332
343
      ret= drizzle_result_write(server, server_result, false);
333
 
      DRIZZLE_RETURN_CHECK(ret, "drizzle_result_write", drizzle)
 
344
      DRIZZLE_RETURN_CHECK(ret, "drizzle_result_write", drizzle);
334
345
    }
335
346
 
336
347
    /* Columns. */
338
349
    {
339
350
      if (drizzle_column_read(client_result, column, &ret) == NULL)
340
351
      {
341
 
        DRIZZLE_RETURN_CHECK(ret, "drizzle_column_read", drizzle)
 
352
        DRIZZLE_RETURN_CHECK(ret, "drizzle_column_read", drizzle);
342
353
        break;
343
354
      }
344
355
 
345
 
      DRIZZLE_RETURN_CHECK(ret, "drizzle_column_read", drizzle)
 
356
      DRIZZLE_RETURN_CHECK(ret, "drizzle_column_read", drizzle);
346
357
 
347
358
      ret= drizzle_column_write(server_result, column);
348
 
      DRIZZLE_RETURN_CHECK(ret, "drizzle_column_write", drizzle)
 
359
      DRIZZLE_RETURN_CHECK(ret, "drizzle_column_write", drizzle);
349
360
 
350
361
      drizzle_column_free(column);
351
362
    }
356
367
    if (command == DRIZZLE_COMMAND_FIELD_LIST)
357
368
    {
358
369
      ret= drizzle_result_write(server, server_result, true);
359
 
      DRIZZLE_RETURN_CHECK(ret, "drizzle_result_write", drizzle)
 
370
      DRIZZLE_RETURN_CHECK(ret, "drizzle_result_write", drizzle);
360
371
      continue;
361
372
    }
362
373
    else
363
374
    {
364
375
      ret= drizzle_result_write(server, server_result, false);
365
 
      DRIZZLE_RETURN_CHECK(ret, "drizzle_result_write", drizzle)
 
376
      DRIZZLE_RETURN_CHECK(ret, "drizzle_result_write", drizzle);
366
377
    }
367
378
 
368
379
    /* Rows. */
369
380
    while (1)
370
381
    {
371
382
      row= drizzle_row_read(client_result, &ret);
372
 
      DRIZZLE_RETURN_CHECK(ret, "drizzle_row_read", drizzle)
 
383
      DRIZZLE_RETURN_CHECK(ret, "drizzle_row_read", drizzle);
373
384
 
374
385
      if (row == 0)
375
386
        break;
378
389
                                  drizzle_result_row_size(client_result));
379
390
 
380
391
      ret= drizzle_row_write(server_result);
381
 
      DRIZZLE_RETURN_CHECK(ret, "drizzle_row_write", drizzle)
 
392
      DRIZZLE_RETURN_CHECK(ret, "drizzle_row_write", drizzle);
382
393
 
383
394
      /* Fields. */
384
395
      row_break= false;
395
406
          row_break= true;
396
407
        }
397
408
        else
398
 
          DRIZZLE_RETURN_CHECK(ret, "drizzle_field_read", drizzle)
 
409
        {
 
410
          DRIZZLE_RETURN_CHECK(ret, "drizzle_field_read", drizzle);
 
411
        }
399
412
 
400
413
        ret= drizzle_field_write(server_result, field, size, total);
401
 
        DRIZZLE_RETURN_CHECK(ret, "drizzle_field_write", drizzle)
 
414
        DRIZZLE_RETURN_CHECK(ret, "drizzle_field_write", drizzle);
402
415
      }
403
416
    }
404
417
 
405
418
    ret= drizzle_result_write(server, server_result, true);
406
 
    DRIZZLE_RETURN_CHECK(ret, "drizzle_result_write", drizzle)
 
419
    DRIZZLE_RETURN_CHECK(ret, "drizzle_result_write", drizzle);
407
420
  }
408
421
}