Re: [Freeipa-devel] [PATCH] 060 Parsing of IPv4 and IPv6 addresses

2011-12-21 Thread Endi Sukma Dewata

On 12/21/2011 7:50 AM, Petr Vobornik wrote:

Added
Added, but I don't see a usage for this.
Added some tests to show the usages.
Added
Added
Changed. Test are still called ip_tests - I wouldn't put there any new
non-ip-address related.
For convenience I also attached a 'diff' patch.


ACK. Pushed to master.

--
Endi S. Dewata

___
Freeipa-devel mailing list
Freeipa-devel@redhat.com
https://www.redhat.com/mailman/listinfo/freeipa-devel


Re: [Freeipa-devel] [PATCH] 060 Parsing of IPv4 and IPv6 addresses

2011-12-20 Thread Petr Vobornik

On 12/19/2011 05:12 PM, Petr Vobornik wrote:

On 12/19/2011 04:44 PM, Petr Vobornik wrote:

[Web UI]

Added support of parsing and validation of IPv4 and IPv6 addresses.
Class IP.address can also create reverse address from any valid IPv4 or
IPv6 address.

This functionality is prerequisite for tickets:
https://fedorahosted.org/freeipa/ticket/1466
https://fedorahosted.org/freeipa/ticket/1975

Ticket: https://fedorahosted.org/freeipa/ticket/1466



Self NACK

Getting reverse addresses is not functional for integer IPv4 input.

Updated patch will follow tomorrow.


Fixed.
Attached new patch.

--
Petr Vobornik
From 5c64802a363f1361d5d6a23446238e9c1eacbbdf Mon Sep 17 00:00:00 2001
From: Petr Vobornik pvobo...@redhat.com
Date: Mon, 19 Dec 2011 16:14:04 +0100
Subject: [PATCH] Parsing of IPv4 and IPv6 addresses

Added support of parsing and validation of IPv4 and IPv6 addresses.
Class IP.address can also create reverse address from any valid IPv4 or IPv6 address.

This functionality is needed for tickets:
https://fedorahosted.org/freeipa/ticket/1466
https://fedorahosted.org/freeipa/ticket/1975
---
 install/ui/Makefile.am   |1 +
 install/ui/ip.js |  366 ++
 install/ui/jsl.conf  |1 +
 install/ui/test/all_tests.html   |4 +-
 install/ui/test/details_tests.js |1 -
 install/ui/test/ip_tests.html|   18 ++
 install/ui/test/ip_tests.js  |  217 ++
 install/ui/test/jsl.conf |4 +-
 8 files changed, 609 insertions(+), 3 deletions(-)
 create mode 100644 install/ui/ip.js
 create mode 100644 install/ui/test/ip_tests.html
 create mode 100644 install/ui/test/ip_tests.js

diff --git a/install/ui/Makefile.am b/install/ui/Makefile.am
index 835888d94e65704ae12d4098ead210bfb195ce85..b316c391c184874c6dd6cb6d855c2769de2b259d 100644
--- a/install/ui/Makefile.am
+++ b/install/ui/Makefile.am
@@ -30,6 +30,7 @@ app_DATA =\
 	hostgroup.js 			\
 	index.html 			\
 	ipa.css\
+	ip.js\
 	ipa.js\
 	jquery-ui.css			\
 	jquery-ui.js			\
diff --git a/install/ui/ip.js b/install/ui/ip.js
new file mode 100644
index ..9ba39416aba660024071e3eb604470ddcfd845d8
--- /dev/null
+++ b/install/ui/ip.js
@@ -0,0 +1,366 @@
+/*  Authors:
+ *Petr Vobornik pvobo...@redhat.com
+ *
+ * Copyright (C) 2010 Red Hat
+ * see file 'COPYING' for use and warranty information
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see http://www.gnu.org/licenses/.
+ */
+
+var IP = {};
+
+IP.address = function(spec) {
+
+spec = spec || {};
+
+var that = {};
+
+that.input = spec.address || '';
+
+that.type;
+that.parts = [];
+that.reverse_address = '';
+that.only_decimal = spec.only_decimal !== undefined? spec.only_decimal :
+false ; //for parsing IPv4 address
+
+that.parse = function() {
+
+that.get_type();
+
+if (that.type === 'v4-quads') {
+return that.parse_v4_quads();
+} else if (that.type === 'v4-int') {
+return that.parse_v4_int();
+} else if (that.type === 'v6') {
+return that.parse_v6();
+}
+
+that.set_error('not an ip address');
+return false;
+};
+
+that.get_type = function() {
+
+if (that.input.indexOf(':')  -1) that.type = 'v6';
+else if (that.input.indexOf('.')  -1) that.type = 'v4-quads';
+else that.type = 'v4-int';
+
+return that.type;
+};
+
+that.parse_v4_int = function() {
+
+var part = { value: that.input };
+if(!that.is_part_valid_v4(part, 32, that.only_decimal)) return false;
+
+that.parts = [];
+that.make_quads(part.decimal_value, that.parts);
+
+that.valid = true;
+return true;
+};
+
+that.parse_v4_quads = function() {
+
+that.parts = that.input.split('.');
+
+if (that.parts.length !== 4) {
+return that.set_error('invalid number of parts');
+}
+
+for (var i=0; i4; i++) {
+
+var part = { value: that.parts[i] };
+
+if (!that.is_part_valid_v4(part, 8, that.only_decimal)) {
+return false;
+}
+that.parts[i] = part.decimal_value;
+}
+
+that.valid = true;
+return true;
+};
+
+that.parse_v6 = function() {
+
+that.parts = 

Re: [Freeipa-devel] [PATCH] 060 Parsing of IPv4 and IPv6 addresses

2011-12-20 Thread Endi Sukma Dewata

On 12/20/2011 2:35 AM, Petr Vobornik wrote:

Added support of parsing and validation of IPv4 and IPv6 addresses.
Class IP.address can also create reverse address from any valid IPv4 or
IPv6 address.

This functionality is prerequisite for tickets:
https://fedorahosted.org/freeipa/ticket/1466
https://fedorahosted.org/freeipa/ticket/1975

Ticket: https://fedorahosted.org/freeipa/ticket/1466


The code isn't used yet in the main code, so it can be pushed without 
breaking anything. I have some suggestions though:


1. For convenience, the IP.address class probably can be made to take a 
string or a spec object then call parse() internally. For example:


  var address1 = IP.address('127.0.0.1');

  var address2 = IP.address({
  parts: [127, 0, 0, 1]
  type: 'v4-quads'
  });

  var reverse = address1.get_reverse();

2. The test checks the return value of parse() but it doesn't validate 
whether the IP address is parsed into the correct parts. It probably 
should do something like this:


  var address = IP.address('127.0.0.1');
  same(address.parts, [127, 0, 0, 1]);

3. The ip_tests.html should be linked from the index.html.

4. It's probably better to use NET instead of IP for the namespace so we 
can add more net-related stuff.


--
Endi S. Dewata

___
Freeipa-devel mailing list
Freeipa-devel@redhat.com
https://www.redhat.com/mailman/listinfo/freeipa-devel


Re: [Freeipa-devel] [PATCH] 060 Parsing of IPv4 and IPv6 addresses

2011-12-19 Thread Petr Vobornik

On 12/19/2011 04:44 PM, Petr Vobornik wrote:

[Web UI]

Added support of parsing and validation of IPv4 and IPv6 addresses.
Class IP.address can also create reverse address from any valid IPv4 or
IPv6 address.

This functionality is prerequisite for tickets:
https://fedorahosted.org/freeipa/ticket/1466
https://fedorahosted.org/freeipa/ticket/1975

Ticket: https://fedorahosted.org/freeipa/ticket/1466



Self NACK

Getting reverse addresses is not functional for integer IPv4 input.

Updated patch will follow tomorrow.

--
Petr Vobornik

___
Freeipa-devel mailing list
Freeipa-devel@redhat.com
https://www.redhat.com/mailman/listinfo/freeipa-devel