Loading...
Searching...
No Matches
Input handler

## Data Structures

struct | ly_in
| Parser input structure specifying the type of data input. More...

## Typedefs

typedef enum LY_IN_TYPE | LY_IN_TYPE
| Types of the parser's inputs.

## Enumerations

enum | LY_IN_TYPE { LY_IN_ERROR = -1 , LY_IN_FD , LY_IN_FILE , LY_IN_FILEPATH , LY_IN_MEMORY }
| Types of the parser's inputs. More...

## Functions

LIBYANG_API_DECL int | ly_in_fd (struct ly_in *in, int fd)
| Get or reset file descriptor input handler.
LIBYANG_API_DECL FILE * | ly_in_file (struct ly_in *in, FILE *f)
| Get or reset file stream input handler.
LIBYANG_API_DECL const char * | ly_in_filepath (struct ly_in *in, const char *filepath, size_t len)
| Get or change the filepath of the file where the parser reads the data.
LIBYANG_API_DECL void | ly_in_free (struct ly_in *in, ly_bool destroy)
| Free the input handler.
LIBYANG_API_DECL const char * | ly_in_memory (struct ly_in *in, const char *str)
| Get or change memory where the data are read from.
LIBYANG_API_DECL LY_ERR | ly_in_new_fd (int fd, struct ly_in **in)
| Create input handler using file descriptor.
LIBYANG_API_DECL LY_ERR | ly_in_new_file (FILE *f, struct ly_in **in)
| Create input handler using file stream.
LIBYANG_API_DECL LY_ERR | ly_in_new_filepath (const char *filepath, size_t len, struct ly_in **in)
| Create input handler file of the given filename.
LIBYANG_API_DECL LY_ERR | ly_in_new_memory (const char *str, struct ly_in **in)
| Create input handler using memory to read data.
LIBYANG_API_DECL size_t | ly_in_parsed (const struct ly_in *in)
| Get the number of parsed bytes by the last function.
LIBYANG_API_DECL LY_ERR | ly_in_read (struct ly_in *in, void *buf, size_t count)
| Read bytes from an input.
LIBYANG_API_DECL LY_ERR | ly_in_reset (struct ly_in *in)
| Reset the input medium to read from its beginning, so the following parser function will read from the object's beginning.
LIBYANG_API_DECL LY_ERR | ly_in_skip (struct ly_in *in, size_t count)
| Just skip bytes in an input.
LIBYANG_API_DECL LY_IN_TYPE | ly_in_type (const struct ly_in *in)
| Get input type of the input handler.

## Detailed Description

Structures and functions for input handling.

The input abstraction allows users for transparent use of various input kinds.

## Data Structure Documentation

## ly_in

struct ly_in

Parser input structure specifying the type of data input.

## Typedef Documentation

## LY_IN_TYPE

typedef enum LY_IN_TYPE LY_IN_TYPE

Types of the parser's inputs.

## Enumeration Type Documentation

## LY_IN_TYPE

enum LY_IN_TYPE

Types of the parser's inputs.

Enumerator
LY_IN_ERROR | error value to indicate failure of the functions returning LY_IN_TYPE
LY_IN_FD | file descriptor printer
LY_IN_FILE | FILE stream parser
LY_IN_FILEPATH | filepath parser
LY_IN_MEMORY | memory parser

Definition at line 92 of file in.h.

## Function Documentation

## ly_in_fd()

LIBYANG_API_DECL int ly_in_fd | ( | struct ly_in * | in,
|  | int | fd
| ) |  |

Get or reset file descriptor input handler.

Parameters

  [in] | in | Input handler.
  [in] | fd | Optional value of a new file descriptor for the handler. If -1, only the current file descriptor value is returned.

Returns
  Previous value of the file descriptor. Note that caller is responsible for closing the returned file descriptor in case of setting new descriptor `fd`.
  -1 in case of error when setting up the new file descriptor.

## ly_in_file()

LIBYANG_API_DECL FILE * ly_in_file | ( | struct ly_in * | in,
|  | FILE * | f
| ) |  |

Get or reset file stream input handler.

Parameters

  [in] | in | Input handler.
  [in] | f | Optional new file stream for the handler. If NULL, only the current file stream is returned.

Returns
  NULL in case of invalid argument or an error when setting up the new input file, original input handler `in` is untouched in this case.
  Previous file stream of the handler. Note that caller is responsible for closing the returned stream in case of setting new stream `f`.

## ly_in_filepath()

LIBYANG_API_DECL const char * ly_in_filepath | ( | struct ly_in * | in,
|  | const char * | filepath,
|  | size_t | len
| ) |  |

Get or change the filepath of the file where the parser reads the data.

Note that in case of changing the filepath, the current file is closed and a new one is created/opened instead of renaming the previous file. Also note that the previous filepath string is returned only in case of not changing it's value.

Parameters

  [in] | in | Input handler.
  [in] | filepath | Optional new filepath for the handler. If and only if NULL, the current filepath string is returned.
  [in] | len | Optional number of bytes to use from `filepath`. If 0, the `filepath` is considered to be NULL-terminated and the whole string is taken into account.

Returns
  Previous filepath string in case the `filepath` argument is NULL.
  NULL if changing filepath succeedes and ((void *)-1) otherwise.

## ly_in_free()

LIBYANG_API_DECL void ly_in_free | ( | struct ly_in * | in,
|  | ly_bool | destroy
| ) |  |

Free the input handler.

Parameters

  [in] | in | Input handler to free.
  [in] | destroy | Flag to free the input data buffer (for LY_IN_MEMORY) or to close stream/file descriptor (for LY_IN_FD and LY_IN_FILE)

## ly_in_memory()

LIBYANG_API_DECL const char * ly_in_memory | ( | struct ly_in * | in,
|  | const char * | str
| ) |  |

Get or change memory where the data are read from.

Parameters

  [in] | in | Input handler.
  [in] | str | String containing the data to read. The input data are expected to be NULL-terminated. Note that in case the destroy argument of ly_in_free() is used, the input string is passed to free(), so if it is really a static string, do not use the destroy argument!

Returns
  Previous starting address to read data from. Note that the caller is responsible to free the data in case of changing string pointer `str`.

## ly_in_new_fd()

LIBYANG_API_DECL LY_ERR ly_in_new_fd | ( | int | fd,
|  | struct ly_in ** | in
| ) |  |

Create input handler using file descriptor.

Parameters

  [in] | fd | File descriptor to use.
  [out] | in | Created input handler supposed to be passed to different ly*_parse() functions.

Returns
  LY_SUCCESS in case of success
  LY_ERR value in case of failure.

## ly_in_new_file()

LIBYANG_API_DECL LY_ERR ly_in_new_file | ( | FILE * | f,
|  | struct ly_in ** | in
| ) |  |

Create input handler using file stream.

Parameters

  [in] | f | File stream to use.
  [out] | in | Created input handler supposed to be passed to different ly*_parse() functions.

Returns
  LY_SUCCESS in case of success
  LY_ERR value in case of failure.

## ly_in_new_filepath()

LIBYANG_API_DECL LY_ERR ly_in_new_filepath | ( | const char * | filepath,
|  | size_t | len,
|  | struct ly_in ** | in
| ) |  |

Create input handler file of the given filename.

Parameters

  [in] | filepath | Path of the file where to read data.
  [in] | len | Optional number of bytes to use from `filepath`. If 0, the `filepath` is considered to be NULL-terminated and the whole string is taken into account.
  [out] | in | Created input handler supposed to be passed to different ly*_parse() functions.

Returns
  LY_SUCCESS in case of success
  LY_ERR value in case of failure.

## ly_in_new_memory()

LIBYANG_API_DECL LY_ERR ly_in_new_memory | ( | const char * | str,
|  | struct ly_in ** | in
| ) |  |

Create input handler using memory to read data.

Parameters

  [in] | str | Pointer where to start reading data. The input data are expected to be NULL-terminated. Note that in case the destroy argument of ly_in_free() is used, the input string is passed to free(), so if it is really a static string, do not use the destroy argument!
  [out] | in | Created input handler supposed to be passed to different ly*_parse() functions.

Returns
  LY_SUCCESS in case of success
  LY_ERR value in case of failure.

## ly_in_parsed()

LIBYANG_API_DECL size_t ly_in_parsed | ( | const struct ly_in * | in | ) |

Get the number of parsed bytes by the last function.

Parameters

  [in] | in | In structure used.

Returns
  Number of parsed bytes.

## ly_in_read()

LIBYANG_API_DECL LY_ERR ly_in_read | ( | struct ly_in * | in,
|  | void * | buf,
|  | size_t | count
| ) |  |

Read bytes from an input.

Does not count new lines, which is expected from the caller who has better idea about the content of the read data and can better optimize counting.

Parameters

  [in] | in | Input structure.
  [in] | buf | Destination buffer.
  [in] | count | Number of bytes to read.

Returns
  LY_SUCCESS on success,
  LY_EDENIED on EOF.

## ly_in_reset()

LIBYANG_API_DECL LY_ERR ly_in_reset | ( | struct ly_in * | in | ) |

Reset the input medium to read from its beginning, so the following parser function will read from the object's beginning.

Note that in case the underlying output is not seekable (stream referring a pipe/FIFO/socket or the callback output type), nothing actually happens despite the function succeeds. Also note that the medium is not returned to the state it was when the handler was created. For example, file is seeked into the offset zero, not to the offset where it was opened when ly_in_new_file() was called.

Parameters

  [in] | in | Input handler.

Returns
  LY_SUCCESS in case of success
  LY_ESYS in case of failure

## ly_in_skip()

LIBYANG_API_DECL LY_ERR ly_in_skip | ( | struct ly_in * | in,
|  | size_t | count
| ) |  |

Just skip bytes in an input.

Does not count new lines, which is expected from the caller who has better idea about the content of the skipped data and can better optimize counting.

Parameters

  [in] | in | Input structure.
  [in] | count | Number of bytes to skip.

Returns
  LY_SUCCESS on success,
  LY_EDENIED on EOF.

## ly_in_type()

LIBYANG_API_DECL LY_IN_TYPE ly_in_type | ( | const struct ly_in * | in | ) |

Get input type of the input handler.

Parameters

  [in] | in | Input handler.

Returns
  Type of the parser's input.