]>
Commit | Line | Data |
---|---|---|
f8a0733d JR |
1 | From f6dccde218fed8dabd3c61efce02d29b320858fe Mon Sep 17 00:00:00 2001 |
2 | From: Marcelo Roberto Jimenez <marcelo.jimenez@gmail.com> | |
3 | Date: Tue, 2 Oct 2018 18:17:43 -0300 | |
4 | Subject: [PATCH] Make aMule compatible with libupnp 1.8 | |
5 | ||
6 | --- | |
7 | src/UPnPBase.cpp | 110 +++++++++++++++++++++++++++-------------------- | |
8 | src/UPnPBase.h | 6 +-- | |
9 | 2 files changed, 66 insertions(+), 50 deletions(-) | |
10 | ||
11 | diff --git a/src/UPnPBase.cpp b/src/UPnPBase.cpp | |
12 | index 01a7c3a05..d4063a136 100644 | |
13 | --- a/src/UPnPBase.cpp | |
14 | +++ b/src/UPnPBase.cpp | |
15 | @@ -1127,7 +1127,7 @@ bool CUPnPControlPoint::PrivateDeletePortMapping( | |
16 | ||
17 | ||
18 | // This function is static | |
19 | -int CUPnPControlPoint::Callback(Upnp_EventType EventType, void *Event, void * /*Cookie*/) | |
20 | +int CUPnPControlPoint::Callback(Upnp_EventType_e EventType, const void *Event, void * /*Cookie*/) | |
21 | { | |
22 | std::ostringstream msg; | |
23 | std::ostringstream msg2; | |
24 | @@ -1149,24 +1149,25 @@ int CUPnPControlPoint::Callback(Upnp_EventType EventType, void *Event, void * /* | |
25 | msg2<< "UPNP_DISCOVERY_SEARCH_RESULT: "; | |
26 | // UPnP Discovery | |
27 | upnpDiscovery: | |
28 | - struct Upnp_Discovery *d_event = (struct Upnp_Discovery *)Event; | |
29 | + UpnpDiscovery *d_event = (UpnpDiscovery *)Event; | |
30 | IXML_Document *doc = NULL; | |
31 | - int ret; | |
32 | - if (d_event->ErrCode != UPNP_E_SUCCESS) { | |
33 | - msg << UpnpGetErrorMessage(d_event->ErrCode) << "."; | |
34 | + int errCode = UpnpDiscovery_get_ErrCode(d_event); | |
35 | + if (errCode != UPNP_E_SUCCESS) { | |
36 | + msg << UpnpGetErrorMessage(errCode) << "."; | |
37 | AddDebugLogLineC(logUPnP, msg); | |
38 | } | |
39 | // Get the XML tree device description in doc | |
40 | - ret = UpnpDownloadXmlDoc(d_event->Location, &doc); | |
41 | + const char *location = UpnpDiscovery_get_Location_cstr(d_event); | |
42 | + int ret = UpnpDownloadXmlDoc(location, &doc); | |
43 | if (ret != UPNP_E_SUCCESS) { | |
44 | msg << "Error retrieving device description from " << | |
45 | - d_event->Location << ": " << | |
46 | + location << ": " << | |
47 | UpnpGetErrorMessage(ret) << | |
48 | "(" << ret << ")."; | |
49 | AddDebugLogLineC(logUPnP, msg); | |
50 | } else { | |
51 | msg2 << "Retrieving device description from " << | |
52 | - d_event->Location << "."; | |
53 | + location << "."; | |
54 | AddDebugLogLineN(logUPnP, msg2); | |
55 | } | |
56 | if (doc) { | |
57 | @@ -1194,8 +1195,9 @@ int CUPnPControlPoint::Callback(Upnp_EventType EventType, void *Event, void * /* | |
58 | AddDebugLogLineC(logUPnP, msg); | |
59 | } | |
60 | // Add the root device to our list | |
61 | + int expires = UpnpDiscovery_get_Expires(d_event); | |
62 | upnpCP->AddRootDevice(rootDevice, urlBase, | |
63 | - d_event->Location, d_event->Expires); | |
64 | + location, expires); | |
65 | } | |
66 | // Free the XML doc tree | |
67 | IXML::Document::Free(doc); | |
68 | @@ -1216,28 +1218,35 @@ int CUPnPControlPoint::Callback(Upnp_EventType EventType, void *Event, void * /* | |
69 | case UPNP_DISCOVERY_ADVERTISEMENT_BYEBYE: { | |
70 | //fprintf(stderr, "Callback: UPNP_DISCOVERY_ADVERTISEMENT_BYEBYE\n"); | |
71 | // UPnP Device Removed | |
72 | - struct Upnp_Discovery *dab_event = (struct Upnp_Discovery *)Event; | |
73 | - if (dab_event->ErrCode != UPNP_E_SUCCESS) { | |
74 | + UpnpDiscovery *dab_event = (UpnpDiscovery *)Event; | |
75 | + int errCode = UpnpDiscovery_get_ErrCode(dab_event); | |
76 | + if (errCode != UPNP_E_SUCCESS) { | |
77 | msg << "error(UPNP_DISCOVERY_ADVERTISEMENT_BYEBYE): " << | |
78 | - UpnpGetErrorMessage(dab_event->ErrCode) << | |
79 | + UpnpGetErrorMessage(errCode) << | |
80 | "."; | |
81 | AddDebugLogLineC(logUPnP, msg); | |
82 | } | |
83 | - std::string devType = dab_event->DeviceType; | |
84 | + std::string devType = UpnpDiscovery_get_DeviceType_cstr(dab_event); | |
85 | // Check for an InternetGatewayDevice and removes it from the list | |
86 | - std::transform(devType.begin(), devType.end(), devType.begin(), tolower); | |
87 | + std::transform(devType.begin(), devType.end(), | |
88 | + devType.begin(), tolower); | |
89 | if (stdStringIsEqualCI(devType, UPnP::Device::IGW)) { | |
90 | - upnpCP->RemoveRootDevice(dab_event->DeviceId); | |
91 | + const char *deviceID = | |
92 | + UpnpDiscovery_get_DeviceID_cstr(dab_event); | |
93 | + upnpCP->RemoveRootDevice(deviceID); | |
94 | } | |
95 | break; | |
96 | } | |
97 | case UPNP_EVENT_RECEIVED: { | |
98 | //fprintf(stderr, "Callback: UPNP_EVENT_RECEIVED\n"); | |
99 | // Event reveived | |
100 | - struct Upnp_Event *e_event = (struct Upnp_Event *)Event; | |
101 | - const std::string Sid = e_event->Sid; | |
102 | + UpnpEvent *e_event = (UpnpEvent *)Event; | |
103 | + int eventKey = UpnpEvent_get_EventKey(e_event); | |
104 | + IXML_Document *changedVariables = | |
105 | + UpnpEvent_get_ChangedVariables(e_event); | |
106 | + const std::string sid = UpnpEvent_get_SID_cstr(e_event); | |
107 | // Parses the event | |
108 | - upnpCP->OnEventReceived(Sid, e_event->EventKey, e_event->ChangedVariables); | |
109 | + upnpCP->OnEventReceived(sid, eventKey, changedVariables); | |
110 | break; | |
111 | } | |
112 | case UPNP_EVENT_SUBSCRIBE_COMPLETE: | |
113 | @@ -1252,24 +1261,23 @@ int CUPnPControlPoint::Callback(Upnp_EventType EventType, void *Event, void * /* | |
114 | //fprintf(stderr, "Callback: UPNP_EVENT_RENEWAL_COMPLETE\n"); | |
115 | msg << "error(UPNP_EVENT_RENEWAL_COMPLETE): "; | |
116 | upnpEventRenewalComplete: | |
117 | - struct Upnp_Event_Subscribe *es_event = | |
118 | - (struct Upnp_Event_Subscribe *)Event; | |
119 | - if (es_event->ErrCode != UPNP_E_SUCCESS) { | |
120 | + UpnpEventSubscribe *es_event = (UpnpEventSubscribe *)Event; | |
121 | + int errCode = UpnpEventSubscribe_get_ErrCode(es_event); | |
122 | + if (errCode != UPNP_E_SUCCESS) { | |
123 | msg << "Error in Event Subscribe Callback"; | |
124 | - UPnP::ProcessErrorMessage( | |
125 | - msg.str(), es_event->ErrCode, NULL, NULL); | |
126 | + UPnP::ProcessErrorMessage(msg.str(), errCode, NULL, NULL); | |
127 | } else { | |
128 | #if 0 | |
129 | + const UpnpString *publisherUrl = | |
130 | + UpnpEventSubscribe_get_PublisherUrl(es_event); | |
131 | + const char *sid = UpnpEvent_get_SID_cstr(es_event); | |
132 | + int timeOut = UpnpEvent_get_TimeOut(es_event); | |
133 | TvCtrlPointHandleSubscribeUpdate( | |
134 | - GET_UPNP_STRING(es_event->PublisherUrl), | |
135 | - es_event->Sid, | |
136 | - es_event->TimeOut ); | |
137 | + publisherUrl, sid, timeOut); | |
138 | #endif | |
139 | } | |
140 | - | |
141 | break; | |
142 | } | |
143 | - | |
144 | case UPNP_EVENT_AUTORENEWAL_FAILED: | |
145 | //fprintf(stderr, "Callback: UPNP_EVENT_AUTORENEWAL_FAILED\n"); | |
146 | msg << "error(UPNP_EVENT_AUTORENEWAL_FAILED): "; | |
147 | @@ -1280,29 +1288,31 @@ int CUPnPControlPoint::Callback(Upnp_EventType EventType, void *Event, void * /* | |
148 | msg << "error(UPNP_EVENT_SUBSCRIPTION_EXPIRED): "; | |
149 | msg2 << "UPNP_EVENT_SUBSCRIPTION_EXPIRED: "; | |
150 | upnpEventSubscriptionExpired: | |
151 | - struct Upnp_Event_Subscribe *es_event = | |
152 | - (struct Upnp_Event_Subscribe *)Event; | |
153 | + UpnpEventSubscribe *es_event = (UpnpEventSubscribe *)Event; | |
154 | Upnp_SID newSID; | |
155 | memset(newSID, 0, sizeof(Upnp_SID)); | |
156 | int TimeOut = 1801; | |
157 | + const char *publisherUrl = | |
158 | + UpnpEventSubscribe_get_PublisherUrl_cstr(es_event); | |
159 | int ret = UpnpSubscribe( | |
160 | upnpCP->m_UPnPClientHandle, | |
161 | - GET_UPNP_STRING(es_event->PublisherUrl), | |
162 | + publisherUrl, | |
163 | &TimeOut, | |
164 | newSID); | |
165 | if (ret != UPNP_E_SUCCESS) { | |
166 | msg << "Error Subscribing to EventURL"; | |
167 | + int errCode = UpnpEventSubscribe_get_ErrCode(es_event); | |
168 | UPnP::ProcessErrorMessage( | |
169 | - msg.str(), es_event->ErrCode, NULL, NULL); | |
170 | + msg.str(), errCode, NULL, NULL); | |
171 | } else { | |
172 | ServiceMap::iterator it = | |
173 | - upnpCP->m_ServiceMap.find(GET_UPNP_STRING(es_event->PublisherUrl)); | |
174 | + upnpCP->m_ServiceMap.find(publisherUrl); | |
175 | if (it != upnpCP->m_ServiceMap.end()) { | |
176 | CUPnPService &service = *(it->second); | |
177 | service.SetTimeout(TimeOut); | |
178 | service.SetSID(newSID); | |
179 | msg2 << "Re-subscribed to EventURL '" << | |
180 | - GET_UPNP_STRING(es_event->PublisherUrl) << | |
181 | + publisherUrl << | |
182 | "' with SID == '" << | |
183 | newSID << "'."; | |
184 | AddDebugLogLineC(logUPnP, msg2); | |
185 | @@ -1321,17 +1331,19 @@ int CUPnPControlPoint::Callback(Upnp_EventType EventType, void *Event, void * /* | |
186 | case UPNP_CONTROL_ACTION_COMPLETE: { | |
187 | //fprintf(stderr, "Callback: UPNP_CONTROL_ACTION_COMPLETE\n"); | |
188 | // This is here if we choose to do this asynchronously | |
189 | - struct Upnp_Action_Complete *a_event = | |
190 | - (struct Upnp_Action_Complete *)Event; | |
191 | - if (a_event->ErrCode != UPNP_E_SUCCESS) { | |
192 | + UpnpActionComplete *a_event = (UpnpActionComplete *)Event; | |
193 | + int errCode = UpnpActionComplete_get_ErrCode(a_event); | |
194 | + IXML_Document *actionResult = | |
195 | + UpnpActionComplete_get_ActionResult(a_event); | |
196 | + if (errCode != UPNP_E_SUCCESS) { | |
197 | UPnP::ProcessErrorMessage( | |
198 | "UpnpSendActionAsync", | |
199 | - a_event->ErrCode, NULL, | |
200 | - a_event->ActionResult); | |
201 | + errCode, NULL, | |
202 | + actionResult); | |
203 | } else { | |
204 | // Check the response document | |
205 | UPnP::ProcessActionResponse( | |
206 | - a_event->ActionResult, | |
207 | + actionResult, | |
208 | "<UpnpSendActionAsync>"); | |
209 | } | |
210 | /* No need for any processing here, just print out results. | |
211 | @@ -1342,21 +1354,25 @@ int CUPnPControlPoint::Callback(Upnp_EventType EventType, void *Event, void * /* | |
212 | case UPNP_CONTROL_GET_VAR_COMPLETE: { | |
213 | //fprintf(stderr, "Callback: UPNP_CONTROL_GET_VAR_COMPLETE\n"); | |
214 | msg << "error(UPNP_CONTROL_GET_VAR_COMPLETE): "; | |
215 | - struct Upnp_State_Var_Complete *sv_event = | |
216 | - (struct Upnp_State_Var_Complete *)Event; | |
217 | - if (sv_event->ErrCode != UPNP_E_SUCCESS) { | |
218 | + UpnpStateVarComplete *sv_event = (UpnpStateVarComplete *)Event; | |
219 | + int errCode = UpnpStateVarComplete_get_ErrCode(sv_event); | |
220 | + if (errCode != UPNP_E_SUCCESS) { | |
221 | msg << "m_UpnpGetServiceVarStatusAsync"; | |
222 | UPnP::ProcessErrorMessage( | |
223 | - msg.str(), sv_event->ErrCode, NULL, NULL); | |
224 | + msg.str(), errCode, NULL, NULL); | |
225 | } else { | |
226 | #if 0 | |
227 | // Warning: The use of UpnpGetServiceVarStatus and | |
228 | // UpnpGetServiceVarStatusAsync is deprecated by the | |
229 | // UPnP forum. | |
230 | + const char *ctrlUrl = | |
231 | + UpnpStateVarComplete_get_CtrlUrl(sv_event); | |
232 | + const char *stateVarName = | |
233 | + UpnpStateVarComplete_get_StateVarName(sv_event); | |
234 | + const DOMString currentVal = | |
235 | + UpnpStateVarComplete_get_CurrentVal(sv_event); | |
236 | TvCtrlPointHandleGetVar( | |
237 | - sv_event->CtrlUrl, | |
238 | - sv_event->StateVarName, | |
239 | - sv_event->CurrentVal ); | |
240 | + ctrlUrl, stateVarName, currentVal); | |
241 | #endif | |
242 | } | |
243 | break; | |
244 | diff --git a/src/UPnPBase.h b/src/UPnPBase.h | |
245 | index 9eafbd143..92753b86a 100644 | |
246 | --- a/src/UPnPBase.h | |
247 | +++ b/src/UPnPBase.h | |
248 | @@ -489,9 +489,9 @@ class CUPnPControlPoint | |
249 | ||
250 | // Callback function | |
251 | static int Callback( | |
252 | - Upnp_EventType EventType, | |
253 | - void* Event, | |
254 | - void* Cookie); | |
255 | + Upnp_EventType_e EventType, | |
256 | + const void *Event, | |
257 | + void *Cookie); | |
258 | ||
259 | private: | |
260 | void OnEventReceived( | |
261 | From 8784480c79680df5c224d6886a8b4cd3dc1d1801 Mon Sep 17 00:00:00 2001 | |
262 | From: Marcelo Roberto Jimenez <marcelo.jimenez@gmail.com> | |
263 | Date: Tue, 25 Aug 2020 18:41:58 -0300 | |
264 | Subject: [PATCH] Fixes libupnp API breakage | |
265 | ||
266 | Fixes github issue #213: Problem compiling with libupnp 1.14.0 | |
267 | ||
268 | UpnpInit() has long been deprecated and has been dropped in 1.14.0. | |
269 | ||
270 | Use UpnpInit2() instead. | |
271 | --- | |
272 | src/UPnPBase.cpp | 10 ++++------ | |
273 | 2 files changed, 7 insertions(+), 6 deletions(-) | |
274 | ||
275 | diff --git a/src/UPnPBase.cpp b/src/UPnPBase.cpp | |
276 | index 46ac7451e..dd244e5b0 100644 | |
277 | --- a/src/UPnPBase.cpp | |
278 | +++ b/src/UPnPBase.cpp | |
279 | @@ -826,15 +826,13 @@ m_WanService(NULL) | |
280 | ||
281 | // Start UPnP | |
282 | int ret; | |
283 | - char *ipAddress = NULL; | |
284 | - unsigned short port = 0; | |
285 | - ret = UpnpInit(ipAddress, udpPort); | |
286 | + ret = UpnpInit2(0, udpPort); | |
287 | if (ret != UPNP_E_SUCCESS) { | |
288 | - msg << "error(UpnpInit): Error code "; | |
289 | + msg << "error(UpnpInit2): Error code "; | |
290 | goto error; | |
291 | } | |
292 | - port = UpnpGetServerPort(); | |
293 | - ipAddress = UpnpGetServerIpAddress(); | |
294 | + unsigned short port = UpnpGetServerPort(); | |
295 | + char *ipAddress = UpnpGetServerIpAddress(); | |
296 | msg << "bound to " << ipAddress << ":" << | |
297 | port << "."; | |
298 | AddDebugLogLineN(logUPnP, msg); | |
299 | From f28e82b95ba5f1d65dbacda393bd0ccc4df03a53 Mon Sep 17 00:00:00 2001 | |
300 | From: Marcelo Roberto Jimenez <marcelo.jimenez@gmail.com> | |
301 | Date: Wed, 26 Aug 2020 12:41:38 -0300 | |
302 | Subject: [PATCH] Fix for compilation error with previous commit | |
303 | MIME-Version: 1.0 | |
304 | Content-Type: text/plain; charset=UTF-8 | |
305 | Content-Transfer-Encoding: 8bit | |
306 | ||
307 | Somehow I did not get this error when compiling. | |
308 | ||
309 | UPnPBase.cpp: In constructor ‘CUPnPControlPoint::CUPnPControlPoint(short unsigned int)’: | |
310 | UPnPBase.cpp:880:1: error: jump to label ‘error’ [-fpermissive] | |
311 | error: | |
312 | ^~~~~ | |
313 | UPnPBase.cpp:832:8: note: from here | |
314 | goto error; | |
315 | ^~~~~ | |
316 | UPnPBase.cpp:835:8: note: crosses initialization of ‘char* ipAddress’ | |
317 | char *ipAddress = UpnpGetServerIpAddress(); | |
318 | ^~~~~~~~~ | |
319 | UPnPBase.cpp:834:17: note: crosses initialization of ‘short unsigned int port’ | |
320 | unsigned short port = UpnpGetServerPort(); | |
321 | ^~~~ | |
322 | --- | |
323 | src/UPnPBase.cpp | 10 ++++++++-- | |
324 | 1 file changed, 8 insertions(+), 2 deletions(-) | |
325 | ||
326 | diff --git a/src/UPnPBase.cpp b/src/UPnPBase.cpp | |
327 | index dd244e5b0..2c2eadcf2 100644 | |
328 | --- a/src/UPnPBase.cpp | |
329 | +++ b/src/UPnPBase.cpp | |
330 | @@ -824,6 +824,12 @@ m_WanService(NULL) | |
331 | // Null string at first | |
332 | std::ostringstream msg; | |
333 | ||
334 | + // Declare those here to avoid | |
335 | + // "jump to label ‘error’ [-fpermissive] crosses initialization | |
336 | + // of ‘char* ipAddress’" | |
337 | + unsigned short port; | |
338 | + char *ipAddress; | |
339 | + | |
340 | // Start UPnP | |
341 | int ret; | |
342 | ret = UpnpInit2(0, udpPort); | |
343 | @@ -831,8 +837,8 @@ m_WanService(NULL) | |
344 | msg << "error(UpnpInit2): Error code "; | |
345 | goto error; | |
346 | } | |
347 | - unsigned short port = UpnpGetServerPort(); | |
348 | - char *ipAddress = UpnpGetServerIpAddress(); | |
349 | + port = UpnpGetServerPort(); | |
350 | + ipAddress = UpnpGetServerIpAddress(); | |
351 | msg << "bound to " << ipAddress << ":" << | |
352 | port << "."; | |
353 | AddDebugLogLineN(logUPnP, msg); |