Ejemplo n.º 1
0
void KineticController_HandleUnexpectedResponse(void *msg,
        int64_t seq_id,
        void *bus_udata,
        void *socket_udata)
{
    KineticResponse * response = msg;
    KineticSession* session = socket_udata;
    bool connetionInfoReceived = false;
    char const * statusTag = "[PDU RX STATUS]";
    char const * unexpectedTag = "[PDU RX UNEXPECTED]";
    char const * logTag = unexpectedTag;
    int logAtLevel, protoLogAtLevel;

    (void)bus_udata;

    // Handle unsolicited status PDUs
    if (response->proto->authtype == COM__SEAGATE__KINETIC__PROTO__MESSAGE__AUTH_TYPE__UNSOLICITEDSTATUS) {
        int64_t connectionID = KineticResponse_GetConnectionID(response);
        if (connectionID != 0)
        {
            // Store connectionID from unsolicited status message in the session for future requests
            KineticSession_SetConnectionID(session, connectionID);
            LOGF2("Extracted connection ID from unsolicited status PDU (id=%lld)", connectionID);
            connetionInfoReceived = true;
            logTag = statusTag;
            logAtLevel = 2;
            protoLogAtLevel = 3;
        }
        else {
            LOG0("WARNING: Unsolicited status received. Connection being terminated by remote!");
            logTag = statusTag;
            logAtLevel = 0;
            protoLogAtLevel = 0;
            KineticStatus status = KineticResponse_GetStatus(response);
            KineticSession_SetTerminationStatus(session, status);
        }
    }
    else {
        LOG0("WARNING: Received unexpected response!");
        logTag = unexpectedTag;
        logAtLevel = 0;
        protoLogAtLevel = 0;
    }

    KineticLogger_LogPrintf(logAtLevel, "%s pdu: %p, session: %p, bus: %p, "
                            "fd: %6d, seq: %8lld, protoLen: %8u, valueLen: %8u",
                            logTag,
                            (void*)response, (void*)session,
                            (void*)session->messageBus,
                            session->socket, (long long)seq_id,
                            KineticResponse_GetProtobufLength(response),
                            KineticResponse_GetValueLength(response));
    KineticLogger_LogProtobuf(protoLogAtLevel, response->proto);

    KineticAllocator_FreeKineticResponse(response);

    if (connetionInfoReceived) {
        KineticResourceWaiter_SetAvailable(&session->connectionReady);
    }
}
Ejemplo n.º 2
0
void test_KineticAllocator_FreeKineticResponse_should_free_the_proto_if_its_not_null(void)
{
    Com__Seagate__Kinetic__Proto__Message proto;

    KineticResponse rsp = { .proto = &proto};
    protobuf_c_message_free_unpacked_Expect(&proto.base, NULL);

    KineticFree_Expect(&rsp);

    KineticAllocator_FreeKineticResponse(&rsp);
}
Ejemplo n.º 3
0
void test_KineticAllocator_FreeKineticResponse_should_free_the_command_if_its_not_null(void)
{
    Com__Seagate__Kinetic__Proto__Command command;

    KineticResponse rsp = { .command = &command};
    protobuf_c_message_free_unpacked_Expect(&command.base, NULL);

    KineticFree_Expect(&rsp);

    KineticAllocator_FreeKineticResponse(&rsp);
}