Leaked source code of windows server 2003
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.

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