-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathckntap.c
5758 lines (5231 loc) · 187 KB
/
ckntap.c
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
/* C K N T A P -- Kermit Telephony interface for MS Win32 TAPI systems */
/*
Author: Jeffrey E Altman (jaltman@secure-endpoints.com),
Secure Endpoints Inc., New York City.
Copyright (C) 1985, 2004, Trustees of Columbia University in the City of New
York.
*/
/*
* =============================#includes=====================================
*/
#include "ckcdeb.h" /* Typedefs, debug formats, etc */
#include "ckcker.h" /* Kermit definitions */
#include "ckucmd.h"
#include "ckuusr.h"
#include "ckowin.h"
#include <string.h>
#include <windows.h>
#define TAPI_CURRENT_VERSION 0x00010004
#include <tapi.h>
#include <mcx.h>
/* all functions in this module return TRUE to indicate success */
/* or FALSE to indicate failure */
#include "ckntap.h" /* Kermit Telephony */
#include "cknwin.h"
#ifdef CK_TAPI
_PROTOTYP( char * cktapiErrorString, (DWORD));
extern int tttapi ; /* is Line TAPI ? */
extern struct keytab * tapilinetab, * tapilocationtab ;
extern int ntapiline, ntapilocation ;
extern long speed;
extern int parity, flow;
#ifndef NODIAL
extern int dialdpy;
extern int
dialidt, /* DIAL IGNORE-DIAL-TONE */
dialec, /* DIAL ERROR-CORRECTION */
dialdc, /* DIAL COMPRESSION */
dialfc, /* DIAL FLOW-CONTROL */
dialmth, /* DIAL METHOD */
dialmauto, /* DIAL METHOD AUTO */
mdmspd, /* SPEED-MATCHING */
mdmspk, /* SPEAKER ON/OFF */
mdmvol; /* SPEAKER VOLUME */
extern int waitct; /* DIAL TIMEOUT */
extern MDMINF *modemp[];
extern MDMINF GENERIC;
#else /* NODIAL */
int dialdpy = 0;
int waitct = 254;
#endif /* NODIAL */
HINSTANCE hLib = NULL ;
extern HINSTANCE hInstance ;
extern HWND hwndConsole ;
extern char * termessage ;
#ifndef NODIAL
/* Failure codes from ckudia.c */
extern int fail_code;
#define F_TIME 1 /* timeout */
#define F_INT 2 /* interrupt */
#define F_MODEM 3 /* modem-detected failure */
#define F_MINIT 4 /* cannot initialize modem */
#endif /* NODIAL */
int tapiopen = 0;
int tapipass = CK_ON ; /* TAPI Passthrough mode */
int tapiconv = CK_AUTO ; /* TAPI Conversion mode */
int tapilights = TRUE;
int tapipreterm = FALSE;
int tapipostterm = FALSE;
int tapimanual = FALSE;
int tapiinactivity = 0;
int tapibong = 8;
int tapiusecfg = CK_OFF;
/* TAPI Location Information */
char tapiloc[257] = "" ;
int tapilocid = -1 ;
DWORD tapiCountryID = -1 ;
char tapiAreaCode[65] = "" ;
DWORD tapiPreferredCardID=MAXDWORD;
DWORD tapiCountryCode=0;
char tapiLocalAccessCode[65] = "" ;
char tapiLongDistAccessCode[65] = "";
char tapiTollPrefixList[4097]="";
DWORD tapiOptions=0;
char tapiCancelCallWaiting[65] = "";
char tapiCountryName[65] = "";
char tapiSameAreaRule[65] = "";
char tapiLongDistanceRule[65] = "";
char tapiInternationalRule[65] = "";
LONG (WINAPI *cklineInitialize)(LPHLINEAPP, HINSTANCE, LINECALLBACK, LPCSTR, LPDWORD ) = NULL ;
LONG (WINAPI *cklineNegotiateAPIVersion)(HLINEAPP, DWORD, DWORD, DWORD, LPDWORD, LPLINEEXTENSIONID) = NULL ;
LONG (WINAPI *cklineGetDevCaps)(HLINEAPP, DWORD, DWORD, DWORD, LPLINEDEVCAPS) = NULL ;
LONG (WINAPI *cklineShutdown)(HLINEAPP) = NULL ;
LONG (WINAPI *cklineOpen)(HLINEAPP, DWORD, LPHLINE, DWORD, DWORD, DWORD, DWORD, DWORD,
LPLINECALLPARAMS) = NULL ;
LONG (WINAPI *cklineMakeCall)(HLINE hLine, LPHCALL lphCall, LPCSTR lpszDestAddress,
DWORD dwCountryCode, LPLINECALLPARAMS const lpCallParams) = NULL ;
LONG (WINAPI *cklineDial)(HCALL hCall, LPCSTR lpszDestAddress, DWORD dwCountryCode) = NULL ;
LONG (WINAPI *cklineDrop)(HCALL hCall, LPCSTR lpsUserUserInfo, DWORD dwSize) = NULL ;
LONG (WINAPI *cklineAnswer)(HCALL hCall, LPCSTR lpsUserUserInfo, DWORD dwSize) = NULL ;
LONG (WINAPI *cklineAccept)(HCALL hCall, LPCSTR lpsUserUserInfo, DWORD dwSize) = NULL ;
LONG (WINAPI *cklineDeallocateCall)(HCALL hCall) = NULL ;
LONG (WINAPI *cklineSetCallPrivilege)(HCALL,DWORD) = NULL ;
LONG (WINAPI *cklineClose)(HLINE hLine) = NULL ;
LONG (WINAPI *cklineHandoff)(HCALL,LPCSTR,DWORD) = NULL ;
LONG (WINAPI *cklineGetID)(HLINE hLine, DWORD dwAddressID, HCALL hCall,
DWORD dwSelect, LPVARSTRING lpDeviceID, LPCSTR lpszDeviceClass) = NULL ;
LONG (WINAPI *cklineGetTranslateCaps)( HLINEAPP hLineApp, DWORD,
LPLINETRANSLATECAPS lpLineTranslateCaps) = NULL ;
LONG (WINAPI *cklineSetCurrentLocation)( HLINEAPP hLineApp, DWORD dwLocationID ) = NULL ;
LONG (WINAPI *cklineSetStatusMessages)( HLINE hLine, DWORD dwLineStates,
DWORD dwAddressStates ) = NULL ;
LONG (WINAPI *cklineConfigDialog)( DWORD dwLine, HWND hwin, LPCSTR lpszTypes ) = NULL ;
LONG (WINAPI *cklineTranslateDialog)( HLINEAPP hTAPI, DWORD dwLine, DWORD dwVersionToUse,
HWND hwndOwner, LPCSTR lpszAddressIn ) = NULL ;
LONG (WINAPI *cklineTranslateAddress)( HLINEAPP hTAPI, DWORD dwLine, DWORD dwVersionToUse,
LPCSTR lpszAddressIn, DWORD dwCard,
DWORD dwTranslateOptions,
LPLINETRANSLATEOUTPUT lpTranslateOutput) = NULL ;
LONG (WINAPI *cklineGetCountry)( DWORD, DWORD, LPLINECOUNTRYLIST ) = NULL;
LONG (WINAPI *cklineGetDevConfig)(DWORD, LPVARSTRING, LPCSTR) = NULL;
LONG (WINAPI *cklineGetLineDevStatus)(HLINE hLine,LPLINEDEVSTATUS lpLineDevStatus)=NULL;
LONG (WINAPI *cklineSetDevConfig)(DWORD,LPVOID const,DWORD,LPCSTR)=NULL;
LONG (WINAPI *cklineGetCallInfo)(HCALL, LPLINECALLINFO)=NULL;
LONG (WINAPI *cklineMonitorMedia)(HCALL,DWORD)=NULL;
LONG (WINAPI *cklineGetAppPriority)(LPCSTR,DWORD,LPLINEEXTENSIONID,
DWORD,LPVARSTRING,LPDWORD)=NULL;
LONG (WINAPI *cklineSetAppPriority)(LPCSTR,DWORD,LPLINEEXTENSIONID,
DWORD,LPCSTR,DWORD)=NULL;
LONG (WINAPI *cklineGetNumRings)(HLINE,DWORD,LPDWORD)=NULL;
LONG (WINAPI *cklineSetNumRings)(HLINE,DWORD,DWORD)=NULL;
LONG (WINAPI *cklineSetCallParams)(HCALL,DWORD,DWORD,DWORD,LPLINEDIALPARAMS)=NULL;
int
cktapiunload(void)
{
debug(F100,"Closing TAPI Semaphores","",0);
CloseTAPIInitSem();
CloseTAPIConnectSem();
CloseTAPIAnswerSem();
debug(F100,"Freeing the TAPI Library","",0);
FreeLibrary( hLib ) ;
hLib = NULL ;
cklineInitialize = NULL ;
debug(F100,"TAPI unload complete","",0);
return TRUE ;
}
int cktapiload(void)
{
DWORD rc = 0 ;
hLib = LoadLibrary("tapi32") ;
if ( !hLib )
{
rc = GetLastError() ;
debug(F111, "cktapiload LoadLibrary failed","tapi32",rc) ;
return FALSE;
}
if (((FARPROC) cklineInitialize = GetProcAddress( hLib, "lineInitialize" )) == NULL )
{
rc = GetLastError() ;
debug(F111, "cktapiload LoadLibrary failed","tapi32",rc) ;
return FALSE;
}
if (((FARPROC) cklineNegotiateAPIVersion = GetProcAddress( hLib, "lineNegotiateAPIVersion" )) == NULL )
{
rc = GetLastError() ;
debug(F111, "cktapiload LoadLibrary failed","tapi32",rc) ;
return FALSE;
}
if (((FARPROC) cklineGetDevCaps = GetProcAddress( hLib, "lineGetDevCaps" )) == NULL )
{
rc = GetLastError() ;
debug(F111, "cktapiload LoadLibrary failed","tapi32",rc) ;
return FALSE;
}
if (((FARPROC) cklineShutdown = GetProcAddress( hLib, "lineShutdown" )) == NULL )
{
rc = GetLastError() ;
debug(F111, "cktapiload LoadLibrary failed","tapi32",rc) ;
return FALSE;
}
if (((FARPROC) cklineOpen = GetProcAddress( hLib, "lineOpen" )) == NULL )
{
rc = GetLastError() ;
debug(F111, "cktapiload LoadLibrary failed","tapi32",rc) ;
return FALSE;
}
if (((FARPROC) cklineMakeCall = GetProcAddress( hLib, "lineMakeCall" )) == NULL )
{
rc = GetLastError() ;
debug(F111, "cktapiload LoadLibrary failed","tapi32",rc) ;
return FALSE;
}
if (((FARPROC) cklineDial = GetProcAddress( hLib, "lineDial" )) == NULL )
{
rc = GetLastError() ;
debug(F111, "cktapiload LoadLibrary failed","tapi32",rc) ;
return FALSE;
}
if (((FARPROC) cklineDrop = GetProcAddress( hLib, "lineDrop" )) == NULL )
{
rc = GetLastError() ;
debug(F111, "cktapiload LoadLibrary failed","tapi32",rc) ;
return FALSE;
}
if (((FARPROC) cklineAnswer = GetProcAddress( hLib, "lineAnswer" )) == NULL )
{
rc = GetLastError() ;
debug(F111, "cktapiload LoadLibrary failed","tapi32",rc) ;
return FALSE;
}
if (((FARPROC) cklineAccept = GetProcAddress( hLib, "lineAccept" )) == NULL )
{
rc = GetLastError() ;
debug(F111, "cktapiload LoadLibrary failed","tapi32",rc) ;
return FALSE;
}
if (((FARPROC) cklineDeallocateCall = GetProcAddress( hLib, "lineDeallocateCall" )) == NULL )
{
rc = GetLastError() ;
debug(F111, "cktapiload LoadLibrary failed","tapi32",rc) ;
return FALSE;
}
if (((FARPROC) cklineClose = GetProcAddress( hLib, "lineClose" )) == NULL )
{
rc = GetLastError() ;
debug(F111, "cktapiload LoadLibrary failed","tapi32",rc) ;
return FALSE;
}
if (((FARPROC) cklineGetID = GetProcAddress( hLib, "lineGetID" )) == NULL )
{
rc = GetLastError() ;
debug(F111, "cktapiload LoadLibrary failed","tapi32",rc) ;
return FALSE;
}
if (((FARPROC) cklineGetTranslateCaps = GetProcAddress( hLib, "lineGetTranslateCaps" )) == NULL )
{
rc = GetLastError() ;
debug(F111, "cktapiload LoadLibrary failed","tapi32",rc) ;
return FALSE;
}
if (((FARPROC) cklineSetCurrentLocation = GetProcAddress( hLib, "lineSetCurrentLocation" )) == NULL )
{
rc = GetLastError() ;
debug(F111, "cktapiload LoadLibrary failed","tapi32",rc) ;
return FALSE;
}
if (((FARPROC) cklineSetStatusMessages = GetProcAddress( hLib, "lineSetStatusMessages" )) == NULL )
{
rc = GetLastError() ;
debug(F111, "cktapiload LoadLibrary failed","tapi32",rc) ;
return FALSE;
}
if (((FARPROC) cklineConfigDialog = GetProcAddress( hLib, "lineConfigDialog" )) == NULL )
{
rc = GetLastError() ;
debug(F111, "cktapiload LoadLibrary failed","tapi32",rc) ;
return FALSE;
}
if (((FARPROC) cklineTranslateDialog = GetProcAddress( hLib, "lineTranslateDialog" )) == NULL )
{
rc = GetLastError() ;
debug(F111, "cktapiload LoadLibrary failed","tapi32",rc) ;
return FALSE;
}
if (((FARPROC) cklineTranslateAddress =
GetProcAddress( hLib, "lineTranslateAddress" )) == NULL )
{
rc = GetLastError() ;
debug(F111, "cktapiload LoadLibrary failed","tapi32",rc) ;
return FALSE;
}
if (((FARPROC) cklineGetCountry =
GetProcAddress( hLib, "lineGetCountry" )) == NULL )
{
rc = GetLastError() ;
debug(F111, "cktapiload LoadLibrary failed","tapi32",rc) ;
return FALSE;
}
if (((FARPROC) cklineGetLineDevStatus =
GetProcAddress( hLib, "lineGetLineDevStatus" )) == NULL )
{
rc = GetLastError() ;
debug(F111, "cktapiload LoadLibrary failed","tapi32",rc) ;
return FALSE;
}
if (((FARPROC) cklineGetDevConfig =
GetProcAddress( hLib, "lineGetDevConfig" )) == NULL )
{
rc = GetLastError() ;
debug(F111, "cktapiload LoadLibrary failed","tapi32",rc) ;
return FALSE;
}
if (((FARPROC) cklineSetDevConfig =
GetProcAddress( hLib, "lineSetDevConfig" )) == NULL )
{
rc = GetLastError() ;
debug(F111, "cktapiload LoadLibrary failed","tapi32",rc) ;
return FALSE;
}
if (((FARPROC) cklineHandoff =
GetProcAddress( hLib, "lineHandoff" )) == NULL )
{
rc = GetLastError() ;
debug(F111, "cktapiload LoadLibrary failed","tapi32",rc) ;
return FALSE;
}
if (((FARPROC) cklineSetCallPrivilege =
GetProcAddress( hLib, "lineSetCallPrivilege" )) == NULL )
{
rc = GetLastError() ;
debug(F111, "cktapiload LoadLibrary failed","tapi32",rc) ;
return FALSE;
}
if (((FARPROC) cklineGetCallInfo =
GetProcAddress( hLib, "lineGetCallInfo" )) == NULL )
{
rc = GetLastError() ;
debug(F111, "cktapiload LoadLibrary failed","tapi32",rc) ;
return FALSE;
}
if (((FARPROC) cklineMonitorMedia =
GetProcAddress( hLib, "lineMonitorMedia" )) == NULL )
{
rc = GetLastError() ;
debug(F111, "cktapiload LoadLibrary failed","tapi32",rc) ;
return FALSE;
}
if (((FARPROC) cklineGetAppPriority =
GetProcAddress( hLib, "lineGetAppPriority" )) == NULL )
{
rc = GetLastError() ;
debug(F111, "cktapiload LoadLibrary failed","tapi32",rc) ;
return FALSE;
}
if (((FARPROC) cklineSetAppPriority =
GetProcAddress( hLib, "lineSetAppPriority" )) == NULL )
{
rc = GetLastError() ;
debug(F111, "cktapiload LoadLibrary failed","tapi32",rc) ;
return FALSE;
}
if (((FARPROC) cklineGetNumRings =
GetProcAddress( hLib, "lineGetNumRings" )) == NULL )
{
rc = GetLastError() ;
debug(F111, "cktapiload LoadLibrary failed","tapi32",rc) ;
return FALSE;
}
if (((FARPROC) cklineSetNumRings =
GetProcAddress( hLib, "lineSetNumRings" )) == NULL )
{
rc = GetLastError() ;
debug(F111, "cktapiload LoadLibrary failed","tapi32",rc) ;
return FALSE;
}
if (((FARPROC) cklineSetCallParams =
GetProcAddress( hLib, "lineSetCallParams" )) == NULL )
{
rc = GetLastError() ;
debug(F111, "cktapiload LoadLibrary failed","tapi32",rc) ;
return FALSE;
}
CreateTAPIInitSem( FALSE );
CreateTAPIConnectSem( FALSE );
CreateTAPIAnswerSem( FALSE );
return TRUE;
}
// Global TAPI variables.
HWND g_hWndMainWindow = NULL; // Apps main window.
HWND g_hDlgParentWindow = NULL; // This will be the parent of all dialogs.
HLINEAPP g_hLineApp = (HLINEAPP) 0;
DWORD g_dwNumDevs = -1;
DWORD g_DataDevices = 0 ;
#define MAXDEVS 64
LPLINEDEVCAPS g_lpLineDevCaps[64] ;
extern HINSTANCE hInst ;
// Global variable that holds the handle to a TAPI dialog
// that needs to be dismissed if line conditions change.
HWND g_hDialog = NULL;
// Global flags to prevent re-entrancy problems.
BOOL g_bShuttingDown = FALSE;
BOOL g_bStoppingCall = FALSE;
BOOL g_bInitializing = FALSE;
// This sample only supports one call in progress at a time.
BOOL g_bTapiInUse = FALSE;
// Data needed per call. This sample only supports one call.
HCALL g_hCall = (HCALL) 0;
HLINE g_hLine = (HLINE) 0;
extern int ttyfd ; /* this holds the HLINE hLine */
extern int mdmtyp ;
static int mdmtyp_sav=0;
CHAR szModemName[256] ;
DWORD LineDeviceId = -1;
DWORD LineDeviceAPIVersion = 0 ;
DWORD LineAddressCount = 0 ;
DWORD LineMediaModes = 0 ;
DWORD g_dwAPIVersion = 0;
DWORD g_dwCallState = 0;
BOOL g_bConnected = FALSE;
// Global variables to allow us to do various waits.
BOOL g_bReplyReceived=FALSE;
DWORD g_dwRequestedID=0;
long g_lAsyncReply=SUCCESS;
BOOL g_bCallStateReceived=FALSE;
BOOL g_bAnswering = FALSE;
BOOL g_bDialing = FALSE;
BOOL g_bHangingUp = FALSE;
BOOL g_bClosing = FALSE;
int
cktapiinit(void)
{
int i = 0 ;
// This will be the parent of all dialogs.
g_hWndMainWindow = g_hDlgParentWindow = hwndConsole;
for ( i=0 ; i < MAXDEVS ; i++ )
g_lpLineDevCaps[i] = NULL ;
if ( cktapiload() )
{
if (cktapiopen())
{
debug(F100,"TAPI open successful","",0);
g_DataDevices = cktapidevenum() ;
cktapiclose() ;
return TRUE ;
}
else
{
debug(F100,"TAPI open failed","",0);
}
}
return FALSE;
}
void
OutputDebugLastError( DWORD x, char * string )
{
char buf[1024];
sprintf(buf,"%s %s",string,cktapiErrorString(x));
debug(F111,"TAPI LastError",buf,x);
#ifdef BETADEBUG
printf("TAPI LastError %s=%x\n",string,x);
#endif
}
void
HandleNoMem( )
{
debug(F100,"TAPI Out of Memory","",0);
}
//
// FUNCTION: LPVOID CheckAndReAllocBuffer(LPVOID, size_t, LPCSTR)
//
// PURPOSE: Checks and ReAllocates a buffer if necessary.
//
// PARAMETERS:
// lpBuffer - Pointer to buffer to be checked. Can be NULL.
// sizeBufferMinimum - Minimum size that lpBuffer should be.
// szApiPhrase - Phrase to print if an error occurs.
//
// RETURN VALUE:
// Returns a pointer to a valid buffer that is guarenteed to be
// at least sizeBufferMinimum size.
// Returns NULL if an error occured.
//
// COMMENTS:
//
// This function is a helper function intended to make all of the
// line API Wrapper Functions much simplier. It allocates (or
// reallocates) a buffer of the requested size.
//
// The returned pointer has been allocated with LocalAlloc,
// so LocalFree has to be called on it when you're finished with it,
// or there will be a memory leak.
//
// Similarly, if a pointer is passed in, it *must* have been allocated
// with LocalAlloc and it could potentially be LocalFree()d.
//
// If lpBuffer == NULL, then a new buffer is allocated. It is
// normal to pass in NULL for this parameter the first time and only
// pass in a pointer if the buffer needs to be reallocated.
//
// szApiPhrase is used only for debugging purposes.
//
// It is assumed that the buffer returned from this function will be used
// to contain a variable sized structure. Thus, the dwTotalSize field
// is always filled in before returning the pointer.
//
//
LPVOID
CheckAndReAllocBuffer(LPVOID lpBuffer, size_t sizeBufferMinimum,
LPCSTR szApiPhrase)
{
size_t sizeBuffer;
debug(F110,"CheckAndReAllocBuffer",szApiPhrase,0);
debug(F111,"CheckAndReAllocBuffer","lpBuffer",lpBuffer);
debug(F111,"CheckAndReAllocBuffer","sizeBufferMinimum",sizeBufferMinimum);
if (lpBuffer == NULL) // Allocate the buffer if necessary.
{
sizeBuffer = sizeBufferMinimum;
lpBuffer = (LPVOID) LocalAlloc(LPTR, sizeBuffer);
if (lpBuffer == NULL)
{
HandleNoMem();
return NULL;
}
}
else // If the structure already exists, make sure its good.
{
sizeBuffer = LocalSize((HLOCAL) lpBuffer);
if (sizeBuffer == 0) // Bad pointer?
{
return NULL;
}
// Was the buffer big enough for the structure?
if (sizeBuffer < sizeBufferMinimum)
{
LocalFree(lpBuffer);
return CheckAndReAllocBuffer(NULL, sizeBufferMinimum, szApiPhrase);
}
// Lets zero the buffer out.
memset(lpBuffer, 0, sizeBuffer);
}
((LPVARSTRING) lpBuffer ) -> dwTotalSize = (DWORD) sizeBuffer;
return lpBuffer;
}
char *
cktapiErrorString(DWORD error)
{
char * estr = NULL;
switch ( error ) {
case 0:
estr = "Success";
break;
case LINEERR_ALLOCATED:
estr = "Line already allocated";
break;
case LINEERR_BADDEVICEID:
estr = "Bad device ID";
break;
case LINEERR_BEARERMODEUNAVAIL:
estr = "Requested Bearer Mode Unavailable";
break;
case LINEERR_CALLUNAVAIL:
estr = "Unable to place call on current device";
break;
case LINEERR_COMPLETIONOVERRUN :
estr = "Completion Overrun";
break;
case LINEERR_CONFERENCEFULL :
estr = "Conference Full";
break;
case LINEERR_DIALBILLING :
estr = "Dial Billing error";
break;
case LINEERR_DIALDIALTONE :
estr = "Wait for Dial Tone not supported";
break;
case LINEERR_DIALPROMPT :
estr = "Wait for Dial Prompt not supported";
break;
case LINEERR_DIALQUIET :
estr = "Wait for Quiet not supported";
break;
case LINEERR_INCOMPATIBLEAPIVERSION :
estr = "Incompatible TAPI Version";
break;
case LINEERR_INCOMPATIBLEEXTVERSION :
estr = "Incompatible Extension Version";
break;
case LINEERR_INIFILECORRUPT :
estr = "TELEPHON.INI file corrupt";
break;
case LINEERR_INUSE :
estr = "Line in use";
break;
case LINEERR_INVALADDRESS :
estr = "Invalid Line Address";
break;
case LINEERR_INVALADDRESSID :
estr = "Invalid Line Address ID";
break;
case LINEERR_INVALADDRESSMODE :
estr = "Invalid Line Address Mode";
break;
case LINEERR_INVALADDRESSSTATE :
estr = "Invalid Line Address State";
break;
case LINEERR_INVALAPPHANDLE :
estr = "Invalid Application Handle";
break;
case LINEERR_INVALAPPNAME :
estr = "Invalid Application Name";
break;
case LINEERR_INVALBEARERMODE :
estr = "Invalid Bearer Mode";
break;
case LINEERR_INVALCALLCOMPLMODE :
estr = "Invalid Call Completion Mode";
break;
case LINEERR_INVALCALLHANDLE :
estr = "Invalid Call Handle";
break;
case LINEERR_INVALCALLPARAMS :
estr = "Invalid Call Parameters";
break;
case LINEERR_INVALCALLPRIVILEGE :
estr = "Invalid Call Privilege";
break;
case LINEERR_INVALCALLSELECT :
estr = "Invalid Call Selection";
break;
case LINEERR_INVALCALLSTATE :
estr = "Invalid Call State";
break;
case LINEERR_INVALCALLSTATELIST :
estr = "Invalid Call State List";
break;
case LINEERR_INVALCARD :
estr = "Invalid Card";
break;
case LINEERR_INVALCOMPLETIONID :
estr = "Invalid Completion ID";
break;
case LINEERR_INVALCONFCALLHANDLE :
estr = "Invalid Conference Call Handle";
break;
case LINEERR_INVALCONSULTCALLHANDLE :
estr = "Invalid Consulation Call Handle";
break;
case LINEERR_INVALCOUNTRYCODE :
estr = "Invalid Country Code";
break;
case LINEERR_INVALDEVICECLASS :
estr = "Invalid Device Class";
break;
case LINEERR_INVALDEVICEHANDLE :
estr = "Invalid Device Handle";
break;
case LINEERR_INVALDIALPARAMS :
estr = "Invalid Dial Parameters";
break;
case LINEERR_INVALDIGITLIST :
estr = "Invalid Digit List";
break;
case LINEERR_INVALDIGITMODE :
estr = "Invalid Digit Mode";
break;
case LINEERR_INVALDIGITS :
estr = "Invalid Digits";
break;
case LINEERR_INVALEXTVERSION :
estr = "Invalid Extension Version";
break;
case LINEERR_INVALGROUPID :
estr = "Invalid Group ID";
break;
case LINEERR_INVALLINEHANDLE :
estr = "Invalid Line Handle";
break;
case LINEERR_INVALLINESTATE :
estr = "Invalid Line State";
break;
case LINEERR_INVALLOCATION :
estr = "Invalid Location";
break;
case LINEERR_INVALMEDIALIST :
estr = "Invalid Media List";
break;
case LINEERR_INVALMEDIAMODE :
estr = "Invalid Media Mode";
break;
case LINEERR_INVALMESSAGEID :
estr = "Invalid Message ID";
break;
case LINEERR_INVALPARAM :
estr = "Invalid Parameter";
break;
case LINEERR_INVALPARKID :
estr = "Invalid Park ID";
break;
case LINEERR_INVALPARKMODE :
estr = "Invaldi Park Mode";
break;
case LINEERR_INVALPOINTER :
estr = "Invalid Pointer";
break;
case LINEERR_INVALPRIVSELECT :
estr = "Invalid Privilege Select";
break;
case LINEERR_INVALRATE :
estr = "Invalid Rate";
break;
case LINEERR_INVALREQUESTMODE :
estr = "Invalid Request Mode";
break;
case LINEERR_INVALTERMINALID :
estr = "Invalid Terminal ID";
break;
case LINEERR_INVALTERMINALMODE :
estr = "Invalid Terminal Mode";
break;
case LINEERR_INVALTIMEOUT :
estr = "Invalid Timeout";
break;
case LINEERR_INVALTONE :
estr = "Invalid Tone";
break;
case LINEERR_INVALTONELIST :
estr = "Invalid Tone List";
break;
case LINEERR_INVALTONEMODE :
estr = "Invalid Tone Mode";
break;
case LINEERR_INVALTRANSFERMODE :
estr = "Invalid Transfer Mode";
break;
case LINEERR_LINEMAPPERFAILED :
estr = "Line Mapper Failed";
break;
case LINEERR_NOCONFERENCE :
estr = "No Conference available";
break;
case LINEERR_NODEVICE :
estr = "No Device available";
break;
case LINEERR_NODRIVER :
estr = "No Driver available";
break;
case LINEERR_NOMEM :
estr = "No memory available";
break;
case LINEERR_NOREQUEST :
estr = "No Request";
break;
case LINEERR_NOTOWNER :
estr = "Not owner";
break;
case LINEERR_NOTREGISTERED :
estr = "Not Registered";
break;
case LINEERR_OPERATIONFAILED :
estr = "Operation Failed";
break;
case LINEERR_OPERATIONUNAVAIL :
estr = "Operation Unavailable";
break;
case LINEERR_RATEUNAVAIL :
estr = "Rate Unavailable";
break;
case LINEERR_RESOURCEUNAVAIL :
estr = "Resource Unavailable";
break;
case LINEERR_REQUESTOVERRUN :
estr = "Request Overrun";
break;
case LINEERR_STRUCTURETOOSMALL :
estr = "Structure Too Small";
break;
case LINEERR_TARGETNOTFOUND :
estr = "Target Not Found";
break;
case LINEERR_TARGETSELF :
estr = "Target Self";
break;
case LINEERR_UNINITIALIZED :
estr = "TAPI Unititialized";
break;
case LINEERR_USERUSERINFOTOOBIG :
estr = "User Info Too Big";
break;
case LINEERR_REINIT :
estr = "TAPI Reinitialization Required";
break;
case LINEERR_ADDRESSBLOCKED :
estr = "Address Blocked";
break;
case LINEERR_BILLINGREJECTED :
estr = "Billing Rejected";
break;
case LINEERR_INVALFEATURE :
estr = "Invalid Feature";
break;
case LINEERR_NOMULTIPLEINSTANCE :
estr = "Multiple Instances not supported";
break;
#ifdef COMMENT /* TAPI 2.0 */
case LINEERR_INVALAGENTID :
estr = "Invalid Agent ID";
break;
case LINEERR_INVALAGENTGROUP :
estr = "Invalid Agent Group";
break;
case LINEERR_INVALPASSWORD :
estr = "Invalid Password";
break;
case LINEERR_INVALAGENTSTATE :
estr = "Invalid Agent State";
break;
case LINEERR_INVALAGENTACTIVITY :
estr = "Invalid Agent Activity";
break;
case LINEERR_DIALVOICEDETECT :
estr = "Voice detected during dialing";
break;
#endif /* COMMENT */
default:
estr = ((LONG) error) > 0 ? "Request ID" : "Unknown TAPI error";
break;
}
return estr;
}
void
UpdateStatusBar( char * str, long param1, long param2 )
{
char buf[1024];
sprintf(buf,"%s::%d,%d",str,param1,param2);
debug(F110,"TAPI Status Message",buf,0);
if ( dialdpy )
printf( "%s\n",str ) ;
}
void
OutputDebugLineError( long param, char * str )
{
char buf[1024];
sprintf(buf,"%s %s",str,cktapiErrorString(param));
#ifdef BETADEBUG
printf("TAPI Debug Line Error: %s=%s(0x%x)\n",str,
cktapiErrorString(param),param);
#endif /* BETADEBUG */
debug(F111,"TAPI Debug Line Error",buf,param);
}
void
OutputDebugLineCallback(
DWORD dwDevice, DWORD dwMsg, DWORD dwCallbackInstance,
DWORD dwParam1, DWORD dwParam2, DWORD dwParam3)
{
char buf[1024];
sprintf(buf,"(%d,%d,%d,%d,%d,%d)",
dwDevice,dwMsg,dwCallbackInstance,
dwParam1,dwParam2,dwParam3);
debug(F110,"TAPI Line Callback",buf,0);
}
//
// FUNCTION: DoLineReply(..)
//
// PURPOSE: Handle LINE_REPLY asynchronous messages.
//
// PARAMETERS:
// dwDevice - Line Handle associated with this LINE_REPLY.
// dwMsg - Should always be LINE_REPLY.
// dwCallbackInstance - Unused by this sample.
// dwParam1 - Asynchronous request ID.
// dwParam2 - success or LINEERR error value.
// dwParam3 - Unused.
//
// RETURN VALUE:
// none
//
// COMMENTS:
//
// All line API calls that return an asynchronous request ID
// will eventually cause a LINE_REPLY message. Handle it.
//
// This sample assumes only one call at time, and that we wait
// for a LINE_REPLY before making any other line API calls.
//
// The only exception to the above is that we might shut down
// the line before receiving a LINE_REPLY.
//
//
void
DoLineReply(
DWORD dwDevice, DWORD dwMessage, DWORD dwCallbackInstance,
DWORD dwParam1, DWORD dwParam2, DWORD dwParam3)
{
debug(F111,"TAPI LINE REPLY","Requested ID",g_dwRequestedID);
debug(F111,"TAPI LINE REPLY","Message ID",dwParam1);
OutputDebugLineError((long) dwParam2, "LINE_REPLY error: ");
while ( g_dwRequestedID == 0 ) {
msleep(100);
}
// If we are currently waiting for this async Request ID
// then set the global variables to acknowledge it.
if (g_dwRequestedID == dwParam1)
{
#ifdef BETADEBUG
printf("LINE_REPLY: dwRequestedID == dwParam1\n");
#endif
g_lAsyncReply = (long) dwParam2;
g_bReplyReceived = TRUE;
}
#ifdef BETADEBUG
else {
printf("LINE_REPLY: dwRequestedID != dwParam1\n");
}
#endif
}
//
// FUNCTION: DoLineClose(..)
//
// PURPOSE: Handle LINE_CLOSE asynchronous messages.
//
// PARAMETERS:
// dwDevice - Line Handle that was closed.
// dwMsg - Should always be LINE_CLOSE.
// dwCallbackInstance - Unused by this sample.
// dwParam1 - Unused.
// dwParam2 - Unused.
// dwParam3 - Unused.
//
// RETURN VALUE:
// none
//
// COMMENTS:
//
// This message is sent when something outside our app shuts
// down a line in use.
//
// The hLine (and any hCall on this line) are no longer valid.
//
//
void
DoLineClose(
DWORD dwDevice, DWORD dwMessage, DWORD dwCallbackInstance,
DWORD dwParam1, DWORD dwParam2, DWORD dwParam3)
{
// Line has been shut down. Clean up our internal variables.
if ( (HLINE) dwDevice == g_hLine ) {
cktapicloseasync();
debug(F110,"TAPI","Line was shutdown by TAPI",0);
printf("%s was shut down.\n",szModemName);
}
}
//
// FUNCTION: DoLineCreate(..)
//
// PURPOSE: Handle LINE_LINECREATE asynchronous messages.
//
// PARAMETERS:
// dwDevice - Unused.
// dwMsg - Should always be LINE_CREATE.
// dwCallbackInstance - Unused.
// dwParam1 - dwDeviceID of new Line created.
// dwParam2 - Unused.
// dwParam3 - Unused.