Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/webcfg.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
/* Macros */
/*----------------------------------------------------------------------------*/
#define MAX_BUF_SIZE 256
#define MAX_URL_LENGTH 768
#define MAX_PARAMETERNAME_LENGTH 512
#define MAX_LBUFF_SIZE 8192

#ifdef BUILD_YOCTO
#define DEVICE_PROPS_FILE "/etc/device.properties"
Expand Down
2 changes: 1 addition & 1 deletion src/webcfg_generic_pc.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ char *getPartnerID(void)

char *getAccountID(void)
{
char *AI=strdup("unkown");
char *AI=strdup("unknown");
return AI;
}

Expand Down
52 changes: 21 additions & 31 deletions src/webcfg_multipart.c
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,6 @@
char *ct = NULL;
char *webConfigURL = NULL;
char *transID = NULL;
char *subdoclist = NULL;
char docList[512] = {'\0'};
char configURL[256] = { 0 };
char c[] = "{mac}";
int rv = 0;
Expand All @@ -216,7 +214,6 @@
struct token_data data;
data.size = 0;
void * dataVal = NULL;
char syncURL[MAX_URL_LENGTH]={'\0'};
char docname_upper[64]={'\0'};

curl = curl_easy_init();
Expand All @@ -231,17 +228,12 @@
return WEBCFG_FAILURE;
}
data.data[0] = '\0';
createCurlHeader(list, &headers_list, status, &transID, &subdoclist);
createCurlHeader(list, &headers_list, status, &transID);

Check warning on line 231 in src/webcfg_multipart.c

View check run for this annotation

Codecov / codecov/patch

src/webcfg_multipart.c#L231

Added line #L231 was not covered by tests
if(transID !=NULL)
{
*transaction_id = strdup(transID);
WEBCFG_FREE(transID);
}
if(subdoclist !=NULL)
{
strncpy(docList, subdoclist, sizeof(docList)-1);
WEBCFG_FREE(subdoclist);
}
WebcfgInfo("The get_global_supplementarySync() is %d\n", get_global_supplementarySync());
if(get_global_supplementarySync() == 0)
{
Expand Down Expand Up @@ -318,17 +310,6 @@
}
WebcfgDebug("ConfigURL fetched is %s\n", webConfigURL);

if(!get_global_supplementarySync())
{
if(strlen(docList) > 0)
{
WebcfgDebug("docList is %s\n", docList);
snprintf(syncURL, MAX_URL_LENGTH, "%s?group_id=%s", webConfigURL, docList);
WEBCFG_FREE(webConfigURL);
WebcfgDebug("syncURL is %s\n", syncURL);
webConfigURL =strdup( syncURL);
}
}
if(webConfigURL !=NULL)
{
WebcfgInfo("Webconfig root ConfigURL is %s\n", webConfigURL);
Expand Down Expand Up @@ -1464,7 +1445,7 @@
/* Traverse through db list to get versions and doclist of all docs with root.
e.g. IF-NONE-MATCH: 123,44317,66317,77317 where 123 is root version.
e.g. root,ble,lan,mesh,moca
Currently versionsList length is fixed to 512 which can support up to 45 docs.
Currently versionsList length is fixed to 8192 which can support up to 512 docs.
This can be increased if required.
VersionList and docList are fetched at once from DB to fix version and docList mismatch when DB is updated.*/
void refreshConfigVersionList(char *versionsList, int http_status, char *docsList)
Expand All @@ -1476,7 +1457,7 @@
WEBCFG_STATUS retStatus = WEBCFG_SUCCESS;

//initialize to default value "0".
snprintf(versionsList, 512, "%s", "0");
snprintf(versionsList, MAX_LBUFF_SIZE, "%s", "0");

derive_root_doc_version_string(&root_str, &root_version, http_status);
WebcfgDebug("update root_version %lu rootString %s to DB\n", (long)root_version, root_str);
Expand All @@ -1495,7 +1476,7 @@
if(root_str!=NULL && strlen(root_str) >0)
{
WebcfgDebug("update root_str %s to versionsList\n", root_str);
snprintf(versionsList, 512, "%s", root_str);
snprintf(versionsList, MAX_LBUFF_SIZE, "%s", root_str);
WEBCFG_FREE(root_str);
}
else
Expand All @@ -1505,7 +1486,7 @@
}
WebcfgInfo("versionsList is %s\n", versionsList);

snprintf(docsList, 512, "%s", "root");
snprintf(docsList, MAX_LBUFF_SIZE, "%s", "root");
WebcfgDebug("docsList is %s\n", docsList);

while (NULL != temp)
Expand All @@ -1519,7 +1500,7 @@
WEBCFG_FREE(versionsList_tmp);
//Fetch docsList and version together to fix docs & version mismatch from DB
docsList_tmp = strdup(docsList);
snprintf(docsList, 512, "%s,%s",docsList_tmp, temp->name);
snprintf(docsList, MAX_LBUFF_SIZE, "%s,%s",docsList_tmp, temp->name);
WEBCFG_FREE(docsList_tmp);
}
}
Expand All @@ -1539,12 +1520,13 @@

//NOTE: If new headers are added in webcfg curl flow add them in MQTT createMqttHeader also if necessary
#if !defined FEATURE_SUPPORT_MQTTCM
void createCurlHeader( struct curl_slist *list, struct curl_slist **header_list, int status, char ** trans_uuid, char **subdocList)
void createCurlHeader( struct curl_slist *list, struct curl_slist **header_list, int status, char ** trans_uuid)

Check warning on line 1523 in src/webcfg_multipart.c

View check run for this annotation

Codecov / codecov/patch

src/webcfg_multipart.c#L1523

Added line #L1523 was not covered by tests
{
char *version_header = NULL;
char *auth_header = NULL;
char *status_header=NULL;
char *schema_header=NULL;
char *doc_header = NULL;
char *bootTime = NULL, *bootTime_header = NULL;
char *FwVersion = NULL, *FwVersion_header=NULL;
char *supportedDocs = NULL;
Expand All @@ -1562,8 +1544,8 @@
char *currentTime_header=NULL;
char *uuid_header = NULL;
char *transaction_uuid = NULL;
char version[512]={'\0'};
char docList[512]={'\0'};
char version[MAX_LBUFF_SIZE]={'\0'};
char docList[MAX_LBUFF_SIZE]={'\0'};
size_t supported_doc_size = 0;
size_t supported_version_size = 0;
size_t supplementary_docs_size = 0;
Expand All @@ -1584,16 +1566,24 @@

if(!get_global_supplementarySync())
{
version_header = (char *) malloc(sizeof(char)*MAX_BUF_SIZE);
version_header = (char *) malloc(sizeof(char) * (MAX_LBUFF_SIZE + strlen("IF-NONE-MATCH:") + 1));
if(version_header !=NULL)
{
refreshConfigVersionList(version, 0, docList);
snprintf(version_header, MAX_BUF_SIZE, "IF-NONE-MATCH:%s", ((strlen(version)!=0) ? version : "0"));
snprintf(version_header, MAX_LBUFF_SIZE + strlen("IF-NONE-MATCH:") + 1, "IF-NONE-MATCH:%s", ((strlen(version)!=0) ? version : "0"));
WebcfgInfo("version_header formed %s\n", version_header);
WebcfgInfo("docList fetched %s\n", docList);
*subdocList = strdup(docList);
list = curl_slist_append(list, version_header);
WEBCFG_FREE(version_header);

doc_header = (char *)malloc(sizeof(char) * (MAX_LBUFF_SIZE + strlen("Doc-Name: ") + 1));
if (doc_header != NULL)

Check warning on line 1580 in src/webcfg_multipart.c

View check run for this annotation

Codecov / codecov/patch

src/webcfg_multipart.c#L1580

Added line #L1580 was not covered by tests
{
snprintf(doc_header, MAX_LBUFF_SIZE + strlen("Doc-Name: ") + 1, "Doc-Name: %s", docList);

Check warning on line 1582 in src/webcfg_multipart.c

View check run for this annotation

Codecov / codecov/patch

src/webcfg_multipart.c#L1582

Added line #L1582 was not covered by tests
list = curl_slist_append(list, doc_header);
WebcfgInfo("doc_header formed %s\n", doc_header);
WEBCFG_FREE(doc_header);
}
}
WebcfgInfo("Post none retain header formed POST-NONE-RETAIN: true\n");
list = curl_slist_append(list, "POST-NONE-RETAIN: true");
Expand Down
2 changes: 1 addition & 1 deletion src/webcfg_multipart.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ WEBCFG_STATUS deleteFromMpList(char* doc_name);
void addToMpList(uint32_t etag, char *name_space, char *data, size_t data_size);
void delete_mp_doc();
#if !defined FEATURE_SUPPORT_MQTTCM
void createCurlHeader( struct curl_slist *list, struct curl_slist **header_list, int status, char ** trans_uuid,char **subdocList);
void createCurlHeader( struct curl_slist *list, struct curl_slist **header_list, int status, char ** trans_uuid);
#endif
char *replaceMacWord(const char *s, const char *macW, const char *deviceMACW);
void checkValidURL(char **s);
Expand Down
4 changes: 2 additions & 2 deletions tests/test_generic_pc.c
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ void test_getAccountID()
{
char *pString = "test";
pString = getAccountID();
CU_ASSERT_STRING_EQUAL(pString, "unkown");
CU_ASSERT_STRING_EQUAL(pString, "unknown");
}

void test_getPartnerID()
Expand Down Expand Up @@ -377,4 +377,4 @@ int main( int argc, char *argv[] )

return rv;
}


Loading
Loading