summaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorHans de Goede <hdegoede@redhat.com>2013-03-14 17:06:22 +0100
committerHans de Goede <hdegoede@redhat.com>2013-03-15 09:44:26 +0100
commit3a2f42555dbae4357aa9fc2e83c9b31a837ac98d (patch)
treeb7aff16ca358c280a16225fba0e1f9d1129bff6b /server
parent89d2a68cb7bfa105d27d12497a1f4e340171b525 (diff)
downloadspice-3a2f42555dbae4357aa9fc2e83c9b31a837ac98d.tar.gz
spice-3a2f42555dbae4357aa9fc2e83c9b31a837ac98d.tar.xz
spice-3a2f42555dbae4357aa9fc2e83c9b31a837ac98d.zip
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>
Diffstat (limited to 'server')
-rw-r--r--server/main_channel.c31
-rw-r--r--server/main_channel.h2
-rw-r--r--server/reds.c3
3 files changed, 14 insertions, 22 deletions
diff --git a/server/main_channel.c b/server/main_channel.c
index 0fd5ab6f..55c32913 100644
--- a/server/main_channel.c
+++ b/server/main_channel.c
@@ -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, &notify);
- 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;
}
diff --git a/server/main_channel.h b/server/main_channel.h
index 285a0096..5f77b74a 100644
--- a/server/main_channel.h
+++ b/server/main_channel.h
@@ -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);
diff --git a/server/reds.c b/server/reds.c
index 5c469090..bbff68e5 100644
--- a/server/reds.c
+++ b/server/reds.c
@@ -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);