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.

176 lines
4.8 KiB

  1. use Strict;
  2. use HTTP::Daemon;
  3. use HTTP::Headers;
  4. use HTTP::Response;
  5. my $d = HTTP::Daemon->new( Listen => 10, LocalPort => 8080 ) || die;
  6. print "Please contact me at: <URL:", $d->url, ">\n";
  7. while (my $c = $d->accept) {
  8. while (my $r = $c->get_request) {
  9. print "\n";
  10. handleGET($r, $c) if ($r->method eq 'GET');
  11. handleHEAD($r, $c) if ($r->method eq 'HEAD');
  12. handleBITS_POST($r, $c) if ($r->method eq 'BITS_POST');
  13. }
  14. $c->close;
  15. undef($c);
  16. }
  17. sub handleBITS_POST {
  18. my ($req, $conn) = @_;
  19. #
  20. # interpret request
  21. #
  22. print "BITS_POST request =================================\n";
  23. print $req->headers()->as_string();
  24. handleCreateSession( $req, $conn ) if ($req->header('Bits-Packet-Type') eq 'Create-Session');
  25. handlePing( $req, $conn ) if ($req->header('Bits-Packet-Type') eq 'Ping');
  26. handleFragment( $req, $conn ) if ($req->header('Bits-Packet-Type') eq 'Fragment');
  27. handleCancelSession( $req, $conn ) if ($req->header('Bits-Packet-Type') eq 'Cancel-Session');
  28. handleCloseSession( $req, $conn ) if ($req->header('Bits-Packet-Type') eq 'Close-Session');
  29. print "end of request -----------------------------------------\n";
  30. }
  31. sub handleCreateSession {
  32. my ($req, $conn) = @_;
  33. #
  34. # generate reply
  35. #
  36. my $response = new HTTP::Response;
  37. $response->protocol('HTTP/1.1');
  38. $response->code(200);
  39. $response->header("Bits-Packet-Type" => 'Ack' );
  40. $response->header("Bits-Protocol" => '{7df0354d-249b-430f-820d-3d2a9bef4931}' );
  41. $response->header("Bits-Session-Id" => '{78d08036-4166-4bb2-b1fb-ac7288355913}' );
  42. $response->header("Content-Length" => 0 );
  43. # $response->header("Bits-Host-Id" => '157.59.246.44' );
  44. # $response->header("Bits-Host-Id-fallback-timeout" => '240' );
  45. print "create-session reply =================================\n";
  46. print $response->as_string();
  47. $conn->send_response($response);
  48. }
  49. sub handlePing {
  50. my ($req, $conn) = @_;
  51. my $sessionid = $req->header('Bits-Session-Id');
  52. #
  53. # generate reply
  54. #
  55. my $response = new HTTP::Response;
  56. $response->protocol('HTTP/1.1');
  57. $response->code(200);
  58. $response->header("Bits-Packet-Type" => 'Ack' );
  59. $response->header("Bits-Session-Id" => $sessionid );
  60. $response->header("Content-Length" => 0 );
  61. print "ping reply =================================\n";
  62. print $response->as_string();
  63. $conn->send_response($response);
  64. }
  65. sub handleFragment {
  66. my ($req, $conn) = @_;
  67. my $sessionid = $req->header('Bits-Session-Id');
  68. my $file_length;
  69. my $end_offset;
  70. my $start_offset;
  71. # parse the incoming range
  72. #
  73. $_ = $req->header('Content-Range');
  74. ( $start_offset, $end_offset, $file_length ) = /bytes (\d+)\-(\d+)\/(\d+)/;
  75. #
  76. # generate reply
  77. #
  78. my $response = new HTTP::Response;
  79. $response->protocol('HTTP/1.1');
  80. $response->header("Bits-Packet-Type" => 'Ack' );
  81. $response->header("Bits-Session-Id" => $sessionid );
  82. $response->header("BITS-Received-Content-Range" => $end_offset+1 );
  83. $response->header("Content-Length" => 0 );
  84. #
  85. # success
  86. #
  87. $response->code(200);
  88. # $response->header("Bits-Error" => '0x555' );
  89. # $response->header("Bits-Error-Context" => '0x7' );
  90. if ($end_offset+1 eq $file_length) {
  91. $response->header("Bits-Reply-Url" => '/foo' );
  92. }
  93. print "fragment reply =================================\n";
  94. print $response->as_string();
  95. $conn->send_response($response);
  96. }
  97. sub handleHEAD {
  98. print "HEAD request\n";
  99. }
  100. sub handleGET {
  101. print "GET request\n";
  102. }
  103. sub handleCloseSession {
  104. my ($req, $conn) = @_;
  105. my $sessionid = $req->header('Bits-Session-Id');
  106. #
  107. # generate reply
  108. #
  109. my $response = new HTTP::Response;
  110. $response->protocol('HTTP/1.1');
  111. $response->code(200);
  112. $response->header("Bits-Packet-Type" => 'Ack' );
  113. $response->header("Bits-Session-Id" => $sessionid );
  114. $response->header("Content-Length" => 0 );
  115. print "close reply =================================\n";
  116. print $response->as_string();
  117. $conn->send_response($response);
  118. }
  119. sub handleCancelSession {
  120. my ($req, $conn) = @_;
  121. my $sessionid = $req->header('Bits-Session-Id');
  122. #
  123. # generate reply
  124. #
  125. my $response = new HTTP::Response;
  126. $response->protocol('HTTP/1.1');
  127. $response->code(200);
  128. $response->header("Bits-Packet-Type" => 'Ack' );
  129. $response->header("Bits-Session-Id" => $sessionid );
  130. $response->header("Content-Length" => 0 );
  131. print "cancel reply =================================\n";
  132. print $response->as_string();
  133. $conn->send_response($response);
  134. }