emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] master ca50c21 21/76: (enwc--int-to-byte-list, enwc--byte-list-to


From: Ian Dunn
Subject: [elpa] master ca50c21 21/76: (enwc--int-to-byte-list, enwc--byte-list-to-int, enwc--htonl): Added to assist with D-Bus conversion.
Date: Thu, 23 Feb 2017 19:42:46 -0500 (EST)

branch: master
commit ca50c2110b6ad647a9e234e0d52412cfc8b48540
Author: Ian D <address@hidden>
Commit: Ian D <address@hidden>

    (enwc--int-to-byte-list, enwc--byte-list-to-int, enwc--htonl): Added to 
assist with D-Bus conversion.
    (enwc-nm-sec-types): Removed.
    (enwc-nm-dbus-*-call-method): Used `apply' to pass the argumetnts to 
`enwc-nm-dbus-call-method'.
    (enwc-nm-gen-uuid): Added doc-string.
    (enwc-nm-convert-addr): Added doc-string.
    (enwc-nm-addr-back): Fixed bugs and added doc-string.
    (enwc-nm-netmask-to-prefix): Added doc-string.
    (enwc-nm-prefix-to-netmask): Fixed bugs and added doc-string.
    (enwc-nm-set-dbus-dict-entry): Added correct return value.
    (enwc-nm-get-profile-info): Implemented `enwc-nm-prefix-to-netmask'.
---
 lisp/enwc-nm.el | 101 ++++++++++++++++++--------------------------------------
 lisp/enwc.el    |  17 ++++++++++
 2 files changed, 50 insertions(+), 68 deletions(-)

diff --git a/lisp/enwc-nm.el b/lisp/enwc-nm.el
index 8124a27..feff840 100644
--- a/lisp/enwc-nm.el
+++ b/lisp/enwc-nm.el
@@ -94,42 +94,6 @@
   '("Ssid" "HwAddress" "Strength" "Flags" "Mode" "Frequency")
   "The list of the desired details to be obtained from each network.")
 
-(defvar enwc-nm-sec-types
-  '(("eap-leap" . (("Name" . "eap-leap")
-                   ("reqs" . ((("identity" . "Username")
-                               ("password" . "Password"))))))
-    ("eap-peap" . (("Name" . "eap-peap")
-                   ("reqs" . ((("anonymous-identity" . "Anonymous Identity")
-                               ("ca-cert" . "CA Certificate")
-                               ("phase2-auth" . "Inner Authentication")
-                               ("phase1-peapver" . "PEAP Version")
-                               ("identity" . "Username")
-                               ("password" . "Password"))))))
-    ("eap-tls" . (("Name" . "eap-tls")
-                  ("reqs" . ((("identity" . "Identity")
-                              ("client-cert" . "User Certificate")
-                              ("ca-cert" . "CA Certificate")
-                              ("private-key" . "Private Key")
-                              ("private-key-password" . "Private Key 
Password"))))))
-    ("eap-ttls" . (("Name" . "eap-ttls")
-                   ("reqs" . ((("anonymous-identity" . "Anonymous Identity")
-                               ("ca-cert" . "CA Certificate")
-                               ("phase2-auth" . "Inner Authentication")
-                               ("identity" . "Username")
-                               ("password" . "Password"))))))
-    ("wpa-psk" . (("Name" . "wpa2")
-                  ("reqs" . ((("psk" . "PSK"))))))
-    ("wep" . (("Name" . "wep")
-              ("reqs" . ((("wep-key0" . "WEP Key")
-                          ("wep-key-type" . "WEP Key Type"))))))
-    ("leap" . (("Name" . "leap")
-               ("reqs" . ((("leap-username" . "Username")
-                           ("leap-password" . "Password"))))))
-    )
-  "The security types for NetworkManager.
-This is still in the process of being worked on."
-  )
-
 (defvar enwc-nm-wired-dev nil
   "The wired device object path.")
 
@@ -160,25 +124,28 @@ This is still in the process of being worked on."
          args))
 
 (defun enwc-nm-dbus-default-call-method (method &rest args)
-  (enwc-nm-dbus-call-method method nil nil args))
+  (apply 'enwc-nm-dbus-call-method method nil nil args))
 
 (defun enwc-nm-dbus-settings-call-method (method &rest args)
-  (enwc-nm-dbus-call-method method
-                            enwc-nm-dbus-settings-path
-                            enwc-nm-dbus-settings-interface
-                            args))
+  (apply 'enwc-nm-dbus-call-method
+         method
+         enwc-nm-dbus-settings-path
+         enwc-nm-dbus-settings-interface
+         args))
 
 (defun enwc-nm-dbus-wireless-call-method (method &rest args)
-  (enwc-nm-dbus-call-method method
-                            enwc-nm-wireless-dev
-                            enwc-nm-dbus-wireless-interface
-                            args))
+  (apply 'enwc-nm-dbus-call-method
+         method
+         enwc-nm-wireless-dev
+         enwc-nm-dbus-wireless-interface
+         args))
 
 (defun enwc-nm-dbus-wired-call-method (method &rest args)
-  (enwc-nm-dbus-call-method method
-                            enwc-nm-wired-dev
-                            enwc-nm-dbus-wired-interface
-                            args))
+  (apply 'enwc-nm-dbus-call-method
+         method
+         enwc-nm-wired-dev
+         enwc-nm-dbus-wired-interface
+         args))
 
 (defun enwc-nm-get-settings (conn)
   "Gets the connection settings.
@@ -198,9 +165,9 @@ CONN is an object path to the connection."
 (defun enwc-nm-get-device-by-name (name)
   (enwc-nm-dbus-default-call-method "GetDeviceByIpIface" :string name))
 
-;;;;;;;;;;;;;;;;;
-;; Get networks
-;;;;;;;;;;;;;;;;;
+;;;;;;;;;;;;;;;;;;
+;; Get networks ;;
+;;;;;;;;;;;;;;;;;;
 
 (defun enwc-nm-get-networks (&optional wired)
   (if wired
@@ -281,8 +248,8 @@ This gets the connection path from NW, and connects to it."
                               dev interface
                               '(:array :signature "{sv}"))))
 
-;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;; Get network properties
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; Get network properties ;;
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
 (defun enwc-nm-get-wireless-network-property (nw prop)
@@ -383,6 +350,7 @@ STATE is the new state."
   enwc-nm-wired-p)
 
 (defun enwc-nm-gen-uuid ()
+  "Generate a UUID."
   (random t)
   (let ((hex-nums
          (mapcar (lambda (x)
@@ -396,6 +364,7 @@ STATE is the new state."
   `(string-to-number (substring ,str ,st ,ed) 16))
 
 (defun enwc-nm-convert-addr (addr)
+  "Convert an address ADDR from an integer in network byte order to a string."
   (if addr
       (let* ((hex-addr (format "%08x" addr))
              (subs (mapcar
@@ -406,17 +375,18 @@ STATE is the new state."
     ""))
 
 (defun enwc-nm-addr-back (addr)
+  "Convert an IP address ADDR in dots notation to an integer."
   (let* ((bytes (split-string addr "\\."))
          (byte-string (mapcar
-                       (lambda (n) (lsh (string-to-number (nth (- 3 n) bytes)) 
n))
+                       (lambda (n) (lsh (string-to-number (nth n bytes))
+                                        (* 8 n)))
                        (number-sequence 0 3))))
     (apply 'logior byte-string)))
 
 ;; These next two come from libnm-util/nm-utils.c in NM's source.
-;; TODO: These should be used.
 
 (defun enwc-nm-netmask-to-prefix (netmask)
-  "Converts a netmask to a prefix.
+  "Converts a netmask to a CIDR prefix.
 NETMASK is an ip address in network byte order."
   (if netmask
       (let* ((mask netmask)
@@ -437,17 +407,11 @@ NETMASK is an ip address in network byte order."
     0))
 
 (defun enwc-nm-prefix-to-netmask (prefix)
-  "Converts a prefix to a netmask.
+  "Converts a CIDR prefix to a netmask.
 PREFIX is an integer <= 32."
   (cl-check-type prefix integer)
-  (let ((pf prefix)
-        (netmask 0)
-        (msk #x80000000))
-    (while (> pf 0)
-      (setq netmask (logior netmask msk)
-            msk     (lsh msk -1)
-            pf      (1- pf)))
-    netmask))
+  (setq prefix (min prefix 32))
+  (enwc--htonl (lsh (1- (expt 2 prefix)) (- 32 prefix))))
 
 (defun enwc-nm-get-dbus-dict-entry (entry dict)
   "Get an entry ENTRY from D-Bus dictionary DICT.
@@ -461,7 +425,8 @@ representing another layer in the dictionary."
       (setq cur-str (pop ent-strs))
       (setq cur-ent (assoc cur-str cur-ent))
       (when cur-ent
-        (setq cur-ent (cadr cur-ent))))))
+        (setq cur-ent (cadr cur-ent))))
+    cur-ent))
 
 (defun enwc-nm-set-dbus-dict-entry (entry dict value)
   "Set an entry."
@@ -481,7 +446,7 @@ representing another layer in the dictionary."
     (when settings
       (let* ((adr-info (caar (enwc-nm-get-dbus-dict-entry "ipv4/addresses" 
settings)))
              (ip-addr (enwc-nm-convert-addr (nth 0 adr-info)))
-             (netmask (enwc-nm-convert-addr (nth 3 adr-info)))
+             (netmask (enwc-nm-convert-addr (enwc-nm-prefix-to-netmask (nth 1 
adr-info))))
              (gateway (enwc-nm-convert-addr (nth 2 adr-info)))
              (dns-list (mapcar 'enwc-nm-convert-addr
                                (car (enwc-nm-get-dbus-dict-entry "ipv4/dns"
diff --git a/lisp/enwc.el b/lisp/enwc.el
index 70d6b28..9b0252e 100644
--- a/lisp/enwc.el
+++ b/lisp/enwc.el
@@ -262,6 +262,23 @@ each word by SEPS, which defaults to \"-\"."
   (cl-check-type seps string)
   (intern (combine-and-quote-strings (enwc--break-by-words str) seps)))
 
+(defun enwc--int-to-byte-list (n)
+  "Convert 32-bit integer N into a byte list."
+  (let (ret)
+    (dotimes (x 4 ret)
+      (push (logand n 255) ret)
+      (setq n (lsh n -8)))))
+
+(defun enwc--byte-list-to-int (bl)
+  "Convert byte list BL into a 32-bit integer."
+  (let ((ret 0))
+    (dolist (x bl ret)
+      (setq ret (logior (lsh ret 8) x)))))
+
+(defun enwc--htonl (n)
+  "Convert 32-bit integer N from hardware to network byte order."
+  (enwc--byte-list-to-int (nreverse (enwc--int-to-byte-list n))))
+
 ;;;;;;;;;;;;;;;;;;;;
 ;; ENWC functions ;;
 ;;;;;;;;;;;;;;;;;;;;



reply via email to

[Prev in Thread] Current Thread [Next in Thread]