void RawResource::didAddClient(ResourceClient* c) { if (!hasClient(c)) return; // The calls to the client can result in events running, potentially causing // this resource to be evicted from the cache and all clients to be removed, // so a protector is necessary. ResourcePtr<RawResource> protect(this); RawResourceClient* client = static_cast<RawResourceClient*>(c); size_t redirectCount = redirectChain().size(); for (size_t i = 0; i < redirectCount; i++) { RedirectPair redirect = redirectChain()[i]; ResourceRequest request(redirect.m_request); client->redirectReceived(this, request, redirect.m_redirectResponse); if (!hasClient(c)) return; } ASSERT(redirectCount == redirectChain().size()); if (!m_response.isNull()) client->responseReceived(this, m_response); if (!hasClient(c)) return; if (m_data) client->dataReceived(this, m_data->data(), m_data->size()); if (!hasClient(c)) return; Resource::didAddClient(client); }
void Resource::removeClient(ResourceClient* client) { ASSERT(hasClient(client)); if (m_finishedClients.contains(client)) m_finishedClients.remove(client); else if (m_clientsAwaitingCallback.contains(client)) m_clientsAwaitingCallback.remove(client); else m_clients.remove(client); didRemoveClient(client); if (m_clientsAwaitingCallback.isEmpty()) ResourceCallback::callbackHandler()->cancel(this); bool deleted = deleteIfPossible(); if (!deleted && !hasClients()) { memoryCache()->makeDead(this); if (!m_switchingClientsToRevalidatedResource) allClientsRemoved(); // RFC2616 14.9.2: // "no-store: ... MUST make a best-effort attempt to remove the information from volatile storage as promptly as possible" // "... History buffers MAY store such responses as part of their normal operation." // We allow non-secure content to be reused in history, but we do not allow secure content to be reused. if (hasCacheControlNoStoreHeader() && url().protocolIs("https")) { memoryCache()->remove(this); memoryCache()->prune(); } else { memoryCache()->prune(this); } } // This object may be dead here. }
EmbedArea::~EmbedArea() { if( hasClient() ) { getClient().close(); } EmbedManager::instance().unregisterEmbedArea( *this ); }
void CSSStyleSheetResource::didAddClient(ResourceClient* c) { DCHECK(StyleSheetResourceClient::isExpectedType(c)); // Resource::didAddClient() must be before setCSSStyleSheet(), because // setCSSStyleSheet() may cause scripts to be executed, which could destroy // 'c' if it is an instance of HTMLLinkElement. see the comment of // HTMLLinkElement::setCSSStyleSheet. Resource::didAddClient(c); if (hasClient(c) && m_didNotifyFirstData) static_cast<StyleSheetResourceClient*>(c)->didAppendFirstData(this); // |c| might be removed in didAppendFirstData, so ensure it is still a client. if (hasClient(c) && !isLoading()) { static_cast<StyleSheetResourceClient*>(c)->setCSSStyleSheet( resourceRequest().url(), response().url(), encoding(), this); } }
void CachedRawResource::didAddClient(CachedResourceClient* c) { if (m_response.isNull() || !hasClient(c)) return; // The calls to the client can result in events running, potentially causing // this resource to be evicted from the cache and all clients to be removed, // so a protector is necessary. CachedResourceHandle<CachedRawResource> protect(this); CachedRawResourceClient* client = static_cast<CachedRawResourceClient*>(c); client->responseReceived(this, m_response); if (!hasClient(c)) return; if (m_data) client->dataReceived(this, m_data->data(), m_data->size()); if (!hasClient(c)) return; CachedResource::didAddClient(client); }
Embeddable& EmbedArea::getClient() const { if( !hasClient() ) { throw std::logic_error( "EmbedArea::getClient invoked but no client embedded" ); } else { return *pClient; } }
std::pair<CRootItem*, std::string> CStreamClientHdl::rmClientStateDiff(const CRootItem* const curState, const std::string& rmClient) { pair<int,int> pospair = hasClient(rmClient); int pos = pospair.first; int insertbefore = pospair.second; if(pos == -1) { // streaming client is not known -> don't care if it disappeared return make_pair((CRootItem*)0, string()); } else { // render client 'rmClient' is already known, as it just disappeared, disable it. // do not touch owner session'n name ostringstream oss; CRootItem* newState = new CRootItem(*curState); /// TODO get service by name from session state! m_session->getServiceByName() gets it // from DnsSDBase where it has already been deleted by now. CCategoryItem* base = newState->getCategoryPtr("/RenderClients"); if(base == 0) { base = newState->mkPath("/RenderClients"); } IContentItem* ci = base->getContentItem(pos); assert( ci->type() == CItemType::E_STREAM_CLIENT); CStreamClientItem *rmsci = reinterpret_cast<CStreamClientItem*>(ci); if( isOwnClient(rmsci) ) { if( rmsci->isEnabled() ) { // it was enabled, disable it oss << "@@ -" << pos + 1 << ",1 +" << pos + 1 << ",1 @@" << endl; oss << "-" << base->getPath() << "\t" << rmsci->serialize(); rmsci->setEnabled(false); oss << "+" << base->getPath() << "\t" << rmsci->serialize(); } else { // it is our own client, but it was already disbled -> do nothing // it was already disabled -> do nothing delete newState; return make_pair((CRootItem*)0, string()); } } else { // client is known and disappeared now. As it is not owned by this session, just remove it. oss << "@@ -" << pos + 1 << ",1 +" << pos + 1 << ",0 @@" << endl; oss << "-" << base->getPath() << "\t" << rmsci->serialize(); base->delContentItem(pos); } return make_pair(newState, oss.str()); } }
void CachedRawResource::didAddClient(CachedResourceClient* c) { if (!hasClient(c)) return; // The calls to the client can result in events running, potentially causing // this resource to be evicted from the cache and all clients to be removed, // so a protector is necessary. CachedResourceHandle<CachedRawResource> protect(this); CachedRawResourceClient* client = static_cast<CachedRawResourceClient*>(c); size_t redirectCount = m_redirectChain.size(); for (size_t i = 0; i < redirectCount; i++) { RedirectPair redirect = m_redirectChain[i]; ResourceRequest request(redirect.m_request); client->redirectReceived(this, request, redirect.m_redirectResponse); if (!hasClient(c)) return; } ASSERT(redirectCount == m_redirectChain.size()); if (!m_response.isNull()) { ResourceResponse response(m_response); if (validationCompleting()) response.setSource(ResourceResponse::Source::MemoryCacheAfterValidation); else { ASSERT(!validationInProgress()); response.setSource(ResourceResponse::Source::MemoryCache); } client->responseReceived(this, response); } if (!hasClient(c)) return; if (m_data) client->dataReceived(this, m_data->data(), m_data->size()); if (!hasClient(c)) return; CachedResource::didAddClient(client); }
int hasProtocol(HostAttributeEntry *host_entry, int ipprotocol, int protocol, int application) { int ret = SFTARGET_NOMATCH; ret = hasService(host_entry, ipprotocol, protocol, application); if (ret == SFTARGET_MATCH) return ret; ret = hasClient(host_entry, ipprotocol, protocol, application); if (ret == SFTARGET_MATCH) return ret; return ret; }
void EmbedArea::releaseClient() { if( hasClient() ) { const QPoint pos = pClient->mapToGlobal( QPoint( 0, 0 ) ); this->layout()->removeWidget( pClient ); pClient->setParent( nullptr ); pClient->move( pos ); pClient->show(); Embeddable& client = *pClient; client.detachedEvent(); pClient = nullptr; this->setFrameStyle( QFrame::Panel | QFrame::Sunken ); emit clientReleased( client ); } }
bool CHostIce::registerClient( const ::Client::CClientPrx & client, const std::string & nickname, std::string & idOrErrMsg, const ::Ice::Current & c ) { IceUtil::Mutex::Lock lock( m_mut ); QLOG_TRACE() << "registerClient( " << QString::fromUtf8( nickname.data(), nickname.size() ) << " )"; try { //client->cam( c.ctx ); //client->ice_id( c.ctx ); if ( !nicknameUnique( nickname ) ) { std::ostringstream msg; msg << "ERROR: \"" << nickname << "\" is aready in use"; QLOG_TRACE() << QString::fromUtf8( msg.str().data(), msg.str().size() ); idOrErrMsg = msg.str(); return false; } std::string id = clientId( nickname, client ); if ( hasClient( id ) ) { std::ostringstream msg; msg << "ERROR: your client id is \"" << id << "\", it is aready in use. Failed to add client."; QLOG_TRACE() << QString::fromUtf8( msg.str().data(), msg.str().size() ); idOrErrMsg = msg.str(); return false; } QLOG_TRACE() << "Assigned id: " << QString::fromStdString( id ); CClientDesc cd( nickname, client ); idOrErrMsg = id; addClient( id, cd ); validateClientList( c ); sendClientList( c ); return true; } catch( const Ice::Exception & ex ) { QLOG_TRACE() << "Exception: " << ex.toString().c_str(); idOrErrMsg = ex.toString().c_str(); fprintf(stderr, "%s\n", ex.toString().c_str()); } return false; }
int main(int argc, char *argv[]) { int sockfd; struct addrinfo hints, *servinfo, *p; int rv; int numbytes; struct sockaddr_in their_addr; char buf[MAXBUFFLEN]; socklen_t addr_len; char s[INET6_ADDRSTRLEN]; unsigned long ip_in_wait = 0; unsigned short wait_port; /*Check for correct terminal usage for this program. It should be UDPClient Servername Port# requestID hostname1 hostname2 ... hostnameX See assignment paper for details */ if(argc > 2) { fprintf(stderr, "\nusage error: argc = %d\tUDPServer ServerPort#\n", argc); exit(1); } char* serverPort = argv[1]; while (1) { memset(&hints, 0, sizeof hints); hints.ai_family = AF_UNSPEC; // set to AF_INET to force IPv4 hints.ai_socktype = SOCK_DGRAM; hints.ai_flags = AI_PASSIVE; // use my IP if ((rv = getaddrinfo(NULL, serverPort, &hints, &servinfo)) != 0) { fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(rv)); return 1; } // loop through all the results and bind to the first we can for(p = servinfo; p != NULL; p = p->ai_next) { if ((sockfd = socket(p->ai_family, p->ai_socktype, p->ai_protocol)) == -1) { perror("listener: socket"); continue; } if (bind(sockfd, p->ai_addr, p->ai_addrlen) == -1) { close(sockfd); perror("listener: bind"); continue; } break; } if (p == NULL) { fprintf(stderr, "listener: failed to bind socket\n"); return 2; } freeaddrinfo(servinfo); printf("\nWaiting for client to connect...\n"); //while (1) { addr_len = sizeof their_addr; if ((numbytes = recvfrom(sockfd, buf, MAXBUFFLEN-1 , 0, (struct sockaddr *)&their_addr, &addr_len)) == -1) { perror("recvfrom"); exit(1); } unsigned long ip_address = their_addr.sin_addr.s_addr; if (hasMagicNumber(buf) && isCorrectLength(buf, numbytes) && portIsInRange(buf)) { if(hasClient(ip_in_wait)) { if(sendClientWaitingMessage(buf, ip_in_wait, sockfd, their_addr)) { ip_in_wait = 0; } else { perror("listener: sendto"); exit(1); } } else { //Removed second paramter: their_addr.sin_port //Need to just grab the client's port within the request AlexAg if (sendNoClientMessage(buf, sockfd, their_addr)) { ip_in_wait = 1; } else { perror("listener: sendto"); exit(1); } ip_in_wait = ip_address; wait_port = their_addr.sin_port; } } else { sendErrorMessage(buf, sockfd, p, numbytes); } close(sockfd); } return 0; }
/** * \brief create a diff string representing an added streaming client * As seen by this session. * * This method gets called for all sessions when a streaming client appears via DNS-SD (Avahi) * If the streaming client is part of a session, it is already known there, but disabled, it will be enabled. * For all sessions this client is not part of, it gets available in the "availStreamingClients" section. * * \return std::pair with the pointer to a new RootItem containing the new state and the diff between * the current state and the new state as string. Null pointer and empty string if nothing changed. */ std::pair<CRootItem*, std::string> CStreamClientHdl::addClientStateDiff(const CRootItem* const curState, const std::string& addClient) { ostringstream oss; int num_clients; CRootItem* newState = new CRootItem(*curState); ServDescPtr srvPtr = m_session->getServiceByName(addClient); assert(srvPtr != NULL); CCategoryItem* base = newState->getCategoryPtr("/RenderClients"); if(base == 0) { base = newState->mkPath("/RenderClients"); num_clients = 0; } else { num_clients = base->getNumContentItems(); } // create new client, but do NOT set its parent pointer so it will not be added to parent as child. // Add it as child of "base" if it is new, only. CStreamClientItem *newsci = new CStreamClientItem(newState, 0, addClient); newsci->setHostName(srvPtr->getHostName()); newsci->setDomainName(srvPtr->getDomainName()); newsci->setPort(srvPtr->getPortNr()); newsci->setEnabled(true); pair<int,int> pospair = hasClient(addClient); int pos = pospair.first; int insertbefore = pospair.second; if(pos == -1) { // streaming client is not known -> append it as available oss << "@@ -" << insertbefore << ",0 +" << insertbefore + 1 << ",1 @@" << endl; oss << "+" << base->getPath() << "\t" << newsci->serialize(); base->addChild(newsci, insertbefore); } else { // render client 'addClient' is already known, as it just appeared, enable it. // do not touch owner session'n name IContentItem *tmp = base->getContentItem(pos); CStreamClientItem *sci = reinterpret_cast<CStreamClientItem*>(tmp); newsci->setOwnerSessionName(sci->getOwnerSessionName()); if(*sci != *newsci) { oss << "@@ -" << pos + 1 << ",1 +" << pos + 1 << ",1 @@" << endl; oss << "-" << base->getPath() << "\t" << sci->serialize(); oss << "+" << base->getPath() << "\t" << newsci->serialize(); base->delContentItem(pos); base->addChild(newsci, pos); } else { delete newState; return make_pair((CRootItem*)0, string()); } } return make_pair( newState, oss.str()); }
/** * \brief Take ownership of a render client * * Ownership of a render client was taken by session 'ownerSessionsName'. If it * belonged to this session before, release ownership. Fill in * 'ownerSessionName' as owner of render client named 'name'. * * \return as a pair: both pointer to sessionState CRootItem and the diff as string */ std::pair<CRootItem*, std::string> CStreamClientHdl::takeClientStateDiff(const CRootItem* const curState, const std::string& name, const std::string& ownerSessionsName) { ostringstream oss; CRootItem* newState = new CRootItem(*curState); ServDescPtr srvPtr = m_session->getServiceByName(name); assert(srvPtr != NULL); CCategoryItem* base = newState->getCategoryPtr("/RenderClients"); if(base == 0) { base = newState->mkPath("/RenderClients"); } CStreamClientItem *newsci = new CStreamClientItem(newState, base, name); newsci->setHostName(srvPtr->getHostName()); newsci->setDomainName(srvPtr->getDomainName()); newsci->setPort(srvPtr->getPortNr()); newsci->setOwnerSessionName(ownerSessionsName); pair<int,int> pospair = hasClient(name); int pos = pospair.first; int insertbefore = pospair.second; if(pos == -1) { // streaming client is not known -> append it as available int num_clients; CCategoryItem* base = newState->getCategoryPtr("/RenderClients"); if(base == 0) { base = newState->mkPath("/RenderClients"); num_clients = 0; } else { num_clients = base->getNumContentItems(); } oss << "@@ -0,0 +" << num_clients + 1 << ",1 @@" << endl; oss << "+" << base->getPath() << "\t" << newsci->serialize(); base->addChild(newsci); } else { // render client 'name' is already known, ownership was taken by 'ownerSessionsName'. // do not touch enabled/disabled state IContentItem *tmp = base->getContentItem(pos); CStreamClientItem *sci = reinterpret_cast<CStreamClientItem*>(tmp); if(*sci != *newsci) { oss << "@@ -" << pos << ",1 +" << pos << ",1 @@" << endl; oss << "-" << base->getPath() << "\t" << sci->serialize(); oss << "+" << base->getPath() << "\t" << newsci->serialize(); sci->setOwnerSessionName(ownerSessionsName); } else { delete newState; return make_pair((CRootItem*)0, string()); } } return make_pair( newState, oss.str()); }
void CHostIce::addClient( const std::string & id, const CClientDesc & client ) { if ( !hasClient( id ) ) m_clients.insert( std::pair<std::string, CClientDesc>( id, client ) ); }