#include #include #include #include using std::string; #include #include #include using namespace cleansocks; #include "sha256.h" // Port numbers. const int DFLTPORT = 45100; // Prompt and read, when you're just not capable of adult forms of // configuration. template T pandr(string prompt) { std::cout << prompt << ": "; T ret; std::cin >> ret; return ret; } // Do all the stuff. // Implement me. void go(string hn, int pno, string user, string pwd) { } // Tell if the string ends with .conf bool is_dot_conf(string s) { return s.length() > 5 && s.substr(s.length() - 5) == ".conf"; } int main(int argc, char **argv) { string pgm = argv[0]; ++argv; --argc; // Port numbers int portno = DFLTPORT+1; // Parms. Lots of ways to provide string host, user, pwd; int pno = DFLTPORT; if(argc == 1 && is_dot_conf(argv[0])) { // .conf file std::ifstream in(argv[0]); in >> host >> pno >> user >> std::ws; std::getline(in,pwd); } else if(argc > 0) { // Command line. host = *argv++; argc--; if(argc > 0 && isdigit(argv[0][0])) { pno = std::atoi(*argv++); argc--; } if(argc > 0) { user = *argv++; argc--; } else { user = pandr("User"); } if(argc > 0) { pwd = *argv++; argc--; } else { pwd = pandr("Password"); } } else { host = pandr("Host"); pno = pandr("Port"); user = pandr("User"); pwd = pandr("Password"); } // The sender uses the odd port if(pno % 2 == 0) ++pno; // Connect. try { go(host,pno,user,pwd); } catch(std::exception &e) { std::cout << "Error: " << e.what() << std::endl; } }