RDK Documentation (Open Sourced RDK Components)
webconfig_utils.cpp
Go to the documentation of this file.
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 2016 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  * @file webconfig_utils.cpp
21  *
22  * @description This file describes the utility functions for webconfig module
23  *
24  */
25 
26 #include <webconfig_utils.h>
27 
28 int getKeyValue(char *key, char *value)
29 {
30  FILE *fp = fopen(DEV_DETAILS_FILE, "r");
31  int i,j;
32  int rval = ERR;
33  if (NULL != fp)
34  {
35  char appendkey[] = "=";
36  char str[512] = {'\0'};
37  char searchkey[64] = {'\0'};
38 
39  strncpy(searchkey, key, strlen(key));
40  strcat(searchkey, appendkey);
41  while(fscanf(fp,"%s", str) != EOF)
42  {
43  char *searchVal = NULL;
44  if(searchVal = strstr(str, searchkey))
45  {
46  searchVal = searchVal + strlen(searchkey);
47  strncpy(value, searchVal, (strlen(str) - strlen(searchkey))+1);
48  rval = SUCCESS;
49  }
50  }
51  fclose(fp);
52  for (i=j=0; i<strlen(value); i++)
53  {
54  if (value[i] != ':')
55  value[j++] = value[i];
56  }
57  value[j] = '\0';
58 
59  for(i=0;i<=strlen(value);i++){
60  if(value[i]>=65&&value[i]<=90)
61  value[i]=value[i]+32;
62  }
63  }
64  if((strlen(value))<1)/*It means only key is populated in the file & value is yet to be*/
65  {
66  rval = ERR;
67  }
68  RDK_LOG(RDK_LOG_INFO, LOG_TR69HOSTIF,"webconfig_lite: [%s] %d key = %s, value = %s rval= %d\n\n", __FUNCTION__, __LINE__, key, value, rval);
69  return rval;
70 }
RDK_LOG
#define RDK_LOG
Definition: rdk_debug.h:258
webconfig_utils.h