/**************************************************************************//**
* Checks the message header in the input stream, and gets the size
*/ staticenum libipm_status
validate_msg_header(struct trans *trans, int *size)
{ struct libipm_priv *priv = (struct libipm_priv *)trans->extra_data; enum libipm_status rv = E_LI_BAD_HEADER;
enum libipm_status
libipm_msg_in_check_available(struct trans *trans, int *available)
{ enum libipm_status rv = E_LI_SUCCESS;
*available = 0;
if (trans == NULL || trans->extra_data == NULL)
{
LOG_DEVEL(LOG_LEVEL_ERROR, "Failed devel check");
rv = E_LI_PROGRAM_ERROR;
} elseif (trans->status != TRANS_STATUS_UP)
{
rv = E_LI_PROGRAM_ERROR; /* Caller should have checked this */
} else
{ unsignedint len = trans->in_s->end - trans->in_s->data; /* Data read so far */
if (len == trans->header_size)
{ if (trans->extra_flags == 0)
{ /* We've read the header so far - validate it */ int size;
rv = validate_msg_header(trans, &size); if (rv == 0)
{ /* Header is OK */
trans->extra_flags = 1;
trans->header_size = size;
enum libipm_status
libipm_msg_in_wait_available(struct trans *trans)
{
tbus wobj[2]; // trans_get_wait_objs() can return at most 2 elements int ocnt = 0; enum libipm_status rv = E_LI_SUCCESS;
if (trans == NULL || trans->extra_data == NULL ||
trans->status != TRANS_STATUS_UP)
{
LOG_DEVEL(LOG_LEVEL_ERROR, "Failed devel check");
rv = E_LI_PROGRAM_ERROR;
} elseif (trans_get_wait_objs(trans, wobj, &ocnt) != 0)
{
LOG(LOG_LEVEL_ERROR, "Can't get wait object for libipm transport");
rv = E_LI_TRANSPORT_ERROR;
} else
{ int gotmsg = 0; /* Prevent trans_check_wait_objs() actioning any callcacks
* when the message is complete */
ttrans_data_in saved_trans_data_in = trans->trans_data_in;
trans->trans_data_in = NULL;
/* Common format string for overflow reporting */ staticconstchar *
not_enough_input_msg = "Input buffer overflow for '%c'";
/**************************************************************************//**
* Extract a bool from the input stream
*
* @param c Type letter which triggered the call
* @param trans libipm transport
* @param argptr Pointer to pointer to receive the value
* @return != 0for error
*
* The value must be a 0or1 on-the-wire, or an error is returned.
*/ staticenum libipm_status
extract_bool_type(char c, struct trans *trans, va_list *argptr)
{ enum libipm_status rv = E_LI_SUCCESS; struct stream *s = trans->in_s; int b;
if (!s_check_rem(s, 1))
{
log_parse_error(trans, not_enough_input_msg, c);
rv = E_LI_BUFFER_OVERFLOW;
} else
{
in_uint8(s, b); if (b < 0 || b > 1)
{
log_parse_error(trans, "Boolean has value other than 0/1");
rv = E_LI_BAD_VALUE;
} else
{ int *tmp = va_arg(*argptr, int *);
*tmp = b;
}
} return rv;
}
/**************************************************************************//**
* Extract an octet from the input stream
*
* @param c Type letter which triggered the call
* @param trans libipm transport
* @param argptr argptr to pointer to receive the value
* @return != 0for error
*/ staticenum libipm_status
extract_int8_type(char c, struct trans *trans, va_list *argptr)
{ enum libipm_status rv = E_LI_SUCCESS; struct stream *s = trans->in_s;
/**************************************************************************//**
* Extract a 16-bit integer from the input stream
*
* @param c Type letter which triggered the call
* @param trans libipm transport
* @param argptr argptr to pointer to receive the value
* @return != 0for error
*/ staticenum libipm_status
extract_int16_type(char c, struct trans *trans, va_list *argptr)
{ enum libipm_status rv = E_LI_SUCCESS; struct stream *s = trans->in_s;
/**************************************************************************//**
* Extract a 32-bit integer from the input stream
*
* @param c Type letter which triggered the call
* @param trans libipm transport
* @param argptr argptr to pointer to receive the value
* @return != 0for error
*/ staticenum libipm_status
extract_int32_type(char c, struct trans *trans, va_list *argptr)
{ enum libipm_status rv = E_LI_SUCCESS; struct stream *s = trans->in_s;
/**************************************************************************//**
* Extract a 64-bit integer from the input stream
*
* @param c Type letter which triggered the call
* @param trans libipm transport
* @param argptr argptr to pointer to receive the value
* @return != 0for error
*/ staticenum libipm_status
extract_int64_type(char c, struct trans *trans, va_list *argptr)
{ enum libipm_status rv = E_LI_SUCCESS; struct stream *s = trans->in_s;
/**************************************************************************//**
* Extract a char * pointer from the input stream
*
* @param c Type letter which triggered the call
* @param trans libipm transport
* @param argptr argptr to pointer to receive the value
* @return != 0for error
*/ staticenum libipm_status
extract_char_ptr_type(char c, struct trans *trans, va_list *argptr)
{ enum libipm_status rv = E_LI_SUCCESS; struct stream *s = trans->in_s;
/* Look for a string terminator in the rest of the input stream */ char *termptr = g_strnchr(s->p, '\0', s->end - s->p);
/**************************************************************************//**
* Extract a file descriptor from the input stream
*
* @param c Type letter which triggered the call
* @param trans libipm transport
* @param argptr argptr to pointer to receive the value
* @return != 0for error
*/ staticenum libipm_status
extract_fd_type(char c, struct trans *trans, va_list *argptr)
{ enum libipm_status rv = E_LI_SUCCESS; struct libipm_priv *priv = (struct libipm_priv *)trans->extra_data;
/* File descriptor available? */ if (priv->in_fd_index >= priv->in_fd_count)
{
log_parse_error(trans, "No file descriptors available");
rv = E_LI_TOO_MANY_FDS;
} else
{ int *tmp = va_arg(*argptr, int *);
/**************************************************************************//**
* Local function to pull data from the input stream
*
* @param trans libipm transport
* @param format type-system compatible string
* @param argptr Pointers to variables to receive extracted data
* @pre - trans->priv has been checked to be non-NULL
* @return != 0for error
*/ staticenum libipm_status
libipm_msg_in_parsev(struct trans *trans, constchar *format, va_list *argptr)
{ enum libipm_status rv = E_LI_SUCCESS; struct stream *s = trans->in_s; struct libipm_priv *priv = (struct libipm_priv *)trans->extra_data; constchar *cp;
if (format != NULL)
{ for (cp = format; rv == 0 && *cp != '\0' ; ++cp)
{ char c = *cp; char actual_c;
++priv->in_param_count; /* Count the parameter */
/* Check the type of the input is supported */ if (g_strchr(libipm_valid_type_chars, c) == NULL)
{
log_parse_error(trans, "Type code '%c' is not supported", c);
rv = E_LI_UNSUPPORTED_TYPE; break;
}
/* Check the type of the input matches the stream */ if (!s_check_rem(s, 1))
{
log_parse_error(trans, not_enough_input_msg, c);
rv = E_LI_BUFFER_OVERFLOW; break;
}
in_uint8(s, actual_c); if (c != actual_c)
{
log_parse_error(trans, "Expected '%c', got '%c'", c, actual_c);
rv = E_LI_UNEXPECTED_TYPE; break;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.