| 1 | #ifndef FIO_PARSE_PATTERN_H |
| 2 | #define FIO_PARSE_PATTERN_H |
| 3 | |
| 4 | /* |
| 5 | * The pattern is dynamically allocated, but that doesn't mean there |
| 6 | * are not limits. The network protocol has a limit of |
| 7 | * FIO_SERVER_MAX_CMD_MB and potentially two patterns must fit in there. |
| 8 | * There's also a need to verify the incoming data from the network and |
| 9 | * this provides a sensible check. |
| 10 | * |
| 11 | * 128MiB is an arbitrary limit that meets these criteria. The patterns |
| 12 | * tend to be truncated at the IO size anyway and IO sizes that large |
| 13 | * aren't terribly practical. |
| 14 | */ |
| 15 | #define MAX_PATTERN_SIZE (128 << 20) |
| 16 | |
| 17 | /** |
| 18 | * Pattern format description. The input for 'parse_pattern'. |
| 19 | * Describes format with its name and callback, which should |
| 20 | * be called to paste something inside the buffer. |
| 21 | */ |
| 22 | struct pattern_fmt_desc { |
| 23 | const char *fmt; |
| 24 | unsigned int len; |
| 25 | int (*paste)(char *buf, unsigned int len, void *priv); |
| 26 | }; |
| 27 | |
| 28 | /** |
| 29 | * Pattern format. The output of 'parse_pattern'. |
| 30 | * Describes the exact position inside the xbuffer. |
| 31 | */ |
| 32 | struct pattern_fmt { |
| 33 | unsigned int off; |
| 34 | const struct pattern_fmt_desc *desc; |
| 35 | }; |
| 36 | |
| 37 | int parse_and_fill_pattern_alloc(const char *in, unsigned int in_len, |
| 38 | char **out, const struct pattern_fmt_desc *fmt_desc, |
| 39 | struct pattern_fmt *fmt, unsigned int *fmt_sz_out); |
| 40 | |
| 41 | int paste_format_inplace(char *pattern, unsigned int pattern_len, |
| 42 | struct pattern_fmt *fmt, unsigned int fmt_sz, |
| 43 | void *priv); |
| 44 | |
| 45 | int paste_format(const char *pattern, unsigned int pattern_len, |
| 46 | struct pattern_fmt *fmt, unsigned int fmt_sz, |
| 47 | char *out, unsigned int out_len, void *priv); |
| 48 | |
| 49 | int cpy_pattern(const char *pattern, unsigned int pattern_len, |
| 50 | char *out, unsigned int out_len); |
| 51 | |
| 52 | int cmp_pattern(const char *pattern, unsigned int pattern_size, |
| 53 | unsigned int off, const char *buf, unsigned int len); |
| 54 | |
| 55 | #endif |