Making sure mono_marshal_free is used instead of g_free in mono_string_builder_to_utf8
[mono.git] / mcs / class / System / System.Net / FtpWebResponse.cs
1 //
2 // System.Net.FtpWebResponse.cs
3 //
4 // Authors:
5 //      Carlos Alberto Cortez (calberto.cortez@gmail.com)
6 //
7 // (c) Copyright 2006 Novell, Inc. (http://www.novell.com)
8 //
9
10 using System;
11 using System.IO;
12 using System.Runtime.Serialization;
13 using System.Net;
14
15 namespace System.Net
16 {
17         public class FtpWebResponse : WebResponse
18         {
19                 Stream stream;
20                 Uri uri;
21                 FtpStatusCode statusCode;
22                 DateTime lastModified = DateTime.MinValue;
23                 string bannerMessage = String.Empty;
24                 string welcomeMessage = String.Empty;
25                 string exitMessage = String.Empty;
26                 string statusDescription;
27                 string method;
28                 //bool keepAlive;
29                 bool disposed;
30                 FtpWebRequest request;
31                 internal long contentLength = -1;
32                 
33                 internal FtpWebResponse (FtpWebRequest request, Uri uri, string method, bool keepAlive)
34                 {
35                         this.request = request;
36                         this.uri = uri;
37                         this.method = method;
38                         //this.keepAlive = keepAlive;
39                 }
40
41                 internal FtpWebResponse (FtpWebRequest request, Uri uri, string method, FtpStatusCode statusCode, string statusDescription)
42                 {
43                         this.request = request;
44                         this.uri = uri;
45                         this.method = method;
46                         this.statusCode = statusCode;
47                         this.statusDescription = statusDescription;
48                 }
49
50                 internal FtpWebResponse (FtpWebRequest request, Uri uri, string method, FtpStatus status) :
51                         this (request, uri, method, status.StatusCode, status.StatusDescription)
52                 {
53                 }
54                 
55                 public override long ContentLength {
56                         get {
57                                 return contentLength;
58                         }
59                 }
60
61                 public override WebHeaderCollection Headers {
62                         get {
63                                 return new WebHeaderCollection ();
64                         }
65                 }
66
67                 public override Uri ResponseUri {
68                         get {
69                                 return uri;
70                         }
71                 }
72
73                 public DateTime LastModified {
74                         get {
75                                 return lastModified;
76                         }
77                         internal set {
78                                 lastModified = value;
79                         }
80                 }
81
82                 public string BannerMessage {
83                         get {
84                                 return bannerMessage;
85                         }
86                         internal set {
87                                 bannerMessage = value;
88                         }
89                 }
90                 
91                 public string WelcomeMessage {
92                         get {
93                                 return welcomeMessage;
94                         }
95                         internal set {
96                                 welcomeMessage = value;
97                         }
98                 }
99
100                 public string ExitMessage {
101                         get {
102                                 return exitMessage;
103                         }
104                         internal set {
105                                 exitMessage = value;
106                         }
107                 }
108
109                 public FtpStatusCode StatusCode {
110                         get {
111                                 return statusCode;
112                         }
113                         internal set {
114                                 statusCode = value;
115                         }
116                 }
117
118                 public string StatusDescription {
119                         get {
120                                 return statusDescription;
121                         }
122                         internal set {
123                                 statusDescription = value;
124                         }
125                 }
126                 
127                 public override void Close ()
128                 {
129                         if (disposed)
130                                 return;
131                         
132                         disposed = true;
133                         if (stream != null) {
134                                 stream.Close ();
135                                 if (stream == Stream.Null)
136                                         request.OperationCompleted ();
137                         }
138                         stream = null;
139                 }
140
141                 public override Stream GetResponseStream ()
142                 {
143                         if (stream == null)
144                                 return Stream.Null; // After a STOR we get this
145                         
146                         if (method != WebRequestMethods.Ftp.DownloadFile &&
147                                         method != WebRequestMethods.Ftp.ListDirectory)
148                                 CheckDisposed ();
149                         
150                         return stream;
151                 }
152
153                 internal Stream Stream {
154                         set {
155                                 stream = value;
156                         }
157
158                         get { return stream; }
159                 }
160
161                 internal void UpdateStatus (FtpStatus status) {
162                         statusCode = status.StatusCode;
163                         statusDescription = status.StatusDescription;
164                 }
165
166                 void CheckDisposed ()
167                 {
168                         if (disposed)
169                                 throw new ObjectDisposedException (GetType ().FullName);
170                 }
171
172                 internal bool IsFinal () {
173                         return ((int) statusCode >= 200);
174                 }
175         }
176 }
177
178