From 1b466efd4cd31eb6ef46ad208002b27deb7751e4 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Wed, 15 Jan 2025 20:41:14 +0300 Subject: code cleaning --- protocols/Weather/src/stdafx.h | 54 ---------------------- protocols/Weather/src/weather_addstn.cpp | 33 +++++++------- protocols/Weather/src/weather_conv.cpp | 77 +++++++++++++++++++++----------- protocols/Weather/src/weather_http.cpp | 1 - 4 files changed, 66 insertions(+), 99 deletions(-) (limited to 'protocols/Weather/src') diff --git a/protocols/Weather/src/stdafx.h b/protocols/Weather/src/stdafx.h index cefb09ce5f..e3df248c79 100644 --- a/protocols/Weather/src/stdafx.h +++ b/protocols/Weather/src/stdafx.h @@ -115,60 +115,6 @@ enum EWeatherCondition #define DOC_TOO_SHORT 43 #define UNKNOWN_ERROR 99 -// weather update error text -#define E10 TranslateT("Invalid ID format, missing \"/\" (10)") -#define E11 TranslateT("Invalid service (11)") -#define E12 TranslateT("Invalid station (12)") -#define E20 TranslateT("Weather service ini for this station is not found (20)") -#define E30 TranslateT("Netlib error - check your internet connection (30)") -#define E40 TranslateT("Empty data is retrieved (40)") -#define E42 TranslateT("Document not found (42)") -#define E43 TranslateT("Document too short to contain any weather data (43)") -#define E99 TranslateT("Unknown error (99)") - -// HTTP error... not all translated -// 100 Continue -// 101 Switching Protocols -// 200 OK -// 201 Created -// 202 Accepted -// 203 Non-Authoritative Information -#define E204 TranslateT("HTTP Error: No content (204)") -// 205 Reset Content -// 206 Partial Content -// 300 Multiple Choices -#define E301 TranslateT("HTTP Error: Data moved (301)") -// 302 Found -// 303 See Other -// 304 Not Modified -#define E305 TranslateT("HTTP Error: Use proxy (305)") -// 306 (Unused) -#define E307 TranslateT("HTTP Error: Temporary redirect (307)") -#define E400 TranslateT("HTTP Error: Bad request (400)") -#define E401 TranslateT("HTTP Error: Unauthorized (401)") -#define E402 TranslateT("HTTP Error: Payment required (402)") -#define E403 TranslateT("HTTP Error: Forbidden (403)") -#define E404 TranslateT("HTTP Error: Not found (404)") -#define E405 TranslateT("HTTP Error: Method not allowed (405)") -// 406 Not Acceptable -#define E407 TranslateT("HTTP Error: Proxy authentication required (407)") -// 408 Request Timeout -// 409 Conflict -#define E410 TranslateT("HTTP Error: Gone (410)") -// 411 Length Required -// 412 Precondition Failed -// 413 Request Entity Too Large -// 414 Request-URI Too Long -// 415 Unsupported Media Type -// 416 Requested Range Not Satisfiable -// 417 Expectation Failed -#define E500 TranslateT("HTTP Error: Internal server error (500)") -// 501 Not Implemented -#define E502 TranslateT("HTTP Error: Bad gateway (502)") -#define E503 TranslateT("HTTP Error: Service unavailable (503)") -#define E504 TranslateT("HTTP Error: Gateway timeout (504)") -// 505 HTTP Version Not Supported - // defaults constants #define VAR_LIST_OPT TranslateT("%c\tcurrent condition\n%d\tcurrent date\n%e\tdewpoint\n%f\tfeel-like temp\n%h\ttoday's high\n%i\twind direction\n%l\ttoday's low\n%m\thumidity\n%n\tstation name\n%p\tpressure\n%r\tsunrise time\n%s\tstation ID\n%t\ttemperature\n%u\tupdate time\n%v\tvisibility\n%w\twind speed\n%y\tsun set\n----------\n\\n\tnew line") diff --git a/protocols/Weather/src/weather_addstn.cpp b/protocols/Weather/src/weather_addstn.cpp index 79504143ae..eb2a85b9fb 100644 --- a/protocols/Weather/src/weather_addstn.cpp +++ b/protocols/Weather/src/weather_addstn.cpp @@ -39,30 +39,29 @@ INT_PTR WeatherAddToList(WPARAM, LPARAM lParam) return 0; // search for existing contact - for (auto &hContact : Contacts()) { - // check if it is a weather contact - if (IsMyContact(hContact)) { - DBVARIANT dbv; - // check ID to see if the contact already exist in the database - if (!g_plugin.getWString(hContact, "ID", &dbv)) { - if (!mir_wstrcmpi(psr->email.w, dbv.pwszVal)) { - // remove the flag for not on list and hidden, thus make the contact visible - // and add them on the list - if (!Contact::OnList(hContact)) { - Contact::PutOnList(hContact); - Contact::Hide(hContact, false); - } - db_free(&dbv); - // contact is added, function quitting - return (INT_PTR)hContact; + for (auto &hContact : Contacts(MODULENAME)) { + DBVARIANT dbv; + // check ID to see if the contact already exist in the database + if (!g_plugin.getWString(hContact, "ID", &dbv)) { + if (!mir_wstrcmpi(psr->email.w, dbv.pwszVal)) { + // remove the flag for not on list and hidden, thus make the contact visible + // and add them on the list + if (!Contact::OnList(hContact)) { + Contact::PutOnList(hContact); + Contact::Hide(hContact, false); } db_free(&dbv); + // contact is added, function quitting + return (INT_PTR)hContact; } + db_free(&dbv); } } // if contact with the same ID was not found, add it - if (psr->cbSize < sizeof(PROTOSEARCHRESULT)) return 0; + if (psr->cbSize < sizeof(PROTOSEARCHRESULT)) + return 0; + MCONTACT hContact = db_add_contact(); Proto_AddToContact(hContact, MODULENAME); // suppress online notification for the new contact diff --git a/protocols/Weather/src/weather_conv.cpp b/protocols/Weather/src/weather_conv.cpp index 649ca37a91..f2d18dc240 100644 --- a/protocols/Weather/src/weather_conv.cpp +++ b/protocols/Weather/src/weather_conv.cpp @@ -569,40 +569,63 @@ void GetID(wchar_t *pszID) } //============ WEATHER ERROR CODE ============ -// // Get the text when an error code is specified // code = the error code obtained when updating weather // str = the string for the error -// + wchar_t *GetError(int code) { wchar_t *str, str2[100]; switch (code) { - case 10: str = E10; break; - case 11: str = E11; break; - case 12: str = E12; break; - case 20: str = E20; break; - case 30: str = E30; break; - case 40: str = E40; break; - case 42: str = E42; break; - case 43: str = E43; break; - case 99: str = E99; break; - case 204: str = E204; break; - case 301: str = E301; break; - case 305: str = E305; break; - case 307: str = E307; break; - case 400: str = E400; break; - case 401: str = E401; break; - case 402: str = E402; break; - case 403: str = E403; break; - case 404: str = E404; break; - case 405: str = E405; break; - case 407: str = E407; break; - case 410: str = E410; break; - case 500: str = E500; break; - case 502: str = E502; break; - case 503: str = E503; break; - case 504: str = E504; break; + case 10: str = TranslateT("Invalid ID format, missing \"/\" (10)"); break; + case 11: str = TranslateT("Invalid service (11)"); break; + case 12: str = TranslateT("Invalid station (12)"); break; + case 20: str = TranslateT("Weather service ini for this station is not found (20)"); break; + case 30: str = TranslateT("Netlib error - check your internet connection (30)"); break; + case 40: str = TranslateT("Empty data is retrieved (40)"); break; + case 42: str = TranslateT("Document not found (42)"); break; + case 43: str = TranslateT("Document too short to contain any weather data (43)"); break; + case 99: str = TranslateT("Unknown error (99)"); break; + // 100 Continue + // 101 Switching Protocols + // 200 OK + // 201 Created + // 202 Accepted + // 203 Non-Authoritative Information + case 204: str = TranslateT("HTTP Error: No content (204)"); break; + // 205 Reset Content + // 206 Partial Content + // 300 Multiple Choices + case 301: str = TranslateT("HTTP Error: Data moved (301)"); break; + // 302 Found + // 303 See Other + // 304 Not Modified + case 305: str = TranslateT("HTTP Error: Use proxy (305)"); break; + case 307: str = TranslateT("HTTP Error: Temporary redirect (307)"); break; + case 400: str = TranslateT("HTTP Error: Bad request (400)"); break; + case 401: str = TranslateT("HTTP Error: Unauthorized (401)"); break; + case 402: str = TranslateT("HTTP Error: Payment required (402)"); break; + case 403: str = TranslateT("HTTP Error: Forbidden (403)"); break; + case 404: str = TranslateT("HTTP Error: Not found (404)"); break; + case 405: str = TranslateT("HTTP Error: Method not allowed (405)"); break; + // 406 Not Acceptable + case 407: str = TranslateT("HTTP Error: Proxy authentication required (407)"); break; + // 408 Request Timeout + // 409 Conflict + case 410: str = TranslateT("HTTP Error: Gone (410)"); break; + // 411 Length Required + // 412 Precondition Failed + // 413 Request Entity Too Large + // 414 Request-URI Too Long + // 415 Unsupported Media Type + // 416 Requested Range Not Satisfiable + // 417 Expectation Failed + case 500: str = TranslateT("HTTP Error: Internal server error (500)"); break; + // 501 Not Implemented + case 502: str = TranslateT("HTTP Error: Bad gateway (502)"); break; + case 503: str = TranslateT("HTTP Error: Service unavailable (503)"); break; + case 504: str = TranslateT("HTTP Error: Gateway timeout (504)"); break; + // 505 HTTP Version Not Supported default: mir_snwprintf(str2, TranslateT("HTTP Error %i"), code); str = str2; diff --git a/protocols/Weather/src/weather_http.cpp b/protocols/Weather/src/weather_http.cpp index 79c9efd21e..bfbcadc589 100644 --- a/protocols/Weather/src/weather_http.cpp +++ b/protocols/Weather/src/weather_http.cpp @@ -28,7 +28,6 @@ from the web using netlib HNETLIBUSER hNetlibUser; //============ DOWNLOAD NEW WEATHER ============ -// // function to download webpage from the internet // szUrl = URL of the webpage to be retrieved // return value = 0 for success, 1 or HTTP error code for failure -- cgit v1.2.3