summaryrefslogtreecommitdiffabout
path: root/T42Secretary.cpp
blob: 62cef8786620c8a02288d8ea27c0c2821797da4c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
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;
}