Skip to content

Commit

Permalink
RDKB-51462-Webconfig poke is not working after mqttcm restart
Browse files Browse the repository at this point in the history
  • Loading branch information
nlrcomcast committed Sep 21, 2023
1 parent c37ade8 commit 65b9faa
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 42 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
build
tags

.vscode
# Compiled Object files, Static and Dynamic libs (Shared Objects)
*.o
*.a
Expand Down
31 changes: 4 additions & 27 deletions src/mqttcm_connect.c
Original file line number Diff line number Diff line change
Expand Up @@ -1691,30 +1691,10 @@ int printList()
return 1;
}

int stripAndAddModuleName(char *str, const char *substr, const char *newstr)
{
size_t substrlen = strlen(substr);
char *match;

while ((match = strstr(str, substr)) != NULL)
{
size_t striplen = strlen(match + substrlen);

// Remove the matched substring
memmove(match, match + substrlen, striplen + 1);
}

// Find the position to add the addition
char *end_of_str = str + strlen(str);

// Append the addition to the end of the resulting string
strncat(end_of_str, newstr, strlen(newstr));
return 1;
}

int mqtt_subscribe(char *comp, char *topic)
{
int rc;
char temp_topic[30];
if(topic != NULL && comp !=NULL)
{
int ret = isSubscribeNeeded(comp);
Expand All @@ -1738,12 +1718,9 @@ int mqtt_subscribe(char *comp, char *topic)
if(strcmp (comp, SUBSCRIBE_WEBCONFIG) == 0)
{
int subscribeId;

//Subscribe to wildcard topic "#"
stripAndAddModuleName(topic, SUBSCRIBE_WEBCONFIG, "#");
MqttCMInfo("Subscribing to wildcard topic - %s\n", topic);

rc = mosquitto_subscribe(mosq, &subscribeId, topic, 1);
sprintf(temp_topic,"%s%s/#",MQTT_SUBSCRIBE_TOPIC,Get_Mqtt_ClientId());
MqttCMInfo("Subscribing to wildcard topic - %s\n", temp_topic);
rc = mosquitto_subscribe(mosq, &subscribeId, temp_topic, 1);

if(rc != MOSQ_ERR_SUCCESS)
{
Expand Down
3 changes: 1 addition & 2 deletions src/mqttcm_connect.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
#include <uuid/uuid.h>

#define MQTT_COMPONENT_NAME "mqttConnManager"

#define MQTT_SUBSCRIBE_TOPIC "x/to/"
#define MQTT_CONFIG_FILE "/tmp/.mqttconfig"
#define MOSQ_TLS_VERSION "tlsv1.2"
#define OPENSYNC_CERT "/etc/mqttcm/mqtt_cert_init.sh"
Expand Down Expand Up @@ -141,7 +141,6 @@ void get_interface(char **interface);
pthread_cond_t *get_global_mqtt1_con(void);
pthread_mutex_t *get_global_mqtt1_mut(void);
rbusHandle_t get_global_rbus_handle(void);
int stripAndAddModuleName(char *str, const char *substr, const char *newstr);
void mosquittoTriggerDisconnect();
int get_global_shutdown();
int valueChangeCheck(char *valueStored, char *valueChanged);
Expand Down
12 changes: 0 additions & 12 deletions tests/test_mqttcm_component.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,17 +139,6 @@ void test_printList(void)
CU_ASSERT_EQUAL(result, 1);
}

// Test function for stripAndAddModuleName
void test_stripAndAddModuleName(void)
{
char inputString[] = "This is a test string with module1 and module2.";
const char* substr = "module1";
const char* newstr = "moduleX";

int result = stripAndAddModuleName(inputString, substr, newstr);
CU_ASSERT_EQUAL(result, 1);
}

// Test function for GetTopicFromFileandUpdateList
void test_GetTopicFromFileandUpdateList()
{
Expand Down Expand Up @@ -188,7 +177,6 @@ void add_suites( CU_pSuite *suite )
CU_add_test( *suite, "test UpdateSubscriptionIdToList_Success", test_UpdateSubscriptionIdToList_Success);
CU_add_test( *suite, "test UpdateSubscriptionIdToList_Failure", test_UpdateSubscriptionIdToList_Failure);
CU_add_test( *suite, "test printList", test_printList);
CU_add_test( *suite, "test stripAndAddModuleName", test_stripAndAddModuleName);
CU_add_test( *suite, "test GetTopicFromFileandUpdateList", test_GetTopicFromFileandUpdateList);
CU_add_test( *suite, "test AddSubscribeTopicToFile_success", test_AddSubscribeTopicToFile_success);
CU_add_test( *suite, "test AddSubscribeTopicToFile_failure", test_AddSubscribeTopicToFile_failure);
Expand Down

0 comments on commit 65b9faa

Please sign in to comment.