Skip to content

Commit

Permalink
Enable use of Exiv2::CurlIo
Browse files Browse the repository at this point in the history
If needed, a dummy CurlIo class is used so SWIG generated files with
EXV_USE_CURL enabled can be linked with libexiv2 built with
EXV_USE_CURL disabled. Similarly SWIG generated files with EXV_USE_CURL
disabled can be linked with libexiv2 built with EXV_USE_CURL enabled.
  • Loading branch information
jim-easterbrook committed Feb 19, 2024
1 parent a1e64cf commit bf8838b
Show file tree
Hide file tree
Showing 20 changed files with 3,410 additions and 1,260 deletions.
16 changes: 16 additions & 0 deletions src/interface/basicio.i
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
%include "shared/enum.i"
%include "shared/exception.i"
%include "shared/keep_reference.i"
%include "shared/remoteio_derived.i"
%include "shared/unique_ptr.i"
%include "shared/windows_path.i"

Expand Down Expand Up @@ -94,6 +95,10 @@ static swig_type_info* basicio_subtype(Exiv2::BasicIo* ptr) {
else if (dynamic_cast<Exiv2::RemoteIo*>(ptr)) {
if (dynamic_cast<Exiv2::HttpIo*>(ptr))
return $descriptor(Exiv2::HttpIo*);
#ifdef EXV_USE_CURL
else if (dynamic_cast<Exiv2::CurlIo*>(ptr))
return $descriptor(Exiv2::CurlIo*);
#endif
else
return $descriptor(Exiv2::RemoteIo*);
}
Expand All @@ -109,6 +114,16 @@ static swig_type_info* basicio_subtype(Exiv2::BasicIo* ptr) {
ptr, basicio_subtype(ptr), SWIG_POINTER_OWN);
}

// CurlIo destructor isn't seen by SWIG in v0.27.x
#if EXIV2_VERSION_HEX < 0x001c0000
#ifdef EXV_USE_CURL
%extend Exiv2::CurlIo {
~CurlIo() {};
}
%ignore Exiv2::CurlIo::~CurlIo;
#endif
#endif

// readOrThrow & seekOrThrow use ErrorCode internally without Exiv2:: prefix
// as if SWIG doesn't realise ErrorCode is in the Exiv2 namespace
%{
Expand Down Expand Up @@ -198,6 +213,7 @@ DEPRECATED_ENUM(BasicIo, Position, "Seek starting positions.",
%ignore Exiv2::BasicIo::~BasicIo;
%ignore Exiv2::BasicIo::bigBlock_;
%ignore Exiv2::BasicIo::populateFakeData;
%ignore Exiv2::curlWriter;
%ignore Exiv2::IoCloser;
%ignore Exiv2::ReplaceStringInPlace;
%ignore Exiv2::readFile;
Expand Down
1 change: 1 addition & 0 deletions src/interface/image.i
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
%include "shared/enum.i"
%include "shared/exception.i"
%include "shared/keep_reference.i"
%include "shared/remoteio_derived.i"
%include "shared/windows_path.i"

%include "std_string.i"
Expand Down
1 change: 1 addition & 0 deletions src/interface/preview.i
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ For Exif thumbnail images see the :py:class:`ExifThumb` class.";
%include "shared/buffers.i"
%include "shared/exception.i"
%include "shared/keep_reference.i"
%include "shared/remoteio_derived.i"
%include "shared/struct_dict.i"
%include "shared/windows_path.i"

Expand Down
37 changes: 37 additions & 0 deletions src/interface/shared/remoteio_derived.i
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// python-exiv2 - Python interface to libexiv2
// http://github.com/jim-easterbrook/python-exiv2
// Copyright (C) 2024 Jim Easterbrook [email protected]
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.


// Replacement for CurlIo missing from linked libexiv2
// First ifdef EXV_USE_CURL detects SWIGging with EXV_USE_CURL set
// Second ifndef EXV_USE_CURL detects compiling with EXV_USE_CURL unset
#ifdef EXV_USE_CURL
%{
#ifndef EXV_USE_CURL
namespace Exiv2 {
class CurlIo : public RemoteIo {
public:
CurlIo(const std::string& url, size_t blockSize=0) {
throw std::runtime_error(
"CurlIo not enabled in linked libexiv2");
};
};
}
#endif
%}
#endif

14 changes: 12 additions & 2 deletions src/interface/version.i
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,19 @@ EXCEPTION()

// Function to report build options used
%feature("docstring") versionInfo "Return a dict of libexiv2 build options."
#ifndef EXV_USE_CURL
%{
#undef EXV_USE_CURL
%}
#endif
%inline %{
static PyObject* versionInfo() {
bool nls = false;
bool bmff = false;
bool video = false;
bool unicode = false;
bool webready = false;
bool curl = false;
#ifdef EXV_ENABLE_NLS
nls = true;
#endif
Expand All @@ -58,13 +64,17 @@ static PyObject* versionInfo() {
#ifdef EXV_ENABLE_WEBREADY
webready = true;
#endif
return Py_BuildValue("{ss,sN,sN,sN,sN,sN}",
#ifdef EXV_USE_CURL
curl = true;
#endif
return Py_BuildValue("{ss,sN,sN,sN,sN,sN,sN}",
"version", Exiv2::version(),
"EXV_ENABLE_NLS", PyBool_FromLong(nls),
"EXV_ENABLE_BMFF", PyBool_FromLong(bmff),
"EXV_ENABLE_VIDEO", PyBool_FromLong(video),
"EXV_UNICODE_PATH", PyBool_FromLong(unicode),
"EXV_ENABLE_WEBREADY", PyBool_FromLong(webready));
"EXV_ENABLE_WEBREADY", PyBool_FromLong(webready),
"EXV_USE_CURL", PyBool_FromLong(curl));
};
%}

Expand Down
Loading

0 comments on commit bf8838b

Please sign in to comment.