Exemple #1
0
void ShuffleRound::ProcessData(const QByteArray &data, const Id &id)
{
    QByteArray payload;
    if(!Verify(data, payload, id)) {
        return;
    }

    QDataStream stream(payload);
    int mtype;

    QByteArray session_id;
    stream >> mtype >> session_id;

    MessageType msg_type = (MessageType) mtype;

    Id sid(session_id);
    if(sid != GetId()) {
        qWarning() << "Invalid session, expected " << GetId().ToString()
                   << ", found " << sid.ToString();
        return;
    }

    _in_log.Append(data, id);

    switch(msg_type) {
    case PublicKeys:
        HandlePublicKeys(stream, id);
        break;
    case Data:
        HandleData(stream, id);
        break;
    case ShuffleData:
        HandleShuffle(stream, id);
        break;
    case EncryptedData:
        HandleDataBroadcast(stream, id);
        break;
    case GoMessage:
        HandleVerification(true, id);
        break;
    case NoGoMessage:
        HandleVerification(false, id);
        break;
    case PrivateKey:
        HandlePrivateKey(stream, id);
        break;
    default:
        qWarning() << "Unknown message type: " << MessageTypeToString(msg_type)
                   << " from " << id.ToString();
        return;
    }
}
Exemple #2
0
void Message::print(ostream& os, Boolean printHeader) const
{
    if (printHeader)
    {
        os << "Message\n";
        os << "{";
    }

    os << "    messageType: " << MessageTypeToString(_type) << endl;

    if (printHeader)
    {
        os << "}";
    }
}
Exemple #3
0
void MessageQueue::enqueue(Message* message)
{
    PEG_METHOD_ENTER(TRC_MESSAGEQUEUESERVICE,"MessageQueue::enqueue()");

    PEGASUS_ASSERT(message != 0);

    PEG_TRACE((TRC_MESSAGEQUEUESERVICE, Tracer::LEVEL3,
        "Queue name: [%s], Message: [%s]",
        getQueueName(),
        MessageTypeToString(message->getType())));

    _messageList.insert_back(message);

    handleEnqueue();
    PEG_METHOD_EXIT();
}
Exemple #4
0
void MessageQueue::enqueue(Message* message)
{
    PEG_METHOD_ENTER(TRC_MESSAGEQUEUESERVICE,"MessageQueue::enqueue()");

    if (!message)
    {
        Tracer::trace(TRC_MESSAGEQUEUESERVICE, Tracer::LEVEL3,
                    "MessageQueue::enqueue failure");
        PEG_METHOD_EXIT();
        throw NullPointer();
    }

    PEG_TRACE_STRING( TRC_MESSAGEQUEUESERVICE, Tracer::LEVEL3,
                      String("Queue name: ") + getQueueName() ) ;
    Tracer::trace   ( TRC_MESSAGEQUEUESERVICE,
                      Tracer::LEVEL3,
                      "Message: [%s, %d]",
                      MessageTypeToString(message->getType()),
                      message->getKey() );

    {
    AutoMutex autoMut(_mut);
    if (_back)
    {
        _back->_next = message;
        message->_prev = _back;
        message->_next = 0;
        _back = message;
    }
    else
    {
        _front = message;
        _back = message;
        message->_prev = 0;
        message->_next = 0;
    }
    message->_owner = this;

    _count++;
    Tracer::trace(TRC_MESSAGEQUEUESERVICE, Tracer::LEVEL4,
                  "MessageQueue::enqueue _queueId = %d, _count = %d", _queueId, _count);

    } // mutex unlocks here

    handleEnqueue();
    PEG_METHOD_EXIT();
}
//// KS_FUTURE make DEBUG compile only
// Diagnostic display of data in the enumeration context object
void EnumerationContext::trace()
{
    PEGASUS_DEBUG_ASSERT(valid());
    PEG_TRACE((TRC_ENUMCONTEXT, Tracer::LEVEL3,
        "EnumerationContextTrace ContextId=%s "
        "requestOperationTimeOut=%u "
        "operationTimer=%lu sec "
        "continueOnError=%s "
        "pullMsgType=%s "
        "processingState=%s "
        "providersComplete=%s "
        "closed=%s "
        "timeOpen=%lu ms "
        "totalPullCount=%u "
        "cacheHighWaterMark=%u "
        "Request count=%u "
        "ResponseObjectCount=%u "
        "totalWaitTimeUsec=%llu "
        "maxWaitTimeUsec=%llu "
        "RequestedResponseObjectCount=%u "
        "consecutiveZeroLenObjectResponseCtr=%u "
        "totalZeroLenObjectResponseCounter=%u"
        "ResponseCacheSize=%u",
        *Str(getContextId()),
        _operationTimeoutSec,
        (long unsigned int)_operationTimerUsec,
        boolToString(_continueOnError),
        MessageTypeToString(_pullRequestType),
        processingState(),
        boolToString(_providersComplete),
        boolToString(_clientClosed),
        (long unsigned int)
            (System::getCurrentTimeUsec() - _startTimeUsec)/1000,
        _pullOperationCounter,
        _cacheHighWaterMark,
        _requestCount,
        _responseObjectsCount,
        _totalWaitTimeUsec,
        _maxWaitTimeUsec,
        _requestedResponseObjectsCount,
        _consecutiveZeroLenObjectResponseCounter,
        _totalZeroLenObjectResponseCounter,
         responseCacheSize()));
}
void CIMExportRequestDispatcher::_handle_async_request(AsyncRequest *req)
{
   PEG_METHOD_ENTER(TRC_EXP_REQUEST_DISP,
      "CIMExportRequestDispatcher::_handle_async_request");

    PEGASUS_ASSERT(req != 0 && req->op != 0);

    if (req->getType() == ASYNC_CIMSERVICE_STOP)
    {
        handle_CimServiceStop(static_cast<CimServiceStop *>(req));
    }
    else if (req->getType() == ASYNC_ASYNC_LEGACY_OP_START)
    {
        Message *legacy =
            (static_cast<AsyncLegacyOperationStart *>(req)->get_action());
        if (legacy->getType() == CIM_EXPORT_INDICATION_REQUEST_MESSAGE)
        {
            Message* legacy_response = _handleExportIndicationRequest(
                (CIMExportIndicationRequestMessage*) legacy);
            // constructor puts itself into a linked list, DO NOT remove the new
            new AsyncLegacyOperationResult(req->op, legacy_response);

            _complete_op_node(req->op);
            delete legacy;
        }
        else
        {
            PEG_TRACE((TRC_DISCARDED_DATA, Tracer::LEVEL1,
                "CIMExportRequestDispatcher::_handle_async_request got "
                    "unexpected legacy message type '%s'",
                MessageTypeToString(legacy->getType())));
            _make_response(req, async_results::CIM_NAK);
            delete legacy;
        }
    }
    else
    {
        Base::_handle_async_request(req);
    }
    PEG_METHOD_EXIT();
}
Exemple #7
0
bool Message::save(core::data & da) const
{
    xmlnode_t node("message");
    
    xmlattr_t* attr = node.add_attr("from");
    attr->value = from.full();
    
    attr = node.add_attr("to");
    attr->value = to.bare();
    
    attr = node.add_attr("type");
    attr->value = MessageTypeToString(type);
    
    attr = node.add_attr("xml:lang");
    attr->value = "utf-8";
    
    xmlnode_t* child = node.add_node("body");
    child->value = content;
    
    return node.save(da);
}
/*
    Insert complete CIMResponseData entities into the cache. If the
    cache is at its max size limit, and there are more provider responses
    wait until it the size drops below the full limit.
    If the operation is closed, ignore the response.
    Return true if putCache worked, false if closed and nothing put into
    the cache.
    NOTE: This function assumes that responses for a request are serialized
    in _enqueueResponse See _enqueueResponseMutex.
*/
bool EnumerationContext::putCache(CIMResponseMessage*& response,
    bool providersComplete)
{
    PEG_METHOD_ENTER(TRC_ENUMCONTEXT, "EnumerationContext::putCache");

    PEGASUS_DEBUG_ASSERT(valid());

    // Design error if we ever get here with providers already set complete
    PEGASUS_DEBUG_ASSERT(!_providersComplete);

    CIMResponseDataMessage* localResponse =
        dynamic_cast<CIMResponseDataMessage*>(response);
    CIMResponseData & from = localResponse->getResponseData();
    //// from.traceResponseData();

    // If there is any binary data, reformat it to SCMO.  There are no
    // size counters for the binary data so reformat to generate
    // counters and make it compatible with the cache access mechanisms
    if (from.hasBinaryData())
    {
        from.resolveBinaryToSCMO();
        //// from.traceResponseData();
    }

#ifdef ENUMERATION_CONTEXT_DIAGNOSTIC_TRACE
    PEG_TRACE((TRC_ENUMCONTEXT, Tracer::LEVEL4,
        "putCache, ContextId=%s isComplete=%s cacheResponseDataType=%u "
            " cacheSize=%u putSize=%u putResponseDataType=%u clientClosed=%s",
        *Str(getContextId()),
        boolToString(providersComplete),
        _responseCache.getResponseDataContent(),
        _responseCache.size(), from.size(), from.getResponseDataContent(),
        boolToString(_clientClosed)));
#endif

    // This test should not be required.  Somewhere in the processing there
    // is a rare return of an erronous response from OOP. This covers that
    // case until we find the issue.  It issues an error a discard trace
    if (from.getResponseDataContent()!=_responseCache.getResponseDataContent())
    {
        PEG_TRACE((TRC_DISCARDED_DATA, Tracer::LEVEL2,
            "Pull Provider Response DataContentType in error. cacheType=%u "
            "responseType=%u "
            "ResponseMsgType=%s ContextId=%s",
            _responseCache.getResponseDataContent(),
            from.getResponseDataContent(),
            MessageTypeToString(response->getType()),
            *Str(getContextId()) ));
        trace();
        // This is temp for testing. KS_TODO delete this console display
        //// cout << System::getCurrentASCIITime()
        ////      << "Error CIMResponseDataMismatch "
        ////     << getContextId() << endl;

        CIMException sysErr = CIMException(CIM_ERR_FAILED,
            "Internal Error in EnumerationContext processing");
        setErrorState(sysErr);
        // Output warning log to indicate that this system failure has occurred

        Logger::put(
                Logger::ERROR_LOG, System::CIMSERVER, Logger::WARNING,
                "Response msg data type mismatch from providers."
                "Internal Error in EnumerationContext processing. "
                " ContextId=", *Str(getContextId() ));
        return _clientClosed;

    }
    // If an operation has closed the enumerationContext
    // ignore any received responses until the providersComplete is received
    // and then remove the Context.
    if (_clientClosed)
    {
        PEG_METHOD_EXIT();
        return false;
    }
    else  // client not closed
    {
        // put the current response into the cache. Lock cache for this
        // operation

        _responseCache.appendResponseData(from);

        // set providersComplete flag from flag in call parameter.
        _providersComplete = providersComplete;

        // test and set the high water mark for this cache.
        if (responseCacheSize() > _cacheHighWaterMark)
        {
            _cacheHighWaterMark = responseCacheSize();
        }
    }

    // Return true indicating that input added to cache and cache is still open
    PEG_METHOD_EXIT();
    return true;
}
Message* BasicProviderManagerRouter::processMessage(Message * message)
{
    PEG_METHOD_ENTER(TRC_PROVIDERMANAGER,
                     "BasicProviderManagerRouter::processMessage");

    CIMRequestMessage* request = dynamic_cast<CIMRequestMessage *>(message);
    PEGASUS_ASSERT(request != 0);

    Message* response = 0;
    Boolean remoteNameSpaceRequest=false;
    Boolean loadProviderManager=true;

    //
    // Retrieve the ProviderManager routing information
    //

    CIMInstance providerModule;

    if ((dynamic_cast<CIMOperationRequestMessage*>(request) != 0) ||
            (request->getType() == CIM_EXPORT_INDICATION_REQUEST_MESSAGE))
    {
        // Provider information is in OperationContext
        ProviderIdContainer pidc = (ProviderIdContainer)
                                   request->operationContext.get(ProviderIdContainer::NAME);
        providerModule = pidc.getModule();
        remoteNameSpaceRequest=pidc.isRemoteNameSpace();
    }
    else if (dynamic_cast<CIMIndicationRequestMessage*>(request) != 0)
    {
        // Provider information is in CIMIndicationRequestMessage
        CIMIndicationRequestMessage* indReq =
            dynamic_cast<CIMIndicationRequestMessage*>(request);
        ProviderIdContainer pidc =
            indReq->operationContext.get(ProviderIdContainer::NAME);
        providerModule = pidc.getModule();
    }
    else if (request->getType() == CIM_ENABLE_MODULE_REQUEST_MESSAGE)
    {
        // Provider information is in CIMEnableModuleRequestMessage
        CIMEnableModuleRequestMessage* emReq =
            dynamic_cast<CIMEnableModuleRequestMessage*>(request);
        providerModule = emReq->providerModule;
        // Do not try to load the provider manager module if not already loaded.
        loadProviderManager=false;
    }
    else if (request->getType() == CIM_DISABLE_MODULE_REQUEST_MESSAGE)
    {
        // Provider information is in CIMDisableModuleRequestMessage
        CIMDisableModuleRequestMessage* dmReq =
            dynamic_cast<CIMDisableModuleRequestMessage*>(request);
        providerModule = dmReq->providerModule;
        // Do not try to load the provider manager module if not already loaded.
        loadProviderManager=false;
    }
    else if ((request->getType() == CIM_STOP_ALL_PROVIDERS_REQUEST_MESSAGE) ||
             (request->getType() ==
              CIM_SUBSCRIPTION_INIT_COMPLETE_REQUEST_MESSAGE) ||
             (request->getType() ==
              CIM_INDICATION_SERVICE_DISABLED_REQUEST_MESSAGE) ||
             (request->getType() == CIM_NOTIFY_CONFIG_CHANGE_REQUEST_MESSAGE))
    {
        // This operation is not provider-specific
    }
    else
    {
        // Error: Unrecognized message type.
        PEGASUS_ASSERT(0);
        CIMResponseMessage* resp = request->buildResponse();
        resp->cimException = PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED,
                             "Unknown message type.");
        response = resp;
    }

    //
    // Forward the request to the appropriate ProviderManager(s)
    //

    if ((request->getType() == CIM_STOP_ALL_PROVIDERS_REQUEST_MESSAGE) ||
            (request->getType() ==
             CIM_SUBSCRIPTION_INIT_COMPLETE_REQUEST_MESSAGE) ||
            (request->getType() ==
             CIM_INDICATION_SERVICE_DISABLED_REQUEST_MESSAGE))
    {
        if (request->getType() ==
                CIM_INDICATION_SERVICE_DISABLED_REQUEST_MESSAGE)
        {
            _subscriptionInitComplete = false;
        }
        else
        {
            _subscriptionInitComplete = true;
        }

        // Send CIMStopAllProvidersRequestMessage or
        // CIMIndicationServiceDisabledRequestMessage or
        // CIMSubscriptionInitCompleteRequestMessage to all ProviderManagers
        ReadLock tableLock(_providerManagerTableLock);
        for (Uint32 i = 0, n = _providerManagerTable.size(); i < n; i++)
        {
            ProviderManagerContainer* pmc=_providerManagerTable[i];
            Message* resp = pmc->getProviderManager()->processMessage(request);
            delete resp;
        }

        response = request->buildResponse();
    }
    else if (request->getType() == CIM_NOTIFY_CONFIG_CHANGE_REQUEST_MESSAGE)
    {
        // Do not need to forward this request to in-process provider
        // managers
        response = request->buildResponse();
    }
    else
    {
        // Retrieve the provider interface type
        String interfaceType;
        CIMValue itValue = providerModule.getProperty(
                               providerModule.findProperty("InterfaceType")).getValue();
        itValue.get(interfaceType);
        // Get providerManager path
        String provMgrPath;
        if (request->operationContext.contains(ProviderIdContainer::NAME))
        {
            ProviderIdContainer pidc = (ProviderIdContainer)
                                       request->operationContext.get(ProviderIdContainer::NAME);
            provMgrPath = pidc.getProvMgrPath();
        }

        ProviderManager* pm = 0;
        try
        {
            // Look up the appropriate ProviderManager by InterfaceType

            pm = _getProviderManager(
                     interfaceType,
                     provMgrPath,
                     loadProviderManager);
        }
        catch (const CIMException& e)
        {
            CIMResponseMessage *cimResponse = request->buildResponse();
            cimResponse->cimException = e;
            response = cimResponse;
        }

        // Incase of CIMEnableModuleRequestMessage or
        // CIMDisableModuleRequestMessage, there must be not necessarily
        // a running provider manager. This is not an error.
        // This means there is no provider to enable or disable.
        if (0 == pm)
        {
            if (request->getType() == CIM_ENABLE_MODULE_REQUEST_MESSAGE)
            {
                CIMEnableModuleResponseMessage* emResponse =
                    dynamic_cast<CIMEnableModuleResponseMessage*>(
                        request->buildResponse());
                emResponse->operationalStatus.append(
                    CIM_MSE_OPSTATUS_VALUE_OK);
                response = emResponse;
            }
            else if (request->getType() == CIM_DISABLE_MODULE_REQUEST_MESSAGE)
            {
                CIMDisableModuleResponseMessage* dmResponse =
                    dynamic_cast<CIMDisableModuleResponseMessage*>(
                        request->buildResponse());
                dmResponse->operationalStatus.append(
                    CIM_MSE_OPSTATUS_VALUE_STOPPED);
                response = dmResponse;
            }
            else
            {
                CIMResponseMessage* resp = request->buildResponse();
                resp->cimException =
                    PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED,
                                          "There is no Provider Manager for interfaceType '" +
                                          interfaceType + ". The request message type is '" +
                                          String(MessageTypeToString(request->getType())) + "'");

                PEG_TRACE((TRC_PROVIDERMANAGER,Tracer::LEVEL1,"%s",
                           (const char*)resp->cimException.getMessage().getCString()));

                response = resp;
            }
        }
        else
        {
            if ( remoteNameSpaceRequest && !pm->supportsRemoteNameSpaces())
            {
                CIMResponseMessage* resp = request->buildResponse();
                resp->cimException = PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED,
                                     "Remote Namespace operations not supported for interface type "
                                     + interfaceType);
                response = resp;
            }
            else
            {
                response = pm->processMessage(request);
            }
        }
    }

    PEG_METHOD_EXIT();
    return response;
}
void DynamicListenerIndicationDispatcher::handleEnqueue(Message* message)
{
    PEG_METHOD_ENTER(
        TRC_LISTENER,
        "DynamicListenerIndicationDispatcher::handleEnqueue");

    if (message!=NULL)
    {
        switch (message->getType())
        {
        case CIM_EXPORT_INDICATION_REQUEST_MESSAGE:
            {
                CIMExportIndicationRequestMessage* request = 
                    (CIMExportIndicationRequestMessage*)message;
                CIMException cimException;

                try
                {
                    _handleIndicationRequest(request);

                } catch (Exception& ex)
                {
                    cimException = CIMException(
                                       CIM_ERR_FAILED,
                                       ex.getMessage());

                    Logger::put(
                               Logger::ERROR_LOG,
                               System::CIMLISTENER,
                               Logger::SEVERE,
                               "Exception getting consumer: $0", 
                               ex.getMessage());

                } catch (...)
                {
                    cimException = CIMException(
                                       CIM_ERR_FAILED,
                                       "Unknown exception");

                    Logger::put(
                               Logger::ERROR_LOG,
                               System::CIMLISTENER,
                               Logger::SEVERE,
                               "Unknown Exception getting consumer");
                }

                /** At this point (barring one of the above exceptions), 
                 * we can be reasonably sure that the indication will get 
                 * delivered and processed. The request was well-formatted and
                 * we were able to locate and load the consumer.
                 * Send an acknowledgement to the client that we received 
                 * the indication. 
                 * We should not wait until the consumer reports ultimate 
                 * success since that could take a long time and would require 
                 * us to store a bunch of status information.  
                 * Additionally, the wait could cause a timeout exception 
                 * on the client end.

                 */
                // ATTN: Why isn't the CIM exception getting appended 
                // to the response?  Go look in Message.h
                CIMResponseMessage* response = request->buildResponse();
                response->cimException = cimException;
                response->dest = request->queueIds.top();
                _enqueueResponse(request, response);
            }
            break;
        default:
            {
                // unsupported message type
                // it should not get here; 
                // this error is caught in the request decoder
                PEG_TRACE((TRC_LISTENER,Tracer::LEVEL2, 
                    "Unsupported msg type: %s",
                    MessageTypeToString(message->getType())));

                CIMRequestMessage* cimRequest = 
                    dynamic_cast<CIMRequestMessage*>(message);

                CIMResponseMessage* response = cimRequest->buildResponse();
                response->cimException = 
                    PEGASUS_CIM_EXCEPTION_L(
                        CIM_ERR_FAILED,
                        MessageLoaderParms(
                            "DynListener.DynamicListenerIndicationDispatcher"
                                ".INVALID_MSG_TYPE",
                            "Invalid message type"));

                _enqueueResponse (cimRequest, response);
            }
            break;
        }   
        delete message;
    }

    PEG_METHOD_EXIT();
}