mupnp 0.1 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -1,8 +1,13 @@
1
1
  = UPnP
2
+ Author:: Dario Meloni (mailto:mellon85@gmail.com)
3
+ License:: LGPL
2
4
 
3
5
  The gem is based on the work of Thomas Bernard, miniupnp library
4
6
  (http://miniupnp.free.fr/). The source code and his license can be
5
7
  found in the ext directory.
8
+ There is a little modification in the code. In the original code there was a compile time switch to receive answer only on the UPnP ports. It is sometimes suefull with certains firewall to have it enabled, but it may give some problems with Windows XP. So i have changed it in a run time switch to be passed to upnpDiscover function.
9
+ By default it wants to receive answer on the same port (firewall friendly). If no answer are received from some devices, then maybe a test with them off (microsoft friendly, may get blocked by firewalls).
10
+
6
11
  The windows version will be made as long as
7
12
  i have some volounteer that can provide me the precompiled code for
8
13
  windows. The library is in the module called MiniUPnP, in it you can
@@ -10,4 +15,4 @@ find all the library functions.
10
15
  The module UPnP is a wrapper that simplify the access to the
11
16
  underlaying library.
12
17
  The interface was automatically built with swig (http://www.swig.org/),
13
- the interface file is upnp.i
18
+ the interface file is upnp.i
data/Rakefile CHANGED
@@ -7,7 +7,7 @@ require 'rake/rdoctask'
7
7
 
8
8
  spec = Gem::Specification.new do |s|
9
9
  s.name = "mupnp"
10
- s.version = "0.1"
10
+ s.version = "0.1.1"
11
11
  s.author = "Dario Meloni"
12
12
  s.email = "mellon85@gmail.com"
13
13
  s.homepage = "http://rubyforge.org/projects/mupnp/"
data/ext/miniupnpc.c CHANGED
@@ -32,12 +32,6 @@
32
32
  #include "minixml.h"
33
33
  #include "upnpcommands.h"
34
34
 
35
- /* Uncomment the following to transmit the msearch from the same port
36
- * as the UPnP multicast port. With WinXP this seems to result in the
37
- * responses to the msearch being lost, thus if things dont work then
38
- * comment this out. */
39
- /* #define TX_FROM_UPNP_PORT */
40
-
41
35
  #ifdef WIN32
42
36
  #define PRINT_SOCKET_ERROR(x) printf("Socket error: %s, %d\n", x, WSAGetLastError());
43
37
  #else
@@ -344,7 +338,7 @@ parseMSEARCHReply(const char * reply, int size,
344
338
  * It is up to the caller to free the chained list
345
339
  * delay is in millisecond (poll) */
346
340
  struct UPNPDev * upnpDiscover(int delay, const char * multicastif,
347
- const char * minissdpdsock)
341
+ const char * minissdpdsock, int sameport)
348
342
  {
349
343
  struct UPNPDev * tmp;
350
344
  struct UPNPDev * devlist = 0;
@@ -397,9 +391,8 @@ struct UPNPDev * upnpDiscover(int delay, const char * multicastif,
397
391
  /* reception */
398
392
  memset(&sockudp_r, 0, sizeof(struct sockaddr_in));
399
393
  sockudp_r.sin_family = AF_INET;
400
- #ifdef TX_FROM_UPNP_PORT
401
- sockudp_r.sin_port = htons(PORT);
402
- #endif
394
+ if (sameport)
395
+ sockudp_r.sin_port = htons(PORT);
403
396
  sockudp_r.sin_addr.s_addr = INADDR_ANY;
404
397
  /* emission */
405
398
  memset(&sockudp_w, 0, sizeof(struct sockaddr_in));
data/ext/miniupnpc.h CHANGED
@@ -41,7 +41,7 @@ struct UPNPDev {
41
41
  * If multicastif is not NULL, it will be used instead of the default
42
42
  * multicast interface for sending SSDP discover packets. */
43
43
  LIBSPEC struct UPNPDev * upnpDiscover(int delay, const char * multicastif,
44
- const char * minissdpdsock);
44
+ const char * minissdpdsock, int sameport);
45
45
  /* freeUPNPDevlist()
46
46
  * free list returned by upnpDiscover() */
47
47
  LIBSPEC void freeUPNPDevlist(struct UPNPDev * devlist);
data/ext/upnp_wrap.c CHANGED
@@ -2452,6 +2452,7 @@ _wrap_upnpDiscover(int argc, VALUE *argv, VALUE self) {
2452
2452
  int arg1 ;
2453
2453
  char *arg2 = (char *) 0 ;
2454
2454
  char *arg3 = (char *) 0 ;
2455
+ int arg4 ;
2455
2456
  struct UPNPDev *result = 0 ;
2456
2457
  int val1 ;
2457
2458
  int ecode1 = 0 ;
@@ -2461,10 +2462,12 @@ _wrap_upnpDiscover(int argc, VALUE *argv, VALUE self) {
2461
2462
  int res3 ;
2462
2463
  char *buf3 = 0 ;
2463
2464
  int alloc3 = 0 ;
2465
+ int val4 ;
2466
+ int ecode4 = 0 ;
2464
2467
  VALUE vresult = Qnil;
2465
2468
 
2466
- if ((argc < 3) || (argc > 3)) {
2467
- rb_raise(rb_eArgError, "wrong # of arguments(%d for 3)",argc); SWIG_fail;
2469
+ if ((argc < 4) || (argc > 4)) {
2470
+ rb_raise(rb_eArgError, "wrong # of arguments(%d for 4)",argc); SWIG_fail;
2468
2471
  }
2469
2472
  ecode1 = SWIG_AsVal_int(argv[0], &val1);
2470
2473
  if (!SWIG_IsOK(ecode1)) {
@@ -2481,7 +2484,12 @@ _wrap_upnpDiscover(int argc, VALUE *argv, VALUE self) {
2481
2484
  SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "upnpDiscover" "', argument " "3"" of type '" "char const *""'");
2482
2485
  }
2483
2486
  arg3 = (char *)(buf3);
2484
- result = (struct UPNPDev *)upnpDiscover(arg1,(char const *)arg2,(char const *)arg3);
2487
+ ecode4 = SWIG_AsVal_int(argv[3], &val4);
2488
+ if (!SWIG_IsOK(ecode4)) {
2489
+ SWIG_exception_fail(SWIG_ArgError(ecode4), "in method '" "upnpDiscover" "', argument " "4"" of type '" "int""'");
2490
+ }
2491
+ arg4 = (int)(val4);
2492
+ result = (struct UPNPDev *)upnpDiscover(arg1,(char const *)arg2,(char const *)arg3,arg4);
2485
2493
  vresult = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_UPNPDev, 0 | 0 );
2486
2494
  if (alloc2 == SWIG_NEWOBJ) free((char*)buf2);
2487
2495
  if (alloc3 == SWIG_NEWOBJ) free((char*)buf3);
data/lib/UPnP.rb CHANGED
@@ -1,9 +1,11 @@
1
1
  #! /usr/bin/ruby
2
- # Author: Dario Meloni <mellon85@gmail.com>
3
2
  # This module is a binding to the Thomas Bernard miniupnp library
4
3
  # written in C. It supports the IGD specification and works with IPv4
5
4
  # only. Every exception that comes from inside the library is report as
6
5
  # UPnPException while wrong arguments are returned as ArgumentError.
6
+ #
7
+ # Author:: Dario Meloni (mailto:mellon85@gmail.com)
8
+ # License:: LGPL
7
9
 
8
10
  require 'MiniUPnP'
9
11
  include ObjectSpace
@@ -80,7 +82,11 @@ module UPnP
80
82
  # on the background to scan the network. All the other
81
83
  # functions are safe to be called in the meanwhile, they will
82
84
  # just wait for the scan to end before operating.
83
- def initialize(autodiscover=true,max_wait=1000)
85
+ # The variable sameport if set to true will receive UPnP answers from
86
+ # the incoming port. It can be usefull with some routers. Try with
87
+ # false, and if it fails try again with true if the firewall allows
88
+ # only UPnP ports.
89
+ def initialize(autodiscover=true,sameport=true,max_wait=1000)
84
90
  if max_wait <= 0 then
85
91
  raise ArgumentError, "Max wait time must be >= 1."
86
92
  end
@@ -92,6 +98,9 @@ module UPnP
92
98
  # start the discover process at the object initialization.
93
99
  # until ruby2, this thread will block the ruby environment
94
100
  # for the wait time.
101
+
102
+ @sameport = sameport
103
+
95
104
  if autodiscover then
96
105
  @igd_thread = Thread.new { discoverIGD }
97
106
  else
@@ -114,7 +123,9 @@ module UPnP
114
123
  if max_wait_time <= 0 then
115
124
  raise ArgumentError, "Max wait time must be >= 1"
116
125
  end
117
- @list = MiniUPnP.upnpDiscover(max_wait_time,nil,nil)
126
+ sameport = 0
127
+ sameport = 1 if @sameport != false
128
+ @list = MiniUPnP.upnpDiscover(max_wait_time,nil,nil,sameport)
118
129
  if @list == nil then
119
130
  raise UPnPException.new,"No UPNP Device Found"
120
131
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mupnp
3
3
  version: !ruby/object:Gem::Version
4
- version: "0.1"
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dario Meloni
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-07-01 00:00:00 +02:00
12
+ date: 2008-09-19 00:00:00 +02:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -75,7 +75,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
75
75
  requirements: []
76
76
 
77
77
  rubyforge_project: mupnp
78
- rubygems_version: 1.0.1
78
+ rubygems_version: 1.2.0
79
79
  signing_key:
80
80
  specification_version: 2
81
81
  summary: UPnP Implementation using the Miniupnpc library