00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "bioPtr.h"
00016
00017 #ifdef HAVE_OPENSSL
00018
00019 #include "urlSpec.h"
00020 #include "config_downloader.h"
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 BioPtr::
00031 BioPtr(const URLSpec &url) {
00032 if (url.get_scheme() == "file") {
00033
00034 string filename = URLSpec::unquote(url.get_path());
00035 #ifdef _WIN32
00036
00037
00038
00039 if (!filename.empty()) {
00040 if (filename[0] == '/' || filename[0] == '\\') {
00041 Filename fname = Filename::from_os_specific(filename.substr(1));
00042 if (fname.is_local()) {
00043
00044 fname = string("/") + fname.get_fullpath();
00045 }
00046 filename = fname.to_os_specific();
00047 }
00048 }
00049 #endif // _WIN32
00050 _server_name = "";
00051 _port = 0;
00052 _bio = BIO_new_file(filename.c_str(), "rb");
00053
00054 } else {
00055
00056 _server_name = url.get_server();
00057 _port = url.get_port();
00058 _bio = BIO_new_connect((char *)_server_name.c_str());
00059 BIO_set_conn_int_port(_bio, &_port);
00060 }
00061 }
00062
00063
00064
00065
00066
00067
00068 BioPtr::
00069 ~BioPtr() {
00070 if (_bio != (BIO *)NULL) {
00071 if (downloader_cat.is_debug() && !_server_name.empty()) {
00072 downloader_cat.debug()
00073 << "Dropping connection to " << _server_name << ":" << _port << "\n";
00074 }
00075
00076 BIO_free_all(_bio);
00077 _bio = (BIO *)NULL;
00078 }
00079 }
00080
00081 #endif // HAVE_OPENSSL