2017-10-06 17:20:58 +02:00
// Decompiled with JetBrains decompiler
// Type: CarotDAV.DAVServer
// Assembly: CarotDAV, Version=1.13.2.18337, Culture=neutral, PublicKeyToken=null
// MVID: C31F2651-A4A8-4D09-916A-8C6106F5E7C8
// Assembly location: F:\Eigene Dateien\Dropbox\portable Collection\Progs\CarotDAV\CarotDAV.exe
using Microsoft.VisualBasic.CompilerServices ;
using Rei.Fs ;
using Rei.Net.HttpServer ;
using System ;
using System.Collections ;
using System.Collections.Generic ;
using System.ComponentModel ;
using System.Diagnostics ;
using System.Globalization ;
using System.IO ;
using System.Net ;
using System.Reflection ;
using System.Runtime.CompilerServices ;
using System.Security ;
using System.Text ;
using System.Threading ;
using System.Windows.Forms ;
using System.Xml ;
namespace CarotDAV
{
public class DAVServer : Component
{
private IContainer components ;
private Thread serverthread ;
private MyHttpListener davserver ;
private string _ServerName ;
private int _port ;
private string _ipaddress ;
private WebDAVClientSetting _setting ;
internal const string GroupNameMain = "DAVServer" ;
public Dictionary < string , string > LockDB ;
[DebuggerNonUserCode]
public DAVServer ( IContainer container )
: this ( )
{
if ( container = = null )
return ;
container . Add ( ( IComponent ) this ) ;
}
[DebuggerNonUserCode]
protected override void Dispose ( bool disposing )
{
try
{
if ( ! disposing | | this . components = = null )
return ;
this . components . Dispose ( ) ;
}
finally
{
base . Dispose ( disposing ) ;
}
}
[DebuggerStepThrough]
private void InitializeComponent ( )
{
this . components = ( IContainer ) new System . ComponentModel . Container ( ) ;
}
public event EventHandler < LogMessageEventArgs > LogMessage ;
public string IpAddress
{
get
{
return this . _ipaddress ;
}
set
{
this . _ipaddress = value ;
}
}
[DefaultValue(80)]
public int ServerPort
{
get
{
return this . _port ;
}
set
{
this . _port = value ;
}
}
public string DavUNC
{
get
{
IPAddress ipAddress = ! string . IsNullOrEmpty ( this . _ipaddress . Trim ( ) ) ? IPAddress . Parse ( this . _ipaddress . Trim ( ) ) : IPAddress . Loopback ;
string str1 = ipAddress . ToString ( ) ;
if ( ipAddress . Equals ( ( object ) IPAddress . Any ) | | ipAddress . Equals ( ( object ) IPAddress . IPv6Any ) )
str1 = "localhost" ;
string str2 = "@" + this . _port . ToString ( ) ;
if ( this . _port = = 80 )
str2 = "" ;
return "\\\\" + str1 + str2 + "\\DavWWWRoot" ;
}
}
public bool IsRunning
{
get
{
return this . serverthread ! = null ;
}
}
[DefaultValue("DAVServer")]
public string ServerName
{
get
{
return this . _ServerName ;
}
set
{
this . _ServerName = value ;
}
}
public WebDAVClientSetting Setting
{
get
{
return this . _setting ;
}
set
{
this . _setting = value ;
}
}
[DebuggerNonUserCode]
public DAVServer ( )
{
this . LockDB = new Dictionary < string , string > ( ) ;
this . InitializeComponent ( ) ;
}
public void Start ( )
{
this . davserver = new MyHttpListener ( ) ;
this . davserver . EndPoint = new IPEndPoint ( ! string . IsNullOrEmpty ( this . _ipaddress . Trim ( ) ) ? IPAddress . Parse ( this . _ipaddress . Trim ( ) ) : IPAddress . Loopback , this . _port ) ;
Assembly executingAssembly = Assembly . GetExecutingAssembly ( ) ;
this . davserver . ServerName = ( ( AssemblyProductAttribute ) executingAssembly . GetCustomAttributes ( typeof ( AssemblyProductAttribute ) , false ) [ 0 ] ) . Product + executingAssembly . GetName ( ) . Version . ToString ( 3 ) ;
this . davserver . Start ( ) ;
this . serverthread = new Thread ( new ThreadStart ( this . DavServerThreadMain ) ) ;
this . serverthread . IsBackground = true ;
this . serverthread . Start ( ) ;
}
public void Stop ( )
{
this . serverthread . Abort ( ) ;
this . serverthread = ( Thread ) null ;
}
private void DavServerThreadMain ( )
{
try
{
while ( true )
new Thread ( new ParameterizedThreadStart ( this . ConnectionThreadMain ) )
{
IsBackground = true
} . Start ( ( object ) this . davserver . GetConnection ( ) ) ;
}
catch ( Exception ex )
{
ProjectData . SetProjectError ( ex ) ;
ProjectData . ClearProjectError ( ) ;
}
finally
{
this . davserver . Stop ( ) ;
this . davserver . Close ( ) ;
}
}
private void ConnectionThreadMain ( object obj )
{
try
{
using ( MyHttpServerConnection con = ( MyHttpServerConnection ) obj )
{
con . Tag = ( object ) new DAVServer . ConnectionCache ( ) ;
while ( con . IsConnected )
{
try
{
using ( MyHttpServerRequest request = con . ReceiveRequest ( ) )
{
this . OnLogMessage ( ")" + request . RequestLine ) ;
int num1 = 0 ;
int num2 = checked ( request . Headers . Count - 1 ) ;
int index = num1 ;
while ( index < = num2 )
{
this . OnLogMessage ( ") " + request . Headers . Keys [ index ] + ": " + request . Headers [ index ] ) ;
checked { + + index ; }
}
this . OnLogMessage ( ")" ) ;
if ( Operators . CompareString ( request . UserAgent , "Microsoft Data Access Internet Publishing Provider DAV 1.1" , false ) = = 0 )
request . RequestUri = UriUtil . UriEncodeConvert ( request . RequestUri , Encoding . GetEncoding ( "SJIS" ) , Encoding . UTF8 ) ;
MyHttpServerResponse res = new MyHttpServerResponse ( ) ;
string upperInvariant = request . Method . ToUpperInvariant ( ) ;
if ( Operators . CompareString ( upperInvariant , "OPTIONS" , false ) = = 0 )
{
res . StatusCode = 200 ;
res . StatusDescription = "OK" ;
res . Headers . Add ( "DAV" , "1, 3" ) ;
res . Headers . Add ( "Allow" , "OPTIONS, PROPFIND, PROPPATCH, GET, HEAD, PUT, DELETE, MKCOL" ) ;
res . ContentLength = 0L ;
using ( this . SendResponse ( con , res ) )
;
}
else if ( Operators . CompareString ( upperInvariant , "PROPFIND" , false ) = = 0 )
this . ProcessPROPFIND ( con , request ) ;
else if ( Operators . CompareString ( upperInvariant , "PROPPATCH" , false ) = = 0 )
this . ProcessPROPPATCH ( con , request ) ;
else if ( Operators . CompareString ( upperInvariant , "GET" , false ) = = 0 )
this . ProcessGETHEAD ( con , request , true ) ;
else if ( Operators . CompareString ( upperInvariant , "HEAD" , false ) = = 0 )
this . ProcessGETHEAD ( con , request , false ) ;
else if ( Operators . CompareString ( upperInvariant , "DELETE" , false ) = = 0 )
this . ProcessDELETE ( con , request ) ;
else if ( Operators . CompareString ( upperInvariant , "PUT" , false ) = = 0 )
this . ProcessPUT ( con , request ) ;
else if ( Operators . CompareString ( upperInvariant , "MKCOL" , false ) = = 0 )
this . ProcessMKCOL ( con , request ) ;
else if ( Operators . CompareString ( upperInvariant , "MOVE" , false ) = = 0 )
this . ProcessMOVE ( con , request ) ;
else if ( Operators . CompareString ( upperInvariant , "LOCK" , false ) = = 0 )
{
string end ;
using ( StreamReader streamReader = new StreamReader ( request . InputStream ) )
end = streamReader . ReadToEnd ( ) ;
this . OnLogMessage ( ")))" ) ;
this . OnLogMessage ( end ) ;
this . OnLogMessage ( ")))" ) ;
string str = ( string ) null ;
if ( request . Headers [ "If" ] ! = null )
{
string header = request . Headers [ "If" ] ;
if ( header . Length = = 49 & & header . StartsWith ( "(<urn:uuid:" ) & & header . EndsWith ( ">)" ) )
str = header . Substring ( 2 , 45 ) ;
}
if ( str = = null )
str = "urn:uuid:" + Guid . NewGuid ( ) . ToString ( ) ;
Uri baseUri = request . RequestUri ;
if ( baseUri . AbsolutePath . Contains ( "&" ) )
baseUri = new Uri ( baseUri , baseUri . AbsolutePath . Replace ( "&" , "%26" ) ) ;
res . StatusCode = 200 ;
res . StatusDescription = "OK" ;
res . Headers . Add ( "Lock-Token" , "<" + str + ">" ) ;
byte [ ] bytes = Encoding . UTF8 . GetBytes ( "<?xml version=\"1.0\" encoding=\"utf-8\" ?><D:prop xmlns:D=\"DAV:\"><D:lockdiscovery><D:activelock><D:lockscope><D:exclusive/></D:lockscope><D:locktype><D:write/></D:locktype><D:depth>0</D:depth><D:locktoken><D:href>" + str + "</D:href></D:locktoken><D:lockroot><D:href>" + baseUri . AbsoluteUri + "</D:href></D:lockroot><D:timeout>Second-3600</D:timeout></D:activelock></D:lockdiscovery></D:prop>" ) ;
res . ContentLength = ( long ) bytes . Length ;
using ( Stream stream = this . SendResponse ( con , res ) )
stream . Write ( bytes , 0 , bytes . Length ) ;
}
else if ( Operators . CompareString ( upperInvariant , "UNLOCK" , false ) = = 0 )
{
res . StatusCode = 204 ;
res . StatusDescription = "No Content" ;
using ( this . SendResponse ( con , res ) )
;
}
else if ( Operators . CompareString ( upperInvariant , "POST" , false ) = = 0 )
{
res . StatusCode = 404 ;
res . StatusDescription = "Not Found" ;
using ( this . SendResponse ( con , res ) )
;
}
else
{
res . StatusCode = 501 ;
res . StatusDescription = "Not Implemented" ;
using ( this . SendResponse ( con , res ) )
;
}
}
}
catch ( MyHttpServerBadRequestException ex )
{
ProjectData . SetProjectError ( ( Exception ) ex ) ;
using ( this . SendResponse ( con , new MyHttpServerResponse ( )
{
StatusCode = 500 ,
StatusDescription = "Bad Request"
} ) )
;
ProjectData . ClearProjectError ( ) ;
break ;
}
catch ( MyHttpServerConnectionClosedException ex )
{
ProjectData . SetProjectError ( ( Exception ) ex ) ;
ProjectData . ClearProjectError ( ) ;
break ;
}
}
}
}
catch ( Exception ex )
{
ProjectData . SetProjectError ( ex ) ;
ProjectData . ClearProjectError ( ) ;
}
}
private void ProcessPROPFIND ( MyHttpServerConnection con , MyHttpServerRequest req )
{
MyHttpServerResponse res = new MyHttpServerResponse ( ) ;
if ( ( object ) req . RequestUri ! = null )
{
string [ ] segments = req . RequestUri . Segments ;
if ( segments . Length > 2 & & ( Operators . CompareString ( segments [ 1 ] , "DavWWWRoot/" , false ) = = 0 | | Operators . CompareString ( segments [ 1 ] , "DavWWWRoot" , false ) = = 0 ) )
Array . Copy ( ( Array ) segments , 2 , ( Array ) segments , 1 , checked ( segments . Length - 2 ) ) ;
int result = - 1 ;
if ( req . Headers [ "Depth" ] ! = null )
int . TryParse ( req . Headers [ "Depth" ] , out result ) ;
if ( result < 0 | | result > 2 )
result = 1 ;
string str1 = "<?xml version=\"1.0\" encoding=\"utf-8\" ?><D:multistatus xmlns:D=\"DAV:\" xmlns:M=\"urn:schemas-microsoft-com:\">" ;
if ( segments . Length < = 1 )
{
str1 = str1 + "<D:response><D:href>" + SecurityElement . Escape ( UriUtil . AddLastSlash ( req . RequestUri ) . AbsoluteUri ) + "</D:href>" + "<D:propstat><D:prop>" + "<D:resourcetype><D:collection/></D:resourcetype>" + "<M:Win32FileAttributes>00000011</M:Win32FileAttributes>" + "</D:prop><D:status>HTTP/1.1 200 OK</D:status>" + "</D:propstat>" + "</D:response>" ;
if ( result > = 1 )
{
int num1 = 0 ;
int num2 = checked ( this . _setting . ConnectionSettings . Count - 1 ) ;
int index = num1 ;
while ( index < = num2 )
{
str1 = str1 + "<D:response><D:href>" + SecurityElement . Escape ( UriUtil . AddLastSlash ( UriUtil . CombineName ( req . RequestUri , this . SanitizeName ( this . _setting . ConnectionSettings [ index ] . Name ) ) ) . AbsoluteUri ) + "</D:href>" + "<D:propstat><D:prop>" + "<D:resourcetype><D:collection/></D:resourcetype>" + "<M:Win32FileAttributes>00000011</M:Win32FileAttributes>" + "</D:prop><D:status>HTTP/1.1 200 OK</D:status>" + "</D:propstat>" + "</D:response>" ;
checked { + + index ; }
}
}
}
else
{
if ( segments . Length = = 2 )
{
ConnectionSettingBase setting = this . FindSetting ( Uri . UnescapeDataString ( segments [ 1 ] ) . Replace ( "/" , "" ) ) ;
if ( setting ! = null )
{
FsBase client = this . CreateClient ( con , setting ) ;
str1 = str1 + "<D:response><D:href>" + SecurityElement . Escape ( UriUtil . AddLastSlash ( req . RequestUri ) . AbsoluteUri ) + "</D:href>" + "<D:propstat><D:prop>" + "<D:resourcetype><D:collection/></D:resourcetype>" + "<M:Win32FileAttributes>00000011</M:Win32FileAttributes>" + "</D:prop><D:status>HTTP/1.1 200 OK</D:status>" + "</D:propstat>" + "</D:response>" ;
if ( result > = 1 )
{
ResourceInfo [ ] resourceInfoArray = ( ResourceInfo [ ] ) null ;
label_16 :
while ( true )
{
try
{
resourceInfoArray = client . GetInfoAndEntries ( setting . TargetUri ) ;
break ;
}
catch ( RemoteCertificateErrorException ex )
{
ProjectData . SetProjectError ( ( Exception ) ex ) ;
RemoteCertificateErrorException certificateErrorException = ex ;
2017-10-06 18:20:35 +02:00
EventHandler < LogMessageEventArgs > logMessageEvent = this . LogMessage ;
2017-10-06 17:20:58 +02:00
if ( logMessageEvent ! = null )
logMessageEvent ( ( object ) this , new LogMessageEventArgs ( certificateErrorException . ToString ( ) ) ) ;
LogWriter . WriteException ( ( Exception ) certificateErrorException ) ;
client . ResetConnection ( ) ;
switch ( ServerCertErrorPromptForm . ShowDialog ( ( IWin32Window ) null , ( string ) null , certificateErrorException . Errors , req . RequestUri . ToString ( ) ) )
{
case DialogResult . Retry :
ProjectData . ClearProjectError ( ) ;
continue ;
case DialogResult . Ignore :
client . ConnectionSetting . CertErrorIgnores = certificateErrorException . Errors ;
ProjectData . ClearProjectError ( ) ;
continue ;
default :
ProjectData . ClearProjectError ( ) ;
goto label_111 ;
}
}
catch ( UnauthorizedException ex1 )
{
ProjectData . SetProjectError ( ( Exception ) ex1 ) ;
UnauthorizedException unauthorizedException = ex1 ;
2017-10-06 18:20:35 +02:00
EventHandler < LogMessageEventArgs > logMessageEvent = this . LogMessage ;
2017-10-06 17:20:58 +02:00
if ( logMessageEvent ! = null )
logMessageEvent ( ( object ) this , new LogMessageEventArgs ( unauthorizedException . ToString ( ) ) ) ;
LogWriter . WriteException ( ( Exception ) unauthorizedException ) ;
client . ResetConnection ( ) ;
if ( unauthorizedException . CanRetry )
{
int retryminutes = 1 ;
while ( true )
{
try
{
if ( setting . DoAuthorization ( req . RequestUri , false ) )
{
ProjectData . ClearProjectError ( ) ;
goto label_16 ;
}
else
break ;
}
catch ( Exception ex2 )
{
ProjectData . SetProjectError ( ex2 ) ;
ErrorPromptFormResult promptFormResult = ErrorPromptForm . ShowDialog ( ( IWin32Window ) null , "Error occurred during authorizing." , req . RequestUri . ToString ( ) , ( Exception ) unauthorizedException , ErrorPromptType . RetryCancel , retryminutes ) ;
if ( promptFormResult . Action = = ErrorAction . AutoRetry )
{
checked { retryminutes * = 2 ; }
ProjectData . ClearProjectError ( ) ;
}
else if ( promptFormResult . Action = = ErrorAction . Retry )
{
ProjectData . ClearProjectError ( ) ;
}
else
{
ProjectData . ClearProjectError ( ) ;
break ;
}
}
}
ProjectData . ClearProjectError ( ) ;
break ;
}
ProjectData . ClearProjectError ( ) ;
goto label_101 ;
}
catch ( RemoteResourceNotFoundException ex )
{
ProjectData . SetProjectError ( ( Exception ) ex ) ;
ProjectData . ClearProjectError ( ) ;
goto label_106 ;
}
catch ( Exception ex1 )
{
ProjectData . SetProjectError ( ex1 ) ;
Exception ex2 = ex1 ;
2017-10-06 18:20:35 +02:00
EventHandler < LogMessageEventArgs > logMessageEvent = this . LogMessage ;
2017-10-06 17:20:58 +02:00
if ( logMessageEvent ! = null )
logMessageEvent ( ( object ) this , new LogMessageEventArgs ( ex2 . ToString ( ) ) ) ;
LogWriter . WriteException ( ex2 ) ;
client . ResetConnection ( ) ;
ProjectData . ClearProjectError ( ) ;
goto label_111 ;
}
}
int num1 = 1 ;
int num2 = checked ( resourceInfoArray . Length - 1 ) ;
int index = num1 ;
while ( index < = num2 )
{
string lastName = UriUtil . GetLastName ( resourceInfoArray [ index ] . Id . Uri ) ;
Uri target = UriUtil . CombineName ( req . RequestUri , lastName ) ;
if ( resourceInfoArray [ index ] . IsCollection )
target = UriUtil . AddLastSlash ( target ) ;
string str2 = str1 + "<D:response><D:href>" + SecurityElement . Escape ( target . AbsoluteUri ) + "</D:href>" + "<D:propstat><D:prop>" ;
DateTime universalTime ;
string str3 ;
if ( resourceInfoArray [ index ] . IsCollection )
{
string str4 = str2 + "<D:resourcetype><D:collection/></D:resourcetype>" + "<D:getcontentlength>" + Conversions . ToString ( resourceInfoArray [ index ] . Size ) + "</D:getcontentlength>" + "<D:getcontenttype>application/octet-stream</D:getcontenttype>" ;
string str5 = "<M:Win32CreationTime>" ;
universalTime = resourceInfoArray [ index ] . CreationTime . ToUniversalTime ( ) ;
string str6 = universalTime . ToString ( "r" ) ;
string str7 = "</M:Win32CreationTime>" ;
string str8 = str4 + str5 + str6 + str7 ;
string str9 = "<M:Win32LastAccessTime>" ;
universalTime = resourceInfoArray [ index ] . LastAccessTime . ToUniversalTime ( ) ;
string str10 = universalTime . ToString ( "r" ) ;
string str11 = "</M:Win32LastAccessTime>" ;
string str12 = str8 + str9 + str10 + str11 ;
string str13 = "<M:Win32LastModifiedTime>" ;
universalTime = resourceInfoArray [ index ] . LastModifiedTime . ToUniversalTime ( ) ;
string str14 = universalTime . ToString ( "r" ) ;
string str15 = "</M:Win32LastModifiedTime>" ;
str3 = str12 + str13 + str14 + str15 + "<M:Win32FileAttributes>00000010</M:Win32FileAttributes>" ;
}
else
{
string str4 = str2 + "<D:getcontentlength>" + Conversions . ToString ( resourceInfoArray [ index ] . Size ) + "</D:getcontentlength>" + "<D:getcontenttype>application/octet-stream</D:getcontenttype>" ;
string str5 = "<M:Win32CreationTime>" ;
universalTime = resourceInfoArray [ index ] . CreationTime . ToUniversalTime ( ) ;
string str6 = universalTime . ToString ( "r" ) ;
string str7 = "</M:Win32CreationTime>" ;
string str8 = str4 + str5 + str6 + str7 ;
string str9 = "<M:Win32LastAccessTime>" ;
universalTime = resourceInfoArray [ index ] . LastAccessTime . ToUniversalTime ( ) ;
string str10 = universalTime . ToString ( "r" ) ;
string str11 = "</M:Win32LastAccessTime>" ;
string str12 = str8 + str9 + str10 + str11 ;
string str13 = "<M:Win32LastModifiedTime>" ;
universalTime = resourceInfoArray [ index ] . LastModifiedTime . ToUniversalTime ( ) ;
string str14 = universalTime . ToString ( "r" ) ;
string str15 = "</M:Win32LastModifiedTime>" ;
str3 = str12 + str13 + str14 + str15 + "<M:Win32FileAttributes>00000000</M:Win32FileAttributes>" ;
}
str1 = str3 + "</D:prop><D:status>HTTP/1.1 200 OK</D:status>" + "</D:propstat>" + "</D:response>" ;
checked { + + index ; }
}
goto label_96 ;
}
else
goto label_96 ;
}
else
goto label_106 ;
}
else
{
string searchname = Uri . UnescapeDataString ( segments [ 1 ] ) . Replace ( "/" , "" ) ;
if ( Operators . CompareString ( UriUtil . GetLastName ( req . RequestUri ) , "desktop.ini" , false ) ! = 0 )
{
ConnectionSettingBase setting = this . FindSetting ( searchname ) ;
if ( setting ! = null )
{
FsBase client = this . CreateClient ( con , setting ) ;
Uri uri1 = setting . TargetUri ;
int num1 = 2 ;
int num2 = checked ( segments . Length - 1 ) ;
int index1 = num1 ;
while ( index1 < = num2 )
{
uri1 = UriUtil . CombineSegment ( uri1 , segments [ index1 ] ) ;
checked { + + index1 ; }
}
label_55 :
ResourceInfo [ ] resourceInfoArray ;
while ( true )
{
try
{
if ( result = = 0 )
{
resourceInfoArray = new ResourceInfo [ 1 ]
{
client . GetInfo ( uri1 )
} ;
break ;
}
resourceInfoArray = client . GetInfoAndEntries ( uri1 ) ;
break ;
}
catch ( RemoteCertificateErrorException ex )
{
ProjectData . SetProjectError ( ( Exception ) ex ) ;
RemoteCertificateErrorException certificateErrorException = ex ;
2017-10-06 18:20:35 +02:00
EventHandler < LogMessageEventArgs > logMessageEvent = this . LogMessage ;
2017-10-06 17:20:58 +02:00
if ( logMessageEvent ! = null )
logMessageEvent ( ( object ) this , new LogMessageEventArgs ( certificateErrorException . ToString ( ) ) ) ;
LogWriter . WriteException ( ( Exception ) certificateErrorException ) ;
client . ResetConnection ( ) ;
switch ( ServerCertErrorPromptForm . ShowDialog ( ( IWin32Window ) null , ( string ) null , certificateErrorException . Errors , req . RequestUri . ToString ( ) ) )
{
case DialogResult . Retry :
ProjectData . ClearProjectError ( ) ;
continue ;
case DialogResult . Ignore :
client . ConnectionSetting . CertErrorIgnores = certificateErrorException . Errors ;
ProjectData . ClearProjectError ( ) ;
continue ;
default :
ProjectData . ClearProjectError ( ) ;
goto label_117 ;
}
}
catch ( UnauthorizedException ex1 )
{
ProjectData . SetProjectError ( ( Exception ) ex1 ) ;
UnauthorizedException unauthorizedException = ex1 ;
2017-10-06 18:20:35 +02:00
EventHandler < LogMessageEventArgs > logMessageEvent = this . LogMessage ;
2017-10-06 17:20:58 +02:00
if ( logMessageEvent ! = null )
logMessageEvent ( ( object ) this , new LogMessageEventArgs ( unauthorizedException . ToString ( ) ) ) ;
LogWriter . WriteException ( ( Exception ) unauthorizedException ) ;
client . ResetConnection ( ) ;
if ( unauthorizedException . CanRetry )
{
int retryminutes = 1 ;
while ( true )
{
try
{
if ( setting . DoAuthorization ( req . RequestUri , false ) )
{
ProjectData . ClearProjectError ( ) ;
goto label_55 ;
}
else
break ;
}
catch ( Exception ex2 )
{
ProjectData . SetProjectError ( ex2 ) ;
ErrorPromptFormResult promptFormResult = ErrorPromptForm . ShowDialog ( ( IWin32Window ) null , "Error occurred during authorizing." , req . RequestUri . ToString ( ) , ( Exception ) unauthorizedException , ErrorPromptType . RetryCancel , retryminutes ) ;
if ( promptFormResult . Action = = ErrorAction . AutoRetry )
{
checked { retryminutes * = 2 ; }
ProjectData . ClearProjectError ( ) ;
}
else if ( promptFormResult . Action = = ErrorAction . Retry )
{
ProjectData . ClearProjectError ( ) ;
}
else
{
ProjectData . ClearProjectError ( ) ;
break ;
}
}
}
}
ProjectData . ClearProjectError ( ) ;
goto label_101 ;
}
catch ( RemoteResourceNotFoundException ex )
{
ProjectData . SetProjectError ( ( Exception ) ex ) ;
ProjectData . ClearProjectError ( ) ;
goto label_106 ;
}
catch ( Exception ex1 )
{
ProjectData . SetProjectError ( ex1 ) ;
Exception ex2 = ex1 ;
2017-10-06 18:20:35 +02:00
EventHandler < LogMessageEventArgs > logMessageEvent = this . LogMessage ;
2017-10-06 17:20:58 +02:00
if ( logMessageEvent ! = null )
logMessageEvent ( ( object ) this , new LogMessageEventArgs ( ex2 . ToString ( ) ) ) ;
LogWriter . WriteException ( ex2 ) ;
client . ResetConnection ( ) ;
ProjectData . ClearProjectError ( ) ;
goto label_117 ;
}
}
Uri uri2 = req . RequestUri ;
if ( uri2 . AbsolutePath . Contains ( "&" ) )
uri2 = new Uri ( uri2 , uri2 . AbsolutePath . Replace ( "&" , "%26" ) ) ;
int num3 = 0 ;
int num4 = checked ( resourceInfoArray . Length - 1 ) ;
int index2 = num3 ;
while ( index2 < = num4 )
{
Uri target ;
if ( index2 = = 0 )
{
target = uri2 ;
}
else
{
string lastName = UriUtil . GetLastName ( resourceInfoArray [ index2 ] . Id . Uri ) ;
if ( Operators . CompareString ( lastName , "desktop.ini" , false ) ! = 0 )
target = UriUtil . CombineName ( uri2 , lastName ) ;
else
goto label_94 ;
}
if ( resourceInfoArray [ index2 ] . IsCollection )
target = UriUtil . AddLastSlash ( target ) ;
string str2 = str1 + "<D:response><D:href>" + SecurityElement . Escape ( target . AbsoluteUri ) + "</D:href>" + "<D:propstat><D:prop>" ;
DateTime universalTime ;
string str3 ;
if ( resourceInfoArray [ index2 ] . IsCollection )
{
string str4 = str2 + "<D:resourcetype><D:collection/></D:resourcetype>" ;
string str5 = "<M:Win32CreationTime>" ;
universalTime = resourceInfoArray [ index2 ] . CreationTime . ToUniversalTime ( ) ;
string str6 = universalTime . ToString ( "r" ) ;
string str7 = "</M:Win32CreationTime>" ;
string str8 = str4 + str5 + str6 + str7 ;
string str9 = "<M:Win32LastAccessTime>" ;
universalTime = resourceInfoArray [ index2 ] . LastAccessTime . ToUniversalTime ( ) ;
string str10 = universalTime . ToString ( "r" ) ;
string str11 = "</M:Win32LastAccessTime>" ;
string str12 = str8 + str9 + str10 + str11 ;
string str13 = "<M:Win32LastModifiedTime>" ;
universalTime = resourceInfoArray [ index2 ] . LastModifiedTime . ToUniversalTime ( ) ;
string str14 = universalTime . ToString ( "r" ) ;
string str15 = "</M:Win32LastModifiedTime>" ;
str3 = str12 + str13 + str14 + str15 + "<M:Win32FileAttributes>00000010</M:Win32FileAttributes>" ;
}
else
{
string str4 = str2 + "<D:getcontentlength>" + Conversions . ToString ( resourceInfoArray [ index2 ] . Size ) + "</D:getcontentlength>" ;
string str5 = "<M:Win32CreationTime>" ;
universalTime = resourceInfoArray [ index2 ] . CreationTime . ToUniversalTime ( ) ;
string str6 = universalTime . ToString ( "r" ) ;
string str7 = "</M:Win32CreationTime>" ;
string str8 = str4 + str5 + str6 + str7 ;
string str9 = "<M:Win32LastAccessTime>" ;
universalTime = resourceInfoArray [ index2 ] . LastAccessTime . ToUniversalTime ( ) ;
string str10 = universalTime . ToString ( "r" ) ;
string str11 = "</M:Win32LastAccessTime>" ;
string str12 = str8 + str9 + str10 + str11 ;
string str13 = "<M:Win32LastModifiedTime>" ;
universalTime = resourceInfoArray [ index2 ] . LastModifiedTime . ToUniversalTime ( ) ;
string str14 = universalTime . ToString ( "r" ) ;
string str15 = "</M:Win32LastModifiedTime>" ;
str3 = str12 + str13 + str14 + str15 + "<M:Win32FileAttributes>00000000</M:Win32FileAttributes>" ;
}
str1 = ( ! resourceInfoArray [ index2 ] . HasError ? str3 + "</D:prop><D:status>HTTP/1.1 200 OK</D:status>" : str3 + "</D:prop><D:status>HTTP/1.1" + resourceInfoArray [ index2 ] . StatusDescription + "</D:status>" ) + "</D:propstat>" + "</D:response>" ;
label_94 :
checked { + + index2 ; }
}
goto label_96 ;
label_117 :
con . Close ( ) ;
return ;
}
goto label_106 ;
}
else
goto label_106 ;
}
label_101 :
res . StatusCode = 401 ;
res . StatusDescription = "Unauthorized" ;
using ( this . SendResponse ( con , res ) )
return ;
label_106 :
res . StatusCode = 404 ;
res . StatusDescription = "Not Found" ;
using ( this . SendResponse ( con , res ) )
return ;
}
label_96 :
string str16 = str1 + "</D:multistatus>" ;
res . StatusCode = 207 ;
res . StatusDescription = "Multi-Status" ;
res . SendChunked = true ;
this . OnLogMessage ( str16 ) ;
byte [ ] bytes = Encoding . UTF8 . GetBytes ( str16 ) ;
res . ContentLength = ( long ) bytes . Length ;
using ( Stream stream = this . SendResponse ( con , res ) )
{
stream . Write ( bytes , 0 , bytes . Length ) ;
return ;
}
}
label_111 :
res . StatusCode = 500 ;
res . StatusDescription = "Internal Server Error" ;
using ( this . SendResponse ( con , res ) )
;
con . Close ( ) ;
}
private void ProcessPROPPATCH ( MyHttpServerConnection con , MyHttpServerRequest req )
{
MyHttpServerResponse res = new MyHttpServerResponse ( ) ;
XmlDocument xmlDocument = new XmlDocument ( ) ;
try
{
string end ;
using ( StreamReader streamReader = new StreamReader ( req . InputStream ) )
end = streamReader . ReadToEnd ( ) ;
this . OnLogMessage ( ")))" ) ;
this . OnLogMessage ( end ) ;
this . OnLogMessage ( ")))" ) ;
xmlDocument . LoadXml ( end ) ;
}
catch ( Exception ex )
{
ProjectData . SetProjectError ( ex ) ;
ProjectData . ClearProjectError ( ) ;
goto label_67 ;
}
if ( ( object ) req . RequestUri ! = null )
{
string [ ] segments = req . RequestUri . Segments ;
if ( segments . Length > 2 & & ( Operators . CompareString ( segments [ 1 ] , "DavWWWRoot/" , false ) = = 0 | | Operators . CompareString ( segments [ 1 ] , "DavWWWRoot" , false ) = = 0 ) )
Array . Copy ( ( Array ) segments , 2 , ( Array ) segments , 1 , checked ( segments . Length - 2 ) ) ;
if ( segments . Length > 1 & & segments . Length ! = 2 )
{
string searchname = Uri . UnescapeDataString ( segments [ 1 ] ) . Replace ( "/" , "" ) ;
UriUtil . GetLastName ( req . RequestUri ) ;
ConnectionSettingBase setting = this . FindSetting ( searchname ) ;
if ( setting ! = null )
{
FsBase client = this . CreateClient ( con , setting ) ;
Uri uri1 = setting . TargetUri ;
int num1 = 2 ;
int num2 = checked ( segments . Length - 1 ) ;
int index = num1 ;
while ( index < = num2 )
{
uri1 = UriUtil . CombineSegment ( uri1 , segments [ index ] ) ;
checked { + + index ; }
}
DateTime result1 = DateTime . MinValue ;
DateTime result2 = DateTime . MinValue ;
DateTime result3 = DateTime . MinValue ;
int result4 = 0 ;
XmlNode documentElement = ( XmlNode ) xmlDocument . DocumentElement ;
if ( Operators . CompareString ( documentElement . LocalName , "propertyupdate" , false ) = = 0 )
{
if ( Operators . CompareString ( documentElement . NamespaceURI , "DAV:" , false ) = = 0 )
{
try
{
foreach ( XmlNode childNode in xmlDocument . DocumentElement . ChildNodes )
{
if ( Operators . CompareString ( childNode . NamespaceURI , "DAV:" , false ) = = 0 )
{
if ( Operators . CompareString ( childNode . LocalName , "set" , false ) = = 0 )
{
XmlNode xmlNode1 = ( XmlNode ) childNode [ "prop" , "DAV:" ] ;
try
{
foreach ( XmlNode xmlNode2 in xmlNode1 )
{
string Left = xmlNode2 . LocalName ;
if ( xmlNode2 . NamespaceURI ! = null )
Left = xmlNode2 . NamespaceURI + Left ;
if ( Operators . CompareString ( Left , "urn:schemas-microsoft-com:Win32CreationTime" , false ) = = 0 )
{
if ( ! DateTime . TryParse ( xmlNode2 . InnerText , out result1 ) )
goto label_67 ;
}
else if ( Operators . CompareString ( Left , "urn:schemas-microsoft-com:Win32LastAccessTime" , false ) = = 0 )
{
if ( ! DateTime . TryParse ( xmlNode2 . InnerText , out result3 ) )
goto label_67 ;
}
else if ( Operators . CompareString ( Left , "urn:schemas-microsoft-com:Win32LastModifiedTime" , false ) = = 0 )
{
if ( ! DateTime . TryParse ( xmlNode2 . InnerText , out result2 ) )
goto label_67 ;
}
else if ( Operators . CompareString ( Left , "urn:schemas-microsoft-com:Win32FileAttributes" , false ) = = 0 )
{
if ( ! int . TryParse ( xmlNode2 . InnerText , NumberStyles . HexNumber , ( IFormatProvider ) null , out result4 ) )
goto label_67 ;
}
}
}
finally
{
2017-10-06 18:20:35 +02:00
//IEnumerator enumerator;
//if (enumerator is IDisposable)
// (enumerator as IDisposable).Dispose();
2017-10-06 17:20:58 +02:00
}
}
else if ( Operators . CompareString ( childNode . LocalName , "remove" , false ) = = 0 )
{
XmlNode xmlNode = ( XmlNode ) childNode [ "prop" , "DAV:" ] ;
}
else
goto label_67 ;
}
else
goto label_67 ;
}
}
finally
{
2017-10-06 18:20:35 +02:00
//IEnumerator enumerator;
//if (enumerator is IDisposable)
// (enumerator as IDisposable).Dispose();
2017-10-06 17:20:58 +02:00
}
if ( ( client . Ability & FsAbility . LastModifiedTime ) = = FsAbility . None )
result2 = DateTime . MinValue ;
if ( ( client . Ability & FsAbility . CreationTime ) = = FsAbility . None )
result1 = DateTime . MinValue ;
if ( ( client . Ability & FsAbility . LastAccessTime ) = = FsAbility . None )
result3 = DateTime . MinValue ;
ResourceInfo resourceInfo ;
try
{
resourceInfo = client . GetInfo ( uri1 ) ;
}
catch ( RemoteResourceNotFoundException ex )
{
ProjectData . SetProjectError ( ( Exception ) ex ) ;
ProjectData . ClearProjectError ( ) ;
goto label_77 ;
}
try
{
if ( DateTime . Compare ( result2 , DateTime . MinValue ) = = 0 & & DateTime . Compare ( result1 , DateTime . MinValue ) = = 0 )
{
if ( DateTime . Compare ( result3 , DateTime . MinValue ) = = 0 )
goto label_55 ;
}
resourceInfo = client . SetTimes ( resourceInfo . Id , result2 , result1 , result3 ) as ResourceInfo ? ? client . GetInfo ( uri1 ) ;
}
catch ( Exception ex )
{
ProjectData . SetProjectError ( ex ) ;
ProjectData . ClearProjectError ( ) ;
goto label_72 ;
}
label_55 :
Uri uri2 = req . RequestUri ;
if ( uri2 . AbsolutePath . Contains ( "&" ) )
uri2 = new Uri ( uri2 , uri2 . AbsolutePath . Replace ( "&" , "%26" ) ) ;
if ( resourceInfo . IsCollection )
uri2 = UriUtil . AddLastSlash ( uri2 ) ;
string str1 = "<?xml version=\"1.0\" encoding=\"utf-8\" ?><D:multistatus xmlns:D=\"DAV:\" xmlns:M=\"urn:schemas-microsoft-com:\">" + "<D:response><D:href>" + SecurityElement . Escape ( uri2 . AbsoluteUri ) + "</D:href>" + "<D:propstat><D:prop>" ;
string str2 ;
if ( resourceInfo . IsCollection )
{
string str3 = str1 + "<D:resourcetype><D:collection/></D:resourcetype>" ;
string str4 = "<M:Win32CreationTime>" ;
DateTime universalTime = resourceInfo . CreationTime . ToUniversalTime ( ) ;
string str5 = universalTime . ToString ( "r" ) ;
string str6 = "</M:Win32CreationTime>" ;
string str7 = str3 + str4 + str5 + str6 ;
string str8 = "<M:Win32LastAccessTime>" ;
universalTime = resourceInfo . LastAccessTime . ToUniversalTime ( ) ;
string str9 = universalTime . ToString ( "r" ) ;
string str10 = "</M:Win32LastAccessTime>" ;
str2 = str7 + str8 + str9 + str10 + "<M:Win32LastModifiedTime>" + resourceInfo . LastModifiedTime . ToUniversalTime ( ) . ToString ( "r" ) + "</M:Win32LastModifiedTime>" + "<M:Win32FileAttributes>00000010</M:Win32FileAttributes>" ;
}
else
str2 = str1 + "<D:getcontentlength>" + Conversions . ToString ( resourceInfo . Size ) + "</D:getcontentlength>" + "<M:Win32CreationTime>" + resourceInfo . CreationTime . ToUniversalTime ( ) . ToString ( "r" ) + "</M:Win32CreationTime>" + "<M:Win32LastAccessTime>" + resourceInfo . LastAccessTime . ToUniversalTime ( ) . ToString ( "r" ) + "</M:Win32LastAccessTime>" + "<M:Win32LastModifiedTime>" + resourceInfo . LastModifiedTime . ToUniversalTime ( ) . ToString ( "r" ) + "</M:Win32LastModifiedTime>" + "<M:Win32FileAttributes>00000000</M:Win32FileAttributes>" ;
string s = str2 + "</D:prop><D:status>HTTP/1.1 200 OK</D:status>" + "</D:propstat>" + "</D:response>" + "</D:multistatus>" ;
res . StatusCode = 207 ;
res . StatusDescription = "Multi-Status" ;
res . SendChunked = true ;
byte [ ] bytes = Encoding . UTF8 . GetBytes ( s ) ;
res . ContentLength = ( long ) bytes . Length ;
using ( Stream stream = this . SendResponse ( con , res ) )
{
stream . Write ( bytes , 0 , bytes . Length ) ;
return ;
}
}
else
goto label_67 ;
}
else
goto label_67 ;
}
label_77 :
res . StatusCode = 404 ;
res . StatusDescription = "Not found" ;
using ( this . SendResponse ( con , res ) )
return ;
}
label_72 :
res . StatusCode = 403 ;
res . StatusDescription = "Forbidden" ;
using ( this . SendResponse ( con , res ) )
return ;
}
else
{
res . StatusCode = 500 ;
res . StatusDescription = "Internal Server Error" ;
using ( this . SendResponse ( con , res ) )
;
con . Close ( ) ;
return ;
}
label_67 :
res . StatusCode = 400 ;
res . StatusDescription = "Bad Request" ;
using ( this . SendResponse ( con , res ) )
;
}
private void ProcessGETHEAD ( MyHttpServerConnection con , MyHttpServerRequest req , bool containbody )
{
MyHttpServerResponse res = new MyHttpServerResponse ( ) ;
if ( ( object ) req . RequestUri ! = null )
{
string [ ] segments = req . RequestUri . Segments ;
if ( segments . Length > 2 & & ( Operators . CompareString ( segments [ 1 ] , "DavWWWRoot/" , false ) = = 0 | | Operators . CompareString ( segments [ 1 ] , "DavWWWRoot" , false ) = = 0 ) )
Array . Copy ( ( Array ) segments , 2 , ( Array ) segments , 1 , checked ( segments . Length - 2 ) ) ;
string s ;
if ( segments . Length < = 1 )
{
string str = "<html><body><ul>" ;
int num1 = 0 ;
int num2 = checked ( this . _setting . ConnectionSettings . Count - 1 ) ;
int index = num1 ;
while ( index < = num2 )
{
str = str + "<li><a href=\"" + UriUtil . AddLastSlash ( UriUtil . CombineName ( req . RequestUri , this . SanitizeName ( this . _setting . ConnectionSettings [ index ] . Name ) ) ) . AbsoluteUri + "\">" + this . SanitizeName ( this . _setting . ConnectionSettings [ index ] . Name ) + "</a>" ;
checked { + + index ; }
}
s = str + "</ul></body></html>" ;
}
else
{
if ( segments . Length = = 2 )
{
ConnectionSettingBase setting = this . FindSetting ( Uri . UnescapeDataString ( segments [ 1 ] ) . Replace ( "/" , "" ) ) ;
if ( setting ! = null )
{
s = "<html><body><h1>" + this . SanitizeName ( setting . Name ) + "</h1></body></html>" ;
goto label_40 ;
}
}
else
{
ConnectionSettingBase setting = this . FindSetting ( Uri . UnescapeDataString ( segments [ 1 ] ) . Replace ( "/" , "" ) ) ;
if ( setting ! = null )
{
FsBase client = this . CreateClient ( con , setting ) ;
Uri uri = setting . TargetUri ;
int num1 = 2 ;
int num2 = checked ( segments . Length - 1 ) ;
int index = num1 ;
while ( index < = num2 )
{
uri = UriUtil . CombineSegment ( uri , segments [ index ] ) ;
checked { + + index ; }
}
try
{
ResourceInfo info ;
try
{
info = client . GetInfo ( uri ) ;
}
catch ( RemoteResourceNotFoundException ex )
{
ProjectData . SetProjectError ( ( Exception ) ex ) ;
ProjectData . ClearProjectError ( ) ;
goto label_46 ;
}
if ( info . Size = = 0L )
{
res . StatusCode = 204 ;
res . StatusDescription = "No Content" ;
res . ContentLength = 0L ;
}
else
{
res . StatusCode = 200 ;
res . StatusDescription = "OK" ;
res . SendChunked = true ;
}
res . Headers . Add ( "Accept-Ranges" , "none" ) ;
res . Headers . Add ( "Allow" , "GET, HEAD, PUT, DELETE, MOVE, COPY, PROPFIND, PROPPATCH" ) ;
res . Headers . Add ( "Connection" , "Keep-Alive" ) ;
using ( Stream stream1 = this . SendResponse ( con , res ) )
{
if ( ! containbody )
return ;
if ( info . Size < = 0L )
return ;
try
{
FsBase fsBase = client ;
ResourceId id = info . Id ;
long start = 0 ;
using ( Stream stream2 = fsBase . OpenRead ( id , ref start , ref info . Size ) )
{
byte [ ] buffer = new byte [ 65536 ] ;
while ( true )
{
int count = stream2 . Read ( buffer , 0 , buffer . Length ) ;
if ( count ! = 0 )
stream1 . Write ( buffer , 0 , count ) ;
else
break ;
}
return ;
}
}
catch ( Exception ex )
{
ProjectData . SetProjectError ( ex ) ;
con . Close ( ) ;
ProjectData . ClearProjectError ( ) ;
return ;
}
}
}
catch ( Exception ex )
{
ProjectData . SetProjectError ( ex ) ;
ProjectData . ClearProjectError ( ) ;
goto label_51 ;
}
}
}
label_46 :
res . StatusCode = 404 ;
res . StatusDescription = "Not found" ;
using ( this . SendResponse ( con , res ) )
return ;
}
label_40 :
res . StatusCode = 200 ;
res . StatusDescription = "OK" ;
res . Headers . Add ( "Accept-Ranges" , "none" ) ;
res . Headers . Add ( "Allow" , "GET, HEAD" ) ;
byte [ ] bytes = Encoding . UTF8 . GetBytes ( s ) ;
res . ContentLength = ( long ) bytes . Length ;
using ( Stream stream = this . SendResponse ( con , res ) )
{
if ( ! containbody )
return ;
stream . Write ( bytes , 0 , bytes . Length ) ;
return ;
}
}
label_51 :
res . StatusCode = 500 ;
res . StatusDescription = "Internal Server Error" ;
using ( this . SendResponse ( con , res ) )
;
con . Close ( ) ;
}
private void ProcessDELETE ( MyHttpServerConnection con , MyHttpServerRequest req )
{
MyHttpServerResponse res = new MyHttpServerResponse ( ) ;
if ( ( object ) req . RequestUri ! = null )
{
string [ ] segments = req . RequestUri . Segments ;
if ( segments . Length > 2 & & ( Operators . CompareString ( segments [ 1 ] , "DavWWWRoot/" , false ) = = 0 | | Operators . CompareString ( segments [ 1 ] , "DavWWWRoot" , false ) = = 0 ) )
Array . Copy ( ( Array ) segments , 2 , ( Array ) segments , 1 , checked ( segments . Length - 2 ) ) ;
if ( segments . Length > 1 & & segments . Length ! = 2 )
{
ConnectionSettingBase setting = this . FindSetting ( Uri . UnescapeDataString ( segments [ 1 ] ) . Replace ( "/" , "" ) ) ;
if ( setting ! = null )
{
FsBase client = this . CreateClient ( con , setting ) ;
Uri uri = setting . TargetUri ;
int num1 = 2 ;
int num2 = checked ( segments . Length - 1 ) ;
int index = num1 ;
while ( index < = num2 )
{
uri = UriUtil . CombineSegment ( uri , segments [ index ] ) ;
checked { + + index ; }
}
ResourceInfo info ;
try
{
info = client . GetInfo ( uri ) ;
}
catch ( RemoteResourceNotFoundException ex )
{
ProjectData . SetProjectError ( ( Exception ) ex ) ;
ProjectData . ClearProjectError ( ) ;
goto label_22 ;
}
try
{
client . Delete ( info . Id ) ;
}
catch ( Exception ex )
{
ProjectData . SetProjectError ( ex ) ;
ProjectData . ClearProjectError ( ) ;
goto label_27 ;
}
res . StatusCode = 204 ;
res . StatusDescription = "No Content" ;
using ( this . SendResponse ( con , res ) )
return ;
}
label_22 :
res . StatusCode = 404 ;
res . StatusDescription = "Not found" ;
using ( this . SendResponse ( con , res ) )
return ;
}
else
{
res . StatusCode = 400 ;
res . StatusDescription = "Bad Request" ;
using ( this . SendResponse ( con , res ) )
return ;
}
}
label_27 :
res . StatusCode = 500 ;
res . StatusDescription = "Internal Server Error" ;
using ( this . SendResponse ( con , res ) )
;
con . Close ( ) ;
}
private void ProcessPUT ( MyHttpServerConnection con , MyHttpServerRequest req )
{
MyHttpServerResponse res = new MyHttpServerResponse ( ) ;
int num1 = 0 ;
int num2 = checked ( req . Headers . Count - 1 ) ;
int index1 = num1 ;
while ( index1 < = num2 )
{
string upperInvariant = req . Headers . Keys [ index1 ] . ToUpperInvariant ( ) ;
if ( ! upperInvariant . StartsWith ( "CONTENT-" ) | | Operators . CompareString ( upperInvariant , "CONTENT-LANGUAGE" , false ) = = 0 | | ( Operators . CompareString ( upperInvariant , "CONTENT-LENGTH" , false ) = = 0 | | Operators . CompareString ( upperInvariant , "CONTENT-LOCATION" , false ) = = 0 ) | | ( Operators . CompareString ( upperInvariant , "CONTENT-MD5" , false ) = = 0 | | Operators . CompareString ( upperInvariant , "CONTENT-TYPE" , false ) = = 0 | | Operators . CompareString ( upperInvariant , "CONTENT-MD5" , false ) = = 0 ) )
{
checked { + + index1 ; }
}
else
{
res . StatusCode = 501 ;
res . StatusDescription = "Not Implemented" ;
using ( this . SendResponse ( con , res ) )
;
con . Close ( ) ;
return ;
}
}
if ( ( object ) req . RequestUri ! = null )
{
string [ ] segments = req . RequestUri . Segments ;
if ( segments . Length > 2 & & ( Operators . CompareString ( segments [ 1 ] , "DavWWWRoot/" , false ) = = 0 | | Operators . CompareString ( segments [ 1 ] , "DavWWWRoot" , false ) = = 0 ) )
Array . Copy ( ( Array ) segments , 2 , ( Array ) segments , 1 , checked ( segments . Length - 2 ) ) ;
if ( segments . Length > 1 & & segments . Length ! = 2 )
{
ConnectionSettingBase setting = this . FindSetting ( Uri . UnescapeDataString ( segments [ 1 ] ) . Replace ( "/" , "" ) ) ;
if ( setting ! = null )
{
FsBase client = this . CreateClient ( con , setting ) ;
Uri uri = setting . TargetUri ;
int num3 = 2 ;
int num4 = checked ( segments . Length - 1 ) ;
int index2 = num3 ;
while ( index2 < = num4 )
{
uri = UriUtil . CombineSegment ( uri , segments [ index2 ] ) ;
checked { + + index2 ; }
}
string lastName = UriUtil . GetLastName ( uri ) ;
Uri parent = UriUtil . GetParent ( uri ) ;
ResourceInfo info ;
try
{
info = client . GetInfo ( parent ) ;
}
catch ( Exception ex )
{
ProjectData . SetProjectError ( ex ) ;
ProjectData . ClearProjectError ( ) ;
goto label_47 ;
}
try
{
using ( Stream st = client . OpenWrite ( info . Id , lastName , req . ContentLength ) )
{
using ( Stream inputStream = req . InputStream )
{
DateTime now = DateTime . Now ;
long num5 = 0 ;
long num6 = 1048576 ;
byte [ ] buffer = new byte [ 65536 ] ;
while ( true )
{
do
{
int count = inputStream . Read ( buffer , 0 , buffer . Length ) ;
if ( count ! = 0 )
{
st . Write ( buffer , 0 , count ) ;
checked { num5 + = ( long ) count ; }
}
else
goto label_24 ;
}
while ( num5 < = num6 ) ;
this . OnLogMessage ( num5 . ToString ( ) ) ;
num6 = checked ( num5 + 1048576L ) ;
}
}
label_24 :
client . CloseWrite ( st ) ;
}
}
catch ( Exception ex )
{
ProjectData . SetProjectError ( ex ) ;
ProjectData . ClearProjectError ( ) ;
goto label_52 ;
}
if ( req . ContentLength < = 0L )
{
res . StatusCode = 201 ;
res . StatusDescription = "Created" ;
Uri baseUri = req . RequestUri ;
if ( baseUri . AbsolutePath . Contains ( "&" ) )
baseUri = new Uri ( baseUri , baseUri . AbsolutePath . Replace ( "&" , "%26" ) ) ;
res . Headers . Add ( "Location" , baseUri . AbsoluteUri ) ;
using ( this . SendResponse ( con , res ) )
return ;
}
else
{
res . StatusCode = 204 ;
res . StatusDescription = "No Content" ;
using ( this . SendResponse ( con , res ) )
return ;
}
}
label_47 :
res . StatusCode = 412 ;
res . StatusDescription = "Precondition Failed" ;
using ( this . SendResponse ( con , res ) )
return ;
}
else
{
res . StatusCode = 403 ;
res . StatusDescription = "Forbidden" ;
using ( this . SendResponse ( con , res ) )
return ;
}
}
label_52 :
res . StatusCode = 500 ;
res . StatusDescription = "Internal Server Error" ;
using ( this . SendResponse ( con , res ) )
;
con . Close ( ) ;
}
private void ProcessMKCOL ( MyHttpServerConnection con , MyHttpServerRequest req )
{
MyHttpServerResponse res = new MyHttpServerResponse ( ) ;
if ( ( object ) req . RequestUri ! = null )
{
string [ ] segments = req . RequestUri . Segments ;
if ( segments . Length > 2 & & ( Operators . CompareString ( segments [ 1 ] , "DavWWWRoot/" , false ) = = 0 | | Operators . CompareString ( segments [ 1 ] , "DavWWWRoot" , false ) = = 0 ) )
Array . Copy ( ( Array ) segments , 2 , ( Array ) segments , 1 , checked ( segments . Length - 2 ) ) ;
if ( segments . Length > 1 & & segments . Length ! = 2 )
{
ConnectionSettingBase setting = this . FindSetting ( Uri . UnescapeDataString ( segments [ 1 ] ) . Replace ( "/" , "" ) ) ;
if ( setting ! = null )
{
FsBase client = this . CreateClient ( con , setting ) ;
Uri uri = setting . TargetUri ;
int num1 = 2 ;
int num2 = checked ( segments . Length - 1 ) ;
int index = num1 ;
while ( index < = num2 )
{
uri = UriUtil . CombineSegment ( uri , segments [ index ] ) ;
checked { + + index ; }
}
string lastName = UriUtil . GetLastName ( uri ) ;
Uri parent = UriUtil . GetParent ( uri ) ;
ResourceInfo info ;
try
{
info = client . GetInfo ( parent ) ;
}
catch ( Exception ex )
{
ProjectData . SetProjectError ( ex ) ;
ProjectData . ClearProjectError ( ) ;
goto label_23 ;
}
try
{
client . CreateCollection ( info . Id , lastName ) ;
}
catch ( Exception ex )
{
ProjectData . SetProjectError ( ex ) ;
ProjectData . ClearProjectError ( ) ;
goto label_28 ;
}
res . StatusCode = 201 ;
res . StatusDescription = "Created" ;
res . ContentLength = 0L ;
using ( this . SendResponse ( con , res ) )
return ;
}
label_23 :
res . StatusCode = 412 ;
res . StatusDescription = "Precondition Failed" ;
res . ContentLength = 0L ;
using ( this . SendResponse ( con , res ) )
return ;
}
else
{
res . StatusCode = 403 ;
res . StatusDescription = "Forbidden" ;
res . ContentLength = 0L ;
using ( this . SendResponse ( con , res ) )
return ;
}
}
label_28 :
res . StatusCode = 500 ;
res . StatusDescription = "Internal Server Error" ;
res . ContentLength = 0L ;
using ( this . SendResponse ( con , res ) )
;
con . Close ( ) ;
}
private void ProcessMOVE ( MyHttpServerConnection con , MyHttpServerRequest req )
{
MyHttpServerResponse res = new MyHttpServerResponse ( ) ;
Uri result = ( Uri ) null ;
if ( ( object ) req . RequestUri ! = null )
{
string [ ] segments1 = req . RequestUri . Segments ;
if ( segments1 . Length > 2 & & ( Operators . CompareString ( segments1 [ 1 ] , "DavWWWRoot/" , false ) = = 0 | | Operators . CompareString ( segments1 [ 1 ] , "DavWWWRoot" , false ) = = 0 ) )
Array . Copy ( ( Array ) segments1 , 2 , ( Array ) segments1 , 1 , checked ( segments1 . Length - 2 ) ) ;
if ( segments1 . Length > 1 & & segments1 . Length ! = 2 )
{
string str1 = Uri . UnescapeDataString ( segments1 [ 1 ] ) . Replace ( "/" , "" ) ;
if ( Uri . TryCreate ( req . Headers [ "Destination" ] , UriKind . RelativeOrAbsolute , out result ) )
{
if ( ! result . IsAbsoluteUri )
result = new Uri ( req . RequestUri , result ) ;
string [ ] segments2 = result . Segments ;
if ( segments2 . Length > 2 & & ( Operators . CompareString ( segments2 [ 1 ] , "DavWWWRoot/" , false ) = = 0 | | Operators . CompareString ( segments2 [ 1 ] , "DavWWWRoot" , false ) = = 0 ) )
Array . Copy ( ( Array ) segments2 , 2 , ( Array ) segments2 , 1 , checked ( segments2 . Length - 2 ) ) ;
if ( Operators . CompareString ( Uri . UnescapeDataString ( segments2 [ 1 ] ) . Replace ( "/" , "" ) , str1 , false ) = = 0 )
{
bool overwrite = false ;
if ( Operators . CompareString ( req . Headers [ "Overwrite" ] . ToUpperInvariant ( ) , "T" , false ) = = 0 )
overwrite = true ;
ConnectionSettingBase setting = this . FindSetting ( str1 ) ;
if ( setting ! = null )
{
FsBase client = this . CreateClient ( con , setting ) ;
Uri uri1 = setting . TargetUri ;
int num1 = 2 ;
int num2 = checked ( segments1 . Length - 1 ) ;
int index1 = num1 ;
while ( index1 < = num2 )
{
uri1 = UriUtil . CombineSegment ( uri1 , segments1 [ index1 ] ) ;
checked { + + index1 ; }
}
Uri uri2 = setting . TargetUri ;
int num3 = 2 ;
int num4 = checked ( segments2 . Length - 1 ) ;
int index2 = num3 ;
while ( index2 < = num4 )
{
uri2 = UriUtil . CombineSegment ( uri2 , segments2 [ index2 ] ) ;
checked { + + index2 ; }
}
string lastName = UriUtil . GetLastName ( uri1 ) ;
Uri parent1 = UriUtil . GetParent ( uri1 ) ;
string str2 = UriUtil . GetLastName ( uri2 ) ;
Uri parent2 = UriUtil . GetParent ( uri2 ) ;
ResourceInfo info ;
try
{
info = client . GetInfo ( uri1 ) ;
}
catch ( Exception ex )
{
ProjectData . SetProjectError ( ex ) ;
ProjectData . ClearProjectError ( ) ;
goto label_44 ;
}
ResourceId newparentid = ( ResourceId ) null ;
if ( parent1 ! = parent2 )
{
try
{
newparentid = client . GetInfo ( parent2 ) . Id ;
}
catch ( Exception ex )
{
ProjectData . SetProjectError ( ex ) ;
ProjectData . ClearProjectError ( ) ;
goto label_44 ;
}
}
if ( Operators . CompareString ( lastName , str2 , false ) = = 0 )
str2 = ( string ) null ;
ReturnedInfo returnedInfo ;
try
{
returnedInfo = client . Move ( info . Id , newparentid , str2 , overwrite ) ;
}
catch ( Exception ex )
{
ProjectData . SetProjectError ( ex ) ;
ProjectData . ClearProjectError ( ) ;
goto label_49 ;
}
ResourceInfo resourceInfo = returnedInfo as ResourceInfo ;
result = ! ( resourceInfo = = null ? ( ResourceId ) returnedInfo : resourceInfo . Id ) . IsCollection ? UriUtil . RemoveLastSlash ( result ) : UriUtil . AddLastSlash ( result ) ;
res . StatusCode = 201 ;
res . StatusDescription = "Created" ;
res . ContentLength = 0L ;
res . Headers . Add ( "Location" , result . AbsoluteUri ) ;
using ( this . SendResponse ( con , res ) )
return ;
}
label_44 :
res . StatusCode = 412 ;
res . StatusDescription = "Precondition Failed" ;
res . ContentLength = 0L ;
using ( this . SendResponse ( con , res ) )
return ;
}
else
{
res . StatusCode = 502 ;
res . StatusDescription = "Bad Gateway" ;
res . ContentLength = 0L ;
using ( this . SendResponse ( con , res ) )
;
con . Close ( ) ;
return ;
}
}
else
{
res . StatusCode = 400 ;
res . StatusDescription = "Bad Request" ;
res . ContentLength = 0L ;
using ( this . SendResponse ( con , res ) )
return ;
}
}
else
{
res . StatusCode = 403 ;
res . StatusDescription = "Forbidden" ;
res . ContentLength = 0L ;
using ( this . SendResponse ( con , res ) )
return ;
}
}
label_49 :
res . StatusCode = 500 ;
res . StatusDescription = "Internal Server Error" ;
res . ContentLength = 0L ;
using ( this . SendResponse ( con , res ) )
;
con . Close ( ) ;
}
private Stream SendResponse ( MyHttpServerConnection con , MyHttpServerResponse res )
{
res . Headers . Add ( "Server" , this . ServerName ) ;
this . OnLogMessage ( "(" + Conversions . ToString ( res . StatusCode ) + " " + res . StatusDescription ) ;
int num1 = 0 ;
int num2 = checked ( res . Headers . Count - 1 ) ;
int index = num1 ;
while ( index < = num2 )
{
this . OnLogMessage ( "( " + res . Headers . Keys [ index ] + ": " + res . Headers [ index ] ) ;
checked { + + index ; }
}
if ( res . SendChunked )
this . OnLogMessage ( "( Transfer-Encoding: chunked" ) ;
else
this . OnLogMessage ( "( Content-Length: " + Conversions . ToString ( res . ContentLength ) ) ;
this . OnLogMessage ( "(" ) ;
return con . SendResponse ( res ) ;
}
private void OnLogMessage ( string str )
{
2017-10-06 18:20:35 +02:00
EventHandler < LogMessageEventArgs > logMessageEvent = this . LogMessage ;
2017-10-06 17:20:58 +02:00
if ( logMessageEvent = = null )
return ;
logMessageEvent ( ( object ) this , new LogMessageEventArgs ( str ) ) ;
}
private ConnectionSettingBase FindSetting ( string searchname )
{
int num1 = 0 ;
int num2 = checked ( this . _setting . ConnectionSettings . Count - 1 ) ;
int index = num1 ;
while ( index < = num2 )
{
if ( Operators . CompareString ( searchname , this . SanitizeName ( this . _setting . ConnectionSettings [ index ] . Name ) , false ) = = 0 )
return this . _setting . ConnectionSettings [ index ] ;
checked { + + index ; }
}
return ( ConnectionSettingBase ) null ;
}
private FsBase CreateClient ( MyHttpServerConnection con , ConnectionSettingBase setting )
{
DAVServer . ConnectionCache tag = ( DAVServer . ConnectionCache ) con . Tag ;
if ( tag . fscache . ContainsKey ( setting ) )
return tag . fscache [ setting ] ;
FsBase client = setting . GetClient ( ) ;
client . LogMessage + = new EventHandler < LogMessageEventArgs > ( this . Client_OnMessage ) ;
client . GroupName = "UpDown " + Conversions . ToString ( Thread . CurrentThread . ManagedThreadId ) ;
tag . fscache . Add ( setting , client ) ;
return client ;
}
private string SanitizeName ( string str )
{
return str . Replace ( "\\" , "" ) . Replace ( "/" , "" ) . Replace ( ":" , "" ) . Replace ( "*" , "" ) . Replace ( "?" , "" ) . Replace ( "\"" , "" ) . Replace ( "<" , "" ) . Replace ( ">" , "" ) . Replace ( "|" , "" ) . Trim ( ) ;
}
private void Client_OnMessage ( object sender , LogMessageEventArgs e )
{
2017-10-06 18:20:35 +02:00
EventHandler < LogMessageEventArgs > logMessageEvent = this . LogMessage ;
2017-10-06 17:20:58 +02:00
if ( logMessageEvent = = null )
return ;
logMessageEvent ( RuntimeHelpers . GetObjectValue ( sender ) , e ) ;
}
public delegate ReturnedInfo closewrite_del ( Stream st ) ;
private class ConnectionCache
{
public Dictionary < ConnectionSettingBase , FsBase > fscache ;
public ConnectionCache ( )
{
this . fscache = new Dictionary < ConnectionSettingBase , FsBase > ( ) ;
}
}
}
}