Example #1
0
void CallbackQueriesManager::on_new_query(int32 flags, int64 callback_query_id, UserId sender_user_id,
                                          DialogId dialog_id, MessageId message_id, BufferSlice &&data,
                                          int64 chat_instance, string &&game_short_name) {
  if (!dialog_id.is_valid()) {
    LOG(ERROR) << "Receive new callback query in invalid " << dialog_id;
    return;
  }
  if (!sender_user_id.is_valid()) {
    LOG(ERROR) << "Receive new callback query from invalid " << sender_user_id << " in " << dialog_id;
    return;
  }
  LOG_IF(ERROR, !td_->contacts_manager_->have_user(sender_user_id)) << "Have no info about " << sender_user_id;
  if (!td_->auth_manager_->is_bot()) {
    LOG(ERROR) << "Receive new callback query";
    return;
  }
  if (!message_id.is_valid()) {
    LOG(ERROR) << "Receive new callback query from " << message_id << " in " << dialog_id << " sent by "
               << sender_user_id;
    return;
  }

  auto payload = get_query_payload(flags, std::move(data), std::move(game_short_name));
  if (payload == nullptr) {
    return;
  }

  td_->messages_manager_->force_create_dialog(dialog_id, "on_new_callback_query");
  send_closure(
      G()->td(), &Td::send_update,
      make_tl_object<td_api::updateNewCallbackQuery>(
          callback_query_id, td_->contacts_manager_->get_user_id_object(sender_user_id, "updateNewCallbackQuery"),
          dialog_id.get(), message_id.get(), chat_instance, std::move(payload)));
}
void MessageIdMarshallerTest::test() {

    MessageIdMarshaller myMarshaller;
    MessageId myCommand;
    MessageId* myCommand2;

    CPPUNIT_ASSERT( myMarshaller.getDataStructureType() == myCommand.getDataStructureType() );
    myCommand2 = dynamic_cast<MessageId*>( myMarshaller.createObject() );
    CPPUNIT_ASSERT( myCommand2 != NULL );
    delete myCommand2;
}
void MessageIdMarshallerTest::testTightMarshal() {

    MessageIdMarshaller marshaller;
    Properties props;
    OpenWireFormat openWireFormat( props );

    // Configure for this test.
    openWireFormat.setVersion( 9 );
    openWireFormat.setTightEncodingEnabled( true );

    MessageId outCommand;
    MessageId inCommand;

    try {

        // Marshal the dataStructure to a byte array.
        ByteArrayOutputStream baos;
        DataOutputStream dataOut( &baos );
        // Phase 1 - count the size
        int size = 1;
        BooleanStream bs;
        size += marshaller.tightMarshal1( &openWireFormat, &outCommand, &bs );
        size += bs.marshalledSize();
        // Phase 2 - marshal
        dataOut.writeByte( outCommand.getDataStructureType() );
        bs.marshal( &dataOut );
        marshaller.tightMarshal2( &openWireFormat, &outCommand, &dataOut, &bs );

        // Now read it back in and make sure it's all right.
        std::pair<const unsigned char*, int> array = baos.toByteArray();
        ByteArrayInputStream bais( array.first, array.second, true );
        DataInputStream dataIn( &bais );

        unsigned char dataType = dataIn.readByte();
        CPPUNIT_ASSERT( dataType == outCommand.getDataStructureType() );
        bs.clear();
        bs.unmarshal( &dataIn );
        marshaller.tightUnmarshal( &openWireFormat, &inCommand, &dataIn, &bs );

        CPPUNIT_ASSERT( inCommand.equals( (DataStructure*) &outCommand ) == true );

    } catch( ActiveMQException& e ) {
        e.printStackTrace();
        CPPUNIT_ASSERT( false );
    } catch( ... ) {
        CPPUNIT_ASSERT( false );
    }
}
Example #4
0
const Value MessageSelectorEnv::specialValue(const string& id) const
{
    Value v;
    // TODO: Just use a simple if chain for now - improve this later
    if ( id=="delivery_mode" ) {
        v = msg.getEncoding().isPersistent() ? PERSISTENT : NON_PERSISTENT;
    } else if ( id=="redelivered" ) {
        v = msg.getDeliveryCount()>0 ? true : false;
    } else if ( id=="priority" ) {
        v = int64_t(msg.getPriority());
    } else if ( id=="correlation_id" ) {
        MessageId cId = msg.getEncoding().getCorrelationId();
        if (cId) {
            returnedStrings.push_back(new string(cId.str()));
            v = returnedStrings[returnedStrings.size()-1];
        }
    } else if ( id=="message_id" ) {
        MessageId mId = msg.getEncoding().getMessageId();
        if (mId) {
            returnedStrings.push_back(new string(mId.str()));
            v = returnedStrings[returnedStrings.size()-1];
        }
    } else if ( id=="to" ) {
        v = EMPTY; // Hard to get this correct for both 1.0 and 0-10
    } else if ( id=="reply_to" ) {
        v = EMPTY; // Hard to get this correct for both 1.0 and 0-10
    } else if ( id=="absolute_expiry_time" ) {
        qpid::sys::AbsTime expiry = msg.getExpiration();
        // Java property has value of 0 for no expiry
        v = (expiry==qpid::sys::FAR_FUTURE) ? 0
            : qpid::sys::Duration(qpid::sys::AbsTime::Epoch(), expiry) / qpid::sys::TIME_MSEC;
    } else if ( id=="creation_time" ) {
        // Use the time put on queue (if it is enabled) as 0-10 has no standard way to get message
        // creation time and we're not paying attention to the 1.0 creation time yet.
        v = int64_t(msg.getTimestamp() * 1000); // getTimestamp() returns time in seconds we need milliseconds
    } else if ( id=="jms_type" ) {
        // Currently we can't distinguish between an empty JMSType and no JMSType
        // We'll assume for now that setting an empty JMSType doesn't make a lot of sense
        const string jmsType = msg.getAnnotation("jms-type").asString();
        if ( !jmsType.empty() ) {
            returnedStrings.push_back(new string(jmsType));
            v = returnedStrings[returnedStrings.size()-1];
        }
    } else {
        v = Value();
    }
    return v;
}
Example #5
0
BroadcastSm::BroadcastSm(const SequenceNumber &sequence_number,
                         const ServiceType &service_type,
                         const SmeAddress &source_addr,
                         const MessageId &message_id,
                         const PriorityFlag &priority_flag,
                         const Time &schedule_delivery_time,
                         const Time &validity_period,
                         const ReplaceIfPresentFlag &replace_if_present_flag,
                         const DataCoding &data_coding,
                         const SmDefaultMsgId &sm_default_msg_id) :
    TlvsHeader(CommandLength(min_length),
               CommandId(CommandId::BroadcastSm),
               CommandStatus(CommandStatus::ESME_ROK),
               sequence_number),
    service_type(service_type),
    source_addr(source_addr),
    message_id(message_id),
    priority_flag(priority_flag),
    schedule_delivery_time(schedule_delivery_time),
    validity_period(validity_period),
    replace_if_present_flag(replace_if_present_flag),
    data_coding(data_coding),
    sm_default_msg_id(sm_default_msg_id) {
    Header::updateLength(service_type.length() +
                         source_addr.getAddress().length() +
                         message_id.length() +
                         schedule_delivery_time.length() +
                         validity_period.length());
}
Example #6
0
  void send(DialogId dialog_id, MessageId message_id, const tl_object_ptr<td_api::CallbackQueryPayload> &payload,
            int64 result_id) {
    result_id_ = result_id;
    dialog_id_ = dialog_id;

    auto input_peer = td->messages_manager_->get_input_peer(dialog_id, AccessRights::Read);
    CHECK(input_peer != nullptr);

    int32 flags = 0;
    BufferSlice data;
    CHECK(payload != nullptr);
    switch (payload->get_id()) {
      case td_api::callbackQueryPayloadData::ID:
        flags = telegram_api::messages_getBotCallbackAnswer::DATA_MASK;
        data = BufferSlice(static_cast<const td_api::callbackQueryPayloadData *>(payload.get())->data_);
        break;
      case td_api::callbackQueryPayloadGame::ID:
        flags = telegram_api::messages_getBotCallbackAnswer::GAME_MASK;
        break;
      default:
        UNREACHABLE();
    }

    auto net_query = G()->net_query_creator().create(create_storer(telegram_api::messages_getBotCallbackAnswer(
        flags, false /*ignored*/, std::move(input_peer), message_id.get_server_message_id().get(), std::move(data))));
    net_query->need_resend_on_503 = false;
    send_query(std::move(net_query));
  }
Example #7
0
SubmitMultiResp::SubmitMultiResp(const CommandStatus &command_status,
                                 const SequenceNumber &sequence_number,
                                 const MessageId &message_id) :
  TlvsHeader(CommandLength(min_length),
             CommandId(CommandId::SubmitMultiResp),
             command_status,
             sequence_number),
  message_id(message_id) {
  Header::updateLength(message_id.length());
}
Example #8
0
 /// @brief Sets the message id.
 /// @param p The message id.
 void message_id(const Smpp::Char* p) {
     int diff = strlen(p) - message_id_.length();
     message_id_ = p;
     Header::update_length(diff);
 }
Example #9
0
 /// @brief Sets the message id.
 /// @param p The message id.
 void message_id(const MessageId& p) {
     int diff = p.length() - message_id_.length();
     message_id_ = p;
     Header::update_length(diff);
 }
void ContactMessageAcknowledgmentProcessor::addMessage(MessageId const& addedMessageId) {
	if (!(messageId == addedMessageId)) {
		throw IllegalArgumentException() << "Tried adding Message ID " << addedMessageId.toString() << " to ContactMessageAcknowledgmentProcessor built for Message ID " << messageId.toString() << ".";
	}
}
Example #11
0
uint qHash(MessageId const& key, uint seed) {
	return qHash(key.getMessageId(), seed);
}
/*
   send ReplicationStartReqMsg
   if send error delete self
   wait for ReplicationStartReplyMsg as follows
      loop until reply is received
          on receive error or peerNode dies, delete self
   get filtered list of messages to replicate
   for all messages to send, loop
       if clear to send
          send next message
          if send error, delete self
       else wait for clear to send (watch out for deadPeer?)
    all done delete self

    note: deleting self signals thread's parent to terminate this thread
          go through the list of successfully send and ack'd?
          and possibly queue up another session?
              
*/
void TargetBasedReplicationController::ReplicationSessionThread::run (void)
{
    int rc;
    const char *pszMethod = "TargetBasedReplicationController::ReplicationSessionThread::run";

    // First - send the ReplicationStartReqMsg
    ReplicationStartReqMsg rsrm (_localNodeID, _targetNodeID, TargetBasedReplicationController::CONTROLLER_TYPE, TargetBasedReplicationController::CONTROLLER_VERSION, _bCheckTargetForMsgs, _bRequireAcks);

    if (_pTBRepCtlr->transmitCtrlToCtrlMessage (&rsrm, "TargetBasedReplicationController: sending ReplicationStartReqMsg") != 0) {
        checkAndLogMsg (pszMethod, Logger::L_MildError,
                        "transmission of ReplicationStartReqMsg failed - terminating replication session\n");
        _pTBRepCtlr->addTerminatingReplicator (this);
        setTerminatingResultCode (-1);
        terminating();
        return;
    }
    else {
        checkAndLogMsg (pszMethod, Logger::L_Info,
                        "transmitted ReplicationStartReqMsg to target node %s\n",
                        (const char*) _targetNodeID);
    }

    // Wait for the ReplicationStartReplyMsg
    _m.lock();
    while (!_bReplicating) {
        if (terminationRequested()) {
            _pTBRepCtlr->addTerminatingReplicator (this);
            setTerminatingResultCode (-2);
            terminating();
            _m.unlock();
            return;
        }
        else if (_bTargetDead) {
            checkAndLogMsg (pszMethod, Logger::L_Warning,
                            "target node %s died while waiting for the ReplicationStartReplyMsg\n",
                            (const char*) _targetNodeID);
            _pTBRepCtlr->addTerminatingReplicator (this);
            setTerminatingResultCode (-3);
            terminating();
            _m.unlock();
            return;
        }
        _cv.wait (1000);
    }
    _m.unlock();

    // Ready to replicate messages at this point
    if ((_pMsgsToExclude != NULL) && (_pMsgsToExclude->getCount() > 0)) {
        checkAndLogMsg (pszMethod, Logger::L_Info,
                        "adding constraint to exclude messages previously received by node %s\n", (const char*) _targetNodeID);
    }

    int64 i64QueryStartTime = getTimeInMilliseconds();
    PtrLList<MessageId> *pMsgIds = _pTBRepCtlr->_pDataCacheInterface->getNotReplicatedMsgList (_targetNodeID, 0, _pMsgsToExclude);
    if (pMsgIds != NULL) {
        checkAndLogMsg (pszMethod, Logger::L_Info,
                        "identified %lu messages to replicate to node %s - query time %lu ms\n",
                        (uint32) pMsgIds->getCount(), (const char*) _targetNodeID, (uint32) (getTimeInMilliseconds() - i64QueryStartTime));
        for (MessageId *pMIdTemp = pMsgIds->getFirst(); pMIdTemp; pMIdTemp = pMsgIds->getNext()) {
            // Check for termination
            if (terminationRequested()) {
                setTerminatingResultCode (-4);
                break;
            }

            // Check Flow Control and target peer death
            int64 i64PauseStartTime = 0;
            while ((!_bTargetDead) && (!_pTBRepCtlr->clearToSendOnAllInterfaces())) {
                if (i64PauseStartTime == 0) {
                    i64PauseStartTime = getTimeInMilliseconds();
                }
                sleepForMilliseconds (100);
            }
            if (_bTargetDead) {
                checkAndLogMsg (pszMethod, Logger::L_Warning,
                                "target %s died while replicating messages\n",
                                (const char*) _targetNodeID);
                setTerminatingResultCode (-5);
                break;
            }
            if (i64PauseStartTime != 0) {
                checkAndLogMsg (pszMethod, Logger::L_Info,
                                "paused replication for %lu ms because it was not clear to send\n",
                                (uint32) (getTimeInMilliseconds() - i64PauseStartTime));
            }

            // Replicate one message
            if (0 != (rc = _pTBRepCtlr->replicateMessage (pMIdTemp->getId(), _targetNodeID, 2000))) {
                checkAndLogMsg (pszMethod, Logger::L_Warning,
                                "replicateMessage() failed for message <%s> to target node <%s>; rc = %d\n",
                                pMIdTemp->getId(), (const char*) _targetNodeID, rc);
            }
            else if (!_bRequireAcks) {
                // Assume that the message has been successfully replicated
                _pTBRepCtlr->_pTransmissionHistory->addMessageTarget (pMIdTemp->getId(), _localNodeID);
                checkAndLogMsg (pszMethod, Logger::L_LowDetailDebug,
                                "replicated message %s to destination node %s\n",
                                pMIdTemp->getId(), (const char *) _localNodeID);
            }
        }
    }
    delete pMsgIds;
    _pTBRepCtlr->releaseQueryResults();

    // Send the ReplicationEnd message
    if (_bTargetDead) {
            checkAndLogMsg (pszMethod, Logger::L_MildError,
                            "not sending replication end message because target node %s is dead\n",
                            (const char *) _targetNodeID);
    }
    else {
        ReplicationEndMsg rem (_localNodeID, _targetNodeID, TargetBasedReplicationController::CONTROLLER_TYPE, TargetBasedReplicationController::CONTROLLER_VERSION);
        if (0 != (rc = _pTBRepCtlr->transmitCtrlToCtrlMessage (&rem, "replication end message"))) {
            checkAndLogMsg (pszMethod, Logger::L_MildError,
                            "failed to send replication end message; rc = %d\n", rc);
        }
        else {
            checkAndLogMsg (pszMethod, Logger::L_Info,
                            "completed replication session with target node %s\n",
                            (const char *) _targetNodeID);
        }
    }

    _pTBRepCtlr->addTerminatingReplicator (this);
    terminating();
}