Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

569 lines
12 KiB

  1. /*++
  2. Copyright (c) 1995-1997 Microsoft Corporation
  3. Module Name:
  4. remotesp.h
  5. Abstract:
  6. This module contains defs, etc for the Remote TAPI Service Provider
  7. Author:
  8. Dan Knudson (DanKn) 09-Aug-1995
  9. Revision History:
  10. --*/
  11. #include "windows.h"
  12. #include "stddef.h"
  13. #include "stdarg.h"
  14. #include "stdio.h"
  15. #include "stdlib.h"
  16. #include "malloc.h"
  17. #include "string.h"
  18. #include "tapi.h"
  19. #include "tspi.h"
  20. #include "client.h"
  21. #include "server.h"
  22. #include "line.h"
  23. #undef DEVICE_ID
  24. #include "phone.h"
  25. #include "tapsrv.h"
  26. #include "tapi.h"
  27. #include "tspi.h"
  28. #include "resource.h"
  29. #include "tlnklist.h"
  30. //#define NO_DATA 0xffffffff
  31. #define DEF_NUM_LINE_ENTRIES 16
  32. #define DEF_NUM_PHONE_ENTRIES 16
  33. #define DEF_MAX_EVENT_BUFFER_SIZE 0x20000
  34. #define IDI_ICON1 101
  35. #define IDI_ICON2 102
  36. #define IDI_ICON3 103
  37. #define DRVLINE_KEY ((DWORD) 'LpsR')
  38. #define DRVCALL_KEY ((DWORD) 'CpsR')
  39. #define DRVPHONE_KEY ((DWORD) 'PpsR')
  40. #define DRVASYNC_KEY ((DWORD) 'ApsR')
  41. #define DRVINVAL_KEY ((DWORD) 'IpsR')
  42. #define RSP_MSG_UIID 1
  43. #define STRUCTCHANGE_LINECALLINFO 0x00000001
  44. #define STRUCTCHANGE_LINECALLSTATUS 0x00000002
  45. #if MEMPHIS
  46. #else
  47. #define STRUCTCHANGE_CALLIDS 0x00000004
  48. #endif
  49. #define INITIALTLSLISTSIZE 10
  50. #define RSP_MAX_SERVER_NAME_SIZE 64
  51. #define NPT_TIMEOUT 60000
  52. #define MIN_MAILSLOT_TIMEOUT 500
  53. #define MAX_MAILSLOT_TIMEOUT 6000
  54. #define ERROR_REMOTESP_NONE 0
  55. #define ERROR_REMOTESP_ATTACH 1
  56. #define ERROR_REMOTESP_EXCEPTION 2
  57. #define ERROR_REMOTESP_NP_ATTACH 3
  58. #define ERROR_REMOTESP_NP_EXCEPTION 4
  59. typedef struct _RSP_INIT_CONTEXT
  60. {
  61. DWORD dwNumRundownsExpected;
  62. BOOL bShutdown;
  63. LIST_ENTRY ServerList;
  64. struct _RSP_INIT_CONTEXT *pNextStaleInitContext;
  65. DWORD dwDrvServerKey;
  66. } RSP_INIT_CONTEXT, *PRSP_INIT_CONTEXT;
  67. #define SERVER_DISCONNECTED (0x00000001)
  68. #define SERVER_REINIT (0x00000002)
  69. typedef struct _DRVSERVER
  70. {
  71. DWORD dwKey;
  72. PRSP_INIT_CONTEXT pInitContext;
  73. PCONTEXT_HANDLE_TYPE phContext;
  74. HLINEAPP hLineApp;
  75. HPHONEAPP hPhoneApp;
  76. RPC_BINDING_HANDLE *phTapSrv;
  77. DWORD dwFlags;
  78. BOOL bVer2xServer;
  79. DWORD dwSpecialHack;
  80. BOOL bConnectionOriented;
  81. LIST_ENTRY ServerList;
  82. DWORD InitContext;
  83. BOOL bSetAuthInfo;
  84. RPC_BINDING_HANDLE hTapSrv;
  85. BOOL bShutdown;
  86. char szServerName[MAX_COMPUTERNAME_LENGTH+1];
  87. } DRVSERVER, *PDRVSERVER;
  88. typedef struct _DRVLINE
  89. {
  90. DWORD dwKey;
  91. DWORD dwDeviceIDLocal;
  92. DWORD dwDeviceIDServer;
  93. DWORD hDeviceCallback;
  94. DWORD dwXPIVersion;
  95. HLINE hLine;
  96. HTAPILINE htLine;
  97. LPVOID pCalls;
  98. PDRVSERVER pServer;
  99. LINEEXTENSIONID ExtensionID;
  100. DWORD dwFlags;
  101. DWORD dwPermanentLineID;
  102. } DRVLINE, *PDRVLINE;
  103. typedef struct _DRVCALL
  104. {
  105. DWORD dwKey;
  106. DWORD dwOriginalRequestID;
  107. PDRVSERVER pServer;
  108. PDRVLINE pLine;
  109. DWORD dwAddressID;
  110. HCALL hCall;
  111. DWORD dwDirtyStructs;
  112. LPLINECALLINFO pCachedCallInfo;
  113. DWORD dwCachedCallInfoCount;
  114. LPLINECALLSTATUS pCachedCallStatus;
  115. DWORD dwCachedCallStatusCount;
  116. struct _DRVCALL *pPrev;
  117. struct _DRVCALL *pNext;
  118. //
  119. // NOTE: Tapisrv relies on the ordering of the following two
  120. // dwInitialXxx fields & the htCall field - don't change this!
  121. //
  122. ULONG_PTR dwInitialCallStateMode;
  123. ULONG_PTR dwInitialPrivilege;
  124. HTAPICALL htCall;
  125. #if MEMPHIS
  126. #else
  127. DWORD dwCallID;
  128. DWORD dwRelatedCallID;
  129. #endif
  130. DWORD dwFlags;
  131. } DRVCALL, *PDRVCALL;
  132. typedef struct _DRVPHONE
  133. {
  134. DWORD dwKey;
  135. DWORD dwDeviceIDLocal;
  136. DWORD dwDeviceIDServer;
  137. DWORD hDeviceCallback;
  138. DWORD dwXPIVersion;
  139. HPHONE hPhone;
  140. PDRVSERVER pServer;
  141. HTAPIPHONE htPhone;
  142. PHONEEXTENSIONID ExtensionID;
  143. DWORD dwPermanentPhoneID;
  144. } DRVPHONE, *PDRVPHONE;
  145. typedef struct _DRVLINELOOKUP
  146. {
  147. DWORD dwTotalEntries;
  148. DWORD dwUsedEntries;
  149. struct _DRVLINELOOKUP *pNext;
  150. DRVLINE aEntries[1];
  151. } DRVLINELOOKUP, *PDRVLINELOOKUP;
  152. typedef struct _DRVPHONELOOKUP
  153. {
  154. DWORD dwTotalEntries;
  155. DWORD dwUsedEntries;
  156. struct _DRVPHONELOOKUP *pNext;
  157. DRVPHONE aEntries[1];
  158. } DRVPHONELOOKUP, *PDRVPHONELOOKUP;
  159. typedef struct _RSP_THREAD_INFO
  160. {
  161. LIST_ENTRY TlsList;
  162. LPBYTE pBuf;
  163. DWORD dwBufSize;
  164. BOOL bAlreadyImpersonated;
  165. } RSP_THREAD_INFO, *PRSP_THREAD_INFO;
  166. typedef void (PASCAL *RSPPOSTPROCESSPROC)(PASYNCEVENTMSG pMsg,LPVOID pContext);
  167. typedef struct _ASYNCREQUESTCONTEXT
  168. {
  169. union
  170. {
  171. DWORD dwKey;
  172. DWORD dwOriginalRequestID;
  173. };
  174. RSPPOSTPROCESSPROC pfnPostProcessProc;
  175. ULONG_PTR Params[2];
  176. } ASYNCREQUESTCONTEXT, *PASYNCREQUESTCONTEXT;
  177. typedef enum
  178. {
  179. Dword,
  180. LineID,
  181. PhoneID,
  182. Hdcall,
  183. Hdline,
  184. Hdphone,
  185. lpDword,
  186. lpsz,
  187. lpGet_SizeToFollow,
  188. lpSet_SizeToFollow,
  189. lpSet_Struct,
  190. lpGet_Struct,
  191. lpGet_CallParamsStruct,
  192. Size,
  193. lpServer,
  194. lpContext
  195. } REMOTE_ARG_TYPES, *PREMOTE_ARG_TYPES;
  196. typedef struct _REMOTE_FUNC_ARGS
  197. {
  198. DWORD Flags;
  199. ULONG_PTR *Args;
  200. PREMOTE_ARG_TYPES ArgTypes;
  201. } REMOTE_FUNC_ARGS, *PREMOTE_FUNC_ARGS;
  202. HANDLE ghInst;
  203. char gszServer[] = "Server",
  204. gszProvider[] = "Provider",
  205. gszNumServers[] = "NumServers",
  206. gszTelephonIni[] = "Telephon.ini";
  207. WCHAR gszMachineName[MAX_COMPUTERNAME_LENGTH + 1];
  208. WCHAR gszRealSPUIDLL[MAX_PATH+1];
  209. char gszDomainUser[64];
  210. DWORD gdwLineDeviceIDBase,
  211. gdwPhoneDeviceIDBase,
  212. gdwInitialNumLineDevices,
  213. gdwInitialNumPhoneDevices,
  214. gdwTempLineID = 0xFFFFFFFF,
  215. gdwTempPhoneID = 0xFFFFFFFF,
  216. gdwTlsIndex,
  217. gdwPermanentProviderID,
  218. gdwRetryCount,
  219. gdwRetryTimeout,
  220. gdwCacheForceCallCount,
  221. gdwMaxEventBufferSize,
  222. gdwRSPRpcTimeout;
  223. BOOL gfCacheStructures;
  224. HICON ghLineIcon,
  225. ghPhoneIcon;
  226. HANDLE hToken,
  227. ghRpcServerThread;
  228. HPROVIDER ghProvider;
  229. LINEEVENT gpfnLineEventProc;
  230. PHONEEVENT gpfnPhoneEventProc;
  231. PDRVLINELOOKUP gpLineLookup;
  232. PDRVPHONELOOKUP gpPhoneLookup;
  233. ASYNC_COMPLETION gpfnCompletionProc;
  234. CRITICAL_SECTION gEventBufferCriticalSection,
  235. gCallListCriticalSection,
  236. gcsTlsList;
  237. #ifdef __TAPI_DEBUG_CS__
  238. DEBUG_CS_CRITICAL_SECTION gCriticalSection;
  239. #else
  240. CRITICAL_SECTION gCriticalSection;
  241. #endif
  242. DWORD gdwTlsListUsedEntries,
  243. gdwTlsListTotalEntries;
  244. PRSP_THREAD_INFO * gpTlsList;
  245. BOOL gbLoadedSelf = FALSE,
  246. gbInitialized;
  247. PRSP_INIT_CONTEXT gpCurrentInitContext, gpStaleInitContexts;
  248. DWORD gdwNumStaleInitContexts;
  249. DWORD gdwDrvServerKey;
  250. LIST_ENTRY gNptListHead;
  251. HANDLE ghNetworkPollThread = NULL;
  252. PWSTR gpszThingToPassToServer = NULL;
  253. HANDLE ghNptShutdownEvent;
  254. PDRVSERVER gpCurrInitServer;
  255. WCHAR gszMailslotName[MAX_COMPUTERNAME_LENGTH + 32];
  256. const TCHAR gszTelephonyKey[] =
  257. "Software\\Microsoft\\Windows\\CurrentVersion\\Telephony";
  258. LONG gaNoMemErrors[3] =
  259. {
  260. 0,
  261. LINEERR_NOMEM,
  262. PHONEERR_NOMEM
  263. };
  264. LONG gaOpFailedErrors[3] =
  265. {
  266. 0,
  267. LINEERR_OPERATIONFAILED,
  268. PHONEERR_OPERATIONFAILED
  269. };
  270. LONG gaServerDisconnectedErrors[3] =
  271. {
  272. 0,
  273. LINEERR_DISCONNECTED,
  274. PHONEERR_DISCONNECTED
  275. };
  276. LONG gaServerReInitErrors[3] =
  277. {
  278. 0,
  279. LINEERR_REINIT,
  280. PHONEERR_REINIT
  281. };
  282. struct
  283. {
  284. HANDLE hThread;
  285. DWORD dwEventBufferTotalSize;
  286. DWORD dwEventBufferUsedSize;
  287. LPBYTE pEventBuffer;
  288. LPBYTE pDataIn;
  289. LPBYTE pDataOut;
  290. HANDLE hEvent;
  291. BOOL bExit;
  292. HANDLE hMailslot;
  293. HANDLE hMailslotEvent;
  294. DWORD dwMsgBufferTotalSize;
  295. LPBYTE pMsgBuffer;
  296. } gEventHandlerThreadParams;
  297. #if DBG
  298. LONG
  299. WINAPI
  300. RemoteDoFunc(
  301. PREMOTE_FUNC_ARGS pFuncArgs,
  302. char *pszFuncName
  303. );
  304. #define REMOTEDOFUNC(arg1,arg2) RemoteDoFunc(arg1,arg2)
  305. DWORD gdwDebugLevel = 0;
  306. DWORD gdwAllocTag = 0;
  307. #else
  308. LONG
  309. WINAPI
  310. RemoteDoFunc(
  311. PREMOTE_FUNC_ARGS pFuncArgs
  312. );
  313. #define REMOTEDOFUNC(arg1,arg2) RemoteDoFunc(arg1)
  314. #endif
  315. BOOL
  316. WINAPI
  317. _CRT_INIT(
  318. HINSTANCE hDLL,
  319. DWORD dwReason,
  320. LPVOID lpReserved
  321. );
  322. void
  323. PASCAL
  324. TSPI_lineMakeCall_PostProcess(
  325. PASYNCEVENTMSG pMsg,
  326. PASYNCREQUESTCONTEXT pContext
  327. );
  328. LONG
  329. AddLine(
  330. PDRVSERVER pServer,
  331. DWORD dwDeviceIDLocal,
  332. DWORD dwDeviceIDServer,
  333. BOOL bInit,
  334. BOOL bNegotiate,
  335. DWORD dwAPIVerion,
  336. LPLINEEXTENSIONID pExtID
  337. );
  338. LONG
  339. AddPhone(
  340. PDRVSERVER pServer,
  341. DWORD dwDeviceIDLocal,
  342. DWORD dwDeviceIDServer,
  343. BOOL bInit,
  344. BOOL bNegotiate,
  345. DWORD dwAPIVerion,
  346. LPPHONEEXTENSIONID pExtID
  347. );
  348. LONG
  349. AddCallToList(
  350. PDRVLINE pLine,
  351. PDRVCALL pCall
  352. );
  353. LONG
  354. RemoveCallFromList(
  355. PDRVCALL pCall
  356. );
  357. void
  358. Shutdown(
  359. PDRVSERVER pServer
  360. );
  361. BOOL
  362. CALLBACK
  363. ConfigDlgProc(
  364. HWND hwnd,
  365. UINT msg,
  366. WPARAM wParam,
  367. LPARAM lParam
  368. );
  369. LONG
  370. PASCAL
  371. ProviderInstall(
  372. char *pszProviderName,
  373. BOOL bNoMultipleInstance
  374. );
  375. void
  376. FreeLeftoverTlsEntries(
  377. );
  378. void
  379. RemoveTlsFromList(
  380. PRSP_THREAD_INFO p
  381. );
  382. void
  383. AddTlsToList(
  384. PRSP_THREAD_INFO p
  385. );
  386. VOID
  387. PASCAL
  388. FreeInitContext(
  389. PRSP_INIT_CONTEXT pInitContext
  390. );
  391. LONG
  392. FinishEnumDevices(
  393. PDRVSERVER pServer,
  394. PCONTEXT_HANDLE_TYPE phContext,
  395. LPDWORD lpdwNumLines,
  396. LPDWORD lpdwNumPhones,
  397. BOOL fStartup,
  398. BOOL bFromReg
  399. );
  400. VOID
  401. WINAPI
  402. NetworkPollThread(
  403. LPVOID pszThingtoPassToServer
  404. );
  405. VOID
  406. PASCAL
  407. FreeInitContext(
  408. PRSP_INIT_CONTEXT pInitContext
  409. );
  410. BOOL
  411. IsClientSystem(
  412. VOID
  413. );
  414. void
  415. PASCAL
  416. TSPI_lineGatherDigits_PostProcess(
  417. PASYNCEVENTMSG pMsg
  418. );
  419. LONG
  420. WINAPI
  421. RSPSetEventFilterMasks (
  422. PDRVSERVER pServer,
  423. DWORD dwObjType,
  424. LONG_PTR lObjectID,
  425. ULONG64 ulEventMasks
  426. );