2 * Copyright 2009 VMware, Inc.
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * on the rights to use, copy, modify, merge, publish, distribute, sub
9 * license, and/or sell copies of the Software, and to permit persons to whom
10 * the Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
19 * VMWARE AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
21 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
22 * USE OR OTHER DEALINGS IN THE SOFTWARE.
26 * This file holds the function implementation for one of the rbug extensions.
27 * Prototypes and declerations of functions and structs is in the same folder
28 * in the header file matching this file's name.
30 * The functions starting rbug_send_* encodes a call to the write format and
31 * sends that to the supplied connection, while functions starting with
32 * rbug_demarshal_* demarshal data in the wire protocol.
34 * Functions ending with _reply are replies to requests.
37 #include "rbug_internal.h"
38 #include "rbug/rbug_core.h"
40 int rbug_send_noop(struct rbug_connection *__con,
45 uint8_t *__data = NULL;
53 __data = (uint8_t*)MALLOC(__len);
57 WRITE(4, int32_t, ((int32_t)RBUG_OP_NOOP));
58 WRITE(4, uint32_t, ((uint32_t)(__len / 4)));
66 rbug_connection_send_start(__con, RBUG_OP_NOOP, __len);
67 rbug_connection_write(__con, __data, __len);
68 __ret = rbug_connection_send_finish(__con, __serial);
75 int rbug_send_ping(struct rbug_connection *__con,
80 uint8_t *__data = NULL;
88 __data = (uint8_t*)MALLOC(__len);
92 WRITE(4, int32_t, ((int32_t)RBUG_OP_PING));
93 WRITE(4, uint32_t, ((uint32_t)(__len / 4)));
101 rbug_connection_send_start(__con, RBUG_OP_PING, __len);
102 rbug_connection_write(__con, __data, __len);
103 __ret = rbug_connection_send_finish(__con, __serial);
110 int rbug_send_error(struct rbug_connection *__con,
116 uint8_t *__data = NULL;
125 __data = (uint8_t*)MALLOC(__len);
129 WRITE(4, int32_t, ((int32_t)RBUG_OP_ERROR));
130 WRITE(4, uint32_t, ((uint32_t)(__len / 4)));
131 WRITE(4, uint32_t, error); /* error */
136 if (__pos != __len) {
139 rbug_connection_send_start(__con, RBUG_OP_ERROR, __len);
140 rbug_connection_write(__con, __data, __len);
141 __ret = rbug_connection_send_finish(__con, __serial);
148 int rbug_send_ping_reply(struct rbug_connection *__con,
154 uint8_t *__data = NULL;
163 __data = (uint8_t*)MALLOC(__len);
167 WRITE(4, int32_t, ((int32_t)RBUG_OP_PING_REPLY));
168 WRITE(4, uint32_t, ((uint32_t)(__len / 4)));
169 WRITE(4, uint32_t, serial); /* serial */
174 if (__pos != __len) {
177 rbug_connection_send_start(__con, RBUG_OP_PING_REPLY, __len);
178 rbug_connection_write(__con, __data, __len);
179 __ret = rbug_connection_send_finish(__con, __serial);
186 int rbug_send_error_reply(struct rbug_connection *__con,
193 uint8_t *__data = NULL;
203 __data = (uint8_t*)MALLOC(__len);
207 WRITE(4, int32_t, ((int32_t)RBUG_OP_ERROR_REPLY));
208 WRITE(4, uint32_t, ((uint32_t)(__len / 4)));
209 WRITE(4, uint32_t, serial); /* serial */
210 WRITE(4, uint32_t, error); /* error */
215 if (__pos != __len) {
218 rbug_connection_send_start(__con, RBUG_OP_ERROR_REPLY, __len);
219 rbug_connection_write(__con, __data, __len);
220 __ret = rbug_connection_send_finish(__con, __serial);
227 struct rbug_proto_noop * rbug_demarshal_noop(struct rbug_proto_header *header)
229 struct rbug_proto_noop *ret;
233 if (header->opcode != (int32_t)RBUG_OP_NOOP)
236 ret = MALLOC(sizeof(*ret));
240 ret->header.__message = header;
241 ret->header.opcode = header->opcode;
246 struct rbug_proto_ping * rbug_demarshal_ping(struct rbug_proto_header *header)
248 struct rbug_proto_ping *ret;
252 if (header->opcode != (int32_t)RBUG_OP_PING)
255 ret = MALLOC(sizeof(*ret));
259 ret->header.__message = header;
260 ret->header.opcode = header->opcode;
265 struct rbug_proto_error * rbug_demarshal_error(struct rbug_proto_header *header)
269 uint8_t *data = NULL;
270 struct rbug_proto_error *ret;
274 if (header->opcode != (int32_t)RBUG_OP_ERROR)
278 len = header->length * 4;
279 data = (uint8_t*)&header[1];
280 ret = MALLOC(sizeof(*ret));
284 ret->header.__message = header;
285 ret->header.opcode = header->opcode;
287 READ(4, uint32_t, error); /* error */
292 struct rbug_proto_ping_reply * rbug_demarshal_ping_reply(struct rbug_proto_header *header)
296 uint8_t *data = NULL;
297 struct rbug_proto_ping_reply *ret;
301 if (header->opcode != (int32_t)RBUG_OP_PING_REPLY)
305 len = header->length * 4;
306 data = (uint8_t*)&header[1];
307 ret = MALLOC(sizeof(*ret));
311 ret->header.__message = header;
312 ret->header.opcode = header->opcode;
314 READ(4, uint32_t, serial); /* serial */
319 struct rbug_proto_error_reply * rbug_demarshal_error_reply(struct rbug_proto_header *header)
323 uint8_t *data = NULL;
324 struct rbug_proto_error_reply *ret;
328 if (header->opcode != (int32_t)RBUG_OP_ERROR_REPLY)
332 len = header->length * 4;
333 data = (uint8_t*)&header[1];
334 ret = MALLOC(sizeof(*ret));
338 ret->header.__message = header;
339 ret->header.opcode = header->opcode;
341 READ(4, uint32_t, serial); /* serial */
342 READ(4, uint32_t, error); /* error */