24
|
1 |
// Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
2 |
// All rights reserved.
|
|
3 |
// This component and the accompanying materials are made available
|
|
4 |
// under the terms of "Eclipse Public License v1.0"
|
|
5 |
// which accompanies this distribution, and is available
|
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
7 |
//
|
|
8 |
// Initial Contributors:
|
|
9 |
// Nokia Corporation - initial contribution.
|
|
10 |
//
|
|
11 |
// Contributors:
|
|
12 |
//
|
|
13 |
// Description:
|
|
14 |
// NetDial Script Executor
|
|
15 |
//
|
|
16 |
//
|
|
17 |
|
|
18 |
/**
|
|
19 |
@file Sscrexec.cpp
|
|
20 |
*/
|
|
21 |
|
|
22 |
#include "SSCREXEC.H"
|
|
23 |
#include "SIO.H"
|
|
24 |
#include "SLOGGER.H"
|
|
25 |
#include "ND_SCR.H"
|
|
26 |
|
|
27 |
_LIT(KPPPProtocolName,"PPP.");
|
|
28 |
|
|
29 |
const TInt KNumErrorVariables=9;
|
|
30 |
//const TInt KMaxReadFromPctLength=256;
|
|
31 |
//const TInt KMaxReadFromPctLength8=2*KMaxReadFromPctLength;
|
|
32 |
|
|
33 |
const SErrorVariable ErrorVariables[KNumErrorVariables]=
|
|
34 |
{
|
|
35 |
{KErrExitScriptTimeOutString,KErrExitScriptTimeOut},
|
|
36 |
{KErrExitLoginFailString,KErrExitLoginFail},
|
|
37 |
{KErrExitNoModemString,KErrExitNoModem},
|
|
38 |
{KErrExitModemErrorString,KErrExitModemError},
|
|
39 |
{KErrExitNoAnswerString,KErrEtelNoAnswer},
|
|
40 |
{KErrExitNoCarrierString,KErrEtelNoCarrier},
|
|
41 |
{KErrExitNoDialToneString,KErrEtelNoDialTone},
|
|
42 |
{KErrExitBusyString,KErrEtelBusyDetected},
|
|
43 |
{KErrExitModemInitErrorString,KErrEtelInitialisationFailure},
|
|
44 |
};
|
|
45 |
|
|
46 |
// CScriptExecutor definitons
|
|
47 |
CScriptExecutor* CScriptExecutor::NewL(CNetDialScript* aScript,const TDesC& aCommChannel, TInt aScriptLength)
|
|
48 |
|
|
49 |
/**
|
|
50 |
2 phased constructor for CScriptExecutor, first phase.
|
|
51 |
|
|
52 |
@param aScript a pointer to used script.
|
|
53 |
@param aCommPort a reference to COMM port.
|
|
54 |
@param aScriptLength is lenght for used script.
|
|
55 |
@exception Leaves if ConstructL() leaves, or not enough memory is available.
|
|
56 |
@return a new CScriptExecutor object.
|
|
57 |
*/
|
|
58 |
{
|
|
59 |
CScriptExecutor* p=new(ELeave) CScriptExecutor(aScript);
|
|
60 |
CleanupStack::PushL(p);
|
|
61 |
p->ConstructL(aCommChannel, aScriptLength);
|
|
62 |
CleanupStack::Pop();
|
|
63 |
return p;
|
|
64 |
}
|
|
65 |
|
|
66 |
CScriptExecutor::CScriptExecutor(CNetDialScript* aScript)
|
|
67 |
: CActive(EPriorityStandard), iScript(aScript), iInitializationFlag(EFalse),iServerRetransmitLoginPromptStatus(EFirstWaitCommand)
|
|
68 |
/**
|
|
69 |
Constructor for CScriptExecutor, used in the first phase of construction.
|
|
70 |
|
|
71 |
@param aScript a pointer to used script.
|
|
72 |
*/
|
|
73 |
{}
|
|
74 |
|
|
75 |
void CScriptExecutor::ConstructL(const TDesC& aCommChannel, TInt aScriptLength)
|
|
76 |
/**
|
|
77 |
Instantiate member variables.
|
|
78 |
|
|
79 |
@param aCommPort a reference to COMM port.
|
|
80 |
@param aScriptLength is script lenght.
|
|
81 |
*/
|
|
82 |
{
|
|
83 |
CActiveScheduler::Add(this);
|
|
84 |
|
|
85 |
iScriptIO=CScriptIO::NewL(this, aCommChannel);
|
|
86 |
|
|
87 |
// create script reader if script length is greater than zero
|
|
88 |
if (aScriptLength>0)
|
|
89 |
{
|
|
90 |
iScriptReader=CScriptReader::NewL(aScriptLength);
|
|
91 |
TScriptStatus scriptStatus=iScriptReader->ScriptStatus();
|
|
92 |
iVarMan=CScriptVarMan::NewL();
|
|
93 |
iCharConv=CScriptCharacterConverter::NewL();
|
|
94 |
iLabelMan=CScriptLabelMan::NewL();
|
|
95 |
// Construct Command Managers
|
|
96 |
iWaitCommand=CWaitCommand::NewL(scriptStatus,iScriptReader,iVarMan,iCharConv,iScriptIO,iLabelMan, this);
|
|
97 |
iCommands[0]=iWaitCommand;
|
|
98 |
iCommands[1]=CSendCommand::NewL(scriptStatus,iScriptReader,iVarMan,iCharConv,iScriptIO);
|
|
99 |
iReadCommand=CReadPCTCommand::NewL(scriptStatus,iScriptReader,iVarMan,iCharConv,this);
|
|
100 |
iCommands[2]=iReadCommand;
|
|
101 |
iLoopCommand=CLoopCommand::NewL(scriptStatus,iScriptReader,iVarMan,iCharConv);
|
|
102 |
iCommands[3]=iLoopCommand;
|
|
103 |
iCommands[4]=CExitCommand::NewL(scriptStatus,iScriptReader,iVarMan,iCharConv);
|
|
104 |
iGotoCommand=CGotoCommand::NewL(scriptStatus,iScriptReader,iVarMan,iCharConv,iLabelMan);
|
|
105 |
iCommands[5]=iGotoCommand;
|
|
106 |
iCommands[6]=CSetCommand::NewL(scriptStatus,iScriptReader,iVarMan,iCharConv);
|
|
107 |
iCommands[7]=CDTRCommand::NewL(scriptStatus,iScriptReader,iVarMan,iCharConv,iScriptIO);
|
|
108 |
iCommands[8]=CCharMapCommand::NewL(scriptStatus,iScriptReader,iVarMan,iCharConv);
|
|
109 |
// Add Error Variables
|
|
110 |
__ASSERT_DEBUG((sizeof(ErrorVariables)/sizeof(SErrorVariable))==KNumErrorVariables,NetDialPanic(ENumOfVariablesIncorrect));
|
|
111 |
TInt i;
|
|
112 |
for (i=0; i<KNumErrorVariables; i++)
|
|
113 |
iVarMan->AddVariableL(TPtrC(ErrorVariables[i].iString),ErrorVariables[i].iValue);
|
|
114 |
}
|
|
115 |
else
|
|
116 |
{
|
|
117 |
iScriptReader=NULL;
|
|
118 |
iVarMan=NULL;
|
|
119 |
iCharConv=NULL;
|
|
120 |
iLabelMan=NULL;
|
|
121 |
iWaitCommand=NULL;
|
|
122 |
iReadCommand=NULL;
|
|
123 |
iGotoCommand=NULL;
|
|
124 |
iLoopCommand=NULL;
|
|
125 |
TInt i;
|
|
126 |
for (i=0; i<KNumCommands; i++)
|
|
127 |
iCommands[i]=NULL;
|
|
128 |
}
|
|
129 |
|
|
130 |
// PCT stuff
|
|
131 |
iReadFound=EFalse;
|
|
132 |
iReadReq=0;
|
|
133 |
iReadFromPctPending=EFalse;
|
|
134 |
iDataToWrite.SetLength(0);
|
|
135 |
}
|
|
136 |
|
|
137 |
CScriptExecutor::~CScriptExecutor()
|
|
138 |
/**
|
|
139 |
Destructor.
|
|
140 |
Cancels active requests and deletes members.
|
|
141 |
*/
|
|
142 |
{
|
|
143 |
Cancel();
|
|
144 |
delete iDummySearchArray;
|
|
145 |
delete iScriptIO;
|
|
146 |
delete iScriptReader;
|
|
147 |
delete iVarMan;
|
|
148 |
delete iCharConv;
|
|
149 |
delete iLabelMan;
|
|
150 |
for(TInt i=0;i<KNumCommands ;i++)
|
|
151 |
delete iCommands[i];
|
|
152 |
}
|
|
153 |
|
|
154 |
void CScriptExecutor::SetLoginParams(const TDesC& aLoginName,const TDesC& aLoginPass)
|
|
155 |
/**
|
|
156 |
Sets login parameters.
|
|
157 |
|
|
158 |
@param aLoginName a reference to login name.
|
|
159 |
@param aLoginPass a reference to login password.
|
|
160 |
*/
|
|
161 |
{
|
|
162 |
iLoginName.Copy(aLoginName);
|
|
163 |
iLoginPass.Copy(aLoginPass);
|
|
164 |
}
|
|
165 |
|
|
166 |
void CScriptExecutor::SetScript(const TDesC& aScript)
|
|
167 |
/**
|
|
168 |
Sets script.
|
|
169 |
|
|
170 |
@param aScript a reference to login name.
|
|
171 |
*/
|
|
172 |
{
|
|
173 |
__ASSERT_DEBUG(iLastCommand==NULL, NetDialPanic(ELastCommandNotNull));
|
|
174 |
__ASSERT_DEBUG(iScriptReader!=NULL, NetDialPanic(ENullScriptReader));
|
|
175 |
|
|
176 |
__FLOG_STMT(_LIT8(logString,"Script:\tBeginning");)
|
|
177 |
__FLOG_STATIC(KNetDialLogFolder(),KNetDialLogFile(),logString());
|
|
178 |
iScriptReader->SetScript(aScript);
|
|
179 |
iLoopCommand->Loop(EFalse);
|
|
180 |
}
|
|
181 |
|
|
182 |
void CScriptExecutor::ScanScriptL()
|
|
183 |
/**
|
|
184 |
Scans script for READ command.
|
|
185 |
*/
|
|
186 |
{
|
|
187 |
__FLOG_STMT(_LIT8(logString1,"Script:\tScanning");)
|
|
188 |
__FLOG_STATIC(KNetDialLogFolder(),KNetDialLogFile(),logString1());
|
|
189 |
|
|
190 |
__ASSERT_DEBUG(iScriptReader!=NULL, NetDialPanic(ENullScriptReader));
|
|
191 |
|
|
192 |
iReadFound=EFalse;
|
|
193 |
TInt ret=KErrNone;
|
|
194 |
iScriptReader->SetLoggingOff();
|
|
195 |
while (ret!=KErrScriptCompleted)
|
|
196 |
{
|
|
197 |
TRAP(ret,(iReadFound=iReadCommand->CheckReadL()));
|
|
198 |
if (iReadFound || ret!=KErrNone)
|
|
199 |
break;
|
|
200 |
ret=iScriptReader->GetNextLine();
|
|
201 |
}
|
|
202 |
|
|
203 |
if (iReadFound)
|
|
204 |
{
|
|
205 |
__FLOG_STMT(_LIT8(logString2,"Script:\tFound Read");)
|
|
206 |
__FLOG_STATIC(KNetDialLogFolder(),KNetDialLogFile(),logString2());
|
|
207 |
}
|
|
208 |
else
|
|
209 |
{
|
|
210 |
__FLOG_STMT(_LIT8(logString3,"Script:\tDid Not Find Read");)
|
|
211 |
__FLOG_STATIC(KNetDialLogFolder(),KNetDialLogFile(),logString3());
|
|
212 |
}
|
|
213 |
|
|
214 |
User::LeaveIfError(iScriptReader->Reset());
|
|
215 |
}
|
|
216 |
|
|
217 |
void CScriptExecutor::RunScript()
|
|
218 |
/**
|
|
219 |
Runs script.
|
|
220 |
*/
|
|
221 |
{
|
|
222 |
iScriptIO->Start();
|
|
223 |
iStatus=KRequestPending;
|
|
224 |
SetActive();
|
|
225 |
}
|
|
226 |
|
|
227 |
void CScriptExecutor::ProcessScript()
|
|
228 |
/**
|
|
229 |
Processes script line by line
|
|
230 |
*/
|
|
231 |
{
|
|
232 |
TRAPD(ret,ProcessNextLinesL());
|
|
233 |
if(ret!=KErrNone)
|
|
234 |
{
|
|
235 |
CompletedScript(ret);
|
|
236 |
}
|
|
237 |
}
|
|
238 |
|
|
239 |
void CScriptExecutor::ProcessNextLinesL()
|
|
240 |
/**
|
|
241 |
If read/write not pending clear previous command. Toggle skip mode if necessary then
|
|
242 |
either parse label or jump to beginning of loop or parse command as necessary.
|
|
243 |
*/
|
|
244 |
{
|
|
245 |
__ASSERT_DEBUG(iScriptReader!=NULL, NetDialPanic(ENullScriptReader));
|
|
246 |
|
|
247 |
while(!(iScriptIO->RWPending())&& !(iReadFromPctPending))
|
|
248 |
{
|
|
249 |
CleanupLastCommand();
|
|
250 |
iGotoCommand->ServiceSkipReqs();
|
|
251 |
if(iGotoCommand->ParseLabelL())
|
|
252 |
continue;
|
|
253 |
if(iLoopCommand->CheckLoopL())
|
|
254 |
continue;
|
|
255 |
|
|
256 |
TInt i;
|
|
257 |
for(i=0;i<KNumCommands;i++)
|
|
258 |
{
|
|
259 |
if(iCommands[i]->ParseL())
|
|
260 |
{
|
|
261 |
iLastCommand=iCommands[i];
|
|
262 |
break;
|
|
263 |
}
|
|
264 |
}
|
|
265 |
if(iLastCommand==NULL)
|
|
266 |
User::Leave(KErrIllegalCommand);
|
|
267 |
}
|
|
268 |
}
|
|
269 |
|
|
270 |
void CScriptExecutor::CompletedWrite(TInt aStatus)
|
|
271 |
/**
|
|
272 |
Stops script if aStatus is an error, otherwise continue to process.
|
|
273 |
|
|
274 |
@param aStatus is status passed from caller.
|
|
275 |
*/
|
|
276 |
{
|
|
277 |
if((aStatus==KErrTimedOut)&&(iInitializationFlag))
|
|
278 |
CompletedScript(KErrExitNoModem);
|
|
279 |
else if((aStatus==KErrNone)||(aStatus==KErrTimedOut))
|
|
280 |
{
|
|
281 |
if (iDataToWrite.Length()>0 && !iScriptIO->WritePending())
|
|
282 |
{
|
|
283 |
iScriptIO->Write(iDataToWrite);
|
|
284 |
iDataToWrite.SetLength(0);
|
|
285 |
}
|
|
286 |
else
|
|
287 |
{
|
|
288 |
iInitializationFlag=EFalse;
|
|
289 |
if(iServerRetransmitLoginPromptStatus == ESendingCR)
|
|
290 |
{
|
|
291 |
// The previous WAIT for a login prompt timed out and we sent
|
|
292 |
// a 0x0d to encourage the server to resend the login
|
|
293 |
// So wait for the login prompt again
|
|
294 |
iServerRetransmitLoginPromptStatus = ESecondWaitCommand;
|
|
295 |
TRAPD(ret, iDummySearchArray=new(ELeave) CLabelSearchArray(1));
|
|
296 |
if(ret != KErrNone)
|
|
297 |
{
|
|
298 |
iServerRetransmitLoginPromptStatus = EDeactivated;
|
|
299 |
ProcessScript();
|
|
300 |
}
|
|
301 |
else iScriptIO->Read(iDummySearchArray, iRetransmitLoginTimeOut);
|
|
302 |
}
|
|
303 |
else ProcessScript();
|
|
304 |
}
|
|
305 |
}
|
|
306 |
else
|
|
307 |
CompletedScript(aStatus);
|
|
308 |
}
|
|
309 |
|
|
310 |
void CScriptExecutor::CompletedReadL(TInt aStatus,TInt aIndex)
|
|
311 |
/**
|
|
312 |
Stops script if there is an error, or otherwise continue to process or jump to
|
|
313 |
label as ncessary. Ignore comms line fail errors.
|
|
314 |
|
|
315 |
@param aStatus is passed from caller.
|
|
316 |
@param aIndex is index for label.
|
|
317 |
*/
|
|
318 |
{
|
|
319 |
__ASSERT_DEBUG(iScriptReader!=NULL, NetDialPanic(ENullScriptReader));
|
|
320 |
|
|
321 |
if(iServerRetransmitLoginPromptStatus == ESecondWaitCommand)
|
|
322 |
{
|
|
323 |
// We must have sent a 0x0d to try and force the server to retransmit the
|
|
324 |
// login prompt
|
|
325 |
// Delete the dummy search array and stop the RetransmitLogin mechanism since
|
|
326 |
// irrespective of the outcome of the read, we're not going to send any more 0x0d
|
|
327 |
delete iDummySearchArray;
|
|
328 |
iDummySearchArray=NULL;
|
|
329 |
iServerRetransmitLoginPromptStatus=EDeactivated;
|
|
330 |
}
|
|
331 |
|
|
332 |
if(iInitializationFlag)
|
|
333 |
{
|
|
334 |
iInitializationFlag=EFalse;
|
|
335 |
ProcessScript();
|
|
336 |
}
|
|
337 |
else
|
|
338 |
{
|
|
339 |
switch(aStatus)
|
|
340 |
{
|
|
341 |
case KErrNone:
|
|
342 |
{
|
|
343 |
iServerRetransmitLoginPromptStatus=EDeactivated;
|
|
344 |
TPtrC label=iWaitCommand->LabelFromIndexL(aIndex);
|
|
345 |
iGotoCommand->Goto(label);
|
|
346 |
}
|
|
347 |
ProcessScript();
|
|
348 |
break;
|
|
349 |
case KErrTimedOut:
|
|
350 |
// If the very first WAIT script command fails it's possible that the
|
|
351 |
// server sent the login prompt before MM.TSY had finished with
|
|
352 |
// the serial port
|
|
353 |
// If so, we can send a 0x0d (Carriage Return) to wake it up
|
|
354 |
// and re-transmit the login prompt
|
|
355 |
if(iServerRetransmitLoginPromptStatus == EFirstWaitCommand)
|
|
356 |
{
|
|
357 |
// Transmit a 0x0d to the server
|
|
358 |
iServerRetransmitLoginPromptStatus=ESendingCR;
|
|
359 |
TBuf8<1> CarriageReturn;
|
|
360 |
CarriageReturn.SetLength(1);
|
|
361 |
CarriageReturn[0]=0x0d;
|
|
362 |
TPtrC8 CR(CarriageReturn);
|
|
363 |
iScriptIO->Write(CR);
|
|
364 |
break;
|
|
365 |
}
|
|
366 |
iServerRetransmitLoginPromptStatus=EDeactivated;
|
|
367 |
ProcessScript();
|
|
368 |
break;
|
|
369 |
case KErrCommsLineFail:
|
|
370 |
iServerRetransmitLoginPromptStatus=EDeactivated;
|
|
371 |
ProcessScript();
|
|
372 |
break;
|
|
373 |
default:
|
|
374 |
iServerRetransmitLoginPromptStatus=EDeactivated;
|
|
375 |
CompletedScript(aStatus);
|
|
376 |
break;
|
|
377 |
}
|
|
378 |
}
|
|
379 |
}
|
|
380 |
|
|
381 |
void CScriptExecutor::CompletedScript(TInt aStatus)
|
|
382 |
/**
|
|
383 |
If aStatus is not an error, check that not still looking for a label.
|
|
384 |
Convert internal error to public error and finish.
|
|
385 |
|
|
386 |
@param aStatus is passed from caller.
|
|
387 |
*/
|
|
388 |
{
|
|
389 |
// Safety check - this method may be called from multiple locations,
|
|
390 |
// possibly resulting in more than one call for the same event.
|
|
391 |
if (iStatus==KRequestPending)
|
|
392 |
{
|
|
393 |
__ASSERT_DEBUG(iScriptReader!=NULL, NetDialPanic(ENullScriptReader));
|
|
394 |
|
|
395 |
if(aStatus==KErrScriptCompleted)
|
|
396 |
aStatus=KErrNone;
|
|
397 |
|
|
398 |
TInt error=aStatus;
|
|
399 |
|
|
400 |
__FLOG_STMT(_LIT8(logString,"Script:\tScript Completed With Error %d");)
|
|
401 |
__FLOG_STATIC1(KNetDialLogFolder(),KNetDialLogFile(),TRefByValue<const TDesC8>(logString()),error);
|
|
402 |
|
|
403 |
ConvertScriptError(error);
|
|
404 |
PctCancelAndClose();
|
|
405 |
|
|
406 |
CleanupLastCommand();
|
|
407 |
iLoopCommand->Loop(EFalse);
|
|
408 |
|
|
409 |
iScriptIO->Cancel();
|
|
410 |
|
|
411 |
TRequestStatus* statusPtr=&iStatus;
|
|
412 |
User::RequestComplete(statusPtr,error);
|
|
413 |
}
|
|
414 |
}
|
|
415 |
|
|
416 |
void CScriptExecutor::DoCancel()
|
|
417 |
/**
|
|
418 |
Cancel read/write, and callbacks and cleanup last command
|
|
419 |
*/
|
|
420 |
{
|
|
421 |
if(iServerRetransmitLoginPromptStatus == ESecondWaitCommand)
|
|
422 |
{
|
|
423 |
delete iDummySearchArray;
|
|
424 |
iDummySearchArray=NULL;
|
|
425 |
iServerRetransmitLoginPromptStatus=EDeactivated;
|
|
426 |
}
|
|
427 |
|
|
428 |
CleanupLastCommand();
|
|
429 |
iScriptIO->Cancel();
|
|
430 |
PctCancelAndClose();
|
|
431 |
|
|
432 |
TRequestStatus* statusPtr=&iStatus;
|
|
433 |
User::RequestComplete(statusPtr,KErrCancel);
|
|
434 |
iScript->ScriptOperationComplete(KErrCancel);
|
|
435 |
}
|
|
436 |
|
|
437 |
void CScriptExecutor::Disconnect()
|
|
438 |
/**
|
|
439 |
Disconect.
|
|
440 |
*/
|
|
441 |
{
|
|
442 |
iScriptIO->Disconnect();
|
|
443 |
}
|
|
444 |
|
|
445 |
void CScriptExecutor::ReConfigureAndCancelCommPort(TRequestStatus& aStatus)
|
|
446 |
/**
|
|
447 |
Call ReConfigureAndCancelPort() from script IO handler.
|
|
448 |
*/
|
|
449 |
{
|
|
450 |
iScriptIO->ReConfigureAndCancelPort(aStatus);
|
|
451 |
}
|
|
452 |
|
|
453 |
|
|
454 |
void CScriptExecutor::CloseScript()
|
|
455 |
/**
|
|
456 |
Close script.
|
|
457 |
*/
|
|
458 |
{
|
|
459 |
__FLOG_STMT(_LIT8(logString,"Script:\tClosing");)
|
|
460 |
__FLOG_STATIC(KNetDialLogFolder(),KNetDialLogFile(),logString());
|
|
461 |
if (iScriptReader!=NULL)
|
|
462 |
iScriptReader->Reset(); // ignore error
|
|
463 |
}
|
|
464 |
|
|
465 |
void CScriptExecutor::Close()
|
|
466 |
/**
|
|
467 |
Cleanup last command, close script file, and delete all variables and labels from lists.
|
|
468 |
*/
|
|
469 |
{
|
|
470 |
CleanupLastCommand();
|
|
471 |
|
|
472 |
if (iLoopCommand!=NULL)
|
|
473 |
iLoopCommand->Loop(EFalse);
|
|
474 |
|
|
475 |
PctCancelAndClose();
|
|
476 |
CloseScript();
|
|
477 |
|
|
478 |
if (iVarMan!=NULL)
|
|
479 |
iVarMan->DeleteAll();
|
|
480 |
if (iLabelMan!=NULL)
|
|
481 |
iLabelMan->DeleteAll();
|
|
482 |
}
|
|
483 |
|
|
484 |
void CScriptExecutor::SetRetransmittedLoginTimeout(TReal& aRetransmitLoginTimeOut)
|
|
485 |
/**
|
|
486 |
Remember the timeout used on the wait statement that is currently executing
|
|
487 |
|
|
488 |
@param aRetransmitLoginTimeOut is passed from CWaitCommand.
|
|
489 |
*/
|
|
490 |
{
|
|
491 |
iRetransmitLoginTimeOut = aRetransmitLoginTimeOut;
|
|
492 |
if(iServerRetransmitLoginPromptStatus == EFirstWaitCommand)
|
|
493 |
{
|
|
494 |
// This is the first time we are going to wait for anything
|
|
495 |
// If we wait too long, the TCP/IP stack will time out so better not
|
|
496 |
// wait more than say 30 seconds the first time around
|
|
497 |
if(aRetransmitLoginTimeOut > 30)
|
|
498 |
aRetransmitLoginTimeOut = 30;
|
|
499 |
}
|
|
500 |
}
|
|
501 |
|
|
502 |
TInt CScriptExecutor::WritePct(const TDesC8& aBuffer)
|
|
503 |
/**
|
|
504 |
CScriptIO calls to write incoming data to PCT. Convert the 8 bit data to
|
|
505 |
default character set and pass up to the dialog server.
|
|
506 |
|
|
507 |
@param aBuffer a reference to buffer to be written.
|
|
508 |
@return error code from WritePct() or leave code if ConvertFromDefaultL() leaves.
|
|
509 |
*/
|
|
510 |
{
|
|
511 |
__ASSERT_DEBUG(aBuffer.Length()<=KRxBufferSize, User::Invariant());
|
|
512 |
TBuf<KRxBufferSize> convertedBuf;
|
|
513 |
TRAPD(ret, iCharConv->ConvertFromDefaultL(aBuffer,convertedBuf));
|
|
514 |
if (ret == KErrNone)
|
|
515 |
{
|
|
516 |
return iScript->WritePct(convertedBuf);
|
|
517 |
}
|
|
518 |
else
|
|
519 |
{
|
|
520 |
return ret;
|
|
521 |
}
|
|
522 |
}
|
|
523 |
|
|
524 |
void CScriptExecutor::SetReadPctBuffer()
|
|
525 |
/**
|
|
526 |
This is for the test dialog server only because we can't type in the value.
|
|
527 |
*/
|
|
528 |
{
|
|
529 |
iReadBuffer.SetLength(0);
|
|
530 |
iReadReq++;
|
|
531 |
if (iReadReq==1)
|
|
532 |
iReadBuffer.Copy(iLoginName.Left(Min(iLoginName.Length(),3)));
|
|
533 |
else if (iReadReq==2)
|
|
534 |
{
|
|
535 |
if (iLoginName.Length()>3)
|
|
536 |
iReadBuffer.Copy(iLoginName.Right(iLoginName.Length()-3));
|
|
537 |
iReadBuffer.Append('.');
|
|
538 |
}
|
|
539 |
else if (iReadReq==3)
|
|
540 |
iReadBuffer.Copy(iLoginPass.Left(Min(iLoginPass.Length(),3)));
|
|
541 |
else if (iReadReq==4)
|
|
542 |
{
|
|
543 |
if (iLoginPass.Length()>3)
|
|
544 |
iReadBuffer.Copy(iLoginPass.Right(iLoginPass.Length()-3));
|
|
545 |
iReadBuffer.Append('.');
|
|
546 |
}
|
|
547 |
else if (iReadReq==5)
|
|
548 |
iReadBuffer.Copy(KPPPProtocolName);
|
|
549 |
else
|
|
550 |
iReadBuffer.Zero();
|
|
551 |
}
|
|
552 |
|
|
553 |
void CScriptExecutor::ReadPct()
|
|
554 |
/**
|
|
555 |
Read PCT.
|
|
556 |
*/
|
|
557 |
{
|
|
558 |
SetReadPctBuffer();
|
|
559 |
iScript->ReadPct(iReadBuffer);
|
|
560 |
iScriptIO->ReadEcho();
|
|
561 |
iReadFromPctPending=ETrue;
|
|
562 |
}
|
|
563 |
|
|
564 |
void CScriptExecutor::ReadPctComplete(TInt aStatus)
|
|
565 |
/**
|
|
566 |
Data recived from PCT to be written to port. For unicode - need to know the
|
|
567 |
character set it should be sent in and convert to this from UNICODE (or whatever
|
|
568 |
PCT uses). Pass to the Script IO as 8 bit.
|
|
569 |
|
|
570 |
@param aStatus passed from caller.
|
|
571 |
*/
|
|
572 |
{
|
|
573 |
__ASSERT_ALWAYS(iReadFromPctPending, NetDialPanic(EIllegalReadPctComplete));
|
|
574 |
|
|
575 |
if (aStatus==KErrCancel) // means that NetDial has called Cancel() or ClosePct() while read request outstanding
|
|
576 |
{
|
|
577 |
iReadFromPctPending=EFalse;
|
|
578 |
return;
|
|
579 |
}
|
|
580 |
|
|
581 |
if (aStatus!=KErrNone) // something other than KErrCancel
|
|
582 |
{
|
|
583 |
iScriptIO->ReadEchoCancel();
|
|
584 |
iReadFromPctPending=EFalse;
|
|
585 |
CompletedScript(aStatus);
|
|
586 |
return;
|
|
587 |
}
|
|
588 |
|
|
589 |
HBufC8* buf=NULL;
|
|
590 |
TRAPD(ret,buf=iCharConv->ConvertL(iReadBuffer,iReadCommand->CharSet()));
|
|
591 |
if(ret!=KErrNone)
|
|
592 |
{
|
|
593 |
iScriptIO->ReadEchoCancel();
|
|
594 |
iReadFromPctPending=EFalse;
|
|
595 |
CompletedScript(ret);
|
|
596 |
return;
|
|
597 |
}
|
|
598 |
TPtr8 eightBitBuf(buf->Des());
|
|
599 |
#ifdef __FLOG_ACTIVE
|
|
600 |
_LIT(logString,"Script:\tRead %S from PCT");
|
|
601 |
TBuf16<KLogBufferSize> temp;
|
|
602 |
temp.Copy(eightBitBuf.Left(Min(eightBitBuf.Length(),KLogBufferSize)));
|
|
603 |
__FLOG_STATIC1(KNetDialLogFolder(),KNetDialLogFile(),TRefByValue<const TDesC>(logString()),&temp);
|
|
604 |
#endif
|
|
605 |
TInt end=iReadBuffer.Locate(KCarriageReturn);
|
|
606 |
TInt spaceInBuffer=iDataToWrite.MaxLength()-iDataToWrite.Length();
|
|
607 |
|
|
608 |
if (end<0)
|
|
609 |
iDataToWrite.Append(eightBitBuf.Left(Min(spaceInBuffer,eightBitBuf.Length())));
|
|
610 |
else
|
|
611 |
iDataToWrite.Append(eightBitBuf.Left(Min(spaceInBuffer,end+1)));
|
|
612 |
|
|
613 |
if (!iScriptIO->WritePending())
|
|
614 |
{
|
|
615 |
iScriptIO->Write(iDataToWrite);
|
|
616 |
iDataToWrite.SetLength(0); // clear buffer so we know it's been sent
|
|
617 |
}
|
|
618 |
|
|
619 |
if (end<0)
|
|
620 |
{
|
|
621 |
SetReadPctBuffer();
|
|
622 |
iScript->ReadPct(iReadBuffer);
|
|
623 |
}
|
|
624 |
else
|
|
625 |
{
|
|
626 |
iScriptIO->ReadEchoCancel();
|
|
627 |
iReadFromPctPending=EFalse;
|
|
628 |
}
|
|
629 |
|
|
630 |
delete buf;
|
|
631 |
}
|
|
632 |
|
|
633 |
void CScriptExecutor::DestroyPctNotificationReceived(TInt aStatus)
|
|
634 |
/**
|
|
635 |
PCT destroyed. Assume KErrNone means destroyed by user / someone else and
|
|
636 |
otherwise we destroyed it.
|
|
637 |
|
|
638 |
@param aStatus is passed from caller.
|
|
639 |
*/
|
|
640 |
{
|
|
641 |
if (aStatus==KErrNone) // user cancelled
|
|
642 |
{
|
|
643 |
iScriptIO->Cancel();
|
|
644 |
iScript->CancelDialogServer(); // cancels any outstanding reads
|
|
645 |
CompletedScript(KErrCancel); // this will close the PCT
|
|
646 |
}
|
|
647 |
else
|
|
648 |
iScript->ClosePct(); // NetDial is in charge of closing the PCT whatever happens
|
|
649 |
|
|
650 |
}
|
|
651 |
|
|
652 |
void CScriptExecutor::PctCancelAndClose()
|
|
653 |
/**
|
|
654 |
Cancel any outstanding requests and cancel the active object waiting on the
|
|
655 |
destroy notification) and close the pct
|
|
656 |
*/
|
|
657 |
{
|
|
658 |
iScript->CancelDialogServer();
|
|
659 |
iScript->ClosePct();
|
|
660 |
}
|
|
661 |
|
|
662 |
void CScriptExecutor::SetVariableL(const TDesC& aName, const TDesC& aContent)
|
|
663 |
/**
|
|
664 |
Add variable with name aName and content aContent to list
|
|
665 |
|
|
666 |
@param aName a reference to variable name.
|
|
667 |
@param aContent a reference to content.
|
|
668 |
*/
|
|
669 |
{
|
|
670 |
iVarMan->AddVariableL(aName,aContent);
|
|
671 |
}
|
|
672 |
|
|
673 |
void CScriptExecutor::ConfigureCommPort(TRequestStatus& aStatus, const TCommConfig& aConfiguration)
|
|
674 |
/**
|
|
675 |
Configure COMM port.
|
|
676 |
|
|
677 |
@param aConfiguration a reference to confiquration
|
|
678 |
@return error code from ConfigurePort().
|
|
679 |
*/
|
|
680 |
{
|
|
681 |
iScriptIO->ConfigurePort(aStatus, aConfiguration);
|
|
682 |
}
|
|
683 |
|
|
684 |
void CScriptExecutor::DropSignals(TRequestStatus& aStatus)
|
|
685 |
/**
|
|
686 |
Drop signals on COMM port.
|
|
687 |
*/
|
|
688 |
{
|
|
689 |
iScriptIO->DropSignals(aStatus);
|
|
690 |
}
|
|
691 |
|
|
692 |
void CScriptExecutor::CancelConfigureCommPort()
|
|
693 |
/**
|
|
694 |
Cancel Configure COMM port.
|
|
695 |
*/
|
|
696 |
{
|
|
697 |
iScriptIO->CancelConfigurePort();
|
|
698 |
}
|
|
699 |
|
|
700 |
void CScriptExecutor::DropDTR(TRequestStatus* aStatusPtr)
|
|
701 |
/**
|
|
702 |
Drop DTR.
|
|
703 |
*/
|
|
704 |
{
|
|
705 |
iScriptIO->DropDTR(aStatusPtr);
|
|
706 |
}
|
|
707 |
|
|
708 |
void CScriptExecutor::CreateChannel(TRequestStatus& aStatus)
|
|
709 |
{
|
|
710 |
ASSERT(iScriptIO);
|
|
711 |
iScriptIO->CreateChannel(aStatus);
|
|
712 |
}
|
|
713 |
|
|
714 |
void CScriptExecutor::CancelCreateChannel()
|
|
715 |
{
|
|
716 |
ASSERT(iScriptIO);
|
|
717 |
iScriptIO->CancelCreateChannel();
|
|
718 |
}
|
|
719 |
|
|
720 |
void CScriptExecutor::ShutdownChannel(TRequestStatus& aStatus)
|
|
721 |
{
|
|
722 |
ASSERT(iScriptIO);
|
|
723 |
iScriptIO->ShutdownChannel(aStatus);
|
|
724 |
}
|
|
725 |
|
|
726 |
TInt CScriptExecutor::GetExcessData(TDes8& aBuffer)
|
|
727 |
/**
|
|
728 |
Get excess data.
|
|
729 |
|
|
730 |
@param aBuffer a reference to excess data.
|
|
731 |
*/
|
|
732 |
{
|
|
733 |
return iScriptIO->GetExcessData(aBuffer);
|
|
734 |
}
|
|
735 |
|
|
736 |
void CScriptExecutor::ConvertScriptError(TInt& aError) const
|
|
737 |
/**
|
|
738 |
Convert internal errors to KErrExitScriptError.
|
|
739 |
|
|
740 |
@param a reference to error code. New value is passed back by using it.
|
|
741 |
*/
|
|
742 |
{
|
|
743 |
if(aError<KNetdialInternalErrorBase)
|
|
744 |
aError=KErrExitScriptError;
|
|
745 |
}
|
|
746 |
|
|
747 |
void CScriptExecutor::CleanupLastCommand()
|
|
748 |
/**
|
|
749 |
Cleanup last command.
|
|
750 |
*/
|
|
751 |
{
|
|
752 |
if(iLastCommand!=NULL)
|
|
753 |
{
|
|
754 |
iLastCommand->Cleanup();
|
|
755 |
iLastCommand=NULL;
|
|
756 |
}
|
|
757 |
}
|
|
758 |
|
|
759 |
void CScriptExecutor::RunL()
|
|
760 |
/**
|
|
761 |
Complete script operation.
|
|
762 |
*/
|
|
763 |
{
|
|
764 |
iScript->ScriptOperationComplete(iStatus.Int());
|
|
765 |
}
|
|
766 |
|