Added: getting paste content.

This commit is contained in:
tobast 2011-11-28 18:24:54 +01:00
parent 9d7a93c622
commit f9b52a5ba3
3 changed files with 40 additions and 4 deletions

View file

@ -114,7 +114,7 @@ void showVersion()
<< "Error report: <error-report@tobast.fr>" << 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;
}

3
func.h
View file

@ -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

View file

@ -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;
}