Inform agent about client's capabilities

The client should inform the agent about capabilities
when the connection is established. This avoid receiving unhandled
agent messages.
This commit is contained in:
Pavel Grunt 2015-01-15 13:33:58 +01:00 committed by Jeremy White
parent 566e4acc39
commit 54ee82f004
3 changed files with 65 additions and 1 deletions

View File

@ -329,6 +329,19 @@ var VD_AGENT_MOUSE_STATE = 1,
VD_AGENT_CLIENT_DISCONNECTED =13,
VD_AGENT_MAX_CLIPBOARD =14;
var VD_AGENT_CAP_MOUSE_STATE = 0,
VD_AGENT_CAP_MONITORS_CONFIG = 1,
VD_AGENT_CAP_REPLY = 2,
VD_AGENT_CAP_CLIPBOARD = 3,
VD_AGENT_CAP_DISPLAY_CONFIG = 4,
VD_AGENT_CAP_CLIPBOARD_BY_DEMAND = 5,
VD_AGENT_CAP_CLIPBOARD_SELECTION = 6,
VD_AGENT_CAP_SPARSE_MONITORS_CONFIG = 7,
VD_AGENT_CAP_GUEST_LINEEND_LF = 8,
VD_AGENT_CAP_GUEST_LINEEND_CRLF = 9,
VD_AGENT_CAP_MAX_CLIPBOARD = 10,
VD_AGENT_END_CAP = 11;
var VD_AGENT_FILE_XFER_STATUS_CAN_SEND_DATA = 0,
VD_AGENT_FILE_XFER_STATUS_CANCELLED = 1,
VD_AGENT_FILE_XFER_STATUS_ERROR = 2,

19
main.js
View File

@ -185,7 +185,14 @@ SpiceMainConn.prototype.process_channel_message = function(msg)
if (msg.type == SPICE_MSG_MAIN_AGENT_DATA)
{
var agent_data = new SpiceMsgMainAgentData(msg.data);
if (agent_data.type == VD_AGENT_FILE_XFER_STATUS)
if (agent_data.type == VD_AGENT_ANNOUNCE_CAPABILITIES)
{
var agent_caps = new VDAgentAnnounceCapabilities(agent_data.data);
if (agent_caps.request)
this.announce_agent_capabilities(0);
return true;
}
else if (agent_data.type == VD_AGENT_FILE_XFER_STATUS)
{
this.handle_file_xfer_status(new VDAgentFileXferStatusMessage(agent_data.data));
return true;
@ -262,6 +269,14 @@ SpiceMainConn.prototype.send_agent_message = function(type, message)
}
}
SpiceMainConn.prototype.announce_agent_capabilities = function(request)
{
var caps = new VDAgentAnnounceCapabilities(request, (1 << VD_AGENT_CAP_MOUSE_STATE) |
(1 << VD_AGENT_CAP_MONITORS_CONFIG) |
(1 << VD_AGENT_CAP_REPLY));
this.send_agent_message(VD_AGENT_ANNOUNCE_CAPABILITIES, caps);
}
SpiceMainConn.prototype.resize_window = function(flags, width, height, depth, x, y)
{
var monitors_config = new VDAgentMonitorsConfig(flags, width, height, depth, x, y);
@ -365,6 +380,8 @@ SpiceMainConn.prototype.connect_agent = function()
mr.build_msg(SPICE_MSGC_MAIN_AGENT_START, agent_start);
this.send_msg(mr);
this.announce_agent_capabilities(1);
if (this.onagent !== undefined)
this.onagent(this);

View File

@ -486,6 +486,40 @@ SpiceMsgcMainAgentData.prototype =
}
}
function VDAgentAnnounceCapabilities(request, caps)
{
if (caps)
{
this.request = request;
this.caps = caps;
}
else
this.from_buffer(request);
}
VDAgentAnnounceCapabilities.prototype =
{
to_buffer: function(a, at)
{
at = at || 0;
var dv = new SpiceDataView(a);
dv.setUint32(at, this.request, true); at += 4;
dv.setUint32(at, this.caps, true); at += 4;
},
from_buffer: function(a, at)
{
at = at || 0;
var dv = new SpiceDataView(a);
this.request = dv.getUint32(at, true); at += 4;
this.caps = dv.getUint32(at, true); at += 4;
return at;
},
buffer_size: function()
{
return 8;
}
}
function VDAgentMonitorsConfig(flags, width, height, depth, x, y)
{
this.num_mon = 1;