-
-
Notifications
You must be signed in to change notification settings - Fork 266
Expand file tree
/
Copy pathprotocol.cpp
More file actions
2602 lines (2206 loc) · 67.2 KB
/
protocol.cpp
File metadata and controls
2602 lines (2206 loc) · 67.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* PROGRAM: JRD Remote Interface/Server
* MODULE: protocol.cpp
* DESCRIPTION: Protocol data structure mapper
*
* The contents of this file are subject to the Interbase Public
* License Version 1.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy
* of the License at http://www.Inprise.com/IPL.html
*
* Software distributed under the License is distributed on an
* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
* or implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code was created by Inprise Corporation
* and its predecessors. Portions created by Inprise Corporation are
* Copyright (C) Inprise Corporation.
*
* All Rights Reserved.
* Contributor(s): ______________________________________.
*
* 2002.02.15 Sean Leyne - Code Cleanup, removed obsolete "IMP" port
*
* 2002.10.27 Sean Leyne - Code Cleanup, removed obsolete "Ultrix/MIPS" port
* 2002.10.28 Sean Leyne - Code cleanup, removed obsolete "SGI" port
*
*/
#include "firebird.h"
#include <stdio.h>
#include <string.h>
#include "../remote/remote.h"
#include "iberror.h"
#include "../common/sdl.h"
#include "../common/gdsassert.h"
#include "../remote/parse_proto.h"
#include "../remote/proto_proto.h"
#include "../remote/remot_proto.h"
#include "../yvalve/gds_proto.h"
#include "../common/sdl_proto.h"
#include "../common/StatusHolder.h"
#include "../common/classes/stack.h"
#include "../common/classes/BatchCompletionState.h"
#include "../common/utils_proto.h"
#include "../dsql/DsqlBatch.h"
using namespace Firebird;
#ifdef DEBUG_XDR_MEMORY
inline bool_t P_TRUE(RemoteXdr* xdrs, PACKET* p)
{
return xdr_debug_packet(xdrs, XDR_FREE, p);
}
inline bool_t P_FALSE(RemoteXdr* xdrs, PACKET* p)
{
return !xdr_debug_packet(xdrs, XDR_FREE, p);
}
inline void DEBUG_XDR_PACKET(RemoteXdr* xdrs, PACKET* p)
{
xdr_debug_packet(xdrs, XDR_DECODE, p);
}
inline void DEBUG_XDR_ALLOC(RemoteXdr* xdrs, const void* xdrvar, const void* addr, ULONG len)
{
xdr_debug_memory(xdrs, XDR_DECODE, xdrvar, addr, len);
}
inline void DEBUG_XDR_FREE(RemoteXdr* xdrs, const void* xdrvar, const void* addr, ULONG len)
{
xdr_debug_memory(xdrs, XDR_DECODE, xdrvar, addr, len);
}
#else
inline bool_t P_TRUE(RemoteXdr*, PACKET*) noexcept
{
return TRUE;
}
inline bool_t P_FALSE(RemoteXdr* xdrs, PACKET*) noexcept
{
return FALSE;
}
inline void DEBUG_XDR_PACKET(RemoteXdr*, PACKET*) noexcept
{
}
inline void DEBUG_XDR_ALLOC(RemoteXdr*, const void*, const void*, ULONG) noexcept
{
}
inline void DEBUG_XDR_FREE(RemoteXdr*, const void*, const void*, ULONG) noexcept
{
}
#endif // DEBUG_XDR_MEMORY
#define P_CHECK(xdr, p, st) if (st.getState() & IStatus::STATE_ERRORS) return P_FALSE(xdr, p)
#define MAP(routine, ptr) if (!routine (xdrs, &ptr)) return P_FALSE(xdrs, p);
constexpr ULONG MAX_OPAQUE = 32768;
enum SQL_STMT_TYPE
{
TYPE_IMMEDIATE,
TYPE_PREPARED
};
static bool alloc_cstring(RemoteXdr*, CSTRING*);
static void reset_statement(RemoteXdr*, SSHORT);
static bool_t xdr_cstring(RemoteXdr*, CSTRING*);
static bool_t xdr_response(RemoteXdr*, CSTRING*);
static bool_t xdr_cstring_with_limit(RemoteXdr*, CSTRING*, ULONG);
static inline bool_t xdr_cstring_const(RemoteXdr*, CSTRING_CONST*);
#ifdef DEBUG_XDR_MEMORY
static bool_t xdr_debug_packet(RemoteXdr*, enum xdr_op, PACKET*);
#endif
static bool_t xdr_longs(RemoteXdr*, CSTRING*);
static bool_t xdr_message(RemoteXdr*, RMessage*, const rem_fmt*);
static bool_t xdr_packed_message(RemoteXdr*, RMessage*, const rem_fmt*);
static bool_t xdr_request(RemoteXdr*, USHORT, USHORT, USHORT);
static bool_t xdr_slice(RemoteXdr*, lstring*, /*USHORT,*/ const UCHAR*);
static bool_t xdr_status_vector(RemoteXdr*, DynamicStatusVector*&);
static bool_t xdr_sql_blr(RemoteXdr*, SLONG, CSTRING*, bool, SQL_STMT_TYPE);
static bool_t xdr_sql_message(RemoteXdr*, SLONG);
static bool_t xdr_trrq_blr(RemoteXdr*, CSTRING*);
static bool_t xdr_trrq_message(RemoteXdr*, USHORT);
static bool_t xdr_bytes(RemoteXdr*, void*, ULONG);
static bool_t xdr_blob_stream(RemoteXdr*, SSHORT, CSTRING*);
static bool_t xdr_blobBuffer(RemoteXdr* xdrs, RemBlobBuffer* buff);
static Rsr* getStatement(RemoteXdr*, USHORT);
static Rtr* getTransaction(RemoteXdr*, USHORT);
inline void fixupLength(const RemoteXdr* xdrs, ULONG& length) noexcept
{
// If the short (16-bit) value >= 32KB is being transmitted,
// it gets expanded to long (32-bit) with a sign bit propagated.
// In order to avoid troubles when reading such a value as long,
// let's detect and fix unexpected overflows. Here we assume
// that real longs will never have the highest 16 bits set.
if (xdrs->x_op == XDR_DECODE && length >> 16 == ULONG{ 0xFFFF })
length &= ULONG{ 0xFFFF };
}
#ifdef DEBUG
static ULONG xdr_save_size = 0;
inline void DEBUG_PRINTSIZE(RemoteXdr* xdrs, P_OP p) noexcept
{
fprintf (stderr, "xdr_protocol: %s op %d size %lu\n",
((xdrs->x_op == XDR_FREE) ? "free" :
(xdrs->x_op == XDR_ENCODE) ? "enc " : (xdrs->x_op == XDR_DECODE) ? "dec " : "othr"),
p,
((xdrs->x_op == XDR_ENCODE) ?
(xdrs->x_handy - xdr_save_size) : (xdr_save_size - xdrs->x_handy)));
}
#else
inline void DEBUG_PRINTSIZE(RemoteXdr*, P_OP) noexcept
{
}
#endif
#ifdef DEBUG_XDR_MEMORY
void xdr_debug_memory(RemoteXdr* xdrs,
enum xdr_op xop,
const void* xdrvar, const void* address, ULONG length)
{
/**************************************
*
* x d r _ d e b u g _ m e m o r y
*
**************************************
*
* Functional description
* Track memory allocation patterns of RemoteXdr aggregate
* types (i.e. xdr_cstring, xdr_string, etc.) to
* validate that memory is not leaked by overwriting
* RemoteXdr aggregate pointers and that freeing a packet
* with REMOTE_free_packet() does not miss anything.
*
* All memory allocations due to marshalling RemoteXdr
* variables are recorded in a debug memory alloca-
* tion table stored at the front of a packet.
*
* Once a packet is being tracked it is an assertion
* error if a memory allocation can not be recorded
* due to space limitations or if a previous memory
* allocation being freed cannot be found. At most
* P_MALLOC_SIZE entries can be stored in the memory
* allocation table. A rough estimate of the number
* of RemoteXdr aggregates that can hang off a packet can
* be obtained by examining the subpackets defined
* in <remote/protocol.h>: A guestimate of 36 at this
* time includes 10 strings used to decode an xdr
* status vector.
*
**************************************/
rem_port* port = xdrs->x_public;
fb_assert(port != 0);
fb_assert(port->port_header.blk_type == type_port);
// Compare the RemoteXdr variable address with the lower and upper bounds
// of each packet to determine which packet contains it. Record or
// delete an entry in that packet's memory allocation table.
rem_vec* vector = port->port_packet_vector;
if (!vector) // Not tracking port's protocol
return;
ULONG i;
for (i = 0; i < vector->vec_count; i++)
{
PACKET* packet = (PACKET*) vector->vec_object[i];
if (packet)
{
fb_assert(packet->p_operation > op_void && packet->p_operation < op_max);
if ((SCHAR*) xdrvar >= (SCHAR*) packet &&
(SCHAR*) xdrvar < (SCHAR*) packet + sizeof(PACKET))
{
ULONG j;
for (j = 0; j < P_MALLOC_SIZE; j++)
{
if (xop == XDR_FREE)
{
if ((SCHAR*) packet->p_malloc[j].p_address == (SCHAR*) address)
{
packet->p_malloc[j].p_operation = op_void;
packet->p_malloc[j].p_allocated = NULL;
packet->p_malloc[j].p_address = 0;
return;
}
}
else
{
// XDR_ENCODE or XDR_DECODE
fb_assert(xop == XDR_ENCODE || xop == XDR_DECODE);
if (packet->p_malloc[j].p_operation == op_void) {
packet->p_malloc[j].p_operation = packet->p_operation;
packet->p_malloc[j].p_allocated = length;
packet->p_malloc[j].p_address = address;
return;
}
}
}
// Assertion failure if not enough entries to record every xdr
// memory allocation or an entry to be freed can't be found.
fb_assert(j < P_MALLOC_SIZE); // Increase P_MALLOC_SIZE if necessary
}
}
}
fb_assert(i < vector->vec_count); // Couldn't find packet for this xdr arg
}
#endif
bool_t xdr_protocol(RemoteXdr* xdrs, PACKET* p)
{
/**************************************
*
* x d r _ p r o t o c o l
*
**************************************
*
* Functional description
* Encode, decode, or free a protocol packet.
*
**************************************/
p_cnct::p_cnct_repeat* tail;
P_ACPT *accept;
P_ACPD *accept_with_data;
P_ATCH *attach;
P_RESP *response;
P_CMPL *compile;
P_STTR *transaction;
P_DATA *data;
P_RLSE *release;
P_BLOB *blob;
P_SGMT *segment;
P_INFO *info;
P_PREP *prepare;
P_REQ *request;
P_SLC *slice;
P_SLR *slice_response;
P_SEEK *seek;
P_SQLFREE *free_stmt;
P_SQLCUR *sqlcur;
P_SQLST *prep_stmt;
P_SQLDATA *sqldata;
P_TRRQ *trrq;
#ifdef DEBUG
xdr_save_size = xdrs->x_handy;
#endif
DEBUG_XDR_PACKET(xdrs, p);
if (!xdr_enum(xdrs, &p->p_operation))
return P_FALSE(xdrs, p);
#if COMPRESS_DEBUG > 1
if (xdrs->x_op != XDR_FREE)
{
fprintf(stderr, "operation=%d %c\n", p->p_operation,
xdrs->x_op == XDR_ENCODE ? 'E' : xdrs->x_op == XDR_DECODE ? 'D' : xdrs->x_op == XDR_FREE ? 'F' : 'U');
}
#endif
const auto port = xdrs->x_public;
if (xdrs->x_op != XDR_FREE)
port->bumpLogPackets(xdrs->x_op == XDR_ENCODE ? rem_port::SEND : rem_port::RECEIVE);
switch (p->p_operation)
{
case op_reject:
case op_disconnect:
case op_dummy:
case op_ping:
case op_abort_aux_connection:
return P_TRUE(xdrs, p);
case op_connect:
{
P_CNCT* connect = &p->p_cnct;
MAP(xdr_enum, connect->p_cnct_operation);
MAP(xdr_short, reinterpret_cast<SSHORT&>(connect->p_cnct_cversion));
MAP(xdr_enum, connect->p_cnct_client);
MAP(xdr_cstring_const, connect->p_cnct_file);
MAP(xdr_short, reinterpret_cast<SSHORT&>(connect->p_cnct_count));
MAP(xdr_cstring_const, connect->p_cnct_user_id);
tail = connect->p_cnct_versions;
for (USHORT i = 0; i < connect->p_cnct_count; i++, tail++)
{
// ignore the rest of protocols in case of too many suggested versions
p_cnct::p_cnct_repeat dummy;
if (i >= MAX_CNCT_VERSIONS)
{
tail = &dummy;
}
MAP(xdr_short, reinterpret_cast<SSHORT&>(tail->p_cnct_version));
MAP(xdr_enum, tail->p_cnct_architecture);
MAP(xdr_u_short, tail->p_cnct_min_type);
MAP(xdr_u_short, tail->p_cnct_max_type);
MAP(xdr_short, reinterpret_cast<SSHORT&>(tail->p_cnct_weight));
}
// ignore the rest of protocols in case of too many suggested versions
if (connect->p_cnct_count > MAX_CNCT_VERSIONS)
{
connect->p_cnct_count = MAX_CNCT_VERSIONS;
}
DEBUG_PRINTSIZE(xdrs, p->p_operation);
return P_TRUE(xdrs, p);
}
case op_accept:
accept = &p->p_acpt;
MAP(xdr_short, reinterpret_cast<SSHORT&>(accept->p_acpt_version));
MAP(xdr_enum, accept->p_acpt_architecture);
MAP(xdr_u_short, accept->p_acpt_type);
DEBUG_PRINTSIZE(xdrs, p->p_operation);
return P_TRUE(xdrs, p);
case op_accept_data:
case op_cond_accept:
accept_with_data = &p->p_acpd;
MAP(xdr_short, reinterpret_cast<SSHORT&>(accept_with_data->p_acpt_version));
MAP(xdr_enum, accept_with_data->p_acpt_architecture);
MAP(xdr_u_short, accept_with_data->p_acpt_type);
MAP(xdr_cstring, accept_with_data->p_acpt_data);
MAP(xdr_cstring, accept_with_data->p_acpt_plugin);
MAP(xdr_u_short, accept_with_data->p_acpt_authenticated);
MAP(xdr_cstring, accept_with_data->p_acpt_keys);
DEBUG_PRINTSIZE(xdrs, p->p_operation);
return P_TRUE(xdrs, p);
case op_connect_request:
case op_aux_connect:
request = &p->p_req;
MAP(xdr_short, reinterpret_cast<SSHORT&>(request->p_req_type));
MAP(xdr_short, reinterpret_cast<SSHORT&>(request->p_req_object));
MAP(xdr_long, reinterpret_cast<SLONG&>(request->p_req_partner));
DEBUG_PRINTSIZE(xdrs, p->p_operation);
return P_TRUE(xdrs, p);
case op_attach:
case op_create:
case op_service_attach:
attach = &p->p_atch;
MAP(xdr_short, reinterpret_cast<SSHORT&>(attach->p_atch_database));
MAP(xdr_cstring_const, attach->p_atch_file);
MAP(xdr_cstring_const, attach->p_atch_dpb);
DEBUG_PRINTSIZE(xdrs, p->p_operation);
return P_TRUE(xdrs, p);
case op_compile:
compile = &p->p_cmpl;
MAP(xdr_short, reinterpret_cast<SSHORT&>(compile->p_cmpl_database));
MAP(xdr_cstring_const, compile->p_cmpl_blr);
DEBUG_PRINTSIZE(xdrs, p->p_operation);
return P_TRUE(xdrs, p);
case op_receive:
case op_start:
case op_start_and_receive:
data = &p->p_data;
MAP(xdr_short, reinterpret_cast<SSHORT&>(data->p_data_request));
MAP(xdr_short, reinterpret_cast<SSHORT&>(data->p_data_incarnation));
MAP(xdr_short, reinterpret_cast<SSHORT&>(data->p_data_transaction));
MAP(xdr_short, reinterpret_cast<SSHORT&>(data->p_data_message_number));
MAP(xdr_short, reinterpret_cast<SSHORT&>(data->p_data_messages));
DEBUG_PRINTSIZE(xdrs, p->p_operation);
return P_TRUE(xdrs, p);
case op_send:
case op_start_and_send:
case op_start_send_and_receive:
data = &p->p_data;
MAP(xdr_short, reinterpret_cast<SSHORT&>(data->p_data_request));
MAP(xdr_short, reinterpret_cast<SSHORT&>(data->p_data_incarnation));
MAP(xdr_short, reinterpret_cast<SSHORT&>(data->p_data_transaction));
MAP(xdr_short, reinterpret_cast<SSHORT&>(data->p_data_message_number));
MAP(xdr_short, reinterpret_cast<SSHORT&>(data->p_data_messages));
// Changes to this op's protocol must mirror in xdr_protocol_overhead
return xdr_request(xdrs, data->p_data_request,
data->p_data_message_number,
data->p_data_incarnation) ? P_TRUE(xdrs, p) : P_FALSE(xdrs, p);
case op_response:
case op_response_piggyback:
// Changes to this op's protocol must be mirrored
// in xdr_protocol_overhead
response = &p->p_resp;
MAP(xdr_short, reinterpret_cast<SSHORT&>(response->p_resp_object));
MAP(xdr_quad, response->p_resp_blob_id);
MAP(xdr_response, response->p_resp_data);
return xdr_status_vector(xdrs, response->p_resp_status_vector) ?
P_TRUE(xdrs, p) : P_FALSE(xdrs, p);
case op_transact:
trrq = &p->p_trrq;
MAP(xdr_short, reinterpret_cast<SSHORT&>(trrq->p_trrq_database));
MAP(xdr_short, reinterpret_cast<SSHORT&>(trrq->p_trrq_transaction));
xdr_trrq_blr(xdrs, &trrq->p_trrq_blr);
MAP(xdr_cstring, trrq->p_trrq_blr);
MAP(xdr_short, reinterpret_cast<SSHORT&>(trrq->p_trrq_messages));
if (trrq->p_trrq_messages)
return xdr_trrq_message(xdrs, 0) ? P_TRUE(xdrs, p) : P_FALSE(xdrs, p);
DEBUG_PRINTSIZE(xdrs, p->p_operation);
return P_TRUE(xdrs, p);
case op_transact_response:
data = &p->p_data;
MAP(xdr_short, reinterpret_cast<SSHORT&>(data->p_data_messages));
if (data->p_data_messages)
return xdr_trrq_message(xdrs, 1) ? P_TRUE(xdrs, p) : P_FALSE(xdrs, p);
DEBUG_PRINTSIZE(xdrs, p->p_operation);
return P_TRUE(xdrs, p);
case op_open_blob2:
case op_create_blob2:
blob = &p->p_blob;
MAP(xdr_cstring_const, blob->p_blob_bpb);
[[fallthrough]];
case op_open_blob:
case op_create_blob:
blob = &p->p_blob;
MAP(xdr_short, reinterpret_cast<SSHORT&>(blob->p_blob_transaction));
MAP(xdr_quad, blob->p_blob_id);
DEBUG_PRINTSIZE(xdrs, p->p_operation);
return P_TRUE(xdrs, p);
case op_get_segment:
case op_put_segment:
case op_batch_segments:
segment = &p->p_sgmt;
MAP(xdr_short, reinterpret_cast<SSHORT&>(segment->p_sgmt_blob));
MAP(xdr_short, reinterpret_cast<SSHORT&>(segment->p_sgmt_length));
MAP(xdr_cstring_const, segment->p_sgmt_segment);
DEBUG_PRINTSIZE(xdrs, p->p_operation);
return P_TRUE(xdrs, p);
case op_seek_blob:
seek = &p->p_seek;
MAP(xdr_short, reinterpret_cast<SSHORT&>(seek->p_seek_blob));
MAP(xdr_short, reinterpret_cast<SSHORT&>(seek->p_seek_mode));
MAP(xdr_long, seek->p_seek_offset);
DEBUG_PRINTSIZE(xdrs, p->p_operation);
return P_TRUE(xdrs, p);
case op_reconnect:
case op_transaction:
transaction = &p->p_sttr;
MAP(xdr_short, reinterpret_cast<SSHORT&>(transaction->p_sttr_database));
MAP(xdr_cstring_const, transaction->p_sttr_tpb);
DEBUG_PRINTSIZE(xdrs, p->p_operation);
return P_TRUE(xdrs, p);
case op_info_blob:
case op_info_database:
case op_info_request:
case op_info_transaction:
case op_service_info:
case op_info_sql:
case op_info_batch:
case op_info_cursor:
info = &p->p_info;
MAP(xdr_short, reinterpret_cast<SSHORT&>(info->p_info_object));
MAP(xdr_short, reinterpret_cast<SSHORT&>(info->p_info_incarnation));
MAP(xdr_cstring_const, info->p_info_items);
if (p->p_operation == op_service_info)
MAP(xdr_cstring_const, info->p_info_recv_items);
MAP(xdr_long, reinterpret_cast<SLONG&>(info->p_info_buffer_length));
// p_info_buffer_length was USHORT in older versions
fixupLength(xdrs, info->p_info_buffer_length);
DEBUG_PRINTSIZE(xdrs, p->p_operation);
return P_TRUE(xdrs, p);
case op_service_start:
info = &p->p_info;
MAP(xdr_short, reinterpret_cast<SSHORT&>(info->p_info_object));
MAP(xdr_short, reinterpret_cast<SSHORT&>(info->p_info_incarnation));
MAP(xdr_cstring_const, info->p_info_items);
DEBUG_PRINTSIZE(xdrs, p->p_operation);
return P_TRUE(xdrs, p);
case op_commit:
case op_prepare:
case op_rollback:
case op_unwind:
case op_release:
case op_close_blob:
case op_cancel_blob:
case op_detach:
case op_drop_database:
case op_service_detach:
case op_commit_retaining:
case op_rollback_retaining:
case op_allocate_statement:
case op_batch_rls:
case op_batch_cancel:
release = &p->p_rlse;
MAP(xdr_short, reinterpret_cast<SSHORT&>(release->p_rlse_object));
DEBUG_PRINTSIZE(xdrs, p->p_operation);
#ifdef NEVERDEF
if (xdrs->x_op != XDR_FREE && (p->p_operation == op_batch_rls || p->p_operation == op_batch_cancel))
DEB_RBATCH(fprintf(stderr, "BatRem: xdr release/cancel %d\n", p->p_operation));
#endif
return P_TRUE(xdrs, p);
case op_prepare2:
prepare = &p->p_prep;
MAP(xdr_short, reinterpret_cast<SSHORT&>(prepare->p_prep_transaction));
MAP(xdr_cstring_const, prepare->p_prep_data);
DEBUG_PRINTSIZE(xdrs, p->p_operation);
return P_TRUE(xdrs, p);
case op_que_events:
case op_event:
{
P_EVENT* event = &p->p_event;
MAP(xdr_short, reinterpret_cast<SSHORT&>(event->p_event_database));
MAP(xdr_cstring_const, event->p_event_items);
// Nickolay Samofatov: these values are parsed, but are ignored by the client.
// Values are useful only for debugging, anyway since upper words of pointers
// are trimmed for 64-bit clients
MAP(xdr_long, reinterpret_cast<SLONG&>(event->p_event_ast));
MAP(xdr_long, event->p_event_arg);
MAP(xdr_long, event->p_event_rid);
DEBUG_PRINTSIZE(xdrs, p->p_operation);
return P_TRUE(xdrs, p);
}
case op_cancel_events:
{
P_EVENT* event = &p->p_event;
MAP(xdr_short, reinterpret_cast<SSHORT&>(event->p_event_database));
MAP(xdr_long, event->p_event_rid);
DEBUG_PRINTSIZE(xdrs, p->p_operation);
return P_TRUE(xdrs, p);
}
case op_ddl:
{
P_DDL* ddl = &p->p_ddl;
MAP(xdr_short, reinterpret_cast<SSHORT&>(ddl->p_ddl_database));
MAP(xdr_short, reinterpret_cast<SSHORT&>(ddl->p_ddl_transaction));
MAP(xdr_cstring_const, ddl->p_ddl_blr);
DEBUG_PRINTSIZE(xdrs, p->p_operation);
return P_TRUE(xdrs, p);
}
case op_get_slice:
case op_put_slice:
slice = &p->p_slc;
MAP(xdr_short, reinterpret_cast<SSHORT&>(slice->p_slc_transaction));
MAP(xdr_quad, slice->p_slc_id);
MAP(xdr_long, reinterpret_cast<SLONG&>(slice->p_slc_length));
MAP(xdr_cstring, slice->p_slc_sdl);
MAP(xdr_longs, slice->p_slc_parameters);
slice_response = &p->p_slr;
if (slice_response->p_slr_sdl)
{
if (!xdr_slice(xdrs, &slice->p_slc_slice, //slice_response->p_slr_sdl_length,
slice_response->p_slr_sdl))
{
return P_FALSE(xdrs, p);
}
}
else
if (!xdr_slice(xdrs, &slice->p_slc_slice, //slice->p_slc_sdl.cstr_length,
slice->p_slc_sdl.cstr_address))
{
return P_FALSE(xdrs, p);
}
DEBUG_PRINTSIZE(xdrs, p->p_operation);
return P_TRUE(xdrs, p);
case op_slice:
slice_response = &p->p_slr;
MAP(xdr_long, reinterpret_cast<SLONG&>(slice_response->p_slr_length));
if (!xdr_slice (xdrs, &slice_response->p_slr_slice, //slice_response->p_slr_sdl_length,
slice_response->p_slr_sdl))
{
return P_FALSE(xdrs, p);
}
DEBUG_PRINTSIZE(xdrs, p->p_operation);
return P_TRUE(xdrs, p);
case op_execute:
case op_execute2:
sqldata = &p->p_sqldata;
MAP(xdr_short, reinterpret_cast<SSHORT&>(sqldata->p_sqldata_statement));
MAP(xdr_short, reinterpret_cast<SSHORT&>(sqldata->p_sqldata_transaction));
if (xdrs->x_op == XDR_DECODE)
{
// the statement should be reset for each execution so that
// all prefetched information from a prior execute is properly
// cleared out. This should be done before fetching any message
// information (for example: blr info)
reset_statement(xdrs, sqldata->p_sqldata_statement);
}
if (!xdr_sql_blr(xdrs, (SLONG) sqldata->p_sqldata_statement,
&sqldata->p_sqldata_blr, false, TYPE_PREPARED))
{
return P_FALSE(xdrs, p);
}
MAP(xdr_short, reinterpret_cast<SSHORT&>(sqldata->p_sqldata_message_number));
MAP(xdr_short, reinterpret_cast<SSHORT&>(sqldata->p_sqldata_messages));
if (sqldata->p_sqldata_messages)
{
if (!xdr_sql_message(xdrs, (SLONG) sqldata->p_sqldata_statement))
return P_FALSE(xdrs, p);
}
if (p->p_operation == op_execute2)
{
if (!xdr_sql_blr(xdrs, (SLONG) - 1, &sqldata->p_sqldata_out_blr, true, TYPE_PREPARED))
{
return P_FALSE(xdrs, p);
}
MAP(xdr_short, reinterpret_cast<SSHORT&>(sqldata->p_sqldata_out_message_number));
}
if (port->port_protocol >= PROTOCOL_STMT_TOUT)
MAP(xdr_u_long, sqldata->p_sqldata_timeout);
if (port->port_protocol >= PROTOCOL_FETCH_SCROLL)
MAP(xdr_u_long, sqldata->p_sqldata_cursor_flags);
if (port->port_protocol >= PROTOCOL_INLINE_BLOB)
MAP(xdr_u_long, sqldata->p_sqldata_inline_blob_size);
DEBUG_PRINTSIZE(xdrs, p->p_operation);
return P_TRUE(xdrs, p);
case op_exec_immediate2:
prep_stmt = &p->p_sqlst;
if (!xdr_sql_blr(xdrs, (SLONG) - 1, &prep_stmt->p_sqlst_blr, false, TYPE_IMMEDIATE))
{
return P_FALSE(xdrs, p);
}
MAP(xdr_short, reinterpret_cast<SSHORT&>(prep_stmt->p_sqlst_message_number));
MAP(xdr_short, reinterpret_cast<SSHORT&>(prep_stmt->p_sqlst_messages));
if (prep_stmt->p_sqlst_messages)
{
if (!xdr_sql_message(xdrs, (SLONG) - 1))
return P_FALSE(xdrs, p);
}
if (!xdr_sql_blr(xdrs, (SLONG) - 1, &prep_stmt->p_sqlst_out_blr, true, TYPE_IMMEDIATE))
{
return P_FALSE(xdrs, p);
}
MAP(xdr_short, reinterpret_cast<SSHORT&>(prep_stmt->p_sqlst_out_message_number));
if (port->port_protocol >= PROTOCOL_INLINE_BLOB)
MAP(xdr_u_long, prep_stmt->p_sqlst_inline_blob_size);
[[fallthrough]];
case op_exec_immediate:
case op_prepare_statement:
prep_stmt = &p->p_sqlst;
MAP(xdr_short, reinterpret_cast<SSHORT&>(prep_stmt->p_sqlst_transaction));
MAP(xdr_short, reinterpret_cast<SSHORT&>(prep_stmt->p_sqlst_statement));
MAP(xdr_short, reinterpret_cast<SSHORT&>(prep_stmt->p_sqlst_SQL_dialect));
MAP(xdr_cstring_const, prep_stmt->p_sqlst_SQL_str);
MAP(xdr_cstring_const, prep_stmt->p_sqlst_items);
MAP(xdr_long, reinterpret_cast<SLONG&>(prep_stmt->p_sqlst_buffer_length));
// p_sqlst_buffer_length was USHORT in older versions
fixupLength(xdrs, prep_stmt->p_sqlst_buffer_length);
if (port->port_protocol >= PROTOCOL_PREPARE_FLAG)
MAP(xdr_short, reinterpret_cast<SSHORT&>(prep_stmt->p_sqlst_flags));
DEBUG_PRINTSIZE(xdrs, p->p_operation);
return P_TRUE(xdrs, p);
case op_fetch:
case op_fetch_scroll:
sqldata = &p->p_sqldata;
MAP(xdr_short, reinterpret_cast<SSHORT&>(sqldata->p_sqldata_statement));
if (!xdr_sql_blr(xdrs, (SLONG) sqldata->p_sqldata_statement,
&sqldata->p_sqldata_blr, true, TYPE_PREPARED))
{
return P_FALSE(xdrs, p);
}
MAP(xdr_short, reinterpret_cast<SSHORT&>(sqldata->p_sqldata_message_number));
MAP(xdr_short, reinterpret_cast<SSHORT&>(sqldata->p_sqldata_messages));
if (p->p_operation == op_fetch_scroll)
{
MAP(xdr_short, reinterpret_cast<SSHORT&>(sqldata->p_sqldata_fetch_op));
MAP(xdr_long, sqldata->p_sqldata_fetch_pos);
}
DEBUG_PRINTSIZE(xdrs, p->p_operation);
return P_TRUE(xdrs, p);
case op_fetch_response:
sqldata = &p->p_sqldata;
MAP(xdr_long, reinterpret_cast<SLONG&>(sqldata->p_sqldata_status));
MAP(xdr_short, reinterpret_cast<SSHORT&>(sqldata->p_sqldata_messages));
// Changes to this op's protocol must mirror in xdr_protocol_overhead
if (sqldata->p_sqldata_messages)
{
return xdr_sql_message(xdrs, (SLONG)sqldata->p_sqldata_statement) ?
P_TRUE(xdrs, p) : P_FALSE(xdrs, p);
}
DEBUG_PRINTSIZE(xdrs, p->p_operation);
return P_TRUE(xdrs, p);
case op_free_statement:
free_stmt = &p->p_sqlfree;
MAP(xdr_short, reinterpret_cast<SSHORT&>(free_stmt->p_sqlfree_statement));
MAP(xdr_short, reinterpret_cast<SSHORT&>(free_stmt->p_sqlfree_option));
DEBUG_PRINTSIZE(xdrs, p->p_operation);
return P_TRUE(xdrs, p);
case op_set_cursor:
sqlcur = &p->p_sqlcur;
MAP(xdr_short, reinterpret_cast<SSHORT&>(sqlcur->p_sqlcur_statement));
MAP(xdr_cstring_const, sqlcur->p_sqlcur_cursor_name);
MAP(xdr_short, reinterpret_cast<SSHORT&>(sqlcur->p_sqlcur_type));
DEBUG_PRINTSIZE(xdrs, p->p_operation);
return P_TRUE(xdrs, p);
case op_sql_response:
sqldata = &p->p_sqldata;
MAP(xdr_short, reinterpret_cast<SSHORT&>(sqldata->p_sqldata_messages));
if (sqldata->p_sqldata_messages)
return xdr_sql_message(xdrs, (SLONG) -1) ? P_TRUE(xdrs, p) : P_FALSE(xdrs, p);
DEBUG_PRINTSIZE(xdrs, p->p_operation);
return P_TRUE(xdrs, p);
// the following added to have formal vulcan compatibility
case op_update_account_info:
{
p_update_account* stuff = &p->p_account_update;
MAP(xdr_short, reinterpret_cast<SSHORT&>(stuff->p_account_database));
MAP(xdr_cstring_const, stuff->p_account_apb);
DEBUG_PRINTSIZE(xdrs, p->p_operation);
return P_TRUE(xdrs, p);
}
case op_authenticate_user:
{
p_authenticate* stuff = &p->p_authenticate_user;
MAP(xdr_short, reinterpret_cast<SSHORT&>(stuff->p_auth_database));
MAP(xdr_cstring_const, stuff->p_auth_dpb);
MAP(xdr_cstring, stuff->p_auth_items);
MAP(xdr_short, reinterpret_cast<SSHORT&>(stuff->p_auth_buffer_length));
DEBUG_PRINTSIZE(xdrs, p->p_operation);
return P_TRUE(xdrs, p);
}
case op_trusted_auth:
{
P_TRAU* trau = &p->p_trau;
MAP(xdr_cstring, trau->p_trau_data);
DEBUG_PRINTSIZE(xdrs, p->p_operation);
return P_TRUE(xdrs, p);
}
case op_cont_auth:
{
P_AUTH_CONT* auth = &p->p_auth_cont;
MAP(xdr_cstring, auth->p_data);
MAP(xdr_cstring, auth->p_name);
MAP(xdr_cstring, auth->p_list);
MAP(xdr_cstring, auth->p_keys);
DEBUG_PRINTSIZE(xdrs, p->p_operation);
return P_TRUE(xdrs, p);
}
case op_cancel:
{
P_CANCEL_OP* cancel_op = &p->p_cancel_op;
MAP(xdr_short, reinterpret_cast<SSHORT&>(cancel_op->p_co_kind));
DEBUG_PRINTSIZE(xdrs, p->p_operation);
return P_TRUE(xdrs, p);
}
case op_crypt:
{
P_CRYPT* crypt = &p->p_crypt;
MAP(xdr_cstring, crypt->p_plugin);
MAP(xdr_cstring, crypt->p_key);
DEBUG_PRINTSIZE(xdrs, p->p_operation);
return P_TRUE(xdrs, p);
}
case op_crypt_key_callback:
{
P_CRYPT_CALLBACK* cc = &p->p_cc;
MAP(xdr_cstring, cc->p_cc_data);
// If the protocol is 0 we are in the process of establishing a connection.
// crypt_key_callback at this phaze means server protocol is at least P15
if (port->port_protocol >= PROTOCOL_VERSION14 || port->port_protocol == 0)
MAP(xdr_short, reinterpret_cast<SSHORT&>(cc->p_cc_reply));
DEBUG_PRINTSIZE(xdrs, p->p_operation);
return P_TRUE(xdrs, p);
}
case op_batch_create:
{
P_BATCH_CREATE* b = &p->p_batch_create;
MAP(xdr_short, reinterpret_cast<SSHORT&>(b->p_batch_statement));
MAP(xdr_cstring_const, b->p_batch_blr);
MAP(xdr_u_long, b->p_batch_msglen);
MAP(xdr_cstring_const, b->p_batch_pb);
DEBUG_PRINTSIZE(xdrs, p->p_operation);
return P_TRUE(xdrs, p);
}
case op_batch_msg:
{
P_BATCH_MSG* b = &p->p_batch_msg;
MAP(xdr_short, reinterpret_cast<SSHORT&>(b->p_batch_statement));
MAP(xdr_u_long, b->p_batch_messages);
if (xdrs->x_op == XDR_FREE)
{
MAP(xdr_cstring, b->p_batch_data);
return P_TRUE(xdrs, p);
}
const SSHORT statement_id = b->p_batch_statement;
Rsr* statement;
if (statement_id >= 0)
{
if (static_cast<ULONG>(statement_id) >= port->port_objects.getCount())
return P_FALSE(xdrs, p);
try
{
statement = port->port_objects[statement_id];
}
catch (const status_exception&)
{
return P_FALSE(xdrs, p);
}
}
else
{
statement = port->port_statement;
}
if (!statement)
return P_FALSE(xdrs, p);
ULONG count = b->p_batch_messages;
ULONG size = statement->rsr_batch_size;
if (!size)
statement->rsr_batch_size = size = FB_ALIGN(statement->rsr_format->fmt_length, FB_ALIGNMENT);
if (xdrs->x_op == XDR_DECODE)
{
b->p_batch_data.cstr_length = (count ? count : 1) * size;
alloc_cstring(xdrs, &b->p_batch_data);
}
RMessage* message = statement->rsr_buffer;
if (!message)
return P_FALSE(xdrs, p);
statement->rsr_buffer = message->msg_next;
message->msg_address = b->p_batch_data.cstr_address;
while (count--)
{
DEB_RBATCH(fprintf(stderr, "BatRem: xdr packed msg\n"));
if (!xdr_packed_message(xdrs, message, statement->rsr_format))
return P_FALSE(xdrs, p);
message->msg_address += statement->rsr_batch_size;
}
message->msg_address = nullptr;
DEBUG_PRINTSIZE(xdrs, p->p_operation);
return P_TRUE(xdrs, p);
}
case op_batch_exec:
{
P_BATCH_EXEC* b = &p->p_batch_exec;
MAP(xdr_short, reinterpret_cast<SSHORT&>(b->p_batch_statement));
MAP(xdr_short, reinterpret_cast<SSHORT&>(b->p_batch_transaction));
if (xdrs->x_op != XDR_FREE)
DEB_RBATCH(fprintf(stderr, "BatRem: xdr execute\n"));
return P_TRUE(xdrs, p);
}
case op_batch_cs:
{
P_BATCH_CS* b = &p->p_batch_cs;
MAP(xdr_short, reinterpret_cast<SSHORT&>(b->p_batch_statement));
MAP(xdr_u_long, b->p_batch_reccount);
MAP(xdr_u_long, b->p_batch_updates);
MAP(xdr_u_long, b->p_batch_vectors);
MAP(xdr_u_long, b->p_batch_errors);
if (xdrs->x_op == XDR_FREE)
return P_TRUE(xdrs, p);
const SSHORT statement_id = b->p_batch_statement;
DEB_RBATCH(fprintf(stderr, "BatRem: xdr CS %d\n", statement_id));
Rsr* statement;
if (statement_id >= 0)
{
if (static_cast<ULONG>(statement_id) >= port->port_objects.getCount())
return P_FALSE(xdrs, p);
try
{
statement = port->port_objects[statement_id];
}
catch (const status_exception&)
{
return P_FALSE(xdrs, p);
}
}
else
{
statement = port->port_statement;
}
if (!statement)
return P_FALSE(xdrs, p);
LocalStatus ls;
CheckStatusWrapper status_vector(&ls);
if ((xdrs->x_op == XDR_DECODE) && (!b->p_batch_updates))
{
DEB_RBATCH(fprintf(stderr, "BatRem: xdr reccount=%d\n", b->p_batch_reccount));
statement->rsr_batch_cs->regSize(b->p_batch_reccount);
}
// Process update counters
DEB_RBATCH(fprintf(stderr, "BatRem: xdr up %d\n", b->p_batch_updates));
for (unsigned i = 0; i < b->p_batch_updates; ++i)