TEST_F(DriverConductorNetworkTest, shouldKeepSubscriptionMediaEndpointUponRemovalOfAllButOneSubscriber) { int64_t client_id = nextCorrelationId(); int64_t sub_id_1 = nextCorrelationId(); int64_t sub_id_2 = nextCorrelationId(); int64_t sub_id_3 = nextCorrelationId(); int64_t sub_id_4 = nextCorrelationId(); ASSERT_EQ(addNetworkSubscription(client_id, sub_id_1, CHANNEL_1, STREAM_ID_1, -1), 0); ASSERT_EQ(addNetworkSubscription(client_id, sub_id_2, CHANNEL_1, STREAM_ID_2, -1), 0); ASSERT_EQ(addNetworkSubscription(client_id, sub_id_3, CHANNEL_1, STREAM_ID_3, -1), 0); ASSERT_EQ(addNetworkSubscription(client_id, sub_id_4, CHANNEL_1, STREAM_ID_4, -1), 0); doWork(); int64_t remove_correlation_id_1 = nextCorrelationId(); int64_t remove_correlation_id_2 = nextCorrelationId(); int64_t remove_correlation_id_3 = nextCorrelationId(); ASSERT_EQ(removeSubscription(client_id, remove_correlation_id_1, sub_id_1), 0); ASSERT_EQ(removeSubscription(client_id, remove_correlation_id_2, sub_id_2), 0); ASSERT_EQ(removeSubscription(client_id, remove_correlation_id_3, sub_id_3), 0); doWork(); aeron_receive_channel_endpoint_t *endpoint = aeron_driver_conductor_find_receive_channel_endpoint( &m_conductor.m_conductor, CHANNEL_1); ASSERT_NE(endpoint, (aeron_receive_channel_endpoint_t *)NULL); ASSERT_EQ(aeron_driver_conductor_num_receive_channel_endpoints(&m_conductor.m_conductor), 1u); ASSERT_EQ(aeron_driver_conductor_num_network_subscriptions(&m_conductor.m_conductor), 1u); EXPECT_EQ(readAllBroadcastsFromConductor(null_handler), 7u); }
int main(int argc, char** argv) { CIMClient client; CIMListener listener(listenerPort); receivedIndications = 0; mut = new Mutex(); EmbeddedInstanceIndicationConsumer consumer1; listener.addConsumer(&consumer1); listener.start(); try { client.connectLocal(); } catch (...) { printf("Embedded Test Failed: Could not connect to server\n"); return -1; } int ret = 0; ret = createSubscription(client); if (ret == 0) ret = createErrorInstance(client); errorPropList.append("errorKey"); errorPropList.append("EmbeddedInst"); if (ret == 0) ret = retrieveErrorInstance(client); if (ret == 0) ret = signalIndication(client); if (ret == 0) ret = retrieveIndicationInstance(client); if (ret == 0) ret = removeErrorInstance(client); if (ret == 0) ret = removeSubscription(client); else { removeErrorInstance(client); removeSubscription(client); } listener.removeConsumer(&consumer1); listener.stop(); if (ret == 0) printf("+++EmbeddedInstanceTest passed+++\n"); delete mut; return ret; }
TEST_F(DriverConductorNetworkTest, shouldRemoveSubscriptionAfterImageTimeout) { int64_t client_id = nextCorrelationId(); int64_t sub_id = nextCorrelationId(); int64_t remove_correlation_id = nextCorrelationId(); ASSERT_EQ(addNetworkSubscription(client_id, sub_id, CHANNEL_1, STREAM_ID_1, -1), 0); doWork(); aeron_receive_channel_endpoint_t *endpoint = aeron_driver_conductor_find_receive_channel_endpoint( &m_conductor.m_conductor, CHANNEL_1); createPublicationImage(endpoint, STREAM_ID_1, 1000); int64_t timeout = m_context.m_context->image_liveness_timeout_ns + (m_context.m_context->client_liveness_timeout_ns * 2); doWorkUntilTimeNs( timeout, 100, [&]() { clientKeepalive(client_id); }); EXPECT_EQ(readAllBroadcastsFromConductor(null_handler), 3u); EXPECT_EQ(aeron_driver_conductor_num_images(&m_conductor.m_conductor), 0u); EXPECT_EQ(aeron_driver_conductor_num_active_network_subscriptions(&m_conductor.m_conductor, CHANNEL_1, STREAM_ID_1), 0u); ASSERT_EQ(removeSubscription(client_id, remove_correlation_id, sub_id), 0); doWork(); doWork(); EXPECT_EQ(aeron_driver_conductor_num_network_subscriptions(&m_conductor.m_conductor), 0u); }
TEST_F(DriverConductorNetworkTest, shouldRemoveSubscriptionFromImageWhenRemoveSubscription) { int64_t client_id = nextCorrelationId(); int64_t sub_id = nextCorrelationId(); ASSERT_EQ(addNetworkSubscription(client_id, sub_id, CHANNEL_1, STREAM_ID_1, -1), 0); doWork(); EXPECT_EQ(readAllBroadcastsFromConductor(null_handler), 1u); aeron_receive_channel_endpoint_t *endpoint = aeron_driver_conductor_find_receive_channel_endpoint( &m_conductor.m_conductor, CHANNEL_1); createPublicationImage(endpoint, STREAM_ID_1, 1000); EXPECT_EQ(aeron_driver_conductor_num_images(&m_conductor.m_conductor), 1u); aeron_publication_image_t *image = aeron_driver_conductor_find_publication_image(&m_conductor.m_conductor, endpoint, STREAM_ID_1); EXPECT_NE(image, (aeron_publication_image_t *)NULL); EXPECT_EQ(aeron_publication_image_num_subscriptions(image), 1u); int64_t remove_correlation_id = nextCorrelationId(); ASSERT_EQ(removeSubscription(client_id, remove_correlation_id, sub_id), 0); doWork(); EXPECT_EQ(aeron_publication_image_num_subscriptions(image), 0u); EXPECT_EQ(readAllBroadcastsFromConductor(null_handler), 2u); }
TEST_F(DriverConductorNetworkTest, shouldBeAbleToTimeoutReceiveChannelEndpointWithClientKeepaliveAfterRemoveSubscription) { int64_t client_id = nextCorrelationId(); int64_t sub_id = nextCorrelationId(); int64_t remove_correlation_id = nextCorrelationId(); ASSERT_EQ(addNetworkSubscription(client_id, sub_id, CHANNEL_1, STREAM_ID_1, false), 0); doWork(); EXPECT_EQ(aeron_driver_conductor_num_network_subscriptions(&m_conductor.m_conductor), 1u); ASSERT_EQ(removeSubscription(client_id, remove_correlation_id, sub_id), 0); doWork(); EXPECT_EQ(readAllBroadcastsFromConductor(null_handler), 2u); int64_t timeout = m_context.m_context->client_liveness_timeout_ns; doWorkUntilTimeNs( timeout, 100, [&]() { clientKeepalive(client_id); }); EXPECT_EQ(aeron_driver_conductor_num_clients(&m_conductor.m_conductor), 1u); EXPECT_EQ(aeron_driver_conductor_num_network_subscriptions(&m_conductor.m_conductor), 0u); EXPECT_EQ(aeron_driver_conductor_num_receive_channel_endpoints(&m_conductor.m_conductor), 0u); }
TEST_F(DriverConductorNetworkTest, shouldBeAbleToAddAndRemoveSingleNetworkSubscription) { int64_t client_id = nextCorrelationId(); int64_t sub_id = nextCorrelationId(); int64_t remove_correlation_id = nextCorrelationId(); ASSERT_EQ(addNetworkSubscription(client_id, sub_id, CHANNEL_1, STREAM_ID_1, -1), 0); doWork(); EXPECT_EQ(aeron_driver_conductor_num_network_subscriptions(&m_conductor.m_conductor), 1u); EXPECT_EQ(readAllBroadcastsFromConductor(null_handler), 1u); ASSERT_EQ(removeSubscription(client_id, remove_correlation_id, sub_id), 0); doWork(); auto handler = [&](std::int32_t msgTypeId, AtomicBuffer& buffer, util::index_t offset, util::index_t length) { ASSERT_EQ(msgTypeId, AERON_RESPONSE_ON_OPERATION_SUCCESS); const command::OperationSucceededFlyweight response(buffer, offset); EXPECT_EQ(response.correlationId(), remove_correlation_id); }; EXPECT_EQ(aeron_driver_conductor_num_network_subscriptions(&m_conductor.m_conductor), 0u); EXPECT_EQ(readAllBroadcastsFromConductor(handler), 1u); }
static void doLog(struct Log* genericLog, enum Log_Level logLevel, const char* fullFilePath, uint32_t line, const char* format, va_list args) { struct AdminLog* log = (struct AdminLog*) genericLog; Dict* message = NULL; #define ALLOC_BUFFER_SZ 4096 uint8_t allocBuffer[ALLOC_BUFFER_SZ]; for (int i = 0; i < (int)log->subscriptionCount; i++) { if (isMatch(&log->subscriptions[i], log, logLevel, fullFilePath, line)) { if (!message) { struct Allocator* alloc = BufferAllocator_new(allocBuffer, ALLOC_BUFFER_SZ); message = makeLogMessage(&log->subscriptions[i], log, logLevel, fullFilePath, line, format, args, alloc); } int ret = Admin_sendMessage(message, log->subscriptions[i].txid, log->admin); if (ret) { removeSubscription(log, &log->subscriptions[i]); } } } }
bool TraCIServer::addObjectVariableSubscription(const int commandId, const bool hasContext) { const SUMOTime beginTime = myInputStorage.readInt(); const SUMOTime endTime = myInputStorage.readInt(); const std::string id = myInputStorage.readString(); const int domain = hasContext ? myInputStorage.readUnsignedByte() : 0; const SUMOReal range = hasContext ? myInputStorage.readDouble() : 0.; const int num = myInputStorage.readUnsignedByte(); std::vector<int> variables; std::vector<std::vector<unsigned char> > parameters; for (int i = 0; i < num; ++i) { const int varID = myInputStorage.readUnsignedByte(); variables.push_back(varID); parameters.push_back(std::vector<unsigned char>()); for (int j = 0; j < myParameterSizes[varID]; j++) { parameters.back().push_back(myInputStorage.readChar()); } } // check subscribe/unsubscribe if (variables.size() == 0) { removeSubscription(commandId, id, -1); return true; } // process subscription Subscription s(commandId, id, variables, parameters, beginTime, endTime, hasContext, domain, range); initialiseSubscription(s); return true; }
int Context::unsubscribeDetail(const String& sKey) { int ok = 1; ok = removeSubscription(sKey); return ok; }
static void teardown(void) { removeSubscription(); *running = false; THREAD_JOIN(server_thread); UA_Server_run_shutdown(server); UA_Boolean_delete(running); UA_Server_delete(server); UA_ServerConfig_delete(config); UA_Array_delete(selectClauses, nSelectClauses, &UA_TYPES[UA_TYPES_SIMPLEATTRIBUTEOPERAND]); UA_Client_disconnect(client); UA_Client_delete(client); }
TEST_F(DriverConductorNetworkTest, shouldErrorOnRemoveSubscriptionOnUnknownRegistrationId) { int64_t client_id = nextCorrelationId(); int64_t sub_id = nextCorrelationId(); int64_t remove_correlation_id = nextCorrelationId(); ASSERT_EQ(removeSubscription(client_id, remove_correlation_id, sub_id), 0); doWork(); auto handler = [&](std::int32_t msgTypeId, AtomicBuffer& buffer, util::index_t offset, util::index_t length) { ASSERT_EQ(msgTypeId, AERON_RESPONSE_ON_ERROR); const command::ErrorResponseFlyweight response(buffer, offset); EXPECT_EQ(response.offendingCommandCorrelationId(), remove_correlation_id); }; EXPECT_EQ(readAllBroadcastsFromConductor(handler), 1u); }
bool TraCIServer::addObjectVariableSubscription(int commandId) { SUMOTime beginTime = myInputStorage.readInt(); SUMOTime endTime = myInputStorage.readInt(); std::string id = myInputStorage.readString(); int no = myInputStorage.readUnsignedByte(); std::vector<int> variables; for (int i = 0; i < no; ++i) { variables.push_back(myInputStorage.readUnsignedByte()); } // check subscribe/unsubscribe if (variables.size() == 0) { removeSubscription(commandId, id, -1); return true; } // process subscription Subscription s(commandId, id, variables, beginTime, endTime, false, 0, 0); initialiseSubscription(s); return true; }
bool TraCIServer::addObjectContextSubscription(int commandId) { SUMOTime beginTime = myInputStorage.readInt(); SUMOTime endTime = myInputStorage.readInt(); std::string id = myInputStorage.readString(); int domain = myInputStorage.readUnsignedByte(); SUMOReal range = myInputStorage.readDouble(); int no = myInputStorage.readUnsignedByte(); std::vector<int> variables; for (int i = 0; i < no; ++i) { variables.push_back(myInputStorage.readUnsignedByte()); } // check subscribe/unsubscribe if (variables.size() == 0) { removeSubscription(commandId, id, -1); return true; } Subscription s(commandId, id, variables, beginTime, endTime, true, domain, range); initialiseSubscription(s); return true; }
static void unsubscribe(Dict* args, void* vcontext, String* txid) { struct AdminLog* log = (struct AdminLog*) vcontext; String* streamIdHex = Dict_getString(args, String_CONST("streamId")); uint8_t streamId[8]; char* error = NULL; if (streamIdHex->len != 16 || Hex_decode(streamId, 8, (uint8_t*)streamIdHex->bytes, 16) != 8) { error = "Invalid streamId."; } else { error = "No such subscription."; for (int i = 0; i < (int)log->subscriptionCount; i++) { if (!Bits_memcmp(streamId, log->subscriptions[i].streamId, 8)) { removeSubscription(log, &log->subscriptions[i]); error = "none"; break; } } } Dict response = Dict_CONST( String_CONST("error"), String_OBJ(String_CONST(error)), NULL ); Admin_sendMessage(&response, txid, log->admin); }
//functions UtlBoolean SubscribeServerThread::handleMessage(OsMsg& eventMessage) { // Only handle SIP messages if (eventMessage.getMsgType() != OsMsg::PHONE_APP || eventMessage.getMsgSubType() != SipMessage::NET_SIP_MESSAGE) { return FALSE ; } const SipMessage* message = ((SipMessageEvent&)eventMessage).getMessage(); UtlString userKey; UtlString uri; SipMessage finalResponse; // Test for request/response processing code path if (!message->isResponse()) { // this is a request, so authenticate and authorize the request if ( isValidDomain( message, &finalResponse ) ) { UtlString eventPackage; UtlString id; UtlHashMap otherParams; message->getEventField(&eventPackage, &id, &otherParams); StatusPluginReference* pluginContainer = mPluginTable->getPlugin( eventPackage ); if( pluginContainer ) { //check in credential database if authentication needed UtlString authenticatedUser, authenticatedRealm; if( isAuthenticated ( message, &finalResponse, authenticatedUser, authenticatedRealm ) ) { if ( isAuthorized ( message, &finalResponse, pluginContainer ) ) { // fetch the plugin SubscribeServerPluginBase* plugin = pluginContainer->getPlugin(); if (plugin) { int timeNow = (int)OsDateTime::getSecsSinceEpoch(); int grantedExpiration; UtlString newToTag; // add the subscription to the IMDB SubscribeStatus isSubscriptionAdded = addSubscription(timeNow, message, mDefaultDomain, eventPackage, id, otherParams, newToTag, grantedExpiration); otherParams.destroyAll(); switch ( isSubscriptionAdded ) { case STATUS_SUCCESS: // create response - 202 Accepted Response finalResponse.setResponseData( message, SIP_ACCEPTED_CODE, SIP_ACCEPTED_TEXT); // Set the granted subscription time. finalResponse.setExpiresField(grantedExpiration); plugin->handleSubscribeRequest( *message, finalResponse, authenticatedUser.data(), authenticatedRealm.data(), mDefaultDomain.data()); // ensure that the contact returned will route back to here // (the default supplied by SipUserAgent will not). { UtlString requestUri; message->getRequestUri(&requestUri); finalResponse.setContactField(requestUri); } break; case STATUS_TO_BE_REMOVED: // create response - 202 Accepted Response finalResponse.setResponseData( message, SIP_ACCEPTED_CODE, SIP_ACCEPTED_TEXT); // Set the granted subscription time. finalResponse.setExpiresField(grantedExpiration); plugin->handleSubscribeRequest( *message, finalResponse, authenticatedUser.data(), authenticatedRealm.data(), mDefaultDomain.data()); // ensure that the contact returned will route back to here // (the default supplied by SipUserAgent will not). { UtlString requestUri; message->getRequestUri(&requestUri); finalResponse.setContactField(requestUri); } // Now that final NOTIFY has been sent, remove row removeSubscription(message); break; case STATUS_LESS_THAN_MINEXPIRES: // (already logged in addSubscription) // send 423 Subscription Too Brief response finalResponse.setResponseData( message, SIP_TOO_BRIEF_CODE, SIP_TOO_BRIEF_TEXT ); finalResponse.setHeaderValue( SIP_MIN_EXPIRES_FIELD, mMinExpiresTimeStr, 0 ); break; case STATUS_INVALID_REQUEST: OsSysLog::add(FAC_SIP, PRI_ERR, "SubscribeServerThread::handleMessage()" "Subscription Could Not Be Added " SIP_BAD_REQUEST_TEXT ); finalResponse.setResponseData( message, SIP_BAD_REQUEST_CODE, SIP_BAD_REQUEST_TEXT ); break; case STATUS_FORBIDDEN: OsSysLog::add(FAC_SIP, PRI_ERR, "SubscribeServerThread::handleMessage()" "Subscription Could Not Be Added " SIP_FORBIDDEN_TEXT ); finalResponse.setResponseData( message, SIP_FORBIDDEN_CODE, SIP_FORBIDDEN_TEXT); break; case STATUS_NOT_FOUND: OsSysLog::add(FAC_SIP, PRI_ERR, "SubscribeServerThread::handleMessage()" "Subscription Could Not Be Added " SIP_NOT_FOUND_TEXT ); finalResponse.setResponseData( message, SIP_NOT_FOUND_CODE, SIP_NOT_FOUND_TEXT ); break; case STATUS_BAD_SUBSCRIPTION: // send 481 Subscription Does Not Exist response OsSysLog::add(FAC_SIP, PRI_DEBUG, "SubscribeServerThread::handleMessage()" "Subscription to be renewed does not exist " SIP_BAD_SUBSCRIPTION_TEXT ); finalResponse.setResponseData( message, SIP_BAD_SUBSCRIPTION_CODE, SIP_BAD_SUBSCRIPTION_TEXT ); break; case STATUS_INTERNAL_ERROR: default: OsSysLog::add(FAC_SIP, PRI_ERR, "SubscribeServerThread::handleMessage()" "Subscription Could Not Be Added " "Status %d from addSubscription", isSubscriptionAdded ); finalResponse.setResponseData( message, SIP_SERVER_INTERNAL_ERROR_CODE, "Subscription database error" ); } // Apply the new to-tag, if any, to the response. if (!newToTag.isNull()) { finalResponse.setToFieldTag(newToTag); } } else { OsSysLog::add(FAC_SIP, PRI_CRIT, "SubscribeServerThread::handleMessage()" " container->getPlugin failed for '%s'", eventPackage.data() ); finalResponse.setResponseData( message, SIP_SERVER_INTERNAL_ERROR_CODE, SIP_SERVER_INTERNAL_ERROR_TEXT ); } } else { // not authorized - the response was created in isAuthorized } } else { // not authenticated - the response was created in isAuthenticated } } else // no plugin found for this event type { OsSysLog::add(FAC_SIP, PRI_WARNING, "SubscribeServerThread::handleMessage()" " Request denied - " SIP_BAD_EVENT_TEXT ); finalResponse.setResponseData( message, SIP_BAD_EVENT_CODE, "Event type not supported" ); } // send final response UtlString finalMessageStr; ssize_t finalMessageLen; finalResponse.getBytes(&finalMessageStr, &finalMessageLen); OsSysLog::add(FAC_SIP, PRI_DEBUG, "\n----------------------------------\n" "Sending final response\n%s",finalMessageStr.data()); mpSipUserAgent->setUserAgentHeader( finalResponse ); mpSipUserAgent->send( finalResponse ); } else // Invalid domain { const char* notFoundMsg = SIP_NOT_FOUND_TEXT " Invalid Domain"; finalResponse.setResponseData(message, SIP_NOT_FOUND_CODE, notFoundMsg ); mpSipUserAgent->setUserAgentHeader( finalResponse ); mpSipUserAgent->send( finalResponse ); } } else // response { // The server may send us back a "481" response, if it does we need // to remove the subscription from the SubscriptionDB as the callid // that it corresponds to is stale (probably the phone was rebooted) // In the above case, RFC 3265 says we MUST remove the subscription. // It also says (essentially) that any error that does not imply a retry // SHOULD remove the subscription. We will interpret this to be any // 4xx code _except_ 408 timeout (because that may be a transient error). int responseCode = message->getResponseStatusCode(); if ( responseCode >= SIP_4XX_CLASS_CODE && responseCode != SIP_REQUEST_TIMEOUT_CODE ) { // remove the subscription removeErrorSubscription ( *message ); } } return TRUE; }
~SubAdBlockManager() { QList<AdBlockSubscription*> list = subscriptions(); foreach (AdBlockSubscription *s, list) removeSubscription(s); setEnabled(false); }