mupnp 0.1

Sign up to get free protection for your applications and to get access to all the features.
data/README ADDED
@@ -0,0 +1,13 @@
1
+ = UPnP
2
+
3
+ The gem is based on the work of Thomas Bernard, miniupnp library
4
+ (http://miniupnp.free.fr/). The source code and his license can be
5
+ found in the ext directory.
6
+ The windows version will be made as long as
7
+ i have some volounteer that can provide me the precompiled code for
8
+ windows. The library is in the module called MiniUPnP, in it you can
9
+ find all the library functions.
10
+ The module UPnP is a wrapper that simplify the access to the
11
+ underlaying library.
12
+ The interface was automatically built with swig (http://www.swig.org/),
13
+ the interface file is upnp.i
data/Rakefile ADDED
@@ -0,0 +1,80 @@
1
+ require 'rubygems'
2
+ Gem::manage_gems
3
+ require 'rake/gempackagetask'
4
+ require 'rake/testtask'
5
+ require 'rake/packagetask'
6
+ require 'rake/rdoctask'
7
+
8
+ spec = Gem::Specification.new do |s|
9
+ s.name = "mupnp"
10
+ s.version = "0.1"
11
+ s.author = "Dario Meloni"
12
+ s.email = "mellon85@gmail.com"
13
+ s.homepage = "http://rubyforge.org/projects/mupnp/"
14
+ s.rubyforge_project = "mupnp"
15
+ s.summary = "UPnP Implementation using the Miniupnpc library"
16
+ s.files = FileList['lib/**/*.rb', 'test/**/*.rb', 'Rakefile',
17
+ 'ext/*.[chi]'].to_a
18
+ s.extra_rdoc_files = FileList['README','ext/README','ext/LICENSE','ext/Changelog.txt'].to_a
19
+ s.require_path = ["lib", "ext"]
20
+ s.test_files = Dir.glob('test/**/tc_*.rb')
21
+ s.has_rdoc = true
22
+ s.extensions << "ext/extconf.rb"
23
+ s.require_path = 'lib'
24
+
25
+ if RUBY_PLATFORM =~ /mswin/
26
+ s.files += ["ext/miniupnp.so"]
27
+ s.extensions.clear
28
+ s.platform = Gem::Platform::WIN32
29
+ end
30
+ end
31
+
32
+ Rake::GemPackageTask.new(spec) do |p|
33
+ p.gem_spec = spec
34
+ unless RUBY_PLATFORM =~ /mswin/
35
+ p.need_tar = true
36
+ p.need_zip = true
37
+ end
38
+ end
39
+
40
+ Rake::RDocTask.new do |rd|
41
+ rd.rdoc_dir = "rdoc"
42
+ rd.rdoc_files.include("./lib/**/*.rb")
43
+ rd.rdoc_files.include("README")
44
+ rd.options = %w(-ap)
45
+ end
46
+
47
+ task :distclean => [:clobber_package, :clobber_rdoc]
48
+ task :dist => [:repackage, :gem, :rdoc]
49
+ task :clean => [:distclean, :extclean]
50
+ task :default => [:test, :dist ]
51
+
52
+ desc "Build the extension"
53
+ task :ext => ["ext/Makefile"] do
54
+ cd "ext"
55
+ if (/mswin/ =~ RUBY_PLATFORM) and ENV['make'].nil?
56
+ begin
57
+ sh "nmake"
58
+ rescue Exception => e
59
+ puts "Windows builds is absolutely experimental... all on your back"
60
+ raise e
61
+ end
62
+ else
63
+ sh "make"
64
+ end
65
+ cd ".."
66
+ end
67
+
68
+ desc "Build makefile"
69
+ file "ext/Makefile" do
70
+ cd "ext"
71
+ `ruby extconf.rb`
72
+ cd ".."
73
+ end
74
+
75
+ desc "Clean extension"
76
+ task :extclean do
77
+ cd 'ext'
78
+ rm_f FileList["*.o","*.so","*.bundle","*.dll","Makefile"]
79
+ cd '..'
80
+ end
data/ext/Changelog.txt ADDED
@@ -0,0 +1,188 @@
1
+ $Id: Changelog.txt,v 1.60 2008/02/21 13:05:27 nanard Exp $
2
+ miniUPnP client Changelog.
3
+
4
+ 2008/02/21:
5
+ put some #ifdef DEBUG around DisplayNameValueList()
6
+
7
+ 2008/02/18:
8
+ Improved error reporting in upnpcommands.c
9
+ UPNP_GetStatusInfo() returns LastConnectionError
10
+
11
+ 2008/02/16:
12
+ better error handling in minisoap.c
13
+ improving display of "valid IGD found" in upnpc.c
14
+
15
+ 2008/02/03:
16
+ Fixing UPNP_GetValidIGD()
17
+ improved make install :)
18
+
19
+ 2007/12/22:
20
+ Adding upnperrors.c/h to provide a strupnperror() function
21
+ used to translate UPnP error codes to string.
22
+
23
+ 2007/12/19:
24
+ Fixing getDevicesFromMiniSSDPD()
25
+ improved error reporting of UPnP functions
26
+
27
+ 2007/12/18:
28
+ It is now possible to specify a different location for MiniSSDPd socket.
29
+ working with MiniSSDPd is now more efficient.
30
+ python module improved.
31
+
32
+ 2007/12/16:
33
+ improving error reporting
34
+
35
+ 2007/12/13:
36
+ Try to improve compatibility by using HTTP/1.0 instead of 1.1 and
37
+ XML a bit different for SOAP.
38
+
39
+ 2007/11/25:
40
+ fixed select() call for linux
41
+
42
+ 2007/11/15:
43
+ Added -fPIC to CFLAG for better shared library code.
44
+
45
+ 2007/11/02:
46
+ Fixed a potential socket leak in miniwget2()
47
+
48
+ 2007/10/16:
49
+ added a parameter to upnpDiscover() in order to allow the use of another
50
+ interface than the default multicast interface.
51
+
52
+ 2007/10/12:
53
+ Fixed the creation of symbolic link in Makefile
54
+
55
+ 2007/10/08:
56
+ Added man page
57
+
58
+ 2007/10/02:
59
+ fixed memory bug in GetUPNPUrls()
60
+
61
+ 2007/10/01:
62
+ fixes in the Makefile
63
+ Added UPNP_GetIGDFromUrl() and adapted the sample program accordingly.
64
+ Added SONAME in the shared library to please debian :)
65
+ fixed MS Windows compilation (minissdpd is not available under MS Windows).
66
+
67
+ 2007/09/25:
68
+ small change to Makefile to be able to install in a different location
69
+ (default is /usr)
70
+
71
+ 2007/09/24:
72
+ now compiling both shared and static library
73
+
74
+ 2007/09/19:
75
+ Cosmetic changes on upnpc.c
76
+
77
+ 2007/09/02:
78
+ adapting to new miniSSDPd (release version ?)
79
+
80
+ 2007/08/31:
81
+ Usage of miniSSDPd to skip discovery process.
82
+
83
+ 2007/08/27:
84
+ fixed python module to allow compilation with Python older than Python 2.4
85
+
86
+ 2007/06/12:
87
+ Added a python module.
88
+
89
+ 2007/05/19:
90
+ Fixed compilation under MinGW
91
+
92
+ 2007/05/15:
93
+ fixed a memory leak in AddPortMapping()
94
+ Added testupnpreplyparse executable to check the parsing of
95
+ upnp soap messages
96
+ minixml now ignore namespace prefixes.
97
+
98
+ 2007/04/26:
99
+ upnpc now displays external ip address with -s or -l
100
+
101
+ 2007/04/11:
102
+ changed MINIUPNPC_URL_MAXSIZE to 128 to accomodate the "BT Voyager 210"
103
+
104
+ 2007/03/19:
105
+ cleanup in miniwget.c
106
+
107
+ 2007/03/01:
108
+ Small typo fix...
109
+
110
+ 2007/01/30:
111
+ Now parsing the HTTP header from SOAP responses in order to
112
+ get content-length value.
113
+
114
+ 2007/01/29:
115
+ Fixed the Soap Query to speedup the HTTP request.
116
+ added some Win32 DLL stuff...
117
+
118
+ 2007/01/27:
119
+ Fixed some WIN32 compatibility issues
120
+
121
+ 2006/12/14:
122
+ Added UPNPIGD_IsConnected() function in miniupnp.c/.h
123
+ Added UPNP_GetValidIGD() in miniupnp.c/.h
124
+ cleaned upnpc.c main(). now using UPNP_GetValidIGD()
125
+
126
+ 2006/12/07:
127
+ Version 1.0-RC1 released
128
+
129
+ 2006/12/03:
130
+ Minor changes to compile under SunOS/Solaris
131
+
132
+ 2006/11/30:
133
+ made a minixml parser validator program
134
+ updated minixml to handle attributes correctly
135
+
136
+ 2006/11/22:
137
+ Added a -r option to the upnpc sample thanks to Alexander Hubmann.
138
+
139
+ 2006/11/19:
140
+ Cleanup code to make it more ANSI C compliant
141
+
142
+ 2006/11/10:
143
+ detect and display local lan address.
144
+
145
+ 2006/11/04:
146
+ Packets and Bytes Sent/Received are now unsigned int.
147
+
148
+ 2006/11/01:
149
+ Bug fix thanks to Giuseppe D'Angelo
150
+
151
+ 2006/10/31:
152
+ C++ compatibility for .h files.
153
+ Added a way to get ip Address on the LAN used to reach the IGD.
154
+
155
+ 2006/10/25:
156
+ Added M-SEARCH to the services in the discovery process.
157
+
158
+ 2006/10/22:
159
+ updated the Makefile to use makedepend, added a "make install"
160
+ update Makefile
161
+
162
+ 2006/10/20:
163
+ fixing the description url parsing thanks to patch sent by
164
+ Wayne Dawe.
165
+ Fixed/translated some comments.
166
+ Implemented a better discover process, first looking
167
+ for IGD then for root devices (as some devices only reply to
168
+ M-SEARCH for root devices).
169
+
170
+ 2006/09/02:
171
+ added freeUPNPDevlist() function.
172
+
173
+ 2006/08/04:
174
+ More command line arguments checking
175
+
176
+ 2006/08/01:
177
+ Added the .bat file to compile under Win32 with minGW32
178
+
179
+ 2006/07/31:
180
+ Fixed the rootdesc parser (igd_desc_parse.c)
181
+
182
+ 2006/07/20:
183
+ parseMSEARCHReply() is now returning the ST: line as well
184
+ starting changes to detect several UPnP devices on the network
185
+
186
+ 2006/07/19:
187
+ using GetCommonLinkProperties to get down/upload bitrate
188
+
data/ext/LICENSE ADDED
@@ -0,0 +1,27 @@
1
+
2
+ Copyright (c) 2005-2007, Thomas BERNARD
3
+ All rights reserved.
4
+
5
+ Redistribution and use in source and binary forms, with or without
6
+ modification, are permitted provided that the following conditions are met:
7
+
8
+ * Redistributions of source code must retain the above copyright notice,
9
+ this list of conditions and the following disclaimer.
10
+ * Redistributions in binary form must reproduce the above copyright notice,
11
+ this list of conditions and the following disclaimer in the documentation
12
+ and/or other materials provided with the distribution.
13
+ * The name of the author may not be used to endorse or promote products
14
+ derived from this software without specific prior written permission.
15
+
16
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26
+ POSSIBILITY OF SUCH DAMAGE.
27
+
data/ext/README ADDED
@@ -0,0 +1,53 @@
1
+
2
+ Project: miniupnp
3
+ Project web page: http://miniupnp.free.fr/
4
+ Author: Thomas Bernard
5
+ Copyright (c) 2005-2007 Thomas Bernard
6
+ This software is subject to the conditions detailed in the
7
+ LICENCE file provided within this distribution.
8
+
9
+ For the comfort of Win32 users, bsdqueue.h is included in the distribution.
10
+ Its licence is included in the header of the file.
11
+ bsdqueue.h is a copy of the sys/queue.h of an OpenBSD system.
12
+
13
+ * miniupnp Client *
14
+
15
+ To compile, simply run 'gmake' (could be 'make').
16
+ Under win32, to compile with MinGW, type "mingw32make.bat".
17
+ The compilation is known to work under linux, FreeBSD,
18
+ OpenBSD, MacOS X and cygwin.
19
+ To install the library and headers on the system use :
20
+ > su
21
+ > make install
22
+ > exit
23
+
24
+ alternatively, to install in a specific location, use :
25
+ > INSTALLPREFIX=/usr/local make install
26
+
27
+ upnpc.c is a sample client using the libminiupnpc.
28
+ To use the libminiupnpc in your application, link it with
29
+ libminiupnpc.a and use the following functions found in miniupnpc.h,
30
+ upnpcommands.h and miniwget.h :
31
+ - upnpDiscover()
32
+ - miniwget()
33
+ - parserootdesc()
34
+ - GetUPNPUrls()
35
+ - UPNP_* (calling UPNP methods)
36
+
37
+ Note : use #include <miniupnpc/miniupnpc.h> etc... for the includes
38
+ and -lminiupnpc for the link
39
+
40
+ * Python module *
41
+
42
+ you can build a python module with 'make pythonmodule'
43
+ and install it with 'make installpythonmodule'.
44
+ setup.py (and setpmingw32.py) are included in the distribution.
45
+
46
+
47
+ Feel free to contact me if you have any problem :
48
+ e-mail : miniupnp@free.fr
49
+
50
+ If you are using libminiupnpc in your application, please
51
+ send me an email !
52
+
53
+
data/ext/declspec.h ADDED
@@ -0,0 +1,15 @@
1
+ #ifndef __DECLSPEC_H__
2
+ #define __DECLSPEC_H__
3
+
4
+ #if defined(WIN32) && !defined(STATICLIB)
5
+ #ifdef MINIUPNP_EXPORTS
6
+ #define LIBSPEC __declspec(dllexport)
7
+ #else
8
+ #define LIBSPEC __declspec(dllimport)
9
+ #endif
10
+ #else
11
+ #define LIBSPEC
12
+ #endif
13
+
14
+ #endif
15
+
data/ext/extconf.rb ADDED
@@ -0,0 +1,5 @@
1
+ require 'mkmf'
2
+
3
+ $CFLAGS = '-DNDEBUG'
4
+ create_makefile("MiniUPnP")
5
+
@@ -0,0 +1,115 @@
1
+ /* $Id: igd_desc_parse.c,v 1.7 2006/11/19 22:32:33 nanard Exp $ */
2
+ /* Project : miniupnp
3
+ * http://miniupnp.free.fr/
4
+ * Author : Thomas Bernard
5
+ * Copyright (c) 2005 Thomas Bernard
6
+ * This software is subject to the conditions detailed in the
7
+ * LICENCE file provided in this distribution.
8
+ * */
9
+ #include "igd_desc_parse.h"
10
+ #include <stdio.h>
11
+ #include <string.h>
12
+
13
+ /* Start element handler :
14
+ * update nesting level counter and copy element name */
15
+ void IGDstartelt(void * d, const char * name, int l)
16
+ {
17
+ struct IGDdatas * datas = (struct IGDdatas *)d;
18
+ memcpy( datas->cureltname, name, l);
19
+ datas->cureltname[l] = '\0';
20
+ datas->level++;
21
+ }
22
+
23
+ /* End element handler :
24
+ * update nesting level counter and update parser state if
25
+ * service element is parsed */
26
+ void IGDendelt(void * d, const char * name, int l)
27
+ {
28
+ struct IGDdatas * datas = (struct IGDdatas *)d;
29
+ datas->level--;
30
+ /*printf("endelt %2d %.*s\n", datas->level, l, name);*/
31
+ if( (l==7) && !memcmp(name, "service", l) )
32
+ {
33
+ /*datas->state++; */
34
+ /*
35
+ if( datas->state < 1
36
+ && !strcmp(datas->servicetype,
37
+ // "urn:schemas-upnp-org:service:WANIPConnection:1") )
38
+ "urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1"))
39
+ datas->state ++;
40
+ */
41
+ if(0==strcmp(datas->servicetype_CIF,
42
+ "urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1"))
43
+ datas->state = 2;
44
+ if(0==strcmp(datas->servicetype,
45
+ "urn:schemas-upnp-org:service:WANIPConnection:1") )
46
+ datas->state = 3;
47
+ /* if(0==strcmp(datas->servicetype,
48
+ "urn:schemas-upnp-org:service:WANPPPConnection:1") )
49
+ datas->state = 4; */
50
+ }
51
+ }
52
+
53
+ /* Data handler :
54
+ * copy data depending on the current element name and state */
55
+ void IGDdata(void * d, const char * data, int l)
56
+ {
57
+ struct IGDdatas * datas = (struct IGDdatas *)d;
58
+ char * dstmember = 0;
59
+ /*printf("%2d %s : %.*s\n",
60
+ datas->level, datas->cureltname, l, data); */
61
+ if( !strcmp(datas->cureltname, "URLBase") )
62
+ dstmember = datas->urlbase;
63
+ else if(datas->state<=1)
64
+ {
65
+ if( !strcmp(datas->cureltname, "serviceType") )
66
+ dstmember = datas->servicetype_CIF;
67
+ else if( !strcmp(datas->cureltname, "controlURL") )
68
+ dstmember = datas->controlurl_CIF;
69
+ else if( !strcmp(datas->cureltname, "eventSubURL") )
70
+ dstmember = datas->eventsuburl_CIF;
71
+ else if( !strcmp(datas->cureltname, "SCPDURL") )
72
+ dstmember = datas->scpdurl_CIF;
73
+ else if( !strcmp(datas->cureltname, "deviceType") )
74
+ dstmember = datas->devicetype_CIF;
75
+ }
76
+ else if(datas->state==2)
77
+ {
78
+ if( !strcmp(datas->cureltname, "serviceType") )
79
+ dstmember = datas->servicetype;
80
+ else if( !strcmp(datas->cureltname, "controlURL") )
81
+ dstmember = datas->controlurl;
82
+ else if( !strcmp(datas->cureltname, "eventSubURL") )
83
+ dstmember = datas->eventsuburl;
84
+ else if( !strcmp(datas->cureltname, "SCPDURL") )
85
+ dstmember = datas->scpdurl;
86
+ else if( !strcmp(datas->cureltname, "deviceType") )
87
+ dstmember = datas->devicetype;
88
+ }
89
+ if(dstmember)
90
+ {
91
+ if(l>=MINIUPNPC_URL_MAXSIZE)
92
+ l = MINIUPNPC_URL_MAXSIZE-1;
93
+ memcpy(dstmember, data, l);
94
+ dstmember[l] = '\0';
95
+ }
96
+ }
97
+
98
+ void printIGD(struct IGDdatas * d)
99
+ {
100
+ printf("urlbase = %s\n", d->urlbase);
101
+ printf("WAN Device (Common interface config) :\n");
102
+ printf(" deviceType = %s\n", d->devicetype_CIF);
103
+ printf(" serviceType = %s\n", d->servicetype_CIF);
104
+ printf(" controlURL = %s\n", d->controlurl_CIF);
105
+ printf(" eventSubURL = %s\n", d->eventsuburl_CIF);
106
+ printf(" SCPDURL = %s\n", d->scpdurl_CIF);
107
+ printf("WAN Connection Device :\n");
108
+ printf(" deviceType = %s\n", d->devicetype);
109
+ printf(" servicetype = %s\n", d->servicetype);
110
+ printf(" controlURL = %s\n", d->controlurl);
111
+ printf(" eventSubURL = %s\n", d->eventsuburl);
112
+ printf(" SCPDURL = %s\n", d->scpdurl);
113
+ }
114
+
115
+