61 #define UTF8_REJECT 12 63 static const uint8_t
utf8d[] = {
66 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
67 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
68 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
69 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
70 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,
71 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
72 8,8,2,2,2,2,2,2,2,2,2,2,2,2,2,2, 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
73 10,3,3,3,3,3,3,3,3,3,3,3,3,4,3,3, 11,6,6,6,5,8,8,8,8,8,8,8,8,8,8,8,
77 0,12,24,36,60,96,84,12,12,12,48,72, 12,12,12,12,12,12,12,12,12,12,12,12,
78 12, 0,12,12,12,12,12, 0,12, 0,12,12, 12,24,12,12,12,12,12,24,12,24,12,12,
79 12,12,12,12,12,12,12,24,12,12,12,12, 12,24,12,12,12,12,12,12,12,24,12,12,
80 12,12,12,12,12,12,12,36,12,36,12,12, 12,36,12,12,12,12,12,36,12,36,12,12,
81 12,36,12,12,12,12,12,12,12,12,12,12,
86 static uint32_t
inline decode(uint32_t *
state, uint32_t *codep, uint32_t byte) {
90 (byte & 0x3fu) | (*codep << 6) :
91 (0xff >> type) & (byte);
98 static uint32_t
inline decode(uint32_t *
state, uint32_t byte) {
115 decode(&state, (uint8_t) *src++);
125 while (size && *src) {
126 decode(&state, (uint8_t) *src++);
136 char *last_good = dst;
140 while (size && *src) {
179 switch (validator->
state) {
202 while (size && *data) {
220 #ifdef TEST_FRAMEWORK 226 info->name =
"is_valid";
227 info->category =
"/main/utf8/";
228 info->summary =
"Test ast_utf8_is_valid and ast_utf8_is_validn";
230 "Tests UTF-8 string validation code.";
284 return strcmp(dst, cmp) == 0;
291 info->name =
"copy_string";
292 info->category =
"/main/utf8/";
293 info->summary =
"Test ast_utf8_copy_string";
295 "Tests UTF-8 string copying code.";
322 info->name =
"utf8_validator";
323 info->category =
"/main/utf8/";
324 info->summary =
"Test ast_utf8_validator";
326 "Tests UTF-8 progressive validator code.";
The consumed sequence is invalid UTF-8.
enum sip_cc_notify_state state
void ast_utf8_validator_destroy(struct ast_utf8_validator *validator)
Destroy a UTF-8 validator.
int ast_utf8_validator_new(struct ast_utf8_validator **validator)
Create a new UTF-8 validator.
Asterisk main include file. File version handling, generic pbx functions.
int ast_utf8_is_validn(const char *src, size_t size)
Check if the first size bytes of a string are valid UTF-8.
void ast_utf8_validator_reset(struct ast_utf8_validator *validator)
Reset the state of a UTF-8 validator.
static int test_copy_and_compare(const char *src, size_t dst_len, const char *cmp)
static uint32_t decode(uint32_t *state, uint32_t byte)
int ast_utf8_is_valid(const char *src)
Check if a zero-terminated string is valid UTF-8.
#define AST_TEST_REGISTER(cb)
static void test_utf8_shutdown(void)
UTF-8 information and validation functions.
int ast_utf8_init(void)
Register UTF-8 tests.
enum ast_utf8_validation_result ast_utf8_validator_state(struct ast_utf8_validator *validator)
Get the current UTF-8 validator state.
enum ast_utf8_validation_result ast_utf8_validator_feed(struct ast_utf8_validator *validator, const char *data)
Feed a zero-terminated string into the UTF-8 validator.
int ast_register_cleanup(void(*func)(void))
Register a function to be executed before Asterisk gracefully exits.
void ast_utf8_copy_string(char *dst, const char *src, size_t size)
Copy a string safely ensuring valid UTF-8.
The consumed sequence is valid UTF-8.
#define ast_malloc(len)
A wrapper for malloc()
ast_utf8_validation_result
#define AST_TEST_UNREGISTER(cb)
enum ast_utf8_validation_result ast_utf8_validator_feedn(struct ast_utf8_validator *validator, const char *data, size_t size)
Feed a string into the UTF-8 validator.
AST_TEST_DEFINE(test_utf8_is_valid)
The validator is in an intermediate state.
static const uint8_t utf8d[]