From a1c9895cdb3287539ad005d97aa16eb9e3888bc6 Mon Sep 17 00:00:00 2001 From: "7u83@mail.ru" <7u83@mail.ru@noemail.net> Date: Sat, 12 Mar 2016 08:35:54 +0000 Subject: [PATCH] moved cw_is_utf8 to format_is_utf8. FossilOrigin-Name: d68e3bec6f9bcf6255ff7e71ae3980a77b207ed1e5bd03cef5778094484108c0 --- src/cw/Makefile | 2 +- src/cw/capwap.h | 2 +- src/cw/dbg.c | 4 +-- src/cw/format.h | 2 +- src/cw/format_is_utf8.c | 66 ++++++++++++++++++++++++++++++++++++ src/cw/mbag_type_bstr16.c | 2 +- src/cw/mbag_type_vendorstr.c | 2 +- src/cw/utf8.c | 36 -------------------- 8 files changed, 73 insertions(+), 43 deletions(-) create mode 100644 src/cw/format_is_utf8.c delete mode 100644 src/cw/utf8.c diff --git a/src/cw/Makefile b/src/cw/Makefile index c6fb2551..3bb16cd8 100644 --- a/src/cw/Makefile +++ b/src/cw/Makefile @@ -81,7 +81,7 @@ MAVLOBJS= \ mavl_merge.o \ mavl_create_conststr.o \ mlist.o \ - utf8.o \ + format_is_utf8.o \ cw_load_file.o \ cw_save_file.o diff --git a/src/cw/capwap.h b/src/cw/capwap.h index f31a5ec0..dd3d83dd 100644 --- a/src/cw/capwap.h +++ b/src/cw/capwap.h @@ -769,7 +769,7 @@ extern int cw_in_radio_administrative_state(struct conn *conn, struct cw_action_ int cw_out_ac_name_with_priority(struct conn *conn, struct cw_action_out *a, uint8_t * dst); int cw_send_request(struct conn *conn, int msg_id); -int cw_is_utf8(unsigned char *str, size_t len); +//int cw_is_utf8(unsigned char *str, size_t len); int cw_in_ac_name_with_priority(struct conn *conn, struct cw_action_in *a, uint8_t * data, int len, struct sockaddr *from); diff --git a/src/cw/dbg.c b/src/cw/dbg.c index 3a908d44..bf874b18 100644 --- a/src/cw/dbg.c +++ b/src/cw/dbg.c @@ -518,7 +518,7 @@ void cw_dbg_colored(int level, const char *file, int line, const char *format, . } -int cw_is_utf8(unsigned char *str, size_t len); +//int cw_is_utf8(unsigned char *str, size_t len); int cw_format_item(char *dst,mbag_item_t * item) @@ -549,7 +549,7 @@ static int cw_format_version(char *s, bstrv_t ver, char * def) int i; - if ( cw_is_utf8(version,len) ){ + if ( format_is_utf8(version,len) ){ if (len != 0 ) rs+=sprintf(s+rs,"%.*s",len,version); else diff --git a/src/cw/format.h b/src/cw/format.h index 130f8181..5d18a7e3 100644 --- a/src/cw/format.h +++ b/src/cw/format.h @@ -81,7 +81,7 @@ static inline int format_hdr_flags(char *dst,uint8_t *th) } -int cw_is_utf8(unsigned char *str, size_t len); +int format_is_utf8(unsigned char *str, size_t len); /**@}*/ diff --git a/src/cw/format_is_utf8.c b/src/cw/format_is_utf8.c new file mode 100644 index 00000000..b36ff7e1 --- /dev/null +++ b/src/cw/format_is_utf8.c @@ -0,0 +1,66 @@ +/* + This file is part of actube. + + actube is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + libcapwap is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Foobar. If not, see . + +*/ + +/** + * @file + * @brief Implementation for format_is_utf8 + */ + +#include "format.h" + +/** + * Check if a string is in UTF8 format + * @param str String to check + * @param len Length of the string + * @return 0 if the string is not in UTF8 format, otherwise it is UTF8. + */ + +int format_is_utf8(unsigned char *str, size_t len) +{ + size_t i = 0; + size_t j = 0; + size_t bytes = 0; + + while (i < len) { + j = i; + if (str[i] < 0x20) { + return 0; + } + if (str[i] <= 0x7F) + bytes = 0; + else if (str[i] >= 0xC0 /*11000000 */ && str[i] <= 0xDF /*11011111 */ ) + bytes = 1; + else if (str[i] >= 0xE0 /*11100000 */ && str[i] <= 0xEF /*11101111 */ ) + bytes = 2; + else if (str[i] >= 0xF0 /*11110000 */ + && str[i] <= 0xF4 /* Cause of RFC 3629 */ ) + bytes = 3; + else { + return 0; + } + i += 1; + while (i < len && bytes > 0 && str[i] >= 0x80 && str[i] <= 0xBF) { + i += 1; + bytes -= 1; + } + if (bytes != 0) { + return 0; + } + } + return 1; +} diff --git a/src/cw/mbag_type_bstr16.c b/src/cw/mbag_type_bstr16.c index c2814e50..ed074428 100644 --- a/src/cw/mbag_type_bstr16.c +++ b/src/cw/mbag_type_bstr16.c @@ -15,7 +15,7 @@ static int to_str(void *item,char *dst) char *d = dst; - int utf8 = cw_is_utf8(bstr16_data(i->data), bstr16_len(i->data)); + int utf8 = format_is_utf8(bstr16_data(i->data), bstr16_len(i->data)); if (utf8) { diff --git a/src/cw/mbag_type_vendorstr.c b/src/cw/mbag_type_vendorstr.c index 4202f5de..fd842df8 100644 --- a/src/cw/mbag_type_vendorstr.c +++ b/src/cw/mbag_type_vendorstr.c @@ -35,7 +35,7 @@ static int to_str(void *item,char *dst) char *d=dst; d+=sprintf(d,"%d,",bstrv_get_vendor_id(i->data)); - if (cw_is_utf8(bstrv_data(i->data), bstrv_len(i->data))) { + if (format_is_utf8(bstrv_data(i->data), bstrv_len(i->data))) { d += sprintf(d, "%.*s", bstrv_len(i->data), bstrv_data(i->data)); } else { diff --git a/src/cw/utf8.c b/src/cw/utf8.c deleted file mode 100644 index 956fcee7..00000000 --- a/src/cw/utf8.c +++ /dev/null @@ -1,36 +0,0 @@ -#include "capwap.h" - -int cw_is_utf8(unsigned char *str, size_t len) -{ - size_t i = 0; - size_t j = 0; - size_t bytes = 0; - - while (i < len) { - j = i; - if (str[i] < 0x20) { - return 0; - } - if (str[i] <= 0x7F) - bytes = 0; - else if (str[i] >= 0xC0 /*11000000 */ && str[i] <= 0xDF /*11011111 */ ) - bytes = 1; - else if (str[i] >= 0xE0 /*11100000 */ && str[i] <= 0xEF /*11101111 */ ) - bytes = 2; - else if (str[i] >= 0xF0 /*11110000 */ - && str[i] <= 0xF4 /* Cause of RFC 3629 */ ) - bytes = 3; - else { - return 0; - } - i += 1; - while (i < len && bytes > 0 && str[i] >= 0x80 && str[i] <= 0xBF) { - i += 1; - bytes -= 1; - } - if (bytes != 0) { - return 0; - } - } - return 1; -}