00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00022 #include "secureclientandserver.h"
00023 #include "secureserver.h"
00024
00030 CSecureServerSubSession::CSecureServerSubSession(CSecureServerSession* aSession) : iSession(aSession)
00031 {
00032 }
00033
00038 void CSecureServerSubSession::SetFromStringL(const RMessage2& aMessage)
00039 {
00040 TInt deslen = aMessage.GetDesLength(0);
00041 RBuf buffer;
00042
00043 buffer.CreateL(deslen);
00044 buffer.CleanupClosePushL();
00045
00046
00047 aMessage.ReadL(0,buffer,0);
00048
00049 if (buffer.Length() == 0)
00050 {
00051 User::Leave(ENonNumericString);
00052 }
00053 TLex16 lexer;
00054 lexer.Assign(buffer);
00055 while (!lexer.Eos())
00056 {
00057 TChar thechar;
00058 thechar = lexer.Peek();
00059
00060 if (!thechar.IsDigit())
00061 {
00062 User::Leave(ENonNumericString);
00063 }
00064 lexer.Inc();
00065 }
00066 lexer.Assign(buffer);
00067 if (lexer.Val(iCount))
00068 {
00069 User::Leave(ENonNumericString);
00070 }
00071 CleanupStack::PopAndDestroy();
00072 }
00073
00077 void CSecureServerSubSession::Increase()
00078 {
00079 iCount ++;
00080 }
00081
00087 void CSecureServerSubSession::IncreaseBy(const RMessage2& aMessage)
00088 {
00089 iCount += aMessage.Int0();
00090 }
00091
00095 void CSecureServerSubSession::Decrease()
00096 {
00097 iCount --;
00098 }
00099
00105 void CSecureServerSubSession::DecreaseBy(const RMessage2& aMessage)
00106 {
00107 iCount -= aMessage.Int0();
00108 }
00109
00114 void CSecureServerSubSession::Reset()
00115 {
00116 iCount = 0;
00117 }
00118
00123 void CSecureServerSubSession::CounterValueL(const RMessage2& aMessage)
00124 {
00125
00126 TPckgBuf<TInt> p(iCount);
00127 aMessage.WriteL(0,p);
00128 }
00129
00142 void CSecureServerSubSession::SaveCounterValueL()
00143 {
00144 RFs fs;
00145 User::LeaveIfError(fs.Connect());
00146 _LIT(KFileName,"counter.dat");
00147 User::LeaveIfError(fs.CreatePrivatePath(RFs::GetSystemDrive()));
00148 User::LeaveIfError(fs.SetSessionToPrivate(RFs::GetSystemDrive()));
00149 TFileName thePath;
00150 User::LeaveIfError(fs.PrivatePath(thePath));
00151 TInt err=fs.MkDir(thePath);
00152 if (err!=KErrAlreadyExists)
00153 {
00154 User::LeaveIfError(err);
00155 }
00156 thePath.Append(KFileName);
00157 RFile file;
00158
00159 TBuf8<20> counterVal;
00160 counterVal.FillZ();
00161
00162 counterVal.AppendNum(iCount);
00163 User::LeaveIfError(file.Replace(fs,thePath,EFileWrite));
00164 User::LeaveIfError(file.Write(counterVal));
00165 User::LeaveIfError(file.Flush());
00166
00167 file.Close();
00168 fs.Close();
00169 }
00170
00175 void CSecureServerSubSession::SetCounterValueFromFileL()
00176 {
00177 RFs fs;
00178 User::LeaveIfError(fs.Connect());
00179 _LIT(KFileName,"counter.dat");
00180 User::LeaveIfError(fs.CreatePrivatePath(RFs::GetSystemDrive()));
00181 User::LeaveIfError(fs.SetSessionToPrivate(RFs::GetSystemDrive()));
00182 TFileName thePath;
00183 User::LeaveIfError(fs.PrivatePath(thePath));
00184 TInt err=fs.MkDir(thePath);
00185 if (err!=KErrAlreadyExists)
00186 {
00187 User::LeaveIfError(err);
00188 }
00189 thePath.Append(KFileName);
00190 RFile file;
00191
00192 TBuf8<20> readVal;
00193 User::LeaveIfError(file.Open(fs,thePath,EFileRead));
00194
00195 User::LeaveIfError(file.Read(readVal));
00196 file.Close();
00197
00198 TLex8 lex(readVal);
00199 lex.Val(iCount);
00200
00201 fs.Close();
00202 }