| 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 "FaxRecvInfo.h" |
| 27 |
|
| 28 |
FaxRecvInfo::FaxRecvInfo() |
| 29 |
{ |
| 30 |
npages = 0; |
| 31 |
time = 0; |
| 32 |
} |
| 33 |
FaxRecvInfo::FaxRecvInfo(const FaxRecvInfo& other) |
| 34 |
: fxObj(other) |
| 35 |
, qfile(other.qfile) |
| 36 |
, commid(other.commid) |
| 37 |
, sender(other.sender) |
| 38 |
, passwd(other.passwd) |
| 39 |
, subaddr(other.subaddr) |
| 40 |
, params(other.params) |
| 41 |
, reason(other.reason) |
| 42 |
, callid(other.callid) |
| 43 |
{ |
| 44 |
npages = other.npages; |
| 45 |
time = other.time; |
| 46 |
} |
| 47 |
FaxRecvInfo::~FaxRecvInfo() {} |
| 48 |
|
| 49 |
fxStr |
| 50 |
FaxRecvInfo::encode() |
| 51 |
{ |
| 52 |
fxStr callid_formatted; |
| 53 |
for (u_int i = 0; i < callid.size(); i++) { |
| 54 |
if (i) callid_formatted.append("\",\""); |
| 55 |
callid_formatted.append(callid[i]); |
| 56 |
} |
| 57 |
return fxStr::format("%x,%x,%x,%s,%s,\"%s\",\"%s\",\"%s\",\"%s\",\"%s\"" |
| 58 |
, time |
| 59 |
, npages |
| 60 |
, params.encode() |
| 61 |
, (const char*) qfile |
| 62 |
, (const char*) commid |
| 63 |
, (const char*) sender |
| 64 |
, (const char*) passwd |
| 65 |
, (const char*) subaddr |
| 66 |
, (const char*) reason |
| 67 |
, (const char*) callid_formatted |
| 68 |
); |
| 69 |
} |
| 70 |
|
| 71 |
bool |
| 72 |
FaxRecvInfo::decode(const char* cp) |
| 73 |
{ |
| 74 |
char* np; |
| 75 |
time = (u_int) strtoul(cp, &np, 16); |
| 76 |
if (np == cp) |
| 77 |
return (false); |
| 78 |
npages = (u_short) strtoul(cp = np+1, &np, 16); |
| 79 |
if (np == cp) |
| 80 |
return (false); |
| 81 |
params.decode((u_int) strtoul(cp = np+1, &np, 16)); |
| 82 |
if (np == cp) |
| 83 |
return (false); |
| 84 |
qfile = np+1; |
| 85 |
qfile.resize(qfile.next(0,',')); |
| 86 |
cp = strchr(np+1, ','); |
| 87 |
if (cp == NULL) |
| 88 |
return (false); |
| 89 |
commid = cp+1; |
| 90 |
commid.resize(commid.next(0,',')); |
| 91 |
cp = strchr(cp+1, '"'); |
| 92 |
if (cp == NULL) |
| 93 |
return (false); |
| 94 |
sender = cp+1; |
| 95 |
sender.resize(sender.next(0,'"')); |
| 96 |
cp = strchr(cp+1, '"'); |
| 97 |
if (cp == NULL || cp[1] != ',' || cp[2] != '"') |
| 98 |
return (false); |
| 99 |
passwd = cp+1; |
| 100 |
passwd.resize(sender.next(0,'"')); |
| 101 |
cp = strchr(cp+1, '"'); |
| 102 |
if (cp == NULL || cp[1] != ',' || cp[2] != '"') |
| 103 |
return (false); |
| 104 |
subaddr = cp+3; // +1 for "/+1 for ,/+1 for " |
| 105 |
subaddr.resize(subaddr.next(0,'"')); |
| 106 |
cp = strchr(cp+1, '"'); |
| 107 |
if (cp == NULL || cp[1] != ',' || cp[2] != '"') |
| 108 |
return (false); |
| 109 |
reason = cp+3; // +1 for "/+1 for ,/+1 for " |
| 110 |
reason.resize(reason.next(0,'"')); |
| 111 |
cp = strchr(cp+1, '"'); |
| 112 |
if (cp == NULL || cp[1] != ',' || cp[2] != '"') |
| 113 |
return (false); |
| 114 |
u_int i = 0; |
| 115 |
while (cp[2] != '\0') { |
| 116 |
callid[i] = cp+3; // +1 for "/+1 for ,/+1 for " |
| 117 |
if (*cp == '\"') break; |
| 118 |
callid[i].resize(callid[i].next(0,'"')); |
| 119 |
i++; |
| 120 |
} |
| 121 |
return (true); |
| 122 |
} |