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.

186 lines
4.7 KiB

  1. <%' CODEPAGE=65001 'UTF-8%>
  2. <%' certsrck.inc - (CERT)srv web - (S)cript: (R)equest-(C)ooc(K)ie management
  3. ' Copyright (C) Microsoft Corporation, 1998 - 1999 %>
  4. <%
  5. ' Format of our cookie:
  6. ' '[' <ReqID> ',' <TargetStoreFlags> ',' <SaveCert> ',' <FriendlyType> ']'...
  7. Const FIELD_REQID=0
  8. Const FIELD_TARGETSTOREFLAGS=1
  9. Const FIELD_SAVECERT=2
  10. Const FIELD_FRIENDLYTYPE=3
  11. Const NUM_FIELDS=4
  12. Const REQUEST_COOKIE_NAME="Requests"
  13. Dim nReqId
  14. ' Look up the requests in the cookie, and return an array of 'request' arrays
  15. Function GetRequests()
  16. ' Get the cookie
  17. Dim sRequests
  18. sRequests=Request.Cookies(REQUEST_COOKIE_NAME)
  19. ' If the cookie was never set, return an empty array
  20. If ""=sRequests Then
  21. GetRequests=Null
  22. Exit Function
  23. End If
  24. Dim nRequests
  25. Dim rgRequests()
  26. nRequests=0
  27. ' Loop through all the requests in the string
  28. Dim nSplitIndex
  29. Do
  30. ' Find the next request
  31. nSplitIndex=InStr(sRequests,"]")
  32. If 0=nSplitIndex Then
  33. Exit Do
  34. End If
  35. ' Split this Request off the string
  36. Dim sElem
  37. sElem=Mid(sRequests, 2, nSplitIndex-2)
  38. sRequests=Mid(sRequests, nSplitIndex+1)
  39. ' Spit this request apart
  40. Dim rgElem
  41. rgElem=Split(sElem, ",")
  42. ' Safety check
  43. If NUM_FIELDS-1<>UBound(rgElem) Then
  44. ' Cookie is corrupt
  45. nRequests=0
  46. Exit Do
  47. End If
  48. ' Add this array to our array of requests
  49. ReDim Preserve rgRequests(nRequests)
  50. rgRequests(nRequests)=rgElem
  51. nRequests=nRequests+1
  52. ' safety check for testing
  53. 'If nRequests>25 Then
  54. ' Err.Raise 6
  55. 'End If
  56. Loop ' End string-parsing loop
  57. ' if there was an error parsing the cookie, just assume it was empty.
  58. If 0=nRequests Then
  59. GetRequests=Null
  60. Else
  61. GetRequests=rgRequests
  62. End If
  63. End Function
  64. ' Combine a requests-array into a single string and set it as a cookie
  65. Sub PutRequests(rgRequests)
  66. Dim sCookie, sRequests, nIndex
  67. sRequests=""
  68. ' check for the empty list
  69. If IsNull(rgRequests) Then
  70. ' the list is empty
  71. ' do nothing
  72. sRequests="-" ' Lynx won't set an empty cookie, so set an invalid one
  73. Else
  74. ' the list is not empty
  75. ' build a string for each request and concatenate to make cookie
  76. For nIndex=0 To UBound(rgRequests)
  77. sRequests=sRequests & "[" & _
  78. rgRequests(nIndex)(FIELD_REQID) & "," & _
  79. rgRequests(nIndex)(FIELD_TARGETSTOREFLAGS) & "," & _
  80. rgRequests(nIndex)(FIELD_SAVECERT) & "," & _
  81. rgRequests(nIndex)(FIELD_FRIENDLYTYPE) & "]"
  82. Next
  83. End If
  84. ' Set the cookie
  85. Response.Cookies(REQUEST_COOKIE_NAME)=sRequests
  86. ' Set the expiration date
  87. Response.Cookies(REQUEST_COOKIE_NAME).Expires=Now+nPendingTimeoutDays
  88. ' Set the path
  89. Response.Cookies(REQUEST_COOKIE_NAME).Path="/certsrv"
  90. End Sub
  91. ' Remove a given request from the requests cookie
  92. Sub RemoveReq(nReqID)
  93. ' get the array of requests
  94. Dim rgRequests
  95. rgRequests=GetRequests()
  96. ' if the cookie is empty, just ignore
  97. If IsNull(rgRequests) Then
  98. Exit Sub
  99. End If
  100. ' find the request
  101. Dim nIndex
  102. Dim nFoundIndex
  103. nFoundIndex=-1
  104. For nIndex=0 To UBound(rgRequests)
  105. If nReqID=rgRequests(nIndex)(FIELD_REQID) Then
  106. nFoundIndex=nIndex
  107. Exit For
  108. End If
  109. Next
  110. If -1=nFoundIndex Then
  111. ' request not found, probably a reload and it was deleted already
  112. ' do nothing
  113. Else
  114. ' remove the request:
  115. If 0=UBound(rgRequests) Then
  116. ' this is the last request
  117. ' removing it leaves an empty list
  118. rgRequests=Null
  119. Else
  120. ' Not the last request, so shuffle down
  121. ' (this is not the most efficient, but it keeps the requests in order)
  122. For nIndex=nFoundIndex To UBound(rgRequests)-1
  123. rgRequests(nIndex)=rgRequests(nIndex+1)
  124. Next
  125. ' shrink the array
  126. ReDim Preserve rgRequests(UBound(rgRequests)-1)
  127. End If
  128. ' set the cookie
  129. PutRequests rgRequests
  130. End If
  131. End Sub
  132. ' Add the current request to the request cookie
  133. Sub AddRequest
  134. ' build a request object for this request
  135. Dim rgNewReq(3) 'NUM_FIELDS-1
  136. nReqId=ICertRequest.GetRequestId()
  137. rgNewReq(FIELD_REQID)=nReqId
  138. rgNewReq(FIELD_TARGETSTOREFLAGS)=Request.Form("TargetStoreFlags")
  139. rgNewReq(FIELD_SAVECERT)=Request.Form("SaveCert")
  140. rgNewReq(FIELD_FRIENDLYTYPE)=Request.Form("FriendlyType")
  141. ' prevent special split characters from being placed in the string
  142. ' by converting them to spaces
  143. rgNewReq(FIELD_FRIENDLYTYPE)=Replace(rgNewReq(FIELD_FRIENDLYTYPE), ",", " ")
  144. rgNewReq(FIELD_FRIENDLYTYPE)=Replace(rgNewReq(FIELD_FRIENDLYTYPE), "]", " ")
  145. ' add it to the list
  146. Dim rgRequests
  147. rgRequests=GetRequests()
  148. If IsNull(rgRequests) Then
  149. ' cookie has never been set
  150. ReDim rgRequests(0)
  151. Else
  152. ' save old requests in cookie
  153. ReDim Preserve rgRequests(UBound(rgRequests)+1)
  154. End If
  155. rgRequests(UBound(rgRequests))=rgNewReq
  156. PutRequests rgRequests
  157. End Sub
  158. %>