128 if (!
file.exists())
return ruleCount;
130 if (!
file.open(QIODevice::ReadOnly | QIODevice::Text))
137 qint64 bytesRead = 0;
142 int parseErrorCount = 0;
143 const auto addLog = [&parseErrorCount](
const QString &msg)
151 bytesRead =
file.read(buffer.data() + offset,
BUFFER_SIZE - offset - 1);
154 const int dataSize = bytesRead + offset;
155 if ((bytesRead == 0) && (dataSize == 0))
158 for (start = 0; start < dataSize; ++start)
162 if (!((bytesRead == 0) && (dataSize > 0)))
164 for (
int i = start; i < dataSize; ++i)
166 if (buffer[i] ==
'\n')
179 endOfLine = dataSize;
180 buffer[dataSize] =
'\0';
187 offset = dataSize - start;
188 memmove(buffer.data(), buffer.data() + start, offset);
194 if ((buffer[start] ==
'#')
195 || ((buffer[start] ==
'/') && ((start + 1 < dataSize) && (buffer[start + 1] ==
'/'))))
205 if (firstComma != -1)
209 if (firstComma != -1)
212 const long int nbAccess = strtol(buffer.data() + firstComma + 1,
nullptr, 10);
222 const int endOfIPRange = ((firstComma == -1) ? (endOfLine - 1) : (firstComma - 1));
227 addLog(tr(
"IP filter line %1 is malformed.").arg(nbLine));
232 lt::address startAddr;
233 int newStart =
trim(buffer.data(), start, delimIP - 1);
237 addLog(tr(
"IP filter line %1 is malformed. Start IP of the range is malformed.").arg(nbLine));
243 newStart =
trim(buffer.data(), delimIP + 1, endOfIPRange);
247 addLog(tr(
"IP filter line %1 is malformed. End IP of the range is malformed.").arg(nbLine));
252 if ((startAddr.is_v4() != endAddr.is_v4())
253 || (startAddr.is_v6() != endAddr.is_v6()))
256 addLog(tr(
"IP filter line %1 is malformed. One IP is IPv4 and the other is IPv6!").arg(nbLine));
266 m_filter.add_rule(startAddr, endAddr, lt::ip_filter::blocked);
269 catch (
const std::exception &
e)
272 addLog(tr(
"IP filter exception thrown for line %1. Exception is: %2")
273 .arg(nbLine).arg(QString::fromLocal8Bit(
e.what())));
277 if (start >= dataSize)
282 LogMsg(tr(
"%1 extra IP filter parsing errors occurred.",
"513 extra IP filter parsing errors occurred.")
int findAndNullDelimiter(char *const data, char delimiter, int start, int end, bool reverse=false)
int trim(char *const data, int start, int end)
void LogMsg(const QString &message, const Log::MsgType &type)
bool parseIPAddress(const char *data, lt::address &address)
const int MAX_LOGGED_ERRORS
file(GLOB QBT_TS_FILES "${qBittorrent_SOURCE_DIR}/src/lang/*.ts") set_source_files_properties($