summary refs log tree commit diff stats
path: root/plugins/upd/upd.c
blob: 1659162c9b9bc3855f5388470e7f6981b3e93ede (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
/* XChat-WDK
 * Copyright (c) 2010-2011 Berke Viktor.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

#include <windows.h>
#include <wininet.h>

#include "xchat-plugin.h"

static xchat_plugin *ph;   /* plugin handle */
static const char name[] = "Update Checker";
static const char desc[] = "Check for XChat-WDK updates automatically";
static const char version[] = "2.1";

static char*
check_version ()
{
#if 0
	HINTERNET hINet, hFile;
	hINet = InternetOpen ("Update Checker", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);

	if (!hINet)
	{
		return "Unknown";
	}

	hFile = InternetOpenUrl (hINet,
							"http://xchat-wdk.googlecode.com/git/version.txt?r=wdk",
							NULL,
							0,
							INTERNET_FLAG_NO_CACHE_WRITE | INTERNET_FLAG_RELOAD,
							0);
	if (hFile)
	{
		static char buffer[1024];
		DWORD dwRead;
		while (InternetReadFile (hFile, buffer, 1023, &dwRead))
		{
			if (dwRead == 0)
			{
				break;
			}
			buffer[dwRead] = 0;
		}

		InternetCloseHandle (hFile);
		InternetCloseHandle (hINet);
		return buffer;
	}

	InternetCloseHandle (hINet);
	return "Unknown";
#endif

	/* Google Code's messing up with requests, use HTTP/1.0 as suggested. More info:

	   http://code.google.com/p/support/issues/detail?id=6095

	   Of course it would be still too simple, coz IE will override settings, so
	   you have to disable HTTP/1.1 manually and globally. More info:

	   http://support.microsoft.com/kb/258425

	   So this code's basically useless since disabling HTTP/1.1 will work with the
	   above code too.

	   Update: a Connection: close header seems to disable chunked encoding.
	*/

	HINTERNET hOpen, hConnect, hResource;

	hOpen = InternetOpen (TEXT ("Update Checker"),
						INTERNET_OPEN_TYPE_PRECONFIG,
						NULL,
						NULL,
						0);
	if (!hOpen)
	{
		return "Unknown";
	}

	hConnect = InternetConnect (hOpen,
								TEXT ("xchat-wdk.googlecode.com"),
								INTERNET_INVALID_PORT_NUMBER,
								NULL,
								NULL,
								INTERNET_SERVICE_HTTP,
								0,
								0);
	if (!hConnect)
	{
		InternetCloseHandle (hOpen);
		return "Unknown";
	}

	hResource = HttpOpenRequest (hConnect,
								TEXT ("GET"),
								TEXT ("/git/version.txt?r=wdk"),
								TEXT ("HTTP/1.0"),
								NULL,
								NULL,
								INTERNET_FLAG_NO_CACHE_WRITE | INTERNET_FLAG_RELOAD | INTERNET_FLAG_NO_AUTH,
								0);
	if (!hResource)
	{
		InternetCloseHandle (hConnect);
		InternetCloseHandle (hOpen);
		return "Unknown";
	}
	else
	{
		static char buffer[1024];
		DWORD dwRead;

		HttpAddRequestHeaders (hResource, TEXT ("Connection: close\r\n"), -1L, HTTP_ADDREQ_FLAG_ADD);	/* workaround for GC bug */
		HttpSendRequest (hResource, NULL, 0, NULL, 0);

		while (InternetReadFile (hResource, buffer, 1023, &dwRead))
		{
			if (dwRead == 0)
			{
				break;
			}
			buffer[dwRead] = 0;
		}

		InternetCloseHandle (hResource);
		InternetCloseHandle (hConnect);
		InternetCloseHandle (hOpen);
		return buffer;
	}
}

static int
print_version ()
{
	char *version = check_version ();

	if (strcmp (version, xchat_get_info (ph, "wdk_version")) == 0)
	{
		xchat_printf (ph, "You have the latest version of XChat-WDK installed!\n");
	}
	else if (strcmp (version, "Unknown") == 0)
	{
		xchat_printf (ph, "Unable to check for XChat-WDK updates!\n");
	}
	else
	{
#ifdef _WIN64 /* use this approach, the wProcessorArchitecture method always returns 0 (=x86) for some reason */
		xchat_printf (ph, "An XChat-WDK update is available! You can download it from here:\nhttp://xchat-wdk.googlecode.com/files/XChat-WDK%%20%s%%20x64.exe\n", version);
#else
		xchat_printf (ph, "An XChat-WDK update is available! You can download it from here:\nhttp://xchat-wdk.googlecode.com/files/XChat-WDK%%20%s%%20x86.exe\n", version);
#endif
	}

	return XCHAT_EAT_XCHAT;
}

static int
print_version_quiet (void *userdata)
{
	char *version = check_version ();

	/* if it's not the current version AND not network error */
	if (!(strcmp (version, xchat_get_info (ph, "wdk_version")) == 0) && !(strcmp (version, "Unknown") == 0))
	{
#ifdef _WIN64 /* use this approach, the wProcessorArchitecture method always returns 0 (=x86) for plugins for some reason */
		xchat_printf (ph, "An XChat-WDK update is available! You can download it from here:\nhttp://xchat-wdk.googlecode.com/files/XChat-WDK%%20%s%%20x64.exe\n", version);
#else
		xchat_printf (ph, "An XChat-WDK update is available! You can download it from here:\nhttp://xchat-wdk.googlecode.com/files/XChat-WDK%%20%s%%20x86.exe\n", version);
#endif
		/* print update url once, then stop the timer */
		return 0;
	}
	/* keep checking */
	return 1;
}

int
xchat_plugin_init (xchat_plugin *plugin_handle, char **plugin_name, char **plugin_desc, char **plugin_version, char *arg)
{
	ph = plugin_handle;

	*plugin_name = name;
	*plugin_desc = desc;
	*plugin_version = version;

	xchat_hook_command (ph, "UPDCHK", XCHAT_PRI_NORM, print_version, 0, 0);
	xchat_command (ph, "MENU -ietc\\download.png ADD \"Help/Check for Updates\" \"UPDCHK\"");
	xchat_printf (ph, "%s plugin loaded\n", name);

	/* only start the timer if there's no update available during startup */
	if (print_version_quiet (NULL))
	{
		/* check for updates every 6 hours */
		xchat_hook_timer (ph, 21600000, print_version_quiet, NULL);
	}

	return 1;       /* return 1 for success */
}

int
xchat_plugin_deinit (void)
{
	xchat_command (ph, "MENU DEL \"Help/Check for updates\"");
	xchat_printf (ph, "%s plugin unloaded\n", name);
	return 1;
}
x2="16.88862" y1="77.796608" x1="16.88862" gradientTransform="matrix(0.735969,0,0,0.735801,-2.052758,-16.66733)" gradientUnits="userSpaceOnUse" id="linearGradient1319-2" xlink:href="#linearGradient2289-4" inkscape:collect="always" /> <linearGradient y2="20.59322" x2="72.348671" y1="77.796608" x1="16.88862" gradientTransform="matrix(0.735969,0,0,0.735801,-2.052758,-16.66733)" gradientUnits="userSpaceOnUse" id="linearGradient1317-8" xlink:href="#linearGradient2289-4" inkscape:collect="always" /> <linearGradient y2="19.001091" x2="16.88862" y1="77.796608" x1="16.88862" gradientTransform="matrix(0.545166,0,0,0.544959,0.186963,35.29511)" gradientUnits="userSpaceOnUse" id="linearGradient1337-8" xlink:href="#linearGradient2289-4" inkscape:collect="always" /> <linearGradient y2="20.59322" x2="72.348671" y1="77.796608" x1="16.88862" gradientTransform="matrix(0.545166,0,0,0.544959,0.186963,35.29511)" gradientUnits="userSpaceOnUse" id="linearGradient1335-4" xlink:href="#linearGradient2289-4" inkscape:collect="always" /> <linearGradient id="linearGradient2289-4"> <stop id="stop2291-0" offset="0" style="stop-color:#ff2600;stop-opacity:1;" /> <stop id="stop2293-9" offset="1" style="stop-color:#ffd600;stop-opacity:1;" /> </linearGradient> <linearGradient inkscape:collect="always" xlink:href="#linearGradient2289-4" id="linearGradient3133" gradientUnits="userSpaceOnUse" gradientTransform="matrix(0.51445624,0,0,0.53856587,7.3477348,6.9450134)" x1="46.881573" y1="91.824585" x2="47.225189" y2="1.5596932" /> <linearGradient inkscape:collect="always" xlink:href="#linearGradient2289-4" id="linearGradient3136" gradientUnits="userSpaceOnUse" gradientTransform="matrix(0.51445624,0,0,0.53856587,-120.3871,-29.360443)" x1="16.88862" y1="77.796608" x2="72.348671" y2="20.59322" /> <filter id="filter3138" style="color-interpolation-filters:sRGB;" inkscape:label="Drop Shadow"> <feFlood id="feFlood3140" flood-opacity="0.33" flood-color="rgb(0,0,0)" result="flood" /> <feComposite id="feComposite3142" in2="SourceGraphic" in="flood" operator="in" result="composite1" /> <feGaussianBlur id="feGaussianBlur3144" in="composite" stdDeviation="2" result="blur" /> <feOffset id="feOffset3146" dx="4" dy="1" result="offset" /> <feComposite id="feComposite3148" in2="offset" in="SourceGraphic" operator="over" result="composite2" /> </filter> </defs> <sodipodi:namedview id="base" pagecolor="#ffffff" bordercolor="#666666" borderopacity="1.0" inkscape:pageopacity="0.0" inkscape:pageshadow="2" inkscape:zoom="2.8284271" inkscape:cx="-86.273528" inkscape:cy="9.7239157" inkscape:document-units="px" inkscape:current-layer="layer1" showgrid="false" inkscape:window-width="1270" inkscape:window-height="972" inkscape:window-x="115" inkscape:window-y="32" showguides="true" inkscape:guide-bbox="true" inkscape:window-maximized="0"> <inkscape:grid type="xygrid" id="grid3001" /> </sodipodi:namedview> <metadata id="metadata7"> <rdf:RDF> <cc:Work rdf:about=""> <dc:format>image/svg+xml</dc:format> <dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> <dc:title></dc:title> <dc:creator> <cc:Agent> <dc:title>Guglielmi David</dc:title> </cc:Agent> </dc:creator> <cc:license rdf:resource="http://creativecommons.org/licenses/GPL/2.0/" /> <dc:rights> <cc:Agent> <dc:title>Peter Zelezny</dc:title> </cc:Agent> </dc:rights> </cc:Work> <cc:License rdf:about="http://creativecommons.org/licenses/GPL/2.0/"> <cc:permits rdf:resource="http://web.resource.org/cc/Reproduction" /> <cc:permits rdf:resource="http://web.resource.org/cc/Distribution" /> <cc:requires rdf:resource="http://web.resource.org/cc/Notice" /> <cc:permits rdf:resource="http://web.resource.org/cc/DerivativeWorks" /> <cc:requires rdf:resource="http://web.resource.org/cc/ShareAlike" /> <cc:requires rdf:resource="http://web.resource.org/cc/SourceCode" /> </cc:License> </rdf:RDF> </metadata> <g inkscape:label="Calque 1" inkscape:groupmode="layer" id="layer1"> <path inkscape:connector-curvature="0" id="path4107" d="m 31.404792,8.7464684 c -6.271873,0.05843 -12.553,0.431777 -13.735377,1.075609 C 15.304661,11.109737 4.1505773,29.32852 4.1783444,31.859522 c 0.02777,2.531005 11.5871596,20.543967 13.9796816,21.787309 2.392519,1.243342 25.106,1.037521 27.470753,-0.250141 C 47.993531,52.109028 59.147618,33.890246 59.119851,31.359242 59.092081,28.828238 47.532689,10.790262 45.140167,9.5469214 43.943907,8.9252504 37.676665,8.6880384 31.404792,8.7464684 z m 0.05429,4.5275596 c 4.90437,-0.047 9.786849,0.175368 10.722281,0.67538 1.870861,1.000021 10.917726,15.499216 10.939439,17.534904 C 53.142512,33.52 44.410541,48.158649 42.561393,49.194315 40.712245,50.229983 22.960549,50.419464 21.089689,49.419444 19.218826,48.419423 10.199106,33.920226 10.177392,31.884537 10.155682,29.84885 18.860508,15.185189 20.709656,14.14952 c 0.924575,-0.517833 5.845056,-0.828498 10.749425,-0.875492 z" style="fill:#000000;fill-opacity:1;filter:url(#filter4111)" /> <path inkscape:connector-curvature="0" id="path4103" d="M 31.801142,5.3887159 C 24.358829,5.4607629 16.905535,5.9211193 15.502506,6.7149966 12.696449,8.3027513 -0.53918189,30.767467 -0.50623228,33.888328 -0.47328049,37.00919 13.243292,59.220118 16.0823,60.753225 18.921305,62.286332 45.873514,62.032541 48.67957,60.444787 51.485627,58.857032 64.721258,36.392315 64.688309,33.271454 64.655357,30.150593 50.938784,7.9088218 48.099776,6.3757155 46.680274,5.6091623 39.243454,5.3166688 31.801142,5.3887159 z m 0.06442,5.5827171 c 5.81961,-0.05795 11.613244,0.216241 12.723243,0.83278 2.219996,1.233079 12.955163,19.111349 12.980929,21.621461 0.02577,2.51011 -10.335747,20.560333 -12.529979,21.837366 -2.19423,1.277031 -23.2587,1.510671 -25.478697,0.277592 C 17.341063,54.307554 6.638107,36.429283 6.6123418,33.919173 6.5865755,31.409062 16.915878,13.327995 19.110109,12.050964 20.207224,11.412447 26.045952,11.02938 31.865563,10.971433 z" style="fill:#000000;fill-opacity:1;filter:url(#filter4123)" transform="matrix(0.97890109,0,0,0.98965389,0.52623659,-1.3159842)" /> <path inkscape:connector-curvature="0" sodipodi:nodetypes="ccccccccccccc" id="path2297" d="m 10.723737,18.285684 7.623916,-7.935243 13.238019,13.886676 12.492701,-13.886676 8.576909,7.935243 -14.294847,14.878584 13.341856,11.902864 -6.670928,6.94334 L 31.585672,39.351071 18.573785,52.010472 11.676724,45.086347 24.065591,33.164268 10.723737,18.285684 z" style="fill:url(#linearGradient3133);fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:1.31593215000000010;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;filter:url(#filter3138)" inkscape:transform-center-x="2.25" inkscape:transform-center-y="2.25" /> <path style="fill:url(#linearGradient4101);fill-opacity:1" d="M 31.293607,6.0952825 C 24.436514,6.1604875 17.569304,6.5771256 16.276601,7.2956116 13.691196,8.7325834 1.4963386,29.063913 1.5266972,31.888398 1.5570579,34.712884 14.195039,54.814527 16.810803,56.20204 19.426566,57.589553 44.25941,57.359866 46.844814,55.922894 49.430219,54.485922 61.625078,34.154591 61.594719,31.330106 61.564358,28.505621 48.926376,8.3760634 46.310612,6.9885506 45.002731,6.294794 38.150699,6.0300774 31.293607,6.0952825 z m 0.05936,5.0525485 c 5.36199,-0.05245 10.700046,0.195704 11.722761,0.753694 2.045429,1.115978 11.936445,17.296419 11.960184,19.568154 0.02374,2.271736 -9.523004,18.6078 -11.544693,19.763557 -2.02169,1.155758 -21.429773,1.36721 -23.475201,0.251232 C 17.970585,50.368491 8.1092472,34.188049 8.085508,31.916313 8.061768,29.644577 17.578834,13.2806 19.600523,12.124842 c 1.010846,-0.577879 6.39045,-0.924567 11.75244,-0.977011 z" id="path3305" inkscape:connector-curvature="0" /> <path style="fill:none" d="M 14.640198,55.682743 C 9.6971439,47.360612 2.8950957,35.733851 2.9419881,35.686959 c 0.031272,-0.03127 0.5023581,0.289334 1.0468575,0.712459 0.5444994,0.423125 1.0414462,0.769317 1.1043264,0.769317 0.06288,0 2.6329414,4.276521 5.711247,9.50338 l 5.59692,9.503379 2.159128,0.007 2.159126,0.007 -0.34365,-0.584653 C 20.186937,55.28323 17.303514,50.518786 13.968339,45.017137 10.633164,39.515488 7.9043842,34.929294 7.9043842,34.825595 c 0,-0.103699 0.2455542,-0.59277 0.545676,-1.086823 0.3001218,-0.494053 0.545676,-0.941721 0.545676,-0.994816 0,-0.05309 -0.2788317,-0.09654 -0.619626,-0.09654 -0.8505388,0 -1.0953557,-0.488405 -1.0953557,-2.185211 0,-1.90734 -0.048411,-1.868066 2.30512,-1.870072 l 1.9823345,-0.0017 1.052375,-1.721616 c 0.578806,-0.94689 1.052375,-1.785869 1.052375,-1.8644 0,-0.07853 -0.829918,-0.162484 -1.844262,-0.186561 l -1.8442631,-0.04378 4.4809551,-7.327649 4.480953,-7.32765 12.466741,-0.0399 12.466738,-0.0399 0.517892,0.854518 0.517892,0.854518 2.335995,0.04287 2.335994,0.04287 2.742626,4.521316 c 1.508447,2.486723 4.136212,6.819001 5.839482,9.627283 1.703268,2.808283 3.157599,5.105969 3.231846,5.105969 0.256907,0 0.13186,-0.393635 -0.411085,-1.294044 -0.299901,-0.497351 -0.545275,-0.935841 -0.545275,-0.974422 0,-0.03858 0.310833,-0.07015 0.69074,-0.07015 0.575204,0 0.699074,-0.05324 0.740561,-0.318272 0.03599,-0.229934 0.273254,0.06215 0.854835,1.052375 0.702767,1.196557 0.780303,1.410253 0.610448,1.682462 -0.107012,0.171499 -0.377881,0.627528 -0.601929,1.013399 l -0.407361,0.701583 0.533953,0.857491 c 0.293674,0.47162 0.535536,0.950306 0.537472,1.063747 0.0019,0.113441 -3.098537,5.322698 -6.889942,11.576127 l -6.893462,11.36987 -16.876654,0 -16.876655,0 -1.226996,-2.065773 z" id="path3077" inkscape:connector-curvature="0" /> </g> </svg>