Replace POCO with CURL.
continuous-integration/drone/push Build is failing
Details
continuous-integration/drone/push Build is failing
Details
This commit is contained in:
parent
18a0edb30a
commit
953c1cf3e7
11
.drone.yml
11
.drone.yml
|
@ -1,3 +1,4 @@
|
||||||
|
# -*- fill-column: 1000 -*-
|
||||||
kind: pipeline
|
kind: pipeline
|
||||||
name: on_push
|
name: on_push
|
||||||
|
|
||||||
|
@ -30,7 +31,7 @@ steps:
|
||||||
- gpg --armor --export 0x60c317803a41ba51845e371a1e9377a2ba9ef27f | apt-key add -
|
- gpg --armor --export 0x60c317803a41ba51845e371a1e9377a2ba9ef27f | apt-key add -
|
||||||
- apt-get update -q
|
- apt-get update -q
|
||||||
- apt-get install -qy -t xenial g++-5
|
- apt-get install -qy -t xenial g++-5
|
||||||
- apt-get install -qy cmake pkg-config libpoco-dev libjsoncpp-dev asciidoc
|
- apt-get install -qy cmake pkg-config libcurl4-openssl-dev libjsoncpp-dev asciidoc
|
||||||
- rm -rf build && mkdir -p build && cd build
|
- rm -rf build && mkdir -p build && cd build
|
||||||
- cmake ..
|
- cmake ..
|
||||||
- make VERBOSE=1
|
- make VERBOSE=1
|
||||||
|
@ -56,7 +57,7 @@ steps:
|
||||||
- gpg --armor --export 0x60c317803a41ba51845e371a1e9377a2ba9ef27f | apt-key add -
|
- gpg --armor --export 0x60c317803a41ba51845e371a1e9377a2ba9ef27f | apt-key add -
|
||||||
- apt-get update -q
|
- apt-get update -q
|
||||||
- apt-get install -qy -t xenial g++-9
|
- apt-get install -qy -t xenial g++-9
|
||||||
- apt-get install -qy cmake pkg-config libpoco-dev libjsoncpp-dev asciidoc
|
- apt-get install -qy cmake pkg-config libcurl4-openssl-dev libjsoncpp-dev asciidoc
|
||||||
- rm -rf build && mkdir -p build && cd build
|
- rm -rf build && mkdir -p build && cd build
|
||||||
- cmake ..
|
- cmake ..
|
||||||
- make VERBOSE=1
|
- make VERBOSE=1
|
||||||
|
@ -75,7 +76,7 @@ steps:
|
||||||
- rm /etc/apt/apt.conf.d/docker-clean
|
- rm /etc/apt/apt.conf.d/docker-clean
|
||||||
- alias apt-get='rm -f /var/cache/apt/archives/lock && apt-get'
|
- alias apt-get='rm -f /var/cache/apt/archives/lock && apt-get'
|
||||||
- apt-get update -q
|
- apt-get update -q
|
||||||
- apt-get install -qy clang cmake pkg-config libpoco-dev libjsoncpp-dev asciidoc
|
- apt-get install -qy clang cmake pkg-config libcurl4-openssl-dev libjsoncpp-dev asciidoc
|
||||||
- rm -rf build && mkdir -p build && cd build
|
- rm -rf build && mkdir -p build && cd build
|
||||||
- cmake ..
|
- cmake ..
|
||||||
- make VERBOSE=1
|
- make VERBOSE=1
|
||||||
|
@ -94,7 +95,7 @@ steps:
|
||||||
- rm /etc/apt/apt.conf.d/docker-clean
|
- rm /etc/apt/apt.conf.d/docker-clean
|
||||||
- alias apt-get='rm -f /var/cache/apt/archives/lock && apt-get'
|
- alias apt-get='rm -f /var/cache/apt/archives/lock && apt-get'
|
||||||
- apt-get update -q
|
- apt-get update -q
|
||||||
- apt-get install -qy clang cmake pkg-config libpoco-dev libjsoncpp-dev asciidoc
|
- apt-get install -qy clang cmake pkg-config libcurl4-openssl-dev libjsoncpp-dev asciidoc
|
||||||
- rm -rf build && mkdir -p build && cd build
|
- rm -rf build && mkdir -p build && cd build
|
||||||
- cmake ..
|
- cmake ..
|
||||||
- make VERBOSE=1
|
- make VERBOSE=1
|
||||||
|
@ -106,7 +107,7 @@ steps:
|
||||||
image: drillster/drone-email
|
image: drillster/drone-email
|
||||||
pull: always
|
pull: always
|
||||||
settings:
|
settings:
|
||||||
host: cryptoparty-celle.de
|
host: mail.tzend.de
|
||||||
from: drone@tzend.de
|
from: drone@tzend.de
|
||||||
username:
|
username:
|
||||||
from_secret: email_username
|
from_secret: email_username
|
||||||
|
|
|
@ -26,8 +26,7 @@ include(cmake/debug_flags.cmake)
|
||||||
|
|
||||||
find_package(PkgConfig REQUIRED)
|
find_package(PkgConfig REQUIRED)
|
||||||
pkg_check_modules(jsoncpp REQUIRED IMPORTED_TARGET jsoncpp)
|
pkg_check_modules(jsoncpp REQUIRED IMPORTED_TARGET jsoncpp)
|
||||||
# Some distributions do not contain Poco*Config.cmake recipes.
|
find_package(CURL 7.56 REQUIRED)
|
||||||
find_package(Poco COMPONENTS Foundation Net NetSSL CONFIG)
|
|
||||||
|
|
||||||
add_subdirectory(src)
|
add_subdirectory(src)
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,7 @@ emerge -a dev-util/gitea2rss
|
||||||
* C++ compiler (tested: https://gcc.gnu.org/[gcc] 5/8/9,
|
* C++ compiler (tested: https://gcc.gnu.org/[gcc] 5/8/9,
|
||||||
https://llvm.org/[clang] 3/7)
|
https://llvm.org/[clang] 3/7)
|
||||||
* https://cmake.org/[cmake] (at least: 3.6)
|
* https://cmake.org/[cmake] (at least: 3.6)
|
||||||
* https://pocoproject.org/[POCO] (tested: 1.9 / 1.7)
|
* https://curl.haxx.se/libcurl/[libcurl] (at least: 7.56)
|
||||||
* https://github.com/open-source-parsers/jsoncpp[jsoncpp] (tested: 1.8)
|
* https://github.com/open-source-parsers/jsoncpp[jsoncpp] (tested: 1.8)
|
||||||
* Optional:
|
* Optional:
|
||||||
** Manpage: http://asciidoc.org/[asciidoc] (tested: 8.6)
|
** Manpage: http://asciidoc.org/[asciidoc] (tested: 8.6)
|
||||||
|
@ -40,7 +40,7 @@ emerge -a dev-util/gitea2rss
|
||||||
|
|
||||||
[source,shell]
|
[source,shell]
|
||||||
----
|
----
|
||||||
apt-get install build-essential cmake libpoco-dev libjsoncpp-dev asciidoc
|
apt-get install build-essential cmake libcurl4-openssl-dev libjsoncpp-dev asciidoc
|
||||||
----
|
----
|
||||||
|
|
||||||
==== Get sourcecode
|
==== Get sourcecode
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
:doctype: manpage
|
:doctype: manpage
|
||||||
:Author: tastytea
|
:Author: tastytea
|
||||||
:Email: tastytea@tastytea.de
|
:Email: tastytea@tastytea.de
|
||||||
:Date: 2019-08-09
|
:Date: 2020-10-24
|
||||||
:Revision: 0.0.0
|
:Revision: 0.0.0
|
||||||
:man source: gitea2rss
|
:man source: gitea2rss
|
||||||
:man version: {revision}
|
:man version: {revision}
|
||||||
|
@ -57,8 +57,8 @@ this in it:
|
||||||
|
|
||||||
== PROXY SERVERS
|
== PROXY SERVERS
|
||||||
|
|
||||||
*gitea2rss* supports HTTP proxies set via the environment variable
|
Since *gitea2rss* is built on libcurl, it respects the same proxy environment
|
||||||
_http_proxy_. Accepted formats are _http://host:port/_ or _host:port_.
|
variables. See *curl*(1), section _ENVIRONMENT_.
|
||||||
|
|
||||||
== EXAMPLES
|
== EXAMPLES
|
||||||
|
|
||||||
|
@ -95,7 +95,7 @@ _http_proxy_. Accepted formats are _http://host:port/_ or _host:port_.
|
||||||
|
|
||||||
== SEE ALSO
|
== SEE ALSO
|
||||||
|
|
||||||
*crontab*(1), *crontab*(5)
|
*crontab*(1), *crontab*(5), *curl*(1)
|
||||||
|
|
||||||
== REPORTING BUGS
|
== REPORTING BUGS
|
||||||
|
|
||||||
|
|
|
@ -11,26 +11,6 @@ target_include_directories(${PROJECT_NAME}
|
||||||
PRIVATE "$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>")
|
PRIVATE "$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>")
|
||||||
|
|
||||||
target_link_libraries(${PROJECT_NAME}
|
target_link_libraries(${PROJECT_NAME}
|
||||||
PRIVATE PkgConfig::jsoncpp)
|
PRIVATE PkgConfig::jsoncpp CURL::libcurl)
|
||||||
|
|
||||||
# If no Poco*Config.cmake recipes are found, look for headers in standard dirs.
|
|
||||||
if(PocoNetSSL_FOUND)
|
|
||||||
target_link_libraries(${PROJECT_NAME}
|
|
||||||
PRIVATE Poco::Foundation Poco::Net Poco::NetSSL)
|
|
||||||
else()
|
|
||||||
find_file(Poco_h NAMES "Poco/Poco.h"
|
|
||||||
PATHS "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}")
|
|
||||||
|
|
||||||
if("${Poco_h}" STREQUAL "Poco_h-NOTFOUND")
|
|
||||||
message(FATAL_ERROR "Could not find POCO.")
|
|
||||||
else()
|
|
||||||
message(WARNING
|
|
||||||
"Your distribution of POCO doesn't contain the *Config.cmake recipes, "
|
|
||||||
"but the files seem to be in the standard directories. "
|
|
||||||
"Let's hope this works.")
|
|
||||||
target_link_libraries(${PROJECT_NAME}
|
|
||||||
PRIVATE PocoFoundation PocoNet PocoNetSSL)
|
|
||||||
endif()
|
|
||||||
endif()
|
|
||||||
|
|
||||||
install(TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_BINDIR})
|
install(TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_BINDIR})
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/* This file is part of gitea2rss.
|
/* This file is part of gitea2rss.
|
||||||
* Copyright © 2019 tastytea <tastytea@tastytea.de>
|
* Copyright © 2019, 2020 tastytea <tastytea@tastytea.de>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -17,22 +17,22 @@
|
||||||
#ifndef GITEA2RSS_HPP
|
#ifndef GITEA2RSS_HPP
|
||||||
#define GITEA2RSS_HPP
|
#define GITEA2RSS_HPP
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <ctime>
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
#include <ctime>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
using std::string;
|
using std::string;
|
||||||
using std::chrono::system_clock;
|
|
||||||
using std::uint8_t;
|
using std::uint8_t;
|
||||||
|
using std::chrono::system_clock;
|
||||||
|
|
||||||
extern bool cgi;
|
extern bool cgi;
|
||||||
|
|
||||||
//! Set proxy from environment variable `http_proxy`.
|
|
||||||
void set_proxy();
|
|
||||||
|
|
||||||
//! Fetch HTTP document.
|
//! Fetch HTTP document.
|
||||||
const string get_http(const string &url);
|
string get_http(const string &url);
|
||||||
|
|
||||||
|
// CURL receive function.
|
||||||
|
size_t writer_body(char *data, size_t size, size_t nmemb);
|
||||||
|
|
||||||
//! Convert time_point to RFC 822 compliant time string.
|
//! Convert time_point to RFC 822 compliant time string.
|
||||||
const string strtime(const system_clock::time_point &timepoint);
|
const string strtime(const system_clock::time_point &timepoint);
|
||||||
|
@ -41,7 +41,7 @@ const string strtime(const system_clock::time_point &timepoint);
|
||||||
const string strtime(const string &time);
|
const string strtime(const string &time);
|
||||||
|
|
||||||
//! Write line of XML.
|
//! Write line of XML.
|
||||||
void write_line(const uint8_t spaces, const string &tag, const string &value);
|
void write_line(uint8_t spaces, const string &tag, const string &value);
|
||||||
|
|
||||||
//! Write the RSS preamble and channel data.
|
//! Write the RSS preamble and channel data.
|
||||||
void write_preamble(const string &url, const string &type);
|
void write_preamble(const string &url, const string &type);
|
||||||
|
@ -67,4 +67,7 @@ const string get_project(const string &url);
|
||||||
//! Escape some characters to named HTML entities.
|
//! Escape some characters to named HTML entities.
|
||||||
const string escape_some_html(string html);
|
const string escape_some_html(string html);
|
||||||
|
|
||||||
#endif // GITEA2RSS_HPP
|
//! Return environment variable or "" if it is not set.
|
||||||
|
string get_env_var(const string &variable);
|
||||||
|
|
||||||
|
#endif // GITEA2RSS_HPP
|
||||||
|
|
211
src/http.cpp
211
src/http.cpp
|
@ -1,5 +1,5 @@
|
||||||
/* This file is part of gitea2rss.
|
/* This file is part of gitea2rss.
|
||||||
* Copyright © 2019 tastytea <tastytea@tastytea.de>
|
* Copyright © 2019, 2020 tastytea <tastytea@tastytea.de>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -14,142 +14,105 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
#include <exception>
|
|
||||||
#include <memory>
|
|
||||||
#include <regex>
|
|
||||||
#include <Poco/Net/HTTPClientSession.h>
|
|
||||||
#include <Poco/Net/HTTPSClientSession.h>
|
|
||||||
#include <Poco/Net/HTTPRequest.h>
|
|
||||||
#include <Poco/Net/HTTPResponse.h>
|
|
||||||
#include <Poco/StreamCopier.h>
|
|
||||||
#include <Poco/URI.h>
|
|
||||||
#include <Poco/Exception.h>
|
|
||||||
#include <Poco/Environment.h>
|
|
||||||
#include "version.hpp"
|
|
||||||
#include "gitea2rss.hpp"
|
#include "gitea2rss.hpp"
|
||||||
|
#include "version.hpp"
|
||||||
|
#include <curl/curl.h>
|
||||||
|
#include <exception>
|
||||||
|
#include <iostream>
|
||||||
|
#include <stdexcept>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
using std::cout;
|
|
||||||
using std::cerr;
|
using std::cerr;
|
||||||
|
using std::cout;
|
||||||
using std::endl;
|
using std::endl;
|
||||||
using std::istream;
|
using std::runtime_error;
|
||||||
using std::unique_ptr;
|
using std::to_string;
|
||||||
using std::make_unique;
|
|
||||||
using std::regex;
|
|
||||||
using std::regex_search;
|
|
||||||
using std::smatch;
|
|
||||||
using Poco::Net::HTTPClientSession;
|
|
||||||
using Poco::Net::HTTPSClientSession;
|
|
||||||
using Poco::Net::HTTPRequest;
|
|
||||||
using Poco::Net::HTTPResponse;
|
|
||||||
using Poco::Net::HTTPMessage;
|
|
||||||
using Poco::StreamCopier;
|
|
||||||
using Poco::Environment;
|
|
||||||
|
|
||||||
void set_proxy()
|
string buffer_body;
|
||||||
|
|
||||||
|
string get_http(const string &url)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
HTTPSClientSession::ProxyConfig proxyconfig;
|
curl_global_init(CURL_GLOBAL_ALL); // NOLINT(hicpp-signed-bitwise)
|
||||||
string env_proxy = Environment::get("http_proxy");
|
CURL *connection{curl_easy_init()};
|
||||||
regex re_proxy("^(?:https?://)?(?:([^:]+):?([^@]*)@)?" // user:password
|
if (connection == nullptr)
|
||||||
"([^:]+):([[:digit:]]+/?)"); // host:port
|
|
||||||
smatch match;
|
|
||||||
|
|
||||||
if (regex_search(env_proxy, match, re_proxy))
|
|
||||||
{
|
{
|
||||||
string username, password;
|
throw runtime_error{"Failed to initialize curl."};
|
||||||
Poco::URI::decode(match[1].str(), username);
|
|
||||||
Poco::URI::decode(match[2].str(), password);
|
|
||||||
|
|
||||||
proxyconfig.host = match[3].str();
|
|
||||||
proxyconfig.port = std::stoi(match[4].str());
|
|
||||||
proxyconfig.username = username;
|
|
||||||
proxyconfig.password = password;
|
|
||||||
|
|
||||||
HTTPSClientSession::setGlobalProxyConfig(proxyconfig);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char buffer_error[256];
|
||||||
|
|
||||||
|
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg)
|
||||||
|
curl_easy_setopt(connection, CURLOPT_ERRORBUFFER, buffer_error);
|
||||||
|
|
||||||
|
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg)
|
||||||
|
curl_easy_setopt(connection, CURLOPT_WRITEFUNCTION, writer_body);
|
||||||
|
|
||||||
|
CURLcode code{curl_easy_setopt(connection, CURLOPT_FOLLOWLOCATION, 1L)};
|
||||||
|
if (code != CURLE_OK)
|
||||||
|
{
|
||||||
|
throw runtime_error{"HTTP is not supported."};
|
||||||
|
}
|
||||||
|
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg)
|
||||||
|
curl_easy_setopt(connection, CURLOPT_MAXREDIRS, 5L);
|
||||||
|
|
||||||
|
code =
|
||||||
|
curl_easy_setopt(connection, CURLOPT_USERAGENT,
|
||||||
|
(string("gitea2rss/") += global::version).c_str());
|
||||||
|
if (code != CURLE_OK)
|
||||||
|
{
|
||||||
|
throw runtime_error{"Failed to set User-Agent."};
|
||||||
|
}
|
||||||
|
|
||||||
|
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg)
|
||||||
|
curl_easy_setopt(connection, CURLOPT_HTTPGET, 1L);
|
||||||
|
|
||||||
|
code = curl_easy_setopt(connection, CURLOPT_URL, url.c_str());
|
||||||
|
if (code != CURLE_OK)
|
||||||
|
{
|
||||||
|
throw runtime_error{"Couldn't set URL: " + to_string(code)};
|
||||||
|
}
|
||||||
|
|
||||||
|
code = curl_easy_perform(connection);
|
||||||
|
if (code != CURLE_OK)
|
||||||
|
{
|
||||||
|
throw runtime_error{"libcurl error: " + to_string(code)};
|
||||||
|
}
|
||||||
|
|
||||||
|
long http_status{0}; // NOLINT(google-runtime-int)
|
||||||
|
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg)
|
||||||
|
curl_easy_getinfo(connection, CURLINFO_RESPONSE_CODE, &http_status);
|
||||||
|
|
||||||
|
curl_easy_cleanup(connection);
|
||||||
|
|
||||||
|
if (http_status == 200)
|
||||||
|
{
|
||||||
|
return buffer_body;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cgi)
|
||||||
|
{
|
||||||
|
cout << "Status: " << http_status << endl;
|
||||||
|
}
|
||||||
|
throw runtime_error{"HTTP error: " + to_string(http_status)};
|
||||||
}
|
}
|
||||||
catch (const std::exception &)
|
catch (const runtime_error &e)
|
||||||
{
|
{
|
||||||
// No proxy found, no problem.
|
cerr << "Error: " << e.what() << endl;
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const string get_http(const string &url)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Poco::URI poco_uri(url);
|
|
||||||
string path = poco_uri.getPathAndQuery();
|
|
||||||
if (path.empty())
|
|
||||||
{
|
|
||||||
path = "/";
|
|
||||||
}
|
|
||||||
|
|
||||||
unique_ptr<HTTPClientSession> session;
|
|
||||||
if (poco_uri.getScheme() == "https")
|
|
||||||
{
|
|
||||||
session = make_unique<HTTPSClientSession>(poco_uri.getHost(),
|
|
||||||
poco_uri.getPort());
|
|
||||||
}
|
|
||||||
else if (poco_uri.getScheme() == "http")
|
|
||||||
{
|
|
||||||
session = make_unique<HTTPClientSession>(poco_uri.getHost(),
|
|
||||||
poco_uri.getPort());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
throw Poco::Exception("Protocol not supported.");
|
|
||||||
}
|
|
||||||
|
|
||||||
HTTPRequest request(HTTPRequest::HTTP_GET, path, HTTPMessage::HTTP_1_1);
|
|
||||||
request.set("User-Agent", string("gitea2rss/") + global::version);
|
|
||||||
|
|
||||||
HTTPResponse response;
|
|
||||||
|
|
||||||
session->sendRequest(request);
|
|
||||||
istream &rs = session->receiveResponse(response);
|
|
||||||
|
|
||||||
// Not using the constants because some are too new for Debian stretch.
|
|
||||||
switch (response.getStatus())
|
|
||||||
{
|
|
||||||
case 301: // HTTPResponse::HTTP_MOVED_PERMANENTLY
|
|
||||||
case 308: // HTTPResponse::HTTP_PERMANENT_REDIRECT
|
|
||||||
case 302: // HTTPResponse::HTTP_FOUND
|
|
||||||
case 303: // HTTPResponse::HTTP_SEE_OTHER
|
|
||||||
case 307: // HTTPResponse::HTTP_TEMPORARY_REDIRECT
|
|
||||||
{
|
|
||||||
string location = response.get("Location");
|
|
||||||
if (location.substr(0, 4) != "http")
|
|
||||||
{
|
|
||||||
location = poco_uri.getScheme() + "://" + poco_uri.getHost()
|
|
||||||
+ location;
|
|
||||||
}
|
|
||||||
return get_http(location);
|
|
||||||
}
|
|
||||||
case HTTPResponse::HTTP_OK:
|
|
||||||
{
|
|
||||||
string answer;
|
|
||||||
StreamCopier::copyToString(rs, answer);
|
|
||||||
return answer;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
{
|
|
||||||
if (cgi)
|
|
||||||
{
|
|
||||||
cout << "Status: " << response.getStatus() << endl;
|
|
||||||
}
|
|
||||||
cerr << "HTTP Error: " << response.getStatus() << endl;
|
|
||||||
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (const Poco::Exception &e)
|
|
||||||
{
|
|
||||||
cerr << "Error: " << e.displayText() << endl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t writer_body(char *data, size_t size, size_t nmemb)
|
||||||
|
{
|
||||||
|
if (data == nullptr)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
buffer_body.append(data, size * nmemb);
|
||||||
|
|
||||||
|
return size * nmemb;
|
||||||
|
}
|
||||||
|
|
25
src/main.cpp
25
src/main.cpp
|
@ -1,5 +1,5 @@
|
||||||
/* This file is part of gitea2rss.
|
/* This file is part of gitea2rss.
|
||||||
* Copyright © 2019 tastytea <tastytea@tastytea.de>
|
* Copyright © 2019, 2020 tastytea <tastytea@tastytea.de>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -14,33 +14,28 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "gitea2rss.hpp"
|
||||||
|
#include "version.hpp"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <Poco/Net/NetSSL.h>
|
|
||||||
#include <Poco/Environment.h>
|
|
||||||
#include "version.hpp"
|
|
||||||
#include "gitea2rss.hpp"
|
|
||||||
|
|
||||||
using std::cout;
|
|
||||||
using std::cerr;
|
using std::cerr;
|
||||||
|
using std::cout;
|
||||||
using std::endl;
|
using std::endl;
|
||||||
using std::string;
|
using std::string;
|
||||||
using std::chrono::system_clock;
|
using std::chrono::system_clock;
|
||||||
using Poco::Environment;
|
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
const string query = Environment::get("QUERY_STRING", "");
|
|
||||||
|
const string query{get_env_var("QUERY_STRING")};
|
||||||
string url;
|
string url;
|
||||||
string type = "releases";
|
string type = "releases";
|
||||||
|
|
||||||
Poco::Net::initializeSSL();
|
|
||||||
|
|
||||||
set_proxy();
|
|
||||||
|
|
||||||
if (!query.empty())
|
if (!query.empty())
|
||||||
{
|
{
|
||||||
const string baseurl = Environment::get("GITEA2RSS_BASEURL", "");
|
cout << query << " AAAAAAAAA\n";
|
||||||
|
const string baseurl{get_env_var("GITEA2RSS_BASEURL")};
|
||||||
if (baseurl.empty())
|
if (baseurl.empty())
|
||||||
{
|
{
|
||||||
cout << "Status: 500 Internal Server Error\n\n";
|
cout << "Status: 500 Internal Server Error\n\n";
|
||||||
|
@ -101,9 +96,7 @@ int main(int argc, char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
cout << " </channel>\n"
|
cout << " </channel>\n"
|
||||||
"</rss>\n";
|
"</rss>\n";
|
||||||
|
|
||||||
Poco::Net::uninitializeSSL();
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/* This file is part of gitea2rss.
|
/* This file is part of gitea2rss.
|
||||||
* Copyright © 2019 tastytea <tastytea@tastytea.de>
|
* Copyright © 2019, 2020 tastytea <tastytea@tastytea.de>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -14,9 +14,12 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "gitea2rss.hpp"
|
||||||
|
#include <cstdlib>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <regex>
|
#include <regex>
|
||||||
#include "gitea2rss.hpp"
|
|
||||||
|
using std::getenv;
|
||||||
|
|
||||||
const string get_baseurl(const string &url)
|
const string get_baseurl(const string &url)
|
||||||
{
|
{
|
||||||
|
@ -44,11 +47,8 @@ const string get_project(const string &url)
|
||||||
|
|
||||||
const string escape_some_html(string html)
|
const string escape_some_html(string html)
|
||||||
{
|
{
|
||||||
const std::map<const char, const string> names =
|
const std::map<const char, const string> names = {{'<', "<"},
|
||||||
{
|
{'>', ">"}};
|
||||||
{ '<', "<" },
|
|
||||||
{ '>', ">" }
|
|
||||||
};
|
|
||||||
|
|
||||||
for (auto &pair : names)
|
for (auto &pair : names)
|
||||||
{
|
{
|
||||||
|
@ -58,3 +58,13 @@ const string escape_some_html(string html)
|
||||||
|
|
||||||
return html;
|
return html;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
string get_env_var(const string &variable)
|
||||||
|
{
|
||||||
|
const char *env{getenv(variable.c_str())};
|
||||||
|
if (env != nullptr)
|
||||||
|
{
|
||||||
|
return env;
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/* This file is part of gitea2rss.
|
/* This file is part of gitea2rss.
|
||||||
* Copyright © 2019 tastytea <tastytea@tastytea.de>
|
* Copyright © 2019, 2020 tastytea <tastytea@tastytea.de>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -14,14 +14,14 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "gitea2rss.hpp"
|
||||||
|
#include "version.hpp"
|
||||||
|
#include <cstdlib>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <regex>
|
#include <regex>
|
||||||
#include <Poco/Environment.h>
|
|
||||||
#include "version.hpp"
|
|
||||||
#include "gitea2rss.hpp"
|
|
||||||
|
|
||||||
using std::cout;
|
using std::cout;
|
||||||
using Poco::Environment;
|
using std::getenv;
|
||||||
|
|
||||||
void write_line(const uint8_t spaces, const string &tag, const string &value)
|
void write_line(const uint8_t spaces, const string &tag, const string &value)
|
||||||
{
|
{
|
||||||
|
@ -44,9 +44,9 @@ void write_line(const uint8_t spaces, const string &tag, const string &value)
|
||||||
|
|
||||||
void write_preamble(const string &url, const string &type)
|
void write_preamble(const string &url, const string &type)
|
||||||
{
|
{
|
||||||
const string request_uri = Environment::get("REQUEST_URI", "");
|
const string request_uri{get_env_var("REQUEST_URI")};
|
||||||
const string server_name = Environment::get("SERVER_NAME", "");
|
const string server_name{get_env_var("SERVER_NAME")};
|
||||||
const string https = Environment::get("HTTPS", "");
|
const string https{get_env_var("HTTPS")};
|
||||||
string selfurl;
|
string selfurl;
|
||||||
|
|
||||||
if (!request_uri.empty() && !server_name.empty())
|
if (!request_uri.empty() && !server_name.empty())
|
||||||
|
@ -64,11 +64,11 @@ void write_preamble(const string &url, const string &type)
|
||||||
}
|
}
|
||||||
|
|
||||||
cout << "<rss version=\"2.0\" xmlns:atom=\"http://www.w3.org/2005/Atom\">\n"
|
cout << "<rss version=\"2.0\" xmlns:atom=\"http://www.w3.org/2005/Atom\">\n"
|
||||||
" <channel>\n";
|
" <channel>\n";
|
||||||
if (cgi)
|
if (cgi)
|
||||||
{
|
{
|
||||||
cout << " <atom:link href=\"" + selfurl
|
cout << " <atom:link href=\"" + selfurl
|
||||||
+ "\" rel=\"self\" type=\"application/rss+xml\"/>\n";
|
+ "\" rel=\"self\" type=\"application/rss+xml\"/>\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
write_line(4, "title", get_project(url) + " " + type);
|
write_line(4, "title", get_project(url) + " " + type);
|
||||||
|
|
|
@ -9,7 +9,7 @@ target_include_directories(${PROJECT_NAME}_testlib
|
||||||
"$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/src>")
|
"$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/src>")
|
||||||
|
|
||||||
target_link_libraries(${PROJECT_NAME}_testlib
|
target_link_libraries(${PROJECT_NAME}_testlib
|
||||||
PRIVATE Poco::Foundation Poco::Net Poco::NetSSL PkgConfig::jsoncpp)
|
PRIVATE CURL::libcurl PkgConfig::jsoncpp)
|
||||||
|
|
||||||
file(GLOB sources_tests test_*.cpp)
|
file(GLOB sources_tests test_*.cpp)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue