Esempio n. 1
0
void
LSDebugLogIncoming(const char *where, _LSTransportMessage *message)
{
    if (DEBUG_TRACING)
    {
        LSMessageToken token = _LSTransportMessageGetReplyToken(message);
        const char *sender_service_name = _LSTransportMessageGetSenderServiceName(message);
        if (!sender_service_name) sender_service_name = "(null)";
        const char *sender_unique_name = _LSTransportMessageGetSenderUniqueName(message);
        if (!sender_unique_name) sender_unique_name = "(null)";

        if (DEBUG_VERBOSE)
        {
            const char *payload = _LSTransportMessageGetPayload(message); 
            if (!payload) payload = "(null)";

            g_debug("RX: %s token <<%ld>> sender: %s sender_unique: %s payload: %s",
                    where, token, sender_service_name, sender_unique_name, payload);
        }
        else
        {
            g_debug("RX: %s token <<%ld>> sender: %s sender_unique: %s",
                    where, token, sender_service_name, sender_unique_name);
        }
    }
}
Esempio n. 2
0
/** 
* @brief Get the payload of this message.
* 
* @param  message 
* 
* @retval
*/
const char *
LSMessageGetPayload(LSMessage *message)
{
    _LSErrorIfFail(message != NULL, NULL);

    if (message->payload)
    {
        return message->payload;
    }

    message->payload = _LSTransportMessageGetPayload(message->transport_msg);

    return message->payload;
}
Esempio n. 3
0
/**
 *******************************************************************************
 * @brief Get the service name from a "ServceStatus" message. The name is
 * allocated and should be freed.
 *
 * @param  message  IN  message
 *
 * @retval name string on success
 * @retval NULL on error
 *******************************************************************************
 */
char*
LSTransportServiceStatusSignalGetServiceName(_LSTransportMessage *message)
{
    JSchemaInfo schemaInfo;
    jschema_info_init(&schemaInfo, jschema_all(), NULL, NULL);

    LS_ASSERT(_LSTransportMessageGetType(message) == _LSTransportMessageTypeServiceDownSignal
              || _LSTransportMessageGetType(message) == _LSTransportMessageTypeServiceUpSignal);

    char *service_name = NULL;
    jvalue_ref service_name_obj = NULL;
    const char *payload = _LSTransportMessageGetPayload(message);

    if (!payload)
    {
        LOG_LS_ERROR(MSGID_LS_INVALID_JSON, 0, "Unable to get payload from message");
        return NULL;
    }

    /* get the serviceName part of the JSON object */
    jvalue_ref payload_json = jdom_parse(j_cstr_to_buffer(payload),
                                         DOMOPT_NOOPT, &schemaInfo);

    bool ret = jobject_get_exists(payload_json,
                                  J_CSTR_TO_BUF(SERVICE_STATUS_SERVICE_NAME),
                                  &service_name_obj);

    if (ret)
    {
        raw_buffer service_name_buf = jstring_get_fast(service_name_obj);
        service_name = g_strndup(service_name_buf.m_str, service_name_buf.m_len);
    }
    else
    {
        LOG_LS_ERROR(MSGID_LS_INVALID_JSON, 0, "Unable to get service name string from payload: %s", payload);
    }

    j_release(&payload_json);

    return service_name;
}