Commit 0ae221fe authored by Mike Hibler's avatar Mike Hibler
Browse files

From the Jon-does-not-like-static-buffers catagory:

Add event_notification_get_{opaque,string}_length functions to return
the length of a "blob" value so that a buffer can be sized in advance
of returning the value via event_notification_get_{opaque,string}.
parent 17fdcd50
/*
* EMULAB-COPYRIGHT
* Copyright (c) 2000-2007 University of Utah and the Flux Group.
* Copyright (c) 2000-2008 University of Utah and the Flux Group.
* All rights reserved.
*/
......@@ -761,6 +761,60 @@ event_notification_get_int64(event_handle_t handle,
}
/*
* Return the length of a attribute with name NAME.
* Used to dynamically size buffers for the event_notification_get_* calls.
* Returns the length or -1 on error.
*
* Note that we only do this for opaques and strings as the other types
* all have a "standard" size.
*/
int
event_notification_get_opaque_length(event_handle_t handle,
event_notification_t notification,
char *name)
{
char *v;
int len;
if (!handle || !notification || !name) {
ERROR("invalid parameter\n");
return -1;
}
if (pubsub_notification_get_opaque(notification->pubsub_notification,
name, &v, &len, &handle->status) != 0) {
ERROR("could not get opaque attribute \"%s\" from notification %p\n",
name, notification);
return -1;
}
return len;
}
int
event_notification_get_string_length(event_handle_t handle,
event_notification_t notification,
char *name)
{
char *v;
if (!handle || !notification || !name) {
ERROR("invalid parameter\n");
return -1;
}
if (pubsub_notification_get_string(notification->pubsub_notification,
name, &v, &handle->status) != 0) {
ERROR("could not get string attribute \"%s\" from notification %p\n",
name, notification);
return -1;
}
return strlen(v);
}
/*
* Get the opaque attribute with name NAME from the event
* notification NOTIFICATION.
......
/*
* EMULAB-COPYRIGHT
* Copyright (c) 2000-2007 University of Utah and the Flux Group.
* Copyright (c) 2000-2008 University of Utah and the Flux Group.
* All rights reserved.
*/
......@@ -204,6 +204,12 @@ int event_notification_get_int32(event_handle_t handle,
int event_notification_get_int64(event_handle_t handle,
event_notification_t notification,
char *name, int64_t *value);
int event_notification_get_opaque_length(event_handle_t handle,
event_notification_t notification,
char *name);
int event_notification_get_string_length(event_handle_t handle,
event_notification_t notification,
char *name);
int event_notification_get_opaque(event_handle_t handle,
event_notification_t notification,
char *name, void *buffer, int length);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment