From 477a6ea70d0bb1b1dfe9cbd9a15b6dad0284ddeb Mon Sep 17 00:00:00 2001 From: George Hazan Date: Wed, 21 Feb 2018 18:40:03 +0300 Subject: all another C++'11 iterators --- protocols/Gadu-Gadu/src/avatar.cpp | 12 ++++----- protocols/Gadu-Gadu/src/gg.cpp | 6 ++--- protocols/Gadu-Gadu/src/links.cpp | 12 ++++----- protocols/Gadu-Gadu/src/oauth.cpp | 55 +++++++++++++------------------------- 4 files changed, 32 insertions(+), 53 deletions(-) (limited to 'protocols/Gadu-Gadu') diff --git a/protocols/Gadu-Gadu/src/avatar.cpp b/protocols/Gadu-Gadu/src/avatar.cpp index 65e71a7456..ab7356ec0a 100644 --- a/protocols/Gadu-Gadu/src/avatar.cpp +++ b/protocols/Gadu-Gadu/src/avatar.cpp @@ -291,14 +291,14 @@ void __cdecl GaduProto::avatarrequestthread(void*) gg_sleep(100, FALSE, "avatarrequestthread", 101, 1); } - for (int i = 0; i < avatar_requests.getCount(); i++) - mir_free(avatar_requests[i]); - - for (int k = 0; k < avatar_transfers.getCount(); k++) - mir_free(avatar_transfers[k]); - + for (auto &it : avatar_requests) + mir_free(it); avatar_requests.destroy(); + + for (auto &it : avatar_transfers) + mir_free(it); avatar_transfers.destroy(); + debugLogA("avatarrequestthread(): end. Avatar Request Thread Ending"); } diff --git a/protocols/Gadu-Gadu/src/gg.cpp b/protocols/Gadu-Gadu/src/gg.cpp index 1d7c253dc5..bb7855c744 100644 --- a/protocols/Gadu-Gadu/src/gg.cpp +++ b/protocols/Gadu-Gadu/src/gg.cpp @@ -222,9 +222,9 @@ static GaduProto* gg_getprotoinstance(MCONTACT hContact) if (szProto == nullptr) return nullptr; - for (int i = 0; i < g_Instances.getCount(); i++) - if (mir_strcmp(szProto, g_Instances[i]->m_szModuleName) == 0) - return g_Instances[i]; + for (auto &it : g_Instances) + if (mir_strcmp(szProto, it->m_szModuleName) == 0) + return it; return nullptr; } diff --git a/protocols/Gadu-Gadu/src/links.cpp b/protocols/Gadu-Gadu/src/links.cpp index 02e4986236..295e9dbcf2 100644 --- a/protocols/Gadu-Gadu/src/links.cpp +++ b/protocols/Gadu-Gadu/src/links.cpp @@ -60,15 +60,13 @@ static INT_PTR gg_parselink(WPARAM, LPARAM lParam) GaduProto *gg = nullptr; int items = 0; - for (int i = 0; i < g_Instances.getCount(); i++) { - gg = g_Instances[i]; - - if (gg->m_iStatus > ID_STATUS_OFFLINE) { + for (auto &it : g_Instances) { + gg = it; + if (it->m_iStatus > ID_STATUS_OFFLINE) { ++items; - Menu_ModifyItem(gg->hInstanceMenuItem, nullptr, Skin_LoadProtoIcon(gg->m_szModuleName, gg->m_iStatus)); + Menu_ModifyItem(it->hInstanceMenuItem, nullptr, Skin_LoadProtoIcon(it->m_szModuleName, it->m_iStatus)); } - else - Menu_ShowItem(gg->hInstanceMenuItem, false); + else Menu_ShowItem(it->hInstanceMenuItem, false); } if (items > 1) { diff --git a/protocols/Gadu-Gadu/src/oauth.cpp b/protocols/Gadu-Gadu/src/oauth.cpp index da0df144b6..cfe7942297 100644 --- a/protocols/Gadu-Gadu/src/oauth.cpp +++ b/protocols/Gadu-Gadu/src/oauth.cpp @@ -82,7 +82,6 @@ char *oauth_uri_escape(const char *str) char *oauth_generate_signature(LIST ¶ms, const char *httpmethod, const char *url) { char *res; - OAUTHPARAMETER *p; int ix = 0; if (httpmethod == nullptr || url == nullptr || !params.getCount()) return mir_strdup(""); @@ -103,10 +102,9 @@ char *oauth_generate_signature(LIST ¶ms, const char *httpmet mir_free(urlnorm); int size = (int)mir_strlen(httpmethod) + (int)mir_strlen(urlenc) + 1 + 2; - for (int i = 0; i < params.getCount(); i++) { - p = params[i]; + for (auto &p : params) { if (!mir_strcmp(p->name, "oauth_signature")) continue; - if (i > 0) size += 3; + if (p != params[0]) size += 3; size += (int)mir_strlen(p->name) + (int)mir_strlen(p->value) + 3; } @@ -117,10 +115,9 @@ char *oauth_generate_signature(LIST ¶ms, const char *httpmet mir_free(urlenc); mir_strcat(res, "&"); - for (int i = 0; i < params.getCount(); i++) { - p = params[i]; + for (auto &p : params) { if (!mir_strcmp(p->name, "oauth_signature")) continue; - if (i > 0) mir_strcat(res, "%26"); + if (p != params[0]) mir_strcat(res, "%26"); mir_strcat(res, p->name); mir_strcat(res, "%3D"); mir_strcat(res, p->value); @@ -136,11 +133,9 @@ char *oauth_getparam(LIST ¶ms, const char *name) if (name == nullptr) return nullptr; - for (int i = 0; i < params.getCount(); i++) { - p = params[i]; + for (auto &p : params) if (!mir_strcmp(p->name, name)) return p->value; - } return nullptr; } @@ -152,14 +147,12 @@ void oauth_setparam(LIST ¶ms, const char *name, const char * if (name == nullptr) return; - for (int i = 0; i < params.getCount(); i++) { - p = params[i]; + for (auto &p : params) if (!mir_strcmp(p->name, name)) { mir_free(p->value); p->value = oauth_uri_escape(value); return; } - } p = (OAUTHPARAMETER*)mir_alloc(sizeof(OAUTHPARAMETER)); p->name = oauth_uri_escape(name); @@ -169,10 +162,7 @@ void oauth_setparam(LIST ¶ms, const char *name, const char * void oauth_freeparams(LIST ¶ms) { - OAUTHPARAMETER *p; - - for (int i = 0; i < params.getCount(); i++) { - p = params[i]; + for (auto &p : params) { mir_free(p->name); mir_free(p->value); } @@ -236,8 +226,6 @@ char *oauth_auth_header(const char *httpmethod, const char *url, OAUTHSIGNMETHOD const char *consumer_key, const char *consumer_secret, const char *token, const char *token_secret) { - char *res, timestamp[22]; - if (httpmethod == nullptr || url == nullptr) return nullptr; @@ -257,6 +245,8 @@ char *oauth_auth_header(const char *httpmethod, const char *url, OAUTHSIGNMETHOD oauth_setparam(oauth_parameters, "oauth_signature_method", "PLAINTEXT"); break; }; + + char timestamp[22]; mir_snprintf(timestamp, "%ld", time(nullptr)); oauth_setparam(oauth_parameters, "oauth_timestamp", timestamp); oauth_setparam(oauth_parameters, "oauth_nonce", ptrA(oauth_generate_nonce())); @@ -268,27 +258,18 @@ char *oauth_auth_header(const char *httpmethod, const char *url, OAUTHSIGNMETHOD return nullptr; } - int size = 7; - for (int i = 0; i < oauth_parameters.getCount(); i++) { - OAUTHPARAMETER *p = oauth_parameters[i]; - if (i > 0) size++; - size += (int)mir_strlen(p->name) + (int)mir_strlen(p->value) + 3; - } - - res = (char *)mir_alloc(size); - mir_strcpy(res, "OAuth "); - - for (int i = 0; i < oauth_parameters.getCount(); i++) { - OAUTHPARAMETER *p = oauth_parameters[i]; - if (i > 0) mir_strcat(res, ","); - mir_strcat(res, p->name); - mir_strcat(res, "=\""); - mir_strcat(res, p->value); - mir_strcat(res, "\""); + CMStringA res("OAuth "); + for (auto &p : oauth_parameters) { + if (res.GetLength() > 6) + res.AppendChar(','); + res.Append(p->name); + res.Append("=\""); + res.Append(p->value); + res.Append("\""); } oauth_freeparams(oauth_parameters); - return res; + return res.Detach(); } int GaduProto::oauth_receivetoken() -- cgit v1.2.3