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
7 src/UPnPBase.cpp | 110 +++++++++++++++++++++++++++--------------------
9 2 files changed, 66 insertions(+), 50 deletions(-)
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(
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*/)
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: ";
28 - struct Upnp_Discovery *d_event = (struct Upnp_Discovery *)Event;
29 + UpnpDiscovery *d_event = (UpnpDiscovery *)Event;
30 IXML_Document *doc = NULL;
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);
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 << ": " <<
47 UpnpGetErrorMessage(ret) <<
49 AddDebugLogLineC(logUPnP, msg);
51 msg2 << "Retrieving device description from " <<
52 - d_event->Location << ".";
54 AddDebugLogLineN(logUPnP, msg2);
57 @@ -1194,8 +1195,9 @@ int CUPnPControlPoint::Callback(Upnp_EventType EventType, void *Event, void * /*
58 AddDebugLogLineC(logUPnP, msg);
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);
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) <<
81 AddDebugLogLineC(logUPnP, msg);
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);
97 case UPNP_EVENT_RECEIVED: {
98 //fprintf(stderr, "Callback: UPNP_EVENT_RECEIVED\n");
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);
108 - upnpCP->OnEventReceived(Sid, e_event->EventKey, e_event->ChangedVariables);
109 + upnpCP->OnEventReceived(sid, eventKey, changedVariables);
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);
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),
136 - es_event->TimeOut );
137 + publisherUrl, sid, timeOut);
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;
155 memset(newSID, 0, sizeof(Upnp_SID));
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),
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);
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) <<
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);
204 // Check the response document
205 UPnP::ProcessActionResponse(
206 - a_event->ActionResult,
208 "<UpnpSendActionAsync>");
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);
227 // Warning: The use of UpnpGetServiceVarStatus and
228 // UpnpGetServiceVarStatusAsync is deprecated by the
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(
238 - sv_event->StateVarName,
239 - sv_event->CurrentVal );
240 + ctrlUrl, stateVarName, currentVal);
244 diff --git a/src/UPnPBase.h b/src/UPnPBase.h
245 index 9eafbd143..92753b86a 100644
248 @@ -489,9 +489,9 @@ class CUPnPControlPoint
252 - Upnp_EventType EventType,
255 + Upnp_EventType_e EventType,
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
266 Fixes github issue #213: Problem compiling with libupnp 1.14.0
268 UpnpInit() has long been deprecated and has been dropped in 1.14.0.
270 Use UpnpInit2() instead.
272 src/UPnPBase.cpp | 10 ++++------
273 2 files changed, 7 insertions(+), 6 deletions(-)
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)
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 ";
292 - port = UpnpGetServerPort();
293 - ipAddress = UpnpGetServerIpAddress();
294 + unsigned short port = UpnpGetServerPort();
295 + char *ipAddress = UpnpGetServerIpAddress();
296 msg << "bound to " << ipAddress << ":" <<
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
304 Content-Type: text/plain; charset=UTF-8
305 Content-Transfer-Encoding: 8bit
307 Somehow I did not get this error when compiling.
309 UPnPBase.cpp: In constructor ‘CUPnPControlPoint::CUPnPControlPoint(short unsigned int)’:
310 UPnPBase.cpp:880:1: error: jump to label ‘error’ [-fpermissive]
313 UPnPBase.cpp:832:8: note: from here
316 UPnPBase.cpp:835:8: note: crosses initialization of ‘char* ipAddress’
317 char *ipAddress = UpnpGetServerIpAddress();
319 UPnPBase.cpp:834:17: note: crosses initialization of ‘short unsigned int port’
320 unsigned short port = UpnpGetServerPort();
323 src/UPnPBase.cpp | 10 ++++++++--
324 1 file changed, 8 insertions(+), 2 deletions(-)
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;
334 + // Declare those here to avoid
335 + // "jump to label ‘error’ [-fpermissive] crosses initialization
336 + // of ‘char* ipAddress’"
337 + unsigned short port;
342 ret = UpnpInit2(0, udpPort);
343 @@ -831,8 +837,8 @@ m_WanService(NULL)
344 msg << "error(UpnpInit2): Error code ";
347 - unsigned short port = UpnpGetServerPort();
348 - char *ipAddress = UpnpGetServerIpAddress();
349 + port = UpnpGetServerPort();
350 + ipAddress = UpnpGetServerIpAddress();
351 msg << "bound to " << ipAddress << ":" <<
353 AddDebugLogLineN(logUPnP, msg);