Skip to content

Commit d9d3924

Browse files
Merge pull request #29 from sadhyama/webcfg_reboot
Webcfg handling of Factory Reset and Reboot scenarios
2 parents 1d7b4dc + bb12635 commit d9d3924

17 files changed

+689
-65
lines changed

src/webcfg.c

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -297,18 +297,29 @@ int handlehttpResponse(long response_code, char *webConfigData, int retry_count,
297297
int first_digit=0;
298298
int msgpack_status=0;
299299
int err = 0;
300+
char version[512]={'\0'};
301+
uint32_t db_root_version = 0;
302+
char *db_root_string = NULL;
303+
int subdocList = 0;
304+
char *contentLength = NULL;
300305

301306
if(response_code == 304)
302307
{
303308
WebcfgInfo("webConfig is in sync with cloud. response_code:%ld\n", response_code);
309+
getRootDocVersionFromDBCache(&db_root_version, &db_root_string, &subdocList);
310+
addWebConfgNotifyMsg(NULL, db_root_version, NULL, NULL, transaction_uuid, 0, "status", 0, db_root_string, response_code);
311+
if(db_root_string !=NULL)
312+
{
313+
WEBCFG_FREE(db_root_string);
314+
}
304315
WEBCFG_FREE(transaction_uuid);
305316
return 1;
306317
}
307318
else if(response_code == 200)
308319
{
309320
WebcfgInfo("webConfig is not in sync with cloud. response_code:%ld\n", response_code);
310321

311-
if(webConfigData !=NULL)
322+
if(webConfigData !=NULL && (strlen(webConfigData)>0))
312323
{
313324
WebcfgDebug("webConfigData fetched successfully\n");
314325
WebcfgDebug("parseMultipartDocument\n");
@@ -321,18 +332,35 @@ int handlehttpResponse(long response_code, char *webConfigData, int retry_count,
321332
}
322333
else
323334
{
324-
WebcfgError("Failed to apply root webConfigData received from server\n");
335+
WebcfgDebug("root webConfigData processed, check apply status events\n");
325336
return 1;
326337
}
327338
}
328339
else
329340
{
330-
WebcfgError("webConfigData is empty, need to do curl retry to server\n");
341+
WebcfgInfo("webConfigData is empty\n");
342+
//After factory reset when server sends 200 with empty config, set POST-NONE root version
343+
contentLength = get_global_contentLen();
344+
if((contentLength !=NULL) && (strcmp(contentLength, "0") == 0))
345+
{
346+
WebcfgInfo("webConfigData content length is 0\n");
347+
refreshConfigVersionList(version, response_code);
348+
WEBCFG_FREE(contentLength);
349+
WEBCFG_FREE(transaction_uuid);
350+
WEBCFG_FREE(webConfigData);
351+
return 1;
352+
}
331353
}
332354
}
333355
else if(response_code == 204)
334356
{
335357
WebcfgInfo("No configuration available for this device. response_code:%ld\n", response_code);
358+
getRootDocVersionFromDBCache(&db_root_version, &db_root_string, &subdocList);
359+
addWebConfgNotifyMsg(NULL, db_root_version, NULL, NULL, transaction_uuid, 0, "status", 0, db_root_string, response_code);
360+
if(db_root_string !=NULL)
361+
{
362+
WEBCFG_FREE(db_root_string);
363+
}
336364
WEBCFG_FREE(transaction_uuid);
337365
return 1;
338366
}
@@ -346,13 +374,30 @@ int handlehttpResponse(long response_code, char *webConfigData, int retry_count,
346374
else if(response_code == 429)
347375
{
348376
WebcfgInfo("No action required from client. response_code:%ld\n", response_code);
377+
getRootDocVersionFromDBCache(&db_root_version, &db_root_string, &subdocList);
378+
addWebConfgNotifyMsg(NULL, db_root_version, NULL, NULL, transaction_uuid, 0, "status", 0, db_root_string, response_code);
379+
if(db_root_string !=NULL)
380+
{
381+
WEBCFG_FREE(db_root_string);
382+
}
349383
WEBCFG_FREE(transaction_uuid);
350384
return 1;
351385
}
352386
first_digit = (int)(response_code / pow(10, (int)log10(response_code)));
353387
if((response_code !=403) && (first_digit == 4)) //4xx
354388
{
355389
WebcfgInfo("Action not supported. response_code:%ld\n", response_code);
390+
if (response_code == 404)
391+
{
392+
//To set POST-NONE root version when 404
393+
refreshConfigVersionList(version, response_code);
394+
}
395+
getRootDocVersionFromDBCache(&db_root_version, &db_root_string, &subdocList);
396+
addWebConfgNotifyMsg(NULL, db_root_version, NULL, NULL, transaction_uuid, 0, "status", 0, db_root_string, response_code);
397+
if(db_root_string !=NULL)
398+
{
399+
WEBCFG_FREE(db_root_string);
400+
}
356401
WEBCFG_FREE(transaction_uuid);
357402
return 1;
358403
}
@@ -362,6 +407,12 @@ int handlehttpResponse(long response_code, char *webConfigData, int retry_count,
362407
if(retry_count == 3 && !err)
363408
{
364409
WebcfgDebug("3 curl retry attempts\n");
410+
getRootDocVersionFromDBCache(&db_root_version, &db_root_string, &subdocList);
411+
addWebConfgNotifyMsg(NULL, db_root_version, NULL, NULL, transaction_uuid, 0, "status", 0, db_root_string, response_code);
412+
if(db_root_string !=NULL)
413+
{
414+
WEBCFG_FREE(db_root_string);
415+
}
365416
WEBCFG_FREE(transaction_uuid);
366417
return 0;
367418
}

src/webcfg_aker.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ void updateAkerMaxRetry(webconfig_tmp_data_t *temp, char *docname)
222222
if( strcmp(docname, temp->name) == 0)
223223
{
224224
updateTmpList(temp, temp->name, temp->version, "failed", "aker_service_unavailable", 0, 0, 0);
225-
addWebConfgNotifyMsg(temp->name, temp->version, "failed", "aker_service_unavailable", get_global_transID(),0, "status", 0);
225+
addWebConfgNotifyMsg(temp->name, temp->version, "failed", "aker_service_unavailable", get_global_transID(),0, "status", 0, NULL, 200);
226226
return;
227227
}
228228
}
@@ -314,7 +314,7 @@ AKER_STATUS processAkerSubdoc(webconfig_tmp_data_t *docNode, int akerIndex)
314314
{
315315
//Invalid aker request
316316
updateTmpList(docNode, gmp->entries[m].name_space, gmp->entries[m].etag, "failed", "doc_rejected", 0, 0, 0);
317-
addWebConfgNotifyMsg(gmp->entries[m].name_space, gmp->entries[m].etag, "failed", "doc_rejected", get_global_transID(),0, "status", 0);
317+
addWebConfgNotifyMsg(gmp->entries[m].name_space, gmp->entries[m].etag, "failed", "doc_rejected", get_global_transID(),0, "status", 0, NULL, 200);
318318
rv = AKER_FAILURE;
319319
}
320320
reqParam_destroy(paramCount, reqParam);

src/webcfg_db.c

Lines changed: 70 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,8 @@ WEBCFG_STATUS addNewDocEntry(size_t count)
144144

145145
WebcfgDebug("DB docs count %ld\n", (size_t)count);
146146
webcfgdbPackSize = webcfgdb_pack(webcfgdb_data, &data, count);
147-
WebcfgInfo("size of webcfgdbPackSize %ld\n", webcfgdbPackSize);
148-
WebcfgInfo("writeToDBFile %s\n", WEBCFG_DB_FILE);
147+
WebcfgDebug("size of webcfgdbPackSize %ld\n", webcfgdbPackSize);
148+
WebcfgDebug("writeToDBFile %s\n", WEBCFG_DB_FILE);
149149
writeToDBFile(WEBCFG_DB_FILE,(char *)data,webcfgdbPackSize);
150150
if(data)
151151
{
@@ -263,6 +263,9 @@ void webcfgdbblob_destroy( blob_struct_t *bd )
263263
if( NULL != bd->entries[i].error_details ) {
264264
free( bd->entries[i].error_details );
265265
}
266+
if( NULL != bd->entries[i].root_string ) {
267+
free( bd->entries[i].root_string );
268+
}
266269
}
267270
if( NULL != bd->entries ) {
268271
free( bd->entries );
@@ -461,9 +464,9 @@ WEBCFG_STATUS addToTmpList( multipart_t *mp)
461464
}
462465

463466

464-
void checkDBList(char *docname, uint32_t version)
467+
void checkDBList(char *docname, uint32_t version, char* rootstr)
465468
{
466-
if(updateDBlist(docname, version) != WEBCFG_SUCCESS)
469+
if(updateDBlist(docname, version, rootstr) != WEBCFG_SUCCESS)
467470
{
468471
webconfig_db_data_t * webcfgdb = NULL;
469472
webcfgdb = (webconfig_db_data_t *) malloc (sizeof(webconfig_db_data_t));
@@ -473,10 +476,24 @@ void checkDBList(char *docname, uint32_t version)
473476

474477
webcfgdb->name = strdup(docname);
475478
webcfgdb->version = version;
479+
if( strcmp("root", webcfgdb->name) == 0)
480+
{
481+
if(rootstr !=NULL)
482+
{
483+
webcfgdb->root_string = strdup(rootstr);
484+
}
485+
}
476486
webcfgdb->next = NULL;
477487

478488
addToDBList(webcfgdb);
479-
WebcfgInfo("webcfgdb->name added to DB %s webcfgdb->version %lu\n",webcfgdb->name, (long)webcfgdb->version);
489+
if(webcfgdb->root_string !=NULL)
490+
{
491+
WebcfgInfo("webcfgdb->name added to DB %s webcfgdb->version %lu webcfgdb->root_string %s\n",webcfgdb->name, (long)webcfgdb->version, webcfgdb->root_string);
492+
}
493+
else
494+
{
495+
WebcfgInfo("webcfgdb->name added to DB %s webcfgdb->version %lu\n",webcfgdb->name, (long)webcfgdb->version);
496+
}
480497
}
481498
else
482499
{
@@ -485,7 +502,7 @@ void checkDBList(char *docname, uint32_t version)
485502
}
486503
}
487504

488-
WEBCFG_STATUS updateDBlist(char *docname, uint32_t version)
505+
WEBCFG_STATUS updateDBlist(char *docname, uint32_t version, char* rootstr)
489506
{
490507
webconfig_db_data_t *webcfgdb = NULL;
491508
webcfgdb = get_global_db_node();
@@ -495,11 +512,23 @@ WEBCFG_STATUS updateDBlist(char *docname, uint32_t version)
495512
{
496513
pthread_mutex_lock (&webconfig_db_mut);
497514
WebcfgDebug("mutex_lock in updateDBlist\n");
498-
WebcfgDebug("node is pointing to webcfgdb->name %s, docname %s, dblen %zu, doclen %zu \n",webcfgdb->name, docname, strlen(webcfgdb->name), strlen(docname));
515+
WebcfgDebug("node is pointing to webcfgdb->name %s, docname %s, dblen %zu, doclen %zu webcfgdb->root_string %s\n",webcfgdb->name, docname, strlen(webcfgdb->name), strlen(docname), webcfgdb->root_string);
499516
if( strcmp(docname, webcfgdb->name) == 0)
500517
{
501518
webcfgdb->version = version;
502-
WebcfgDebug("webcfgdb %s is updated to version %lu\n", docname, (long)webcfgdb->version);
519+
if( strcmp("root", webcfgdb->name) == 0)
520+
{
521+
if(webcfgdb->root_string !=NULL)
522+
{
523+
WEBCFG_FREE(webcfgdb->root_string);
524+
webcfgdb->root_string = NULL;
525+
}
526+
if(rootstr!=NULL)
527+
{
528+
webcfgdb->root_string = strdup(rootstr);
529+
}
530+
}
531+
WebcfgDebug("webcfgdb %s is updated to version %lu webcfgdb->root_string %s\n", docname, (long)webcfgdb->version, webcfgdb->root_string);
503532
pthread_mutex_unlock (&webconfig_db_mut);
504533
WebcfgDebug("mutex_unlock if docname is webcfgdb name\n");
505534
return WEBCFG_SUCCESS;
@@ -641,7 +670,7 @@ void delete_tmp_doc_list()
641670
int process_webcfgdbparams( webconfig_db_data_t *e, msgpack_object_map *map )
642671
{
643672
int left = map->size;
644-
uint8_t objects_left = 0x02;
673+
uint8_t objects_left = 0x03;
645674
msgpack_object_kv *p;
646675

647676
p = map->ptr;
@@ -675,16 +704,27 @@ int process_webcfgdbparams( webconfig_db_data_t *e, msgpack_object_map *map )
675704
{
676705
e->name = strndup( p->val.via.str.ptr, p->val.via.str.size );
677706
//WebcfgDebug("e->name is %s\n", e->name);
678-
objects_left &= ~(1 << 0);
707+
objects_left &= ~(1 << 2);
679708
//WebcfgDebug("objects_left after name %d\n", objects_left);
680709
}
710+
else if( 0 == match(p, "root_string") )
711+
{
712+
e->root_string = strndup( p->val.via.str.ptr, p->val.via.str.size );
713+
//WebcfgDebug("e->root_string is %s\n", e->root_string);
714+
objects_left &= ~(1 << 0);
715+
//WebcfgDebug("objects_left after root_string %d\n", objects_left);
716+
}
681717
}
682718
}
683719
p++;
684720
}
685-
686721
if( 1 & objects_left )
687722
{
723+
if( (1 << 0) & objects_left )
724+
{
725+
WebcfgDebug("Skip optional root_string element\n");
726+
objects_left &= ~(1 << 0);
727+
}
688728
}
689729
else
690730
{
@@ -815,7 +855,14 @@ char * get_DB_BLOB_base64()
815855
{
816856
for(k = 0;k< bd->entries_count ; k++)
817857
{
818-
WebcfgInfo("Blob bd->entries[%zu].name %s, version: %lu, status: %s, error_details: %s, error_code: %d\n", k, bd->entries[k].name, (long)bd->entries[k].version, bd->entries[k].status, bd->entries[k].error_details, bd->entries[k].error_code );
858+
if(bd->entries[k].root_string !=NULL)
859+
{
860+
WebcfgInfo("Blob bd->entries[%zu].name %s, version: %lu, status: %s, error_details: %s, error_code: %d root_string: %s\n", k, bd->entries[k].name, (long)bd->entries[k].version, bd->entries[k].status, bd->entries[k].error_details, bd->entries[k].error_code, bd->entries[k].root_string );
861+
}
862+
else
863+
{
864+
WebcfgInfo("Blob bd->entries[%zu].name %s, version: %lu, status: %s, error_details: %s, error_code: %d\n", k, bd->entries[k].name, (long)bd->entries[k].version, bd->entries[k].status, bd->entries[k].error_details, bd->entries[k].error_code );
865+
}
819866
}
820867

821868
}
@@ -874,7 +921,7 @@ int process_webcfgdbblobparams( blob_data_t *e, msgpack_object_map *map )
874921
e->error_code = (uint16_t) p->val.via.u64;
875922
//WebcfgDebug("e->version is %d\n", e->error_code);
876923
}
877-
objects_left &= ~(1 << 3);
924+
objects_left &= ~(1 << 4);
878925

879926
}
880927
}
@@ -898,14 +945,23 @@ int process_webcfgdbblobparams( blob_data_t *e, msgpack_object_map *map )
898945
//WebcfgDebug("e->error_details is %s\n", e->error_details);
899946
objects_left &= ~(1 << 2);
900947
}
948+
else if(0 == match(p, "root_string") )
949+
{
950+
e->root_string = strndup( p->val.via.str.ptr, p->val.via.str.size );
951+
//WebcfgDebug("e->root_string is %s\n", e->root_string);
952+
objects_left &= ~(1 << 3);
953+
}
901954
}
902955
}
903956
p++;
904957
}
905-
906958
if( 1 & objects_left )
907959
{
908960
}
961+
else if( (1 << 3) & objects_left ) {
962+
WebcfgDebug("Skip optional root_string element\n");
963+
objects_left &= ~(1 << 3);
964+
}
909965
else
910966
{
911967
errno = BD_OK;

src/webcfg_db.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ typedef struct webconfig_tmp_data
5050
typedef struct webconfig_db_data{
5151
char * name;
5252
uint32_t version;
53+
char *root_string;
5354
struct webconfig_db_data *next;
5455
}webconfig_db_data_t;
5556

@@ -62,6 +63,7 @@ typedef struct blob{
6263
typedef struct{
6364
char * name;
6465
uint32_t version;
66+
char *root_string;
6567
char * status;
6668
char * error_details;
6769
uint16_t error_code;
@@ -130,9 +132,9 @@ void set_doc_fail( int value);
130132

131133
char * get_DB_BLOB_base64();
132134

133-
void checkDBList(char *docname, uint32_t version);
135+
void checkDBList(char *docname, uint32_t version,char *rootstr);
134136

135-
WEBCFG_STATUS updateDBlist(char *docname, uint32_t version);
137+
WEBCFG_STATUS updateDBlist(char *docname, uint32_t version,char *rootstr);
136138

137139
int writebase64ToDBFile(char *base64_file_path, char *data);
138140

0 commit comments

Comments
 (0)