summaryrefslogtreecommitdiff
path: root/plugins/Weather
diff options
context:
space:
mode:
authorRobert Pösel <robyer@seznam.cz>2014-11-07 20:36:31 +0000
committerRobert Pösel <robyer@seznam.cz>2014-11-07 20:36:31 +0000
commit0bf13f208abe2713455ba8e2d9ffb752233fcc24 (patch)
tree1aac80de79699b448f7bc88c5f7b8fb51304ad06 /plugins/Weather
parent3a3ae2263b70483741017e01340d4898248138d2 (diff)
Weather: Add support for specifying own UserAgent in INI (requested in #810)
git-svn-id: http://svn.miranda-ng.org/main/trunk@10923 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/Weather')
-rw-r--r--plugins/Weather/docs/sample_ini.ini11
-rw-r--r--plugins/Weather/src/weather.h5
-rw-r--r--plugins/Weather/src/weather_addstn.cpp4
-rw-r--r--plugins/Weather/src/weather_contacts.cpp2
-rw-r--r--plugins/Weather/src/weather_http.cpp7
-rw-r--r--plugins/Weather/src/weather_info.cpp2
-rw-r--r--plugins/Weather/src/weather_ini.cpp5
-rw-r--r--plugins/Weather/src/weather_update.cpp2
8 files changed, 28 insertions, 10 deletions
diff --git a/plugins/Weather/docs/sample_ini.ini b/plugins/Weather/docs/sample_ini.ini
index dc36eda754..4790a4051f 100644
--- a/plugins/Weather/docs/sample_ini.ini
+++ b/plugins/Weather/docs/sample_ini.ini
@@ -1,4 +1,4 @@
-[Weather 0.3.x Update Data 1.4]
+[Weather 0.3.x Update Data 1.5]
; This file contains the information required for the weather protocol to obtain update.
; For the plugin to function properly, at least one of these file must be present.
@@ -15,6 +15,7 @@
; [Weather 0.3.x Update Data 1.2] (min. req. v0.3.5.0)
; [Weather 0.3.x Update Data 1.3] (min. req. v0.3.8.0)
; [Weather 0.3.x Update Data 1.4] (min. req. v0.3.8.12)
+; [Weather 0.3.x Update Data 1.5] (min. req. v0.4.0.2)
; Minimun version for not crashing Miranda (Set to this version to prevent the ini from
; loading in an old version of weather plugin and crash Miranda)
@@ -25,6 +26,7 @@
; Minimun version for using the new features (Set to this version to prevent invalid data
; for user with old version of weather plugin. However, the other features still works)
+; 1.5 Using "UserAgent="
; 1.4 Using "Cookie="
; 1.3 Using "Update Url2=" & "Update Url3="
; 1.2 Using the operation "Break Data="
@@ -35,6 +37,8 @@
; 1.0 All other features
; Revision history:
+; 1.5 (Updated in v0.4.0.2)
+; New "UserAgent="
; 1.4 (Updated in v0.3.8.12)
; New "Cookie="
; 1.3 (Updated in v0.3.8.0)
@@ -95,7 +99,10 @@ Update URL3=
Update URL4=
; Set cookie(s) when retrieving weather updates.
-Cookie=
+Cookie=
+
+; Set user agent for http requests.
+UserAgent=
; ======================================================================================
diff --git a/plugins/Weather/src/weather.h b/plugins/Weather/src/weather.h
index 9caeddf1f6..ab64d6237c 100644
--- a/plugins/Weather/src/weather.h
+++ b/plugins/Weather/src/weather.h
@@ -323,7 +323,8 @@ typedef struct {
char *UpdateURL2;
char *UpdateURL3;
char *UpdateURL4;
- char *Cookie;
+ char *Cookie;
+ char *UserAgent;
// items
int UpdateDataCount;
WIDATAITEMLIST *UpdateData;
@@ -441,7 +442,7 @@ void wfree(WCHAR **Data);
void DBDataManage(MCONTACT hContact, WORD Mode, WPARAM wParam, LPARAM lParam);
// functions in weather_http.c
-int InternetDownloadFile (char *szUrl, char *cookie, TCHAR** szData);
+int InternetDownloadFile (char *szUrl, char *cookie, char *userAgent, TCHAR** szData);
void NetlibInit();
void NetlibHttpDisconnect(void);
diff --git a/plugins/Weather/src/weather_addstn.cpp b/plugins/Weather/src/weather_addstn.cpp
index 37bea56fd3..f8951396ce 100644
--- a/plugins/Weather/src/weather_addstn.cpp
+++ b/plugins/Weather/src/weather_addstn.cpp
@@ -235,7 +235,7 @@ int IDSearchProc(TCHAR *sID, const int searchId, WIIDSEARCH *sData, TCHAR *svc,
// load the page
mir_snprintf(loc, SIZEOF(loc), sData->SearchURL, sID);
- if (InternetDownloadFile(loc, NULL, &szData) == 0) {
+ if (InternetDownloadFile(loc, NULL, NULL, &szData) == 0) {
TCHAR* szInfo = szData;
// not found
@@ -310,7 +310,7 @@ int NameSearchProc(TCHAR *name, const int searchId, WINAMESEARCH *sData, TCHAR *
char loc[256];
ptrA szSearchName( mir_utf8encodeT(name));
mir_snprintf(loc, SIZEOF(loc), sData->SearchURL, ptrA( mir_urlEncode(szSearchName)));
- if (InternetDownloadFile(loc, NULL, &szData) == 0) {
+ if (InternetDownloadFile(loc, NULL, NULL, &szData) == 0) {
TCHAR* szInfo = szData;
search = _tcsstr(szInfo, sData->NotFoundStr); // determine if data is available
if (search == NULL) { // if data is found
diff --git a/plugins/Weather/src/weather_contacts.cpp b/plugins/Weather/src/weather_contacts.cpp
index 03690c9815..ca24b7c690 100644
--- a/plugins/Weather/src/weather_contacts.cpp
+++ b/plugins/Weather/src/weather_contacts.cpp
@@ -262,7 +262,7 @@ INT_PTR CALLBACK DlgProcChange(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPa
// load the page
mir_snprintf(loc, SIZEOF(loc), sData->IDSearch.SearchURL, str);
str[0] = 0;
- if (InternetDownloadFile(loc, NULL, &szData) == 0) {
+ if (InternetDownloadFile(loc, NULL, sData->UserAgent, &szData) == 0) {
TCHAR *szInfo = szData;
TCHAR* search = _tcsstr(szInfo, sData->IDSearch.NotFoundStr);
diff --git a/plugins/Weather/src/weather_http.cpp b/plugins/Weather/src/weather_http.cpp
index ddb5cd973c..05547fd798 100644
--- a/plugins/Weather/src/weather_http.cpp
+++ b/plugins/Weather/src/weather_http.cpp
@@ -48,11 +48,14 @@ int findHeader(NETLIBHTTPREQUEST *nlhrReply, char *hdr)
// return value = 0 for success, 1 or HTTP error code for failure
// global var used: szData, szInfo = containing the retrieved data
-int InternetDownloadFile (char *szUrl, char *cookie, TCHAR **szData)
+int InternetDownloadFile (char *szUrl, char *cookie, char *userAgent, TCHAR **szData)
{
+ if (userAgent == NULL || userAgent[0] == 0)
+ userAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)";
+
NETLIBHTTPHEADER headers[5];
headers[0].szName = "User-Agent";
- headers[0].szValue = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)";
+ headers[0].szValue = userAgent;
headers[1].szName = "Cache-Control";
headers[1].szValue = "no-cache";
headers[2].szName = "Pragma";
diff --git a/plugins/Weather/src/weather_info.cpp b/plugins/Weather/src/weather_info.cpp
index d50f3d1881..62859b800f 100644
--- a/plugins/Weather/src/weather_info.cpp
+++ b/plugins/Weather/src/weather_info.cpp
@@ -64,6 +64,7 @@ void INIInfo(HWND hwndDlg)
case 4: lvi.pszText = _T("1.2"); break;
case 5: lvi.pszText = _T("1.3"); break;
case 6: lvi.pszText = _T("1.4"); break;
+ case 7: lvi.pszText = _T("1.5"); break;
default: lvi.pszText = _T(""); break;
}
ListView_SetItem(hIniList, &lvi);
@@ -185,6 +186,7 @@ void GetINIInfo(TCHAR *pszSvc)
case 4: _tcscat(str2,_T("1.2")); break;
case 5: _tcscat(str2,_T("1.3")); break;
case 6: _tcscat(str2,_T("1.4")); break;
+ case 7: _tcscat(str2,_T("1.5")); break;
}
_tcscat(str2,_T("\n"));
_tcscat(str2, TranslateT("File Name:"));
diff --git a/plugins/Weather/src/weather_ini.cpp b/plugins/Weather/src/weather_ini.cpp
index 73456a8a73..59c618382b 100644
--- a/plugins/Weather/src/weather_ini.cpp
+++ b/plugins/Weather/src/weather_ini.cpp
@@ -270,6 +270,8 @@ void LoadStationData(TCHAR *pszFile, TCHAR *pszShortFile, WIDATA *Data)
Data->InternalVer = 5;
else if ( !strcmp(Line, "[Weather 0.3.x Update Data 1.4]"))
Data->InternalVer = 6;
+ else if ( !strcmp(Line, "[Weather 0.3.x Update Data 1.5]"))
+ Data->InternalVer = 7;
else
{
TCHAR str[4096];
@@ -294,6 +296,7 @@ void LoadStationData(TCHAR *pszFile, TCHAR *pszShortFile, WIDATA *Data)
Data->UpdateURL3 = "";
Data->UpdateURL4 = "";
Data->Cookie = "";
+ Data->UserAgent = "";
Data->IDSearch.SearchURL = "";
Data->IDSearch.NotFoundStr = _T("");
Data->NameSearch.SearchURL = "";
@@ -399,6 +402,7 @@ void LoadStationData(TCHAR *pszFile, TCHAR *pszShortFile, WIDATA *Data)
else if ( !_stricmp(ValName, "UPDATE URL3")) wSetData(&Data->UpdateURL3, Value);
else if ( !_stricmp(ValName, "UPDATE URL4")) wSetData(&Data->UpdateURL4, Value);
else if ( !_stricmp(ValName, "COOKIE")) wSetData(&Data->Cookie, Value);
+ else if ( !_stricmp(ValName, "USERAGENT")) wSetData(&Data->UserAgent, Value);
}
else if ( !_stricmp(Group, "ID SEARCH")) {
if ( !_stricmp(ValName, "AVAILABLE")) {
@@ -507,6 +511,7 @@ void FreeWIData(WIDATA *Data)
wfree(&Data->UpdateURL3);
wfree(&Data->UpdateURL4);
wfree(&Data->Cookie);
+ wfree(&Data->UserAgent);
wfree(&Data->IDSearch.SearchURL);
wfree(&Data->IDSearch.NotFoundStr);
FreeDataItem(&Data->IDSearch.Name);
diff --git a/plugins/Weather/src/weather_update.cpp b/plugins/Weather/src/weather_update.cpp
index 584b99f927..b5b0c582ed 100644
--- a/plugins/Weather/src/weather_update.cpp
+++ b/plugins/Weather/src/weather_update.cpp
@@ -429,7 +429,7 @@ int GetWeatherData(MCONTACT hContact)
// download the html file from the internet
TCHAR* szData = NULL;
- int retval = InternetDownloadFile(loc, Data->Cookie, &szData);
+ int retval = InternetDownloadFile(loc, Data->Cookie, Data->UserAgent, &szData);
if (retval != 0) {
mir_free(szData);
return retval;