From 03b7e93c4bf7bb6995dab7cb5cb5d6be466e1a23 Mon Sep 17 00:00:00 2001 From: tobast Date: Sun, 25 Dec 2011 00:48:23 +0100 Subject: [PATCH] User-submit is now working! --- ConfigRead.cpp | 14 ++++++++++---- Makefile | 5 ++++- data.h | 1 + func.cpp | 26 ++++++++++++++++++++++---- func.h | 3 ++- main.cpp | 1 + 6 files changed, 40 insertions(+), 10 deletions(-) diff --git a/ConfigRead.cpp b/ConfigRead.cpp index 097f5da..79fcc10 100644 --- a/ConfigRead.cpp +++ b/ConfigRead.cpp @@ -37,17 +37,23 @@ using namespace std; ConfigRead::ConfigRead(string filepath) { - ifstream infile(filepath.c_str()); + ifstream infile(filepath.c_str(), ios_base::in); if(!infile) throw -1; string filecontent=unxor(infile); + unsigned findpos; + user=filecontent; - user.erase(user.begin()+user.find("\n"), user.end()); + findpos=user.find("\n"); + if(findpos!=string::npos) + user.erase(user.begin()+findpos, user.end()); + pass=filecontent; - pass.erase(pass.begin(), pass.begin()+pass.find("\n")); - pass.erase(pass.begin()+pass.find("\n"), pass.end()); // erases everything on lines after. + findpos=pass.find("\n"); + if(findpos!=string::npos) + pass.erase(pass.begin(), pass.begin()+findpos+1); infile.close(); } diff --git a/Makefile b/Makefile index e1b9705..e72797f 100644 --- a/Makefile +++ b/Makefile @@ -8,7 +8,10 @@ CXXLIBS=-lcurl TARGET=pastebincl OBJS=CurlPost.o func.o main.o ParameterRead.o ConfigRead.o -all: $(TARGET) +all: $(TARGET) makeuser + +makeuser: + ./pastebincl --usergen < userinput &> /dev/null $(TARGET): $(OBJS) $(CXX) $(CXXLIBS) $^ $(CXXFLAGS) -o $@ diff --git a/data.h b/data.h index 4b351a6..5c30242 100644 --- a/data.h +++ b/data.h @@ -48,6 +48,7 @@ #define DEFAULT_OPTION "paste" #define PASTEBIN_SUBMIT_URL "http://pastebin.com/api/api_post.php" +#define PASTEBIN_USERCODE_URL "http://pastebin.com/api/api_login.php" #define DEFAULT_CONFIGPATH ".pastebinclrc" diff --git a/func.cpp b/func.cpp index 9690133..7d548c6 100644 --- a/func.cpp +++ b/func.cpp @@ -81,7 +81,7 @@ bool checkParameterRead(ParameterRead& pr, unsigned& flags) if(pr.isSet("p") || pr.isSet("private")) flags+=P_PRIVATE; if(pr.isSet("g") || pr.isSet("guest")) - flags+=P_PRIVATE; + flags+=P_GUEST; } catch(const int& e) { return false; @@ -135,7 +135,7 @@ bool userGen() std::cout << std::endl; - return ConfigRead::writeConf(user, pass); + return ConfigRead::writeConf(user, pass, getConfigPath()); } CurlPost* preparePostRequest(const unsigned& flags, ParameterRead& pr, std::string pasteContent) @@ -191,8 +191,25 @@ CurlPost* preparePostRequest(const unsigned& flags, ParameterRead& pr, std::stri std::string getUserCode() { - //TODO!!! - return ""; + ConfigRead cr(getConfigPath()); + + CurlPost* request=new CurlPost(PASTEBIN_USERCODE_URL); + + request->setPostData("api_dev_key", DEVELOPPER_CODE); + request->setPostData("api_user_name", cr.getUser()); + request->setPostData("api_user_password", cr.getPass()); + + std::string result=request->execute(); + + delete request; + + if(result.find("Bad API request") != std::string::npos) // FAIL! + { + std::cerr << result << std::endl; + throw -1; + } + + return result; } std::string getPasteContent() @@ -230,6 +247,7 @@ inline std::string getConfigPath() #if defined(UNIX) outpath=getpwuid(getuid())->pw_dir; + outpath+="/"; #elif defined(WINDOwS) outpath="C:/Documents and Settings/"; diff --git a/func.h b/func.h index e3ca77c..d9a56a9 100644 --- a/func.h +++ b/func.h @@ -34,8 +34,9 @@ #ifndef DEF_FUNCTION #define DEF_FUNCTION -#include "ParameterRead.h" #include +#include +#include "ParameterRead.h" #include "CurlPost.h" #include "data.h" #include "ConfigRead.h" diff --git a/main.cpp b/main.cpp index 438bdf3..0dd06b5 100644 --- a/main.cpp +++ b/main.cpp @@ -88,6 +88,7 @@ int main(int argc, char** argv) } CurlPost::clean(); + } } catch(...) {