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.

303 lines
11 KiB

  1. /****************************************************************************/
  2. -- tssdsp.sql
  3. --
  4. -- Terminal Server Session Directory stored procedures.
  5. --
  6. -- Copyright (C) 2000 Microsoft Corporation
  7. /****************************************************************************/
  8. /****************************************************************************/
  9. -- SP_TSSDServerOnline
  10. --
  11. -- Called by TSSDSQL to indicate a new server is coming up. Removes all
  12. -- previous entries related to this server in case of unexpected shutdown.
  13. -- Returns a 2-entry recordset with the values (ServerID, ClusterID) that
  14. -- are used in later stored procedure calls.
  15. /****************************************************************************/
  16. IF EXISTS (SELECT name FROM sysobjects
  17. WHERE name = 'SP_TSSDServerOnline' and type = 'P')
  18. DROP PROCEDURE SP_TSSDServerOnline
  19. GO
  20. CREATE PROCEDURE SP_TSSDServerOnline
  21. @ServerAddress nvarchar(63),
  22. @ClusterName nvarchar(63)
  23. AS
  24. DECLARE @ClusterID int
  25. DECLARE @ServerID int
  26. DECLARE @ParsedClusterName nvarchar(63)
  27. -- Turn off intermediate returns to the client. Needed to help ADO
  28. -- return a valid final recordset, plus reduces round-trips on network.
  29. SET NOCOUNT ON
  30. -- We need to perform some locking on the tables to make sure
  31. -- of the data integrity. We are assuming default isolation level
  32. -- of Read Committed.
  33. BEGIN TRANSACTION
  34. SET @ServerID = (SELECT MIN(ServerID) FROM TSSD_Servers
  35. WHERE ServerAddress = @ServerAddress)
  36. DELETE FROM TSSD_Sessions WHERE ServerID = @ServerID
  37. DELETE FROM TSSD_Servers WHERE ServerID = @ServerID
  38. -- The TS may end up sending a NULL param when it's really an empty
  39. -- string. Handle that gracefully.
  40. IF (@ClusterName IS NULL) BEGIN
  41. SET @ParsedClusterName = ""
  42. END
  43. ELSE BEGIN
  44. SET @ParsedClusterName = @ClusterName
  45. END
  46. -- If the cluster does not exist, create it.
  47. SET @ClusterID = (SELECT MIN(ClusterID) FROM TSSD_Clusters
  48. WHERE ClusterName = @ParsedClusterName)
  49. IF (@ClusterID IS NULL) BEGIN
  50. INSERT INTO TSSD_Clusters (ClusterName) VALUES (@ParsedClusterName)
  51. SET @ClusterID = (SELECT MIN(ClusterID) FROM TSSD_Clusters
  52. WHERE ClusterName = @ParsedClusterName)
  53. END
  54. INSERT INTO TSSD_Servers (ServerAddress, ClusterID, AlmostInTimeLow,
  55. AlmostInTimeHigh) VALUES (@ServerAddress, @ClusterID, 0, 0)
  56. -- Generate the return recordset.
  57. SELECT ServerID, @ClusterID FROM TSSD_Servers WHERE
  58. ServerAddress = @ServerAddress
  59. -- Finished the update.
  60. COMMIT TRANSACTION
  61. GO
  62. /****************************************************************************/
  63. -- SP_TSSDServerOffline
  64. --
  65. -- Called by TSSDSQL to indicate a server is going offline in a graceful
  66. -- fashion. Removes all remaining entries related to this server.
  67. /****************************************************************************/
  68. IF EXISTS (SELECT name FROM sysobjects
  69. WHERE name = 'SP_TSSDServerOffline' and type = 'P')
  70. DROP PROCEDURE SP_TSSDServerOffline
  71. GO
  72. CREATE PROCEDURE SP_TSSDServerOffline
  73. @ServerID int
  74. AS
  75. -- Turn off intermediate returns to the client. Needed to help ADO
  76. -- return a valid final recordset, plus reduces round-trips on network.
  77. SET NOCOUNT ON
  78. -- We need to perform some locking on the tables to make sure
  79. -- of the data integrity. We are assuming default isolation level
  80. -- of Read Committed.
  81. BEGIN TRANSACTION
  82. DELETE FROM TSSD_Sessions WHERE ServerID = @ServerID
  83. DELETE FROM TSSD_Servers WHERE ServerID = @ServerID
  84. -- Finished the update.
  85. COMMIT TRANSACTION
  86. GO
  87. /****************************************************************************/
  88. -- SP_TSSDGetUserDisconnectedSessions
  89. --
  90. -- Called by the TSSDSQL directory provider to return a recordset
  91. -- containing the info needed to populate the disconnected session info
  92. -- blocks.
  93. /****************************************************************************/
  94. IF EXISTS (SELECT name FROM sysobjects
  95. WHERE name = 'SP_TSSDGetUserDisconnectedSessions' and type = 'P')
  96. DROP PROCEDURE SP_TSSDGetUserDisconnectedSessions
  97. GO
  98. CREATE PROCEDURE SP_TSSDGetUserDisconnectedSessions
  99. @UserName nvarchar(255),
  100. @Domain nvarchar(127),
  101. @ClusterID int
  102. AS
  103. -- Turn off intermediate returns to the client. Needed to help ADO
  104. -- return a valid final recordset, plus reduces round-trips on network.
  105. SET NOCOUNT ON
  106. -- We need to perform some locking on the tables to make sure
  107. -- of the data integrity. We are assuming default isolation level
  108. -- of Read Committed.
  109. BEGIN TRANSACTION
  110. -- Create the result set with the fields from the (only) user record.
  111. SELECT ServerAddress, SessionID, TSProtocol, CreateTimeLow,
  112. CreateTimeHigh, DisconnectionTimeLow, DisconnectionTimeHigh,
  113. ApplicationType, ResolutionWidth, ResolutionHeight,
  114. ColorDepth
  115. FROM TSSD_Sessions JOIN TSSD_Servers
  116. ON (TSSD_Sessions.ServerID = TSSD_Servers.ServerID)
  117. WHERE UserName = @UserName AND Domain = @Domain AND State = 1 AND
  118. ClusterID = @ClusterID
  119. -- Finished the update.
  120. COMMIT TRANSACTION
  121. GO
  122. /****************************************************************************/
  123. -- SP_TSSDCreateSession
  124. --
  125. -- Adds a session record to the system.
  126. /****************************************************************************/
  127. IF EXISTS (SELECT name FROM sysobjects
  128. WHERE name = 'SP_TSSDCreateSession' and type = 'P')
  129. DROP PROCEDURE SP_TSSDCreateSession
  130. GO
  131. CREATE PROCEDURE SP_TSSDCreateSession
  132. @UserName nvarchar(255),
  133. @Domain nvarchar(127),
  134. @ServerID int,
  135. @SessionID int,
  136. @TSProtocol int,
  137. @AppType nvarchar(255),
  138. @ResolutionWidth int,
  139. @ResolutionHeight int,
  140. @ColorDepth int,
  141. @CreateTimeLow int,
  142. @CreateTimeHigh int
  143. AS
  144. -- Turn off intermediate returns to the client. Needed to help ADO
  145. -- return a valid recordset, plus reduces round-trips on network.
  146. SET NOCOUNT ON
  147. -- We need to perform some locking on the tables to make sure
  148. -- of the data integrity. We are assuming default isolation level
  149. -- of Read Committed.
  150. BEGIN TRANSACTION
  151. -- If this ServerName/SessionID combo already exists in the table,
  152. -- remove it.
  153. DELETE FROM TSSD_Sessions WHERE ServerID = @ServerID AND
  154. SessionID = @SessionID
  155. -- Add the session.
  156. INSERT TSSD_Sessions (UserName, Domain, ServerID,
  157. SessionID, TSProtocol, CreateTimeLow,
  158. CreateTimeHigh, ApplicationType, ResolutionWidth, ResolutionHeight,
  159. ColorDepth)
  160. VALUES (@UserName, @Domain, @ServerID, @SessionID,
  161. @TSProtocol, @CreateTimeLow, @CreateTimeHigh, @AppType,
  162. @ResolutionWidth, @ResolutionHeight, @ColorDepth)
  163. -- Finished the update.
  164. COMMIT TRANSACTION
  165. GO
  166. /****************************************************************************/
  167. -- SP_TSSDDeleteSession
  168. --
  169. -- Removes a session from the database.
  170. /****************************************************************************/
  171. IF EXISTS (SELECT name FROM sysobjects
  172. WHERE name = 'SP_TSSDDeleteSession' and type = 'P')
  173. DROP PROCEDURE SP_TSSDDeleteSession
  174. GO
  175. CREATE PROCEDURE SP_TSSDDeleteSession
  176. @ServerID int,
  177. @SessionID int
  178. AS
  179. BEGIN TRANSACTION
  180. DELETE FROM TSSD_Sessions WHERE ServerID = @ServerID AND
  181. SessionID = @SessionID
  182. COMMIT TRANSACTION
  183. GO
  184. /****************************************************************************/
  185. -- SP_TSSDSetSessionDisconnected
  186. --
  187. -- Changes the session to disconnected and sets the disconnection time.
  188. /****************************************************************************/
  189. IF EXISTS (SELECT name FROM sysobjects
  190. WHERE name = 'SP_TSSDSetSessionDisconnected' and type = 'P')
  191. DROP PROCEDURE SP_TSSDSetSessionDisconnected
  192. GO
  193. CREATE PROCEDURE SP_TSSDSetSessionDisconnected
  194. @ServerID int,
  195. @SessionID int,
  196. @DiscTimeLow int,
  197. @DisctimeHigh int
  198. AS
  199. BEGIN TRANSACTION
  200. UPDATE TSSD_Sessions SET State = 1, DisconnectionTimeLow = @DiscTimeLow,
  201. DisconnectionTimeHigh = @DiscTimeHigh
  202. WHERE ServerID = @ServerID AND SessionID = @SessionID
  203. COMMIT TRANSACTION
  204. GO
  205. /****************************************************************************/
  206. -- SP_TSSDSetSessionReconnected
  207. --
  208. -- Changes the session to connected and updates the fields that can change on
  209. -- reconnection.
  210. /****************************************************************************/
  211. IF EXISTS (SELECT name FROM sysobjects
  212. WHERE name = 'SP_TSSDSetSessionReconnected' and type = 'P')
  213. DROP PROCEDURE SP_TSSDSetSessionReconnected
  214. GO
  215. CREATE PROCEDURE SP_TSSDSetSessionReconnected
  216. @ServerID int,
  217. @SessionID int,
  218. @TSProtocol int,
  219. @ResWidth int,
  220. @ResHeight int,
  221. @ColorDepth int
  222. AS
  223. BEGIN TRANSACTION
  224. UPDATE TSSD_Sessions SET State = 0, TSProtocol = @TSProtocol,
  225. ResolutionWidth = @ResWidth, ResolutionHeight = @ResHeight,
  226. ColorDepth = @ColorDepth
  227. WHERE ServerID = @ServerID AND SessionID = @SessionID
  228. UPDATE TSSD_Servers SET AlmostInTimeLow = 0, AlmostInTimeHigh = 0
  229. WHERE ServerID = @ServerID
  230. COMMIT TRANSACTION
  231. GO
  232. /****************************************************************************/
  233. -- SP_TSSDSetServerReconnectPending
  234. --
  235. -- If the specified server has 0's in its Almost-In-Time values, add the
  236. -- timestamp passed in. Used by Directory Integrity Service
  237. /****************************************************************************/
  238. IF EXISTS (SELECT name FROM sysobjects
  239. WHERE name = 'SP_TSSDSetServerReconnectPending' and type = 'P')
  240. DROP PROCEDURE SP_TSSDSetServerReconnectPending
  241. GO
  242. CREATE PROCEDURE SP_TSSDSetServerReconnectPending
  243. @ServerAddress nvarchar(63),
  244. @AlmostTimeLow int,
  245. @AlmostTimeHigh int
  246. AS
  247. DECLARE @ServerID int
  248. BEGIN TRANSACTION
  249. SET @ServerID = (SELECT MIN(ServerID) FROM TSSD_Servers
  250. WHERE ServerAddress = @ServerAddress)
  251. UPDATE TSSD_Servers SET AlmostInTimeLow = @AlmostTimeLow,
  252. AlmostInTimeHigh = @AlmostTimeHigh
  253. WHERE ServerID = @ServerID AND AlmostInTimeLow = 0 AND
  254. AlmostInTimeHigh = 0
  255. COMMIT TRANSACTION
  256. GO