From 6d737a60aba9927be6b09f9915c3dd4e70029ad7 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Thu, 4 Apr 2019 22:35:56 +0300 Subject: unused code removed --- protocols/JabberG/src/jabber_proto.h | 4 +- protocols/JabberG/src/jabber_search.cpp | 57 +++++++++--------- protocols/JabberG/src/jabber_search.h | 100 +++++++++++++------------------- 3 files changed, 68 insertions(+), 93 deletions(-) diff --git a/protocols/JabberG/src/jabber_proto.h b/protocols/JabberG/src/jabber_proto.h index 58685fa31f..3bea53160a 100755 --- a/protocols/JabberG/src/jabber_proto.h +++ b/protocols/JabberG/src/jabber_proto.h @@ -49,8 +49,6 @@ typedef void (CJabberProto::*JABBER_FORM_SUBMIT_FUNC)(CJabberFormDlg *pDlg, void enum TJabberGcLogInfoType { INFO_BAN, INFO_STATUS, INFO_CONFIG, INFO_AFFILIATION, INFO_ROLE }; -typedef UNIQUE_MAP U_TCHAR_MAP; - #define JABBER_DEFAULT_RECENT_COUNT 10 struct TFilterInfo @@ -702,7 +700,7 @@ struct CJabberProto : public PROTO, public IJabberInterface //---- jabber_search.cpp ------------------------------------------------------------- - void SearchReturnResults(HANDLE id, void* pvUsersInfo, U_TCHAR_MAP *pmAllFields); + void SearchReturnResults(HANDLE id, void* pvUsersInfo, UNIQUE_MAP *pmAllFields); void OnIqResultAdvancedSearch(const TiXmlElement *iqNode, CJabberIqInfo *pInfo); void OnIqResultGetSearchFields(const TiXmlElement *iqNode, CJabberIqInfo *pInfo); int SearchRenewFields(HWND hwndDlg, JabberSearchData * dat); diff --git a/protocols/JabberG/src/jabber_search.cpp b/protocols/JabberG/src/jabber_search.cpp index 8223ee5682..4cfb616394 100644 --- a/protocols/JabberG/src/jabber_search.cpp +++ b/protocols/JabberG/src/jabber_search.cpp @@ -67,9 +67,10 @@ static int JabberSearchFrameProc(HWND hwnd, int msg, WPARAM wParam, LPARAM lPara dat->curPos = pos; } } - if (HIWORD(wParam) == EN_SETFOCUS) { //Transmit focus set notification to parent window + + // Transmit focus set notification to parent window + if (HIWORD(wParam) == EN_SETFOCUS) PostMessage(GetParent(hwndDlg), WM_COMMAND, MAKEWPARAM(0, EN_SETFOCUS), (LPARAM)hwndDlg); - } } if (msg == WM_PAINT) { @@ -115,8 +116,9 @@ static int JabberSearchAddField(HWND hwndDlg, Data* FieldDat) EnableWindow(hwndLabel, !FieldDat->bReadOnly); SendMessage(hwndVar, EM_SETREADONLY, (WPARAM)FieldDat->bReadOnly, 0); } - //remade list - //reallocation + + // remade list + // reallocation JabberSearchData *dat = (JabberSearchData *)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); if (dat) { dat->pJSInf = (JabberSearchFieldsInfo*)realloc(dat->pJSInf, sizeof(JabberSearchFieldsInfo)*(dat->nJSInfCount + 1)); @@ -197,16 +199,21 @@ void CJabberProto::OnIqResultGetSearchFields(const TiXmlElement *iqNode, CJabber ////////////////////////////////////////////////////////////////////////////////////////// // Return results to search dialog -// The pmFields is the pointer to map of Not unical but ordered +// The pmFields is the pointer to map of Not unical but ordered // This can help to made result parser routines more simple static wchar_t *nickfields[] = { L"nick", L"nickname", L"fullname", L"name", L"given", L"first", L"jid", nullptr }; -void CJabberProto::SearchReturnResults(HANDLE id, void * pvUsersInfo, U_TCHAR_MAP * pmAllFields) +static int TCharKeyCmp(const wchar_t *p1, const wchar_t *p2) +{ + return mir_wstrcmpi(p1, p2); +} + +void CJabberProto::SearchReturnResults(HANDLE id, void *pvUsersInfo, UNIQUE_MAP *pmAllFields) { - LIST ListOfNonEmptyFields(20, (LIST::FTSortFunc)TCharKeyCmp); + LIST ListOfNonEmptyFields(20, TCharKeyCmp); LIST ListOfFields(20); - LIST *plUsersInfo = (LIST*)pvUsersInfo; + LIST *plUsersInfo = (LIST*)pvUsersInfo; // lets fill the ListOfNonEmptyFields but in users order for (auto &pmUserData : *plUsersInfo) { @@ -235,7 +242,7 @@ void CJabberProto::SearchReturnResults(HANDLE id, void * pvUsersInfo, U_TCHAR_M Results.pszFields = (wchar_t**)mir_alloc(sizeof(wchar_t*)*nFieldCount); Results.nFieldCount = nFieldCount; - /* Sending Columns Titles */ + // Sending Columns Titles for (int i = 0; i < nFieldCount; i++) { wchar_t *var = ListOfFields[i]; if (var) @@ -245,8 +252,8 @@ void CJabberProto::SearchReturnResults(HANDLE id, void * pvUsersInfo, U_TCHAR_M Results.psr.cbSize = 0; // sending column names ProtoBroadcastAck(0, ACKTYPE_SEARCH, ACKRESULT_SEARCHRESULT, id, (LPARAM)&Results); - /* Sending Users Data */ - Results.psr.cbSize = sizeof(Results.psr); // sending user data + // Sending Users Data + Results.psr.cbSize = sizeof(Results.psr); for (auto &pmUserData : *plUsersInfo) { wchar_t buff[200]; @@ -280,16 +287,6 @@ void CJabberProto::SearchReturnResults(HANDLE id, void * pvUsersInfo, U_TCHAR_M mir_free(Results.pszFields); } -void DestroyKey(wchar_t* key) -{ - mir_free(key); -} - -wchar_t* CopyKey(wchar_t* key) -{ - return mir_wstrdup(key); -} - //////////////////////////////////////////////////////////////////////////////// // Search field request result handler (XEP-0055. Examples 3, 8) @@ -298,7 +295,7 @@ void CJabberProto::OnIqResultAdvancedSearch(const TiXmlElement *iqNode, CJabberI const char *type; int id; - U_TCHAR_MAP mColumnsNames(10); + UNIQUE_MAP mColumnsNames(10); LIST SearchResults(2); if (((id = JabberGetPacketID(iqNode)) == -1) || ((type = XmlGetAttr(iqNode, "type")) == nullptr)) { @@ -320,7 +317,7 @@ void CJabberProto::OnIqResultAdvancedSearch(const TiXmlElement *iqNode, CJabberI } for (auto *itemNode : TiXmlFilter(xNode, "item")) { - U_TCHAR_MAP *pUserColumn = new U_TCHAR_MAP(10); + UNIQUE_MAP *pUserColumn = new UNIQUE_MAP(10); for (auto *fieldNode : TiXmlFilter(itemNode, "field")) { if (const char* var = XmlGetAttr(fieldNode, "var")) { if (auto *textNode = XmlFirstChild(fieldNode, "value")) { @@ -338,13 +335,13 @@ void CJabberProto::OnIqResultAdvancedSearch(const TiXmlElement *iqNode, CJabberI else { // 2. Field list search results info for (auto *itemNode : TiXmlFilter(queryNode, "item")) { - U_TCHAR_MAP *pUserColumn = new U_TCHAR_MAP(10); + UNIQUE_MAP *pUserColumn = new UNIQUE_MAP(10); Utf2T jid(XmlGetAttr(itemNode, "jid")); wchar_t *keyReturned; - mColumnsNames.insertCopyKey(L"jid", L"jid", &keyReturned, CopyKey, DestroyKey); + mColumnsNames.insertCopyKey(L"jid", L"jid", &keyReturned); mColumnsNames.insert(L"jid", keyReturned); - pUserColumn->insertCopyKey(L"jid", jid, nullptr, CopyKey, DestroyKey); + pUserColumn->insertCopyKey(L"jid", jid, nullptr); for (auto *child : TiXmlEnum(itemNode)) { const char *szColumnName = child->Name(); @@ -352,9 +349,9 @@ void CJabberProto::OnIqResultAdvancedSearch(const TiXmlElement *iqNode, CJabberI const char *pszChild = child->GetText(); if (pszChild && *pszChild) { Utf2T wszVar(szColumnName), wszText(pszChild); - mColumnsNames.insertCopyKey(wszVar, L"", &keyReturned, CopyKey, DestroyKey); + mColumnsNames.insertCopyKey(wszVar, L"", &keyReturned); mColumnsNames.insert(wszVar, keyReturned); - pUserColumn->insertCopyKey(wszVar, wszText, nullptr, CopyKey, DestroyKey); + pUserColumn->insertCopyKey(wszVar, wszText, nullptr); } } } @@ -383,10 +380,10 @@ void CJabberProto::OnIqResultAdvancedSearch(const TiXmlElement *iqNode, CJabberI return; } - SearchReturnResults((HANDLE)id, (void*)&SearchResults, (U_TCHAR_MAP *)&mColumnsNames); + SearchReturnResults((HANDLE)id, (void*)&SearchResults, (UNIQUE_MAP *)&mColumnsNames); for (auto &it : SearchResults) - delete ((U_TCHAR_MAP*)it); + delete ((UNIQUE_MAP*)it); //send success to finish searching ProtoBroadcastAck(0, ACKTYPE_SEARCH, ACKRESULT_SUCCESS, (HANDLE)id, 0); diff --git a/protocols/JabberG/src/jabber_search.h b/protocols/JabberG/src/jabber_search.h index 49fc5a2d01..4010cb9bd6 100644 --- a/protocols/JabberG/src/jabber_search.h +++ b/protocols/JabberG/src/jabber_search.h @@ -30,8 +30,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. struct JabberSearchFieldsInfo { - wchar_t * szFieldName; - wchar_t * szFieldCaption; + wchar_t *szFieldName; + wchar_t *szFieldCaption; HWND hwndCaptionItem; HWND hwndValueItem; }; @@ -54,40 +54,29 @@ struct JabberSearchData : public MZeroedObject struct Data { wchar_t *Label; - wchar_t * Var; - wchar_t * defValue; - BOOL bHidden; - BOOL bReadOnly; + wchar_t *Var; + wchar_t *defValue; + BOOL bHidden; + BOOL bReadOnly; int Order; - }; static HWND searchHandleDlg = nullptr; // Implementation of MAP class (the list -template class UNIQUE_MAP { - -public: - typedef _KEYTYPE* (*COPYKEYPROC)(_KEYTYPE*); - typedef void(*DESTROYKEYPROC)(_KEYTYPE*); - -private: typedef struct _tagRECORD { - _tagRECORD(_KEYTYPE * key, wchar_t * value = nullptr) { _key = key; _value = value; _order = 0; _destroyKeyProc = nullptr; } + _tagRECORD(wchar_t *key, wchar_t *value = nullptr) { _key = key; _value = value; _order = 0; } ~_tagRECORD() { - if (_key && _destroyKeyProc) - _destroyKeyProc(_key); + mir_free(_key); _key = nullptr; - _destroyKeyProc = nullptr; } - _KEYTYPE *_key; - wchar_t * _value; + wchar_t *_key; + wchar_t *_value; int _order; - DESTROYKEYPROC _destroyKeyProc; } _RECORD; int _nextOrder; @@ -95,13 +84,10 @@ private: static int _KeysEqual(const _RECORD *p1, const _RECORD *p2) { - if (COMPARATOR) - return (int)(COMPARATOR((p1->_key), (p2->_key))); - else - return (int)(p1->_key < p2->_key); + return mir_wstrcmpi(p1->_key, p2->_key); } - inline int _remove(_RECORD* p) + inline int _remove(_RECORD *p) { int _itemOrder = p->_order; if (_Records.remove(p)) { @@ -114,7 +100,7 @@ private: } return 0; } - inline _RECORD * _getUnorderedRec(int index) + inline _RECORD* _getUnorderedRec(int index) { for (auto &rec : _Records) if (rec->_order == index) @@ -130,14 +116,14 @@ public: }; ~UNIQUE_MAP() { - _RECORD * record; + _RECORD *record; int i = 0; while (record = _Records[i++]) delete record; } - int insert(_KEYTYPE* Key, wchar_t *Value) + int insert(wchar_t *Key, wchar_t *Value) { - _RECORD * rec = new _RECORD(Key, Value); + _RECORD *rec = new _RECORD(Key, Value); int index = _Records.getIndex(rec); if (index < 0) { if (!_Records.insert(rec)) delete rec; @@ -152,37 +138,41 @@ public: } return index; } - int insertCopyKey(_KEYTYPE* Key, wchar_t *Value, _KEYTYPE** _KeyReturn, COPYKEYPROC CopyProc, DESTROYKEYPROC DestroyProc) + + int insertCopyKey(wchar_t *Key, wchar_t *Value, wchar_t **_KeyReturn) { - _RECORD * rec = new _RECORD(Key, Value); + _RECORD *rec = new _RECORD(Key, Value); int index = _Records.getIndex(rec); if (index < 0) { - _KEYTYPE* newKey = CopyProc(Key); + wchar_t *newKey = mir_wstrdup(Key); if (!_Records.insert(rec)) { delete rec; - DestroyProc(newKey); - if (_KeyReturn) *_KeyReturn = nullptr; + mir_free(newKey); + if (_KeyReturn) + *_KeyReturn = nullptr; } else { rec->_key = newKey; - rec->_destroyKeyProc = DestroyProc; index = _Records.getIndex(rec); rec->_order = _nextOrder++; - if (_KeyReturn) *_KeyReturn = newKey; + if (_KeyReturn) + *_KeyReturn = newKey; } } else { _Records[index]->_value = Value; - if (_KeyReturn) *_KeyReturn = _Records[index]->_key; + if (_KeyReturn) + *_KeyReturn = _Records[index]->_key; delete rec; } return index; } - inline wchar_t* operator[](_KEYTYPE* _KEY) const + + inline wchar_t* operator[](wchar_t* _KEY) const { _RECORD rec(_KEY); int index = _Records.getIndex(&rec); - _RECORD * rv = _Records[index]; + _RECORD *rv = _Records[index]; if (rv) { if (rv->_value) return rv->_value; @@ -194,25 +184,25 @@ public: } inline wchar_t* operator[](int index) const { - _RECORD * rv = _Records[index]; + _RECORD *rv = _Records[index]; if (rv) return rv->_value; else return nullptr; } - inline _KEYTYPE* getKeyName(int index) + inline wchar_t* getKeyName(int index) { - _RECORD * rv = _Records[index]; + _RECORD *rv = _Records[index]; if (rv) return rv->_key; else return nullptr; } - inline wchar_t * getUnOrdered(int index) + inline wchar_t* getUnOrdered(int index) { - _RECORD * rec = _getUnorderedRec(index); + _RECORD *rec = _getUnorderedRec(index); if (rec) return rec->_value; else return nullptr; } - inline _KEYTYPE * getUnOrderedKeyName(int index) + inline wchar_t* getUnOrderedKeyName(int index) { - _RECORD * rec = _getUnorderedRec(index); + _RECORD *rec = _getUnorderedRec(index); if (rec) return rec->_key; else return nullptr; } @@ -222,29 +212,19 @@ public: } inline int removeUnOrdered(int index) { - _RECORD * p = _getUnorderedRec(index); + _RECORD *p = _getUnorderedRec(index); if (p) return _remove(p); else return 0; } inline int remove(int index) { - _RECORD * p = _Records[index]; + _RECORD *p = _Records[index]; if (p) return _remove(p); else return 0; } - inline int getIndex(_KEYTYPE * key) + inline int getIndex(wchar_t * key) { _RECORD temp(key); return _Records.getIndex(&temp); } }; - -inline int TCharKeyCmp(wchar_t* a, wchar_t* b) -{ - return (int)(mir_wstrcmpi(a, b)); -} - -inline int CharKeyCmp(char *a, char *b) -{ - return mir_strcmpi(a, b); -} -- cgit v1.2.3