/* * _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; }
/* * _event_server_err_check * * Check that the version and error code are good prior to * unmarshalling * * Returns 0 on success, -1 on error */ static int _event_server_err_check(cerebro_t handle, const char *buf, unsigned int buflen) { int n, len = 0; int32_t version; u_int32_t err_code; if ((n = unmarshall_int32(&version, buf + len, buflen - len)) < 0) { CEREBRO_DBG(("unmarshall_int32")); handle->errnum = CEREBRO_ERR_INTERNAL; return -1; } if (!n) { handle->errnum = CEREBRO_ERR_PROTOCOL; return -1; } len += n; if ((n = unmarshall_u_int32(&err_code, buf + len, buflen - len)) < 0) { CEREBRO_DBG(("unmarshall_u_int32")); handle->errnum = CEREBRO_ERR_INTERNAL; return -1; } if (!n) { handle->errnum = CEREBRO_ERR_PROTOCOL; return -1; } len += n; if (version != CEREBRO_EVENT_SERVER_PROTOCOL_VERSION) { handle->errnum = CEREBRO_ERR_VERSION_INCOMPATIBLE; return -1; } if (err_code != CEREBRO_EVENT_SERVER_PROTOCOL_ERR_SUCCESS) { handle->errnum = _event_server_protocol_err_code_conversion(err_code); return -1; } /* Note: We don't care about the 'end' or the 'event_name' portions * of the response when we're just looking for an error code. */ return 0; }
/* * _metric_control_response_check * * Check the version and error code * * Returns 0 on success, -1 on error */ static int _metric_control_response_check(cerebro_t handle, const char *buf, unsigned int buflen) { int n, len = 0; int32_t version; u_int32_t err_code; if ((n = unmarshall_int32(&version, buf + len, buflen - len)) < 0) { CEREBRO_DBG(("unmarshall_int32")); handle->errnum = CEREBRO_ERR_INTERNAL; return -1; } if (!n) { handle->errnum = CEREBRO_ERR_PROTOCOL; return -1; } len += n; if ((n = unmarshall_u_int32(&err_code, buf + len, buflen - len)) < 0) { CEREBRO_DBG(("unmarshall_u_int32")); handle->errnum = CEREBRO_ERR_INTERNAL; return -1; } if (!n) { handle->errnum = CEREBRO_ERR_PROTOCOL; return -1; } len += n; if (version != CEREBRO_METRIC_CONTROL_PROTOCOL_VERSION) { handle->errnum = CEREBRO_ERR_VERSION_INCOMPATIBLE; return -1; } if (err_code != CEREBRO_METRIC_CONTROL_PROTOCOL_ERR_SUCCESS) { handle->errnum = _metric_control_protocol_err_code_conversion(err_code); return -1; } return 0; }
int wrap_unmarshall_int32(WRAPPERS_ARGS, int32_t *val, const char *buf, unsigned int buflen) { int rv; assert(file && function); if (!val || !buf) WRAPPERS_ERR_INVALID_PARAMETERS("unmarshall_int32"); if ((rv = unmarshall_int32(val, buf, buflen)) < 0) WRAPPERS_ERR_ERRNO("unmarshall_int32"); return rv; }
/* * _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; }