From 62ab18a9fda2f19c08ae63a14c7a262ca62f0cce Mon Sep 17 00:00:00 2001 From: George Hazan Date: Tue, 8 Jul 2014 15:49:18 +0000 Subject: code cleaning git-svn-id: http://svn.miranda-ng.org/main/trunk@9732 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/SecureIM/src/splitmsg.cpp | 88 ++++++++++++++++++--------------------- 1 file changed, 41 insertions(+), 47 deletions(-) (limited to 'plugins/SecureIM/src/splitmsg.cpp') diff --git a/plugins/SecureIM/src/splitmsg.cpp b/plugins/SecureIM/src/splitmsg.cpp index c9098e1999..259d636955 100644 --- a/plugins/SecureIM/src/splitmsg.cpp +++ b/plugins/SecureIM/src/splitmsg.cpp @@ -1,28 +1,27 @@ #include "commonheaders.h" - // разбивает сообщение szMsg на части длиной iLen, возвращает строку вида PARTzPARTzz LPSTR splitMsg(LPSTR szMsg, int iLen) { - Sent_NetLog("split: msg: -----\n%s\n-----\n",szMsg); + Sent_NetLog("split: msg: -----\n%s\n-----\n", szMsg); int len = (int)strlen(szMsg); - LPSTR out = (LPSTR) mir_alloc(len*2); + LPSTR out = (LPSTR)mir_alloc(len * 2); LPSTR buf = out; WORD msg_id = db_get_w(0, MODULENAME, "msgid", 0) + 1; db_set_w(0, MODULENAME, "msgid", msg_id); - int part_all = (len+iLen-1)/iLen; - for (int part_num=0; part_numiLen)?iLen:len; - mir_snprintf(buf,32,"%s%04X%02X%02X",SIG_SECP,msg_id,part_num,part_all); - memcpy(buf+LEN_SECP+8,szMsg,sz); - *(buf+LEN_SECP+8+sz) = '\0'; + int part_all = (len + iLen - 1) / iLen; + for (int part_num = 0; part_numiLen) ? iLen : len; + mir_snprintf(buf, 32, "%s%04X%02X%02X", SIG_SECP, msg_id, part_num, part_all); + memcpy(buf + LEN_SECP + 8, szMsg, sz); + *(buf + LEN_SECP + 8 + sz) = '\0'; - Sent_NetLog("split: part: %s",buf); + Sent_NetLog("split: part: %s", buf); - buf += LEN_SECP+8+sz+1; + buf += LEN_SECP + 8 + sz + 1; szMsg += sz; len -= sz; } @@ -34,46 +33,46 @@ LPSTR splitMsg(LPSTR szMsg, int iLen) // собираем сообщение из частей, части храним в структуре у контакта LPSTR combineMessage(pUinKey ptr, LPSTR szMsg) { - Sent_NetLog("combine: part: %s",szMsg); + Sent_NetLog("combine: part: %s", szMsg); - int msg_id,part_num,part_all; - sscanf(szMsg,"%4X%2X%2X",&msg_id,&part_num,&part_all); + int msg_id, part_num, part_all; + sscanf(szMsg, "%4X%2X%2X", &msg_id, &part_num, &part_all); // pPM ppm = NULL, pm = ptr->msgPart; if (!ptr->msgPart) { pm = ptr->msgPart = new partitionMessage; - memset(pm,0,sizeof(partitionMessage)); + memset(pm, 0, sizeof(partitionMessage)); pm->id = msg_id; pm->message = new LPSTR[part_all]; - memset(pm->message,0,sizeof(LPSTR)*part_all); + memset(pm->message, 0, sizeof(LPSTR)*part_all); } else - while(pm) { - if (pm->id == msg_id ) break; + while (pm) { + if (pm->id == msg_id) break; ppm = pm; pm = pm->nextMessage; - } + } if (!pm) { // nothing to found pm = ppm->nextMessage = new partitionMessage; - memset(pm,0,sizeof(partitionMessage)); + memset(pm, 0, sizeof(partitionMessage)); pm->id = msg_id; pm->message = new LPSTR[part_all]; - memset(pm->message,0,sizeof(LPSTR)*part_all); + memset(pm->message, 0, sizeof(LPSTR)*part_all); } pm->message[part_num] = new char[strlen(szMsg)]; - strcpy(pm->message[part_num],szMsg+8); + strcpy(pm->message[part_num], szMsg + 8); - Sent_NetLog("combine: save part: %s",pm->message[part_num]); + Sent_NetLog("combine: save part: %s", pm->message[part_num]); - int len=0,i; - for ( i=0; imessage[i] == NULL) break; - len+=(int)strlen(pm->message[i]); + len += (int)strlen(pm->message[i]); } if (i == part_all) { // combine message - SAFE_FREE(ptr->tmp); - ptr->tmp = (LPSTR) mir_alloc(len+1); *(ptr->tmp)='\0'; - for ( i=0; itmp,pm->message[i]); + SAFE_FREE(ptr->tmp); + ptr->tmp = (LPSTR)mir_alloc(len + 1); *(ptr->tmp) = '\0'; + for (i = 0; i < part_all; i++) { + strcat(ptr->tmp, pm->message[i]); delete pm->message[i]; } delete pm->message; @@ -91,30 +90,25 @@ LPSTR combineMessage(pUinKey ptr, LPSTR szMsg) return NULL; } - // отправляет сообщение, если надо то разбивает на части -int splitMessageSend(pUinKey ptr, LPSTR szMsg) { - - int ret; +int splitMessageSend(pUinKey ptr, LPSTR szMsg) +{ int len = (int)strlen(szMsg); - int par = (getContactStatus(ptr->hContact) == ID_STATUS_OFFLINE)?ptr->proto->split_off:ptr->proto->split_on; - if (par && len>par) { - LPSTR msg = splitMsg(szMsg,par); + int par = (getContactStatus(ptr->hContact) == ID_STATUS_OFFLINE) ? ptr->proto->split_off : ptr->proto->split_on; + if (par && len > par) { + int ret; + LPSTR msg = splitMsg(szMsg, par); LPSTR buf = msg; - while( *buf) { + while (*buf) { len = (int)strlen(buf); LPSTR tmp = mir_strdup(buf); - ret = CallContactService(ptr->hContact,PSS_MESSAGE,(WPARAM)PREF_METANODB,(LPARAM)tmp); + ret = CallContactService(ptr->hContact, PSS_MESSAGE, (WPARAM)PREF_METANODB, (LPARAM)tmp); mir_free(tmp); - buf += len+1; + buf += len + 1; } SAFE_FREE(msg); + return ret; } - else { - ret = CallContactService(ptr->hContact,PSS_MESSAGE,(WPARAM)PREF_METANODB,(LPARAM)szMsg); - } - return ret; + + return (int)CallContactService(ptr->hContact, PSS_MESSAGE, (WPARAM)PREF_METANODB, (LPARAM)szMsg); } - - -// EOF -- cgit v1.2.3