iAnish / openhab

Automatically exported from code.google.com/p/openhab
GNU General Public License v3.0
0 stars 0 forks source link

CUPS binding could not connect #491

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Configure cups binding with IP Adresse e.g. 192.168.0.21
2.
3.

What is the expected output? What do you see instead?
Couldn't connect to CupsServer because of missing connection parameters [Host 
'null' Port '631'].

What version of the product are you using? On what operating system?
1.3.1

Please provide any additional information below.
The problem is Line 167 ff.
                        host = (String) config.get("host");
                        Matcher matcher = IP_PATTERN.matcher(host);
                        if (!matcher.matches()) {
It is checked if the host is an correct numeric IP address. If OK, there is 
only an if clause, but the else is missing, because in line  197 there is "ip" 
used, but not set with host
                       connect(ip, port);
So, I have added an else clause in line 196 with
          else {
        ip = host;
      }

Original issue reported on code.google.com by steffen2...@gmail.com on 16 Oct 2013 at 9:50

GoogleCodeExporter commented 9 years ago
Ah, I forgot to mention the filename CupsBinding.java.

Original comment by steffen2...@gmail.com on 16 Oct 2013 at 9:51

GoogleCodeExporter commented 9 years ago
Your hint on the error in the code is not quite correct. As you can see it is 
checked if the given host is NO corrent IP address (there is a negotiation !):

if (!matcher.matches())

in this case it is assumed that the host-variable contains a valid hostname in 
your network and tries to find the corresponding ip address.

Original comment by TBraeuti...@gmail.com on 17 Oct 2013 at 5:35

GoogleCodeExporter commented 9 years ago
You are right. But if the ip is correct, the correct IP is in the host variable 
and not in the ip Variable. And the later statement connect(ip, port); uses the 
ip Variable which is null if the host contains a valid IP in the first place.
            host = (String) config.get("host");
            Matcher matcher = IP_PATTERN.matcher(host);
            if (!matcher.matches()) {
                try {
                    InetAddress address = InetAddress.getByName(host);
                    ip = address.getHostAddress();
                } catch (UnknownHostException e) {
                    throw new ConfigurationException("host", "unknown host '" + host + "'!");
                }
            } else {
                ip = host;
            }

Original comment by steffen2...@gmail.com on 17 Oct 2013 at 7:22

GoogleCodeExporter commented 9 years ago
Oops you are right. My fault, maybe it was too early in the morning to think 
clearly for me ;-)

Original comment by TBraeuti...@gmail.com on 17 Oct 2013 at 7:58

GoogleCodeExporter commented 9 years ago
And for me too late, to write more words ;-) I am glad if I can get some hints 
on how to build just single bindings, without compiling the whole product. I am 
not so used to maven and its structure an tools. For now I have manually 
exchanged the .class in the jar ;-) 

Original comment by steffen2...@gmail.com on 17 Oct 2013 at 8:16

GoogleCodeExporter commented 9 years ago
Currently I have some changes in my master branch and an ongoing pull request. 
As I am quite new to git, I don´t know how to create a new branch on my clone 
without my changes in order to create a pull request with only contains this 
bugfix.

If you have any chance to to so, please go ahead. Otherwise I will fix it after 
my former pull request gets accepted.

Original comment by TBraeuti...@gmail.com on 17 Oct 2013 at 8:20

GoogleCodeExporter commented 9 years ago
Ok, so you are in the same situation. It took me a while to get the right 
version of the source for remote debugging. So take the fix if it is nice 
enough ...

Original comment by steffen2...@gmail.com on 17 Oct 2013 at 8:29

GoogleCodeExporter commented 9 years ago
merged pull request. can you confirm the fix is working for you?

Original comment by teichsta on 4 Nov 2013 at 8:47

GoogleCodeExporter commented 9 years ago
ACK, binding works fine. Thanks

Original comment by steffen2...@gmail.com on 7 Nov 2013 at 4:37

GoogleCodeExporter commented 9 years ago
perfect, thanks for your confirmation!

Original comment by teichsta on 7 Nov 2013 at 5:05