PERFORCE change 164658 for review
Jonathan Anderson
jona at FreeBSD.org
Thu Jun 18 11:11:36 UTC 2009
http://perforce.freebsd.org/chv.cgi?CH=164658
Change 164658 by jona at jona-trustedbsd-kentvm on 2009/06/18 11:11:15
Provided the code for marshalling and unmarshalling errors
Affected files ...
.. //depot/projects/trustedbsd/capabilities/src/tools/cap/user_angel/protocol.c#10 edit
.. //depot/projects/trustedbsd/capabilities/src/tools/cap/user_angel/protocol.h#9 edit
Differences ...
==== //depot/projects/trustedbsd/capabilities/src/tools/cap/user_angel/protocol.c#10 (text+ko) ====
@@ -162,6 +162,86 @@
}
+
+wire_datum* cap_marshall_error(int errno, const char *msg, int msglen)
+{
+ wire_datum *data[2];
+ data[0] = cap_marshall_int(errno);
+ data[1] = cap_marshall_string(msg, msglen);
+
+ int total_size = 0;
+ for(int i = 0; i < 2; i++)
+ if(data[i] == NULL)
+ {
+ sprintf(errmsg, "Error datum %i is NULL", i);
+ return NULL;
+ }
+ else total_size += (sizeof(wire_datum) + data[i]->length);
+
+ wire_datum *d = (wire_datum*) malloc(sizeof(wire_datum) + total_size);
+ d->type = ERROR;
+ d->length = total_size;
+
+ char *buffer = ((char*) d) + sizeof(wire_datum);
+ char *head = buffer;
+ for(int i = 0; i < 2; i++)
+ {
+ memcpy(head, data[i], sizeof(wire_datum) + data[i]->length);
+ head += sizeof(wire_datum) + data[i]->length;
+
+ free(data[i]);
+ }
+
+ return d;
+}
+
+
+int cap_unmarshall_error(const wire_datum *d, int *errno, const char *msg, int *msglen)
+{
+ if(datum == NULL)
+ {
+ sprintf(errmsg, "NULL datum");
+ return -1;
+ }
+ else if(datum->type != ERROR)
+ {
+ sprintf(errmsg, "Datum's type is %i, not ERROR (%i)",
+ datum->type, ERROR);
+ }
+ else if(datum->length < 0)
+ {
+ sprintf(errmsg, "Datum length should be positive, not %i",
+ datum->length);
+ return -1;
+ }
+
+ int32_t tmp_int;
+ wire_datum *d = (wire_datum*) (((char*) datum) + sizeof(wire_datum));
+
+ if(cap_unmarshall_int(d, &tmp_int) < 0)
+ {
+ char error[128];
+ sprintf(error, "Error unmarshalling errno: %s", cap_error());
+ strcpy(errmsg, error);
+ return -1;
+ }
+ *errno = tmp_int;
+ d = (wire_datum*) (((char*) d) + sizeof(wire_datum) + d->length);
+
+
+ if(cap_unmarshall_string(d, msg, msglen) < 0)
+ {
+ char error[128];
+ sprintf(error, "Error unmarshalling path: %s", cap_error());
+ strcpy(errmsg, error);
+ return -1;
+ }
+
+ return sizeof(wire_datum) + datum->length;
+}
+
+
+
wire_datum* cap_marshall_capbox(const struct capbox_options *options)
{
wire_datum *data[8];
==== //depot/projects/trustedbsd/capabilities/src/tools/cap/user_angel/protocol.h#9 (text+ko) ====
@@ -82,8 +82,8 @@
/* Unmarshalling functions; return the number of bytes unmarshalled (or -1) */
int cap_unmarshall_int(const struct cap_wire_datum *d, int32_t *value);
-int cap_unmarshall_string(const struct cap_wire_datum *d, char* value, int *len);
-int cap_unmarshall_error(const struct cap_wire_datum *d, int errno, const char *msg, int msglen);
+int cap_unmarshall_string(const struct cap_wire_datum *d, char *value, int *len);
+int cap_unmarshall_error(const struct cap_wire_datum *d, int *errno, const char *msg, int *msglen);
int cap_unmarshall_capbox(const struct cap_wire_datum *d, struct capbox_options *options);
More information about the p4-projects
mailing list