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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
|
#include "main.h"
#include "./pcasturihandler.h"
#include "./Feeds.h"
#include "./FeedUtil.h"
#include "../nu/AutoLock.h"
#include "./wire.h"
#include "./errors.h"
//#include "../Agave/URIHandler/svc_urihandler.h"
//#include <api/service/waservicefactory.h>
#include "api__ml_wire.h"
#include "./cloud.h"
#include "./SubscriptionView.h"
#include "./resource.h"
#include "navigation.h"
#include "..\..\General\gen_ml/ml_ipc_0313.h"
#include <strsafe.h>
using namespace Nullsoft::Utility;
extern ChannelList channels;
extern Cloud cloud;
static uint8_t quickhex(wchar_t c)
{
int hexvalue = c;
if (hexvalue & 0x10)
hexvalue &= ~0x30;
else
{
hexvalue &= 0xF;
hexvalue += 9;
}
return hexvalue;
}
static uint8_t DecodeEscape(const wchar_t *&str)
{
uint8_t a = quickhex(*++str);
uint8_t b = quickhex(*++str);
str++;
return a * 16 + b;
}
static void DecodeEscapedUTF8(wchar_t *&output, const wchar_t *&input)
{
uint8_t utf8_data[1024] = {0}; // hopefully big enough!!
int num_utf8_words=0;
bool error=false;
while (input && *input == '%' && num_utf8_words < sizeof(utf8_data))
{
if (iswxdigit(input[1]) && iswxdigit(input[2]))
{
utf8_data[num_utf8_words++]=DecodeEscape(input);
}
else if (input[1] == '%')
{
input+=2;
utf8_data[num_utf8_words++]='%';
}
else
{
error = true;
break;
}
}
int len = MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)utf8_data, num_utf8_words, 0, 0);
MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)utf8_data, num_utf8_words, output, len);
output += len;
if (error)
{
*output++ = *input++;
}
}
static void UrlDecode(const wchar_t *input, wchar_t *output, size_t len)
{
const wchar_t *stop = output+len-4; // give ourself a cushion large enough to hold a full UTF-16 sequence
const wchar_t *itr = input;
while (itr && *itr)
{
if (output >= stop)
{
*output=0;
return;
}
switch (*itr)
{
case '%':
DecodeEscapedUTF8(output, itr);
break;
case '&':
*output = 0;
return;
default:
*output++ = *itr++;
break;
}
}
*output = 0;
}
// first parameter has param name either null or = terminated, second is null terminated
static bool ParamCompare(const wchar_t *url_param, const wchar_t *param_name)
{
while (url_param && *url_param && *param_name && *url_param!=L'=')
{
if (*url_param++ != *param_name++)
return false;
}
return true;
}
static bool get_request_parm(const wchar_t *params, const wchar_t *param_name, wchar_t *value, size_t value_len)
{
size_t param_name_len = wcslen(param_name);
const wchar_t *t=params;
while (t && *t && *t != L'?') // find start of parameters
t++;
while (t && *t)
{
t++; // skip ? or &
if (ParamCompare(t, param_name))
{
while (t && *t && *t != L'=' && *t != '&') // find start of value
t++;
switch(*t)
{
case L'=':
UrlDecode(++t, value, value_len);
return true;
case 0:
case L'&': // no value
*value=0;
return true;
default: // shouldn't get here
return false;
}
}
while (t && *t && *t != L'&') // find next parameter
t++;
}
return false;
}
int PCastURIHandler::ProcessFilename(const wchar_t *filename)
{
if (
(wcsnicmp(filename, L"pcast://", 8)) == 0 ||
(wcsnicmp(filename, L"feed://", 7) == 0) ||
(wcsnicmp(filename, L"winamp://Podcast/Subscribe", 26) == 0) ||
(wcsnicmp(filename, L"winamp://Podcast/Search", 23) == 0)
)
{
wchar_t *tempFilename = NULL;
wchar_t url[1024] = {0};
if (wcsnicmp(filename, L"winamp://Podcast/Subscribe", 26) == 0)
{
// extract/decode and use the url= parameter
if (get_request_parm(filename, L"url", url, 1024) && url[0])
{
tempFilename = wcsdup(url);
}
else
{
// did not find a url parameter
return NOT_HANDLED;
}
}
else if (wcsnicmp(filename, L"winamp://Podcast/Search", 23) == 0)
{
// TODO: maybe: if (get_request_parm(filename, L"url", url, 1024) && url[0])
{
HNAVITEM hItem = Navigation_FindService(SERVICE_PODCAST, NULL, NULL);
MLNavItem_Select(plugin.hwndLibraryParent, hItem);
return HANDLED;
}
/*
else
{
// did not find a url parameter
return NOT_HANDLED;
}
*/
}
else
{
// Use the full filename
tempFilename = wcsdup(filename);
}
// subscription confirmation
WCHAR szText[1024] = {0}, szBuffer[1024] = {0};
WASABI_API_LNGSTRINGW_BUF(IDS_PODCAST_SUBSCRIPTION_PROMP, szBuffer, ARRAYSIZE(szBuffer));
StringCchPrintf(szText, ARRAYSIZE(szText), szBuffer, tempFilename);
WASABI_API_LNGSTRINGW_BUF(IDS_PODCAST_SUBSCRIPTION_HEADER, szBuffer, ARRAYSIZE(szBuffer));
if (IDYES == MessageBox(plugin.hwndLibraryParent, szText, szBuffer, MB_YESNO | MB_ICONQUESTION | MB_TOPMOST | MB_SETFOREGROUND) )
{
// add feed to channels, pulse the cloud, refresh the UI pane.
Channel newFeed;
newFeed.SetURL(tempFilename);
if (DownloadFeedInformation(newFeed)==DOWNLOAD_SUCCESS)
{
channels.channelGuard.Lock();
channels.AddChannel(newFeed);
channels.channelGuard.Unlock();
cloud.Pulse();
HWND hView = SubscriptionView_FindWindow();
if (NULL != hView)
{
SubscriptionView_RefreshChannels(hView, TRUE);
}
else
{
HNAVITEM myItem = Navigation_FindService(SERVICE_PODCAST, NULL, NULL);
HNAVITEM podcastItem = MLNavItem_GetChild(plugin.hwndLibraryParent, myItem);
HNAVITEM subscriptionItem = Navigation_FindService(SERVICE_SUBSCRIPTION, podcastItem, NULL);
MLNavItem_Select(plugin.hwndLibraryParent, subscriptionItem);
}
}
free(tempFilename);
return HANDLED;
}
else
free(tempFilename);
}
return NOT_HANDLED;
}
int PCastURIHandler::IsMine(const wchar_t *filename)
{
int i = 0;
if (
(wcsnicmp(filename, L"pcast://", 8)) == 0 ||
(wcsnicmp(filename, L"feed://", 7) == 0) ||
(wcsnicmp(filename, L"winamp://Podcast/Subscribe", 26) == 0) ||
(wcsnicmp(filename, L"winamp://Podcast/Search", 23) == 0)
)
return HANDLED;
else
return NOT_HANDLED;
}
#define CBCLASS PCastURIHandler
START_DISPATCH;
CB(PROCESSFILENAME, ProcessFilename);
CB(ISMINE, IsMine);
END_DISPATCH;
#undef CBCLASS
|