2019-04-17 00:17:26 +02:00
|
|
|
/* This file is part of gitea2rss.
|
|
|
|
* Copyright © 2019 tastytea <tastytea@tastytea.de>
|
|
|
|
*
|
|
|
|
* 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, version 3.
|
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <iostream>
|
2019-04-17 01:00:33 +02:00
|
|
|
#include <string>
|
2019-08-09 22:38:28 +02:00
|
|
|
#include <Poco/Net/NetSSL.h>
|
|
|
|
#include <Poco/Environment.h>
|
2019-04-17 01:00:33 +02:00
|
|
|
#include "version.hpp"
|
2019-04-20 04:47:53 +02:00
|
|
|
#include "gitea2rss.hpp"
|
2019-04-17 00:17:26 +02:00
|
|
|
|
|
|
|
using std::cout;
|
|
|
|
using std::cerr;
|
2019-04-20 06:08:17 +02:00
|
|
|
using std::endl;
|
2019-04-17 01:00:33 +02:00
|
|
|
using std::string;
|
2019-04-17 02:51:40 +02:00
|
|
|
using std::chrono::system_clock;
|
2019-08-09 22:38:28 +02:00
|
|
|
using Poco::Environment;
|
2019-04-17 01:00:33 +02:00
|
|
|
|
2019-04-17 00:17:26 +02:00
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
2019-08-09 22:38:28 +02:00
|
|
|
const string query = Environment::get("QUERY_STRING");
|
2019-04-17 05:52:10 +02:00
|
|
|
string url;
|
2019-04-20 06:08:17 +02:00
|
|
|
string type = "releases";
|
2019-04-17 05:52:10 +02:00
|
|
|
|
2019-08-09 22:38:28 +02:00
|
|
|
Poco::Net::initializeSSL();
|
2019-04-20 04:47:53 +02:00
|
|
|
|
2019-08-09 22:38:28 +02:00
|
|
|
set_proxy();
|
|
|
|
|
|
|
|
if (!query.empty())
|
2019-04-17 05:52:10 +02:00
|
|
|
{
|
2019-08-09 22:38:28 +02:00
|
|
|
const string baseurl = Environment::get("GITEA2RSS_BASEURL");
|
|
|
|
if (baseurl.empty())
|
2019-04-17 05:52:10 +02:00
|
|
|
{
|
2019-04-17 08:26:26 +02:00
|
|
|
cout << "Status: 500 Internal Server Error\n\n";
|
2019-04-17 07:12:08 +02:00
|
|
|
cerr << "Error: GITEA2RSS_BASEURL not set\n";
|
2019-04-17 05:52:10 +02:00
|
|
|
return 1;
|
|
|
|
}
|
2019-04-17 08:26:26 +02:00
|
|
|
cgi = true;
|
|
|
|
|
2019-04-20 06:08:17 +02:00
|
|
|
// Look for repo in QUERY_STRING.
|
|
|
|
size_t pos_found = query.find("repo=");
|
|
|
|
if (pos_found == std::string::npos)
|
2019-04-17 08:26:26 +02:00
|
|
|
{
|
|
|
|
cout << "Status: 400 Bad Request\n\n";
|
|
|
|
return 1;
|
|
|
|
}
|
2019-04-20 06:08:17 +02:00
|
|
|
const size_t pos_repo = pos_found + 5;
|
|
|
|
const size_t pos_endrepo = query.find('&', pos_repo) - pos_repo;
|
2019-08-09 22:38:28 +02:00
|
|
|
url = string(baseurl) + "/" + query.substr(pos_repo, pos_endrepo);
|
2019-04-20 06:08:17 +02:00
|
|
|
|
|
|
|
// Look for type in QUERY_STRING.
|
|
|
|
pos_found = query.find("type=");
|
|
|
|
if (pos_found != std::string::npos)
|
|
|
|
{
|
|
|
|
const size_t pos_type = pos_found + 5;
|
|
|
|
type = query.substr(pos_type, query.find('&') - pos_type);
|
|
|
|
}
|
2019-04-17 08:26:26 +02:00
|
|
|
|
|
|
|
cout << "Content-Type: application/rss+xml\n";
|
2019-04-17 05:52:10 +02:00
|
|
|
}
|
|
|
|
else if (argc < 2)
|
2019-04-17 00:17:26 +02:00
|
|
|
{
|
2019-04-22 11:31:58 +02:00
|
|
|
cerr << "usage: " << argv[0]
|
|
|
|
<< " URL of Gitea project [releases|tags]\n";
|
2019-04-17 00:17:26 +02:00
|
|
|
return 1;
|
|
|
|
}
|
2019-04-17 05:52:10 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
url = argv[1];
|
2019-04-20 06:08:17 +02:00
|
|
|
if (argc > 2)
|
|
|
|
{
|
|
|
|
type = argv[2];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t ret = 0;
|
|
|
|
if (type == "releases")
|
|
|
|
{
|
2019-04-20 07:43:23 +02:00
|
|
|
ret = write_releases(url);
|
|
|
|
}
|
|
|
|
else if (type == "tags")
|
|
|
|
{
|
|
|
|
ret = write_tags(url);
|
2019-04-20 06:08:17 +02:00
|
|
|
}
|
|
|
|
|
2019-04-20 05:15:30 +02:00
|
|
|
if (ret != 0)
|
2019-04-17 01:23:23 +02:00
|
|
|
{
|
2019-04-20 05:15:30 +02:00
|
|
|
return ret;
|
2019-04-17 01:23:23 +02:00
|
|
|
}
|
2019-04-17 01:00:33 +02:00
|
|
|
|
2019-04-20 07:43:23 +02:00
|
|
|
cout << " </channel>\n"
|
2019-04-17 02:51:40 +02:00
|
|
|
"</rss>\n";
|
|
|
|
|
2019-08-09 22:38:28 +02:00
|
|
|
Poco::Net::uninitializeSSL();
|
2019-04-20 04:47:53 +02:00
|
|
|
|
2019-04-17 00:17:26 +02:00
|
|
|
return 0;
|
|
|
|
}
|