RDK Documentation (Open Sourced RDK Components)
XrdkCentralComRFC.cpp
1 /*
2  * If not stated otherwise in this file or this component's Licenses.txt file the
3  * following copyright and licenses apply:
4  *
5  * Copyright 2018 RDK Management
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18 */
19 
20 #include "XrdkCentralComRFC.h"
21 #include "hostIf_main.h"
22 #include "hostIf_utils.h"
23 
24 using namespace std;
25 
26 const char *TR181_RFC_STORE_KEY = "TR181_STORE_FILENAME";
27 const char *RFC_PROPERTIES_FILE = "/etc/rfc.properties";
28 
29 XRFCStorage::XRFCStorage()
30 {
31  m_storageLoaded = false;
32 }
33 
34 void XRFCStorage::clearAll()
35 {
36  m_storage.clear();
37 }
38 
39 int XRFCStorage::getValue(HOSTIF_MsgData_t *stMsgData)
40 {
41  if (!init()) {
42  return NOK;
43  }
44 
45  int ret = NOK;
46 
47  const std::string &paramValue = m_storage.value(stMsgData->paramName);
48  ret = paramValue.empty() ? NOK : OK;
49 
50  // FIXME:: problem with tr181Set, it expects OK and will call set on a value if the
51  // get return ok. This override should be removed one tr181Set is fixed.
52  ret = OK;
53 
54  // if there is no value no need to unnecessary work, just return failure
55  if (ret == NOK) {
56  //stMsgData->faultCode = fcInvalidParameterName;
57  return ret;
58  }
59 
60  // FIXME:: we don't set type of param. It should have happen before the profiles.
61  // everyone should follow data-model.xml and no one should be expected to set it
62  // or overrirde.
63 
64  putValue(stMsgData, paramValue);
65 
66  return ret;
67 }
68 
69 int XRFCStorage::setValue(HOSTIF_MsgData_t *stMsgData)
70 {
71  if (!init()) {
72  return NOK;
73  }
74 
75  // FixMe:: validate
76  const string &valueString = getStringValue(stMsgData);
77 
78  const string &oldValue = m_storage.value(stMsgData->paramName);
79 
80  // if nothing changed, don't do anything
81  if (oldValue == valueString) {
82  return OK;
83  }
84 
85  // store
86  int ret = NOK;
87  if ((m_storage.setValue(stMsgData->paramName, valueString))) {
88  ret = OK;
89  }
90  return ret;
91 }
92 
93 string XRFCStorage::getRawValue(const string &key)
94 {
95  if (!init()) {
96  return "";
97  }
98 
99  return m_storage.value(key);
100 }
101 
102 bool XRFCStorage::setRawValue(const string &key, const string &value)
103 {
104  if (!init()) {
105  return false;
106  }
107 
108  return m_storage.setValue(key, value);
109 }
110 
111 
112 bool XRFCStorage::init()
113 {
114  if (m_storageLoaded) {
115  return true;
116  }
117 
118  // get the file path
119  IniFile file;
120  file.load(RFC_PROPERTIES_FILE);
121  m_storageFile = file.value(TR181_RFC_STORE_KEY);
122 
123  if (m_storageFile.empty()) {
124  RDK_LOG(RDK_LOG_INFO,LOG_TR69HOSTIF, "Looks like %s doesn't contain the key %s\n", __FUNCTION__, __LINE__, RFC_PROPERTIES_FILE, TR181_RFC_STORE_KEY);
125  return false;
126  }
127 
128  m_storage.load(m_storageFile);
129 
130  m_storageLoaded = true;
131 
132  return true;
133 }
_HostIf_MsgData_t
Definition: hostIf_tr69ReqHandler.h:170
hostIf_main.h
hostIf_main API.
RDK_LOG
#define RDK_LOG
Definition: rdk_debug.h:258
_HostIf_MsgData_t::paramName
char paramName[(4 *1024)]
Definition: hostIf_tr69ReqHandler.h:171
IniFile
Definition: IniFile.h:26