From 14ad63ba98f4f63e6869f5bc75816b84ba474aa7 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Mon, 28 Sep 2015 20:29:23 +0200 Subject: [PATCH] Added support for apikey, and reading apikey / expiry from conf --- stikkit/configuration.cpp | 31 +++++++++++++++++++++++++++++++ stikkit/configuration.hpp | 1 + stikkit/main.cpp | 6 ++++++ stikkit/terminalparser.cpp | 12 ++++++++++++ 4 files changed, 50 insertions(+) diff --git a/stikkit/configuration.cpp b/stikkit/configuration.cpp index 0dddd2b..912836b 100644 --- a/stikkit/configuration.cpp +++ b/stikkit/configuration.cpp @@ -30,6 +30,7 @@ string Configuration::Home = ""; bool Configuration::NoExtras = false; string Configuration::Input = ""; string Configuration::DefaultURL = ""; +string Configuration::Apikey = ""; void Configuration::Init() { @@ -61,6 +62,36 @@ void Configuration::Init() Configuration::DefaultURL = line; } f.close(); + + //Apikey + ifstream fapi; + fapi.open(string(homedir + "/.stikkit/apikey").c_str()); + string lineapi; + if(getline(fapi, lineapi)) + { + Configuration::Apikey = lineapi; + } + fapi.close(); + + //expiry + ifstream fexp; + fexp.open(string(homedir + "/.stikkit/expiry").c_str()); + string lineexp; + if(getline(fexp, lineexp)) + { + Configuration::Expiry = lineexp; + } + fexp.close(); + + //author + ifstream fauth; + fauth.open(string(homedir + "/.stikkit/author").c_str()); + string lineauth; + if(getline(fauth, lineauth)) + { + Configuration::Author = lineauth; + } + fauth.close(); } if (Configuration::Author.length() < 1) { diff --git a/stikkit/configuration.hpp b/stikkit/configuration.hpp index 5cb2dc9..d0178b3 100644 --- a/stikkit/configuration.hpp +++ b/stikkit/configuration.hpp @@ -33,6 +33,7 @@ namespace Stikkit static string DefaultURL; static bool Private; static string Home; + static string Apikey; static bool NoExtras; }; } diff --git a/stikkit/main.cpp b/stikkit/main.cpp index d010650..75ee00b 100644 --- a/stikkit/main.cpp +++ b/stikkit/main.cpp @@ -103,6 +103,12 @@ int main(int argc, char *argv[]) readBuffer.clear(); string post = "text="; post += curl_easy_escape(curl, Stikkit::Configuration::Source.c_str(), Stikkit::Configuration::Source.length()); + if (Stikkit::Configuration::Apikey.length() > 0) + { + Stikkit::Configuration::URL += "?apikey="; + Stikkit::Configuration::URL += curl_easy_escape(curl, Stikkit::Configuration::Apikey.c_str(), Stikkit::Configuration::Apikey.length()); + } + if (Stikkit::Configuration::Author.length() > 0) { post += "&name="; diff --git a/stikkit/terminalparser.cpp b/stikkit/terminalparser.cpp index ab43b7e..d47af67 100644 --- a/stikkit/terminalparser.cpp +++ b/stikkit/terminalparser.cpp @@ -95,6 +95,17 @@ bool TerminalParser::Parse() cerr << "Parameter -i requires an argument for it to work!" << endl; return true; } + } else if (text.at(0) == 'k') + { + if (this->argc > x + 1 && !this->argv[x + 1][0] != '-') + { + x++; + Configuration::Apikey = this->argv[x]; + } else + { + cerr << "Parameter -k requires an argument for it to work!" << endl; + return true; + } } text = text.substr(1); } @@ -149,6 +160,7 @@ void TerminalParser::DisplayHelp() " -s: Display only RAW url of paste and no extra text\n"\ " -e : Set expiry in minutes, parameter needs\n"\ " to be a number, default: unlimited time\n"\ + " -k : Set api key for current server\n"\ " --version: Display a version\n"\ " -h | --help: Display this help\n\n"\ "Note: every argument in [brackets] is optional\n"\