| 1 |
/* $Id$ */ |
| 2 |
/* |
| 3 |
* Copyright (c) 1995-1996 Sam Leffler |
| 4 |
* Copyright (c) 1995-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 "config.h" |
| 27 |
#include "Transport.h" |
| 28 |
#include "FaxClient.h" |
| 29 |
#include "InetTransport.h" |
| 30 |
#if CONFIG_UNIXTRANSPORT |
| 31 |
#include "UnixTransport.h" |
| 32 |
#endif |
| 33 |
#include "Sys.h" |
| 34 |
|
| 35 |
#include <errno.h> |
| 36 |
|
| 37 |
Transport::Transport(FaxClient& c) : client(c) {} |
| 38 |
Transport::~Transport() {} |
| 39 |
bool Transport::hangupServer() { return (true); } |
| 40 |
|
| 41 |
void |
| 42 |
Transport::closeDataConn(int fd) |
| 43 |
{ |
| 44 |
(void) Sys::close(fd); |
| 45 |
} |
| 46 |
|
| 47 |
Transport& |
| 48 |
Transport::getTransport(FaxClient& client, const char* address) |
| 49 |
{ |
| 50 |
if (address[0] == '\0') { |
| 51 |
/* |
| 52 |
* An unqualified destination; look for |
| 53 |
* the best available transport facility. |
| 54 |
*/ |
| 55 |
#if CONFIG_UNIXTRANSPORT |
| 56 |
if (UnixTransport::isA(FAX_DEFUNIX)) { |
| 57 |
client.setHost(FAX_DEFUNIX); |
| 58 |
return *new UnixTransport(client); |
| 59 |
} else { |
| 60 |
#endif |
| 61 |
client.setHost(FAX_DEFHOST); |
| 62 |
return *new InetTransport(client); |
| 63 |
#if CONFIG_UNIXTRANSPORT |
| 64 |
} |
| 65 |
#endif |
| 66 |
} else { |
| 67 |
#if CONFIG_UNIXTRANSPORT |
| 68 |
if (UnixTransport::isA(address)) |
| 69 |
return *new UnixTransport(client); |
| 70 |
else |
| 71 |
#endif |
| 72 |
return *new InetTransport(client); |
| 73 |
} |
| 74 |
} |
| 75 |
|
| 76 |
bool |
| 77 |
Transport::abortCmd(fxStr& emsg) |
| 78 |
{ |
| 79 |
static const char msg[] = { 'A', 'B', 'O', 'R', '\r', '\n' }; |
| 80 |
int s = fileno(client.getCtrlFd()); |
| 81 |
if (Sys::write(s, msg, sizeof (msg)) != sizeof (msg)) { |
| 82 |
emsg = fxStr::format("send(ABOR\\r\\n): %s", strerror(errno)); |
| 83 |
return (false); |
| 84 |
} |
| 85 |
return (true); |
| 86 |
} |