| 207 | } |
| 208 | |
| 209 | void HTTPSession::processGet(Exception& ex, HTTPPacket& request, QueryReader& parameters) { |
| 210 | // use index http option in the case of GET request on a directory |
| 211 | |
| 212 | File& file(request.file); |
| 213 | |
| 214 | if (!file.isFolder()) { |
| 215 | // FILE // |
| 216 | |
| 217 | // 1 - priority on client method |
| 218 | if (file.extension().empty() && peer.onMessage(ex, file.name(), parameters)) // can be method! |
| 219 | return; |
| 220 | |
| 221 | // 2 - try to get a file |
| 222 | shared_ptr<Parameters> pFileParams(new MapParameters()); |
| 223 | ParameterWriter parameterWriter(*pFileParams); |
| 224 | if (!peer.onRead(ex, parameters, file, parameterWriter)) { |
| 225 | if (!ex) |
| 226 | ex.set(Exception::PERMISSION, "No authorization to see the content of ", file.path()); |
| 227 | return; |
| 228 | } |
| 229 | // If onRead has been authorised, and that the file is a multimedia file, and it doesn't exists (no VOD, filePath.lastModified()==0 means "doesn't exists") |
| 230 | // Subscribe for a live stream with the basename file as stream name |
| 231 | if (!file.exists()) { |
| 232 | if (request.contentType == HTTP::CONTENT_ABSENT) |
| 233 | request.contentType = HTTP::ExtensionToMIMEType(file.extension(), request.contentSubType); |
| 234 | if (request.contentType == HTTP::CONTENT_VIDEO || request.contentType == HTTP::CONTENT_AUDIO) { |
| 235 | if (openSubscribtion(ex, file.baseName(), _writer)) |
| 236 | return; |
| 237 | } |
| 238 | } |
| 239 | if (!file.isFolder()) |
| 240 | return _writer.writeFile(file.path(), pFileParams); |
| 241 | } |
| 242 | |
| 243 | |
| 244 | // FOLDER // |
| 245 | if (_index.find_last_of('.') == string::npos && peer.onMessage(ex, _index, parameters)) // can be method! |
| 246 | return; |
| 247 | |
| 248 | // Redirect to the file (get name to prevent path insertion), if impossible (_index empty or invalid) list directory |
| 249 | if (!_index.empty()) |
| 250 | file.setPath(file.path(),_index); |
| 251 | else if (!_indexDirectory) { |
| 252 | ex.set(Exception::PERMISSION, "No authorization to see the content of ", peer.path, '/'); |
| 253 | return; |
| 254 | } |
| 255 | shared_ptr<Parameters> pFileParams(new MapParameters()); |
| 256 | ParameterWriter parameterWriter(*pFileParams); |
| 257 | parameters.read(parameterWriter); |
| 258 | return _writer.writeFile(file.path(), pFileParams); // folder view or index redirection (without pass by onRead because can create a infinite loop |
| 259 | } |
| 260 | |
| 261 | } // namespace Mona |