Exemple #1
0
void SchemaMethodImpl::encode(Buffer& buffer) const
{
    FieldTable map;

    map.setString("name", name);
    map.setInt("argCount", arguments.size());
    if (!description.empty())
        map.setString("desc", description);
    map.encode(buffer);

    for (vector<const SchemaArgument*>::const_iterator iter = arguments.begin();
         iter != arguments.end(); iter++)
        (*iter)->impl->encode(buffer);
}
void MessageTransfer::processProperties(qpid::amqp::MapHandler& handler) const
{
    const qpid::framing::MessageProperties* mp = getProperties<qpid::framing::MessageProperties>();
    if (mp && mp->hasApplicationHeaders()) {
        const FieldTable ft = mp->getApplicationHeaders();
        for (FieldTable::const_iterator i = ft.begin(); i != ft.end(); ++i) {
            qpid::types::Variant v;
            qpid::amqp_0_10::translate(i->second, v);
            qpid::amqp::CharSequence key = {i->first.data(), i->first.size()};
            switch (v.getType()) {
            case qpid::types::VAR_VOID:
                handler.handleVoid(key); break;
            case qpid::types::VAR_BOOL:
                handler.handleBool(key, v); break;
            case qpid::types::VAR_UINT8:
                handler.handleUint8(key, v); break;
            case qpid::types::VAR_UINT16:
                handler.handleUint8(key, v); break;
            case qpid::types::VAR_UINT32:
                handler.handleUint32(key, v); break;
            case qpid::types::VAR_UINT64:
                handler.handleUint64(key, v); break;
            case qpid::types::VAR_INT8:
                handler.handleInt8(key, v); break;
            case qpid::types::VAR_INT16:
                handler.handleInt16(key, v); break;
            case qpid::types::VAR_INT32:
                handler.handleInt32(key, v); break;
            case qpid::types::VAR_INT64:
                handler.handleInt64(key, v); break;
            case qpid::types::VAR_FLOAT:
                handler.handleFloat(key, v); break;
            case qpid::types::VAR_DOUBLE:
                handler.handleDouble(key, v); break;
            case qpid::types::VAR_STRING: {
                std::string s(v);
                qpid::amqp::CharSequence value = {s.data(), s.size()};
                qpid::amqp::CharSequence encoding = {0, 0};
                handler.handleString(key, value, encoding);
                break;
            }
            case qpid::types::VAR_MAP:
            case qpid::types::VAR_LIST:
            case qpid::types::VAR_UUID:
                 QPID_LOG(debug, "Unhandled key!" << v);
                 break;
            }
        }
    }
}
Exemple #3
0
SchemaMethodImpl::SchemaMethodImpl(Buffer& buffer)
{
    FieldTable map;
    int argCount;

    map.decode(buffer);
    name = map.getAsString("name");
    argCount = map.getAsInt("argCount");
    description = map.getAsString("desc");

    for (int idx = 0; idx < argCount; idx++) {
        SchemaArgument* arg = SchemaArgumentImpl::factory(buffer);
        addArgument(arg);
    }
}
Exemple #4
0
SchemaPropertyImpl::SchemaPropertyImpl(Buffer& buffer)
{
    FieldTable map;
    map.decode(buffer);

    name = map.getAsString("name");
    typecode = (Typecode) map.getAsInt("type");
    access = (Access) map.getAsInt("access");
    index = map.getAsInt("index") != 0;
    optional = map.getAsInt("optional") != 0;
    unit = map.getAsString("unit");
    description = map.getAsString("desc");
}
Exemple #5
0
ValueImpl::ValueImpl(Typecode t, Buffer& buf) : typecode(t)
{
    uint64_t first;
    uint64_t second;
    FieldTable ft;
    List fl;

    switch (typecode) {
    case TYPE_UINT8     : value.u32 = (uint32_t) buf.getOctet();  break;
    case TYPE_UINT16    : value.u32 = (uint32_t) buf.getShort();  break;
    case TYPE_UINT32    : value.u32 = (uint32_t) buf.getLong();   break;
    case TYPE_UINT64    : value.u64 = buf.getLongLong();          break;
    case TYPE_SSTR      : buf.getShortString(stringVal);          break;
    case TYPE_LSTR      : buf.getMediumString(stringVal);         break;
    case TYPE_ABSTIME   : value.s64 = buf.getLongLong();          break;
    case TYPE_DELTATIME : value.u64 = buf.getLongLong();          break;
    case TYPE_BOOL      : value.boolVal = (buf.getOctet() != 0);  break;
    case TYPE_FLOAT     : value.floatVal = buf.getFloat();        break;
    case TYPE_DOUBLE    : value.doubleVal = buf.getDouble();      break;
    case TYPE_INT8      : value.s32 = (int32_t) ((int8_t) buf.getOctet()); break;
    case TYPE_INT16     : value.s32 = (int32_t) ((int16_t) buf.getShort()); break;
    case TYPE_INT32     : value.s32 = (int32_t) buf.getLong();    break;
    case TYPE_INT64     : value.s64 = buf.getLongLong();          break;
    case TYPE_UUID      : buf.getBin128(value.uuidVal);           break;
    case TYPE_REF:
        first = buf.getLongLong();
        second = buf.getLongLong();
        refVal.impl->setValue(first, second);
        break;

    case TYPE_MAP:
        ft.decode(buf);
        initMap(ft);
        break;

    case TYPE_LIST:
        fl.decode(buf);
        initList(fl);
        break;

    case TYPE_ARRAY:
    case TYPE_OBJECT:
    default:
        break;
    }
}
Exemple #6
0
uint32_t ValueImpl::encodedSize() const
{
    FieldTable ft;
    List fl;

    switch (typecode) {
    case TYPE_UINT8     :
    case TYPE_BOOL      :
    case TYPE_INT8      : return 1;
 
    case TYPE_UINT16    :
    case TYPE_INT16     : return 2;

    case TYPE_UINT32    :
    case TYPE_INT32     :
    case TYPE_FLOAT     : return 4;

    case TYPE_UINT64    :
    case TYPE_INT64     :
    case TYPE_DOUBLE    :
    case TYPE_ABSTIME   :
    case TYPE_DELTATIME : return 8;

    case TYPE_UUID      : 
    case TYPE_REF       : return 16;

    case TYPE_SSTR      : return 1 + stringVal.size();
    case TYPE_LSTR      : return 2 + stringVal.size();
    case TYPE_MAP:
        mapToFieldTable(ft);
        return ft.encodedSize();

    case TYPE_LIST:
        listToFramingList(fl);
        return fl.encodedSize();

    case TYPE_ARRAY:
    case TYPE_OBJECT:
    default:
        break;
    }

    return 0;
}
Exemple #7
0
ConnectionHandler::Handler::Handler(Connection& c, bool isClient) :
    proxy(c.getOutput()),
    connection(c), serverMode(!isClient), secured(0),
    isOpen(false)
{
    if (serverMode) {
        FieldTable properties;
        Array mechanisms(0x95);

        properties.setString(QPID_FED_TAG, connection.getBroker().getFederationTag());

        authenticator = SaslAuthenticator::createAuthenticator(c);
        authenticator->getMechanisms(mechanisms);

        Array locales(0x95);
        boost::shared_ptr<FieldValue> l(new Str16Value(en_US));
        locales.add(l);
        proxy.start(properties, mechanisms, locales);
    }

    maxFrameSize = (64 * 1024) - 1;
}
Exemple #8
0
void SchemaArgumentImpl::encode(Buffer& buffer) const
{
    FieldTable map;

    map.setString("name", name);
    map.setInt("type", (int) typecode);
    if (dir == DIR_IN)
        map.setString("dir", "I");
    else if (dir == DIR_OUT)
        map.setString("dir", "O");
    else
        map.setString("dir", "IO");
    if (!unit.empty())
        map.setString("unit", unit);
    if (!description.empty())
        map.setString("desc", description);

    map.encode(buffer);
}
Exemple #9
0
void ValueImpl::encode(Buffer& buf) const
{
    FieldTable ft;
    List fl;

    switch (typecode) {
    case TYPE_UINT8     : buf.putOctet((uint8_t) value.u32);        break;
    case TYPE_UINT16    : buf.putShort((uint16_t) value.u32);       break;
    case TYPE_UINT32    : buf.putLong(value.u32);                   break;
    case TYPE_UINT64    : buf.putLongLong(value.u64);               break;
    case TYPE_SSTR      : buf.putShortString(stringVal);            break;
    case TYPE_LSTR      : buf.putMediumString(stringVal);           break;
    case TYPE_ABSTIME   : buf.putLongLong(value.s64);               break;
    case TYPE_DELTATIME : buf.putLongLong(value.u64);               break;
    case TYPE_BOOL      : buf.putOctet(value.boolVal ? 1 : 0);      break;
    case TYPE_FLOAT     : buf.putFloat(value.floatVal);             break;
    case TYPE_DOUBLE    : buf.putDouble(value.doubleVal);           break;
    case TYPE_INT8      : buf.putOctet((uint8_t) value.s32);        break;
    case TYPE_INT16     : buf.putShort((uint16_t) value.s32);       break;
    case TYPE_INT32     : buf.putLong(value.s32);                   break;
    case TYPE_INT64     : buf.putLongLong(value.s64);               break;
    case TYPE_UUID      : buf.putBin128(value.uuidVal);             break;
    case TYPE_REF       : refVal.impl->encode(buf);                 break;
    case TYPE_MAP:
        mapToFieldTable(ft);
        ft.encode(buf);
        break;
    case TYPE_LIST:
        listToFramingList(fl);
        fl.encode(buf);
        break;

    case TYPE_ARRAY:
    case TYPE_OBJECT:
    default:
        break;
    }
}
Exemple #10
0
void SchemaPropertyImpl::encode(Buffer& buffer) const
{
    FieldTable map;

    map.setString("name", name);
    map.setInt("type", (int) typecode);
    map.setInt("access", (int) access);
    map.setInt("index", index ? 1 : 0);
    map.setInt("optional", optional ? 1 : 0);
    if (!unit.empty())
        map.setString("unit", unit);
    if (!description.empty())
        map.setString("desc", description);

    map.encode(buffer);
}
Exemple #11
0
SchemaStatisticImpl::SchemaStatisticImpl(Buffer& buffer)
{
    FieldTable map;
    map.decode(buffer);

    name = map.getAsString("name");
    typecode = (Typecode) map.getAsInt("type");
    unit = map.getAsString("unit");
    description = map.getAsString("desc");
}
Exemple #12
0
void SchemaStatisticImpl::encode(Buffer& buffer) const
{
    FieldTable map;

    map.setString("name", name);
    map.setInt("type", (int) typecode);
    if (!unit.empty())
        map.setString("unit", unit);
    if (!description.empty())
        map.setString("desc", description);

    map.encode(buffer);
}
Exemple #13
0
SchemaArgumentImpl::SchemaArgumentImpl(Buffer& buffer)
{
    FieldTable map;
    map.decode(buffer);

    name = map.getAsString("name");
    typecode = (Typecode) map.getAsInt("type");
    unit = map.getAsString("unit");
    description = map.getAsString("desc");

    dir = DIR_IN;
    string dstr(map.getAsString("dir"));
    if (dstr == "O")
        dir = DIR_OUT;
    else if (dstr == "IO")
        dir = DIR_IN_OUT;
}
Exemple #14
0
void translate(const Variant::Map& from, const std::string& efield, const Variant& evalue, FieldTable& to)
{
    // Create buffer of correct size to encode Variant::Map
    uint32_t len = encodedSize(from, efield, evalue);
    std::vector<char> space(len);
    qpid::framing::Buffer buff(&space[0], len);

    // Encode Variant::Map into buffer directly -
    // We pass the already calculated length in to avoid
    // recalculating it.
    encode(from, efield, evalue, len, buff);

    // Give buffer to FieldTable
    // Could speed this up a bit by avoiding copying
    // the buffer we just created into the FieldTable
    assert( len == buff.getPosition() );
    buff.reset();
    to.decode(buff);
}
Exemple #15
0
SIRE_OUTOFLINE_TEMPLATE
void Intra2B2G3DFF<Potential>::field(FieldTable &fieldtable, const Symbol &component,
                                     const Probe &prob, double scale_field)
{
    if (scale_field == 0)
        return;

    const typename Potential::Probe probe = prob.convertTo<typename Potential::Probe>();

    const int nfieldmols = fieldtable.nMolecules();
    const int nmols0 = this->mols[0].count();
    const int nmols1 = this->mols[1].count();
    const int ngrids = fieldtable.nGrids();
    
    typename Potential::FieldWorkspace workspace;
    
    MolFieldTable *fieldtable_array = fieldtable.moleculeData();
    const ChunkedVector<typename Potential::Molecule> &mols0_array 
                            = this->mols[0].moleculesByIndex();
    const ChunkedVector<typename Potential::Molecule> &mols1_array
                            = this->mols[1].moleculesByIndex();
    
    for (int i=0; i<nfieldmols; ++i)
    {
        MolFieldTable &moltable = fieldtable_array[i];
        
        MolNum molnum = moltable.molNum();
        
        if (this->mols[0].contains(molnum) and this->mols[1].contains(molnum))
        {
            int imol0 = this->mols[0].indexOf(molnum);
            int imol1 = this->mols[1].indexOf(molnum);
            
            const typename Potential::Molecule &mol0 = mols0_array[imol0];
            const typename Potential::Molecule &mol1 = mols1_array[imol1];

            //calculate the field on mols[0] caused by mols[1]
            Potential::calculateField(mol0, mol1, probe, moltable, 
                                      component, this->components(),
                                      workspace, scale_field);
                                      
            //now add on the forces on mols[1] caused by mols[0]
            Potential::calculateField(mol1, mol0, probe, moltable,
                                      component, this->components(),
                                      workspace, scale_field);
        }
    }

    if (ngrids > 0)
    {
        GridFieldTable *gridtable_array = fieldtable.gridData();
        
        for (int i=0; i<ngrids; ++i)
        {
            GridFieldTable &gridtable = gridtable_array[i];
            
            for (int j=0; j<nmols0; ++j)
            {
                const typename Potential::Molecule &mol = mols0_array[j];
                    
                Potential::calculateField(mol, probe, gridtable,
                                          component, this->components(),
                                          workspace, scale_field);
            }
            
            for (int j=0; j<nmols1; ++j)
            {
                const typename Potential::Molecule &mol = mols1_array[j];
                    
                Potential::calculateField(mol, probe, gridtable,
                                          component, this->components(),
                                          workspace, scale_field);
            }
        }
    }
}
Exemple #16
0
void ValueImpl::initMap(const FieldTable& ft)
{
    for (FieldTable::ValueMap::const_iterator iter = ft.begin();
         iter != ft.end(); iter++) {
        const string&     name(iter->first);
        const FieldValue& fvalue(*iter->second);
        uint8_t amqType = fvalue.getType();

        if (amqType == 0x32) {
            Value* subval(new Value(TYPE_UINT64));
            subval->setUint64(fvalue.get<int64_t>());
            insert(name.c_str(), subval);
        } else if ((amqType & 0xCF) == 0x02) {
            Value* subval(new Value(TYPE_UINT32));
            switch (amqType) {
            case 0x02 : subval->setUint(fvalue.get<int>()); break;
            case 0x12 : subval->setUint(fvalue.get<int>()); break;
            case 0x22 : subval->setUint(fvalue.get<int>()); break;
            }
            insert(name.c_str(), subval);
        } else if (amqType == 0x31) {   // int64
            Value* subval(new Value(TYPE_INT64));
            subval->setInt64(fvalue.get<int64_t>());
            insert(name.c_str(), subval);
        } else if ((amqType & 0xCF) == 0x01) {  // 0x01:int8, 0x11:int16, 0x21:int21
            Value* subval(new Value(TYPE_INT32));
            subval->setInt((int32_t)fvalue.get<int>());
            insert(name.c_str(), subval);
        } else if (amqType == 0x85 || amqType == 0x95) {
            Value* subval(new Value(TYPE_LSTR));
            subval->setString(fvalue.get<string>().c_str());
            insert(name.c_str(), subval);
        } else if (amqType == 0x23 || amqType == 0x33) {
            Value* subval(new Value(TYPE_DOUBLE));
            subval->setDouble(fvalue.get<double>());
            insert(name.c_str(), subval);
        } else if (amqType == 0xa8) {
            FieldTable subFt;
            bool valid = qpid::framing::getEncodedValue<FieldTable>(iter->second, subFt);
            if (valid) {
                Value* subval(new Value(TYPE_MAP));
                subval->impl->initMap(subFt);
                insert(name.c_str(), subval);
            }
        } else if (amqType == 0xa9) {
            List subList;
            bool valid = qpid::framing::getEncodedValue<List>(iter->second, subList);
            if (valid) {
                Value* subval(new Value(TYPE_LIST));
                subval->impl->initList(subList);
                insert(name.c_str(), subval);
            }
        } else if (amqType == 0x08) {
            Value* subval(new Value(TYPE_BOOL));
            subval->setBool(fvalue.get<int>() ? true : false);
            insert(name.c_str(), subval);
        } else {
            QPID_LOG(error, "Unable to decode unsupported AMQP typecode=" << amqType << " map index=" << name);
        }
    }
}
Exemple #17
0
void ValueImpl::mapToFieldTable(FieldTable& ft) const
{
    FieldTable subFt;

    for (map<string, Value>::const_iterator iter = mapVal.begin();
         iter != mapVal.end(); iter++) {
        const string& name(iter->first);
        const Value& subval(iter->second);

        switch (subval.getType()) {
        case TYPE_UINT8:
        case TYPE_UINT16:
        case TYPE_UINT32:
            ft.setUInt64(name, (uint64_t) subval.asUint());
            break;
        case TYPE_UINT64:
        case TYPE_DELTATIME:
            ft.setUInt64(name, subval.asUint64());
            break;
        case TYPE_SSTR:
        case TYPE_LSTR:
            ft.setString(name, subval.asString());
            break;
        case TYPE_INT64:
        case TYPE_ABSTIME:
            ft.setInt64(name, subval.asInt64());
            break;
        case TYPE_BOOL:
            ft.set(name, FieldTable::ValuePtr(new BoolValue(subval.asBool())));
            break;
        case TYPE_FLOAT:
            ft.setFloat(name, subval.asFloat());
            break;
        case TYPE_DOUBLE:
            ft.setDouble(name, subval.asDouble());
            break;
        case TYPE_INT8:
        case TYPE_INT16:
        case TYPE_INT32:
            ft.setInt(name, subval.asInt());
            break;
        case TYPE_MAP:
            subFt.clear();
            subval.impl->mapToFieldTable(subFt);
            ft.setTable(name, subFt);
            break;
        case TYPE_LIST:
            {
                List subList;
                subval.impl->listToFramingList(subList);
                ft.set(name,
                       ::qpid::framing::FieldTable::ValuePtr(
                                                             new ListValue(
                                                                           subList)));
            } break;
        case TYPE_ARRAY:
        case TYPE_OBJECT:
        case TYPE_UUID:
        case TYPE_REF:
        default:
            break;
        }
    }
 }
Exemple #18
0
void ConnectionHandler::Handler::start(const FieldTable& serverProperties,
                                       const framing::Array& supportedMechanisms,
                                       const framing::Array& /*locales*/)
{
    string requestedMechanism = connection.getAuthMechanism();

    std::string username = connection.getUsername();

    std::string password = connection.getPassword();
    std::string host     = connection.getHost();
    std::string service("qpidd");

    if ( connection.getBroker().isAuthenticating() ) {
        sasl = SaslFactory::getInstance().create( username,
                                                  password,
                                                  service,
                                                  host,
                                                  0,   // TODO -- mgoulish Fri Sep 24 2010
                                                  256,
                                                  false ); // disallow interaction
    }
    std::string supportedMechanismsList;
    Array::const_iterator i;

    /*
      If no specific mechanism has been requested, just make
      a list of all of them, and assert that the one the caller
      requested is there.  ( If *any* are supported! )
    */
    if ( requestedMechanism.empty() ) {
        for ( i = supportedMechanisms.begin(); i != supportedMechanisms.end(); ++i) {
            if (i != supportedMechanisms.begin())
                supportedMechanismsList += SPACE;
            supportedMechanismsList += (*i)->get<std::string>();
        }
    }
    else {
        /*
          The caller has requested a mechanism.  If it's available,
          make sure it ends up at the head of the list.
        */
        for ( i = supportedMechanisms.begin(); i != supportedMechanisms.end(); ++i) {
            string currentMechanism = (*i)->get<std::string>();

            if ( requestedMechanism == currentMechanism ) {
                supportedMechanismsList = currentMechanism + SPACE + supportedMechanismsList;
            } else {
                if (i != supportedMechanisms.begin())
                    supportedMechanismsList += SPACE;
                supportedMechanismsList += currentMechanism;
            }
        }
    }

    if (serverProperties.isSet(QPID_FED_TAG)) {
        connection.setFederationPeerTag(serverProperties.getAsString(QPID_FED_TAG));
    }

    FieldTable ft = connection.getBroker().getLinkClientProperties();
    ft.setInt(QPID_FED_LINK,1);
    ft.setString(QPID_FED_TAG, connection.getBroker().getFederationTag());

    string response;
    if (sasl.get()) {
        const qpid::sys::SecuritySettings& ss = connection.getExternalSecuritySettings();
        if (sasl->start ( requestedMechanism.empty()
                          ? supportedMechanismsList
                          : requestedMechanism,
                          response,
                          & ss )) {
            proxy.startOk ( ft, sasl->getMechanism(), response, en_US );
        } else {
            //response was null
            ConnectionStartOkBody body;
            body.setClientProperties(ft);
            body.setMechanism(sasl->getMechanism());
            //Don't set response, as none was given
            body.setLocale(en_US);
            proxy.send(body);
        }
    }
    else {
        response = ((char)0) + username + ((char)0) + password;
        proxy.startOk ( ft, requestedMechanism, response, en_US );
    }

}