00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00035 #include "secureclientandserver.h"
00036 #include "secureserver.h"
00037
00043 CSecureServerSubSession::CSecureServerSubSession(CSecureServerSession* aSession) : iSession(aSession)
00044 {
00045 }
00046
00051 void CSecureServerSubSession::SetFromStringL(const RMessage2& aMessage)
00052 {
00053 TInt deslen = aMessage.GetDesLength(0);
00054 RBuf buffer;
00055
00056 buffer.CreateL(deslen);
00057 buffer.CleanupClosePushL();
00058
00059
00060 aMessage.ReadL(0,buffer,0);
00061
00062 if (buffer.Length() == 0)
00063 {
00064 User::Leave(ENonNumericString);
00065 }
00066 TLex16 lexer;
00067 lexer.Assign(buffer);
00068 while (!lexer.Eos())
00069 {
00070 TChar thechar;
00071 thechar = lexer.Peek();
00072
00073 if (!thechar.IsDigit())
00074 {
00075 User::Leave(ENonNumericString);
00076 }
00077 lexer.Inc();
00078 }
00079 lexer.Assign(buffer);
00080 if (lexer.Val(iCount))
00081 {
00082 User::Leave(ENonNumericString);
00083 }
00084 CleanupStack::PopAndDestroy();
00085 }
00086
00090 void CSecureServerSubSession::Increase()
00091 {
00092 iCount ++;
00093 }
00094
00100 void CSecureServerSubSession::IncreaseBy(const RMessage2& aMessage)
00101 {
00102 iCount += aMessage.Int0();
00103 }
00104
00108 void CSecureServerSubSession::Decrease()
00109 {
00110 iCount --;
00111 }
00112
00118 void CSecureServerSubSession::DecreaseBy(const RMessage2& aMessage)
00119 {
00120 iCount -= aMessage.Int0();
00121 }
00122
00127 void CSecureServerSubSession::Reset()
00128 {
00129 iCount = 0;
00130 }
00131
00136 void CSecureServerSubSession::CounterValueL(const RMessage2& aMessage)
00137 {
00138
00139 TPckgBuf<TInt> p(iCount);
00140 aMessage.WriteL(0,p);
00141 }
00142
00155 void CSecureServerSubSession::SaveCounterValueL()
00156 {
00157 RFs fs;
00158 User::LeaveIfError(fs.Connect());
00159 _LIT(KFileName,"counter.dat");
00160 User::LeaveIfError(fs.CreatePrivatePath(RFs::GetSystemDrive()));
00161 User::LeaveIfError(fs.SetSessionToPrivate(RFs::GetSystemDrive()));
00162 TFileName thePath;
00163 User::LeaveIfError(fs.PrivatePath(thePath));
00164 TInt err=fs.MkDir(thePath);
00165 if (err!=KErrAlreadyExists)
00166 {
00167 User::LeaveIfError(err);
00168 }
00169 thePath.Append(KFileName);
00170 RFile file;
00171
00172 TBuf8<20> counterVal;
00173 counterVal.FillZ();
00174
00175 counterVal.AppendNum(iCount);
00176 User::LeaveIfError(file.Replace(fs,thePath,EFileWrite));
00177 User::LeaveIfError(file.Write(counterVal));
00178 User::LeaveIfError(file.Flush());
00179
00180 file.Close();
00181 fs.Close();
00182 }
00183
00188 void CSecureServerSubSession::SetCounterValueFromFileL()
00189 {
00190 RFs fs;
00191 User::LeaveIfError(fs.Connect());
00192 _LIT(KFileName,"counter.dat");
00193 User::LeaveIfError(fs.CreatePrivatePath(RFs::GetSystemDrive()));
00194 User::LeaveIfError(fs.SetSessionToPrivate(RFs::GetSystemDrive()));
00195 TFileName thePath;
00196 User::LeaveIfError(fs.PrivatePath(thePath));
00197 TInt err=fs.MkDir(thePath);
00198 if (err!=KErrAlreadyExists)
00199 {
00200 User::LeaveIfError(err);
00201 }
00202 thePath.Append(KFileName);
00203 RFile file;
00204
00205 TBuf8<20> readVal;
00206 User::LeaveIfError(file.Open(fs,thePath,EFileRead));
00207
00208 User::LeaveIfError(file.Read(readVal));
00209 file.Close();
00210
00211 TLex8 lex(readVal);
00212 lex.Val(iCount);
00213
00214 fs.Close();
00215 }