@@ -47,87 +47,6 @@ using namespace libtorrent;
47
47
broadcast_socket* sock = 0 ;
48
48
int g_port = 0 ;
49
49
50
- char upnp_xml[] =
51
- " <root>"
52
- " <specVersion>"
53
- " <major>1</major>"
54
- " <minor>0</minor>"
55
- " </specVersion>"
56
- " <URLBase>http://127.0.0.1:%d</URLBase>"
57
- " <device>"
58
- " <deviceType>"
59
- " urn:schemas-upnp-org:device:InternetGatewayDevice:1"
60
- " </deviceType>"
61
- " <presentationURL>http://192.168.0.1:80</presentationURL>"
62
- " <friendlyName>D-Link Router</friendlyName>"
63
- " <manufacturer>D-Link</manufacturer>"
64
- " <manufacturerURL>http://www.dlink.com</manufacturerURL>"
65
- " <modelDescription>Internet Access Router</modelDescription>"
66
- " <modelName>D-Link Router</modelName>"
67
- " <UDN>uuid:upnp-InternetGatewayDevice-1_0-12345678900001</UDN>"
68
- " <UPC>123456789001</UPC>"
69
- " <serviceList>"
70
- " <service>"
71
- " <serviceType>urn:schemas-upnp-org:service:Layer3Forwarding:1</serviceType>"
72
- " <serviceId>urn:upnp-org:serviceId:L3Forwarding1</serviceId>"
73
- " <controlURL>/Layer3Forwarding</controlURL>"
74
- " <eventSubURL>/Layer3Forwarding</eventSubURL>"
75
- " <SCPDURL>/Layer3Forwarding.xml</SCPDURL>"
76
- " </service>"
77
- " </serviceList>"
78
- " <deviceList>"
79
- " <device>"
80
- " <deviceType>urn:schemas-upnp-org:device:WANDevice:1</deviceType>"
81
- " <friendlyName>WANDevice</friendlyName>"
82
- " <manufacturer>D-Link</manufacturer>"
83
- " <manufacturerURL>http://www.dlink.com</manufacturerURL>"
84
- " <modelDescription>Internet Access Router</modelDescription>"
85
- " <modelName>D-Link Router</modelName>"
86
- " <modelNumber>1</modelNumber>"
87
- " <modelURL>http://support.dlink.com</modelURL>"
88
- " <serialNumber>12345678900001</serialNumber>"
89
- " <UDN>uuid:upnp-WANDevice-1_0-12345678900001</UDN>"
90
- " <UPC>123456789001</UPC>"
91
- " <serviceList>"
92
- " <service>"
93
- " <serviceType>"
94
- " urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1"
95
- " </serviceType>"
96
- " <serviceId>urn:upnp-org:serviceId:WANCommonInterfaceConfig</serviceId>"
97
- " <controlURL>/WANCommonInterfaceConfig</controlURL>"
98
- " <eventSubURL>/WANCommonInterfaceConfig</eventSubURL>"
99
- " <SCPDURL>/WANCommonInterfaceConfig.xml</SCPDURL>"
100
- " </service>"
101
- " </serviceList>"
102
- " <deviceList>"
103
- " <device>"
104
- " <deviceType>urn:schemas-upnp-org:device:WANConnectionDevice:1</deviceType>"
105
- " <friendlyName>WAN Connection Device</friendlyName>"
106
- " <manufacturer>D-Link</manufacturer>"
107
- " <manufacturerURL>http://www.dlink.com</manufacturerURL>"
108
- " <modelDescription>Internet Access Router</modelDescription>"
109
- " <modelName>D-Link Router</modelName>"
110
- " <modelNumber>1</modelNumber>"
111
- " <modelURL>http://support.dlink.com</modelURL>"
112
- " <serialNumber>12345678900001</serialNumber>"
113
- " <UDN>uuid:upnp-WANConnectionDevice-1_0-12345678900001</UDN>"
114
- " <UPC>123456789001</UPC>"
115
- " <serviceList>"
116
- " <service>"
117
- " <serviceType>urn:schemas-upnp-org:service:WANIPConnection:1</serviceType>"
118
- " <serviceId>urn:upnp-org:serviceId:WANIPConnection</serviceId>"
119
- " <controlURL>/WANIPConnection</controlURL>"
120
- " <eventSubURL>/WANIPConnection</eventSubURL>"
121
- " <SCPDURL>/WANIPConnection.xml</SCPDURL>"
122
- " </service>"
123
- " </serviceList>"
124
- " </device>"
125
- " </deviceList>"
126
- " </device>"
127
- " </deviceList>"
128
- " </device>"
129
- " </root>" ;
130
-
131
50
char soap_add_response[] =
132
51
" <s:Envelope xmlns:s=\" http://schemas.xmlsoap.org/soap/envelope/\" "
133
52
" s:encodingStyle=\" http://schemas.xmlsoap.org/soap/encoding/\" >"
@@ -202,16 +121,22 @@ void callback(int mapping, address const& ip, int port, error_code const& err)
202
121
// TODO: store the callbacks and verify that the ports were successful
203
122
}
204
123
205
- int test_main ( )
124
+ int run_upnp_test ( char const * root_filename, char const * router_model, char const * control_name )
206
125
{
207
126
libtorrent::io_service ios;
208
127
209
128
g_port = start_web_server ();
129
+
130
+ std::vector<char > buf;
131
+ error_code ec;
132
+ load_file (root_filename, buf, ec);
133
+ buf.push_back (0 );
134
+
210
135
FILE* xml_file = fopen (" upnp.xml" , " w+" );
211
- fprintf (xml_file, upnp_xml , g_port);
136
+ fprintf (xml_file, &buf[ 0 ] , g_port);
212
137
fclose (xml_file);
213
138
214
- std::ofstream xml (" WANIPConnection " , std::ios::trunc );
139
+ std::ofstream xml (control_name , std::ios::trunc );
215
140
xml.write (soap_add_response, sizeof (soap_add_response)-1 );
216
141
xml.close ();
217
142
@@ -226,7 +151,6 @@ int test_main()
226
151
upnp_handler->discover_device ();
227
152
228
153
libtorrent::deadline_timer timer (ios);
229
- error_code ec;
230
154
timer.expires_from_now (seconds (10 ), ec);
231
155
timer.async_wait (boost::bind (&libtorrent::io_service::stop, boost::ref (ios)));
232
156
@@ -246,7 +170,7 @@ int test_main()
246
170
xml.close ();
247
171
248
172
std::cerr << " router: " << upnp_handler->router_model () << std::endl;
249
- TEST_CHECK (upnp_handler->router_model () == " D-Link Router " );
173
+ TEST_CHECK (upnp_handler->router_model () == router_model );
250
174
upnp_handler->close ();
251
175
sock->close ();
252
176
@@ -260,8 +184,16 @@ int test_main()
260
184
261
185
stop_web_server ();
262
186
187
+ callbacks.clear ();
188
+
263
189
delete sock;
264
190
return 0 ;
265
191
}
266
192
193
+ int test_main ()
194
+ {
195
+ run_upnp_test (" root1.xml" , " Xtreme N GIGABIT Router" , " wipconn" );
196
+ run_upnp_test (" root2.xml" , " D-Link Router" , " WANIPConnection" );
197
+ return 0 ;
198
+ }
267
199
0 commit comments