Debian Codegraph @

util/faxwatch.c++

raw
1 /* $Id$ */
2 /*
3 * Copyright (c) 1990-1996 Sam Leffler
4 * Copyright (c) 1991-1996 Silicon Graphics, Inc.
5 * HylaFAX is a trademark of Silicon Graphics
6 *
7 * Permission to use, copy, modify, distribute, and sell this software and
8 * its documentation for any purpose is hereby granted without fee, provided
9 * that (i) the above copyright notices and this permission notice appear in
10 * all copies of the software and related documentation, and (ii) the names of
11 * Sam Leffler and Silicon Graphics may not be used in any advertising or
12 * publicity relating to the software without the specific, prior written
13 * permission of Sam Leffler and Silicon Graphics.
14 *
15 * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
17 * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
18 *
19 * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
20 * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
21 * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
22 * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
23 * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
24 * OF THIS SOFTWARE.
25 */
26 #include "FaxClient.h"
27 #include "Sys.h"
28 #include "config.h"
29
30 #include <errno.h>
31 #ifdef HAVE_STDINT_H
32 #include <stdint.h>
33 #endif
34
35 class watchApp : public FaxClient {
36 private:
37 fxStr appName;
38
39 void fatal(const char* fmt ...);
40 void usage();
41 public:
42 watchApp();
43 ~watchApp();
44
45 void run(int argc, char** argv);
46 };
47
48 watchApp::watchApp() {}
49 watchApp::~watchApp() {}
50
51 static bool
52 writeData(int arg, const char* buf, int cc, fxStr& emsg)
53 {
54 if (Sys::write((intptr_t) arg, buf, cc) != cc) {
55 emsg = fxStr::format(_("write error: %s"), strerror(errno));
56 return (false);
57 } else
58 return (true);
59 }
60
61 void
62 watchApp::run(int argc, char** argv)
63 {
64 extern int optind;
65 extern char* optarg;
66 int c;
67
68 appName = argv[0];
69 u_int l = appName.length();
70 appName = appName.tokenR(l, '/');
71
72 resetConfig();
73 readConfig(FAX_SYSCONF);
74 readConfig(FAX_USERCONF);
75
76 while ((c = Sys::getopt(argc, argv, "gh:lv")) != -1)
77 switch (c) {
78 case 'g':
79 setTimeZone(TZ_GMT);
80 break;
81 case 'h': // server's host
82 setHost(optarg);
83 break;
84 case 'l':
85 setTimeZone(TZ_LOCAL);
86 break;
87 case 'v': // verbose mode
88 setvbuf(stdout, NULL, _IOLBF, BUFSIZ);
89 FaxClient::setVerbose(true);// protocol tracing
90 break;
91 case '?':
92 usage();
93 /*NOTREACHED*/
94 }
95 if (argc - optind != 1)
96 usage();
97 fxStr emsg;
98 if (callServer(emsg)) {
99 if (login(NULL, emsg) && setType(TYPE_A)) {
100 if (getTimeZone() == TZ_GMT)
101 printWarning(_("time values reported in GMT"));
102 (void) recvData(writeData, STDOUT_FILENO, emsg, 0,
103 "SITE TRIGGER %s", argv[optind]);
104 }
105 hangupServer();
106 }
107 if (emsg != "")
108 printError("%s", (const char*) emsg);
109 }
110
111 void
112 watchApp::usage()
113 {
114 fxFatal(_("usage: %s [-h host] [-g] [-l] [-v] trigger-specification"),
115 (const char*) appName);
116 }
117
118 int
119 main(int argc, char** argv)
120 {
121 watchApp app;
122 app.run(argc, argv);
123 return (-1); // reached only on error
124 }