553 } |
516 } |
554 CleanupStack::PopAndDestroy(); // policyData |
517 CleanupStack::PopAndDestroy(); // policyData |
555 |
518 |
556 aMessage.Complete(KErrNone); |
519 aMessage.Complete(KErrNone); |
557 } |
520 } |
558 |
|
559 void CVpnApiServant::CreateProvisionServerL( const RMessage2& aMessage ) |
|
560 { |
|
561 TAgileProvisionApiServerSettings* serverCreate = new (ELeave) TAgileProvisionApiServerSettings(); |
|
562 CleanupStack::PushL(serverCreate); |
|
563 TPckg<TAgileProvisionApiServerSettings> pckgServerCreate(*serverCreate); |
|
564 aMessage.ReadL(0, pckgServerCreate); |
|
565 TAgileProvisionServerLocals* serverAccountLocalData = new (ELeave) TAgileProvisionServerLocals(); |
|
566 CleanupStack::PushL(serverAccountLocalData); |
|
567 serverAccountLocalData->iSelection = serverCreate->iSelection; |
|
568 serverAccountLocalData->iServerAddress.Copy(serverCreate->iServerUrl); |
|
569 serverAccountLocalData->iServerNameLocal.Copy(serverCreate->iServerNameLocal); |
|
570 |
|
571 TFileName serverFilePath; |
|
572 User::LeaveIfError(iFs.PrivatePath(serverFilePath)); |
|
573 serverFilePath.Append(KProvisionServerSettings); |
|
574 |
|
575 /* Check if file allready exists and copy policy and vpn iap id to a new file */ |
|
576 TFileName policyFileName; |
|
577 TUint32 agileProvisionAPId=0; |
|
578 |
|
579 if ( iFileUtil.FileExists(serverFilePath) ) |
|
580 { |
|
581 HBufC8* fileData=iFileUtil.LoadFileDataL(serverFilePath); |
|
582 CleanupStack::PushL(fileData); |
|
583 |
|
584 TPtrC8 restOfData = fileData->Des(); |
|
585 |
|
586 TInt bofInt; |
|
587 TInt line=1; |
|
588 while ( (bofInt=restOfData.Find(KCRLF)) != KErrNotFound && line < KPolicyFileLine ) |
|
589 { |
|
590 restOfData.Set(restOfData.Mid(bofInt + KCRLF().Length())); |
|
591 line++; |
|
592 } |
|
593 TInt iapIdStart=restOfData.Find(KCRLF); |
|
594 HBufC16* iapIdBuf; |
|
595 |
|
596 if ( iapIdStart!=KErrNotFound ) |
|
597 { |
|
598 TPtrC8 iapIdPtr=restOfData.Mid(iapIdStart + KCRLF().Length(),restOfData.Length()-KCRLF().Length()-iapIdStart); |
|
599 iapIdBuf=iFileUtil.To16BitL(iapIdPtr); |
|
600 CleanupStack::PushL(iapIdBuf); |
|
601 TLex iapIdConverter(*iapIdBuf); |
|
602 iapIdConverter.Val(agileProvisionAPId,EDecimal); |
|
603 CleanupStack::PopAndDestroy(iapIdBuf); |
|
604 } |
|
605 |
|
606 if ( agileProvisionAPId >0) |
|
607 { |
|
608 restOfData.Set(restOfData.Mid(0,iapIdStart)); |
|
609 HBufC16* policyFileNameBuf = iFileUtil.To16BitL(restOfData); |
|
610 policyFileName = *policyFileNameBuf; |
|
611 delete policyFileNameBuf; |
|
612 } |
|
613 CleanupStack::PopAndDestroy(fileData); |
|
614 } |
|
615 /* end of saving old values */ |
|
616 |
|
617 //IAP data Max value 255 |
|
618 TBuf<10> iapIdStr; |
|
619 TBuf<10> iapModeStr; |
|
620 TBuf<10> iapAgileIdStr; |
|
621 |
|
622 iapIdStr.Num(serverAccountLocalData->iSelection.iId); |
|
623 iapModeStr.Num(serverAccountLocalData->iSelection.iResult); |
|
624 HBufC* serverSettingsDataBuf; |
|
625 if ( agileProvisionAPId >0 ) |
|
626 { |
|
627 iapAgileIdStr.Num(agileProvisionAPId); |
|
628 |
|
629 serverSettingsDataBuf = HBufC::NewL(serverAccountLocalData->iServerNameLocal.Length() + serverAccountLocalData->iServerAddress.Length() + |
|
630 iapIdStr.Length() + iapModeStr.Length() + policyFileName.Length() + iapAgileIdStr.Length() + 5*(KCRLF().Length()) ); |
|
631 } |
|
632 else |
|
633 { |
|
634 serverSettingsDataBuf = HBufC::NewL(serverAccountLocalData->iServerNameLocal.Length() + serverAccountLocalData->iServerAddress.Length() + |
|
635 iapIdStr.Length() + iapModeStr.Length() + 3*(KCRLF().Length()) ); |
|
636 } |
|
637 CleanupStack::PushL(serverSettingsDataBuf); |
|
638 TPtr tPtr(serverSettingsDataBuf->Des()); |
|
639 tPtr.Copy(serverAccountLocalData->iServerAddress); |
|
640 _LIT(KCRLF, "\r\n"); |
|
641 tPtr.Append(KCRLF); |
|
642 tPtr.Append(serverAccountLocalData->iServerNameLocal); |
|
643 tPtr.Append(KCRLF); |
|
644 tPtr.Append(iapIdStr); |
|
645 tPtr.Append(KCRLF); |
|
646 tPtr.Append(iapModeStr); |
|
647 if ( agileProvisionAPId >0 ) |
|
648 { |
|
649 tPtr.Append(KCRLF); |
|
650 tPtr.Append(policyFileName); |
|
651 tPtr.Append(KCRLF); |
|
652 tPtr.Append(iapAgileIdStr); |
|
653 } |
|
654 |
|
655 iFileUtil.SaveFileDataL(serverFilePath,tPtr); |
|
656 CleanupStack::PopAndDestroy(3); |
|
657 aMessage.Complete(KErrNone); |
|
658 } |
|
659 |
|
660 void CVpnApiServant::ListProvisionServerL( const RMessage2& aMessage ) |
|
661 { |
|
662 _LIT8(KCRLF, "\r\n"); |
|
663 |
|
664 const TInt KEolLen = 2; |
|
665 |
|
666 TAgileProvisionApiServerListElem* serverList = new (ELeave) TAgileProvisionApiServerListElem(); |
|
667 CleanupStack::PushL(serverList); |
|
668 TPckg<TAgileProvisionApiServerListElem> serverPckg(*serverList); |
|
669 |
|
670 TFileName serverFilePath; |
|
671 User::LeaveIfError(iFs.PrivatePath(serverFilePath)); |
|
672 serverFilePath.Append(KProvisionServerSettings); |
|
673 |
|
674 HBufC8* fileData(NULL); |
|
675 |
|
676 if ( iFileUtil.FileExists(serverFilePath) ) |
|
677 { |
|
678 fileData=iFileUtil.LoadFileDataL(serverFilePath); |
|
679 CleanupStack::PushL(fileData); |
|
680 TInt endOfLine=fileData->Find(KCRLF); |
|
681 serverList->iServerUrl=fileData->Mid(0,endOfLine); |
|
682 |
|
683 TInt startOfLine(endOfLine+KEolLen); |
|
684 TPtrC8 nameData=fileData->Right(fileData->Length()-startOfLine); |
|
685 endOfLine=nameData.Find(KCRLF); |
|
686 HBufC16* serverName=iFileUtil.To16BitL(nameData.Left(endOfLine)); |
|
687 serverList->iServerNameLocal=*serverName; |
|
688 delete serverName; |
|
689 serverName = NULL; |
|
690 } |
|
691 |
|
692 aMessage.WriteL(0, serverPckg); |
|
693 if ( iFileUtil.FileExists(serverFilePath) ) |
|
694 CleanupStack::PopAndDestroy(fileData); |
|
695 |
|
696 CleanupStack::PopAndDestroy(serverList); |
|
697 aMessage.Complete(KErrNone); |
|
698 } |
|
699 |
|
700 void CVpnApiServant::GetProvisionServerDetailsL( const RMessage2& aMessage ) |
|
701 { |
|
702 |
|
703 TAgileProvisionApiServerSettings* serverList = new (ELeave) TAgileProvisionApiServerSettings(); |
|
704 CleanupStack::PushL(serverList); |
|
705 TPckg<TAgileProvisionApiServerSettings> serverPckg(*serverList); |
|
706 |
|
707 _LIT8(KCRLF, "\r\n"); |
|
708 |
|
709 TFileName serverFilePath; |
|
710 User::LeaveIfError(iFs.PrivatePath(serverFilePath)); |
|
711 serverFilePath.Append(KProvisionServerSettings); |
|
712 |
|
713 HBufC8* fileData(NULL); |
|
714 const TInt KEolLen = 2; |
|
715 TBool serverFileExist = EFalse; |
|
716 |
|
717 if ( iFileUtil.FileExists(serverFilePath) ) |
|
718 { |
|
719 fileData=iFileUtil.LoadFileDataL(serverFilePath); |
|
720 CleanupStack::PushL(fileData); |
|
721 TInt endOfLine=fileData->Find(KCRLF); |
|
722 serverList->iServerUrl=fileData->Mid(0,endOfLine); |
|
723 |
|
724 TInt startOfLine(endOfLine+2); |
|
725 TPtrC8 nameData=fileData->Right(fileData->Length()-startOfLine); |
|
726 endOfLine=nameData.Find(KCRLF); |
|
727 |
|
728 HBufC16* serverName=iFileUtil.To16BitL(nameData.Left(endOfLine)); |
|
729 serverList->iServerNameLocal=*serverName; |
|
730 delete serverName; |
|
731 serverName = NULL; |
|
732 |
|
733 startOfLine = endOfLine + KEolLen; |
|
734 TPtrC8 iapIdData=nameData.Right(nameData.Length()-startOfLine); |
|
735 endOfLine=iapIdData.Find(KCRLF); |
|
736 TLex8 iapIdConverter(iapIdData.Left(endOfLine)); |
|
737 TUint idInt; |
|
738 iapIdConverter.Val(idInt); |
|
739 serverList->iSelection.iId = idInt; |
|
740 |
|
741 startOfLine = endOfLine + KEolLen; |
|
742 TPtrC8 iapModeData=iapIdData.Right(iapIdData.Length()-startOfLine); |
|
743 TLex8 iapModeConverter; |
|
744 endOfLine=iapModeData.Find(KCRLF); |
|
745 if ( endOfLine==KErrNotFound ) |
|
746 iapModeConverter = iapModeData; |
|
747 else |
|
748 iapModeConverter = iapModeData.Left(endOfLine); |
|
749 |
|
750 iapModeConverter.Val(idInt); |
|
751 CMManager::TCmSettingSelectionMode selectionMode = (CMManager::TCmSettingSelectionMode) idInt; |
|
752 serverList->iSelection.iResult = selectionMode; |
|
753 serverFileExist = ETrue; |
|
754 } |
|
755 aMessage.WriteL(0, serverPckg); |
|
756 |
|
757 if ( serverFileExist ) |
|
758 CleanupStack::PopAndDestroy(fileData); |
|
759 |
|
760 CleanupStack::PopAndDestroy(serverList); |
|
761 |
|
762 aMessage.Complete(KErrNone); |
|
763 } |
|
764 |
|
765 void CVpnApiServant::SynchronizeVPNPolicyServerL( const RMessage2& aMessage ) |
|
766 { |
|
767 iPolicyImporter = CPolicyImporter::NewL(aMessage, *this, *iPolicyStore, iFs); |
|
768 |
|
769 //Asynchronous call |
|
770 iPolicyImporter->SynchronizeVpnPolicyServerL(); |
|
771 } |
|
772 |
|
773 void CVpnApiServant::DeleteVPNPolicyServerL( const RMessage2& aMessage ) |
|
774 { |
|
775 TFileName serverFilePath; |
|
776 User::LeaveIfError(iFs.PrivatePath(serverFilePath)); |
|
777 serverFilePath.Append(KProvisionServerSettings); |
|
778 iFileUtil.DeleteFileL(serverFilePath); |
|
779 aMessage.Complete(KErrNone); |
|
780 } |
|
781 |
|
782 void CVpnApiServant::CancelSynchronize( const RMessage2& aMessage ) |
|
783 { |
|
784 if (iPolicyImporter) |
|
785 { |
|
786 if ( iPolicyImporter->iAgileProvisionWs != NULL ) |
|
787 { |
|
788 CAgileProvisionWs* ws = iPolicyImporter->iAgileProvisionWs; |
|
789 ws->CancelGetPolicy(); |
|
790 } |
|
791 iPolicyImporter->Cancel(); |
|
792 delete iPolicyImporter; |
|
793 iPolicyImporter = NULL; |
|
794 } |
|
795 aMessage.Complete(KErrCancel); |
|
796 } |
|
797 |
|
798 void CVpnApiServant::GetVPNPolicyNameL( const RMessage2& aMessage ) |
|
799 { |
|
800 TAgileProvisionPolicy* policy = new (ELeave) TAgileProvisionPolicy(); |
|
801 CleanupStack::PushL(policy); |
|
802 TPckg<TAgileProvisionPolicy> serverPckg(*policy); |
|
803 |
|
804 _LIT8(KCRLF, "\r\n"); |
|
805 |
|
806 TFileName serverFilePath; |
|
807 User::LeaveIfError(iFs.PrivatePath(serverFilePath)); |
|
808 serverFilePath.Append(KProvisionServerSettings); |
|
809 |
|
810 HBufC8* fileData(NULL); |
|
811 |
|
812 const TInt KEolLen = 2; |
|
813 TBool serverFileExist = EFalse; |
|
814 |
|
815 if ( iFileUtil.FileExists(serverFilePath) ) |
|
816 { |
|
817 fileData=iFileUtil.LoadFileDataL(serverFilePath); |
|
818 CleanupStack::PushL(fileData); |
|
819 TInt endOfLine=fileData->Find(KCRLF); |
|
820 if (endOfLine<=0) |
|
821 User::Leave(KErrArgument); |
|
822 |
|
823 TInt startOfLine(endOfLine + KEolLen); |
|
824 TPtrC8 nameData=fileData->Right(fileData->Length()-startOfLine); |
|
825 endOfLine=nameData.Find(KCRLF); |
|
826 if (endOfLine<=0) |
|
827 User::Leave(KErrArgument); |
|
828 |
|
829 startOfLine = endOfLine + KEolLen; |
|
830 TPtrC8 iapIdData=nameData.Right(nameData.Length()-startOfLine); |
|
831 endOfLine=iapIdData.Find(KCRLF); |
|
832 if (endOfLine<=0) |
|
833 User::Leave(KErrArgument); |
|
834 |
|
835 startOfLine = endOfLine + KEolLen; |
|
836 TPtrC8 iapModeData=iapIdData.Right(iapIdData.Length()-startOfLine); |
|
837 endOfLine=iapModeData.Find(KCRLF); |
|
838 if (endOfLine<=0) |
|
839 User::Leave(KErrArgument); |
|
840 |
|
841 startOfLine = endOfLine + KEolLen; |
|
842 TPtrC8 policyData=iapModeData.Right(iapModeData.Length()-startOfLine); |
|
843 endOfLine=policyData.Find(KCRLF); |
|
844 if (endOfLine<=0) |
|
845 User::Leave(KErrArgument); |
|
846 |
|
847 HBufC16* policyName = iFileUtil.To16BitL(policyData.Left(endOfLine)); |
|
848 policy->iPolicyName = *policyName; |
|
849 delete policyName; |
|
850 policyName=NULL; |
|
851 serverFileExist = ETrue; |
|
852 } |
|
853 |
|
854 aMessage.WriteL(0, serverPckg); |
|
855 |
|
856 if ( serverFileExist ) |
|
857 CleanupStack::PopAndDestroy(fileData); |
|
858 |
|
859 CleanupStack::PopAndDestroy(policy); |
|
860 |
|
861 aMessage.Complete(KErrNone); |
|
862 } |
|