summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-rw-r--r--plugins/Dropbox/Dropbox.vcxproj45
-rw-r--r--plugins/Dropbox/Dropbox.vcxproj.filters4
-rw-r--r--plugins/Dropbox/proto_dropbox/Proto_Dropbox.vcxproj28
-rw-r--r--plugins/Dropbox/proto_dropbox/Proto_Dropbox.vcxproj.filters4
-rw-r--r--plugins/Dropbox/proto_dropbox/res/Offline.icobin5430 -> 0 bytes
-rw-r--r--plugins/Dropbox/proto_dropbox/res/Online.icobin5430 -> 0 bytes
-rw-r--r--plugins/Dropbox/proto_dropbox/res/Proto_Dropbox.rc70
-rw-r--r--plugins/Dropbox/proto_dropbox/src/resource.h17
-rw-r--r--plugins/Dropbox/res/dropbox.icobin5430 -> 0 bytes
-rw-r--r--plugins/Dropbox/res/resource.rc175
-rw-r--r--plugins/Dropbox/res/upload.icobin5430 -> 0 bytes
-rw-r--r--plugins/Dropbox/res/version.rc55
-rw-r--r--plugins/Dropbox/src/api/account.h38
-rw-r--r--plugins/Dropbox/src/api/operations.h143
-rw-r--r--plugins/Dropbox/src/api/upload.h94
-rw-r--r--plugins/Dropbox/src/dropbox.cpp219
-rw-r--r--plugins/Dropbox/src/dropbox.h142
-rw-r--r--plugins/Dropbox/src/dropbox_commands.cpp176
-rw-r--r--plugins/Dropbox/src/dropbox_events.cpp129
-rw-r--r--plugins/Dropbox/src/dropbox_icons.cpp30
-rw-r--r--plugins/Dropbox/src/dropbox_menus.cpp51
-rw-r--r--plugins/Dropbox/src/dropbox_options.cpp160
-rw-r--r--plugins/Dropbox/src/dropbox_options.h50
-rw-r--r--plugins/Dropbox/src/dropbox_services.cpp227
-rw-r--r--plugins/Dropbox/src/dropbox_transfers.cpp217
-rw-r--r--plugins/Dropbox/src/dropbox_utils.cpp156
-rw-r--r--plugins/Dropbox/src/file_transfer.h245
-rw-r--r--plugins/Dropbox/src/http_request.h166
-rw-r--r--plugins/Dropbox/src/main.cpp55
-rw-r--r--plugins/Dropbox/src/resource.h34
-rw-r--r--plugins/Dropbox/src/stdafx.cxx20
-rw-r--r--plugins/Dropbox/src/stdafx.h87
-rw-r--r--plugins/Dropbox/src/version.h14
-rw-r--r--plugins/SmileyAdd/SmileyAdd.vcxproj10
-rw-r--r--plugins/SmileyAdd/src/download.cpp11
-rw-r--r--plugins/SmileyAdd/src/options.cpp4
-rw-r--r--plugins/SmileyAdd/src/regexp/WCMatcher.cpp181
-rw-r--r--plugins/SmileyAdd/src/regexp/WCMatcher.h230
-rw-r--r--plugins/SmileyAdd/src/regexp/WCPattern.cpp1668
-rw-r--r--plugins/SmileyAdd/src/regexp/WCPattern.h1654
-rw-r--r--plugins/SmileyAdd/src/smileys.cpp534
-rw-r--r--plugins/SmileyAdd/src/smileys.h8
-rw-r--r--plugins/SmileyAdd/src/stdafx.h7
-rw-r--r--plugins/SmileyAdd/src/version.h6
-rwxr-xr-xplugins/Watrack_MPD/src/options.cpp71
-rwxr-xr-xplugins/Watrack_MPD/src/stdafx.h1
46 files changed, 191 insertions, 7045 deletions
diff --git a/plugins/Dropbox/Dropbox.vcxproj b/plugins/Dropbox/Dropbox.vcxproj
deleted file mode 100644
index a2df21bfb9..0000000000
--- a/plugins/Dropbox/Dropbox.vcxproj
+++ /dev/null
@@ -1,45 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
- <ItemGroup Label="ProjectConfigurations">
- <ProjectConfiguration Include="Debug|Win32">
- <Configuration>Debug</Configuration>
- <Platform>Win32</Platform>
- </ProjectConfiguration>
- <ProjectConfiguration Include="Debug|x64">
- <Configuration>Debug</Configuration>
- <Platform>x64</Platform>
- </ProjectConfiguration>
- <ProjectConfiguration Include="Release|Win32">
- <Configuration>Release</Configuration>
- <Platform>Win32</Platform>
- </ProjectConfiguration>
- <ProjectConfiguration Include="Release|x64">
- <Configuration>Release</Configuration>
- <Platform>x64</Platform>
- </ProjectConfiguration>
- </ItemGroup>
- <PropertyGroup Label="Globals">
- <ProjectName>Dropbox</ProjectName>
- <ProjectGuid>{CBA58126-3E02-4159-9BD3-059AF9DBC84E}</ProjectGuid>
- </PropertyGroup>
- <ImportGroup Label="PropertySheets">
- <Import Project="$(ProjectDir)..\..\build\vc.common\plugin.props" />
- </ImportGroup>
- <ItemGroup>
- <ClInclude Include="src\api\*.h" />
- <None Include="res\*.ico" />
- </ItemGroup>
- <ItemDefinitionGroup>
- <Link>
- <AdditionalDependencies>comctl32.lib;shlwapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
- </Link>
- <ClCompile>
- <ExceptionHandling>Sync</ExceptionHandling>
- </ClCompile>
- </ItemDefinitionGroup>
- <ItemGroup>
- <ProjectReference Include="..\..\libs\libjson\libjson.vcxproj">
- <Project>{f6a9340e-b8d9-4c75-be30-47dc66d0abc7}</Project>
- </ProjectReference>
- </ItemGroup>
-</Project>
diff --git a/plugins/Dropbox/Dropbox.vcxproj.filters b/plugins/Dropbox/Dropbox.vcxproj.filters
deleted file mode 100644
index a8ab01c0e5..0000000000
--- a/plugins/Dropbox/Dropbox.vcxproj.filters
+++ /dev/null
@@ -1,4 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
- <Import Project="$(ProjectDir)..\..\build\vc.common\common.filters" />
-</Project>
diff --git a/plugins/Dropbox/proto_dropbox/Proto_Dropbox.vcxproj b/plugins/Dropbox/proto_dropbox/Proto_Dropbox.vcxproj
deleted file mode 100644
index cb1d058dc4..0000000000
--- a/plugins/Dropbox/proto_dropbox/Proto_Dropbox.vcxproj
+++ /dev/null
@@ -1,28 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
- <ItemGroup Label="ProjectConfigurations">
- <ProjectConfiguration Include="Debug|Win32">
- <Configuration>Debug</Configuration>
- <Platform>Win32</Platform>
- </ProjectConfiguration>
- <ProjectConfiguration Include="Debug|x64">
- <Configuration>Debug</Configuration>
- <Platform>x64</Platform>
- </ProjectConfiguration>
- <ProjectConfiguration Include="Release|Win32">
- <Configuration>Release</Configuration>
- <Platform>Win32</Platform>
- </ProjectConfiguration>
- <ProjectConfiguration Include="Release|x64">
- <Configuration>Release</Configuration>
- <Platform>x64</Platform>
- </ProjectConfiguration>
- </ItemGroup>
- <PropertyGroup Label="Globals">
- <ProjectName>Proto_Dropbox</ProjectName>
- <ProjectGuid>{16D1337A-C442-4D3E-857C-E0269BA1CCF0}</ProjectGuid>
- </PropertyGroup>
- <ImportGroup Label="PropertySheets">
- <Import Project="$(ProjectDir)..\..\..\build\vc.common\icons.props" />
- </ImportGroup>
-</Project> \ No newline at end of file
diff --git a/plugins/Dropbox/proto_dropbox/Proto_Dropbox.vcxproj.filters b/plugins/Dropbox/proto_dropbox/Proto_Dropbox.vcxproj.filters
deleted file mode 100644
index e39f86d5d6..0000000000
--- a/plugins/Dropbox/proto_dropbox/Proto_Dropbox.vcxproj.filters
+++ /dev/null
@@ -1,4 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
- <Import Project="$(ProjectDir)..\..\..\build\vc.common\common.filters" />
-</Project> \ No newline at end of file
diff --git a/plugins/Dropbox/proto_dropbox/res/Offline.ico b/plugins/Dropbox/proto_dropbox/res/Offline.ico
deleted file mode 100644
index 8f24010392..0000000000
--- a/plugins/Dropbox/proto_dropbox/res/Offline.ico
+++ /dev/null
Binary files differ
diff --git a/plugins/Dropbox/proto_dropbox/res/Online.ico b/plugins/Dropbox/proto_dropbox/res/Online.ico
deleted file mode 100644
index 915cc776c7..0000000000
--- a/plugins/Dropbox/proto_dropbox/res/Online.ico
+++ /dev/null
Binary files differ
diff --git a/plugins/Dropbox/proto_dropbox/res/Proto_Dropbox.rc b/plugins/Dropbox/proto_dropbox/res/Proto_Dropbox.rc
deleted file mode 100644
index 22339493ab..0000000000
--- a/plugins/Dropbox/proto_dropbox/res/Proto_Dropbox.rc
+++ /dev/null
@@ -1,70 +0,0 @@
-// Microsoft Visual C++ generated resource script.
-//
-#include "..\src\resource.h"
-
-#define APSTUDIO_READONLY_SYMBOLS
-/////////////////////////////////////////////////////////////////////////////
-//
-// Generated from the TEXTINCLUDE 2 resource.
-//
-#include "afxres.h"
-
-/////////////////////////////////////////////////////////////////////////////
-#undef APSTUDIO_READONLY_SYMBOLS
-
-/////////////////////////////////////////////////////////////////////////////
-// Russian (Russia) resources
-
-#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_RUS)
-LANGUAGE LANG_RUSSIAN, SUBLANG_DEFAULT
-
-#ifdef APSTUDIO_INVOKED
-/////////////////////////////////////////////////////////////////////////////
-//
-// TEXTINCLUDE
-//
-
-1 TEXTINCLUDE
-BEGIN
- "..\\src\\resource.h\0"
-END
-
-2 TEXTINCLUDE
-BEGIN
- "#include ""afxres.h""\r\n"
- "\0"
-END
-
-3 TEXTINCLUDE
-BEGIN
- "\r\n"
- "\0"
-END
-
-#endif // APSTUDIO_INVOKED
-
-
-/////////////////////////////////////////////////////////////////////////////
-//
-// Icon
-//
-
-// Icon with lowest ID value placed first to ensure application icon
-// remains consistent on all systems.
-IDI_ICON1 ICON "Offline.ico"
-IDI_ICON2 ICON "Online.ico"
-#endif // Russian (Russia) resources
-/////////////////////////////////////////////////////////////////////////////
-
-
-
-#ifndef APSTUDIO_INVOKED
-/////////////////////////////////////////////////////////////////////////////
-//
-// Generated from the TEXTINCLUDE 3 resource.
-//
-
-
-/////////////////////////////////////////////////////////////////////////////
-#endif // not APSTUDIO_INVOKED
-
diff --git a/plugins/Dropbox/proto_dropbox/src/resource.h b/plugins/Dropbox/proto_dropbox/src/resource.h
deleted file mode 100644
index f234a1cbb7..0000000000
--- a/plugins/Dropbox/proto_dropbox/src/resource.h
+++ /dev/null
@@ -1,17 +0,0 @@
-//{{NO_DEPENDENCIES}}
-// Microsoft Visual C++ generated include file.
-// Used by Proto_NewsAggr.rc
-//
-#define IDI_ICON1 105
-#define IDI_ICON2 104
-
-// Next default values for new objects
-//
-#ifdef APSTUDIO_INVOKED
-#ifndef APSTUDIO_READONLY_SYMBOLS
-#define _APS_NEXT_RESOURCE_VALUE 103
-#define _APS_NEXT_COMMAND_VALUE 40001
-#define _APS_NEXT_CONTROL_VALUE 1001
-#define _APS_NEXT_SYMED_VALUE 101
-#endif
-#endif
diff --git a/plugins/Dropbox/res/dropbox.ico b/plugins/Dropbox/res/dropbox.ico
deleted file mode 100644
index 915cc776c7..0000000000
--- a/plugins/Dropbox/res/dropbox.ico
+++ /dev/null
Binary files differ
diff --git a/plugins/Dropbox/res/resource.rc b/plugins/Dropbox/res/resource.rc
deleted file mode 100644
index f9a41025a3..0000000000
--- a/plugins/Dropbox/res/resource.rc
+++ /dev/null
@@ -1,175 +0,0 @@
-// Microsoft Visual C++ generated resource script.
-//
-#include "..\src\resource.h"
-
-#define APSTUDIO_READONLY_SYMBOLS
-/////////////////////////////////////////////////////////////////////////////
-//
-// Generated from the TEXTINCLUDE 2 resource.
-//
-#include "winres.h"
-
-/////////////////////////////////////////////////////////////////////////////
-#undef APSTUDIO_READONLY_SYMBOLS
-
-/////////////////////////////////////////////////////////////////////////////
-// Russian (Russia) resources
-
-#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_RUS)
-LANGUAGE LANG_RUSSIAN, SUBLANG_DEFAULT
-#pragma code_page(1251)
-
-#ifdef APSTUDIO_INVOKED
-/////////////////////////////////////////////////////////////////////////////
-//
-// TEXTINCLUDE
-//
-
-1 TEXTINCLUDE
-BEGIN
- "..\\src\\resource.h\0"
-END
-
-2 TEXTINCLUDE
-BEGIN
- "#include ""winres.h""\r\n"
- "\0"
-END
-
-3 TEXTINCLUDE
-BEGIN
- "\r\n"
- "\0"
-END
-
-#endif // APSTUDIO_INVOKED
-
-#endif // Russian (Russia) resources
-/////////////////////////////////////////////////////////////////////////////
-
-
-/////////////////////////////////////////////////////////////////////////////
-// English resources
-
-#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
-LANGUAGE LANG_ENGLISH, SUBLANG_NEUTRAL
-#pragma code_page(1252)
-
-/////////////////////////////////////////////////////////////////////////////
-//
-// Dialog
-//
-
-IDD_OPTIONS_MAIN DIALOGEX 0, 0, 307, 234
-STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD
-EXSTYLE WS_EX_CONTROLPARENT
-FONT 8, "MS Shell Dlg", 0, 0, 0x1
-BEGIN
- GROUPBOX "Authorization",IDC_STATIC,5,5,297,103
- LTEXT "To allow Miranda NG access in your Dropbox account:",IDC_STATIC,15,18,270,10
- CONTROL "Go to this link",IDC_GETAUTH,"Hyperlink",WS_GROUP | WS_TABSTOP | 0x1,144,35,153,8
- LTEXT "1.",IDC_STATIC,21,35,8,8
- LTEXT "Allow access to app folder",IDC_STATIC,29,35,109,16
- LTEXT "2.",IDC_STATIC,21,53,8,8
- LTEXT "Enter authorization code",IDC_STATIC,29,53,109,16
- EDITTEXT IDC_REQUEST_CODE,144,51,153,13,ES_AUTOHSCROLL
- LTEXT "3.",IDC_STATIC,21,71,8,8
- LTEXT "Initiate authorization",IDC_STATIC,29,71,109,16
- PUSHBUTTON "Authorize",IDC_AUTHORIZE,144,68,153,14,BS_CENTER | WS_DISABLED
- GROUPBOX "Download link",IDC_STATIC,5,111,297,70
- CONTROL "Generate temporary link",IDC_URL_ISTEMPORARY,"Button",BS_AUTOCHECKBOX | WS_GROUP | WS_TABSTOP,15,125,282,10
- LTEXT "4.",IDC_STATIC,22,89,8,8
- LTEXT "Check status of authorization",IDC_STATIC,30,89,108,17
- CTEXT "",IDC_AUTH_STATUS,144,89,153,8
- CONTROL "Autosend download link to contact",IDC_URL_AUTOSEND,
- "Button",BS_AUTORADIOBUTTON,15,138,282,10
- CONTROL "Paste download link into message input area",IDC_URL_COPYTOMIA,
- "Button",BS_AUTORADIOBUTTON,15,151,282,10
- CONTROL "Copy download link to clipboard",IDC_URL_COPYTOCB,
- "Button",BS_AUTOCHECKBOX | WS_TABSTOP,15,164,282,10
-END
-
-IDD_OPTIONS_INTERCEPTION DIALOGEX 0, 0, 308, 234
-STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD
-EXSTYLE WS_EX_CONTROLPARENT
-FONT 8, "MS Shell Dlg", 0, 0, 0x1
-BEGIN
- CONTROL "",IDC_ACCOUNTS,"SysListView32",LVS_REPORT | LVS_ALIGNLEFT | WS_BORDER | WS_TABSTOP,5,34,298,195
- LTEXT "Here you can choose the protocols in which Dropbox will be used instead of regular file transfers (sending), used by this protocol.",IDC_STATIC,5,5,298,24
-END
-
-
-/////////////////////////////////////////////////////////////////////////////
-//
-// DESIGNINFO
-//
-
-#ifdef APSTUDIO_INVOKED
-GUIDELINES DESIGNINFO
-BEGIN
- IDD_OPTIONS_MAIN, DIALOG
- BEGIN
- LEFTMARGIN, 5
- RIGHTMARGIN, 302
- VERTGUIDE, 15
- VERTGUIDE, 21
- VERTGUIDE, 29
- VERTGUIDE, 90
- VERTGUIDE, 96
- VERTGUIDE, 138
- VERTGUIDE, 144
- VERTGUIDE, 297
- TOPMARGIN, 5
- BOTTOMMARGIN, 229
- END
-
- IDD_OPTIONS_INTERCEPTION, DIALOG
- BEGIN
- LEFTMARGIN, 5
- RIGHTMARGIN, 303
- TOPMARGIN, 5
- BOTTOMMARGIN, 229
- HORZGUIDE, 29
- HORZGUIDE, 34
- END
-END
-#endif // APSTUDIO_INVOKED
-
-
-/////////////////////////////////////////////////////////////////////////////
-//
-// Icon
-//
-
-// Icon with lowest ID value placed first to ensure application icon
-// remains consistent on all systems.
-IDI_DROPBOX ICON "dropbox.ico"
-
-IDI_UPLOAD ICON "upload.ico"
-
-
-/////////////////////////////////////////////////////////////////////////////
-//
-// AFX_DIALOG_LAYOUT
-//
-
-IDD_OPTIONS_MAIN AFX_DIALOG_LAYOUT
-BEGIN
- 0
-END
-
-#endif // English resources
-/////////////////////////////////////////////////////////////////////////////
-
-
-
-#ifndef APSTUDIO_INVOKED
-/////////////////////////////////////////////////////////////////////////////
-//
-// Generated from the TEXTINCLUDE 3 resource.
-//
-
-
-/////////////////////////////////////////////////////////////////////////////
-#endif // not APSTUDIO_INVOKED
-
diff --git a/plugins/Dropbox/res/upload.ico b/plugins/Dropbox/res/upload.ico
deleted file mode 100644
index e4d86ec109..0000000000
--- a/plugins/Dropbox/res/upload.ico
+++ /dev/null
Binary files differ
diff --git a/plugins/Dropbox/res/version.rc b/plugins/Dropbox/res/version.rc
deleted file mode 100644
index fdeb14668c..0000000000
--- a/plugins/Dropbox/res/version.rc
+++ /dev/null
@@ -1,55 +0,0 @@
-// Microsoft Visual C++ generated resource script.
-//
-#ifdef APSTUDIO_INVOKED
-#error this file is not editable by Microsoft Visual C++
-#endif //APSTUDIO_INVOKED
-
-#include "..\src\version.h"
-
-#define APSTUDIO_READONLY_SYMBOLS
-#include "afxres.h"
-#undef APSTUDIO_READONLY_SYMBOLS
-
-/////////////////////////////////////////////////////////////////////////////
-// English (U.S.) resources
-
-#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
-#ifdef _WIN32
-LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
-#pragma code_page(1252)
-#endif //_WIN32
-
-VS_VERSION_INFO VERSIONINFO
- FILEVERSION __FILEVERSION_STRING
- PRODUCTVERSION __FILEVERSION_STRING
- FILEFLAGSMASK 0x17L
-#ifdef _DEBUG
- FILEFLAGS 0x1L
-#else
- FILEFLAGS 0x0L
-#endif
- FILEOS 0x4L
- FILETYPE 0x2L
- FILESUBTYPE 0x0L
-BEGIN
- BLOCK "StringFileInfo"
- BEGIN
- BLOCK "000004b0"
- BEGIN
- VALUE "Author", __AUTHOR
- VALUE "FileDescription", __DESCRIPTION
- VALUE "FileVersion", __VERSION_STRING
- VALUE "InternalName", __PLUGIN_NAME
- VALUE "LegalCopyright", __COPYRIGHT
- VALUE "OriginalFilename", __FILENAME
- VALUE "ProductName", __PLUGIN_NAME
- END
- END
- BLOCK "VarFileInfo"
- BEGIN
- VALUE "Translation", 0x0, 1200
- END
-END
-
-#endif // English (U.S.) resources
-/////////////////////////////////////////////////////////////////////////////
diff --git a/plugins/Dropbox/src/api/account.h b/plugins/Dropbox/src/api/account.h
deleted file mode 100644
index 6943bd29c3..0000000000
--- a/plugins/Dropbox/src/api/account.h
+++ /dev/null
@@ -1,38 +0,0 @@
-#ifndef _DROPBOX_API_ACCOUNT_H_
-#define _DROPBOX_API_ACCOUNT_H_
-
-class GetAccessTokenRequest : public HttpRequest
-{
-public:
- GetAccessTokenRequest(const char *requestToken) :
- HttpRequest(REQUEST_POST, DROPBOX_API "/oauth2/token")
- {
- AddHeader("Content-Type", "application/x-www-form-urlencoded");
-
- CMStringA data(CMStringDataFormat::FORMAT,
- "client_id=%s&client_secret=%s&grant_type=authorization_code&code=%s",
- DROPBOX_APP_KEY, DROPBOX_API_SECRET, requestToken);
- SetData(data.GetBuffer(), data.GetLength());
- }
-};
-
-class RevokeAccessTokenRequest : public HttpRequest
-{
-public:
- RevokeAccessTokenRequest() :
- HttpRequest(REQUEST_POST, DROPBOX_API "/oauth2/token/revoke")
- {
- }
-};
-
-class GetCurrentAccountRequest : public HttpRequest
-{
-public:
- GetCurrentAccountRequest(const char *token) :
- HttpRequest(REQUEST_POST, DROPBOX_API_RPC "/users/get_current_account")
- {
- AddBearerAuthHeader(token);
- }
-};
-
-#endif //_DROPBOX_API_ACCOUNT_H_
diff --git a/plugins/Dropbox/src/api/operations.h b/plugins/Dropbox/src/api/operations.h
deleted file mode 100644
index d97dec731e..0000000000
--- a/plugins/Dropbox/src/api/operations.h
+++ /dev/null
@@ -1,143 +0,0 @@
-#ifndef _DROPBOX_API_OPERATIONS_H_
-#define _DROPBOX_API_OPERATIONS_H_
-
-class GetTemporaryLinkRequest : public HttpRequest
-{
-public:
- GetTemporaryLinkRequest(const char *token, const char *path) :
- HttpRequest(REQUEST_POST, DROPBOX_API_RPC "/files/get_temporary_link")
- {
- AddBearerAuthHeader(token);
- AddHeader("Content-Type", "application/json");
-
- JSONNode root(JSON_NODE);
- root << JSONNode("path", path);
-
- json_string data = root.write();
- SetData(data.c_str(), data.length());
- }
-};
-
-class CreateSharedLinkRequest : public HttpRequest
-{
-public:
- CreateSharedLinkRequest(const char *token, const char *path) :
- HttpRequest(REQUEST_POST, DROPBOX_API_RPC "/sharing/create_shared_link_with_settings")
- {
- AddBearerAuthHeader(token);
- AddHeader("Content-Type", "application/json");
-
- JSONNode root(JSON_NODE);
- root << JSONNode("path", path);
-
- json_string data = root.write();
- SetData(data.c_str(), data.length());
- }
-};
-
-class GetSharedLinkRequest : public HttpRequest
-{
-public:
- GetSharedLinkRequest(const char *token, const char *path) :
- HttpRequest(REQUEST_POST, DROPBOX_API_RPC "/sharing/list_shared_links")
- {
- AddBearerAuthHeader(token);
- AddHeader("Content-Type", "application/json");
-
- JSONNode root(JSON_NODE);
- root << JSONNode("path", path);
-
- json_string data = root.write();
- SetData(data.c_str(), data.length());
- }
-};
-
-class SearchRequest : public HttpRequest
-{
-public:
- SearchRequest(const char *token, const char *query) :
- HttpRequest(REQUEST_POST, DROPBOX_API_RPC "/files/search")
- {
- AddBearerAuthHeader(token);
- AddHeader("Content-Type", "application/json");
-
- JSONNode params(JSON_NODE);
- params
- << JSONNode("path", "")
- << JSONNode("query", query)
- << JSONNode("max_results", 10);
-
- json_string data = params.write();
- SetData(data.c_str(), data.length());
- }
-};
-
-class DeleteRequest : public HttpRequest
-{
-public:
- DeleteRequest(const char *token, const char *path) :
- HttpRequest(REQUEST_POST, DROPBOX_API_RPC "/files/delete")
- {
- AddBearerAuthHeader(token);
- AddHeader("Content-Type", "application/json");
-
- JSONNode root(JSON_NODE);
- root << JSONNode("path", path);
-
- json_string data = root.write();
- SetData(data.c_str(), data.length());
- }
-};
-
-class CreateFolderRequest : public HttpRequest
-{
-public:
- CreateFolderRequest(const char *token, const char *path) :
- HttpRequest(REQUEST_POST, DROPBOX_API_RPC "/files/create_folder")
- {
- AddBearerAuthHeader(token);
- AddHeader("Content-Type", "application/json");
-
- JSONNode root(JSON_NODE);
- root << JSONNode("path", path);
-
- json_string data = root.write();
- SetData(data.c_str(), data.length());
- }
-};
-
-class GetMetadataRequest : public HttpRequest
-{
-public:
- GetMetadataRequest(const char *token, const char *path) :
- HttpRequest(REQUEST_POST, DROPBOX_API_RPC "/files/get_metadata")
- {
- AddBearerAuthHeader(token);
- AddHeader("Content-Type", "application/json");
-
- JSONNode root(JSON_NODE);
- root << JSONNode("path", path);
-
- json_string data = root.write();
- SetData(data.c_str(), data.length());
- }
-};
-
-class ListFolderRequest : public HttpRequest
-{
-public:
- ListFolderRequest(const char *token, const char *path) :
- HttpRequest(REQUEST_POST, DROPBOX_API_RPC "/files/list_folder")
- {
- AddBearerAuthHeader(token);
- AddHeader("Content-Type", "application/json");
-
- JSONNode root(JSON_NODE);
- root << JSONNode("path", path);
-
- json_string data = root.write();
- SetData(data.c_str(), data.length());
- }
-};
-
-#endif //_DROPBOX_API_OPERATIONS_H_
diff --git a/plugins/Dropbox/src/api/upload.h b/plugins/Dropbox/src/api/upload.h
deleted file mode 100644
index 98841e9b98..0000000000
--- a/plugins/Dropbox/src/api/upload.h
+++ /dev/null
@@ -1,94 +0,0 @@
-#ifndef _DROPBOX_API_UPLOAD_H_
-#define _DROPBOX_API_UPLOAD_H_
-
-class UploadFileRequest : public HttpRequest
-{
-public:
- UploadFileRequest(const char *token, const char *path, const char *data, size_t size) :
- HttpRequest(REQUEST_POST, DROPBOX_API_CU "/files/upload")
- {
- AddBearerAuthHeader(token);
- AddHeader("Content-Type", "application/octet-stream");
-
- JSONNode params(JSON_NODE);
- params
- << JSONNode("path", path)
- << JSONNode("mode", "overwrite");
-
- AddHeader("Dropbox-API-Arg", params.write().c_str());
-
- SetData(data, size);
- }
-};
-
-class StartUploadSessionRequest : public HttpRequest
-{
-public:
- StartUploadSessionRequest(const char *token, const char *data, size_t size) :
- HttpRequest(REQUEST_POST, DROPBOX_API_CU "/files/upload_session/start")
- {
- AddBearerAuthHeader(token);
- AddHeader("Content-Type", "application/octet-stream");
-
- SetData(data, size);
- }
-};
-
-class AppendToUploadSessionRequest : public HttpRequest
-{
-public:
- AppendToUploadSessionRequest(const char *token, const char *sessionId, size_t offset, const char *data, size_t size) :
- HttpRequest(REQUEST_POST, DROPBOX_API_CU "/files/upload_session/append_v2")
- {
- AddBearerAuthHeader(token);
- AddHeader("Content-Type", "application/octet-stream");
-
-
- JSONNode cursor;
- cursor.set_name("cursor");
- cursor
- << JSONNode("session_id", sessionId)
- << JSONNode("offset", (unsigned long)offset);
-
- JSONNode param;
- param << cursor;
-
- AddHeader("Dropbox-API-Arg", param.write().c_str());
-
- SetData(data, size);
- }
-};
-
-class FinishUploadSessionRequest : public HttpRequest
-{
-public:
- FinishUploadSessionRequest(const char *token, const char *sessionId, size_t offset, const char *path, const char *data, size_t size) :
- HttpRequest(REQUEST_POST, DROPBOX_API_CU "/files/upload_session/finish")
- {
- AddBearerAuthHeader(token);
- AddHeader("Content-Type", "application/octet-stream");
-
- JSONNode cursor(JSON_NODE);
- cursor.set_name("cursor");
- cursor
- << JSONNode("session_id", sessionId)
- << JSONNode("offset", (unsigned long)offset);
-
- JSONNode commit(JSON_NODE);
- commit.set_name("commit");
- commit
- << JSONNode("path", path)
- << JSONNode("mode", "overwrite");
-
- JSONNode params(JSON_NODE);
- params
- << cursor
- << commit;
-
- AddHeader("Dropbox-API-Arg", params.write().c_str());
-
- SetData(data, size);
- }
-};
-
-#endif //_DROPBOX_API_UPLOAD_H_
diff --git a/plugins/Dropbox/src/dropbox.cpp b/plugins/Dropbox/src/dropbox.cpp
deleted file mode 100644
index e19cd22b9c..0000000000
--- a/plugins/Dropbox/src/dropbox.cpp
+++ /dev/null
@@ -1,219 +0,0 @@
-#include "stdafx.h"
-
-CDropbox::CDropbox() : transfers(1, HandleKeySortT)
-{
- HookEvent(ME_PROTO_ACK, OnProtoAck);
- HookEventObj(ME_SYSTEM_MODULESLOADED, GlobalEvent<&CDropbox::OnModulesLoaded>, this);
-
- hUploadedEventHook = CreateHookableEvent(ME_DROPBOX_UPLOADED);
-
- CreateServiceFunctionObj(MS_DROPBOX_UPLOAD, GlobalService<&CDropbox::UploadToDropbox>, this);
- CreateServiceFunctionObj(MS_DROPBOX_UPLOADASYNC, GlobalService<&CDropbox::UploadToDropboxAsync>, this);
-
- PROTOCOLDESCRIPTOR pd = { 0 };
- pd.cbSize = sizeof(pd);
- pd.szName = MODULE;
- pd.type = PROTOTYPE_VIRTUAL;
- Proto_RegisterModule(&pd);
-
- CreateServiceFunction(MODULE PS_GETCAPS, ProtoGetCaps);
- CreateServiceFunction(MODULE PS_GETNAME, ProtoGetName);
- CreateServiceFunction(MODULE PS_LOADICON, ProtoLoadIcon);
- CreateServiceFunctionObj(MODULE PS_GETSTATUS, GlobalService<&CDropbox::ProtoGetStatus>, this);
- CreateServiceFunctionObj(MODULE PSS_FILE, GlobalService<&CDropbox::ProtoSendFile>, this);
- CreateServiceFunctionObj(MODULE PSS_FILECANCEL, GlobalService<&CDropbox::ProtoCancelFile>, this);
- CreateServiceFunctionObj(MODULE PSS_MESSAGE, GlobalService<&CDropbox::ProtoSendMessage>, this);
- CreateServiceFunction(MODULE PSR_MESSAGE, ProtoReceiveMessage);
-
- pd.szName = MODULE"Inteceptor";
- pd.type = PROTOTYPE_FILTER;
- Proto_RegisterModule(&pd);
-
- CreateServiceFunctionObj(MODULE "Inteceptor" PSS_FILE, GlobalService<&CDropbox::ProtoSendFileInterceptor>, this);
-
- InitializeMenus();
-
- hMessageProcess = 1;
-}
-
-CDropbox::~CDropbox()
-{
- DestroyHookableEvent(hUploadedEventHook);
-}
-
-MCONTACT CDropbox::GetDefaultContact()
-{
- if (!hDefaultContact)
- hDefaultContact = db_find_first(MODULE);
-
- if (!hDefaultContact) {
- hDefaultContact = db_add_contact();
- if (!Proto_AddToContact(hDefaultContact, MODULE)) {
- db_set_s(NULL, MODULE, "Nick", MODULE);
- db_set_s(hDefaultContact, MODULE, "Nick", MODULE);
- db_set_ws(hDefaultContact, "CList", "MyHandle", L"Dropbox");
- }
- db_set_w(hDefaultContact, MODULE, "Status", HasAccessToken() ? ID_STATUS_ONLINE : ID_STATUS_OFFLINE);
- }
-
- return hDefaultContact;
-}
-
-bool CDropbox::HasAccessToken()
-{
- ptrA token(db_get_sa(NULL, MODULE, "TokenSecret"));
- return token != NULL;
-}
-
-void CDropbox::RequestAccountInfo(void *p)
-{
- CDropbox *instance = (CDropbox*)p;
-
- MCONTACT hContact = instance->GetDefaultContact();
-
- ptrA token(db_get_sa(NULL, MODULE, "TokenSecret"));
- GetCurrentAccountRequest request(token);
- NLHR_PTR response(request.Send(instance->hNetlibConnection));
-
- try
- {
- HandleHttpResponse(response);
- }
- catch (DropboxException &ex)
- {
- Netlib_Logf(instance->hNetlibConnection, "%s: %s", MODULE, ex.what());
- return;
- }
-
- JSONNode root = JSONNode::parse(response->pData);
- if (root.empty())
- return;
-
- JSONNode referral_link = root.at("referral_link");
- if (!referral_link.empty())
- db_set_s(hContact, MODULE, "Homepage", referral_link.as_string().c_str());
-
- JSONNode email = root.at("email");
- if (!email.empty())
- db_set_s(hContact, MODULE, "e-mail", email.as_string().c_str());
-
- JSONNode name = root.at("name");
- if (!name.empty()) {
- db_set_utf(hContact, MODULE, "FirstName", name.at("given_name").as_string().c_str());
- db_set_utf(hContact, MODULE, "LastName", name.at("surname").as_string().c_str());
- }
-
- JSONNode country = root.at("country");
- if (!country.empty()) {
- std::string isocode = country.as_string();
-
- if (isocode.empty())
- db_unset(hContact, MODULE, "Country");
- else {
- char *szCountry = (char *)CallService(MS_UTILS_GETCOUNTRYBYISOCODE, (WPARAM)isocode.c_str(), 0);
- db_set_s(hContact, MODULE, "Country", szCountry);
- }
- }
-
- /*JSONNode quota_info = root.at("quota_info");
- if (!quota_info.empty()) {
- ULONG lTotalQuota = quota_info.at("quota").as_int();
- ULONG lNormalQuota = quota_info.at("normal").as_int();
- ULONG lSharedQuota = quota_info.at("shared").as_int();
-
- db_set_dw(hContact, MODULE, "SharedQuota", lSharedQuota);
- db_set_dw(hContact, MODULE, "NormalQuota", lNormalQuota);
- db_set_dw(hContact, MODULE, "TotalQuota", lTotalQuota);
-
- db_set_s(hContact, "CList", "StatusMsg", CMStringA(FORMAT, Translate("Free %ld of %ld MB"), (lTotalQuota - lNormalQuota) / (1024 * 1024), lTotalQuota / (1024 * 1024)));
- }*/
-}
-
-void CDropbox::DestroyAccessToken()
-{
- RevokeAccessTokenRequest request;
- NLHR_PTR response(request.Send(hNetlibConnection));
-
- db_unset(NULL, MODULE, "TokenSecret");
- MCONTACT hContact = CDropbox::GetDefaultContact();
- if (hContact)
- if (db_get_w(hContact, MODULE, "Status", ID_STATUS_ONLINE) != ID_STATUS_OFFLINE)
- db_set_w(hContact, MODULE, "Status", ID_STATUS_OFFLINE);
-
- ProtoBroadcastAck(MODULE, NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)ID_STATUS_ONLINE, (WPARAM)ID_STATUS_OFFLINE);
-}
-
-UINT CDropbox::RequestAccessTokenAsync(void *owner, void *param)
-{
- HWND hwndDlg = (HWND)param;
- CDropbox *instance = (CDropbox*)owner;
-
- EnableWindow(GetDlgItem(hwndDlg, IDC_AUTHORIZE), FALSE);
- SetDlgItemText(hwndDlg, IDC_AUTH_STATUS, TranslateT("in process..."));
-
- if (instance->HasAccessToken())
- instance->DestroyAccessToken();
-
- char requestToken[128];
- GetDlgItemTextA(hwndDlg, IDC_REQUEST_CODE, requestToken, _countof(requestToken));
-
- GetAccessTokenRequest request(requestToken);
- NLHR_PTR response(request.Send(instance->hNetlibConnection));
-
- if (response == nullptr || response->resultCode != HTTP_STATUS_OK) {
- Netlib_Logf(instance->hNetlibConnection, "%s: %s", MODULE, HttpStatusToText(HTTP_STATUS_ERROR));
- if (hwndDlg)
- SetDlgItemText(hwndDlg, IDC_AUTH_STATUS, TranslateT("server does not respond"));
- /*else
- ShowNotification(TranslateT("server does not respond"), MB_ICONERROR);*/
- return 0;
- }
-
- JSONNode root = JSONNode::parse(response->pData);
- if (root.empty()) {
- Netlib_Logf(instance->hNetlibConnection, "%s: %s", MODULE, HttpStatusToText((HTTP_STATUS)response->resultCode));
- if (hwndDlg)
- SetDlgItemText(hwndDlg, IDC_AUTH_STATUS, TranslateT("server does not respond"));
- /*else
- ShowNotification((wchar_t*)error_description, MB_ICONERROR);*/
- return 0;
- }
-
- JSONNode node = root.at("error_description");
- if (node != JSONNULL) {
- ptrW error_description(mir_a2u_cp(node.as_string().c_str(), CP_UTF8));
- Netlib_Logf(instance->hNetlibConnection, "%s: %s", MODULE, HttpStatusToText((HTTP_STATUS)response->resultCode));
- if (hwndDlg)
- SetDlgItemText(hwndDlg, IDC_AUTH_STATUS, error_description);
- /*else
- ShowNotification((wchar_t*)error_description, MB_ICONERROR);*/
- return 0;
- }
-
- node = root.at("access_token");
- db_set_s(NULL, MODULE, "TokenSecret", node.as_string().c_str());
- ProtoBroadcastAck(MODULE, NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)ID_STATUS_OFFLINE, (WPARAM)ID_STATUS_ONLINE);
-
- MCONTACT hContact = instance->GetDefaultContact();
- if (hContact) {
- if (db_get_w(hContact, MODULE, "Status", ID_STATUS_OFFLINE) != ID_STATUS_ONLINE)
- db_set_w(hContact, MODULE, "Status", ID_STATUS_ONLINE);
- }
-
- try {
- RequestAccountInfo(instance);
- }
- catch (DropboxException &ex) {
- Netlib_Logf(instance->hNetlibConnection, "%s: %s", MODULE, ex.what());
- return 0;
- }
-
- if (hwndDlg)
- SetDlgItemText(hwndDlg, IDC_AUTH_STATUS, TranslateT("you have been authorized"));
- /*else
- ShowNotification(TranslateT("you have been authorized"), MB_ICONINFORMATION);*/
-
- SetDlgItemTextA(hwndDlg, IDC_REQUEST_CODE, "");
-
- return 0;
-}
diff --git a/plugins/Dropbox/src/dropbox.h b/plugins/Dropbox/src/dropbox.h
deleted file mode 100644
index f9957cc5b3..0000000000
--- a/plugins/Dropbox/src/dropbox.h
+++ /dev/null
@@ -1,142 +0,0 @@
-#ifndef _DROPBOX_PROTO_H_
-#define _DROPBOX_PROTO_H_
-
-enum
-{
- CMI_SEND_FILES,
- CMI_MAX // this item shall be the last one
-};
-
-#define JSONNULL JSONNode(JSON_NULL)
-
-class CDropbox : public MZeroedObject
-{
- friend CDropboxOptionsMain;
-
- struct CommandParam
- {
- CDropbox *instance;
- HANDLE hProcess;
- MCONTACT hContact;
- void *data;
- };
-
-public:
- CDropbox();
- virtual ~CDropbox();
-
-private:
- HNETLIBUSER hNetlibConnection;
- ULONG hMessageProcess;
-
- HANDLE hUploadedEventHook;
-
- MCONTACT hDefaultContact;
-
- HGENMENU contactMenuItems[CMI_MAX];
-
- std::map<MCONTACT, HWND> interceptedContacts;
-
- LIST<FileTransferParam> transfers;
-
- // hooks
- static int OnProtoAck(WPARAM wParam, LPARAM lParam);
- int OnToolbarLoaded(WPARAM wParam, LPARAM lParam);
- int OnModulesLoaded(WPARAM wParam, LPARAM lParam);
- int OnContactDeleted(WPARAM wParam, LPARAM lParam);
- int OnOptionsInitialized(WPARAM wParam, LPARAM lParam);
- int OnPrebuildContactMenu(WPARAM wParam, LPARAM lParam);
- int OnSrmmWindowOpened(WPARAM wParam, LPARAM lParam);
- int OnTabSrmmButtonPressed(WPARAM wParam, LPARAM lParam);
- int OnFileDialogCancelled(WPARAM wParam, LPARAM lParam);
-
- // services
- static INT_PTR ProtoGetCaps(WPARAM wParam, LPARAM lParam);
- static INT_PTR ProtoGetName(WPARAM wParam, LPARAM lParam);
- static INT_PTR ProtoLoadIcon(WPARAM wParam, LPARAM lParam);
- INT_PTR ProtoGetStatus(WPARAM wParam, LPARAM lParam);
- INT_PTR ProtoSendFile(WPARAM wParam, LPARAM lParam);
- INT_PTR ProtoCancelFile(WPARAM wParam, LPARAM lParam);
- INT_PTR ProtoSendMessage(WPARAM wParam, LPARAM lParam);
- static INT_PTR ProtoReceiveMessage(WPARAM wParam, LPARAM lParam);
-
- INT_PTR ProtoSendFileInterceptor(WPARAM wParam, LPARAM lParam);
-
- INT_PTR UploadToDropbox(WPARAM wParam, LPARAM lParam);
- INT_PTR UploadToDropboxAsync(WPARAM wParam, LPARAM lParam);
-
- // commands
- static void CommandHelp(void *arg);
- static void CommandList(void *arg);
- static void CommandShare(void *arg);
- static void CommandSearch(void *arg);
- static void CommandDelete(void *arg);
-
- // access token
- bool HasAccessToken();
-
- void RequestAccessToken();
- void DestroyAccessToken();
-
- static UINT RequestAccessTokenAsync(void *owner, void *param);
-
- // account info
- static void __cdecl RequestAccountInfo(void*);
-
- // transfers
- char* UploadFile(const char *data, size_t size, char *path);
- void StartUploadSession(const char *data, size_t size, char *sessionId);
- void AppendToUploadSession(const char *data, size_t size, const char *sessionId, size_t offset);
- char* FinishUploadSession(const char *data, size_t size, const char *sessionId, size_t offset, char *path);
-
- void CreateFolder(const char *path);
-
- void CreateDownloadUrl(const char *path, char *url);
-
- static UINT UploadToDropbox(void *owner, void *arg);
-
- static UINT UploadAndRaiseEvent(void *owner, void *arg);
- static UINT UploadAndReportProgress(void *owner, void *arg);
-
- // contacts
- MCONTACT GetDefaultContact();
-
- // menus
- void InitializeMenus();
- static void Menu_DisableItem(HGENMENU hMenuItem, BOOL bDisable);
-
- static INT_PTR SendFilesToDropboxCommand(void *obj, WPARAM wParam, LPARAM lParam);
-
- // utils
- static char* PreparePath(const char *oldPath, char *newPath);
- static char* PreparePath(const wchar_t *oldPath, char *newPath);
-
- static bool IsAccountIntercepted(const char *module);
-
- static char* HttpStatusToText(HTTP_STATUS status);
- static void HandleHttpResponse(NETLIBHTTPREQUEST *response);
- static JSONNode HandleJsonResponse(NETLIBHTTPREQUEST *response);
-
- static MEVENT AddEventToDb(MCONTACT hContact, WORD type, DWORD flags, DWORD cbBlob, PBYTE pBlob);
-
- void SendToContact(MCONTACT hContact, const wchar_t *data);
- void PasteToInputArea(MCONTACT hContact, const wchar_t *data);
- void PasteToClipboard(const wchar_t *data);
- void Report(MCONTACT hContact, const wchar_t *data);
-
- template<int(CDropbox::*Event)(WPARAM, LPARAM)>
- static int GlobalEvent(void *obj, WPARAM wParam, LPARAM lParam)
- {
- CDropbox *instance = (CDropbox*)obj;
- return instance ? (instance->*Event)(wParam, lParam) : 0;
- }
-
- template<INT_PTR(CDropbox::*Service)(WPARAM, LPARAM)>
- static INT_PTR GlobalService(void *obj, WPARAM wParam, LPARAM lParam)
- {
- CDropbox *instance = (CDropbox*)obj;
- return instance ? (instance->*Service)(wParam, lParam) : 0;
- }
-};
-
-#endif //_DROPBOX_PROTO_H_ \ No newline at end of file
diff --git a/plugins/Dropbox/src/dropbox_commands.cpp b/plugins/Dropbox/src/dropbox_commands.cpp
deleted file mode 100644
index 0d6c5e4391..0000000000
--- a/plugins/Dropbox/src/dropbox_commands.cpp
+++ /dev/null
@@ -1,176 +0,0 @@
-#include "stdafx.h"
-
-void CDropbox::CommandHelp(void *arg)
-{
- CommandParam *param = (CommandParam*)arg;
-
- CMStringA help = (char*)T2Utf(TranslateT("Dropbox supports the following commands:"));
- help += "\n";
- help += "\"/list [path]\" \t- "; help += T2Utf(TranslateT("shows all files in folder \"path\" (\"path\" is relative from root and can be omitted for root folder)"));
- help += "\n";
- help += "\"/share <path>\" \t- "; help += T2Utf(TranslateT("returns download link for file or folder with specified path (\"path\" is relative from root folder)"));
- help += "\n";
- help += "\"/search <query>\" \t- "; help += T2Utf(TranslateT("searches for file or folder matched by query (\"query\" is split on spaces into multiple tokens)"));
- help += "\n";
- help += "\"/delete <path>\" \t- "; help += T2Utf(TranslateT("deletes file or folder with specified path (\"path\" is relative from root folder)"));
-
- ProtoBroadcastAck(MODULE, param->hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, param->hProcess, 0);
- ProtoChainSend(param->instance->GetDefaultContact(), PSR_MESSAGE, 0, (LPARAM)help.GetBuffer());
-}
-
-void CDropbox::CommandList(void *arg)
-{
- CommandParam *param = (CommandParam*)arg;
-
- char path[MAX_PATH];
- PreparePath((char*)param->data, path);
- if (path[0] == NULL) {
- CMStringA error(FORMAT, T2Utf(TranslateT("\"%s\" command has invalid parameter.\nUse \"/help\" for more info.")), "/list");
- ProtoBroadcastAck(MODULE, param->hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, param->hProcess, 0);
- ProtoChainSend(param->instance->GetDefaultContact(), PSR_MESSAGE, 0, (LPARAM)error.GetBuffer());
- return;
- }
-
- ptrA token(db_get_sa(NULL, MODULE, "TokenSecret"));
- ListFolderRequest request(token, path);
- NLHR_PTR response(request.Send(param->instance->hNetlibConnection));
-
- if (response == nullptr || response->resultCode != HTTP_STATUS_OK) {
- ProtoBroadcastAck(MODULE, param->hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, param->hProcess, 0);
- return;
- }
-
- JSONNode root = JSONNode::parse(response->pData);
- if (root.empty()) {
- ProtoBroadcastAck(MODULE, param->hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, param->hProcess, 0);
- return;
- }
-
- CMStringA message;
- JSONNode entries = root.at("entries").as_array();
- if (entries.empty())
- message.AppendFormat("\"%s\" %s", path, T2Utf(TranslateT("is empty")));
- else
- {
- for (size_t i = 0; i < entries.size(); i++) {
- JSONNode entry = entries[i];
- CMStringA subName(entry.at("path_lower").as_string().c_str());
- message.Append((subName[0] == '/') ? subName.Mid(1) : subName);
- message.AppendChar('\n');
- }
- }
-
- ProtoBroadcastAck(MODULE, param->hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, param->hProcess, 0);
- ProtoChainSend(param->instance->GetDefaultContact(), PSR_MESSAGE, 0, (LPARAM)message.GetBuffer());
-}
-
-void CDropbox::CommandShare(void *arg)
-{
- CommandParam *param = (CommandParam*)arg;
-
- char path[MAX_PATH];
- PreparePath((char*)param->data, path);
- if (path[0] == NULL) {
- CMStringA error(FORMAT, T2Utf(TranslateT("\"%s\" command has invalid parameter.\nUse \"/help\" for more info.")), "/share");
- ProtoBroadcastAck(MODULE, param->hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, param->hProcess, 0);
- ProtoChainSend(param->instance->GetDefaultContact(), PSR_MESSAGE, 0, (LPARAM)error.GetBuffer());
- return;
- }
-
- ptrA token(db_get_sa(NULL, MODULE, "TokenSecret"));
- GetTemporaryLinkRequest request(token, path);
- NLHR_PTR response(request.Send(param->instance->hNetlibConnection));
-
- if (response == nullptr || response->resultCode != HTTP_STATUS_OK) {
- ProtoBroadcastAck(MODULE, param->hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, param->hProcess, 0);
- return;
- }
-
- JSONNode root = JSONNode::parse(response->pData);
- if (root.empty()) {
- ProtoBroadcastAck(MODULE, param->hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, param->hProcess, 0);
- return;
- }
-
- CMStringA link = root.at("link").as_string().c_str();
- ProtoBroadcastAck(MODULE, param->hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, param->hProcess, 0);
- ProtoChainSend(param->instance->GetDefaultContact(), PSR_MESSAGE, 0, (LPARAM)link.GetBuffer());
-}
-
-void CDropbox::CommandSearch(void *arg)
-{
- CommandParam *param = (CommandParam*)arg;
-
- char *query = (char*)param->data;
- if (query == nullptr) {
- CMStringA error(FORMAT, T2Utf(TranslateT("\"%s\" command has invalid parameter.\nUse \"/help\" for more info.")), "/search");
- ProtoBroadcastAck(MODULE, param->hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, param->hProcess, 0);
- ProtoChainSend(param->instance->GetDefaultContact(), PSR_MESSAGE, 0, (LPARAM)error.GetBuffer());
- return;
- }
-
- ptrA token(db_get_sa(NULL, MODULE, "TokenSecret"));
- //bool useShortUrl = db_get_b(NULL, MODULE, "UseSortLinks", 1) > 0;
- SearchRequest request(token, query);
- NLHR_PTR response(request.Send(param->instance->hNetlibConnection));
-
- if (response == nullptr || response->resultCode != HTTP_STATUS_OK) {
- ProtoBroadcastAck(MODULE, param->hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, param->hProcess, 0);
- return;
- }
-
- JSONNode root = JSONNode::parse(response->pData);
- if (root.empty()) {
- ProtoBroadcastAck(MODULE, param->hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, param->hProcess, 0);
- return;
- }
-
- CMStringA message;
- JSONNode matches = root.at("matches").as_array();
- if (matches.empty())
- message.AppendFormat("\"%s\" %s", query, T2Utf(TranslateT("is not found")));
- else
- {
- for (size_t i = 0; i < matches.size(); i++) {
- JSONNode metadata = matches[i].at("metadata").as_node();
- message.AppendFormat("%s\n", metadata.at("path_lower").as_string().c_str());
- }
- }
-
- ProtoBroadcastAck(MODULE, param->hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, param->hProcess, 0);
- ProtoChainSend(param->instance->GetDefaultContact(), PSR_MESSAGE, 0, (LPARAM)message.GetBuffer());
-}
-
-void CDropbox::CommandDelete(void *arg)
-{
- CommandParam *param = (CommandParam*)arg;
-
- char path[MAX_PATH];
- PreparePath((char*)param->data, path);
- if (path[0] == NULL) {
- CMStringA error(FORMAT, T2Utf(TranslateT("\"%s\" command has invalid parameter.\nUse \"/help\" for more info.")), "/delete");
- ProtoBroadcastAck(MODULE, param->hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, param->hProcess, 0);
- ProtoChainSend(param->instance->GetDefaultContact(), PSR_MESSAGE, 0, (LPARAM)error.GetBuffer());
- return;
- }
-
- ptrA token(db_get_sa(NULL, MODULE, "TokenSecret"));
- DeleteRequest request(token, path);
- NLHR_PTR response(request.Send(param->instance->hNetlibConnection));
-
- try
- {
- HandleJsonResponse(response);
-
- CMStringA message(FORMAT, "%s %s", path, T2Utf(TranslateT("is deleted")));
- ProtoBroadcastAck(MODULE, param->hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, param->hProcess, 0);
- ProtoChainSend(param->instance->GetDefaultContact(), PSR_MESSAGE, 0, (LPARAM)message.GetBuffer());
- }
- catch (DropboxException &ex)
- {
- ProtoBroadcastAck(MODULE, param->hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, param->hProcess, (LPARAM)ex.what());
- return;
- }
-
- ProtoBroadcastAck(MODULE, param->hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, param->hProcess, 0);
-}
diff --git a/plugins/Dropbox/src/dropbox_events.cpp b/plugins/Dropbox/src/dropbox_events.cpp
deleted file mode 100644
index f06b4514e3..0000000000
--- a/plugins/Dropbox/src/dropbox_events.cpp
+++ /dev/null
@@ -1,129 +0,0 @@
-#include "stdafx.h"
-
-int CDropbox::OnToolbarLoaded(WPARAM, LPARAM)
-{
- BBButton bbd = {};
- bbd.pszModuleName = MODULE;
- bbd.bbbFlags = BBBF_ISIMBUTTON | BBBF_ISCHATBUTTON | BBBF_ISRSIDEBUTTON;
- bbd.pwszTooltip = TranslateT("Upload files to Dropbox");
- bbd.hIcon = GetIconHandleByName("upload");
- bbd.dwButtonID = BBB_ID_FILE_SEND;
- bbd.dwDefPos = 100 + bbd.dwButtonID;
- Srmm_AddButton(&bbd);
- return 0;
-}
-
-int CDropbox::OnModulesLoaded(WPARAM, LPARAM)
-{
- HookEventObj(ME_DB_CONTACT_DELETED, GlobalEvent<&CDropbox::OnContactDeleted>, this);
- HookEventObj(ME_OPT_INITIALISE, GlobalEvent<&CDropbox::OnOptionsInitialized>, this);
- HookEventObj(ME_CLIST_PREBUILDCONTACTMENU, GlobalEvent<&CDropbox::OnPrebuildContactMenu>, this);
- HookEventObj(ME_MSG_TOOLBARLOADED, GlobalEvent<&CDropbox::OnToolbarLoaded>, this);
-
- HookEventObj(ME_MSG_WINDOWEVENT, GlobalEvent<&CDropbox::OnSrmmWindowOpened>, this);
- HookEventObj(ME_FILEDLG_CANCELED, GlobalEvent<&CDropbox::OnFileDialogCancelled>, this);
-
- NETLIBUSER nlu = {};
- nlu.flags = NUF_INCOMING | NUF_OUTGOING | NUF_HTTPCONNS | NUF_UNICODE;
- nlu.szSettingsModule = MODULE;
- nlu.szDescriptiveName.w = L"Dropbox";
- hNetlibConnection = Netlib_RegisterUser(&nlu);
-
- GetDefaultContact();
-
- WORD status = ProtoGetStatus(0, 0);
- ProtoBroadcastAck(MODULE, NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)ID_STATUS_OFFLINE, status);
-
- HookEventObj(ME_MSG_BUTTONPRESSED, GlobalEvent<&CDropbox::OnTabSrmmButtonPressed>, this);
- return 0;
-}
-
-int CDropbox::OnContactDeleted(WPARAM hContact, LPARAM)
-{
- if (mir_strcmpi(GetContactProto(hContact), MODULE) == 0) {
- if (HasAccessToken())
- DestroyAccessToken();
- hDefaultContact = NULL;
- }
- return 0;
-}
-
-int CDropbox::OnSrmmWindowOpened(WPARAM, LPARAM lParam)
-{
- MessageWindowEventData *ev = (MessageWindowEventData*)lParam;
- if (ev->uType == MSG_WINDOW_EVT_OPENING && ev->hContact) {
- char *proto = GetContactProto(ev->hContact);
- bool isProtoOnline = CallProtoService(proto, PS_GETSTATUS, 0, 0) > ID_STATUS_OFFLINE;
- WORD status = db_get_w(ev->hContact, proto, "Status", ID_STATUS_OFFLINE);
- bool canSendOffline = (CallProtoService(proto, PS_GETCAPS, PFLAGNUM_4, 0) & PF4_IMSENDOFFLINE) > 0;
-
- BBButton bbd = {};
- bbd.pszModuleName = MODULE;
- bbd.dwButtonID = BBB_ID_FILE_SEND;
- bbd.bbbFlags = BBSF_RELEASED;
- if (!HasAccessToken() || ev->hContact == GetDefaultContact() || IsAccountIntercepted(proto))
- bbd.bbbFlags = BBSF_HIDDEN | BBSF_DISABLED;
- else if (!isProtoOnline || (status == ID_STATUS_OFFLINE && !canSendOffline))
- bbd.bbbFlags = BBSF_DISABLED;
-
- Srmm_SetButtonState(ev->hContact, &bbd);
- }
-
- return 0;
-}
-
-int CDropbox::OnTabSrmmButtonPressed(WPARAM, LPARAM lParam)
-{
- CustomButtonClickData *cbc = (CustomButtonClickData *)lParam;
- if (!mir_strcmp(cbc->pszModule, MODULE) && cbc->dwButtonId == BBB_ID_FILE_SEND && cbc->hContact) {
- auto it = interceptedContacts.find(cbc->hContact);
- if (it == interceptedContacts.end())
- {
- HWND hwnd = (HWND)CallService(MS_FILE_SENDFILE, cbc->hContact, 0);
- interceptedContacts[cbc->hContact] = hwnd;
- }
- else
- FlashWindow(it->second, FALSE);
- }
-
- return 0;
-}
-
-int CDropbox::OnFileDialogCancelled(WPARAM hContact, LPARAM)
-{
- auto it = interceptedContacts.find(hContact);
- if (it != interceptedContacts.end())
- interceptedContacts.erase(it);
-
- return 0;
-}
-
-int CDropbox::OnProtoAck(WPARAM, LPARAM lParam)
-{
- ACKDATA *ack = (ACKDATA*)lParam;
-
- if (!mir_strcmp(ack->szModule, MODULE))
- return 0; // don't rebroadcast our own acks
-
- if (ack->type == ACKTYPE_STATUS) {
- WORD status = ack->lParam;
- bool canSendOffline = (CallProtoService(ack->szModule, PS_GETCAPS, PFLAGNUM_4, 0) & PF4_IMSENDOFFLINE) > 0;
-
- for (MCONTACT hContact = db_find_first(ack->szModule); hContact; hContact = db_find_next(hContact, ack->szModule)) {
- MessageWindowData msgw;
- if (!Srmm_GetWindowData(hContact, msgw) && msgw.uState & MSG_WINDOW_STATE_EXISTS) {
- BBButton bbd = {};
- bbd.pszModuleName = MODULE;
- bbd.dwButtonID = BBB_ID_FILE_SEND;
- bbd.bbbFlags = BBSF_RELEASED;
-
- if (status == ID_STATUS_OFFLINE && !canSendOffline)
- bbd.bbbFlags = BBSF_DISABLED;
-
- Srmm_SetButtonState(hContact, &bbd);
- }
- }
- }
-
- return 0;
-}
diff --git a/plugins/Dropbox/src/dropbox_icons.cpp b/plugins/Dropbox/src/dropbox_icons.cpp
deleted file mode 100644
index 33cc167117..0000000000
--- a/plugins/Dropbox/src/dropbox_icons.cpp
+++ /dev/null
@@ -1,30 +0,0 @@
-#include "stdafx.h"
-
-static IconItem iconList[] =
-{
- { LPGEN("Protocol icon"), "main", IDI_DROPBOX },
- { LPGEN("Upload file(s)"), "upload", IDI_UPLOAD }
-};
-
-void InitializeIcons()
-{
- Icon_Register(g_hInstance, "Protocols/" MODULE, iconList, _countof(iconList), MODULE);
-}
-
-HANDLE GetIconHandleByName(const char *name)
-{
- for (size_t i = 0; i < _countof(iconList); i++)
- if (mir_strcmpi(iconList[i].szName, name) == 0)
- return iconList[i].hIcolib;
-
- return nullptr;
-}
-
-HICON LoadIconEx(int iconId, bool big)
-{
- for (int i = 0; i < _countof(iconList); i++)
- if (iconList[i].defIconID == iconId)
- return IcoLib_GetIconByHandle(iconList[i].hIcolib, big);
-
- return nullptr;
-}
diff --git a/plugins/Dropbox/src/dropbox_menus.cpp b/plugins/Dropbox/src/dropbox_menus.cpp
deleted file mode 100644
index 1a96848edd..0000000000
--- a/plugins/Dropbox/src/dropbox_menus.cpp
+++ /dev/null
@@ -1,51 +0,0 @@
-#include "stdafx.h"
-
-INT_PTR CDropbox::SendFilesToDropboxCommand(void *obj, WPARAM hContact, LPARAM)
-{
- CDropbox *instance = (CDropbox*)obj;
- if (!instance->HasAccessToken())
- return 1;
-
- auto it = instance->interceptedContacts.find(hContact);
- if (it == instance->interceptedContacts.end())
- {
- HWND hwnd = (HWND)CallService(MS_FILE_SENDFILE, hContact, 0);
- instance->interceptedContacts[hContact] = hwnd;
- }
- else
- SetActiveWindow(it->second);
-
- return 0;
-}
-
-void CDropbox::InitializeMenus()
-{
- CMenuItem mi;
- SET_UID(mi, 0x19af0aaf, 0x37d0, 0x4b88, 0xa5, 0x92, 0xf1, 0x6f, 0x54, 0xfd, 0x67, 0xb5);
- mi.pszService = MODULE"/SendFilesToDropbox";
- mi.name.a = LPGEN("Upload files to Dropbox");
- mi.position = -2000020000 + CMI_SEND_FILES;
- mi.hIcolibItem = GetIconHandleByName("upload");
- contactMenuItems[CMI_SEND_FILES] = Menu_AddContactMenuItem(&mi);
- CreateServiceFunctionObj(mi.pszService, SendFilesToDropboxCommand, this);
-}
-
-int CDropbox::OnPrebuildContactMenu(WPARAM hContact, LPARAM)
-{
- bool bShow = false;
-
- char *proto = GetContactProto(hContact);
- if (proto != nullptr) {
- bool bHasIM = (CallProtoService(proto, PS_GETCAPS, PFLAGNUM_1, 0) & PF1_IMSEND) != 0;
- if (bHasIM && HasAccessToken() && hContact != GetDefaultContact() && !IsAccountIntercepted(proto)) {
- bool isProtoOnline = CallProtoService(proto, PS_GETSTATUS, 0, 0) > ID_STATUS_OFFLINE;
- WORD status = db_get_w(hContact, proto, "Status", ID_STATUS_OFFLINE);
- bool canSendOffline = (CallProtoService(proto, PS_GETCAPS, PFLAGNUM_4, 0) & PF4_IMSENDOFFLINE) > 0;
- if (isProtoOnline && (status != ID_STATUS_OFFLINE || canSendOffline))
- bShow = true;
- }
- }
-
- Menu_ShowItem(contactMenuItems[CMI_SEND_FILES], bShow);
- return 0;
-}
diff --git a/plugins/Dropbox/src/dropbox_options.cpp b/plugins/Dropbox/src/dropbox_options.cpp
deleted file mode 100644
index 65722da497..0000000000
--- a/plugins/Dropbox/src/dropbox_options.cpp
+++ /dev/null
@@ -1,160 +0,0 @@
-#include "stdafx.h"
-
-CDropboxOptionsMain::CDropboxOptionsMain(CDropbox *instance)
- : CPluginDlgBase(g_hInstance, IDD_OPTIONS_MAIN, MODULE),
- m_instance(instance),
- m_auth(this, IDC_GETAUTH, DROPBOX_WWW_URL "/oauth2/authorize?response_type=code&client_id=" DROPBOX_APP_KEY),
- m_requestCode(this, IDC_REQUEST_CODE), m_authorize(this, IDC_AUTHORIZE), m_authStatus(this, IDC_AUTH_STATUS),
- m_urlIsTemporary(this, IDC_URL_ISTEMPORARY), m_urlAutoSend(this, IDC_URL_AUTOSEND),
- m_urlPasteToMessageInputArea(this, IDC_URL_COPYTOMIA), m_urlCopyToClipboard(this, IDC_URL_COPYTOCB)
-{
- CreateLink(m_urlIsTemporary, "UrlIsTemporary", DBVT_BYTE, 0);
- CreateLink(m_urlAutoSend, "UrlAutoSend", DBVT_BYTE, 1);
- CreateLink(m_urlPasteToMessageInputArea, "UrlPasteToMessageInputArea", DBVT_BYTE, 0);
- CreateLink(m_urlCopyToClipboard, "UrlCopyToClipboard", DBVT_BYTE, 0);
-
- //m_auth.OnClick = Callback(this, &CDropboxOptionsMain::Auth_OnClick);
- m_requestCode.OnChange = Callback(this, &CDropboxOptionsMain::RequestCode_OnChange);
- m_authorize.OnClick = Callback(this, &CDropboxOptionsMain::Authorize_OnClick);
-}
-
-void CDropboxOptionsMain::OnInitDialog()
-{
- CDlgBase::OnInitDialog();
-
- LOGFONT lf;
- HFONT hFont = (HFONT)m_authStatus.SendMsg(WM_GETFONT, 0, 0);
- GetObject(hFont, sizeof(lf), &lf);
- lf.lfWeight = FW_BOLD;
- m_authStatus.SendMsg(WM_SETFONT, (WPARAM)CreateFontIndirect(&lf), 0);
-
- if (m_instance->HasAccessToken())
- m_authStatus.SetText(TranslateT("you are already authorized"));
- else
- m_authStatus.SetText(TranslateT("you are not authorized yet"));
-}
-
-void CDropboxOptionsMain::Auth_OnClick(CCtrlBase*)
-{
- SetFocus(m_requestCode.GetHwnd());
-}
-
-void CDropboxOptionsMain::RequestCode_OnChange(CCtrlBase*)
-{
- ptrA requestToken(m_requestCode.GetTextA());
- EnableWindow(m_authorize.GetHwnd(), mir_strlen(requestToken) != 0);
-}
-
-void CDropboxOptionsMain::Authorize_OnClick(CCtrlBase*)
-{
- mir_forkthreadowner(CDropbox::RequestAccessTokenAsync, m_instance, m_hwnd, nullptr);
-}
-
-/////////////////////////////////////////////////////////////////////////////////
-
-CDropboxOptionsInterception::CDropboxOptionsInterception(CDropbox*)
- : CPluginDlgBase(g_hInstance, IDD_OPTIONS_INTERCEPTION, MODULE),
- m_accounts(this, IDC_ACCOUNTS), isAccountListInit(false)
-{
-}
-
-void CDropboxOptionsInterception::OnInitDialog()
-{
- CDlgBase::OnInitDialog();
-
- m_accounts.SetExtendedListViewStyle(LVS_EX_FULLROWSELECT | LVS_EX_CHECKBOXES | LVS_EX_INFOTIP);
-
- m_accounts.AddColumn(0, TranslateT("Account name"), 50);
- m_accounts.AddColumn(1, TranslateT("Protocol"), 50);
-
- int count;
- PROTOACCOUNT** accounts;
- Proto_EnumAccounts(&count, &accounts);
- const char *interceptedAccounts = db_get_sa(NULL, MODULE, "InterceptedAccounts");
- if (interceptedAccounts == nullptr)
- interceptedAccounts = db_get_sa(NULL, MODULE, "InterceptedProtos");
- for (int i = 0; i < count; i++) {
- PROTOACCOUNT *acc = accounts[i];
- if (strstr(acc->szProtoName, MODULE) || strstr(acc->szProtoName, "Meta"))
- continue;
- int iItem = m_accounts.AddItem(mir_wstrdup(acc->tszAccountName), -1, (LPARAM)acc);
- m_accounts.SetItem(iItem, 1, mir_a2u(acc->szProtoName));
- if (interceptedAccounts && strstr(interceptedAccounts, acc->szModuleName))
- m_accounts.SetCheckState(iItem, TRUE);
- }
-
- m_accounts.SetColumnWidth(0, LVSCW_AUTOSIZE_USEHEADER);
- m_accounts.SetColumnWidth(1, LVSCW_AUTOSIZE_USEHEADER);
-
- isAccountListInit = true;
-}
-
-INT_PTR CDropboxOptionsInterception::DlgProc(UINT msg, WPARAM wParam, LPARAM lParam)
-{
- switch (msg)
- {
- case WM_NOTIFY:
- {
- LPNMHDR lpnmHdr = (LPNMHDR)lParam;
- if (lpnmHdr->idFrom == (UINT_PTR)m_accounts.GetCtrlId() && lpnmHdr->code == LVN_ITEMCHANGED)
- {
- LPNMLISTVIEW pnmv = (LPNMLISTVIEW)lParam;
- if (pnmv->uChanged & LVIF_STATE && pnmv->uNewState & LVIS_STATEIMAGEMASK)
- {
- if (isAccountListInit)
- NotifyChange();
- }
- }
- }
- break;
- }
-
- return CDlgBase::DlgProc(msg, wParam, lParam);
-}
-
-void CDropboxOptionsInterception::OnApply()
-{
- CMStringA interceptedProtos;
- int count = m_accounts.GetItemCount();
- for (int iItem = 0; iItem < count; iItem++)
- {
- PROTOACCOUNT *acc = (PROTOACCOUNT*)m_accounts.GetItemData(iItem);
- if (m_accounts.GetCheckState(iItem))
- interceptedProtos.AppendFormat("%s\t", acc->szModuleName);
-
- // hide tabsrmm button for intercepted accounts
- for (MCONTACT hContact = db_find_first(acc->szModuleName); hContact; hContact = db_find_next(hContact, acc->szModuleName)) {
- MessageWindowData msgw;
- if (!Srmm_GetWindowData(hContact, msgw) && msgw.uState & MSG_WINDOW_STATE_EXISTS) {
- BBButton bbd = {};
- bbd.pszModuleName = MODULE;
- bbd.dwButtonID = BBB_ID_FILE_SEND;
- bbd.bbbFlags = BBSF_HIDDEN | BBSF_DISABLED;
- Srmm_SetButtonState(hContact, &bbd);
- }
- }
- }
- interceptedProtos.TrimRight();
- db_set_s(NULL, MODULE, "InterceptedAccounts", interceptedProtos);
- db_unset(NULL, MODULE, "InterceptedProtos");
-}
-
-/////////////////////////////////////////////////////////////////////////////////
-
-int CDropbox::OnOptionsInitialized(WPARAM wParam, LPARAM)
-{
- OPTIONSDIALOGPAGE odp = { 0 };
- odp.szTitle.w = _A2W(MODULE);
- odp.flags = ODPF_BOLDGROUPS | ODPF_UNICODE | ODPF_DONTTRANSLATE;
- odp.szGroup.w = LPGENW("Network");
-
- odp.szTab.w = LPGENW("General");
- odp.pDialog = CDropboxOptionsMain::CreateOptionsPage(this);
- Options_AddPage(wParam, &odp);
-
- odp.szTab.w = LPGENW("Interception");
- odp.pDialog = CDropboxOptionsInterception::CreateOptionsPage(this);
- Options_AddPage(wParam, &odp);
-
- return 0;
-}
diff --git a/plugins/Dropbox/src/dropbox_options.h b/plugins/Dropbox/src/dropbox_options.h
deleted file mode 100644
index 9f5ffa1607..0000000000
--- a/plugins/Dropbox/src/dropbox_options.h
+++ /dev/null
@@ -1,50 +0,0 @@
-#ifndef _DROPBOX_OPTIONS_H_
-#define _DROPBOX_OPTIONS_H_
-
-class CDropboxOptionsMain : public CPluginDlgBase
-{
-private:
- CDropbox *m_instance;
-
-
- CCtrlHyperlink m_auth;
- CCtrlEdit m_requestCode;
- CCtrlButton m_authorize;
- CCtrlBase m_authStatus;
-
- CCtrlCheck m_urlIsTemporary;
- CCtrlCheck m_urlAutoSend;
- CCtrlCheck m_urlPasteToMessageInputArea;
- CCtrlCheck m_urlCopyToClipboard;
-
-protected:
- void OnInitDialog();
-
- void Auth_OnClick(CCtrlBase*);
- void RequestCode_OnChange(CCtrlBase*);
- void Authorize_OnClick(CCtrlBase*);
-
-public:
- CDropboxOptionsMain(CDropbox *instance);
-
- static CDlgBase *CreateOptionsPage(void *param) { return new CDropboxOptionsMain((CDropbox*)param); }
-};
-
-class CDropboxOptionsInterception : public CPluginDlgBase
-{
-private:
- bool isAccountListInit;
- CCtrlListView m_accounts;
-
-protected:
- void OnInitDialog();
- INT_PTR DlgProc(UINT msg, WPARAM wParam, LPARAM lParam);
- void OnApply();
-
-public:
- CDropboxOptionsInterception(CDropbox *instance);
-
- static CDlgBase *CreateOptionsPage(void *param) { return new CDropboxOptionsInterception((CDropbox*)param); }
-};
-
-#endif //_DROPBOX_OPTIONS_H_ \ No newline at end of file
diff --git a/plugins/Dropbox/src/dropbox_services.cpp b/plugins/Dropbox/src/dropbox_services.cpp
deleted file mode 100644
index 5457883d60..0000000000
--- a/plugins/Dropbox/src/dropbox_services.cpp
+++ /dev/null
@@ -1,227 +0,0 @@
-#include "stdafx.h"
-
-INT_PTR CDropbox::ProtoGetCaps(WPARAM wParam, LPARAM)
-{
- switch (wParam) {
- case PFLAGNUM_1:
- return PF1_IM | PF1_FILESEND;
- case PFLAGNUM_2:
- return PF2_ONLINE;
- case PFLAGNUM_4:
- return PF4_OFFLINEFILES;
- }
-
- return 0;
-}
-
-INT_PTR CDropbox::ProtoGetName(WPARAM wParam, LPARAM lParam)
-{
- if (lParam) {
- mir_strncpy((char *)lParam, MODULE, wParam);
- return 0;
- }
-
- return 1;
-}
-
-INT_PTR CDropbox::ProtoLoadIcon(WPARAM wParam, LPARAM)
-{
- return (LOWORD(wParam) == PLI_PROTOCOL) ? (INT_PTR)CopyIcon(LoadIconEx(IDI_DROPBOX)) : 0;
-}
-
-INT_PTR CDropbox::ProtoGetStatus(WPARAM, LPARAM)
-{
- return HasAccessToken() ? ID_STATUS_ONLINE : ID_STATUS_OFFLINE;
-}
-
-INT_PTR CDropbox::ProtoSendFile(WPARAM, LPARAM lParam)
-{
- CCSDATA *pccsd = (CCSDATA*)lParam;
-
- if (!HasAccessToken()) {
- ProtoBroadcastAck(MODULE, pccsd->hContact, ACKTYPE_FILE, ACKRESULT_FAILED, nullptr, (LPARAM)"You cannot send files when you are not authorized.");
- return 0;
- }
-
- FileTransferParam *ftp = new FileTransferParam(pccsd->hContact);
-
- const wchar_t *description = (wchar_t*)pccsd->wParam;
- if (description && description[0])
- ftp->AppendFormatData(L"%s\r\n", (wchar_t*)pccsd->wParam);
-
- wchar_t **paths = (wchar_t**)pccsd->lParam;
- ftp->SetWorkingDirectory(paths[0]);
- for (int i = 0; paths[i]; i++) {
- if (PathIsDirectory(paths[i]))
- continue;
- ftp->AddFile(paths[i]);
- }
-
- transfers.insert(ftp);
-
- mir_forkthreadowner(CDropbox::UploadAndReportProgress, this, ftp, nullptr);
-
- return ftp->GetId();
-}
-
-INT_PTR CDropbox::ProtoSendFileInterceptor(WPARAM wParam, LPARAM lParam)
-{
- CCSDATA *pccsd = (CCSDATA*)lParam;
-
- const char *proto = GetContactProto(pccsd->hContact);
- if (!IsAccountIntercepted(proto))
- {
- auto it = interceptedContacts.find(pccsd->hContact);
- if (it == interceptedContacts.end())
- return CALLSERVICE_NOTFOUND;
- }
-
- auto it = interceptedContacts.find(pccsd->hContact);
- if (it != interceptedContacts.end())
- interceptedContacts.erase(it);
-
- return ProtoSendFile(wParam, lParam);
-}
-
-INT_PTR CDropbox::ProtoCancelFile(WPARAM, LPARAM lParam)
-{
- CCSDATA *pccsd = (CCSDATA*)lParam;
-
- HANDLE hTransfer = (HANDLE)pccsd->wParam;
- FileTransferParam *ftp = transfers.find((FileTransferParam*)&hTransfer);
- if (ftp == nullptr)
- return 0;
-
- ftp->Terminate();
-
- return 0;
-}
-
-INT_PTR CDropbox::ProtoSendMessage(WPARAM, LPARAM lParam)
-{
- CCSDATA *pccsd = (CCSDATA*)lParam;
-
- if (!HasAccessToken()) {
- ProtoBroadcastAck(MODULE, pccsd->hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, nullptr, (LPARAM)"You cannot send messages when you are not authorized.");
- return 0;
- }
-
- char *szMessage = (char*)pccsd->lParam;
- if (*szMessage == '/') {
- // parse commands
- char *sep = strchr(szMessage, ' ');
-
- struct
- {
- const char *szCommand;
- pThreadFunc pHandler;
- }
- static commands[] =
- {
- { "help", &CDropbox::CommandHelp },
- { "list", &CDropbox::CommandList },
- { "share", &CDropbox::CommandShare },
- { "search", &CDropbox::CommandSearch },
- { "delete", &CDropbox::CommandDelete }
- };
-
- char command[16] = {0};
- mir_strncpy(command, szMessage + 1, sep ? sep - szMessage : mir_strlen(szMessage));
- for (int i = 0; i < _countof(commands); i++) {
- if (!mir_strcmp(command, commands[i].szCommand)) {
- ULONG messageId = InterlockedIncrement(&hMessageProcess);
-
- CommandParam *param = new CommandParam();
- param->instance = this;
- param->hContact = pccsd->hContact;
- param->hProcess = (HANDLE)messageId;
- param->data = (sep ? sep + 1 : NULL);
-
- mir_forkthread(commands[i].pHandler, param);
-
- return messageId;
- }
- }
- }
-
- ProtoBroadcastAck(MODULE, pccsd->hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, nullptr, 0);
- char help[1024];
- mir_snprintf(help, Translate("\"%s\" is not valid.\nUse \"/help\" for more info."), szMessage);
- ProtoChainSend(GetDefaultContact(), PSR_MESSAGE, 0, (LPARAM)help);
- return 0;
-}
-
-INT_PTR CDropbox::ProtoReceiveMessage(WPARAM, LPARAM lParam)
-{
- CCSDATA *pccsd = (CCSDATA*)lParam;
-
- char *message = (char*)pccsd->lParam;
-
- DBEVENTINFO dbei = {};
- dbei.flags = DBEF_UTF;
- dbei.szModule = MODULE;
- dbei.timestamp = time(nullptr);
- dbei.eventType = EVENTTYPE_MESSAGE;
- dbei.cbBlob = (int)mir_strlen(message);
- dbei.pBlob = (PBYTE)mir_strdup(message);
- db_event_add(pccsd->hContact, &dbei);
-
- return 0;
-}
-
-INT_PTR CDropbox::UploadToDropbox(WPARAM wParam, LPARAM lParam)
-{
- DropboxUploadInfo *uploadInfo = (DropboxUploadInfo*)lParam;
-
- FileTransferParam *ftp = new FileTransferParam(GetDefaultContact());
- ftp->SetWorkingDirectory(uploadInfo->localPath);
- ftp->SetServerFolder(uploadInfo->serverFolder);
-
- if (PathIsDirectory(uploadInfo->localPath))
- {
- // temporary unsupported
-
- transfers.remove(ftp);
- delete ftp;
-
- return ACKRESULT_FAILED;
- }
- else
- ftp->AddFile(uploadInfo->localPath);
-
- int res = UploadToDropbox(this, ftp);
- if (res == ACKRESULT_SUCCESS && wParam) {
- char **data = (char**)wParam;
- *data = mir_utf8encodeW(ftp->GetData());
- }
-
- transfers.remove(ftp);
- delete ftp;
-
- return res;
-}
-
-INT_PTR CDropbox::UploadToDropboxAsync(WPARAM, LPARAM lParam)
-{
- DropboxUploadInfo *uploadInfo = (DropboxUploadInfo*)lParam;
-
- FileTransferParam *ftp = new FileTransferParam(GetDefaultContact());
- ftp->SetWorkingDirectory(uploadInfo->localPath);
- ftp->SetServerFolder(uploadInfo->serverFolder);
-
- if (PathIsDirectory(uploadInfo->localPath))
- {
- // temporary unsupported
-
- transfers.remove(ftp);
- delete ftp;
-
- return NULL;
- }
- else
- ftp->AddFile(uploadInfo->localPath);
-
- mir_forkthreadowner(CDropbox::UploadAndRaiseEvent, this, ftp, nullptr);
-
- return ftp->GetId();
-} \ No newline at end of file
diff --git a/plugins/Dropbox/src/dropbox_transfers.cpp b/plugins/Dropbox/src/dropbox_transfers.cpp
deleted file mode 100644
index 177d5768bb..0000000000
--- a/plugins/Dropbox/src/dropbox_transfers.cpp
+++ /dev/null
@@ -1,217 +0,0 @@
-#include "stdafx.h"
-
-char* CDropbox::UploadFile(const char *data, size_t size, char *path)
-{
- ptrA token(db_get_sa(NULL, MODULE, "TokenSecret"));
- ptrA encodedPath(mir_utf8encode(path));
- UploadFileRequest request(token, encodedPath, data, size);
- NLHR_PTR response(request.Send(hNetlibConnection));
-
- JSONNode root = HandleJsonResponse(response);
- JSONNode node = root.at("path_lower");
- mir_strcpy(path, node.as_string().c_str());
-
- return path;
-}
-
-void CDropbox::StartUploadSession(const char *data, size_t size, char *sessionId)
-{
- ptrA token(db_get_sa(NULL, MODULE, "TokenSecret"));
- StartUploadSessionRequest request(token, data, size);
- NLHR_PTR response(request.Send(hNetlibConnection));
-
- JSONNode root = HandleJsonResponse(response);
- JSONNode node = root.at("session_id");
- mir_strcpy(sessionId, node.as_string().c_str());
-}
-
-void CDropbox::AppendToUploadSession(const char *data, size_t size, const char *sessionId, size_t offset)
-{
- ptrA token(db_get_sa(NULL, MODULE, "TokenSecret"));
- AppendToUploadSessionRequest request(token, sessionId, offset, data, size);
- NLHR_PTR response(request.Send(hNetlibConnection));
-
- HandleJsonResponse(response);
-}
-
-char* CDropbox::FinishUploadSession(const char *data, size_t size, const char *sessionId, size_t offset, char *path)
-{
- ptrA token(db_get_sa(NULL, MODULE, "TokenSecret"));
- FinishUploadSessionRequest request(token, sessionId, offset, path, data, size);
- NLHR_PTR response(request.Send(hNetlibConnection));
-
- JSONNode root = HandleJsonResponse(response);
- JSONNode node = root.at("path_lower");
- mir_strcpy(path, node.as_string().c_str());
-
- return path;
-}
-
-void CDropbox::CreateFolder(const char *path)
-{
- ptrA token(db_get_sa(NULL, MODULE, "TokenSecret"));
- CreateFolderRequest request(token, path);
- NLHR_PTR response(request.Send(hNetlibConnection));
-
- // forder exists on server
- if (response->resultCode == HTTP_STATUS_FORBIDDEN)
- return;
-
- HandleJsonResponse(response);
-}
-
-void CDropbox::CreateDownloadUrl(const char *path, char *url)
-{
- ptrA token(db_get_sa(NULL, MODULE, "TokenSecret"));
- if (db_get_b(NULL, MODULE, "UrlIsTemporary", 0)) {
- GetTemporaryLinkRequest request(token, path);
- NLHR_PTR response(request.Send(hNetlibConnection));
-
- JSONNode root = HandleJsonResponse(response);
- JSONNode link = root.at("link");
- mir_strcpy(url, link.as_string().c_str());
- return;
- }
-
- CreateSharedLinkRequest shareRequest(token, path);
- NLHR_PTR response(shareRequest.Send(hNetlibConnection));
-
- HandleHttpResponse(response);
-
- JSONNode root = JSONNode::parse(response->pData);
- if (root.isnull())
- throw DropboxException(HttpStatusToText(HTTP_STATUS_ERROR));
-
- JSONNode error = root.at("error");
- if (error.isnull()) {
- JSONNode link = root.at("url");
- mir_strcpy(url, link.as_string().c_str());
- return;
- }
-
- json_string tag = error.at(".tag").as_string();
- if (tag != "shared_link_already_exists")
- throw DropboxException(tag.c_str());
-
- GetSharedLinkRequest getRequest(token, path);
- response = getRequest.Send(hNetlibConnection);
-
- root = HandleJsonResponse(response);
-
- JSONNode links = root.at("links").as_array();
- const JSONNode &link = (*links.begin()).at("url");
- mir_strcpy(url, link.as_string().c_str());
-}
-
-UINT CDropbox::UploadToDropbox(void *owner, void *arg)
-{
- CDropbox *instance = (CDropbox*)owner;
- FileTransferParam *ftp = (FileTransferParam*)arg;
-
- try {
- const wchar_t *folderName = ftp->GetFolderName();
- if (folderName) {
- char path[MAX_PATH], url[MAX_PATH];
- PreparePath(folderName, path);
- instance->CreateFolder(path);
- instance->CreateDownloadUrl(path, url);
- ftp->AppendFormatData(L"%s\r\n", ptrW(mir_utf8decodeW(url)));
- }
-
- ftp->FirstFile();
- do
- {
- const wchar_t *fileName = ftp->GetCurrentRelativeFilePath();
- uint64_t fileSize = ftp->GetCurrentFileSize();
-
- int chunkSize = ftp->GetCurrentFileChunkSize();
- mir_ptr<char>data((char*)mir_calloc(chunkSize));
- size_t size = ftp->ReadCurrentFile(data, chunkSize);
-
- size_t offset = 0;
- char sessionId[64];
- instance->StartUploadSession(data, size, sessionId);
-
- offset += size;
- ftp->Progress(size);
-
- for (size_t chunk = 0; chunk < (fileSize / chunkSize) - 1; chunk++)
- {
- ftp->CheckCurrentFile();
-
- size = ftp->ReadCurrentFile(data, chunkSize);
- instance->AppendToUploadSession(data, size, sessionId, offset);
-
- offset += size;
- ftp->Progress(size);
- }
-
- if (offset < fileSize)
- size = ftp->ReadCurrentFile(data, fileSize - offset);
- else
- size = 0;
-
- char path[MAX_PATH];
- const wchar_t *serverFolder = ftp->GetServerFolder();
- if (serverFolder) {
- wchar_t serverPath[MAX_PATH] = { 0 };
- mir_snwprintf(serverPath, L"%s\\%s", serverFolder, fileName);
- PreparePath(serverPath, path);
- }
- else
- PreparePath(fileName, path);
- instance->FinishUploadSession(data, size, sessionId, offset, path);
-
- ftp->Progress(size);
-
- if (!wcschr(fileName, L'\\')) {
- char url[MAX_PATH];
- instance->CreateDownloadUrl(path, url);
- ftp->AppendFormatData(L"%s\r\n", ptrW(mir_utf8decodeW(url)));
- }
- } while (ftp->NextFile());
- }
- catch (DropboxException &ex) {
- Netlib_Logf(instance->hNetlibConnection, "%s: %s", MODULE, ex.what());
- ftp->SetStatus(ACKRESULT_FAILED);
- return ACKRESULT_FAILED;
- }
-
- ftp->SetStatus(ACKRESULT_SUCCESS);
- return ACKRESULT_SUCCESS;
-}
-
-UINT CDropbox::UploadAndReportProgress(void *owner, void *arg)
-{
- CDropbox *instance = (CDropbox*)owner;
- FileTransferParam *ftp = (FileTransferParam*)arg;
-
- int res = UploadToDropbox(owner, arg);
- if (res == ACKRESULT_SUCCESS)
- instance->Report(ftp->GetHContact(), ftp->GetData());
-
- instance->transfers.remove(ftp);
- delete ftp;
-
- return res;
-}
-
-UINT CDropbox::UploadAndRaiseEvent(void *owner, void *arg)
-{
- CDropbox *instance = (CDropbox*)owner;
- FileTransferParam *ftp = (FileTransferParam*)arg;
-
- int res = UploadToDropbox(owner, arg);
-
- DropboxUploadResult ur = {};
- ur.hProcess = (HANDLE)ftp->GetId();
- ur.status = res;
- ur.data = T2Utf(ftp->GetData());
-
- NotifyEventHooks(instance->hUploadedEventHook, ftp->GetHContact(), (LPARAM)&ur);
-
- instance->transfers.remove(ftp);
- delete ftp;
-
- return res;
-} \ No newline at end of file
diff --git a/plugins/Dropbox/src/dropbox_utils.cpp b/plugins/Dropbox/src/dropbox_utils.cpp
deleted file mode 100644
index a4e5d51747..0000000000
--- a/plugins/Dropbox/src/dropbox_utils.cpp
+++ /dev/null
@@ -1,156 +0,0 @@
-#include "stdafx.h"
-
-char* CDropbox::PreparePath(const char *oldPath, char *newPath)
-{
- if (oldPath == nullptr)
- mir_strcpy(newPath, "");
- else if (*oldPath != '/')
- {
- CMStringA result("/");
- result.Append(oldPath);
- result.Replace("\\", "/");
- mir_strcpy(newPath, result);
- }
- else
- mir_strcpy(newPath, oldPath);
- return newPath;
-}
-
-char* CDropbox::PreparePath(const wchar_t *oldPath, char *newPath)
-{
- return PreparePath(ptrA(mir_utf8encodeW(oldPath)), newPath);
-}
-
-bool CDropbox::IsAccountIntercepted(const char *module)
-{
- const char *interceptedAccounts = db_get_sa(NULL, MODULE, "InterceptedAccounts");
- if (interceptedAccounts == nullptr)
- interceptedAccounts = db_get_sa(NULL, MODULE, "InterceptedProtos");
- return interceptedAccounts && strstr(interceptedAccounts, module);
-}
-
-char* CDropbox::HttpStatusToText(HTTP_STATUS status)
-{
- switch (status) {
- case HTTP_STATUS_ERROR:
- return "Server does not respond";
- case HTTP_STATUS_OK:
- return "OK";
- case HTTP_STATUS_BAD_REQUEST:
- return "Bad input parameter. Error message should indicate which one and why";
- case HTTP_STATUS_UNAUTHORIZED:
- return "Bad or expired token. This can happen if the user or Dropbox revoked or expired an access token. To fix, you should re-authenticate the user";
- case HTTP_STATUS_FORBIDDEN:
- return "Bad OAuth request (wrong consumer key, bad nonce, expired timestamp...). Unfortunately, re-authenticating the user won't help here";
- case HTTP_STATUS_NOT_FOUND:
- return "File or folder not found at the specified path";
- case HTTP_STATUS_METHOD_NOT_ALLOWED:
- return "Request method not expected (generally should be GET or POST)";
- case HTTP_STATUS_TOO_MANY_REQUESTS:
- return "Your app is making too many requests and is being rate limited. 429s can trigger on a per-app or per-user basis";
- case HTTP_STATUS_SERVICE_UNAVAILABLE:
- return "If the response includes the Retry-After header, this means your OAuth 1.0 app is being rate limited. Otherwise, this indicates a transient server error, and your app should retry its request.";
- case HTTP_STATUS_INSUFICIENTE_STORAGE:
- return "User is over Dropbox storage quota";
- }
-
- return "Unknown error";
-}
-
-void CDropbox::HandleHttpResponse(NETLIBHTTPREQUEST *response)
-{
- if (response == nullptr)
- throw DropboxException(HttpStatusToText(HTTP_STATUS_ERROR));
-}
-
-JSONNode CDropbox::HandleJsonResponse(NETLIBHTTPREQUEST *response)
-{
- HandleHttpResponse(response);
-
- if (response->resultCode != HTTP_STATUS_OK &&
- response->resultCode != HTTP_STATUS_CONFLICT) {
- if (response->dataLength)
- throw DropboxException(response->pData);
- throw DropboxException(HttpStatusToText((HTTP_STATUS)response->resultCode));
- }
-
- JSONNode root = JSONNode::parse(response->pData);
- if (root.isnull())
- throw DropboxException(HttpStatusToText(HTTP_STATUS_ERROR));
-
- JSONNode error = root.at("error");
- if (!error.isnull()) {
- json_string tag = error.at(".tag").as_string();
- throw DropboxException(tag.c_str());
- }
-
- return root;
-}
-
-MEVENT CDropbox::AddEventToDb(MCONTACT hContact, WORD type, DWORD flags, DWORD cbBlob, PBYTE pBlob)
-{
- DBEVENTINFO dbei = {};
- dbei.szModule = MODULE;
- dbei.timestamp = time(nullptr);
- dbei.eventType = type;
- dbei.cbBlob = cbBlob;
- dbei.pBlob = pBlob;
- dbei.flags = flags;
- return db_event_add(hContact, &dbei);
-}
-
-void CDropbox::SendToContact(MCONTACT hContact, const wchar_t *data)
-{
- if (hContact == GetDefaultContact()) {
- char *message = mir_utf8encodeW(data);
- AddEventToDb(hContact, EVENTTYPE_MESSAGE, DBEF_UTF, (DWORD)mir_strlen(message), (PBYTE)message);
- return;
- }
-
- const char *szProto = GetContactProto(hContact);
- if (db_get_b(hContact, szProto, "ChatRoom", 0) == TRUE) {
- ptrW tszChatRoom(db_get_wsa(hContact, szProto, "ChatRoomID"));
- Chat_SendUserMessage(szProto, tszChatRoom, data);
- return;
- }
-
- char *message = mir_utf8encodeW(data);
- if (ProtoChainSend(hContact, PSS_MESSAGE, 0, (LPARAM)message) != ACKRESULT_FAILED)
- AddEventToDb(hContact, EVENTTYPE_MESSAGE, DBEF_UTF | DBEF_SENT, (DWORD)mir_strlen(message), (PBYTE)message);
-}
-
-void CDropbox::PasteToInputArea(MCONTACT hContact, const wchar_t *data)
-{
- CallService(MS_MSG_SENDMESSAGEW, hContact, (LPARAM)data);
-}
-
-void CDropbox::PasteToClipboard(const wchar_t *data)
-{
- if (OpenClipboard(nullptr)) {
- EmptyClipboard();
-
- size_t size = sizeof(wchar_t) * (mir_wstrlen(data) + 1);
- HGLOBAL hClipboardData = GlobalAlloc(NULL, size);
- if (hClipboardData) {
- wchar_t *pchData = (wchar_t*)GlobalLock(hClipboardData);
- if (pchData) {
- memcpy(pchData, (wchar_t*)data, size);
- GlobalUnlock(hClipboardData);
- SetClipboardData(CF_UNICODETEXT, hClipboardData);
- }
- }
- CloseClipboard();
- }
-}
-
-void CDropbox::Report(MCONTACT hContact, const wchar_t *data)
-{
- if (db_get_b(NULL, MODULE, "UrlAutoSend", 1))
- SendToContact(hContact, data);
-
- if (db_get_b(NULL, MODULE, "UrlPasteToMessageInputArea", 0))
- PasteToInputArea(hContact, data);
-
- if (db_get_b(NULL, MODULE, "UrlCopyToClipboard", 0))
- PasteToClipboard(data);
-}
diff --git a/plugins/Dropbox/src/file_transfer.h b/plugins/Dropbox/src/file_transfer.h
deleted file mode 100644
index 8c50542bed..0000000000
--- a/plugins/Dropbox/src/file_transfer.h
+++ /dev/null
@@ -1,245 +0,0 @@
-#ifndef _FILE_TRANSFER_H_
-#define _FILE_TRANSFER_H_
-
-class FileTransferParam
-{
-private:
- static ULONG hFileProcess;
-
- ULONG id;
- FILE *hFile;
- PROTOFILETRANSFERSTATUS pfts;
-
- bool isTerminated;
-
- const wchar_t* folderName;
- int relativePathStart;
-
- CMStringW serverFolder;
-
- CMStringW data;
-
-public:
- FileTransferParam(MCONTACT hContact)
- {
- hFile = NULL;
- id = InterlockedIncrement(&hFileProcess);
-
- isTerminated = false;
-
- folderName = NULL;
- relativePathStart = 0;
-
- pfts.cbSize = sizeof(this->pfts);
- pfts.flags = PFTS_UNICODE | PFTS_SENDING;
- pfts.hContact = hContact;
- pfts.currentFileNumber = -1;
- pfts.currentFileProgress = 0;
- pfts.currentFileSize = 0;
- pfts.currentFileTime = 0;
- pfts.totalBytes = 0;
- pfts.totalFiles = 0;
- pfts.totalProgress = 0;
- pfts.ptszFiles = (wchar_t**)mir_alloc(sizeof(wchar_t*) * (pfts.totalFiles + 1));
- pfts.ptszFiles[pfts.totalFiles] = NULL;
- pfts.tszWorkingDir = NULL;
- pfts.tszCurrentFile = NULL;
-
- ProtoBroadcastAck(MODULE, pfts.hContact, ACKTYPE_FILE, ACKRESULT_INITIALISING, (HANDLE)id, 0);
- }
-
- ~FileTransferParam()
- {
- CloseCurrentFile();
-
- if (pfts.tszWorkingDir)
- mir_free(pfts.tszWorkingDir);
-
- if (pfts.pszFiles)
- {
- for (int i = 0; pfts.pszFiles[i]; i++)
- {
- if (pfts.pszFiles[i]) mir_free(pfts.pszFiles[i]);
- }
- mir_free(pfts.pszFiles);
- }
- }
-
- ULONG GetId() const
- {
- return id;
- }
-
- MCONTACT GetHContact() const
- {
- return pfts.hContact;
- }
-
- const wchar_t* GetData() const
- {
- if (data.IsEmpty())
- return NULL;
- return data;
- }
-
- void Terminate()
- {
- isTerminated = true;
- }
-
- void SetWorkingDirectory(const wchar_t *path)
- {
- relativePathStart = wcsrchr(path, '\\') - path + 1;
- pfts.tszWorkingDir = (wchar_t*)mir_calloc(sizeof(wchar_t) * relativePathStart);
- mir_wstrncpy(pfts.tszWorkingDir, path, relativePathStart);
- if (PathIsDirectory(path))
- folderName = wcsrchr(path, '\\') + 1;
- }
-
- void SetServerFolder(const wchar_t *path)
- {
- if (path)
- serverFolder = path;
- }
-
- const wchar_t* GetServerFolder() const
- {
- if (serverFolder.IsEmpty())
- return NULL;
- return serverFolder;
- }
-
- const wchar_t* GetFolderName() const
- {
- return folderName;
- }
-
- void AddFile(const wchar_t *path)
- {
- pfts.ptszFiles = (wchar_t**)mir_realloc(pfts.ptszFiles, sizeof(wchar_t*) * (pfts.totalFiles + 2));
- pfts.ptszFiles[pfts.totalFiles++] = mir_wstrdup(path);
- pfts.ptszFiles[pfts.totalFiles] = NULL;
-
- FILE *file = _wfopen(path, L"rb");
- if (file != NULL) {
- _fseeki64(file, 0, SEEK_END);
- pfts.totalBytes += _ftelli64(file);
- fclose(file);
- }
- }
-
- void AppendFormatData(const wchar_t *format, ...)
- {
- va_list args;
- va_start(args, format);
- data.AppendFormatV(format, args);
- va_end(args);
- }
-
- const wchar_t* GetCurrentFilePath() const
- {
- return pfts.ptszFiles[pfts.currentFileNumber];
- }
-
- const wchar_t* GetCurrentRelativeFilePath() const
- {
- return &GetCurrentFilePath()[relativePathStart];
- }
-
- const wchar_t* GetCurrentFileName() const
- {
- return wcsrchr(pfts.ptszFiles[pfts.currentFileNumber], '\\') + 1;
- }
-
- void OpenCurrentFile()
- {
- hFile = _wfopen(GetCurrentFilePath(), L"rb");
- if (!hFile)
- throw DropboxException("Unable to open file");
- _fseeki64(hFile, 0, SEEK_END);
- pfts.currentFileSize = _ftelli64(hFile);
- rewind(hFile);
- }
-
- size_t ReadCurrentFile(void *buffer, size_t count)
- {
- return fread(buffer, sizeof(char), count, hFile);
- }
-
- void CheckCurrentFile()
- {
- if (ferror(hFile))
- throw DropboxException("Error while file sending");
-
- if (isTerminated)
- throw DropboxException("Transfer was terminated");
- }
-
- void CloseCurrentFile()
- {
- if (hFile != NULL)
- {
- fclose(hFile);
- hFile = NULL;
- }
- }
-
- const uint64_t GetCurrentFileSize() const
- {
- return pfts.currentFileSize;
- }
-
- const uint64_t GetCurrentFileChunkSize() const
- {
- int chunkSize = 1024 * 1024;
- if (pfts.currentFileSize < chunkSize)
- chunkSize = min(pfts.currentFileSize, chunkSize / 4);
- else if (pfts.currentFileSize > 20 * chunkSize)
- chunkSize = chunkSize * 4;
- return chunkSize;
- }
-
- void Progress(size_t count)
- {
- pfts.currentFileProgress += count;
- pfts.totalProgress += count;
- ProtoBroadcastAck(MODULE, pfts.hContact, ACKTYPE_FILE, ACKRESULT_DATA, (HANDLE)id, (LPARAM)&pfts);
- }
-
- void FirstFile()
- {
- CloseCurrentFile();
-
- pfts.currentFileNumber = 0;
- pfts.currentFileProgress = 0;
- pfts.tszCurrentFile = wcsrchr(pfts.ptszFiles[pfts.currentFileNumber], '\\') + 1;
- ProtoBroadcastAck(MODULE, pfts.hContact, ACKTYPE_FILE, ACKRESULT_DATA, (HANDLE)id, (LPARAM)&pfts);
-
- OpenCurrentFile();
- CheckCurrentFile();
- }
-
- bool NextFile()
- {
- CloseCurrentFile();
-
- if (++pfts.currentFileNumber == pfts.totalFiles)
- return false;
-
- pfts.currentFileProgress = 0;
- pfts.tszCurrentFile = wcsrchr(pfts.ptszFiles[pfts.currentFileNumber], '\\') + 1;
- ProtoBroadcastAck(MODULE, pfts.hContact, ACKTYPE_FILE, ACKRESULT_NEXTFILE, (HANDLE)id, 0);
-
- OpenCurrentFile();
- CheckCurrentFile();
-
- return true;
- }
-
- void SetStatus(int status, LPARAM param = 0)
- {
- ProtoBroadcastAck(MODULE, pfts.hContact, ACKTYPE_FILE, status, (HANDLE)id, param);
- }
-};
-
-#endif //_FILE_TRANSFER_H_ \ No newline at end of file
diff --git a/plugins/Dropbox/src/http_request.h b/plugins/Dropbox/src/http_request.h
deleted file mode 100644
index 9d11ee4742..0000000000
--- a/plugins/Dropbox/src/http_request.h
+++ /dev/null
@@ -1,166 +0,0 @@
-#ifndef _HTTP_REQUEST_H_
-#define _HTTP_REQUEST_H_
-
-enum HTTP_STATUS
-{
- HTTP_STATUS_ERROR = 0,
- HTTP_STATUS_OK = 200,
- HTTP_STATUS_BAD_REQUEST = 400,
- HTTP_STATUS_UNAUTHORIZED = 401,
- HTTP_STATUS_FORBIDDEN = 403,
- HTTP_STATUS_NOT_FOUND = 404,
- HTTP_STATUS_METHOD_NOT_ALLOWED = 405,
- HTTP_STATUS_CONFLICT = 409,
- HTTP_STATUS_TOO_MANY_REQUESTS = 429,
- HTTP_STATUS_SERVICE_UNAVAILABLE = 503,
- HTTP_STATUS_INSUFICIENTE_STORAGE = 507
-};
-
-class HttpRequestException
-{
- CMStringA message;
-
-public:
- HttpRequestException(const char *message) :
- message(message)
- {
- }
-
- const char* what() const throw()
- {
- return message.c_str();
- }
-};
-
-class HttpRequest : protected NETLIBHTTPREQUEST
-{
-private:
- CMStringA m_szUrl;
-
- void Init(int type)
- {
- cbSize = sizeof(NETLIBHTTPREQUEST);
- requestType = type;
- flags = NLHRF_HTTP11 | NLHRF_SSL | NLHRF_NODUMPSEND | NLHRF_DUMPASTEXT;
- szUrl = NULL;
- headers = NULL;
- headersCount = 0;
- pData = NULL;
- dataLength = 0;
- resultCode = 0;
- szResultDescr = NULL;
- nlc = NULL;
- timeout = 0;
- }
-
-protected:
- enum HttpRequestUrlFormat { FORMAT };
-
- void AddHeader(LPCSTR szName, LPCSTR szValue)
- {
- headers = (NETLIBHTTPHEADER*)mir_realloc(headers, sizeof(NETLIBHTTPHEADER) * (headersCount + 1));
- headers[headersCount].szName = mir_strdup(szName);
- headers[headersCount].szValue = mir_strdup(szValue);
- headersCount++;
- }
-
- void AddBasicAuthHeader(LPCSTR szLogin, LPCSTR szPassword)
- {
- char cPair[128];
- mir_snprintf(
- cPair,
- _countof(cPair),
- "%s:%s",
- szLogin,
- szPassword);
-
- char *ePair = (char *)mir_base64_encode((BYTE*)cPair, (UINT)mir_strlen(cPair));
-
- char value[128];
- mir_snprintf(
- value,
- _countof(value),
- "Basic %s",
- ePair);
-
- mir_free(ePair);
-
- headers = (NETLIBHTTPHEADER*)mir_realloc(headers, sizeof(NETLIBHTTPHEADER)*(headersCount + 1));
- headers[headersCount].szName = mir_strdup("Authorization");
- headers[headersCount].szValue = mir_strdup(value);
- headersCount++;
- }
-
- void AddBearerAuthHeader(LPCSTR szValue)
- {
- char value[128];
- mir_snprintf(
- value,
- _countof(value),
- "Bearer %s",
- szValue);
-
- headers = (NETLIBHTTPHEADER*)mir_realloc(headers, sizeof(NETLIBHTTPHEADER)*(headersCount + 1));
- headers[headersCount].szName = mir_strdup("Authorization");
- headers[headersCount].szValue = mir_strdup(value);
- headersCount++;
- }
-
- void AddUrlParameter(const char *urlFormat, ...)
- {
- va_list urlArgs;
- va_start(urlArgs, urlFormat);
- m_szUrl += m_szUrl.Find('?') == -1 ? '?' : '&';
- m_szUrl.AppendFormatV(urlFormat, urlArgs);
- va_end(urlArgs);
- }
-
- void SetData(const char *data, size_t size)
- {
- if (pData != NULL)
- mir_free(pData);
-
- dataLength = (int)size;
- pData = (char*)mir_alloc(size);
- memcpy(pData, data, size);
- }
-
-public:
- HttpRequest(int type, LPCSTR url)
- {
- Init(type);
-
- m_szUrl = url;
- }
-
- HttpRequest(int type, HttpRequestUrlFormat, LPCSTR urlFormat, ...)
- {
- Init(type);
-
- va_list formatArgs;
- va_start(formatArgs, urlFormat);
- m_szUrl.AppendFormatV(urlFormat, formatArgs);
- va_end(formatArgs);
- }
-
- ~HttpRequest()
- {
- for (int i = 0; i < headersCount; i++)
- {
- mir_free(headers[i].szName);
- mir_free(headers[i].szValue);
- }
- mir_free(headers);
- if (pData)
- mir_free(pData);
- }
-
- NETLIBHTTPREQUEST* Send(HNETLIBUSER hNetlibConnection)
- {
- m_szUrl.Replace('\\', '/');
- szUrl = m_szUrl.GetBuffer();
- return Netlib_HttpTransaction(hNetlibConnection, this);
- }
-};
-
-#endif //_HTTP_REQUEST_H_ \ No newline at end of file
diff --git a/plugins/Dropbox/src/main.cpp b/plugins/Dropbox/src/main.cpp
deleted file mode 100644
index 033ca11032..0000000000
--- a/plugins/Dropbox/src/main.cpp
+++ /dev/null
@@ -1,55 +0,0 @@
-#include "stdafx.h"
-
-void InitializeIcons();
-
-int hLangpack;
-CDropbox *dropbox;
-HINSTANCE g_hInstance;
-
-PLUGININFOEX pluginInfo =
-{
- sizeof(PLUGININFOEX),
- __PLUGIN_NAME,
- PLUGIN_MAKE_VERSION(__MAJOR_VERSION, __MINOR_VERSION, __RELEASE_NUM, __BUILD_NUM),
- __DESCRIPTION,
- __AUTHOR,
- __AUTHOREMAIL,
- __COPYRIGHT,
- __AUTHORWEB,
- UNICODE_AWARE,
- // {B908773A-86F7-4A91-8674-6A20BA0E67D1}
- { 0xb908773a, 0x86f7, 0x4a91, { 0x86, 0x74, 0x6a, 0x20, 0xba, 0xe, 0x67, 0xd1 } }
-
-};
-
-DWORD WINAPI DllMain(HINSTANCE hInstance, DWORD, LPVOID)
-{
- g_hInstance = hInstance;
-
- return TRUE;
-}
-
-extern "C" __declspec(dllexport) PLUGININFOEX* MirandaPluginInfoEx(DWORD)
-{
- return &pluginInfo;
-}
-
-extern "C" __declspec(dllexport) const MUUID MirandaInterfaces[] = { MIID_DROPBOX, MIID_LAST };
-
-extern "C" int __declspec(dllexport) Load(void)
-{
- mir_getLP(&pluginInfo);
-
- InitializeIcons();
-
- dropbox = new CDropbox();
-
- return 0;
-}
-
-extern "C" int __declspec(dllexport) Unload(void)
-{
- delete dropbox;
-
- return 0;
-} \ No newline at end of file
diff --git a/plugins/Dropbox/src/resource.h b/plugins/Dropbox/src/resource.h
deleted file mode 100644
index 1c8d33bf53..0000000000
--- a/plugins/Dropbox/src/resource.h
+++ /dev/null
@@ -1,34 +0,0 @@
-//{{NO_DEPENDENCIES}}
-// Microsoft Visual C++ generated include file.
-// Used by C:\Users\unsane\Projects\c++\miranda-ng\plugins\Dropbox\res\resource.rc
-//
-#define IDI_DROPBOX 102
-#define IDI_UPLOAD 103
-#define IDD_OPTIONS_MAIN 109
-#define IDD_OPTIONS_INTERCEPTION 110
-#define IDC_REQUEST_CODE 1001
-#define IDC_AUTHORIZE 1002
-#define IDC_USE_SHORT_LINKS 1004
-#define IDC_URL_USE_SHORT 1004
-#define IDC_URL_ISTEMPORARY 1004
-#define IDC_AUTH_STATUS 1005
-#define IDC_GET_AUTH_LINK 1006
-#define IDC_URL_COPYTOCB 1009
-#define IDC_CHECK1 1010
-#define IDC_PROTOCOLS 1011
-#define IDC_ACCOUNTS 1011
-#define IDC_URL_COPYTOML 1029
-#define IDC_URL_COPYTOMIA 1029
-#define IDC_URL_AUTOSEND 1030
-#define IDC_GETAUTH 1200
-
-// Next default values for new objects
-//
-#ifdef APSTUDIO_INVOKED
-#ifndef APSTUDIO_READONLY_SYMBOLS
-#define _APS_NEXT_RESOURCE_VALUE 105
-#define _APS_NEXT_COMMAND_VALUE 40001
-#define _APS_NEXT_CONTROL_VALUE 1013
-#define _APS_NEXT_SYMED_VALUE 101
-#endif
-#endif
diff --git a/plugins/Dropbox/src/stdafx.cxx b/plugins/Dropbox/src/stdafx.cxx
deleted file mode 100644
index 0d27ff81bb..0000000000
--- a/plugins/Dropbox/src/stdafx.cxx
+++ /dev/null
@@ -1,20 +0,0 @@
-/*
-Copyright (C) 2012-17 Miranda NG project (https://miranda-ng.org)
-
-This program is free software; you can redistribute it and/or
-modify it under the terms of the GNU General Public License
-as published by the Free Software Foundation version 2
-of the License.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-#include "stdafx.h"
-
-ULONG FileTransferParam::hFileProcess = 1; \ No newline at end of file
diff --git a/plugins/Dropbox/src/stdafx.h b/plugins/Dropbox/src/stdafx.h
deleted file mode 100644
index 84aeb6e2a2..0000000000
--- a/plugins/Dropbox/src/stdafx.h
+++ /dev/null
@@ -1,87 +0,0 @@
-#ifndef _COMMON_H_
-#define _COMMON_H_
-
-#include <windows.h>
-#include <shlwapi.h>
-#include <commctrl.h>
-
-#include <malloc.h>
-#include <time.h>
-
-#include <map>
-
-#include <newpluginapi.h>
-
-#include <m_options.h>
-#include <m_database.h>
-#include <m_netlib.h>
-#include <m_clist.h>
-#include <m_skin.h>
-#include <m_icolib.h>
-#include <m_popup.h>
-#include <m_file.h>
-#include <m_json.h>
-#include <m_langpack.h>
-#include <m_message.h>
-#include <m_string.h>
-#include <m_gui.h>
-#include <m_chat.h>
-
-#include <m_protoint.h>
-#include <m_protosvc.h>
-
-#include <m_dropbox.h>
-
-#include "version.h"
-#include "resource.h"
-
-class CDropbox;
-
-#define DROPBOX_API_VER "/2"
-#define DROPBOX_WWW_URL "https://www.dropbox.com"
-#define DROPBOX_API "https://api.dropboxapi.com"
-#define DROPBOX_API_RPC DROPBOX_API DROPBOX_API_VER
-#define DROPBOX_CONTENT "https://content.dropboxapi.com"
-#define DROPBOX_API_CU DROPBOX_CONTENT DROPBOX_API_VER
-
-#define DROPBOX_APP_KEY "fa8du7gkf2q8xzg"
-#include "../../../miranda-private-keys/Dropbox/secret_key.h"
-
-class DropboxException
-{
- CMStringA message;
-
-public:
- DropboxException(const char *message) :
- message(message)
- {
- }
-
- const char* what() const throw()
- {
- return message.c_str();
- }
-};
-
-#define MODULE "Dropbox"
-
-#include "dropbox_options.h"
-#include "http_request.h"
-#include "api/account.h"
-#include "api/upload.h"
-#include "api/operations.h"
-#include "file_transfer.h"
-#include "dropbox.h"
-
-extern HINSTANCE g_hInstance;
-
-#define DROPBOX_FILE_CHUNK_SIZE 1024 * 1024 //1 MB
-
-#define BBB_ID_FILE_SEND 10001
-
-// icons
-void InitializeIcons();
-HANDLE GetIconHandleByName(const char *name);
-HICON LoadIconEx(int iconId, bool big = false);
-
-#endif //_COMMON_H_ \ No newline at end of file
diff --git a/plugins/Dropbox/src/version.h b/plugins/Dropbox/src/version.h
deleted file mode 100644
index aaec775b44..0000000000
--- a/plugins/Dropbox/src/version.h
+++ /dev/null
@@ -1,14 +0,0 @@
-#define __MAJOR_VERSION 0
-#define __MINOR_VERSION 12
-#define __RELEASE_NUM 2
-#define __BUILD_NUM 4
-
-#include <stdver.h>
-
-#define __PLUGIN_NAME "Dropbox"
-#define __FILENAME "Dropbox.dll"
-#define __DESCRIPTION "Allows you to transfer files via Dropbox."
-#define __AUTHOR "Miranda NG Team"
-#define __AUTHOREMAIL ""
-#define __AUTHORWEB "https://miranda-ng.org/p/Dropbox/"
-#define __COPYRIGHT "© 2014-17 Miranda NG project"
diff --git a/plugins/SmileyAdd/SmileyAdd.vcxproj b/plugins/SmileyAdd/SmileyAdd.vcxproj
index 51e6354a80..68cab8ea78 100644
--- a/plugins/SmileyAdd/SmileyAdd.vcxproj
+++ b/plugins/SmileyAdd/SmileyAdd.vcxproj
@@ -18,6 +18,11 @@
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\..\libs\Pcre16\pcre16.vcxproj">
+ <Project>{6124e997-426e-4a0b-9617-d6d577d5e7d7}</Project>
+ </ProjectReference>
+ </ItemGroup>
<PropertyGroup Label="Globals">
<ProjectName>SmileyAdd</ProjectName>
<ProjectGuid>{5BBA7E51-B494-4462-BC4F-1AE5F57F9857}</ProjectGuid>
@@ -30,9 +35,4 @@
<DisableSpecificWarnings>4458;%(DisableSpecificWarnings)</DisableSpecificWarnings>
</ClCompile>
</ItemDefinitionGroup>
- <ItemGroup>
- <ClCompile Include="src\regexp\*.cpp">
- <PrecompiledHeaderFile>..\stdafx.h</PrecompiledHeaderFile>
- </ClCompile>
- </ItemGroup>
</Project> \ No newline at end of file
diff --git a/plugins/SmileyAdd/src/download.cpp b/plugins/SmileyAdd/src/download.cpp
index a305436364..7633dffab0 100644
--- a/plugins/SmileyAdd/src/download.cpp
+++ b/plugins/SmileyAdd/src/download.cpp
@@ -158,18 +158,13 @@ void __cdecl SmileyDownloadThread(void*)
bool GetSmileyFile(CMStringW &url, const CMStringW &packstr)
{
- _TPattern *urlsplit = _TPattern::compile(L".*/(.*)");
- _TMatcher *m0 = urlsplit->createWCMatcher(url);
-
- m0->findFirstMatch();
+ MRegexp16 urlsplit(L".*/(.*)");
+ urlsplit.match(url);
CMStringW filename;
filename.AppendFormat(L"%s\\%s\\", cachepath, packstr.c_str());
int pathpos = filename.GetLength();
- filename += m0->getGroup(1);
-
- delete m0;
- delete urlsplit;
+ filename += urlsplit.getGroup(1);
bool needext = filename.Find('.') == -1;
if (needext)
diff --git a/plugins/SmileyAdd/src/options.cpp b/plugins/SmileyAdd/src/options.cpp
index b0fd12b50b..780c06c131 100644
--- a/plugins/SmileyAdd/src/options.cpp
+++ b/plugins/SmileyAdd/src/options.cpp
@@ -482,9 +482,9 @@ bool OptionsDialogType::BrowseForSmileyPacks(int item)
wchar_t filter[512], *pfilter;
mir_wstrcpy(filter, TranslateT("Smiley packs"));
- mir_wstrcat(filter, L" (*.msl;*.asl;*.xep)");
+ mir_wstrcat(filter, L" (*.msl;*.asl)");
pfilter = filter + mir_wstrlen(filter) + 1;
- mir_wstrcpy(pfilter, L"*.msl;*.asl;*.xep");
+ mir_wstrcpy(pfilter, L"*.msl;*.asl");
pfilter = pfilter + mir_wstrlen(pfilter) + 1;
mir_wstrcpy(pfilter, TranslateT("All files"));
mir_wstrcat(pfilter, L" (*.*)");
diff --git a/plugins/SmileyAdd/src/regexp/WCMatcher.cpp b/plugins/SmileyAdd/src/regexp/WCMatcher.cpp
deleted file mode 100644
index 12c1c0d4bd..0000000000
--- a/plugins/SmileyAdd/src/regexp/WCMatcher.cpp
+++ /dev/null
@@ -1,181 +0,0 @@
-#include "../stdafx.h"
-
-const int WCMatcher::MATCH_ENTIRE_STRING = 0x01;
-
-/*
- Detailed documentation is provided in this class' header file
-
- @author Jeffery Stuart
- @since November 2004
- @version 1.07.00
- */
-
-WCMatcher::WCMatcher(WCPattern *pattern, const CMStringW &text)
-{
- pat = pattern;
- str = &text;
- gc = pattern->groupCount;
- ncgc = -pattern->nonCapGroupCount;
- flags = 0;
- matchedSomething = false;
- starts = new int[gc + ncgc];
- ends = new int[gc + ncgc];
- groups = new int[gc + ncgc];
- groupPos = new int[gc + ncgc];
- groupIndeces = new int[gc + ncgc];
- starts = starts + ncgc;
- ends = ends + ncgc;
- groups = groups + ncgc;
- groupPos = groupPos + ncgc;
- groupIndeces = groupIndeces + ncgc;
- for (int i = 0; i < gc; ++i) starts[i] = ends[i] = 0;
-}
-
-WCMatcher::~WCMatcher()
-{
- delete[](starts - ncgc);
- delete[](ends - ncgc);
- delete[](groups - ncgc);
- delete[](groupIndeces - ncgc);
- delete[](groupPos - ncgc);
-}
-
-void WCMatcher::clearGroups()
-{
- int i;
- lm = 0;
- for (i = 0; i < gc; ++i) groups[i] = starts[i] = ends[i] = -1;
- for (i = 1; i <= ncgc; ++i) groups[0 - i] = starts[0 - i] = ends[0 - i] = -1;
-}
-
-CMStringW WCMatcher::replaceWithGroups(const CMStringW &pStr)
-{
- CMStringW ret;
-
- CMStringW t = pStr;
- while (t.GetLength() > 0) {
- if (t[0] == '\\') {
- t.Delete(0);
- if (t.GetLength() == 0)
- ret += L"\\";
- else if (t[0] < '0' || t[0] > '9') {
- ret += t[0];
- t.Delete(0);
- }
- else {
- int gn = 0;
- while (t.GetLength() > 0 && t[0] >= '0' && t[0] <= '9')
- {
- gn = gn * 10 + (t[0] - '0');
- t.Delete(0);
- }
- ret += getGroup(gn);
- }
- }
- else {
- ret += t[0];
- t.Delete(0);
- }
- }
-
- return ret;
-}
-
-unsigned long WCMatcher::getFlags() const
-{
- return flags;
-}
-
-const CMStringW& WCMatcher::getText() const
-{
- return *str;
-}
-
-bool WCMatcher::matches()
-{
- flags = MATCH_ENTIRE_STRING;
- matchedSomething = false;
- clearGroups();
- lm = 0;
- return pat->head->match(*str, this, 0) == str->GetLength();
-}
-
-bool WCMatcher::findFirstMatch()
-{
- starts[0] = 0;
- flags = 0;
- clearGroups();
- start = 0;
- lm = 0;
- ends[0] = pat->head->match(*str, this, 0);
- if (ends[0] >= 0) {
- matchedSomething = true;
- return 1;
- }
- return 0;
-}
-
-bool WCMatcher::findNextMatch()
-{
- int s = starts[0], e = ends[0];
-
- if (!matchedSomething) return findFirstMatch();
- if (s == e) ++e;
- flags = 0;
- clearGroups();
-
- starts[0] = e;
- if (e >= str->GetLength()) return 0;
- start = e;
- lm = e;
- ends[0] = pat->head->match(*str, this, e);
- return ends[0] >= 0;
-}
-
-std::vector<CMStringW> WCMatcher::findAll()
-{
- std::vector<CMStringW> ret;
- reset();
- while (findNextMatch())
- ret.push_back(getGroup());
-
- return ret;
-}
-
-void WCMatcher::reset()
-{
- lm = 0;
- clearGroups();
- matchedSomething = false;
-}
-
-int WCMatcher::getStartingIndex(const int groupNum) const
-{
- if (groupNum < 0 || groupNum >= gc)
- return -1;
- return starts[groupNum];
-}
-
-int WCMatcher::getEndingIndex(const int groupNum) const
-{
- if (groupNum < 0 || groupNum >= gc)
- return -1;
- return ends[groupNum];
-}
-
-CMStringW WCMatcher::getGroup(const int groupNum) const
-{
- if (groupNum < 0 || groupNum >= gc) return L"";
- if (starts[groupNum] < 0 || ends[groupNum] < 0) return L"";
- return str->Mid(starts[groupNum], ends[groupNum] - starts[groupNum]);
-}
-
-std::vector<CMStringW> WCMatcher::getGroups(const bool includeGroupZero) const
-{
- std::vector<CMStringW> ret;
-
- for (int i = (includeGroupZero ? 0 : 1); i < gc; ++i)
- ret.push_back(getGroup(i));
-
- return ret;
-}
diff --git a/plugins/SmileyAdd/src/regexp/WCMatcher.h b/plugins/SmileyAdd/src/regexp/WCMatcher.h
deleted file mode 100644
index 285a49c349..0000000000
--- a/plugins/SmileyAdd/src/regexp/WCMatcher.h
+++ /dev/null
@@ -1,230 +0,0 @@
-#ifndef __WCMATCHER_H__
-#define __WCMATCHER_H__
-
-/**
- A matcher is a non thread-safe object used to scan strings using a given
- {@link WCPattern WCPattern} object. Using a <code>WCMatcher</code> is the preferred
- method for scanning strings. WCMatchers are not thread-safe. WCMatchers require
- very little dynamic memory, hence one is encouraged to create several
- instances of a matcher when necessary as opposed to sharing a single instance
- of a matcher.
- <p>
- The most common methods needed by the matcher are <code>matches</code>,
- <code>findNextMatch</code>, and <code>getGroup</code>. <code>matches</code>
- and <code>findNextMatch</code> both return success or failure, and further
- details can be gathered from their documentation.
- <p>
- Unlike Java's <code>WCMatcher</code>, this class allows you to change the string
- you are matching against. This provides a small optimization, since you no
- longer need multiple matchers for a single pattern in a single thread.
- <p>
- This class also provides an extremely handy method for replacing text with
- captured data via the <code>replaceWithGroups</code> method. A typical
- invocation looks like:
- <pre>
- wchar_t buf[10000];
- CMStringW str = "\\5 (user name \\1) uses \\7 for his/her shell and \\6 is their home directory";
- FILE * fp = fopen("/etc/passwd", "r");
- WCPattern::registerWCPattern("entry", "[^:]+");
- WCPattern * p = WCPattern::compile("^({entry}):({entry}):({entry}):({entry}):({entry}):({entry}):({entry})$",
- &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;WCPattern::MULTILINE_MATCHING | WCPattern::UNIX_LINE_MODE);
- WCMatcher * m = p->createWCMatcher("");
- while (fgets(buf, 9999, fp))
- {
- &nbsp;&nbsp;m->setString(buf);
- &nbsp;&nbsp;if (m->matches())
- &nbsp;&nbsp;{
- &nbsp;&nbsp;&nbsp;&nbsp;printf("%s\n", m->replaceWithGroups(str).c_str());
- &nbsp;&nbsp;}
- }
- fclose(fp);
-
- </pre>
- Calling any of the following functions before first calling
- <code>matches</code>, <code>findFirstMatch</code>, or
- <code>findNextMatch</code> results in undefined behavior and may cause your
- program to crash.
- <code>
- <ul>
- <li>replaceWithGroups</code>
- <li>getStartingIndex</li>
- <li>getEndingIndex</li>
- <li>getGroup</li>
- <li>getGroups</li>
- </ul>
- </code>
- <p>
- The function <code>findFirstMatch</code> will attempt to find the first match
- in the input string. The same results can be obtained by first calling
- <code>reset</code> followed by <code>findNextMatch</code>.
- <p>
- To eliminate the necessity of looping through a string to find all the
- matching substrings, <code>findAll</code> was created. The function will find
- all matching substrings and return them in a <code>vector</code>. If you need
- to examine specific capture groups within the substrings, then this method
- should not be used.
-
- @author Jeffery Stuart
- @since March 2003, Stable Since November 2004
- @version 1.05.00
- @memo Mutable object used on instances of a WCPattern class
- */
-class WCMatcher
-{
- friend class NFAUNode;
- friend class NFAStartUNode;
- friend class NFAEndUNode;
- friend class NFAGroupHeadUNode;
- friend class NFAGroupLoopUNode;
- friend class NFAGroupLoopPrologueUNode;
- friend class NFAGroupTailUNode;
- friend class NFALookBehindUNode;
- friend class NFAStartOfLineUNode;
- friend class NFAEndOfLineUNode;
- friend class NFAEndOfMatchUNode;
- friend class NFAReferenceUNode;
- friend class WCPattern;
- private:
- /**
- Creates a new matcher object against <code>text</code> using
- <code>pattern</code>.
-
- @param pattern The pattern with which to search
- @param text The text in which to search
- */
- WCMatcher(WCPattern *pattern, const CMStringW & ext);
- protected:
- /// The pattern we use to match
- WCPattern *pat;
- /// The string in which we are matching
- const CMStringW *str;
- /// The starting point of our match
- int start;
- /// An array of the starting positions for each group
- int *starts;
- /// An array of the ending positions for each group
- int *ends;
- /// An array of private data used by NFAUNodes during matching
- int *groups;
- /// An array of private data used by NFAUNodes during matching
- int *groupIndeces;
- /// An array of private data used by NFAUNodes during matching
- int *groupPos;
- /// The ending index of the last match
- int lm;
- /// The number of capturing groups we have
- int gc;
- /// The number of non-capturing groups we havew
- int ncgc;
- /// Whether or not we have matched something (used only by findFirstMatch and findNextMatch)
- int matchedSomething;
- /// The flags with which we were made
- unsigned long flags;
- /// Called by reset to clear the group arrays
- void clearGroups();
- public:
- /// Used internally by match to signify we want the entire string matched
- const static int MATCH_ENTIRE_STRING;
- public:
- /// Cleans up the dynamic memory used by this matcher
- ~WCMatcher();
- /**
- Replaces the contents of <code>str</code> with the appropriate captured
- text. <code>str</code> should have at least one back reference, otherwise
- this function does nothing.
- @param str The string in which to replace text
- @return A string with all backreferences appropriately replaced
- */
- CMStringW replaceWithGroups(const CMStringW & str);
- /**
- The flags currently being used by the matcher.
- @return Zero
- */
- unsigned long getFlags() const;
- /**
- The text being searched by the matcher.
- @return the text being searched by the matcher.
- */
- const CMStringW& getText() const;
-
- /**
- Scans the string from start to finish for a match. The entire string must
- match for this function to return success. Group variables are
- appropriately set and can be queried after this function returns.
-
- @return Success if and only if the entire string matches the pattern
- */
- bool matches();
- /**
- Scans the string for the first substring matching the pattern. The entire
- string does not necessarily have to match for this function to return
- success. Group variables are appropriately set and can be queried after
- this function returns.
-
- @return Success if any substring matches the specified pattern
- */
- bool findFirstMatch();
- /**
- Scans the string for the next substring matching the pattern. If no calls
- have been made to findFirstMatch of findNextMatch since the last call to
- reset, matches, or setString, then this function's behavior results to
- that of findFirstMatch.
-
- @return Success if another substring can be found that matches the pattern
- */
- bool findNextMatch();
- /**
- Returns a vector of every substring in order which matches the given
- pattern.
-
- @return Every substring in order which matches the given pattern
- */
- std::vector<CMStringW> findAll();
- /**
- Resets the internal state of the matcher
- */
- void reset();
- /**
- Same as getText. Left n for backwards compatibilty with old source code
- @return Returns the string that is currently being used for matching
- */
- inline const CMStringW& getString() const { return *str; }
- /**
- Sets the string to scan
- @param newStr The string to scan for subsequent matches
- */
- inline void setString(const CMStringW & newStr) { str = &newStr; reset(); }
-
- /**
- Returns the starting index of the specified group.
- @param groupNum The group to query
- @return The starting index of the group if it was matched, -1 for an
- invalid group or if the group was not matched
- */
- int getStartingIndex(const int groupNum = 0) const;
- /**
- Returns the ending index of the specified group.
- @param groupNum The group to query
- @return The ending index of the group if it was matched, -1 for an
- invalid group or if the group was not matched
- */
- int getEndingIndex(const int groupNum = 0) const;
- /**
- Returns the specified group. An empty string ("") does not necessarily
- mean the group was not matched. A group such as (a*b?) could be matched by
- a zero length. If an empty string is returned, getStartingIndex can be
- called to determine if the group was actually matched.
- @param groupNum The group to query
- @return The text of the group
- */
- CMStringW getGroup(const int groupNum = 0) const;
- /**
- Returns every capture group in a vector
-
- @param includeGroupZero Whether or not include capture group zero
- @return Every capture group
- */
- std::vector<CMStringW> getGroups(const bool includeGroupZero = 0) const;
-};
-
-#endif
diff --git a/plugins/SmileyAdd/src/regexp/WCPattern.cpp b/plugins/SmileyAdd/src/regexp/WCPattern.cpp
deleted file mode 100644
index e2b99b6f3e..0000000000
--- a/plugins/SmileyAdd/src/regexp/WCPattern.cpp
+++ /dev/null
@@ -1,1668 +0,0 @@
-/**
- From the author (Jeff Stuart)
- "
- Let me start by saying this file is pretty big. If you feel up to it, you can
- try making changes yourself, but you would be better off to just email me at
- stuart@cs.ucdavis.edu if you think there is a bug, or have something useful you
- would like added. This project is very "near and dear" to me, so I am fairly quick
- to make bug fixes. The header files for WCPattern and WCMatcher are fairly well
- documented and the function names are pretty self-explanatory, but if you are having
- any trouble, feel free to email me at stuart@cs.ucdavis.edu.
-
- If you email me, make sure you put something like C++RE in the subject because
- I tend to delete email if I don't recognize the name and the subject is
- something like "I Need Your Help" or "Got A Second" or "I Found It".
- "
- */
-
-/*
- Detailed documentation is provided in this class' header file
-
- @author Jeffery Stuart
- @since November 2004
- @version 1.07.00
- */
-
-#include "../stdafx.h"
-
-std::map<CMStringW, WCPattern *> WCPattern::compiledWCPatterns;
-std::map<CMStringW, std::pair<CMStringW, unsigned long> > WCPattern::registeredWCPatterns;
-
-const int WCPattern::MIN_QMATCH = 0x00000000;
-const int WCPattern::MAX_QMATCH = 0x7FFFFFFF;
-
-const unsigned long WCPattern::CASE_INSENSITIVE = 0x01;
-const unsigned long WCPattern::LITERAL = 0x02;
-const unsigned long WCPattern::DOT_MATCHES_ALL = 0x04;
-const unsigned long WCPattern::MULTILINE_MATCHING = 0x08;
-const unsigned long WCPattern::UNIX_LINE_MODE = 0x10;
-
-#define to_lower(a) (wchar_t)(UINT_PTR)CharLowerW((LPWSTR)(unsigned)a)
-#define is_alpha IsCharAlphaW
-
-#if defined(_WIN32)
-#define str_icmp mir_wstrcmpi
-#elif defined(__CYGWIN__) || defined(__APPLE__)
-#include <wctype.h>
-static inline int str_icmp(const wchar_t *a, const wchar_t *b)
-{
- while (*a && *b) {
- const int t = (int)towlower(*a) - (int)tolower(*b);
- if (t) return t;
- ++a; ++b;
- }
- if (*a) {
- if (*b) return (int)towlower(*a) - (int)tolower(*b);
- return 1;
- }
- else if (*b) return 1;
- return 0;
-}
-#else
-#define str_icmp wcscasecmp
-#endif
-
-WCPattern::WCPattern(const CMStringW &rhs)
-{
- matcher = nullptr;
- pattern = rhs;
- curInd = 0;
- groupCount = 0;
- nonCapGroupCount = 0;
- error = 0;
- head = nullptr;
-}
-
-// convenient function in case we want to add any extra debugging output
-void WCPattern::raiseError()
-{
- error = 1;
-}
-
-NFAUNode *WCPattern::registerNode(NFAUNode *node)
-{
- nodes[node] = 1;
- return node;
-}
-
-CMStringW WCPattern::classUnion(CMStringW s1, CMStringW s2) const
-{
- wchar_t *out = new wchar_t[66000];
- std::sort((LPTSTR)s1.GetString(), (LPTSTR)s1.GetTail());
- std::sort((LPTSTR)s2.GetString(), (LPTSTR)s2.GetTail());
- wchar_t *p = std::set_union(s1.GetString(), s1.GetTail(), s2.GetString(), s2.GetTail(), out); *p = 0;
- CMStringW ret = out;
- delete[] out;
- return ret;
-}
-
-CMStringW WCPattern::classIntersect(CMStringW s1, CMStringW s2) const
-{
- wchar_t *out = new wchar_t[66000];
- std::sort((LPTSTR)s1.GetString(), (LPTSTR)s1.GetTail());
- std::sort((LPTSTR)s2.GetString(), (LPTSTR)s2.GetTail());
- *std::set_intersection(s1.GetString(), s1.GetTail(), s2.GetString(), s2.GetTail(), out) = 0;
- CMStringW ret = out;
- delete[] out;
- return ret;
-}
-
-CMStringW WCPattern::classNegate(CMStringW s1) const
-{
- wchar_t *out = new wchar_t[66000];
- int i, ind = 0;
- std::map<wchar_t, bool> m;
-
- for (i = 0; i < s1.GetLength(); ++i) m[s1[i]] = 1;
- for (i = 0xFF; i >= 0; --i) if (m.find((wchar_t)i) == m.end()) out[ind++] = (wchar_t)i;
- out[ind] = 0;
- CMStringW ret(out, ind);
- delete[] out;
- return ret;
-}
-
-CMStringW WCPattern::classCreateRange(wchar_t low, wchar_t hi) const
-{
- wchar_t out[300];
- int ind = 0;
- while (low != hi) out[ind++] = low++;
- out[ind++] = low;
- return CMStringW(out, ind);
-}
-
-int WCPattern::getInt(int start, int end)
-{
- int ret = 0;
- for (; start <= end; ++start) ret = ret * 10 + (pattern[start] - '0');
- return ret;
-}
-
-bool WCPattern::quantifyCurly(int &sNum, int &eNum)
-{
- bool good = 1;
- int i, ci = curInd + 1;
- int commaInd = ci, endInd = ci, len = pattern.GetLength();
- sNum = eNum = 0;
-
- while (endInd < len && pattern[endInd] != '}') ++endInd;
- while (commaInd < endInd && pattern[commaInd] != ',') ++commaInd;
- if (endInd >= len) { raiseError(); return 0; }
- for (i = ci; good && i < endInd; ++i) if (i != commaInd && !isdigit(pattern[i])) good = 0;
- if (!good && commaInd < endInd) { raiseError(); return 0; }
- if (!good) return 0;
- /* so now everything in here is either a comma (and there is at most one comma) or a digit */
- if (commaInd == ci) // {,*}
- {
- if (endInd == commaInd + 1) { sNum = MIN_QMATCH; eNum = MAX_QMATCH; } // {,} = *
- else { sNum = MIN_QMATCH; eNum = getInt(commaInd + 1, endInd - 1); } // {,+}
- }
- else if (commaInd == endInd - 1) { sNum = getInt(ci, commaInd - 1); eNum = MAX_QMATCH; } // {+,}
- else if (commaInd == endInd) { sNum = getInt(ci, endInd - 1); eNum = sNum; } // {+}
- else { sNum = getInt(ci, commaInd - 1); eNum = getInt(commaInd + 1, endInd - 1); } // {+,+}
- curInd = endInd + 1;
- return 1;
-}
-
-NFAUNode* WCPattern::quantifyGroup(NFAUNode *start, NFAUNode *stop, const int gn)
-{
- NFAUNode *newNode = nullptr;
- int type = 0;
-
- if (curInd < pattern.GetLength()) {
- wchar_t ch = (curInd + 1 >= pattern.GetLength()) ? USHRT_MAX : pattern[curInd + 1];
- switch (pattern[curInd]) {
- case '*':
- ++curInd;
- switch (ch) {
- case '?': ++curInd; type = 1; break;
- case '+': ++curInd; type = 2; break;
- }
- newNode = registerNode(new NFAGroupLoopPrologueUNode(gn));
- newNode->next = registerNode(new NFAGroupLoopUNode(start, MIN_QMATCH, MAX_QMATCH, gn, type));
- stop->next = newNode->next;
- return newNode;
- case '?':
- ++curInd;
- switch (ch) {
- case '?': ++curInd; type = 1; break;
- case '+': ++curInd; type = 2; break;
- }
- newNode = registerNode(new NFAGroupLoopPrologueUNode(gn));
- newNode->next = registerNode(new NFAGroupLoopUNode(start, MIN_QMATCH, 1, gn, type));
- stop->next = newNode->next;
- return newNode;
- case '+':
- ++curInd;
- switch (ch) {
- case '?': ++curInd; type = 1; break;
- case '+': ++curInd; type = 2; break;
- }
- newNode = registerNode(new NFAGroupLoopPrologueUNode(gn));
- newNode->next = registerNode(new NFAGroupLoopUNode(start, 1, MAX_QMATCH, gn, type));
- stop->next = newNode->next;
- return newNode;
- case '{':
- {
- int s, e;
- if (quantifyCurly(s, e)) {
- ch = (curInd < pattern.GetLength()) ? pattern[curInd] : USHRT_MAX;
- switch (ch) {
- case '?': ++curInd; type = 1; break;
- case '+': ++curInd; type = 2; break;
- }
- newNode = registerNode(new NFAGroupLoopPrologueUNode(gn));
- newNode->next = registerNode(new NFAGroupLoopUNode(start, s, e, gn, type));
- stop->next = newNode->next;
- return newNode;
- }
- }
- }
- }
- return nullptr;
-}
-
-NFAUNode* WCPattern::quantify(NFAUNode *newNode)
-{
- if (curInd < pattern.GetLength()) {
- wchar_t ch = (curInd + 1 >= pattern.GetLength()) ? USHRT_MAX : pattern[curInd + 1];
- switch (pattern[curInd]) {
- case '*':
- ++curInd;
- switch (ch) {
- case '?': ++curInd; newNode = registerNode(new NFALazyQuantifierUNode(this, newNode, MIN_QMATCH, MAX_QMATCH)); break;
- case '+': ++curInd; newNode = registerNode(new NFAPossessiveQuantifierUNode(this, newNode, MIN_QMATCH, MAX_QMATCH)); break;
- default: newNode = registerNode(new NFAGreedyQuantifierUNode(this, newNode, MIN_QMATCH, MAX_QMATCH)); break;
- }
- break;
- case '?':
- ++curInd;
- switch (ch) {
- case '?': ++curInd; newNode = registerNode(new NFALazyQuantifierUNode(this, newNode, MIN_QMATCH, 1)); break;
- case '+': ++curInd; newNode = registerNode(new NFAPossessiveQuantifierUNode(this, newNode, MIN_QMATCH, 1)); break;
- default: newNode = registerNode(new NFAGreedyQuantifierUNode(this, newNode, MIN_QMATCH, 1)); break;
- }
- break;
- case '+':
- ++curInd;
- switch (ch) {
- case '?': ++curInd; newNode = registerNode(new NFALazyQuantifierUNode(this, newNode, 1, MAX_QMATCH)); break;
- case '+': ++curInd; newNode = registerNode(new NFAPossessiveQuantifierUNode(this, newNode, 1, MAX_QMATCH)); break;
- default: newNode = registerNode(new NFAGreedyQuantifierUNode(this, newNode, 1, MAX_QMATCH)); break;
- }
- break;
- case '{':
- int s, e;
- if (quantifyCurly(s, e)) {
- ch = (curInd < pattern.GetLength()) ? pattern[curInd] : USHRT_MAX;
- switch (ch) {
- case '?': ++curInd; newNode = registerNode(new NFALazyQuantifierUNode(this, newNode, s, e)); break;
- case '+': ++curInd; newNode = registerNode(new NFAPossessiveQuantifierUNode(this, newNode, s, e)); break;
- default: newNode = registerNode(new NFAGreedyQuantifierUNode(this, newNode, s, e)); break;
- }
- }
- break;
- }
- }
- return newNode;
-}
-
-CMStringW WCPattern::parseClass()
-{
- CMStringW t, ret;
- wchar_t ch, c1, c2;
- bool inv = 0, neg = 0, quo = 0;
-
- if (curInd < pattern.GetLength() && pattern[curInd] == '^') {
- ++curInd;
- neg = 1;
- }
-
- while (curInd < pattern.GetLength() && pattern[curInd] != ']') {
- ch = pattern[curInd++];
- if (ch == '[') {
- t = parseClass();
- ret = classUnion(ret, t);
- }
- else if (ch == '&' && curInd < pattern.GetLength() && pattern[curInd] == '&') {
- if (pattern[++curInd] != '[') {
- raiseError();
- curInd = pattern.GetLength();
- }
- else {
- ++curInd;
- t = parseClass();
- ret = classIntersect(ret, t);
- }
- }
- else if (ch == '\\') {
- t = parseEscape(inv, quo);
- if (quo) {
- raiseError();
- curInd = pattern.GetLength();
- }
- else if (inv || t.GetLength() > 1) { // cant be part of a range (a-z)
- if (inv) t = classNegate(t);
- ret = classUnion(ret, t);
- }
- else if (curInd < pattern.GetLength() && pattern[curInd] == '-') { // part of a range (a-z)
- c1 = t[0];
- ++curInd;
- if (curInd >= pattern.GetLength()) raiseError();
- else {
- c2 = pattern[curInd++];
- if (c2 == '\\') {
- t = parseEscape(inv, quo);
- if (quo) {
- raiseError();
- curInd = pattern.GetLength();
- }
- else if (inv || t.GetLength() > 1) raiseError();
- else ret = classUnion(ret, classCreateRange(c1, c2));
- }
- else if (c2 == '[' || c2 == ']' || c2 == '-' || c2 == '&') {
- raiseError();
- curInd = pattern.GetLength();
- }
- else ret = classUnion(ret, classCreateRange(c1, c2));
- }
- }
- else ret = classUnion(ret, t);
- }
- else if (curInd < pattern.GetLength() && pattern[curInd] == '-') {
- c1 = ch;
- ++curInd;
- if (curInd >= pattern.GetLength()) raiseError();
- else {
- c2 = pattern[curInd++];
- if (c2 == '\\') {
- t = parseEscape(inv, quo);
- if (quo) {
- raiseError();
- curInd = pattern.GetLength();
- }
- else if (inv || t.GetLength() > 1) raiseError();
- else ret = classUnion(ret, classCreateRange(c1, c2));
- }
- else if (c2 == '[' || c2 == ']' || c2 == '-' || c2 == '&') {
- raiseError();
- curInd = pattern.GetLength();
- }
- else ret = classUnion(ret, classCreateRange(c1, c2));
- }
- }
- else ret.AppendChar(ch);
- }
-
- if (curInd >= pattern.GetLength() || pattern[curInd] != ']') {
- raiseError();
- ret = L"";
- }
- else {
- ++curInd;
- if (neg) ret = classNegate(ret);
- }
- return ret;
-}
-
-CMStringW WCPattern::parsePosix()
-{
- CMStringW s7 = pattern.Mid(curInd, 7);
- if (s7 == L"{Lower}") { curInd += 7; return L"abcdefghijklmnopqrstuvwxyz"; }
- if (s7 == L"{Upper}") { curInd += 7; return L"ABCDEFGHIJKLMNOPQRSTUVWXYZ"; }
- if (s7 == L"{Alpha}") { curInd += 7; return L"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; }
- if (s7 == L"{Digit}") { curInd += 7; return L"0123456789"; }
- if (s7 == L"{Alnum}") { curInd += 7; return L"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; }
- if (s7 == L"{Punct}") { curInd += 7; return L"!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~"; }
- if (s7 == L"{Graph}") { curInd += 7; return L"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~"; }
- if (s7 == L"{Print}") { curInd += 7; return L"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~"; }
- if (s7 == L"{Blank}") { curInd += 7; return L" \t"; }
- if (s7 == L"{Space}") { curInd += 7; return L" \t\n\x0B\f\r"; }
- if (s7 == L"{Cntrl}") {
- CMStringW s(' ', 32 + 1);
- for (int i = 0; i <= 0x1F; ++i)
- s.SetAt(i, i);
- s.SetAt(0x20, 0x7F);
- curInd += 7;
- return s;
- }
- if (s7 == L"{ASCII}") {
- CMStringW s(' ', 0x80);
- for (int i = 0; i <= 0x7f; ++i) s.SetAt(i, i);
- curInd += 7;
- return s;
- }
- if (pattern.Mid(curInd, 8) == L"{XDigit}") { curInd += 8; return L"abcdefABCDEF0123456789"; }
- raiseError();
- return L"";
-}
-
-NFAUNode* WCPattern::parseBackref()
-{
- #define is_dig(x) ((x) >= '0' && (x) <= '9')
- #define to_int(x) ((x) - '0')
- int ci = curInd;
- int oldRef = 0, ref = 0;
-
- while (ci < pattern.GetLength() && is_dig(pattern[ci]) && (ref < 10 || ref < groupCount)) {
- oldRef = ref;
- ref = ref * 10 + to_int(pattern[ci++]);
- }
- if (ci == pattern.GetLength()) {
- oldRef = ref;
- ++ci;
- }
- if (oldRef < 0 || ci <= curInd) {
- raiseError();
- return registerNode(new NFAReferenceUNode(-1));
- }
- curInd = ci;
- return registerNode(new NFAReferenceUNode(ref));
-
- #undef is_dig
- #undef to_int
-}
-
-CMStringW WCPattern::parseOctal()
-{
- #define islowoc(x) ((x) >= '0' && (x) <= '3')
- #define isoc(x) ((x) >= '0' && (x) <= '7')
- #define fromoc(x) ((x) - '0')
- int ci = curInd;
- wchar_t ch1 = (ci + 0 < pattern.GetLength()) ? pattern[ci + 0] : USHRT_MAX;
- wchar_t ch2 = (ci + 1 < pattern.GetLength()) ? pattern[ci + 1] : USHRT_MAX;
- wchar_t ch3 = (ci + 2 < pattern.GetLength()) ? pattern[ci + 2] : USHRT_MAX;
- CMStringW s = L" ";
-
- if (islowoc(ch1) && isoc(ch2)) {
- curInd += 2;
- s.SetAt(0, fromoc(ch1) * 8 + fromoc(ch2));
- if (isoc(ch3)) {
- ++curInd;
- s.SetAt(0, s[0] * 8 + fromoc(ch3));
- }
- }
- else if (isoc(ch1) && isoc(ch2)) {
- curInd += 2;
- s.SetAt(0, fromoc(ch1) * 8 + fromoc(ch2));
- }
- else raiseError();
-
- return s;
- #undef islowoc
- #undef isoc
- #undef fromoc
-}
-
-CMStringW WCPattern::parseHex()
-{
- #define to_low(x) (((x) >= 'A' && (x) <= 'Z') ? ((x) - 'A' + 'a') : (x))
- #define is_dig(x) ((x) >= '0' && (x) <= '9')
- #define is_hex(x) (is_dig(x) || (to_low(x) >= 'a' && to_low(x) <= 'f'))
- #define to_int(x) ((is_dig(x)) ? ((x) - '0') : (to_low(x) - 'a' + 10))
-
- int ci = curInd;
- wchar_t ch1 = (ci + 0 < pattern.GetLength()) ? pattern[ci + 0] : USHRT_MAX;
- wchar_t ch2 = (ci + 1 < pattern.GetLength()) ? pattern[ci + 1] : USHRT_MAX;
- wchar_t ch3 = (ci + 2 < pattern.GetLength()) ? pattern[ci + 2] : USHRT_MAX;
- wchar_t ch4 = (ci + 3 < pattern.GetLength()) ? pattern[ci + 3] : USHRT_MAX;
- CMStringW s = L" ";
-
- if (is_hex(ch1) && is_hex(ch2) && is_hex(ch3) && is_hex(ch4)) {
- curInd += 2;
- s.SetAt(0, (to_int(ch1) << 12 & 0xF000) | (to_int(ch2) << 8 & 0x0F00) |
- (to_int(ch3) << 4 & 0x0F00) | (to_int(ch4) & 0x000F));
- }
- else if (is_hex(ch1) && is_hex(ch2)) {
- curInd += 2;
- s.SetAt(0, (to_int(ch1) << 4 & 0xF0) | (to_int(ch2) & 0x0F));
- }
-
- return s;
- #undef to_low
- #undef is_dig
- #undef is_hex
- #undef to_int
-}
-
-CMStringW WCPattern::parseEscape(bool &inv, bool &quo)
-{
- wchar_t ch = pattern[curInd++];
- CMStringW classes;
-
- if (curInd > pattern.GetLength()) {
- raiseError();
- return "";
- }
-
- quo = 0;
- inv = 0;
- switch (ch) {
- case 'p': classes = parsePosix(); break;
- case 'P': classes = L"!!"; classes += parsePosix(); break;
- case 'd': classes = L"0123456789"; break;
- case 'D': classes = L"!!0123456789"; break;
- case 's': classes = L" \t\r\n\f"; break;
- case 'S': classes = L"!! \t\r\n\f"; break;
- case 'w': classes = L"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_"; break;
- case 'W': classes = L"!!abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_"; break;
- case '0': classes = parseOctal(); break;
- case 'x': classes = parseHex(); break;
-
- case 'Q': quo = 1; break;
- case 't': classes = L"\t"; break;
- case 'r': classes = L"\r"; break;
- case 'n': classes = L"\n"; break;
- case 'f': classes = L"\f"; break;
- case 'a': classes = L"\a"; break;
- case 'e': classes = L"\r"; break;
- default:
- classes.AppendChar(ch);
- break;
- }
-
- if (classes.Mid(0, 2) == L"!!") {
- classes = classes.Mid(2);
- inv = 1;
- }
- return classes;
-}
-
-NFAUNode* WCPattern::parseRegisteredWCPattern(NFAUNode **end)
-{
- int i, j;
- CMStringW s;
- NFAUNode *ret = nullptr;
- for (i = curInd; i < pattern.GetLength() && pattern[i] != '}'; ++i) {}
- if (pattern[i] != '}') { raiseError(); return nullptr; }
- if (i == curInd + 1) { raiseError(); return nullptr; } // {}
- if (!((pattern[curInd] >= 'a' && pattern[curInd] <= 'z') ||
- (pattern[curInd] >= 'A' && pattern[curInd] <= 'Z') ||
- (pattern[curInd] == '_'))) {
- raiseError();
- return nullptr;
- }
-
- for (j = curInd; !error && j < i; ++j) {
- if (!((pattern[j] >= 'a' && pattern[j] <= 'z') ||
- (pattern[j] >= 'A' && pattern[j] <= 'Z') ||
- (pattern[j] >= '0' && pattern[j] <= '9') ||
- (pattern[j] == '_'))) {
- raiseError();
- return nullptr;
- }
- }
- s = pattern.Mid(curInd, i - curInd);
- if (registeredWCPatterns.find(s) == registeredWCPatterns.end()) raiseError();
- else {
- unsigned long oflags = flags;
- CMStringW op = pattern;
- int ci = i + 1;
-
- pattern = registeredWCPatterns[s].first;
- curInd = 0;
- flags = registeredWCPatterns[s].second;
-
- --groupCount;
- ret = parse(0, 0, end);
-
- pattern = op;
- curInd = ci;
- flags = oflags;
- }
- if (error) { *end = ret = nullptr; }
- return ret;
-}
-
-// look behind should interpret everything as a literal (except \\) since the
-// pattern must have a concrete length
-NFAUNode* WCPattern::parseBehind(const bool pos, NFAUNode **end)
-{
- CMStringW t;
- while (curInd < pattern.GetLength() && pattern[curInd] != ')') {
- wchar_t ch = pattern[curInd++];
- if (ch == '\\') {
- if (curInd + 1 >= pattern.GetLength()) {
- raiseError();
- return *end = registerNode(new NFACharUNode(' '));
- }
- ch = pattern[curInd++];
- }
- t.AppendChar(ch);
- }
- if (curInd >= pattern.GetLength() || pattern[curInd] != ')') raiseError();
- else ++curInd;
- return *end = registerNode(new NFALookBehindUNode(t, pos));
-}
-
-NFAUNode* WCPattern::parseQuote()
-{
- bool done = 0;
- CMStringW s;
-
- while (!done) {
- if (curInd >= pattern.GetLength()) {
- raiseError();
- done = 1;
- }
- else if (pattern.Mid(curInd, 2) == L"\\E") {
- curInd += 2;
- done = 1;
- }
- else if (pattern[curInd] == '\\') {
- s.AppendChar(pattern[++curInd]);
- ++curInd;
- }
- else s.AppendChar(pattern[curInd++]);
- }
- if ((flags & WCPattern::CASE_INSENSITIVE) != 0)
- return registerNode(new NFACIQuoteUNode(s));
- return registerNode(new NFAQuoteUNode(s));
-}
-NFAUNode* WCPattern::parse(const bool inParen, const bool inOr, NFAUNode **end)
-{
- NFAUNode *start, *cur, *next = nullptr;
- CMStringW t;
- int grc = groupCount++;
- bool inv, quo;
- bool ahead = 0, pos = 0, noncap = 0, indep = 0;
- unsigned long oldFlags = flags;
-
- if (inParen) {
- if (pattern[curInd] == '?') {
- ++curInd;
- --groupCount;
- if (pattern[curInd] == ':') { noncap = 1; ++curInd; grc = --nonCapGroupCount; }
- else if (pattern[curInd] == '=') { ++curInd; ahead = 1; pos = 1; }
- else if (pattern[curInd] == '!') { ++curInd; ahead = 1; pos = 0; }
- else if (pattern.Mid(curInd, 2) == L"<=") { curInd += 2; return parseBehind(1, end); }
- else if (pattern.Mid(curInd, 2) == L"<!") { curInd += 2; return parseBehind(0, end); }
- else if (pattern[curInd] == '>') { ++curInd; indep = 1; }
- else {
- bool negate = false, done = false;
- while (!done) {
- if (curInd >= pattern.GetLength()) {
- raiseError();
- return nullptr;
- }
- else if (negate) {
- switch (pattern[curInd]) {
- case 'i': flags &= ~WCPattern::CASE_INSENSITIVE; break;
- case 'd': flags &= ~WCPattern::UNIX_LINE_MODE; break;
- case 'm': flags &= ~WCPattern::MULTILINE_MATCHING; break;
- case 's': flags &= ~WCPattern::DOT_MATCHES_ALL; break;
- case ':': done = true; break;
- case ')':
- ++curInd;
- *end = registerNode(new NFALookBehindUNode(L"", true));
- return *end;
- case '-':
- default:
- raiseError();
- return nullptr;
- }
- }
- else {
- switch (pattern[curInd]) {
- case 'i': flags |= WCPattern::CASE_INSENSITIVE; break;
- case 'd': flags |= WCPattern::UNIX_LINE_MODE; break;
- case 'm': flags |= WCPattern::MULTILINE_MATCHING; break;
- case 's': flags |= WCPattern::DOT_MATCHES_ALL; break;
- case ':': done = true; break;
- case '-': negate = true; break;
- case ')':
- ++curInd;
- *end = registerNode(new NFALookBehindUNode(L"", true));
- return *end;
- default:
- raiseError();
- return nullptr;
- }
- }
- ++curInd;
- }
- noncap = 1;
- grc = --nonCapGroupCount;
- }
-
- if (noncap) cur = start = registerNode(new NFAGroupHeadUNode(grc));
- else cur = start = registerNode(new NFASubStartUNode);
- }
- else cur = start = registerNode(new NFAGroupHeadUNode(grc));
- }
- else cur = start = registerNode(new NFASubStartUNode);
-
- while (curInd < pattern.GetLength()) {
- wchar_t ch = pattern[curInd++];
-
- next = nullptr;
- if (error) return nullptr;
- switch (ch) {
- case '^':
- if ((flags & WCPattern::MULTILINE_MATCHING) != 0) next = registerNode(new NFAStartOfLineUNode);
- else next = registerNode(new NFAStartOfInputUNode);
- break;
- case '$':
- if ((flags & WCPattern::MULTILINE_MATCHING) != 0) next = registerNode(new NFAEndOfLineUNode);
- else next = registerNode(new NFAEndOfInputUNode(0));
- break;
- case '|':
- --groupCount;
- cur->next = registerNode(new NFAAcceptUNode);
- cur = start = registerNode(new NFAOrUNode(start, parse(inParen, 1)));
- break;
- case '\\':
- if (curInd < pattern.GetLength()) {
- bool eoi = 0;
- switch (pattern[curInd]) {
- case '1':
- case '2':
- case '3':
- case '4':
- case '5':
- case '6':
- case '7':
- case '8':
- case '9': next = parseBackref(); break;
- case 'A': ++curInd; next = registerNode(new NFAStartOfInputUNode); break;
- case 'B': ++curInd; next = registerNode(new NFAWordBoundaryUNode(0)); break;
- case 'b': ++curInd; next = registerNode(new NFAWordBoundaryUNode(1)); break;
- case 'G': ++curInd; next = registerNode(new NFAEndOfMatchUNode); break;
- case 'Z': eoi = 1;
- case 'z': ++curInd; next = registerNode(new NFAEndOfInputUNode(eoi)); break;
- default:
- t = parseEscape(inv, quo);
- //printf("inv quo classes { %c %c %s }\n", inv ? 't' : 'f', quo ? 't' : 'f', t.c_str());
- if (!quo) {
- if (t.GetLength() > 1 || inv) {
- if ((flags & WCPattern::CASE_INSENSITIVE) != 0) next = registerNode(new NFACIClassUNode(t, inv));
- else next = registerNode(new NFAClassUNode(t, inv));
- }
- else next = registerNode(new NFACharUNode(t[0]));
- }
- else next = parseQuote();
- }
- }
- else raiseError();
- break;
- case '[':
- if ((flags & WCPattern::CASE_INSENSITIVE) == 0) {
- NFAClassUNode *clazz = new NFAClassUNode();
- CMStringW s = parseClass();
- for (int i = 0; i < (int)s.GetLength(); ++i) clazz->vals[s[i]] = 1;
- next = registerNode(clazz);
- }
- else {
- NFACIClassUNode *clazz = new NFACIClassUNode();
- CMStringW s = parseClass();
- for (int i = 0; i < s.GetLength(); ++i) clazz->vals[to_lower(s[i])] = 1;
- next = registerNode(clazz);
- }
- break;
- case '.':
- {
- bool useN = 1, useR = 1;
- NFAClassUNode *clazz = new NFAClassUNode(1);
- if ((flags & WCPattern::UNIX_LINE_MODE) != 0) useR = 0;
- if ((flags & WCPattern::DOT_MATCHES_ALL) != 0) useN = useR = 0;
- if (useN) clazz->vals['\n'] = 1;
- if (useR) clazz->vals['\r'] = 1;
- next = registerNode(clazz);
- }
- break;
- case '(':
- {
- NFAUNode *pEnd, *t1, *t2;
- t1 = parse(1, 0, &pEnd);
- if (!t1) raiseError();
- else if (t1->isGroupHeadNode() && (t2 = quantifyGroup(t1, pEnd, grc)) != nullptr) {
- cur->next = t2;
- cur = t2->next;
- }
- else {
- cur->next = t1;
- cur = pEnd;
- }
- }
- break;
- case ')':
- if (!inParen) raiseError();
- else if (inOr) {
- --curInd;
- cur = cur->next = registerNode(new NFAAcceptUNode);
- flags = oldFlags;
- return start;
- }
- else {
- if (ahead) {
- cur = cur->next = registerNode(new NFAAcceptUNode);
- flags = oldFlags;
- return *end = registerNode(new NFALookAheadUNode(start, pos));
- }
- else if (indep) {
- cur = cur->next = registerNode(new NFAAcceptUNode);
- flags = oldFlags;
- return *end = registerNode(new NFAPossessiveQuantifierUNode(this, start, 1, 1));
- }
- else { // capping or noncapping, it doesnt matter
- *end = cur = cur->next = registerNode(new NFAGroupTailUNode(grc));
- next = quantifyGroup(start, *end, grc);
- if (next) {
- start = next;
- *end = next->next;
- }
- flags = oldFlags;
- return start;
- }
- }
- break;
- case '{': // registered pattern
- cur->next = parseRegisteredWCPattern(&next);
- if (cur->next) cur = next;
- break;
- case '*':
- case '+':
- case '?':
- // case '}':
- // case ']':
- raiseError();
- break;
- default:
- if ((flags & WCPattern::CASE_INSENSITIVE) != 0) next = registerNode(new NFACICharUNode(ch));
- else next = registerNode(new NFACharUNode(ch));
- break;
- }
- if (next) cur = cur->next = quantify(next);
- }
- if (inParen) raiseError();
- else {
- if (inOr) cur = cur->next = registerNode(new NFAAcceptUNode);
- if (end) *end = cur;
- }
-
- flags = oldFlags;
- if (error) return nullptr;
-
- return start;
-}
-
-WCPattern* WCPattern::compile(const CMStringW &pattern, const unsigned long mode)
-{
- WCPattern *p = new WCPattern(pattern);
- NFAUNode *end;
-
- p->flags = mode;
- if ((mode & WCPattern::LITERAL) != 0) {
- p->head = p->registerNode(new NFAStartUNode);
- if ((mode & WCPattern::CASE_INSENSITIVE) != 0) p->head->next = p->registerNode(new NFACIQuoteUNode(pattern));
- else p->head->next = p->registerNode(new NFAQuoteUNode(pattern));
- p->head->next->next = p->registerNode(new NFAEndUNode);
- }
- else {
- p->head = p->parse(0, 0, &end);
- if (!p->head) {
- delete p;
- p = nullptr;
- }
- else {
- if (!(p->head && p->head->isStartOfInputNode())) {
- NFAUNode *n = p->registerNode(new NFAStartUNode);
- n->next = p->head;
- p->head = n;
- }
- end->next = p->registerNode(new NFAEndUNode);
- }
- }
-
- if (p != nullptr)
- p->matcher = new WCMatcher(p, L"");
-
- return p;
-}
-
-WCPattern* WCPattern::compileAndKeep(const CMStringW &pattern, const unsigned long mode)
-{
- WCPattern *ret = nullptr;
- std::map<CMStringW, WCPattern*>::iterator it = compiledWCPatterns.find(pattern);
- if (it != compiledWCPatterns.end())
- ret = it->second;
- else {
- ret = compile(pattern, mode);
- compiledWCPatterns[pattern] = ret;
- }
-
- return ret;
-}
-
-CMStringW WCPattern::replace(const CMStringW &pattern, const CMStringW &str, const CMStringW &replacementText, const unsigned long mode)
-{
- CMStringW ret;
- WCPattern *p = WCPattern::compile(pattern, mode);
- if (p) {
- ret = p->replace(str, replacementText);
- delete p;
- }
- return ret;
-}
-
-std::vector<CMStringW> WCPattern::split(const CMStringW &pattern, const CMStringW &str, const bool keepEmptys, const unsigned long limit, const unsigned long mode)
-{
- std::vector<CMStringW> ret;
- WCPattern *p = WCPattern::compile(pattern, mode);
- if (p) {
- ret = p->split(str, keepEmptys, limit);
- delete p;
- }
- return ret;
-}
-
-std::vector<CMStringW> WCPattern::findAll(const CMStringW &pattern, const CMStringW &str, const unsigned long mode)
-{
- std::vector<CMStringW> ret;
- WCPattern *p = WCPattern::compile(pattern, mode);
- if (p) {
- ret = p->findAll(str);
- delete p;
- }
- return ret;
-}
-
-bool WCPattern::matches(const CMStringW &pattern, const CMStringW &str, const unsigned long mode)
-{
- bool ret = 0;
- WCPattern *p = compile(pattern, mode);
- if (p) {
- ret = p->matches(str);
- delete p;
- }
-
- return ret;
-}
-
-bool WCPattern::registerWCPattern(const CMStringW &name, const CMStringW &pattern, const unsigned long mode)
-{
- WCPattern *p = WCPattern::compile(pattern, mode);
- if (!p)
- return 0;
-
- WCPattern::registeredWCPatterns[name] = std::make_pair(pattern, mode);
- delete p;
- return 1;
-}
-
-void WCPattern::unregisterWCPatterns()
-{
- registeredWCPatterns.clear();
-}
-
-void WCPattern::clearWCPatternCache()
-{
- std::map<CMStringW, WCPattern*>::iterator it;
- for (it = compiledWCPatterns.begin(); it != compiledWCPatterns.end(); ++it)
- delete it->second;
-
- compiledWCPatterns.clear();
-}
-
-std::pair<CMStringW, int> WCPattern::findNthMatch(const CMStringW &pattern, const CMStringW &str,
- const int matchNum, const unsigned long mode)
-{
- std::pair<CMStringW, int> ret;
- WCPattern *p = WCPattern::compile(pattern, mode);
-
- ret.second = -1;
- if (p) {
- int i = -1;
- p->matcher->setString(str);
- while (i < matchNum && p->matcher->findNextMatch()) { ++i; }
- if (i == matchNum && p->matcher->getStartingIndex() >= 0) {
- ret.first = p->matcher->getGroup(0);
- ret.second = p->matcher->getStartingIndex();
- }
- delete p;
- }
-
- return ret;
-}
-
-WCPattern::~WCPattern()
-{
- if (matcher) delete matcher;
- for (std::map<NFAUNode*, bool>::iterator it = nodes.begin(); it != nodes.end(); ++it)
- delete it->first;
-}
-
-CMStringW WCPattern::replace(const CMStringW &str, const CMStringW &replacementText)
-{
- int li = 0;
- CMStringW ret;
-
- matcher->setString(str);
- while (matcher->findNextMatch()) {
- ret += str.Mid(li, matcher->getStartingIndex() - li);
- ret += matcher->replaceWithGroups(replacementText);
- li = matcher->getEndingIndex();
- }
- ret += str.Mid(li);
-
- return ret;
-}
-
-std::vector<CMStringW> WCPattern::split(const CMStringW &str, const bool keepEmptys, const unsigned long limit)
-{
- unsigned long lim = (limit == 0 ? MAX_QMATCH : limit);
- int li = 0;
- std::vector<CMStringW> ret;
-
- matcher->setString(str);
-
- while (matcher->findNextMatch() && ret.size() < lim) {
- if (matcher->getStartingIndex() == 0 && keepEmptys) ret.push_back(L"");
- if ((matcher->getStartingIndex() != matcher->getEndingIndex()) || keepEmptys) {
- if (li != matcher->getStartingIndex() || keepEmptys)
- ret.push_back(str.Mid(li, matcher->getStartingIndex() - li));
-
- li = matcher->getEndingIndex();
- }
- }
-
- if (li < str.GetLength())
- ret.push_back(str.Mid(li));
-
- return ret;
-}
-
-std::vector<CMStringW> WCPattern::findAll(const CMStringW &str)
-{
- matcher->setString(str);
- return matcher->findAll();
-}
-
-bool WCPattern::matches(const CMStringW &str)
-{
- matcher->setString(str);
- return matcher->matches();
-}
-
-unsigned long WCPattern::getFlags() const
-{
- return flags;
-}
-
-CMStringW WCPattern::getWCPattern() const
-{
- return pattern;
-}
-
-WCMatcher *WCPattern::createWCMatcher(const CMStringW &str)
-{
- return new WCMatcher(this, str);
-}
-
-// NFAUNode
-
-NFAUNode::NFAUNode() { next = nullptr; }
-NFAUNode::~NFAUNode() {}
-void NFAUNode::findAllNodes(std::map<NFAUNode*, bool> &soFar)
-{
- if (soFar.find(this) == soFar.end()) return;
- soFar[this] = 1;
- if (next) next->findAllNodes(soFar);
-}
-
-// NFACharUNode
-
-NFACharUNode::NFACharUNode(const wchar_t c) { ch = c; }
-int NFACharUNode::match(const CMStringW &str, WCMatcher *matcher, const int curInd) const
-{
- if (curInd < str.GetLength() && str[curInd] == ch)
- return next->match(str, matcher, curInd + 1);
- return -1;
-}
-
-// NFACICharUNode
-
-NFACICharUNode::NFACICharUNode(const wchar_t c) { ch = to_lower(c); }
-int NFACICharUNode::match(const CMStringW &str, WCMatcher *matcher, const int curInd) const
-{
- if (curInd < str.GetLength() && to_lower(str[curInd]) == ch)
- return next->match(str, matcher, curInd + 1);
- return -1;
-}
-
-// NFAStartUNode
-
-NFAStartUNode::NFAStartUNode() {}
-int NFAStartUNode::match(const CMStringW &str, WCMatcher *matcher, const int curInd) const
-{
- int ret = -1, ci = curInd;
-
- matcher->starts[0] = curInd;
- if ((matcher->getFlags() & WCMatcher::MATCH_ENTIRE_STRING) == (unsigned int)WCMatcher::MATCH_ENTIRE_STRING) {
- if (curInd != 0) {
- matcher->starts[0] = -1;
- return -1;
- }
- return next->match(str, matcher, 0);
- }
-
- while ((ret = next->match(str, matcher, ci)) == -1 && ci < str.GetLength()) {
- matcher->clearGroups();
- matcher->starts[0] = ++ci;
- }
-
- if (ret < 0)
- matcher->starts[0] = -1;
- return ret;
-}
-
-// NFAEndUNode
-
-NFAEndUNode::NFAEndUNode() {}
-int NFAEndUNode::match(const CMStringW &str, WCMatcher *matcher, const int curInd) const
-{
- matcher->ends[0] = curInd;
- if ((matcher->getFlags() & WCMatcher::MATCH_ENTIRE_STRING) != 0) {
- if (curInd == str.GetLength())
- return curInd;
-
- matcher->ends[0] = -1;
- return -1;
- }
- return curInd;
-}
-
-// NFAQuantifierUNode
-
-void NFAQuantifierUNode::findAllNodes(std::map<NFAUNode*, bool> &soFar)
-{
- inner->findAllNodes(soFar);
- NFAUNode::findAllNodes(soFar);
-}
-
-NFAQuantifierUNode::NFAQuantifierUNode(WCPattern *pat, NFAUNode *internal, const int minMatch, const int maxMatch)
-{
- inner = internal;
- inner->next = pat->registerNode(new NFAAcceptUNode);
- min = (minMatch < WCPattern::MIN_QMATCH) ? WCPattern::MIN_QMATCH : minMatch;
- max = (maxMatch > WCPattern::MAX_QMATCH) ? WCPattern::MAX_QMATCH : maxMatch;
-}
-
-int NFAQuantifierUNode::match(const CMStringW &str, WCMatcher *matcher, const int curInd) const
-{
- int i0, i1, i2 = 0;
-
- i0 = i1 = curInd;
- while (i2 < min) {
- ++i2;
- i1 = inner->match(str, matcher, i0);
- if (i1 <= i0) return i1; // i1 < i0 means i1 is -1
- i0 = i1;
- }
-
- return i1;
-}
-// NFAGreedyQuantifierUNode
-
-NFAGreedyQuantifierUNode::NFAGreedyQuantifierUNode(WCPattern *pat, NFAUNode *internal, const int minMatch, const int maxMatch) :
- NFAQuantifierUNode(pat, internal, minMatch, maxMatch)
-{
-}
-
-int NFAGreedyQuantifierUNode::match(const CMStringW &str, WCMatcher *matcher, const int curInd) const
-{
- int t = NFAQuantifierUNode::match(str, matcher, curInd);
- if (t != -1) return matchInternal(str, matcher, t, min);
- return t;
-}
-
-int NFAGreedyQuantifierUNode::matchInternal(const CMStringW &str, WCMatcher *matcher, const int curInd, const int soFar) const
-{
- if (soFar >= max)
- return next->match(str, matcher, curInd);
-
- int i = inner->match(str, matcher, curInd);
- if (i != -1) {
- int j = matchInternal(str, matcher, i, soFar + 1);
- if (j != -1)
- return j;
- }
- return next->match(str, matcher, curInd);
-}
-
-// NFALazyQuantifierUNode
-
-NFALazyQuantifierUNode::NFALazyQuantifierUNode(WCPattern *pat, NFAUNode *internal, const int minMatch, const int maxMatch) :
- NFAQuantifierUNode(pat, internal, minMatch, maxMatch)
-{
-}
-
-int NFALazyQuantifierUNode::match(const CMStringW &str, WCMatcher *matcher, const int curInd) const
-{
- int m = NFAQuantifierUNode::match(str, matcher, curInd);
- if (m == -1)
- return -1;
-
- for (int i = min; i < max; ++i) {
- int j = next->match(str, matcher, m);
- if (j == -1) {
- j = inner->match(str, matcher, m);
- // if j < m, then j is -1, so we bail.
- // if j == m, then we would just go and call next->match on the same index,
- // but it already failed trying to match right there, so we know we can
- // just bail
- if (j <= m) return -1;
- m = j;
- }
- else return j;
- }
- return next->match(str, matcher, m);
-}
-
-// NFAPossessiveQuantifierUNode
-
-NFAPossessiveQuantifierUNode::NFAPossessiveQuantifierUNode(WCPattern *pat, NFAUNode *internal, const int minMatch, const int maxMatch) :
- NFAQuantifierUNode(pat, internal, minMatch, maxMatch)
-{
-}
-
-int NFAPossessiveQuantifierUNode::match(const CMStringW &str, WCMatcher *matcher, const int curInd) const
-{
- int m = NFAQuantifierUNode::match(str, matcher, curInd);
- if (m == -1)
- return -1;
-
- for (int i = min; i < max; ++i) {
- int j = inner->match(str, matcher, m);
- if (j <= m)
- return next->match(str, matcher, m);
- m = j;
- }
- return next->match(str, matcher, m);
-}
-
-// NFAAcceptUNode
-
-NFAAcceptUNode::NFAAcceptUNode()
-{
-}
-
-int NFAAcceptUNode::match(const CMStringW &str, WCMatcher *matcher, const int curInd) const
-{
- if (!next) return curInd;
- else return next->match(str, matcher, curInd);
-}
-
-// NFAClassUNode
-
-NFAClassUNode::NFAClassUNode(const bool invert)
-{
- inv = invert;
-}
-
-NFAClassUNode::NFAClassUNode(const CMStringW &clazz, const bool invert)
-{
- inv = invert;
- for (int i = 0; i < clazz.GetLength(); ++i)
- vals[clazz[i]] = 1;
-}
-
-int NFAClassUNode::match(const CMStringW &str, WCMatcher *matcher, const int curInd) const
-{
- if (curInd < str.GetLength() && ((vals.find(str[curInd]) != vals.end()) ^ inv)) {
- return next->match(str, matcher, curInd + 1);
- }
- return -1;
-}
-
-// NFACIClassUNode
-
-NFACIClassUNode::NFACIClassUNode(const bool invert)
-{
- inv = invert;
-}
-
-NFACIClassUNode::NFACIClassUNode(const CMStringW &clazz, const bool invert)
-{
- inv = invert;
- for (int i = 0; i < (int)clazz.GetLength(); ++i)
- vals[to_lower(clazz[i])] = 1;
-}
-
-int NFACIClassUNode::match(const CMStringW &str, WCMatcher *matcher, const int curInd) const
-{
- if (curInd < str.GetLength() && ((vals.find(to_lower(str[curInd])) != vals.end()) ^ inv))
- return next->match(str, matcher, curInd + 1);
-
- return -1;
-}
-
-// NFASubStartUNode
-
-NFASubStartUNode::NFASubStartUNode()
-{
-}
-
-int NFASubStartUNode::match(const CMStringW &str, WCMatcher *matcher, const int curInd) const
-{
- return next->match(str, matcher, curInd);
-}
-
-// NFAOrUNode
-
-NFAOrUNode::NFAOrUNode(NFAUNode *first, NFAUNode *second) :
- one(first), two(second)
-{
-}
-
-void NFAOrUNode::findAllNodes(std::map<NFAUNode*, bool> &soFar)
-{
- if (one) one->findAllNodes(soFar);
- if (two) two->findAllNodes(soFar);
- NFAUNode::findAllNodes(soFar);
-}
-int NFAOrUNode::match(const CMStringW &str, WCMatcher *matcher, const int curInd) const
-{
- int ci = one->match(str, matcher, curInd);
-
- if (ci != -1) ci = next->match(str, matcher, ci);
- if (ci != -1) return ci;
- if (ci == -1) ci = two->match(str, matcher, curInd);
- if (ci != -1) ci = next->match(str, matcher, ci);
- return ci;
-}
-
-// NFAQuoteUNode
-
-NFAQuoteUNode::NFAQuoteUNode(const CMStringW &quoted) :
- qStr(quoted)
-{
-}
-
-int NFAQuoteUNode::match(const CMStringW &str, WCMatcher *matcher, const int curInd) const
-{
- if (curInd + qStr.GetLength() > str.GetLength()) return -1;
- if (str.Mid(curInd, qStr.GetLength()) != qStr) return -1;
- return next->match(str, matcher, curInd + qStr.GetLength());
-}
-
-// NFACIQuoteUNode
-
-NFACIQuoteUNode::NFACIQuoteUNode(const CMStringW &quoted) :
- qStr(quoted)
-{
-}
-
-int NFACIQuoteUNode::match(const CMStringW &str, WCMatcher *matcher, const int curInd) const
-{
- if (curInd + qStr.GetLength() > str.GetLength()) return -1;
- if (str_icmp(str.Mid(curInd, qStr.GetLength()).c_str(), qStr.c_str())) return -1;
- return next->match(str, matcher, qStr.GetLength());
-}
-
-// NFALookAheadUNode
-
-NFALookAheadUNode::NFALookAheadUNode(NFAUNode *internal, const bool positive) :
- NFAUNode(), pos(positive), inner(internal)
-{
-}
-
-void NFALookAheadUNode::findAllNodes(std::map<NFAUNode*, bool> &soFar)
-{
- if (inner) inner->findAllNodes(soFar);
- NFAUNode::findAllNodes(soFar);
-}
-
-int NFALookAheadUNode::match(const CMStringW &str, WCMatcher *matcher, const int curInd) const
-{
- return ((inner->match(str, matcher, curInd) == -1) ^ pos) ? next->match(str, matcher, curInd) : -1;
-}
-
-// NFALookBehindUNode
-
-NFALookBehindUNode::NFALookBehindUNode(const CMStringW &str, const bool positive) :
- pos(positive), mStr(str)
-{
-}
-
-int NFALookBehindUNode::match(const CMStringW &str, WCMatcher *matcher, const int curInd) const
-{
- if (pos) {
- if (curInd < mStr.GetLength())
- return -1;
- if (str.Mid(curInd - mStr.GetLength(), mStr.GetLength()) == mStr)
- return next->match(str, matcher, curInd);
- }
- else {
- if (curInd < mStr.GetLength())
- return next->match(str, matcher, curInd);
- if (str.Mid(curInd - mStr.GetLength(), mStr.GetLength()) == mStr)
- return -1;
- return next->match(str, matcher, curInd);
- }
- return -1;
-}
-
-// NFAStartOfLineUNode
-
-NFAStartOfLineUNode::NFAStartOfLineUNode()
-{
-}
-
-int NFAStartOfLineUNode::match(const CMStringW &str, WCMatcher *matcher, const int curInd) const
-{
- if (curInd == 0 || str[curInd - 1] == '\n' || str[curInd - 1] == '\r')
- return next->match(str, matcher, curInd);
-
- return -1;
-}
-
-// NFAEndOfLineUNode
-
-NFAEndOfLineUNode::NFAEndOfLineUNode()
-{
-}
-
-int NFAEndOfLineUNode::match(const CMStringW &str, WCMatcher *matcher, const int curInd) const
-{
- if (curInd >= str.GetLength() || str[curInd] == '\n' || str[curInd] == '\r')
- return next->match(str, matcher, curInd);
-
- return -1;
-}
-
-// NFAReferenceUNode
-
-NFAReferenceUNode::NFAReferenceUNode(const int groupIndex) :
- gi(groupIndex)
-{
-}
-
-int NFAReferenceUNode::match(const CMStringW &str, WCMatcher *matcher, const int curInd) const
-{
- int len = matcher->ends[gi] - matcher->starts[gi];
- int ni = -1;
- if (gi < 1 || matcher->ends[gi] < matcher->starts[gi] || len == 0) ni = curInd;
- else if (curInd + len > (int)str.GetLength()) return -1;
- else if (str.Mid(curInd, len) != str.Mid(matcher->starts[gi], len)) return -1;
- else ni = curInd + len;
-
- return next->match(str, matcher, ni);
-}
-
-// NFAStartOfInputUNode
-
-NFAStartOfInputUNode::NFAStartOfInputUNode()
-{
-}
-
-int NFAStartOfInputUNode::match(const CMStringW &str, WCMatcher *matcher, const int curInd) const
-{
- if (curInd == 0) return next->match(str, matcher, curInd);
- return -1;
-}
-
-// NFAEndOfInputUNode
-
-NFAEndOfInputUNode::NFAEndOfInputUNode(const bool lookForTerm) :
- term(lookForTerm)
-{
-}
-
-int NFAEndOfInputUNode::match(const CMStringW &str, WCMatcher *matcher, const int curInd) const
-{
- int len = str.GetLength();
- if (curInd == len) return next->match(str, matcher, curInd);
- else if (term) {
- if (curInd == len - 1 && (str[curInd] == '\r' || str[curInd] == '\n')) {
- return next->match(str, matcher, curInd);
- }
- else if (curInd == len - 2 && str.Mid(curInd, 2) == L"\r\n") {
- return next->match(str, matcher, curInd);
- }
- }
- return -1;
-}
-
-// NFAWordBoundaryUNode
-
-NFAWordBoundaryUNode::NFAWordBoundaryUNode(const bool positive) :
- pos(positive)
-{
-}
-
-int NFAWordBoundaryUNode::match(const CMStringW &str, WCMatcher *matcher, const int curInd) const
-{
- int len = str.GetLength();
-
- wchar_t c1 = (curInd - 1 < len && curInd > 0) ? str[curInd - 1] : '\n';
- wchar_t c2 = (curInd < len) ? str[curInd] : '\n';
-
- if (curInd == len) return next->match(str, matcher, curInd);
- bool ok = is_alpha(c1) != is_alpha(c2);
- if (ok && pos) return next->match(str, matcher, curInd);
- return -1;
-}
-
-// NFAEndOfMatchUNode
-
-NFAEndOfMatchUNode::NFAEndOfMatchUNode()
-{
-}
-
-int NFAEndOfMatchUNode::match(const CMStringW &str, WCMatcher *matcher, const int curInd) const
-{
- if (curInd == matcher->lm) return next->match(str, matcher, curInd);
- return -1;
-}
-
-// NFAGroupHeadUNode
-
-NFAGroupHeadUNode::NFAGroupHeadUNode(const int groupIndex) :
- gi(groupIndex)
-{
-}
-
-int NFAGroupHeadUNode::match(const CMStringW &str, WCMatcher *matcher, const int curInd) const
-{
- int ret, o = matcher->starts[gi];
-
- matcher->starts[gi] = curInd;
- ret = next->match(str, matcher, curInd);
- if (ret < 0) matcher->starts[gi] = o;
-
- return ret;
-}
-
-// NFAGroupTailUNode
-
-NFAGroupTailUNode::NFAGroupTailUNode(const int groupIndex) :
- gi(groupIndex)
-{
-}
-
-int NFAGroupTailUNode::match(const CMStringW &str, WCMatcher *matcher, const int curInd) const
-{
- int ret, o = matcher->ends[gi];
-
- matcher->ends[gi] = curInd;
- ret = next->match(str, matcher, curInd);
- if (ret < 0) matcher->ends[gi] = o;
-
- return ret;
-}
-
-// NFAGroupLoopPrologueUNode
-
-NFAGroupLoopPrologueUNode::NFAGroupLoopPrologueUNode(const int groupIndex) :
- gi(groupIndex)
-{
-}
-
-int NFAGroupLoopPrologueUNode::match(const CMStringW &str, WCMatcher *matcher, const int curInd) const
-{
- int ret, o1 = matcher->groups[gi], o2 = matcher->groupPos[gi], o3 = matcher->groupIndeces[gi];
-
- matcher->groups[gi] = 0;
- matcher->groupPos[gi] = 0;
- matcher->groupIndeces[gi] = -1;
- ret = next->match(str, matcher, curInd);
- if (ret < 0) {
- matcher->groups[gi] = o1;
- matcher->groupPos[gi] = o2;
- matcher->groupIndeces[gi] = o3;
- }
-
- return ret;
-}
-
-// NFAGroupLoopUNode
-
-NFAGroupLoopUNode::NFAGroupLoopUNode(NFAUNode *internal, const int minMatch, const int maxMatch,
- const int groupIndex, const int matchType)
-{
- inner = internal;
- min = minMatch;
- max = maxMatch;
- gi = groupIndex;
- type = matchType;
-}
-
-void NFAGroupLoopUNode::findAllNodes(std::map<NFAUNode*, bool> &soFar)
-{
- if (inner) inner->findAllNodes(soFar);
- NFAUNode::findAllNodes(soFar);
-}
-
-int NFAGroupLoopUNode::match(const CMStringW &str, WCMatcher *matcher, const int curInd) const
-{
- bool b = (curInd > matcher->groupIndeces[gi]);
-
- if (b && matcher->groups[gi] < min) {
- ++matcher->groups[gi];
- int o = matcher->groupIndeces[gi];
- matcher->groupIndeces[gi] = curInd;
- int ret = inner->match(str, matcher, curInd);
- if (ret < 0) {
- matcher->groupIndeces[gi] = o;
- --matcher->groups[gi];
- }
- return ret;
- }
- else if (!b || matcher->groups[gi] >= max) {
- return next->match(str, matcher, curInd);
- }
- else {
- switch (type) {
- case 0: return matchGreedy(str, matcher, curInd);
- case 1: return matchLazy(str, matcher, curInd);
- case 2: return matchPossessive(str, matcher, curInd);
- }
- }
- return -1;
-}
-
-int NFAGroupLoopUNode::matchGreedy(const CMStringW &str, WCMatcher *matcher, const int curInd) const
-{
- int o = matcher->groupIndeces[gi]; // save our info for backtracking
- matcher->groupIndeces[gi] = curInd; // move along
- ++matcher->groups[gi];
- int ret = inner->match(str, matcher, curInd); // match internally
- if (ret < 0) { // if we failed, then restore info and match next
- --matcher->groups[gi];
- matcher->groupIndeces[gi] = o;
- ret = next->match(str, matcher, curInd);
- }
- return ret;
-}
-
-int NFAGroupLoopUNode::matchLazy(const CMStringW &str, WCMatcher *matcher, const int curInd) const
-{
- int ret = next->match(str, matcher, curInd); // be lazy, just go on
- if (ret < 0) {
- int o = matcher->groupIndeces[gi]; // save info for backtracking
- matcher->groupIndeces[gi] = curInd; // advance our position
- ++matcher->groups[gi];
- ret = inner->match(str, matcher, curInd); // match our internal stuff
- if (ret < 0) // if we failed, then restore the info
- {
- --matcher->groups[gi];
- matcher->groupIndeces[gi] = o;
- }
- }
- return ret;
-}
-
-int NFAGroupLoopUNode::matchPossessive(const CMStringW &str, WCMatcher *matcher, const int curInd) const
-{
- int o = matcher->groupIndeces[gi]; // save info for backtracking
- matcher->groupPos[gi] = matcher->groups[gi]; // set a flag stating we have matcher at least this much
- matcher->groupIndeces[gi] = curInd; // move along
- ++matcher->groups[gi];
- int ret = inner->match(str, matcher, curInd); // try and match again
- if (ret < 0) { // if we fail, back off, but to an extent
- --matcher->groups[gi];
- matcher->groupIndeces[gi] = o;
- if (matcher->groups[gi] == matcher->groupPos[gi]) ret = next->match(str, matcher, curInd);
- }
- return ret;
-}
diff --git a/plugins/SmileyAdd/src/regexp/WCPattern.h b/plugins/SmileyAdd/src/regexp/WCPattern.h
deleted file mode 100644
index d45f734645..0000000000
--- a/plugins/SmileyAdd/src/regexp/WCPattern.h
+++ /dev/null
@@ -1,1654 +0,0 @@
-#ifndef __WCPATTERN_H__
-#define __WCPATTERN_H__
-
-class WCMatcher;
-class NFAUNode;
-class NFAQuantifierUNode;
-
-/**
- This pattern class is very similar in functionality to Java's
- java.util.regex.WCPattern class. The pattern class represents an immutable
- regular expression object. Instead of having a single object contain both the
- regular expression object and the matching object, instead the two objects are
- split apart. The {@link WCMatcher WCMatcher} class represents the maching
- object.
-
- The WCPattern class works primarily off of "compiled" patterns. A typical
- instantiation of a regular expression looks like:
-
- <pre>
- WCPattern * p = WCPattern::compile(L"a*b");
- WCMatcher * m = p->createWCMatcher(L"aaaaaab");
- if (m->matches()) ...
- </pre>
-
- However, if you do not need to use a pattern more than once, it is often times
- okay to use the WCPattern's static methods insteads. An example looks like this:
-
- <pre>
- if (WCPattern::matches(L"a*b", L"aaaab")) { ... }
- </pre>
-
- This class does not currently support unicode. The unicode update for this
- class is coming soon.
-
- This class is partially immutable. It is completely safe to call createWCMatcher
- concurrently in different threads, but the other functions (e.g. split) should
- not be called concurrently on the same <code>WCPattern</code>.
-
- <table border="0" cellpadding="1" cellspacing="0">
- <tr align="left" bgcolor="#CCCCFF">
- <td>
- <b>Construct</b>
- </td>
- <td>
- <b>Matches</b>
- </th>
- </tr>
- <tr>
- <td colspan="2">
- &nbsp;
- </td>
- </tr>
- <tr>
- <td colspan="2">
- <b>Characters</b>
- </td>
- </tr>
- <tr>
- <td>
- <code><i>x</i></code>
- </td>
- <td>
- The character <code><i>x</i></code>
- </td>
- </tr>
- <tr>
- <td>
- <code>\\</code>
- </td>
- <td>
- The character <code>\</code>
- </td>
- </tr>
- <tr>
- <td>
- <code>\0<i>nn</i></code>
- </td>
- <td>
- The character with octal ASCII value <code><i>nn</i></code>
- </td>
- </tr>
- <tr>
- <td>
- <code>\0<i>nnn</i></code>
- </td>
- <td>
- The character with octal ASCII value <code><i>nnn</i></code>
- </td>
- </tr>
- <tr>
- <td>
- <code>\x<i>hh</i></code>
- </td>
- <td>
- The character with hexadecimal ASCII value <code><i>hh</i></code>
- </td>
- </tr>
- <tr>
- <td>
- <code>\t</code>
- </td>
- <td>
- A tab character
- </td>
- </tr>
- <tr>
- <td>
- <code>\r</code>
- </td>
- <td>
- A carriage return character
- </td>
- </tr>
- <tr>
- <td>
- <code>\n</code>
- </td>
- <td>
- A new-line character
- </td>
- </tr>
- <tr>
- <td colspan="2">
- &nbsp;
- </td>
- </tr>
- <tr>
- <td>
- <b>Character Classes</b>
- </td>
- </tr>
- <tr>
- <td>
- <code>[abc]</code>
- </td>
- <td>
- Either <code>a</code>, <code>b</code>, or <code>c</code>
- </td>
- </tr>
- <tr>
- <td>
- <code>[^abc]</code>
- </td>
- <td>
- Any character but <code>a</code>, <code>b</code>, or <code>c</code>
- </td>
- </tr>
- <tr>
- <td>
- <code>[a-zA-Z]</code>
- </td>
- <td>
- Any character ranging from <code>a</code> thru <code>z</code>, or
- <code>A</code> thru <code>Z</code>
- </td>
- </tr>
- <tr>
- <td>
- <code>[^a-zA-Z]</code>
- </td>
- <td>
- Any character except those ranging from <code>a</code> thru
- <code>z</code>, or <code>A</code> thru <code>Z</code>
- </td>
- </tr>
- <tr>
- <td>
- <code>[a\-z]</code>
- </td>
- <td>
- Either <code>a</code>, <code>-</code>, or <code>z</code>
- </td>
- </tr>
- <tr>
- <td>
- <code>[a-z[A-Z]]</code>
- </td>
- <td>
- Same as <code>[a-zA-Z]</code>
- </td>
- </tr>
- <tr>
- <td>
- <code>[a-z&&[g-i]]</code>
- </td>
- <td>
- Any character in the intersection of <code>a-z</code> and
- <code>g-i</code>
- </td>
- </tr>
- <tr>
- <td>
- <code>[a-z&&[^g-i]]</code>
- </td>
- <td>
- Any character in <code>a-z</code> and not in <code>g-i</code>
- </td>
- </tr>
- <tr>
- <td colspan="2">
- &nbsp;
- </td>
- </tr>
- <tr>
- <td colspan="2">
- <b>Prefefined character classes</b>
- </td>
- </tr>
- <tr>
- <td>
- <code><b>.</b></code>
- </td>
- <td>
- Any character. Multiline matching must be compiled into the pattern for
- <code><b>.</b></code> to match a <code>\r</code> or a <code>\n</code>.
- Even if multiline matching is enabled, <code><b>.</b></code> will not
- match a <code>\r\n</code>, only a <code>\r</code> or a <code>\n</code>.
- </td>
- </tr>
- <tr>
- <td>
- <code>\d</code>
- </td>
- <td>
- <code>[0-9]</code>
- </td>
- </tr>
- <tr>
- <td>
- <code>\D</code>
- </td>
- <td>
- <code>[^\d]</code>
- </td>
- </tr>
- <tr>
- <td>
- <code>\s</code>
- </td>
- <td>
- <code>[&nbsp;\t\r\n\x0B]</code>
- </td>
- </tr>
- <tr>
- <td>
- <code>\S</code>
- </td>
- <td>
- <code>[^\s]</code>
- </td>
- </tr>
- <tr>
- <td>
- <code>\w</code>
- </td>
- <td>
- <code>[a-zA-Z0-9_]</code>
- </td>
- </tr>
- <tr>
- <td>
- <code>\W</code>
- </td>
- <td>
- <code>[^\w]</code>
- </td>
- </tr>
- <tr>
- <td colspan="2">
- &nbsp;
- </td>
- </tr>
- <tr>
- <td colspan="2">
- <b>POSIX character classes
- </td>
- </tr>
- <tr>
- <td>
- <code>\p{Lower}</code>
- </td>
- <td>
- <code>[a-z]</code>
- </td>
- </tr>
- <tr>
- <td>
- <code>\p{Upper}</code>
- </td>
- <td>
- <code>[A-Z]</code>
- </td>
- </tr>
- <tr>
- <td>
- <code>\p{ASCII}</code>
- </td>
- <td>
- <code>[\x00-\x7F]</code>
- </td>
- </tr>
- <tr>
- <td>
- <code>\p{Alpha}</code>
- </td>
- <td>
- <code>[a-zA-Z]</code>
- </td>
- </tr>
- <tr>
- <td>
- <code>\p{Digit}</code>
- </td>
- <td>
- <code>[0-9]</code>
- </td>
- </tr>
- <tr>
- <td>
- <code>\p{Alnum}</code>
- </td>
- <td>
- <code>[\w&&[^_]]</code>
- </td>
- </tr>
- <tr>
- <td>
- <code>\p{Punct}</code>
- </td>
- <td>
- <code>[!"#$%&'()*+,-./:;&lt;=&gt;?@[\]^_`{|}~]</code>
- </td>
- </tr>
- <tr>
- <td>
- <code>\p{XDigit}</code>
- </td>
- <td>
- <code>[a-fA-F0-9]</code>
- </td>
- </tr>
- <tr>
- <td colspan="2">
- &nbsp;
- </td>
- </tr>
- <tr>
- <td colspan="2">
- <b>Boundary Matches</b>
- </td>
- </tr>
- <tr>
- <td>
- <code>^</code>
- </td>
- <td>
- The beginning of a line. Also matches the beginning of input.
- </td>
- </tr>
- <tr>
- <td>
- <code>$</code>
- </td>
- <td>
- The end of a line. Also matches the end of input.
- </td>
- </tr>
- <tr>
- <td>
- <code>\b</code>
- </td>
- <td>
- A word boundary
- </td>
- </tr>
- <tr>
- <td>
- <code>\B</code>
- </td>
- <td>
- A non word boundary
- </td>
- </tr>
- <tr>
- <td>
- <code>\A</code>
- </td>
- <td>
- The beginning of input
- </td>
- </tr>
- <tr>
- <td>
- <code>\G</code>
- </td>
- <td>
- The end of the previous match. Ensures that a "next" match will only
- happen if it begins with the character immediately following the end of
- the "current" match.
- </td>
- </tr>
- <tr>
- <td>
- <code>\Z</code>
- </td>
- <td>
- The end of input. Will also match if there is a single trailing
- <code>\r\n</code>, a single trailing <code>\r</code>, or a single
- trailing <code>\n</code>.
- </td>
- </tr>
- <tr>
- <td>
- <code>\z</code>
- </td>
- <td>
- The end of input
- </td>
- </tr>
- <tr>
- <td>
- &nbsp;
- </td>
- </tr>
- <tr>
- <td colspan="2">
- <b>Greedy Quantifiers</b>
- </td>
- </tr>
- <tr>
- <td>
- <code><i>x?</i></code>
- </td>
- <td>
- <i>x</i>, either zero times or one time
- </td>
- </tr>
- <tr>
- <td>
- <code><i>x*</i></code>
- </td>
- <td>
- <i>x</i>, zero or more times
- </td>
- </tr>
- <tr>
- <td>
- <code><i>x+</i></code>
- </td>
- <td>
- <i>x</i>, one or more times
- </td>
- </tr>
- <tr>
- <td>
- <code><i>x{n}</i></code>
- </td>
- <td>
- <i>x</i>, exactly n times
- </td>
- </tr>
- <tr>
- <td>
- <code><i>x{n,}</i></code>
- </td>
- <td>
- <i>x</i>, at least <code><i>n</i></code> times
- </td>
- </tr>
- <tr>
- <td>
- <code><i>x{,m}</i></code>
- </td>
- <td>
- <i>x</i>, at most <code><i>m</i></code> times
- </td>
- </tr>
- <tr>
- <td>
- <code><i>x{n,m}</i></code>
- </td>
- <td>
- <i>x</i>, at least <code><i>n</i></code> times and at most
- <code><i>m</i></code> times
- </td>
- </tr>
- <tr>
- <td>
- &nbsp;
- </td>
- </tr>
- <tr>
- <td colspan="2">
- <b>Possessive Quantifiers</b>
- </td>
- </tr>
- <tr>
- <td>
- <code><i>x?+</i></code>
- </td>
- <td>
- <i>x</i>, either zero times or one time
- </td>
- </tr>
- <tr>
- <td>
- <code><i>x*+</i></code>
- </td>
- <td>
- <i>x</i>, zero or more times
- </td>
- </tr>
- <tr>
- <td>
- <code><i>x++</i></code>
- </td>
- <td>
- <i>x</i>, one or more times
- </td>
- </tr>
- <tr>
- <td>
- <code><i>x{n}+</i></code>
- </td>
- <td>
- <i>x</i>, exactly n times
- </td>
- </tr>
- <tr>
- <td>
- <code><i>x{n,}+</i></code>
- </td>
- <td>
- <i>x</i>, at least <code><i>n</i></code> times
- </td>
- </tr>
- <tr>
- <td>
- <code><i>x{,m}+</i></code>
- </td>
- <td>
- <i>x</i>, at most <code><i>m</i></code> times
- </td>
- </tr>
- <tr>
- <td>
- <code><i>x{n,m}+</i></code>
- </td>
- <td>
- <i>x</i>, at least <code><i>n</i></code> times and at most
- <code><i>m</i></code> times
- </td>
- </tr>
- <tr>
- <td colspan="2">
- &nbsp;
- </td>
- </tr>
- <tr>
- <td colspan="2">
- <b>Reluctant Quantifiers</b>
- </td>
- </tr>
- <tr>
- <td>
- <code><i>x??</i></code>
- </td>
- <td>
- <i>x</i>, either zero times or one time
- </td>
- </tr>
- <tr>
- <td>
- <code><i>x*?</i></code>
- </td>
- <td>
- <i>x</i>, zero or more times
- </td>
- </tr>
- <tr>
- <td>
- <code><i>x+?</i></code>
- </td>
- <td>
- <i>x</i>, one or more times
- </td>
- </tr>
- <tr>
- <td>
- <code><i>x{n}?</i></code>
- </td>
- <td>
- <i>x</i>, exactly n times
- </td>
- </tr>
- <tr>
- <td>
- <code><i>x{n,}?</i></code>
- </td>
- <td>
- <i>x</i>, at least <code><i>n</i></code> times
- </td>
- </tr>
- <tr>
- <td>
- <code><i>x{,m}?</i></code>
- </td>
- <td>
- <i>x</i>, at most <code><i>m</i></code> times
- </td>
- </tr>
- <tr>
- <td>
- <code><i>x{n,m}?</i></code>
- </td>
- <td>
- <i>x</i>, at least <code><i>n</i></code> times and at most
- <code><i>m</i></code> times
- </td>
- </tr>
- <tr>
- <td>
- &nbsp;
- </td>
- </tr>
- <tr>
- <td colspan="2">
- <b>Operators</b>
- </td>
- </tr>
- <tr>
- <td>
- <code><i>xy</i></code>
- </td>
- <td>
- <code><i>x</i></code> then <code><i>y</i></code>
- </td>
- </tr>
- <tr>
- <td>
- <code><i>x</i></code>|<code><i>y</i></code>
- </td>
- <td>
- <code><i>x</i></code> or <code><i>y</i></code>
- </td>
- </tr>
- <tr>
- <td>
- <code>(<i>x</i>)</code>
- </td>
- <td>
- <code><i>x</i></code> as a capturing group
- </td>
- </tr>
- <tr>
- <td colspan="2">
- &nbsp;
- </td>
- </tr>
- <tr>
- <td colspan="2">
- <b>Quoting</b>
- </td>
- </tr>
- <tr>
- <td>
- <code>\Q</code>
- </td>
- <td>
- Nothing, but treat every character (including \s) literally until a
- matching <code>\E</code>
- </td>
- </tr>
- <tr>
- <td>
- <code>\E</code>
- </td>
- <td>
- Nothing, but ends its matching <code>\Q</code>
- </td>
- </tr>
- <tr>
- <td>
- &nbsp;
- </td>
- </tr>
- <tr>
- <td colspan="2">
- <b>Special Constructs</b>
- </td>
- </tr>
- <tr>
- <td>
- <code>(?:<i>x</i>)</code>
- </td>
- <td>
- <code><i>x</i></code>, but not as a capturing group
- </td>
- </tr>
- <tr>
- <td>
- <code>(?=<i>x</i>)</code>
- </td>
- <td>
- <code><i>x</i></code>, via positive lookahead. This means that the
- expression will match only if it is trailed by <code><i>x</i></code>.
- It will not "eat" any of the characters matched by
- <code><i>x</i></code>.
- </td>
- </tr>
- <tr>
- <td>
- <code>(?!<i>x</i>)</code>
- </td>
- <td>
- <code><i>x</i></code>, via negative lookahead. This means that the
- expression will match only if it is not trailed by
- <code><i>x</i></code>. It will not "eat" any of the characters
- matched by <code><i>x</i></code>.
- </td>
- </tr>
- <tr>
- <td>
- <code>(?<=<i>x</i>)</code>
- </td>
- <td>
- <code><i>x</i></code>, via positive lookbehind. <code><i>x</i></code>
- cannot contain any quantifiers.
- </td>
- </tr>
- <tr>
- <td>
- <code>(?<!<i>x</i>)</code>
- </td>
- <td>
- <code><i>x</i></code>, via negative lookbehind. <code><i>x</i></code>
- cannot contain any quantifiers.
- </td>
- </tr>
- <tr>
- <td>
- <code>(?><i>x</i>)</code>
- </td>
- <td>
- <code><i>x</i>{1}+</code>
- </td>
- </tr>
- <tr>
- <td colspan="2">
- &nbsp;
- </td>
- </tr>
- <tr>
- <td colspan="2">
- <b>Registered Expression Matching</b>
- </td>
- </tr>
- <tr>
- <td>
- <code>{<i>x</i>}</code>
- </td>
- <td>
- The registered pattern <code><i>x</i></code>
- </td>
- </tr>
- </table>
-
- <hr>
-
- <i>Begin Text Extracted And Modified From java.util.regex.WCPattern documentation</i>
-
- <h4> Backslashes, escapes, and quoting </h4>
-
- <p> The backslash character (<tt>'\'</tt>) serves to introduce escaped
- constructs, as defined in the table above, as well as to quote characters
- that otherwise would be interpreted as unescaped constructs. Thus the
- expression <tt>\\</tt> matches a single backslash and <tt>\{</tt> matches a
- left brace.
-
- <p> It is an error to use a backslash prior to any alphabetic character that
- does not denote an escaped construct; these are reserved for future
- extensions to the regular-expression language. A backslash may be used
- prior to a non-alphabetic character regardless of whether that character is
- part of an unescaped construct.
-
- <p>It is necessary to double backslashes in string literals that represent
- regular expressions to protect them from interpretation by a compiler. The
- string literal <tt>"&#92;b"</tt>, for example, matches a single backspace
- character when interpreted as a regular expression, while
- <tt>"&#92;&#92;b"</tt> matches a word boundary. The string litera
- <tt>"&#92;(hello&#92;)"</tt> is illegal and leads to a compile-time error;
- in order to match the string <tt>(hello)</tt> the string literal
- <tt>"&#92;&#92;(hello&#92;&#92;)"</tt> must be used.
-
- <h4> Character Classes </h4>
-
- <p> Character classes may appear within other character classes, and
- may be composed by the union operator (implicit) and the intersection
- operator (<tt>&amp;&amp;</tt>).
- The union operator denotes a class that contains every character that is
- in at least one of its operand classes. The intersection operator
- denotes a class that contains every character that is in both of its
- operand classes.
-
- <p> The precedence of character-class operators is as follows, from
- highest to lowest:
-
- <blockquote><table border="0" cellpadding="1" cellspacing="0"
- summary="Precedence of character class operators.">
-
- <tr><th>1&nbsp;&nbsp;&nbsp;&nbsp;</th>
- <td>Literal escape&nbsp;&nbsp;&nbsp;&nbsp;</td>
- <td><tt>\x</tt></td></tr>
- <tr><th>2&nbsp;&nbsp;&nbsp;&nbsp;</th>
- <td>Range</td>
- <td><tt>a-z</tt></td></tr>
- <tr><th>3&nbsp;&nbsp;&nbsp;&nbsp;</th>
- <td>Grouping</td>
- <td><tt>[...]</tt></td></tr>
- <tr><th>4&nbsp;&nbsp;&nbsp;&nbsp;</th>
- <td>Intersection</td>
- <td><tt>[a-z&&[aeiou]]</tt></td></tr>
- <tr><th>5&nbsp;&nbsp;&nbsp;&nbsp;</th>
- <td>Union</td>
- <td><tt>[a-e][i-u]<tt></td></tr>
- </table></blockquote>
-
- <p> Note that a different set of metacharacters are in effect inside
- a character class than outside a character class. For instance, the
- regular expression <tt>.</tt> loses its special meaning inside a
- character class, while the expression <tt>-</tt> becomes a range
- forming metacharacter.
-
- <a name="lt">
-
- <a name="cg">
- <h4> Groups and capturing </h4>
-
- <p> Capturing groups are numbered by counting their opening parentheses from
- left to right. In the expression <tt>((A)(B(C)))</tt>, for example, there
- are four such groups: </p>
-
- <blockquote><table cellpadding=1 cellspacing=0 summary="Capturing group numberings">
-
- <tr><th>1&nbsp;&nbsp;&nbsp;&nbsp;</th>
- <td><tt>((A)(B(C)))</tt></td></tr>
- <tr><th>2&nbsp;&nbsp;&nbsp;&nbsp;</th>
- <td><tt>(A)</tt></td></tr>
- <tr><th>3&nbsp;&nbsp;&nbsp;&nbsp;</th>
- <td><tt>(B(C))</tt></td></tr>
-
- <tr><th>4&nbsp;&nbsp;&nbsp;&nbsp;</th>
- <td><tt>(C)</tt></td></tr>
- </table></blockquote>
-
- <p> Group zero always stands for the entire expression.
-
- <p> Capturing groups are so named because, during a match, each subsequence
- of the input sequence that matches such a group is saved. The captured
- subsequence may be used later in the expression, via a back reference, and
- may also be retrieved from the matcher once the match operation is complete.
-
- <p> The captured input associated with a group is always the subsequence
- that the group most recently matched. If a group is evaluated a second time
- because of quantification then its previously-captured value, if any, will
- be retained if the second evaluation fails. Matching the string
- <tt>L"aba"</tt> against the expression <tt>(a(b)?)+</tt>, for example, leaves
- group two set to <tt>L"b"</tt>. All captured input is discarded at the
- beginning of each match.
-
- <p> Groups beginning with <tt>(?</tt> are pure, <i>non-capturing</i> groups
- that do not capture text and do not count towards the group total.
-
-
- <h4> WC support </h4>
-
- <p> Coming Soon.
-
- <h4> Comparison to Perl 5 </h4>
-
- <p>The <code>WCPattern</code> engine performs traditional NFA-based matching
- with ordered alternation as occurs in Perl 5.
-
- <p> Perl constructs not supported by this class: </p>
-
- <ul>
-
- <li><p> The conditional constructs <tt>(?{</tt><i>X</i><tt>})</tt> and
- <tt>(?(</tt><i>condition</i><tt>)</tt><i>X</i><tt>|</tt><i>Y</i><tt>)</tt>,
- </p></li>
-
- <li><p> The embedded code constructs <tt>(?{</tt><i>code</i><tt>})</tt>
- and <tt>(??{</tt><i>code</i><tt>})</tt>,</p></li>
-
- <li><p> The embedded comment syntax <tt>(?#comment)</tt>, and </p></li>
-
- <li><p> The preprocessing operations <tt>\l</tt> <tt>&#92;u</tt>,
- <tt>\L</tt>, and <tt>\U</tt>. </p></li>
-
- <li><p> Embedded flags</p></li>
-
- </ul>
-
- <p> Constructs supported by this class but not by Perl: </p>
-
- <ul>
-
- <li><p> Possessive quantifiers, which greedily match as much as they can
- and do not back off, even when doing so would allow the overall match to
- succeed. </p></li>
-
- <li><p> Character-class union and intersection as described
- above.</p></li>
-
- </ul>
-
- <p> Notable differences from Perl: </p>
-
- <ul>
-
- <li><p> In Perl, <tt>\1</tt> through <tt>\9</tt> are always interpreted
- as back references; a backslash-escaped number greater than <tt>9</tt> is
- treated as a back reference if at least that many subexpressions exist,
- otherwise it is interpreted, if possible, as an octal escape. In this
- class octal escapes must always begin with a zero. In this class,
- <tt>\1</tt> through <tt>\9</tt> are always interpreted as back
- references, and a larger number is accepted as a back reference if at
- least that many subexpressions exist at that point in the regular
- expression, otherwise the parser will drop digits until the number is
- smaller or equal to the existing number of groups or it is one digit.
- </p></li>
-
- <li><p> Perl uses the <tt>g</tt> flag to request a match that resumes
- where the last match left off. This functionality is provided implicitly
- by the <CODE>WCMatcher</CODE> class: Repeated invocations of the
- <code>find</code> method will resume where the last match left off,
- unless the matcher is reset. </p></li>
-
- <li><p> Perl is forgiving about malformed matching constructs, as in the
- expression <tt>*a</tt>, as well as dangling brackets, as in the
- expression <tt>abc]</tt>, and treats them as literals. This
- class also strict and will not compile a pattern when dangling characters
- are encountered.</p></li>
-
- </ul>
-
-
- <p> For a more precise description of the behavior of regular expression
- constructs, please see <a href="http://www.oreilly.com/catalog/regex2/">
- <i>Mastering Regular Expressions, 2nd Edition</i>, Jeffrey E. F. Friedl,
- O'Reilly and Associates, 2002.</a>
- </p>
- <P>
-
- <i>End Text Extracted And Modified From java.util.regex.WCPattern documentation</i>
-
- <hr>
-
- @author Jeffery Stuart
- @since March 2003, Stable Since November 2004
- @version 1.07.00
- @memo A class used to represent "PERL 5"-ish regular expressions
- */
-class WCPattern
-{
- friend class WCMatcher;
- friend class NFAUNode;
- friend class NFAQuantifierUNode;
-private:
- /**
- This constructor should not be called directly. Those wishing to use the
- WCPattern class should instead use the {@link compile compile} method.
-
- @param rhs The pattern to compile
- @memo Creates a new pattern from the regular expression in <code>rhs</code>.
- */
- WCPattern(const CMStringW &rhs);
-protected:
- /**
- This currently is not used, so don't try to do anything with it.
- @memo Holds all the compiled patterns for quick access.
- */
- static std::map<CMStringW, WCPattern*> compiledWCPatterns;
- /**
- Holds all of the registered patterns as strings. Due to certain problems
- with compilation of patterns, especially with capturing groups, this seemed
- to be the best way to do it.
- */
- static std::map<CMStringW, std::pair<CMStringW, unsigned long> > registeredWCPatterns;
-protected:
- /**
- Holds all the NFA nodes used. This makes deletion of a pattern, as well as
- clean-up from an unsuccessful compile much easier and faster.
- */
- std::map<NFAUNode*, bool> nodes;
- /**
- Used when methods like split are called. The matcher class uses a lot of
- dynamic memeory, so having an instance increases speedup of certain
- operations.
- */
- WCMatcher * matcher;
- /**
- The front node of the NFA.
- */
- NFAUNode * head;
- /**
- The actual regular expression we rerpesent
- */
- CMStringW pattern;
- /**
- Flag used during compilation. Once the pattern is successfully compiled,
- <code>error</code> is no longer used.
- */
- bool error;
- /**
- Used during compilation to keep track of the current index into
- <code>{@link pattern pattern}<code>. Once the pattern is successfully
- compiled, <code>error</code> is no longer used.
- */
- int curInd;
- /**
- The number of capture groups this contains.
- */
- int groupCount;
- /**
- The number of non-capture groups this contains.
- */
- int nonCapGroupCount;
- /**
- The flags specified when this was compiled.
- */
- unsigned long flags;
-protected:
- /**
- Raises an error during compilation. Compilation will cease at that point
- and compile will return <code>NULL</code>.
- */
- void raiseError();
- /**
- Convenience function for registering a node in <code>nodes</code>.
- @param node The node to register
- @return The registered node
- */
- NFAUNode * registerNode(NFAUNode * node);
-
- /**
- Calculates the union of two strings. This function will first sort the
- strings and then use a simple selection algorithm to find the union.
- @param s1 The first "class" to union
- @param s2 The second "class" to union
- @return A new string containing all unique characters. Each character
- must have appeared in one or both of <code>s1</code> and
- <code>s2</code>.
- */
- CMStringW classUnion(CMStringW s1, CMStringW s2) const;
- /**
- Calculates the intersection of two strings. This function will first sort
- the strings and then use a simple selection algorithm to find the
- intersection.
- @param s1 The first "class" to intersect
- @param s2 The second "class" to intersect
- @return A new string containing all unique characters. Each character
- must have appeared both <code>s1</code> and <code>s2</code>.
- */
- CMStringW classIntersect(CMStringW s1, CMStringW s2) const;
- /**
- Calculates the negation of a string. The negation is the set of all
- characters between <code>\x00</code> and <code>\xFF</code> not
- contained in <code>s1</code>.
- @param s1 The "class" to be negated.
- @param s2 The second "class" to intersect
- @return A new string containing all unique characters. Each character
- must have appeared both <code>s1</code> and <code>s2</code>.
- */
- CMStringW classNegate(CMStringW s1) const;
- /**
- Creates a new "class" representing the range from <code>low</code> thru
- <code>hi</code>. This function will wrap if <code>low</code> &gt;
- <code>hi</code>. This is a feature, not a buf. Sometimes it is useful
- to be able to say [\x70-\x10] instead of [\x70-\x7F\x00-\x10].
- @param low The beginning character
- @param hi The ending character
- @return A new string containing all the characters from low thru hi.
- */
- CMStringW classCreateRange(wchar_t low, wchar_t hi) const;
-
- /**
- Extracts a decimal number from the substring of member-variable
- <code>{@link pattern pattern}<code> starting at <code>start</code> and
- ending at <code>end</code>.
- @param start The starting index in <code>{@link pattern pattern}<code>
- @param end The last index in <code>{@link pattern pattern}<code>
- @return The decimal number in <code>{@link pattern pattern}<code>
- */
- int getInt(int start, int end);
- /**
- Parses a <code>{n,m}</code> string out of the member-variable
- <code>{@link pattern pattern}<code> stores the result in <code>sNum</code>
- and <code>eNum</code>.
- @param sNum Output parameter. The minimum number of matches required
- by the curly quantifier are stored here.
- @param eNum Output parameter. The maximum number of matches allowed
- by the curly quantifier are stored here.
- @return Success/Failure. Fails when the curly does not have the proper
- syntax
- */
- bool quantifyCurly(int & sNum, int & eNum);
- /**
- Tries to quantify the currently parsed group. If the group being parsed
- is indeed quantified in the member-variable
- <code>{@link pattern pattern}<code>, then the NFA is modified accordingly.
- @param start The starting node of the current group being parsed
- @param stop The ending node of the current group being parsed
- @param gn The group number of the current group being parsed
- @return The node representing the starting node of the group. If the
- group becomes quantified, then this node is not necessarily
- a GroupHead node.
- */
- NFAUNode * quantifyGroup(NFAUNode * start, NFAUNode * stop, const int gn);
-
- /**
- Tries to quantify the last parsed expression. If the character was indeed
- quantified, then the NFA is modified accordingly.
- @param newNode The recently created expression node
- @return The node representing the last parsed expression. If the
- expression was quantified, <code>return value != newNode</code>
- */
- NFAUNode * quantify(NFAUNode * newNode);
- /**
- Parses the current class being examined in
- <code>{@link pattern pattern}</code>.
- @return A string of unique characters contained in the current class being
- parsed
- */
- CMStringW parseClass();
- /**
- Parses the current POSIX class being examined in
- <code>{@link pattern pattern}</code>.
- @return A string of unique characters representing the POSIX class being
- parsed
- */
- CMStringW parsePosix();
- /**
- Returns a string containing the octal character being parsed
- @return The string contained the octal value being parsed
- */
- CMStringW parseOctal();
- /**
- Returns a string containing the hex character being parsed
- @return The string contained the hex value being parsed
- */
- CMStringW parseHex();
- /**
- Returns a new node representing the back reference being parsed
- @return The new node representing the back reference being parsed
- */
- NFAUNode * parseBackref();
- /**
- Parses the escape sequence currently being examined. Determines if the
- escape sequence is a class, a single character, or the beginning of a
- quotation sequence.
- @param inv Output parameter. Whether or not to invert the returned class
- @param quo Output parameter. Whether or not this sequence starts a
- quotation.
- @return The characters represented by the class
- */
- CMStringW parseEscape(bool & inv, bool & quo);
- /**
- Parses a supposed registered pattern currently under compilation. If the
- sequence of characters does point to a registered pattern, then the
- registered pattern is appended to <code>*end<code>. The registered pattern
- is parsed with the current compilation flags.
- @param end The ending node of the thus-far compiled pattern
- @return The new end node of the current pattern
- */
- NFAUNode * parseRegisteredWCPattern(NFAUNode ** end);
- /**
- Parses a lookbehind expression. Appends the necessary nodes
- <code>*end</code>.
- @param pos Positive or negative look behind
- @param end The ending node of the current pattern
- @return The new end node of the current pattern
- */
- NFAUNode * parseBehind(const bool pos, NFAUNode ** end);
- /**
- Parses the current expression and tacks on nodes until a \E is found.
- @return The end of the current pattern
- */
- NFAUNode * parseQuote();
- /**
- Parses <code>{@link pattern pattern}</code>. This function is called
- recursively when an or (<code>|</code>) or a group is encountered.
- @param inParen Are we currently parsing inside a group
- @param inOr Are we currently parsing one side of an or (<code>|</code>)
- @param end The end of the current expression
- @return The starting node of the NFA constructed from this parse
- */
- NFAUNode * parse(const bool inParen = 0, const bool inOr = 0, NFAUNode ** end = NULL);
-public:
- /// We should match regardless of case
- const static unsigned long CASE_INSENSITIVE;
- /// We are implicitly quoted
- const static unsigned long LITERAL;
- /// @memo We should treat a <code><b>.</b></code> as [\x00-\x7F]
- const static unsigned long DOT_MATCHES_ALL;
- /** <code>^</code> and <code>$</code> should anchor to the beginning and
- ending of lines, not all input
- */
- const static unsigned long MULTILINE_MATCHING;
- /** When enabled, only instances of <code>\n</codes> are recognized as
- line terminators
- */
- const static unsigned long UNIX_LINE_MODE;
- /// The absolute minimum number of matches a quantifier can match (0)
- const static int MIN_QMATCH;
- /// The absolute maximum number of matches a quantifier can match (0x7FFFFFFF)
- const static int MAX_QMATCH;
-public:
- /**
- Call this function to compile a regular expression into a
- <code>WCPattern</code> object. Special values can be assigned to
- <code>mode</code> when certain non-standard behaviors are expected from
- the <code>WCPattern</code> object.
- @param pattern The regular expression to compile
- @param mode A bitwise or of flags signalling what special behaviors are
- wanted from this <code>WCPattern</code> object
- @return If successful, <code>compile</code> returns a <code>WCPattern</code>
- pointer. Upon failure, <code>compile</code> returns
- <code>NULL</code>
- */
- static WCPattern * compile(const CMStringW & pattern,
- const unsigned long mode = 0);
- /**
- Dont use this function. This function will compile a pattern, and cache
- the result. This will eventually be used as an optimization when people
- just want to call static methods using the same pattern over and over
- instead of first compiling the pattern and then using the compiled
- instance for matching.
- @param pattern The regular expression to compile
- @param mode A bitwise or of flags signalling what special behaviors are
- wanted from this <code>WCPattern</code> object
- @return If successful, <code>compileAndKeep</code> returns a
- <code>WCPattern</code> pointer. Upon failure, <code>compile</code>
- returns <code>NULL</code>.
- */
- static WCPattern * compileAndKeep(const CMStringW & pattern,
- const unsigned long mode = 0);
-
- /**
- Searches through <code>replace</code> and replaces all substrings matched
- by <code>pattern</code> with <code>str</code>. <code>str</code> may
- contain backreferences (e.g. <code>\1</code>) to capture groups. A typical
- invocation looks like:
- <p>
- <code>
- WCPattern::replace(L"(a+)b(c+)", L"abcccbbabcbabc", L"\\2b\\1");
- </code>
- <p>
- which would replace <code>abcccbbabcbabc</code> with
- <code>cccbabbcbabcba</code>.
- @param pattern The regular expression
- @param str The replacement text
- @param replacementText The string in which to perform replacements
- @param mode The special mode requested of the <code>WCPattern</code>
- during the replacement process
- @return The text with the replacement string substituted where necessary
- */
- static CMStringW replace(const CMStringW & pattern,
- const CMStringW & str,
- const CMStringW & replacementText,
- const unsigned long mode = 0);
-
- /**
- Splits the specified string over occurrences of the specified pattern.
- Empty strings can be optionally ignored. The number of strings returned is
- configurable. A typical invocation looks like:
- <p>
- <code>
- CMStringW str(strSize, 0);<br>
- FILE * fp = fopen(fileName, "r");<br>
- fread((char*)str.data(), strSize * 2, 1, fp);<br>
- fclose(fp);<br>
- <br>
- std::vector&lt;CMStringW&gt; lines = WCPattern::split(L"[\r\n]+", str, true);<br>
- <br>
- </code>
-
- @param pattern The regular expression
- @param replace The string to split
- @param keepEmptys Whether or not to keep empty strings
- @param limit The maximum number of splits to make
- @param mode The special mode requested of the <code>WCPattern</code>
- during the split process
- @return All substrings of <code>str</code> split across <code>pattern</code>.
- */
- static std::vector<CMStringW> split(const CMStringW & pattern,
- const CMStringW & str,
- const bool keepEmptys = 0,
- const unsigned long limit = 0,
- const unsigned long mode = 0);
-
- /**
- Finds all the instances of the specified pattern within the string. You
- should be careful to only pass patterns with a minimum length of one. For
- example, the pattern <code>a*</code> can be matched by an empty string, so
- instead you should pass <code>a+</code> since at least one character must
- be matched. A typical invocation of <code>findAll</code> looks like:
- <p>
- <code>
- std::vector&lt;td::string&gt; numbers = WCPattern::findAll(L"\\d+", string);
- </code>
- <p>
-
- @param pattern The pattern for which to search
- @param str The string to search
- @param mode The special mode requested of the <code>WCPattern</code>
- during the find process
- @return All instances of <code>pattern</code> in <code>str</code>
- */
- static std::vector<CMStringW> findAll(const CMStringW & pattern,
- const CMStringW & str,
- const unsigned long mode = 0);
-
- /**
- Determines if an entire string matches the specified pattern
-
- @param pattern The pattern for to match
- @param str The string to match
- @param mode The special mode requested of the <code>WCPattern</code>
- during the replacement process
- @return True if <code>str</code> is recognized by <code>pattern</code>
- */
- static bool matches(const CMStringW & pattern,
- const CMStringW & str,
- const unsigned long mode = 0);
-
- /**
- Registers a pattern under a specific name for use in later compilations.
- A typical invocation and later use looks like:
- <p>
- <code>
- WCPattern::registerWCPattern(L"ip", L"(?:\\d{1,3}\\.){3}\\d{1,3}");<br>
- WCPattern * p1 = WCPattern::compile(L"{ip}:\\d+");<br>
- WCPattern * p2 = WCPattern::compile(L"Connection from ({ip}) on port \\d+");<br>
- </code>
- <p>
- Multiple calls to <code>registerWCPattern</code> with the same
- <code>name</code> will result in the pattern getting overwritten.
-
- @param name The name to give to the pattern
- @param pattern The pattern to register
- @param mode Any special flags to use when compiling pattern
- @return Success/Failure. Fails only if <code>pattern</code> has invalid
- syntax
- */
- static bool registerWCPattern(const CMStringW & name,
- const CMStringW & pattern,
- const unsigned long mode = 0);
-
- /**
- Clears the pattern registry
- */
- static void unregisterWCPatterns();
- /**
- Don't use
- */
- static void clearWCPatternCache();
-
- /**
- Searches through a string for the <code>n<sup>th</sup></code> match of the
- given pattern in the string. Match indeces start at zero, not one.
- A typical invocation looks like this:
- <p>
- <code>
- std::pair&lt;CMStringW, int&gt; match = WCPattern::findNthMatch(L"\\d{1,3}", L"192.168.1.101:22", 1);<br>
- wprintf(L"%s %i\n", match.first.c_str(), match.second);<br>
- <br>
- Output: 168 4<br>
- <br>
-
- @param pattern The pattern for which to search
- @param str The string to search
- @param matchNum Which match to find
- @param mode Any special flags to use during the matching process
- @return A string and an integer. The string is the string matched. The
- integer is the starting location of the matched string in
- <code>str</code>. You can check for success/failure by making sure
- that the integer returned is greater than or equal to zero.
- */
- static std::pair<CMStringW, int> findNthMatch(const CMStringW & pattern,
- const CMStringW & str,
- const int matchNum,
- const unsigned long mode = 0);
-public:
- /**
- Deletes all NFA nodes allocated during compilation
- */
- ~WCPattern();
-
- CMStringW replace(const CMStringW & str,
- const CMStringW & replacementText);
- std::vector<CMStringW> split(const CMStringW & str, const bool keepEmptys = 0,
- const unsigned long limit = 0);
- std::vector<CMStringW> findAll(const CMStringW & str);
- bool matches(const CMStringW & str);
- /**
- Returns the flags used during compilation of this pattern
- @return The flags used during compilation of this pattern
- */
- unsigned long getFlags() const;
- /**
- Returns the regular expression this pattern represents
- @return The regular expression this pattern represents
- */
- CMStringW getWCPattern() const;
- /**
- Creates a matcher object using the specified string and this pattern.
- @param str The string to match against
- @return A new matcher using object using this pattern and the specified
- string
- */
- WCMatcher * createWCMatcher(const CMStringW & str);
-};
-
-class NFAUNode
-{
- friend class WCMatcher;
-public:
- NFAUNode * next;
- NFAUNode();
- virtual ~NFAUNode();
- virtual void findAllNodes(std::map<NFAUNode*, bool> & soFar);
- virtual int match(const CMStringW & str, WCMatcher * matcher, const int curInd = 0) const = 0;
- inline virtual bool isGroupHeadNode() const { return false; }
- inline virtual bool isStartOfInputNode() const { return false; }
-};
-class NFACharUNode : public NFAUNode
-{
-protected:
- wchar_t ch;
-public:
- NFACharUNode(const wchar_t c);
- virtual int match(const CMStringW & str, WCMatcher * matcher, const int curInd = 0) const;
-};
-class NFACICharUNode : public NFAUNode
-{
-protected:
- wchar_t ch;
-public:
- NFACICharUNode(const wchar_t c);
- virtual int match(const CMStringW & str, WCMatcher * matcher, const int curInd = 0) const;
-};
-class NFAStartUNode : public NFAUNode
-{
-public:
- NFAStartUNode();
- virtual int match(const CMStringW & str, WCMatcher * matcher, const int curInd = 0) const;
-};
-class NFAEndUNode : public NFAUNode
-{
-public:
- NFAEndUNode();
- virtual int match(const CMStringW & str, WCMatcher * matcher, const int curInd = 0) const;
-};
-class NFAQuantifierUNode : public NFAUNode
-{
-public:
- int min, max;
- NFAUNode * inner;
- virtual void findAllNodes(std::map<NFAUNode*, bool> & soFar);
- NFAQuantifierUNode(WCPattern * pat, NFAUNode * internal,
- const int minMatch = WCPattern::MIN_QMATCH,
- const int maxMatch = WCPattern::MAX_QMATCH);
- virtual int match(const CMStringW & str, WCMatcher * matcher, const int curInd = 0) const;
-};
-class NFAGreedyQuantifierUNode : public NFAQuantifierUNode
-{
-public:
- NFAGreedyQuantifierUNode(WCPattern * pat, NFAUNode * internal,
- const int minMatch = WCPattern::MIN_QMATCH,
- const int maxMatch = WCPattern::MAX_QMATCH);
- virtual int match(const CMStringW & str, WCMatcher * matcher, const int curInd = 0) const;
- virtual int matchInternal(const CMStringW & str, WCMatcher * matcher, const int curInd, const int soFar) const;
-};
-class NFALazyQuantifierUNode : public NFAQuantifierUNode
-{
-public:
- NFALazyQuantifierUNode(WCPattern * pat, NFAUNode * internal,
- const int minMatch = WCPattern::MIN_QMATCH,
- const int maxMatch = WCPattern::MAX_QMATCH);
- virtual int match(const CMStringW & str, WCMatcher * matcher, const int curInd = 0) const;
-};
-class NFAPossessiveQuantifierUNode : public NFAQuantifierUNode
-{
-public:
- NFAPossessiveQuantifierUNode(WCPattern * pat, NFAUNode * internal,
- const int minMatch = WCPattern::MIN_QMATCH,
- const int maxMatch = WCPattern::MAX_QMATCH);
- virtual int match(const CMStringW & str, WCMatcher * matcher, const int curInd = 0) const;
-};
-class NFAAcceptUNode : public NFAUNode
-{
-public:
- NFAAcceptUNode();
- virtual int match(const CMStringW & str, WCMatcher * matcher, const int curInd = 0) const;
-};
-class NFAClassUNode : public NFAUNode
-{
-public:
- bool inv;
- std::map<wchar_t, bool> vals;
- NFAClassUNode(const bool invert = 0);
- NFAClassUNode(const CMStringW & clazz, const bool invert);
- virtual int match(const CMStringW & str, WCMatcher * matcher, const int curInd = 0) const;
-};
-class NFACIClassUNode : public NFAUNode
-{
-public:
- bool inv;
- std::map<wchar_t, bool> vals;
- NFACIClassUNode(const bool invert = 0);
- NFACIClassUNode(const CMStringW & clazz, const bool invert);
- virtual int match(const CMStringW & str, WCMatcher * matcher, const int curInd = 0) const;
-};
-class NFASubStartUNode : public NFAUNode
-{
-public:
- NFASubStartUNode();
- virtual int match(const CMStringW & str, WCMatcher * matcher, const int curInd = 0) const;
-};
-class NFAOrUNode : public NFAUNode
-{
-public:
- NFAUNode * one;
- NFAUNode * two;
- NFAOrUNode(NFAUNode * first, NFAUNode * second);
- virtual void findAllNodes(std::map<NFAUNode*, bool> & soFar);
- virtual int match(const CMStringW & str, WCMatcher * matcher, const int curInd = 0) const;
-};
-class NFAQuoteUNode : public NFAUNode
-{
-public:
- CMStringW qStr;
- NFAQuoteUNode(const CMStringW & quoted);
- virtual int match(const CMStringW & str, WCMatcher * matcher, const int curInd = 0) const;
-};
-class NFACIQuoteUNode : public NFAUNode
-{
-public:
- CMStringW qStr;
- NFACIQuoteUNode(const CMStringW & quoted);
- virtual int match(const CMStringW & str, WCMatcher * matcher, const int curInd = 0) const;
-};
-class NFALookAheadUNode : public NFAUNode
-{
-public:
- bool pos;
- NFAUNode * inner;
- NFALookAheadUNode(NFAUNode * internal, const bool positive);
- virtual void findAllNodes(std::map<NFAUNode*, bool> & soFar);
- virtual int match(const CMStringW & str, WCMatcher * matcher, const int curInd = 0) const;
-};
-class NFALookBehindUNode : public NFAUNode
-{
-public:
- bool pos;
- CMStringW mStr;
- NFALookBehindUNode(const CMStringW & str, const bool positive);
- virtual int match(const CMStringW & str, WCMatcher * matcher, const int curInd = 0) const;
-};
-class NFAStartOfLineUNode : public NFAUNode
-{
-public:
- NFAStartOfLineUNode();
- virtual int match(const CMStringW & str, WCMatcher * matcher, const int curInd = 0) const;
-};
-class NFAEndOfLineUNode : public NFAUNode
-{
-public:
- NFAEndOfLineUNode();
- virtual int match(const CMStringW & str, WCMatcher * matcher, const int curInd = 0) const;
-};
-class NFAReferenceUNode : public NFAUNode
-{
-public:
- int gi;
- NFAReferenceUNode(const int groupIndex);
- virtual int match(const CMStringW & str, WCMatcher * matcher, const int curInd = 0) const;
-};
-class NFAStartOfInputUNode : public NFAUNode
-{
-public:
- NFAStartOfInputUNode();
- virtual int match(const CMStringW & str, WCMatcher * matcher, const int curInd = 0) const;
- inline virtual bool isStartOfInputNode() const { return false; }
-};
-class NFAEndOfInputUNode : public NFAUNode
-{
-public:
- bool term;
- NFAEndOfInputUNode(const bool lookForTerm);
- virtual int match(const CMStringW & str, WCMatcher * matcher, const int curInd = 0) const;
-};
-class NFAWordBoundaryUNode : public NFAUNode
-{
-public:
- bool pos;
- NFAWordBoundaryUNode(const bool positive);
- virtual int match(const CMStringW & str, WCMatcher * matcher, const int curInd = 0) const;
-};
-class NFAEndOfMatchUNode : public NFAUNode
-{
-public:
- NFAEndOfMatchUNode();
- virtual int match(const CMStringW & str, WCMatcher * matcher, const int curInd = 0) const;
-};
-class NFAGroupHeadUNode : public NFAUNode
-{
-public:
- int gi;
- NFAGroupHeadUNode(const int groupIndex);
- virtual int match(const CMStringW & str, WCMatcher * matcher, const int curInd = 0) const;
- inline virtual bool isGroupHeadNode() const { return false; }
-};
-class NFAGroupTailUNode : public NFAUNode
-{
-public:
- int gi;
- NFAGroupTailUNode(const int groupIndex);
- virtual int match(const CMStringW & str, WCMatcher * matcher, const int curInd = 0) const;
-};
-class NFAGroupLoopPrologueUNode : public NFAUNode
-{
-public:
- int gi;
- NFAGroupLoopPrologueUNode(const int groupIndex);
- virtual int match(const CMStringW & str, WCMatcher * matcher, const int curInd = 0) const;
-};
-class NFAGroupLoopUNode : public NFAUNode
-{
-public:
- int gi, min, max, type;
- NFAUNode * inner;
- NFAGroupLoopUNode(NFAUNode * internal, const int minMatch,
- const int maxMatch, const int groupIndex, const int matchType);
- virtual void findAllNodes(std::map<NFAUNode*, bool> & soFar);
- virtual int match(const CMStringW & str, WCMatcher * matcher, const int curInd = 0) const;
- int matchGreedy(const CMStringW & str, WCMatcher * matcher, const int curInd = 0) const;
- int matchLazy(const CMStringW & str, WCMatcher * matcher, const int curInd = 0) const;
- int matchPossessive(const CMStringW & str, WCMatcher * matcher, const int curInd = 0) const;
-};
-
-#endif
-
diff --git a/plugins/SmileyAdd/src/smileys.cpp b/plugins/SmileyAdd/src/smileys.cpp
index f66a6e374e..21e879f87e 100644
--- a/plugins/SmileyAdd/src/smileys.cpp
+++ b/plugins/SmileyAdd/src/smileys.cpp
@@ -222,51 +222,42 @@ static DWORD_PTR ConvertServiceParam(MCONTACT hContact, const wchar_t *param)
void SmileyType::CallSmileyService(MCONTACT hContact)
{
- _TPattern *srvsplit = _TPattern::compile(L"(.*)\\|(.*)\\|(.*)");
- _TMatcher *m0 = srvsplit->createWCMatcher(GetTriggerText());
- m0->findFirstMatch();
+ MRegexp16 srvsplit(L"(.*)\\|(.*)\\|(.*)");
+ srvsplit.match(m_TriggerText);
- CMStringW name = m0->getGroup(1);
- CMStringW par1 = m0->getGroup(2);
- CMStringW par2 = m0->getGroup(3);
+ CMStringW name = srvsplit.getGroup(1);
+ CMStringW par1 = srvsplit.getGroup(2);
+ CMStringW par2 = srvsplit.getGroup(3);
- delete m0;
- delete srvsplit;
-
- char str[MAXMODULELABELLENGTH];
const char *proto = "";
-
if (name[0] == '/') {
proto = (const char*)GetContactProto(hContact);
- if (proto == nullptr) return;
+ if (proto == nullptr)
+ return;
}
+
+ char str[MAXMODULELABELLENGTH];
mir_snprintf(str, "%s%s", proto, _T2A(name.c_str()));
CallService(str,
ConvertServiceParam(hContact, par1.c_str()),
ConvertServiceParam(hContact, par2.c_str()));
}
-
-
SmileyPackType::~SmileyPackType()
{
if (m_hSmList != nullptr) ImageList_Destroy(m_hSmList);
}
-static const wchar_t urlRegEx[] =
-L"(?:ftp|https|http|file|aim|webcal|irc|msnim|xmpp|gopher|mailto|news|nntp|telnet|wais|prospero)://?[\\w.?%:/$+;]*";
+static const wchar_t urlRegEx[] = L"(?:ftp|https|http|file|aim|webcal|irc|msnim|xmpp|gopher|mailto|news|nntp|telnet|wais|prospero)://?[\\w.?%:/$+;]*";
static const wchar_t pathRegEx[] = L"[\\s\"][a-zA-Z]:[\\\\/][\\w.\\-\\\\/]*";
static const wchar_t timeRegEx[] = L"\\d{1,2}:\\d{2}:\\d{2}|\\d{1,2}:\\d{2}";
void SmileyPackType::AddTriggersToSmileyLookup(void)
{
- _TPattern *p = _TPattern::compile(L"\\s+");
- {
- CMStringW emptystr;
- m_SmileyLookup.insert(new SmileyLookup(urlRegEx, true, -1, emptystr));
- m_SmileyLookup.insert(new SmileyLookup(pathRegEx, true, -1, emptystr));
- m_SmileyLookup.insert(new SmileyLookup(timeRegEx, true, -1, emptystr));
- }
+ CMStringW emptystr;
+ m_SmileyLookup.insert(new SmileyLookup(urlRegEx, true, -1, emptystr));
+ m_SmileyLookup.insert(new SmileyLookup(pathRegEx, true, -1, emptystr));
+ m_SmileyLookup.insert(new SmileyLookup(timeRegEx, true, -1, emptystr));
for (int dist = 0; dist < m_SmileyList.getCount(); dist++) {
if (m_SmileyList[dist].IsRegEx()) {
@@ -280,50 +271,34 @@ void SmileyPackType::AddTriggersToSmileyLookup(void)
}
else if (!m_SmileyList[dist].IsService()) {
bool first = true;
- int li = 0;
- _TMatcher *m0 = p->createWCMatcher(m_SmileyList[dist].GetTriggerText());
- while (m0->findNextMatch()) {
- int stind = m0->getStartingIndex();
- if (li != stind) {
- CMStringW out;
- ReplaceAllSpecials(m0->getString().Mid(li, stind - li), out);
- SmileyLookup *dats = new SmileyLookup(out, false, dist, GetFilename());
- if (dats->IsValid()) {
- m_SmileyLookup.insert(dats);
- if (first) {
- m_SmileyList[dist].m_InsertText = out;
- first = false;
- }
- } // fallthrough
- }
- li = m0->getEndingIndex();
- }
-
- int stind = (int)m0->getString().GetLength();
- if (li < stind) {
- CMStringW out;
- ReplaceAllSpecials(m0->getString().Mid(li, stind - li), out);
- SmileyLookup *dats = new SmileyLookup(out, false, dist, GetFilename());
+ const CMStringW &text = m_SmileyList[dist].GetTriggerText();
+ int iStart = 0;
+ while (true) {
+ CMStringW wszWord = text.Tokenize(L" \t", iStart);
+ if (iStart == -1)
+ break;
+
+ ReplaceAllSpecials(wszWord, wszWord);
+ SmileyLookup *dats = new SmileyLookup(wszWord, false, dist, GetFilename());
if (dats->IsValid()) {
m_SmileyLookup.insert(dats);
if (first) {
- m_SmileyList[dist].m_InsertText = out;
+ m_SmileyList[dist].m_InsertText = wszWord;
first = false;
}
}
- else
- delete dats;
+ else delete dats;
}
- delete m0;
}
}
- delete p;
}
void SmileyPackType::ReplaceAllSpecials(const CMStringW &Input, CMStringW &Output)
{
- Output = _TPattern::replace(L"%%_{1,2}%%", Input, L" ");
- Output = _TPattern::replace(L"%%''%%", Output, L"\"");
+ Output = Input;
+ Output.Replace(L"%%_%%", L" ");
+ Output.Replace(L"%%__%%", L" ");
+ Output.Replace(L"%%''%%", L"\"");
}
void SmileyPackType::Clear(void)
@@ -353,7 +328,7 @@ bool SmileyPackType::LoadSmileyFile(const CMStringW &filename, const CMStringW &
CMStringW modpath;
pathToAbsolute(filename, modpath);
- // Load xep file
+ // Load file
int fh = _wopen(modpath.c_str(), _O_BINARY | _O_RDONLY);
if (fh == -1) {
if (!noerr) {
@@ -375,7 +350,7 @@ bool SmileyPackType::LoadSmileyFile(const CMStringW &filename, const CMStringW &
// Allocate file buffer
char *buf = new char[flen + sizeof(wchar_t)];
- // Read xep file in
+ // Read file in
int len = _read(fh, buf, flen);
*(wchar_t*)(buf + len) = 0;
@@ -393,321 +368,145 @@ bool SmileyPackType::LoadSmileyFile(const CMStringW &filename, const CMStringW &
delete[] buf;
- bool res;
- if (filename.Find(L".xep") == -1)
- res = LoadSmileyFileMSL(tbuf, onlyInfo, modpath);
- else
- res = LoadSmileyFileXEP(tbuf, onlyInfo, modpath);
-
- if (errorFound)
- ReportError(TranslateT("There were problems loading smiley pack (it should be corrected).\nSee network log for details."));
-
- return res;
-}
-
-bool SmileyPackType::LoadSmileyFileMSL(CMStringW &tbuf, bool onlyInfo, CMStringW &modpath)
-{
CMStringW pathstr, packstr;
{
- _TPattern *pathsplit = _TPattern::compile(L"(.*\\\\)(.*)\\.|$");
- _TMatcher *m0 = pathsplit->createWCMatcher(modpath);
- m0->findFirstMatch();
- pathstr = m0->getGroup(1);
- packstr = m0->getGroup(2);
- delete m0;
- delete pathsplit;
- }
- {
- _TPattern *otherf = _TPattern::compile(
- L"^\\s*(Name|Author|Date|Version|ButtonSmiley)\\s*=\\s*\"(.*)\"",
- _TPattern::MULTILINE_MATCHING);
-
- _TMatcher *m0 = otherf->createWCMatcher(tbuf);
- while (m0->findNextMatch()) {
- if (m0->getGroup(1) == L"Name") m_Name = m0->getGroup(2);
- if (m0->getGroup(1) == L"Author") m_Author = m0->getGroup(2);
- if (m0->getGroup(1) == L"Date") m_Date = m0->getGroup(2);
- if (m0->getGroup(1) == L"Version") m_Version = m0->getGroup(2);
- if (m0->getGroup(1) == L"ButtonSmiley") m_ButtonSmiley = m0->getGroup(2);
- }
- delete m0;
- delete otherf;
+ MRegexp16 pathsplit(L"(.*\\\\)(.*)\\.|$");
+ pathsplit.match(modpath);
+
+ pathstr = pathsplit.getGroup(1);
+ packstr = pathsplit.getGroup(2);
}
- if (!onlyInfo) {
+ if (!onlyInfo)
selec.x = selec.y = win.x = win.y = 0;
- {
- _TPattern *pat = _TPattern::compile(
- L"^\\s*(Selection|Window)Size\\s*=\\s*(\\d+)\\s*,\\s*(\\d+)",
- _TPattern::MULTILINE_MATCHING);
- _TMatcher *m0 = pat->createWCMatcher(tbuf);
- while (m0->findNextMatch()) {
- POINT tpt;
- tpt.x = _wtol(m0->getGroup(2).c_str());
- tpt.y = _wtol(m0->getGroup(3).c_str());
-
- if (m0->getGroup(1) == L"Selection")
- selec = tpt;
- else if (m0->getGroup(1) == L"Window")
- win = tpt;
- }
- delete m0;
- delete pat;
- }
-
- _TPattern *smiley = _TPattern::compile(
- L"^\\s*Smiley(\\*)?\\s*=" // Is Hidden
- L"(?:\\s*\"(.*)\")" // Smiley file name
- L"(?:[\\s,]+(\\-?\\d+))" // Icon resource id
- L"(?:[\\s,]+(R|S)?\"(.*?)\")" // Trigger text
- L"(?:[\\s,]+\"(.*?)\")?" // Tooltip or insert text
- L"(?:[\\s,]+\"(.*?)\")?", // Tooltip text
- _TPattern::MULTILINE_MATCHING);
-
- SmileyVectorType hiddenSmileys;
- unsigned smnum = 0;
- {
- _TMatcher *m0 = smiley->createWCMatcher(tbuf);
- while (m0->findNextMatch()) {
- CMStringW resname = m0->getGroup(2);
- if (resname.Find(L"http://") != -1) {
- if (GetSmileyFile(resname, packstr))
- continue;
- }
- else if (!resname.IsEmpty())
- resname.Insert(0, pathstr);
-
- SmileyType *dat = new SmileyType;
- const int iconIndex = _wtol(m0->getGroup(3).c_str());
-
- dat->SetHidden(m0->getStartingIndex(1) >= 0);
- if (m0->getStartingIndex(4) >= 0) {
- dat->SetRegEx(m0->getGroup(4) == L"R");
- dat->SetService(m0->getGroup(4) == L"S");
- }
- dat->m_TriggerText = m0->getGroup(5);
- if (dat->IsRegEx()) {
- if (m0->getStartingIndex(6) >= 0)
- ReplaceAllSpecials(m0->getGroup(6), dat->m_InsertText);
-
- if (m0->getStartingIndex(7) >= 0)
- ReplaceAllSpecials(m0->getGroup(7), dat->m_ToolText);
- else
- dat->m_ToolText = dat->m_InsertText;
- }
- else {
- if (m0->getStartingIndex(6) >= 0)
- ReplaceAllSpecials(m0->getGroup(6), dat->m_ToolText);
- else
- ReplaceAllSpecials(dat->m_TriggerText, dat->m_ToolText);
- }
+ int iStart = 0;
+ MRegexp16 otherf(L"^\\s*(Name|Author|Date|Version|ButtonSmiley)\\s*=\\s*\"(.*)\"");
+ MRegexp16 size(L"^\\s*(Selection|Window)Size\\s*=\\s*(\\d+)\\s*,\\s*(\\d+)");
+ MRegexp16 smiley(
+ L"^\\s*Smiley(\\*)?\\s*=" // Is Hidden
+ L"(?:\\s*\"(.*)\")" // Smiley file name
+ L"(?:[\\s,]+(\\-?\\d+))" // Icon resource id
+ L"(?:[\\s,]+(R|S)?\"(.*?)\")" // Trigger text
+ L"(?:[\\s,]+\"(.*?)\")?" // Tooltip or insert text
+ L"(?:[\\s,]+\"(.*?)\")?"); // Tooltip text
+
+ SmileyVectorType hiddenSmileys;
+ unsigned smnum = 0;
+
+ while (true) {
+ CMStringW line = tbuf.Tokenize(L"\r\n", iStart);
+ if (iStart == -1)
+ break;
- bool noerr;
- if (resname.IsEmpty()) {
- dat->SetHidden(true);
- dat->SetText(true);
- noerr = true;
- }
- else noerr = dat->LoadFromResource(resname, iconIndex);
+ if (line.IsEmpty() || line[0] == ';')
+ continue;
- if (dat->IsHidden())
- hiddenSmileys.insert(dat);
- else
- m_SmileyList.insert(dat);
-
- if (!noerr) {
- static const wchar_t errmsg[] = LPGENW("Smiley #%u in file %s for smiley pack %s not found.");
- wchar_t msgtxt[1024];
- mir_snwprintf(msgtxt, TranslateW(errmsg), smnum, resname.c_str(), modpath.c_str());
- Netlib_LogW(hNetlibUser, msgtxt);
- errorFound = true;
- }
- smnum++;
- }
- delete smiley;
- delete m0;
+ if (otherf.match(line) >= 0) {
+ CMStringW key(otherf.getGroup(1)), value(otherf.getGroup(2));
+ if (key == L"Name")
+ m_Name = value;
+ else if (key == L"Author")
+ m_Author = value;
+ else if (key == L"Date")
+ m_Date = value;
+ else if (key == L"Version")
+ m_Version = value;
+ else if (key == L"ButtonSmiley")
+ m_ButtonSmiley = value;
+ continue;
}
- m_VisibleCount = m_SmileyList.getCount();
-
- m_SmileyList.splice(hiddenSmileys);
-
- AddTriggersToSmileyLookup();
- }
-
- return true;
-}
-
-
-static void DecodeHTML(CMStringW &str)
-{
- if (str.Find('&') != -1) {
- str = _TPattern::replace(CMStringW(L"&lt;"), str, CMStringW(L"<"));
- str = _TPattern::replace(CMStringW(L"&gt;"), str, CMStringW(L">"));
- }
-}
-
-
-static IStream* DecodeBase64Data(const char *pData)
-{
- unsigned dataLen;
- ptrA data((char*)mir_base64_decode(pData, &dataLen));
- if (data == NULL)
- return nullptr;
-
- // Read image list
- HGLOBAL hBuffer = GlobalAlloc(GMEM_MOVEABLE, dataLen);
- if (!hBuffer)
- return nullptr;
-
- void *dst = GlobalLock(hBuffer);
- memcpy(dst, data, dataLen);
- GlobalUnlock(hBuffer);
-
- IStream *pStream = nullptr;
- CreateStreamOnHGlobal(hBuffer, TRUE, &pStream);
- return pStream;
-}
+ if (onlyInfo)
+ continue;
+ if (size.match(line) >= 0) {
+ POINT tpt;
+ tpt.x = _wtol(size.getGroup(2));
+ tpt.y = _wtol(size.getGroup(3));
-bool SmileyPackType::LoadSmileyFileXEP(CMStringW &tbuf, bool onlyInfo, CMStringW&)
-{
- _TMatcher *m0, *m1, *m2;
-
- _TPattern *dbname_re = _TPattern::compile(L"<DataBaseName>\\s*\"(.*?)\"\\s*</DataBaseName>",
- _TPattern::MULTILINE_MATCHING);
- _TPattern *author_re = _TPattern::compile(L"<PackageAuthor>\\s*\"(.*?)\"\\s*</PackageAuthor>",
- _TPattern::MULTILINE_MATCHING);
- _TPattern *settings_re = _TPattern::compile(L"<settings>(.*?)</settings>",
- _TPattern::MULTILINE_MATCHING | _TPattern::DOT_MATCHES_ALL);
-
- m0 = settings_re->createWCMatcher(tbuf);
- if (m0->findFirstMatch()) {
- CMStringW settings = m0->getGroup(1);
-
- m1 = author_re->createWCMatcher(settings);
- if (m1->findFirstMatch()) {
- m_Author = m1->getGroup(1);
- DecodeHTML(m_Author);
+ if (size.getGroup(1) == L"Selection")
+ selec = tpt;
+ else if (size.getGroup(1) == L"Window")
+ win = tpt;
+ continue;
}
- delete m1;
- m1 = dbname_re->createWCMatcher(settings);
- if (m1->findFirstMatch()) {
- m_Name = m1->getGroup(1);
- DecodeHTML(m_Name);
- }
- delete m1;
- }
- delete m0;
-
- delete dbname_re;
- delete author_re;
- delete settings_re;
-
- if (!onlyInfo) {
- _TPattern *record_re = _TPattern::compile(L"<record.*?ImageIndex=\"(.*?)\".*?>(?:\\s*\"(.*?)\"?(.*?)</record>)",
- _TPattern::MULTILINE_MATCHING | _TPattern::DOT_MATCHES_ALL);
- _TPattern *expression_re = _TPattern::compile(L"<Expression>\\s*\"(.*?)\"\\s*</Expression>",
- _TPattern::MULTILINE_MATCHING);
- _TPattern *pastetext_re = _TPattern::compile(L"<PasteText>\\s*\"(.*?)\"\\s*</PasteText>",
- _TPattern::MULTILINE_MATCHING);
- _TPattern *images_re = _TPattern::compile(L"<images>(.*?)</images>",
- _TPattern::MULTILINE_MATCHING | _TPattern::DOT_MATCHES_ALL);
- _TPattern *image_re = _TPattern::compile(L"<Image>(.*?)</Image>",
- _TPattern::MULTILINE_MATCHING | _TPattern::DOT_MATCHES_ALL);
- _TPattern *imagedt_re = _TPattern::compile(L"<!\\[CDATA\\[(.*?)\\]\\]>",
- _TPattern::MULTILINE_MATCHING);
-
- m0 = images_re->createWCMatcher(tbuf);
- if (m0->findFirstMatch()) {
- CMStringW images = m0->getGroup(1);
-
- m1 = imagedt_re->createWCMatcher(images);
- if (m1->findFirstMatch()) {
- IStream *pStream = DecodeBase64Data(_T2A(m1->getGroup(1).c_str()));
- if (pStream != nullptr) {
- if (m_hSmList != nullptr) ImageList_Destroy(m_hSmList);
- m_hSmList = ImageList_Read(pStream);
- pStream->Release();
- }
+ if (smiley.match(line)) {
+ CMStringW resname = smiley.getGroup(2);
+ if (resname.Find(L"http://") != -1) {
+ if (GetSmileyFile(resname, packstr))
+ continue;
}
- delete m1;
- }
- delete m0;
+ else if (!resname.IsEmpty())
+ resname.Insert(0, pathstr);
- m0 = record_re->createWCMatcher(tbuf);
- while (m0->findNextMatch()) {
SmileyType *dat = new SmileyType;
- dat->SetRegEx(true);
- dat->SetImList(m_hSmList, _wtol(m0->getGroup(1).c_str()));
- dat->m_ToolText = m0->getGroup(2);
- DecodeHTML(dat->m_ToolText);
+ const int iconIndex = _wtol(smiley.getGroup(3));
- CMStringW rec = m0->getGroup(3);
+ dat->SetHidden(!smiley.getGroup(1).IsEmpty());
- m1 = expression_re->createWCMatcher(rec);
- if (m1->findFirstMatch()) {
- dat->m_TriggerText = m1->getGroup(1);
- DecodeHTML(dat->m_TriggerText);
+ CMStringW wszGrp4(smiley.getGroup(4));
+ if (!wszGrp4.IsEmpty()) {
+ dat->SetRegEx(wszGrp4 == L"R");
+ dat->SetService(wszGrp4 == L"S");
}
- delete m1;
- m1 = pastetext_re->createWCMatcher(rec);
- if (m1->findFirstMatch()) {
- dat->m_InsertText = m1->getGroup(1);
- DecodeHTML(dat->m_InsertText);
+ dat->m_TriggerText = smiley.getGroup(5);
+
+ CMStringW wszGrp6(smiley.getGroup(6)), wszGrp7(smiley.getGroup(7));
+ if (dat->IsRegEx()) {
+ if (!wszGrp6.IsEmpty())
+ ReplaceAllSpecials(wszGrp6, dat->m_InsertText);
+
+ if (!wszGrp7.IsEmpty())
+ ReplaceAllSpecials(wszGrp7, dat->m_ToolText);
+ else
+ dat->m_ToolText = dat->m_InsertText;
}
- delete m1;
- dat->SetHidden(dat->m_InsertText.IsEmpty());
-
- m1 = image_re->createWCMatcher(rec);
- if (m1->findFirstMatch()) {
- CMStringW images = m1->getGroup(1);
-
- m2 = imagedt_re->createWCMatcher(images);
- if (m2->findFirstMatch()) {
- IStream *pStream = DecodeBase64Data(_T2A(m2->getGroup(1).c_str()));
- if (pStream != nullptr) {
- dat->LoadFromImage(pStream);
- pStream->Release();
- }
- }
- delete m2;
+ else {
+ if (!wszGrp6.IsEmpty())
+ ReplaceAllSpecials(wszGrp6, dat->m_ToolText);
+ else
+ ReplaceAllSpecials(dat->m_TriggerText, dat->m_ToolText);
+ }
+
+ if (resname.IsEmpty()) {
+ dat->SetHidden(true);
+ dat->SetText(true);
+ noerr = true;
}
- delete m1;
+ else noerr = dat->LoadFromResource(resname, iconIndex);
- m_SmileyList.insert(dat);
+ if (dat->IsHidden())
+ hiddenSmileys.insert(dat);
+ else
+ m_SmileyList.insert(dat);
+
+ if (!noerr) {
+ static const wchar_t errmsg[] = LPGENW("Smiley #%u in file %s for smiley pack %s not found.");
+ wchar_t msgtxt[1024];
+ mir_snwprintf(msgtxt, TranslateW(errmsg), smnum, resname.c_str(), modpath.c_str());
+ Netlib_LogW(hNetlibUser, msgtxt);
+ errorFound = true;
+ }
+ smnum++;
}
- delete m0;
-
- delete record_re;
- delete expression_re;
- delete pastetext_re;
- delete images_re;
- delete image_re;
- delete imagedt_re;
}
m_VisibleCount = m_SmileyList.getCount();
-
+ m_SmileyList.splice(hiddenSmileys);
AddTriggersToSmileyLookup();
- selec.x = 0;
- selec.y = 0;
- win.x = 0;
- win.y = 0;
+ if (errorFound)
+ ReportError(TranslateT("There were problems loading smiley pack (it should be corrected).\nSee network log for details."));
return true;
}
-
-//
+/////////////////////////////////////////////////////////////////////////////////////////
// SmileyPackListType
-//
-
bool SmileyPackListType::AddSmileyPack(CMStringW &filename, CMStringW &packname)
{
@@ -724,7 +523,6 @@ bool SmileyPackListType::AddSmileyPack(CMStringW &filename, CMStringW &packname)
return res;
}
-
SmileyPackType* SmileyPackListType::GetSmileyPack(CMStringW &filename)
{
CMStringW modpath;
@@ -743,11 +541,8 @@ void SmileyPackListType::ClearAndFreeAll()
m_SmileyPacks.destroy();
}
-
-//
+/////////////////////////////////////////////////////////////////////////////////////////
// SmileyCategoryType
-//
-
SmileyCategoryType::SmileyCategoryType(SmileyPackListType *pSPS, const CMStringW &name,
const CMStringW &displayName, const CMStringW &defaultFilename, SmcType typ)
@@ -775,21 +570,18 @@ void SmileyCategoryType::Load(void)
}
}
-
SmileyPackType* SmileyCategoryType::GetSmileyPack(void)
{
return m_pSmileyPackStore->GetSmileyPack(m_Filename);
}
-
void SmileyCategoryType::SaveSettings(void)
{
opt.WritePackFileName(m_Filename, m_Name);
}
-//
+/////////////////////////////////////////////////////////////////////////////////////////
// SmileyCategoryListType
-//
void SmileyCategoryListType::ClearAndLoadAll(void)
{
@@ -799,7 +591,6 @@ void SmileyCategoryListType::ClearAndLoadAll(void)
m_SmileyCategories[i].Load();
}
-
SmileyCategoryType* SmileyCategoryListType::GetSmileyCategory(const CMStringW &name)
{
for (int i = 0; i < m_SmileyCategories.getCount(); i++)
@@ -809,20 +600,17 @@ SmileyCategoryType* SmileyCategoryListType::GetSmileyCategory(const CMStringW &n
return nullptr;
}
-
SmileyCategoryType* SmileyCategoryListType::GetSmileyCategory(unsigned index)
{
return index < (unsigned)m_SmileyCategories.getCount() ? &m_SmileyCategories[index] : nullptr;
}
-
SmileyPackType* SmileyCategoryListType::GetSmileyPack(CMStringW &categoryname)
{
SmileyCategoryType *smc = GetSmileyCategory(categoryname);
return smc != nullptr ? smc->GetSmileyPack() : nullptr;
}
-
void SmileyCategoryListType::SaveSettings(void)
{
CMStringW catstr;
@@ -836,7 +624,6 @@ void SmileyCategoryListType::SaveSettings(void)
opt.WriteCustomCategories(catstr);
}
-
void SmileyCategoryListType::AddAndLoad(const CMStringW &name, const CMStringW &displayName)
{
if (GetSmileyCategory(name) != nullptr)
@@ -848,14 +635,12 @@ void SmileyCategoryListType::AddAndLoad(const CMStringW &name, const CMStringW &
m_SmileyCategories[m_SmileyCategories.getCount() - 1].Load();
}
-
void SmileyCategoryListType::AddCategory(const CMStringW &name, const CMStringW &displayName, SmcType typ, const CMStringW &defaultFilename)
{
if (GetSmileyCategory(name) == nullptr)
m_SmileyCategories.insert(new SmileyCategoryType(m_pSmileyPackStore, name, displayName, defaultFilename, typ));
}
-
bool SmileyCategoryListType::DeleteCustomCategory(int index)
{
if (index < m_SmileyCategories.getCount()) {
@@ -1056,60 +841,37 @@ static const CMStringW testString(L"Test String");
SmileyLookup::SmileyLookup(const CMStringW &str, const bool regexs, const int ind, const CMStringW &smpt)
{
- wchar_t msgtxt[1024];
-
m_ind = ind;
if (regexs) {
- m_pattern = _TPattern::compile(str);
- m_valid = m_pattern != nullptr;
- if (m_valid) {
- _TMatcher *matcher = m_pattern->createWCMatcher(testString);
- m_valid &= (!matcher->findFirstMatch() ||
- matcher->getStartingIndex() != matcher->getEndingIndex());
- if (!m_valid) {
- static const wchar_t errmsg[] = LPGENW("Regular expression \"%s\" in smiley pack \"%s\" could produce \"empty matches\".");
- mir_snwprintf(msgtxt, TranslateW(errmsg), str.c_str(), smpt.c_str());
- }
- delete matcher;
- }
- else {
- static const wchar_t errmsg[] = LPGENW("Regular expression \"%s\" in smiley pack \"%s\" malformed.");
- mir_snwprintf(msgtxt, TranslateW(errmsg), str.c_str(), smpt.c_str());
- }
-
- if (!m_valid)
+ m_pattern.compile(str);
+ m_valid = m_pattern.isValid();
+ if (!m_valid) {
+ wchar_t msgtxt[1024];
+ mir_snwprintf(msgtxt, TranslateT("Regular expression \"%s\" in smiley pack \"%s\" malformed."), str.c_str(), smpt.c_str());
Netlib_LogW(hNetlibUser, msgtxt);
+ }
}
else {
m_text = str;
- m_pattern = nullptr;
m_valid = !str.IsEmpty();
}
}
-
SmileyLookup::~SmileyLookup()
{
- delete m_pattern;
}
-
-void SmileyLookup::Find(const CMStringW &str, SmileyLocVecType &smlcur, bool firstOnly) const
+void SmileyLookup::Find(const CMStringW &str, SmileyLocVecType &smlcur, bool firstOnly)
{
if (!m_valid) return;
if (m_text.IsEmpty()) {
- _TMatcher *matcher = m_pattern->createWCMatcher(str);
- while (matcher->findNextMatch()) {
- int st = matcher->getStartingIndex();
- int sz = matcher->getEndingIndex() - st;
- if (sz != 0) {
- smlcur.insert(new SmileyLocType(st, sz));
- if (firstOnly && m_ind != -1)
- return;
- }
+ while (m_pattern.nextMatch(str) >= 0) {
+ CMStringW wszMatch(m_pattern.getMatch());
+ smlcur.insert(new SmileyLocType(m_pattern.getPos(), wszMatch.GetLength()));
+ if (firstOnly && m_ind != -1)
+ return;
}
- delete matcher;
}
else {
const wchar_t *pos = str.c_str();
diff --git a/plugins/SmileyAdd/src/smileys.h b/plugins/SmileyAdd/src/smileys.h
index e21687d674..6eca91c18b 100644
--- a/plugins/SmileyAdd/src/smileys.h
+++ b/plugins/SmileyAdd/src/smileys.h
@@ -130,7 +130,7 @@ template<class T> struct SMOBJLIST : public OBJLIST<T>
class SmileyLookup
{
private:
- _TPattern *m_pattern;
+ MRegexp16 m_pattern;
int m_ind;
CMStringW m_text;
@@ -145,11 +145,11 @@ public:
};
typedef SMOBJLIST<SmileyLocType> SmileyLocVecType;
- SmileyLookup() { m_ind = 0; m_valid = false; m_pattern = NULL; };
+ SmileyLookup() : m_pattern(L"") { m_ind = 0; m_valid = false; m_pattern = NULL; };
SmileyLookup(const CMStringW &str, const bool regexs, const int ind, const CMStringW &smpt);
~SmileyLookup();
- void Find(const CMStringW &str, SmileyLocVecType &smlcur, bool firstOnly) const;
+ void Find(const CMStringW &str, SmileyLocVecType &smlcur, bool firstOnly);
int GetIndex(void) const { return m_ind; }
bool IsValid(void) const { return m_valid; }
};
@@ -182,8 +182,6 @@ private:
void AddTriggersToSmileyLookup(void);
void ReplaceAllSpecials(const CMStringW &Input, CMStringW &Output);
- bool LoadSmileyFileMSL(CMStringW &tbuf, bool onlyInfo, CMStringW &modpath);
- bool LoadSmileyFileXEP(CMStringW &tbuf, bool onlyInfo, CMStringW &modpath);
public:
SmileyPackType();
diff --git a/plugins/SmileyAdd/src/stdafx.h b/plugins/SmileyAdd/src/stdafx.h
index 0beb3b3005..227d1744fb 100644
--- a/plugins/SmileyAdd/src/stdafx.h
+++ b/plugins/SmileyAdd/src/stdafx.h
@@ -65,6 +65,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <m_icolib.h>
#include <m_genmenu.h>
#include <m_imgsrvc.h>
+#include <m_regexp.h>
#include <m_string.h>
#include <m_fontservice.h>
@@ -72,12 +73,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <m_smileyadd.h>
#include <m_folders.h>
-#include "regexp/wcpattern.h"
-#include "regexp/wcmatcher.h"
-
-typedef WCPattern _TPattern;
-typedef WCMatcher _TMatcher;
-
#include "resource.h"
#include "version.h"
#include "imagecache.h"
diff --git a/plugins/SmileyAdd/src/version.h b/plugins/SmileyAdd/src/version.h
index 084efc5042..8d5a256e61 100644
--- a/plugins/SmileyAdd/src/version.h
+++ b/plugins/SmileyAdd/src/version.h
@@ -1,7 +1,7 @@
#define __MAJOR_VERSION 0
-#define __MINOR_VERSION 2
-#define __RELEASE_NUM 4
-#define __BUILD_NUM 2
+#define __MINOR_VERSION 3
+#define __RELEASE_NUM 0
+#define __BUILD_NUM 1
#include <stdver.h>
diff --git a/plugins/Watrack_MPD/src/options.cpp b/plugins/Watrack_MPD/src/options.cpp
index 13313079d0..b615ee3826 100755
--- a/plugins/Watrack_MPD/src/options.cpp
+++ b/plugins/Watrack_MPD/src/options.cpp
@@ -16,66 +16,45 @@
#include "stdafx.h"
-static INT_PTR CALLBACK DlgProcWaMpdOpts(HWND hwndDlg, UINT msg, WPARAM, LPARAM lParam)
+class COptWaMpdDlg : public CDlgBase
{
- switch (msg)
- {
- case WM_INITDIALOG:
- {
- TranslateDialogDefault(hwndDlg);
- SetDlgItemInt(hwndDlg, IDC_PORT, db_get_w(NULL, szModuleName, "Port", 6600), FALSE);
+public:
+ COptWaMpdDlg() : CDlgBase(hInst, IDD_OPT_WA_MPD),
+ edit_PORT(this, IDC_PORT), edit_SERVER(this, IDC_SERVER), edit_PASSWORD(this, IDC_PASSWORD)
+ {}
+ virtual void OnInitDialog() override
+ {
+ edit_PORT.SetInt(db_get_w(NULL, szModuleName, "Port", 6600));
wchar_t *tmp = UniGetContactSettingUtf(NULL, szModuleName, "Server", L"127.0.0.1");
- SetDlgItemText(hwndDlg, IDC_SERVER, tmp);
+ edit_SERVER.SetText(tmp);
mir_free(tmp);
tmp = UniGetContactSettingUtf(NULL, szModuleName, "Password", L"");
- SetDlgItemText(hwndDlg, IDC_PASSWORD, tmp);
+ edit_PASSWORD.SetText(tmp);
mir_free(tmp);
- return TRUE;
- }
-
-
- case WM_COMMAND:
- {
- SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
- break;
- }
-
- case WM_NOTIFY:
- {
- switch (((LPNMHDR)lParam)->code)
- {
-
- case PSN_APPLY:
- {
- wchar_t szText[256];
- db_set_w(NULL, szModuleName, "Port", (WORD)GetDlgItemInt(hwndDlg, IDC_PORT, nullptr, FALSE));
- gbPort = (WORD)GetDlgItemInt(hwndDlg, IDC_PORT, nullptr, FALSE);
- GetDlgItemText(hwndDlg, IDC_SERVER, szText, _countof(szText));
- db_set_ws(NULL, szModuleName, "Server", szText);
- mir_wstrcpy(gbHost, szText);
- GetDlgItemText(hwndDlg, IDC_PASSWORD, szText, _countof(szText));
- db_set_ws(NULL, szModuleName, "Password", szText);
- mir_wstrcpy(gbPassword, szText);
- return TRUE;
- }
- }
- }
- break;
- }
+ }
+ virtual void OnApply() override
+ {
+ db_set_w(NULL, szModuleName, "Port", (WORD)edit_PORT.GetInt());
+ gbPort = edit_PORT.GetInt();
+ db_set_ws(NULL, szModuleName, "Server", edit_SERVER.GetText());
+ mir_wstrcpy(gbHost, edit_SERVER.GetText());
+ db_set_ws(NULL, szModuleName, "Password", edit_PASSWORD.GetText());
+ mir_wstrcpy(gbPassword, edit_PASSWORD.GetText());
+ }
+private:
+ CCtrlSpin edit_PORT;
+ CCtrlEdit edit_SERVER, edit_PASSWORD;
+};
- return FALSE;
-}
int WaMpdOptInit(WPARAM wParam,LPARAM)
{
OPTIONSDIALOGPAGE odp = { 0 };
- odp.hInstance = hInst;
- odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPT_WA_MPD);
odp.szTitle.w = LPGENW("Winamp Track");
odp.szGroup.w = LPGENW("Plugins");
odp.szTab.w = LPGENW("Watrack MPD");
odp.flags=ODPF_BOLDGROUPS|ODPF_UNICODE;
- odp.pfnDlgProc = DlgProcWaMpdOpts;
+ odp.pDialog = new COptWaMpdDlg();
Options_AddPage(wParam, &odp);
return 0;
}
diff --git a/plugins/Watrack_MPD/src/stdafx.h b/plugins/Watrack_MPD/src/stdafx.h
index 914126d34d..c9a6a3f014 100755
--- a/plugins/Watrack_MPD/src/stdafx.h
+++ b/plugins/Watrack_MPD/src/stdafx.h
@@ -24,6 +24,7 @@
#include <m_utils.h>
#include <m_options.h>
#include <m_langpack.h>
+#include <m_gui.h>
#include <m_music.h>