Added what I coded on my laptop: request building, etc.

This commit is contained in:
tobast 2011-11-24 22:51:30 +01:00
parent 3841a366fa
commit 9d7a93c622
6 changed files with 169 additions and 4 deletions

36
ConfigRead.cpp Normal file
View File

@ -0,0 +1,36 @@
/*
* 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.
*/
#include "ConfigRead.h"

48
ConfigRead.h Normal file
View File

@ -0,0 +1,48 @@
/*
* 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.
*/
#ifndef DEF_CONFIGREAD
#define DEF_CONFIGREAD
#include <string>
#include <fstream>
#include "data.h"
class ConfigRead
{
public:
ConfigRead(std::string filepath=DEFAULT_CONFIGPATH);
}
#endif//DEF_CONFIGREAD

11
data.h
View File

@ -47,6 +47,17 @@
#define DEFAULT_USERKEY ""
#define DEFAULT_OPTION "paste"
#define PASTEBIN_SUBMIT_URL "http://pastebin.com/api/api_post.php"
#ifdef UNIX
#define DEFAULT_CONFIGPATH "~/.pastebinclrc"
#endif
#ifdef WINDOWS
#define DEFAULT_CONFIGPATH "%APPLICATION_DATA%/.pastebinclrc"
#endif
#ifndef DEFAULT_CONFIGPATH
#define DEFAULT_CONFIGPATH ""
#endif
enum FlagParameter {
P_NAME=1, P_SYNTAX=2, P_PRIVATE=4, P_EXPIRE=8, P_GUEST=16, P_HELP=32, P_VERSION=64, P_LICENCE=128

View File

@ -114,8 +114,59 @@ void showVersion()
<< "Error report: <error-report@tobast.fr>" << std::endl << std::endl;
}
CurlPost* preparePostRequest(const unsigned& flags, const ParameterRead& pr)
CurlPost* preparePostRequest(const unsigned& flags, ParameterRead& pr)
{
// TODO!
CurlPost* request=new CurlPost(PASTEBIN_SUBMIT_URL);
if(flags & P_NAME)
{
if(pr.isSet("n"))
request->setPostData("api_paste_name", pr.getValue("n"));
else if(pr.isSet("name"));
request->setPostData("api_paste_name", pr.getValue("name"));
}
else
request->setPostData("name", DEFAULT_NAME);
if(flags & P_SYNTAX)
{
if(pr.isSet("s"))
request->setPostData("api_paste_format", pr.getValue("s"));
else if(pr.isSet("syntax"));
request->setPostData("api_paste_format", pr.getValue("syntax"));
}
if(flags & P_PRIVATE)
request->setPostData("api_paste_private", "1");
else
request->setPostData("api_paste_private", DEFAULT_PRIVATE);
if(flags & P_EXPIRE)
{
if(pr.isSet("e"))
request->setPostData("api_paste_expire_date", pr.getValue("e"));
else if(pr.isSet("expire"));
request->setPostData("api_paste_expire_date", pr.getValue("expire"));
}
else
request->setPostData("api_paste_expire_date", DEFAULT_EXPIRE);
if(!(flags & P_GUEST))
{
std::string usercode=getUserCode();
if(!usercode.empty())
request->setPostData("api_user_key", usercode);
}
request->setPostData("api_dev_key", DEVELOPPER_CODE);
request->setPostData("api_option", "paste");
return request;
}
std::string getUserCode()
{
//TODO!!!
return "";
}

6
func.h
View File

@ -36,7 +36,7 @@
#include <parameterread/ParameterRead.h>
#include <iostream>
#include <CurlPost.h>
#include "CurlPost.h"
#include "data.h"
bool initParameterRead(ParameterRead& pr, unsigned& flags);
@ -46,7 +46,9 @@ void showLicence();
void showHelp();
void showVersion();
CurlPost* preparePostRequest(const unsigned& flags, const ParameterRead& pr);
CurlPost* preparePostRequest(const unsigned& flags, ParameterRead& pr);
std::string getUserCode();
#endif//DEF_FUNCTION

View File

@ -36,6 +36,7 @@
#include "func.h"
#include <parameterread/ParameterRead.h>
#include <iostream>
#include <string>
int main(int argc, char** argv)
{
@ -60,6 +61,22 @@ int main(int argc, char** argv)
{
// Here we start real stuff!
CurlPost::init();
CurlPost* request=preparePostRequest(parameterFlags, pr);
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;
}
CurlPost::clean();
}
}