Skip to content

Commit 1d7b4dc

Browse files
Merge pull request #28 from guruchandru/webcfg_meta
webconfig metadata parsing and processing
2 parents 6702047 + a061eaa commit 1d7b4dc

File tree

11 files changed

+571
-12
lines changed

11 files changed

+571
-12
lines changed

src/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
# limitations under the License.
1414

1515
set(PROJ_WEBCFG webcfg)
16-
set(HEADERS webcfg.h webcfg_param.h webcfg_pack.h webcfg_multipart.h webcfg_auth.h webcfg_notify.h webcfg_generic.h webcfg_db.h webcfg_log.h webcfg_blob.h webcfg_event.h webcfg_aker.h)
17-
set(SOURCES webcfg_helpers.c webcfg.c webcfg_param.c webcfg_pack.c webcfg_multipart.c webcfg_auth.c webcfg_notify.c webcfg_db.c webcfg_generic.c webcfg_blob.c webcfg_event.c webcfg_client.c webcfg_aker.c)
16+
set(HEADERS webcfg.h webcfg_param.h webcfg_pack.h webcfg_multipart.h webcfg_auth.h webcfg_notify.h webcfg_generic.h webcfg_db.h webcfg_log.h webcfg_blob.h webcfg_event.h webcfg_aker.h webcfg_metadata.h)
17+
set(SOURCES webcfg_helpers.c webcfg.c webcfg_param.c webcfg_pack.c webcfg_multipart.c webcfg_auth.c webcfg_notify.c webcfg_db.c webcfg_generic.c webcfg_blob.c webcfg_event.c webcfg_client.c webcfg_aker.c webcfg_metadata.c)
1818

1919
add_library(${PROJ_WEBCFG} STATIC ${HEADERS} ${SOURCES})
2020
add_library(${PROJ_WEBCFG}.shared SHARED ${HEADERS} ${SOURCES})

src/webcfg.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include <base64.h>
3232
#include "webcfg_db.h"
3333
#include "webcfg_aker.h"
34+
#include "webcfg_metadata.h"
3435
/*----------------------------------------------------------------------------*/
3536
/* Macros */
3637
/*----------------------------------------------------------------------------*/
@@ -94,6 +95,8 @@ void *WebConfigMultipartTask(void *status)
9495
Status = (unsigned long)status;
9596

9697
//start webconfig notification thread.
98+
initWebcfgProperties(WEBCFG_PROPERTIES_FILE);
99+
97100
initWebConfigNotifyTask();
98101
initWebConfigClient();
99102
WebcfgInfo("initDB %s\n", WEBCFG_DB_FILE);
@@ -417,7 +420,7 @@ int testUtility()
417420
{
418421
ptr1_count = memchr(ptr_count+1, '\r', test_dataSize - (ptr_count - data_body));
419422
temp = strndup(ptr_count, (ptr1_count-ptr_count));
420-
strcpy(ct,temp);
423+
strncpy(ct,temp,(sizeof(ct)-1));
421424
break;
422425
}
423426

@@ -443,6 +446,7 @@ int testUtility()
443446
}
444447
else
445448
{
449+
WEBCFG_FREE(transaction_uuid);
446450
WebcfgError("webConfigData is empty, need to retry\n");
447451
}
448452
sprintf(command,"rm -rf %s",TEST_FILE_LOCATION);

src/webcfg_client.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ static void get_parodus_url(char **parodus_url, char **client_url)
184184
if (NULL != fp)
185185
{
186186
char str[255] = {'\0'};
187+
//TODO:: Use Fgets to fix coverity issue "fscanf" assumes an arbitrarily long string.
187188
while(fscanf(fp,"%s", str) != EOF)
188189
{
189190
char *value = NULL;

src/webcfg_event.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ void* processSubdocEvents()
260260
WebcfgInfo("ACK for mesh/cujo received: %s,%lu,%lu,%s,%lu\n", eventParam->subdoc_name,(long)eventParam->trans_id, (long)eventParam->version, eventParam->status, (long)eventParam->timeout);
261261
handleConnectedClientNotify(eventParam->status);
262262
}
263+
263264
WebcfgInfo("ACK EVENT: %s,%lu,%lu,ACK,%lu %s\n", eventParam->subdoc_name,(long)eventParam->trans_id, (long)eventParam->version, (long)eventParam->timeout, "(doc apply success)");
264265
WebcfgInfo("doc apply success, proceed to add to DB\n");
265266
if( validateEvent(subdoc_node, eventParam->subdoc_name, eventParam->trans_id) == WEBCFG_SUCCESS)
@@ -980,7 +981,7 @@ uint32_t getDocVersionFromTmpList(webconfig_tmp_data_t *temp, char *docname)
980981
//validate each event based on exact doc txid in tmp list.
981982
WEBCFG_STATUS validateEvent(webconfig_tmp_data_t *temp, char *docname, uint16_t txid)
982983
{
983-
if (NULL != temp)
984+
if ((NULL != temp) && (docname != NULL))
984985
{
985986
WebcfgDebug("validateEvent: temp->name %s, temp->trans_id %hu\n",temp->name, temp->trans_id);
986987
if( strcmp(docname, temp->name) == 0)
@@ -1034,7 +1035,7 @@ void handleConnectedClientNotify(char *status)
10341035

10351036
if(status != NULL)
10361037
{
1037-
strcpy(tmpStr , status);
1038+
strncpy(tmpStr , status,(sizeof(tmpStr)-1));
10381039
token = strtok(tmpStr, s);
10391040
if( token != NULL )
10401041
{

src/webcfg_metadata.c

Lines changed: 253 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,253 @@
1+
/*
2+
* Copyright 2020 Comcast Cable Communications Management, LLC
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+
#include <errno.h>
17+
#include <string.h>
18+
#include <stdlib.h>
19+
#include "webcfg_log.h"
20+
#include "webcfg_metadata.h"
21+
#include "webcfg_multipart.h"
22+
23+
/*----------------------------------------------------------------------------*/
24+
/* Macros */
25+
/*----------------------------------------------------------------------------*/
26+
#define MAXCHAR 1024
27+
/*----------------------------------------------------------------------------*/
28+
/* Data Structures */
29+
/*----------------------------------------------------------------------------*/
30+
typedef struct SubDocSupportMap
31+
{
32+
char name[256];//portforwarding or wlan
33+
char support[8];//true or false;
34+
struct SubDocSupportMap *next;
35+
}SubDocSupportMap_t;
36+
37+
/*----------------------------------------------------------------------------*/
38+
/* File Scoped Variables */
39+
/*----------------------------------------------------------------------------*/
40+
static char * supported_bits = NULL;
41+
static char * supported_version = NULL;
42+
SubDocSupportMap_t *g_sdInfoHead = NULL;
43+
SubDocSupportMap_t *g_sdInfoTail = NULL;
44+
/*----------------------------------------------------------------------------*/
45+
/* Function Prototypes */
46+
/*----------------------------------------------------------------------------*/
47+
void displaystruct();
48+
SubDocSupportMap_t * get_global_sdInfoHead(void);
49+
SubDocSupportMap_t * get_global_sdInfoTail(void);
50+
/*----------------------------------------------------------------------------*/
51+
/* External Functions */
52+
/*----------------------------------------------------------------------------*/
53+
54+
55+
void initWebcfgProperties(char * filename)
56+
{
57+
FILE *fp = NULL;
58+
char str[MAXCHAR] = {'\0'};
59+
//For WEBCONFIG_SUBDOC_MAP parsing
60+
char *p;
61+
char *token;
62+
63+
WebcfgDebug("webcfg properties file path is %s\n", filename);
64+
fp = fopen(filename,"r");
65+
66+
if (fp == NULL)
67+
{
68+
WebcfgError("Failed to open file %s\n", filename);
69+
return;
70+
}
71+
72+
while (fgets(str, MAXCHAR, fp) != NULL)
73+
{
74+
char * value = NULL;
75+
76+
if(NULL != (value = strstr(str,"WEBCONFIG_SUPPORTED_DOCS_BIT=")))
77+
{
78+
WebcfgDebug("The value stored is %s\n", str);
79+
value = value + strlen("WEBCONFIG_SUPPORTED_DOCS_BIT=");
80+
value[strlen(value)-1] = '\0';
81+
setsupportedDocs(value);
82+
value = NULL;
83+
}
84+
85+
if(NULL != (value =strstr(str,"WEBCONFIG_DOC_SCHEMA_VERSION")))
86+
{
87+
WebcfgDebug("The value stored is %s\n", str);
88+
value = value + strlen("WEBCONFIG_DOC_SCHEMA_VERSION=");
89+
value[strlen(value)-1] = '\0';
90+
setsupportedVersion(value);
91+
value = NULL;
92+
}
93+
94+
if(strncmp(str,"WEBCONFIG_SUBDOC_MAP",strlen("WEBCONFIG_SUBDOC_MAP")) ==0)
95+
{
96+
97+
p = str;
98+
char *tok = NULL;
99+
WebcfgDebug("The value of tok is %s\n", tok);
100+
tok = strtok_r(p, " =",&p);
101+
token = strtok_r(p,",",&p);
102+
while(token!= NULL)
103+
{
104+
105+
char subdoc[100];
106+
char *subtoken;
107+
SubDocSupportMap_t *sdInfo = NULL;
108+
strncpy(subdoc,token,(sizeof(subdoc)-1));
109+
puts(subdoc);
110+
sdInfo = (SubDocSupportMap_t *)malloc(sizeof(SubDocSupportMap_t));
111+
if( sdInfo==NULL )
112+
{
113+
fclose(fp);
114+
WebcfgError("Unable to allocate memory");
115+
return;
116+
}
117+
memset(sdInfo, 0, sizeof(SubDocSupportMap_t));
118+
119+
subtoken = strtok(subdoc,":");//portforwarding or lan
120+
121+
if(subtoken == NULL)
122+
{
123+
fclose(fp);
124+
WEBCFG_FREE(sdInfo);
125+
return;
126+
}
127+
128+
strncpy(sdInfo->name,subtoken,(sizeof(sdInfo->name)-1));
129+
subtoken = strtok(NULL,":");//skip 1st value
130+
subtoken = strtok(NULL,":");//true or false
131+
strncpy(sdInfo->support,subtoken,(sizeof(sdInfo->support)-1));
132+
token =strtok_r(p,",",&p);
133+
sdInfo->next = NULL;
134+
135+
if(g_sdInfoTail == NULL)
136+
{
137+
g_sdInfoHead = sdInfo;
138+
g_sdInfoTail = sdInfo;
139+
}
140+
else
141+
{
142+
SubDocSupportMap_t *temp =NULL;
143+
temp = get_global_sdInfoTail();
144+
temp->next = sdInfo;
145+
g_sdInfoTail = sdInfo;
146+
}
147+
148+
}
149+
150+
}
151+
}
152+
fclose(fp);
153+
154+
if(g_sdInfoHead != NULL)
155+
{
156+
displaystruct();
157+
}
158+
}
159+
160+
void setsupportedDocs( char * value)
161+
{
162+
if(value != NULL)
163+
{
164+
supported_bits = strdup(value);
165+
}
166+
else
167+
{
168+
supported_bits = NULL;
169+
}
170+
}
171+
172+
void setsupportedVersion( char * value)
173+
{
174+
if(value != NULL)
175+
{
176+
supported_version = strdup(value);
177+
}
178+
else
179+
{
180+
supported_version = NULL;
181+
}
182+
}
183+
184+
char * getsupportedDocs()
185+
{
186+
WebcfgDebug("The value in supportedbits get is %s\n",supported_bits);
187+
return supported_bits;
188+
}
189+
190+
char * getsupportedVersion()
191+
{
192+
WebcfgDebug("The value in supportedversion get is %s\n",supported_version);
193+
return supported_version;
194+
}
195+
196+
WEBCFG_STATUS isSubDocSupported(char *subDoc)
197+
{
198+
199+
SubDocSupportMap_t *sd = NULL;
200+
201+
sd = get_global_sdInfoHead();
202+
203+
while(sd != NULL)
204+
{
205+
if(strncmp(sd->name, subDoc, strlen(subDoc)) == 0)
206+
{
207+
WebcfgDebug("The subdoc %s is present\n",sd->name);
208+
if(strncmp(sd->support, "true", strlen("true")) == 0)
209+
{
210+
WebcfgInfo("%s is supported\n",subDoc);
211+
return WEBCFG_SUCCESS;
212+
213+
}
214+
else
215+
{
216+
WebcfgInfo("%s is not supported\n",subDoc);
217+
return WEBCFG_FAILURE;
218+
}
219+
}
220+
sd = sd->next;
221+
222+
}
223+
WebcfgError("Supported doc bit not found for %s\n",subDoc);
224+
return WEBCFG_FAILURE;
225+
}
226+
227+
/*----------------------------------------------------------------------------*/
228+
/* Internal functions */
229+
/*----------------------------------------------------------------------------*/
230+
SubDocSupportMap_t * get_global_sdInfoHead(void)
231+
{
232+
SubDocSupportMap_t *tmp = NULL;
233+
tmp = g_sdInfoHead;
234+
return tmp;
235+
}
236+
237+
SubDocSupportMap_t * get_global_sdInfoTail(void)
238+
{
239+
SubDocSupportMap_t *tmp = NULL;
240+
tmp = g_sdInfoTail;
241+
return tmp;
242+
}
243+
244+
void displaystruct()
245+
{
246+
SubDocSupportMap_t *temp =NULL;
247+
temp = get_global_sdInfoHead();
248+
while(temp != NULL)
249+
{
250+
WebcfgDebug(" %s %s\n",temp->name,temp->support);
251+
temp=temp->next;
252+
}
253+
}

src/webcfg_metadata.h

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright 2020 Comcast Cable Communications Management, LLC
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+
#ifndef __WEBCFG__METADATA_H__
17+
#define __WEBCFG__METADATA_H__
18+
19+
#include <stdint.h>
20+
#include <string.h>
21+
#include "webcfg.h"
22+
/*----------------------------------------------------------------------------*/
23+
/* Macros */
24+
/*----------------------------------------------------------------------------*/
25+
#ifdef BUILD_YOCTO
26+
#define WEBCFG_PROPERTIES_FILE "/etc/webconfig.properties"
27+
#else
28+
#define WEBCFG_PROPERTIES_FILE "/tmp/webconfig.properties"
29+
#endif
30+
31+
/*----------------------------------------------------------------------------*/
32+
/* Data Structures */
33+
/*----------------------------------------------------------------------------*/
34+
35+
/*----------------------------------------------------------------------------*/
36+
/* External Functions */
37+
/*----------------------------------------------------------------------------*/
38+
WEBCFG_STATUS isSubDocSupported(char *subDoc);
39+
void initWebcfgProperties(char * filename);
40+
void setsupportedDocs( char * value);
41+
void setsupportedVersion( char * value);
42+
char * getsupportedDocs();
43+
char * getsupportedVersion();
44+
#endif

0 commit comments

Comments
 (0)