From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: =?utf-8?Q?No=C3=A9_Lopez?= via "Emacs development discussions." Newsgroups: gmane.emacs.devel Subject: [PATCH] [ELPA] Implement connman in enwc Date: Fri, 29 Mar 2024 23:10:45 +0100 Message-ID: <87bk6wadui.fsf@xn--no-cja.eu> Reply-To: =?utf-8?Q?No=C3=A9_Lopez?= Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="20394"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org, noelopez@free.fr To: dunni@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sat Mar 30 07:03:23 2024 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1rqRoI-00053z-Ta for ged-emacs-devel@m.gmane-mx.org; Sat, 30 Mar 2024 07:03:23 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rqRmx-0007Y3-Fk; Sat, 30 Mar 2024 02:01:59 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rqKR4-00032r-PM for emacs-devel@gnu.org; Fri, 29 Mar 2024 18:10:54 -0400 Original-Received: from smtp.domeneshop.no ([2a01:5b40:0:3006::1]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rqKR2-0007f0-MQ; Fri, 29 Mar 2024 18:10:54 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xn--no-cja.eu; s=ds202402; h=Content-Type:MIME-Version:Message-ID:Date:CC: Subject:To:From:Sender:Reply-To:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=UETmskOnqhKFwWFjX5hBK30wegLoPacyj+eAYtvLv+k=; b=BDJHVseVpTJCfEUXtpMJ+kL9IM qKbwTDh2T+P6hfjpTkDCiKXJxHf553NbmdwWDKMZjI0SA7G3ZorFcOI3Iv6UW3uo6B/PwefbSQmFe eAev8yx6xI+h2o5dI86lDAAx47sEwVOjxSKZbliB7Do8VmlIfkA0eXyF3c48c/ttJnCzgQGGl5CiQ wlC9OPv9y9jIP9H7LUf2OxozSI12DCKeyrohxwNSRXRTpfP1ld+3ii1GPt9oGTv1mw0P2+AuxX8fe 9BLWRaleTiu+1PBmE3EQb6mHNLR6NWj5iFsNL82Kc44MC1Am7HUMyQOB1AzrtvooCxzaEIVLTvwiH kgX0hsCg==; Original-Received: from 88-166-66-165.subs.proxad.net ([88.166.66.165]:44754 helo=lignux) by smtp.domeneshop.no with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1rqKQw-0086Pq-HQ; Fri, 29 Mar 2024 23:10:46 +0100 Received-SPF: pass client-ip=2a01:5b40:0:3006::1; envelope-from=noe@xn--no-cja.eu; helo=smtp.domeneshop.no X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Sat, 30 Mar 2024 02:01:57 -0400 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:317383 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Hi, I've recently stumbled upon the enwc package, it said connman support was experimental so I tried it and since there was no commits since a few years I started finishing it myself. Here is a patch that updates it to finish the connman support. I'm sending it to emacs-devel because I understand it's hosted at ELPA (?) If this is not the right place please tell me what needs to be done for sending patches to inactive packages, thanks. In the near future I would also like to finish the info manual that was started for this package. All the best, No=C3=A9 Lopez --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-Finish-Connman-backend.patch >From b36714fd5aea523ec868227aecbe9579aa57c780 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9=20Lopez?= Date: Fri, 29 Mar 2024 16:32:50 +0100 Subject: [PATCH] Finish Connman backend * enwc-cm.el: Finish backend. * enwc.el: Update package metadata and document the changes. --- doc/enwc.texi | 10 ++++++ enwc-cm.el | 97 ++++++++++++++++++++++++++++++++------------------- enwc.el | 9 +++-- 3 files changed, 76 insertions(+), 40 deletions(-) diff --git a/doc/enwc.texi b/doc/enwc.texi index dddb66df7d..154c2dcae1 100644 --- a/doc/enwc.texi +++ b/doc/enwc.texi @@ -75,4 +75,14 @@ First, the path to ENWC must be added to the @var{load-path} variable. Then, in Now, simply press @kbd{M+x}, and type @kbd{ENWC}, and press @kbd{RET}. ENWC will begin scanning for networks on the wireless interface, and display them in its buffer. +@node Configuration +@chapter Configuration + +TODO + +@node Commands +@chapter Commands + +TODO + @bye diff --git a/enwc-cm.el b/enwc-cm.el index 0dc64a7118..a94a772de3 100644 --- a/enwc-cm.el +++ b/enwc-cm.el @@ -1,4 +1,4 @@ -;; enwc-cm.el --- The ConnMan back-end to ENWC. +;; enwc-cm.el --- The ConnMan back-end to ENWC. -*- lexical-binding: t; -*- ;; Copyright (C) 2012-2017 Free Software Foundation, Inc. @@ -94,31 +94,31 @@ (concat enwc-cm-dbus-technology-path "ethernet")) (defun enwc-cm-get-network (id) - (nth id (enwc-cm-get-services))) + (assoc id (enwc-cm-get-services) #'string=)) ;; connect -(defun enwc-cm-connect (wired id) - (let ((path (concat enwc-cm-dbus-service-path (number-to-string id)))) - (dbus-call-method :system - enwc-cm-dbus-service - path - enwc-cm-dbus-service-interface - "Connect"))) +(defun enwc-cm-connect (nw &optional wired) + (dbus-call-method :system + enwc-cm-dbus-service + nw + enwc-cm-dbus-service-interface + "Connect")) ;; disconnect (defun enwc-cm-disconnect (wired) (dbus-call-method :system enwc-cm-dbus-service - "/net/connman/service/CONNECTED-SERVICE" + (enwc-cm-get-current-nw-id wired) enwc-cm-dbus-service-interface "Disconnect")) ;; scan -(defun enwc-cm-scan (wired) +(defun enwc-cm-scan (&optional wired) (let ((path (if wired (enwc-cm-get-wired-tech-path) (enwc-cm-get-wifi-tech-path)))) (dbus-call-method-asynchronously :system + enwc-cm-dbus-service path enwc-cm-dbus-technology-interface "Scan" @@ -148,17 +148,22 @@ (let ((network (enwc-cm-get-network id))) (car (cadr (assoc prop (cadr network)))))) -(defun enwc-cm-get-network-props (id wired) +(defun enwc-cm-get-nw-props (id wired) (let ((network (enwc-cm-get-network id)) props) ;; network should be a pair, (path . props) (unless network (error "Invalid Network Id %d" id)) (setq props (cadr network)) - (mapcar - (lambda (det) - (enwc-cm-dict-assoc props det)) - enwc-cm-details-list))) + (let ((values (mapcar + (lambda (det) + (enwc-cm-dict-assoc props det)) + enwc-cm-details-list)))) + `((essid . ,(or (enwc-cm-dict-assoc props "Name") "[hidden]")) + (bssid . ,(enwc-cm-dict-assoc props "Ethernet/Address")) + (strength . ,(enwc-cm-dict-assoc props "Strength")) + (encrypt . ,(enwc-cm-dict-assoc props "Security")) + (channel . ,(or (enwc-cm-dict-assoc props "Channel") 0))))) (defun enwc-cm-get-wireless-network-property (id prop) (enwc-cm-get-nw-prop id prop)) @@ -193,17 +198,17 @@ (member (enwc-cm-dict-assoc (cadr service) "State") '("ready" "online"))) -(defun enwc-cm--find-connected-service (services num) +(defun enwc-cm--find-connected-service (services) (if services (if (enwc-cm-is-connected-p (car services)) - num - (enwc-cm--find-connected-service (cdr services) (1+ num))) - -1)) + (car services) + (enwc-cm--find-connected-service (cdr services))) + nil)) -(defun enwc-cm-get-current-nw-id () +(defun enwc-cm-get-current-nw-id (wired) ;TODO : handle wired "Get the current network id." (let* ((services (enwc-cm-get-services))) - (enwc-cm--find-connected-service services 0))) + (car (enwc-cm--find-connected-service services)))) ;; save-profile (defun enwc-cm-set-nw-prop (nw prop val &optional wired) @@ -252,7 +257,7 @@ enwc-cm-dbus-manager-interface "GetServices")) -(defun enwc-cm-get-networks () +(defun enwc-cm-get-networks (&optional wired) ;TODO : handle wired (let ((services (enwc-cm-get-services))) (mapcar 'car services))) @@ -293,15 +298,15 @@ FIELDS is an associative list of requested fields." (defmacro enwc-cm-agent-register-method (method) "Register a method METHOD with D-Bus. METHOD is assumed to be the camel-case D-Bus method." - `((dbus-register-method :session - enwc-cm-dbus-agent-service - enwc-cm-dbus-agent-path - enwc-cm-dbus-agent-interface - ,method - (quote ,(car (read-from-string - (concat - "enwc-cm-agent-" - (enwc-cm-method-to-defun method)))))))) + `(dbus-register-method :session + enwc-cm-dbus-agent-service + enwc-cm-dbus-agent-path + enwc-cm-dbus-agent-interface + ,method + (quote ,(car (read-from-string + (concat + "enwc-cm-agent-" + (enwc-cm-method-to-defun method))))))) ;; Run during setup. (defun enwc-cm-setup () @@ -318,11 +323,11 @@ METHOD is assumed to be the camel-case D-Bus method." (enwc-cm-agent-register-method "Cancel") (dbus-call-method :system - enwc-cm-dbus-manager-service - enwc-cm-dbus-manager-path + enwc-cm-dbus-service + "/" enwc-cm-dbus-manager-interface "RegisterAgent" - :string enwc-cm-dbus-agent-path)) + :object-path enwc-cm-dbus-agent-path)) ;; (defun enwc-cm-get-encryption-type (id) @@ -363,6 +368,28 @@ METHOD is assumed to be the camel-case D-Bus method." ;; (enwc-cm-set-nw-prop wired id "Nameservers.Configuration" ;; new-dns-config))) + +(defun enwc-cm-can-load-p () + (dbus-ping :system enwc-cm-dbus-service)) + +(defun enwc-cm-is-wired () ;TODO + nil) + +(enwc-register-backend + (make-enwc-backend + :key 'cm + :can-load-p #'enwc-cm-can-load-p + :load #'enwc-cm-setup + :unload #'enwc-cm-unload + :network-ids #'enwc-cm-get-networks + :scan #'enwc-cm-scan + :connect #'enwc-cm-connect + :disconnect #'enwc-cm-disconnect + :current-nw-id #'enwc-cm-get-current-nw-id + :is-connecting-p #'enwc-cm-check-connecting-p + :nw-props #'enwc-cm-get-nw-props + :is-wired-p #'enwc-cm-is-wired)) + (provide 'enwc-cm) ;; Local Variables: diff --git a/enwc.el b/enwc.el index 5bd01a5382..015dc41d01 100644 --- a/enwc.el +++ b/enwc.el @@ -3,8 +3,8 @@ ;; Copyright (C) 2012-2017 Free Software Foundation, Inc. ;; Author: Ian Dunn -;; Keywords: external, network, wicd, manager, nm -;; Version: 2.0 +;; Keywords: external, network, wicd, manager, nm, connman +;; Version: 2.1 ;; Package-Requires: ((emacs "25.1")) ;; Homepage: https://savannah.nongnu.org/p/enwc @@ -30,14 +30,13 @@ ;; ENWC is the Emacs Network Client. It is designed to provide a front-end to ;; various network managers, such as NetworkManager and Wicd. ;; -;; Currently, only NetworkManager and Wicd are supported, although experimental -;; support exists for Connman. +;; Currently, NetworkManager, Wicd and Connman are supported. ;; ;; In order to use this package, add ;; ;; (setq enwc-default-backend BACKEND-SYMBOL) ;; -;; where BACKEND-SYMBOL is either 'wicd or 'nm, to your .emacs file (or other init +;; where BACKEND-SYMBOL is either 'wicd, 'nm or 'cm, to your .emacs file (or other init ;; file). ;; ;; Then you can just run `enwc' to start everything. -- 2.41.0 --=-=-=--