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.

146 lines
3.6 KiB

  1. package cookie;
  2. use strict;
  3. use lib $ENV{RAZZLETOOLPATH};
  4. use Win32::Event;
  5. use Win32::IPC;
  6. use Logmsg;
  7. # declare globals for this package
  8. my( $LogFile, $ScriptName, $Ext );
  9. $LogFile = $ENV{ "LOGFILE" };
  10. unless ( defined( $LogFile ) ) {
  11. $0 =~ /(.*)\.(.*?)$/;
  12. $ScriptName = $1;
  13. $Ext = "\L$2";
  14. if ( $Ext ne "log" ) { $LogFile = $ScriptName . ".log"; }
  15. else { $LogFile = $ScriptName . ".logfile"; }
  16. }
  17. return( 1 );
  18. #
  19. # CreateCookie( $CookieName )
  20. #
  21. # this routine will firstly query to make sure an event with the requested name
  22. # does not yet exist. if it doesn't, it attempts to create an event. upon
  23. # failure of either of these tasks, we log an error and return undef. upon
  24. # success, we return the event created.
  25. #
  26. sub CreateCookie
  27. {
  28. # get passed args
  29. my( $CookieName ) = @_;
  30. # declare locals
  31. my( $Event );
  32. # check to make sure we don't already have a cookie with this name
  33. if ( &QueryCookie( $CookieName ) ) {
  34. errmsg( "A cookie with name '$CookieName' already exists.",
  35. $LogFile );
  36. return( undef );
  37. }
  38. $Event = Win32::Event->new( "TRUE", undef, $CookieName );
  39. unless ( defined( $Event ) ) {
  40. errmsg( "Failed to create cookie '$CookieName'.", $LogFile );
  41. return( undef );
  42. }
  43. # at this point, we've created our cookie.
  44. # just return the cookie name.
  45. return( $Event );
  46. }
  47. #
  48. # QueryCookie( $CookieName )
  49. #
  50. # this routine will simply query to see if a cookie with the given name already
  51. # exists. if so, we return the event. if not, we return undef.
  52. #
  53. sub QueryCookie
  54. {
  55. # get passed args
  56. my( $CookieName ) = @_;
  57. # declare locals
  58. my( $Event );
  59. $Event = Win32::Event->open( $CookieName );
  60. # at this point, if event is defined, we created the cookie. if not, we
  61. # didn't. so event is what we want to return.
  62. return( $Event );
  63. }
  64. #
  65. # KillCookie( $CookieName, $ForceKill )
  66. #
  67. # BUGBUG
  68. # perl does not support a kill for events! thus, we can't really kill an
  69. # event using the Win32::Event module. so instead, we just return undef.
  70. #
  71. # this routine will kill the cookie with the given name. if the $ForceKill
  72. # parameter is true (non-undef), it will not report errors attempting to kill
  73. # the cookie. if the kill succeeds, we return the cookie name, otherwise undef.
  74. #
  75. sub KillCookie
  76. {
  77. # get passed args
  78. my( $CookieName, $ForceKill ) = @_;
  79. # declare locals
  80. my( $ReturnCode );
  81. # BUGBUG
  82. # perl doesn't support a kill for events, so just return for now.
  83. return( undef );
  84. # close the event
  85. $ReturnCode = Win32::Event->close( $CookieName );
  86. if ( $ReturnCode != 0 ) {
  87. if ( ! ( defined( $ForceKill ) ) ) {
  88. errmsg( "Failed to kill cookie '$CookieName'.",
  89. $LogFile );
  90. }
  91. return( undef );
  92. }
  93. # we successfully killed the cookie, return the cookie name.
  94. return( $CookieName );
  95. }
  96. #
  97. # CreateCookieQuiet( $CookieName )
  98. #
  99. # this routine will firstly query to make sure an event with the requested name
  100. # does not yet exist. if it doesn't, it attempts to create an event. upon
  101. # failure of either of these tasks, we log an error and return undef. upon
  102. # success, we return the event created.
  103. #
  104. # this routine differs from CreateCookie in that it will not attempt any
  105. # logging.
  106. #
  107. sub CreateCookieQuiet
  108. {
  109. # get passed args
  110. my( $CookieName ) = @_;
  111. # declare locals
  112. my( $Event );
  113. # check to make sure we don't already have a cookie with this name
  114. if ( &QueryCookie( $CookieName ) ) {return( undef ); }
  115. $Event = Win32::Event->new( "TRUE", undef, $CookieName );
  116. unless ( defined( $Event ) ) {return( undef ); }
  117. # at this point, we've created our cookie.
  118. # just return the cookie name.
  119. return( $Event );
  120. }