Skip to content

Commit

Permalink
Merge commit '8f9e7bf4bfd2d235fde130e3cb81a6660cced38b' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
maksis committed Sep 25, 2024
2 parents a93efa7 + 8f9e7bf commit 53b283c
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 20 deletions.
31 changes: 23 additions & 8 deletions airdcpp-core/airdcpp/HttpConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
#include <airdcpp/ResourceManager.h>
#include <airdcpp/format.h>

#include <boost/algorithm/string/trim.hpp>

namespace dcpp {

HttpConnection::HttpConnection(bool aIsUnique, const HttpOptions& aOptions) :
Expand Down Expand Up @@ -246,15 +248,28 @@ void HttpConnection::on(BufferedSocketListener::Line, const string& aLine) noexc
if(size != -1) {
socket->setDataMode(size);
} else connState = CONN_CHUNKED;
} else if(Util::findSubString(aLine, "Content-Length") != string::npos) {
size = Util::toInt(aLine.substr(16, aLine.length() - 17));
} else if(mimeType.empty()) {
if(Util::findSubString(aLine, "Content-Encoding") != string::npos) {
if(aLine.substr(18, aLine.length() - 19) == "x-bzip2")
mimeType = "application/x-bzip2";
} else if(Util::findSubString(aLine, "Content-Type") != string::npos) {
mimeType = aLine.substr(14, aLine.length() - 15);
} else if (aLine.length() > 2) {
// Header
auto separator = aLine.find_first_of(':');
if (separator <= 1) {
return;
}

auto name = boost::algorithm::trim_copy(aLine.substr(0, separator));
auto value = boost::algorithm::trim_copy(aLine.substr(separator + 1));

if (name == "Content-Length") {
size = Util::toInt(value);
} else if (mimeType.empty()) {
if (name == "Content-Encoding") {
if (value == "x-bzip2")
mimeType = "application/x-bzip2";
} else if (name == "Content-Type") {
mimeType = value;
}
}

headers.try_emplace(name, value);
}
}

Expand Down
3 changes: 3 additions & 0 deletions airdcpp-core/airdcpp/HttpConnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class HttpConnection : private BufferedSocketListener, public Speaker<HttpConnec
int64_t getSize() const { return size; }
int64_t getDone() const { return done; }

const StringMap getHeaders() const noexcept { return headers; }
private:
enum RequestType { TYPE_GET, TYPE_POST, TYPE_UNKNOWN };
enum ConnectionStates { CONN_UNKNOWN, CONN_OK, CONN_FAILED, CONN_MOVED, CONN_CHUNKED };
Expand Down Expand Up @@ -87,6 +88,8 @@ class HttpConnection : private BufferedSocketListener, public Speaker<HttpConnec

const bool isUnique;
const HttpOptions options;

StringMap headers;
};

} // namespace dcpp
Expand Down
1 change: 1 addition & 0 deletions airdcpp-core/airdcpp/HttpDownload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ void HttpDownload::on(HttpConnectionListener::Failed, HttpConnection*, const str

void HttpDownload::on(HttpConnectionListener::Complete, HttpConnection*, const string& status_) noexcept {
status = status_;
headers = c->getHeaders();
f();
}

Expand Down
1 change: 1 addition & 0 deletions airdcpp-core/airdcpp/HttpDownload.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ struct HttpDownload : private HttpConnectionListener, private boost::noncopyable
HttpConnection* c;
string buf;
string status;
StringMap headers;
using CompletionF = std::function<void ()>;
CompletionF f;

Expand Down
14 changes: 9 additions & 5 deletions airdcpp-core/airdcpp/UpdateManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ UpdateManager::UpdateManager() : lastIPUpdate(GET_TICK()) {
links.geoip = "http://geoip.airdcpp.net";
links.ipcheck4 = "http://checkip.dyndns.org/";
links.ipcheck6 = "http://checkip.dyndns.org/";
links.language = "http://languages.airdcpp.net/tx/checkLangVersion.php?lc=%[locale]";
links.language = "https://languages.airdcpp.net/tx/checkLangVersion.php?lc=%[locale]";

SettingsManager::getInstance()->registerChangeHandler({
SettingsManager::GET_USER_COUNTRY,
Expand Down Expand Up @@ -340,10 +340,14 @@ void UpdateManager::completeLanguageCheck() {
if(!conn->buf.empty()) {
if (Util::toDouble(conn->buf) > Localization::getCurLanguageVersion()) {
fire(UpdateManagerListener::LanguageDownloading());
conns[CONN_LANGUAGE_FILE] = make_unique<HttpDownload>(
links.language + PathUtil::getFileName(Localization::getCurLanguageFilePath()),
[this] { completeLanguageDownload(); }
);

auto url = conn->headers.find("X-File-Location");
if (url != conn->headers.end()) {
conns[CONN_LANGUAGE_FILE] = make_unique<HttpDownload>(
url->second,
[this] { completeLanguageDownload(); }
);
}
} else {
fire(UpdateManagerListener::LanguageFinished());
}
Expand Down
1 change: 1 addition & 0 deletions airdcpp-core/scripts/generate_stringdefs.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ def write_text(strings, name):
(r'\n', '\n'),
(r'\\', '\\'),
(r'\"', '\"'),
(r'\'', '\''),
]

# Convert StringDefs to Android resource XML file that is supported by Transifex
Expand Down
36 changes: 29 additions & 7 deletions airdcpp-core/scripts/server/checkLangVersion.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,32 @@
<?php
$fileContent = @file_get_contents("/home/airdcpp-www/languages/tx/" . $_GET["locale"] . ".xml");
$pattern = '/(?<=\sVersion=")\d{1,9}(?=">)/';
if (preg_match($pattern, $fileContent, $matches)) {
echo $matches[0];
} else {
echo '0';
}
function removeFilename($url) {
$file_info = pathinfo($url);
return isset($file_info['extension'])
? str_replace($file_info['filename'] . "." . $file_info['extension'], "", $url)
: $url;
}

if (!isset($_GET["lc"])) {
$fileContent = 'Locale missing';
http_response_code(400);
return;
}

header('X-File-Location: https://' . $_SERVER['HTTP_HOST'] . removeFilename($_SERVER['REQUEST_URI']) . $_GET["lc"] . ".xml");

$filePath = getcwd() . '/' . $_GET["lc"] . ".xml";
if (!file_exists($filePath)) {
$fileContent = 'Invalid locale';
http_response_code(404);
return;
}

$fileContent = @file_get_contents($filePath);
$pattern = '/(?<=\sRevision=")\d{1,9}(?=">)/';
if (preg_match($pattern, $fileContent, $matches)) {
echo $matches[0];
} else {
echo '0';
}
?>

6 changes: 6 additions & 0 deletions airdcpp-core/scripts/update_languages.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import argparse
import xml.etree.ElementTree as ET
from pathlib import Path

import glob, os
import shutil
Expand Down Expand Up @@ -32,6 +33,7 @@ def get_new_version(file_path):
(r'\n', '\n'),
(r'\\', '\\'),
(r'\"', '\"'),
(r'\'', '\''),
]


Expand All @@ -47,6 +49,7 @@ def convert_file(input_file, output_file):
for child in source_root:
string = ET.SubElement(output_strings, 'String', Name=child.attrib['name'])

text = child.text
for str, replacement in replace_map:
text = text.replace(str, replacement)

Expand Down Expand Up @@ -74,6 +77,9 @@ def has_changed(source_file_path, temp_file_path):
def update_translation_files(source_directory, target_directory, force = False):
temp_directory = os.path.join(source_directory, 'previous')

Path(temp_directory).mkdir(parents=True, exist_ok=True)
Path(target_directory).mkdir(parents=True, exist_ok=True)

converted = 0
unchanged = 0
failed = 0
Expand Down

0 comments on commit 53b283c

Please sign in to comment.