plptools
Loading...
Searching...
No Matches
main.cc
Go to the documentation of this file.
1/*
2 * This file is part of plptools.
3 *
4 * Copyright (C) 1999 Philip Proudman <philip.proudman@btinternet.com>
5 * Copyright (C) 1999-2002 Fritz Elfert <felfert@to.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * along with this program; if not, see <https://www.gnu.org/licenses/>.
19 *
20 */
21#include "config.h"
22
23#include <cli_utils.h>
24#include <rfsv.h>
25#include <rfsvfactory.h>
26#include <rpcs.h>
27#include <rpcsfactory.h>
28#include <rclip.h>
29#include <plpintl.h>
30#include <tcpsocket.h>
31#include <bufferstore.h>
32
33#include <iostream>
34#include <vector>
35
36#include <stdlib.h>
37#include <stdio.h>
38
39#include "ftp.h"
40
41#ifndef _GNU_SOURCE
42#define _GNU_SOURCE
43#endif
44#include <getopt.h>
45
46using namespace std;
47
48static void
50{
51 cout << _(
52 "Usage: plpftp [OPTIONS]... [FTPCOMMAND]\n"
53 "\n"
54 "If FTPCOMMAND is given, connect; run FTPCOMMAND and\n"
55 "terminate afterwards. If no FTPCOMMAND is given, start up\n"
56 "in interactive mode. For help on supported FTPCOMMANDs,\n"
57 "use `?' or `help' as FTPCOMMAND.\n"
58 "\n"
59 "Supported options:\n"
60 "\n"
61 " -h, --help Display this text.\n"
62 " -V, --version Print version and exit.\n"
63 " -p, --port=[HOST:]PORT Connect to port PORT on host HOST.\n"
64 " Default for HOST is 127.0.0.1\n"
65 " Default for PORT is "
66 ) << DPORT << "\n\n";
67}
68
69static void
71 cerr << _("Try `plpftp --help' for more information") << endl;
72}
73
74static struct option opts[] = {
75 {"help", no_argument, nullptr, 'h'},
76 {"version", no_argument, nullptr, 'V'},
77 {"port", required_argument, nullptr, 'p'},
78 {NULL, 0, nullptr, 0 }
79};
80
81void
83{
84 cout << _("PLPFTP Version ") << VERSION;
85 cout << _(" Copyright (C) 1999 Philip Proudman") << endl;
86 cout << _(" Additions Copyright (C) 1999-2002 Fritz Elfert <felfert@to.com>") << endl;
87 cout << _(" & (C) 1999 Matt Gumbley <matt@gumbley.demon.co.uk>") << endl;
88 cout << _(" & (C) 2006-2025 Reuben Thomas <rrt@sc3d.org>") << endl;
89 cout << _("PLPFTP comes with ABSOLUTELY NO WARRANTY.") << endl;
90 cout << _("This is free software, and you are welcome to redistribute it") << endl;
91 cout << _("under GPL conditions; see the COPYING file in the distribution.") << endl;
92 cout << endl;
93 cout << _("FTP like interface started. Type \"?\" for help.") << endl;
94}
95
96int
97main(int argc, char **argv)
98{
99 TCPSocket *skt;
100 TCPSocket *skt2;
101 rfsv *a;
102 rpcs *r;
103 TCPSocket *rclipSocket;
104 rclip *rc;
105 ftp f;
106 string host = "127.0.0.1";
107 int status = 0;
108 int sockNum = cli_utils::lookup_default_port();
109
110 setlocale (LC_ALL, "");
111 textdomain(PACKAGE);
112
113 while (1) {
114 int c = getopt_long(argc, argv, "hVp:", opts, NULL);
115 if (c == -1)
116 break;
117 switch (c) {
118 case '?':
119 usage();
120 return -1;
121 case 'V':
122 cout << _("plpftp Version ") << VERSION << endl;
123 return 0;
124 case 'h':
125 help();
126 return 0;
127 case 'p':
128 if (!cli_utils::parse_port(optarg, &host, &sockNum)) {
129 cout << _("Invalid port definition.") << endl;
130 return 1;
131 }
132 break;
133 }
134 }
135 if (optind == argc)
136 ftpHeader();
137
138 skt = new TCPSocket();
139 if (!skt->connect(host.c_str(), sockNum)) {
140 cout << _("plpftp: could not connect to ncpd") << endl;
141 return 1;
142 }
143 skt2 = new TCPSocket();
144 if (!skt2->connect(host.c_str(), sockNum)) {
145 cout << _("plpftp: could not connect to ncpd") << endl;
146 return 1;
147 }
148 rfsvfactory *rf = new rfsvfactory(skt);
149 rpcsfactory *rp = new rpcsfactory(skt2);
150 a = rf->create(false);
151 r = rp->create(false);
152 rclipSocket = new TCPSocket();
153 rclipSocket->connect(NULL, sockNum);
154 if (rclipSocket)
155 rc = new rclip(rclipSocket);
156 f.canClip = rclipSocket && rc ? true : false;
157 if ((a != NULL) && (r != NULL)) {
158 vector<char *> args(argv + optind, argv + argc);
159 status = f.session(*a, *r, *rc, *rclipSocket, args);
160 delete r;
161 delete a;
162 delete skt;
163 delete skt2;
164 if (rclipSocket)
165 delete rclipSocket;
166 if (rc)
167 delete rc;
168 } else {
169 cerr << "plpftp: " << rf->getError() << endl;
170 status = 1;
171 }
172 delete rf;
173 delete rp;
174 return status;
175}
A class for dealing with sockets.
Definition: tcpsocket.h:38
virtual bool connect(const char *const Peer, int PeerPort, const char *const Host=NULL, int HostPort=0)
Connects to a given host.
Definition: tcpsocket.cc:153
Definition: ftp.h:36
bool canClip
Definition: ftp.h:41
int session(rfsv &a, rpcs &r, rclip &rc, TCPSocket &rclipSocket, std::vector< char * > argv)
Definition: ftp.cc:640
Remote ClipBoard services via PLP.
Definition: rclip.h:43
Access remote file services of a Psion.
Definition: rfsv.h:75
A factory for automatically instantiating the correct rfsv protocol variant depending on the connecte...
Definition: rfsvfactory.h:33
virtual Enum< errs > getError()
Retrieve an error code.
Definition: rfsvfactory.h:80
virtual rfsv * create(bool)
Creates a new rfsv instance.
Definition: rfsvfactory.cc:54
Remote procedure call services via PLP.
Definition: rpcs.h:51
A factory for automatically instantiating the correct protocol variant depending on the connected Psi...
Definition: rpcsfactory.h:32
virtual rpcs * create(bool reconnect)
Creates a new rpcs instance.
Definition: rpcsfactory.cc:47
bool parse_port(const std::string &arg, std::string *host, int *port)
Definition: cli_utils.cc:52
int lookup_default_port()
Definition: cli_utils.cc:43
Definition: doctest.h:522
int main(int argc, char **argv)
Definition: main.cc:97
static void usage()
Definition: main.cc:70
static struct option opts[]
Definition: main.cc:74
void ftpHeader()
Definition: main.cc:82
static void help()
Definition: main.cc:49
static rpcsfactory * rp
Definition: main.cc:57
static rpcs * r
Definition: main.cc:56
static rfsvfactory * rf
Definition: main.cc:54
static rfsv * a
Definition: main.cc:53
#define _(String)
Definition: plpintl.h:35
#define textdomain(Domain)
Definition: plpintl.h:37