[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 245a82f 52/76: Moved Wicd and NetworkManager backends to n
From: |
Ian Dunn |
Subject: |
[elpa] master 245a82f 52/76: Moved Wicd and NetworkManager backends to new system. |
Date: |
Thu, 23 Feb 2017 19:42:52 -0500 (EST) |
branch: master
commit 245a82f5f875380f2c0f9a4255aaf2875fb0fa2c
Author: Ian Dunn <address@hidden>
Commit: Ian Dunn <address@hidden>
Moved Wicd and NetworkManager backends to new system.
---
lisp/enwc-nm.el | 108 +++++++++++++++++++++++++++-----------------
lisp/enwc-wicd.el | 133 ++++++++++++++++++++++++++++++++----------------------
2 files changed, 146 insertions(+), 95 deletions(-)
diff --git a/lisp/enwc-nm.el b/lisp/enwc-nm.el
index b6499ce..363cb3d 100644
--- a/lisp/enwc-nm.el
+++ b/lisp/enwc-nm.el
@@ -29,7 +29,9 @@
;; This requires NetworkManager >= 0.9.6
;;
+(require 'enwc-backend)
(require 'enwc)
+(require 'dbus)
(defgroup enwc-nm nil
"*NetworkManager variables for ENWC"
@@ -421,31 +423,31 @@ If STATE is 40, then NetworkManager is connecting to a
new AP."
(let* ((bytes (split-string addr "\\."))
(byte-string (mapcar
(lambda (n) (lsh (string-to-number (nth n bytes))
- (* 8 n)))
+ (* 8 n)))
(number-sequence 0 3))))
(apply 'logior byte-string)))
;; These next two come from libnm-util/nm-utils.c in NM's source.
-(defun enwc-nm-netmask-to-prefix (netmask)
- "Convert a netmask to a CIDR prefix.
-NETMASK is an ip address in network byte order."
- (if (and netmask (integerp netmask))
- (progn
- (setq netmask (enwc--htonl netmask))
- (while (cl-evenp netmask)
- (setq netmask (lsh netmask -1)))
- (floor (log (1+ netmask) 2)))
- 0))
-
-(defun enwc-nm-prefix-to-netmask (prefix)
- "Convert a CIDR prefix to a netmask.
-PREFIX is an integer <= 32."
- (if (and prefix (integerp prefix))
- (progn
- (setq prefix (min prefix 32))
- (enwc--htonl (lsh (1- (expt 2 prefix)) (- 32 prefix))))
- 0))
+;; (defun enwc-nm-netmask-to-prefix (netmask)
+;; "Convert a netmask to a CIDR prefix.
+;; NETMASK is an ip address in network byte order."
+;; (if (and netmask (integerp netmask))
+;; (progn
+;; (setq netmask (enwc--htonl netmask))
+;; (while (cl-evenp netmask)
+;; (setq netmask (lsh netmask -1)))
+;; (floor (log (1+ netmask) 2)))
+;; 0))
+
+;; (defun enwc-nm-prefix-to-netmask (prefix)
+;; "Convert a CIDR prefix to a netmask.
+;; PREFIX is an integer <= 32."
+;; (if (and prefix (integerp prefix))
+;; (progn
+;; (setq prefix (min prefix 32))
+;; (enwc--htonl (lsh (1- (expt 2 prefix)) (- 32 prefix))))
+;; 0))
;;;;;;;;;;;;;;;;;;;;;;
;; D-Bus Conversion ;;
@@ -537,27 +539,27 @@ representing another layer in the dictionary."
(push `(:string (car ent) ,(enwc-nm-alist-to-dbus-dict (cadr ent))) ret)
(push :dict-entry ret))))
-(defun enwc-nm-get-profile-info (ap &optional wired)
- "Get the profile info for access point AP."
- (let ((conn (enwc-nm--ap-to-conn ap))
- settings)
- (when conn
- (setq settings (enwc-nm-get-settings conn)))
- (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 (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"
- settings))))
- (sec-info (enwc-nm-get-sec-info settings)))
- `((addr . ,ip-addr)
- (netmask . ,netmask)
- (gateway . ,gateway)
- (dns1 . ,(nth 0 dns-list))
- (dns2 . ,(nth 1 dns-list))
- ,@sec-info)))))
+;; (defun enwc-nm-get-profile-info (ap &optional wired)
+;; "Get the profile info for access point AP."
+;; (let ((conn (enwc-nm--ap-to-conn ap))
+;; settings)
+;; (when conn
+;; (setq settings (enwc-nm-get-settings conn)))
+;; (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 (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"
+;;
settings))))
+;; (sec-info (enwc-nm-get-sec-info settings)))
+;; `((addr . ,ip-addr)
+;; (netmask . ,netmask)
+;; (gateway . ,gateway)
+;; (dns1 . ,(nth 0 dns-list))
+;; (dns2 . ,(nth 1 dns-list))
+;; ,@sec-info)))))
(defun enwc-nm-finalize-settings (settings)
"Set up all of the D-BUS types of a settings list SETTINGS.
@@ -604,6 +606,12 @@ to put it in the form that NetworkManager will recognize."
enwc-nm-dbus-settings-interface
(enwc-nm-setup-settings ap settings wired)))))
+
+ ; ;;;;;;;;;;;;;;;;; ;
+ ; ;; Load/Unload ;; ;
+ ; ;;;;;;;;;;;;;;;;; ;
+
+
(defun enwc-nm-load ()
"Setup the NetworkManager back-end."
;;TODO: Add way of changing these two after load.
@@ -685,6 +693,24 @@ Unregister all of the D-Bus signals set up during load."
(dbus-unregister-object enwc-nm-wired-state-changed-signal)
(dbus-unregister-object enwc-nm-state-changed-signal))
+(defun enwc-nm-can-load-p ()
+ (dbus-ping :system enwc-nm-dbus-service))
+
+(enwc-register-backend
+ (make-enwc-backend
+ :key 'nm
+ :can-load-p #'enwc-nm-can-load-p
+ :load #'enwc-nm-load
+ :unload #'enwc-nm-unload
+ :network-ids #'enwc-nm-get-networks
+ :scan #'enwc-nm-scan
+ :connect #'enwc-nm-connect
+ :disconnect #'enwc-nm-disconnect
+ :current-nw-id #'enwc-nm-get-current-nw-id
+ :is-connecting-p #'enwc-nm-check-connecting
+ :wireless-nw-props #'enwc-nm-get-wireless-nw-props
+ :is-wired-p #'enwc-nm-is-wired))
+
(provide 'enwc-nm)
;;; enwc-nm.el ends here
diff --git a/lisp/enwc-wicd.el b/lisp/enwc-wicd.el
index 3438ee2..cb64fa8 100644
--- a/lisp/enwc-wicd.el
+++ b/lisp/enwc-wicd.el
@@ -30,7 +30,9 @@
;;; Code:
+(require 'enwc-backend)
(require 'enwc)
+(require 'dbus)
(defgroup enwc-wicd nil
"*Wicd variables for ENWC."
@@ -289,60 +291,60 @@ so this jut returns the tracked network id."
;; Get Profile Info ;;
;;;;;;;;;;;;;;;;;;;;;;
-(defun enwc-wicd-get-profile-ent (id ent wired)
- "Get profile entry ENT from the network with id ID.
-WIRED is set to indicate whether this is a wired network.
-This function is a wrapper around the *-get-(wired|wireless)-nw-prop
-functions, allowing for a single function that checks for wired."
- (if wired
- (enwc-wicd-get-wired-nw-prop id ent)
- (enwc-wicd-dbus-wireless-call-method "GetWirelessProperty" id ent)))
-
-(defun enwc-wicd-get-profile-info (id &optional wired)
- "Get the profile for profile ID.
-WIRED is set to indicate whether this is a wired network."
- (let ((dns-list (enwc-wicd-get-dns id wired))
- (sec-info (enwc-wicd-get-profile-sec-info id wired)))
- `((addr . ,(enwc-wicd-get-ip-addr id wired))
- (netmask . ,(enwc-wicd-get-netmask id wired))
- (gateway . ,(enwc-wicd-get-gateway id wired))
- (dns1 . ,(nth 0 dns-list))
- (dns2 . ,(nth 1 dns-list))
- ,@sec-info)))
-
-(defun enwc-wicd-get-profile-sec-info (id &optional wired)
- "Get the security info for profile with id ID.
-WIRED is set to indicate whether this is a wired network."
- (remq nil
- (mapcar
- (lambda (ent)
- (let ((info (enwc-wicd-get-profile-ent wired id (symbol-name (car
ent)))))
- (if info
- (cons (car ent) info)
- nil)))
- enwc-supplicant-alist)))
-
-(defun enwc-wicd-get-ip-addr (id wired)
- "Get the IP Address from the network with id ID.
-Wired is set to indicate whether this is a wired network."
- (or (enwc-wicd-get-profile-ent id "ip" wired) ""))
-
-(defun enwc-wicd-get-netmask (id wired)
- "Get the Netmask from the network with id ID.
-WIRED is set to indicate whether this is a wired network."
- (or (enwc-wicd-get-profile-ent id "netmask" wired) ""))
-
-(defun enwc-wicd-get-gateway (id wired)
- "Get the Gateway from the network with id ID.
-WIRED is set to indicate whether this is a wired network."
- (or (enwc-wicd-get-profile-ent id "gateway" wired) ""))
-
-(defun enwc-wicd-get-dns (id wired)
- "Get the list of DNS servers from the network with id ID.
-WIRED is set to indicate whether this is a wired network."
- (list (or (enwc-wicd-get-profile-ent id "dns1" wired) "")
- (or (enwc-wicd-get-profile-ent id "dns2" wired) "")
- (or (enwc-wicd-get-profile-ent id "dns3" wired) "")))
+;; (defun enwc-wicd-get-profile-ent (id ent wired)
+;; "Get profile entry ENT from the network with id ID.
+;; WIRED is set to indicate whether this is a wired network.
+;; This function is a wrapper around the *-get-(wired|wireless)-nw-prop
+;; functions, allowing for a single function that checks for wired."
+;; (if wired
+;; (enwc-wicd-get-wired-nw-prop id ent)
+;; (enwc-wicd-dbus-wireless-call-method "GetWirelessProperty" id ent)))
+
+;; (defun enwc-wicd-get-profile-info (id &optional wired)
+;; "Get the profile for profile ID.
+;; WIRED is set to indicate whether this is a wired network."
+;; (let ((dns-list (enwc-wicd-get-dns id wired))
+;; (sec-info (enwc-wicd-get-profile-sec-info id wired)))
+;; `((addr . ,(enwc-wicd-get-ip-addr id wired))
+;; (netmask . ,(enwc-wicd-get-netmask id wired))
+;; (gateway . ,(enwc-wicd-get-gateway id wired))
+;; (dns1 . ,(nth 0 dns-list))
+;; (dns2 . ,(nth 1 dns-list))
+;; ,@sec-info)))
+
+;; (defun enwc-wicd-get-profile-sec-info (id &optional wired)
+;; "Get the security info for profile with id ID.
+;; WIRED is set to indicate whether this is a wired network."
+;; (remq nil
+;; (mapcar
+;; (lambda (ent)
+;; (let ((info (enwc-wicd-get-profile-ent wired id (symbol-name (car
ent)))))
+;; (if info
+;; (cons (car ent) info)
+;; nil)))
+;; enwc-supplicant-alist)))
+
+;; (defun enwc-wicd-get-ip-addr (id wired)
+;; "Get the IP Address from the network with id ID.
+;; Wired is set to indicate whether this is a wired network."
+;; (or (enwc-wicd-get-profile-ent id "ip" wired) ""))
+
+;; (defun enwc-wicd-get-netmask (id wired)
+;; "Get the Netmask from the network with id ID.
+;; WIRED is set to indicate whether this is a wired network."
+;; (or (enwc-wicd-get-profile-ent id "netmask" wired) ""))
+
+;; (defun enwc-wicd-get-gateway (id wired)
+;; "Get the Gateway from the network with id ID.
+;; WIRED is set to indicate whether this is a wired network."
+;; (or (enwc-wicd-get-profile-ent id "gateway" wired) ""))
+
+;; (defun enwc-wicd-get-dns (id wired)
+;; "Get the list of DNS servers from the network with id ID.
+;; WIRED is set to indicate whether this is a wired network."
+;; (list (or (enwc-wicd-get-profile-ent id "dns1" wired) "")
+;; (or (enwc-wicd-get-profile-ent id "dns2" wired) "")
+;; (or (enwc-wicd-get-profile-ent id "dns3" wired) "")))
;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Save Network Settings ;;
@@ -414,6 +416,11 @@ WIRED indicates whether or not ID is a wired connection."
(caar (nthcdr 3 info))
(string-to-number (caar (nthcdr 3
info))))))))
+
+; ;;;;;;;;;;;;;;;;; ;
+; ;; Load/Unload ;; ;
+; ;;;;;;;;;;;;;;;;; ;
+
(defun enwc-wicd-load ()
"Load the Wicd backend."
;; Thanks to Michael Albinus for pointing out this signal.
@@ -440,6 +447,24 @@ Unregister all of the D-Bus signals set up during load."
(dbus-unregister-object enwc-wicd-end-scan-signal)
(dbus-unregister-object enwc-wicd-status-changed-signal))
+(defun enwc-wicd-can-load-p ()
+ (dbus-ping :system enwc-wicd-dbus-service))
+
+(enwc-register-backend
+ (make-enwc-backend
+ :key 'enwc
+ :can-load-p #'enwc-wicd-can-load-p
+ :load #'enwc-wicd-load
+ :unload #'enwc-wicd-unload
+ :network-ids #'enwc-wicd-get-networks
+ :scan #'enwc-wicd-scan
+ :connect #'enwc-wicd-connect
+ :disconnect #'enwc-wicd-disconnect
+ :current-nw-id #'enwc-wicd-get-current-nw-id
+ :is-connecting-p #'enwc-wicd-check-connecting
+ :wireless-nw-props #'enwc-wicd-get-wireless-network-props
+ :is-wired-p #'enwc-wicd-is-wired))
+
(provide 'enwc-wicd)
;;; enwc-wicd.el ends here.
- [elpa] master 5c63470 48/76: Fixed autoloads generation and added hgignore., (continued)
- [elpa] master 5c63470 48/76: Fixed autoloads generation and added hgignore., Ian Dunn, 2017/02/23
- [elpa] master 43c98da 50/76: Changed enwc-last-scan to a hashtable., Ian Dunn, 2017/02/23
- [elpa] master c6585bb 47/76: Added autoloads, Ian Dunn, 2017/02/23
- [elpa] master 48e7aa4 55/76: Updated Makefile, Ian Dunn, 2017/02/23
- [elpa] master 2e07c3a 54/76: Began work on WPA backend. EXPERIMENTAL!, Ian Dunn, 2017/02/23
- [elpa] master ba6061b 51/76: Created more robust backend system., Ian Dunn, 2017/02/23
- [elpa] master ad38333 59/76: Cleaned up enwc-refresh-widths and changed enwc-details-list to enwc-column-specs., Ian Dunn, 2017/02/23
- [elpa] master a46fe3c 64/76: Don't switch to the ENWC buffer when processing a scan., Ian Dunn, 2017/02/23
- [elpa] master 33515f8 66/76: Silenced byte-compiler., Ian Dunn, 2017/02/23
- [elpa] master bcb33e6 30/76: (enwc-get-networks): Improved docstring., Ian Dunn, 2017/02/23
- [elpa] master 245a82f 52/76: Moved Wicd and NetworkManager backends to new system.,
Ian Dunn <=
- [elpa] master 3b1bbc6 69/76: Fixed autoloads target in Makefile, Ian Dunn, 2017/02/23
- [elpa] master 8c17c8c 73/76: Updated hgignore to ignore elc files in top-level directory., Ian Dunn, 2017/02/23
- [elpa] master a3c59cc 74/76: Updated version to 2.0beta1, Ian Dunn, 2017/02/23
- [elpa] master 2e271c6 72/76: Moved lisp files into top-level directory., Ian Dunn, 2017/02/23
- [elpa] master b673e3a 63/76: Added default setup and removed experimental WPA supplicant backend., Ian Dunn, 2017/02/23
- [elpa] master 2c298fc 70/76: Updated copyright and keywords on all files., Ian Dunn, 2017/02/23
- [elpa] master 8e44368 68/76: Moved enwc-setup to enwc.el, and added it to enwc., Ian Dunn, 2017/02/23
- [elpa] master 4462fba 56/76: Lots of changes to enwc.el., Ian Dunn, 2017/02/23
- [elpa] master 62fe017 71/76: Removed some files from docs., Ian Dunn, 2017/02/23
- [elpa] master 942d83d 15/76: enwc.el, enwc-setup.el: Consolidated and concretely defined front-end interface., Ian Dunn, 2017/02/23