Merge branch 'master' of http://192.168.100.140:8099/sane/code_production
This commit is contained in:
commit
6854c431cf
|
@ -0,0 +1,325 @@
|
|||
// CDlgItemMgr.cpp: 实现文件
|
||||
//
|
||||
|
||||
#include "pch.h"
|
||||
#include "scanner-check.h"
|
||||
#include "CDlgItemMgr.h"
|
||||
#include "afxdialogex.h"
|
||||
|
||||
#include <file/file_util.h>
|
||||
#include <coding/coding.h>
|
||||
|
||||
// CDlgItemMgr 对话框
|
||||
#pragma warning(disable: 4996)
|
||||
|
||||
static bool is_checked(CWnd* ctrl)
|
||||
{
|
||||
return ((CButton*)ctrl)->GetCheck() == BST_CHECKED;
|
||||
}
|
||||
static bool is_checked(CDialogEx* dlg, UINT id)
|
||||
{
|
||||
return is_checked(dlg->GetDlgItem(id));
|
||||
}
|
||||
static void set_checked(CWnd* ctrl, bool checked)
|
||||
{
|
||||
((CButton*)ctrl)->SetCheck(checked ? BST_CHECKED : BST_UNCHECKED);
|
||||
}
|
||||
static void set_checked(CDialogEx* dlg, UINT id, bool checked)
|
||||
{
|
||||
return set_checked(dlg->GetDlgItem(id), checked);
|
||||
}
|
||||
|
||||
IMPLEMENT_DYNAMIC(CDlgItemMgr, CDialogEx)
|
||||
|
||||
CDlgItemMgr::CDlgItemMgr(CWnd* pParent /*=nullptr*/)
|
||||
: CDialogEx(IDD_TEST_ITEM, pParent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
CDlgItemMgr::~CDlgItemMgr()
|
||||
{
|
||||
}
|
||||
|
||||
void CDlgItemMgr::DoDataExchange(CDataExchange* pDX)
|
||||
{
|
||||
CDialogEx::DoDataExchange(pDX);
|
||||
DDX_Control(pDX, IDC_LIST1, list_);
|
||||
}
|
||||
|
||||
BOOL CDlgItemMgr::OnInitDialog()
|
||||
{
|
||||
CDialogEx::OnInitDialog();
|
||||
|
||||
int ind = list_.InsertColumn(list_.GetHeaderCtrl()->GetItemCount(), TEXT("\u5E8F\u53F7"), 0, 40);
|
||||
list_.InsertColumn(list_.GetHeaderCtrl()->GetItemCount(), TEXT("ID"), 0, 60);
|
||||
list_.InsertColumn(list_.GetHeaderCtrl()->GetItemCount(), TEXT("\u540D\u79F0"), 0, 102);
|
||||
list_.InsertColumn(list_.GetHeaderCtrl()->GetItemCount(), TEXT("\u5FC5\u987B\u8054\u673A\u6D4B\u8BD5"), 0, 87);
|
||||
list_.InsertColumn(list_.GetHeaderCtrl()->GetItemCount(), TEXT("\u4E0D\u901A\u8FC7\u5219\u505C\u6B62"), 0, 87);
|
||||
list_.SetExtendedStyle((list_.GetExStyle() | LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES) & (~LVS_EX_CHECKBOXES));
|
||||
list_.ModifyStyle(0, LVS_SINGLESEL);
|
||||
load_stored_config();
|
||||
|
||||
return TRUE; // 除非将焦点设置到控件,否则返回 TRUE
|
||||
}
|
||||
|
||||
BEGIN_MESSAGE_MAP(CDlgItemMgr, CDialogEx)
|
||||
ON_BN_CLICKED(IDC_BUTTON_ADD, &CDlgItemMgr::OnBnClickedButtonAdd)
|
||||
ON_NOTIFY(NM_DBLCLK, IDC_LIST1, &CDlgItemMgr::OnNMDblclkList1)
|
||||
ON_WM_DROPFILES()
|
||||
END_MESSAGE_MAP()
|
||||
|
||||
|
||||
// CDlgItemMgr 消息处理程序
|
||||
|
||||
|
||||
void CDlgItemMgr::OnBnClickedButtonAdd()
|
||||
{
|
||||
// TODO: 在此添加控件通知处理程序代码
|
||||
wchar_t text[128] = { 0 }, name[128] = { 0 };
|
||||
bool online = is_checked(this, IDC_CHECK_ONLINE), fatal = is_checked(this, IDC_CHECK_FATAL);
|
||||
int ind = -1;
|
||||
|
||||
if (::GetWindowTextW(GetDlgItem(IDC_EDIT_TITLE)->m_hWnd, text, _countof(text) - 1) == 0 ||
|
||||
::GetWindowTextW(GetDlgItem(IDC_EDIT_NAME)->m_hWnd, name, _countof(name) - 1) == 0)
|
||||
return;
|
||||
|
||||
for (int i = 0; i < list_.GetItemCount(); ++i)
|
||||
{
|
||||
wchar_t val[128] = { 0 };
|
||||
list_.GetItemText(i, 1, val, _countof(val) - 1);
|
||||
if (wcscmp(name, val) == 0)
|
||||
{
|
||||
ind = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (ind == -1)
|
||||
{
|
||||
wchar_t sn[20] = { 0 };
|
||||
swprintf_s(sn, _countof(sn) - 1, L"%u", list_.GetItemCount() + 1);
|
||||
ind = list_.InsertItem(list_.GetItemCount(), sn);
|
||||
list_.SetItemText(ind, 1, name);
|
||||
}
|
||||
|
||||
list_.SetItemText(ind, 2, text);
|
||||
list_.SetItemText(ind, 3, online ? L"true" : L"false");
|
||||
list_.SetItemText(ind, 4, fatal ? L"true" : L"false");
|
||||
list_.SetItemState(ind, LVNI_FOCUSED | LVIS_SELECTED, LVNI_FOCUSED | LVIS_SELECTED);
|
||||
item_changed();
|
||||
}
|
||||
void CDlgItemMgr::OnNMDblclkList1(NMHDR* pNMHDR, LRESULT* pResult)
|
||||
{
|
||||
LPNMITEMACTIVATE pNMItemActivate = reinterpret_cast<LPNMITEMACTIVATE>(pNMHDR);
|
||||
// TODO: 在此添加控件通知处理程序代码
|
||||
POINT pos = { 0 };
|
||||
RECT r = { 0 };
|
||||
|
||||
GetCursorPos(&pos);
|
||||
list_.ScreenToClient(&pos);
|
||||
r.left = list_.HitTest(pos);
|
||||
if (r.left != -1)
|
||||
{
|
||||
std::vector<int> width;
|
||||
int ind = r.left;
|
||||
|
||||
for (int i = 0; i < list_.GetHeaderCtrl()->GetItemCount(); ++i)
|
||||
{
|
||||
RECT r = { 0 };
|
||||
list_.GetHeaderCtrl()->GetItemRect(i, &r);
|
||||
width.push_back(r.right - r.left);
|
||||
}
|
||||
for (int i = 0; i < width.size(); ++i)
|
||||
{
|
||||
if (pos.x <= width[i])
|
||||
{
|
||||
wchar_t text[128] = { 0 };
|
||||
if (i < 3)
|
||||
{
|
||||
std::wstring tips(L"\u5220\u9664\u6D4B\u8BD5\u9879\uFF1A");
|
||||
|
||||
list_.GetItemText(ind, 1, text, _countof(text) - 1);
|
||||
tips += text;
|
||||
tips += L"\uFF1F";
|
||||
if (::MessageBoxW(m_hWnd, tips.c_str(), L"\u786E\u8BA4", MB_YESNO | MB_ICONQUESTION) == IDYES)
|
||||
{
|
||||
list_.DeleteItem(ind);
|
||||
for (; ind < list_.GetItemCount(); ++ind)
|
||||
{
|
||||
swprintf_s(text, _countof(text) - 1, L"%u", ind + 1);
|
||||
list_.SetItemText(ind, 0, text);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
list_.GetItemText(ind, i, text, _countof(text) - 1);
|
||||
if (wcscmp(text, L"true"))
|
||||
list_.SetItemText(ind, i, L"true");
|
||||
else
|
||||
list_.SetItemText(ind, i, L"false");
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
pos.x -= width[i];
|
||||
}
|
||||
}
|
||||
|
||||
*pResult = 0;
|
||||
item_changed();
|
||||
}
|
||||
|
||||
std::wstring CDlgItemMgr::get_stored_config_file(void)
|
||||
{
|
||||
wchar_t path[MAX_PATH] = { 0 };
|
||||
std::wstring file(L"");
|
||||
size_t pos = 0;
|
||||
|
||||
GetModuleFileNameW(NULL, path, _countof(path) - 1);
|
||||
file = path;
|
||||
pos = file.rfind(L'\\');
|
||||
if (pos++ != std::wstring::npos)
|
||||
file.erase(pos);
|
||||
|
||||
file += L"config\\stored.txt";
|
||||
|
||||
return file;
|
||||
}
|
||||
void CDlgItemMgr::get_item(int ind, page_config::ITEM* item)
|
||||
{
|
||||
wchar_t text[128] = { 0 };
|
||||
|
||||
list_.GetItemText(ind, 1, text, _countof(text) - 1);
|
||||
item->name = text;
|
||||
list_.GetItemText(ind, 2, text, _countof(text) - 1);
|
||||
item->title = text;
|
||||
list_.GetItemText(ind, 3, text, _countof(text) - 1);
|
||||
item->man = wcscmp(text, L"false") == 0;
|
||||
list_.GetItemText(ind, 4, text, _countof(text) - 1);
|
||||
item->fatal = wcscmp(text, L"true") == 0;
|
||||
}
|
||||
void CDlgItemMgr::load_from_file(const wchar_t* file)
|
||||
{
|
||||
wchar_t path[MAX_PATH] = { 0 },
|
||||
*sn = path,
|
||||
*n = sn + 40,
|
||||
*t = n + 40,
|
||||
*m = t + 40,
|
||||
*f = m + 40;
|
||||
size_t pos = 0;
|
||||
std::string bom("");
|
||||
std::wstring cont(L"");
|
||||
|
||||
list_.DeleteAllItems();
|
||||
file_util::load_file(file, got_str, &bom);
|
||||
coding_util::bom::to_unicode(bom.c_str(), bom.length(), got_wstr, &cont);
|
||||
cont += L"\r\n";
|
||||
while ((pos = cont.find(L"\r\n")) != std::wstring::npos)
|
||||
{
|
||||
int cnt = swscanf(cont.substr(0, pos).c_str(), L"%s %s %s %s", n, t, m, f);
|
||||
if (cnt >= 2)
|
||||
{
|
||||
bool man = false, fatal = true;
|
||||
if (cnt >= 3)
|
||||
man = wcscmp(m, L"false") == 0;
|
||||
if (cnt >= 4)
|
||||
fatal = wcscmp(f, L"true") == 0;
|
||||
|
||||
swprintf_s(sn, 20, L"%u", list_.GetItemCount() + 1);
|
||||
cnt = list_.InsertItem(list_.GetItemCount(), sn);
|
||||
list_.SetItemText(cnt, 1, n);
|
||||
list_.SetItemText(cnt, 2, t);
|
||||
list_.SetItemText(cnt, 3, man ? L"false" : L"true");
|
||||
list_.SetItemText(cnt, 4, f ? L"true" : L"false");
|
||||
}
|
||||
|
||||
cont.erase(0, pos + 2);
|
||||
}
|
||||
::PostMessage(GetParent()->m_hWnd, WM_TEST_ITEM_CHANGED, 0, 0);
|
||||
}
|
||||
void CDlgItemMgr::load_stored_config(void)
|
||||
{
|
||||
std::wstring file(get_stored_config_file());
|
||||
|
||||
load_from_file(file.c_str());
|
||||
}
|
||||
void CDlgItemMgr::item_changed(void)
|
||||
{
|
||||
std::vector<page_config::ITEM> items;
|
||||
std::wstring text(L"");
|
||||
std::string bom("");
|
||||
|
||||
get_all_items(items);
|
||||
for (size_t i = 0; i < items.size(); ++i)
|
||||
{
|
||||
text += items[i].name + L" " + items[i].title + L" ";
|
||||
text += items[i].man ? L"false " : L"true ";
|
||||
text += items[i].fatal ? L"true\r\n" : L"false\r\n";
|
||||
}
|
||||
coding_util::bom::from_unicode(text.c_str(), text.length() * 2, got_str, &bom);
|
||||
file_util::save_2_file(bom.c_str(), bom.length(), get_stored_config_file().c_str());
|
||||
::PostMessage(GetParent()->m_hWnd, WM_TEST_ITEM_CHANGED, 0, 0);
|
||||
}
|
||||
bool CDlgItemMgr::get_name(const wchar_t* title, page_config::ITEM* item)
|
||||
{
|
||||
wchar_t text[128] = { 0 };
|
||||
|
||||
for (size_t i = 0; i < list_.GetItemCount(); ++i)
|
||||
{
|
||||
list_.GetItemText(i, 2, text, _countof(text) - 1);
|
||||
if (wcscmp(text, title) == 0)
|
||||
{
|
||||
get_item(i, item);
|
||||
return true;
|
||||
}
|
||||
text[0] = 0;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
bool CDlgItemMgr::get_title(const wchar_t* name, page_config::ITEM* item)
|
||||
{
|
||||
wchar_t text[128] = { 0 };
|
||||
|
||||
for (size_t i = 0; i < list_.GetItemCount(); ++i)
|
||||
{
|
||||
list_.GetItemText(i, 1, text, _countof(text) - 1);
|
||||
if (wcscmp(text, name) == 0)
|
||||
{
|
||||
get_item(i, item);
|
||||
return true;
|
||||
}
|
||||
text[0] = 0;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
void CDlgItemMgr::get_all_items(std::vector<page_config::ITEM>& items)
|
||||
{
|
||||
wchar_t text[128] = { 0 };
|
||||
|
||||
for (size_t i = 0; i < list_.GetItemCount(); ++i)
|
||||
{
|
||||
page_config::ITEM item;
|
||||
get_item(i, &item);
|
||||
items.push_back(item);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CDlgItemMgr::OnDropFiles(HDROP hDropInfo)
|
||||
{
|
||||
// TODO: 在此添加消息处理程序代码和/或调用默认值
|
||||
// TODO: 在此添加消息处理程序代码和/或调用默认值
|
||||
wchar_t path[MAX_PATH] = { 0 };
|
||||
std::wstring cont(L"");
|
||||
std::string bom("");
|
||||
|
||||
DragQueryFileW(hDropInfo, 0, path, _countof(path) - 1);
|
||||
load_from_file(path);
|
||||
|
||||
CDialogEx::OnDropFiles(hDropInfo);
|
||||
}
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
#pragma once
|
||||
|
||||
|
||||
// CDlgItemMgr 对话框
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "page.h"
|
||||
|
||||
class CDlgItemMgr : public CDialogEx
|
||||
{
|
||||
DECLARE_DYNAMIC(CDlgItemMgr)
|
||||
|
||||
public:
|
||||
CDlgItemMgr(CWnd* pParent = nullptr); // 标准构造函数
|
||||
virtual ~CDlgItemMgr();
|
||||
|
||||
// 对话框数据
|
||||
#ifdef AFX_DESIGN_TIME
|
||||
enum { IDD = IDD_TEST_ITEM };
|
||||
#endif
|
||||
|
||||
protected:
|
||||
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持
|
||||
virtual BOOL OnInitDialog();
|
||||
|
||||
std::wstring get_stored_config_file(void);
|
||||
void get_item(int ind, page_config::ITEM* item);
|
||||
void load_from_file(const wchar_t* file);
|
||||
void load_stored_config(void);
|
||||
void item_changed(void);
|
||||
|
||||
DECLARE_MESSAGE_MAP()
|
||||
public:
|
||||
CListCtrl list_;
|
||||
afx_msg void OnNMDblclkList1(NMHDR* pNMHDR, LRESULT* pResult);
|
||||
afx_msg void OnBnClickedButtonAdd();
|
||||
bool get_name(const wchar_t* title, page_config::ITEM* item);
|
||||
bool get_title(const wchar_t* name, page_config::ITEM* item);
|
||||
void get_all_items(std::vector<page_config::ITEM>& items);
|
||||
afx_msg void OnDropFiles(HDROP hDropInfo);
|
||||
};
|
|
@ -0,0 +1,743 @@
|
|||
// CDlgMgr.cpp: 实现文件
|
||||
//
|
||||
|
||||
#include "pch.h"
|
||||
#include "scanner-check.h"
|
||||
#include "CDlgMgr.h"
|
||||
#include "afxdialogex.h"
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
#include <file/file_util.h>
|
||||
#include <coding/coding.h>
|
||||
|
||||
// CDlgMgr 对话框
|
||||
static std::wstring vid_pid_edit_org_proc = L"vid_pid_edit_org_proc";
|
||||
static wchar_t* hex = L"0123456789ABCDEF";
|
||||
|
||||
IMPLEMENT_DYNAMIC(CDlgMgr, CDialogEx)
|
||||
|
||||
CDlgMgr::CDlgMgr(CWnd* pParent /*=nullptr*/)
|
||||
: CDialogEx(IDD_MANAGER, pParent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
CDlgMgr::~CDlgMgr()
|
||||
{
|
||||
}
|
||||
|
||||
static bool is_checked(CWnd* ctrl)
|
||||
{
|
||||
return ((CButton*)ctrl)->GetCheck() == BST_CHECKED;
|
||||
}
|
||||
static bool is_checked(CDialogEx* dlg, UINT id)
|
||||
{
|
||||
return is_checked(dlg->GetDlgItem(id));
|
||||
}
|
||||
static void set_checked(CWnd* ctrl, bool checked)
|
||||
{
|
||||
((CButton*)ctrl)->SetCheck(checked ? BST_CHECKED : BST_UNCHECKED);
|
||||
}
|
||||
static void set_checked(CDialogEx* dlg, UINT id, bool checked)
|
||||
{
|
||||
return set_checked(dlg->GetDlgItem(id), checked);
|
||||
}
|
||||
static LRESULT vid_pid_edit_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
|
||||
{
|
||||
wchar_t now[40] = { 0 };
|
||||
int len = 0, sel = 0, max_len = 4;
|
||||
bool all_digit = true;
|
||||
WNDPROC wndproc = (WNDPROC)GetPropW(hwnd, vid_pid_edit_org_proc.c_str());
|
||||
std::wstring buf(L"");
|
||||
|
||||
if (!wndproc)
|
||||
wndproc = DefWindowProcW;
|
||||
|
||||
switch (msg)
|
||||
{
|
||||
case WM_CHAR:
|
||||
GetWindowTextW(hwnd, now, _countof(now));
|
||||
len = lstrlenW(now);
|
||||
sel = SendMessage(hwnd, EM_GETSEL, 0, 0);
|
||||
sel = ((sel >> 16) & 0x0ff) - (sel & 0x0ffff);
|
||||
if (wp >= ' ' && len - sel >= max_len)
|
||||
return 0;
|
||||
if (wp >= '0' && wp <= '9')
|
||||
wp = hex[wp - '0'];
|
||||
else if (wp >= 'A' && wp <= 'F')
|
||||
wp = hex[wp - 'A' + 10];
|
||||
else if (wp >= 'a' && wp <= 'f')
|
||||
wp = hex[wp - 'a' + 10];
|
||||
else if(wp >= ' ')
|
||||
return 0;
|
||||
break;
|
||||
//case WM_COPY:
|
||||
// return 0;
|
||||
case WM_PASTE:
|
||||
{
|
||||
size_t l = 0;
|
||||
if (file_util::get_clipboard(NULL, &l, CF_UNICODETEXT) == ERROR_INSUFFICIENT_BUFFER)
|
||||
{
|
||||
buf.resize(l + 4);
|
||||
l++;
|
||||
if (file_util::get_clipboard(&buf[0], &l, CF_UNICODETEXT))
|
||||
l = 0;
|
||||
}
|
||||
if (l == 0)
|
||||
return 0;
|
||||
lp = (LPARAM)&buf[0];
|
||||
msg = WM_SETTEXT;
|
||||
}
|
||||
case WM_SETTEXT:
|
||||
for (int i = 0; len < max_len + 1 && i < lstrlenW((wchar_t*)lp); ++i)
|
||||
{
|
||||
wchar_t ch = ((wchar_t*)lp)[i];
|
||||
if (ch >= '0' && ch <= '9')
|
||||
now[len++] = hex[ch - '0'];
|
||||
else if (ch >= 'A' && ch <= 'F')
|
||||
{
|
||||
now[len++] = hex[ch - 'A' + 10];
|
||||
all_digit = false;
|
||||
}
|
||||
else if (ch >= 'a' && ch <= 'f')
|
||||
{
|
||||
now[len++] = hex[ch - 'a' + 10];
|
||||
all_digit = false;
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
if(len == 0)
|
||||
return 0;
|
||||
if (/*len == max_len + 1 &&*/ all_digit)
|
||||
{
|
||||
sel = _wtoi(now);
|
||||
//if (sel <= 0x0ffff)
|
||||
{
|
||||
now[max_len] = 0;
|
||||
for (int l = max_len - 1; l >= 0; --l, sel >>= 4)
|
||||
now[l] = hex[sel % 16];
|
||||
}
|
||||
//else
|
||||
// now[max_len] = 0;
|
||||
}
|
||||
lp = (LPARAM)now;
|
||||
break;
|
||||
}
|
||||
|
||||
return wndproc(hwnd, msg, wp, lp);
|
||||
}
|
||||
static void set_vid_pid_proc(HWND hwnd)
|
||||
{
|
||||
SetPropW(hwnd, vid_pid_edit_org_proc.c_str(), (HANDLE)(FARPROC)GetWindowLong(hwnd, GWL_WNDPROC));
|
||||
SetWindowLong(hwnd, GWL_WNDPROC, (LONG)(FARPROC)vid_pid_edit_proc);
|
||||
}
|
||||
static WORD vid_pid_edit_value(HWND hwnd)
|
||||
{
|
||||
wchar_t text[40] = { 0 };
|
||||
int off = 10;
|
||||
WORD vpid = 0;
|
||||
|
||||
GetWindowTextW(hwnd, text + off, _countof(text) - off - 1);
|
||||
for (int i = 0; text[off + i]; ++i)
|
||||
{
|
||||
const wchar_t* ptr = NULL;
|
||||
|
||||
text[0] = text[off + i];
|
||||
ptr = wcsstr(hex, text);
|
||||
if (!ptr)
|
||||
break;
|
||||
|
||||
vpid <<= 4;
|
||||
vpid += ptr - hex;
|
||||
}
|
||||
|
||||
return vpid;
|
||||
}
|
||||
|
||||
void CDlgMgr::DoDataExchange(CDataExchange* pDX)
|
||||
{
|
||||
CDialogEx::DoDataExchange(pDX);
|
||||
DDX_Control(pDX, IDC_LIST1, list_);
|
||||
DDX_Control(pDX, IDC_COMBO_ITEM, combo_);
|
||||
DDX_Control(pDX, IDC_IPADDRESS1, ip_);
|
||||
}
|
||||
|
||||
|
||||
BEGIN_MESSAGE_MAP(CDlgMgr, CDialogEx)
|
||||
ON_BN_CLICKED(IDC_CHECK2, &CDlgMgr::OnBnClickedCheckReport)
|
||||
ON_MESSAGE(WM_USER + 1, &CDlgMgr::OnDisableIPCtrl)
|
||||
ON_BN_CLICKED(IDC_BUTTON_MAINTAIN, &CDlgMgr::OnBnClickedButtonMaintain)
|
||||
ON_BN_CLICKED(IDC_BUTTON_ADD, &CDlgMgr::OnBnClickedButtonAdd)
|
||||
ON_CBN_SELCHANGE(IDC_COMBO_ITEM, &CDlgMgr::OnCbnSelchangeComboItem)
|
||||
ON_NOTIFY(NM_DBLCLK, IDC_LIST1, &CDlgMgr::OnNMDblclkList1)
|
||||
ON_BN_CLICKED(IDC_BUTTON_ADD_ALL, &CDlgMgr::OnBnClickedButtonAddAll)
|
||||
ON_WM_DROPFILES()
|
||||
// ON_WM_GETDLGCODE()
|
||||
ON_COMMAND(ID_LIST_PASTE_CLIPBOARD, &CDlgMgr::OnListPasteClipboard)
|
||||
ON_NOTIFY(NM_RCLICK, IDC_LIST1, &CDlgMgr::OnNMRClickList1)
|
||||
ON_COMMAND(ID_LIST_CLEAR, &CDlgMgr::OnListClear)
|
||||
END_MESSAGE_MAP()
|
||||
|
||||
static DWORD WINAPI disable_ip_ctrl(LPVOID lp)
|
||||
{
|
||||
Sleep(500);
|
||||
PostMessage((HWND)lp, WM_USER + 1, 0, 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
LRESULT CDlgMgr::OnDisableIPCtrl(WPARAM, LPARAM)
|
||||
{
|
||||
OnBnClickedCheckReport();
|
||||
|
||||
return 0;
|
||||
}
|
||||
// CDlgMgr 消息处理程序
|
||||
BOOL CDlgMgr::OnInitDialog()
|
||||
{
|
||||
CDialogEx::OnInitDialog();
|
||||
|
||||
int ind = list_.InsertColumn(list_.GetHeaderCtrl()->GetItemCount(), TEXT("\u5E8F\u53F7"), 0, 40);
|
||||
list_.InsertColumn(list_.GetHeaderCtrl()->GetItemCount(), TEXT("\u6D4B\u8BD5\u9879\u76EE"), 0, 171);
|
||||
list_.InsertColumn(list_.GetHeaderCtrl()->GetItemCount(), TEXT("\u5FC5\u987B\u8054\u673A\u6D4B\u8BD5"), 0, 86);
|
||||
list_.InsertColumn(list_.GetHeaderCtrl()->GetItemCount(), TEXT("\u4E0D\u901A\u8FC7\u5219\u505C\u6B62"), 0, 86);
|
||||
list_.SetExtendedStyle((list_.GetExStyle() | LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES) & (~LVS_EX_CHECKBOXES));
|
||||
list_.ModifyStyle(0, LVS_SINGLESEL);
|
||||
|
||||
set_checked(this, IDC_CHECK_ONLINE, true);
|
||||
set_checked(this, IDC_CHECK_FATAL, true);
|
||||
|
||||
combo_.AddString(L"船形开关");
|
||||
combo_.AddString(L"外观");
|
||||
combo_.AddString(L"显示屏");
|
||||
combo_.AddString(L"歪斜");
|
||||
combo_.AddString(L"超声波");
|
||||
|
||||
set_vid_pid_proc(GetDlgItem(IDC_EDIT_VID_SRC)->m_hWnd);
|
||||
set_vid_pid_proc(GetDlgItem(IDC_EDIT_PID_SRC)->m_hWnd);
|
||||
set_vid_pid_proc(GetDlgItem(IDC_EDIT_VID_TO)->m_hWnd);
|
||||
set_vid_pid_proc(GetDlgItem(IDC_EDIT_PID_TO)->m_hWnd);
|
||||
|
||||
SetDlgItemInt(IDC_EDIT_VID_SRC, 0x3072);
|
||||
SetDlgItemInt(IDC_EDIT_PID_SRC, 0x200);
|
||||
SetDlgItemInt(IDC_EDIT_VID_TO, 0x3072);
|
||||
SetDlgItemInt(IDC_EDIT_PID_TO, 0x0239);
|
||||
|
||||
return TRUE; // 除非将焦点设置到控件,否则返回 TRUE
|
||||
}
|
||||
|
||||
|
||||
void CDlgMgr::OnBnClickedCheckReport()
|
||||
{
|
||||
// TODO: 在此添加控件通知处理程序代码
|
||||
bool enable = is_checked(this, IDC_CHECK2);
|
||||
|
||||
GetDlgItem(IDC_IPADDRESS1)->EnableWindow(enable);
|
||||
GetDlgItem(IDC_IPADDRESS1)->ShowWindow(SW_SHOW);
|
||||
GetDlgItem(IDC_EDIT_IP)->ShowWindow(SW_HIDE);
|
||||
GetDlgItem(IDC_EDIT_PORT)->EnableWindow(enable);
|
||||
GetDlgItem(IDC_EDIT_DB)->EnableWindow(enable);
|
||||
if (enable)
|
||||
GotoDlgCtrl(GetDlgItem(IDC_IPADDRESS1));
|
||||
}
|
||||
|
||||
|
||||
void CDlgMgr::OnBnClickedButtonMaintain()
|
||||
{
|
||||
// TODO: 在此添加控件通知处理程序代码
|
||||
::PostMessage(GetParent()->m_hWnd, WM_TO_ITEM_MGR_TAB, 0, 0);
|
||||
}
|
||||
|
||||
|
||||
void CDlgMgr::OnBnClickedButtonAdd()
|
||||
{
|
||||
// TODO: 在此添加控件通知处理程序代码
|
||||
wchar_t text[128] = { 0 };
|
||||
bool online = is_checked(this, IDC_CHECK_ONLINE), fatal = is_checked(this, IDC_CHECK_FATAL);
|
||||
int ind = -1;
|
||||
|
||||
if (::GetWindowTextW(GetDlgItem(IDC_COMBO_ITEM)->m_hWnd, text, _countof(text) - 1) == 0)
|
||||
return;
|
||||
|
||||
for (int i = 0; i < list_.GetItemCount(); ++i)
|
||||
{
|
||||
wchar_t val[128] = { 0 };
|
||||
list_.GetItemText(i, 1, val, _countof(val) - 1);
|
||||
if (wcscmp(text, val) == 0)
|
||||
{
|
||||
ind = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (ind == -1)
|
||||
{
|
||||
wchar_t sn[20] = { 0 };
|
||||
swprintf_s(sn, _countof(sn) - 1, L"%u", list_.GetItemCount() + 1);
|
||||
ind = list_.InsertItem(list_.GetItemCount(), sn);
|
||||
list_.SetItemText(ind, 1, text);
|
||||
}
|
||||
|
||||
list_.SetItemText(ind, 2, online ? L"true" : L"false");
|
||||
list_.SetItemText(ind, 3, fatal ? L"true" : L"false");
|
||||
list_.SetItemState(ind, LVNI_FOCUSED | LVIS_SELECTED, LVNI_FOCUSED | LVIS_SELECTED);
|
||||
list_.EnsureVisible(ind, FALSE);
|
||||
}
|
||||
|
||||
|
||||
void CDlgMgr::OnCbnSelchangeComboItem()
|
||||
{
|
||||
// TODO: 在此添加控件通知处理程序代码
|
||||
wchar_t text[128] = { 0 }, val[128] = { 0 };
|
||||
page_config::ITEM item;
|
||||
|
||||
::GetWindowTextW(GetDlgItem(IDC_COMBO_ITEM)->m_hWnd, text, _countof(text) - 1);
|
||||
for (int i = 0; i < list_.GetItemCount(); ++i)
|
||||
{
|
||||
list_.GetItemText(i, 1, val, _countof(val) - 1);
|
||||
if (wcscmp(text, val) == 0)
|
||||
{
|
||||
list_.SetItemState(i, LVNI_FOCUSED | LVIS_SELECTED, LVNI_FOCUSED | LVIS_SELECTED);
|
||||
list_.GetItemText(i, 2, val, _countof(val) - 1);
|
||||
set_checked(this, IDC_CHECK_ONLINE, wcscmp(val, L"true") == 0);
|
||||
list_.GetItemText(i, 3, val, _countof(val) - 1);
|
||||
set_checked(this, IDC_CHECK_FATAL, wcscmp(val, L"true") == 0);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
::SendMessageW(GetParent()->m_hWnd, WM_GET_TEST_ITEM_NAME, (WPARAM)text, (LPARAM)&item);
|
||||
if (item.title == text)
|
||||
{
|
||||
set_checked(this, IDC_CHECK_ONLINE, !item.man);
|
||||
set_checked(this, IDC_CHECK_FATAL, item.fatal);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CDlgMgr::OnNMDblclkList1(NMHDR* pNMHDR, LRESULT* pResult)
|
||||
{
|
||||
LPNMITEMACTIVATE pNMItemActivate = reinterpret_cast<LPNMITEMACTIVATE>(pNMHDR);
|
||||
// TODO: 在此添加控件通知处理程序代码
|
||||
POINT pos = { 0 };
|
||||
RECT r = { 0 };
|
||||
|
||||
GetCursorPos(&pos);
|
||||
list_.ScreenToClient(&pos);
|
||||
r.left = list_.HitTest(pos);
|
||||
if (r.left != -1)
|
||||
{
|
||||
std::vector<int> width;
|
||||
int ind = r.left;
|
||||
|
||||
for (int i = 0; i < list_.GetHeaderCtrl()->GetItemCount(); ++i)
|
||||
{
|
||||
RECT r = { 0 };
|
||||
list_.GetHeaderCtrl()->GetItemRect(i, &r);
|
||||
width.push_back(r.right - r.left);
|
||||
}
|
||||
for (int i = 0; i < width.size(); ++i)
|
||||
{
|
||||
if (pos.x <= width[i])
|
||||
{
|
||||
wchar_t text[128] = { 0 };
|
||||
if (i < 2)
|
||||
{
|
||||
std::wstring tips(L"\u5220\u9664\u6D4B\u8BD5\u9879\uFF1A");
|
||||
|
||||
list_.GetItemText(ind, 1, text, _countof(text) - 1);
|
||||
tips += text;
|
||||
tips += L"\uFF1F";
|
||||
if (::MessageBoxW(m_hWnd,tips.c_str(), L"\u786E\u8BA4", MB_YESNO | MB_ICONQUESTION) == IDYES)
|
||||
{
|
||||
list_.DeleteItem(ind);
|
||||
for (; ind < list_.GetItemCount(); ++ind)
|
||||
{
|
||||
swprintf_s(text, _countof(text) - 1, L"%u", ind + 1);
|
||||
list_.SetItemText(ind, 0, text);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
list_.GetItemText(ind, i, text, _countof(text) - 1);
|
||||
if (wcscmp(text, L"true"))
|
||||
list_.SetItemText(ind, i, L"true");
|
||||
else
|
||||
list_.SetItemText(ind, i, L"false");
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
pos.x -= width[i];
|
||||
}
|
||||
}
|
||||
|
||||
*pResult = 0;
|
||||
}
|
||||
|
||||
|
||||
void CDlgMgr::OnBnClickedButtonAddAll()
|
||||
{
|
||||
// TODO: 在此添加控件通知处理程序代码
|
||||
for (int i = 0; i < combo_.GetCount(); ++i)
|
||||
{
|
||||
combo_.SetCurSel(i);
|
||||
OnCbnSelchangeComboItem();
|
||||
OnBnClickedButtonAdd();
|
||||
}
|
||||
}
|
||||
|
||||
void CDlgMgr::init_test_items(std::vector<page_config::ITEM>& items)
|
||||
{
|
||||
combo_.ResetContent();
|
||||
for (size_t i = 0; i < items.size(); ++i)
|
||||
combo_.AddString(items[i].title.c_str());
|
||||
|
||||
if (items.size())
|
||||
{
|
||||
combo_.SetCurSel(0);
|
||||
OnCbnSelchangeComboItem();
|
||||
}
|
||||
}
|
||||
|
||||
INTER_MODULE_CALLBACK(got_wstr)
|
||||
{
|
||||
*((std::wstring*)param) += std::wstring((const wchar_t*)data, len / 2);
|
||||
|
||||
return inter_module_data::SET_RESULT_CONTINUE;
|
||||
}
|
||||
std::wstring CDlgMgr::export_config(bool *ok, bool used_in_code, int code_ver)
|
||||
{
|
||||
known_file_util::IJsonW * jsn = known_file_util::create_jsonW(),
|
||||
* child = known_file_util::create_jsonW();
|
||||
wchar_t text[256] = { 0 };
|
||||
bool result = false;
|
||||
|
||||
if (!ok)
|
||||
ok = &result;
|
||||
|
||||
*ok = false;
|
||||
if (!used_in_code)
|
||||
{
|
||||
WORD vid_f = vid_pid_edit_value(GetDlgItem(IDC_EDIT_VID_SRC)->m_hWnd),
|
||||
pid_f = vid_pid_edit_value(GetDlgItem(IDC_EDIT_PID_SRC)->m_hWnd),
|
||||
vid_t = vid_pid_edit_value(GetDlgItem(IDC_EDIT_VID_TO)->m_hWnd),
|
||||
pid_t = vid_pid_edit_value(GetDlgItem(IDC_EDIT_PID_TO)->m_hWnd),
|
||||
port = 0;
|
||||
bool report = is_checked(GetDlgItem(IDC_CHECK2));
|
||||
BYTE ip1 = 0, ip2 = 0, ip3 = 0, ip4 = 0;
|
||||
|
||||
if (!vid_f)
|
||||
{
|
||||
GotoDlgCtrl(GetDlgItem(IDC_EDIT_VID_SRC));
|
||||
jsn->release();
|
||||
|
||||
return L"\u8BF7\u91CD\u65B0\u8F93\u5165 \u6E90\uFF36\uFF29\uFF24\uFF01";
|
||||
}
|
||||
if (!pid_f)
|
||||
{
|
||||
GotoDlgCtrl(GetDlgItem(IDC_EDIT_PID_SRC));
|
||||
jsn->release();
|
||||
|
||||
return L"\u8BF7\u91CD\u65B0\u8F93\u5165 \u6E90\uFF30\uFF29\uFF24\uFF01";
|
||||
}
|
||||
if (!vid_t)
|
||||
{
|
||||
GotoDlgCtrl(GetDlgItem(IDC_EDIT_VID_TO));
|
||||
jsn->release();
|
||||
|
||||
return L"\u8BF7\u91CD\u65B0\u8F93\u5165 \u76EE\u6807\uFF36\uFF29\uFF24\uFF01";
|
||||
}
|
||||
if (!pid_t)
|
||||
{
|
||||
GotoDlgCtrl(GetDlgItem(IDC_EDIT_PID_TO));
|
||||
jsn->release();
|
||||
|
||||
return L"\u8BF7\u91CD\u65B0\u8F93\u5165 \u76EE\u6807\uFF30\uFF29\uFF24\uFF01";
|
||||
}
|
||||
|
||||
if (report)
|
||||
{
|
||||
ip_.GetAddress(ip1, ip2, ip3, ip4);
|
||||
port = GetDlgItemInt(IDC_EDIT_PORT);
|
||||
::GetDlgItemTextW(m_hWnd, IDC_EDIT_DB, text, _countof(text) - 1);
|
||||
}
|
||||
|
||||
child->set_value(L"vid-org", vid_f);
|
||||
child->set_value(L"pid-org", pid_f);
|
||||
child->set_value(L"vid-to", vid_t);
|
||||
child->set_value(L"pid-to", pid_t);
|
||||
if (report)
|
||||
{
|
||||
::GetDlgItemTextW(m_hWnd, IDC_EDIT_DB, text, _countof(text) - 1);
|
||||
std::wstring url(text);
|
||||
|
||||
swprintf_s(text, _countof(text) - 1, L"%u:", port);
|
||||
url.insert(0, text);
|
||||
swprintf_s(text, _countof(text) - 1, L"%u.%u.%u.%u:", ip1, ip2, ip3, ip4);
|
||||
url.insert(0, text);
|
||||
child->set_value(L"report-url", url.c_str());
|
||||
}
|
||||
jsn->set_value(L"global", child);
|
||||
}
|
||||
child->release();
|
||||
|
||||
if (list_.GetItemCount() == 0)
|
||||
{
|
||||
jsn->release();
|
||||
return L"\u6CA1\u6709\u8F93\u5165\u6709\u6548\u7684\u6D4B\u8BD5\u9879\u76EE\uFF01";
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < list_.GetItemCount(); ++i)
|
||||
{
|
||||
page_config::ITEM item;
|
||||
child = known_file_util::create_jsonW();
|
||||
list_.GetItemText(i, 1, text, _countof(text) - 1);
|
||||
::SendMessageW(GetParent()->m_hWnd, WM_GET_TEST_ITEM_NAME, (WPARAM)text, (LPARAM)&item);
|
||||
if (item.name.empty())
|
||||
{
|
||||
child->release();
|
||||
jsn->release();
|
||||
|
||||
return L"\u6D4B\u8BD5\u9879\u76EE \u201C" + std::wstring(text) + L"\u201D \u4E0D\u5B58\u5728\u4E8E\u914D\u7F6E\u5E93\u4E2D\u3002";
|
||||
}
|
||||
child->set_value(L"name", item.name.c_str());
|
||||
if (!used_in_code)
|
||||
{
|
||||
child->set_value(L"title", text);
|
||||
list_.GetItemText(i, 2, text, _countof(text) - 1);
|
||||
child->set_value(L"man", wcscmp(text, L"false") == 0);
|
||||
list_.GetItemText(i, 3, text, _countof(text) - 1);
|
||||
child->set_value(L"err-level", wcscmp(text, L"true") == 0 ? L"fatal" : L"warning");
|
||||
}
|
||||
else
|
||||
{
|
||||
child->set_value(L"ver", code_ver);
|
||||
}
|
||||
|
||||
swprintf_s(text, _countof(text) - 1, L"%u", i + 1);
|
||||
jsn->set_value(text, child);
|
||||
child->release();
|
||||
}
|
||||
|
||||
std::wstring ret(L"");
|
||||
|
||||
jsn->to_string(got_wstr, &ret);
|
||||
jsn->release();
|
||||
if (used_in_code)
|
||||
{
|
||||
size_t pos = ret.find(L"\"");
|
||||
|
||||
while (pos != std::string::npos)
|
||||
{
|
||||
ret.insert(pos, L"\\");
|
||||
pos = ret.find(L"\"", pos + 2);
|
||||
}
|
||||
|
||||
pos = ret.find(L"\\u");
|
||||
while (pos != std::string::npos)
|
||||
{
|
||||
ret.insert(pos, L"\\");
|
||||
pos = ret.find(L"\\u", pos + 3);
|
||||
}
|
||||
|
||||
// divide into multi-lines with 16KB per line ...
|
||||
int lines = 1;
|
||||
wchar_t var[80] = { 0 };
|
||||
|
||||
pos = ret.length();
|
||||
while (pos > 16 * 1024)
|
||||
{
|
||||
pos -= 12 * 1024;
|
||||
while (ret[pos - 1] == L'\\')
|
||||
pos++;
|
||||
lines++;
|
||||
swprintf_s(var, _countof(var) - 1, L"\");\r\nstatic std::wstring jsontext%d(L\"", lines);
|
||||
ret.insert(pos, var);
|
||||
}
|
||||
ret.insert(0, L"static std::string jsontext1(\"");
|
||||
ret += L"\");\r\n";
|
||||
}
|
||||
|
||||
*ok = true;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void trans_code_json(std::wstring& json)
|
||||
{
|
||||
size_t pos = json.find(L"(L\"");
|
||||
|
||||
if (pos == std::wstring::npos)
|
||||
return;
|
||||
|
||||
json.erase(0, pos + 3);
|
||||
pos = json.rfind(L'\"');
|
||||
if (pos != std::wstring::npos)
|
||||
json.erase(pos);
|
||||
|
||||
pos = 0;
|
||||
while ((pos = json.find(L"\\\""), pos) != std::wstring::npos)
|
||||
{
|
||||
json.erase(pos++, 1);
|
||||
}
|
||||
|
||||
pos = 0;
|
||||
while ((pos = json.find(L"\\"), pos) != std::wstring::npos)
|
||||
{
|
||||
json.erase(pos++, 1);
|
||||
}
|
||||
}
|
||||
void CDlgMgr::reload(std::wstring& cont)
|
||||
{
|
||||
if (cont.find(L"static std::wstring") == 0)
|
||||
trans_code_json(cont);
|
||||
|
||||
known_file_util::IJsonW* jsn = known_file_util::create_jsonW();
|
||||
if (jsn->attach(cont.c_str()))
|
||||
{
|
||||
known_file_util::IJsonW* child = NULL;
|
||||
const wchar_t* val = NULL;
|
||||
|
||||
cont = L"";
|
||||
jsn->get_value(L"global", &child);
|
||||
if (child)
|
||||
{
|
||||
int n = 0;
|
||||
child->get_value(L"vid-org", n);
|
||||
SetDlgItemInt(IDC_EDIT_VID_SRC, n);
|
||||
child->get_value(L"pid-org", n);
|
||||
SetDlgItemInt(IDC_EDIT_PID_SRC, n);
|
||||
child->get_value(L"vid-to", n);
|
||||
SetDlgItemInt(IDC_EDIT_VID_TO, n);
|
||||
child->get_value(L"pid-to", n);
|
||||
SetDlgItemInt(IDC_EDIT_PID_TO, n);
|
||||
if (child->get_value(L"report-url", &val) && val)
|
||||
{
|
||||
size_t pos = 0;
|
||||
|
||||
cont = val;
|
||||
pos = cont.find(L":");
|
||||
if (pos++ != std::wstring::npos)
|
||||
{
|
||||
ip_.SetWindowTextW(cont.substr(0, pos).c_str());
|
||||
cont.erase(0, pos);
|
||||
SetDlgItemInt(IDC_EDIT_PORT, _wtoi(cont.c_str()));
|
||||
pos = cont.find(L":");
|
||||
if (pos++ != std::wstring::npos)
|
||||
cont.erase(0, pos);
|
||||
}
|
||||
::SetDlgItemTextW(m_hWnd, IDC_EDIT_DB, cont.c_str());
|
||||
set_checked(this, IDC_CHECK2, true);
|
||||
OnBnClickedCheckReport();
|
||||
}
|
||||
child->release();
|
||||
}
|
||||
|
||||
list_.DeleteAllItems();
|
||||
for (int i = 1; 1; ++i)
|
||||
{
|
||||
wchar_t sn[20] = { 0 };
|
||||
swprintf_s(sn, _countof(sn) - 1, L"%d", i);
|
||||
if (!jsn->get_value(sn, &child))
|
||||
break;
|
||||
|
||||
if (child->get_value(L"title", &val))
|
||||
{
|
||||
int ind = list_.InsertItem(list_.GetItemCount(), sn);
|
||||
list_.SetItemText(ind, 1, val);
|
||||
|
||||
if (child->get_value(L"err-level", &val))
|
||||
list_.SetItemText(ind, 3, wcscmp(val, L"fatal") == 0 ? L"true" : L"false");
|
||||
|
||||
bool man = false;
|
||||
child->get_value(L"man", man);
|
||||
list_.SetItemText(ind, 2, !man ? L"true" : L"false");
|
||||
}
|
||||
else if (child->get_value(L"name", &val))
|
||||
{
|
||||
page_config::ITEM item;
|
||||
::SendMessageW(GetParent()->m_hWnd, WM_GET_TEST_ITEM_TITLE, (WPARAM)val, (LPARAM)&item);
|
||||
int ind = list_.InsertItem(list_.GetItemCount(), sn);
|
||||
|
||||
list_.SetItemText(ind, 1, item.title.c_str());
|
||||
list_.SetItemText(ind, 2, !item.man ? L"true" : L"false");
|
||||
list_.SetItemText(ind, 3, item.fatal ? L"true" : L"false");
|
||||
|
||||
child->get_value(L"ver", ind);
|
||||
SetDlgItemInt(IDC_EDIT_VER, ind);
|
||||
}
|
||||
child->release();
|
||||
}
|
||||
}
|
||||
jsn->release();
|
||||
}
|
||||
void CDlgMgr::OnDropFiles(HDROP hDropInfo)
|
||||
{
|
||||
// TODO: 在此添加消息处理程序代码和/或调用默认值
|
||||
wchar_t path[MAX_PATH] = { 0 };
|
||||
std::wstring cont(L"");
|
||||
std::string bom("");
|
||||
|
||||
DragQueryFileW(hDropInfo, 0, path, _countof(path) - 1);
|
||||
file_util::load_file(path, got_str, &bom);
|
||||
coding_util::bom::to_unicode(bom.c_str(), bom.length(), got_wstr, &cont);
|
||||
|
||||
reload(cont);
|
||||
|
||||
__super::OnDropFiles(hDropInfo);
|
||||
}
|
||||
|
||||
|
||||
//UINT CDlgMgr::OnGetDlgCode()
|
||||
//{
|
||||
// // TODO: 在此添加消息处理程序代码和/或调用默认值
|
||||
//
|
||||
// return __super::OnGetDlgCode();
|
||||
//}
|
||||
|
||||
|
||||
void CDlgMgr::OnListPasteClipboard()
|
||||
{
|
||||
// TODO: 在此添加命令处理程序代码
|
||||
wchar_t* buf = NULL;
|
||||
size_t len = 0;
|
||||
|
||||
if (file_util::get_clipboard(buf, &len, CF_UNICODETEXT) == ERROR_INSUFFICIENT_BUFFER)
|
||||
{
|
||||
buf = new wchar_t[len + 8];
|
||||
memset(buf, 0, (len + 8) * 2);
|
||||
len++;
|
||||
if (file_util::get_clipboard(buf, &len, CF_UNICODETEXT) == ERROR_SUCCESS)
|
||||
{
|
||||
std::wstring cont(buf);
|
||||
reload(cont);
|
||||
}
|
||||
delete[] buf;
|
||||
}
|
||||
}
|
||||
|
||||
void CDlgMgr::OnNMRClickList1(NMHDR* pNMHDR, LRESULT* pResult)
|
||||
{
|
||||
LPNMITEMACTIVATE pNMItemActivate = reinterpret_cast<LPNMITEMACTIVATE>(pNMHDR);
|
||||
// TODO: 在此添加控件通知处理程序代码
|
||||
*pResult = 0;
|
||||
POINT pt = { 0 };
|
||||
CMenu menu;
|
||||
|
||||
menu.LoadMenuW(MAKEINTRESOURCE(IDR_MENU1));
|
||||
GetCursorPos(&pt);
|
||||
menu.GetSubMenu(0)->TrackPopupMenu(0, pt.x, pt.y, this);
|
||||
}
|
||||
|
||||
|
||||
void CDlgMgr::OnListClear()
|
||||
{
|
||||
// TODO: 在此添加命令处理程序代码
|
||||
list_.DeleteAllItems();
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
#pragma once
|
||||
|
||||
#include "page.h"
|
||||
|
||||
// CDlgMgr 对话框
|
||||
class CDlgMgr : public CDialogEx, public page_config
|
||||
{
|
||||
DECLARE_DYNAMIC(CDlgMgr)
|
||||
|
||||
public:
|
||||
CDlgMgr(CWnd* pParent = nullptr); // 标准构造函数
|
||||
virtual ~CDlgMgr();
|
||||
|
||||
// 对话框数据
|
||||
#ifdef AFX_DESIGN_TIME
|
||||
enum { IDD = IDD_MANAGER };
|
||||
#endif
|
||||
|
||||
protected:
|
||||
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持
|
||||
virtual BOOL OnInitDialog();
|
||||
void reload(std::wstring& cont);
|
||||
|
||||
DECLARE_MESSAGE_MAP()
|
||||
public:
|
||||
CListCtrl list_;
|
||||
afx_msg void OnBnClickedCheckReport();
|
||||
afx_msg LRESULT OnDisableIPCtrl(WPARAM, LPARAM);
|
||||
afx_msg void OnBnClickedButtonMaintain();
|
||||
afx_msg void OnBnClickedButtonAdd();
|
||||
afx_msg void OnCbnSelchangeComboItem();
|
||||
afx_msg void OnNMDblclkList1(NMHDR* pNMHDR, LRESULT* pResult);
|
||||
CComboBox combo_;
|
||||
afx_msg void OnBnClickedButtonAddAll();
|
||||
|
||||
void init_test_items(std::vector<page_config::ITEM>& items);
|
||||
|
||||
public:
|
||||
virtual std::wstring export_config(bool* ok, bool used_in_code = false, int code_ver = 1) override;
|
||||
CIPAddressCtrl ip_;
|
||||
afx_msg void OnDropFiles(HDROP hDropInfo);
|
||||
// afx_msg UINT OnGetDlgCode();
|
||||
afx_msg void OnListPasteClipboard();
|
||||
afx_msg void OnNMRClickList1(NMHDR* pNMHDR, LRESULT* pResult);
|
||||
afx_msg void OnListClear();
|
||||
};
|
|
@ -0,0 +1,49 @@
|
|||
#pragma once
|
||||
|
||||
#ifndef VC_EXTRALEAN
|
||||
#define VC_EXTRALEAN // 从 Windows 头中排除极少使用的资料
|
||||
#endif
|
||||
|
||||
#include "targetver.h"
|
||||
|
||||
#define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS // 某些 CString 构造函数将是显式的
|
||||
|
||||
// 关闭 MFC 的一些常见且经常可放心忽略的隐藏警告消息
|
||||
#define _AFX_ALL_WARNINGS
|
||||
|
||||
#include <afxwin.h> // MFC 核心组件和标准组件
|
||||
#include <afxext.h> // MFC 扩展
|
||||
|
||||
|
||||
#include <afxdisp.h> // MFC 自动化类
|
||||
|
||||
|
||||
|
||||
#ifndef _AFX_NO_OLE_SUPPORT
|
||||
#include <afxdtctl.h> // MFC 对 Internet Explorer 4 公共控件的支持
|
||||
#endif
|
||||
#ifndef _AFX_NO_AFXCMN_SUPPORT
|
||||
#include <afxcmn.h> // MFC 对 Windows 公共控件的支持
|
||||
#endif // _AFX_NO_AFXCMN_SUPPORT
|
||||
|
||||
#include <afxcontrolbars.h> // MFC 支持功能区和控制条
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#ifdef _UNICODE
|
||||
#if defined _M_IX86
|
||||
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"")
|
||||
#elif defined _M_X64
|
||||
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\"")
|
||||
#else
|
||||
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
//
|
||||
#pragma once
|
||||
#include <string>
|
||||
#include <utility/known_file.h>
|
||||
#pragma comment(lib, "base_util.lib")
|
||||
|
||||
#define WM_GET_TEST_ITEM_NAME WM_USER + 100 // WPARAM: (wchar_t*)title, LPARAM: (ITEM*)item
|
||||
#define WM_GET_TEST_ITEM_TITLE WM_USER + 101 // WPARAM: (wchar_t*)name, LPARAM: (ITEM*)item
|
||||
#define WM_TO_ITEM_MGR_TAB WM_USER + 102
|
||||
#define WM_TEST_ITEM_CHANGED WM_USER + 103
|
||||
|
||||
#include <string>
|
||||
#include <algorithm>
|
||||
|
||||
class page_config
|
||||
{
|
||||
public:
|
||||
page_config()
|
||||
{}
|
||||
virtual ~page_config()
|
||||
{}
|
||||
|
||||
typedef struct _item
|
||||
{
|
||||
std::wstring name;
|
||||
std::wstring title;
|
||||
bool man;
|
||||
bool fatal;
|
||||
|
||||
bool operator==(const wchar_t* t)
|
||||
{
|
||||
return title == t;
|
||||
}
|
||||
}ITEM;
|
||||
|
||||
public:
|
||||
virtual std::wstring export_config(bool *ok/*return error message if this returned false*/, bool used_in_code = false, int code_ver = 1) = 0;
|
||||
};
|
||||
|
||||
extern INTER_MODULE_CALLBACK(got_wstr);
|
||||
extern INTER_MODULE_CALLBACK(got_str);
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
// pch.cpp: 与预编译标头对应的源文件
|
||||
|
||||
#include "pch.h"
|
||||
|
||||
// 当使用预编译的头时,需要使用此源文件,编译才能成功。
|
|
@ -0,0 +1,13 @@
|
|||
// pch.h: 这是预编译标头文件。
|
||||
// 下方列出的文件仅编译一次,提高了将来生成的生成性能。
|
||||
// 这还将影响 IntelliSense 性能,包括代码完成和许多代码浏览功能。
|
||||
// 但是,如果此处列出的文件中的任何一个在生成之间有更新,它们全部都将被重新编译。
|
||||
// 请勿在此处添加要频繁更新的文件,这将使得性能优势无效。
|
||||
|
||||
#ifndef PCH_H
|
||||
#define PCH_H
|
||||
|
||||
// 添加要在此处预编译的标头
|
||||
#include "framework.h"
|
||||
|
||||
#endif //PCH_H
|
Binary file not shown.
After Width: | Height: | Size: 154 KiB |
Binary file not shown.
|
@ -0,0 +1,50 @@
|
|||
//{{NO_DEPENDENCIES}}
|
||||
// Microsoft Visual C++ 生成的包含文件。
|
||||
// 供 scannercheck.rc 使用
|
||||
//
|
||||
#define IDM_ABOUTBOX 0x0010
|
||||
#define IDS_ABOUTBOX 101
|
||||
#define IDD_SCANNERCHECK_DIALOG 102
|
||||
#define IDR_MAINFRAME 128
|
||||
#define IDD_MANAGER 130
|
||||
#define IDD_TEST_ITEM 131
|
||||
#define IDR_MENU1 133
|
||||
#define IDC_TAB1 1000
|
||||
#define IDC_STATIC_RECT 1001
|
||||
#define IDC_EDIT_VID_SRC 1002
|
||||
#define IDC_EDIT_PID_SRC 1003
|
||||
#define IDC_EDIT_VID_TO 1004
|
||||
#define IDC_EDIT_PID_TO 1005
|
||||
#define IDC_EDIT_PORT 1006
|
||||
#define IDC_CHECK2 1007
|
||||
#define IDC_IPADDRESS1 1008
|
||||
#define IDC_EDIT_DB 1009
|
||||
#define IDC_LIST1 1010
|
||||
#define IDC_COMBO_ITEM 1011
|
||||
#define IDC_CHECK_ONLINE 1012
|
||||
#define IDC_CHECK_FATAL 1013
|
||||
#define IDC_BUTTON_ADD 1014
|
||||
#define IDC_EDIT_IP 1015
|
||||
#define IDC_BUTTON_EXPORT 1015
|
||||
#define IDC_BUTTON_MAINTAIN 1016
|
||||
#define IDC_COMBO1 1016
|
||||
#define IDC_BUTTON_ADD_ALL 1017
|
||||
#define IDC_STATIC_VER 1017
|
||||
#define IDC_EDIT_VER 1018
|
||||
#define IDC_EDIT_NAME 1019
|
||||
#define IDC_EDIT_TITLE 1020
|
||||
#define ID_LIST_32771 32771
|
||||
#define ID_LIST_PASTE_CLIPBOARD 32772
|
||||
#define ID_LIST_32773 32773
|
||||
#define ID_LIST_CLEAR 32774
|
||||
|
||||
// Next default values for new objects
|
||||
//
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
#ifndef APSTUDIO_READONLY_SYMBOLS
|
||||
#define _APS_NEXT_RESOURCE_VALUE 134
|
||||
#define _APS_NEXT_COMMAND_VALUE 32775
|
||||
#define _APS_NEXT_CONTROL_VALUE 1020
|
||||
#define _APS_NEXT_SYMED_VALUE 101
|
||||
#endif
|
||||
#endif
|
|
@ -0,0 +1,107 @@
|
|||
|
||||
// scanner-check.cpp: 定义应用程序的类行为。
|
||||
//
|
||||
|
||||
#include "pch.h"
|
||||
#include "framework.h"
|
||||
#include "scanner-check.h"
|
||||
#include "scanner-checkDlg.h"
|
||||
|
||||
#ifdef _DEBUG
|
||||
#define new DEBUG_NEW
|
||||
#endif
|
||||
|
||||
|
||||
// CscannercheckApp
|
||||
|
||||
BEGIN_MESSAGE_MAP(CscannercheckApp, CWinApp)
|
||||
ON_COMMAND(ID_HELP, &CWinApp::OnHelp)
|
||||
END_MESSAGE_MAP()
|
||||
|
||||
|
||||
// CscannercheckApp 构造
|
||||
|
||||
CscannercheckApp::CscannercheckApp()
|
||||
{
|
||||
// 支持重新启动管理器
|
||||
m_dwRestartManagerSupportFlags = AFX_RESTART_MANAGER_SUPPORT_RESTART;
|
||||
|
||||
// TODO: 在此处添加构造代码,
|
||||
// 将所有重要的初始化放置在 InitInstance 中
|
||||
}
|
||||
|
||||
|
||||
// 唯一的 CscannercheckApp 对象
|
||||
|
||||
CscannercheckApp theApp;
|
||||
|
||||
|
||||
// CscannercheckApp 初始化
|
||||
|
||||
BOOL CscannercheckApp::InitInstance()
|
||||
{
|
||||
// 如果一个运行在 Windows XP 上的应用程序清单指定要
|
||||
// 使用 ComCtl32.dll 版本 6 或更高版本来启用可视化方式,
|
||||
//则需要 InitCommonControlsEx()。 否则,将无法创建窗口。
|
||||
INITCOMMONCONTROLSEX InitCtrls;
|
||||
InitCtrls.dwSize = sizeof(InitCtrls);
|
||||
// 将它设置为包括所有要在应用程序中使用的
|
||||
// 公共控件类。
|
||||
InitCtrls.dwICC = ICC_WIN95_CLASSES;
|
||||
InitCommonControlsEx(&InitCtrls);
|
||||
|
||||
CWinApp::InitInstance();
|
||||
|
||||
|
||||
AfxEnableControlContainer();
|
||||
|
||||
// 创建 shell 管理器,以防对话框包含
|
||||
// 任何 shell 树视图控件或 shell 列表视图控件。
|
||||
CShellManager *pShellManager = new CShellManager;
|
||||
|
||||
// 激活“Windows Native”视觉管理器,以便在 MFC 控件中启用主题
|
||||
CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerWindows));
|
||||
|
||||
// 标准初始化
|
||||
// 如果未使用这些功能并希望减小
|
||||
// 最终可执行文件的大小,则应移除下列
|
||||
// 不需要的特定初始化例程
|
||||
// 更改用于存储设置的注册表项
|
||||
// TODO: 应适当修改该字符串,
|
||||
// 例如修改为公司或组织名
|
||||
SetRegistryKey(_T("应用程序向导生成的本地应用程序"));
|
||||
|
||||
CscannercheckDlg dlg;
|
||||
m_pMainWnd = &dlg;
|
||||
INT_PTR nResponse = dlg.DoModal();
|
||||
if (nResponse == IDOK)
|
||||
{
|
||||
// TODO: 在此放置处理何时用
|
||||
// “确定”来关闭对话框的代码
|
||||
}
|
||||
else if (nResponse == IDCANCEL)
|
||||
{
|
||||
// TODO: 在此放置处理何时用
|
||||
// “取消”来关闭对话框的代码
|
||||
}
|
||||
else if (nResponse == -1)
|
||||
{
|
||||
TRACE(traceAppMsg, 0, "警告: 对话框创建失败,应用程序将意外终止。\n");
|
||||
TRACE(traceAppMsg, 0, "警告: 如果您在对话框上使用 MFC 控件,则无法 #define _AFX_NO_MFC_CONTROLS_IN_DIALOGS。\n");
|
||||
}
|
||||
|
||||
// 删除上面创建的 shell 管理器。
|
||||
if (pShellManager != nullptr)
|
||||
{
|
||||
delete pShellManager;
|
||||
}
|
||||
|
||||
#if !defined(_AFXDLL) && !defined(_AFX_NO_MFC_CONTROLS_IN_DIALOGS)
|
||||
ControlBarCleanUp();
|
||||
#endif
|
||||
|
||||
// 由于对话框已关闭,所以将返回 FALSE 以便退出应用程序,
|
||||
// 而不是启动应用程序的消息泵。
|
||||
return FALSE;
|
||||
}
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
|
||||
// scanner-check.h: PROJECT_NAME 应用程序的主头文件
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef __AFXWIN_H__
|
||||
#error "在包含此文件之前包含 'pch.h' 以生成 PCH"
|
||||
#endif
|
||||
|
||||
#include "resource.h" // 主符号
|
||||
|
||||
|
||||
// CscannercheckApp:
|
||||
// 有关此类的实现,请参阅 scanner-check.cpp
|
||||
//
|
||||
|
||||
class CscannercheckApp : public CWinApp
|
||||
{
|
||||
public:
|
||||
CscannercheckApp();
|
||||
|
||||
// 重写
|
||||
public:
|
||||
virtual BOOL InitInstance();
|
||||
|
||||
// 实现
|
||||
|
||||
DECLARE_MESSAGE_MAP()
|
||||
};
|
||||
|
||||
extern CscannercheckApp theApp;
|
|
@ -0,0 +1,226 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<VCProjectVersion>16.0</VCProjectVersion>
|
||||
<ProjectGuid>{A8F24886-2A0E-4D4F-87C0-C752A17183FB}</ProjectGuid>
|
||||
<Keyword>MFCProj</Keyword>
|
||||
<RootNamespace>scannercheck</RootNamespace>
|
||||
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
<UseOfMfc>Dynamic</UseOfMfc>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
<UseOfMfc>Dynamic</UseOfMfc>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
<UseOfMfc>Dynamic</UseOfMfc>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
<UseOfMfc>Dynamic</UseOfMfc>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="Shared">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
<IncludePath>$(ProjectDir)..\..\sdk\include\;$(IncludePath)</IncludePath>
|
||||
<LibraryPath>$(ProjectDir)..\..\sdk\lib;$(LibraryPath)</LibraryPath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
<IncludePath>$(ProjectDir)..\..\sdk\include\;$(IncludePath)</IncludePath>
|
||||
<LibraryPath>$(ProjectDir)..\..\sdk\lib;$(LibraryPath)</LibraryPath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
<IncludePath>$(ProjectDir)..\..\sdk\include\;$(IncludePath)</IncludePath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
<IncludePath>$(ProjectDir)..\..\sdk\include\;$(IncludePath)</IncludePath>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>WIN32;_WINDOWS;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
</Link>
|
||||
<Midl>
|
||||
<MkTypLibCompatible>false</MkTypLibCompatible>
|
||||
<ValidateAllParameters>true</ValidateAllParameters>
|
||||
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</Midl>
|
||||
<ResourceCompile>
|
||||
<Culture>0x0804</Culture>
|
||||
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<AdditionalIncludeDirectories>$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
</ResourceCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>WIN32;_WINDOWS;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
</Link>
|
||||
<Midl>
|
||||
<MkTypLibCompatible>false</MkTypLibCompatible>
|
||||
<ValidateAllParameters>true</ValidateAllParameters>
|
||||
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</Midl>
|
||||
<ResourceCompile>
|
||||
<Culture>0x0804</Culture>
|
||||
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<AdditionalIncludeDirectories>$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
</ResourceCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>_WINDOWS;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
</Link>
|
||||
<Midl>
|
||||
<MkTypLibCompatible>false</MkTypLibCompatible>
|
||||
<ValidateAllParameters>true</ValidateAllParameters>
|
||||
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</Midl>
|
||||
<ResourceCompile>
|
||||
<Culture>0x0804</Culture>
|
||||
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<AdditionalIncludeDirectories>$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
</ResourceCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>_WINDOWS;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
</Link>
|
||||
<Midl>
|
||||
<MkTypLibCompatible>false</MkTypLibCompatible>
|
||||
<ValidateAllParameters>true</ValidateAllParameters>
|
||||
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</Midl>
|
||||
<ResourceCompile>
|
||||
<Culture>0x0804</Culture>
|
||||
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<AdditionalIncludeDirectories>$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
</ResourceCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="CDlgItemMgr.h" />
|
||||
<ClInclude Include="CDlgMgr.h" />
|
||||
<ClInclude Include="framework.h" />
|
||||
<ClInclude Include="page.h" />
|
||||
<ClInclude Include="pch.h" />
|
||||
<ClInclude Include="Resource.h" />
|
||||
<ClInclude Include="scanner-check.h" />
|
||||
<ClInclude Include="scanner-checkDlg.h" />
|
||||
<ClInclude Include="targetver.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="CDlgItemMgr.cpp" />
|
||||
<ClCompile Include="CDlgMgr.cpp" />
|
||||
<ClCompile Include="pch.cpp">
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
|
||||
</ClCompile>
|
||||
<ClCompile Include="scanner-check.cpp" />
|
||||
<ClCompile Include="scanner-checkDlg.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ResourceCompile Include="scannercheck.rc" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="res\scannercheck.rc2" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Image Include="res\scanner-check.ico" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
|
@ -0,0 +1,78 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="源文件">
|
||||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="头文件">
|
||||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="资源文件">
|
||||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
||||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="scanner-check.h">
|
||||
<Filter>头文件</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="scanner-checkDlg.h">
|
||||
<Filter>头文件</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="framework.h">
|
||||
<Filter>头文件</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="targetver.h">
|
||||
<Filter>头文件</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Resource.h">
|
||||
<Filter>头文件</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="pch.h">
|
||||
<Filter>头文件</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="CDlgMgr.h">
|
||||
<Filter>头文件</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="page.h">
|
||||
<Filter>头文件</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="CDlgItemMgr.h">
|
||||
<Filter>头文件</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="scanner-check.cpp">
|
||||
<Filter>源文件</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="scanner-checkDlg.cpp">
|
||||
<Filter>源文件</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="pch.cpp">
|
||||
<Filter>源文件</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="CDlgMgr.cpp">
|
||||
<Filter>源文件</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="CDlgItemMgr.cpp">
|
||||
<Filter>源文件</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ResourceCompile Include="scannercheck.rc">
|
||||
<Filter>资源文件</Filter>
|
||||
</ResourceCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="res\scannercheck.rc2">
|
||||
<Filter>资源文件</Filter>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Image Include="res\scanner-check.ico">
|
||||
<Filter>资源文件</Filter>
|
||||
</Image>
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -0,0 +1,278 @@
|
|||
|
||||
// scanner-checkDlg.cpp: 实现文件
|
||||
//
|
||||
|
||||
#include "pch.h"
|
||||
#include "framework.h"
|
||||
#include "scanner-check.h"
|
||||
#include "scanner-checkDlg.h"
|
||||
#include "afxdialogex.h"
|
||||
#include <imm.h>
|
||||
|
||||
#pragma comment(lib, "imm32.lib")
|
||||
|
||||
#ifdef _DEBUG
|
||||
#define new DEBUG_NEW
|
||||
#endif
|
||||
|
||||
#include "CDlgMgr.h"
|
||||
#include "CDlgItemMgr.h"
|
||||
#include <coding/coding.h>
|
||||
#include <file/file_util.h>
|
||||
|
||||
// CscannercheckDlg 对话框
|
||||
|
||||
|
||||
|
||||
CscannercheckDlg::CscannercheckDlg(CWnd* pParent /*=nullptr*/)
|
||||
: CDialogEx(IDD_SCANNERCHECK_DIALOG, pParent)
|
||||
{
|
||||
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
|
||||
}
|
||||
|
||||
void CscannercheckDlg::DoDataExchange(CDataExchange* pDX)
|
||||
{
|
||||
CDialogEx::DoDataExchange(pDX);
|
||||
DDX_Control(pDX, IDC_TAB1, tab_);
|
||||
DDX_Control(pDX, IDC_COMBO1, combo_);
|
||||
}
|
||||
|
||||
BEGIN_MESSAGE_MAP(CscannercheckDlg, CDialogEx)
|
||||
ON_WM_SYSCOMMAND()
|
||||
ON_WM_PAINT()
|
||||
ON_WM_QUERYDRAGICON()
|
||||
ON_BN_CLICKED(IDC_BUTTON_EXPORT, &CscannercheckDlg::OnBnClickedButtonExport)
|
||||
ON_CBN_SELCHANGE(IDC_COMBO1, &CscannercheckDlg::OnCbnSelchangeCombo1)
|
||||
ON_NOTIFY(TCN_SELCHANGE, IDC_TAB1, &CscannercheckDlg::OnTcnSelchangeTab1)
|
||||
ON_NOTIFY(TCN_SELCHANGING, IDC_TAB1, &CscannercheckDlg::OnTcnSelchangingTab1)
|
||||
ON_MESSAGE(WM_TO_ITEM_MGR_TAB, &CscannercheckDlg::on_to_item_manager_tab)
|
||||
ON_MESSAGE(WM_GET_TEST_ITEM_NAME, &CscannercheckDlg::on_name_from_title)
|
||||
ON_MESSAGE(WM_GET_TEST_ITEM_TITLE, &CscannercheckDlg::on_name_to_title)
|
||||
ON_MESSAGE(WM_TEST_ITEM_CHANGED, &CscannercheckDlg::on_test_item_changed)
|
||||
END_MESSAGE_MAP()
|
||||
|
||||
void CscannercheckDlg::add_page(const wchar_t* title, CDialogEx* child)
|
||||
{
|
||||
RECT r = { 0 };
|
||||
int ind = 0;
|
||||
TCITEM item = { 0 };
|
||||
|
||||
GetDlgItem(IDC_STATIC_RECT)->GetWindowRect(&r);
|
||||
ScreenToClient(&r);
|
||||
child->MoveWindow(&r);
|
||||
|
||||
ind = tab_.InsertItem(tab_.GetItemCount(), title);
|
||||
item.lParam = (LPARAM)child;
|
||||
item.mask = TCIF_PARAM;
|
||||
tab_.SetItem(ind, &item);
|
||||
}
|
||||
|
||||
// CscannercheckDlg 消息处理程序
|
||||
|
||||
BOOL CscannercheckDlg::OnInitDialog()
|
||||
{
|
||||
CDialogEx::OnInitDialog();
|
||||
|
||||
// 设置此对话框的图标。 当应用程序主窗口不是对话框时,框架将自动
|
||||
// 执行此操作
|
||||
SetIcon(m_hIcon, TRUE); // 设置大图标
|
||||
SetIcon(m_hIcon, FALSE); // 设置小图标
|
||||
|
||||
// 工作台配置; DLL配置;
|
||||
int ind = combo_.AddString(TEXT("DLL \u914D\u7F6E"));
|
||||
combo_.SetItemData(ind, (DWORD_PTR)1);
|
||||
ind = combo_.AddString(TEXT("\u5DE5\u4F5C\u53F0\u914D\u7F6E"));
|
||||
combo_.SetItemData(ind, NULL);
|
||||
combo_.SetCurSel(ind);
|
||||
OnCbnSelchangeCombo1();
|
||||
|
||||
SetDlgItemInt(IDC_EDIT_VER, 1);
|
||||
|
||||
// TODO: 在此添加额外的初始化代码
|
||||
mgr_ = new CDlgMgr(this);
|
||||
mgr_->Create(IDD_MANAGER, this);
|
||||
add_page(L"\u6D4B\u8BD5\u9879\u76EE\u914D\u7F6E", mgr_);
|
||||
mgr_->ShowWindow(SW_SHOW);
|
||||
|
||||
items_ = new CDlgItemMgr(this);
|
||||
items_->Create(IDD_TEST_ITEM, this);
|
||||
add_page(L"\u6D4B\u8BD5\u9879\u76EE\u5E93\u7BA1\u7406", items_);
|
||||
items_->ShowWindow(SW_HIDE);
|
||||
|
||||
on_test_item_changed(0, 0);
|
||||
// ImmDisableIME(0);
|
||||
|
||||
return FALSE; // 除非将焦点设置到控件,否则返回 TRUE
|
||||
}
|
||||
|
||||
void CscannercheckDlg::OnSysCommand(UINT nID, LPARAM lParam)
|
||||
{
|
||||
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
CDialogEx::OnSysCommand(nID, lParam);
|
||||
}
|
||||
}
|
||||
|
||||
// 如果向对话框添加最小化按钮,则需要下面的代码
|
||||
// 来绘制该图标。 对于使用文档/视图模型的 MFC 应用程序,
|
||||
// 这将由框架自动完成。
|
||||
|
||||
void CscannercheckDlg::OnPaint()
|
||||
{
|
||||
if (IsIconic())
|
||||
{
|
||||
CPaintDC dc(this); // 用于绘制的设备上下文
|
||||
|
||||
SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
|
||||
|
||||
// 使图标在工作区矩形中居中
|
||||
int cxIcon = GetSystemMetrics(SM_CXICON);
|
||||
int cyIcon = GetSystemMetrics(SM_CYICON);
|
||||
CRect rect;
|
||||
GetClientRect(&rect);
|
||||
int x = (rect.Width() - cxIcon + 1) / 2;
|
||||
int y = (rect.Height() - cyIcon + 1) / 2;
|
||||
|
||||
// 绘制图标
|
||||
dc.DrawIcon(x, y, m_hIcon);
|
||||
}
|
||||
else
|
||||
{
|
||||
CDialogEx::OnPaint();
|
||||
}
|
||||
}
|
||||
|
||||
//当用户拖动最小化窗口时系统调用此函数取得光标
|
||||
//显示。
|
||||
HCURSOR CscannercheckDlg::OnQueryDragIcon()
|
||||
{
|
||||
return static_cast<HCURSOR>(m_hIcon);
|
||||
}
|
||||
|
||||
|
||||
INTER_MODULE_CALLBACK(got_str)
|
||||
{
|
||||
*((std::string*)param) += std::string(data, len);
|
||||
|
||||
return inter_module_data::SET_RESULT_CONTINUE;
|
||||
}
|
||||
void CscannercheckDlg::OnBnClickedButtonExport()
|
||||
{
|
||||
// TODO: 在此添加控件通知处理程序代码
|
||||
int ind = tab_.GetCurSel(), ver = GetDlgItemInt(IDC_EDIT_VER);
|
||||
TCITEM item = { 0 };
|
||||
|
||||
item.mask = TCIF_PARAM;
|
||||
tab_.GetItem(ind, &item);
|
||||
if (!item.lParam)
|
||||
{
|
||||
MessageBox(TEXT("\u4E22\u5931\u8BBE\u7F6E\u9875\u9762\u5BF9\u8C61\u6307\u9488"), TEXT("\u9519\u8BEF"), MB_OK);
|
||||
return;
|
||||
}
|
||||
|
||||
bool ok = true, code = (bool)combo_.GetItemData(combo_.GetCurSel());
|
||||
std::wstring text((dynamic_cast<page_config*>((CWnd*)item.lParam))->export_config(&ok, code, ver));
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
::MessageBoxW(m_hWnd, text.c_str(), L"\u9519\u8BEF", MB_OK);
|
||||
return;
|
||||
}
|
||||
|
||||
if (file_util::set_clipboard(text.c_str(), text.length() * 2, CF_UNICODETEXT))
|
||||
{
|
||||
file_util::PATHFILE path = { 0 };
|
||||
if (file_util::browser_file(m_hWnd, &path, L"All Files(*.*)\0\0\0", false, L"\u8BF7\u9009\u62E9\u6587\u4EF6\u4FDD\u5B58\u8DEF\u5F84"))
|
||||
{
|
||||
std::string bom("");
|
||||
|
||||
coding_util::bom::from_unicode(text.c_str(), text.length() * 2, got_str, &bom);
|
||||
file_util::save_2_file(bom.c_str(), bom.length(), path.path);
|
||||
file_util::display_file_in_explorer(path.path);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
::MessageBoxW(m_hWnd, L"\u5BFC\u51FA\u5185\u5BB9\u5DF2\u62F7\u8D1D\u5230\u526A\u8D34\u677F", L"\u5BFC\u51FA\u5B8C\u6210", MB_OK | MB_ICONINFORMATION);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CscannercheckDlg::OnCbnSelchangeCombo1()
|
||||
{
|
||||
// TODO: 在此添加控件通知处理程序代码
|
||||
bool dll = (bool)combo_.GetItemData(combo_.GetCurSel());
|
||||
|
||||
GetDlgItem(IDC_STATIC_VER)->EnableWindow(dll);
|
||||
GetDlgItem(IDC_EDIT_VER)->EnableWindow(dll);
|
||||
if (dll)
|
||||
GotoDlgCtrl(GetDlgItem(IDC_EDIT_VER));
|
||||
}
|
||||
|
||||
|
||||
void CscannercheckDlg::OnTcnSelchangeTab1(NMHDR* pNMHDR, LRESULT* pResult)
|
||||
{
|
||||
// TODO: 在此添加控件通知处理程序代码
|
||||
*pResult = 0;
|
||||
TCITEM item = { 0 };
|
||||
page_config* page = NULL;
|
||||
|
||||
item.mask = TCIF_PARAM;
|
||||
tab_.GetItem(tab_.GetCurSel(), &item);
|
||||
page = dynamic_cast<page_config*>((CWnd*)item.lParam);
|
||||
GetDlgItem(IDC_BUTTON_EXPORT)->EnableWindow(page != NULL);
|
||||
((CWnd*)item.lParam)->ShowWindow(SW_SHOW);
|
||||
}
|
||||
|
||||
void CscannercheckDlg::OnTcnSelchangingTab1(NMHDR* pNMHDR, LRESULT* pResult)
|
||||
{
|
||||
// TODO: 在此添加控件通知处理程序代码
|
||||
*pResult = 0;
|
||||
*pResult = 0;
|
||||
TCITEM item = { 0 };
|
||||
item.mask = TCIF_PARAM;
|
||||
tab_.GetItem(tab_.GetCurSel(), &item);
|
||||
((CWnd*)item.lParam)->ShowWindow(SW_HIDE);
|
||||
}
|
||||
|
||||
LRESULT CscannercheckDlg::on_to_item_manager_tab(WPARAM, LPARAM)
|
||||
{
|
||||
LRESULT result = 0;
|
||||
|
||||
OnTcnSelchangingTab1(NULL, &result);
|
||||
tab_.SetCurSel(1);
|
||||
OnTcnSelchangeTab1(NULL, &result);
|
||||
|
||||
return 0;
|
||||
}
|
||||
LRESULT CscannercheckDlg::on_name_from_title(WPARAM wp, LPARAM lp)
|
||||
{
|
||||
std::wstring title((wchar_t*)wp);
|
||||
page_config::ITEM* item = (page_config::ITEM*)lp;
|
||||
|
||||
items_->get_name(title.c_str(), item);
|
||||
|
||||
return 0;
|
||||
}
|
||||
LRESULT CscannercheckDlg::on_name_to_title(WPARAM wp, LPARAM lp)
|
||||
{
|
||||
std::wstring name((wchar_t*)wp);
|
||||
page_config::ITEM* item = (page_config::ITEM*)lp;
|
||||
|
||||
items_->get_title(name.c_str(), item);
|
||||
|
||||
return 0;
|
||||
}
|
||||
LRESULT CscannercheckDlg::on_test_item_changed(WPARAM wp, LPARAM lp)
|
||||
{
|
||||
std::vector<page_config::ITEM> items;
|
||||
items_->get_all_items(items);
|
||||
mgr_->init_test_items(items);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,53 @@
|
|||
|
||||
// scanner-checkDlg.h: 头文件
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Resource.h"
|
||||
|
||||
class CDlgMgr;
|
||||
class CDlgItemMgr;
|
||||
|
||||
// CscannercheckDlg 对话框
|
||||
class CscannercheckDlg : public CDialogEx
|
||||
{
|
||||
// 构造
|
||||
public:
|
||||
CscannercheckDlg(CWnd* pParent = nullptr); // 标准构造函数
|
||||
|
||||
// 对话框数据
|
||||
#ifdef AFX_DESIGN_TIME
|
||||
enum { IDD = IDD_SCANNERCHECK_DIALOG };
|
||||
#endif
|
||||
|
||||
protected:
|
||||
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持
|
||||
|
||||
void add_page(const wchar_t* title, CDialogEx* child);
|
||||
|
||||
CDlgItemMgr* items_;
|
||||
CDlgMgr* mgr_;
|
||||
|
||||
// 实现
|
||||
protected:
|
||||
HICON m_hIcon;
|
||||
|
||||
// 生成的消息映射函数
|
||||
virtual BOOL OnInitDialog();
|
||||
afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
|
||||
afx_msg void OnPaint();
|
||||
afx_msg HCURSOR OnQueryDragIcon();
|
||||
DECLARE_MESSAGE_MAP()
|
||||
public:
|
||||
CTabCtrl tab_;
|
||||
afx_msg void OnBnClickedButtonExport();
|
||||
CComboBox combo_;
|
||||
afx_msg void OnCbnSelchangeCombo1();
|
||||
afx_msg void OnTcnSelchangeTab1(NMHDR* pNMHDR, LRESULT* pResult);
|
||||
afx_msg LRESULT on_to_item_manager_tab(WPARAM, LPARAM);
|
||||
afx_msg LRESULT on_name_from_title(WPARAM wp, LPARAM lp);
|
||||
afx_msg LRESULT on_name_to_title(WPARAM wp, LPARAM lp);
|
||||
afx_msg LRESULT on_test_item_changed(WPARAM wp, LPARAM lp);
|
||||
afx_msg void OnTcnSelchangingTab1(NMHDR* pNMHDR, LRESULT* pResult);
|
||||
};
|
Binary file not shown.
|
@ -0,0 +1,8 @@
|
|||
#pragma once
|
||||
|
||||
// 包括 SDKDDKVer.h 将定义可用的最高版本的 Windows 平台。
|
||||
|
||||
//如果要为以前的 Windows 平台生成应用程序,请包括 WinSDKVer.h,并
|
||||
// 将 _WIN32_WINNT 宏设置为要支持的平台,然后再包括 SDKDDKVer.h。
|
||||
|
||||
#include <SDKDDKVer.h>
|
|
@ -0,0 +1,516 @@
|
|||
|
||||
// gb_base64.h : base64 encoding, allow you use your own BASE64 letter table
|
||||
//
|
||||
// Author: Gongbing
|
||||
//
|
||||
// Date: 2016-07-02
|
||||
|
||||
#pragma once
|
||||
#ifndef _INCLUDED_REF_
|
||||
#define _INCLUDED_REF_
|
||||
#include "../ref/ref.h"
|
||||
#endif
|
||||
|
||||
#define MINI_BUF_LEN 40
|
||||
|
||||
// this MACRO should include <algorithm> and <string> header files ...
|
||||
#define STD_STR_TO_LOWER(str) std::transform((str).begin(), (str).end(), (str).begin(), tolower)
|
||||
|
||||
namespace coding_util
|
||||
{
|
||||
// all apis return error code, except commenting specially
|
||||
|
||||
__declspec(novtable) struct IBase64 : public ref_util::IRef
|
||||
{
|
||||
COM_API_DECLARE(bool, init_table(const char* base64_table = 0));
|
||||
|
||||
// parameter: result((char*)data, ...)
|
||||
// return: error code
|
||||
COM_API_DECLARE(int, encode(const char* data, size_t len, inter_module_data::set_data result, void* param, unsigned int max_line_len = -1, bool need_padding = true));
|
||||
COM_API_DECLARE(int, decode(const char* data, size_t len, inter_module_data::set_data result, void* param));
|
||||
};
|
||||
__declspec(novtable) struct IBitsBuf : public ref_util::IRef
|
||||
{
|
||||
COM_API_DECLARE(bool, resize(int len, bool init_val = false));
|
||||
COM_API_DECLARE(void, reset(bool val = false));
|
||||
COM_API_DECLARE(void, set(int index, bool val));
|
||||
COM_API_DECLARE(bool, get(int index));
|
||||
|
||||
// following for two-dimension
|
||||
COM_API_DECLARE(bool, resize(short row, short col, bool init_val = false));
|
||||
COM_API_DECLARE(void, set(short row, short col, bool val));
|
||||
COM_API_DECLARE(bool, get(short row, short col));
|
||||
};
|
||||
|
||||
// convert a hex letter to 4-bits integer.
|
||||
// ch: to receive the result
|
||||
// return whether the parameter 'hex' is a valid hex-letter
|
||||
PORT_API(bool) hex_str_2_int(char hex, unsigned char* ch);
|
||||
|
||||
/* commonplace code page: refer to https://www.cnblogs.com/answercard/p/10122434.html
|
||||
GBK: 936
|
||||
BIG5: 950
|
||||
UTF-16: 1200
|
||||
unicode: 1201
|
||||
GB2312: 20936
|
||||
hz-gb-2312: 52936
|
||||
GB18030: 54936
|
||||
UTF-7: 65000
|
||||
UTF-8: 65001
|
||||
*/
|
||||
// get code page of given charset name, 0 is failure
|
||||
PORT_API(UINT) code_page_from_name(const char* name);
|
||||
PORT_API(UINT) code_page_from_name(const wchar_t* name);
|
||||
|
||||
// result((wchar_t*)data, ...);
|
||||
//
|
||||
// return: error code, 0 is success
|
||||
PORT_API(int) ansi_2_unicode(const char* data, inter_module_data::set_data result, void* param, int chars = -1, UINT ansi_code_page = CP_ACP);
|
||||
PORT_API(int) ansi_2_utf8(const char* data, inter_module_data::set_data result, void* param, int chars = -1, UINT ansi_code_page = CP_ACP);
|
||||
PORT_API(int) unicode_2_ansi(const wchar_t* data, inter_module_data::set_data result, void* param, int chars = -1, UINT ansi_code_page = CP_ACP);
|
||||
PORT_API(int) unicode_2_utf8(const wchar_t* data, inter_module_data::set_data result, void* param, int chars = -1);
|
||||
PORT_API(int) utf8_2_ansi(const char* data, inter_module_data::set_data result, void* param, int chars = -1, UINT ansi_code_page = CP_ACP);
|
||||
PORT_API(int) utf8_2_unicode(const char* data, inter_module_data::set_data result, void* param, int chars = -1);
|
||||
|
||||
// case transfer, return changes
|
||||
PORT_API(int) to_upper(char* str, int len = -1);
|
||||
PORT_API(int) to_upper(wchar_t* str, int len = -1);
|
||||
PORT_API(int) to_lower(char* str, int len = -1);
|
||||
PORT_API(int) to_lower(wchar_t* str, int len = -1);
|
||||
|
||||
// Function: transform string between unicode style as 0x1234 and web style such as \u1234, %12%34 ...
|
||||
// result((wchar_t*)data, ...);
|
||||
PORT_API(void) from_web_style(const wchar_t* data, inter_module_data::set_data result, void* param);
|
||||
PORT_API(void) to_web_style(const wchar_t* data, inter_module_data::set_data result, void* param);
|
||||
|
||||
namespace bom
|
||||
{
|
||||
PORT_API(bool) is_unicode(const char* bom_str, bool* big_ending); // bom_str must be great than 3 bytes, big_ending to receive whether the bom is a Big-Ending unicode
|
||||
PORT_API(bool) is_utf8(const char* bom_str); // bom_str must be great than 3 bytes
|
||||
|
||||
// result((char*)data, ...), maybe DATA_FLAG_ERROR
|
||||
PORT_API(void) to_ansi(const char* bom_str, size_t bytes, inter_module_data::set_data result, void* param);
|
||||
PORT_API(void) to_utf8(const char* bom_str, size_t bytes, inter_module_data::set_data result, void* param);
|
||||
|
||||
// result((wchar_t*)data, ...), maybe DATA_FLAG_ERROR
|
||||
PORT_API(void) to_unicode(const char* bom_str, size_t bytes, inter_module_data::set_data result, void* param, bool little_ending = true);
|
||||
|
||||
// result((char*)data, ...), maybe DATA_FLAG_ERROR
|
||||
PORT_API(void) from_ansi(const char* bom_str, size_t bytes, inter_module_data::set_data result, void* param);
|
||||
PORT_API(void) from_unicode(const wchar_t* bom_str, size_t bytes, inter_module_data::set_data result, void* param, bool little_ending = true);
|
||||
PORT_API(void) from_utf8(const char* bom_str, size_t bytes, inter_module_data::set_data result, void* param);
|
||||
}
|
||||
|
||||
PORT_API(int) trim_left(char* str, const char* trim_letter = " \t"); // return erased letters count
|
||||
PORT_API(int) trim_left(wchar_t* str, const wchar_t* trim_letter = L" \t"); // return erased letters count
|
||||
PORT_API(int) trim_right(char* str, const char* trim_letter = " \t"); // return erased letters count
|
||||
PORT_API(int) trim_right(wchar_t* str, const wchar_t* trim_letter = L" \t"); // return erased letters count
|
||||
|
||||
// return whether replaced, maybe DATA_FLAG_ERROR if 'old' is a sub-string in rep when 'all' is true
|
||||
// all string should ended with '\0'
|
||||
PORT_API(bool) replace(const char* str, const char* old, const char* rep, inter_module_data::set_data result, void* param, bool all = true);
|
||||
PORT_API(bool) replace(const wchar_t* str, const wchar_t* old, const wchar_t* rep, inter_module_data::set_data result, void* param, bool all = true);
|
||||
|
||||
// function: to pick the value between 'lead' and 'end' block.
|
||||
// cont: the origin text
|
||||
// lead: the leading mark
|
||||
// end: the ending mark
|
||||
// result: data - (const wchar_t*) or (const char*) value, without lead and rear mark
|
||||
// len - data bytes
|
||||
// total - found count
|
||||
// flag - DATA_FLAG_FINAL
|
||||
// param - same as the parameter 'param'
|
||||
// first: to receive the beginning of the found value
|
||||
// last: to receive the endding of the found value
|
||||
// include_tag: picked result whether include the 'lead' and 'end' string
|
||||
// case_sensitive: whether the lead and end are case sensitive
|
||||
//
|
||||
// return: found count, -1 is error
|
||||
enum mark_layer
|
||||
{
|
||||
MARK_LAYER_FLAT = 1, // context formed as lead + val + end + ... + lead + val + end + ...
|
||||
MARK_LAYER_EMBED, // context formed as lead + (lead + val + end) ... + end + ...
|
||||
};
|
||||
PORT_API(int) pick_value(const char* cont, const char* lead, const char* end, inter_module_data::set_data result, void* param, bool include_tag = false, bool case_sensitive = true, mark_layer layer = MARK_LAYER_EMBED);
|
||||
PORT_API(int) pick_value(const char* cont, const char* lead, const char* end, int* first, int* last, bool include_tag = false, bool case_sensitive = true, mark_layer layer = MARK_LAYER_EMBED);
|
||||
PORT_API(int) pick_value(const wchar_t* cont, const wchar_t* lead, const wchar_t* end, inter_module_data::set_data result, void* param, bool include_tag = false, bool case_sensitive = true, mark_layer layer = MARK_LAYER_EMBED);
|
||||
PORT_API(int) pick_value(const wchar_t* cont, const wchar_t* lead, const wchar_t* end, int* first, int* last, bool include_tag = false, bool case_sensitive = true, mark_layer layer = MARK_LAYER_EMBED);
|
||||
PORT_API(int) pick_first_branch_in_if_else_endif(const wchar_t* cont, const wchar_t* lead, const wchar_t* elif, const wchar_t* end, int* first, int* last, bool include_tag = false, bool case_sensitive = true);
|
||||
|
||||
// simple_line: consider followin lines
|
||||
// line 1\
|
||||
// -line 2
|
||||
// true - return "line 1"
|
||||
// false - return "line 1-line 2"
|
||||
PORT_API(void) pick_line(const char* str, inter_module_data::set_data result, void* param, int* next_line = NULL, bool simple_line = false);
|
||||
PORT_API(void) pick_line(const wchar_t* str, inter_module_data::set_data result, void* param, int* next_line = NULL, bool simple_line = false);
|
||||
PORT_API(void) pick_whole_line(const char* cur, const char* bgn, inter_module_data::set_data result, void* param, int* next_line = NULL, bool simple_line = false);
|
||||
PORT_API(void) pick_whole_line(const wchar_t* cur, const wchar_t* bgn, inter_module_data::set_data result, void* param, int* next_line = NULL, bool simple_line = false);
|
||||
|
||||
enum num_format
|
||||
{
|
||||
NUM_FMT_DECIMAL, // float/double
|
||||
NUM_FMT_INTEGER, // int in decimal
|
||||
NUM_FMT_BIN,
|
||||
NUM_FMT_OCT,
|
||||
NUM_FMT_HEX,
|
||||
};
|
||||
// function: to pick a number from string
|
||||
// num_str: number string
|
||||
// ret: to receive the ending point of the number
|
||||
// nf: format of num_str
|
||||
//
|
||||
// return: all in double value, if nf is in BIN, OCT or HEX, this contains max 32-bits
|
||||
// maybe return NON if num_str in DECIMAL or INTEGER
|
||||
PORT_API(double) pick_number(const char* num_str, const char** ret = NULL, num_format nf = NUM_FMT_DECIMAL);
|
||||
PORT_API(double) pick_number(const wchar_t* num_str, const wchar_t** ret = NULL, num_format nf = NUM_FMT_DECIMAL);
|
||||
|
||||
// function: to pick an integer from a number string
|
||||
//
|
||||
// remarks: if all digit is in [0, 9], then consider it as a decimal
|
||||
// 0xnnn or nnnh: heximal
|
||||
// nnno: oct
|
||||
// nnnb: binary
|
||||
// other: decimal
|
||||
// return: -1 if failed
|
||||
PORT_API(unsigned long long) pick_integer(const char* num_str, size_t bytes = 4);
|
||||
PORT_API(unsigned long long) pick_integer(const wchar_t* num_str, size_t bytes = 4);
|
||||
|
||||
// following two apis replace the string in str buffer, and return ERROR_SUCCESS or ERROR_INSUFFICIENT_BUFFER
|
||||
// all string should ended with '\0'
|
||||
PORT_API(int) replace(char* str, size_t str_buf_len, const char* old, const char* _new, bool *rep);
|
||||
PORT_API(int) replace(wchar_t* str, size_t str_buf_len, const wchar_t* old, const wchar_t* _new, bool *rep);
|
||||
|
||||
PORT_API(IBase64*) create_base64(void);
|
||||
PORT_API(IBitsBuf*) create_bits_buffer(void);
|
||||
|
||||
// function: calculate md5
|
||||
// return: md5_val, may be empty if the path_file is not accessible
|
||||
PORT_API(char*) md5(const char* data, size_t len, char md5_val[MINI_BUF_LEN]);
|
||||
PORT_API(char*) md5(const wchar_t* path_file, char md5_val[MINI_BUF_LEN]);
|
||||
|
||||
enum _aes_type_
|
||||
{
|
||||
AES_ECB = 1,
|
||||
AES_CBC,
|
||||
AES_OFB,
|
||||
AES_CFB,
|
||||
};
|
||||
PORT_API(int) aes_encoding(const char* plain, size_t len, const char *iv, const char* pwd, inter_module_data::set_data result, void* param, int iv_len = 16, int pwd_len = 16, _aes_type_ type = AES_CBC);
|
||||
PORT_API(int) aes_decoding(const char* cipher, size_t len, const char *iv, const char* pwd, inter_module_data::set_data result, void* param, int iv_len = 16, int pwd_len = 16, _aes_type_ type = AES_CBC);
|
||||
|
||||
// return 0 if success
|
||||
PORT_API(int) lzw_encoding(const char* plain, size_t len, inter_module_data::set_data result, void* param);
|
||||
PORT_API(int) lzw_decoding(const char* cipher, size_t len, inter_module_data::set_data result, void* param);
|
||||
|
||||
// wildcard matching ...
|
||||
// str: to be compared string
|
||||
// pattern: include '*' or '?', e.g. "*.bat"
|
||||
PORT_API(bool) is_wildcard_match(const char* str, const char* pattern, int str_len = -1, int patt_len = -1);
|
||||
PORT_API(bool) is_wildcard_match(const wchar_t* str, const wchar_t* pattern, int str_len = -1, int patt_len = -1);
|
||||
|
||||
// convert time to string like: "yyyy-mm-dd hh:mm:ss"
|
||||
// NOTE: parameter 'tmprc' is valid only when 't' is ZERO
|
||||
enum _time_precision
|
||||
{
|
||||
TIME_PRECISION_SECOND = 0,
|
||||
TIME_PRECISION_MILLISECOND,
|
||||
TIME_PRECISION_ms = TIME_PRECISION_MILLISECOND,
|
||||
TIME_PRECISION_MICROSECOND,
|
||||
TIME_PRECISION_us = TIME_PRECISION_MICROSECOND,
|
||||
TIME_PRECISION_NANOSECOND,
|
||||
TIME_PRECISION_ns = TIME_PRECISION_NANOSECOND,
|
||||
};
|
||||
enum _week
|
||||
{
|
||||
WEEK_DAY_NO = 0,
|
||||
WEEK_DAY_CN,
|
||||
WEEK_DAY_EN,
|
||||
};
|
||||
PORT_API(bool) local_time_2_string(char tm_str[MINI_BUF_LEN], _time_precision tmprc = TIME_PRECISION_SECOND, _week week = WEEK_DAY_NO, time_t t = 0);
|
||||
PORT_API(bool) local_time_2_string(wchar_t tm_str[MINI_BUF_LEN], _time_precision tmprc = TIME_PRECISION_SECOND, _week week = WEEK_DAY_NO, time_t t = 0);
|
||||
PORT_API(const wchar_t*) get_week_string(int day_of_week, bool chinese);
|
||||
|
||||
// convert string like "yyyy-mm-dd hh:mm:ss" to local time, return -1 is error
|
||||
PORT_API(time_t) time_str_2_date_time(const char* tm_str);
|
||||
PORT_API(time_t) time_str_2_date_time(const wchar_t* tm_str);
|
||||
|
||||
// version ...
|
||||
// function: convert version '1.2.3.4' to 0x01020304
|
||||
PORT_API(UINT64) version_string_2_int(const char* dot_version);
|
||||
PORT_API(UINT64) version_string_2_int(const wchar_t* dot_version);
|
||||
|
||||
// return ver_buf
|
||||
PORT_API(char*) version_string_from_int(UINT64 val, char ver_buf[MINI_BUF_LEN]);
|
||||
PORT_API(wchar_t*) version_string_from_int(UINT64 val, wchar_t ver_buf[MINI_BUF_LEN]);
|
||||
|
||||
// return: 0 - equal; 1 - dot_version1 > dot_version2; -1 - dot_version1 < dot_version2
|
||||
PORT_API(int) compare_version(const char* dot_version1, const char* dot_version2);
|
||||
PORT_API(int) compare_version(const wchar_t* dot_version1, const wchar_t* dot_version2);
|
||||
|
||||
// file time
|
||||
PORT_API(bool) file_time_2_time(FILETIME ft, time_t* t);
|
||||
PORT_API(bool) file_time_from_time(time_t t, FILETIME* ft);
|
||||
|
||||
// convert the hex-string '12cdef' to [0x12, 0xcd, 0xef]
|
||||
// return: ending position in hex_str after this
|
||||
PORT_API(int) hex_string_2_bytes_seq(const char* hex_str, inter_module_data::set_data result, void* param, const char* omit = " \t\r\n");
|
||||
PORT_API(int) hex_string_2_bytes_seq(const wchar_t* hex_str, inter_module_data::set_data result, void* param, const wchar_t* omit = L" \t\r\n");
|
||||
|
||||
// transferred char like '\r', '\n' ... 'ok' to receive whether transfered
|
||||
PORT_API(char*) to_transfer_text(char trans_char, bool* ok); // return "\n" for '\n'
|
||||
PORT_API(wchar_t*) to_transfer_text(wchar_t trans_char, bool* ok); // return L"\n" for L'\n
|
||||
PORT_API(char) from_transfer_text(const char* trans_char, int* used_bytes, bool* ok); // return '\n' for "\n"
|
||||
PORT_API(wchar_t) from_transfer_text(const wchar_t* trans_char, int* used_bytes, bool* ok); // return L'\n' for L"\n"
|
||||
|
||||
// create guid as "{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}", return buf
|
||||
wchar_t* create_guid(wchar_t buf[MINI_BUF_LEN * 2]);
|
||||
};
|
||||
|
||||
namespace cxx_code
|
||||
{
|
||||
// function: to check a character is space or not
|
||||
//
|
||||
// parameter: ch - the character to be check
|
||||
//
|
||||
// return: whether the character 'ch' is a space
|
||||
//
|
||||
// NOTE: we assume the following characters spaces:
|
||||
// ' ', '\r', '\n', '\t'
|
||||
PORT_API(bool) is_space_char(wchar_t ch);
|
||||
|
||||
// function: skip the space character until valid character or ending
|
||||
//
|
||||
// parameter: codes - the cxx codes string
|
||||
//
|
||||
// pos - [in] starting pos to skip, [out] - the first none-space character position
|
||||
//
|
||||
// has_lrn - whether the spaces has '\n'
|
||||
//
|
||||
// return: whether any spaces has been skipped, i.e. the out pos is greater than in pos
|
||||
//
|
||||
// NOTE: space characters: ' '; '\t'; '\r'; '\n'
|
||||
PORT_API(bool) skip_space(const wchar_t* codes, int* pos, bool *has_lrn = NULL);
|
||||
|
||||
// function: to check the character 'ch' is whether a valid leading character of a variable
|
||||
PORT_API(bool) is_var_leading_char(wchar_t ch);
|
||||
|
||||
// function: to check the character 'ch' is whether a valid character of a variable
|
||||
PORT_API(bool) is_var_char(wchar_t ch);
|
||||
|
||||
// return the line ending char '\n' position or ending position if no, support multi-line joint by '\\'
|
||||
// str[ret] = L'\n' || str[ret] = 0
|
||||
PORT_API(long) line_ending(const wchar_t* str, int bgn);
|
||||
|
||||
// find the next 'key' position in 'str', omit those in quotes or comments, return -1 when not found
|
||||
PORT_API(long) next_key(const wchar_t* str, const wchar_t* key, int bgn = 0);
|
||||
|
||||
// return comment block beginning position (str[ret] = L'/'), -1 if not a comment block, start from *pos and set ending in pos when return
|
||||
//
|
||||
// pos when out will be the line ending (str[*pos] = L'\n') or the last '/' character of "/**/" block (str[*pos] = L'/')
|
||||
PORT_API(long) comment_block(const wchar_t* str, int* pos);
|
||||
|
||||
// function: erase the comments in "/**/" or after "//"
|
||||
//
|
||||
// parameter: codes - the cxx codes string
|
||||
//
|
||||
// notify - data: (const wchar_t*)the codes string after erasing comments
|
||||
//
|
||||
// len: unused
|
||||
//
|
||||
// total: unused
|
||||
//
|
||||
// flag: always be DATA_FLAG_FINAL
|
||||
//
|
||||
// param: same as the parameter 'param' you passed in the function
|
||||
//
|
||||
// param - for callback 'notify' using
|
||||
//
|
||||
// return: nonsence
|
||||
//
|
||||
// NOTE: the last '\n' after the comments will be reserved
|
||||
PORT_API(void) erase_comments(const wchar_t* codes, INTER_MODULE_CALLBACK_VAR(notify), void* param);
|
||||
|
||||
// function: pick a variable or function name
|
||||
//
|
||||
// parameter: codes - the cxx codes string
|
||||
//
|
||||
// pos - [in] starting pos, [out] - ending position after the last name character, or error position when failed
|
||||
//
|
||||
// digit - true to pick a digit, false to pick a variable
|
||||
//
|
||||
// return: the beginning of the name, -1 for error
|
||||
PORT_API(int) pick_variable(const wchar_t* codes, int* pos, bool digit = false);
|
||||
|
||||
// function: pick a block between characters 'bgn_ch' and 'end_ch'
|
||||
//
|
||||
// parameter: codes - the cxx codes string
|
||||
//
|
||||
// pos - [in] starting pos, [out] - ending position after the last name character(codes[*pos] == 'end_ch'), or error position when failed
|
||||
//
|
||||
// bgn_ch - the beginning character of the block, e.g. '('
|
||||
//
|
||||
// end_ch - the ending character of the block, e.g. ')'
|
||||
//
|
||||
// single_line - whether the block will be a single line in commonplace, or else with '\\' at the line ending
|
||||
//
|
||||
// other_comment_leading_char - other sinle line comment leading character
|
||||
//
|
||||
// return: the beginning of the block (codes[ret] == 'bgn_ch'), -1 for error.
|
||||
// failed also when single_line was true and meeting line-endig before 'end_ch'
|
||||
//
|
||||
// NOTE: this function will ommit the 'bgn_ch' and 'end_ch' which is after '\\' or in quotes "" or ''
|
||||
PORT_API(int) pick_block(const wchar_t* codes, int* pos, wchar_t bgn_ch, wchar_t end_ch, bool single_line = false, wchar_t other_comment_leading_char = 0);
|
||||
|
||||
// function: pick a if-else codes block
|
||||
//
|
||||
// parameter: codes - the cxx codes string
|
||||
//
|
||||
// pos - [in] starting pos, [out] - ending position after the last name character, or error position when failed
|
||||
//
|
||||
// notify - to notify a picked branch
|
||||
//
|
||||
// data: (const wchar_t*)condition, "(...)", empty string if the last 'else' branch
|
||||
//
|
||||
// len: (const wchar_t*)entity, "{...}"
|
||||
//
|
||||
// total: unused, always be ZERO
|
||||
//
|
||||
// flag: always be DATA_FLAG_FINAL. no invoking if error occurs
|
||||
//
|
||||
// param: same as the parameter 'param' you passed in the function
|
||||
//
|
||||
// return: SET_RESULT_CONTINUE to continue, SET_RESULT_STOP to stop this invoking
|
||||
//
|
||||
// param - for callback 'notify' using
|
||||
//
|
||||
// other_comment_leading_char - other sinle line comment leading character
|
||||
//
|
||||
// return: the beginning of the block, -1 for error
|
||||
//
|
||||
// NOTE: first word must be "if"
|
||||
PORT_API(int) pick_if_else_block(const wchar_t* codes, int* pos, INTER_MODULE_CALLBACK_VAR(notify), void* param, wchar_t other_comment_leading_char = 0);
|
||||
|
||||
// function: pick a #if-#endif codes block
|
||||
//
|
||||
// parameter: codes - the cxx codes string
|
||||
//
|
||||
// pos - [in] starting pos, [out] - ending position after the last name character, or error position when failed
|
||||
//
|
||||
// notify - to notify a picked branch
|
||||
//
|
||||
// data: (const wchar_t*)condition, empty string if the last 'else' branch
|
||||
//
|
||||
// len: (const wchar_t*)entity
|
||||
//
|
||||
// total: unused, always be ZERO
|
||||
//
|
||||
// flag: always be DATA_FLAG_FINAL. no invoking if error occurs
|
||||
//
|
||||
// param: same as the parameter 'param' you passed in the function
|
||||
//
|
||||
// return: SET_RESULT_CONTINUE to continue, SET_RESULT_STOP to stop this invoking
|
||||
//
|
||||
// param - for callback 'notify' using
|
||||
//
|
||||
// return: the beginning of the block, -1 for error
|
||||
//
|
||||
// NOTE: first word must be "#if"
|
||||
PORT_API(int) pick_macro_if_else_block(const wchar_t* codes, int* pos, INTER_MODULE_CALLBACK_VAR(notify), void* param);
|
||||
|
||||
// function: pick a function block
|
||||
//
|
||||
// parameter: codes - the cxx codes string
|
||||
//
|
||||
// pos - [in] starting pos, [out] - ending position after the last '}', or error position when return false
|
||||
//
|
||||
// notify - data: (const wchar_t*)function name and pre_leading declaration
|
||||
//
|
||||
// len: parameters ending with double '\0'
|
||||
//
|
||||
// total: (const wchar_t*)function entity, leading with '{' and ending with '}'
|
||||
//
|
||||
// flag: always be DATA_FLAG_FINAL. no invoking if error occurs
|
||||
//
|
||||
// param: same as the parameter 'param' you passed in the function
|
||||
//
|
||||
// param - for callback 'notify' using
|
||||
//
|
||||
// other_comment_leading_char - other sinle line comment leading character
|
||||
//
|
||||
// return: true when success, and then the function elements is passed back by 'notify'
|
||||
//
|
||||
// NOTE: it will be without entity if it was a function invoking
|
||||
PORT_API(bool) pick_function(const wchar_t* codes, int* pos, INTER_MODULE_CALLBACK_VAR(notify), void* param, wchar_t other_comment_leading_char = 0);
|
||||
|
||||
// function: to get the line number from offset 'pos'
|
||||
//
|
||||
PORT_API(unsigned) line_from_pos(const wchar_t* cont, unsigned pos);
|
||||
|
||||
// Function: to save and calculate a logical action result
|
||||
//
|
||||
// e.g.: set 'is_win' is 'true, then check 'is_win' will return true and '!is_win' is false
|
||||
//
|
||||
// NOTE: now support '||', '&&' and '!' operator and consider expression like 'i >= 0' as ONE variable
|
||||
// this means every expression between '&&' and '||' will consider as ONE variable
|
||||
//
|
||||
__declspec(novtable) struct ILogicAction : public ref_util::IRef
|
||||
{
|
||||
// Function: to set the callback to query value when a variable is unknown
|
||||
//
|
||||
// get_variable_val: data - see 'inter_module_data::DATA_FLAG_GET_VAL'
|
||||
//
|
||||
// len - see 'inter_module_data::DATA_FLAG_GET_VAL'
|
||||
//
|
||||
// total - see 'inter_module_data::DATA_FLAG_GET_VAL'
|
||||
//
|
||||
// flag - always be DATA_FLAG_GET_VAL
|
||||
//
|
||||
// param - the same as 'param' in this function
|
||||
//
|
||||
// NOTE: all unknown variable would be considered as 'false' if you did not set the callback
|
||||
// variable values has multi-strings format, and end with '\0' per value, double '\0' for all values
|
||||
COM_API_DECLARE(void, set_callback(inter_module_data::set_data get_variable_val, void* param));
|
||||
|
||||
// Function: add or modify known boolean value
|
||||
//
|
||||
// var: boolean variable, multi-vars divided by ';'
|
||||
//
|
||||
COM_API_DECLARE(void, set_variable_value(const wchar_t* var, const wchar_t* val, int bytes = 0));
|
||||
COM_API_DECLARE(void, set_variable_value(const wchar_t* var, bool val));
|
||||
COM_API_DECLARE(void, remove_variable(const wchar_t* var));
|
||||
COM_API_DECLARE(void, clear(void));
|
||||
|
||||
// Function: calculate logical expression such as 'is_win && is_android' ...
|
||||
//
|
||||
// logic_exp: logical expression, like 'is_win && is_android', '!is_win' ...
|
||||
//
|
||||
// supported: to receive whether the logic_exp is valid/supported now, return value would be nonsence if this was false
|
||||
//
|
||||
// return: boolean result. SEE 'supported' !!!
|
||||
//
|
||||
COM_API_DECLARE(bool, logic_expression_result(const wchar_t* logic_exp, bool* supported));
|
||||
|
||||
// Function: to query an logical expression value without user interacting
|
||||
//
|
||||
// Parameter: logic_expression - logical expression, like 'is_win && is_android', '!is_win' ...
|
||||
//
|
||||
// val - to receive the expression value if it was existing
|
||||
//
|
||||
// Return: whether the 'logic_expression' all are existing already (until calculate the result)
|
||||
COM_API_DECLARE(bool, query_existing_value(const wchar_t* logic_exp, bool* val));
|
||||
|
||||
COM_API_DECLARE(inter_module_data::set_result, last_input_result(void));
|
||||
|
||||
// Function: get symbol's value. e.g. return L"1" of symbol_value(L"BUILD_TYPE", ...) if L"BUILD_TYPE=1" was existed
|
||||
//
|
||||
// return: value, NULL if not found. you should use it immediately, and need not free it.
|
||||
COM_API_DECLARE(const wchar_t*, symbol_value(const wchar_t* symbol));
|
||||
|
||||
// save the logical-expressions to path_file which it is 'true'
|
||||
COM_API_DECLARE(int, save(const wchar_t* path_file));
|
||||
};
|
||||
|
||||
// logical action
|
||||
PORT_API(ILogicAction*) create_logical_action(void);
|
||||
}
|
|
@ -0,0 +1,70 @@
|
|||
|
||||
// database.h: simple database interface
|
||||
//
|
||||
// Author: Gongbing
|
||||
//
|
||||
// Date: 2020-09-11
|
||||
|
||||
#pragma once
|
||||
#ifndef _INCLUDED_REF_
|
||||
#define _INCLUDED_REF_
|
||||
#include "../ref/ref.h"
|
||||
#endif
|
||||
#include <OAIdl.h> // for VARIANT
|
||||
|
||||
#define MAX_TABLE_FIELD_NAME_LEN 20
|
||||
|
||||
namespace db_util
|
||||
{
|
||||
enum // Driver type
|
||||
{
|
||||
DBDRIVER_ODBC_DBASE = 533,
|
||||
DBDRIVER_ODBC_EXCEL = 790,
|
||||
DBDRIVER_ODBC_ACCESS = 25,
|
||||
DBDRIVER_ODBC_VFDB,
|
||||
DBDRIVER_ODBC_VFTABLE,
|
||||
DBDRIVER_FILE_SQLITE = 1000,
|
||||
};
|
||||
typedef struct _table_fields
|
||||
{
|
||||
wchar_t name[MAX_TABLE_FIELD_NAME_LEN];
|
||||
VARIANT default_val; // the field 'type' is defining the field type too.
|
||||
// NOW support VT_BOOL, VT_BSTR, VT_DATE, VT_I1(to VT_I8), VT_R4, VT_R8
|
||||
// VT_DATE use function VariantTimeToSystemTime to convert !!!
|
||||
int length; // 0 is not set, always for TEXT field
|
||||
bool unique;
|
||||
bool not_null;
|
||||
bool primary_key;
|
||||
bool foreign_key;
|
||||
bool use_default_val; // whether use the 'default_val' in table as the field's default value
|
||||
}TBLFLD;
|
||||
|
||||
__declspec(novtable) struct IRecordset : public ref_util::IRef
|
||||
{
|
||||
COM_API_DECLARE(int, get_rows(void)); // get count of records
|
||||
COM_API_DECLARE(int, get_cols(void)); // get count of record fields
|
||||
COM_API_DECLARE(bool, get_value(int row, int col, bool* boolean));
|
||||
COM_API_DECLARE(bool, get_value(int row, int col, int* integer));
|
||||
COM_API_DECLARE(bool, get_value(int row, int col, double* decimal));
|
||||
COM_API_DECLARE(bool, get_value(int row, int col, wchar_t* buf, int* words/*[in] - words in buf; [out] - real length of the value. you should provide greater buffer if it was greater than in*/));
|
||||
COM_API_DECLARE(bool, get_value(int row, int col, inter_module_data::set_data set_val/*data: pointed to an unicode string*/, void* param));
|
||||
};
|
||||
|
||||
__declspec(novtable) struct IDatabase : public ref_util::IRef
|
||||
{
|
||||
COM_API_DECLARE(int, open(const wchar_t* db_name, const wchar_t* user_name = 0, const wchar_t* password = 0));
|
||||
COM_API_DECLARE(int, create_table(const wchar_t* table_name, db_util::TBLFLD* fields, int fields_num, int *composed_primary_key_index = NULL));
|
||||
COM_API_DECLARE(int, close(void));
|
||||
COM_API_DECLARE(int, execute_sql(const wchar_t* sql, IRecordset** record = 0));
|
||||
COM_API_DECLARE(int, get_error_msg(inter_module_data::set_data set_msg/*data: pointed to an unicode string*/, void* param)); // return error code
|
||||
};
|
||||
|
||||
// exports ...
|
||||
PORT_API(bool) add_database(const wchar_t* db_name, const wchar_t* db_file, int driver_type);
|
||||
PORT_API(bool) del_database(const wchar_t* db_name, int driver_type = DBDRIVER_ODBC_ACCESS);
|
||||
PORT_API(IDatabase*) create_database_instance(int driver_type = DBDRIVER_ODBC_ACCESS);
|
||||
PORT_API(bool) create_table_sql(const wchar_t* table_name, TBLFLD* fields, int fields_num
|
||||
, inter_module_data::set_data set_msg/*data: pointed to an unicode string*/, void* param
|
||||
, int *composed_primary_key_index = NULL); // -1 is over
|
||||
};
|
||||
|
|
@ -0,0 +1,230 @@
|
|||
// folder_util.h : include utilities for manage folders
|
||||
//
|
||||
// Author: Gongbing
|
||||
//
|
||||
// Date: 2016-09-21
|
||||
|
||||
#pragma once
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <list>
|
||||
#ifndef _INCLUDED_REF_
|
||||
#define _INCLUDED_REF_
|
||||
#include "../ref/ref.h"
|
||||
#endif
|
||||
|
||||
namespace file_util
|
||||
{
|
||||
// 1 - all paths returned by these apis ended with '\\'
|
||||
typedef struct _path_file
|
||||
{
|
||||
wchar_t path[MAX_PATH];
|
||||
}PATHFILE, *LPPATHFILE;
|
||||
|
||||
enum file_coding
|
||||
{
|
||||
FILE_CODING_ANSI = 1,
|
||||
FILE_CODING_UTF8,
|
||||
FILE_CODING_UNICODE,
|
||||
};
|
||||
__declspec(novtable) struct IFileFinder : public ref_util::IRef
|
||||
{
|
||||
// found_file: to receive the found file with full path
|
||||
// NOTE: child folder will always be in the found queue wherever you given the 'mark' !!!
|
||||
// filter '*.*' will not match the file which without extension, so use '*' as default filter for mark
|
||||
COM_API_DECLARE(int, find_first(const wchar_t* dir, LPPATHFILE found_file, const wchar_t* mark = L"*", bool recursive = true, bool depth_first = true, bool ignore_dot_folder = true));
|
||||
COM_API_DECLARE(int, find_next(LPPATHFILE found_file));
|
||||
COM_API_DECLARE(int, current_file_attr(WIN32_FILE_ATTRIBUTE_DATA* attr)); // return file attributes, -1 is error
|
||||
COM_API_DECLARE(int, current_root(LPPATHFILE root)); // root: full path with last '\\' of current finding path
|
||||
COM_API_DECLARE(int, stop_find(void));
|
||||
|
||||
COM_API_DECLARE(bool, is_current_folder(void));
|
||||
};
|
||||
__declspec(novtable) struct ISimpleShareMemory : public ref_util::IRef
|
||||
{
|
||||
// for monitor using, called should before write_result
|
||||
COM_API_DECLARE(int, wait_result(const wchar_t* id, inter_module_data::set_data notify, void* notify_param, DWORD wait_milliseconds = -1, size_t max_size = -1/*one page*/));
|
||||
|
||||
// for notifier using
|
||||
COM_API_DECLARE(int, write_result(const wchar_t* id, const char* data, size_t data_bytes));
|
||||
};
|
||||
__declspec(novtable) struct IGroupFile : public ref_util::IRef // to write grp_0000.txt, grp_0001.txt, ... files
|
||||
{
|
||||
COM_API_DECLARE(int, set_read_param(inter_module_data::set_data set_d, file_coding fc = FILE_CODING_ANSI));
|
||||
COM_API_DECLARE(int, to_line(int line/*ZERO-based*/, int file_ind = -1)); // locate in read, return ERROR_SUCCESS in success
|
||||
COM_API_DECLARE(int, read_line(void* param, bool next = true)); // param is used in the set_d callback; get the first line if next was true
|
||||
COM_API_DECLARE(int, write(const char* data, size_t len));
|
||||
COM_API_DECLARE(int, next_file(void));
|
||||
COM_API_DECLARE(DWORD, cur_size(void));
|
||||
COM_API_DECLARE(DWORD, cur_index(void)); // return current file index
|
||||
COM_API_DECLARE(DWORD, cur_line(void)); // return current line in file
|
||||
};
|
||||
__declspec(novtable) struct IOvlHandler : public ref_util::IRef
|
||||
{
|
||||
COM_API_DECLARE(long, on_data_arrived(const char* data, size_t bytes, void* user_key)); // return how many bytes used, -1 to stop receiving !!!
|
||||
COM_API_DECLARE(bool, on_data_sent(char* data, size_t bytes, size_t data_buf_len/*for reuse inner_buffer*/, void* user_key)); // return whether to keep the data buffer in use. true - use again, false - default value, should free it
|
||||
COM_API_DECLARE(void, on_error(int err));
|
||||
};
|
||||
__declspec(novtable) struct IPipe : public ref_util::IRef
|
||||
{
|
||||
COM_API_DECLARE(int, read(void)); // data returned by IOvlHandler::on_data_arrived
|
||||
COM_API_DECLARE(int, write(const char* data, size_t bytes, bool inner_buf/*whether the 'data' is returned by get_write_buf*/));
|
||||
COM_API_DECLARE(int, close(void));
|
||||
|
||||
COM_API_DECLARE(char*, get_write_buf(size_t bytes));
|
||||
COM_API_DECLARE(void, free_got_write_buf(void* buf/*returned by get_write_buf*/));
|
||||
};
|
||||
|
||||
PORT_API(int) get_special_folder(int clsidl, LPPATHFILE path);
|
||||
PORT_API(int) desktop(bool current_user, LPPATHFILE path);
|
||||
PORT_API(int) start_menu(bool current_user, LPPATHFILE path);
|
||||
PORT_API(int) start_menu_program(bool current_user, LPPATHFILE path);
|
||||
PORT_API(int) start_menu_startup(bool current_user, LPPATHFILE path);
|
||||
PORT_API(int) start_menu_recently(LPPATHFILE path);
|
||||
PORT_API(int) application_data(bool current_user, LPPATHFILE path);
|
||||
PORT_API(int) my_documents(bool current_user, LPPATHFILE path);
|
||||
PORT_API(int) self_path(LPPATHFILE path);
|
||||
PORT_API(int) local_application_data(LPPATHFILE path);
|
||||
PORT_API(int) program_files(LPPATHFILE path);
|
||||
PORT_API(int) windows(LPPATHFILE path);
|
||||
PORT_API(int) system(LPPATHFILE path);
|
||||
PORT_API(int) start_menu_program(LPPATHFILE path);
|
||||
PORT_API(int) quick_launch(bool current_user, LPPATHFILE path, LPPATHFILE path_pin = NULL/*full path*/);
|
||||
PORT_API(int) temporary_file(LPPATHFILE path, const wchar_t* prefix = NULL);
|
||||
PORT_API(int) get_currentLoginUser_AppdataPath(LPPATHFILE path);//add by weidongli on 2019-6-3
|
||||
|
||||
PORT_API(void) simplify_path(wchar_t* path, size_t path_buf_len = 0/*as lstrlenW(path) + 1*/);
|
||||
PORT_API(void) to_absolute_path(LPPATHFILE path); // convert './', '%WINDOWS%', '%SYSTEM%', ... to absolute path
|
||||
PORT_API(void) to_relative_path(const wchar_t* path_file_base, const wchar_t* path_file_tobe, LPPATHFILE rel_path);
|
||||
PORT_API(void) to_known_path(LPPATHFILE path); // convert absolute path to './', '%WINDOWS%', '%SYSTEM%', ...
|
||||
PORT_API(void) append_name(const wchar_t* path_file, const wchar_t* append, LPPATHFILE result); // to insert string 'append' before extension name
|
||||
PORT_API(bool) is_file_existing(const wchar_t* path_file);
|
||||
PORT_API(bool) is_valid_file_name_character(wchar_t file_name_char);
|
||||
PORT_API(int) force_rename_file(const wchar_t* from, const wchar_t* to);
|
||||
PORT_API(int) force_copy_file(const wchar_t* from, const wchar_t* to);
|
||||
PORT_API(int) force_move_file(const wchar_t* from, const wchar_t* to);
|
||||
PORT_API(int) force_delete_file(const wchar_t* file);
|
||||
PORT_API(int) force_create_file(const wchar_t* path_file, HANDLE* ret, DWORD acc = GENERIC_WRITE | GENERIC_READ, DWORD share = 0, DWORD method = CREATE_ALWAYS
|
||||
, DWORD attr = FILE_ATTRIBUTE_NORMAL, LPSECURITY_ATTRIBUTES psa = NULL);
|
||||
PORT_API(int) force_create_folder(const wchar_t* path_folder, SECURITY_ATTRIBUTES* psa = NULL, bool default_psa = true);
|
||||
PORT_API(bool) initialize_commonplace_security(SECURITY_ATTRIBUTES* psa);
|
||||
PORT_API(bool) is_valid_path(const wchar_t* path);
|
||||
PORT_API(bool) is_dir(DWORD attr);
|
||||
PORT_API(bool) is_dir(const wchar_t* path);
|
||||
PORT_API(int) get_file_attributes(const wchar_t* path_file, WIN32_FILE_ATTRIBUTE_DATA* attr);
|
||||
PORT_API(bool) get_file_version(const wchar_t* path_file, WORD* lpver_hh, WORD* lpver_hl, WORD* lpver_lh, WORD* lpver_ll, bool file_ver = true/*false is product version*/);
|
||||
PORT_API(UINT64) get_file_size(const wchar_t* path_file);
|
||||
PORT_API(UINT64) get_disk_available_space(const wchar_t* disk_path);
|
||||
|
||||
// when return false, 'err' can be:
|
||||
//
|
||||
// 1: ERROR_DISK_FULL - the free space in 'disk' is not enough
|
||||
//
|
||||
// 2: ERROR_FILE_SYSTEM_LIMITATION - 'bytes' exceedes the maximum of the file-system's limitation
|
||||
//
|
||||
PORT_API(bool) is_disk_space_enough_for_single_file(const wchar_t* disk, UINT64 bytes, int* err = NULL);
|
||||
PORT_API(bool) is_parent_path(const wchar_t* path_to_check, const wchar_t* file); // to check whether the path 'path_to_check' is the parent path of 'file'
|
||||
PORT_API(int) parent_folder(const wchar_t* path_file, LPPATHFILE path); // without last '\\'
|
||||
PORT_API(int) common_parent_folder(const wchar_t* path_file1, const wchar_t* path_file2, LPPATHFILE parent);
|
||||
PORT_API(int) file_name(const wchar_t* path_file, LPPATHFILE path, bool with_ext = NULL);
|
||||
PORT_API(int) file_extension(const wchar_t* path_file, LPPATHFILE path); // without '.'
|
||||
|
||||
PORT_API(int) load_file(const wchar_t* file, inter_module_data::set_data result, void* param);
|
||||
PORT_API(int) save_2_file(const char* data, size_t len, const wchar_t* file);
|
||||
PORT_API(void*) map_file_to_memory(const wchar_t* path_file, bool read_only = true, DWORD expand_size = 0, HANDLE *file_handle = NULL, HANDLE *map_handle = NULL);
|
||||
|
||||
// clipboard
|
||||
PORT_API(int) set_clipboard(const void* data, size_t bytes, int format = CF_TEXT, HWND owner = NULL);
|
||||
PORT_API(int) set_clipboard_directly(HANDLE data, int format = CF_TEXT, HWND owner = NULL);
|
||||
PORT_API(int) get_clipboard(void* buf, size_t* bytes/*[in]-bytes of buf, [out]-content bytes in clipboard*/, int format = CF_TEXT, HWND owner = NULL);
|
||||
|
||||
// parameter of result:
|
||||
//
|
||||
// data: real data of the clipboard format
|
||||
//
|
||||
// len: bytes of the data
|
||||
//
|
||||
// total: clipboard fromat, support CF_TEXT - (char*)data
|
||||
// CF_UNICODETEXT - (wchar_t*)data
|
||||
// CF_BITMAP - 'data' contains contents of PNG file
|
||||
// CF_DIB - 'data' contains contents of BMP file
|
||||
// CF_HDROP - (wchar_t*)data, copying files list, separated by "\r\n"
|
||||
//
|
||||
// flag: DATA_FLAG_FINAL
|
||||
//
|
||||
// param: same as 'user'
|
||||
//
|
||||
PORT_API(int) get_clipboard(inter_module_data::set_data result, void* user);
|
||||
|
||||
PORT_API(bool) browser_file(HWND owner, LPPATHFILE file, const wchar_t *filter = L"All Files(*.*)\0\0", bool open = true, const wchar_t* title = NULL, WNDPROC cust_proc = NULL, LPARAM proc_param = NULL);
|
||||
|
||||
// function: monitor file & folder
|
||||
//
|
||||
// path: full path, can be a folder or a file
|
||||
//
|
||||
// mask: FILE_NOTIFY_CHANGE_FILE_NAME FILE_NOTIFY_CHANGE_DIR_NAME FILE_NOTIFY_CHANGE_ATTRIBUTES FILE_NOTIFY_CHANGE_SIZE FILE_NOTIFY_CHANGE_LAST_WRITE FILE_NOTIFY_CHANGE_LAST_ACCESS FILE_NOTIFY_CHANGE_CREATION FILE_NOTIFY_CHANGE_SECURITY
|
||||
//
|
||||
// result: data - (const wchar_t*)path_file_name
|
||||
// len - bytes of data
|
||||
// total - unused
|
||||
// flag - DATA_FLAG_FINAL
|
||||
// param - the same as 'param' of this function
|
||||
//
|
||||
// return: monitor key , NULL if failed. should call un_monitor to free the return value
|
||||
//
|
||||
PORT_API(void*) monitor_files(const wchar_t* path, int mask, bool sub_dir, inter_module_data::set_data result, void* param);
|
||||
PORT_API(void) un_monitor(void* key);
|
||||
PORT_API(void) display_file_in_explorer(const wchar_t* path_file);
|
||||
PORT_API(UINT64) get_filesystem_maximum_file_bytes(const wchar_t* disk, wchar_t* fs_name = NULL/*provids NULL or not less than "MAX_PATH + 2"*/);
|
||||
|
||||
PORT_API(IFileFinder*) create_file_finder(void);
|
||||
PORT_API(ISimpleShareMemory*) create_simple_share_memory(void);
|
||||
PORT_API(IGroupFile*) create_group_files(const wchar_t* first_file, bool for_read, int sn_digits = 4, DWORD limit_bytes = 0); // the limit_bytes would be ommited if fro_read was true
|
||||
|
||||
PORT_API(IPipe*) open_pipe(IOvlHandler* handler, const wchar_t* name);
|
||||
}
|
||||
|
||||
#define STR_SIMPLIFY_PATH(str) \
|
||||
{ \
|
||||
file_util::PATHFILE pf = { 0 }; \
|
||||
wcscpy_s(pf.path, _countof(pf.path) - 1, (str).c_str()); \
|
||||
file_util::simplify_path(pf.path); \
|
||||
(str) = pf.path; \
|
||||
}
|
||||
|
||||
#define STR_TO_ABSOLUTE_PATH(str) \
|
||||
{ \
|
||||
file_util::PATHFILE pf = { 0 }; \
|
||||
wcscpy_s(pf.path, _countof(pf.path) - 1, (str).c_str()); \
|
||||
file_util::to_absolute_path(&pf); \
|
||||
(str) = pf.path; \
|
||||
}
|
||||
|
||||
#define STR_TO_KNOWN_PATH(str) \
|
||||
{ \
|
||||
file_util::PATHFILE pf = { 0 }; \
|
||||
wcscpy_s(pf.path, _countof(pf.path) - 1, (str).c_str()); \
|
||||
file_util::to_known_path(&pf); \
|
||||
(str) = pf.path; \
|
||||
}
|
||||
|
||||
#define STR_PARENT_FOLDER(str) \
|
||||
{ \
|
||||
file_util::PATHFILE pf = { 0 }; \
|
||||
file_util::parent_folder((str).c_str(), &pf); \
|
||||
(str) = pf.path; \
|
||||
}
|
||||
|
||||
#define STR_FILE_NAME(str, with_ext) \
|
||||
{ \
|
||||
file_util::PATHFILE pf = { 0 }; \
|
||||
file_util::file_name((str).c_str(), &pf, with_ext); \
|
||||
(str) = pf.path; \
|
||||
}
|
||||
|
||||
#define STR_FILE_EXTENSION(str) \
|
||||
{ \
|
||||
file_util::PATHFILE pf = { 0 }; \
|
||||
file_util::file_extension((str).c_str(), &pf); \
|
||||
(str) = pf.path; \
|
||||
}
|
|
@ -0,0 +1,75 @@
|
|||
// log.h : log utility
|
||||
//
|
||||
// Author: Gongbing
|
||||
//
|
||||
// Create: 2019-08-07
|
||||
|
||||
#pragma once
|
||||
#ifndef _INCLUDED_REF_
|
||||
#define _INCLUDED_REF_
|
||||
#include "../ref/ref.h"
|
||||
#endif
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
// level
|
||||
enum _log_level
|
||||
{
|
||||
LOG_LEVEL_ALL = 1,
|
||||
LOG_LEVEL_PART,
|
||||
LOG_LEVEL_IMPORTANT,
|
||||
LOG_LEVEL_VERY_IMPORTANT,
|
||||
LOG_LEVEL_NONE = INT_MAX,
|
||||
};
|
||||
enum _log_type
|
||||
{
|
||||
LOG_TYPE_NONE,
|
||||
LOG_TYPE_CONSOLE_OUT,
|
||||
LOG_TYPE_OUTPUTDBG,
|
||||
LOG_TYPE_WRITE_FILE,
|
||||
LOG_TYPE_USER_CUSTOM,
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
// macros
|
||||
#ifndef UNICODE_STR
|
||||
#define _TO_UNICODE(str) L##str
|
||||
#define UNICODE_STR(str) _TO_UNICODE(str)
|
||||
#define MAKE_UNICODE(str) UNICODE_STR(str)
|
||||
#endif
|
||||
|
||||
#define LOG_API_PROTO(name) void(__stdcall *name)(const wchar_t* info, size_t words, void* user)
|
||||
#define LOG_API_INSTANCE(name) void __stdcall name(const wchar_t* info, size_t words, void* user)
|
||||
|
||||
namespace log_util
|
||||
{
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
// log interface
|
||||
typedef LOG_API_PROTO(real_log);
|
||||
|
||||
__declspec(novtable) struct ILog : public ref_util::IRef
|
||||
{
|
||||
// param0: (const wchar_t*)path file when type is LOG_TYPE_WRITE_FILE, real_log when type is LOG_TYPE_USER_CUSTOM. otherwise always be ZERO
|
||||
// param1: for parameter 'user' of real_log when type is LOG_TYPE_USER_CUSTOM, otherwise always be ZERO
|
||||
COM_API_DECLARE(int, set_log_level(_log_level level));
|
||||
COM_API_DECLARE(int, set_log_type(_log_type type, void* param0 = NULL, void* param1 = NULL)); // return type after this oper
|
||||
COM_API_DECLARE(void, write_log(const wchar_t* info, size_t bytes, _log_level level));
|
||||
COM_API_DECLARE(bool, is_level_enabled(_log_level level)); // whether the message of level can be logged
|
||||
COM_API_DECLARE(void, set_prefix(const wchar_t* pref)); // default is without prefix
|
||||
COM_API_DECLARE(void, enable_time_stamp(bool enable)); // default is without timestamp
|
||||
};
|
||||
|
||||
// use inner log_util
|
||||
// param0: (const wchar_t*)path file when type is LOG_TYPE_WRITE_FILE, real_log when type is LOG_TYPE_USER_CUSTOM. otherwise always be ZERO
|
||||
// param1: for parameter 'user' of real_log when type is LOG_TYPE_USER_CUSTOM, otherwise always be ZERO
|
||||
PORT_API(ILog*) start_log(_log_type type = LOG_TYPE_OUTPUTDBG, _log_level level = LOG_LEVEL_ALL, void* param0 = NULL, void* param1 = NULL);
|
||||
PORT_API(ILog*) get_cur_log_util(void);
|
||||
|
||||
// set an external log_util, NULL to stop current log, will invoke log->add_ref() if log is valid
|
||||
PORT_API(void) set_log_util(ILog* log);
|
||||
|
||||
|
||||
// invoke log
|
||||
PORT_API(bool) is_logging_enable(_log_level level);
|
||||
PORT_API_CALL(void, __cdecl) log(_log_level level, size_t estimate_bytes, const wchar_t* format, ...);
|
||||
PORT_API_CALL(void, __cdecl) log(_log_level level, size_t estimate_bytes, const char* format, ...);
|
||||
}
|
|
@ -0,0 +1,259 @@
|
|||
// net_app.h : network applications
|
||||
//
|
||||
// Author: Gongbing
|
||||
//
|
||||
// Create: 2019-07-22
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "net_base.h"
|
||||
|
||||
//typedef struct ip_option_information {
|
||||
// UCHAR Ttl;
|
||||
// UCHAR Tos;
|
||||
// UCHAR Flags;
|
||||
// UCHAR OptionsSize;
|
||||
// PUCHAR OptionsData;
|
||||
//} IP_OPTION_INFORMATION, *PIP_OPTION_INFORMATION;
|
||||
//typedef struct icmp_echo_reply {
|
||||
// struct sockaddr_in Address;
|
||||
// ULONG Status;
|
||||
// ULONG RoundTripTime;
|
||||
// USHORT DataSize;
|
||||
// USHORT Reserved;
|
||||
// PVOID Data;
|
||||
// struct ip_option_information Options;
|
||||
//} ICMP_ECHO_REPLY, *PICMP_ECHO_REPLY;
|
||||
//#define IPAddr struct sockaddr_in
|
||||
|
||||
namespace net_app
|
||||
{
|
||||
enum web_format
|
||||
{
|
||||
WEB_FMT_UNKNOWN = 0,
|
||||
WEB_FMT_STREAM, // binary stream ...
|
||||
WEB_FMT_ANSI,
|
||||
WEB_FMT_UTF8,
|
||||
WEB_FMT_UNICODE,
|
||||
WEB_FMT_DECIDE_BY_CONTENT, // text/html should decide by content
|
||||
};
|
||||
__declspec(novtable) struct IAcceptClient : public ref_util::IRef
|
||||
{
|
||||
COM_API_DECLARE(long, client_accepted(SOCKET s, const char* ip, unsigned port));
|
||||
COM_API_DECLARE(void, on_server_exited(unsigned exit_code));
|
||||
};
|
||||
__declspec(novtable) struct ITcpSvrSocket : public ref_util::IRef
|
||||
{
|
||||
COM_API_DECLARE(long, listen_at(unsigned short port, const char* ip = NULL/*INADDR_ANY*/, bool reuse_addr = true));
|
||||
COM_API_DECLARE(long, stop(void));
|
||||
COM_API_DECLARE(long, listen_port(void));
|
||||
COM_API_DECLARE(SOCKET, listen_socket(void));
|
||||
};
|
||||
__declspec(novtable) struct IAsyncTcpSvr : public ITcpSvrSocket
|
||||
{
|
||||
// following two functions return ERROR_FILE_HANDLE_REVOKED if the peer is used in transmit file
|
||||
COM_API_DECLARE(long, read_from_peer(void* peer_key)); // DO NOT call this until you stop the read with return -1 in IPeerManager::on_data_arrived, server will invoke this automately
|
||||
COM_API_DECLARE(long, write_2_peer(void* peer_key, const char* data, size_t data_len, bool inner_buffer = false/*whether the data buffer is returned by request_sent_buffer, if failed and iner_buffer is 'true', the 'data' would be freed !!!*/));
|
||||
COM_API_DECLARE(long, close_peer(void* peer_key, int* peer_ref));
|
||||
COM_API_DECLARE(long, set_peer_data(void* peer_key, int index, void* data));
|
||||
COM_API_DECLARE(long, get_peer_data(void* peer_key, int index, void** data));
|
||||
COM_API_DECLARE(long, peer_address(void* peer_key, char ip_buf[IP_BUF_LEN], unsigned* port));
|
||||
COM_API_DECLARE(long, send_file_content(void* peer_key, HANDLE file)); // NOTE: this method only used for transmitting file content, all pre- or post-task should done by caller !!!
|
||||
COM_API_DECLARE(size_t, io_buffer_size(bool in_buf));
|
||||
|
||||
// add on 2017-08-26 for add an existing connecting into client queue (DO NOT add it which is already in queue !!!)
|
||||
// after this, you should operate the peer in IPeerManager.
|
||||
// following two apis return peer_key
|
||||
COM_API_DECLARE(void*, add_2_client_queue(SOCKET s));
|
||||
COM_API_DECLARE(void*, create_async_tcp_client(const char* ip, unsigned short port, unsigned conn_timeout_seconds = 0, const char* reuse_ip = NULL, unsigned reuse_port = 0));
|
||||
|
||||
// for reducing the times of memory copying, request memory from inner - added on 2019-07-28
|
||||
COM_API_DECLARE(char*, request_sent_buffer(size_t bytes));
|
||||
COM_API_DECLARE(void, free_unsent_buffer(void* buf)); // free the returned value of request_sent_buffer which has NOT called write_2_peer with inner_buffer is 'true' yet!!!
|
||||
};
|
||||
__declspec(novtable) struct IAsyncTcpHatcher : public ref_util::IRef
|
||||
{
|
||||
COM_API_DECLARE(void*, connect(const char* ip, int port, const char* reuse_ip = NULL, unsigned reuse_port = 0));
|
||||
COM_API_DECLARE(int, write(void* client, const char* buf, size_t data_len, bool inner_buf));
|
||||
//COM_API_DECLARE(void*, add_2_client_queue(SOCKET s));
|
||||
COM_API_DECLARE(int, close_client(void* client));
|
||||
COM_API_DECLARE(int, destroy(void));
|
||||
COM_API_DECLARE(long, send_file_content(void* client, HANDLE file)); // NOTE: this method only used for transmitting file content, all pre- or post-task should done by caller !!!
|
||||
COM_API_DECLARE(bool, get_address(void* client, char* ip/*at least with 40 bytes!!!*/, int* port, bool svr = true));
|
||||
};
|
||||
__declspec(novtable) struct IAsyncTcpHandler : public ref_util::IRef
|
||||
{
|
||||
COM_API_DECLARE(long, on_data_arrived(void* client, const char* data, size_t data_len, bool* rcv_file/*[in] - whether in receiving file for transmit_file, [out] - stop(true) or continue(true) receiving file*/)); // return how many bytes used, -1 to stop receiving !!!
|
||||
COM_API_DECLARE(bool, on_data_sent(void* client, char* data, size_t data_len, size_t data_buf_len/*for reuse inner_buffer*/)); // return whether to keep the data buffer in use. true - use again, false - default value, should free it
|
||||
COM_API_DECLARE(void, on_closed(void* client, int err));
|
||||
COM_API_DECLARE(void, on_file_content_sent(void* client, HANDLE file, ULONGLONG bytes, int error)); // response for IAsyncTcpSvr::send_file_content
|
||||
};
|
||||
__declspec(novtable) struct IPeerManager : public ref_util::IRef
|
||||
{
|
||||
COM_API_DECLARE(void, on_peer_connected(void* peer_key));
|
||||
COM_API_DECLARE(void, on_server_exited(unsigned exit_code));
|
||||
COM_API_DECLARE(long, on_data_arrived(void* peer_key, const char* data, size_t data_len, bool* rcv_file/*[in] - whether in receiving file for transmit_file, [out] - stop(true) or continue(true) receiving file*/)); // return how many bytes used, -1 to stop receiving !!!
|
||||
COM_API_DECLARE(bool, on_data_sent(void* peer_key, char* data, size_t data_len, size_t data_buf_len/*for reuse inner_buffer*/)); // return whether to keep the data buffer in use. true - use again, false - default value, should free it
|
||||
COM_API_DECLARE(void, on_peer_error(void* peer_key, unsigned err_code));
|
||||
COM_API_DECLARE(void, on_peer_closed(void* peer_key));
|
||||
COM_API_DECLARE(bool, is_peer_timeout(void* peer_key, int elapsed_seconds/*elapsed seconds from last active*/));
|
||||
COM_API_DECLARE(void, on_file_content_sent(void* peer_key, HANDLE file, ULONGLONG bytes, int error)); // response for IAsyncTcpSvr::send_file_content
|
||||
};
|
||||
__declspec(novtable) struct IBlockTcp : public ref_util::IRef
|
||||
{
|
||||
COM_API_DECLARE(SOCKET, attach(SOCKET s));
|
||||
COM_API_DECLARE(SOCKET, detach(void));
|
||||
COM_API_DECLARE(SOCKET, socket_handle(void));
|
||||
COM_API_DECLARE(int, re_connect(const char* dot_ip = NULL, unsigned short port = 0));
|
||||
COM_API_DECLARE(int, set_timeout(unsigned *read_timeout/*milliseconds*/, unsigned *write_timeout/*milliseconds*/));
|
||||
COM_API_DECLARE(int, read(char* buf, size_t buf_len, size_t* read_bytes));
|
||||
COM_API_DECLARE(int, write(const char* buf, size_t data_len, size_t* wrote));
|
||||
COM_API_DECLARE(int, last_error(void));
|
||||
COM_API_DECLARE(long, send_file_content(HANDLE file)); // NOTE: this method only used for transmitting file content, all pre- or post-task should done by caller !!!
|
||||
COM_API_DECLARE(void, get_address(char* ip/*at least with 40 bytes!!!*/, int* port, bool svr = true));
|
||||
COM_API_DECLARE(int, close(void));
|
||||
};
|
||||
|
||||
__declspec(novtable) struct IUdpSvrHandler : public ref_util::IRef
|
||||
{
|
||||
COM_API_DECLARE(size_t,on_udp_data_arrived(const char* data, size_t data_len, const char* ip, unsigned port)); // return used data bytes
|
||||
COM_API_DECLARE(bool, on_udp_data_sent(char* data, size_t data_len, size_t data_buf_len/*for reuse inner_buffer*/, const char* ip, unsigned port)); // return whether to keep the data buffer in use. true - use again, false - default value, should free it
|
||||
COM_API_DECLARE(void, on_udp_server_exit(unsigned err));
|
||||
};
|
||||
__declspec(novtable) struct IUdpServer : public ref_util::IRef
|
||||
{
|
||||
COM_API_DECLARE(int, start(unsigned short port));
|
||||
COM_API_DECLARE(int, send_to(const char* buf, size_t len, const char* ip, unsigned port, bool inner_buffer = false/*whether the data buffer is returned by request_sent_buffer*/));
|
||||
COM_API_DECLARE(int, broad_cast(const char* buf, size_t len, unsigned short port, bool inner_buffer = false, const char* broad_ip_seg = NULL));
|
||||
COM_API_DECLARE(int, stop(void));
|
||||
|
||||
// for reducing the times of memory copying, request memory from inner - added on 2019-07-28
|
||||
COM_API_DECLARE(char*, request_sent_buffer(size_t bytes));
|
||||
COM_API_DECLARE(void, free_unsent_buffer(void* buf)); // free the returned value of request_sent_buffer which has NOT called write_2_peer with inner_buffer is 'true' yet!!!
|
||||
};
|
||||
|
||||
typedef struct _set_cookie // all members and its' buffers will be in the same buffer with the head
|
||||
{
|
||||
char *name;
|
||||
char *val;
|
||||
char *path;
|
||||
char *expire;
|
||||
char *domain;
|
||||
bool http_only;
|
||||
bool https_only; // true - secure 1; false - secure 0
|
||||
}SETCOOKIE, *LPSETCOOKIE;
|
||||
enum _add_head_flag
|
||||
{
|
||||
ADD_HEAD_ADD = 1, // new item added if the key was not existing, or else failed
|
||||
ADD_HEAD_NEW, // new item added however the key is existing already
|
||||
ADD_HEAD_REPLACE, // new item added if the key was not existing, or else replace it with new val
|
||||
ADD_HEAD_APPEND_COMMA, // like ADD_HEAD_REPLACE but append new val to rear with comma(,) if the key was existing
|
||||
ADD_HEAD_APPEND_SEMIC, // like ADD_HEAD_REPLACE but append new val to rear with semicolon(;) if the key was existing
|
||||
};
|
||||
enum _cookie_index
|
||||
{
|
||||
COOKIE_INDEX_ALL = -1,
|
||||
};
|
||||
#ifdef _USE_HTTP_CALLBACK_
|
||||
__declspec(novtable) struct IHttpCallback : public ref_util::IRef
|
||||
{
|
||||
COM_API_DECLARE(void, on_response_header_ok(int response_code, unsigned __int64 cont_len, bool cont_chunked, bool cont_zipped));
|
||||
COM_API_DECLARE(int, on_response_content(const char* content, size_t len)); // return 0 to continue, other to stop
|
||||
COM_API_DECLARE(int, on_url_jump(int jump_code, const char* utf8_new_url)); // return 0 to continue, other to stop
|
||||
};
|
||||
#endif
|
||||
__declspec(novtable) struct IHttp : public ref_util::IRef // all methods are thread unsafe, all history cookies will occur in last request
|
||||
{
|
||||
#ifndef _USE_HTTP_CALLBACK_
|
||||
COM_API_DECLARE(void, set_response_data_callback(inter_module_data::set_data setdata, void* param));
|
||||
#endif
|
||||
COM_API_DECLARE(int, add_header(const char* utf8_key, const char* utf8_val, _add_head_flag flag = ADD_HEAD_REPLACE)); // 0 - ok; ERROR_ALREADY_EXISTS. must call before open_url or post_data
|
||||
COM_API_DECLARE(int, remove_header(const char* utf8_key/*NULL to clear all extra headers*/)); // 0 - ok; ERROR_NOT_FOUND. must call before open_url or post_data
|
||||
COM_API_DECLARE(int, clear_cookie(void)); // all history cookies would be added on the last request, call this to clear all cookies
|
||||
COM_API_DECLARE(int, open_url(const char* url, const char* cookie, const char* agent, bool get = true, const char* content = NULL, size_t content_len = 0));
|
||||
COM_API_DECLARE(int, post_data(const char* url, const char* data, unsigned __int64 data_len, const char* utf8_file_tag, const char* utf8_file_name, const char* cookie, const char* agent));
|
||||
COM_API_DECLARE(int, get_response_code(void));
|
||||
COM_API_DECLARE(int, get_set_cookie(LPSETCOOKIE buf/*format: cookie1\0cookie2\0\0*/, size_t* len/*[in] - bytes of buf, [out] - string length in buf or minimum buffer size if buf was NULL*/
|
||||
, int index = 0/*if index == COOKIE_INDEX_ALL, then return all cookies in ONE string and put it in buf*/)); // 0 - ok; ERROR_NOT_FOUND
|
||||
COM_API_DECLARE(int, get_jump_url(char* buf, size_t* len/*[in] - bytes of buf, [out] - string length in buf or minimum buffer size if buf was NULL*/)); // 0 - ok; ERROR_NOT_FOUND
|
||||
COM_API_DECLARE(int, get_response_all_header(char* buf, size_t* len/*[in] - bytes of buf, [out] - string length in buf or minimum buffer size if buf was NULL*/)); // 0 - ok; ERROR_NOT_FOUND
|
||||
COM_API_DECLARE(unsigned __int64, get_response_content_length(void));
|
||||
COM_API_DECLARE(enum web_format, get_content_format(void));
|
||||
COM_API_DECLARE(void, close(void));
|
||||
};
|
||||
|
||||
PORT_API(ITcpSvrSocket*) create_tcp_server_socket(IAcceptClient* ac, bool ipv6 = false);
|
||||
enum _svr_ip_type
|
||||
{
|
||||
SVR_TYPE_NONE = 0,
|
||||
SVR_TYPE_IPV4_ONLY = 1,
|
||||
SVR_TYPE_IPV6_ONLY,
|
||||
SVR_TYPE_IPV4_AND_IPV6,
|
||||
};
|
||||
PORT_API(IAsyncTcpSvr*) create_async_tcp_server(IPeerManager* peer, _svr_ip_type svr_type = SVR_TYPE_IPV4_ONLY, int buf_size_in = 0, int buf_size_out = 0, int desired_threads = 0, unsigned allow_cpu_mask = -1);
|
||||
|
||||
// for blocking tcp would blocks following operation, this function will set r/w timeout to be 9 seconds;
|
||||
PORT_API(IBlockTcp*) connect_2_server(const char* ip, unsigned short port, unsigned conn_timeout_seconds = 0, const char* reuse_ip = NULL, unsigned reuse_port = 0);
|
||||
PORT_API(IBlockTcp*) connect_2_server_by_host(const char* host, unsigned short port, unsigned conn_timeout_seconds = 0, const char* reuse_ip = NULL, unsigned reuse_port = 0);
|
||||
PORT_API(IAsyncTcpHatcher*) create_async_tcp_hatcher(IAsyncTcpHandler* handler);
|
||||
PORT_API(IUdpServer*) create_udp_server(IUdpSvrHandler* handler, _svr_ip_type type = SVR_TYPE_IPV4_ONLY);
|
||||
#ifdef _USE_HTTP_CALLBACK_
|
||||
PORT_API(IHttp*) create_http(IHttpCallback* cb);
|
||||
#else
|
||||
PORT_API(IHttp*) create_http(void);
|
||||
#endif
|
||||
|
||||
// trace route by ICMPxxx function, to be completed ...
|
||||
// parameter of result:
|
||||
// data: ip, NULL when over
|
||||
// len: milliseconds, -1 is timeout, or error code when over
|
||||
// total: hops count, unused when over
|
||||
// flag: DATA_FLAG_FINAL in hops, DATA_FLAG_INSTAR in beginning information, and DATA_FLAG_OVER for over
|
||||
// param: 'param'
|
||||
PORT_API(int) trace_route(const char* www, inter_module_data::set_data result, void* param, int max_hops = 30);
|
||||
PORT_API(int) get_default_gateway(char gateway[IP_BUF_LEN]);
|
||||
PORT_API(int) get_mac(const char* dot_ip, char *mac, int* mac_bytes/*in - bytes of 'mac', out - result bytes in 'mac'*/);
|
||||
|
||||
// enum all ips in given subnet ...
|
||||
// parameter of result:
|
||||
// data: ip, NULL when over
|
||||
// len: bytes of 'data'
|
||||
// total: unused
|
||||
// flag: DATA_FLAG_FINAL
|
||||
// param: same as 'param'
|
||||
PORT_API(int) enum_all_ips_in_subnet(const char* dot_ip, const char* dot_subnet, inter_module_data::set_data result, void* param);
|
||||
|
||||
PORT_API(int) parse_cookie(const char* cookie_str, LPSETCOOKIE lpcookie, size_t size/*size of lpcookie must great than sizeof(SETCOOKIE) + lstrlenA(cookie_str) * 2*/);
|
||||
PORT_API(int) cookie_for_url(LPSETCOOKIE lpcookie, const char* url, char* cookie, size_t* len);
|
||||
PORT_API(int) http_post(const char* url, const char* content, size_t length, const char* utf8_file_tag, const char* utf8_file_name = NULL, const char* cookie = NULL, const char* agent = NULL);
|
||||
PORT_API(int) http_download(const char* url, inter_module_data::set_data setdata, void* param, const char* cookie = NULL, const char* agent = NULL, const char* extra_data = 0, size_t extra_data_len = 0);
|
||||
PORT_API(enum web_format) web_content_format(const char* web_cont, size_t bytes, UINT* cp = NULL/*to receive the code page*/);
|
||||
|
||||
// function: send file by 'TransmitFile' for more efficiency, the function is blocked until all content transfered or error happens if parameter 'lpovl' was NULL
|
||||
// file: an openning file handle, suggest use flag with 'FILE_FLAG_SEQUENTIAL_SCAN'
|
||||
// s: an connection socket
|
||||
// packet_size: bytes of every packet
|
||||
// lpovl: asynchronous OVERLAPPED data. if you bind the socket on an IOCP, the IOCP will receive a write complete notify
|
||||
// pre: the content sent to remote before the file content
|
||||
// pre_bytes: bytes of 'pre' content
|
||||
// rear: the content sent to remote after all file contents transfered
|
||||
// rear_bytes: bytes of 'rear' content
|
||||
//
|
||||
// return: error code.
|
||||
PORT_API(int) transmit_file(HANDLE file, SOCKET s, size_t bytes_to_sent = 0/*max up to INT_MAX - 1*/, size_t packet_size = 4096, LPOVERLAPPED lpovl = NULL, void* pre = NULL, size_t pre_bytes = 0, void* rear = NULL, size_t rear_bytes = 0);
|
||||
PORT_API(HANDLE) open_file_for_sending(const wchar_t* local_file);
|
||||
|
||||
enum
|
||||
{
|
||||
NIC_CHANGED = 0, // MibParameterNotification,
|
||||
NIC_ADDED = 1, // MibAddInstance,
|
||||
NIC_DELETED = 2, // MibDeleteInstance,
|
||||
};
|
||||
// parameter of notify:
|
||||
// data: ip, this is the final ip
|
||||
// len: index of network interface
|
||||
// total_len: NIC_CHANGED - parameter changed; NIC_ADDED - new NIC added; NIC_DELETED - NIC deleted
|
||||
// flag: be inter_module_data::DATA_FLAG_FINAL always
|
||||
PORT_API(void*) reg_interface_notification(inter_module_data::set_data notify, void* param); // free the returned object by unreg_interface_notification
|
||||
PORT_API(void) unreg_interface_notification(void* key/*returned by reg_interface_notification()*/);
|
||||
}
|
|
@ -0,0 +1,332 @@
|
|||
// net_base.h : network utility
|
||||
//
|
||||
// Author: Gongbing
|
||||
//
|
||||
// Create: 2019-07-18
|
||||
|
||||
#pragma once
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
// module type and global definition
|
||||
#ifndef _INCLUDED_REF_
|
||||
#define _INCLUDED_REF_
|
||||
#include "../ref/ref.h"
|
||||
#endif
|
||||
#ifndef SOCKET
|
||||
#define SOCKET unsigned int
|
||||
#endif
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
// import headers
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
// structures && enumerations
|
||||
#define IP_BUF_LEN 48
|
||||
|
||||
typedef struct _ip_info
|
||||
{
|
||||
int index; // NIC index
|
||||
char ip[IP_BUF_LEN];
|
||||
char gateway[IP_BUF_LEN];
|
||||
char subnet[IP_BUF_LEN];
|
||||
}IPINFO, *LPIPINFO;
|
||||
|
||||
enum firewall_port_cat
|
||||
{
|
||||
FWPORT_UNKNOWN = 0,
|
||||
FWPORT_TCP,
|
||||
FWPORT_UDP,
|
||||
FWPORT_ALL,
|
||||
};
|
||||
|
||||
#pragma pack(push)
|
||||
#pragma pack(1)
|
||||
typedef struct _ip_pack
|
||||
{
|
||||
// all in net-sn, i.e. big-endian
|
||||
unsigned long ver : 4; // version of the ip-datagram
|
||||
unsigned long head_len : 4; // length in four-bytes of this head, unit as long
|
||||
unsigned long service : 8; // service type ...
|
||||
unsigned long total_len : 16; // total bytes of this datagram, include this header
|
||||
unsigned long mark : 16;
|
||||
unsigned long flag : 3;
|
||||
unsigned long offset : 13; // offet of part data in whole data
|
||||
unsigned long ttl : 8; // living time, as hops
|
||||
unsigned long protocol : 8; // protocol type, see IPPROTO_ICMP ...
|
||||
unsigned long checksum : 16; //
|
||||
unsigned long src_ip;
|
||||
unsigned long dst_ip;
|
||||
unsigned char head_data[0];
|
||||
|
||||
void from_buffer(const unsigned char* buf)
|
||||
{
|
||||
ver = *buf >> 4;
|
||||
head_len = *buf++;
|
||||
service = *buf++;
|
||||
total_len = *buf++;
|
||||
total_len <<= 8;
|
||||
total_len |= *buf++;
|
||||
mark = *buf++;
|
||||
mark <<= 8;
|
||||
mark |= *buf++;
|
||||
flag = *buf >> 5;
|
||||
|
||||
offset = *buf & 0x1f;
|
||||
offset <<= 8;
|
||||
offset |= buf[1];
|
||||
buf += 2;
|
||||
|
||||
ttl = *buf++;
|
||||
protocol = *buf++;
|
||||
checksum = *buf++;
|
||||
checksum <<= 8;
|
||||
checksum |= *buf++;
|
||||
|
||||
src_ip = *buf++;
|
||||
src_ip <<= 8;
|
||||
src_ip |= *buf++;
|
||||
src_ip <<= 8;
|
||||
src_ip |= *buf++;
|
||||
src_ip <<= 8;
|
||||
src_ip |= *buf++;
|
||||
|
||||
dst_ip = *buf++;
|
||||
dst_ip <<= 8;
|
||||
dst_ip |= *buf++;
|
||||
dst_ip <<= 8;
|
||||
dst_ip |= *buf++;
|
||||
dst_ip <<= 8;
|
||||
dst_ip |= *buf++;
|
||||
|
||||
// data, you should ensure enough buffer to contains it !!!
|
||||
int rest = head_len * 4 - sizeof(*this);
|
||||
if (rest > 0)
|
||||
memcpy(head_data, buf, rest);
|
||||
}
|
||||
unsigned long calc_checksum(void)
|
||||
{
|
||||
unsigned long chk = 0;
|
||||
|
||||
// 1 - fixed fields:
|
||||
chk = (ver << 12) | (head_len << 8) | service;
|
||||
chk += total_len;
|
||||
chk += mark;
|
||||
chk += (flag << 13) | offset;
|
||||
chk += (ttl << 8) | protocol;
|
||||
chk += src_ip & 0x0ffff;
|
||||
chk += src_ip >> 16;
|
||||
chk += dst_ip & 0x0ffff;
|
||||
chk += dst_ip >> 16;
|
||||
|
||||
// 2 - appendix data in header:
|
||||
unsigned short *d = (unsigned short*)head_data;
|
||||
int num = (head_len * 4 - sizeof(*this)) / 2;
|
||||
for (int i = 0; i < num; ++i)
|
||||
chk += *d++;
|
||||
|
||||
// 3 - add the overflow of short
|
||||
chk = (chk & 0x0ffff) + (chk >> 16);
|
||||
chk = (chk & 0x0ffff) + (chk >> 16);
|
||||
|
||||
// 4 - NOT
|
||||
checksum = ~chk;
|
||||
|
||||
return checksum;
|
||||
}
|
||||
int to_buffer(unsigned char* buf)
|
||||
{
|
||||
calc_checksum();
|
||||
|
||||
*buf++ = (ver << 4) | head_len;
|
||||
*buf++ = service;
|
||||
*buf++ = total_len >> 8;
|
||||
*buf++ = total_len;
|
||||
*buf++ = mark >> 8;
|
||||
*buf++ = mark;
|
||||
*buf++ = (flag << 5) | (offset >> 8);
|
||||
*buf++ = offset;
|
||||
*buf++ = ttl;
|
||||
*buf++ = protocol;
|
||||
*buf++ = checksum >> 8;
|
||||
*buf++ = checksum;
|
||||
*buf++ = src_ip >> 24;
|
||||
*buf++ = src_ip >> 16;
|
||||
*buf++ = src_ip >> 8;
|
||||
*buf++ = src_ip;
|
||||
*buf++ = dst_ip >> 24;
|
||||
*buf++ = dst_ip >> 16;
|
||||
*buf++ = dst_ip >> 8;
|
||||
*buf++ = dst_ip;
|
||||
|
||||
int rest = head_len * 4 - sizeof(*this);
|
||||
if (rest > 0)
|
||||
memcpy(buf, head_data, rest);
|
||||
|
||||
return head_len * 4;
|
||||
}
|
||||
}IPPACK, *LPIPPACK;
|
||||
|
||||
enum _icmp_type
|
||||
{
|
||||
ICMP_TYPE_TERM_UNREACHABLE = 3, // the terminal is unreachable
|
||||
ICMP_TYPE_RESTRICT_SOURCE,
|
||||
ICMP_TYPE_MODIFY_ROUTER,
|
||||
ICMP_TYPE_TIMEOUT = 11, // when ttl == 0, send back this type by router
|
||||
ICMP_TYPE_INVALID_PARAMETER,
|
||||
|
||||
ICMP_TYPE_ECHO_ANSWER = 0, // answer for query request
|
||||
ICMP_TYPE_ECHO_REQUEST = 8,
|
||||
ICMP_TYPE_TIMESTAMP_REQUEST = 13,
|
||||
ICMP_TYPE_TIMESTAMP_ANSWER,
|
||||
};
|
||||
enum _term_unrechable_code
|
||||
{
|
||||
TERM_UNREACHABLE_NETWORK = 0,
|
||||
TERM_UNREACHABLE_TERMINAL,
|
||||
TERM_UNREACHABLE_PROTOCOL,
|
||||
TERM_UNREACHABLE_PORT,
|
||||
TERM_UNREACHABLE_DATA_SEGMENT, // data should divided into several segments
|
||||
TERM_UNREACHABLE_SOURCE_ROUTER, // source router cannot complete
|
||||
TERM_UNREACHABLE_UNKNOWN_DST_NET, // destination network is unknown
|
||||
TERM_UNREACHABLE_UNKNOWN_TERMINAL,
|
||||
TERM_UNREACHABLE_SOURCE_DISABLED, // source host is disabled
|
||||
TERM_UNREACHABLE_DISABLE_NETWORK, // disabled with network by policy
|
||||
TERM_UNREACHABLE_DISABLE_TERM, // disabled with destion terminal by policy
|
||||
TERM_UNREACHABLE_SERVICE_NETWORK, // network cannot support the service
|
||||
TERM_UNREACHABLE_SERVICE_TERM, // destion terminal cannot support the service
|
||||
TERM_UNREACHABLE_TERM_FILTER, // destion terminal has filter
|
||||
TERM_UNREACHABLE_TERM_PRIORITY, // confilict with priority policy
|
||||
TERM_UNREACHABLE_PRIORITY_DISABLED, //
|
||||
};
|
||||
enum _modi_router_code
|
||||
{
|
||||
MODI_ROUTER_FOR_NETWORK = 0, // modify the router-table for given network
|
||||
MODI_ROUTER_FOR_TERM, // modify the router-table for given terminal
|
||||
MODI_ROUTER_FOR_SERVICE_NETWORK, // modify the router-table for given network on given service
|
||||
MODI_ROUTER_FOR_SERVICE_TERM, // modify the router-table for given termina on given service
|
||||
};
|
||||
typedef struct _icmp_pack
|
||||
{
|
||||
unsigned char type;
|
||||
unsigned char code;
|
||||
unsigned short checksum;
|
||||
unsigned short mark;
|
||||
unsigned short seq;
|
||||
|
||||
void from_buffer(const unsigned char* buf)
|
||||
{
|
||||
type = *buf++;
|
||||
code = *buf++;
|
||||
checksum = (buf[0] << 8) | buf[1];
|
||||
buf += 2;
|
||||
mark = (buf[0] << 8) | buf[1];
|
||||
buf += 2;
|
||||
seq = (buf[0] << 8) | buf[1];
|
||||
}
|
||||
void to_buffer(unsigned char* buf)
|
||||
{
|
||||
*buf++ = type;
|
||||
*buf++ = code;
|
||||
*buf++ = checksum >> 8;
|
||||
*buf++ = checksum;
|
||||
*buf++ = mark >> 8;
|
||||
*buf++ = mark;
|
||||
*buf++ = seq >> 8;
|
||||
*buf++ = seq;
|
||||
}
|
||||
}ICMPPACK, *LPICMPPACK;
|
||||
#pragma pack(pop)
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
// apis
|
||||
|
||||
namespace net_base_util
|
||||
{
|
||||
PORT_API(void) free_sock_addr(void* sockaddr);
|
||||
PORT_API(void*) init_sock_addr(const char* ip, unsigned port, int* addrlen, int family = /*AF_INET*/2, int type = /*SOCK_STREAM*/1, int proto = /*IPPROTO_TCP*/6); // return sockaddr_in* type. call net_base_util::free_sock_addr to free the returned value !!!
|
||||
PORT_API(void) ipv4_broadcast_address(unsigned self_ip, unsigned subnet, char ipbuf[IP_BUF_LEN]);
|
||||
PORT_API(bool) ip_from_sockaddr_storage(const void/*sockaddr_storage*/* sockaddr_storage_, char ipbuf[IP_BUF_LEN], unsigned* port);
|
||||
PORT_API(bool) is_ip_equal(const void/*sockaddr_storage*/* sockaddr_storage1_, const void/*sockaddr_storage*/* sockaddr_storage2_, bool compare_port = false);
|
||||
|
||||
// following apis return as base-socket api
|
||||
PORT_API(int) init_network(unsigned min_ver = 2, unsigned max_ver = 2);
|
||||
PORT_API(int) cleanup_network(void);
|
||||
PORT_API(SOCKET) raw_socket(int raw_proto, bool overlapped = false, bool ipv6 = false);
|
||||
PORT_API(SOCKET) tcp_socket(bool overlapped = false, bool ipv6 = false);
|
||||
PORT_API(SOCKET) udp_socket(bool overlapped = false, bool ipv6 = false, bool broadcast = false);
|
||||
PORT_API(int) close_socket(SOCKET s);
|
||||
PORT_API(int) bind_socket(SOCKET s, bool ipv6_socket, const char* ip, unsigned port);
|
||||
PORT_API(int) ip_from_domain(const char* domain, char ipbuf[IP_BUF_LEN]);
|
||||
PORT_API(int) get_local_ip(LPIPINFO ips, size_t* count/*[in] - count of ips; [out] - ip numbers in ips*/);
|
||||
PORT_API(int) get_ipv6_addrress(LPIPINFO ips, size_t* count/*[in] - count of ips; [out] - ip numbers in ips*/, const char* hostname = NULL/*local ipv6 when NULL*/);
|
||||
PORT_API(int) set_socket_block(SOCKET s, bool blocked);
|
||||
PORT_API(int) set_socket_buffer(SOCKET s, int buf_size, bool in_buf/*true for in buffer and false for out buffer*/);
|
||||
PORT_API(int) set_socket_keepalive(SOCKET s, bool keep_alive);
|
||||
PORT_API(int) set_socket_keepalive_detect(SOCKET s, bool detect_on, int alive_heart_milliseconds = 0, int retry_heart_milliseconds = 0);
|
||||
PORT_API(int) set_socket_timeout(SOCKET s, int milliseconds = 0/*no timeout*/, bool rcv_timeout = true);
|
||||
PORT_API(int) get_socket_timeout(SOCKET s, int *milliseconds, bool rcv_timeout);
|
||||
PORT_API(int) set_socket_nagle(SOCKET s, bool nagle_on); // if nagle_on is true, then the packet maybe sent delayed
|
||||
PORT_API(int) set_socket_ttl(SOCKET s, unsigned short ttl);
|
||||
PORT_API(int) set_reused_address(SOCKET s, bool reused);
|
||||
PORT_API(int) set_broadcast(SOCKET s, bool enabled);
|
||||
PORT_API(int) connect_with_timeout(SOCKET s, const char* ip, unsigned port, unsigned timeout_seconds, bool return_block_socket = false);
|
||||
PORT_API(SOCKET) connect_2_server(const char* ip, unsigned short port, unsigned timeout_seconds = 0/*0 to blocked*/, bool return_block_socket = false, const char* bind_ip = NULL, unsigned bind_port = 0);
|
||||
|
||||
// following apis return 0 for success otherwise error code
|
||||
PORT_API(int) ipv4_broadcast_address(const char* self_ip, const char* subnet, char ip_buf[IP_BUF_LEN]);
|
||||
PORT_API(int) get_peer_address(SOCKET s, bool remote, unsigned* port, char ip_buf[IP_BUF_LEN]);
|
||||
PORT_API(int) ipv4_address(unsigned addr, char ip_buf[IP_BUF_LEN]);
|
||||
PORT_API(unsigned) ipv4_address(const char* ipv4);
|
||||
PORT_API(bool) is_in_same_ipv4_subnet(const char* ip1, const char* ip2, const char* subnet);
|
||||
|
||||
// parameters of result:
|
||||
// data: (const char*)adapter_name
|
||||
// data_len: (const char*)adapter_description
|
||||
// total_len: IPINFO*
|
||||
// flag: inter_module_data::DATA_FLAG_FINAL
|
||||
// param: the same as 'param'
|
||||
PORT_API(int) enum_network_adapters(inter_module_data::set_data result, void* param);
|
||||
|
||||
// parameters of result:
|
||||
// data: (const char*)local address
|
||||
// data_len: (const char*)remote address
|
||||
// total_len: HIDWORD = state, LODWORD = owning pid
|
||||
// flag: inter_module_data::DATA_FLAG_FINAL
|
||||
// param: the same as 'param'
|
||||
PORT_API(int) enum_sockets(bool tcp, inter_module_data::set_data result, void* param);
|
||||
|
||||
// trace route by raw socket with ICMP
|
||||
// parameter of result:
|
||||
// data: ip, NULL when over
|
||||
// len: milliseconds, -1 is timeout, or error code when over
|
||||
// total: hops count, unused when over
|
||||
// flag: DATA_FLAG_FINAL in hops, DATA_FLAG_INSTAR in beginning information, and DATA_FLAG_OVER for over
|
||||
// param: 'param'
|
||||
// PORT_API(int) trace_route(const char* www, inter_module_data::set_data result, void* param, int max_hops = 30); // commented, use net_app::trace_route
|
||||
PORT_API(unsigned) proto_default_port(const char* proto);
|
||||
|
||||
// function: get the next hop, generally as gateway
|
||||
// for_ip: in multi-network-card, get the the next hop for given ip, if was NULL, return the first
|
||||
PORT_API(int) get_next_hop(char next_hop[IP_BUF_LEN], const char* for_ip = NULL);
|
||||
|
||||
// Note: the buffer length of proto(proto_buf_len) must be double of url!!! for host and page would use the buffer
|
||||
// and need not free host and page
|
||||
PORT_API(bool) parse_url(const char* url, char* proto, size_t proto_buf_len, char** host, char** page, unsigned* port, bool* port_from_host = NULL);
|
||||
PORT_API(bool) parse_url(const wchar_t* url, wchar_t* proto, size_t proto_buf_len, wchar_t** host, wchar_t** page, unsigned* port, bool* port_from_host = NULL);
|
||||
|
||||
PORT_API(unsigned short) calculate_ip_datagram_checksum(const unsigned char* buf, int bytes, bool* ok = NULL);
|
||||
PORT_API(unsigned short) calculate_icmp_checksum(LPICMPPACK pack, int bytes, bool* ok = NULL);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// windows firewall
|
||||
PORT_API(bool) firewall_is_on(void);
|
||||
PORT_API(bool) firewall_is_app_enabled(const wchar_t* app_pe_name);
|
||||
PORT_API(bool) firewall_is_port_enabled(unsigned port, firewall_port_cat fpc);
|
||||
PORT_API(int) firewall_turn_on(void);
|
||||
PORT_API(int) firewall_turn_off(void);
|
||||
PORT_API(int) firewall_enable_app(const wchar_t* name/*display name in firewall*/, const wchar_t* pe/*pe-image file name*/, bool enable);
|
||||
PORT_API(int) firewall_enable_port(unsigned port, firewall_port_cat fpc, bool enable, const wchar_t* name/*display name in firewall*/ = NULL);
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,223 @@
|
|||
// process_util.h : include utilities for manage folders
|
||||
//
|
||||
// Author: Gongbing
|
||||
//
|
||||
// Date: 2016-09-25
|
||||
|
||||
#pragma once
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#ifndef _INCLUDED_REF_
|
||||
#define _INCLUDED_REF_
|
||||
#include "../ref/ref.h"
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
// hook utils
|
||||
namespace pe_util
|
||||
{
|
||||
__declspec(novtable) struct IObscurityCall : public ref_util::IRef
|
||||
{
|
||||
// params must not be NULL but the API was no parameter
|
||||
COM_API_DECLARE(long, invoke(void** params, int* ret_val = NULL)); // return error code
|
||||
};
|
||||
#pragma pack(push)
|
||||
#pragma pack(1)
|
||||
typedef struct _hook_instruction_info
|
||||
{
|
||||
// e.g. in instruction 'E912345678', then bytes = 5, rel_addr_off = 1, rel_addr_size = 4
|
||||
unsigned long bytes : 6; // all bytes in this instruction
|
||||
unsigned long far_bytes : 3; // the far jumping instruction bytes if this was a near jumping instruction
|
||||
unsigned long rel_addr_off : 3; // relative address offset to instruction in this
|
||||
unsigned long rel_addr_size : 3; // relative address size of this instruction, ZERO is none
|
||||
unsigned char far_instruction[8]; // far jumping instruction, relative address size always be 4 bytes (int)
|
||||
unsigned long far_adden; // the jumping offset should added this value for converting near jumping to far jumping
|
||||
}HOOKII, *LPHOOKII;
|
||||
|
||||
typedef struct _group_icon_entry
|
||||
{
|
||||
unsigned char width;
|
||||
unsigned char height;
|
||||
unsigned char color_count;
|
||||
unsigned char reserved;
|
||||
unsigned short planes;
|
||||
unsigned short bits_per_pixel;
|
||||
unsigned long bytes;
|
||||
unsigned short id;
|
||||
}GROUPICONENTRY, *LPGROUPICONENTRY;
|
||||
typedef struct _group_icon // for RT_GROUP_ICON
|
||||
{
|
||||
unsigned short reserved;
|
||||
unsigned short res_type; // 1 for icon
|
||||
unsigned short entries;
|
||||
GROUPICONENTRY entry[1];
|
||||
}GROUPICON, *LPGROUPICON;
|
||||
#pragma pack(pop)
|
||||
|
||||
PORT_API(LPVOID) allocate_code_buffer(size_t size);
|
||||
PORT_API(void) free_code_buffer(LPVOID code_buf);
|
||||
PORT_API(int) get_min_code_buffer_bytes(void);
|
||||
|
||||
// function: calculate hooking info at hook_addr
|
||||
// hook_addr: the address will be hooked
|
||||
// lphii: the hooking instruction info, at least 6 elements
|
||||
// size: [in] - count of lphii, [out] - valid elements in lphii
|
||||
// bytes: to receive the minimum bytes to be moved for hooking
|
||||
// return: error code
|
||||
PORT_API(int) calculate_hook_bytes(const BYTE* hook_addr, LPHOOKII lphii, int* size, int* bytes);
|
||||
PORT_API(LPVOID) move_src_code_for_hook(LPVOID src_code, LPHOOKII lphii, int count, LPVOID given_buf = NULL, int bytes = 0);
|
||||
|
||||
// hook_addr: the instruction address which you should hooking at
|
||||
// new_addr: your hooking codes which would jump from hood_addr
|
||||
// origin_code: to receive origin codes at hook_addr. or the given address for hook junk if was not NULL, then the moved_bytes contains the size of the buffer when in
|
||||
// moved_bytes: to receive copied bytes from hook_addr. it can contains the origin_code buffer bytes if origin_code is not NULL
|
||||
PORT_API(int) hook_at(DWORD_PTR hook_addr, FARPROC new_addr, DWORD_PTR *origin_code, int *moved_bytes);
|
||||
PORT_API(int) hook_at(const char* module_name, const char* api, FARPROC new_addr, DWORD_PTR *origin_code, int *moved_bytes, int api_offset = 0);
|
||||
PORT_API(int) hook_with_shellcode(DWORD_PTR hook_addr, unsigned char* shellcodes, size_t shell_codes_bytes); // // RVA in shellcodes will not be handled !!!
|
||||
PORT_API(int) unhook_at(DWORD_PTR unhook_addr, DWORD_PTR* origin_code, int bytes_moved);
|
||||
PORT_API(int) unhook_at(const char* module_name, const char* api, DWORD_PTR *origin_code, int bytes_moved, int api_offset = 0);
|
||||
|
||||
// hook_bef: call method must be '__stdcall', and the parameters are pointers that points to the parameter of the origin api
|
||||
// hook_after: call method must be '__stdcall', and the first parameter is the return value of origin api whenever the origin api return value or not
|
||||
// and following the parameters is the same as origin api
|
||||
//
|
||||
// e.g. system api: HANDLE WINAPI CreateFileW(_In_ LPCWSTR lpFileName,
|
||||
// _In_ DWORD dwDesiredAccess, _In_ DWORD dwShareMode,
|
||||
// _In_opt_ LPSECURITY_ATTRIBUTES lpSecurityAttributes,
|
||||
// _In_ DWORD dwCreationDisposition, _In_ DWORD dwFlagsAndAttributes,
|
||||
// _In_opt_ HANDLE hTemplateFile);
|
||||
// hook_bef: void __stdcall hook_bef(LPCWSTR* lpFileName,
|
||||
// DWORD* dwDesiredAccess, DWORD* dwShareMode,
|
||||
// LPSECURITY_ATTRIBUTES* lpSecurityAttributes,
|
||||
// DWORD* dwCreationDisposition, DWORD* dwFlagsAndAttributes,
|
||||
// HANDLE* hTemplateFile
|
||||
// void* user_data);
|
||||
// or can be void __stdcall hook_bef(void* user_data) if no_param_for_hook_before was true;
|
||||
//
|
||||
// hook_after: void __stdcall hook_after(HANDLE* ret, LPCWSTR lpFileName,
|
||||
// DWORD dwDesiredAccess, DWORD dwShareMode,
|
||||
// LPSECURITY_ATTRIBUTES lpSecurityAttributes,
|
||||
// DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes,
|
||||
// HANDLE hTemplateFile
|
||||
// void* user_data);
|
||||
//
|
||||
//
|
||||
PORT_API(void*) any_hook_at(FARPROC api, size_t param_count, bool stdcall, FARPROC hook_bef = NULL, bool hook_bef_without_param = false, FARPROC hook_after = NULL, void* user_data = NULL);
|
||||
PORT_API(void) free_any_hook(void* any_hook);
|
||||
|
||||
PORT_API(IObscurityCall*) create_obscurity_caller(const wchar_t* module, const char* api, int api_params, bool stdcall);
|
||||
PORT_API(IObscurityCall*) create_obscurity_caller(HMODULE module, const char* api, int api_params, bool stdcall);
|
||||
|
||||
// pe parsing ...
|
||||
enum pe_address_type
|
||||
{
|
||||
PE_ADDR_RELATIVE_TO_FILE = 0,
|
||||
PE_ADDR_RELATIVE_TO_MEM,
|
||||
PE_ADDR_ABSOLUTE_ON_DEFAULT_BASE,
|
||||
};
|
||||
__declspec(novtable) struct IPe : public ref_util::IRef
|
||||
{
|
||||
// params must not be NULL but the API was no parameter
|
||||
COM_API_DECLARE(long, load_pe(const wchar_t* path_pe)); // return error code
|
||||
COM_API_DECLARE(long, close(void)); // return error code, owner MUST call this before 'release' when you never use this !!!
|
||||
COM_API_DECLARE(long, attach(unsigned char* buf, UINT64 bytes)); // return error code
|
||||
COM_API_DECLARE(long, detach(unsigned char** buf)); // return error code
|
||||
|
||||
// cb: data - (const char*)dll_name if flag was DATA_FLAG_FINAL or (const char*)err_msg if flag was DATA_FLAG_ERROR
|
||||
// or "IAT" if flag was DATA_FLAG_INSTAR
|
||||
// len - (const char*)api_name
|
||||
// or IAT sector info(void*[2]) if flag was DATA_FLAG_INSTAR: [0] - (char*)section name, [1] - (UINT64) offset to file
|
||||
// total - UINT64[2]: [0] - hint, [2] - offset in file(EAT only), [1] - offset in mem set to be '0' if 'only_dll' was true if flag was DATA_FLAG_FINAL or unused if flag was DATA_FLAG_ERROR
|
||||
// or IAT table info(UINT64[3]) if flag was DATA_FLAG_INSTAR: [0] - offset to file, [1] - offset in memory, [2] - table bytes
|
||||
// flag - DATA_FLAG_FINAL or DATA_FLAG_INSTAR or DATA_FLAG_ERROR
|
||||
//
|
||||
// param - same as the paramenter you passed 'param'
|
||||
//
|
||||
// return non 'SET_RESULT_CONTINUE' to stop working
|
||||
COM_API_DECLARE(long, dump_iat(INTER_MODULE_CALLBACK_VAR(cb), void* param, bool only_dll = false));
|
||||
COM_API_DECLARE(long, dump_eat(INTER_MODULE_CALLBACK_VAR(cb), void* param));
|
||||
|
||||
// cb: data - (const char*)section name
|
||||
//
|
||||
// len - bytes of section name
|
||||
//
|
||||
// total - UINT64 pos[3]: pos[0] - offset in file, pos[1] - offset in memory, pos[2] - section size in bytes
|
||||
//
|
||||
// flag - DATA_FLAG_FINAL
|
||||
//
|
||||
// param - same as the paramenter you passed 'param'
|
||||
COM_API_DECLARE(long, dump_sections(INTER_MODULE_CALLBACK_VAR(cb), void* param));
|
||||
|
||||
// cb: data - (const char*)resource name
|
||||
//
|
||||
// len - UINT64[2]: [0] - bytes of resource; [1] - (void*)resource_data
|
||||
//
|
||||
// total - UINT64[4]: [0] - id; [1] - memory offset; [2] - file offset, [3] - codepage
|
||||
//
|
||||
// flag - DATA_FLAG_FINAL
|
||||
//
|
||||
// param - same as the paramenter you passed 'param'
|
||||
COM_API_DECLARE(long, dump_resources(INTER_MODULE_CALLBACK_VAR(cb), void* param));
|
||||
|
||||
// function: convert RVA between memory offset and file offset
|
||||
//
|
||||
// parameter: from - source address;
|
||||
//
|
||||
// to - to receive the target address
|
||||
//
|
||||
// off2rva - true: file offset to memory offset; false: memory offset to file offset
|
||||
COM_API_DECLARE(long, rva(UINT64 from, UINT64* to, bool off2rva));
|
||||
|
||||
// cb: data - (const char*)assembly
|
||||
//
|
||||
// len - bytes of assembly
|
||||
//
|
||||
// total - UINT[2]: 0 - offset in file of the code, 1 - offset in memory of the assembly
|
||||
//
|
||||
// flag - DATA_FLAG_FINAL
|
||||
//
|
||||
// param - same as the paramenter you passed 'param'
|
||||
COM_API_DECLARE(long, find_address_ref(UINT64 addr, INTER_MODULE_CALLBACK_VAR(cb), void* param, short addr_bytes = 4));
|
||||
COM_API_DECLARE(long, find_iat_ref(const char* dll_name, const char* api_name/*consider as hint if less than 0x10000*/, INTER_MODULE_CALLBACK_VAR(cb), void* param));
|
||||
COM_API_DECLARE(long, find_string_ref(const char* str, INTER_MODULE_CALLBACK_VAR(cb), void* param));
|
||||
COM_API_DECLARE(long, find_string_ref(const wchar_t* str, INTER_MODULE_CALLBACK_VAR(cb), void* param));
|
||||
|
||||
// function: un-assembly given function begin from 'addr' and ENDING at instruction 'ret' or 'cb' return SET_RESULT_STOP
|
||||
//
|
||||
// parameter: addr - given address
|
||||
//
|
||||
// addr_type - how to use the address 'addr'
|
||||
//
|
||||
// cb - data: (const char*) assembly
|
||||
// len: bytes of data
|
||||
// total: UINT64[4]: 0 - file offset; 1 - instruction absolute address; 2 - bytes; [3] - (unsigned char*) codes
|
||||
// flag: DATA_FLAG_FINAL
|
||||
// param: same as the paramenter you passed 'param'
|
||||
// return SET_RESULT_CONTINUE to work until 'ret', or SET_RESULT_STOP to stop immediately
|
||||
//
|
||||
// param - parameter for 'cb'
|
||||
//
|
||||
// img_base - specify the image base. use default base if it was '0'
|
||||
COM_API_DECLARE(long, un_assembly(UINT64 addr, enum pe_address_type addr_type, INTER_MODULE_CALLBACK_VAR(cb), void* param, UINT64 img_base = 0));
|
||||
COM_API_DECLARE(long, un_assembly(const char* export_api_name, INTER_MODULE_CALLBACK_VAR(cb), void* param));
|
||||
|
||||
// function: to change content at given file offset
|
||||
//
|
||||
// cb - data: (const wchar_t*) target file after changed
|
||||
// len: bytes of data
|
||||
// total: unused
|
||||
// flag: DATA_FLAG_FINAL
|
||||
// param: same as the parameter you passed 'param'
|
||||
// return: omitted
|
||||
COM_API_DECLARE(long, change(UINT64 file_off, const unsigned char* data, size_t bytes, INTER_MODULE_CALLBACK_VAR(cb), void* param));
|
||||
|
||||
COM_API_DECLARE(bool, is_pe_64(void)); // whether the PE is a 64-bits module
|
||||
COM_API_DECLARE(long, get_entry_point(UINT64* off)); // get offset of entry-point in memory
|
||||
COM_API_DECLARE(long, get_image_base_addr(UINT64* addr)); // get offset of entry-point in memory
|
||||
COM_API_DECLARE(long, get_file_time(UINT64* file_time)); // get file compiled time
|
||||
};
|
||||
|
||||
PORT_API(IPe*) create_pe_parser(void);
|
||||
};
|
||||
|
|
@ -0,0 +1,171 @@
|
|||
// process_util.h : include utilities for manage folders
|
||||
//
|
||||
// Author: Gongbing
|
||||
//
|
||||
// Date: 2016-09-25
|
||||
|
||||
#pragma once
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#ifndef _INCLUDED_REF_
|
||||
#define _INCLUDED_REF_
|
||||
#include "../ref/ref.h"
|
||||
#endif
|
||||
|
||||
#define STATUS_SUCCESS 0x00000000
|
||||
#define STATUS_BUFFER_OVERFLOW 0x80000005
|
||||
#define STATUS_INFO_LENGTH_MISMATCH 0xC0000004
|
||||
|
||||
// process utils
|
||||
namespace process_util
|
||||
{
|
||||
PORT_API(int) start_program(const wchar_t* prog_file, const wchar_t* param, bool show_wnd, DWORD* pid = NULL, bool as_admin = false, const wchar_t* path_dll = NULL);
|
||||
PORT_API(bool) is_me_in_admin(void);
|
||||
PORT_API(int) try_me_in_admin(bool show_wnd, DWORD *pid = NULL, const wchar_t* append_param = NULL);
|
||||
PORT_API(int) start_program_as_current_user(const wchar_t* prog_file, const wchar_t* param, bool show_wnd, unsigned* proc_id = NULL, bool merge_pe_2_param = true, const wchar_t* path_dll = NULL);
|
||||
PORT_API(bool) start_program_by_cmd(const wchar_t* prog_file, const wchar_t* param);
|
||||
PORT_API(bool) query_acting_user_token(HANDLE* aut);
|
||||
PORT_API(int) enable_privilege(const wchar_t* privilege_name, bool enabled);
|
||||
PORT_API(bool) kill_process_by_name(const wchar_t* proc_name, const wchar_t* taskkill_path = NULL);
|
||||
PORT_API(bool) is_process_living(const wchar_t* proc_name, DWORD* pid = NULL);
|
||||
|
||||
// parameter of result:
|
||||
// data: (wchar_t*)pe_path_file
|
||||
// len: process id
|
||||
// total: parent process id
|
||||
PORT_API(void) enum_processes(inter_module_data::set_data result, void* param);
|
||||
|
||||
// parameter of result:
|
||||
// data: (wchar_t*)module path file
|
||||
// len: base address
|
||||
// total: module size
|
||||
PORT_API(void) enum_modules(DWORD proc_id, inter_module_data::set_data result, void* param);
|
||||
PORT_API(bool) module_pe_from_run_address(void* addr, wchar_t path_name[MAX_PATH], void** base_addr = NULL);
|
||||
|
||||
PORT_API(int) find_resource(HINSTANCE inst, const wchar_t* res_type, UINT res_id, inter_module_data::set_data result, void* param);
|
||||
PORT_API(bool) is_pe_checksum_ok(const wchar_t* pe_path_file, DWORD* lppe_chksum = NULL, DWORD* lpfile_chksum = NULL);
|
||||
PORT_API(bool) get_module_info(HMODULE module, void** base, void** entry, size_t* size);
|
||||
PORT_API(bool) get_process_time(DWORD proc_id, LPFILETIME start = NULL, LPFILETIME kern = NULL, LPFILETIME user = NULL);
|
||||
PORT_API(DWORD) get_parent_process(DWORD proc_id);
|
||||
PORT_API(int) get_process_name(DWORD proc_id, wchar_t path_name[MAX_PATH]);
|
||||
PORT_API(int) get_self_pathname(wchar_t path_name[MAX_PATH], bool call_module = false/*default to get exe pathname*/);
|
||||
PORT_API(void) quit_and_delete_self(void);
|
||||
PORT_API(char*) set_command_lineA(char* cmda); // the return buffer need not free
|
||||
PORT_API(wchar_t*) set_command_lineW(wchar_t* cmda, bool is_setpeb); // the return buffer need not free
|
||||
PORT_API(void) set_peb_command_lineW(wchar_t* cmda);
|
||||
|
||||
PORT_API(HANDLE) get_file_handle_by_name(const wchar_t* filename, ULONG *pid = NULL);
|
||||
PORT_API(BOOL) is_wow64_process(DWORD proc_id);
|
||||
PORT_API(HMODULE) load_system_dll(const wchar_t* dll);
|
||||
|
||||
PORT_API(void*) write_to_process(HANDLE proc, const void* src, int bytes);
|
||||
PORT_API(void*) write_to_process(DWORD proc_id, const void* src, int bytes);
|
||||
PORT_API(int) read_process_memory(DWORD proc_id, void* base_addr, int read_bytes, unsigned char* buf); // read proc_id [base_addr, base_addr] contents into buf, return error code, 0 is success
|
||||
|
||||
// function: create a remote thread in given process
|
||||
// proc_id: the target process ID
|
||||
// code_bytes: remote thread code size in bytes
|
||||
// susbend: whether to supspend this thread when create it
|
||||
// parameter_size: remote thread parameter size
|
||||
// tid: to receive the remote thread id
|
||||
// thread: to receive the remote thread handle
|
||||
// fill: to fill the thread code and parameter in this callback
|
||||
// data: unused, always be NULL
|
||||
// len: (LPVOID), the memory address in process proc_id
|
||||
// total: (unsigned char*), to receive the content
|
||||
// flag: write code when DATA_FLAG_REMOTE_THREAD_INSTRUCT, or parameter when DATA_FLAG_REMOTE_THREAD_PARAMETER if parameter_bytes was great than ZERO
|
||||
// param: the same as 'param'
|
||||
// param: parameter 'param' of callback fill
|
||||
// return: error code, 0 is success
|
||||
PORT_API(int) create_remote_thread(DWORD proc_id, int code_bytes, inter_module_data::set_data fill, void* param, bool suspend = false
|
||||
, int parameter_bytes = 0, DWORD* tid = NULL, HANDLE* thread = NULL);
|
||||
|
||||
// code and param: [in] - the source code or parameter buffer; [out] - remote code or parameter buffer
|
||||
PORT_API(int) create_remote_thread(DWORD proc_id, const unsigned char **code, int code_bytes, bool suspend = false
|
||||
, const unsigned char** param = NULL, int param_bytes = 0, DWORD* tid = NULL, HANDLE* thread = NULL);
|
||||
PORT_API(bool) get_api_in_process(DWORD proc_id, const wchar_t* dll, const char* apis/*GetTickCount\0CreateFileW\0\0*/, FARPROC* api_addrs/*length as same as apis*/);
|
||||
PORT_API(HMODULE) load_dll_in_process(DWORD proc_id, const wchar_t* path_dll); // return the loaded dll handle in the process
|
||||
PORT_API(HMODULE) free_dll_in_process(DWORD proc_id, const wchar_t* path_dll); // return the dll in the process
|
||||
|
||||
enum _inst_statu
|
||||
{
|
||||
INST_STATU_FIRST = 0, // 0 - I am the FIRST instance
|
||||
INST_STATU_FAILED_CREATE, // 1 - no instance existing and failed to create the singleton instance
|
||||
INST_STATU_INFO_FIRST, // 2 - an instance is already existing and informed my parameter
|
||||
INST_STATU_FAILED_INFO_FIRST, // 3 - an instance is already existing and failed in informing my parameter
|
||||
INST_STATU_ID_USED, // 4 - the name is used by other object
|
||||
|
||||
INST_STATU_UNKNOWN = 10, // unknown error
|
||||
};
|
||||
__declspec(novtable) struct ISingleton : public ref_util::IRef
|
||||
{
|
||||
COM_API_DECLARE(_inst_statu, statu(void));
|
||||
COM_API_DECLARE(bool, set_max_run_seconds(DWORD seconds = -1)); // quit after seconds when not -1
|
||||
};
|
||||
__declspec(novtable) struct ICmd : public ref_util::IRef
|
||||
{
|
||||
COM_API_DECLARE(void, reset(const wchar_t* cmdline = NULL)); // reset command line string, use GetCommandLineW if cmd_line was NULL
|
||||
COM_API_DECLARE(long, count(void)); // return parameter count, if has key-val pair, then count them as 2
|
||||
|
||||
// function: whether the command line has 'param'
|
||||
// case_sens: is case sensitive
|
||||
// ind: to receive the index in command line if has
|
||||
COM_API_DECLARE(bool, has(const wchar_t* param, bool case_sens = false, int *ind = NULL));
|
||||
COM_API_DECLARE(bool, is_first_main_pe(void)); // return whether the first parameter is main-pe
|
||||
COM_API_DECLARE(const wchar_t*, parameter(int index)); // ZERO-based index, should not free the return buffer but use it immediately
|
||||
|
||||
// key: the key for the parameter
|
||||
// case_sens: whether the 'key' is case sensitive
|
||||
// return: return im.exe of key '/im' in "taskkill /f /im im.exe", should not free but use it immediately
|
||||
COM_API_DECLARE(const wchar_t*, parameter(const wchar_t* key, bool case_sens = false));
|
||||
COM_API_DECLARE(const wchar_t*, main_pe(void)); // DO NOT free the return buffer but use it immediately
|
||||
|
||||
COM_API_DECLARE(int, add(const wchar_t* param, bool case_sens = false, int index = -1));
|
||||
COM_API_DECLARE(int, add(const wchar_t* key, const wchar_t* val, bool case_sens = false, int index = -1));
|
||||
|
||||
// if as_key was true, then remove param and the next item to it
|
||||
COM_API_DECLARE(int, remove(const wchar_t* param, bool case_sens = false, bool as_key = false));
|
||||
COM_API_DECLARE(int, remove(int index));
|
||||
|
||||
// function: convert to a command line string
|
||||
// buf: to receive the string, can be NULL
|
||||
// len: [in] - count of buf, [out] - content length in buf, if buf was NULL or len is small, then contains the minimum length and return ERROR_INSUFFICIENT_BUFFER
|
||||
// return: ERROR_SUCCESS if buf is length enough, or ERROR_INSUFFICIENT_BUFFER if len was less than required,
|
||||
COM_API_DECLARE(int, to_command_line(wchar_t* buf, int* len));
|
||||
|
||||
// data: (const wchar_t*)
|
||||
// len: bytes of 'data'
|
||||
// total: unused, be ZERO
|
||||
// flag: inter_module_data::DATA_FLAG_FINAL
|
||||
// param: same as 'user'
|
||||
COM_API_DECLARE(int, to_command_line(INTER_MODULE_CALLBACK_VAR(got_result), void* user));
|
||||
};
|
||||
|
||||
PORT_API(long) invoke_api(FARPROC func, bool stdcall_, int param_count, void** params, int* ret_val = NULL);
|
||||
PORT_API(long) invoke_api(const wchar_t* path_module, const char* api, bool stdcall_, int param_count, void** params, int* ret_val = NULL);
|
||||
|
||||
// parameter of result:
|
||||
// data: (const wchar_t*)command line
|
||||
// len: length of (const wchar_t*)data
|
||||
// total: as same as len
|
||||
// flag: DATA_FLAG_FINAL in commonplace, or DATA_FLAG_UNKNOWN to quit
|
||||
// param: like 'param'
|
||||
PORT_API(ISingleton*) create_singleton(const wchar_t* inst_id, inter_module_data::set_data result, void* param);
|
||||
PORT_API(ICmd*) create_command_line(const wchar_t* cmd = NULL);
|
||||
enum _console_attr
|
||||
{
|
||||
CA_FOREGROUND_BLUE = FOREGROUND_BLUE,
|
||||
CA_FOREGROUND_GREEN = FOREGROUND_GREEN,
|
||||
CA_FOREGROUND_RED = FOREGROUND_RED,
|
||||
CA_FOREGROUND_INTENSITY = FOREGROUND_INTENSITY,
|
||||
CA_BACKGROUND_BLUE = BACKGROUND_BLUE,
|
||||
CA_BACKGROUND_GREEN = BACKGROUND_GREEN,
|
||||
CA_BACKGROUND_RED = BACKGROUND_RED,
|
||||
CA_BACKGROUND_INTENSITY = BACKGROUND_INTENSITY,
|
||||
};
|
||||
PORT_API(WORD) set_console_attribute(WORD attr);
|
||||
PORT_API(ICmd*) from_console(const wchar_t* tips = L"input");
|
||||
PORT_API(ICmd*) from_console(const char* tips = "input");
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,126 @@
|
|||
// un_asm.h : include utilities for unassembly
|
||||
//
|
||||
// Author: Gongbing
|
||||
//
|
||||
// Date: 2020-03-19
|
||||
|
||||
#pragma once
|
||||
#ifndef _INCLUDED_REF_
|
||||
#define _INCLUDED_REF_
|
||||
#include "../ref/ref.h"
|
||||
#endif
|
||||
|
||||
|
||||
namespace ia_asm
|
||||
{
|
||||
// unassembly utils
|
||||
enum ia_arch
|
||||
{
|
||||
IA_ARCHITECTURE_32 = 1,
|
||||
IA_ARCHITECTURE_64,
|
||||
};
|
||||
const UINT64 REGISTER_BMP_RAX = (UINT64)1 << 0; const UINT64 REGISTER_BMP_EAX = (UINT64)1 << 0;
|
||||
const UINT64 REGISTER_BMP_RCX = (UINT64)1 << 1; const UINT64 REGISTER_BMP_ECX = (UINT64)1 << 1;
|
||||
const UINT64 REGISTER_BMP_RDX = (UINT64)1 << 2; const UINT64 REGISTER_BMP_EDX = (UINT64)1 << 2;
|
||||
const UINT64 REGISTER_BMP_RBX = (UINT64)1 << 3; const UINT64 REGISTER_BMP_EBX = (UINT64)1 << 3;
|
||||
const UINT64 REGISTER_BMP_RSP = (UINT64)1 << 4; const UINT64 REGISTER_BMP_ESP = (UINT64)1 << 4;
|
||||
const UINT64 REGISTER_BMP_RBP = (UINT64)1 << 5; const UINT64 REGISTER_BMP_EBP = (UINT64)1 << 5;
|
||||
const UINT64 REGISTER_BMP_RSI = (UINT64)1 << 6; const UINT64 REGISTER_BMP_ESI = (UINT64)1 << 6;
|
||||
const UINT64 REGISTER_BMP_RDI = (UINT64)1 << 7; const UINT64 REGISTER_BMP_EDI = (UINT64)1 << 7;
|
||||
const UINT64 REGISTER_BMP_R08 = (UINT64)1 << 8;
|
||||
const UINT64 REGISTER_BMP_R09 = (UINT64)1 << 9;
|
||||
const UINT64 REGISTER_BMP_R10 = (UINT64)1 << 10;
|
||||
const UINT64 REGISTER_BMP_R11 = (UINT64)1 << 11;
|
||||
const UINT64 REGISTER_BMP_R12 = (UINT64)1 << 12;
|
||||
const UINT64 REGISTER_BMP_R13 = (UINT64)1 << 13;
|
||||
const UINT64 REGISTER_BMP_R14 = (UINT64)1 << 14;
|
||||
const UINT64 REGISTER_BMP_R15 = (UINT64)1 << 15;
|
||||
const UINT64 REGISTER_BMP_MM0 = (UINT64)1 << 16;
|
||||
const UINT64 REGISTER_BMP_MM1 = (UINT64)1 << 17;
|
||||
const UINT64 REGISTER_BMP_MM2 = (UINT64)1 << 18;
|
||||
const UINT64 REGISTER_BMP_MM3 = (UINT64)1 << 19;
|
||||
const UINT64 REGISTER_BMP_MM4 = (UINT64)1 << 20;
|
||||
const UINT64 REGISTER_BMP_MM5 = (UINT64)1 << 21;
|
||||
const UINT64 REGISTER_BMP_MM6 = (UINT64)1 << 22;
|
||||
const UINT64 REGISTER_BMP_MM7 = (UINT64)1 << 23;
|
||||
const UINT64 REGISTER_BMP_XMM0 = (UINT64)1 << 24;
|
||||
const UINT64 REGISTER_BMP_XMM1 = (UINT64)1 << 25;
|
||||
const UINT64 REGISTER_BMP_XMM2 = (UINT64)1 << 26;
|
||||
const UINT64 REGISTER_BMP_XMM3 = (UINT64)1 << 27;
|
||||
const UINT64 REGISTER_BMP_XMM4 = (UINT64)1 << 28;
|
||||
const UINT64 REGISTER_BMP_XMM5 = (UINT64)1 << 29;
|
||||
const UINT64 REGISTER_BMP_XMM6 = (UINT64)1 << 30;
|
||||
const UINT64 REGISTER_BMP_XMM7 = (UINT64)1 << 31;
|
||||
const UINT64 REGISTER_BMP_FLAG = (UINT64)1 << 32;
|
||||
|
||||
#pragma pack(push)
|
||||
#pragma pack(1)
|
||||
typedef struct _instruction_data
|
||||
{
|
||||
unsigned long long address; // instruction address
|
||||
unsigned long bytes; // all bytes of this instruction
|
||||
unsigned long cycle; // cpu cycle
|
||||
UINT64 reg_chg_bmp; // changed register bit-map mask
|
||||
struct _rel_addr
|
||||
{
|
||||
union
|
||||
{
|
||||
unsigned char rel_byte;
|
||||
struct
|
||||
{
|
||||
unsigned char offset : 5; // the offest to codes[0] of the relative address, ZERO means no
|
||||
unsigned char size : 3; // bytes of the relative address, ZERO means no
|
||||
};
|
||||
};
|
||||
}rel_addr[4]; // relative address in this instruction, max up to 4
|
||||
struct
|
||||
{
|
||||
unsigned char bytes[4]; // bytes for val, ZERO means no imm val, often be 1, 2, 4, 8
|
||||
UINT64 val[4]; // imm value
|
||||
}imm;
|
||||
char codes[20]; // instruction code bytes
|
||||
char assembly[84]; // instruction text
|
||||
|
||||
struct _instruction_data()
|
||||
{
|
||||
clear();
|
||||
}
|
||||
void clear(void)
|
||||
{
|
||||
memset(this, 0, sizeof(struct _instruction_data));
|
||||
}
|
||||
void copy(struct _instruction_data* r)
|
||||
{
|
||||
memcpy(this, r, sizeof(struct _instruction_data));
|
||||
}
|
||||
}INSTRUCTION, *LPINSTRUCTION;
|
||||
#pragma pack(pop)
|
||||
|
||||
// function: to un-assembly the codes
|
||||
//
|
||||
// return: error codes, ZERO is success
|
||||
PORT_API(int) unasm(const unsigned char* codes // code stream
|
||||
, LPINSTRUCTION lpasm // to receive the assembly text
|
||||
, unsigned long long address = 0 // instruction address, use address 'codes' if this was ZERO
|
||||
, ia_arch ia32 = IA_ARCHITECTURE_32); // intel architecture
|
||||
|
||||
// function: to convert near instruction to far instruction
|
||||
//
|
||||
// return: ZERO - have far instruction; 1 - no far instruction
|
||||
PORT_API(int) far_instruction(const LPINSTRUCTION near
|
||||
, LPINSTRUCTION far // to receive the far instruction
|
||||
, unsigned long long far_instruction_addr = 0 // the address of the far instruction, use near's address if was ZERO
|
||||
, ia_arch ia32 = IA_ARCHITECTURE_32); // intel architecture);
|
||||
|
||||
// function: compile single instruction
|
||||
//
|
||||
// return: error codes, ZERO is success
|
||||
PORT_API(int) compile(const char* assembly // assembly text such as 'mov eax, ebp'
|
||||
, unsigned long long *address // [in] - address of this assembly, [out] - address of the next statement, commonly [in] add lpasm->bytes
|
||||
, LPINSTRUCTION lpasm // instruction array to receive the result
|
||||
, inter_module_data::set_data label // label callback. see DATA_FLAG_UNASM_SET_LABEL && DATA_FLAG_UNASM_GET_LABEL
|
||||
, ia_arch ia32 = IA_ARCHITECTURE_32); // assembly architecture
|
||||
PORT_API(int) compile_one(const char* assembly
|
||||
, unsigned char *code // minimum length with 40 bytes. [bytes]codes[bytes]codes[0]
|
||||
, unsigned long long address = 0);
|
||||
}
|
|
@ -0,0 +1,208 @@
|
|||
// ref.h : the base utility for life-cycle control by reference
|
||||
//
|
||||
// Author: Gongbing
|
||||
//
|
||||
// Create: 2017-05-20
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef _AS_DLL_
|
||||
#ifdef _NET_EXPORTS_
|
||||
#define PORT_API(ret) __declspec(dllexport) ret __stdcall
|
||||
#define PORT_API_CALL(ret, call_) __declspec(dllexport) ret call_
|
||||
#else
|
||||
#define PORT_API(ret) __declspec(dllimport) ret __stdcall
|
||||
#define PORT_API_CALL(ret, call_) __declspec(dllimport) ret call_
|
||||
#ifdef _DEBUG
|
||||
#pragma comment(lib, "./Debug/base_util.lib")
|
||||
#else
|
||||
#pragma comment(lib, "./Release/base_util.lib")
|
||||
#endif
|
||||
#endif
|
||||
#else
|
||||
#define PORT_API(ret) ret __stdcall
|
||||
#define PORT_API_CALL(ret, call_) ret call_
|
||||
#ifndef _BASE_EXPORTS_
|
||||
#ifdef _DEBUG
|
||||
#pragma comment(lib, "./Debug/base_util.lib")
|
||||
#else
|
||||
#pragma comment(lib, "./Release/base_util.lib")
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
//#define STRUCT_ALIGN(bytes) \
|
||||
// #pragma pack(push) \
|
||||
// #pragma pack(bytes)
|
||||
//#define STRUCT_ALIGN_END \
|
||||
// #pragma pack(pop)
|
||||
|
||||
#define COM_API_DECLARE(ret, decl) virtual ret __stdcall decl = 0
|
||||
#define COM_API_DECLARE_NON_PURE(ret, decl) virtual ret __stdcall decl
|
||||
#define COM_API_OVERRIDE(ret, decl) virtual ret __stdcall decl override
|
||||
#define COM_API_IMPLEMENT(cls, ret, decl) ret __stdcall cls##::decl
|
||||
|
||||
#define ALIGN_MEMORY(n, align) ((n + align - 1) / (align) * (align))
|
||||
#define _TO_UNICODE_(str) L##str
|
||||
#define UNICODE_STR(str) _TO_UNICODE_(str)
|
||||
|
||||
// refferer simulating-COM
|
||||
namespace ref_util
|
||||
{
|
||||
//
|
||||
// rule:
|
||||
//
|
||||
// if a member of container owns the container pointer, the member should release the container pointer
|
||||
// in an explicit function like 'stop'; the container could release the member pointer in destructor!!!
|
||||
//
|
||||
__declspec(novtable) struct IRef
|
||||
{
|
||||
COM_API_DECLARE(long, add_ref(void));
|
||||
COM_API_DECLARE(long, release(void));
|
||||
};
|
||||
|
||||
class refer : public IRef
|
||||
{
|
||||
volatile long m_ref;
|
||||
|
||||
public:
|
||||
refer() : m_ref(1)
|
||||
{}
|
||||
|
||||
protected:
|
||||
virtual ~refer()
|
||||
{}
|
||||
|
||||
public:
|
||||
COM_API_OVERRIDE(long, add_ref(void))
|
||||
{
|
||||
return InterlockedIncrement(&m_ref);
|
||||
}
|
||||
COM_API_OVERRIDE(long, release(void))
|
||||
{
|
||||
long ref = InterlockedDecrement(&m_ref);
|
||||
|
||||
if (ref <= 0) delete this;
|
||||
|
||||
return ref;
|
||||
}
|
||||
};
|
||||
|
||||
template<class T>
|
||||
class auto_pointer
|
||||
{
|
||||
T* m_ptr;
|
||||
|
||||
public:
|
||||
auto_pointer() : m_ptr(NULL)
|
||||
{}
|
||||
auto_pointer(T* ptr) : m_ptr(ptr)
|
||||
{}
|
||||
auto_pointer(const auto_pointer& r)
|
||||
{
|
||||
m_ptr = r.m_ptr;
|
||||
if (m_ptr) m_ptr->add_ref();
|
||||
}
|
||||
~auto_pointer()
|
||||
{
|
||||
if (m_ptr) m_ptr->release();
|
||||
}
|
||||
|
||||
public:
|
||||
auto_pointer& operator=(T* ptr)
|
||||
{
|
||||
if (m_ptr) m_ptr->release();
|
||||
m_ptr = ptr;
|
||||
|
||||
return *this;
|
||||
}
|
||||
auto_pointer& operator=(const auto_pointer& r)
|
||||
{
|
||||
if (m_ptr) m_ptr->release();
|
||||
m_ptr = r.m_ptr;
|
||||
if (m_ptr) m_ptr->add_ref();
|
||||
|
||||
return *this;
|
||||
}
|
||||
T* ptr(void)
|
||||
{
|
||||
return m_ptr;
|
||||
}
|
||||
T* operator->(void)
|
||||
{
|
||||
return m_ptr;
|
||||
}
|
||||
bool is_empty(void)
|
||||
{
|
||||
return m_ptr == NULL;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#define IMPL_REF_BY_REFER() \
|
||||
COM_API_OVERRIDE(long, add_ref(void)) \
|
||||
{ \
|
||||
return ref_util::refer::add_ref(); \
|
||||
} \
|
||||
COM_API_OVERRIDE(long, release(void)) \
|
||||
{ \
|
||||
return ref_util::refer::release(); \
|
||||
}
|
||||
|
||||
// inter-module data
|
||||
namespace inter_module_data
|
||||
{
|
||||
enum data_flag
|
||||
{
|
||||
// commonly
|
||||
DATA_FLAG_UNKNOWN = 0,
|
||||
DATA_FLAG_ERROR, // the parameter 'len' is contains the error code, total is extension info for 'len'
|
||||
DATA_FLAG_FINAL, // data is final result for the api which you called
|
||||
DATA_FLAG_INSTAR, // data is instar for your api, and finally will notified with flag DATA_TYPE_FINAL
|
||||
DATA_FLAG_OVER, // all data has been transfered, parameter data, len and total are all invalid
|
||||
|
||||
DATA_FLAG_GET_VAL, // (const wchar_t*)data, 'len' is bytes of data, 'total' is set_data
|
||||
// call (set_data)total(const wchar_t* data, bytes of 'data', 0, DATA_FLAG_FINAL, param)
|
||||
DATA_FLAG_DEBUG_INFO,
|
||||
|
||||
// for http data
|
||||
DATA_FLAG_HTTP_HEAD = 100, // http(s) response head
|
||||
DATA_FLAG_302, // 301 or 302 to new url, the data contains the url. in this case, return SET_RESULT_CONTINUE to jump, SET_RESULT_DISCARD to stop jumping
|
||||
|
||||
// for remote thread
|
||||
DATA_FLAG_REMOTE_THREAD_INSTRUCT = 200, // to fill the remote thread code in given address
|
||||
DATA_FLAG_REMOTE_THREAD_PARAMETER, // to fill the remote thread parameter in given address
|
||||
|
||||
// the parameter data, len and total will be all set to ZERO if unused
|
||||
DATA_FALG_SVC_ENTER = 300, // service callback, called when initailizing, parameter 'data' is pointing to proc_util::ICmd*
|
||||
DATA_FALG_SVC_TIMER, // service callback, called when timer is set, parameter 'len' is the count base from ZERO
|
||||
DATA_FALG_SVC_CONTROL, // service callback, called when service control is invoked, parameter 'len' is the control code
|
||||
DATA_FALG_SVC_EXIT, // service callback, called when service exiting
|
||||
|
||||
// for un-assembly
|
||||
DATA_FLAG_UNASM_SET_LABEL = 1000, // set the label address, data is label, len is address, other has no mean
|
||||
DATA_FLAG_UNASM_GET_LABEL, // query the label address. data is label, param is a pointer points to the UINT64 variable to receive the address
|
||||
};
|
||||
|
||||
// return true to continue, false to stop
|
||||
enum set_result
|
||||
{
|
||||
SET_RESULT_CONTINUE = ERROR_SUCCESS, // continue doing the task of the calling api
|
||||
SET_RESULT_UNKNOWN = -100, // omit this value
|
||||
SET_RESULT_DISCARD, // discard this data handling. i.e. it will stop jump to new url if flag is DATA_FLAG_302
|
||||
SET_RESULT_STOP, // this will stop all operations of the api you calling
|
||||
};
|
||||
|
||||
// real usage of these parameters, see the API which use this callback ...
|
||||
typedef set_result(__stdcall* set_data)(const char* data // data buffer
|
||||
, UINT64 len // bytes of data in data-buffer or error code if flag was DATA_FLAG_ERROR
|
||||
, UINT64 total // total bytes of the data for the api which you called
|
||||
, data_flag flag // data flag
|
||||
, void* param); // user defined data, and passing it when call the callback
|
||||
}
|
||||
|
||||
#define INTER_MODULE_CALLBACK(name) \
|
||||
inter_module_data::set_result __stdcall name(const char* data, UINT64 len, UINT64 total, inter_module_data::data_flag flag, void* param)
|
||||
#define INTER_MODULE_CALLBACK_VAR(name) \
|
||||
inter_module_data::set_result (__stdcall *name)(const char* data, UINT64 len, UINT64 total, inter_module_data::data_flag flag, void* param)
|
|
@ -0,0 +1,242 @@
|
|||
// utility for registery operation
|
||||
//
|
||||
// Date: 2019-10-30
|
||||
//
|
||||
#pragma once
|
||||
|
||||
#ifndef _INCLUDED_REF_
|
||||
#define _INCLUDED_REF_
|
||||
#include "../ref/ref.h"
|
||||
#endif
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// export interface for other modules on 2017-08-23 by GB
|
||||
namespace sys_util
|
||||
{
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// registry utilities ...
|
||||
enum _wow_type
|
||||
{
|
||||
WOW_TYPE_DEFAULT = 0, // both given path and the Wow6432Node path in 32-bits app
|
||||
WOW_TYPE_32_BITS, // the same as WOW_TYPE_DEFAULT in 32-bits app
|
||||
WOW_TYPE_64_BITS, // no affect on registry in 32-bits app
|
||||
};
|
||||
|
||||
// if parameter 'temporary' is true, then the key you created would lost after the system restart !!!
|
||||
PORT_API(long) reg_create_key(const wchar_t* path, HKEY* ret = NULL, HKEY root = HKEY_LOCAL_MACHINE, _wow_type type = WOW_TYPE_DEFAULT, bool temporary = false);
|
||||
PORT_API(long) reg_close_key(HKEY key);
|
||||
PORT_API(long) reg_remove_key(const wchar_t* path, HKEY root = HKEY_LOCAL_MACHINE, _wow_type type = WOW_TYPE_DEFAULT);
|
||||
PORT_API(long) reg_remove_value(const wchar_t* path, const wchar_t* val_name, HKEY root = HKEY_LOCAL_MACHINE, _wow_type type = WOW_TYPE_DEFAULT);
|
||||
|
||||
// parameter of cb
|
||||
// data: (const wchar_t*)
|
||||
// len: bytes of data
|
||||
// total: unused
|
||||
// flag: inter_module_data::DATA_FLAG_FINAL
|
||||
// param: the same as the parameter 'param'
|
||||
//
|
||||
// return: error code
|
||||
PORT_API(long) reg_get_string(HKEY root, const wchar_t* path, const wchar_t* name, inter_module_data::set_data cb, void* param, _wow_type type = WOW_TYPE_DEFAULT);
|
||||
PORT_API(long) reg_get_binary(HKEY root, const wchar_t* path, const wchar_t* name, inter_module_data::set_data cb, void* param, _wow_type type = WOW_TYPE_DEFAULT);
|
||||
PORT_API(long) reg_get_integer(HKEY root, const wchar_t* path, const wchar_t* name, int* val, _wow_type type = WOW_TYPE_DEFAULT);
|
||||
PORT_API(long) reg_get_integer(HKEY root, const wchar_t* path, const wchar_t* name, unsigned long long* val, _wow_type type = WOW_TYPE_DEFAULT);
|
||||
|
||||
// parameter of cb
|
||||
// data: (const wchar_t*)key_name
|
||||
// len: (const wchar_t*)path
|
||||
// total: unused
|
||||
// flag: inter_module_data::DATA_FLAG_FINAL
|
||||
// param: the same as the parameter 'param'
|
||||
//
|
||||
// return: error code
|
||||
PORT_API(long) reg_enum_key(HKEY root, const wchar_t* path, inter_module_data::set_data cb, void* param, _wow_type type = WOW_TYPE_DEFAULT);
|
||||
|
||||
// parameter of cb
|
||||
// data: (const wchar_t*) reg_value name
|
||||
// len: (HIDWORD): type - REG_SZ, (wchar_t*)total; REG_DWORD/REG_QWORD, (DWORD/UINT64)total; REG_BINARY, (unsigned char*)total
|
||||
// (LODWORD): bytes of data
|
||||
// total: value
|
||||
// flag: inter_module_data::DATA_FLAG_FINAL
|
||||
// param: the same as the parameter 'param'
|
||||
//
|
||||
// return: error code
|
||||
PORT_API(long) reg_enum_value(HKEY root, const wchar_t* path, inter_module_data::set_data cb, void* param, _wow_type type = WOW_TYPE_DEFAULT);
|
||||
|
||||
// function: set string value
|
||||
// val: can be multi-string fromat such as "123\0456\0789\0\0", in this circumstance, caller must provides val_bytes
|
||||
// val_bytes: length of val, in bytes. will consider as single string if it was 0
|
||||
//
|
||||
// NOTE: this api would not support REG_EXPAND_SZ that with unexpanded string such as %systemroot%
|
||||
PORT_API(long) reg_set_string(HKEY root, const wchar_t* path, const wchar_t* name, const wchar_t* val, int val_bytes = 0, _wow_type type = WOW_TYPE_DEFAULT);
|
||||
PORT_API(long) reg_set_integer(HKEY root, const wchar_t* path, const wchar_t* name, unsigned val, _wow_type type = WOW_TYPE_DEFAULT);
|
||||
PORT_API(long) reg_set_integer(HKEY root, const wchar_t* path, const wchar_t* name, unsigned long long val, _wow_type type = WOW_TYPE_DEFAULT);
|
||||
PORT_API(long) reg_set_binary(HKEY root, const wchar_t* path, const wchar_t* name, unsigned char* val, int val_bytes, _wow_type type = WOW_TYPE_DEFAULT);
|
||||
|
||||
// function: to find the default opener of given file type
|
||||
// file_ext: the extension name of the file, such as ".txt", lead with '.'
|
||||
// cb: data - (const wchar_t*)path_opener
|
||||
PORT_API(long) reg_get_file_opener(const wchar_t* file_ext/*.txt*/, inter_module_data::set_data cb, void* param);
|
||||
|
||||
// function: enumerate installed service
|
||||
// cb: data - (const wchar_t*) reg_service name
|
||||
// len - (const wchar_t*) reg_service path file
|
||||
// total - (const wchar_t*) reg_service description
|
||||
// flag - inter_module_data::DATA_FLAG_FINAL
|
||||
PORT_API(long) reg_enum_service(inter_module_data::set_data cb, void* param);
|
||||
|
||||
// function: enumerate the auto starting program when system power on
|
||||
// cb: data - (const wchar_t*) reg_program name
|
||||
// len - (const wchar_t*) reg_program path file
|
||||
// total - (const wchar_t*) reg_startup parameter
|
||||
// flag - inter_module_data::DATA_FLAG_FINAL
|
||||
PORT_API(long) reg_enum_program_on_system_poweron(inter_module_data::set_data cb, void* param);
|
||||
PORT_API(long) reg_remove_program_on_system_poweron(const wchar_t* name); // the name should be the same as in enum_program_on_system_poweron
|
||||
|
||||
// function: enumerate installed service
|
||||
// cb: data - (const wchar_t*) reg_software display name
|
||||
// len - (const wchar_t*) reg_uninstaller path file
|
||||
// total - (const wchar_t*) reg_publisher
|
||||
// flag - inter_module_data::DATA_FLAG_FINAL
|
||||
PORT_API(long) reg_enum_uninstaller(inter_module_data::set_data cb, void* param);
|
||||
PORT_API(long) reg_reg_uninstaller(const wchar_t* app_name, const wchar_t* display_name, const wchar_t* uninstall_pe, const wchar_t* uninstall_param = NULL
|
||||
, const wchar_t* publisher = NULL, const wchar_t* version = NULL, unsigned size_in_bytes = 0, _wow_type type = WOW_TYPE_DEFAULT);
|
||||
PORT_API(long) reg_del_uninstaller(const wchar_t* app_name, _wow_type type = WOW_TYPE_DEFAULT);
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// wmi utilities ...
|
||||
// initialize a WMI object, use wmi_free to free the returned object
|
||||
PORT_API(void*) wmi_initialize(void);
|
||||
|
||||
// because WMI is query system database, so consider it as registry and provides here ...
|
||||
// function: query system configuration through by WMI
|
||||
// win32_cls: the class name like Win32_xxxx, e.g. "Win32_NetworkAdapterConfiguration"
|
||||
// attr_name: the attribute name in the win32_cls, e.g. "IPAddress" of "Win32_NetworkAdapterConfiguration"
|
||||
// cb: data - value depends on len, see comments of parameter 'len'
|
||||
// len - value type: VT_BSTR(const wchar_t*), VT_I1~8(char*, short*, int*, longlong*), VT_R4/8(float*, double*), VT_BOOL(bool*)
|
||||
// total - unused
|
||||
// flag - inter_module_data::DATA_FLAG_INSTAR in enumeration, and inter_module_data::DATA_FLAG_FINAL at over, then the data is invalid
|
||||
// param - the same as parameter 'param'
|
||||
PORT_API(HRESULT) wmi_query(const wchar_t* win32_cls, const wchar_t* attr_name, inter_module_data::set_data cb, void* param, void* wmi = NULL/*returned by wmi_initialize*/);
|
||||
PORT_API(void) wmi_free(void* wmi/*returned by wmi_initialize*/);
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// service utilities ...
|
||||
enum _svc_state
|
||||
{
|
||||
SVC_STATE_UNKNOWN = 0,
|
||||
SVC_STATE_STOPPED,
|
||||
SVC_STATE_STARTING,
|
||||
SVC_STATE_STOPPING,
|
||||
SVC_STATE_RUNNING,
|
||||
SVC_STATE_RESUMING,
|
||||
SVC_STATE_PAUSING,
|
||||
SVC_STATE_PAUSED,
|
||||
};
|
||||
PORT_API(long) svc_install(const wchar_t* svc_file, const wchar_t* svc_name, const wchar_t* svc_desc, const wchar_t* display_name = NULL);
|
||||
PORT_API(long) svc_uninstall(const wchar_t* svc_name);
|
||||
PORT_API(long) svc_start(const wchar_t* svc_name, DWORD wait_running_timeout = 0/*milliseconds*/);
|
||||
PORT_API(long) svc_pause(const wchar_t* svc_name);
|
||||
PORT_API(long) svc_resume(const wchar_t* svc_name);
|
||||
PORT_API(long) svc_enable(const wchar_t* svc_name, bool enable);
|
||||
PORT_API(long) svc_stop(const wchar_t* svc_name, DWORD wait_stopped_timeout = 0/*milliseconds*/);
|
||||
PORT_API(long) svc_change_pe_file(const wchar_t* svc_name, const wchar_t* to_pe_file);
|
||||
PORT_API(long) svc_change_description(const wchar_t* svc_name, const wchar_t* description);
|
||||
PORT_API(bool) svc_is_running(const wchar_t* svc_name);
|
||||
PORT_API(long) svc_pe_file(const wchar_t* svc_name, inter_module_data::set_data cb, void* param); // NOTE: DLL service will return "%system%\svchost.exe -k name" !!!
|
||||
|
||||
// function: handle the service common command, supporting following commands:
|
||||
// --install: install self, or other service if with "-pe given service file" parameter
|
||||
// --uninstall: uninstall self
|
||||
// --restart: restart self
|
||||
// --start: start self
|
||||
// --stop: stop self
|
||||
// --pause: pause self
|
||||
// --resume: resume self
|
||||
//
|
||||
// return: whether handled the command
|
||||
//
|
||||
// NOTE: this API's codes must be in the service module; if with parameter "-pe given service file" then all operation are both on the given service
|
||||
PORT_API(bool) svc_handle_common_command(const wchar_t* svc_name, const wchar_t* svc_desc, long* err);
|
||||
|
||||
// function: service enter, call this in main() for exe service.... support --install, --uninstall and --restart startup parameter
|
||||
// parameter of cb: see the comment of DATA_FALG_SVC_xxx
|
||||
PORT_API(long) start_as_service(const wchar_t* svc_name, const wchar_t* svc_desc, inter_module_data::set_data cb, void* param, DWORD timer_elapse = 0/*millisecond*/);
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// shortcut utilities ...
|
||||
//
|
||||
// lnk_file: the file which with '.lnk' extension name
|
||||
// target_file: the final file linked by lnk_file
|
||||
//
|
||||
PORT_API(HRESULT) link_create(const wchar_t* lnk_file, const wchar_t* target_file, const wchar_t* start_arguments
|
||||
, const wchar_t* icon_path_file = NULL, int icon_index = 0, const wchar_t* lnk_desc = NULL);
|
||||
|
||||
// icon_index: change the icon in target file of icon index; or not change the icon if it was -1, you can call link_change_icon to change it later
|
||||
PORT_API(HRESULT) link_change_target_file(const wchar_t* lnk_file, const wchar_t* target_file, int icon_index = 0);
|
||||
PORT_API(HRESULT) link_change_icon(const wchar_t* lnk_file, const wchar_t* file_ico, int index = 0);
|
||||
PORT_API(HRESULT) link_change_startup_arguments(const wchar_t* lnk_file, const wchar_t* start_arguments);
|
||||
PORT_API(HRESULT) link_change_description(const wchar_t* lnk_file, const wchar_t* description);
|
||||
PORT_API(long) link_pin_to_taskbar(const wchar_t* lnk_file, bool pin = true);
|
||||
|
||||
// flag: DATA_FLAG_INSTAR for startup arguments, DATA_FLAG_FINAL for the target pe file
|
||||
PORT_API(HRESULT) link_get_target_file(const wchar_t* lnk_file, inter_module_data::set_data cb, void* param);
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////
|
||||
// hardware info
|
||||
enum cpu_cache_type
|
||||
{
|
||||
CPU_CACHE_NULL = 0, // 0 = Null - No more caches.
|
||||
CPU_CACHE_DATA, // 1 = Data Cache.
|
||||
CPU_CACHE_INSTRUCTION, // 2 = Instruction Cache.
|
||||
CPU_CACHE_UNIFIED, // 3 = Unified Cache.
|
||||
CPU_CACHE_COUNT,
|
||||
};
|
||||
typedef struct _cpu_cache
|
||||
{
|
||||
cpu_cache_type type;
|
||||
int level;
|
||||
UINT64 bytes;
|
||||
}CPUCACHE, *LPCPUCACHE;
|
||||
typedef struct _cpu_info
|
||||
{
|
||||
int max_cpuid;
|
||||
int cores;
|
||||
int speed_base; // in MHz, 0 - not got; < 0 is unreliable
|
||||
int speed_max; // in MHz, 0 - not got; < 0 is unreliable
|
||||
char *manufactor;
|
||||
char *product;
|
||||
int cache_num;
|
||||
CPUCACHE caches[4];
|
||||
}CPUINFO, *LPCPUINFO;
|
||||
typedef struct _bios_info
|
||||
{
|
||||
char *base_board_manufactor;
|
||||
char *base_board_product_name;
|
||||
char *base_board_version;
|
||||
char *bios_vendor;
|
||||
char *bios_version;
|
||||
char *bios_release_date;
|
||||
char bios_major_release;
|
||||
char bios_minor_release;
|
||||
char controller_major_release;
|
||||
char controller_minor_release;
|
||||
}BIOSINFO, *LPBIOSINFO;
|
||||
|
||||
// result: data - LPCPUINFO
|
||||
// len - error code, 0 is success
|
||||
// total - unused, always be ZERO
|
||||
// flag - DATA_FLAG_FINAL
|
||||
// param - same as the parameter 'param'
|
||||
PORT_API(bool) get_cpu_info(inter_module_data::set_data result, void* param);
|
||||
|
||||
// result: data - LPBIOSINFO
|
||||
// len - error code, 0 is success
|
||||
// total - unused, always be ZERO
|
||||
// flag - DATA_FLAG_FINAL
|
||||
// param - same as the parameter 'param'
|
||||
PORT_API(bool) get_bios_info(inter_module_data::set_data result, void* param);
|
||||
};
|
||||
|
||||
|
|
@ -0,0 +1,224 @@
|
|||
// thread.h : the base utility for thread pool management
|
||||
//
|
||||
// Author: Gongbing
|
||||
//
|
||||
// Create: 2017-05-20
|
||||
|
||||
#pragma once
|
||||
#ifndef _INCLUDED_REF_
|
||||
#define _INCLUDED_REF_
|
||||
#include "../ref/ref.h"
|
||||
#endif
|
||||
#pragma warning(disable: 4996)
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// thread ...
|
||||
//
|
||||
// purpose: if you CreateThrad and TerminateThread then, the new thread maybe occupying the global
|
||||
// RTL_CRITICAL_SECTION variable in ntdll.dll module. In this situation, all threads that
|
||||
// created by CreateThread will no longer have opportunity to run!!!
|
||||
// This class is providing you to TerminateThread safely
|
||||
|
||||
namespace thread_util
|
||||
{
|
||||
enum _io_direction
|
||||
{
|
||||
IO_WRITE = 1,
|
||||
IO_READ,
|
||||
IO_CONTROL,
|
||||
IO_USER_TYPE_BASE = 10,
|
||||
};
|
||||
#pragma pack(push)
|
||||
#pragma pack(1)
|
||||
typedef struct _ovl_extension : OVERLAPPED
|
||||
{
|
||||
int io_direction; // _io_direction
|
||||
size_t buf_len; // bytes of payload buffer
|
||||
size_t data_len; // valid bytes of payload
|
||||
size_t io_pos; // current IO position
|
||||
char payload[8]; // payload data buffer
|
||||
|
||||
char* user_payload(void)
|
||||
{
|
||||
return payload;
|
||||
}
|
||||
}OVLEX, *LPOVLEX;
|
||||
#pragma pack(pop)
|
||||
|
||||
__declspec(novtable) struct ILock : public ref_util::IRef
|
||||
{
|
||||
COM_API_DECLARE(void, lock(void));
|
||||
COM_API_DECLARE(bool, try_lock(void));
|
||||
COM_API_DECLARE(void, unlock(void));
|
||||
};
|
||||
__declspec(novtable) struct IThreadWorker : public ref_util::IRef
|
||||
{
|
||||
COM_API_DECLARE(void*/*void* tls*/, thread_enter(void)); // you can initialize tls in this method
|
||||
COM_API_DECLARE(void, thread_work(void*/*bind data*/ task_key, LPOVLEX task_data, unsigned data_size, DWORD err_code, void* enter_data));
|
||||
COM_API_DECLARE(void, thread_exit(void* enter_data/*tls*/));
|
||||
};
|
||||
__declspec(novtable) struct IThreadPool : public ref_util::IRef
|
||||
{
|
||||
COM_API_DECLARE(long, add_task(void* task_key, void* task_data, unsigned data_size)); // return 0 when success
|
||||
COM_API_DECLARE(long, stop(void));
|
||||
|
||||
COM_API_DECLARE(long, worker_threads(void));
|
||||
COM_API_DECLARE(long, busy_threads(void));
|
||||
COM_API_DECLARE(long, waiting_task(void));
|
||||
};
|
||||
__declspec(novtable) struct IEventDispatchThreadPool : public IThreadPool // dispach thread pool through by hardware-event mechanism
|
||||
{
|
||||
COM_API_DECLARE(long, bind_object(void* object, void* bind_key));
|
||||
COM_API_DECLARE(long, remove_object(void* object, void* bind_key));
|
||||
};
|
||||
|
||||
class simple_lock
|
||||
{
|
||||
ILock *lck_;
|
||||
|
||||
public:
|
||||
simple_lock(ILock* lck)
|
||||
{
|
||||
lck_ = lck;
|
||||
if (lck_)
|
||||
{
|
||||
//lck_->add_ref();
|
||||
lck_->lock();
|
||||
}
|
||||
}
|
||||
~simple_lock()
|
||||
{
|
||||
if (lck_)
|
||||
{
|
||||
lck_->unlock();
|
||||
//lck_->release();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// for reducing the times of memory copying, request memory from inner - added on 2019-07-28
|
||||
PORT_API(LPOVLEX) inner_buffer_to_OVLEX_head(void* buf/*'buf' is returned by request_inner_buffer*/);
|
||||
PORT_API(char*) request_inner_buffer(size_t bytes);
|
||||
PORT_API(void) free_inner_buffer(void* buf); // free the buffer returned by 'request_inner_buffer'
|
||||
PORT_API(void) free_inner_buffer(LPOVLEX buf); // free the buffer returned by 'request_inner_buffer'
|
||||
|
||||
PORT_API(HANDLE) create_thread(unsigned(__stdcall* thread)(void*), void* param, bool suspend = false, unsigned allow_cpu_mask = -1); // return thread id
|
||||
PORT_API(ILock*) create_lock(void);
|
||||
PORT_API(IThreadPool*) create_thread_pool(IThreadWorker* worker, int desired_threads = 0, unsigned cpu_allow_mask = -1);
|
||||
PORT_API(IEventDispatchThreadPool*) create_event_thread_pool(IThreadWorker* worker, int desired_threads = 0, unsigned cpu_allow_mask = -1);
|
||||
|
||||
// parameter of result:
|
||||
// data: (wchar_t*)thread name, maybe null
|
||||
// len: thread id
|
||||
// total: start address
|
||||
PORT_API(void) enum_threads(DWORD proc_id, inter_module_data::set_data result, void* param);
|
||||
PORT_API(LPVOID) get_thread_start_address(DWORD thread_id);
|
||||
PORT_API(DWORD) get_call_stack(DWORD ebp, DWORD *stack/*caller allocate the buffer*/, int depth = 6, void* ensure_module = NULL/*ensure the module which contains the address ensure_module in the stack, omit if stack_data was valid*/
|
||||
, unsigned char* stack_data = NULL, int stack_bytes = 0); // return depth in stack
|
||||
PORT_API(DWORD) get_thread_call_stack(DWORD thread_id, DWORD *stack/*caller allocate the buffer*/, int depth = 6, void* ensure_module = NULL/*ensure the module which contains the address ensure_module in the stack*/); // return depth in stack
|
||||
PORT_API(void) set_thread_name(DWORD thread_id, const char* thread_name);
|
||||
|
||||
// the parameter 'allow_cpu_mask' is is a bit vector in which each bit represents the processors that a thread is allowed to run on
|
||||
// 1 represent CPU0, 5 represent CPU0 and CPU2, and so on...
|
||||
enum _ict_state
|
||||
{
|
||||
ICT_STATE_NONE = 0,
|
||||
ICT_STATE_START_FAIL,
|
||||
ICT_STATE_RUNNING,
|
||||
ICT_STATE_COMPLETE,
|
||||
};
|
||||
template<class T> // NOTE: class T must derived from ref_util::IRef !!!
|
||||
class invoke_class_thread : public ref_util::refer
|
||||
{
|
||||
void(__stdcall T::* handle_func)(void*);
|
||||
void *param_; // dynamic parameter should free in handle_func !!!
|
||||
T *obj_;
|
||||
HANDLE wait_;
|
||||
HANDLE thread_;
|
||||
unsigned thread_id_;
|
||||
unsigned affinity_mask_;
|
||||
|
||||
_ict_state state_;
|
||||
unsigned start_tick_; // elapse milliseconds if state_ == ICT_STATE_COMPLETE, start time tick counts in others
|
||||
|
||||
public:
|
||||
invoke_class_thread(T* obj, void(__stdcall T::* thread_func)(void*), void* param, unsigned allow_cpu_mask = -1) : state_(ICT_STATE_NONE), start_tick_(0)
|
||||
{
|
||||
if (obj) obj->add_ref();
|
||||
obj_ = obj;
|
||||
param_ = param;
|
||||
handle_func = thread_func;
|
||||
|
||||
wait_ = CreateEvent(NULL, TRUE, FALSE, NULL);
|
||||
thread_ = thread_util::create_thread(invoke_thread, this, false, allow_cpu_mask);
|
||||
if (thread_ == NULL) state_ = ICT_STATE_START_FAIL;
|
||||
else
|
||||
{
|
||||
thread_id_ = GetThreadId(thread_);
|
||||
WaitForSingleObject(wait_, INFINITE);
|
||||
}
|
||||
CloseHandle(wait_);
|
||||
wait_ = NULL;
|
||||
}
|
||||
|
||||
protected:
|
||||
~invoke_class_thread()
|
||||
{
|
||||
if (thread_) CloseHandle(thread_);
|
||||
if (obj_) obj_->release();
|
||||
}
|
||||
|
||||
private:
|
||||
static unsigned WINAPI invoke_thread(void* lp)
|
||||
{
|
||||
invoke_class_thread *obj = (invoke_class_thread*)lp;
|
||||
|
||||
obj->add_ref();
|
||||
obj->state_ = ICT_STATE_RUNNING;
|
||||
obj->start_tick_ = GetTickCount();
|
||||
SetEvent(obj->wait_);
|
||||
(obj->obj_->*obj->handle_func)(obj->param_);
|
||||
obj->state_ = ICT_STATE_COMPLETE;
|
||||
obj->start_tick_ = GetTickCount() - obj->start_tick_;
|
||||
obj->release();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public:
|
||||
unsigned thread_id(void)
|
||||
{
|
||||
return thread_id_;
|
||||
}
|
||||
HANDLE thread(bool take = false)
|
||||
{
|
||||
HANDLE h = thread_;
|
||||
|
||||
if (take)
|
||||
thread_ = NULL;
|
||||
|
||||
return h;
|
||||
}
|
||||
enum _ict_state thread_state(void)
|
||||
{
|
||||
return state_;
|
||||
}
|
||||
unsigned start_tick_count(bool elapse = false)
|
||||
{
|
||||
return elapse && state_ != ICT_STATE_COMPLETE ? GetTickCount() - start_tick_ : start_tick_;
|
||||
}
|
||||
int terminate(int reason = 0)
|
||||
{
|
||||
HANDLE h = OpenThread(THREAD_ALL_ACCESS, FALSE, thread_id_);
|
||||
int err = GetLastError();
|
||||
if (h)
|
||||
{
|
||||
err = TerminateThread(h, reason) ? ERROR_SUCCESS : GetLastError();
|
||||
CloseHandle(h);
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,152 @@
|
|||
// zip_util.h : include utilities for manage zip/unzip
|
||||
//
|
||||
// Author: Gongbing
|
||||
//
|
||||
// Date: 2016-09-25
|
||||
|
||||
#pragma once
|
||||
#ifndef _INCLUDED_REF_
|
||||
#define _INCLUDED_REF_
|
||||
#include "../ref/ref.h"
|
||||
#endif
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
#pragma pack(push)
|
||||
#pragma pack(1)
|
||||
typedef struct zip_local_file_header
|
||||
{
|
||||
unsigned signature; // 0x04034B50
|
||||
unsigned short ver;
|
||||
unsigned short flag;
|
||||
unsigned short compression;
|
||||
unsigned short last_modify_time;
|
||||
unsigned short last_modify_date;
|
||||
unsigned crc;
|
||||
unsigned compressed_size;
|
||||
unsigned uncompressed_size;
|
||||
unsigned short name_len;
|
||||
unsigned short ext_len;
|
||||
char name[0];
|
||||
|
||||
char* extension()
|
||||
{
|
||||
char *ext = NULL;
|
||||
|
||||
if (ext_len)
|
||||
{
|
||||
ext = (char*)this;
|
||||
ext += sizeof(struct zip_local_file_header);
|
||||
ext += name_len;
|
||||
}
|
||||
|
||||
return ext;
|
||||
}
|
||||
}ZIPLFH, *LPZIPLFH;
|
||||
|
||||
typedef struct zip_centeral_file_header
|
||||
{
|
||||
unsigned signature; // 0x02014B50
|
||||
unsigned short ver_zip;
|
||||
unsigned short ver_unzip;
|
||||
unsigned short flag;
|
||||
unsigned short compression;
|
||||
unsigned short last_modify_time;
|
||||
unsigned short last_modify_date;
|
||||
unsigned crc;
|
||||
unsigned compressed_size;
|
||||
unsigned uncompressed_size;
|
||||
unsigned short name_len;
|
||||
unsigned short ext_len;
|
||||
unsigned short comment_len;
|
||||
unsigned short start_disk_number;
|
||||
unsigned short inter_file_attr;
|
||||
unsigned outer_file_attr;
|
||||
unsigned lfh_rva;
|
||||
char file_name[0]; // follwing by extra & comment
|
||||
}ZIPCFH, *LPZIPCFH;
|
||||
#pragma pack(pop)
|
||||
|
||||
|
||||
namespace zip_util
|
||||
{
|
||||
__declspec(novtable) struct IUnzipPack : public ref_util::IRef
|
||||
{
|
||||
// open a local packet file
|
||||
COM_API_DECLARE(int, open(const wchar_t* path_file, const char* pwd = NULL));
|
||||
|
||||
// open a memory packet content
|
||||
COM_API_DECLARE(int, open(void* data, size_t len, const char* pwd = NULL));
|
||||
|
||||
// files: to receive all items include folder
|
||||
// folders: to receive folders in this packet
|
||||
// total_size: to receive every file size(exclude folder)
|
||||
// return: result statu code, ERROR_SUCCESS or other error code
|
||||
COM_API_DECLARE(int, get_files(int *files, int* folders, UINT64* total_size));
|
||||
|
||||
// index: ZERO-based index in this packet
|
||||
// size: to receive the item bytes data in returned buffer
|
||||
// name: to receive the item name, maybe with relative path. call free_zip_buffer to free it
|
||||
// cont: to receive the content, call free_zip_buffer to free it
|
||||
// attr: to receive the item attribute
|
||||
// create_time: to receive the item created time
|
||||
// modi_time: to receive the item last modified time
|
||||
// acc_time: to receive the item last accessed time
|
||||
COM_API_DECLARE(int, get_item(int index, DWORD* attr, wchar_t** name = NULL, char** cont = NULL, UINT64* size = NULL
|
||||
, FILETIME* create_time = NULL, FILETIME* modi_time = NULL, FILETIME* acc_time = NULL));
|
||||
|
||||
// Function: unzip this packet to an existing local directory. caller should ensure the path local_dir is existing already
|
||||
// prog: data - points to a wchar_t* buffer contains the current file path
|
||||
// len - current file bytes of data if flag was DATA_FLAG_FINAL, when flag is DATA_FLAG_ERROR then contains error:
|
||||
// ERROR_ALREADY_EXISTS, return SET_RESULT_DISCARD to reserve the file; SET_RESULT_CONTINUE to overwrite
|
||||
// ERROR_CREATE_FAILED, create local file failed, parameter 'total' is GetLastError
|
||||
// ERROR_DATA_CHECKSUM_ERROR, unzip the file failed, the (wchar_t*)data is unreliable
|
||||
// total- all data bytes to be unzipped
|
||||
// flag - be DATA_FLAG_FINAL always in normal or DATA_FLAG_ERROR if error occurs
|
||||
// param- be prog_param always
|
||||
COM_API_DECLARE(int, unzip_to(const wchar_t* local_dir, inter_module_data::set_data prog, void* prog_param));
|
||||
COM_API_DECLARE(int, close(void));
|
||||
};
|
||||
__declspec(novtable) struct IZipPack : public ref_util::IRef
|
||||
{
|
||||
// add a local file or directory into the packet, rel_path is relative to the packet
|
||||
// rel_path: relative to the packet, only file name if NULL. e.g. 'first\\data.txt' or 'data.txt'
|
||||
COM_API_DECLARE(int, add_local_file(const wchar_t* path_file, const wchar_t* rel_path = NULL));
|
||||
|
||||
// add memory data into the packet, rel_path_name is relative to the packet
|
||||
// rel_path_name: e.g. 'first\\data.txt' or 'data.txt'
|
||||
COM_API_DECLARE(int, add_data(void* data, size_t len, const wchar_t* rel_path_name));
|
||||
|
||||
// add a folder into the packet, only folder, no data. path is relative to the packet
|
||||
// add local directory into the packet, use add_local_file
|
||||
// folder_rel_path_name: e.g. 'folder' or 'top\\folder'
|
||||
COM_API_DECLARE(int, add_folder(const wchar_t* folder_rel_path_name));
|
||||
|
||||
// if you create a memory packet, this will return the start buffer and data length.
|
||||
// the buffer 'data' is caller passed in
|
||||
COM_API_DECLARE(int, get_memory_data(void** data, UINT64* len));
|
||||
|
||||
COM_API_DECLARE(int, close(void));
|
||||
};
|
||||
|
||||
// Function: zip data into stream which leading by 0x1f, 0x8b, ...
|
||||
// data: should be zipped data
|
||||
// len: bytes of data
|
||||
// return: error code
|
||||
PORT_API(int) gzip_zip(const char* data, ULONGLONG len, inter_module_data::set_data result, void* result_param);
|
||||
|
||||
// Function: unzip the gzip data which leading by 0x1f, 0x8b, ...
|
||||
// data: should be unzipped data
|
||||
// len: bytes of data
|
||||
// return: error code
|
||||
PORT_API(int) gzip_unzip(const char* data, ULONGLONG len, inter_module_data::set_data result, void* result_param);
|
||||
|
||||
PORT_API(IZipPack*) create_zip_file(const wchar_t* local_file, const char* pwd = NULL);
|
||||
PORT_API(IZipPack*) create_zip_memory(void* buf, UINT64 len, const char* pwd = NULL);
|
||||
PORT_API(IUnzipPack*) open_zip(const wchar_t* local_file, const char* pwd = NULL);
|
||||
PORT_API(IUnzipPack*) open_zip(void* buf, UINT64 len, const char* pwd = NULL);
|
||||
};
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,30 @@
|
|||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 16
|
||||
VisualStudioVersion = 16.0.32106.194
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "app", "app", "{434BA17E-2347-4C76-97A2-DF9940EEB9FC}"
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "scanner-check", "..\apps\scanner-check\scanner-check.vcxproj", "{A8F24886-2A0E-4D4F-87C0-C752A17183FB}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Win32 = Debug|Win32
|
||||
Release|Win32 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{A8F24886-2A0E-4D4F-87C0-C752A17183FB}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{A8F24886-2A0E-4D4F-87C0-C752A17183FB}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{A8F24886-2A0E-4D4F-87C0-C752A17183FB}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{A8F24886-2A0E-4D4F-87C0-C752A17183FB}.Release|Win32.Build.0 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(NestedProjects) = preSolution
|
||||
{A8F24886-2A0E-4D4F-87C0-C752A17183FB} = {434BA17E-2347-4C76-97A2-DF9940EEB9FC}
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {8F4909F0-C507-4210-A730-BFFBF9773850}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
|
@ -3,7 +3,7 @@
|
|||
#include "base/HGInc.h"
|
||||
|
||||
HGResult HGAPI HGPdtToolDb_CreateUserMgr(const HGChar* host, HGUShort port,
|
||||
const HGChar* user, const HGChar* pwd, HGPdtToolDbUserMgr* userMgr)
|
||||
const HGChar* userName, const HGChar* pwd, HGPdtToolDbUserMgr* userMgr)
|
||||
{
|
||||
if (NULL == userMgr)
|
||||
{
|
||||
|
@ -11,7 +11,7 @@ HGResult HGAPI HGPdtToolDb_CreateUserMgr(const HGChar* host, HGUShort port,
|
|||
}
|
||||
|
||||
HGPdtToolDbUserMgrImpl* userMgrImpl = new HGPdtToolDbUserMgrImpl;
|
||||
HGResult ret = userMgrImpl->Create(host, port, user, pwd);
|
||||
HGResult ret = userMgrImpl->Create(host, port, userName, pwd);
|
||||
if (HGBASE_ERR_OK != ret)
|
||||
{
|
||||
delete userMgrImpl;
|
||||
|
@ -40,6 +40,88 @@ HGResult HGAPI HGPdtToolDb_DestroyUserMgr(HGPdtToolDbUserMgr userMgr)
|
|||
return HGBASE_ERR_OK;
|
||||
}
|
||||
|
||||
HGResult HGAPI HGPdtToolDb_GetUserType(HGPdtToolDbUserMgr userMgr, HGUInt* userType)
|
||||
{
|
||||
if (NULL == userMgr)
|
||||
{
|
||||
return HGBASE_ERR_INVALIDARG;
|
||||
}
|
||||
|
||||
HGPdtToolDbUserMgrImpl* userMgrImpl = (HGPdtToolDbUserMgrImpl*)userMgr;
|
||||
return userMgrImpl->GetUserType(userType);
|
||||
}
|
||||
|
||||
HGResult HGAPI HGPdtToolDb_GetUserName(HGPdtToolDbUserMgr userMgr, HGChar* userName, HGUInt maxLen)
|
||||
{
|
||||
if (NULL == userMgr)
|
||||
{
|
||||
return HGBASE_ERR_INVALIDARG;
|
||||
}
|
||||
|
||||
HGPdtToolDbUserMgrImpl* userMgrImpl = (HGPdtToolDbUserMgrImpl*)userMgr;
|
||||
return userMgrImpl->GetUserName(userName, maxLen);
|
||||
}
|
||||
|
||||
HGResult HGAPI HGPdtToolDb_GetUserList(HGPdtToolDbUserMgr userMgr, HGChar** userNameList, HGUInt maxLen, HGUInt* count)
|
||||
{
|
||||
if (NULL == userMgr)
|
||||
{
|
||||
return HGBASE_ERR_INVALIDARG;
|
||||
}
|
||||
|
||||
HGPdtToolDbUserMgrImpl* userMgrImpl = (HGPdtToolDbUserMgrImpl*)userMgr;
|
||||
return userMgrImpl->GetUserList(userNameList, maxLen, count);
|
||||
}
|
||||
|
||||
HGResult HGAPI HGPdtToolDb_ReleaseUserList(HGChar** userNameList, HGUInt count)
|
||||
{
|
||||
return HGPdtToolDbUserMgrImpl::ReleaseUserList(userNameList, count);
|
||||
}
|
||||
|
||||
HGResult HGAPI HGPdtToolDb_CreateUser(HGPdtToolDbUserMgr userMgr, const HGChar* userName, const HGChar* defPwd)
|
||||
{
|
||||
if (NULL == userMgr)
|
||||
{
|
||||
return HGBASE_ERR_INVALIDARG;
|
||||
}
|
||||
|
||||
HGPdtToolDbUserMgrImpl* userMgrImpl = (HGPdtToolDbUserMgrImpl*)userMgr;
|
||||
return userMgrImpl->CreateUser(userName, defPwd);
|
||||
}
|
||||
|
||||
HGResult HGAPI HGPdtToolDb_DestroyUser(HGPdtToolDbUserMgr userMgr, const HGChar* userName)
|
||||
{
|
||||
if (NULL == userMgr)
|
||||
{
|
||||
return HGBASE_ERR_INVALIDARG;
|
||||
}
|
||||
|
||||
HGPdtToolDbUserMgrImpl* userMgrImpl = (HGPdtToolDbUserMgrImpl*)userMgr;
|
||||
return userMgrImpl->DestroyUser(userName);
|
||||
}
|
||||
|
||||
HGResult HGAPI HGPdtToolDb_SetPassword(HGPdtToolDbUserMgr userMgr, const HGChar* userName, const HGChar* pwd)
|
||||
{
|
||||
if (NULL == userMgr)
|
||||
{
|
||||
return HGBASE_ERR_INVALIDARG;
|
||||
}
|
||||
|
||||
HGPdtToolDbUserMgrImpl* userMgrImpl = (HGPdtToolDbUserMgrImpl*)userMgr;
|
||||
return userMgrImpl->SetPassword(userName, pwd);
|
||||
}
|
||||
|
||||
HGResult HGAPI HGPdtToolDb_ModifyPassword(HGPdtToolDbUserMgr userMgr, const HGChar* oldPwd, const HGChar* newPwd)
|
||||
{
|
||||
if (NULL == userMgr)
|
||||
{
|
||||
return HGBASE_ERR_INVALIDARG;
|
||||
}
|
||||
|
||||
HGPdtToolDbUserMgrImpl* userMgrImpl = (HGPdtToolDbUserMgrImpl*)userMgr;
|
||||
return userMgrImpl->ModifyPassword(oldPwd, newPwd);
|
||||
}
|
||||
|
||||
HGResult HGAPI HGPdtToolDb_Export(HGPdtToolDbUserMgr userMgr, const HGChar* xlsPath)
|
||||
{
|
||||
if (NULL == userMgr)
|
||||
|
|
|
@ -4,6 +4,14 @@ EXPORTS
|
|||
|
||||
HGPdtToolDb_CreateUserMgr
|
||||
HGPdtToolDb_DestroyUserMgr
|
||||
HGPdtToolDb_GetUserType
|
||||
HGPdtToolDb_GetUserName
|
||||
HGPdtToolDb_GetUserList
|
||||
HGPdtToolDb_ReleaseUserList
|
||||
HGPdtToolDb_CreateUser
|
||||
HGPdtToolDb_DestroyUser
|
||||
HGPdtToolDb_SetPassword
|
||||
HGPdtToolDb_ModifyPassword
|
||||
HGPdtToolDb_Export
|
||||
HGPdtToolDb_GetUserConfig
|
||||
HGPdtToolDb_SetUserConfig
|
||||
|
|
|
@ -4,6 +4,11 @@
|
|||
#include "base/HGDef.h"
|
||||
#include "base/HGBaseErr.h"
|
||||
|
||||
/* 管理员账户 */
|
||||
#define HGPDTTOOLDB_USERTYPE_ROOT 1L
|
||||
/* 普通账户 */
|
||||
#define HGPDTTOOLDB_USERTYPE_NORMAL 2L
|
||||
|
||||
/* 拨码开关校验 */
|
||||
#define HGPDTTOOLDB_ENTRYNAME_DIAL_SWITCH 1L
|
||||
/* 检查船型开关功能 */
|
||||
|
@ -91,12 +96,36 @@ HG_DECLARE_HANDLE(HGPdtToolDbDevice);
|
|||
|
||||
/* 登录 */
|
||||
HGEXPORT HGResult HGAPI HGPdtToolDb_CreateUserMgr(const HGChar *host, HGUShort port,
|
||||
const HGChar *user, const HGChar *pwd, HGPdtToolDbUserMgr *userMgr);
|
||||
const HGChar *userName, const HGChar *pwd, HGPdtToolDbUserMgr *userMgr);
|
||||
|
||||
/* 登出 */
|
||||
HGEXPORT HGResult HGAPI HGPdtToolDb_DestroyUserMgr(HGPdtToolDbUserMgr userMgr);
|
||||
|
||||
/* 导出所有设备测试信息到XLS文件 */
|
||||
/* 获取当前账户类型 */
|
||||
HGEXPORT HGResult HGAPI HGPdtToolDb_GetUserType(HGPdtToolDbUserMgr userMgr, HGUInt *userType);
|
||||
|
||||
/* 获取当前账户名称 */
|
||||
HGEXPORT HGResult HGAPI HGPdtToolDb_GetUserName(HGPdtToolDbUserMgr userMgr, HGChar *userName, HGUInt maxLen);
|
||||
|
||||
/* 获取账户列表,需要管理员账户才能调用 */
|
||||
HGEXPORT HGResult HGAPI HGPdtToolDb_GetUserList(HGPdtToolDbUserMgr userMgr, HGChar **userNameList, HGUInt maxLen, HGUInt* count);
|
||||
|
||||
/* 销毁账户列表 */
|
||||
HGEXPORT HGResult HGAPI HGPdtToolDb_ReleaseUserList(HGChar **userNameList, HGUInt count);
|
||||
|
||||
/* 创建账户,需要管理员账户才能调用 */
|
||||
HGEXPORT HGResult HGAPI HGPdtToolDb_CreateUser(HGPdtToolDbUserMgr userMgr, const HGChar *userName, const HGChar* defPwd);
|
||||
|
||||
/* 销毁账户,需要管理员账户才能调用 */
|
||||
HGEXPORT HGResult HGAPI HGPdtToolDb_DestroyUser(HGPdtToolDbUserMgr userMgr, const HGChar* userName);
|
||||
|
||||
/* 设置账户密码,需要管理员账户才能调用 */
|
||||
HGEXPORT HGResult HGAPI HGPdtToolDb_SetPassword(HGPdtToolDbUserMgr userMgr, const HGChar* userName, const HGChar* pwd);
|
||||
|
||||
/* 修改本账户的密码 */
|
||||
HGEXPORT HGResult HGAPI HGPdtToolDb_ModifyPassword(HGPdtToolDbUserMgr userMgr, const HGChar* oldPwd, const HGChar* newPwd);
|
||||
|
||||
/* 导出所有设备测试信息到XLS文件,需要管理员账户才能调用 */
|
||||
HGEXPORT HGResult HGAPI HGPdtToolDb_Export(HGPdtToolDbUserMgr userMgr, const HGChar *xlsPath);
|
||||
|
||||
/* 获取用户配置 */
|
||||
|
|
|
@ -104,13 +104,15 @@
|
|||
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
||||
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
|
||||
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
|
||||
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<AdditionalIncludeDirectories>../include/x86;../../../sdk/include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableUAC>false</EnableUAC>
|
||||
<ModuleDefinitionFile>HGPdtToolDb.def</ModuleDefinitionFile>
|
||||
<AdditionalDependencies>libmysql.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalLibraryDirectories>../lib/x86;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
|
@ -124,6 +126,7 @@
|
|||
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
||||
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
|
||||
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||
<AdditionalIncludeDirectories>../include/x86;../../../sdk/include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
|
@ -132,6 +135,8 @@
|
|||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableUAC>false</EnableUAC>
|
||||
<ModuleDefinitionFile>HGPdtToolDb.def</ModuleDefinitionFile>
|
||||
<AdditionalLibraryDirectories>../lib/x86;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<AdditionalDependencies>libmysql.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
|
@ -143,7 +148,7 @@
|
|||
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
||||
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
|
||||
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
|
||||
<AdditionalIncludeDirectories>../include;../../../sdk/include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<AdditionalIncludeDirectories>../include/x64;../../../sdk/include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
|
@ -165,7 +170,7 @@
|
|||
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
||||
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
|
||||
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||
<AdditionalIncludeDirectories>../include;../../../sdk/include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<AdditionalIncludeDirectories>../include/x64;../../../sdk/include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
|
|
|
@ -101,7 +101,7 @@ const HGChar* PRESSURE_INSPECTION_CN[] =
|
|||
HGPdtToolDbUserMgrImpl::HGPdtToolDbUserMgrImpl()
|
||||
{
|
||||
m_sql = NULL;
|
||||
m_user.clear();
|
||||
m_userName.clear();
|
||||
m_deviceList.clear();
|
||||
}
|
||||
|
||||
|
@ -110,7 +110,7 @@ HGPdtToolDbUserMgrImpl::~HGPdtToolDbUserMgrImpl()
|
|||
|
||||
}
|
||||
|
||||
HGResult HGPdtToolDbUserMgrImpl::Create(const HGChar* host, HGUShort port, const HGChar* user, const HGChar* pwd)
|
||||
HGResult HGPdtToolDbUserMgrImpl::Create(const HGChar* host, HGUShort port, const HGChar* userName, const HGChar* pwd)
|
||||
{
|
||||
if (NULL != m_sql)
|
||||
{
|
||||
|
@ -123,7 +123,7 @@ HGResult HGPdtToolDbUserMgrImpl::Create(const HGChar* host, HGUShort port, const
|
|||
return HGBASE_ERR_FAIL;
|
||||
}
|
||||
|
||||
if (NULL == mysql_real_connect(sql, host, user, pwd, NULL, port, NULL, 0))
|
||||
if (NULL == mysql_real_connect(sql, host, userName, pwd, NULL, port, NULL, 0))
|
||||
{
|
||||
mysql_close(sql);
|
||||
return HGBASE_ERR_FAIL;
|
||||
|
@ -142,16 +142,8 @@ HGResult HGPdtToolDbUserMgrImpl::Create(const HGChar* host, HGUShort port, const
|
|||
mysql_close(sql);
|
||||
return HGBASE_ERR_FAIL;
|
||||
}
|
||||
#if 0
|
||||
mysql_query(sql, "drop table main_test;");
|
||||
mysql_query(sql, "drop table initial_inspection_test;");
|
||||
mysql_query(sql, "drop table initial_inspection_desc;");
|
||||
mysql_query(sql, "drop table image_inspection_test;");
|
||||
mysql_query(sql, "drop table image_inspection_desc;");
|
||||
mysql_query(sql, "drop table pressure_inspection_test;");
|
||||
mysql_query(sql, "drop table pressure_inspection_desc;");
|
||||
#endif
|
||||
if (0 != CreateUserConfigTable(sql, user) && 0 != CreateMainTestTable(sql)
|
||||
|
||||
if (0 != CreateUserConfigTable(sql, userName) || 0 != CreateMainTestTable(sql)
|
||||
|| 0 != CreateInitInspTestTable(sql) || 0 != CreateInitInspDescTable(sql)
|
||||
|| 0 != CreateImgInspTestTable(sql) || 0 != CreateImgInspDescTable(sql)
|
||||
|| 0 != CreatePreInspTestTable(sql) || 0 != CreatePreInspDescTable(sql))
|
||||
|
@ -161,7 +153,7 @@ HGResult HGPdtToolDbUserMgrImpl::Create(const HGChar* host, HGUShort port, const
|
|||
}
|
||||
|
||||
m_sql = sql;
|
||||
m_user = user;
|
||||
m_userName = userName;
|
||||
return HGBASE_ERR_OK;
|
||||
}
|
||||
|
||||
|
@ -174,10 +166,263 @@ HGResult HGPdtToolDbUserMgrImpl::Destroy()
|
|||
|
||||
mysql_close(m_sql);
|
||||
m_sql = NULL;
|
||||
m_user.clear();
|
||||
m_userName.clear();
|
||||
return HGBASE_ERR_OK;
|
||||
}
|
||||
|
||||
HGResult HGPdtToolDbUserMgrImpl::GetUserType(HGUInt* userType)
|
||||
{
|
||||
if (NULL == m_sql)
|
||||
{
|
||||
return HGBASE_ERR_FAIL;
|
||||
}
|
||||
|
||||
if (NULL == userType)
|
||||
{
|
||||
return HGBASE_ERR_INVALIDARG;
|
||||
}
|
||||
|
||||
*userType = HGPDTTOOLDB_USERTYPE_NORMAL;
|
||||
if (0 == strcmp(m_userName.c_str(), "root"))
|
||||
*userType = HGPDTTOOLDB_USERTYPE_ROOT;
|
||||
return HGBASE_ERR_OK;
|
||||
}
|
||||
|
||||
HGResult HGPdtToolDbUserMgrImpl::GetUserName(HGChar* userName, HGUInt maxLen)
|
||||
{
|
||||
if (NULL == m_sql)
|
||||
{
|
||||
return HGBASE_ERR_FAIL;
|
||||
}
|
||||
|
||||
if (NULL == userName || 0 == maxLen)
|
||||
{
|
||||
return HGBASE_ERR_INVALIDARG;
|
||||
}
|
||||
|
||||
if (maxLen < m_userName.size() + 1)
|
||||
{
|
||||
return HGBASE_ERR_FAIL;
|
||||
}
|
||||
|
||||
strcpy(userName, m_userName.c_str());
|
||||
return HGBASE_ERR_OK;
|
||||
}
|
||||
|
||||
HGResult HGPdtToolDbUserMgrImpl::GetUserList(HGChar** userNameList, HGUInt maxLen, HGUInt* count)
|
||||
{
|
||||
if (NULL == m_sql)
|
||||
{
|
||||
return HGBASE_ERR_FAIL;
|
||||
}
|
||||
|
||||
if (NULL == userNameList || 0 == maxLen || NULL == count)
|
||||
{
|
||||
return HGBASE_ERR_INVALIDARG;
|
||||
}
|
||||
|
||||
HGUInt userType = 0;
|
||||
GetUserType(&userType);
|
||||
if (HGPDTTOOLDB_USERTYPE_ROOT != userType)
|
||||
{
|
||||
return HGBASE_ERR_ACCESSDENIED;
|
||||
}
|
||||
|
||||
char sqlCmd[1024] = {0};
|
||||
sprintf(sqlCmd, "select user, host from mysql.user");
|
||||
int ret = mysql_query(m_sql, sqlCmd);
|
||||
if (0 != ret)
|
||||
{
|
||||
return HGBASE_ERR_FAIL;
|
||||
}
|
||||
|
||||
MYSQL_RES* sqlRes = mysql_use_result(m_sql);
|
||||
if (NULL == sqlRes)
|
||||
{
|
||||
return HGBASE_ERR_FAIL;
|
||||
}
|
||||
|
||||
*count = 0;
|
||||
MYSQL_ROW row = NULL;
|
||||
while ((row = mysql_fetch_row(sqlRes)) != NULL)
|
||||
{
|
||||
if (*count >= maxLen)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
assert(NULL != row[0] && NULL != row[1]);
|
||||
if (0 == strcmp(row[1], "%"))
|
||||
{
|
||||
userNameList[*count] = (HGChar*)malloc(strlen(row[0]) + 1);
|
||||
assert(NULL != userNameList[*count]);
|
||||
strcpy(userNameList[*count], row[0]);
|
||||
++(*count);
|
||||
}
|
||||
}
|
||||
|
||||
mysql_free_result(sqlRes);
|
||||
return HGBASE_ERR_OK;
|
||||
}
|
||||
|
||||
HGResult HGPdtToolDbUserMgrImpl::ReleaseUserList(HGChar** userNameList, HGUInt count)
|
||||
{
|
||||
if (NULL == userNameList || 0 == count)
|
||||
{
|
||||
return HGBASE_ERR_INVALIDARG;
|
||||
}
|
||||
|
||||
for (HGUInt i = 0; i < count; ++i)
|
||||
{
|
||||
free(userNameList[i]);
|
||||
}
|
||||
|
||||
return HGBASE_ERR_OK;
|
||||
}
|
||||
|
||||
HGResult HGPdtToolDbUserMgrImpl::CreateUser(const HGChar* userName, const HGChar* defPwd)
|
||||
{
|
||||
if (NULL == m_sql)
|
||||
{
|
||||
return HGBASE_ERR_FAIL;
|
||||
}
|
||||
|
||||
if (NULL == userName || 0 == *userName || NULL == defPwd || 0 == *defPwd)
|
||||
{
|
||||
return HGBASE_ERR_INVALIDARG;
|
||||
}
|
||||
|
||||
HGUInt userType = 0;
|
||||
GetUserType(&userType);
|
||||
if (HGPDTTOOLDB_USERTYPE_ROOT != userType)
|
||||
{
|
||||
return HGBASE_ERR_ACCESSDENIED;
|
||||
}
|
||||
|
||||
if (0 == strcmp(userName, "root"))
|
||||
{
|
||||
return HGBASE_ERR_FAIL;
|
||||
}
|
||||
|
||||
char sqlCmd[1024] = {0};
|
||||
sprintf(sqlCmd, "grant all privileges on huago_production_tool.* to '%s'@'%%' identified by '%s';", userName, defPwd);
|
||||
int ret = mysql_query(m_sql, sqlCmd);
|
||||
return (0 == ret) ? HGBASE_ERR_OK : HGBASE_ERR_FAIL;
|
||||
}
|
||||
|
||||
HGResult HGPdtToolDbUserMgrImpl::DestroyUser(const HGChar* userName)
|
||||
{
|
||||
if (NULL == m_sql)
|
||||
{
|
||||
return HGBASE_ERR_FAIL;
|
||||
}
|
||||
|
||||
if (NULL == userName || 0 == *userName)
|
||||
{
|
||||
return HGBASE_ERR_INVALIDARG;
|
||||
}
|
||||
|
||||
HGUInt userType = 0;
|
||||
GetUserType(&userType);
|
||||
if (HGPDTTOOLDB_USERTYPE_ROOT != userType)
|
||||
{
|
||||
return HGBASE_ERR_ACCESSDENIED;
|
||||
}
|
||||
|
||||
if (0 == strcmp(userName, "root"))
|
||||
{
|
||||
return HGBASE_ERR_FAIL;
|
||||
}
|
||||
|
||||
char sqlCmd[1024] = { 0 };
|
||||
sprintf(sqlCmd, "drop user '%s'@'%%';", userName);
|
||||
int ret = mysql_query(m_sql, sqlCmd);
|
||||
return (0 == ret) ? HGBASE_ERR_OK : HGBASE_ERR_FAIL;
|
||||
}
|
||||
|
||||
HGResult HGPdtToolDbUserMgrImpl::SetPassword(const HGChar* userName, const HGChar* pwd)
|
||||
{
|
||||
if (NULL == m_sql)
|
||||
{
|
||||
return HGBASE_ERR_FAIL;
|
||||
}
|
||||
|
||||
if (NULL == userName || 0 == *userName || NULL == pwd || 0 == *pwd)
|
||||
{
|
||||
return HGBASE_ERR_INVALIDARG;
|
||||
}
|
||||
|
||||
HGUInt userType = 0;
|
||||
GetUserType(&userType);
|
||||
if (HGPDTTOOLDB_USERTYPE_ROOT != userType)
|
||||
{
|
||||
return HGBASE_ERR_ACCESSDENIED;
|
||||
}
|
||||
|
||||
char sqlCmd[1024] = { 0 };
|
||||
sprintf(sqlCmd, "set password for '%s'@'%%' = password('%s');", userName, pwd);
|
||||
int ret = mysql_query(m_sql, sqlCmd);
|
||||
return (0 == ret) ? HGBASE_ERR_OK : HGBASE_ERR_FAIL;
|
||||
}
|
||||
|
||||
HGResult HGPdtToolDbUserMgrImpl::ModifyPassword(const HGChar* oldPwd, const HGChar* newPwd)
|
||||
{
|
||||
if (NULL == m_sql)
|
||||
{
|
||||
return HGBASE_ERR_FAIL;
|
||||
}
|
||||
|
||||
if (NULL == oldPwd || 0 == *oldPwd || NULL == newPwd || 0 == *newPwd)
|
||||
{
|
||||
return HGBASE_ERR_INVALIDARG;
|
||||
}
|
||||
|
||||
std::string oldAuthStr;
|
||||
char sqlCmd[1024] = { 0 };
|
||||
sprintf(sqlCmd, "select authentication_string from mysql.user where user = '%s' and host = '%%';", m_userName.c_str());
|
||||
int ret = mysql_query(m_sql, sqlCmd);
|
||||
if (0 == ret)
|
||||
{
|
||||
MYSQL_RES* sqlRes = mysql_use_result(m_sql);
|
||||
if (NULL != sqlRes)
|
||||
{
|
||||
MYSQL_ROW row = mysql_fetch_row(sqlRes);
|
||||
assert(NULL != row[0]);
|
||||
oldAuthStr = row[0];
|
||||
mysql_free_result(sqlRes);
|
||||
}
|
||||
}
|
||||
|
||||
if (oldAuthStr.empty())
|
||||
{
|
||||
return HGBASE_ERR_FAIL;
|
||||
}
|
||||
|
||||
std::string oldAuthStr2;
|
||||
sprintf(sqlCmd, "select password('%s');", oldPwd);
|
||||
ret = mysql_query(m_sql, sqlCmd);
|
||||
if (0 == ret)
|
||||
{
|
||||
MYSQL_RES* sqlRes = mysql_use_result(m_sql);
|
||||
if (NULL != sqlRes)
|
||||
{
|
||||
MYSQL_ROW row = mysql_fetch_row(sqlRes);
|
||||
assert(NULL != row[0]);
|
||||
oldAuthStr2 = row[0];
|
||||
mysql_free_result(sqlRes);
|
||||
}
|
||||
}
|
||||
|
||||
if (0 != strcmp(oldAuthStr.c_str(), oldAuthStr2.c_str()))
|
||||
{
|
||||
return HGBASE_ERR_FAIL;
|
||||
}
|
||||
|
||||
sprintf(sqlCmd, "set password for '%s'@'%%' = password('%s');", m_userName.c_str(), newPwd);
|
||||
ret = mysql_query(m_sql, sqlCmd);
|
||||
return (0 == ret) ? HGBASE_ERR_OK : HGBASE_ERR_FAIL;
|
||||
}
|
||||
|
||||
HGResult HGPdtToolDbUserMgrImpl::Export(const HGChar* xlsPath)
|
||||
{
|
||||
if (NULL == m_sql)
|
||||
|
@ -190,6 +435,13 @@ HGResult HGPdtToolDbUserMgrImpl::Export(const HGChar* xlsPath)
|
|||
return HGBASE_ERR_INVALIDARG;
|
||||
}
|
||||
|
||||
HGUInt userType = 0;
|
||||
GetUserType(&userType);
|
||||
if (HGPDTTOOLDB_USERTYPE_ROOT != userType)
|
||||
{
|
||||
return HGBASE_ERR_ACCESSDENIED;
|
||||
}
|
||||
|
||||
std::string cmd = "select main_test.sn";
|
||||
cmd += ", main_test.create_time";
|
||||
cmd += ", main_test.create_user";
|
||||
|
@ -336,7 +588,7 @@ HGResult HGPdtToolDbUserMgrImpl::GetConfig(const HGChar* key, HGChar* value, HGU
|
|||
}
|
||||
|
||||
char sqlCmd[1024] = { 0 };
|
||||
sprintf(sqlCmd, "select config_value from %s_config where config_key = '%s';", m_user.c_str(), key);
|
||||
sprintf(sqlCmd, "select config_value from %s_config where config_key = '%s';", m_userName.c_str(), key);
|
||||
int ret = mysql_query(m_sql, sqlCmd);
|
||||
if (0 != ret)
|
||||
{
|
||||
|
@ -388,7 +640,7 @@ HGResult HGPdtToolDbUserMgrImpl::SetConfig(const HGChar* key, const HGChar* valu
|
|||
|
||||
char sqlCmd[1024] = {0};
|
||||
sprintf(sqlCmd, "insert into %s_config (config_key, config_value) values ('%s', '%s')",
|
||||
m_user.c_str(), key, (NULL != value) ? value : "");
|
||||
m_userName.c_str(), key, (NULL != value) ? value : "");
|
||||
int ret = mysql_query(m_sql, sqlCmd);
|
||||
if (0 == ret)
|
||||
{
|
||||
|
@ -398,7 +650,7 @@ HGResult HGPdtToolDbUserMgrImpl::SetConfig(const HGChar* key, const HGChar* valu
|
|||
if (1062 == mysql_errno(m_sql))
|
||||
{
|
||||
sprintf(sqlCmd, "update %s_config set config_value = '%s' where config_key = '%s'",
|
||||
m_user.c_str(), (NULL != value) ? value : "", key);
|
||||
m_userName.c_str(), (NULL != value) ? value : "", key);
|
||||
int ret = mysql_query(m_sql, sqlCmd);
|
||||
return (0 == ret) ? HGBASE_ERR_OK : HGBASE_ERR_FAIL;
|
||||
}
|
||||
|
@ -596,7 +848,7 @@ int HGPdtToolDbUserMgrImpl::InitMainTestItem(const HGChar* sn)
|
|||
assert(NULL != sn && 0 != *sn && NULL != m_sql);
|
||||
|
||||
std::string title = "(sn, create_time, create_user, last_modify_time, last_modify_user)";
|
||||
std::string value = "('" + (std::string)sn + "', now(), '" + m_user + "', now(), '" + m_user + "')";
|
||||
std::string value = "('" + (std::string)sn + "', now(), '" + m_userName + "', now(), '" + m_userName + "')";
|
||||
std::string cmd = (std::string)"insert into main_test " + title + " values " + value + ";";
|
||||
int ret = mysql_query(m_sql, cmd.c_str());
|
||||
return (1062 == mysql_errno(m_sql)) ? 0 : ret;
|
||||
|
@ -672,7 +924,7 @@ HGResult HGPdtToolDbDeviceImpl::SetCurrEntry(HGUInt entryName)
|
|||
|
||||
char sqlCmd[1024] = { 0 };
|
||||
sprintf(sqlCmd, "update main_test set current_entry = %u, last_modify_time = now(), last_modify_user = '%s' where sn = '%s';",
|
||||
entryName, m_userMgr->m_user.c_str(), m_sn.c_str());
|
||||
entryName, m_userMgr->m_userName.c_str(), m_sn.c_str());
|
||||
int ret = mysql_query(m_userMgr->m_sql, sqlCmd);
|
||||
return (0 == ret) ? HGBASE_ERR_OK : HGBASE_ERR_FAIL;
|
||||
}
|
||||
|
@ -750,7 +1002,7 @@ HGResult HGPdtToolDbDeviceImpl::SetEntryStatus(HGUInt entryName, HGUInt entrySta
|
|||
}
|
||||
|
||||
sprintf(sqlCmd, "update main_test set last_modify_time = now(), last_modify_user = '%s' where sn = '%s';",
|
||||
m_userMgr->m_user.c_str(), m_sn.c_str());
|
||||
m_userMgr->m_userName.c_str(), m_sn.c_str());
|
||||
ret = mysql_query(m_userMgr->m_sql, sqlCmd);
|
||||
if (0 != ret)
|
||||
{
|
||||
|
@ -846,7 +1098,7 @@ HGResult HGPdtToolDbDeviceImpl::SetEntryExcepDesc(HGUInt entryName, const HGChar
|
|||
}
|
||||
|
||||
sprintf(sqlCmd, "update main_test set last_modify_time = now(), last_modify_user = '%s' where sn = '%s';",
|
||||
m_userMgr->m_user.c_str(), m_sn.c_str());
|
||||
m_userMgr->m_userName.c_str(), m_sn.c_str());
|
||||
ret = mysql_query(m_userMgr->m_sql, sqlCmd);
|
||||
if (0 != ret)
|
||||
{
|
||||
|
|
|
@ -14,8 +14,16 @@ public:
|
|||
HGPdtToolDbUserMgrImpl();
|
||||
~HGPdtToolDbUserMgrImpl();
|
||||
|
||||
HGResult Create(const HGChar* host, HGUShort port, const HGChar* user, const HGChar* pwd);
|
||||
HGResult Create(const HGChar* host, HGUShort port, const HGChar* userName, const HGChar* pwd);
|
||||
HGResult Destroy();
|
||||
HGResult GetUserType(HGUInt* userType);
|
||||
HGResult GetUserName(HGChar* userName, HGUInt maxLen);
|
||||
HGResult GetUserList(HGChar** userNameList, HGUInt maxLen, HGUInt *count);
|
||||
static HGResult ReleaseUserList(HGChar** userNameList, HGUInt count);
|
||||
HGResult CreateUser(const HGChar* userName, const HGChar* defPwd);
|
||||
HGResult DestroyUser(const HGChar* userName);
|
||||
HGResult SetPassword(const HGChar* userName, const HGChar* pwd);
|
||||
HGResult ModifyPassword(const HGChar* oldPwd, const HGChar* newPwd);
|
||||
HGResult Export(const HGChar* xlsPath);
|
||||
HGResult GetConfig(const HGChar *key, HGChar *value, HGUInt maxLen);
|
||||
HGResult SetConfig(const HGChar* key, const HGChar *value);
|
||||
|
@ -39,7 +47,7 @@ private:
|
|||
|
||||
private:
|
||||
MYSQL* m_sql;
|
||||
std::string m_user;
|
||||
std::string m_userName;
|
||||
std::list<class HGPdtToolDbDeviceImpl*> m_deviceList;
|
||||
};
|
||||
|
||||
|
|
|
@ -5,11 +5,24 @@
|
|||
int main()
|
||||
{
|
||||
HGPdtToolDbUserMgr userMgr = NULL;
|
||||
HGPdtToolDb_CreateUserMgr("127.0.0.1", 3306, "huago", "huago", &userMgr);
|
||||
HGPdtToolDb_CreateUserMgr("127.0.0.1", 3306, "root", "123456", &userMgr);
|
||||
if (NULL != userMgr)
|
||||
{
|
||||
HGPdtToolDb_Export(userMgr, "D:\\1.xls");
|
||||
HGChar* name[256];
|
||||
HGUInt count;
|
||||
HGPdtToolDb_GetUserList(userMgr, name, 256, &count);
|
||||
|
||||
//HGPdtToolDb_DestroyUser(userMgr, "huago");
|
||||
|
||||
//HGPdtToolDb_CreateUser(userMgr, "huago", "huago");
|
||||
HGPdtToolDb_ModifyPassword(userMgr, "12345", "123456");
|
||||
//HGPdtToolDb_SetPassword(userMgr, "huago", "qqq");
|
||||
|
||||
HGPdtToolDbDevice device = NULL;
|
||||
HGPdtToolDb_OpenDevice(userMgr, "G123456", &device);
|
||||
HGPdtToolDb_CloseDevice(device);
|
||||
|
||||
HGPdtToolDb_Export(userMgr, "D:\\1.xls");
|
||||
HGPdtToolDb_DestroyUserMgr(userMgr);
|
||||
}
|
||||
|
||||
|
|
|
@ -88,10 +88,12 @@
|
|||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<AdditionalIncludeDirectories>../../../sdk/include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalDependencies>../Debug/HGPdtToolDb.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
|
@ -102,12 +104,14 @@
|
|||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<AdditionalIncludeDirectories>../../../sdk/include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalDependencies>../Release/HGPdtToolDb.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
|
@ -132,6 +136,7 @@
|
|||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<AdditionalIncludeDirectories>../../../sdk/include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
|
|
|
@ -1,145 +0,0 @@
|
|||
#ifndef ERRMSG_INCLUDED
|
||||
#define ERRMSG_INCLUDED
|
||||
|
||||
/* Copyright (c) 2000, 2022, Oracle and/or its affiliates.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License, version 2.0,
|
||||
as published by the Free Software Foundation.
|
||||
|
||||
This program is also distributed with certain software (including
|
||||
but not limited to OpenSSL) that is licensed under separate terms,
|
||||
as designated in a particular file or component or in included license
|
||||
documentation. The authors of MySQL hereby grant you an additional
|
||||
permission to link the program and your derivative works with the
|
||||
separately licensed software that they have included with MySQL.
|
||||
|
||||
Without limiting anything contained in the foregoing, this file,
|
||||
which is part of C Driver for MySQL (Connector/C), is also subject to the
|
||||
Universal FOSS Exception, version 1.0, a copy of which can be found at
|
||||
http://oss.oracle.com/licenses/universal-foss-exception.
|
||||
|
||||
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, version 2.0, 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 St, Fifth Floor, Boston, MA 02110-1301 USA */
|
||||
|
||||
/**
|
||||
@file include/errmsg.h
|
||||
|
||||
Error messages for MySQL clients.
|
||||
These are constant and use the CR_ prefix.
|
||||
<mysqlclient_ername.h> will contain auto-generated mappings
|
||||
containing the symbolic name and the number from this file,
|
||||
and the english error messages in libmysql/errmsg.c.
|
||||
|
||||
Dynamic error messages for the daemon are in share/language/errmsg.sys.
|
||||
The server equivalent to <errmsg.h> is <mysqld_error.h>.
|
||||
The server equivalent to <mysqlclient_ername.h> is <mysqld_ername.h>.
|
||||
|
||||
Note that the auth subsystem also uses codes with a CR_ prefix.
|
||||
*/
|
||||
|
||||
void init_client_errs(void);
|
||||
void finish_client_errs(void);
|
||||
extern const char *client_errors[]; /* Error messages */
|
||||
|
||||
#define CR_MIN_ERROR 2000 /* For easier client code */
|
||||
#define CR_MAX_ERROR 2999
|
||||
#define CLIENT_ERRMAP 2 /* Errormap used by my_error() */
|
||||
|
||||
/* Do not add error numbers before CR_ERROR_FIRST. */
|
||||
/* If necessary to add lower numbers, change CR_ERROR_FIRST accordingly. */
|
||||
#define CR_ERROR_FIRST 2000 /*Copy first error nr.*/
|
||||
#define CR_UNKNOWN_ERROR 2000
|
||||
#define CR_SOCKET_CREATE_ERROR 2001
|
||||
#define CR_CONNECTION_ERROR 2002
|
||||
#define CR_CONN_HOST_ERROR 2003
|
||||
#define CR_IPSOCK_ERROR 2004
|
||||
#define CR_UNKNOWN_HOST 2005
|
||||
#define CR_SERVER_GONE_ERROR 2006
|
||||
#define CR_VERSION_ERROR 2007
|
||||
#define CR_OUT_OF_MEMORY 2008
|
||||
#define CR_WRONG_HOST_INFO 2009
|
||||
#define CR_LOCALHOST_CONNECTION 2010
|
||||
#define CR_TCP_CONNECTION 2011
|
||||
#define CR_SERVER_HANDSHAKE_ERR 2012
|
||||
#define CR_SERVER_LOST 2013
|
||||
#define CR_COMMANDS_OUT_OF_SYNC 2014
|
||||
#define CR_NAMEDPIPE_CONNECTION 2015
|
||||
#define CR_NAMEDPIPEWAIT_ERROR 2016
|
||||
#define CR_NAMEDPIPEOPEN_ERROR 2017
|
||||
#define CR_NAMEDPIPESETSTATE_ERROR 2018
|
||||
#define CR_CANT_READ_CHARSET 2019
|
||||
#define CR_NET_PACKET_TOO_LARGE 2020
|
||||
#define CR_EMBEDDED_CONNECTION 2021
|
||||
#define CR_PROBE_SLAVE_STATUS 2022
|
||||
#define CR_PROBE_SLAVE_HOSTS 2023
|
||||
#define CR_PROBE_SLAVE_CONNECT 2024
|
||||
#define CR_PROBE_MASTER_CONNECT 2025
|
||||
#define CR_SSL_CONNECTION_ERROR 2026
|
||||
#define CR_MALFORMED_PACKET 2027
|
||||
#define CR_WRONG_LICENSE 2028
|
||||
|
||||
/* new 4.1 error codes */
|
||||
#define CR_NULL_POINTER 2029
|
||||
#define CR_NO_PREPARE_STMT 2030
|
||||
#define CR_PARAMS_NOT_BOUND 2031
|
||||
#define CR_DATA_TRUNCATED 2032
|
||||
#define CR_NO_PARAMETERS_EXISTS 2033
|
||||
#define CR_INVALID_PARAMETER_NO 2034
|
||||
#define CR_INVALID_BUFFER_USE 2035
|
||||
#define CR_UNSUPPORTED_PARAM_TYPE 2036
|
||||
|
||||
#define CR_SHARED_MEMORY_CONNECTION 2037
|
||||
#define CR_SHARED_MEMORY_CONNECT_REQUEST_ERROR 2038
|
||||
#define CR_SHARED_MEMORY_CONNECT_ANSWER_ERROR 2039
|
||||
#define CR_SHARED_MEMORY_CONNECT_FILE_MAP_ERROR 2040
|
||||
#define CR_SHARED_MEMORY_CONNECT_MAP_ERROR 2041
|
||||
#define CR_SHARED_MEMORY_FILE_MAP_ERROR 2042
|
||||
#define CR_SHARED_MEMORY_MAP_ERROR 2043
|
||||
#define CR_SHARED_MEMORY_EVENT_ERROR 2044
|
||||
#define CR_SHARED_MEMORY_CONNECT_ABANDONED_ERROR 2045
|
||||
#define CR_SHARED_MEMORY_CONNECT_SET_ERROR 2046
|
||||
#define CR_CONN_UNKNOW_PROTOCOL 2047
|
||||
#define CR_INVALID_CONN_HANDLE 2048
|
||||
#define CR_UNUSED_1 2049
|
||||
#define CR_FETCH_CANCELED 2050
|
||||
#define CR_NO_DATA 2051
|
||||
#define CR_NO_STMT_METADATA 2052
|
||||
#define CR_NO_RESULT_SET 2053
|
||||
#define CR_NOT_IMPLEMENTED 2054
|
||||
#define CR_SERVER_LOST_EXTENDED 2055
|
||||
#define CR_STMT_CLOSED 2056
|
||||
#define CR_NEW_STMT_METADATA 2057
|
||||
#define CR_ALREADY_CONNECTED 2058
|
||||
#define CR_AUTH_PLUGIN_CANNOT_LOAD 2059
|
||||
#define CR_DUPLICATE_CONNECTION_ATTR 2060
|
||||
#define CR_AUTH_PLUGIN_ERR 2061
|
||||
#define CR_INSECURE_API_ERR 2062
|
||||
#define CR_FILE_NAME_TOO_LONG 2063
|
||||
#define CR_SSL_FIPS_MODE_ERR 2064
|
||||
#define CR_DEPRECATED_COMPRESSION_NOT_SUPPORTED 2065
|
||||
#define CR_COMPRESSION_WRONGLY_CONFIGURED 2066
|
||||
#define CR_KERBEROS_USER_NOT_FOUND 2067
|
||||
#define CR_LOAD_DATA_LOCAL_INFILE_REJECTED 2068
|
||||
#define CR_LOAD_DATA_LOCAL_INFILE_REALPATH_FAIL 2069
|
||||
#define CR_DNS_SRV_LOOKUP_FAILED 2070
|
||||
#define CR_MANDATORY_TRACKER_NOT_FOUND 2071
|
||||
#define CR_INVALID_FACTOR_NO 2072
|
||||
#define CR_CANT_GET_SESSION_DATA 2073
|
||||
#define CR_ERROR_LAST /*Copy last error nr:*/ 2073
|
||||
/* Add error numbers before CR_ERROR_LAST and change it accordingly. */
|
||||
|
||||
/* Visual Studio requires '__inline' for C code */
|
||||
static inline const char *ER_CLIENT(int client_errno) {
|
||||
if (client_errno >= CR_ERROR_FIRST && client_errno <= CR_ERROR_LAST)
|
||||
return client_errors[client_errno - CR_ERROR_FIRST];
|
||||
return client_errors[CR_UNKNOWN_ERROR - CR_ERROR_FIRST];
|
||||
}
|
||||
|
||||
#endif /* ERRMSG_INCLUDED */
|
|
@ -1,103 +0,0 @@
|
|||
/* Copyright (c) 2015, 2022, Oracle and/or its affiliates.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License, version 2.0,
|
||||
as published by the Free Software Foundation.
|
||||
|
||||
This program is also distributed with certain software (including
|
||||
but not limited to OpenSSL) that is licensed under separate terms,
|
||||
as designated in a particular file or component or in included license
|
||||
documentation. The authors of MySQL hereby grant you an additional
|
||||
permission to link the program and your derivative works with the
|
||||
separately licensed software that they have included with MySQL.
|
||||
|
||||
Without limiting anything contained in the foregoing, this file,
|
||||
which is part of C Driver for MySQL (Connector/C), is also subject to the
|
||||
Universal FOSS Exception, version 1.0, a copy of which can be found at
|
||||
http://oss.oracle.com/licenses/universal-foss-exception.
|
||||
|
||||
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, version 2.0, 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 St, Fifth Floor, Boston, MA 02110-1301 USA */
|
||||
|
||||
#ifndef _mysql_command_h
|
||||
#define _mysql_command_h
|
||||
|
||||
/**
|
||||
@file include/my_command.h
|
||||
*/
|
||||
|
||||
/**
|
||||
@enum enum_server_command
|
||||
|
||||
@brief A list of all MySQL protocol commands.
|
||||
|
||||
These are the top level commands the server can receive
|
||||
while it listens for a new command in ::dispatch_command
|
||||
|
||||
@par Warning
|
||||
Add new commands to the end of this list, otherwise old
|
||||
servers won't be able to handle them as 'unsupported'.
|
||||
*/
|
||||
enum enum_server_command {
|
||||
/**
|
||||
Currently refused by the server. See ::dispatch_command.
|
||||
Also used internally to mark the start of a session.
|
||||
*/
|
||||
COM_SLEEP,
|
||||
COM_QUIT, /**< See @ref page_protocol_com_quit */
|
||||
COM_INIT_DB, /**< See @ref page_protocol_com_init_db */
|
||||
COM_QUERY, /**< See @ref page_protocol_com_query */
|
||||
COM_FIELD_LIST, /**< Deprecated. See @ref page_protocol_com_field_list */
|
||||
COM_CREATE_DB, /**< Currently refused by the server. See ::dispatch_command */
|
||||
COM_DROP_DB, /**< Currently refused by the server. See ::dispatch_command */
|
||||
COM_REFRESH, /**< Deprecated. See @ref page_protocol_com_refresh */
|
||||
COM_DEPRECATED_1, /**< Deprecated, used to be COM_SHUTDOWN */
|
||||
COM_STATISTICS, /**< See @ref page_protocol_com_statistics */
|
||||
COM_PROCESS_INFO, /**< Deprecated. See @ref page_protocol_com_process_info */
|
||||
COM_CONNECT, /**< Currently refused by the server. */
|
||||
COM_PROCESS_KILL, /**< Deprecated. See @ref page_protocol_com_process_kill */
|
||||
COM_DEBUG, /**< See @ref page_protocol_com_debug */
|
||||
COM_PING, /**< See @ref page_protocol_com_ping */
|
||||
COM_TIME, /**< Currently refused by the server. */
|
||||
COM_DELAYED_INSERT, /**< Functionality removed. */
|
||||
COM_CHANGE_USER, /**< See @ref page_protocol_com_change_user */
|
||||
COM_BINLOG_DUMP, /**< See @ref page_protocol_com_binlog_dump */
|
||||
COM_TABLE_DUMP,
|
||||
COM_CONNECT_OUT,
|
||||
COM_REGISTER_SLAVE,
|
||||
COM_STMT_PREPARE, /**< See @ref page_protocol_com_stmt_prepare */
|
||||
COM_STMT_EXECUTE, /**< See @ref page_protocol_com_stmt_execute */
|
||||
/** See @ref page_protocol_com_stmt_send_long_data */
|
||||
COM_STMT_SEND_LONG_DATA,
|
||||
COM_STMT_CLOSE, /**< See @ref page_protocol_com_stmt_close */
|
||||
COM_STMT_RESET, /**< See @ref page_protocol_com_stmt_reset */
|
||||
COM_SET_OPTION, /**< See @ref page_protocol_com_set_option */
|
||||
COM_STMT_FETCH, /**< See @ref page_protocol_com_stmt_fetch */
|
||||
/**
|
||||
Currently refused by the server. See ::dispatch_command.
|
||||
Also used internally to mark the session as a "daemon",
|
||||
i.e. non-client THD. Currently the scheduler and the GTID
|
||||
code does use this state.
|
||||
These threads won't be killed by `KILL`
|
||||
|
||||
@sa Event_scheduler::start, ::init_thd, ::kill_one_thread,
|
||||
::Find_thd_with_id
|
||||
*/
|
||||
COM_DAEMON,
|
||||
COM_BINLOG_DUMP_GTID,
|
||||
COM_RESET_CONNECTION, /**< See @ref page_protocol_com_reset_connection */
|
||||
COM_CLONE,
|
||||
COM_SUBSCRIBE_GROUP_REPLICATION_STREAM,
|
||||
/* don't forget to update const char *command_name[] in sql_parse.cc */
|
||||
|
||||
/* Must be last */
|
||||
COM_END /**< Not a real command. Refused. */
|
||||
};
|
||||
|
||||
#endif /* _mysql_command_h */
|
|
@ -1,114 +0,0 @@
|
|||
/* Copyright (c) 2019, 2022, Oracle and/or its affiliates.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License, version 2.0,
|
||||
as published by the Free Software Foundation.
|
||||
|
||||
This program is also distributed with certain software (including
|
||||
but not limited to OpenSSL) that is licensed under separate terms,
|
||||
as designated in a particular file or component or in included license
|
||||
documentation. The authors of MySQL hereby grant you an additional
|
||||
permission to link the program and your derivative works with the
|
||||
separately licensed software that they have included with MySQL.
|
||||
|
||||
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, version 2.0, 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 St, Fifth Floor, Boston, MA 02110-1301 USA */
|
||||
|
||||
#ifndef MY_COMPRESS_INCLUDED
|
||||
#define MY_COMPRESS_INCLUDED
|
||||
|
||||
/* List of valid values for compression_algorithm */
|
||||
enum enum_compression_algorithm {
|
||||
MYSQL_UNCOMPRESSED = 1,
|
||||
MYSQL_ZLIB,
|
||||
MYSQL_ZSTD,
|
||||
MYSQL_INVALID
|
||||
};
|
||||
|
||||
/**
|
||||
Compress context information. relating to zlib compression.
|
||||
*/
|
||||
|
||||
typedef struct mysql_zlib_compress_context {
|
||||
/**
|
||||
Compression level to use in zlib compression.
|
||||
*/
|
||||
unsigned int compression_level;
|
||||
} mysql_zlib_compress_context;
|
||||
|
||||
typedef struct ZSTD_CCtx_s ZSTD_CCtx;
|
||||
typedef struct ZSTD_DCtx_s ZSTD_DCtx;
|
||||
|
||||
/**
|
||||
Compress context information relating to zstd compression.
|
||||
*/
|
||||
|
||||
typedef struct mysql_zstd_compress_context {
|
||||
/**
|
||||
Pointer to compressor context.
|
||||
*/
|
||||
ZSTD_CCtx *cctx;
|
||||
/**
|
||||
Pointer to decompressor context.
|
||||
*/
|
||||
ZSTD_DCtx *dctx;
|
||||
/**
|
||||
Compression level to use in zstd compression.
|
||||
*/
|
||||
unsigned int compression_level;
|
||||
} mysql_zstd_compress_context;
|
||||
|
||||
/**
|
||||
Compression context information.
|
||||
It encapsulate the context information based on compression method and
|
||||
presents a generic struct.
|
||||
*/
|
||||
|
||||
typedef struct mysql_compress_context {
|
||||
enum enum_compression_algorithm algorithm; ///< Compression algorithm name.
|
||||
union {
|
||||
mysql_zlib_compress_context zlib_ctx; ///< Context information of zlib.
|
||||
mysql_zstd_compress_context zstd_ctx; ///< Context information of zstd.
|
||||
} u;
|
||||
} mysql_compress_context;
|
||||
|
||||
/**
|
||||
Get default compression level corresponding to a given compression method.
|
||||
|
||||
@param algorithm Compression Method. Possible values are zlib or zstd.
|
||||
|
||||
@return an unsigned int representing default compression level.
|
||||
6 is the default compression level for zlib and 3 is the
|
||||
default compression level for zstd.
|
||||
*/
|
||||
|
||||
unsigned int mysql_default_compression_level(
|
||||
enum enum_compression_algorithm algorithm);
|
||||
|
||||
/**
|
||||
Initialize a compress context object to be associated with a NET object.
|
||||
|
||||
@param cmp_ctx Pointer to compression context.
|
||||
@param algorithm Compression algorithm.
|
||||
@param compression_level Compression level corresponding to the compression
|
||||
algorithm.
|
||||
*/
|
||||
|
||||
void mysql_compress_context_init(mysql_compress_context *cmp_ctx,
|
||||
enum enum_compression_algorithm algorithm,
|
||||
unsigned int compression_level);
|
||||
/**
|
||||
Deinitialize the compression context allocated.
|
||||
|
||||
@param mysql_compress_ctx Pointer to Compression context.
|
||||
*/
|
||||
|
||||
void mysql_compress_context_deinit(mysql_compress_context *mysql_compress_ctx);
|
||||
|
||||
#endif // MY_COMPRESS_INCLUDED
|
|
@ -1,814 +0,0 @@
|
|||
/* Copyright (c) 2000, 2022, Oracle and/or its affiliates.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License, version 2.0,
|
||||
as published by the Free Software Foundation.
|
||||
|
||||
This program is also distributed with certain software (including
|
||||
but not limited to OpenSSL) that is licensed under separate terms,
|
||||
as designated in a particular file or component or in included license
|
||||
documentation. The authors of MySQL hereby grant you an additional
|
||||
permission to link the program and your derivative works with the
|
||||
separately licensed software that they have included with MySQL.
|
||||
|
||||
Without limiting anything contained in the foregoing, this file,
|
||||
which is part of C Driver for MySQL (Connector/C), is also subject to the
|
||||
Universal FOSS Exception, version 1.0, a copy of which can be found at
|
||||
http://oss.oracle.com/licenses/universal-foss-exception.
|
||||
|
||||
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, version 2.0, 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 St, Fifth Floor, Boston, MA 02110-1301 USA */
|
||||
|
||||
/**
|
||||
@file include/mysql.h
|
||||
This file defines the client API to MySQL and also the ABI of the
|
||||
dynamically linked libmysqlclient.
|
||||
|
||||
The ABI should never be changed in a released product of MySQL,
|
||||
thus you need to take great care when changing the file. In case
|
||||
the file is changed so the ABI is broken, you must also update
|
||||
the SHARED_LIB_MAJOR_VERSION in cmake/mysql_version.cmake
|
||||
*/
|
||||
|
||||
#ifndef _mysql_h
|
||||
#define _mysql_h
|
||||
|
||||
#ifndef MYSQL_ABI_CHECK
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
#endif
|
||||
|
||||
// Legacy definition for the benefit of old code. Use uint64_t in new code.
|
||||
// If you get warnings from printf, use the PRIu64 macro, or, if you need
|
||||
// compatibility with older versions of the client library, cast
|
||||
// before printing.
|
||||
typedef uint64_t my_ulonglong;
|
||||
|
||||
#ifndef my_socket_defined
|
||||
#define my_socket_defined
|
||||
#if defined(_WIN32) && !defined(MYSQL_ABI_CHECK)
|
||||
#include <windows.h>
|
||||
#ifdef WIN32_LEAN_AND_MEAN
|
||||
#include <winsock2.h>
|
||||
#endif
|
||||
#define my_socket SOCKET
|
||||
#else
|
||||
typedef int my_socket;
|
||||
#endif /* _WIN32 && ! MYSQL_ABI_CHECK */
|
||||
#endif /* my_socket_defined */
|
||||
|
||||
// Small extra definition to avoid pulling in my_compiler.h in client code.
|
||||
// IWYU pragma: no_include "my_compiler.h"
|
||||
#ifndef MY_COMPILER_INCLUDED
|
||||
#if !defined(_WIN32) || defined(MYSQL_ABI_CHECK)
|
||||
#define STDCALL
|
||||
#else
|
||||
#define STDCALL __stdcall
|
||||
#endif
|
||||
#endif /* MY_COMPILER_INCLUDED */
|
||||
|
||||
#include "field_types.h"
|
||||
#include "my_list.h"
|
||||
#include "mysql_com.h"
|
||||
|
||||
/* Include declarations of plug-in API */
|
||||
#include "mysql/client_plugin.h" // IWYU pragma: keep
|
||||
|
||||
/*
|
||||
The client should be able to know which version it is compiled against,
|
||||
even if mysql.h doesn't use this information directly.
|
||||
*/
|
||||
#include "mysql_version.h" // IWYU pragma: keep
|
||||
|
||||
// MYSQL_TIME is part of our public API.
|
||||
#include "mysql_time.h" // IWYU pragma: keep
|
||||
|
||||
// The error messages are part of our public API.
|
||||
#include "errmsg.h" // IWYU pragma: keep
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern unsigned int mysql_port;
|
||||
extern char *mysql_unix_port;
|
||||
|
||||
#define CLIENT_NET_RETRY_COUNT 1 /* Retry count */
|
||||
#define CLIENT_NET_READ_TIMEOUT 365 * 24 * 3600 /* Timeout on read */
|
||||
#define CLIENT_NET_WRITE_TIMEOUT 365 * 24 * 3600 /* Timeout on write */
|
||||
|
||||
#define IS_PRI_KEY(n) ((n)&PRI_KEY_FLAG)
|
||||
#define IS_NOT_NULL(n) ((n)&NOT_NULL_FLAG)
|
||||
#define IS_BLOB(n) ((n)&BLOB_FLAG)
|
||||
/**
|
||||
Returns true if the value is a number which does not need quotes for
|
||||
the sql_lex.cc parser to parse correctly.
|
||||
*/
|
||||
#define IS_NUM(t) \
|
||||
(((t) <= MYSQL_TYPE_INT24 && (t) != MYSQL_TYPE_TIMESTAMP) || \
|
||||
(t) == MYSQL_TYPE_YEAR || (t) == MYSQL_TYPE_NEWDECIMAL)
|
||||
#define IS_LONGDATA(t) ((t) >= MYSQL_TYPE_TINY_BLOB && (t) <= MYSQL_TYPE_STRING)
|
||||
|
||||
typedef struct MYSQL_FIELD {
|
||||
char *name; /* Name of column */
|
||||
char *org_name; /* Original column name, if an alias */
|
||||
char *table; /* Table of column if column was a field */
|
||||
char *org_table; /* Org table name, if table was an alias */
|
||||
char *db; /* Database for table */
|
||||
char *catalog; /* Catalog for table */
|
||||
char *def; /* Default value (set by mysql_list_fields) */
|
||||
unsigned long length; /* Width of column (create length) */
|
||||
unsigned long max_length; /* Max width for selected set */
|
||||
unsigned int name_length;
|
||||
unsigned int org_name_length;
|
||||
unsigned int table_length;
|
||||
unsigned int org_table_length;
|
||||
unsigned int db_length;
|
||||
unsigned int catalog_length;
|
||||
unsigned int def_length;
|
||||
unsigned int flags; /* Div flags */
|
||||
unsigned int decimals; /* Number of decimals in field */
|
||||
unsigned int charsetnr; /* Character set */
|
||||
enum enum_field_types type; /* Type of field. See mysql_com.h for types */
|
||||
void *extension;
|
||||
} MYSQL_FIELD;
|
||||
|
||||
typedef char **MYSQL_ROW; /* return data as array of strings */
|
||||
typedef unsigned int MYSQL_FIELD_OFFSET; /* offset to current field */
|
||||
|
||||
#define MYSQL_COUNT_ERROR (~(uint64_t)0)
|
||||
|
||||
/* backward compatibility define - to be removed eventually */
|
||||
#define ER_WARN_DATA_TRUNCATED WARN_DATA_TRUNCATED
|
||||
|
||||
typedef struct MYSQL_ROWS {
|
||||
struct MYSQL_ROWS *next; /* list of rows */
|
||||
MYSQL_ROW data;
|
||||
unsigned long length;
|
||||
} MYSQL_ROWS;
|
||||
|
||||
typedef MYSQL_ROWS *MYSQL_ROW_OFFSET; /* offset to current row */
|
||||
|
||||
struct MEM_ROOT;
|
||||
|
||||
typedef struct MYSQL_DATA {
|
||||
MYSQL_ROWS *data;
|
||||
struct MEM_ROOT *alloc;
|
||||
uint64_t rows;
|
||||
unsigned int fields;
|
||||
} MYSQL_DATA;
|
||||
|
||||
enum mysql_option {
|
||||
MYSQL_OPT_CONNECT_TIMEOUT,
|
||||
MYSQL_OPT_COMPRESS,
|
||||
MYSQL_OPT_NAMED_PIPE,
|
||||
MYSQL_INIT_COMMAND,
|
||||
MYSQL_READ_DEFAULT_FILE,
|
||||
MYSQL_READ_DEFAULT_GROUP,
|
||||
MYSQL_SET_CHARSET_DIR,
|
||||
MYSQL_SET_CHARSET_NAME,
|
||||
MYSQL_OPT_LOCAL_INFILE,
|
||||
MYSQL_OPT_PROTOCOL,
|
||||
MYSQL_SHARED_MEMORY_BASE_NAME,
|
||||
MYSQL_OPT_READ_TIMEOUT,
|
||||
MYSQL_OPT_WRITE_TIMEOUT,
|
||||
MYSQL_OPT_USE_RESULT,
|
||||
MYSQL_REPORT_DATA_TRUNCATION,
|
||||
MYSQL_OPT_RECONNECT,
|
||||
MYSQL_PLUGIN_DIR,
|
||||
MYSQL_DEFAULT_AUTH,
|
||||
MYSQL_OPT_BIND,
|
||||
MYSQL_OPT_SSL_KEY,
|
||||
MYSQL_OPT_SSL_CERT,
|
||||
MYSQL_OPT_SSL_CA,
|
||||
MYSQL_OPT_SSL_CAPATH,
|
||||
MYSQL_OPT_SSL_CIPHER,
|
||||
MYSQL_OPT_SSL_CRL,
|
||||
MYSQL_OPT_SSL_CRLPATH,
|
||||
MYSQL_OPT_CONNECT_ATTR_RESET,
|
||||
MYSQL_OPT_CONNECT_ATTR_ADD,
|
||||
MYSQL_OPT_CONNECT_ATTR_DELETE,
|
||||
MYSQL_SERVER_PUBLIC_KEY,
|
||||
MYSQL_ENABLE_CLEARTEXT_PLUGIN,
|
||||
MYSQL_OPT_CAN_HANDLE_EXPIRED_PASSWORDS,
|
||||
MYSQL_OPT_MAX_ALLOWED_PACKET,
|
||||
MYSQL_OPT_NET_BUFFER_LENGTH,
|
||||
MYSQL_OPT_TLS_VERSION,
|
||||
MYSQL_OPT_SSL_MODE,
|
||||
MYSQL_OPT_GET_SERVER_PUBLIC_KEY,
|
||||
MYSQL_OPT_RETRY_COUNT,
|
||||
MYSQL_OPT_OPTIONAL_RESULTSET_METADATA,
|
||||
MYSQL_OPT_SSL_FIPS_MODE,
|
||||
MYSQL_OPT_TLS_CIPHERSUITES,
|
||||
MYSQL_OPT_COMPRESSION_ALGORITHMS,
|
||||
MYSQL_OPT_ZSTD_COMPRESSION_LEVEL,
|
||||
MYSQL_OPT_LOAD_DATA_LOCAL_DIR,
|
||||
MYSQL_OPT_USER_PASSWORD,
|
||||
MYSQL_OPT_SSL_SESSION_DATA
|
||||
};
|
||||
|
||||
/**
|
||||
@todo remove the "extension", move st_mysql_options completely
|
||||
out of mysql.h
|
||||
*/
|
||||
struct st_mysql_options_extention;
|
||||
|
||||
struct st_mysql_options {
|
||||
unsigned int connect_timeout, read_timeout, write_timeout;
|
||||
unsigned int port, protocol;
|
||||
unsigned long client_flag;
|
||||
char *host, *user, *password, *unix_socket, *db;
|
||||
struct Init_commands_array *init_commands;
|
||||
char *my_cnf_file, *my_cnf_group, *charset_dir, *charset_name;
|
||||
char *ssl_key; /* PEM key file */
|
||||
char *ssl_cert; /* PEM cert file */
|
||||
char *ssl_ca; /* PEM CA file */
|
||||
char *ssl_capath; /* PEM directory of CA-s? */
|
||||
char *ssl_cipher; /* cipher to use */
|
||||
char *shared_memory_base_name;
|
||||
unsigned long max_allowed_packet;
|
||||
bool compress, named_pipe;
|
||||
/**
|
||||
The local address to bind when connecting to remote server.
|
||||
*/
|
||||
char *bind_address;
|
||||
/* 0 - never report, 1 - always report (default) */
|
||||
bool report_data_truncation;
|
||||
|
||||
/* function pointers for local infile support */
|
||||
int (*local_infile_init)(void **, const char *, void *);
|
||||
int (*local_infile_read)(void *, char *, unsigned int);
|
||||
void (*local_infile_end)(void *);
|
||||
int (*local_infile_error)(void *, char *, unsigned int);
|
||||
void *local_infile_userdata;
|
||||
struct st_mysql_options_extention *extension;
|
||||
};
|
||||
|
||||
enum mysql_status {
|
||||
MYSQL_STATUS_READY,
|
||||
MYSQL_STATUS_GET_RESULT,
|
||||
MYSQL_STATUS_USE_RESULT,
|
||||
MYSQL_STATUS_STATEMENT_GET_RESULT
|
||||
};
|
||||
|
||||
enum mysql_protocol_type {
|
||||
MYSQL_PROTOCOL_DEFAULT,
|
||||
MYSQL_PROTOCOL_TCP,
|
||||
MYSQL_PROTOCOL_SOCKET,
|
||||
MYSQL_PROTOCOL_PIPE,
|
||||
MYSQL_PROTOCOL_MEMORY
|
||||
};
|
||||
|
||||
enum mysql_ssl_mode {
|
||||
SSL_MODE_DISABLED = 1,
|
||||
SSL_MODE_PREFERRED,
|
||||
SSL_MODE_REQUIRED,
|
||||
SSL_MODE_VERIFY_CA,
|
||||
SSL_MODE_VERIFY_IDENTITY
|
||||
};
|
||||
|
||||
enum mysql_ssl_fips_mode {
|
||||
SSL_FIPS_MODE_OFF = 0,
|
||||
SSL_FIPS_MODE_ON = 1,
|
||||
SSL_FIPS_MODE_STRICT
|
||||
};
|
||||
|
||||
typedef struct character_set {
|
||||
unsigned int number; /* character set number */
|
||||
unsigned int state; /* character set state */
|
||||
const char *csname; /* character set name */
|
||||
const char *name; /* collation name */
|
||||
const char *comment; /* comment */
|
||||
const char *dir; /* character set directory */
|
||||
unsigned int mbminlen; /* min. length for multibyte strings */
|
||||
unsigned int mbmaxlen; /* max. length for multibyte strings */
|
||||
} MY_CHARSET_INFO;
|
||||
|
||||
struct MYSQL_METHODS;
|
||||
struct MYSQL_STMT;
|
||||
|
||||
typedef struct MYSQL {
|
||||
NET net; /* Communication parameters */
|
||||
unsigned char *connector_fd; /* ConnectorFd for SSL */
|
||||
char *host, *user, *passwd, *unix_socket, *server_version, *host_info;
|
||||
char *info, *db;
|
||||
struct CHARSET_INFO *charset;
|
||||
MYSQL_FIELD *fields;
|
||||
struct MEM_ROOT *field_alloc;
|
||||
uint64_t affected_rows;
|
||||
uint64_t insert_id; /* id if insert on table with NEXTNR */
|
||||
uint64_t extra_info; /* Not used */
|
||||
unsigned long thread_id; /* Id for connection in server */
|
||||
unsigned long packet_length;
|
||||
unsigned int port;
|
||||
unsigned long client_flag, server_capabilities;
|
||||
unsigned int protocol_version;
|
||||
unsigned int field_count;
|
||||
unsigned int server_status;
|
||||
unsigned int server_language;
|
||||
unsigned int warning_count;
|
||||
struct st_mysql_options options;
|
||||
enum mysql_status status;
|
||||
enum enum_resultset_metadata resultset_metadata;
|
||||
bool free_me; /* If free in mysql_close */
|
||||
bool reconnect; /* set to 1 if automatic reconnect */
|
||||
|
||||
/* session-wide random string */
|
||||
char scramble[SCRAMBLE_LENGTH + 1];
|
||||
|
||||
LIST *stmts; /* list of all statements */
|
||||
const struct MYSQL_METHODS *methods;
|
||||
void *thd;
|
||||
/*
|
||||
Points to boolean flag in MYSQL_RES or MYSQL_STMT. We set this flag
|
||||
from mysql_stmt_close if close had to cancel result set of this object.
|
||||
*/
|
||||
bool *unbuffered_fetch_owner;
|
||||
void *extension;
|
||||
} MYSQL;
|
||||
|
||||
typedef struct MYSQL_RES {
|
||||
uint64_t row_count;
|
||||
MYSQL_FIELD *fields;
|
||||
struct MYSQL_DATA *data;
|
||||
MYSQL_ROWS *data_cursor;
|
||||
unsigned long *lengths; /* column lengths of current row */
|
||||
MYSQL *handle; /* for unbuffered reads */
|
||||
const struct MYSQL_METHODS *methods;
|
||||
MYSQL_ROW row; /* If unbuffered read */
|
||||
MYSQL_ROW current_row; /* buffer to current row */
|
||||
struct MEM_ROOT *field_alloc;
|
||||
unsigned int field_count, current_field;
|
||||
bool eof; /* Used by mysql_fetch_row */
|
||||
/* mysql_stmt_close() had to cancel this result */
|
||||
bool unbuffered_fetch_cancelled;
|
||||
enum enum_resultset_metadata metadata;
|
||||
void *extension;
|
||||
} MYSQL_RES;
|
||||
|
||||
/**
|
||||
Flag to indicate that COM_BINLOG_DUMP_GTID should
|
||||
be used rather than COM_BINLOG_DUMP in the @sa mysql_binlog_open().
|
||||
*/
|
||||
#define MYSQL_RPL_GTID (1 << 16)
|
||||
/**
|
||||
Skip HEARBEAT events in the @sa mysql_binlog_fetch().
|
||||
*/
|
||||
#define MYSQL_RPL_SKIP_HEARTBEAT (1 << 17)
|
||||
|
||||
/**
|
||||
Flag to indicate that the heartbeat_event being generated
|
||||
is using the class Heartbeat_event_v2
|
||||
*/
|
||||
#define USE_HEARTBEAT_EVENT_V2 (1 << 1)
|
||||
|
||||
/**
|
||||
Struct for information about a replication stream.
|
||||
|
||||
@sa mysql_binlog_open()
|
||||
@sa mysql_binlog_fetch()
|
||||
@sa mysql_binlog_close()
|
||||
*/
|
||||
typedef struct MYSQL_RPL {
|
||||
size_t file_name_length; /** Length of the 'file_name' or 0 */
|
||||
const char *file_name; /** Filename of the binary log to read */
|
||||
uint64_t start_position; /** Position in the binary log to */
|
||||
/* start reading from */
|
||||
unsigned int server_id; /** Server ID to use when identifying */
|
||||
/* with the master */
|
||||
unsigned int flags; /** Flags, e.g. MYSQL_RPL_GTID */
|
||||
|
||||
/** Size of gtid set data */
|
||||
size_t gtid_set_encoded_size;
|
||||
/** Callback function which is called */
|
||||
/* from @sa mysql_binlog_open() to */
|
||||
/* fill command packet gtid set */
|
||||
void (*fix_gtid_set)(struct MYSQL_RPL *rpl, unsigned char *packet_gtid_set);
|
||||
void *gtid_set_arg; /** GTID set data or an argument for */
|
||||
/* fix_gtid_set() callback function */
|
||||
|
||||
unsigned long size; /** Size of the packet returned by */
|
||||
/* mysql_binlog_fetch() */
|
||||
const unsigned char *buffer; /** Pointer to returned data */
|
||||
} MYSQL_RPL;
|
||||
|
||||
/*
|
||||
Set up and bring down the server; to ensure that applications will
|
||||
work when linked against either the standard client library or the
|
||||
embedded server library, these functions should be called.
|
||||
*/
|
||||
int STDCALL mysql_server_init(int argc, char **argv, char **groups);
|
||||
void STDCALL mysql_server_end(void);
|
||||
|
||||
/*
|
||||
mysql_server_init/end need to be called when using libmysqld or
|
||||
libmysqlclient (exactly, mysql_server_init() is called by mysql_init() so
|
||||
you don't need to call it explicitly; but you need to call
|
||||
mysql_server_end() to free memory). The names are a bit misleading
|
||||
(mysql_SERVER* to be used when using libmysqlCLIENT). So we add more general
|
||||
names which suit well whether you're using libmysqld or libmysqlclient. We
|
||||
intend to promote these aliases over the mysql_server* ones.
|
||||
*/
|
||||
#define mysql_library_init mysql_server_init
|
||||
#define mysql_library_end mysql_server_end
|
||||
|
||||
/*
|
||||
Set up and bring down a thread; these function should be called
|
||||
for each thread in an application which opens at least one MySQL
|
||||
connection. All uses of the connection(s) should be between these
|
||||
function calls.
|
||||
*/
|
||||
bool STDCALL mysql_thread_init(void);
|
||||
void STDCALL mysql_thread_end(void);
|
||||
|
||||
/*
|
||||
Functions to get information from the MYSQL and MYSQL_RES structures
|
||||
Should definitely be used if one uses shared libraries.
|
||||
*/
|
||||
|
||||
uint64_t STDCALL mysql_num_rows(MYSQL_RES *res);
|
||||
unsigned int STDCALL mysql_num_fields(MYSQL_RES *res);
|
||||
bool STDCALL mysql_eof(MYSQL_RES *res);
|
||||
MYSQL_FIELD *STDCALL mysql_fetch_field_direct(MYSQL_RES *res,
|
||||
unsigned int fieldnr);
|
||||
MYSQL_FIELD *STDCALL mysql_fetch_fields(MYSQL_RES *res);
|
||||
MYSQL_ROW_OFFSET STDCALL mysql_row_tell(MYSQL_RES *res);
|
||||
MYSQL_FIELD_OFFSET STDCALL mysql_field_tell(MYSQL_RES *res);
|
||||
enum enum_resultset_metadata STDCALL mysql_result_metadata(MYSQL_RES *result);
|
||||
|
||||
unsigned int STDCALL mysql_field_count(MYSQL *mysql);
|
||||
uint64_t STDCALL mysql_affected_rows(MYSQL *mysql);
|
||||
uint64_t STDCALL mysql_insert_id(MYSQL *mysql);
|
||||
unsigned int STDCALL mysql_errno(MYSQL *mysql);
|
||||
const char *STDCALL mysql_error(MYSQL *mysql);
|
||||
const char *STDCALL mysql_sqlstate(MYSQL *mysql);
|
||||
unsigned int STDCALL mysql_warning_count(MYSQL *mysql);
|
||||
const char *STDCALL mysql_info(MYSQL *mysql);
|
||||
unsigned long STDCALL mysql_thread_id(MYSQL *mysql);
|
||||
const char *STDCALL mysql_character_set_name(MYSQL *mysql);
|
||||
int STDCALL mysql_set_character_set(MYSQL *mysql, const char *csname);
|
||||
|
||||
MYSQL *STDCALL mysql_init(MYSQL *mysql);
|
||||
bool STDCALL mysql_ssl_set(MYSQL *mysql, const char *key, const char *cert,
|
||||
const char *ca, const char *capath,
|
||||
const char *cipher);
|
||||
const char *STDCALL mysql_get_ssl_cipher(MYSQL *mysql);
|
||||
bool STDCALL mysql_get_ssl_session_reused(MYSQL *mysql);
|
||||
void *STDCALL mysql_get_ssl_session_data(MYSQL *mysql, unsigned int n_ticket,
|
||||
unsigned int *out_len);
|
||||
bool STDCALL mysql_free_ssl_session_data(MYSQL *mysql, void *data);
|
||||
bool STDCALL mysql_change_user(MYSQL *mysql, const char *user,
|
||||
const char *passwd, const char *db);
|
||||
MYSQL *STDCALL mysql_real_connect(MYSQL *mysql, const char *host,
|
||||
const char *user, const char *passwd,
|
||||
const char *db, unsigned int port,
|
||||
const char *unix_socket,
|
||||
unsigned long clientflag);
|
||||
int STDCALL mysql_select_db(MYSQL *mysql, const char *db);
|
||||
int STDCALL mysql_query(MYSQL *mysql, const char *q);
|
||||
int STDCALL mysql_send_query(MYSQL *mysql, const char *q, unsigned long length);
|
||||
int STDCALL mysql_real_query(MYSQL *mysql, const char *q, unsigned long length);
|
||||
MYSQL_RES *STDCALL mysql_store_result(MYSQL *mysql);
|
||||
MYSQL_RES *STDCALL mysql_use_result(MYSQL *mysql);
|
||||
|
||||
enum net_async_status STDCALL mysql_real_connect_nonblocking(
|
||||
MYSQL *mysql, const char *host, const char *user, const char *passwd,
|
||||
const char *db, unsigned int port, const char *unix_socket,
|
||||
unsigned long clientflag);
|
||||
enum net_async_status STDCALL mysql_send_query_nonblocking(
|
||||
MYSQL *mysql, const char *query, unsigned long length);
|
||||
enum net_async_status STDCALL mysql_real_query_nonblocking(
|
||||
MYSQL *mysql, const char *query, unsigned long length);
|
||||
enum net_async_status STDCALL
|
||||
mysql_store_result_nonblocking(MYSQL *mysql, MYSQL_RES **result);
|
||||
enum net_async_status STDCALL mysql_next_result_nonblocking(MYSQL *mysql);
|
||||
enum net_async_status STDCALL mysql_select_db_nonblocking(MYSQL *mysql,
|
||||
const char *db,
|
||||
bool *error);
|
||||
void STDCALL mysql_get_character_set_info(MYSQL *mysql,
|
||||
MY_CHARSET_INFO *charset);
|
||||
|
||||
int STDCALL mysql_session_track_get_first(MYSQL *mysql,
|
||||
enum enum_session_state_type type,
|
||||
const char **data, size_t *length);
|
||||
int STDCALL mysql_session_track_get_next(MYSQL *mysql,
|
||||
enum enum_session_state_type type,
|
||||
const char **data, size_t *length);
|
||||
/* local infile support */
|
||||
|
||||
#define LOCAL_INFILE_ERROR_LEN 512
|
||||
|
||||
void mysql_set_local_infile_handler(
|
||||
MYSQL *mysql, int (*local_infile_init)(void **, const char *, void *),
|
||||
int (*local_infile_read)(void *, char *, unsigned int),
|
||||
void (*local_infile_end)(void *),
|
||||
int (*local_infile_error)(void *, char *, unsigned int), void *);
|
||||
|
||||
void mysql_set_local_infile_default(MYSQL *mysql);
|
||||
int STDCALL mysql_shutdown(MYSQL *mysql,
|
||||
enum mysql_enum_shutdown_level shutdown_level);
|
||||
int STDCALL mysql_dump_debug_info(MYSQL *mysql);
|
||||
int STDCALL mysql_refresh(MYSQL *mysql, unsigned int refresh_options);
|
||||
int STDCALL mysql_kill(MYSQL *mysql, unsigned long pid);
|
||||
int STDCALL mysql_set_server_option(MYSQL *mysql,
|
||||
enum enum_mysql_set_option option);
|
||||
int STDCALL mysql_ping(MYSQL *mysql);
|
||||
const char *STDCALL mysql_stat(MYSQL *mysql);
|
||||
const char *STDCALL mysql_get_server_info(MYSQL *mysql);
|
||||
const char *STDCALL mysql_get_client_info(void);
|
||||
unsigned long STDCALL mysql_get_client_version(void);
|
||||
const char *STDCALL mysql_get_host_info(MYSQL *mysql);
|
||||
unsigned long STDCALL mysql_get_server_version(MYSQL *mysql);
|
||||
unsigned int STDCALL mysql_get_proto_info(MYSQL *mysql);
|
||||
MYSQL_RES *STDCALL mysql_list_dbs(MYSQL *mysql, const char *wild);
|
||||
MYSQL_RES *STDCALL mysql_list_tables(MYSQL *mysql, const char *wild);
|
||||
MYSQL_RES *STDCALL mysql_list_processes(MYSQL *mysql);
|
||||
int STDCALL mysql_options(MYSQL *mysql, enum mysql_option option,
|
||||
const void *arg);
|
||||
int STDCALL mysql_options4(MYSQL *mysql, enum mysql_option option,
|
||||
const void *arg1, const void *arg2);
|
||||
int STDCALL mysql_get_option(MYSQL *mysql, enum mysql_option option,
|
||||
const void *arg);
|
||||
void STDCALL mysql_free_result(MYSQL_RES *result);
|
||||
enum net_async_status STDCALL mysql_free_result_nonblocking(MYSQL_RES *result);
|
||||
void STDCALL mysql_data_seek(MYSQL_RES *result, uint64_t offset);
|
||||
MYSQL_ROW_OFFSET STDCALL mysql_row_seek(MYSQL_RES *result,
|
||||
MYSQL_ROW_OFFSET offset);
|
||||
MYSQL_FIELD_OFFSET STDCALL mysql_field_seek(MYSQL_RES *result,
|
||||
MYSQL_FIELD_OFFSET offset);
|
||||
MYSQL_ROW STDCALL mysql_fetch_row(MYSQL_RES *result);
|
||||
enum net_async_status STDCALL mysql_fetch_row_nonblocking(MYSQL_RES *res,
|
||||
MYSQL_ROW *row);
|
||||
|
||||
unsigned long *STDCALL mysql_fetch_lengths(MYSQL_RES *result);
|
||||
MYSQL_FIELD *STDCALL mysql_fetch_field(MYSQL_RES *result);
|
||||
MYSQL_RES *STDCALL mysql_list_fields(MYSQL *mysql, const char *table,
|
||||
const char *wild);
|
||||
unsigned long STDCALL mysql_escape_string(char *to, const char *from,
|
||||
unsigned long from_length);
|
||||
unsigned long STDCALL mysql_hex_string(char *to, const char *from,
|
||||
unsigned long from_length);
|
||||
unsigned long STDCALL mysql_real_escape_string(MYSQL *mysql, char *to,
|
||||
const char *from,
|
||||
unsigned long length);
|
||||
unsigned long STDCALL mysql_real_escape_string_quote(MYSQL *mysql, char *to,
|
||||
const char *from,
|
||||
unsigned long length,
|
||||
char quote);
|
||||
void STDCALL mysql_debug(const char *debug);
|
||||
void STDCALL myodbc_remove_escape(MYSQL *mysql, char *name);
|
||||
unsigned int STDCALL mysql_thread_safe(void);
|
||||
bool STDCALL mysql_read_query_result(MYSQL *mysql);
|
||||
int STDCALL mysql_reset_connection(MYSQL *mysql);
|
||||
|
||||
int STDCALL mysql_binlog_open(MYSQL *mysql, MYSQL_RPL *rpl);
|
||||
int STDCALL mysql_binlog_fetch(MYSQL *mysql, MYSQL_RPL *rpl);
|
||||
void STDCALL mysql_binlog_close(MYSQL *mysql, MYSQL_RPL *rpl);
|
||||
|
||||
/*
|
||||
The following definitions are added for the enhanced
|
||||
client-server protocol
|
||||
*/
|
||||
|
||||
/* statement state */
|
||||
enum enum_mysql_stmt_state {
|
||||
MYSQL_STMT_INIT_DONE = 1,
|
||||
MYSQL_STMT_PREPARE_DONE,
|
||||
MYSQL_STMT_EXECUTE_DONE,
|
||||
MYSQL_STMT_FETCH_DONE
|
||||
};
|
||||
|
||||
/*
|
||||
This structure is used to define bind information, and
|
||||
internally by the client library.
|
||||
Public members with their descriptions are listed below
|
||||
(conventionally `On input' refers to the binds given to
|
||||
mysql_stmt_bind_param, `On output' refers to the binds given
|
||||
to mysql_stmt_bind_result):
|
||||
|
||||
buffer_type - One of the MYSQL_* types, used to describe
|
||||
the host language type of buffer.
|
||||
On output: if column type is different from
|
||||
buffer_type, column value is automatically converted
|
||||
to buffer_type before it is stored in the buffer.
|
||||
buffer - On input: points to the buffer with input data.
|
||||
On output: points to the buffer capable to store
|
||||
output data.
|
||||
The type of memory pointed by buffer must correspond
|
||||
to buffer_type. See the correspondence table in
|
||||
the comment to mysql_stmt_bind_param.
|
||||
|
||||
The two above members are mandatory for any kind of bind.
|
||||
|
||||
buffer_length - the length of the buffer. You don't have to set
|
||||
it for any fixed length buffer: float, double,
|
||||
int, etc. It must be set however for variable-length
|
||||
types, such as BLOBs or STRINGs.
|
||||
|
||||
length - On input: in case when lengths of input values
|
||||
are different for each execute, you can set this to
|
||||
point at a variable containing value length. This
|
||||
way the value length can be different in each execute.
|
||||
If length is not NULL, buffer_length is not used.
|
||||
Note, length can even point at buffer_length if
|
||||
you keep bind structures around while fetching:
|
||||
this way you can change buffer_length before
|
||||
each execution, everything will work ok.
|
||||
On output: if length is set, mysql_stmt_fetch will
|
||||
write column length into it.
|
||||
|
||||
is_null - On input: points to a boolean variable that should
|
||||
be set to TRUE for NULL values.
|
||||
This member is useful only if your data may be
|
||||
NULL in some but not all cases.
|
||||
If your data is never NULL, is_null should be set to 0.
|
||||
If your data is always NULL, set buffer_type
|
||||
to MYSQL_TYPE_NULL, and is_null will not be used.
|
||||
|
||||
is_unsigned - On input: used to signify that values provided for one
|
||||
of numeric types are unsigned.
|
||||
On output describes signedness of the output buffer.
|
||||
If, taking into account is_unsigned flag, column data
|
||||
is out of range of the output buffer, data for this column
|
||||
is regarded truncated. Note that this has no correspondence
|
||||
to the sign of result set column, if you need to find it out
|
||||
use mysql_stmt_result_metadata.
|
||||
error - where to write a truncation error if it is present.
|
||||
possible error value is:
|
||||
0 no truncation
|
||||
1 value is out of range or buffer is too small
|
||||
|
||||
Please note that MYSQL_BIND also has internals members.
|
||||
*/
|
||||
|
||||
typedef struct MYSQL_BIND {
|
||||
unsigned long *length; /* output length pointer */
|
||||
bool *is_null; /* Pointer to null indicator */
|
||||
void *buffer; /* buffer to get/put data */
|
||||
/* set this if you want to track data truncations happened during fetch */
|
||||
bool *error;
|
||||
unsigned char *row_ptr; /* for the current data position */
|
||||
void (*store_param_func)(NET *net, struct MYSQL_BIND *param);
|
||||
void (*fetch_result)(struct MYSQL_BIND *, MYSQL_FIELD *, unsigned char **row);
|
||||
void (*skip_result)(struct MYSQL_BIND *, MYSQL_FIELD *, unsigned char **row);
|
||||
/* output buffer length, must be set when fetching str/binary */
|
||||
unsigned long buffer_length;
|
||||
unsigned long offset; /* offset position for char/binary fetch */
|
||||
unsigned long length_value; /* Used if length is 0 */
|
||||
unsigned int param_number; /* For null count and error messages */
|
||||
unsigned int pack_length; /* Internal length for packed data */
|
||||
enum enum_field_types buffer_type; /* buffer type */
|
||||
bool error_value; /* used if error is 0 */
|
||||
bool is_unsigned; /* set if integer type is unsigned */
|
||||
bool long_data_used; /* If used with mysql_send_long_data */
|
||||
bool is_null_value; /* Used if is_null is 0 */
|
||||
void *extension;
|
||||
} MYSQL_BIND;
|
||||
|
||||
struct MYSQL_STMT_EXT;
|
||||
|
||||
/* statement handler */
|
||||
typedef struct MYSQL_STMT {
|
||||
struct MEM_ROOT *mem_root; /* root allocations */
|
||||
LIST list; /* list to keep track of all stmts */
|
||||
MYSQL *mysql; /* connection handle */
|
||||
MYSQL_BIND *params; /* input parameters */
|
||||
MYSQL_BIND *bind; /* output parameters */
|
||||
MYSQL_FIELD *fields; /* result set metadata */
|
||||
MYSQL_DATA result; /* cached result set */
|
||||
MYSQL_ROWS *data_cursor; /* current row in cached result */
|
||||
/*
|
||||
mysql_stmt_fetch() calls this function to fetch one row (it's different
|
||||
for buffered, unbuffered and cursor fetch).
|
||||
*/
|
||||
int (*read_row_func)(struct MYSQL_STMT *stmt, unsigned char **row);
|
||||
/* copy of mysql->affected_rows after statement execution */
|
||||
uint64_t affected_rows;
|
||||
uint64_t insert_id; /* copy of mysql->insert_id */
|
||||
unsigned long stmt_id; /* Id for prepared statement */
|
||||
unsigned long flags; /* i.e. type of cursor to open */
|
||||
unsigned long prefetch_rows; /* number of rows per one COM_FETCH */
|
||||
/*
|
||||
Copied from mysql->server_status after execute/fetch to know
|
||||
server-side cursor status for this statement.
|
||||
*/
|
||||
unsigned int server_status;
|
||||
unsigned int last_errno; /* error code */
|
||||
unsigned int param_count; /* input parameter count */
|
||||
unsigned int field_count; /* number of columns in result set */
|
||||
enum enum_mysql_stmt_state state; /* statement state */
|
||||
char last_error[MYSQL_ERRMSG_SIZE]; /* error message */
|
||||
char sqlstate[SQLSTATE_LENGTH + 1];
|
||||
/* Types of input parameters should be sent to server */
|
||||
bool send_types_to_server;
|
||||
bool bind_param_done; /* input buffers were supplied */
|
||||
unsigned char bind_result_done; /* output buffers were supplied */
|
||||
/* mysql_stmt_close() had to cancel this result */
|
||||
bool unbuffered_fetch_cancelled;
|
||||
/*
|
||||
Is set to true if we need to calculate field->max_length for
|
||||
metadata fields when doing mysql_stmt_store_result.
|
||||
*/
|
||||
bool update_max_length;
|
||||
struct MYSQL_STMT_EXT *extension;
|
||||
} MYSQL_STMT;
|
||||
|
||||
enum enum_stmt_attr_type {
|
||||
/*
|
||||
When doing mysql_stmt_store_result calculate max_length attribute
|
||||
of statement metadata. This is to be consistent with the old API,
|
||||
where this was done automatically.
|
||||
In the new API we do that only by request because it slows down
|
||||
mysql_stmt_store_result sufficiently.
|
||||
*/
|
||||
STMT_ATTR_UPDATE_MAX_LENGTH,
|
||||
/*
|
||||
unsigned long with combination of cursor flags (read only, for update,
|
||||
etc)
|
||||
*/
|
||||
STMT_ATTR_CURSOR_TYPE,
|
||||
/*
|
||||
Amount of rows to retrieve from server per one fetch if using cursors.
|
||||
Accepts unsigned long attribute in the range 1 - ulong_max
|
||||
*/
|
||||
STMT_ATTR_PREFETCH_ROWS
|
||||
};
|
||||
|
||||
bool STDCALL mysql_bind_param(MYSQL *mysql, unsigned n_params,
|
||||
MYSQL_BIND *binds, const char **names);
|
||||
|
||||
MYSQL_STMT *STDCALL mysql_stmt_init(MYSQL *mysql);
|
||||
int STDCALL mysql_stmt_prepare(MYSQL_STMT *stmt, const char *query,
|
||||
unsigned long length);
|
||||
int STDCALL mysql_stmt_execute(MYSQL_STMT *stmt);
|
||||
int STDCALL mysql_stmt_fetch(MYSQL_STMT *stmt);
|
||||
int STDCALL mysql_stmt_fetch_column(MYSQL_STMT *stmt, MYSQL_BIND *bind_arg,
|
||||
unsigned int column, unsigned long offset);
|
||||
int STDCALL mysql_stmt_store_result(MYSQL_STMT *stmt);
|
||||
unsigned long STDCALL mysql_stmt_param_count(MYSQL_STMT *stmt);
|
||||
bool STDCALL mysql_stmt_attr_set(MYSQL_STMT *stmt,
|
||||
enum enum_stmt_attr_type attr_type,
|
||||
const void *attr);
|
||||
bool STDCALL mysql_stmt_attr_get(MYSQL_STMT *stmt,
|
||||
enum enum_stmt_attr_type attr_type,
|
||||
void *attr);
|
||||
bool STDCALL mysql_stmt_bind_param(MYSQL_STMT *stmt, MYSQL_BIND *bnd);
|
||||
bool STDCALL mysql_stmt_bind_result(MYSQL_STMT *stmt, MYSQL_BIND *bnd);
|
||||
bool STDCALL mysql_stmt_close(MYSQL_STMT *stmt);
|
||||
bool STDCALL mysql_stmt_reset(MYSQL_STMT *stmt);
|
||||
bool STDCALL mysql_stmt_free_result(MYSQL_STMT *stmt);
|
||||
bool STDCALL mysql_stmt_send_long_data(MYSQL_STMT *stmt,
|
||||
unsigned int param_number,
|
||||
const char *data, unsigned long length);
|
||||
MYSQL_RES *STDCALL mysql_stmt_result_metadata(MYSQL_STMT *stmt);
|
||||
MYSQL_RES *STDCALL mysql_stmt_param_metadata(MYSQL_STMT *stmt);
|
||||
unsigned int STDCALL mysql_stmt_errno(MYSQL_STMT *stmt);
|
||||
const char *STDCALL mysql_stmt_error(MYSQL_STMT *stmt);
|
||||
const char *STDCALL mysql_stmt_sqlstate(MYSQL_STMT *stmt);
|
||||
MYSQL_ROW_OFFSET STDCALL mysql_stmt_row_seek(MYSQL_STMT *stmt,
|
||||
MYSQL_ROW_OFFSET offset);
|
||||
MYSQL_ROW_OFFSET STDCALL mysql_stmt_row_tell(MYSQL_STMT *stmt);
|
||||
void STDCALL mysql_stmt_data_seek(MYSQL_STMT *stmt, uint64_t offset);
|
||||
uint64_t STDCALL mysql_stmt_num_rows(MYSQL_STMT *stmt);
|
||||
uint64_t STDCALL mysql_stmt_affected_rows(MYSQL_STMT *stmt);
|
||||
uint64_t STDCALL mysql_stmt_insert_id(MYSQL_STMT *stmt);
|
||||
unsigned int STDCALL mysql_stmt_field_count(MYSQL_STMT *stmt);
|
||||
|
||||
bool STDCALL mysql_commit(MYSQL *mysql);
|
||||
bool STDCALL mysql_rollback(MYSQL *mysql);
|
||||
bool STDCALL mysql_autocommit(MYSQL *mysql, bool auto_mode);
|
||||
bool STDCALL mysql_more_results(MYSQL *mysql);
|
||||
int STDCALL mysql_next_result(MYSQL *mysql);
|
||||
int STDCALL mysql_stmt_next_result(MYSQL_STMT *stmt);
|
||||
void STDCALL mysql_close(MYSQL *sock);
|
||||
|
||||
/* Public key reset */
|
||||
void STDCALL mysql_reset_server_public_key(void);
|
||||
|
||||
/* status return codes */
|
||||
#define MYSQL_NO_DATA 100
|
||||
#define MYSQL_DATA_TRUNCATED 101
|
||||
|
||||
#define mysql_reload(mysql) mysql_refresh((mysql), REFRESH_GRANT)
|
||||
|
||||
#define HAVE_MYSQL_REAL_CONNECT
|
||||
|
||||
MYSQL *STDCALL mysql_real_connect_dns_srv(MYSQL *mysql,
|
||||
const char *dns_srv_name,
|
||||
const char *user, const char *passwd,
|
||||
const char *db,
|
||||
unsigned long client_flag);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _mysql_h */
|
|
@ -1,90 +0,0 @@
|
|||
/* Copyright (c) 2017, 2022, Oracle and/or its affiliates.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License, version 2.0,
|
||||
as published by the Free Software Foundation.
|
||||
|
||||
This program is also distributed with certain software (including
|
||||
but not limited to OpenSSL) that is licensed under separate terms,
|
||||
as designated in a particular file or component or in included license
|
||||
documentation. The authors of MySQL hereby grant you an additional
|
||||
permission to link the program and your derivative works with the
|
||||
separately licensed software that they have included with MySQL.
|
||||
|
||||
Without limiting anything contained in the foregoing, this file,
|
||||
which is part of C Driver for MySQL (Connector/C), is also subject to the
|
||||
Universal FOSS Exception, version 1.0, a copy of which can be found at
|
||||
http://oss.oracle.com/licenses/universal-foss-exception.
|
||||
|
||||
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, version 2.0, 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 St, Fifth Floor, Boston, MA 02110-1301 USA */
|
||||
|
||||
#ifndef UDF_REGISTRATION_TYPES_H
|
||||
#define UDF_REGISTRATION_TYPES_H
|
||||
|
||||
#ifndef MYSQL_ABI_CHECK
|
||||
#include <stdbool.h>
|
||||
#endif
|
||||
|
||||
/**
|
||||
Type of the user defined function return slot and arguments
|
||||
*/
|
||||
enum Item_result {
|
||||
INVALID_RESULT = -1, /** not valid for UDFs */
|
||||
STRING_RESULT = 0, /** char * */
|
||||
REAL_RESULT, /** double */
|
||||
INT_RESULT, /** long long */
|
||||
ROW_RESULT, /** not valid for UDFs */
|
||||
DECIMAL_RESULT /** char *, to be converted to/from a decimal */
|
||||
};
|
||||
|
||||
typedef struct UDF_ARGS {
|
||||
unsigned int arg_count; /**< Number of arguments */
|
||||
enum Item_result *arg_type; /**< Pointer to item_results */
|
||||
char **args; /**< Pointer to argument */
|
||||
unsigned long *lengths; /**< Length of string arguments */
|
||||
char *maybe_null; /**< Set to 1 for all maybe_null args */
|
||||
char **attributes; /**< Pointer to attribute name */
|
||||
unsigned long *attribute_lengths; /**< Length of attribute arguments */
|
||||
void *extension;
|
||||
} UDF_ARGS;
|
||||
|
||||
/**
|
||||
Information about the result of a user defined function
|
||||
|
||||
@todo add a notion for determinism of the UDF.
|
||||
|
||||
@sa Item_udf_func::update_used_tables()
|
||||
*/
|
||||
typedef struct UDF_INIT {
|
||||
bool maybe_null; /** 1 if function can return NULL */
|
||||
unsigned int decimals; /** for real functions */
|
||||
unsigned long max_length; /** For string functions */
|
||||
char *ptr; /** free pointer for function data */
|
||||
bool const_item; /** 1 if function always returns the same value */
|
||||
void *extension;
|
||||
} UDF_INIT;
|
||||
|
||||
enum Item_udftype { UDFTYPE_FUNCTION = 1, UDFTYPE_AGGREGATE };
|
||||
|
||||
typedef void (*Udf_func_clear)(UDF_INIT *, unsigned char *, unsigned char *);
|
||||
typedef void (*Udf_func_add)(UDF_INIT *, UDF_ARGS *, unsigned char *,
|
||||
unsigned char *);
|
||||
typedef void (*Udf_func_deinit)(UDF_INIT *);
|
||||
typedef bool (*Udf_func_init)(UDF_INIT *, UDF_ARGS *, char *);
|
||||
typedef void (*Udf_func_any)(void);
|
||||
typedef double (*Udf_func_double)(UDF_INIT *, UDF_ARGS *, unsigned char *,
|
||||
unsigned char *);
|
||||
typedef long long (*Udf_func_longlong)(UDF_INIT *, UDF_ARGS *, unsigned char *,
|
||||
unsigned char *);
|
||||
typedef char *(*Udf_func_string)(UDF_INIT *, UDF_ARGS *, char *,
|
||||
unsigned long *, unsigned char *,
|
||||
unsigned char *);
|
||||
|
||||
#endif /* UDF_REGISTRATION_TYPES_H */
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -1,99 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2016, 2022, Oracle and/or its affiliates.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License, version 2.0,
|
||||
* as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is also distributed with certain software (including
|
||||
* but not limited to OpenSSL) that is licensed under separate terms,
|
||||
* as designated in a particular file or component or in included license
|
||||
* documentation. The authors of MySQL hereby grant you an additional
|
||||
* permission to link the program and your derivative works with the
|
||||
* separately licensed software that they have included with MySQL.
|
||||
*
|
||||
* 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, version 2.0, 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 St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
/* Autogenerated file, please don't edit */
|
||||
|
||||
#include "mysqlx_error.h"
|
||||
|
||||
{"ER_X_BAD_MESSAGE", ER_X_BAD_MESSAGE, "", NULL, NULL, 0 },
|
||||
{"ER_X_CAPABILITIES_PREPARE_FAILED", ER_X_CAPABILITIES_PREPARE_FAILED, "", NULL, NULL, 0 },
|
||||
{"ER_X_CAPABILITY_NOT_FOUND", ER_X_CAPABILITY_NOT_FOUND, "", NULL, NULL, 0 },
|
||||
{"ER_X_INVALID_PROTOCOL_DATA", ER_X_INVALID_PROTOCOL_DATA, "", NULL, NULL, 0 },
|
||||
{"ER_X_BAD_CONNECTION_SESSION_ATTRIBUTE_VALUE_LENGTH", ER_X_BAD_CONNECTION_SESSION_ATTRIBUTE_VALUE_LENGTH, "", NULL, NULL, 0 },
|
||||
{"ER_X_BAD_CONNECTION_SESSION_ATTRIBUTE_KEY_LENGTH", ER_X_BAD_CONNECTION_SESSION_ATTRIBUTE_KEY_LENGTH, "", NULL, NULL, 0 },
|
||||
{"ER_X_BAD_CONNECTION_SESSION_ATTRIBUTE_EMPTY_KEY", ER_X_BAD_CONNECTION_SESSION_ATTRIBUTE_EMPTY_KEY, "", NULL, NULL, 0 },
|
||||
{"ER_X_BAD_CONNECTION_SESSION_ATTRIBUTE_LENGTH", ER_X_BAD_CONNECTION_SESSION_ATTRIBUTE_LENGTH, "", NULL, NULL, 0 },
|
||||
{"ER_X_BAD_CONNECTION_SESSION_ATTRIBUTE_TYPE", ER_X_BAD_CONNECTION_SESSION_ATTRIBUTE_TYPE, "", NULL, NULL, 0 },
|
||||
{"ER_X_CAPABILITY_SET_NOT_ALLOWED", ER_X_CAPABILITY_SET_NOT_ALLOWED, "", NULL, NULL, 0 },
|
||||
{"ER_X_SERVICE_ERROR", ER_X_SERVICE_ERROR, "", NULL, NULL, 0 },
|
||||
{"ER_X_SESSION", ER_X_SESSION, "", NULL, NULL, 0 },
|
||||
{"ER_X_INVALID_ARGUMENT", ER_X_INVALID_ARGUMENT, "", NULL, NULL, 0 },
|
||||
{"ER_X_MISSING_ARGUMENT", ER_X_MISSING_ARGUMENT, "", NULL, NULL, 0 },
|
||||
{"ER_X_BAD_INSERT_DATA", ER_X_BAD_INSERT_DATA, "", NULL, NULL, 0 },
|
||||
{"ER_X_CMD_NUM_ARGUMENTS", ER_X_CMD_NUM_ARGUMENTS, "", NULL, NULL, 0 },
|
||||
{"ER_X_CMD_ARGUMENT_TYPE", ER_X_CMD_ARGUMENT_TYPE, "", NULL, NULL, 0 },
|
||||
{"ER_X_CMD_ARGUMENT_VALUE", ER_X_CMD_ARGUMENT_VALUE, "", NULL, NULL, 0 },
|
||||
{"ER_X_BAD_UPSERT_DATA", ER_X_BAD_UPSERT_DATA, "", NULL, NULL, 0 },
|
||||
{"ER_X_DUPLICATED_CAPABILITIES", ER_X_DUPLICATED_CAPABILITIES, "", NULL, NULL, 0 },
|
||||
{"ER_X_CMD_ARGUMENT_OBJECT_EMPTY", ER_X_CMD_ARGUMENT_OBJECT_EMPTY, "", NULL, NULL, 0 },
|
||||
{"ER_X_CMD_INVALID_ARGUMENT", ER_X_CMD_INVALID_ARGUMENT, "", NULL, NULL, 0 },
|
||||
{"ER_X_BAD_UPDATE_DATA", ER_X_BAD_UPDATE_DATA, "", NULL, NULL, 0 },
|
||||
{"ER_X_BAD_TYPE_OF_UPDATE", ER_X_BAD_TYPE_OF_UPDATE, "", NULL, NULL, 0 },
|
||||
{"ER_X_BAD_COLUMN_TO_UPDATE", ER_X_BAD_COLUMN_TO_UPDATE, "", NULL, NULL, 0 },
|
||||
{"ER_X_BAD_MEMBER_TO_UPDATE", ER_X_BAD_MEMBER_TO_UPDATE, "", NULL, NULL, 0 },
|
||||
{"ER_X_BAD_STATEMENT_ID", ER_X_BAD_STATEMENT_ID, "", NULL, NULL, 0 },
|
||||
{"ER_X_BAD_CURSOR_ID", ER_X_BAD_CURSOR_ID, "", NULL, NULL, 0 },
|
||||
{"ER_X_BAD_SCHEMA", ER_X_BAD_SCHEMA, "", NULL, NULL, 0 },
|
||||
{"ER_X_BAD_TABLE", ER_X_BAD_TABLE, "", NULL, NULL, 0 },
|
||||
{"ER_X_BAD_PROJECTION", ER_X_BAD_PROJECTION, "", NULL, NULL, 0 },
|
||||
{"ER_X_DOC_ID_MISSING", ER_X_DOC_ID_MISSING, "", NULL, NULL, 0 },
|
||||
{"ER_X_DUPLICATE_ENTRY", ER_X_DUPLICATE_ENTRY, "", NULL, NULL, 0 },
|
||||
{"ER_X_DOC_REQUIRED_FIELD_MISSING", ER_X_DOC_REQUIRED_FIELD_MISSING, "", NULL, NULL, 0 },
|
||||
{"ER_X_PROJ_BAD_KEY_NAME", ER_X_PROJ_BAD_KEY_NAME, "", NULL, NULL, 0 },
|
||||
{"ER_X_BAD_DOC_PATH", ER_X_BAD_DOC_PATH, "", NULL, NULL, 0 },
|
||||
{"ER_X_CURSOR_EXISTS", ER_X_CURSOR_EXISTS, "", NULL, NULL, 0 },
|
||||
{"ER_X_CURSOR_REACHED_EOF", ER_X_CURSOR_REACHED_EOF, "", NULL, NULL, 0 },
|
||||
{"ER_X_PREPARED_STATMENT_CAN_HAVE_ONE_CURSOR", ER_X_PREPARED_STATMENT_CAN_HAVE_ONE_CURSOR, "", NULL, NULL, 0 },
|
||||
{"ER_X_PREPARED_EXECUTE_ARGUMENT_NOT_SUPPORTED", ER_X_PREPARED_EXECUTE_ARGUMENT_NOT_SUPPORTED, "", NULL, NULL, 0 },
|
||||
{"ER_X_PREPARED_EXECUTE_ARGUMENT_CONSISTENCY", ER_X_PREPARED_EXECUTE_ARGUMENT_CONSISTENCY, "", NULL, NULL, 0 },
|
||||
{"ER_X_EXPR_BAD_OPERATOR", ER_X_EXPR_BAD_OPERATOR, "", NULL, NULL, 0 },
|
||||
{"ER_X_EXPR_BAD_NUM_ARGS", ER_X_EXPR_BAD_NUM_ARGS, "", NULL, NULL, 0 },
|
||||
{"ER_X_EXPR_MISSING_ARG", ER_X_EXPR_MISSING_ARG, "", NULL, NULL, 0 },
|
||||
{"ER_X_EXPR_BAD_TYPE_VALUE", ER_X_EXPR_BAD_TYPE_VALUE, "", NULL, NULL, 0 },
|
||||
{"ER_X_EXPR_BAD_VALUE", ER_X_EXPR_BAD_VALUE, "", NULL, NULL, 0 },
|
||||
{"ER_X_INVALID_COLLECTION", ER_X_INVALID_COLLECTION, "", NULL, NULL, 0 },
|
||||
{"ER_X_INVALID_ADMIN_COMMAND", ER_X_INVALID_ADMIN_COMMAND, "", NULL, NULL, 0 },
|
||||
{"ER_X_EXPECT_NOT_OPEN", ER_X_EXPECT_NOT_OPEN, "", NULL, NULL, 0 },
|
||||
{"ER_X_EXPECT_NO_ERROR_FAILED", ER_X_EXPECT_NO_ERROR_FAILED, "", NULL, NULL, 0 },
|
||||
{"ER_X_EXPECT_BAD_CONDITION", ER_X_EXPECT_BAD_CONDITION, "", NULL, NULL, 0 },
|
||||
{"ER_X_EXPECT_BAD_CONDITION_VALUE", ER_X_EXPECT_BAD_CONDITION_VALUE, "", NULL, NULL, 0 },
|
||||
{"ER_X_INVALID_NAMESPACE", ER_X_INVALID_NAMESPACE, "", NULL, NULL, 0 },
|
||||
{"ER_X_BAD_NOTICE", ER_X_BAD_NOTICE, "", NULL, NULL, 0 },
|
||||
{"ER_X_CANNOT_DISABLE_NOTICE", ER_X_CANNOT_DISABLE_NOTICE, "", NULL, NULL, 0 },
|
||||
{"ER_X_BAD_CONFIGURATION", ER_X_BAD_CONFIGURATION, "", NULL, NULL, 0 },
|
||||
{"ER_X_MYSQLX_ACCOUNT_MISSING_PERMISSIONS", ER_X_MYSQLX_ACCOUNT_MISSING_PERMISSIONS, "", NULL, NULL, 0 },
|
||||
{"ER_X_EXPECT_FIELD_EXISTS_FAILED", ER_X_EXPECT_FIELD_EXISTS_FAILED, "", NULL, NULL, 0 },
|
||||
{"ER_X_BAD_LOCKING", ER_X_BAD_LOCKING, "", NULL, NULL, 0 },
|
||||
{"ER_X_FRAME_COMPRESSION_DISABLED", ER_X_FRAME_COMPRESSION_DISABLED, "", NULL, NULL, 0 },
|
||||
{"ER_X_DECOMPRESSION_FAILED", ER_X_DECOMPRESSION_FAILED, "", NULL, NULL, 0 },
|
||||
{"ER_X_BAD_COMPRESSED_FRAME", ER_X_BAD_COMPRESSED_FRAME, "", NULL, NULL, 0 },
|
||||
{"ER_X_CAPABILITY_COMPRESSION_INVALID_ALGORITHM", ER_X_CAPABILITY_COMPRESSION_INVALID_ALGORITHM, "", NULL, NULL, 0 },
|
||||
{"ER_X_CAPABILITY_COMPRESSION_INVALID_SERVER_STYLE", ER_X_CAPABILITY_COMPRESSION_INVALID_SERVER_STYLE, "", NULL, NULL, 0 },
|
||||
{"ER_X_CAPABILITY_COMPRESSION_INVALID_CLIENT_STYLE", ER_X_CAPABILITY_COMPRESSION_INVALID_CLIENT_STYLE, "", NULL, NULL, 0 },
|
||||
{"ER_X_CAPABILITY_COMPRESSION_INVALID_OPTION", ER_X_CAPABILITY_COMPRESSION_INVALID_OPTION, "", NULL, NULL, 0 },
|
||||
{"ER_X_CAPABILITY_COMPRESSION_MISSING_REQUIRED_FIELDS", ER_X_CAPABILITY_COMPRESSION_MISSING_REQUIRED_FIELDS, "", NULL, NULL, 0 },
|
||||
{"ER_X_DOCUMENT_DOESNT_MATCH_EXPECTED_SCHEMA", ER_X_DOCUMENT_DOESNT_MATCH_EXPECTED_SCHEMA, "", NULL, NULL, 0 },
|
||||
{"ER_X_COLLECTION_OPTION_DOESNT_EXISTS", ER_X_COLLECTION_OPTION_DOESNT_EXISTS, "", NULL, NULL, 0 },
|
||||
{"ER_X_INVALID_VALIDATION_SCHEMA", ER_X_INVALID_VALIDATION_SCHEMA, "", NULL, NULL, 0 },
|
||||
|
|
@ -1,99 +0,0 @@
|
|||
/* Copyright (c) 2015, 2022, Oracle and/or its affiliates.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License, version 2.0,
|
||||
as published by the Free Software Foundation.
|
||||
|
||||
This program is also distributed with certain software (including
|
||||
but not limited to OpenSSL) that is licensed under separate terms,
|
||||
as designated in a particular file or component or in included license
|
||||
documentation. The authors of MySQL hereby grant you an additional
|
||||
permission to link the program and your derivative works with the
|
||||
separately licensed software that they have included with MySQL.
|
||||
|
||||
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, version 2.0, 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 St, Fifth Floor, Boston, MA 02110-1301 USA */
|
||||
|
||||
|
||||
#ifndef _MYSQLX_ERROR_H_
|
||||
#define _MYSQLX_ERROR_H_
|
||||
|
||||
#define ER_X_BAD_MESSAGE 5000
|
||||
#define ER_X_CAPABILITIES_PREPARE_FAILED 5001
|
||||
#define ER_X_CAPABILITY_NOT_FOUND 5002
|
||||
#define ER_X_INVALID_PROTOCOL_DATA 5003
|
||||
#define ER_X_BAD_CONNECTION_SESSION_ATTRIBUTE_VALUE_LENGTH 5004
|
||||
#define ER_X_BAD_CONNECTION_SESSION_ATTRIBUTE_KEY_LENGTH 5005
|
||||
#define ER_X_BAD_CONNECTION_SESSION_ATTRIBUTE_EMPTY_KEY 5006
|
||||
#define ER_X_BAD_CONNECTION_SESSION_ATTRIBUTE_LENGTH 5007
|
||||
#define ER_X_BAD_CONNECTION_SESSION_ATTRIBUTE_TYPE 5008
|
||||
#define ER_X_CAPABILITY_SET_NOT_ALLOWED 5009
|
||||
#define ER_X_SERVICE_ERROR 5010
|
||||
#define ER_X_SESSION 5011
|
||||
#define ER_X_INVALID_ARGUMENT 5012
|
||||
#define ER_X_MISSING_ARGUMENT 5013
|
||||
#define ER_X_BAD_INSERT_DATA 5014
|
||||
#define ER_X_CMD_NUM_ARGUMENTS 5015
|
||||
#define ER_X_CMD_ARGUMENT_TYPE 5016
|
||||
#define ER_X_CMD_ARGUMENT_VALUE 5017
|
||||
#define ER_X_BAD_UPSERT_DATA 5018
|
||||
#define ER_X_DUPLICATED_CAPABILITIES 5019
|
||||
#define ER_X_CMD_ARGUMENT_OBJECT_EMPTY 5020
|
||||
#define ER_X_CMD_INVALID_ARGUMENT 5021
|
||||
#define ER_X_BAD_UPDATE_DATA 5050
|
||||
#define ER_X_BAD_TYPE_OF_UPDATE 5051
|
||||
#define ER_X_BAD_COLUMN_TO_UPDATE 5052
|
||||
#define ER_X_BAD_MEMBER_TO_UPDATE 5053
|
||||
#define ER_X_BAD_STATEMENT_ID 5110
|
||||
#define ER_X_BAD_CURSOR_ID 5111
|
||||
#define ER_X_BAD_SCHEMA 5112
|
||||
#define ER_X_BAD_TABLE 5113
|
||||
#define ER_X_BAD_PROJECTION 5114
|
||||
#define ER_X_DOC_ID_MISSING 5115
|
||||
#define ER_X_DUPLICATE_ENTRY 5116
|
||||
#define ER_X_DOC_REQUIRED_FIELD_MISSING 5117
|
||||
#define ER_X_PROJ_BAD_KEY_NAME 5120
|
||||
#define ER_X_BAD_DOC_PATH 5121
|
||||
#define ER_X_CURSOR_EXISTS 5122
|
||||
#define ER_X_CURSOR_REACHED_EOF 5123
|
||||
#define ER_X_PREPARED_STATMENT_CAN_HAVE_ONE_CURSOR 5131
|
||||
#define ER_X_PREPARED_EXECUTE_ARGUMENT_NOT_SUPPORTED 5133
|
||||
#define ER_X_PREPARED_EXECUTE_ARGUMENT_CONSISTENCY 5134
|
||||
#define ER_X_EXPR_BAD_OPERATOR 5150
|
||||
#define ER_X_EXPR_BAD_NUM_ARGS 5151
|
||||
#define ER_X_EXPR_MISSING_ARG 5152
|
||||
#define ER_X_EXPR_BAD_TYPE_VALUE 5153
|
||||
#define ER_X_EXPR_BAD_VALUE 5154
|
||||
#define ER_X_INVALID_COLLECTION 5156
|
||||
#define ER_X_INVALID_ADMIN_COMMAND 5157
|
||||
#define ER_X_EXPECT_NOT_OPEN 5158
|
||||
#define ER_X_EXPECT_NO_ERROR_FAILED 5159
|
||||
#define ER_X_EXPECT_BAD_CONDITION 5160
|
||||
#define ER_X_EXPECT_BAD_CONDITION_VALUE 5161
|
||||
#define ER_X_INVALID_NAMESPACE 5162
|
||||
#define ER_X_BAD_NOTICE 5163
|
||||
#define ER_X_CANNOT_DISABLE_NOTICE 5164
|
||||
#define ER_X_BAD_CONFIGURATION 5165
|
||||
#define ER_X_MYSQLX_ACCOUNT_MISSING_PERMISSIONS 5167
|
||||
#define ER_X_EXPECT_FIELD_EXISTS_FAILED 5168
|
||||
#define ER_X_BAD_LOCKING 5169
|
||||
#define ER_X_FRAME_COMPRESSION_DISABLED 5170
|
||||
#define ER_X_DECOMPRESSION_FAILED 5171
|
||||
#define ER_X_BAD_COMPRESSED_FRAME 5174
|
||||
#define ER_X_CAPABILITY_COMPRESSION_INVALID_ALGORITHM 5175
|
||||
#define ER_X_CAPABILITY_COMPRESSION_INVALID_SERVER_STYLE 5176
|
||||
#define ER_X_CAPABILITY_COMPRESSION_INVALID_CLIENT_STYLE 5177
|
||||
#define ER_X_CAPABILITY_COMPRESSION_INVALID_OPTION 5178
|
||||
#define ER_X_CAPABILITY_COMPRESSION_MISSING_REQUIRED_FIELDS 5179
|
||||
#define ER_X_DOCUMENT_DOESNT_MATCH_EXPECTED_SCHEMA 5180
|
||||
#define ER_X_COLLECTION_OPTION_DOESNT_EXISTS 5181
|
||||
#define ER_X_INVALID_VALIDATION_SCHEMA 5182
|
||||
|
||||
|
||||
#endif // _MYSQLX_ERROR_H_
|
|
@ -1,138 +0,0 @@
|
|||
/*
|
||||
* Copyright 2004-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
* in the file LICENSE in the source distribution or at
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
#define APPLINK_STDIN 1
|
||||
#define APPLINK_STDOUT 2
|
||||
#define APPLINK_STDERR 3
|
||||
#define APPLINK_FPRINTF 4
|
||||
#define APPLINK_FGETS 5
|
||||
#define APPLINK_FREAD 6
|
||||
#define APPLINK_FWRITE 7
|
||||
#define APPLINK_FSETMOD 8
|
||||
#define APPLINK_FEOF 9
|
||||
#define APPLINK_FCLOSE 10 /* should not be used */
|
||||
|
||||
#define APPLINK_FOPEN 11 /* solely for completeness */
|
||||
#define APPLINK_FSEEK 12
|
||||
#define APPLINK_FTELL 13
|
||||
#define APPLINK_FFLUSH 14
|
||||
#define APPLINK_FERROR 15
|
||||
#define APPLINK_CLEARERR 16
|
||||
#define APPLINK_FILENO 17 /* to be used with below */
|
||||
|
||||
#define APPLINK_OPEN 18 /* formally can't be used, as flags can vary */
|
||||
#define APPLINK_READ 19
|
||||
#define APPLINK_WRITE 20
|
||||
#define APPLINK_LSEEK 21
|
||||
#define APPLINK_CLOSE 22
|
||||
#define APPLINK_MAX 22 /* always same as last macro */
|
||||
|
||||
#ifndef APPMACROS_ONLY
|
||||
# include <stdio.h>
|
||||
# include <io.h>
|
||||
# include <fcntl.h>
|
||||
|
||||
static void *app_stdin(void)
|
||||
{
|
||||
return stdin;
|
||||
}
|
||||
|
||||
static void *app_stdout(void)
|
||||
{
|
||||
return stdout;
|
||||
}
|
||||
|
||||
static void *app_stderr(void)
|
||||
{
|
||||
return stderr;
|
||||
}
|
||||
|
||||
static int app_feof(FILE *fp)
|
||||
{
|
||||
return feof(fp);
|
||||
}
|
||||
|
||||
static int app_ferror(FILE *fp)
|
||||
{
|
||||
return ferror(fp);
|
||||
}
|
||||
|
||||
static void app_clearerr(FILE *fp)
|
||||
{
|
||||
clearerr(fp);
|
||||
}
|
||||
|
||||
static int app_fileno(FILE *fp)
|
||||
{
|
||||
return _fileno(fp);
|
||||
}
|
||||
|
||||
static int app_fsetmod(FILE *fp, char mod)
|
||||
{
|
||||
return _setmode(_fileno(fp), mod == 'b' ? _O_BINARY : _O_TEXT);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
__declspec(dllexport)
|
||||
void **
|
||||
# if defined(__BORLANDC__)
|
||||
/*
|
||||
* __stdcall appears to be the only way to get the name
|
||||
* decoration right with Borland C. Otherwise it works
|
||||
* purely incidentally, as we pass no parameters.
|
||||
*/
|
||||
__stdcall
|
||||
# else
|
||||
__cdecl
|
||||
# endif
|
||||
OPENSSL_Applink(void)
|
||||
{
|
||||
static int once = 1;
|
||||
static void *OPENSSL_ApplinkTable[APPLINK_MAX + 1] =
|
||||
{ (void *)APPLINK_MAX };
|
||||
|
||||
if (once) {
|
||||
OPENSSL_ApplinkTable[APPLINK_STDIN] = app_stdin;
|
||||
OPENSSL_ApplinkTable[APPLINK_STDOUT] = app_stdout;
|
||||
OPENSSL_ApplinkTable[APPLINK_STDERR] = app_stderr;
|
||||
OPENSSL_ApplinkTable[APPLINK_FPRINTF] = fprintf;
|
||||
OPENSSL_ApplinkTable[APPLINK_FGETS] = fgets;
|
||||
OPENSSL_ApplinkTable[APPLINK_FREAD] = fread;
|
||||
OPENSSL_ApplinkTable[APPLINK_FWRITE] = fwrite;
|
||||
OPENSSL_ApplinkTable[APPLINK_FSETMOD] = app_fsetmod;
|
||||
OPENSSL_ApplinkTable[APPLINK_FEOF] = app_feof;
|
||||
OPENSSL_ApplinkTable[APPLINK_FCLOSE] = fclose;
|
||||
|
||||
OPENSSL_ApplinkTable[APPLINK_FOPEN] = fopen;
|
||||
OPENSSL_ApplinkTable[APPLINK_FSEEK] = fseek;
|
||||
OPENSSL_ApplinkTable[APPLINK_FTELL] = ftell;
|
||||
OPENSSL_ApplinkTable[APPLINK_FFLUSH] = fflush;
|
||||
OPENSSL_ApplinkTable[APPLINK_FERROR] = app_ferror;
|
||||
OPENSSL_ApplinkTable[APPLINK_CLEARERR] = app_clearerr;
|
||||
OPENSSL_ApplinkTable[APPLINK_FILENO] = app_fileno;
|
||||
|
||||
OPENSSL_ApplinkTable[APPLINK_OPEN] = _open;
|
||||
OPENSSL_ApplinkTable[APPLINK_READ] = _read;
|
||||
OPENSSL_ApplinkTable[APPLINK_WRITE] = _write;
|
||||
OPENSSL_ApplinkTable[APPLINK_LSEEK] = _lseek;
|
||||
OPENSSL_ApplinkTable[APPLINK_CLOSE] = _close;
|
||||
|
||||
once = 0;
|
||||
}
|
||||
|
||||
return OPENSSL_ApplinkTable;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
|
@ -0,0 +1,121 @@
|
|||
/* Copyright (c) 2012, 2022, Oracle and/or its affiliates.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License, version 2.0,
|
||||
as published by the Free Software Foundation.
|
||||
|
||||
This program is also distributed with certain software (including
|
||||
but not limited to OpenSSL) that is licensed under separate terms,
|
||||
as designated in a particular file or component or in included license
|
||||
documentation. The authors of MySQL hereby grant you an additional
|
||||
permission to link the program and your derivative works with the
|
||||
separately licensed software that they have included with MySQL.
|
||||
|
||||
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, version 2.0, 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 St, Fifth Floor, Boston, MA 02110-1301 USA */
|
||||
|
||||
#include <string.h>
|
||||
|
||||
/*
|
||||
Data in big-endian format.
|
||||
*/
|
||||
static inline void float4store(uchar *T, float A)
|
||||
{ *(T)= ((uchar *) &A)[3];
|
||||
*((T)+1)=(char) ((uchar *) &A)[2];
|
||||
*((T)+2)=(char) ((uchar *) &A)[1];
|
||||
*((T)+3)=(char) ((uchar *) &A)[0]; }
|
||||
|
||||
static inline void float4get (float *V, const uchar *M)
|
||||
{ float def_temp;
|
||||
((uchar*) &def_temp)[0]=(M)[3];
|
||||
((uchar*) &def_temp)[1]=(M)[2];
|
||||
((uchar*) &def_temp)[2]=(M)[1];
|
||||
((uchar*) &def_temp)[3]=(M)[0];
|
||||
(*V)=def_temp; }
|
||||
|
||||
static inline void float8store(uchar *T, double V)
|
||||
{ *(T)= ((uchar *) &V)[7];
|
||||
*((T)+1)=(char) ((uchar *) &V)[6];
|
||||
*((T)+2)=(char) ((uchar *) &V)[5];
|
||||
*((T)+3)=(char) ((uchar *) &V)[4];
|
||||
*((T)+4)=(char) ((uchar *) &V)[3];
|
||||
*((T)+5)=(char) ((uchar *) &V)[2];
|
||||
*((T)+6)=(char) ((uchar *) &V)[1];
|
||||
*((T)+7)=(char) ((uchar *) &V)[0]; }
|
||||
|
||||
static inline void float8get (double *V, const uchar *M)
|
||||
{ double def_temp;
|
||||
((uchar*) &def_temp)[0]=(M)[7];
|
||||
((uchar*) &def_temp)[1]=(M)[6];
|
||||
((uchar*) &def_temp)[2]=(M)[5];
|
||||
((uchar*) &def_temp)[3]=(M)[4];
|
||||
((uchar*) &def_temp)[4]=(M)[3];
|
||||
((uchar*) &def_temp)[5]=(M)[2];
|
||||
((uchar*) &def_temp)[6]=(M)[1];
|
||||
((uchar*) &def_temp)[7]=(M)[0];
|
||||
(*V) = def_temp; }
|
||||
|
||||
static inline void ushortget(uint16 *V, const uchar *pM)
|
||||
{ *V = (uint16) (((uint16) ((uchar) (pM)[1]))+
|
||||
((uint16) ((uint16) (pM)[0]) << 8)); }
|
||||
static inline void shortget (int16 *V, const uchar *pM)
|
||||
{ *V = (short) (((short) ((uchar) (pM)[1]))+
|
||||
((short) ((short) (pM)[0]) << 8)); }
|
||||
static inline void longget (int32 *V, const uchar *pM)
|
||||
{ int32 def_temp;
|
||||
((uchar*) &def_temp)[0]=(pM)[0];
|
||||
((uchar*) &def_temp)[1]=(pM)[1];
|
||||
((uchar*) &def_temp)[2]=(pM)[2];
|
||||
((uchar*) &def_temp)[3]=(pM)[3];
|
||||
(*V)=def_temp; }
|
||||
static inline void ulongget (uint32 *V, const uchar *pM)
|
||||
{ uint32 def_temp;
|
||||
((uchar*) &def_temp)[0]=(pM)[0];
|
||||
((uchar*) &def_temp)[1]=(pM)[1];
|
||||
((uchar*) &def_temp)[2]=(pM)[2];
|
||||
((uchar*) &def_temp)[3]=(pM)[3];
|
||||
(*V)=def_temp; }
|
||||
static inline void shortstore(uchar *T, int16 A)
|
||||
{ uint def_temp=(uint) (A) ;
|
||||
*(((char*)T)+1)=(char)(def_temp);
|
||||
*(((char*)T)+0)=(char)(def_temp >> 8); }
|
||||
static inline void longstore (uchar *T, int32 A)
|
||||
{ *(((char*)T)+3)=((A));
|
||||
*(((char*)T)+2)=(((A) >> 8));
|
||||
*(((char*)T)+1)=(((A) >> 16));
|
||||
*(((char*)T)+0)=(((A) >> 24)); }
|
||||
|
||||
static inline void floatget(float *V, const uchar *M)
|
||||
{
|
||||
memcpy(V, (M), sizeof(float));
|
||||
}
|
||||
|
||||
static inline void floatstore(uchar *T, float V)
|
||||
{
|
||||
memcpy((T), (&V), sizeof(float));
|
||||
}
|
||||
|
||||
static inline void doubleget(double *V, const uchar *M)
|
||||
{
|
||||
memcpy(V, (M), sizeof(double));
|
||||
}
|
||||
|
||||
static inline void doublestore(uchar *T, double V)
|
||||
{
|
||||
memcpy((T), &V, sizeof(double));
|
||||
}
|
||||
|
||||
static inline void longlongget(longlong *V, const uchar *M)
|
||||
{
|
||||
memcpy(V, (M), sizeof(ulonglong));
|
||||
}
|
||||
static inline void longlongstore(uchar *T, longlong V)
|
||||
{
|
||||
memcpy((T), &V, sizeof(ulonglong));
|
||||
}
|
|
@ -26,7 +26,7 @@
|
|||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
|
||||
|
||||
/**
|
||||
@file field_types.h
|
||||
@file binary_log_types.h
|
||||
|
||||
@brief This file contains the field type.
|
||||
|
||||
|
@ -35,61 +35,48 @@
|
|||
definitions have to be constructed to support this.
|
||||
*/
|
||||
|
||||
#ifndef FIELD_TYPES_INCLUDED
|
||||
#define FIELD_TYPES_INCLUDED
|
||||
#ifndef BINARY_LOG_TYPES_INCLUDED
|
||||
#define BINARY_LOG_TYPES_INCLUDED
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Constants exported from this package.
|
||||
*/
|
||||
|
||||
/**
|
||||
Column types for MySQL
|
||||
*/
|
||||
enum enum_field_types {
|
||||
MYSQL_TYPE_DECIMAL,
|
||||
MYSQL_TYPE_TINY,
|
||||
MYSQL_TYPE_SHORT,
|
||||
MYSQL_TYPE_LONG,
|
||||
MYSQL_TYPE_FLOAT,
|
||||
MYSQL_TYPE_DOUBLE,
|
||||
MYSQL_TYPE_NULL,
|
||||
MYSQL_TYPE_TIMESTAMP,
|
||||
MYSQL_TYPE_LONGLONG,
|
||||
MYSQL_TYPE_INT24,
|
||||
MYSQL_TYPE_DATE,
|
||||
MYSQL_TYPE_TIME,
|
||||
MYSQL_TYPE_DATETIME,
|
||||
MYSQL_TYPE_YEAR,
|
||||
MYSQL_TYPE_NEWDATE, /**< Internal to MySQL. Not used in protocol */
|
||||
MYSQL_TYPE_VARCHAR,
|
||||
typedef enum enum_field_types {
|
||||
MYSQL_TYPE_DECIMAL, MYSQL_TYPE_TINY,
|
||||
MYSQL_TYPE_SHORT, MYSQL_TYPE_LONG,
|
||||
MYSQL_TYPE_FLOAT, MYSQL_TYPE_DOUBLE,
|
||||
MYSQL_TYPE_NULL, MYSQL_TYPE_TIMESTAMP,
|
||||
MYSQL_TYPE_LONGLONG,MYSQL_TYPE_INT24,
|
||||
MYSQL_TYPE_DATE, MYSQL_TYPE_TIME,
|
||||
MYSQL_TYPE_DATETIME, MYSQL_TYPE_YEAR,
|
||||
MYSQL_TYPE_NEWDATE, MYSQL_TYPE_VARCHAR,
|
||||
MYSQL_TYPE_BIT,
|
||||
MYSQL_TYPE_TIMESTAMP2,
|
||||
MYSQL_TYPE_DATETIME2, /**< Internal to MySQL. Not used in protocol */
|
||||
MYSQL_TYPE_TIME2, /**< Internal to MySQL. Not used in protocol */
|
||||
MYSQL_TYPE_TYPED_ARRAY, /**< Used for replication only */
|
||||
MYSQL_TYPE_INVALID = 243,
|
||||
MYSQL_TYPE_BOOL = 244, /**< Currently just a placeholder */
|
||||
MYSQL_TYPE_JSON = 245,
|
||||
MYSQL_TYPE_NEWDECIMAL = 246,
|
||||
MYSQL_TYPE_ENUM = 247,
|
||||
MYSQL_TYPE_SET = 248,
|
||||
MYSQL_TYPE_TINY_BLOB = 249,
|
||||
MYSQL_TYPE_MEDIUM_BLOB = 250,
|
||||
MYSQL_TYPE_LONG_BLOB = 251,
|
||||
MYSQL_TYPE_BLOB = 252,
|
||||
MYSQL_TYPE_VAR_STRING = 253,
|
||||
MYSQL_TYPE_STRING = 254,
|
||||
MYSQL_TYPE_GEOMETRY = 255
|
||||
};
|
||||
MYSQL_TYPE_DATETIME2,
|
||||
MYSQL_TYPE_TIME2,
|
||||
MYSQL_TYPE_JSON=245,
|
||||
MYSQL_TYPE_NEWDECIMAL=246,
|
||||
MYSQL_TYPE_ENUM=247,
|
||||
MYSQL_TYPE_SET=248,
|
||||
MYSQL_TYPE_TINY_BLOB=249,
|
||||
MYSQL_TYPE_MEDIUM_BLOB=250,
|
||||
MYSQL_TYPE_LONG_BLOB=251,
|
||||
MYSQL_TYPE_BLOB=252,
|
||||
MYSQL_TYPE_VAR_STRING=253,
|
||||
MYSQL_TYPE_STRING=254,
|
||||
MYSQL_TYPE_GEOMETRY=255
|
||||
} enum_field_types;
|
||||
|
||||
#define DATETIME_MAX_DECIMALS 6
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#else
|
||||
typedef enum enum_field_types enum_field_types;
|
||||
#endif /* __cplusplus */
|
||||
}
|
||||
#endif // __cplusplus
|
||||
|
||||
#endif /* FIELD_TYPES_INCLUDED */
|
||||
#endif /* BINARY_LOG_TYPES_INCLUDED */
|
|
@ -0,0 +1,104 @@
|
|||
/* Copyright (c) 2001, 2022, Oracle and/or its affiliates.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License, version 2.0,
|
||||
as published by the Free Software Foundation.
|
||||
|
||||
This program is also distributed with certain software (including
|
||||
but not limited to OpenSSL) that is licensed under separate terms,
|
||||
as designated in a particular file or component or in included license
|
||||
documentation. The authors of MySQL hereby grant you an additional
|
||||
permission to link the program and your derivative works with the
|
||||
separately licensed software that they have included with MySQL.
|
||||
|
||||
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, version 2.0, 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 St, Fifth Floor, Boston, MA 02110-1301 USA */
|
||||
|
||||
/*
|
||||
Endianness-independent definitions for architectures other
|
||||
than the x86 architecture.
|
||||
*/
|
||||
static inline int16 sint2korr(const uchar *A)
|
||||
{
|
||||
return
|
||||
(int16) (((int16) (A[0])) +
|
||||
((int16) (A[1]) << 8))
|
||||
;
|
||||
}
|
||||
|
||||
static inline int32 sint4korr(const uchar *A)
|
||||
{
|
||||
return
|
||||
(int32) (((int32) (A[0])) +
|
||||
(((int32) (A[1]) << 8)) +
|
||||
(((int32) (A[2]) << 16)) +
|
||||
(((int32) (A[3]) << 24)))
|
||||
;
|
||||
}
|
||||
|
||||
static inline uint16 uint2korr(const uchar *A)
|
||||
{
|
||||
return
|
||||
(uint16) (((uint16) (A[0])) +
|
||||
((uint16) (A[1]) << 8))
|
||||
;
|
||||
}
|
||||
|
||||
static inline uint32 uint4korr(const uchar *A)
|
||||
{
|
||||
return
|
||||
(uint32) (((uint32) (A[0])) +
|
||||
(((uint32) (A[1])) << 8) +
|
||||
(((uint32) (A[2])) << 16) +
|
||||
(((uint32) (A[3])) << 24))
|
||||
;
|
||||
}
|
||||
|
||||
static inline ulonglong uint8korr(const uchar *A)
|
||||
{
|
||||
return
|
||||
((ulonglong)(((uint32) (A[0])) +
|
||||
(((uint32) (A[1])) << 8) +
|
||||
(((uint32) (A[2])) << 16) +
|
||||
(((uint32) (A[3])) << 24)) +
|
||||
(((ulonglong) (((uint32) (A[4])) +
|
||||
(((uint32) (A[5])) << 8) +
|
||||
(((uint32) (A[6])) << 16) +
|
||||
(((uint32) (A[7])) << 24))) <<
|
||||
32))
|
||||
;
|
||||
}
|
||||
|
||||
static inline longlong sint8korr(const uchar *A)
|
||||
{
|
||||
return (longlong) uint8korr(A);
|
||||
}
|
||||
|
||||
static inline void int2store(uchar *T, uint16 A)
|
||||
{
|
||||
uint def_temp= A ;
|
||||
*(T)= (uchar)(def_temp);
|
||||
*(T+1)= (uchar)(def_temp >> 8);
|
||||
}
|
||||
|
||||
static inline void int4store(uchar *T, uint32 A)
|
||||
{
|
||||
*(T)= (uchar) (A);
|
||||
*(T+1)=(uchar) (A >> 8);
|
||||
*(T+2)=(uchar) (A >> 16);
|
||||
*(T+3)=(uchar) (A >> 24);
|
||||
}
|
||||
|
||||
static inline void int8store(uchar *T, ulonglong A)
|
||||
{
|
||||
uint def_temp= (uint) A,
|
||||
def_temp2= (uint) (A >> 32);
|
||||
int4store(T, def_temp);
|
||||
int4store(T+4,def_temp2);
|
||||
}
|
|
@ -0,0 +1,68 @@
|
|||
/* Copyright (c) 2001, 2022, Oracle and/or its affiliates.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License, version 2.0,
|
||||
as published by the Free Software Foundation.
|
||||
|
||||
This program is also distributed with certain software (including
|
||||
but not limited to OpenSSL) that is licensed under separate terms,
|
||||
as designated in a particular file or component or in included license
|
||||
documentation. The authors of MySQL hereby grant you an additional
|
||||
permission to link the program and your derivative works with the
|
||||
separately licensed software that they have included with MySQL.
|
||||
|
||||
Without limiting anything contained in the foregoing, this file,
|
||||
which is part of C Driver for MySQL (Connector/C), is also subject to the
|
||||
Universal FOSS Exception, version 1.0, a copy of which can be found at
|
||||
http://oss.oracle.com/licenses/universal-foss-exception.
|
||||
|
||||
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, version 2.0, 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 St, Fifth Floor, Boston, MA 02110-1301 USA */
|
||||
|
||||
/*
|
||||
Optimized functions for the x86 architecture (_WIN32 included).
|
||||
|
||||
x86 handles misaligned reads and writes just fine, so suppress
|
||||
UBSAN warnings for these functions.
|
||||
*/
|
||||
static inline int16 sint2korr(const uchar *A) SUPPRESS_UBSAN;
|
||||
static inline int16 sint2korr(const uchar *A) { return *((int16*) A); }
|
||||
|
||||
static inline int32 sint4korr(const uchar *A) SUPPRESS_UBSAN;
|
||||
static inline int32 sint4korr(const uchar *A) { return *((int32*) A); }
|
||||
|
||||
static inline uint16 uint2korr(const uchar *A) SUPPRESS_UBSAN;
|
||||
static inline uint16 uint2korr(const uchar *A) { return *((uint16*) A); }
|
||||
|
||||
static inline uint32 uint4korr(const uchar *A) SUPPRESS_UBSAN;
|
||||
static inline uint32 uint4korr(const uchar *A) { return *((uint32*) A); }
|
||||
|
||||
static inline ulonglong uint8korr(const uchar *A) SUPPRESS_UBSAN;
|
||||
static inline ulonglong uint8korr(const uchar *A) { return *((ulonglong*) A);}
|
||||
|
||||
static inline longlong sint8korr(const uchar *A) SUPPRESS_UBSAN;
|
||||
static inline longlong sint8korr(const uchar *A) { return *((longlong*) A); }
|
||||
|
||||
static inline void int2store(uchar *T, uint16 A) SUPPRESS_UBSAN;
|
||||
static inline void int2store(uchar *T, uint16 A)
|
||||
{
|
||||
*((uint16*) T)= A;
|
||||
}
|
||||
|
||||
static inline void int4store(uchar *T, uint32 A) SUPPRESS_UBSAN;
|
||||
static inline void int4store(uchar *T, uint32 A)
|
||||
{
|
||||
*((uint32*) T)= A;
|
||||
}
|
||||
|
||||
static inline void int8store(uchar *T, ulonglong A) SUPPRESS_UBSAN;
|
||||
static inline void int8store(uchar *T, ulonglong A)
|
||||
{
|
||||
*((ulonglong*) T)= A;
|
||||
}
|
|
@ -0,0 +1,144 @@
|
|||
/* Copyright (c) 2000, 2022, Oracle and/or its affiliates.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License, version 2.0,
|
||||
as published by the Free Software Foundation.
|
||||
|
||||
This program is also distributed with certain software (including
|
||||
but not limited to OpenSSL) that is licensed under separate terms,
|
||||
as designated in a particular file or component or in included license
|
||||
documentation. The authors of MySQL hereby grant you an additional
|
||||
permission to link the program and your derivative works with the
|
||||
separately licensed software that they have included with MySQL.
|
||||
|
||||
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, version 2.0, 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 St, Fifth Floor, Boston, MA 02110-1301 USA */
|
||||
|
||||
#ifndef DECIMAL_INCLUDED
|
||||
#define DECIMAL_INCLUDED
|
||||
|
||||
typedef enum
|
||||
{TRUNCATE=0, HALF_EVEN, HALF_UP, CEILING, FLOOR}
|
||||
decimal_round_mode;
|
||||
typedef int32 decimal_digit_t;
|
||||
|
||||
/**
|
||||
intg is the number of *decimal* digits (NOT number of decimal_digit_t's !)
|
||||
before the point
|
||||
frac is the number of decimal digits after the point
|
||||
len is the length of buf (length of allocated space) in decimal_digit_t's,
|
||||
not in bytes
|
||||
sign false means positive, true means negative
|
||||
buf is an array of decimal_digit_t's
|
||||
*/
|
||||
typedef struct st_decimal_t {
|
||||
int intg, frac, len;
|
||||
my_bool sign;
|
||||
decimal_digit_t *buf;
|
||||
} decimal_t;
|
||||
|
||||
#ifndef MYSQL_ABI_CHECK
|
||||
int internal_str2dec(const char *from, decimal_t *to, char **end,
|
||||
my_bool fixed);
|
||||
int decimal2string(const decimal_t *from, char *to, int *to_len,
|
||||
int fixed_precision, int fixed_decimals,
|
||||
char filler);
|
||||
int decimal2ulonglong(decimal_t *from, ulonglong *to);
|
||||
int ulonglong2decimal(ulonglong from, decimal_t *to);
|
||||
int decimal2longlong(decimal_t *from, longlong *to);
|
||||
int longlong2decimal(longlong from, decimal_t *to);
|
||||
int decimal2double(const decimal_t *from, double *to);
|
||||
int double2decimal(double from, decimal_t *to);
|
||||
int decimal_actual_fraction(decimal_t *from);
|
||||
int decimal2bin(decimal_t *from, uchar *to, int precision, int scale);
|
||||
int bin2decimal(const uchar *from, decimal_t *to, int precision, int scale);
|
||||
|
||||
/**
|
||||
Convert decimal to lldiv_t.
|
||||
The integer part is stored in to->quot.
|
||||
The fractional part is multiplied to 10^9 and stored to to->rem.
|
||||
@param from Decimal value
|
||||
@param to lldiv_t value
|
||||
@retval 0 on success
|
||||
@retval !0 in error
|
||||
*/
|
||||
int decimal2lldiv_t(const decimal_t *from, lldiv_t *to);
|
||||
|
||||
/**
|
||||
Convert doube to lldiv_t.
|
||||
The integer part is stored in to->quot.
|
||||
The fractional part is multiplied to 10^9 and stored to to->rem.
|
||||
@param from Decimal value
|
||||
@param to lldiv_t value
|
||||
@retval 0 on success
|
||||
@retval !0 in error
|
||||
*/
|
||||
|
||||
int double2lldiv_t(double from, lldiv_t *to);
|
||||
int decimal_size(int precision, int scale);
|
||||
int decimal_bin_size(int precision, int scale);
|
||||
int decimal_result_size(decimal_t *from1, decimal_t *from2, char op,
|
||||
int param);
|
||||
|
||||
int decimal_intg(const decimal_t *from);
|
||||
int decimal_add(const decimal_t *from1, const decimal_t *from2, decimal_t *to);
|
||||
int decimal_sub(const decimal_t *from1, const decimal_t *from2, decimal_t *to);
|
||||
int decimal_cmp(const decimal_t *from1, const decimal_t *from2);
|
||||
int decimal_mul(const decimal_t *from1, const decimal_t *from2, decimal_t *to);
|
||||
int decimal_div(const decimal_t *from1, const decimal_t *from2, decimal_t *to,
|
||||
int scale_incr);
|
||||
int decimal_mod(const decimal_t *from1, const decimal_t *from2, decimal_t *to);
|
||||
int decimal_round(const decimal_t *from, decimal_t *to, int new_scale,
|
||||
decimal_round_mode mode);
|
||||
int decimal_is_zero(const decimal_t *from);
|
||||
void max_decimal(int precision, int frac, decimal_t *to);
|
||||
|
||||
#define string2decimal(A,B,C) internal_str2dec((A), (B), (C), 0)
|
||||
#define string2decimal_fixed(A,B,C) internal_str2dec((A), (B), (C), 1)
|
||||
|
||||
/* set a decimal_t to zero */
|
||||
|
||||
#define decimal_make_zero(dec) do { \
|
||||
(dec)->buf[0]=0; \
|
||||
(dec)->intg=1; \
|
||||
(dec)->frac=0; \
|
||||
(dec)->sign=0; \
|
||||
} while(0)
|
||||
|
||||
/*
|
||||
returns the length of the buffer to hold string representation
|
||||
of the decimal (including decimal dot, possible sign and \0)
|
||||
*/
|
||||
|
||||
#define decimal_string_size(dec) (((dec)->intg ? (dec)->intg : 1) + \
|
||||
(dec)->frac + ((dec)->frac > 0) + 2)
|
||||
|
||||
/*
|
||||
conventions:
|
||||
|
||||
decimal_smth() == 0 -- everything's ok
|
||||
decimal_smth() <= 1 -- result is usable, but precision loss is possible
|
||||
decimal_smth() <= 2 -- result can be unusable, most significant digits
|
||||
could've been lost
|
||||
decimal_smth() > 2 -- no result was generated
|
||||
*/
|
||||
|
||||
#define E_DEC_OK 0
|
||||
#define E_DEC_TRUNCATED 1
|
||||
#define E_DEC_OVERFLOW 2
|
||||
#define E_DEC_DIV_ZERO 4
|
||||
#define E_DEC_BAD_NUM 8
|
||||
#define E_DEC_OOM 16
|
||||
|
||||
#define E_DEC_ERROR 31
|
||||
#define E_DEC_FATAL_ERROR 30
|
||||
|
||||
#endif // !MYSQL_ABI_CHECK
|
||||
|
||||
#endif
|
|
@ -0,0 +1,121 @@
|
|||
#ifndef ERRMSG_INCLUDED
|
||||
#define ERRMSG_INCLUDED
|
||||
|
||||
/* Copyright (c) 2000, 2022, Oracle and/or its affiliates.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License, version 2.0,
|
||||
as published by the Free Software Foundation.
|
||||
|
||||
This program is also distributed with certain software (including
|
||||
but not limited to OpenSSL) that is licensed under separate terms,
|
||||
as designated in a particular file or component or in included license
|
||||
documentation. The authors of MySQL hereby grant you an additional
|
||||
permission to link the program and your derivative works with the
|
||||
separately licensed software that they have included with MySQL.
|
||||
|
||||
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, version 2.0, 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 St, Fifth Floor, Boston, MA 02110-1301 USA */
|
||||
|
||||
/* Error messages for MySQL clients */
|
||||
/* (Error messages for the daemon are in sql/share/errmsg.txt) */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
void init_client_errs(void);
|
||||
void finish_client_errs(void);
|
||||
extern const char *client_errors[]; /* Error messages */
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#define CR_MIN_ERROR 2000 /* For easier client code */
|
||||
#define CR_MAX_ERROR 2999
|
||||
#if !defined(ER)
|
||||
#define ER(X) (((X) >= CR_ERROR_FIRST && (X) <= CR_ERROR_LAST)? \
|
||||
client_errors[(X)-CR_ERROR_FIRST]: \
|
||||
client_errors[CR_UNKNOWN_ERROR -CR_ERROR_FIRST])
|
||||
|
||||
#endif
|
||||
#define CLIENT_ERRMAP 2 /* Errormap used by my_error() */
|
||||
|
||||
/* Do not add error numbers before CR_ERROR_FIRST. */
|
||||
/* If necessary to add lower numbers, change CR_ERROR_FIRST accordingly. */
|
||||
#define CR_ERROR_FIRST 2000 /*Copy first error nr.*/
|
||||
#define CR_UNKNOWN_ERROR 2000
|
||||
#define CR_SOCKET_CREATE_ERROR 2001
|
||||
#define CR_CONNECTION_ERROR 2002
|
||||
#define CR_CONN_HOST_ERROR 2003
|
||||
#define CR_IPSOCK_ERROR 2004
|
||||
#define CR_UNKNOWN_HOST 2005
|
||||
#define CR_SERVER_GONE_ERROR 2006
|
||||
#define CR_VERSION_ERROR 2007
|
||||
#define CR_OUT_OF_MEMORY 2008
|
||||
#define CR_WRONG_HOST_INFO 2009
|
||||
#define CR_LOCALHOST_CONNECTION 2010
|
||||
#define CR_TCP_CONNECTION 2011
|
||||
#define CR_SERVER_HANDSHAKE_ERR 2012
|
||||
#define CR_SERVER_LOST 2013
|
||||
#define CR_COMMANDS_OUT_OF_SYNC 2014
|
||||
#define CR_NAMEDPIPE_CONNECTION 2015
|
||||
#define CR_NAMEDPIPEWAIT_ERROR 2016
|
||||
#define CR_NAMEDPIPEOPEN_ERROR 2017
|
||||
#define CR_NAMEDPIPESETSTATE_ERROR 2018
|
||||
#define CR_CANT_READ_CHARSET 2019
|
||||
#define CR_NET_PACKET_TOO_LARGE 2020
|
||||
#define CR_EMBEDDED_CONNECTION 2021
|
||||
#define CR_PROBE_SLAVE_STATUS 2022
|
||||
#define CR_PROBE_SLAVE_HOSTS 2023
|
||||
#define CR_PROBE_SLAVE_CONNECT 2024
|
||||
#define CR_PROBE_MASTER_CONNECT 2025
|
||||
#define CR_SSL_CONNECTION_ERROR 2026
|
||||
#define CR_MALFORMED_PACKET 2027
|
||||
#define CR_WRONG_LICENSE 2028
|
||||
|
||||
/* new 4.1 error codes */
|
||||
#define CR_NULL_POINTER 2029
|
||||
#define CR_NO_PREPARE_STMT 2030
|
||||
#define CR_PARAMS_NOT_BOUND 2031
|
||||
#define CR_DATA_TRUNCATED 2032
|
||||
#define CR_NO_PARAMETERS_EXISTS 2033
|
||||
#define CR_INVALID_PARAMETER_NO 2034
|
||||
#define CR_INVALID_BUFFER_USE 2035
|
||||
#define CR_UNSUPPORTED_PARAM_TYPE 2036
|
||||
|
||||
#define CR_SHARED_MEMORY_CONNECTION 2037
|
||||
#define CR_SHARED_MEMORY_CONNECT_REQUEST_ERROR 2038
|
||||
#define CR_SHARED_MEMORY_CONNECT_ANSWER_ERROR 2039
|
||||
#define CR_SHARED_MEMORY_CONNECT_FILE_MAP_ERROR 2040
|
||||
#define CR_SHARED_MEMORY_CONNECT_MAP_ERROR 2041
|
||||
#define CR_SHARED_MEMORY_FILE_MAP_ERROR 2042
|
||||
#define CR_SHARED_MEMORY_MAP_ERROR 2043
|
||||
#define CR_SHARED_MEMORY_EVENT_ERROR 2044
|
||||
#define CR_SHARED_MEMORY_CONNECT_ABANDONED_ERROR 2045
|
||||
#define CR_SHARED_MEMORY_CONNECT_SET_ERROR 2046
|
||||
#define CR_CONN_UNKNOW_PROTOCOL 2047
|
||||
#define CR_INVALID_CONN_HANDLE 2048
|
||||
#define CR_UNUSED_1 2049
|
||||
#define CR_FETCH_CANCELED 2050
|
||||
#define CR_NO_DATA 2051
|
||||
#define CR_NO_STMT_METADATA 2052
|
||||
#define CR_NO_RESULT_SET 2053
|
||||
#define CR_NOT_IMPLEMENTED 2054
|
||||
#define CR_SERVER_LOST_EXTENDED 2055
|
||||
#define CR_STMT_CLOSED 2056
|
||||
#define CR_NEW_STMT_METADATA 2057
|
||||
#define CR_ALREADY_CONNECTED 2058
|
||||
#define CR_AUTH_PLUGIN_CANNOT_LOAD 2059
|
||||
#define CR_DUPLICATE_CONNECTION_ATTR 2060
|
||||
#define CR_AUTH_PLUGIN_ERR 2061
|
||||
#define CR_INSECURE_API_ERR 2062
|
||||
#define CR_ERROR_LAST /*Copy last error nr:*/ 2062
|
||||
/* Add error numbers before CR_ERROR_LAST and change it accordingly. */
|
||||
|
||||
#endif /* ERRMSG_INCLUDED */
|
|
@ -0,0 +1,163 @@
|
|||
/* Copyright (c) 2003, 2022, Oracle and/or its affiliates.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License, version 2.0,
|
||||
as published by the Free Software Foundation.
|
||||
|
||||
This program is also distributed with certain software (including
|
||||
but not limited to OpenSSL) that is licensed under separate terms,
|
||||
as designated in a particular file or component or in included license
|
||||
documentation. The authors of MySQL hereby grant you an additional
|
||||
permission to link the program and your derivative works with the
|
||||
separately licensed software that they have included with MySQL.
|
||||
|
||||
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, version 2.0, 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 St, Fifth Floor, Boston, MA 02110-1301 USA */
|
||||
|
||||
/* Key cache variable structures */
|
||||
|
||||
#ifndef _keycache_h
|
||||
#define _keycache_h
|
||||
|
||||
#include "my_sys.h" /* flush_type */
|
||||
|
||||
C_MODE_START
|
||||
|
||||
/* declare structures that is used by st_key_cache */
|
||||
|
||||
struct st_block_link;
|
||||
typedef struct st_block_link BLOCK_LINK;
|
||||
struct st_hash_link;
|
||||
typedef struct st_hash_link HASH_LINK;
|
||||
|
||||
/* Thread specific variables */
|
||||
typedef struct st_keycache_thread_var
|
||||
{
|
||||
mysql_cond_t suspend;
|
||||
struct st_keycache_thread_var *next,**prev;
|
||||
void *opt_info;
|
||||
} st_keycache_thread_var;
|
||||
|
||||
/* info about requests in a waiting queue */
|
||||
typedef struct st_keycache_wqueue
|
||||
{
|
||||
st_keycache_thread_var *last_thread; /* circular list of waiting threads */
|
||||
} KEYCACHE_WQUEUE;
|
||||
|
||||
#define CHANGED_BLOCKS_HASH 128 /* must be power of 2 */
|
||||
|
||||
/*
|
||||
The key cache structure
|
||||
It also contains read-only statistics parameters.
|
||||
*/
|
||||
|
||||
typedef struct st_key_cache
|
||||
{
|
||||
my_bool key_cache_inited;
|
||||
my_bool in_resize; /* true during resize operation */
|
||||
my_bool resize_in_flush; /* true during flush of resize operation */
|
||||
my_bool can_be_used; /* usage of cache for read/write is allowed */
|
||||
size_t key_cache_mem_size; /* specified size of the cache memory */
|
||||
uint key_cache_block_size; /* size of the page buffer of a cache block */
|
||||
ulonglong min_warm_blocks; /* min number of warm blocks; */
|
||||
ulonglong age_threshold; /* age threshold for hot blocks */
|
||||
ulonglong keycache_time; /* total number of block link operations */
|
||||
uint hash_entries; /* max number of entries in the hash table */
|
||||
int hash_links; /* max number of hash links */
|
||||
int hash_links_used; /* number of hash links currently used */
|
||||
int disk_blocks; /* max number of blocks in the cache */
|
||||
ulong blocks_used; /* maximum number of concurrently used blocks */
|
||||
ulong blocks_unused; /* number of currently unused blocks */
|
||||
ulong blocks_changed; /* number of currently dirty blocks */
|
||||
ulong warm_blocks; /* number of blocks in warm sub-chain */
|
||||
ulong cnt_for_resize_op; /* counter to block resize operation */
|
||||
long blocks_available; /* number of blocks available in the LRU chain */
|
||||
HASH_LINK **hash_root; /* arr. of entries into hash table buckets */
|
||||
HASH_LINK *hash_link_root; /* memory for hash table links */
|
||||
HASH_LINK *free_hash_list; /* list of free hash links */
|
||||
BLOCK_LINK *free_block_list; /* list of free blocks */
|
||||
BLOCK_LINK *block_root; /* memory for block links */
|
||||
uchar *block_mem; /* memory for block buffers */
|
||||
BLOCK_LINK *used_last; /* ptr to the last block of the LRU chain */
|
||||
BLOCK_LINK *used_ins; /* ptr to the insertion block in LRU chain */
|
||||
mysql_mutex_t cache_lock; /* to lock access to the cache structure */
|
||||
KEYCACHE_WQUEUE resize_queue; /* threads waiting during resize operation */
|
||||
/*
|
||||
Waiting for a zero resize count. Using a queue for symmetry though
|
||||
only one thread can wait here.
|
||||
*/
|
||||
KEYCACHE_WQUEUE waiting_for_resize_cnt;
|
||||
KEYCACHE_WQUEUE waiting_for_hash_link; /* waiting for a free hash link */
|
||||
KEYCACHE_WQUEUE waiting_for_block; /* requests waiting for a free block */
|
||||
BLOCK_LINK *changed_blocks[CHANGED_BLOCKS_HASH]; /* hash for dirty file bl.*/
|
||||
BLOCK_LINK *file_blocks[CHANGED_BLOCKS_HASH]; /* hash for other file bl.*/
|
||||
|
||||
/*
|
||||
The following variables are and variables used to hold parameters for
|
||||
initializing the key cache.
|
||||
*/
|
||||
|
||||
ulonglong param_buff_size; /* size the memory allocated for the cache */
|
||||
ulonglong param_block_size; /* size of the blocks in the key cache */
|
||||
ulonglong param_division_limit; /* min. percentage of warm blocks */
|
||||
ulonglong param_age_threshold; /* determines when hot block is downgraded */
|
||||
|
||||
/* Statistics variables. These are reset in reset_key_cache_counters(). */
|
||||
ulong global_blocks_changed; /* number of currently dirty blocks */
|
||||
ulonglong global_cache_w_requests;/* number of write requests (write hits) */
|
||||
ulonglong global_cache_write; /* number of writes from cache to files */
|
||||
ulonglong global_cache_r_requests;/* number of read requests (read hits) */
|
||||
ulonglong global_cache_read; /* number of reads from files to cache */
|
||||
|
||||
int blocks; /* max number of blocks in the cache */
|
||||
my_bool in_init; /* Set to 1 in MySQL during init/resize */
|
||||
} KEY_CACHE;
|
||||
|
||||
/* The default key cache */
|
||||
extern KEY_CACHE dflt_key_cache_var, *dflt_key_cache;
|
||||
|
||||
extern int init_key_cache(KEY_CACHE *keycache, ulonglong key_cache_block_size,
|
||||
size_t use_mem, ulonglong division_limit,
|
||||
ulonglong age_threshold);
|
||||
extern int resize_key_cache(KEY_CACHE *keycache,
|
||||
st_keycache_thread_var *thread_var,
|
||||
ulonglong key_cache_block_size,
|
||||
size_t use_mem, ulonglong division_limit,
|
||||
ulonglong age_threshold);
|
||||
extern uchar *key_cache_read(KEY_CACHE *keycache,
|
||||
st_keycache_thread_var *thread_var,
|
||||
File file, my_off_t filepos, int level,
|
||||
uchar *buff, uint length,
|
||||
uint block_length,int return_buffer);
|
||||
extern int key_cache_insert(KEY_CACHE *keycache,
|
||||
st_keycache_thread_var *thread_var,
|
||||
File file, my_off_t filepos, int level,
|
||||
uchar *buff, uint length);
|
||||
extern int key_cache_write(KEY_CACHE *keycache,
|
||||
st_keycache_thread_var *thread_var,
|
||||
File file, my_off_t filepos, int level,
|
||||
uchar *buff, uint length,
|
||||
uint block_length,int force_write);
|
||||
extern int flush_key_blocks(KEY_CACHE *keycache,
|
||||
st_keycache_thread_var *thread_var,
|
||||
int file, enum flush_type type);
|
||||
extern void end_key_cache(KEY_CACHE *keycache, my_bool cleanup);
|
||||
|
||||
/* Functions to handle multiple key caches */
|
||||
extern my_bool multi_keycache_init(void);
|
||||
extern void multi_keycache_free(void);
|
||||
extern KEY_CACHE *multi_key_cache_search(uchar *key, uint length);
|
||||
extern my_bool multi_key_cache_set(const uchar *key, uint length,
|
||||
KEY_CACHE *key_cache);
|
||||
extern void multi_key_cache_change(KEY_CACHE *old_data,
|
||||
KEY_CACHE *new_data);
|
||||
extern int reset_key_cache_counters(const char *name,
|
||||
KEY_CACHE *key_cache);
|
||||
C_MODE_END
|
||||
#endif /* _keycache_h */
|
|
@ -0,0 +1,105 @@
|
|||
#ifndef LITTLE_ENDIAN_INCLUDED
|
||||
#define LITTLE_ENDIAN_INCLUDED
|
||||
/* Copyright (c) 2012, 2022, Oracle and/or its affiliates.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License, version 2.0,
|
||||
as published by the Free Software Foundation.
|
||||
|
||||
This program is also distributed with certain software (including
|
||||
but not limited to OpenSSL) that is licensed under separate terms,
|
||||
as designated in a particular file or component or in included license
|
||||
documentation. The authors of MySQL hereby grant you an additional
|
||||
permission to link the program and your derivative works with the
|
||||
separately licensed software that they have included with MySQL.
|
||||
|
||||
Without limiting anything contained in the foregoing, this file,
|
||||
which is part of C Driver for MySQL (Connector/C), is also subject to the
|
||||
Universal FOSS Exception, version 1.0, a copy of which can be found at
|
||||
http://oss.oracle.com/licenses/universal-foss-exception.
|
||||
|
||||
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, version 2.0, 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 St, Fifth Floor, Boston, MA 02110-1301 USA */
|
||||
|
||||
/*
|
||||
Data in little-endian format.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
static inline void float4get (float *V, const uchar *M)
|
||||
{
|
||||
memcpy(V, (M), sizeof(float));
|
||||
}
|
||||
|
||||
static inline void float4store(uchar *V, float M)
|
||||
{
|
||||
memcpy(V, (&M), sizeof(float));
|
||||
}
|
||||
|
||||
static inline void float8get (double *V, const uchar *M)
|
||||
{
|
||||
memcpy(V, M, sizeof(double));
|
||||
}
|
||||
|
||||
static inline void float8store(uchar *V, double M)
|
||||
{
|
||||
memcpy(V, &M, sizeof(double));
|
||||
}
|
||||
|
||||
static inline void floatget (float *V, const uchar *M) { float4get(V, M); }
|
||||
static inline void floatstore (uchar *V, float M) { float4store(V, M); }
|
||||
|
||||
/* Bi-endian hardware.... */
|
||||
#if defined(__FLOAT_WORD_ORDER) && (__FLOAT_WORD_ORDER == __BIG_ENDIAN)
|
||||
static inline void doublestore(uchar *T, double V)
|
||||
{ *(((char*)T)+0)=(char) ((uchar *) &V)[4];
|
||||
*(((char*)T)+1)=(char) ((uchar *) &V)[5];
|
||||
*(((char*)T)+2)=(char) ((uchar *) &V)[6];
|
||||
*(((char*)T)+3)=(char) ((uchar *) &V)[7];
|
||||
*(((char*)T)+4)=(char) ((uchar *) &V)[0];
|
||||
*(((char*)T)+5)=(char) ((uchar *) &V)[1];
|
||||
*(((char*)T)+6)=(char) ((uchar *) &V)[2];
|
||||
*(((char*)T)+7)=(char) ((uchar *) &V)[3]; }
|
||||
static inline void doubleget(double *V, const uchar *M)
|
||||
{ double def_temp;
|
||||
((uchar*) &def_temp)[0]=(M)[4];
|
||||
((uchar*) &def_temp)[1]=(M)[5];
|
||||
((uchar*) &def_temp)[2]=(M)[6];
|
||||
((uchar*) &def_temp)[3]=(M)[7];
|
||||
((uchar*) &def_temp)[4]=(M)[0];
|
||||
((uchar*) &def_temp)[5]=(M)[1];
|
||||
((uchar*) &def_temp)[6]=(M)[2];
|
||||
((uchar*) &def_temp)[7]=(M)[3];
|
||||
(*V) = def_temp; }
|
||||
|
||||
#else /* Bi-endian hardware.... */
|
||||
|
||||
static inline void doublestore(uchar *T, double V) { memcpy(T, &V, sizeof(double)); }
|
||||
static inline void doubleget (double *V, const uchar *M) { memcpy(V, M, sizeof(double)); }
|
||||
|
||||
#endif /* Bi-endian hardware.... */
|
||||
|
||||
static inline void ushortget(uint16 *V, const uchar *pM) { *V= uint2korr(pM); }
|
||||
static inline void shortget (int16 *V, const uchar *pM) { *V= sint2korr(pM); }
|
||||
static inline void longget (int32 *V, const uchar *pM) { *V= sint4korr(pM); }
|
||||
static inline void ulongget (uint32 *V, const uchar *pM) { *V= uint4korr(pM); }
|
||||
static inline void shortstore(uchar *T, int16 V) { int2store(T, V); }
|
||||
static inline void longstore (uchar *T, int32 V) { int4store(T, V); }
|
||||
|
||||
static inline void longlongget(longlong *V, const uchar *M)
|
||||
{
|
||||
memcpy(V, (M), sizeof(ulonglong));
|
||||
}
|
||||
static inline void longlongstore(uchar *T, longlong V)
|
||||
{
|
||||
memcpy((T), &V, sizeof(ulonglong));
|
||||
}
|
||||
|
||||
#endif /* LITTLE_ENDIAN_INCLUDED */
|
|
@ -0,0 +1,813 @@
|
|||
/* Copyright (c) 2000, 2022, Oracle and/or its affiliates.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License, version 2.0,
|
||||
as published by the Free Software Foundation.
|
||||
|
||||
This program is also distributed with certain software (including
|
||||
but not limited to OpenSSL) that is licensed under separate terms,
|
||||
as designated in a particular file or component or in included license
|
||||
documentation. The authors of MySQL hereby grant you an additional
|
||||
permission to link the program and your derivative works with the
|
||||
separately licensed software that they have included with MySQL.
|
||||
|
||||
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, version 2.0, 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 St, Fifth Floor, Boston, MA 02110-1301 USA */
|
||||
|
||||
/*
|
||||
A better inplementation of the UNIX ctype(3) library.
|
||||
*/
|
||||
|
||||
#ifndef _m_ctype_h
|
||||
#define _m_ctype_h
|
||||
|
||||
#include "my_global.h" /* uint16, uchar */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define MY_CS_NAME_SIZE 32
|
||||
#define MY_CS_CTYPE_TABLE_SIZE 257
|
||||
#define MY_CS_TO_LOWER_TABLE_SIZE 256
|
||||
#define MY_CS_TO_UPPER_TABLE_SIZE 256
|
||||
#define MY_CS_SORT_ORDER_TABLE_SIZE 256
|
||||
#define MY_CS_TO_UNI_TABLE_SIZE 256
|
||||
|
||||
#define CHARSET_DIR "charsets/"
|
||||
|
||||
#define my_wc_t ulong
|
||||
|
||||
#define MY_CS_REPLACEMENT_CHARACTER 0xFFFD
|
||||
|
||||
/*
|
||||
On i386 we store Unicode->CS conversion tables for
|
||||
some character sets using Big-endian order,
|
||||
to copy two bytes at onces.
|
||||
This gives some performance improvement.
|
||||
*/
|
||||
#ifdef __i386__
|
||||
#define MB2(x) (((x) >> 8) + (((x) & 0xFF) << 8))
|
||||
#define MY_PUT_MB2(s, code) { *((uint16*)(s))= (code); }
|
||||
#else
|
||||
#define MB2(x) (x)
|
||||
#define MY_PUT_MB2(s, code) { (s)[0]= code >> 8; (s)[1]= code & 0xFF; }
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
typedef struct unicase_info_char_st
|
||||
{
|
||||
uint32 toupper;
|
||||
uint32 tolower;
|
||||
uint32 sort;
|
||||
} MY_UNICASE_CHARACTER;
|
||||
|
||||
|
||||
typedef struct unicase_info_st
|
||||
{
|
||||
my_wc_t maxchar;
|
||||
const MY_UNICASE_CHARACTER **page;
|
||||
} MY_UNICASE_INFO;
|
||||
|
||||
|
||||
extern MY_UNICASE_INFO my_unicase_default;
|
||||
extern MY_UNICASE_INFO my_unicase_turkish;
|
||||
extern MY_UNICASE_INFO my_unicase_mysql500;
|
||||
extern MY_UNICASE_INFO my_unicase_unicode520;
|
||||
|
||||
#define MY_UCA_MAX_CONTRACTION 6
|
||||
#define MY_UCA_MAX_WEIGHT_SIZE 8
|
||||
#define MY_UCA_WEIGHT_LEVELS 1
|
||||
|
||||
typedef struct my_contraction_t
|
||||
{
|
||||
my_wc_t ch[MY_UCA_MAX_CONTRACTION]; /* Character sequence */
|
||||
uint16 weight[MY_UCA_MAX_WEIGHT_SIZE];/* Its weight string, 0-terminated */
|
||||
my_bool with_context;
|
||||
} MY_CONTRACTION;
|
||||
|
||||
|
||||
|
||||
typedef struct my_contraction_list_t
|
||||
{
|
||||
size_t nitems; /* Number of items in the list */
|
||||
MY_CONTRACTION *item; /* List of contractions */
|
||||
char *flags; /* Character flags, e.g. "is contraction head") */
|
||||
} MY_CONTRACTIONS;
|
||||
|
||||
|
||||
my_bool my_uca_can_be_contraction_head(const MY_CONTRACTIONS *c, my_wc_t wc);
|
||||
my_bool my_uca_can_be_contraction_tail(const MY_CONTRACTIONS *c, my_wc_t wc);
|
||||
uint16 *my_uca_contraction2_weight(const MY_CONTRACTIONS *c,
|
||||
my_wc_t wc1, my_wc_t wc2);
|
||||
|
||||
|
||||
/* Collation weights on a single level (e.g. primary, secondary, tertiarty) */
|
||||
typedef struct my_uca_level_info_st
|
||||
{
|
||||
my_wc_t maxchar;
|
||||
uchar *lengths;
|
||||
uint16 **weights;
|
||||
MY_CONTRACTIONS contractions;
|
||||
} MY_UCA_WEIGHT_LEVEL;
|
||||
|
||||
|
||||
typedef struct uca_info_st
|
||||
{
|
||||
MY_UCA_WEIGHT_LEVEL level[MY_UCA_WEIGHT_LEVELS];
|
||||
|
||||
/* Logical positions */
|
||||
my_wc_t first_non_ignorable;
|
||||
my_wc_t last_non_ignorable;
|
||||
my_wc_t first_primary_ignorable;
|
||||
my_wc_t last_primary_ignorable;
|
||||
my_wc_t first_secondary_ignorable;
|
||||
my_wc_t last_secondary_ignorable;
|
||||
my_wc_t first_tertiary_ignorable;
|
||||
my_wc_t last_tertiary_ignorable;
|
||||
my_wc_t first_trailing;
|
||||
my_wc_t last_trailing;
|
||||
my_wc_t first_variable;
|
||||
my_wc_t last_variable;
|
||||
|
||||
} MY_UCA_INFO;
|
||||
|
||||
|
||||
|
||||
extern MY_UCA_INFO my_uca_v400;
|
||||
|
||||
|
||||
typedef struct uni_ctype_st
|
||||
{
|
||||
uchar pctype;
|
||||
uchar *ctype;
|
||||
} MY_UNI_CTYPE;
|
||||
|
||||
extern MY_UNI_CTYPE my_uni_ctype[256];
|
||||
|
||||
/* wm_wc and wc_mb return codes */
|
||||
#define MY_CS_ILSEQ 0 /* Wrong by sequence: wb_wc */
|
||||
#define MY_CS_ILUNI 0 /* Cannot encode Unicode to charset: wc_mb */
|
||||
#define MY_CS_TOOSMALL -101 /* Need at least one byte: wc_mb and mb_wc */
|
||||
#define MY_CS_TOOSMALL2 -102 /* Need at least two bytes: wc_mb and mb_wc */
|
||||
#define MY_CS_TOOSMALL3 -103 /* Need at least three bytes: wc_mb and mb_wc */
|
||||
/* These following three are currently not really used */
|
||||
#define MY_CS_TOOSMALL4 -104 /* Need at least 4 bytes: wc_mb and mb_wc */
|
||||
#define MY_CS_TOOSMALL5 -105 /* Need at least 5 bytes: wc_mb and mb_wc */
|
||||
#define MY_CS_TOOSMALL6 -106 /* Need at least 6 bytes: wc_mb and mb_wc */
|
||||
/* A helper macros for "need at least n bytes" */
|
||||
#define MY_CS_TOOSMALLN(n) (-100-(n))
|
||||
|
||||
#define MY_SEQ_INTTAIL 1
|
||||
#define MY_SEQ_SPACES 2
|
||||
|
||||
/* My charsets_list flags */
|
||||
#define MY_CS_COMPILED 1 /* compiled-in sets */
|
||||
#define MY_CS_CONFIG 2 /* sets that have a *.conf file */
|
||||
#define MY_CS_INDEX 4 /* sets listed in the Index file */
|
||||
#define MY_CS_LOADED 8 /* sets that are currently loaded */
|
||||
#define MY_CS_BINSORT 16 /* if binary sort order */
|
||||
#define MY_CS_PRIMARY 32 /* if primary collation */
|
||||
#define MY_CS_STRNXFRM 64 /* if strnxfrm is used for sort */
|
||||
#define MY_CS_UNICODE 128 /* is a charset is BMP Unicode */
|
||||
#define MY_CS_READY 256 /* if a charset is initialized */
|
||||
#define MY_CS_AVAILABLE 512 /* If either compiled-in or loaded*/
|
||||
#define MY_CS_CSSORT 1024 /* if case sensitive sort order */
|
||||
#define MY_CS_HIDDEN 2048 /* don't display in SHOW */
|
||||
#define MY_CS_PUREASCII 4096 /* if a charset is pure ascii */
|
||||
#define MY_CS_NONASCII 8192 /* if not ASCII-compatible */
|
||||
#define MY_CS_UNICODE_SUPPLEMENT 16384 /* Non-BMP Unicode characters */
|
||||
#define MY_CS_LOWER_SORT 32768 /* If use lower case as weight */
|
||||
#define MY_CHARSET_UNDEFINED 0
|
||||
|
||||
/* Character repertoire flags */
|
||||
#define MY_REPERTOIRE_ASCII 1 /* Pure ASCII U+0000..U+007F */
|
||||
#define MY_REPERTOIRE_EXTENDED 2 /* Extended characters: U+0080..U+FFFF */
|
||||
#define MY_REPERTOIRE_UNICODE30 3 /* ASCII | EXTENDED: U+0000..U+FFFF */
|
||||
|
||||
/* Flags for strxfrm */
|
||||
#define MY_STRXFRM_LEVEL1 0x00000001 /* for primary weights */
|
||||
#define MY_STRXFRM_LEVEL2 0x00000002 /* for secondary weights */
|
||||
#define MY_STRXFRM_LEVEL3 0x00000004 /* for tertiary weights */
|
||||
#define MY_STRXFRM_LEVEL4 0x00000008 /* fourth level weights */
|
||||
#define MY_STRXFRM_LEVEL5 0x00000010 /* fifth level weights */
|
||||
#define MY_STRXFRM_LEVEL6 0x00000020 /* sixth level weights */
|
||||
#define MY_STRXFRM_LEVEL_ALL 0x0000003F /* Bit OR for the above six */
|
||||
#define MY_STRXFRM_NLEVELS 6 /* Number of possible levels*/
|
||||
|
||||
#define MY_STRXFRM_PAD_WITH_SPACE 0x00000040 /* if pad result with spaces */
|
||||
#define MY_STRXFRM_PAD_TO_MAXLEN 0x00000080 /* if pad tail(for filesort) */
|
||||
|
||||
#define MY_STRXFRM_DESC_LEVEL1 0x00000100 /* if desc order for level1 */
|
||||
#define MY_STRXFRM_DESC_LEVEL2 0x00000200 /* if desc order for level2 */
|
||||
#define MY_STRXFRM_DESC_LEVEL3 0x00000300 /* if desc order for level3 */
|
||||
#define MY_STRXFRM_DESC_LEVEL4 0x00000800 /* if desc order for level4 */
|
||||
#define MY_STRXFRM_DESC_LEVEL5 0x00001000 /* if desc order for level5 */
|
||||
#define MY_STRXFRM_DESC_LEVEL6 0x00002000 /* if desc order for level6 */
|
||||
#define MY_STRXFRM_DESC_SHIFT 8
|
||||
|
||||
#define MY_STRXFRM_UNUSED_00004000 0x00004000 /* for future extensions */
|
||||
#define MY_STRXFRM_UNUSED_00008000 0x00008000 /* for future extensions */
|
||||
|
||||
#define MY_STRXFRM_REVERSE_LEVEL1 0x00010000 /* if reverse order for level1 */
|
||||
#define MY_STRXFRM_REVERSE_LEVEL2 0x00020000 /* if reverse order for level2 */
|
||||
#define MY_STRXFRM_REVERSE_LEVEL3 0x00040000 /* if reverse order for level3 */
|
||||
#define MY_STRXFRM_REVERSE_LEVEL4 0x00080000 /* if reverse order for level4 */
|
||||
#define MY_STRXFRM_REVERSE_LEVEL5 0x00100000 /* if reverse order for level5 */
|
||||
#define MY_STRXFRM_REVERSE_LEVEL6 0x00200000 /* if reverse order for level6 */
|
||||
#define MY_STRXFRM_REVERSE_SHIFT 16
|
||||
|
||||
|
||||
typedef struct my_uni_idx_st
|
||||
{
|
||||
uint16 from;
|
||||
uint16 to;
|
||||
const uchar *tab;
|
||||
} MY_UNI_IDX;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint beg;
|
||||
uint end;
|
||||
uint mb_len;
|
||||
} my_match_t;
|
||||
|
||||
struct charset_info_st;
|
||||
|
||||
typedef struct my_charset_loader_st
|
||||
{
|
||||
char error[128];
|
||||
void *(*once_alloc)(size_t);
|
||||
void *(*mem_malloc)(size_t);
|
||||
void *(*mem_realloc)(void *, size_t);
|
||||
void (*mem_free)(void *);
|
||||
void (*reporter)(enum loglevel, const char *format, ...);
|
||||
int (*add_collation)(struct charset_info_st *cs);
|
||||
} MY_CHARSET_LOADER;
|
||||
|
||||
|
||||
extern int (*my_string_stack_guard)(int);
|
||||
|
||||
/* See strings/CHARSET_INFO.txt for information about this structure */
|
||||
typedef struct my_collation_handler_st
|
||||
{
|
||||
my_bool (*init)(struct charset_info_st *, MY_CHARSET_LOADER *);
|
||||
/* Collation routines */
|
||||
int (*strnncoll)(const struct charset_info_st *,
|
||||
const uchar *, size_t, const uchar *, size_t, my_bool);
|
||||
int (*strnncollsp)(const struct charset_info_st *,
|
||||
const uchar *, size_t, const uchar *, size_t,
|
||||
my_bool diff_if_only_endspace_difference);
|
||||
size_t (*strnxfrm)(const struct charset_info_st *,
|
||||
uchar *dst, size_t dstlen, uint nweights,
|
||||
const uchar *src, size_t srclen, uint flags);
|
||||
size_t (*strnxfrmlen)(const struct charset_info_st *, size_t);
|
||||
my_bool (*like_range)(const struct charset_info_st *,
|
||||
const char *s, size_t s_length,
|
||||
pchar w_prefix, pchar w_one, pchar w_many,
|
||||
size_t res_length,
|
||||
char *min_str, char *max_str,
|
||||
size_t *min_len, size_t *max_len);
|
||||
int (*wildcmp)(const struct charset_info_st *,
|
||||
const char *str,const char *str_end,
|
||||
const char *wildstr,const char *wildend,
|
||||
int escape,int w_one, int w_many);
|
||||
|
||||
int (*strcasecmp)(const struct charset_info_st *, const char *,
|
||||
const char *);
|
||||
|
||||
uint (*instr)(const struct charset_info_st *,
|
||||
const char *b, size_t b_length,
|
||||
const char *s, size_t s_length,
|
||||
my_match_t *match, uint nmatch);
|
||||
|
||||
/* Hash calculation */
|
||||
void (*hash_sort)(const struct charset_info_st *cs, const uchar *key,
|
||||
size_t len, ulong *nr1, ulong *nr2);
|
||||
my_bool (*propagate)(const struct charset_info_st *cs, const uchar *str,
|
||||
size_t len);
|
||||
} MY_COLLATION_HANDLER;
|
||||
|
||||
extern MY_COLLATION_HANDLER my_collation_mb_bin_handler;
|
||||
extern MY_COLLATION_HANDLER my_collation_8bit_bin_handler;
|
||||
extern MY_COLLATION_HANDLER my_collation_8bit_simple_ci_handler;
|
||||
extern MY_COLLATION_HANDLER my_collation_ucs2_uca_handler;
|
||||
|
||||
/* Some typedef to make it easy for C++ to make function pointers */
|
||||
typedef int (*my_charset_conv_mb_wc)(const struct charset_info_st *,
|
||||
my_wc_t *, const uchar *, const uchar *);
|
||||
typedef int (*my_charset_conv_wc_mb)(const struct charset_info_st *, my_wc_t,
|
||||
uchar *, uchar *);
|
||||
typedef size_t (*my_charset_conv_case)(const struct charset_info_st *,
|
||||
char *, size_t, char *, size_t);
|
||||
|
||||
|
||||
/* See strings/CHARSET_INFO.txt about information on this structure */
|
||||
typedef struct my_charset_handler_st
|
||||
{
|
||||
my_bool (*init)(struct charset_info_st *, MY_CHARSET_LOADER *loader);
|
||||
/* Multibyte routines */
|
||||
uint (*ismbchar)(const struct charset_info_st *, const char *,
|
||||
const char *);
|
||||
uint (*mbcharlen)(const struct charset_info_st *, uint c);
|
||||
size_t (*numchars)(const struct charset_info_st *, const char *b,
|
||||
const char *e);
|
||||
size_t (*charpos)(const struct charset_info_st *, const char *b,
|
||||
const char *e, size_t pos);
|
||||
size_t (*well_formed_len)(const struct charset_info_st *,
|
||||
const char *b,const char *e,
|
||||
size_t nchars, int *error);
|
||||
size_t (*lengthsp)(const struct charset_info_st *, const char *ptr,
|
||||
size_t length);
|
||||
size_t (*numcells)(const struct charset_info_st *, const char *b,
|
||||
const char *e);
|
||||
|
||||
/* Unicode conversion */
|
||||
my_charset_conv_mb_wc mb_wc;
|
||||
my_charset_conv_wc_mb wc_mb;
|
||||
|
||||
/* CTYPE scanner */
|
||||
int (*ctype)(const struct charset_info_st *cs, int *ctype,
|
||||
const uchar *s, const uchar *e);
|
||||
|
||||
/* Functions for case and sort conversion */
|
||||
size_t (*caseup_str)(const struct charset_info_st *, char *);
|
||||
size_t (*casedn_str)(const struct charset_info_st *, char *);
|
||||
|
||||
my_charset_conv_case caseup;
|
||||
my_charset_conv_case casedn;
|
||||
|
||||
/* Charset dependant snprintf() */
|
||||
size_t (*snprintf)(const struct charset_info_st *, char *to, size_t n,
|
||||
const char *fmt,
|
||||
...) MY_ATTRIBUTE((format(printf, 4, 5)));
|
||||
size_t (*long10_to_str)(const struct charset_info_st *, char *to, size_t n,
|
||||
int radix, long int val);
|
||||
size_t (*longlong10_to_str)(const struct charset_info_st *, char *to,
|
||||
size_t n, int radix, longlong val);
|
||||
|
||||
void (*fill)(const struct charset_info_st *, char *to, size_t len,
|
||||
int fill);
|
||||
|
||||
/* String-to-number conversion routines */
|
||||
long (*strntol)(const struct charset_info_st *, const char *s,
|
||||
size_t l, int base, char **e, int *err);
|
||||
ulong (*strntoul)(const struct charset_info_st *, const char *s,
|
||||
size_t l, int base, char **e, int *err);
|
||||
longlong (*strntoll)(const struct charset_info_st *, const char *s,
|
||||
size_t l, int base, char **e, int *err);
|
||||
ulonglong (*strntoull)(const struct charset_info_st *, const char *s,
|
||||
size_t l, int base, char **e, int *err);
|
||||
double (*strntod)(const struct charset_info_st *, char *s,
|
||||
size_t l, char **e, int *err);
|
||||
longlong (*strtoll10)(const struct charset_info_st *cs,
|
||||
const char *nptr, char **endptr, int *error);
|
||||
ulonglong (*strntoull10rnd)(const struct charset_info_st *cs,
|
||||
const char *str, size_t length,
|
||||
int unsigned_fl,
|
||||
char **endptr, int *error);
|
||||
size_t (*scan)(const struct charset_info_st *, const char *b,
|
||||
const char *e, int sq);
|
||||
} MY_CHARSET_HANDLER;
|
||||
|
||||
extern MY_CHARSET_HANDLER my_charset_8bit_handler;
|
||||
extern MY_CHARSET_HANDLER my_charset_ascii_handler;
|
||||
extern MY_CHARSET_HANDLER my_charset_ucs2_handler;
|
||||
|
||||
|
||||
/*
|
||||
We define this CHARSET_INFO_DEFINED here to prevent a repeat of the
|
||||
typedef in hash.c, which will cause a compiler error.
|
||||
*/
|
||||
#define CHARSET_INFO_DEFINED
|
||||
|
||||
/* See strings/CHARSET_INFO.txt about information on this structure */
|
||||
typedef struct charset_info_st
|
||||
{
|
||||
uint number;
|
||||
uint primary_number;
|
||||
uint binary_number;
|
||||
uint state;
|
||||
const char *csname;
|
||||
const char *name;
|
||||
const char *comment;
|
||||
const char *tailoring;
|
||||
const uchar *ctype;
|
||||
const uchar *to_lower;
|
||||
const uchar *to_upper;
|
||||
const uchar *sort_order;
|
||||
MY_UCA_INFO *uca; /* This can be changed in apply_one_rule() */
|
||||
const uint16 *tab_to_uni;
|
||||
const MY_UNI_IDX *tab_from_uni;
|
||||
const MY_UNICASE_INFO *caseinfo;
|
||||
const struct lex_state_maps_st *state_maps; /* parser internal data */
|
||||
const uchar *ident_map; /* parser internal data */
|
||||
uint strxfrm_multiply;
|
||||
uchar caseup_multiply;
|
||||
uchar casedn_multiply;
|
||||
uint mbminlen;
|
||||
uint mbmaxlen;
|
||||
uint mbmaxlenlen;
|
||||
my_wc_t min_sort_char;
|
||||
my_wc_t max_sort_char; /* For LIKE optimization */
|
||||
uchar pad_char;
|
||||
my_bool escape_with_backslash_is_dangerous;
|
||||
uchar levels_for_compare;
|
||||
uchar levels_for_order;
|
||||
|
||||
MY_CHARSET_HANDLER *cset;
|
||||
MY_COLLATION_HANDLER *coll;
|
||||
|
||||
} CHARSET_INFO;
|
||||
#define ILLEGAL_CHARSET_INFO_NUMBER (~0U)
|
||||
|
||||
|
||||
extern MYSQL_PLUGIN_IMPORT CHARSET_INFO my_charset_bin;
|
||||
extern MYSQL_PLUGIN_IMPORT CHARSET_INFO my_charset_latin1;
|
||||
extern MYSQL_PLUGIN_IMPORT CHARSET_INFO my_charset_filename;
|
||||
|
||||
extern CHARSET_INFO my_charset_big5_chinese_ci;
|
||||
extern CHARSET_INFO my_charset_big5_bin;
|
||||
extern CHARSET_INFO my_charset_cp932_japanese_ci;
|
||||
extern CHARSET_INFO my_charset_cp932_bin;
|
||||
extern CHARSET_INFO my_charset_cp1250_czech_ci;
|
||||
extern CHARSET_INFO my_charset_eucjpms_japanese_ci;
|
||||
extern CHARSET_INFO my_charset_eucjpms_bin;
|
||||
extern CHARSET_INFO my_charset_euckr_korean_ci;
|
||||
extern CHARSET_INFO my_charset_euckr_bin;
|
||||
extern CHARSET_INFO my_charset_gb2312_chinese_ci;
|
||||
extern CHARSET_INFO my_charset_gb2312_bin;
|
||||
extern CHARSET_INFO my_charset_gbk_chinese_ci;
|
||||
extern CHARSET_INFO my_charset_gbk_bin;
|
||||
extern CHARSET_INFO my_charset_gb18030_chinese_ci;
|
||||
extern CHARSET_INFO my_charset_gb18030_bin;
|
||||
extern CHARSET_INFO my_charset_latin1_german2_ci;
|
||||
extern CHARSET_INFO my_charset_latin1_bin;
|
||||
extern CHARSET_INFO my_charset_latin2_czech_ci;
|
||||
extern CHARSET_INFO my_charset_sjis_japanese_ci;
|
||||
extern CHARSET_INFO my_charset_sjis_bin;
|
||||
extern CHARSET_INFO my_charset_tis620_thai_ci;
|
||||
extern CHARSET_INFO my_charset_tis620_bin;
|
||||
extern CHARSET_INFO my_charset_ucs2_general_ci;
|
||||
extern CHARSET_INFO my_charset_ucs2_bin;
|
||||
extern CHARSET_INFO my_charset_ucs2_unicode_ci;
|
||||
extern CHARSET_INFO my_charset_ucs2_general_mysql500_ci;
|
||||
extern CHARSET_INFO my_charset_ujis_japanese_ci;
|
||||
extern CHARSET_INFO my_charset_ujis_bin;
|
||||
extern CHARSET_INFO my_charset_utf16_bin;
|
||||
extern CHARSET_INFO my_charset_utf16_general_ci;
|
||||
extern CHARSET_INFO my_charset_utf16_unicode_ci;
|
||||
extern CHARSET_INFO my_charset_utf16le_bin;
|
||||
extern CHARSET_INFO my_charset_utf16le_general_ci;
|
||||
extern CHARSET_INFO my_charset_utf32_bin;
|
||||
extern CHARSET_INFO my_charset_utf32_general_ci;
|
||||
extern CHARSET_INFO my_charset_utf32_unicode_ci;
|
||||
|
||||
extern MYSQL_PLUGIN_IMPORT CHARSET_INFO my_charset_utf8_general_ci;
|
||||
extern CHARSET_INFO my_charset_utf8_tolower_ci;
|
||||
extern CHARSET_INFO my_charset_utf8_unicode_ci;
|
||||
extern CHARSET_INFO my_charset_utf8_bin;
|
||||
extern CHARSET_INFO my_charset_utf8_general_mysql500_ci;
|
||||
extern CHARSET_INFO my_charset_utf8mb4_bin;
|
||||
extern MYSQL_PLUGIN_IMPORT CHARSET_INFO my_charset_utf8mb4_general_ci;
|
||||
extern CHARSET_INFO my_charset_utf8mb4_unicode_ci;
|
||||
#define MY_UTF8MB3 "utf8"
|
||||
#define MY_UTF8MB4 "utf8mb4"
|
||||
|
||||
|
||||
/* declarations for simple charsets */
|
||||
extern size_t my_strnxfrm_simple(const CHARSET_INFO *,
|
||||
uchar *dst, size_t dstlen, uint nweights,
|
||||
const uchar *src, size_t srclen, uint flags);
|
||||
size_t my_strnxfrmlen_simple(const CHARSET_INFO *, size_t);
|
||||
extern int my_strnncoll_simple(const CHARSET_INFO *, const uchar *, size_t,
|
||||
const uchar *, size_t, my_bool);
|
||||
|
||||
extern int my_strnncollsp_simple(const CHARSET_INFO *, const uchar *, size_t,
|
||||
const uchar *, size_t,
|
||||
my_bool diff_if_only_endspace_difference);
|
||||
|
||||
extern void my_hash_sort_simple(const CHARSET_INFO *cs,
|
||||
const uchar *key, size_t len,
|
||||
ulong *nr1, ulong *nr2);
|
||||
|
||||
extern size_t my_lengthsp_8bit(const CHARSET_INFO *cs, const char *ptr,
|
||||
size_t length);
|
||||
|
||||
extern uint my_instr_simple(const struct charset_info_st *,
|
||||
const char *b, size_t b_length,
|
||||
const char *s, size_t s_length,
|
||||
my_match_t *match, uint nmatch);
|
||||
|
||||
|
||||
/* Functions for 8bit */
|
||||
extern size_t my_caseup_str_8bit(const CHARSET_INFO *, char *);
|
||||
extern size_t my_casedn_str_8bit(const CHARSET_INFO *, char *);
|
||||
extern size_t my_caseup_8bit(const CHARSET_INFO *, char *src, size_t srclen,
|
||||
char *dst, size_t dstlen);
|
||||
extern size_t my_casedn_8bit(const CHARSET_INFO *, char *src, size_t srclen,
|
||||
char *dst, size_t dstlen);
|
||||
|
||||
extern int my_strcasecmp_8bit(const CHARSET_INFO * cs, const char *,
|
||||
const char *);
|
||||
|
||||
int my_mb_wc_8bit(const CHARSET_INFO *cs,my_wc_t *wc, const uchar *s,
|
||||
const uchar *e);
|
||||
int my_wc_mb_8bit(const CHARSET_INFO *cs,my_wc_t wc, uchar *s, uchar *e);
|
||||
|
||||
int my_mb_ctype_8bit(const CHARSET_INFO *,int *, const uchar *,const uchar *);
|
||||
int my_mb_ctype_mb(const CHARSET_INFO *,int *, const uchar *,const uchar *);
|
||||
|
||||
size_t my_scan_8bit(const CHARSET_INFO *cs, const char *b, const char *e,
|
||||
int sq);
|
||||
|
||||
size_t my_snprintf_8bit(const struct charset_info_st *, char *to, size_t n,
|
||||
const char *fmt, ...)
|
||||
MY_ATTRIBUTE((format(printf, 4, 5)));
|
||||
|
||||
long my_strntol_8bit(const CHARSET_INFO *, const char *s, size_t l,
|
||||
int base, char **e, int *err);
|
||||
ulong my_strntoul_8bit(const CHARSET_INFO *, const char *s, size_t l,
|
||||
int base, char **e, int *err);
|
||||
longlong my_strntoll_8bit(const CHARSET_INFO *, const char *s, size_t l,
|
||||
int base, char **e, int *err);
|
||||
ulonglong my_strntoull_8bit(const CHARSET_INFO *, const char *s, size_t l,
|
||||
int base, char **e, int *err);
|
||||
double my_strntod_8bit(const CHARSET_INFO *, char *s, size_t l, char **e,
|
||||
int *err);
|
||||
size_t my_long10_to_str_8bit(const CHARSET_INFO *, char *to, size_t l,
|
||||
int radix, long int val);
|
||||
size_t my_longlong10_to_str_8bit(const CHARSET_INFO *, char *to, size_t l,
|
||||
int radix, longlong val);
|
||||
|
||||
longlong my_strtoll10_8bit(const CHARSET_INFO *cs,
|
||||
const char *nptr, char **endptr, int *error);
|
||||
longlong my_strtoll10_ucs2(const CHARSET_INFO *cs,
|
||||
const char *nptr, char **endptr, int *error);
|
||||
|
||||
ulonglong my_strntoull10rnd_8bit(const CHARSET_INFO *cs,
|
||||
const char *str, size_t length, int
|
||||
unsigned_fl, char **endptr, int *error);
|
||||
ulonglong my_strntoull10rnd_ucs2(const CHARSET_INFO *cs,
|
||||
const char *str, size_t length,
|
||||
int unsigned_fl, char **endptr, int *error);
|
||||
|
||||
void my_fill_8bit(const CHARSET_INFO *cs, char* to, size_t l, int fill);
|
||||
|
||||
/* For 8-bit character set */
|
||||
my_bool my_like_range_simple(const CHARSET_INFO *cs,
|
||||
const char *ptr, size_t ptr_length,
|
||||
pbool escape, pbool w_one, pbool w_many,
|
||||
size_t res_length,
|
||||
char *min_str, char *max_str,
|
||||
size_t *min_length, size_t *max_length);
|
||||
|
||||
/* For ASCII-based multi-byte character sets with mbminlen=1 */
|
||||
my_bool my_like_range_mb(const CHARSET_INFO *cs,
|
||||
const char *ptr, size_t ptr_length,
|
||||
pbool escape, pbool w_one, pbool w_many,
|
||||
size_t res_length,
|
||||
char *min_str, char *max_str,
|
||||
size_t *min_length, size_t *max_length);
|
||||
|
||||
/* For other character sets, with arbitrary mbminlen and mbmaxlen numbers */
|
||||
my_bool my_like_range_generic(const CHARSET_INFO *cs,
|
||||
const char *ptr, size_t ptr_length,
|
||||
pbool escape, pbool w_one, pbool w_many,
|
||||
size_t res_length,
|
||||
char *min_str, char *max_str,
|
||||
size_t *min_length, size_t *max_length);
|
||||
|
||||
int my_wildcmp_8bit(const CHARSET_INFO *,
|
||||
const char *str,const char *str_end,
|
||||
const char *wildstr,const char *wildend,
|
||||
int escape, int w_one, int w_many);
|
||||
|
||||
int my_wildcmp_bin(const CHARSET_INFO *,
|
||||
const char *str,const char *str_end,
|
||||
const char *wildstr,const char *wildend,
|
||||
int escape, int w_one, int w_many);
|
||||
|
||||
size_t my_numchars_8bit(const CHARSET_INFO *, const char *b, const char *e);
|
||||
size_t my_numcells_8bit(const CHARSET_INFO *, const char *b, const char *e);
|
||||
size_t my_charpos_8bit(const CHARSET_INFO *, const char *b, const char *e,
|
||||
size_t pos);
|
||||
size_t my_well_formed_len_8bit(const CHARSET_INFO *, const char *b,
|
||||
const char *e, size_t pos, int *error);
|
||||
uint my_mbcharlen_8bit(const CHARSET_INFO *, uint c);
|
||||
|
||||
|
||||
/* Functions for multibyte charsets */
|
||||
extern size_t my_caseup_str_mb(const CHARSET_INFO *, char *);
|
||||
extern size_t my_casedn_str_mb(const CHARSET_INFO *, char *);
|
||||
extern size_t my_caseup_mb(const CHARSET_INFO *, char *src, size_t srclen,
|
||||
char *dst, size_t dstlen);
|
||||
extern size_t my_casedn_mb(const CHARSET_INFO *, char *src, size_t srclen,
|
||||
char *dst, size_t dstlen);
|
||||
extern size_t my_caseup_mb_varlen(const CHARSET_INFO *, char *src,
|
||||
size_t srclen, char *dst, size_t dstlen);
|
||||
extern size_t my_casedn_mb_varlen(const CHARSET_INFO *, char *src,
|
||||
size_t srclen, char *dst, size_t dstlen);
|
||||
extern size_t my_caseup_ujis(const CHARSET_INFO *, char *src, size_t srclen,
|
||||
char *dst, size_t dstlen);
|
||||
extern size_t my_casedn_ujis(const CHARSET_INFO *, char *src, size_t srclen,
|
||||
char *dst, size_t dstlen);
|
||||
extern int my_strcasecmp_mb(const CHARSET_INFO * cs,const char *,
|
||||
const char *);
|
||||
|
||||
int my_wildcmp_mb(const CHARSET_INFO *,
|
||||
const char *str,const char *str_end,
|
||||
const char *wildstr,const char *wildend,
|
||||
int escape, int w_one, int w_many);
|
||||
size_t my_numchars_mb(const CHARSET_INFO *, const char *b, const char *e);
|
||||
size_t my_numcells_mb(const CHARSET_INFO *, const char *b, const char *e);
|
||||
size_t my_charpos_mb(const CHARSET_INFO *, const char *b, const char *e,
|
||||
size_t pos);
|
||||
size_t my_well_formed_len_mb(const CHARSET_INFO *, const char *b,
|
||||
const char *e, size_t pos, int *error);
|
||||
uint my_instr_mb(const struct charset_info_st *,
|
||||
const char *b, size_t b_length,
|
||||
const char *s, size_t s_length,
|
||||
my_match_t *match, uint nmatch);
|
||||
|
||||
int my_strnncoll_mb_bin(const CHARSET_INFO * cs,
|
||||
const uchar *s, size_t slen,
|
||||
const uchar *t, size_t tlen,
|
||||
my_bool t_is_prefix);
|
||||
|
||||
int my_strnncollsp_mb_bin(const CHARSET_INFO *cs,
|
||||
const uchar *a, size_t a_length,
|
||||
const uchar *b, size_t b_length,
|
||||
my_bool diff_if_only_endspace_difference);
|
||||
|
||||
int my_wildcmp_mb_bin(const CHARSET_INFO *cs,
|
||||
const char *str,const char *str_end,
|
||||
const char *wildstr,const char *wildend,
|
||||
int escape, int w_one, int w_many);
|
||||
|
||||
int my_strcasecmp_mb_bin(const CHARSET_INFO * cs MY_ATTRIBUTE((unused)),
|
||||
const char *s, const char *t);
|
||||
|
||||
void my_hash_sort_mb_bin(const CHARSET_INFO *cs MY_ATTRIBUTE((unused)),
|
||||
const uchar *key, size_t len,ulong *nr1, ulong *nr2);
|
||||
|
||||
size_t my_strnxfrm_mb(const CHARSET_INFO *,
|
||||
uchar *dst, size_t dstlen, uint nweights,
|
||||
const uchar *src, size_t srclen, uint flags);
|
||||
|
||||
size_t my_strnxfrm_unicode(const CHARSET_INFO *,
|
||||
uchar *dst, size_t dstlen, uint nweights,
|
||||
const uchar *src, size_t srclen, uint flags);
|
||||
|
||||
size_t my_strnxfrm_unicode_full_bin(const CHARSET_INFO *,
|
||||
uchar *dst, size_t dstlen, uint nweights,
|
||||
const uchar *src, size_t srclen, uint flags);
|
||||
size_t my_strnxfrmlen_unicode_full_bin(const CHARSET_INFO *, size_t);
|
||||
|
||||
int my_wildcmp_unicode(const CHARSET_INFO *cs,
|
||||
const char *str, const char *str_end,
|
||||
const char *wildstr, const char *wildend,
|
||||
int escape, int w_one, int w_many,
|
||||
const MY_UNICASE_INFO *weights);
|
||||
|
||||
extern my_bool my_parse_charset_xml(MY_CHARSET_LOADER *loader,
|
||||
const char *buf, size_t buflen);
|
||||
extern char *my_strchr(const CHARSET_INFO *cs, const char *str,
|
||||
const char *end, pchar c);
|
||||
extern size_t my_strcspn(const CHARSET_INFO *cs, const char *str,
|
||||
const char *end, const char *reject,
|
||||
size_t reject_length);
|
||||
|
||||
my_bool my_propagate_simple(const CHARSET_INFO *cs, const uchar *str,
|
||||
size_t len);
|
||||
my_bool my_propagate_complex(const CHARSET_INFO *cs, const uchar *str,
|
||||
size_t len);
|
||||
|
||||
|
||||
uint my_string_repertoire(const CHARSET_INFO *cs, const char *str, size_t len);
|
||||
my_bool my_charset_is_ascii_based(const CHARSET_INFO *cs);
|
||||
my_bool my_charset_is_8bit_pure_ascii(const CHARSET_INFO *cs);
|
||||
uint my_charset_repertoire(const CHARSET_INFO *cs);
|
||||
|
||||
|
||||
uint my_strxfrm_flag_normalize(uint flags, uint nlevels);
|
||||
void my_strxfrm_desc_and_reverse(uchar *str, uchar *strend,
|
||||
uint flags, uint level);
|
||||
size_t my_strxfrm_pad_desc_and_reverse(const CHARSET_INFO *cs,
|
||||
uchar *str, uchar *frmend, uchar *strend,
|
||||
uint nweights, uint flags, uint level);
|
||||
|
||||
my_bool my_charset_is_ascii_compatible(const CHARSET_INFO *cs);
|
||||
|
||||
const MY_CONTRACTIONS *my_charset_get_contractions(const CHARSET_INFO *cs,
|
||||
int level);
|
||||
|
||||
extern size_t my_vsnprintf_ex(const CHARSET_INFO *cs, char *to, size_t n,
|
||||
const char* fmt, va_list ap);
|
||||
|
||||
size_t my_convert(char *to, size_t to_length, const CHARSET_INFO *to_cs,
|
||||
const char *from, size_t from_length,
|
||||
const CHARSET_INFO *from_cs, uint *errors);
|
||||
|
||||
uint my_mbcharlen_ptr(const CHARSET_INFO *cs, const char *s, const char *e);
|
||||
|
||||
#define _MY_U 01 /* Upper case */
|
||||
#define _MY_L 02 /* Lower case */
|
||||
#define _MY_NMR 04 /* Numeral (digit) */
|
||||
#define _MY_SPC 010 /* Spacing character */
|
||||
#define _MY_PNT 020 /* Punctuation */
|
||||
#define _MY_CTR 040 /* Control character */
|
||||
#define _MY_B 0100 /* Blank */
|
||||
#define _MY_X 0200 /* heXadecimal digit */
|
||||
|
||||
|
||||
#define my_isascii(c) (!((c) & ~0177))
|
||||
#define my_toascii(c) ((c) & 0177)
|
||||
#define my_tocntrl(c) ((c) & 31)
|
||||
#define my_toprint(c) ((c) | 64)
|
||||
#define my_toupper(s,c) (char) ((s)->to_upper[(uchar) (c)])
|
||||
#define my_tolower(s,c) (char) ((s)->to_lower[(uchar) (c)])
|
||||
#define my_isalpha(s, c) (((s)->ctype+1)[(uchar) (c)] & (_MY_U | _MY_L))
|
||||
#define my_isupper(s, c) (((s)->ctype+1)[(uchar) (c)] & _MY_U)
|
||||
#define my_islower(s, c) (((s)->ctype+1)[(uchar) (c)] & _MY_L)
|
||||
#define my_isdigit(s, c) (((s)->ctype+1)[(uchar) (c)] & _MY_NMR)
|
||||
#define my_isxdigit(s, c) (((s)->ctype+1)[(uchar) (c)] & _MY_X)
|
||||
#define my_isalnum(s, c) (((s)->ctype+1)[(uchar) (c)] & (_MY_U | _MY_L | _MY_NMR))
|
||||
#define my_isspace(s, c) (((s)->ctype+1)[(uchar) (c)] & _MY_SPC)
|
||||
#define my_ispunct(s, c) (((s)->ctype+1)[(uchar) (c)] & _MY_PNT)
|
||||
#define my_isprint(s, c) (((s)->ctype+1)[(uchar) (c)] & (_MY_PNT | _MY_U | _MY_L | _MY_NMR | _MY_B))
|
||||
#define my_isgraph(s, c) (((s)->ctype+1)[(uchar) (c)] & (_MY_PNT | _MY_U | _MY_L | _MY_NMR))
|
||||
#define my_iscntrl(s, c) (((s)->ctype+1)[(uchar) (c)] & _MY_CTR)
|
||||
|
||||
/* Some macros that should be cleaned up a little */
|
||||
#define my_isvar(s,c) (my_isalnum(s,c) || (c) == '_')
|
||||
#define my_isvar_start(s,c) (my_isalpha(s,c) || (c) == '_')
|
||||
|
||||
#define my_binary_compare(s) ((s)->state & MY_CS_BINSORT)
|
||||
#define use_strnxfrm(s) ((s)->state & MY_CS_STRNXFRM)
|
||||
#define my_strnxfrm(cs, d, dl, s, sl) \
|
||||
((cs)->coll->strnxfrm((cs), (d), (dl), (dl), (s), (sl), MY_STRXFRM_PAD_WITH_SPACE))
|
||||
#define my_strnncoll(s, a, b, c, d) ((s)->coll->strnncoll((s), (a), (b), (c), (d), 0))
|
||||
#define my_like_range(s, a, b, c, d, e, f, g, h, i, j) \
|
||||
((s)->coll->like_range((s), (a), (b), (c), (d), (e), (f), (g), (h), (i), (j)))
|
||||
#define my_wildcmp(cs,s,se,w,we,e,o,m) ((cs)->coll->wildcmp((cs),(s),(se),(w),(we),(e),(o),(m)))
|
||||
#define my_strcasecmp(s, a, b) ((s)->coll->strcasecmp((s), (a), (b)))
|
||||
#define my_charpos(cs, b, e, num) (cs)->cset->charpos((cs), (const char*) (b), (const char *)(e), (num))
|
||||
|
||||
|
||||
#define use_mb(s) ((s)->cset->ismbchar != NULL)
|
||||
#define my_ismbchar(s, a, b) ((s)->cset->ismbchar((s), (a), (b)))
|
||||
#define my_mbcharlen(s, a) ((s)->cset->mbcharlen((s),(a)))
|
||||
/**
|
||||
Get the length of gb18030 code by the given two leading bytes
|
||||
|
||||
@param[in] s charset_info
|
||||
@param[in] a first byte of gb18030 code
|
||||
@param[in] b second byte of gb18030 code
|
||||
@return the length of gb18030 code starting with given two bytes,
|
||||
the length would be 2 or 4 for valid gb18030 code,
|
||||
or 0 for invalid gb18030 code
|
||||
*/
|
||||
#define my_mbcharlen_2(s, a, b) ((s)->cset->mbcharlen((s),((((a) & 0xFF) << 8) + ((b) & 0xFF))))
|
||||
/**
|
||||
Get the maximum length of leading bytes needed to determine the length of a
|
||||
multi-byte gb18030 code
|
||||
|
||||
@param[in] s charset_info
|
||||
@return number of leading bytes we need, would be 2 for gb18030
|
||||
and 1 for all other charsets
|
||||
*/
|
||||
#define my_mbmaxlenlen(s) ((s)->mbmaxlenlen)
|
||||
/**
|
||||
Judge if the given byte is a possible leading byte for a charset.
|
||||
For gb18030 whose mbmaxlenlen is 2, we can't determine the length of
|
||||
a multi-byte character by looking at the first byte only
|
||||
|
||||
@param[in] s charset_info
|
||||
@param[in] i possible leading byte
|
||||
@return true if it is, otherwise false
|
||||
*/
|
||||
#define my_ismb1st(s, i) \
|
||||
(my_mbcharlen((s), (i)) > 1 || \
|
||||
(my_mbmaxlenlen((s)) == 2 && my_mbcharlen((s), (i)) == 0))
|
||||
|
||||
#define my_caseup_str(s, a) ((s)->cset->caseup_str((s), (a)))
|
||||
#define my_casedn_str(s, a) ((s)->cset->casedn_str((s), (a)))
|
||||
#define my_strntol(s, a, b, c, d, e) ((s)->cset->strntol((s),(a),(b),(c),(d),(e)))
|
||||
#define my_strntoul(s, a, b, c, d, e) ((s)->cset->strntoul((s),(a),(b),(c),(d),(e)))
|
||||
#define my_strntoll(s, a, b, c, d, e) ((s)->cset->strntoll((s),(a),(b),(c),(d),(e)))
|
||||
#define my_strntoull(s, a, b, c,d, e) ((s)->cset->strntoull((s),(a),(b),(c),(d),(e)))
|
||||
#define my_strntod(s, a, b, c, d) ((s)->cset->strntod((s),(a),(b),(c),(d)))
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _m_ctype_h */
|
|
@ -0,0 +1,351 @@
|
|||
/*
|
||||
Copyright (c) 2000, 2022, Oracle and/or its affiliates.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License, version 2.0,
|
||||
as published by the Free Software Foundation.
|
||||
|
||||
This program is also distributed with certain software (including
|
||||
but not limited to OpenSSL) that is licensed under separate terms,
|
||||
as designated in a particular file or component or in included license
|
||||
documentation. The authors of MySQL hereby grant you an additional
|
||||
permission to link the program and your derivative works with the
|
||||
separately licensed software that they have included with MySQL.
|
||||
|
||||
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, version 2.0, 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 St, Fifth Floor, Boston, MA 02110-1301 USA */
|
||||
|
||||
#ifndef _m_string_h
|
||||
#define _m_string_h
|
||||
|
||||
#include "my_global.h" /* HAVE_* */
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#define bfill please_use_memset_rather_than_bfill
|
||||
#ifdef bzero
|
||||
#undef bzero
|
||||
#endif
|
||||
#define bzero please_use_memset_rather_than_bzero
|
||||
#define bmove please_use_memmove_rather_than_bmove
|
||||
#define strmov please_use_my_stpcpy_or_my_stpmov_rather_than_strmov
|
||||
#define strnmov please_use_my_stpncpy_or_my_stpnmov_rather_than_strnmov
|
||||
|
||||
#include "mysql/service_my_snprintf.h"
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
my_str_malloc(), my_str_realloc() and my_str_free() are assigned to
|
||||
implementations in strings/alloc.c, but can be overridden in
|
||||
the calling program.
|
||||
*/
|
||||
extern void *(*my_str_malloc)(size_t);
|
||||
extern void *(*my_str_realloc)(void *, size_t);
|
||||
extern void (*my_str_free)(void *);
|
||||
|
||||
/* Declared in int2str() */
|
||||
extern char _dig_vec_upper[];
|
||||
extern char _dig_vec_lower[];
|
||||
|
||||
/* Prototypes for string functions */
|
||||
|
||||
extern void bchange(uchar *dst,size_t old_len,const uchar *src,
|
||||
size_t new_len,size_t tot_len);
|
||||
extern void strappend(char *s,size_t len,pchar fill);
|
||||
extern char *strend(const char *s);
|
||||
extern char *strcend(const char *, pchar);
|
||||
extern char *strfill(char * s,size_t len,pchar fill);
|
||||
extern char *strmake(char *dst,const char *src,size_t length);
|
||||
|
||||
extern char *my_stpmov(char *dst,const char *src);
|
||||
extern char *my_stpnmov(char *dst, const char *src, size_t n);
|
||||
extern char *strcont(const char *src, const char *set);
|
||||
extern char *strxmov(char *dst, const char *src, ...);
|
||||
extern char *strxnmov(char *dst, size_t len, const char *src, ...);
|
||||
|
||||
/**
|
||||
Copy a string from src to dst until (and including) terminating null byte.
|
||||
|
||||
@param dst Destination
|
||||
@param src Source
|
||||
|
||||
@note src and dst cannot overlap.
|
||||
Use my_stpmov() if src and dst overlaps.
|
||||
|
||||
@note Unsafe, consider using my_stpnpy() instead.
|
||||
|
||||
@return pointer to terminating null byte.
|
||||
*/
|
||||
static inline char *my_stpcpy(char *dst, const char *src)
|
||||
{
|
||||
#if defined(HAVE_BUILTIN_STPCPY)
|
||||
return __builtin_stpcpy(dst, src);
|
||||
#elif defined(HAVE_STPCPY)
|
||||
return stpcpy(dst, src);
|
||||
#else
|
||||
/* Fallback to implementation supporting overlap. */
|
||||
return my_stpmov(dst, src);
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
Copy fixed-size string from src to dst.
|
||||
|
||||
@param dst Destination
|
||||
@param src Source
|
||||
@param n Maximum number of characters to copy.
|
||||
|
||||
@note src and dst cannot overlap
|
||||
Use my_stpnmov() if src and dst overlaps.
|
||||
|
||||
@return pointer to terminating null byte.
|
||||
*/
|
||||
static inline char *my_stpncpy(char *dst, const char *src, size_t n)
|
||||
{
|
||||
#if defined(HAVE_STPNCPY)
|
||||
return stpncpy(dst, src, n);
|
||||
#else
|
||||
/* Fallback to implementation supporting overlap. */
|
||||
return my_stpnmov(dst, src, n);
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline longlong my_strtoll(const char *nptr, char **endptr, int base)
|
||||
{
|
||||
#if defined _WIN32
|
||||
return _strtoi64(nptr, endptr, base);
|
||||
#else
|
||||
return strtoll(nptr, endptr, base);
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline ulonglong my_strtoull(const char *nptr, char **endptr, int base)
|
||||
{
|
||||
#if defined _WIN32
|
||||
return _strtoui64(nptr, endptr, base);
|
||||
#else
|
||||
return strtoull(nptr, endptr, base);
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline char *my_strtok_r(char *str, const char *delim, char **saveptr)
|
||||
{
|
||||
#if defined _WIN32
|
||||
return strtok_s(str, delim, saveptr);
|
||||
#else
|
||||
return strtok_r(str, delim, saveptr);
|
||||
#endif
|
||||
}
|
||||
|
||||
/* native_ rather than my_ since my_strcasecmp already exists */
|
||||
static inline int native_strcasecmp(const char *s1, const char *s2)
|
||||
{
|
||||
#if defined _WIN32
|
||||
return _stricmp(s1, s2);
|
||||
#else
|
||||
return strcasecmp(s1, s2);
|
||||
#endif
|
||||
}
|
||||
|
||||
/* native_ rather than my_ for consistency with native_strcasecmp */
|
||||
static inline int native_strncasecmp(const char *s1, const char *s2, size_t n)
|
||||
{
|
||||
#if defined _WIN32
|
||||
return _strnicmp(s1, s2, n);
|
||||
#else
|
||||
return strncasecmp(s1, s2, n);
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Prototypes of normal stringfunctions (with may ours) */
|
||||
#ifndef HAVE_STRNLEN
|
||||
extern size_t strnlen(const char *s, size_t n);
|
||||
#endif
|
||||
|
||||
extern int is_prefix(const char *, const char *);
|
||||
|
||||
/* Conversion routines */
|
||||
typedef enum {
|
||||
MY_GCVT_ARG_FLOAT,
|
||||
MY_GCVT_ARG_DOUBLE
|
||||
} my_gcvt_arg_type;
|
||||
|
||||
double my_strtod(const char *str, char **end, int *error);
|
||||
double my_atof(const char *nptr);
|
||||
size_t my_fcvt(double x, int precision, char *to, my_bool *error);
|
||||
size_t my_gcvt(double x, my_gcvt_arg_type type, int width, char *to,
|
||||
my_bool *error);
|
||||
|
||||
#define NOT_FIXED_DEC 31
|
||||
|
||||
/*
|
||||
The longest string my_fcvt can return is 311 + "precision" bytes.
|
||||
Here we assume that we never cal my_fcvt() with precision >= NOT_FIXED_DEC
|
||||
(+ 1 byte for the terminating '\0').
|
||||
*/
|
||||
#define FLOATING_POINT_BUFFER (311 + NOT_FIXED_DEC)
|
||||
|
||||
/*
|
||||
We want to use the 'e' format in some cases even if we have enough space
|
||||
for the 'f' one just to mimic sprintf("%.15g") behavior for large integers,
|
||||
and to improve it for numbers < 10^(-4).
|
||||
That is, for |x| < 1 we require |x| >= 10^(-15), and for |x| > 1 we require
|
||||
it to be integer and be <= 10^DBL_DIG for the 'f' format to be used.
|
||||
We don't lose precision, but make cases like "1e200" or "0.00001" look nicer.
|
||||
*/
|
||||
#define MAX_DECPT_FOR_F_FORMAT DBL_DIG
|
||||
|
||||
/*
|
||||
The maximum possible field width for my_gcvt() conversion.
|
||||
(DBL_DIG + 2) significant digits + sign + "." + ("e-NNN" or
|
||||
MAX_DECPT_FOR_F_FORMAT zeros for cases when |x|<1 and the 'f' format is used).
|
||||
*/
|
||||
#define MY_GCVT_MAX_FIELD_WIDTH (DBL_DIG + 4 + MY_MAX(5, MAX_DECPT_FOR_F_FORMAT)) \
|
||||
|
||||
extern char *llstr(longlong value,char *buff);
|
||||
extern char *ullstr(longlong value,char *buff);
|
||||
|
||||
extern char *int2str(long val, char *dst, int radix, int upcase);
|
||||
extern char *int10_to_str(long val,char *dst,int radix);
|
||||
extern char *str2int(const char *src,int radix,long lower,long upper,
|
||||
long *val);
|
||||
longlong my_strtoll10(const char *nptr, char **endptr, int *error);
|
||||
#if SIZEOF_LONG == SIZEOF_LONG_LONG
|
||||
#define ll2str(A,B,C,D) int2str((A),(B),(C),(D))
|
||||
#define longlong10_to_str(A,B,C) int10_to_str((A),(B),(C))
|
||||
#undef strtoll
|
||||
#define strtoll(A,B,C) strtol((A),(B),(C))
|
||||
#define strtoull(A,B,C) strtoul((A),(B),(C))
|
||||
#else
|
||||
extern char *ll2str(longlong val,char *dst,int radix, int upcase);
|
||||
extern char *longlong10_to_str(longlong val,char *dst,int radix);
|
||||
#endif
|
||||
#define longlong2str(A,B,C) ll2str((A),(B),(C),1)
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
LEX_STRING -- a pair of a C-string and its length.
|
||||
(it's part of the plugin API as a MYSQL_LEX_STRING)
|
||||
Ditto LEX_CSTRING/MYSQL_LEX_CSTRING.
|
||||
*/
|
||||
|
||||
#include <mysql/mysql_lex_string.h>
|
||||
typedef struct st_mysql_lex_string LEX_STRING;
|
||||
typedef struct st_mysql_const_lex_string LEX_CSTRING;
|
||||
|
||||
#define STRING_WITH_LEN(X) (X), ((sizeof(X) - 1))
|
||||
#define USTRING_WITH_LEN(X) ((uchar*) X), ((sizeof(X) - 1))
|
||||
#define C_STRING_WITH_LEN(X) ((char *) (X)), ((sizeof(X) - 1))
|
||||
|
||||
|
||||
/**
|
||||
Skip trailing space.
|
||||
|
||||
On most systems reading memory in larger chunks (ideally equal to the size of
|
||||
the chinks that the machine physically reads from memory) causes fewer memory
|
||||
access loops and hence increased performance.
|
||||
This is why the 'int' type is used : it's closest to that (according to how
|
||||
it's defined in C).
|
||||
So when we determine the amount of whitespace at the end of a string we do
|
||||
the following :
|
||||
1. We divide the string into 3 zones :
|
||||
a) from the start of the string (__start) to the first multiple
|
||||
of sizeof(int) (__start_words)
|
||||
b) from the end of the string (__end) to the last multiple of sizeof(int)
|
||||
(__end_words)
|
||||
c) a zone that is aligned to sizeof(int) and can be safely accessed
|
||||
through an int *
|
||||
2. We start comparing backwards from (c) char-by-char. If all we find is
|
||||
space then we continue
|
||||
3. If there are elements in zone (b) we compare them as unsigned ints to a
|
||||
int mask (SPACE_INT) consisting of all spaces
|
||||
4. Finally we compare the remaining part (a) of the string char by char.
|
||||
This covers for the last non-space unsigned int from 3. (if any)
|
||||
|
||||
This algorithm works well for relatively larger strings, but it will slow
|
||||
the things down for smaller strings (because of the additional calculations
|
||||
and checks compared to the naive method). Thus the barrier of length 20
|
||||
is added.
|
||||
|
||||
@param ptr pointer to the input string
|
||||
@param len the length of the string
|
||||
@return the last non-space character
|
||||
*/
|
||||
#if defined(__sparc) || defined(__sparcv9)
|
||||
static inline const uchar *skip_trailing_space(const uchar *ptr,size_t len)
|
||||
{
|
||||
/* SPACE_INT is a word that contains only spaces */
|
||||
#if SIZEOF_INT == 4
|
||||
const unsigned SPACE_INT= 0x20202020U;
|
||||
#elif SIZEOF_INT == 8
|
||||
const unsigned SPACE_INT= 0x2020202020202020ULL;
|
||||
#else
|
||||
#error define the appropriate constant for a word full of spaces
|
||||
#endif
|
||||
|
||||
const uchar *end= ptr + len;
|
||||
|
||||
if (len > 20)
|
||||
{
|
||||
const uchar *end_words= (const uchar *)(intptr)
|
||||
(((ulonglong)(intptr)end) / SIZEOF_INT * SIZEOF_INT);
|
||||
const uchar *start_words= (const uchar *)(intptr)
|
||||
((((ulonglong)(intptr)ptr) + SIZEOF_INT - 1) / SIZEOF_INT * SIZEOF_INT);
|
||||
|
||||
assert(end_words > ptr);
|
||||
while (end > end_words && end[-1] == 0x20)
|
||||
end--;
|
||||
if (end[-1] == 0x20 && start_words < end_words)
|
||||
while (end > start_words && ((unsigned *)end)[-1] == SPACE_INT)
|
||||
end -= SIZEOF_INT;
|
||||
}
|
||||
while (end > ptr && end[-1] == 0x20)
|
||||
end--;
|
||||
return (end);
|
||||
}
|
||||
#else
|
||||
/*
|
||||
Reads 8 bytes at a time, ignoring alignment.
|
||||
We use uint8korr, which is fast (it simply reads a *ulonglong)
|
||||
on all platforms, except sparc.
|
||||
*/
|
||||
static inline const uchar *skip_trailing_space(const uchar *ptr, size_t len)
|
||||
{
|
||||
const uchar *end= ptr + len;
|
||||
while (end - ptr >= 8)
|
||||
{
|
||||
if (uint8korr(end-8) != 0x2020202020202020ULL)
|
||||
break;
|
||||
end-= 8;
|
||||
}
|
||||
while (end > ptr && end[-1] == 0x20)
|
||||
end--;
|
||||
return (end);
|
||||
}
|
||||
#endif
|
||||
|
||||
static inline void lex_string_set(LEX_STRING *lex_str, const char *c_str)
|
||||
{
|
||||
lex_str->str= (char *) c_str;
|
||||
lex_str->length= strlen(c_str);
|
||||
}
|
||||
|
||||
static inline void lex_cstring_set(LEX_CSTRING *lex_str, const char *c_str)
|
||||
{
|
||||
lex_str->str= c_str;
|
||||
lex_str->length= strlen(c_str);
|
||||
}
|
||||
|
||||
#endif
|
|
@ -0,0 +1,90 @@
|
|||
/* Copyright (c) 2000, 2022, Oracle and/or its affiliates.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License, version 2.0,
|
||||
as published by the Free Software Foundation.
|
||||
|
||||
This program is also distributed with certain software (including
|
||||
but not limited to OpenSSL) that is licensed under separate terms,
|
||||
as designated in a particular file or component or in included license
|
||||
documentation. The authors of MySQL hereby grant you an additional
|
||||
permission to link the program and your derivative works with the
|
||||
separately licensed software that they have included with MySQL.
|
||||
|
||||
Without limiting anything contained in the foregoing, this file,
|
||||
which is part of C Driver for MySQL (Connector/C), is also subject to the
|
||||
Universal FOSS Exception, version 1.0, a copy of which can be found at
|
||||
http://oss.oracle.com/licenses/universal-foss-exception.
|
||||
|
||||
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, version 2.0, 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 St, Fifth Floor, Boston, MA 02110-1301 USA */
|
||||
|
||||
/*
|
||||
Data structures for mysys/my_alloc.c (root memory allocator)
|
||||
*/
|
||||
|
||||
#ifndef _my_alloc_h
|
||||
#define _my_alloc_h
|
||||
|
||||
#define ALLOC_MAX_BLOCK_TO_DROP 4096
|
||||
#define ALLOC_MAX_BLOCK_USAGE_BEFORE_DROP 10
|
||||
|
||||
/* PSI_memory_key */
|
||||
#include "mysql/psi/psi_memory.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct st_used_mem
|
||||
{ /* struct for once_alloc (block) */
|
||||
struct st_used_mem *next; /* Next block in use */
|
||||
unsigned int left; /* memory left in block */
|
||||
unsigned int size; /* size of block */
|
||||
} USED_MEM;
|
||||
|
||||
|
||||
typedef struct st_mem_root
|
||||
{
|
||||
USED_MEM *free; /* blocks with free memory in it */
|
||||
USED_MEM *used; /* blocks almost without free memory */
|
||||
USED_MEM *pre_alloc; /* preallocated block */
|
||||
/* if block have less memory it will be put in 'used' list */
|
||||
size_t min_malloc;
|
||||
size_t block_size; /* initial block size */
|
||||
unsigned int block_num; /* allocated blocks counter */
|
||||
/*
|
||||
first free block in queue test counter (if it exceed
|
||||
MAX_BLOCK_USAGE_BEFORE_DROP block will be dropped in 'used' list)
|
||||
*/
|
||||
unsigned int first_block_usage;
|
||||
|
||||
/*
|
||||
Maximum amount of memory this mem_root can hold. A value of 0
|
||||
implies there is no limit.
|
||||
*/
|
||||
size_t max_capacity;
|
||||
|
||||
/* Allocated size for this mem_root */
|
||||
|
||||
size_t allocated_size;
|
||||
|
||||
/* Enable this for error reporting if capacity is exceeded */
|
||||
my_bool error_for_capacity_exceeded;
|
||||
|
||||
void (*error_handler)(void);
|
||||
|
||||
PSI_memory_key m_psi_key;
|
||||
} MEM_ROOT;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -0,0 +1,225 @@
|
|||
#ifndef MY_BYTEORDER_INCLUDED
|
||||
#define MY_BYTEORDER_INCLUDED
|
||||
|
||||
/* Copyright (c) 2001, 2022, Oracle and/or its affiliates.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License, version 2.0,
|
||||
as published by the Free Software Foundation.
|
||||
|
||||
This program is also distributed with certain software (including
|
||||
but not limited to OpenSSL) that is licensed under separate terms,
|
||||
as designated in a particular file or component or in included license
|
||||
documentation. The authors of MySQL hereby grant you an additional
|
||||
permission to link the program and your derivative works with the
|
||||
separately licensed software that they have included with MySQL.
|
||||
|
||||
Without limiting anything contained in the foregoing, this file,
|
||||
which is part of C Driver for MySQL (Connector/C), is also subject to the
|
||||
Universal FOSS Exception, version 1.0, a copy of which can be found at
|
||||
http://oss.oracle.com/licenses/universal-foss-exception.
|
||||
|
||||
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, version 2.0, 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 St, Fifth Floor, Boston, MA 02110-1301 USA */
|
||||
|
||||
|
||||
/*
|
||||
Functions for reading and storing in machine independent
|
||||
format (low byte first). There are 'korr' (assume 'corrector') variants
|
||||
for integer types, but 'get' (assume 'getter') for floating point types.
|
||||
*/
|
||||
#if defined(__i386__) || defined(_WIN32) || defined(__x86_64__)
|
||||
#include "byte_order_generic_x86.h"
|
||||
#else
|
||||
#include "byte_order_generic.h"
|
||||
#endif
|
||||
|
||||
static inline int32 sint3korr(const uchar *A)
|
||||
{
|
||||
return
|
||||
((int32) (((A[2]) & 128) ?
|
||||
(((uint32) 255L << 24) |
|
||||
(((uint32) A[2]) << 16) |
|
||||
(((uint32) A[1]) << 8) |
|
||||
((uint32) A[0])) :
|
||||
(((uint32) A[2]) << 16) |
|
||||
(((uint32) A[1]) << 8) |
|
||||
((uint32) A[0])))
|
||||
;
|
||||
}
|
||||
|
||||
static inline uint32 uint3korr(const uchar *A)
|
||||
{
|
||||
return
|
||||
(uint32) (((uint32) (A[0])) +
|
||||
(((uint32) (A[1])) << 8) +
|
||||
(((uint32) (A[2])) << 16))
|
||||
;
|
||||
}
|
||||
|
||||
static inline ulonglong uint5korr(const uchar *A)
|
||||
{
|
||||
return
|
||||
((ulonglong)(((uint32) (A[0])) +
|
||||
(((uint32) (A[1])) << 8) +
|
||||
(((uint32) (A[2])) << 16) +
|
||||
(((uint32) (A[3])) << 24)) +
|
||||
(((ulonglong) (A[4])) << 32))
|
||||
;
|
||||
}
|
||||
|
||||
static inline ulonglong uint6korr(const uchar *A)
|
||||
{
|
||||
return
|
||||
((ulonglong)(((uint32) (A[0])) +
|
||||
(((uint32) (A[1])) << 8) +
|
||||
(((uint32) (A[2])) << 16) +
|
||||
(((uint32) (A[3])) << 24)) +
|
||||
(((ulonglong) (A[4])) << 32) +
|
||||
(((ulonglong) (A[5])) << 40))
|
||||
;
|
||||
}
|
||||
|
||||
static inline void int3store(uchar *T, uint A)
|
||||
{
|
||||
*(T)= (uchar) (A);
|
||||
*(T+1)= (uchar) (A >> 8);
|
||||
*(T+2)= (uchar) (A >> 16);
|
||||
}
|
||||
|
||||
static inline void int5store(uchar *T, ulonglong A)
|
||||
{
|
||||
*(T)= (uchar) (A);
|
||||
*(T+1)= (uchar) (A >> 8);
|
||||
*(T+2)= (uchar) (A >> 16);
|
||||
*(T+3)= (uchar) (A >> 24);
|
||||
*(T+4)= (uchar) (A >> 32);
|
||||
}
|
||||
|
||||
static inline void int6store(uchar *T, ulonglong A)
|
||||
{
|
||||
*(T)= (uchar) (A);
|
||||
*(T+1)= (uchar) (A >> 8);
|
||||
*(T+2)= (uchar) (A >> 16);
|
||||
*(T+3)= (uchar) (A >> 24);
|
||||
*(T+4)= (uchar) (A >> 32);
|
||||
*(T+5)= (uchar) (A >> 40);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
static inline int16 sint2korr(const char *pT)
|
||||
{
|
||||
return sint2korr(static_cast<const uchar*>(static_cast<const void*>(pT)));
|
||||
}
|
||||
|
||||
static inline uint16 uint2korr(const char *pT)
|
||||
{
|
||||
return uint2korr(static_cast<const uchar*>(static_cast<const void*>(pT)));
|
||||
}
|
||||
|
||||
static inline uint32 uint3korr(const char *pT)
|
||||
{
|
||||
return uint3korr(static_cast<const uchar*>(static_cast<const void*>(pT)));
|
||||
}
|
||||
|
||||
static inline int32 sint3korr(const char *pT)
|
||||
{
|
||||
return sint3korr(static_cast<const uchar*>(static_cast<const void*>(pT)));
|
||||
}
|
||||
|
||||
static inline uint32 uint4korr(const char *pT)
|
||||
{
|
||||
return uint4korr(static_cast<const uchar*>(static_cast<const void*>(pT)));
|
||||
}
|
||||
|
||||
static inline int32 sint4korr(const char *pT)
|
||||
{
|
||||
return sint4korr(static_cast<const uchar*>(static_cast<const void*>(pT)));
|
||||
}
|
||||
|
||||
static inline ulonglong uint6korr(const char *pT)
|
||||
{
|
||||
return uint6korr(static_cast<const uchar*>(static_cast<const void*>(pT)));
|
||||
}
|
||||
|
||||
static inline ulonglong uint8korr(const char *pT)
|
||||
{
|
||||
return uint8korr(static_cast<const uchar*>(static_cast<const void*>(pT)));
|
||||
}
|
||||
|
||||
static inline longlong sint8korr(const char *pT)
|
||||
{
|
||||
return sint8korr(static_cast<const uchar*>(static_cast<const void*>(pT)));
|
||||
}
|
||||
|
||||
|
||||
static inline void int2store(char *pT, uint16 A)
|
||||
{
|
||||
int2store(static_cast<uchar*>(static_cast<void*>(pT)), A);
|
||||
}
|
||||
|
||||
static inline void int3store(char *pT, uint A)
|
||||
{
|
||||
int3store(static_cast<uchar*>(static_cast<void*>(pT)), A);
|
||||
}
|
||||
|
||||
static inline void int4store(char *pT, uint32 A)
|
||||
{
|
||||
int4store(static_cast<uchar*>(static_cast<void*>(pT)), A);
|
||||
}
|
||||
|
||||
static inline void int5store(char *pT, ulonglong A)
|
||||
{
|
||||
int5store(static_cast<uchar*>(static_cast<void*>(pT)), A);
|
||||
}
|
||||
|
||||
static inline void int6store(char *pT, ulonglong A)
|
||||
{
|
||||
int6store(static_cast<uchar*>(static_cast<void*>(pT)), A);
|
||||
}
|
||||
|
||||
static inline void int8store(char *pT, ulonglong A)
|
||||
{
|
||||
int8store(static_cast<uchar*>(static_cast<void*>(pT)), A);
|
||||
}
|
||||
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/*
|
||||
Functions for reading and storing in machine format from/to
|
||||
short/long to/from some place in memory V should be a variable
|
||||
and M a pointer to byte.
|
||||
*/
|
||||
#ifdef WORDS_BIGENDIAN
|
||||
#include "big_endian.h"
|
||||
#else
|
||||
#include "little_endian.h"
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
static inline void float4store(char *V, float M)
|
||||
{
|
||||
float4store(static_cast<uchar*>(static_cast<void*>(V)), M);
|
||||
}
|
||||
|
||||
static inline void float8get(double *V, const char *M)
|
||||
{
|
||||
float8get(V, static_cast<const uchar*>(static_cast<const void*>(M)));
|
||||
}
|
||||
|
||||
static inline void float8store(char *V, double M)
|
||||
{
|
||||
float8store(static_cast<uchar*>(static_cast<void*>(V)), M);
|
||||
}
|
||||
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* MY_BYTEORDER_INCLUDED */
|
|
@ -0,0 +1,76 @@
|
|||
/* Copyright (c) 2015, 2022, Oracle and/or its affiliates.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License, version 2.0,
|
||||
as published by the Free Software Foundation.
|
||||
|
||||
This program is also distributed with certain software (including
|
||||
but not limited to OpenSSL) that is licensed under separate terms,
|
||||
as designated in a particular file or component or in included license
|
||||
documentation. The authors of MySQL hereby grant you an additional
|
||||
permission to link the program and your derivative works with the
|
||||
separately licensed software that they have included with MySQL.
|
||||
|
||||
Without limiting anything contained in the foregoing, this file,
|
||||
which is part of C Driver for MySQL (Connector/C), is also subject to the
|
||||
Universal FOSS Exception, version 1.0, a copy of which can be found at
|
||||
http://oss.oracle.com/licenses/universal-foss-exception.
|
||||
|
||||
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, version 2.0, 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 St, Fifth Floor, Boston, MA 02110-1301 USA */
|
||||
|
||||
#ifndef _mysql_command_h
|
||||
#define _mysql_command_h
|
||||
|
||||
/**
|
||||
@enum enum_server_command
|
||||
@brief You should add new commands to the end of this list, otherwise old
|
||||
servers won't be able to handle them as 'unsupported'.
|
||||
*/
|
||||
enum enum_server_command
|
||||
{
|
||||
COM_SLEEP,
|
||||
COM_QUIT,
|
||||
COM_INIT_DB,
|
||||
COM_QUERY,
|
||||
COM_FIELD_LIST,
|
||||
COM_CREATE_DB,
|
||||
COM_DROP_DB,
|
||||
COM_REFRESH,
|
||||
COM_SHUTDOWN,
|
||||
COM_STATISTICS,
|
||||
COM_PROCESS_INFO,
|
||||
COM_CONNECT,
|
||||
COM_PROCESS_KILL,
|
||||
COM_DEBUG,
|
||||
COM_PING,
|
||||
COM_TIME,
|
||||
COM_DELAYED_INSERT,
|
||||
COM_CHANGE_USER,
|
||||
COM_BINLOG_DUMP,
|
||||
COM_TABLE_DUMP,
|
||||
COM_CONNECT_OUT,
|
||||
COM_REGISTER_SLAVE,
|
||||
COM_STMT_PREPARE,
|
||||
COM_STMT_EXECUTE,
|
||||
COM_STMT_SEND_LONG_DATA,
|
||||
COM_STMT_CLOSE,
|
||||
COM_STMT_RESET,
|
||||
COM_SET_OPTION,
|
||||
COM_STMT_FETCH,
|
||||
COM_DAEMON,
|
||||
COM_BINLOG_DUMP_GTID,
|
||||
COM_RESET_CONNECTION,
|
||||
/* don't forget to update const char *command_name[] in sql_parse.cc */
|
||||
|
||||
/* Must be last */
|
||||
COM_END
|
||||
};
|
||||
|
||||
#endif /* _mysql_command_h */
|
|
@ -0,0 +1,190 @@
|
|||
#ifndef MY_COMPILER_INCLUDED
|
||||
#define MY_COMPILER_INCLUDED
|
||||
|
||||
/* Copyright (c) 2010, 2022, Oracle and/or its affiliates.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License, version 2.0,
|
||||
as published by the Free Software Foundation.
|
||||
|
||||
This program is also distributed with certain software (including
|
||||
but not limited to OpenSSL) that is licensed under separate terms,
|
||||
as designated in a particular file or component or in included license
|
||||
documentation. The authors of MySQL hereby grant you an additional
|
||||
permission to link the program and your derivative works with the
|
||||
separately licensed software that they have included with MySQL.
|
||||
|
||||
Without limiting anything contained in the foregoing, this file,
|
||||
which is part of C Driver for MySQL (Connector/C), is also subject to the
|
||||
Universal FOSS Exception, version 1.0, a copy of which can be found at
|
||||
http://oss.oracle.com/licenses/universal-foss-exception.
|
||||
|
||||
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, version 2.0, 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 St, Fifth Floor, Boston, MA 02110-1301 USA */
|
||||
|
||||
/**
|
||||
Header for compiler-dependent features.
|
||||
|
||||
Intended to contain a set of reusable wrappers for preprocessor
|
||||
macros, attributes, pragmas, and any other features that are
|
||||
specific to a target compiler.
|
||||
*/
|
||||
|
||||
#include <stddef.h> /* size_t */
|
||||
|
||||
#if defined __GNUC__
|
||||
/*
|
||||
Convenience macro to test the minimum required GCC version.
|
||||
These should be used with care as Clang also sets __GNUC__ and
|
||||
__GNUC_MINOR__ (currently to 4.2). Prefer using feature specific
|
||||
CMake checks in configure.cmake instead.
|
||||
*/
|
||||
# define MY_GNUC_PREREQ(maj, min) \
|
||||
((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
|
||||
# define GCC_VERSION (__GNUC__ * 1000 + __GNUC_MINOR__)
|
||||
#else
|
||||
# define MY_GNUC_PREREQ(maj, min) (0)
|
||||
#endif
|
||||
|
||||
/*
|
||||
The macros below are borrowed from include/linux/compiler.h in the
|
||||
Linux kernel. Use them to indicate the likelyhood of the truthfulness
|
||||
of a condition. This serves two purposes - newer versions of gcc will be
|
||||
able to optimize for branch predication, which could yield siginficant
|
||||
performance gains in frequently executed sections of the code, and the
|
||||
other reason to use them is for documentation
|
||||
*/
|
||||
#ifdef HAVE_BUILTIN_EXPECT
|
||||
|
||||
// likely/unlikely are likely to clash with other symbols, do not #define
|
||||
#if defined(__cplusplus)
|
||||
inline bool likely(bool expr)
|
||||
{
|
||||
return __builtin_expect(expr, true);
|
||||
}
|
||||
inline bool unlikely(bool expr)
|
||||
{
|
||||
return __builtin_expect(expr, false);
|
||||
}
|
||||
#else
|
||||
# define likely(x) __builtin_expect((x),1)
|
||||
# define unlikely(x) __builtin_expect((x),0)
|
||||
#endif
|
||||
|
||||
#else /* HAVE_BUILTIN_EXPECT */
|
||||
|
||||
#if defined(__cplusplus)
|
||||
inline bool likely(bool expr)
|
||||
{
|
||||
return expr;
|
||||
}
|
||||
inline bool unlikely(bool expr)
|
||||
{
|
||||
return expr;
|
||||
}
|
||||
#else
|
||||
# define likely(x) (x)
|
||||
# define unlikely(x) (x)
|
||||
#endif
|
||||
|
||||
#endif /* HAVE_BUILTIN_EXPECT */
|
||||
|
||||
/* Comunicate to the compiler the unreachability of the code. */
|
||||
#ifdef HAVE_BUILTIN_UNREACHABLE
|
||||
# define MY_ASSERT_UNREACHABLE() __builtin_unreachable()
|
||||
#else
|
||||
# define MY_ASSERT_UNREACHABLE() do { assert(0); } while (0)
|
||||
#endif
|
||||
|
||||
#if defined __GNUC__ || defined __SUNPRO_C || defined __SUNPRO_CC
|
||||
/* Specifies the minimum alignment of a type. */
|
||||
# define MY_ALIGNOF(type) __alignof__(type)
|
||||
/* Determine the alignment requirement of a type. */
|
||||
# define MY_ALIGNED(n) __attribute__((__aligned__((n))))
|
||||
/* Microsoft Visual C++ */
|
||||
#elif defined _MSC_VER
|
||||
# define MY_ALIGNOF(type) __alignof(type)
|
||||
# define MY_ALIGNED(n) __declspec(align(n))
|
||||
#else /* Make sure they are defined for other compilers. */
|
||||
# define MY_ALIGNOF(type)
|
||||
# define MY_ALIGNED(size)
|
||||
#endif
|
||||
|
||||
/* Visual Studio requires '__inline' for C code */
|
||||
#if !defined(__cplusplus) && defined(_MSC_VER)
|
||||
# define inline __inline
|
||||
#endif
|
||||
|
||||
/* Provide __func__ macro definition for Visual Studio. */
|
||||
#if defined(_MSC_VER)
|
||||
# define __func__ __FUNCTION__
|
||||
#endif
|
||||
|
||||
/**
|
||||
C++ Type Traits
|
||||
*/
|
||||
#ifdef __cplusplus
|
||||
|
||||
/**
|
||||
Opaque storage with a particular alignment.
|
||||
Partial specialization used due to MSVC++.
|
||||
*/
|
||||
template<size_t alignment> struct my_alignment_imp;
|
||||
template<> struct MY_ALIGNED(1) my_alignment_imp<1> {};
|
||||
template<> struct MY_ALIGNED(2) my_alignment_imp<2> {};
|
||||
template<> struct MY_ALIGNED(4) my_alignment_imp<4> {};
|
||||
template<> struct MY_ALIGNED(8) my_alignment_imp<8> {};
|
||||
template<> struct MY_ALIGNED(16) my_alignment_imp<16> {};
|
||||
|
||||
/**
|
||||
A POD type with a given size and alignment.
|
||||
|
||||
@remark If the compiler does not support a alignment attribute
|
||||
(MY_ALIGN macro), the default alignment of a double is
|
||||
used instead.
|
||||
|
||||
@tparam size The minimum size.
|
||||
@tparam alignment The desired alignment: 1, 2, 4, 8 or 16.
|
||||
*/
|
||||
template <size_t size, size_t alignment>
|
||||
struct my_aligned_storage
|
||||
{
|
||||
union
|
||||
{
|
||||
char data[size];
|
||||
my_alignment_imp<alignment> align;
|
||||
};
|
||||
};
|
||||
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/*
|
||||
Disable MY_ATTRIBUTE for Sun Studio and Visual Studio.
|
||||
Note that Sun Studio supports some __attribute__ variants,
|
||||
but not format or unused which we use quite a lot.
|
||||
*/
|
||||
#ifndef MY_ATTRIBUTE
|
||||
#if defined(__GNUC__)
|
||||
# define MY_ATTRIBUTE(A) __attribute__(A)
|
||||
#else
|
||||
# define MY_ATTRIBUTE(A)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef __has_attribute
|
||||
# define __has_attribute(x) 0
|
||||
#endif
|
||||
|
||||
#if __has_attribute(no_sanitize_undefined)
|
||||
# define SUPPRESS_UBSAN __attribute__((no_sanitize_undefined))
|
||||
#else
|
||||
# define SUPPRESS_UBSAN
|
||||
#endif
|
||||
|
||||
#endif /* MY_COMPILER_INCLUDED */
|
|
@ -0,0 +1,469 @@
|
|||
/* Copyright (c) 2009, 2022, Oracle and/or its affiliates.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License, version 2.0,
|
||||
as published by the Free Software Foundation.
|
||||
|
||||
This program is also distributed with certain software (including
|
||||
but not limited to OpenSSL) that is licensed under separate terms,
|
||||
as designated in a particular file or component or in included license
|
||||
documentation. The authors of MySQL hereby grant you an additional
|
||||
permission to link the program and your derivative works with the
|
||||
separately licensed software that they have included with MySQL.
|
||||
|
||||
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, version 2.0, 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 St, Fifth Floor, Boston, MA 02110-1301 USA */
|
||||
|
||||
#ifndef MY_CONFIG_H
|
||||
#define MY_CONFIG_H
|
||||
|
||||
/*
|
||||
* From configure.cmake, in order of appearance
|
||||
*/
|
||||
/* #undef HAVE_LLVM_LIBCPP */
|
||||
#define _LARGEFILE_SOURCE 1
|
||||
|
||||
/* Libraries */
|
||||
/* #undef HAVE_LIBM */
|
||||
/* #undef HAVE_LIBNSL */
|
||||
/* #undef HAVE_LIBCRYPT */
|
||||
/* #undef HAVE_LIBSOCKET */
|
||||
/* #undef HAVE_LIBDL */
|
||||
/* #undef HAVE_LIBRT */
|
||||
/* #undef HAVE_LIBWRAP */
|
||||
/* #undef HAVE_LIBWRAP_PROTOTYPES */
|
||||
|
||||
/* Header files */
|
||||
/* #undef HAVE_ALLOCA_H */
|
||||
/* #undef HAVE_ARPA_INET_H */
|
||||
/* #undef HAVE_CRYPT_H */
|
||||
/* #undef HAVE_DLFCN_H */
|
||||
/* #undef HAVE_EXECINFO_H */
|
||||
/* #undef HAVE_FPU_CONTROL_H */
|
||||
/* #undef HAVE_GRP_H */
|
||||
/* #undef HAVE_IEEEFP_H */
|
||||
/* #undef HAVE_LANGINFO_H */
|
||||
#define HAVE_MALLOC_H 1
|
||||
/* #undef HAVE_NETINET_IN_H */
|
||||
/* #undef HAVE_POLL_H */
|
||||
/* #undef HAVE_PWD_H */
|
||||
/* #undef HAVE_STRINGS_H */
|
||||
/* #undef HAVE_SYS_CDEFS_H */
|
||||
/* #undef HAVE_SYS_IOCTL_H */
|
||||
/* #undef HAVE_SYS_MMAN_H */
|
||||
/* #undef HAVE_SYS_RESOURCE_H */
|
||||
/* #undef HAVE_SYS_SELECT_H */
|
||||
/* #undef HAVE_SYS_SOCKET_H */
|
||||
/* #undef HAVE_TERM_H */
|
||||
/* #undef HAVE_TERMIOS_H */
|
||||
/* #undef HAVE_TERMIO_H */
|
||||
/* #undef HAVE_UNISTD_H */
|
||||
/* #undef HAVE_SYS_WAIT_H */
|
||||
/* #undef HAVE_SYS_PARAM_H */
|
||||
/* #undef HAVE_FNMATCH_H */
|
||||
/* #undef HAVE_SYS_UN_H */
|
||||
/* #undef HAVE_SASL_SASL_H */
|
||||
|
||||
/* Libevent */
|
||||
/* #undef HAVE_DEVPOLL */
|
||||
/* #undef HAVE_SYS_DEVPOLL_H */
|
||||
/* #undef HAVE_SYS_EPOLL_H */
|
||||
/* #undef HAVE_TAILQFOREACH */
|
||||
|
||||
/* Functions */
|
||||
#define HAVE_ALIGNED_MALLOC 1
|
||||
/* #undef HAVE_BACKTRACE */
|
||||
/* #undef HAVE_PRINTSTACK */
|
||||
/* #undef HAVE_INDEX */
|
||||
/* #undef HAVE_CLOCK_GETTIME */
|
||||
/* #undef HAVE_CUSERID */
|
||||
/* #undef HAVE_DIRECTIO */
|
||||
/* #undef HAVE_FTRUNCATE */
|
||||
#define HAVE_COMPRESS 1
|
||||
/* #undef HAVE_CRYPT */
|
||||
/* #undef HAVE_DLOPEN */
|
||||
/* #undef HAVE_FCHMOD */
|
||||
/* #undef HAVE_FCNTL */
|
||||
/* #undef HAVE_FDATASYNC */
|
||||
/* #undef HAVE_DECL_FDATASYNC */
|
||||
/* #undef HAVE_FEDISABLEEXCEPT */
|
||||
/* #undef HAVE_FSEEKO */
|
||||
/* #undef HAVE_FSYNC */
|
||||
/* #undef HAVE_GETHOSTBYADDR_R */
|
||||
/* #undef HAVE_GETHRTIME */
|
||||
#define HAVE_GETNAMEINFO 1
|
||||
/* #undef HAVE_GETPASS */
|
||||
/* #undef HAVE_GETPASSPHRASE */
|
||||
/* #undef HAVE_GETPWNAM */
|
||||
/* #undef HAVE_GETPWUID */
|
||||
/* #undef HAVE_GETRLIMIT */
|
||||
/* #undef HAVE_GETRUSAGE */
|
||||
/* #undef HAVE_INITGROUPS */
|
||||
/* #undef HAVE_ISSETUGID */
|
||||
/* #undef HAVE_GETUID */
|
||||
/* #undef HAVE_GETEUID */
|
||||
/* #undef HAVE_GETGID */
|
||||
/* #undef HAVE_GETEGID */
|
||||
/* #undef HAVE_LSTAT */
|
||||
/* #undef HAVE_MADVISE */
|
||||
/* #undef HAVE_MALLOC_INFO */
|
||||
/* #undef HAVE_MEMRCHR */
|
||||
/* #undef HAVE_MLOCK */
|
||||
/* #undef HAVE_MLOCKALL */
|
||||
/* #undef HAVE_MMAP64 */
|
||||
/* #undef HAVE_POLL */
|
||||
/* #undef HAVE_POSIX_FALLOCATE */
|
||||
/* #undef HAVE_POSIX_MEMALIGN */
|
||||
/* #undef HAVE_PREAD */
|
||||
/* #undef HAVE_PTHREAD_CONDATTR_SETCLOCK */
|
||||
/* #undef HAVE_PTHREAD_SIGMASK */
|
||||
/* #undef HAVE_READLINK */
|
||||
/* #undef HAVE_REALPATH */
|
||||
/* #undef HAVE_SETFD */
|
||||
/* #undef HAVE_SIGACTION */
|
||||
/* #undef HAVE_SLEEP */
|
||||
/* #undef HAVE_STPCPY */
|
||||
/* #undef HAVE_STPNCPY */
|
||||
/* #undef HAVE_STRLCPY */
|
||||
#define HAVE_STRNLEN 1
|
||||
/* #undef HAVE_STRLCAT */
|
||||
/* #undef HAVE_STRSIGNAL */
|
||||
/* #undef HAVE_FGETLN */
|
||||
/* #undef HAVE_STRSEP */
|
||||
#define HAVE_TELL 1
|
||||
/* #undef HAVE_VASPRINTF */
|
||||
/* #undef HAVE_MEMALIGN */
|
||||
/* #undef HAVE_NL_LANGINFO */
|
||||
/* #undef HAVE_HTONLL */
|
||||
/* #undef DNS_USE_CPU_CLOCK_FOR_ID */
|
||||
/* #undef HAVE_EPOLL */
|
||||
/* #undef HAVE_EVENT_PORTS */
|
||||
#define HAVE_INET_NTOP 1
|
||||
/* #undef HAVE_WORKING_KQUEUE */
|
||||
/* #undef HAVE_TIMERADD */
|
||||
/* #undef HAVE_TIMERCLEAR */
|
||||
/* #undef HAVE_TIMERCMP */
|
||||
/* #undef HAVE_TIMERISSET */
|
||||
|
||||
/* WL2373 */
|
||||
/* #undef HAVE_SYS_TIME_H */
|
||||
/* #undef HAVE_SYS_TIMES_H */
|
||||
/* #undef HAVE_TIMES */
|
||||
/* #undef HAVE_GETTIMEOFDAY */
|
||||
|
||||
/* Symbols */
|
||||
/* #undef HAVE_LRAND48 */
|
||||
/* #undef GWINSZ_IN_SYS_IOCTL */
|
||||
/* #undef FIONREAD_IN_SYS_IOCTL */
|
||||
/* #undef FIONREAD_IN_SYS_FILIO */
|
||||
/* #undef HAVE_SIGEV_THREAD_ID */
|
||||
/* #undef HAVE_SIGEV_PORT */
|
||||
#define HAVE_LOG2 1
|
||||
|
||||
#define HAVE_ISINF 1
|
||||
|
||||
/* #undef HAVE_KQUEUE_TIMERS */
|
||||
/* #undef HAVE_POSIX_TIMERS */
|
||||
|
||||
/* Endianess */
|
||||
/* #undef WORDS_BIGENDIAN */
|
||||
|
||||
/* Type sizes */
|
||||
#define SIZEOF_VOIDP 8
|
||||
#define SIZEOF_CHARP 8
|
||||
#define SIZEOF_LONG 4
|
||||
#define SIZEOF_SHORT 2
|
||||
#define SIZEOF_INT 4
|
||||
#define SIZEOF_LONG_LONG 8
|
||||
#define SIZEOF_OFF_T 4
|
||||
#define SIZEOF_TIME_T 8
|
||||
/* #undef HAVE_UINT */
|
||||
/* #undef HAVE_ULONG */
|
||||
/* #undef HAVE_U_INT32_T */
|
||||
#define HAVE_STRUCT_TIMESPEC
|
||||
|
||||
/* Support for tagging symbols with __attribute__((visibility("hidden"))) */
|
||||
/* #undef HAVE_VISIBILITY_HIDDEN */
|
||||
|
||||
/* Code tests*/
|
||||
#define STACK_DIRECTION -1
|
||||
/* #undef TIME_WITH_SYS_TIME */
|
||||
#define NO_FCNTL_NONBLOCK 1
|
||||
/* #undef HAVE_PAUSE_INSTRUCTION */
|
||||
/* #undef HAVE_FAKE_PAUSE_INSTRUCTION */
|
||||
/* #undef HAVE_HMT_PRIORITY_INSTRUCTION */
|
||||
/* #undef HAVE_ABI_CXA_DEMANGLE */
|
||||
/* #undef HAVE_BUILTIN_UNREACHABLE */
|
||||
/* #undef HAVE_BUILTIN_EXPECT */
|
||||
/* #undef HAVE_BUILTIN_STPCPY */
|
||||
/* #undef HAVE_GCC_ATOMIC_BUILTINS */
|
||||
/* #undef HAVE_GCC_SYNC_BUILTINS */
|
||||
/* #undef HAVE_VALGRIND */
|
||||
/* #undef HAVE_PTHREAD_THREADID_NP */
|
||||
|
||||
/* IPV6 */
|
||||
/* #undef HAVE_NETINET_IN6_H */
|
||||
#define HAVE_STRUCT_SOCKADDR_IN6 1
|
||||
#define HAVE_STRUCT_IN6_ADDR 1
|
||||
#define HAVE_IPV6 1
|
||||
|
||||
/* #undef ss_family */
|
||||
/* #undef HAVE_SOCKADDR_IN_SIN_LEN */
|
||||
/* #undef HAVE_SOCKADDR_IN6_SIN6_LEN */
|
||||
|
||||
/*
|
||||
* Platform specific CMake files
|
||||
*/
|
||||
#define MACHINE_TYPE "x86_64"
|
||||
/* #undef HAVE_LINUX_LARGE_PAGES */
|
||||
/* #undef HAVE_SOLARIS_LARGE_PAGES */
|
||||
/* #undef HAVE_SOLARIS_ATOMIC */
|
||||
/* #undef HAVE_SOLARIS_STYLE_GETHOST */
|
||||
#define SYSTEM_TYPE "Win64"
|
||||
/* Windows stuff, mostly functions, that have Posix analogs but named differently */
|
||||
/* #undef IPPROTO_IPV6 */
|
||||
/* #undef IPV6_V6ONLY */
|
||||
/* This should mean case insensitive file system */
|
||||
#define FN_NO_CASE_SENSE 1
|
||||
/* #undef APPLE_ARM */
|
||||
|
||||
/*
|
||||
* From main CMakeLists.txt
|
||||
*/
|
||||
#define MAX_INDEXES 64U
|
||||
/* #undef WITH_INNODB_MEMCACHED */
|
||||
/* #undef ENABLE_MEMCACHED_SASL */
|
||||
/* #undef ENABLE_MEMCACHED_SASL_PWDB */
|
||||
#define ENABLED_PROFILING 1
|
||||
/* #undef HAVE_ASAN */
|
||||
#define ENABLED_LOCAL_INFILE 1
|
||||
#define OPTIMIZER_TRACE 1
|
||||
#define DEFAULT_MYSQL_HOME "C:/Program Files/MySQL/MySQL Server 5.7"
|
||||
#define SHAREDIR "share"
|
||||
#define DEFAULT_BASEDIR "C:/Program Files/MySQL/MySQL Server 5.7"
|
||||
#define MYSQL_DATADIR "C:/Program Files/MySQL/MySQL Server 5.7/data"
|
||||
#define MYSQL_KEYRINGDIR "C:/Program Files/MySQL/MySQL Server 5.7/keyring"
|
||||
#define DEFAULT_CHARSET_HOME "C:/Program Files/MySQL/MySQL Server 5.7"
|
||||
#define PLUGINDIR "C:/Program Files/MySQL/MySQL Server 5.7/lib/plugin"
|
||||
/* #undef DEFAULT_SYSCONFDIR */
|
||||
#define DEFAULT_TMPDIR ""
|
||||
#define INSTALL_SBINDIR "/bin"
|
||||
#define INSTALL_BINDIR "/bin"
|
||||
#define INSTALL_MYSQLSHAREDIR "/share"
|
||||
#define INSTALL_SHAREDIR "/share"
|
||||
#define INSTALL_PLUGINDIR "/lib/plugin"
|
||||
#define INSTALL_INCLUDEDIR "/include"
|
||||
#define INSTALL_SCRIPTDIR "/scripts"
|
||||
#define INSTALL_MYSQLDATADIR "/data"
|
||||
#define INSTALL_MYSQLKEYRINGDIR "/keyring"
|
||||
/* #undef INSTALL_PLUGINTESTDIR */
|
||||
#define INSTALL_INFODIR "/docs"
|
||||
#define INSTALL_MYSQLTESTDIR "/mysql-test"
|
||||
#define INSTALL_DOCREADMEDIR "/."
|
||||
#define INSTALL_DOCDIR "/docs"
|
||||
#define INSTALL_MANDIR "/man"
|
||||
#define INSTALL_SUPPORTFILESDIR "/support-files"
|
||||
#define INSTALL_LIBDIR "/lib"
|
||||
|
||||
/*
|
||||
* Readline
|
||||
*/
|
||||
/* #undef HAVE_MBSTATE_T */
|
||||
/* #undef HAVE_LANGINFO_CODESET */
|
||||
/* #undef HAVE_WCSDUP */
|
||||
/* #undef HAVE_WCHAR_T */
|
||||
/* #undef HAVE_WINT_T */
|
||||
/* #undef HAVE_CURSES_H */
|
||||
/* #undef HAVE_NCURSES_H */
|
||||
/* #undef USE_LIBEDIT_INTERFACE */
|
||||
/* #undef HAVE_HIST_ENTRY */
|
||||
/* #undef USE_NEW_EDITLINE_INTERFACE */
|
||||
/* #undef EDITLINE_HAVE_COMPLETION_CHAR */
|
||||
/* #undef EDITLINE_HAVE_COMPLETION_INT */
|
||||
|
||||
/*
|
||||
* Libedit
|
||||
*/
|
||||
/* #undef HAVE_GETLINE */
|
||||
/* #undef HAVE___SECURE_GETENV */
|
||||
/* #undef HAVE_SECURE_GETENV */
|
||||
/* #undef HAVE_VIS */
|
||||
/* #undef HAVE_UNVIS */
|
||||
/* #undef HAVE_GETPW_R_DRAFT */
|
||||
/* #undef HAVE_GETPW_R_POSIX */
|
||||
|
||||
/*
|
||||
* DTrace
|
||||
*/
|
||||
/* #undef HAVE_DTRACE */
|
||||
|
||||
/*
|
||||
* Character sets
|
||||
*/
|
||||
#define MYSQL_DEFAULT_CHARSET_NAME "latin1"
|
||||
#define MYSQL_DEFAULT_COLLATION_NAME "latin1_swedish_ci"
|
||||
#define HAVE_CHARSET_armscii8 1
|
||||
#define HAVE_CHARSET_ascii 1
|
||||
#define HAVE_CHARSET_big5 1
|
||||
#define HAVE_CHARSET_cp1250 1
|
||||
#define HAVE_CHARSET_cp1251 1
|
||||
#define HAVE_CHARSET_cp1256 1
|
||||
#define HAVE_CHARSET_cp1257 1
|
||||
#define HAVE_CHARSET_cp850 1
|
||||
#define HAVE_CHARSET_cp852 1
|
||||
#define HAVE_CHARSET_cp866 1
|
||||
#define HAVE_CHARSET_cp932 1
|
||||
#define HAVE_CHARSET_dec8 1
|
||||
#define HAVE_CHARSET_eucjpms 1
|
||||
#define HAVE_CHARSET_euckr 1
|
||||
#define HAVE_CHARSET_gb2312 1
|
||||
#define HAVE_CHARSET_gbk 1
|
||||
#define HAVE_CHARSET_gb18030 1
|
||||
#define HAVE_CHARSET_geostd8 1
|
||||
#define HAVE_CHARSET_greek 1
|
||||
#define HAVE_CHARSET_hebrew 1
|
||||
#define HAVE_CHARSET_hp8 1
|
||||
#define HAVE_CHARSET_keybcs2 1
|
||||
#define HAVE_CHARSET_koi8r 1
|
||||
#define HAVE_CHARSET_koi8u 1
|
||||
#define HAVE_CHARSET_latin1 1
|
||||
#define HAVE_CHARSET_latin2 1
|
||||
#define HAVE_CHARSET_latin5 1
|
||||
#define HAVE_CHARSET_latin7 1
|
||||
#define HAVE_CHARSET_macce 1
|
||||
#define HAVE_CHARSET_macroman 1
|
||||
#define HAVE_CHARSET_sjis 1
|
||||
#define HAVE_CHARSET_swe7 1
|
||||
#define HAVE_CHARSET_tis620 1
|
||||
#define HAVE_CHARSET_ucs2 1
|
||||
#define HAVE_CHARSET_ujis 1
|
||||
#define HAVE_CHARSET_utf8mb4 1
|
||||
/* #undef HAVE_CHARSET_utf8mb3 */
|
||||
#define HAVE_CHARSET_utf8 1
|
||||
#define HAVE_CHARSET_utf16 1
|
||||
#define HAVE_CHARSET_utf32 1
|
||||
#define HAVE_UCA_COLLATIONS 1
|
||||
|
||||
/*
|
||||
* Feature set
|
||||
*/
|
||||
#define WITH_PARTITION_STORAGE_ENGINE 1
|
||||
|
||||
/*
|
||||
* Performance schema
|
||||
*/
|
||||
#define WITH_PERFSCHEMA_STORAGE_ENGINE 1
|
||||
/* #undef DISABLE_PSI_THREAD */
|
||||
/* #undef DISABLE_PSI_MUTEX */
|
||||
/* #undef DISABLE_PSI_RWLOCK */
|
||||
/* #undef DISABLE_PSI_COND */
|
||||
/* #undef DISABLE_PSI_FILE */
|
||||
/* #undef DISABLE_PSI_TABLE */
|
||||
/* #undef DISABLE_PSI_SOCKET */
|
||||
/* #undef DISABLE_PSI_STAGE */
|
||||
/* #undef DISABLE_PSI_STATEMENT */
|
||||
/* #undef DISABLE_PSI_SP */
|
||||
/* #undef DISABLE_PSI_PS */
|
||||
/* #undef DISABLE_PSI_IDLE */
|
||||
/* #undef DISABLE_PSI_STATEMENT_DIGEST */
|
||||
/* #undef DISABLE_PSI_METADATA */
|
||||
/* #undef DISABLE_PSI_MEMORY */
|
||||
/* #undef DISABLE_PSI_TRANSACTION */
|
||||
|
||||
/*
|
||||
* syscall
|
||||
*/
|
||||
/* #undef HAVE_SYS_THREAD_SELFID */
|
||||
/* #undef HAVE_SYS_GETTID */
|
||||
/* #undef HAVE_PTHREAD_GETTHREADID_NP */
|
||||
/* #undef HAVE_PTHREAD_SETNAME_NP */
|
||||
/* #undef HAVE_INTEGER_PTHREAD_SELF */
|
||||
|
||||
/* Platform-specific C++ compiler behaviors we rely upon */
|
||||
|
||||
/*
|
||||
This macro defines whether the compiler in use needs a 'typename' keyword
|
||||
to access the types defined inside a class template, such types are called
|
||||
dependent types. Some compilers require it, some others forbid it, and some
|
||||
others may work with or without it. For example, GCC requires the 'typename'
|
||||
keyword whenever needing to access a type inside a template, but msvc
|
||||
forbids it.
|
||||
*/
|
||||
#define HAVE_IMPLICIT_DEPENDENT_NAME_TYPING 1
|
||||
|
||||
|
||||
/*
|
||||
* MySQL version
|
||||
*/
|
||||
#define DOT_FRM_VERSION 6
|
||||
#define MYSQL_VERSION_MAJOR 5
|
||||
#define MYSQL_VERSION_MINOR 7
|
||||
#define MYSQL_VERSION_PATCH 39
|
||||
#define MYSQL_VERSION_EXTRA ""
|
||||
#define PACKAGE "mysql"
|
||||
#define PACKAGE_BUGREPORT ""
|
||||
#define PACKAGE_NAME "MySQL Server"
|
||||
#define PACKAGE_STRING "MySQL Server 5.7.39"
|
||||
#define PACKAGE_TARNAME "mysql"
|
||||
#define PACKAGE_VERSION "5.7.39"
|
||||
#define VERSION "5.7.39"
|
||||
#define PROTOCOL_VERSION 10
|
||||
|
||||
/*
|
||||
* CPU info
|
||||
*/
|
||||
#define CPU_LEVEL1_DCACHE_LINESIZE 64
|
||||
|
||||
/*
|
||||
* NDB
|
||||
*/
|
||||
/* #undef WITH_NDBCLUSTER_STORAGE_ENGINE */
|
||||
/* #undef HAVE_PTHREAD_SETSCHEDPARAM */
|
||||
|
||||
/*
|
||||
* Other
|
||||
*/
|
||||
/* #undef EXTRA_DEBUG */
|
||||
/* #undef HAVE_CHOWN */
|
||||
|
||||
/*
|
||||
* Hardcoded values needed by libevent/NDB/memcached
|
||||
*/
|
||||
#define HAVE_FCNTL_H 1
|
||||
#define HAVE_GETADDRINFO 1
|
||||
#define HAVE_INTTYPES_H 1
|
||||
/* libevent's select.c is not Windows compatible */
|
||||
#ifndef _WIN32
|
||||
#define HAVE_SELECT 1
|
||||
#endif
|
||||
#define HAVE_SIGNAL_H 1
|
||||
#define HAVE_STDARG_H 1
|
||||
#define HAVE_STDINT_H 1
|
||||
#define HAVE_STDLIB_H 1
|
||||
#define HAVE_STRDUP 1
|
||||
#define HAVE_STRTOK_R 1
|
||||
#define HAVE_STRTOLL 1
|
||||
#define HAVE_SYS_STAT_H 1
|
||||
#define HAVE_SYS_TYPES_H 1
|
||||
#define SIZEOF_CHAR 1
|
||||
|
||||
/*
|
||||
* Needed by libevent
|
||||
*/
|
||||
/* #undef HAVE_SOCKLEN_T */
|
||||
|
||||
/* For --secure-file-priv */
|
||||
#define DEFAULT_SECURE_FILE_PRIV_DIR "NULL"
|
||||
#define DEFAULT_SECURE_FILE_PRIV_EMBEDDED_DIR "NULL"
|
||||
/* #undef HAVE_LIBNUMA */
|
||||
|
||||
/* For default value of --early_plugin_load */
|
||||
/* #undef DEFAULT_EARLY_PLUGIN_LOAD */
|
||||
|
||||
#endif
|
|
@ -0,0 +1,255 @@
|
|||
/* Copyright (c) 2000, 2022, Oracle and/or its affiliates.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License, version 2.0,
|
||||
as published by the Free Software Foundation.
|
||||
|
||||
This program is also distributed with certain software (including
|
||||
but not limited to OpenSSL) that is licensed under separate terms,
|
||||
as designated in a particular file or component or in included license
|
||||
documentation. The authors of MySQL hereby grant you an additional
|
||||
permission to link the program and your derivative works with the
|
||||
separately licensed software that they have included with MySQL.
|
||||
|
||||
Without limiting anything contained in the foregoing, this file,
|
||||
which is part of C Driver for MySQL (Connector/C), is also subject to the
|
||||
Universal FOSS Exception, version 1.0, a copy of which can be found at
|
||||
http://oss.oracle.com/licenses/universal-foss-exception.
|
||||
|
||||
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, version 2.0, 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 St, Fifth Floor, Boston, MA 02110-1301 USA */
|
||||
|
||||
#ifndef MY_DBUG_INCLUDED
|
||||
#define MY_DBUG_INCLUDED
|
||||
|
||||
#include "my_global.h" /* MYSQL_PLUGIN_IMPORT */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#if !defined(NDEBUG)
|
||||
|
||||
struct _db_stack_frame_ {
|
||||
const char *func; /* function name of the previous stack frame */
|
||||
const char *file; /* filename of the function of previous frame */
|
||||
uint level; /* this nesting level, highest bit enables tracing */
|
||||
struct _db_stack_frame_ *prev; /* pointer to the previous frame */
|
||||
};
|
||||
|
||||
struct _db_code_state_;
|
||||
extern MYSQL_PLUGIN_IMPORT my_bool _dbug_on_;
|
||||
extern my_bool _db_keyword_(struct _db_code_state_ *, const char *, int);
|
||||
extern int _db_explain_(struct _db_code_state_ *cs, char *buf, size_t len);
|
||||
extern int _db_explain_init_(char *buf, size_t len);
|
||||
extern int _db_is_pushed_(void);
|
||||
extern void _db_setjmp_(void);
|
||||
extern void _db_longjmp_(void);
|
||||
extern void _db_process_(const char *name);
|
||||
extern void _db_push_(const char *control);
|
||||
extern void _db_pop_(void);
|
||||
extern void _db_set_(const char *control);
|
||||
extern void _db_set_init_(const char *control);
|
||||
extern void _db_enter_(const char *_func_, const char *_file_, uint _line_,
|
||||
struct _db_stack_frame_ *_stack_frame_);
|
||||
extern void _db_return_(uint _line_, struct _db_stack_frame_ *_stack_frame_);
|
||||
extern void _db_pargs_(uint _line_,const char *keyword);
|
||||
extern int _db_enabled_();
|
||||
extern void _db_doprnt_(const char *format,...)
|
||||
MY_ATTRIBUTE((format(printf, 1, 2)));
|
||||
extern void _db_doputs_(const char *log);
|
||||
extern void _db_dump_(uint _line_,const char *keyword,
|
||||
const unsigned char *memory, size_t length);
|
||||
extern void _db_end_(void);
|
||||
extern void _db_lock_file_(void);
|
||||
extern void _db_unlock_file_(void);
|
||||
extern FILE *_db_fp_(void);
|
||||
extern void _db_flush_();
|
||||
extern const char* _db_get_func_(void);
|
||||
|
||||
#define DBUG_ENTER(a) struct _db_stack_frame_ _db_stack_frame_; \
|
||||
_db_enter_ (a,__FILE__,__LINE__,&_db_stack_frame_)
|
||||
#define DBUG_LEAVE _db_return_ (__LINE__, &_db_stack_frame_)
|
||||
#define DBUG_RETURN(a1) do {DBUG_LEAVE; return(a1);} while(0)
|
||||
#define DBUG_VOID_RETURN do {DBUG_LEAVE; return;} while(0)
|
||||
#define DBUG_EXECUTE(keyword,a1) \
|
||||
do {if (_db_keyword_(0, (keyword), 0)) { a1 }} while(0)
|
||||
#define DBUG_EXECUTE_IF(keyword,a1) \
|
||||
do {if (_db_keyword_(0, (keyword), 1)) { a1 }} while(0)
|
||||
#define DBUG_EVALUATE(keyword,a1,a2) \
|
||||
(_db_keyword_(0,(keyword), 0) ? (a1) : (a2))
|
||||
#define DBUG_EVALUATE_IF(keyword,a1,a2) \
|
||||
(_db_keyword_(0,(keyword), 1) ? (a1) : (a2))
|
||||
#define DBUG_PRINT(keyword,arglist) \
|
||||
do \
|
||||
{ \
|
||||
if (_dbug_on_) \
|
||||
{ \
|
||||
_db_pargs_(__LINE__,keyword); \
|
||||
if (_db_enabled_()) \
|
||||
{ \
|
||||
_db_doprnt_ arglist; \
|
||||
} \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
/*
|
||||
An alternate to DBUG_PRINT() macro, which takes a single string
|
||||
as the second argument.
|
||||
*/
|
||||
#define DBUG_PUTS(keyword,arg) \
|
||||
do \
|
||||
{ \
|
||||
if (_dbug_on_) \
|
||||
{ \
|
||||
_db_pargs_(__LINE__,keyword); \
|
||||
if (_db_enabled_()) \
|
||||
{ \
|
||||
_db_doputs_(arg); \
|
||||
} \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
#define DBUG_PUSH(a1) _db_push_ (a1)
|
||||
#define DBUG_POP() _db_pop_ ()
|
||||
#define DBUG_SET(a1) _db_set_ (a1)
|
||||
#define DBUG_SET_INITIAL(a1) _db_set_init_ (a1)
|
||||
#define DBUG_PROCESS(a1) _db_process_(a1)
|
||||
#define DBUG_FILE _db_fp_()
|
||||
#define DBUG_SETJMP(a1) (_db_setjmp_ (), setjmp (a1))
|
||||
#define DBUG_LONGJMP(a1,a2) (_db_longjmp_ (), longjmp (a1, a2))
|
||||
#define DBUG_DUMP(keyword,a1,a2) _db_dump_(__LINE__,keyword,a1,a2)
|
||||
#define DBUG_END() _db_end_ ()
|
||||
#define DBUG_LOCK_FILE _db_lock_file_()
|
||||
#define DBUG_UNLOCK_FILE _db_unlock_file_()
|
||||
#define DBUG_EXPLAIN(buf,len) _db_explain_(0, (buf),(len))
|
||||
#define DBUG_EXPLAIN_INITIAL(buf,len) _db_explain_init_((buf),(len))
|
||||
#define DEBUGGER_OFF do { _dbug_on_= 0; } while(0)
|
||||
#define DEBUGGER_ON do { _dbug_on_= 1; } while(0)
|
||||
#ifndef _WIN32
|
||||
#define DBUG_ABORT() (_db_flush_(), abort())
|
||||
#else
|
||||
/*
|
||||
Avoid popup with abort/retry/ignore buttons. When BUG#31745 is fixed we can
|
||||
call abort() instead of _exit(2) (now it would cause a "test signal" popup).
|
||||
*/
|
||||
#include <crtdbg.h>
|
||||
#define DBUG_ABORT() (_db_flush_(),\
|
||||
(void)_CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE),\
|
||||
(void)_CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR),\
|
||||
_exit(2))
|
||||
#endif
|
||||
#define DBUG_CHECK_CRASH(func, op) \
|
||||
do { char _dbuf_[255]; strxnmov(_dbuf_, sizeof(_dbuf_)-1, (func), (op)); \
|
||||
DBUG_EXECUTE_IF(_dbuf_, DBUG_ABORT()); } while(0)
|
||||
#define DBUG_CRASH_ENTER(func) \
|
||||
DBUG_ENTER(func); DBUG_CHECK_CRASH(func, "_crash_enter")
|
||||
#define DBUG_CRASH_RETURN(val) \
|
||||
DBUG_CHECK_CRASH(_db_get_func_(), "_crash_return")
|
||||
#define DBUG_CRASH_VOID_RETURN \
|
||||
DBUG_CHECK_CRASH (_db_get_func_(), "_crash_return")
|
||||
|
||||
/*
|
||||
Make the program fail, without creating a core file.
|
||||
abort() will send SIGABRT which (most likely) generates core.
|
||||
Use SIGKILL instead, which cannot be caught.
|
||||
We also pause the current thread, until the signal is actually delivered.
|
||||
An alternative would be to use _exit(EXIT_FAILURE),
|
||||
but then valgrind would report lots of memory leaks.
|
||||
*/
|
||||
#ifdef _WIN32
|
||||
#define DBUG_SUICIDE() DBUG_ABORT()
|
||||
#else
|
||||
extern void _db_suicide_();
|
||||
extern void _db_flush_gcov_();
|
||||
#define DBUG_SUICIDE() (_db_flush_(), _db_suicide_())
|
||||
#endif
|
||||
|
||||
#else /* No debugger */
|
||||
|
||||
#define DBUG_ENTER(a1)
|
||||
#define DBUG_LEAVE
|
||||
#define DBUG_RETURN(a1) do { return(a1); } while(0)
|
||||
#define DBUG_VOID_RETURN do { return; } while(0)
|
||||
#define DBUG_EXECUTE(keyword,a1) do { } while(0)
|
||||
#define DBUG_EXECUTE_IF(keyword,a1) do { } while(0)
|
||||
#define DBUG_EVALUATE(keyword,a1,a2) (a2)
|
||||
#define DBUG_EVALUATE_IF(keyword,a1,a2) (a2)
|
||||
#define DBUG_PRINT(keyword,arglist) do { } while(0)
|
||||
#define DBUG_PUTS(keyword,arg) do { } while(0)
|
||||
#define DBUG_LOG(keyword,arglist) do { } while(0)
|
||||
#define DBUG_PUSH(a1) do { } while(0)
|
||||
#define DBUG_SET(a1) do { } while(0)
|
||||
#define DBUG_SET_INITIAL(a1) do { } while(0)
|
||||
#define DBUG_POP() do { } while(0)
|
||||
#define DBUG_PROCESS(a1) do { } while(0)
|
||||
#define DBUG_SETJMP(a1) setjmp(a1)
|
||||
#define DBUG_LONGJMP(a1) longjmp(a1)
|
||||
#define DBUG_DUMP(keyword,a1,a2) do { } while(0)
|
||||
#define DBUG_END() do { } while(0)
|
||||
#define DBUG_LOCK_FILE do { } while(0)
|
||||
#define DBUG_FILE (stderr)
|
||||
#define DBUG_UNLOCK_FILE do { } while(0)
|
||||
#define DBUG_EXPLAIN(buf,len)
|
||||
#define DBUG_EXPLAIN_INITIAL(buf,len)
|
||||
#define DEBUGGER_OFF do { } while(0)
|
||||
#define DEBUGGER_ON do { } while(0)
|
||||
#define DBUG_ABORT() do { } while(0)
|
||||
#define DBUG_CRASH_ENTER(func)
|
||||
#define DBUG_CRASH_RETURN(val) do { return(val); } while(0)
|
||||
#define DBUG_CRASH_VOID_RETURN do { return; } while(0)
|
||||
#define DBUG_SUICIDE() do { } while(0)
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef EXTRA_DEBUG
|
||||
/**
|
||||
Sync points allow us to force the server to reach a certain line of code
|
||||
and block there until the client tells the server it is ok to go on.
|
||||
The client tells the server to block with SELECT GET_LOCK()
|
||||
and unblocks it with SELECT RELEASE_LOCK(). Used for debugging difficult
|
||||
concurrency problems
|
||||
*/
|
||||
#define DBUG_SYNC_POINT(lock_name,lock_timeout) \
|
||||
debug_sync_point(lock_name,lock_timeout)
|
||||
void debug_sync_point(const char* lock_name, uint lock_timeout);
|
||||
#else
|
||||
#define DBUG_SYNC_POINT(lock_name,lock_timeout)
|
||||
#endif /* EXTRA_DEBUG */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if !defined(NDEBUG)
|
||||
#include <sstream>
|
||||
|
||||
/*
|
||||
A C++ interface to the DBUG_PUTS macro. The DBUG_LOG macro also
|
||||
takes two arguments. The first argument is the keyword, as that of the
|
||||
DBUG_PRINT. The 2nd argument 'v' will be passed to a C++ output stream.
|
||||
This enables the use of C++ style output stream operator. In the code, it
|
||||
will be used as follows:
|
||||
|
||||
DBUG_LOG("blob", "space: " << space_id);
|
||||
|
||||
Note: DBUG_PRINT() has a limitation of 1024 bytes for a single
|
||||
print out. This limitation is not there for DBUG_PUTS and DBUG_LOG
|
||||
macros.
|
||||
*/
|
||||
|
||||
#define DBUG_LOG(keyword, v) do { \
|
||||
std::ostringstream sout; \
|
||||
sout << v; \
|
||||
DBUG_PUTS(keyword, sout.str().c_str()); \
|
||||
} while(0)
|
||||
#endif /* NDEBUG */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* MY_DBUG_INCLUDED */
|
|
@ -0,0 +1,100 @@
|
|||
/* Copyright (c) 2000, 2022, Oracle and/or its affiliates.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License, version 2.0,
|
||||
as published by the Free Software Foundation.
|
||||
|
||||
This program is also distributed with certain software (including
|
||||
but not limited to OpenSSL) that is licensed under separate terms,
|
||||
as designated in a particular file or component or in included license
|
||||
documentation. The authors of MySQL hereby grant you an additional
|
||||
permission to link the program and your derivative works with the
|
||||
separately licensed software that they have included with MySQL.
|
||||
|
||||
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, version 2.0, 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 St, Fifth Floor, Boston, MA 02110-1301 USA */
|
||||
|
||||
#ifndef MY_DIR_H
|
||||
#define MY_DIR_H
|
||||
|
||||
#include "my_global.h"
|
||||
|
||||
#include <sys/stat.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Defines for my_dir and my_stat */
|
||||
|
||||
#ifdef _WIN32
|
||||
#define S_IROTH _S_IREAD
|
||||
#define S_IFIFO _S_IFIFO
|
||||
#endif
|
||||
|
||||
#define MY_S_IFMT S_IFMT /* type of file */
|
||||
#define MY_S_IFDIR S_IFDIR /* directory */
|
||||
#define MY_S_IFCHR S_IFCHR /* character special */
|
||||
#define MY_S_IFBLK S_IFBLK /* block special */
|
||||
#define MY_S_IFREG S_IFREG /* regular */
|
||||
#define MY_S_IFIFO S_IFIFO /* fifo */
|
||||
#define MY_S_ISUID S_ISUID /* set user id on execution */
|
||||
#define MY_S_ISGID S_ISGID /* set group id on execution */
|
||||
#define MY_S_ISVTX S_ISVTX /* save swapped text even after use */
|
||||
#define MY_S_IREAD S_IREAD /* read permission, owner */
|
||||
#define MY_S_IWRITE S_IWRITE /* write permission, owner */
|
||||
#define MY_S_IEXEC S_IEXEC /* execute/search permission, owner */
|
||||
|
||||
#define MY_S_ISDIR(m) (((m) & MY_S_IFMT) == MY_S_IFDIR)
|
||||
#define MY_S_ISCHR(m) (((m) & MY_S_IFMT) == MY_S_IFCHR)
|
||||
#define MY_S_ISBLK(m) (((m) & MY_S_IFMT) == MY_S_IFBLK)
|
||||
#define MY_S_ISREG(m) (((m) & MY_S_IFMT) == MY_S_IFREG)
|
||||
#define MY_S_ISFIFO(m) (((m) & MY_S_IFMT) == MY_S_IFIFO)
|
||||
|
||||
#define MY_DONT_SORT 512 /* my_lib; Don't sort files */
|
||||
#define MY_WANT_STAT 1024 /* my_lib; stat files */
|
||||
|
||||
/* typedefs for my_dir & my_stat */
|
||||
|
||||
#if(_MSC_VER)
|
||||
#define MY_STAT struct _stati64 /* 64 bit file size */
|
||||
#else
|
||||
#define MY_STAT struct stat /* Orginal struct have what we need */
|
||||
#endif
|
||||
|
||||
/* Struct describing one file returned from my_dir */
|
||||
typedef struct fileinfo
|
||||
{
|
||||
char *name;
|
||||
MY_STAT *mystat;
|
||||
} FILEINFO;
|
||||
|
||||
typedef struct st_my_dir /* Struct returned from my_dir */
|
||||
{
|
||||
/*
|
||||
These members are just copies of parts of DYNAMIC_ARRAY structure,
|
||||
which is allocated right after the end of MY_DIR structure (MEM_ROOT
|
||||
for storing names is also resides there). We've left them here because
|
||||
we don't want to change code that uses my_dir.
|
||||
*/
|
||||
struct fileinfo *dir_entry;
|
||||
uint number_off_files;
|
||||
} MY_DIR;
|
||||
|
||||
extern MY_DIR *my_dir(const char *path,myf MyFlags);
|
||||
extern void my_dirend(MY_DIR *buffer);
|
||||
extern MY_STAT *my_stat(const char *path, MY_STAT *stat_area, myf my_flags);
|
||||
extern int my_fstat(int filenr, MY_STAT *stat_area, myf MyFlags);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* MY_DIR_H */
|
||||
|
|
@ -0,0 +1,156 @@
|
|||
/*
|
||||
Copyright (c) 2002, 2022, Oracle and/or its affiliates.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License, version 2.0,
|
||||
as published by the Free Software Foundation.
|
||||
|
||||
This program is also distributed with certain software (including
|
||||
but not limited to OpenSSL) that is licensed under separate terms,
|
||||
as designated in a particular file or component or in included license
|
||||
documentation. The authors of MySQL hereby grant you an additional
|
||||
permission to link the program and your derivative works with the
|
||||
separately licensed software that they have included with MySQL.
|
||||
|
||||
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, version 2.0, 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 St, Fifth Floor, Boston, MA 02110-1301 USA */
|
||||
|
||||
#ifndef _my_getopt_h
|
||||
#define _my_getopt_h
|
||||
|
||||
#include "my_sys.h" /* loglevel */
|
||||
|
||||
C_MODE_START
|
||||
|
||||
#define GET_NO_ARG 1
|
||||
#define GET_BOOL 2
|
||||
#define GET_INT 3
|
||||
#define GET_UINT 4
|
||||
#define GET_LONG 5
|
||||
#define GET_ULONG 6
|
||||
#define GET_LL 7
|
||||
#define GET_ULL 8
|
||||
#define GET_STR 9
|
||||
#define GET_STR_ALLOC 10
|
||||
#define GET_DISABLED 11
|
||||
#define GET_ENUM 12
|
||||
#define GET_SET 13
|
||||
#define GET_DOUBLE 14
|
||||
#define GET_FLAGSET 15
|
||||
#define GET_PASSWORD 16
|
||||
|
||||
#if SIZEOF_INT == 4
|
||||
#define GET_INT32 GET_INT
|
||||
#define GET_UINT32 GET_UINT
|
||||
#elif SIZEOF_LONG == 4
|
||||
#define GET_INT32 GET_LONG
|
||||
#define GET_UINT32 GET_ULONG
|
||||
#else
|
||||
#error Neither int or long is of 4 bytes width
|
||||
#endif
|
||||
|
||||
#define GET_ASK_ADDR 128
|
||||
#define GET_TYPE_MASK 127
|
||||
|
||||
/**
|
||||
Enumeration of the my_option::arg_type attributes.
|
||||
It should be noted that for historical reasons variables with the combination
|
||||
arg_type=NO_ARG, my_option::var_type=GET_BOOL still accepts
|
||||
arguments. This is someone counter intuitive and care should be taken
|
||||
if the code is refactored.
|
||||
*/
|
||||
enum get_opt_arg_type { NO_ARG, OPT_ARG, REQUIRED_ARG };
|
||||
|
||||
struct st_typelib;
|
||||
|
||||
struct my_option
|
||||
{
|
||||
const char *name; /**< Name of the option. name=NULL
|
||||
marks the end of the my_option[]
|
||||
array.
|
||||
*/
|
||||
int id; /**< For 0<id<=255 it's means one
|
||||
character for a short option
|
||||
(like -A), if >255 no short option
|
||||
is created, but a long option still
|
||||
can be identified uniquely in the
|
||||
my_get_one_option() callback.
|
||||
If an opton needs neither special
|
||||
treatment in the my_get_one_option()
|
||||
nor one-letter short equivalent
|
||||
use id=0.
|
||||
id=-1 is a special case and is used
|
||||
to generate deprecation warnings for
|
||||
plugin options. It should not be
|
||||
used for anything else.
|
||||
*/
|
||||
const char *comment; /**< option comment, for autom. --help.
|
||||
if it's NULL the option is not
|
||||
visible in --help.
|
||||
*/
|
||||
void *value; /**< A pointer to the variable value */
|
||||
void *u_max_value; /**< The user def. max variable value */
|
||||
struct st_typelib *typelib; /**< Pointer to possible values */
|
||||
ulong var_type; /**< GET_BOOL, GET_ULL, etc */
|
||||
enum get_opt_arg_type arg_type; /**< e.g. REQUIRED_ARG or OPT_ARG */
|
||||
longlong def_value; /**< Default value */
|
||||
longlong min_value; /**< Min allowed value (for numbers) */
|
||||
ulonglong max_value; /**< Max allowed value (for numbers) */
|
||||
longlong sub_size; /**< Unused */
|
||||
long block_size; /**< Value should be a mult. of this (for numbers) */
|
||||
void *app_type; /**< To be used by an application */
|
||||
};
|
||||
|
||||
|
||||
typedef my_bool (*my_get_one_option)(int, const struct my_option *, char *);
|
||||
/**
|
||||
Used to retrieve a reference to the object (variable) that holds the value
|
||||
for the given option. For example, if var_type is GET_UINT, the function
|
||||
must return a pointer to a variable of type uint. A argument is stored in
|
||||
the location pointed to by the returned pointer.
|
||||
*/
|
||||
typedef void *(*my_getopt_value)(const char *, size_t, const struct my_option *,
|
||||
int *);
|
||||
|
||||
|
||||
extern char *disabled_my_option;
|
||||
extern my_bool my_getopt_print_errors;
|
||||
extern my_bool my_getopt_skip_unknown;
|
||||
extern my_error_reporter my_getopt_error_reporter;
|
||||
|
||||
extern int handle_options (int *argc, char ***argv,
|
||||
const struct my_option *longopts, my_get_one_option);
|
||||
extern int my_handle_options (int *argc, char ***argv,
|
||||
const struct my_option *longopts,
|
||||
my_get_one_option,
|
||||
const char **command_list, my_bool ignore_unknown_option);
|
||||
extern void print_cmdline_password_warning();
|
||||
extern void my_cleanup_options(const struct my_option *options);
|
||||
extern void my_cleanup_options(const struct my_option *options);
|
||||
extern void my_print_help(const struct my_option *options);
|
||||
extern void my_print_variables(const struct my_option *options);
|
||||
extern void my_print_variables_ex(const struct my_option *options, FILE* file);
|
||||
extern void my_getopt_register_get_addr(my_getopt_value);
|
||||
|
||||
ulonglong getopt_ull_limit_value(ulonglong num, const struct my_option *optp,
|
||||
my_bool *fix);
|
||||
longlong getopt_ll_limit_value(longlong, const struct my_option *,
|
||||
my_bool *fix);
|
||||
double getopt_double_limit_value(double num, const struct my_option *optp,
|
||||
my_bool *fix);
|
||||
my_bool getopt_compare_strings(const char *s, const char *t, uint length);
|
||||
ulonglong max_of_int_range(int var_type);
|
||||
|
||||
ulonglong getopt_double2ulonglong(double);
|
||||
double getopt_ulonglong2double(ulonglong);
|
||||
|
||||
C_MODE_END
|
||||
|
||||
#endif /* _my_getopt_h */
|
||||
|
|
@ -0,0 +1,804 @@
|
|||
/*
|
||||
Copyright (c) 2001, 2022, Oracle and/or its affiliates.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License, version 2.0,
|
||||
as published by the Free Software Foundation.
|
||||
|
||||
This program is also distributed with certain software (including
|
||||
but not limited to OpenSSL) that is licensed under separate terms,
|
||||
as designated in a particular file or component or in included license
|
||||
documentation. The authors of MySQL hereby grant you an additional
|
||||
permission to link the program and your derivative works with the
|
||||
separately licensed software that they have included with MySQL.
|
||||
|
||||
Without limiting anything contained in the foregoing, this file,
|
||||
which is part of C Driver for MySQL (Connector/C), is also subject to the
|
||||
Universal FOSS Exception, version 1.0, a copy of which can be found at
|
||||
http://oss.oracle.com/licenses/universal-foss-exception.
|
||||
|
||||
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, version 2.0, 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 St, Fifth Floor, Boston, MA 02110-1301 USA */
|
||||
|
||||
#ifndef MY_GLOBAL_INCLUDED
|
||||
#define MY_GLOBAL_INCLUDED
|
||||
|
||||
/*
|
||||
This include file should be included first in every header file.
|
||||
|
||||
This makes sure my_config.h is included to get platform specific
|
||||
symbols defined and it makes sure a lot of platform/compiler
|
||||
differences are mitigated.
|
||||
*/
|
||||
|
||||
#include "my_config.h"
|
||||
|
||||
#define __STDC_LIMIT_MACROS /* Enable C99 limit macros */
|
||||
#define __STDC_FORMAT_MACROS /* Enable C99 printf format macros */
|
||||
#define _USE_MATH_DEFINES /* Get access to M_PI, M_E, etc. in math.h */
|
||||
|
||||
#ifdef _WIN32
|
||||
/* Include common headers.*/
|
||||
# include <winsock2.h>
|
||||
# include <ws2tcpip.h> /* SOCKET */
|
||||
# include <io.h> /* access(), chmod() */
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
#include <stddef.h>
|
||||
#include <math.h>
|
||||
#include <limits.h>
|
||||
#include <float.h>
|
||||
#include <fcntl.h>
|
||||
#include <time.h>
|
||||
#include <errno.h> /* Recommended by debian */
|
||||
#include <sys/types.h>
|
||||
|
||||
#ifdef HAVE_SYS_SOCKET_H
|
||||
#include <sys/socket.h>
|
||||
#endif
|
||||
#if !defined(_WIN32)
|
||||
#include <netdb.h>
|
||||
#endif
|
||||
#ifdef MY_MSCRT_DEBUG
|
||||
#include <crtdbg.h>
|
||||
#endif
|
||||
|
||||
/*
|
||||
A lot of our programs uses asserts, so better to always include it
|
||||
This also fixes a problem when people uses assert without including
|
||||
assert.h
|
||||
*/
|
||||
#include <assert.h>
|
||||
|
||||
/* Include standard definitions of operator new and delete. */
|
||||
#ifdef __cplusplus
|
||||
# include <new>
|
||||
#endif
|
||||
|
||||
#include "my_compiler.h"
|
||||
|
||||
|
||||
/*
|
||||
InnoDB depends on some MySQL internals which other plugins should not
|
||||
need. This is because of InnoDB's foreign key support, "safe" binlog
|
||||
truncation, and other similar legacy features.
|
||||
|
||||
We define accessors for these internals unconditionally, but do not
|
||||
expose them in mysql/plugin.h. They are declared in ha_innodb.h for
|
||||
InnoDB's use.
|
||||
*/
|
||||
#define INNODB_COMPATIBILITY_HOOKS
|
||||
|
||||
/* Macros to make switching between C and C++ mode easier */
|
||||
#ifdef __cplusplus
|
||||
#define C_MODE_START extern "C" {
|
||||
#define C_MODE_END }
|
||||
#else
|
||||
#define C_MODE_START
|
||||
#define C_MODE_END
|
||||
#endif
|
||||
|
||||
#ifdef WITH_PERFSCHEMA_STORAGE_ENGINE
|
||||
#define HAVE_PSI_INTERFACE
|
||||
#endif /* WITH_PERFSCHEMA_STORAGE_ENGINE */
|
||||
|
||||
/* Make it easier to add conditional code in _expressions_ */
|
||||
#ifdef _WIN32
|
||||
#define IF_WIN(A,B) A
|
||||
#else
|
||||
#define IF_WIN(A,B) B
|
||||
#endif
|
||||
|
||||
#if defined (_WIN32)
|
||||
/*
|
||||
off_t is 32 bit long. We do not use C runtime functions
|
||||
with off_t but native Win32 file IO APIs, that work with
|
||||
64 bit offsets.
|
||||
*/
|
||||
#undef SIZEOF_OFF_T
|
||||
#define SIZEOF_OFF_T 8
|
||||
|
||||
static inline void sleep(unsigned long seconds)
|
||||
{
|
||||
Sleep(seconds * 1000);
|
||||
}
|
||||
|
||||
/* Define missing access() modes. */
|
||||
#define F_OK 0
|
||||
#define W_OK 2
|
||||
#define R_OK 4 /* Test for read permission. */
|
||||
|
||||
/* Define missing file locking constants. */
|
||||
#define F_RDLCK 1
|
||||
#define F_WRLCK 2
|
||||
#define F_UNLCK 3
|
||||
#define F_TO_EOF 0x3FFFFFFF
|
||||
|
||||
#define O_NONBLOCK 1 /* For emulation of fcntl() */
|
||||
|
||||
/*
|
||||
SHUT_RDWR is called SD_BOTH in windows and
|
||||
is defined to 2 in winsock2.h
|
||||
#define SD_BOTH 0x02
|
||||
*/
|
||||
#define SHUT_RDWR 0x02
|
||||
|
||||
/* Shared memory and named pipe connections are supported. */
|
||||
#define shared_memory_buffer_length 16000
|
||||
#define default_shared_memory_base_name "MYSQL"
|
||||
#endif /* _WIN32*/
|
||||
|
||||
/**
|
||||
Cast a member of a structure to the structure that contains it.
|
||||
|
||||
@param ptr Pointer to the member.
|
||||
@param type Type of the structure that contains the member.
|
||||
@param member Name of the member within the structure.
|
||||
*/
|
||||
#define my_container_of(ptr, type, member) \
|
||||
((type *)((char *)ptr - offsetof(type, member)))
|
||||
|
||||
/* an assert that works at compile-time. only for constant expression */
|
||||
#define compile_time_assert(X) \
|
||||
do \
|
||||
{ \
|
||||
typedef char compile_time_assert[(X) ? 1 : -1] MY_ATTRIBUTE((unused)); \
|
||||
} while(0)
|
||||
|
||||
#define QUOTE_ARG(x) #x /* Quote argument (before cpp) */
|
||||
#define STRINGIFY_ARG(x) QUOTE_ARG(x) /* Quote argument, after cpp */
|
||||
|
||||
#ifdef _WIN32
|
||||
#define SO_EXT ".dll"
|
||||
#elif defined(__APPLE__)
|
||||
#define SO_EXT ".dylib"
|
||||
#else
|
||||
#define SO_EXT ".so"
|
||||
#endif
|
||||
|
||||
#if !defined(HAVE_UINT)
|
||||
typedef unsigned int uint;
|
||||
typedef unsigned short ushort;
|
||||
#endif
|
||||
|
||||
#define swap_variables(t, a, b) { t dummy; dummy= a; a= b; b= dummy; }
|
||||
#define MY_TEST(a) ((a) ? 1 : 0)
|
||||
#define set_if_bigger(a,b) do { if ((a) < (b)) (a)=(b); } while(0)
|
||||
#define set_if_smaller(a,b) do { if ((a) > (b)) (a)=(b); } while(0)
|
||||
#define test_all_bits(a,b) (((a) & (b)) == (b))
|
||||
#define array_elements(A) ((uint) (sizeof(A)/sizeof(A[0])))
|
||||
|
||||
/* Define some general constants */
|
||||
#ifndef TRUE
|
||||
#define TRUE (1) /* Logical true */
|
||||
#define FALSE (0) /* Logical false */
|
||||
#endif
|
||||
|
||||
/* Some types that is different between systems */
|
||||
|
||||
typedef int File; /* File descriptor */
|
||||
#ifdef _WIN32
|
||||
typedef SOCKET my_socket;
|
||||
#else
|
||||
typedef int my_socket; /* File descriptor for sockets */
|
||||
#define INVALID_SOCKET -1
|
||||
#endif
|
||||
C_MODE_START
|
||||
typedef void (*sig_return)();/* Returns type from signal */
|
||||
C_MODE_END
|
||||
#if defined(__GNUC__)
|
||||
typedef char pchar; /* Mixed prototypes can take char */
|
||||
typedef char pbool; /* Mixed prototypes can take char */
|
||||
#else
|
||||
typedef int pchar; /* Mixed prototypes can't take char */
|
||||
typedef int pbool; /* Mixed prototypes can't take char */
|
||||
#endif
|
||||
C_MODE_START
|
||||
typedef int (*qsort_cmp)(const void *,const void *);
|
||||
typedef int (*qsort_cmp2)(const void*, const void *,const void *);
|
||||
C_MODE_END
|
||||
#ifdef _WIN32
|
||||
typedef int socket_len_t;
|
||||
typedef int sigset_t;
|
||||
typedef int mode_t;
|
||||
typedef SSIZE_T ssize_t;
|
||||
#else
|
||||
typedef socklen_t socket_len_t;
|
||||
#endif
|
||||
typedef socket_len_t SOCKET_SIZE_TYPE; /* Used by NDB */
|
||||
|
||||
/* file create flags */
|
||||
|
||||
#ifndef O_SHARE /* Probably not windows */
|
||||
#define O_SHARE 0 /* Flag to my_open for shared files */
|
||||
#ifndef O_BINARY
|
||||
#define O_BINARY 0 /* Flag to my_open for binary files */
|
||||
#endif
|
||||
#ifndef FILE_BINARY
|
||||
#define FILE_BINARY O_BINARY /* Flag to my_fopen for binary streams */
|
||||
#endif
|
||||
#ifdef HAVE_FCNTL
|
||||
#define HAVE_FCNTL_LOCK
|
||||
#define F_TO_EOF 0L /* Param to lockf() to lock rest of file */
|
||||
#endif
|
||||
#endif /* O_SHARE */
|
||||
|
||||
#ifndef O_TEMPORARY
|
||||
#define O_TEMPORARY 0
|
||||
#endif
|
||||
#ifndef O_SHORT_LIVED
|
||||
#define O_SHORT_LIVED 0
|
||||
#endif
|
||||
#ifndef O_NOFOLLOW
|
||||
#define O_NOFOLLOW 0
|
||||
#endif
|
||||
|
||||
/* additional file share flags for win32 */
|
||||
#ifdef _WIN32
|
||||
#define _SH_DENYRWD 0x110 /* deny read/write mode & delete */
|
||||
#define _SH_DENYWRD 0x120 /* deny write mode & delete */
|
||||
#define _SH_DENYRDD 0x130 /* deny read mode & delete */
|
||||
#define _SH_DENYDEL 0x140 /* deny delete only */
|
||||
#endif /* _WIN32 */
|
||||
|
||||
|
||||
/* General constants */
|
||||
#define FN_LEN 256 /* Max file name len */
|
||||
#define FN_HEADLEN 253 /* Max length of filepart of file name */
|
||||
#define FN_EXTLEN 20 /* Max length of extension (part of FN_LEN) */
|
||||
#define FN_REFLEN 512 /* Max length of full path-name */
|
||||
#define FN_REFLEN_SE 4000 /* Max length of full path-name in SE */
|
||||
#define FN_EXTCHAR '.'
|
||||
#define FN_HOMELIB '~' /* ~/ is used as abbrev for home dir */
|
||||
#define FN_CURLIB '.' /* ./ is used as abbrev for current dir */
|
||||
#define FN_PARENTDIR ".." /* Parent directory; Must be a string */
|
||||
|
||||
#ifdef _WIN32
|
||||
#define FN_LIBCHAR '\\'
|
||||
#define FN_LIBCHAR2 '/'
|
||||
#define FN_DIRSEP "/\\" /* Valid directory separators */
|
||||
#define FN_EXEEXT ".exe"
|
||||
#define FN_SOEXT ".dll"
|
||||
#define FN_ROOTDIR "\\"
|
||||
#define FN_DEVCHAR ':'
|
||||
#define FN_NETWORK_DRIVES /* Uses \\ to indicate network drives */
|
||||
#else
|
||||
#define FN_LIBCHAR '/'
|
||||
/*
|
||||
FN_LIBCHAR2 is not defined on !Windows. Use is_directory_separator().
|
||||
*/
|
||||
#define FN_DIRSEP "/" /* Valid directory separators */
|
||||
#define FN_EXEEXT ""
|
||||
#define FN_SOEXT ".so"
|
||||
#define FN_ROOTDIR "/"
|
||||
#endif
|
||||
|
||||
static inline int is_directory_separator(char c)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
return c == FN_LIBCHAR || c == FN_LIBCHAR2;
|
||||
#else
|
||||
return c == FN_LIBCHAR;
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
MY_FILE_MIN is Windows speciality and is used to quickly detect
|
||||
the mismatch of CRT and mysys file IO usage on Windows at runtime.
|
||||
CRT file descriptors can be in the range 0-2047, whereas descriptors returned
|
||||
by my_open() will start with 2048. If a file descriptor with value less then
|
||||
MY_FILE_MIN is passed to mysys IO function, chances are it stemms from
|
||||
open()/fileno() and not my_open()/my_fileno.
|
||||
|
||||
For Posix, mysys functions are light wrappers around libc, and MY_FILE_MIN
|
||||
is logically 0.
|
||||
*/
|
||||
|
||||
#ifdef _WIN32
|
||||
#define MY_FILE_MIN 2048
|
||||
#else
|
||||
#define MY_FILE_MIN 0
|
||||
#endif
|
||||
|
||||
/*
|
||||
MY_NFILE is the default size of my_file_info array.
|
||||
|
||||
It is larger on Windows, because it all file handles are stored in my_file_info
|
||||
Default size is 16384 and this should be enough for most cases.If it is not
|
||||
enough, --max-open-files with larger value can be used.
|
||||
|
||||
For Posix , my_file_info array is only used to store filenames for
|
||||
error reporting and its size is not a limitation for number of open files.
|
||||
*/
|
||||
#ifdef _WIN32
|
||||
#define MY_NFILE (16384 + MY_FILE_MIN)
|
||||
#else
|
||||
#define MY_NFILE 64
|
||||
#endif
|
||||
|
||||
#define OS_FILE_LIMIT UINT_MAX
|
||||
|
||||
/*
|
||||
Io buffer size; Must be a power of 2 and a multiple of 512. May be
|
||||
smaller what the disk page size. This influences the speed of the
|
||||
isam btree library. eg to big to slow.
|
||||
*/
|
||||
#define IO_SIZE 4096
|
||||
/*
|
||||
How much overhead does malloc have. The code often allocates
|
||||
something like 1024-MALLOC_OVERHEAD bytes
|
||||
*/
|
||||
#define MALLOC_OVERHEAD 8
|
||||
|
||||
/* get memory in huncs */
|
||||
#define ONCE_ALLOC_INIT (uint) (4096-MALLOC_OVERHEAD)
|
||||
/* Typical record cash */
|
||||
#define RECORD_CACHE_SIZE (uint) (64*1024-MALLOC_OVERHEAD)
|
||||
/* Typical key cash */
|
||||
#define KEY_CACHE_SIZE (uint) (8*1024*1024)
|
||||
/* Default size of a key cache block */
|
||||
#define KEY_CACHE_BLOCK_SIZE (uint) 1024
|
||||
|
||||
|
||||
/* Some defines of functions for portability */
|
||||
|
||||
#if (_WIN32)
|
||||
#if !defined(_WIN64)
|
||||
inline double my_ulonglong2double(unsigned long long value)
|
||||
{
|
||||
long long nr=(long long) value;
|
||||
if (nr >= 0)
|
||||
return (double) nr;
|
||||
return (18446744073709551616.0 + (double) nr);
|
||||
}
|
||||
#define ulonglong2double my_ulonglong2double
|
||||
#define my_off_t2double my_ulonglong2double
|
||||
#endif /* _WIN64 */
|
||||
inline unsigned long long my_double2ulonglong(double d)
|
||||
{
|
||||
double t= d - (double) 0x8000000000000000ULL;
|
||||
|
||||
if (t >= 0)
|
||||
return ((unsigned long long) t) + 0x8000000000000000ULL;
|
||||
return (unsigned long long) d;
|
||||
}
|
||||
#define double2ulonglong my_double2ulonglong
|
||||
#endif /* _WIN32 */
|
||||
|
||||
#ifndef ulonglong2double
|
||||
#define ulonglong2double(A) ((double) (ulonglong) (A))
|
||||
#define my_off_t2double(A) ((double) (my_off_t) (A))
|
||||
#endif
|
||||
#ifndef double2ulonglong
|
||||
#define double2ulonglong(A) ((ulonglong) (double) (A))
|
||||
#endif
|
||||
|
||||
#define INT_MIN64 (~0x7FFFFFFFFFFFFFFFLL)
|
||||
#define INT_MAX64 0x7FFFFFFFFFFFFFFFLL
|
||||
#define INT_MIN32 (~0x7FFFFFFFL)
|
||||
#define INT_MAX32 0x7FFFFFFFL
|
||||
#define UINT_MAX32 0xFFFFFFFFL
|
||||
#define INT_MIN24 (~0x007FFFFF)
|
||||
#define INT_MAX24 0x007FFFFF
|
||||
#define UINT_MAX24 0x00FFFFFF
|
||||
#define INT_MIN16 (~0x7FFF)
|
||||
#define INT_MAX16 0x7FFF
|
||||
#define UINT_MAX16 0xFFFF
|
||||
#define INT_MIN8 (~0x7F)
|
||||
#define INT_MAX8 0x7F
|
||||
#define UINT_MAX8 0xFF
|
||||
|
||||
#ifndef SIZE_T_MAX
|
||||
#define SIZE_T_MAX (~((size_t) 0))
|
||||
#endif
|
||||
|
||||
// Our ifdef trickery for my_isfinite does not work with gcc/solaris unless we:
|
||||
#ifdef HAVE_IEEEFP_H
|
||||
#include <ieeefp.h>
|
||||
#endif
|
||||
|
||||
#if (__cplusplus >= 201103L)
|
||||
/* For C++11 use the new std functions rather than C99 macros. */
|
||||
#include <cmath>
|
||||
#define my_isfinite(X) std::isfinite(X)
|
||||
#define my_isnan(X) std::isnan(X)
|
||||
#define my_isinf(X) std::isinf(X)
|
||||
#else
|
||||
#ifdef HAVE_LLVM_LIBCPP /* finite is deprecated in libc++ */
|
||||
#define my_isfinite(X) isfinite(X)
|
||||
#elif defined _WIN32
|
||||
#define my_isfinite(X) _finite(X)
|
||||
#else
|
||||
#define my_isfinite(X) finite(X)
|
||||
#endif
|
||||
#define my_isnan(X) isnan(X)
|
||||
#ifdef HAVE_ISINF
|
||||
/* System-provided isinf() is available and safe to use */
|
||||
#define my_isinf(X) isinf(X)
|
||||
#else /* !HAVE_ISINF */
|
||||
#define my_isinf(X) (!my_isfinite(X) && !my_isnan(X))
|
||||
#endif
|
||||
#endif /* __cplusplus >= 201103L */
|
||||
|
||||
/*
|
||||
Max size that must be added to a so that we know Size to make
|
||||
adressable obj.
|
||||
*/
|
||||
#if SIZEOF_CHARP == 4
|
||||
typedef long my_ptrdiff_t;
|
||||
#else
|
||||
typedef long long my_ptrdiff_t;
|
||||
#endif
|
||||
|
||||
#define MY_ALIGN(A,L) (((A) + (L) - 1) & ~((L) - 1))
|
||||
#define ALIGN_SIZE(A) MY_ALIGN((A),sizeof(double))
|
||||
/* Size to make adressable obj. */
|
||||
#define ADD_TO_PTR(ptr,size,type) (type) ((uchar*) (ptr)+size)
|
||||
#define PTR_BYTE_DIFF(A,B) (my_ptrdiff_t) ((uchar*) (A) - (uchar*) (B))
|
||||
|
||||
/*
|
||||
Custom version of standard offsetof() macro which can be used to get
|
||||
offsets of members in class for non-POD types (according to the current
|
||||
version of C++ standard offsetof() macro can't be used in such cases and
|
||||
attempt to do so causes warnings to be emitted, OTOH in many cases it is
|
||||
still OK to assume that all instances of the class has the same offsets
|
||||
for the same members).
|
||||
|
||||
This is temporary solution which should be removed once File_parser class
|
||||
and related routines are refactored.
|
||||
*/
|
||||
|
||||
#define my_offsetof(TYPE, MEMBER) \
|
||||
((size_t)((char *)&(((TYPE *)0x10)->MEMBER) - (char*)0x10))
|
||||
|
||||
#define NullS (char *) 0
|
||||
|
||||
#ifdef _WIN32
|
||||
#define STDCALL __stdcall
|
||||
#else
|
||||
#define STDCALL
|
||||
#endif
|
||||
|
||||
/* Typdefs for easyier portability */
|
||||
|
||||
typedef unsigned char uchar; /* Short for unsigned char */
|
||||
typedef signed char int8; /* Signed integer >= 8 bits */
|
||||
typedef unsigned char uint8; /* Unsigned integer >= 8 bits */
|
||||
typedef short int16;
|
||||
typedef unsigned short uint16;
|
||||
#if SIZEOF_INT == 4
|
||||
typedef int int32;
|
||||
typedef unsigned int uint32;
|
||||
#elif SIZEOF_LONG == 4
|
||||
typedef long int32;
|
||||
typedef unsigned long uint32;
|
||||
#else
|
||||
#error Neither int or long is of 4 bytes width
|
||||
#endif
|
||||
|
||||
#if !defined(HAVE_ULONG)
|
||||
typedef unsigned long ulong; /* Short for unsigned long */
|
||||
#endif
|
||||
/*
|
||||
Using [unsigned] long long is preferable as [u]longlong because we use
|
||||
[unsigned] long long unconditionally in many places,
|
||||
for example in constants with [U]LL suffix.
|
||||
*/
|
||||
typedef unsigned long long int ulonglong; /* ulong or unsigned long long */
|
||||
typedef long long int longlong;
|
||||
typedef longlong int64;
|
||||
typedef ulonglong uint64;
|
||||
|
||||
#if defined (_WIN32)
|
||||
typedef unsigned __int64 my_ulonglong;
|
||||
#else
|
||||
typedef unsigned long long my_ulonglong;
|
||||
#endif
|
||||
|
||||
#if SIZEOF_CHARP == SIZEOF_INT
|
||||
typedef int intptr;
|
||||
#elif SIZEOF_CHARP == SIZEOF_LONG
|
||||
typedef long intptr;
|
||||
#elif SIZEOF_CHARP == SIZEOF_LONG_LONG
|
||||
typedef long long intptr;
|
||||
#else
|
||||
#error sizeof(void *) is neither sizeof(int) nor sizeof(long) nor sizeof(long long)
|
||||
#endif
|
||||
|
||||
#define MY_ERRPTR ((void*)(intptr)1)
|
||||
|
||||
#if defined(_WIN32)
|
||||
typedef unsigned long long my_off_t;
|
||||
typedef unsigned long long os_off_t;
|
||||
#else
|
||||
typedef off_t os_off_t;
|
||||
#if SIZEOF_OFF_T > 4
|
||||
typedef ulonglong my_off_t;
|
||||
#else
|
||||
typedef unsigned long my_off_t;
|
||||
#endif
|
||||
#endif /*_WIN32*/
|
||||
#define MY_FILEPOS_ERROR (~(my_off_t) 0)
|
||||
|
||||
/*
|
||||
TODO Convert these to use Bitmap class.
|
||||
*/
|
||||
typedef ulonglong table_map; /* Used for table bits in join */
|
||||
typedef ulonglong nesting_map; /* Used for flags of nesting constructs */
|
||||
|
||||
#if defined(_WIN32)
|
||||
#define socket_errno WSAGetLastError()
|
||||
#define SOCKET_EINTR WSAEINTR
|
||||
#define SOCKET_EAGAIN WSAEINPROGRESS
|
||||
#define SOCKET_EWOULDBLOCK WSAEWOULDBLOCK
|
||||
#define SOCKET_EADDRINUSE WSAEADDRINUSE
|
||||
#define SOCKET_ETIMEDOUT WSAETIMEDOUT
|
||||
#define SOCKET_ECONNRESET WSAECONNRESET
|
||||
#define SOCKET_ENFILE ENFILE
|
||||
#define SOCKET_EMFILE EMFILE
|
||||
#else /* Unix */
|
||||
#define socket_errno errno
|
||||
#define closesocket(A) close(A)
|
||||
#define SOCKET_EINTR EINTR
|
||||
#define SOCKET_EAGAIN EAGAIN
|
||||
#define SOCKET_EWOULDBLOCK EWOULDBLOCK
|
||||
#define SOCKET_EADDRINUSE EADDRINUSE
|
||||
#define SOCKET_ETIMEDOUT ETIMEDOUT
|
||||
#define SOCKET_ECONNRESET ECONNRESET
|
||||
#define SOCKET_ENFILE ENFILE
|
||||
#define SOCKET_EMFILE EMFILE
|
||||
#endif
|
||||
|
||||
typedef int myf; /* Type of MyFlags in my_funcs */
|
||||
typedef char my_bool; /* Small bool */
|
||||
|
||||
/* Macros for converting *constants* to the right type */
|
||||
#define MYF(v) (myf) (v)
|
||||
|
||||
/* Some helper macros */
|
||||
#define YESNO(X) ((X) ? "yes" : "no")
|
||||
|
||||
#define MY_HOW_OFTEN_TO_WRITE 1000 /* How often we want info on screen */
|
||||
|
||||
#include <my_byteorder.h>
|
||||
|
||||
#ifdef HAVE_CHARSET_utf8
|
||||
#define MYSQL_UNIVERSAL_CLIENT_CHARSET "utf8"
|
||||
#else
|
||||
#define MYSQL_UNIVERSAL_CLIENT_CHARSET MYSQL_DEFAULT_CHARSET_NAME
|
||||
#endif
|
||||
|
||||
#if defined(_WIN32)
|
||||
#define dlsym(lib, name) (void*)GetProcAddress((HMODULE)lib, name)
|
||||
#define dlopen(libname, unused) LoadLibraryEx(libname, NULL, 0)
|
||||
#define dlclose(lib) FreeLibrary((HMODULE)lib)
|
||||
#ifndef HAVE_DLOPEN
|
||||
#define HAVE_DLOPEN
|
||||
#endif
|
||||
#define DLERROR_GENERATE(errmsg, error_number) \
|
||||
char win_errormsg[2048]; \
|
||||
if(FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, \
|
||||
0, error_number, 0, win_errormsg, 2048, NULL)) \
|
||||
{ \
|
||||
char *ptr; \
|
||||
for (ptr= &win_errormsg[0] + strlen(win_errormsg) - 1; \
|
||||
ptr >= &win_errormsg[0] && strchr("\r\n\t\0x20", *ptr); \
|
||||
ptr--) \
|
||||
*ptr= 0; \
|
||||
errmsg= win_errormsg; \
|
||||
} \
|
||||
else \
|
||||
errmsg= ""
|
||||
#define dlerror() ""
|
||||
#define dlopen_errno GetLastError()
|
||||
|
||||
#else /* _WIN32 */
|
||||
#define DLERROR_GENERATE(errmsg, error_number) errmsg= dlerror()
|
||||
#define dlopen_errno errno
|
||||
#endif /* _WIN32 */
|
||||
|
||||
/* Length of decimal number represented by INT32. */
|
||||
#define MY_INT32_NUM_DECIMAL_DIGITS 11U
|
||||
|
||||
/* Length of decimal number represented by INT64. */
|
||||
#define MY_INT64_NUM_DECIMAL_DIGITS 21U
|
||||
|
||||
/* Define some useful general macros (should be done after all headers). */
|
||||
#define MY_MAX(a, b) ((a) > (b) ? (a) : (b))
|
||||
#define MY_MIN(a, b) ((a) < (b) ? (a) : (b))
|
||||
|
||||
#if !defined(__cplusplus) && !defined(bool)
|
||||
#define bool In_C_you_should_use_my_bool_instead()
|
||||
#endif
|
||||
|
||||
/*
|
||||
MYSQL_PLUGIN_IMPORT macro is used to export mysqld data
|
||||
(i.e variables) for usage in storage engine loadable plugins.
|
||||
Outside of Windows, it is dummy.
|
||||
*/
|
||||
#if (defined(_WIN32) && defined(MYSQL_DYNAMIC_PLUGIN))
|
||||
#define MYSQL_PLUGIN_IMPORT __declspec(dllimport)
|
||||
#else
|
||||
#define MYSQL_PLUGIN_IMPORT
|
||||
#endif
|
||||
|
||||
#include <my_dbug.h>
|
||||
|
||||
#ifdef EMBEDDED_LIBRARY
|
||||
#define NO_EMBEDDED_ACCESS_CHECKS
|
||||
/* Things we don't need in the embedded version of MySQL */
|
||||
#undef HAVE_OPENSSL
|
||||
#endif /* EMBEDDED_LIBRARY */
|
||||
|
||||
|
||||
enum loglevel {
|
||||
ERROR_LEVEL= 0,
|
||||
WARNING_LEVEL= 1,
|
||||
INFORMATION_LEVEL= 2
|
||||
};
|
||||
|
||||
|
||||
#ifdef _WIN32
|
||||
/****************************************************************************
|
||||
** Replacements for localtime_r and gmtime_r
|
||||
****************************************************************************/
|
||||
|
||||
static inline struct tm *localtime_r(const time_t *timep, struct tm *tmp)
|
||||
{
|
||||
localtime_s(tmp, timep);
|
||||
return tmp;
|
||||
}
|
||||
|
||||
static inline struct tm *gmtime_r(const time_t *clock, struct tm *res)
|
||||
{
|
||||
gmtime_s(res, clock);
|
||||
return res;
|
||||
}
|
||||
#endif /* _WIN32 */
|
||||
|
||||
#ifndef HAVE_STRUCT_TIMESPEC /* Windows before VS2015 */
|
||||
/*
|
||||
Declare a union to make sure FILETIME is properly aligned
|
||||
so it can be used directly as a 64 bit value. The value
|
||||
stored is in 100ns units.
|
||||
*/
|
||||
union ft64 {
|
||||
FILETIME ft;
|
||||
__int64 i64;
|
||||
};
|
||||
|
||||
struct timespec {
|
||||
union ft64 tv;
|
||||
/* The max timeout value in millisecond for native_cond_timedwait */
|
||||
long max_timeout_msec;
|
||||
};
|
||||
|
||||
#endif /* !HAVE_STRUCT_TIMESPEC */
|
||||
|
||||
C_MODE_START
|
||||
extern ulonglong my_getsystime(void);
|
||||
C_MODE_END
|
||||
|
||||
static inline void set_timespec_nsec(struct timespec *abstime, ulonglong nsec)
|
||||
{
|
||||
#ifdef HAVE_STRUCT_TIMESPEC
|
||||
ulonglong now= my_getsystime() + (nsec / 100);
|
||||
ulonglong tv_sec= now / 10000000ULL;
|
||||
#if SIZEOF_TIME_T < SIZEOF_LONG_LONG
|
||||
/* Ensure that the number of seconds don't overflow. */
|
||||
tv_sec= MY_MIN(tv_sec, ((ulonglong)INT_MAX32));
|
||||
#endif
|
||||
abstime->tv_sec= (time_t)tv_sec;
|
||||
abstime->tv_nsec= (now % 10000000ULL) * 100 + (nsec % 100);
|
||||
#else /* !HAVE_STRUCT_TIMESPEC */
|
||||
ulonglong max_timeout_msec= (nsec / 1000000);
|
||||
union ft64 tv;
|
||||
GetSystemTimeAsFileTime(&tv.ft);
|
||||
abstime->tv.i64= tv.i64 + (__int64)(nsec / 100);
|
||||
#if SIZEOF_LONG < SIZEOF_LONG_LONG
|
||||
/* Ensure that the msec value doesn't overflow. */
|
||||
max_timeout_msec= MY_MIN(max_timeout_msec, ((ulonglong)INT_MAX32));
|
||||
#endif
|
||||
abstime->max_timeout_msec= (long)max_timeout_msec;
|
||||
#endif /* !HAVE_STRUCT_TIMESPEC */
|
||||
}
|
||||
|
||||
static inline void set_timespec(struct timespec *abstime, ulonglong sec)
|
||||
{
|
||||
set_timespec_nsec(abstime, sec * 1000000000ULL);
|
||||
}
|
||||
|
||||
/**
|
||||
Compare two timespec structs.
|
||||
|
||||
@retval 1 If ts1 ends after ts2.
|
||||
@retval -1 If ts1 ends before ts2.
|
||||
@retval 0 If ts1 is equal to ts2.
|
||||
*/
|
||||
static inline int cmp_timespec(struct timespec *ts1, struct timespec *ts2)
|
||||
{
|
||||
#ifdef HAVE_STRUCT_TIMESPEC
|
||||
if (ts1->tv_sec > ts2->tv_sec ||
|
||||
(ts1->tv_sec == ts2->tv_sec && ts1->tv_nsec > ts2->tv_nsec))
|
||||
return 1;
|
||||
if (ts1->tv_sec < ts2->tv_sec ||
|
||||
(ts1->tv_sec == ts2->tv_sec && ts1->tv_nsec < ts2->tv_nsec))
|
||||
return -1;
|
||||
#else
|
||||
if (ts1->tv.i64 > ts2->tv.i64)
|
||||
return 1;
|
||||
if (ts1->tv.i64 < ts2->tv.i64)
|
||||
return -1;
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline ulonglong diff_timespec(struct timespec *ts1, struct timespec *ts2)
|
||||
{
|
||||
#ifdef HAVE_STRUCT_TIMESPEC
|
||||
return (ts1->tv_sec - ts2->tv_sec) * 1000000000ULL +
|
||||
ts1->tv_nsec - ts2->tv_nsec;
|
||||
#else
|
||||
return (ts1->tv.i64 - ts2->tv.i64) * 100;
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
typedef int MY_MODE;
|
||||
#else
|
||||
typedef mode_t MY_MODE;
|
||||
#endif /* _WIN32 */
|
||||
|
||||
/* File permissions */
|
||||
#define USER_READ (1L << 0)
|
||||
#define USER_WRITE (1L << 1)
|
||||
#define USER_EXECUTE (1L << 2)
|
||||
#define GROUP_READ (1L << 3)
|
||||
#define GROUP_WRITE (1L << 4)
|
||||
#define GROUP_EXECUTE (1L << 5)
|
||||
#define OTHERS_READ (1L << 6)
|
||||
#define OTHERS_WRITE (1L << 7)
|
||||
#define OTHERS_EXECUTE (1L << 8)
|
||||
#define USER_RWX USER_READ | USER_WRITE | USER_EXECUTE
|
||||
#define GROUP_RWX GROUP_READ | GROUP_WRITE | GROUP_EXECUTE
|
||||
#define OTHERS_RWX OTHERS_READ | OTHERS_WRITE | OTHERS_EXECUTE
|
||||
|
||||
/* Defaults */
|
||||
#define DEFAULT_SSL_CA_CERT "ca.pem"
|
||||
#define DEFAULT_SSL_CA_KEY "ca-key.pem"
|
||||
#define DEFAULT_SSL_SERVER_CERT "server-cert.pem"
|
||||
#define DEFAULT_SSL_SERVER_KEY "server-key.pem"
|
||||
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#define strcasecmp _stricmp
|
||||
#endif
|
||||
#endif // MY_GLOBAL_INCLUDED
|
|
@ -25,28 +25,33 @@
|
|||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
|
||||
|
||||
#ifndef MY_LIST_INCLUDED
|
||||
#define MY_LIST_INCLUDED
|
||||
#ifndef _list_h_
|
||||
#define _list_h_
|
||||
|
||||
/**
|
||||
@file include/my_list.h
|
||||
*/
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct LIST {
|
||||
struct LIST *prev, *next;
|
||||
typedef struct st_list {
|
||||
struct st_list *prev,*next;
|
||||
void *data;
|
||||
} LIST;
|
||||
|
||||
typedef int (*list_walk_action)(void *, void *);
|
||||
typedef int (*list_walk_action)(void *,void *);
|
||||
|
||||
extern LIST *list_add(LIST *root, LIST *element);
|
||||
extern LIST *list_delete(LIST *root, LIST *element);
|
||||
extern LIST *list_cons(void *data, LIST *root);
|
||||
extern LIST *list_add(LIST *root,LIST *element);
|
||||
extern LIST *list_delete(LIST *root,LIST *element);
|
||||
extern LIST *list_cons(void *data,LIST *root);
|
||||
extern LIST *list_reverse(LIST *root);
|
||||
extern void list_free(LIST *root, unsigned int free_data);
|
||||
extern void list_free(LIST *root,unsigned int free_data);
|
||||
extern unsigned int list_length(LIST *);
|
||||
extern int list_walk(LIST *, list_walk_action action, unsigned char *argument);
|
||||
extern int list_walk(LIST *,list_walk_action action,unsigned char * argument);
|
||||
|
||||
#define list_rest(a) ((a)->next)
|
||||
#define list_push(a,b) (a)=list_cons((b),(a))
|
||||
#define list_pop(A) {LIST *old=(A); (A)=list_delete(old,old); my_free(old); }
|
||||
|
||||
#endif // MY_LIST_INCLUDED
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
|
@ -0,0 +1,992 @@
|
|||
/* Copyright (c) 2000, 2022, Oracle and/or its affiliates.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License, version 2.0,
|
||||
as published by the Free Software Foundation.
|
||||
|
||||
This program is also distributed with certain software (including
|
||||
but not limited to OpenSSL) that is licensed under separate terms,
|
||||
as designated in a particular file or component or in included license
|
||||
documentation. The authors of MySQL hereby grant you an additional
|
||||
permission to link the program and your derivative works with the
|
||||
separately licensed software that they have included with MySQL.
|
||||
|
||||
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, version 2.0, 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 St, Fifth Floor, Boston, MA 02110-1301 USA */
|
||||
|
||||
#ifndef _my_sys_h
|
||||
#define _my_sys_h
|
||||
|
||||
#include "my_global.h" /* C_MODE_START, C_MODE_END */
|
||||
#include "m_ctype.h" /* for CHARSET_INFO */
|
||||
|
||||
#include "my_thread.h" /* Needed for psi.h */
|
||||
#include "mysql/psi/psi.h"
|
||||
#include "mysql/service_mysql_alloc.h"
|
||||
#include "mysql/psi/mysql_memory.h"
|
||||
#include "mysql/psi/mysql_thread.h"
|
||||
|
||||
#ifdef HAVE_ALLOCA_H
|
||||
#include <alloca.h>
|
||||
#endif
|
||||
#ifdef _WIN32
|
||||
#include <malloc.h>
|
||||
#endif
|
||||
#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#include <sys/stat.h>
|
||||
|
||||
C_MODE_START
|
||||
|
||||
#ifdef HAVE_VALGRIND
|
||||
# include <valgrind/valgrind.h>
|
||||
# define MEM_MALLOCLIKE_BLOCK(p1, p2, p3, p4) VALGRIND_MALLOCLIKE_BLOCK(p1, p2, p3, p4)
|
||||
# define MEM_FREELIKE_BLOCK(p1, p2) VALGRIND_FREELIKE_BLOCK(p1, p2)
|
||||
# include <valgrind/memcheck.h>
|
||||
# define MEM_UNDEFINED(a,len) VALGRIND_MAKE_MEM_UNDEFINED(a,len)
|
||||
# define MEM_NOACCESS(a,len) VALGRIND_MAKE_MEM_NOACCESS(a,len)
|
||||
# define MEM_CHECK_ADDRESSABLE(a,len) VALGRIND_CHECK_MEM_IS_ADDRESSABLE(a,len)
|
||||
#else /* HAVE_VALGRIND */
|
||||
# define MEM_MALLOCLIKE_BLOCK(p1, p2, p3, p4) do {} while (0)
|
||||
# define MEM_FREELIKE_BLOCK(p1, p2) do {} while (0)
|
||||
# define MEM_UNDEFINED(a,len) ((void) 0)
|
||||
# define MEM_NOACCESS(a,len) ((void) 0)
|
||||
# define MEM_CHECK_ADDRESSABLE(a,len) ((void) 0)
|
||||
#endif /* HAVE_VALGRIND */
|
||||
|
||||
#include <typelib.h>
|
||||
|
||||
#define MY_INIT(name) { my_progname= name; my_init(); }
|
||||
|
||||
/**
|
||||
Max length of an error message generated by mysys utilities.
|
||||
Some mysys functions produce error messages. These mostly go
|
||||
to stderr.
|
||||
This constant defines the size of the buffer used to format
|
||||
the message. It should be kept in sync with MYSQL_ERRMSG_SIZE,
|
||||
since sometimes mysys errors are stored in the server diagnostics
|
||||
area, and we would like to avoid unexpected truncation.
|
||||
*/
|
||||
#define MYSYS_ERRMSG_SIZE (512)
|
||||
#define MYSYS_STRERROR_SIZE (128)
|
||||
|
||||
#define MY_FILE_ERROR ((size_t) -1)
|
||||
|
||||
/* General bitmaps for my_func's */
|
||||
#define MY_FFNF 1 /* Fatal if file not found */
|
||||
#define MY_FNABP 2 /* Fatal if not all bytes read/writen */
|
||||
#define MY_NABP 4 /* Error if not all bytes read/writen */
|
||||
#define MY_FAE 8 /* Fatal if any error */
|
||||
#define MY_WME 16 /* Write message on error */
|
||||
#define MY_WAIT_IF_FULL 32 /* Wait and try again if disk full error */
|
||||
#define MY_IGNORE_BADFD 32 /* my_sync: ignore 'bad descriptor' errors */
|
||||
#define MY_SYNC_DIR 8192 /* my_create/delete/rename: sync directory */
|
||||
#define MY_UNUSED 64 /* Unused (was support for RAID) */
|
||||
#define MY_FULL_IO 512 /* For my_read - loop intil I/O is complete */
|
||||
#define MY_DONT_CHECK_FILESIZE 128 /* Option to init_io_cache() */
|
||||
#define MY_LINK_WARNING 32 /* my_redel() gives warning if links */
|
||||
#define MY_COPYTIME 64 /* my_redel() copys time */
|
||||
#define MY_DELETE_OLD 256 /* my_create_with_symlink() */
|
||||
#define MY_RESOLVE_LINK 128 /* my_realpath(); Only resolve links */
|
||||
#define MY_HOLD_ORIGINAL_MODES 128 /* my_copy() holds to file modes */
|
||||
#define MY_REDEL_MAKE_BACKUP 256
|
||||
#define MY_REDEL_NO_COPY_STAT 512 /* my_redel() doesn't call my_copystat() */
|
||||
#define MY_SEEK_NOT_DONE 32 /* my_lock may have to do a seek */
|
||||
#define MY_DONT_WAIT 64 /* my_lock() don't wait if can't lock */
|
||||
#define MY_ZEROFILL 32 /* my_malloc(), fill array with zero */
|
||||
#define MY_ALLOW_ZERO_PTR 64 /* my_realloc() ; zero ptr -> malloc */
|
||||
#define MY_FREE_ON_ERROR 128 /* my_realloc() ; Free old ptr on error */
|
||||
#define MY_HOLD_ON_ERROR 256 /* my_realloc() ; Return old ptr on error */
|
||||
#define MY_DONT_OVERWRITE_FILE 1024 /* my_copy: Don't overwrite file */
|
||||
#define MY_THREADSAFE 2048 /* my_seek(): lock fd mutex */
|
||||
#define MY_SYNC 4096 /* my_copy(): sync dst file */
|
||||
|
||||
#define MYF_RW MYF(MY_WME+MY_NABP) /* For my_read & my_write */
|
||||
|
||||
#define MY_CHECK_ERROR 1 /* Params to my_end; Check open-close */
|
||||
#define MY_GIVE_INFO 2 /* Give time info about process*/
|
||||
#define MY_DONT_FREE_DBUG 4 /* Do not call DBUG_END() in my_end() */
|
||||
|
||||
/* Flags for my_error() */
|
||||
#define ME_BELL 4 /* DEPRECATED: Ring bell then printing message */
|
||||
#define ME_ERRORLOG 64 /* Write the error message to error log */
|
||||
#define ME_FATALERROR 1024 /* Fatal statement error */
|
||||
|
||||
/* Bits in last argument to fn_format */
|
||||
#define MY_REPLACE_DIR 1 /* replace dir in name with 'dir' */
|
||||
#define MY_REPLACE_EXT 2 /* replace extension with 'ext' */
|
||||
#define MY_UNPACK_FILENAME 4 /* Unpack name (~ -> home) */
|
||||
#define MY_PACK_FILENAME 8 /* Pack name (home -> ~) */
|
||||
#define MY_RESOLVE_SYMLINKS 16 /* Resolve all symbolic links */
|
||||
#define MY_RETURN_REAL_PATH 32 /* return full path for file */
|
||||
#define MY_SAFE_PATH 64 /* Return NULL if too long path */
|
||||
#define MY_RELATIVE_PATH 128 /* name is relative to 'dir' */
|
||||
#define MY_APPEND_EXT 256 /* add 'ext' as additional extension*/
|
||||
|
||||
|
||||
/* My seek flags */
|
||||
#define MY_SEEK_SET 0
|
||||
#define MY_SEEK_CUR 1
|
||||
#define MY_SEEK_END 2
|
||||
|
||||
/* Some constants */
|
||||
#define MY_WAIT_FOR_USER_TO_FIX_PANIC 60 /* in seconds */
|
||||
#define MY_WAIT_GIVE_USER_A_MESSAGE 10 /* Every 10 times of prev */
|
||||
#define MIN_COMPRESS_LENGTH 50 /* Don't compress small bl. */
|
||||
#define DFLT_INIT_HITS 3
|
||||
|
||||
/* root_alloc flags */
|
||||
#define MY_KEEP_PREALLOC 1
|
||||
#define MY_MARK_BLOCKS_FREE 2 /* move used to free list and reuse them */
|
||||
|
||||
/* Internal error numbers (for assembler functions) */
|
||||
#define MY_ERRNO_EDOM 33
|
||||
#define MY_ERRNO_ERANGE 34
|
||||
|
||||
/* Bits for get_date timeflag */
|
||||
#define GETDATE_DATE_TIME 1
|
||||
#define GETDATE_SHORT_DATE 2
|
||||
#define GETDATE_HHMMSSTIME 4
|
||||
#define GETDATE_GMT 8
|
||||
#define GETDATE_FIXEDLENGTH 16
|
||||
#define GETDATE_T_DELIMITER 32
|
||||
#define GETDATE_SHORT_DATE_FULL_YEAR 64
|
||||
|
||||
/* defines when allocating data */
|
||||
extern void *my_multi_malloc(PSI_memory_key key, myf flags, ...);
|
||||
|
||||
/*
|
||||
Switch to my_malloc() if the memory block to be allocated is bigger than
|
||||
max_alloca_sz.
|
||||
*/
|
||||
extern PSI_memory_key key_memory_max_alloca;
|
||||
#define my_safe_alloca(size, max_alloca_sz) ((size <= max_alloca_sz) ? \
|
||||
my_alloca(size) : \
|
||||
my_malloc(key_memory_max_alloca, size, MYF(0)))
|
||||
#define my_safe_afree(ptr, size, max_alloca_sz) if (size > max_alloca_sz) \
|
||||
my_free(ptr)
|
||||
|
||||
#if !defined(NDEBUG) || defined(HAVE_VALGRIND)
|
||||
/**
|
||||
Put bad content in memory to be sure it will segfault if dereferenced.
|
||||
With Valgrind, verify that memory is addressable, and mark it undefined.
|
||||
We cache value of B because if B is expression which depends on A, memset()
|
||||
trashes value of B.
|
||||
*/
|
||||
#define TRASH(A,B) do { \
|
||||
void *p = (A); \
|
||||
const size_t l= (B); \
|
||||
MEM_CHECK_ADDRESSABLE(A, l); \
|
||||
memset(p, 0x8F, l); \
|
||||
MEM_UNDEFINED(A, l); \
|
||||
} while (0)
|
||||
#else
|
||||
#define TRASH(A,B) do {} while(0)
|
||||
#endif
|
||||
#if defined(ENABLED_DEBUG_SYNC)
|
||||
extern void (*debug_sync_C_callback_ptr)(const char *, size_t);
|
||||
#define DEBUG_SYNC_C(_sync_point_name_) do { \
|
||||
if (debug_sync_C_callback_ptr != NULL) \
|
||||
(*debug_sync_C_callback_ptr)(STRING_WITH_LEN(_sync_point_name_)); } \
|
||||
while(0)
|
||||
#define DEBUG_SYNC_C_IF_THD(thd, _sync_point_name_) do { \
|
||||
if (debug_sync_C_callback_ptr != NULL && thd) \
|
||||
(*debug_sync_C_callback_ptr)(STRING_WITH_LEN(_sync_point_name_)); } \
|
||||
while(0)
|
||||
#else
|
||||
#define DEBUG_SYNC_C(_sync_point_name_)
|
||||
#define DEBUG_SYNC_C_IF_THD(thd, _sync_point_name_)
|
||||
#endif /* defined(ENABLED_DEBUG_SYNC) */
|
||||
|
||||
#ifdef HAVE_LINUX_LARGE_PAGES
|
||||
extern uint my_get_large_page_size(void);
|
||||
extern uchar * my_large_malloc(PSI_memory_key key, size_t size, myf my_flags);
|
||||
extern void my_large_free(uchar *ptr);
|
||||
extern my_bool my_use_large_pages;
|
||||
extern uint my_large_page_size;
|
||||
#else
|
||||
#define my_get_large_page_size() (0)
|
||||
#define my_large_malloc(A,B,C) my_malloc((A),(B),(C))
|
||||
#define my_large_free(A) my_free((A))
|
||||
#endif /* HAVE_LINUX_LARGE_PAGES */
|
||||
|
||||
#define my_alloca(SZ) alloca((size_t) (SZ))
|
||||
|
||||
#include <errno.h> /* errno is a define */
|
||||
|
||||
extern char *home_dir; /* Home directory for user */
|
||||
extern const char *my_progname; /* program-name (printed in errors) */
|
||||
extern char curr_dir[]; /* Current directory for user */
|
||||
extern void (*error_handler_hook)(uint my_err, const char *str,myf MyFlags);
|
||||
extern void (*fatal_error_handler_hook)(uint my_err, const char *str,
|
||||
myf MyFlags);
|
||||
extern void (*local_message_hook)(enum loglevel ll,
|
||||
const char *format, va_list args);
|
||||
extern uint my_file_limit;
|
||||
extern MYSQL_PLUGIN_IMPORT ulong my_thread_stack_size;
|
||||
|
||||
/*
|
||||
Hooks for reporting execution stage information. The server implementation
|
||||
of these will also set THD::current_cond/current_mutex.
|
||||
By having hooks, we avoid direct dependencies on server code.
|
||||
*/
|
||||
extern void (*enter_cond_hook)(void *opaque_thd,
|
||||
mysql_cond_t *cond,
|
||||
mysql_mutex_t *mutex,
|
||||
const PSI_stage_info *stage,
|
||||
PSI_stage_info *old_stage,
|
||||
const char *src_function,
|
||||
const char *src_file,
|
||||
int src_line);
|
||||
|
||||
extern void (*exit_cond_hook)(void *opaque_thd,
|
||||
const PSI_stage_info *stage,
|
||||
const char *src_function,
|
||||
const char *src_file,
|
||||
int src_line);
|
||||
|
||||
/*
|
||||
Hook for checking if the thread has been killed.
|
||||
*/
|
||||
extern int (*is_killed_hook)(const void *opaque_thd);
|
||||
|
||||
/* charsets */
|
||||
#define MY_ALL_CHARSETS_SIZE 2048
|
||||
extern MYSQL_PLUGIN_IMPORT CHARSET_INFO *default_charset_info;
|
||||
extern MYSQL_PLUGIN_IMPORT CHARSET_INFO *all_charsets[MY_ALL_CHARSETS_SIZE];
|
||||
extern CHARSET_INFO compiled_charsets[];
|
||||
|
||||
/* statistics */
|
||||
extern ulong my_file_opened,my_stream_opened, my_tmp_file_created;
|
||||
extern ulong my_file_total_opened;
|
||||
extern my_bool my_init_done;
|
||||
|
||||
extern MYSQL_PLUGIN_IMPORT int my_umask; /* Default creation mask */
|
||||
extern int my_umask_dir;
|
||||
|
||||
extern ulong my_default_record_cache_size;
|
||||
extern my_bool my_disable_locking,
|
||||
my_enable_symlinks;
|
||||
extern char wild_many,wild_one,wild_prefix;
|
||||
extern const char *charsets_dir;
|
||||
|
||||
enum cache_type
|
||||
{
|
||||
TYPE_NOT_SET= 0, READ_CACHE, WRITE_CACHE,
|
||||
SEQ_READ_APPEND /* sequential read or append */,
|
||||
READ_FIFO, READ_NET,WRITE_NET};
|
||||
|
||||
enum flush_type
|
||||
{
|
||||
FLUSH_KEEP, /* flush block and keep it in the cache */
|
||||
FLUSH_RELEASE, /* flush block and remove it from the cache */
|
||||
FLUSH_IGNORE_CHANGED, /* remove block from the cache */
|
||||
/*
|
||||
As my_disable_flush_pagecache_blocks is always 0, the following option
|
||||
is strictly equivalent to FLUSH_KEEP
|
||||
*/
|
||||
FLUSH_FORCE_WRITE
|
||||
};
|
||||
|
||||
enum file_type
|
||||
{
|
||||
UNOPEN = 0, FILE_BY_OPEN, FILE_BY_CREATE, STREAM_BY_FOPEN, STREAM_BY_FDOPEN,
|
||||
FILE_BY_MKSTEMP, FILE_BY_DUP
|
||||
};
|
||||
|
||||
struct st_my_file_info
|
||||
{
|
||||
char *name;
|
||||
#ifdef _WIN32
|
||||
HANDLE fhandle; /* win32 file handle */
|
||||
int oflag; /* open flags, e.g O_APPEND */
|
||||
#endif
|
||||
enum file_type type;
|
||||
};
|
||||
|
||||
extern struct st_my_file_info *my_file_info;
|
||||
|
||||
/* needed for client-only build */
|
||||
#ifndef PSI_FILE_KEY_DEFINED
|
||||
typedef unsigned int PSI_file_key;
|
||||
#define PSI_FILE_KEY_DEFINED
|
||||
#endif
|
||||
|
||||
typedef struct st_dynamic_array
|
||||
{
|
||||
uchar *buffer;
|
||||
uint elements,max_element;
|
||||
uint alloc_increment;
|
||||
uint size_of_element;
|
||||
PSI_memory_key m_psi_key;
|
||||
} DYNAMIC_ARRAY;
|
||||
|
||||
typedef struct st_my_tmpdir
|
||||
{
|
||||
char **list;
|
||||
uint cur, max;
|
||||
mysql_mutex_t mutex;
|
||||
} MY_TMPDIR;
|
||||
|
||||
typedef struct st_dynamic_string
|
||||
{
|
||||
char *str;
|
||||
size_t length,max_length,alloc_increment;
|
||||
} DYNAMIC_STRING;
|
||||
|
||||
struct st_io_cache;
|
||||
typedef int (*IO_CACHE_CALLBACK)(struct st_io_cache*);
|
||||
|
||||
typedef struct st_io_cache_share
|
||||
{
|
||||
mysql_mutex_t mutex; /* To sync on reads into buffer. */
|
||||
mysql_cond_t cond; /* To wait for signals. */
|
||||
mysql_cond_t cond_writer; /* For a synchronized writer. */
|
||||
/* Offset in file corresponding to the first byte of buffer. */
|
||||
my_off_t pos_in_file;
|
||||
/* If a synchronized write cache is the source of the data. */
|
||||
struct st_io_cache *source_cache;
|
||||
uchar *buffer; /* The read buffer. */
|
||||
uchar *read_end; /* Behind last valid byte of buffer. */
|
||||
int running_threads; /* threads not in lock. */
|
||||
int total_threads; /* threads sharing the cache. */
|
||||
int error; /* Last error. */
|
||||
} IO_CACHE_SHARE;
|
||||
|
||||
typedef struct st_io_cache /* Used when cacheing files */
|
||||
{
|
||||
/* Offset in file corresponding to the first byte of uchar* buffer. */
|
||||
my_off_t pos_in_file;
|
||||
/*
|
||||
The offset of end of file for READ_CACHE and WRITE_CACHE.
|
||||
For SEQ_READ_APPEND it the maximum of the actual end of file and
|
||||
the position represented by read_end.
|
||||
*/
|
||||
my_off_t end_of_file;
|
||||
/* Points to current read position in the buffer */
|
||||
uchar *read_pos;
|
||||
/* the non-inclusive boundary in the buffer for the currently valid read */
|
||||
uchar *read_end;
|
||||
uchar *buffer; /* The read buffer */
|
||||
/* Used in ASYNC_IO */
|
||||
uchar *request_pos;
|
||||
|
||||
/* Only used in WRITE caches and in SEQ_READ_APPEND to buffer writes */
|
||||
uchar *write_buffer;
|
||||
/*
|
||||
Only used in SEQ_READ_APPEND, and points to the current read position
|
||||
in the write buffer. Note that reads in SEQ_READ_APPEND caches can
|
||||
happen from both read buffer (uchar* buffer) and write buffer
|
||||
(uchar* write_buffer).
|
||||
*/
|
||||
uchar *append_read_pos;
|
||||
/* Points to current write position in the write buffer */
|
||||
uchar *write_pos;
|
||||
/* The non-inclusive boundary of the valid write area */
|
||||
uchar *write_end;
|
||||
|
||||
/*
|
||||
Current_pos and current_end are convenience variables used by
|
||||
my_b_tell() and other routines that need to know the current offset
|
||||
current_pos points to &write_pos, and current_end to &write_end in a
|
||||
WRITE_CACHE, and &read_pos and &read_end respectively otherwise
|
||||
*/
|
||||
uchar **current_pos, **current_end;
|
||||
|
||||
/*
|
||||
The lock is for append buffer used in SEQ_READ_APPEND cache
|
||||
need mutex copying from append buffer to read buffer.
|
||||
*/
|
||||
mysql_mutex_t append_buffer_lock;
|
||||
/*
|
||||
The following is used when several threads are reading the
|
||||
same file in parallel. They are synchronized on disk
|
||||
accesses reading the cached part of the file asynchronously.
|
||||
It should be set to NULL to disable the feature. Only
|
||||
READ_CACHE mode is supported.
|
||||
*/
|
||||
IO_CACHE_SHARE *share;
|
||||
|
||||
/*
|
||||
A caller will use my_b_read() macro to read from the cache
|
||||
if the data is already in cache, it will be simply copied with
|
||||
memcpy() and internal variables will be accordinging updated with
|
||||
no functions invoked. However, if the data is not fully in the cache,
|
||||
my_b_read() will call read_function to fetch the data. read_function
|
||||
must never be invoked directly.
|
||||
*/
|
||||
int (*read_function)(struct st_io_cache *,uchar *,size_t);
|
||||
/*
|
||||
Same idea as in the case of read_function, except my_b_write() needs to
|
||||
be replaced with my_b_append() for a SEQ_READ_APPEND cache
|
||||
*/
|
||||
int (*write_function)(struct st_io_cache *,const uchar *,size_t);
|
||||
/*
|
||||
Specifies the type of the cache. Depending on the type of the cache
|
||||
certain operations might not be available and yield unpredicatable
|
||||
results. Details to be documented later
|
||||
*/
|
||||
enum cache_type type;
|
||||
/*
|
||||
Callbacks when the actual read I/O happens. These were added and
|
||||
are currently used for binary logging of LOAD DATA INFILE - when a
|
||||
block is read from the file, we create a block create/append event, and
|
||||
when IO_CACHE is closed, we create an end event. These functions could,
|
||||
of course be used for other things
|
||||
*/
|
||||
IO_CACHE_CALLBACK pre_read;
|
||||
IO_CACHE_CALLBACK post_read;
|
||||
IO_CACHE_CALLBACK pre_close;
|
||||
/*
|
||||
Counts the number of times, when we were forced to use disk. We use it to
|
||||
increase the binlog_cache_disk_use and binlog_stmt_cache_disk_use status
|
||||
variables.
|
||||
*/
|
||||
ulong disk_writes;
|
||||
void* arg; /* for use by pre/post_read */
|
||||
char *file_name; /* if used with 'open_cached_file' */
|
||||
char *dir,*prefix;
|
||||
File file; /* file descriptor */
|
||||
PSI_file_key file_key; /* instrumented file key */
|
||||
|
||||
/*
|
||||
seek_not_done is set by my_b_seek() to inform the upcoming read/write
|
||||
operation that a seek needs to be preformed prior to the actual I/O
|
||||
error is 0 if the cache operation was successful, -1 if there was a
|
||||
"hard" error, and the actual number of I/O-ed bytes if the read/write was
|
||||
partial.
|
||||
*/
|
||||
int seek_not_done,error;
|
||||
/* buffer_length is memory size allocated for buffer or write_buffer */
|
||||
size_t buffer_length;
|
||||
/* read_length is the same as buffer_length except when we use async io */
|
||||
size_t read_length;
|
||||
myf myflags; /* Flags used to my_read/my_write */
|
||||
/*
|
||||
alloced_buffer is 1 if the buffer was allocated by init_io_cache() and
|
||||
0 if it was supplied by the user.
|
||||
Currently READ_NET is the only one that will use a buffer allocated
|
||||
somewhere else
|
||||
*/
|
||||
my_bool alloced_buffer;
|
||||
} IO_CACHE;
|
||||
|
||||
typedef int (*qsort2_cmp)(const void *, const void *, const void *);
|
||||
|
||||
/*
|
||||
Subset of struct stat fields filled by stat/lstat/fstat that uniquely
|
||||
identify a file
|
||||
*/
|
||||
typedef struct st_file_id
|
||||
{
|
||||
dev_t st_dev;
|
||||
ino_t st_ino;
|
||||
} ST_FILE_ID;
|
||||
|
||||
typedef void (*my_error_reporter)(enum loglevel level, const char *format, ...)
|
||||
MY_ATTRIBUTE((format(printf, 2, 3)));
|
||||
|
||||
extern my_error_reporter my_charset_error_reporter;
|
||||
|
||||
/* defines for mf_iocache */
|
||||
extern PSI_file_key key_file_io_cache;
|
||||
|
||||
/* Test if buffer is inited */
|
||||
#define my_b_clear(info) (info)->buffer=0
|
||||
#define my_b_inited(info) (info)->buffer
|
||||
#define my_b_EOF INT_MIN
|
||||
|
||||
#define my_b_read(info,Buffer,Count) \
|
||||
((info)->read_pos + (Count) <= (info)->read_end ?\
|
||||
(memcpy(Buffer,(info)->read_pos,(size_t) (Count)), \
|
||||
((info)->read_pos+=(Count)),0) :\
|
||||
(*(info)->read_function)((info),Buffer,Count))
|
||||
|
||||
#define my_b_write(info,Buffer,Count) \
|
||||
((info)->write_pos + (Count) <=(info)->write_end ?\
|
||||
(memcpy((info)->write_pos, (Buffer), (size_t)(Count)),\
|
||||
((info)->write_pos+=(Count)),0) : \
|
||||
(*(info)->write_function)((info),(uchar *)(Buffer),(Count)))
|
||||
|
||||
#define my_b_get(info) \
|
||||
((info)->read_pos != (info)->read_end ?\
|
||||
((info)->read_pos++, (int) (uchar) (info)->read_pos[-1]) :\
|
||||
_my_b_get(info))
|
||||
|
||||
#define my_b_tell(info) ((info)->pos_in_file + \
|
||||
(size_t) (*(info)->current_pos - (info)->request_pos))
|
||||
|
||||
#define my_b_get_buffer_start(info) (info)->request_pos
|
||||
#define my_b_get_bytes_in_buffer(info) (char*) (info)->read_end - \
|
||||
(char*) my_b_get_buffer_start(info)
|
||||
#define my_b_get_pos_in_file(info) (info)->pos_in_file
|
||||
|
||||
/* tell write offset in the SEQ_APPEND cache */
|
||||
int my_b_copy_to_file(IO_CACHE *cache, FILE *file);
|
||||
my_off_t my_b_append_tell(IO_CACHE* info);
|
||||
my_off_t my_b_safe_tell(IO_CACHE* info); /* picks the correct tell() */
|
||||
|
||||
#define my_b_bytes_in_cache(info) (size_t) (*(info)->current_end - \
|
||||
*(info)->current_pos)
|
||||
|
||||
typedef uint32 ha_checksum;
|
||||
|
||||
#include <my_alloc.h>
|
||||
|
||||
|
||||
/* Prototypes for mysys and my_func functions */
|
||||
|
||||
extern int my_copy(const char *from,const char *to,myf MyFlags);
|
||||
extern int my_delete(const char *name,myf MyFlags);
|
||||
extern int my_getwd(char * buf,size_t size,myf MyFlags);
|
||||
extern int my_setwd(const char *dir,myf MyFlags);
|
||||
extern int my_lock(File fd,int op,my_off_t start, my_off_t length,myf MyFlags);
|
||||
extern void *my_once_alloc(size_t Size,myf MyFlags);
|
||||
extern void my_once_free(void);
|
||||
extern char *my_once_strdup(const char *src,myf myflags);
|
||||
extern void *my_once_memdup(const void *src, size_t len, myf myflags);
|
||||
extern File my_open(const char *FileName,int Flags,myf MyFlags);
|
||||
extern File my_register_filename(File fd, const char *FileName,
|
||||
enum file_type type_of_file,
|
||||
uint error_message_number, myf MyFlags);
|
||||
extern File my_create(const char *FileName,int CreateFlags,
|
||||
int AccessFlags, myf MyFlags);
|
||||
extern int my_close(File Filedes,myf MyFlags);
|
||||
extern int my_mkdir(const char *dir, int Flags, myf MyFlags);
|
||||
extern int my_readlink(char *to, const char *filename, myf MyFlags);
|
||||
extern int my_is_symlink(const char *filename, ST_FILE_ID *file_id);
|
||||
extern int my_realpath(char *to, const char *filename, myf MyFlags);
|
||||
extern int my_is_same_file(File file, const ST_FILE_ID *file_id);
|
||||
extern File my_create_with_symlink(const char *linkname, const char *filename,
|
||||
int createflags, int access_flags,
|
||||
myf MyFlags);
|
||||
extern int my_delete_with_symlink(const char *name, myf MyFlags);
|
||||
extern int my_rename_with_symlink(const char *from,const char *to,myf MyFlags);
|
||||
extern int my_symlink(const char *content, const char *linkname, myf MyFlags);
|
||||
extern size_t my_read(File Filedes,uchar *Buffer,size_t Count,myf MyFlags);
|
||||
extern size_t my_pread(File Filedes,uchar *Buffer,size_t Count,my_off_t offset,
|
||||
myf MyFlags);
|
||||
extern int my_rename(const char *from,const char *to,myf MyFlags);
|
||||
extern my_off_t my_seek(File fd,my_off_t pos,int whence,myf MyFlags);
|
||||
extern my_off_t my_tell(File fd,myf MyFlags);
|
||||
extern size_t my_write(File Filedes,const uchar *Buffer,size_t Count,
|
||||
myf MyFlags);
|
||||
extern size_t my_pwrite(File Filedes,const uchar *Buffer,size_t Count,
|
||||
my_off_t offset,myf MyFlags);
|
||||
extern size_t my_fread(FILE *stream,uchar *Buffer,size_t Count,myf MyFlags);
|
||||
extern size_t my_fwrite(FILE *stream,const uchar *Buffer,size_t Count,
|
||||
myf MyFlags);
|
||||
extern my_off_t my_fseek(FILE *stream,my_off_t pos,int whence,myf MyFlags);
|
||||
extern my_off_t my_ftell(FILE *stream,myf MyFlags);
|
||||
|
||||
/* implemented in my_syslog.c */
|
||||
|
||||
// Maximum size of message that will be logged.
|
||||
#define MAX_SYSLOG_MESSAGE_SIZE 1024
|
||||
|
||||
/* Platform-independent SysLog support */
|
||||
|
||||
/* facilities on unixoid syslog. harmless on systemd / Win platforms. */
|
||||
typedef struct st_syslog_facility { int id; const char *name; } SYSLOG_FACILITY;
|
||||
extern SYSLOG_FACILITY syslog_facility[];
|
||||
|
||||
enum my_syslog_options { MY_SYSLOG_PIDS= 1 };
|
||||
|
||||
int my_openlog(const char *eventSourceName, int option, int facility);
|
||||
int my_closelog();
|
||||
int my_syslog(const CHARSET_INFO *cs, enum loglevel level, const char *msg);
|
||||
|
||||
/* implemented in my_memmem.c */
|
||||
extern void *my_memmem(const void *haystack, size_t haystacklen,
|
||||
const void *needle, size_t needlelen);
|
||||
|
||||
|
||||
#ifdef _WIN32
|
||||
extern int my_access(const char *path, int amode);
|
||||
#else
|
||||
#define my_access access
|
||||
#endif
|
||||
|
||||
extern int check_if_legal_filename(const char *path);
|
||||
extern int check_if_legal_tablename(const char *path);
|
||||
|
||||
#ifdef _WIN32
|
||||
extern my_bool is_filename_allowed(const char *name, size_t length,
|
||||
my_bool allow_current_dir);
|
||||
#else /* _WIN32 */
|
||||
# define is_filename_allowed(name, length, allow_cwd) (TRUE)
|
||||
#endif /* _WIN32 */
|
||||
|
||||
#ifdef _WIN32
|
||||
extern int nt_share_delete(const char *name,myf MyFlags);
|
||||
#define my_delete_allow_opened(fname,flags) nt_share_delete((fname),(flags))
|
||||
#else
|
||||
#define my_delete_allow_opened(fname,flags) my_delete((fname),(flags))
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
/* Windows-only functions (CRT equivalents)*/
|
||||
extern HANDLE my_get_osfhandle(File fd);
|
||||
extern void my_osmaperr(unsigned long last_error);
|
||||
#endif
|
||||
|
||||
extern const char* get_global_errmsg(int nr);
|
||||
extern void wait_for_free_space(const char *filename, int errors);
|
||||
extern FILE *my_fopen(const char *FileName,int Flags,myf MyFlags);
|
||||
extern FILE *my_fdopen(File Filedes,const char *name, int Flags,myf MyFlags);
|
||||
extern FILE *my_freopen(const char *path, const char *mode, FILE *stream);
|
||||
extern int my_fclose(FILE *fd,myf MyFlags);
|
||||
extern File my_fileno(FILE *fd);
|
||||
extern int my_chsize(File fd,my_off_t newlength, int filler, myf MyFlags);
|
||||
extern void thr_set_sync_wait_callback(void (*before_sync)(void),
|
||||
void (*after_sync)(void));
|
||||
extern int my_sync(File fd, myf my_flags);
|
||||
extern int my_sync_dir(const char *dir_name, myf my_flags);
|
||||
extern int my_sync_dir_by_file(const char *file_name, myf my_flags);
|
||||
extern char *my_strerror(char *buf, size_t len, int errnum);
|
||||
extern const char *my_get_err_msg(int nr);
|
||||
extern void my_error(int nr,myf MyFlags, ...);
|
||||
extern void my_printf_error(uint my_err, const char *format,
|
||||
myf MyFlags, ...)
|
||||
MY_ATTRIBUTE((format(printf, 2, 4)));
|
||||
extern void my_printv_error(uint error, const char *format, myf MyFlags,
|
||||
va_list ap);
|
||||
extern int my_error_register(const char* (*get_errmsg) (int),
|
||||
int first, int last);
|
||||
extern my_bool my_error_unregister(int first, int last);
|
||||
extern void my_message(uint my_err, const char *str,myf MyFlags);
|
||||
extern void my_message_stderr(uint my_err, const char *str, myf MyFlags);
|
||||
void my_message_local_stderr(enum loglevel ll,
|
||||
const char *format, va_list args);
|
||||
extern void my_message_local(enum loglevel ll, const char *format, ...);
|
||||
extern my_bool my_init(void);
|
||||
extern void my_end(int infoflag);
|
||||
extern int my_redel(const char *from, const char *to, int MyFlags);
|
||||
extern int my_copystat(const char *from, const char *to, int MyFlags);
|
||||
extern char * my_filename(File fd);
|
||||
extern MY_MODE get_file_perm(ulong perm_flags);
|
||||
extern my_bool my_chmod(const char *filename, ulong perm_flags, myf my_flags);
|
||||
|
||||
#ifdef EXTRA_DEBUG
|
||||
void my_print_open_files(void);
|
||||
#else
|
||||
#define my_print_open_files()
|
||||
#endif
|
||||
|
||||
extern my_bool init_tmpdir(MY_TMPDIR *tmpdir, const char *pathlist);
|
||||
extern char *my_tmpdir(MY_TMPDIR *tmpdir);
|
||||
extern void free_tmpdir(MY_TMPDIR *tmpdir);
|
||||
|
||||
extern size_t dirname_part(char * to,const char *name, size_t *to_res_length);
|
||||
extern size_t dirname_length(const char *name);
|
||||
#define base_name(A) (A+dirname_length(A))
|
||||
extern int test_if_hard_path(const char *dir_name);
|
||||
extern my_bool has_path(const char *name);
|
||||
extern char *convert_dirname(char *to, const char *from, const char *from_end);
|
||||
extern void to_unix_path(char * name);
|
||||
extern char * fn_ext(const char *name);
|
||||
extern char * fn_same(char * toname,const char *name,int flag);
|
||||
extern char * fn_format(char * to,const char *name,const char *dir,
|
||||
const char *form, uint flag);
|
||||
extern size_t strlength(const char *str);
|
||||
extern void pack_dirname(char * to,const char *from);
|
||||
extern size_t normalize_dirname(char * to, const char *from);
|
||||
extern size_t unpack_dirname(char * to,const char *from);
|
||||
extern size_t cleanup_dirname(char * to,const char *from);
|
||||
extern size_t system_filename(char * to,const char *from);
|
||||
extern size_t unpack_filename(char * to,const char *from);
|
||||
extern char * intern_filename(char * to,const char *from);
|
||||
extern int pack_filename(char * to, const char *name, size_t max_length);
|
||||
extern char * my_path(char * to,const char *progname,
|
||||
const char *own_pathname_part);
|
||||
extern char * my_load_path(char * to, const char *path,
|
||||
const char *own_path_prefix);
|
||||
extern int wild_compare(const char *str,const char *wildstr,
|
||||
pbool str_is_pattern);
|
||||
extern my_bool array_append_string_unique(const char *str,
|
||||
const char **array, size_t size);
|
||||
extern void get_date(char * to,int timeflag,time_t use_time);
|
||||
extern void soundex(CHARSET_INFO *, char * out_pntr, char * in_pntr,
|
||||
pbool remove_garbage);
|
||||
|
||||
extern my_bool radixsort_is_appliccable(uint n_items, size_t size_of_element);
|
||||
extern void radixsort_for_str_ptr(uchar* base[], uint number_of_elements,
|
||||
size_t size_of_element,uchar *buffer[]);
|
||||
extern void my_qsort(void *base_ptr, size_t total_elems, size_t size,
|
||||
qsort_cmp cmp);
|
||||
extern void my_qsort2(void *base_ptr, size_t total_elems, size_t size,
|
||||
qsort2_cmp cmp, const void *cmp_argument);
|
||||
void my_store_ptr(uchar *buff, size_t pack_length, my_off_t pos);
|
||||
my_off_t my_get_ptr(uchar *ptr, size_t pack_length);
|
||||
extern int init_io_cache_ext(IO_CACHE *info,File file,size_t cachesize,
|
||||
enum cache_type type,my_off_t seek_offset,
|
||||
pbool use_async_io, myf cache_myflags,
|
||||
PSI_file_key file_key);
|
||||
extern int init_io_cache(IO_CACHE *info,File file,size_t cachesize,
|
||||
enum cache_type type,my_off_t seek_offset,
|
||||
pbool use_async_io, myf cache_myflags);
|
||||
extern my_bool reinit_io_cache(IO_CACHE *info,enum cache_type type,
|
||||
my_off_t seek_offset,pbool use_async_io,
|
||||
pbool clear_cache);
|
||||
extern void setup_io_cache(IO_CACHE* info);
|
||||
extern int _my_b_read(IO_CACHE *info,uchar *Buffer,size_t Count);
|
||||
extern int _my_b_read_r(IO_CACHE *info,uchar *Buffer,size_t Count);
|
||||
extern void init_io_cache_share(IO_CACHE *read_cache, IO_CACHE_SHARE *cshare,
|
||||
IO_CACHE *write_cache, uint num_threads);
|
||||
extern void remove_io_thread(IO_CACHE *info);
|
||||
extern int _my_b_seq_read(IO_CACHE *info,uchar *Buffer,size_t Count);
|
||||
extern int _my_b_net_read(IO_CACHE *info,uchar *Buffer,size_t Count);
|
||||
extern int _my_b_get(IO_CACHE *info);
|
||||
extern int _my_b_write(IO_CACHE *info,const uchar *Buffer,size_t Count);
|
||||
extern int my_b_append(IO_CACHE *info,const uchar *Buffer,size_t Count);
|
||||
extern int my_b_safe_write(IO_CACHE *info,const uchar *Buffer,size_t Count);
|
||||
|
||||
extern int my_block_write(IO_CACHE *info, const uchar *Buffer,
|
||||
size_t Count, my_off_t pos);
|
||||
extern int my_b_flush_io_cache(IO_CACHE *info, int need_append_buffer_lock);
|
||||
|
||||
#define flush_io_cache(info) my_b_flush_io_cache((info),1)
|
||||
|
||||
extern int end_io_cache(IO_CACHE *info);
|
||||
extern size_t my_b_fill(IO_CACHE *info);
|
||||
extern void my_b_seek(IO_CACHE *info,my_off_t pos);
|
||||
extern size_t my_b_gets(IO_CACHE *info, char *to, size_t max_length);
|
||||
extern my_off_t my_b_filelength(IO_CACHE *info);
|
||||
extern size_t my_b_printf(IO_CACHE *info, const char* fmt, ...)
|
||||
MY_ATTRIBUTE((format(printf, 2, 3)));
|
||||
extern size_t my_b_vprintf(IO_CACHE *info, const char* fmt, va_list ap);
|
||||
extern my_bool open_cached_file(IO_CACHE *cache,const char *dir,
|
||||
const char *prefix, size_t cache_size,
|
||||
myf cache_myflags);
|
||||
extern my_bool real_open_cached_file(IO_CACHE *cache);
|
||||
extern void close_cached_file(IO_CACHE *cache);
|
||||
File create_temp_file(char *to, const char *dir, const char *pfx,
|
||||
int mode, myf MyFlags);
|
||||
|
||||
// Use Prealloced_array or std::vector or something similar in C++
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern my_bool my_init_dynamic_array(DYNAMIC_ARRAY *array,
|
||||
PSI_memory_key key,
|
||||
uint element_size,
|
||||
void *init_buffer,
|
||||
uint init_alloc,
|
||||
uint alloc_increment);
|
||||
/* init_dynamic_array() function is deprecated */
|
||||
extern my_bool init_dynamic_array(DYNAMIC_ARRAY *array, uint element_size,
|
||||
uint init_alloc, uint alloc_increment);
|
||||
#define dynamic_element(array,array_index,type) \
|
||||
((type)((array)->buffer) +(array_index))
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Some functions are still in use in C++, because HASH uses DYNAMIC_ARRAY */
|
||||
extern my_bool insert_dynamic(DYNAMIC_ARRAY *array, const void *element);
|
||||
extern void *alloc_dynamic(DYNAMIC_ARRAY *array);
|
||||
extern void *pop_dynamic(DYNAMIC_ARRAY*);
|
||||
extern void get_dynamic(DYNAMIC_ARRAY *array, void *element, uint array_index);
|
||||
extern void claim_dynamic(DYNAMIC_ARRAY *array);
|
||||
extern void delete_dynamic(DYNAMIC_ARRAY *array);
|
||||
extern void freeze_size(DYNAMIC_ARRAY *array);
|
||||
static inline void reset_dynamic(DYNAMIC_ARRAY *array)
|
||||
{
|
||||
array->elements= 0;
|
||||
}
|
||||
|
||||
extern my_bool init_dynamic_string(DYNAMIC_STRING *str, const char *init_str,
|
||||
size_t init_alloc,size_t alloc_increment);
|
||||
extern my_bool dynstr_append(DYNAMIC_STRING *str, const char *append);
|
||||
my_bool dynstr_append_mem(DYNAMIC_STRING *str, const char *append,
|
||||
size_t length);
|
||||
extern my_bool dynstr_append_os_quoted(DYNAMIC_STRING *str, const char *append,
|
||||
...);
|
||||
extern my_bool dynstr_set(DYNAMIC_STRING *str, const char *init_str);
|
||||
extern my_bool dynstr_realloc(DYNAMIC_STRING *str, size_t additional_size);
|
||||
extern my_bool dynstr_trunc(DYNAMIC_STRING *str, size_t n);
|
||||
extern void dynstr_free(DYNAMIC_STRING *str);
|
||||
#define alloc_root_inited(A) ((A)->min_malloc != 0)
|
||||
#define ALLOC_ROOT_MIN_BLOCK_SIZE (MALLOC_OVERHEAD + sizeof(USED_MEM) + 8)
|
||||
#define clear_alloc_root(A) do { (A)->free= (A)->used= (A)->pre_alloc= 0; (A)->min_malloc=0;} while(0)
|
||||
extern void init_alloc_root(PSI_memory_key key,
|
||||
MEM_ROOT *mem_root, size_t block_size,
|
||||
size_t pre_alloc_size);
|
||||
extern void *alloc_root(MEM_ROOT *mem_root, size_t Size);
|
||||
extern void *multi_alloc_root(MEM_ROOT *mem_root, ...);
|
||||
extern void claim_root(MEM_ROOT *root);
|
||||
extern void free_root(MEM_ROOT *root, myf MyFLAGS);
|
||||
extern void reset_root_defaults(MEM_ROOT *mem_root, size_t block_size,
|
||||
size_t prealloc_size);
|
||||
extern char *strdup_root(MEM_ROOT *root,const char *str);
|
||||
static inline char *safe_strdup_root(MEM_ROOT *root, const char *str)
|
||||
{
|
||||
return str ? strdup_root(root, str) : 0;
|
||||
}
|
||||
extern char *strmake_root(MEM_ROOT *root,const char *str,size_t len);
|
||||
extern void *memdup_root(MEM_ROOT *root,const void *str, size_t len);
|
||||
extern void set_memroot_max_capacity(MEM_ROOT *mem_root, size_t size);
|
||||
extern void set_memroot_error_reporting(MEM_ROOT *mem_root,
|
||||
my_bool report_error);
|
||||
extern my_bool my_compress(uchar *, size_t *, size_t *);
|
||||
extern my_bool my_uncompress(uchar *, size_t , size_t *);
|
||||
extern uchar *my_compress_alloc(const uchar *packet, size_t *len,
|
||||
size_t *complen);
|
||||
extern int packfrm(uchar *, size_t, uchar **, size_t *);
|
||||
extern int unpackfrm(uchar **, size_t *, const uchar *);
|
||||
|
||||
extern ha_checksum my_checksum(ha_checksum crc, const uchar *mem,
|
||||
size_t count);
|
||||
|
||||
/* Wait a given number of microseconds */
|
||||
static inline void my_sleep(time_t m_seconds)
|
||||
{
|
||||
#if defined(_WIN32)
|
||||
Sleep((DWORD)m_seconds/1000+1); /* Sleep() has millisecond arg */
|
||||
#else
|
||||
struct timeval t;
|
||||
t.tv_sec= m_seconds / 1000000L;
|
||||
t.tv_usec= m_seconds % 1000000L;
|
||||
select(0,0,0,0,&t); /* sleep */
|
||||
#endif
|
||||
}
|
||||
|
||||
extern ulong crc32(ulong crc, const uchar *buf, uint len);
|
||||
extern uint my_set_max_open_files(uint files);
|
||||
void my_free_open_file_info(void);
|
||||
|
||||
extern time_t my_time(myf flags);
|
||||
extern ulonglong my_getsystime(void);
|
||||
extern ulonglong my_micro_time();
|
||||
extern my_bool my_gethwaddr(uchar *to);
|
||||
|
||||
#ifdef HAVE_SYS_MMAN_H
|
||||
#include <sys/mman.h>
|
||||
|
||||
#ifndef MAP_NOSYNC
|
||||
#define MAP_NOSYNC 0
|
||||
#endif
|
||||
|
||||
/*
|
||||
Not defined in FreeBSD 11.
|
||||
Was never implemented in FreeBSD, so we just set it to 0.
|
||||
*/
|
||||
#ifndef MAP_NORESERVE
|
||||
#define MAP_NORESERVE 0
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_MMAP64
|
||||
#define my_mmap(a,b,c,d,e,f) mmap64(a,b,c,d,e,f)
|
||||
#else
|
||||
#define my_mmap(a,b,c,d,e,f) mmap(a,b,c,d,e,f)
|
||||
#endif
|
||||
#define my_munmap(a,b) munmap((a),(b))
|
||||
|
||||
#else
|
||||
/* not a complete set of mmap() flags, but only those that nesessary */
|
||||
#define PROT_READ 1
|
||||
#define PROT_WRITE 2
|
||||
#define MAP_NORESERVE 0
|
||||
#define MAP_SHARED 0x0001
|
||||
#define MAP_PRIVATE 0x0002
|
||||
#define MAP_NOSYNC 0x0800
|
||||
#define MAP_FAILED ((void *)-1)
|
||||
#define MS_SYNC 0x0000
|
||||
|
||||
void *my_mmap(void *, size_t, int, int, int, my_off_t);
|
||||
int my_munmap(void *, size_t);
|
||||
#endif
|
||||
|
||||
/* my_getpagesize */
|
||||
static inline int my_getpagesize()
|
||||
{
|
||||
#ifndef _WIN32
|
||||
return getpagesize();
|
||||
#else
|
||||
SYSTEM_INFO si;
|
||||
GetSystemInfo(&si);
|
||||
return (int)si.dwPageSize;
|
||||
#endif
|
||||
}
|
||||
|
||||
int my_msync(int, void *, size_t, int);
|
||||
|
||||
/* character sets */
|
||||
extern void my_charset_loader_init_mysys(MY_CHARSET_LOADER *loader);
|
||||
extern uint get_charset_number(const char *cs_name, uint cs_flags);
|
||||
extern uint get_collation_number(const char *name);
|
||||
extern const char *get_charset_name(uint cs_number);
|
||||
|
||||
extern CHARSET_INFO *get_charset(uint cs_number, myf flags);
|
||||
extern CHARSET_INFO *get_charset_by_name(const char *cs_name, myf flags);
|
||||
extern CHARSET_INFO *my_collation_get_by_name(MY_CHARSET_LOADER *loader,
|
||||
const char *name, myf flags);
|
||||
extern CHARSET_INFO *get_charset_by_csname(const char *cs_name,
|
||||
uint cs_flags, myf my_flags);
|
||||
extern CHARSET_INFO *my_charset_get_by_name(MY_CHARSET_LOADER *loader,
|
||||
const char *name,
|
||||
uint cs_flags, myf my_flags);
|
||||
extern my_bool resolve_charset(const char *cs_name,
|
||||
const CHARSET_INFO *default_cs,
|
||||
const CHARSET_INFO **cs);
|
||||
extern my_bool resolve_collation(const char *cl_name,
|
||||
const CHARSET_INFO *default_cl,
|
||||
const CHARSET_INFO **cl);
|
||||
extern void free_charsets(void);
|
||||
extern char *get_charsets_dir(char *buf);
|
||||
extern my_bool my_charset_same(const CHARSET_INFO *cs1,
|
||||
const CHARSET_INFO *cs2);
|
||||
extern my_bool init_compiled_charsets(myf flags);
|
||||
extern void add_compiled_collation(CHARSET_INFO *cs);
|
||||
extern size_t escape_string_for_mysql(const CHARSET_INFO *charset_info,
|
||||
char *to, size_t to_length,
|
||||
const char *from, size_t length);
|
||||
#ifdef _WIN32
|
||||
/* File system character set */
|
||||
extern CHARSET_INFO *fs_character_set(void);
|
||||
#endif
|
||||
extern size_t escape_quotes_for_mysql(CHARSET_INFO *charset_info,
|
||||
char *to, size_t to_length,
|
||||
const char *from, size_t length, char quote);
|
||||
#ifdef _WIN32
|
||||
extern my_bool have_tcpip; /* Is set if tcpip is used */
|
||||
|
||||
/* implemented in my_windac.c */
|
||||
|
||||
int my_security_attr_create(SECURITY_ATTRIBUTES **psa, const char **perror,
|
||||
DWORD owner_rights, DWORD everybody_rights);
|
||||
|
||||
void my_security_attr_free(SECURITY_ATTRIBUTES *sa);
|
||||
|
||||
/* implemented in my_conio.c */
|
||||
my_bool my_win_is_console(FILE *file);
|
||||
char *my_win_console_readline(const CHARSET_INFO *cs, char *mbbuf, size_t mbbufsize,
|
||||
size_t *nread);
|
||||
void my_win_console_write(const CHARSET_INFO *cs, const char *data, size_t datalen);
|
||||
void my_win_console_fputs(const CHARSET_INFO *cs, const char *data);
|
||||
void my_win_console_putc(const CHARSET_INFO *cs, int c);
|
||||
void my_win_console_vfprintf(const CHARSET_INFO *cs, const char *fmt, va_list args);
|
||||
int my_win_translate_command_line_args(const CHARSET_INFO *cs, int *ac, char ***av);
|
||||
#endif /* _WIN32 */
|
||||
|
||||
#ifdef HAVE_PSI_INTERFACE
|
||||
extern MYSQL_PLUGIN_IMPORT struct PSI_bootstrap *PSI_hook;
|
||||
extern void set_psi_server(PSI *psi);
|
||||
void my_init_mysys_psi_keys(void);
|
||||
#endif
|
||||
|
||||
struct st_mysql_file;
|
||||
extern struct st_mysql_file *mysql_stdin;
|
||||
|
||||
C_MODE_END
|
||||
#endif /* _my_sys_h */
|
|
@ -0,0 +1,199 @@
|
|||
/* Copyright (c) 2000, 2022, Oracle and/or its affiliates.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License, version 2.0,
|
||||
as published by the Free Software Foundation.
|
||||
|
||||
This program is also distributed with certain software (including
|
||||
but not limited to OpenSSL) that is licensed under separate terms,
|
||||
as designated in a particular file or component or in included license
|
||||
documentation. The authors of MySQL hereby grant you an additional
|
||||
permission to link the program and your derivative works with the
|
||||
separately licensed software that they have included with MySQL.
|
||||
|
||||
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, version 2.0, 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 */
|
||||
|
||||
/* Defines to make different thread packages compatible */
|
||||
|
||||
#ifndef MY_THREAD_INCLUDED
|
||||
#define MY_THREAD_INCLUDED
|
||||
|
||||
#include "my_global.h" /* my_bool */
|
||||
|
||||
#if !defined(_WIN32)
|
||||
#include <pthread.h>
|
||||
#endif
|
||||
|
||||
#ifndef ETIME
|
||||
#define ETIME ETIMEDOUT /* For FreeBSD */
|
||||
#endif
|
||||
|
||||
#ifndef ETIMEDOUT
|
||||
#define ETIMEDOUT 145 /* Win32 doesn't have this */
|
||||
#endif
|
||||
|
||||
/*
|
||||
MySQL can survive with 32K, but some glibc libraries require > 128K stack
|
||||
To resolve hostnames. Also recursive stored procedures needs stack.
|
||||
*/
|
||||
#if defined(__sparc) && (defined(__SUNPRO_CC) || defined(__SUNPRO_C))
|
||||
#define STACK_MULTIPLIER 2UL
|
||||
#else
|
||||
#define STACK_MULTIPLIER 1UL
|
||||
#endif
|
||||
|
||||
#if SIZEOF_CHARP > 4
|
||||
#define DEFAULT_THREAD_STACK (STACK_MULTIPLIER * 256UL * 1024UL)
|
||||
#else
|
||||
#define DEFAULT_THREAD_STACK (STACK_MULTIPLIER * 192UL * 1024UL)
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define EXTERNC extern "C"
|
||||
#else
|
||||
#define EXTERNC
|
||||
#endif
|
||||
|
||||
C_MODE_START
|
||||
|
||||
#ifdef _WIN32
|
||||
typedef volatile LONG my_thread_once_t;
|
||||
typedef DWORD my_thread_t;
|
||||
typedef struct thread_attr
|
||||
{
|
||||
DWORD dwStackSize;
|
||||
int detachstate;
|
||||
} my_thread_attr_t;
|
||||
#define MY_THREAD_CREATE_JOINABLE 0
|
||||
#define MY_THREAD_CREATE_DETACHED 1
|
||||
typedef void * (__cdecl *my_start_routine)(void *);
|
||||
#define MY_THREAD_ONCE_INIT 0
|
||||
#define MY_THREAD_ONCE_INPROGRESS 1
|
||||
#define MY_THREAD_ONCE_DONE 2
|
||||
#else
|
||||
typedef pthread_once_t my_thread_once_t;
|
||||
typedef pthread_t my_thread_t;
|
||||
typedef pthread_attr_t my_thread_attr_t;
|
||||
#define MY_THREAD_CREATE_JOINABLE PTHREAD_CREATE_JOINABLE
|
||||
#define MY_THREAD_CREATE_DETACHED PTHREAD_CREATE_DETACHED
|
||||
typedef void *(* my_start_routine)(void *);
|
||||
#define MY_THREAD_ONCE_INIT PTHREAD_ONCE_INIT
|
||||
#endif
|
||||
|
||||
typedef struct st_my_thread_handle
|
||||
{
|
||||
my_thread_t thread;
|
||||
#ifdef _WIN32
|
||||
HANDLE handle;
|
||||
#endif
|
||||
} my_thread_handle;
|
||||
|
||||
int my_thread_once(my_thread_once_t *once_control, void (*init_routine)(void));
|
||||
|
||||
static inline my_thread_t my_thread_self()
|
||||
{
|
||||
#ifdef _WIN32
|
||||
return GetCurrentThreadId();
|
||||
#else
|
||||
return pthread_self();
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline int my_thread_equal(my_thread_t t1, my_thread_t t2)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
return t1 == t2;
|
||||
#else
|
||||
return pthread_equal(t1, t2);
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline int my_thread_attr_init(my_thread_attr_t *attr)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
attr->dwStackSize= 0;
|
||||
/* Set to joinable by default to match Linux */
|
||||
attr->detachstate= MY_THREAD_CREATE_JOINABLE;
|
||||
return 0;
|
||||
#else
|
||||
return pthread_attr_init(attr);
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline int my_thread_attr_destroy(my_thread_attr_t *attr)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
attr->dwStackSize= 0;
|
||||
/* Set to joinable by default to match Linux */
|
||||
attr->detachstate= MY_THREAD_CREATE_JOINABLE;
|
||||
return 0;
|
||||
#else
|
||||
return pthread_attr_destroy(attr);
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline int my_thread_attr_setstacksize(my_thread_attr_t *attr,
|
||||
size_t stacksize)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
attr->dwStackSize= (DWORD)stacksize;
|
||||
return 0;
|
||||
#else
|
||||
return pthread_attr_setstacksize(attr, stacksize);
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline int my_thread_attr_setdetachstate(my_thread_attr_t *attr,
|
||||
int detachstate)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
attr->detachstate= detachstate;
|
||||
return 0;
|
||||
#else
|
||||
return pthread_attr_setdetachstate(attr, detachstate);
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline int my_thread_attr_getstacksize(my_thread_attr_t *attr,
|
||||
size_t *stacksize)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
*stacksize= (size_t)attr->dwStackSize;
|
||||
return 0;
|
||||
#else
|
||||
return pthread_attr_getstacksize(attr, stacksize);
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline void my_thread_yield()
|
||||
{
|
||||
#ifdef _WIN32
|
||||
SwitchToThread();
|
||||
#else
|
||||
sched_yield();
|
||||
#endif
|
||||
}
|
||||
|
||||
int my_thread_create(my_thread_handle *thread, const my_thread_attr_t *attr,
|
||||
my_start_routine func, void *arg);
|
||||
int my_thread_join(my_thread_handle *thread, void **value_ptr);
|
||||
int my_thread_cancel(my_thread_handle *thread);
|
||||
void my_thread_exit(void *value_ptr);
|
||||
|
||||
|
||||
extern my_bool my_thread_global_init();
|
||||
extern void my_thread_global_reinit();
|
||||
extern void my_thread_global_end();
|
||||
extern my_bool my_thread_init();
|
||||
extern void my_thread_end();
|
||||
|
||||
C_MODE_END
|
||||
|
||||
#endif /* MY_THREAD_INCLUDED */
|
|
@ -0,0 +1,114 @@
|
|||
/* Copyright (c) 2000, 2022, Oracle and/or its affiliates.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License, version 2.0,
|
||||
as published by the Free Software Foundation.
|
||||
|
||||
This program is also distributed with certain software (including
|
||||
but not limited to OpenSSL) that is licensed under separate terms,
|
||||
as designated in a particular file or component or in included license
|
||||
documentation. The authors of MySQL hereby grant you an additional
|
||||
permission to link the program and your derivative works with the
|
||||
separately licensed software that they have included with MySQL.
|
||||
|
||||
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, version 2.0, 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 St, Fifth Floor, Boston, MA 02110-1301, USA */
|
||||
|
||||
#ifndef MY_THREAD_LOCAL_INCLUDED
|
||||
#define MY_THREAD_LOCAL_INCLUDED
|
||||
|
||||
#ifndef _WIN32
|
||||
#include <pthread.h>
|
||||
#endif
|
||||
|
||||
struct _db_code_state_;
|
||||
typedef uint32 my_thread_id;
|
||||
|
||||
C_MODE_START
|
||||
|
||||
#ifdef _WIN32
|
||||
typedef DWORD thread_local_key_t;
|
||||
#else
|
||||
typedef pthread_key_t thread_local_key_t;
|
||||
#endif
|
||||
|
||||
static inline int my_create_thread_local_key(thread_local_key_t *key,
|
||||
void (*destructor)(void *))
|
||||
{
|
||||
#ifdef _WIN32
|
||||
*key= TlsAlloc();
|
||||
return (*key == TLS_OUT_OF_INDEXES);
|
||||
#else
|
||||
return pthread_key_create(key, destructor);
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline int my_delete_thread_local_key(thread_local_key_t key)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
return !TlsFree(key);
|
||||
#else
|
||||
return pthread_key_delete(key);
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline void* my_get_thread_local(thread_local_key_t key)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
return TlsGetValue(key);
|
||||
#else
|
||||
return pthread_getspecific(key);
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline int my_set_thread_local(thread_local_key_t key,
|
||||
void *value)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
return !TlsSetValue(key, value);
|
||||
#else
|
||||
return pthread_setspecific(key, value);
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
Retrieve the MySQL thread-local storage variant of errno.
|
||||
*/
|
||||
int my_errno();
|
||||
|
||||
/**
|
||||
Set the MySQL thread-local storage variant of errno.
|
||||
*/
|
||||
void set_my_errno(int my_errno);
|
||||
|
||||
#ifdef _WIN32
|
||||
/*
|
||||
thr_winerr is used for returning the original OS error-code in Windows,
|
||||
my_osmaperr() returns EINVAL for all unknown Windows errors, hence we
|
||||
preserve the original Windows Error code in thr_winerr.
|
||||
*/
|
||||
int thr_winerr();
|
||||
|
||||
void set_thr_winerr(int winerr);
|
||||
|
||||
#endif
|
||||
|
||||
#ifndef NDEBUG
|
||||
/* Return pointer to DBUG for holding current state */
|
||||
struct _db_code_state_ **my_thread_var_dbug();
|
||||
|
||||
my_thread_id my_thread_var_id();
|
||||
|
||||
void set_my_thread_var_id(my_thread_id id);
|
||||
|
||||
#endif
|
||||
|
||||
C_MODE_END
|
||||
|
||||
#endif // MY_THREAD_LOCAL_INCLUDED
|
|
@ -0,0 +1,103 @@
|
|||
/* Copyright (c) 2000, 2022, Oracle and/or its affiliates.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License, version 2.0,
|
||||
as published by the Free Software Foundation.
|
||||
|
||||
This program is also distributed with certain software (including
|
||||
but not limited to OpenSSL) that is licensed under separate terms,
|
||||
as designated in a particular file or component or in included license
|
||||
documentation. The authors of MySQL hereby grant you an additional
|
||||
permission to link the program and your derivative works with the
|
||||
separately licensed software that they have included with MySQL.
|
||||
|
||||
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, version 2.0, 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 _my_xml_h
|
||||
#define _my_xml_h
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
#define MY_XML_OK 0
|
||||
#define MY_XML_ERROR 1
|
||||
|
||||
/*
|
||||
A flag whether to use absolute tag names in call-back functions,
|
||||
like "a", "a.b" and "a.b.c" (used in character set file parser),
|
||||
or relative names like "a", "b" and "c".
|
||||
*/
|
||||
#define MY_XML_FLAG_RELATIVE_NAMES 1
|
||||
|
||||
/*
|
||||
A flag whether to skip normilization of text values before calling
|
||||
call-back functions: i.e. skip leading/trailing spaces,
|
||||
\r, \n, \t characters.
|
||||
*/
|
||||
#define MY_XML_FLAG_SKIP_TEXT_NORMALIZATION 2
|
||||
|
||||
enum my_xml_node_type
|
||||
{
|
||||
MY_XML_NODE_TAG, /* can have TAG, ATTR and TEXT children */
|
||||
MY_XML_NODE_ATTR, /* can have TEXT children */
|
||||
MY_XML_NODE_TEXT /* cannot have children */
|
||||
};
|
||||
|
||||
typedef struct xml_stack_st
|
||||
{
|
||||
int flags;
|
||||
enum my_xml_node_type current_node_type;
|
||||
char errstr[128];
|
||||
|
||||
struct {
|
||||
char static_buffer[128];
|
||||
char *buffer;
|
||||
size_t buffer_size;
|
||||
char *start;
|
||||
char *end;
|
||||
} attr;
|
||||
|
||||
const char *beg;
|
||||
const char *cur;
|
||||
const char *end;
|
||||
void *user_data;
|
||||
int (*enter)(struct xml_stack_st *st,const char *val, size_t len);
|
||||
int (*value)(struct xml_stack_st *st,const char *val, size_t len);
|
||||
int (*leave_xml)(struct xml_stack_st *st,const char *val, size_t len);
|
||||
} MY_XML_PARSER;
|
||||
|
||||
void my_xml_parser_create(MY_XML_PARSER *st);
|
||||
void my_xml_parser_free(MY_XML_PARSER *st);
|
||||
int my_xml_parse(MY_XML_PARSER *st,const char *str, size_t len);
|
||||
|
||||
void my_xml_set_value_handler(MY_XML_PARSER *st, int (*)(MY_XML_PARSER *,
|
||||
const char *,
|
||||
size_t len));
|
||||
void my_xml_set_enter_handler(MY_XML_PARSER *st, int (*)(MY_XML_PARSER *,
|
||||
const char *,
|
||||
size_t len));
|
||||
void my_xml_set_leave_handler(MY_XML_PARSER *st, int (*)(MY_XML_PARSER *,
|
||||
const char *,
|
||||
size_t len));
|
||||
void my_xml_set_user_data(MY_XML_PARSER *st, void *);
|
||||
|
||||
size_t my_xml_error_pos(MY_XML_PARSER *st);
|
||||
uint my_xml_error_lineno(MY_XML_PARSER *st);
|
||||
|
||||
const char *my_xml_error_string(MY_XML_PARSER *st);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _my_xml_h */
|
|
@ -0,0 +1,741 @@
|
|||
/* Copyright (c) 2000, 2022, Oracle and/or its affiliates.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License, version 2.0,
|
||||
as published by the Free Software Foundation.
|
||||
|
||||
This program is also distributed with certain software (including
|
||||
but not limited to OpenSSL) that is licensed under separate terms,
|
||||
as designated in a particular file or component or in included license
|
||||
documentation. The authors of MySQL hereby grant you an additional
|
||||
permission to link the program and your derivative works with the
|
||||
separately licensed software that they have included with MySQL.
|
||||
|
||||
Without limiting anything contained in the foregoing, this file,
|
||||
which is part of C Driver for MySQL (Connector/C), is also subject to the
|
||||
Universal FOSS Exception, version 1.0, a copy of which can be found at
|
||||
http://oss.oracle.com/licenses/universal-foss-exception.
|
||||
|
||||
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, version 2.0, 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 St, Fifth Floor, Boston, MA 02110-1301 USA */
|
||||
|
||||
/*
|
||||
This file defines the client API to MySQL and also the ABI of the
|
||||
dynamically linked libmysqlclient.
|
||||
|
||||
The ABI should never be changed in a released product of MySQL,
|
||||
thus you need to take great care when changing the file. In case
|
||||
the file is changed so the ABI is broken, you must also update
|
||||
the SHARED_LIB_MAJOR_VERSION in cmake/mysql_version.cmake
|
||||
*/
|
||||
|
||||
#ifndef _mysql_h
|
||||
#define _mysql_h
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef MY_GLOBAL_INCLUDED /* If not standard header */
|
||||
#ifndef MYSQL_ABI_CHECK
|
||||
#include <sys/types.h>
|
||||
#endif
|
||||
typedef char my_bool;
|
||||
#if !defined(_WIN32)
|
||||
#define STDCALL
|
||||
#else
|
||||
#define STDCALL __stdcall
|
||||
#endif
|
||||
|
||||
#ifndef my_socket_defined
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#ifdef WIN32_LEAN_AND_MEAN
|
||||
#include <winsock2.h>
|
||||
#endif
|
||||
#define my_socket SOCKET
|
||||
#else
|
||||
typedef int my_socket;
|
||||
#endif /* _WIN32 */
|
||||
#endif /* my_socket_defined */
|
||||
#endif /* MY_GLOBAL_INCLUDED */
|
||||
|
||||
#include "mysql_version.h"
|
||||
#include "mysql_com.h"
|
||||
#include "mysql_time.h"
|
||||
|
||||
#include "my_list.h" /* for LISTs used in 'MYSQL' and 'MYSQL_STMT' */
|
||||
|
||||
/* Include declarations of plug-in API */
|
||||
#include "mysql/client_plugin.h"
|
||||
|
||||
extern unsigned int mysql_port;
|
||||
extern char *mysql_unix_port;
|
||||
|
||||
#define CLIENT_NET_READ_TIMEOUT 365*24*3600 /* Timeout on read */
|
||||
#define CLIENT_NET_WRITE_TIMEOUT 365*24*3600 /* Timeout on write */
|
||||
|
||||
#define IS_PRI_KEY(n) ((n) & PRI_KEY_FLAG)
|
||||
#define IS_NOT_NULL(n) ((n) & NOT_NULL_FLAG)
|
||||
#define IS_BLOB(n) ((n) & BLOB_FLAG)
|
||||
/**
|
||||
Returns true if the value is a number which does not need quotes for
|
||||
the sql_lex.cc parser to parse correctly.
|
||||
*/
|
||||
#define IS_NUM(t) (((t) <= MYSQL_TYPE_INT24 && (t) != MYSQL_TYPE_TIMESTAMP) || (t) == MYSQL_TYPE_YEAR || (t) == MYSQL_TYPE_NEWDECIMAL)
|
||||
#define IS_LONGDATA(t) ((t) >= MYSQL_TYPE_TINY_BLOB && (t) <= MYSQL_TYPE_STRING)
|
||||
|
||||
|
||||
typedef struct st_mysql_field {
|
||||
char *name; /* Name of column */
|
||||
char *org_name; /* Original column name, if an alias */
|
||||
char *table; /* Table of column if column was a field */
|
||||
char *org_table; /* Org table name, if table was an alias */
|
||||
char *db; /* Database for table */
|
||||
char *catalog; /* Catalog for table */
|
||||
char *def; /* Default value (set by mysql_list_fields) */
|
||||
unsigned long length; /* Width of column (create length) */
|
||||
unsigned long max_length; /* Max width for selected set */
|
||||
unsigned int name_length;
|
||||
unsigned int org_name_length;
|
||||
unsigned int table_length;
|
||||
unsigned int org_table_length;
|
||||
unsigned int db_length;
|
||||
unsigned int catalog_length;
|
||||
unsigned int def_length;
|
||||
unsigned int flags; /* Div flags */
|
||||
unsigned int decimals; /* Number of decimals in field */
|
||||
unsigned int charsetnr; /* Character set */
|
||||
enum enum_field_types type; /* Type of field. See mysql_com.h for types */
|
||||
void *extension;
|
||||
} MYSQL_FIELD;
|
||||
|
||||
typedef char **MYSQL_ROW; /* return data as array of strings */
|
||||
typedef unsigned int MYSQL_FIELD_OFFSET; /* offset to current field */
|
||||
|
||||
#ifndef MY_GLOBAL_INCLUDED
|
||||
#if defined (_WIN32)
|
||||
typedef unsigned __int64 my_ulonglong;
|
||||
#else
|
||||
typedef unsigned long long my_ulonglong;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include "typelib.h"
|
||||
|
||||
#define MYSQL_COUNT_ERROR (~(my_ulonglong) 0)
|
||||
|
||||
/* backward compatibility define - to be removed eventually */
|
||||
#define ER_WARN_DATA_TRUNCATED WARN_DATA_TRUNCATED
|
||||
|
||||
typedef struct st_mysql_rows {
|
||||
struct st_mysql_rows *next; /* list of rows */
|
||||
MYSQL_ROW data;
|
||||
unsigned long length;
|
||||
} MYSQL_ROWS;
|
||||
|
||||
typedef MYSQL_ROWS *MYSQL_ROW_OFFSET; /* offset to current row */
|
||||
|
||||
#include "my_alloc.h"
|
||||
|
||||
typedef struct embedded_query_result EMBEDDED_QUERY_RESULT;
|
||||
typedef struct st_mysql_data {
|
||||
MYSQL_ROWS *data;
|
||||
struct embedded_query_result *embedded_info;
|
||||
MEM_ROOT alloc;
|
||||
my_ulonglong rows;
|
||||
unsigned int fields;
|
||||
/* extra info for embedded library */
|
||||
void *extension;
|
||||
} MYSQL_DATA;
|
||||
|
||||
enum mysql_option
|
||||
{
|
||||
MYSQL_OPT_CONNECT_TIMEOUT, MYSQL_OPT_COMPRESS, MYSQL_OPT_NAMED_PIPE,
|
||||
MYSQL_INIT_COMMAND, MYSQL_READ_DEFAULT_FILE, MYSQL_READ_DEFAULT_GROUP,
|
||||
MYSQL_SET_CHARSET_DIR, MYSQL_SET_CHARSET_NAME, MYSQL_OPT_LOCAL_INFILE,
|
||||
MYSQL_OPT_PROTOCOL, MYSQL_SHARED_MEMORY_BASE_NAME, MYSQL_OPT_READ_TIMEOUT,
|
||||
MYSQL_OPT_WRITE_TIMEOUT, MYSQL_OPT_USE_RESULT,
|
||||
MYSQL_OPT_USE_REMOTE_CONNECTION, MYSQL_OPT_USE_EMBEDDED_CONNECTION,
|
||||
MYSQL_OPT_GUESS_CONNECTION, MYSQL_SET_CLIENT_IP, MYSQL_SECURE_AUTH,
|
||||
MYSQL_REPORT_DATA_TRUNCATION, MYSQL_OPT_RECONNECT,
|
||||
MYSQL_OPT_SSL_VERIFY_SERVER_CERT, MYSQL_PLUGIN_DIR, MYSQL_DEFAULT_AUTH,
|
||||
MYSQL_OPT_BIND,
|
||||
MYSQL_OPT_SSL_KEY, MYSQL_OPT_SSL_CERT,
|
||||
MYSQL_OPT_SSL_CA, MYSQL_OPT_SSL_CAPATH, MYSQL_OPT_SSL_CIPHER,
|
||||
MYSQL_OPT_SSL_CRL, MYSQL_OPT_SSL_CRLPATH,
|
||||
MYSQL_OPT_CONNECT_ATTR_RESET, MYSQL_OPT_CONNECT_ATTR_ADD,
|
||||
MYSQL_OPT_CONNECT_ATTR_DELETE,
|
||||
MYSQL_SERVER_PUBLIC_KEY,
|
||||
MYSQL_ENABLE_CLEARTEXT_PLUGIN,
|
||||
MYSQL_OPT_CAN_HANDLE_EXPIRED_PASSWORDS,
|
||||
MYSQL_OPT_SSL_ENFORCE,
|
||||
MYSQL_OPT_MAX_ALLOWED_PACKET, MYSQL_OPT_NET_BUFFER_LENGTH,
|
||||
MYSQL_OPT_TLS_VERSION,
|
||||
MYSQL_OPT_SSL_MODE,
|
||||
MYSQL_OPT_GET_SERVER_PUBLIC_KEY
|
||||
};
|
||||
|
||||
/**
|
||||
@todo remove the "extension", move st_mysql_options completely
|
||||
out of mysql.h
|
||||
*/
|
||||
struct st_mysql_options_extention;
|
||||
|
||||
struct st_mysql_options {
|
||||
unsigned int connect_timeout, read_timeout, write_timeout;
|
||||
unsigned int port, protocol;
|
||||
unsigned long client_flag;
|
||||
char *host,*user,*password,*unix_socket,*db;
|
||||
struct st_dynamic_array *init_commands;
|
||||
char *my_cnf_file,*my_cnf_group, *charset_dir, *charset_name;
|
||||
char *ssl_key; /* PEM key file */
|
||||
char *ssl_cert; /* PEM cert file */
|
||||
char *ssl_ca; /* PEM CA file */
|
||||
char *ssl_capath; /* PEM directory of CA-s? */
|
||||
char *ssl_cipher; /* cipher to use */
|
||||
char *shared_memory_base_name;
|
||||
unsigned long max_allowed_packet;
|
||||
my_bool use_ssl; /* Deprecated ! Former use_ssl */
|
||||
my_bool compress,named_pipe;
|
||||
my_bool unused1;
|
||||
my_bool unused2;
|
||||
my_bool unused3;
|
||||
my_bool unused4;
|
||||
enum mysql_option methods_to_use;
|
||||
union {
|
||||
/*
|
||||
The ip/hostname to use when authenticating
|
||||
client against embedded server built with
|
||||
grant tables - only used in embedded server
|
||||
*/
|
||||
char *client_ip;
|
||||
|
||||
/*
|
||||
The local address to bind when connecting to
|
||||
remote server - not used in embedded server
|
||||
*/
|
||||
char *bind_address;
|
||||
} ci;
|
||||
my_bool unused5;
|
||||
/* 0 - never report, 1 - always report (default) */
|
||||
my_bool report_data_truncation;
|
||||
|
||||
/* function pointers for local infile support */
|
||||
int (*local_infile_init)(void **, const char *, void *);
|
||||
int (*local_infile_read)(void *, char *, unsigned int);
|
||||
void (*local_infile_end)(void *);
|
||||
int (*local_infile_error)(void *, char *, unsigned int);
|
||||
void *local_infile_userdata;
|
||||
struct st_mysql_options_extention *extension;
|
||||
};
|
||||
|
||||
enum mysql_status
|
||||
{
|
||||
MYSQL_STATUS_READY, MYSQL_STATUS_GET_RESULT, MYSQL_STATUS_USE_RESULT,
|
||||
MYSQL_STATUS_STATEMENT_GET_RESULT
|
||||
};
|
||||
|
||||
enum mysql_protocol_type
|
||||
{
|
||||
MYSQL_PROTOCOL_DEFAULT, MYSQL_PROTOCOL_TCP, MYSQL_PROTOCOL_SOCKET,
|
||||
MYSQL_PROTOCOL_PIPE, MYSQL_PROTOCOL_MEMORY
|
||||
};
|
||||
|
||||
enum mysql_ssl_mode
|
||||
{
|
||||
SSL_MODE_DISABLED= 1, SSL_MODE_PREFERRED, SSL_MODE_REQUIRED,
|
||||
SSL_MODE_VERIFY_CA, SSL_MODE_VERIFY_IDENTITY
|
||||
};
|
||||
|
||||
typedef struct character_set
|
||||
{
|
||||
unsigned int number; /* character set number */
|
||||
unsigned int state; /* character set state */
|
||||
const char *csname; /* collation name */
|
||||
const char *name; /* character set name */
|
||||
const char *comment; /* comment */
|
||||
const char *dir; /* character set directory */
|
||||
unsigned int mbminlen; /* min. length for multibyte strings */
|
||||
unsigned int mbmaxlen; /* max. length for multibyte strings */
|
||||
} MY_CHARSET_INFO;
|
||||
|
||||
struct st_mysql_methods;
|
||||
struct st_mysql_stmt;
|
||||
|
||||
typedef struct st_mysql
|
||||
{
|
||||
NET net; /* Communication parameters */
|
||||
unsigned char *connector_fd; /* ConnectorFd for SSL */
|
||||
char *host,*user,*passwd,*unix_socket,*server_version,*host_info;
|
||||
char *info, *db;
|
||||
struct charset_info_st *charset;
|
||||
MYSQL_FIELD *fields;
|
||||
MEM_ROOT field_alloc;
|
||||
my_ulonglong affected_rows;
|
||||
my_ulonglong insert_id; /* id if insert on table with NEXTNR */
|
||||
my_ulonglong extra_info; /* Not used */
|
||||
unsigned long thread_id; /* Id for connection in server */
|
||||
unsigned long packet_length;
|
||||
unsigned int port;
|
||||
unsigned long client_flag,server_capabilities;
|
||||
unsigned int protocol_version;
|
||||
unsigned int field_count;
|
||||
unsigned int server_status;
|
||||
unsigned int server_language;
|
||||
unsigned int warning_count;
|
||||
struct st_mysql_options options;
|
||||
enum mysql_status status;
|
||||
my_bool free_me; /* If free in mysql_close */
|
||||
my_bool reconnect; /* set to 1 if automatic reconnect */
|
||||
|
||||
/* session-wide random string */
|
||||
char scramble[SCRAMBLE_LENGTH+1];
|
||||
my_bool unused1;
|
||||
void *unused2, *unused3, *unused4, *unused5;
|
||||
|
||||
LIST *stmts; /* list of all statements */
|
||||
const struct st_mysql_methods *methods;
|
||||
void *thd;
|
||||
/*
|
||||
Points to boolean flag in MYSQL_RES or MYSQL_STMT. We set this flag
|
||||
from mysql_stmt_close if close had to cancel result set of this object.
|
||||
*/
|
||||
my_bool *unbuffered_fetch_owner;
|
||||
/* needed for embedded server - no net buffer to store the 'info' */
|
||||
char *info_buffer;
|
||||
void *extension;
|
||||
} MYSQL;
|
||||
|
||||
|
||||
typedef struct st_mysql_res {
|
||||
my_ulonglong row_count;
|
||||
MYSQL_FIELD *fields;
|
||||
MYSQL_DATA *data;
|
||||
MYSQL_ROWS *data_cursor;
|
||||
unsigned long *lengths; /* column lengths of current row */
|
||||
MYSQL *handle; /* for unbuffered reads */
|
||||
const struct st_mysql_methods *methods;
|
||||
MYSQL_ROW row; /* If unbuffered read */
|
||||
MYSQL_ROW current_row; /* buffer to current row */
|
||||
MEM_ROOT field_alloc;
|
||||
unsigned int field_count, current_field;
|
||||
my_bool eof; /* Used by mysql_fetch_row */
|
||||
/* mysql_stmt_close() had to cancel this result */
|
||||
my_bool unbuffered_fetch_cancelled;
|
||||
void *extension;
|
||||
} MYSQL_RES;
|
||||
|
||||
|
||||
#if !defined(MYSQL_SERVER) && !defined(MYSQL_CLIENT)
|
||||
#define MYSQL_CLIENT
|
||||
#endif
|
||||
|
||||
/*
|
||||
Set up and bring down the server; to ensure that applications will
|
||||
work when linked against either the standard client library or the
|
||||
embedded server library, these functions should be called.
|
||||
*/
|
||||
int STDCALL mysql_server_init(int argc, char **argv, char **groups);
|
||||
void STDCALL mysql_server_end(void);
|
||||
|
||||
/*
|
||||
mysql_server_init/end need to be called when using libmysqld or
|
||||
libmysqlclient (exactly, mysql_server_init() is called by mysql_init() so
|
||||
you don't need to call it explicitely; but you need to call
|
||||
mysql_server_end() to free memory). The names are a bit misleading
|
||||
(mysql_SERVER* to be used when using libmysqlCLIENT). So we add more general
|
||||
names which suit well whether you're using libmysqld or libmysqlclient. We
|
||||
intend to promote these aliases over the mysql_server* ones.
|
||||
*/
|
||||
#define mysql_library_init mysql_server_init
|
||||
#define mysql_library_end mysql_server_end
|
||||
|
||||
|
||||
/*
|
||||
Set up and bring down a thread; these function should be called
|
||||
for each thread in an application which opens at least one MySQL
|
||||
connection. All uses of the connection(s) should be between these
|
||||
function calls.
|
||||
*/
|
||||
my_bool STDCALL mysql_thread_init(void);
|
||||
void STDCALL mysql_thread_end(void);
|
||||
|
||||
/*
|
||||
Functions to get information from the MYSQL and MYSQL_RES structures
|
||||
Should definitely be used if one uses shared libraries.
|
||||
*/
|
||||
|
||||
my_ulonglong STDCALL mysql_num_rows(MYSQL_RES *res);
|
||||
unsigned int STDCALL mysql_num_fields(MYSQL_RES *res);
|
||||
my_bool STDCALL mysql_eof(MYSQL_RES *res);
|
||||
MYSQL_FIELD *STDCALL mysql_fetch_field_direct(MYSQL_RES *res,
|
||||
unsigned int fieldnr);
|
||||
MYSQL_FIELD * STDCALL mysql_fetch_fields(MYSQL_RES *res);
|
||||
MYSQL_ROW_OFFSET STDCALL mysql_row_tell(MYSQL_RES *res);
|
||||
MYSQL_FIELD_OFFSET STDCALL mysql_field_tell(MYSQL_RES *res);
|
||||
|
||||
unsigned int STDCALL mysql_field_count(MYSQL *mysql);
|
||||
my_ulonglong STDCALL mysql_affected_rows(MYSQL *mysql);
|
||||
my_ulonglong STDCALL mysql_insert_id(MYSQL *mysql);
|
||||
unsigned int STDCALL mysql_errno(MYSQL *mysql);
|
||||
const char * STDCALL mysql_error(MYSQL *mysql);
|
||||
const char *STDCALL mysql_sqlstate(MYSQL *mysql);
|
||||
unsigned int STDCALL mysql_warning_count(MYSQL *mysql);
|
||||
const char * STDCALL mysql_info(MYSQL *mysql);
|
||||
unsigned long STDCALL mysql_thread_id(MYSQL *mysql);
|
||||
const char * STDCALL mysql_character_set_name(MYSQL *mysql);
|
||||
int STDCALL mysql_set_character_set(MYSQL *mysql, const char *csname);
|
||||
|
||||
MYSQL * STDCALL mysql_init(MYSQL *mysql);
|
||||
my_bool STDCALL mysql_ssl_set(MYSQL *mysql, const char *key,
|
||||
const char *cert, const char *ca,
|
||||
const char *capath, const char *cipher);
|
||||
const char * STDCALL mysql_get_ssl_cipher(MYSQL *mysql);
|
||||
my_bool STDCALL mysql_change_user(MYSQL *mysql, const char *user,
|
||||
const char *passwd, const char *db);
|
||||
MYSQL * STDCALL mysql_real_connect(MYSQL *mysql, const char *host,
|
||||
const char *user,
|
||||
const char *passwd,
|
||||
const char *db,
|
||||
unsigned int port,
|
||||
const char *unix_socket,
|
||||
unsigned long clientflag);
|
||||
int STDCALL mysql_select_db(MYSQL *mysql, const char *db);
|
||||
int STDCALL mysql_query(MYSQL *mysql, const char *q);
|
||||
int STDCALL mysql_send_query(MYSQL *mysql, const char *q,
|
||||
unsigned long length);
|
||||
int STDCALL mysql_real_query(MYSQL *mysql, const char *q,
|
||||
unsigned long length);
|
||||
MYSQL_RES * STDCALL mysql_store_result(MYSQL *mysql);
|
||||
MYSQL_RES * STDCALL mysql_use_result(MYSQL *mysql);
|
||||
|
||||
void STDCALL mysql_get_character_set_info(MYSQL *mysql,
|
||||
MY_CHARSET_INFO *charset);
|
||||
|
||||
int STDCALL mysql_session_track_get_first(MYSQL *mysql,
|
||||
enum enum_session_state_type type,
|
||||
const char **data,
|
||||
size_t *length);
|
||||
int STDCALL mysql_session_track_get_next(MYSQL *mysql,
|
||||
enum enum_session_state_type type,
|
||||
const char **data,
|
||||
size_t *length);
|
||||
/* local infile support */
|
||||
|
||||
#define LOCAL_INFILE_ERROR_LEN 512
|
||||
|
||||
void
|
||||
mysql_set_local_infile_handler(MYSQL *mysql,
|
||||
int (*local_infile_init)(void **, const char *,
|
||||
void *),
|
||||
int (*local_infile_read)(void *, char *,
|
||||
unsigned int),
|
||||
void (*local_infile_end)(void *),
|
||||
int (*local_infile_error)(void *, char*,
|
||||
unsigned int),
|
||||
void *);
|
||||
|
||||
void
|
||||
mysql_set_local_infile_default(MYSQL *mysql);
|
||||
|
||||
int STDCALL mysql_shutdown(MYSQL *mysql,
|
||||
enum mysql_enum_shutdown_level
|
||||
shutdown_level);
|
||||
int STDCALL mysql_dump_debug_info(MYSQL *mysql);
|
||||
int STDCALL mysql_refresh(MYSQL *mysql,
|
||||
unsigned int refresh_options);
|
||||
int STDCALL mysql_kill(MYSQL *mysql,unsigned long pid);
|
||||
int STDCALL mysql_set_server_option(MYSQL *mysql,
|
||||
enum enum_mysql_set_option
|
||||
option);
|
||||
int STDCALL mysql_ping(MYSQL *mysql);
|
||||
const char * STDCALL mysql_stat(MYSQL *mysql);
|
||||
const char * STDCALL mysql_get_server_info(MYSQL *mysql);
|
||||
const char * STDCALL mysql_get_client_info(void);
|
||||
unsigned long STDCALL mysql_get_client_version(void);
|
||||
const char * STDCALL mysql_get_host_info(MYSQL *mysql);
|
||||
unsigned long STDCALL mysql_get_server_version(MYSQL *mysql);
|
||||
unsigned int STDCALL mysql_get_proto_info(MYSQL *mysql);
|
||||
MYSQL_RES * STDCALL mysql_list_dbs(MYSQL *mysql,const char *wild);
|
||||
MYSQL_RES * STDCALL mysql_list_tables(MYSQL *mysql,const char *wild);
|
||||
MYSQL_RES * STDCALL mysql_list_processes(MYSQL *mysql);
|
||||
int STDCALL mysql_options(MYSQL *mysql,enum mysql_option option,
|
||||
const void *arg);
|
||||
int STDCALL mysql_options4(MYSQL *mysql,enum mysql_option option,
|
||||
const void *arg1, const void *arg2);
|
||||
int STDCALL mysql_get_option(MYSQL *mysql, enum mysql_option option,
|
||||
const void *arg);
|
||||
void STDCALL mysql_free_result(MYSQL_RES *result);
|
||||
void STDCALL mysql_data_seek(MYSQL_RES *result,
|
||||
my_ulonglong offset);
|
||||
MYSQL_ROW_OFFSET STDCALL mysql_row_seek(MYSQL_RES *result,
|
||||
MYSQL_ROW_OFFSET offset);
|
||||
MYSQL_FIELD_OFFSET STDCALL mysql_field_seek(MYSQL_RES *result,
|
||||
MYSQL_FIELD_OFFSET offset);
|
||||
MYSQL_ROW STDCALL mysql_fetch_row(MYSQL_RES *result);
|
||||
unsigned long * STDCALL mysql_fetch_lengths(MYSQL_RES *result);
|
||||
MYSQL_FIELD * STDCALL mysql_fetch_field(MYSQL_RES *result);
|
||||
MYSQL_RES * STDCALL mysql_list_fields(MYSQL *mysql, const char *table,
|
||||
const char *wild);
|
||||
unsigned long STDCALL mysql_escape_string(char *to,const char *from,
|
||||
unsigned long from_length);
|
||||
unsigned long STDCALL mysql_hex_string(char *to,const char *from,
|
||||
unsigned long from_length);
|
||||
unsigned long STDCALL mysql_real_escape_string(MYSQL *mysql,
|
||||
char *to,const char *from,
|
||||
unsigned long length);
|
||||
unsigned long STDCALL mysql_real_escape_string_quote(MYSQL *mysql,
|
||||
char *to, const char *from,
|
||||
unsigned long length, char quote);
|
||||
void STDCALL mysql_debug(const char *debug);
|
||||
void STDCALL myodbc_remove_escape(MYSQL *mysql,char *name);
|
||||
unsigned int STDCALL mysql_thread_safe(void);
|
||||
my_bool STDCALL mysql_embedded(void);
|
||||
my_bool STDCALL mysql_read_query_result(MYSQL *mysql);
|
||||
int STDCALL mysql_reset_connection(MYSQL *mysql);
|
||||
|
||||
/*
|
||||
The following definitions are added for the enhanced
|
||||
client-server protocol
|
||||
*/
|
||||
|
||||
/* statement state */
|
||||
enum enum_mysql_stmt_state
|
||||
{
|
||||
MYSQL_STMT_INIT_DONE= 1, MYSQL_STMT_PREPARE_DONE, MYSQL_STMT_EXECUTE_DONE,
|
||||
MYSQL_STMT_FETCH_DONE
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
This structure is used to define bind information, and
|
||||
internally by the client library.
|
||||
Public members with their descriptions are listed below
|
||||
(conventionally `On input' refers to the binds given to
|
||||
mysql_stmt_bind_param, `On output' refers to the binds given
|
||||
to mysql_stmt_bind_result):
|
||||
|
||||
buffer_type - One of the MYSQL_* types, used to describe
|
||||
the host language type of buffer.
|
||||
On output: if column type is different from
|
||||
buffer_type, column value is automatically converted
|
||||
to buffer_type before it is stored in the buffer.
|
||||
buffer - On input: points to the buffer with input data.
|
||||
On output: points to the buffer capable to store
|
||||
output data.
|
||||
The type of memory pointed by buffer must correspond
|
||||
to buffer_type. See the correspondence table in
|
||||
the comment to mysql_stmt_bind_param.
|
||||
|
||||
The two above members are mandatory for any kind of bind.
|
||||
|
||||
buffer_length - the length of the buffer. You don't have to set
|
||||
it for any fixed length buffer: float, double,
|
||||
int, etc. It must be set however for variable-length
|
||||
types, such as BLOBs or STRINGs.
|
||||
|
||||
length - On input: in case when lengths of input values
|
||||
are different for each execute, you can set this to
|
||||
point at a variable containining value length. This
|
||||
way the value length can be different in each execute.
|
||||
If length is not NULL, buffer_length is not used.
|
||||
Note, length can even point at buffer_length if
|
||||
you keep bind structures around while fetching:
|
||||
this way you can change buffer_length before
|
||||
each execution, everything will work ok.
|
||||
On output: if length is set, mysql_stmt_fetch will
|
||||
write column length into it.
|
||||
|
||||
is_null - On input: points to a boolean variable that should
|
||||
be set to TRUE for NULL values.
|
||||
This member is useful only if your data may be
|
||||
NULL in some but not all cases.
|
||||
If your data is never NULL, is_null should be set to 0.
|
||||
If your data is always NULL, set buffer_type
|
||||
to MYSQL_TYPE_NULL, and is_null will not be used.
|
||||
|
||||
is_unsigned - On input: used to signify that values provided for one
|
||||
of numeric types are unsigned.
|
||||
On output describes signedness of the output buffer.
|
||||
If, taking into account is_unsigned flag, column data
|
||||
is out of range of the output buffer, data for this column
|
||||
is regarded truncated. Note that this has no correspondence
|
||||
to the sign of result set column, if you need to find it out
|
||||
use mysql_stmt_result_metadata.
|
||||
error - where to write a truncation error if it is present.
|
||||
possible error value is:
|
||||
0 no truncation
|
||||
1 value is out of range or buffer is too small
|
||||
|
||||
Please note that MYSQL_BIND also has internals members.
|
||||
*/
|
||||
|
||||
typedef struct st_mysql_bind
|
||||
{
|
||||
unsigned long *length; /* output length pointer */
|
||||
my_bool *is_null; /* Pointer to null indicator */
|
||||
void *buffer; /* buffer to get/put data */
|
||||
/* set this if you want to track data truncations happened during fetch */
|
||||
my_bool *error;
|
||||
unsigned char *row_ptr; /* for the current data position */
|
||||
void (*store_param_func)(NET *net, struct st_mysql_bind *param);
|
||||
void (*fetch_result)(struct st_mysql_bind *, MYSQL_FIELD *,
|
||||
unsigned char **row);
|
||||
void (*skip_result)(struct st_mysql_bind *, MYSQL_FIELD *,
|
||||
unsigned char **row);
|
||||
/* output buffer length, must be set when fetching str/binary */
|
||||
unsigned long buffer_length;
|
||||
unsigned long offset; /* offset position for char/binary fetch */
|
||||
unsigned long length_value; /* Used if length is 0 */
|
||||
unsigned int param_number; /* For null count and error messages */
|
||||
unsigned int pack_length; /* Internal length for packed data */
|
||||
enum enum_field_types buffer_type; /* buffer type */
|
||||
my_bool error_value; /* used if error is 0 */
|
||||
my_bool is_unsigned; /* set if integer type is unsigned */
|
||||
my_bool long_data_used; /* If used with mysql_send_long_data */
|
||||
my_bool is_null_value; /* Used if is_null is 0 */
|
||||
void *extension;
|
||||
} MYSQL_BIND;
|
||||
|
||||
|
||||
struct st_mysql_stmt_extension;
|
||||
|
||||
/* statement handler */
|
||||
typedef struct st_mysql_stmt
|
||||
{
|
||||
MEM_ROOT mem_root; /* root allocations */
|
||||
LIST list; /* list to keep track of all stmts */
|
||||
MYSQL *mysql; /* connection handle */
|
||||
MYSQL_BIND *params; /* input parameters */
|
||||
MYSQL_BIND *bind; /* output parameters */
|
||||
MYSQL_FIELD *fields; /* result set metadata */
|
||||
MYSQL_DATA result; /* cached result set */
|
||||
MYSQL_ROWS *data_cursor; /* current row in cached result */
|
||||
/*
|
||||
mysql_stmt_fetch() calls this function to fetch one row (it's different
|
||||
for buffered, unbuffered and cursor fetch).
|
||||
*/
|
||||
int (*read_row_func)(struct st_mysql_stmt *stmt,
|
||||
unsigned char **row);
|
||||
/* copy of mysql->affected_rows after statement execution */
|
||||
my_ulonglong affected_rows;
|
||||
my_ulonglong insert_id; /* copy of mysql->insert_id */
|
||||
unsigned long stmt_id; /* Id for prepared statement */
|
||||
unsigned long flags; /* i.e. type of cursor to open */
|
||||
unsigned long prefetch_rows; /* number of rows per one COM_FETCH */
|
||||
/*
|
||||
Copied from mysql->server_status after execute/fetch to know
|
||||
server-side cursor status for this statement.
|
||||
*/
|
||||
unsigned int server_status;
|
||||
unsigned int last_errno; /* error code */
|
||||
unsigned int param_count; /* input parameter count */
|
||||
unsigned int field_count; /* number of columns in result set */
|
||||
enum enum_mysql_stmt_state state; /* statement state */
|
||||
char last_error[MYSQL_ERRMSG_SIZE]; /* error message */
|
||||
char sqlstate[SQLSTATE_LENGTH+1];
|
||||
/* Types of input parameters should be sent to server */
|
||||
my_bool send_types_to_server;
|
||||
my_bool bind_param_done; /* input buffers were supplied */
|
||||
unsigned char bind_result_done; /* output buffers were supplied */
|
||||
/* mysql_stmt_close() had to cancel this result */
|
||||
my_bool unbuffered_fetch_cancelled;
|
||||
/*
|
||||
Is set to true if we need to calculate field->max_length for
|
||||
metadata fields when doing mysql_stmt_store_result.
|
||||
*/
|
||||
my_bool update_max_length;
|
||||
struct st_mysql_stmt_extension *extension;
|
||||
} MYSQL_STMT;
|
||||
|
||||
enum enum_stmt_attr_type
|
||||
{
|
||||
/*
|
||||
When doing mysql_stmt_store_result calculate max_length attribute
|
||||
of statement metadata. This is to be consistent with the old API,
|
||||
where this was done automatically.
|
||||
In the new API we do that only by request because it slows down
|
||||
mysql_stmt_store_result sufficiently.
|
||||
*/
|
||||
STMT_ATTR_UPDATE_MAX_LENGTH,
|
||||
/*
|
||||
unsigned long with combination of cursor flags (read only, for update,
|
||||
etc)
|
||||
*/
|
||||
STMT_ATTR_CURSOR_TYPE,
|
||||
/*
|
||||
Amount of rows to retrieve from server per one fetch if using cursors.
|
||||
Accepts unsigned long attribute in the range 1 - ulong_max
|
||||
*/
|
||||
STMT_ATTR_PREFETCH_ROWS
|
||||
};
|
||||
|
||||
|
||||
MYSQL_STMT * STDCALL mysql_stmt_init(MYSQL *mysql);
|
||||
int STDCALL mysql_stmt_prepare(MYSQL_STMT *stmt, const char *query,
|
||||
unsigned long length);
|
||||
int STDCALL mysql_stmt_execute(MYSQL_STMT *stmt);
|
||||
int STDCALL mysql_stmt_fetch(MYSQL_STMT *stmt);
|
||||
int STDCALL mysql_stmt_fetch_column(MYSQL_STMT *stmt, MYSQL_BIND *bind_arg,
|
||||
unsigned int column,
|
||||
unsigned long offset);
|
||||
int STDCALL mysql_stmt_store_result(MYSQL_STMT *stmt);
|
||||
unsigned long STDCALL mysql_stmt_param_count(MYSQL_STMT * stmt);
|
||||
my_bool STDCALL mysql_stmt_attr_set(MYSQL_STMT *stmt,
|
||||
enum enum_stmt_attr_type attr_type,
|
||||
const void *attr);
|
||||
my_bool STDCALL mysql_stmt_attr_get(MYSQL_STMT *stmt,
|
||||
enum enum_stmt_attr_type attr_type,
|
||||
void *attr);
|
||||
my_bool STDCALL mysql_stmt_bind_param(MYSQL_STMT * stmt, MYSQL_BIND * bnd);
|
||||
my_bool STDCALL mysql_stmt_bind_result(MYSQL_STMT * stmt, MYSQL_BIND * bnd);
|
||||
my_bool STDCALL mysql_stmt_close(MYSQL_STMT * stmt);
|
||||
my_bool STDCALL mysql_stmt_reset(MYSQL_STMT * stmt);
|
||||
my_bool STDCALL mysql_stmt_free_result(MYSQL_STMT *stmt);
|
||||
my_bool STDCALL mysql_stmt_send_long_data(MYSQL_STMT *stmt,
|
||||
unsigned int param_number,
|
||||
const char *data,
|
||||
unsigned long length);
|
||||
MYSQL_RES *STDCALL mysql_stmt_result_metadata(MYSQL_STMT *stmt);
|
||||
MYSQL_RES *STDCALL mysql_stmt_param_metadata(MYSQL_STMT *stmt);
|
||||
unsigned int STDCALL mysql_stmt_errno(MYSQL_STMT * stmt);
|
||||
const char *STDCALL mysql_stmt_error(MYSQL_STMT * stmt);
|
||||
const char *STDCALL mysql_stmt_sqlstate(MYSQL_STMT * stmt);
|
||||
MYSQL_ROW_OFFSET STDCALL mysql_stmt_row_seek(MYSQL_STMT *stmt,
|
||||
MYSQL_ROW_OFFSET offset);
|
||||
MYSQL_ROW_OFFSET STDCALL mysql_stmt_row_tell(MYSQL_STMT *stmt);
|
||||
void STDCALL mysql_stmt_data_seek(MYSQL_STMT *stmt, my_ulonglong offset);
|
||||
my_ulonglong STDCALL mysql_stmt_num_rows(MYSQL_STMT *stmt);
|
||||
my_ulonglong STDCALL mysql_stmt_affected_rows(MYSQL_STMT *stmt);
|
||||
my_ulonglong STDCALL mysql_stmt_insert_id(MYSQL_STMT *stmt);
|
||||
unsigned int STDCALL mysql_stmt_field_count(MYSQL_STMT *stmt);
|
||||
|
||||
my_bool STDCALL mysql_commit(MYSQL * mysql);
|
||||
my_bool STDCALL mysql_rollback(MYSQL * mysql);
|
||||
my_bool STDCALL mysql_autocommit(MYSQL * mysql, my_bool auto_mode);
|
||||
my_bool STDCALL mysql_more_results(MYSQL *mysql);
|
||||
int STDCALL mysql_next_result(MYSQL *mysql);
|
||||
int STDCALL mysql_stmt_next_result(MYSQL_STMT *stmt);
|
||||
void STDCALL mysql_close(MYSQL *sock);
|
||||
|
||||
|
||||
/* status return codes */
|
||||
#define MYSQL_NO_DATA 100
|
||||
#define MYSQL_DATA_TRUNCATED 101
|
||||
|
||||
#define mysql_reload(mysql) mysql_refresh((mysql),REFRESH_GRANT)
|
||||
|
||||
#define HAVE_MYSQL_REAL_CONNECT
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _mysql_h */
|
|
@ -0,0 +1,38 @@
|
|||
/* Copyright (c) 2012, 2022, Oracle and/or its affiliates.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License, version 2.0,
|
||||
as published by the Free Software Foundation.
|
||||
|
||||
This program is also distributed with certain software (including
|
||||
but not limited to OpenSSL) that is licensed under separate terms,
|
||||
as designated in a particular file or component or in included license
|
||||
documentation. The authors of MySQL hereby grant you an additional
|
||||
permission to link the program and your derivative works with the
|
||||
separately licensed software that they have included with MySQL.
|
||||
|
||||
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, version 2.0, 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 St, Fifth Floor, Boston, MA 02110-1301 USA */
|
||||
#ifndef CLIENT_AUTHENTICATION_H
|
||||
#define CLIENT_AUTHENTICATION_H
|
||||
#include <my_global.h>
|
||||
#include "mysql.h"
|
||||
#include "mysql/client_plugin.h"
|
||||
|
||||
C_MODE_START
|
||||
int sha256_password_auth_client(MYSQL_PLUGIN_VIO *vio, MYSQL *mysql);
|
||||
int sha256_password_init(char *, size_t, int, va_list);
|
||||
int sha256_password_deinit(void);
|
||||
int caching_sha2_password_auth_client(MYSQL_PLUGIN_VIO *vio, MYSQL *mysql);
|
||||
int caching_sha2_password_init(char *, size_t, int, va_list);
|
||||
int caching_sha2_password_deinit(void);
|
||||
C_MODE_END
|
||||
|
||||
#endif
|
||||
|
|
@ -27,8 +27,10 @@
|
|||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
|
||||
|
||||
/**
|
||||
@file include/mysql/client_plugin.h
|
||||
MySQL Client Plugin API.
|
||||
@file
|
||||
|
||||
MySQL Client Plugin API
|
||||
|
||||
This file defines the API for plugins that work on the client side
|
||||
*/
|
||||
#define MYSQL_CLIENT_PLUGIN_INCLUDED
|
||||
|
@ -49,27 +51,22 @@
|
|||
|
||||
#if defined(_MSC_VER)
|
||||
#if defined(MYSQL_DYNAMIC_PLUGIN)
|
||||
#ifdef __cplusplus
|
||||
#define MYSQL_PLUGIN_EXPORT extern "C" __declspec(dllexport)
|
||||
#else
|
||||
#define MYSQL_PLUGIN_EXPORT __declspec(dllexport)
|
||||
#endif
|
||||
#ifdef __cplusplus
|
||||
#define MYSQL_PLUGIN_EXPORT extern "C" __declspec(dllexport)
|
||||
#else
|
||||
#define MYSQL_PLUGIN_EXPORT __declspec(dllexport)
|
||||
#endif
|
||||
#else /* MYSQL_DYNAMIC_PLUGIN */
|
||||
#ifdef __cplusplus
|
||||
#define MYSQL_PLUGIN_EXPORT extern "C"
|
||||
#else
|
||||
#define MYSQL_PLUGIN_EXPORT
|
||||
#endif
|
||||
#ifdef __cplusplus
|
||||
#define MYSQL_PLUGIN_EXPORT extern "C"
|
||||
#else
|
||||
#define MYSQL_PLUGIN_EXPORT
|
||||
#endif
|
||||
#endif /*MYSQL_DYNAMIC_PLUGIN */
|
||||
#else /*_MSC_VER */
|
||||
|
||||
#if defined(MYSQL_DYNAMIC_PLUGIN)
|
||||
#define MYSQL_PLUGIN_EXPORT MY_ATTRIBUTE((visibility("default")))
|
||||
#else
|
||||
#define MYSQL_PLUGIN_EXPORT
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
@ -81,18 +78,16 @@ extern "C" {
|
|||
#define MYSQL_CLIENT_AUTHENTICATION_PLUGIN 2
|
||||
#define MYSQL_CLIENT_TRACE_PLUGIN 3
|
||||
|
||||
#define MYSQL_CLIENT_AUTHENTICATION_PLUGIN_INTERFACE_VERSION 0x0200
|
||||
#define MYSQL_CLIENT_TRACE_PLUGIN_INTERFACE_VERSION 0x0200
|
||||
#define MYSQL_CLIENT_AUTHENTICATION_PLUGIN_INTERFACE_VERSION 0x0100
|
||||
#define MYSQL_CLIENT_TRACE_PLUGIN_INTERFACE_VERSION 0x0100
|
||||
|
||||
#define MYSQL_CLIENT_MAX_PLUGINS 4
|
||||
|
||||
#define MYSQL_CLIENT_PLUGIN_AUTHOR_ORACLE "Oracle Corporation"
|
||||
|
||||
#define mysql_declare_client_plugin(X) \
|
||||
MYSQL_PLUGIN_EXPORT st_mysql_client_plugin_##X \
|
||||
MYSQL_PLUGIN_EXPORT struct st_mysql_client_plugin_ ## X \
|
||||
_mysql_client_plugin_declaration_ = { \
|
||||
MYSQL_CLIENT_##X##_PLUGIN, \
|
||||
MYSQL_CLIENT_##X##_PLUGIN_INTERFACE_VERSION,
|
||||
MYSQL_CLIENT_ ## X ## _PLUGIN, \
|
||||
MYSQL_CLIENT_ ## X ## _PLUGIN_INTERFACE_VERSION,
|
||||
#define mysql_end_client_plugin }
|
||||
|
||||
/* generic plugin header structure */
|
||||
|
@ -107,29 +102,24 @@ extern "C" {
|
|||
void *mysql_api; \
|
||||
int (*init)(char *, size_t, int, va_list); \
|
||||
int (*deinit)(void); \
|
||||
int (*options)(const char *option, const void *); \
|
||||
int (*get_options)(const char *option, void *);
|
||||
int (*options)(const char *option, const void *);
|
||||
|
||||
struct st_mysql_client_plugin {
|
||||
struct st_mysql_client_plugin
|
||||
{
|
||||
MYSQL_CLIENT_PLUGIN_HEADER
|
||||
};
|
||||
|
||||
struct MYSQL;
|
||||
struct st_mysql;
|
||||
|
||||
/******** authentication plugin specific declarations *********/
|
||||
#include "plugin_auth_common.h"
|
||||
|
||||
struct auth_plugin_t {
|
||||
struct st_mysql_client_plugin_AUTHENTICATION
|
||||
{
|
||||
MYSQL_CLIENT_PLUGIN_HEADER
|
||||
int (*authenticate_user)(MYSQL_PLUGIN_VIO *vio, struct MYSQL *mysql);
|
||||
enum net_async_status (*authenticate_user_nonblocking)(MYSQL_PLUGIN_VIO *vio,
|
||||
struct MYSQL *mysql,
|
||||
int *result);
|
||||
int (*authenticate_user)(MYSQL_PLUGIN_VIO *vio, struct st_mysql *mysql);
|
||||
};
|
||||
|
||||
// Needed for the mysql_declare_client_plugin() macro. Do not use elsewhere.
|
||||
typedef struct auth_plugin_t st_mysql_client_plugin_AUTHENTICATION;
|
||||
|
||||
/******** using plugins ************/
|
||||
|
||||
/**
|
||||
|
@ -145,8 +135,8 @@ typedef struct auth_plugin_t st_mysql_client_plugin_AUTHENTICATION;
|
|||
@retval
|
||||
a pointer to the loaded plugin, or NULL in case of a failure
|
||||
*/
|
||||
struct st_mysql_client_plugin *mysql_load_plugin(struct MYSQL *mysql,
|
||||
const char *name, int type,
|
||||
struct st_mysql_client_plugin *
|
||||
mysql_load_plugin(struct st_mysql *mysql, const char *name, int type,
|
||||
int argc, ...);
|
||||
|
||||
/**
|
||||
|
@ -165,8 +155,8 @@ struct st_mysql_client_plugin *mysql_load_plugin(struct MYSQL *mysql,
|
|||
@retval
|
||||
a pointer to the loaded plugin, or NULL in case of a failure
|
||||
*/
|
||||
struct st_mysql_client_plugin *mysql_load_plugin_v(struct MYSQL *mysql,
|
||||
const char *name, int type,
|
||||
struct st_mysql_client_plugin *
|
||||
mysql_load_plugin_v(struct st_mysql *mysql, const char *name, int type,
|
||||
int argc, va_list args);
|
||||
|
||||
/**
|
||||
|
@ -179,9 +169,8 @@ struct st_mysql_client_plugin *mysql_load_plugin_v(struct MYSQL *mysql,
|
|||
@retval
|
||||
a pointer to the plugin, or NULL in case of a failure
|
||||
*/
|
||||
struct st_mysql_client_plugin *mysql_client_find_plugin(struct MYSQL *mysql,
|
||||
const char *name,
|
||||
int type);
|
||||
struct st_mysql_client_plugin *
|
||||
mysql_client_find_plugin(struct st_mysql *mysql, const char *name, int type);
|
||||
|
||||
/**
|
||||
adds a plugin structure to the list of loaded plugins
|
||||
|
@ -197,8 +186,9 @@ struct st_mysql_client_plugin *mysql_client_find_plugin(struct MYSQL *mysql,
|
|||
@retval
|
||||
a pointer to the plugin, or NULL in case of a failure
|
||||
*/
|
||||
struct st_mysql_client_plugin *mysql_client_register_plugin(
|
||||
struct MYSQL *mysql, struct st_mysql_client_plugin *plugin);
|
||||
struct st_mysql_client_plugin *
|
||||
mysql_client_register_plugin(struct st_mysql *mysql,
|
||||
struct st_mysql_client_plugin *plugin);
|
||||
|
||||
/**
|
||||
set plugin options
|
||||
|
@ -215,23 +205,10 @@ struct st_mysql_client_plugin *mysql_client_register_plugin(
|
|||
int mysql_plugin_options(struct st_mysql_client_plugin *plugin,
|
||||
const char *option, const void *value);
|
||||
|
||||
/**
|
||||
get plugin options
|
||||
|
||||
Can be used to get options from a plugin.
|
||||
This function may be called multiple times to get several options
|
||||
|
||||
@param plugin an st_mysql_client_plugin structure
|
||||
@param option a string which specifies the option to get
|
||||
@param[out] value value for the option.
|
||||
|
||||
@retval 0 on success, 1 in case of failure
|
||||
**/
|
||||
int mysql_plugin_get_option(struct st_mysql_client_plugin *plugin,
|
||||
const char *option, void *value);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
struct st_mysql_client_plugin
|
||||
{
|
||||
int type; unsigned int interface_version; const char *name; const char *author; const char *desc; unsigned int version[3]; const char *license; void *mysql_api; int (*init)(char *, size_t, int, va_list); int (*deinit)(void); int (*options)(const char *option, const void *);
|
||||
};
|
||||
struct st_mysql;
|
||||
#include "plugin_auth_common.h"
|
||||
typedef struct st_plugin_vio_info
|
||||
{
|
||||
enum { MYSQL_VIO_INVALID, MYSQL_VIO_TCP, MYSQL_VIO_SOCKET,
|
||||
MYSQL_VIO_PIPE, MYSQL_VIO_MEMORY } protocol;
|
||||
int socket;
|
||||
} MYSQL_PLUGIN_VIO_INFO;
|
||||
typedef struct st_plugin_vio
|
||||
{
|
||||
int (*read_packet)(struct st_plugin_vio *vio,
|
||||
unsigned char **buf);
|
||||
int (*write_packet)(struct st_plugin_vio *vio,
|
||||
const unsigned char *packet,
|
||||
int packet_len);
|
||||
void (*info)(struct st_plugin_vio *vio, struct st_plugin_vio_info *info);
|
||||
} MYSQL_PLUGIN_VIO;
|
||||
struct st_mysql_client_plugin_AUTHENTICATION
|
||||
{
|
||||
int type; unsigned int interface_version; const char *name; const char *author; const char *desc; unsigned int version[3]; const char *license; void *mysql_api; int (*init)(char *, size_t, int, va_list); int (*deinit)(void); int (*options)(const char *option, const void *);
|
||||
int (*authenticate_user)(MYSQL_PLUGIN_VIO *vio, struct st_mysql *mysql);
|
||||
};
|
||||
struct st_mysql_client_plugin *
|
||||
mysql_load_plugin(struct st_mysql *mysql, const char *name, int type,
|
||||
int argc, ...);
|
||||
struct st_mysql_client_plugin *
|
||||
mysql_load_plugin_v(struct st_mysql *mysql, const char *name, int type,
|
||||
int argc, va_list args);
|
||||
struct st_mysql_client_plugin *
|
||||
mysql_client_find_plugin(struct st_mysql *mysql, const char *name, int type);
|
||||
struct st_mysql_client_plugin *
|
||||
mysql_client_register_plugin(struct st_mysql *mysql,
|
||||
struct st_mysql_client_plugin *plugin);
|
||||
int mysql_plugin_options(struct st_mysql_client_plugin *plugin,
|
||||
const char *option, const void *value);
|
|
@ -0,0 +1,132 @@
|
|||
/* Copyright (c) 2015, 2022, Oracle and/or its affiliates.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License, version 2.0,
|
||||
as published by the Free Software Foundation.
|
||||
|
||||
This program is also distributed with certain software (including
|
||||
but not limited to OpenSSL) that is licensed under separate terms,
|
||||
as designated in a particular file or component or in included license
|
||||
documentation. The authors of MySQL hereby grant you an additional
|
||||
permission to link the program and your derivative works with the
|
||||
separately licensed software that they have included with MySQL.
|
||||
|
||||
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, version 2.0, 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 St, Fifth Floor, Boston, MA 02110-1301 USA */
|
||||
#ifndef PLUGIN_PROTOCOL_INCLUDED
|
||||
#define PLUGIN_PROTOCOL_INCLUDED
|
||||
|
||||
#ifndef MYSQL_ABI_CHECK
|
||||
#include "my_global.h" /* Needed for my_bool in mysql_com.h */
|
||||
#include "mysql_com.h" /* mysql_enum_shutdown_level */
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
@file
|
||||
Definition of COM_DATA to be used with the Command service as data input
|
||||
structure.
|
||||
*/
|
||||
|
||||
|
||||
typedef struct st_com_init_db_data
|
||||
{
|
||||
const char *db_name;
|
||||
unsigned long length;
|
||||
} COM_INIT_DB_DATA;
|
||||
|
||||
typedef struct st_com_refresh_data
|
||||
{
|
||||
unsigned char options;
|
||||
} COM_REFRESH_DATA;
|
||||
|
||||
typedef struct st_com_shutdown_data
|
||||
{
|
||||
enum mysql_enum_shutdown_level level;
|
||||
} COM_SHUTDOWN_DATA;
|
||||
|
||||
typedef struct st_com_kill_data
|
||||
{
|
||||
unsigned long id;
|
||||
} COM_KILL_DATA;
|
||||
|
||||
typedef struct st_com_set_option_data
|
||||
{
|
||||
unsigned int opt_command;
|
||||
} COM_SET_OPTION_DATA;
|
||||
|
||||
typedef struct st_com_stmt_execute_data
|
||||
{
|
||||
unsigned long stmt_id;
|
||||
unsigned long flags;
|
||||
unsigned char *params;
|
||||
unsigned long params_length;
|
||||
} COM_STMT_EXECUTE_DATA;
|
||||
|
||||
typedef struct st_com_stmt_fetch_data
|
||||
{
|
||||
unsigned long stmt_id;
|
||||
unsigned long num_rows;
|
||||
} COM_STMT_FETCH_DATA;
|
||||
|
||||
typedef struct st_com_stmt_send_long_data_data
|
||||
{
|
||||
unsigned long stmt_id;
|
||||
unsigned int param_number;
|
||||
unsigned char *longdata;
|
||||
unsigned long length;
|
||||
} COM_STMT_SEND_LONG_DATA_DATA;
|
||||
|
||||
typedef struct st_com_stmt_prepare_data
|
||||
{
|
||||
const char *query;
|
||||
unsigned int length;
|
||||
} COM_STMT_PREPARE_DATA;
|
||||
|
||||
typedef struct st_stmt_close_data
|
||||
{
|
||||
unsigned int stmt_id;
|
||||
} COM_STMT_CLOSE_DATA;
|
||||
|
||||
typedef struct st_com_stmt_reset_data
|
||||
{
|
||||
unsigned int stmt_id;
|
||||
} COM_STMT_RESET_DATA;
|
||||
|
||||
typedef struct st_com_query_data
|
||||
{
|
||||
const char *query;
|
||||
unsigned int length;
|
||||
} COM_QUERY_DATA;
|
||||
|
||||
typedef struct st_com_field_list_data
|
||||
{
|
||||
unsigned char *table_name;
|
||||
unsigned int table_name_length;
|
||||
const unsigned char *query;
|
||||
unsigned int query_length;
|
||||
} COM_FIELD_LIST_DATA;
|
||||
|
||||
union COM_DATA {
|
||||
COM_INIT_DB_DATA com_init_db;
|
||||
COM_REFRESH_DATA com_refresh;
|
||||
COM_SHUTDOWN_DATA com_shutdown;
|
||||
COM_KILL_DATA com_kill;
|
||||
COM_SET_OPTION_DATA com_set_option;
|
||||
COM_STMT_EXECUTE_DATA com_stmt_execute;
|
||||
COM_STMT_FETCH_DATA com_stmt_fetch;
|
||||
COM_STMT_SEND_LONG_DATA_DATA com_stmt_send_long_data;
|
||||
COM_STMT_PREPARE_DATA com_stmt_prepare;
|
||||
COM_STMT_CLOSE_DATA com_stmt_close;
|
||||
COM_STMT_RESET_DATA com_stmt_reset;
|
||||
COM_QUERY_DATA com_query;
|
||||
COM_FIELD_LIST_DATA com_field_list;
|
||||
};
|
||||
|
||||
#endif /* PLUGIN_PROTOCOL_INCLUDED */
|
|
@ -0,0 +1,43 @@
|
|||
/* Copyright (c) 2000, 2022, Oracle and/or its affiliates.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License, version 2.0,
|
||||
as published by the Free Software Foundation.
|
||||
|
||||
This program is also distributed with certain software (including
|
||||
but not limited to OpenSSL) that is licensed under separate terms,
|
||||
as designated in a particular file or component or in included license
|
||||
documentation. The authors of MySQL hereby grant you an additional
|
||||
permission to link the program and your derivative works with the
|
||||
separately licensed software that they have included with MySQL.
|
||||
|
||||
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, version 2.0, 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 St, Fifth Floor, Boston, MA 02110-1301 USA */
|
||||
|
||||
/*
|
||||
** Ask for a password from tty
|
||||
** This is an own file to avoid conflicts with curses
|
||||
*/
|
||||
|
||||
#ifndef MYSQL_GET_PASSWORD_H_INCLUDED
|
||||
#define MYSQL_GET_PASSWORD_H_INCLUDED
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef char *(* strdup_handler_t)(const char *, int);
|
||||
char *get_tty_password_ext(const char *opt_message,
|
||||
strdup_handler_t strdup_function);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* ! MYSQL_GET_PASSWORD_H_INCLUDED */
|
|
@ -0,0 +1,206 @@
|
|||
/* Copyright (c) 2015, 2022, Oracle and/or its affiliates.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License, version 2.0,
|
||||
as published by the Free Software Foundation.
|
||||
|
||||
This program is also distributed with certain software (including
|
||||
but not limited to OpenSSL) that is licensed under separate terms,
|
||||
as designated in a particular file or component or in included license
|
||||
documentation. The authors of MySQL hereby grant you an additional
|
||||
permission to link the program and your derivative works with the
|
||||
separately licensed software that they have included with MySQL.
|
||||
|
||||
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, version 2.0, 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,
|
||||
51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */
|
||||
|
||||
#ifndef GROUP_REPLICATION_PRIV_INCLUDE
|
||||
#define GROUP_REPLICATION_PRIV_INCLUDE
|
||||
|
||||
#ifndef MYSQL_SERVER
|
||||
#define MYSQL_SERVER
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_REPLICATION
|
||||
#define HAVE_REPLICATION
|
||||
#endif
|
||||
|
||||
#include <my_global.h>
|
||||
#include <my_thread.h>
|
||||
#include <my_sys.h>
|
||||
|
||||
#include <debug_sync.h>
|
||||
#include <log_event.h>
|
||||
#include <replication.h>
|
||||
#include <rpl_channel_service_interface.h>
|
||||
#include <rpl_gtid.h>
|
||||
#include <rpl_write_set_handler.h>
|
||||
|
||||
|
||||
/**
|
||||
Server side initializations.
|
||||
*/
|
||||
int group_replication_init();
|
||||
|
||||
|
||||
/**
|
||||
Returns the server connection attribute
|
||||
|
||||
@Note This method implementation is on sql_class.cc
|
||||
|
||||
@return the pthread for the connection attribute.
|
||||
*/
|
||||
my_thread_attr_t *get_connection_attrib();
|
||||
|
||||
/**
|
||||
Returns the server hostname, port and uuid.
|
||||
|
||||
@param[out] hostname
|
||||
@param[out] port
|
||||
@param[out] uuid
|
||||
@param[out] server_version
|
||||
@param[out] server_ssl_variables
|
||||
|
||||
*/
|
||||
void get_server_parameters(char **hostname, uint *port, char **uuid,
|
||||
unsigned int *server_version,
|
||||
st_server_ssl_variables* server_ssl_variables);
|
||||
|
||||
/**
|
||||
Returns the server_id.
|
||||
|
||||
@return server_id
|
||||
*/
|
||||
ulong get_server_id();
|
||||
|
||||
/**
|
||||
Returns the server auto_increment_increment
|
||||
|
||||
@return auto_increment_increment
|
||||
*/
|
||||
ulong get_auto_increment_increment();
|
||||
|
||||
|
||||
/**
|
||||
Returns the server auto_increment_offset
|
||||
|
||||
@return auto_increment_offset
|
||||
*/
|
||||
ulong get_auto_increment_offset();
|
||||
|
||||
|
||||
/**
|
||||
Set server auto_increment_increment
|
||||
|
||||
@param[in] auto_increment_increment
|
||||
*/
|
||||
void set_auto_increment_increment(ulong auto_increment_increment);
|
||||
|
||||
|
||||
/**
|
||||
Set server auto_increment_offset
|
||||
|
||||
@param[in] auto_increment_offset
|
||||
*/
|
||||
void set_auto_increment_offset(ulong auto_increment_offset);
|
||||
|
||||
|
||||
/**
|
||||
Returns a struct containing all server startup information needed to evaluate
|
||||
if one has conditions to proceed executing master-master replication.
|
||||
|
||||
@param[out] requirements
|
||||
|
||||
@param[in] has_lock Caller should set this to true if the calling
|
||||
thread holds gtid_mode_lock; otherwise set it to false.
|
||||
*/
|
||||
void get_server_startup_prerequirements(Trans_context_info& requirements,
|
||||
bool has_lock);
|
||||
|
||||
|
||||
/**
|
||||
Returns the server GTID_EXECUTED encoded as a binary string.
|
||||
|
||||
@note Memory allocated to encoded_gtid_executed must be release by caller.
|
||||
|
||||
@param[out] encoded_gtid_executed binary string
|
||||
@param[out] length binary string length
|
||||
*/
|
||||
bool get_server_encoded_gtid_executed(uchar **encoded_gtid_executed,
|
||||
size_t *length);
|
||||
|
||||
#if !defined(NDEBUG)
|
||||
/**
|
||||
Returns a text representation of a encoded GTID set.
|
||||
|
||||
@note Memory allocated to returned pointer must be release by caller.
|
||||
|
||||
@param[in] encoded_gtid_set binary string
|
||||
@param[in] length binary string length
|
||||
|
||||
@return a pointer to text representation of the encoded set
|
||||
*/
|
||||
char* encoded_gtid_set_to_string(uchar *encoded_gtid_set, size_t length);
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
Return last gno for a given sidno, see
|
||||
Gtid_state::get_last_executed_gno() for details.
|
||||
*/
|
||||
rpl_gno get_last_executed_gno(rpl_sidno sidno);
|
||||
|
||||
|
||||
/**
|
||||
Return sidno for a given sid, see Sid_map::add_sid() for details.
|
||||
*/
|
||||
rpl_sidno get_sidno_from_global_sid_map(rpl_sid sid);
|
||||
|
||||
|
||||
/**
|
||||
Set slave thread default options.
|
||||
|
||||
@param[in] thd The thread
|
||||
*/
|
||||
void set_slave_thread_options(THD* thd);
|
||||
|
||||
|
||||
/**
|
||||
Add thread to Global_THD_manager singleton.
|
||||
|
||||
@param[in] thd The thread
|
||||
*/
|
||||
void global_thd_manager_add_thd(THD *thd);
|
||||
|
||||
|
||||
/**
|
||||
Remove thread from Global_THD_manager singleton.
|
||||
|
||||
@param[in] thd The thread
|
||||
*/
|
||||
void global_thd_manager_remove_thd(THD *thd);
|
||||
|
||||
/**
|
||||
Function that returns the write set extraction algorithm name.
|
||||
|
||||
@param[in] algorithm The algorithm value
|
||||
|
||||
@return the algorithm name
|
||||
*/
|
||||
const char* get_write_set_algorithm_string(unsigned int algorithm);
|
||||
|
||||
/**
|
||||
Returns the value of slave_max_allowed_packet.
|
||||
|
||||
@return slave_max_allowed_packet
|
||||
*/
|
||||
unsigned long get_slave_max_allowed_packet();
|
||||
|
||||
#endif /* GROUP_REPLICATION_PRIV_INCLUDE */
|
||||
|
|
@ -0,0 +1,62 @@
|
|||
/* Copyright (c) 2010, 2022, Oracle and/or its affiliates.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License, version 2.0,
|
||||
as published by the Free Software Foundation.
|
||||
|
||||
This program is also distributed with certain software (including
|
||||
but not limited to OpenSSL) that is licensed under separate terms,
|
||||
as designated in a particular file or component or in included license
|
||||
documentation. The authors of MySQL hereby grant you an additional
|
||||
permission to link the program and your derivative works with the
|
||||
separately licensed software that they have included with MySQL.
|
||||
|
||||
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, version 2.0, 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 INNODB_PRIV_INCLUDED
|
||||
#define INNODB_PRIV_INCLUDED
|
||||
|
||||
/** @file Declaring server-internal functions that are used by InnoDB. */
|
||||
|
||||
class THD;
|
||||
|
||||
int get_quote_char_for_identifier(THD *thd, const char *name, size_t length);
|
||||
bool schema_table_store_record(THD *thd, TABLE *table);
|
||||
void localtime_to_TIME(MYSQL_TIME *to, struct tm *from);
|
||||
bool check_global_access(THD *thd, ulong want_access);
|
||||
size_t strconvert(CHARSET_INFO *from_cs, const char *from,
|
||||
CHARSET_INFO *to_cs, char *to, size_t to_length,
|
||||
uint *errors);
|
||||
void sql_print_error(const char *format, ...);
|
||||
|
||||
/**
|
||||
Store record to I_S table, convert HEAP table to InnoDB table if necessary.
|
||||
|
||||
@param[in] thd thread handler
|
||||
@param[in] table Information schema table to be updated
|
||||
@param[in] make_ondisk if true, convert heap table to on disk table.
|
||||
default value is true.
|
||||
@return 0 on success
|
||||
@return error code on failure.
|
||||
*/
|
||||
int schema_table_store_record2(THD *thd, TABLE *table, bool make_ondisk);
|
||||
|
||||
/**
|
||||
Convert HEAP table to InnoDB table if necessary
|
||||
|
||||
@param[in] thd thread handler
|
||||
@param[in] table Information schema table to be converted.
|
||||
@param[in] error the error code returned previously.
|
||||
@return false on success, true on error.
|
||||
*/
|
||||
bool convert_heap_table_to_ondisk(THD *thd, TABLE *table, int error);
|
||||
|
||||
|
||||
#endif /* INNODB_PRIV_INCLUDED */
|
|
@ -0,0 +1,40 @@
|
|||
/* Copyright (c) 2015, 2022, Oracle and/or its affiliates.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License, version 2.0,
|
||||
as published by the Free Software Foundation.
|
||||
|
||||
This program is also distributed with certain software (including
|
||||
but not limited to OpenSSL) that is licensed under separate terms,
|
||||
as designated in a particular file or component or in included license
|
||||
documentation. The authors of MySQL hereby grant you an additional
|
||||
permission to link the program and your derivative works with the
|
||||
separately licensed software that they have included with MySQL.
|
||||
|
||||
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, version 2.0, 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 St, Fifth Floor, Boston, MA 02110-1301 USA */
|
||||
|
||||
#ifndef MYSQL_LEX_STRING_INCLUDED
|
||||
#define MYSQL_LEX_STRING_INCLUDED
|
||||
|
||||
struct st_mysql_lex_string
|
||||
{
|
||||
char *str;
|
||||
size_t length;
|
||||
};
|
||||
typedef struct st_mysql_lex_string MYSQL_LEX_STRING;
|
||||
|
||||
struct st_mysql_const_lex_string
|
||||
{
|
||||
const char *str;
|
||||
size_t length;
|
||||
};
|
||||
typedef struct st_mysql_const_lex_string MYSQL_LEX_CSTRING;
|
||||
|
||||
#endif // MYSQL_LEX_STRING_INCLUDED
|
|
@ -0,0 +1,752 @@
|
|||
/* Copyright (c) 2005, 2022, Oracle and/or its affiliates.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License, version 2.0,
|
||||
as published by the Free Software Foundation.
|
||||
|
||||
This program is also distributed with certain software (including
|
||||
but not limited to OpenSSL) that is licensed under separate terms,
|
||||
as designated in a particular file or component or in included license
|
||||
documentation. The authors of MySQL hereby grant you an additional
|
||||
permission to link the program and your derivative works with the
|
||||
separately licensed software that they have included with MySQL.
|
||||
|
||||
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, version 2.0, 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 St, Fifth Floor, Boston, MA 02110-1301 USA */
|
||||
|
||||
#ifndef _my_plugin_h
|
||||
#define _my_plugin_h
|
||||
|
||||
#ifndef MYSQL_ABI_CHECK
|
||||
#include <stddef.h>
|
||||
#include "mysql_version.h" /* MYSQL_VERSION_ID */
|
||||
#endif
|
||||
|
||||
/*
|
||||
On Windows, exports from DLL need to be declared.
|
||||
Also, plugin needs to be declared as extern "C" because MSVC
|
||||
unlike other compilers, uses C++ mangling for variables not only
|
||||
for functions.
|
||||
*/
|
||||
#if defined(_MSC_VER)
|
||||
#if defined(MYSQL_DYNAMIC_PLUGIN)
|
||||
#ifdef __cplusplus
|
||||
#define MYSQL_PLUGIN_EXPORT extern "C" __declspec(dllexport)
|
||||
#else
|
||||
#define MYSQL_PLUGIN_EXPORT __declspec(dllexport)
|
||||
#endif
|
||||
#else /* MYSQL_DYNAMIC_PLUGIN */
|
||||
#ifdef __cplusplus
|
||||
#define MYSQL_PLUGIN_EXPORT extern "C"
|
||||
#else
|
||||
#define MYSQL_PLUGIN_EXPORT
|
||||
#endif
|
||||
#endif /*MYSQL_DYNAMIC_PLUGIN */
|
||||
#else /*_MSC_VER */
|
||||
#define MYSQL_PLUGIN_EXPORT
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
class THD;
|
||||
class Item;
|
||||
#define MYSQL_THD THD*
|
||||
#else
|
||||
#define MYSQL_THD void*
|
||||
#endif
|
||||
|
||||
typedef void * MYSQL_PLUGIN;
|
||||
|
||||
#ifndef MYSQL_ABI_CHECK
|
||||
#include <mysql/services.h>
|
||||
#endif
|
||||
|
||||
#define MYSQL_XIDDATASIZE 128
|
||||
/**
|
||||
struct st_mysql_xid is binary compatible with the XID structure as
|
||||
in the X/Open CAE Specification, Distributed Transaction Processing:
|
||||
The XA Specification, X/Open Company Ltd., 1991.
|
||||
http://www.opengroup.org/bookstore/catalog/c193.htm
|
||||
|
||||
@see XID in sql/handler.h
|
||||
*/
|
||||
struct st_mysql_xid {
|
||||
long formatID;
|
||||
long gtrid_length;
|
||||
long bqual_length;
|
||||
char data[MYSQL_XIDDATASIZE]; /* Not \0-terminated */
|
||||
};
|
||||
typedef struct st_mysql_xid MYSQL_XID;
|
||||
|
||||
/*************************************************************************
|
||||
Plugin API. Common for all plugin types.
|
||||
*/
|
||||
|
||||
#define MYSQL_PLUGIN_INTERFACE_VERSION 0x0107
|
||||
|
||||
/*
|
||||
The allowable types of plugins
|
||||
*/
|
||||
#define MYSQL_UDF_PLUGIN 0 /* User-defined function */
|
||||
#define MYSQL_STORAGE_ENGINE_PLUGIN 1 /* Storage Engine */
|
||||
#define MYSQL_FTPARSER_PLUGIN 2 /* Full-text parser plugin */
|
||||
#define MYSQL_DAEMON_PLUGIN 3 /* The daemon/raw plugin type */
|
||||
#define MYSQL_INFORMATION_SCHEMA_PLUGIN 4 /* The I_S plugin type */
|
||||
#define MYSQL_AUDIT_PLUGIN 5 /* The Audit plugin type */
|
||||
#define MYSQL_REPLICATION_PLUGIN 6 /* The replication plugin type */
|
||||
#define MYSQL_AUTHENTICATION_PLUGIN 7 /* The authentication plugin type */
|
||||
#define MYSQL_VALIDATE_PASSWORD_PLUGIN 8 /* validate password plugin type */
|
||||
#define MYSQL_GROUP_REPLICATION_PLUGIN 9 /* The Group Replication plugin */
|
||||
#define MYSQL_KEYRING_PLUGIN 10 /* The Keyring plugin type */
|
||||
#define MYSQL_MAX_PLUGIN_TYPE_NUM 11 /* The number of plugin types */
|
||||
|
||||
/* We use the following strings to define licenses for plugins */
|
||||
#define PLUGIN_LICENSE_PROPRIETARY 0
|
||||
#define PLUGIN_LICENSE_GPL 1
|
||||
#define PLUGIN_LICENSE_BSD 2
|
||||
|
||||
#define PLUGIN_LICENSE_PROPRIETARY_STRING "PROPRIETARY"
|
||||
#define PLUGIN_LICENSE_GPL_STRING "GPL"
|
||||
#define PLUGIN_LICENSE_BSD_STRING "BSD"
|
||||
|
||||
/*
|
||||
Macros for beginning and ending plugin declarations. Between
|
||||
mysql_declare_plugin and mysql_declare_plugin_end there should
|
||||
be a st_mysql_plugin struct for each plugin to be declared.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef MYSQL_DYNAMIC_PLUGIN
|
||||
#define __MYSQL_DECLARE_PLUGIN(NAME, VERSION, PSIZE, DECLS) \
|
||||
MYSQL_PLUGIN_EXPORT int VERSION= MYSQL_PLUGIN_INTERFACE_VERSION; \
|
||||
MYSQL_PLUGIN_EXPORT int PSIZE= sizeof(struct st_mysql_plugin); \
|
||||
MYSQL_PLUGIN_EXPORT struct st_mysql_plugin DECLS[]= {
|
||||
#else
|
||||
#define __MYSQL_DECLARE_PLUGIN(NAME, VERSION, PSIZE, DECLS) \
|
||||
MYSQL_PLUGIN_EXPORT int _mysql_plugin_interface_version_= MYSQL_PLUGIN_INTERFACE_VERSION; \
|
||||
MYSQL_PLUGIN_EXPORT int _mysql_sizeof_struct_st_plugin_= sizeof(struct st_mysql_plugin); \
|
||||
MYSQL_PLUGIN_EXPORT struct st_mysql_plugin _mysql_plugin_declarations_[]= {
|
||||
#endif
|
||||
|
||||
#define mysql_declare_plugin(NAME) \
|
||||
__MYSQL_DECLARE_PLUGIN(NAME, \
|
||||
builtin_ ## NAME ## _plugin_interface_version, \
|
||||
builtin_ ## NAME ## _sizeof_struct_st_plugin, \
|
||||
builtin_ ## NAME ## _plugin)
|
||||
|
||||
#define mysql_declare_plugin_end ,{0,0,0,0,0,0,0,0,0,0,0,0,0}}
|
||||
|
||||
/**
|
||||
Declarations for SHOW STATUS support in plugins
|
||||
*/
|
||||
enum enum_mysql_show_type
|
||||
{
|
||||
SHOW_UNDEF, SHOW_BOOL,
|
||||
SHOW_INT, ///< shown as _unsigned_ int
|
||||
SHOW_LONG, ///< shown as _unsigned_ long
|
||||
SHOW_LONGLONG, ///< shown as _unsigned_ longlong
|
||||
SHOW_CHAR, SHOW_CHAR_PTR,
|
||||
SHOW_ARRAY, SHOW_FUNC, SHOW_DOUBLE
|
||||
#ifdef MYSQL_SERVER
|
||||
/*
|
||||
This include defines server-only values of the enum.
|
||||
Using them in plugins is not supported.
|
||||
*/
|
||||
#include "sql_plugin_enum.h"
|
||||
#endif
|
||||
};
|
||||
|
||||
/**
|
||||
Status variable scope.
|
||||
Only GLOBAL status variable scope is available in plugins.
|
||||
*/
|
||||
enum enum_mysql_show_scope
|
||||
{
|
||||
SHOW_SCOPE_UNDEF,
|
||||
SHOW_SCOPE_GLOBAL
|
||||
#ifdef MYSQL_SERVER
|
||||
/* Server-only values. Not supported in plugins. */
|
||||
,
|
||||
SHOW_SCOPE_SESSION,
|
||||
SHOW_SCOPE_ALL
|
||||
#endif
|
||||
};
|
||||
|
||||
/**
|
||||
SHOW STATUS Server status variable
|
||||
*/
|
||||
struct st_mysql_show_var
|
||||
{
|
||||
const char *name;
|
||||
char *value;
|
||||
enum enum_mysql_show_type type;
|
||||
enum enum_mysql_show_scope scope;
|
||||
};
|
||||
|
||||
#define SHOW_VAR_MAX_NAME_LEN 64
|
||||
#define SHOW_VAR_FUNC_BUFF_SIZE 1024
|
||||
typedef int (*mysql_show_var_func)(MYSQL_THD, struct st_mysql_show_var*, char *);
|
||||
|
||||
|
||||
/*
|
||||
Constants for plugin flags.
|
||||
*/
|
||||
|
||||
#define PLUGIN_OPT_NO_INSTALL 1UL /* Not dynamically loadable */
|
||||
#define PLUGIN_OPT_NO_UNINSTALL 2UL /* Not dynamically unloadable */
|
||||
|
||||
|
||||
/*
|
||||
declarations for server variables and command line options
|
||||
*/
|
||||
|
||||
|
||||
#define PLUGIN_VAR_BOOL 0x0001
|
||||
#define PLUGIN_VAR_INT 0x0002
|
||||
#define PLUGIN_VAR_LONG 0x0003
|
||||
#define PLUGIN_VAR_LONGLONG 0x0004
|
||||
#define PLUGIN_VAR_STR 0x0005
|
||||
#define PLUGIN_VAR_ENUM 0x0006
|
||||
#define PLUGIN_VAR_SET 0x0007
|
||||
#define PLUGIN_VAR_DOUBLE 0x0008
|
||||
#define PLUGIN_VAR_UNSIGNED 0x0080
|
||||
#define PLUGIN_VAR_THDLOCAL 0x0100 /* Variable is per-connection */
|
||||
#define PLUGIN_VAR_READONLY 0x0200 /* Server variable is read only */
|
||||
#define PLUGIN_VAR_NOSYSVAR 0x0400 /* Not a server variable */
|
||||
#define PLUGIN_VAR_NOCMDOPT 0x0800 /* Not a command line option */
|
||||
#define PLUGIN_VAR_NOCMDARG 0x1000 /* No argument for cmd line */
|
||||
#define PLUGIN_VAR_RQCMDARG 0x0000 /* Argument required for cmd line */
|
||||
#define PLUGIN_VAR_OPCMDARG 0x2000 /* Argument optional for cmd line */
|
||||
#define PLUGIN_VAR_NODEFAULT 0x4000 /* SET DEFAULT is prohibited */
|
||||
#define PLUGIN_VAR_MEMALLOC 0x8000 /* String needs memory allocated */
|
||||
#define PLUGIN_VAR_INVISIBLE 0x10000 /* Variable should not be shown */
|
||||
|
||||
struct st_mysql_sys_var;
|
||||
struct st_mysql_value;
|
||||
|
||||
/*
|
||||
SYNOPSIS
|
||||
(*mysql_var_check_func)()
|
||||
thd thread handle
|
||||
var dynamic variable being altered
|
||||
save pointer to temporary storage
|
||||
value user provided value
|
||||
RETURN
|
||||
0 user provided value is OK and the update func may be called.
|
||||
any other value indicates error.
|
||||
|
||||
This function should parse the user provided value and store in the
|
||||
provided temporary storage any data as required by the update func.
|
||||
There is sufficient space in the temporary storage to store a double.
|
||||
Note that the update func may not be called if any other error occurs
|
||||
so any memory allocated should be thread-local so that it may be freed
|
||||
automatically at the end of the statement.
|
||||
*/
|
||||
|
||||
typedef int (*mysql_var_check_func)(MYSQL_THD thd,
|
||||
struct st_mysql_sys_var *var,
|
||||
void *save, struct st_mysql_value *value);
|
||||
|
||||
/*
|
||||
SYNOPSIS
|
||||
(*mysql_var_update_func)()
|
||||
thd thread handle
|
||||
var dynamic variable being altered
|
||||
var_ptr pointer to dynamic variable
|
||||
save pointer to temporary storage
|
||||
RETURN
|
||||
NONE
|
||||
|
||||
This function should use the validated value stored in the temporary store
|
||||
and persist it in the provided pointer to the dynamic variable.
|
||||
For example, strings may require memory to be allocated.
|
||||
*/
|
||||
typedef void (*mysql_var_update_func)(MYSQL_THD thd,
|
||||
struct st_mysql_sys_var *var,
|
||||
void *var_ptr, const void *save);
|
||||
|
||||
|
||||
/* the following declarations are for internal use only */
|
||||
|
||||
|
||||
#define PLUGIN_VAR_MASK \
|
||||
(PLUGIN_VAR_READONLY | PLUGIN_VAR_NOSYSVAR | \
|
||||
PLUGIN_VAR_NOCMDOPT | PLUGIN_VAR_NOCMDARG | \
|
||||
PLUGIN_VAR_OPCMDARG | PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_MEMALLOC | \
|
||||
PLUGIN_VAR_NODEFAULT | PLUGIN_VAR_INVISIBLE)
|
||||
|
||||
#define MYSQL_PLUGIN_VAR_HEADER \
|
||||
int flags; \
|
||||
const char *name; \
|
||||
const char *comment; \
|
||||
mysql_var_check_func check; \
|
||||
mysql_var_update_func update
|
||||
|
||||
#define MYSQL_SYSVAR_NAME(name) mysql_sysvar_ ## name
|
||||
#define MYSQL_SYSVAR(name) \
|
||||
((struct st_mysql_sys_var *)&(MYSQL_SYSVAR_NAME(name)))
|
||||
|
||||
/*
|
||||
for global variables, the value pointer is the first
|
||||
element after the header, the default value is the second.
|
||||
for thread variables, the value offset is the first
|
||||
element after the header, the default value is the second.
|
||||
*/
|
||||
|
||||
|
||||
#define DECLARE_MYSQL_SYSVAR_BASIC(name, type) struct { \
|
||||
MYSQL_PLUGIN_VAR_HEADER; \
|
||||
type *value; \
|
||||
const type def_val; \
|
||||
} MYSQL_SYSVAR_NAME(name)
|
||||
|
||||
#define DECLARE_MYSQL_SYSVAR_SIMPLE(name, type) struct { \
|
||||
MYSQL_PLUGIN_VAR_HEADER; \
|
||||
type *value; type def_val; \
|
||||
type min_val; type max_val; \
|
||||
type blk_sz; \
|
||||
} MYSQL_SYSVAR_NAME(name)
|
||||
|
||||
#define DECLARE_MYSQL_SYSVAR_TYPELIB(name, type) struct { \
|
||||
MYSQL_PLUGIN_VAR_HEADER; \
|
||||
type *value; type def_val; \
|
||||
TYPELIB *typelib; \
|
||||
} MYSQL_SYSVAR_NAME(name)
|
||||
|
||||
#define DECLARE_THDVAR_FUNC(type) \
|
||||
type *(*resolve)(MYSQL_THD thd, int offset)
|
||||
|
||||
#define DECLARE_MYSQL_THDVAR_BASIC(name, type) struct { \
|
||||
MYSQL_PLUGIN_VAR_HEADER; \
|
||||
int offset; \
|
||||
const type def_val; \
|
||||
DECLARE_THDVAR_FUNC(type); \
|
||||
} MYSQL_SYSVAR_NAME(name)
|
||||
|
||||
#define DECLARE_MYSQL_THDVAR_SIMPLE(name, type) struct { \
|
||||
MYSQL_PLUGIN_VAR_HEADER; \
|
||||
int offset; \
|
||||
type def_val; type min_val; \
|
||||
type max_val; type blk_sz; \
|
||||
DECLARE_THDVAR_FUNC(type); \
|
||||
} MYSQL_SYSVAR_NAME(name)
|
||||
|
||||
#define DECLARE_MYSQL_THDVAR_TYPELIB(name, type) struct { \
|
||||
MYSQL_PLUGIN_VAR_HEADER; \
|
||||
int offset; \
|
||||
type def_val; \
|
||||
DECLARE_THDVAR_FUNC(type); \
|
||||
TYPELIB *typelib; \
|
||||
} MYSQL_SYSVAR_NAME(name)
|
||||
|
||||
|
||||
/*
|
||||
the following declarations are for use by plugin implementors
|
||||
*/
|
||||
|
||||
#define MYSQL_SYSVAR_BOOL(name, varname, opt, comment, check, update, def) \
|
||||
DECLARE_MYSQL_SYSVAR_BASIC(name, char) = { \
|
||||
PLUGIN_VAR_BOOL | ((opt) & PLUGIN_VAR_MASK), \
|
||||
#name, comment, check, update, &varname, def}
|
||||
|
||||
#define MYSQL_SYSVAR_STR(name, varname, opt, comment, check, update, def) \
|
||||
DECLARE_MYSQL_SYSVAR_BASIC(name, char *) = { \
|
||||
PLUGIN_VAR_STR | ((opt) & PLUGIN_VAR_MASK), \
|
||||
#name, comment, check, update, &varname, def}
|
||||
|
||||
#define MYSQL_SYSVAR_INT(name, varname, opt, comment, check, update, def, min, max, blk) \
|
||||
DECLARE_MYSQL_SYSVAR_SIMPLE(name, int) = { \
|
||||
PLUGIN_VAR_INT | ((opt) & PLUGIN_VAR_MASK), \
|
||||
#name, comment, check, update, &varname, def, min, max, blk }
|
||||
|
||||
#define MYSQL_SYSVAR_UINT(name, varname, opt, comment, check, update, def, min, max, blk) \
|
||||
DECLARE_MYSQL_SYSVAR_SIMPLE(name, unsigned int) = { \
|
||||
PLUGIN_VAR_INT | PLUGIN_VAR_UNSIGNED | ((opt) & PLUGIN_VAR_MASK), \
|
||||
#name, comment, check, update, &varname, def, min, max, blk }
|
||||
|
||||
#define MYSQL_SYSVAR_LONG(name, varname, opt, comment, check, update, def, min, max, blk) \
|
||||
DECLARE_MYSQL_SYSVAR_SIMPLE(name, long) = { \
|
||||
PLUGIN_VAR_LONG | ((opt) & PLUGIN_VAR_MASK), \
|
||||
#name, comment, check, update, &varname, def, min, max, blk }
|
||||
|
||||
#define MYSQL_SYSVAR_ULONG(name, varname, opt, comment, check, update, def, min, max, blk) \
|
||||
DECLARE_MYSQL_SYSVAR_SIMPLE(name, unsigned long) = { \
|
||||
PLUGIN_VAR_LONG | PLUGIN_VAR_UNSIGNED | ((opt) & PLUGIN_VAR_MASK), \
|
||||
#name, comment, check, update, &varname, def, min, max, blk }
|
||||
|
||||
#define MYSQL_SYSVAR_LONGLONG(name, varname, opt, comment, check, update, def, min, max, blk) \
|
||||
DECLARE_MYSQL_SYSVAR_SIMPLE(name, long long) = { \
|
||||
PLUGIN_VAR_LONGLONG | ((opt) & PLUGIN_VAR_MASK), \
|
||||
#name, comment, check, update, &varname, def, min, max, blk }
|
||||
|
||||
#define MYSQL_SYSVAR_ULONGLONG(name, varname, opt, comment, check, update, def, min, max, blk) \
|
||||
DECLARE_MYSQL_SYSVAR_SIMPLE(name, unsigned long long) = { \
|
||||
PLUGIN_VAR_LONGLONG | PLUGIN_VAR_UNSIGNED | ((opt) & PLUGIN_VAR_MASK), \
|
||||
#name, comment, check, update, &varname, def, min, max, blk }
|
||||
|
||||
#define MYSQL_SYSVAR_ENUM(name, varname, opt, comment, check, update, def, typelib) \
|
||||
DECLARE_MYSQL_SYSVAR_TYPELIB(name, unsigned long) = { \
|
||||
PLUGIN_VAR_ENUM | ((opt) & PLUGIN_VAR_MASK), \
|
||||
#name, comment, check, update, &varname, def, typelib }
|
||||
|
||||
#define MYSQL_SYSVAR_SET(name, varname, opt, comment, check, update, def, typelib) \
|
||||
DECLARE_MYSQL_SYSVAR_TYPELIB(name, unsigned long long) = { \
|
||||
PLUGIN_VAR_SET | ((opt) & PLUGIN_VAR_MASK), \
|
||||
#name, comment, check, update, &varname, def, typelib }
|
||||
|
||||
#define MYSQL_SYSVAR_DOUBLE(name, varname, opt, comment, check, update, def, min, max, blk) \
|
||||
DECLARE_MYSQL_SYSVAR_SIMPLE(name, double) = { \
|
||||
PLUGIN_VAR_DOUBLE | ((opt) & PLUGIN_VAR_MASK), \
|
||||
#name, comment, check, update, &varname, def, min, max, blk }
|
||||
|
||||
#define MYSQL_THDVAR_BOOL(name, opt, comment, check, update, def) \
|
||||
DECLARE_MYSQL_THDVAR_BASIC(name, char) = { \
|
||||
PLUGIN_VAR_BOOL | PLUGIN_VAR_THDLOCAL | ((opt) & PLUGIN_VAR_MASK), \
|
||||
#name, comment, check, update, -1, def, NULL}
|
||||
|
||||
#define MYSQL_THDVAR_STR(name, opt, comment, check, update, def) \
|
||||
DECLARE_MYSQL_THDVAR_BASIC(name, char *) = { \
|
||||
PLUGIN_VAR_STR | PLUGIN_VAR_THDLOCAL | ((opt) & PLUGIN_VAR_MASK), \
|
||||
#name, comment, check, update, -1, def, NULL}
|
||||
|
||||
#define MYSQL_THDVAR_INT(name, opt, comment, check, update, def, min, max, blk) \
|
||||
DECLARE_MYSQL_THDVAR_SIMPLE(name, int) = { \
|
||||
PLUGIN_VAR_INT | PLUGIN_VAR_THDLOCAL | ((opt) & PLUGIN_VAR_MASK), \
|
||||
#name, comment, check, update, -1, def, min, max, blk, NULL }
|
||||
|
||||
#define MYSQL_THDVAR_UINT(name, opt, comment, check, update, def, min, max, blk) \
|
||||
DECLARE_MYSQL_THDVAR_SIMPLE(name, unsigned int) = { \
|
||||
PLUGIN_VAR_INT | PLUGIN_VAR_THDLOCAL | PLUGIN_VAR_UNSIGNED | ((opt) & PLUGIN_VAR_MASK), \
|
||||
#name, comment, check, update, -1, def, min, max, blk, NULL }
|
||||
|
||||
#define MYSQL_THDVAR_LONG(name, opt, comment, check, update, def, min, max, blk) \
|
||||
DECLARE_MYSQL_THDVAR_SIMPLE(name, long) = { \
|
||||
PLUGIN_VAR_LONG | PLUGIN_VAR_THDLOCAL | ((opt) & PLUGIN_VAR_MASK), \
|
||||
#name, comment, check, update, -1, def, min, max, blk, NULL }
|
||||
|
||||
#define MYSQL_THDVAR_ULONG(name, opt, comment, check, update, def, min, max, blk) \
|
||||
DECLARE_MYSQL_THDVAR_SIMPLE(name, unsigned long) = { \
|
||||
PLUGIN_VAR_LONG | PLUGIN_VAR_THDLOCAL | PLUGIN_VAR_UNSIGNED | ((opt) & PLUGIN_VAR_MASK), \
|
||||
#name, comment, check, update, -1, def, min, max, blk, NULL }
|
||||
|
||||
#define MYSQL_THDVAR_LONGLONG(name, opt, comment, check, update, def, min, max, blk) \
|
||||
DECLARE_MYSQL_THDVAR_SIMPLE(name, long long) = { \
|
||||
PLUGIN_VAR_LONGLONG | PLUGIN_VAR_THDLOCAL | ((opt) & PLUGIN_VAR_MASK), \
|
||||
#name, comment, check, update, -1, def, min, max, blk, NULL }
|
||||
|
||||
#define MYSQL_THDVAR_ULONGLONG(name, opt, comment, check, update, def, min, max, blk) \
|
||||
DECLARE_MYSQL_THDVAR_SIMPLE(name, unsigned long long) = { \
|
||||
PLUGIN_VAR_LONGLONG | PLUGIN_VAR_THDLOCAL | PLUGIN_VAR_UNSIGNED | ((opt) & PLUGIN_VAR_MASK), \
|
||||
#name, comment, check, update, -1, def, min, max, blk, NULL }
|
||||
|
||||
#define MYSQL_THDVAR_ENUM(name, opt, comment, check, update, def, typelib) \
|
||||
DECLARE_MYSQL_THDVAR_TYPELIB(name, unsigned long) = { \
|
||||
PLUGIN_VAR_ENUM | PLUGIN_VAR_THDLOCAL | ((opt) & PLUGIN_VAR_MASK), \
|
||||
#name, comment, check, update, -1, def, NULL, typelib }
|
||||
|
||||
#define MYSQL_THDVAR_SET(name, opt, comment, check, update, def, typelib) \
|
||||
DECLARE_MYSQL_THDVAR_TYPELIB(name, unsigned long long) = { \
|
||||
PLUGIN_VAR_SET | PLUGIN_VAR_THDLOCAL | ((opt) & PLUGIN_VAR_MASK), \
|
||||
#name, comment, check, update, -1, def, NULL, typelib }
|
||||
|
||||
#define MYSQL_THDVAR_DOUBLE(name, opt, comment, check, update, def, min, max, blk) \
|
||||
DECLARE_MYSQL_THDVAR_SIMPLE(name, double) = { \
|
||||
PLUGIN_VAR_DOUBLE | PLUGIN_VAR_THDLOCAL | ((opt) & PLUGIN_VAR_MASK), \
|
||||
#name, comment, check, update, -1, def, min, max, blk, NULL }
|
||||
|
||||
/* accessor macros */
|
||||
|
||||
#define SYSVAR(name) \
|
||||
(*(MYSQL_SYSVAR_NAME(name).value))
|
||||
|
||||
/* when thd == null, result points to global value */
|
||||
#define THDVAR(thd, name) \
|
||||
(*(MYSQL_SYSVAR_NAME(name).resolve(thd, MYSQL_SYSVAR_NAME(name).offset)))
|
||||
|
||||
|
||||
/*
|
||||
Plugin description structure.
|
||||
*/
|
||||
|
||||
struct st_mysql_plugin
|
||||
{
|
||||
int type; /* the plugin type (a MYSQL_XXX_PLUGIN value) */
|
||||
void *info; /* pointer to type-specific plugin descriptor */
|
||||
const char *name; /* plugin name */
|
||||
const char *author; /* plugin author (for I_S.PLUGINS) */
|
||||
const char *descr; /* general descriptive text (for I_S.PLUGINS) */
|
||||
int license; /* the plugin license (PLUGIN_LICENSE_XXX) */
|
||||
int (*init)(MYSQL_PLUGIN); /* the function to invoke when plugin is loaded */
|
||||
int (*deinit)(MYSQL_PLUGIN);/* the function to invoke when plugin is unloaded */
|
||||
unsigned int version; /* plugin version (for I_S.PLUGINS) */
|
||||
struct st_mysql_show_var *status_vars;
|
||||
struct st_mysql_sys_var **system_vars;
|
||||
void * __reserved1; /* reserved for dependency checking */
|
||||
unsigned long flags; /* flags for plugin */
|
||||
};
|
||||
|
||||
/*************************************************************************
|
||||
API for Full-text parser plugin. (MYSQL_FTPARSER_PLUGIN)
|
||||
*/
|
||||
#define MYSQL_FTPARSER_INTERFACE_VERSION 0x0101
|
||||
|
||||
/*************************************************************************
|
||||
API for Query Rewrite plugin. (MYSQL_QUERY_REWRITE_PLUGIN)
|
||||
*/
|
||||
|
||||
#define MYSQL_REWRITE_PRE_PARSE_INTERFACE_VERSION 0x0010
|
||||
#define MYSQL_REWRITE_POST_PARSE_INTERFACE_VERSION 0x0010
|
||||
|
||||
/*************************************************************************
|
||||
API for Storage Engine plugin. (MYSQL_DAEMON_PLUGIN)
|
||||
*/
|
||||
|
||||
/* handlertons of different MySQL releases are incompatible */
|
||||
#define MYSQL_DAEMON_INTERFACE_VERSION (MYSQL_VERSION_ID << 8)
|
||||
|
||||
/*
|
||||
Here we define only the descriptor structure, that is referred from
|
||||
st_mysql_plugin.
|
||||
*/
|
||||
|
||||
struct st_mysql_daemon
|
||||
{
|
||||
int interface_version;
|
||||
};
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
API for I_S plugin. (MYSQL_INFORMATION_SCHEMA_PLUGIN)
|
||||
*/
|
||||
|
||||
/* handlertons of different MySQL releases are incompatible */
|
||||
#define MYSQL_INFORMATION_SCHEMA_INTERFACE_VERSION (MYSQL_VERSION_ID << 8)
|
||||
|
||||
/*
|
||||
Here we define only the descriptor structure, that is referred from
|
||||
st_mysql_plugin.
|
||||
*/
|
||||
|
||||
struct st_mysql_information_schema
|
||||
{
|
||||
int interface_version;
|
||||
};
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
API for Storage Engine plugin. (MYSQL_STORAGE_ENGINE_PLUGIN)
|
||||
*/
|
||||
|
||||
/* handlertons of different MySQL releases are incompatible */
|
||||
#define MYSQL_HANDLERTON_INTERFACE_VERSION (MYSQL_VERSION_ID << 8)
|
||||
|
||||
/*
|
||||
The real API is in the sql/handler.h
|
||||
Here we define only the descriptor structure, that is referred from
|
||||
st_mysql_plugin.
|
||||
*/
|
||||
|
||||
struct st_mysql_storage_engine
|
||||
{
|
||||
int interface_version;
|
||||
};
|
||||
|
||||
struct handlerton;
|
||||
|
||||
|
||||
/*
|
||||
API for Replication plugin. (MYSQL_REPLICATION_PLUGIN)
|
||||
*/
|
||||
#define MYSQL_REPLICATION_INTERFACE_VERSION 0x0400
|
||||
|
||||
/**
|
||||
Replication plugin descriptor
|
||||
*/
|
||||
struct Mysql_replication {
|
||||
int interface_version;
|
||||
};
|
||||
|
||||
/*************************************************************************
|
||||
st_mysql_value struct for reading values from mysqld.
|
||||
Used by server variables framework to parse user-provided values.
|
||||
Will be used for arguments when implementing UDFs.
|
||||
|
||||
Note that val_str() returns a string in temporary memory
|
||||
that will be freed at the end of statement. Copy the string
|
||||
if you need it to persist.
|
||||
*/
|
||||
|
||||
#define MYSQL_VALUE_TYPE_STRING 0
|
||||
#define MYSQL_VALUE_TYPE_REAL 1
|
||||
#define MYSQL_VALUE_TYPE_INT 2
|
||||
|
||||
struct st_mysql_value
|
||||
{
|
||||
int (*value_type)(struct st_mysql_value *);
|
||||
const char *(*val_str)(struct st_mysql_value *, char *buffer, int *length);
|
||||
int (*val_real)(struct st_mysql_value *, double *realbuf);
|
||||
int (*val_int)(struct st_mysql_value *, long long *intbuf);
|
||||
int (*is_unsigned)(struct st_mysql_value *);
|
||||
};
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
Miscellaneous functions for plugin implementors
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int thd_in_lock_tables(const MYSQL_THD thd);
|
||||
int thd_tablespace_op(const MYSQL_THD thd);
|
||||
long long thd_test_options(const MYSQL_THD thd, long long test_options);
|
||||
int thd_sql_command(const MYSQL_THD thd);
|
||||
const char *set_thd_proc_info(MYSQL_THD thd, const char *info,
|
||||
const char *calling_func,
|
||||
const char *calling_file,
|
||||
const unsigned int calling_line);
|
||||
void **thd_ha_data(const MYSQL_THD thd, const struct handlerton *hton);
|
||||
void thd_storage_lock_wait(MYSQL_THD thd, long long value);
|
||||
int thd_tx_isolation(const MYSQL_THD thd);
|
||||
int thd_tx_is_read_only(const MYSQL_THD thd);
|
||||
MYSQL_THD thd_tx_arbitrate(MYSQL_THD requestor, MYSQL_THD holder);
|
||||
int thd_tx_priority(const MYSQL_THD thd);
|
||||
int thd_tx_is_dd_trx(const MYSQL_THD thd);
|
||||
char *thd_security_context(MYSQL_THD thd, char *buffer, size_t length,
|
||||
size_t max_query_len);
|
||||
/* Increments the row counter, see THD::row_count */
|
||||
void thd_inc_row_count(MYSQL_THD thd);
|
||||
int thd_allow_batch(MYSQL_THD thd);
|
||||
|
||||
|
||||
/**
|
||||
Mark transaction to rollback and mark error as fatal to a
|
||||
sub-statement if in sub statement mode.
|
||||
|
||||
@param thd user thread connection handle
|
||||
@param all if all != 0, rollback the main transaction
|
||||
*/
|
||||
|
||||
void thd_mark_transaction_to_rollback(MYSQL_THD thd, int all);
|
||||
|
||||
/**
|
||||
Create a temporary file.
|
||||
|
||||
@details
|
||||
The temporary file is created in a location specified by the mysql
|
||||
server configuration (--tmpdir option). The caller does not need to
|
||||
delete the file, it will be deleted automatically.
|
||||
|
||||
@param prefix prefix for temporary file name
|
||||
@retval -1 error
|
||||
@retval >= 0 a file handle that can be passed to dup or my_close
|
||||
*/
|
||||
int mysql_tmpfile(const char *prefix);
|
||||
|
||||
/**
|
||||
Check the killed state of a connection
|
||||
|
||||
@details
|
||||
In MySQL support for the KILL statement is cooperative. The KILL
|
||||
statement only sets a "killed" flag. This function returns the value
|
||||
of that flag. A thread should check it often, especially inside
|
||||
time-consuming loops, and gracefully abort the operation if it is
|
||||
non-zero.
|
||||
|
||||
@param thd user thread connection handle
|
||||
@retval 0 the connection is active
|
||||
@retval 1 the connection has been killed
|
||||
*/
|
||||
int thd_killed(const MYSQL_THD thd);
|
||||
|
||||
/**
|
||||
Set the killed status of the current statement.
|
||||
|
||||
@param thd user thread connection handle
|
||||
*/
|
||||
void thd_set_kill_status(const MYSQL_THD thd);
|
||||
|
||||
/**
|
||||
Get binary log position for latest written entry.
|
||||
|
||||
@note The file variable will be set to a buffer holding the name of
|
||||
the file name currently, but this can change if a rotation
|
||||
occur. Copy the string if you want to retain it.
|
||||
|
||||
@param thd Use thread connection handle
|
||||
@param file_var Pointer to variable that will hold the file name.
|
||||
@param pos_var Pointer to variable that will hold the file position.
|
||||
*/
|
||||
void thd_binlog_pos(const MYSQL_THD thd,
|
||||
const char **file_var,
|
||||
unsigned long long *pos_var);
|
||||
|
||||
/**
|
||||
Return the thread id of a user thread
|
||||
|
||||
@param thd user thread connection handle
|
||||
@return thread id
|
||||
*/
|
||||
unsigned long thd_get_thread_id(const MYSQL_THD thd);
|
||||
|
||||
/**
|
||||
Get the XID for this connection's transaction
|
||||
|
||||
@param thd user thread connection handle
|
||||
@param xid location where identifier is stored
|
||||
*/
|
||||
void thd_get_xid(const MYSQL_THD thd, MYSQL_XID *xid);
|
||||
|
||||
/**
|
||||
Invalidate the query cache for a given table.
|
||||
|
||||
@param thd user thread connection handle
|
||||
@param key databasename/tablename in the canonical format.
|
||||
@param key_length length of key in bytes, including the PATH separator
|
||||
@param using_trx flag: TRUE if using transactions, FALSE otherwise
|
||||
*/
|
||||
void mysql_query_cache_invalidate4(MYSQL_THD thd,
|
||||
const char *key, unsigned int key_length,
|
||||
int using_trx);
|
||||
|
||||
|
||||
/**
|
||||
Provide a handler data getter to simplify coding
|
||||
*/
|
||||
void *thd_get_ha_data(const MYSQL_THD thd, const struct handlerton *hton);
|
||||
|
||||
|
||||
/**
|
||||
Provide a handler data setter to simplify coding
|
||||
|
||||
@details
|
||||
Set ha_data pointer (storage engine per-connection information).
|
||||
|
||||
To avoid unclean deactivation (uninstall) of storage engine plugin
|
||||
in the middle of transaction, additional storage engine plugin
|
||||
lock is acquired.
|
||||
|
||||
If ha_data is not null and storage engine plugin was not locked
|
||||
by thd_set_ha_data() in this connection before, storage engine
|
||||
plugin gets locked.
|
||||
|
||||
If ha_data is null and storage engine plugin was locked by
|
||||
thd_set_ha_data() in this connection before, storage engine
|
||||
plugin lock gets released.
|
||||
|
||||
If handlerton::close_connection() didn't reset ha_data, server does
|
||||
it immediately after calling handlerton::close_connection().
|
||||
*/
|
||||
void thd_set_ha_data(MYSQL_THD thd, const struct handlerton *hton,
|
||||
const void *ha_data);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _my_plugin_h */
|
|
@ -0,0 +1,565 @@
|
|||
/* Copyright (c) 2007, 2022, Oracle and/or its affiliates.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License, version 2.0,
|
||||
as published by the Free Software Foundation.
|
||||
|
||||
This program is also distributed with certain software (including
|
||||
but not limited to OpenSSL) that is licensed under separate terms,
|
||||
as designated in a particular file or component or in included license
|
||||
documentation. The authors of MySQL hereby grant you an additional
|
||||
permission to link the program and your derivative works with the
|
||||
separately licensed software that they have included with MySQL.
|
||||
|
||||
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, version 2.0, 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 St, Fifth Floor, Boston, MA 02110-1301 USA */
|
||||
|
||||
#ifndef _my_audit_h
|
||||
#define _my_audit_h
|
||||
|
||||
#include "plugin.h"
|
||||
#include "mysql/mysql_lex_string.h"
|
||||
#ifndef MYSQL_ABI_CHECK
|
||||
#include "m_string.h"
|
||||
#endif
|
||||
#include "my_command.h"
|
||||
#include "my_sqlcommand.h"
|
||||
|
||||
#define MYSQL_AUDIT_INTERFACE_VERSION 0x0401
|
||||
|
||||
/**
|
||||
@enum mysql_event_class_t
|
||||
|
||||
Audit event classes.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
MYSQL_AUDIT_GENERAL_CLASS = 0,
|
||||
MYSQL_AUDIT_CONNECTION_CLASS = 1,
|
||||
MYSQL_AUDIT_PARSE_CLASS = 2,
|
||||
MYSQL_AUDIT_AUTHORIZATION_CLASS = 3,
|
||||
MYSQL_AUDIT_TABLE_ACCESS_CLASS = 4,
|
||||
MYSQL_AUDIT_GLOBAL_VARIABLE_CLASS = 5,
|
||||
MYSQL_AUDIT_SERVER_STARTUP_CLASS = 6,
|
||||
MYSQL_AUDIT_SERVER_SHUTDOWN_CLASS = 7,
|
||||
MYSQL_AUDIT_COMMAND_CLASS = 8,
|
||||
MYSQL_AUDIT_QUERY_CLASS = 9,
|
||||
MYSQL_AUDIT_STORED_PROGRAM_CLASS = 10,
|
||||
/* This item must be last in the list. */
|
||||
MYSQL_AUDIT_CLASS_MASK_SIZE
|
||||
} mysql_event_class_t;
|
||||
|
||||
/**
|
||||
@struct st_mysql_audit
|
||||
|
||||
The descriptor structure that is referred from st_mysql_plugin.
|
||||
*/
|
||||
struct st_mysql_audit
|
||||
{
|
||||
/**
|
||||
Interface version.
|
||||
*/
|
||||
int interface_version;
|
||||
|
||||
/**
|
||||
Event occurs when the event class consumer is to be
|
||||
disassociated from the specified THD.This would typically occur
|
||||
before some operation which may require sleeping - such as when
|
||||
waiting for the next query from the client.
|
||||
*/
|
||||
void (*release_thd)(MYSQL_THD);
|
||||
|
||||
/**
|
||||
Invoked whenever an event occurs which is of any
|
||||
class for which the plugin has interest.The second argument
|
||||
indicates the specific event class and the third argument is data
|
||||
as required for that class.
|
||||
*/
|
||||
int (*event_notify)(MYSQL_THD, mysql_event_class_t, const void *);
|
||||
|
||||
/**
|
||||
An array of bits used to indicate what event classes
|
||||
that this plugin wants to receive.
|
||||
*/
|
||||
unsigned long class_mask[MYSQL_AUDIT_CLASS_MASK_SIZE];
|
||||
};
|
||||
|
||||
/**
|
||||
@typedef enum_sql_command_t
|
||||
|
||||
SQL command type definition.
|
||||
*/
|
||||
typedef enum enum_sql_command enum_sql_command_t;
|
||||
|
||||
/**
|
||||
@enum mysql_event_general_subclass_t
|
||||
|
||||
Events for the MYSQL_AUDIT_GENERAL_CLASS event class.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
/** occurs before emitting to the general query log. */
|
||||
MYSQL_AUDIT_GENERAL_LOG = 1 << 0,
|
||||
/** occurs before transmitting errors to the user. */
|
||||
MYSQL_AUDIT_GENERAL_ERROR = 1 << 1,
|
||||
/** occurs after transmitting a resultset to the user. */
|
||||
MYSQL_AUDIT_GENERAL_RESULT = 1 << 2,
|
||||
/** occurs after transmitting a resultset or errors */
|
||||
MYSQL_AUDIT_GENERAL_STATUS = 1 << 3
|
||||
} mysql_event_general_subclass_t;
|
||||
|
||||
#define MYSQL_AUDIT_GENERAL_ALL (MYSQL_AUDIT_GENERAL_LOG | \
|
||||
MYSQL_AUDIT_GENERAL_ERROR | \
|
||||
MYSQL_AUDIT_GENERAL_RESULT | \
|
||||
MYSQL_AUDIT_GENERAL_STATUS)
|
||||
/**
|
||||
@struct mysql_event_general
|
||||
|
||||
Structure for the MYSQL_AUDIT_GENERAL_CLASS event class.
|
||||
*/
|
||||
struct mysql_event_general
|
||||
{
|
||||
mysql_event_general_subclass_t event_subclass;
|
||||
int general_error_code;
|
||||
unsigned long general_thread_id;
|
||||
MYSQL_LEX_CSTRING general_user;
|
||||
MYSQL_LEX_CSTRING general_command;
|
||||
MYSQL_LEX_CSTRING general_query;
|
||||
struct charset_info_st *general_charset;
|
||||
unsigned long long general_time;
|
||||
unsigned long long general_rows;
|
||||
MYSQL_LEX_CSTRING general_host;
|
||||
MYSQL_LEX_CSTRING general_sql_command;
|
||||
MYSQL_LEX_CSTRING general_external_user;
|
||||
MYSQL_LEX_CSTRING general_ip;
|
||||
};
|
||||
|
||||
/**
|
||||
@enum mysql_event_connection_subclass_t
|
||||
|
||||
Events for MYSQL_AUDIT_CONNECTION_CLASS event class.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
/** occurs after authentication phase is completed. */
|
||||
MYSQL_AUDIT_CONNECTION_CONNECT = 1 << 0,
|
||||
/** occurs after connection is terminated. */
|
||||
MYSQL_AUDIT_CONNECTION_DISCONNECT = 1 << 1,
|
||||
/** occurs after COM_CHANGE_USER RPC is completed. */
|
||||
MYSQL_AUDIT_CONNECTION_CHANGE_USER = 1 << 2,
|
||||
/** occurs before authentication. */
|
||||
MYSQL_AUDIT_CONNECTION_PRE_AUTHENTICATE = 1 << 3
|
||||
} mysql_event_connection_subclass_t;
|
||||
|
||||
#define MYSQL_AUDIT_CONNECTION_ALL (MYSQL_AUDIT_CONNECTION_CONNECT | \
|
||||
MYSQL_AUDIT_CONNECTION_DISCONNECT | \
|
||||
MYSQL_AUDIT_CONNECTION_CHANGE_USER | \
|
||||
MYSQL_AUDIT_CONNECTION_PRE_AUTHENTICATE)
|
||||
/**
|
||||
@struct mysql_event_connection
|
||||
|
||||
Structure for the MYSQL_AUDIT_CONNECTION_CLASS event class.
|
||||
*/
|
||||
struct mysql_event_connection
|
||||
{
|
||||
/** Event subclass. */
|
||||
mysql_event_connection_subclass_t event_subclass;
|
||||
/** Current status of the connection. */
|
||||
int status;
|
||||
/** Connection id. */
|
||||
unsigned long connection_id;
|
||||
/** User name of this connection. */
|
||||
MYSQL_LEX_CSTRING user;
|
||||
/** Priv user name. */
|
||||
MYSQL_LEX_CSTRING priv_user;
|
||||
/** External user name. */
|
||||
MYSQL_LEX_CSTRING external_user;
|
||||
/** Proxy user used for this connection. */
|
||||
MYSQL_LEX_CSTRING proxy_user;
|
||||
/** Connection host. */
|
||||
MYSQL_LEX_CSTRING host;
|
||||
/** IP of the connection. */
|
||||
MYSQL_LEX_CSTRING ip;
|
||||
/** Database name specified at connection time. */
|
||||
MYSQL_LEX_CSTRING database;
|
||||
/** Connection type:
|
||||
- 0 Undefined
|
||||
- 1 TCP/IP
|
||||
- 2 Socket
|
||||
- 3 Named pipe
|
||||
- 4 SSL
|
||||
- 5 Shared memory
|
||||
*/
|
||||
int connection_type;
|
||||
};
|
||||
|
||||
/**
|
||||
@enum mysql_event_parse_subclass_t
|
||||
|
||||
Events for MYSQL_AUDIT_PARSE_CLASS event class.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
/** occurs before the query parsing. */
|
||||
MYSQL_AUDIT_PARSE_PREPARSE = 1 << 0,
|
||||
/** occurs after the query parsing. */
|
||||
MYSQL_AUDIT_PARSE_POSTPARSE = 1 << 1
|
||||
} mysql_event_parse_subclass_t;
|
||||
|
||||
#define MYSQL_AUDIT_PARSE_ALL (MYSQL_AUDIT_PARSE_PREPARSE | \
|
||||
MYSQL_AUDIT_PARSE_POSTPARSE)
|
||||
|
||||
typedef enum
|
||||
{
|
||||
MYSQL_AUDIT_PARSE_REWRITE_PLUGIN_NONE = 0,
|
||||
/// mysql_event_parse::flags Must be set by a plugin if the query is rewritten.
|
||||
MYSQL_AUDIT_PARSE_REWRITE_PLUGIN_QUERY_REWRITTEN = 1 << 0,
|
||||
/// mysql_event_parse::flags Is set by the server if the query is prepared statement.
|
||||
MYSQL_AUDIT_PARSE_REWRITE_PLUGIN_IS_PREPARED_STATEMENT = 1 << 1
|
||||
} mysql_event_parse_rewrite_plugin_flag;
|
||||
|
||||
/** Data for the MYSQL_AUDIT_PARSE events */
|
||||
struct mysql_event_parse
|
||||
{
|
||||
/** MYSQL_AUDIT_[PRE|POST]_PARSE event id */
|
||||
mysql_event_parse_subclass_t event_subclass;
|
||||
|
||||
/** one of FLAG_REWRITE_PLUGIN_* */
|
||||
mysql_event_parse_rewrite_plugin_flag *flags;
|
||||
|
||||
/** input: the original query text */
|
||||
MYSQL_LEX_CSTRING query;
|
||||
|
||||
/** output: returns the null-terminated rewriten query allocated by my_malloc() */
|
||||
MYSQL_LEX_CSTRING *rewritten_query;
|
||||
};
|
||||
|
||||
/**
|
||||
@enum mysql_event_authorization_subclass_t
|
||||
|
||||
Events for MYSQL_AUDIT_AUTHORIZATION_CLASS event class.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
MYSQL_AUDIT_AUTHORIZATION_USER = 1 << 0,
|
||||
/** Occurs when database privilege is checked. */
|
||||
MYSQL_AUDIT_AUTHORIZATION_DB = 1 << 1,
|
||||
/** Occurs when table privilege is checked. */
|
||||
MYSQL_AUDIT_AUTHORIZATION_TABLE = 1 << 2,
|
||||
/** Occurs when column privilege is checked. */
|
||||
MYSQL_AUDIT_AUTHORIZATION_COLUMN = 1 << 3,
|
||||
/** Occurs when procedure privilege is checked. */
|
||||
MYSQL_AUDIT_AUTHORIZATION_PROCEDURE = 1 << 4,
|
||||
/** Occurs when proxy privilege is checked. */
|
||||
MYSQL_AUDIT_AUTHORIZATION_PROXY = 1 << 5
|
||||
} mysql_event_authorization_subclass_t;
|
||||
|
||||
#define MYSQL_AUDIT_AUTHORIZATION_ALL (MYSQL_AUDIT_AUTHORIZATION_USER | \
|
||||
MYSQL_AUDIT_AUTHORIZATION_DB | \
|
||||
MYSQL_AUDIT_AUTHORIZATION_TABLE | \
|
||||
MYSQL_AUDIT_AUTHORIZATION_COLUMN | \
|
||||
MYSQL_AUDIT_AUTHORIZATION_PROCEDURE | \
|
||||
MYSQL_AUDIT_AUTHORIZATION_PROXY)
|
||||
/**
|
||||
@struct mysql_event_authorization
|
||||
|
||||
Structure for MYSQL_AUDIT_AUTHORIZATION_CLASS event class.
|
||||
*/
|
||||
struct mysql_event_authorization
|
||||
{
|
||||
/** Event subclass. */
|
||||
mysql_event_authorization_subclass_t event_subclass;
|
||||
/** Event status. */
|
||||
int status;
|
||||
/** Connection id. */
|
||||
unsigned int connection_id;
|
||||
/** SQL command id. */
|
||||
enum_sql_command_t sql_command_id;
|
||||
/** SQL query text. */
|
||||
MYSQL_LEX_CSTRING query;
|
||||
/** SQL query charset. */
|
||||
const struct charset_info_st *query_charset;
|
||||
/** Database name. */
|
||||
MYSQL_LEX_CSTRING database;
|
||||
/** Table name. */
|
||||
MYSQL_LEX_CSTRING table;
|
||||
/** Other name associated with the event. */
|
||||
MYSQL_LEX_CSTRING object;
|
||||
/** Requested authorization privileges. */
|
||||
unsigned long requested_privilege;
|
||||
/** Currently granted authorization privileges. */
|
||||
unsigned long granted_privilege;
|
||||
};
|
||||
|
||||
/**
|
||||
@enum mysql_event_table_row_access_subclass_t
|
||||
|
||||
Events for MYSQL_AUDIT_TABLE_ACCES_CLASS event class.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
/** Occurs when table data are read. */
|
||||
MYSQL_AUDIT_TABLE_ACCESS_READ = 1 << 0,
|
||||
/** Occurs when table data are inserted. */
|
||||
MYSQL_AUDIT_TABLE_ACCESS_INSERT = 1 << 1,
|
||||
/** Occurs when table data are updated. */
|
||||
MYSQL_AUDIT_TABLE_ACCESS_UPDATE = 1 << 2,
|
||||
/** Occurs when table data are deleted. */
|
||||
MYSQL_AUDIT_TABLE_ACCESS_DELETE = 1 << 3
|
||||
} mysql_event_table_access_subclass_t;
|
||||
|
||||
#define MYSQL_AUDIT_TABLE_ACCESS_ALL (MYSQL_AUDIT_TABLE_ACCESS_READ | \
|
||||
MYSQL_AUDIT_TABLE_ACCESS_INSERT | \
|
||||
MYSQL_AUDIT_TABLE_ACCESS_UPDATE | \
|
||||
MYSQL_AUDIT_TABLE_ACCESS_DELETE)
|
||||
|
||||
/**
|
||||
@struct mysql_event_table_row_access
|
||||
|
||||
Structure for MYSQL_AUDIT_TABLE_ACCES_CLASS event class.
|
||||
*/
|
||||
struct mysql_event_table_access
|
||||
{
|
||||
/** Event subclass. */
|
||||
mysql_event_table_access_subclass_t event_subclass;
|
||||
/** Connection id. */
|
||||
unsigned long connection_id;
|
||||
/** SQL command id. */
|
||||
enum_sql_command_t sql_command_id;
|
||||
/** SQL query. */
|
||||
MYSQL_LEX_CSTRING query;
|
||||
/** SQL query charset. */
|
||||
const struct charset_info_st *query_charset;
|
||||
/** Database name. */
|
||||
MYSQL_LEX_CSTRING table_database;
|
||||
/** Table name. */
|
||||
MYSQL_LEX_CSTRING table_name;
|
||||
};
|
||||
|
||||
/**
|
||||
@enum mysql_event_global_variable_subclass_t
|
||||
|
||||
Events for MYSQL_AUDIT_GLOBAL_VARIABLE_CLASS event class.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
/** Occurs when global variable is retrieved. */
|
||||
MYSQL_AUDIT_GLOBAL_VARIABLE_GET = 1 << 0,
|
||||
/** Occurs when global variable is set. */
|
||||
MYSQL_AUDIT_GLOBAL_VARIABLE_SET = 1 << 1
|
||||
} mysql_event_global_variable_subclass_t;
|
||||
|
||||
#define MYSQL_AUDIT_GLOBAL_VARIABLE_ALL (MYSQL_AUDIT_GLOBAL_VARIABLE_GET | \
|
||||
MYSQL_AUDIT_GLOBAL_VARIABLE_SET)
|
||||
|
||||
/** Events for MYSQL_AUDIT_GLOBAL_VARIABLE_CLASS event class. */
|
||||
struct mysql_event_global_variable
|
||||
{
|
||||
/** Event subclass. */
|
||||
mysql_event_global_variable_subclass_t event_subclass;
|
||||
/** Connection id. */
|
||||
unsigned long connection_id;
|
||||
/** SQL command id. */
|
||||
enum_sql_command_t sql_command_id;
|
||||
/** Variable name. */
|
||||
MYSQL_LEX_CSTRING variable_name;
|
||||
/** Variable value. */
|
||||
MYSQL_LEX_CSTRING variable_value;
|
||||
};
|
||||
|
||||
/**
|
||||
@enum mysql_event_server_startup_subclass_t
|
||||
|
||||
Events for MYSQL_AUDIT_SERVER_STARTUP_CLASS event class.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
/** Occurs after all subsystem are initialized during system start. */
|
||||
MYSQL_AUDIT_SERVER_STARTUP_STARTUP = 1 << 0
|
||||
} mysql_event_server_startup_subclass_t;
|
||||
|
||||
#define MYSQL_AUDIT_SERVER_STARTUP_ALL (MYSQL_AUDIT_SERVER_STARTUP_STARTUP)
|
||||
|
||||
/**
|
||||
@struct mysql_event_server_startup
|
||||
|
||||
Structure for MYSQL_AUDIT_SERVER_STARTUP_CLASS event class.
|
||||
*/
|
||||
struct mysql_event_server_startup
|
||||
{
|
||||
/** Event subclass. */
|
||||
mysql_event_server_startup_subclass_t event_subclass;
|
||||
/** Command line arguments. */
|
||||
const char **argv;
|
||||
/** Command line arguments count. */
|
||||
unsigned int argc;
|
||||
};
|
||||
|
||||
/**
|
||||
@enum mysql_event_server_shutdown_subclass_t
|
||||
|
||||
Events for MYSQL_AUDIT_SERVER_SHUTDOWN_CLASS event class.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
/** Occurs when global variable is set. */
|
||||
MYSQL_AUDIT_SERVER_SHUTDOWN_SHUTDOWN = 1 << 0
|
||||
} mysql_event_server_shutdown_subclass_t;
|
||||
|
||||
#define MYSQL_AUDIT_SERVER_SHUTDOWN_ALL (MYSQL_AUDIT_SERVER_SHUTDOWN_SHUTDOWN)
|
||||
|
||||
/**
|
||||
@enum mysql_server_shutdown_reason_t
|
||||
|
||||
Server shutdown reason.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
/** User requested shut down. */
|
||||
MYSQL_AUDIT_SERVER_SHUTDOWN_REASON_SHUTDOWN,
|
||||
/** The server aborts. */
|
||||
MYSQL_AUDIT_SERVER_SHUTDOWN_REASON_ABORT
|
||||
} mysql_server_shutdown_reason_t;
|
||||
|
||||
/**
|
||||
@struct mysql_event_server_shutdown
|
||||
|
||||
Structure for MYSQL_AUDIT_SERVER_SHUTDOWN_CLASS event class.
|
||||
*/
|
||||
struct mysql_event_server_shutdown
|
||||
{
|
||||
/** Shutdown event. */
|
||||
mysql_event_server_shutdown_subclass_t event_subclass;
|
||||
/** Exit code associated with the shutdown event. */
|
||||
int exit_code;
|
||||
/** Shutdown reason. */
|
||||
mysql_server_shutdown_reason_t reason;
|
||||
};
|
||||
|
||||
/**
|
||||
@enum mysql_event_command_subclass_t
|
||||
|
||||
Events for MYSQL_AUDIT_COMMAND_CLASS event class.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
/** Command start event. */
|
||||
MYSQL_AUDIT_COMMAND_START = 1 << 0,
|
||||
/** Command end event. */
|
||||
MYSQL_AUDIT_COMMAND_END = 1 << 1
|
||||
} mysql_event_command_subclass_t;
|
||||
|
||||
#define MYSQL_AUDIT_COMMAND_ALL (MYSQL_AUDIT_COMMAND_START | \
|
||||
MYSQL_AUDIT_COMMAND_END)
|
||||
/**
|
||||
@typedef enum_server_command_t
|
||||
|
||||
Server command type definition.
|
||||
*/
|
||||
typedef enum enum_server_command enum_server_command_t;
|
||||
|
||||
/**
|
||||
@struct mysql_event_command
|
||||
|
||||
Event for MYSQL_AUDIT_COMMAND_CLASS event class.
|
||||
Events generated as a result of RPC command requests.
|
||||
*/
|
||||
struct mysql_event_command
|
||||
{
|
||||
/** Command event subclass. */
|
||||
mysql_event_command_subclass_t event_subclass;
|
||||
/** Command event status. */
|
||||
int status;
|
||||
/** Connection id. */
|
||||
unsigned long connection_id;
|
||||
/** Command id. */
|
||||
enum_server_command_t command_id;
|
||||
};
|
||||
|
||||
/**
|
||||
@enum mysql_event_query_subclass_t
|
||||
|
||||
Events for MYSQL_AUDIT_QUERY_CLASS event class.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
/** Query start event. */
|
||||
MYSQL_AUDIT_QUERY_START = 1 << 0,
|
||||
/** Nested query start event. */
|
||||
MYSQL_AUDIT_QUERY_NESTED_START = 1 << 1,
|
||||
/** Query post parse event. */
|
||||
MYSQL_AUDIT_QUERY_STATUS_END = 1 << 2,
|
||||
/** Nested query status end event. */
|
||||
MYSQL_AUDIT_QUERY_NESTED_STATUS_END = 1 << 3
|
||||
} mysql_event_query_subclass_t;
|
||||
|
||||
#define MYSQL_AUDIT_QUERY_ALL (MYSQL_AUDIT_QUERY_START | \
|
||||
MYSQL_AUDIT_QUERY_NESTED_START | \
|
||||
MYSQL_AUDIT_QUERY_STATUS_END | \
|
||||
MYSQL_AUDIT_QUERY_NESTED_STATUS_END)
|
||||
/**
|
||||
@struct mysql_event_command
|
||||
|
||||
Event for MYSQL_AUDIT_COMMAND_CLASS event class.
|
||||
*/
|
||||
struct mysql_event_query
|
||||
{
|
||||
/** Event subclass. */
|
||||
mysql_event_query_subclass_t event_subclass;
|
||||
/** Event status. */
|
||||
int status;
|
||||
/** Connection id. */
|
||||
unsigned long connection_id;
|
||||
/** SQL command id. */
|
||||
enum_sql_command_t sql_command_id;
|
||||
/** SQL query. */
|
||||
MYSQL_LEX_CSTRING query;
|
||||
/** SQL query charset. */
|
||||
const struct charset_info_st *query_charset;
|
||||
};
|
||||
|
||||
/**
|
||||
@enum mysql_event_stored_program_subclass_t
|
||||
|
||||
Events for MYSQL_AUDIT_STORED_PROGRAM_CLASS event class.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
/** Stored program execution event. */
|
||||
MYSQL_AUDIT_STORED_PROGRAM_EXECUTE = 1 << 0
|
||||
} mysql_event_stored_program_subclass_t;
|
||||
|
||||
#define MYSQL_AUDIT_STORED_PROGRAM_ALL (MYSQL_AUDIT_STORED_PROGRAM_EXECUTE)
|
||||
|
||||
/**
|
||||
@struct mysql_event_command
|
||||
|
||||
Event for MYSQL_AUDIT_COMMAND_CLASS event class.
|
||||
*/
|
||||
struct mysql_event_stored_program
|
||||
{
|
||||
/** Event subclass. */
|
||||
mysql_event_stored_program_subclass_t event_subclass;
|
||||
/** Connection id. */
|
||||
unsigned long connection_id;
|
||||
/** SQL command id. */
|
||||
enum_sql_command_t sql_command_id;
|
||||
/** SQL query text. */
|
||||
MYSQL_LEX_CSTRING query;
|
||||
/** SQL query charset. */
|
||||
const struct charset_info_st *query_charset;
|
||||
/** The Database the procedure is defined in. */
|
||||
MYSQL_LEX_CSTRING database;
|
||||
/** Name of the stored program. */
|
||||
MYSQL_LEX_CSTRING name;
|
||||
/** Stored program parameters. */
|
||||
void *parameters;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -0,0 +1,514 @@
|
|||
#include "plugin.h"
|
||||
typedef void * MYSQL_PLUGIN;
|
||||
struct st_mysql_xid {
|
||||
long formatID;
|
||||
long gtrid_length;
|
||||
long bqual_length;
|
||||
char data[128];
|
||||
};
|
||||
typedef struct st_mysql_xid MYSQL_XID;
|
||||
enum enum_mysql_show_type
|
||||
{
|
||||
SHOW_UNDEF, SHOW_BOOL,
|
||||
SHOW_INT,
|
||||
SHOW_LONG,
|
||||
SHOW_LONGLONG,
|
||||
SHOW_CHAR, SHOW_CHAR_PTR,
|
||||
SHOW_ARRAY, SHOW_FUNC, SHOW_DOUBLE
|
||||
};
|
||||
enum enum_mysql_show_scope
|
||||
{
|
||||
SHOW_SCOPE_UNDEF,
|
||||
SHOW_SCOPE_GLOBAL
|
||||
};
|
||||
struct st_mysql_show_var
|
||||
{
|
||||
const char *name;
|
||||
char *value;
|
||||
enum enum_mysql_show_type type;
|
||||
enum enum_mysql_show_scope scope;
|
||||
};
|
||||
typedef int (*mysql_show_var_func)(void*, struct st_mysql_show_var*, char *);
|
||||
struct st_mysql_sys_var;
|
||||
struct st_mysql_value;
|
||||
typedef int (*mysql_var_check_func)(void* thd,
|
||||
struct st_mysql_sys_var *var,
|
||||
void *save, struct st_mysql_value *value);
|
||||
typedef void (*mysql_var_update_func)(void* thd,
|
||||
struct st_mysql_sys_var *var,
|
||||
void *var_ptr, const void *save);
|
||||
struct st_mysql_plugin
|
||||
{
|
||||
int type;
|
||||
void *info;
|
||||
const char *name;
|
||||
const char *author;
|
||||
const char *descr;
|
||||
int license;
|
||||
int (*init)(MYSQL_PLUGIN);
|
||||
int (*deinit)(MYSQL_PLUGIN);
|
||||
unsigned int version;
|
||||
struct st_mysql_show_var *status_vars;
|
||||
struct st_mysql_sys_var **system_vars;
|
||||
void * __reserved1;
|
||||
unsigned long flags;
|
||||
};
|
||||
struct st_mysql_daemon
|
||||
{
|
||||
int interface_version;
|
||||
};
|
||||
struct st_mysql_information_schema
|
||||
{
|
||||
int interface_version;
|
||||
};
|
||||
struct st_mysql_storage_engine
|
||||
{
|
||||
int interface_version;
|
||||
};
|
||||
struct handlerton;
|
||||
struct Mysql_replication {
|
||||
int interface_version;
|
||||
};
|
||||
struct st_mysql_value
|
||||
{
|
||||
int (*value_type)(struct st_mysql_value *);
|
||||
const char *(*val_str)(struct st_mysql_value *, char *buffer, int *length);
|
||||
int (*val_real)(struct st_mysql_value *, double *realbuf);
|
||||
int (*val_int)(struct st_mysql_value *, long long *intbuf);
|
||||
int (*is_unsigned)(struct st_mysql_value *);
|
||||
};
|
||||
int thd_in_lock_tables(const void* thd);
|
||||
int thd_tablespace_op(const void* thd);
|
||||
long long thd_test_options(const void* thd, long long test_options);
|
||||
int thd_sql_command(const void* thd);
|
||||
const char *set_thd_proc_info(void* thd, const char *info,
|
||||
const char *calling_func,
|
||||
const char *calling_file,
|
||||
const unsigned int calling_line);
|
||||
void **thd_ha_data(const void* thd, const struct handlerton *hton);
|
||||
void thd_storage_lock_wait(void* thd, long long value);
|
||||
int thd_tx_isolation(const void* thd);
|
||||
int thd_tx_is_read_only(const void* thd);
|
||||
void* thd_tx_arbitrate(void* requestor, void* holder);
|
||||
int thd_tx_priority(const void* thd);
|
||||
int thd_tx_is_dd_trx(const void* thd);
|
||||
char *thd_security_context(void* thd, char *buffer, size_t length,
|
||||
size_t max_query_len);
|
||||
void thd_inc_row_count(void* thd);
|
||||
int thd_allow_batch(void* thd);
|
||||
void thd_mark_transaction_to_rollback(void* thd, int all);
|
||||
int mysql_tmpfile(const char *prefix);
|
||||
int thd_killed(const void* thd);
|
||||
void thd_set_kill_status(const void* thd);
|
||||
void thd_binlog_pos(const void* thd,
|
||||
const char **file_var,
|
||||
unsigned long long *pos_var);
|
||||
unsigned long thd_get_thread_id(const void* thd);
|
||||
void thd_get_xid(const void* thd, MYSQL_XID *xid);
|
||||
void mysql_query_cache_invalidate4(void* thd,
|
||||
const char *key, unsigned int key_length,
|
||||
int using_trx);
|
||||
void *thd_get_ha_data(const void* thd, const struct handlerton *hton);
|
||||
void thd_set_ha_data(void* thd, const struct handlerton *hton,
|
||||
const void *ha_data);
|
||||
#include "mysql/mysql_lex_string.h"
|
||||
struct st_mysql_lex_string
|
||||
{
|
||||
char *str;
|
||||
size_t length;
|
||||
};
|
||||
typedef struct st_mysql_lex_string MYSQL_LEX_STRING;
|
||||
struct st_mysql_const_lex_string
|
||||
{
|
||||
const char *str;
|
||||
size_t length;
|
||||
};
|
||||
typedef struct st_mysql_const_lex_string MYSQL_LEX_CSTRING;
|
||||
#include "my_command.h"
|
||||
enum enum_server_command
|
||||
{
|
||||
COM_SLEEP,
|
||||
COM_QUIT,
|
||||
COM_INIT_DB,
|
||||
COM_QUERY,
|
||||
COM_FIELD_LIST,
|
||||
COM_CREATE_DB,
|
||||
COM_DROP_DB,
|
||||
COM_REFRESH,
|
||||
COM_SHUTDOWN,
|
||||
COM_STATISTICS,
|
||||
COM_PROCESS_INFO,
|
||||
COM_CONNECT,
|
||||
COM_PROCESS_KILL,
|
||||
COM_DEBUG,
|
||||
COM_PING,
|
||||
COM_TIME,
|
||||
COM_DELAYED_INSERT,
|
||||
COM_CHANGE_USER,
|
||||
COM_BINLOG_DUMP,
|
||||
COM_TABLE_DUMP,
|
||||
COM_CONNECT_OUT,
|
||||
COM_REGISTER_SLAVE,
|
||||
COM_STMT_PREPARE,
|
||||
COM_STMT_EXECUTE,
|
||||
COM_STMT_SEND_LONG_DATA,
|
||||
COM_STMT_CLOSE,
|
||||
COM_STMT_RESET,
|
||||
COM_SET_OPTION,
|
||||
COM_STMT_FETCH,
|
||||
COM_DAEMON,
|
||||
COM_BINLOG_DUMP_GTID,
|
||||
COM_RESET_CONNECTION,
|
||||
COM_END
|
||||
};
|
||||
#include "my_sqlcommand.h"
|
||||
enum enum_sql_command {
|
||||
SQLCOM_SELECT,
|
||||
SQLCOM_CREATE_TABLE,
|
||||
SQLCOM_CREATE_INDEX,
|
||||
SQLCOM_ALTER_TABLE,
|
||||
SQLCOM_UPDATE,
|
||||
SQLCOM_INSERT,
|
||||
SQLCOM_INSERT_SELECT,
|
||||
SQLCOM_DELETE,
|
||||
SQLCOM_TRUNCATE,
|
||||
SQLCOM_DROP_TABLE,
|
||||
SQLCOM_DROP_INDEX,
|
||||
SQLCOM_SHOW_DATABASES,
|
||||
SQLCOM_SHOW_TABLES,
|
||||
SQLCOM_SHOW_FIELDS,
|
||||
SQLCOM_SHOW_KEYS,
|
||||
SQLCOM_SHOW_VARIABLES,
|
||||
SQLCOM_SHOW_STATUS,
|
||||
SQLCOM_SHOW_ENGINE_LOGS,
|
||||
SQLCOM_SHOW_ENGINE_STATUS,
|
||||
SQLCOM_SHOW_ENGINE_MUTEX,
|
||||
SQLCOM_SHOW_PROCESSLIST,
|
||||
SQLCOM_SHOW_MASTER_STAT,
|
||||
SQLCOM_SHOW_SLAVE_STAT,
|
||||
SQLCOM_SHOW_GRANTS,
|
||||
SQLCOM_SHOW_CREATE,
|
||||
SQLCOM_SHOW_CHARSETS,
|
||||
SQLCOM_SHOW_COLLATIONS,
|
||||
SQLCOM_SHOW_CREATE_DB,
|
||||
SQLCOM_SHOW_TABLE_STATUS,
|
||||
SQLCOM_SHOW_TRIGGERS,
|
||||
SQLCOM_LOAD,
|
||||
SQLCOM_SET_OPTION,
|
||||
SQLCOM_LOCK_TABLES,
|
||||
SQLCOM_UNLOCK_TABLES,
|
||||
SQLCOM_GRANT,
|
||||
SQLCOM_CHANGE_DB,
|
||||
SQLCOM_CREATE_DB,
|
||||
SQLCOM_DROP_DB,
|
||||
SQLCOM_ALTER_DB,
|
||||
SQLCOM_REPAIR,
|
||||
SQLCOM_REPLACE,
|
||||
SQLCOM_REPLACE_SELECT,
|
||||
SQLCOM_CREATE_FUNCTION,
|
||||
SQLCOM_DROP_FUNCTION,
|
||||
SQLCOM_REVOKE,
|
||||
SQLCOM_OPTIMIZE,
|
||||
SQLCOM_CHECK,
|
||||
SQLCOM_ASSIGN_TO_KEYCACHE,
|
||||
SQLCOM_PRELOAD_KEYS,
|
||||
SQLCOM_FLUSH,
|
||||
SQLCOM_KILL,
|
||||
SQLCOM_ANALYZE,
|
||||
SQLCOM_ROLLBACK,
|
||||
SQLCOM_ROLLBACK_TO_SAVEPOINT,
|
||||
SQLCOM_COMMIT,
|
||||
SQLCOM_SAVEPOINT,
|
||||
SQLCOM_RELEASE_SAVEPOINT,
|
||||
SQLCOM_SLAVE_START,
|
||||
SQLCOM_SLAVE_STOP,
|
||||
SQLCOM_START_GROUP_REPLICATION,
|
||||
SQLCOM_STOP_GROUP_REPLICATION,
|
||||
SQLCOM_BEGIN,
|
||||
SQLCOM_CHANGE_MASTER,
|
||||
SQLCOM_CHANGE_REPLICATION_FILTER,
|
||||
SQLCOM_RENAME_TABLE,
|
||||
SQLCOM_RESET,
|
||||
SQLCOM_PURGE,
|
||||
SQLCOM_PURGE_BEFORE,
|
||||
SQLCOM_SHOW_BINLOGS,
|
||||
SQLCOM_SHOW_OPEN_TABLES,
|
||||
SQLCOM_HA_OPEN,
|
||||
SQLCOM_HA_CLOSE,
|
||||
SQLCOM_HA_READ,
|
||||
SQLCOM_SHOW_SLAVE_HOSTS,
|
||||
SQLCOM_DELETE_MULTI,
|
||||
SQLCOM_UPDATE_MULTI,
|
||||
SQLCOM_SHOW_BINLOG_EVENTS,
|
||||
SQLCOM_DO,
|
||||
SQLCOM_SHOW_WARNS,
|
||||
SQLCOM_EMPTY_QUERY,
|
||||
SQLCOM_SHOW_ERRORS,
|
||||
SQLCOM_SHOW_STORAGE_ENGINES,
|
||||
SQLCOM_SHOW_PRIVILEGES,
|
||||
SQLCOM_HELP,
|
||||
SQLCOM_CREATE_USER,
|
||||
SQLCOM_DROP_USER,
|
||||
SQLCOM_RENAME_USER,
|
||||
SQLCOM_REVOKE_ALL,
|
||||
SQLCOM_CHECKSUM,
|
||||
SQLCOM_CREATE_PROCEDURE,
|
||||
SQLCOM_CREATE_SPFUNCTION,
|
||||
SQLCOM_CALL,
|
||||
SQLCOM_DROP_PROCEDURE,
|
||||
SQLCOM_ALTER_PROCEDURE,
|
||||
SQLCOM_ALTER_FUNCTION,
|
||||
SQLCOM_SHOW_CREATE_PROC,
|
||||
SQLCOM_SHOW_CREATE_FUNC,
|
||||
SQLCOM_SHOW_STATUS_PROC,
|
||||
SQLCOM_SHOW_STATUS_FUNC,
|
||||
SQLCOM_PREPARE,
|
||||
SQLCOM_EXECUTE,
|
||||
SQLCOM_DEALLOCATE_PREPARE,
|
||||
SQLCOM_CREATE_VIEW,
|
||||
SQLCOM_DROP_VIEW,
|
||||
SQLCOM_CREATE_TRIGGER,
|
||||
SQLCOM_DROP_TRIGGER,
|
||||
SQLCOM_XA_START,
|
||||
SQLCOM_XA_END,
|
||||
SQLCOM_XA_PREPARE,
|
||||
SQLCOM_XA_COMMIT,
|
||||
SQLCOM_XA_ROLLBACK,
|
||||
SQLCOM_XA_RECOVER,
|
||||
SQLCOM_SHOW_PROC_CODE,
|
||||
SQLCOM_SHOW_FUNC_CODE,
|
||||
SQLCOM_ALTER_TABLESPACE,
|
||||
SQLCOM_INSTALL_PLUGIN,
|
||||
SQLCOM_UNINSTALL_PLUGIN,
|
||||
SQLCOM_BINLOG_BASE64_EVENT,
|
||||
SQLCOM_SHOW_PLUGINS,
|
||||
SQLCOM_CREATE_SERVER,
|
||||
SQLCOM_DROP_SERVER,
|
||||
SQLCOM_ALTER_SERVER,
|
||||
SQLCOM_CREATE_EVENT,
|
||||
SQLCOM_ALTER_EVENT,
|
||||
SQLCOM_DROP_EVENT,
|
||||
SQLCOM_SHOW_CREATE_EVENT,
|
||||
SQLCOM_SHOW_EVENTS,
|
||||
SQLCOM_SHOW_CREATE_TRIGGER,
|
||||
SQLCOM_ALTER_DB_UPGRADE,
|
||||
SQLCOM_SHOW_PROFILE,
|
||||
SQLCOM_SHOW_PROFILES,
|
||||
SQLCOM_SIGNAL,
|
||||
SQLCOM_RESIGNAL,
|
||||
SQLCOM_SHOW_RELAYLOG_EVENTS,
|
||||
SQLCOM_GET_DIAGNOSTICS,
|
||||
SQLCOM_ALTER_USER,
|
||||
SQLCOM_EXPLAIN_OTHER,
|
||||
SQLCOM_SHOW_CREATE_USER,
|
||||
SQLCOM_SHUTDOWN,
|
||||
SQLCOM_ALTER_INSTANCE,
|
||||
SQLCOM_END
|
||||
};
|
||||
typedef enum
|
||||
{
|
||||
MYSQL_AUDIT_GENERAL_CLASS = 0,
|
||||
MYSQL_AUDIT_CONNECTION_CLASS = 1,
|
||||
MYSQL_AUDIT_PARSE_CLASS = 2,
|
||||
MYSQL_AUDIT_AUTHORIZATION_CLASS = 3,
|
||||
MYSQL_AUDIT_TABLE_ACCESS_CLASS = 4,
|
||||
MYSQL_AUDIT_GLOBAL_VARIABLE_CLASS = 5,
|
||||
MYSQL_AUDIT_SERVER_STARTUP_CLASS = 6,
|
||||
MYSQL_AUDIT_SERVER_SHUTDOWN_CLASS = 7,
|
||||
MYSQL_AUDIT_COMMAND_CLASS = 8,
|
||||
MYSQL_AUDIT_QUERY_CLASS = 9,
|
||||
MYSQL_AUDIT_STORED_PROGRAM_CLASS = 10,
|
||||
MYSQL_AUDIT_CLASS_MASK_SIZE
|
||||
} mysql_event_class_t;
|
||||
struct st_mysql_audit
|
||||
{
|
||||
int interface_version;
|
||||
void (*release_thd)(void*);
|
||||
int (*event_notify)(void*, mysql_event_class_t, const void *);
|
||||
unsigned long class_mask[MYSQL_AUDIT_CLASS_MASK_SIZE];
|
||||
};
|
||||
typedef enum enum_sql_command enum_sql_command_t;
|
||||
typedef enum
|
||||
{
|
||||
MYSQL_AUDIT_GENERAL_LOG = 1 << 0,
|
||||
MYSQL_AUDIT_GENERAL_ERROR = 1 << 1,
|
||||
MYSQL_AUDIT_GENERAL_RESULT = 1 << 2,
|
||||
MYSQL_AUDIT_GENERAL_STATUS = 1 << 3
|
||||
} mysql_event_general_subclass_t;
|
||||
struct mysql_event_general
|
||||
{
|
||||
mysql_event_general_subclass_t event_subclass;
|
||||
int general_error_code;
|
||||
unsigned long general_thread_id;
|
||||
MYSQL_LEX_CSTRING general_user;
|
||||
MYSQL_LEX_CSTRING general_command;
|
||||
MYSQL_LEX_CSTRING general_query;
|
||||
struct charset_info_st *general_charset;
|
||||
unsigned long long general_time;
|
||||
unsigned long long general_rows;
|
||||
MYSQL_LEX_CSTRING general_host;
|
||||
MYSQL_LEX_CSTRING general_sql_command;
|
||||
MYSQL_LEX_CSTRING general_external_user;
|
||||
MYSQL_LEX_CSTRING general_ip;
|
||||
};
|
||||
typedef enum
|
||||
{
|
||||
MYSQL_AUDIT_CONNECTION_CONNECT = 1 << 0,
|
||||
MYSQL_AUDIT_CONNECTION_DISCONNECT = 1 << 1,
|
||||
MYSQL_AUDIT_CONNECTION_CHANGE_USER = 1 << 2,
|
||||
MYSQL_AUDIT_CONNECTION_PRE_AUTHENTICATE = 1 << 3
|
||||
} mysql_event_connection_subclass_t;
|
||||
struct mysql_event_connection
|
||||
{
|
||||
mysql_event_connection_subclass_t event_subclass;
|
||||
int status;
|
||||
unsigned long connection_id;
|
||||
MYSQL_LEX_CSTRING user;
|
||||
MYSQL_LEX_CSTRING priv_user;
|
||||
MYSQL_LEX_CSTRING external_user;
|
||||
MYSQL_LEX_CSTRING proxy_user;
|
||||
MYSQL_LEX_CSTRING host;
|
||||
MYSQL_LEX_CSTRING ip;
|
||||
MYSQL_LEX_CSTRING database;
|
||||
int connection_type;
|
||||
};
|
||||
typedef enum
|
||||
{
|
||||
MYSQL_AUDIT_PARSE_PREPARSE = 1 << 0,
|
||||
MYSQL_AUDIT_PARSE_POSTPARSE = 1 << 1
|
||||
} mysql_event_parse_subclass_t;
|
||||
typedef enum
|
||||
{
|
||||
MYSQL_AUDIT_PARSE_REWRITE_PLUGIN_NONE = 0,
|
||||
MYSQL_AUDIT_PARSE_REWRITE_PLUGIN_QUERY_REWRITTEN = 1 << 0,
|
||||
MYSQL_AUDIT_PARSE_REWRITE_PLUGIN_IS_PREPARED_STATEMENT = 1 << 1
|
||||
} mysql_event_parse_rewrite_plugin_flag;
|
||||
struct mysql_event_parse
|
||||
{
|
||||
mysql_event_parse_subclass_t event_subclass;
|
||||
mysql_event_parse_rewrite_plugin_flag *flags;
|
||||
MYSQL_LEX_CSTRING query;
|
||||
MYSQL_LEX_CSTRING *rewritten_query;
|
||||
};
|
||||
typedef enum
|
||||
{
|
||||
MYSQL_AUDIT_AUTHORIZATION_USER = 1 << 0,
|
||||
MYSQL_AUDIT_AUTHORIZATION_DB = 1 << 1,
|
||||
MYSQL_AUDIT_AUTHORIZATION_TABLE = 1 << 2,
|
||||
MYSQL_AUDIT_AUTHORIZATION_COLUMN = 1 << 3,
|
||||
MYSQL_AUDIT_AUTHORIZATION_PROCEDURE = 1 << 4,
|
||||
MYSQL_AUDIT_AUTHORIZATION_PROXY = 1 << 5
|
||||
} mysql_event_authorization_subclass_t;
|
||||
struct mysql_event_authorization
|
||||
{
|
||||
mysql_event_authorization_subclass_t event_subclass;
|
||||
int status;
|
||||
unsigned int connection_id;
|
||||
enum_sql_command_t sql_command_id;
|
||||
MYSQL_LEX_CSTRING query;
|
||||
const struct charset_info_st *query_charset;
|
||||
MYSQL_LEX_CSTRING database;
|
||||
MYSQL_LEX_CSTRING table;
|
||||
MYSQL_LEX_CSTRING object;
|
||||
unsigned long requested_privilege;
|
||||
unsigned long granted_privilege;
|
||||
};
|
||||
typedef enum
|
||||
{
|
||||
MYSQL_AUDIT_TABLE_ACCESS_READ = 1 << 0,
|
||||
MYSQL_AUDIT_TABLE_ACCESS_INSERT = 1 << 1,
|
||||
MYSQL_AUDIT_TABLE_ACCESS_UPDATE = 1 << 2,
|
||||
MYSQL_AUDIT_TABLE_ACCESS_DELETE = 1 << 3
|
||||
} mysql_event_table_access_subclass_t;
|
||||
struct mysql_event_table_access
|
||||
{
|
||||
mysql_event_table_access_subclass_t event_subclass;
|
||||
unsigned long connection_id;
|
||||
enum_sql_command_t sql_command_id;
|
||||
MYSQL_LEX_CSTRING query;
|
||||
const struct charset_info_st *query_charset;
|
||||
MYSQL_LEX_CSTRING table_database;
|
||||
MYSQL_LEX_CSTRING table_name;
|
||||
};
|
||||
typedef enum
|
||||
{
|
||||
MYSQL_AUDIT_GLOBAL_VARIABLE_GET = 1 << 0,
|
||||
MYSQL_AUDIT_GLOBAL_VARIABLE_SET = 1 << 1
|
||||
} mysql_event_global_variable_subclass_t;
|
||||
struct mysql_event_global_variable
|
||||
{
|
||||
mysql_event_global_variable_subclass_t event_subclass;
|
||||
unsigned long connection_id;
|
||||
enum_sql_command_t sql_command_id;
|
||||
MYSQL_LEX_CSTRING variable_name;
|
||||
MYSQL_LEX_CSTRING variable_value;
|
||||
};
|
||||
typedef enum
|
||||
{
|
||||
MYSQL_AUDIT_SERVER_STARTUP_STARTUP = 1 << 0
|
||||
} mysql_event_server_startup_subclass_t;
|
||||
struct mysql_event_server_startup
|
||||
{
|
||||
mysql_event_server_startup_subclass_t event_subclass;
|
||||
const char **argv;
|
||||
unsigned int argc;
|
||||
};
|
||||
typedef enum
|
||||
{
|
||||
MYSQL_AUDIT_SERVER_SHUTDOWN_SHUTDOWN = 1 << 0
|
||||
} mysql_event_server_shutdown_subclass_t;
|
||||
typedef enum
|
||||
{
|
||||
MYSQL_AUDIT_SERVER_SHUTDOWN_REASON_SHUTDOWN,
|
||||
MYSQL_AUDIT_SERVER_SHUTDOWN_REASON_ABORT
|
||||
} mysql_server_shutdown_reason_t;
|
||||
struct mysql_event_server_shutdown
|
||||
{
|
||||
mysql_event_server_shutdown_subclass_t event_subclass;
|
||||
int exit_code;
|
||||
mysql_server_shutdown_reason_t reason;
|
||||
};
|
||||
typedef enum
|
||||
{
|
||||
MYSQL_AUDIT_COMMAND_START = 1 << 0,
|
||||
MYSQL_AUDIT_COMMAND_END = 1 << 1
|
||||
} mysql_event_command_subclass_t;
|
||||
typedef enum enum_server_command enum_server_command_t;
|
||||
struct mysql_event_command
|
||||
{
|
||||
mysql_event_command_subclass_t event_subclass;
|
||||
int status;
|
||||
unsigned long connection_id;
|
||||
enum_server_command_t command_id;
|
||||
};
|
||||
typedef enum
|
||||
{
|
||||
MYSQL_AUDIT_QUERY_START = 1 << 0,
|
||||
MYSQL_AUDIT_QUERY_NESTED_START = 1 << 1,
|
||||
MYSQL_AUDIT_QUERY_STATUS_END = 1 << 2,
|
||||
MYSQL_AUDIT_QUERY_NESTED_STATUS_END = 1 << 3
|
||||
} mysql_event_query_subclass_t;
|
||||
struct mysql_event_query
|
||||
{
|
||||
mysql_event_query_subclass_t event_subclass;
|
||||
int status;
|
||||
unsigned long connection_id;
|
||||
enum_sql_command_t sql_command_id;
|
||||
MYSQL_LEX_CSTRING query;
|
||||
const struct charset_info_st *query_charset;
|
||||
};
|
||||
typedef enum
|
||||
{
|
||||
MYSQL_AUDIT_STORED_PROGRAM_EXECUTE = 1 << 0
|
||||
} mysql_event_stored_program_subclass_t;
|
||||
struct mysql_event_stored_program
|
||||
{
|
||||
mysql_event_stored_program_subclass_t event_subclass;
|
||||
unsigned long connection_id;
|
||||
enum_sql_command_t sql_command_id;
|
||||
MYSQL_LEX_CSTRING query;
|
||||
const struct charset_info_st *query_charset;
|
||||
MYSQL_LEX_CSTRING database;
|
||||
MYSQL_LEX_CSTRING name;
|
||||
void *parameters;
|
||||
};
|
|
@ -0,0 +1,185 @@
|
|||
#ifndef MYSQL_PLUGIN_AUTH_INCLUDED
|
||||
/* Copyright (c) 2010, 2022, Oracle and/or its affiliates.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License, version 2.0,
|
||||
as published by the Free Software Foundation.
|
||||
|
||||
This program is also distributed with certain software (including
|
||||
but not limited to OpenSSL) that is licensed under separate terms,
|
||||
as designated in a particular file or component or in included license
|
||||
documentation. The authors of MySQL hereby grant you an additional
|
||||
permission to link the program and your derivative works with the
|
||||
separately licensed software that they have included with MySQL.
|
||||
|
||||
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, version 2.0, 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 St, Fifth Floor, Boston, MA 02110-1301 USA */
|
||||
|
||||
/**
|
||||
@file
|
||||
|
||||
Authentication Plugin API.
|
||||
|
||||
This file defines the API for server authentication plugins.
|
||||
*/
|
||||
|
||||
#define MYSQL_PLUGIN_AUTH_INCLUDED
|
||||
|
||||
#include <mysql/plugin.h>
|
||||
|
||||
#define MYSQL_AUTHENTICATION_INTERFACE_VERSION 0x0101
|
||||
|
||||
#include "plugin_auth_common.h"
|
||||
|
||||
/* defines for MYSQL_SERVER_AUTH_INFO.password_used */
|
||||
|
||||
#define PASSWORD_USED_NO 0
|
||||
#define PASSWORD_USED_YES 1
|
||||
#define PASSWORD_USED_NO_MENTION 2
|
||||
|
||||
/* Authentication flags */
|
||||
|
||||
#define AUTH_FLAG_PRIVILEGED_USER_FOR_PASSWORD_CHANGE (1L << 0)
|
||||
#define AUTH_FLAG_USES_INTERNAL_STORAGE (1L << 1)
|
||||
|
||||
/**
|
||||
Provides server plugin access to authentication information
|
||||
*/
|
||||
typedef struct st_mysql_server_auth_info
|
||||
{
|
||||
/**
|
||||
User name as sent by the client and shown in USER().
|
||||
NULL if the client packet with the user name was not received yet.
|
||||
*/
|
||||
char *user_name;
|
||||
|
||||
/**
|
||||
Length of user_name
|
||||
*/
|
||||
unsigned int user_name_length;
|
||||
|
||||
/**
|
||||
A corresponding column value from the mysql.user table for the
|
||||
matching account name
|
||||
*/
|
||||
const char *auth_string;
|
||||
|
||||
/**
|
||||
Length of auth_string
|
||||
*/
|
||||
unsigned long auth_string_length;
|
||||
|
||||
/**
|
||||
Matching account name as found in the mysql.user table.
|
||||
A plugin can override it with another name that will be
|
||||
used by MySQL for authorization, and shown in CURRENT_USER()
|
||||
*/
|
||||
char authenticated_as[MYSQL_USERNAME_LENGTH+1];
|
||||
|
||||
|
||||
/**
|
||||
The unique user name that was used by the plugin to authenticate.
|
||||
Plugins should put null-terminated UTF-8 here.
|
||||
Available through the @@EXTERNAL_USER variable.
|
||||
*/
|
||||
char external_user[512];
|
||||
|
||||
/**
|
||||
This only affects the "Authentication failed. Password used: %s"
|
||||
error message. has the following values :
|
||||
0 : %s will be NO.
|
||||
1 : %s will be YES.
|
||||
2 : there will be no %s.
|
||||
Set it as appropriate or ignore at will.
|
||||
*/
|
||||
int password_used;
|
||||
|
||||
/**
|
||||
Set to the name of the connected client host, if it can be resolved,
|
||||
or to its IP address otherwise.
|
||||
*/
|
||||
const char *host_or_ip;
|
||||
|
||||
/**
|
||||
Length of host_or_ip
|
||||
*/
|
||||
unsigned int host_or_ip_length;
|
||||
|
||||
} MYSQL_SERVER_AUTH_INFO;
|
||||
|
||||
/**
|
||||
Server authentication plugin descriptor
|
||||
*/
|
||||
struct st_mysql_auth
|
||||
{
|
||||
int interface_version; /** version plugin uses */
|
||||
/**
|
||||
A plugin that a client must use for authentication with this server
|
||||
plugin. Can be NULL to mean "any plugin".
|
||||
*/
|
||||
const char *client_auth_plugin;
|
||||
/**
|
||||
Function provided by the plugin which should perform authentication (using
|
||||
the vio functions if necessary) and return 0 if successful. The plugin can
|
||||
also fill the info.authenticated_as field if a different username should be
|
||||
used for authorization.
|
||||
*/
|
||||
int (*authenticate_user)(MYSQL_PLUGIN_VIO *vio, MYSQL_SERVER_AUTH_INFO *info);
|
||||
/**
|
||||
New plugin API to generate password digest out of authentication string.
|
||||
This function will first invoke a service to check for validity of the
|
||||
password based on the policies defined and then generate encrypted hash
|
||||
|
||||
@param[OUT] outbuf A buffer provided by server which will hold the
|
||||
authentication string generated by plugin.
|
||||
@param[INOUT] outbuflen Length of server provided buffer as IN param and
|
||||
length of plugin generated string as OUT param.
|
||||
@param[IN] inbuf auth string provided by user.
|
||||
@param[IN] inbuflen auth string length.
|
||||
|
||||
@retval 0 OK
|
||||
1 ERROR
|
||||
|
||||
*/
|
||||
int (*generate_authentication_string)(char *outbuf,
|
||||
unsigned int *outbuflen, const char *inbuf, unsigned int inbuflen);
|
||||
/**
|
||||
Plugin API to validate password digest.
|
||||
|
||||
@param[IN] inbuf hash string to be validated.
|
||||
@param[IN] buflen hash string length.
|
||||
|
||||
@retval 0 OK
|
||||
1 ERROR
|
||||
|
||||
*/
|
||||
int (*validate_authentication_string)(char* const inbuf, unsigned int buflen);
|
||||
/**
|
||||
Plugin API to convert scrambled password to binary form
|
||||
based on scramble type.
|
||||
|
||||
@param[IN] password The password hash containing the salt.
|
||||
@param[IN] password_len The length of the password hash.
|
||||
@param[INOUT] salt Used as password hash based on the
|
||||
authentication plugin.
|
||||
@param[INOUT] salt_len The length of salt.
|
||||
|
||||
@retval 0 OK
|
||||
1 ERROR
|
||||
|
||||
*/
|
||||
int (*set_salt)(const char *password, unsigned int password_len,
|
||||
unsigned char* salt, unsigned char *salt_len);
|
||||
/**
|
||||
Authentication plugin capabilities
|
||||
*/
|
||||
const unsigned long authentication_flags;
|
||||
};
|
||||
#endif
|
||||
|
|
@ -0,0 +1,153 @@
|
|||
#include <mysql/plugin.h>
|
||||
typedef void * MYSQL_PLUGIN;
|
||||
struct st_mysql_xid {
|
||||
long formatID;
|
||||
long gtrid_length;
|
||||
long bqual_length;
|
||||
char data[128];
|
||||
};
|
||||
typedef struct st_mysql_xid MYSQL_XID;
|
||||
enum enum_mysql_show_type
|
||||
{
|
||||
SHOW_UNDEF, SHOW_BOOL,
|
||||
SHOW_INT,
|
||||
SHOW_LONG,
|
||||
SHOW_LONGLONG,
|
||||
SHOW_CHAR, SHOW_CHAR_PTR,
|
||||
SHOW_ARRAY, SHOW_FUNC, SHOW_DOUBLE
|
||||
};
|
||||
enum enum_mysql_show_scope
|
||||
{
|
||||
SHOW_SCOPE_UNDEF,
|
||||
SHOW_SCOPE_GLOBAL
|
||||
};
|
||||
struct st_mysql_show_var
|
||||
{
|
||||
const char *name;
|
||||
char *value;
|
||||
enum enum_mysql_show_type type;
|
||||
enum enum_mysql_show_scope scope;
|
||||
};
|
||||
typedef int (*mysql_show_var_func)(void*, struct st_mysql_show_var*, char *);
|
||||
struct st_mysql_sys_var;
|
||||
struct st_mysql_value;
|
||||
typedef int (*mysql_var_check_func)(void* thd,
|
||||
struct st_mysql_sys_var *var,
|
||||
void *save, struct st_mysql_value *value);
|
||||
typedef void (*mysql_var_update_func)(void* thd,
|
||||
struct st_mysql_sys_var *var,
|
||||
void *var_ptr, const void *save);
|
||||
struct st_mysql_plugin
|
||||
{
|
||||
int type;
|
||||
void *info;
|
||||
const char *name;
|
||||
const char *author;
|
||||
const char *descr;
|
||||
int license;
|
||||
int (*init)(MYSQL_PLUGIN);
|
||||
int (*deinit)(MYSQL_PLUGIN);
|
||||
unsigned int version;
|
||||
struct st_mysql_show_var *status_vars;
|
||||
struct st_mysql_sys_var **system_vars;
|
||||
void * __reserved1;
|
||||
unsigned long flags;
|
||||
};
|
||||
struct st_mysql_daemon
|
||||
{
|
||||
int interface_version;
|
||||
};
|
||||
struct st_mysql_information_schema
|
||||
{
|
||||
int interface_version;
|
||||
};
|
||||
struct st_mysql_storage_engine
|
||||
{
|
||||
int interface_version;
|
||||
};
|
||||
struct handlerton;
|
||||
struct Mysql_replication {
|
||||
int interface_version;
|
||||
};
|
||||
struct st_mysql_value
|
||||
{
|
||||
int (*value_type)(struct st_mysql_value *);
|
||||
const char *(*val_str)(struct st_mysql_value *, char *buffer, int *length);
|
||||
int (*val_real)(struct st_mysql_value *, double *realbuf);
|
||||
int (*val_int)(struct st_mysql_value *, long long *intbuf);
|
||||
int (*is_unsigned)(struct st_mysql_value *);
|
||||
};
|
||||
int thd_in_lock_tables(const void* thd);
|
||||
int thd_tablespace_op(const void* thd);
|
||||
long long thd_test_options(const void* thd, long long test_options);
|
||||
int thd_sql_command(const void* thd);
|
||||
const char *set_thd_proc_info(void* thd, const char *info,
|
||||
const char *calling_func,
|
||||
const char *calling_file,
|
||||
const unsigned int calling_line);
|
||||
void **thd_ha_data(const void* thd, const struct handlerton *hton);
|
||||
void thd_storage_lock_wait(void* thd, long long value);
|
||||
int thd_tx_isolation(const void* thd);
|
||||
int thd_tx_is_read_only(const void* thd);
|
||||
void* thd_tx_arbitrate(void* requestor, void* holder);
|
||||
int thd_tx_priority(const void* thd);
|
||||
int thd_tx_is_dd_trx(const void* thd);
|
||||
char *thd_security_context(void* thd, char *buffer, size_t length,
|
||||
size_t max_query_len);
|
||||
void thd_inc_row_count(void* thd);
|
||||
int thd_allow_batch(void* thd);
|
||||
void thd_mark_transaction_to_rollback(void* thd, int all);
|
||||
int mysql_tmpfile(const char *prefix);
|
||||
int thd_killed(const void* thd);
|
||||
void thd_set_kill_status(const void* thd);
|
||||
void thd_binlog_pos(const void* thd,
|
||||
const char **file_var,
|
||||
unsigned long long *pos_var);
|
||||
unsigned long thd_get_thread_id(const void* thd);
|
||||
void thd_get_xid(const void* thd, MYSQL_XID *xid);
|
||||
void mysql_query_cache_invalidate4(void* thd,
|
||||
const char *key, unsigned int key_length,
|
||||
int using_trx);
|
||||
void *thd_get_ha_data(const void* thd, const struct handlerton *hton);
|
||||
void thd_set_ha_data(void* thd, const struct handlerton *hton,
|
||||
const void *ha_data);
|
||||
#include "plugin_auth_common.h"
|
||||
typedef struct st_plugin_vio_info
|
||||
{
|
||||
enum { MYSQL_VIO_INVALID, MYSQL_VIO_TCP, MYSQL_VIO_SOCKET,
|
||||
MYSQL_VIO_PIPE, MYSQL_VIO_MEMORY } protocol;
|
||||
int socket;
|
||||
} MYSQL_PLUGIN_VIO_INFO;
|
||||
typedef struct st_plugin_vio
|
||||
{
|
||||
int (*read_packet)(struct st_plugin_vio *vio,
|
||||
unsigned char **buf);
|
||||
int (*write_packet)(struct st_plugin_vio *vio,
|
||||
const unsigned char *packet,
|
||||
int packet_len);
|
||||
void (*info)(struct st_plugin_vio *vio, struct st_plugin_vio_info *info);
|
||||
} MYSQL_PLUGIN_VIO;
|
||||
typedef struct st_mysql_server_auth_info
|
||||
{
|
||||
char *user_name;
|
||||
unsigned int user_name_length;
|
||||
const char *auth_string;
|
||||
unsigned long auth_string_length;
|
||||
char authenticated_as[96 +1];
|
||||
char external_user[512];
|
||||
int password_used;
|
||||
const char *host_or_ip;
|
||||
unsigned int host_or_ip_length;
|
||||
} MYSQL_SERVER_AUTH_INFO;
|
||||
struct st_mysql_auth
|
||||
{
|
||||
int interface_version;
|
||||
const char *client_auth_plugin;
|
||||
int (*authenticate_user)(MYSQL_PLUGIN_VIO *vio, MYSQL_SERVER_AUTH_INFO *info);
|
||||
int (*generate_authentication_string)(char *outbuf,
|
||||
unsigned int *outbuflen, const char *inbuf, unsigned int inbuflen);
|
||||
int (*validate_authentication_string)(char* const inbuf, unsigned int buflen);
|
||||
int (*set_salt)(const char *password, unsigned int password_len,
|
||||
unsigned char* salt, unsigned char *salt_len);
|
||||
const unsigned long authentication_flags;
|
||||
};
|
|
@ -27,7 +27,7 @@
|
|||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
|
||||
|
||||
/**
|
||||
@file include/mysql/plugin_auth_common.h
|
||||
@file
|
||||
|
||||
This file defines constants and data structures that are the same for
|
||||
both client- and server-side authentication plugins.
|
||||
|
@ -94,12 +94,7 @@
|
|||
or not.
|
||||
*/
|
||||
#define CR_OK_HANDSHAKE_COMPLETE -2
|
||||
/**
|
||||
Authentication was successful with limited operations.
|
||||
It means that the both client and server side plugins decided to allow
|
||||
authentication with very limited operations ALTER USER to do registration.
|
||||
*/
|
||||
#define CR_OK_AUTH_IN_SANDBOX_MODE -3
|
||||
|
||||
/**
|
||||
Flag to be passed back to server from authentication plugins via
|
||||
authenticated_as when proxy mapping should be done by the server.
|
||||
|
@ -110,78 +105,51 @@ authenticated_as when proxy mapping should be done by the server.
|
|||
We need HANDLE definition if on Windows. Define WIN32_LEAN_AND_MEAN (if
|
||||
not already done) to minimize amount of imported declarations.
|
||||
*/
|
||||
#if defined(_WIN32) && !defined(MYSQL_ABI_CHECK)
|
||||
#ifdef _WIN32
|
||||
#ifndef WIN32_LEAN_AND_MEAN
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#endif
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
struct MYSQL_PLUGIN_VIO_INFO {
|
||||
enum {
|
||||
MYSQL_VIO_INVALID,
|
||||
MYSQL_VIO_TCP,
|
||||
MYSQL_VIO_SOCKET,
|
||||
MYSQL_VIO_PIPE,
|
||||
MYSQL_VIO_MEMORY
|
||||
} protocol;
|
||||
typedef struct st_plugin_vio_info
|
||||
{
|
||||
enum { MYSQL_VIO_INVALID, MYSQL_VIO_TCP, MYSQL_VIO_SOCKET,
|
||||
MYSQL_VIO_PIPE, MYSQL_VIO_MEMORY } protocol;
|
||||
int socket; /**< it's set, if the protocol is SOCKET or TCP */
|
||||
#if defined(_WIN32) && !defined(MYSQL_ABI_CHECK)
|
||||
#ifdef _WIN32
|
||||
HANDLE handle; /**< it's set, if the protocol is PIPE or MEMORY */
|
||||
#endif
|
||||
};
|
||||
|
||||
/* state of an asynchronous operation */
|
||||
enum net_async_status {
|
||||
NET_ASYNC_COMPLETE = 0,
|
||||
NET_ASYNC_NOT_READY,
|
||||
NET_ASYNC_ERROR,
|
||||
NET_ASYNC_COMPLETE_NO_MORE_RESULTS
|
||||
};
|
||||
} MYSQL_PLUGIN_VIO_INFO;
|
||||
|
||||
/**
|
||||
Provides plugin access to communication channel
|
||||
*/
|
||||
typedef struct MYSQL_PLUGIN_VIO {
|
||||
typedef struct st_plugin_vio
|
||||
{
|
||||
/**
|
||||
Plugin provides a pointer reference and this function sets it to the
|
||||
contents of any incoming packet. Returns the packet length, or -1 if
|
||||
the plugin should terminate.
|
||||
*/
|
||||
int (*read_packet)(struct MYSQL_PLUGIN_VIO *vio, unsigned char **buf);
|
||||
int (*read_packet)(struct st_plugin_vio *vio,
|
||||
unsigned char **buf);
|
||||
|
||||
/**
|
||||
Plugin provides a buffer with data and the length and this
|
||||
function sends it as a packet. Returns 0 on success, 1 on failure.
|
||||
*/
|
||||
int (*write_packet)(struct MYSQL_PLUGIN_VIO *vio, const unsigned char *packet,
|
||||
int (*write_packet)(struct st_plugin_vio *vio,
|
||||
const unsigned char *packet,
|
||||
int packet_len);
|
||||
|
||||
/**
|
||||
Fills in a MYSQL_PLUGIN_VIO_INFO structure, providing the information
|
||||
Fills in a st_plugin_vio_info structure, providing the information
|
||||
about the connection.
|
||||
*/
|
||||
void (*info)(struct MYSQL_PLUGIN_VIO *vio,
|
||||
struct MYSQL_PLUGIN_VIO_INFO *info);
|
||||
|
||||
/**
|
||||
Non blocking version of read_packet. This function points buf to starting
|
||||
position of incoming packet. When this function returns NET_ASYNC_NOT_READY
|
||||
plugin should call this function again until all incoming packets are read.
|
||||
If return code is NET_ASYNC_COMPLETE, plugin can do further processing of
|
||||
read packets.
|
||||
*/
|
||||
enum net_async_status (*read_packet_nonblocking)(struct MYSQL_PLUGIN_VIO *vio,
|
||||
unsigned char **buf,
|
||||
int *result);
|
||||
/**
|
||||
Non blocking version of write_packet. Sends data available in pkt of length
|
||||
pkt_len to server in asynchronous way.
|
||||
*/
|
||||
enum net_async_status (*write_packet_nonblocking)(
|
||||
struct MYSQL_PLUGIN_VIO *vio, const unsigned char *pkt, int pkt_len,
|
||||
int *result);
|
||||
void (*info)(struct st_plugin_vio *vio, struct st_plugin_vio_info *info);
|
||||
|
||||
} MYSQL_PLUGIN_VIO;
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,221 @@
|
|||
/* Copyright (c) 2005, 2022, Oracle and/or its affiliates.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License, version 2.0,
|
||||
as published by the Free Software Foundation.
|
||||
|
||||
This program is also distributed with certain software (including
|
||||
but not limited to OpenSSL) that is licensed under separate terms,
|
||||
as designated in a particular file or component or in included license
|
||||
documentation. The authors of MySQL hereby grant you an additional
|
||||
permission to link the program and your derivative works with the
|
||||
separately licensed software that they have included with MySQL.
|
||||
|
||||
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, version 2.0, 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 St, Fifth Floor, Boston, MA 02110-1301 USA */
|
||||
|
||||
#ifndef _my_plugin_ftparser_h
|
||||
#define _my_plugin_ftparser_h
|
||||
|
||||
#include "plugin.h"
|
||||
|
||||
/*************************************************************************
|
||||
API for Full-text parser plugin. (MYSQL_FTPARSER_PLUGIN)
|
||||
*/
|
||||
|
||||
|
||||
/* Parsing modes. Set in MYSQL_FTPARSER_PARAM::mode */
|
||||
enum enum_ftparser_mode
|
||||
{
|
||||
/*
|
||||
Fast and simple mode. This mode is used for indexing, and natural
|
||||
language queries.
|
||||
|
||||
The parser is expected to return only those words that go into the
|
||||
index. Stopwords or too short/long words should not be returned. The
|
||||
'boolean_info' argument of mysql_add_word() does not have to be set.
|
||||
*/
|
||||
MYSQL_FTPARSER_SIMPLE_MODE= 0,
|
||||
|
||||
/*
|
||||
Parse with stopwords mode. This mode is used in boolean searches for
|
||||
"phrase matching."
|
||||
|
||||
The parser is not allowed to ignore words in this mode. Every word
|
||||
should be returned, including stopwords and words that are too short
|
||||
or long. The 'boolean_info' argument of mysql_add_word() does not
|
||||
have to be set.
|
||||
*/
|
||||
MYSQL_FTPARSER_WITH_STOPWORDS= 1,
|
||||
|
||||
/*
|
||||
Parse in boolean mode. This mode is used to parse a boolean query string.
|
||||
|
||||
The parser should provide a valid MYSQL_FTPARSER_BOOLEAN_INFO
|
||||
structure in the 'boolean_info' argument to mysql_add_word().
|
||||
Usually that means that the parser should recognize boolean operators
|
||||
in the parsing stream and set appropriate fields in
|
||||
MYSQL_FTPARSER_BOOLEAN_INFO structure accordingly. As for
|
||||
MYSQL_FTPARSER_WITH_STOPWORDS mode, no word should be ignored.
|
||||
Instead, use FT_TOKEN_STOPWORD for the token type of such a word.
|
||||
*/
|
||||
MYSQL_FTPARSER_FULL_BOOLEAN_INFO= 2
|
||||
};
|
||||
|
||||
/*
|
||||
Token types for boolean mode searching (used for the type member of
|
||||
MYSQL_FTPARSER_BOOLEAN_INFO struct)
|
||||
|
||||
FT_TOKEN_EOF: End of data.
|
||||
FT_TOKEN_WORD: Regular word.
|
||||
FT_TOKEN_LEFT_PAREN: Left parenthesis (start of group/sub-expression).
|
||||
FT_TOKEN_RIGHT_PAREN: Right parenthesis (end of group/sub-expression).
|
||||
FT_TOKEN_STOPWORD: Stopword.
|
||||
*/
|
||||
|
||||
enum enum_ft_token_type
|
||||
{
|
||||
FT_TOKEN_EOF= 0,
|
||||
FT_TOKEN_WORD= 1,
|
||||
FT_TOKEN_LEFT_PAREN= 2,
|
||||
FT_TOKEN_RIGHT_PAREN= 3,
|
||||
FT_TOKEN_STOPWORD= 4
|
||||
};
|
||||
|
||||
/*
|
||||
This structure is used in boolean search mode only. It conveys
|
||||
boolean-mode metadata to the MySQL search engine for every word in
|
||||
the search query. A valid instance of this structure must be filled
|
||||
in by the plugin parser and passed as an argument in the call to
|
||||
mysql_add_word (the callback function in the MYSQL_FTPARSER_PARAM
|
||||
structure) when a query is parsed in boolean mode.
|
||||
|
||||
type: The token type. Should be one of the enum_ft_token_type values.
|
||||
|
||||
yesno: Whether the word must be present for a match to occur:
|
||||
>0 Must be present
|
||||
<0 Must not be present
|
||||
0 Neither; the word is optional but its presence increases the relevance
|
||||
With the default settings of the ft_boolean_syntax system variable,
|
||||
>0 corresponds to the '+' operator, <0 corrresponds to the '-' operator,
|
||||
and 0 means neither operator was used.
|
||||
|
||||
weight_adjust: A weighting factor that determines how much a match
|
||||
for the word counts. Positive values increase, negative - decrease the
|
||||
relative word's importance in the query.
|
||||
|
||||
wasign: The sign of the word's weight in the query. If it's non-negative
|
||||
the match for the word will increase document relevance, if it's
|
||||
negative - decrease (the word becomes a "noise word", the less of it the
|
||||
better).
|
||||
|
||||
trunc: Corresponds to the '*' operator in the default setting of the
|
||||
ft_boolean_syntax system variable.
|
||||
|
||||
position: Start position in bytes of the word in the document, used by InnoDB FTS.
|
||||
*/
|
||||
|
||||
typedef struct st_mysql_ftparser_boolean_info
|
||||
{
|
||||
enum enum_ft_token_type type;
|
||||
int yesno;
|
||||
int weight_adjust;
|
||||
char wasign;
|
||||
char trunc;
|
||||
int position;
|
||||
/* These are parser state and must be removed. */
|
||||
char prev;
|
||||
char *quot;
|
||||
} MYSQL_FTPARSER_BOOLEAN_INFO;
|
||||
|
||||
/*
|
||||
The following flag means that buffer with a string (document, word)
|
||||
may be overwritten by the caller before the end of the parsing (that is
|
||||
before st_mysql_ftparser::deinit() call). If one needs the string
|
||||
to survive between two successive calls of the parsing function, she
|
||||
needs to save a copy of it. The flag may be set by MySQL before calling
|
||||
st_mysql_ftparser::parse(), or it may be set by a plugin before calling
|
||||
st_mysql_ftparser_param::mysql_parse() or
|
||||
st_mysql_ftparser_param::mysql_add_word().
|
||||
*/
|
||||
#define MYSQL_FTFLAGS_NEED_COPY 1
|
||||
|
||||
/*
|
||||
An argument of the full-text parser plugin. This structure is
|
||||
filled in by MySQL server and passed to the parsing function of the
|
||||
plugin as an in/out parameter.
|
||||
|
||||
mysql_parse: A pointer to the built-in parser implementation of the
|
||||
server. It's set by the server and can be used by the parser plugin
|
||||
to invoke the MySQL default parser. If plugin's role is to extract
|
||||
textual data from .doc, .pdf or .xml content, it might extract
|
||||
plaintext from the content, and then pass the text to the default
|
||||
MySQL parser to be parsed.
|
||||
|
||||
mysql_add_word: A server callback to add a new word. When parsing
|
||||
a document, the server sets this to point at a function that adds
|
||||
the word to MySQL full-text index. When parsing a search query,
|
||||
this function will add the new word to the list of words to search
|
||||
for. The boolean_info argument can be NULL for all cases except
|
||||
when mode is MYSQL_FTPARSER_FULL_BOOLEAN_INFO.
|
||||
|
||||
ftparser_state: A generic pointer. The plugin can set it to point
|
||||
to information to be used internally for its own purposes.
|
||||
|
||||
mysql_ftparam: This is set by the server. It is used by MySQL functions
|
||||
called via mysql_parse() and mysql_add_word() callback. The plugin
|
||||
should not modify it.
|
||||
|
||||
cs: Information about the character set of the document or query string.
|
||||
|
||||
doc: A pointer to the document or query string to be parsed.
|
||||
|
||||
length: Length of the document or query string, in bytes.
|
||||
|
||||
flags: See MYSQL_FTFLAGS_* constants above.
|
||||
|
||||
mode: The parsing mode. With boolean operators, with stopwords, or
|
||||
nothing. See enum_ftparser_mode above.
|
||||
*/
|
||||
|
||||
typedef struct st_mysql_ftparser_param
|
||||
{
|
||||
int (*mysql_parse)(struct st_mysql_ftparser_param *,
|
||||
char *doc, int doc_len);
|
||||
int (*mysql_add_word)(struct st_mysql_ftparser_param *,
|
||||
char *word, int word_len,
|
||||
MYSQL_FTPARSER_BOOLEAN_INFO *boolean_info);
|
||||
void *ftparser_state;
|
||||
void *mysql_ftparam;
|
||||
const struct charset_info_st *cs;
|
||||
char *doc;
|
||||
int length;
|
||||
int flags;
|
||||
enum enum_ftparser_mode mode;
|
||||
} MYSQL_FTPARSER_PARAM;
|
||||
|
||||
/*
|
||||
Full-text parser descriptor.
|
||||
|
||||
interface_version is, e.g., MYSQL_FTPARSER_INTERFACE_VERSION.
|
||||
The parsing, initialization, and deinitialization functions are
|
||||
invoked per SQL statement for which the parser is used.
|
||||
*/
|
||||
|
||||
struct st_mysql_ftparser
|
||||
{
|
||||
int interface_version;
|
||||
int (*parse)(MYSQL_FTPARSER_PARAM *param);
|
||||
int (*init)(MYSQL_FTPARSER_PARAM *param);
|
||||
int (*deinit)(MYSQL_FTPARSER_PARAM *param);
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,160 @@
|
|||
#include "plugin.h"
|
||||
typedef void * MYSQL_PLUGIN;
|
||||
struct st_mysql_xid {
|
||||
long formatID;
|
||||
long gtrid_length;
|
||||
long bqual_length;
|
||||
char data[128];
|
||||
};
|
||||
typedef struct st_mysql_xid MYSQL_XID;
|
||||
enum enum_mysql_show_type
|
||||
{
|
||||
SHOW_UNDEF, SHOW_BOOL,
|
||||
SHOW_INT,
|
||||
SHOW_LONG,
|
||||
SHOW_LONGLONG,
|
||||
SHOW_CHAR, SHOW_CHAR_PTR,
|
||||
SHOW_ARRAY, SHOW_FUNC, SHOW_DOUBLE
|
||||
};
|
||||
enum enum_mysql_show_scope
|
||||
{
|
||||
SHOW_SCOPE_UNDEF,
|
||||
SHOW_SCOPE_GLOBAL
|
||||
};
|
||||
struct st_mysql_show_var
|
||||
{
|
||||
const char *name;
|
||||
char *value;
|
||||
enum enum_mysql_show_type type;
|
||||
enum enum_mysql_show_scope scope;
|
||||
};
|
||||
typedef int (*mysql_show_var_func)(void*, struct st_mysql_show_var*, char *);
|
||||
struct st_mysql_sys_var;
|
||||
struct st_mysql_value;
|
||||
typedef int (*mysql_var_check_func)(void* thd,
|
||||
struct st_mysql_sys_var *var,
|
||||
void *save, struct st_mysql_value *value);
|
||||
typedef void (*mysql_var_update_func)(void* thd,
|
||||
struct st_mysql_sys_var *var,
|
||||
void *var_ptr, const void *save);
|
||||
struct st_mysql_plugin
|
||||
{
|
||||
int type;
|
||||
void *info;
|
||||
const char *name;
|
||||
const char *author;
|
||||
const char *descr;
|
||||
int license;
|
||||
int (*init)(MYSQL_PLUGIN);
|
||||
int (*deinit)(MYSQL_PLUGIN);
|
||||
unsigned int version;
|
||||
struct st_mysql_show_var *status_vars;
|
||||
struct st_mysql_sys_var **system_vars;
|
||||
void * __reserved1;
|
||||
unsigned long flags;
|
||||
};
|
||||
struct st_mysql_daemon
|
||||
{
|
||||
int interface_version;
|
||||
};
|
||||
struct st_mysql_information_schema
|
||||
{
|
||||
int interface_version;
|
||||
};
|
||||
struct st_mysql_storage_engine
|
||||
{
|
||||
int interface_version;
|
||||
};
|
||||
struct handlerton;
|
||||
struct Mysql_replication {
|
||||
int interface_version;
|
||||
};
|
||||
struct st_mysql_value
|
||||
{
|
||||
int (*value_type)(struct st_mysql_value *);
|
||||
const char *(*val_str)(struct st_mysql_value *, char *buffer, int *length);
|
||||
int (*val_real)(struct st_mysql_value *, double *realbuf);
|
||||
int (*val_int)(struct st_mysql_value *, long long *intbuf);
|
||||
int (*is_unsigned)(struct st_mysql_value *);
|
||||
};
|
||||
int thd_in_lock_tables(const void* thd);
|
||||
int thd_tablespace_op(const void* thd);
|
||||
long long thd_test_options(const void* thd, long long test_options);
|
||||
int thd_sql_command(const void* thd);
|
||||
const char *set_thd_proc_info(void* thd, const char *info,
|
||||
const char *calling_func,
|
||||
const char *calling_file,
|
||||
const unsigned int calling_line);
|
||||
void **thd_ha_data(const void* thd, const struct handlerton *hton);
|
||||
void thd_storage_lock_wait(void* thd, long long value);
|
||||
int thd_tx_isolation(const void* thd);
|
||||
int thd_tx_is_read_only(const void* thd);
|
||||
void* thd_tx_arbitrate(void* requestor, void* holder);
|
||||
int thd_tx_priority(const void* thd);
|
||||
int thd_tx_is_dd_trx(const void* thd);
|
||||
char *thd_security_context(void* thd, char *buffer, size_t length,
|
||||
size_t max_query_len);
|
||||
void thd_inc_row_count(void* thd);
|
||||
int thd_allow_batch(void* thd);
|
||||
void thd_mark_transaction_to_rollback(void* thd, int all);
|
||||
int mysql_tmpfile(const char *prefix);
|
||||
int thd_killed(const void* thd);
|
||||
void thd_set_kill_status(const void* thd);
|
||||
void thd_binlog_pos(const void* thd,
|
||||
const char **file_var,
|
||||
unsigned long long *pos_var);
|
||||
unsigned long thd_get_thread_id(const void* thd);
|
||||
void thd_get_xid(const void* thd, MYSQL_XID *xid);
|
||||
void mysql_query_cache_invalidate4(void* thd,
|
||||
const char *key, unsigned int key_length,
|
||||
int using_trx);
|
||||
void *thd_get_ha_data(const void* thd, const struct handlerton *hton);
|
||||
void thd_set_ha_data(void* thd, const struct handlerton *hton,
|
||||
const void *ha_data);
|
||||
enum enum_ftparser_mode
|
||||
{
|
||||
MYSQL_FTPARSER_SIMPLE_MODE= 0,
|
||||
MYSQL_FTPARSER_WITH_STOPWORDS= 1,
|
||||
MYSQL_FTPARSER_FULL_BOOLEAN_INFO= 2
|
||||
};
|
||||
enum enum_ft_token_type
|
||||
{
|
||||
FT_TOKEN_EOF= 0,
|
||||
FT_TOKEN_WORD= 1,
|
||||
FT_TOKEN_LEFT_PAREN= 2,
|
||||
FT_TOKEN_RIGHT_PAREN= 3,
|
||||
FT_TOKEN_STOPWORD= 4
|
||||
};
|
||||
typedef struct st_mysql_ftparser_boolean_info
|
||||
{
|
||||
enum enum_ft_token_type type;
|
||||
int yesno;
|
||||
int weight_adjust;
|
||||
char wasign;
|
||||
char trunc;
|
||||
int position;
|
||||
char prev;
|
||||
char *quot;
|
||||
} MYSQL_FTPARSER_BOOLEAN_INFO;
|
||||
typedef struct st_mysql_ftparser_param
|
||||
{
|
||||
int (*mysql_parse)(struct st_mysql_ftparser_param *,
|
||||
char *doc, int doc_len);
|
||||
int (*mysql_add_word)(struct st_mysql_ftparser_param *,
|
||||
char *word, int word_len,
|
||||
MYSQL_FTPARSER_BOOLEAN_INFO *boolean_info);
|
||||
void *ftparser_state;
|
||||
void *mysql_ftparam;
|
||||
const struct charset_info_st *cs;
|
||||
char *doc;
|
||||
int length;
|
||||
int flags;
|
||||
enum enum_ftparser_mode mode;
|
||||
} MYSQL_FTPARSER_PARAM;
|
||||
struct st_mysql_ftparser
|
||||
{
|
||||
int interface_version;
|
||||
int (*parse)(MYSQL_FTPARSER_PARAM *param);
|
||||
int (*init)(MYSQL_FTPARSER_PARAM *param);
|
||||
int (*deinit)(MYSQL_FTPARSER_PARAM *param);
|
||||
};
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue