-
-
Notifications
You must be signed in to change notification settings - Fork 266
Expand file tree
/
Copy pathinterface.cpp
More file actions
10586 lines (8705 loc) · 256 KB
/
interface.cpp
File metadata and controls
10586 lines (8705 loc) · 256 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
* MODULE: interface.cpp
* DESCRIPTION: User visible entrypoints remote interface
*
* 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.10.27 Sean Leyne - Code Cleanup, removed obsolete "Ultrix" port
*
* 2002.10.28 Sean Leyne - Code cleanup, removed obsolete "MPEXL" port
* 2002.10.28 Sean Leyne - Code cleanup, removed obsolete "DecOSF" port
*
* 2002.10.29 Sean Leyne - Removed support for obsolete IPX/SPX Protocol
* 2002.10.29 Sean Leyne - Removed obsolete "Netware" port
*
*/
#include "firebird.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "../remote/remote.h"
#include "../common/gdsassert.h"
#include "../common/isc_proto.h"
#include <stdarg.h>
#ifndef NO_NFS
#include <sys/param.h>
#endif
#include "ibase.h"
#include "../common/ThreadStart.h"
#include "../jrd/license.h"
#include "../remote/inet_proto.h"
#include "../remote/merge_proto.h"
#include "../remote/parse_proto.h"
#include "../remote/remot_proto.h"
#include "../remote/proto_proto.h"
#include "../common/cvt.h"
#include "../yvalve/gds_proto.h"
#include "../common/isc_f_proto.h"
#include "../common/classes/ClumpletWriter.h"
#include "../common/classes/BatchCompletionState.h"
#include "../common/config/config.h"
#include "../common/utils_proto.h"
#include "../common/classes/DbImplementation.h"
#include "../common/Auth.h"
#include "../common/classes/GetPlugins.h"
#include "firebird/Interface.h"
#include "../common/StatementMetadata.h"
#include "../common/IntlParametersBlock.h"
#include "../common/status.h"
#include "../common/db_alias.h"
#include "../common/classes/auto.h"
#include "../auth/SecurityDatabase/LegacyClient.h"
#include "../auth/SecureRemotePassword/client/SrpClient.h"
#include "../auth/trusted/AuthSspi.h"
#include "../plugins/crypt/arc4/Arc4.h"
#include "BlrFromMessage.h"
#include "../dsql/DsqlBatch.h"
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef WIN_NT
#include <process.h>
#endif
#if defined(WIN_NT)
#include "../common/isc_proto.h"
#include "../remote/os/win32/xnet_proto.h"
#endif
const char* const PROTOCOL_INET = "inet";
const char* const PROTOCOL_INET4 = "inet4";
const char* const PROTOCOL_INET6 = "inet6";
#ifdef WIN_NT
const char* const PROTOCOL_XNET = "xnet";
#endif
const char* const INET_SEPARATOR = "/";
const char* const INET_LOCALHOST = "localhost";
using namespace Firebird;
namespace {
[[noreturn]] void handle_error(ISC_STATUS code)
{
Arg::Gds(code).raise();
}
template <typename T>
inline void CHECK_HANDLE(T* blk, ISC_STATUS error)
{
if (!blk || !blk->checkHandle())
{
handle_error(error);
}
}
inline void CHECK_LENGTH(rem_port* port, size_t length)
{
if (length > MAX_USHORT && port->port_protocol < PROTOCOL_VERSION13)
status_exception::raise(Arg::Gds(isc_imp_exc) << Arg::Gds(isc_blktoobig));
}
class UsePreallocatedBuffer
{
public:
UsePreallocatedBuffer(cstring& toSave, ULONG newLength, UCHAR* newBuffer)
: ptr(&toSave),
oldValue(*ptr)
{
ptr->cstr_address = newBuffer;
ptr->cstr_allocated = newLength;
}
~UsePreallocatedBuffer()
{
*ptr = oldValue;
}
protected:
cstring* ptr;
private:
cstring oldValue;
};
class UseStandardBuffer : public UsePreallocatedBuffer
{
public:
UseStandardBuffer(cstring& toSave)
: UsePreallocatedBuffer(toSave,0, nullptr)
{ }
~UseStandardBuffer()
{
ptr->free();
}
};
class ClientPortsCleanup : public PortsCleanup
{
public:
ClientPortsCleanup() :
PortsCleanup()
{}
explicit ClientPortsCleanup(MemoryPool& p) :
PortsCleanup(p)
{}
void closePort(rem_port* port) override;
void delay() override
{
Thread::sleep(50);
}
};
GlobalPtr<ClientPortsCleanup> outPorts;
}
namespace Remote {
// Provider stuff
class Attachment;
class Statement;
class Blob final : public RefCntIface<IBlobImpl<Blob, CheckStatusWrapper> >
{
public:
// IBlob implementation
int release() override;
void getInfo(CheckStatusWrapper* status,
unsigned int itemsLength, const unsigned char* items,
unsigned int bufferLength, unsigned char* buffer) override;
int getSegment(CheckStatusWrapper* status, unsigned int bufferLength,
void* buffer, unsigned int* segmentLength) override;
void putSegment(CheckStatusWrapper* status, unsigned int length, const void* buffer) override;
void cancel(CheckStatusWrapper* status) override;
void close(CheckStatusWrapper* status) override;
int seek(CheckStatusWrapper* status, int mode, int offset) override; // returns position
void deprecatedCancel(CheckStatusWrapper* status) override;
void deprecatedClose(CheckStatusWrapper* status) override;
public:
explicit Blob(Rbl* handle)
: blob(handle)
{
blob->rbl_self = &blob;
}
private:
void freeClientData(CheckStatusWrapper* status, bool force = false);
void internalCancel(CheckStatusWrapper* status);
void internalClose(CheckStatusWrapper* status);
// seek in cached blob
int seekCached(int mode, int offset);
Rbl* blob;
};
int Blob::release()
{
if (--refCounter != 0)
{
return 1;
}
if (blob)
{
LocalStatus ls;
CheckStatusWrapper status(&ls);
freeClientData(&status, true);
}
delete this;
return 0;
}
class Transaction final : public RefCntIface<ITransactionImpl<Transaction, CheckStatusWrapper> >
{
public:
// ITransaction implementation
int release() override;
void getInfo(CheckStatusWrapper* status,
unsigned int itemsLength, const unsigned char* items,
unsigned int bufferLength, unsigned char* buffer) override;
void prepare(CheckStatusWrapper* status,
unsigned int msg_length = 0, const unsigned char* message = 0) override;
void commit(CheckStatusWrapper* status) override;
void commitRetaining(CheckStatusWrapper* status) override;
void rollback(CheckStatusWrapper* status) override;
void rollbackRetaining(CheckStatusWrapper* status) override;
void disconnect(CheckStatusWrapper* status) override;
ITransaction* join(CheckStatusWrapper* status, ITransaction* tra) override;
Transaction* validate(CheckStatusWrapper* status, IAttachment* attachment) override;
Transaction* enterDtc(CheckStatusWrapper* status) override;
void deprecatedCommit(CheckStatusWrapper* status) override;
void deprecatedRollback(CheckStatusWrapper* status) override;
void deprecatedDisconnect(CheckStatusWrapper* status) override;
public:
Transaction(Rtr* handle, Attachment* a)
: remAtt(a),
transaction(handle)
{
transaction->rtr_self = &transaction;
}
Rtr* getTransaction()
{
return transaction;
}
void clear()
{
transaction = NULL;
}
private:
Transaction(Transaction* from)
: remAtt(from->remAtt),
transaction(from->transaction)
{ }
void freeClientData(CheckStatusWrapper* status, bool force = false);
void internalCommit(CheckStatusWrapper* status);
void internalRollback(CheckStatusWrapper* status);
void internalDisconnect(CheckStatusWrapper* status);
Attachment* remAtt;
Rtr* transaction;
};
int Transaction::release()
{
if (--refCounter != 0)
return 1;
if (transaction)
{
LocalStatus ls;
CheckStatusWrapper status(&ls);
freeClientData(&status, true); // ASF: Rollback - is this correct for reconnected transactions?
}
delete this;
return 0;
}
class ResultSet final : public RefCntIface<IResultSetImpl<ResultSet, CheckStatusWrapper> >
{
public:
// IResultSet implementation
int release() override;
int fetchNext(CheckStatusWrapper* status, void* message) override;
int fetchPrior(CheckStatusWrapper* status, void* message) override;
int fetchFirst(CheckStatusWrapper* status, void* message) override;
int fetchLast(CheckStatusWrapper* status, void* message) override;
int fetchAbsolute(CheckStatusWrapper* status, int position, void* message) override;
int fetchRelative(CheckStatusWrapper* status, int offset, void* message) override;
FB_BOOLEAN isEof(CheckStatusWrapper* status) override;
FB_BOOLEAN isBof(CheckStatusWrapper* status) override;
IMessageMetadata* getMetadata(CheckStatusWrapper* status) override;
void close(CheckStatusWrapper* status) override;
void deprecatedClose(CheckStatusWrapper* status) override;
void setDelayedOutputFormat(CheckStatusWrapper* status, IMessageMetadata* format) override;
void getInfo(CheckStatusWrapper* status,
unsigned int itemsLength, const unsigned char* items,
unsigned int bufferLength, unsigned char* buffer) override;
ResultSet(Statement* s, IMessageMetadata* outFmt, unsigned f)
: stmt(s), flags(f), tmpStatement(false), delayedFormat(outFmt == DELAYED_OUT_FORMAT)
{
if (!delayedFormat)
outputFormat = outFmt;
}
private:
bool fetch(CheckStatusWrapper* status, void* message, P_FETCH operation, int position = 0);
void releaseStatement();
void freeClientData(CheckStatusWrapper* status, bool force = false);
void internalClose(CheckStatusWrapper* status);
Statement* stmt;
const unsigned flags;
RefPtr<IMessageMetadata> outputFormat;
public:
bool tmpStatement, delayedFormat;
};
int ResultSet::release()
{
if (--refCounter != 0)
return 1;
if (stmt)
{
LocalStatus ls;
CheckStatusWrapper status(&ls);
freeClientData(&status, true);
}
delete this;
return 0;
}
class Batch final : public RefCntIface<IBatchImpl<Batch, CheckStatusWrapper> >
{
public:
static const ULONG DEFER_BATCH_LIMIT = 64;
Batch(Statement* s, IMessageMetadata* inFmt, unsigned parLength, const unsigned char* par);
// IBatch implementation
int release() override;
void add(CheckStatusWrapper* status, unsigned count, const void* inBuffer) override;
void addBlob(CheckStatusWrapper* status, unsigned length, const void* inBuffer, ISC_QUAD* blobId,
unsigned parLength, const unsigned char* par) override;
void appendBlobData(CheckStatusWrapper* status, unsigned length, const void* inBuffer) override;
void addBlobStream(CheckStatusWrapper* status, unsigned length, const void* inBuffer) override;
void registerBlob(CheckStatusWrapper* status, const ISC_QUAD* existingBlob, ISC_QUAD* blobId) override;
IBatchCompletionState* execute(CheckStatusWrapper* status, ITransaction* transaction) override;
void cancel(CheckStatusWrapper* status) override;
unsigned getBlobAlignment(CheckStatusWrapper* status) override;
void setDefaultBpb(CheckStatusWrapper* status, unsigned parLength, const unsigned char* par) override;
IMessageMetadata* getMetadata(CheckStatusWrapper* status) override;
void close(CheckStatusWrapper* status) override;
void deprecatedClose(CheckStatusWrapper* status) override;
void getInfo(CheckStatusWrapper* status,
unsigned int itemsLength, const unsigned char* items,
unsigned int bufferLength, unsigned char* buffer) override;
private:
void freeClientData(CheckStatusWrapper* status, bool force = false);
void internalClose(CheckStatusWrapper* status);
void releaseStatement();
void setServerInfo();
void cleanup()
{
if (blobPolicy != BLOB_NONE)
blobStream = blobStreamBuffer;
sizePointer = nullptr;
messageStream = 0;
}
void genBlobId(ISC_QUAD* blobId)
{
if (++genId.gds_quad_low == 0)
++genId.gds_quad_high;
memcpy(blobId, &genId, sizeof(genId));
}
bool batchHasData()
{
return batchActive;
}
// working with message stream buffer
void putMessageData(ULONG count, const void* p)
{
fb_assert(messageStreamBuffer);
const UCHAR* ptr = static_cast<const UCHAR*>(p);
while(count)
{
ULONG remainSpace = messageBufferSize - messageStream;
ULONG step = MIN(count, remainSpace);
if (step == messageBufferSize)
{
// direct packet sent
sendMessagePacket(step, ptr, false);
}
else
{
// use buffer
memcpy(&messageStreamBuffer[messageStream * alignedSize], ptr, step * alignedSize);
messageStream += step;
if (messageStream == messageBufferSize)
{
sendMessagePacket(messageBufferSize, messageStreamBuffer, false);
messageStream = 0;
}
}
count -= step;
ptr += step * alignedSize;
}
}
// working with blob stream buffer
void newBlob()
{
setServerInfo();
alignBlobBuffer(blobAlign);
fb_assert(blobStream - blobStreamBuffer <= blobBufferSize);
ULONG space = blobBufferSize - (blobStream - blobStreamBuffer);
if (space < Rsr::BatchStream::SIZEOF_BLOB_HEAD)
{
sendBlobPacket(blobStream - blobStreamBuffer, blobStreamBuffer, false);
blobStream = blobStreamBuffer;
}
}
void alignBlobBuffer(unsigned alignment, ULONG* bs = NULL)
{
fb_assert(alignment);
ULONG align = FB_ALIGN(blobStream, alignment) - blobStream;
if (bs)
*bs += align;
FB_UINT64 zeroFill = 0;
putBlobData(align, &zeroFill);
}
void putBlobData(ULONG size, const void* p)
{
fb_assert(blobStreamBuffer);
const UCHAR* ptr = static_cast<const UCHAR*>(p);
while(size)
{
ULONG space = blobBufferSize - (blobStream - blobStreamBuffer);
ULONG step = MIN(size, space);
if (step == blobBufferSize)
{
// direct packet sent
sendBlobPacket(blobBufferSize, ptr, false);
}
else
{
// use buffer
memcpy(blobStream, ptr, step);
blobStream += step;
if (blobStream - blobStreamBuffer == blobBufferSize)
{
sendBlobPacket(blobBufferSize, blobStreamBuffer, false);
blobStream = blobStreamBuffer;
sizePointer = nullptr;
}
}
size -= step;
ptr += step;
}
}
void setSizePointer()
{
fb_assert(FB_ALIGN(blobStream, sizeof(*sizePointer)) == blobStream);
sizePointer = reinterpret_cast<ULONG*>(blobStream);
}
void putSegment(ULONG size, const void* ptr)
{
if (!sizePointer)
{
newBlob();
ISC_QUAD quadZero = {0, 0};
putBlobData(sizeof quadZero, &quadZero);
setSizePointer();
ULONG longZero = 0;
putBlobData(sizeof longZero, &longZero);
putBlobData(sizeof longZero, &longZero);
}
*sizePointer += size;
if (segmented)
{
if (size > MAX_USHORT)
{
(Arg::Gds(isc_imp_exc) << Arg::Gds(isc_blobtoobig)
<< Arg::Gds(isc_big_segment) << Arg::Num(size)).raise();
}
*sizePointer += sizeof(USHORT);
alignBlobBuffer(BLOB_SEGHDR_ALIGN, sizePointer);
USHORT segSize = size;
putBlobData(sizeof segSize, &segSize);
}
putBlobData(size, ptr);
}
void flashBatch()
{
if (blobPolicy != BLOB_NONE)
{
setServerInfo();
alignBlobBuffer(blobAlign);
ULONG size = blobStream - blobStreamBuffer;
if (size)
{
sendBlobPacket(size, blobStreamBuffer, messageStream == 0);
blobStream = blobStreamBuffer;
}
}
if (messageStream)
{
sendMessagePacket(messageStream, messageStreamBuffer, true);
messageStream = 0;
}
batchActive = false;
blobCount = messageCount = 0;
}
void sendBlobPacket(unsigned size, const UCHAR* ptr, bool flash);
void sendMessagePacket(unsigned size, const UCHAR* ptr, bool flash);
void sendDeferredPacket(IStatus* status, rem_port* port, PACKET* packet, bool flash);
AutoPtr<UCHAR, ArrayDelete> messageStreamBuffer, blobStreamBuffer;
ULONG messageStream;
UCHAR* blobStream;
ULONG* sizePointer;
ULONG messageSize, alignedSize, blobBufferSize, messageBufferSize, flags;
Statement* stmt;
RefPtr<IMessageMetadata> format;
ISC_QUAD genId;
int blobAlign;
UCHAR blobPolicy;
bool segmented, defSegmented, batchActive;
ULONG messageCount, blobCount, serverSize, blobHeadSize;
public:
bool tmpStatement;
};
int Batch::release()
{
if (--refCounter != 0)
return 1;
if (stmt)
{
LocalStatus ls;
CheckStatusWrapper status(&ls);
freeClientData(&status, true);
}
delete this;
return 0;
}
class Replicator final : public RefCntIface<IReplicatorImpl<Replicator, CheckStatusWrapper> >
{
public:
// IReplicator implementation
int release() override;
void process(CheckStatusWrapper* status, unsigned length, const unsigned char* data) override;
void close(CheckStatusWrapper* status) override;
void deprecatedClose(CheckStatusWrapper* status) override;
explicit Replicator(Attachment* att) : attachment(att)
{}
private:
void freeClientData(CheckStatusWrapper* status, bool force = false);
void internalClose(CheckStatusWrapper* status);
Attachment* attachment;
};
int Replicator::release()
{
if (--refCounter != 0)
return 1;
if (attachment)
{
LocalStatus ls;
CheckStatusWrapper status(&ls);
freeClientData(&status, true);
}
delete this;
return 0;
}
class Statement final : public RefCntIface<IStatementImpl<Statement, CheckStatusWrapper> >
{
public:
// IStatement implementation
int release() override;
void getInfo(CheckStatusWrapper* status,
unsigned int itemsLength, const unsigned char* items,
unsigned int bufferLength, unsigned char* buffer) override;
unsigned getType(CheckStatusWrapper* status) override;
const char* getPlan(CheckStatusWrapper* status, FB_BOOLEAN detailed) override;
IMessageMetadata* getInputMetadata(CheckStatusWrapper* status) override;
IMessageMetadata* getOutputMetadata(CheckStatusWrapper* status) override;
ISC_UINT64 getAffectedRecords(CheckStatusWrapper* status) override;
ITransaction* execute(CheckStatusWrapper* status, ITransaction* tra,
IMessageMetadata* inMetadata, void* inBuffer,
IMessageMetadata* outMetadata, void* outBuffer) override;
ResultSet* openCursor(CheckStatusWrapper* status, ITransaction* tra,
IMessageMetadata* inMetadata, void* inBuffer, IMessageMetadata* outFormat,
unsigned int flags) override;
void setCursorName(CheckStatusWrapper* status, const char* name) override;
void free(CheckStatusWrapper* status) override;
void deprecatedFree(CheckStatusWrapper* status) override;
unsigned getFlags(CheckStatusWrapper* status) override;
unsigned int getTimeout(CheckStatusWrapper* status) override
{
if (statement->rsr_rdb->rdb_port->port_protocol < PROTOCOL_STMT_TOUT)
{
status->setErrors(Arg::Gds(isc_wish_list).value());
return 0;
}
return statement->rsr_timeout;
}
void setTimeout(CheckStatusWrapper* status, unsigned int timeOut) override
{
if (timeOut && statement->rsr_rdb->rdb_port->port_protocol < PROTOCOL_STMT_TOUT)
{
status->setErrors(Arg::Gds(isc_wish_list).value());
return;
}
statement->rsr_timeout = timeOut;
}
Batch* createBatch(CheckStatusWrapper* status, IMessageMetadata* inMetadata,
unsigned parLength, const unsigned char* par) override;
unsigned getMaxInlineBlobSize(CheckStatusWrapper* status) override;
void setMaxInlineBlobSize(CheckStatusWrapper* status, unsigned size) override;
public:
Statement(Rsr* handle, Attachment* a, unsigned aDialect)
: metadata(getPool(), this, NULL),
remAtt(a),
statement(handle),
dialect(aDialect)
{
statement->rsr_self = &statement;
}
Rsr* getStatement()
{
return statement;
}
Attachment* getAttachment()
{
return remAtt;
}
void parseMetadata(const Array<UCHAR>& buffer)
{
metadata.clear();
metadata.parse((ULONG) buffer.getCount(), buffer.begin());
}
unsigned getDialect() const
{
return dialect;
}
private:
void freeClientData(CheckStatusWrapper* status, bool force = false);
void internalFree(CheckStatusWrapper* status);
~Statement()
{
if (statement)
statement->rsr_self = NULL;
}
StatementMetadata metadata;
Attachment* remAtt;
Rsr* statement;
unsigned dialect;
};
int Statement::release()
{
if (--refCounter != 0)
return 1;
if (statement)
{
LocalStatus ls;
CheckStatusWrapper status(&ls);
freeClientData(&status, true);
}
delete this;
return 0;
}
class Request final : public RefCntIface<IRequestImpl<Request, CheckStatusWrapper> >
{
public:
// IRequest implementation
int release() override;
void receive(CheckStatusWrapper* status, int level, unsigned int msg_type,
unsigned int length, void* message) override;
void send(CheckStatusWrapper* status, int level, unsigned int msg_type,
unsigned int length, const void* message) override;
void getInfo(CheckStatusWrapper* status, int level,
unsigned int itemsLength, const unsigned char* items,
unsigned int bufferLength, unsigned char* buffer) override;
void start(CheckStatusWrapper* status, ITransaction* tra, int level) override;
void startAndSend(CheckStatusWrapper* status, ITransaction* tra, int level, unsigned int msg_type,
unsigned int length, const void* message) override;
void unwind(CheckStatusWrapper* status, int level) override;
void free(CheckStatusWrapper* status) override;
void deprecatedFree(CheckStatusWrapper* status) override;
public:
Request(Rrq* handle, Attachment* a)
: remAtt(a), rq(handle)
{
rq->rrq_self = &rq;
}
private:
void freeClientData(CheckStatusWrapper* status, bool force = false);
void internalFree(CheckStatusWrapper* status);
Attachment* remAtt;
Rrq* rq;
};
int Request::release()
{
if (--refCounter != 0)
return 1;
if (rq)
{
LocalStatus ls;
CheckStatusWrapper status(&ls);
freeClientData(&status, true);
}
delete this;
return 0;
}
class Events final : public RefCntIface<IEventsImpl<Events, CheckStatusWrapper> >
{
public:
// IEvents implementation
int release() override;
void cancel(CheckStatusWrapper* status) override;
void deprecatedCancel(CheckStatusWrapper* status) override;
public:
Events(Rvnt* handle)
: rvnt(handle), rdb(rvnt->rvnt_rdb)
{
rvnt->rvnt_self = &rvnt;
}
private:
void freeClientData(CheckStatusWrapper* status, bool force = false);
void internalCancel(CheckStatusWrapper* status);
Rvnt* rvnt;
Rdb* rdb;
};
int Events::release()
{
int rc = --refCounter;
if (rc != 0)
{
fb_assert(rc > 0);
return 1;
}
if (rvnt)
{
LocalStatus ls;
CheckStatusWrapper status(&ls);
freeClientData(&status, true);
}
delete this;
return 0;
}
class Attachment final : public RefCntIface<IAttachmentImpl<Attachment, CheckStatusWrapper> >
{
public:
// IAttachment implementation
int release() override;
void getInfo(CheckStatusWrapper* status,
unsigned int itemsLength, const unsigned char* items,
unsigned int bufferLength, unsigned char* buffer) override;
ITransaction* startTransaction(CheckStatusWrapper* status,
unsigned int tpbLength, const unsigned char* tpb) override;
ITransaction* reconnectTransaction(CheckStatusWrapper* status, unsigned int length, const unsigned char* id) override;
IRequest* compileRequest(CheckStatusWrapper* status, unsigned int blr_length, const unsigned char* blr) override;
void transactRequest(CheckStatusWrapper* status, ITransaction* transaction,
unsigned int blr_length, const unsigned char* blr,
unsigned int in_msg_length, const unsigned char* in_msg,
unsigned int out_msg_length, unsigned char* out_msg) override;
IBlob* createBlob(CheckStatusWrapper* status, ITransaction* transaction,
ISC_QUAD* id, unsigned int bpbLength = 0, const unsigned char* bpb = 0) override;
IBlob* openBlob(CheckStatusWrapper* status, ITransaction* transaction,
ISC_QUAD* id, unsigned int bpbLength = 0, const unsigned char* bpb = 0) override;
int getSlice(CheckStatusWrapper* status, ITransaction* transaction, ISC_QUAD* id,
unsigned int sdl_length, const unsigned char* sdl,
unsigned int param_length, const unsigned char* param,
int sliceLength, unsigned char* slice) override;
void putSlice(CheckStatusWrapper* status, ITransaction* transaction, ISC_QUAD* id,
unsigned int sdl_length, const unsigned char* sdl,
unsigned int param_length, const unsigned char* param,
int sliceLength, unsigned char* slice) override;
void executeDyn(CheckStatusWrapper* status, ITransaction* transaction, unsigned int length,
const unsigned char* dyn) override;
Statement* prepare(CheckStatusWrapper* status, ITransaction* transaction,
unsigned int stmtLength, const char* sqlStmt, unsigned int dialect, unsigned int flags) override;
ITransaction* execute(CheckStatusWrapper* status, ITransaction* transaction,
unsigned int stmtLength, const char* sqlStmt, unsigned int dialect,
IMessageMetadata* inMetadata, void* inBuffer, IMessageMetadata* outMetadata, void* outBuffer) override;
IResultSet* openCursor(CheckStatusWrapper* status, ITransaction* transaction,
unsigned int stmtLength, const char* sqlStmt, unsigned dialect,
IMessageMetadata* inMetadata, void* inBuffer, IMessageMetadata* outMetadata,
const char* cursorName, unsigned int cursorFlags) override;
IEvents* queEvents(CheckStatusWrapper* status, IEventCallback* callback,
unsigned int length, const unsigned char* events) override;
void cancelOperation(CheckStatusWrapper* status, int option) override;
void ping(CheckStatusWrapper* status) override;
void detach(CheckStatusWrapper* status) override;
void dropDatabase(CheckStatusWrapper* status) override;
void deprecatedDetach(CheckStatusWrapper* status) override;
void deprecatedDropDatabase(CheckStatusWrapper* status) override;
unsigned int getIdleTimeout(CheckStatusWrapper* status) override;
void setIdleTimeout(CheckStatusWrapper* status, unsigned int timeOut) override;
unsigned int getStatementTimeout(CheckStatusWrapper* status) override;
void setStatementTimeout(CheckStatusWrapper* status, unsigned int timeOut) override;
Batch* createBatch(CheckStatusWrapper* status, ITransaction* transaction,
unsigned stmtLength, const char* sqlStmt, unsigned dialect,
IMessageMetadata* inMetadata, unsigned parLength, const unsigned char* par) override;
Replicator* createReplicator(CheckStatusWrapper* status) override;
unsigned getMaxBlobCacheSize(CheckStatusWrapper* status) override;
void setMaxBlobCacheSize(CheckStatusWrapper* status, unsigned size) override;
unsigned getMaxInlineBlobSize(CheckStatusWrapper* status) override;
void setMaxInlineBlobSize(CheckStatusWrapper* status, unsigned size) override;
public:
Attachment(Rdb* handle, const PathName& path)
: replicator(nullptr), rdb(handle), dbPath(getPool(), path)
{ }
Rdb* getRdb()
{
return rdb;
}
const PathName& getDbPath()
{
return dbPath;
}
Rtr* remoteTransaction(ITransaction* apiTra);
Transaction* remoteTransactionInterface(ITransaction* apiTra);
Statement* createStatement(CheckStatusWrapper* status, unsigned dialect);
// Set params that was set in DPB, ignoring unknown and not applicable tags.
void setParamsFromDPB(ClumpletReader& dpb);
Replicator* replicator;
private:
void execWithCheck(CheckStatusWrapper* status, const string& stmt);
void freeClientData(CheckStatusWrapper* status, bool force = false);
void internalDetach(CheckStatusWrapper* status);
void internalDropDatabase(CheckStatusWrapper* status);
SLONG getSingleInfo(CheckStatusWrapper* status, UCHAR infoItem);
// Returns nullptr if all items was handled or if user buffer is full, else
// returns pointer into unused buffer space. Handled info items are removed.
unsigned char* getLocalInfo(UCharBuffer& info, unsigned int buffer_length,
unsigned char* buffer);
Rdb* rdb;
const PathName dbPath;
};
int Attachment::release()
{
if (--refCounter != 0)
return 1;
if (rdb)
{
LocalStatus ls;
CheckStatusWrapper status(&ls);
freeClientData(&status, true);
}
delete this;
return 0;
}
class Service final : public RefCntIface<IServiceImpl<Service, CheckStatusWrapper> >
{
public:
// IService implementation
int release() override;
void detach(CheckStatusWrapper* status) override;
void deprecatedDetach(CheckStatusWrapper* status) override;
void query(CheckStatusWrapper* status,
unsigned int sendLength, const unsigned char* sendItems,
unsigned int receiveLength, const unsigned char* receiveItems,
unsigned int bufferLength, unsigned char* buffer) override;
void start(CheckStatusWrapper* status, unsigned int spbLength, const unsigned char* spb) override;
void cancel(CheckStatusWrapper* status) override;
public:
Service(Rdb* handle) : rdb(handle) { }