1// qhostaddress.sip generated by MetaSIP 2// 3// This file is part of the QtNetwork Python extension module. 4// 5// Copyright (c) 2021 Riverbank Computing Limited <info@riverbankcomputing.com> 6// 7// This file is part of PyQt5. 8// 9// This file may be used under the terms of the GNU General Public License 10// version 3.0 as published by the Free Software Foundation and appearing in 11// the file LICENSE included in the packaging of this file. Please review the 12// following information to ensure the GNU General Public License version 3.0 13// requirements will be met: http://www.gnu.org/copyleft/gpl.html. 14// 15// If you do not wish to use this file under the terms of the GPL version 3.0 16// then you may purchase a commercial license. For more information contact 17// info@riverbankcomputing.com. 18// 19// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 20// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 21 22 23class QHostAddress /TypeHintIn="Union[QHostAddress, QHostAddress.SpecialAddress]"/ 24{ 25%TypeHeaderCode 26#include <qhostaddress.h> 27%End 28 29%ConvertToTypeCode 30// SIP doesn't support automatic type convertors so we explicitly allow a 31// QHostAddress::SpecialAddress to be used whenever a QHostAddress is expected. 32 33if (sipIsErr == NULL) 34 return (PyObject_TypeCheck(sipPy, sipTypeAsPyTypeObject(sipType_QHostAddress_SpecialAddress)) || 35 sipCanConvertToType(sipPy, sipType_QHostAddress, SIP_NO_CONVERTORS)); 36 37if (PyObject_TypeCheck(sipPy, sipTypeAsPyTypeObject(sipType_QHostAddress_SpecialAddress))) 38{ 39 *sipCppPtr = new QHostAddress((QHostAddress::SpecialAddress)SIPLong_AsLong(sipPy)); 40 41 return sipGetState(sipTransferObj); 42} 43 44*sipCppPtr = reinterpret_cast<QHostAddress *>(sipConvertToType(sipPy, sipType_QHostAddress, sipTransferObj, SIP_NO_CONVERTORS, 0, sipIsErr)); 45 46return 0; 47%End 48 49public: 50 enum SpecialAddress 51 { 52 Null, 53 Broadcast, 54 LocalHost, 55 LocalHostIPv6, 56 AnyIPv4, 57 AnyIPv6, 58 Any, 59 }; 60 61 QHostAddress(); 62 QHostAddress(QHostAddress::SpecialAddress address /Constrained/); 63 explicit QHostAddress(quint32 ip4Addr); 64 explicit QHostAddress(const QString &address); 65 explicit QHostAddress(const Q_IPV6ADDR &ip6Addr); 66 QHostAddress(const QHostAddress ©); 67 ~QHostAddress(); 68%If (Qt_5_8_0 -) 69 void setAddress(QHostAddress::SpecialAddress address /Constrained/); 70%End 71 void setAddress(quint32 ip4Addr); 72 bool setAddress(const QString &address); 73 void setAddress(const Q_IPV6ADDR &ip6Addr); 74 QAbstractSocket::NetworkLayerProtocol protocol() const; 75 quint32 toIPv4Address() const; 76 Q_IPV6ADDR toIPv6Address() const; 77 QString toString() const; 78 QString scopeId() const; 79 void setScopeId(const QString &id); 80 bool operator==(const QHostAddress &address) const; 81 bool operator==(QHostAddress::SpecialAddress address) const; 82 bool operator!=(const QHostAddress &address) const; 83 bool operator!=(QHostAddress::SpecialAddress address) const; 84 bool isNull() const; 85 void clear(); 86 long __hash__() const; 87%MethodCode 88 sipRes = qHash(*sipCpp); 89%End 90 91 bool isInSubnet(const QHostAddress &subnet, int netmask) const; 92 bool isInSubnet(const QPair<QHostAddress, int> &subnet) const; 93 bool isLoopback() const; 94 static QPair<QHostAddress, int> parseSubnet(const QString &subnet); 95%If (Qt_5_6_0 -) 96 void swap(QHostAddress &other /Constrained/); 97%End 98%If (Qt_5_6_0 -) 99 bool isMulticast() const; 100%End 101%If (Qt_5_8_0 -) 102 103 enum ConversionModeFlag 104 { 105 ConvertV4MappedToIPv4, 106 ConvertV4CompatToIPv4, 107 ConvertUnspecifiedAddress, 108 ConvertLocalHost, 109 TolerantConversion, 110 StrictConversion, 111 }; 112 113%End 114%If (Qt_5_8_0 -) 115 typedef QFlags<QHostAddress::ConversionModeFlag> ConversionMode; 116%End 117%If (Qt_5_8_0 -) 118 bool isEqual(const QHostAddress &address, QHostAddress::ConversionMode mode = QHostAddress::TolerantConversion) const; 119%End 120%If (Qt_5_11_0 -) 121 bool isGlobal() const; 122%End 123%If (Qt_5_11_0 -) 124 bool isLinkLocal() const; 125%End 126%If (Qt_5_11_0 -) 127 bool isSiteLocal() const; 128%End 129%If (Qt_5_11_0 -) 130 bool isUniqueLocalUnicast() const; 131%End 132%If (Qt_5_11_0 -) 133 bool isBroadcast() const; 134%End 135}; 136 137bool operator==(QHostAddress::SpecialAddress address1, const QHostAddress &address2); 138%If (Qt_5_9_0 -) 139bool operator!=(QHostAddress::SpecialAddress lhs, const QHostAddress &rhs); 140%End 141QDataStream &operator<<(QDataStream &, const QHostAddress &) /ReleaseGIL/; 142QDataStream &operator>>(QDataStream &, QHostAddress &) /ReleaseGIL/; 143// Q_IPV6ADDR is implemented as a Python 16-tuple of ints. 144%MappedType Q_IPV6ADDR /TypeHint="Tuple[int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int]"/ 145{ 146%TypeHeaderCode 147#include <qhostaddress.h> 148%End 149 150%ConvertFromTypeCode 151 // Create the tuple. 152 PyObject *t; 153 154 if ((t = PyTuple_New(16)) == NULL) 155 return NULL; 156 157 // Set the tuple elements. 158 for (int i = 0; i < 16; ++i) 159 { 160 PyObject *pobj; 161 162 if ((pobj = SIPLong_FromLong((*sipCpp)[i])) == NULL) 163 { 164 Py_DECREF(t); 165 166 return NULL; 167 } 168 169 PyTuple_SetItem(t, i, pobj); 170 } 171 172 return t; 173%End 174 175%ConvertToTypeCode 176 // Check the type if that is all that is required. 177 if (sipIsErr == NULL) 178 return (PySequence_Check(sipPy) && PySequence_Size(sipPy) == 16); 179 180 Q_IPV6ADDR *qa = new Q_IPV6ADDR; 181 182 for (Py_ssize_t i = 0; i < 16; ++i) 183 { 184 PyObject *itm = PySequence_GetItem(sipPy, i); 185 186 if (!itm) 187 { 188 delete qa; 189 *sipIsErr = 1; 190 191 return 0; 192 } 193 194 (*qa)[i] = SIPLong_AsLong(itm); 195 196 Py_DECREF(itm); 197 } 198 199 *sipCppPtr = qa; 200 201 return sipGetState(sipTransferObj); 202%End 203}; 204%If (Qt_5_8_0 -) 205QFlags<QHostAddress::ConversionModeFlag> operator|(QHostAddress::ConversionModeFlag f1, QFlags<QHostAddress::ConversionModeFlag> f2); 206%End 207