Panda3D
|
00001 // Filename: bioPtr.cxx 00002 // Created by: drose (15Oct02) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 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 // Function: BioPtr::Constructor 00024 // Access: Public 00025 // Description: This flavor of the constructor automatically creates 00026 // a socket BIO and feeds it the server and port name 00027 // from the indicated URL. It doesn't call 00028 // BIO_do_connect(), though. 00029 //////////////////////////////////////////////////////////////////// 00030 BioPtr:: 00031 BioPtr(const URLSpec &url) { 00032 if (url.get_scheme() == "file") { 00033 // We're just reading a disk file. 00034 string filename = URLSpec::unquote(url.get_path()); 00035 #ifdef _WIN32 00036 // On Windows, we have to munge the filename specially, because it's 00037 // been URL-munged. It might begin with a leading slash as well as 00038 // a drive letter. Clean up that nonsense. 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 // Put the slash back on. 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 // A normal network-based URL. 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 // Function: BioPtr::Destructor 00065 // Access: Public 00066 // Description: 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