summaryrefslogtreecommitdiff
path: root/plugins/CmdLine/src/mimcmd_handlers.cpp
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2015-06-07 12:10:26 +0000
committerGeorge Hazan <george.hazan@gmail.com>2015-06-07 12:10:26 +0000
commit1d18d087d47d7a54f68950f983029642a54d6f43 (patch)
treef13ea4f54b2c576ce802388022b5c8545483bc05 /plugins/CmdLine/src/mimcmd_handlers.cpp
parent1dd4c9316543ff292ce250f7f08b25385fc8e37a (diff)
- common.props divided into app.props & plugin.props;
- MimCmd & CmdLine converted to Unicode; git-svn-id: http://svn.miranda-ng.org/main/trunk@14048 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/CmdLine/src/mimcmd_handlers.cpp')
-rw-r--r--plugins/CmdLine/src/mimcmd_handlers.cpp566
1 files changed, 267 insertions, 299 deletions
diff --git a/plugins/CmdLine/src/mimcmd_handlers.cpp b/plugins/CmdLine/src/mimcmd_handlers.cpp
index 3b450485a1..64ab262bf7 100644
--- a/plugins/CmdLine/src/mimcmd_handlers.cpp
+++ b/plugins/CmdLine/src/mimcmd_handlers.cpp
@@ -18,7 +18,7 @@ along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
-#include "commonheaders.h"
+#include "stdafx.h"
#define STATE_UNKNOWN -1
#define STATE_OFF 0
@@ -46,27 +46,27 @@ __inline static int matches(char *command, char *lower)
int Get2StateValue(char *state)
{
char lower[512];
- STRNCPY(lower, state, sizeof(lower));
+ strncpy_s(lower, state, sizeof(lower));
_strlwr(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)))
{
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)))
{
return STATE_OFF;
}
-
+
//if (mir_strcmp(lower, "toggle") == 0)
if (matches("toggle", lower))
{
return STATE_TOGGLE;
}
-
+
return STATE_UNKNOWN;
}
@@ -74,33 +74,16 @@ int AccountName2Protocol(const char *accountName, OUT char *uniqueProtocolName,
{
int count;
PROTOACCOUNT **accounts = NULL;
-
ProtoEnumAccounts(&count, &accounts);
- STRNCPY(uniqueProtocolName, accountName, length);
-
- for (int i = 0; i < count; i++)
- {
- if (accounts[i]->bIsEnabled)
- {
- if (_stricmp(accountName, accounts[i]->tszAccountName) == 0)
- {
- STRNCPY(uniqueProtocolName, accounts[i]->szModuleName, length);
+ strncpy_s(uniqueProtocolName, length, accountName, _TRUNCATE);
+ for (int i = 0; i < count; i++) {
+ if (accounts[i]->bIsEnabled) {
+ if (_stricmp(accountName, _T2A(accounts[i]->tszAccountName)) == 0) {
+ strncpy_s(uniqueProtocolName, length, accounts[i]->szModuleName, _TRUNCATE);
return 0;
}
-
- //the account name may be unicode, try comparing with an unicode string too
- char *account = mir_u2a((wchar_t *) accounts[i]->tszAccountName);
- if (_stricmp(accountName, account) == 0)
- {
- STRNCPY(uniqueProtocolName, accounts[i]->szModuleName, length);
-
- mir_free(account);
- return 0;
- }
-
- mir_free(account);
}
}
@@ -121,68 +104,64 @@ void HandleUnknownParameter(PCommand command, char *param, PReply reply)
int ParseValueParam(char *param, void *&result)
{
- if (mir_strlen(param) > 0)
- {
- switch (*param)
+ if (mir_strlen(param) > 0) {
+ switch (*param) {
+ case 's':
{
- case 's':
- {
- size_t len = mir_strlen(param); //- 1 + 1
- result = (char *) malloc(len * sizeof(char));
- STRNCPY((char *) result, param + 1, len);
- ((char *) result)[len - 1] = 0;
- return VALUE_STRING;
- }
-
- case 'w':
- {
- size_t len = mir_strlen(param);
- result = (WCHAR *) malloc(len * sizeof(WCHAR));
- char *buffer = (char *) malloc(len * sizeof(WCHAR));
- STRNCPY(buffer, param + 1, len);
-
- MultiByteToWideChar(CP_ACP, 0, buffer, -1, (WCHAR *) result, (int) len);
-
- free(buffer);
- return VALUE_WIDE;
- }
+ size_t len = mir_strlen(param); //- 1 + 1
+ result = (char*)malloc(len * sizeof(char));
+ strcpy((char*) result, param + 1);
+ return VALUE_STRING;
+ }
- case 'b':
- {
- result = (char *) malloc(sizeof(char));
- char *stop;
-
- long tmp = strtol(param + 1, &stop, 10);
- * ((char *) result) = tmp;
-
- return (*stop == 0) ? VALUE_BYTE : VALUE_ERROR;
- }
+ case 'w':
+ {
+ size_t len = mir_strlen(param);
+ result = (WCHAR *)malloc(len * sizeof(WCHAR));
+ char *buffer = (char*)malloc(len * sizeof(WCHAR));
+ strncpy_s(buffer, len, param + 1, _TRUNCATE);
- case 'i':
- {
- result = (int *) malloc(sizeof(int));
- char *stop;
-
- long tmp = strtol(param + 1, &stop, 10);
- * ((int *) result) = tmp;
-
- return (*stop == 0) ? VALUE_WORD : VALUE_ERROR;
- }
+ MultiByteToWideChar(CP_ACP, 0, buffer, -1, (WCHAR *) result, (int) len);
- case 'd':
- {
- result = (long *) malloc(sizeof(long));
- char *stop;
- * ((long *) result) = strtol(param + 1, &stop, 10);
-
- return (*stop == 0) ? VALUE_DWORD : VALUE_ERROR;
- }
- default:
- return VALUE_UNKNOWN;
+ free(buffer);
+ return VALUE_WIDE;
+ }
+
+ case 'b':
+ {
+ result = (char *)malloc(sizeof(char));
+
+ char *stop;
+ long tmp = strtol(param + 1, &stop, 10);
+ * ((char *) result) = tmp;
+
+ return (*stop == 0) ? VALUE_BYTE : VALUE_ERROR;
+ }
+
+ case 'i':
+ {
+ result = (int *)malloc(sizeof(int));
+ char *stop;
+
+ long tmp = strtol(param + 1, &stop, 10);
+ * ((int *) result) = tmp;
+
+ return (*stop == 0) ? VALUE_WORD : VALUE_ERROR;
+ }
+
+ case 'd':
+ {
+ result = (long *)malloc(sizeof(long));
+ char *stop;
+ * ((long *) result) = strtol(param + 1, &stop, 10);
+
+ return (*stop == 0) ? VALUE_DWORD : VALUE_ERROR;
+ }
+ default:
+ return VALUE_UNKNOWN;
}
}
- else
- return VALUE_ERROR;
+ else return VALUE_ERROR;
}
int ParseStatusParam(char *status)
@@ -211,7 +190,7 @@ int ParseStatusParam(char *status)
else if ( !mir_strcmp(lower, "outtolunch"))
return ID_STATUS_OUTTOLUNCH;
else
- return 0;
+ return 0;
}
char *PrettyStatusMode(int status, char *buffer, int size)
@@ -219,7 +198,7 @@ char *PrettyStatusMode(int status, char *buffer, int size)
*buffer = 0;
char *data = (char *) CallService(MS_CLIST_GETSTATUSMODEDESCRIPTION, status, 0);
if (data)
- STRNCPY(buffer, data, size);
+ strncpy_s(buffer, size, data, _TRUNCATE);
return buffer;
}
@@ -233,7 +212,7 @@ void HandleStatusCommand(PCommand command, TArgument *argv, int argc, PReply rep
INT_PTR status = CallService(MS_CLIST_GETSTATUSMODE, 0, 0);
char pretty[128];
PrettyStatusMode(status, pretty, sizeof(pretty));
-
+
CMStringA perAccountStatus;
int count;
@@ -261,7 +240,7 @@ void HandleStatusCommand(PCommand command, TArgument *argv, int argc, PReply rep
return;
}
-
+
case 3:
{
int status = ParseStatusParam(argv[2]);
@@ -273,22 +252,22 @@ void HandleStatusCommand(PCommand command, TArgument *argv, int argc, PReply rep
{
announce_status_change(NULL, status, NULL);
}
-
+
PrettyStatusMode(old, po, sizeof(po));
CallService(MS_CLIST_SETSTATUSMODE, status, 0);
char pn[128];
PrettyStatusMode(status, pn, sizeof(pn));
-
+
reply->code = MIMRES_SUCCESS;
mir_snprintf(reply->message, _countof(reply->message), Translate("Changed global status to '%s' (previous status was '%s')."), pn, po);
}
else{
HandleUnknownParameter(command, argv[2], reply);
}
-
+
return;
}
-
+
case 4:
{
int status = ParseStatusParam(argv[2]);
@@ -304,24 +283,24 @@ void HandleStatusCommand(PCommand command, TArgument *argv, int argc, PReply rep
{
announce_status_change(protocol, status, NULL);
}
-
+
PrettyStatusMode(old, po, sizeof(po));
INT_PTR res = CallProtoService(protocol, PS_SETSTATUS, status, 0);
char pn[128];
PrettyStatusMode(status, pn, sizeof(pn));
-
+
switch (res)
{
case 0:
reply->code = MIMRES_SUCCESS;
mir_snprintf(reply->message, _countof(reply->message), Translate("Changed '%s' status to '%s' (previous status was '%s')."), account, pn, po);
return;
-
+
case CALLSERVICE_NOTFOUND:
reply->code = MIMRES_FAILURE;
mir_snprintf(reply->message, _countof(reply->message), Translate("'%s' doesn't seem to be a valid account."), account);
return;
-
+
default:
reply->code = MIMRES_FAILURE;
mir_snprintf(reply->message, _countof(reply->message), Translate("Failed to change status for account '%s' to '%s'."), account, pn);
@@ -331,10 +310,10 @@ void HandleStatusCommand(PCommand command, TArgument *argv, int argc, PReply rep
else{
HandleUnknownParameter(command, argv[2], reply);
}
-
+
return;
}
-
+
default:
HandleWrongParametersCount(command, reply);
}
@@ -383,14 +362,14 @@ void HandleAwayMsgCommand(PCommand command, TArgument *argv, int argc, PReply re
reply->code = MIMRES_SUCCESS;
return;
}
-
+
case 4:
{
char *awayMsg = argv[2];
char protocol[128];
char *account = argv[3];
AccountName2Protocol(account, protocol, sizeof(protocol));
-
+
char pn[128];
INT_PTR res = CallProtoService(protocol, PS_GETCAPS, PFLAGNUM_1, 0);
if ((res & PF1_MODEMSGSEND) != 0) //if the protocol supports away messages
@@ -407,31 +386,31 @@ void HandleAwayMsgCommand(PCommand command, TArgument *argv, int argc, PReply re
else {
res = -2;
}
-
+
switch (res)
{
case 0:
reply->code = MIMRES_SUCCESS;
mir_snprintf(reply->message, _countof(reply->message), Translate("Changed '%s' status message to '%s' (status is '%s')."), account, awayMsg, pn);
return;
-
+
case CALLSERVICE_NOTFOUND:
reply->code = MIMRES_FAILURE;
mir_snprintf(reply->message, _countof(reply->message), Translate("'%s' doesn't seem to be a valid account."), account);
return;
-
+
case -2:
reply->code = MIMRES_FAILURE;
mir_snprintf(reply->message, _countof(reply->message), Translate("Account '%s' does not support away messages, skipping."), account);
return;
-
+
default:
reply->code = MIMRES_FAILURE;
mir_snprintf(reply->message, _countof(reply->message), Translate("Failed to change status message for account '%s' to '%s' (status is '%s')."), account, awayMsg, pn);
return;
}
}
-
+
default:
HandleWrongParametersCount(command, reply);
}
@@ -472,27 +451,27 @@ void HandlePopupsCommand(PCommand command, TArgument *argv, int argc, PReply rep
{
int state = CallService(MS_POPUP_QUERY, PUQS_GETSTATUS, 0);
Set2StateReply(reply, state, 0, LPGEN("Popups are currently enabled."), "", LPGEN("Popups are currently disabled."), "");
-
+
return;
}
-
+
case 3:
{
int failure;
int state = 0;
-
+
switch (Get2StateValue(argv[2]))
{
case STATE_ON:
failure = CallService(MS_POPUP_QUERY, PUQS_ENABLEPOPUPS, 0);
state = TRUE;
break;
-
+
case STATE_OFF:
failure = CallService(MS_POPUP_QUERY, PUQS_DISABLEPOPUPS, 0);
state = FALSE;
break;
-
+
case STATE_TOGGLE:
{
int state = CallService(MS_POPUP_QUERY, PUQS_GETSTATUS, 0);
@@ -500,18 +479,18 @@ void HandlePopupsCommand(PCommand command, TArgument *argv, int argc, PReply rep
state = 1 - state;
break;
}
-
+
default:
HandleUnknownParameter(command, argv[2], reply);
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."));
-
+
return;
}
-
+
default:
HandleWrongParametersCount(command, reply);
}
@@ -527,39 +506,39 @@ void HandleSoundsCommand(PCommand command, TArgument *argv, int argc, PReply rep
Set2StateReply(reply, state, 0, LPGEN("Sounds are currently enabled."), "", LPGEN("Sounds are currently disabled."), "");
return;
}
-
+
case 3:
{
int state = 0;
-
+
switch (Get2StateValue(argv[2]))
{
case STATE_ON:
db_set_b(NULL, "Skin", "UseSound", 1);
state = TRUE;
break;
-
+
case STATE_OFF:
db_set_b(NULL, "Skin", "UseSound", 0);
state = FALSE;
break;
-
+
case STATE_TOGGLE:
state = db_get_b(NULL, "Skin", "UseSound", 1);
state = 1 - state;
db_set_b(NULL, "Skin", "UseSound", state);
break;
-
+
default:
HandleUnknownParameter(command, argv[2], reply);
return;
}
Set2StateReply(reply, state, 0, LPGEN("Sounds were enabled successfully."), "", LPGEN("Sounds were disabled successfully."), "");
-
+
return;
}
-
+
default:
HandleWrongParametersCount(command, reply);
}
@@ -574,56 +553,56 @@ void HandleClistCommand(PCommand command, TArgument *argv, int argc, PReply repl
HWND hClist = (HWND) CallService(MS_CLUI_GETHWND, 0, 0);
int state = IsWindowVisible(hClist);
Set2StateReply(reply, state, 0, LPGEN("Contact list is currently shown."), "", LPGEN("Contact list is currently hidden."), "");
-
+
return;
}
-
+
case 3:
{
int state = 0;
HWND hClist = (HWND) CallService(MS_CLUI_GETHWND, 0, 0);
-
+
switch (Get2StateValue(argv[2]))
{
case STATE_ON:
{
ShowWindow(hClist, SW_SHOW);
-
+
state = TRUE;
-
+
break;
}
-
+
case STATE_OFF:
{
ShowWindow(hClist, SW_HIDE);
state = FALSE;
-
+
break;
}
-
+
case STATE_TOGGLE:
{
state = IsWindowVisible(hClist);
-
+
state = 1 - state;
ShowWindow(hClist, (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."), "");
-
+
return;
}
-
+
default:
HandleWrongParametersCount(command, reply);
}
@@ -636,38 +615,37 @@ void HandleQuitCommand(PCommand command, TArgument *argv, int argc, PReply reply
case 2:
{
CallService("CloseAction", 0, 0);
-
+
//try another quit method
HWND hWndMiranda = (HWND)CallService(MS_CLUI_GETHWND, 0, 0);
PostMessage(hWndMiranda, WM_COMMAND, ID_ICQ_EXIT, 0);
-
+
reply->code = MIMRES_SUCCESS;
- mir_snprintf(reply->message, _countof(reply->message), TranslateT("Issued a quit command."));
-
+ mir_snprintf(reply->message, _countof(reply->message), Translate("Issued a quit command."));
break;
}
-
+
case 3:
{
char lower[128];
- STRNCPY(lower, argv[2], sizeof(lower));
+ strncpy_s(lower, argv[2], sizeof(lower));
_strlwr(lower);
-
+
if (mir_strcmp(lower, "wait") == 0)
{
CallService("CloseAction", 0, 0);
-
+
//try another quit method
HWND hWndMiranda = (HWND)CallService(MS_CLUI_GETHWND, 0, 0);
PostMessage(hWndMiranda, WM_COMMAND, ID_ICQ_EXIT, 0);
-
+
reply->code = MIMRES_SUCCESS;
- mir_snprintf(reply->message, _countof(reply->message), TranslateT("Issued a quit and wait command."));
-
+ mir_snprintf(reply->message, _countof(reply->message), Translate("Issued a quit and wait command."));
+
SetEvent(heServerBufferFull);
-
+
bWaitForUnload = 1;
-
+
while (bWaitForUnload)
{
Sleep(250); //wait for Miranda to quit.
@@ -676,10 +654,10 @@ void HandleQuitCommand(PCommand command, TArgument *argv, int argc, PReply reply
else{
HandleUnknownParameter(command, argv[2], reply);
}
-
+
break;
}
-
+
default:
HandleWrongParametersCount(command, reply);
}
@@ -692,7 +670,7 @@ void HandleExchangeCommand(PCommand command, TArgument *argv, int argc, PReply r
case 3:
{
char lower[128];
- STRNCPY(lower, argv[2], sizeof(lower));
+ strncpy_s(lower, argv[2], sizeof(lower));
_strlwr(lower);
if (mir_strcmp(lower, "check") == 0)
{
@@ -710,10 +688,10 @@ void HandleExchangeCommand(PCommand command, TArgument *argv, int argc, PReply r
else{
HandleUnknownParameter(command, argv[2], reply);
}
-
+
return;
}
-
+
default:
HandleWrongParametersCount(command, reply);
}
@@ -726,14 +704,14 @@ void HandleYAMNCommand(PCommand command, TArgument *argv, int argc, PReply reply
case 3:
{
char lower[128];
- STRNCPY(lower, argv[2], sizeof(lower));
+ strncpy_s(lower, argv[2], sizeof(lower));
_strlwr(lower);
if (mir_strcmp(lower, "check") == 0)
{
if (ServiceExists(MS_YAMN_FORCECHECK))
{
CallService(MS_YAMN_FORCECHECK, 0, 0);
-
+
reply->code = MIMRES_SUCCESS;
mir_snprintf(reply->message, _countof(reply->message), Translate("Issued check email command to YAMN plugin."));
}
@@ -745,10 +723,10 @@ void HandleYAMNCommand(PCommand command, TArgument *argv, int argc, PReply reply
else{
HandleUnknownParameter(command, argv[2], reply);
}
-
+
return;
}
-
+
default:
HandleWrongParametersCount(command, reply);
}
@@ -771,7 +749,7 @@ void HandleCallServiceCommand(PCommand command, TArgument *argv, int argc, PRepl
{
//very dangerous but the user asked
INT_PTR res = CallService(service, ((res1 == 1) ? *((long *) wParam) : (WPARAM) wParam), (LPARAM) ((res2 == 1) ? *((long *) lParam) : (LPARAM) lParam));
-
+
reply->code = MIMRES_SUCCESS;
mir_snprintf(reply->message, _countof(reply->message), Translate("CallService call successful: service '%s' returned %p."), service, res);
}
@@ -788,10 +766,10 @@ void HandleCallServiceCommand(PCommand command, TArgument *argv, int argc, PRepl
reply->code = MIMRES_FAILURE;
mir_snprintf(reply->message, _countof(reply->message), Translate("Service '%s' does not exist."), service);
}
-
+
break;
}
-
+
default:
HandleWrongParametersCount(command, reply);
}
@@ -816,23 +794,15 @@ MCONTACT ParseContactParam(char *contact)
char account[128];
char protocol[128];
char *p = strrchr(contact, ':');
- MCONTACT hContact = NULL;
- if (p)
- {
- *p = 0;
- STRNCPY(name, contact, p - contact + 1);
- STRNCPY(account, p + 1, sizeof(account));
- *p = ':';
- AccountName2Protocol(account, protocol, sizeof(protocol));
-
- hContact = GetContactFromID(name, protocol);
+ if (p == 0)
+ return GetContactFromID(contact, (char*)NULL);
- }
- else{
- hContact = GetContactFromID(contact, (char *) NULL);
- }
-
- return hContact;
+ *p = 0;
+ strncpy_s(name, contact, _TRUNCATE);
+ strncpy_s(account, p+1, _TRUNCATE);
+ *p = ':';
+ AccountName2Protocol(account, protocol, sizeof(protocol));
+ return GetContactFromID(name, protocol);
}
void HandleMessageCommand(PCommand command, TArgument *argv, int argc, PReply reply)
@@ -842,13 +812,13 @@ void HandleMessageCommand(PCommand command, TArgument *argv, int argc, PReply re
char message[512];
ParseMessage(message, argv[argc - 1]); //get the message
- CMString szReply;
+ CMStringA szReply;
ACKDATA *ack = NULL;
for (int i = 2; i < argc - 1; i++)
{
char *contact = argv[i];
MCONTACT hContact = ParseContactParam(contact);
-
+
if (i != 3)
szReply.AppendChar('\n');
@@ -864,13 +834,13 @@ void HandleMessageCommand(PCommand command, TArgument *argv, int argc, PReply re
counter++;
}
bShouldProcessAcks = FALSE;
-
+
if (counter < MAX_COUNT)
{
if (ack->result == ACKRESULT_SUCCESS)
{
if (ack->szModule)
- {
+ {
szReply.AppendFormat(Translate("Message sent to '%s'."), contact);
DBEVENTINFO e = {0};
@@ -878,14 +848,14 @@ void HandleMessageCommand(PCommand command, TArgument *argv, int argc, PReply re
e.cbSize = sizeof(DBEVENTINFO);
e.eventType = EVENTTYPE_MESSAGE;
e.flags = DBEF_SENT;
-
+
e.pBlob = (PBYTE) message;
e.cbBlob = (DWORD) mir_strlen((char *) message) + 1;
-
- STRNCPY(module, ack->szModule, sizeof(module));
+
+ strncpy_s(module, ack->szModule, sizeof(module));
e.szModule = module;
e.timestamp = (DWORD) time(NULL);
-
+
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);
@@ -908,44 +878,44 @@ bool ParseDatabaseData(DBVARIANT *var, char *buffer, int size, int free)
case DBVT_BYTE:
mir_snprintf(buffer, size, Translate("byte:%d"), var->bVal);
return true;
-
+
case DBVT_WORD:
mir_snprintf(buffer, size, Translate("word:%d"), var->wVal);
return true;
-
+
case DBVT_DWORD:
mir_snprintf(buffer, size, Translate("dword:%ld"), var->dVal);
return true;
-
+
case DBVT_ASCIIZ:
mir_snprintf(buffer, size, Translate("string:'%s'"), var->pszVal);
if (free) {
mir_free(var->pszVal);
}
-
+
return true;
-
+
case DBVT_WCHAR:
mir_snprintf(buffer, size, Translate("wide string:'%S'"), var->pwszVal);
if (free) {
mir_free(var->pwszVal);
}
return true;
-
+
case DBVT_UTF8:
mir_snprintf(buffer, size, Translate("utf8:'%s'"), var->pszVal);
if (free) {
mir_free(var->pszVal);
}
return true;
-
+
case DBVT_BLOB:
mir_snprintf(buffer, size, Translate("blob:N/A"));
if (free) {
mir_free(var->pbVal);
}
return true;
-
+
default:
mir_snprintf(buffer, size, Translate("unknown value"));
return false;
@@ -957,7 +927,7 @@ void HandleDatabaseCommand(PCommand command, TArgument *argv, int argc, PReply r
if (argc >= 3) //we have something to parse
{
char dbcmd[128];
- STRNCPY(dbcmd, argv[2], sizeof(dbcmd));
+ strncpy_s(dbcmd, argv[2], sizeof(dbcmd));
dbcmd[sizeof(dbcmd) - 1] = 0;
_strlwr(dbcmd);
if (mir_strcmp(dbcmd, "delete") == 0)
@@ -966,9 +936,9 @@ void HandleDatabaseCommand(PCommand command, TArgument *argv, int argc, PReply r
{
char *module = argv[3];
char *key = argv[4];
-
+
db_unset(NULL, module, key);
-
+
reply->code = MIMRES_SUCCESS;
mir_snprintf(reply->message, _countof(reply->message), Translate("Setting '%s/%s' deleted."), module, key);
}
@@ -982,46 +952,44 @@ void HandleDatabaseCommand(PCommand command, TArgument *argv, int argc, PReply r
{
char *module = argv[3];
char *key = argv[4];
-
- int ok = 1;
-
+
void *value = NULL;
char *wrote = NULL;
int type = ParseValueParam(argv[5], value);
-
+
switch (type)
{
case VALUE_STRING:
db_set_s(NULL, module, key, (char *) value);
wrote = Translate("string");
-
+
break;
-
+
case VALUE_BYTE:
db_set_b(NULL, module, key, (* (char *) value));
wrote = Translate("byte");
break;
-
+
case VALUE_WORD:
db_set_w(NULL, module, key, (* (WORD *) value));
wrote = Translate("word");
break;
-
+
case VALUE_DWORD:
db_set_dw(NULL, module, key, (* (DWORD *) value));
wrote = Translate("dword");
break;
-
+
case VALUE_WIDE:
db_set_ws(NULL, module, key, (WCHAR *) value);
wrote = Translate("wide string");
break;
-
+
default:
HandleUnknownParameter(command, argv[5], reply);
return;
}
-
+
reply->code = MIMRES_SUCCESS;
mir_snprintf(reply->message, _countof(reply->message), Translate("Wrote '%s:%s' to database entry '%s/%s'."), wrote, argv[5] + 1, module, key);
@@ -1037,18 +1005,18 @@ void HandleDatabaseCommand(PCommand command, TArgument *argv, int argc, PReply r
{
char *module = argv[3];
char *key = argv[4];
-
+
DBVARIANT var = {0};
-
+
int res = db_get(NULL, module, key, &var);
if (!res)
{
char buffer[1024];
-
+
if (ParseDatabaseData(&var, buffer, sizeof(buffer), TRUE))
{
reply->code = MIMRES_SUCCESS;
- mir_snprintf(reply->message, _countof(reply->message), "'%s/%s' - %s.", module, key, buffer);
+ mir_snprintf(reply->message, _countof(reply->message), "'%s/%s' - %s.", module, key, buffer);
}
else{
reply->code = MIMRES_FAILURE;
@@ -1059,7 +1027,7 @@ void HandleDatabaseCommand(PCommand command, TArgument *argv, int argc, PReply r
reply->code = MIMRES_FAILURE;
mir_snprintf(reply->message, _countof(reply->message), Translate("Setting '%s/%s' was not found."), module, key);
}
-
+
}
else{
HandleWrongParametersCount(command, reply);
@@ -1077,10 +1045,10 @@ void HandleDatabaseCommand(PCommand command, TArgument *argv, int argc, PReply r
int ParseProxyType(char *type)
{
char lower[128];
- STRNCPY(lower, type, sizeof(lower));
+ strncpy_s(lower, type, sizeof(lower));
lower[sizeof(lower) - 1] = 0;
_strlwr(lower);
-
+
if (mir_strcmp(lower, "socks4") == 0)
{
return PROXY_SOCKS4;
@@ -1109,32 +1077,32 @@ char *PrettyProxyType(int type, char *buffer, int size)
case PROXY_SOCKS4:
pretty = "SOCKS4";
break;
-
+
case PROXY_SOCKS5:
pretty = "SOCKS5";
break;
-
+
case PROXY_HTTP:
pretty = "HTTP";
break;
-
+
case PROXY_HTTPS:
pretty = "HTTPS";
break;
-
+
default:
pretty = "Unknown";
}
-
- STRNCPY(buffer, pretty, 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(proxycmd, argv[3], sizeof(proxycmd));
+ strncpy_s(proxycmd, argv[3], sizeof(proxycmd));
proxycmd[sizeof(proxycmd) - 1] = 0;
_strlwr(proxycmd);
@@ -1148,13 +1116,13 @@ void HandleProtocolProxyCommand(PCommand command, TArgument *argv, int argc, PRe
case 4:
{
int value = db_get_b(NULL, module, "NLUseProxy", 0);
-
+
reply->code = MIMRES_SUCCESS;
mir_snprintf(buffer, _countof(buffer), "%s proxy status is %s", protocol, (value) ? "enabled" : "disabled");
-
+
break;
}
-
+
case 5:
{
int state = Get2StateValue(argv[4]);
@@ -1163,43 +1131,43 @@ void HandleProtocolProxyCommand(PCommand command, TArgument *argv, int argc, PRe
case STATE_OFF:
{
db_set_b(NULL, module, "NLUseProxy", 0);
-
+
reply->code = MIMRES_SUCCESS;
mir_snprintf(buffer, _countof(buffer), Translate("'%s' proxy was disabled."), protocol);
-
+
break;
}
-
+
case STATE_ON:
{
db_set_b(NULL, module, "NLUseProxy", 1);
-
+
reply->code = MIMRES_SUCCESS;
mir_snprintf(buffer, _countof(buffer), Translate("'%s' proxy was enabled."), protocol);
-
+
break;
}
-
+
case STATE_TOGGLE:
{
int value = db_get_b(NULL, module, "NLUseProxy", 0);
value = 1 - value;
db_set_b(NULL, module, "NLUseProxy", value);
-
+
reply->code = MIMRES_SUCCESS;
mir_snprintf(buffer, _countof(buffer), (value) ? Translate("'%s' proxy was enabled.") : Translate("'%s' proxy was disabled."));
-
+
break;
}
-
+
default:
HandleUnknownParameter(command, argv[4], reply);
return;
}
-
+
break;
}
-
+
default:
HandleWrongParametersCount(command, reply);
return;
@@ -1215,13 +1183,13 @@ void HandleProtocolProxyCommand(PCommand command, TArgument *argv, int argc, PRe
GetStringFromDatabase(NULL, module, "NLProxyServer", "<unknown>", host, sizeof(host));
int port = db_get_w(NULL, module, "NLProxyPort", 0);
PrettyProxyType(db_get_b(NULL, module, "NLProxyType", 0), type, sizeof(type));
-
+
reply->code = MIMRES_SUCCESS;
mir_snprintf(buffer, _countof(buffer), Translate("%s proxy server: %s %s:%d."), protocol, type, host, port);
-
+
break;
}
-
+
case 7:
{
int type = ParseProxyType(argv[4]);
@@ -1229,13 +1197,13 @@ void HandleProtocolProxyCommand(PCommand command, TArgument *argv, int argc, PRe
long port;
char *stop = NULL;
port = strtol(argv[6], &stop, 10);
-
+
if ((*stop == 0) && (type > 0))
{
db_set_s(NULL, module, "NLProxyServer", host);
db_set_w(NULL, module, "NLProxyPort", port);
db_set_b(NULL, module, "NLProxyType", type);
-
+
reply->code = MIMRES_SUCCESS;
mir_snprintf(buffer, _countof(buffer), Translate("%s proxy set to %s %s:%d."), protocol, argv[4], host, port);
}
@@ -1243,10 +1211,10 @@ void HandleProtocolProxyCommand(PCommand command, TArgument *argv, int argc, PRe
reply->code = MIMRES_FAILURE;
mir_snprintf(buffer, _countof(buffer), Translate("%s The port or the proxy type parameter is invalid."), protocol);
}
-
+
break;
}
-
+
default:
HandleWrongParametersCount(command, reply);
return;
@@ -1257,7 +1225,7 @@ 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));
@@ -1275,15 +1243,15 @@ void HandleProxyCommand(PCommand command, TArgument *argv, int argc, PReply repl
{
char account[128];
char protocol[128];
- STRNCPY(account, argv[2], sizeof(account));
+ strncpy_s(account, argv[2], sizeof(account));
account[sizeof(account) - 1] = 0;
AccountName2Protocol(account, protocol, sizeof(protocol));
-
+
int count = 0;
PROTOACCOUNT **accounts = NULL;
ProtoEnumAccounts(&count, &accounts);
-
+
int i;
int global = (mir_strcmp(protocol, "GLOBAL") == 0);
@@ -1295,9 +1263,9 @@ void HandleProxyCommand(PCommand command, TArgument *argv, int argc, PReply repl
HandleProtocolProxyCommand(command, argv, argc, reply, "Netlib", protocol);
found = 1;
}
-
+
char *match;
-
+
for (i = 0; i < count; i++)
{
if (accounts[i]->bIsEnabled)
@@ -1310,7 +1278,7 @@ void HandleProxyCommand(PCommand command, TArgument *argv, int argc, PReply repl
}
}
}
-
+
if (!found)
{
reply->code = MIMRES_FAILURE;
@@ -1325,27 +1293,27 @@ void HandleProxyCommand(PCommand command, TArgument *argv, int argc, PReply repl
int ContactMatchSearch(MCONTACT hContact, char *contact, char *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;
-
- STRNCPY(lwrName, contact, sizeof(lwrName));
- STRNCPY(lwrAccount, account, sizeof(lwrAccount));
-
- if (id) { STRNCPY(lwrID, id, sizeof(lwrID)); }
-
+
+ strncpy_s(lwrName, contact, sizeof(lwrName));
+ strncpy_s(lwrAccount, account, sizeof(lwrAccount));
+
+ if (id) { strncpy_s(lwrID, id, sizeof(lwrID)); }
+
_strlwr(lwrName);
_strlwr(lwrAccount);
_strlwr(lwrID);
-
+
for (int i = 0; i < argc; i++)
{
- STRNCPY(lwrKeyword, argv[i], sizeof(lwrKeyword));
+ strncpy_s(lwrKeyword, argv[i], sizeof(lwrKeyword));
_strlwr(lwrKeyword);
-
+
pos = strstr(lwrKeyword, "account:");
if (pos)
{
@@ -1353,7 +1321,7 @@ int ContactMatchSearch(MCONTACT hContact, char *contact, char *id, char *account
if (strstr(lwrAccount, pos) == NULL)
{
matches = 0;
-
+
break;
}
}
@@ -1366,7 +1334,7 @@ int ContactMatchSearch(MCONTACT hContact, char *contact, char *id, char *account
AccountName2Protocol(account, protocol, sizeof(protocol));
WORD contactStatus = db_get_w(hContact, protocol, "Status", ID_STATUS_ONLINE);
-
+
if (searchStatus != contactStatus)
{
matches = 0;
@@ -1392,7 +1360,7 @@ int ContactMatchSearch(MCONTACT hContact, char *contact, char *id, char *account
}
}
}
-
+
return matches;
}
@@ -1414,13 +1382,13 @@ void HandleContactsCommand(PCommand command, TArgument *argv, int argc, PReply r
{
char 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));
-
+
char *contact = GetContactName(hContact, protocol);
char *id = GetContactID(hContact, protocol);
if (ContactMatchSearch(hContact, contact, id, protocol, &argv[3], argc - 3))
@@ -1432,9 +1400,9 @@ void HandleContactsCommand(PCommand command, TArgument *argv, int argc, PReply r
mir_strncat(reply->message, buffer, _countof(reply->message) - mir_strlen(reply->message));
}
else{
- STRNCPY(reply->message, buffer, _countof(reply->message));
+ strncpy_s(reply->message, buffer, _countof(reply->message));
}
-
+
if (mir_strlen(reply->message) > 4096)
{
SetEvent(heServerBufferFull);
@@ -1442,10 +1410,10 @@ void HandleContactsCommand(PCommand command, TArgument *argv, int argc, PReply r
count = 0;
*reply->message = 0;
}
-
+
count++;
}
-
+
free(contact);
free(id);
}
@@ -1455,17 +1423,17 @@ void HandleContactsCommand(PCommand command, TArgument *argv, int argc, PReply r
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));
-
+
char *contact = GetContactName(hContact, protocol);
char *id = GetContactID(hContact, protocol);
if (ContactMatchSearch(hContact, contact, id, protocol, &argv[3], argc - 3))
- HANDLE thread = mir_forkthread(OpenMessageWindowThread, (void*)hContact);
-
+ mir_forkthread(OpenMessageWindowThread, (void*)hContact);
+
free(contact);
free(id);
}
@@ -1477,14 +1445,14 @@ void HandleContactsCommand(PCommand command, TArgument *argv, int argc, PReply r
for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) {
MEVENT hUnreadEvent = db_event_firstUnread(hContact);
if (hUnreadEvent != NULL)
- HANDLE thread = mir_forkthread(OpenMessageWindowThread, (void*)hContact);
+ mir_forkthread(OpenMessageWindowThread, (void*)hContact);
}
}
else HandleWrongParametersCount(command, reply);
}
else HandleUnknownParameter(command, argv[2], reply);
}
- else HandleWrongParametersCount(command, reply);
+ else HandleWrongParametersCount(command, reply);
}
void AddHistoryEvent(DBEVENTINFO *dbEvent, char *contact, PReply reply)
@@ -1495,23 +1463,23 @@ void AddHistoryEvent(DBEVENTINFO *dbEvent, char *contact, PReply reply)
tts.cbDest = sizeof(timestamp);
tts.szFormat = "D, s";
CallService(MS_DB_TIME_TIMESTAMPTOSTRING, dbEvent->timestamp,(LPARAM) &tts);
-
+
char *sender = (dbEvent->flags & DBEF_SENT) ? Translate("[me]") : contact;
char *message = DbGetEventTextA(dbEvent,CP_ACP);
-
+
static char buffer[8192];
mir_snprintf(buffer, _countof(buffer), "[%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(reply->message, buffer, _countof(reply->message));
+ strncpy_s(reply->message, buffer, _countof(reply->message));
}
-
+
if (mir_strlen(reply->message) > (_countof(reply->message) / 2))
{
SetEvent(heServerBufferFull);
@@ -1562,7 +1530,7 @@ void HandleHistoryCommand(PCommand command, TArgument *argv, int argc, PReply re
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(reply->message, buffer, _countof(reply->message));
+ else strncpy_s(reply->message, buffer, _countof(reply->message));
contacts++;
@@ -1599,7 +1567,7 @@ void HandleHistoryCommand(PCommand command, TArgument *argv, int argc, PReply re
hEvent = db_event_next(hContact, hEvent);
}
}
- else if (_stricmp(cmd, "show") == 0) {
+ else if (_stricmp(cmd, "show") == 0) {
reply->code = MIMRES_SUCCESS;
mir_snprintf(reply->message, _countof(reply->message), Translate("Contact '%s' has %d events in history."), contact, db_event_count(hContact));
}
@@ -1684,7 +1652,7 @@ void HandleHistoryCommand(PCommand command, TArgument *argv, int argc, PReply re
else HandleWrongParametersCount(command, reply);
}
-void HandleVersionCommand(PCommand command, TArgument *argv, int argc, PReply reply)
+void HandleVersionCommand(PCommand command, TArgument*, int argc, PReply reply)
{
if (argc == 2)
{
@@ -1776,59 +1744,59 @@ void HandleCommand(PCommand command, TArgument *argv, int argc, PReply reply)
case MIMCMD_STATUS:
HandleStatusCommand(command, argv, argc, reply);
return;
-
+
case MIMCMD_AWAYMSG:
HandleAwayMsgCommand(command, argv, argc, reply);
return;
-
+
case MIMCMD_POPUPS:
HandlePopupsCommand(command, argv, argc, reply);
return;
-
+
case MIMCMD_SOUNDS:
HandleSoundsCommand(command, argv, argc, reply);
return;
-
+
case MIMCMD_CLIST:
HandleClistCommand(command, argv, argc, reply);
return;
-
+
case MIMCMD_QUIT:
HandleQuitCommand(command, argv, argc, reply);
return;
-
+
case MIMCMD_EXCHANGE:
HandleExchangeCommand(command, argv, argc, reply);
return;
-
+
case MIMCMD_YAMN:
HandleYAMNCommand(command, argv, argc, reply);
return;
-
+
case MIMCMD_CALLSERVICE:
HandleCallServiceCommand(command, argv, argc, reply);
return;
-
+
case MIMCMD_MESSAGE:
HandleMessageCommand(command, argv, argc, reply);
return;
-
+
case MIMCMD_DATABASE:
HandleDatabaseCommand(command, argv, argc, reply);
return;
-
+
case MIMCMD_PROXY:
HandleProxyCommand(command, argv, argc, reply);
return;
-
+
case MIMCMD_CONTACTS:
HandleContactsCommand(command, argv, argc, reply);
return;
-
+
case MIMCMD_HISTORY:
HandleHistoryCommand(command, argv, argc, reply);
break;
-
+
case MIMCMD_VERSION:
HandleVersionCommand(command, argv, argc, reply);
return;
@@ -1840,7 +1808,7 @@ void HandleCommand(PCommand command, TArgument *argv, int argc, PReply reply)
case MIMCMD_IGNORE:
HandleIgnoreCommand(command, argv, argc, reply);
return;
-
+
default:
reply->code = MIMRES_NOTFOUND;
mir_snprintf(reply->message, _countof(reply->message), Translate("Command '%s' is not currently supported."), command->command);