From b9505e60f46f054610eb34990e6fbce40db92ef8 Mon Sep 17 00:00:00 2001 From: Sadhyama Vengilat Date: Fri, 13 Jan 2023 19:43:03 +0530 Subject: [PATCH 1/5] Webcfg to resync with cloud on wan restore via curl get --- src/CMakeLists.txt | 9 +++++++++ src/webcfg.c | 45 +++++++++++++++++++++++++++++++++++++++++++-- src/webcfg.h | 5 ++++- src/webcfg_rbus.c | 34 +++++++++++++++++++++++++++++++--- src/webcfg_rbus.h | 1 + 5 files changed, 88 insertions(+), 6 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a2926596..4009d4bc 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -18,6 +18,10 @@ if (WEBCONFIG_BIN_SUPPORT) add_definitions(-DWEBCONFIG_BIN_SUPPORT) endif (WEBCONFIG_BIN_SUPPORT) +if (WAN_FAILOVER_SUPPORTED) +add_definitions(-DWAN_FAILOVER_SUPPORTED) +endif (WAN_FAILOVER_SUPPORTED) + if (FEATURE_SUPPORT_AKER) add_definitions(-DFEATURE_SUPPORT_AKER) endif (FEATURE_SUPPORT_AKER) @@ -28,6 +32,11 @@ else() message(STATUS "WEBCONFIG_BIN_SUPPORT is not supported") endif (WEBCONFIG_BIN_SUPPORT) +if (WAN_FAILOVER_SUPPORTED) +message(STATUS "WAN_FAILOVER_SUPPORTED is supported") +else() +message(STATUS "WAN_FAILOVER_SUPPORTED is not supported") +endif (WAN_FAILOVER_SUPPORTED) 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_metadata.h webcfg_timer.h webcfg_privilege.h) 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_blob.c webcfg_event.c webcfg_metadata.c webcfg_timer.c webcfg_privilege.c) diff --git a/src/webcfg.c b/src/webcfg.c index 451aa047..12348a32 100644 --- a/src/webcfg.c +++ b/src/webcfg.c @@ -34,7 +34,7 @@ #include "webcfg_event.h" #include "webcfg_blob.h" #include "webcfg_timer.h" - +#include "webcfg_rbus.h" #ifdef FEATURE_SUPPORT_AKER #include "webcfg_aker.h" #endif @@ -71,6 +71,8 @@ pthread_t* g_mpthreadId; static int g_testfile = 0; #endif static int g_supplementarySync = 0; +static int g_wanrestore_sync = 0; +static int g_wanrestoresync_start = 0; /*----------------------------------------------------------------------------*/ /* Function Prototypes */ /*----------------------------------------------------------------------------*/ @@ -180,6 +182,11 @@ void *WebConfigMultipartTask(void *status) } setForceSync("", "", 0); set_global_supplementarySync(0); + if(get_global_wanrestoresync_start()) + { + WebcfgInfo("reset wanrestore_start\n"); + set_global_wanrestoresync_start(0); + } } if(!wait_flag) @@ -261,7 +268,14 @@ void *WebConfigMultipartTask(void *status) WebcfgDebug("The retry triggers at %s\n", printTime((long long)ts.tv_sec)); } - if(retry_flag == 1 || maintenance_doc_sync == 1) + if(get_global_wanrestore_sync() == 1) + { + WebcfgInfo("wanrestore sync detected, trigger force sync with cloud.\n"); + forced_sync = 1; + wait_flag = 1; + rv = 0; + } + else if(retry_flag == 1 || maintenance_doc_sync == 1) { WebcfgDebug("B4 sync_condition pthread_cond_timedwait\n"); set_maintenanceSync(false); @@ -295,6 +309,12 @@ void *WebConfigMultipartTask(void *status) } else if(!rv && !g_shutdown) { + if(get_global_wanrestore_sync()) + { + set_global_wanrestore_sync(0); + set_global_wanrestoresync_start(1); + WebcfgInfo("wanrestore_sync reset to %d and wanrestoresync_start %d\n", get_global_wanrestore_sync(), get_global_wanrestoresync_start()); + } char *ForceSyncDoc = NULL; char* ForceSyncTransID = NULL; @@ -383,6 +403,8 @@ void *WebConfigMultipartTask(void *status) set_global_retry_timestamp(0); set_retry_timer(0); set_global_supplementarySync(0); + set_global_wanrestore_sync(0); + set_global_wanrestoresync_start(0); #ifdef FEATURE_SUPPORT_AKER set_send_aker_flag(false); #endif @@ -484,6 +506,25 @@ int get_global_supplementarySync() return g_supplementarySync; } +void set_global_wanrestore_sync(int value) +{ + g_wanrestore_sync = value; +} + +int get_global_wanrestore_sync() +{ + return g_wanrestore_sync; +} + +void set_global_wanrestoresync_start(int value) +{ + g_wanrestoresync_start = value; +} + +int get_global_wanrestoresync_start() +{ + return g_wanrestoresync_start; +} /*----------------------------------------------------------------------------*/ /* Internal functions */ /*----------------------------------------------------------------------------*/ diff --git a/src/webcfg.h b/src/webcfg.h index c7c4bed0..0119f2fa 100644 --- a/src/webcfg.h +++ b/src/webcfg.h @@ -92,7 +92,10 @@ pthread_mutex_t *get_global_sync_mutex(void); pthread_t *get_global_mpThreadId(void); int get_global_supplementarySync(); void set_global_supplementarySync(int value); - +int get_global_wanrestore_sync(); +void set_global_wanrestore_sync(int value); +void set_global_wanrestoresync_start(int value); +int get_global_wanrestoresync_start(); void initWebConfigMultipartTask(unsigned long status); void processWebconfgSync(int Status, char* docname); WEBCFG_STATUS webcfg_http_request(char **configData, int r_count, int status, long *code, char **transaction_id,char* contentType, size_t* dataSize, char* docname); diff --git a/src/webcfg_rbus.c b/src/webcfg_rbus.c index 4069487d..9efc83fd 100755 --- a/src/webcfg_rbus.c +++ b/src/webcfg_rbus.c @@ -1634,8 +1634,12 @@ int set_rbus_ForceSync(char* pString, int *pStatus) *pStatus = 1; return 0; } - else if(strlen(ForceSyncTransID)>0) + else if((strlen(ForceSyncTransID)>0) || (get_global_wanrestoresync_start() ==1)) { + if(get_global_wanrestoresync_start()) + { + WebcfgInfo("wanrestoresync is in progress, Ignoring this request.\n"); + } WebcfgInfo("Force sync is already in progress, Ignoring this request.\n"); *pStatus = 1; return 0; @@ -1796,7 +1800,18 @@ static void eventReceiveHandler( } if(newValue !=NULL && oldValue!=NULL && get_global_interface()!=NULL) { WebcfgInfo("New Value: %s Old Value: %s New Interface Value: %s\n", rbusValue_GetString(newValue, NULL), rbusValue_GetString(oldValue, NULL), get_global_interface()); - } + + if(get_webcfgReady()) + { + + WebcfgInfo("Trigger force sync with cloud on wan restore\n"); + trigger_wanrestore_forcesync(); + } + else + { + WebcfgInfo("wan restore force sync is skipped as webcfg is not ready\n"); + } + } } static void subscribeAsyncHandler( @@ -1826,5 +1841,18 @@ int subscribeTo_CurrentActiveInterface_Event() WebcfgError("%s subscribe failed : %d - %s\n", WEBCFG_INTERFACE_PARAM, rc, rbusError_ToString(rc)); } return rc; -} +} + +//Trigger webconfig resync/force sync with cloud on wan restore value change event +void trigger_wanrestore_forcesync() +{ + char *str = NULL; + int status = 0; + + str = strdup("root"); + set_global_wanrestore_sync(1); + WebcfgInfo("set wanrestore_sync to %d\n", get_global_wanrestore_sync()); + set_rbus_ForceSync(str, &status); + WebcfgInfo("set_rbus_ForceSync on wan restore done\n"); +} #endif diff --git a/src/webcfg_rbus.h b/src/webcfg_rbus.h index 7203ab67..613a41be 100755 --- a/src/webcfg_rbus.h +++ b/src/webcfg_rbus.h @@ -116,5 +116,6 @@ void waitForUpstreamEventSubscribe(int wait_time); webcfgError_t fetchMpBlobData(char *docname, void **blobdata, int *len, uint32_t *etag); #ifdef WAN_FAILOVER_SUPPORTED int subscribeTo_CurrentActiveInterface_Event(); +void trigger_wanrestore_forcesync(); #endif #endif From 9e9178b375d738f030a68e761f615201912bb7bc Mon Sep 17 00:00:00 2001 From: Sadhyama Vengilat Date: Tue, 24 Jan 2023 17:46:00 +0530 Subject: [PATCH 2/5] Add _wanrestore suffix transid and wanfailover flag checks --- src/webcfg.c | 17 ++++++++++++++--- src/webcfg.h | 2 ++ src/webcfg_multipart.c | 15 +++++++++++++-- src/webcfg_rbus.c | 14 +++++++++----- src/webcfg_wanhandle.c | 23 +++++++++++++++++++++++ src/webcfg_wanhandle.h | 18 ++++++++++++++++++ 6 files changed, 79 insertions(+), 10 deletions(-) create mode 100644 src/webcfg_wanhandle.c create mode 100644 src/webcfg_wanhandle.h diff --git a/src/webcfg.c b/src/webcfg.c index 12348a32..c54b3b57 100644 --- a/src/webcfg.c +++ b/src/webcfg.c @@ -71,8 +71,10 @@ pthread_t* g_mpthreadId; static int g_testfile = 0; #endif static int g_supplementarySync = 0; +#ifdef WAN_FAILOVER_SUPPORTED static int g_wanrestore_sync = 0; static int g_wanrestoresync_start = 0; +#endif /*----------------------------------------------------------------------------*/ /* Function Prototypes */ /*----------------------------------------------------------------------------*/ @@ -182,11 +184,13 @@ void *WebConfigMultipartTask(void *status) } setForceSync("", "", 0); set_global_supplementarySync(0); + #ifdef WAN_FAILOVER_SUPPORTED if(get_global_wanrestoresync_start()) { WebcfgInfo("reset wanrestore_start\n"); set_global_wanrestoresync_start(0); } + #endif } if(!wait_flag) @@ -267,7 +271,7 @@ void *WebConfigMultipartTask(void *status) ts.tv_sec += get_retry_timer(); WebcfgDebug("The retry triggers at %s\n", printTime((long long)ts.tv_sec)); } - + #ifdef WAN_FAILOVER_SUPPORTED if(get_global_wanrestore_sync() == 1) { WebcfgInfo("wanrestore sync detected, trigger force sync with cloud.\n"); @@ -275,7 +279,9 @@ void *WebConfigMultipartTask(void *status) wait_flag = 1; rv = 0; } - else if(retry_flag == 1 || maintenance_doc_sync == 1) + else + #endif + if(retry_flag == 1 || maintenance_doc_sync == 1) { WebcfgDebug("B4 sync_condition pthread_cond_timedwait\n"); set_maintenanceSync(false); @@ -309,12 +315,14 @@ void *WebConfigMultipartTask(void *status) } else if(!rv && !g_shutdown) { + #ifdef WAN_FAILOVER_SUPPORTED if(get_global_wanrestore_sync()) { set_global_wanrestore_sync(0); set_global_wanrestoresync_start(1); WebcfgInfo("wanrestore_sync reset to %d and wanrestoresync_start %d\n", get_global_wanrestore_sync(), get_global_wanrestoresync_start()); } + #endif char *ForceSyncDoc = NULL; char* ForceSyncTransID = NULL; @@ -403,8 +411,10 @@ void *WebConfigMultipartTask(void *status) set_global_retry_timestamp(0); set_retry_timer(0); set_global_supplementarySync(0); + #ifdef WAN_FAILOVER_SUPPORTED set_global_wanrestore_sync(0); set_global_wanrestoresync_start(0); + #endif #ifdef FEATURE_SUPPORT_AKER set_send_aker_flag(false); #endif @@ -505,7 +515,7 @@ int get_global_supplementarySync() { return g_supplementarySync; } - +#ifdef WAN_FAILOVER_SUPPORTED void set_global_wanrestore_sync(int value) { g_wanrestore_sync = value; @@ -525,6 +535,7 @@ int get_global_wanrestoresync_start() { return g_wanrestoresync_start; } +#endif /*----------------------------------------------------------------------------*/ /* Internal functions */ /*----------------------------------------------------------------------------*/ diff --git a/src/webcfg.h b/src/webcfg.h index 0119f2fa..e86d4f76 100644 --- a/src/webcfg.h +++ b/src/webcfg.h @@ -92,10 +92,12 @@ pthread_mutex_t *get_global_sync_mutex(void); pthread_t *get_global_mpThreadId(void); int get_global_supplementarySync(); void set_global_supplementarySync(int value); +#ifdef WAN_FAILOVER_SUPPORTED int get_global_wanrestore_sync(); void set_global_wanrestore_sync(int value); void set_global_wanrestoresync_start(int value); int get_global_wanrestoresync_start(); +#endif void initWebConfigMultipartTask(unsigned long status); void processWebconfgSync(int Status, char* docname); WEBCFG_STATUS webcfg_http_request(char **configData, int r_count, int status, long *code, char **transaction_id,char* contentType, size_t* dataSize, char* docname); diff --git a/src/webcfg_multipart.c b/src/webcfg_multipart.c index 6cbf1b7a..9272f4c1 100644 --- a/src/webcfg_multipart.c +++ b/src/webcfg_multipart.c @@ -1804,8 +1804,19 @@ void createCurlHeader( struct curl_slist *list, struct curl_slist **header_list, uuid_header = (char *) malloc(sizeof(char)*MAX_BUF_SIZE); if(uuid_header !=NULL) { - snprintf(uuid_header, MAX_BUF_SIZE, "Transaction-ID: %s", transaction_uuid); - WebcfgInfo("uuid_header formed %s\n", uuid_header); + #ifdef WAN_FAILOVER_SUPPORTED + if(get_global_wanrestoresync_start()) + { + //To add _wanrestore suffixed transaction_id for wanrestore sync + snprintf(uuid_header, MAX_BUF_SIZE, "Transaction-ID: %s_wanrestore", transaction_uuid); + WebcfgInfo("uuid_header formed for wanfailover sync %s\n", uuid_header); + } + else + #endif + { + snprintf(uuid_header, MAX_BUF_SIZE, "Transaction-ID: %s", transaction_uuid); + WebcfgInfo("uuid_header formed %s\n", uuid_header); + } list = curl_slist_append(list, uuid_header); *trans_uuid = strdup(transaction_uuid); WEBCFG_FREE(transaction_uuid); diff --git a/src/webcfg_rbus.c b/src/webcfg_rbus.c index 9efc83fd..da47eb15 100755 --- a/src/webcfg_rbus.c +++ b/src/webcfg_rbus.c @@ -1634,16 +1634,20 @@ int set_rbus_ForceSync(char* pString, int *pStatus) *pStatus = 1; return 0; } - else if((strlen(ForceSyncTransID)>0) || (get_global_wanrestoresync_start() ==1)) + else if(strlen(ForceSyncTransID)>0) { - if(get_global_wanrestoresync_start()) - { - WebcfgInfo("wanrestoresync is in progress, Ignoring this request.\n"); - } WebcfgInfo("Force sync is already in progress, Ignoring this request.\n"); *pStatus = 1; return 0; } + #ifdef WAN_FAILOVER_SUPPORTED + else if(get_global_wanrestoresync_start() ==1) + { + WebcfgInfo("Wanrestoresync is already in progress, Ignoring this request & will retry later.\n"); + *pStatus = 1; + return 0; + } + #endif else { /* sending signal to initWebConfigMultipartTask to trigger sync */ diff --git a/src/webcfg_wanhandle.c b/src/webcfg_wanhandle.c new file mode 100644 index 00000000..8ff59a6d --- /dev/null +++ b/src/webcfg_wanhandle.c @@ -0,0 +1,23 @@ +/* + * Copyright 2023 Comcast Cable Communications Management, LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* This is a stub file that will be overridden in a patch */ + +#include "webcfg_wanhandle.h" + +void WanEventHandler() +{ +} diff --git a/src/webcfg_wanhandle.h b/src/webcfg_wanhandle.h new file mode 100644 index 00000000..48e9aab7 --- /dev/null +++ b/src/webcfg_wanhandle.h @@ -0,0 +1,18 @@ +/* + * Copyright 2023 Comcast Cable Communications Management, LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +void WanEventHandler(); +#define LOGGING_INTERVAL_SECS ( 60 * 60 ) From 8ae2b3395ec37925c51f243de493aaf39d3bbd07 Mon Sep 17 00:00:00 2001 From: Sadhyama Vengilat Date: Mon, 30 Jan 2023 21:20:48 +0530 Subject: [PATCH 3/5] To use generic functions for both wanrestore and wanstart sync --- src/main.c | 3 +++ src/webcfg.c | 57 ++++++++++++++++-------------------------- src/webcfg.h | 10 +++----- src/webcfg_multipart.c | 8 +++--- src/webcfg_rbus.c | 24 ++++++++---------- src/webcfg_rbus.h | 2 +- 6 files changed, 45 insertions(+), 59 deletions(-) diff --git a/src/main.c b/src/main.c index 6ab47dbc..63d86043 100644 --- a/src/main.c +++ b/src/main.c @@ -24,6 +24,7 @@ #include "webcfg_log.h" #include "webcfg_generic.h" #include "webcfg_rbus.h" +#include "webcfg_wanhandle.h" #include "webcfg_privilege.h" #include #include @@ -80,6 +81,8 @@ int main() snprintf(systemReadyTime, sizeof(systemReadyTime),"%d", (int)cTime.tv_sec); WebcfgInfo("systemReadyTime is %s\n", systemReadyTime); set_global_systemReadyTime(systemReadyTime); + WebcfgInfo("Registering WanEventHandler sysevents\n"); + WanEventHandler(); // wait for upstream subscriber for 5mins waitForUpstreamEventSubscribe(300); #ifdef WAN_FAILOVER_SUPPORTED diff --git a/src/webcfg.c b/src/webcfg.c index c54b3b57..c1c2188d 100644 --- a/src/webcfg.c +++ b/src/webcfg.c @@ -71,10 +71,8 @@ pthread_t* g_mpthreadId; static int g_testfile = 0; #endif static int g_supplementarySync = 0; -#ifdef WAN_FAILOVER_SUPPORTED -static int g_wanrestore_sync = 0; -static int g_wanrestoresync_start = 0; -#endif +static int g_wanstatus_sync = 0; +static int g_wanstatussync_start = 0; /*----------------------------------------------------------------------------*/ /* Function Prototypes */ /*----------------------------------------------------------------------------*/ @@ -184,13 +182,11 @@ void *WebConfigMultipartTask(void *status) } setForceSync("", "", 0); set_global_supplementarySync(0); - #ifdef WAN_FAILOVER_SUPPORTED - if(get_global_wanrestoresync_start()) + if(get_global_wanstatussync_start()) { - WebcfgInfo("reset wanrestore_start\n"); - set_global_wanrestoresync_start(0); + WebcfgInfo("reset wanstatus_start\n"); + set_global_wanstatussync_start(0); } - #endif } if(!wait_flag) @@ -271,17 +267,14 @@ void *WebConfigMultipartTask(void *status) ts.tv_sec += get_retry_timer(); WebcfgDebug("The retry triggers at %s\n", printTime((long long)ts.tv_sec)); } - #ifdef WAN_FAILOVER_SUPPORTED - if(get_global_wanrestore_sync() == 1) + if(get_global_wanstatus_sync() == 1) { - WebcfgInfo("wanrestore sync detected, trigger force sync with cloud.\n"); + WebcfgInfo("wanstatus sync detected, trigger force sync with cloud.\n"); forced_sync = 1; wait_flag = 1; rv = 0; } - else - #endif - if(retry_flag == 1 || maintenance_doc_sync == 1) + else if(retry_flag == 1 || maintenance_doc_sync == 1) { WebcfgDebug("B4 sync_condition pthread_cond_timedwait\n"); set_maintenanceSync(false); @@ -315,14 +308,12 @@ void *WebConfigMultipartTask(void *status) } else if(!rv && !g_shutdown) { - #ifdef WAN_FAILOVER_SUPPORTED - if(get_global_wanrestore_sync()) + if(get_global_wanstatus_sync()) { - set_global_wanrestore_sync(0); - set_global_wanrestoresync_start(1); - WebcfgInfo("wanrestore_sync reset to %d and wanrestoresync_start %d\n", get_global_wanrestore_sync(), get_global_wanrestoresync_start()); + set_global_wanstatus_sync(0); + set_global_wanstatussync_start(1); + WebcfgInfo("wanstatus_sync reset to %d and wanstatussync_start %d\n", get_global_wanstatus_sync(), get_global_wanstatussync_start()); } - #endif char *ForceSyncDoc = NULL; char* ForceSyncTransID = NULL; @@ -411,10 +402,8 @@ void *WebConfigMultipartTask(void *status) set_global_retry_timestamp(0); set_retry_timer(0); set_global_supplementarySync(0); - #ifdef WAN_FAILOVER_SUPPORTED - set_global_wanrestore_sync(0); - set_global_wanrestoresync_start(0); - #endif + set_global_wanstatus_sync(0); + set_global_wanstatussync_start(0); #ifdef FEATURE_SUPPORT_AKER set_send_aker_flag(false); #endif @@ -515,27 +504,25 @@ int get_global_supplementarySync() { return g_supplementarySync; } -#ifdef WAN_FAILOVER_SUPPORTED -void set_global_wanrestore_sync(int value) +void set_global_wanstatus_sync(int value) { - g_wanrestore_sync = value; + g_wanstatus_sync = value; } -int get_global_wanrestore_sync() +int get_global_wanstatus_sync() { - return g_wanrestore_sync; + return g_wanstatus_sync; } -void set_global_wanrestoresync_start(int value) +void set_global_wanstatussync_start(int value) { - g_wanrestoresync_start = value; + g_wanstatussync_start = value; } -int get_global_wanrestoresync_start() +int get_global_wanstatussync_start() { - return g_wanrestoresync_start; + return g_wanstatussync_start; } -#endif /*----------------------------------------------------------------------------*/ /* Internal functions */ /*----------------------------------------------------------------------------*/ diff --git a/src/webcfg.h b/src/webcfg.h index e86d4f76..228fb1c0 100644 --- a/src/webcfg.h +++ b/src/webcfg.h @@ -92,12 +92,10 @@ pthread_mutex_t *get_global_sync_mutex(void); pthread_t *get_global_mpThreadId(void); int get_global_supplementarySync(); void set_global_supplementarySync(int value); -#ifdef WAN_FAILOVER_SUPPORTED -int get_global_wanrestore_sync(); -void set_global_wanrestore_sync(int value); -void set_global_wanrestoresync_start(int value); -int get_global_wanrestoresync_start(); -#endif +int get_global_wanstatus_sync(); +void set_global_wanstatus_sync(int value); +void set_global_wanstatussync_start(int value); +int get_global_wanstatussync_start(); void initWebConfigMultipartTask(unsigned long status); void processWebconfgSync(int Status, char* docname); WEBCFG_STATUS webcfg_http_request(char **configData, int r_count, int status, long *code, char **transaction_id,char* contentType, size_t* dataSize, char* docname); diff --git a/src/webcfg_multipart.c b/src/webcfg_multipart.c index 9272f4c1..30732f90 100644 --- a/src/webcfg_multipart.c +++ b/src/webcfg_multipart.c @@ -1805,11 +1805,11 @@ void createCurlHeader( struct curl_slist *list, struct curl_slist **header_list, if(uuid_header !=NULL) { #ifdef WAN_FAILOVER_SUPPORTED - if(get_global_wanrestoresync_start()) + if(get_global_wanstatussync_start()) { - //To add _wanrestore suffixed transaction_id for wanrestore sync - snprintf(uuid_header, MAX_BUF_SIZE, "Transaction-ID: %s_wanrestore", transaction_uuid); - WebcfgInfo("uuid_header formed for wanfailover sync %s\n", uuid_header); + //To add _wanstatus suffixed transaction_id for wanstatus sync + snprintf(uuid_header, MAX_BUF_SIZE, "Transaction-ID: %s_wanstatus", transaction_uuid); + WebcfgInfo("uuid_header formed for wan status sync %s\n", uuid_header); } else #endif diff --git a/src/webcfg_rbus.c b/src/webcfg_rbus.c index da47eb15..4e78b40a 100755 --- a/src/webcfg_rbus.c +++ b/src/webcfg_rbus.c @@ -1640,14 +1640,12 @@ int set_rbus_ForceSync(char* pString, int *pStatus) *pStatus = 1; return 0; } - #ifdef WAN_FAILOVER_SUPPORTED - else if(get_global_wanrestoresync_start() ==1) + else if(get_global_wanstatussync_start() ==1) { - WebcfgInfo("Wanrestoresync is already in progress, Ignoring this request & will retry later.\n"); + WebcfgInfo("wanstatus sync is already in progress, Ignoring this request & will retry later.\n"); *pStatus = 1; return 0; } - #endif else { /* sending signal to initWebConfigMultipartTask to trigger sync */ @@ -1808,8 +1806,8 @@ static void eventReceiveHandler( if(get_webcfgReady()) { - WebcfgInfo("Trigger force sync with cloud on wan restore\n"); - trigger_wanrestore_forcesync(); + WebcfgInfo("Trigger force sync with cloud on wan restore event\n"); + trigger_wanstatus_forcesync(); } else { @@ -1846,17 +1844,17 @@ int subscribeTo_CurrentActiveInterface_Event() } return rc; } - -//Trigger webconfig resync/force sync with cloud on wan restore value change event -void trigger_wanrestore_forcesync() +#endif +//Trigger webconfig resync/force sync with cloud on wan restore/ wan start events +void trigger_wanstatus_forcesync() { char *str = NULL; int status = 0; str = strdup("root"); - set_global_wanrestore_sync(1); - WebcfgInfo("set wanrestore_sync to %d\n", get_global_wanrestore_sync()); + set_global_wanstatus_sync(1); + WebcfgInfo("set wanstatus_sync to %d\n", get_global_wanstatus_sync()); set_rbus_ForceSync(str, &status); - WebcfgInfo("set_rbus_ForceSync on wan restore done\n"); + WebcfgInfo("set_rbus_ForceSync on wan status event done\n"); } -#endif + diff --git a/src/webcfg_rbus.h b/src/webcfg_rbus.h index 613a41be..b3480a32 100755 --- a/src/webcfg_rbus.h +++ b/src/webcfg_rbus.h @@ -116,6 +116,6 @@ void waitForUpstreamEventSubscribe(int wait_time); webcfgError_t fetchMpBlobData(char *docname, void **blobdata, int *len, uint32_t *etag); #ifdef WAN_FAILOVER_SUPPORTED int subscribeTo_CurrentActiveInterface_Event(); -void trigger_wanrestore_forcesync(); #endif +void trigger_wanstatus_forcesync(); #endif From 3d916218a9eeece3bb7f037fb5b9e8da92c39f2d Mon Sep 17 00:00:00 2001 From: Sadhyama Vengilat Date: Wed, 1 Feb 2023 14:18:31 +0530 Subject: [PATCH 4/5] Add wan handler stub for local pc --- src/CMakeLists.txt | 4 ++-- tests/CMakeLists.txt | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 4009d4bc..e356fb8d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -38,8 +38,8 @@ else() message(STATUS "WAN_FAILOVER_SUPPORTED is not supported") endif (WAN_FAILOVER_SUPPORTED) -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_metadata.h webcfg_timer.h webcfg_privilege.h) -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_blob.c webcfg_event.c webcfg_metadata.c webcfg_timer.c webcfg_privilege.c) +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_metadata.h webcfg_timer.h webcfg_privilege.h webcfg_wanhandle.h) +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_blob.c webcfg_event.c webcfg_metadata.c webcfg_timer.c webcfg_privilege.c webcfg_wanhandle.c) if (FEATURE_SUPPORT_AKER) set(HEADERS ${HEADERS} webcfg_aker.h) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 26bb8275..77556ad9 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -253,7 +253,7 @@ target_link_libraries (test_multipart_unittest gcov -Wl,--no-as-needed ) #------------------------------------------------------------------------------- if (WEBCONFIG_BIN_SUPPORT) add_test(NAME test_rbus_fr COMMAND ${MEMORY_CHECK} ./test_rbus_fr) -add_executable(test_rbus_fr test_rbus_fr.c ../src/webcfg_rbus.c ) +add_executable(test_rbus_fr test_rbus_fr.c ../src/webcfg_rbus.c ../src/webcfg_wanhandle.c) target_link_libraries (test_rbus_fr -lcunit -lwrp-c -lcimplog -lmsgpackc -lcurl -lpthread -lm -luuid -ltrower-base64 -lwdmp-c -lcjson -lrbus) target_link_libraries (test_rbus_fr gcov -Wl,--no-as-needed ) From 298584d2520b0087a6ed44e2dcbd11d42cb22ec2 Mon Sep 17 00:00:00 2001 From: suvi-123 Date: Wed, 14 Jun 2023 19:40:58 +0530 Subject: [PATCH 5/5] Update and test wan upstream with latest master branch --- src/webcfg.c | 45 ------------------------------------------ src/webcfg.h | 5 ----- src/webcfg_multipart.c | 15 ++------------ src/webcfg_rbus.c | 34 ++----------------------------- src/webcfg_rbus.h | 1 - tests/test_rbus_fr.c | 1 - 6 files changed, 4 insertions(+), 97 deletions(-) diff --git a/src/webcfg.c b/src/webcfg.c index 2bf1d2b2..d4855c8e 100644 --- a/src/webcfg.c +++ b/src/webcfg.c @@ -34,7 +34,6 @@ #include "webcfg_event.h" #include "webcfg_blob.h" #include "webcfg_timer.h" -#include "webcfg_rbus.h" #ifdef FEATURE_SUPPORT_AKER #include "webcfg_aker.h" #endif @@ -75,8 +74,6 @@ static int g_testfile = 0; static int g_supplementarySync = 0; static int g_webcfg_forcedsync_needed = 0; static int g_webcfg_forcedsync_started = 0; -static int g_wanstatus_sync = 0; -static int g_wanstatussync_start = 0; /*----------------------------------------------------------------------------*/ /* Function Prototypes */ /*----------------------------------------------------------------------------*/ @@ -191,11 +188,6 @@ void *WebConfigMultipartTask(void *status) WebcfgDebug("reset webcfg_forcedsync_started\n"); set_global_webcfg_forcedsync_started(0); } - if(get_global_wanstatussync_start()) - { - WebcfgInfo("reset wanstatus_start\n"); - set_global_wanstatussync_start(0); - } } if(!wait_flag) @@ -286,14 +278,6 @@ void *WebConfigMultipartTask(void *status) if(get_global_webcfg_forcedsync_needed() == 1) { WebcfgInfo("webcfg_forcedsync detected, trigger force sync with cloud.\n"); - forced_sync = 1; - wait_flag = 1; - rv = 0; - } - if(get_global_wanstatus_sync() == 1) - { - WebcfgInfo("wanstatus sync detected, trigger force sync with cloud.\n"); ->>>>>>> upstream/wan_restore forced_sync = 1; wait_flag = 1; rv = 0; @@ -339,12 +323,6 @@ void *WebConfigMultipartTask(void *status) set_global_webcfg_forcedsync_started(1); WebcfgDebug("webcfg_forcedsync_needed reset to %d and webcfg_forcedsync_started %d\n", get_global_webcfg_forcedsync_needed(), get_global_webcfg_forcedsync_started()); } - if(get_global_wanstatus_sync()) - { - set_global_wanstatus_sync(0); - set_global_wanstatussync_start(1); - WebcfgInfo("wanstatus_sync reset to %d and wanstatussync_start %d\n", get_global_wanstatus_sync(), get_global_wanstatussync_start()); - } char *ForceSyncDoc = NULL; char* ForceSyncTransID = NULL; @@ -438,8 +416,6 @@ void *WebConfigMultipartTask(void *status) set_global_supplementarySync(0); set_global_webcfg_forcedsync_needed(0); set_global_webcfg_forcedsync_started(0); - set_global_wanstatus_sync(0); - set_global_wanstatussync_start(0); #ifdef FEATURE_SUPPORT_AKER set_send_aker_flag(false); #endif @@ -559,27 +535,6 @@ int get_global_webcfg_forcedsync_started() { return g_webcfg_forcedsync_started; } - -void set_global_wanstatus_sync(int value) -{ - g_wanstatus_sync = value; -} - -int get_global_wanstatus_sync() -{ - return g_wanstatus_sync; -} - -void set_global_wanstatussync_start(int value) -{ - g_wanstatussync_start = value; -} - -int get_global_wanstatussync_start() -{ - return g_wanstatussync_start; ->>>>>>> upstream/wan_restore -} /*----------------------------------------------------------------------------*/ /* Internal functions */ /*----------------------------------------------------------------------------*/ diff --git a/src/webcfg.h b/src/webcfg.h index 727e4673..fb6ade92 100644 --- a/src/webcfg.h +++ b/src/webcfg.h @@ -96,11 +96,6 @@ int get_global_webcfg_forcedsync_needed(); void set_global_webcfg_forcedsync_needed(int value); void set_global_webcfg_forcedsync_started(int value); int get_global_webcfg_forcedsync_started(); -int get_global_wanstatus_sync(); -void set_global_wanstatus_sync(int value); -void set_global_wanstatussync_start(int value); -int get_global_wanstatussync_start(); ->>>>>>> upstream/wan_restore void initWebConfigMultipartTask(unsigned long status); void processWebconfgSync(int Status, char* docname); WEBCFG_STATUS webcfg_http_request(char **configData, int r_count, int status, long *code, char **transaction_id,char* contentType, size_t* dataSize, char* docname); diff --git a/src/webcfg_multipart.c b/src/webcfg_multipart.c index 3da34e3a..08b390bf 100644 --- a/src/webcfg_multipart.c +++ b/src/webcfg_multipart.c @@ -1795,19 +1795,8 @@ void createCurlHeader( struct curl_slist *list, struct curl_slist **header_list, uuid_header = (char *) malloc(sizeof(char)*MAX_BUF_SIZE); if(uuid_header !=NULL) { - #ifdef WAN_FAILOVER_SUPPORTED - if(get_global_wanstatussync_start()) - { - //To add _wanstatus suffixed transaction_id for wanstatus sync - snprintf(uuid_header, MAX_BUF_SIZE, "Transaction-ID: %s_wanstatus", transaction_uuid); - WebcfgInfo("uuid_header formed for wan status sync %s\n", uuid_header); - } - else - #endif - { - snprintf(uuid_header, MAX_BUF_SIZE, "Transaction-ID: %s", transaction_uuid); - WebcfgInfo("uuid_header formed %s\n", uuid_header); - } + snprintf(uuid_header, MAX_BUF_SIZE, "Transaction-ID: %s", transaction_uuid); + WebcfgInfo("uuid_header formed %s\n", uuid_header); list = curl_slist_append(list, uuid_header); *trans_uuid = strdup(transaction_uuid); WEBCFG_FREE(uuid_header); diff --git a/src/webcfg_rbus.c b/src/webcfg_rbus.c index b0986400..06953d27 100755 --- a/src/webcfg_rbus.c +++ b/src/webcfg_rbus.c @@ -1926,13 +1926,7 @@ int set_rbus_ForceSync(char* pString, int *pStatus) } else if(get_global_webcfg_forcedsync_started() ==1) { - WebcfgInfo("Webcfg forced sync is in progress, Ignoring this request & will retry later.\n"); - *pStatus = 1; - return 0; - } - else if(get_global_wanstatussync_start() ==1) - { - WebcfgInfo("wanstatus sync is already in progress, Ignoring this request & will retry later.\n"); + WebcfgInfo("Webcfg forced sync is in progress, Ignoring this request & will retry later.\n"); *pStatus = 1; return 0; } @@ -2098,12 +2092,10 @@ static void eventReceiveHandler( } if(newValue !=NULL && oldValue!=NULL && get_global_interface()!=NULL) { WebcfgInfo("New Value: %s Old Value: %s New Interface Value: %s\n", rbusValue_GetString(newValue, NULL), rbusValue_GetString(oldValue, NULL), get_global_interface()); - if(get_webcfgReady()) { - WebcfgInfo("Trigger force sync with cloud on wan restore event\n"); - trigger_wanstatus_forcesync(); + trigger_webcfg_forcedsync(); } else { @@ -2147,7 +2139,6 @@ void trigger_webcfg_forcedsync() { char *str = NULL; int status = 0; - str = strdup("root"); //webcfg_forcedsync_needed is set initially whenever force sync set is detected, but this does not guarantee the force sync to happen immediately when previous sync is in progress, cloud sync will be retried once previous sync is completed. set_global_webcfg_forcedsync_needed(1); @@ -2157,19 +2148,6 @@ void trigger_webcfg_forcedsync() str=NULL; } -//Trigger webconfig resync/force sync with cloud on wan restore/ wan start events -void trigger_wanstatus_forcesync() -{ - char *str = NULL; - int status = 0; - - str = strdup("root"); - set_global_wanstatus_sync(1); - WebcfgInfo("set wanstatus_sync to %d\n", get_global_wanstatus_sync()); - set_rbus_ForceSync(str, &status); - WebcfgInfo("set_rbus_ForceSync on wan status event done\n"); -} - /* Enables rbus ERROR level logs in webconfig. Modify RBUS_LOG_ERROR check if more debug logs are needed from rbus. */ void rbus_log_handler( rbusLogLevel level, @@ -2199,11 +2177,3 @@ void registerRbusLogger() rbus_registerLogHandler(rbus_log_handler); WebcfgDebug("Registered rbus log handler\n"); } -======= - set_global_wanstatus_sync(1); - WebcfgInfo("set wanstatus_sync to %d\n", get_global_wanstatus_sync()); - set_rbus_ForceSync(str, &status); - WebcfgInfo("set_rbus_ForceSync on wan status event done\n"); -} - ->>>>>>> upstream/wan_restore diff --git a/src/webcfg_rbus.h b/src/webcfg_rbus.h index 45e0b61c..8ffd6d07 100755 --- a/src/webcfg_rbus.h +++ b/src/webcfg_rbus.h @@ -121,5 +121,4 @@ webcfgError_t fetchMpBlobData(char *docname, void **blobdata, int *len, uint32_t #ifdef WAN_FAILOVER_SUPPORTED int subscribeTo_CurrentActiveInterface_Event(); #endif -void trigger_wanstatus_forcesync(); #endif diff --git a/tests/test_rbus_fr.c b/tests/test_rbus_fr.c index 56d97217..9af4342f 100644 --- a/tests/test_rbus_fr.c +++ b/tests/test_rbus_fr.c @@ -73,7 +73,6 @@ int get_global_supplementarySync() return 0; } - int Get_Supplementary_URL( char *name, char *pString) { UNUSED(name);