-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathconn.c
More file actions
1330 lines (1130 loc) · 31.6 KB
/
conn.c
File metadata and controls
1330 lines (1130 loc) · 31.6 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
/******************************************************************
Copyright 2001 by Object Craft P/L, Melbourne, Australia.
LICENCE - see LICENCE file distributed with this software for details.
******************************************************************/
#include "sybasect.h"
static CS_CONNECTIONObj *conn_list;
static void conn_add_object(CS_CONNECTIONObj *conn)
{
conn->next = conn_list;
conn_list = conn;
}
static void conn_del_object(CS_CONNECTIONObj *conn)
{
CS_CONNECTIONObj *scan, *prev;
for (prev = NULL, scan = conn_list; scan != NULL; scan = scan->next) {
if (scan == conn) {
if (prev == NULL)
conn_list = scan->next;
else
prev->next = scan->next;
}
}
}
PyObject *conn_find_object(CS_CONNECTION *cs_conn)
{
CS_CONNECTIONObj *conn;
for (conn = conn_list; conn != NULL; conn = conn->next)
if (conn->conn == cs_conn)
return (PyObject*)conn;
return NULL;
}
static char CS_CONNECTION_ct_diag__doc__[] =
"ct_diag(CS_INIT) -> status\n"
"ct_diag(CS_MSGLIMIT, type, num) -> status\n"
"ct_diag(CS_CLEAR, type) -> status\n"
"ct_diag(CS_GET, type, index) -> status, msg\n"
"ct_diag(CS_STATUS, type) -> status, num\n"
"ct_diag(CS_EED_CMD, type, index) -> status, cmd";
static PyObject *CS_CONNECTION_ct_diag(CS_CONNECTIONObj *self, PyObject *args)
{
int operation, type, index, num;
CS_VOID *buffer;
PyObject *msg;
CS_RETCODE status;
#ifndef HAVE_FREETDS
PyObject *cmd;
CS_COMMAND *eed;
#endif
if (!first_tuple_int(args, &operation))
return NULL;
if (self->conn == NULL) {
PyErr_SetString(PyExc_TypeError, "CS_CONNECTION has been dropped");
return NULL;
}
switch (operation) {
case CS_INIT:
/* ct_diag(CS_INIT) -> status */
if (!PyArg_ParseTuple(args, "i", &operation))
return NULL;
/* PyErr_Clear(); */
#ifdef HAVE_FREETDS
status = CS_SUCCEED;
#else
SY_CONN_BEGIN_THREADS(self);
status = ct_diag(self->conn, operation, CS_UNUSED, CS_UNUSED, NULL);
SY_CONN_END_THREADS(self);
#endif
if (self->debug)
debug_msg("ct_diag(conn%d, CS_INIT, CS_UNUSED, CS_UNUSED, NULL)"
" -> %s\n",
self->serial, value_str(VAL_STATUS, status));
if (PyErr_Occurred())
return NULL;
return PyInt_FromLong(status);
case CS_MSGLIMIT:
/* ct_diag(CS_MSGLIMIT, type, num) -> status */
if (!PyArg_ParseTuple(args, "iii", &operation, &type, &num))
return NULL;
/* PyErr_Clear(); */
#ifdef HAVE_FREETDS
status = CS_SUCCEED;
#else
SY_CONN_BEGIN_THREADS(self);
status = ct_diag(self->conn, operation, type, CS_UNUSED, &num);
SY_CONN_END_THREADS(self);
#endif
if (self->debug)
debug_msg("ct_diag(conn%d, CS_MSGLIMIT, %s, CS_UNUSED, %d)"
" -> %s\n",
self->serial, value_str(VAL_TYPE, type), num,
value_str(VAL_STATUS, status));
if (PyErr_Occurred())
return NULL;
return PyInt_FromLong(status);
case CS_CLEAR:
/* ct_diag(CS_CLEAR, type) -> status */
if (!PyArg_ParseTuple(args, "ii", &operation, &type))
return NULL;
/* PyErr_Clear(); */
#ifdef HAVE_FREETDS
status = CS_SUCCEED;
#else
SY_CONN_BEGIN_THREADS(self);
status = ct_diag(self->conn, operation, type, CS_UNUSED, NULL);
SY_CONN_END_THREADS(self);
#endif
if (self->debug)
debug_msg("ct_diag(conn%d, CS_CLEAR, %s, CS_UNUSED, NULL) -> %s\n",
self->serial, value_str(VAL_TYPE, type),
value_str(VAL_STATUS, status));
if (PyErr_Occurred())
return NULL;
return PyInt_FromLong(status);
case CS_GET:
/* ct_diag(CS_GET, type, index) -> status, msg */
if (!PyArg_ParseTuple(args, "iii", &operation, &type, &index))
return NULL;
if (type == CS_CLIENTMSG_TYPE) {
if ((msg = clientmsg_alloc()) == NULL)
return NULL;
buffer = &((CS_CLIENTMSGObj*)msg)->msg;
} else if (type == CS_SERVERMSG_TYPE) {
if ((msg = servermsg_alloc()) == NULL)
return NULL;
buffer = &((CS_SERVERMSGObj*)msg)->msg;
} else {
PyErr_SetString(PyExc_TypeError, "unsupported message type");
return NULL;
}
/* PyErr_Clear(); */
#ifdef HAVE_FREETDS
status = CS_SUCCEED;
#else
SY_CONN_BEGIN_THREADS(self);
status = ct_diag(self->conn, operation, type, index, buffer);
SY_CONN_END_THREADS(self);
#endif
if (self->debug)
debug_msg("ct_diag(conn%d, CS_GET, %s, %d, buff) -> %s\n",
self->serial, value_str(VAL_TYPE, type), index,
value_str(VAL_STATUS, status));
if (PyErr_Occurred()) {
Py_DECREF(msg);
return NULL;
}
if (status != CS_SUCCEED) {
Py_DECREF(msg);
return Py_BuildValue("iO", status, Py_None);
}
return Py_BuildValue("iN", CS_SUCCEED, msg);
case CS_STATUS:
/* ct_diag(CS_STATUS, type) -> status, num */
if (!PyArg_ParseTuple(args, "ii", &operation, &type))
return NULL;
num = 0;
/* PyErr_Clear(); */
#ifdef HAVE_FREETDS
status = CS_SUCCEED;
#else
SY_CONN_BEGIN_THREADS(self);
status = ct_diag(self->conn, operation, type, CS_UNUSED, &num);
SY_CONN_END_THREADS(self);
#endif
if (self->debug)
debug_msg("ct_diag(conn%d, CS_STATUS, %s, CS_UNUSED, &num)"
" -> %s, %d\n",
self->serial, value_str(VAL_TYPE, type),
value_str(VAL_STATUS, status), num);
if (PyErr_Occurred())
return NULL;
return Py_BuildValue("ii", status, num);
#ifndef HAVE_FREETDS
case CS_EED_CMD:
/* ct_diag(CS_EED_CMD, type, index) -> status, cmd */
if (!PyArg_ParseTuple(args, "iii", &operation, &type, &index))
return NULL;
/* PyErr_Clear(); */
SY_CONN_BEGIN_THREADS(self);
status = ct_diag(self->conn, operation, type, index, &eed);
SY_CONN_END_THREADS(self);
if (self->debug)
debug_msg("ct_diag(conn%d, CS_EED_CMD, %s, %d, &eed) -> %s",
self->serial, value_str(VAL_TYPE, type), index,
value_str(VAL_STATUS, status));
if (PyErr_Occurred()) {
if (self->debug)
debug_msg("\n");
return NULL;
}
cmd = cmd_eed(self, eed);
if (cmd == NULL) {
if (self->debug)
debug_msg("\n");
return NULL;
}
if (self->debug)
debug_msg(", cmd%d\n", ((CS_COMMANDObj*)cmd)->serial);
return Py_BuildValue("iN", status, cmd);
#endif
default:
PyErr_SetString(PyExc_TypeError, "unknown operation");
return NULL;
}
}
static char CS_CONNECTION_ct_cancel__doc__[] =
"ct_cancel(type) -> status";
static PyObject *CS_CONNECTION_ct_cancel(CS_CONNECTIONObj *self, PyObject *args)
{
int type;
CS_RETCODE status;
if (!PyArg_ParseTuple(args, "i", &type))
return NULL;
if (self->conn == NULL) {
PyErr_SetString(PyExc_TypeError, "CS_CONNECTION has been dropped");
return NULL;
}
/* PyErr_Clear(); */
SY_CONN_BEGIN_THREADS(self);
status = ct_cancel(self->conn, NULL, type);
SY_CONN_END_THREADS(self);
if (self->debug)
debug_msg("ct_cancel(conn%d, NULL, %s) -> %s\n",
self->serial, value_str(VAL_CANCEL, type),
value_str(VAL_STATUS, status));
if (PyErr_Occurred())
return NULL;
return PyInt_FromLong(status);
}
static char CS_CONNECTION_ct_connect__doc__[] =
"ct_connect(str = None) - > status";
static PyObject *CS_CONNECTION_ct_connect(CS_CONNECTIONObj *self, PyObject *args)
{
CS_RETCODE status;
char *dsn = NULL;
if (!PyArg_ParseTuple(args, "|s", &dsn))
return NULL;
if (self->conn == NULL) {
PyErr_SetString(PyExc_TypeError, "CS_CONNECTION has been dropped");
return NULL;
}
/* PyErr_Clear(); */
if (dsn == NULL) {
SY_CONN_BEGIN_THREADS(self);
status = ct_connect(self->conn, NULL, 0);
SY_CONN_END_THREADS(self);
if (self->debug)
debug_msg("ct_connect(conn%d, NULL, 0) -> %s\n",
self->serial, value_str(VAL_STATUS, status));
} else {
SY_CONN_BEGIN_THREADS(self);
status = ct_connect(self->conn, dsn, CS_NULLTERM);
SY_CONN_END_THREADS(self);
if (self->debug)
debug_msg("ct_connect(conn%d, \"%s\", CS_NULLTERM) -> %s\n",
self->serial, dsn, value_str(VAL_STATUS, status));
}
if (PyErr_Occurred())
return NULL;
return PyInt_FromLong(status);
}
static char CS_CONNECTION_ct_cmd_alloc__doc__[] =
"ct_cmd_alloc() -> status, cmd";
static PyObject *CS_CONNECTION_ct_cmd_alloc(CS_CONNECTIONObj *self, PyObject *args)
{
if (!PyArg_ParseTuple(args, ""))
return NULL;
if (self->conn == NULL) {
PyErr_SetString(PyExc_TypeError, "CS_CONNECTION has been dropped");
return NULL;
}
return cmd_alloc(self);
}
#ifdef WANT_BULKCOPY
static char CS_CONNECTION_blk_alloc__doc__[] =
"blk_alloc([version = BLK_VERSION_100) -> status, blk";
static PyObject *CS_CONNECTION_blk_alloc(CS_CONNECTIONObj *self, PyObject *args)
{
int version = BLK_VERSION_100;
if (!PyArg_ParseTuple(args, "|i", &version))
return NULL;
if (self->conn == NULL) {
PyErr_SetString(PyExc_TypeError, "CS_CONNECTION has been dropped");
return NULL;
}
return bulk_alloc(self, version);
}
#endif
static char CS_CONNECTION_ct_close__doc__[] =
"ct_close([option]) - > status";
static PyObject *CS_CONNECTION_ct_close(CS_CONNECTIONObj *self, PyObject *args)
{
CS_RETCODE status;
int option = CS_UNUSED;
if (!PyArg_ParseTuple(args, "|i", &option))
return NULL;
if (self->conn == NULL) {
PyErr_SetString(PyExc_TypeError, "CS_CONNECTION has been dropped");
return NULL;
}
/* PyErr_Clear(); */
SY_CONN_BEGIN_THREADS(self);
status = ct_close(self->conn, option);
SY_CONN_END_THREADS(self);
if (self->debug)
debug_msg("ct_close(conn%d, %s) -> %s\n",
self->serial, value_str(VAL_OPTION, option),
value_str(VAL_STATUS, status));
if (PyErr_Occurred())
return NULL;
return PyInt_FromLong(status);
}
static char CS_CONNECTION_ct_con_drop__doc__[] =
"ct_con_drop() - > status";
static PyObject *CS_CONNECTION_ct_con_drop(CS_CONNECTIONObj *self, PyObject *args)
{
CS_RETCODE status;
if (!PyArg_ParseTuple(args, ""))
return NULL;
if (self->conn == NULL) {
PyErr_SetString(PyExc_TypeError, "CS_CONNECTION has been dropped");
return NULL;
}
/* PyErr_Clear(); */
SY_CONN_BEGIN_THREADS(self);
status = ct_con_drop(self->conn);
SY_CONN_END_THREADS(self);
if (self->debug)
debug_msg("ct_con_drop(conn%d) -> %s\n",
self->serial, value_str(VAL_STATUS, status));
if (status == CS_SUCCEED)
self->conn = NULL;
if (PyErr_Occurred())
return NULL;
return PyInt_FromLong(status);
}
static int property_type(int property)
{
switch (property) {
#ifdef CS_ANSI_BINDS
case CS_ANSI_BINDS:
#endif
#ifdef CS_ASYNC_NOTIFS
case CS_ASYNC_NOTIFS:
#endif
#ifdef CS_BULK_LOGIN
case CS_BULK_LOGIN:
#endif
#ifdef CS_CHARSETCNV
case CS_CHARSETCNV:
#endif
#ifdef CS_CONFIG_BY_SERVERNAME
case CS_CONFIG_BY_SERVERNAME:
#endif
#ifdef CS_DIAG_TIMEOUT
case CS_DIAG_TIMEOUT:
#endif
#ifdef CS_DISABLE_POLL
case CS_DISABLE_POLL:
#endif
#ifdef CS_DS_COPY
case CS_DS_COPY:
#endif
#ifdef CS_DS_EXPANDALIAS
case CS_DS_EXPANDALIAS:
#endif
#ifdef CS_DS_FAILOVER
case CS_DS_FAILOVER:
#endif
#ifdef CS_EXPOSE_FMTS
case CS_EXPOSE_FMTS:
#endif
#ifdef CS_EXTERNAL_CONFIG
case CS_EXTERNAL_CONFIG:
#endif
#ifdef CS_EXTRA_INF
case CS_EXTRA_INF:
#endif
#ifdef CS_HIDDEN_KEYS
case CS_HIDDEN_KEYS:
#endif
#ifdef CS_LOGIN_STATUS
case CS_LOGIN_STATUS:
#endif
#ifdef CS_NOCHARSETCNV_REQD
case CS_NOCHARSETCNV_REQD:
#endif
#ifdef CS_SEC_APPDEFINED
case CS_SEC_APPDEFINED:
#endif
#ifdef CS_SEC_CHALLENGE
case CS_SEC_CHALLENGE:
#endif
#ifdef CS_SEC_CHANBIND
case CS_SEC_CHANBIND:
#endif
#ifdef CS_SEC_CONFIDENTIALITY
case CS_SEC_CONFIDENTIALITY:
#endif
#ifdef CS_SEC_DATAORIGIN
case CS_SEC_DATAORIGIN:
#endif
#ifdef CS_SEC_DELEGATION
case CS_SEC_DELEGATION:
#endif
#ifdef CS_SEC_DETECTREPLAY
case CS_SEC_DETECTREPLAY:
#endif
#ifdef CS_SEC_DETECTSEQ
case CS_SEC_DETECTSEQ:
#endif
#ifdef CS_SEC_ENCRYPTION
case CS_SEC_ENCRYPTION:
#endif
#ifdef CS_SEC_INTEGRITY
case CS_SEC_INTEGRITY:
#endif
#ifdef CS_SEC_MUTUALAUTH
case CS_SEC_MUTUALAUTH:
#endif
#ifdef CS_SEC_NEGOTIATE
case CS_SEC_NEGOTIATE:
#endif
#ifdef CS_SEC_NETWORKAUTH
case CS_SEC_NETWORKAUTH:
#endif
return OPTION_BOOL;
#ifdef CS_CON_STATUS
case CS_CON_STATUS:
#endif
#ifdef CS_LOOP_DELAY
case CS_LOOP_DELAY:
#endif
#ifdef CS_RETRY_COUNT
case CS_RETRY_COUNT:
#endif
#ifdef CS_NETIO
case CS_NETIO:
#endif
#ifdef CS_TEXTLIMIT
case CS_TEXTLIMIT:
#endif
#ifdef CS_DS_SEARCH
case CS_DS_SEARCH:
#endif
#ifdef CS_DS_SIZELIMIT
case CS_DS_SIZELIMIT:
#endif
#ifdef CS_DS_TIMELIMIT
case CS_DS_TIMELIMIT:
#endif
#ifdef CS_ENDPOINT
case CS_ENDPOINT:
#endif
#ifdef CS_PACKETSIZE
case CS_PACKETSIZE:
#endif
#ifdef CS_SEC_CREDTIMEOUT
case CS_SEC_CREDTIMEOUT:
#endif
#ifdef CS_SEC_SESSTIMEOUT
case CS_SEC_SESSTIMEOUT:
#endif
#ifdef CS_TDS_VERSION
case CS_TDS_VERSION:
#endif
return OPTION_INT;
#ifdef CS_APPNAME
case CS_APPNAME:
#endif
#ifdef CS_HOSTNAME
case CS_HOSTNAME:
#endif
#ifdef CS_PASSWORD
case CS_PASSWORD:
#endif
#ifdef CS_SERVERNAME
case CS_SERVERNAME:
#endif
#ifdef CS_USERNAME
case CS_USERNAME:
#endif
#ifdef CS_DS_DITBASE
case CS_DS_DITBASE:
#endif
#ifdef CS_DS_PASSWORD
case CS_DS_PASSWORD:
#endif
#ifdef CS_DS_PRINCIPAL
case CS_DS_PRINCIPAL:
#endif
#ifdef CS_DS_PROVIDER
case CS_DS_PROVIDER:
#endif
#ifdef CS_SEC_KEYTAB
case CS_SEC_KEYTAB:
#endif
#ifdef CS_SEC_MECHANISM
case CS_SEC_MECHANISM:
#endif
#ifdef CS_SEC_SERVERPRINCIPAL
case CS_SEC_SERVERPRINCIPAL:
#endif
#ifdef CS_TRANSACTION_NAME
case CS_TRANSACTION_NAME:
#endif
return OPTION_STRING;
#ifdef CS_LOC_PROP
case CS_LOC_PROP:
return OPTION_LOCALE;
#endif
#ifdef CS_EED_CMD
case CS_EED_CMD:
return OPTION_CMD;
#endif
default:
return OPTION_UNKNOWN;
}
}
static char CS_CONNECTION_ct_con_props__doc__[] =
"ct_con_props(CS_SET, property, value) -> status\n"
"ct_con_props(CS_GET, property) -> status, value\n"
#ifdef CS_CLEAR
"ct_con_props(CS_CLEAR, property) -> status\n"
#endif
;
static PyObject *CS_CONNECTION_ct_con_props(CS_CONNECTIONObj *self, PyObject *args)
{
int action, property;
PyObject *obj = NULL;
CS_RETCODE status;
CS_INT int_value;
CS_BOOL bool_value;
char *str_value;
char str_buff[10240];
CS_INT buff_len;
if (!first_tuple_int(args, &action))
return NULL;
if (self->conn == NULL) {
PyErr_SetString(PyExc_TypeError, "CS_CONNECTION has been dropped");
return NULL;
}
switch (action) {
case CS_SET:
/* ct_con_props(CS_SET, property, value) -> status */
if (!PyArg_ParseTuple(args, "iiO", &action, &property, &obj))
return NULL;
switch (property_type(property)) {
case OPTION_BOOL:
bool_value = PyInt_AsLong(obj);
if (PyErr_Occurred())
return NULL;
/* PyErr_Clear(); */
SY_CONN_BEGIN_THREADS(self);
status = ct_con_props(self->conn, CS_SET, property,
&bool_value, CS_UNUSED, NULL);
SY_CONN_END_THREADS(self);
if (self->debug)
debug_msg("ct_con_props(conn%d, CS_SET, %s, %d, CS_UNUSED,"
" NULL) -> %s\n",
self->serial,
value_str(VAL_PROPS, property), (int)bool_value,
value_str(VAL_STATUS, status));
if (PyErr_Occurred())
return NULL;
return PyInt_FromLong(status);
case OPTION_INT:
int_value = PyInt_AsLong(obj);
if (PyErr_Occurred())
return NULL;
/* PyErr_Clear(); */
SY_CONN_BEGIN_THREADS(self);
status = ct_con_props(self->conn, CS_SET, property,
&int_value, CS_UNUSED, NULL);
SY_CONN_END_THREADS(self);
if (self->debug)
debug_msg("ct_con_props(conn%d, CS_SET, %s, %d, CS_UNUSED,"
" NULL) -> %s\n",
self->serial,
value_str(VAL_PROPS, property), (int)int_value,
value_str(VAL_STATUS, status));
if (PyErr_Occurred())
return NULL;
return PyInt_FromLong(status);
case OPTION_STRING:
str_value = PyString_AsString(obj);
if (PyErr_Occurred())
return NULL;
/* PyErr_Clear(); */
SY_CONN_BEGIN_THREADS(self);
status = ct_con_props(self->conn, CS_SET, property,
str_value, CS_NULLTERM, NULL);
SY_CONN_END_THREADS(self);
if (self->debug)
debug_msg("ct_con_props(conn%d, CS_SET, %s, \"%s\","
" CS_NULLTERM, NULL) -> %s\n",
self->serial,
value_str(VAL_PROPS, property), str_value,
value_str(VAL_STATUS, status));
if (PyErr_Occurred())
return NULL;
return PyInt_FromLong(status);
case OPTION_LOCALE:
if (!CS_LOCALE_Check(obj)) {
PyErr_SetString(PyExc_TypeError, "CS_LOCALE is required");
return NULL;
}
/* PyErr_Clear(); */
SY_CONN_BEGIN_THREADS(self);
status = ct_con_props(self->conn, CS_SET, property,
((CS_LOCALEObj*)obj)->locale, CS_UNUSED, NULL);
SY_CONN_END_THREADS(self);
if (self->debug)
debug_msg("ct_con_props(conn%d, CS_SET, %s, locale%d,"
" CS_UNUSED, NULL) -> %s\n",
self->serial, value_str(VAL_PROPS, property),
((CS_LOCALEObj*)obj)->serial,
value_str(VAL_STATUS, status));
if (PyErr_Occurred())
return NULL;
return PyInt_FromLong(status);
default:
PyErr_SetString(PyExc_TypeError, "unhandled property value");
return NULL;
}
break;
case CS_GET:
/* ct_con_props(CS_GET, property) -> status, value */
if (!PyArg_ParseTuple(args, "ii", &action, &property))
return NULL;
switch (property_type(property)) {
case OPTION_BOOL:
/* PyErr_Clear(); */
SY_CONN_BEGIN_THREADS(self);
status = ct_con_props(self->conn, CS_GET, property,
&bool_value, CS_UNUSED, NULL);
SY_CONN_END_THREADS(self);
if (self->debug)
debug_msg("ct_con_props(conn%d, CS_GET, %s, &value, CS_UNUSED,"
" NULL) -> %s, %d\n",
self->serial,
value_str(VAL_PROPS, property),
value_str(VAL_STATUS, status), (int)bool_value);
if (PyErr_Occurred())
return NULL;
return Py_BuildValue("ii", status, bool_value);
case OPTION_INT:
/* PyErr_Clear(); */
SY_CONN_BEGIN_THREADS(self);
status = ct_con_props(self->conn, CS_GET, property,
&int_value, CS_UNUSED, NULL);
SY_CONN_END_THREADS(self);
if (self->debug) {
#ifdef CS_LOGIN_STATUS
if (property == CS_CON_STATUS || property == CS_LOGIN_STATUS)
#else
if (property == CS_CON_STATUS)
#endif
debug_msg("ct_con_props(conn%d, CS_GET, %s, &value,"
" CS_UNUSED, NULL) -> %s, %s\n",
self->serial,
value_str(VAL_PROPS, property),
value_str(VAL_STATUS, status),
mask_str(VAL_CONSTAT, (int)int_value));
else
debug_msg("ct_con_props(conn%d, CS_GET, %s, &value,"
" CS_UNUSED, NULL) -> %s, %d\n",
self->serial,
value_str(VAL_PROPS, property),
value_str(VAL_STATUS, status), (int)int_value);
}
if (PyErr_Occurred())
return NULL;
return Py_BuildValue("ii", status, int_value);
case OPTION_STRING:
/* PyErr_Clear(); */
SY_CONN_BEGIN_THREADS(self);
status = ct_con_props(self->conn, CS_GET, property,
str_buff, sizeof(str_buff), &buff_len);
SY_CONN_END_THREADS(self);
if (buff_len > sizeof(str_buff))
buff_len = sizeof(str_buff);
if (self->debug)
debug_msg("ct_con_props(conn%d, CS_GET, %s, buff, %d, &outlen)"
" -> %s, '%.*s'\n",
self->serial,
value_str(VAL_PROPS, property), sizeof(str_buff),
value_str(VAL_STATUS, status), (int)buff_len, str_buff);
if (PyErr_Occurred())
return NULL;
return Py_BuildValue("is", status, str_buff);
case OPTION_CMD:
PyErr_SetString(PyExc_TypeError, "EED not supported yet");
return NULL;
case OPTION_LOCALE:
PyErr_SetString(PyExc_TypeError, "LOCALE not supported yet");
return NULL;
case OPTION_UNKNOWN:
PyErr_SetString(PyExc_TypeError, "unknown property value");
return NULL;
default:
PyErr_SetString(PyExc_TypeError, "unhandled property value");
return NULL;
}
break;
#ifdef CS_CLEAR
case CS_CLEAR:
/* ct_con_props(CS_CLEAR, property) -> status */
if (!PyArg_ParseTuple(args, "ii", &action, &property))
return NULL;
/* PyErr_Clear(); */
SY_CONN_BEGIN_THREADS(self);
status = ct_con_props(self->conn, CS_CLEAR, property,
NULL, CS_UNUSED, NULL);
SY_CONN_END_THREADS(self);
if (self->debug)
debug_msg("ct_con_props(conn%d, CS_CLEAR, %s, NULL, CS_UNUSED,"
" NULL) -> %s\n",
self->serial,
value_str(VAL_PROPS, property),
value_str(VAL_STATUS, status));
if (PyErr_Occurred())
return NULL;
return PyInt_FromLong(status);
#endif
default:
PyErr_SetString(PyExc_TypeError, "unknown action");
return NULL;
}
}
static int option_type(int option)
{
switch (option) {
#ifdef CS_OPT_ANSINULL
case CS_OPT_ANSINULL:
#endif
#ifdef CS_OPT_ANSIPERM
case CS_OPT_ANSIPERM:
#endif
#ifdef CS_OPT_ARITHABORT
case CS_OPT_ARITHABORT:
#endif
#ifdef CS_OPT_ARITHIGNORE
case CS_OPT_ARITHIGNORE:
#endif
#ifdef CS_OPT_CHAINXACTS
case CS_OPT_CHAINXACTS:
#endif
#ifdef CS_OPT_CURCLOSEONXACT
case CS_OPT_CURCLOSEONXACT:
#endif
#ifdef CS_OPT_FIPSFLAG
case CS_OPT_FIPSFLAG:
#endif
#ifdef CS_OPT_FORCEPLAN
case CS_OPT_FORCEPLAN:
#endif
#ifdef CS_OPT_FORMATONLY
case CS_OPT_FORMATONLY:
#endif
#ifdef CS_OPT_GETDATA
case CS_OPT_GETDATA:
#endif
#ifdef CS_OPT_NOCOUNT
case CS_OPT_NOCOUNT:
#endif
#ifdef CS_OPT_NOEXEC
case CS_OPT_NOEXEC:
#endif
#ifdef CS_OPT_PARSEONLY
case CS_OPT_PARSEONLY:
#endif
#ifdef CS_OPT_QUOTED_IDENT
case CS_OPT_QUOTED_IDENT:
#endif
#ifdef CS_OPT_RESTREES
case CS_OPT_RESTREES:
#endif
#ifdef CS_OPT_SHOWPLAN
case CS_OPT_SHOWPLAN:
#endif
#ifdef CS_OPT_STATS_IO
case CS_OPT_STATS_IO:
#endif
#ifdef CS_OPT_STATS_TIME
case CS_OPT_STATS_TIME:
#endif
#ifdef CS_OPT_STR_RTRUNC
case CS_OPT_STR_RTRUNC:
#endif
#ifdef CS_OPT_TRUNCIGNORE
case CS_OPT_TRUNCIGNORE:
#endif
return OPTION_BOOL;
#ifdef CS_OPT_DATEFIRST
case CS_OPT_DATEFIRST:
#endif
#ifdef CS_OPT_DATEFORMAT
case CS_OPT_DATEFORMAT:
#endif
#ifdef CS_OPT_ISOLATION
case CS_OPT_ISOLATION:
#endif
#ifdef CS_OPT_ROWCOUNT
case CS_OPT_ROWCOUNT:
#endif
#ifdef CS_OPT_TEXTSIZE
case CS_OPT_TEXTSIZE:
#endif
return OPTION_INT;
#ifdef CS_OPT_AUTHOFF
case CS_OPT_AUTHOFF:
#endif
#ifdef CS_OPT_AUTHON
case CS_OPT_AUTHON:
#endif
#ifdef CS_OPT_CURREAD
case CS_OPT_CURREAD:
#endif
#ifdef CS_OPT_CURWRITE
case CS_OPT_CURWRITE:
#endif
#ifdef CS_OPT_IDENTITYOFF
case CS_OPT_IDENTITYOFF:
#endif
#ifdef CS_OPT_IDENTITYON
case CS_OPT_IDENTITYON:
#endif
return OPTION_STRING;
default:
return OPTION_UNKNOWN;
}
}
static char CS_CONNECTION_ct_options__doc__[] =
"ct_options(CS_SET, option, value) -> status\n"
"ct_options(CS_GET, option) -> status, value\n"
#ifdef CS_CLEAR
"ct_options(CS_CLEAR, option) -> status\n"
#endif
;
static PyObject *CS_CONNECTION_ct_options(CS_CONNECTIONObj *self, PyObject *args)
{
int action, option;
PyObject *obj = NULL;
CS_RETCODE status;
CS_INT int_value;
CS_BOOL bool_value;
char *str_value;
char str_buff[10240];
CS_INT buff_len;
if (!first_tuple_int(args, &action))
return NULL;
if (self->conn == NULL) {
PyErr_SetString(PyExc_TypeError, "CS_CONNECTION has been dropped");
return NULL;
}
switch (action) {
case CS_SET: