-
Notifications
You must be signed in to change notification settings - Fork 1
/
HttpTapi.c
3524 lines (2987 loc) · 91.8 KB
/
HttpTapi.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
/*++
Copyright 2009-2012 IPcom GmbH
Copyright 1995 - 2000 Microsoft Corporation
Module Name: HttpTapi.c
--*/
#define _WIN32_WINNT 0x0400
// TSPI uses UNICODE (WCHAR). Other APIs (Debug, Registry, GUI) are generic (e.g. lpcTstr)
// and map to wide or ANSI dependent if UNICODE is defined or not.
// As the ATSP sample uses ANSI strings we also use ANSI, thus UNICODE will be not defined!
// Thus, we do manual WCHAR-ANSI conversion for strings exchanged with TSPI.
#ifdef UNICODE
#error UNICODE is defined, but HttpTapi supports only ANSI mode! Undefine UNICODE!
#endif
#define TAPI_CURRENT_VERSION 0x00030000
#include "HttpTapi.h"
#include "tapi_logging.h"
#include "ExportCertificates.h"
#include <curl\curl.h>
/* *** decryptLicense ***
* return values:
* 0: OK
* 1: memory allocation error
* 2: invalid number of elements
* 3: wrong license identifier
* 4: wrong license version number
* 5: bad number of lines
* 6: error parsing additional data
* 7: error in CSP acquiration
* 8: error in decryption
*/
DWORD decryptLicense(PLICENSE pLicense, char *szencryptedLicense) {
DWORD bufflen;
char *buff, *buffbackup, *next;
HCRYPTPROV hProv;
HCRYPTKEY hKey;
LOG((5,"License: decrypting license ..."));
CryptStringToBinary(
szencryptedLicense,
0,
CRYPT_STRING_BASE64,
0,
&bufflen,
0,
0);
if ( !(buff = (char *) DrvAlloc(bufflen*sizeof(BYTE) + 1)) ) {
return 1;
}
CryptStringToBinary(
szencryptedLicense,
0,
CRYPT_STRING_BASE64,
(BYTE *) buff,
&bufflen,
0,
0);
// Acquire a handle to the CSP.
if(!CryptAcquireContext(
&hProv,
NULL,
MS_ENHANCED_PROV,
PROV_RSA_FULL,
CRYPT_VERIFYCONTEXT))
{
// If the key container cannot be opened, try creating a new
// container by specifying a container name and setting the
// CRYPT_NEWKEYSET flag.
if(NTE_BAD_KEYSET == GetLastError())
{
if(!CryptAcquireContext(
&hProv,
"mytestcontainer",
MS_ENHANCED_PROV,
PROV_RSA_FULL,
CRYPT_NEWKEYSET | CRYPT_VERIFYCONTEXT))
{
LOG((1,"License: Error in AcquireContext 0x%08x",GetLastError()));
if (buff) DrvFree(buff);
return 7;
}
}
else
{
LOG((1,"License: Error in AcquireContext 0x%08x",GetLastError()));
if (buff) DrvFree(buff);
return 7;
}
}
// Use the CryptImportKey function to import the PLAINTEXTKEYBLOB
// BYTE array into the key container. The function returns a
// pointer to an HCRYPTKEY variable that contains the handle of
// the imported key.
if (!CryptImportKey(
hProv,
DesKeyBlob,
sizeof(DesKeyBlob),
0,
CRYPT_EXPORTABLE,
&hKey ) )
{
LOG((1,"License: Error 0x%08x in importing the Des key",GetLastError()));
if (buff) DrvFree(buff);
if (hProv) CryptReleaseContext(hProv, 0);
return 7;
}
if (!CryptDecrypt(
hKey, //__in HCRYPTKEY hKey,
0, //__in HCRYPTHASH hHash,
TRUE, //__in BOOL Final,
0, //__in DWORD dwFlags,
(BYTE *) buff, //__inout BYTE *pbData,
&bufflen //__inout DWORD *pdwDataLen
) )
{
LOG((1,"License: Error 0x%08x during decryption",GetLastError()));
if (buff) DrvFree(buff);
if (hProv) CryptReleaseContext(hProv, 0);
return 8;
}
if (hProv) CryptReleaseContext(hProv, 0);
// zero terminate the decrypted license (make it a string)
// not needed as the encrypted string contains \0
//*(buff+bufflen) = '\0';
// parse the decoded license string
LOG((1,"License: parsing license string: %s", buff));
buffbackup = buff;
// License Identifier
gLicense.licenseIdentifier = buff;
if ( (next=StrChr(buff,'\n')) == 0 ) {
LOG((1,"License: error parsing license identifier %s", buff));
if (buffbackup) DrvFree(buffbackup);
return 2;
}
*next = '\0';
buff = next + 1;
// verify license identifier
if ( StrCmp(gLicense.licenseIdentifier, gszHttpTapiLicenseIdentifier) ) {
LOG((1,"License: wrong license identifier. %s!=%s", gLicense.licenseIdentifier, gszHttpTapiLicenseIdentifier));
if (buffbackup) DrvFree(buffbackup);
return 3;
}
// License Version
gLicense.licenseVersion = buff;
if ( (next=StrChr(buff,'\n')) == 0 ) {
LOG((1,"License: error parsing license version %s", buff));
if (buffbackup) DrvFree(buffbackup);
return 2;
}
*next = '\0';
gLicense.iLicenseVersion = StrToInt(gLicense.licenseVersion);
buff = next + 1;
// verify license version
if (gLicense.iLicenseVersion != gszHttpTapiLicenseVersion) {
LOG((1,"License: wrong license version. %d!=%d", gLicense.iLicenseVersion, gszHttpTapiLicenseVersion));
if (buffbackup) DrvFree(buffbackup);
return 4;
}
// Name
gLicense.name = buff;
if ( (next=StrChr(buff,'\n')) == 0 ) {
LOG((1,"License: error parsing license name %s", buff));
if (buffbackup) DrvFree(buffbackup);
return 2;
}
*next = '\0';
buff = next + 1;
// Company
gLicense.company = buff;
if ( (next=StrChr(buff,'\n')) == 0 ) {
LOG((1,"License: error parsing license company %s", buff));
if (buffbackup) DrvFree(buffbackup);
return 2;
}
*next = '\0';
buff = next + 1;
// Address
gLicense.address = buff;
if ( (next=StrChr(buff,'\n')) == 0 ) {
LOG((1,"License: error parsing license address %s", buff));
if (buffbackup) DrvFree(buffbackup);
return 2;
}
*next = '\0';
buff = next + 1;
// Valid until
gLicense.validUntil = buff;
if ( (next=StrChr(buff,'\n')) == 0 ) {
LOG((1,"License: error parsing license validity %s", buff));
if (buffbackup) DrvFree(buffbackup);
return 2;
}
*next = '\0';
buff = next + 1;
// Number of lines
gLicense.numberOfLines = buff;
if ( (next=StrChr(buff,'\n')) == 0 ) {
LOG((1,"License: error parsing license number of lines %s", buff));
if (buffbackup) DrvFree(buffbackup);
return 2;
}
*next = '\0';
gLicense.iNumberOfLines = StrToInt(gLicense.numberOfLines);
buff = next + 1;
// additional data
gLicense.additionalData = buff;
if ( (next=StrChr(buff,'\n')) != 0 ) {
LOG((1,"License: error parsing additional data %s", buff));
if (buffbackup) DrvFree(buffbackup);
return 2;
}
// decryption was successfull
LOG((3,"License: successfully decrypted license!"));
LOG((3,"License: License Identifier: %s",gLicense.licenseIdentifier));
LOG((3,"License: License Version: %d",gLicense.iLicenseVersion));
LOG((3,"License: Name: %s",gLicense.name));
LOG((3,"License: Company: %s",gLicense.company));
LOG((3,"License: Address: %s",gLicense.address));
LOG((3,"License: Valid Until: %s",gLicense.validUntil));
LOG((3,"License: Number of Lines: %d",gLicense.iNumberOfLines));
LOG((3,"License: Additional Data: %s",gLicense.additionalData));
LOG((3,"License: ----------------------"));
if (gLicenseString) {
LOG((5,"freeing existing licenseString %p",gLicenseString));
DrvFree(gLicenseString);
}
gLicenseString = buffbackup;
return 0;
};
void set_gdwNumberOfLines(int dialog) {
// verify the license (load number of licensed lines)
HKEY hKey;
DWORD dwDataSize, dwDataType, ret;
char szencryptedLicense[MAX_LICENSE_LENGTH];
#ifdef SINGLELINE
gdwNumberOfLines = 1;
return;
#endif
#ifdef NOLICENSE
gdwNumberOfLines = 9999;
return;
#endif
//DebugBreak();
RegOpenKeyExA(
HKEY_LOCAL_MACHINE,
gszHttpTapiKeyFull,
0,
KEY_ALL_ACCESS,
&hKey
);
dwDataSize = MAX_LICENSE_LENGTH;
if (RegQueryValueEx(
hKey,
gszHttpTapiLicense,
0,
&dwDataType,
(LPBYTE) szencryptedLicense,
&dwDataSize
)) {
// error, no license found
LOG((1,"License: failed reading license ..."));
if (dialog) MessageBox(0,
"Could not found a license - please configure a valid license!",
"HttpTapi",
MB_OK | MB_ICONERROR | MB_SERVICE_NOTIFICATION);
gdwNumberOfLines = 0;
} else {
LOG((3,"License: decrypting license ..."));
ret = decryptLicense(&gLicense, szencryptedLicense);
LOG((3,"License: decrypting license ... done"));
if (ret) {
// error decrypting license
LOG((3,"License: invalid license ..."));
if (dialog) MessageBox(0,
"License is invalid - please configure a valid license!",
"HttpTapi",
MB_OK | MB_ICONERROR | MB_SERVICE_NOTIFICATION);
gdwNumberOfLines = 0;
} else if (strlen(gLicense.validUntil) == 0) {
// no validity date -> license does not expire
LOG((3,"License: license does not expire ..."));
gdwNumberOfLines = gLicense.iNumberOfLines;
} else {
// verify if license is still valid
SYSTEMTIME currentSystemTime, licenseSystemTime;
LOG((3,"License: verify if license is still valid ..."));
GetLocalTime(¤tSystemTime);
GetLocalTime(&licenseSystemTime); // workaround to init the structure :-)
LOG((3,"License: parsing validity date ..."));
if (sscanf_s(gLicense.validUntil,
"%04u-%02u-%02u", &licenseSystemTime.wYear,
&licenseSystemTime.wMonth, &licenseSystemTime.wDay) != 3) {
// error parsing date
LOG((3,"License: invalid license date ..."));
if (dialog) MessageBox(0, "Wrong license validity - please configure a valid license!",
"HttpTapi", MB_OK | MB_ICONERROR | MB_SERVICE_NOTIFICATION);
gdwNumberOfLines = 0;
} else {
// compare timestamps
FILETIME currentFileTime, licenseFileTime;
LOG((3,"License: compare expiration date ..."));
SystemTimeToFileTime(¤tSystemTime, ¤tFileTime);
SystemTimeToFileTime(&licenseSystemTime, &licenseFileTime);
if (CompareFileTime(¤tFileTime,&licenseFileTime) == 1) {
// license expired
LOG((3,"License: licensed expired at %s",gLicense.validUntil));
if (dialog) MessageBox(0, "License expired - please configure a valid license!",
"HttpTapi", MB_OK | MB_ICONERROR | MB_SERVICE_NOTIFICATION);
gdwNumberOfLines = 0;
} else {
// license valid
LOG((3,"License: licensed still valid (till %s (%04u-%02u-%02u))",gLicense.validUntil,
licenseSystemTime.wYear, licenseSystemTime.wMonth, licenseSystemTime.wDay));
gdwNumberOfLines = gLicense.iNumberOfLines;
}
}
}
}
RegCloseKey (hKey);
}
BOOL
WINAPI
DllMain(
HANDLE hDLL,
DWORD dwReason,
LPVOID lpReserved
)
{
#ifdef LOGGING
{
HKEY hKey;
DWORD dwDataSize, dwDataType, dwDebugLevel=0;
RegOpenKeyExA(
HKEY_LOCAL_MACHINE,
gszHttpTapiKeyFull,
0,
KEY_ALL_ACCESS,
&hKey
);
dwDataSize = sizeof (DWORD);
RegQueryValueEx(
hKey,
gszHttpTapiDebugLevel,
0,
&dwDataType,
(LPBYTE) &dwDebugLevel,
&dwDataSize
);
LOG((3,"DllMain: setting debug level to %d", dwDebugLevel));
setLogLevel(dwDebugLevel);
RegCloseKey (hKey);
}
#endif
if (dwReason == DLL_PROCESS_ATTACH)
{
ghInst = hDLL;
gLicenseString = NULL;
gdwNumberOfLines = 0;
gpfnLineCreateProc = NULL;
LOG((5,"DllMain: entering with DLL_PROCESS_ATTACH ..."));
} else if (dwReason == DLL_PROCESS_DETACH) {
LOG((5,"DllMain: entering with DLL_PROCESS_DETACH ..."));
} else if (dwReason == DLL_THREAD_ATTACH) {
LOG((5,"DllMain: entering with DLL_THREAD_ATTACH ..."));
} else if (dwReason == DLL_THREAD_DETACH) {
LOG((5,"DllMain: entering with DLL_THREAD_DETACH ..."));
}
return TRUE;
}
//
// We get a slough of C4047 (different levels of indrection) warnings down
// below in the initialization of FUNC_PARAM structs as a result of the
// real func prototypes having params that are types other than DWORDs,
// so since these are known non-interesting warnings just turn them off
//
#pragma warning (disable:4047)
//
// --------------------------- TAPI_lineXxx funcs -----------------------------
//
LONG
TSPIAPI
TSPI_lineClose(
HDRVLINE hdLine
)
{
LONG lResult = 0;
#ifdef LOGGING
FUNC_PARAM params[] =
{
{ gszhdLine, hdLine }
};
FUNC_INFO info =
{
"TSPI_lineClose",
1,
params,
};
#endif
Prolog (&info);
DrvFree ((PDRVLINE) hdLine);
return (Epilog (&info, lResult));
}
LONG
TSPIAPI
TSPI_lineCloseCall(
HDRVCALL hdCall
)
{
PDRVLINE pLine = (PDRVLINE) hdCall;
#ifdef LOGGING
FUNC_PARAM params[] =
{
{ gszhdCall, hdCall }
};
FUNC_INFO info =
{
"TSPI_lineCloseCall",
1,
params
};
#endif
//
// Note that in TAPI 2.0 TSPI_lineCloseCall can get called
// without TSPI_lineDrop ever being called, so we need to
// be prepared for either case.
//
Prolog (&info);
DropActiveCall (pLine);
pLine->htCall = NULL;
return (Epilog (&info, 0));
}
LONG
TSPIAPI
TSPI_lineConditionalMediaDetection(
HDRVLINE hdLine,
DWORD dwMediaModes,
LPLINECALLPARAMS const lpCallParams
)
{
#ifdef LOGGING
FUNC_PARAM params[] =
{
{ gszhdLine, hdLine },
{ "dwMediaModes", dwMediaModes },
{ gszlpCallParams, lpCallParams }
};
FUNC_INFO info =
{
"TSPI_lineConditionalMediaDetection",
3,
params
};
#endif
//
// This func is really a no-op for us, since we don't look
// for incoming calls (though we do say we support them to
// make apps happy)
//
Prolog (&info);
return (Epilog (&info, 0));
}
LONG
TSPIAPI
TSPI_lineDrop(
DRV_REQUESTID dwRequestID,
HDRVCALL hdCall,
LPCSTR lpsUserUserInfo,
DWORD dwSize
)
{
PDRVLINE pLine = (PDRVLINE) hdCall;
#ifdef LOGGING
FUNC_PARAM params[] =
{
{ gszdwRequestID, dwRequestID },
{ gszhdCall, hdCall },
{ "lpsUserUserInfo", lpsUserUserInfo },
{ gszdwSize, dwSize }
};
FUNC_INFO info =
{
"TSPI_lineDrop",
4,
params
};
#endif
Prolog (&info);
DropActiveCall (pLine);
SetCallState (pLine, LINECALLSTATE_IDLE, 0);
/* Klaus: ConnectWise CRM does lineMakeCall, TSPI_lineDrop, lineMakeCall, TSPI_lineDrop ... without TSPI_lineCloseCall.
* Therefore I reset pLine->htCall already during TSPI_lineDrop (and not only during TSPI_lineCloseCall) to allow subsequent
* lineMakeCall.
*/
pLine->htCall = NULL;
(*gpfnCompletionProc)(dwRequestID, 0);
return (Epilog (&info, dwRequestID));
}
LONG
TSPIAPI
TSPI_lineGetAddressCaps(
DWORD dwDeviceID,
DWORD dwAddressID,
DWORD dwTSPIVersion,
DWORD dwExtVersion,
LPLINEADDRESSCAPS lpAddressCaps
)
{
#ifdef LOGGING
FUNC_PARAM params[] =
{
{ gszdwDeviceID, dwDeviceID },
{ "dwAddressID", dwAddressID },
{ "dwTSPIVersion", dwTSPIVersion },
{ "dwExtVersion", dwExtVersion },
{ "lpAddressCaps", lpAddressCaps }
};
FUNC_INFO info =
{
"TSPI_lineGetAddressCaps",
5,
params
};
#endif
LONG lResult = 0;
Prolog (&info);
if (dwAddressID != 0)
{
lResult = LINEERR_INVALADDRESSID;
}
lpAddressCaps->dwNeededSize =
lpAddressCaps->dwUsedSize = sizeof(LINEADDRESSCAPS);
lpAddressCaps->dwLineDeviceID = dwDeviceID;
lpAddressCaps->dwAddressSharing = LINEADDRESSSHARING_PRIVATE;
lpAddressCaps->dwCallInfoStates = LINECALLINFOSTATE_MEDIAMODE |
LINECALLINFOSTATE_APPSPECIFIC;
lpAddressCaps->dwCallerIDFlags =
lpAddressCaps->dwCalledIDFlags =
lpAddressCaps->dwRedirectionIDFlags =
lpAddressCaps->dwRedirectingIDFlags = LINECALLPARTYID_UNAVAIL;
lpAddressCaps->dwCallStates = LINECALLSTATE_IDLE |
LINECALLSTATE_OFFERING |
LINECALLSTATE_ACCEPTED |
LINECALLSTATE_DIALTONE |
LINECALLSTATE_DIALING |
LINECALLSTATE_CONNECTED |
LINECALLSTATE_PROCEEDING |
LINECALLSTATE_DISCONNECTED |
LINECALLSTATE_UNKNOWN;
lpAddressCaps->dwDialToneModes = LINEDIALTONEMODE_UNAVAIL;
lpAddressCaps->dwBusyModes = LINEBUSYMODE_UNAVAIL;
lpAddressCaps->dwSpecialInfo = LINESPECIALINFO_UNAVAIL;
lpAddressCaps->dwDisconnectModes = LINEDISCONNECTMODE_NORMAL |
LINEDISCONNECTMODE_BUSY |
LINEDISCONNECTMODE_NOANSWER |
LINEDISCONNECTMODE_UNAVAIL |
LINEDISCONNECTMODE_NODIALTONE;
lpAddressCaps->dwMaxNumActiveCalls = 1;
lpAddressCaps->dwAddrCapFlags = LINEADDRCAPFLAGS_DIALED;
lpAddressCaps->dwCallFeatures = LINECALLFEATURE_ACCEPT |
LINECALLFEATURE_ANSWER |
LINECALLFEATURE_DROP |
LINECALLFEATURE_SETCALLPARAMS;
lpAddressCaps->dwAddressFeatures = LINEADDRFEATURE_MAKECALL;
return (Epilog (&info, lResult));
}
LONG
TSPIAPI
TSPI_lineGetAddressStatus(
HDRVLINE hdLine,
DWORD dwAddressID,
LPLINEADDRESSSTATUS lpAddressStatus
)
{
#ifdef LOGGING
FUNC_PARAM params[] =
{
{ gszhdLine, hdLine },
{ "dwAddressID", dwAddressID },
{ "lpAddressStatus", lpAddressStatus }
};
FUNC_INFO info =
{
"TSPI_lineGetAddressStatus",
3,
params
};
#endif
LONG lResult = 0;
PDRVLINE pLine = (PDRVLINE) hdLine;
Prolog (&info);
lpAddressStatus->dwNeededSize =
lpAddressStatus->dwUsedSize = sizeof(LINEADDRESSSTATUS);
lpAddressStatus->dwNumActiveCalls = (pLine->htCall ? 1 : 0);
lpAddressStatus->dwAddressFeatures = LINEADDRFEATURE_MAKECALL;
return (Epilog (&info, lResult));
}
LONG
TSPIAPI
TSPI_lineGetCallAddressID(
HDRVCALL hdCall,
LPDWORD lpdwAddressID
)
{
#ifdef LOGGING
FUNC_PARAM params[] =
{
{ gszhdCall, hdCall },
{ "lpdwAddressID", lpdwAddressID }
};
FUNC_INFO info =
{
"TSPI_lineGetCallAddressID",
2,
params
};
#endif
//
// We only support 1 address (id=0)
//
Prolog (&info);
*lpdwAddressID = 0;
return (Epilog (&info, 0));
}
LONG
TSPIAPI
TSPI_lineGetCallInfo(
HDRVCALL hdCall,
LPLINECALLINFO lpLineInfo
)
{
#ifdef LOGGING
FUNC_PARAM params[] =
{
{ gszhdCall, hdCall },
{ "lpLineInfo", lpLineInfo }
};
FUNC_INFO info =
{
"TSPI_lineGetCallInfo",
2,
params
};
#endif
LONG lResult = 0;
PDRVLINE pLine = (PDRVLINE) hdCall;
Prolog (&info);
lpLineInfo->dwNeededSize =
lpLineInfo->dwUsedSize = sizeof(LINECALLINFO);
lpLineInfo->dwBearerMode = LINEBEARERMODE_VOICE;
lpLineInfo->dwMediaMode = pLine->dwMediaMode;
lpLineInfo->dwCallStates = LINECALLSTATE_IDLE |
LINECALLSTATE_DIALTONE |
LINECALLSTATE_DIALING |
LINECALLSTATE_CONNECTED |
LINECALLSTATE_PROCEEDING |
LINECALLSTATE_DISCONNECTED |
LINECALLSTATE_UNKNOWN;
lpLineInfo->dwOrigin = LINECALLORIGIN_OUTBOUND;
lpLineInfo->dwReason = LINECALLREASON_DIRECT;
lpLineInfo->dwCallerIDFlags =
lpLineInfo->dwCalledIDFlags =
lpLineInfo->dwConnectedIDFlags =
lpLineInfo->dwRedirectionIDFlags =
lpLineInfo->dwRedirectingIDFlags = LINECALLPARTYID_UNAVAIL;
return (Epilog (&info, lResult));
}
LONG
TSPIAPI
TSPI_lineGetCallStatus(
HDRVCALL hdCall,
LPLINECALLSTATUS lpLineStatus
)
{
#ifdef LOGGING
FUNC_PARAM params[] =
{
{ gszhdCall, hdCall },
{ "lpLineStatus", lpLineStatus }
};
FUNC_INFO info =
{
"TSPI_lineGetCallStatus",
2,
params
};
#endif
LONG lResult = 0;
PDRVLINE pLine = (PDRVLINE) hdCall;
Prolog (&info);
lpLineStatus->dwNeededSize =
lpLineStatus->dwUsedSize = sizeof(LINECALLSTATUS);
lpLineStatus->dwCallState = pLine->dwCallState;
if (pLine->dwCallState != LINECALLSTATE_IDLE)
{
lpLineStatus->dwCallFeatures = LINECALLFEATURE_DROP;
}
return (Epilog (&info, lResult));
}
LONG TSPIAPI TSPI_providerCreateLineDevice(
DWORD_PTR dwTempID,
DWORD dwDeviceID
)
{
#ifdef LOGGING
FUNC_PARAM params[] =
{
{ "dwTempID", dwTempID },
{ "dwDeviceID", dwDeviceID }
};
FUNC_INFO info =
{
"TSPI_providerCreateLineDevice",
2,
params
};
#endif
LONG lResult = 0;
Prolog (&info);
return (Epilog (&info, lResult));
};
LONG
TSPIAPI
TSPI_lineGetDevCaps(
DWORD dwDeviceID,
DWORD dwTSPIVersion,
DWORD dwExtVersion,
LPLINEDEVCAPS lpLineDevCaps
)
{
#ifdef LOGGING
FUNC_PARAM params[] =
{
{ gszdwDeviceID, dwDeviceID },
{ "dwTSPIVersion", dwTSPIVersion },
{ "dwExtVersion", dwExtVersion },
{ "lpLineDevCaps", lpLineDevCaps }
};
FUNC_INFO info =
{
"TSPI_lineGetDevCaps",
4,
params
};
#endif
LONG lResult = 0;
static WCHAR szProviderInfo[] = L"Generic HTTP TAPI service provider";
#define PROVIDER_INFO_SIZE (35 * sizeof (WCHAR))
Prolog (&info);
lpLineDevCaps->dwNeededSize = sizeof (LINEDEVCAPS) + PROVIDER_INFO_SIZE +
(MAX_REGKEYVAL_LENGTH + 1) * sizeof (WCHAR);
if (lpLineDevCaps->dwTotalSize >= lpLineDevCaps->dwNeededSize)
{
#define LINECONFIG_SIZE (2 * (MAX_REGKEYVAL_LENGTH + 1) + 40)
char szLineConfig[MAX_REGKEYVAL_LENGTH], szLineN[MAX_REGKEYNAME_LENGTH], szLineName[MAX_REGKEYVAL_LENGTH];
HKEY hKey;
DWORD dwDataSize, dwDataType;
lpLineDevCaps->dwUsedSize = lpLineDevCaps->dwNeededSize;
lpLineDevCaps->dwProviderInfoSize = PROVIDER_INFO_SIZE;
lpLineDevCaps->dwProviderInfoOffset = sizeof(LINEDEVCAPS);
My_lstrcpyW ((WCHAR *)(lpLineDevCaps + 1), szProviderInfo);
RegOpenKeyEx(
HKEY_LOCAL_MACHINE,
gszHttpTapiKeyFull,
0,
KEY_ALL_ACCESS,
&hKey
);
dwDataSize = LINECONFIG_SIZE;
wsprintf (szLineN, "Line%dName", dwDeviceID - gdwLineDeviceIDBase);
strncpy (szLineConfig, gszHttpTapiDefLineConfigParamsName, MAX_REGKEYVAL_LENGTH-1);
szLineConfig[MAX_REGKEYVAL_LENGTH-1] = '\0';
RegQueryValueEx(
hKey,
szLineN,
0,
&dwDataType,
(LPBYTE) szLineConfig,
&dwDataSize
);
RegCloseKey (hKey);
_snprintf(szLineName, MAX_REGKEYVAL_LENGTH-1, "HTTPTAPI %02d: %s", dwDeviceID-gdwLineDeviceIDBase+1, szLineConfig);
szLineName[sizeof(szLineName)-1] = 0;
lpLineDevCaps->dwLineNameSize = (lstrlen (szLineName) + 1) *
sizeof (WCHAR);
lpLineDevCaps->dwLineNameOffset = sizeof(LINEDEVCAPS) +
PROVIDER_INFO_SIZE;
MultiByteToWideChar(
CP_ACP,
MB_PRECOMPOSED,
szLineName,
-1,
(WCHAR *) ((LPBYTE) (lpLineDevCaps + 1) + PROVIDER_INFO_SIZE),
(lpLineDevCaps->dwLineNameSize)/sizeof(WCHAR)
);
}
else
{
lpLineDevCaps->dwUsedSize = sizeof(LINEDEVCAPS);
}
lpLineDevCaps->dwStringFormat = STRINGFORMAT_ASCII;
// assign a permanent line ID (from "Windows telephony programming: a developer's guide to TAPI" by Chris Sells)
// this enables dialer.exe to "remember" the choosen line for the next call, but may cause confusion when
// lines are added/removed, as the order of the lines may change
// ToDo: store the permanent ID also in registry to keep it constant when adding/deleting lines
//#define MAKEPERMLINEID(dwPermProviderID, dwDeviceID) ((LOWORD(dwPermProviderID) << 16) | dwDeviceID)
// KlausDarilion: when the TSP is used on multiple terminal servers the PermantLineId should be the
// same on all of them.
#define MAKEPERMLINEID(dwPermProviderID, dwDeviceID) ((LOWORD(1975) << 16) | dwDeviceID)
lpLineDevCaps->dwPermanentLineID = MAKEPERMLINEID(gdwPermanentProviderID, dwDeviceID - gdwLineDeviceIDBase);
lpLineDevCaps->dwAddressModes = LINEADDRESSMODE_ADDRESSID;
lpLineDevCaps->dwNumAddresses = 1;
lpLineDevCaps->dwBearerModes = LINEBEARERMODE_VOICE;
lpLineDevCaps->dwMediaModes = LINEMEDIAMODE_INTERACTIVEVOICE;
lpLineDevCaps->dwDevCapFlags = LINEDEVCAPFLAGS_CLOSEDROP;
lpLineDevCaps->dwAddressTypes = LINEADDRESSTYPE_PHONENUMBER;
lpLineDevCaps->dwMaxNumActiveCalls = 1;
lpLineDevCaps->dwRingModes = 1;
lpLineDevCaps->dwLineFeatures = LINEFEATURE_MAKECALL;
return (Epilog (&info, lResult));
}
LONG
TSPIAPI
TSPI_lineGetID(
HDRVLINE hdLine,
DWORD dwAddressID,
HDRVCALL hdCall,
DWORD dwSelect,
LPVARSTRING lpDeviceID,
LPCWSTR lpszDeviceClass,
HANDLE hTargetProcess
)
{
#ifdef LOGGING
FUNC_PARAM params[] =
{
{ gszhdLine, hdLine },
{ "dwAddressID", dwAddressID },
{ gszhdCall, hdCall },
{ "dwSelect", dwSelect },
{ "lpDeviceID", lpDeviceID },
{ "lpszDeviceClass", lpszDeviceClass },
{ "hTargetProcess", hTargetProcess }
};
FUNC_INFO info =
{
"TSPI_lineGetID",
7,
params
};
#endif
DWORD dwNeededSize = sizeof(VARSTRING) + sizeof (DWORD);
LONG lResult = 0;
PDRVLINE pLine = (dwSelect == LINECALLSELECT_CALL ?
(PDRVLINE) hdCall : (PDRVLINE) hdLine);