Esempio n. 1
0
int 
wrap_marshall_int32(WRAPPERS_ARGS, int32_t val, char *buf, unsigned int buflen)
{
  int rv;

  assert(file && function);

  if (!buf)
    WRAPPERS_ERR_INVALID_PARAMETERS("marshall_int32");

  if ((rv = marshall_int32(val, buf, buflen)) <= 0)
    WRAPPERS_ERR_ERRNO("marshall_int32");

  return rv;
}
Esempio n. 2
0
/*
 * _event_server_request_marshall
 *
 * Marshall contents of a event server request
 *
 * Returns length written to buffer on success, -1 on error
 */
static int
_event_server_request_marshall(cerebro_t handle,
                               struct cerebro_event_server_request *req,
                               char *buf,
                               unsigned int buflen)
{
  int n, bufPtrlen, c = 0;
  char *bufPtr;
  
  if (!buf || buflen < CEREBRO_EVENT_SERVER_REQUEST_PACKET_LEN)
    {
      CEREBRO_DBG(("invalid parameters"));
      handle->errnum = CEREBRO_ERR_INTERNAL;
      return -1;
    }
  
  memset(buf, '\0', buflen);
  
  if ((n = marshall_int32(req->version, buf + c, buflen - c)) <= 0)
    {
      CEREBRO_DBG(("marshall_int32"));
      handle->errnum = CEREBRO_ERR_INTERNAL;
      return -1;
    }
  c += n;
  
  bufPtr = req->event_name;
  bufPtrlen = sizeof(req->event_name);
  if ((n = marshall_buffer(bufPtr, bufPtrlen, buf + c, buflen - c)) <= 0)
    {
      CEREBRO_DBG(("marshall_buffer"));
      handle->errnum = CEREBRO_ERR_INTERNAL;
      return -1;
    }
  c += n;
  
  if ((n = marshall_u_int32(req->flags, buf + c, buflen - c)) <= 0)
    {
      CEREBRO_DBG(("marshall_u_int32"));
      handle->errnum = CEREBRO_ERR_INTERNAL;
      return -1;
    }
  c += n;

  return c;
}
Esempio n. 3
0
/*
 * _metric_control_request_marshall
 *
 * Marshall contents of a metric control request
 *
 * Returns length written to buffer on success, -1 on error
 */
static int
_metric_control_request_marshall(cerebro_t handle,
                                 struct cerebro_metric_control_request *req,
                                 char *buf,
                                 unsigned int buflen)
{
  int n, errnum, bufPtrlen, c = 0;
  char *bufPtr;

  if (!buf || buflen < CEREBRO_METRIC_CONTROL_REQUEST_HEADER_LEN)
    {
      CEREBRO_DBG(("invalid parameters"));
      handle->errnum = CEREBRO_ERR_INTERNAL;
      return -1;
    }

  memset(buf, '\0', buflen);

  if ((n = marshall_int32(req->version, buf + c, buflen - c)) <= 0)
    {
      CEREBRO_DBG(("marshall_int32"));
      handle->errnum = CEREBRO_ERR_INTERNAL;
      return -1;
    }
  c += n;

  if ((n = marshall_int32(req->command, buf + c, buflen - c)) <= 0)
    {
      CEREBRO_DBG(("marshall_int32"));
      handle->errnum = CEREBRO_ERR_INTERNAL;
      return -1;
    }
  c += n;

  if ((n = marshall_u_int32(req->flags, buf + c, buflen - c)) <= 0)
    {
      CEREBRO_DBG(("marshall_u_int32"));
      handle->errnum = CEREBRO_ERR_INTERNAL;
      return -1;
    }
  c += n;

  bufPtr = req->metric_name;
  bufPtrlen = sizeof(req->metric_name);
  if ((n = marshall_buffer(bufPtr, bufPtrlen, buf + c, buflen - c)) <= 0)
    {
      CEREBRO_DBG(("marshall_buffer"));
      handle->errnum = CEREBRO_ERR_INTERNAL;
      return -1;
    }
  c += n;

  if ((n = marshall_data(req->metric_value_type,
                         req->metric_value_len,
                         req->metric_value,
                         buf + c,
                         buflen - c,
                         &errnum)) < 0)
    {
      handle->errnum = errnum;
      return -1;
    }
  c += n;
  
  return c;
}