diff --git a/.gitignore b/.gitignore index fc86604..8800167 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ build tags - +.vscode # Compiled Object files, Static and Dynamic libs (Shared Objects) *.o *.a diff --git a/src/mqttcm_connect.c b/src/mqttcm_connect.c index 0242733..054c92e 100644 --- a/src/mqttcm_connect.c +++ b/src/mqttcm_connect.c @@ -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); @@ -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) { diff --git a/src/mqttcm_connect.h b/src/mqttcm_connect.h index fe84f8b..a3f6425 100644 --- a/src/mqttcm_connect.h +++ b/src/mqttcm_connect.h @@ -43,7 +43,7 @@ #include #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" @@ -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); diff --git a/tests/test_mqttcm_component.c b/tests/test_mqttcm_component.c index d7e8ea7..7514134 100644 --- a/tests/test_mqttcm_component.c +++ b/tests/test_mqttcm_component.c @@ -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() { @@ -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);