| 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 |
class faxFetchApp : public FaxClient { |
| 31 |
private: |
| 32 |
virtual void vtraceServer(const char* fmt, va_list ap); |
| 33 |
public: |
| 34 |
faxFetchApp(); |
| 35 |
~faxFetchApp(); |
| 36 |
|
| 37 |
void run(int argc, char** argv); |
| 38 |
}; |
| 39 |
faxFetchApp::faxFetchApp() {} |
| 40 |
faxFetchApp::~faxFetchApp() {} |
| 41 |
|
| 42 |
static bool |
| 43 |
writeStdout(int, const char* buf, int cc, fxStr&) |
| 44 |
{ |
| 45 |
(void) Sys::write(STDOUT_FILENO, buf, cc); |
| 46 |
return (true); |
| 47 |
} |
| 48 |
|
| 49 |
static bool |
| 50 |
writeStdout(void*, const char* buf, int cc, fxStr&) |
| 51 |
{ |
| 52 |
return writeStdout(0,buf,cc); |
| 53 |
} |
| 54 |
|
| 55 |
void |
| 56 |
faxFetchApp::vtraceServer(const char* fmt, va_list ap) |
| 57 |
{ |
| 58 |
vfprintf(stderr, fmt, ap); |
| 59 |
fputs("\n", stderr); |
| 60 |
} |
| 61 |
|
| 62 |
void |
| 63 |
faxFetchApp::run(int argc, char** argv) |
| 64 |
{ |
| 65 |
resetConfig(); |
| 66 |
readConfig(FAX_SYSCONF); |
| 67 |
readConfig(FAX_USERCONF); |
| 68 |
|
| 69 |
int c; |
| 70 |
fxStr op = "RETR "; |
| 71 |
u_int mode = MODE_S; |
| 72 |
u_long page = 0; |
| 73 |
while ((c = Sys::getopt(argc, argv, "h:o:p:svz")) != -1) |
| 74 |
switch (c) { |
| 75 |
case 'h': // server's host |
| 76 |
setHost(optarg); |
| 77 |
break; |
| 78 |
case 'p': // retrieve page |
| 79 |
op = "RETP "; |
| 80 |
page = atol(optarg); |
| 81 |
break; |
| 82 |
case 's': |
| 83 |
mode = MODE_S; |
| 84 |
break; |
| 85 |
case 'v': // enable protocol tracing |
| 86 |
setVerbose(true); |
| 87 |
break; |
| 88 |
case 'z': |
| 89 |
mode = MODE_Z; |
| 90 |
break; |
| 91 |
case '?': |
| 92 |
fxFatal(_("usage: faxfetch [-h server-host] [-v] file")); |
| 93 |
} |
| 94 |
if (optind < argc) { |
| 95 |
fxStr emsg; |
| 96 |
if (callServer(emsg)) { |
| 97 |
if (login(NULL, emsg)) { |
| 98 |
setType(TYPE_I); // always image type |
| 99 |
for (; optind < argc; optind++) |
| 100 |
if (mode == MODE_S) |
| 101 |
recvData(writeStdout, 0, emsg, page, op | argv[optind]); |
| 102 |
else |
| 103 |
recvZData(writeStdout, NULL, emsg, page, op | argv[optind]); |
| 104 |
} |
| 105 |
hangupServer(); |
| 106 |
} |
| 107 |
if (emsg != "") |
| 108 |
printError("%s", (const char*) emsg); |
| 109 |
} |
| 110 |
} |
| 111 |
|
| 112 |
int |
| 113 |
main(int argc, char** argv) |
| 114 |
{ |
| 115 |
faxFetchApp app; |
| 116 |
app.run(argc, argv); |
| 117 |
return 0; |
| 118 |
} |