modify:oc_mqtt:filter the same topic when do selftopic subscribe
@@ -945,17 +945,34 @@ static int deal_api_subscribe( oc_mqtt_tiny_cb_t *cb, oc_mqtt_daemon_cmd_t *cmd
else if(((int)en_daemon_status_hub_keep == cb->flag.bits.bit_daemon_status) &&\
(en_mqtt_al_connect_ok == mqtt_al_check_status(cb->mqtt_para.mqtt_handle)))
{
+ ///< checkif the topic has been subscribe
+ topic_sub = cb->subscribe_lst;
+ while(NULL != topic_sub)
+ {
+ if(0 == strcmp(topic_sub->topic, subpara->topic.data))
+ {
+ break;
+ }
+ topic_sub = topic_sub->nxt;
+ }
+ if(NULL != topic_sub) ///< THERE HAS BEEN ONE
+ {
+ LINK_LOG_DEBUG("RESUBSCRIBED THE SAME TOPIC");
+ ret = (int)en_oc_mqtt_err_subscribe;
+ }
+ else
+ {
topic_sub = osal_malloc( sizeof( tiny_topic_sub_t ) + subpara->topic.len + 1 );
if ( NULL != topic_sub)
{
- ///< initialize the subtopic add it to the subscribe list
+ ///< initialize the subtopic and add it to the subscribe list when success
topic_sub->qos = (int) subpara->qos;
topic_sub->topic = (char *)topic_sub + sizeof(tiny_topic_sub_t);
(void) strncpy(topic_sub->topic, subpara->topic.data,subpara->topic.len);
topic_sub->topic[subpara->topic.len] = '\0';
- ///< copy the old parameters to the new one, for we could not change the user'd memory
+ ///< copy the old parameters to the new one, for we could not change the user's memory
(void)memset(&sub_new,0,sizeof(sub_new));
sub_new.arg = cb;
sub_new.dealer = hub_msg_default_deal;
@@ -981,6 +998,7 @@ static int deal_api_subscribe( oc_mqtt_tiny_cb_t *cb, oc_mqtt_daemon_cmd_t *cmd
ret = (int)en_oc_mqtt_err_sysmem;
}
}
+ }
else
{
ret = (int)en_oc_mqtt_err_noconected;
