FaxRecvInfo.c++
上传用户:weiyuanprp
上传日期:2020-05-20
资源大小:1169k
文件大小:4k
源码类别:

传真(Fax)编程

开发平台:

C/C++

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