diff options
author | George Hazan <ghazan@miranda.im> | 2018-02-16 22:07:43 +0200 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2018-02-16 22:08:26 +0200 |
commit | 8d127430d057891fbd3ac5989d32090715d7923a (patch) | |
tree | 2c02b3401ca7a583302730161c3e11ec9607c1f4 /plugins | |
parent | 9cde0c92420f4811a646964c1304f7c55f8a50a5 (diff) |
fixes #1143 (CmdLine Plugin error when using Diacritics in message)
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/CmdLine/src/mimcmd_data.cpp | 42 | ||||
-rw-r--r-- | plugins/CmdLine/src/mimcmd_data.h | 50 | ||||
-rw-r--r-- | plugins/CmdLine/src/mimcmd_handlers.cpp | 778 | ||||
-rw-r--r-- | plugins/CmdLine/src/services.cpp | 12 | ||||
-rw-r--r-- | plugins/CmdLine/src/utils.cpp | 44 | ||||
-rw-r--r-- | plugins/CmdLine/src/utils.h | 8 | ||||
-rw-r--r-- | plugins/CmdLine/src/version.h | 6 | ||||
-rw-r--r-- | plugins/MimCmd/src/MimCmd.cpp | 55 | ||||
-rw-r--r-- | plugins/MimCmd/src/commands.cpp | 57 | ||||
-rw-r--r-- | plugins/MimCmd/src/commands.h | 6 | ||||
-rw-r--r-- | plugins/MimCmd/src/stdafx.h | 2 | ||||
-rw-r--r-- | plugins/MimCmd/src/version.h | 4 |
12 files changed, 464 insertions, 600 deletions
diff --git a/plugins/CmdLine/src/mimcmd_data.cpp b/plugins/CmdLine/src/mimcmd_data.cpp index affcdfbd9e..6165c32a01 100644 --- a/plugins/CmdLine/src/mimcmd_data.cpp +++ b/plugins/CmdLine/src/mimcmd_data.cpp @@ -22,26 +22,26 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. TCommand mimCommands[] =
{
- { MIMCMD_STATUS, "status", MIMCMD_HELP_STATUS },
- { MIMCMD_AWAYMSG, "awaymsg", MIMCMD_HELP_AWAYMSG },
- { MIMCMD_XSTATUS, "xstatus", MIMCMD_HELP_XSTATUS },
- { MIMCMD_POPUPS, "popups", MIMCMD_HELP_POPUPS },
- { MIMCMD_SOUNDS, "sounds", MIMCMD_HELP_SOUNDS },
- { MIMCMD_CLIST, "clist", MIMCMD_HELP_CLIST },
- { MIMCMD_QUIT, "quit", MIMCMD_HELP_QUIT },
- { MIMCMD_HELP, "help", MIMCMD_HELP_HELP },
- { MIMCMD_EXCHANGE, "exchange", MIMCMD_HELP_EXCHANGE },
- { MIMCMD_YAMN, "yamn", MIMCMD_HELP_YAMN },
- { MIMCMD_CALLSERVICE, "callservice", MIMCMD_HELP_CALLSERVICE },
- { MIMCMD_MESSAGE, "message", MIMCMD_HELP_MESSAGE },
- { MIMCMD_DATABASE, "db", MIMCMD_HELP_DATABASE },
- { MIMCMD_PROXY, "proxy", MIMCMD_HELP_PROXY },
- { MIMCMD_CONTACTS, "contacts", MIMCMD_HELP_CONTACTS },
- { MIMCMD_HISTORY, "history", MIMCMD_HELP_HISTORY },
- { MIMCMD_VERSION, "version", MIMCMD_HELP_VERSION },
- { MIMCMD_SETNICKNAME, "setnickname", MIMCMD_HELP_SETNICKNAME },
- { MIMCMD_IGNORE, "ignore", MIMCMD_HELP_IGNORE },
- { MIMCMD_LUA, "lua", MIMCMD_HELP_LUA },
+ { MIMCMD_STATUS, L"status", MIMCMD_HELP_STATUS },
+ { MIMCMD_AWAYMSG, L"awaymsg", MIMCMD_HELP_AWAYMSG },
+ { MIMCMD_XSTATUS, L"xstatus", MIMCMD_HELP_XSTATUS },
+ { MIMCMD_POPUPS, L"popups", MIMCMD_HELP_POPUPS },
+ { MIMCMD_SOUNDS, L"sounds", MIMCMD_HELP_SOUNDS },
+ { MIMCMD_CLIST, L"clist", MIMCMD_HELP_CLIST },
+ { MIMCMD_QUIT, L"quit", MIMCMD_HELP_QUIT },
+ { MIMCMD_HELP, L"help", MIMCMD_HELP_HELP },
+ { MIMCMD_EXCHANGE, L"exchange", MIMCMD_HELP_EXCHANGE },
+ { MIMCMD_YAMN, L"yamn", MIMCMD_HELP_YAMN },
+ { MIMCMD_CALLSERVICE, L"callservice", MIMCMD_HELP_CALLSERVICE },
+ { MIMCMD_MESSAGE, L"message", MIMCMD_HELP_MESSAGE },
+ { MIMCMD_DATABASE, L"db", MIMCMD_HELP_DATABASE },
+ { MIMCMD_PROXY, L"proxy", MIMCMD_HELP_PROXY },
+ { MIMCMD_CONTACTS, L"contacts", MIMCMD_HELP_CONTACTS },
+ { MIMCMD_HISTORY, L"history", MIMCMD_HELP_HISTORY },
+ { MIMCMD_VERSION, L"version", MIMCMD_HELP_VERSION },
+ { MIMCMD_SETNICKNAME, L"setnickname", MIMCMD_HELP_SETNICKNAME },
+ { MIMCMD_IGNORE, L"ignore", MIMCMD_HELP_IGNORE },
+ { MIMCMD_LUA, L"lua", MIMCMD_HELP_LUA },
};
-int cMimCommands = sizeof(mimCommands) / sizeof(mimCommands[0]);
\ No newline at end of file +int cMimCommands = _countof(mimCommands);
\ No newline at end of file diff --git a/plugins/CmdLine/src/mimcmd_data.h b/plugins/CmdLine/src/mimcmd_data.h index 46ffafdfde..6660375062 100644 --- a/plugins/CmdLine/src/mimcmd_data.h +++ b/plugins/CmdLine/src/mimcmd_data.h @@ -30,25 +30,25 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define MAX_ARGUMENTS 20
#define ARGUMENT_SIZE 512
-typedef char TArgument[ARGUMENT_SIZE];
+typedef wchar_t TArgument[ARGUMENT_SIZE];
struct TReply{
int code;
- char message[REPLY_SIZE];
+ wchar_t message[REPLY_SIZE];
};
typedef TReply *PReply;
struct TCommand{
long ID;
- char command[COMMAND_SIZE];
- char help[HELP_SIZE];
+ wchar_t command[COMMAND_SIZE];
+ wchar_t help[HELP_SIZE];
};
typedef TCommand *PCommand;
struct TSharedData{
- char mimFolder[MIMFOLDER_SIZE];
+ wchar_t mimFolder[MIMFOLDER_SIZE];
TCommand command;
TArgument arguments[MAX_ARGUMENTS];
int cArguments;
@@ -89,26 +89,26 @@ typedef TSharedData *PSharedData; #define MIMCMD_IGNORE 19
#define MIMCMD_LUA 20
-#define MIMCMD_HELP_STATUS LPGEN("Changes account status either globally or per account.\nUsage: status <status> [<account>].\nPossible values for <status> are: offline, online, away, dnd, na, occupied, freechat, invisible, onthephone, outtolunch.\n<Account> is an optional parameter specifying the account to set the status for. If it's not specified then the command will issue a global status change.")
-#define MIMCMD_HELP_AWAYMSG LPGEN("Changes away message either globally or per account.\nUsage: awaymsg <message> [<account>].\n<Message> is the new away message.\n<Account> is an optional parameter specifying the account to set the away message for. If not specified then the away message will be set globally.")
-#define MIMCMD_HELP_XSTATUS LPGEN("Changes extended status either globally or per account.\nUsage: xstatus <xStatus> [<account>].\n<xStatus> is the new extended status to set. Possible values are: ...\n<Account> is an optional parameter specifying the account for which extended status is set. If not specified then extended status for all accounts will be changed.\nNOTE: Not all accounts/protocols support extended status.")
-#define MIMCMD_HELP_POPUPS LPGEN("Disables or enables popups display.\nUsage: popups (disable | enable | toggle).\nThe command will either enable or disable popups display.")
-#define MIMCMD_HELP_SOUNDS LPGEN("Disables or enables sounds.\nUsage: sounds (disable | enable | toggle).\nThe command will either disable or enable sounds.")
-#define MIMCMD_HELP_CLIST LPGEN("Hides or shows the contact list window.\nUsage: clist (show | hide | toggle).\nThe command will either show or hide the contact list window.")
-#define MIMCMD_HELP_QUIT LPGEN("Closes Miranda.\nUsage: quit [wait].\nIf wait is used then the command will return only when CmdLine plugin has been unloaded by Miranda.")
-#define MIMCMD_HELP_HELP LPGEN("Provides help on other commands.\nUsage: help [<command>].\nThe command will print help information for other commands. If run without any parameters it will print available commands.")
-#define MIMCMD_HELP_EXCHANGE LPGEN("Notifies Exchange plugin to check for email.\nUsage: exchange check.")
-#define MIMCMD_HELP_YAMN LPGEN("Notifies YAMN plugin to check for email.\nUsage: yamn check.")
-#define MIMCMD_HELP_CALLSERVICE LPGEN("Calls a Miranda service.\nUsage: callservice <service> (d|s)<wParam> (d|s)<lParam>.\nThe command will call Miranda <service> service using wParam and lParam as arguments; the first letter of the parameter must be either 'd' if the parameter is a decimal number or 's' if the parameter is a string. Be careful when you use this function as you can only pass numbers and strings as data.\nNOTE: If you pass invalid data to a service, Miranda might crash.")
-#define MIMCMD_HELP_MESSAGE LPGEN("Sends a message to the specified contact(s).\nUsage: message <contact> [<contact> [<contact> [...]]] <message>.\nThe command will send <message> to the specified contact(s) - at least one contact must be specified - all parameters except the last one are considered recipients.\n<Contact> has the following format: <name>[:<account>]. <Name> is the contact display name or unique ID and <account> is an optional parameter representing the account of the contact (useful in case there is more than one contact with the same name).\nNOTE: The message string cannot exceed 512 characters. You can use \\n for new line (and \\\\n for \\n).")
-#define MIMCMD_HELP_DATABASE LPGEN("Allows you to manage database settings.\nUsage:\n db set <module> <name> (b|i|d|s|w)<value>\n db delete <module> <name>\n db get <module> <name>.\nThe command can set a database entry to the specified value (if the entry does not exist, it will be created) as well as read or delete a specified database entry. <Module> is the name of the module where the key should be located, <name> is the name of the key and <value> is the value to be written. A character must be placed before <value> in order to specify what kind of data to write: b - byte, i - integer (word), d - double word, s - string, w - wide string.")
-#define MIMCMD_HELP_PROXY LPGEN("Configures proxy settings either globally or per account.\nUsage: proxy (global|<account>) <setting> [<params>].\n<Setting> is one of the following settings:\n status (disable | enable | toggle)\n server <proxy type> <server> <port>.")
-#define MIMCMD_HELP_CONTACTS LPGEN("Allows you to search/list contacts or open message windows for specified contacts.\nUsage:\n contacts list [<keyword> [account:<account>] [id:<id>] [status:<status>] [<keyword> [...]]].\nThe command will search all contacts and display the ones matching the search criteria. To search for a specific account use the keyword 'account:<account>'. To search for contacts that have a certain ID use the keyword 'id:<id>'. To search for contacts that have a certain status use 'status:<status>'.\n contacts open [<keyword> [account:<account>] [id:<id>] [status:<status>] [<keyword> [...]]].\nThe command will open a message window for all contacts that match the search criteria. To search for a specific account use the keyword 'account:<account>'. To search for contacts that have a certain ID use the keyword 'id:<id>'. To search for contacts that have a certain status use 'status:<status>'. If no keyword is specified, the command will open a message window for all contacts that have unread messages.")
-#define MIMCMD_HELP_HISTORY LPGEN("Shows history or unread messages for a contact.\nUsage: history <command> <contact>.\n<Command> is one of the following commands:\n unread - show unread messages for that contact.\n show <contact> <start> <finish> - show history from event number <start> to <finish>. If any number is negative, it is interpreted as a relative index from the last event number +1 (so the last event for a contact is -1).")
-#define MIMCMD_HELP_VERSION LPGEN("Shows version information for Miranda and CmdLine plugin. If CrashDumper plugin is installed, it will use its report instead.\nUsage: version.\nThe command will print Miranda's and CmdLine's version numbers or, if CrashDumper plugin is installed, it will show Version Info report.")
-#define MIMCMD_HELP_SETNICKNAME LPGEN("Changes the user's nickname on the given protocol to the new name.\nUsage: setnickname <protocol> new_nickname.")
-#define MIMCMD_HELP_IGNORE LPGEN("Ignores or removes ignore flags for specific contacts.\nUsage:\n ignore (block | unblock) <contact> [<contact> [<contact> [...]]].\nThe command will set or remove ignore flags for the specified contacts")
-#define MIMCMD_HELP_LUA LPGEN("Executes Lua script via MirLua plugin.\nUsage:\n call [<module>] <function>\n exec \"<path>\"\n eval \"<code>\"")
+#define MIMCMD_HELP_STATUS LPGENW("Changes account status either globally or per account.\nUsage: status <status> [<account>].\nPossible values for <status> are: offline, online, away, dnd, na, occupied, freechat, invisible, onthephone, outtolunch.\n<Account> is an optional parameter specifying the account to set the status for. If it's not specified then the command will issue a global status change.")
+#define MIMCMD_HELP_AWAYMSG LPGENW("Changes away message either globally or per account.\nUsage: awaymsg <message> [<account>].\n<Message> is the new away message.\n<Account> is an optional parameter specifying the account to set the away message for. If not specified then the away message will be set globally.")
+#define MIMCMD_HELP_XSTATUS LPGENW("Changes extended status either globally or per account.\nUsage: xstatus <xStatus> [<account>].\n<xStatus> is the new extended status to set. Possible values are: ...\n<Account> is an optional parameter specifying the account for which extended status is set. If not specified then extended status for all accounts will be changed.\nNOTE: Not all accounts/protocols support extended status.")
+#define MIMCMD_HELP_POPUPS LPGENW("Disables or enables popups display.\nUsage: popups (disable | enable | toggle).\nThe command will either enable or disable popups display.")
+#define MIMCMD_HELP_SOUNDS LPGENW("Disables or enables sounds.\nUsage: sounds (disable | enable | toggle).\nThe command will either disable or enable sounds.")
+#define MIMCMD_HELP_CLIST LPGENW("Hides or shows the contact list window.\nUsage: clist (show | hide | toggle).\nThe command will either show or hide the contact list window.")
+#define MIMCMD_HELP_QUIT LPGENW("Closes Miranda.\nUsage: quit [wait].\nIf wait is used then the command will return only when CmdLine plugin has been unloaded by Miranda.")
+#define MIMCMD_HELP_HELP LPGENW("Provides help on other commands.\nUsage: help [<command>].\nThe command will print help information for other commands. If run without any parameters it will print available commands.")
+#define MIMCMD_HELP_EXCHANGE LPGENW("Notifies Exchange plugin to check for email.\nUsage: exchange check.")
+#define MIMCMD_HELP_YAMN LPGENW("Notifies YAMN plugin to check for email.\nUsage: yamn check.")
+#define MIMCMD_HELP_CALLSERVICE LPGENW("Calls a Miranda service.\nUsage: callservice <service> (d|s)<wParam> (d|s)<lParam>.\nThe command will call Miranda <service> service using wParam and lParam as arguments; the first letter of the parameter must be either 'd' if the parameter is a decimal number or 's' if the parameter is a string. Be careful when you use this function as you can only pass numbers and strings as data.\nNOTE: If you pass invalid data to a service, Miranda might crash.")
+#define MIMCMD_HELP_MESSAGE LPGENW("Sends a message to the specified contact(s).\nUsage: message <contact> [<contact> [<contact> [...]]] <message>.\nThe command will send <message> to the specified contact(s) - at least one contact must be specified - all parameters except the last one are considered recipients.\n<Contact> has the following format: <name>[:<account>]. <Name> is the contact display name or unique ID and <account> is an optional parameter representing the account of the contact (useful in case there is more than one contact with the same name).\nNOTE: The message string cannot exceed 512 characters. You can use \\n for new line (and \\\\n for \\n).")
+#define MIMCMD_HELP_DATABASE LPGENW("Allows you to manage database settings.\nUsage:\n db set <module> <name> (b|i|d|s|w)<value>\n db delete <module> <name>\n db get <module> <name>.\nThe command can set a database entry to the specified value (if the entry does not exist, it will be created) as well as read or delete a specified database entry. <Module> is the name of the module where the key should be located, <name> is the name of the key and <value> is the value to be written. A character must be placed before <value> in order to specify what kind of data to write: b - byte, i - integer (word), d - double word, s - string, w - wide string.")
+#define MIMCMD_HELP_PROXY LPGENW("Configures proxy settings either globally or per account.\nUsage: proxy (global|<account>) <setting> [<params>].\n<Setting> is one of the following settings:\n status (disable | enable | toggle)\n server <proxy type> <server> <port>.")
+#define MIMCMD_HELP_CONTACTS LPGENW("Allows you to search/list contacts or open message windows for specified contacts.\nUsage:\n contacts list [<keyword> [account:<account>] [id:<id>] [status:<status>] [<keyword> [...]]].\nThe command will search all contacts and display the ones matching the search criteria. To search for a specific account use the keyword 'account:<account>'. To search for contacts that have a certain ID use the keyword 'id:<id>'. To search for contacts that have a certain status use 'status:<status>'.\n contacts open [<keyword> [account:<account>] [id:<id>] [status:<status>] [<keyword> [...]]].\nThe command will open a message window for all contacts that match the search criteria. To search for a specific account use the keyword 'account:<account>'. To search for contacts that have a certain ID use the keyword 'id:<id>'. To search for contacts that have a certain status use 'status:<status>'. If no keyword is specified, the command will open a message window for all contacts that have unread messages.")
+#define MIMCMD_HELP_HISTORY LPGENW("Shows history or unread messages for a contact.\nUsage: history <command> <contact>.\n<Command> is one of the following commands:\n unread - show unread messages for that contact.\n show <contact> <start> <finish> - show history from event number <start> to <finish>. If any number is negative, it is interpreted as a relative index from the last event number +1 (so the last event for a contact is -1).")
+#define MIMCMD_HELP_VERSION LPGENW("Shows version information for Miranda and CmdLine plugin. If CrashDumper plugin is installed, it will use its report instead.\nUsage: version.\nThe command will print Miranda's and CmdLine's version numbers or, if CrashDumper plugin is installed, it will show Version Info report.")
+#define MIMCMD_HELP_SETNICKNAME LPGENW("Changes the user's nickname on the given protocol to the new name.\nUsage: setnickname <protocol> new_nickname.")
+#define MIMCMD_HELP_IGNORE LPGENW("Ignores or removes ignore flags for specific contacts.\nUsage:\n ignore (block | unblock) <contact> [<contact> [<contact> [...]]].\nThe command will set or remove ignore flags for the specified contacts")
+#define MIMCMD_HELP_LUA LPGENW("Executes Lua script via MirLua plugin.\nUsage:\n call [<module>] <function>\n exec \"<path>\"\n eval \"<code>\"")
#define MIMMEM_REPLY 1 //data is a PReply structure
diff --git a/plugins/CmdLine/src/mimcmd_handlers.cpp b/plugins/CmdLine/src/mimcmd_handlers.cpp index 039b4c76bc..10caca7621 100644 --- a/plugins/CmdLine/src/mimcmd_handlers.cpp +++ b/plugins/CmdLine/src/mimcmd_handlers.cpp @@ -38,46 +38,43 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define VALUE_STRING 4
#define VALUE_WIDE 5
-__inline static int matches(char *command, char *lower)
+__inline static int matches(const wchar_t *command, const wchar_t *lower)
{
- return ((mir_strcmp(lower, command) == 0) || (mir_strcmp(lower, Translate(command)) == 0));
+ return ((mir_wstrcmp(lower, command) == 0) || (mir_wstrcmp(lower, TranslateW(command)) == 0));
}
-int Get2StateValue(char *state)
+int Get2StateValue(wchar_t *state)
{
- char lower[512];
- strncpy_s(lower, state, sizeof(lower));
- _strlwr(lower);
+ wchar_t lower[512];
+ wcsncpy_s(lower, state, _countof(lower));
+ _wcslwr(lower);
//if ((mir_strcmp(lower, "enable") == 0) || (mir_strcmp(lower, "show") == 0) || (mir_strcmp(lower, "on") == 0))
- if ((matches("enable", lower)) || (matches("show", lower)) || (matches("on", lower))) {
+ if ((matches(L"enable", lower)) || (matches(L"show", lower)) || (matches(L"on", lower)))
return STATE_ON;
- }
//if ((mir_strcmp(lower, "disable") == 0) || (mir_strcmp(lower, "hide") == 0) || (mir_strcmp(lower, "off") == 0))
- if ((matches("disable", lower)) || (matches("hide", lower)) || (matches("off", lower))) {
+ if ((matches(L"disable", lower)) || (matches(L"hide", lower)) || (matches(L"off", lower)))
return STATE_OFF;
- }
//if (mir_strcmp(lower, "toggle") == 0)
- if (matches("toggle", lower)) {
+ if (matches(L"toggle", lower))
return STATE_TOGGLE;
- }
return STATE_UNKNOWN;
}
-int AccountName2Protocol(const char *accountName, OUT char *uniqueProtocolName, size_t length)
+int AccountName2Protocol(const wchar_t *accountName, OUT char *uniqueProtocolName, size_t length)
{
int count;
PROTOACCOUNT **accounts = nullptr;
Proto_EnumAccounts(&count, &accounts);
- strncpy_s(uniqueProtocolName, length, accountName, _TRUNCATE);
+ strncpy_s(uniqueProtocolName, length, _T2A(accountName), _TRUNCATE);
for (int i = 0; i < count; i++) {
if (accounts[i]->bIsEnabled) {
- if (_stricmp(accountName, _T2A(accounts[i]->tszAccountName)) == 0) {
+ if (_wcsicmp(accountName, accounts[i]->tszAccountName) == 0) {
strncpy_s(uniqueProtocolName, length, accounts[i]->szModuleName, _TRUNCATE);
return 0;
}
@@ -90,37 +87,32 @@ int AccountName2Protocol(const char *accountName, OUT char *uniqueProtocolName, void HandleWrongParametersCount(PCommand command, PReply reply)
{
reply->code = MIMRES_WRONGPARAMSCOUNT;
- mir_snprintf(reply->message, Translate("Wrong number of parameters for command '%s'."), command->command);
+ mir_snwprintf(reply->message, TranslateT("Wrong number of parameters for command '%s'."), command->command);
}
-void HandleUnknownParameter(PCommand command, char *param, PReply reply)
+void HandleUnknownParameter(PCommand command, wchar_t *param, PReply reply)
{
reply->code = MIMRES_UNKNOWNPARAM;
- mir_snprintf(reply->message, Translate("Unknown parameter '%s' for command '%s'."), param, command->command);
+ mir_snwprintf(reply->message, TranslateT("Unknown parameter '%s' for command '%s'."), param, command->command);
}
-int ParseValueParam(char *param, void *&result)
+int ParseValueParam(wchar_t *param, void *&result)
{
- if (mir_strlen(param) > 0) {
+ if (mir_wstrlen(param) > 0) {
switch (*param) {
case 's':
{
- size_t len = mir_strlen(param); //- 1 + 1
- result = (char*)malloc(len * sizeof(char));
- strcpy((char*)result, param + 1);
+ size_t len = mir_wstrlen(param); //- 1 + 1
+ result = malloc(len * sizeof(char));
+ strcpy((char*)result, _T2A(param + 1));
return VALUE_STRING;
}
case 'w':
{
- size_t len = mir_strlen(param);
+ size_t len = mir_wstrlen(param);
result = (WCHAR *)malloc(len * sizeof(WCHAR));
- char *buffer = (char*)malloc(len * sizeof(WCHAR));
- strncpy_s(buffer, len, param + 1, _TRUNCATE);
-
- MultiByteToWideChar(CP_ACP, 0, buffer, -1, (WCHAR *)result, (int)len);
-
- free(buffer);
+ wcsncpy_s((wchar_t*)result, len, param + 1, _TRUNCATE);
return VALUE_WIDE;
}
@@ -128,8 +120,8 @@ int ParseValueParam(char *param, void *&result) {
result = (char *)malloc(sizeof(char));
- char *stop;
- long tmp = strtol(param + 1, &stop, 10);
+ wchar_t *stop;
+ long tmp = wcstol(param + 1, &stop, 10);
*((char *)result) = tmp;
return (*stop == 0) ? VALUE_BYTE : VALUE_ERROR;
@@ -138,9 +130,9 @@ int ParseValueParam(char *param, void *&result) case 'i':
{
result = (int *)malloc(sizeof(int));
- char *stop;
+ wchar_t *stop;
- long tmp = strtol(param + 1, &stop, 10);
+ long tmp = wcstol(param + 1, &stop, 10);
*((int *)result) = tmp;
return (*stop == 0) ? VALUE_WORD : VALUE_ERROR;
@@ -149,11 +141,12 @@ int ParseValueParam(char *param, void *&result) case 'd':
{
result = (long *)malloc(sizeof(long));
- char *stop;
- *((long *)result) = strtol(param + 1, &stop, 10);
+ wchar_t *stop;
+ *((long *)result) = wcstol(param + 1, &stop, 10);
return (*stop == 0) ? VALUE_DWORD : VALUE_ERROR;
}
+
default:
return VALUE_UNKNOWN;
}
@@ -161,40 +154,39 @@ int ParseValueParam(char *param, void *&result) else return VALUE_ERROR;
}
-int ParseStatusParam(char *status)
+int ParseStatusParam(const wchar_t *status)
{
- char *lower = NEWSTR_ALLOCA(status);
- _strlwr(lower);
+ wchar_t *lower = NEWWSTR_ALLOCA(status);
+ CharLower(lower);
- if (!mir_strcmp(lower, "offline"))
+ if (!mir_wstrcmp(lower, L"offline"))
return ID_STATUS_OFFLINE;
- else if (!mir_strcmp(lower, "online"))
+ if (!mir_wstrcmp(lower, L"online"))
return ID_STATUS_ONLINE;
- else if (!mir_strcmp(lower, "away"))
+ if (!mir_wstrcmp(lower, L"away"))
return ID_STATUS_AWAY;
- else if (!mir_strcmp(lower, "dnd"))
+ if (!mir_wstrcmp(lower, L"dnd"))
return ID_STATUS_DND;
- else if (!mir_strcmp(lower, "na"))
+ if (!mir_wstrcmp(lower, L"na"))
return ID_STATUS_NA;
- else if (!mir_strcmp(lower, "occupied"))
+ if (!mir_wstrcmp(lower, L"occupied"))
return ID_STATUS_OCCUPIED;
- else if (!mir_strcmp(lower, "freechat"))
+ if (!mir_wstrcmp(lower, L"freechat"))
return ID_STATUS_FREECHAT;
- else if (!mir_strcmp(lower, "invisible"))
+ if (!mir_wstrcmp(lower, L"invisible"))
return ID_STATUS_INVISIBLE;
- else if (!mir_strcmp(lower, "onthephone"))
+ if (!mir_wstrcmp(lower, L"onthephone"))
return ID_STATUS_ONTHEPHONE;
- else if (!mir_strcmp(lower, "outtolunch"))
+ if (!mir_wstrcmp(lower, L"outtolunch"))
return ID_STATUS_OUTTOLUNCH;
- else
- return 0;
+ return 0;
}
-char *PrettyStatusMode(int status, char *buffer, int size)
+wchar_t* PrettyStatusMode(int status, wchar_t *buffer, size_t size)
{
wchar_t *data = pcli->pfnGetStatusModeDescription(status, 0);
if (data)
- strncpy_s(buffer, size, _T2A(data), _TRUNCATE);
+ wcsncpy_s(buffer, size, data, _TRUNCATE);
else
*buffer = 0;
@@ -207,102 +199,95 @@ void HandleStatusCommand(PCommand command, TArgument *argv, int argc, PReply rep case 2:
{
INT_PTR status = CallService(MS_CLIST_GETSTATUSMODE, 0, 0);
- char pretty[128];
- PrettyStatusMode(status, pretty, sizeof(pretty));
+ wchar_t pretty[128];
+ PrettyStatusMode(status, pretty, _countof(pretty));
- CMStringA perAccountStatus;
+ CMStringW perAccountStatus;
int count;
PROTOACCOUNT **accounts = nullptr;
Proto_EnumAccounts(&count, &accounts);
- char pn[128];
+ wchar_t pn[128];
for (int i = 0; i < count; i++) {
if (accounts[i]->bIsEnabled) {
status = CallProtoService(accounts[i]->szModuleName, PS_GETSTATUS, 0, 0);
- PrettyStatusMode(status, pn, sizeof(pn));
+ PrettyStatusMode(status, pn, _countof(pn));
perAccountStatus.AppendChar('\n');
- perAccountStatus.Append(_T2A(accounts[i]->tszAccountName));
- perAccountStatus.Append(": ");
+ perAccountStatus.Append(accounts[i]->tszAccountName);
+ perAccountStatus.Append(L": ");
perAccountStatus.Append(pn);
}
}
reply->code = MIMRES_SUCCESS;
- mir_snprintf(reply->message, Translate("Current global status: %s.%s"), pretty, perAccountStatus.c_str());
-
- return;
+ mir_snwprintf(reply->message, TranslateT("Current global status: %s.%s"), pretty, perAccountStatus.c_str());
}
+ return;
case 3:
{
int status = ParseStatusParam(argv[2]);
if (status) {
INT_PTR old = CallService(MS_CLIST_GETSTATUSMODE, 0, 0);
- char po[128];
+ wchar_t po[128];
if (ServiceExists(MS_KS_ANNOUNCESTATUSCHANGE)) {
announce_status_change(nullptr, status, nullptr);
}
- PrettyStatusMode(old, po, sizeof(po));
+ PrettyStatusMode(old, po, _countof(po));
Clist_SetStatusMode(status);
- char pn[128];
- PrettyStatusMode(status, pn, sizeof(pn));
+ wchar_t pn[128];
+ PrettyStatusMode(status, pn, _countof(pn));
reply->code = MIMRES_SUCCESS;
- mir_snprintf(reply->message, Translate("Changed global status to '%s' (previous status was '%s')."), pn, po);
- }
- else {
- HandleUnknownParameter(command, argv[2], reply);
+ mir_snwprintf(reply->message, TranslateT("Changed global status to '%s' (previous status was '%s')."), pn, po);
}
-
- return;
+ else HandleUnknownParameter(command, argv[2], reply);
}
+ return;
case 4:
{
int status = ParseStatusParam(argv[2]);
if (status) {
char protocol[128];
- char *account = argv[3];
- AccountName2Protocol(account, protocol, sizeof(protocol));
+ wchar_t *account = argv[3];
+ AccountName2Protocol(account, protocol, _countof(protocol));
INT_PTR old = CallProtoService(protocol, PS_GETSTATUS, 0, 0);
- char po[128];
+ wchar_t po[128];
if (ServiceExists(MS_KS_ANNOUNCESTATUSCHANGE)) {
announce_status_change(protocol, status, nullptr);
}
- PrettyStatusMode(old, po, sizeof(po));
+ PrettyStatusMode(old, po, _countof(po));
INT_PTR res = CallProtoService(protocol, PS_SETSTATUS, status, 0);
- char pn[128];
- PrettyStatusMode(status, pn, sizeof(pn));
+ wchar_t pn[128];
+ PrettyStatusMode(status, pn, _countof(pn));
switch (res) {
case 0:
reply->code = MIMRES_SUCCESS;
- mir_snprintf(reply->message, Translate("Changed '%s' status to '%s' (previous status was '%s')."), account, pn, po);
+ mir_snwprintf(reply->message, TranslateT("Changed '%s' status to '%s' (previous status was '%s')."), account, pn, po);
return;
case CALLSERVICE_NOTFOUND:
reply->code = MIMRES_FAILURE;
- mir_snprintf(reply->message, Translate("'%s' doesn't seem to be a valid account."), account);
+ mir_snwprintf(reply->message, TranslateT("'%s' doesn't seem to be a valid account."), account);
return;
default:
reply->code = MIMRES_FAILURE;
- mir_snprintf(reply->message, Translate("Failed to change status for account '%s' to '%s'."), account, pn);
+ mir_snwprintf(reply->message, TranslateT("Failed to change status for account '%s' to '%s'."), account, pn);
return;
}
}
- else {
- HandleUnknownParameter(command, argv[2], reply);
- }
-
- return;
+ else HandleUnknownParameter(command, argv[2], reply);
}
+ return;
default:
HandleWrongParametersCount(command, reply);
@@ -314,58 +299,53 @@ void HandleAwayMsgCommand(PCommand command, TArgument *argv, int argc, PReply re switch (argc) {
case 3:
{
- char *awayMsg = argv[2];
+ wchar_t *awayMsg = argv[2];
int count = 0;
PROTOACCOUNT **accounts = nullptr;
Proto_EnumAccounts(&count, &accounts);
- CMStringA szReply;
- int i;
- INT_PTR status;
- INT_PTR res = 0;
- char *protocol;
- char pn[128];
- for (i = 0; i < count; i++) {
+ CMStringW szReply;
+ for (int i = 0; i < count; i++) {
if (!accounts[i]->bIsEnabled)
continue;
if (i != 0)
szReply.AppendChar('\n');
- protocol = accounts[i]->szModuleName;
- if ((CallProtoService(protocol, PS_GETCAPS, PFLAGNUM_1, 0) & PF1_MODEMSGSEND) != 0) //if the protocol supports away messages
- {
- status = CallProtoService(protocol, PS_GETSTATUS, 0, 0);
- ptrW wszAwayMsg(mir_a2u(awayMsg));
- res = CallProtoService(protocol, PS_SETAWAYMSG, status, wszAwayMsg);
- PrettyStatusMode(status, pn, sizeof(pn));
+ char *protocol = accounts[i]->szModuleName;
+ if ((CallProtoService(protocol, PS_GETCAPS, PFLAGNUM_1, 0) & PF1_MODEMSGSEND) != 0) { //if the protocol supports away messages
+ INT_PTR status = CallProtoService(protocol, PS_GETSTATUS, 0, 0);
+ INT_PTR res = CallProtoService(protocol, PS_SETAWAYMSG, status, (LPARAM)awayMsg);
+
+ wchar_t pn[128];
+ PrettyStatusMode(status, pn, _countof(pn));
if (res)
- szReply.AppendFormat(Translate("Failed to set '%S' status message to '%s' (status is '%s')."), accounts[i]->tszAccountName, awayMsg, pn);
+ szReply.AppendFormat(TranslateT("Failed to set '%s' status message to '%s' (status is '%s')."), accounts[i]->tszAccountName, awayMsg, pn);
else
- szReply.AppendFormat(Translate("Successfully set '%S' status message to '%s' (status is '%s')."), accounts[i]->tszAccountName, awayMsg, pn);
+ szReply.AppendFormat(TranslateT("Successfully set '%s' status message to '%s' (status is '%s')."), accounts[i]->tszAccountName, awayMsg, pn);
}
- else szReply.AppendFormat(Translate("Account '%S' does not support away messages, skipping."), accounts[i]->tszAccountName);
+ else szReply.AppendFormat(TranslateT("Account '%s' does not support away messages, skipping."), accounts[i]->tszAccountName);
}
- strncpy_s(reply->message, szReply, _TRUNCATE);
+ wcsncpy_s(reply->message, szReply, _TRUNCATE);
reply->code = MIMRES_SUCCESS;
return;
}
case 4:
{
- char *awayMsg = argv[2];
+ wchar_t *awayMsg = argv[2];
char protocol[128];
- char *account = argv[3];
- AccountName2Protocol(account, protocol, sizeof(protocol));
+ wchar_t *account = argv[3];
+ AccountName2Protocol(account, protocol, _countof(protocol));
- char pn[128];
+ wchar_t pn[128];
INT_PTR res = CallProtoService(protocol, PS_GETCAPS, PFLAGNUM_1, 0);
if ((res & PF1_MODEMSGSEND) != 0) //if the protocol supports away messages
{
INT_PTR status = CallProtoService(protocol, PS_GETSTATUS, 0, 0);
res = CallProtoService(protocol, PS_SETAWAYMSG, status, (LPARAM)awayMsg);
- PrettyStatusMode(status, pn, sizeof(pn));
+ PrettyStatusMode(status, pn, _countof(pn));
}
else if (CallProtoService(protocol, PS_GETSTATUS, 0, 0) == CALLSERVICE_NOTFOUND) {
res = CALLSERVICE_NOTFOUND;
@@ -377,22 +357,22 @@ void HandleAwayMsgCommand(PCommand command, TArgument *argv, int argc, PReply re switch (res) {
case 0:
reply->code = MIMRES_SUCCESS;
- mir_snprintf(reply->message, Translate("Changed '%s' status message to '%s' (status is '%s')."), account, awayMsg, pn);
+ mir_snwprintf(reply->message, TranslateT("Changed '%s' status message to '%s' (status is '%s')."), account, awayMsg, pn);
return;
case CALLSERVICE_NOTFOUND:
reply->code = MIMRES_FAILURE;
- mir_snprintf(reply->message, Translate("'%s' doesn't seem to be a valid account."), account);
+ mir_snwprintf(reply->message, TranslateT("'%s' doesn't seem to be a valid account."), account);
return;
case -2:
reply->code = MIMRES_FAILURE;
- mir_snprintf(reply->message, Translate("Account '%s' does not support away messages, skipping."), account);
+ mir_snwprintf(reply->message, TranslateT("Account '%s' does not support away messages, skipping."), account);
return;
default:
reply->code = MIMRES_FAILURE;
- mir_snprintf(reply->message, Translate("Failed to change status message for account '%s' to '%s' (status is '%s')."), account, awayMsg, pn);
+ mir_snwprintf(reply->message, TranslateT("Failed to change status message for account '%s' to '%s' (status is '%s')."), account, awayMsg, pn);
return;
}
}
@@ -402,26 +382,26 @@ void HandleAwayMsgCommand(PCommand command, TArgument *argv, int argc, PReply re }
}
-void Set2StateReply(PReply reply, int state, int failure, char *successTrue, char *failureTrue, char *successFalse, char *failureFalse)
+void Set2StateReply(PReply reply, int state, int failure, wchar_t *successTrue, wchar_t *failureTrue, wchar_t *successFalse, wchar_t *failureFalse)
{
if (state) {
if (failure) {
reply->code = MIMRES_FAILURE;
- mir_snprintf(reply->message, Translate(failureTrue));
+ mir_snwprintf(reply->message, TranslateW(failureTrue));
}
else {
reply->code = MIMRES_SUCCESS;
- mir_snprintf(reply->message, Translate(successTrue));
+ mir_snwprintf(reply->message, TranslateW(successTrue));
}
}
else {
if (failure) {
reply->code = MIMRES_FAILURE;
- mir_snprintf(reply->message, Translate(failureFalse));
+ mir_snwprintf(reply->message, TranslateW(failureFalse));
}
else {
reply->code = MIMRES_SUCCESS;
- mir_snprintf(reply->message, Translate(successFalse));
+ mir_snwprintf(reply->message, TranslateW(successFalse));
}
}
}
@@ -432,8 +412,7 @@ void HandlePopupsCommand(PCommand command, TArgument *argv, int argc, PReply rep case 2:
{
int state = CallService(MS_POPUP_QUERY, PUQS_GETSTATUS, 0);
- Set2StateReply(reply, state, 0, LPGEN("Popups are currently enabled."), "", LPGEN("Popups are currently disabled."), "");
-
+ Set2StateReply(reply, state, 0, LPGENW("Popups are currently enabled."), L"", LPGENW("Popups are currently disabled."), L"");
return;
}
@@ -464,8 +443,8 @@ void HandlePopupsCommand(PCommand command, TArgument *argv, int argc, PReply rep return;
}
- Set2StateReply(reply, state, failure, LPGEN("Popups were enabled successfully."), LPGEN("Popups could not be enabled."),
- LPGEN("Popups were disabled successfully."), LPGEN("Popups could not be disabled."));
+ Set2StateReply(reply, state, failure, LPGENW("Popups were enabled successfully."), LPGENW("Popups could not be enabled."),
+ LPGENW("Popups were disabled successfully."), LPGENW("Popups could not be disabled."));
return;
}
@@ -481,7 +460,7 @@ void HandleSoundsCommand(PCommand command, TArgument *argv, int argc, PReply rep case 2:
{
int state = db_get_b(NULL, "Skin", "UseSound", 1);
- Set2StateReply(reply, state, 0, LPGEN("Sounds are currently enabled."), "", LPGEN("Sounds are currently disabled."), "");
+ Set2StateReply(reply, state, 0, LPGENW("Sounds are currently enabled."), L"", LPGENW("Sounds are currently disabled."), L"");
return;
}
@@ -511,7 +490,7 @@ void HandleSoundsCommand(PCommand command, TArgument *argv, int argc, PReply rep return;
}
- Set2StateReply(reply, state, 0, LPGEN("Sounds were enabled successfully."), "", LPGEN("Sounds were disabled successfully."), "");
+ Set2StateReply(reply, state, 0, LPGENW("Sounds were enabled successfully."), L"", LPGENW("Sounds were disabled successfully."), L"");
return;
}
@@ -527,7 +506,7 @@ void HandleClistCommand(PCommand command, TArgument *argv, int argc, PReply repl case 2:
{
int state = IsWindowVisible(pcli->hwndContactList);
- Set2StateReply(reply, state, 0, LPGEN("Contact list is currently shown."), "", LPGEN("Contact list is currently hidden."), "");
+ Set2StateReply(reply, state, 0, LPGENW("Contact list is currently shown."), L"", LPGENW("Contact list is currently hidden."), L"");
return;
}
@@ -535,45 +514,29 @@ void HandleClistCommand(PCommand command, TArgument *argv, int argc, PReply repl case 3:
{
int state = 0;
- HWND hClist = pcli->hwndContactList;
switch (Get2StateValue(argv[2])) {
case STATE_ON:
- {
- ShowWindow(hClist, SW_SHOW);
-
- state = TRUE;
-
- break;
- }
+ ShowWindow(pcli->hwndContactList, SW_SHOW);
+ state = TRUE;
+ break;
case STATE_OFF:
- {
- ShowWindow(hClist, SW_HIDE);
- state = FALSE;
-
- break;
- }
+ ShowWindow(pcli->hwndContactList, SW_HIDE);
+ state = FALSE;
+ break;
case STATE_TOGGLE:
- {
- state = IsWindowVisible(hClist);
-
- state = 1 - state;
- ShowWindow(hClist, (state) ? SW_SHOW : SW_HIDE);
-
- break;
- }
+ state = !IsWindowVisible(pcli->hwndContactList);
+ ShowWindow(pcli->hwndContactList, (state) ? SW_SHOW : SW_HIDE);
+ break;
default:
HandleUnknownParameter(command, argv[2], reply);
return;
}
-
- Set2StateReply(reply, state, 0, LPGEN("Contact list was shown successfully."), "",
- LPGEN("Contact list was hidden successfully."), "");
-
+ Set2StateReply(reply, state, 0, LPGENW("Contact list was shown successfully."), L"", LPGENW("Contact list was hidden successfully."), L"");
return;
}
@@ -589,30 +552,28 @@ void HandleQuitCommand(PCommand command, TArgument *argv, int argc, PReply reply {
CallService("CloseAction", 0, 0);
- //try another quit method
- HWND hWndMiranda = pcli->hwndContactList;
- PostMessage(hWndMiranda, WM_COMMAND, ID_ICQ_EXIT, 0);
+ // try another quit method
+ PostMessage(pcli->hwndContactList, WM_COMMAND, ID_ICQ_EXIT, 0);
reply->code = MIMRES_SUCCESS;
- mir_snprintf(reply->message, Translate("Issued a quit command."));
+ mir_snwprintf(reply->message, TranslateT("Issued a quit command."));
break;
}
case 3:
{
- char lower[128];
- strncpy_s(lower, argv[2], sizeof(lower));
- _strlwr(lower);
+ wchar_t lower[128];
+ wcsncpy_s(lower, argv[2], _countof(lower));
+ _wcslwr(lower);
- if (mir_strcmp(lower, "wait") == 0) {
+ if (mir_wstrcmp(lower, L"wait") == 0) {
CallService("CloseAction", 0, 0);
//try another quit method
- HWND hWndMiranda = pcli->hwndContactList;
- PostMessage(hWndMiranda, WM_COMMAND, ID_ICQ_EXIT, 0);
+ PostMessage(pcli->hwndContactList, WM_COMMAND, ID_ICQ_EXIT, 0);
reply->code = MIMRES_SUCCESS;
- mir_snprintf(reply->message, Translate("Issued a quit and wait command."));
+ mir_snwprintf(reply->message, TranslateT("Issued a quit and wait command."));
SetEvent(heServerBufferFull);
@@ -622,9 +583,7 @@ void HandleQuitCommand(PCommand command, TArgument *argv, int argc, PReply reply Sleep(250); //wait for Miranda to quit.
}
}
- else {
- HandleUnknownParameter(command, argv[2], reply);
- }
+ else HandleUnknownParameter(command, argv[2], reply);
break;
}
@@ -639,23 +598,21 @@ void HandleExchangeCommand(PCommand command, TArgument *argv, int argc, PReply r switch (argc) {
case 3:
{
- char lower[128];
- strncpy_s(lower, argv[2], sizeof(lower));
- _strlwr(lower);
- if (mir_strcmp(lower, "check") == 0) {
+ wchar_t lower[128];
+ wcsncpy_s(lower, argv[2], _countof(lower));
+ _wcslwr(lower);
+ if (mir_wstrcmp(lower, L"check") == 0) {
INT_PTR ret = CallService(MS_EXCHANGE_CHECKEMAIL, 0, 0);
if (ret != CALLSERVICE_NOTFOUND) {
reply->code = MIMRES_SUCCESS;
- mir_snprintf(reply->message, Translate("Issued check email command to Exchange plugin."));
+ mir_snwprintf(reply->message, TranslateT("Issued check email command to Exchange plugin."));
}
else {
reply->code = MIMRES_FAILURE;
- mir_snprintf(reply->message, Translate("Exchange plugin is not running."));
+ mir_snwprintf(reply->message, TranslateT("Exchange plugin is not running."));
}
}
- else {
- HandleUnknownParameter(command, argv[2], reply);
- }
+ else HandleUnknownParameter(command, argv[2], reply);
return;
}
@@ -670,19 +627,19 @@ void HandleYAMNCommand(PCommand command, TArgument *argv, int argc, PReply reply switch (argc) {
case 3:
{
- char lower[128];
- strncpy_s(lower, argv[2], sizeof(lower));
- _strlwr(lower);
- if (mir_strcmp(lower, "check") == 0) {
+ wchar_t lower[128];
+ wcsncpy_s(lower, argv[2], _countof(lower));
+ _wcslwr(lower);
+ if (mir_wstrcmp(lower, L"check") == 0) {
if (ServiceExists(MS_YAMN_FORCECHECK)) {
CallService(MS_YAMN_FORCECHECK, 0, 0);
reply->code = MIMRES_SUCCESS;
- mir_snprintf(reply->message, Translate("Issued check email command to YAMN plugin."));
+ mir_snwprintf(reply->message, TranslateT("Issued check email command to YAMN plugin."));
}
else {
reply->code = MIMRES_FAILURE;
- mir_snprintf(reply->message, Translate("YAMN plugin is not running."));
+ mir_snwprintf(reply->message, TranslateT("YAMN plugin is not running."));
}
}
else {
@@ -702,22 +659,22 @@ void HandleCallServiceCommand(PCommand command, TArgument *argv, int argc, PRepl switch (argc) {
case 5:
{
- char *service = argv[2];
- if (ServiceExists(service)) {
+ wchar_t *service = argv[2];
+ if (ServiceExists(_T2A(service))) {
void *wParam = nullptr;
void *lParam = nullptr;
INT_PTR res1 = ParseValueParam(argv[3], wParam);
INT_PTR res2 = ParseValueParam(argv[4], lParam);
if ((res1 != 0) && (res2 != 0)) {
- //very dangerous but the user asked
- INT_PTR res = CallService(service, ((res1 == 1) ? *((long *)wParam) : (WPARAM)wParam), (LPARAM)((res2 == 1) ? *((long *)lParam) : (LPARAM)lParam));
+ // very dangerous but the user asked
+ INT_PTR res = CallService(_T2A(service), ((res1 == 1) ? *((long *)wParam) : (WPARAM)wParam), (LPARAM)((res2 == 1) ? *((long *)lParam) : (LPARAM)lParam));
reply->code = MIMRES_SUCCESS;
- mir_snprintf(reply->message, Translate("CallService call successful: service '%s' returned %p."), service, res);
+ mir_snwprintf(reply->message, TranslateT("CallService call successful: service '%s' returned %p."), service, res);
}
else {
reply->code = MIMRES_FAILURE;
- mir_snprintf(reply->message, Translate("Invalid parameter '%s' passed to CallService command."), (wParam) ? argv[4] : argv[3]);
+ mir_snwprintf(reply->message, TranslateT("Invalid parameter '%s' passed to CallService command."), (wParam) ? argv[4] : argv[3]);
}
free(wParam);
@@ -726,7 +683,7 @@ void HandleCallServiceCommand(PCommand command, TArgument *argv, int argc, PRepl }
else {
reply->code = MIMRES_FAILURE;
- mir_snprintf(reply->message, Translate("Service '%s' does not exist."), service);
+ mir_snwprintf(reply->message, TranslateT("Service '%s' does not exist."), service);
}
break;
@@ -737,12 +694,12 @@ void HandleCallServiceCommand(PCommand command, TArgument *argv, int argc, PRepl }
}
-void ParseMessage(char buffer[512], const char *message)
+void ParseMessage(wchar_t buffer[512], const wchar_t *message)
{
unsigned int j = 0;
- for (unsigned int i = 0; i < mir_strlen(message); ++i) {
- char c = message[i];
- if (c == '\\' && i < (mir_strlen(message) - 1) && message[i + 1] == 'n') {
+ for (unsigned int i = 0; i < mir_wstrlen(message); ++i) {
+ wchar_t c = message[i];
+ if (c == '\\' && i < (mir_wstrlen(message) - 1) && message[i + 1] == 'n') {
c = '\n';
i++;
}
@@ -751,33 +708,33 @@ void ParseMessage(char buffer[512], const char *message) buffer[j] = '\0';
}
-MCONTACT ParseContactParam(char *contact)
+MCONTACT ParseContactParam(wchar_t *contact)
{
- char name[512];
- char account[128];
+ wchar_t name[512];
+ wchar_t account[128];
char protocol[128];
- char *p = strrchr(contact, ':');
+ wchar_t *p = wcsrchr(contact, ':');
if (p == nullptr)
- return GetContactFromID(contact, (char*)nullptr);
+ return GetContactFromID(contact, nullptr);
*p = 0;
- strncpy_s(name, contact, _TRUNCATE);
- strncpy_s(account, p + 1, _TRUNCATE);
+ wcsncpy_s(name, contact, _TRUNCATE);
+ wcsncpy_s(account, p + 1, _TRUNCATE);
*p = ':';
- AccountName2Protocol(account, protocol, sizeof(protocol));
+ AccountName2Protocol(account, protocol, _countof(protocol));
return GetContactFromID(name, protocol);
}
void HandleMessageCommand(PCommand command, TArgument *argv, int argc, PReply reply)
{
if (argc >= 4) {
- char message[512];
+ wchar_t message[512];
ParseMessage(message, argv[argc - 1]); //get the message
- CMStringA szReply;
+ CMStringW szReply;
ACKDATA *ack = nullptr;
for (int i = 2; i < argc - 1; i++) {
- char *contact = argv[i];
+ wchar_t *contact = argv[i];
MCONTACT hContact = ParseContactParam(contact);
if (i != 3)
@@ -785,7 +742,7 @@ void HandleMessageCommand(PCommand command, TArgument *argv, int argc, PReply re if (hContact) {
bShouldProcessAcks = TRUE;
- HANDLE hProcess = (HANDLE)ProtoChainSend(hContact, PSS_MESSAGE, 0, (LPARAM)message);
+ HANDLE hProcess = (HANDLE)ProtoChainSend(hContact, PSS_MESSAGE, 0, ptrA(Utf8EncodeW(message)));
const int MAX_COUNT = 60;
int counter = 0;
while (((ack = GetAck(hProcess)) == nullptr) && (counter < MAX_COUNT)) {
@@ -797,7 +754,7 @@ void HandleMessageCommand(PCommand command, TArgument *argv, int argc, PReply re if (counter < MAX_COUNT) {
if (ack->result == ACKRESULT_SUCCESS) {
if (ack->szModule) {
- szReply.AppendFormat(Translate("Message sent to '%s'."), contact);
+ szReply.AppendFormat(TranslateT("Message sent to '%s'."), contact);
DBEVENTINFO e = {};
char module[128];
@@ -807,21 +764,21 @@ void HandleMessageCommand(PCommand command, TArgument *argv, int argc, PReply re e.pBlob = (PBYTE)message;
e.cbBlob = (DWORD)mir_strlen((char *)message) + 1;
- strncpy_s(module, ack->szModule, sizeof(module));
+ strncpy_s(module, ack->szModule, _countof(module));
e.szModule = module;
e.timestamp = (DWORD)time(nullptr);
db_event_add(ack->hContact, &e);
}
- else szReply.AppendFormat(Translate("Message to '%s' was marked as sent but the account seems to be offline"), contact);
+ else szReply.AppendFormat(TranslateT("Message to '%s' was marked as sent but the account seems to be offline"), contact);
}
- else szReply.AppendFormat(Translate("Could not send message to '%s'."), contact);
+ else szReply.AppendFormat(TranslateT("Could not send message to '%s'."), contact);
}
- else szReply.AppendFormat(Translate("Timed out while waiting for acknowledgment for contact '%s'."), contact);
+ else szReply.AppendFormat(TranslateT("Timed out while waiting for acknowledgment for contact '%s'."), contact);
}
- else szReply.AppendFormat(Translate("Could not find contact handle for contact '%s'."), contact);
+ else szReply.AppendFormat(TranslateT("Could not find contact handle for contact '%s'."), contact);
}
- strncpy_s(reply->message, szReply, _TRUNCATE);
+ wcsncpy_s(reply->message, szReply, _TRUNCATE);
}
else HandleWrongParametersCount(command, reply);
}
@@ -846,7 +803,6 @@ bool ParseDatabaseData(DBVARIANT *var, char *buffer, int size, int free) if (free) {
mir_free(var->pszVal);
}
-
return true;
case DBVT_WCHAR:
@@ -878,30 +834,26 @@ bool ParseDatabaseData(DBVARIANT *var, char *buffer, int size, int free) void HandleDatabaseCommand(PCommand command, TArgument *argv, int argc, PReply reply)
{
- if (argc >= 3) //we have something to parse
- {
- char dbcmd[128];
- strncpy_s(dbcmd, argv[2], sizeof(dbcmd));
- dbcmd[sizeof(dbcmd) - 1] = 0;
- _strlwr(dbcmd);
- if (mir_strcmp(dbcmd, "delete") == 0) {
+ if (argc >= 3) { // we have something to parse
+ wchar_t dbcmd[128];
+ wcsncpy_s(dbcmd, argv[2], _TRUNCATE);
+ _wcslwr(dbcmd);
+ if (mir_wstrcmp(dbcmd, L"delete") == 0) {
if (argc == 5) {
- char *module = argv[3];
- char *key = argv[4];
+ wchar_t *module = argv[3];
+ wchar_t *key = argv[4];
- db_unset(NULL, module, key);
+ db_unset(NULL, _T2A(module), _T2A(key));
reply->code = MIMRES_SUCCESS;
- mir_snprintf(reply->message, Translate("Setting '%s/%s' deleted."), module, key);
- }
- else {
- HandleWrongParametersCount(command, reply);
+ mir_snwprintf(reply->message, TranslateT("Setting '%s/%s' deleted."), module, key);
}
+ else HandleWrongParametersCount(command, reply);
}
- else if (mir_strcmp(dbcmd, "set") == 0) {
+ else if (mir_wstrcmp(dbcmd, L"set") == 0) {
if (argc == 6) {
- char *module = argv[3];
- char *key = argv[4];
+ ptrA module(mir_u2a(argv[3]));
+ ptrA key(mir_u2a(argv[4]));
void *value = nullptr;
char *wrote = nullptr;
@@ -940,18 +892,16 @@ void HandleDatabaseCommand(PCommand command, TArgument *argv, int argc, PReply r }
reply->code = MIMRES_SUCCESS;
- mir_snprintf(reply->message, Translate("Wrote '%s:%s' to database entry '%s/%s'."), wrote, argv[5] + 1, module, key);
+ mir_snwprintf(reply->message, TranslateT("Wrote '%S:%s' to database entry '%S/%S'."), wrote, argv[5] + 1, module, key);
free(value);
}
- else {
- HandleWrongParametersCount(command, reply);
- }
+ else HandleWrongParametersCount(command, reply);
}
- else if (mir_strcmp(dbcmd, "get") == 0) {
+ else if (mir_wstrcmp(dbcmd, L"get") == 0) {
if (argc == 5) {
- char *module = argv[3];
- char *key = argv[4];
+ ptrA module(mir_u2a(argv[3]));
+ ptrA key(mir_u2a(argv[4]));
DBVARIANT var = { 0 };
@@ -959,58 +909,51 @@ void HandleDatabaseCommand(PCommand command, TArgument *argv, int argc, PReply r if (!res) {
char buffer[1024];
- if (ParseDatabaseData(&var, buffer, sizeof(buffer), TRUE)) {
+ if (ParseDatabaseData(&var, buffer, _countof(buffer), TRUE)) {
reply->code = MIMRES_SUCCESS;
- mir_snprintf(reply->message, "'%s/%s' - %s.", module, key, buffer);
+ mir_snwprintf(reply->message, L"'%S/%S' - %S.", module, key, buffer);
}
else {
reply->code = MIMRES_FAILURE;
- mir_snprintf(reply->message, Translate("Could not retrieve setting '%s/%s': %s."), module, key, buffer);
+ mir_snwprintf(reply->message, TranslateT("Could not retrieve setting '%S/%S': %S."), module, key, buffer);
}
}
else {
reply->code = MIMRES_FAILURE;
- mir_snprintf(reply->message, Translate("Setting '%s/%s' was not found."), module, key);
+ mir_snwprintf(reply->message, TranslateT("Setting '%S/%S' was not found."), module, key);
}
}
- else {
- HandleWrongParametersCount(command, reply);
- }
- }
- else {
- HandleUnknownParameter(command, dbcmd, reply);
+ else HandleWrongParametersCount(command, reply);
}
+ else HandleUnknownParameter(command, dbcmd, reply);
}
- else {
- HandleWrongParametersCount(command, reply);
- }
+ else HandleWrongParametersCount(command, reply);
}
-int ParseProxyType(char *type)
+int ParseProxyType(wchar_t *type)
{
- char lower[128];
- strncpy_s(lower, type, sizeof(lower));
- lower[sizeof(lower) - 1] = 0;
- _strlwr(lower);
+ wchar_t lower[128];
+ wcsncpy_s(lower, type, _countof(lower));
+ lower[_countof(lower) - 1] = 0;
+ _wcslwr(lower);
- if (mir_strcmp(lower, "socks4") == 0) {
+ if (mir_wstrcmp(lower, L"socks4") == 0)
return PROXY_SOCKS4;
- }
- else if (mir_strcmp(lower, "socks5") == 0) {
+
+ if (mir_wstrcmp(lower, L"socks5") == 0)
return PROXY_SOCKS5;
- }
- else if (mir_strcmp(lower, "http") == 0) {
+
+ if (mir_wstrcmp(lower, L"http") == 0)
return PROXY_HTTP;
- }
- else if (mir_strcmp(lower, "https") == 0) {
+
+ if (mir_wstrcmp(lower, L"https") == 0)
return PROXY_HTTPS;
- }
- else
- return 0;
+
+ return 0;
}
-char *PrettyProxyType(int type, char *buffer, int size)
+char* PrettyProxyType(int type, char *buffer, int size)
{
char *pretty = "";
switch (type) {
@@ -1035,55 +978,46 @@ char *PrettyProxyType(int type, char *buffer, int size) }
strncpy_s(buffer, size, pretty, _TRUNCATE);
-
return buffer;
}
void HandleProtocolProxyCommand(PCommand command, TArgument *argv, int argc, PReply reply, char *module, char *protocol)
{
- char proxycmd[128];
- strncpy_s(proxycmd, argv[3], sizeof(proxycmd));
- proxycmd[sizeof(proxycmd) - 1] = 0;
- _strlwr(proxycmd);
-
- char buffer[1024];
+ wchar_t proxycmd[128];
+ wcsncpy_s(proxycmd, argv[3], _countof(proxycmd));
+ proxycmd[_countof(proxycmd) - 1] = 0;
+ _wcslwr(proxycmd);
+ wchar_t buffer[1024];
- if (mir_strcmp(proxycmd, "status") == 0) {//status command
+ if (mir_wstrcmp(proxycmd, L"status") == 0) {//status command
switch (argc) {
case 4:
{
int value = db_get_b(NULL, module, "NLUseProxy", 0);
reply->code = MIMRES_SUCCESS;
- mir_snprintf(buffer, "%s proxy status is %s", protocol, (value) ? "enabled" : "disabled");
-
- break;
+ mir_snwprintf(buffer, L"%S proxy status is %s", protocol, (value) ? L"enabled" : L"disabled");
}
+ break;
case 5:
{
int state = Get2StateValue(argv[4]);
switch (state) {
case STATE_OFF:
- {
- db_set_b(NULL, module, "NLUseProxy", 0);
-
- reply->code = MIMRES_SUCCESS;
- mir_snprintf(buffer, Translate("'%s' proxy was disabled."), protocol);
+ db_set_b(NULL, module, "NLUseProxy", 0);
- break;
- }
+ reply->code = MIMRES_SUCCESS;
+ mir_snwprintf(buffer, TranslateT("'%S' proxy was disabled."), protocol);
+ break;
case STATE_ON:
- {
- db_set_b(NULL, module, "NLUseProxy", 1);
-
- reply->code = MIMRES_SUCCESS;
- mir_snprintf(buffer, Translate("'%s' proxy was enabled."), protocol);
+ db_set_b(NULL, module, "NLUseProxy", 1);
- break;
- }
+ reply->code = MIMRES_SUCCESS;
+ mir_snwprintf(buffer, TranslateT("'%S' proxy was enabled."), protocol);
+ break;
case STATE_TOGGLE:
{
@@ -1092,16 +1026,14 @@ void HandleProtocolProxyCommand(PCommand command, TArgument *argv, int argc, PRe db_set_b(NULL, module, "NLUseProxy", value);
reply->code = MIMRES_SUCCESS;
- mir_snprintf(buffer, (value) ? Translate("'%s' proxy was enabled.") : Translate("'%s' proxy was disabled."));
-
- break;
+ mir_snwprintf(buffer, (value) ? TranslateT("'%S' proxy was enabled.") : TranslateT("'%S' proxy was disabled."), protocol);
}
+ break;
default:
HandleUnknownParameter(command, argv[4], reply);
return;
}
-
break;
}
@@ -1110,28 +1042,26 @@ void HandleProtocolProxyCommand(PCommand command, TArgument *argv, int argc, PRe return;
}
}
- else if (mir_strcmp(proxycmd, "server") == 0) {
+ else if (mir_wstrcmp(proxycmd, L"server") == 0) {
switch (argc) {
case 4:
{
char host[256], type[256];
- GetStringFromDatabase(NULL, module, "NLProxyServer", "<unknown>", host, sizeof(host));
+ GetStringFromDatabase(NULL, module, "NLProxyServer", "<unknown>", host, _countof(host));
int port = db_get_w(NULL, module, "NLProxyPort", 0);
- PrettyProxyType(db_get_b(NULL, module, "NLProxyType", 0), type, sizeof(type));
+ PrettyProxyType(db_get_b(NULL, module, "NLProxyType", 0), type, _countof(type));
reply->code = MIMRES_SUCCESS;
- mir_snprintf(buffer, Translate("%s proxy server: %s %s:%d."), protocol, type, host, port);
-
- break;
+ mir_snwprintf(buffer, TranslateT("%S proxy server: %S %S:%d."), protocol, type, host, port);
}
+ break;
case 7:
{
int type = ParseProxyType(argv[4]);
- char *host = argv[5];
- long port;
- char *stop = nullptr;
- port = strtol(argv[6], &stop, 10);
+ ptrA host(mir_u2a(argv[5]));
+ wchar_t *stop = nullptr;
+ long port = wcstol(argv[6], &stop, 10);
if ((*stop == 0) && (type > 0)) {
db_set_s(NULL, module, "NLProxyServer", host);
@@ -1139,15 +1069,14 @@ void HandleProtocolProxyCommand(PCommand command, TArgument *argv, int argc, PRe db_set_b(NULL, module, "NLProxyType", type);
reply->code = MIMRES_SUCCESS;
- mir_snprintf(buffer, Translate("%s proxy set to %s %s:%d."), protocol, argv[4], host, port);
+ mir_snwprintf(buffer, TranslateT("%S proxy set to %s %S:%d."), protocol, argv[4], host, port);
}
else {
reply->code = MIMRES_FAILURE;
- mir_snprintf(buffer, Translate("%s The port or the proxy type parameter is invalid."), protocol);
+ mir_snwprintf(buffer, TranslateT("%S The port or the proxy type parameter is invalid."), protocol);
}
-
- break;
}
+ break;
default:
HandleWrongParametersCount(command, reply);
@@ -1159,26 +1088,23 @@ void HandleProtocolProxyCommand(PCommand command, TArgument *argv, int argc, PRe return;
}
-
if (reply->message[0] != 0) {
- mir_strncat(reply->message, "\n", _countof(reply->message) - mir_strlen(reply->message));
- mir_strncat(reply->message, buffer, _countof(reply->message) - mir_strlen(reply->message));
+ mir_wstrncat(reply->message, L"\n", _countof(reply->message) - mir_wstrlen(reply->message));
+ mir_wstrncat(reply->message, buffer, _countof(reply->message) - mir_wstrlen(reply->message));
reply->message[_countof(reply->message) - 1] = 0;
}
- else {
- mir_snprintf(reply->message, buffer);
- }
+ else mir_snwprintf(reply->message, buffer);
}
void HandleProxyCommand(PCommand command, TArgument *argv, int argc, PReply reply)
{
if (argc >= 4) {
- char account[128];
- char protocol[128];
- strncpy_s(account, argv[2], sizeof(account));
- account[sizeof(account) - 1] = 0;
+ wchar_t account[128];
+ wcsncpy_s(account, argv[2], _countof(account));
+ account[_countof(account) - 1] = 0;
- AccountName2Protocol(account, protocol, sizeof(protocol));
+ char protocol[128];
+ AccountName2Protocol(account, protocol, _countof(protocol));
int count = 0;
PROTOACCOUNT **accounts = nullptr;
@@ -1209,53 +1135,53 @@ void HandleProxyCommand(PCommand command, TArgument *argv, int argc, PReply repl if (!found) {
reply->code = MIMRES_FAILURE;
- mir_snprintf(reply->message, Translate("'%s' doesn't seem to be a valid account."), account);
+ mir_snwprintf(reply->message, TranslateT("'%s' doesn't seem to be a valid account."), account);
}
}
- else {
- HandleWrongParametersCount(command, reply);
- }
+ else HandleWrongParametersCount(command, reply);
}
-int ContactMatchSearch(MCONTACT hContact, char *contact, char *id, char *account, TArgument *argv, int argc)
+int ContactMatchSearch(MCONTACT hContact, wchar_t *contact, wchar_t *id, char *account, TArgument *argv, int argc)
{
int matches = 1;
- char lwrName[2048] = "\0";
- char lwrAccount[128] = "\0";
- char lwrKeyword[512] = "\0";
- char lwrID[512] = "\0";
- char *pos;
+ wchar_t lwrName[2048];
+ char lwrAccount[128];
+ wchar_t lwrKeyword[512];
+ wchar_t lwrID[512];
+ wchar_t *pos;
- strncpy_s(lwrName, contact, sizeof(lwrName));
- strncpy_s(lwrAccount, account, sizeof(lwrAccount));
+ wcsncpy_s(lwrName, contact, _countof(lwrName));
+ strncpy_s(lwrAccount, account, _countof(lwrAccount));
- if (id) { strncpy_s(lwrID, id, sizeof(lwrID)); }
+ if (id)
+ wcsncpy_s(lwrID, id, _countof(lwrID));
+ else
+ lwrID[0] = 0;
- _strlwr(lwrName);
+ _wcslwr(lwrName);
_strlwr(lwrAccount);
- _strlwr(lwrID);
+ _wcslwr(lwrID);
for (int i = 0; i < argc; i++) {
- strncpy_s(lwrKeyword, argv[i], sizeof(lwrKeyword));
- _strlwr(lwrKeyword);
+ wcsncpy_s(lwrKeyword, argv[i], _countof(lwrKeyword));
+ _wcslwr(lwrKeyword);
- pos = strstr(lwrKeyword, "account:");
+ pos = wcsstr(lwrKeyword, L"account:");
if (pos) {
pos += 8;
- if (strstr(lwrAccount, pos) == nullptr) {
+ if (strstr(lwrAccount, _T2A(pos)) == nullptr) {
matches = 0;
-
break;
}
}
else {
- pos = strstr(lwrKeyword, "status:");
+ pos = wcsstr(lwrKeyword, L"status:");
if (pos) {
int searchStatus = ParseStatusParam(pos + 7);
char protocol[128];
- AccountName2Protocol(account, protocol, sizeof(protocol));
+ AccountName2Protocol(_A2T(account), protocol, _countof(protocol));
WORD contactStatus = db_get_w(hContact, protocol, "Status", ID_STATUS_OFFLINE);
if (searchStatus != contactStatus) {
@@ -1264,15 +1190,15 @@ int ContactMatchSearch(MCONTACT hContact, char *contact, char *id, char *account }
}
else {
- pos = strstr(lwrKeyword, "id:");
+ pos = wcsstr(lwrKeyword, L"id:");
if (pos) {
pos += 3;
- if (strstr(lwrID, pos) == nullptr) {
+ if (wcsstr(lwrID, pos) == nullptr) {
matches = 0;
break;
}
}
- else if ((strstr(lwrName, lwrKeyword) == nullptr)) {
+ else if ((wcsstr(lwrName, lwrKeyword) == nullptr)) {
matches = 0;
break;
}
@@ -1286,38 +1212,34 @@ int ContactMatchSearch(MCONTACT hContact, char *contact, char *id, char *account void __cdecl OpenMessageWindowThread(void *data)
{
MCONTACT hContact = (UINT_PTR)data;
- if (hContact) {
+ if (hContact)
CallServiceSync(MS_MSG_SENDMESSAGEW, hContact, 0);
- }
}
-
void HandleContactsCommand(PCommand command, TArgument *argv, int argc, PReply reply)
{
if (argc >= 3) {
- if (_stricmp(argv[2], "list") == 0) {
- char buffer[1024];
+ if (_wcsicmp(argv[2], L"list") == 0) {
+ wchar_t buffer[1024];
char protocol[128];
int count = 0;
reply->code = MIMRES_SUCCESS;
for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) {
- GetContactProto(hContact, protocol, sizeof(protocol));
+ GetContactProto(hContact, protocol, _countof(protocol));
- char *contact = GetContactName(hContact, protocol);
- char *id = GetContactID(hContact, protocol);
+ ptrW contact(GetContactName(hContact, protocol));
+ ptrW id(GetContactID(hContact, protocol));
if (ContactMatchSearch(hContact, contact, id, protocol, &argv[3], argc - 3)) {
- mir_snprintf(buffer, "%s:[%s]:%s (%08d)", contact, id, protocol, hContact);
+ mir_snwprintf(buffer, L"%s:[%s]:%S (%08d)", contact, id, protocol, hContact);
if (count) {
- mir_strncat(reply->message, "\n", _countof(reply->message) - mir_strlen(reply->message));
- mir_strncat(reply->message, buffer, _countof(reply->message) - mir_strlen(reply->message));
- }
- else {
- strncpy_s(reply->message, buffer, _countof(reply->message));
+ mir_wstrncat(reply->message, L"\n", _countof(reply->message) - mir_wstrlen(reply->message));
+ mir_wstrncat(reply->message, buffer, _countof(reply->message) - mir_wstrlen(reply->message));
}
+ else wcsncpy_s(reply->message, buffer, _countof(reply->message));
- if (mir_strlen(reply->message) > 4096) {
+ if (mir_wstrlen(reply->message) > 4096) {
SetEvent(heServerBufferFull);
Sleep(750); //wait a few milliseconds for the event to be processed
count = 0;
@@ -1326,27 +1248,21 @@ void HandleContactsCommand(PCommand command, TArgument *argv, int argc, PReply r count++;
}
-
- free(contact);
- free(id);
}
}
- else if (_stricmp(argv[2], "open") == 0) {
+ else if (_wcsicmp(argv[2], L"open") == 0) {
if (argc > 3) {
char protocol[128];
reply->code = MIMRES_SUCCESS;
*reply->message = 0;
for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) {
- GetContactProto(hContact, protocol, sizeof(protocol));
+ GetContactProto(hContact, protocol, _countof(protocol));
- char *contact = GetContactName(hContact, protocol);
- char *id = GetContactID(hContact, protocol);
+ ptrW contact(GetContactName(hContact, protocol));
+ ptrW id(GetContactID(hContact, protocol));
if (ContactMatchSearch(hContact, contact, id, protocol, &argv[3], argc - 3))
mir_forkthread(OpenMessageWindowThread, (void*)hContact);
-
- free(contact);
- free(id);
}
}
else if (argc == 3) {
@@ -1366,31 +1282,28 @@ void HandleContactsCommand(PCommand command, TArgument *argv, int argc, PReply r else HandleWrongParametersCount(command, reply);
}
-void AddHistoryEvent(DBEVENTINFO *dbEvent, char *contact, PReply reply)
+void AddHistoryEvent(DBEVENTINFO *dbEvent, wchar_t *contact, PReply reply)
{
char timestamp[256];
- TimeZone_ToString(dbEvent->timestamp, "D, s", timestamp, sizeof(timestamp));
-
- char *sender = (dbEvent->flags & DBEF_SENT) ? Translate("[me]") : contact;
- char *message = DbEvent_GetTextA(dbEvent, CP_ACP);
+ TimeZone_ToString(dbEvent->timestamp, "D, s", timestamp, _countof(timestamp));
- static char buffer[8192];
- mir_snprintf(buffer, "[%s] %15s: %s", timestamp, sender, message);
+ wchar_t *sender = (dbEvent->flags & DBEF_SENT) ? TranslateT("[me]") : contact;
+ wchar_t *message = DbEvent_GetTextW(dbEvent, CP_ACP);
+ static wchar_t buffer[8192];
+ mir_snwprintf(buffer, L"[%S] %15s: %s", timestamp, sender, message);
if (reply->message[0] != 0) {
- mir_strncat(reply->message, "\n", _countof(reply->message) - mir_strlen(reply->message));
- mir_strncat(reply->message, buffer, _countof(reply->message) - mir_strlen(reply->message));
- }
- else {
- strncpy_s(reply->message, buffer, _countof(reply->message));
+ mir_wstrncat(reply->message, L"\n", _countof(reply->message) - mir_wstrlen(reply->message));
+ mir_wstrncat(reply->message, buffer, _countof(reply->message) - mir_wstrlen(reply->message));
}
+ else wcsncpy_s(reply->message, buffer, _countof(reply->message));
- if (mir_strlen(reply->message) > (_countof(reply->message) / 2)) {
+ if (mir_wstrlen(reply->message) > (_countof(reply->message) / 2)) {
SetEvent(heServerBufferFull);
Sleep(750);
- mir_strcpy(reply->message, "\n");
+ mir_wstrcpy(reply->message, L"\n");
}
mir_free(message);
}
@@ -1398,17 +1311,17 @@ void AddHistoryEvent(DBEVENTINFO *dbEvent, char *contact, PReply reply) void HandleHistoryCommand(PCommand command, TArgument *argv, int argc, PReply reply)
{
if (argc >= 3) {
- char *cmd = argv[2];
+ wchar_t *cmd = argv[2];
switch (argc) {
case 3:
- if (_stricmp(cmd, "unread") == 0) {
- char buffer[4096];
+ if (_wcsicmp(cmd, L"unread") == 0) {
+ wchar_t buffer[4096];
int count;
int contacts = 0;
DBEVENTINFO dbEvent = {};
reply->code = MIMRES_SUCCESS;
- mir_snprintf(reply->message, Translate("No unread messages found."));
+ mir_snwprintf(reply->message, TranslateT("No unread messages found."));
for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) {
MEVENT hEvent = db_event_firstUnread(hContact);
@@ -1423,23 +1336,21 @@ void HandleHistoryCommand(PCommand command, TArgument *argv, int argc, PReply re }
char protocol[128];
- GetContactProto(hContact, protocol, sizeof(protocol));
- char *contact = GetContactName(hContact, protocol);
- mir_snprintf(buffer, Translate("%s:%s - %d unread events."), contact, protocol, count);
+ GetContactProto(hContact, protocol, _countof(protocol));
+ ptrW contact(GetContactName(hContact, protocol));
+ mir_snwprintf(buffer, TranslateT("%s:%S - %d unread events."), contact, protocol, count);
if (contacts > 0) {
- mir_strncat(reply->message, "\n", _countof(reply->message) - mir_strlen(reply->message));
- mir_strncat(reply->message, buffer, _countof(reply->message) - mir_strlen(reply->message));
+ mir_wstrncat(reply->message, L"\n", _countof(reply->message) - mir_wstrlen(reply->message));
+ mir_wstrncat(reply->message, buffer, _countof(reply->message) - mir_wstrlen(reply->message));
}
- else strncpy_s(reply->message, buffer, _countof(reply->message));
+ else wcsncpy_s(reply->message, buffer, _countof(reply->message));
contacts++;
-
- free(contact);
}
}
}
- else if (_stricmp(cmd, "show") == 0)
+ else if (_wcsicmp(cmd, L"show") == 0)
HandleWrongParametersCount(command, reply);
else
HandleUnknownParameter(command, cmd, reply);
@@ -1447,10 +1358,10 @@ void HandleHistoryCommand(PCommand command, TArgument *argv, int argc, PReply re case 4:
{
- char *contact = argv[3];
+ wchar_t *contact = argv[3];
MCONTACT hContact = ParseContactParam(contact);
if (hContact) {
- if (_stricmp(cmd, "unread") == 0) {
+ if (_wcsicmp(cmd, L"unread") == 0) {
MEVENT hEvent = db_event_firstUnread(hContact);
reply->code = MIMRES_SUCCESS;
@@ -1464,29 +1375,29 @@ void HandleHistoryCommand(PCommand command, TArgument *argv, int argc, PReply re hEvent = db_event_next(hContact, hEvent);
}
}
- else if (_stricmp(cmd, "show") == 0) {
+ else if (_wcsicmp(cmd, L"show") == 0) {
reply->code = MIMRES_SUCCESS;
- mir_snprintf(reply->message, Translate("Contact '%s' has %d events in history."), contact, db_event_count(hContact));
+ mir_snwprintf(reply->message, TranslateT("Contact '%s' has %d events in history."), contact, db_event_count(hContact));
}
else HandleUnknownParameter(command, cmd, reply);
}
else {
reply->code = MIMRES_FAILURE;
- mir_snprintf(reply->message, Translate("Could not find contact handle for contact '%s'."), contact);
+ mir_snwprintf(reply->message, TranslateT("Could not find contact handle for contact '%s'."), contact);
}
}
break;
case 6:
{
- char *contact = argv[3];
+ wchar_t *contact = argv[3];
MCONTACT hContact = ParseContactParam(contact);
if (hContact) {
- if (_stricmp(cmd, "show") == 0) {
- char *stop1 = nullptr;
- char *stop2 = nullptr;
- long start = strtol(argv[4], &stop1, 10);
- long stop = strtol(argv[5], &stop2, 10);
+ if (_wcsicmp(cmd, L"show") == 0) {
+ wchar_t *stop1 = nullptr;
+ wchar_t *stop2 = nullptr;
+ long start = wcstol(argv[4], &stop1, 10);
+ long stop = wcstol(argv[5], &stop2, 10);
if (!(*stop1) && !(*stop2)) {
int size = db_event_count(hContact);
if (start < 0) { start = size + start + 1; }
@@ -1503,9 +1414,8 @@ void HandleHistoryCommand(PCommand command, TArgument *argv, int argc, PReply re dbEvent.pBlob = (PBYTE)message;
while (hEvent) {
- dbEvent.cbBlob = sizeof(message);
- if (!db_event_get(hEvent, &dbEvent)) // if successful call
- {
+ dbEvent.cbBlob = _countof(message);
+ if (!db_event_get(hEvent, &dbEvent)) { // if successful call
dbEvent.pBlob[dbEvent.cbBlob] = 0;
if ((index >= start) && (index <= stop))
AddHistoryEvent(&dbEvent, contact, reply);
@@ -1521,14 +1431,14 @@ void HandleHistoryCommand(PCommand command, TArgument *argv, int argc, PReply re }
else HandleUnknownParameter(command, (*stop1) ? argv[4] : argv[5], reply);
}
- else if (_stricmp(cmd, "unread") == 0)
+ else if (_wcsicmp(cmd, L"unread") == 0)
HandleWrongParametersCount(command, reply);
else
HandleUnknownParameter(command, cmd, reply);
}
else {
reply->code = MIMRES_FAILURE;
- mir_snprintf(reply->message, Translate("Could not find contact handle for contact '%s'."), contact);
+ mir_snwprintf(reply->message, TranslateT("Could not find contact handle for contact '%s'."), contact);
}
}
break;
@@ -1548,14 +1458,14 @@ void HandleVersionCommand(PCommand command, TArgument*, int argc, PReply reply) if (ServiceExists(MS_CRASHDUMPER_GETINFO)) {
char *data;
CallService(MS_CRASHDUMPER_GETINFO, (WPARAM)FALSE, (LPARAM)&data);
- mir_snprintf(reply->message, data);
+ mir_snwprintf(reply->message, _A2T(data));
mir_free(data);
}
else {
char miranda[512];
DWORD v = pluginInfo.version;
- Miranda_GetVersionText(miranda, sizeof(miranda));
- mir_snprintf(reply->message, "Miranda %s\nCmdLine v.%d.%d.%d.%d", miranda, ((v >> 24) & 0xFF), ((v >> 16) & 0xFF), ((v >> 8) & 0xFF), (v & 0xFF));
+ Miranda_GetVersionText(miranda, _countof(miranda));
+ mir_snwprintf(reply->message, L"Miranda %S\nCmdLine v.%d.%d.%d.%d", miranda, ((v >> 24) & 0xFF), ((v >> 16) & 0xFF), ((v >> 8) & 0xFF), (v & 0xFF));
}
}
else HandleWrongParametersCount(command, reply);
@@ -1564,11 +1474,11 @@ void HandleVersionCommand(PCommand command, TArgument*, int argc, PReply reply) void HandleSetNicknameCommand(PCommand command, TArgument *argv, int argc, PReply reply)
{
if (argc == 4) {
- char protocol[512], nickname[512];
- mir_strcpy(protocol, argv[2]);
- mir_strcpy(nickname, argv[3]);
+ wchar_t protocol[512], nickname[512];
+ mir_wstrcpy(protocol, argv[2]);
+ mir_wstrcpy(nickname, argv[3]);
- int res = CallProtoService(protocol, PS_SETMYNICKNAME, SMNN_UNICODE, (LPARAM)nickname);
+ int res = CallProtoService(_T2A(protocol), PS_SETMYNICKNAME, SMNN_UNICODE, (LPARAM)nickname);
if (res == 0) {
reply->code = MIMRES_SUCCESS;
@@ -1576,7 +1486,7 @@ void HandleSetNicknameCommand(PCommand command, TArgument *argv, int argc, PRepl }
else {
reply->code = MIMRES_FAILURE;
- mir_snprintf(reply->message, Translate("Error setting nickname to '%s' for protocol '%s'"), nickname, protocol);
+ mir_snwprintf(reply->message, TranslateT("Error setting nickname to '%s' for protocol '%s'"), nickname, protocol);
}
}
else HandleWrongParametersCount(command, reply);
@@ -1586,10 +1496,10 @@ void HandleIgnoreCommand(PCommand command, TArgument *argv, int argc, PReply rep {
if (argc >= 4) {
BOOL block = FALSE;
- if (_stricmp(argv[2], "block") == 0) {
+ if (_wcsicmp(argv[2], L"block") == 0) {
block = TRUE;
}
- else if (_stricmp(argv[2], "unblock") == 0) {
+ else if (_wcsicmp(argv[2], L"unblock") == 0) {
block = FALSE;
}
else {
@@ -1617,26 +1527,26 @@ void HandleLuaCommand(PCommand command, TArgument *argv, int argc, PReply reply) return;
}
- if (_stricmp(argv[2], "call") == 0) {
+ if (_wcsicmp(argv[2], L"call") == 0) {
wchar_t *result = argc == 4
- ? lua_call(nullptr, _A2T(argv[3]))
- : lua_call(_A2T(argv[3]), _A2T(argv[4]));
- mir_strcpy(reply->message, _T2A(result));
+ ? lua_call(nullptr, argv[3])
+ : lua_call(argv[3], argv[4]);
+ mir_wstrcpy(reply->message, result);
mir_free(result);
reply->code = MIMRES_SUCCESS;
return;
}
- if (_stricmp(argv[2], "exec") == 0) {
- ptrW result(lua_exec(_A2T(argv[3])));
- mir_strcpy(reply->message, _T2A(result));
+ if (_wcsicmp(argv[2], L"exec") == 0) {
+ ptrW result(lua_exec(argv[3]));
+ mir_wstrcpy(reply->message, result);
reply->code = MIMRES_SUCCESS;
return;
}
- if (_stricmp(argv[2], "eval") == 0) {
- ptrW result(lua_eval(_A2T(argv[3])));
- mir_strcpy(reply->message, _T2A(result));
+ if (_wcsicmp(argv[2], L"eval") == 0) {
+ ptrW result(lua_eval(argv[3]));
+ mir_wstrcpy(reply->message, result);
reply->code = MIMRES_SUCCESS;
return;
}
@@ -1721,6 +1631,6 @@ void HandleCommand(PCommand command, TArgument *argv, int argc, PReply reply) default:
reply->code = MIMRES_NOTFOUND;
- mir_snprintf(reply->message, Translate("Command '%s' is not currently supported."), command->command);
+ mir_snwprintf(reply->message, TranslateT("Command '%s' is not currently supported."), command->command);
}
}
diff --git a/plugins/CmdLine/src/services.cpp b/plugins/CmdLine/src/services.cpp index 56c768878a..66f1c6d310 100644 --- a/plugins/CmdLine/src/services.cpp +++ b/plugins/CmdLine/src/services.cpp @@ -75,11 +75,11 @@ int StartServer() HANDLE server = mir_forkthread(ServerWorkerThread, nullptr);
if (server)
{
- char path[MIMFOLDER_SIZE];
- GetModuleFileNameA(GetModuleHandle(nullptr), path, sizeof(path));
- char *p = strrchr(path, '\\');
- if (p) { *p = 0; }
- strncpy_s(sdCmdLine->mimFolder, path, _TRUNCATE);
+ wchar_t path[MIMFOLDER_SIZE];
+ GetModuleFileNameW(GetModuleHandle(nullptr), path, _countof(path));
+ wchar_t *p = wcsrchr(path, '\\');
+ if (p) *p = 0;
+ wcsncpy_s(sdCmdLine->mimFolder, path, _TRUNCATE);
sdCmdLine->instances++;
failure = 0;
@@ -96,4 +96,4 @@ extern "C" __declspec(dllexport) void ListCommands(PCommand * commands, int *cou {
*commands = mimCommands;
*count = cMimCommands;
-}
\ No newline at end of file +}
diff --git a/plugins/CmdLine/src/utils.cpp b/plugins/CmdLine/src/utils.cpp index eb8081ccd0..97c2ef57f7 100644 --- a/plugins/CmdLine/src/utils.cpp +++ b/plugins/CmdLine/src/utils.cpp @@ -150,70 +150,44 @@ int GetStringFromDatabase(char *szSettingName, WCHAR *szError, WCHAR *szResult, }
#pragma warning (disable: 4312)
-char* GetContactName(MCONTACT hContact, char *szProto)
+wchar_t* GetContactName(MCONTACT hContact, char *szProto)
{
- ptrW name(Contact_GetInfo(CNF_DISPLAY, hContact, szProto));
- return (name == NULL) ? nullptr : strdup(_T2A(name));
+ return Contact_GetInfo(CNF_DISPLAY, hContact, szProto);
}
-#pragma warning (default: 4312)
-#pragma warning (disable: 4312)
void GetContactProto(MCONTACT hContact, char *szProto, size_t size)
{
GetStringFromDatabase(hContact, "Protocol", "p", nullptr, szProto, size);
}
-#pragma warning (default: 4312)
-#pragma warning (disable: 4312)
-char* GetContactID(MCONTACT hContact)
+wchar_t* GetContactID(MCONTACT hContact, char *szProto)
{
- char protocol[256];
- GetContactProto(hContact, protocol, sizeof(protocol));
-
- return GetContactID(hContact, protocol);
+ return Contact_GetInfo(CNF_UNIQUEID, hContact, szProto);
}
-char* GetContactID(MCONTACT hContact, char *szProto)
+MCONTACT GetContactFromID(wchar_t *szID, char *szProto)
{
- ptrW name(Contact_GetInfo(CNF_UNIQUEID, hContact, szProto));
- return (name == NULL) ? nullptr : strdup(_T2A(name));
-}
-#pragma warning (default: 4312)
-
-#pragma warning (disable: 4312)
-MCONTACT GetContactFromID(char *szID, char *szProto)
-{
- char dispName[1024];
+ wchar_t dispName[1024];
char cProtocol[256];
int found = 0;
for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) {
GetContactProto(hContact, cProtocol, sizeof(cProtocol));
- char *szHandle = GetContactID(hContact, cProtocol);
+ ptrW szHandle(GetContactID(hContact, cProtocol));
wchar_t *tmp = pcli->pfnGetContactDisplayName(hContact, 0);
- strncpy_s(dispName, _T2A(tmp), _TRUNCATE);
+ wcsncpy_s(dispName, tmp, _TRUNCATE);
- if ((szHandle) && ((mir_strcmpi(szHandle, szID) == 0) || (mir_strcmpi(dispName, szID) == 0)) && ((szProto == nullptr) || (_stricmp(szProto, cProtocol) == 0)))
+ if ((szHandle) && ((mir_wstrcmpi(szHandle, szID) == 0) || (mir_wstrcmpi(dispName, szID) == 0)) && ((szProto == nullptr) || (_stricmp(szProto, cProtocol) == 0)))
found = 1;
- free(szHandle);
-
if (found)
return hContact;
}
return 0;
}
-#pragma warning (default: 4312)
-#pragma warning (disable: 4312)
-MCONTACT GetContactFromID(char *szID, wchar_t *szProto)
-{
- char protocol[1024];
- WideCharToMultiByte(CP_ACP, 0, szProto, -1, protocol, sizeof(protocol), nullptr, nullptr);
- return GetContactFromID(szID, protocol);
-}
#pragma warning (default: 4312)
void ScreenToClient(HWND hWnd, LPRECT rect)
diff --git a/plugins/CmdLine/src/utils.h b/plugins/CmdLine/src/utils.h index 3fe9f4ca61..617f329391 100644 --- a/plugins/CmdLine/src/utils.h +++ b/plugins/CmdLine/src/utils.h @@ -43,11 +43,9 @@ int GetStringFromDatabase(MCONTACT hContact, char *szModule, char *szSettingName int GetStringFromDatabase(char *szSettingName, char *szError, char *szResult, size_t size);
int GetStringFromDatabase(char *szSettingName, WCHAR *szError, WCHAR *szResult, size_t count);
-char* GetContactName(MCONTACT hContact, char *szProto);
-char* GetContactID(MCONTACT hContact);
-char* GetContactID(MCONTACT hContact, char *szProto);
-MCONTACT GetContactFromID(char *szID, char *szProto);
-MCONTACT GetContactFromID(char *szID, wchar_t *szProto);
+wchar_t* GetContactName(MCONTACT hContact, char *szProto);
+wchar_t* GetContactID(MCONTACT hContact, char *szProto);
+MCONTACT GetContactFromID(wchar_t *szID, char *szProto);
void GetContactProto(MCONTACT hContact, char *szProto, size_t size);
int MyPUShowMessage(char *lpzText, BYTE kind);
diff --git a/plugins/CmdLine/src/version.h b/plugins/CmdLine/src/version.h index 489988db0c..d5a28d7b91 100644 --- a/plugins/CmdLine/src/version.h +++ b/plugins/CmdLine/src/version.h @@ -1,7 +1,7 @@ #define __MAJOR_VERSION 0
-#define __MINOR_VERSION 0
-#define __RELEASE_NUM 4
-#define __BUILD_NUM 7
+#define __MINOR_VERSION 1
+#define __RELEASE_NUM 0
+#define __BUILD_NUM 1
#include <stdver.h>
diff --git a/plugins/MimCmd/src/MimCmd.cpp b/plugins/MimCmd/src/MimCmd.cpp index 14f8667b0c..fea2335465 100644 --- a/plugins/MimCmd/src/MimCmd.cpp +++ b/plugins/MimCmd/src/MimCmd.cpp @@ -22,62 +22,47 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. int hLangpack = 0;
-int lpprintf(const char *format, ...)
+wchar_t* GetProgramName(wchar_t *programName, size_t size)
{
- va_list va;
- va_start(va, format);
- const int MAX_SIZE = 16192;
- char buffer[MAX_SIZE] = { 0 };
- int len = _vsnprintf(buffer, MAX_SIZE, format, va);
- va_end(va);
- std::wcout << (wchar_t*)_A2T(buffer);
- return len;
-}
-
-char* GetProgramName(char *programName, int size)
-{
- char name[512];
- GetModuleFileNameA(GetModuleHandle(nullptr), name, sizeof(name));
- char *p = strrchr(name, '\\');
+ wchar_t name[512];
+ GetModuleFileNameW(GetModuleHandleW(nullptr), name, _countof(name));
+ wchar_t *p = wcsrchr(name, '\\');
if (p)
- strncpy_s(programName, size, p + 1, _TRUNCATE);
+ wcsncpy_s(programName, size, p + 1, _TRUNCATE);
else
- strncpy_s(programName, size, name, _TRUNCATE);
+ wcsncpy_s(programName, size, name, _TRUNCATE);
return programName;
}
void PrintUsage()
{
- char name[128];
- GetProgramName(name, sizeof(name));
+ wchar_t name[128];
+ GetProgramName(name, _countof(name));
- lpprintf(Translate("%s usage:\n"), name);
- lpprintf(Translate("%s <command> [<param> [<param> [...]]].\n"), name);
- lpprintf(Translate("This will tell Miranda to run the specified command. The commands can have zero, one or more parameters. Use '%s help' to get a list of possible commands.\n"), name);
- lpprintf(Translate("No command can have more than %d parameters.\n"), MAX_ARGUMENTS - 1);
+ wprintf(TranslateT("%s usage:\n"), name);
+ wprintf(TranslateT("%s <command> [<param> [<param> [...]]].\n"), name);
+ wprintf(TranslateT("This will tell Miranda to run the specified command. The commands can have zero, one or more parameters. Use '%s help' to get a list of possible commands.\n"), name);
+ wprintf(TranslateT("No command can have more than %d parameters.\n"), MAX_ARGUMENTS - 1);
}
void ShowVersion()
{
- char name[128];
- char message[1024];
- GetProgramName(name, sizeof(name));
- mir_snprintf(message, sizeof(message), Translate("%s version %s"), name, __VERSION_STRING_DOTS);
-
- lpprintf("%s\n", message);
+ wchar_t name[128];
+ GetProgramName(name, _countof(name));
+ wprintf(TranslateT("%s version %s"), name, __VERSION_STRING_DOTS);
}
-int main(int argc, char *argv[])
+int wmain(int argc, wchar_t *argv[])
{
_setmode(_fileno(stdout), _O_U16TEXT);
- if (argc == 2 && !strcmp(argv[1], "-v")) {
+ if (argc == 2 && !wcscmp(argv[1], L"-v")) {
ShowVersion();
return 0;
}
if ((InitClient()) || (ConnectToMiranda()) || (GetKnownCommands()) || (LoadLangPackModule())) {
- lpprintf("Could not create connection with Miranda or could not retrieve list of known commands.\n");
+ wprintf(L"Could not create connection with Miranda or could not retrieve list of known commands.\n");
return MIMRES_NOMIRANDA;
}
@@ -90,10 +75,10 @@ int main(int argc, char *argv[]) PReply reply = ParseCommand(argv, argc);
if (reply) {
error = reply->code;
- lpprintf("%s\n", reply->message);
+ wprintf(L"%s\n", reply->message);
}
else {
- lpprintf(Translate("Unknown command '%s'.\n"), argv[1]);
+ wprintf(TranslateT("Unknown command '%s'.\n"), argv[1]);
error = 0;
}
diff --git a/plugins/MimCmd/src/commands.cpp b/plugins/MimCmd/src/commands.cpp index 4d11c66f24..37a6be7795 100644 --- a/plugins/MimCmd/src/commands.cpp +++ b/plugins/MimCmd/src/commands.cpp @@ -27,9 +27,9 @@ int cKnownCommands = 0; HMODULE hCmdLineDLL = nullptr;
-char *GetMirandaFolder(char *mimFolder, int size)
+wchar_t* GetMirandaFolder(wchar_t *mimFolder, int size)
{
- strncpy_s(mimFolder, size, sdCmdLine->mimFolder, _TRUNCATE);
+ wcsncpy_s(mimFolder, size, sdCmdLine->mimFolder, _TRUNCATE);
return mimFolder;
}
@@ -51,17 +51,17 @@ int ConnectToMiranda() SetEnvironmentVariable(L"PATH", ptszVal);
delete[] ptszVal;
- char pluginPath[1024];
- GetMirandaFolder(pluginPath, sizeof(pluginPath));
- mir_strcat(pluginPath, "\\plugins\\cmdline.dll");
+ wchar_t pluginPath[1024];
+ GetMirandaFolder(pluginPath, _countof(pluginPath));
+ mir_wstrcat(pluginPath, L"\\plugins\\cmdline.dll");
ListCommands = nullptr;
- hCmdLineDLL = LoadLibraryA(pluginPath);
+ hCmdLineDLL = LoadLibraryW(pluginPath);
int failure = 1;
if (hCmdLineDLL)
- ListCommands = (LISTCOMMANDS) GetProcAddress(hCmdLineDLL, "ListCommands");
+ ListCommands = (LISTCOMMANDS)GetProcAddress(hCmdLineDLL, "ListCommands");
if (ListCommands)
failure = 0;
@@ -85,19 +85,19 @@ int DestroyKnownCommands() return 0;
}
-PCommand GetCommand(char *command)
+PCommand GetCommand(wchar_t *command)
{
int i;
- char lower[512];
- strncpy_s(lower, command, _TRUNCATE);
- _strlwr(lower);
+ wchar_t lower[512];
+ wcsncpy_s(lower, command, _TRUNCATE);
+ _wcslwr(lower);
for (i = 0; i < cKnownCommands; i++)
- if (mir_strcmp(knownCommands[i].command, lower) == 0)
+ if (mir_wstrcmp(knownCommands[i].command, lower) == 0)
return &knownCommands[i];
//allow more parameters to trigger the help command - /h -h /? --help
- if ((mir_strcmp(lower, "/h") == 0) || (mir_strcmp(lower, "-h") == 0) || (mir_strcmp(lower, "/?") == 0) || (mir_strcmp(lower, "--help") == 0))
+ if ((mir_wstrcmp(lower, L"/h") == 0) || (mir_wstrcmp(lower, L"-h") == 0) || (mir_wstrcmp(lower, L"/?") == 0) || (mir_wstrcmp(lower, L"--help") == 0))
for (i = 0; i < cKnownCommands; i++)
if (knownCommands[i].ID == MIMCMD_HELP)
return &knownCommands[i];
@@ -105,37 +105,37 @@ PCommand GetCommand(char *command) return nullptr;
}
-void HandleHelpCommand(PCommand, char *argv[], int argc, PReply reply)
+void HandleHelpCommand(PCommand, wchar_t *argv[], int argc, PReply reply)
{
- CMStringA szReply;
+ CMStringW szReply;
if (argc >= 3) {
PCommand command = GetCommand(argv[2]);
if (command) {
reply->code = MIMRES_SUCCESS;
- szReply.Append(Translate(command->help));
+ szReply.Append(TranslateW(command->help));
}
else {
reply->code = MIMRES_NOTFOUND;
- szReply.AppendFormat(Translate("No help for '%s'."), argv[2]);
+ szReply.AppendFormat(TranslateT("No help for '%s'."), argv[2]);
}
}
else {
reply->code = MIMRES_SUCCESS;
- szReply.Append(Translate("Available commands: "));
+ szReply.Append(TranslateT("Available commands: "));
for (int i = 0; i < cKnownCommands - 1; i++) {
szReply.Append(knownCommands[i].command);
- szReply.Append(", ");
+ szReply.Append(L", ");
}
szReply.Append(knownCommands[cKnownCommands-1].command);
szReply.AppendChar('.');
}
- strncpy_s(reply->message, szReply, _TRUNCATE);
+ wcsncpy_s(reply->message, szReply, _TRUNCATE);
}
-PReply ParseCommand(char *argv[], int argc)
+PReply ParseCommand(wchar_t *argv[], int argc)
{
PCommand command = GetCommand(argv[1]);
if (!command)
@@ -150,10 +150,10 @@ PReply ParseCommand(char *argv[], int argc) return reply;
}
-void FillSharedDataStruct(PCommand command, char *arguments[], int count)
+void FillSharedDataStruct(PCommand command, wchar_t *arguments[], int count)
{
for (int i = 0; i < count; i++)
- strncpy_s(sdCmdLine->arguments[i], ARGUMENT_SIZE, arguments[i], _TRUNCATE);
+ wcsncpy_s(sdCmdLine->arguments[i], ARGUMENT_SIZE, arguments[i], _TRUNCATE);
sdCmdLine->cArguments = count;
sdCmdLine->command = *command;
@@ -161,10 +161,9 @@ void FillSharedDataStruct(PCommand command, char *arguments[], int count) sdCmdLine->reply.code =-1;
}
-void ProcessConsoleCommand(PCommand command, char *arguments[], int count, PReply reply)
+void ProcessConsoleCommand(PCommand command, wchar_t *arguments[], int count, PReply reply)
{
const HANDLE events[] = { heServerDone, heServerClose, heServerBufferFull };
- const int cEvents = sizeof(events) / sizeof(events[0]);
if (WaitForSingleObject(hmClient, INFINITE) == WAIT_OBJECT_0) {//got the mutex, we're the only one who can talk to miranda now
FillSharedDataStruct(command, arguments, count);
@@ -173,25 +172,25 @@ void ProcessConsoleCommand(PCommand command, char *arguments[], int count, PRepl int done = FALSE;
while (!done) {
// wait until server either finished processing or miranda was closed
- switch (WaitForMultipleObjects(cEvents, events, FALSE, INFINITE)) {
+ switch (WaitForMultipleObjects(_countof(events), events, FALSE, INFINITE)) {
case WAIT_OBJECT_0: //done event
done = TRUE;
break; //nothing to do
case WAIT_OBJECT_0 + 1: //close event
default:
- mir_strcpy(sdCmdLine->reply.message, Translate("Miranda has been closed or an error has occurred while waiting for the result, could not process request."));
+ mir_wstrcpy(sdCmdLine->reply.message, TranslateT("Miranda has been closed or an error has occurred while waiting for the result, could not process request."));
done = TRUE;
break;
case WAIT_OBJECT_0 + 2: //buffer full event
- lpprintf("%s", reply->message);
+ wprintf(L"%s", reply->message);
break;
}
}
reply->code = sdCmdLine->reply.code;
- strncpy_s(reply->message, sdCmdLine->reply.message, _TRUNCATE);
+ wcsncpy_s(reply->message, sdCmdLine->reply.message, _TRUNCATE);
ReleaseMutex(hmClient); //let other possible clients talk to the server
}
diff --git a/plugins/MimCmd/src/commands.h b/plugins/MimCmd/src/commands.h index 2bd0f74a06..591572d15a 100644 --- a/plugins/MimCmd/src/commands.h +++ b/plugins/MimCmd/src/commands.h @@ -35,8 +35,8 @@ int DisconnectFromMiranda(); int GetKnownCommands();
int DestroyKnownCommands();
-PCommand GetCommand(char *command);
-PReply ParseCommand(char *argv[], int argc);
-void ProcessConsoleCommand(PCommand command, char *arguments[], int count, PReply reply);
+PCommand GetCommand(wchar_t *command);
+PReply ParseCommand(wchar_t *argv[], int argc);
+void ProcessConsoleCommand(PCommand command, wchar_t *arguments[], int count, PReply reply);
#endif
\ No newline at end of file diff --git a/plugins/MimCmd/src/stdafx.h b/plugins/MimCmd/src/stdafx.h index 51c2476f62..0ed8285a81 100644 --- a/plugins/MimCmd/src/stdafx.h +++ b/plugins/MimCmd/src/stdafx.h @@ -36,5 +36,3 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "version.h"
#include "../CmdLine/src/utils.h"
#include "commands.h"
-
-int lpprintf(const char *format, ...);
diff --git a/plugins/MimCmd/src/version.h b/plugins/MimCmd/src/version.h index c9625d9e64..75fb63c56a 100644 --- a/plugins/MimCmd/src/version.h +++ b/plugins/MimCmd/src/version.h @@ -1,6 +1,6 @@ #define __MAJOR_VERSION 0
-#define __MINOR_VERSION 0
-#define __RELEASE_NUM 4
+#define __MINOR_VERSION 1
+#define __RELEASE_NUM 0
#define __BUILD_NUM 1
#include <stdver.h>
|