2011-11-20 11:55:02 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* PROGRAM:
|
|
|
|
* Command-line pastebin
|
|
|
|
*
|
|
|
|
* AUTHOR:
|
|
|
|
* Théophile BASTIAN (a.k.a. Tobast)
|
|
|
|
*
|
|
|
|
* CONTACT & WEBSITE:
|
|
|
|
* http://tobast.fr/ (contact feature included)
|
|
|
|
* error-report@tobast.fr (error reporting only)
|
|
|
|
*
|
|
|
|
* SHORT DESCRIPTION:
|
|
|
|
* See first license line.
|
|
|
|
*
|
|
|
|
* LICENSE:
|
|
|
|
* "Command-line pastebin" is a software designed to submit a "paste" on http://pastebin.com/ using a command-line tool
|
|
|
|
* Copyright (C) 2011 Théophile BASTIAN
|
|
|
|
*
|
|
|
|
* 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, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* 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/gpl.txt.
|
|
|
|
*/
|
|
|
|
|
2011-11-21 18:43:40 +01:00
|
|
|
#include "CurlPost.h"
|
2011-11-21 21:46:03 +01:00
|
|
|
#include "data.h"
|
|
|
|
#include "func.h"
|
2011-11-28 22:09:25 +01:00
|
|
|
#include "ParameterRead.h"
|
2011-11-21 21:46:03 +01:00
|
|
|
#include <iostream>
|
2011-11-24 22:51:30 +01:00
|
|
|
#include <string>
|
2011-11-20 11:55:02 +01:00
|
|
|
|
2011-11-21 18:43:40 +01:00
|
|
|
int main(int argc, char** argv)
|
|
|
|
{
|
2011-11-21 21:46:03 +01:00
|
|
|
|
|
|
|
try {
|
|
|
|
ParameterRead pr(argc,argv);
|
|
|
|
unsigned parameterFlags=0;
|
|
|
|
|
|
|
|
if(!initParameterRead(pr, parameterFlags))
|
|
|
|
{
|
|
|
|
std::cerr << "FATAL ERROR: Bad parameters. See pastebincl -h for more help." << std::endl;
|
|
|
|
throw 42;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(parameterFlags & P_LICENCE)
|
|
|
|
showLicence();
|
|
|
|
else if(parameterFlags & P_HELP)
|
|
|
|
showHelp();
|
|
|
|
else if(parameterFlags & P_VERSION)
|
|
|
|
showVersion();
|
2011-12-19 00:20:16 +01:00
|
|
|
else if(parameterFlags & P_USERGEN)
|
|
|
|
{
|
|
|
|
if(userGen())
|
|
|
|
std::cout << "Configuration file generated!" << std::endl;
|
|
|
|
else
|
|
|
|
std::cerr << "An error occured while writing configuration file. FAIL." << std::endl;
|
|
|
|
}
|
2011-11-21 21:46:03 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
// Here we start real stuff!
|
|
|
|
CurlPost::init();
|
2011-11-28 18:24:54 +01:00
|
|
|
|
|
|
|
CurlPost* request=preparePostRequest(parameterFlags, pr, getPasteContent());
|
|
|
|
|
|
|
|
std::cout << "Submitting paste..." << std::endl;
|
2011-11-24 22:51:30 +01:00
|
|
|
|
|
|
|
std::string result=request->execute();
|
|
|
|
delete request;
|
|
|
|
|
|
|
|
if(result.find("http://pastebin.com/") == 0) // SUCCESS !
|
|
|
|
{
|
|
|
|
std::cout << "Paste submitted successfully!" << std::endl
|
|
|
|
<< "URL: " << result << std::endl;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
std::cerr << "ERROR: Pastebin.com returned an error to your request." << std::endl
|
|
|
|
<< "Message: " << result << std::endl;
|
|
|
|
}
|
|
|
|
|
2011-11-21 21:46:03 +01:00
|
|
|
CurlPost::clean();
|
2011-12-25 00:48:23 +01:00
|
|
|
|
2011-11-21 21:46:03 +01:00
|
|
|
}
|
|
|
|
}
|
2011-11-28 18:24:54 +01:00
|
|
|
catch(...) {
|
|
|
|
std::cerr << "Exception catched. Program is terminating." << std::endl;
|
|
|
|
}
|
2011-11-21 18:43:40 +01:00
|
|
|
|
2011-11-21 21:46:03 +01:00
|
|
|
return 0;
|
2011-11-21 18:43:40 +01:00
|
|
|
}
|
2011-11-20 11:55:02 +01:00
|
|
|
|