From be733f30414ceb85304396d30b9648b6afe283e5 Mon Sep 17 00:00:00 2001 From: Jakub Zawadzki Date: Sat, 21 Dec 2013 14:38:51 +0000 Subject: Move epan/base64.[ch] to wsutil/ with function name change. svn path=/trunk/; revision=54326 --- epan/CMakeLists.txt | 1 - epan/Makefile.common | 2 -- epan/base64.c | 67 ------------------------------------------- epan/base64.h | 41 -------------------------- epan/dissectors/packet-http.c | 4 +-- epan/dissectors/packet-smtp.c | 18 ++++++------ epan/tvbuff_base64.c | 4 +-- epan/wslua/wslua_tvb.c | 4 +-- wsutil/CMakeLists.txt | 1 + wsutil/Makefile.common | 4 ++- wsutil/base64.c | 67 +++++++++++++++++++++++++++++++++++++++++++ wsutil/base64.h | 41 ++++++++++++++++++++++++++ 12 files changed, 127 insertions(+), 127 deletions(-) delete mode 100644 epan/base64.c delete mode 100644 epan/base64.h create mode 100644 wsutil/base64.c create mode 100644 wsutil/base64.h diff --git a/epan/CMakeLists.txt b/epan/CMakeLists.txt index 9b20aa0e63..c7a7b98cf3 100644 --- a/epan/CMakeLists.txt +++ b/epan/CMakeLists.txt @@ -1471,7 +1471,6 @@ set(LIBWIRESHARK_FILES app_mem_usage.c asn1.c atalk-utils.c - base64.c camel-persistentdata.c charsets.c circuit.c diff --git a/epan/Makefile.common b/epan/Makefile.common index 3e7f1b288d..69b7f6d811 100644 --- a/epan/Makefile.common +++ b/epan/Makefile.common @@ -32,7 +32,6 @@ LIBWIRESHARK_SRC = \ app_mem_usage.c \ asn1.c \ atalk-utils.c \ - base64.c \ camel-persistentdata.c \ charsets.c \ circuit.c \ @@ -158,7 +157,6 @@ LIBWIRESHARK_INCLUDES = \ asn1.h \ atalk-utils.h \ ax25_pids.h \ - base64.h \ bridged_pids.h \ camel-persistentdata.h \ charsets.h \ diff --git a/epan/base64.c b/epan/base64.c deleted file mode 100644 index bf507fca8a..0000000000 --- a/epan/base64.c +++ /dev/null @@ -1,67 +0,0 @@ -/* base64.c - * Base-64 conversion - * - * $Id$ - * - * Wireshark - Network traffic analyzer - * By Gerald Combs - * Copyright 1998 Gerald Combs - * - * This program 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 2 - * of the License, or (at your option) any later version. - * - * This program 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 this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#include "config.h" - -#include -#include "base64.h" - -/* Decode a base64 string in-place - simple and slow algorithm. - Return length of result. Taken from rproxy/librsync/base64.c by - Andrew Tridgell. */ - -size_t epan_base64_decode(char *s) -{ - static const char b64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/\r\n"; - int bit_offset, byte_offset, idx, i; - unsigned char *d = (unsigned char *)s; - char *p; - int cr_idx; - - /* we will allow CR and LF - but ignore them */ - cr_idx = (int) (strchr(b64, '\r') - b64); - - i=0; - - while (*s && (p=strchr(b64, *s))) { - idx = (int)(p - b64); - if(idx < cr_idx) { - byte_offset = (i*6)/8; - bit_offset = (i*6)%8; - d[byte_offset] &= ~((1<<(8-bit_offset))-1); - if (bit_offset < 3) { - d[byte_offset] |= (idx << (2-bit_offset)); - } else { - d[byte_offset] |= (idx >> (bit_offset-2)); - d[byte_offset+1] = 0; - d[byte_offset+1] |= (idx << (8-(bit_offset-2))) & 0xFF; - } - i++; - } - s++; - } - - d[i*3/4] = 0; - return i*3/4; -} diff --git a/epan/base64.h b/epan/base64.h deleted file mode 100644 index 2888bbdac0..0000000000 --- a/epan/base64.h +++ /dev/null @@ -1,41 +0,0 @@ -/* base64.h - * Base-64 conversion - * - * $Id$ - * - * Wireshark - Network traffic analyzer - * By Gerald Combs - * Copyright 1998 Gerald Combs - * - * This program 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 2 - * of the License, or (at your option) any later version. - * - * This program 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 this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ -#ifndef __BASE64_H__ -#define __BASE64_H__ - -#include "ws_symbol_export.h" - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -/* In-place decoding of a base64 string. Resulting string is NULL terminated */ -WS_DLL_PUBLIC -size_t epan_base64_decode(char *s); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* __BASE64_H__ */ diff --git a/epan/dissectors/packet-http.c b/epan/dissectors/packet-http.c index ce372e6823..1a9529e8ea 100644 --- a/epan/dissectors/packet-http.c +++ b/epan/dissectors/packet-http.c @@ -41,7 +41,7 @@ #include #include #include -#include +#include #include #include @@ -2655,7 +2655,7 @@ check_auth_basic(proto_item *hdr_item, tvbuff_t *tvb, gchar *value) hdr_tree = NULL; value += hdrlen; - epan_base64_decode(value); + ws_base64_decode_inplace(value); proto_tree_add_string(hdr_tree, hf_http_basic, tvb, 0, 0, value); diff --git a/epan/dissectors/packet-smtp.c b/epan/dissectors/packet-smtp.c index bdcb4b8070..6a1f8bdcf7 100644 --- a/epan/dissectors/packet-smtp.c +++ b/epan/dissectors/packet-smtp.c @@ -40,7 +40,7 @@ #include #include #include -#include +#include #include /* RFC 2821 */ @@ -321,7 +321,7 @@ decode_plain_auth(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, decrypt = tvb_get_string(wmem_packet_scope(), tvb, a_offset, a_linelen); if (stmp_decryption_enabled) { - returncode = (gint)epan_base64_decode(decrypt); + returncode = (gint)ws_base64_decode_inplace(decrypt); if (returncode) { length_user1 = (gint)strlen(decrypt); if (returncode >= (length_user1 + 1)) { @@ -579,7 +579,7 @@ dissect_smtp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) (pinfo->fd->num >= session_state->first_auth_frame) && ((session_state->last_auth_frame == 0) || (pinfo->fd->num <= session_state->last_auth_frame))) { decrypt = tvb_get_string(wmem_packet_scope(), tvb, loffset, linelen); - if ((stmp_decryption_enabled) && (epan_base64_decode(decrypt) > 0)) { + if ((stmp_decryption_enabled) && (ws_base64_decode_inplace(decrypt) > 0)) { line = decrypt; } else { line = tvb_get_ptr(tvb, loffset, linelen); @@ -837,7 +837,7 @@ dissect_smtp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) /* This line wasn't already decrypted through the state machine */ decrypt = tvb_get_string(wmem_packet_scope(), tvb, loffset, linelen); if (stmp_decryption_enabled) { - if (epan_base64_decode(decrypt) == 0) { + if (ws_base64_decode_inplace(decrypt) == 0) { /* Go back to the original string */ decrypt = tvb_get_string(wmem_packet_scope(), tvb, loffset, linelen); } @@ -851,7 +851,7 @@ dissect_smtp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) /* This line wasn't already decrypted through the state machine */ decrypt = tvb_get_string(wmem_packet_scope(), tvb, loffset, linelen); if (stmp_decryption_enabled) { - if (epan_base64_decode(decrypt) == 0) { + if (ws_base64_decode_inplace(decrypt) == 0) { /* Go back to the original string */ decrypt = tvb_get_string(wmem_packet_scope(), tvb, loffset, linelen); } @@ -863,7 +863,7 @@ dissect_smtp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) } else if (session_state->ntlm_rsp_frame == pinfo->fd->num) { decrypt = tvb_get_string(wmem_packet_scope(), tvb, loffset, linelen); if (stmp_decryption_enabled) { - if (epan_base64_decode(decrypt) == 0) { + if (ws_base64_decode_inplace(decrypt) == 0) { /* Go back to the original string */ decrypt = tvb_get_string(wmem_packet_scope(), tvb, loffset, linelen); col_append_str(pinfo->cinfo, COL_INFO, decrypt); @@ -907,7 +907,7 @@ dissect_smtp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) /* This line wasn't already decrypted through the state machine */ decrypt = tvb_get_string(wmem_packet_scope(), tvb, loffset + 11, linelen - 11); if (stmp_decryption_enabled) { - if (epan_base64_decode(decrypt) == 0) { + if (ws_base64_decode_inplace(decrypt) == 0) { /* Go back to the original string */ decrypt = tvb_get_string(wmem_packet_scope(), tvb, loffset + 11, linelen - 11); } @@ -922,7 +922,7 @@ dissect_smtp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) loffset + 5, linelen - 5, ENC_ASCII|ENC_NA); decrypt = tvb_get_string(wmem_packet_scope(), tvb, loffset + 10, linelen - 10); if (stmp_decryption_enabled) { - if (epan_base64_decode(decrypt) == 0) { + if (ws_base64_decode_inplace(decrypt) == 0) { /* Go back to the original string */ decrypt = tvb_get_string(wmem_packet_scope(), tvb, loffset + 10, linelen - 10); col_append_str(pinfo->cinfo, COL_INFO, tvb_get_string(wmem_packet_scope(), tvb, loffset, 10)); @@ -1097,7 +1097,7 @@ dissect_smtp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) if (linelen >= 4) { if ((stmp_decryption_enabled) && (code == 334)) { decrypt = tvb_get_string(wmem_packet_scope(), tvb, offset + 4, linelen - 4); - if (epan_base64_decode(decrypt) > 0) { + if (ws_base64_decode_inplace(decrypt) > 0) { if (g_ascii_strncasecmp(decrypt, "NTLMSSP", 7) == 0) { base64_string = tvb_get_string(wmem_packet_scope(), tvb, loffset + 4, linelen - 4); col_append_fstr(pinfo->cinfo, COL_INFO, "%d ", code); diff --git a/epan/tvbuff_base64.c b/epan/tvbuff_base64.c index 425670a71b..5f4cb67f8b 100644 --- a/epan/tvbuff_base64.c +++ b/epan/tvbuff_base64.c @@ -27,7 +27,7 @@ #include #include -#include +#include tvbuff_t * base64_to_tvb(tvbuff_t *parent, const char *base64) @@ -36,7 +36,7 @@ base64_to_tvb(tvbuff_t *parent, const char *base64) char *data = g_strdup(base64); gint len; - len = (gint) epan_base64_decode(data); + len = (gint) ws_base64_decode_inplace(data); tvb = tvb_new_child_real_data(parent, (const guint8 *)data, len, len); tvb_set_free_cb(tvb, g_free); diff --git a/epan/wslua/wslua_tvb.c b/epan/wslua/wslua_tvb.c index aa1d7b5bc1..2341abfc1f 100644 --- a/epan/wslua/wslua_tvb.c +++ b/epan/wslua/wslua_tvb.c @@ -35,7 +35,7 @@ /* WSLUA_MODULE Tvb Functions for handling packet data */ #include "wslua.h" -#include "epan/base64.h" +#include "wsutil/base64.h" WSLUA_CLASS_DEFINE(ByteArray,FAIL_ON_NULL("null bytearray"),NOP); @@ -269,7 +269,7 @@ static int ByteArray_base64_decode(lua_State* L) { memcpy(data, ba->data, ba->len); data[ba->len] = '\0'; - len = epan_base64_decode(data); + len = ws_base64_decode_inplace(data); g_byte_array_append(ba2,data,(int)len); g_free(data); diff --git a/wsutil/CMakeLists.txt b/wsutil/CMakeLists.txt index 9ad86e8247..b14c236238 100644 --- a/wsutil/CMakeLists.txt +++ b/wsutil/CMakeLists.txt @@ -39,6 +39,7 @@ set(WSUTIL_FILES adler32.c aes.c airpdcap_wep.c + base64.c bitswap.c crash_info.c crc10.c diff --git a/wsutil/Makefile.common b/wsutil/Makefile.common index 1ed4f22ed3..96b5a7cfa3 100644 --- a/wsutil/Makefile.common +++ b/wsutil/Makefile.common @@ -32,7 +32,8 @@ LIBWSUTIL_SRC = \ adler32.c \ aes.c \ airpdcap_wep.c \ - bitswap.c \ + base64.c \ + bitswap.c \ crash_info.c \ crc6.c \ crc7.c \ @@ -66,6 +67,7 @@ LIBWSUTIL_SRC = \ LIBWSUTIL_INCLUDES = \ adler32.h \ aes.h \ + base64.h \ bits_ctz.h \ bits_count_ones.h \ bitswap.h \ diff --git a/wsutil/base64.c b/wsutil/base64.c new file mode 100644 index 0000000000..2211cff522 --- /dev/null +++ b/wsutil/base64.c @@ -0,0 +1,67 @@ +/* base64.c + * Base-64 conversion + * + * $Id$ + * + * Wireshark - Network traffic analyzer + * By Gerald Combs + * Copyright 1998 Gerald Combs + * + * This program 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 2 + * of the License, or (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include "config.h" + +#include +#include "base64.h" + +/* Decode a base64 string in-place - simple and slow algorithm. + Return length of result. Taken from rproxy/librsync/base64.c by + Andrew Tridgell. */ + +size_t ws_base64_decode_inplace(char *s) +{ + static const char b64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/\r\n"; + int bit_offset, byte_offset, idx, i; + unsigned char *d = (unsigned char *)s; + char *p; + int cr_idx; + + /* we will allow CR and LF - but ignore them */ + cr_idx = (int) (strchr(b64, '\r') - b64); + + i=0; + + while (*s && (p=strchr(b64, *s))) { + idx = (int)(p - b64); + if(idx < cr_idx) { + byte_offset = (i*6)/8; + bit_offset = (i*6)%8; + d[byte_offset] &= ~((1<<(8-bit_offset))-1); + if (bit_offset < 3) { + d[byte_offset] |= (idx << (2-bit_offset)); + } else { + d[byte_offset] |= (idx >> (bit_offset-2)); + d[byte_offset+1] = 0; + d[byte_offset+1] |= (idx << (8-(bit_offset-2))) & 0xFF; + } + i++; + } + s++; + } + + d[i*3/4] = 0; + return i*3/4; +} diff --git a/wsutil/base64.h b/wsutil/base64.h new file mode 100644 index 0000000000..e9bc51758d --- /dev/null +++ b/wsutil/base64.h @@ -0,0 +1,41 @@ +/* base64.h + * Base-64 conversion + * + * $Id$ + * + * Wireshark - Network traffic analyzer + * By Gerald Combs + * Copyright 1998 Gerald Combs + * + * This program 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 2 + * of the License, or (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ +#ifndef __BASE64_H__ +#define __BASE64_H__ + +#include "ws_symbol_export.h" + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/* In-place decoding of a base64 string. Resulting string is NULL terminated */ +WS_DLL_PUBLIC +size_t ws_base64_decode_inplace(char *s); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* __BASE64_H__ */ -- cgit v1.2.1