From 6f7054d8f6c14e032a45a42555d4ab097fc82863 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Mon, 11 May 2015 16:39:06 +0000 Subject: - STL removed; - code optimization and restructuring; - warning fixes git-svn-id: http://svn.miranda-ng.org/main/trunk@13549 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/Dropbox/src/dropbox_services.cpp | 71 ++++++++++++++------------------ 1 file changed, 30 insertions(+), 41 deletions(-) (limited to 'plugins/Dropbox/src/dropbox_services.cpp') diff --git a/plugins/Dropbox/src/dropbox_services.cpp b/plugins/Dropbox/src/dropbox_services.cpp index c1bce181d0..4667998633 100644 --- a/plugins/Dropbox/src/dropbox_services.cpp +++ b/plugins/Dropbox/src/dropbox_services.cpp @@ -67,7 +67,6 @@ INT_PTR CDropbox::ProtoSetStatus(void *obj, WPARAM wp, LPARAM) INT_PTR CDropbox::ProtoSendFile(void *obj, WPARAM, LPARAM lParam) { CDropbox *instance = (CDropbox*)obj; - if (!instance->HasAccessToken()) return ACKRESULT_FAILED; @@ -147,69 +146,60 @@ INT_PTR CDropbox::ProtoSendFile(void *obj, WPARAM, LPARAM lParam) INT_PTR CDropbox::ProtoSendMessage(void *obj, WPARAM, LPARAM lParam) { CDropbox *instance = (CDropbox*)obj; - if (!instance->HasAccessToken()) return ACKRESULT_FAILED; CCSDATA *pccsd = (CCSDATA*)lParam; - char *message = (char*)pccsd->lParam; + char *message = NEWSTR_ALLOCA((char*)pccsd->lParam); DBEVENTINFO dbei = { sizeof(dbei) }; dbei.szModule = MODULE; dbei.timestamp = time(NULL); dbei.eventType = EVENTTYPE_MESSAGE; - dbei.cbBlob = strlen(message); + dbei.cbBlob = (int)strlen(message); dbei.pBlob = (PBYTE)message; dbei.flags = DBEF_SENT | DBEF_READ | DBEF_UTF; db_event_add(pccsd->hContact, &dbei); - char help[1024]; - - if (message[0] && message[0] == '/') - { + if (message[0] && message[0] == '/') { // parse commands char *sep = strchr(message, ' '); - int len = strlen(message) - (sep ? strlen(sep) : 0) - 1; - ptrA cmd((char*)mir_alloc(len + 1)); - strncpy(cmd, message + 1, len); - cmd[len] = 0; - if (instance->commands.find((char*)cmd) != instance->commands.end()) - { - ULONG messageId = InterlockedIncrement(&instance->hMessageProcess); - - CommandParam *param = new CommandParam(); - param->instance = instance; - param->hContact = pccsd->hContact; - param->hProcess = (HANDLE)messageId; - param->data = (sep ? sep + 1 : NULL); - - mir_forkthread(instance->commands[(char*)cmd], param); + if (sep != NULL) *sep = 0; - return messageId; + struct + { + const char *szCommand; + pThreadFunc pHandler; } - else + static commands[] = { - mir_snprintf( - help, - SIZEOF(help), - Translate("Unknown command \"%s\".\nUse \"/help\" for more info."), - message); + { "help", &CDropbox::CommandHelp }, + { "content", &CDropbox::CommandContent }, + { "share", &CDropbox::CommandShare }, + { "delete", &CDropbox::CommandDelete } + }; + + for (int i=0; i < SIZEOF(commands); i++) { + if (!strcmp(message+1, commands[i].szCommand)) { + ULONG messageId = InterlockedIncrement(&instance->hMessageProcess); - CallContactService(instance->GetDefaultContact(), PSR_MESSAGE, 0, (LPARAM)help); + CommandParam *param = new CommandParam(); + param->instance = instance; + param->hContact = pccsd->hContact; + param->hProcess = (HANDLE)messageId; + param->data = (sep ? sep + 1 : NULL); - return 0; + mir_forkthread(commands[i].pHandler, param); + + return messageId; + } } } - mir_snprintf( - help, - SIZEOF(help), - Translate("\"%s\" is not valid.\nUse \"/help\" for more info."), - message); - + char help[1024]; + mir_snprintf(help, SIZEOF(help), Translate("\"%s\" is not valid.\nUse \"/help\" for more info."), message); CallContactService(instance->GetDefaultContact(), PSR_MESSAGE, 0, (LPARAM)help); - return 0; } @@ -223,7 +213,7 @@ INT_PTR CDropbox::ProtoReceiveMessage(void *, WPARAM, LPARAM lParam) dbei.szModule = MODULE; dbei.timestamp = time(NULL); dbei.eventType = EVENTTYPE_MESSAGE; - dbei.cbBlob = strlen(message); + dbei.cbBlob = (int)strlen(message); dbei.pBlob = (PBYTE)message; db_event_add(pccsd->hContact, &dbei); @@ -233,7 +223,6 @@ INT_PTR CDropbox::ProtoReceiveMessage(void *, WPARAM, LPARAM lParam) INT_PTR CDropbox::SendFileToDropbox(void *obj, WPARAM hContact, LPARAM lParam) { CDropbox *instance = (CDropbox*)obj; - if (!instance->HasAccessToken()) return 0; -- cgit v1.2.3