From f9b52a5ba3d20d70e5d9f7da74757fbf4ef67a86 Mon Sep 17 00:00:00 2001 From: tobast Date: Mon, 28 Nov 2011 18:24:54 +0100 Subject: [PATCH] Added: getting paste content. --- func.cpp | 32 +++++++++++++++++++++++++++++++- func.h | 3 ++- main.cpp | 9 +++++++-- 3 files changed, 40 insertions(+), 4 deletions(-) diff --git a/func.cpp b/func.cpp index af9e168..24735f1 100644 --- a/func.cpp +++ b/func.cpp @@ -114,7 +114,7 @@ void showVersion() << "Error report: " << std::endl << std::endl; } -CurlPost* preparePostRequest(const unsigned& flags, ParameterRead& pr) +CurlPost* preparePostRequest(const unsigned& flags, ParameterRead& pr, std::string pasteContent) { CurlPost* request=new CurlPost(PASTEBIN_SUBMIT_URL); @@ -158,6 +158,7 @@ CurlPost* preparePostRequest(const unsigned& flags, ParameterRead& pr) request->setPostData("api_user_key", usercode); } + request->setPostData("api_paste_code", pasteContent); request->setPostData("api_dev_key", DEVELOPPER_CODE); request->setPostData("api_option", "paste"); @@ -170,3 +171,32 @@ std::string getUserCode() return ""; } +std::string getPasteContent() +{ + std::string outstr; + + if(!std::cin.eof()) + { + while(1) + { + char c=std::cin.get(); + if(std::cin.eof()) + break; + outstr+=c; + } + } + else + { + while(1) + { + std::string tmp; + std::cin >> tmp; + outstr+=tmp; + if(tmp.find(-1) != std::string::npos) // found a ^D + break; + } + } + + return outstr; +} + diff --git a/func.h b/func.h index 5a49bb5..56f7326 100644 --- a/func.h +++ b/func.h @@ -46,9 +46,10 @@ void showLicence(); void showHelp(); void showVersion(); -CurlPost* preparePostRequest(const unsigned& flags, ParameterRead& pr); +CurlPost* preparePostRequest(const unsigned& flags, ParameterRead& pr, std::string pasteContent); std::string getUserCode(); +std::string getPasteContent(); #endif//DEF_FUNCTION diff --git a/main.cpp b/main.cpp index e2a1214..8503de1 100644 --- a/main.cpp +++ b/main.cpp @@ -61,8 +61,11 @@ int main(int argc, char** argv) { // Here we start real stuff! CurlPost::init(); + + CurlPost* request=preparePostRequest(parameterFlags, pr, getPasteContent()); + + std::cout << "Submitting paste..." << std::endl; - CurlPost* request=preparePostRequest(parameterFlags, pr); std::string result=request->execute(); delete request; @@ -80,7 +83,9 @@ int main(int argc, char** argv) CurlPost::clean(); } } - catch(...) {} + catch(...) { + std::cerr << "Exception catched. Program is terminating." << std::endl; + } return 0; }