summaryrefslogtreecommitdiffabout
path: root/T42Secretary.cpp
authorMichael Krelin <hacker@klever.net>2004-07-05 01:53:09 (UTC)
committer Michael Krelin <hacker@klever.net>2004-07-05 01:53:09 (UTC)
commit955d4e00adc9f39ab93bf21f07506eb75b013c70 (patch) (unidiff)
tree92493a2c9ac206b822e24a9e5a6f6b1589be6afb /T42Secretary.cpp
downloadT42-955d4e00adc9f39ab93bf21f07506eb75b013c70.zip
T42-955d4e00adc9f39ab93bf21f07506eb75b013c70.tar.gz
T42-955d4e00adc9f39ab93bf21f07506eb75b013c70.tar.bz2
initial commit into svn repository
git-svn-id: http://svn.klever.net/kin/T42/trunk@1 fe716a7a-6dde-0310-88d9-d003556173a8
Diffstat (limited to 'T42Secretary.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--T42Secretary.cpp121
1 files changed, 121 insertions, 0 deletions
diff --git a/T42Secretary.cpp b/T42Secretary.cpp
new file mode 100644
index 0000000..62cef87
--- a/dev/null
+++ b/T42Secretary.cpp
@@ -0,0 +1,121 @@
1// T42Secretary.cpp : implementation file
2//
3
4#include "stdafx.h"
5#include "T42.h"
6#include "T42Document.h"
7#include "T42Secretary.h"
8
9#include "T42View.h"
10#include "T42Frame.h"
11
12CT42Secretary::CT42Secretary()
13{
14 m_logEntry.m_Time = CTime::GetCurrentTime();
15CT42App* app = (CT42App*)AfxGetApp();
16 app->m_T42LinesBusy++;
17 m_limitTime = app->m_T42STimeLimit;
18 m_limitBytes = app->m_T42SBytesLimit;
19 TRACE0("Secretary++\n");
20}
21
22CT42Secretary::~CT42Secretary()
23{
24CT42App* app = (CT42App*)AfxGetApp();
25 app->m_T42LinesBusy--;
26 TRACE0("Secretary--\n");
27}
28
29
30BOOL CT42Secretary::OnAttach(T42Document* pDocument)
31{
32 TRACE0("T42S - OnAttach\n");
33 return CT42Robot::OnAttach(pDocument);
34}
35
36BOOL CT42Secretary::OnConnect()
37{
38 m_logEntry.m_Caller = m_pDocument->m_pView->m_pFrame->m_Target;
39 m_logEntry.m_Callee = m_pDocument->m_pView->m_pFrame->m_LocalUser;
40 m_logEntry.m_Message.Empty();
41 m_logEntry.m_Time = CTime::GetCurrentTime();
42
43CT42App* app = (CT42App*)AfxGetApp();
44CString greet = app->m_T42SGreeting;
45int ix;
46 while((ix=greet.Find("%t"))>=0){
47 CString tmp;
48 tmp.Format("%lu",app->m_T42STimeLimit.GetTotalSeconds()/60);
49 greet = greet.Left(ix)+tmp+greet.Mid(ix+2);
50 }
51 while((ix=greet.Find("%c"))>=0){
52 CString tmp;
53 tmp.Format("%u",app->m_T42SBytesLimit);
54 greet = greet.Left(ix)+tmp+greet.Mid(ix+2);
55 }
56 m_pDocument->SendOver(greet);
57 return TRUE;
58}
59
60BOOL CT42Secretary::OnReceive(char* pData,int nBytes)
61{
62 if(m_limitBytes && m_pDocument->m_pView->m_remoteCtl.GetTextLength()>=m_limitBytes)
63 OnDisconnect();
64 return TRUE;
65}
66
67BOOL CT42Secretary::OnDisconnect()
68{
69 m_logEntry.m_Duration = CTime::GetCurrentTime()-m_logEntry.m_Time;
70EDITSTREAM es;
71 memset(&es,0,sizeof(es));
72 es.dwCookie = (DWORD)&m_logEntry.m_Message;
73 es.pfnCallback = ESINProc;
74 m_pDocument->m_pView->m_remoteCtl.StreamOut(SF_RTF,es);
75 m_logEntry.m_Status = CT42CallLogEntry::statusOk;
76CT42App* app = (CT42App*)AfxGetApp();
77 VERIFY(app->AddT42Call(m_logEntry));
78 m_pDocument->m_pView->m_pFrame->OnTalkClose();
79 return TRUE;
80}
81
82BOOL CT42Secretary::OnDetach()
83{
84 TRACE0("T42S - OnDetach\n");
85 delete this;
86 return TRUE;
87}
88
89
90BOOL CT42Secretary::OnIPResolved()
91{
92 m_logEntry.m_Caller = m_pDocument->m_pView->m_pFrame->m_Target;
93 return TRUE;
94}
95
96DWORD CALLBACK CT42Secretary::ESINProc(DWORD dwCookie,LPBYTE pbBuff,LONG cb,LONG FAR *pcb)
97{
98CString* str = (CString*)dwCookie;
99 if(memchr(pbBuff,0,cb-1)){
100 (*pcb) = 0;
101 return 1;
102 }
103UINT p = str->GetLength();
104CHAR* s = str->GetBuffer(p+cb+1);
105 memmove(&s[p],pbBuff,cb);
106 s[p+cb]=0;
107 str->ReleaseBuffer();
108 (*pcb)=cb;
109 return 0;
110}
111
112BOOL CT42Secretary::OnMinute()
113{
114 if(
115 m_limitTime.GetTotalSeconds() &&
116 (CTime::GetCurrentTime()-m_logEntry.m_Time)>=m_limitTime
117 )
118 OnDisconnect();
119 return TRUE;
120}
121