Example #1
0
static SmartCardDeviceState *smartcard_device_state_new(SpiceCharDeviceInstance *sin)
{
    SmartCardDeviceState *st;
    SpiceCharDeviceCallbacks chardev_cbs = { NULL, };

    chardev_cbs.read_one_msg_from_device = smartcard_read_msg_from_device;
    chardev_cbs.ref_msg_to_client = smartcard_ref_msg_to_client;
    chardev_cbs.unref_msg_to_client = smartcard_unref_msg_to_client;
    chardev_cbs.send_msg_to_client = smartcard_send_msg_to_client;
    chardev_cbs.send_tokens_to_client = smartcard_send_tokens_to_client;
    chardev_cbs.remove_client = smartcard_remove_client;

    st = spice_new0(SmartCardDeviceState, 1);
    st->chardev_st = spice_char_device_state_create(sin,
                                                    0, /* tokens interval */
                                                    ~0, /* self tokens */
                                                    &chardev_cbs,
                                                    st);
    st->reader_id = VSCARD_UNDEFINED_READER_ID;
    st->reader_added = FALSE;
    st->buf_size = APDUBufSize + sizeof(VSCMsgHeader);
    st->buf = spice_malloc(st->buf_size);
    st->buf_pos = st->buf;
    st->buf_used = 0;
    st->scc = NULL;
    return st;
}
ZlibEncoder* zlib_encoder_create(ZlibEncoderUsrContext *usr, int level)
{
    ZlibEncoder *enc;
    int z_ret;

    if (!usr->more_space || !usr->more_input) {
        return NULL;
    }

    enc = spice_new0(ZlibEncoder, 1);

    enc->usr = usr;

    enc->strm.zalloc = Z_NULL;
    enc->strm.zfree = Z_NULL;
    enc->strm.opaque = Z_NULL;

    z_ret = deflateInit(&enc->strm, level);
    enc->last_level = level;
    if (z_ret != Z_OK) {
        red_printf("zlib error");
        free(enc);
        return NULL;
    }

    return enc;
}
Example #3
0
Test *test_new(SpiceCoreInterface *core)
{
    int port = 5912;
    Test *test = spice_new0(Test, 1);
    SpiceServer* server = spice_server_new();

    test->qxl_instance.base.sif = &display_sif.base;
    test->qxl_instance.id = 0;

    test->core = core;
    test->server = server;
    test->wakeup_ms = 1;
    test->cursor_notify = NOTIFY_CURSOR_BATCH;
    // some common initialization for all display tests
    printf("TESTER: listening on port %d (unsecure)\n", port);
    spice_server_set_port(server, port);
    spice_server_set_noauth(server);
    spice_server_init(server, core);

    cursor_init();
    path_init(&path, 0, angle_parts);
    test->has_secondary = 0;
    test->wakeup_timer = core->timer_add(do_wakeup, test);
    return test;
}
SpiceOpenSSLVerify* spice_openssl_verify_new(SSL *ssl, SPICE_SSL_VERIFY_OP verifyop,
                                             const char *hostname,
                                             const char *pubkey, size_t pubkey_size,
                                             const char *subject)
{
    SpiceOpenSSLVerify *v;

    if (!verifyop)
        return NULL;

    v = spice_new0(SpiceOpenSSLVerify, 1);

    v->ssl              = ssl;
    v->verifyop         = verifyop;
    v->hostname         = spice_strdup(hostname);
    v->pubkey           = (char*)spice_memdup(pubkey, pubkey_size);
    v->pubkey_size      = pubkey_size;
    v->subject          = spice_strdup(subject);

    v->all_preverify_ok = 1;

    SSL_set_app_data(ssl, v);
    SSL_set_verify(ssl,
                   SSL_VERIFY_PEER, openssl_verify);

    return v;
}
Example #5
0
static void smartcard_push_reader_add_response(SmartCardChannel *channel, uint32_t reader_id)
{
    ReaderAddResponseItem *rar_item = spice_new0(ReaderAddResponseItem, 1);

    rar_item->base.type = PIPE_ITEM_TYPE_READER_ADD_RESPONSE;
    rar_item->reader_id = reader_id;
    smartcard_channel_pipe_add(channel, &rar_item->base);
}
Example #6
0
static void smartcard_push_vscmsg(SmartCardChannel *channel, VSCMsgHeader *vheader)
{
    MsgItem *msg_item = spice_new0(MsgItem, 1);

    msg_item->base.type = PIPE_ITEM_TYPE_MSG;
    msg_item->vheader = vheader;
    smartcard_channel_pipe_add(channel, &msg_item->base);
}
Example #7
0
static void smartcard_push_error(SmartCardChannel* channel, reader_id_t reader_id, VSCErrorCode error)
{
    ErrorItem *error_item = spice_new0(ErrorItem, 1);

    error_item->base.type = PIPE_ITEM_TYPE_ERROR;
    error_item->reader_id = reader_id;
    error_item->error = error;
    smartcard_channel_pipe_add(channel, &error_item->base);
}
Example #8
0
static MsgItem *smartcard_get_vsc_msg_item(RedChannelClient *rcc, VSCMsgHeader *vheader)
{
    MsgItem *msg_item = spice_new0(MsgItem, 1);

    red_channel_pipe_item_init(rcc->channel, &msg_item->base,
                               PIPE_ITEM_TYPE_SMARTCARD_DATA);
    msg_item->refs = 1;
    msg_item->vheader = vheader;
    return msg_item;
}
Example #9
0
void smartcard_channel_init()
{
    Channel *channel;

    channel = spice_new0(Channel, 1);
    channel->type = SPICE_CHANNEL_SMARTCARD;
    channel->link = smartcard_link;
    channel->shutdown = smartcard_shutdown;
    channel->migrate = smartcard_migrate;
    reds_register_channel(channel);
}
Example #10
0
Lz4EncoderContext* lz4_encoder_create(Lz4EncoderUsrContext *usr)
{
    Lz4Encoder *enc;
    if (!usr->more_space || !usr->more_lines) {
        return NULL;
    }

    enc = spice_new0(Lz4Encoder, 1);
    enc->usr = usr;

    return (Lz4EncoderContext*)enc;
}
G_GNUC_INTERNAL
spice_msg_in *spice_msg_in_new(SpiceChannel *channel)
{
    spice_msg_in *in;

    g_return_val_if_fail(channel != NULL, NULL);

    in = spice_new0(spice_msg_in, 1);
    in->refcount = 1;
    in->channel  = channel;
    return in;
}
Example #12
0
static AsyncCommand *async_command_alloc(RedDispatcher *dispatcher,
                                         RedWorkerMessage message,
                                         uint64_t cookie)
{
    AsyncCommand *async_command = spice_new0(AsyncCommand, 1);

    pthread_mutex_lock(&dispatcher->async_lock);
    async_command->cookie = cookie;
    async_command->message = message;
    ring_add(&dispatcher->async_commands, &async_command->link);
    pthread_mutex_unlock(&dispatcher->async_lock);
    spice_debug("%p", async_command);
    return async_command;
}
Example #13
0
static void smartcard_push_error(RedChannelClient *rcc, uint32_t reader_id, VSCErrorCode error)
{
    ErrorItem *error_item = spice_new0(ErrorItem, 1);

    red_channel_pipe_item_init(rcc->channel, &error_item->base,
                               PIPE_ITEM_TYPE_ERROR);

    error_item->base.type = PIPE_ITEM_TYPE_ERROR;
    error_item->vheader.reader_id = reader_id;
    error_item->vheader.type = VSC_Error;
    error_item->vheader.length = sizeof(error_item->error);
    error_item->error.code = error;
    smartcard_channel_client_pipe_add_push(rcc, &error_item->base);
}
Example #14
0
static SmartCardDeviceState* smartcard_device_state_new()
{
    SmartCardDeviceState *st;

    st = spice_new0(SmartCardDeviceState, 1);
    st->base.wakeup = smartcard_char_device_wakeup;
    st->reader_id = VSCARD_UNDEFINED_READER_ID;
    st->attached = FALSE;
    st->buf_size = APDUBufSize + sizeof(VSCMsgHeader);
    st->buf = spice_malloc(st->buf_size);
    st->buf_pos = st->buf;
    st->buf_used = 0;
    return st;
}
Example #15
0
RedsStream *reds_stream_new(RedsState *reds, int socket)
{
    RedsStream *stream;

    stream = spice_malloc0(sizeof(RedsStream) + sizeof(RedsStreamPrivate));
    stream->priv = (RedsStreamPrivate *)(stream+1);
    stream->priv->info = spice_new0(SpiceChannelEventInfo, 1);
    stream->priv->reds = reds;
    reds_stream_set_socket(stream, socket);

    stream->priv->read = stream_read_cb;
    stream->priv->write = stream_write_cb;
    stream->priv->writev = stream_writev_cb;

    return stream;
}
SpiceJpegDecoder *jpeg_decoder_new(void)
{
    GlibJpegDecoder *d = spice_new0(GlibJpegDecoder, 1);

    d->_cinfo.err = jpeg_std_error(&d->_jerr);
    jpeg_create_decompress(&d->_cinfo);

    d->_cinfo.src = &d->_jsrc;
    d->_cinfo.src->init_source = jpeg_decoder_init_source;
    d->_cinfo.src->fill_input_buffer = jpeg_decoder_fill_input_buffer;
    d->_cinfo.src->skip_input_data = jpeg_decoder_skip_input_data;
    d->_cinfo.src->resync_to_restart = jpeg_resync_to_restart;
    d->_cinfo.src->term_source = jpeg_decoder_term_source;

    d->base.ops = &jpeg_decoder_ops;

    return &d->base;
}
G_GNUC_INTERNAL
spice_msg_out *spice_msg_out_new(SpiceChannel *channel, int type)
{
    spice_channel *c = channel->priv;
    spice_msg_out *out;

    g_return_val_if_fail(c != NULL, NULL);

    out = spice_new0(spice_msg_out, 1);
    out->refcount = 1;
    out->channel  = channel;

    out->marshallers = c->marshallers;
    out->marshaller = spice_marshaller_new();
    out->header = (SpiceDataHeader *)
        spice_marshaller_reserve_space(out->marshaller, sizeof(SpiceDataHeader));
    spice_marshaller_set_base(out->marshaller, sizeof(SpiceDataHeader));
    out->header->serial = c->serial++;
    out->header->type = type;
    out->header->sub_list = 0;
    return out;
}
MJpegEncoder *mjpeg_encoder_new(int width, int height)
{
    MJpegEncoder *enc;

    enc = spice_new0(MJpegEncoder, 1);

    enc->first_frame = TRUE;
    enc->width = width;
    enc->height = height;
    enc->stride = width * 3;
    enc->quality = 70;
    if (enc->stride < width) {
        abort();
    }
    enc->frame = spice_malloc_n(enc->stride, height);

    enc->cinfo.err = jpeg_std_error(&enc->jerr);

    jpeg_create_compress(&enc->cinfo);

    return enc;
}
Example #19
0
G_GNUC_INTERNAL
VideoDecoder* create_gstreamer_decoder(int codec_type, display_stream *stream)
{
    SpiceGstDecoder *decoder = NULL;

    if (gstvideo_init()) {
        decoder = spice_new0(SpiceGstDecoder, 1);
        decoder->base.destroy = spice_gst_decoder_destroy;
        decoder->base.reschedule = spice_gst_decoder_reschedule;
        decoder->base.queue_frame = spice_gst_decoder_queue_frame;
        decoder->base.codec_type = codec_type;
        decoder->base.stream = stream;
        g_mutex_init(&decoder->queues_mutex);
        decoder->decoding_queue = g_queue_new();
        decoder->display_queue = g_queue_new();

        if (!create_pipeline(decoder)) {
            decoder->base.destroy((VideoDecoder*)decoder);
            decoder = NULL;
        }
    }

    return (VideoDecoder*)decoder;
}
Example #20
0
static SpiceCharDeviceMsgToClient *spicevmc_chardev_read_msg_from_dev(SpiceCharDeviceInstance *sin,
                                                                      void *opaque)
{
    SpiceVmcState *state = opaque;
    SpiceCharDeviceInterface *sif;
    SpiceVmcPipeItem *msg_item;
    int n;

    sif = SPICE_CONTAINEROF(sin->base.sif, SpiceCharDeviceInterface, base);

    if (!state->rcc) {
        return NULL;
    }

    if (!state->pipe_item) {
        msg_item = spice_new0(SpiceVmcPipeItem, 1);
        msg_item->refs = 1;
        red_channel_pipe_item_init(&state->channel,
                                   &msg_item->base, PIPE_ITEM_TYPE_SPICEVMC_DATA);
    } else {
        spice_assert(state->pipe_item->buf_used == 0);
        msg_item = state->pipe_item;
        state->pipe_item = NULL;
    }

    n = sif->read(sin, msg_item->buf,
                  sizeof(msg_item->buf));
    if (n > 0) {
        spice_debug("read from dev %d", n);
        msg_item->buf_used = n;
        return msg_item;
    } else {
        state->pipe_item = msg_item;
        return NULL;
    }
}
Example #21
0
RedDispatcher *red_dispatcher_init(QXLInstance *qxl)
{
    RedDispatcher *red_dispatcher;
    RedWorkerMessage message;
    WorkerInitData init_data;
    QXLDevInitInfo init_info;
    int r;
    RedChannel *display_channel;
    RedChannel *cursor_channel;
    sigset_t thread_sig_mask;
    sigset_t curr_sig_mask;
    ClientCbs client_cbs = { NULL, };

    quic_init();
    sw_canvas_init();
#ifdef USE_OPENGL
    gl_canvas_init();
#endif // USE_OPENGL

    red_dispatcher = spice_new0(RedDispatcher, 1);
    ring_init(&red_dispatcher->async_commands);
    spice_debug("red_dispatcher->async_commands.next %p", red_dispatcher->async_commands.next);
    dispatcher_init(&red_dispatcher->dispatcher, RED_WORKER_MESSAGE_COUNT, NULL);
    init_data.qxl = red_dispatcher->qxl = qxl;
    init_data.id = qxl->id;
    init_data.red_dispatcher = red_dispatcher;
    init_data.pending = &red_dispatcher->pending;
    init_data.num_renderers = num_renderers;
    memcpy(init_data.renderers, renderers, sizeof(init_data.renderers));

    pthread_mutex_init(&red_dispatcher->async_lock, NULL);
    init_data.image_compression = image_compression;
    init_data.jpeg_state = jpeg_state;
    init_data.zlib_glz_state = zlib_glz_state;
    init_data.streaming_video = streaming_video;

    red_dispatcher->base.major_version = SPICE_INTERFACE_QXL_MAJOR;
    red_dispatcher->base.minor_version = SPICE_INTERFACE_QXL_MINOR;
    red_dispatcher->base.wakeup = qxl_worker_wakeup;
    red_dispatcher->base.oom = qxl_worker_oom;
    red_dispatcher->base.start = qxl_worker_start;
    red_dispatcher->base.stop = qxl_worker_stop;
    red_dispatcher->base.update_area = qxl_worker_update_area;
    red_dispatcher->base.add_memslot = qxl_worker_add_memslot;
    red_dispatcher->base.del_memslot = qxl_worker_del_memslot;
    red_dispatcher->base.reset_memslots = qxl_worker_reset_memslots;
    red_dispatcher->base.destroy_surfaces = qxl_worker_destroy_surfaces;
    red_dispatcher->base.create_primary_surface = qxl_worker_create_primary_surface;
    red_dispatcher->base.destroy_primary_surface = qxl_worker_destroy_primary_surface;

    red_dispatcher->base.reset_image_cache = qxl_worker_reset_image_cache;
    red_dispatcher->base.reset_cursor = qxl_worker_reset_cursor;
    red_dispatcher->base.destroy_surface_wait = qxl_worker_destroy_surface_wait;
    red_dispatcher->base.loadvm_commands = qxl_worker_loadvm_commands;

    qxl->st->qif->get_init_info(qxl, &init_info);

    init_data.memslot_id_bits = init_info.memslot_id_bits;
    init_data.memslot_gen_bits = init_info.memslot_gen_bits;
    init_data.num_memslots = init_info.num_memslots;
    init_data.num_memslots_groups = init_info.num_memslots_groups;
    init_data.internal_groupslot_id = init_info.internal_groupslot_id;
    init_data.n_surfaces = init_info.n_surfaces;

    num_active_workers = 1;

    sigfillset(&thread_sig_mask);
    sigdelset(&thread_sig_mask, SIGILL);
    sigdelset(&thread_sig_mask, SIGFPE);
    sigdelset(&thread_sig_mask, SIGSEGV);
    pthread_sigmask(SIG_SETMASK, &thread_sig_mask, &curr_sig_mask);
    if ((r = pthread_create(&red_dispatcher->worker_thread, NULL, red_worker_main, &init_data))) {
        spice_error("create thread failed %d", r);
    }
    pthread_sigmask(SIG_SETMASK, &curr_sig_mask, NULL);

    read_message(red_dispatcher->dispatcher.send_fd, &message);
    spice_assert(message == RED_WORKER_MESSAGE_READY);

    display_channel = red_dispatcher_display_channel_create(red_dispatcher);

    if (display_channel) {
        client_cbs.connect = red_dispatcher_set_display_peer;
        client_cbs.disconnect = red_dispatcher_disconnect_display_peer;
        client_cbs.migrate = red_dispatcher_display_migrate;
        red_channel_register_client_cbs(display_channel, &client_cbs);
        red_channel_set_data(display_channel, red_dispatcher);
        red_channel_set_cap(display_channel, SPICE_DISPLAY_CAP_MONITORS_CONFIG);
        reds_register_channel(display_channel);
    }

    cursor_channel = red_dispatcher_cursor_channel_create(red_dispatcher);

    if (cursor_channel) {
        client_cbs.connect = red_dispatcher_set_cursor_peer;
        client_cbs.disconnect = red_dispatcher_disconnect_cursor_peer;
        client_cbs.migrate = red_dispatcher_cursor_migrate;
        red_channel_register_client_cbs(cursor_channel, &client_cbs);
        red_channel_set_data(cursor_channel, red_dispatcher);
        reds_register_channel(cursor_channel);
    }

    qxl->st->qif->attache_worker(qxl, &red_dispatcher->base);
    qxl->st->qif->set_compression_level(qxl, calc_compression_level());

    red_dispatcher->next = dispatchers;
    dispatchers = red_dispatcher;
    return red_dispatcher;
}