Parameter input bug fixed 4/22
#include <cctype>
#include <iostream>
#include <fstream>
#include <string>
using std::string;
#include <cleansocks.h>
#include <cleanip.h>
#include <cleanbuf.h>
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 <typename T>
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<string>("User");
}
if(argc > 0) {
pwd = *argv++; argc--;
} else {
pwd = pandr<string>("Password");
}
} else {
host = pandr<string>("Host");
pno = pandr<int>("Port");
user = pandr<string>("User");
pwd = pandr<string>("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;
}
}