xref: /haiku/src/kits/network/libnetservices/UrlProtocolRoster.cpp (revision 410ed2fbba58819ac21e27d3676739728416761d)
1 /*
2  * Copyright 2010-2013 Haiku Inc. All rights reserved.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  *		Christophe Huriaux, c.huriaux@gmail.com
7  *		Adrien Destugues, pulkomandy@pulkomandy.tk
8  */
9 
10 #include <UrlProtocolRoster.h>
11 
12 #include <new>
13 
14 #include <DataRequest.h>
15 #include <Debug.h>
16 #include <FileRequest.h>
17 #include <GopherRequest.h>
18 #include <HttpRequest.h>
19 #include <UrlRequest.h>
20 
21 #ifndef LIBNETAPI_DEPRECATED
22 using namespace BPrivate::Network;
23 #endif
24 
25 
26 #ifdef LIBNETAPI_DEPRECATED
27 /* static */ BUrlRequest*
28 BUrlProtocolRoster::MakeRequest(const BUrl& url,
29 	BUrlProtocolListener* listener, BUrlContext* context)
30 {
31 	// TODO: instanciate the correct BUrlProtocol using add-on interface
32 	if (url.Protocol() == "http") {
33 		return new(std::nothrow) BHttpRequest(url, false, "HTTP", listener,
34 			context);
35 	} else if (url.Protocol() == "https") {
36 		return new(std::nothrow) BHttpRequest(url, true, "HTTPS", listener,
37 			context);
38 	} else if (url.Protocol() == "file") {
39 		return new(std::nothrow) BFileRequest(url, listener, context);
40 	} else if (url.Protocol() == "data") {
41 		return new(std::nothrow) BDataRequest(url, listener, context);
42 	} else if (url.Protocol() == "gopher") {
43 		return new(std::nothrow) BGopherRequest(url, listener, context);
44 	}
45 
46 	return NULL;
47 }
48 
49 #else
50 
51 /* static */ BUrlRequest*
52 BUrlProtocolRoster::MakeRequest(const BUrl& url, BDataIO* output,
53 	BUrlProtocolListener* listener, BUrlContext* context)
54 {
55 	// TODO: instanciate the correct BUrlProtocol using add-on interface
56 	if (url.Protocol() == "http") {
57 		return new(std::nothrow) BHttpRequest(url, output, false, "HTTP",
58 			listener, context);
59 	} else if (url.Protocol() == "https") {
60 		return new(std::nothrow) BHttpRequest(url, output, true, "HTTPS",
61 			listener, context);
62 	} else if (url.Protocol() == "file") {
63 		return new(std::nothrow) BFileRequest(url, output, listener, context);
64 	} else if (url.Protocol() == "data") {
65 		return new(std::nothrow) BDataRequest(url, output, listener, context);
66 	} else if (url.Protocol() == "gopher") {
67 		return new(std::nothrow) BGopherRequest(url, output, listener, context);
68 	}
69 
70 	return NULL;
71 }
72 #endif //LIBNETAPI_DEPRECATED
73