My Project
|
00001 /* Copyright (c) 2008, 2015, Oracle and/or its affiliates. All rights reserved. 00002 00003 This program is free software; you can redistribute it and/or modify 00004 it under the terms of the GNU General Public License as published by 00005 the Free Software Foundation; version 2 of the License. 00006 00007 This program is distributed in the hope that it will be useful, 00008 but WITHOUT ANY WARRANTY; without even the implied warranty of 00009 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00010 GNU General Public License for more details. 00011 00012 You should have received a copy of the GNU General Public License 00013 along with this program; if not, write to the Free Software Foundation, 00014 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */ 00015 00016 #ifndef SQL_DIGEST_H 00017 #define SQL_DIGEST_H 00018 00019 #include <string.h> 00020 class String; 00021 #include "my_md5.h" 00022 00023 #define MAX_DIGEST_STORAGE_SIZE (1024*1024) 00024 00025 ulong get_max_digest_length(); 00026 00031 struct sql_digest_storage 00032 { 00033 bool m_full; 00034 size_t m_byte_count; 00035 unsigned char m_md5[MD5_HASH_SIZE]; 00037 uint m_charset_number; 00047 unsigned char *m_token_array; 00048 /* Length of the token array to be considered for DIGEST_TEXT calculation. */ 00049 uint m_token_array_length; 00050 00051 sql_digest_storage() 00052 { 00053 reset(NULL, 0); 00054 } 00055 00056 inline void reset(unsigned char *token_array, uint length) 00057 { 00058 m_token_array= token_array; 00059 m_token_array_length= length; 00060 reset(); 00061 } 00062 00063 inline void reset() 00064 { 00065 m_full= false; 00066 m_byte_count= 0; 00067 m_charset_number= 0; 00068 if (m_token_array_length > 0) 00069 { 00070 memset(m_token_array, 0, m_token_array_length); 00071 } 00072 memset(m_md5, 0, MD5_HASH_SIZE); 00073 } 00074 00075 inline bool is_empty() 00076 { 00077 return (m_byte_count == 0); 00078 } 00079 00080 inline void copy(const sql_digest_storage *from) 00081 { 00082 /* 00083 Keep in mind this is a dirty copy of something that may change, 00084 as the thread producing the digest is executing concurrently, 00085 without any lock enforced. 00086 */ 00087 size_t byte_count_copy= m_token_array_length < from->m_byte_count ? 00088 m_token_array_length : from->m_byte_count; 00089 00090 if (byte_count_copy > 0) 00091 { 00092 m_full= from->m_full; 00093 m_byte_count= byte_count_copy; 00094 m_charset_number= from->m_charset_number; 00095 memcpy(m_token_array, from->m_token_array, m_byte_count); 00096 memcpy(m_md5, from->m_md5, MD5_HASH_SIZE); 00097 } 00098 else 00099 { 00100 m_full= false; 00101 m_byte_count= 0; 00102 m_charset_number= 0; 00103 } 00104 } 00105 }; 00106 typedef struct sql_digest_storage sql_digest_storage; 00107 00113 void compute_digest_md5(const sql_digest_storage *digest_storage, unsigned char *md5); 00114 00128 void compute_digest_text(const sql_digest_storage *digest_storage, 00129 String *digest_text); 00130 00131 #endif 00132