1 /* 2 * Copyright (C) 2014 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 /*================================================================================================== 18 19 Source Name: dmConfigItem.cc 20 21 General Description: Implementation of the DMConfigItem class 22 23 ==================================================================================================*/ 24 25 #include "dmConfigItem.h" 26 #include "dm_uri_utils.h" 27 #include "dmdefs.h" 28 #include "dmtoken.h" 29 30 DMConfigItem::DMConfigItem(CPCHAR szPath) 31 { 32 m_strPath = szPath; 33 } 34 35 void DMConfigItem::AttachProperty( DMString & strConfig, char cDelim, CPCHAR szProperty ) 36 { 37 if ( !strConfig[0] == 0 ) 38 { 39 char s[2] = {cDelim,0}; 40 strConfig += s; 41 } 42 43 strConfig += szProperty; 44 } 45 46 47 SYNCML_DM_RET_STATUS_T DMConfigItem::Serialize( DMFileHandler& dmf) 48 { 49 if ( dmf.write( "[", 1 ) != SYNCML_DM_SUCCESS || 50 dmf.write( m_strPath.c_str(), m_strPath.length())!= SYNCML_DM_SUCCESS || 51 dmf.write( "]\n", 2 ) != SYNCML_DM_SUCCESS ) 52 return SYNCML_DM_IO_FAILURE; 53 return SYNCML_DM_SUCCESS; 54 55 } 56 57 void DMConfigItem::CreateProperty( const DMVector<DmtPrincipal> aPrincipals, 58 CPCHAR szKey, 59 const DMMap<DMString, INT32>& aDict, 60 DMString & strProperty ) 61 { 62 63 if ( aPrincipals.size() == 0 ) 64 return; 65 66 DMString strPrincipals = ""; 67 for (INT32 index=0; index<aPrincipals.size(); index++) 68 { 69 const DmtPrincipal& oPrincipal = aPrincipals[index]; 70 INT32 nID = aDict.get(oPrincipal.getName()); 71 char szNumBuffer[20] = ""; 72 sprintf( szNumBuffer, "%d", nID ); 73 74 AttachProperty( strPrincipals, '+', szNumBuffer ); 75 } 76 77 strProperty = szKey; 78 strProperty += strPrincipals; 79 80 } 81 82 83 SYNCML_DM_RET_STATUS_T 84 DMConfigItem::Set(CPCHAR szPath) 85 { 86 if ( szPath == NULL ) 87 return SYNCML_DM_FAIL; 88 89 m_strPath = szPath; 90 return SYNCML_DM_SUCCESS; 91 92 } 93