int deliverMessage(Client* c, MQTTString* topicName, MQTTMessage* message)
{
    int i;
    int rc = FAILURE;

    // we have to find the right message handler - indexed by topic
    for (i = 0; i < MAX_MESSAGE_HANDLERS; ++i)
    {
        if (c->messageHandlers[i].topicFilter != 0 && (MQTTPacket_equals(topicName, (char*)c->messageHandlers[i].topicFilter) ||
                isTopicMatched((char*)c->messageHandlers[i].topicFilter, topicName)))
        {
            if (c->messageHandlers[i].fp != NULL)
            {
                MessageData md;
                NewMessageData(&md, topicName, message, c->messageHandlers[i].applicationHandler);
                c->messageHandlers[i].fp(&md);
                rc = SUCCESS;
            }
        }
    }
    
    if (rc == FAILURE && c->defaultMessageHandler != NULL) 
    {
        MessageData md;
        NewMessageData(&md, topicName, message, NULL);
        c->defaultMessageHandler(&md);
        rc = SUCCESS;
    }   
    
    return rc;
}
Exemple #2
0
static int mqttClient_deliverMsg(mqttClient_t* clientData, MQTTString* topicName, mqttClient_msg_t* message)
{
  int i;
  int rc = LE_OK;

  LE_ASSERT(clientData);
  LE_ASSERT(topicName);
  LE_ASSERT(message);

  for (i = 0; i < MQTT_CLIENT_MAX_MESSAGE_HANDLERS; ++i)
  {
    if ((clientData->msgHndlrs[i].topicFilter != 0) && 
        (MQTTPacket_equals(topicName, (char*)clientData->msgHndlrs[i].topicFilter) || 
         mqttClient_isTopicMatched((char*)clientData->msgHndlrs[i].topicFilter, topicName)))
    {
      if (clientData->msgHndlrs[i].fp != NULL)
      {
        mqttClient_msg_data_t msgData;
        mqttClient_newMsgData(&msgData, topicName, message);
        clientData->msgHndlrs[i].fp(&msgData);
        goto cleanup;
      }
    }
  }
    
  mqttClient_msg_data_t msgData;
  mqttClient_newMsgData(&msgData, topicName, message);
  clientData->defaultMsgHndlr(&msgData);
   
cleanup:    
  return rc;
}