Pass modutil function state as a struct

This allows the type to change without changing it at the call sites.
This commit is contained in:
Markus Mäkelä
2017-08-29 22:46:35 +03:00
parent 2a346fd061
commit e6f78bfcb3
5 changed files with 36 additions and 24 deletions

View File

@ -52,6 +52,15 @@ GWBUF* modutil_create_mysql_err_msg(int packet_number,
const char *statemsg,
const char *msg);
/** Struct used for tracking the state inside the modutil functions */
typedef struct
{
uint8_t state;
} modutil_state;
/** Static initialization define for modutil_state */
#define MODUTIL_STATE_INIT {0}
/**
* @brief Count the number of EOF and ERR packets in the buffer.
*
@ -59,19 +68,20 @@ GWBUF* modutil_create_mysql_err_msg(int packet_number,
* whole packets. If partial packets are in the buffer, they are ignored.
* The caller must handle the detection of partial packets in buffers.
*
* On the first invocation, the value pointed by @c skip should be set to false.
* On all subsequent calls, for partial result sets, the function uses it to
* store the internal state. When the value pointed by @c skip is set to true,
* the next call must be done with only unprocessed packets in @c reply.
* Before the first invocation, the value pointed by the @c state parameter
* should be initialized with MODUTIL_STATE_INIT. All subsequent calls with a
* partially processed result set must be made with only unprocessed packets
* in @c reply.
*
* @param reply Buffer to use
* @param n_found Number of previous found packets
* @param more Set to true of more results exist
* @param skip Internal state of the function used for handling large payloads.
* @param more Set to true if more results exist
* @param state Internal state of the function, NULL if the function is
* only called once per result set
*
* @return Total number of EOF and ERR packets including the ones already found
*/
int modutil_count_signal_packets(GWBUF *reply, int n_found, bool* more, bool* skip);
int modutil_count_signal_packets(GWBUF *reply, int n_found, bool* more, modutil_state* state);
mxs_pcre2_result_t modutil_mysql_wildcard_match(const char* pattern, const char* string);