コード例 #1
0
ファイル: cerebro_event.c プロジェクト: BenCasses/cerebro
/*
 * _event_server_response_unmarshall
 *
 * Unmarshall contents of a event server response
 *
 * Returns 0 on success, -1 on error
 */
static int
_event_server_response_unmarshall(cerebro_t handle,
                                  struct cerebro_event_server_response *res,
                                  const char *buf,
                                  unsigned int buflen)
{
  int n, bufPtrlen, c = 0;
  char *bufPtr;

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

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

  if ((n = unmarshall_u_int32(&(res->err_code), buf + c, buflen - c)) < 0)
    {
      CEREBRO_DBG(("unmarshall_u_int32"));
      handle->errnum = CEREBRO_ERR_INTERNAL;
      return -1;
    }
  c += n;

  if ((n = unmarshall_u_int8(&(res->end), buf + c, buflen - c)) < 0)
    {
      CEREBRO_DBG(("unmarshall_u_int8"));
      handle->errnum = CEREBRO_ERR_INTERNAL;
      return -1;
    }
  c += n;

  bufPtr = res->event_name;
  bufPtrlen = sizeof(res->event_name);
  if ((n = unmarshall_buffer(bufPtr, bufPtrlen, buf + c, buflen - c)) < 0)
    {
      CEREBRO_DBG(("unmarshall_buffer"));
      handle->errnum = CEREBRO_ERR_INTERNAL;
      return -1;
    }
  c += n;
  
  if (c != CEREBRO_EVENT_SERVER_RESPONSE_LEN)
    {
      handle->errnum = CEREBRO_ERR_PROTOCOL;
      return -1;
    }
  
  return 0;
}
コード例 #2
0
int 
wrap_unmarshall_buffer(WRAPPERS_ARGS, char *val, unsigned int vallen, const char *buf, unsigned int buflen)
{
  int rv;

  assert(file && function);

  if (!val || !buf)
    WRAPPERS_ERR_INVALID_PARAMETERS("unmarshall_buffer");

  if ((rv = unmarshall_buffer(val, vallen, buf, buflen)) < 0)
    WRAPPERS_ERR_ERRNO("unmarshall_float");

  return rv;
}
コード例 #3
0
ファイル: cerebro_event.c プロジェクト: BenCasses/cerebro
/*
 * _event_header_unmarshall
 *
 * Unmarshall contents of a event server event header
 *
 * Returns 0 on success, -1 on error
 */
static int
_event_header_unmarshall(cerebro_t handle,
                         struct cerebro_event *event,
                         const char *buf,
                         unsigned int buflen)
{
  u_int32_t *etypePtr, *elenPtr;
  int n, bufPtrlen, c = 0;
  char *bufPtr;

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

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

  if ((n = unmarshall_u_int32(&(event->err_code), buf + c, buflen - c)) < 0)
    {
      CEREBRO_DBG(("unmarshall_u_int32"));
      handle->errnum = CEREBRO_ERR_INTERNAL;
      return -1;
    }
  c += n;

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

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

  etypePtr = &(event->event_value_type);
  if ((n = unmarshall_u_int32(etypePtr, buf + c,  buflen - c)) < 0)
    {
      CEREBRO_DBG(("unmarshall_u_int32"));
      handle->errnum = CEREBRO_ERR_INTERNAL;
      return -1;
    }
  c += n;

  elenPtr = &(event->event_value_len);
  if ((n = unmarshall_u_int32(elenPtr, buf + c, buflen - c)) < 0)
    {
      CEREBRO_DBG(("unmarshall_u_int32"));
      handle->errnum = CEREBRO_ERR_INTERNAL;
      return -1;
    }
  c += n;

  if (c != CEREBRO_EVENT_HEADER_LEN)
    {
      handle->errnum = CEREBRO_ERR_PROTOCOL;
      return -1;
    }

  return 0;
}