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) (side-by-side diff)
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) (show 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 @@
+// T42Secretary.cpp : implementation file
+//
+
+#include "stdafx.h"
+#include "T42.h"
+#include "T42Document.h"
+#include "T42Secretary.h"
+
+#include "T42View.h"
+#include "T42Frame.h"
+
+CT42Secretary::CT42Secretary()
+{
+ m_logEntry.m_Time = CTime::GetCurrentTime();
+CT42App* app = (CT42App*)AfxGetApp();
+ app->m_T42LinesBusy++;
+ m_limitTime = app->m_T42STimeLimit;
+ m_limitBytes = app->m_T42SBytesLimit;
+ TRACE0("Secretary++\n");
+}
+
+CT42Secretary::~CT42Secretary()
+{
+CT42App* app = (CT42App*)AfxGetApp();
+ app->m_T42LinesBusy--;
+ TRACE0("Secretary--\n");
+}
+
+
+BOOL CT42Secretary::OnAttach(T42Document* pDocument)
+{
+ TRACE0("T42S - OnAttach\n");
+ return CT42Robot::OnAttach(pDocument);
+}
+
+BOOL CT42Secretary::OnConnect()
+{
+ m_logEntry.m_Caller = m_pDocument->m_pView->m_pFrame->m_Target;
+ m_logEntry.m_Callee = m_pDocument->m_pView->m_pFrame->m_LocalUser;
+ m_logEntry.m_Message.Empty();
+ m_logEntry.m_Time = CTime::GetCurrentTime();
+
+CT42App* app = (CT42App*)AfxGetApp();
+CString greet = app->m_T42SGreeting;
+int ix;
+ while((ix=greet.Find("%t"))>=0){
+ CString tmp;
+ tmp.Format("%lu",app->m_T42STimeLimit.GetTotalSeconds()/60);
+ greet = greet.Left(ix)+tmp+greet.Mid(ix+2);
+ }
+ while((ix=greet.Find("%c"))>=0){
+ CString tmp;
+ tmp.Format("%u",app->m_T42SBytesLimit);
+ greet = greet.Left(ix)+tmp+greet.Mid(ix+2);
+ }
+ m_pDocument->SendOver(greet);
+ return TRUE;
+}
+
+BOOL CT42Secretary::OnReceive(char* pData,int nBytes)
+{
+ if(m_limitBytes && m_pDocument->m_pView->m_remoteCtl.GetTextLength()>=m_limitBytes)
+ OnDisconnect();
+ return TRUE;
+}
+
+BOOL CT42Secretary::OnDisconnect()
+{
+ m_logEntry.m_Duration = CTime::GetCurrentTime()-m_logEntry.m_Time;
+EDITSTREAM es;
+ memset(&es,0,sizeof(es));
+ es.dwCookie = (DWORD)&m_logEntry.m_Message;
+ es.pfnCallback = ESINProc;
+ m_pDocument->m_pView->m_remoteCtl.StreamOut(SF_RTF,es);
+ m_logEntry.m_Status = CT42CallLogEntry::statusOk;
+CT42App* app = (CT42App*)AfxGetApp();
+ VERIFY(app->AddT42Call(m_logEntry));
+ m_pDocument->m_pView->m_pFrame->OnTalkClose();
+ return TRUE;
+}
+
+BOOL CT42Secretary::OnDetach()
+{
+ TRACE0("T42S - OnDetach\n");
+ delete this;
+ return TRUE;
+}
+
+
+BOOL CT42Secretary::OnIPResolved()
+{
+ m_logEntry.m_Caller = m_pDocument->m_pView->m_pFrame->m_Target;
+ return TRUE;
+}
+
+DWORD CALLBACK CT42Secretary::ESINProc(DWORD dwCookie,LPBYTE pbBuff,LONG cb,LONG FAR *pcb)
+{
+CString* str = (CString*)dwCookie;
+ if(memchr(pbBuff,0,cb-1)){
+ (*pcb) = 0;
+ return 1;
+ }
+UINT p = str->GetLength();
+CHAR* s = str->GetBuffer(p+cb+1);
+ memmove(&s[p],pbBuff,cb);
+ s[p+cb]=0;
+ str->ReleaseBuffer();
+ (*pcb)=cb;
+ return 0;
+}
+
+BOOL CT42Secretary::OnMinute()
+{
+ if(
+ m_limitTime.GetTotalSeconds() &&
+ (CTime::GetCurrentTime()-m_logEntry.m_Time)>=m_limitTime
+ )
+ OnDisconnect();
+ return TRUE;
+}
+