Type Type::operator&(Type rhs) const { auto lhs = *this; // When intersecting a constant value with another type, the result will be // the constant value if the other value is a supertype of the constant, and // Bottom otherwise. if (lhs.m_hasConstVal) return lhs <= rhs ? lhs : TBottom; if (rhs.m_hasConstVal) return rhs <= lhs ? rhs : TBottom; auto bits = lhs.m_bits & rhs.m_bits; auto ptr = lhs.ptrKind() & rhs.ptrKind(); auto arrSpec = lhs.arrSpec() & rhs.arrSpec(); auto clsSpec = lhs.clsSpec() & rhs.clsSpec(); // Filter out bits and pieces that no longer exist due to other components // going to Bottom, starting with bits. if (ptr == Ptr::Bottom) bits &= ~kGen; if (arrSpec == ArraySpec::Bottom) bits &= ~kArrSpecBits; if (clsSpec == ClassSpec::Bottom) bits &= ~kClsSpecBits; // ptr if ((bits & kGen) == 0) ptr = Ptr::Bottom; // specs if (!supports(bits, SpecKind::Array)) arrSpec = ArraySpec::Bottom; if (!supports(bits, SpecKind::Class)) clsSpec = ClassSpec::Bottom; return Type{bits, ptr}.specialize({arrSpec, clsSpec}); }
Aligned::Aligned ( size_t alignment ) : myAlignment(alignment) { if ( !supports(alignment) ) { throw (std::invalid_argument("Aligned")); } }
void VideoOutput::getSupportedCodecs(Array<InternalCodecID>& list) { for (int i = CODEC_ID_NONE; i < CODEC_ID_LAST; ++i) { InternalCodecID c = (InternalCodecID)i; if (supports(c)) { list.append(c); } } }
bool Extensions3DOpenGLCommon::isEnabled(const String& name) { if (name == "GL_OES_standard_derivatives") { ANGLEWebKitBridge& compiler = m_context->m_compiler; return compiler.getResources().OES_standard_derivatives; } return supports(name); }
bool Identity::isTcp4Active(const ClientPtr& c) const noexcept { if (!user->isSet(User::NMDC)) { return !getIp4().empty() && supports(AdcHub::TCP4_FEATURE); } else { //we don't want to use the global passive flag for our own user... return c && user == ClientManager::getInstance()->getMe() ? c->isActiveV4() : !user->isSet(User::PASSIVE); } }
bool Identity::isTcpActive(const Client* c) const { if(c != NULL && user == ClientManager::getInstance()->getMe()) { return c->isActive(); // userlist should display our real mode } else { return (!user->isSet(User::NMDC)) ? !getIp().empty() && supports(AdcHub::TCP4_FEATURE) : !user->isSet(User::PASSIVE); } }
void Extensions3DOpenGL::bindVertexArrayOES(Platform3DObject array) { m_context->makeContextCurrent(); #if GL_APPLE_vertex_array_object glBindVertexArrayAPPLE(array); #else ASSERT_UNUSED(array, supports(array)); #endif }
void PromiseWorkerProxy::StoreISupports(nsISupports* aSupports) { MOZ_ASSERT(NS_IsMainThread()); nsMainThreadPtrHandle<nsISupports> supports( new nsMainThreadPtrHolder<nsISupports>(aSupports)); mSupportsArray.AppendElement(supports); }
/** * This is the generic mutator for properties. Given a value, this will * change it and emit propertyChanged if its different and supported. */ void DisplayProperties::setValue(int property, QVariant value) { if ((*m_propertyValues)[property] != value) { (*m_propertyValues)[property] = value; if (supports(property)) { emit propertyChanged(this); } } }
Type Type::specialize(TypeSpec spec) const { assertx(!spec.arrSpec() || supports(SpecKind::Array)); assertx(!spec.clsSpec() || supports(SpecKind::Class)); // If we don't have exactly one kind of specialization, or if our bits // support both kinds, don't specialize. if ((bool)spec.arrSpec() == (bool)spec.clsSpec() || (supports(SpecKind::Array) && supports(SpecKind::Class))) { return *this; } if (spec.arrSpec() != ArraySpec::Bottom) { return Type{*this, spec.arrSpec()}; } assertx(spec.clsSpec() != ClassSpec::Bottom); return Type{*this, spec.clsSpec()}; }
bool Identity::updateConnectMode(const Identity& me, const Client* aClient) noexcept { Mode newMode = MODE_NOCONNECT_IP; bool meSupports6 = !me.getIp6().empty(); if (meSupports6 && !getIp6().empty()) { // IPv6? active / NAT-T if (isTcp6Active()) { newMode = MODE_ACTIVE_V6; } else if (me.isTcp6Active() || supports(AdcHub::NAT0_FEATURE)) { newMode = MODE_PASSIVE_V6; } } if (!me.getIp4().empty() && !getIp4().empty()) { if (isTcp4Active()) { newMode = newMode == MODE_ACTIVE_V6 ? MODE_ACTIVE_DUAL : MODE_ACTIVE_V4; } else if (newMode == MODE_NOCONNECT_IP && (me.isTcp4Active() || supports(AdcHub::NAT0_FEATURE))) { //passive v4 isn't any better than passive v6 newMode = MODE_PASSIVE_V4; } } if (newMode == MODE_NOCONNECT_IP) { // the hub doesn't support hybrid connectivity or we weren't able to authenticate the secondary protocol? we are passive via that protocol in that case if (isTcp4Active() && aClient->get(HubSettings::Connection) != SettingsManager::INCOMING_DISABLED) { newMode = MODE_ACTIVE_V4; } else if (isTcp6Active() && aClient->get(HubSettings::Connection6) != SettingsManager::INCOMING_DISABLED) { newMode = MODE_ACTIVE_V6; } else if (!me.isTcpActive()) { //this user is passive with no NAT-T (or the hub is hiding all IP addresses) if (!supports(AdcHub::NAT0_FEATURE) && !aClient->isActive()) { newMode = MODE_NOCONNECT_PASSIVE; } } else { //could this user still support the same protocol? can't know for sure newMode = meSupports6 ? MODE_PASSIVE_V6_UNKNOWN : MODE_PASSIVE_V4_UNKNOWN; } } if (connectMode != newMode) { connectMode = newMode; return true; } return false; }
bool Extensions3DOpenGL::isEnabled(const String& name) { #if PLATFORM(MAC) || PLATFORM(QT) if (name == "GL_OES_standard_derivatives") { ANGLEWebKitBridge& compiler = m_context->m_compiler; return compiler.getResources().OES_standard_derivatives; } #endif return supports(name); }
// Component // // void Component:: traverse (Type& c) { pre (c); name (c); inherits (c); supports (c); names (c); post (c); }
// Home // // void Home:: traverse (Type& h) { pre (h); name (h); inherits (h); supports (h); manages (h); names (h); post (h); }
bool can_do(const context& d, pk_t ptype) { int ret = mbedtls_pk_can_do(&d.pk_, to_native(ptype)); // refinement due to build options if (type_of(d) == pk_t::eckey && ptype == pk_t::ecdsa) { if (!supports(pk_t::ecdsa)) ret = 0; } return ret == 1; }
void BinaryRelation::validate () const { POMAGMA_INFO("Validating BinaryRelation"); m_lines.validate(); size_t num_pairs = 0; DenseSet Lx(round_item_dim(), nullptr); DenseSet Rx(round_item_dim(), nullptr); for (Ob i = 1; i <= item_dim(); ++i) { bool sup_i = supports(i); Lx.init(m_lines.Lx(i)); for (Ob j = 1; j <= item_dim(); ++j) { bool sup_ij = sup_i and supports(j); Rx.init(m_lines.Rx(j)); bool Lx_ij = Lx.contains(j); bool Rx_ij = Rx.contains(i); num_pairs += Rx_ij; POMAGMA_ASSERT(Lx_ij == Rx_ij, "Lx,Rx disagree at " << i << "," << j << ", Lx is " << Lx_ij << ", Rx is " << Rx_ij ); POMAGMA_ASSERT(sup_ij or not Lx_ij, "Lx unsupported at " << i << "," << j ); POMAGMA_ASSERT(sup_ij or not Rx_ij, "Rx unsupported at " << i << "," << j ); } } size_t true_size = count_pairs(); POMAGMA_ASSERT(num_pairs == true_size, "incorrect number of pairs: " << num_pairs << " should be " << true_size); }
void ImageOutput::stash_spec(ImageSpec newspec) { m_spec = newspec; if ( !supports("datawindow")) { m_spec.width = m_spec.full_width; m_spec.height = m_spec.full_height; m_spec.depth = m_spec.full_depth; m_spec.x = m_spec.full_x; m_spec.y = m_spec.full_y; m_spec.z = m_spec.full_z; } }
bool ImageOutput::copy_image (ImageInput *in) { if (! in) { error ("copy_image: no input supplied"); return false; } // Make sure the images are compatible in size const ImageSpec &inspec (in->spec()); if (inspec.width != spec().width || inspec.height != spec().height || inspec.depth != spec().depth || inspec.nchannels != spec().nchannels) { error ("Could not copy %d x %d x %d channels to %d x %d x %d channels", inspec.width, inspec.height, inspec.nchannels, spec().width, spec().height, spec().nchannels); return false; } // in most cases plugins don't allow to copy 0x0 images // but there are some exceptions (like in FITS plugin) // when we want to do this. Because 0x0 means there is no image // data in the file, we simply return true so the application thought // that everything went right. if (! spec().image_bytes()) return true; if (spec().deep) { // Special case for ''deep'' images DeepData deepdata; bool ok = in->read_native_deep_image (deepdata); if (ok) ok = write_deep_image (deepdata); else error ("%s", in->geterror()); // copy err from in to out return ok; } // Naive implementation -- read the whole image and write it back out. // FIXME -- a smarter implementation would read scanlines or tiles at // a time, to minimize mem footprint. bool native = supports("channelformats") && inspec.channelformats.size(); TypeDesc format = native ? TypeDesc::UNKNOWN : inspec.format; boost::scoped_array<char> pixels (new char [inspec.image_bytes(native)]); bool ok = in->read_image (format, &pixels[0]); if (ok) ok = write_image (format, &pixels[0]); else error ("%s", in->geterror()); // copy err from in to out return ok; }
void Extensions3DOpenGL::ensureEnabled(const String& name) { #if PLATFORM(MAC) || PLATFORM(QT) if (name == "GL_OES_standard_derivatives") { // Enable support in ANGLE (if not enabled already) ANGLEWebKitBridge& compiler = m_context->m_compiler; ShBuiltInResources ANGLEResources = compiler.getResources(); if (!ANGLEResources.OES_standard_derivatives) { ANGLEResources.OES_standard_derivatives = 1; compiler.setResources(ANGLEResources); } } #else ASSERT_UNUSED(name, supports(name)); #endif }
bool Extensions3DOpenGL::isVertexArrayObjectSupported() { static const bool supportsVertexArrayObject = supports("GL_OES_vertex_array_object"); return supportsVertexArrayObject; }
Type Type::operator-(Type rhs) const { auto lhs = *this; if (rhs == TBottom) return lhs; if (lhs <= rhs) return TBottom; if (lhs.hasConstVal()) return lhs; // not covered by rhs. // If `rhs' has a constant value, but `lhs' doesn't, conservatively return // `lhs', rather than trying to represent things like "everything except // Int<24>". Boolean is a special case. if (rhs.m_hasConstVal) { if (rhs <= TBool && lhs <= TBool) { auto const res = !rhs.boolVal(); if (lhs.hasConstVal() && lhs.boolVal() != res) return TBottom; return cns(res); } return lhs; } // For each component C, we should subtract C_rhs from C_lhs iff every other // component of lhs that can intersect with C is subsumed by the // corresponding component of rhs. This prevents us from removing members of // lhs that weren't present in rhs, but would be casualties of removing // certain bits in lhs. // // As an example, consider PtrToRMembInt - PtrToRefStr. Simple subtraction of // each component would yield PtrToMembInt, but that would mean we removed // PtrToRefInt from the lhs despite it not being in rhs. Checking if Int is a // subset of Str shows us that removing Ref from lhs would erase types not // present in rhs. // // In practice, it's more concise to eagerly do each subtraction, then check // for components that went to Bottom as a way of seeing which components of // lhs were subsets of the corresponding components in rhs. When we find a // component that we weren't supposed to subtract, just restore lhs's // original value. auto bits = lhs.m_bits & ~rhs.m_bits; auto ptr = lhs.ptrKind() - rhs.ptrKind(); auto arrSpec = lhs.arrSpec() - rhs.arrSpec(); auto clsSpec = lhs.clsSpec() - rhs.clsSpec(); auto const have_gen_bits = (bits & kGen) != 0; auto const have_arr_bits = supports(bits, SpecKind::Array); auto const have_cls_bits = supports(bits, SpecKind::Class); auto const have_ptr = ptr != Ptr::Bottom; auto const have_arr_spec = arrSpec != ArraySpec::Bottom; auto const have_cls_spec = clsSpec != ClassSpec::Bottom; // ptr can only interact with clsSpec if lhs.m_bits has at least one kGen // member of kClsSpecBits. auto const have_ptr_cls = supports(lhs.m_bits & kGen, SpecKind::Class); // bits if (have_ptr) bits |= lhs.m_bits & kGen; if (have_arr_spec) bits |= lhs.m_bits & kArrSpecBits; if (have_cls_spec) bits |= lhs.m_bits & kClsSpecBits; // ptr if (have_gen_bits || have_arr_spec || (have_cls_spec && have_ptr_cls)) { ptr = lhs.ptrKind(); } // specs if (have_ptr || have_arr_bits) arrSpec = lhs.arrSpec(); if ((have_ptr && have_ptr_cls) || have_cls_bits) clsSpec = lhs.clsSpec(); return Type{bits, ptr}.specialize({arrSpec, clsSpec}); }
bool Identity::isUdp4Active() const noexcept { if(getIp4().empty() || getUdp4Port().empty()) return false; return user->isSet(User::NMDC) ? !user->isSet(User::PASSIVE) : supports(AdcHub::UDP4_FEATURE); }
bool ImageOutput::write_image (TypeDesc format, const void *data, stride_t xstride, stride_t ystride, stride_t zstride, ProgressCallback progress_callback, void *progress_callback_data) { bool native = (format == TypeDesc::UNKNOWN); stride_t pixel_bytes = native ? (stride_t) m_spec.pixel_bytes (native) : format.size() * m_spec.nchannels; if (xstride == AutoStride) xstride = pixel_bytes; m_spec.auto_stride (xstride, ystride, zstride, format, m_spec.nchannels, m_spec.width, m_spec.height); if (supports ("rectangles")) { // Use a rectangle if we can return write_rectangle (0, m_spec.width, 0, m_spec.height, 0, m_spec.depth, format, data, xstride, ystride, zstride); } bool ok = true; if (progress_callback && progress_callback (progress_callback_data, 0.0f)) return ok; if (m_spec.tile_width && supports ("tiles")) { // Tiled image for (int z = 0; z < m_spec.depth; z += m_spec.tile_depth) { int zend = std::min (z+m_spec.z+m_spec.tile_depth, m_spec.z+m_spec.depth); for (int y = 0; y < m_spec.height; y += m_spec.tile_height) { int yend = std::min (y+m_spec.y+m_spec.tile_height, m_spec.y+m_spec.height); const char *d = (const char *)data + z*zstride + y*ystride; ok &= write_tiles (m_spec.x, m_spec.x+m_spec.width, y+m_spec.y, yend, z+m_spec.z, zend, format, d, xstride, ystride, zstride); if (progress_callback && progress_callback (progress_callback_data, (float)(z*m_spec.height+y)/(m_spec.height*m_spec.depth))) return ok; } } } else { // Scanline image const int chunk = 256; for (int z = 0; z < m_spec.depth; ++z) for (int y = 0; y < m_spec.height && ok; y += chunk) { int yend = std::min (y+m_spec.y+chunk, m_spec.y+m_spec.height); const char *d = (const char *)data + z*zstride + y*ystride; ok &= write_scanlines (y+m_spec.y, yend, z+m_spec.z, format, d, xstride, ystride); if (progress_callback && progress_callback (progress_callback_data, (float)(z*m_spec.height+y)/(m_spec.height*m_spec.depth))) return ok; } } if (progress_callback) progress_callback (progress_callback_data, 1.0f); return ok; }
void NmdcHub::onLine(const string& aLine) throw() { lastActivity = GET_TICK(); if(aLine.length() == 0) return; if(aLine[0] != '$') { // Check if we're being banned... if(state != STATE_CONNECTED) { if(Util::findSubString(aLine, "banned") != string::npos) { reconnect = false; } } Speaker<NmdcHubListener>::fire(NmdcHubListener::Message(), this, Util::validateMessage(fromNmdc(aLine), true)); return; } string cmd; string param; string::size_type x; if( (x = aLine.find(' ')) == string::npos) { cmd = aLine; } else { cmd = aLine.substr(0, x); param = aLine.substr(x+1); } if(cmd == "$Search") { if(state != STATE_CONNECTED) { return; } string::size_type i = 0; string::size_type j = param.find(' ', i); if(j == string::npos || i == j) return; string seeker = fromNmdc(param.substr(i, j-i)); // Filter own searches if(SETTING(CONNECTION_TYPE) == SettingsManager::CONNECTION_ACTIVE) { if(seeker == (getLocalIp() + ":" + Util::toString(SETTING(IN_PORT)))) { return; } } else { // Hub:seeker if(Util::stricmp(seeker.c_str() + 4, getNick().c_str()) == 0) { return; } } i = j + 1; { Lock l(cs); u_int32_t tick = GET_TICK(); seekers.push_back(make_pair(seeker, tick)); // First, check if it's a flooder FloodIter fi; for(fi = flooders.begin(); fi != flooders.end(); ++fi) { if(fi->first == seeker) { return; } } int count = 0; for(fi = seekers.begin(); fi != seekers.end(); ++fi) { if(fi->first == seeker) count++; if(count > 7) { if(seeker.compare(0, 4, "Hub:") == 0) Speaker<NmdcHubListener>::fire(NmdcHubListener::SearchFlood(), this, seeker.substr(4)); else Speaker<NmdcHubListener>::fire(NmdcHubListener::SearchFlood(), this, seeker + STRING(NICK_UNKNOWN)); flooders.push_back(make_pair(seeker, tick)); return; } } } int a; if(param[i] == 'F') { a = SearchManager::SIZE_DONTCARE; } else if(param[i+2] == 'F') { a = SearchManager::SIZE_ATLEAST; } else { a = SearchManager::SIZE_ATMOST; } i += 4; j = param.find('?', i); if(j == string::npos || i == j) return; string size = param.substr(i, j-i); i = j + 1; j = param.find('?', i); if(j == string::npos || i == j) return; int type = Util::toInt(param.substr(i, j-i)) - 1; i = j + 1; param = param.substr(i); if(param.size() > 0) { Speaker<NmdcHubListener>::fire(NmdcHubListener::Search(), this, seeker, a, Util::toInt64(size), type, fromNmdc(param)); if(seeker.compare(0, 4, "Hub:") == 0) { User::Ptr u; { Lock l(cs); User::NickIter ni = users.find(seeker.substr(4)); if(ni != users.end() && !ni->second->isSet(User::PASSIVE)) { u = ni->second; u->setFlag(User::PASSIVE); } } if(u) { updated(u); } } } } else if(cmd == "$MyINFO") { string::size_type i, j; i = 5; j = param.find(' ', i); if( (j == string::npos) || (j == i) ) return; string nick = fromNmdc(param.substr(i, j-i)); i = j + 1; User::Ptr u; dcassert(nick.size() > 0); { Lock l(cs); User::NickIter ni = users.find(nick); if(ni == users.end()) { u = users[nick] = ClientManager::getInstance()->getUser(nick, this); } else { u = ni->second; } } j = param.find('$', i); if(j == string::npos) return; string tmpDesc = Util::validateMessage(fromNmdc(param.substr(i, j-i)), true); // Look for a tag... if(tmpDesc.size() > 0 && tmpDesc[tmpDesc.size()-1] == '>') { x = tmpDesc.rfind('<'); if(x != string::npos) { // Hm, we have something... u->setTag(tmpDesc.substr(x)); tmpDesc.erase(x); } else { u->setTag(Util::emptyString); } } else { u->setTag(Util::emptyString); } u->setDescription(tmpDesc); i = j + 3; j = param.find('$', i); if(j == string::npos) return; u->setConnection(fromNmdc(param.substr(i, j-i-1))); i = j + 1; j = param.find('$', i); if(j == string::npos) return; u->setEmail(Util::validateMessage(fromNmdc(param.substr(i, j-i)), true)); i = j + 1; j = param.find('$', i); if(j == string::npos) return; u->setBytesShared(param.substr(i, j-i)); Speaker<NmdcHubListener>::fire(NmdcHubListener::MyInfo(), this, u); } else if(cmd == "$Quit") { if(!param.empty()) { User::Ptr u; { Lock l(cs); User::NickIter i = users.find(fromNmdc(param)); if(i == users.end()) { dcdebug("C::onLine Quitting user %s not found\n", param.c_str()); return; } u = i->second; users.erase(i); } Speaker<NmdcHubListener>::fire(NmdcHubListener::Quit(), this, u); ClientManager::getInstance()->putUserOffline(u, true); } } else if(cmd == "$ConnectToMe") { if(state != STATE_CONNECTED) { return; } string::size_type i = param.find(' '); string::size_type j; if( (i == string::npos) || ((i + 1) >= param.size()) ) { return; } i++; j = param.find(':', i); if(j == string::npos) { return; } string server = fromNmdc(param.substr(i, j-i)); if(j+1 >= param.size()) { return; } string port = param.substr(j+1); ConnectionManager::getInstance()->connect(server, (short)Util::toInt(port), getNick()); Speaker<NmdcHubListener>::fire(NmdcHubListener::ConnectToMe(), this, server, (short)Util::toInt(port)); } else if(cmd == "$RevConnectToMe") { if(state != STATE_CONNECTED) { return; } User::Ptr u; bool up = false; { Lock l(cs); string::size_type j = param.find(' '); if(j == string::npos) { return; } User::NickIter i = users.find(fromNmdc(param.substr(0, j))); if(i == users.end()) { return; } u = i->second; if(!u->isSet(User::PASSIVE)) { u->setFlag(User::PASSIVE); up = true; } } if(u) { if(SETTING(CONNECTION_TYPE) == SettingsManager::CONNECTION_ACTIVE) { connectToMe(u); Speaker<NmdcHubListener>::fire(NmdcHubListener::RevConnectToMe(), this, u); } else { // Notify the user that we're passive too... if(up) revConnectToMe(u); } if(up) updated(u); } } else if(cmd == "$SR") { SearchManager::getInstance()->onSearchResult(aLine); } else if(cmd == "$HubName") { name = fromNmdc(param); Speaker<NmdcHubListener>::fire(NmdcHubListener::HubName(), this); } else if(cmd == "$Supports") { StringTokenizer<string> st(param, ' '); StringList& sl = st.getTokens(); for(StringIter i = sl.begin(); i != sl.end(); ++i) { if(*i == "UserCommand") { supportFlags |= SUPPORTS_USERCOMMAND; } else if(*i == "NoGetINFO") { supportFlags |= SUPPORTS_NOGETINFO; } else if(*i == "UserIP2") { supportFlags |= SUPPORTS_USERIP2; } } Speaker<NmdcHubListener>::fire(NmdcHubListener::Supports(), this, sl); } else if(cmd == "$UserCommand") { string::size_type i = 0; string::size_type j = param.find(' '); if(j == string::npos) return; int type = Util::toInt(param.substr(0, j)); i = j+1; if(type == UserCommand::TYPE_SEPARATOR || type == UserCommand::TYPE_CLEAR) { int ctx = Util::toInt(param.substr(i)); Speaker<NmdcHubListener>::fire(NmdcHubListener::UserCommand(), this, type, ctx, Util::emptyString, Util::emptyString); } else if(type == UserCommand::TYPE_RAW || type == UserCommand::TYPE_RAW_ONCE) { j = param.find(' ', i); if(j == string::npos) return; int ctx = Util::toInt(param.substr(i)); i = j+1; j = param.find('$'); if(j == string::npos) return; string name = fromNmdc(param.substr(i, j-i)); i = j+1; string command = fromNmdc(param.substr(i, param.length() - i)); Speaker<NmdcHubListener>::fire(NmdcHubListener::UserCommand(), this, type, ctx, Util::validateMessage(name, true, false), Util::validateMessage(command, true, false)); } } else if(cmd == "$Lock") { if(state != STATE_LOCK) { return; } state = STATE_HELLO; if(!param.empty()) { string::size_type j = param.find(" Pk="); string lock, pk; if( j != string::npos ) { lock = param.substr(0, j); pk = param.substr(j + 4); } else { // Workaround for faulty linux hubs... j = param.find(" "); if(j != string::npos) lock = param.substr(0, j); else lock = param; } if(CryptoManager::getInstance()->isExtended(lock)) { StringList feat; feat.push_back("UserCommand"); feat.push_back("NoGetINFO"); feat.push_back("NoHello"); feat.push_back("UserIP2"); feat.push_back("TTHSearch"); if(BOOLSETTING(COMPRESS_TRANSFERS)) feat.push_back("GetZBlock"); supports(feat); } key(CryptoManager::getInstance()->makeKey(lock)); validateNick(getNick()); Speaker<NmdcHubListener>::fire(NmdcHubListener::CLock(), this, lock, pk); } } else if(cmd == "$Hello") { if(!param.empty()) { string nick = fromNmdc(param); User::Ptr u = ClientManager::getInstance()->getUser(nick, this); { Lock l(cs); users[nick] = u; } if(getNick() == nick) { setMe(u); u->setFlag(User::DCPLUSPLUS); if(SETTING(CONNECTION_TYPE) != SettingsManager::CONNECTION_ACTIVE) u->setFlag(User::PASSIVE); else u->unsetFlag(User::PASSIVE); } if(state == STATE_HELLO) { state = STATE_CONNECTED; updateCounts(false); version(); getNickList(); myInfo(); } Speaker<NmdcHubListener>::fire(NmdcHubListener::Hello(), this, u); } } else if(cmd == "$ForceMove") { disconnect(); Speaker<NmdcHubListener>::fire(NmdcHubListener::Redirect(), this, param); } else if(cmd == "$HubIsFull") { Speaker<NmdcHubListener>::fire(NmdcHubListener::HubFull(), this); } else if(cmd == "$ValidateDenide") { // Mind the spelling... disconnect(); Speaker<NmdcHubListener>::fire(NmdcHubListener::ValidateDenied(), this); } else if(cmd == "$UserIP") { if(!param.empty()) { User::List v; StringTokenizer<string> t(fromNmdc(param), "$$"); StringList& l = t.getTokens(); for(StringIter it = l.begin(); it != l.end(); ++it) { string::size_type j = 0; if((j = it->find(' ')) == string::npos) continue; if((j+1) == it->length()) continue; v.push_back(ClientManager::getInstance()->getUser(it->substr(0, j), this)); v.back()->setIp(it->substr(j+1)); } Speaker<NmdcHubListener>::fire(NmdcHubListener::UserIp(), this, v); } } else if(cmd == "$NickList") { if(!param.empty()) { User::List v; StringTokenizer<string> t(fromNmdc(param), "$$"); StringList& sl = t.getTokens(); for(StringIter it = sl.begin(); it != sl.end(); ++it) { v.push_back(ClientManager::getInstance()->getUser(*it, this)); } { Lock l(cs); for(User::Iter it2 = v.begin(); it2 != v.end(); ++it2) { users[(*it2)->getNick()] = *it2; } } if(!(getSupportFlags() & SUPPORTS_NOGETINFO)) { string tmp; // Let's assume 10 characters per nick... tmp.reserve(v.size() * (11 + 10 + getNick().length())); for(User::List::const_iterator i = v.begin(); i != v.end(); ++i) { tmp += "$GetINFO "; tmp += (*i)->getNick(); tmp += ' '; tmp += getNick(); tmp += '|'; } if(!tmp.empty()) { send(tmp); } } Speaker<NmdcHubListener>::fire(NmdcHubListener::NickList(), this, v); } } else if(cmd == "$OpList") { if(!param.empty()) { User::List v; StringTokenizer<string> t(fromNmdc(param), "$$"); StringList& sl = t.getTokens(); for(StringIter it = sl.begin(); it != sl.end(); ++it) { v.push_back(ClientManager::getInstance()->getUser(*it, this)); v.back()->setFlag(User::OP); } { Lock l(cs); for(User::Iter it2 = v.begin(); it2 != v.end(); ++it2) { users[(*it2)->getNick()] = *it2; } } Speaker<NmdcHubListener>::fire(NmdcHubListener::OpList(), this, v); updateCounts(false); // Special...to avoid op's complaining that their count is not correctly // updated when they log in (they'll be counted as registered first...) myInfo(); } } else if(cmd == "$To:") { string::size_type i = param.find("From:"); if(i != string::npos) { i+=6; string::size_type j = param.find("$"); if(j != string::npos) { string from = fromNmdc(param.substr(i, j - 1 - i)); if(from.size() > 0 && param.size() > (j + 1)) { Speaker<NmdcHubListener>::fire(NmdcHubListener::PrivateMessage(), this, ClientManager::getInstance()->getUser(from, this, false), Util::validateMessage(fromNmdc(param.substr(j + 1)), true)); } } } } else if(cmd == "$GetPass") { setRegistered(true); Speaker<NmdcHubListener>::fire(NmdcHubListener::GetPassword(), this); } else if(cmd == "$BadPass") { Speaker<NmdcHubListener>::fire(NmdcHubListener::BadPassword(), this); } else if(cmd == "$LogedIn") { Speaker<NmdcHubListener>::fire(NmdcHubListener::LoggedIn(), this); } else { dcassert(cmd[0] == '$'); dcdebug("NmdcHub::onLine Unknown command %s\n", aLine.c_str()); } }
bool Identity::isUdp6Active() const noexcept { if(getIp6().empty() || getUdp6Port().empty()) return false; return user->isSet(User::NMDC) ? false : supports(AdcHub::UDP6_FEATURE); }
bool hwdec() const { return supports(DecoderDevice::GPU); }
bool swdec() const { return supports(DecoderDevice::CPU); }
bool Identity::isTcp6Active() const noexcept { return !getIp6().empty() && supports(AdcHub::TCP6_FEATURE); }
bool Extensions3DAndroid::isEnabled(const String& name) { return supports(name); }
const void * ImageOutput::to_native_rectangle (int xbegin, int xend, int ybegin, int yend, int zbegin, int zend, TypeDesc format, const void *data, stride_t xstride, stride_t ystride, stride_t zstride, std::vector<unsigned char> &scratch) { // native_pixel_bytes is the size of a pixel in the FILE, including // the per-channel format, if specified when the file was opened. stride_t native_pixel_bytes = (stride_t) m_spec.pixel_bytes (true); // perchanfile is true if the file has different per-channel formats bool perchanfile = m_spec.channelformats.size() && supports("channelformats"); // It's an error to pass per-channel data formats to a writer that // doesn't support it. if (m_spec.channelformats.size() && !perchanfile) return NULL; // native_data is true if the user is passing data in the native format bool native_data = (format == TypeDesc::UNKNOWN || (format == m_spec.format && !perchanfile)); // If the user is passing native data and they've left xstride set // to Auto, then we know it's the native pixel size. if (native_data && xstride == AutoStride) xstride = native_pixel_bytes; // Fill in the rest of the strides that haven't been set. m_spec.auto_stride (xstride, ystride, zstride, format, m_spec.nchannels, xend-xbegin, yend-ybegin); // Compute width and height from the rectangle extents int width = xend - xbegin; int height = yend - ybegin; int depth = zend - zbegin; // Do the strides indicate that the data area is contiguous? bool contiguous = (xstride == (stride_t)m_spec.pixel_bytes(native_data)); contiguous &= ((ystride == xstride*width || height == 1) && (zstride == ystride*height || depth == 1)); if (native_data && contiguous) { // Data are already in the native format and contiguous // just return a ptr to the original data. return data; } imagesize_t rectangle_pixels = width * height * depth; imagesize_t rectangle_values = rectangle_pixels * m_spec.nchannels; imagesize_t rectangle_bytes = rectangle_pixels * native_pixel_bytes; // Cases to handle: // 1. File has per-channel data, user passes native data -- this has // already returned above, since the data didn't need munging. // 2. File has per-channel data, user passes some other data type // 3. File has uniform data, user passes some other data type // 4. File has uniform data, user passes the right data -- note that // this case already returned if the user data was contiguous // Handle the per-channel format case (#2) where the user is passing // a non-native buffer. if (perchanfile) { if (native_data) { ASSERT (contiguous && "Per-channel native output requires contiguous strides"); } ASSERT (format != TypeDesc::UNKNOWN); ASSERT (m_spec.channelformats.size() == (size_t)m_spec.nchannels); scratch.resize (rectangle_bytes); size_t offset = 0; for (int c = 0; c < m_spec.nchannels; ++c) { TypeDesc chanformat = m_spec.channelformats[c]; convert_image (1 /* channels */, width, height, depth, (char *)data + c*format.size(), format, xstride, ystride, zstride, &scratch[offset], chanformat, native_pixel_bytes, AutoStride, AutoStride, NULL, c == m_spec.alpha_channel ? 0 : -1, c == m_spec.z_channel ? 0 : -1); offset += chanformat.size (); } return &scratch[0]; } // The remaining code is where all channels in the file have the // same data type, which may or may not be what the user passed in // (cases #3 and #4 above). imagesize_t contiguoussize = contiguous ? 0 : rectangle_values * native_pixel_bytes; contiguoussize = (contiguoussize+3) & (~3); // Round up to 4-byte boundary DASSERT ((contiguoussize & 3) == 0); imagesize_t floatsize = rectangle_values * sizeof(float); scratch.resize (contiguoussize + floatsize + rectangle_bytes); // Force contiguity if not already present if (! contiguous) { data = contiguize (data, m_spec.nchannels, xstride, ystride, zstride, (void *)&scratch[0], width, height, depth, format); } // Rather than implement the entire cross-product of possible // conversions, use float as an intermediate format, which generally // will always preserve enough precision. const float *buf; if (format == TypeDesc::FLOAT) { // Already in float format -- leave it as-is. buf = (float *)data; } else { // Convert to from 'format' to float. buf = convert_to_float (data, (float *)&scratch[contiguoussize], rectangle_values, format); } // Convert from float to native format. return convert_from_float (buf, &scratch[contiguoussize+floatsize], rectangle_values, m_spec.quant_black, m_spec.quant_white, m_spec.quant_min, m_spec.quant_max, m_spec.format); }