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.

450 lines
12 KiB

  1. #include "globals.h"
  2. #include "line.h"
  3. #include "config.h"
  4. #define H323_VERSION_LO 0x00000000
  5. #define H323_VERSION_HI 0x00000000
  6. #define TSPI_VERSION_LO 0x00030000
  7. #define TSPI_VERSION_HI TAPI_CURRENT_VERSION
  8. //
  9. // Global variables
  10. //
  11. HINSTANCE g_hInstance;
  12. WCHAR g_pwszProviderInfo[64];
  13. WCHAR g_pwszLineName[16];
  14. DWORD g_dwTSPIVersion;
  15. //
  16. // Private procedures
  17. //
  18. /*++
  19. Routine Description:
  20. This function determines whether or not specified TSPI version is
  21. supported by the service provider.
  22. Arguments:
  23. dwLowVersion - Specifies the lowest TSPI version number under which the
  24. TAPI DLL is willing to operate. The most-significant WORD is the
  25. major version number and the least-significant WORD is the minor
  26. version number.
  27. dwHighVersion - Specifies the highest TSPI version number under which
  28. the TAPI DLL is willing to operate. The most-significant WORD is the
  29. major version number and the least-significant WORD is the minor
  30. version number.
  31. pdwTSPIVersion - Specifies a far pointer to a DWORD. The service
  32. provider fills this location with the highest TSPI version number,
  33. within the range requested by the caller, under which the service
  34. provider is willing to operate. The most-significant WORD is the
  35. major version number and the least-significant WORD is the minor
  36. version number.
  37. Return Values:
  38. Returns true if successful.
  39. --*/
  40. BOOL
  41. H323NegotiateTSPIVersion(
  42. IN DWORD dwLowVersion,
  43. IN DWORD dwHighVersion,
  44. OUT PDWORD pdwTSPIVersion
  45. )
  46. {
  47. // validate extension version range
  48. if ((TSPI_VERSION_HI <= dwHighVersion) &&
  49. (TSPI_VERSION_HI >= dwLowVersion))
  50. {
  51. // save negotiated version
  52. *pdwTSPIVersion = TSPI_VERSION_HI;
  53. // success
  54. return TRUE;
  55. }
  56. else if( (dwHighVersion <= TSPI_VERSION_HI) &&
  57. (dwHighVersion >= TSPI_VERSION_LO) )
  58. {
  59. // save negotiated version
  60. *pdwTSPIVersion = dwHighVersion;
  61. // success
  62. return TRUE;
  63. }
  64. H323DBG(( DEBUG_LEVEL_FORCE, "TSPI version (%08XH:%08XH) rejected.",
  65. dwHighVersion, dwLowVersion ));
  66. // failure
  67. return FALSE;
  68. }
  69. //
  70. // Public procedures
  71. //
  72. /*++
  73. Routine Description:
  74. This function determines whether or not specified TSPI version is
  75. supported by the service provider.
  76. Arguments:
  77. dwTSPIVersion - Specifies the TSPI version to validate.
  78. Return Values:
  79. Returns true if successful.
  80. --*/
  81. BOOL
  82. H323ValidateTSPIVersion(
  83. IN DWORD dwTSPIVersion
  84. )
  85. {
  86. // see if specified version is supported
  87. if ((dwTSPIVersion >= TSPI_VERSION_LO) &&
  88. (dwTSPIVersion <= TSPI_VERSION_HI)) {
  89. // success
  90. return TRUE;
  91. }
  92. H323DBG((DEBUG_LEVEL_FORCE, "do not support TSPI version %08XH.",
  93. dwTSPIVersion));
  94. // failure
  95. return FALSE;
  96. }
  97. /*++
  98. Routine Description:
  99. This function determines whether or not specified extension version is
  100. supported by the service provider.
  101. Arguments:
  102. dwExtVersion - Specifies the extension version to validate.
  103. Return Values:
  104. Returns true if successful.
  105. --*/
  106. BOOL
  107. H323ValidateExtVersion(
  108. IN DWORD dwExtVersion
  109. )
  110. {
  111. // no device specific extension
  112. if (dwExtVersion == H323_VERSION_HI) {
  113. // success
  114. return TRUE;
  115. }
  116. H323DBG((
  117. DEBUG_LEVEL_ERROR,
  118. "do not support extension version %d.%d.",
  119. HIWORD(dwExtVersion),
  120. LOWORD(dwExtVersion)
  121. ));
  122. // failure
  123. return FALSE;
  124. }
  125. //
  126. // TSPI procedures
  127. //
  128. /*++
  129. Routine Description:
  130. This function returns the highest SPI version the Service Provider is
  131. willing to operate under for this device given the range of possible
  132. SPI versions.
  133. The TAPI DLL typically calls this function early in the initialization
  134. sequence for each line device. In addition, it calls this with the
  135. value INITIALIZE_NEGOTIATION for dwDeviceID to negotiate an interface
  136. version for calling early initialization functions.
  137. Note that when dwDeviceID is INITIALIZE_NEGOTIATION, this function must
  138. not return LINEERR_OPERATIONUNAVAIL, since this function (with that value)
  139. is mandatory for negotiating the overall interface version even if the
  140. service provider supports no line devices.
  141. Negotiation of an Extension version is done through the separate
  142. procedure TSPI_lineNegotiateExtVersion.
  143. Arguments:
  144. dwDeviceID - Identifies the line device for which interface version
  145. negotiation is to be performed. In addition to device IDs within
  146. the range the Service Provider supports, this may be the value:
  147. INITIALIZE_NEGOTIATION - This value is used to signify that an overall
  148. interface version is to be negotiated. Such an interface version
  149. is required for functions that can be called early in the
  150. initialization sequence, i.e., before the device ID range has
  151. been set.
  152. dwLowVersion - Specifies the lowest TSPI version number under which the
  153. TAPI DLL is willing to operate. The most-significant WORD is the
  154. major version number and the least-significant WORD is the minor
  155. version number.
  156. dwHighVersion - Specifies the highest TSPI version number under which
  157. the TAPI DLL is willing to operate. The most-significant WORD is the
  158. major version number and the least-significant WORD is the minor
  159. version number.
  160. pdwTSPIVersion - Specifies a far pointer to a DWORD. The service
  161. provider fills this location with the highest TSPI version number,
  162. within the range requested by the caller, under which the service
  163. provider is willing to operate. The most-significant WORD is the
  164. major version number and the least-significant WORD is the minor
  165. version number. If the requested range does not overlap the range
  166. supported by the service provider, the function returns
  167. LINEERR_INCOMPATIBLEAPIVERSION.
  168. Return Values:
  169. Returns zero if the function is successful, or a negative error number
  170. if an error has occurred. Possible return values are as follows:
  171. LINEERR_BADDEVICEID - The specified device identifier or line device
  172. identifier (such as in a dwDeviceID parameter) is invalid or
  173. out of range.
  174. LINEERR_INCOMPATIBLEAPIVERSION - The application requested an API
  175. version or version range that is either incompatible or cannot
  176. be supported by the Telephony API implementation and/or
  177. corresponding service provider.
  178. LINEERR_OPERATIONFAILED - The operation failed for an unspecified
  179. or unknown reason.
  180. --*/
  181. LONG
  182. TSPIAPI
  183. TSPI_lineNegotiateTSPIVersion(
  184. DWORD dwDeviceID,
  185. DWORD dwLowVersion,
  186. DWORD dwHighVersion,
  187. PDWORD pdwTSPIVersion
  188. )
  189. {
  190. DWORD dwTSPIVersion;
  191. H323DBG(( DEBUG_LEVEL_TRACE, "TSPI_lineNegotiateTSPIVer - Entered." ));
  192. // see if this is a init line device
  193. if ((DWORD_PTR)dwDeviceID == INITIALIZE_NEGOTIATION)
  194. {
  195. H323DBG(( DEBUG_LEVEL_VERBOSE,
  196. "tapisrv supports tspi version %d.%d through %d.%d.",
  197. HIWORD(dwLowVersion),
  198. LOWORD(dwLowVersion),
  199. HIWORD(dwHighVersion),
  200. LOWORD(dwHighVersion)
  201. ));
  202. // perform version negotiation
  203. if (!H323NegotiateTSPIVersion(
  204. dwLowVersion,
  205. dwHighVersion,
  206. &dwTSPIVersion))
  207. {
  208. H323DBG(( DEBUG_LEVEL_TRACE, "TSPI_lineNegotiateTSPIVer - bad version." ));
  209. // negotiated version not agreed upon
  210. return LINEERR_INCOMPATIBLEAPIVERSION;
  211. }
  212. // see if this is a valid line device
  213. }
  214. else if( g_pH323Line -> GetDeviceID() == (DWORD)dwDeviceID )
  215. {
  216. // perform version negotiation
  217. if (!H323NegotiateTSPIVersion(
  218. dwLowVersion,
  219. dwHighVersion,
  220. &dwTSPIVersion))
  221. {
  222. H323DBG(( DEBUG_LEVEL_TRACE, "TSPI_lineNegotiateTSPIVer - incompat ver." ));
  223. // negotiated version not agreed upon
  224. return LINEERR_INCOMPATIBLEAPIVERSION;
  225. }
  226. }
  227. else
  228. {
  229. H323DBG(( DEBUG_LEVEL_TRACE, "TSPI_lineNegotiateTSPIVer - bad device id:%d:%d.",
  230. g_pH323Line -> GetDeviceID(), dwDeviceID));
  231. // do not recognize device
  232. return LINEERR_BADDEVICEID;
  233. }
  234. // return negotiated version
  235. *pdwTSPIVersion = dwTSPIVersion;
  236. g_dwTSPIVersion = dwTSPIVersion;
  237. H323DBG(( DEBUG_LEVEL_TRACE, "TSPI_lineNegotiateTSPIVer - Exited." ));
  238. // success
  239. return NOERROR;
  240. }
  241. /*++
  242. Routine Description:
  243. Loads strings from resource table.
  244. Arguments:
  245. None.
  246. Return Values:
  247. Returns true if successful.
  248. --*/
  249. BOOL
  250. H323LoadStrings(
  251. )
  252. {
  253. DWORD dwNumBytes;
  254. DWORD dwNumChars;
  255. WCHAR wszBuffer[256];
  256. // load string into buffer
  257. dwNumChars = LoadStringW(
  258. g_hInstance,
  259. IDS_LINENAME,
  260. g_pwszLineName,
  261. sizeof(g_pwszLineName)/sizeof(WCHAR)
  262. );
  263. if( dwNumChars == 0 )
  264. return FALSE;
  265. // load string into buffer
  266. dwNumChars = LoadStringW(
  267. g_hInstance,
  268. IDS_PROVIDERNAME,
  269. g_pwszProviderInfo,
  270. sizeof(g_pwszProviderInfo)/sizeof(WCHAR)
  271. );
  272. if( dwNumChars == 0 )
  273. return FALSE;
  274. // success
  275. return TRUE;
  276. }
  277. //
  278. // Public Procedures
  279. //
  280. /*++
  281. Routine Description:
  282. Dll entry point.
  283. Arguments:
  284. Same as DllMain.
  285. Return Values:
  286. Returns true if successful.
  287. --*/
  288. BOOL
  289. WINAPI
  290. DllMain(
  291. PVOID DllHandle,
  292. ULONG Reason,
  293. LPVOID lpReserved
  294. )
  295. {
  296. BOOL fOk = TRUE;
  297. // check if new process attaching
  298. if (Reason == DLL_PROCESS_ATTACH)
  299. {
  300. g_RegistrySettings.dwLogLevel = DEBUG_LEVEL_FORCE;
  301. H323DBG ((DEBUG_LEVEL_FORCE, "DLL_PROCESS_ATTACH"));
  302. // store the handle into a global variable so that
  303. // the UI code can use it.
  304. g_hInstance = (HINSTANCE)DllHandle;
  305. // turn off thread attach messages
  306. DisableThreadLibraryCalls( g_hInstance );
  307. // start h323 tsp
  308. fOk = H323LoadStrings();
  309. // check if new process detaching
  310. }
  311. else if (Reason == DLL_PROCESS_DETACH)
  312. {
  313. H323DBG ((DEBUG_LEVEL_FORCE, "DLL_PROCESS_DETACH"));
  314. #if DBG
  315. TRACELogDeRegister();
  316. #else
  317. CloseLogFile();
  318. #endif
  319. fOk = TRUE;
  320. }
  321. return fOk;
  322. }