[Spice-devel] [PATCH spice 1/4] main-channel: Make main_channel_push_notify deal with dynamic memory
Hans de Goede
hdegoede at redhat.com
Thu Mar 14 09:27:17 PDT 2013
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 the arguments to are 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 at redhat.com>
---
server/main_channel.c | 31 ++++++++++++-------------------
server/main_channel.h | 2 +-
server/reds.c | 3 +--
3 files changed, 14 insertions(+), 22 deletions(-)
diff --git a/server/main_channel.c b/server/main_channel.c
index 0fd5ab6..55c3291 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, ¬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;
}
diff --git a/server/main_channel.h b/server/main_channel.h
index 285a009..5f77b74 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 5c46909..bbff68e 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);
--
1.8.1.4
More information about the Spice-devel
mailing list