mirror of
https://gitlab.uni-freiburg.de/opensourcevdi/spice
synced 2025-12-31 20:04:09 +00:00
main-channel: Make main_channel_push_notify deal with dynamic memory
Currently main_channel_push_notify only gets passed a static string, but chances are in the future it may get passed dynamically allocated strings, prepare it for this. While at it also make clear that its argument is a string, and simplify things a bit by making use of this knowledge (pushing the strlen call down). Signed-off-by: Hans de Goede <hdegoede@redhat.com>
This commit is contained in:
parent
89d2a68cb7
commit
3a2f42555d
@ -131,8 +131,7 @@ typedef struct UuidPipeItem {
|
||||
|
||||
typedef struct NotifyPipeItem {
|
||||
PipeItem base;
|
||||
uint8_t *mess;
|
||||
int mess_len;
|
||||
char *msg;
|
||||
} NotifyPipeItem;
|
||||
|
||||
typedef struct MultiMediaTimePipeItem {
|
||||
@ -305,20 +304,14 @@ static PipeItem *main_uuid_item_new(MainChannelClient *mcc, const uint8_t uuid[1
|
||||
return &item->base;
|
||||
}
|
||||
|
||||
typedef struct NotifyPipeInfo {
|
||||
uint8_t *mess;
|
||||
int mess_len;
|
||||
} NotifyPipeInfo;
|
||||
|
||||
static PipeItem *main_notify_item_new(RedChannelClient *rcc, void *data, int num)
|
||||
{
|
||||
NotifyPipeItem *item = spice_malloc(sizeof(NotifyPipeItem));
|
||||
NotifyPipeInfo *info = data;
|
||||
const char *msg = data;
|
||||
|
||||
red_channel_pipe_item_init(rcc->channel, &item->base,
|
||||
PIPE_ITEM_TYPE_MAIN_NOTIFY);
|
||||
item->mess = info->mess;
|
||||
item->mess_len = info->mess_len;
|
||||
item->msg = spice_strdup(msg);
|
||||
return &item->base;
|
||||
}
|
||||
|
||||
@ -583,15 +576,10 @@ void main_channel_push_uuid(MainChannelClient *mcc, const uint8_t uuid[16])
|
||||
}
|
||||
|
||||
// TODO - some notifications are new client only (like "keyboard is insecure" on startup)
|
||||
void main_channel_push_notify(MainChannel *main_chan, uint8_t *mess, const int mess_len)
|
||||
void main_channel_push_notify(MainChannel *main_chan, const char *msg)
|
||||
{
|
||||
NotifyPipeInfo info = {
|
||||
.mess = mess,
|
||||
.mess_len = mess_len,
|
||||
};
|
||||
|
||||
red_channel_pipes_new_add_push(&main_chan->base,
|
||||
main_notify_item_new, &info);
|
||||
main_notify_item_new, (void *)msg);
|
||||
}
|
||||
|
||||
static uint64_t get_time_stamp(void)
|
||||
@ -611,9 +599,9 @@ static void main_channel_marshall_notify(RedChannelClient *rcc,
|
||||
notify.severity = SPICE_NOTIFY_SEVERITY_WARN;
|
||||
notify.visibilty = SPICE_NOTIFY_VISIBILITY_HIGH;
|
||||
notify.what = SPICE_WARN_GENERAL;
|
||||
notify.message_len = item->mess_len;
|
||||
notify.message_len = strlen(item->msg);
|
||||
spice_marshall_msg_notify(m, ¬ify);
|
||||
spice_marshaller_add(m, item->mess, item->mess_len + 1);
|
||||
spice_marshaller_add(m, (uint8_t *)item->msg, notify.message_len + 1);
|
||||
}
|
||||
|
||||
static void main_channel_fill_migrate_dst_info(MainChannel *main_channel,
|
||||
@ -816,6 +804,11 @@ static void main_channel_release_pipe_item(RedChannelClient *rcc,
|
||||
data->free_data(data->data, data->opaque);
|
||||
break;
|
||||
}
|
||||
case PIPE_ITEM_TYPE_MAIN_NOTIFY: {
|
||||
NotifyPipeItem *data = (NotifyPipeItem *)base;
|
||||
free(data->msg);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
@ -60,7 +60,7 @@ void main_channel_client_start_net_test(MainChannelClient *mcc);
|
||||
void main_channel_push_init(MainChannelClient *mcc, int display_channels_hint,
|
||||
int current_mouse_mode, int is_client_mouse_allowed, int multi_media_time,
|
||||
int ram_hint);
|
||||
void main_channel_push_notify(MainChannel *main_chan, uint8_t *mess, const int mess_len);
|
||||
void main_channel_push_notify(MainChannel *main_chan, const char *msg);
|
||||
void main_channel_push_multi_media_time(MainChannel *main_chan, int time);
|
||||
int main_channel_getsockname(MainChannel *main_chan, struct sockaddr *sa, socklen_t *salen);
|
||||
int main_channel_getpeername(MainChannel *main_chan, struct sockaddr *sa, socklen_t *salen);
|
||||
|
||||
@ -1749,8 +1749,7 @@ static void reds_channel_do_link(RedChannel *channel, RedClient *client,
|
||||
|
||||
if (link_msg->channel_type == SPICE_CHANNEL_INPUTS && !stream->ssl) {
|
||||
const char *mess = "keyboard channel is insecure";
|
||||
const int mess_len = strlen(mess);
|
||||
main_channel_push_notify(reds->main_channel, (uint8_t*)mess, mess_len);
|
||||
main_channel_push_notify(reds->main_channel, mess);
|
||||
}
|
||||
|
||||
caps = (uint32_t *)((uint8_t *)link_msg + link_msg->caps_offset);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user